@expo/schema-utils 56.0.2-canary-20260624-9d83b81 → 56.0.2

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.
@@ -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
1
+ "use strict";
2
+ //# sourceMappingURL=JSONSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["JSONSchema.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,oDAAoD,GAEpD;;;CAGC"}
1
+ {"version":3,"file":"JSONSchema.js","names":[],"sources":["../src/JSONSchema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n\n/**\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"positiveInteger\".\n */\nexport type PositiveInteger = number;\n/**\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"positiveIntegerDefault0\".\n */\nexport type PositiveIntegerDefault0 = PositiveInteger;\n/**\n * @minItems 1\n *\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"schemaArray\".\n */\nexport type SchemaArray = [JSONSchema, ...JSONSchema[]];\n/**\n * @minItems 1\n *\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"stringArray\".\n */\nexport type StringArray = [string, ...string[]];\n/**\n * This interface was referenced by `JSONSchema`'s JSON-Schema\n * via the `definition` \"simpleTypes\".\n */\nexport type SimpleTypes = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string';\n\n/**\n * Core schema meta-schema.\n *\n * Supports both Draft 04 and Draft 06 keywords:\n * - `id` (Draft 04) and `$id` (Draft 06)\n * - boolean `exclusiveMinimum`/`exclusiveMaximum` (Draft 04, used alongside `minimum`/`maximum`)\n * - numeric `exclusiveMinimum`/`exclusiveMaximum` (Draft 06, standalone bounds)\n *\n * The runtime validator in `validate.ts` already handles both forms correctly.\n */\nexport interface JSONSchema<_SchemaType = unknown> {\n /** @deprecated Use `$id` (Draft 06+). Kept for Draft 04 backward compatibility. */\n id?: string;\n /** Draft 06+: replaces the Draft 04 `id` keyword. */\n $id?: string;\n $schema?: string;\n title?: string;\n description?: string;\n default?: unknown;\n multipleOf?: number;\n maximum?: number;\n /**\n * Draft 04: `true` means the value must be strictly less than `maximum`.\n * Draft 06+: a number that is itself the exclusive upper bound (no need for `maximum`).\n */\n exclusiveMaximum?: boolean | number;\n minimum?: number;\n /**\n * Draft 04: `true` means the value must be strictly greater than `minimum`.\n * Draft 06+: a number that is itself the exclusive lower bound (no need for `minimum`).\n */\n exclusiveMinimum?: boolean | number;\n maxLength?: PositiveInteger;\n minLength?: PositiveIntegerDefault0;\n pattern?: string;\n additionalItems?: boolean | JSONSchema;\n items?: JSONSchema | SchemaArray;\n maxItems?: PositiveInteger;\n minItems?: PositiveIntegerDefault0;\n uniqueItems?: boolean;\n maxProperties?: PositiveInteger;\n minProperties?: PositiveIntegerDefault0;\n required?: StringArray;\n additionalProperties?: boolean | JSONSchema;\n definitions?: {\n [k: string]: JSONSchema;\n };\n properties?: {\n [k: string]: JSONSchema;\n };\n patternProperties?: {\n [k: string]: JSONSchema;\n };\n dependencies?: {\n [k: string]: (JSONSchema | StringArray) | undefined;\n };\n /**\n * @minItems 1\n */\n enum?: [unknown, ...unknown[]];\n type?: SimpleTypes | [SimpleTypes, ...SimpleTypes[]];\n format?: string;\n allOf?: SchemaArray;\n anyOf?: SchemaArray;\n oneOf?: SchemaArray;\n not?: JSONSchema;\n [k: string]: unknown | undefined;\n}\n"],"mappings":"","ignoreList":[]}
package/build/deref.js CHANGED
@@ -1,168 +1,174 @@
1
1
  "use strict";
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;
2
+
3
+ exports.__esModule = true;
4
+ exports.deref = deref;
5
+ /** Return JSON schema ref if input is of `NodeRef` type */
6
+ const getRef = node => node != null && typeof node === 'object' && '$ref' in node && typeof node.$ref === 'string' ? node.$ref : undefined;
7
+
8
+ /** Parse a JSON schema ref into a path array, or return undefined */
9
+ const parseRefMaybe = ref => {
10
+ if (ref == null || ref[0] !== '#') {
11
+ return undefined;
12
+ }
13
+ const props = [];
14
+ let startIndex = 1;
15
+ let index = 1;
16
+ let char;
17
+ while (index < ref.length) {
18
+ while ((char = ref.charCodeAt(index++)) && char !== 47 /*'/'*/);
19
+ const prop = ref.slice(startIndex, index - 1);
20
+ startIndex = index;
21
+ if (prop) props.push(prop);
22
+ }
23
+ return props.length ? props : undefined;
27
24
  };
28
25
  const NOT_FOUND_SYMBOL = Symbol();
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
- }
39
- }
40
- return node;
41
- };
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
- }
26
+
27
+ /** Get value at given JSON schema path or return `NOT_FOUND_SYMBOL` */
28
+ const getValueAtPath = (input, ref) => {
29
+ let node = input;
30
+ for (let index = 0; index < ref.length; index++) {
31
+ const part = ref[index];
32
+ if (node != null && typeof node === 'object' && part != null && part in node) {
33
+ node = node[part];
59
34
  } 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
- }
35
+ node = NOT_FOUND_SYMBOL;
36
+ break;
76
37
  }
38
+ }
39
+ return node;
77
40
  };
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;
41
+
42
+ /** Find all JSON schema refs recursively and add them to `refs` Map */
43
+ const findRefsRec = (node, refs, path) => {
44
+ if (node == null || typeof node !== 'object') {} else if (Array.isArray(node)) {
45
+ for (let index = 0, l = node.length; index < l; index++) {
46
+ const value = node[index];
47
+ const ref = getRef(value);
48
+ if (ref) {
49
+ const targetRef = parseRefMaybe(ref);
50
+ if (targetRef) refs.set([...path, index], targetRef);
51
+ } else if (value != null && typeof value === 'object') {
52
+ path.push(index);
53
+ findRefsRec(value, refs, path);
54
+ path.pop();
55
+ }
81
56
  }
82
- return true;
57
+ } else {
58
+ const record = node;
59
+ for (const key in record) {
60
+ const value = record[key];
61
+ const ref = getRef(value);
62
+ if (ref) {
63
+ const targetRef = parseRefMaybe(ref);
64
+ if (targetRef) refs.set([...path, key], targetRef);
65
+ } else if (value != null && typeof value === 'object') {
66
+ path.push(key);
67
+ findRefsRec(value, refs, path);
68
+ path.pop();
69
+ }
70
+ }
71
+ }
83
72
  };
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-referenceing 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]));
73
+
74
+ /** Detect whether target (where we set the source value) is a nested path inside the source path */
75
+ const isSelfReferencingRefEntry = (target, source) => {
76
+ for (let index = 0; index < source.length; index++) {
77
+ if (source[index] !== target[index]) return false;
78
+ }
79
+ return true;
91
80
  };
81
+
82
+ /** Return sorted refs entries. Longest target paths will be returned first */
83
+ const getSortedRefEntries = refs => {
84
+ const entries = [...refs.entries()].sort((a, b) => b[1].length - a[1].length);
85
+ // Filter out self-referenceing paths. If we set nested targets to source values, we'd
86
+ // create unserializable circular references
87
+ return entries.filter(entry => !isSelfReferencingRefEntry(entry[0], entry[1]));
88
+ };
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
+ */
92
98
  function deref(input) {
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;
99
+ const refs = new Map();
100
+ // Find all JSON schema refs paths
101
+ findRefsRec(input, refs, []);
102
+ // Shallow copy output
103
+ const output = {
104
+ ...input
105
+ };
106
+ // Process all ref entries with deepest targets first
107
+ nextRef: for (const [target, source] of getSortedRefEntries(refs)) {
108
+ let inputNode = input;
109
+ let outputNode = output;
110
+ let targetIndex = 0;
111
+ // For each path part on the target, traverse the output and clone the input
112
+ // to not pollute it
113
+ for (; targetIndex < target.length - 1; targetIndex++) {
114
+ const part = target[targetIndex];
115
+ if (inputNode == null || typeof inputNode !== 'object' || part == null || !(part in inputNode)) {
116
+ // If the part doesn't exist, we abort
117
+ break;
118
+ } else if (outputNode[part] === inputNode[part]) {
119
+ // Copy the input on the output if references are equal
120
+ outputNode[part] = Array.isArray(inputNode[part]) ? [...inputNode[part]] : {
121
+ ...inputNode[part]
122
+ };
123
+ inputNode = inputNode[part];
124
+ outputNode = outputNode[part];
125
+ } else {
126
+ // If this part has already been copied, abort
127
+ break;
128
+ }
145
129
  }
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
- }
130
+ // For each remaining part on the target, continue traversing the output
131
+ for (; targetIndex < target.length - 1; targetIndex++) {
132
+ const part = target[targetIndex];
133
+ if (outputNode == null || typeof outputNode !== 'object' || part == null || !(part in outputNode)) {
134
+ // If the part doesn't exist, skip the entire ref
135
+ continue nextRef;
136
+ } else {
137
+ outputNode = outputNode[part];
138
+ }
163
139
  }
164
- // Return the output with resolved refs
165
- return output;
140
+ // Get value from output
141
+ let sourceValue = getValueAtPath(output, source);
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;
166
173
  }
