@oridune/epic-odm
Advanced tools
Comparing version 1.0.65 to 1.0.66
{ | ||
"name": "@oridune/epic-odm", | ||
"version": "1.0.65", | ||
"version": "1.0.66", | ||
"description": "Install 1 ODM and code once with any database driver.", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -154,51 +154,36 @@ "use strict"; | ||
break; | ||
case "SetTo": | ||
Results["$set"] = { | ||
[Key]: Target.Value, | ||
case "IsArrayEmpty": | ||
Results[Key] = { | ||
$in: [null, []], | ||
}; | ||
break; | ||
case "NotArrayEmpty": | ||
Results[Key] = { | ||
$exists: true, | ||
$not: { $size: 0 }, | ||
}; | ||
break; | ||
case "PushToSet": | ||
Results["$addToSet"] = { | ||
[Key]: { | ||
Results["$addToSet"] = Object.assign(Object.assign({}, Results["$addToSet"]), { [Key]: { | ||
$each: Target.Value instanceof Array | ||
? Target.Value | ||
: [Target.Value], | ||
}, | ||
}; | ||
} }); | ||
break; | ||
case "Push": | ||
Results["$set"] = { | ||
[Key]: { | ||
$each: Target.Value instanceof Array | ||
? Target.Value | ||
: [Target.Value], | ||
}, | ||
Results[Key] = { | ||
$each: Target.Value instanceof Array | ||
? Target.Value | ||
: [Target.Value], | ||
}; | ||
break; | ||
case "Increment": | ||
Results["$inc"] = { | ||
[Key]: Target.Value, | ||
}; | ||
Results["$inc"] = Object.assign(Object.assign({}, Results["$inc"]), { [Key]: Target.Value }); | ||
break; | ||
case "Decrement": | ||
Results["$inc"] = { | ||
[Key]: -Target.Value, | ||
}; | ||
Results["$inc"] = Object.assign(Object.assign({}, Results["$inc"]), { [Key]: -Target.Value }); | ||
break; | ||
case "ReplaceWith": | ||
Results["$replaceWith"] = { | ||
[Key]: Target.Value, | ||
}; | ||
Results["$replaceWith"] = Object.assign(Object.assign({}, Results["$replaceWith"]), { [Key]: Target.Value }); | ||
break; | ||
case "IsArrayEmpty": | ||
Results[Key] = { | ||
$in: [null, []], | ||
}; | ||
break; | ||
case "NotArrayEmpty": | ||
Results[Key] = { | ||
$exists: true, | ||
$not: { $size: 0 }, | ||
}; | ||
break; | ||
default: | ||
@@ -454,2 +439,3 @@ Results[Key] = Target.Value; | ||
const Dataset = merge ? TransposeToNative([data])[0] : data; | ||
// Separate Incrementor | ||
const Incrementor = typeof Dataset["$inc"] === "object" | ||
@@ -459,3 +445,9 @@ ? { $inc: Dataset["$inc"] } | ||
delete Dataset["$inc"]; | ||
const Set = Object.keys(Dataset).length ? { $set: Dataset } : undefined; | ||
// Separate Set Pusher | ||
const PushToSet = typeof Dataset["$addToSet"] === "object" | ||
? { $addToSet: Dataset["$addToSet"] } | ||
: undefined; | ||
delete Dataset["$addToSet"]; | ||
// Separete Setter | ||
const Setter = Object.keys(Dataset).length ? { $set: Dataset } : undefined; | ||
// Create New Document | ||
@@ -465,3 +457,3 @@ const Results = await (await this.getConnectionObject()) | ||
.collection(ModelOptions.getResolvedName()) | ||
.updateMany({ _id: { $in: targets.map((_) => _._id) } }, Object.assign(Object.assign({}, Set), Incrementor), { session: connection }); | ||
.updateMany({ _id: { $in: targets.map((_) => _._id) } }, Object.assign(Object.assign(Object.assign({}, Setter), PushToSet), Incrementor), { session: connection }); | ||
return { updatedCount: Results.modifiedCount }; | ||
@@ -468,0 +460,0 @@ } |
117584
2441