object-rewrite
Advanced tools
Comparing version 5.0.0 to 6.0.0
@@ -21,5 +21,6 @@ "use strict"; | ||
contextSchema: Joi.alternatives(Joi.object(), Joi.array(), Joi.function()).optional(), | ||
valueSchema: Joi.alternatives(Joi.object(), Joi.array(), Joi.function()).optional(), | ||
init: Joi.function().optional(), | ||
fn: Joi.function(), | ||
schema: type === 'INJECT' ? Joi.alternatives(Joi.object(), Joi.array(), Joi.function()) : Joi.forbidden(), | ||
fnSchema: type === 'INJECT' ? Joi.alternatives(Joi.object(), Joi.array(), Joi.function()) : Joi.forbidden(), | ||
limit: type === 'SORT' ? Joi.function().optional() : Joi.forbidden() | ||
@@ -32,7 +33,9 @@ })); | ||
contextSchema, | ||
valueSchema, | ||
init, | ||
fn, | ||
schema, | ||
fnSchema, | ||
limit | ||
} = options; | ||
const contextSchemaCompiled = contextSchema === undefined ? () => true : validationCompile(contextSchema, false); | ||
let localCache; | ||
@@ -55,2 +58,23 @@ let localContext; | ||
const fnWrapped = (() => { | ||
const wrapped = wrap(fn); | ||
if (valueSchema === undefined) { | ||
return wrapped; | ||
} | ||
const valueSchemaCompiled = validationCompile(valueSchema, false); | ||
return kwargs => { | ||
if (valueSchemaCompiled(kwargs.value) !== true) { | ||
throw new Error(`Value Schema validation failure\n${JSON.stringify({ | ||
origin: 'object-rewrite', | ||
value: kwargs.value, | ||
options | ||
})}`); | ||
} | ||
return wrapped(kwargs); | ||
}; | ||
})(); | ||
const self = prefix => { | ||
@@ -68,3 +92,3 @@ const targetAbs = joinPath([prefix, target]); | ||
type, | ||
fn: wrap(fn), | ||
fn: fnWrapped, | ||
limit: wrap(limit) | ||
@@ -75,4 +99,4 @@ }; | ||
result.targetNormalized = prefix; | ||
result.schema = validationCompile(schema); | ||
result.targets = validationExtractKeys(targetAbs, schema); | ||
result.fnSchema = validationCompile(fnSchema); | ||
result.targets = validationExtractKeys(targetAbs, fnSchema); | ||
} | ||
@@ -86,3 +110,3 @@ | ||
init: (context, logger) => { | ||
if (contextSchema !== undefined && validationCompile(contextSchema, false)(context) === false) { | ||
if (contextSchemaCompiled(context) === false) { | ||
logger.warn(`Context validation failure\n${JSON.stringify({ | ||
@@ -89,0 +113,0 @@ origin: 'object-rewrite', |
@@ -36,3 +36,3 @@ "use strict"; | ||
const exec = r => { | ||
assert(plugin.schema(r) === true); | ||
assert(plugin.fnSchema(r) === true); | ||
@@ -39,0 +39,0 @@ if (plugin.targetRel === '*') { |
{ | ||
"name": "object-rewrite", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Rewrite Object(s) in place using plugins.", | ||
@@ -13,3 +13,3 @@ "main": "lib/index.js", | ||
"object-fields": "2.0.20", | ||
"object-scan": "13.8.0" | ||
"object-scan": "13.9.0" | ||
}, | ||
@@ -26,3 +26,3 @@ "devDependencies": { | ||
"coveralls": "3.1.0", | ||
"eslint": "7.18.0", | ||
"eslint": "7.19.0", | ||
"eslint-config-airbnb-base": "14.2.1", | ||
@@ -29,0 +29,0 @@ "eslint-plugin-import": "2.22.1", |
@@ -76,2 +76,3 @@ # object-rewrite | ||
- `contextSchema`: Object schema structure of what is expected to be present in `context` (subset) | ||
- `valueSchema` (optional): Used to validate value before passed into `fn` | ||
@@ -92,3 +93,3 @@ where: | ||
- `fn`: return value is used for target. Relative to prefix | ||
- `schema`: Object schema structure of what is being injected (strict result of `fn`) | ||
- `fnSchema`: Object schema structure of what is being injected (strict result of `fn`) | ||
@@ -95,0 +96,0 @@ ### Filter Plugin |
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
25267
456
178
+ Addedobject-scan@13.9.0(transitive)
- Removedobject-scan@13.8.0(transitive)
Updatedobject-scan@13.9.0