@expo/schema-utils 57.0.2 → 58.0.0-canary-20260812-27f94d4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/JSONSchema.js +9 -2
- package/build/JSONSchema.js.map +1 -1
- package/build/deref.js +155 -161
- package/build/deref.js.map +1 -1
- package/build/index.d.ts +3 -0
- package/build/index.js +84 -66
- package/build/index.js.map +1 -1
- package/build/validate.js +509 -499
- package/build/validate.js.map +1 -1
- package/build/visit.d.ts +3 -0
- package/build/visit.js +120 -0
- package/build/visit.js.map +1 -0
- package/package.json +20 -18
package/build/JSONSchema.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */ /**
|
|
2
|
+
* This interface was referenced by `JSONSchema`'s JSON-Schema
|
|
3
|
+
* via the `definition` "positiveInteger".
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=JSONSchema.js.map
|
package/build/JSONSchema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["JSONSchema.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,oDAAoD,GAEpD;;;CAGC"}
|
package/build/deref.js
CHANGED
|
@@ -1,174 +1,168 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "deref", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return deref;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
/** Return JSON schema ref if input is of `NodeRef` type */ const getRef = (node)=>node != null && typeof node === 'object' && '$ref' in node && typeof node.$ref === 'string' ? node.$ref : undefined;
|
|
12
|
+
/** Parse a JSON schema ref into a path array, or return undefined */ const parseRefMaybe = (ref)=>{
|
|
13
|
+
if (ref == null || ref[0] !== '#') {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const props = [];
|
|
17
|
+
let startIndex = 1;
|
|
18
|
+
let index = 1;
|
|
19
|
+
let char;
|
|
20
|
+
while(index < ref.length){
|
|
21
|
+
while((char = ref.charCodeAt(index++)) && char !== 47 /*'/'*/ );
|
|
22
|
+
const prop = ref.slice(startIndex, index - 1);
|
|
23
|
+
startIndex = index;
|
|
24
|
+
if (prop) props.push(prop);
|
|
25
|
+
}
|
|
26
|
+
return props.length ? props : undefined;
|
|
24
27
|
};
|
|
25
28
|
const NOT_FOUND_SYMBOL = Symbol();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
break;
|
|
29
|
+
/** Get value at given JSON schema path or return `NOT_FOUND_SYMBOL` */ const getValueAtPath = (input, ref)=>{
|
|
30
|
+
let node = input;
|
|
31
|
+
for(let index = 0; index < ref.length; index++){
|
|
32
|
+
const part = ref[index];
|
|
33
|
+
if (node != null && typeof node === 'object' && part != null && part in node) {
|
|
34
|
+
node = node[part];
|
|
35
|
+
} else {
|
|
36
|
+
node = NOT_FOUND_SYMBOL;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
return node;
|
|
40
|
+
return node;
|
|
40
41
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
42
|
+
/** Find all JSON schema refs recursively and add them to `refs` Map */ const findRefsRec = (node, refs, path)=>{
|
|
43
|
+
if (node == null || typeof node !== 'object') {} else if (Array.isArray(node)) {
|
|
44
|
+
for(let index = 0, l = node.length; index < l; index++){
|
|
45
|
+
const value = node[index];
|
|
46
|
+
const ref = getRef(value);
|
|
47
|
+
if (ref) {
|
|
48
|
+
const targetRef = parseRefMaybe(ref);
|
|
49
|
+
if (targetRef) refs.set([
|
|
50
|
+
...path,
|
|
51
|
+
index
|
|
52
|
+
], targetRef);
|
|
53
|
+
} else if (value != null && typeof value === 'object') {
|
|
54
|
+
path.push(index);
|
|
55
|
+
findRefsRec(value, refs, path);
|
|
56
|
+
path.pop();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
const record = node;
|
|
61
|
+
for(const key in record){
|
|
62
|
+
const value = record[key];
|
|
63
|
+
const ref = getRef(value);
|
|
64
|
+
if (ref) {
|
|
65
|
+
const targetRef = parseRefMaybe(ref);
|
|
66
|
+
if (targetRef) refs.set([
|
|
67
|
+
...path,
|
|
68
|
+
key
|
|
69
|
+
], targetRef);
|
|
70
|
+
} else if (value != null && typeof value === 'object') {
|
|
71
|
+
path.push(key);
|
|
72
|
+
findRefsRec(value, refs, path);
|
|
73
|
+
path.pop();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
|
-
}
|
|
72
77
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
return true;
|
|
78
|
+
/** Detect whether target (where we set the source value) is a nested path inside the source path */ const isSelfReferencingRefEntry = (target, source)=>{
|
|
79
|
+
for(let index = 0; index < source.length; index++){
|
|
80
|
+
if (source[index] !== target[index]) return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
80
83
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
/** Return sorted refs entries. Longest target paths will be returned first */ const getSortedRefEntries = (refs)=>{
|
|
85
|
+
const entries = [
|
|
86
|
+
...refs.entries()
|
|
87
|
+
].sort((a, b)=>b[1].length - a[1].length);
|
|
88
|
+
// Filter out self-referencing paths. If we set nested targets to source values, we'd
|
|
89
|
+
// create unserializable circular references
|
|
90
|
+
return entries.filter((entry)=>!isSelfReferencingRefEntry(entry[0], entry[1]));
|
|
88
91
|
};
|
|
89
|
-
|
|
90
|
-
/** Dereference JSON schema pointers.
|
|
91
|
-
*
|
|
92
|
-
* @remarks
|
|
93
|
-
* This is a minimal reimplementation of `json-schema-deref-sync` without
|
|
94
|
-
* file reference, URL/web reference, and loader support.
|
|
95
|
-
*
|
|
96
|
-
* @see https://github.com/cvent/json-schema-deref-sync
|
|
97
|
-
*/
|
|
98
92
|
function deref(input) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
93
|
+
const refs = new Map();
|
|
94
|
+
// Find all JSON schema refs paths
|
|
95
|
+
findRefsRec(input, refs, []);
|
|
96
|
+
// Shallow copy output
|
|
97
|
+
const output = {
|
|
98
|
+
...input
|
|
99
|
+
};
|
|
100
|
+
// Process all ref entries with deepest targets first
|
|
101
|
+
nextRef: for (const [target, source] of getSortedRefEntries(refs)){
|
|
102
|
+
let inputNode = input;
|
|
103
|
+
let outputNode = output;
|
|
104
|
+
let targetIndex = 0;
|
|
105
|
+
// For each path part on the target, traverse the output and clone the input
|
|
106
|
+
// to not pollute it
|
|
107
|
+
for(; targetIndex < target.length - 1; targetIndex++){
|
|
108
|
+
const part = target[targetIndex];
|
|
109
|
+
if (inputNode == null || typeof inputNode !== 'object' || part == null || !(part in inputNode)) {
|
|
110
|
+
break;
|
|
111
|
+
} else if (outputNode[part] === inputNode[part]) {
|
|
112
|
+
// Copy the input on the output if references are equal
|
|
113
|
+
outputNode[part] = Array.isArray(inputNode[part]) ? [
|
|
114
|
+
...inputNode[part]
|
|
115
|
+
] : {
|
|
116
|
+
...inputNode[part]
|
|
117
|
+
};
|
|
118
|
+
inputNode = inputNode[part];
|
|
119
|
+
outputNode = outputNode[part];
|
|
120
|
+
} else {
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// For each remaining part on the target, continue traversing the output
|
|
125
|
+
for(; targetIndex < target.length - 1; targetIndex++){
|
|
126
|
+
const part = target[targetIndex];
|
|
127
|
+
if (outputNode == null || typeof outputNode !== 'object' || part == null || !(part in outputNode)) {
|
|
128
|
+
continue nextRef;
|
|
129
|
+
} else {
|
|
130
|
+
outputNode = outputNode[part];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Get value from output
|
|
134
|
+
let sourceValue = getValueAtPath(output, source);
|
|
135
|
+
if (sourceValue === NOT_FOUND_SYMBOL) {
|
|
136
|
+
// If no value was found, try to get a value from the input instead
|
|
137
|
+
sourceValue = getValueAtPath(input, source);
|
|
138
|
+
// Otherwise, skip this ref
|
|
139
|
+
if (sourceValue === NOT_FOUND_SYMBOL) continue;
|
|
140
|
+
}
|
|
141
|
+
// Set the source value on the target path
|
|
142
|
+
// The for-loops prior have made sure that the output has already been deeply
|
|
143
|
+
// cloned and traversed for the entire path
|
|
144
|
+
outputNode[target[target.length - 1]] = sourceValue;
|
|
129
145
|
}
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
// Handle root refs last
|
|
147
|
+
const rootTargetRef = parseRefMaybe(getRef(input));
|
|
148
|
+
if (rootTargetRef) {
|
|
149
|
+
// Get value from output
|
|
150
|
+
let sourceValue = getValueAtPath(output, rootTargetRef);
|
|
151
|
+
// If no value was found, try to get a value from the input instead
|
|
152
|
+
if (sourceValue === NOT_FOUND_SYMBOL) {
|
|
153
|
+
sourceValue = getValueAtPath(input, rootTargetRef);
|
|
154
|
+
}
|
|
155
|
+
// Assign the target object to the output
|
|
156
|
+
if (sourceValue !== NOT_FOUND_SYMBOL && sourceValue != null) {
|
|
157
|
+
return typeof sourceValue === 'object' ? {
|
|
158
|
+
...sourceValue,
|
|
159
|
+
title: output.title,
|
|
160
|
+
description: output.description
|
|
161
|
+
} : sourceValue;
|
|
162
|
+
}
|
|
139
163
|
}
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
if (sourceValue === NOT_FOUND_SYMBOL) {
|
|
143
|
-
// If no value was found, try to get a value from the input instead
|
|
144
|
-
sourceValue = getValueAtPath(input, source);
|
|
145
|
-
// Otherwise, skip this ref
|
|
146
|
-
if (sourceValue === NOT_FOUND_SYMBOL) continue;
|
|
147
|
-
}
|
|
148
|
-
// Set the source value on the target path
|
|
149
|
-
// The for-loops prior have made sure that the output has already been deeply
|
|
150
|
-
// cloned and traversed for the entire path
|
|
151
|
-
outputNode[target[target.length - 1]] = sourceValue;
|
|
152
|
-
}
|
|
153
|
-
// Handle root refs last
|
|
154
|
-
const rootTargetRef = parseRefMaybe(getRef(input));
|
|
155
|
-
if (rootTargetRef) {
|
|
156
|
-
// Get value from output
|
|
157
|
-
let sourceValue = getValueAtPath(output, rootTargetRef);
|
|
158
|
-
// If no value was found, try to get a value from the input instead
|
|
159
|
-
if (sourceValue === NOT_FOUND_SYMBOL) {
|
|
160
|
-
sourceValue = getValueAtPath(input, rootTargetRef);
|
|
161
|
-
}
|
|
162
|
-
// Assign the target object to the output
|
|
163
|
-
if (sourceValue !== NOT_FOUND_SYMBOL && sourceValue != null) {
|
|
164
|
-
return typeof sourceValue === 'object' ? {
|
|
165
|
-
...sourceValue,
|
|
166
|
-
title: output.title,
|
|
167
|
-
description: output.description
|
|
168
|
-
} : sourceValue;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
// Return the output with resolved refs
|
|
172
|
-
return output;
|
|
164
|
+
// Return the output with resolved refs
|
|
165
|
+
return output;
|
|
173
166
|
}
|
|
174
|
-
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=deref.js.map
|
package/build/deref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deref.js","names":["getRef","node","$ref","undefined","parseRefMaybe","ref","props","startIndex","index","char","length","charCodeAt","prop","slice","push","NOT_FOUND_SYMBOL","Symbol","getValueAtPath","input","part","findRefsRec","refs","path","Array","isArray","l","value","targetRef","set","pop","record","key","isSelfReferencingRefEntry","target","source","getSortedRefEntries","entries","sort","a","b","filter","entry","deref","Map","output","nextRef","inputNode","outputNode","targetIndex","sourceValue","rootTargetRef","title","description"],"sources":["../src/deref.ts"],"sourcesContent":["type RefPath = readonly (string | number)[];\n\ninterface NodeRef {\n $ref: string;\n}\n\n/** Return JSON schema ref if input is of `NodeRef` type */\nconst getRef = (node: NodeRef | unknown): string | undefined =>\n node != null && typeof node === 'object' && '$ref' in node && typeof node.$ref === 'string'\n ? node.$ref\n : undefined;\n\n/** Parse a JSON schema ref into a path array, or return undefined */\nconst parseRefMaybe = (ref: string | undefined): RefPath | undefined => {\n if (ref == null || ref[0] !== '#') {\n return undefined;\n }\n const props = [];\n let startIndex = 1;\n let index = 1;\n let char: number;\n while (index < ref.length) {\n while ((char = ref.charCodeAt(index++)) && char !== 47 /*'/'*/);\n const prop = ref.slice(startIndex, index - 1);\n startIndex = index;\n if (prop) props.push(prop);\n }\n return props.length ? props : undefined;\n};\n\nconst NOT_FOUND_SYMBOL = Symbol();\n\n/** Get value at given JSON schema path or return `NOT_FOUND_SYMBOL` */\nconst getValueAtPath = (input: unknown, ref: RefPath): unknown | typeof NOT_FOUND_SYMBOL => {\n let node = input;\n for (let index = 0; index < ref.length; index++) {\n const part = ref[index];\n if (node != null && typeof node === 'object' && part != null && part in node) {\n node = (node as Record<string, unknown>)[part];\n } else {\n node = NOT_FOUND_SYMBOL;\n break;\n }\n }\n return node;\n};\n\n/** Find all JSON schema refs recursively and add them to `refs` Map */\nconst findRefsRec = (\n node: unknown,\n refs: Map<RefPath, RefPath>,\n path: (string | number)[]\n): void => {\n if (node == null || typeof node !== 'object') {\n } else if (Array.isArray(node)) {\n for (let index = 0, l = node.length; index < l; index++) {\n const value = node[index];\n const ref = getRef(value);\n if (ref) {\n const targetRef = parseRefMaybe(ref);\n if (targetRef) refs.set([...path, index], targetRef);\n } else if (value != null && typeof value === 'object') {\n path.push(index);\n findRefsRec(value, refs, path);\n path.pop();\n }\n }\n } else {\n const record = node as Record<string, unknown>;\n for (const key in record) {\n const value = record[key];\n const ref = getRef(value);\n if (ref) {\n const targetRef = parseRefMaybe(ref);\n if (targetRef) refs.set([...path, key], targetRef);\n } else if (value != null && typeof value === 'object') {\n path.push(key);\n findRefsRec(value, refs, path);\n path.pop();\n }\n }\n }\n};\n\n/** Detect whether target (where we set the source value) is a nested path inside the source path */\nconst isSelfReferencingRefEntry = (target: RefPath, source: RefPath) => {\n for (let index = 0; index < source.length; index++) {\n if (source[index] !== target[index]) return false;\n }\n return true;\n};\n\n/** Return sorted refs entries. Longest target paths will be returned first */\nconst getSortedRefEntries = (refs: Map<RefPath, RefPath>): readonly [RefPath, RefPath][] => {\n const entries = [...refs.entries()].sort((a, b) => b[1].length - a[1].length);\n // Filter out self-referenceing paths. If we set nested targets to source values, we'd\n // create unserializable circular references\n return entries.filter((entry) => !isSelfReferencingRefEntry(entry[0], entry[1]));\n};\n\n/** Dereference JSON schema pointers.\n *\n * @remarks\n * This is a minimal reimplementation of `json-schema-deref-sync` without\n * file reference, URL/web reference, and loader support.\n *\n * @see https://github.com/cvent/json-schema-deref-sync\n */\nexport function deref(input: any): any {\n const refs = new Map<RefPath, RefPath>();\n // Find all JSON schema refs paths\n findRefsRec(input, refs, []);\n // Shallow copy output\n const output = { ...input };\n // Process all ref entries with deepest targets first\n nextRef: for (const [target, source] of getSortedRefEntries(refs)) {\n let inputNode = input;\n let outputNode = output;\n let targetIndex = 0;\n // For each path part on the target, traverse the output and clone the input\n // to not pollute it\n for (; targetIndex < target.length - 1; targetIndex++) {\n const part = target[targetIndex];\n if (\n inputNode == null ||\n typeof inputNode !== 'object' ||\n part == null ||\n !(part in inputNode)\n ) {\n // If the part doesn't exist, we abort\n break;\n } else if (outputNode[part] === inputNode[part]) {\n // Copy the input on the output if references are equal\n outputNode[part] = Array.isArray(inputNode[part])\n ? [...inputNode[part]]\n : { ...inputNode[part] };\n inputNode = inputNode[part];\n outputNode = outputNode[part];\n } else {\n // If this part has already been copied, abort\n break;\n }\n }\n // For each remaining part on the target, continue traversing the output\n for (; targetIndex < target.length - 1; targetIndex++) {\n const part = target[targetIndex];\n if (\n outputNode == null ||\n typeof outputNode !== 'object' ||\n part == null ||\n !(part in outputNode)\n ) {\n // If the part doesn't exist, skip the entire ref\n continue nextRef;\n } else {\n outputNode = outputNode[part];\n }\n }\n // Get value from output\n let sourceValue = getValueAtPath(output, source);\n if (sourceValue === NOT_FOUND_SYMBOL) {\n // If no value was found, try to get a value from the input instead\n sourceValue = getValueAtPath(input, source);\n // Otherwise, skip this ref\n if (sourceValue === NOT_FOUND_SYMBOL) continue;\n }\n // Set the source value on the target path\n // The for-loops prior have made sure that the output has already been deeply\n // cloned and traversed for the entire path\n outputNode[target[target.length - 1]!] = sourceValue;\n }\n // Handle root refs last\n const rootTargetRef = parseRefMaybe(getRef(input));\n if (rootTargetRef) {\n // Get value from output\n let sourceValue = getValueAtPath(output, rootTargetRef);\n // If no value was found, try to get a value from the input instead\n if (sourceValue === NOT_FOUND_SYMBOL) {\n sourceValue = getValueAtPath(input, rootTargetRef);\n }\n // Assign the target object to the output\n if (sourceValue !== NOT_FOUND_SYMBOL && sourceValue != null) {\n return typeof sourceValue === 'object'\n ? {\n ...sourceValue,\n title: output.title,\n description: output.description,\n }\n : sourceValue;\n }\n }\n // Return the output with resolved refs\n return output;\n}\n"],"mappings":";;;;AAMA;AACA,MAAMA,MAAM,GAAIC,IAAuB,IACrCA,IAAI,IAAI,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAIA,IAAI,IAAI,OAAOA,IAAI,CAACC,IAAI,KAAK,QAAQ,GACvFD,IAAI,CAACC,IAAI,GACTC,SAAS;;AAEf;AACA,MAAMC,aAAa,GAAIC,GAAuB,IAA0B;EACtE,IAAIA,GAAG,IAAI,IAAI,IAAIA,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;IACjC,OAAOF,SAAS;EAClB;EACA,MAAMG,KAAK,GAAG,EAAE;EAChB,IAAIC,UAAU,GAAG,CAAC;EAClB,IAAIC,KAAK,GAAG,CAAC;EACb,IAAIC,IAAY;EAChB,OAAOD,KAAK,GAAGH,GAAG,CAACK,MAAM,EAAE;IACzB,OAAO,CAACD,IAAI,GAAGJ,GAAG,CAACM,UAAU,CAACH,KAAK,EAAE,CAAC,KAAKC,IAAI,KAAK,EAAE,CAAC,QAAQ;IAC/D,MAAMG,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C,CAAC,CAAE,GAAGuC,WAAW;EACtD;EACA;EACA,MAAMC,aAAa,GAAG9C,aAAa,CAACJ,MAAM,CAACkB,KAAK,CAAC,CAAC;EAClD,IAAIgC,aAAa,EAAE;IACjB;IACA,IAAID,WAAW,GAAGhC,cAAc,CAAC2B,MAAM,EAAEM,aAAa,CAAC;IACvD;IACA,IAAID,WAAW,KAAKlC,gBAAgB,EAAE;MACpCkC,WAAW,GAAGhC,cAAc,CAACC,KAAK,EAAEgC,aAAa,CAAC;IACpD;IACA;IACA,IAAID,WAAW,KAAKlC,gBAAgB,IAAIkC,WAAW,IAAI,IAAI,EAAE;MAC3D,OAAO,OAAOA,WAAW,KAAK,QAAQ,GAClC;QACE,GAAGA,WAAW;QACdE,KAAK,EAAEP,MAAM,CAACO,KAAK;QACnBC,WAAW,EAAER,MAAM,CAACQ;MACtB,CAAC,GACDH,WAAW;IACjB;EACF;EACA;EACA,OAAOL,MAAM;AACf","ignoreList":[]}
|
|
1
|
+
{"version":3,"sources":["deref.ts"],"sourcesContent":[null],"names":["deref","getRef","node","$ref","undefined","parseRefMaybe","ref","props","startIndex","index","char","length","charCodeAt","prop","slice","push","NOT_FOUND_SYMBOL","Symbol","getValueAtPath","input","part","findRefsRec","refs","path","Array","isArray","l","value","targetRef","set","pop","record","key","isSelfReferencingRefEntry","target","source","getSortedRefEntries","entries","sort","a","b","filter","entry","Map","output","nextRef","inputNode","outputNode","targetIndex","sourceValue","rootTargetRef","title","description"],"mappings":";;;;+BA4GgBA;;;eAAAA;;;AAtGhB,yDAAyD,GACzD,MAAMC,SAAS,CAACC,OACdA,QAAQ,QAAQ,OAAOA,SAAS,YAAY,UAAUA,QAAQ,OAAOA,KAAKC,IAAI,KAAK,WAC/ED,KAAKC,IAAI,GACTC;AAEN,mEAAmE,GACnE,MAAMC,gBAAgB,CAACC;IACrB,IAAIA,OAAO,QAAQA,GAAG,CAAC,EAAE,KAAK,KAAK;QACjC,OAAOF;IACT;IACA,MAAMG,QAAQ,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B,UAAU,CAACb,MAAM,CAACA,OAAOvB,MAAM,GAAG,EAAE,CAAE,GAAGsC;IAC3C;IACA,wBAAwB;IACxB,MAAMC,gBAAgB7C,cAAcJ,OAAOkB;IAC3C,IAAI+B,eAAe;QACjB,wBAAwB;QACxB,IAAID,cAAc/B,eAAe0B,QAAQM;QACzC,mEAAmE;QACnE,IAAID,gBAAgBjC,kBAAkB;YACpCiC,cAAc/B,eAAeC,OAAO+B;QACtC;QACA,yCAAyC;QACzC,IAAID,gBAAgBjC,oBAAoBiC,eAAe,MAAM;YAC3D,OAAO,OAAOA,gBAAgB,WAC1B;gBACE,GAAGA,WAAW;gBACdE,OAAOP,OAAOO,KAAK;gBACnBC,aAAaR,OAAOQ,WAAW;YACjC,IACAH;QACN;IACF;IACA,uCAAuC;IACvC,OAAOL;AACT"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { JSONSchema } from './JSONSchema';
|
|
2
2
|
import { BaseValidationError, ValidationError as ValidationResult } from './validate';
|
|
3
|
+
import { SchemaVisitor } from './visit';
|
|
3
4
|
export type { JSONSchema } from './JSONSchema';
|
|
5
|
+
export type { SchemaVisitor } from './visit';
|
|
4
6
|
export declare class ValidationError<T> extends Error {
|
|
5
7
|
schema: JSONSchema<T>;
|
|
6
8
|
errors: BaseValidationError[];
|
|
@@ -9,3 +11,4 @@ export declare class ValidationError<T> extends Error {
|
|
|
9
11
|
}
|
|
10
12
|
export declare function derefSchema<T>(schema: JSONSchema<T>): JSONSchema<T>;
|
|
11
13
|
export declare function validate<T>(schema: JSONSchema<T>, value: unknown): asserts value is T;
|
|
14
|
+
export declare function visit<T>(schema: JSONSchema<T>, value: unknown, visitor: SchemaVisitor): void;
|
package/build/index.js
CHANGED
|
@@ -1,78 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_validate = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
0 && (module.exports = {
|
|
6
|
+
ValidationError: null,
|
|
7
|
+
derefSchema: null,
|
|
8
|
+
validate: null,
|
|
9
|
+
visit: null
|
|
10
|
+
});
|
|
11
|
+
function _export(target, all) {
|
|
12
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
15
|
+
});
|
|
20
16
|
}
|
|
17
|
+
_export(exports, {
|
|
18
|
+
get ValidationError () {
|
|
19
|
+
return ValidationError;
|
|
20
|
+
},
|
|
21
|
+
get derefSchema () {
|
|
22
|
+
return derefSchema;
|
|
23
|
+
},
|
|
24
|
+
get validate () {
|
|
25
|
+
return validate;
|
|
26
|
+
},
|
|
27
|
+
get visit () {
|
|
28
|
+
return visit;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _deref = require("./deref");
|
|
32
|
+
const _validate = require("./validate");
|
|
33
|
+
const _visit = require("./visit");
|
|
21
34
|
const CACHE_SYMBOL = Symbol('@expo/schema-utils');
|
|
22
|
-
const flattenValidationResults = (input, output = [])
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
const flattenValidationResults = (input, output = [])=>{
|
|
36
|
+
output.push({
|
|
37
|
+
message: input.message,
|
|
38
|
+
path: input.path,
|
|
39
|
+
keyword: input.keyword,
|
|
40
|
+
value: input.value
|
|
41
|
+
});
|
|
42
|
+
for (const cause of input.cause ?? []){
|
|
43
|
+
flattenValidationResults(cause, output);
|
|
44
|
+
}
|
|
45
|
+
return output;
|
|
33
46
|
};
|
|
34
|
-
const toErrorsMessages = errors
|
|
35
|
-
|
|
36
|
-
});
|
|
47
|
+
const toErrorsMessages = (errors)=>errors.map((error)=>{
|
|
48
|
+
return `\n - options${error.path} (${error.keyword}): ${error.message}`;
|
|
49
|
+
});
|
|
37
50
|
class ValidationError extends Error {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
schema;
|
|
52
|
+
errors;
|
|
53
|
+
constructor(result, schema){
|
|
54
|
+
const errors = flattenValidationResults(result);
|
|
55
|
+
const title = typeof schema.title === 'string' ? schema.title : 'Value';
|
|
56
|
+
super(`Invalid options object. ${title} options object does not match the defined schema.\n` + toErrorsMessages(errors).map((line)=>` - options${line}`).join('\n'));
|
|
57
|
+
this.name = 'ValidationError';
|
|
58
|
+
this.errors = errors;
|
|
59
|
+
this.schema = schema;
|
|
60
|
+
}
|
|
61
|
+
toErrorsMessage() {
|
|
62
|
+
return toErrorsMessages(this.errors);
|
|
63
|
+
}
|
|
49
64
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return derefed;
|
|
65
|
+
const derefSchemaCache = (schema)=>{
|
|
66
|
+
let derefed = schema[CACHE_SYMBOL];
|
|
67
|
+
if (!derefed) {
|
|
68
|
+
derefed = {
|
|
69
|
+
schema: (0, _deref.deref)(schema),
|
|
70
|
+
cache: new WeakMap()
|
|
71
|
+
};
|
|
72
|
+
schema[CACHE_SYMBOL] = derefed;
|
|
73
|
+
}
|
|
74
|
+
return derefed;
|
|
61
75
|
};
|
|
62
76
|
function derefSchema(schema) {
|
|
63
|
-
|
|
77
|
+
return derefSchemaCache(schema).schema;
|
|
64
78
|
}
|
|
65
79
|
function validate(schema, value) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
const data = derefSchemaCache(schema);
|
|
81
|
+
let result;
|
|
82
|
+
if (typeof value !== 'object' || value == null || (result = data.cache.get(value)) === undefined) {
|
|
83
|
+
result = (0, _validate.validateSchema)(data.schema, value, '');
|
|
84
|
+
if (typeof value === 'object' && value != null) {
|
|
85
|
+
data.cache.set(value, result);
|
|
86
|
+
}
|
|
72
87
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
88
|
+
if (result) {
|
|
89
|
+
throw new ValidationError(result, data.schema);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function visit(schema, value, visitor) {
|
|
93
|
+
(0, _visit.visitNode)(derefSchemaCache(schema).schema, value, visitor);
|
|
77
94
|
}
|
|
78
|
-
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":[null],"names":["ValidationError","derefSchema","validate","visit","CACHE_SYMBOL","Symbol","flattenValidationResults","input","output","push","message","path","keyword","value","cause","toErrorsMessages","errors","map","error","Error","schema","result","title","line","join","name","toErrorsMessage","derefSchemaCache","derefed","deref","cache","WeakMap","data","get","undefined","validateSchema","set","visitor","visitNode"],"mappings":";;;;;;;;;;;;;;;;;QAwCaA;eAAAA;;QAkCGC;eAAAA;;QAIAC;eAAAA;;QAkBAC;eAAAA;;;uBA/FM;0BAKf;uBACkC;AAKzC,MAAMC,eAAeC,OAAO;AAO5B,MAAMC,2BAA2B,CAC/BC,OACAC,SAAgC,EAAE;IAElCA,OAAOC,IAAI,CAAC;QACVC,SAASH,MAAMG,OAAO;QACtBC,MAAMJ,MAAMI,IAAI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