Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-schema-extend

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-schema-extend - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

Gruntfile.js

41

index.js

@@ -0,1 +1,3 @@

'use strict';
var mongoose = require('mongoose'),

@@ -23,2 +25,11 @@ owl = require('owl-deepcopy');

// Fix validators RegExps
Object.keys(this.paths).forEach(function(k) {
this.paths[k].validators.forEach(function (validator, index) {
if (validator.validator instanceof RegExp) {
newSchema.paths[k].validators[index].validator = validator.validator;
}
});
}, this);
// Override the existing options with any newly supplied ones

@@ -29,2 +40,24 @@ for(var k in options) {

// Change the unique fields to compound discriminator/field unique indexes
// using a 2dSphere [HACK ALERT] to allow duplicates or missing fields on subSchemas where
// the option has not been specified
var uniqueFields = [];
for(var k in obj) {
if(obj[k].unique) {
obj[k].unique = false;
uniqueFields.push(k);
}
}
uniqueFields.forEach(function (field) {
obj[field + '_unique'] = { type: {type: String, enum: "Point", default: "Point"}, coordinates: { type: [Number], default: [0,0] } };
var index = {};
index[newSchema.options.discriminatorKey] = 1;
index[field] = 1;
index[field + '_unique'] = '2dsphere';
newSchema.index(index, { unique: true });
});
// This adds all the new schema fields

@@ -56,3 +89,3 @@ newSchema.add(obj);

*/
var oldInit = Model.prototype.init;
var _init = Model.prototype.init;
Model.prototype.init = function(doc, query, fn) {

@@ -70,3 +103,3 @@ var key = this.schema.options['discriminatorKey'];

process.nextTick(function() {
fn.apply(this, arguments);
if(fn && typeof fn === 'function') fn.apply(this, arguments);
});

@@ -76,3 +109,3 @@ }

this.schema = model.schema;
var obj = oldInit.call(this, doc, query, newFn);
var obj = _init.call(this, doc, query, newFn);
obj.__proto__ = model.prototype;

@@ -84,3 +117,3 @@ return obj;

// If theres no discriminatorKey we can just call the original method
return oldInit.apply(this, arguments);
return _init.apply(this, arguments);
}

19

package.json
{
"name": "mongoose-schema-extend",
"version": "0.1.7",
"version": "0.2.0",
"description": "mongoose schema inheritance and discriminator key extension",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "node ./node_modules/.bin/grunt test"
},

@@ -25,5 +25,6 @@ "homepage": "https://github.com/briankircho/mongoose-schema-extend",

{ "name": "Ajay Sabhaney", "email": "ajay@mothercreative.com" },
{ "name": "Nicholas Calugar", "email" : "njcalugar@gmail.com" }
{ "name": "Nicholas Calugar", "email" : "njcalugar@gmail.com" },
{ "name": "Luis Sieira", "email" : "luis.sieira@spacebar.fr" }
],
"license": "BSD",
"license": "BSD-3-Clause",
"dependencies": {

@@ -33,6 +34,10 @@ "owl-deepcopy": "~0.0.1"

"devDependencies": {
"mocha": "~1.3.2",
"should": "~1.1.0",
"mongoose": "~3.5.7"
"glob": "^5.0.15",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-mocha-test": "^0.12.7",
"mocha": "^2.3.3",
"mongoose": "^4.2.4",
"should": "~1.1.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc