<commit_before>define(['../util'], function(util) {

  // Namespace: store.memory
  // <StorageAdapter> implementation that keeps data in memory.

  var logger = util.getLogger('store::memory');

  return function() {
    var nodes = {};

    return {
      on: function() {},

      transaction: function(write, body) {
        return util.makePromise(function(promise) {
          body({
            get: function(path) {
              logger.info('get', path);
              return util.getPromise().fulfillLater(nodes[path]);
            },

            set: function(path, node) {
              logger.info('set', path);
              nodes[path] = node;
              return util.getPromise().fulfillLater();
            },

            remove: function(path) {
              logger.info('remove', path);
              delete nodes[path];
              return util.getPromise().fulfillLater();
            }
          });
          promise.fulfillLater();
        });
      },

      forgetAll: function() {
        logger.info('forgetAll');
        nodes = {};
        return util.getPromise().fulfillLater();
      },

      hasKey: function(path) {
        return !! nodes[path];
      },

      // wireClient STUB

      getState: function() {
        return 'connected';
      },

      // TESTS & DEBUGGING

      printTree: function() {
        var printOne = function(path, indent) {
          return this.get(path).
            then(function(node) {
              if(! node) {
                throw "No node for path: " + path;
              }
              if(util.isDir(path)) {
                console.log(indent + '+ ' + util.baseName(path));
                return util.asyncEach(Object.keys(node.data), function(key) {
                  return printOne(path + key, indent + '| ');
                });
              } else {
                console.log(indent + util.baseName(path) + ' ' +
                            node.data.length + ' bytes, ' +
                            node.mimeType);
              }
            });
        }.bind(this);

        return printOne('/', '');
      },

      // FIXME: implement through 'set' and move to common.
      init: function(dataTree, mimeType, timestamp, access) {
        this.forgetAll();
        var initNode = function (path, tree) {
          var node = {
            startAccess: Object.keys(access).reduce(function(a, k) {
              return (k === path) ? access[k] : a;
            }, null),
            startForce: null,
            startForceTree: null,
            timestamp: timestamp,
            lastUpdatedAt: timestamp
          };
          if(typeof(tree) == 'object') {
            node.mimeType = 'application/json';
            node.data = Object.keys(tree).reduce(function(listing, _key) {
              var key = _key;
              if(typeof(tree[_key]) === 'object') {
                key += '/';
              }
              initNode(path + key, tree[_key]);
              listing[key] = timestamp;
              return listing;
            }, {});
            node.diff = {};
          } else {
            node.mimeType = mimeType;
            node.data = tree;
          }
          nodes[path] = node;
        }.bind(this);

        initNode('/', dataTree);
      }
    };
  };
});<commit_msg>fake transactions for memory-store<commit_after>define(['../util'], function(util) {

  // Namespace: store.memory
  // <StorageAdapter> implementation that keeps data in memory.

  var logger = util.getLogger('store::memory');

  return function() {
    var nodes = {};

    var pseudoTransaction = {
      get: function(path) {
        logger.info('get', path);
        return util.getPromise().fulfillLater(nodes[path]);
      },

      set: function(path, node) {
        logger.info('set', path);
        nodes[path] = node;
        return util.getPromise().fulfillLater();
      },

      remove: function(path) {
        logger.info('remove', path);
        delete nodes[path];
        return util.getPromise().fulfillLater();
      }
    };

    return util.extend(pseudoTransaction, {
      on: function() {},

      transaction: function(write, body) {
        return util.makePromise(function(promise) {
          body(pseudoTransaction);
          promise.fulfillLater();
        });
      },

      forgetAll: function() {
        logger.info('forgetAll');
        nodes = {};
        return util.getPromise().fulfillLater();
      },

      hasKey: function(path) {
        return !! nodes[path];
      },

      // wireClient STUB

      getState: function() {
        return 'connected';
      },

      // TESTS & DEBUGGING

      printTree: function() {
        var printOne = function(path, indent) {
          return this.get(path).
            then(function(node) {
              if(! node) {
                throw "No node for path: " + path;
              }
              if(util.isDir(path)) {
                console.log(indent + '+ ' + util.baseName(path));
                return util.asyncEach(Object.keys(node.data), function(key) {
                  return printOne(path + key, indent + '| ');
                });
              } else {
                console.log(indent + util.baseName(path) + ' ' +
                            node.data.length + ' bytes, ' +
                            node.mimeType);
              }
            });
        }.bind(this);

        return printOne('/', '');
      },

      // FIXME: implement through 'set' and move to common.
      init: function(dataTree, mimeType, timestamp, access) {
        this.forgetAll();
        var initNode = function (path, tree) {
          var node = {
            startAccess: Object.keys(access).reduce(function(a, k) {
              return (k === path) ? access[k] : a;
            }, null),
            startForce: null,
            startForceTree: null,
            timestamp: timestamp,
            lastUpdatedAt: timestamp
          };
          if(typeof(tree) == 'object') {
            node.mimeType = 'application/json';
            node.data = Object.keys(tree).reduce(function(listing, _key) {
              var key = _key;
              if(typeof(tree[_key]) === 'object') {
                key += '/';
              }
              initNode(path + key, tree[_key]);
              listing[key] = timestamp;
              return listing;
            }, {});
            node.diff = {};
          } else {
            node.mimeType = mimeType;
            node.data = tree;
          }
          nodes[path] = node;
        }.bind(this);

        initNode('/', dataTree);
      }
    });
  };
});
{'fraction_non_alphanumeric': 0.13943981831945496, 'fraction_numerical': 0.0, 'mean_word_length': 1.468609865470852, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1324091', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1744, 'n_words': 354}