xpress-mongo
Advanced tools
Comparing version 0.10.0 to 0.10.1
{ | ||
"name": "xpress-mongo", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "Light Weight ODM for mongoDb", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -465,3 +465,5 @@ "use strict"; | ||
else { | ||
// Resolve | ||
resolve(res.connection); | ||
// Run Watch Event | ||
inbuilt_1.RunOnEvent("watch", this, changes); | ||
@@ -488,4 +490,6 @@ } | ||
this.$setOriginal(this.data); | ||
// resolve | ||
resolve(res); | ||
// Run on created event | ||
inbuilt_1.RunOnEvent("created", this); | ||
return resolve(res); | ||
}); | ||
@@ -1110,8 +1114,10 @@ } | ||
throw Error(`${modelName}.on("${event}") is deprecated. Use "deleted" instead.`); | ||
const handlerIsFunction = typeof functionOrFunctions === "function"; | ||
// Validate events that must be a function | ||
if (["deleted", "created"].includes(event) && typeof functionOrFunctions !== "function") { | ||
if (["deleted", "created"].includes(event) && !handlerIsFunction) { | ||
throw Error(`${modelName}.on("${event}") event must be type of Function.`); | ||
} | ||
const handlerIsObject = typeof functionOrFunctions === "object"; | ||
// watch when not using dot notation must be an object | ||
if (event === "watch" && typeof functionOrFunctions !== "object") { | ||
if (event === "watch" && !handlerIsObject) { | ||
throw Error(`${modelName}.on("watch") event must be type of Object.`); | ||
@@ -1123,2 +1129,5 @@ } | ||
if (event.includes(".")) { | ||
if (!handlerIsFunction) { | ||
throw Error(`Event handler for DOT notated events must be a function. {event:"${event}"}`); | ||
} | ||
// Split . | ||
@@ -1128,3 +1137,3 @@ const dots = event.split("."); | ||
if (dots.length > 2) { | ||
throw Error(`Model events supports only first level Field names when using dot notation. {event:"${event}"}`); | ||
throw Error(`Model events supports only first level Field names when using DOT notation. {event:"${event}"}`); | ||
} | ||
@@ -1135,3 +1144,3 @@ else if (dots.length === 2) { | ||
if (!["create", "update", "watch"].includes(main)) { | ||
throw Error(`${modelName}.on("${main}") does not support dot notation. {event:"${event}"}`); | ||
throw Error(`${modelName}.on("${main}") does not support DOT notation. {event:"${event}"}`); | ||
} | ||
@@ -1144,3 +1153,8 @@ } | ||
// Merge to events | ||
_.merge(this.events, _.set({}, event, functionOrFunctions)); | ||
if (handlerIsObject) { | ||
_.merge(this.events, _.extend({}, { [event]: functionOrFunctions })); | ||
} | ||
else { | ||
_.merge(this.events, _.set({}, event, functionOrFunctions)); | ||
} | ||
} | ||
@@ -1147,0 +1161,0 @@ /** |
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
83863
2617