Comparing version 2.9.4 to 2.10.0
@@ -57,2 +57,7 @@ /// <reference path="../nodelib/node.js"/> | ||
Object.defineProperty(Instance.prototype, 'document', { | ||
get: function() { return this.__state.modified; }, | ||
enumerable: false | ||
}); | ||
Instance.prototype.save = function(conditions, changes, callback) { | ||
@@ -131,3 +136,3 @@ /// <signature> | ||
if(!changes) { | ||
var validation = validate(schema, this.__state.modified, undefined, this.__state.model.extraValidators); | ||
var validation = validate(this.__state.model.schema, this.__state.modified, undefined, this.__state.model.extraValidators); | ||
if(!validation.passed) return callback(validation.toError()); | ||
@@ -220,2 +225,55 @@ | ||
Instance.prototype.select = function(collection, filter) { | ||
/// <signature> | ||
/// <summary>Finds elements in the array for which the filter function returns truey</summary> | ||
/// <param name="collection" type="Object">The array to search through for matches</param> | ||
/// <param name="filter" type="Function">A function called with the array's element and its index/key for filtering pursposes</param> | ||
/// <returns type="Object"/> | ||
/// </signature> | ||
/// <signature> | ||
/// <summary>Finds elements in the array for which the filter function returns truey</summary> | ||
/// <param name="collection" type="Array">The array to search through for matches</param> | ||
/// <param name="filter" type="Function">A function called with the array's element and its index/key for filtering pursposes</param> | ||
/// <returns type="Array"/> | ||
/// </signature> | ||
var isArray = Array.isArray(collection); | ||
var results = isArray ? [] : {}; | ||
_.each(collection, function(value, key) { | ||
if(filter.call(this, value, key)) { | ||
if(isArray) results.push(value); | ||
else results[key] = value; | ||
} | ||
}, this); | ||
return results; | ||
}; | ||
Instance.prototype.first = function(collection, filter) { | ||
/// <signature> | ||
/// <summary>Finds the first element in the object for which the filter function returns truey</summary> | ||
/// <param name="collection" type="Object">The array to search through for matches</param> | ||
/// <param name="filter" type="Function">A function called with the array's element and its index/key for filtering pursposes</param> | ||
/// <returns type="Mixed"/> | ||
/// </signature> | ||
/// <signature> | ||
/// <summary>Finds the first element in the array for which the filter function returns truey</summary> | ||
/// <param name="collection" type="Array">The array to search through for matches</param> | ||
/// <param name="filter" type="Function">A function called with the array's element and its index/key for filtering pursposes</param> | ||
/// <returns type="Mixed"/> | ||
/// </signature> | ||
var result; | ||
_.each(collection, function(value, key) { | ||
if(filter.call(this, value, key)) { | ||
result = value; | ||
return false; | ||
} | ||
}, this); | ||
return result; | ||
} | ||
Instance.prototype.__extendSchema = function() { | ||
@@ -222,0 +280,0 @@ var $ = this; |
{ | ||
"name": "iridium", | ||
"version": "2.9.4", | ||
"author": "Benjamin Pannell <admin@sierrasoftworks.com>", | ||
"description": "A custom lightweight ORM for MongoDB designed for power-users", | ||
"homepage": "https://sierrasoftworks.com/iridium", | ||
"repository": "https://github.com/sierrasoftworks/iridium", | ||
"contributors": [ | ||
{ "name": "Benjamin Pannell", "email": "admin@sierrasoftworks.com" } | ||
], | ||
"licence": "MIT", | ||
"main": "./index", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"engines": { | ||
"node": ">= 0.8" | ||
}, | ||
"dependencies": { | ||
"mongodb": "*", | ||
"lodash": "*", | ||
"async": "*", | ||
"concoction": "*", | ||
"debug": "*" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
}, | ||
"keywords": [ | ||
"mongodb", | ||
"orm", | ||
"odm", | ||
"iridium", | ||
"validation", | ||
"transformation", | ||
"preprocessing" | ||
] | ||
} | ||
"name": "iridium", | ||
"version": "2.10.0", | ||
"author": "Benjamin Pannell <admin@sierrasoftworks.com>", | ||
"description": "A custom lightweight ORM for MongoDB designed for power-users", | ||
"homepage": "https://sierrasoftworks.com/iridium", | ||
"repository": "https://github.com/sierrasoftworks/iridium", | ||
"contributors": [ | ||
{ | ||
"name": "Benjamin Pannell", | ||
"email": "admin@sierrasoftworks.com" | ||
} | ||
], | ||
"licence": "MIT", | ||
"main": "./index", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"engines": { | ||
"node": ">= 0.8" | ||
}, | ||
"dependencies": { | ||
"mongodb": "*", | ||
"lodash": "*", | ||
"async": "*", | ||
"concoction": "*", | ||
"debug": "*" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
}, | ||
"keywords": [ | ||
"mongodb", | ||
"orm", | ||
"odm", | ||
"iridium", | ||
"validation", | ||
"transformation", | ||
"preprocessing" | ||
] | ||
} |
@@ -11,10 +11,56 @@ var Database = require('../index'); | ||
describe('Instance', function () { | ||
var db = { | ||
plugins: [] | ||
}; | ||
var db = new Database({ database: 'iridium_test' }); | ||
var model = new Model(db, 'instances', { | ||
username: String, | ||
sessions: [{ | ||
id: String, | ||
expires: Date | ||
}] | ||
}, { | ||
preprocessors: [ | ||
new Concoction.Rename({ '_id': 'username' }) | ||
] | ||
}); | ||
before(function(done) { | ||
db.connect(function(err) { | ||
if(err) return done(err); | ||
model.remove(done); | ||
}); | ||
}); | ||
after(function() { | ||
db.disconnect(); | ||
}); | ||
describe('database', function () { | ||
describe('save', function() { | ||
it('should correctly store changes made to the instance', function(done) { | ||
model.create({ | ||
username: 'billy', | ||
sessions: [{ | ||
id: 'aaaa', | ||
expires: new Date() | ||
}] | ||
}, function(err, original) { | ||
if(err) return done(err); | ||
original.sessions.push({ | ||
id: 'bbbb', | ||
expires: new Date() | ||
}); | ||
original.save(function(err, updated) { | ||
if(err) return done(err); | ||
updated.should.equal(original); | ||
updated.sessions.length.toString().should.eql('2'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
352718
70
7153