<commit_before>'use strict';

angular.module('pouchdb', [])
  .constant('POUCHDB_METHODS', {
    destroy: 'qify',
    put: 'qify',
    post: 'qify',
    get: 'qify',
    remove: 'qify',
    bulkDocs: 'qify',
    allDocs: 'qify',
    putAttachment: 'qify',
    getAttachment: 'qify',
    removeAttachment: 'qify',
    query: 'qify',
    viewCleanup: 'qify',
    info: 'qify',
    compact: 'qify',
    revsDiff: 'qify',
    changes: 'eventEmitter',
    sync: 'eventEmitter',
    replicate: {
      to: 'eventEmitter',
      from: 'eventEmitter'
    }
  })
  .service('pouchDecorators', function($q) {
    this.qify = function(fn) {
      return function() {
        return $q.when(fn.apply(this, arguments));
      };
    };

    this.eventEmitter = function(fn) {
      return function() {
        var deferred = $q.defer();
        var emitter = fn.apply(this, arguments)
          .on('change', function(change) {
            return deferred.notify({
              change: change
            });
          })
          .on('uptodate', function(uptodate) {
            return deferred.notify({
              uptodate: uptodate
            });
          })
          .on('complete', function(response) {
            return deferred.resolve(response);
          })
          .on('error', function(error) {
            return deferred.reject(error);
          });
        emitter.$promise = deferred.promise;
        return emitter;
      };
    };
  })
  .provider('pouchDB', function(POUCHDB_METHODS) {
    this.methods = POUCHDB_METHODS;
    this.$get = function($window, pouchDecorators) {
      var methods = this.methods;

      function wrapMethods(db, methods, parent) {
        for (var method in methods) {
          var wrapFunction = methods[method];

          if (!angular.isString(wrapFunction)) {
            return wrapMethods(db, wrapFunction, method);
          }

          wrapFunction = pouchDecorators[wrapFunction];

          if (!parent) {
            db[method] = wrapFunction(db[method]);
            continue;
          }

          db[parent][method] = wrapFunction(db[parent][method]);
        }
        return db;
      }

      return function pouchDB(name, options) {
        var db = new $window.PouchDB(name, options);
        return wrapMethods(db, methods);
      };
    };
  });<commit_msg>refactor: delint/reference self<commit_after>'use strict';

angular.module('pouchdb', [])
  .constant('POUCHDB_METHODS', {
    destroy: 'qify',
    put: 'qify',
    post: 'qify',
    get: 'qify',
    remove: 'qify',
    bulkDocs: 'qify',
    allDocs: 'qify',
    putAttachment: 'qify',
    getAttachment: 'qify',
    removeAttachment: 'qify',
    query: 'qify',
    viewCleanup: 'qify',
    info: 'qify',
    compact: 'qify',
    revsDiff: 'qify',
    changes: 'eventEmitter',
    sync: 'eventEmitter',
    replicate: {
      to: 'eventEmitter',
      from: 'eventEmitter'
    }
  })
  .service('pouchDecorators', function($q) {
    this.qify = function(fn) {
      return function() {
        return $q.when(fn.apply(this, arguments));
      };
    };

    this.eventEmitter = function(fn) {
      return function() {
        var deferred = $q.defer();
        var emitter = fn.apply(this, arguments)
          .on('change', function(change) {
            return deferred.notify({
              change: change
            });
          })
          .on('uptodate', function(uptodate) {
            return deferred.notify({
              uptodate: uptodate
            });
          })
          .on('complete', function(response) {
            return deferred.resolve(response);
          })
          .on('error', function(error) {
            return deferred.reject(error);
          });
        emitter.$promise = deferred.promise;
        return emitter;
      };
    };
  })
  .provider('pouchDB', function(POUCHDB_METHODS) {
    var self = this;
    self.methods = POUCHDB_METHODS;
    self.$get = function($window, pouchDecorators) {
      function wrapMethods(db, methods, parent) {
        for (var method in methods) {
          var wrapFunction = methods[method];

          if (!angular.isString(wrapFunction)) {
            return wrapMethods(db, wrapFunction, method);
          }

          wrapFunction = pouchDecorators[wrapFunction];

          if (!parent) {
            db[method] = wrapFunction(db[method]);
            continue;
          }

          db[parent][method] = wrapFunction(db[parent][method]);
        }
        return db;
      }

      return function pouchDB(name, options) {
        var db = new $window.PouchDB(name, options);
        return wrapMethods(db, self.methods);
      };
    };
  });
{'fraction_non_alphanumeric': 0.14031323750268182, 'fraction_numerical': 0.0, 'mean_word_length': 2.0253082414016874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1258061', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1405, 'n_words': 278}