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 8.0.0 to 9.0.0

21

lib/module/plugin.js

@@ -22,3 +22,4 @@ "use strict";

valueSchema: Joi.alternatives(Joi.object(), Joi.array(), Joi.function()).optional(),
active: Joi.function().optional(),
onInit: Joi.function().optional(),
onRewrite: Joi.function().optional(),
fn: Joi.function(),

@@ -34,3 +35,4 @@ fnSchema: type === 'INJECT' ? Joi.alternatives(Joi.object(), Joi.array(), Joi.function()) : Joi.forbidden(),

valueSchema,
active,
onInit,
onRewrite,
fn,

@@ -139,3 +141,13 @@ fnSchema,

contextSchema,
active: (context, logger) => {
onInit: initContext => {
localCache = {};
localContext = initContext;
if (onInit === undefined) {
return true;
}
return wrap(onInit)();
},
onRewrite: (data, context, logger) => {
if (contextSchemaCompiled(context) === false) {

@@ -149,3 +161,2 @@ logger.warn(`Context validation failure\n${JSON.stringify({

localCache = {};
localContext = contextSchema instanceof Object && !Array.isArray(contextSchema) ? Object.keys(contextSchema).reduce((p, k) => {

@@ -156,3 +167,3 @@ // eslint-disable-next-line no-param-reassign

}, {}) : context;
return active === undefined ? true : wrap(active)();
return onRewrite === undefined ? true : wrap(onRewrite)();
}

@@ -159,0 +170,0 @@ };

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

} = injectRewriter(input, {
injectMap: initPluginMap(injectMap, context, logger),
injectMap: initPluginMap(injectMap, input, context, logger),
promises: []

@@ -77,6 +77,6 @@ });

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

@@ -90,3 +90,6 @@ });

activePlugins,
rewrite: (input, context = {}) => {
rewrite: (input, context_ = {}) => {
const context = { ...context_,
...initContext
};
const promises = rewriteStart(input, context);

@@ -96,3 +99,6 @@ assert(promises.length === 0, 'Please use rewriteAsync() for async logic');

},
rewriteAsync: async (input, context = {}) => {
rewriteAsync: async (input, context_ = {}) => {
const context = { ...context_,
...initContext
};
const promises = rewriteStart(input, context);

@@ -99,0 +105,0 @@ await Promise.all(promises.map(p => p()));

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

};
const activeLookup = new Map();
const activePlugins = new Set();

@@ -23,3 +24,7 @@ const inactivePlugins = [...plugins];

if (plugin.targets.includes(field) || (plugin.type !== 'INJECT' || plugin.targetRel === '*') && (`${field}.` === plugin.target || field.startsWith(plugin.target))) {
if (!activeLookup.has(plugin.self)) {
activeLookup.set(plugin.self, plugin.self.meta.onInit(initContext));
}
if (activeLookup.get(plugin.self) === true && (plugin.targets.includes(field) || (plugin.type !== 'INJECT' || plugin.targetRel === '*') && (`${field}.` === plugin.target || field.startsWith(plugin.target)))) {
const requires = [...plugin.requires(initContext)];

@@ -26,0 +31,0 @@

"use strict";
module.exports = (map, context, logger) => {
module.exports = (map, data, context, logger) => {
const result = {};
const plugins = new Map();
const activeLookup = new Map();
Object.entries(map).forEach(([prefix, pls]) => {
result[prefix] = pls.filter(pl => {
if (!plugins.has(pl.self)) {
plugins.set(pl.self, pl.self.meta.active(context, logger));
if (!activeLookup.has(pl.self)) {
activeLookup.set(pl.self, pl.self.meta.onRewrite(data, context, logger));
}
return plugins.get(pl.self) === true;
return activeLookup.get(pl.self) === true;
});

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

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

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -74,4 +74,5 @@ # object-rewrite

- `fn` _Function_: result of this function is used by the plugin. Signature is `fn({ key, value, parents, context, cache })`.
- `active({ 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)
- `onInit({ context, cache })` _Function_ (optional): if present called once per init, used to initialize cache, if returns other than `true`, the plugin is disabled
- `onRewrite({ data, context, cache })` _Function_ (optional): if present called once per rewrite, used to update cache, if returns other than `true`, the plugin is disabled
- `contextSchema`: Object schema structure of what is expected to be present in rewrite `context` (subset)
- `valueSchema` (optional): Used to validate value before passed into `fn`

@@ -78,0 +79,0 @@

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