Skip to content

Commit c793fbd

Browse files
committed
dist: update
1 parent 28c38a1 commit c793fbd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+400
-318
lines changed

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export type { CompileOptions } from "./src/compileSchema";
33
export type { Context, SchemaNode, GetNodeOptions } from "./src/SchemaNode";
44
export type { DataNode } from "./src/methods/toDataNodes";
55
export type { Draft, DraftVersion } from "./src/Draft";
6-
export type { JsonError, JsonPointer, JsonSchema, OptionalNodeAndError } from "./src/types";
6+
export type { JsonError, JsonPointer, JsonSchema, OptionalNodeOrError, NodeOrError } from "./src/types";
77
export type { Keyword, ValidationPath, JsonSchemaReducerParams, JsonSchemaReducer, JsonSchemaResolverParams, JsonSchemaResolver, JsonSchemaValidatorParams, JsonSchemaValidator } from "./src/Keyword";
88
export { draft04 } from "./src/draft04";
99
export { draft06 } from "./src/draft06";

dist/jsonSchemaLibrary.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/module/src/SchemaNode.js

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { toSchemaNodes } from "./methods/toSchemaNodes";
66
import { getValue } from "./utils/getValue";
77
import { isJsonError } from "./types";
88
import { isObject } from "./utils/isObject";
9-
import { join, split } from "@sagold/json-pointer";
9+
import { join } from "@sagold/json-pointer";
1010
import { joinId } from "./utils/joinId";
1111
import { mergeNode } from "./mergeNode";
1212
import { omit } from "./utils/omit";
1313
import { pick } from "./utils/pick";
1414
import { render } from "./errors/render";
1515
import { validateNode } from "./validateNode";
16+
import { hasProperty } from "./utils/hasProperty";
17+
import { getNode } from "./getNode";
1618
const { DYNAMIC_PROPERTIES } = settings;
1719
export function isSchemaNode(value) {
1820
return isObject(value) && Array.isArray(value === null || value === void 0 ? void 0 : value.reducers) && Array.isArray(value === null || value === void 0 ? void 0 : value.resolvers);
@@ -81,70 +83,34 @@ export const SchemaNodeMethods = {
8183
return { type: "error", code, message: errorMessage, data };
8284
},
8385
createSchema,
84-
getChildSchemaSelection(property) {
86+
getChildSelection(property) {
8587
const node = this;
86-
return node.context.methods.getChildSchemaSelection(node, property);
87-
},
88-
/**
89-
* Returns a node containing JSON Schema of a data JSON Pointer.
90-
*
91-
* To resolve dynamic schema where the type of JSON Schema is evaluated by
92-
* its value, a data object has to be passed in options.
93-
*
94-
* Per default this function will return `undefined` schema for valid properties
95-
* that do not have a defined schema. Use the option `withSchemaWarning: true` to
96-
* receive an error with `code: schema-warning` containing the location of its
97-
* last evaluated json-schema.
98-
*
99-
* @returns { node } or { error } where node can also be undefined (valid but undefined)
100-
*/
101-
getNode(pointer, data, options = {}) {
102-
var _a, _b, _c;
103-
options.path = (_a = options.path) !== null && _a !== void 0 ? _a : [];
104-
options.withSchemaWarning = (_b = options.withSchemaWarning) !== null && _b !== void 0 ? _b : false;
105-
options.pointer = (_c = options.pointer) !== null && _c !== void 0 ? _c : "#";
106-
const node = this;
107-
const keys = split(pointer);
108-
if (keys.length === 0) {
109-
const result = node.resolveRef(options);
110-
return isJsonError(result) ? { node: undefined, error: result } : { node: result, error: undefined };
111-
}
112-
let currentPointer = "#";
113-
let currentNode = node;
114-
for (let i = 0, l = keys.length; i < l; i += 1) {
115-
currentPointer = `${currentPointer}/${keys[i]}`;
116-
const result = currentNode.getChild(keys[i], data, { ...options, pointer: currentPointer });
117-
if (result.error) {
118-
return result;
119-
}
120-
if (result.node == null) {
121-
return result;
122-
}
123-
currentNode = result.node;
124-
data = getValue(data, keys[i]);
125-
}
126-
const result = currentNode.resolveRef(options);
127-
return isJsonError(result) ? { node: undefined, error: result } : { node: result, error: undefined };
88+
return node.context.methods.getChildSelection(node, property);
12889
},
90+
getNode,
12991
/**
13092
* @returns for $ref, the corresponding SchemaNode or undefined
13193
*/
132-
getRef($ref) {
94+
getNodeRef($ref) {
13395
const node = this;
13496
return node.compileSchema({ $ref }).resolveRef();
13597
},
98+
getNodeRoot() {
99+
const node = this;
100+
return node.context.rootNode;
101+
},
136102
/**
137103
* @returns child node identified by property as SchemaNode
138104
*/
139-
getChild(key, data, options = {}) {
105+
getNodeChild(key, data, options = {}) {
140106
var _a, _b, _c;
141107
options.path = (_a = options.path) !== null && _a !== void 0 ? _a : [];
142108
options.withSchemaWarning = (_b = options.withSchemaWarning) !== null && _b !== void 0 ? _b : false;
143109
options.pointer = (_c = options.pointer) !== null && _c !== void 0 ? _c : "#";
144110
const { path, pointer } = options;
145111
let node = this;
146112
if (node.reducers.length) {
147-
const result = node.reduceSchema(data, { key, path, pointer });
113+
const result = node.reduceNode(data, { key, path, pointer });
148114
if (result.error) {
149115
return result;
150116
}
@@ -163,7 +129,7 @@ export const SchemaNodeMethods = {
163129
}
164130
const referencedNode = node.resolveRef({ path });
165131
if (referencedNode !== node) {
166-
return referencedNode.getChild(key, data, options);
132+
return referencedNode.getNodeChild(key, data, options);
167133
}
168134
if (options.createSchema === true) {
169135
const newNode = node.compileSchema(createSchema(getValue(data, key)), `${node.spointer}/additional`, `${node.schemaId}/additional`);
@@ -197,7 +163,7 @@ export const SchemaNodeMethods = {
197163
/**
198164
* @returns SchemaNode with a reduced JSON Schema matching the given data
199165
*/
200-
reduceSchema(data, options = {}) {
166+
reduceNode(data, options = {}) {
201167
const node = this;
202168
const { key, pointer, path } = options;
203169
// @ts-expect-error bool schema
@@ -273,7 +239,7 @@ export const SchemaNodeMethods = {
273239
* Register a JSON Schema as a remote-schema to be resolved by $ref, $anchor, etc
274240
* @returns the current node (not the remote schema-node)
275241
*/
276-
addRemote(url, schema) {
242+
addRemoteSchema(url, schema) {
277243
var _a;
278244
// @draft >= 6
279245
schema.$id = joinId(schema.$id || url);

0 commit comments

Comments
 (0)