@allbin/entity-logic
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -9,2 +9,5 @@ import { Entity, EntitySchema } from './types/schema'; | ||
declare const validateSchema: (schema: EntitySchema) => void; | ||
interface ValidatePropertiesModifiableOptions { | ||
strict?: boolean; | ||
} | ||
interface EntityLogic { | ||
@@ -16,3 +19,3 @@ execute: <T>(entities: Entity<T>[], filter: Filter) => Entity<T>[]; | ||
validateProperties: (properties: Record<string, unknown>) => void; | ||
validatePropertiesModifiable: (prev_properties: Record<string, unknown>, properties: Record<string, unknown>) => void; | ||
validatePropertiesModifiable: (prev_properties: Record<string, unknown>, properties: Record<string, unknown>, options?: ValidatePropertiesModifiableOptions) => void; | ||
serializeFilterCondition: (condition: FilterCondition) => SerializedFilterCondition; | ||
@@ -19,0 +22,0 @@ unserializeFilterCondition: (condition: SerializedFilterCondition) => FilterCondition; |
@@ -326,3 +326,3 @@ "use strict"; | ||
}; | ||
var validatePropertiesModifiable = function (schemaPropsByKey, prev_properties, properties) { | ||
var validatePropertiesModifiable = function (schemaPropsByKey, prev_properties, properties, options) { | ||
Object.keys(schemaPropsByKey) | ||
@@ -335,2 +335,6 @@ .filter(function (p) { return !schemaPropsByKey[p].modifiable; }) | ||
} | ||
if ((options === null || options === void 0 ? void 0 : options.strict) && | ||
Object.prototype.hasOwnProperty.call(properties, p)) { | ||
throw new Error("Property '" + p + "' is not modifiable and must not be included in updates"); | ||
} | ||
var invalid = false; | ||
@@ -423,3 +427,5 @@ var prev_val = prev_properties[p]; | ||
}, | ||
validatePropertiesModifiable: function (prev_properties, properties) { return validatePropertiesModifiable(propsByKey, prev_properties, properties); }, | ||
validatePropertiesModifiable: function (prev_properties, properties, options) { | ||
return validatePropertiesModifiable(propsByKey, prev_properties, properties, options); | ||
}, | ||
serializeFilterCondition: function (condition) { | ||
@@ -426,0 +432,0 @@ return serializeFilterCondition(condition); |
@@ -1216,2 +1216,14 @@ "use strict"; | ||
}); | ||
it('rejects unmodifiable properties altogether, in strict mode', function () { | ||
var prev_props = { | ||
'meta.id': 'something', | ||
}; | ||
var props = { | ||
'meta.id': 'something', | ||
}; | ||
var logic = (0, index_1.EntityLogic)(schema); | ||
expect(function () { | ||
return logic.validatePropertiesModifiable(prev_props, props, { strict: true }); | ||
}).toThrow(); | ||
}); | ||
it('correctly validates modifiable single properties (pos)', function () { | ||
@@ -1218,0 +1230,0 @@ var prev_props = { |
{ | ||
"name": "@allbin/entity-logic", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Logic solver for mobilix filters", | ||
@@ -5,0 +5,0 @@ "main": "lib/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
88922
2405