mongoose-schema-extend
Advanced tools
Comparing version 0.2.0 to 0.2.1
35
index.js
@@ -9,2 +9,4 @@ 'use strict'; | ||
var Reflect = require('harmony-reflect'); | ||
/** | ||
@@ -17,9 +19,26 @@ * Add a new function to the schema prototype to create a new schema by extending an existing one | ||
// Fix for callQueue arguments, todo: fix clone implementation | ||
newSchema.callQueue.forEach(function(k) { | ||
var args = []; | ||
for(var i in k[1]) { | ||
args.push(k[1][i]); | ||
newSchema._callQueue = []; | ||
var that = this; | ||
newSchema.callQueue = new Proxy(newSchema._callQueue, { | ||
get: function(target, property, receiver) { | ||
switch (property) { | ||
case 'length': | ||
return target.length + that.callQueue.length; | ||
case 'toJSON': | ||
return () => target.concat(that.callQueue); | ||
case 'push': | ||
return (e) => target.push(e); | ||
break; | ||
case 'reduce': | ||
return Array.prototype.reduce.bind(target.concat(that.callQueue)); | ||
default: | ||
if(isNaN(property)) { | ||
return target[property]; | ||
} else { | ||
return that.callQueue.concat(target)[property]; | ||
} | ||
} | ||
} | ||
k[1] = args; | ||
}); | ||
@@ -30,4 +49,4 @@ | ||
this.paths[k].validators.forEach(function (validator, index) { | ||
if (validator.validator instanceof RegExp) { | ||
newSchema.paths[k].validators[index].validator = validator.validator; | ||
if (validator.regexp instanceof RegExp) { | ||
newSchema.paths[k].validators[index].regexp = validator.regexp; | ||
} | ||
@@ -34,0 +53,0 @@ }); |
{ | ||
"name": "mongoose-schema-extend", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "mongoose schema inheritance and discriminator key extension", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node ./node_modules/.bin/grunt test" | ||
"test": "node --harmony_proxies ./node_modules/.bin/grunt test" | ||
}, | ||
@@ -23,9 +23,22 @@ "homepage": "https://github.com/briankircho/mongoose-schema-extend", | ||
"contributors": [ | ||
{ "name": "Brian Kirchoff", "email": "briankircho@gmail.com" }, | ||
{ "name": "Ajay Sabhaney", "email": "ajay@mothercreative.com" }, | ||
{ "name": "Nicholas Calugar", "email" : "njcalugar@gmail.com" }, | ||
{ "name": "Luis Sieira", "email" : "luis.sieira@spacebar.fr" } | ||
{ | ||
"name": "Brian Kirchoff", | ||
"email": "briankircho@gmail.com" | ||
}, | ||
{ | ||
"name": "Ajay Sabhaney", | ||
"email": "ajay@mothercreative.com" | ||
}, | ||
{ | ||
"name": "Nicholas Calugar", | ||
"email": "njcalugar@gmail.com" | ||
}, | ||
{ | ||
"name": "Luis Sieira", | ||
"email": "luis.sieira@spacebar.fr" | ||
} | ||
], | ||
"license": "BSD-3-Clause", | ||
"license": "MIT", | ||
"dependencies": { | ||
"harmony-reflect": "^1.4.2", | ||
"owl-deepcopy": "~0.0.1" | ||
@@ -32,0 +45,0 @@ }, |
@@ -62,2 +62,24 @@ 'use strict'; | ||
it('Should allow two vehicles of the same brand with different model', function (done) { | ||
var fordSierra = new fixtures.Ford({ | ||
year : 1986, | ||
model : 'sierra' | ||
}); | ||
var anotherFordSierra = new fixtures.Ford({ | ||
year : 2030, | ||
model : 'planet' | ||
}); | ||
fordSierra.save(function(err) { | ||
should.not.exist(err); | ||
fordSierra._type.should.equal('ford'); | ||
anotherFordSierra.save(function(err) { | ||
should.not.exist(err); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
it('Should allow two vehicles of the same obscure brand with the same model', function (done) { | ||
@@ -64,0 +86,0 @@ var fordSierra = new fixtures.Ford({ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
19239
10
448
0
2
+ Addedharmony-reflect@^1.4.2
+ Addedharmony-reflect@1.6.2(transitive)