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 0.0.12 to 0.0.13

107

lib/model.js

@@ -31,3 +31,18 @@ 'use strict';

/**
* Extracts one option from the object and returns it.
* @private
*/
function extractOption(name, options) {
var option;
if (options) {
if (options.hasOwnProperty(name)) {
option = options[name];
delete options[name];
}
}
return option;
}
/**
* @private
* Initialize the model object with the data either from db or from user

@@ -80,3 +95,3 @@ */

// common instance prototype helpers
function isEmptyProto (obj) {
function isEmptyProto(obj) {
if (obj !== undefined && obj !== null) {

@@ -108,3 +123,3 @@ var keys = Object.keys(obj);

function hasOwnPropertyProto (obj, key) {
function hasOwnPropertyProto(obj, key) {
if (obj === undefined || obj === null) {

@@ -324,2 +339,5 @@ return true;

var directObject = extractOption('directObject', options);
var includeNotFound = extractOption('includeNotFound', options);
var _id;

@@ -342,3 +360,3 @@

if (el.hasOwnProperty('_id') && _id.equals(el._id)) {
if (options.directObject) {
if (directObject) {
return callback(null, value[i]);

@@ -351,3 +369,7 @@ }

// not found
callback(null, null);
if (includeNotFound) {
return callback(null, null);
} else {
return callback(_id.toHexString() + ' not found');
}
}

@@ -370,2 +392,4 @@ });

var directObject = extractOption('directObject', options);
for (i = 0; i < value.length; i++) {

@@ -380,3 +404,3 @@ var match = matches(query, value[i]);

if (match === 1) {
if (options.directObject) {
if (directObject) {
result.push(value[i]);

@@ -404,2 +428,3 @@ } else {

var i;
var directObject = extractOption('directObject', options);

@@ -415,3 +440,3 @@ for (i = 0; i < value.length; i++) {

if (match === 1) {
if (options.directObject) {
if (directObject) {
return callback(null, value[i]);

@@ -428,3 +453,3 @@ }

// enhance arrays with basic findOne
// enhance arrays with basic findAll
if (!value.hasOwnProperty('findAll')) {

@@ -441,5 +466,6 @@ Object.defineProperty(value, 'findAll', {

var i;
var directObject = extractOption('directObject', options);
for (i = 0; i < value.length; i++) {
if (options.directObject) {
if (directObject) {
result.push(value[i]);

@@ -482,3 +508,3 @@ } else {

} else {
// enhance arrays with basic find with equality check
// enhance arrays with basic findOne with equality check
if (!value.hasOwnProperty('findOne')) {

@@ -516,2 +542,33 @@ Object.defineProperty(value, 'findOne', {

// enhance arrays with basic find with equality check
if (!value.hasOwnProperty('find')) {
Object.defineProperty(value, 'find', {
value: function (val, options, callback) {
if (callback === undefined) {
callback = options;
options = {};
}
var result = [];
var i;
var hasEquals = val.equals !== undefined && val.equals !== null && typeof(val.equals) === 'function';
for (i = 0; i < value.length; i++) {
if (hasEquals) {
if (val.equals(value[i])) {
result.push(value[i]);
}
} else {
if (val === value[i]) {
result.push(value[i]);
}
}
}
callback(null, result);
}
});
}
// enhance arrays with basic remove with equality check

@@ -992,2 +1049,4 @@ if (!value.hasOwnProperty('remove')) {

var directObject = extractOption('directObject', options);
odm.collection(mongoCollection, options, function (err, collection) {

@@ -1008,3 +1067,3 @@ if (err) {

// special case (return direct document from mongoDB)
if (options.directObject) {
if (directObject) {
return callback(null, documentLoaded);

@@ -1042,2 +1101,4 @@ }

var _id;
var directObject = extractOption('directObject', options);
var includeNotFound = extractOption('includeNotFound', options);

@@ -1062,7 +1123,11 @@ if (id instanceof ObjectID) {

if (cachedDocument === null) {
return callback(null, null);
if (includeNotFound) {
return callback(null, null);
} else {
return callback(mongoCollection + ' ' + _id.toHexString() + ' not found');
}
}
// special case (return direct document from mongoDB)
if (options.directObject) {
if (directObject) {
return callback(null, cachedDocument);

@@ -1092,7 +1157,11 @@ }

if (documentLoaded === null) {
return callback(null, null);
if (includeNotFound) {
return callback(null, null);
} else {
return callback(mongoCollection + ' ' + _id.toHexString() + ' not found');
}
}
// special case (return direct document from mongoDB)
if (options.directObject) {
if (directObject) {
return callback(null, documentLoaded);

@@ -1134,2 +1203,4 @@ }

var directObject = extractOption('directObject', options);
odm.collection(mongoCollection, options, function (err, collection) {

@@ -1149,3 +1220,3 @@ if (err) {

// special case (return direct document from mongoDB)
if (options.directObject) {
if (directObject) {
return callback(null, documentsLoaded);

@@ -1189,2 +1260,4 @@ }

var directObject = extractOption('directObject', options);
// verify if it is in cache

@@ -1197,3 +1270,3 @@ if (l2cache) {

// special case (return direct document from mongoDB)
if (options.directObject) {
if (directObject) {
return callback(null, cachedDocuments);

@@ -1230,3 +1303,3 @@ }

// special case (return direct document from mongoDB)
if (options.directObject) {
if (directObject) {
return callback(null, documentsLoaded);

@@ -1233,0 +1306,0 @@ }

2

package.json

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

],
"version": "0.0.12",
"version": "0.0.13",
"engines": {

@@ -11,0 +11,0 @@ "node": ">=0.4.12"

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