<commit_before>import Ember from 'ember';
import DS from 'ember-data';
import LFQueue from 'ember-localforage-adapter/utils/queue';
import LFCache from 'ember-localforage-adapter/utils/cache';

export default DS.Adapter.extend(Ember.Evented, {
  defaultSerializer: 'localforage',
  queue : LFQueue.create(),
  cache : LFCache.create(),
  caching : 'model',

  /**
    This is the main entry point into finding records. The first parameter to
    this method is the model's name as a string.

    @method find
    @param {DS.Model} type
    @param {Object|String|Integer|null} id
    */
  find: function(store, type, id, opts) {
    var adapter = this;

    return new Ember.RSVP.Promise(function(resolve, reject) {
        var allowRecursive = true;
       adapter._namespaceForType(type).then (function (namespace) {
          /**
             * In the case where there are relationships, this method is called again
             * for each relation. Given the relations have references to the main
             * object, we use allowRecursive to avoid going further into infinite
             * recursiveness.
             *
             * Concept from ember-indexdb-adapter
             */
            if (opts && typeof opts.allowRecursive !== 'undefined') {
              allowRecursive = opts.allowRecursive;
            }

          var record = Ember.A(namespace.records[id]);
          if (!record) {
            reject();
            return;
          }

          if (allowRecursive) {
            adapter.loadRelationships(type, record).then(function(finalRecord) {
              resolve(finalRecord);
            });
          } else {
            resolve(record);
          }
        });
    });
  },

  findMany: function (store, type, ids) {
    var adapter = this;

    return new Ember.RSVP.Promise(function(resolve, reject) {
    adapter._namespaceForType(type).then (function (namespace) {
      var results = [];

          for (var i = 0; i < ids.length; i++) {
            results.push(Ember.copy(namespace.records[ids[i]]));
          }

          resolve(results);
    });
    }).then(function(records) {
      if (records.get('length')) {
        return adapter.loadRelationshipsForMany(type, records);
      } else {
        return records;
      }
    });
  },

  // Supports queries that look like this:
  //
  //   {
  //     <property to query>: <value or regex (for strings) to match>,
  //     ...
  //   }
  //
  // Every property added to the query is an "AND" query, not "OR"
  //
  // Example:
  //
  //  match records with "complete: true" and the name "foo" or "bar"
  //
  //    { complete: true, name: /foo|bar/ }
  findQuery: function (store, type, query, recordArray) {
      var adapter = this;
    return new Ember.RSVP.Promise(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespace) {
        var results = adapter.query(namespace.records, query);

          if (results.get('length')) {
            results = adapter.loadRelationshipsForMany(type, results);
          }

          resolve(results);
     });
    });

  },

  query: function (records, query) {
    var results = [],
        id, record, property, test, push;
    for (id in records) {
      record = records[id];
      for (property in query) {
        test = query[property];
        push = false;
        if (Object.prototype.toString.call(test) === '[object RegExp]') {
          push = test.test(record[property]);
        } else {
          push = record[property] === test;
        }
      }
      if (push) {
        results.push(record);
      }
    }
    return results;
  },

  findAll: function (store, type) {
    var adapter = this;
    return new Ember.RSVP.Promise(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespace) {
        var results = [];

        for (var id in namespace.records) {
          results.push(Ember.copy(namespace.records[id]));
        }
        resolve(results);
      });
    });
  },

  createRecord: function (store, type, snapshot) {
    var adapter = this;
    return this.queue.attach(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespaceRecords) {
        var recordHash = snapshot.record.serialize({includeId: true});

            namespaceRecords.records[recordHash.id] = recordHash;
            adapter.persistData(type, namespaceRecords).then (function () {
              resolve();
            });
      });
    });
  },

  updateRecord: function (store, type, snapshot) {
    var adapter = this;
    return this.queue.attach(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespaceRecords) {
           var id = snapshot.get('id');

        namespaceRecords.records[id] = snapshot.record.serialize({ includeId: true });

        adapter.persistData(type, namespaceRecords).then (function () {
          resolve();
        });
      });
    });
  },

  deleteRecord: function (store, type, record) {
    var adapter = this;
    return this.queue.attach(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespaceRecords) {
           var id = record.get('id');

        delete namespaceRecords.records[id];

        adapter.persistData(type, namespaceRecords).then(function () {
          resolve();
        });
      });
    });
  },

  generateIdForRecord: function () {
    return Math.random().toString(32).slice(2).substr(0, 5);
  },

  // private

  adapterNamespace: function () {
    return this.get('namespace') || 'DS.LFAdapter';
  },<commit_msg>[wroding] change record to snapshot<commit_after>import Ember from 'ember';
import DS from 'ember-data';
import LFQueue from 'ember-localforage-adapter/utils/queue';
import LFCache from 'ember-localforage-adapter/utils/cache';

