Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-rewrite

Package Overview
Dependencies
Maintainers
1
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-rewrite - npm Package Compare versions

Comparing version 4.3.4 to 4.4.0

4

lib/module/plugin.js

@@ -19,2 +19,3 @@ "use strict";

requires: Joi.array().items(Joi.string()),
contextSchema: Joi.alternatives(Joi.object(), Joi.array(), Joi.function()).optional(),
init: Joi.function().optional(),

@@ -28,2 +29,3 @@ fn: Joi.function(),

requires,
contextSchema,
init,

@@ -71,2 +73,4 @@ fn,

self.contextSchema = contextSchema === undefined ? () => true : validationCompile(contextSchema, false);
self.options = options;
return self;

@@ -73,0 +77,0 @@ };

8

lib/module/plugin/validation-compile.js

@@ -5,3 +5,3 @@ "use strict";

const validationCompile = input => {
const validationCompile = (input, strict = true) => {
if (typeof input === 'function') {

@@ -12,3 +12,3 @@ return input;

if (Array.isArray(input)) {
const compiled = input.map(v => validationCompile(v));
const compiled = input.map(v => validationCompile(v, strict));
return r => Array.isArray(r) && r.every(e => compiled.some(v => v(e) === true));

@@ -18,6 +18,6 @@ }

assert(input instanceof Object);
const compiled = Object.entries(input).map(([k, v]) => [k, validationCompile(v)]);
return r => r instanceof Object && !Array.isArray(r) && Object.keys(r).length === compiled.length && compiled.every(([k, v]) => v(r[k]) === true);
const compiled = Object.entries(input).map(([k, v]) => [k, validationCompile(v, strict)]);
return r => r instanceof Object && !Array.isArray(r) && (strict === false || Object.keys(r).length === compiled.length) && compiled.every(([k, v]) => v(r[k]) === true);
};
module.exports = validationCompile;

@@ -17,3 +17,3 @@ "use strict";

module.exports = (pluginMap, dataStoreFields_) => {
module.exports = (pluginMap, dataStoreFields_, logger = console) => {
assert(pluginMap instanceof Object && !Array.isArray(pluginMap));

@@ -61,3 +61,3 @@ assert(Array.isArray(dataStoreFields_) && dataStoreFields_.every(e => typeof e === 'string'));

context,
injectMap: initPluginMap(injectMap, context),
injectMap: initPluginMap(injectMap, context, logger),
promises: []

@@ -71,7 +71,7 @@ });

context,
filterMap: initPluginMap(filterMap, context)
filterMap: initPluginMap(filterMap, context, logger)
});
sortRewriter(input, {
context,
sortMap: initPluginMap(sortMap, context),
sortMap: initPluginMap(sortMap, context, logger),
lookups: []

@@ -78,0 +78,0 @@ });

"use strict";
module.exports = (map, context) => {
module.exports = (map, context, logger) => {
const result = {};

@@ -9,3 +9,13 @@ const plugins = new Map();

if (!plugins.has(pl.self)) {
plugins.set(pl.self, pl.self.init(context));
const validContext = pl.self.contextSchema(context);
if (!validContext) {
logger.warn(`Context validation failure\n${JSON.stringify({
origin: 'object-rewrite',
options: pl.self.options
})}`);
plugins.set(pl.self, false);
} else {
plugins.set(pl.self, pl.self.init(context));
}
}

@@ -12,0 +22,0 @@

{
"name": "object-rewrite",
"version": "4.3.4",
"version": "4.4.0",
"description": "Rewrite Object(s) in place using plugins.",

@@ -12,3 +12,3 @@ "main": "lib/index.js",

"lodash.set": "4.3.2",
"object-fields": "2.0.19",
"object-fields": "2.0.20",
"object-scan": "13.7.1"

@@ -32,3 +32,3 @@ },

"eslint-plugin-mocha": "8.0.0",
"js-gardener": "2.0.182",
"js-gardener": "2.0.183",
"lodash.get": "4.4.2",

@@ -35,0 +35,0 @@ "nyc": "15.1.0",

@@ -75,2 +75,3 @@ # object-rewrite

- `init({ context, cache })` _Function_ (optional): if present called once per run, if returns other than `true`, the plugin is disabled for the run
- `contextSchema`: Object schema structure of what is expected to be present in `context` (subset)

@@ -91,3 +92,3 @@ where:

- `fn`: return value is used for target. Relative to prefix
- `schema`: Joi schema or object containing schema values of what is being injected
- `schema`: Object schema structure of what is being injected (strict result of `fn`)

@@ -94,0 +95,0 @@ ### Filter Plugin

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc