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

p-odm

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-odm - npm Package Compare versions

Comparing version 3.1.2 to 3.1.3

examples/validator.js

5

lib/index.js

@@ -70,4 +70,7 @@ 'use strict';

_collections = {};
_safeOptions = extractOption('safe', options);
_safeOptions = extractOption('safe', options, true);
// enable safe by default
_options.db = {safe: _safeOptions};
if (callback !== undefined) {

@@ -74,0 +77,0 @@ mongodb.connect(_url, _options, function (err, db) {

71

lib/protos/freemodel.js

@@ -448,31 +448,9 @@ /**

BaseModel[methodName] = function (id, fields, options, callback) {
var hasFields = true;
var isUnique = false;
if (callback === undefined) {
if (options === undefined) {
callback = fields;
options = {};
fields = {};
hasFields = false;
} else {
callback = options;
options = fields;
fields = {};
hasFields = false;
}
}
if (options.unique !== undefined && options.unique === true) {
isUnique = true;
}
if (!mongoCollection) {
return callback('Cannot ' + methodName + ' on embedded model');
}
var pluck = extractOption('pluck', options);
if (pluck !== undefined) {
// state that we only care about the plucked field
fields[pluck] = true;
hasFields = true;
}
BaseModel[methodName] = function (id, fields, options, callback) {
if (id === undefined) {

@@ -482,35 +460,10 @@ return callback('undefined id');

var includeNotFound = true;
if (options.unique !== undefined && options.unique === true) {
includeNotFound = false;
}
var query = {};
query[field] = id;
return odm.findOne(mongoCollection, query, fields, options, function (err, documentLoaded) {
if (err) {
return callback(err);
}
// if we search for an Id and get null it should return right away
if (documentLoaded === null) {
if (includeNotFound) {
return callback(null, null);
} else {
return callback(mongoCollection + ' ' + id + ' not found');
}
}
if (hasFields) {
if (pluck !== undefined) {
documentLoaded = documentLoaded[pluck];
}
return callback(null, documentLoaded);
}
documentLoaded[PROTO] = BaseModel.prototype;
return callback(null, documentLoaded);
});
if (isUnique) {
return BaseModel.findOne(query, fields, options, callback);
} else {
return BaseModel.find(query, fields, options, callback);
}
};

@@ -562,2 +515,3 @@ }

* @memberOf BaseModel.prototype
* @param {Object} [partUpdate] partial update
* @param {Object} [options] options for the query

@@ -719,2 +673,3 @@ * @param {Function} callback Callback function (error, documentId) with the result of the operation

* @memberOf BaseModel
* @param {Object} document document to save
* @param {Object|Function} [options] options for the query

@@ -737,2 +692,3 @@ * @param {Function} callback Callback function (error, documentId) with the result of the operation

* @memberOf BaseModel
* @param {Object} document document to insert
* @param {Object} [options] options for the query

@@ -756,2 +712,3 @@ * @param {Function} callback Callback function (error, documentId) with the result of the operation

* @param {Object} query Search query of objects to remove
* @param {Object} document document to update the existing one
* @param {Object} [options] options for the query

@@ -758,0 +715,0 @@ * @param {Function} callback Callback function (error) with the result of the operation

@@ -551,27 +551,9 @@ /**

SchemaModel[methodName] = function (id, fields, options, callback) {
var hasFields = true;
var isUnique = false;
if (callback === undefined) {
if (options === undefined) {
callback = fields;
options = {};
fields = {};
hasFields = false;
} else {
callback = options;
options = fields;
fields = {};
hasFields = false;
}
}
if (options.unique !== undefined && options.unique === true) {
isUnique = true;
}
var pluck = extractOption('pluck', options);
if (pluck !== undefined) {
// state that we only care about the plucked field
fields[pluck] = true;
hasFields = true;
}
SchemaModel[methodName] = function (id, fields, options, callback) {
if (id === undefined) {

@@ -581,37 +563,10 @@ return callback('undefined id');

var includeNotFound = true;
if (options.unique !== undefined && options.unique === true) {
includeNotFound = false;
}
var query = {};
query[field] = id;
return odm.findOne(mongoCollection, query, fields, options, function (err, documentLoaded) {
if (err) {
return callback(err);
}
// clean up
query = null;
// if we search for an Id and get null it should return right away
if (documentLoaded === null) {
if (includeNotFound) {
return callback(null, null);
} else {
return callback(mongoCollection + ' ' + id + ' not found');
}
}
if (hasFields) {
if (pluck !== undefined) {
documentLoaded = documentLoaded[pluck];
}
} else {
documentLoaded[PROTO] = SchemaModel.prototype;
}
return callback(null, documentLoaded);
});
if (isUnique) {
return SchemaModel.findOne(query, fields, options, callback);
} else {
return SchemaModel.find(query, fields, options, callback);
}
};

@@ -668,2 +623,3 @@ }

* @memberOf SchemaModel.prototype
* @param {Object} [partUpdate] update statement
* @param {Object} [options] options for the query

@@ -670,0 +626,0 @@ * @param {Function} callback Callback function (error, documentId) with the result of the operation

@@ -8,3 +8,3 @@ {

],
"version": "3.1.2",
"version": "3.1.3",
"engines": {

@@ -14,4 +14,4 @@ "node": ">=0.4.12"

"dependencies": {
"mongodb": "1.1.7",
"jsonschema": "0.1.2"
"mongodb": "1.1.11",
"jsonschema": "0.1.3"
},

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