export default DS.Adapter.extend(Ember.Evented, {
  defaultSerializer: 'localforage',
  queue : LFQueue.create(),
  cache : LFCache.create(),
  caching : 'model',

  /**
    This is the main entry point into finding records. The first parameter to
    this method is the model's name as a string.

    @method find
    @param {DS.Model} type
    @param {Object|String|Integer|null} id
    */
  find: function(store, type, id, snapshot) {
    var adapter = this;

    return new Ember.RSVP.Promise(function(resolve, reject) {
        var allowRecursive = true;
       adapter._namespaceForType(type).then (function (namespace) {
          /**
             * In the case where there are relationships, this method is called again
             * for each relation. Given the relations have references to the main
             * object, we use allowRecursive to avoid going further into infinite
             * recursiveness.
             *
             * Concept from ember-indexdb-adapter
             */
            if (snapshot && typeof snapshot.allowRecursive !== 'undefined') {
              allowRecursive = snapshot.allowRecursive;
            }

          var record = Ember.A(namespace.records[id]);
          if (!record) {
            reject();
            return;
          }

          if (allowRecursive) {
            adapter.loadRelationships(type, record).then(function(finalRecord) {
              resolve(finalRecord);
            });
          } else {
            resolve(record);
          }
        });
    });
  },

  findMany: function (store, type, ids) {
    var adapter = this;

    return new Ember.RSVP.Promise(function(resolve, reject) {
    adapter._namespaceForType(type).then (function (namespace) {
      var results = [];

          for (var i = 0; i < ids.length; i++) {
            results.push(Ember.copy(namespace.records[ids[i]]));
          }

          resolve(results);
    });
    }).then(function(records) {
      if (records.get('length')) {
        return adapter.loadRelationshipsForMany(type, records);
      } else {
        return records;
      }
    });
  },

  // Supports queries that look like this:
  //
  //   {
  //     <property to query>: <value or regex (for strings) to match>,
  //     ...
  //   }
  //
  // Every property added to the query is an "AND" query, not "OR"
  //
  // Example:
  //
  //  match records with "complete: true" and the name "foo" or "bar"
  //
  //    { complete: true, name: /foo|bar/ }
  findQuery: function (store, type, query, recordArray) {
      var adapter = this;
    return new Ember.RSVP.Promise(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespace) {
        var results = adapter.query(namespace.records, query);

          if (results.get('length')) {
            results = adapter.loadRelationshipsForMany(type, results);
          }

          resolve(results);
     });
    });

  },

  query: function (records, query) {
    var results = [],
        id, record, property, test, push;
    for (id in records) {
      record = records[id];
      for (property in query) {
        test = query[property];
        push = false;
        if (Object.prototype.toString.call(test) === '[object RegExp]') {
          push = test.test(record[property]);
        } else {
          push = record[property] === test;
        }
      }
      if (push) {
        results.push(record);
      }
    }
    return results;
  },

  findAll: function (store, type) {
    var adapter = this;
    return new Ember.RSVP.Promise(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespace) {
        var results = [];

        for (var id in namespace.records) {
          results.push(Ember.copy(namespace.records[id]));
        }
        resolve(results);
      });
    });
  },

  createRecord: function (store, type, snapshot) {
    var adapter = this;
    return this.queue.attach(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespaceRecords) {
        var recordHash = snapshot.record.serialize({includeId: true});

            namespaceRecords.records[recordHash.id] = recordHash;
            adapter.persistData(type, namespaceRecords).then (function () {
              resolve();
            });
      });
    });
  },

  updateRecord: function (store, type, snapshot) {
    var adapter = this;
    return this.queue.attach(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespaceRecords) {
           var id = snapshot.get('id');

        namespaceRecords.records[id] = snapshot.record.serialize({ includeId: true });

        adapter.persistData(type, namespaceRecords).then (function () {
          resolve();
        });
      });
    });
  },

  deleteRecord: function (store, type, snapshot) {
    var adapter = this;
    return this.queue.attach(function(resolve, reject) {
      adapter._namespaceForType(type).then (function (namespaceRecords) {
           var id = snapshot.get('id');

        delete namespaceRecords.records[id];

        adapter.persistData(type, namespaceRecords).then(function () {
          resolve();
        });
      });
    });
  },

  generateIdForRecord: function () {
    return Math.random().toString(32).slice(2).substr(0, 5);
  },

  // private

  adapterNamespace: function () {
    return this.get('namespace') || 'DS.LFAdapter';
  },
{'fraction_non_alphanumeric': 0.12969222558263654, 'fraction_numerical': 0.0010674257249599715, 'mean_word_length': 2.2428612633400635, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1527924', 'n_tokens_mistral': 3181, 'n_tokens_neox': 3102, 'n_words': 770}