@synatic/mongo-magic
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -109,6 +109,7 @@ const ObjectID = require('mongodb').ObjectId; | ||
* @param {object[]} aggregate - the aggregate to get paths for | ||
* @param {boolean} throwErrorOnUnsafe - Specifies if the library should throw an error when the aggregation pipeline is unsafe | ||
* @return {object[]} - the paths nad collection names | ||
* @throws | ||
*/ | ||
static cleanAggregate(aggregate) { | ||
static cleanAggregate(aggregate, throwErrorOnUnsafe=true) { | ||
if (!$check.array(aggregate)) { | ||
@@ -128,2 +129,5 @@ throw new Error('Invalid aggregate array'); | ||
unsafe = true; | ||
if(throwErrorOnUnsafe){ | ||
throw new Error(`Unsafe function "${invalidAggr.name}" in pipeline:\n${JSON.stringify(pipeline, null, 4)}`); | ||
} | ||
break; | ||
@@ -151,3 +155,3 @@ } | ||
for (const invalidAggr of _unsafeAggregateFunctions) { | ||
if (path.indexOf('/' + invalidAggr.name)>-1) { | ||
if (path.endsWith('/'+invalidAggr.name) || path.indexOf('/' + invalidAggr.name+'/') > -1) { | ||
unsafe = path; | ||
@@ -159,3 +163,3 @@ break; | ||
if (unsafe) { | ||
throw new Error(`Unsafe functions at: ${unsafe}`); | ||
throw new Error(`Unsafe functions at path: ${unsafe}\nPipeline:\n${JSON.stringify(newAggr, null, 4)}`); | ||
} | ||
@@ -162,0 +166,0 @@ |
{ | ||
"name": "@synatic/mongo-magic", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "mongo magic utils", | ||
@@ -61,3 +61,3 @@ "main": "index.js", | ||
"eslint-config-prettier": "^8.5.0", | ||
"mocha": "^9.2.2", | ||
"mocha": "^10.0.0", | ||
"nyc": "^15.1.0", | ||
@@ -64,0 +64,0 @@ "prettier": "^2.5.1" |
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
31184
725