From 669f414dfb29c0773236b644cf841fe2ed4e9cdf Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Tue, 21 Apr 2015 22:15:02 +0200 Subject: [PATCH] Add compiled JS files back in It'll make the repository a bit heavier, but will allow us to actually run CI tests... Lose/Win situation I guess until we can get a proper in-place compiler set up --- .gitignore | 2 - example/IntelliSense.js | 71 +++ example/IntelliSense.js.map | 1 + index.js | 45 ++ index.js.map | 1 + lib/Cache.js | 1 + lib/Cache.js.map | 1 + lib/CacheDirector.js | 1 + lib/CacheDirector.js.map | 1 + lib/Configuration.js | 1 + lib/Configuration.js.map | 1 + lib/Core.js | 153 ++++++ lib/Core.js.map | 1 + lib/General.js | 1 + lib/General.js.map | 1 + lib/Hooks.js | 2 + lib/Hooks.js.map | 1 + lib/Instance.js | 213 +++++++++ lib/Instance.js.map | 1 + lib/Middleware.js | 1 + lib/Middleware.js.map | 1 + lib/Model.js | 624 +++++++++++++++++++++++++ lib/Model.js.map | 1 + lib/Plugins.js | 2 + lib/Plugins.js.map | 1 + lib/Schema.js | 1 + lib/Schema.js.map | 1 + lib/cacheControllers/IDDirector.js | 13 + lib/cacheControllers/IDDirector.js.map | 1 + lib/caches/MemoryCache.js | 23 + lib/caches/MemoryCache.js.map | 1 + lib/caches/NoOpCache.js | 17 + lib/caches/NoOpCache.js.map | 1 + lib/middleware/Express.js | 14 + lib/middleware/Express.js.map | 1 + lib/utils/Omnom.js | 149 ++++++ lib/utils/Omnom.js.map | 1 + test/Core.js | 131 ++++++ test/Core.js.map | 1 + test/Iridium.js | 13 + test/Iridium.js.map | 1 + test/Model.js | 86 ++++ test/Model.js.map | 1 + test/support/chai.js | 8 + test/support/chai.js.map | 1 + 45 files changed, 1592 insertions(+), 2 deletions(-) create mode 100644 example/IntelliSense.js create mode 100644 example/IntelliSense.js.map create mode 100644 index.js create mode 100644 index.js.map create mode 100644 lib/Cache.js create mode 100644 lib/Cache.js.map create mode 100644 lib/CacheDirector.js create mode 100644 lib/CacheDirector.js.map create mode 100644 lib/Configuration.js create mode 100644 lib/Configuration.js.map create mode 100644 lib/Core.js create mode 100644 lib/Core.js.map create mode 100644 lib/General.js create mode 100644 lib/General.js.map create mode 100644 lib/Hooks.js create mode 100644 lib/Hooks.js.map create mode 100644 lib/Instance.js create mode 100644 lib/Instance.js.map create mode 100644 lib/Middleware.js create mode 100644 lib/Middleware.js.map create mode 100644 lib/Model.js create mode 100644 lib/Model.js.map create mode 100644 lib/Plugins.js create mode 100644 lib/Plugins.js.map create mode 100644 lib/Schema.js create mode 100644 lib/Schema.js.map create mode 100644 lib/cacheControllers/IDDirector.js create mode 100644 lib/cacheControllers/IDDirector.js.map create mode 100644 lib/caches/MemoryCache.js create mode 100644 lib/caches/MemoryCache.js.map create mode 100644 lib/caches/NoOpCache.js create mode 100644 lib/caches/NoOpCache.js.map create mode 100644 lib/middleware/Express.js create mode 100644 lib/middleware/Express.js.map create mode 100644 lib/utils/Omnom.js create mode 100644 lib/utils/Omnom.js.map create mode 100644 test/Core.js create mode 100644 test/Core.js.map create mode 100644 test/Iridium.js create mode 100644 test/Iridium.js.map create mode 100644 test/Model.js create mode 100644 test/Model.js.map create mode 100644 test/support/chai.js create mode 100644 test/support/chai.js.map diff --git a/.gitignore b/.gitignore index ee0e6db..eac4c8b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,4 @@ node_modules/ *.dat .idea dist/ -*.js -*.map *.tmp \ No newline at end of file diff --git a/example/IntelliSense.js b/example/IntelliSense.js new file mode 100644 index 0000000..4a183cf --- /dev/null +++ b/example/IntelliSense.js @@ -0,0 +1,71 @@ +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Iridium = require('../index'); +var User = (function (_super) { + __extends(User, _super); + function User() { + _super.apply(this, arguments); + } + User.prototype.changePassword = function (newPassword) { + this.passwordHash = newPassword.toLowerCase(); + }; + return User; +})(Iridium.Instance); +var MyDB = (function (_super) { + __extends(MyDB, _super); + function MyDB() { + _super.apply(this, arguments); + this.Users = new Iridium.Model(this, User, "users", { + username: /^[a-z][a-z0-9_]{7,}$/, + fullname: String, + email: String, + dateOfBirth: Date, + passwordHash: String + }, { + indexes: [ + { email: 1 } + ] + }); + this.PlainUsers = new Iridium.Model(this, function (doc) { return doc; }, "users", { + username: /^[a-z][a-z0-9_]{7,}$/, + fullname: String, + email: String, + dateOfBirth: Date, + passwordHash: String + }, { + indexes: [ + { email: 1 } + ] + }); + } + return MyDB; +})(Iridium.Core); +var db = new MyDB("mongodb://localhost/test"); +db.connect().then(function () { + db.Users.insert({ fullname: 'test', username: 'test', passwordHash: 'test', email: 'test@test.com', dateOfBirth: new Date() }).then(function (user) { + user.fullname; + user.dateOfBirth.getTime(); + }); + db.Users.insert([{ fullname: 'test', username: 'test', passwordHash: 'test', email: 'test@test.com', dateOfBirth: new Date() }]).then(function (users) { + users[0].fullname; + }); + db.Users.findOne().then(function (instance) { + instance.save().then(function (i) { + i.remove().then(function (i) { + i.username = 'test'; + return i.save(); + }); + }); + }); + db.Users.count().then(function (count) { + count.toPrecision(2); + }); + db.PlainUsers.get().then(function (plainUser) { + plainUser.username; + }); +}); +//# sourceMappingURL=IntelliSense.js.map \ No newline at end of file diff --git a/example/IntelliSense.js.map b/example/IntelliSense.js.map new file mode 100644 index 0000000..7035ff0 --- /dev/null +++ b/example/IntelliSense.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IntelliSense.js","sourceRoot":"","sources":["IntelliSense.ts"],"names":["User","User.constructor","User.changePassword","MyDB","MyDB.constructor"],"mappings":";;;;;;AACA,IAAO,OAAO,WAAW,UAAU,CAAC,CAAC;AAUrC,IAAM,IAAI;IAASA,UAAbA,IAAIA,UAAwCA;IAAlDA,SAAMA,IAAIA;QAASC,8BAA+BA;IAUlDA,CAACA;IAHGD,6BAAcA,GAAdA,UAAeA,WAAmBA;QAC9BE,IAAIA,CAACA,YAAYA,GAAG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/index.js @@ -0,0 +1,45 @@ +/// +/// +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var _Core = require('./lib/Core'); +var _Model = require('./lib/Model'); +var _Instance = require('./lib/Instance'); +var Iridium; +(function (Iridium) { + var Core = (function (_super) { + __extends(Core, _super); + function Core() { + _super.apply(this, arguments); + } + return Core; + })(_Core); + Iridium.Core = Core; + ; + var Model = (function (_super) { + __extends(Model, _super); + function Model() { + _super.apply(this, arguments); + } + return Model; + })(_Model.Model); + Iridium.Model = Model; + ; + var Instance = (function (_super) { + __extends(Instance, _super); + function Instance() { + _super.apply(this, arguments); + } + return Instance; + })(_Instance); + Iridium.Instance = Instance; + ; + ; +})(Iridium || (Iridium = {})); +; +module.exports = Iridium; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..1d7adee --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":["Iridium","Iridium.Core","Iridium.Core.constructor","Iridium.Model","Iridium.Model.constructor","Iridium.Instance","Iridium.Instance.constructor"],"mappings":"AAAA,sCAAsC;AACtC,uCAAuC;;;;;;;AAEvC,IAAO,KAAK,WAAW,YAAY,CAAC,CAAC;AACrC,IAAO,MAAM,WAAW,aAAa,CAAC,CAAC;AACvC,IAAO,SAAS,WAAW,gBAAgB,CAAC,CAAC;AAK7C,IAAO,OAAO,CAKb;AALD,WAAO,OAAO,EAAC,CAAC;IACZA,IAAaA,IAAIA;QAASC,UAAbA,IAAIA,UAAcA;QAA/BA,SAAaA,IAAIA;YAASC,8BAAKA;QAAGA,CAACA;QAADD,WAACA;IAADA,CAACA,AAAnCD,EAA0BA,KAAKA,EAAIA;IAAtBA,YAAIA,GAAJA,IAAsBA,CAAAA;IAAAA,CAACA;IACpCA,IAAaA,KAAKA;QAA+BG,UAApCA,KAAKA,UAAiEA;QAAnFA,SAAaA,KAAKA;YAA+BC,8BAAkCA;QAAGA,CAACA;QAADD,YAACA;IAADA,CAACA,AAAvFH,EAAiDA,MAAMA,CAACA,KAAKA,EAA0BA;IAA1EA,aAAKA,GAALA,KAA0EA,CAAAA;IAAAA,CAACA;IACxFA,IAAaA,QAAQA;QAA+BK,UAAvCA,QAAQA,UAA8DA;QAAnFA,SAAaA,QAAQA;YAA+BC,8BAA+BA;QAAGA,CAACA;QAADD,eAACA;IAADA,CAACA,AAAvFL,EAAoDA,SAASA,EAA0BA;IAA1EA,gBAAQA,GAARA,QAA0EA,CAAAA;IAAAA,CAACA;IAC7CA,CAACA;AAChDA,CAACA,EALM,OAAO,KAAP,OAAO,QAKb;AAAA,CAAC;AAPF,iBAAS,OAAO,CAAC"} \ No newline at end of file diff --git a/lib/Cache.js b/lib/Cache.js new file mode 100644 index 0000000..3338fd7 --- /dev/null +++ b/lib/Cache.js @@ -0,0 +1 @@ +//# sourceMappingURL=Cache.js.map \ No newline at end of file diff --git a/lib/Cache.js.map b/lib/Cache.js.map new file mode 100644 index 0000000..5e13fb8 --- /dev/null +++ b/lib/Cache.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Cache.js","sourceRoot":"","sources":["Cache.ts"],"names":[],"mappings":"AASC"} \ No newline at end of file diff --git a/lib/CacheDirector.js b/lib/CacheDirector.js new file mode 100644 index 0000000..bd4b9ba --- /dev/null +++ b/lib/CacheDirector.js @@ -0,0 +1 @@ +//# sourceMappingURL=CacheDirector.js.map \ No newline at end of file diff --git a/lib/CacheDirector.js.map b/lib/CacheDirector.js.map new file mode 100644 index 0000000..37bc429 --- /dev/null +++ b/lib/CacheDirector.js.map @@ -0,0 +1 @@ +{"version":3,"file":"CacheDirector.js","sourceRoot":"","sources":["CacheDirector.ts"],"names":[],"mappings":"AAKC"} \ No newline at end of file diff --git a/lib/Configuration.js b/lib/Configuration.js new file mode 100644 index 0000000..a8ab8ef --- /dev/null +++ b/lib/Configuration.js @@ -0,0 +1 @@ +//# sourceMappingURL=Configuration.js.map \ No newline at end of file diff --git a/lib/Configuration.js.map b/lib/Configuration.js.map new file mode 100644 index 0000000..c47a3d8 --- /dev/null +++ b/lib/Configuration.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["Configuration.ts"],"names":[],"mappings":"AASC"} \ No newline at end of file diff --git a/lib/Core.js b/lib/Core.js new file mode 100644 index 0000000..b5b290b --- /dev/null +++ b/lib/Core.js @@ -0,0 +1,153 @@ +/// +/// +/// +/// +/// +/// +var Promise = require('bluebird'); +var MongoDB = require('mongodb'); +var expressMiddleware = require('./middleware/Express'); +var noOpCache = require('./caches/NoOpCache'); +var MongoConnectAsyc = Promise.promisify(MongoDB.MongoClient.connect); +var Core = (function () { + function Core(uri, config) { + this._plugins = []; + this._cache = new noOpCache(); + var args = Array.prototype.slice.call(arguments, 0); + uri = config = null; + for (var i = 0; i < args.length; i++) { + if (typeof args[i] == 'string') + uri = args[i]; + else if (typeof args[i] == 'object') + config = args[i]; + } + if (!uri && !config) + throw new Error("Expected either a URI or config object to be supplied when initializing Iridium"); + this._url = uri; + this._config = config; + } + Object.defineProperty(Core.prototype, "plugins", { + /** + * Gets the plugins registered with this Iridium Core + * @returns {[Iridium.Plugin]} + */ + get: function () { + return this._plugins; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Core.prototype, "settings", { + /** + * Gets the configuration specified in the construction of this + * Iridium Core. + * @returns {Iridium.Configuration} + */ + get: function () { + return this._config; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Core.prototype, "connection", { + /** + * Gets the currently active database connection for this Iridium + * Core. + * @returns {MongoDB.Db} + */ + get: function () { + return this._connection; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Core.prototype, "url", { + /** + * Gets the URL used to connect to MongoDB + * @returns {String} + */ + get: function () { + if (this._url) + return this._url; + var url = 'mongodb://'; + if (this._config.username) { + url += this._config.username; + if (this._config.password) + url += ':' + this._config.password; + url += '@'; + } + url += (this._config.host || 'localhost'); + if (this._config.port) + url += ':' + this._config.port; + url += '/' + this._config.database; + return url; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Core.prototype, "cache", { + /** + * Gets the cache used to store objects retrieved from the database for performance reasons + * @returns {cache} + */ + get: function () { + return this._cache; + }, + set: function (value) { + this._cache = value; + }, + enumerable: true, + configurable: true + }); + /** + * Registers a new plugin with this Iridium Core + * @param {Iridium.Plugin} plugin The plugin to register with this Iridium Core + * @returns {Iridium.Core} + */ + Core.prototype.register = function (plugin) { + this.plugins.push(plugin); + return this; + }; + /** + * Connects to the database server specified in the provided configuration + * @param {function(Error, Iridium.Core)} [callback] A callback to be triggered once the connection is established. + * @returns {Promise} + */ + Core.prototype.connect = function (callback) { + var self = this; + return Promise.bind(this).then(function () { + if (self._connection) + return self._connection; + return MongoConnectAsyc(self.url); + }).then(function (db) { + self._connection = db; + return self; + }).nodeify(callback); + }; + /** + * Closes the active database connection + * @type {Promise} + */ + Core.prototype.close = function () { + var self = this; + return Promise.bind(this).then(function () { + if (!self._connection) + return this; + var conn = self._connection; + self._connection = null; + conn.close(); + return this; + }); + }; + /** + * Provides an express middleware which can be used to set the req.db property + * to the current Iridium instance. + * @returns {Iridium.ExpressMiddleware} + */ + Core.prototype.express = function () { + return expressMiddleware.ExpressMiddlewareFactory(this); + }; + return Core; +})(); +module.exports = Core; +//# sourceMappingURL=Core.js.map \ No newline at end of file diff --git a/lib/Core.js.map b/lib/Core.js.map new file mode 100644 index 0000000..e36b211 --- /dev/null +++ b/lib/Core.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Core.js","sourceRoot":"","sources":["Core.ts"],"names":["Core","Core.constructor","Core.plugins","Core.settings","Core.connection","Core.url","Core.cache","Core.register","Core.connect","Core.close","Core.express"],"mappings":"AAAA,kDAAkD;AAClD,wDAAwD;AACxD,sDAAsD;AACtD,0DAA0D;AAC1D,gCAAgC;AAChC,mCAAmC;AAEn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CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC;QAChB,CAAC,CAACA,CAACA;IACPA,CAACA;IAEDT;;;;OAIGA;IACHA,sBAAOA,GAAPA;QACIU,MAAMA,CAACA,iBAAiBA,CAACA,wBAAwBA,CAACA,IAAIA,CAACA,CAACA;IAC5DA,CAACA;IACLV,WAACA;AAADA,CAACA,AApJD,IAoJC;AAtJD,iBAAS,IAAI,CAAC"} \ No newline at end of file diff --git a/lib/General.js b/lib/General.js new file mode 100644 index 0000000..07146e8 --- /dev/null +++ b/lib/General.js @@ -0,0 +1 @@ +//# sourceMappingURL=General.js.map \ No newline at end of file diff --git a/lib/General.js.map b/lib/General.js.map new file mode 100644 index 0000000..33baafa --- /dev/null +++ b/lib/General.js.map @@ -0,0 +1 @@ +{"version":3,"file":"General.js","sourceRoot":"","sources":["General.ts"],"names":[],"mappings":"AAmBC"} \ No newline at end of file diff --git a/lib/Hooks.js b/lib/Hooks.js new file mode 100644 index 0000000..1072b7a --- /dev/null +++ b/lib/Hooks.js @@ -0,0 +1,2 @@ +/// +//# sourceMappingURL=Hooks.js.map \ No newline at end of file diff --git a/lib/Hooks.js.map b/lib/Hooks.js.map new file mode 100644 index 0000000..c71716d --- /dev/null +++ b/lib/Hooks.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Hooks.js","sourceRoot":"","sources":["Hooks.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAUzD"} \ No newline at end of file diff --git a/lib/Instance.js b/lib/Instance.js new file mode 100644 index 0000000..5edba26 --- /dev/null +++ b/lib/Instance.js @@ -0,0 +1,213 @@ +/// +/// +/// +/// +/// +/// +var _ = require('lodash'); +var Promise = require('bluebird'); +var Instance = (function () { + /** + * Creates a new instance which represents the given document as a type of model + * @param {model.Model} model The model that the document represents + * @param {TSchema} document The document which should be wrapped by this instance + * @param {Boolean} isNew Whether the document is new (doesn't exist in the database) or not + * @param {Boolean} isPartial Whether the document has only a subset of its fields populated + * @description + * This class will be subclassed automatically by Iridium to create a model specific instance + * which takes advantage of some of v8's optimizations to boost performance significantly. + * The instance returned by the model, and all of this instance's methods, will be of type + * TInstance - which should represent the merger of TSchema and IInstance for best results. + */ + function Instance(model, document, isNew, isPartial) { + var _this = this; + if (isNew === void 0) { isNew = false; } + if (isPartial === void 0) { isPartial = false; } + this._model = model; + this._isNew = !!isNew; + this._isPartial = isPartial; + this._original = document; + this._modified = _.cloneDeep(document); + _.each(model.core.plugins, function (plugin) { + if (plugin.newInstance) + plugin.newInstance(_this, model); + }); + } + Object.defineProperty(Instance.prototype, "document", { + /** + * Gets the underlying document representation of this instance + */ + get: function () { + return this._modified; + }, + enumerable: true, + configurable: true + }); + Instance.prototype.save = function () { + var _this = this; + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + var callback = null; + var changes = null; + var conditions = {}; + Array.prototype.slice.call(args, 0).reverse().forEach(function (arg) { + if (typeof arg == 'function') + callback = arg; + else if (typeof arg == 'object') { + if (!changes) + changes = arg; + else + conditions = arg; + } + }); + return Promise.resolve().then(function () { + _.merge(conditions, _this._model.helpers.selectOneDownstream(_this._modified)); + _this._model.helpers.transform.reverse(conditions); + if (!changes) { + var validation = _this._model.helpers.validate(_this._modified); + if (validation.failed) + return Promise.reject(validation.error).bind(_this).nodeify(callback); + var original = _.cloneDeep(_this._original); + var modified = _.cloneDeep(_this._modified); + changes = _this._model.helpers.diff(original, modified); + } + }).then(function () { + return _this._model.handlers.savingDocument(_this, changes); + }).then(function () { + return new Promise(function (resolve, reject) { + this._model.collection.update(conditions, changes, { w: 1 }, function (err, changed) { + if (err) + return reject(err); + return resolve(changed); + }); + }); + }).then(function (changed) { + conditions = _this._model.helpers.selectOne(_this._modified); + if (!changed) + return _this._modified; + return new Promise(function (resolve, reject) { + _this._model.collection.findOne(conditions, function (err, latest) { + if (err) + return reject(err); + return resolve(latest); + }); + }); + }).then(function (latest) { + return _this._model.handlers.documentsReceived(conditions, [latest], function (value) { + this._model.helpers.transform.apply(value); + this._isPartial = false; + this._isNew = false; + this._original = value; + this._modified = _.clone(value); + return this; + }); + }).then(function (instances) { + return instances[0]; + }).nodeify(callback); + }; + /** + * Updates this instance to match the latest document available in the backing collection + * @param {function(Error, IInstance)} callback A callback which is triggered when the update completes + * @returns {Promise} + */ + Instance.prototype.update = function (callback) { + return this.refresh(callback); + }; + /** + * Updates this instance to match the latest document available in the backing collection + * @param {function(Error, IInstance)} callback A callback which is triggered when the update completes + * @returns {Promise} + */ + Instance.prototype.refresh = function (callback) { + var _this = this; + var conditions = this._model.helpers.selectOne(this._original); + return Promise.resolve().then(function () { + return new Promise(function (resolve, reject) { + _this._model.collection.findOne(conditions, function (err, doc) { + if (err) + return reject(err); + return resolve(doc); + }); + }); + }).then(function (doc) { + if (!doc) { + _this._isPartial = true; + _this._isNew = true; + _this._original = _.cloneDeep(_this._modified); + return _this; + } + return _this._model.handlers.documentsReceived(conditions, [doc], _this._model.helpers.transform.apply, { wrap: false }).then(function (doc) { + _this._model.helpers.transform.apply(doc); + _this._isNew = false; + _this._isPartial = false; + _this._original = doc; + _this._modified = _.cloneDeep(doc); + return _this; + }); + }).then(function (instances) { return instances[0]; }).nodeify(callback); + }; + /** + * Removes this instance's document from the backing collection + * @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes + * @returns {Promise} + */ + Instance.prototype.delete = function (callback) { + return this.remove(callback); + }; + /** + * Removes this instance's document from the backing collection + * @param {function(Error, IInstance)} callback A callback which is triggered when the operation completes + * @returns {Promise} + */ + Instance.prototype.remove = function (callback) { + var _this = this; + var conditions = this._model.helpers.selectOne(this._original); + return Promise.resolve().then(function () { + if (_this._isNew) + return 0; + return new Promise(function (resolve, reject) { + _this._model.collection.remove(conditions, function (err, removed) { + if (err) + return reject(err); + return resolve(removed); + }); + }); + }).then(function (removed) { + if (removed) + return _this._model.cache.clear(conditions); + return false; + }).then(function (removed) { + return _this; + }).nodeify(callback); + }; + Instance.prototype.first = function (collection, predicate) { + var _this = this; + var result = null; + _.each(collection, function (value, key) { + if (predicate.call(_this, value, key)) { + result = value; + return false; + } + }); + return result; + }; + Instance.prototype.select = function (collection, predicate) { + var _this = this; + var isArray = Array.isArray(collection); + var results = isArray ? [] : {}; + _.each(collection, function (value, key) { + if (predicate.call(_this, value, key)) { + if (isArray) + results.push(value); + else + results[key] = value; + } + }); + return results; + }; + return Instance; +})(); +module.exports = Instance; +//# sourceMappingURL=Instance.js.map \ No newline at end of file diff --git a/lib/Instance.js.map b/lib/Instance.js.map new file mode 100644 index 0000000..5ad9a90 --- /dev/null +++ b/lib/Instance.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Instance.js","sourceRoot":"","sources":["Instance.ts"],"names":["Instance","Instance.constructor","Instance.document","Instance.save","Instance.update","Instance.refresh","Instance.delete","Instance.remove","Instance.first","Instance.select"],"mappings":"AAAA,kDAAkD;AAClD,wDAAwD;AACxD,sDAAsD;AACtD,0DAA0D;AAC1D,gCAAgC;AAChC,iCAAiC;AAKjC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,OAAO,WAAW,UAAU,CAAC,CAAC;AAIrC,IAAM,QAAQ;IACVA;;;;;;;;;;;OAWGA;IACHA,SAbEA,QAAQA,CAaEA,KAAwCA,EAAEA,QAAmBA,EAAEA,KAAsBA,EAAEA,SAA0BA;QAbjIC,iBA8PCA;QAjP8EA,qBAAsBA,GAAtBA,aAAsBA;QAAEA,yBAA0BA,GAA1BA,iBAA0BA;QACzHA,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,CAACA,QAAQA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CAACA;gBACnCA,MAAMA,GAAGA,KAAKA,CAACA;gBACfA,MAAMA,CAACA,KAAKA,CAACA;YACjBA,CAACA;QACLA,CAACA,CAACA,CAACA;QAEHA,MAAMA,CAACA,MAAMA,CAACA;IAClBA,CAACA;IAgBDR,yBAAMA,GAANA,UAAUA,UAAqCA,EAAEA,SAA+BA;QAAhFS,iBAYCA;QAXGA,IAAIA,OAAOA,GAAGA,KAAKA,CAACA,OAAOA,CAACA,UAAUA,CAACA,CAACA;QACxCA,IAAIA,OAAOA,GAAQA,OAAOA,GAAGA,EAAEA,GAAGA,EAAEA,CAACA;QAErCA,CAACA,CAACA,IAAIA,CAACA,UAAUA,EAAEA,UAACA,KAAQA,EAAEA,GAAGA;YAC7BA,EAAEA,CAACA,CAACA,SAASA,CAACA,IAAIA,CAACA,KAAIA,EAAEA,KAAKA,EAAEA,GAAGA,CAACA,CAACA,CAACA,CAACA;gBACnCA,EAAEA,CAACA,CAACA,OAAOA,CAACA;oBAACA,OAAOA,CAACA,IAAIA,CAACA,KAAKA,CAACA,CAACA;gBACjCA,IAAIA;oBAACA,OAAOA,CAACA,GAAGA,CAACA,GAAGA,KAAKA,CAACA;YAC9BA,CAACA;QACLA,CAACA,CAACA,CAACA;QAEHA,MAAMA,CAACA,OAAOA,CAACA;IACnBA,CAACA;IACLT,eAACA;AAADA,CAACA,AA9PD,IA8PC;AAEiB,AAAlB,iBAAS,QAAQ,CAAC"} \ No newline at end of file diff --git a/lib/Middleware.js b/lib/Middleware.js new file mode 100644 index 0000000..6c69b91 --- /dev/null +++ b/lib/Middleware.js @@ -0,0 +1 @@ +//# sourceMappingURL=Middleware.js.map \ No newline at end of file diff --git a/lib/Middleware.js.map b/lib/Middleware.js.map new file mode 100644 index 0000000..029f1dd --- /dev/null +++ b/lib/Middleware.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Middleware.js","sourceRoot":"","sources":["Middleware.ts"],"names":[],"mappings":"AAKC"} \ No newline at end of file diff --git a/lib/Model.js b/lib/Model.js new file mode 100644 index 0000000..6435f3c --- /dev/null +++ b/lib/Model.js @@ -0,0 +1,624 @@ +var MongoDB = require('mongodb'); +var Skmatc = require('skmatc'); +var Concoction = require('concoction'); +var Promise = require('bluebird'); +var _ = require('lodash'); +var Iridium = require('./Core'); +var idCacheController = require('./cacheControllers/IDDirector'); +var Omnom = require('./utils/Omnom'); +/** + * An Iridium Model which represents a structured MongoDB collection + * @class + */ +var Model = (function () { + /** + * Creates a new Iridium model representing a given ISchema and backed by a collection whose name is specified + * @param {Iridium} core The Iridium core that this model should use for database access + * @param {String} collection The name of the collection within the database which should be used by this model + * @param {schema} schema The schema defining the data validations to be performed on the model + * @param {IModelOptions} options The options dictating the behaviour of the model + * @returns {Model} + * @constructor + */ + function Model(core, instanceType, collection, schema, options) { + if (options === void 0) { options = {}; } + // Allow instantiation doing `require('iridium').Model(db, 'collection', {})` + if (!(this instanceof Model)) + return new Model(core, instanceType, collection, schema, options); + if (!(core instanceof Iridium)) + throw new Error("You failed to provide a valid Iridium core for this model"); + if (typeof instanceType != 'function') + throw new Error("You failed to provide a valid instance constructor for this model"); + if (typeof collection != 'string' || !collection) + throw new Error("You failed to provide a valid collection name for this model"); + if (!_.isPlainObject(schema) || !_.keys(schema).length) + throw new Error("You failed to provide a valid schema for this model"); + options = options || {}; + _.defaults(options, { + hooks: {}, + transforms: [ + new Concoction.Rename({ _id: 'id' }), + new Concoction.Convert({ + id: { + apply: function (value) { + return (value && value.id) ? new MongoDB.ObjectID(value.id).toHexString() : value; + }, + reverse: function (value) { + if (value === null || value === undefined) + return undefined; + if (value && /^[a-f0-9]{24}$/.test(value)) + return MongoDB.ObjectID.createFromHexString(value); + return value; + } + } + }) + ], + cache: new idCacheController() + }); + this._core = core; + this._collection = collection; + this._schema = schema; + this._options = options; + core.plugins.forEach(function (plugin) { + if (plugin.newModel) + plugin.newModel(this); + }); + this._cache = new ModelCache(this); + this._Instance = new ModelSpecificInstance(this, instanceType); + this._helpers = new ModelHelpers(this); + this._handlers = new ModelHandlers(this); + } + Object.defineProperty(Model.prototype, "options", { + /** + * Gets the options provided when instantiating this model + * @public + * @returns {IModelOptions} + * @description + * This is intended to be consumed by plugins which require any configuration + * options. Changes made to this object after the {plugin.newModel} hook are + * called will not have any effect on this model. + */ + get: function () { + return this._options; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Model.prototype, "helpers", { + /** + * Provides helper methods used by Iridium for common tasks + * @returns {ModelHelpers} + */ + get: function () { + return this._helpers; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Model.prototype, "handlers", { + /** + * Provides helper methods used by Iridium for hook delegation and common processes + * @returns {ModelHandlers} + */ + get: function () { + return this._handlers; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Model.prototype, "schema", { + /** + * Gets the ISchema dictating the data structure represented by this model + * @public + * @returns {schema} + */ + get: function () { + return this._schema; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Model.prototype, "core", { + /** + * Gets the Iridium core that this model is associated with + * @public + * @returns {Iridium} + */ + get: function () { + return this._core; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Model.prototype, "collection", { + /** + * Gets the underlying MongoDB collection from which this model's documents are retrieved + * @public + * @returns {Collection} + */ + get: function () { + return this.core.connection.collection(this._collection); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Model.prototype, "collectionName", { + /** + * Gets the name of the underlying MongoDB collection from which this model's documents are retrieved + * @public + */ + get: function () { + return this._collection; + }, + /** + * Sets the name of the underlying MongoDB collection from which this model's documents are retrieved + * @public + */ + set: function (value) { + this._collection = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Model.prototype, "cacheDirector", { + /** + * Gets the cache controller which dictates which queries will be cached, and under which key + * @public + * @returns {CacheDirector} + */ + get: function () { + return this._cacheDirector; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Model.prototype, "cache", { + /** + * Gets the cache responsible for storing objects for quick retrieval under certain conditions + * @public + * @returns {ModelCache} + */ + get: function () { + return this._cache; + }, + enumerable: true, + configurable: true + }); + /** + * Wraps the given document using the instance constructor provided for this model + * @public + * @param {TDocument} document The document to wrap in an instance object + * @param {Boolean} isNew Whether the document is present in the database or not + * @param {Boolean} isPartial Whether the document contains all properties defined in the database + * @returns {function(Object): Instance} + * @constructor + */ + Model.prototype.wrap = function (document, isNew, isPartial) { + if (isNew === void 0) { isNew = true; } + if (isPartial === void 0) { isPartial = false; } + return this._Instance.build(document, isNew, isPartial); + }; + Model.prototype.find = function (conditions, options, callback) { + var _this = this; + if (typeof options == 'function') { + callback = options; + options = {}; + } + if (typeof conditions == 'function') { + callback = conditions; + conditions = {}; + options = {}; + } + conditions = conditions || {}; + options = options || {}; + _.defaults(options, {}); + return Promise.resolve().then(function () { + if (options.fields) + _this.helpers.transform.reverse(options.fields); + if (!_.isPlainObject(conditions)) + conditions = _this.helpers.selectOneDownstream(conditions); + _this.helpers.transform.reverse(conditions); + var cursor = _this.collection.find(conditions, { + limit: options.limit, + sort: options.sort, + skip: options.skip, + fields: options.fields + }); + return Promise.promisify(function (callback) { + cursor.toArray(callback); + })(); + }).then(function (results) { + if (!results || !results.length) + return Promise.resolve([]); + return _this.handlers.documentsReceived(conditions, results, _this.helpers.wrapDocument, options); + }).nodeify(callback); + }; + Model.prototype.get = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + return this.get.apply(this, args); + }; + Model.prototype.findOne = function () { + var _this = this; + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + var conditions = null; + var options = null; + var callback = null; + for (var argI = 0; argI < args.length; argI++) { + if (typeof args[argI] == 'function') + callback = callback || args[argI]; + else if (_.isPlainObject(args[argI])) { + if (conditions) + options = args[argI]; + else + conditions = args[argI]; + } + else + conditions = this.helpers.selectOneDownstream(args[argI]); + } + _.defaults(options, { + wrap: true, + cache: true + }); + return Promise.resolve().bind(this).then(function () { + _this.helpers.transform.reverse(conditions); + if (options.fields) + _this.helpers.transform.reverse(options.fields); + return _this.cache.get(conditions); + }).then(function (cachedDocument) { + if (cachedDocument) + return cachedDocument; + return null; + }).then(function (document) { + if (!document) + return null; + return _this.handlers.documentsReceived(conditions, [document], _this.helpers.wrapDocument, options).then(function (documents) { + return documents[0]; + }); + }).nodeify(callback); + }; + Model.prototype.create = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + return this.insert.apply(this, args); + }; + Model.prototype.insert = function (objs) { + var _this = this; + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + var objects; + var options = {}; + var callback = null; + if (typeof args[0] == 'function') + callback = args[0]; + else { + options = args[0]; + callback = args[1]; + } + var returnArray = false; + if (Array.isArray(objs)) + objects = objs; + else + objects = [objs]; + options = options || {}; + _.defaults(options, { + w: 1 + }); + return Promise.resolve().then(function () { + var queryOptions = { w: options.w, upsert: options.upsert, new: true }; + if (options.upsert) + return _this.handlers.creatingDocuments(objects).map(function (object) { + return new Promise(function (resolve, reject) { + _this.collection.findAndModify({ _id: object._id }, ["_id"], object, queryOptions, function (err, result) { + if (err) + return reject(err); + return resolve(result); + }); + }); + }); + else + return _this.handlers.creatingDocuments(objects).then(function (objects) { + return new Promise(function (resolve, reject) { + _this.collection.insert(objects, queryOptions, function (err, results) { + if (err) + return reject(err); + return resolve(results); + }); + }); + }); + }).then(function (inserted) { + return _this.handlers.documentsReceived(null, inserted, function (document, isNew, isPartial) { return _this.helpers.wrapDocument(document, isNew, isPartial); }, { cache: options.cache }); + }).then(function (results) { + if (Array.isArray(objs)) + return results; + return results[0]; + }).nodeify(callback); + }; + Model.prototype.update = function (conditions, changes, options, callback) { + var _this = this; + if (typeof options == 'function') { + callback = options; + options = {}; + } + _.defaults(options, { + w: 1, + multi: true + }); + this.helpers.transform.reverse(conditions); + return new Promise(function (resolve, reject) { + _this.collection.update(conditions, changes, options, function (err, changes) { + if (err) + return reject(err); + return resolve(changes); + }); + }).nodeify(callback); + }; + Model.prototype.count = function (conditions, callback) { + if (typeof conditions == 'function') { + callback = conditions; + conditions = {}; + } + var $this = this; + return new Promise(function (resolve, reject) { + $this.collection.count(conditions, function (err, results) { + if (err) + return reject(err); + return resolve(results); + }); + }).nodeify(callback); + }; + Model.prototype.remove = function (conditions, callback) { + var _this = this; + if (typeof conditions == 'function') { + callback = conditions; + conditions = {}; + } + return new Promise(function (resolve, reject) { + _this.collection.remove(conditions, function (err, results) { + if (err) + return reject(err); + return resolve(results); + }); + }).then(function (count) { + return _this.cache.clear(conditions).then(function () { return count; }); + }).nodeify(callback); + }; + Model.prototype.ensureIndex = function (specification, options, callback) { + var _this = this; + if (typeof options == 'function') { + callback = options; + options = {}; + } + return new Promise(function (resolve, reject) { + _this.collection.ensureIndex(specification, options, function (err, name) { + if (err) + return reject(err); + return resolve(name); + }); + }).nodeify(callback); + }; + Model.prototype.ensureIndices = function (callback) { + var _this = this; + return Promise.resolve(this.options.indices).map(function (index) { + return _this.ensureIndex(index.spec || index, index.options || {}); + }).nodeify(callback); + }; + return Model; +})(); +exports.Model = Model; +var ModelSpecificInstance = (function () { + function ModelSpecificInstance(model, instanceConstructor) { + var _this = this; + this.Constructor = function (document, isNew, isPartial) { + instanceConstructor.call(this, model, document, isNew, isPartial); + }; + _.each(model.schema, function (property, key) { + Object.defineProperty(_this.Constructor.prototype, key, { + get: function () { + return this._modified[key]; + }, + set: function (value) { + this._modified[key] = value; + }, + enumerable: true + }); + }); + } + ModelSpecificInstance.prototype.build = function (document, isNew, isPartial) { + return new this.Constructor(document, isNew, isPartial); + }; + return ModelSpecificInstance; +})(); +exports.ModelSpecificInstance = ModelSpecificInstance; +var ModelHelpers = (function () { + function ModelHelpers(model) { + this._model = model; + this._validator = new Skmatc(model.schema); + this._transform = new Concoction(model.options.transforms); + } + Object.defineProperty(ModelHelpers.prototype, "transform", { + /** + * Gets the Concoction transforms defined for this model + * @returns {Concoction} + */ + get: function () { + return this._transform; + }, + enumerable: true, + configurable: true + }); + /** + * Validates a document to ensure that it matches the model's ISchema requirements + * @param {any} document The document to validate against the ISchema + * @returns {SkmatcCore.IResult} The result of the validation + */ + ModelHelpers.prototype.validate = function (document) { + return this._validator.validate(document); + }; + /** + * Creates a selector based on the document's unique _id field + * @param {object} document The document to render the unique selector for + * @returns {{_id: any}} A database selector which can be used to return only this document + */ + ModelHelpers.prototype.selectOne = function (document) { + var testDoc = _.cloneDeep(document); + this.transform.reverse(testDoc); + return { + _id: testDoc._id + }; + }; + Object.defineProperty(ModelHelpers.prototype, "identifierField", { + /** + * Gets the field used in the ISchema to represent the document _id + */ + get: function () { + var id = new String(""); + var testDoc = { + _id: id + }; + this.transform.apply(testDoc); + var idField = null; + for (var k in testDoc) + if (testDoc[k] === id) { + idField = k; + break; + } + return idField; + }, + enumerable: true, + configurable: true + }); + /** + * Creates a selector based on the document's unique _id field in downstream format + * @param {any} id The downstream identifier to use when creating the selector + * @returns {object} A database selector which can be used to return only this document in downstream form + */ + ModelHelpers.prototype.selectOneDownstream = function (id) { + var conditions = {}; + conditions[this.identifierField] = id; + return conditions; + }; + /** + * Wraps the given document in an instance wrapper for use throughout the application + * @param {any} document The document to be wrapped as an instance + * @param {Boolean} isNew Whether the instance originated from the database or was created by the application + * @param {Boolean} isPartial Whether the document supplied contains all information present in the database + * @returns {any} An instance which wraps this document + */ + ModelHelpers.prototype.wrapDocument = function (document, isNew, isPartial) { + return this._model.wrap(document, isNew, isPartial); + }; + /** + * Performs a diff operation between two documents and creates a MongoDB changes object to represent the differences + * @param {any} original The original document prior to changes being made + * @param {any} modified The document after changes were made + */ + ModelHelpers.prototype.diff = function (original, modified) { + var omnom = new Omnom(); + omnom.diff(original, modified); + return omnom.changes; + }; + return ModelHelpers; +})(); +exports.ModelHelpers = ModelHelpers; +var ModelHandlers = (function () { + function ModelHandlers(model) { + this._model = model; + } + Object.defineProperty(ModelHandlers.prototype, "model", { + get: function () { + return this._model; + }, + enumerable: true, + configurable: true + }); + ModelHandlers.prototype.documentsReceived = function (conditions, results, wrapper, options) { + var _this = this; + if (options === void 0) { options = {}; } + _.defaults(options, { + cache: true, + partial: false + }); + return Promise.resolve(results).map(function (target) { + return Promise.resolve().then(function () { + // Trigger the received hook + if (_this.model.options.hooks.retrieved) + return _this.model.options.hooks.retrieved(target); + }).then(function () { + // Cache the document if caching is enabled + if (_this.model.core.cache && options.cache && !options.fields) { + var cacheDoc = _.cloneDeep(target); + return _this.model.cache.set(conditions, cacheDoc); + } + }).then(function () { + // Wrap the document and trigger the ready hook + var wrapped = wrapper(target, false, !!options.fields); + if (_this.model.options.hooks.ready) + return Promise.resolve(_this.model.options.hooks.ready(wrapped)).then(function () { return wrapped; }); + return wrapped; + }); + }); + }; + ModelHandlers.prototype.creatingDocuments = function (documents) { + var _this = this; + return Promise.all(documents.map(function (document) { + return Promise.resolve().then(function () { + if (_this.model.options.hooks.retrieved) + return _this.model.options.hooks.creating(document); + }).then(function () { + var validation = _this.model.helpers.validate(document); + if (validation.failed) + return Promise.reject(validation.error); + _this.model.helpers.transform.reverse(document); + return document; + }); + })); + }; + ModelHandlers.prototype.savingDocument = function (instance, changes) { + var _this = this; + return Promise.resolve().then(function () { + if (_this.model.options.hooks.saving) + return _this.model.options.hooks.saving(instance, changes); + }).then(function () { return instance; }); + }; + return ModelHandlers; +})(); +exports.ModelHandlers = ModelHandlers; +var ModelCache = (function () { + function ModelCache(model) { + this._model = model; + } + Object.defineProperty(ModelCache.prototype, "model", { + get: function () { + return this._model; + }, + enumerable: true, + configurable: true + }); + ModelCache.prototype.set = function (conditions, value) { + if (!this.model.cacheDirector || !this.model.cacheDirector.valid(conditions)) + return Promise.resolve(value); + return this.model.core.cache.set(this.model.cacheDirector.buildKey(conditions), value); + }; + ModelCache.prototype.get = function (conditions) { + if (!this.model.cacheDirector || !this.model.cacheDirector.valid(conditions)) + return Promise.resolve(null); + return this.model.core.cache.get(this.model.cacheDirector.buildKey(conditions)); + }; + ModelCache.prototype.clear = function (conditions) { + if (!this.model.cacheDirector || !this.model.cacheDirector.valid(conditions)) + return Promise.resolve(false); + return this.model.core.cache.clear(this.model.cacheDirector.buildKey(conditions)); + }; + return ModelCache; +})(); +//# sourceMappingURL=Model.js.map \ No newline at end of file diff --git a/lib/Model.js.map b/lib/Model.js.map new file mode 100644 index 0000000..0ea4dc5 --- /dev/null +++ b/lib/Model.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Model.js","sourceRoot":"","sources":["Model.ts"],"names":["Model","Model.constructor","Model.options","Model.helpers","Model.handlers","Model.schema","Model.core","Model.collection","Model.collectionName","Model.cacheDirector","Model.cache","Model.wrap","Model.find","Model.get","Model.findOne","Model.create","Model.insert","Model.update","Model.count","Model.remove","Model.ensureIndex","Model.ensureIndices","ModelSpecificInstance","ModelSpecificInstance.constructor","ModelSpecificInstance.build","ModelHelpers","ModelHelpers.constructor","ModelHelpers.transform","ModelHelpers.validate","ModelHelpers.selectOne","ModelHelpers.identifierField","ModelHelpers.selectOneDownstream","ModelHelpers.wrapDocument","ModelHelpers.diff","ModelHandlers","ModelHandlers.constructor","ModelHandlers.model","ModelHandlers.documentsReceived","ModelHandlers.creatingDocuments","ModelHandlers.savingDocument","ModelCache","ModelCache.constructor","ModelCache.model","ModelCache.set","ModelCache.get","ModelCache.clear"],"mappings":"AAAA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,MAAM,WAAW,QAAQ,CAAC,CAAC;AAClC,IAAO,UAAU,WAAW,YAAY,CAAC,CAAC;AAC1C,IAAO,OAAO,WAAW,UAAU,CAAC,CAAC;AAErC,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAE7B,IAAO,OAAO,WAAW,QAAQ,CAAC,CAAC;AAWnC,IAAO,iBAAiB,WAAW,+BAA+B,CAAC,CAAC;AAEpE,IAAO,KAAK,WAAW,eAAe,CAAC,CAAC;AAMxC,AAJA;;;GAGG;IACU,KAAK;IACdA;;;;;;;;OAQGA;IACHA,SAVSA,KAAK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,CAACA,KAAKA,CAACA,UAAUA,CAACA,CAACA;YAACA,MAAMA,CAACA,OAAOA,CAACA,OAAOA,CAAIA,IAAIA,CAACA,CAACA;QAC9GA,MAAMA,CAACA,IAAIA,CAACA,KAAKA,CAACA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAAIA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,QAAQA,CAACA,UAAUA,CAACA,CAACA,CAACA;IACvFA,CAACA;IAEDJ,0BAAKA,GAALA,UAAMA,UAAeA;QACjBK,EAAEA,CAACA,CAACA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,IAAIA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,KAAKA,CAACA,UAAUA,CAACA,CAACA;YAACA,MAAMA,CAACA,OAAOA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA;QAC5GA,MAAMA,CAACA,IAAIA,CAACA,KAAKA,CAACA,IAAIA,CAACA,KAAKA,CAACA,KAAKA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,QAAQA,CAACA,UAAUA,CAACA,CAACA,CAACA;IACtFA,CAACA;IACLL,iBAACA;AAADA,CAACA,AAxBD,IAwBC"} \ No newline at end of file diff --git a/lib/Plugins.js b/lib/Plugins.js new file mode 100644 index 0000000..03826e6 --- /dev/null +++ b/lib/Plugins.js @@ -0,0 +1,2 @@ +/// +//# sourceMappingURL=Plugins.js.map \ No newline at end of file diff --git a/lib/Plugins.js.map b/lib/Plugins.js.map new file mode 100644 index 0000000..bf4e9fc --- /dev/null +++ b/lib/Plugins.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Plugins.js","sourceRoot":"","sources":["Plugins.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAYrD"} \ No newline at end of file diff --git a/lib/Schema.js b/lib/Schema.js new file mode 100644 index 0000000..4df92c0 --- /dev/null +++ b/lib/Schema.js @@ -0,0 +1 @@ +//# sourceMappingURL=Schema.js.map \ No newline at end of file diff --git a/lib/Schema.js.map b/lib/Schema.js.map new file mode 100644 index 0000000..eb24a90 --- /dev/null +++ b/lib/Schema.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Schema.js","sourceRoot":"","sources":["Schema.ts"],"names":[],"mappings":"AAIC"} \ No newline at end of file diff --git a/lib/cacheControllers/IDDirector.js b/lib/cacheControllers/IDDirector.js new file mode 100644 index 0000000..52cc05a --- /dev/null +++ b/lib/cacheControllers/IDDirector.js @@ -0,0 +1,13 @@ +var IDCacheDirector = (function () { + function IDCacheDirector() { + } + IDCacheDirector.prototype.valid = function (object) { + return object._id; + }; + IDCacheDirector.prototype.buildKey = function (object) { + return JSON.stringify(object._id); + }; + return IDCacheDirector; +})(); +module.exports = IDCacheDirector; +//# sourceMappingURL=IDDirector.js.map \ No newline at end of file diff --git a/lib/cacheControllers/IDDirector.js.map b/lib/cacheControllers/IDDirector.js.map new file mode 100644 index 0000000..ad8830d --- /dev/null +++ b/lib/cacheControllers/IDDirector.js.map @@ -0,0 +1 @@ +{"version":3,"file":"IDDirector.js","sourceRoot":"","sources":["IDDirector.ts"],"names":["IDCacheDirector","IDCacheDirector.constructor","IDCacheDirector.valid","IDCacheDirector.buildKey"],"mappings":"AAIA,IAAM,eAAe;IAArBA,SAAMA,eAAeA;IAQrBC,CAACA;IAPGD,+BAAKA,GAALA,UAAMA,MAAoBA;QACtBE,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA;IACtBA,CAACA;IAEDF,kCAAQA,GAARA,UAASA,MAAoBA;QACzBG,MAAMA,CAACA,IAAIA,CAACA,SAASA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;IACtCA,CAACA;IACLH,sBAACA;AAADA,CAACA,AARD,IAQC;AAVD,iBAAS,eAAe,CAAC"} \ No newline at end of file diff --git a/lib/caches/MemoryCache.js b/lib/caches/MemoryCache.js new file mode 100644 index 0000000..e26ccc7 --- /dev/null +++ b/lib/caches/MemoryCache.js @@ -0,0 +1,23 @@ +/// +var Promise = require('bluebird'); +var MemoryCache = (function () { + function MemoryCache() { + this.cache = {}; + } + MemoryCache.prototype.set = function (key, value) { + this.cache[key] = value; + return Promise.resolve(value); + }; + MemoryCache.prototype.get = function (key) { + return Promise.resolve(this.cache[key]); + }; + MemoryCache.prototype.clear = function (key) { + var has = this.cache.hasOwnProperty(key); + if (has) + delete this.cache[key]; + return Promise.resolve(has); + }; + return MemoryCache; +})(); +module.exports = MemoryCache; +//# sourceMappingURL=MemoryCache.js.map \ No newline at end of file diff --git a/lib/caches/MemoryCache.js.map b/lib/caches/MemoryCache.js.map new file mode 100644 index 0000000..a51be5b --- /dev/null +++ b/lib/caches/MemoryCache.js.map @@ -0,0 +1 @@ +{"version":3,"file":"MemoryCache.js","sourceRoot":"","sources":["MemoryCache.ts"],"names":["MemoryCache","MemoryCache.constructor","MemoryCache.set","MemoryCache.get","MemoryCache.clear"],"mappings":"AACA,AADA,6DAA6D;AAC7D,IAAO,OAAO,WAAW,UAAU,CAAC,CAAC;AAKrC,IAAM,WAAW;IAAjBA,SAAMA,WAAWA;QACLC,UAAKA,GAAQA,EAAEA,CAACA;IAgB5BA,CAACA;IAdGD,yBAAGA,GAAHA,UAAOA,GAAWA,EAAEA,KAAQA;QACxBE,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAACA,GAAGA,KAAKA,CAACA;QACxBA,MAAMA,CAACA,OAAOA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA;IAClCA,CAACA;IAEDF,yBAAGA,GAAHA,UAAOA,GAAWA;QACdG,MAAMA,CAACA,OAAOA,CAACA,OAAOA,CAACA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAACA,CAACA,CAACA;IAC5CA,CAACA;IAEDH,2BAAKA,GAALA,UAAMA,GAAWA;QACbI,IAAIA,GAAGA,GAAGA,IAAIA,CAACA,KAAKA,CAACA,cAAcA,CAACA,GAAGA,CAACA,CAACA;QACzCA,EAAEA,CAAAA,CAACA,GAAGA,CAACA;YAACA,OAAOA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAACA,CAACA;QAC/BA,MAAMA,CAACA,OAAOA,CAACA,OAAOA,CAACA,GAAGA,CAACA,CAACA;IAChCA,CAACA;IACLJ,kBAACA;AAADA,CAACA,AAjBD,IAiBC;AAnBD,iBAAS,WAAW,CAAC"} \ No newline at end of file diff --git a/lib/caches/NoOpCache.js b/lib/caches/NoOpCache.js new file mode 100644 index 0000000..f432db6 --- /dev/null +++ b/lib/caches/NoOpCache.js @@ -0,0 +1,17 @@ +var Promise = require('bluebird'); +var NoOpCache = (function () { + function NoOpCache() { + } + NoOpCache.prototype.set = function (key, object) { + return Promise.resolve(object); + }; + NoOpCache.prototype.get = function (key) { + return Promise.resolve(); + }; + NoOpCache.prototype.clear = function (key) { + return Promise.resolve(false); + }; + return NoOpCache; +})(); +module.exports = NoOpCache; +//# sourceMappingURL=NoOpCache.js.map \ No newline at end of file diff --git a/lib/caches/NoOpCache.js.map b/lib/caches/NoOpCache.js.map new file mode 100644 index 0000000..0ee472b --- /dev/null +++ b/lib/caches/NoOpCache.js.map @@ -0,0 +1 @@ +{"version":3,"file":"NoOpCache.js","sourceRoot":"","sources":["NoOpCache.ts"],"names":["NoOpCache","NoOpCache.constructor","NoOpCache.set","NoOpCache.get","NoOpCache.clear"],"mappings":"AAEA,IAAO,OAAO,WAAW,UAAU,CAAC,CAAC;AAIrC,IAAM,SAAS;IAAfA,SAAMA,SAASA;IAYfC,CAACA;IAXGD,uBAAGA,GAAHA,UAAOA,GAAWA,EAAEA,MAASA;QACzBE,MAAMA,CAACA,OAAOA,CAACA,OAAOA,CAACA,MAAMA,CAACA,CAACA;IACnCA,CAACA;IAEDF,uBAAGA,GAAHA,UAAOA,GAAWA;QACdG,MAAMA,CAACA,OAAOA,CAACA,OAAOA,EAAEA,CAACA;IAC7BA,CAACA;IAEDH,yBAAKA,GAALA,UAAMA,GAAWA;QACbI,MAAMA,CAACA,OAAOA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA;IAClCA,CAACA;IACLJ,gBAACA;AAADA,CAACA,AAZD,IAYC;AAdD,iBAAS,SAAS,CAAC"} \ No newline at end of file diff --git a/lib/middleware/Express.js b/lib/middleware/Express.js new file mode 100644 index 0000000..edf57a5 --- /dev/null +++ b/lib/middleware/Express.js @@ -0,0 +1,14 @@ +function ExpressMiddlewareFactory(core) { + return function (req, res, next) { + core.connect().then(function () { + Object.defineProperty(req, 'db', { + get: function () { + return core; + } + }); + next(); + }).catch(next); + }; +} +exports.ExpressMiddlewareFactory = ExpressMiddlewareFactory; +//# sourceMappingURL=Express.js.map \ No newline at end of file diff --git a/lib/middleware/Express.js.map b/lib/middleware/Express.js.map new file mode 100644 index 0000000..50f6823 --- /dev/null +++ b/lib/middleware/Express.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Express.js","sourceRoot":"","sources":["Express.ts"],"names":["ExpressMiddlewareFactory"],"mappings":"AAIA,SAAgB,wBAAwB,CAAC,IAAU;IAC/CA,MAAMA,CAACA,UAAUA,GAAuBA,EAAEA,GAAwBA,EAAEA,IAA0CA;QAC1G,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;YAChB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE;gBAC7B,GAAG,EAAE;oBAAa,MAAM,CAAC,IAAI,CAAC;gBAAC,CAAC;aACnC,CAAC,CAAC;YACH,IAAI,EAAE,CAAC;QACX,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,CAACA;AACNA,CAACA;AATe,gCAAwB,GAAxB,wBASf,CAAA;AAIA"} \ No newline at end of file diff --git a/lib/utils/Omnom.js b/lib/utils/Omnom.js new file mode 100644 index 0000000..3f39a13 --- /dev/null +++ b/lib/utils/Omnom.js @@ -0,0 +1,149 @@ +/// +/// +/// +var _ = require('lodash'); +var MongoDB = require('mongodb'); +var Omnom = (function () { + function Omnom(options) { + if (options === void 0) { options = {}; } + this.options = options; + this._changes = {}; + } + Object.defineProperty(Omnom.prototype, "changes", { + get: function () { + return this._changes; + }, + enumerable: true, + configurable: true + }); + Omnom.prototype.diff = function (original, modified) { + this.onObject(original, modified); + }; + Omnom.prototype.onObject = function (original, modified, changePath) { + if (original === undefined || original === null) + return (original !== modified) && this.set(changePath, modified); + if (typeof original == 'number' && typeof modified == 'number' && original !== modified) { + if (this.options.atomicNumbers) + return this.inc(changePath, modified - original); + return this.set(changePath, modified); + } + if (Array.isArray(original) && Array.isArray(modified)) + return this.onArray(original, modified, changePath); + if (original instanceof MongoDB.ObjectID && modified instanceof MongoDB.ObjectID) + return !original.equals(modified) && this.set(changePath, modified); + if (!_.isPlainObject(original) || !_.isPlainObject(modified)) + return !_.isEqual(original, modified) && this.set(changePath, modified); + _.each(modified, function (value, key) { + // Handle array diffs in their own special way + if (Array.isArray(value) && Array.isArray(original[key])) + this.onArray(original[key], value, this.resolve(changePath, key)); + else + this.onObject(original[key], value, this.resolve(changePath, key)); + }, this); + // Unset removed properties + _.each(original, function (value, key) { + if (modified[key] === undefined || modified[key] === null) + return this.unset(this.resolve(changePath, key)); + }, this); + }; + Omnom.prototype.onArray = function (original, modified, changePath) { + var i, j; + // Check if we can get from original => modified using just pulls + if (original.length > modified.length) { + var pulls = []; + for (i = 0, j = 0; i < original.length && j < modified.length; i++) { + if (this.almostEqual(original[i], modified[j])) + j++; + else + pulls.push(original[i]); + } + for (; i < original.length; i++) + pulls.push(original[i]); + if (j === modified.length) { + if (pulls.length === 1) + return this.pull(changePath, pulls[0]); + // We can complete using just pulls + return this.pullAll(changePath, pulls); + } + else + return this.set(changePath, modified); + } + }; + Omnom.prototype.set = function (path, value) { + if (!this.changes.$set) + this.changes.$set = {}; + this.changes.$set[path] = value; + }; + Omnom.prototype.unset = function (path, value) { + if (!this.changes.$unset) + this.changes.$unset = {}; + this.changes.$unset[path] = value; + }; + Omnom.prototype.inc = function (path, value) { + if (!this.changes.$inc) + this.changes.$inc = {}; + this.changes.$inc[path] = value; + }; + Omnom.prototype.push = function (path, value) { + if (!this.changes.$push) + this.changes.$push = {}; + if (this.changes.$push[path]) { + if (this.changes.$push[path].$each) + this.changes.$push[path].$each.push(value); + else + this.changes.$push[path] = { $each: [this.changes.$push[path], value] }; + } + else + this.changes.$push[path] = value; + }; + Omnom.prototype.pull = function (path, value) { + if (!this.changes.$pull) + this.changes.$pull = {}; + if (this.changes.$pullAll && this.changes.$pullAll[path]) { + return this.changes.$pullAll[path].push(value); + } + if (this.changes.$pull[path]) { + this.pullAll(path, [this.changes.$pull[path], value]); + delete this.changes.$pull[path]; + return; + } + this.changes.$pull[path] = value; + }; + Omnom.prototype.pullAll = function (path, values) { + if (!this.changes.$pullAll) + this.changes.$pullAll = {}; + this.changes.$pullAll[path] = values; + }; + Omnom.prototype.resolve = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + var validArguments = []; + args.forEach(function (arg) { + if (arg) + validArguments.push(arg); + }); + return validArguments.join('.'); + }; + Omnom.prototype.almostEqual = function (o1, o2) { + if (!_.isPlainObject(o1) || !_.isPlainObject(o2)) + return o1 == o2 ? 1 : 0; + var o1i, o1k = Object.keys(o1); + var o2i, o2k = Object.keys(o2); + var commonKeys = []; + for (o1i = 0; o1i < o1k.length; o1i++) + if (~o2k.indexOf(o1k[o1i])) + commonKeys.push(o1k[o1i]); + var totalKeys = o1k.length + o2k.length - commonKeys.length; + var keysDifference = totalKeys - commonKeys.length; + var requiredChanges = 0; + for (var i = 0; i < commonKeys.length; i++) + if (this.almostEqual(o1[commonKeys[i]], o2[commonKeys[i]]) < 1) + requiredChanges++; + return 1 - (keysDifference / totalKeys) - (requiredChanges / commonKeys.length); + }; + return Omnom; +})(); +module.exports = Omnom; +//# sourceMappingURL=Omnom.js.map \ No newline at end of file diff --git a/lib/utils/Omnom.js.map b/lib/utils/Omnom.js.map new file mode 100644 index 0000000..4ed23f0 --- /dev/null +++ b/lib/utils/Omnom.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Omnom.js","sourceRoot":"","sources":["Omnom.ts"],"names":["Omnom","Omnom.constructor","Omnom.changes","Omnom.diff","Omnom.onObject","Omnom.onArray","Omnom.set","Omnom.unset","Omnom.inc","Omnom.push","Omnom.pull","Omnom.pullAll","Omnom.resolve","Omnom.almostEqual"],"mappings":"AAAA,qDAAqD;AACrD,2DAA2D;AAC3D,yDAAyD;AAEzD,IAAO,CAAC,WAAW,QAAQ,CAAC,CAAC;AAC7B,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAIpC,IAAM,KAAK;IACPA,SADEA,KAAKA,CACYA,OAEbA;QAFMC,uBAENA,GAFMA,YAENA;QAFaA,YAAOA,GAAPA,OAAOA,CAEpBA;QACFA,IAAIA,CAACA,QAAQA,GAAGA,EAAEA,CAACA;IACvBA,CAACA;IAUDD,sBAAIA,0BAAOA;aAAXA;YAQIE,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;;;OAAAF;IAMDA,oBAAIA,GAAJA,UAAKA,QAAaA,EAAEA,QAAaA;QAC7BG,IAAIA,CAACA,QAAQA,CAACA,QAAQA,EAAEA,QAAQA,CAACA,CAACA;IACtCA,CAACA;IAOOH,wBAAQA,GAAhBA,UAAiBA,QAAaA,EAAEA,QAAaA,EAAEA,UAAmBA;QAC9DI,EAAEA,CAAAA,CAACA,QAAQA,KAAKA,SAASA,IAAIA,QAAQA,KAAKA,IAAIA,CAACA;YAC3CA,MAAMA,CAACA,CAACA,QAAQA,KAAKA,QAAQA,CAACA,IAAIA,IAAIA,CAACA,GAAGA,CAACA,UAAUA,EAAEA,QAAQA,CAACA,CAACA;QAErEA,EAAEA,CAAAA,CAACA,OAAOA,QAAQA,IAAIA,QAAQA,IAAIA,OAAOA,QAAQA,IAAIA,QAAQA,IAAIA,QAAQA,KAAKA,QAAQA,CAACA,CAACA,CAACA;YACrFA,EAAEA,CAAAA,CAACA,IAAIA,CAACA,OAAOA,CAACA,aAAaA,CAACA;gBA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;QACxBA,GAAGA,CAAAA,CAACA,GAAGA,CAACA,CAACA,GAAGA,CAACA,EAAEA,CAACA,GAAGA,UAAUA,CAACA,MAAMA,EAAEA,CAACA,EAAEA;YACrCA,EAAEA,CAAAA,CAACA,IAAIA,CAACA,WAAWA,CAACA,EAAEA,CAACA,UAAUA,CAACA,CAACA,CAACA,CAACA,EAAEA,EAAEA,CAACA,UAAUA,CAACA,CAACA,CAACA,CAACA,CAACA,GAAGA,CAACA,CAACA;gBAACA,eAAeA,EAAEA,CAACA;QAErFA,MAAMA,CAACA,CAACA,GAAGA,CAACA,cAAcA,GAAGA,SAASA,CAACA,GAAGA,CAACA,eAAeA,GAAGA,UAAUA,CAACA,MAAMA,CAACA,CAACA;IACpFA,CAACA;IACLb,YAACA;AAADA,CAACA,AAtLD,IAsLC;AAxLD,iBAAS,KAAK,CAAC"} \ No newline at end of file diff --git a/test/Core.js b/test/Core.js new file mode 100644 index 0000000..54697e5 --- /dev/null +++ b/test/Core.js @@ -0,0 +1,131 @@ +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Iridium = require('../index'); +var InheritedCore = (function (_super) { + __extends(InheritedCore, _super); + function InheritedCore() { + _super.apply(this, arguments); + this.theAnswer = 42; + } + return InheritedCore; +})(Iridium.Core); +var InheritedCoreWithCustomConstructor = (function (_super) { + __extends(InheritedCoreWithCustomConstructor, _super); + function InheritedCoreWithCustomConstructor() { + _super.call(this, "mongodb://localhost/test"); + } + return InheritedCoreWithCustomConstructor; +})(Iridium.Core); +describe("Core", function () { + describe("constructor", function () { + it("should accept a URI string", function () { + var core = new Iridium.Core("mongodb://localhost/test"); + chai.expect(core.url).to.equal("mongodb://localhost/test"); + }); + it("should accept a configuration object", function () { + new Iridium.Core({ + database: 'test' + }); + }); + it("should correctly convert the configuration object into a URI string", function () { + var core = new Iridium.Core({ + host: 'localhost', + port: 27016, + database: 'test', + username: 'user', + password: 'password' + }); + chai.expect(core.url).to.equal("mongodb://user:password@localhost:27016/test"); + }); + it("should make logical assumptions about the default host", function () { + var core = new Iridium.Core({ + database: 'test' + }); + chai.expect(core.url).to.equal("mongodb://localhost/test"); + }); + }); + describe("plugins", function () { + var core = new Iridium.Core({ + database: 'test' + }); + var plugin = { + newModel: function (model) { + } + }; + it("should be registered through the register method", function () { + chai.expect(core.register(plugin)).to.equal(core); + }); + it("should then be available through the plugins collection", function () { + chai.expect(core.plugins).to.contain(plugin); + }); + }); + describe("middleware", function () { + var core = new Iridium.Core({ + database: 'test' + }); + it("should have an Express provider", function () { + chai.expect(core.express).to.exist.and.be.a('function'); + }); + }); + describe("cache", function () { + var core = new Iridium.Core({ + database: 'test' + }); + it("should have a default no-op cache provider", function () { + chai.expect(core.cache).to.exist; + return core.cache.set("test", true).then(function () { + chai.expect(core.cache.get("test")).to.eventually.not.exist; + }); + }); + }); + describe("connect", function () { + var core; + it("should return a rejection if the connection fails", function () { + core = new Iridium.Core("mongodb://0.0.0.0/test"); + return chai.expect(core.connect()).to.be.rejected; + }); + it("should open a connection to the correct database and return the core", function () { + core = new Iridium.Core("mongodb://localhost/test"); + return chai.expect(core.connect()).to.eventually.exist.and.equal(core); + }); + it("should then be able to close the connection", function () { + return core.close(); + }); + }); + describe("close", function () { + var core = new Iridium.Core("mongodb://localhost/test"); + it("should not fail if called when not connected", function () { + return core.close(); + }); + it("should chain promises", function () { + chai.expect(core.close()).to.eventually.equal(core); + }); + }); + describe("inheritance", function () { + it("should allow a class to extend the core", function () { + chai.expect(InheritedCore).to.exist; + chai.expect(new InheritedCore("mongodb://localhost/test")).to.be.an.instanceof(Iridium.Core); + }); + it("should pass through constructor arguments to the core", function () { + var core = new InheritedCore({ + database: 'test' + }); + chai.expect(core.url).to.equal("mongodb://localhost/test"); + }); + it("should pass through the properties of the object", function () { + var core = new InheritedCore({ + database: 'test' + }); + chai.expect(core.theAnswer).to.equal(42); + }); + it("should support custom constructors", function () { + var core = new InheritedCoreWithCustomConstructor(); + chai.expect(core.url).to.equal("mongodb://localhost/test"); + }); + }); +}); +//# sourceMappingURL=Core.js.map \ No newline at end of file diff --git a/test/Core.js.map b/test/Core.js.map new file mode 100644 index 0000000..e05f2bb --- /dev/null +++ b/test/Core.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Core.js","sourceRoot":"","sources":["Core.ts"],"names":["InheritedCore","InheritedCore.constructor","InheritedCoreWithCustomConstructor","InheritedCoreWithCustomConstructor.constructor"],"mappings":";;;;;;AAAA,IAAO,OAAO,WAAW,UAAU,CAAC,CAAC;AAErC,IAAM,aAAa;IAASA,UAAtBA,aAAaA,UAAqBA;IAAxCA,SAAMA,aAAaA;QAASC,8BAAYA;QACpCA,cAASA,GAAGA,EAAEA,CAACA;IACnBA,CAACA;IAADD,oBAACA;AAADA,CAACA,AAFD,EAA4B,OAAO,CAAC,IAAI,EAEvC;AAED,IAAM,kCAAkC;IAASE,UAA3CA,kCAAkCA,UAAqBA;IACzDA,SADEA,kCAAkCA;QAEhCC,kBAAMA,0BAA0BA,CAACA,CAACA;IACtCA,CAACA;IACLD,yCAACA;AAADA,CAACA,AAJD,EAAiD,OAAO,CAAC,IAAI,EAI5D;AAED,QAAQ,CAAC,MAAM,EAAC;IACZ,QAAQ,CAAC,aAAa,EAAC;QACnB,EAAE,CAAC,4BAA4B,EAAC;YAC5B,IAAI,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YACxD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sCAAsC,EAAC;YACtC,IAAI,OAAO,CAAC,IAAI,CAAC;gBACb,QAAQ,EAAE,MAAM;aACnB,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qEAAqE,EA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,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kDAAkD,EAAC;YAClD,IAAI,IAAI,GAAG,IAAI,aAAa,CAAC;gBACzB,QAAQ,EAAE,MAAM;aACnB,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAC;YACpC,IAAI,IAAI,GAAG,IAAI,kCAAkC,EAAE,CAAC;YACpD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/test/Iridium.js b/test/Iridium.js new file mode 100644 index 0000000..5c2e54e --- /dev/null +++ b/test/Iridium.js @@ -0,0 +1,13 @@ +var Iridium = require('../index'); +describe("Iridium", function () { + it("should expose the Core", function () { + chai.expect(Iridium.Core).to.exist.and.be.a('function'); + }); + it("should expose the Model constructor", function () { + chai.expect(Iridium.Model).to.exist.and.be.a('function'); + }); + it("should expose the default Instance class", function () { + chai.expect(Iridium.Instance).to.exist.and.be.a('function'); + }); +}); +//# sourceMappingURL=Iridium.js.map \ No newline at end of file diff --git a/test/Iridium.js.map b/test/Iridium.js.map new file mode 100644 index 0000000..3d90d84 --- /dev/null +++ b/test/Iridium.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Iridium.js","sourceRoot":"","sources":["Iridium.ts"],"names":[],"mappings":"AAAA,IAAO,OAAO,WAAW,UAAU,CAAC,CAAC;AAErC,QAAQ,CAAC,SAAS,EAAC;IACf,EAAE,CAAC,wBAAwB,EAAC;QACxB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE;QACtC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAC;QAC1C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/test/Model.js b/test/Model.js new file mode 100644 index 0000000..e2c3d19 --- /dev/null +++ b/test/Model.js @@ -0,0 +1,86 @@ +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Iridium = require('../index'); +var Test = (function (_super) { + __extends(Test, _super); + function Test() { + _super.apply(this, arguments); + } + return Test; +})(Iridium.Instance); +describe("Model", function () { + var core = new Iridium.Core({ database: 'test' }); + describe("constructor", function () { + it("should throw an error if you don't provide a valid core", function () { + chai.expect(function () { + new Iridium.Model(null, function () { + }, 'test', { id: String }); + }).to.throw("You failed to provide a valid Iridium core for this model"); + }); + it("should throw an error if you don't provide a valid instanceType", function () { + chai.expect(function () { + new Iridium.Model(core, null, 'test', { id: String }); + }).to.throw("You failed to provide a valid instance constructor for this model"); + }); + it("should throw an error if you don't provide a collection name", function () { + chai.expect(function () { + new Iridium.Model(core, function () { + }, null, { id: String }); + }).to.throw("You failed to provide a valid collection name for this model"); + chai.expect(function () { + new Iridium.Model(core, function () { + }, '', { id: String }); + }).to.throw("You failed to provide a valid collection name for this model"); + chai.expect(function () { + new Iridium.Model(core, function () { + }, 4, { id: String }); + }).to.throw("You failed to provide a valid collection name for this model"); + }); + it("should throw an error if you don't provide a valid schema", function () { + chai.expect(function () { + new Iridium.Model(core, function () { + }, 'test', null); + }).to.throw("You failed to provide a valid schema for this model"); + chai.expect(function () { + new Iridium.Model(core, function () { + }, 'test', {}); + }).to.throw("You failed to provide a valid schema for this model"); + }); + it("should correctly set the core", function () { + chai.expect(new Iridium.Model(core, function () { + }, 'test', { id: String }).core).to.equal(core); + }); + it("should correctly set the collectionName", function () { + chai.expect(new Iridium.Model(core, function () { + }, 'test', { id: String }).collectionName).to.equal('test'); + }); + it("should correctly set the schema", function () { + chai.expect(new Iridium.Model(core, function () { + }, 'test', { id: String }).schema).to.eql({ id: String }); + }); + }); + describe("create", function () { + var model = new Iridium.Model(core, Test, 'test', { answer: Number }); + before(function () { + return core.connect(); + }); + it("should allow the insertion of a single document", function () { + return chai.expect(model.create({ answer: 10 })).to.eventually.exist.and.have.property('answer', 10); + }); + it("should allow the insertion of multiple documents", function () { + return chai.expect(model.create([ + { answer: 11 }, + { answer: 12 }, + { answer: 13 } + ])).to.eventually.exist.and.have.lengthOf(3); + }); + it("should allow you to provide options to control the creation", function () { + return chai.expect(model.create({ answer: 14 }, { w: 'majority' })).to.eventually.exist; + }); + }); +}); +//# sourceMappingURL=Model.js.map \ No newline at end of file diff --git a/test/Model.js.map b/test/Model.js.map new file mode 100644 index 0000000..dc5374f --- /dev/null +++ b/test/Model.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Model.js","sourceRoot":"","sources":["Model.ts"],"names":["Test","Test.constructor"],"mappings":";;;;;;AAAA,IAAO,OAAO,WAAW,UAAU,CAAC,CAAC;AAOrC,IAAM,IAAI;IAASA,UAAbA,IAAIA,UAA6CA;IAAvDA,SAAMA,IAAIA;QAASC,8BAAoCA;IAGvDA,CAACA;IAADD,WAACA;AAADA,CAACA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IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;QAC5F,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/test/support/chai.js b/test/support/chai.js new file mode 100644 index 0000000..b0445f6 --- /dev/null +++ b/test/support/chai.js @@ -0,0 +1,8 @@ +var chai = require('chai'); +var chaiAsPromised = require('chai-as-promised'); +var chaiFuzzy = require('chai-fuzzy'); +chai.use(chaiAsPromised); +chai.use(chaiFuzzy); +global.chai = chai; +global.expect = chai.expect; +//# sourceMappingURL=chai.js.map \ No newline at end of file diff --git a/test/support/chai.js.map b/test/support/chai.js.map new file mode 100644 index 0000000..d86f1b6 --- /dev/null +++ b/test/support/chai.js.map @@ -0,0 +1 @@ +{"version":3,"file":"chai.js","sourceRoot":"","sources":["chai.ts"],"names":[],"mappings":"AAAA,IAAO,IAAI,WAAW,MAAM,CAAC,CAAC;AAC9B,IAAO,cAAc,WAAW,kBAAkB,CAAC,CAAC;AAEpD,IAAI,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEtC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AACzB,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAEpB,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;AACnB,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC"} \ No newline at end of file