From deb45809aec6e52e900422b3646ce07dd377b8a1 Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Fri, 11 Mar 2016 09:40:30 +0200 Subject: [PATCH] tweak: Recompile using TS1.8 --- dist/index.js | 8 +- dist/index.js.map | 2 +- dist/lib/Aggregate.js | 2 +- dist/lib/Bson.js | 1 + dist/lib/Cache.js | 2 +- dist/lib/CacheDirector.js | 2 +- dist/lib/Configuration.js | 2 +- dist/lib/Core.js | 3 +- dist/lib/Core.js.map | 2 +- dist/lib/Cursor.js | 3 +- dist/lib/Cursor.js.map | 2 +- dist/lib/Decorators.js | 1 + dist/lib/Decorators.js.map | 2 +- dist/lib/General.js | 2 +- dist/lib/Hooks.js | 2 +- dist/lib/Index.js | 2 +- dist/lib/Instance.js | 3 +- dist/lib/Instance.js.map | 2 +- dist/lib/InstanceInterface.js | 2 +- dist/lib/Middleware.js | 2 +- dist/lib/Model.js | 3 +- dist/lib/Model.js.map | 2 +- dist/lib/ModelCache.js | 3 +- dist/lib/ModelCache.js.map | 2 +- dist/lib/ModelHandlers.js | 3 +- dist/lib/ModelHandlers.js.map | 2 +- dist/lib/ModelHelpers.js | 3 +- dist/lib/ModelHelpers.js.map | 2 +- dist/lib/ModelInterfaces.js | 2 +- dist/lib/ModelOptions.js | 2 +- dist/lib/ModelSpecificInstance.js | 1 + dist/lib/ModelSpecificInstance.js.map | 2 +- dist/lib/Plugins.js | 2 +- dist/lib/Schema.js | 2 +- dist/lib/Transforms.js | 1 + dist/lib/Transforms.js.map | 2 +- dist/lib/Validators.js | 1 + dist/lib/Validators.js.map | 2 +- dist/lib/cacheControllers/IDDirector.js | 3 +- dist/lib/cacheControllers/IDDirector.js.map | 2 +- dist/lib/caches/MemoryCache.js | 3 +- dist/lib/caches/MemoryCache.js.map | 2 +- dist/lib/caches/NoOpCache.js | 3 +- dist/lib/caches/NoOpCache.js.map | 2 +- dist/lib/middleware/Express.js | 1 + dist/lib/middleware/Express.js.map | 2 +- dist/lib/utils/ObjectID.js | 1 + dist/lib/utils/ObjectID.js.map | 2 +- dist/lib/utils/Omnom.js | 94 ++++++++++++--------- dist/lib/utils/Omnom.js.map | 2 +- 50 files changed, 112 insertions(+), 89 deletions(-) diff --git a/dist/index.js b/dist/index.js index 959232e..5d9d870 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,3 +1,4 @@ +"use strict"; function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } @@ -5,13 +6,6 @@ __export(require('./lib/Core')); __export(require('./lib/Model')); __export(require('./lib/Instance')); __export(require('./lib/Decorators')); -__export(require('./lib/Plugins')); -__export(require('./lib/Schema')); -__export(require('./lib/Cache')); -__export(require('./lib/CacheDirector')); -__export(require('./lib/ModelOptions')); -__export(require('./lib/Configuration')); -__export(require('./lib/Hooks')); __export(require('./lib/Transforms')); __export(require('./lib/caches/MemoryCache')); __export(require('./lib/caches/NoOpCache')); diff --git a/dist/index.js.map b/dist/index.js.map index f73fc6b..7a0fe37 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;AAAA,iBAAc,YAAY,CAAC,EAAA;AAC3B,iBAAc,aAAa,CAAC,EAAA;AAC5B,iBAAc,gBAAgB,CAAC,EAAA;AAE/B,iBAAc,kBAAkB,CAAC,EAAA;AAEjC,iBAAc,eAAe,CAAC,EAAA;AAC9B,iBAAc,cAAc,CAAC,EAAA;AAC7B,iBAAc,aAAa,CAAC,EAAA;AAC5B,iBAAc,qBAAqB,CAAC,EAAA;AACpC,iBAAc,oBAAoB,CAAC,EAAA;AACnC,iBAAc,qBAAqB,CAAC,EAAA;AACpC,iBAAc,aAAa,CAAC,EAAA;AAC5B,iBAAc,kBAAkB,CAAC,EAAA;AAEjC,iBAAc,0BAA0B,CAAC,EAAA;AACzC,iBAAc,wBAAwB,CAAC,EAAA;AAEvC,iBAAc,mCAAmC,CAAC,EAAA;AAElD,iBAAc,sBAAsB,CAAC,EAAA","file":"index.js","sourcesContent":["export * from './lib/Core';\r\nexport * from './lib/Model';\r\nexport * from './lib/Instance';\r\n\r\nexport * from './lib/Decorators';\r\n\r\nexport * from './lib/Plugins';\r\nexport * from './lib/Schema';\r\nexport * from './lib/Cache';\r\nexport * from './lib/CacheDirector';\r\nexport * from './lib/ModelOptions';\r\nexport * from './lib/Configuration';\r\nexport * from './lib/Hooks';\r\nexport * from './lib/Transforms';\r\n\r\nexport * from './lib/caches/MemoryCache';\r\nexport * from './lib/caches/NoOpCache';\r\n\r\nexport * from './lib/cacheControllers/IDDirector';\r\n\r\nexport * from './lib/utils/ObjectID';\r\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;AAAA,iBAAc,YAAY,CAAC,EAAA;AAC3B,iBAAc,aAAa,CAAC,EAAA;AAC5B,iBAAc,gBAAgB,CAAC,EAAA;AAE/B,iBAAc,kBAAkB,CAAC,EAAA;AASjC,iBAAc,kBAAkB,CAAC,EAAA;AAEjC,iBAAc,0BAA0B,CAAC,EAAA;AACzC,iBAAc,wBAAwB,CAAC,EAAA;AAEvC,iBAAc,mCAAmC,CAAC,EAAA;AAElD,iBAAc,sBAAsB,CAAC,EAAA","file":"index.js","sourcesContent":["export * from './lib/Core';\r\nexport * from './lib/Model';\r\nexport * from './lib/Instance';\r\n\r\nexport * from './lib/Decorators';\r\n\r\nexport * from './lib/Plugins';\r\nexport * from './lib/Schema';\r\nexport * from './lib/Cache';\r\nexport * from './lib/CacheDirector';\r\nexport * from './lib/ModelOptions';\r\nexport * from './lib/Configuration';\r\nexport * from './lib/Hooks';\r\nexport * from './lib/Transforms';\r\n\r\nexport * from './lib/caches/MemoryCache';\r\nexport * from './lib/caches/NoOpCache';\r\n\r\nexport * from './lib/cacheControllers/IDDirector';\r\n\r\nexport * from './lib/utils/ObjectID';\r\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/Aggregate.js b/dist/lib/Aggregate.js index 570eb84..abb9b06 100644 --- a/dist/lib/Aggregate.js +++ b/dist/lib/Aggregate.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=Aggregate.js.map diff --git a/dist/lib/Bson.js b/dist/lib/Bson.js index 356d0d2..f99a111 100644 --- a/dist/lib/Bson.js +++ b/dist/lib/Bson.js @@ -1,5 +1,6 @@ /** * Various interfaces for low level BSON types used within Iridium. */ +"use strict"; //# sourceMappingURL=BSON.js.map diff --git a/dist/lib/Cache.js b/dist/lib/Cache.js index d9710bc..2734599 100644 --- a/dist/lib/Cache.js +++ b/dist/lib/Cache.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=Cache.js.map diff --git a/dist/lib/CacheDirector.js b/dist/lib/CacheDirector.js index 0ae8228..24a94e1 100644 --- a/dist/lib/CacheDirector.js +++ b/dist/lib/CacheDirector.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=CacheDirector.js.map diff --git a/dist/lib/Configuration.js b/dist/lib/Configuration.js index a177dbe..4ff7a34 100644 --- a/dist/lib/Configuration.js +++ b/dist/lib/Configuration.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=Configuration.js.map diff --git a/dist/lib/Core.js b/dist/lib/Core.js index 6c5e983..fb4d8e0 100644 --- a/dist/lib/Core.js +++ b/dist/lib/Core.js @@ -1,3 +1,4 @@ +"use strict"; var Bluebird = require('bluebird'); var MongoDB = require('mongodb'); var _ = require('lodash'); @@ -206,7 +207,7 @@ var Core = (function () { return Bluebird.resolve(); }; return Core; -})(); +}()); exports.Core = Core; //# sourceMappingURL=Core.js.map diff --git a/dist/lib/Core.js.map b/dist/lib/Core.js.map index 7239a85..48ab525 100644 --- a/dist/lib/Core.js.map +++ b/dist/lib/Core.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/Core.ts"],"names":["Core","Core.constructor","Core.plugins","Core.settings","Core.connection","Core.url","Core.cache","Core.register","Core.connect","Core.close","Core.express","Core.onConnecting","Core.onConnected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,CAACA,KAAIA,CAACA,WAAWA,CAACA;gBAACA,KAAIA,CAACA,WAAWA,CAACA,KAAKA,EAAEA,CAACA;YAC/CA,KAAIA,CAACA,WAAWA,GAAGA,IAAIA,CAACA;YACxBA,KAAIA,CAACA,eAAeA,GAAGA,IAAIA,CAACA;YAC5BA,MAAMA,CAACA,QAAQA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;QAChCA,CAACA,CAACA,CAACA,OAAOA,CAACA,QAAQA,CAACA,CAACA;IACzBA,CAACA;IAEDR;;;OAGGA;IACHA,oBAAKA,GAALA;QAAAS,iBAQCA;QAPGA,MAAMA,CAACA,QAAQA,CAACA,OAAOA,EAAEA,CAACA,IAAIA,CAACA;YAC3BA,EAAEA,CAACA,CAACA,CAACA,KAAIA,CAACA,WAAWA,CAACA;gBAACA,MAAMA,CAACA,KAAIA,CAACA;YACnCA,IAAIA,IAAIA,GAAeA,KAAIA,CAACA,WAAWA,CAACA;YACxCA,KAAIA,CAACA,WAAWA,GAAGA,IAAIA,CAACA;YACxBA,IAAIA,CAACA,KAAKA,EAAEA,CAACA;YACbA,MAAMA,CAACA,KAAIA,CAACA;QAChBA,CAACA,CAACA,CAACA;IACPA,CAACA;IAEDT;;;;OAIGA;IACHA,sBAAOA,GAAPA;QACIU,MAAMA,CAACA,kCAAwBA,CAACA,IAAIA,CAACA,CAACA;IAC1CA,CAACA;IAEDV;;;;;;;;;;OAUGA;IACOA,2BAAYA,GAAtBA,UAAuBA,UAAsBA;QACzCW,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAACA,UAAUA,CAACA,CAACA;IACxCA,CAACA;IAEDX;;;;;;OAMGA;IACOA,0BAAWA,GAArBA;QACIY,MAAMA,CAACA,QAAQA,CAACA,OAAOA,EAAEA,CAACA;IAC9BA,CAACA;IACLZ,WAACA;AAADA,CAhNA,AAgNCA,IAAA;AAhNY,YAAI,OAgNhB,CAAA","file":"lib/Core.js","sourcesContent":["import Bluebird = require('bluebird');\r\nimport MongoDB = require('mongodb');\r\nimport _ = require('lodash');\r\nimport http = require('http');\r\nimport events = require('events');\r\n\r\nimport {Configuration} from './Configuration';\r\nimport {Plugin} from './Plugins';\r\nimport {Model} from './Model';\r\nimport {Instance} from './Instance';\r\n\r\nimport {MiddlewareFactory} from './Middleware';\r\nimport * as ExpressMiddleware from './middleware/Express';\r\nimport {ExpressMiddlewareFactory} from './middleware/Express';\r\n\r\nimport {Cache} from './Cache';\r\nimport {NoOpCache} from './caches/NoOpCache';\r\nimport {MemoryCache} from './caches/MemoryCache';\r\n\r\n/**\r\n * The Iridium Core, responsible for managing the connection to the database as well\r\n * as any plugins you are making use of.\r\n *\r\n * Generally you will subclass this to provide your own custom core with the models you\r\n * make use of within your application.\r\n */\r\nexport class Core {\r\n /**\r\n * Creates a new Iridium Core instance connected to the specified MongoDB instance\r\n * @param {Iridium.IridiumConfiguration} config The config object defining the database to connect to\r\n * @constructs Core\r\n */\r\n constructor(config: Configuration);\r\n /**\r\n * Creates a new Iridium Core instance connected to the specified MongoDB instance\r\n * @param {String} url The URL of the MongoDB instance to connect to\r\n * @param {Iridium.IridiumConfiguration} config The config object made available as settings\r\n * @constructs Core\r\n */\r\n constructor(uri: string, config?: Configuration);\r\n constructor(uri: string | Configuration, config?: Configuration) {\r\n\r\n var args = Array.prototype.slice.call(arguments, 0);\r\n uri = config = null;\r\n for (var i = 0; i < args.length; i++) {\r\n if (typeof args[i] == 'string')\r\n uri = args[i];\r\n else if (typeof args[i] == 'object')\r\n config = args[i];\r\n }\r\n\r\n if (!uri && !config) throw new Error(\"Expected either a URI or config object to be supplied when initializing Iridium\");\r\n\r\n this._url = uri;\r\n this._config = config;\r\n }\r\n\r\n private mongoConnectAsyc = Bluebird.promisify(MongoDB.MongoClient.connect);\r\n\r\n private _plugins: Plugin[] = [];\r\n private _url: string;\r\n private _config: Configuration;\r\n private _connection: MongoDB.Db;\r\n private _cache: Cache = new NoOpCache();\r\n\r\n private _connectPromise: Bluebird;\r\n\r\n /**\r\n * Gets the plugins registered with this Iridium Core\r\n * @returns {[Iridium.Plugin]}\r\n */\r\n get plugins(): Plugin[] {\r\n return this._plugins;\r\n }\r\n\r\n /**\r\n * Gets the configuration specified in the construction of this\r\n * Iridium Core.\r\n * @returns {Iridium.Configuration}\r\n */\r\n get settings(): Configuration {\r\n return this._config;\r\n }\r\n\r\n /**\r\n * Gets the currently active database connection for this Iridium\r\n * Core.\r\n * @returns {MongoDB.Db}\r\n */\r\n get connection(): MongoDB.Db {\r\n return this._connection;\r\n }\r\n\r\n /**\r\n * Gets the URL used to connect to MongoDB\r\n * @returns {String}\r\n */\r\n get url(): string {\r\n if (this._url) return this._url;\r\n var url: string = 'mongodb://';\r\n\r\n if (this._config.username) {\r\n url += this._config.username;\r\n if (this._config.password)\r\n url += ':' + this._config.password;\r\n url += '@';\r\n }\r\n\r\n var hosts = [];\r\n\r\n if (this._config.host) {\r\n if (this._config.port)\r\n hosts.push(this._config.host + ':' + this._config.port);\r\n else\r\n hosts.push(this._config.host);\r\n }\r\n\r\n if (this._config.hosts) {\r\n _.each(this._config.hosts, (host) => {\r\n if (host.port)\r\n hosts.push(host.address + ':' + host.port);\r\n else if(this._config.port)\r\n hosts.push(host.address + ':' + this._config.port);\r\n else\r\n hosts.push(host.address);\r\n });\r\n }\r\n\r\n if (hosts.length)\r\n url += _.uniq(hosts).join(',');\r\n else\r\n url += 'localhost';\r\n\r\n url += '/' + this._config.database;\r\n\r\n return url;\r\n }\r\n\r\n /**\r\n * Gets the cache used to store objects retrieved from the database for performance reasons\r\n * @returns {cache}\r\n */\r\n get cache(): Cache {\r\n return this._cache;\r\n }\r\n\r\n set cache(value: Cache) {\r\n this._cache = value;\r\n }\r\n\r\n /**\r\n * Registers a new plugin with this Iridium Core\r\n * @param {Iridium.Plugin} plugin The plugin to register with this Iridium Core\r\n * @returns {Iridium.Core}\r\n */\r\n register(plugin: Plugin): Core {\r\n this.plugins.push(plugin);\r\n return this;\r\n }\r\n\r\n /**\r\n * Connects to the database server specified in the provided configuration\r\n * @param {function(Error, Iridium.Core)} [callback] A callback to be triggered once the connection is established.\r\n * @returns {Promise}\r\n */\r\n connect(callback?: (err: Error, core: Core) => any): Bluebird {\r\n return Bluebird.resolve().then(() => {\r\n if (this._connection) return this._connection;\r\n if (this._connectPromise) return this._connectPromise;\r\n return this._connectPromise = this.mongoConnectAsyc(this.url, this._config && this._config.options);\r\n }).then((db: MongoDB.Db) => {\r\n return this.onConnecting(db);\r\n }).then(db => {\r\n this._connection = db;\r\n this._connectPromise = null;\r\n return this.onConnected();\r\n }).then(() => {\r\n return this;\r\n }, (err) => {\r\n if (this._connection) this._connection.close();\r\n this._connection = null;\r\n this._connectPromise = null;\r\n return Bluebird.reject(err);\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Closes the active database connection\r\n * @type {Promise}\r\n */\r\n close(): Bluebird {\r\n return Bluebird.resolve().then(() => {\r\n if (!this._connection) return this;\r\n var conn: MongoDB.Db = this._connection;\r\n this._connection = null;\r\n conn.close();\r\n return this;\r\n });\r\n }\r\n\r\n /**\r\n * Provides an express middleware which can be used to set the req.db property\r\n * to the current Iridium instance.\r\n * @returns {Iridium.ExpressMiddleware}\r\n */\r\n express(): ExpressMiddleware.ExpressMiddleware {\r\n return ExpressMiddlewareFactory(this);\r\n }\r\n\r\n /**\r\n * A method which is called whenever a new connection is made to the database.\r\n *\r\n * @param connection The underlying MongoDB connection which was created, you can modify or replace this if you wish.\r\n * @returns A promise for the connection, allowing you to perform any asynchronous initialization required by your application.\r\n *\r\n * In subclassed Iridium Cores this method can be overridden to manipulate the properties\r\n * of the underlying MongoDB connection object, such as authenticating. Until this method\r\n * resolves a connection object, Iridium will be unable to execute any queries. If you wish\r\n * to run Iridium queries then look at the onConnected method.\r\n */\r\n protected onConnecting(connection: MongoDB.Db): Bluebird {\r\n return Bluebird.resolve(connection);\r\n }\r\n\r\n /**\r\n * A method which is called once a database connection has been established and accepted by Iridium\r\n *\r\n * In subclassed Iridium cores this method can be overridden to perform tasks whenever a\r\n * connection to the database has been established - such as setting up indexes for your\r\n * collections or seeding the database.\r\n */\r\n protected onConnected(): Bluebird {\r\n return Bluebird.resolve();\r\n }\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/Core.ts"],"names":[],"mappings":";AAAA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AACtC,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAW7B,wBAAuC,sBAAsB,CAAC,CAAA;AAG9D,0BAAwB,oBAAoB,CAAC,CAAA;AAG7C;;;;;;GAMG;AACH;IAcI,cAAY,GAA2B,EAAE,MAAsB;QAiBvD,qBAAgB,GAAG,QAAQ,CAAC,SAAS,CAA0B,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAE5F,aAAQ,GAAa,EAAE,CAAC;QAIxB,WAAM,GAAU,IAAI,qBAAS,EAAE,CAAC;QArBpC,IAAI,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QACpD,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC;QACpB,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC;gBAC3B,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC;gBAChC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;QAED,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;YAAC,MAAM,IAAI,KAA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;;OAGG;IACH,oBAAK,GAAL;QAAA,iBAQC;QAPG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;YAC3B,EAAE,CAAC,CAAC,CAAC,KAAI,CAAC,WAAW,CAAC;gBAAC,MAAM,CAAC,KAAI,CAAC;YACnC,IAAI,IAAI,GAAe,KAAI,CAAC,WAAW,CAAC;YACxC,KAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,KAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACH,sBAAO,GAAP;QACI,MAAM,CAAC,kCAAwB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;OAUG;IACO,2BAAY,GAAtB,UAAuB,UAAsB;QACzC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACO,0BAAW,GAArB;QACI,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IACL,WAAC;AAAD,CAhNA,AAgNC,IAAA;AAhNY,YAAI,OAgNhB,CAAA","file":"lib/Core.js","sourcesContent":["import Bluebird = require('bluebird');\r\nimport MongoDB = require('mongodb');\r\nimport _ = require('lodash');\r\nimport http = require('http');\r\nimport events = require('events');\r\n\r\nimport {Configuration} from './Configuration';\r\nimport {Plugin} from './Plugins';\r\nimport {Model} from './Model';\r\nimport {Instance} from './Instance';\r\n\r\nimport {MiddlewareFactory} from './Middleware';\r\nimport * as ExpressMiddleware from './middleware/Express';\r\nimport {ExpressMiddlewareFactory} from './middleware/Express';\r\n\r\nimport {Cache} from './Cache';\r\nimport {NoOpCache} from './caches/NoOpCache';\r\nimport {MemoryCache} from './caches/MemoryCache';\r\n\r\n/**\r\n * The Iridium Core, responsible for managing the connection to the database as well\r\n * as any plugins you are making use of.\r\n *\r\n * Generally you will subclass this to provide your own custom core with the models you\r\n * make use of within your application.\r\n */\r\nexport class Core {\r\n /**\r\n * Creates a new Iridium Core instance connected to the specified MongoDB instance\r\n * @param {Iridium.IridiumConfiguration} config The config object defining the database to connect to\r\n * @constructs Core\r\n */\r\n constructor(config: Configuration);\r\n /**\r\n * Creates a new Iridium Core instance connected to the specified MongoDB instance\r\n * @param {String} url The URL of the MongoDB instance to connect to\r\n * @param {Iridium.IridiumConfiguration} config The config object made available as settings\r\n * @constructs Core\r\n */\r\n constructor(uri: string, config?: Configuration);\r\n constructor(uri: string | Configuration, config?: Configuration) {\r\n\r\n var args = Array.prototype.slice.call(arguments, 0);\r\n uri = config = null;\r\n for (var i = 0; i < args.length; i++) {\r\n if (typeof args[i] == 'string')\r\n uri = args[i];\r\n else if (typeof args[i] == 'object')\r\n config = args[i];\r\n }\r\n\r\n if (!uri && !config) throw new Error(\"Expected either a URI or config object to be supplied when initializing Iridium\");\r\n\r\n this._url = uri;\r\n this._config = config;\r\n }\r\n\r\n private mongoConnectAsyc = Bluebird.promisify(MongoDB.MongoClient.connect);\r\n\r\n private _plugins: Plugin[] = [];\r\n private _url: string;\r\n private _config: Configuration;\r\n private _connection: MongoDB.Db;\r\n private _cache: Cache = new NoOpCache();\r\n\r\n private _connectPromise: Bluebird;\r\n\r\n /**\r\n * Gets the plugins registered with this Iridium Core\r\n * @returns {[Iridium.Plugin]}\r\n */\r\n get plugins(): Plugin[] {\r\n return this._plugins;\r\n }\r\n\r\n /**\r\n * Gets the configuration specified in the construction of this\r\n * Iridium Core.\r\n * @returns {Iridium.Configuration}\r\n */\r\n get settings(): Configuration {\r\n return this._config;\r\n }\r\n\r\n /**\r\n * Gets the currently active database connection for this Iridium\r\n * Core.\r\n * @returns {MongoDB.Db}\r\n */\r\n get connection(): MongoDB.Db {\r\n return this._connection;\r\n }\r\n\r\n /**\r\n * Gets the URL used to connect to MongoDB\r\n * @returns {String}\r\n */\r\n get url(): string {\r\n if (this._url) return this._url;\r\n var url: string = 'mongodb://';\r\n\r\n if (this._config.username) {\r\n url += this._config.username;\r\n if (this._config.password)\r\n url += ':' + this._config.password;\r\n url += '@';\r\n }\r\n\r\n var hosts = [];\r\n\r\n if (this._config.host) {\r\n if (this._config.port)\r\n hosts.push(this._config.host + ':' + this._config.port);\r\n else\r\n hosts.push(this._config.host);\r\n }\r\n\r\n if (this._config.hosts) {\r\n _.each(this._config.hosts, (host) => {\r\n if (host.port)\r\n hosts.push(host.address + ':' + host.port);\r\n else if(this._config.port)\r\n hosts.push(host.address + ':' + this._config.port);\r\n else\r\n hosts.push(host.address);\r\n });\r\n }\r\n\r\n if (hosts.length)\r\n url += _.uniq(hosts).join(',');\r\n else\r\n url += 'localhost';\r\n\r\n url += '/' + this._config.database;\r\n\r\n return url;\r\n }\r\n\r\n /**\r\n * Gets the cache used to store objects retrieved from the database for performance reasons\r\n * @returns {cache}\r\n */\r\n get cache(): Cache {\r\n return this._cache;\r\n }\r\n\r\n set cache(value: Cache) {\r\n this._cache = value;\r\n }\r\n\r\n /**\r\n * Registers a new plugin with this Iridium Core\r\n * @param {Iridium.Plugin} plugin The plugin to register with this Iridium Core\r\n * @returns {Iridium.Core}\r\n */\r\n register(plugin: Plugin): Core {\r\n this.plugins.push(plugin);\r\n return this;\r\n }\r\n\r\n /**\r\n * Connects to the database server specified in the provided configuration\r\n * @param {function(Error, Iridium.Core)} [callback] A callback to be triggered once the connection is established.\r\n * @returns {Promise}\r\n */\r\n connect(callback?: (err: Error, core: Core) => any): Bluebird {\r\n return Bluebird.resolve().then(() => {\r\n if (this._connection) return this._connection;\r\n if (this._connectPromise) return this._connectPromise;\r\n return this._connectPromise = this.mongoConnectAsyc(this.url, this._config && this._config.options);\r\n }).then((db: MongoDB.Db) => {\r\n return this.onConnecting(db);\r\n }).then(db => {\r\n this._connection = db;\r\n this._connectPromise = null;\r\n return this.onConnected();\r\n }).then(() => {\r\n return this;\r\n }, (err) => {\r\n if (this._connection) this._connection.close();\r\n this._connection = null;\r\n this._connectPromise = null;\r\n return Bluebird.reject(err);\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Closes the active database connection\r\n * @type {Promise}\r\n */\r\n close(): Bluebird {\r\n return Bluebird.resolve().then(() => {\r\n if (!this._connection) return this;\r\n var conn: MongoDB.Db = this._connection;\r\n this._connection = null;\r\n conn.close();\r\n return this;\r\n });\r\n }\r\n\r\n /**\r\n * Provides an express middleware which can be used to set the req.db property\r\n * to the current Iridium instance.\r\n * @returns {Iridium.ExpressMiddleware}\r\n */\r\n express(): ExpressMiddleware.ExpressMiddleware {\r\n return ExpressMiddlewareFactory(this);\r\n }\r\n\r\n /**\r\n * A method which is called whenever a new connection is made to the database.\r\n *\r\n * @param connection The underlying MongoDB connection which was created, you can modify or replace this if you wish.\r\n * @returns A promise for the connection, allowing you to perform any asynchronous initialization required by your application.\r\n *\r\n * In subclassed Iridium Cores this method can be overridden to manipulate the properties\r\n * of the underlying MongoDB connection object, such as authenticating. Until this method\r\n * resolves a connection object, Iridium will be unable to execute any queries. If you wish\r\n * to run Iridium queries then look at the onConnected method.\r\n */\r\n protected onConnecting(connection: MongoDB.Db): Bluebird {\r\n return Bluebird.resolve(connection);\r\n }\r\n\r\n /**\r\n * A method which is called once a database connection has been established and accepted by Iridium\r\n *\r\n * In subclassed Iridium cores this method can be overridden to perform tasks whenever a\r\n * connection to the database has been established - such as setting up indexes for your\r\n * collections or seeding the database.\r\n */\r\n protected onConnected(): Bluebird {\r\n return Bluebird.resolve();\r\n }\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/Cursor.js b/dist/lib/Cursor.js index f661616..9982935 100644 --- a/dist/lib/Cursor.js +++ b/dist/lib/Cursor.js @@ -1,3 +1,4 @@ +"use strict"; var Bluebird = require('bluebird'); /** * An Iridium collection cursor which allows the itteration through documents @@ -180,7 +181,7 @@ var Cursor = (function () { return new Cursor(this.model, this.conditions, this.cursor.setReadPreference(type)); }; return Cursor; -})(); +}()); exports.Cursor = Cursor; //# sourceMappingURL=Cursor.js.map diff --git a/dist/lib/Cursor.js.map b/dist/lib/Cursor.js.map index 4373ef0..054e708 100644 --- a/dist/lib/Cursor.js.map +++ b/dist/lib/Cursor.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/Cursor.ts"],"names":["Cursor","Cursor.constructor","Cursor.count","Cursor.forEach","Cursor.map","Cursor.toArray","Cursor.next","Cursor.one","Cursor.rewind","Cursor.sort","Cursor.limit","Cursor.skip","Cursor.readFrom"],"mappings":"AAGA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAGtC;;;;;;GAMG;AACH;IACIA;;;;;;OAMGA;IACHA,gBAAoBA,KAAkCA,EAAUA,UAAeA,EAASA,MAAsBA;QAA1FC,UAAKA,GAALA,KAAKA,CAA6BA;QAAUA,eAAUA,GAAVA,UAAUA,CAAKA;QAASA,WAAMA,GAANA,MAAMA,CAAgBA;IAE9GA,CAACA;IAEDD;;;;OAIGA;IACHA,sBAAKA,GAALA,UAAMA,QAAmCA;QAAzCE,iBAOCA;QANGA,MAAMA,CAACA,IAAIA,QAAQA,CAASA,UAACA,OAAOA,EAAEA,MAAMA;YACxCA,KAAIA,CAACA,MAAMA,CAACA,KAAKA,CAACA,IAAIA,EAACA,UAACA,GAAGA,EAAEA,KAAKA;gBAC9BA,EAAEA,CAACA,CAACA,GAAGA,CAACA;oBAACA,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;gBAC5BA,MAAMA,CAACA,OAAOA,CAAMA,KAAKA,CAACA,CAACA;YAC/BA,CAACA,CAACA,CAACA;QACPA,CAACA,CAACA,CAACA,OAAOA,CAACA,QAAQA,CAACA,CAACA;IACzBA,CAACA;IAEDF;;;;;OAKGA;IACHA,wBAAOA,GAAPA,UAAQA,OAAsCA,EAAEA,QAAiCA;QAAjFG,iBAUCA;QATGA,IAAIA,OAAOA,GAAGA,IAAIA,CAACA,KAAKA,CAACA,OAAOA,CAACA;QACjCA,MAAMA,CAACA,IA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AAcA,CAACA,CAACA,CAACA;IACrFA,CAACA;IAEDT;;;;OAIGA;IACHA,sBAAKA,GAALA,UAAMA,KAAaA;QACfU,MAAMA,CAACA,IAAIA,MAAMA,CAACA,IAAIA,CAACA,KAAKA,EAAEA,IAAIA,CAACA,UAAUA,EAAEA,IAAIA,CAACA,MAAMA,CAACA,KAAKA,CAACA,KAAKA,CAACA,CAACA,CAACA;IAC7EA,CAACA;IAEDV;;;;;OAKGA;IACHA,qBAAIA,GAAJA,UAAKA,IAAYA;QACbW,MAAMA,CAACA,IAAIA,MAAMA,CAACA,IAAIA,CAACA,KAAKA,EAAEA,IAAIA,CAACA,UAAUA,EAAEA,IAAIA,CAACA,MAAMA,CAACA,IAAIA,CAACA,IAAIA,CAACA,CAACA,CAACA;IAC3EA,CAACA;IAEDX;;;;OAIGA;IACHA,yBAAQA,GAARA,UAASA,IAAYA;QACjBY,MAAMA,CAACA,IAAIA,MAAMA,CAACA,IAAIA,CAACA,KAAKA,EAAEA,IAAIA,CAACA,UAAUA,EAAEA,IAAIA,CAACA,MAAMA,CAACA,iBAAiBA,CAACA,IAAIA,CAACA,CAACA,CAACA;IACxFA,CAACA;IACLZ,aAACA;AAADA,CAvKA,AAuKCA,IAAA;AAvKY,cAAM,SAuKlB,CAAA","file":"lib/Cursor.js","sourcesContent":["import {Model} from './Model';\r\nimport General = require('./General');\r\nimport MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\nimport * as Index from './Index';\r\n\r\n/**\r\n * An Iridium collection cursor which allows the itteration through documents\r\n * in the collection, automatically wrapping them in the correct instance type.\r\n *\r\n * @param TDocument The interface representing the collection's documents\r\n * @param TInstance The interface or class used to represent the wrapped documents.\r\n */\r\nexport class Cursor {\r\n /**\r\n * Creates a new Iridium cursor which wraps a MongoDB cursor object\r\n * @param {Model} model The Iridium model that this cursor belongs to\r\n * @param {Object} conditions The conditions that resulte in this cursor being created\r\n * @param {MongoDB.Cursor} cursor The MongoDB native cursor object to be wrapped\r\n * @constructor\r\n */\r\n constructor(private model: Model, private conditions: any, public cursor: MongoDB.Cursor) {\r\n\r\n }\r\n\r\n /**\r\n * Counts the number of documents which are matched by this cursor\r\n * @param {function(Error, Number)} callback A callback which is triggered when the result is available\r\n * @return {Promise} A promise which will resolve with the number of documents matched by this cursor\r\n */\r\n count(callback?: General.Callback): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.count(true,(err, count) => {\r\n if (err) return reject(err);\r\n return resolve(count);\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Runs the specified handler over each instance in the query results\r\n * @param {function(Instance)} handler The handler which is triggered for each element in the query\r\n * @param {function(Error)} callback A callback which is triggered when all operations have been dispatched\r\n * @return {Promise} A promise which is resolved when all operations have been dispatched\r\n */\r\n forEach(handler: (instance: TInstance) => void, callback?: General.Callback): Bluebird {\r\n var helpers = this.model.helpers;\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.forEach((item: TDocument) => {\r\n this.model.handlers.documentReceived(this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); }).then(handler);\r\n },(err) => {\r\n if (err) return reject(err);\r\n return resolve(null);\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Runs the specified transform over each instance in the query results and returns the resulting transformed objects\r\n * @param {function(Instance): TResult} transform A handler which is used to transform the result objects\r\n * @param {function(Error, TResult[])} callback A callback which is triggered when the transformations are completed\r\n * @return {Promise} A promise which is fulfilled with the results of the transformations\r\n */\r\n map(transform: (instance: TInstance) => TResult | Bluebird, callback?: General.Callback): Bluebird {\r\n var helpers = this.model.helpers;\r\n return new Bluebird((resolve, reject) => {\r\n var promises: Bluebird[] = [];\r\n this.cursor.forEach((item: TDocument) => {\r\n promises.push(this.model.handlers.documentReceived(this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); })\r\n .then(<(instance) => TResult>transform));\r\n },(err) => {\r\n if (err) return reject(err);\r\n return resolve(Bluebird.all(promises));\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Retrieves all matching instances and returns them in an array\r\n * @param {function(Error, TInstance[])} callback A callback which is triggered with the resulting instances\r\n * @return {Promise} A promise which resolves with the instances returned by the query\r\n */\r\n toArray(callback?: General.Callback): Bluebird {\r\n var helpers = this.model.helpers;\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.toArray((err, results: any[]) => {\r\n if (err) return reject(err);\r\n return resolve(results);\r\n });\r\n }).map((document) => {\r\n return this.model.handlers.documentReceived(this.conditions, document, function () { return helpers.wrapDocument.apply(helpers, arguments); });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Retrieves the next item in the results list\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the next item becomes available\r\n * @return {Promise} A promise which is resolved with the next item\r\n */\r\n next(callback?: General.Callback): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.next((err, result: any) => {\r\n if (err) return reject(err);\r\n return resolve(result);\r\n });\r\n }).then((document) => {\r\n if (!document) return Bluebird.resolve(null);\r\n return this.model.handlers.documentReceived(this.conditions, document,(document, isNew?, isPartial?) => this.model.helpers.wrapDocument(document, isNew, isPartial));\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Retrieves the next item in the result list and then closes the cursor\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the next item becomes available\r\n * @return {Promise} A promise which is resolved once the item becomes available and the cursor has been closed.\r\n */\r\n one(callback?: General.Callback): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.next((err, result: any) => {\r\n if (err) return reject(err);\r\n return resolve(result);\r\n });\r\n }).then((document) => {\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.close((err) => {\r\n if (err) return reject(err);\r\n return resolve(document);\r\n });\r\n });\r\n }).then((document) => {\r\n if (!document) return Bluebird.resolve(null);\r\n return this.model.handlers.documentReceived(this.conditions, document,(document, isNew?, isPartial?) => this.model.helpers.wrapDocument(document, isNew, isPartial));\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Returns a new cursor which behaves the same as this one did before any results were retrieved\r\n * @return {Cursor} The new cursor which starts at the beginning of the results\r\n */\r\n rewind(): Cursor {\r\n this.cursor.rewind();\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new cursor which sorts its results by the given index expression\r\n * @param {model.IndexSpecification} sortExpression The index expression dictating the sort order and direction to use\r\n * @return {Cursor} The new cursor which sorts its results by the sortExpression\r\n */\r\n sort(sortExpression: Index.IndexSpecification): Cursor {\r\n return new Cursor(this.model, this.conditions, this.cursor.sort(sortExpression));\r\n }\r\n\r\n /**\r\n * Returns a new cursor which limits the number of returned results\r\n * @param {Number} limit The maximum number of results to return\r\n * @return {Cursor} The new cursor which will return a maximum number of results\r\n */\r\n limit(limit: number): Cursor {\r\n return new Cursor(this.model, this.conditions, this.cursor.limit(limit));\r\n }\r\n\r\n /**\r\n * Returns a new cursor which skips a number of results before it begins\r\n * returning any.\r\n * @param {Number} skip The number of results to skip before the cursor beings returning\r\n * @return {Cursor} The new cursor which skips a number of results\r\n */\r\n skip(skip: number): Cursor {\r\n return new Cursor(this.model, this.conditions, this.cursor.skip(skip));\r\n }\r\n\r\n /**\r\n * Returns a new cursor which will read from the specified node type.\r\n * @param {String} type The type of node to read from - see https://docs.mongodb.org/manual/core/read-preference/\r\n * @return {Cursor} The new cursor which reads from the specified node type\r\n */\r\n readFrom(type: string): Cursor {\r\n return new Cursor(this.model, this.conditions, this.cursor.setReadPreference(type));\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/Cursor.ts"],"names":[],"mappings":";AAGA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAGtC;;;;;;GAMG;AACH;IACI;;;;;;OAMG;IACH,gBAAoB,KAAkC,EAAU,UAAe,EAAS,MAAsB;QAA1F,UAAK,GAAL,KAAK,CAA6B;QAAU,eAAU,GAAV,UAAU,CAAK;QAAS,WAAM,GAAN,MAAM,CAAgB;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IAED;;;;OAIG;IACH,qBAAI,GAAJ,UAAK,cAAwC;QACzC,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACH,sBAAK,GAAL,UAAM,KAAa;QACf,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED;;;;;OAKG;IACH,qBAAI,GAAJ,UAAK,IAAY;QACb,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;;;OAIG;IACH,yBAAQ,GAAR,UAAS,IAAY;QACjB,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IACxF,CAAC;IACL,aAAC;AAAD,CAvKA,AAuKC,IAAA;AAvKY,cAAM,SAuKlB,CAAA","file":"lib/Cursor.js","sourcesContent":["import {Model} from './Model';\r\nimport General = require('./General');\r\nimport MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\nimport * as Index from './Index';\r\n\r\n/**\r\n * An Iridium collection cursor which allows the itteration through documents\r\n * in the collection, automatically wrapping them in the correct instance type.\r\n *\r\n * @param TDocument The interface representing the collection's documents\r\n * @param TInstance The interface or class used to represent the wrapped documents.\r\n */\r\nexport class Cursor {\r\n /**\r\n * Creates a new Iridium cursor which wraps a MongoDB cursor object\r\n * @param {Model} model The Iridium model that this cursor belongs to\r\n * @param {Object} conditions The conditions that resulte in this cursor being created\r\n * @param {MongoDB.Cursor} cursor The MongoDB native cursor object to be wrapped\r\n * @constructor\r\n */\r\n constructor(private model: Model, private conditions: any, public cursor: MongoDB.Cursor) {\r\n\r\n }\r\n\r\n /**\r\n * Counts the number of documents which are matched by this cursor\r\n * @param {function(Error, Number)} callback A callback which is triggered when the result is available\r\n * @return {Promise} A promise which will resolve with the number of documents matched by this cursor\r\n */\r\n count(callback?: General.Callback): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.count(true,(err, count) => {\r\n if (err) return reject(err);\r\n return resolve(count);\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Runs the specified handler over each instance in the query results\r\n * @param {function(Instance)} handler The handler which is triggered for each element in the query\r\n * @param {function(Error)} callback A callback which is triggered when all operations have been dispatched\r\n * @return {Promise} A promise which is resolved when all operations have been dispatched\r\n */\r\n forEach(handler: (instance: TInstance) => void, callback?: General.Callback): Bluebird {\r\n var helpers = this.model.helpers;\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.forEach((item: TDocument) => {\r\n this.model.handlers.documentReceived(this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); }).then(handler);\r\n },(err) => {\r\n if (err) return reject(err);\r\n return resolve(null);\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Runs the specified transform over each instance in the query results and returns the resulting transformed objects\r\n * @param {function(Instance): TResult} transform A handler which is used to transform the result objects\r\n * @param {function(Error, TResult[])} callback A callback which is triggered when the transformations are completed\r\n * @return {Promise} A promise which is fulfilled with the results of the transformations\r\n */\r\n map(transform: (instance: TInstance) => TResult | Bluebird, callback?: General.Callback): Bluebird {\r\n var helpers = this.model.helpers;\r\n return new Bluebird((resolve, reject) => {\r\n var promises: Bluebird[] = [];\r\n this.cursor.forEach((item: TDocument) => {\r\n promises.push(this.model.handlers.documentReceived(this.conditions, item, function () { return helpers.wrapDocument.apply(helpers, arguments); })\r\n .then(<(instance) => TResult>transform));\r\n },(err) => {\r\n if (err) return reject(err);\r\n return resolve(Bluebird.all(promises));\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Retrieves all matching instances and returns them in an array\r\n * @param {function(Error, TInstance[])} callback A callback which is triggered with the resulting instances\r\n * @return {Promise} A promise which resolves with the instances returned by the query\r\n */\r\n toArray(callback?: General.Callback): Bluebird {\r\n var helpers = this.model.helpers;\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.toArray((err, results: any[]) => {\r\n if (err) return reject(err);\r\n return resolve(results);\r\n });\r\n }).map((document) => {\r\n return this.model.handlers.documentReceived(this.conditions, document, function () { return helpers.wrapDocument.apply(helpers, arguments); });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Retrieves the next item in the results list\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the next item becomes available\r\n * @return {Promise} A promise which is resolved with the next item\r\n */\r\n next(callback?: General.Callback): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.next((err, result: any) => {\r\n if (err) return reject(err);\r\n return resolve(result);\r\n });\r\n }).then((document) => {\r\n if (!document) return Bluebird.resolve(null);\r\n return this.model.handlers.documentReceived(this.conditions, document,(document, isNew?, isPartial?) => this.model.helpers.wrapDocument(document, isNew, isPartial));\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Retrieves the next item in the result list and then closes the cursor\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the next item becomes available\r\n * @return {Promise} A promise which is resolved once the item becomes available and the cursor has been closed.\r\n */\r\n one(callback?: General.Callback): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.next((err, result: any) => {\r\n if (err) return reject(err);\r\n return resolve(result);\r\n });\r\n }).then((document) => {\r\n return new Bluebird((resolve, reject) => {\r\n this.cursor.close((err) => {\r\n if (err) return reject(err);\r\n return resolve(document);\r\n });\r\n });\r\n }).then((document) => {\r\n if (!document) return Bluebird.resolve(null);\r\n return this.model.handlers.documentReceived(this.conditions, document,(document, isNew?, isPartial?) => this.model.helpers.wrapDocument(document, isNew, isPartial));\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Returns a new cursor which behaves the same as this one did before any results were retrieved\r\n * @return {Cursor} The new cursor which starts at the beginning of the results\r\n */\r\n rewind(): Cursor {\r\n this.cursor.rewind();\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns a new cursor which sorts its results by the given index expression\r\n * @param {model.IndexSpecification} sortExpression The index expression dictating the sort order and direction to use\r\n * @return {Cursor} The new cursor which sorts its results by the sortExpression\r\n */\r\n sort(sortExpression: Index.IndexSpecification): Cursor {\r\n return new Cursor(this.model, this.conditions, this.cursor.sort(sortExpression));\r\n }\r\n\r\n /**\r\n * Returns a new cursor which limits the number of returned results\r\n * @param {Number} limit The maximum number of results to return\r\n * @return {Cursor} The new cursor which will return a maximum number of results\r\n */\r\n limit(limit: number): Cursor {\r\n return new Cursor(this.model, this.conditions, this.cursor.limit(limit));\r\n }\r\n\r\n /**\r\n * Returns a new cursor which skips a number of results before it begins\r\n * returning any.\r\n * @param {Number} skip The number of results to skip before the cursor beings returning\r\n * @return {Cursor} The new cursor which skips a number of results\r\n */\r\n skip(skip: number): Cursor {\r\n return new Cursor(this.model, this.conditions, this.cursor.skip(skip));\r\n }\r\n\r\n /**\r\n * Returns a new cursor which will read from the specified node type.\r\n * @param {String} type The type of node to read from - see https://docs.mongodb.org/manual/core/read-preference/\r\n * @return {Cursor} The new cursor which reads from the specified node type\r\n */\r\n readFrom(type: string): Cursor {\r\n return new Cursor(this.model, this.conditions, this.cursor.setReadPreference(type));\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/Decorators.js b/dist/lib/Decorators.js index c87d87c..d11b9b4 100644 --- a/dist/lib/Decorators.js +++ b/dist/lib/Decorators.js @@ -1,3 +1,4 @@ +"use strict"; var MongoDB = require('mongodb'); var _ = require('lodash'); var Skmatc = require('skmatc'); diff --git a/dist/lib/Decorators.js.map b/dist/lib/Decorators.js.map index 0dd580f..312a488 100644 --- a/dist/lib/Decorators.js.map +++ b/dist/lib/Decorators.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/Decorators.ts"],"names":["Collection","Index","Validate","Property","Transform","ObjectID","Binary"],"mappings":"AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAMlC,2BAA4C,cAAc,CAAC,CAAA;AAE3D;;;;;;;GAOG;AACH,oBAA2B,IAAY;IACtCA,MAAMA,CAACA,UAASA,MAAwCA;QACvD,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;IAC1B,CAAC,CAACA;AACHA,CAACA;AAJe,kBAAU,aAIzB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAsB,IAAwB,EAAE,OAA8B;IAC7EC,MAAMA,CAACA,UAASA,MAAuCA;QACtD,MAAM,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC,CAAC;IAC/F,CAAC,CAAAA;AACFA,CAACA;AAJe,aAAK,QAIpB,CAAA;AAED;;;;;;;;;GASG;AACH,kBAAyB,OAAY,EAAE,QAAiE;IACvGC,MAAMA,CAACA,UAASA,MAAuCA;QACtD,MAAM,CAAC,UAAU,GAAG,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAA,MAAM,IAAI,OAAA,MAAM,KAAK,OAAO,EAAlB,CAAkB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7G,CAAC,CAAAA;AACFA,CAACA;AAJe,gBAAQ,WAIvB,CAAA;AAoBD;IAAyBC,cAAcA;SAAdA,WAAcA,C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AAEA,QAA8BA;QAA9B,wBAA8B,GAA9B,sBAA8B;QACzE,IAAI,YAAY,GAAuE,CAAC,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,CAAC;QAEtH,YAAY,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,IAAgB,EAAE,CAAC,CAAA;QAC5E,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG;YACnC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;SACV,CAAC;IACH,CAAC,CAACA;AACHA,CAACA;AAVe,iBAAS,YAUxB,CAAA;AAGD;;;;;;GAMG;AACH,kBAAyB,MAA0B,EAAE,IAAY;IAChEC,QAAQA,CAACA,OAAOA,CAACA,QAAQA,CAACA,CAACA,MAAMA,EAAEA,IAAIA,CAACA,CAACA;IACzCA,SAASA,CACRA,8BAAiBA,CAACA,QAAQA,CAACA,MAAMA,EACjCA,8BAAiBA,CAACA,QAAQA,CAACA,IAAIA,CAC/BA,CAACA,MAAMA,EAAEA,IAAIA,CAACA,CAACA;AACjBA,CAACA;AANe,gBAAQ,WAMvB,CAAA;AAED;;;;;;;GAOG;AACH,gBAAuB,MAA0B,EAAE,IAAY;IAC9DC,QAAQA,CAACA,MAAMA,CAACA,CAACA,MAAMA,EAAEA,IAAIA,CAACA,CAACA;IAC/BA,SAASA,CACRA,8BAAiBA,CAACA,MAAMA,CAACA,MAAMA,EAC/BA,8BAAiBA,CAACA,MAAMA,CAACA,IAAIA,CAC7BA,CAACA,MAAMA,EAAEA,IAAIA,CAACA,CAACA;AACjBA,CAACA;AANe,cAAM,SAMrB,CAAA","file":"lib/Decorators.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport _ = require('lodash');\r\nimport Skmatc = require('skmatc');\r\nimport {Instance} from './Instance';\r\nimport {Model} from './Model';\r\nimport {Index, IndexSpecification} from './Index';\r\nimport {Schema} from './Schema';\r\nimport {InstanceImplementation} from './InstanceInterface';\r\nimport {Transforms, DefaultTransforms} from './Transforms';\r\n\r\n/**\r\n * Specifies the name of the collection to which this instance's documents should be sent.\r\n * @param name The name of the MongoDB collection to store the documents in.\r\n *\r\n * This decorator replaces the use of the static collection property on instance implementation\r\n * classes. If your transpiler does not support decorators then you are free to make use of the\r\n * property instead.\r\n */\r\nexport function Collection(name: string) {\r\n\treturn function(target: InstanceImplementation) {\r\n\t\ttarget.collection = name;\r\n\t};\r\n}\r\n\r\n/**\r\n * Specifies a MongoDB collection level index to be managed by Iridium for this instance type.\r\n * More than one instance of this decorator may be used if you wish to specify multiple indexes.\r\n * @param spec The formal index specification which defines the properties and ordering used in the index.\r\n * @param options The options dictating the way in which the index behaves.\r\n *\r\n * This decorator replaces the use of the static indexes property on instance implementation\r\n * classes. If your transpiler does not support decorators then you are free to make use of the\r\n * property instead.\r\n */\r\nexport function Index(spec: IndexSpecification, options?: MongoDB.IndexOptions) {\r\n\treturn function(target: InstanceImplementation) {\r\n\t\ttarget.indexes = (target.indexes || []).concat({ spec: spec, options: options || {} });\r\n\t}\r\n}\r\n\r\n/**\r\n * Specifies a custom validator to be made available for this collection's schema.\r\n * More than one instance of this decorator may be used if you wish to specify multiple validators.\r\n * @param forType The value in the schema which will be delegated to this function for validation.\r\n * @param validate A function which calls this.assert(condition) to determine whether a schema node is valid or not.\r\n *\r\n * This decorator replaces the use of the static validators property on instance implementation\r\n * classes. If your transpiler does not support decorators then you are free to make use of the\r\n * property instead.\r\n */\r\nexport function Validate(forType: any, validate: (schema: any, data: any, path: string) => Skmatc.Result) {\r\n\treturn function(target: InstanceImplementation) {\r\n\t\ttarget.validators = (target.validators || []).concat(Skmatc.create(schema => schema === forType, validate));\r\n\t}\r\n}\r\n\r\n/**\r\n * Specifies the schema type for the property this decorator is applied to. This can be used to replace the\r\n * static schema property on your instance. Multiple instances of this decorator can be applied, but no more\r\n * than one per property.\r\n *\r\n * @param asType The schema validation type to make use of for this property\r\n * @param required Whether this property is required to have a value or not, defaults to true.\r\n */\r\nexport function Property(asType: any, required?: boolean): (target: Instance, name: string) => void;\r\n/**\r\n * Specifies the schema type for a property with the given name on the class this decorator is applied to. This\r\n * can either compliment or replace the static schema property on your instance class.\r\n *\r\n * @param name The name of the property that is being targetted\r\n * @param asType The schema validation type to make use of for this property\r\n * @param required Whether this property is required to have a value or not, defaults to true.\r\n */\r\nexport function Property(name: string, asType: any, required?: boolean): (target: InstanceImplementation) => void;\r\nexport function Property(...args: any[]): (target: Instance | InstanceImplementation, name?: string) => void {\r\n\tlet name = null,\r\n\t\tasType = false,\r\n\t\trequired = true;\r\n\r\n\tif (args.length > 1 && typeof args[args.length - 1] === 'boolean')\r\n\t\trequired = args.pop();\r\n\r\n\treturn function(target: InstanceImplementation, property?: string) {\r\n\t\tlet staticTarget: InstanceImplementation = target;\r\n\t\tif (!property) name = args.shift();\r\n\t\telse {\r\n\t\t\tname = property;\r\n\t\t\tstaticTarget = >target.constructor;\r\n\t\t}\r\n\t\tasType = args.pop() || false;\r\n\r\n\t\tstaticTarget.schema = _.clone(staticTarget.schema || { _id: false });\r\n\t\tif(!required && typeof asType !== 'boolean') staticTarget.schema[name] = { $required: required, $type: asType };\r\n\t\telse staticTarget.schema[name] = asType;\r\n\t}\r\n}\r\n\r\n/**\r\n * Specifies a custom transform to be applied to the property this decorator is applied to.\r\n *\r\n * @param fromDB The function used to convert values from the database for the application.\r\n * @param toDB The function used to convert values from the application to the form used in the database.\r\n *\r\n * This decorator can either compliment or replace the static transforms property on your instance\r\n * class, however only one transform can be applied to any property at a time.\r\n * If your transpiler does not support decorators then you are free to make use of the\r\n * property instead.\r\n * \r\n * If this decorator is applied to the instance class itself, as opposed to a property, then\r\n * it will be treated as a $document transformer - and will receive the full document as opposed\r\n * to individual property values. Similarly, it is expected to return a full document when either\r\n * fromDB or toDB is called.\r\n */\r\nexport function Transform(fromDB: (value: any, property: string, model: Model) => any, toDB: (value: any, property: string, model: Model) => any) {\r\n\treturn function(target: Instance, property: string = '$document') {\r\n\t\tlet staticTarget: InstanceImplementation = >(target.constructor || target);\r\n\r\n\t\tstaticTarget.transforms = _.clone(staticTarget.transforms || {})\r\n\t\tstaticTarget.transforms[property] = {\r\n\t\t\tfromDB: fromDB,\r\n\t\t\ttoDB: toDB\r\n\t\t};\r\n\t};\r\n}\r\n\r\n\r\n/**\r\n * Specifies that this property should be treated as an ObjectID, with the requisite validator and transforms.\r\n *\r\n * This decorator applies an ObjectID validator to the property, which ensures that values sent to the database\r\n * are instances of the MongoDB ObjectID type, as well as applying a transform operation which converts ObjectIDs\r\n * to strings for your application, and then converts strings back to ObjectIDs for the database.\r\n */\r\nexport function ObjectID(target: Instance, name: string) {\r\n\tProperty(MongoDB.ObjectID)(target, name);\r\n\tTransform(\r\n\t\tDefaultTransforms.ObjectID.fromDB,\r\n\t\tDefaultTransforms.ObjectID.toDB\r\n\t)(target, name);\r\n}\r\n\r\n/**\r\n * Specifies that this property should be stored using the MongoDB binary type and represented as a Buffer.\r\n * \r\n * This decorator applies a Buffer validator to the property, which ensures that values you send to the database\r\n * are well formatted Buffer objects represented using the BSON Binary datatype. In addition to this, it will\r\n * apply a transform which ensures you only work with Buffer objects and that data is always stored in Binary\r\n * format.\r\n */\r\nexport function Binary(target: Instance, name: string) {\r\n\tProperty(Buffer)(target, name);\r\n\tTransform(\r\n\t\tDefaultTransforms.Binary.fromDB,\r\n\t\tDefaultTransforms.Binary.toDB\r\n\t)(target, name);\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/Decorators.ts"],"names":[],"mappings":";AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAMlC,2BAA4C,cAAc,CAAC,CAAA;AAE3D;;;;;;;GAOG;AACH,oBAA2B,IAAY;IACtC,MAAM,CAAC,UAAS,MAAwC;QACvD,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;IAC1B,CA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MAAM,EACjC,8BAAiB,CAAC,QAAQ,CAAC,IAAI,CAC/B,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACjB,CAAC;AANe,gBAAQ,WAMvB,CAAA;AAED;;;;;;;GAOG;AACH,gBAAuB,MAA0B,EAAE,IAAY;IAC9D,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/B,SAAS,CACR,8BAAiB,CAAC,MAAM,CAAC,MAAM,EAC/B,8BAAiB,CAAC,MAAM,CAAC,IAAI,CAC7B,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACjB,CAAC;AANe,cAAM,SAMrB,CAAA","file":"lib/Decorators.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport _ = require('lodash');\r\nimport Skmatc = require('skmatc');\r\nimport {Instance} from './Instance';\r\nimport {Model} from './Model';\r\nimport {Index, IndexSpecification} from './Index';\r\nimport {Schema} from './Schema';\r\nimport {InstanceImplementation} from './InstanceInterface';\r\nimport {Transforms, DefaultTransforms} from './Transforms';\r\n\r\n/**\r\n * Specifies the name of the collection to which this instance's documents should be sent.\r\n * @param name The name of the MongoDB collection to store the documents in.\r\n *\r\n * This decorator replaces the use of the static collection property on instance implementation\r\n * classes. If your transpiler does not support decorators then you are free to make use of the\r\n * property instead.\r\n */\r\nexport function Collection(name: string) {\r\n\treturn function(target: InstanceImplementation) {\r\n\t\ttarget.collection = name;\r\n\t};\r\n}\r\n\r\n/**\r\n * Specifies a MongoDB collection level index to be managed by Iridium for this instance type.\r\n * More than one instance of this decorator may be used if you wish to specify multiple indexes.\r\n * @param spec The formal index specification which defines the properties and ordering used in the index.\r\n * @param options The options dictating the way in which the index behaves.\r\n *\r\n * This decorator replaces the use of the static indexes property on instance implementation\r\n * classes. If your transpiler does not support decorators then you are free to make use of the\r\n * property instead.\r\n */\r\nexport function Index(spec: IndexSpecification, options?: MongoDB.IndexOptions) {\r\n\treturn function(target: InstanceImplementation) {\r\n\t\ttarget.indexes = (target.indexes || []).concat({ spec: spec, options: options || {} });\r\n\t}\r\n}\r\n\r\n/**\r\n * Specifies a custom validator to be made available for this collection's schema.\r\n * More than one instance of this decorator may be used if you wish to specify multiple validators.\r\n * @param forType The value in the schema which will be delegated to this function for validation.\r\n * @param validate A function which calls this.assert(condition) to determine whether a schema node is valid or not.\r\n *\r\n * This decorator replaces the use of the static validators property on instance implementation\r\n * classes. If your transpiler does not support decorators then you are free to make use of the\r\n * property instead.\r\n */\r\nexport function Validate(forType: any, validate: (schema: any, data: any, path: string) => Skmatc.Result) {\r\n\treturn function(target: InstanceImplementation) {\r\n\t\ttarget.validators = (target.validators || []).concat(Skmatc.create(schema => schema === forType, validate));\r\n\t}\r\n}\r\n\r\n/**\r\n * Specifies the schema type for the property this decorator is applied to. This can be used to replace the\r\n * static schema property on your instance. Multiple instances of this decorator can be applied, but no more\r\n * than one per property.\r\n *\r\n * @param asType The schema validation type to make use of for this property\r\n * @param required Whether this property is required to have a value or not, defaults to true.\r\n */\r\nexport function Property(asType: any, required?: boolean): (target: Instance, name: string) => void;\r\n/**\r\n * Specifies the schema type for a property with the given name on the class this decorator is applied to. This\r\n * can either compliment or replace the static schema property on your instance class.\r\n *\r\n * @param name The name of the property that is being targetted\r\n * @param asType The schema validation type to make use of for this property\r\n * @param required Whether this property is required to have a value or not, defaults to true.\r\n */\r\nexport function Property(name: string, asType: any, required?: boolean): (target: InstanceImplementation) => void;\r\nexport function Property(...args: any[]): (target: Instance | InstanceImplementation, name?: string) => void {\r\n\tlet name = null,\r\n\t\tasType = false,\r\n\t\trequired = true;\r\n\r\n\tif (args.length > 1 && typeof args[args.length - 1] === 'boolean')\r\n\t\trequired = args.pop();\r\n\r\n\treturn function(target: InstanceImplementation, property?: string) {\r\n\t\tlet staticTarget: InstanceImplementation = target;\r\n\t\tif (!property) name = args.shift();\r\n\t\telse {\r\n\t\t\tname = property;\r\n\t\t\tstaticTarget = >target.constructor;\r\n\t\t}\r\n\t\tasType = args.pop() || false;\r\n\r\n\t\tstaticTarget.schema = _.clone(staticTarget.schema || { _id: false });\r\n\t\tif(!required && typeof asType !== 'boolean') staticTarget.schema[name] = { $required: required, $type: asType };\r\n\t\telse staticTarget.schema[name] = asType;\r\n\t}\r\n}\r\n\r\n/**\r\n * Specifies a custom transform to be applied to the property this decorator is applied to.\r\n *\r\n * @param fromDB The function used to convert values from the database for the application.\r\n * @param toDB The function used to convert values from the application to the form used in the database.\r\n *\r\n * This decorator can either compliment or replace the static transforms property on your instance\r\n * class, however only one transform can be applied to any property at a time.\r\n * If your transpiler does not support decorators then you are free to make use of the\r\n * property instead.\r\n * \r\n * If this decorator is applied to the instance class itself, as opposed to a property, then\r\n * it will be treated as a $document transformer - and will receive the full document as opposed\r\n * to individual property values. Similarly, it is expected to return a full document when either\r\n * fromDB or toDB is called.\r\n */\r\nexport function Transform(fromDB: (value: any, property: string, model: Model) => any, toDB: (value: any, property: string, model: Model) => any) {\r\n\treturn function(target: Instance, property: string = '$document') {\r\n\t\tlet staticTarget: InstanceImplementation = >(target.constructor || target);\r\n\r\n\t\tstaticTarget.transforms = _.clone(staticTarget.transforms || {})\r\n\t\tstaticTarget.transforms[property] = {\r\n\t\t\tfromDB: fromDB,\r\n\t\t\ttoDB: toDB\r\n\t\t};\r\n\t};\r\n}\r\n\r\n\r\n/**\r\n * Specifies that this property should be treated as an ObjectID, with the requisite validator and transforms.\r\n *\r\n * This decorator applies an ObjectID validator to the property, which ensures that values sent to the database\r\n * are instances of the MongoDB ObjectID type, as well as applying a transform operation which converts ObjectIDs\r\n * to strings for your application, and then converts strings back to ObjectIDs for the database.\r\n */\r\nexport function ObjectID(target: Instance, name: string) {\r\n\tProperty(MongoDB.ObjectID)(target, name);\r\n\tTransform(\r\n\t\tDefaultTransforms.ObjectID.fromDB,\r\n\t\tDefaultTransforms.ObjectID.toDB\r\n\t)(target, name);\r\n}\r\n\r\n/**\r\n * Specifies that this property should be stored using the MongoDB binary type and represented as a Buffer.\r\n * \r\n * This decorator applies a Buffer validator to the property, which ensures that values you send to the database\r\n * are well formatted Buffer objects represented using the BSON Binary datatype. In addition to this, it will\r\n * apply a transform which ensures you only work with Buffer objects and that data is always stored in Binary\r\n * format.\r\n */\r\nexport function Binary(target: Instance, name: string) {\r\n\tProperty(Buffer)(target, name);\r\n\tTransform(\r\n\t\tDefaultTransforms.Binary.fromDB,\r\n\t\tDefaultTransforms.Binary.toDB\r\n\t)(target, name);\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/General.js b/dist/lib/General.js index 8fd2e3c..9468606 100644 --- a/dist/lib/General.js +++ b/dist/lib/General.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=General.js.map diff --git a/dist/lib/Hooks.js b/dist/lib/Hooks.js index d85dcbf..2244236 100644 --- a/dist/lib/Hooks.js +++ b/dist/lib/Hooks.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=Hooks.js.map diff --git a/dist/lib/Index.js b/dist/lib/Index.js index 632e5c0..0276118 100644 --- a/dist/lib/Index.js +++ b/dist/lib/Index.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=Index.js.map diff --git a/dist/lib/Instance.js b/dist/lib/Instance.js index 82a48ec..e88cc1c 100644 --- a/dist/lib/Instance.js +++ b/dist/lib/Instance.js @@ -1,3 +1,4 @@ +"use strict"; var Validators_1 = require('./Validators'); var _ = require('lodash'); var Bluebird = require('bluebird'); @@ -273,7 +274,7 @@ var Instance = (function () { */ Instance.indexes = []; return Instance; -})(); +}()); exports.Instance = Instance; //# sourceMappingURL=Instance.js.map diff --git a/dist/lib/Instance.js.map b/dist/lib/Instance.js.map index 59cecf8..cd4fdec 100644 --- a/dist/lib/Instance.js.map +++ b/dist/lib/Instance.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/Instance.ts"],"names":["Instance","Instance.constructor","Instance.document","Instance.save","Instance.update","Instance.refresh","Instance.delete","Instance.remove","Instance.first","Instance.select","Instance.toJSON","Instance.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OAAOA,GAAGA,KAAKA,CAACA,OAAOA,CAACA,UAAUA,CAACA,CAACA;QACxCA,IAAIA,OAAOA,GAAQA,OAAOA,GAAGA,EAAEA,GAAGA,EAAEA,CAACA;QAErCA,CAACA,CAACA,IAAIA,CAACA,UAAUA,EAACA,UAACA,KAAQA,EAAEA,GAAGA;YAC5BA,EAAEA,CAACA,CAACA,SAASA,CAACA,IAAIA,CAACA,KAAIA,EAAEA,KAAKA,EAAEA,GAAGA,CAACA,CAACA,CAACA,CAACA;gBACnCA,EAAEA,CAACA,CAACA,OAAOA,CAACA;oBAACA,OAAOA,CAACA,IAAIA,CAACA,KAAKA,CAACA,CAACA;gBACjCA,IAAIA;oBAACA,OAAOA,CAACA,GAAGA,CAACA,GAAGA,KAAKA,CAACA;YAC9BA,CAACA;QACLA,CAACA,CAACA,CAACA;QAEHA,MAAMA,CAACA,OAAOA,CAACA;IACnBA,CAACA;IAEDT;;;OAGGA;IACHA,yBAAMA,GAANA;QACIU,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IAEDV;;;OAGGA;IACHA,2BAAQA,GAARA;QACIW,MAAMA,CAACA,IAAIA,CAACA,SAASA,CAACA,IAAIA,CAACA,QAAQA,EAAEA,IAAIA,EAAEA,CAACA,CAACA,CAACA;IAClDA,CAACA;IA7RDX;;OAEGA;IACIA,eAAMA,GAAWA;QACpBA,GAAGA,EAAEA,KAAKA;KACbA,CAACA;IAEFA;;OAEGA;IACIA,mBAAUA,GAAuBA,8BAAiBA,EAAEA,CAACA;IAE5DA;;OAEGA;IACIA,mBAAUA,GAAeA,EAE/BA,CAACA;IAOFA;;OAEGA;IACIA,gBAAOA,GAA+CA,EAAEA,CAACA;IAmQpEA,eAACA;AAADA,CApWA,AAoWCA,IAAA;AApWY,gBAAQ,WAoWpB,CAAA","file":"lib/Instance.js","sourcesContent":["import {Core} from './Core';\r\nimport {Model} from './Model';\r\nimport {Plugin} from './Plugins';\r\nimport {CacheDirector} from './CacheDirector';\r\nimport * as General from './General';\r\nimport * as ModelInterfaces from './ModelInterfaces';\r\nimport * as Index from './Index';\r\nimport {Schema} from './Schema';\r\nimport {Transforms} from './Transforms';\r\nimport {DefaultValidators} from './Validators';\r\n\r\nimport _ = require('lodash');\r\nimport MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\nimport Skmatc = require('skmatc');\r\n\r\n/**\r\n * The default Iridium Instance implementation which provides methods for saving, refreshing and\r\n * removing the wrapped document from the collection, as well as integrating with Omnom, our\r\n * built in document diff processor which allows clean, atomic, document updates to be performed\r\n * without needing to write the update queries yourself.\r\n *\r\n * @param TDocument The interface representing the structure of the documents in the collection.\r\n * @param TInstance The type of instance which wraps the documents, generally the subclass of this class.\r\n *\r\n * This class will be subclassed automatically by Iridium to create a model specific instance\r\n * which takes advantage of some of v8's optimizations to boost performance significantly.\r\n * The instance returned by the model, and all of this instance's methods, will be of type\r\n * TInstance - which should represent the merger of TSchema and IInstance for best results.\r\n */\r\nexport class Instance {\r\n /**\r\n * Creates a new instance which represents the given document as a type of model\r\n * @param model The model that dictates the collection the document originated from as well as how validations are performed.\r\n * @param document The document which should be wrapped by this instance\r\n * @param isNew Whether the document is new (doesn't exist in the database) or not\r\n * @param isPartial Whether the document has only a subset of its fields populated\r\n *\r\n */\r\n constructor(model: Model, document: TDocument, isNew: boolean = true, isPartial: boolean = false) {\r\n this._model = model;\r\n\r\n this._isNew = !!isNew;\r\n this._isPartial = isPartial;\r\n this._original = document;\r\n this._modified = model.helpers.cloneDocument(document);\r\n\r\n _.each(model.core.plugins,(plugin: Plugin) => {\r\n if (plugin.newInstance) plugin.newInstance(this, model);\r\n });\r\n }\r\n\r\n private _isNew: boolean;\r\n private _isPartial: boolean;\r\n private _model: Model;\r\n private _original: TDocument;\r\n private _modified: TDocument;\r\n\r\n /**\r\n * Gets the underlying document representation of this instance\r\n */\r\n get document(): TDocument {\r\n return this._modified;\r\n }\r\n\r\n [name: string]: any;\r\n\r\n /**\r\n * A function which is called whenever a new document is in the process of being inserted into the database.\r\n * @param document The document which will be inserted into the database.\r\n */\r\n static onCreating: (document: { _id?: any }) => Promise.Thenable | void;\r\n\r\n /**\r\n * A function which is called whenever a document of this type is received from the database, prior to it being\r\n * wrapped by an Instance object.\r\n * @param document The document that was retrieved from the database.\r\n */\r\n static onRetrieved: (document: { _id?: any }) => Promise.Thenable | void;\r\n\r\n /**\r\n * A function which is called whenever a new instance has been created to wrap a document.\r\n * @param instance The instance which has been created.\r\n */\r\n static onReady: (instance: Instance<{ _id?: any }, Instance<{ _id?: any }, any>>) => Promise.Thenable | void;\r\n\r\n /**\r\n * A function which is called whenever an instance's save() method is called to allow you to interrogate and/or manipulate\r\n * the changes which are being made.\r\n *\r\n * @param instance The instance to which the changes are being made\r\n * @param changes The MongoDB change object describing the changes being made to the document.\r\n */\r\n static onSaving: (instance: Instance<{ _id?: any }, Instance<{ _id?: any }, any>>, changes: any) => Promise.Thenable | void;\r\n\r\n /**\r\n * The name of the collection into which documents of this type are stored.\r\n */\r\n static collection: string;\r\n\r\n /**\r\n * The schema used to validate documents of this type before being stored in the database.\r\n */\r\n static schema: Schema = {\r\n _id: false\r\n };\r\n\r\n /**\r\n * Additional which should be made available for use in the schema definition for this instance.\r\n */\r\n static validators: Skmatc.Validator[] = DefaultValidators();\r\n\r\n /**\r\n * The transformations which should be applied to properties of documents of this type.\r\n */\r\n static transforms: Transforms = {\r\n\r\n };\r\n\r\n /**\r\n * The cache director used to derive unique cache keys for documents of this type.\r\n */\r\n static cache: CacheDirector;\r\n\r\n /**\r\n * The indexes which should be managed by Iridium for the collection used by this type.\r\n */\r\n static indexes: (Index.Index | Index.IndexSpecification)[] = [];\r\n\r\n /**\r\n * Saves any changes to this instance, using the built in diff algorithm to write the update query.\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes\r\n * @returns {Promise}\r\n */\r\n save(callback?: General.Callback): Bluebird;\r\n /**\r\n * Saves the given changes to this instance and updates the instance to match the latest database document.\r\n * @param {Object} changes The MongoDB changes object to be used when updating this instance\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes\r\n * @returns {Promise}\r\n */\r\n save(changes: Object, callback?: General.Callback): Bluebird;\r\n /**\r\n * Saves the given changes to this instance and updates the instance to match the latest database document.\r\n * @param {Object} conditions The conditions under which the update will take place - these will be merged with an _id query\r\n * @param {Object} changes The MongoDB changes object to be used when updating this instance\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes\r\n * @returns {Promise}\r\n */\r\n save(conditions: Object, changes: Object, callback?: General.Callback): Bluebird;\r\n save(...args: any[]): Bluebird {\r\n var callback: General.Callback = null;\r\n var changes: any = null;\r\n var conditions: any = {};\r\n\r\n Array.prototype.slice.call(args, 0).reverse().forEach((arg) => {\r\n if (typeof arg == 'function') callback = arg;\r\n else if (typeof arg == 'object') {\r\n if (!changes) changes = arg;\r\n else conditions = arg;\r\n }\r\n });\r\n\r\n return Bluebird.resolve().then(() => {\r\n conditions = this._model.helpers.cloneConditions(conditions);\r\n _.merge(conditions, { _id: this._modified._id });\r\n\r\n if (!changes) {\r\n var validation = this._model.helpers.validate(this._modified);\r\n if (validation.failed) return Bluebird.reject(validation.error).bind(this).nodeify(callback);\r\n\r\n var original = this._model.helpers.cloneDocument(this._original);\r\n var modified = this._model.helpers.cloneDocument(this._modified);\r\n \r\n modified = this._model.helpers.transformToDB(modified, { document: true }); \r\n\r\n changes = this._model.helpers.diff(original, modified);\r\n }\r\n\r\n if (!_.keys(changes).length) return null;\r\n\r\n return changes;\r\n }).then((changes) => {\r\n if (!changes && !this._isNew) return changes;\r\n return this._model.handlers.savingDocument(this, changes).then(() => changes);\r\n }).then((changes) => {\r\n if (!changes && !this._isNew) return false;\r\n\r\n if (this._isNew) {\r\n return new Bluebird((resolve, reject) => {\r\n this._model.collection.insertOne(this._modified, { w: 'majority' }, (err, doc) => {\r\n if (err) return reject(err);\r\n return resolve(!!doc);\r\n });\r\n });\r\n } else {\r\n return new Bluebird((resolve: (changed: boolean) => void, reject) => {\r\n this._model.collection.updateOne(conditions, changes, { w: 'majority' }, (err: Error, changed: boolean) => {\r\n if(err) {\r\n err['conditions'] = conditions;\r\n err['changes'] = changes;\r\n return reject(err);\r\n }\r\n\r\n return resolve(changed);\r\n });\r\n });\r\n }\r\n }).catch(err => {\r\n err['original'] = this._original;\r\n err['modified'] = this._modified;\r\n return Bluebird.reject(err);\r\n }).then((changed: boolean) => {\r\n conditions = { _id: this._modified._id };\r\n if (!changed) return this._modified;\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this._model.collection.findOne(conditions, (err: Error, latest) => {\r\n if (err) return reject(err);\r\n return resolve(latest);\r\n });\r\n });\r\n }).then((latest: TDocument) => {\r\n if(!latest) {\r\n this._isNew = true;\r\n this._original = this._model.helpers.cloneDocument(this._modified);\r\n return Bluebird.resolve(this);\r\n }\r\n\r\n return this._model.handlers.documentReceived(conditions, latest, (value) => {\r\n this._isPartial = false;\r\n this._isNew = false;\r\n this._modified = value;\r\n this._original = this._model.helpers.cloneDocument(value);\r\n return this;\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Updates this instance to match the latest document available in the backing collection\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the update completes\r\n * @returns {Promise}\r\n */\r\n update(callback?: General.Callback): Bluebird {\r\n return this.refresh(callback);\r\n }\r\n\r\n /**\r\n * Updates this instance to match the latest document available in the backing collection\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the update completes\r\n * @returns {Promise}\r\n */\r\n refresh(callback?: General.Callback): Bluebird {\r\n var conditions = { _id: this._original._id };\r\n\r\n return Bluebird.resolve().then(() => {\r\n return new Bluebird((resolve, reject) => {\r\n this._model.collection.findOne(conditions,(err: Error, doc: any) => {\r\n if (err) return reject(err);\r\n return resolve(doc);\r\n });\r\n });\r\n }).then((newDocument) => {\r\n if (!newDocument) {\r\n this._isPartial = true;\r\n this._isNew = true;\r\n this._original = this._model.helpers.cloneDocument(this._modified);\r\n return >this;\r\n }\r\n\r\n return this._model.handlers.documentReceived(conditions, newDocument, (doc) => {\r\n this._isNew = false;\r\n this._isPartial = false;\r\n this._original = doc;\r\n this._modified = this._model.helpers.cloneDocument(doc);\r\n\r\n return this;\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Removes this instance's document from the backing collection\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n delete(callback?: General.Callback): Bluebird {\r\n return this.remove(callback);\r\n }\r\n\r\n /**\r\n * Removes this instance's document from the backing collection\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n remove(callback?: General.Callback): Bluebird {\r\n var conditions = { _id: this._original._id };\r\n\r\n return Bluebird.resolve().then(() => {\r\n if (this._isNew) return 0;\r\n return new Bluebird((resolve, reject) => {\r\n this._model.collection.remove(conditions, { w: 'majority' },(err: Error, removed?: any) => {\r\n if (err) return reject(err);\r\n return resolve(removed);\r\n });\r\n });\r\n }).then((removed) => {\r\n if (removed) return this._model.cache.clear(conditions);\r\n return false;\r\n }).then(() => {\r\n this._isNew = true;\r\n return this;\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Retrieves the first element in an enumerable collection which matches the predicate\r\n * @param collection The collection from which to retrieve the element\r\n * @param predicate The function which determines whether to select an element\r\n * @returns The first element in the array which matched the predicate.\r\n */\r\n first(collection: T[], predicate: General.Predicate): T;\r\n /**\r\n * Retrieves the first element in an enumerable collection which matches the predicate\r\n * @param collection The collection from which to retrieve the element\r\n * @param predicate The function which determines whether to select an element\r\n * @returns The first element in the object which matched the predicate.\r\n */\r\n first(collection: { [key: string]: T }, predicate: General.Predicate): T;\r\n first(collection: T[]| { [key: string]: T }, predicate: General.Predicate): T {\r\n var result = null;\r\n\r\n _.each(collection,(value: T, key) => {\r\n if (predicate.call(this, value, key)) {\r\n result = value;\r\n return false;\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Retrieves a number of elements from an enumerable collection which match the predicate\r\n * @param collection The collection from which elements will be plucked\r\n * @param predicate The function which determines the elements to be plucked\r\n * @returns A new array containing the elements in the array which matched the predicate.\r\n */\r\n select(collection: T[], predicate: General.Predicate): T[];\r\n /**\r\n * Retrieves a number of elements from an enumerable collection which match the predicate\r\n * @param collection The collection from which elements will be plucked\r\n * @param predicate The function which determines the elements to be plucked\r\n * @returns An object with the properties from the collection which matched the predicate.\r\n */\r\n select(collection: { [key: string]: T }, predicate: General.Predicate): { [key: string]: T };\r\n select(collection: T[]| { [key: string]: T }, predicate: General.Predicate): any {\r\n var isArray = Array.isArray(collection);\r\n var results: any = isArray ? [] : {};\r\n\r\n _.each(collection,(value: T, key) => {\r\n if (predicate.call(this, value, key)) {\r\n if (isArray) results.push(value);\r\n else results[key] = value;\r\n }\r\n });\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Gets the JSON representation of this instance\r\n * @returns {TDocument}\r\n */\r\n toJSON(): any {\r\n return this.document;\r\n }\r\n\r\n /**\r\n * Gets a string representation of this instance\r\n * @returns {String}\r\n */\r\n toString(): string {\r\n return JSON.stringify(this.document, null, 2);\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/Instance.ts"],"names":[],"mappings":";AASA,2BAAgC,cAAc,CAAC,CAAA;AAE/C,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAE7B,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAGtC;;;;;;;;;;;;;GAaG;AACH;IACI;;;;;;;OAOG;IACH,kBAAY,KAAkC,EAAE,QAAmB,EAAE,KAAqB,EAAE,SAA0B;QAT1H,iBAoWC;QA3VwE,qBAAqB,GAArB,YAAqB;QAAE,yBAA0B,GAA1B,iBAA0B;QAClH,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEpB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC;QACtB,IAAI,CAAC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AErC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAC,UAAC,KAAQ,EAAE,GAAG;YAC5B,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAI,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;gBACnC,EAAE,CAAC,CAAC,OAAO,CAAC;oBAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACjC,IAAI;oBAAC,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAC9B,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,OAAO,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,yBAAM,GAAN;QACI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,2BAAQ,GAAR;QACI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC;IA7RD;;OAEG;IACI,eAAM,GAAW;QACpB,GAAG,EAAE,KAAK;KACb,CAAC;IAEF;;OAEG;IACI,mBAAU,GAAuB,8BAAiB,EAAE,CAAC;IAE5D;;OAEG;IACI,mBAAU,GAAe,EAE/B,CAAC;IAOF;;OAEG;IACI,gBAAO,GAA+C,EAAE,CAAC;IAmQpE,eAAC;AAAD,CApWA,AAoWC,IAAA;AApWY,gBAAQ,WAoWpB,CAAA","file":"lib/Instance.js","sourcesContent":["import {Core} from './Core';\r\nimport {Model} from './Model';\r\nimport {Plugin} from './Plugins';\r\nimport {CacheDirector} from './CacheDirector';\r\nimport * as General from './General';\r\nimport * as ModelInterfaces from './ModelInterfaces';\r\nimport * as Index from './Index';\r\nimport {Schema} from './Schema';\r\nimport {Transforms} from './Transforms';\r\nimport {DefaultValidators} from './Validators';\r\n\r\nimport _ = require('lodash');\r\nimport MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\nimport Skmatc = require('skmatc');\r\n\r\n/**\r\n * The default Iridium Instance implementation which provides methods for saving, refreshing and\r\n * removing the wrapped document from the collection, as well as integrating with Omnom, our\r\n * built in document diff processor which allows clean, atomic, document updates to be performed\r\n * without needing to write the update queries yourself.\r\n *\r\n * @param TDocument The interface representing the structure of the documents in the collection.\r\n * @param TInstance The type of instance which wraps the documents, generally the subclass of this class.\r\n *\r\n * This class will be subclassed automatically by Iridium to create a model specific instance\r\n * which takes advantage of some of v8's optimizations to boost performance significantly.\r\n * The instance returned by the model, and all of this instance's methods, will be of type\r\n * TInstance - which should represent the merger of TSchema and IInstance for best results.\r\n */\r\nexport class Instance {\r\n /**\r\n * Creates a new instance which represents the given document as a type of model\r\n * @param model The model that dictates the collection the document originated from as well as how validations are performed.\r\n * @param document The document which should be wrapped by this instance\r\n * @param isNew Whether the document is new (doesn't exist in the database) or not\r\n * @param isPartial Whether the document has only a subset of its fields populated\r\n *\r\n */\r\n constructor(model: Model, document: TDocument, isNew: boolean = true, isPartial: boolean = false) {\r\n this._model = model;\r\n\r\n this._isNew = !!isNew;\r\n this._isPartial = isPartial;\r\n this._original = document;\r\n this._modified = model.helpers.cloneDocument(document);\r\n\r\n _.each(model.core.plugins,(plugin: Plugin) => {\r\n if (plugin.newInstance) plugin.newInstance(this, model);\r\n });\r\n }\r\n\r\n private _isNew: boolean;\r\n private _isPartial: boolean;\r\n private _model: Model;\r\n private _original: TDocument;\r\n private _modified: TDocument;\r\n\r\n /**\r\n * Gets the underlying document representation of this instance\r\n */\r\n get document(): TDocument {\r\n return this._modified;\r\n }\r\n\r\n [name: string]: any;\r\n\r\n /**\r\n * A function which is called whenever a new document is in the process of being inserted into the database.\r\n * @param document The document which will be inserted into the database.\r\n */\r\n static onCreating: (document: { _id?: any }) => Promise.Thenable | void;\r\n\r\n /**\r\n * A function which is called whenever a document of this type is received from the database, prior to it being\r\n * wrapped by an Instance object.\r\n * @param document The document that was retrieved from the database.\r\n */\r\n static onRetrieved: (document: { _id?: any }) => Promise.Thenable | void;\r\n\r\n /**\r\n * A function which is called whenever a new instance has been created to wrap a document.\r\n * @param instance The instance which has been created.\r\n */\r\n static onReady: (instance: Instance<{ _id?: any }, Instance<{ _id?: any }, any>>) => Promise.Thenable | void;\r\n\r\n /**\r\n * A function which is called whenever an instance's save() method is called to allow you to interrogate and/or manipulate\r\n * the changes which are being made.\r\n *\r\n * @param instance The instance to which the changes are being made\r\n * @param changes The MongoDB change object describing the changes being made to the document.\r\n */\r\n static onSaving: (instance: Instance<{ _id?: any }, Instance<{ _id?: any }, any>>, changes: any) => Promise.Thenable | void;\r\n\r\n /**\r\n * The name of the collection into which documents of this type are stored.\r\n */\r\n static collection: string;\r\n\r\n /**\r\n * The schema used to validate documents of this type before being stored in the database.\r\n */\r\n static schema: Schema = {\r\n _id: false\r\n };\r\n\r\n /**\r\n * Additional which should be made available for use in the schema definition for this instance.\r\n */\r\n static validators: Skmatc.Validator[] = DefaultValidators();\r\n\r\n /**\r\n * The transformations which should be applied to properties of documents of this type.\r\n */\r\n static transforms: Transforms = {\r\n\r\n };\r\n\r\n /**\r\n * The cache director used to derive unique cache keys for documents of this type.\r\n */\r\n static cache: CacheDirector;\r\n\r\n /**\r\n * The indexes which should be managed by Iridium for the collection used by this type.\r\n */\r\n static indexes: (Index.Index | Index.IndexSpecification)[] = [];\r\n\r\n /**\r\n * Saves any changes to this instance, using the built in diff algorithm to write the update query.\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes\r\n * @returns {Promise}\r\n */\r\n save(callback?: General.Callback): Bluebird;\r\n /**\r\n * Saves the given changes to this instance and updates the instance to match the latest database document.\r\n * @param {Object} changes The MongoDB changes object to be used when updating this instance\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes\r\n * @returns {Promise}\r\n */\r\n save(changes: Object, callback?: General.Callback): Bluebird;\r\n /**\r\n * Saves the given changes to this instance and updates the instance to match the latest database document.\r\n * @param {Object} conditions The conditions under which the update will take place - these will be merged with an _id query\r\n * @param {Object} changes The MongoDB changes object to be used when updating this instance\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the save operation completes\r\n * @returns {Promise}\r\n */\r\n save(conditions: Object, changes: Object, callback?: General.Callback): Bluebird;\r\n save(...args: any[]): Bluebird {\r\n var callback: General.Callback = null;\r\n var changes: any = null;\r\n var conditions: any = {};\r\n\r\n Array.prototype.slice.call(args, 0).reverse().forEach((arg) => {\r\n if (typeof arg == 'function') callback = arg;\r\n else if (typeof arg == 'object') {\r\n if (!changes) changes = arg;\r\n else conditions = arg;\r\n }\r\n });\r\n\r\n return Bluebird.resolve().then(() => {\r\n conditions = this._model.helpers.cloneConditions(conditions);\r\n _.merge(conditions, { _id: this._modified._id });\r\n\r\n if (!changes) {\r\n var validation = this._model.helpers.validate(this._modified);\r\n if (validation.failed) return Bluebird.reject(validation.error).bind(this).nodeify(callback);\r\n\r\n var original = this._model.helpers.cloneDocument(this._original);\r\n var modified = this._model.helpers.cloneDocument(this._modified);\r\n \r\n modified = this._model.helpers.transformToDB(modified, { document: true }); \r\n\r\n changes = this._model.helpers.diff(original, modified);\r\n }\r\n\r\n if (!_.keys(changes).length) return null;\r\n\r\n return changes;\r\n }).then((changes) => {\r\n if (!changes && !this._isNew) return changes;\r\n return this._model.handlers.savingDocument(this, changes).then(() => changes);\r\n }).then((changes) => {\r\n if (!changes && !this._isNew) return false;\r\n\r\n if (this._isNew) {\r\n return new Bluebird((resolve, reject) => {\r\n this._model.collection.insertOne(this._modified, { w: 'majority' }, (err, doc) => {\r\n if (err) return reject(err);\r\n return resolve(!!doc);\r\n });\r\n });\r\n } else {\r\n return new Bluebird((resolve: (changed: boolean) => void, reject) => {\r\n this._model.collection.updateOne(conditions, changes, { w: 'majority' }, (err: Error, changed: boolean) => {\r\n if(err) {\r\n err['conditions'] = conditions;\r\n err['changes'] = changes;\r\n return reject(err);\r\n }\r\n\r\n return resolve(changed);\r\n });\r\n });\r\n }\r\n }).catch(err => {\r\n err['original'] = this._original;\r\n err['modified'] = this._modified;\r\n return Bluebird.reject(err);\r\n }).then((changed: boolean) => {\r\n conditions = { _id: this._modified._id };\r\n if (!changed) return this._modified;\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this._model.collection.findOne(conditions, (err: Error, latest) => {\r\n if (err) return reject(err);\r\n return resolve(latest);\r\n });\r\n });\r\n }).then((latest: TDocument) => {\r\n if(!latest) {\r\n this._isNew = true;\r\n this._original = this._model.helpers.cloneDocument(this._modified);\r\n return Bluebird.resolve(this);\r\n }\r\n\r\n return this._model.handlers.documentReceived(conditions, latest, (value) => {\r\n this._isPartial = false;\r\n this._isNew = false;\r\n this._modified = value;\r\n this._original = this._model.helpers.cloneDocument(value);\r\n return this;\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Updates this instance to match the latest document available in the backing collection\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the update completes\r\n * @returns {Promise}\r\n */\r\n update(callback?: General.Callback): Bluebird {\r\n return this.refresh(callback);\r\n }\r\n\r\n /**\r\n * Updates this instance to match the latest document available in the backing collection\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the update completes\r\n * @returns {Promise}\r\n */\r\n refresh(callback?: General.Callback): Bluebird {\r\n var conditions = { _id: this._original._id };\r\n\r\n return Bluebird.resolve().then(() => {\r\n return new Bluebird((resolve, reject) => {\r\n this._model.collection.findOne(conditions,(err: Error, doc: any) => {\r\n if (err) return reject(err);\r\n return resolve(doc);\r\n });\r\n });\r\n }).then((newDocument) => {\r\n if (!newDocument) {\r\n this._isPartial = true;\r\n this._isNew = true;\r\n this._original = this._model.helpers.cloneDocument(this._modified);\r\n return >this;\r\n }\r\n\r\n return this._model.handlers.documentReceived(conditions, newDocument, (doc) => {\r\n this._isNew = false;\r\n this._isPartial = false;\r\n this._original = doc;\r\n this._modified = this._model.helpers.cloneDocument(doc);\r\n\r\n return this;\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Removes this instance's document from the backing collection\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n delete(callback?: General.Callback): Bluebird {\r\n return this.remove(callback);\r\n }\r\n\r\n /**\r\n * Removes this instance's document from the backing collection\r\n * @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n remove(callback?: General.Callback): Bluebird {\r\n var conditions = { _id: this._original._id };\r\n\r\n return Bluebird.resolve().then(() => {\r\n if (this._isNew) return 0;\r\n return new Bluebird((resolve, reject) => {\r\n this._model.collection.remove(conditions, { w: 'majority' },(err: Error, removed?: any) => {\r\n if (err) return reject(err);\r\n return resolve(removed);\r\n });\r\n });\r\n }).then((removed) => {\r\n if (removed) return this._model.cache.clear(conditions);\r\n return false;\r\n }).then(() => {\r\n this._isNew = true;\r\n return this;\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Retrieves the first element in an enumerable collection which matches the predicate\r\n * @param collection The collection from which to retrieve the element\r\n * @param predicate The function which determines whether to select an element\r\n * @returns The first element in the array which matched the predicate.\r\n */\r\n first(collection: T[], predicate: General.Predicate): T;\r\n /**\r\n * Retrieves the first element in an enumerable collection which matches the predicate\r\n * @param collection The collection from which to retrieve the element\r\n * @param predicate The function which determines whether to select an element\r\n * @returns The first element in the object which matched the predicate.\r\n */\r\n first(collection: { [key: string]: T }, predicate: General.Predicate): T;\r\n first(collection: T[]| { [key: string]: T }, predicate: General.Predicate): T {\r\n var result = null;\r\n\r\n _.each(collection,(value: T, key) => {\r\n if (predicate.call(this, value, key)) {\r\n result = value;\r\n return false;\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Retrieves a number of elements from an enumerable collection which match the predicate\r\n * @param collection The collection from which elements will be plucked\r\n * @param predicate The function which determines the elements to be plucked\r\n * @returns A new array containing the elements in the array which matched the predicate.\r\n */\r\n select(collection: T[], predicate: General.Predicate): T[];\r\n /**\r\n * Retrieves a number of elements from an enumerable collection which match the predicate\r\n * @param collection The collection from which elements will be plucked\r\n * @param predicate The function which determines the elements to be plucked\r\n * @returns An object with the properties from the collection which matched the predicate.\r\n */\r\n select(collection: { [key: string]: T }, predicate: General.Predicate): { [key: string]: T };\r\n select(collection: T[]| { [key: string]: T }, predicate: General.Predicate): any {\r\n var isArray = Array.isArray(collection);\r\n var results: any = isArray ? [] : {};\r\n\r\n _.each(collection,(value: T, key) => {\r\n if (predicate.call(this, value, key)) {\r\n if (isArray) results.push(value);\r\n else results[key] = value;\r\n }\r\n });\r\n\r\n return results;\r\n }\r\n\r\n /**\r\n * Gets the JSON representation of this instance\r\n * @returns {TDocument}\r\n */\r\n toJSON(): any {\r\n return this.document;\r\n }\r\n\r\n /**\r\n * Gets a string representation of this instance\r\n * @returns {String}\r\n */\r\n toString(): string {\r\n return JSON.stringify(this.document, null, 2);\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/InstanceInterface.js b/dist/lib/InstanceInterface.js index 760d882..c721540 100644 --- a/dist/lib/InstanceInterface.js +++ b/dist/lib/InstanceInterface.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=InstanceInterface.js.map diff --git a/dist/lib/Middleware.js b/dist/lib/Middleware.js index bcd68e8..2a5c356 100644 --- a/dist/lib/Middleware.js +++ b/dist/lib/Middleware.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=Middleware.js.map diff --git a/dist/lib/Model.js b/dist/lib/Model.js index 5da88d5..fc3a8f4 100644 --- a/dist/lib/Model.js +++ b/dist/lib/Model.js @@ -1,3 +1,4 @@ +"use strict"; var MongoDB = require('mongodb'); var Bluebird = require('bluebird'); var _ = require('lodash'); @@ -532,7 +533,7 @@ var Model = (function () { }).nodeify(callback); }; return Model; -})(); +}()); exports.Model = Model; //# sourceMappingURL=Model.js.map diff --git a/dist/lib/Model.js.map b/dist/lib/Model.js.map index a539153..8faec39 100644 --- a/dist/lib/Model.js.map +++ b/dist/lib/Model.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/Model.ts"],"names":["Model","Model.constructor","Model.loadExternal","Model.loadInternal","Model.onNewModel","Model.helpers","Model.handlers","Model.hooks","Model.schema","Model.core","Model.collection","Model.collectionName","Model.cacheDirector","Model.cache","Model.Instance","Model.transforms","Model.validators","Model.indexes","Model.find","Model.get","Model.findOne","Model.create","Model.insert","Model.update","Model.count","Model.remove","Model.aggregate","Model.ensureIndex","Model.ensureIndexes","Model.dropIndex","Model.dropIndexes"],"mappings":"AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAEtC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAG7B,qBAAmB,QAAQ,CAAC,CAAA;AAC5B,yBAAuB,YAAY,CAAC,CAAA;AAOpC,uBAAqB,UAAU,CAAC,CAAA;AAKhC,2BAAyB,cAAc,CAAC,CAAA;AACxC,6BAA2B,gBAAgB,CAAC,CAAA;AAC5C,8BAA4B,iBAAiB,CAAC,CAAA;AAE9C,sCAAoC,yBAAyB,CAAC,CAAA;AAE9D,2BAA4C,cAAc,CAAC,CAAA;AAG3D;;;;;;;;;GASG;AACH;IACIA;;;;;OAKGA;IACHA,eAAYA,IAAUA,EAAEA,YAA0DA;QAwE1EC,WAAMA,GAAgCA,EAAEA,CAACA;QAvE7CA,EAAEA,CAACA,CAACA,CAACA,CAACA,IAAIA,YAAYA,WAAIA,CAACA,CAACA;YAACA,MAAMA,IAAIA,KAAKA,CAACA,2DAA2DA,CAACA,CAACA;QAC1GA,EAAEA,CAACA,CAACA,OAAOA,YAAYA,IAAIA,UAAUA,CAACA;YAACA,MAAMA,IAAIA,KAAKA,CAACA,mEAAmEA,CAACA,CAACA;QAC5HA,EAAEA,CAACA,CAACA,OAAOA,YAAYA,CAACA,UAAUA,IAAIA,QAAQA,IAAIA,CAACA,YAAYA,CAACA,UAAUA,CAACA;YAACA,MAAMA,IAAIA,KAAKA,CAACA,8DAA8DA,CAACA,CAACA;QAC5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PA,CAACA,CAACA,CAACA,OAAOA,CAACA,QAAQA,CAACA,CAACA;IACzBA,CAACA;IAED7B;;;;OAIGA;IACHA,2BAAWA,GAAXA,UAAYA,QAAoCA;QAAhD8B,iBAOCA;QANGA,MAAMA,CAACA,IAAIA,QAAQA,CAAMA,UAACA,OAAOA,EAAEA,MAAMA;YACrCA,KAAIA,CAACA,UAAUA,CAACA,cAAcA,CAACA,UAACA,GAAGA,EAAEA,KAAKA;gBACtCA,EAAEA,CAACA,CAACA,GAAGA,CAACA;oBAACA,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;gBAC5BA,MAAMA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA;YAC1BA,CAACA,CAACA,CAACA;QACPA,CAACA,CAACA,CAACA,OAAOA,CAACA,QAAQA,CAACA,CAACA;IACzBA,CAACA;IACL9B,YAACA;AAADA,CA3sBA,AA2sBCA,IAAA;AA3sBY,aAAK,QA2sBjB,CAAA","file":"lib/Model.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\nimport util = require('util');\r\nimport _ = require('lodash');\r\nimport Skmatc = require('skmatc');\r\n\r\nimport {Core} from './Core';\r\nimport {Instance} from './Instance';\r\nimport {Schema} from './Schema';\r\nimport {Hooks} from './Hooks';\r\nimport {Plugin} from './Plugins';\r\nimport {Cache} from './Cache';\r\nimport {CacheDirector} from './CacheDirector';\r\nimport * as General from './General';\r\nimport {Cursor} from './Cursor';\r\nimport * as Index from './Index';\r\nimport * as ModelOptions from './ModelOptions';\r\n\r\nimport {Omnom} from './utils/Omnom';\r\nimport {ModelCache} from './ModelCache';\r\nimport {ModelHelpers} from './ModelHelpers';\r\nimport {ModelHandlers} from './ModelHandlers';\r\nimport * as ModelInterfaces from './ModelInterfaces';\r\nimport {ModelSpecificInstance} from './ModelSpecificInstance';\r\nimport {InstanceImplementation} from './InstanceInterface';\r\nimport {Transforms, DefaultTransforms} from './Transforms';\r\nimport * as AggregationPipeline from './Aggregate';\r\n\r\n/**\r\n * An Iridium Model which represents a structured MongoDB collection.\r\n * Models expose the methods you will generally use to query those collections, and ensure that\r\n * the results of those queries are returned as {TInstance} instances.\r\n *\r\n * @param TDocument The interface used to determine the schema of documents in the collection.\r\n * @param TInstance The interface or class used to represent collection documents in the JS world.\r\n *\r\n * @class\r\n */\r\nexport class Model {\r\n /**\r\n * Creates a new Iridium model representing a given ISchema and backed by a collection whose name is specified\r\n * @param core The Iridium core that this model should use for database access\r\n * @param instanceType The class which will be instantiated for each document retrieved from the database\r\n * @constructor\r\n */\r\n constructor(core: Core, instanceType: InstanceImplementation) {\r\n if (!(core instanceof Core)) throw new Error(\"You failed to provide a valid Iridium core for this model\");\r\n if (typeof instanceType != 'function') throw new Error(\"You failed to provide a valid instance constructor for this model\");\r\n if (typeof instanceType.collection != 'string' || !instanceType.collection) throw new Error(\"You failed to provide a valid collection name for this model\");\r\n if (!_.isPlainObject(instanceType.schema) || instanceType.schema._id === undefined) throw new Error(\"You failed to provide a valid schema for this model\");\r\n\r\n this._core = core;\r\n\r\n this.loadExternal(instanceType);\r\n this.onNewModel();\r\n this.loadInternal();\r\n }\r\n\r\n /**\r\n * Loads any externally available properties (generally accessed using public getters/setters).\r\n */\r\n private loadExternal(instanceType: InstanceImplementation) {\r\n this._collection = instanceType.collection;\r\n this._schema = instanceType.schema;\r\n this._hooks = instanceType;\r\n this._cacheDirector = instanceType.cache;\r\n this._transforms = instanceType.transforms || {};\r\n this._validators = instanceType.validators || [];\r\n this._indexes = instanceType.indexes || [];\r\n\r\n if(!this._schema._id) this._schema._id = MongoDB.ObjectID;\r\n\r\n if(this._schema._id === MongoDB.ObjectID && !this._transforms['_id'])\r\n this._transforms['_id'] = DefaultTransforms.ObjectID;\r\n\r\n if ((instanceType).prototype instanceof Instance)\r\n this._Instance = ModelSpecificInstance(this, instanceType);\r\n else\r\n this._Instance = instanceType.bind(undefined, this);\r\n }\r\n\r\n /**\r\n * Loads any internally (protected/private) properties and helpers only used within Iridium itself.\r\n */\r\n private loadInternal() {\r\n this._cache = new ModelCache(this);\r\n this._helpers = new ModelHelpers(this);\r\n this._handlers = new ModelHandlers(this);\r\n }\r\n\r\n /**\r\n * Process any callbacks and plugin delegation for the creation of this model.\r\n * It will generally be called whenever a new Iridium Core is created, however is\r\n * more specifically tied to the lifespan of the models themselves.\r\n */\r\n private onNewModel() {\r\n this._core.plugins.forEach(plugin => plugin.newModel && plugin.newModel(this));\r\n }\r\n\r\n private _helpers: ModelHelpers;\r\n /**\r\n * Provides helper methods used by Iridium for common tasks\r\n * @returns A set of helper methods which are used within Iridium for common tasks\r\n */\r\n get helpers(): ModelHelpers {\r\n return this._helpers;\r\n }\r\n\r\n private _handlers: ModelHandlers;\r\n /**\r\n * Provides helper methods used by Iridium for hook delegation and common processes\r\n * @returns A set of helper methods which perform common event and response handling tasks within Iridium.\r\n */\r\n get handlers(): ModelHandlers {\r\n return this._handlers;\r\n }\r\n\r\n private _hooks: Hooks = {};\r\n\r\n /**\r\n * Gets the even hooks subscribed on this model for a number of different state changes.\r\n * These hooks are primarily intended to allow lifecycle manipulation logic to be added\r\n * in the user's model definition, allowing tasks such as the setting of default values\r\n * or automatic client-side joins to take place.\r\n */\r\n get hooks(): Hooks {\r\n return this._hooks;\r\n }\r\n\r\n private _schema: Schema;\r\n /**\r\n * Gets the schema dictating the data structure represented by this model.\r\n * The schema is used by skmatc to validate documents before saving to the database, however\r\n * until MongoDB 3.1 becomes widely available (with server side validation support) we are\r\n * limited in our ability to validate certain types of updates. As such, these validations\r\n * act more as a data-integrity check than anything else, unless you purely make use of Omnom\r\n * updates within instances.\r\n * @public\r\n * @returns The defined validation schema for this model\r\n */\r\n get schema(): Schema {\r\n return this._schema;\r\n }\r\n\r\n private _core: Core;\r\n /**\r\n * Gets the Iridium core that this model is associated with.\r\n * @public\r\n * @returns The Iridium core that this model is bound to\r\n */\r\n get core(): Core {\r\n return this._core;\r\n }\r\n\r\n private _collection: string;\r\n /**\r\n * Gets the underlying MongoDB collection from which this model's documents are retrieved.\r\n * You can make use of this object if you require any low level access to the MongoDB collection,\r\n * however we recommend you make use of the Iridium methods whereever possible, as we cannot\r\n * guarantee the accuracy of the type definitions for the underlying MongoDB driver.\r\n * @public\r\n * @returns {Collection}\r\n */\r\n get collection(): MongoDB.Collection {\r\n if (!this.core.connection) throw new Error(\"Iridium Core not connected to a database.\");\r\n return this.core.connection.collection(this._collection);\r\n }\r\n\r\n /**\r\n * Gets the name of the underlying MongoDB collection from which this model's documents are retrieved\r\n * @public\r\n */\r\n get collectionName(): string {\r\n return this._collection;\r\n }\r\n\r\n /**\r\n * Sets the name of the underlying MongoDB collection from which this model's documents are retrieved\r\n * @public\r\n */\r\n set collectionName(value: string) {\r\n this._collection = value;\r\n }\r\n\r\n private _cacheDirector: CacheDirector;\r\n /**\r\n * Gets the cache controller which dictates which queries will be cached, and under which key\r\n * @public\r\n * @returns {CacheDirector}\r\n */\r\n get cacheDirector(): CacheDirector {\r\n return this._cacheDirector;\r\n }\r\n\r\n private _cache: ModelCache;\r\n /**\r\n * Gets the cache responsible for storing objects for quick retrieval under certain conditions\r\n * @public\r\n * @returns {ModelCache}\r\n */\r\n get cache(): ModelCache {\r\n return this._cache;\r\n }\r\n\r\n private _Instance: ModelInterfaces.ModelSpecificInstanceConstructor;\r\n\r\n /**\r\n * Gets the constructor responsible for creating instances for this model\r\n */\r\n get Instance(): ModelInterfaces.ModelSpecificInstanceConstructor {\r\n return this._Instance;\r\n }\r\n\r\n private _transforms: Transforms;\r\n\r\n /**\r\n * Gets the transforms which are applied whenever a document is received from the database, or\r\n * prior to storing a document in the database. Tasks such as converting an ObjectID to a string\r\n * and vice versa are all listed in this object.\r\n */\r\n get transforms() {\r\n return this._transforms;\r\n }\r\n\r\n private _validators: Skmatc.Validator[];\r\n\r\n /**\r\n * Gets the custom validation types available for this model. These validators are added to the\r\n * default skmatc validators, as well as those available through plugins, for use when checking\r\n * your instances.\r\n */\r\n get validators() {\r\n return this._validators;\r\n }\r\n\r\n private _indexes: (Index.Index | Index.IndexSpecification)[];\r\n\r\n /**\r\n * Gets the indexes which Iridium will manage on this model's database collection.\r\n */\r\n get indexes() {\r\n return this._indexes;\r\n }\r\n\r\n /**\r\n * Retrieves all documents in the collection and wraps them as instances\r\n * @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available\r\n * @returns {Promise}\r\n */\r\n find(): Cursor;\r\n /**\r\n * Returns all documents in the collection which match the conditions and wraps them as instances\r\n * @param {Object} conditions The MongoDB query dictating which documents to return\r\n * @returns {Promise}\r\n */\r\n find(conditions: { _id?: any, [key: string]: any } | any): Cursor;\r\n /**\r\n * Returns all documents in the collection which match the conditions\r\n * @param {Object} conditions The MongoDB query dictating which documents to return\r\n * @param {Object} fields The fields to include or exclude from the document\r\n * @returns {Promise}\r\n */\r\n find(conditions: { _id?: any, [key: string]: any } | any, fields: { [name: string]: number }): Cursor;\r\n find(conditions?: { _id?: any, [key: string]: any } | any, fields?: any): Cursor {\r\n conditions = conditions || {};\r\n fields = fields || {};\r\n\r\n if (!_.isPlainObject(conditions)) conditions = { _id: conditions };\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n var cursor = this.collection.find(conditions, {\r\n fields: fields\r\n });\r\n\r\n return new Cursor(this, conditions, cursor);\r\n }\r\n\r\n /**\r\n * Retrieves a single document from the collection and wraps it as an instance\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection with the given ID and wraps it as an instance\r\n * @param {any} id The document's unique _id field value in downstream format\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(id: any, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection which matches the conditions\r\n * @param {Object} conditions The MongoDB query dictating which document to return\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(conditions: { _id?: any, [key: string]: any }, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection with the given ID and wraps it as an instance\r\n * @param {any} id The document's unique _id field value in downstream format\r\n * @param {QueryOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(id: any, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection which matches the conditions\r\n * @param {Object} conditions The MongoDB query dictating which document to return\r\n * @param {QueryOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(conditions: { _id?: any, [key: string]: any }, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird;\r\n get(...args: any[]): Bluebird {\r\n return this.findOne.apply(this, args);\r\n }\r\n\r\n /**\r\n * Retrieves a single document from the collection and wraps it as an instance\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection with the given ID and wraps it as an instance\r\n * @param {any} id The document's unique _id field value in downstream format\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(id: any, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection which matches the conditions\r\n * @param {Object} conditions The MongoDB query dictating which document to return\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(conditions: { _id?: any, [key: string]: any }, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection with the given ID and wraps it as an instance\r\n * @param {any} id The document's unique _id field value in downstream format\r\n * @param {QueryOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(id: any, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection which matches the conditions\r\n * @param {Object} conditions The MongoDB query dictating which document to return\r\n * @param {QueryOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(conditions: { _id?: any, [key: string]: any }, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird;\r\n findOne(...args: any[]): Bluebird {\r\n var conditions: { _id?: any, [key: string]: any } = null;\r\n var options: ModelOptions.QueryOptions = null;\r\n var callback: General.Callback = null;\r\n\r\n for (var argI = 0; argI < args.length; argI++) {\r\n if (typeof args[argI] == 'function') callback = callback || args[argI];\r\n else if (_.isPlainObject(args[argI])) {\r\n if (conditions) options = args[argI];\r\n else conditions = args[argI];\r\n }\r\n else conditions = { _id: args[argI] };\r\n }\r\n\r\n conditions = conditions || {};\r\n options = options || {};\r\n\r\n _.defaults(options, {\r\n cache: true\r\n });\r\n\r\n return Bluebird.resolve().bind(this).then(() => {\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n return this._cache.get(conditions);\r\n }).then((cachedDocument: TDocument) => {\r\n if (cachedDocument) return cachedDocument;\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.findOne(conditions, {\r\n fields: options.fields,\r\n skip: options.skip,\r\n sort: options.sort,\r\n limit: options.limit\r\n },(err, result) => {\r\n if (err) return reject(err);\r\n return resolve(result);\r\n });\r\n });\r\n }).then((document: TDocument) => {\r\n if (!document) return null;\r\n return this._handlers.documentReceived(conditions, document,(document, isNew?, isPartial?) => this._helpers.wrapDocument(document, isNew, isPartial), options);\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Inserts an object into the collection after validating it against this model's schema\r\n * @param {Object} object The object to insert into the collection\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n create(objects: TDocument, callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts an object into the collection after validating it against this model's schema\r\n * @param {Object} object The object to insert into the collection\r\n * @param {CreateOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n create(objects: TDocument, options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts the objects into the collection after validating them against this model's schema\r\n * @param {Object[]} objects The objects to insert into the collection\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n create(objects: TDocument[], callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts the objects into the collection after validating them against this model's schema\r\n * @param {Object[]} objects The objects to insert into the collection\r\n * @param {CreateOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n create(objects: TDocument[], options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird;\r\n create(...args: any[]): Bluebird {\r\n return this.insert.apply(this, args);\r\n }\r\n\r\n /**\r\n * Inserts an object into the collection after validating it against this model's schema\r\n * @param {Object} object The object to insert into the collection\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n insert(objects: TDocument, callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts an object into the collection after validating it against this model's schema\r\n * @param {Object} object The object to insert into the collection\r\n * @param {CreateOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n insert(objects: TDocument, options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts the objects into the collection after validating them against this model's schema\r\n * @param {Object[]} objects The objects to insert into the collection\r\n * @param {function(Error, TInstance[])} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n insert(objects: TDocument[], callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts the objects into the collection after validating them against this model's schema\r\n * @param {Object[]} objects The objects to insert into the collection\r\n * @param {CreateOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance[])} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n insert(objects: TDocument[], options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird;\r\n insert(objs: TDocument | TDocument[], ...args: any[]): Bluebird {\r\n var objects: TDocument[];\r\n var options: ModelOptions.CreateOptions = {};\r\n var callback: General.Callback = null;\r\n if (typeof args[0] == 'function') callback = args[0];\r\n else {\r\n options = args[0];\r\n callback = args[1];\r\n }\r\n\r\n if (Array.isArray(objs))\r\n objects = objs;\r\n else\r\n objects = [objs];\r\n\r\n options = options || {};\r\n _.defaults(options, {\r\n w: 'majority',\r\n forceServerObjectId: true\r\n });\r\n\r\n return Bluebird.resolve().then(() => {\r\n var queryOptions = { w: options.w, upsert: options.upsert, new: true };\r\n\r\n if (options.upsert) {\r\n var docs = this._handlers.creatingDocuments(objects);\r\n return docs.map((object: { _id: any; }) => {\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.findAndModify({ _id: object._id }, [\"_id\"], object, queryOptions,(err, result) => {\r\n if (err) return reject(err);\r\n return resolve(result);\r\n });\r\n });\r\n });\r\n }\r\n else\r\n return this._handlers.creatingDocuments(objects).then(objects => _.chunk(objects, 1000)).map((objects: any[]) => {\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.insertMany(objects, queryOptions,(err, result) => {\r\n if (err) return reject(err);\r\n return resolve(result.ops);\r\n });\r\n });\r\n }).then(results => _.flatten(results));\r\n }).map((inserted: any) => {\r\n return this._handlers.documentReceived(null, inserted,(document, isNew?, isPartial?) => this._helpers.wrapDocument(document, isNew, isPartial), { cache: options.cache });\r\n }).then((results: TInstance[]) => {\r\n if (Array.isArray(objs)) return results;\r\n return results[0];\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Updates the documents in the backing collection which match the conditions using the given update instructions\r\n * @param {Object} conditions The conditions which determine which documents will be updated\r\n * @param {Object} changes The changes to make to the documents\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n */\r\n update(conditions: { _id?: any, [key: string]: any } | any, changes: any, callback?: General.Callback): Bluebird;\r\n /**\r\n * Updates the documents in the backing collection which match the conditions using the given update instructions\r\n * @param {Object} conditions The conditions which determine which documents will be updated\r\n * @param {Object} changes The changes to make to the documents\r\n * @param {UpdateOptions} options The options which dictate how this function behaves\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n */\r\n update(conditions: { _id?: any, [key: string]: any } | any, changes: any, options: ModelOptions.UpdateOptions, callback?: General.Callback): Bluebird;\r\n update(conditions: { _id?: any, [key: string]: any } | any, changes: any, options?: ModelOptions.UpdateOptions, callback?: General.Callback): Bluebird {\r\n if (typeof options == 'function') {\r\n callback = >options;\r\n options = {};\r\n }\r\n\r\n options = options || {};\r\n\r\n if (!_.isPlainObject(conditions)) conditions = {\r\n _id: conditions\r\n };\r\n\r\n _.defaults(options, {\r\n w: 'majority',\r\n multi: true\r\n });\r\n\r\n return Bluebird.resolve().then(() => {\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.updateMany(conditions, changes, options,(err, response) => {\r\n if (err) return reject(err);\r\n\r\n // New MongoDB 2.6+ response type\r\n if (response.result && response.result.nModified !== undefined) return resolve(response.result.nModified);\r\n\r\n // Legacy response type\r\n return resolve(response.result.n);\r\n });\r\n })\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Counts the number of documents in the collection\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n count(callback?: General.Callback): Bluebird;\r\n /**\r\n * Counts the number of documents in the collection which match the conditions provided\r\n * @param {Object} conditions The conditions which determine whether an object is counted or not\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n count(conditions: { _id?: any, [key: string]: any } | any, callback?: General.Callback): Bluebird;\r\n count(conds?: any, callback?: General.Callback): Bluebird {\r\n var conditions: { _id?: any, [key: string]: any } = <{ _id?: any, [key: string]: any }>conds;\r\n if (typeof conds == 'function') {\r\n callback = >conds;\r\n conditions = {};\r\n }\r\n\r\n conditions = conditions || {};\r\n\r\n if (!_.isPlainObject(conditions)) conditions = {\r\n _id: conditions\r\n };\r\n\r\n return Bluebird.resolve().then(() => {\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.count(conditions,(err, results) => {\r\n if (err) return reject(err);\r\n return resolve(results);\r\n });\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Removes all documents from the collection\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n remove(callback?: General.Callback): Bluebird;\r\n /**\r\n * Removes all documents from the collection which match the conditions\r\n * @param {Object} conditions The conditions determining whether an object is removed or not\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n remove(conditions: { _id?: any, [key: string]: any } | any, callback?: General.Callback): Bluebird;\r\n /**\r\n * Removes all documents from the collection which match the conditions\r\n * @param {Object} conditions The conditions determining whether an object is removed or not\r\n * @param {Object} options The options controlling the way in which the function behaves\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n remove(conditions: { _id?: any, [key: string]: any }, options: ModelOptions.RemoveOptions, callback?: General.Callback): Bluebird;\r\n remove(conds?: any, options?: ModelOptions.RemoveOptions, callback?: General.Callback): Bluebird {\r\n var conditions: { _id?: any, [key: string]: any } = <{ _id?: any, [key: string]: any }>conds;\r\n\r\n if (typeof options === 'function') {\r\n callback = >options;\r\n options = {};\r\n }\r\n\r\n if (typeof conds == 'function') {\r\n callback = >conds;\r\n options = {};\r\n conditions = {};\r\n }\r\n\r\n conditions = conditions || {};\r\n options = options || {};\r\n\r\n _.defaults(options, {\r\n w: 'majority'\r\n });\r\n\r\n if (!_.isPlainObject(conditions)) conditions = {\r\n _id: conditions\r\n };\r\n\r\n return Bluebird.resolve().then(() => {\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.remove(conditions, options,(err, response) => {\r\n if (err) return reject(err);\r\n return resolve(response.result.n);\r\n });\r\n });\r\n }).then((count) => {\r\n if (count === 1) this._cache.clear(conditions);\r\n return Bluebird.resolve(count);\r\n }).nodeify(callback);\r\n }\r\n\r\n aggregate(pipeline: AggregationPipeline.Stage[]): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.aggregate(pipeline, (err, results) => {\r\n if(err) return reject(err);\r\n return resolve(results);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Ensures that the given index is created for the collection\r\n * @param {Object} specification The index specification object used by MongoDB\r\n * @param {function(Error, String)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} The name of the index\r\n */\r\n ensureIndex(specification: Index.IndexSpecification, callback?: General.Callback): Bluebird;\r\n /**\r\n * Ensures that the given index is created for the collection\r\n * @param {Object} specification The index specification object used by MongoDB\r\n * @param {MongoDB.IndexOptions} options The options dictating how the index is created and behaves\r\n * @param {function(Error, String)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} The name of the index\r\n */\r\n ensureIndex(specification: Index.IndexSpecification, options: MongoDB.IndexOptions, callback?: General.Callback): Bluebird;\r\n ensureIndex(specification: Index.IndexSpecification, options?: MongoDB.IndexOptions, callback?: General.Callback): Bluebird {\r\n if (typeof options == 'function') {\r\n callback = >options;\r\n options = {};\r\n }\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.ensureIndex(specification, options,(err, name: any) => {\r\n if (err) return reject(err);\r\n return resolve(name);\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Ensures that all indexes defined in the model's options are created\r\n * @param {function(Error, String[])} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} The names of the indexes\r\n */\r\n ensureIndexes(callback?: General.Callback): Bluebird {\r\n return Bluebird.resolve(this._indexes).map((index: Index.Index | Index.IndexSpecification) => {\r\n return this.ensureIndex((index).spec || index,(index).options || {});\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Drops the index with the specified name if it exists in the collection\r\n * @param {String} name The name of the index to remove\r\n * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} Whether the index was dropped\r\n */\r\n dropIndex(name: string, callback?: General.Callback): Bluebird;\r\n /**\r\n * Drops the index if it exists in the collection\r\n * @param {IndexSpecification} index The index to remove\r\n * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} Whether the index was dropped\r\n */\r\n dropIndex(index: Index.IndexSpecification, callback?: General.Callback): Bluebird;\r\n dropIndex(specification: string | Index.IndexSpecification, callback?: General.Callback): Bluebird {\r\n var index: string;\r\n\r\n if (typeof (specification) === 'string') index = specification;\r\n else {\r\n index = _(specification).map((direction, key) => key + '_' + direction).reduce((x, y) => x + '_' + y);\r\n }\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.dropIndex(index,(err, result: { ok: number }) => {\r\n if (err) return reject(err);\r\n return resolve(!!result.ok);\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Removes all indexes (except for _id) from the collection\r\n * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} Whether the indexes were dropped\r\n */\r\n dropIndexes(callback?: General.Callback): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.dropAllIndexes((err, count) => {\r\n if (err) return reject(err);\r\n return resolve(count);\r\n });\r\n }).nodeify(callback);\r\n }\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/Model.ts"],"names":[],"mappings":";AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,QAAQ,WAAW,U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,KAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,EAAC,UAAC,GAAG,EAAE,MAAsB;gBACxD,EAAE,CAAC,CAAC,GAAG,CAAC;oBAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC5B,MAAM,CAAC,OAAO,CAAM,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,2BAAW,GAAX,UAAY,QAAoC;QAAhD,iBAOC;QANG,MAAM,CAAC,IAAI,QAAQ,CAAM,UAAC,OAAO,EAAE,MAAM;YACrC,KAAI,CAAC,UAAU,CAAC,cAAc,CAAC,UAAC,GAAG,EAAE,KAAK;gBACtC,EAAE,CAAC,CAAC,GAAG,CAAC;oBAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC5B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IACL,YAAC;AAAD,CA3sBA,AA2sBC,IAAA;AA3sBY,aAAK,QA2sBjB,CAAA","file":"lib/Model.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\nimport util = require('util');\r\nimport _ = require('lodash');\r\nimport Skmatc = require('skmatc');\r\n\r\nimport {Core} from './Core';\r\nimport {Instance} from './Instance';\r\nimport {Schema} from './Schema';\r\nimport {Hooks} from './Hooks';\r\nimport {Plugin} from './Plugins';\r\nimport {Cache} from './Cache';\r\nimport {CacheDirector} from './CacheDirector';\r\nimport * as General from './General';\r\nimport {Cursor} from './Cursor';\r\nimport * as Index from './Index';\r\nimport * as ModelOptions from './ModelOptions';\r\n\r\nimport {Omnom} from './utils/Omnom';\r\nimport {ModelCache} from './ModelCache';\r\nimport {ModelHelpers} from './ModelHelpers';\r\nimport {ModelHandlers} from './ModelHandlers';\r\nimport * as ModelInterfaces from './ModelInterfaces';\r\nimport {ModelSpecificInstance} from './ModelSpecificInstance';\r\nimport {InstanceImplementation} from './InstanceInterface';\r\nimport {Transforms, DefaultTransforms} from './Transforms';\r\nimport * as AggregationPipeline from './Aggregate';\r\n\r\n/**\r\n * An Iridium Model which represents a structured MongoDB collection.\r\n * Models expose the methods you will generally use to query those collections, and ensure that\r\n * the results of those queries are returned as {TInstance} instances.\r\n *\r\n * @param TDocument The interface used to determine the schema of documents in the collection.\r\n * @param TInstance The interface or class used to represent collection documents in the JS world.\r\n *\r\n * @class\r\n */\r\nexport class Model {\r\n /**\r\n * Creates a new Iridium model representing a given ISchema and backed by a collection whose name is specified\r\n * @param core The Iridium core that this model should use for database access\r\n * @param instanceType The class which will be instantiated for each document retrieved from the database\r\n * @constructor\r\n */\r\n constructor(core: Core, instanceType: InstanceImplementation) {\r\n if (!(core instanceof Core)) throw new Error(\"You failed to provide a valid Iridium core for this model\");\r\n if (typeof instanceType != 'function') throw new Error(\"You failed to provide a valid instance constructor for this model\");\r\n if (typeof instanceType.collection != 'string' || !instanceType.collection) throw new Error(\"You failed to provide a valid collection name for this model\");\r\n if (!_.isPlainObject(instanceType.schema) || instanceType.schema._id === undefined) throw new Error(\"You failed to provide a valid schema for this model\");\r\n\r\n this._core = core;\r\n\r\n this.loadExternal(instanceType);\r\n this.onNewModel();\r\n this.loadInternal();\r\n }\r\n\r\n /**\r\n * Loads any externally available properties (generally accessed using public getters/setters).\r\n */\r\n private loadExternal(instanceType: InstanceImplementation) {\r\n this._collection = instanceType.collection;\r\n this._schema = instanceType.schema;\r\n this._hooks = instanceType;\r\n this._cacheDirector = instanceType.cache;\r\n this._transforms = instanceType.transforms || {};\r\n this._validators = instanceType.validators || [];\r\n this._indexes = instanceType.indexes || [];\r\n\r\n if(!this._schema._id) this._schema._id = MongoDB.ObjectID;\r\n\r\n if(this._schema._id === MongoDB.ObjectID && !this._transforms['_id'])\r\n this._transforms['_id'] = DefaultTransforms.ObjectID;\r\n\r\n if ((instanceType).prototype instanceof Instance)\r\n this._Instance = ModelSpecificInstance(this, instanceType);\r\n else\r\n this._Instance = instanceType.bind(undefined, this);\r\n }\r\n\r\n /**\r\n * Loads any internally (protected/private) properties and helpers only used within Iridium itself.\r\n */\r\n private loadInternal() {\r\n this._cache = new ModelCache(this);\r\n this._helpers = new ModelHelpers(this);\r\n this._handlers = new ModelHandlers(this);\r\n }\r\n\r\n /**\r\n * Process any callbacks and plugin delegation for the creation of this model.\r\n * It will generally be called whenever a new Iridium Core is created, however is\r\n * more specifically tied to the lifespan of the models themselves.\r\n */\r\n private onNewModel() {\r\n this._core.plugins.forEach(plugin => plugin.newModel && plugin.newModel(this));\r\n }\r\n\r\n private _helpers: ModelHelpers;\r\n /**\r\n * Provides helper methods used by Iridium for common tasks\r\n * @returns A set of helper methods which are used within Iridium for common tasks\r\n */\r\n get helpers(): ModelHelpers {\r\n return this._helpers;\r\n }\r\n\r\n private _handlers: ModelHandlers;\r\n /**\r\n * Provides helper methods used by Iridium for hook delegation and common processes\r\n * @returns A set of helper methods which perform common event and response handling tasks within Iridium.\r\n */\r\n get handlers(): ModelHandlers {\r\n return this._handlers;\r\n }\r\n\r\n private _hooks: Hooks = {};\r\n\r\n /**\r\n * Gets the even hooks subscribed on this model for a number of different state changes.\r\n * These hooks are primarily intended to allow lifecycle manipulation logic to be added\r\n * in the user's model definition, allowing tasks such as the setting of default values\r\n * or automatic client-side joins to take place.\r\n */\r\n get hooks(): Hooks {\r\n return this._hooks;\r\n }\r\n\r\n private _schema: Schema;\r\n /**\r\n * Gets the schema dictating the data structure represented by this model.\r\n * The schema is used by skmatc to validate documents before saving to the database, however\r\n * until MongoDB 3.1 becomes widely available (with server side validation support) we are\r\n * limited in our ability to validate certain types of updates. As such, these validations\r\n * act more as a data-integrity check than anything else, unless you purely make use of Omnom\r\n * updates within instances.\r\n * @public\r\n * @returns The defined validation schema for this model\r\n */\r\n get schema(): Schema {\r\n return this._schema;\r\n }\r\n\r\n private _core: Core;\r\n /**\r\n * Gets the Iridium core that this model is associated with.\r\n * @public\r\n * @returns The Iridium core that this model is bound to\r\n */\r\n get core(): Core {\r\n return this._core;\r\n }\r\n\r\n private _collection: string;\r\n /**\r\n * Gets the underlying MongoDB collection from which this model's documents are retrieved.\r\n * You can make use of this object if you require any low level access to the MongoDB collection,\r\n * however we recommend you make use of the Iridium methods whereever possible, as we cannot\r\n * guarantee the accuracy of the type definitions for the underlying MongoDB driver.\r\n * @public\r\n * @returns {Collection}\r\n */\r\n get collection(): MongoDB.Collection {\r\n if (!this.core.connection) throw new Error(\"Iridium Core not connected to a database.\");\r\n return this.core.connection.collection(this._collection);\r\n }\r\n\r\n /**\r\n * Gets the name of the underlying MongoDB collection from which this model's documents are retrieved\r\n * @public\r\n */\r\n get collectionName(): string {\r\n return this._collection;\r\n }\r\n\r\n /**\r\n * Sets the name of the underlying MongoDB collection from which this model's documents are retrieved\r\n * @public\r\n */\r\n set collectionName(value: string) {\r\n this._collection = value;\r\n }\r\n\r\n private _cacheDirector: CacheDirector;\r\n /**\r\n * Gets the cache controller which dictates which queries will be cached, and under which key\r\n * @public\r\n * @returns {CacheDirector}\r\n */\r\n get cacheDirector(): CacheDirector {\r\n return this._cacheDirector;\r\n }\r\n\r\n private _cache: ModelCache;\r\n /**\r\n * Gets the cache responsible for storing objects for quick retrieval under certain conditions\r\n * @public\r\n * @returns {ModelCache}\r\n */\r\n get cache(): ModelCache {\r\n return this._cache;\r\n }\r\n\r\n private _Instance: ModelInterfaces.ModelSpecificInstanceConstructor;\r\n\r\n /**\r\n * Gets the constructor responsible for creating instances for this model\r\n */\r\n get Instance(): ModelInterfaces.ModelSpecificInstanceConstructor {\r\n return this._Instance;\r\n }\r\n\r\n private _transforms: Transforms;\r\n\r\n /**\r\n * Gets the transforms which are applied whenever a document is received from the database, or\r\n * prior to storing a document in the database. Tasks such as converting an ObjectID to a string\r\n * and vice versa are all listed in this object.\r\n */\r\n get transforms() {\r\n return this._transforms;\r\n }\r\n\r\n private _validators: Skmatc.Validator[];\r\n\r\n /**\r\n * Gets the custom validation types available for this model. These validators are added to the\r\n * default skmatc validators, as well as those available through plugins, for use when checking\r\n * your instances.\r\n */\r\n get validators() {\r\n return this._validators;\r\n }\r\n\r\n private _indexes: (Index.Index | Index.IndexSpecification)[];\r\n\r\n /**\r\n * Gets the indexes which Iridium will manage on this model's database collection.\r\n */\r\n get indexes() {\r\n return this._indexes;\r\n }\r\n\r\n /**\r\n * Retrieves all documents in the collection and wraps them as instances\r\n * @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available\r\n * @returns {Promise}\r\n */\r\n find(): Cursor;\r\n /**\r\n * Returns all documents in the collection which match the conditions and wraps them as instances\r\n * @param {Object} conditions The MongoDB query dictating which documents to return\r\n * @returns {Promise}\r\n */\r\n find(conditions: { _id?: any, [key: string]: any } | any): Cursor;\r\n /**\r\n * Returns all documents in the collection which match the conditions\r\n * @param {Object} conditions The MongoDB query dictating which documents to return\r\n * @param {Object} fields The fields to include or exclude from the document\r\n * @returns {Promise}\r\n */\r\n find(conditions: { _id?: any, [key: string]: any } | any, fields: { [name: string]: number }): Cursor;\r\n find(conditions?: { _id?: any, [key: string]: any } | any, fields?: any): Cursor {\r\n conditions = conditions || {};\r\n fields = fields || {};\r\n\r\n if (!_.isPlainObject(conditions)) conditions = { _id: conditions };\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n var cursor = this.collection.find(conditions, {\r\n fields: fields\r\n });\r\n\r\n return new Cursor(this, conditions, cursor);\r\n }\r\n\r\n /**\r\n * Retrieves a single document from the collection and wraps it as an instance\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection with the given ID and wraps it as an instance\r\n * @param {any} id The document's unique _id field value in downstream format\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(id: any, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection which matches the conditions\r\n * @param {Object} conditions The MongoDB query dictating which document to return\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(conditions: { _id?: any, [key: string]: any }, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection with the given ID and wraps it as an instance\r\n * @param {any} id The document's unique _id field value in downstream format\r\n * @param {QueryOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(id: any, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection which matches the conditions\r\n * @param {Object} conditions The MongoDB query dictating which document to return\r\n * @param {QueryOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n get(conditions: { _id?: any, [key: string]: any }, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird;\r\n get(...args: any[]): Bluebird {\r\n return this.findOne.apply(this, args);\r\n }\r\n\r\n /**\r\n * Retrieves a single document from the collection and wraps it as an instance\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection with the given ID and wraps it as an instance\r\n * @param {any} id The document's unique _id field value in downstream format\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(id: any, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection which matches the conditions\r\n * @param {Object} conditions The MongoDB query dictating which document to return\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(conditions: { _id?: any, [key: string]: any }, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection with the given ID and wraps it as an instance\r\n * @param {any} id The document's unique _id field value in downstream format\r\n * @param {QueryOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(id: any, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird;\r\n /**\r\n * Retrieves a single document from the collection which matches the conditions\r\n * @param {Object} conditions The MongoDB query dictating which document to return\r\n * @param {QueryOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available\r\n * @returns {Promise}\r\n */\r\n findOne(conditions: { _id?: any, [key: string]: any }, options: ModelOptions.QueryOptions, callback?: General.Callback): Bluebird;\r\n findOne(...args: any[]): Bluebird {\r\n var conditions: { _id?: any, [key: string]: any } = null;\r\n var options: ModelOptions.QueryOptions = null;\r\n var callback: General.Callback = null;\r\n\r\n for (var argI = 0; argI < args.length; argI++) {\r\n if (typeof args[argI] == 'function') callback = callback || args[argI];\r\n else if (_.isPlainObject(args[argI])) {\r\n if (conditions) options = args[argI];\r\n else conditions = args[argI];\r\n }\r\n else conditions = { _id: args[argI] };\r\n }\r\n\r\n conditions = conditions || {};\r\n options = options || {};\r\n\r\n _.defaults(options, {\r\n cache: true\r\n });\r\n\r\n return Bluebird.resolve().bind(this).then(() => {\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n return this._cache.get(conditions);\r\n }).then((cachedDocument: TDocument) => {\r\n if (cachedDocument) return cachedDocument;\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.findOne(conditions, {\r\n fields: options.fields,\r\n skip: options.skip,\r\n sort: options.sort,\r\n limit: options.limit\r\n },(err, result) => {\r\n if (err) return reject(err);\r\n return resolve(result);\r\n });\r\n });\r\n }).then((document: TDocument) => {\r\n if (!document) return null;\r\n return this._handlers.documentReceived(conditions, document,(document, isNew?, isPartial?) => this._helpers.wrapDocument(document, isNew, isPartial), options);\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Inserts an object into the collection after validating it against this model's schema\r\n * @param {Object} object The object to insert into the collection\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n create(objects: TDocument, callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts an object into the collection after validating it against this model's schema\r\n * @param {Object} object The object to insert into the collection\r\n * @param {CreateOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n create(objects: TDocument, options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts the objects into the collection after validating them against this model's schema\r\n * @param {Object[]} objects The objects to insert into the collection\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n create(objects: TDocument[], callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts the objects into the collection after validating them against this model's schema\r\n * @param {Object[]} objects The objects to insert into the collection\r\n * @param {CreateOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n create(objects: TDocument[], options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird;\r\n create(...args: any[]): Bluebird {\r\n return this.insert.apply(this, args);\r\n }\r\n\r\n /**\r\n * Inserts an object into the collection after validating it against this model's schema\r\n * @param {Object} object The object to insert into the collection\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n insert(objects: TDocument, callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts an object into the collection after validating it against this model's schema\r\n * @param {Object} object The object to insert into the collection\r\n * @param {CreateOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n insert(objects: TDocument, options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts the objects into the collection after validating them against this model's schema\r\n * @param {Object[]} objects The objects to insert into the collection\r\n * @param {function(Error, TInstance[])} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n insert(objects: TDocument[], callback?: General.Callback): Bluebird;\r\n /**\r\n * Inserts the objects into the collection after validating them against this model's schema\r\n * @param {Object[]} objects The objects to insert into the collection\r\n * @param {CreateOptions} options The options dictating how this function behaves\r\n * @param {function(Error, TInstance[])} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n insert(objects: TDocument[], options: ModelOptions.CreateOptions, callback?: General.Callback): Bluebird;\r\n insert(objs: TDocument | TDocument[], ...args: any[]): Bluebird {\r\n var objects: TDocument[];\r\n var options: ModelOptions.CreateOptions = {};\r\n var callback: General.Callback = null;\r\n if (typeof args[0] == 'function') callback = args[0];\r\n else {\r\n options = args[0];\r\n callback = args[1];\r\n }\r\n\r\n if (Array.isArray(objs))\r\n objects = objs;\r\n else\r\n objects = [objs];\r\n\r\n options = options || {};\r\n _.defaults(options, {\r\n w: 'majority',\r\n forceServerObjectId: true\r\n });\r\n\r\n return Bluebird.resolve().then(() => {\r\n var queryOptions = { w: options.w, upsert: options.upsert, new: true };\r\n\r\n if (options.upsert) {\r\n var docs = this._handlers.creatingDocuments(objects);\r\n return docs.map((object: { _id: any; }) => {\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.findAndModify({ _id: object._id }, [\"_id\"], object, queryOptions,(err, result) => {\r\n if (err) return reject(err);\r\n return resolve(result);\r\n });\r\n });\r\n });\r\n }\r\n else\r\n return this._handlers.creatingDocuments(objects).then(objects => _.chunk(objects, 1000)).map((objects: any[]) => {\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.insertMany(objects, queryOptions,(err, result) => {\r\n if (err) return reject(err);\r\n return resolve(result.ops);\r\n });\r\n });\r\n }).then(results => _.flatten(results));\r\n }).map((inserted: any) => {\r\n return this._handlers.documentReceived(null, inserted,(document, isNew?, isPartial?) => this._helpers.wrapDocument(document, isNew, isPartial), { cache: options.cache });\r\n }).then((results: TInstance[]) => {\r\n if (Array.isArray(objs)) return results;\r\n return results[0];\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Updates the documents in the backing collection which match the conditions using the given update instructions\r\n * @param {Object} conditions The conditions which determine which documents will be updated\r\n * @param {Object} changes The changes to make to the documents\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n */\r\n update(conditions: { _id?: any, [key: string]: any } | any, changes: any, callback?: General.Callback): Bluebird;\r\n /**\r\n * Updates the documents in the backing collection which match the conditions using the given update instructions\r\n * @param {Object} conditions The conditions which determine which documents will be updated\r\n * @param {Object} changes The changes to make to the documents\r\n * @param {UpdateOptions} options The options which dictate how this function behaves\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n */\r\n update(conditions: { _id?: any, [key: string]: any } | any, changes: any, options: ModelOptions.UpdateOptions, callback?: General.Callback): Bluebird;\r\n update(conditions: { _id?: any, [key: string]: any } | any, changes: any, options?: ModelOptions.UpdateOptions, callback?: General.Callback): Bluebird {\r\n if (typeof options == 'function') {\r\n callback = >options;\r\n options = {};\r\n }\r\n\r\n options = options || {};\r\n\r\n if (!_.isPlainObject(conditions)) conditions = {\r\n _id: conditions\r\n };\r\n\r\n _.defaults(options, {\r\n w: 'majority',\r\n multi: true\r\n });\r\n\r\n return Bluebird.resolve().then(() => {\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.updateMany(conditions, changes, options,(err, response) => {\r\n if (err) return reject(err);\r\n\r\n // New MongoDB 2.6+ response type\r\n if (response.result && response.result.nModified !== undefined) return resolve(response.result.nModified);\r\n\r\n // Legacy response type\r\n return resolve(response.result.n);\r\n });\r\n })\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Counts the number of documents in the collection\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n count(callback?: General.Callback): Bluebird;\r\n /**\r\n * Counts the number of documents in the collection which match the conditions provided\r\n * @param {Object} conditions The conditions which determine whether an object is counted or not\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n count(conditions: { _id?: any, [key: string]: any } | any, callback?: General.Callback): Bluebird;\r\n count(conds?: any, callback?: General.Callback): Bluebird {\r\n var conditions: { _id?: any, [key: string]: any } = <{ _id?: any, [key: string]: any }>conds;\r\n if (typeof conds == 'function') {\r\n callback = >conds;\r\n conditions = {};\r\n }\r\n\r\n conditions = conditions || {};\r\n\r\n if (!_.isPlainObject(conditions)) conditions = {\r\n _id: conditions\r\n };\r\n\r\n return Bluebird.resolve().then(() => {\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.count(conditions,(err, results) => {\r\n if (err) return reject(err);\r\n return resolve(results);\r\n });\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Removes all documents from the collection\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n remove(callback?: General.Callback): Bluebird;\r\n /**\r\n * Removes all documents from the collection which match the conditions\r\n * @param {Object} conditions The conditions determining whether an object is removed or not\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n remove(conditions: { _id?: any, [key: string]: any } | any, callback?: General.Callback): Bluebird;\r\n /**\r\n * Removes all documents from the collection which match the conditions\r\n * @param {Object} conditions The conditions determining whether an object is removed or not\r\n * @param {Object} options The options controlling the way in which the function behaves\r\n * @param {function(Error, Number)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise}\r\n */\r\n remove(conditions: { _id?: any, [key: string]: any }, options: ModelOptions.RemoveOptions, callback?: General.Callback): Bluebird;\r\n remove(conds?: any, options?: ModelOptions.RemoveOptions, callback?: General.Callback): Bluebird {\r\n var conditions: { _id?: any, [key: string]: any } = <{ _id?: any, [key: string]: any }>conds;\r\n\r\n if (typeof options === 'function') {\r\n callback = >options;\r\n options = {};\r\n }\r\n\r\n if (typeof conds == 'function') {\r\n callback = >conds;\r\n options = {};\r\n conditions = {};\r\n }\r\n\r\n conditions = conditions || {};\r\n options = options || {};\r\n\r\n _.defaults(options, {\r\n w: 'majority'\r\n });\r\n\r\n if (!_.isPlainObject(conditions)) conditions = {\r\n _id: conditions\r\n };\r\n\r\n return Bluebird.resolve().then(() => {\r\n conditions = this._helpers.convertToDB(conditions);\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.remove(conditions, options,(err, response) => {\r\n if (err) return reject(err);\r\n return resolve(response.result.n);\r\n });\r\n });\r\n }).then((count) => {\r\n if (count === 1) this._cache.clear(conditions);\r\n return Bluebird.resolve(count);\r\n }).nodeify(callback);\r\n }\r\n\r\n aggregate(pipeline: AggregationPipeline.Stage[]): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.aggregate(pipeline, (err, results) => {\r\n if(err) return reject(err);\r\n return resolve(results);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Ensures that the given index is created for the collection\r\n * @param {Object} specification The index specification object used by MongoDB\r\n * @param {function(Error, String)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} The name of the index\r\n */\r\n ensureIndex(specification: Index.IndexSpecification, callback?: General.Callback): Bluebird;\r\n /**\r\n * Ensures that the given index is created for the collection\r\n * @param {Object} specification The index specification object used by MongoDB\r\n * @param {MongoDB.IndexOptions} options The options dictating how the index is created and behaves\r\n * @param {function(Error, String)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} The name of the index\r\n */\r\n ensureIndex(specification: Index.IndexSpecification, options: MongoDB.IndexOptions, callback?: General.Callback): Bluebird;\r\n ensureIndex(specification: Index.IndexSpecification, options?: MongoDB.IndexOptions, callback?: General.Callback): Bluebird {\r\n if (typeof options == 'function') {\r\n callback = >options;\r\n options = {};\r\n }\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.ensureIndex(specification, options,(err, name: any) => {\r\n if (err) return reject(err);\r\n return resolve(name);\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Ensures that all indexes defined in the model's options are created\r\n * @param {function(Error, String[])} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} The names of the indexes\r\n */\r\n ensureIndexes(callback?: General.Callback): Bluebird {\r\n return Bluebird.resolve(this._indexes).map((index: Index.Index | Index.IndexSpecification) => {\r\n return this.ensureIndex((index).spec || index,(index).options || {});\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Drops the index with the specified name if it exists in the collection\r\n * @param {String} name The name of the index to remove\r\n * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} Whether the index was dropped\r\n */\r\n dropIndex(name: string, callback?: General.Callback): Bluebird;\r\n /**\r\n * Drops the index if it exists in the collection\r\n * @param {IndexSpecification} index The index to remove\r\n * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} Whether the index was dropped\r\n */\r\n dropIndex(index: Index.IndexSpecification, callback?: General.Callback): Bluebird;\r\n dropIndex(specification: string | Index.IndexSpecification, callback?: General.Callback): Bluebird {\r\n var index: string;\r\n\r\n if (typeof (specification) === 'string') index = specification;\r\n else {\r\n index = _(specification).map((direction, key) => key + '_' + direction).reduce((x, y) => x + '_' + y);\r\n }\r\n\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.dropIndex(index,(err, result: { ok: number }) => {\r\n if (err) return reject(err);\r\n return resolve(!!result.ok);\r\n });\r\n }).nodeify(callback);\r\n }\r\n\r\n /**\r\n * Removes all indexes (except for _id) from the collection\r\n * @param {function(Error, Boolean)} callback A callback which is triggered when the operation completes\r\n * @returns {Promise} Whether the indexes were dropped\r\n */\r\n dropIndexes(callback?: General.Callback): Bluebird {\r\n return new Bluebird((resolve, reject) => {\r\n this.collection.dropAllIndexes((err, count) => {\r\n if (err) return reject(err);\r\n return resolve(count);\r\n });\r\n }).nodeify(callback);\r\n }\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/ModelCache.js b/dist/lib/ModelCache.js index 35a9926..8620df2 100644 --- a/dist/lib/ModelCache.js +++ b/dist/lib/ModelCache.js @@ -1,3 +1,4 @@ +"use strict"; var Bluebird = require('bluebird'); /** * A centralized class which ties the cache and cache directors together in a cohesive way @@ -24,7 +25,7 @@ var ModelCache = (function () { this.model.core.cache.clear(this.model.cacheDirector.buildQueryKey(conditions)); }; return ModelCache; -})(); +}()); exports.ModelCache = ModelCache; //# sourceMappingURL=ModelCache.js.map diff --git a/dist/lib/ModelCache.js.map b/dist/lib/ModelCache.js.map index 43bb7a8..a95c015 100644 --- a/dist/lib/ModelCache.js.map +++ b/dist/lib/ModelCache.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/ModelCache.ts"],"names":["ModelCache","ModelCache.constructor","ModelCache.set","ModelCache.get","ModelCache.clear"],"mappings":"AACA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAEtC;;;;GAIG;AACH;IACIA,oBAAmBA,KAAqBA;QAArBC,UAAKA,GAALA,KAAKA,CAAgBA;IAExCA,CAACA;IAEDD,wBAAGA,GAAHA,UAAOA,KAAQA;QACXE,EAAEA,CAACA,CAACA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,IAAIA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,KAAKA,CAACA,KAAKA,CAACA,CAACA;YAACA,MAAMA,CAACA;QAChFA,IAAIA,CAACA,KAAKA,CAACA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,QAAQA,CAACA,KAAKA,CAACA,EAAEA,KAAKA,CAACA,CAACA;IAC/EA,CAACA;IAEDF,wBAAGA,GAAHA,UAAOA,UAAeA;QAClBG,EAAEA,CAACA,CAACA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,IAAIA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,UAAUA,CAACA,UAAUA,CAACA,CAACA;YAACA,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAAIA,IAAIA,CAACA,CAACA;QACpHA,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAACA,IAAIA,CAACA,KAAKA,CAACA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAAIA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,aAAaA,CAACA,UAAUA,CAACA,CAACA,CAACA,CAACA;IAC9GA,CAACA;IAEDH,0BAAKA,GAALA,UAAMA,UAAeA;QACjBI,EAAEA,CAACA,CAACA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,IAAIA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,UAAUA,CAACA,UAAUA,CAACA,CAACA;YAACA,MAAMA,CAACA;QAC1FA,IAAIA,CAACA,KAAKA,CAACA,IAAIA,CAACA,KAAKA,CAACA,KAAKA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,aAAaA,CAACA,UAAUA,CAACA,CAACA,CAACA;IACpFA,CAACA;IACLJ,iBAACA;AAADA,CAnBA,AAmBCA,IAAA;AAnBY,kBAAU,aAmBtB,CAAA","file":"lib/ModelCache.js","sourcesContent":["import {Model} from './Model';\r\nimport Bluebird = require('bluebird');\r\n\r\n/**\r\n * A centralized class which ties the cache and cache directors together in a cohesive way\r\n * for use by Iridium.\r\n * @internal\r\n */\r\nexport class ModelCache {\r\n constructor(public model: Model) {\r\n\r\n }\r\n\r\n set(value: T): void {\r\n if (!this.model.cacheDirector || !this.model.cacheDirector.valid(value)) return;\r\n this.model.core.cache.set(this.model.cacheDirector.buildKey(value), value);\r\n }\r\n\r\n get(conditions: any): Bluebird {\r\n if (!this.model.cacheDirector || !this.model.cacheDirector.validQuery(conditions)) return Bluebird.resolve(null);\r\n return Bluebird.resolve(this.model.core.cache.get(this.model.cacheDirector.buildQueryKey(conditions)));\r\n }\r\n\r\n clear(conditions: any): void {\r\n if (!this.model.cacheDirector || !this.model.cacheDirector.validQuery(conditions)) return;\r\n this.model.core.cache.clear(this.model.cacheDirector.buildQueryKey(conditions));\r\n }\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/ModelCache.ts"],"names":[],"mappings":";AACA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAEtC;;;;GAIG;AACH;IACI,oBAAmB,KAAqB;QAArB,UAAK,GAAL,KAAK,CAAgB;IAExC,CAAC;IAED,wBAAG,GAAH,UAAO,KAAQ;QACX,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAAC,MAAM,CAAC;QAChF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/E,CAAC;IAED,wBAAG,GAAH,UAAO,UAAe;QAClB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAI,IAAI,CAAC,CAAC;QACpH,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9G,CAAC;IAED,0BAAK,GAAL,UAAM,UAAe;QACjB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAAC,MAAM,CAAC;QAC1F,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;IACpF,CAAC;IACL,iBAAC;AAAD,CAnBA,AAmBC,IAAA;AAnBY,kBAAU,aAmBtB,CAAA","file":"lib/ModelCache.js","sourcesContent":["import {Model} from './Model';\r\nimport Bluebird = require('bluebird');\r\n\r\n/**\r\n * A centralized class which ties the cache and cache directors together in a cohesive way\r\n * for use by Iridium.\r\n * @internal\r\n */\r\nexport class ModelCache {\r\n constructor(public model: Model) {\r\n\r\n }\r\n\r\n set(value: T): void {\r\n if (!this.model.cacheDirector || !this.model.cacheDirector.valid(value)) return;\r\n this.model.core.cache.set(this.model.cacheDirector.buildKey(value), value);\r\n }\r\n\r\n get(conditions: any): Bluebird {\r\n if (!this.model.cacheDirector || !this.model.cacheDirector.validQuery(conditions)) return Bluebird.resolve(null);\r\n return Bluebird.resolve(this.model.core.cache.get(this.model.cacheDirector.buildQueryKey(conditions)));\r\n }\r\n\r\n clear(conditions: any): void {\r\n if (!this.model.cacheDirector || !this.model.cacheDirector.validQuery(conditions)) return;\r\n this.model.core.cache.clear(this.model.cacheDirector.buildQueryKey(conditions));\r\n }\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/ModelHandlers.js b/dist/lib/ModelHandlers.js index 27162a4..b34ecd0 100644 --- a/dist/lib/ModelHandlers.js +++ b/dist/lib/ModelHandlers.js @@ -1,3 +1,4 @@ +"use strict"; var _ = require('lodash'); var Bluebird = require('bluebird'); /** @@ -61,7 +62,7 @@ var ModelHandlers = (function () { }); }; return ModelHandlers; -})(); +}()); exports.ModelHandlers = ModelHandlers; //# sourceMappingURL=ModelHandlers.js.map diff --git a/dist/lib/ModelHandlers.js.map b/dist/lib/ModelHandlers.js.map index 6af7cf2..078fcaf 100644 --- a/dist/lib/ModelHandlers.js.map +++ b/dist/lib/ModelHandlers.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/ModelHandlers.ts"],"names":["ModelHandlers","ModelHandlers.constructor","ModelHandlers.documentReceived","ModelHandlers.creatingDocuments","ModelHandlers.savingDocument"],"mappings":"AAOA,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAE7B,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAEtC;;;;;;;GAOG;AACH;IACIA,uBAAmBA,KAAkCA;QAAlCC,UAAKA,GAALA,KAAKA,CAA6BA;IAErDA,CAACA;IAEDD,wCAAgBA,GAAhBA,UAA0BA,UAAeA,EACrCA,MAAiBA,EACjBA,OAA+EA,EAC/EA,OAAuCA;QAH3CE,iBA+BCA;QA5BGA,uBAAuCA,GAAvCA,YAAuCA;QACvCA,CAACA,CAACA,QAAQA,CAACA,OAAOA,EAAEA;YAChBA,KAAKA,EAAEA,IAAIA;YACXA,OAAOA,EAAEA,KAAKA;SACjBA,CAACA,CAACA;QAEHA,IAAIA,OAAgBA,CAACA;QACrBA,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAACA,IAAIA,CAACA,KAAKA,CAACA,OAAOA,CAACA,eAAeA,CAACA,MAAMA,EAAEA,EAAEA,QAAQA,EAAEA,IAAIA,EAAEA,CAACA,CAACA,CAACA,IAAIA,CAACA,UAACA,MAAWA;YACrGA,MAAMA,CAAoBA,QAAQA;iBAE7BA,OAAOA,CAACA,KAAIA,CAACA,KAAKA,CAACA,KAAKA,CAACA,WAAWA,IAAIA,KAAIA,CAACA,KAAKA,CAACA,KAAKA,CAACA,WAAWA,CAACA,MAAMA,CAACA,CAACA;iBAC7EA,IAAIA,CAACA;gBACFA,2CAA2CA;gBAC3CA,EAAEA,CAACA,CAACA,KAAIA,CAACA,KAAKA,CA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A,EAAEA,CAACA,CAACA;gBAC1FA,IAAIA,UAAUA,GAAkBA,KAAIA,CAACA,KAAKA,CAACA,OAAOA,CAACA,QAAQA,CAACA,QAAQA,CAACA,CAACA;gBACtEA,EAAEA,CAACA,CAACA,UAAUA,CAACA,MAAMA,CAACA;oBAACA,MAAMA,CAACA,QAAQA,CAACA,MAAMA,CAACA,UAAUA,CAACA,KAAKA,CAACA,CAACA;gBAEhEA,MAAMA,CAACA,QAAQA,CAACA;YACpBA,CAACA,CAACA,CAACA;QACXA,CAACA,CAACA,CAACA,CAACA;IACRA,CAACA;IAEDH,sCAAcA,GAAdA,UAAeA,QAAmBA,EAAEA,OAAYA;QAC5CI,MAAMA,CAACA,QAAQA;aAEVA,OAAOA,CAACA,IAAIA,CAACA,KAAKA,CAACA,KAAKA,CAACA,QAAQA,IAAIA,IAAIA,CAACA,KAAKA,CAACA,KAAKA,CAACA,QAAQA,CAACA,QAAQA,EAAEA,OAAOA,CAACA,CAACA;aAClFA,IAAIA,CAACA;YACFA,MAAMA,CAACA,QAAQA,CAACA;QACpBA,CAACA,CAACA,CAACA;IACXA,CAACA;IACLJ,oBAACA;AAADA,CA7DA,AA6DCA,IAAA;AA7DY,qBAAa,gBA6DzB,CAAA","file":"lib/ModelHandlers.js","sourcesContent":["import {Core} from './Core';\r\nimport {Schema} from './Schema';\r\nimport {Model} from './Model';\r\nimport {ModelCache} from './ModelCache';\r\nimport * as ModelOptions from './ModelOptions';\r\n\r\nimport Skmatc = require('skmatc');\r\nimport _ = require('lodash');\r\nimport MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\n\r\n/**\r\n * Provides a number of methods which are used to handle events that occur within\r\n * the Iridium workflow - such as what happens when a document is received from\r\n * the database, or how to handle the creation of new documents and saving of instances.\r\n *\r\n * Mostly this is for cache support, wrapping and hook triggering.\r\n * @internal\r\n */\r\nexport class ModelHandlers {\r\n constructor(public model: Model) {\r\n\r\n }\r\n\r\n documentReceived(conditions: any,\r\n result: TDocument,\r\n wrapper: (document: TDocument, isNew?: boolean, isPartial?: boolean) => TResult,\r\n options: ModelOptions.QueryOptions = {}): Bluebird {\r\n _.defaults(options, {\r\n cache: true,\r\n partial: false\r\n });\r\n\r\n let wrapped: TResult;\r\n return Bluebird.resolve(this.model.helpers.transformFromDB(result, { document: true })).then((target: any) => {\r\n return >Bluebird\r\n // If onRetrieved returns a Bluebird promise then there is no significant performance overhead here\r\n .resolve(this.model.hooks.onRetrieved && this.model.hooks.onRetrieved(target))\r\n .then(() => {\r\n // Cache the document if caching is enabled\r\n if (this.model.core.cache && options.cache && !options.fields) {\r\n this.model.cache.set(target); // Does not block execution pipeline - fire and forget\r\n }\r\n\r\n // Wrap the document and trigger the ready hook\r\n let wrapped: TResult = wrapper(target, false, !!options.fields);\r\n\r\n // Only incur the additional promise's performance penalty if this hook is being used\r\n if (this.model.hooks.onReady)\r\n return Bluebird\r\n .resolve(this.model.hooks.onReady(wrapped))\r\n .then(() => wrapped);\r\n return wrapped;\r\n });\r\n });\r\n }\r\n\r\n creatingDocuments(documents: TDocument[]): Bluebird {\r\n return Bluebird.all(documents.map((document: any) => {\r\n return Bluebird\r\n // If onCreating returns a Bluebird promise then there is no significant performance overhead here\r\n .resolve(this.model.hooks.onCreating && this.model.hooks.onCreating(document))\r\n .then(() => {\r\n document = this.model.helpers.convertToDB(document, { document: true, properties: true });\r\n let validation: Skmatc.Result = this.model.helpers.validate(document);\r\n if (validation.failed) return Bluebird.reject(validation.error);\r\n\r\n return document;\r\n });\r\n }));\r\n }\r\n\r\n savingDocument(instance: TInstance, changes: any): Bluebird {\r\n return Bluebird\r\n // If onSaving returns a Bluebird promise then there is no significant performance overhead here\r\n .resolve(this.model.hooks.onSaving && this.model.hooks.onSaving(instance, changes))\r\n .then(() => {\r\n return instance;\r\n });\r\n }\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/ModelHandlers.ts"],"names":[],"mappings":";AAOA,IAAO,CAAC,WAAW,Q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,EAAE,OAAO,CAAC,CAAC;aAClF,IAAI,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC;QACpB,CAAC,CAAC,CAAC;IACX,CAAC;IACL,oBAAC;AAAD,CA7DA,AA6DC,IAAA;AA7DY,qBAAa,gBA6DzB,CAAA","file":"lib/ModelHandlers.js","sourcesContent":["import {Core} from './Core';\r\nimport {Schema} from './Schema';\r\nimport {Model} from './Model';\r\nimport {ModelCache} from './ModelCache';\r\nimport * as ModelOptions from './ModelOptions';\r\n\r\nimport Skmatc = require('skmatc');\r\nimport _ = require('lodash');\r\nimport MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\n\r\n/**\r\n * Provides a number of methods which are used to handle events that occur within\r\n * the Iridium workflow - such as what happens when a document is received from\r\n * the database, or how to handle the creation of new documents and saving of instances.\r\n *\r\n * Mostly this is for cache support, wrapping and hook triggering.\r\n * @internal\r\n */\r\nexport class ModelHandlers {\r\n constructor(public model: Model) {\r\n\r\n }\r\n\r\n documentReceived(conditions: any,\r\n result: TDocument,\r\n wrapper: (document: TDocument, isNew?: boolean, isPartial?: boolean) => TResult,\r\n options: ModelOptions.QueryOptions = {}): Bluebird {\r\n _.defaults(options, {\r\n cache: true,\r\n partial: false\r\n });\r\n\r\n let wrapped: TResult;\r\n return Bluebird.resolve(this.model.helpers.transformFromDB(result, { document: true })).then((target: any) => {\r\n return >Bluebird\r\n // If onRetrieved returns a Bluebird promise then there is no significant performance overhead here\r\n .resolve(this.model.hooks.onRetrieved && this.model.hooks.onRetrieved(target))\r\n .then(() => {\r\n // Cache the document if caching is enabled\r\n if (this.model.core.cache && options.cache && !options.fields) {\r\n this.model.cache.set(target); // Does not block execution pipeline - fire and forget\r\n }\r\n\r\n // Wrap the document and trigger the ready hook\r\n let wrapped: TResult = wrapper(target, false, !!options.fields);\r\n\r\n // Only incur the additional promise's performance penalty if this hook is being used\r\n if (this.model.hooks.onReady)\r\n return Bluebird\r\n .resolve(this.model.hooks.onReady(wrapped))\r\n .then(() => wrapped);\r\n return wrapped;\r\n });\r\n });\r\n }\r\n\r\n creatingDocuments(documents: TDocument[]): Bluebird {\r\n return Bluebird.all(documents.map((document: any) => {\r\n return Bluebird\r\n // If onCreating returns a Bluebird promise then there is no significant performance overhead here\r\n .resolve(this.model.hooks.onCreating && this.model.hooks.onCreating(document))\r\n .then(() => {\r\n document = this.model.helpers.convertToDB(document, { document: true, properties: true });\r\n let validation: Skmatc.Result = this.model.helpers.validate(document);\r\n if (validation.failed) return Bluebird.reject(validation.error);\r\n\r\n return document;\r\n });\r\n }));\r\n }\r\n\r\n savingDocument(instance: TInstance, changes: any): Bluebird {\r\n return Bluebird\r\n // If onSaving returns a Bluebird promise then there is no significant performance overhead here\r\n .resolve(this.model.hooks.onSaving && this.model.hooks.onSaving(instance, changes))\r\n .then(() => {\r\n return instance;\r\n });\r\n }\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/ModelHelpers.js b/dist/lib/ModelHelpers.js index 72845cd..826ce2f 100644 --- a/dist/lib/ModelHelpers.js +++ b/dist/lib/ModelHelpers.js @@ -1,3 +1,4 @@ +"use strict"; var MongoDB = require('mongodb'); var Skmatc = require('skmatc'); var Omnom_1 = require('./utils/Omnom'); @@ -130,7 +131,7 @@ var ModelHelpers = (function () { return this.cloneDocument(original); }; return ModelHelpers; -})(); +}()); exports.ModelHelpers = ModelHelpers; //# sourceMappingURL=ModelHelpers.js.map diff --git a/dist/lib/ModelHelpers.js.map b/dist/lib/ModelHelpers.js.map index 53f796a..d17f026 100644 --- a/dist/lib/ModelHelpers.js.map +++ b/dist/lib/ModelHelpers.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/ModelHelpers.ts"],"names":["ModelHelpers","ModelHelpers.constructor","ModelHelpers.validate","ModelHelpers.wrapDocument","ModelHelpers.transformToDB","ModelHelpers.transformFromDB","ModelHelpers.convertToDB","ModelHelpers.diff","ModelHelpers.cloneDocument","ModelHelpers.cloneConditions"],"mappings":"AA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ACxBA,MAAMA,CAACA,KAAKA,CAACA;YACjBA,CAACA;YAEDA,EAAEA,CAAAA,CAACA,KAAKA,YAAYA,OAAOA,CAACA,MAAMA,CAACA,CAACA,CAACA;gBACjCA,MAAMA,CAACA,KAAKA,CAACA;YACjBA,CAACA;YAEDA,EAAEA,CAAAA,CAACA,KAAKA,YAAYA,OAAOA,CAACA,QAAQA,CAACA,CAACA,CAACA;gBACnCA,MAAMA,CAACA,KAAKA,CAACA;YACjBA,CAACA;QACJA,CAACA,CAACA,CAACA;IACPA,CAACA;IAEDR;;;;;;OAMGA;IACHA,sCAAeA,GAAfA,UAAmBA,QAAWA;QAC1BS,MAAMA,CAACA,IAAIA,CAACA,aAAaA,CAACA,QAAQA,CAACA,CAACA;IACxCA,CAACA;IACLT,mBAACA;AAADA,CAlIA,AAkICA,IAAA;AAlIY,oBAAY,eAkIxB,CAAA","file":"lib/ModelHelpers.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport {Model} from './Model';\r\nimport Skmatc = require('skmatc');\r\nimport {Omnom} from './utils/Omnom';\r\nimport _ = require('lodash');\r\nimport Bluebird = require('bluebird');\r\n\r\n/**\r\n * A number of helper methods used commonly within Iridium, they provide a means to transform,\r\n * validate, wrap and diff instances and documents. By keeping these methods in one place we\r\n * help to improve testability and reduce code duplication (mouse abuse) throughout the codebase.\r\n * @internal\r\n */\r\nexport class ModelHelpers {\r\n constructor(public model: Model) {\r\n this._validator = Skmatc.scope(model.schema);\r\n model.validators.forEach(validator => this._validator.register(validator));\r\n }\r\n\r\n private _validator: Skmatc.Skmatc;\r\n\r\n /**\r\n * Validates a document to ensure that it matches the model's ISchema requirements\r\n * @param {any} document The document to validate against the ISchema\r\n * @returns {SkmatcCore.IResult} The result of the validation\r\n */\r\n validate(document: TDocument): Skmatc.Result {\r\n return this._validator.validate(document);\r\n }\r\n\r\n /**\r\n * Wraps the given document in an instance wrapper for use throughout the application\r\n * @param {any} document The document to be wrapped as an instance\r\n * @param {Boolean} isNew Whether the instance originated from the database or was created by the application\r\n * @param {Boolean} isPartial Whether the document supplied contains all information present in the database\r\n * @returns {any} An instance which wraps this document\r\n */\r\n wrapDocument(document: TDocument, isNew?: boolean, isPartial?: boolean): TInstance {\r\n return new this.model.Instance(document, isNew, isPartial);\r\n }\r\n\r\n /**\r\n * Converts the given document to its database form into a form\r\n * using the transforms defined on the model.\r\n * @param {any} document The document to be converted\r\n * @returns {any} The result of having transformed the document.\r\n * @remarks This is only really called from insert/create - as \r\n */\r\n transformToDB(document: T, options: TransformOptions = { properties: true }): T {\r\n if(options.document && this.model.transforms.$document)\r\n document = this.model.transforms.$document.toDB(document, '$document', this.model);\r\n \r\n if(!options.properties) return document;\r\n \r\n for (var property in this.model.transforms)\r\n if(property === '$document') continue;\r\n else if(document.hasOwnProperty(property)) {\r\n document[property] = this.model.transforms[property].toDB(document[property], property, this.model);\r\n }\r\n \r\n return document;\r\n }\r\n \r\n /**\r\n * Converts the given document from its database form using the\r\n * transforms defined on the model.\r\n * @param document The document to be converted.\r\n * @returns The result of having transformed the document.\r\n * @remarks Unlike the transformToDB function - this method only applies\r\n * document level transforms, as property level transforms are applied in\r\n * their relevant instance setters.\r\n */\r\n transformFromDB(document: TDocument, options: TransformOptions = { properties: true }): TDocument {\r\n if(options.document && this.model.transforms.$document)\r\n document = this.model.transforms.$document.fromDB(document, '$document', this.model);\r\n \r\n if(!options.properties) return document;\r\n \r\n for (var property in this.model.transforms)\r\n if(property === '$document') continue;\r\n else if(document.hasOwnProperty(property)) {\r\n document[property] = this.model.transforms[property].fromDB(document[property], property, this.model);\r\n }\r\n \r\n return document;\r\n }\r\n\r\n /**\r\n * Converts the given document to its database form into a form\r\n * using the transforms defined on the model.\r\n * @param document The document to be converted\r\n * @param processProperties Whether or not to process properties in addition\r\n * document level transforms.\r\n * @returns {any} A new document cloned from the original and transformed\r\n */\r\n convertToDB(document: T, options: TransformOptions = { properties: true }): T {\r\n var doc: T = this.cloneDocument(document);\r\n return this.transformToDB(doc, options);\r\n }\r\n\r\n /**\r\n * Performs a diff operation between two documents and creates a MongoDB changes object to represent the differences\r\n * @param {any} original The original document prior to changes being made\r\n * @param {any} modified The document after changes were made\r\n */\r\n diff(original: TDocument, modified: TDocument): any {\r\n var omnom = new Omnom();\r\n omnom.diff(original, modified);\r\n return omnom.changes;\r\n }\r\n \r\n /**\r\n * Clones the given document recursively, taking into account complex types like\r\n * Buffers correctly.\r\n * \r\n * @param {any} The document you wish to clone deeply.\r\n */\r\n cloneDocument(original: T): T {\r\n return _.cloneDeepWith(original, (value) => {\r\n if(Buffer.isBuffer(value)) {\r\n return value;\r\n }\r\n \r\n if(value instanceof MongoDB.Binary) {\r\n return value;\r\n }\r\n \r\n if(value instanceof MongoDB.ObjectID) {\r\n return value;\r\n }\r\n });\r\n }\r\n \r\n /**\r\n * Clones the given document recursively, taking into account complex types like\r\n * Buffers correctly. Optimized for working with query documents instead of true\r\n * documents.\r\n * \r\n * @param {any} The document you wish to clone deeply.\r\n */\r\n cloneConditions(original: T): T {\r\n return this.cloneDocument(original);\r\n }\r\n}\r\n\r\nexport interface TransformOptions {\r\n properties?: boolean;\r\n document?: boolean;\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/ModelHelpers.ts"],"names":[],"mappings":";AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAEpC,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAClC,sBAAoB,eAAe,CAAC,CAAA;AACpC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAG7B;;;;;GAKG;AACH;IACI,sBAAmB,KAAkC;QADzD,iBAkIC;QAjIsB,UAAK,GAAL,KAAK,CAA6B;QACjD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC7C,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,UAAA,SAAS,IAAI,OAAA,KAAI,CAAC,UAAU,CAAC,QAAQ,CA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AAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,2BAAI,GAAJ,UAAK,QAAmB,EAAE,QAAmB;QACzC,IAAI,KAAK,GAAG,IAAI,aAAK,EAAE,CAAC;QACxB,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/B,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,oCAAa,GAAb,UAAiB,QAAW;QACxB,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAC,KAAK;YACpC,EAAE,CAAA,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACxB,MAAM,CAAC,KAAK,CAAC;YACjB,CAAC;YAED,EAAE,CAAA,CAAC,KAAK,YAAY,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;gBACjC,MAAM,CAAC,KAAK,CAAC;YACjB,CAAC;YAED,EAAE,CAAA,CAAC,KAAK,YAAY,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACnC,MAAM,CAAC,KAAK,CAAC;YACjB,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;OAMG;IACH,sCAAe,GAAf,UAAmB,QAAW;QAC1B,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IACL,mBAAC;AAAD,CAlIA,AAkIC,IAAA;AAlIY,oBAAY,eAkIxB,CAAA","file":"lib/ModelHelpers.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport {Model} from './Model';\r\nimport Skmatc = require('skmatc');\r\nimport {Omnom} from './utils/Omnom';\r\nimport _ = require('lodash');\r\nimport Bluebird = require('bluebird');\r\n\r\n/**\r\n * A number of helper methods used commonly within Iridium, they provide a means to transform,\r\n * validate, wrap and diff instances and documents. By keeping these methods in one place we\r\n * help to improve testability and reduce code duplication (mouse abuse) throughout the codebase.\r\n * @internal\r\n */\r\nexport class ModelHelpers {\r\n constructor(public model: Model) {\r\n this._validator = Skmatc.scope(model.schema);\r\n model.validators.forEach(validator => this._validator.register(validator));\r\n }\r\n\r\n private _validator: Skmatc.Skmatc;\r\n\r\n /**\r\n * Validates a document to ensure that it matches the model's ISchema requirements\r\n * @param {any} document The document to validate against the ISchema\r\n * @returns {SkmatcCore.IResult} The result of the validation\r\n */\r\n validate(document: TDocument): Skmatc.Result {\r\n return this._validator.validate(document);\r\n }\r\n\r\n /**\r\n * Wraps the given document in an instance wrapper for use throughout the application\r\n * @param {any} document The document to be wrapped as an instance\r\n * @param {Boolean} isNew Whether the instance originated from the database or was created by the application\r\n * @param {Boolean} isPartial Whether the document supplied contains all information present in the database\r\n * @returns {any} An instance which wraps this document\r\n */\r\n wrapDocument(document: TDocument, isNew?: boolean, isPartial?: boolean): TInstance {\r\n return new this.model.Instance(document, isNew, isPartial);\r\n }\r\n\r\n /**\r\n * Converts the given document to its database form into a form\r\n * using the transforms defined on the model.\r\n * @param {any} document The document to be converted\r\n * @returns {any} The result of having transformed the document.\r\n * @remarks This is only really called from insert/create - as \r\n */\r\n transformToDB(document: T, options: TransformOptions = { properties: true }): T {\r\n if(options.document && this.model.transforms.$document)\r\n document = this.model.transforms.$document.toDB(document, '$document', this.model);\r\n \r\n if(!options.properties) return document;\r\n \r\n for (var property in this.model.transforms)\r\n if(property === '$document') continue;\r\n else if(document.hasOwnProperty(property)) {\r\n document[property] = this.model.transforms[property].toDB(document[property], property, this.model);\r\n }\r\n \r\n return document;\r\n }\r\n \r\n /**\r\n * Converts the given document from its database form using the\r\n * transforms defined on the model.\r\n * @param document The document to be converted.\r\n * @returns The result of having transformed the document.\r\n * @remarks Unlike the transformToDB function - this method only applies\r\n * document level transforms, as property level transforms are applied in\r\n * their relevant instance setters.\r\n */\r\n transformFromDB(document: TDocument, options: TransformOptions = { properties: true }): TDocument {\r\n if(options.document && this.model.transforms.$document)\r\n document = this.model.transforms.$document.fromDB(document, '$document', this.model);\r\n \r\n if(!options.properties) return document;\r\n \r\n for (var property in this.model.transforms)\r\n if(property === '$document') continue;\r\n else if(document.hasOwnProperty(property)) {\r\n document[property] = this.model.transforms[property].fromDB(document[property], property, this.model);\r\n }\r\n \r\n return document;\r\n }\r\n\r\n /**\r\n * Converts the given document to its database form into a form\r\n * using the transforms defined on the model.\r\n * @param document The document to be converted\r\n * @param processProperties Whether or not to process properties in addition\r\n * document level transforms.\r\n * @returns {any} A new document cloned from the original and transformed\r\n */\r\n convertToDB(document: T, options: TransformOptions = { properties: true }): T {\r\n var doc: T = this.cloneDocument(document);\r\n return this.transformToDB(doc, options);\r\n }\r\n\r\n /**\r\n * Performs a diff operation between two documents and creates a MongoDB changes object to represent the differences\r\n * @param {any} original The original document prior to changes being made\r\n * @param {any} modified The document after changes were made\r\n */\r\n diff(original: TDocument, modified: TDocument): any {\r\n var omnom = new Omnom();\r\n omnom.diff(original, modified);\r\n return omnom.changes;\r\n }\r\n \r\n /**\r\n * Clones the given document recursively, taking into account complex types like\r\n * Buffers correctly.\r\n * \r\n * @param {any} The document you wish to clone deeply.\r\n */\r\n cloneDocument(original: T): T {\r\n return _.cloneDeepWith(original, (value) => {\r\n if(Buffer.isBuffer(value)) {\r\n return value;\r\n }\r\n \r\n if(value instanceof MongoDB.Binary) {\r\n return value;\r\n }\r\n \r\n if(value instanceof MongoDB.ObjectID) {\r\n return value;\r\n }\r\n });\r\n }\r\n \r\n /**\r\n * Clones the given document recursively, taking into account complex types like\r\n * Buffers correctly. Optimized for working with query documents instead of true\r\n * documents.\r\n * \r\n * @param {any} The document you wish to clone deeply.\r\n */\r\n cloneConditions(original: T): T {\r\n return this.cloneDocument(original);\r\n }\r\n}\r\n\r\nexport interface TransformOptions {\r\n properties?: boolean;\r\n document?: boolean;\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/ModelInterfaces.js b/dist/lib/ModelInterfaces.js index 57c9a5a..42528a4 100644 --- a/dist/lib/ModelInterfaces.js +++ b/dist/lib/ModelInterfaces.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=ModelInterfaces.js.map diff --git a/dist/lib/ModelOptions.js b/dist/lib/ModelOptions.js index 57b2e73..6d659ab 100644 --- a/dist/lib/ModelOptions.js +++ b/dist/lib/ModelOptions.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=ModelOptions.js.map diff --git a/dist/lib/ModelSpecificInstance.js b/dist/lib/ModelSpecificInstance.js index f6fd046..548ba87 100644 --- a/dist/lib/ModelSpecificInstance.js +++ b/dist/lib/ModelSpecificInstance.js @@ -1,3 +1,4 @@ +"use strict"; var util = require('util'); var _ = require('lodash'); /** diff --git a/dist/lib/ModelSpecificInstance.js.map b/dist/lib/ModelSpecificInstance.js.map index d45dfea..7968e76 100644 --- a/dist/lib/ModelSpecificInstance.js.map +++ b/dist/lib/ModelSpecificInstance.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/ModelSpecificInstance.ts"],"names":["ModelSpecificInstance"],"mappings":"AAGA,IAAO,IAAI,WAAW,MAAM,CAAC,CAAC;AAC9B,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAE7B;;;;;;;;;;;GAWG;AACH,+BAAkF,KAAkC,EAAE,YAA0D;IAC5KA,IAAIA,WAAWA,GAAGA,UAAUA,GAAcA,EAAEA,KAAeA,EAAEA,SAAmBA;QAC5E,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC,CAACA;IAEFA,IAAIA,CAACA,QAAQA,CAACA,WAAWA,EAAEA,YAAYA,CAACA,CAACA;IAEzCA,CAACA,CAACA,IAAIA,CAACA,MAAMA,CAACA,IAAIA,CAACA,KAAKA,CAACA,MAAMA,CAACA,EAACA,UAACA,QAAQA;QACtCA,EAAEA,CAACA,CAACA,KAAKA,CAACA,UAAUA,CAACA,cAAcA,CAACA,QAAQA,CAACA,CAACA,CAACA,CAACA;YAC5CA,MAAMA,CAACA,MAAMA,CAACA,cAAcA,CAACA,WAAWA,CAACA,SAASA,EAAEA,QAAQA,EAAEA;gBAC1DA,GAAGA,EAAEA;oBACD,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;gBACxF,CAAC;gBACDA,GAAGA,EAAEA,UAAUA,KAAKA;oBAChB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;gBACvF,CAAC;gBACDA,UAAUA,EAAEA,IAAIA;gBAChBA,YAAYA,EAAEA,IAAIA;aACrBA,CAACA,CAACA;QACPA,CAACA;QAEDA,MAAMA,CAACA,cAAcA,CAACA,WAAWA,CAACA,SAASA,EAAEA,QAAQA,EAAEA;YACnDA,GAAGA,EAAEA;gBACD,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YACpC,CAAC;YACDA,GAAGA,EAAEA,UAAUA,KAAKA;gBAChB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;YACrC,CAAC;YACDA,UAAUA,EAAEA,IAAIA;SACnBA,CAACA,CAACA;IACPA,CAACA,CAACA,CAACA;IAEHA,MAAMA,CAAMA,WAAWA,CAACA;AAC5BA,CAACA;AAjCe,6BAAqB,wBAiCpC,CAAA","file":"lib/ModelSpecificInstance.js","sourcesContent":["import {Model} from './Model';\r\nimport {InstanceImplementation} from './InstanceInterface';\r\nimport {ModelSpecificInstanceConstructor} from './ModelInterfaces';\r\nimport util = require('util');\r\nimport _ = require('lodash');\r\n\r\n/**\r\n * Creates a new subclass of the given instanceType which correctly performs property transforms\r\n * and associates the instance with the correct model when instantiated.\r\n *\r\n * @param TDocument The interface representing the structure of the documents found in the database.\r\n * @param TInstance The interface or class representing the documents after they have been wrapped in an instance.\r\n *\r\n * @param model The model which instances should be associated with when the resulting constructor is used.\r\n * @param instanceType The constructor used to create new instances of type TInstance.\r\n *\r\n * @internal\r\n */\r\nexport function ModelSpecificInstance(model: Model, instanceType: InstanceImplementation): ModelSpecificInstanceConstructor {\r\n var constructor = function (doc: TDocument, isNew?: boolean, isPartial?: boolean) {\r\n instanceType.call(this, model, doc, isNew, isPartial);\r\n };\r\n\r\n util.inherits(constructor, instanceType);\r\n\r\n _.each(Object.keys(model.schema),(property) => {\r\n if (model.transforms.hasOwnProperty(property)) {\r\n return Object.defineProperty(constructor.prototype, property, {\r\n get: function () {\r\n return model.transforms[property].fromDB(this._modified[property], property, model);\r\n },\r\n set: function (value) {\r\n this._modified[property] = model.transforms[property].toDB(value, property, model);\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n }\r\n\r\n Object.defineProperty(constructor.prototype, property, {\r\n get: function () {\r\n return this._modified[property];\r\n },\r\n set: function (value) {\r\n this._modified[property] = value;\r\n },\r\n enumerable: true\r\n });\r\n });\r\n\r\n return constructor;\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/ModelSpecificInstance.ts"],"names":[],"mappings":";AAGA,IAAO,IAAI,WAAW,MAAM,CAAC,CAAC;AAC9B,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAE7B;;;;;;;;;;;GAWG;AACH,+BAAkF,KAAkC,EAAE,YAA0D;IAC5K,IAAI,WAAW,GAAG,UAAU,GAAc,EAAE,KAAe,EAAE,SAAmB;QAC5E,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAEzC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAC,UAAC,QAAQ;QACtC,EAAE,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC5C,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE;gBAC1D,GAAG,EAAE;oBACD,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;gBACxF,CAAC;gBACD,GAAG,EAAE,UAAU,KAAK;oBAChB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;gBACvF,CAAC;gBACD,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,IAAI;aACrB,CAAC,CAAC;QACP,CAAC;QAED,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,EAAE;YACnD,GAAG,EAAE;gBACD,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YACpC,CAAC;YACD,GAAG,EAAE,UAAU,KAAK;gBAChB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;YACrC,CAAC;YACD,UAAU,EAAE,IAAI;SACnB,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,MAAM,CAAM,WAAW,CAAC;AAC5B,CAAC;AAjCe,6BAAqB,wBAiCpC,CAAA","file":"lib/ModelSpecificInstance.js","sourcesContent":["import {Model} from './Model';\r\nimport {InstanceImplementation} from './InstanceInterface';\r\nimport {ModelSpecificInstanceConstructor} from './ModelInterfaces';\r\nimport util = require('util');\r\nimport _ = require('lodash');\r\n\r\n/**\r\n * Creates a new subclass of the given instanceType which correctly performs property transforms\r\n * and associates the instance with the correct model when instantiated.\r\n *\r\n * @param TDocument The interface representing the structure of the documents found in the database.\r\n * @param TInstance The interface or class representing the documents after they have been wrapped in an instance.\r\n *\r\n * @param model The model which instances should be associated with when the resulting constructor is used.\r\n * @param instanceType The constructor used to create new instances of type TInstance.\r\n *\r\n * @internal\r\n */\r\nexport function ModelSpecificInstance(model: Model, instanceType: InstanceImplementation): ModelSpecificInstanceConstructor {\r\n var constructor = function (doc: TDocument, isNew?: boolean, isPartial?: boolean) {\r\n instanceType.call(this, model, doc, isNew, isPartial);\r\n };\r\n\r\n util.inherits(constructor, instanceType);\r\n\r\n _.each(Object.keys(model.schema),(property) => {\r\n if (model.transforms.hasOwnProperty(property)) {\r\n return Object.defineProperty(constructor.prototype, property, {\r\n get: function () {\r\n return model.transforms[property].fromDB(this._modified[property], property, model);\r\n },\r\n set: function (value) {\r\n this._modified[property] = model.transforms[property].toDB(value, property, model);\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n }\r\n\r\n Object.defineProperty(constructor.prototype, property, {\r\n get: function () {\r\n return this._modified[property];\r\n },\r\n set: function (value) {\r\n this._modified[property] = value;\r\n },\r\n enumerable: true\r\n });\r\n });\r\n\r\n return constructor;\r\n}\r\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/Plugins.js b/dist/lib/Plugins.js index 940f1ac..3515687 100644 --- a/dist/lib/Plugins.js +++ b/dist/lib/Plugins.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=Plugins.js.map diff --git a/dist/lib/Schema.js b/dist/lib/Schema.js index 014a6ce..2ac0f6b 100644 --- a/dist/lib/Schema.js +++ b/dist/lib/Schema.js @@ -1,3 +1,3 @@ - +"use strict"; //# sourceMappingURL=Schema.js.map diff --git a/dist/lib/Transforms.js b/dist/lib/Transforms.js index 073097e..bc9bde0 100644 --- a/dist/lib/Transforms.js +++ b/dist/lib/Transforms.js @@ -1,3 +1,4 @@ +"use strict"; var MongoDB = require('mongodb'); exports.DefaultTransforms = { ObjectID: { diff --git a/dist/lib/Transforms.js.map b/dist/lib/Transforms.js.map index 215fd9b..a48a228 100644 --- a/dist/lib/Transforms.js.map +++ b/dist/lib/Transforms.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/Transforms.ts"],"names":[],"mappings":"AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAqCvB,yBAAiB,GAAG;IAC/B,QAAQ,EAAuC;QAC/C,MAAM,EAAE,UAAA,KAAK,IAAI,OAAA,KAAK,YAAY,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,WAAW,EAAE,GAAG,KAAK,EAA/D,CAA+D;QAChF,IAAI,EAAE,UAAA,KAAK,IAAI,OAAA,OAAO,KAAK,KAAK,QAAQ,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,EAA/D,CAA+D;KAC9E;IACD,MAAM,EAAqC;QAC1C,MAAM,EAAE,UAAA,KAAK;YACZ,EAAE,CAAA,CAAC,CAAC,KAAK,CAAC;gBAAC,MAAM,CAAC,IAAI,CAAC;YACvB,EAAE,CAAA,CAAC,KAAK,YAAY,OAAO,CAAC,MAAM,CAAC;gBAAC,MAAM,CAAO,KAAM,CAAC,MAAM,CAAC;YAE/D,MAAM,CAAC,KAAK,CAAC;QACd,CAAC;QACD,IAAI,EAAE,UAAA,KAAK;YACV,EAAE,CAAA,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5D,EAAE,CAAA,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACtE,MAAM,CAAC,IAAI,CAAC;QACb,CAAC;KACD;CACD,CAAA","file":"lib/Transforms.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport {Model} from './Model';\r\nimport * as BSON from './BSON'; \r\n\r\nexport interface Transforms {\r\n\t/**\r\n\t * A transform which is applied to the entire document.\r\n\t */\r\n\t$document?: PropertyTransform;\r\n\t[property:string]: PropertyTransform;\r\n}\r\n\r\n/**\r\n * Converts the value of a property to and from its database representation.\r\n */\r\nexport interface PropertyTransform {\r\n\t/**\r\n\t * Converts a property's value from its database representation into one\r\n\t * suitable for the application.\r\n\t * @param value The value stored in the MongoDB database document.\r\n\t * @param property The name of the document property to which this transform is being applied.\r\n\t * @param model The Iridium Model on which this transform is being applied\r\n\t * @returns A derived value which is more useful to the application.\r\n\t */\r\n\tfromDB(value: T, property: string, model: Model): any;\r\n\r\n\t/**\r\n\t * Converts a property's value into a representation more suitable for\r\n\t * the database.\r\n\t * @param value The value used by the application.\r\n\t * @param property The name of the document property to which this transform is being applied.\r\n\t * @param model The Iridium Model on which this transform is being applied\r\n\t * @returns The database optimized representation of the value.\r\n\t */\r\n\ttoDB(value: any, property: string, model: Model): T;\r\n}\r\n\r\nexport const DefaultTransforms = {\r\n \tObjectID: >{\r\n\t\tfromDB: value => value instanceof MongoDB.ObjectID ? value.toHexString() : value,\r\n\t\ttoDB: value => typeof value === 'string' ? new MongoDB.ObjectID(value) : value\r\n\t},\r\n\tBinary: >{\r\n\t\tfromDB: value => {\r\n\t\t\tif(!value) return null;\r\n\t\t\tif(value instanceof MongoDB.Binary) return (value).buffer;\r\n\t\t\t\r\n\t\t\treturn value;\r\n\t\t},\r\n\t\ttoDB: value => {\r\n\t\t\tif(Buffer.isBuffer(value)) return new MongoDB.Binary(value);\r\n\t\t\tif(Array.isArray(value)) return new MongoDB.Binary(new Buffer(value));\r\n\t\t\treturn null;\r\n\t\t}\r\n\t}\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/Transforms.ts"],"names":[],"mappings":";AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAqCvB,yBAAiB,GAAG;IAC/B,QAAQ,EAAuC;QAC/C,MAAM,EAAE,UAAA,KAAK,IAAI,OAAA,KAAK,YAAY,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,WAAW,EAAE,GAAG,KAAK,EAA/D,CAA+D;QAChF,IAAI,EAAE,UAAA,KAAK,IAAI,OAAA,OAAO,KAAK,KAAK,QAAQ,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,EAA/D,CAA+D;KAC9E;IACD,MAAM,EAAqC;QAC1C,MAAM,EAAE,UAAA,KAAK;YACZ,EAAE,CAAA,CAAC,CAAC,KAAK,CAAC;gBAAC,MAAM,CAAC,IAAI,CAAC;YACvB,EAAE,CAAA,CAAC,KAAK,YAAY,OAAO,CAAC,MAAM,CAAC;gBAAC,MAAM,CAAO,KAAM,CAAC,MAAM,CAAC;YAE/D,MAAM,CAAC,KAAK,CAAC;QACd,CAAC;QACD,IAAI,EAAE,UAAA,KAAK;YACV,EAAE,CAAA,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5D,EAAE,CAAA,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACtE,MAAM,CAAC,IAAI,CAAC;QACb,CAAC;KACD;CACD,CAAA","file":"lib/Transforms.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport {Model} from './Model';\r\nimport * as BSON from './BSON'; \r\n\r\nexport interface Transforms {\r\n\t/**\r\n\t * A transform which is applied to the entire document.\r\n\t */\r\n\t$document?: PropertyTransform;\r\n\t[property:string]: PropertyTransform;\r\n}\r\n\r\n/**\r\n * Converts the value of a property to and from its database representation.\r\n */\r\nexport interface PropertyTransform {\r\n\t/**\r\n\t * Converts a property's value from its database representation into one\r\n\t * suitable for the application.\r\n\t * @param value The value stored in the MongoDB database document.\r\n\t * @param property The name of the document property to which this transform is being applied.\r\n\t * @param model The Iridium Model on which this transform is being applied\r\n\t * @returns A derived value which is more useful to the application.\r\n\t */\r\n\tfromDB(value: T, property: string, model: Model): any;\r\n\r\n\t/**\r\n\t * Converts a property's value into a representation more suitable for\r\n\t * the database.\r\n\t * @param value The value used by the application.\r\n\t * @param property The name of the document property to which this transform is being applied.\r\n\t * @param model The Iridium Model on which this transform is being applied\r\n\t * @returns The database optimized representation of the value.\r\n\t */\r\n\ttoDB(value: any, property: string, model: Model): T;\r\n}\r\n\r\nexport const DefaultTransforms = {\r\n \tObjectID: >{\r\n\t\tfromDB: value => value instanceof MongoDB.ObjectID ? value.toHexString() : value,\r\n\t\ttoDB: value => typeof value === 'string' ? new MongoDB.ObjectID(value) : value\r\n\t},\r\n\tBinary: >{\r\n\t\tfromDB: value => {\r\n\t\t\tif(!value) return null;\r\n\t\t\tif(value instanceof MongoDB.Binary) return (value).buffer;\r\n\t\t\t\r\n\t\t\treturn value;\r\n\t\t},\r\n\t\ttoDB: value => {\r\n\t\t\tif(Buffer.isBuffer(value)) return new MongoDB.Binary(value);\r\n\t\t\tif(Array.isArray(value)) return new MongoDB.Binary(new Buffer(value));\r\n\t\t\treturn null;\r\n\t\t}\r\n\t}\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/Validators.js b/dist/lib/Validators.js index 8467ca9..36d64b1 100644 --- a/dist/lib/Validators.js +++ b/dist/lib/Validators.js @@ -1,3 +1,4 @@ +"use strict"; var MongoDB = require('mongodb'); var Skmatc = require('skmatc'); function DefaultValidators() { diff --git a/dist/lib/Validators.js.map b/dist/lib/Validators.js.map index bbd3c01..307cf9c 100644 --- a/dist/lib/Validators.js.map +++ b/dist/lib/Validators.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/Validators.ts"],"names":["DefaultValidators"],"mappings":"AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAElC;IACCA,MAAMA,CAACA;QACNA,MAAMA,CAACA,MAAMA,CAACA,UAAAA,MAAMA,IAAIA,OAAAA,MAAMA,KAAKA,OAAOA,CAACA,QAAQA,EAA3BA,CAA2BA,EAAEA,UAASA,MAAMA,EAAEA,IAAIA;YACzE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,IAAI,YAAY,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,UAAU,IAAI,IAAI,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,wCAAwC,CAAC,CAAC;QAC5L,CAAC,EAAEA,EAAEA,IAAIA,EAAEA,qBAAqBA,EAAEA,CAACA;QACnCA,MAAMA,CAACA,MAAMA,CAACA,UAAAA,MAAMA,IAAIA,OAAAA,MAAMA,KAAKA,MAAMA,EAAjBA,CAAiBA,EAAEA,UAASA,MAAMA,EAAEA,IAAIA;YAC/D,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,YAAY,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,sCAAsC,CAAC,CAAC;QAC3L,CAAC,EAAEA,EAAEA,IAAIA,EAAEA,mBAAmBA,EAAEA,CAACA;KACjCA,CAACA;AACHA,CAACA;AATe,yBAAiB,oBAShC,CAAA","file":"lib/Validators.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport Skmatc = require('skmatc');\r\n\r\nexport function DefaultValidators() {\r\n\treturn [\r\n\t\tSkmatc.create(schema => schema === MongoDB.ObjectID, function(schema, data) {\r\n\t\t\treturn this.assert(!data || data instanceof MongoDB.ObjectID || (data._bsontype === 'ObjectID' && data.id), \"Expected \" + JSON.stringify(data) + \" to be a valid MongoDB.ObjectID object\");\r\n\t\t}, { name: 'ObjectID validation' }),\r\n\t\tSkmatc.create(schema => schema === Buffer, function(schema, data) {\r\n\t\t\treturn this.assert(data && (data instanceof MongoDB.Binary || (data._bsontype === 'Binary' && data.buffer)), \"Expected \" + JSON.stringify(data) + \" to be a valid MongoDB.Binary object\");\r\n\t\t}, { name: 'Buffer validation' })\r\n\t];\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/Validators.ts"],"names":[],"mappings":";AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAElC;IACC,MAAM,CAAC;QACN,MAAM,CAAC,MAAM,CAAC,UAAA,MAAM,IAAI,OAAA,MAAM,KAAK,OAAO,CAAC,QAAQ,EAA3B,CAA2B,EAAE,UAAS,MAAM,EAAE,IAAI;YACzE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,IAAI,YAAY,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,UAAU,IAAI,IAAI,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,wCAAwC,CAAC,CAAC;QAC5L,CAAC,EAAE,EAAE,IAAI,EAAE,qBAAqB,EAAE,CAAC;QACnC,MAAM,CAAC,MAAM,CAAC,UAAA,MAAM,IAAI,OAAA,MAAM,KAAK,MAAM,EAAjB,CAAiB,EAAE,UAAS,MAAM,EAAE,IAAI;YAC/D,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,YAAY,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,sCAAsC,CAAC,CAAC;QAC3L,CAAC,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;KACjC,CAAC;AACH,CAAC;AATe,yBAAiB,oBAShC,CAAA","file":"lib/Validators.js","sourcesContent":["import MongoDB = require('mongodb');\r\nimport Skmatc = require('skmatc');\r\n\r\nexport function DefaultValidators() {\r\n\treturn [\r\n\t\tSkmatc.create(schema => schema === MongoDB.ObjectID, function(schema, data) {\r\n\t\t\treturn this.assert(!data || data instanceof MongoDB.ObjectID || (data._bsontype === 'ObjectID' && data.id), \"Expected \" + JSON.stringify(data) + \" to be a valid MongoDB.ObjectID object\");\r\n\t\t}, { name: 'ObjectID validation' }),\r\n\t\tSkmatc.create(schema => schema === Buffer, function(schema, data) {\r\n\t\t\treturn this.assert(data && (data instanceof MongoDB.Binary || (data._bsontype === 'Binary' && data.buffer)), \"Expected \" + JSON.stringify(data) + \" to be a valid MongoDB.Binary object\");\r\n\t\t}, { name: 'Buffer validation' })\r\n\t];\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/cacheControllers/IDDirector.js b/dist/lib/cacheControllers/IDDirector.js index 8b554c9..c344136 100644 --- a/dist/lib/cacheControllers/IDDirector.js +++ b/dist/lib/cacheControllers/IDDirector.js @@ -1,3 +1,4 @@ +"use strict"; var MongoDB = require('mongodb'); /** * Caches documents using their _id field as the unique cache key. This @@ -25,7 +26,7 @@ var CacheOnID = (function () { return conditions._id; }; return CacheOnID; -})(); +}()); exports.CacheOnID = CacheOnID; //# sourceMappingURL=IDDirector.js.map diff --git a/dist/lib/cacheControllers/IDDirector.js.map b/dist/lib/cacheControllers/IDDirector.js.map index 70b7ee2..16005ee 100644 --- a/dist/lib/cacheControllers/IDDirector.js.map +++ b/dist/lib/cacheControllers/IDDirector.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/cacheControllers/IDDirector.ts"],"names":["CacheOnID","CacheOnID.constructor","CacheOnID.valid","CacheOnID.buildKey","CacheOnID.validQuery","CacheOnID.buildQueryKey"],"mappings":"AACA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAEpC;;;;;GAKG;AACH;IAAAA;IAoBAC,CAACA;IAnBGD,yBAAKA,GAALA,UAAMA,MAAoBA;QACtBE,MAAMA,CAACA,CAACA,CAACA,MAAMA,CAACA,GAAGA,CAACA;IACxBA,CAACA;IAEDF,4BAAQA,GAARA,UAASA,MAAoBA;QACzBG,EAAEA,CAACA,CAACA,MAAMA,CAACA,GAAGA,CAACA,SAASA,IAAIA,UAAUA,CAACA;YACnCA,MAAMA,CAACA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,MAAMA,CAACA,GAAGA,CAACA,EAAEA,CAACA,CAACA,WAAWA,EAAEA,CAACA;QAC7DA,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA;IACtBA,CAACA;IAEDH,8BAAUA,GAAVA,UAAWA,UAAUA;QACjBI,MAAMA,CAACA,CAACA,CAACA,UAAUA,CAACA,GAAGA,CAACA;IAC5BA,CAACA;IAEDJ,iCAAaA,GAAbA,UAAcA,UAAUA;QACpBK,EAAEA,CAACA,CAACA,UAAUA,CAACA,GAAGA,CAACA,SAASA,IAAIA,UAAUA,CAACA;YACvCA,MAAMA,CAACA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,UAAUA,CAACA,GAAGA,CAACA,EAAEA,CAACA,CAACA,WAAWA,EAAEA,CAACA;QACjEA,MAAMA,CAACA,UAAUA,CAACA,GAAGA,CAACA;IAC1BA,CAACA;IACLL,gBAACA;AAADA,CApBA,AAoBCA,IAAA;AApBY,iBAAS,YAoBrB,CAAA","file":"lib/cacheControllers/IDDirector.js","sourcesContent":["import {CacheDirector} from '../CacheDirector';\r\nimport MongoDB = require('mongodb');\r\n\r\n/**\r\n * Caches documents using their _id field as the unique cache key. This\r\n * is useful if you primarily query your documents using their _id field,\r\n * however can be suboptimal (or even a complete waste) if you use different\r\n * types of queries.\r\n */\r\nexport class CacheOnID implements CacheDirector{\r\n valid(object: { _id: any }) {\r\n return !!object._id;\r\n }\r\n\r\n buildKey(object: { _id: any }) {\r\n if (object._id._bsontype == 'ObjectID')\r\n return new MongoDB.ObjectID(object._id.id).toHexString();\r\n return object._id;\r\n }\r\n\r\n validQuery(conditions) {\r\n return !!conditions._id;\r\n }\r\n\r\n buildQueryKey(conditions) {\r\n if (conditions._id._bsontype == 'ObjectID')\r\n return new MongoDB.ObjectID(conditions._id.id).toHexString();\r\n return conditions._id;\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/cacheControllers/IDDirector.ts"],"names":[],"mappings":";AACA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAEpC;;;;;GAKG;AACH;IAAA;IAoBA,CAAC;IAnBG,yBAAK,GAAL,UAAM,MAAoB;QACtB,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IACxB,CAAC;IAED,4BAAQ,GAAR,UAAS,MAAoB;QACzB,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,IAAI,UAAU,CAAC;YACnC,MAAM,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7D,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,8BAAU,GAAV,UAAW,UAAU;QACjB,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;IAC5B,CAAC;IAED,iCAAa,GAAb,UAAc,UAAU;QACpB,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,IAAI,UAAU,CAAC;YACvC,MAAM,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACjE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC;IAC1B,CAAC;IACL,gBAAC;AAAD,CApBA,AAoBC,IAAA;AApBY,iBAAS,YAoBrB,CAAA","file":"lib/cacheControllers/IDDirector.js","sourcesContent":["import {CacheDirector} from '../CacheDirector';\r\nimport MongoDB = require('mongodb');\r\n\r\n/**\r\n * Caches documents using their _id field as the unique cache key. This\r\n * is useful if you primarily query your documents using their _id field,\r\n * however can be suboptimal (or even a complete waste) if you use different\r\n * types of queries.\r\n */\r\nexport class CacheOnID implements CacheDirector{\r\n valid(object: { _id: any }) {\r\n return !!object._id;\r\n }\r\n\r\n buildKey(object: { _id: any }) {\r\n if (object._id._bsontype == 'ObjectID')\r\n return new MongoDB.ObjectID(object._id.id).toHexString();\r\n return object._id;\r\n }\r\n\r\n validQuery(conditions) {\r\n return !!conditions._id;\r\n }\r\n\r\n buildQueryKey(conditions) {\r\n if (conditions._id._bsontype == 'ObjectID')\r\n return new MongoDB.ObjectID(conditions._id.id).toHexString();\r\n return conditions._id;\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/caches/MemoryCache.js b/dist/lib/caches/MemoryCache.js index 59cd048..71ec0fa 100644 --- a/dist/lib/caches/MemoryCache.js +++ b/dist/lib/caches/MemoryCache.js @@ -1,3 +1,4 @@ +"use strict"; var Bluebird = require('bluebird'); /** * A cache implementation which stores documents in an in-memory cache. @@ -23,7 +24,7 @@ var MemoryCache = (function () { return Bluebird.resolve(has); }; return MemoryCache; -})(); +}()); exports.MemoryCache = MemoryCache; //# sourceMappingURL=MemoryCache.js.map diff --git a/dist/lib/caches/MemoryCache.js.map b/dist/lib/caches/MemoryCache.js.map index 2a24043..99bc39a 100644 --- a/dist/lib/caches/MemoryCache.js.map +++ b/dist/lib/caches/MemoryCache.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/caches/MemoryCache.ts"],"names":["MemoryCache","MemoryCache.constructor","MemoryCache.set","MemoryCache.get","MemoryCache.clear"],"mappings":"AAAA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAGtC;;;;;GAKG;AACH;IAAAA;QACYC,UAAKA,GAAQA,EAAEA,CAACA;IAgB5BA,CAACA;IAdGD,yBAAGA,GAAHA,UAAOA,GAAWA,EAAEA,KAAQA;QACxBE,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAACA,GAAGA,KAAKA,CAACA;QACxBA,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA;IACnCA,CAACA;IAEDF,yBAAGA,GAAHA,UAAOA,GAAWA;QACdG,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAACA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAACA,CAACA,CAACA;IAC7CA,CAACA;IAEDH,2BAAKA,GAALA,UAAMA,GAAWA;QACbI,IAAIA,GAAGA,GAAGA,IAAIA,CAACA,KAAKA,CAACA,cAAcA,CAACA,GAAGA,CAACA,CAACA;QACzCA,EAAEA,CAAAA,CAACA,GAAGA,CAACA;YAACA,OAAOA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAACA,CAACA;QAC/BA,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAACA,GAAGA,CAACA,CAACA;IACjCA,CAACA;IACLJ,kBAACA;AAADA,CAjBA,AAiBCA,IAAA;AAjBY,mBAAW,cAiBvB,CAAA","file":"lib/caches/MemoryCache.js","sourcesContent":["import Bluebird = require('bluebird');\r\nimport {Cache} from '../Cache';\r\n\r\n/**\r\n * A cache implementation which stores documents in an in-memory cache.\r\n *\r\n * Be aware that this is an incredibly simplistic implementation which doesn't manage\r\n * memory usage at all and is very likely NOT suitable for production use.\r\n */\r\nexport class MemoryCache implements Cache {\r\n private cache: any = {};\r\n\r\n set(key: string, value: T): Bluebird {\r\n this.cache[key] = value;\r\n return Bluebird.resolve(value);\r\n }\r\n\r\n get(key: string): Bluebird {\r\n return Bluebird.resolve(this.cache[key]);\r\n }\r\n\r\n clear(key: string) : Bluebird {\r\n var has = this.cache.hasOwnProperty(key);\r\n if(has) delete this.cache[key];\r\n return Bluebird.resolve(has);\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/caches/MemoryCache.ts"],"names":[],"mappings":";AAAA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAGtC;;;;;GAKG;AACH;IAAA;QACY,UAAK,GAAQ,EAAE,CAAC;IAgB5B,CAAC;IAdG,yBAAG,GAAH,UAAO,GAAW,EAAE,KAAQ;QACxB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,yBAAG,GAAH,UAAO,GAAW;QACd,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,2BAAK,GAAL,UAAM,GAAW;QACb,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QACzC,EAAE,CAAA,CAAC,GAAG,CAAC;YAAC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IACL,kBAAC;AAAD,CAjBA,AAiBC,IAAA;AAjBY,mBAAW,cAiBvB,CAAA","file":"lib/caches/MemoryCache.js","sourcesContent":["import Bluebird = require('bluebird');\r\nimport {Cache} from '../Cache';\r\n\r\n/**\r\n * A cache implementation which stores documents in an in-memory cache.\r\n *\r\n * Be aware that this is an incredibly simplistic implementation which doesn't manage\r\n * memory usage at all and is very likely NOT suitable for production use.\r\n */\r\nexport class MemoryCache implements Cache {\r\n private cache: any = {};\r\n\r\n set(key: string, value: T): Bluebird {\r\n this.cache[key] = value;\r\n return Bluebird.resolve(value);\r\n }\r\n\r\n get(key: string): Bluebird {\r\n return Bluebird.resolve(this.cache[key]);\r\n }\r\n\r\n clear(key: string) : Bluebird {\r\n var has = this.cache.hasOwnProperty(key);\r\n if(has) delete this.cache[key];\r\n return Bluebird.resolve(has);\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/caches/NoOpCache.js b/dist/lib/caches/NoOpCache.js index a01259d..822a2cb 100644 --- a/dist/lib/caches/NoOpCache.js +++ b/dist/lib/caches/NoOpCache.js @@ -1,3 +1,4 @@ +"use strict"; var Bluebird = require('bluebird'); /** * A cache implementation which does not cache any received documents @@ -19,7 +20,7 @@ var NoOpCache = (function () { return Bluebird.resolve(false); }; return NoOpCache; -})(); +}()); exports.NoOpCache = NoOpCache; //# sourceMappingURL=NoOpCache.js.map diff --git a/dist/lib/caches/NoOpCache.js.map b/dist/lib/caches/NoOpCache.js.map index 83ed2d5..6c9c105 100644 --- a/dist/lib/caches/NoOpCache.js.map +++ b/dist/lib/caches/NoOpCache.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/caches/NoOpCache.ts"],"names":["NoOpCache","NoOpCache.constructor","NoOpCache.set","NoOpCache.get","NoOpCache.clear"],"mappings":"AACA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAEtC;;;;;;GAMG;AACH;IAAAA;IAYAC,CAACA;IAXGD,uBAAGA,GAAHA,UAAOA,GAAWA,EAAEA,MAASA;QACzBE,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAACA,MAAMA,CAACA,CAACA;IACpCA,CAACA;IAEDF,uBAAGA,GAAHA,UAAOA,GAAWA;QACdG,MAAMA,CAACA,QAAQA,CAACA,OAAOA,EAAEA,CAACA;IAC9BA,CAACA;IAEDH,yBAAKA,GAALA,UAAMA,GAAWA;QACbI,MAAMA,CAACA,QAAQA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA;IACnCA,CAACA;IACLJ,gBAACA;AAADA,CAZA,AAYCA,IAAA;AAZY,iBAAS,YAYrB,CAAA","file":"lib/caches/NoOpCache.js","sourcesContent":["import {Cache} from '../Cache';\r\nimport Bluebird = require('bluebird');\r\n\r\n/**\r\n * A cache implementation which does not cache any received documents\r\n * and returns nothing when requested - mimicking an empty cache.\r\n *\r\n * This is the default cache used if one is not supplied and should\r\n * not impose any significant performance overhead.\r\n */\r\nexport class NoOpCache implements Cache {\r\n set(key: string, object: T): Bluebird {\r\n return Bluebird.resolve(object);\r\n }\r\n\r\n get(key: string): Bluebird {\r\n return Bluebird.resolve();\r\n }\r\n\r\n clear(key: string): Bluebird {\r\n return Bluebird.resolve(false);\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/caches/NoOpCache.ts"],"names":[],"mappings":";AACA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAEtC;;;;;;GAMG;AACH;IAAA;IAYA,CAAC;IAXG,uBAAG,GAAH,UAAO,GAAW,EAAE,MAAS;QACzB,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,uBAAG,GAAH,UAAO,GAAW;QACd,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IAED,yBAAK,GAAL,UAAM,GAAW;QACb,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IACL,gBAAC;AAAD,CAZA,AAYC,IAAA;AAZY,iBAAS,YAYrB,CAAA","file":"lib/caches/NoOpCache.js","sourcesContent":["import {Cache} from '../Cache';\r\nimport Bluebird = require('bluebird');\r\n\r\n/**\r\n * A cache implementation which does not cache any received documents\r\n * and returns nothing when requested - mimicking an empty cache.\r\n *\r\n * This is the default cache used if one is not supplied and should\r\n * not impose any significant performance overhead.\r\n */\r\nexport class NoOpCache implements Cache {\r\n set(key: string, object: T): Bluebird {\r\n return Bluebird.resolve(object);\r\n }\r\n\r\n get(key: string): Bluebird {\r\n return Bluebird.resolve();\r\n }\r\n\r\n clear(key: string): Bluebird {\r\n return Bluebird.resolve(false);\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/middleware/Express.js b/dist/lib/middleware/Express.js index 8e94404..415e6ba 100644 --- a/dist/lib/middleware/Express.js +++ b/dist/lib/middleware/Express.js @@ -1,3 +1,4 @@ +"use strict"; /** * A factory method which creates Express/Connect compatible middleware functions to inject * a 'db' field on your request objects as well as ensuring that the Iridium Core is connected diff --git a/dist/lib/middleware/Express.js.map b/dist/lib/middleware/Express.js.map index e529520..ba0e49f 100644 --- a/dist/lib/middleware/Express.js.map +++ b/dist/lib/middleware/Express.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/middleware/Express.ts"],"names":["ExpressMiddlewareFactory"],"mappings":"AAIA;;;;;;GAMG;AACH,kCAAyC,IAAU;IAC/CA,MAAMA,CAACA,UAAUA,GAAuBA,EAAEA,GAAwBA,EAAEA,IAA0CA;QAC1G,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;YAChB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE;gBAC7B,GAAG,EAAE,cAAa,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;aACnC,CAAC,CAAC;YACH,IAAI,EAAE,CAAC;QACX,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,CAACA;AACNA,CAACA;AATe,gCAAwB,2BASvC,CAAA","file":"lib/middleware/Express.js","sourcesContent":["import http = require('http');\r\nimport {MiddlewareFactory} from '../Middleware';\r\nimport {Core} from '../Core';\r\n\r\n/**\r\n * A factory method which creates Express/Connect compatible middleware functions to inject\r\n * a 'db' field on your request objects as well as ensuring that the Iridium Core is connected\r\n * to a MongoDB database before handling any requests.\r\n *\r\n * @internal\r\n */\r\nexport function ExpressMiddlewareFactory(core: Core): ExpressMiddleware {\r\n return function (req: http.ServerRequest, res: http.ServerResponse, next:(err?: Error, route?: String) => void) {\r\n core.connect().then(function() {\r\n Object.defineProperty(req, 'db', {\r\n get: function() { return core; }\r\n });\r\n next();\r\n }).catch(next);\r\n };\r\n}\r\n\r\n/**\r\n * An Express/Connect compatible middleware function which injects req.db and ensures that the Iridium Core\r\n * has an active database connection before continuing the request handling process.\r\n */\r\nexport interface ExpressMiddleware {\r\n (req: http.ServerRequest, res: http.ServerResponse, next:(err?: Error, route?: String) => void);\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/middleware/Express.ts"],"names":[],"mappings":";AAIA;;;;;;GAMG;AACH,kCAAyC,IAAU;IAC/C,MAAM,CAAC,UAAU,GAAuB,EAAE,GAAwB,EAAE,IAA0C;QAC1G,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;YAChB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE;gBAC7B,GAAG,EAAE,cAAa,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;aACnC,CAAC,CAAC;YACH,IAAI,EAAE,CAAC;QACX,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,CAAC;AACN,CAAC;AATe,gCAAwB,2BASvC,CAAA","file":"lib/middleware/Express.js","sourcesContent":["import http = require('http');\r\nimport {MiddlewareFactory} from '../Middleware';\r\nimport {Core} from '../Core';\r\n\r\n/**\r\n * A factory method which creates Express/Connect compatible middleware functions to inject\r\n * a 'db' field on your request objects as well as ensuring that the Iridium Core is connected\r\n * to a MongoDB database before handling any requests.\r\n *\r\n * @internal\r\n */\r\nexport function ExpressMiddlewareFactory(core: Core): ExpressMiddleware {\r\n return function (req: http.ServerRequest, res: http.ServerResponse, next:(err?: Error, route?: String) => void) {\r\n core.connect().then(function() {\r\n Object.defineProperty(req, 'db', {\r\n get: function() { return core; }\r\n });\r\n next();\r\n }).catch(next);\r\n };\r\n}\r\n\r\n/**\r\n * An Express/Connect compatible middleware function which injects req.db and ensures that the Iridium Core\r\n * has an active database connection before continuing the request handling process.\r\n */\r\nexport interface ExpressMiddleware {\r\n (req: http.ServerRequest, res: http.ServerResponse, next:(err?: Error, route?: String) => void);\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/utils/ObjectID.js b/dist/lib/utils/ObjectID.js index 8ccea59..a8e3eab 100644 --- a/dist/lib/utils/ObjectID.js +++ b/dist/lib/utils/ObjectID.js @@ -1,3 +1,4 @@ +"use strict"; var MongoDB = require('mongodb'); /** * Converts a string to an ObjectID instance - a shortcut for require('mongodb').ObjectID.createFromHexString diff --git a/dist/lib/utils/ObjectID.js.map b/dist/lib/utils/ObjectID.js.map index dc04a37..c3c94d4 100644 --- a/dist/lib/utils/ObjectID.js.map +++ b/dist/lib/utils/ObjectID.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/utils/ObjectID.ts"],"names":["toObjectID"],"mappings":"AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAEpC;;;;;;;;;;;;GAYG;AACH,oBAA2B,KAAa;IACvCA,MAAMA,CAACA,OAAOA,CAACA,QAAQA,CAACA,mBAAmBA,CAACA,KAAKA,CAACA,CAACA;AACpDA,CAACA;AAFe,kBAAU,aAEzB,CAAA","file":"lib/utils/ObjectID.js","sourcesContent":["import MongoDB = require('mongodb');\r\n\r\n/**\r\n * Converts a string to an ObjectID instance - a shortcut for require('mongodb').ObjectID.createFromHexString\r\n *\r\n * @param value The string representation of the ObjectID you wish to create.\r\n * @returns A MongoDB ObjectID instance equivalent to the string you provided.\r\n *\r\n * You should be aware that this method performs no validation on the received string, MongoDB's ObjectID requires\r\n * that it either be a 12 byte UTF8 string, or a 24 byte hexadecimal string in order to be converted correctly.\r\n *\r\n * This method removes the need for your application to directly depend on MongoDB's Node.js client library,\r\n * which helps clean up your code a bit and reduces the headache of maintaining two different versions of the\r\n * library (since Iridium also has one).\r\n */\r\nexport function toObjectID(value: string): MongoDB.ObjectID {\r\n\treturn MongoDB.ObjectID.createFromHexString(value);\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["lib/utils/ObjectID.ts"],"names":[],"mappings":";AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAEpC;;;;;;;;;;;;GAYG;AACH,oBAA2B,KAAa;IACvC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAFe,kBAAU,aAEzB,CAAA","file":"lib/utils/ObjectID.js","sourcesContent":["import MongoDB = require('mongodb');\r\n\r\n/**\r\n * Converts a string to an ObjectID instance - a shortcut for require('mongodb').ObjectID.createFromHexString\r\n *\r\n * @param value The string representation of the ObjectID you wish to create.\r\n * @returns A MongoDB ObjectID instance equivalent to the string you provided.\r\n *\r\n * You should be aware that this method performs no validation on the received string, MongoDB's ObjectID requires\r\n * that it either be a 12 byte UTF8 string, or a 24 byte hexadecimal string in order to be converted correctly.\r\n *\r\n * This method removes the need for your application to directly depend on MongoDB's Node.js client library,\r\n * which helps clean up your code a bit and reduces the headache of maintaining two different versions of the\r\n * library (since Iridium also has one).\r\n */\r\nexport function toObjectID(value: string): MongoDB.ObjectID {\r\n\treturn MongoDB.ObjectID.createFromHexString(value);\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/lib/utils/Omnom.js b/dist/lib/utils/Omnom.js index b664cde..777a379 100644 --- a/dist/lib/utils/Omnom.js +++ b/dist/lib/utils/Omnom.js @@ -1,3 +1,4 @@ +"use strict"; var _ = require('lodash'); var MongoDB = require('mongodb'); var Omnom = (function () { @@ -24,7 +25,7 @@ var Omnom = (function () { var _this = this; if (original === undefined || original === null) return (original !== modified) && this.set(changePath, modified); - if (typeof original == 'number' && typeof modified == 'number' && original !== modified) { + if (typeof original === 'number' && typeof modified === 'number' && original !== modified) { if (this.options.atomicNumbers) return this.inc(changePath, modified - original); return this.set(changePath, modified); @@ -49,48 +50,59 @@ var Omnom = (function () { }, this); }; Omnom.prototype.onArray = function (original, modified, changePath) { - var _this = this; - var i, j; // Check if we can get from original => modified using just pulls if (original.length > modified.length) { - var pulls = []; - for (i = 0, j = 0; i < original.length && j < modified.length; i++) { - if (this.almostEqual(original[i], modified[j])) - j++; - else - pulls.push(original[i]); - } - for (; i < original.length; i++) - pulls.push(original[i]); - if (j === modified.length) { - if (pulls.length === 1) - return this.pull(changePath, pulls[0]); - // We can complete using just pulls - return pulls.forEach(function (pull) { return _this.pull(changePath, pull); }); - } - else - return this.set(changePath, modified); + return this.onSmallerArray(original, modified, changePath); } // Check if we can get from original => modified using just pushes if (original.length < modified.length) { - var canPush = true; - for (i = 0; i < original.length; i++) - if (this.almostEqual(original[i], modified[i]) < 1) { - canPush = false; - break; - } - if (canPush) { - for (i = original.length; i < modified.length; i++) - this.push(changePath, modified[i]); - return; - } + return this.onLargerArray(original, modified, changePath); } // Otherwise, we need to use $set to generate the new array + return this.onSimilarArray(original, modified, changePath); + }; + Omnom.prototype.onSmallerArray = function (original, modified, changePath) { + var _this = this; + var pulls = []; + var i = 0; + var j = 0; + for (; i < original.length && j < modified.length; i++) { + if (this.almostEqual(original[i], modified[j])) + j++; + else + pulls.push(original[i]); + } + for (; i < original.length; i++) + pulls.push(original[i]); + if (j === modified.length) { + if (pulls.length === 1) + return this.pull(changePath, pulls[0]); + // We can complete using just pulls + return pulls.forEach(function (pull) { return _this.pull(changePath, pull); }); + } + else + return this.set(changePath, modified); + }; + Omnom.prototype.onLargerArray = function (original, modified, changePath) { + var canPush = true; + for (var i = 0; i < original.length; i++) + if (this.almostEqual(original[i], modified[i]) < 1) { + canPush = false; + break; + } + if (canPush) { + for (var i = original.length; i < modified.length; i++) + this.push(changePath, modified[i]); + return; + } + return this.onSimilarArray(original, modified, changePath); + }; + Omnom.prototype.onSimilarArray = function (original, modified, changePath) { // Check how many manipulations would need to be performed, if it's more than half the array size // then rather re-create the array var sets = []; var partials = []; - for (i = 0; i < modified.length; i++) { + for (var i = 0; i < modified.length; i++) { var equality = this.almostEqual(original[i], modified[i]); if (equality === 0) sets.push(i); @@ -99,9 +111,9 @@ var Omnom = (function () { } if (sets.length > modified.length / 2) return this.set(changePath, modified); - for (i = 0; i < sets.length; i++) + for (var i = 0; i < sets.length; i++) this.set(this.resolve(changePath, sets[i].toString()), modified[sets[i]]); - for (i = 0; i < partials.length; i++) + for (var i = 0; i < partials.length; i++) this.onObject(original[partials[i]], modified[partials[i]], this.resolve(changePath, partials[i].toString())); }; Omnom.prototype.set = function (path, value) { @@ -166,13 +178,13 @@ var Omnom = (function () { Omnom.prototype.almostEqual = function (o1, o2) { if (!_.isPlainObject(o1) || !_.isPlainObject(o2)) return o1 == o2 ? 1 : 0; - var o1i, o1k = Object.keys(o1); - var o2k = Object.keys(o2); + var object1KeyIndex, object1Keys = Object.keys(o1); + var object2Keys = Object.keys(o2); var commonKeys = []; - for (o1i = 0; o1i < o1k.length; o1i++) - if (~o2k.indexOf(o1k[o1i])) - commonKeys.push(o1k[o1i]); - var totalKeys = o1k.length + o2k.length - commonKeys.length; + for (object1KeyIndex = 0; object1KeyIndex < object1Keys.length; object1KeyIndex++) + if (~object2Keys.indexOf(object1Keys[object1KeyIndex])) + commonKeys.push(object1Keys[object1KeyIndex]); + var totalKeys = object1Keys.length + object2Keys.length - commonKeys.length; var keysDifference = totalKeys - commonKeys.length; var requiredChanges = 0; for (var i = 0; i < commonKeys.length; i++) @@ -181,7 +193,7 @@ var Omnom = (function () { return 1 - (keysDifference / totalKeys) - (requiredChanges / commonKeys.length); }; return Omnom; -})(); +}()); exports.Omnom = Omnom; //# sourceMappingURL=Omnom.js.map diff --git a/dist/lib/utils/Omnom.js.map b/dist/lib/utils/Omnom.js.map index e503bc2..2e4674c 100644 --- a/dist/lib/utils/Omnom.js.map +++ b/dist/lib/utils/Omnom.js.map @@ -1 +1 @@ -{"version":3,"sources":["lib/utils/Omnom.ts"],"names":["Omnom","Omnom.constructor","Omnom.changes","Omnom.diff","Omnom.onObject","Omnom.onArray","Omnom.set","Omnom.unset","Omnom.inc","Omnom.push","Omnom.pull","Omnom.pullAll","Omnom.resolve","Omnom.almostEqual"],"mappings":"AAAA,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAEpC;IACIA,eAAmBA,OAEbA;QAFMC,uBAENA,GAFMA,YAENA;QAFaA,YAAOA,GAAPA,OAAOA,CAEpBA;QACFA,IAAIA,CAACA,QAAQA,GAAGA,EAAEA,CAACA;IACvBA,CAACA;IAUDD,sBAAIA,0BAAOA;aAAXA;YAQIE,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;;;OAAAF;IAMDA,oBAAIA,GAAJA,UAAKA,QAAaA,EAAEA,QAAaA;QAC7BG,IAAIA,CAACA,QAAQA,CAACA,QAAQA,EAAEA,QAAQA,CAACA,CAACA;QAClCA,MAAMA,CAACA,IAAIA,CAACA;IAChBA,CAACA;IAcMH,UAAIA,GAAXA,UAAYA,QAAaA,EAAEA,QAAaA,EAAEA,OAEzCA;QACGG,MAAMA,CAACA,IAAIA,KAAKA,CAACA,OAAOA,CAACA,CAACA,IAAIA,CAACA,QAAQA,EAAEA,QAAQA,CAACA,CAACA,OAAOA,CAACA;IAC/DA,CAACA;IAMOH,wBAAQA,GAAhBA,UAAiBA,QAAaA,EAAEA,QAAaA,EAAEA,UAAmBA;QAAlEI,iBA8BCA;QA7BGA,EAAEA,CAACA,CAACA,QAAQA,KAAKA,SAASA,IAAIA,QAAQA,KAAKA,IAAIA,CAACA;YAC5CA,MAAMA,CAACA,CAACA,QAAQA,KAAKA,QAAQA,CAACA,IAAIA,IAAIA,CAACA,GAAGA,CAACA,UAAUA,EAAEA,QAAQA,CAACA,CAACA;QAErEA,EAAEA,CAACA,CAACA,OAAOA,QAAQA,IAAIA,QAAQA,IAAIA,OAAOA,QAAQA,IAAIA,QAAQA,IAAIA,QAAQA,KAAKA,QAAQA,CAACA,C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ACA,MAAMA,CAACA;QAEnDA,IAAIA,eAAeA,GAAGA,CAACA,CAACA;QACxBA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,UAAUA,CAACA,MAAMA,EAAEA,CAACA,EAAEA;YACtCA,EAAEA,CAACA,CAACA,IAAIA,CAACA,WAAWA,CAACA,EAAEA,CAACA,UAAUA,CAACA,CAACA,CAACA,CAACA,EAAEA,EAAEA,CAACA,UAAUA,CAACA,CAACA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA;gBAACA,eAAeA,EAAEA,CAACA;QAEtFA,MAAMA,CAACA,CAACA,GAAGA,CAACA,cAAcA,GAAGA,SAASA,CAACA,GAAGA,CAACA,eAAeA,GAAGA,UAAUA,CAACA,MAAMA,CAACA,CAACA;IACpFA,CAACA;IACLb,YAACA;AAADA,CAhPA,AAgPCA,IAAA;AAhPY,aAAK,QAgPjB,CAAA","file":"lib/utils/Omnom.js","sourcesContent":["import _ = require('lodash');\r\nimport MongoDB = require('mongodb');\r\n\r\nexport class Omnom {\r\n constructor(public options: {\r\n atomicNumbers?: boolean;\r\n } = {}) {\r\n this._changes = {};\r\n }\r\n\r\n private _changes: {\r\n $set?: any;\r\n $unset?: any;\r\n $inc?: any;\r\n $push?: any;\r\n $pull?: any;\r\n $pullAll?: any;\r\n };\r\n get changes(): {\r\n $set?: any;\r\n $unset?: any;\r\n $inc?: any;\r\n $push?: any;\r\n $pull?: any;\r\n $pullAll?: any;\r\n } {\r\n return this._changes;\r\n }\r\n\r\n diff(original: number, modified: number): Omnom;\r\n diff(original: [any], modified: any[]): Omnom;\r\n diff(original: MongoDB.ObjectID, modified: MongoDB.ObjectID): Omnom;\r\n diff(original: Object, modified: Object): Omnom;\r\n diff(original: any, modified: any): Omnom {\r\n this.onObject(original, modified);\r\n return this;\r\n }\r\n\r\n static diff(original: number, modified: number, options?: {\r\n atomicNumbers?: boolean;\r\n });\r\n static diff(original: [any], modified: any[], options?: {\r\n atomicNumbers?: boolean;\r\n });\r\n static diff(original: MongoDB.ObjectID, modified: MongoDB.ObjectID, options?: {\r\n atomicNumbers?: boolean;\r\n });\r\n static diff(original: Object, modified: Object, options?: {\r\n atomicNumbers?: boolean;\r\n });\r\n static diff(original: any, modified: any, options?: {\r\n atomicNumbers?: boolean;\r\n }) {\r\n return new Omnom(options).diff(original, modified).changes;\r\n }\r\n\r\n private onObject(original: number, modified: number, changePath?: string);\r\n private onObject(original: [any], modified: any[], changePath?: string);\r\n private onObject(original: MongoDB.ObjectID, modified: MongoDB.ObjectID, changePath?: string);\r\n private onObject(original: Object, modified: Object, changePath?: string);\r\n private onObject(original: any, modified: any, changePath?: string) {\r\n if (original === undefined || original === null)\r\n return (original !== modified) && this.set(changePath, modified);\r\n\r\n if (typeof original == 'number' && typeof modified == 'number' && original !== modified) {\r\n if (this.options.atomicNumbers) return this.inc(changePath, modified - original);\r\n return this.set(changePath, modified);\r\n }\r\n\r\n if (Array.isArray(original) && Array.isArray(modified))\r\n return this.onArray(original, modified, changePath);\r\n\r\n if (original instanceof MongoDB.ObjectID && modified instanceof MongoDB.ObjectID)\r\n return !original.equals(modified) && this.set(changePath, modified);\r\n\r\n if (!_.isPlainObject(original) || !_.isPlainObject(modified))\r\n return !_.isEqual(original, modified) && this.set(changePath, modified);\r\n\r\n _.each(modified, (value, key) => {\r\n // Handle array diffs in their own special way\r\n if (Array.isArray(value) && Array.isArray(original[key])) this.onArray(original[key], value, this.resolve(changePath, key));\r\n\r\n // Otherwise, just keep going\r\n else this.onObject(original[key], value, this.resolve(changePath, key));\r\n }, this);\r\n\r\n // Unset removed properties\r\n _.each(original, (value, key) => {\r\n if (modified[key] === undefined) return this.unset(this.resolve(changePath, key));\r\n }, this);\r\n }\r\n\r\n private onArray(original: any[], modified: any[], changePath: string) {\r\n var i, j;\r\n\r\n // Check if we can get from original => modified using just pulls\r\n if (original.length > modified.length) {\r\n var pulls = [];\r\n for (i = 0, j = 0; i < original.length && j < modified.length; i++) {\r\n if (this.almostEqual(original[i], modified[j])) j++;\r\n else pulls.push(original[i]);\r\n }\r\n\r\n for (; i < original.length; i++)\r\n pulls.push(original[i]);\r\n\r\n if (j === modified.length) {\r\n if (pulls.length === 1) return this.pull(changePath, pulls[0]);\r\n // We can complete using just pulls\r\n return pulls.forEach((pull) => this.pull(changePath, pull));\r\n }\r\n\r\n // If we have a smaller target array than our source, we will need to re-create it\r\n // regardless (if we want to do so in a single operation anyway)\r\n else return this.set(changePath, modified);\r\n }\r\n\r\n // Check if we can get from original => modified using just pushes\r\n if (original.length < modified.length) {\r\n var canPush = true;\r\n for (i = 0; i < original.length; i++)\r\n if (this.almostEqual(original[i], modified[i]) < 1) {\r\n canPush = false;\r\n break;\r\n }\r\n\r\n if (canPush) {\r\n for (i = original.length; i < modified.length; i++)\r\n this.push(changePath, modified[i]);\r\n return;\r\n }\r\n }\r\n\r\n // Otherwise, we need to use $set to generate the new array\r\n\r\n // Check how many manipulations would need to be performed, if it's more than half the array size\r\n // then rather re-create the array\r\n\r\n var sets = [];\r\n var partials = [];\r\n for (i = 0; i < modified.length; i++) {\r\n var equality = this.almostEqual(original[i], modified[i]);\r\n if (equality === 0) sets.push(i);\r\n else if (equality < 1) partials.push(i);\r\n }\r\n\r\n if (sets.length > modified.length / 2)\r\n return this.set(changePath, modified);\r\n\r\n for (i = 0; i < sets.length; i++)\r\n this.set(this.resolve(changePath, sets[i].toString()), modified[sets[i]]);\r\n\r\n for (i = 0; i < partials.length; i++)\r\n this.onObject(original[partials[i]], modified[partials[i]], this.resolve(changePath, partials[i].toString()));\r\n }\r\n\r\n private set(path: string, value: any) {\r\n if (!this.changes.$set)\r\n this.changes.$set = {};\r\n\r\n this.changes.$set[path] = value;\r\n }\r\n\r\n private unset(path: string) {\r\n if (!this.changes.$unset)\r\n this.changes.$unset = {};\r\n\r\n this.changes.$unset[path] = 1;\r\n }\r\n\r\n private inc(path: string, value: number) {\r\n if (!this.changes.$inc)\r\n this.changes.$inc = {};\r\n\r\n this.changes.$inc[path] = value;\r\n }\r\n\r\n private push(path: string, value: any) {\r\n if (!this.changes.$push)\r\n this.changes.$push = {};\r\n\r\n if (this.changes.$push[path]) {\r\n if (this.changes.$push[path].$each)\r\n this.changes.$push[path].$each.push(value);\r\n else\r\n this.changes.$push[path] = { $each: [this.changes.$push[path], value] };\r\n } else this.changes.$push[path] = value;\r\n }\r\n\r\n private pull(path: string, value: any) {\r\n if (!this.changes.$pull)\r\n this.changes.$pull = {};\r\n\r\n if (this.changes.$pullAll && this.changes.$pullAll[path]) {\r\n return this.changes.$pullAll[path].push(value);\r\n }\r\n\r\n if (this.changes.$pull[path]) {\r\n this.pullAll(path, [this.changes.$pull[path], value]);\r\n delete this.changes.$pull[path];\r\n if (_.keys(this.changes.$pull).length === 0)\r\n delete this.changes.$pull;\r\n return;\r\n }\r\n\r\n this.changes.$pull[path] = value;\r\n }\r\n\r\n private pullAll(path: string, values: any[]) {\r\n if (!this.changes.$pullAll)\r\n this.changes.$pullAll = {};\r\n\r\n this.changes.$pullAll[path] = values;\r\n }\r\n\r\n private resolve(...args) {\r\n var validArguments = [];\r\n args.forEach(function (arg) {\r\n if (arg) validArguments.push(arg);\r\n });\r\n return validArguments.join('.');\r\n }\r\n\r\n private almostEqual(o1: Object, o2: Object);\r\n private almostEqual(o1: any, o2: any) {\r\n if (!_.isPlainObject(o1) || !_.isPlainObject(o2)) return o1 == o2 ? 1 : 0;\r\n\r\n var o1i, o1k = Object.keys(o1);\r\n var o2k = Object.keys(o2);\r\n\r\n var commonKeys = [];\r\n for (o1i = 0; o1i < o1k.length; o1i++)\r\n if (~o2k.indexOf(o1k[o1i])) commonKeys.push(o1k[o1i]);\r\n\r\n var totalKeys = o1k.length + o2k.length - commonKeys.length;\r\n var keysDifference = totalKeys - commonKeys.length;\r\n\r\n var requiredChanges = 0;\r\n for (var i = 0; i < commonKeys.length; i++)\r\n if (this.almostEqual(o1[commonKeys[i]], o2[commonKeys[i]]) < 1) requiredChan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,cAAc,GAAG,SAAS,CAAC,GAAG,CAAC,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACpF,CAAC;IACL,YAAC;AAAD,CA7PA,AA6PC,IAAA;AA7PY,aAAK,QA6PjB,CAAA","file":"lib/utils/Omnom.js","sourcesContent":["import _ = require('lodash');\r\nimport MongoDB = require('mongodb');\r\n\r\nexport class Omnom {\r\n constructor(public options: {\r\n atomicNumbers?: boolean;\r\n } = {}) {\r\n this._changes = {};\r\n }\r\n\r\n private _changes: {\r\n $set?: any;\r\n $unset?: any;\r\n $inc?: any;\r\n $push?: any;\r\n $pull?: any;\r\n $pullAll?: any;\r\n };\r\n get changes(): {\r\n $set?: any;\r\n $unset?: any;\r\n $inc?: any;\r\n $push?: any;\r\n $pull?: any;\r\n $pullAll?: any;\r\n } {\r\n return this._changes;\r\n }\r\n\r\n diff(original: number, modified: number): Omnom;\r\n diff(original: [any], modified: any[]): Omnom;\r\n diff(original: MongoDB.ObjectID, modified: MongoDB.ObjectID): Omnom;\r\n diff(original: Object, modified: Object): Omnom;\r\n diff(original: any, modified: any): Omnom {\r\n this.onObject(original, modified);\r\n return this;\r\n }\r\n\r\n static diff(original: number, modified: number, options?: {\r\n atomicNumbers?: boolean;\r\n });\r\n static diff(original: [any], modified: any[], options?: {\r\n atomicNumbers?: boolean;\r\n });\r\n static diff(original: MongoDB.ObjectID, modified: MongoDB.ObjectID, options?: {\r\n atomicNumbers?: boolean;\r\n });\r\n static diff(original: Object, modified: Object, options?: {\r\n atomicNumbers?: boolean;\r\n });\r\n static diff(original: any, modified: any, options?: {\r\n atomicNumbers?: boolean;\r\n }) {\r\n return new Omnom(options).diff(original, modified).changes;\r\n }\r\n\r\n private onObject(original: number, modified: number, changePath?: string): void;\r\n private onObject(original: [any], modified: any[], changePath?: string): void;\r\n private onObject(original: MongoDB.ObjectID, modified: MongoDB.ObjectID, changePath?: string): void;\r\n private onObject(original: Object, modified: Object, changePath?: string): void;\r\n private onObject(original: any, modified: any, changePath?: string): void {\r\n if (original === undefined || original === null)\r\n return (original !== modified) && this.set(changePath, modified);\r\n\r\n if (typeof original === 'number' && typeof modified === 'number' && original !== modified) {\r\n if (this.options.atomicNumbers) return this.inc(changePath, modified - original);\r\n return this.set(changePath, modified);\r\n }\r\n\r\n if (Array.isArray(original) && Array.isArray(modified))\r\n return this.onArray(original, modified, changePath);\r\n\r\n if (original instanceof MongoDB.ObjectID && modified instanceof MongoDB.ObjectID)\r\n return !original.equals(modified) && this.set(changePath, modified);\r\n\r\n if (!_.isPlainObject(original) || !_.isPlainObject(modified))\r\n return !_.isEqual(original, modified) && this.set(changePath, modified);\r\n\r\n _.each(modified, (value, key) => {\r\n // Handle array diffs in their own special way\r\n if (Array.isArray(value) && Array.isArray(original[key])) this.onArray(original[key], value, this.resolve(changePath, key));\r\n\r\n // Otherwise, just keep going\r\n else this.onObject(original[key], value, this.resolve(changePath, key));\r\n }, this);\r\n\r\n // Unset removed properties\r\n _.each(original, (value, key) => {\r\n if (modified[key] === undefined) return this.unset(this.resolve(changePath, key));\r\n }, this);\r\n }\r\n\r\n private onArray(original: any[], modified: any[], changePath: string): void {\r\n // Check if we can get from original => modified using just pulls\r\n if (original.length > modified.length) {\r\n return this.onSmallerArray(original, modified, changePath);\r\n }\r\n\r\n // Check if we can get from original => modified using just pushes\r\n if (original.length < modified.length) {\r\n return this.onLargerArray(original, modified, changePath);\r\n }\r\n\r\n // Otherwise, we need to use $set to generate the new array\r\n return this.onSimilarArray(original, modified, changePath);\r\n }\r\n\r\n private onSmallerArray(original: any[], modified: any[], changePath: string): void {\r\n let pulls = [];\r\n let i = 0;\r\n let j = 0;\r\n \r\n for (; i < original.length && j < modified.length; i++) {\r\n if (this.almostEqual(original[i], modified[j])) j++;\r\n else pulls.push(original[i]);\r\n }\r\n\r\n for (; i < original.length; i++)\r\n pulls.push(original[i]);\r\n\r\n if (j === modified.length) {\r\n if (pulls.length === 1) return this.pull(changePath, pulls[0]);\r\n // We can complete using just pulls\r\n return pulls.forEach((pull) => this.pull(changePath, pull));\r\n }\r\n\r\n // If we have a smaller target array than our source, we will need to re-create it\r\n // regardless (if we want to do so in a single operation anyway)\r\n else return this.set(changePath, modified);\r\n }\r\n \r\n private onLargerArray(original: any[], modified: any[], changePath: string): void {\r\n let canPush = true;\r\n for (let i = 0; i < original.length; i++)\r\n if (this.almostEqual(original[i], modified[i]) < 1) {\r\n canPush = false;\r\n break;\r\n }\r\n\r\n if (canPush) {\r\n for (let i = original.length; i < modified.length; i++)\r\n this.push(changePath, modified[i]);\r\n return;\r\n }\r\n \r\n return this.onSimilarArray(original, modified, changePath);\r\n }\r\n \r\n private onSimilarArray(original: any[], modified: any[], changePath: string): void {\r\n // Check how many manipulations would need to be performed, if it's more than half the array size\r\n // then rather re-create the array\r\n let sets = [];\r\n let partials = [];\r\n for (let i = 0; i < modified.length; i++) {\r\n let equality = this.almostEqual(original[i], modified[i]);\r\n if (equality === 0) sets.push(i);\r\n else if (equality < 1) partials.push(i);\r\n }\r\n\r\n if (sets.length > modified.length / 2)\r\n return this.set(changePath, modified);\r\n\r\n for (let i = 0; i < sets.length; i++)\r\n this.set(this.resolve(changePath, sets[i].toString()), modified[sets[i]]);\r\n\r\n for (let i = 0; i < partials.length; i++)\r\n this.onObject(original[partials[i]], modified[partials[i]], this.resolve(changePath, partials[i].toString()));\r\n }\r\n\r\n private set(path: string, value: any) {\r\n if (!this.changes.$set)\r\n this.changes.$set = {};\r\n\r\n this.changes.$set[path] = value;\r\n }\r\n\r\n private unset(path: string) {\r\n if (!this.changes.$unset)\r\n this.changes.$unset = {};\r\n\r\n this.changes.$unset[path] = 1;\r\n }\r\n\r\n private inc(path: string, value: number) {\r\n if (!this.changes.$inc)\r\n this.changes.$inc = {};\r\n\r\n this.changes.$inc[path] = value;\r\n }\r\n\r\n private push(path: string, value: any) {\r\n if (!this.changes.$push)\r\n this.changes.$push = {};\r\n\r\n if (this.changes.$push[path]) {\r\n if (this.changes.$push[path].$each)\r\n this.changes.$push[path].$each.push(value);\r\n else\r\n this.changes.$push[path] = { $each: [this.changes.$push[path], value] };\r\n } else this.changes.$push[path] = value;\r\n }\r\n\r\n private pull(path: string, value: any) {\r\n if (!this.changes.$pull)\r\n this.changes.$pull = {};\r\n\r\n if (this.changes.$pullAll && this.changes.$pullAll[path]) {\r\n return this.changes.$pullAll[path].push(value);\r\n }\r\n\r\n if (this.changes.$pull[path]) {\r\n this.pullAll(path, [this.changes.$pull[path], value]);\r\n delete this.changes.$pull[path];\r\n if (_.keys(this.changes.$pull).length === 0)\r\n delete this.changes.$pull;\r\n return;\r\n }\r\n\r\n this.changes.$pull[path] = value;\r\n }\r\n\r\n private pullAll(path: string, values: any[]) {\r\n if (!this.changes.$pullAll)\r\n this.changes.$pullAll = {};\r\n\r\n this.changes.$pullAll[path] = values;\r\n }\r\n\r\n private resolve(...args) {\r\n let validArguments = [];\r\n args.forEach(function (arg) {\r\n if (arg) validArguments.push(arg);\r\n });\r\n return validArguments.join('.');\r\n }\r\n\r\n private almostEqual(o1: Object, o2: Object);\r\n private almostEqual(o1: any, o2: any) {\r\n if (!_.isPlainObject(o1) || !_.isPlainObject(o2)) return o1 == o2 ? 1 : 0;\r\n\r\n let object1KeyIndex, object1Keys = Object.keys(o1);\r\n let object2Keys = Object.keys(o2);\r\n\r\n let commonKeys = [];\r\n for (object1KeyIndex = 0; object1KeyIndex < object1Keys.length; object1KeyIndex++)\r\n if (~object2Keys.indexOf(object1Keys[object1KeyIndex])) commonKeys.push(object1Keys[object1KeyIndex]);\r\n\r\n let totalKeys = object1Keys.length + object2Keys.length - commonKeys.length;\r\n let keysDifference = totalKeys - commonKeys.length;\r\n\r\n let requiredChanges = 0;\r\n for (let i = 0; i < commonKeys.length; i++)\r\n if (this.almostEqual(o1[commonKeys[i]], o2[commonKeys[i]]) < 1) requiredChanges++;\r\n\r\n return 1 - (keysDifference / totalKeys) - (requiredChanges / commonKeys.length);\r\n }\r\n}"],"sourceRoot":"/source/"} \ No newline at end of file