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

cosa

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cosa - npm Package Compare versions

Comparing version 2.6.0 to 2.6.1

12

lib/db.js

@@ -124,3 +124,3 @@ var util = require('util');

});
query = EJSON.deflate(query);
query = EJSON.deserialize(query);
debug('getting db collection');

@@ -148,3 +148,3 @@ return this.collection(collection)

debug('getting db collection');
docs = EJSON.deflate(docs);
docs = EJSON.deserialize(docs);
return this.collection(collection)

@@ -176,4 +176,4 @@ .then(function (collection) {

debug('getting db collection');
query = EJSON.deflate(query);
update = EJSON.deflate(update);
query = EJSON.deserialize(query);
update = EJSON.deserialize(update);
return this.collection(collection)

@@ -205,3 +205,3 @@ .then(function (collection) {

debug('getting db collection');
query = EJSON.deflate(query);
query = EJSON.deserialize(query);
return this.collection(collection)

@@ -246,3 +246,3 @@ .then(function (collection) {

debug('getting db collection');
query = EJSON.deflate(query);
query = EJSON.deserialize(query);
return this.collection(collection)

@@ -249,0 +249,0 @@ .then(function (collection) {

@@ -269,3 +269,3 @@ var q = require('q');

var val = def.virtuals[name].call(obj);
obj[name] = val && 'function' === typeof val.toJSON ? val.toJSON() : val;
obj[name] = val;
}.bind(this));

@@ -283,14 +283,9 @@ }

delete json.__original;
if (options.extended) {
json = EJSON.inflate(json);
} else {
for (var p in json) {
if (json[p] && 'function' === typeof json[p].toJSON) {
json[p] = json[p].toJSON();
}
}
}
if (options.virtuals) {
addVirtuals(definition, json);
}
if (options.extended) {
json = EJSON.serialize(json);
}
json = _serialize(json);
return json;

@@ -336,3 +331,3 @@ };

.then(function (value) {
var obj = EJSON.inflate(value);
var obj = EJSON.serialize(value);
var original = obj.__original;

@@ -519,3 +514,25 @@ delete obj.__modified;

return schema;
}
function _serializeArray (arr) {
return arr.map(_serialize.bind(null));
}
function _serializeObject (obj) {
var newObj = {};
for (var p in obj) {
newObj[p] = _serialize(obj[p]);
}
return newObj;
}
function _serialize (val) {
if (val && 'function' === typeof val.toJSON) {
return val.toJSON();
} else if (Array.isArray(val)) {
return _serializeArray(val);
} else if (typeof val !== 'object') {
return val;
}
return _serializeObject(val);
}
{
"name": "cosa",
"version": "2.6.0",
"version": "2.6.1",
"description": "Cosa Models for MongoDB",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

var chai = require('chai');
var MongoClient = require('mongodb').MongoClient;
var q = require('q');
var bson = require('bson');

@@ -286,4 +287,4 @@ chai.use(require('chai-datetime'));

done();
})
})
});
});

@@ -300,24 +301,48 @@ after(function (done) {

it('should except a virtuals option', function () {
var model = FullTestModel.create({
str: 'foo',
obj: { deep: { blah: 'blah' } }
it('should return valid json', function () {
var DeepArrayModel = Model.define({
collection: 'mocha_test',
properties: {
arr: {
type: 'array',
items: {
type: 'object',
properties: {
oid: { type: 'objectid' }
}
}
}
}
});
model
.save()
.then(function (newModel) {
// console.log(newModel.toJSON({ virtuals: true }));
});
var model = DeepArrayModel.create({
arr: [
{ oid: bson.ObjectId('abdfabdfabdfabdfabdfabdf') },
{ oid: bson.ObjectId('abdfabdfabdfabdfabdfabdf') }
]
});
expect(JSON.stringify(model.toJSON())).to.equal("{\"arr\":[{\"oid\":{\"$oid\":\"abdfabdfabdfabdfabdfabdf\"}},{\"oid\":{\"$oid\":\"abdfabdfabdfabdfabdfabdf\"}}]}");
});
it('should except an extended option', function () {
var model = FullTestModel.create({
str: 'foo',
obj: { deep: { blah: 'blah' } }
var DeepArrayModel = Model.define({
collection: 'mocha_test',
properties: {
arr: {
type: 'array',
items: {
type: 'object',
properties: {
oid: { type: 'objectid' }
}
}
}
}
});
model
.save()
.then(function (newModel) {
// console.log(newModel.toJSON({ extended: false }));
});
var model = DeepArrayModel.create({
arr: [
{ oid: bson.ObjectId('abdfabdfabdfabdfabdfabdf') },
{ oid: bson.ObjectId('abdfabdfabdfabdfabdfabdf') }
]
});
expect(JSON.stringify(model.toJSON({ extended: false }))).to.equal("{\"arr\":[{\"oid\":\"abdfabdfabdfabdfabdfabdf\"},{\"oid\":\"abdfabdfabdfabdfabdfabdf\"}]}");
});

@@ -324,0 +349,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