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,KAAK,GAAW,SAAU,GAC3C,OAAO,IAAO,EAAS,EACzB,KAGE,EAAS,IAAI,KAAK,CAAE,GAAI,EAAS,GAAI,QAAS,CAAE,IAAK,EAAS,mBAF9D,EAAS,IAAI,KAAK,CAAE,GAAI,GAI5B,IAEA,EAAK,OAAO,KAAK,GACd,KAAK,CAAE,GAAI,EAAG,QAAS,IACvB,SAAQ,SAAU,EAAK,GACtB,GAAI,EAAK,OAAO,EAAG,GACnB,IAAK,EAAU,SAAW,EAAO,OAAQ,OAAO,EAAG,KAAM,MACzD,MAAM,EAAU,GAYhB,OAXA,EAAI,SAAQ,SAAU,GACpB,MAAM,EAAW,EAAE,KAAK,GAAW,SAAU,GAC3C,OAAO,EAAS,KAAO,CACzB,IACI,UAAiB,EAAS,IAC9B,MAAM,EAAQ,EAAE,OAAO,GAAQ,SAAU,GACvC,OAAO,EAAM,KAAO,CACtB,IACM,EAAS,EAAK,aAAa,EAAI,EAAU,GAC/C,EAAQ,KAAK,EACf,IACO,EAAG,KAAM,EAClB,GACJ,EAEA,OAAO,QAAQ,WAAa","file":"/npm/sourced-repo-mongo@1.0.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/sourced-repo-mongo@1.0.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const EventEmitter = require('events').EventEmitter\nconst log = require('debug')('sourced-repo-mongo')\nconst mongo = require('./mongo')\nconst util = require('util')\nconst _ = require('lodash')\n\nfunction Repository (EntityType, options) {\n  options = options || {}\n  EventEmitter.call(this)\n  if (!options.db && !mongo.db) {\n    throw new Error('mongo has not been initialized. you must call require(\\'sourced-repo-mongo/mongo\\').connect(config.MONGO_URL); before instantiating a Repository')\n  }\n  const indices = _.union(options.indices, ['id'])\n  const self = this\n  const db = options.db || mongo.db\n  self.EntityType = EntityType\n  self.indices = indices\n  self.snapshotFrequency = options.snapshotFrequency || 10\n\n  const snapshotCollectionName = util.format('%s.snapshots', EntityType.name)\n  const snapshots = db.collection(snapshotCollectionName)\n  self.snapshots = snapshots\n  const eventCollectionName = util.format('%s.events', EntityType.name)\n  const events = db.collection(eventCollectionName)\n  self.events = events\n\n  const error = function (err) {\n    if (err) return self.emit('error', err)\n  }\n\n  self.indices.forEach(function (index) {\n    snapshots.createIndex(index, error)\n    events.createIndex(index, error)\n  })\n  events.createIndex({ id: 1, version: 1 }, error)\n  snapshots.createIndex({ id: 1, version: 1 }, error)\n  snapshots.createIndex('snapshotVersion', error)\n\n  log('initialized %s entity store', self.EntityType.name)\n\n  self.emit('ready')\n}\n\nutil.inherits(Repository, EventEmitter)\n\nRepository.prototype.commit = function commit (entity, options, cb) {\n  if (typeof options === 'function') {\n    cb = options\n    options = {}\n  }\n\n  const self = this\n\n  log('committing %s for id %s', this.EntityType.name, entity.id)\n\n  this._commitEvents(entity, function _afterCommitEvents (err) {\n    if (err) return cb(err)\n\n    self._commitSnapshots(entity, options, function _afterCommitSnapshots (err) {\n      if (err) return cb(err)\n      self._emitEvents(entity)\n      return cb()\n    })\n  })\n}\n\nRepository.prototype.commitAll = function commit (entities, options, cb) {\n  if (typeof options === 'function') {\n    cb = options\n    options = {}\n  }\n\n  const self = this\n\n  log('committing %s for id %j', this.EntityType.name, _.map(entities, 'id'))\n\n  this._commitAllEvents(entities, function _afterCommitEvents (err) {\n    if (err) return cb(err)\n    self._commitAllSnapshots(entities, options, function _afterCommitSnapshots (err) {\n      if (err) return cb(err)\n      entities.forEach(function (entity) {\n        self._emitEvents(entity)\n      })\n      return cb()\n    })\n  })\n}\n\nRepository.prototype.get = function get (id, cb) {\n  return this._getByIndex('id', id, cb)\n}\n\nRepository.prototype._getByIndex = function _getByIndex (index, value, cb) {\n  const self = this\n\n  if (this.indices.indexOf(index) === -1) throw new Error('Cannot get sourced entity type [%s] by index [%s]', this.EntityType, index)\n\n  log('getting %s for %s %s', this.EntityType.name, index, value)\n\n  const criteria = { }\n  criteria[index] = value\n\n  this.snapshots\n    .find(criteria)\n    .sort({ version: -1 })\n    .limit(-1)\n    .toArray(function (err, snapshots) {\n      if (err) return cb(err)\n\n      const snapshot = snapshots[0]\n\n      if (snapshot) criteria.version = { $gt: snapshot.version }\n      self.events.find(criteria)\n        .sort({ version: 1 })\n        .toArray(function (err, events) {\n          if (err) return cb(err)\n          if (snapshot) delete snapshot._id\n          if (!snapshot && !events.length) return cb(null, null)\n\n          const id = (index === 'id') ? value : (snapshot) ? snapshot.id : events[0].id\n\n          const entity = self._deserialize(id, snapshot, events)\n          return cb(null, entity)\n        })\n    })\n}\n\nRepository.prototype.getAll = function getAll (ids, cb) {\n  const self = this\n\n  if (typeof ids === 'function') {\n    cb = ids\n    ids = null\n    return this.events.distinct('id', function (err, distinctEventIds) {\n      if (err) return cb(err)\n      self.getAll(distinctEventIds, cb)\n    })\n  }\n\n  log('getting %ss for ids %j', this.EntityType.name, ids)\n\n  if (ids.length === 0) return cb(null, [])\n\n  this._getAllSnapshots(ids, function _afterGetAllSnapshots (err, snapshots) {\n    if (err) return cb(err)\n    self._getAllEvents(ids, snapshots, function (err, entities) {\n      if (err) return cb(err)\n      return cb(null, entities)\n    })\n  })\n}\n\nRepository.prototype._commitEvents = function _commitEvents (entity, cb) {\n  const self = this\n\n  if (entity.newEvents.length === 0) return cb()\n\n  if (!entity.id) return cb(new Error('Cannot commit an entity of type [%s] without an [id] property', this.EntityType))\n\n  const events = entity.newEvents\n  events.forEach(function _applyIndices (event) {\n    if (event && event._id) delete event._id // mongo will blow up if we try to insert multiple _id keys\n    self.indices.forEach(function (index) {\n      event[index] = entity[index]\n    })\n  })\n  self.events.insertMany(events, function (err) {\n    if (err) return cb(err)\n    log('committed %s.events for id %s', self.EntityType.name, entity.id)\n    entity.newEvents = []\n    return cb()\n  })\n}\n\nRepository.prototype._commitAllEvents = function _commitEvents (entities, cb) {\n  const self = this\n\n  const events = []\n  entities.forEach(function (entity) {\n    if (entity.newEvents.length === 0) return\n\n    if (!entity.id) return cb(new Error('Cannot commit an entity of type [%s] without an [id] property', self.EntityType))\n\n    const evnts = entity.newEvents\n    evnts.forEach(function _applyIndices (event) {\n      if (event && event._id) delete event._id // mongo will blow up if we try to insert multiple _id keys\n      self.indices.forEach(function (index) {\n        event[index] = entity[index]\n      })\n    })\n    Array.prototype.unshift.apply(events, evnts)\n  })\n\n  if (events.length === 0) return cb()\n\n  self.events.insertMany(events, function (err) {\n    if (err) return cb(err)\n    log('committed %s.events for ids %j', self.EntityType.name, _.map(entities, 'id'))\n    entities.forEach(function (entity) {\n      entity.newEvents = []\n    })\n    return cb()\n  })\n}\n\nRepository.prototype._commitSnapshots = function _commitSnapshots (entity, options, cb) {\n  const self = this\n\n  if (options.forceSnapshot || entity.version >= entity.snapshotVersion + self.snapshotFrequency) {\n    const snapshot = entity.snapshot()\n    if (snapshot && snapshot._id) delete snapshot._id // mongo will blow up if we try to insert multiple _id keys\n    self.snapshots.insertOne(snapshot, function (err) {\n      if (err) return cb(err)\n      log('committed %s.snapshot for id %s %j', self.EntityType.name, entity.id, snapshot)\n      return cb(null, entity)\n    })\n  } else {\n    return cb(null, entity)\n  }\n}\n\nRepository.prototype._commitAllSnapshots = function _commitAllSnapshots (entities, options, cb) {\n  const self = this\n\n  const snapshots = []\n  entities.forEach(function (entity) {\n    if (options.forceSnapshot || entity.version >= entity.snapshotVersion + self.snapshotFrequency) {\n      const snapshot = entity.snapshot()\n      if (snapshot) {\n        if (snapshot._id) delete snapshot._id // mongo will blow up if we try to insert multiple _id keys)\n        snapshots.push(snapshot)\n      }\n    }\n  })\n\n  if (snapshots.length === 0) return cb()\n\n  self.snapshots.insertMany(snapshots, function (err) {\n    if (err) return cb(err)\n    log('committed %s.snapshot for ids %s %j', self.EntityType.name, _.map(entities, 'id'), snapshots)\n    return cb(null, entities)\n  })\n}\n\nRepository.prototype._deserialize = function _deserialize (id, snapshot, events) {\n  log('deserializing %s entity ', this.EntityType.name)\n  const entity = new this.EntityType(snapshot, events)\n  entity.id = id\n  return entity\n}\n\nRepository.prototype._emitEvents = function _emitEvents (entity) {\n  const self = this\n\n  const eventsToEmit = entity.eventsToEmit\n  entity.eventsToEmit = []\n  eventsToEmit.forEach(function (eventToEmit) {\n    const args = Array.prototype.slice.call(eventToEmit)\n    self.EntityType.prototype.emit.apply(entity, args)\n  })\n\n  log('emitted local events for id %s', entity.id)\n}\n\nRepository.prototype._getAllSnapshots = function _getAllSnapshots (ids, cb) {\n  const self = this\n\n  const match = { $match: { id: { $in: ids } } }\n  const sort = { $sort: { snapshotVersion: 1 } }\n  const group = { $group: { _id: '$id', snapshotVersion: { $last: '$snapshotVersion' } } }\n\n  self.snapshots.aggregate([match, sort, group], function (err, cursor) {\n    if (err) return cb(err)\n    cursor.toArray(function (err, idVersionPairs) {\n      if (err) return cb(err)\n      let criteria = {}\n      if (idVersionPairs.length === 0) {\n        return cb(null, [])\n      } else if (idVersionPairs.length === 1) {\n        criteria = { id: idVersionPairs[0]._id, snapshotVersion: idVersionPairs[0].snapshotVersion }\n      } else {\n        criteria.$or = []\n        idVersionPairs.forEach(function (pair) {\n          const cri = { id: pair._id, snapshotVersion: pair.snapshotVersion }\n          criteria.$or.push(cri)\n        })\n      }\n      self.snapshots\n        .find(criteria)\n        .toArray(function (err, snapshots) {\n          if (err) cb(err)\n          return cb(null, snapshots)\n        })\n    })\n  })\n}\n\nRepository.prototype._getAllEvents = function _getAllEvents (ids, snapshots, cb) {\n  const self = this\n\n  const criteria = { $or: [] }\n  ids.forEach(function (id) {\n    let snapshot\n    if (!(snapshot = _.find(snapshots, function (snapshot) {\n      return id === snapshot.id\n    }))) {\n      criteria.$or.push({ id: id })\n    } else {\n      criteria.$or.push({ id: snapshot.id, version: { $gt: snapshot.snapshotVersion } })\n    }\n  })\n\n  self.events.find(criteria)\n    .sort({ id: 1, version: 1 })\n    .toArray(function (err, events) {\n      if (err) return cb(err)\n      if (!snapshots.length && !events.length) return cb(null, null)\n      const results = []\n      ids.forEach(function (id) {\n        const snapshot = _.find(snapshots, function (snapshot) {\n          return snapshot.id === id\n        })\n        if (snapshot) delete snapshot._id\n        const evnts = _.filter(events, function (event) {\n          return event.id === id\n        })\n        const entity = self._deserialize(id, snapshot, evnts)\n        results.push(entity)\n      })\n      return cb(null, results)\n    })\n}\n\nmodule.exports.Repository = Repository\n"]}