Socket
Socket
Sign inDemoInstall

@json-schema-tools/traverse

Package Overview
Dependencies
0
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.9.0 to 1.10.0

3

build/index.d.ts

@@ -8,4 +8,5 @@ import { JSONSchema } from "@json-schema-tools/meta-schema";

* @param path json-path string in dot-notation as per [draft-goessner-dispatch-jsonpath-00](https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html#name-overview-of-jsonpath-expres)
* @param parent if the schema is the root, this will be the same as `schema`. Otherwise, it will be a reference to JSONSchema that is the parent.
*/
export declare type MutationFunction = (schema: JSONSchema, isCycle: boolean, path: string) => JSONSchema;
export declare type MutationFunction = (schema: JSONSchema, isCycle: boolean, path: string, parent: JSONSchema) => JSONSchema;
/**

@@ -12,0 +13,0 @@ * The options you can use when traversing.

@@ -46,2 +46,7 @@ "use strict";

};
var last = function (i, skipTwo) {
if (skipTwo === void 0) { skipTwo = false; }
var skip = skipTwo ? -2 : -1;
return i[i.length - skip];
};
/**

@@ -78,3 +83,3 @@ * Traverse all subschema of a schema, calling the mutator function with each.

else {
return mutation(schema, false, jsonPathStringify(pathStack));
return mutation(schema, false, jsonPathStringify(pathStack), last(recursiveStack) || schema);
}

@@ -88,3 +93,3 @@ }

if (opts.skipFirstMutation === false || depth !== 0) {
mutableSchema = mutation(mutableSchema, false, jsonPathStringify(pathStack));
mutableSchema = mutation(mutableSchema, false, jsonPathStringify(pathStack), last(recursiveStack) || schema);
}

@@ -101,3 +106,3 @@ }

if (opts.skipFirstMutation === true && foundCycle === recursiveStack[0]) {
return mutation(s, true, jsonPathStringify(path));
return mutation(s, true, jsonPathStringify(path), last(recursiveStack, true) || schema);
}

@@ -145,3 +150,3 @@ var _a = prePostMap.find(function (_a) {

if (opts.skipFirstMutation === true && foundCycle_1 === recursiveStack[0]) {
mutableSchema.items = mutation(schema.items, true, jsonPathStringify(pathStack));
mutableSchema.items = mutation(schema.items, true, jsonPathStringify(pathStack), last(recursiveStack, true) || schema);
}

@@ -193,5 +198,5 @@ else {

var isCycle_1 = cycleSet.indexOf(schema) !== -1;
return mutation(mutableSchema, isCycle_1, jsonPathStringify(pathStack));
return mutation(mutableSchema, isCycle_1, jsonPathStringify(pathStack), last(recursiveStack, true) || schema);
}
}
exports.default = traverse;
{
"name": "@json-schema-tools/traverse",
"version": "1.9.0",
"version": "1.10.0",
"description": "This package exports a method that will traverse a JSON-Schema, calling a mutation function for each sub schema found. It is useful for building tools to work with JSON Schemas.",

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

@@ -21,3 +21,3 @@ # JSON Schema Traverse

- optional mutability (toggle updating original schema object)
- returns paths as it traverses
- returns [JSONPaths](https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html) as it traverses

@@ -24,0 +24,0 @@ ## Getting Started

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc