diff --git a/.settings/launch.json b/.vscode/launch.json
similarity index 100%
rename from .settings/launch.json
rename to .vscode/launch.json
diff --git a/.settings/tasks.json b/.vscode/tasks.json
similarity index 100%
rename from .settings/tasks.json
rename to .vscode/tasks.json
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1be3d2c..629f72c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,10 +1,46 @@
+## [v6.0.0](https://github.com/sierrasoftworks/iridium/tree/v6.0.0)
+- [656c73d](https://github.com/sierrasoftworks/iridium/commit/656c73d) Version 6.0.0
+- [7e4c31f](https://github.com/sierrasoftworks/iridium/commit/7e4c31f) (origin/master, origin/HEAD) Updated CHANGELOG
+- [8fe5933](https://github.com/sierrasoftworks/iridium/commit/8fe5933) Updated documentation
+
+## [v6.0.0-alpha.2](https://github.com/sierrasoftworks/iridium/tree/v6.0.0-alpha.2)
+- [30c17cb](https://github.com/sierrasoftworks/iridium/commit/30c17cb) Version 6.0.0-alpha.2
+- [56bb772](https://github.com/sierrasoftworks/iridium/commit/56bb772) fix: Undefined reference to Skmatc in ModelHandlers
+- [44fc771](https://github.com/sierrasoftworks/iridium/commit/44fc771) test: Fix compilation of tests
+- [cfb92a9](https://github.com/sierrasoftworks/iridium/commit/cfb92a9) tweak: Updated typescript definition pointer in package.json
+- [92ae221](https://github.com/sierrasoftworks/iridium/commit/92ae221) refactor: Remove _references.d.ts file
+- [9d4f52b](https://github.com/sierrasoftworks/iridium/commit/9d4f52b) refactor: Update all skmatc references to use new dependency structure
+- [a020ffe](https://github.com/sierrasoftworks/iridium/commit/a020ffe) dep: Update skmatc to 1.1.4
+- [9370b18](https://github.com/sierrasoftworks/iridium/commit/9370b18) dep: Update skmatc to 1.1.3
+- [f35342b](https://github.com/sierrasoftworks/iridium/commit/f35342b) Updated documentation
+- [a19768c](https://github.com/sierrasoftworks/iridium/commit/a19768c) Updated CHANGELOG
+
+## [v6.0.0-alpha.1](https://github.com/sierrasoftworks/iridium/tree/v6.0.0-alpha.1)
+- [a8f4c01](https://github.com/sierrasoftworks/iridium/commit/a8f4c01) Version 6.0.0-alpha.1
+- [f7886b3](https://github.com/sierrasoftworks/iridium/commit/f7886b3) Version 6.0.0-alpha.1
+- [8ba693c](https://github.com/sierrasoftworks/iridium/commit/8ba693c) tweak: Gulp CI command includes build step
+- [bd728e1](https://github.com/sierrasoftworks/iridium/commit/bd728e1) tweak: Added multi option to update options
+- [3fe9ebc](https://github.com/sierrasoftworks/iridium/commit/3fe9ebc) build: Fix CI test command
+- [6b73bbe](https://github.com/sierrasoftworks/iridium/commit/6b73bbe) dist: Build latest version of Iridium
+- [14cc15e](https://github.com/sierrasoftworks/iridium/commit/14cc15e) fix: Remove hacky approach to dependency resolution
+- [6032286](https://github.com/sierrasoftworks/iridium/commit/6032286) feat: Add index.d.ts file for TypeScript 1.6
+- [aabb131](https://github.com/sierrasoftworks/iridium/commit/aabb131) refactor: Remove references file from all files
+- [ba6c01c](https://github.com/sierrasoftworks/iridium/commit/ba6c01c) dep: Updated dependencies to latest versions
+- [12b201b](https://github.com/sierrasoftworks/iridium/commit/12b201b) refactor: Fix definitelytyped reference for mongodb remove function
+- [b869541](https://github.com/sierrasoftworks/iridium/commit/b869541) test: Fix reference to _id for a number of instance tests
+- [aa34363](https://github.com/sierrasoftworks/iridium/commit/aa34363) build: Switch to tsconfig for all build tasks
+- [351deb3](https://github.com/sierrasoftworks/iridium/commit/351deb3) build: Set experimental decorators flag when building TS files
+- [78f5339](https://github.com/sierrasoftworks/iridium/commit/78f5339) env: Update to VSCode 0.8.0
+- [6d1278d](https://github.com/sierrasoftworks/iridium/commit/6d1278d) Updated documentation
+- [0ea880a](https://github.com/sierrasoftworks/iridium/commit/0ea880a) Updated CHANGELOG
+
## [v5.11.0](https://github.com/sierrasoftworks/iridium/tree/v5.11.0)
- [bd475da](https://github.com/sierrasoftworks/iridium/commit/bd475da) Version 5.11.0
- [ea2a7c8](https://github.com/sierrasoftworks/iridium/commit/ea2a7c8) Listed docs in README (Closes [#9](https://github.com/sierrasoftworks/iridium/issues/9))
- [d806e89](https://github.com/sierrasoftworks/iridium/commit/d806e89) Updated documentation
- [971a2b8](https://github.com/sierrasoftworks/iridium/commit/971a2b8) Added implementation and tests for core level connection hooks
-- [4b52136](https://github.com/sierrasoftworks/iridium/commit/4b52136) (origin/master, origin/HEAD) Updated documentation
+- [4b52136](https://github.com/sierrasoftworks/iridium/commit/4b52136) Updated documentation
- [016263c](https://github.com/sierrasoftworks/iridium/commit/016263c) Updated CHANGELOG
## [v5.10.1](https://github.com/sierrasoftworks/iridium/tree/v5.10.1)
diff --git a/_references.d.ts b/_references.d.ts
deleted file mode 100644
index 4995816..0000000
--- a/_references.d.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-///
-///
diff --git a/build/build.js b/build/build.js
index 6fa1421..a4ca760 100644
--- a/build/build.js
+++ b/build/build.js
@@ -1,31 +1,33 @@
var gulp = require('gulp'),
typescript = require('gulp-typescript'),
sourcemaps = require('gulp-sourcemaps');
-
+
var paths = require('./paths');
-
-var tsProject = {
- module: 'commonjs',
- target: 'es5',
+
+var tsProjectLib = typescript.createProject('tsconfig.json', {
typescript: require('typescript')
-};
+});
+
+var tsProjectTest = typescript.createProject('test/tsconfig.json', {
+ typescript: require('typescript')
+});
gulp.task('build', ['build-lib', 'build-tests']);
-function build(files) {
+function build(files, project) {
var tsResult = gulp.src(files, { base: paths.projectRoot })
.pipe(sourcemaps.init())
- .pipe(typescript(tsProject));
-
+ .pipe(typescript(project));
+
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.distFolder));
}
gulp.task('build-lib', function () {
- return build(paths.buildFiles);
+ return build(paths.buildFiles, tsProjectLib);
});
gulp.task('build-tests', function () {
- return build(paths.testFiles);
+ return build(paths.testFiles, tsProjectTest);
});
\ No newline at end of file
diff --git a/build/ci.js b/build/ci.js
index ce54436..e70b436 100644
--- a/build/ci.js
+++ b/build/ci.js
@@ -7,7 +7,7 @@ var path = require('path');
var paths = require('./paths');
gulp.task('ci', function () {
- return runSequence('postpublish','build', 'ci-test');
+ return runSequence('build', 'ci-test');
});
gulp.task('ci-test', function () {
diff --git a/build/paths.js b/build/paths.js
index 1163216..492c61f 100644
--- a/build/paths.js
+++ b/build/paths.js
@@ -3,22 +3,23 @@ module.exports = {
distFolder: path.resolve(__dirname, '../dist'),
projectRoot: path.dirname(__dirname),
coverageFolder: path.resolve(__dirname, '../coverage'),
-
- buildFiles: ["lib/**/*.ts", "index.ts"],
- testFiles: ["test/**/*.ts"],
+
+ buildFiles: ["typings/DefinitelyTyped/tsd.d.ts", "lib/**/*.ts", "index.ts"],
+ testFiles: ["typings/DefinitelyTyped/tsd.d.ts", "test/**/*.ts"],
cleanFiles: ["coverage", "dist"],
-
+
builtTestFiles: 'dist/test/*.js',
builtFiles: ["dist/lib/**/*.js", "dist/index.js"],
testSupportFiles: ['dist/test/support/chai'],
-
+
docSourceFiles: [
+ "typings/DefinitelyTyped/tsd.d.ts",
"lib/Core.ts",
"lib/Model.ts",
"lib/Instance.ts",
-
+
"lib/Decorators.ts",
-
+
"lib/Plugins.ts",
"lib/Schema.ts",
"lib/Cache.ts",
@@ -27,12 +28,12 @@ module.exports = {
"lib/Configuration.ts",
"lib/Hooks.ts",
"lib/Transforms.ts",
-
+
"lib/caches/MemoryCache.ts",
"lib/caches/NoOpCache.ts",
-
+
"lib/cacheControllers/IDDirector.ts",
-
+
"lib/utils/ObjectID.ts"
]
};
\ No newline at end of file
diff --git a/build/publish.js b/build/publish.js
deleted file mode 100644
index 5f3ee71..0000000
--- a/build/publish.js
+++ /dev/null
@@ -1,14 +0,0 @@
-var gulp = require('gulp'),
- replace = require('gulp-replace');
-
-gulp.task('prepublish', function () {
- return gulp.src(['_references.d.ts'])
- .pipe(replace(/^(\/{3}\s*<[^>]*tsd\.d\.ts[^>]*\/>)/g, '//$1'))
- .pipe(gulp.dest('.'));
-});
-
-gulp.task('postpublish', function () {
- return gulp.src('_references.d.ts')
- .pipe(replace(/^\/{2}(\/{3}\s*<[^>]*tsd\.d\.ts[^>]*\/>)/ig, '$1'))
- .pipe(gulp.dest('.'));
-});
\ No newline at end of file
diff --git a/build/version.js b/build/version.js
index 1347c11..fc7fefd 100644
--- a/build/version.js
+++ b/build/version.js
@@ -45,7 +45,6 @@ gulp.task('version-push-tags', function (cb) {
gulp.task('version', function (callback) {
runSequence(
- 'postpublish',
'doc',
'version-bump',
'version-commit',
diff --git a/dist/index.js b/dist/index.js
index db3a407..959232e 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -18,4 +18,4 @@ __export(require('./lib/caches/NoOpCache'));
__export(require('./lib/cacheControllers/IDDirector'));
__export(require('./lib/utils/ObjectID'));
-//# sourceMappingURL=index.js.map
\ No newline at end of file
+//# sourceMappingURL=index.js.map
diff --git a/dist/lib/Aggregate.js b/dist/lib/Aggregate.js
index 1bf79e7..570eb84 100644
--- a/dist/lib/Aggregate.js
+++ b/dist/lib/Aggregate.js
@@ -1,3 +1,3 @@
-///
-//# sourceMappingURL=../lib/Aggregate.js.map
\ No newline at end of file
+
+//# sourceMappingURL=Aggregate.js.map
diff --git a/dist/lib/Aggregate.js.map b/dist/lib/Aggregate.js.map
index 043d6c5..438741a 100644
--- a/dist/lib/Aggregate.js.map
+++ b/dist/lib/Aggregate.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/Aggregate.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAI3C","file":"lib/Aggregate.js","sourcesContent":["/// \r\n\r\nexport interface Stage {\r\n\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/Aggregate.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Cache.js b/dist/lib/Cache.js
index d1bbc7d..d9710bc 100644
--- a/dist/lib/Cache.js
+++ b/dist/lib/Cache.js
@@ -1,3 +1,3 @@
-//# sourceMappingURL=../lib/Cache.js.map
\ No newline at end of file
+//# sourceMappingURL=Cache.js.map
diff --git a/dist/lib/Cache.js.map b/dist/lib/Cache.js.map
index 8fe1036..cb6eacc 100644
--- a/dist/lib/Cache.js.map
+++ b/dist/lib/Cache.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/Cache.ts"],"names":[],"mappings":"AAOC","file":"lib/Cache.js","sourcesContent":["/// \r\nimport Bluebird = require('bluebird');\r\n\r\nexport interface Cache {\r\n set(key: string, value: T): void;\r\n get(key: string): Bluebird;\r\n clear(key: string): void\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/Cache.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/CacheDirector.js b/dist/lib/CacheDirector.js
index fa0218f..0ae8228 100644
--- a/dist/lib/CacheDirector.js
+++ b/dist/lib/CacheDirector.js
@@ -1,3 +1,3 @@
-///
-//# sourceMappingURL=../lib/CacheDirector.js.map
\ No newline at end of file
+
+//# sourceMappingURL=CacheDirector.js.map
diff --git a/dist/lib/CacheDirector.js.map b/dist/lib/CacheDirector.js.map
index a6557ff..c8cb4bf 100644
--- a/dist/lib/CacheDirector.js.map
+++ b/dist/lib/CacheDirector.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/CacheDirector.ts"],"names":[],"mappings":"AAAA,AACA,4CAD4C;AAO3C","file":"lib/CacheDirector.js","sourcesContent":["/// \r\nexport interface CacheDirector {\r\n valid(object: T): boolean;\r\n buildKey(object: T): string;\r\n\r\n validQuery(conditions: any): boolean;\r\n buildQueryKey(conditions: any): string;\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/CacheDirector.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Configuration.js b/dist/lib/Configuration.js
index 01a23ff..a177dbe 100644
--- a/dist/lib/Configuration.js
+++ b/dist/lib/Configuration.js
@@ -1,3 +1,3 @@
-///
-//# sourceMappingURL=../lib/Configuration.js.map
\ No newline at end of file
+
+//# sourceMappingURL=Configuration.js.map
diff --git a/dist/lib/Configuration.js.map b/dist/lib/Configuration.js.map
index f15a39c..37929ab 100644
--- a/dist/lib/Configuration.js.map
+++ b/dist/lib/Configuration.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/Configuration.ts"],"names":[],"mappings":"AAAA,AACA,4CAD4C;AAS3C","file":"lib/Configuration.js","sourcesContent":["/// \r\nexport interface Configuration {\r\n host?: string;\r\n port?: number;\r\n hosts?: { address: string; port?: number }[];\r\n database?: string;\r\n username?: string;\r\n password?: string;\r\n [key:string]: any;\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/Configuration.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Core.js b/dist/lib/Core.js
index 0bc49be..0ffcfac 100644
--- a/dist/lib/Core.js
+++ b/dist/lib/Core.js
@@ -1,4 +1,3 @@
-///
var Bluebird = require('bluebird');
var MongoDB = require('mongodb');
var _ = require('lodash');
@@ -210,4 +209,4 @@ var Core = (function () {
})();
exports.Core = Core;
-//# sourceMappingURL=../lib/Core.js.map
\ No newline at end of file
+//# sourceMappingURL=Core.js.map
diff --git a/dist/lib/Core.js.map b/dist/lib/Core.js.map
index bd55bc9..55d342f 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"],"mappings":"AAAA,AACA,4CAD4C;AAC5C,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;IAcIA,cAAYA,GAA2BA,EAAEA,MAAsBA;QAiBvDC,qBAAgBA,GAAGA,QAAQA,CAACA,SAASA,CAACA,OAAOA,CAACA,WAAWA,CAACA,OAAOA,CAACA,CAACA;QAEnEA,aAAQA,GAAaA,EAAEA,CAACA;QAIxBA,WAAMA,GAAUA,IAAIA,qBAASA,EAAEA,CAACA;QArBpCA,IAAIA,IAAIA,GAAGA,KAAKA,CAACA,SAASA,CAACA,KAAKA,CAACA,IAAIA,CAACA,SAASA,EAAEA,CAACA,CAACA,CAACA;QACpDA,GAAGA,GAAGA,MAAMA,GAAGA,IAAIA,CAACA;QACpBA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,IAAIA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CAACA;YACnCA,EAAEA,CAACA,CAACA,OAAOA,IAAIA,CAACA,CAACA,CAACA,IAAIA,QAAQA,CAACA;gBAC3BA,GAAGA,GAAGA,IAAIA,CAACA,CAACA,CAACA,CAACA;YAClBA,IAAIA,CAACA,EAAEA,CAACA,CAACA,OAAOA,IAAIA,CAACA,CAACA,CAACA,IAAIA,QAAQA,CAACA;gB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,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":["/// \r\nimport 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.bind(this).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);\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.bind(this).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":["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"],"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;IAcIA,cAAYA,GAA2BA,EAAEA,MAAsBA;QAiBvDC,qBAAgBA,GAAGA,QAAQA,CAACA,SAASA,CAACA,OAAOA,CAACA,WAAWA,CAACA,OAAOA,CAACA,CAACA;QAEnEA,aAAQA,GAAaA,EAAEA,CAACA;QAIxBA,WAAMA,GAAUA,IAAIA,qBAASA,EAAEA,CAACA;QArBpCA,IAAIA,IAAIA,GAAGA,KAAKA,CAACA,SAASA,CAACA,KAAKA,CAACA,IAAIA,CAACA,SAASA,EAAEA,CAACA,CAACA,CAACA;QACpDA,GAAGA,GAAGA,MAAMA,GAAGA,IAAIA,CAACA;QACpBA,GAAGA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,IAAIA,CAACA,MAAMA,EAAEA,CAACA,EAAEA,EAAEA,CA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,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.bind(this).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);\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.bind(this).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 9418db3..c1dff17 100644
--- a/dist/lib/Cursor.js
+++ b/dist/lib/Cursor.js
@@ -148,4 +148,4 @@ var Cursor = (function () {
})();
exports.Cursor = Cursor;
-//# sourceMappingURL=../lib/Cursor.js.map
\ No newline at end of file
+//# sourceMappingURL=Cursor.js.map
diff --git a/dist/lib/Cursor.js.map b/dist/lib/Cursor.js.map
index a7e3c05..51eb0b9 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.rewind","Cursor.sort","Cursor.limit","Cursor.skip"],"mappings":"AAIA,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAGtC;;;;;;GAMG;AACH;IACIA;;;;;;OAMGA;IACHA,gBAAoBA,KAAkCA,EAAUA,UAAeA,EAASA,MAAsBA;QAA1FC,UAAKA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AsIlB,CAAA","file":"lib/Cursor.js","sourcesContent":["/// \r\nimport {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 * 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}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":["lib/Cursor.ts"],"names":["Cursor","Cursor.constructor","Cursor.count","Cursor.forEach","Cursor.map","Cursor.toArray","Cursor.next","Cursor.rewind","Cursor.sort","Cursor.limit","Cursor.skip"],"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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A,YAAYA,CAACA,QAAQA,EAAEA,KAAKA,EAAEA,SAASA,CAACA,EAA3DA,CAA2DA,CAACA,CAACA;QACzKA,CAACA,CAACA,CAACA,OAAOA,CAACA,QAAQA,CAACA,CAACA;IACzBA,CAACA;IAEDN;;;OAGGA;IACHA,uBAAMA,GAANA;QACIO,IAAIA,CAACA,MAAMA,CAACA,MAAMA,EAAEA,CAACA;QACrBA,MAAMA,CAACA,IAAIA,CAACA;IAChBA,CAACA;IAEDP;;;;OAIGA;IACHA,qBAAIA,GAAJA,UAAKA,cAAwCA;QACzCQ,MAAMA,CAACA,IAAIA,MAAMA,CAACA,IAAIA,CAACA,KAAKA,EAAEA,IAAIA,CAACA,UAAUA,EAAEA,IAAIA,CAACA,MAAMA,CAACA,IAAIA,CAACA,cAAcA,CAACA,CAACA,CAACA;IACrFA,CAACA;IAEDR;;;;OAIGA;IACHA,sBAAKA,GAALA,UAAMA,KAAaA;QACfS,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;IAEDT;;;;;OAKGA;IACHA,qBAAIA,GAAJA,UAAKA,IAAYA;QACbU,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;IACLV,aAACA;AAADA,CAtIA,AAsICA,IAAA;AAtIY,cAAM,SAsIlB,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 * 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}"],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Decorators.js b/dist/lib/Decorators.js
index 47a0345..31ced78 100644
--- a/dist/lib/Decorators.js
+++ b/dist/lib/Decorators.js
@@ -1,7 +1,6 @@
-///
var MongoDB = require('mongodb');
var _ = require('lodash');
-var skmatc = require('skmatc');
+var Skmatc = require('skmatc');
/**
* Specifies the name of the collection to which this instance's documents should be sent.
* @param name The name of the MongoDB collection to store the documents in.
@@ -44,7 +43,7 @@ exports.Index = Index;
*/
function Validate(forType, validate) {
return function (target) {
- target.validators = (target.validators || []).concat(skmatc.create(function (schema) { return schema === forType; }, validate));
+ target.validators = (target.validators || []).concat(Skmatc.create(function (schema) { return schema === forType; }, validate));
};
}
exports.Validate = Validate;
@@ -57,18 +56,19 @@ function Property() {
if (args.length > 1 && typeof args[args.length - 1] === 'boolean')
required = args.pop();
return function (target, property) {
+ var staticTarget = target;
if (!property)
name = args.shift();
else {
name = property;
- target = target.constructor;
+ staticTarget = target.constructor;
}
asType = args.pop() || false;
- target.schema = _.clone(target.schema || {});
+ staticTarget.schema = _.clone(staticTarget.schema || { _id: false });
if (!required && typeof asType !== 'boolean')
- target.schema[name] = { $required: required, $type: asType };
+ staticTarget.schema[name] = { $required: required, $type: asType };
else
- target.schema[name] = asType;
+ staticTarget.schema[name] = asType;
};
}
exports.Property = Property;
@@ -85,8 +85,9 @@ exports.Property = Property;
*/
function Transform(fromDB, toDB) {
return function (target, property) {
- target.constructor.transforms = _.clone(target.constructor.transforms || {});
- target.constructor.transforms[property] = {
+ var staticTarget = (target.constructor || target);
+ staticTarget.transforms = _.clone(staticTarget.transforms || {});
+ staticTarget.transforms[property] = {
fromDB: fromDB,
toDB: toDB
};
@@ -106,4 +107,4 @@ function ObjectID(target, name) {
}
exports.ObjectID = ObjectID;
-//# sourceMappingURL=../lib/Decorators.js.map
\ No newline at end of file
+//# sourceMappingURL=Decorators.js.map
diff --git a/dist/lib/Decorators.js.map b/dist/lib/Decorators.js.map
index a93fa2a..8d2b1bc 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"],"mappings":"AAAA,AACA,4CAD4C;AAC5C,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAMlC;;;;;;;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,CAA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AEA,IAAIA,CAACA,CAACA;AACjBA,CAACA;AANe,gBAAQ,WAMvB,CAAA","file":"lib/Decorators.js","sourcesContent":["/// \r\nimport MongoDB = require('mongodb');\r\nimport _ = require('lodash');\r\nimport skmatc = require('skmatc');\r\nimport {Instance} from './Instance';\r\nimport {Index, IndexSpecification} from './Index';\r\nimport {Schema} from './Schema';\r\nimport {InstanceImplementation} from './InstanceInterface';\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: { constructor: Function }, 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: Function) => void;\r\nexport function Property(...args: any[]): (target: any, name?: string) => void {\r\n\tlet name = null,\r\n\t\tasType = false,\r\n\t\trequired = true;\r\n\t\r\n\tif (args.length > 1 && typeof args[args.length - 1] === 'boolean')\r\n\t\trequired = args.pop();\r\n\t\r\n\treturn function(target: any, property?: string) {\r\n\t\tif (!property) name = args.shift();\r\n\t\telse {\r\n\t\t\tname = property;\r\n\t\t\ttarget = target.constructor;\r\n\t\t}\r\n\t\tasType = args.pop() || false;\r\n\t\t\r\n\t\ttarget.schema = _.clone(target.schema || {});\r\n\t\tif(!required && typeof asType !== 'boolean') target.schema[name] = { $required: required, $type: asType };\r\n\t\telse target.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\nexport function Transform(fromDB: (value: any) => any, toDB: (value: any) => any) {\r\n\treturn function(target: any, property: string) {\r\n\t\ttarget.constructor.transforms = _.clone(target.constructor.transforms || {})\r\n\t\ttarget.constructor.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: { constructor: typeof Instance }, name: string) {\r\n\tProperty(MongoDB.ObjectID)(target, name);\r\n\tTransform(\r\n\t\tvalue => value && value._bsontype == 'ObjectID' ? new MongoDB.ObjectID(value.id).toHexString() : value,\r\n\t\tvalue => value && typeof value === 'string' ? new MongoDB.ObjectID(value) : value\r\n\t)(target, name);\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":["lib/Decorators.ts"],"names":["Collection","Index","Validate","Property","Transform","ObjectID"],"mappings":"AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAOlC;;;;;;;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,CAAA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,QAAQA,CAACA,KAAKA,CAACA,GAAGA,KAAKA,EAAxEA,CAAwEA,CACjFA,CAACA,MAAMA,EAAEA,IAAIA,CAACA,CAACA;AACjBA,CAACA;AANe,gBAAQ,WAMvB,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 {Index, IndexSpecification} from './Index';\r\nimport {Schema} from './Schema';\r\nimport {InstanceImplementation} from './InstanceInterface';\r\nimport {Transforms} 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\nexport function Transform(fromDB: (value: any) => any, toDB: (value: any) => any) {\r\n\treturn function(target: Instance, property: string) {\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\tvalue => value && value._bsontype == 'ObjectID' ? new MongoDB.ObjectID(value.id).toHexString() : value,\r\n\t\tvalue => value && typeof value === 'string' ? new MongoDB.ObjectID(value) : value\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 f88be71..8fd2e3c 100644
--- a/dist/lib/General.js
+++ b/dist/lib/General.js
@@ -1,3 +1,3 @@
-///
-//# sourceMappingURL=../lib/General.js.map
\ No newline at end of file
+
+//# sourceMappingURL=General.js.map
diff --git a/dist/lib/General.js.map b/dist/lib/General.js.map
index ce272e2..e883d6d 100644
--- a/dist/lib/General.js.map
+++ b/dist/lib/General.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/General.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAiE3C","file":"lib/General.js","sourcesContent":["/// \r\n\r\n/**\r\n * A method which is called once an asynchronous operation has completed, an alternative\r\n * to using Promises.\r\n * @param T The type of object returned by the asynchronous operation.\r\n */\r\nexport interface Callback {\r\n /**\r\n * @param err The error object, if one occurred, otherwise null if the operation completed successfully.\r\n * @param object The result of the asynchronous operation if it completed successfully. If err is defined, the presence of this value is unknown.\r\n */\r\n (err: Error, object?: T): void;\r\n}\r\n\r\n/**\r\n * A method which is used to determine whether a value within a collection meets a set of criteria.\r\n * @param T The type of item in the collection.\r\n */\r\nexport interface Predicate {\r\n /**\r\n * @param object The value of the item in the collection\r\n * @param key The key, if one is available, under which the item appeared within the collection\r\n * @returns A true-y value if the item met the predicate conditions, false-y values if it did not.\r\n */\r\n (object: T, key?: string): boolean;\r\n}\r\n\r\n/**\r\n * A method which is called to retrieve a value of the given type.\r\n * @param T The type of value to be retrieved.\r\n */\r\nexport interface PropertyGetter {\r\n /**\r\n * Gets the current value of the property\r\n * @returns The current value\r\n */\r\n (): T;\r\n}\r\n\r\n/**\r\n * A method which is called to set a value of the given type.\r\n * @param T The type of value to set\r\n */\r\nexport interface PropertySetter {\r\n /**\r\n * Sets the value to the provided one\r\n * @param value The new value to set\r\n */\r\n (value: T): void;\r\n}\r\n\r\n/**\r\n * A compound property which provides either a getter, setter or both.\r\n * @param T The type of objects stored in the property\r\n */\r\nexport interface Property {\r\n /**\r\n * An optional getter which can be used to retrieve the property's value\r\n */\r\n get?: PropertyGetter;\r\n /**\r\n * An optional setter which can be used to set the property's value\r\n */\r\n set?: PropertySetter;\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/General.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Hooks.js b/dist/lib/Hooks.js
index 117b52f..d85dcbf 100644
--- a/dist/lib/Hooks.js
+++ b/dist/lib/Hooks.js
@@ -1,3 +1,3 @@
-//# sourceMappingURL=../lib/Hooks.js.map
\ No newline at end of file
+//# sourceMappingURL=Hooks.js.map
diff --git a/dist/lib/Hooks.js.map b/dist/lib/Hooks.js.map
index 91cecf9..ac61dd3 100644
--- a/dist/lib/Hooks.js.map
+++ b/dist/lib/Hooks.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/Hooks.ts"],"names":[],"mappings":"AAQC","file":"lib/Hooks.js","sourcesContent":["/// \r\nimport instance = require('./Instance');\r\n\r\nexport interface Hooks {\r\n onCreating? (document: TDocument): void;\r\n onRetrieved? (document: TDocument): void;\r\n onReady? (instance: TInstance): void;\r\n onSaving? (instance: TInstance, changes: any): void;\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/Hooks.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Index.js b/dist/lib/Index.js
index f99f4da..632e5c0 100644
--- a/dist/lib/Index.js
+++ b/dist/lib/Index.js
@@ -1,3 +1,3 @@
-//# sourceMappingURL=../lib/Index.js.map
\ No newline at end of file
+//# sourceMappingURL=Index.js.map
diff --git a/dist/lib/Index.js.map b/dist/lib/Index.js.map
index 713707c..0b0f8cb 100644
--- a/dist/lib/Index.js.map
+++ b/dist/lib/Index.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/Index.ts"],"names":[],"mappings":"AAUC","file":"lib/Index.js","sourcesContent":["/// \r\nimport MongoDB = require('mongodb');\r\n\r\nexport interface Index {\r\n spec: IndexSpecification;\r\n options?: MongoDB.IndexOptions;\r\n}\r\n\r\nexport interface IndexSpecification {\r\n [key: string]: number | string;\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/Index.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Instance.js b/dist/lib/Instance.js
index 1817ffe..4d0dc37 100644
--- a/dist/lib/Instance.js
+++ b/dist/lib/Instance.js
@@ -1,7 +1,7 @@
var _ = require('lodash');
var MongoDB = require('mongodb');
var Bluebird = require('bluebird');
-var skmatc = require('skmatc');
+var Skmatc = require('skmatc');
/**
* The default Iridium Instance implementation which provides methods for saving, refreshing and
* removing the wrapped document from the collection, as well as integrating with Omnom, our
@@ -264,7 +264,7 @@ var Instance = (function () {
* Additional which should be made available for use in the schema definition for this instance.
*/
Instance.validators = [
- skmatc.create(function (schema) { return schema === MongoDB.ObjectID; }, function (schema, data) {
+ Skmatc.create(function (schema) { return schema === MongoDB.ObjectID; }, function (schema, data) {
return this.assert(!data || data instanceof MongoDB.ObjectID || (data._bsontype === 'ObjectID' && data.id));
}, { name: 'ObjectID validation' })
];
@@ -280,4 +280,4 @@ var Instance = (function () {
})();
exports.Instance = Instance;
-//# sourceMappingURL=../lib/Instance.js.map
\ No newline at end of file
+//# sourceMappingURL=Instance.js.map
diff --git a/dist/lib/Instance.js.map b/dist/lib/Instance.js.map
index 316587f..d77cc6b 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.toString"],"mappings":"AAWA,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AACtC,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH;IACIA;;;;;;;OAOGA;IACHA,kBAAYA,KAAkCA,EAAEA,QAAmBA,EAAEA,KAAqBA,EAAEA,SAA0BA;QAT1HC,iBAsWCA;QA7VwEA,qBAAqBA,GAArBA,YAAqBA;QAAEA,yBAA0BA,GAA1BA,iBAA0BA;QAClHA,IAAIA,CAACA,MAAMA,GAAGA,KAAKA,CAACA;QAEpBA,IAAIA,CAACA,MAAMA,GAAGA,CAACA,CAACA,KAAKA,CAACA;QACtBA,IAAIA,CAACA,UAAUA,GAAGA,SA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AACA;QAEHA,MAAMA,CAACA,QAAQA,CAACA,OAAOA,EAAEA,CAACA,IAAIA,CAACA;YAC3BA,UAAUA,GAAGA,CAACA,CAACA,SAASA,CAACA,UAAUA,CAACA,CAACA;YACrCA,CAACA,CAACA,KAAKA,CAACA,UAAUA,EAAEA,EAAEA,GAAGA,EAAEA,KAAIA,CAACA,SAASA,CAACA,GAAGA,EAAEA,CAACA,CAACA;YAEjDA,EAAEA,CAACA,CAACA,CAACA,OAAOA,CAACA,CAACA,CAACA;gBACXA,IAAIA,UAAUA,GAAGA,KAAIA,CAACA,MAAMA,CAACA,OAAOA,CAACA,QAAQA,CAACA,KAAIA,CAACA,SAASA,CAACA,CAACA;gBAC9DA,EAAEA,CAACA,CAACA,UAAUA,CAACA,MAAMA,CAACA;oBAACA,MAAMA,CAACA,QAAQA,CAACA,MAAMA,CAACA,UAAUA,CAACA,KAAKA,CAACA,CAACA,IAAIA,CAACA,KAAIA,CAACA,CAACA,OAAOA,CAACA,QAAQA,CAACA,CAACA;gBAE7FA,IAAIA,QAAQA,GAAGA,CAACA,CAACA,SAASA,CAACA,KAAIA,CAACA,SAASA,CAACA,CAACA;gBAC3CA,IAAIA,QAAQA,GAAGA,CAACA,CAACA,SAASA,CAACA,KAAIA,CAACA,SAASA,CAACA,CAACA;gBAE3CA,OAAOA,GAAGA,KAAIA,CAACA,MAAMA,CAACA,OAAOA,CAACA,IAAIA,CAACA,QAAQA,EAAEA,QAAQA,CAACA,CAACA;YAC3DA,CAACA;YAEDA,EAAEA,CAACA,CAACA,CAACA,CAACA,CAACA,IAAIA,CAACA,OAAOA,CAACA,CAACA,MAAMA,CAACA;gBAACA,MAAMA,CAACA,IAAIA,CAACA;YAEzCA,MAAMA,CAACA,OAAOA,CAACA;QACnBA,CAACA,CAACA,CAACA,IAAIA,CAACA,UAACA,OAAOA;YACZA,EAAEA,CAACA,CAACA,CAACA,OAAOA,IAAIA,CAACA,KAAIA,CAACA,MAAMA,CAACA;gBAACA,MAAMA,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,CAACA;4BAC/BA,GAAGA,CAACA,SAASA,CAACA,GAAGA,OAAOA,CAACA;4BACzBA,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;wBACvBA,CAACA;wBAEDA,MAAMA,CAACA,OAAOA,CAACA,OAAOA,CAACA,CAACA;oBAC5BA,CAACA,CAACA,CAACA;gBACPA,CAACA,CAACA,CAACA;YACPA,CAACA;QACLA,CAACA,CAACA,CAACA,KAAKA,CAACA,UAAAA,GAAGA;YACRA,GAAGA,CAACA,UAAUA,CAACA,GAAGA,KAAIA,CAACA,SAASA,CAACA;YACjCA,GAAGA,CAACA,UAAUA,CAACA,GAAGA,KAAIA,CAACA,SAASA,CAACA;YACjCA,MAAMA,CAACA,QAAQA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;QAChCA,CAACA,CAACA,CAACA,IAAIA,CAACA,UAACA,OAAgBA;YACrBA,UAAUA,GAAGA,EAAEA,GAAGA,EAAEA,KAAIA,CAACA,SAASA,CAACA,GAAGA,EAAEA,CAACA;YACzCA,EAAEA,CAACA,CAACA,CAACA,OAAOA,CAACA;gBAACA,MAAMA,CAACA,KAAIA,CAACA,SAASA,CAACA;YAEpCA,MAAMA,CAACA,IAAIA,QAAQA,CAAYA,UAACA,OAAOA,EAAEA,MAAMA;gBAC3CA,KAAIA,CAACA,MAAMA,CAACA,UAAUA,CAACA,OAAOA,CAACA,UAAUA,EAAEA,UAACA,GAAUA,EAAEA,MAAMA;oBAC1DA,EAAEA,CAACA,CAACA,GAAGA,CAACA;wBAACA,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;oBAC5BA,MAAMA,CAACA,OAAOA,CAACA,MAAMA,CAACA,CAACA;gBAC3BA,CAACA,CAACA,CAACA;YACPA,CAACA,CAACA,CAACA;QACPA,CAACA,CAACA,CAACA,IAAIA,CAACA,UAACA,MAAiBA;YACtBA,EAAEA,CAAAA,CAACA,CAACA,MAAMA,CAACA,CAACA,CAACA;gBACTA,KAA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MA,GAAWA;QACpBA,GAAGA,EAAEA,KAAKA;KACbA,CAACA;IAEFA;;OAEGA;IACIA,mBAAUA,GAAuBA;QACpCA,MAAMA,CAACA,MAAMA,CAACA,UAAAA,MAAMA,IAAIA,OAAAA,MAAMA,KAAKA,OAAOA,CAACA,QAAQA,EAA3BA,CAA2BA,EAAEA,UAASA,MAAMA,EAAEA,IAAIA;YACtE,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,CAAC,CAAC;QAChH,CAAC,EAAEA,EAAEA,IAAIA,EAAEA,qBAAqBA,EAAEA,CAACA;KACtCA,CAACA;IAEFA;;OAEGA;IACIA,mBAAUA,GAAeA,EAE/BA,CAACA;IAOFA;;OAEGA;IACIA,gBAAOA,GAA+CA,EAAEA,CAACA;IAiQpEA,eAACA;AAADA,CAtWA,AAsWCA,IAAA;AAtWY,gBAAQ,WAsWpB,CAAA","file":"lib/Instance.js","sourcesContent":["/// \r\nimport {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\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 = _.cloneDeep(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 }) => 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 }) => 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>>) => 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) => 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[] = [\r\n skmatc.create(schema => schema === MongoDB.ObjectID, function(schema, data) {\r\n return this.assert(!data || data instanceof MongoDB.ObjectID || (data._bsontype === 'ObjectID' && data.id));\r\n }, { name: 'ObjectID validation' })\r\n ];\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 = _.cloneDeep(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 = _.cloneDeep(this._original);\r\n var modified = _.cloneDeep(this._modified);\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 = _.cloneDeep(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 = _.cloneDeep(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 = _.cloneDeep(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 = _.cloneDeep(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":["Instance","Instance.constructor","Instance.document","Instance.save","Instance.update","Instance.refresh","Instance.delete","Instance.remove","Instance.first","Instance.select","Instance.toJSON","Instance.toString"],"mappings":"AAUA,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AACtC,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH;IACIA;;;;;;;OAOGA;IACHA,kBAAYA,KAAkCA,EAAEA,QAAmBA,EAAEA,KAAqBA,EAAEA,SAA0BA;QAT1HC,iBAsWCA;QA7VwEA,qBAAqBA,GAArBA,YAAqBA;QAAEA,yBAA0BA,GAA1BA,iBAA0BA;QAClHA,IAAIA,CAACA,MAAMA,GAAGA,KAAKA,CAACA;QAEpBA,IAAIA,CAACA,MAAMA,GAAGA,CAACA,CAACA,KAAKA,CAACA;QACtBA,IAAIA,CAACA,UAAUA,GAAGA,SAASA,CAACA;QAC5BA,IAAIA,CAACA,SAASA,GAAGA,QAAQA,CAACA;QAC1BA,IAAIA,CAACA,SAASA,GAAGA,CAACA,CAACA,SAASA,CAAYA,QAAQA,CAACA,CAACA;QAElDA,CAACA,CAACA,IAAIA,CAACA,KAAKA,CAACA,IAAIA,CAACA,OAAOA,EAACA,UAACA,MAAcA;YACrCA,EAAEA,CAACA,CAACA,MAAMA,CAACA,WAAWA,CAACA;gBAACA,MA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C,IAAI,IAAI,IAAI,YAAY,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,UAAU,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAChH,CAAC,EAAEA,EAAEA,IAAIA,EAAEA,qBAAqBA,EAAEA,CAACA;KACtCA,CAACA;IAEFA;;OAEGA;IACIA,mBAAUA,GAAeA,EAE/BA,CAACA;IAOFA;;OAEGA;IACIA,gBAAOA,GAA+CA,EAAEA,CAACA;IAiQpEA,eAACA;AAADA,CAtWA,AAsWCA,IAAA;AAtWY,gBAAQ,WAsWpB,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\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 = _.cloneDeep(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 }) => 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 }) => 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>>) => 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) => 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[] = [\r\n Skmatc.create(schema => schema === MongoDB.ObjectID, function(schema, data) {\r\n return this.assert(!data || data instanceof MongoDB.ObjectID || (data._bsontype === 'ObjectID' && data.id));\r\n }, { name: 'ObjectID validation' })\r\n ];\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 = _.cloneDeep(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 = _.cloneDeep(this._original);\r\n var modified = _.cloneDeep(this._modified);\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 = _.cloneDeep(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 = _.cloneDeep(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 = _.cloneDeep(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 = _.cloneDeep(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 430cbbd..760d882 100644
--- a/dist/lib/InstanceInterface.js
+++ b/dist/lib/InstanceInterface.js
@@ -1,3 +1,3 @@
-//# sourceMappingURL=../lib/InstanceInterface.js.map
\ No newline at end of file
+//# sourceMappingURL=InstanceInterface.js.map
diff --git a/dist/lib/InstanceInterface.js.map b/dist/lib/InstanceInterface.js.map
index 5926ff6..50a9833 100644
--- a/dist/lib/InstanceInterface.js.map
+++ b/dist/lib/InstanceInterface.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/InstanceInterface.ts"],"names":[],"mappings":"AAkGC","file":"lib/InstanceInterface.js","sourcesContent":["/// \r\nimport {Schema} from './Schema';\r\nimport {Model} from './Model';\r\nimport * as Index from './Index';\r\nimport {CacheDirector} from './CacheDirector';\r\nimport {Transforms} from './Transforms';\r\n\r\n/**\r\n * This interface dictates the format of an instance class which wraps documents received\r\n * from the database for a specific Iridium model.\r\n * \r\n * @param TDocument The interface representing the documents stored in the database, after being passed through the transforms pipeline.\r\n * @param TInstance The type of object which is instantiated when calling this implementation's constructor.\r\n * \r\n * It is important to note that, when implementing this interface, each of the properties and methods\r\n * should be exposed statically. That is, you would expose the collection property as a static variable\r\n * on the instance implementation, since prototype methods and variables become available to consumers of the\r\n * instance itself.\r\n */\r\nexport interface InstanceImplementation {\r\n /**\r\n * A constructor which creates a new instance tied to the given model and representing the given document.\r\n * @param model The Iridium Model which this instance should be tied to, gives the instance access to the database collection and any other context it requires.\r\n * @param doc The document this instance should wrap from the database. This provides the data context for the instance.\r\n * @param isNew Whether this document is known to exist in the database or not, for example, if the instance was generated from user input and hasn't been saved yet.\r\n * @param isPartial Whether the document which has been given to this instance had any field restrictions imposed on it during the query, and may therefore only contain partial data.\r\n */\r\n new (model: Model, doc: TDocument, isNew?: boolean, isPartial?: boolean): TInstance;\r\n \r\n /**\r\n * The name of the database collection from which documents are retrieved, and to which they are stored.\r\n */\r\n collection: string;\r\n\r\n /**\r\n * The database schematic used for validation of instances prior to storing them in the database.\r\n * This schematic should follow the guides set out in skmatc's documentation, and is used whenever\r\n * you insert a new document into the collection or save an instance using the default instance type.\r\n * Operations like update() (and by extension, save() when using the update operations) cannot be checked\r\n * by skmatc for consistency and as a result will not have their data validated - be careful when making\r\n * use of them as a result.\r\n */\r\n schema: Schema;\r\n \r\n /**\r\n * Any additional indexes on the collection which should be managed by Iridium.\r\n * This field is optional, but if provided allows you to make use of the model's ensureIndexes() method\r\n * to automatically generate all specified indexes.\r\n */\r\n indexes?: (Index.Index | Index.IndexSpecification)[];\r\n \r\n /**\r\n * An optional method which will be called whenever a document is about to be inserted into the database,\r\n * allowing you to set default values and do any preprocessing you wish prior to the document being inserted.\r\n */\r\n onCreating? (document: TDocument): void;\r\n \r\n /**\r\n * An optional method which is called whenever a new document is received from the model's collection and\r\n * prior to the document being wrapped, can be used to perform preprocessing if necessary - however we recommend\r\n * you rather make use of transforms for that task.\r\n */\r\n onRetrieved? (document: TDocument): void;\r\n \r\n /**\r\n * An optional method which is called whenever a new document for this model has been wrapped in an instance.\r\n */\r\n onReady? (instance: TInstance): void;\r\n \r\n /**\r\n * An optional method which is called prior to saving an instance, it is provided with the instance itself as\r\n * well as the proposed changes to the instance. This allows you to make additional changes, such as updating\r\n * a lastChanged property on the document, or abort changes by throwing an error.\r\n */\r\n onSaving? (instance: TInstance, changes: any): void;\r\n\r\n /**\r\n * The cache controller used to determine whether a document may be cached, as well as deriving a unique cache\r\n * key for the document and similarly, for a query. This works in concert with the cache implementation itself\r\n * to ensure that documents are cached in an intelligent manner. By default this will simply make use of the\r\n * document's _id field as the cache key - however that behaviour may be modified if you wish to query on other\r\n * properties instead.\r\n */\r\n cache?: CacheDirector;\r\n \r\n /**\r\n * Any additional validation types you wish to make available for use within this model's database schema. This\r\n * allows you to validate using conditions otherwise not available within skmatc itself. For more information\r\n * on implementing a validator, take a look at the skmatc documentation on GitHub.\r\n */\r\n validators?: Skmatc.Validator[];\r\n \r\n /**\r\n * Any transform operations you would like to perform on documents received from the database, or prior to being\r\n * sent to the database. These may include things such as converting ObjectIDs to strings for the application, and\r\n * then back to ObjectIDs once they return to the database.\r\n */\r\n transforms?: Transforms;\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/InstanceInterface.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Middleware.js b/dist/lib/Middleware.js
index 33be524..bcd68e8 100644
--- a/dist/lib/Middleware.js
+++ b/dist/lib/Middleware.js
@@ -1,3 +1,3 @@
-//# sourceMappingURL=../lib/Middleware.js.map
\ No newline at end of file
+//# sourceMappingURL=Middleware.js.map
diff --git a/dist/lib/Middleware.js.map b/dist/lib/Middleware.js.map
index 05be03c..e305d11 100644
--- a/dist/lib/Middleware.js.map
+++ b/dist/lib/Middleware.js.map
@@ -1 +1 @@
-{"version":3,"sources":["lib/Middleware.ts"],"names":[],"mappings":"AASC","file":"lib/Middleware.js","sourcesContent":["/// \r\nimport {Core} from './Core';\r\n\r\n/**\r\n * Middlewares provided by Iridium, such as the Express one, derive from this interface.\r\n * @internal\r\n */\r\nexport interface MiddlewareFactory {\r\n (core: Core): T;\r\n}"],"sourceRoot":"/source/"}
\ No newline at end of file
+{"version":3,"sources":[],"names":[],"mappings":"","file":"lib/Middleware.js","sourcesContent":[],"sourceRoot":"/source/"}
\ No newline at end of file
diff --git a/dist/lib/Model.js b/dist/lib/Model.js
index 618c5f3..84ef40e 100644
--- a/dist/lib/Model.js
+++ b/dist/lib/Model.js
@@ -1,4 +1,3 @@
-///
var MongoDB = require('mongodb');
var Bluebird = require('bluebird');
var _ = require('lodash');
@@ -538,4 +537,4 @@ var Model = (function () {
})();
exports.Model = Model;
-//# sourceMappingURL=../lib/Model.js.map
\ No newline at end of file
+//# sourceMappingURL=Model.js.map
diff --git a/dist/lib/Model.js.map b/dist/lib/Model.js.map
index dd70524..06d2102 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,AACA,4CAD4C;AAC5C,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,QAAQ,WAAW,UAAU,CAAC,CAAC;AAEtC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAE7B,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;AAK9D;;;;;;;;;GASG;AACH;IACIA;;;;;OAKGA;IACHA,eAAYA,IAAUA,EAAEA,YAA0DA;QA2E1EC,WAAMA,GAAgCA,EAAEA,CAACA;QA1E7CA,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,KAA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,EAAXA,CAAWA,CAACA,CAACA;QAC5IA,CAACA;QAEDA,MAAMA,CAACA,IAAIA,QAAQA,CAAUA,UAACA,OAAOA,EAAEA,MAAMA;YACzCA,KAAIA,CAACA,UAAUA,CAACA,SAASA,CAACA,KAAKA,EAACA,UAACA,GAAGA,EAAEA,MAAsBA;gBACxDA,EAAEA,CAACA,CAACA,GAAGA,CAACA;oBAACA,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;gBAC5BA,MAAMA,CAACA,OAAOA,CAAMA,CAACA,CAACA,MAAMA,CAACA,EAAEA,CAACA,CAACA;YACrCA,CAACA,CAACA,CAACA;QACPA,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,CA9sBA,AA8sBCA,IAAA;AA9sBY,aAAK,QA8sBjB,CAAA","file":"lib/Model.js","sourcesContent":["/// \r\nimport MongoDB = require('mongodb');\r\nimport Bluebird = require('bluebird');\r\nimport util = require('util');\r\nimport _ = require('lodash');\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} 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'] = {\r\n fromDB: value => value._bsontype == 'ObjectID' ? new MongoDB.ObjectID(value.id).toHexString() : value,\r\n toDB: value => value && typeof value === 'string' ? new MongoDB.ObjectID(value) : value\r\n };\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