Socket
Socket
Sign inDemoInstall

camouflage

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

camouflage - npm Package Compare versions

Comparing version 0.8.7 to 0.8.8

51

lib/base-document.js

@@ -263,17 +263,45 @@ "use strict";

var instance = this._instantiate();
_.keys(d).forEach(function(key) {
return instance.fill(d);
}
populate() {
return BaseDocument.populate(this);
}
fill(newValues) {
var instance = this;
if(newValues === null || newValues === undefined){
return this;
}
if(DB().isNativeId(newValues)){
this._values._id = newValues;
return this;
}
_.keys(newValues).forEach(function(key) {
var value = null;
if (d[key] === null || d[key] === undefined) {
value = instance.getDefault(key);
if (!(key in newValues)) {
value = instance._values[key];
if(value === undefined) {
value = instance.getDefault(key);
}
} else {
value = d[key];
value = newValues[key];
}
// If its not in the schema, we don't care about it... right?
if (key in instance._schema) {
var type = instance._schema[key].type;
if (type.documentClass && type.documentClass() === 'embedded') {
instance._values[key] = type._fromData(value);
if (type.prototype instanceof BaseDocument) {
if(value === null || value === undefined){
instance._values[key] = value;
} else if(instance._values[key] instanceof BaseDocument){
instance._values[key].fill(value);
} else if(typeof value === 'object' && !(DB().isNativeId(value))) {
instance._values[key] = type._fromData(value);
} else {
instance._values[key] = value;
}
} else if(key === '_id' || key === 'id') {
instance._values[key] = DB().toNativeId(value);
} else {

@@ -283,14 +311,8 @@ instance._values[key] = value;

} else if (key in instance) {
// Handles virtual setters
instance[key] = value;
}
});
return instance;
return this;
}
populate() {
return BaseDocument.populate(this);
}
// TODO : EMBEDDED

@@ -382,3 +404,2 @@ //

var defVal = typeof(def) === 'function' ? def() : def;
this._values[schemaProp] = defVal; // TODO: Wait... should we be assigning it here?
return defVal;

@@ -385,0 +406,0 @@ } else if (schemaProp === '_id') {

@@ -354,3 +354,3 @@ "use strict";

for (var i = 0; i < instancesArray.length; i++) {
if (datasArray[i].hasOwnProperty('_id')) {
if (datasArray[i] && datasArray[i].hasOwnProperty('_id')) {
instancesArray[i].id = datasArray[i]._id;

@@ -357,0 +357,0 @@ } else {

{
"name": "camouflage",
"version": "0.8.7",
"version": "0.8.8",
"description": "A class-based ES6 ODM for Mongo-like databases.",

@@ -5,0 +5,0 @@ "author": {

@@ -73,3 +73,3 @@ "use strict";

expect(d.mod).to.be.a('object');
expect(d.mod instanceof EmbeddedModel).to.be.true;
expect(d.mod).to.be.an.instanceof(EmbeddedModel);
expect(d.mod.str).to.be.equal('some data');

@@ -76,0 +76,0 @@ }).then(done, done);

Sorry, the diff of this file is not supported yet

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