167
-
168
- //# sourceMappingURL=deref.js.map
174
+ //# sourceMappingURL=deref.js.map
@@ -1 +1 @@
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,EAAE;IAChB,IAAIC,aAAa;IACjB,IAAIC,QAAQ;IACZ,IAAIC;IACJ,MAAOD,QAAQH,IAAIK,MAAM,CAAE;QACzB,MAAO,AAACD,CAAAA,OAAOJ,IAAIM,UAAU,CAACH,QAAO,KAAMC,SAAS,GAAG,KAAK;QAC5D,MAAMG,OAAOP,IAA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EAAmE;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"}
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,IAAI,GAAGP,GAAG,CAACQ,KAAK,CAACN,UAAU,EAAEC,KAAK,GAAG,CAAC,CAAC;IAC7CD,UAAU,GAAGC,KAAK;IAClB,IAAII,IAAI,EAAEN,KAAK,CAACQ,IAAI,CAACF,IAAI,CAAC;EAC5B;EACA,OAAON,KAAK,CAACI,MAAM,GAAGJ,KAAK,GAAGH,SAAS;AACzC,CAAC;AAED,MAAMY,gBAAgB,GAAGC,MAAM,CAAC,CAAC;;AAEjC;AACA,MAAMC,cAAc,GAAGA,CAACC,KAAc,EAAEb,GAAY,KAAwC;EAC1F,IAAIJ,IAAI,GAAGiB,KAAK;EAChB,KAAK,IAAIV,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGH,GAAG,CAACK,MAAM,EAAEF,KAAK,EAAE,EAA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AAK;QACnBC,WAAW,EAAER,MAAM,CAACQ;MACtB,CAAC,GACDH,WAAW;IACjB;EACF;EACA;EACA,OAAOL,MAAM;AACf","ignoreList":[]}
package/build/index.js CHANGED
@@ -1,88 +1,78 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- 0 && (module.exports = {
6
- ValidationError: null,
7
- derefSchema: null,
8
- validate: null
9
- });
10
- function _export(target, all) {
11
- for(var name in all)Object.defineProperty(target, name, {
12
- enumerable: true,
13
- get: Object.getOwnPropertyDescriptor(all, name).get
14
- });
2
+
3
+ exports.__esModule = true;
4
+ exports.ValidationError = void 0;
5
+ exports.derefSchema = derefSchema;
6
+ exports.validate = validate;
7
+ function _deref() {
8
+ const data = require("./deref");
9
+ _deref = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _validate() {
15
+ const data = require("./validate");
16
+ _validate = function () {
17
+ return data;
18
+ };
19
+ return data;
15
20
  }
16
- _export(exports, {
17
- get ValidationError () {
18
- return ValidationError;
19
- },
20
- get derefSchema () {
21
- return derefSchema;
22
- },
23
- get validate () {
24
- return validate;
25
- }
26
- });
27
- const _deref = require("./deref");
28
- const _validate = require("./validate");
29
21
  const CACHE_SYMBOL = Symbol('@expo/schema-utils');
30
- const flattenValidationResults = (input, output = [])=>{
31
- output.push({
32
- message: input.message,
33
- path: input.path,
34
- keyword: input.keyword,
35
- value: input.value
36
- });
37
- for (const cause of input.cause ?? []){
38
- flattenValidationResults(cause, output);
39
- }
40
- return output;
22
+ const flattenValidationResults = (input, output = []) => {
23
+ output.push({
24
+ message: input.message,
25
+ path: input.path,
26
+ keyword: input.keyword,
27
+ value: input.value
28
+ });
29
+ for (const cause of input.cause ?? []) {
30
+ flattenValidationResults(cause, output);
31
+ }
32
+ return output;
41
33
  };
42
- const toErrorsMessages = (errors)=>errors.map((error)=>{
43
- return `\n - options${error.path} (${error.keyword}): ${error.message}`;
44
- });
34
+ const toErrorsMessages = errors => errors.map(error => {
35
+ return `\n - options${error.path} (${error.keyword}): ${error.message}`;
36
+ });
45
37
  class ValidationError extends Error {
46
- schema;
47
- errors;
48
- constructor(result, schema){
49
- const errors = flattenValidationResults(result);
50
- const title = typeof schema.title === 'string' ? schema.title : 'Value';
51
- super(`Invalid options object. ${title} options object does not match the defined schema.\n` + toErrorsMessages(errors).map((line)=>` - options${line}`).join('\n'));
52
- this.name = 'ValidationError';
53
- this.errors = errors;
54
- this.schema = schema;
55
- }
56
- toErrorsMessage() {
57
- return toErrorsMessages(this.errors);
58
- }
38
+ constructor(result, schema) {
39
+ const errors = flattenValidationResults(result);
40
+ const title = typeof schema.title === 'string' ? schema.title : 'Value';
41
+ super(`Invalid options object. ${title} options object does not match the defined schema.\n` + toErrorsMessages(errors).map(line => ` - options${line}`).join('\n'));
42
+ this.name = 'ValidationError';
43
+ this.errors = errors;
44
+ this.schema = schema;
45
+ }
46
+ toErrorsMessage() {
47
+ return toErrorsMessages(this.errors);
48
+ }
59
49
  }
60
- const derefSchemaCache = (schema)=>{
61
- let derefed = schema[CACHE_SYMBOL];
62
- if (!derefed) {
63
- derefed = {
64
- schema: (0, _deref.deref)(schema),
65
- cache: new WeakMap()
66
- };
67
- schema[CACHE_SYMBOL] = derefed;
68
- }
69
- return derefed;
50
+ exports.ValidationError = ValidationError;
51
+ const derefSchemaCache = schema => {
52
+ let derefed = schema[CACHE_SYMBOL];
53
+ if (!derefed) {
54
+ derefed = {
55
+ schema: (0, _deref().deref)(schema),
56
+ cache: new WeakMap()
57
+ };
58
+ schema[CACHE_SYMBOL] = derefed;
59
+ }
60
+ return derefed;
70
61
  };
71
62
  function derefSchema(schema) {
72
- return derefSchemaCache(schema).schema;
63
+ return derefSchemaCache(schema).schema;
73
64
  }
74
65
  function validate(schema, value) {
75
- const data = derefSchemaCache(schema);
76
- let result;
77
- if (typeof value !== 'object' || value == null || (result = data.cache.get(value)) === undefined) {
78
- result = (0, _validate.validateSchema)(data.schema, value, '');
79
- if (typeof value === 'object' && value != null) {
80
- data.cache.set(value, result);
81
- }
82
- }
83
- if (result) {
84
- throw new ValidationError(result, data.schema);
66
+ const data = derefSchemaCache(schema);
67
+ let result;
68
+ if (typeof value !== 'object' || value == null || (result = data.cache.get(value)) === undefined) {
69
+ result = (0, _validate().validateSchema)(data.schema, value, '');
70
+ if (typeof value === 'object' && value != null) {
71
+ data.cache.set(value, result);
85
72
  }
73
+ }
74
+ if (result) {
75
+ throw new ValidationError(result, data.schema);
76
+ }
86
77
  }
87
-
88
- //# sourceMappingURL=index.js.map
78
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":[null],"names":["ValidationError","derefSchema","validate","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"],"mappings":";;;;;;;;;;;;;;;;QAsCaA;eAAAA;;QAkCGC;eAAAA;;QAIAC;eAAAA;;;uBA3EM;0BAKf;AAIP,MAAMC,eAAeC,OAAO;AAO5B,MAAMC,2BAA2B,CAC/BC,OACAC,SAAgC,EAAE;IAElCA,OAAOC,IAAI,CAAC;QACVC,SAASH,MAAMG,OAAO;QACtBC,MAAMJ,MAAMI,IAAI;QAChBC,SAASL,MAAMK,OAAO;QACtBC,OAAON,MAAMM,KAAK;IACpB;IACA,KAAK,MAAMC,SAASP,MAAMO,KAAK,IAAI,EAAE,CAAE;QACrCR,yBAAyBQ,OAAON;IAClC;IACA,OAAOA;AACT;AAEA,MAAMO,mBAAmB,CAACC,SACxBA,OAAOC,GAAG,CAAC,CAACC;QACV,OAAO,CAAC,YAAY,EAAEA,MAAMP,IAAI,CAAC,EAAE,EAAEO,MAAMN,OAAO,CAAC,GAAG,EAAEM,MAAMR,OAAO,EAAE;IACzE;AAEK,MAAMT,wBAA2BkB;IACtCC,OAAsB;IACtBJ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":3,"file":"index.js","names":["_deref","data","require","_validate","CACHE_SYMBOL","Symbol","flattenValidationResults","input","output","push","message","path","keyword","value","cause","toErrorsMessages","errors","map","error","ValidationError","Error","constructor","result","schema","title","line","join","name","toErrorsMessage","exports","derefSchemaCache","derefed","deref","cache","WeakMap","derefSchema","validate","get","undefined","validateSchema","set"],"sources":["../src/index.ts"],"sourcesContent":["import { JSONSchema } from './JSONSchema';\nimport { deref } from './deref';\nimport {\n validateSchema,\n BaseValidationError,\n ValidationError as ValidationResult,\n} from './validate';\n\nexport type { JSONSchema } from './JSONSchema';\n\nconst CACHE_SYMBOL = Symbol('@expo/schema-utils');\n\ninterface SchemaCacheData {\n schema: JSONSchema;\n cache: WeakMap<object, ValidationResult | null>;\n}\n\nconst flattenValidationResults = (\n input: ValidationResult,\n output: BaseValidationError[] = []\n): BaseValidationError[] => {\n output.push({\n message: input.message,\n path: input.path,\n keyword: input.keyword,\n value: input.value,\n });\n for (const cause of input.cause ?? []) {\n flattenValidationResults(cause, output);\n }\n return output;\n};\n\nconst toErrorsMessages = (errors: BaseValidationError[]) =>\n errors.map((error) => {\n return `\\n - options${error.path} (${error.keyword}): ${error.message}`;\n });\n\nexport class ValidationError<T> extends Error {\n schema: JSONSchema<T>;\n errors: BaseValidationError[];\n constructor(result: ValidationResult, schema: JSONSchema<T>) {\n const errors = flattenValidationResults(result);\n const title = typeof schema.title === 'string' ? schema.title : 'Value';\n super(\n `Invalid options object. ${title} options object does not match the defined schema.\\n` +\n toErrorsMessages(errors)\n .map((line) => ` - options${line}`)\n .join('\\n')\n );\n this.name = 'ValidationError';\n this.errors = errors;\n this.schema = schema;\n }\n\n toErrorsMessage(): string[] {\n return toErrorsMessages(this.errors);\n }\n}\n\nconst derefSchemaCache = (schema: JSONSchema): SchemaCacheData => {\n let derefed = (schema as any)[CACHE_SYMBOL] as SchemaCacheData | undefined;\n if (!derefed) {\n derefed = {\n schema: deref(schema),\n cache: new WeakMap(),\n };\n (schema as any)[CACHE_SYMBOL] = derefed;\n }\n return derefed!;\n};\n\nexport function derefSchema<T>(schema: JSONSchema<T>): JSONSchema<T> {\n return derefSchemaCache(schema).schema;\n}\n\nexport function validate<T>(schema: JSONSchema<T>, value: unknown): asserts value is T {\n const data = derefSchemaCache(schema);\n let result: ValidationResult | null | undefined;\n if (\n typeof value !== 'object' ||\n value == null ||\n (result = data.cache.get(value)) === undefined\n ) {\n result = validateSchema(data.schema, value, '');\n if (typeof value === 'object' && value != null) {\n data.cache.set(value, result);\n }\n }\n if (result) {\n throw new ValidationError(result, data.schema);\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,UAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,SAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAQA,MAAMG,YAAY,GAAGC,MAAM,CAAC,oBAAoB,CAAC;AAOjD,MAAMC,wBAAwB,GAAGA,CAC/BC,KAAuB,EACvBC,MAA6B,GAAG,EAAE,KACR;EAC1BA,MAAM,CAACC,IAAI,CAAC;IACVC,OAAO,EAAEH,KAAK,CAACG,OAAO;IACtBC,IAAI,EAAEJ,KAAK,CAACI,IAAI;IAChBC,OAAO,EAAEL,KAAK,CAACK,OAAO;IACtBC,KAAK,EAAEN,KAAK,CAACM;EACf,CAAC,CAAC;EACF,KAAK,MAAMC,KAAK,IAAIP,KAAK,CAACO,KAAK,IAAI,EAAE,EAAE;IACrCR,wBAAwB,CAACQ,KAAK,EAAEN,MAAM,CAAC;EACzC;EACA,OAAOA,MAAM;AACf,CAAC;AAED,MAAMO,gBAAgB,GAAIC,MAA6B,IACrDA,MAAM,CAACC,GAAG,CAAEC,KAAK,IAAK;EACpB,OAAO,eAAeA,KAAK,CAACP,IAAI,KAAKO,KAAK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