@filepounder/mongo-magic
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -7,3 +7,3 @@ const $merge = require('deepmerge'); | ||
const oDataParser = require('./oDataParser.js'); | ||
const utils=require('./utils.js') | ||
const _defaultLimit = 50; | ||
@@ -61,3 +61,3 @@ | ||
if ($check.object(obj[key])&&!$mongo.ObjectID.isValid(obj[key])){ | ||
if ($check.object(obj[key])&&!utils.isValidId(obj[key])){ | ||
mergeRawQueryRecursive(obj[key], obj, key); | ||
@@ -71,6 +71,4 @@ } else if($check.array(obj[key])){ | ||
parent[parentKey] = new Date(obj[key]); | ||
} else if (key === "$objectId"&&$check.string(obj[key])) { | ||
parent[parentKey] = new $mongo.ObjectID(obj[key]); | ||
}else if (key === "$objectId"&&$mongo.ObjectID.isValid(obj[key])) { | ||
parent[parentKey] = obj[key]; | ||
} else if (key === "$objectId"&&utils.isValidId(obj[key])) { | ||
parent[parentKey] = utils.parseId(obj[key]); | ||
} | ||
@@ -77,0 +75,0 @@ else if (key === "$int") { |
const ObjectID = require('mongodb').ObjectID; | ||
const $check=require('check-types'); | ||
@@ -11,2 +12,7 @@ class Utils{ | ||
} | ||
if ($check.object(id)&&id._bsontype==="ObjectID"&&Buffer.isBuffer(id.id)&&id.id.length===12){ | ||
return ObjectID.isValid(id.id); | ||
} | ||
if (id.toString().length !== 24) { | ||
@@ -18,8 +24,21 @@ return false; | ||
} | ||
static parseId (id) { | ||
if (Utils.isValidId(id)) { | ||
return new ObjectID(id.toString()); | ||
} else { | ||
if (!id) { | ||
return false; | ||
} | ||
if ($check.object(id)&&id._bsontype==="ObjectID"&&Buffer.isBuffer(id.id)&&id.id.length===12){ | ||
return new ObjectID(id.id); | ||
} | ||
if (id.toString().length !== 24) { | ||
return null; | ||
} | ||
if (ObjectID.isValid(id.toString())){ | ||
return new ObjectID(id.toString()); | ||
} | ||
} | ||
@@ -26,0 +45,0 @@ } |
{ | ||
"name": "@filepounder/mongo-magic", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "mongo magic utils", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18458
379