diff --git a/Iridium.njsproj b/Iridium.njsproj
index 414c122..ab88aa7 100644
--- a/Iridium.njsproj
+++ b/Iridium.njsproj
@@ -52,8 +52,17 @@
Code
Mocha
+
+ Code
+ Mocha
+
+
+ Code
+ Mocha
+
+
diff --git a/lib/Model.js b/lib/Model.js
index a7884ea..9d75711 100644
--- a/lib/Model.js
+++ b/lib/Model.js
@@ -431,7 +431,7 @@ var Model = (function () {
if (typeof (specification) === 'string')
index = specification;
else {
- index = _(specification).map(function (direction, key) { return key + '_' + direction; }).reduce(function (x, y) { return x + '_' + y; }, '').value();
+ index = _(specification).map(function (direction, key) { return key + '_' + direction; }).reduce(function (x, y) { return x + '_' + y; }, '');
}
return new Promise(function (resolve, reject) {
_this.collection.dropIndex(index, function (err, count) {
diff --git a/lib/Model.js.map b/lib/Model.js.map
index 91ffc7d..e49352b 100644
--- a/lib/Model.js.map
+++ b/lib/Model.js.map
@@ -1 +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","Model.dropIndex","Model.dropIndexes","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":"AACA,AADA,4CAA4C;AAC5C,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AACpC,IAAO,M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MA,CAACA,OAAOA,CAACA,OAAOA,CAACA,KAAKA,CAACA,CAACA;QAC5GA,MAAMA,CAACA,IAAIA,CAACA,KAAKA,CAACA,IAAIA,CAACA,KAAKA,CAACA,GAAGA,CAACA,IAAIA,CAACA,KAAKA,CAACA,aAAaA,CAACA,QAAQA,CAACA,UAAUA,CAACA,EAAEA,KAAKA,CAACA,CAACA;IAC3FA,CAACA;IAEDH,wBAAGA,GAAHA,UAAOA,UAAeA;QAClBI,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,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
+{"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","Model.dropIndex","Model.dropIndexes","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":"AACA,AADA,4CAA4C;AAC5C,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;AACrC,IAAO,IAAI,WAAW,MAAM,CAAC,CAAC;AAC9B,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,KAAKA,CAUFA,IAAaA,EAAEA,YAAYA,EAAEA,UAAkBA,EAAEA,MAAeA,EAAEA,OAAiDA;QAAjDC,uBAAiDA,GAAjDA,YAAiDA;QAG3HA,AADAA,6EAA6EA;QAC7EA,EAAEA,CAACA,CAACA,CAACA,CAACA,IAAIA,YAAYA,KAAKA,CAACA,CAACA;YAACA,MAAMA,CAACA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,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/Model.ts b/lib/Model.ts
index 66d62af..3eb5697 100644
--- a/lib/Model.ts
+++ b/lib/Model.ts
@@ -1 +1 @@
-///
import MongoDB = require('mongodb');
import Skmatc = require('skmatc');
import Concoction = require('concoction');
import Promise = require('bluebird');
import util = require('util');
import _ = require('lodash');
import Iridium = require('./Core');
import instance = require('./Instance');
import ISchema = require('./Schema');
import hooks = require('./Hooks');
import IPlugin = require('./Plugins');
import cache = require('./Cache');
import CacheDirector = require('./CacheDirector');
import general = require('./General');
import noOpCache = require('./caches/NoOpCache');
import memoryCache = require('./caches/MemoryCache');
import idCacheController = require('./cacheControllers/IDDirector');
import Omnom = require('./utils/Omnom');
/**
* An Iridium Model which represents a structured MongoDB collection
* @class
*/
export class Model implements IModel {
/**
* 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
*/
constructor(core: Iridium, instanceType, collection: string, schema: ISchema, options: IModelOptions = {}) {
// 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: IPlugin) {
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);
}
private _options: IModelOptions;
/**
* 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 options(): IModelOptions {
return this._options;
}
private _helpers: ModelHelpers;
/**
* Provides helper methods used by Iridium for common tasks
* @returns {ModelHelpers}
*/
get helpers(): ModelHelpers {
return this._helpers;
}
private _handlers: ModelHandlers;
/**
* Provides helper methods used by Iridium for hook delegation and common processes
* @returns {ModelHandlers}
*/
get handlers(): ModelHandlers {
return this._handlers;
}
private _schema: ISchema;
/**
* Gets the ISchema dictating the data structure represented by this model
* @public
* @returns {schema}
*/
get schema(): ISchema {
return this._schema;
}
private _core: Iridium;
/**
* Gets the Iridium core that this model is associated with
* @public
* @returns {Iridium}
*/
get core(): Iridium {
return this._core;
}
private _collection: string;
/**
* Gets the underlying MongoDB collection from which this model's documents are retrieved
* @public
* @returns {Collection}
*/
get collection(): MongoDB.Collection {
return this.core.connection.collection(this._collection);
}
/**
* Gets the name of the underlying MongoDB collection from which this model's documents are retrieved
* @public
*/
get collectionName(): string {
return this._collection;
}
/**
* Sets the name of the underlying MongoDB collection from which this model's documents are retrieved
* @public
*/
set collectionName(value: string) {
this._collection = value;
}
private _cacheDirector: CacheDirector;
/**
* Gets the cache controller which dictates which queries will be cached, and under which key
* @public
* @returns {CacheDirector}
*/
get cacheDirector(): CacheDirector {
return this._cacheDirector;
}
private _cache: ModelCache;
/**
* Gets the cache responsible for storing objects for quick retrieval under certain conditions
* @public
* @returns {ModelCache}
*/
get cache(): ModelCache {
return this._cache;
}
private _Instance: ModelSpecificInstance;
/**
* 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
*/
wrap(document: TDocument, isNew: boolean = true, isPartial: boolean = false): TInstance {
return this._Instance.build(document, isNew, isPartial);
}
/**
* Retrieves all documents in the collection and wraps them as instances
* @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available
* @returns {Promise}
*/
find(callback?: general.Callback): Promise;
/**
* Returns all documents in the collection which match the conditions and wraps them as instances
* @param {Object} conditions The MongoDB query dictating which documents to return
* @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available
* @returns {Promise}
*/
find(conditions: any, callback?: general.Callback): Promise;
/**
* Returns all documents in the collection which match the conditions
* @param {Object} conditions The MongoDB query dictating which documents to return
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available
* @returns {Promise}
*/
find(conditions: any, options: QueryOptions, callback?: general.Callback): Promise;
find(conditions?: any, options?: QueryOptions, callback?: general.Callback): Promise {
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(() => {
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((callback) => {
cursor.toArray(callback);
})();
}).then((results: TDocument[]) => {
if (!results || !results.length) return Promise.resolve([]);
return this.handlers.documentsReceived(conditions, results,(document, isNew?, isPartial?) => this.helpers.wrapDocument(document, isNew, isPartial), options);
}).nodeify(callback);
}
/**
* Retrieves a single document from the collection and wraps it as an instance
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection with the given ID and wraps it as an instance
* @param {any} id The document's unique _id field value in downstream format
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(id: any, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection which matches the conditions
* @param {Object} conditions The MongoDB query dictating which document to return
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(conditions: { [key: string]: any }, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection with the given ID and wraps it as an instance
* @param {any} id The document's unique _id field value in downstream format
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(id: any, options: QueryOptions, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection which matches the conditions
* @param {Object} conditions The MongoDB query dictating which document to return
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(conditions: { [key: string]: any }, options: QueryOptions, callback?: general.Callback): Promise;
get(...args: any[]): Promise {
return this.get.apply(this, args);
}
/**
* Retrieves a single document from the collection and wraps it as an instance
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection with the given ID and wraps it as an instance
* @param {any} id The document's unique _id field value in downstream format
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(id: any, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection which matches the conditions
* @param {Object} conditions The MongoDB query dictating which document to return
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(conditions: { [key: string]: any }, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection with the given ID and wraps it as an instance
* @param {any} id The document's unique _id field value in downstream format
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(id: any, options: QueryOptions, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection which matches the conditions
* @param {Object} conditions The MongoDB query dictating which document to return
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(conditions: { [key: string]: any }, options: QueryOptions, callback?: general.Callback): Promise;
findOne(...args: any[]): Promise {
var conditions: { [key: string]: any } = null;
var options: QueryOptions = null;
var callback: general.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]);
}
conditions = conditions || {};
options = options || {};
_.defaults(options, {
wrap: true,
cache: true
});
return Promise.resolve().bind(this).then(() => {
this.helpers.transform.reverse(conditions);
if (options.fields)
this.helpers.transform.reverse(options.fields);
return this.cache.get(conditions);
}).then((cachedDocument: TDocument) => {
if (cachedDocument) return cachedDocument;
return new Promise((resolve, reject) => {
this.collection.findOne(conditions, {
fields: options.fields,
skip: options.skip,
sort: options.sort,
limit: options.limit
},(err, result) => {
if (err) return reject(err);
return resolve(result);
});
});
}).then((document: TDocument) => {
if (!document) return null;
return this.handlers.documentsReceived(conditions, [document],(document, isNew?, isPartial?) => this.helpers.wrapDocument(document, isNew, isPartial), options).then((documents) => documents[0]);
}).nodeify(callback);
}
create(objects: TDocument, callback?: general.Callback): Promise;
create(objects: TDocument, options: CreateOptions, callback?: general.Callback): Promise;
create(objects: TDocument[], callback?: general.Callback): Promise;
create(objects: TDocument[], options: CreateOptions, callback?: general.Callback): Promise;
create(...args: any[]): Promise {
return this.insert.apply(this, args);
}
insert(objects: TDocument, callback?: general.Callback): Promise;
insert(objects: TDocument, options: CreateOptions, callback?: general.Callback): Promise;
insert(objects: TDocument[], callback?: general.Callback): Promise;
insert(objects: TDocument[], options: CreateOptions, callback?: general.Callback): Promise;
insert(objs: TDocument | TDocument[], ...args: any[]): Promise {
var objects: TDocument[];
var options: CreateOptions = {};
var callback: general.Callback = null;
if (typeof args[0] == 'function') callback = args[0];
else {
options = args[0];
callback = args[1];
}
var returnArray: boolean = false;
if (Array.isArray(objs))
objects = objs;
else
objects = [objs];
options = options || {};
_.defaults(options, {
w: 1
});
return Promise.resolve().then(() => {
var queryOptions = { w: options.w, upsert: options.upsert, new: true };
if (options.upsert)
return this.handlers.creatingDocuments(objects).map((object: { _id: any; }) => {
return new Promise((resolve, reject) => {
this.collection.findAndModify({ _id: object._id }, ["_id"], object, queryOptions,(err, result) => {
if (err) return reject(err);
return resolve(result);
});
});
});
else
return this.handlers.creatingDocuments(objects).then((objects) => {
return new Promise((resolve, reject) => {
this.collection.insert(objects, queryOptions,(err, results) => {
if (err) return reject(err);
return resolve(results);
});
});
});
}).then((inserted: any[]) => {
return this.handlers.documentsReceived(null, inserted,(document, isNew?, isPartial?) => this.helpers.wrapDocument(document, isNew, isPartial), { cache: options.cache });
}).then((results: TInstance[]) => {
if (Array.isArray(objs)) return results;
return results[0];
}).nodeify(callback);
}
update(conditions: any, changes: any, callback?: general.Callback): Promise;
update(conditions: any, changes: any, options: UpdateOptions, callback?: general.Callback): Promise;
update(conditions: any, changes: any, options?: UpdateOptions, callback?: general.Callback): Promise {
if (typeof options == 'function') {
callback = >options;
options = {};
}
_.defaults(options, {
w: 1,
multi: true
});
this.helpers.transform.reverse(conditions);
return new Promise((resolve, reject) => {
this.collection.update(conditions, changes, options,(err, changes) => {
if (err) return reject(err);
return resolve(changes);
});
}).nodeify(callback);
}
count(callback?: general.Callback): Promise;
count(conditions: any, callback?: general.Callback): Promise;
count(conditions?: any, callback?: general.Callback): Promise {
if (typeof conditions == 'function') {
callback = >conditions;
conditions = {};
}
var $this = this;
return new Promise((resolve, reject) => {
$this.collection.count(conditions,(err, results) => {
if (err) return reject(err);
return resolve(results);
});
}).nodeify(callback);
}
remove(callback?: general.Callback): Promise;
remove(conditions: any, callback?: general.Callback): Promise;
remove(conditions?: any, callback?: general.Callback): Promise {
if (typeof conditions == 'function') {
callback = >conditions;
conditions = {};
}
return new Promise((resolve, reject) => {
this.collection.remove(conditions,(err, results) => {
if (err) return reject(err);
return resolve(results);
});
}).then((count) => {
return this.cache.clear(conditions).then(() => count);
}).nodeify(callback);
}
ensureIndex(specification: IndexSpecification, callback?: general.Callback): Promise;
ensureIndex(specification: IndexSpecification, options: MongoDB.IndexOptions, callback?: general.Callback): Promise;
ensureIndex(specification: IndexSpecification, options?: MongoDB.IndexOptions, callback?: general.Callback): Promise {
if (typeof options == 'function') {
callback = >options;
options = {};
}
return new Promise((resolve, reject) => {
this.collection.ensureIndex(specification, options,(err, name: any) => {
if (err) return reject(err);
return resolve(name);
});
}).nodeify(callback);
}
ensureIndices(callback?: general.Callback): Promise {
return Promise.resolve(this.options.indices).map((index: Index | IndexSpecification) => {
return this.ensureIndex((index).spec || index,(index).options || {});
}).nodeify(callback);
}
dropIndex(name: string, callback?: general.Callback): Promise;
dropIndex(index: IndexSpecification, callback?: general.Callback): Promise;
dropIndex(specification: string | IndexSpecification, callback?: general.Callback): Promise {
var index: string;
if (typeof (specification) === 'string') index = specification;
else {
index = _(specification).map((direction, key) => key + '_' + direction).reduce((x, y) => x + '_' + y, '').value();
}
return new Promise((resolve, reject) => {
this.collection.dropIndex(index,(err, count) => {
if (err) return reject(err);
return resolve(count);
});
}).nodeify(callback);
}
dropIndexes(callback?: general.Callback): Promise {
return new Promise((resolve, reject) => {
this.collection.dropAllIndexes((err, count) => {
if (err) return reject(err);
return resolve(count);
});
}).nodeify(callback);
}
}
export interface IModelBase {
collection: MongoDB.Collection;
collectionName: string;
core: Iridium;
schema: ISchema;
cache: ModelCache;
cacheDirector: CacheDirector;
}
export interface IModelFactory {
(core: Iridium): IModel;
}
export interface IModelOptions {
hooks?: hooks.IHooks;
validators?: SkmatcCore.IValidator[];
transforms?: Concoction.Ingredient[];
cache?: CacheDirector;
indices?: (Index | IndexSpecification)[];
properties?: { [key: string]: (general.PropertyGetter | general.Property) };
}
export interface IModel extends IModelBase {
wrap(doc: TDocument, isNew?: boolean, isPartial?: boolean): TInstance;
}
export class ModelSpecificInstance {
constructor(model: Model, instanceConstructor) {
this.Constructor = function (document: TDocument, isNew?: boolean, isPartial?: boolean) {
instanceConstructor.call(this, model, document, isNew, isPartial);
};
util.inherits(this.Constructor, instanceConstructor);
_.each(model.schema,(property, key) => {
Object.defineProperty(this.Constructor.prototype, key, {
get: function () {
return this._modified[key];
},
set: function (value) {
this._modified[key] = value;
},
enumerable: true
});
});
}
private Constructor: (document: TDocument, isNew?: boolean, isPartial?: boolean) => void;
build(document: TDocument, isNew?: boolean, isPartial?: boolean): TInstance {
return new this.Constructor(document, isNew, isPartial);
}
}
export class ModelHelpers {
constructor(model: Model) {
this._model = model;
this._validator = new Skmatc(model.schema);
this._transform = new Concoction(model.options.transforms);
}
private _model: Model;
private _transform: concoction;
/**
* Gets the Concoction transforms defined for this model
* @returns {Concoction}
*/
get transform(): Concoction {
return this._transform;
}
private _validator: Skmatc;
/**
* 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
*/
validate(document: TDocument): SkmatcCore.IResult {
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
*/
selectOne(document: TDocument): { _id: any } {
var testDoc: any = _.cloneDeep(document);
this.transform.reverse(testDoc);
return {
_id: testDoc._id
};
}
/**
* Gets the field used in the ISchema to represent the document _id
*/
get identifierField(): string {
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;
}
/**
* 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
*/
selectOneDownstream(id: TDocument): any {
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
*/
wrapDocument(document: TDocument, isNew?: boolean, isPartial?: boolean): TInstance {
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
*/
diff(original: TDocument, modified: TDocument): any {
var omnom = new Omnom();
omnom.diff(original, modified);
return omnom.changes;
}
}
export class ModelHandlers {
constructor(model: Model) {
this._model = model;
}
private _model: Model;
get model(): Model {
return this._model;
}
documentsReceived(conditions: any,
results: TDocument[],
wrapper: (document: TDocument, isNew?: boolean, isPartial?: boolean) => TInstance,
options: QueryOptions = {}): Promise {
_.defaults(options, {
cache: true,
partial: false
});
return Promise.resolve(results).map((target: any) => {
return >Promise.resolve().then(() => {
// Trigger the received hook
if (this.model.options.hooks.retrieved) return this.model.options.hooks.retrieved(target);
}).then(() => {
// 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(() => {
// Transform the document
this.model.helpers.transform.apply(target);
// Wrap the document and trigger the ready hook
var wrapped: TInstance = wrapper(target, false, !!options.fields);
if (this.model.options.hooks.ready) return Promise.resolve(this.model.options.hooks.ready(wrapped)).then(() => wrapped);
return wrapped;
});
});
}
creatingDocuments(documents: TDocument[]): Promise {
return Promise.all(documents.map((document: any) => {
return Promise.resolve().then(() => {
if (this.model.options.hooks.retrieved) return this.model.options.hooks.creating(document);
}).then(() => {
var validation: SkmatcCore.IResult = this.model.helpers.validate(document);
if (validation.failed) return Promise.reject(validation.error);
this.model.helpers.transform.reverse(document);
return document;
});
}));
}
savingDocument(instance: TInstance, changes: any): Promise {
return Promise.resolve().then(() => {
if (this.model.options.hooks.saving) return this.model.options.hooks.saving(instance, changes);
}).then(() => instance);
}
}
export interface QueryOptions {
cache?: boolean;
fields?: { [name: string]: number };
limit?: number;
skip?: number;
sort?: IndexSpecification;
}
export interface CreateOptions {
w?: any;
upsert?: boolean;
cache?: boolean;
}
export interface UpdateOptions {
w?: any;
multi?: boolean;
}
export interface IndexSpecification {
[key: string]: number;
}
export interface Index {
spec: IndexSpecification;
options?: MongoDB.IndexOptions;
}
class ModelCache {
constructor(model: IModelBase) {
this._model = model;
}
private _model: IModelBase;
get model(): IModelBase {
return this._model;
}
set(conditions: any, value: T): Promise {
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);
}
get(conditions: any): Promise {
if (!this.model.cacheDirector || !this.model.cacheDirector.valid(conditions)) return Promise.resolve(null);
return this.model.core.cache.get(this.model.cacheDirector.buildKey(conditions));
}
clear(conditions: any): Promise {
if (!this.model.cacheDirector || !this.model.cacheDirector.valid(conditions)) return Promise.resolve(false);
return this.model.core.cache.clear(this.model.cacheDirector.buildKey(conditions));
}
}
+///
import MongoDB = require('mongodb');
import Skmatc = require('skmatc');
import Concoction = require('concoction');
import Promise = require('bluebird');
import util = require('util');
import _ = require('lodash');
import Iridium = require('./Core');
import instance = require('./Instance');
import ISchema = require('./Schema');
import hooks = require('./Hooks');
import IPlugin = require('./Plugins');
import cache = require('./Cache');
import CacheDirector = require('./CacheDirector');
import general = require('./General');
import noOpCache = require('./caches/NoOpCache');
import memoryCache = require('./caches/MemoryCache');
import idCacheController = require('./cacheControllers/IDDirector');
import Omnom = require('./utils/Omnom');
/**
* An Iridium Model which represents a structured MongoDB collection
* @class
*/
export class Model implements IModel {
/**
* 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
*/
constructor(core: Iridium, instanceType, collection: string, schema: ISchema, options: IModelOptions = {}) {
// 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: IPlugin) {
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);
}
private _options: IModelOptions;
/**
* 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 options(): IModelOptions {
return this._options;
}
private _helpers: ModelHelpers;
/**
* Provides helper methods used by Iridium for common tasks
* @returns {ModelHelpers}
*/
get helpers(): ModelHelpers {
return this._helpers;
}
private _handlers: ModelHandlers;
/**
* Provides helper methods used by Iridium for hook delegation and common processes
* @returns {ModelHandlers}
*/
get handlers(): ModelHandlers {
return this._handlers;
}
private _schema: ISchema;
/**
* Gets the ISchema dictating the data structure represented by this model
* @public
* @returns {schema}
*/
get schema(): ISchema {
return this._schema;
}
private _core: Iridium;
/**
* Gets the Iridium core that this model is associated with
* @public
* @returns {Iridium}
*/
get core(): Iridium {
return this._core;
}
private _collection: string;
/**
* Gets the underlying MongoDB collection from which this model's documents are retrieved
* @public
* @returns {Collection}
*/
get collection(): MongoDB.Collection {
return this.core.connection.collection(this._collection);
}
/**
* Gets the name of the underlying MongoDB collection from which this model's documents are retrieved
* @public
*/
get collectionName(): string {
return this._collection;
}
/**
* Sets the name of the underlying MongoDB collection from which this model's documents are retrieved
* @public
*/
set collectionName(value: string) {
this._collection = value;
}
private _cacheDirector: CacheDirector;
/**
* Gets the cache controller which dictates which queries will be cached, and under which key
* @public
* @returns {CacheDirector}
*/
get cacheDirector(): CacheDirector {
return this._cacheDirector;
}
private _cache: ModelCache;
/**
* Gets the cache responsible for storing objects for quick retrieval under certain conditions
* @public
* @returns {ModelCache}
*/
get cache(): ModelCache {
return this._cache;
}
private _Instance: ModelSpecificInstance;
/**
* 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
*/
wrap(document: TDocument, isNew: boolean = true, isPartial: boolean = false): TInstance {
return this._Instance.build(document, isNew, isPartial);
}
/**
* Retrieves all documents in the collection and wraps them as instances
* @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available
* @returns {Promise}
*/
find(callback?: general.Callback): Promise;
/**
* Returns all documents in the collection which match the conditions and wraps them as instances
* @param {Object} conditions The MongoDB query dictating which documents to return
* @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available
* @returns {Promise}
*/
find(conditions: any, callback?: general.Callback): Promise;
/**
* Returns all documents in the collection which match the conditions
* @param {Object} conditions The MongoDB query dictating which documents to return
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance[])} callback An optional callback which will be triggered when results are available
* @returns {Promise}
*/
find(conditions: any, options: QueryOptions, callback?: general.Callback): Promise;
find(conditions?: any, options?: QueryOptions, callback?: general.Callback): Promise {
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(() => {
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((callback) => {
cursor.toArray(callback);
})();
}).then((results: TDocument[]) => {
if (!results || !results.length) return Promise.resolve([]);
return this.handlers.documentsReceived(conditions, results,(document, isNew?, isPartial?) => this.helpers.wrapDocument(document, isNew, isPartial), options);
}).nodeify(callback);
}
/**
* Retrieves a single document from the collection and wraps it as an instance
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection with the given ID and wraps it as an instance
* @param {any} id The document's unique _id field value in downstream format
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(id: any, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection which matches the conditions
* @param {Object} conditions The MongoDB query dictating which document to return
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(conditions: { [key: string]: any }, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection with the given ID and wraps it as an instance
* @param {any} id The document's unique _id field value in downstream format
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(id: any, options: QueryOptions, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection which matches the conditions
* @param {Object} conditions The MongoDB query dictating which document to return
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
get(conditions: { [key: string]: any }, options: QueryOptions, callback?: general.Callback): Promise;
get(...args: any[]): Promise {
return this.get.apply(this, args);
}
/**
* Retrieves a single document from the collection and wraps it as an instance
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection with the given ID and wraps it as an instance
* @param {any} id The document's unique _id field value in downstream format
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(id: any, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection which matches the conditions
* @param {Object} conditions The MongoDB query dictating which document to return
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(conditions: { [key: string]: any }, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection with the given ID and wraps it as an instance
* @param {any} id The document's unique _id field value in downstream format
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(id: any, options: QueryOptions, callback?: general.Callback): Promise;
/**
* Retrieves a single document from the collection which matches the conditions
* @param {Object} conditions The MongoDB query dictating which document to return
* @param {QueryOptions} options The options dictating how this function behaves
* @param {function(Error, TInstance)} callback An optional callback which will be triggered when a result is available
* @returns {Promise}
*/
findOne(conditions: { [key: string]: any }, options: QueryOptions, callback?: general.Callback): Promise;
findOne(...args: any[]): Promise {
var conditions: { [key: string]: any } = null;
var options: QueryOptions = null;
var callback: general.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]);
}
conditions = conditions || {};
options = options || {};
_.defaults(options, {
wrap: true,
cache: true
});
return Promise.resolve().bind(this).then(() => {
this.helpers.transform.reverse(conditions);
if (options.fields)
this.helpers.transform.reverse(options.fields);
return this.cache.get(conditions);
}).then((cachedDocument: TDocument) => {
if (cachedDocument) return cachedDocument;
return new Promise((resolve, reject) => {
this.collection.findOne(conditions, {
fields: options.fields,
skip: options.skip,
sort: options.sort,
limit: options.limit
},(err, result) => {
if (err) return reject(err);
return resolve(result);
});
});
}).then((document: TDocument) => {
if (!document) return null;
return this.handlers.documentsReceived(conditions, [document],(document, isNew?, isPartial?) => this.helpers.wrapDocument(document, isNew, isPartial), options).then((documents) => documents[0]);
}).nodeify(callback);
}
create(objects: TDocument, callback?: general.Callback): Promise;
create(objects: TDocument, options: CreateOptions, callback?: general.Callback): Promise;
create(objects: TDocument[], callback?: general.Callback): Promise;
create(objects: TDocument[], options: CreateOptions, callback?: general.Callback): Promise;
create(...args: any[]): Promise {
return this.insert.apply(this, args);
}
insert(objects: TDocument, callback?: general.Callback): Promise;
insert(objects: TDocument, options: CreateOptions, callback?: general.Callback): Promise;
insert(objects: TDocument[], callback?: general.Callback): Promise;
insert(objects: TDocument[], options: CreateOptions, callback?: general.Callback): Promise;
insert(objs: TDocument | TDocument[], ...args: any[]): Promise {
var objects: TDocument[];
var options: CreateOptions = {};
var callback: general.Callback = null;
if (typeof args[0] == 'function') callback = args[0];
else {
options = args[0];
callback = args[1];
}
var returnArray: boolean = false;
if (Array.isArray(objs))
objects = objs;
else
objects = [objs];
options = options || {};
_.defaults(options, {
w: 1
});
return Promise.resolve().then(() => {
var queryOptions = { w: options.w, upsert: options.upsert, new: true };
if (options.upsert)
return this.handlers.creatingDocuments(objects).map((object: { _id: any; }) => {
return new Promise