@zuplo/cli 6.70.15 → 6.70.21

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.
Files changed (203) hide show
  1. package/dist/ca-certificate/create/handler.d.ts +3 -0
  2. package/dist/ca-certificate/create/handler.d.ts.map +1 -0
  3. package/dist/ca-certificate/create/handler.js +46 -0
  4. package/dist/ca-certificate/create/handler.js.map +1 -0
  5. package/dist/ca-certificate/delete/handler.d.ts +3 -0
  6. package/dist/ca-certificate/delete/handler.d.ts.map +1 -0
  7. package/dist/ca-certificate/delete/handler.js +18 -0
  8. package/dist/ca-certificate/delete/handler.js.map +1 -0
  9. package/dist/ca-certificate/describe/handler.d.ts +3 -0
  10. package/dist/ca-certificate/describe/handler.d.ts.map +1 -0
  11. package/dist/ca-certificate/describe/handler.js +32 -0
  12. package/dist/ca-certificate/describe/handler.js.map +1 -0
  13. package/dist/ca-certificate/list/handler.d.ts +3 -0
  14. package/dist/ca-certificate/list/handler.d.ts.map +1 -0
  15. package/dist/ca-certificate/list/handler.js +28 -0
  16. package/dist/ca-certificate/list/handler.js.map +1 -0
  17. package/dist/ca-certificate/models.d.ts +51 -0
  18. package/dist/ca-certificate/models.d.ts.map +1 -0
  19. package/dist/ca-certificate/models.js +2 -0
  20. package/dist/ca-certificate/models.js.map +1 -0
  21. package/dist/ca-certificate/update/handler.d.ts +3 -0
  22. package/dist/ca-certificate/update/handler.d.ts.map +1 -0
  23. package/dist/ca-certificate/update/handler.js +26 -0
  24. package/dist/ca-certificate/update/handler.js.map +1 -0
  25. package/dist/ca-certificate/validation.d.ts +21 -0
  26. package/dist/ca-certificate/validation.d.ts.map +1 -0
  27. package/dist/ca-certificate/validation.js +135 -0
  28. package/dist/ca-certificate/validation.js.map +1 -0
  29. package/dist/ca-certificate/validation.test.d.ts +2 -0
  30. package/dist/ca-certificate/validation.test.d.ts.map +1 -0
  31. package/dist/ca-certificate/validation.test.js +131 -0
  32. package/dist/ca-certificate/validation.test.js.map +1 -0
  33. package/dist/cli.js +2 -6
  34. package/dist/cli.js.map +1 -1
  35. package/dist/cmds/ca-certificate/create.d.ts +9 -0
  36. package/dist/cmds/ca-certificate/create.d.ts.map +1 -0
  37. package/dist/cmds/ca-certificate/create.js +66 -0
  38. package/dist/cmds/ca-certificate/create.js.map +1 -0
  39. package/dist/cmds/ca-certificate/delete.d.ts +9 -0
  40. package/dist/cmds/ca-certificate/delete.d.ts.map +1 -0
  41. package/dist/cmds/ca-certificate/delete.js +56 -0
  42. package/dist/cmds/ca-certificate/delete.js.map +1 -0
  43. package/dist/cmds/ca-certificate/describe.d.ts +9 -0
  44. package/dist/cmds/ca-certificate/describe.d.ts.map +1 -0
  45. package/dist/cmds/ca-certificate/describe.js +56 -0
  46. package/dist/cmds/ca-certificate/describe.js.map +1 -0
  47. package/dist/cmds/ca-certificate/index.d.ts +4 -0
  48. package/dist/cmds/ca-certificate/index.d.ts.map +1 -0
  49. package/dist/cmds/ca-certificate/index.js +18 -0
  50. package/dist/cmds/ca-certificate/index.js.map +1 -0
  51. package/dist/cmds/ca-certificate/list.d.ts +9 -0
  52. package/dist/cmds/ca-certificate/list.d.ts.map +1 -0
  53. package/dist/cmds/ca-certificate/list.js +48 -0
  54. package/dist/cmds/ca-certificate/list.js.map +1 -0
  55. package/dist/cmds/ca-certificate/update.d.ts +9 -0
  56. package/dist/cmds/ca-certificate/update.d.ts.map +1 -0
  57. package/dist/cmds/ca-certificate/update.js +56 -0
  58. package/dist/cmds/ca-certificate/update.js.map +1 -0
  59. package/dist/cmds/mtls-certificates/index.js +1 -1
  60. package/dist/cmds/mtls-certificates/index.js.map +1 -1
  61. package/dist/tsconfig.tsbuildinfo +1 -1
  62. package/node_modules/@cfworker/json-schema/README.md +75 -0
  63. package/node_modules/@cfworker/json-schema/dist/commonjs/deep-compare-strict.d.ts +1 -0
  64. package/node_modules/@cfworker/json-schema/dist/commonjs/deep-compare-strict.js +42 -0
  65. package/node_modules/@cfworker/json-schema/dist/commonjs/dereference.d.ts +7 -0
  66. package/node_modules/@cfworker/json-schema/dist/commonjs/dereference.js +147 -0
  67. package/node_modules/@cfworker/json-schema/dist/commonjs/format.d.ts +1 -0
  68. package/node_modules/@cfworker/json-schema/dist/commonjs/format.js +111 -0
  69. package/node_modules/@cfworker/json-schema/dist/commonjs/index.d.ts +8 -0
  70. package/node_modules/@cfworker/json-schema/dist/commonjs/index.js +24 -0
  71. package/node_modules/@cfworker/json-schema/dist/commonjs/package.json +3 -0
  72. package/node_modules/@cfworker/json-schema/dist/commonjs/pointer.d.ts +2 -0
  73. package/node_modules/@cfworker/json-schema/dist/commonjs/pointer.js +10 -0
  74. package/node_modules/@cfworker/json-schema/dist/commonjs/types.d.ts +72 -0
  75. package/node_modules/@cfworker/json-schema/dist/commonjs/types.js +9 -0
  76. package/node_modules/@cfworker/json-schema/dist/commonjs/ucs2-length.d.ts +1 -0
  77. package/node_modules/@cfworker/json-schema/dist/commonjs/ucs2-length.js +20 -0
  78. package/node_modules/@cfworker/json-schema/dist/commonjs/validate.d.ts +3 -0
  79. package/node_modules/@cfworker/json-schema/dist/commonjs/validate.js +805 -0
  80. package/node_modules/@cfworker/json-schema/dist/commonjs/validator.d.ts +10 -0
  81. package/node_modules/@cfworker/json-schema/dist/commonjs/validator.js +27 -0
  82. package/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.d.ts +1 -0
  83. package/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js +39 -0
  84. package/node_modules/@cfworker/json-schema/dist/esm/dereference.d.ts +7 -0
  85. package/node_modules/@cfworker/json-schema/dist/esm/dereference.js +143 -0
  86. package/node_modules/@cfworker/json-schema/dist/esm/format.d.ts +1 -0
  87. package/node_modules/@cfworker/json-schema/dist/esm/format.js +108 -0
  88. package/node_modules/@cfworker/json-schema/dist/esm/index.d.ts +8 -0
  89. package/node_modules/@cfworker/json-schema/dist/esm/index.js +8 -0
  90. package/node_modules/@cfworker/json-schema/dist/esm/package.json +3 -0
  91. package/node_modules/@cfworker/json-schema/dist/esm/pointer.d.ts +2 -0
  92. package/node_modules/@cfworker/json-schema/dist/esm/pointer.js +6 -0
  93. package/node_modules/@cfworker/json-schema/dist/esm/types.d.ts +72 -0
  94. package/node_modules/@cfworker/json-schema/dist/esm/types.js +6 -0
  95. package/node_modules/@cfworker/json-schema/dist/esm/ucs2-length.d.ts +1 -0
  96. package/node_modules/@cfworker/json-schema/dist/esm/ucs2-length.js +17 -0
  97. package/node_modules/@cfworker/json-schema/dist/esm/validate.d.ts +3 -0
  98. package/node_modules/@cfworker/json-schema/dist/esm/validate.js +802 -0
  99. package/node_modules/@cfworker/json-schema/dist/esm/validator.d.ts +10 -0
  100. package/node_modules/@cfworker/json-schema/dist/esm/validator.js +23 -0
  101. package/node_modules/@cfworker/json-schema/package.json +68 -0
  102. package/node_modules/@cfworker/json-schema/src/deep-compare-strict.d.ts +1 -0
  103. package/node_modules/@cfworker/json-schema/src/deep-compare-strict.ts +39 -0
  104. package/node_modules/@cfworker/json-schema/src/dereference.d.ts +12 -0
  105. package/node_modules/@cfworker/json-schema/src/dereference.ts +188 -0
  106. package/node_modules/@cfworker/json-schema/src/format.d.ts +2 -0
  107. package/node_modules/@cfworker/json-schema/src/format.ts +164 -0
  108. package/node_modules/@cfworker/json-schema/src/index.d.ts +8 -0
  109. package/node_modules/@cfworker/json-schema/src/index.ts +8 -0
  110. package/node_modules/@cfworker/json-schema/src/pointer.d.ts +2 -0
  111. package/node_modules/@cfworker/json-schema/src/pointer.ts +7 -0
  112. package/node_modules/@cfworker/json-schema/src/types.d.ts +79 -0
  113. package/node_modules/@cfworker/json-schema/src/types.ts +92 -0
  114. package/node_modules/@cfworker/json-schema/src/ucs2-length.d.ts +1 -0
  115. package/node_modules/@cfworker/json-schema/src/ucs2-length.ts +24 -0
  116. package/node_modules/@cfworker/json-schema/src/validate.d.ts +13 -0
  117. package/node_modules/@cfworker/json-schema/src/validate.ts +1168 -0
  118. package/node_modules/@cfworker/json-schema/src/validator.d.ts +14 -0
  119. package/node_modules/@cfworker/json-schema/src/validator.ts +32 -0
  120. package/node_modules/@zuplo/core/package.json +1 -1
  121. package/node_modules/@zuplo/graphql/package.json +1 -1
  122. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  123. package/node_modules/@zuplo/otel/package.json +1 -1
  124. package/node_modules/@zuplo/runtime/out/esm/{chunk-YJ3VHQXF.js → chunk-2ZQVIVZ3.js} +2 -2
  125. package/node_modules/@zuplo/runtime/out/esm/{chunk-STBDRSX7.js → chunk-UMZORQLU.js} +67 -66
  126. package/node_modules/@zuplo/runtime/out/esm/chunk-UMZORQLU.js.map +1 -0
  127. package/node_modules/@zuplo/runtime/out/esm/{chunk-KWR5BV7H.js → chunk-YGYFQCBA.js} +6 -6
  128. package/node_modules/@zuplo/runtime/out/esm/chunk-YGYFQCBA.js.map +1 -0
  129. package/node_modules/@zuplo/runtime/out/esm/{chunk-NJNTFB34.js → chunk-ZS34EO4B.js} +2 -2
  130. package/node_modules/@zuplo/runtime/out/esm/{chunk-NJNTFB34.js.map → chunk-ZS34EO4B.js.map} +1 -1
  131. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  132. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  133. package/node_modules/@zuplo/runtime/out/esm/internal/index.js +1 -1
  134. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +208 -72
  135. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
  136. package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
  137. package/node_modules/@zuplo/runtime/out/types/index.d.ts +61 -12
  138. package/node_modules/@zuplo/runtime/out/types/mcp-gateway/index.d.ts +8 -17
  139. package/node_modules/@zuplo/runtime/out/types/mocks/index.d.ts +3 -12
  140. package/node_modules/@zuplo/runtime/package.json +3 -2
  141. package/node_modules/agent-base/README.md +145 -0
  142. package/node_modules/agent-base/dist/src/index.d.ts +78 -0
  143. package/node_modules/agent-base/dist/src/index.js +203 -0
  144. package/node_modules/agent-base/dist/src/index.js.map +1 -0
  145. package/node_modules/agent-base/dist/src/promisify.d.ts +4 -0
  146. package/node_modules/agent-base/dist/src/promisify.js +18 -0
  147. package/node_modules/agent-base/dist/src/promisify.js.map +1 -0
  148. package/node_modules/agent-base/package.json +64 -0
  149. package/node_modules/agent-base/src/index.ts +345 -0
  150. package/node_modules/agent-base/src/promisify.ts +33 -0
  151. package/node_modules/axios/CHANGELOG.md +71 -0
  152. package/node_modules/axios/README.md +46 -11
  153. package/node_modules/axios/dist/axios.js +81 -53
  154. package/node_modules/axios/dist/axios.js.map +1 -1
  155. package/node_modules/axios/dist/axios.min.js +2 -2
  156. package/node_modules/axios/dist/axios.min.js.map +1 -1
  157. package/node_modules/axios/dist/browser/axios.cjs +96 -64
  158. package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
  159. package/node_modules/axios/dist/esm/axios.js +96 -64
  160. package/node_modules/axios/dist/esm/axios.js.map +1 -1
  161. package/node_modules/axios/dist/esm/axios.min.js +2 -2
  162. package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
  163. package/node_modules/axios/dist/node/axios.cjs +206 -85
  164. package/node_modules/axios/dist/node/axios.cjs.map +1 -1
  165. package/node_modules/axios/index.d.cts +1 -1
  166. package/node_modules/axios/index.d.ts +1 -1
  167. package/node_modules/axios/lib/adapters/fetch.js +6 -2
  168. package/node_modules/axios/lib/adapters/http.js +139 -29
  169. package/node_modules/axios/lib/adapters/xhr.js +2 -1
  170. package/node_modules/axios/lib/core/AxiosHeaders.js +1 -33
  171. package/node_modules/axios/lib/env/data.js +1 -1
  172. package/node_modules/axios/lib/helpers/composeSignals.js +48 -47
  173. package/node_modules/axios/lib/helpers/formDataToJSON.js +1 -1
  174. package/node_modules/axios/lib/helpers/fromDataURI.js +18 -5
  175. package/node_modules/axios/lib/helpers/progressEventReducer.js +3 -0
  176. package/node_modules/axios/lib/helpers/sanitizeHeaderValue.js +60 -0
  177. package/node_modules/axios/lib/utils.js +8 -7
  178. package/node_modules/axios/package.json +3 -1
  179. package/node_modules/https-proxy-agent/README.md +137 -0
  180. package/node_modules/https-proxy-agent/dist/agent.d.ts +30 -0
  181. package/node_modules/https-proxy-agent/dist/agent.js +177 -0
  182. package/node_modules/https-proxy-agent/dist/agent.js.map +1 -0
  183. package/node_modules/https-proxy-agent/dist/index.d.ts +23 -0
  184. package/node_modules/https-proxy-agent/dist/index.js +14 -0
  185. package/node_modules/https-proxy-agent/dist/index.js.map +1 -0
  186. package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts +7 -0
  187. package/node_modules/https-proxy-agent/dist/parse-proxy-response.js +66 -0
  188. package/node_modules/https-proxy-agent/dist/parse-proxy-response.js.map +1 -0
  189. package/node_modules/https-proxy-agent/package.json +56 -0
  190. package/node_modules/type-is/index.js +8 -18
  191. package/node_modules/type-is/node_modules/content-type/LICENSE +22 -0
  192. package/node_modules/type-is/node_modules/content-type/README.md +69 -0
  193. package/node_modules/type-is/node_modules/content-type/dist/index.d.ts +26 -0
  194. package/node_modules/type-is/node_modules/content-type/dist/index.js +170 -0
  195. package/node_modules/type-is/node_modules/content-type/dist/index.js.map +1 -0
  196. package/node_modules/type-is/node_modules/content-type/package.json +52 -0
  197. package/node_modules/type-is/package.json +9 -5
  198. package/package.json +6 -6
  199. package/node_modules/@zuplo/runtime/out/esm/chunk-KWR5BV7H.js.map +0 -1
  200. package/node_modules/@zuplo/runtime/out/esm/chunk-STBDRSX7.js.map +0 -1
  201. /package/node_modules/@zuplo/runtime/out/esm/{chunk-YJ3VHQXF.js.map → chunk-2ZQVIVZ3.js.map} +0 -0
  202. /package/node_modules/@zuplo/runtime/out/esm/{chunk-STBDRSX7.js.LEGAL.txt → chunk-UMZORQLU.js.LEGAL.txt} +0 -0
  203. /package/node_modules/@zuplo/runtime/out/esm/{chunk-KWR5BV7H.js.LEGAL.txt → chunk-YGYFQCBA.js.LEGAL.txt} +0 -0
@@ -0,0 +1,1168 @@
1
+ import { deepCompareStrict } from './deep-compare-strict.js';
2
+ import { dereference } from './dereference.js';
3
+ import { format } from './format.js';
4
+ import { encodePointer } from './pointer.js';
5
+ import {
6
+ InstanceType,
7
+ OutputUnit,
8
+ Schema,
9
+ SchemaDraft,
10
+ ValidationResult
11
+ } from './types.js';
12
+ import { ucs2length } from './ucs2-length.js';
13
+
14
+ export type Evaluated = Record<string | number, boolean>;
15
+
16
+ export function validate(
17
+ instance: any,
18
+ schema: Schema | boolean,
19
+ draft: SchemaDraft = '2019-09',
20
+ lookup: Record<string, Schema | boolean> = dereference(schema),
21
+ shortCircuit = true,
22
+ recursiveAnchor: Schema | null = null,
23
+ instanceLocation = '#',
24
+ schemaLocation = '#',
25
+ evaluated: Evaluated = Object.create(null)
26
+ ): ValidationResult {
27
+ if (schema === true) {
28
+ return { valid: true, errors: [] };
29
+ }
30
+
31
+ if (schema === false) {
32
+ return {
33
+ valid: false,
34
+ errors: [
35
+ {
36
+ instanceLocation,
37
+ keyword: 'false',
38
+ keywordLocation: instanceLocation,
39
+ error: 'False boolean schema.'
40
+ }
41
+ ]
42
+ };
43
+ }
44
+
45
+ const rawInstanceType = typeof instance;
46
+ let instanceType: Exclude<InstanceType, 'integer'>;
47
+ switch (rawInstanceType) {
48
+ case 'boolean':
49
+ case 'number':
50
+ case 'string':
51
+ instanceType = rawInstanceType;
52
+ break;
53
+ case 'object':
54
+ if (instance === null) {
55
+ instanceType = 'null';
56
+ } else if (Array.isArray(instance)) {
57
+ instanceType = 'array';
58
+ } else {
59
+ instanceType = 'object';
60
+ }
61
+ break;
62
+ default:
63
+ // undefined, bigint, function, symbol
64
+ throw new Error(
65
+ `Instances of "${rawInstanceType}" type are not supported.`
66
+ );
67
+ }
68
+
69
+ const {
70
+ $ref,
71
+ $recursiveRef,
72
+ $recursiveAnchor,
73
+ type: $type,
74
+ const: $const,
75
+ enum: $enum,
76
+ required: $required,
77
+ not: $not,
78
+ anyOf: $anyOf,
79
+ allOf: $allOf,
80
+ oneOf: $oneOf,
81
+ if: $if,
82
+ then: $then,
83
+ else: $else,
84
+
85
+ format: $format,
86
+
87
+ properties: $properties,
88
+ patternProperties: $patternProperties,
89
+ additionalProperties: $additionalProperties,
90
+ unevaluatedProperties: $unevaluatedProperties,
91
+ minProperties: $minProperties,
92
+ maxProperties: $maxProperties,
93
+ propertyNames: $propertyNames,
94
+ dependentRequired: $dependentRequired,
95
+ dependentSchemas: $dependentSchemas,
96
+ dependencies: $dependencies,
97
+
98
+ prefixItems: $prefixItems,
99
+ items: $items,
100
+ additionalItems: $additionalItems,
101
+ unevaluatedItems: $unevaluatedItems,
102
+ contains: $contains,
103
+ minContains: $minContains,
104
+ maxContains: $maxContains,
105
+ minItems: $minItems,
106
+ maxItems: $maxItems,
107
+ uniqueItems: $uniqueItems,
108
+
109
+ minimum: $minimum,
110
+ maximum: $maximum,
111
+ exclusiveMinimum: $exclusiveMinimum,
112
+ exclusiveMaximum: $exclusiveMaximum,
113
+ multipleOf: $multipleOf,
114
+
115
+ minLength: $minLength,
116
+ maxLength: $maxLength,
117
+ pattern: $pattern,
118
+
119
+ __absolute_ref__,
120
+ __absolute_recursive_ref__
121
+ } = schema;
122
+
123
+ const errors: OutputUnit[] = [];
124
+
125
+ if ($recursiveAnchor === true && recursiveAnchor === null) {
126
+ recursiveAnchor = schema;
127
+ }
128
+
129
+ if ($recursiveRef === '#') {
130
+ const refSchema =
131
+ recursiveAnchor === null
132
+ ? (lookup[__absolute_recursive_ref__!] as Schema)
133
+ : recursiveAnchor;
134
+ const keywordLocation = `${schemaLocation}/$recursiveRef`;
135
+ const result = validate(
136
+ instance,
137
+ recursiveAnchor === null ? schema : recursiveAnchor,
138
+ draft,
139
+ lookup,
140
+ shortCircuit,
141
+ refSchema,
142
+ instanceLocation,
143
+ keywordLocation,
144
+ evaluated
145
+ );
146
+ if (!result.valid) {
147
+ errors.push(
148
+ {
149
+ instanceLocation,
150
+ keyword: '$recursiveRef',
151
+ keywordLocation,
152
+ error: 'A subschema had errors.'
153
+ },
154
+ ...result.errors
155
+ );
156
+ }
157
+ }
158
+
159
+ if ($ref !== undefined) {
160
+ const uri = __absolute_ref__ || $ref;
161
+ const refSchema = lookup[uri];
162
+ if (refSchema === undefined) {
163
+ let message = `Unresolved $ref "${$ref}".`;
164
+ if (__absolute_ref__ && __absolute_ref__ !== $ref) {
165
+ message += ` Absolute URI "${__absolute_ref__}".`;
166
+ }
167
+ message += `\nKnown schemas:\n- ${Object.keys(lookup).join('\n- ')}`;
168
+ throw new Error(message);
169
+ }
170
+ const keywordLocation = `${schemaLocation}/$ref`;
171
+ const result = validate(
172
+ instance,
173
+ refSchema,
174
+ draft,
175
+ lookup,
176
+ shortCircuit,
177
+ recursiveAnchor,
178
+ instanceLocation,
179
+ keywordLocation,
180
+ evaluated
181
+ );
182
+ if (!result.valid) {
183
+ errors.push(
184
+ {
185
+ instanceLocation,
186
+ keyword: '$ref',
187
+ keywordLocation,
188
+ error: 'A subschema had errors.'
189
+ },
190
+ ...result.errors
191
+ );
192
+ }
193
+ if (draft === '4' || draft === '7') {
194
+ return { valid: errors.length === 0, errors };
195
+ }
196
+ }
197
+
198
+ if (Array.isArray($type)) {
199
+ let length = $type.length;
200
+ let valid = false;
201
+ for (let i = 0; i < length; i++) {
202
+ if (
203
+ instanceType === $type[i] ||
204
+ ($type[i] === 'integer' &&
205
+ instanceType === 'number' &&
206
+ instance % 1 === 0 &&
207
+ instance === instance)
208
+ ) {
209
+ valid = true;
210
+ break;
211
+ }
212
+ }
213
+ if (!valid) {
214
+ errors.push({
215
+ instanceLocation,
216
+ keyword: 'type',
217
+ keywordLocation: `${schemaLocation}/type`,
218
+ error: `Instance type "${instanceType}" is invalid. Expected "${$type.join(
219
+ '", "'
220
+ )}".`
221
+ });
222
+ }
223
+ } else if ($type === 'integer') {
224
+ if (instanceType !== 'number' || instance % 1 || instance !== instance) {
225
+ errors.push({
226
+ instanceLocation,
227
+ keyword: 'type',
228
+ keywordLocation: `${schemaLocation}/type`,
229
+ error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`
230
+ });
231
+ }
232
+ } else if ($type !== undefined && instanceType !== $type) {
233
+ errors.push({
234
+ instanceLocation,
235
+ keyword: 'type',
236
+ keywordLocation: `${schemaLocation}/type`,
237
+ error: `Instance type "${instanceType}" is invalid. Expected "${$type}".`
238
+ });
239
+ }
240
+
241
+ if ($const !== undefined) {
242
+ if (instanceType === 'object' || instanceType === 'array') {
243
+ if (!deepCompareStrict(instance, $const)) {
244
+ errors.push({
245
+ instanceLocation,
246
+ keyword: 'const',
247
+ keywordLocation: `${schemaLocation}/const`,
248
+ error: `Instance does not match ${JSON.stringify($const)}.`
249
+ });
250
+ }
251
+ } else if (instance !== $const) {
252
+ errors.push({
253
+ instanceLocation,
254
+ keyword: 'const',
255
+ keywordLocation: `${schemaLocation}/const`,
256
+ error: `Instance does not match ${JSON.stringify($const)}.`
257
+ });
258
+ }
259
+ }
260
+
261
+ if ($enum !== undefined) {
262
+ if (instanceType === 'object' || instanceType === 'array') {
263
+ if (!$enum.some(value => deepCompareStrict(instance, value))) {
264
+ errors.push({
265
+ instanceLocation,
266
+ keyword: 'enum',
267
+ keywordLocation: `${schemaLocation}/enum`,
268
+ error: `Instance does not match any of ${JSON.stringify($enum)}.`
269
+ });
270
+ }
271
+ } else if (!$enum.some(value => instance === value)) {
272
+ errors.push({
273
+ instanceLocation,
274
+ keyword: 'enum',
275
+ keywordLocation: `${schemaLocation}/enum`,
276
+ error: `Instance does not match any of ${JSON.stringify($enum)}.`
277
+ });
278
+ }
279
+ }
280
+
281
+ if ($not !== undefined) {
282
+ const keywordLocation = `${schemaLocation}/not`;
283
+ const result = validate(
284
+ instance,
285
+ $not,
286
+ draft,
287
+ lookup,
288
+ shortCircuit,
289
+ recursiveAnchor,
290
+ instanceLocation,
291
+ keywordLocation /*,
292
+ evaluated*/
293
+ );
294
+ if (result.valid) {
295
+ errors.push({
296
+ instanceLocation,
297
+ keyword: 'not',
298
+ keywordLocation,
299
+ error: 'Instance matched "not" schema.'
300
+ });
301
+ }
302
+ }
303
+
304
+ let subEvaluateds: Array<Evaluated> = [];
305
+
306
+ if ($anyOf !== undefined) {
307
+ const keywordLocation = `${schemaLocation}/anyOf`;
308
+ const errorsLength = errors.length;
309
+ let anyValid = false;
310
+ for (let i = 0; i < $anyOf.length; i++) {
311
+ const subSchema = $anyOf[i];
312
+ const subEvaluated: Evaluated = Object.create(evaluated);
313
+ const result = validate(
314
+ instance,
315
+ subSchema,
316
+ draft,
317
+ lookup,
318
+ shortCircuit,
319
+ $recursiveAnchor === true ? recursiveAnchor : null,
320
+ instanceLocation,
321
+ `${keywordLocation}/${i}`,
322
+ subEvaluated
323
+ );
324
+ errors.push(...result.errors);
325
+ anyValid = anyValid || result.valid;
326
+ if (result.valid) {
327
+ subEvaluateds.push(subEvaluated);
328
+ }
329
+ }
330
+ if (anyValid) {
331
+ errors.length = errorsLength;
332
+ } else {
333
+ errors.splice(errorsLength, 0, {
334
+ instanceLocation,
335
+ keyword: 'anyOf',
336
+ keywordLocation,
337
+ error: 'Instance does not match any subschemas.'
338
+ });
339
+ }
340
+ }
341
+
342
+ if ($allOf !== undefined) {
343
+ const keywordLocation = `${schemaLocation}/allOf`;
344
+ const errorsLength = errors.length;
345
+ let allValid = true;
346
+ for (let i = 0; i < $allOf.length; i++) {
347
+ const subSchema = $allOf[i];
348
+ const subEvaluated: Evaluated = Object.create(evaluated);
349
+ const result = validate(
350
+ instance,
351
+ subSchema,
352
+ draft,
353
+ lookup,
354
+ shortCircuit,
355
+ $recursiveAnchor === true ? recursiveAnchor : null,
356
+ instanceLocation,
357
+ `${keywordLocation}/${i}`,
358
+ subEvaluated
359
+ );
360
+ errors.push(...result.errors);
361
+ allValid = allValid && result.valid;
362
+ if (result.valid) {
363
+ subEvaluateds.push(subEvaluated);
364
+ }
365
+ }
366
+ if (allValid) {
367
+ errors.length = errorsLength;
368
+ } else {
369
+ errors.splice(errorsLength, 0, {
370
+ instanceLocation,
371
+ keyword: 'allOf',
372
+ keywordLocation,
373
+ error: `Instance does not match every subschema.`
374
+ });
375
+ }
376
+ }
377
+
378
+ if ($oneOf !== undefined) {
379
+ const keywordLocation = `${schemaLocation}/oneOf`;
380
+ const errorsLength = errors.length;
381
+ const matches = $oneOf.filter((subSchema, i) => {
382
+ const subEvaluated: Evaluated = Object.create(evaluated);
383
+ const result = validate(
384
+ instance,
385
+ subSchema,
386
+ draft,
387
+ lookup,
388
+ shortCircuit,
389
+ $recursiveAnchor === true ? recursiveAnchor : null,
390
+ instanceLocation,
391
+ `${keywordLocation}/${i}`,
392
+ subEvaluated
393
+ );
394
+ errors.push(...result.errors);
395
+ if (result.valid) {
396
+ subEvaluateds.push(subEvaluated);
397
+ }
398
+ return result.valid;
399
+ }).length;
400
+ if (matches === 1) {
401
+ errors.length = errorsLength;
402
+ } else {
403
+ errors.splice(errorsLength, 0, {
404
+ instanceLocation,
405
+ keyword: 'oneOf',
406
+ keywordLocation,
407
+ error: `Instance does not match exactly one subschema (${matches} matches).`
408
+ });
409
+ }
410
+ }
411
+
412
+ if (instanceType === 'object' || instanceType === 'array') {
413
+ Object.assign(evaluated, ...subEvaluateds);
414
+ }
415
+
416
+ if ($if !== undefined) {
417
+ const keywordLocation = `${schemaLocation}/if`;
418
+ const conditionResult = validate(
419
+ instance,
420
+ $if,
421
+ draft,
422
+ lookup,
423
+ shortCircuit,
424
+ recursiveAnchor,
425
+ instanceLocation,
426
+ keywordLocation,
427
+ evaluated
428
+ ).valid;
429
+ if (conditionResult) {
430
+ if ($then !== undefined) {
431
+ const thenResult = validate(
432
+ instance,
433
+ $then,
434
+ draft,
435
+ lookup,
436
+ shortCircuit,
437
+ recursiveAnchor,
438
+ instanceLocation,
439
+ `${schemaLocation}/then`,
440
+ evaluated
441
+ );
442
+ if (!thenResult.valid) {
443
+ errors.push(
444
+ {
445
+ instanceLocation,
446
+ keyword: 'if',
447
+ keywordLocation,
448
+ error: `Instance does not match "then" schema.`
449
+ },
450
+ ...thenResult.errors
451
+ );
452
+ }
453
+ }
454
+ } else if ($else !== undefined) {
455
+ const elseResult = validate(
456
+ instance,
457
+ $else,
458
+ draft,
459
+ lookup,
460
+ shortCircuit,
461
+ recursiveAnchor,
462
+ instanceLocation,
463
+ `${schemaLocation}/else`,
464
+ evaluated
465
+ );
466
+ if (!elseResult.valid) {
467
+ errors.push(
468
+ {
469
+ instanceLocation,
470
+ keyword: 'if',
471
+ keywordLocation,
472
+ error: `Instance does not match "else" schema.`
473
+ },
474
+ ...elseResult.errors
475
+ );
476
+ }
477
+ }
478
+ }
479
+
480
+ if (instanceType === 'object') {
481
+ if ($required !== undefined) {
482
+ for (const key of $required) {
483
+ if (!(key in instance)) {
484
+ errors.push({
485
+ instanceLocation,
486
+ keyword: 'required',
487
+ keywordLocation: `${schemaLocation}/required`,
488
+ error: `Instance does not have required property "${key}".`
489
+ });
490
+ }
491
+ }
492
+ }
493
+
494
+ const keys = Object.keys(instance);
495
+
496
+ if ($minProperties !== undefined && keys.length < $minProperties) {
497
+ errors.push({
498
+ instanceLocation,
499
+ keyword: 'minProperties',
500
+ keywordLocation: `${schemaLocation}/minProperties`,
501
+ error: `Instance does not have at least ${$minProperties} properties.`
502
+ });
503
+ }
504
+
505
+ if ($maxProperties !== undefined && keys.length > $maxProperties) {
506
+ errors.push({
507
+ instanceLocation,
508
+ keyword: 'maxProperties',
509
+ keywordLocation: `${schemaLocation}/maxProperties`,
510
+ error: `Instance does not have at least ${$maxProperties} properties.`
511
+ });
512
+ }
513
+
514
+ if ($propertyNames !== undefined) {
515
+ const keywordLocation = `${schemaLocation}/propertyNames`;
516
+ for (const key in instance) {
517
+ const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
518
+ const result = validate(
519
+ key,
520
+ $propertyNames,
521
+ draft,
522
+ lookup,
523
+ shortCircuit,
524
+ recursiveAnchor,
525
+ subInstancePointer,
526
+ keywordLocation
527
+ );
528
+ if (!result.valid) {
529
+ errors.push(
530
+ {
531
+ instanceLocation,
532
+ keyword: 'propertyNames',
533
+ keywordLocation,
534
+ error: `Property name "${key}" does not match schema.`
535
+ },
536
+ ...result.errors
537
+ );
538
+ }
539
+ }
540
+ }
541
+
542
+ if ($dependentRequired !== undefined) {
543
+ const keywordLocation = `${schemaLocation}/dependantRequired`;
544
+ for (const key in $dependentRequired) {
545
+ if (key in instance) {
546
+ const required = $dependentRequired[key] as string[];
547
+ for (const dependantKey of required) {
548
+ if (!(dependantKey in instance)) {
549
+ errors.push({
550
+ instanceLocation,
551
+ keyword: 'dependentRequired',
552
+ keywordLocation,
553
+ error: `Instance has "${key}" but does not have "${dependantKey}".`
554
+ });
555
+ }
556
+ }
557
+ }
558
+ }
559
+ }
560
+
561
+ if ($dependentSchemas !== undefined) {
562
+ for (const key in $dependentSchemas) {
563
+ const keywordLocation = `${schemaLocation}/dependentSchemas`;
564
+ if (key in instance) {
565
+ const result = validate(
566
+ instance,
567
+ $dependentSchemas[key],
568
+ draft,
569
+ lookup,
570
+ shortCircuit,
571
+ recursiveAnchor,
572
+ instanceLocation,
573
+ `${keywordLocation}/${encodePointer(key)}`,
574
+ evaluated
575
+ );
576
+ if (!result.valid) {
577
+ errors.push(
578
+ {
579
+ instanceLocation,
580
+ keyword: 'dependentSchemas',
581
+ keywordLocation,
582
+ error: `Instance has "${key}" but does not match dependant schema.`
583
+ },
584
+ ...result.errors
585
+ );
586
+ }
587
+ }
588
+ }
589
+ }
590
+
591
+ if ($dependencies !== undefined) {
592
+ const keywordLocation = `${schemaLocation}/dependencies`;
593
+ for (const key in $dependencies) {
594
+ if (key in instance) {
595
+ const propsOrSchema = $dependencies[key] as Schema | string[];
596
+ if (Array.isArray(propsOrSchema)) {
597
+ for (const dependantKey of propsOrSchema) {
598
+ if (!(dependantKey in instance)) {
599
+ errors.push({
600
+ instanceLocation,
601
+ keyword: 'dependencies',
602
+ keywordLocation,
603
+ error: `Instance has "${key}" but does not have "${dependantKey}".`
604
+ });
605
+ }
606
+ }
607
+ } else {
608
+ const result = validate(
609
+ instance,
610
+ propsOrSchema,
611
+ draft,
612
+ lookup,
613
+ shortCircuit,
614
+ recursiveAnchor,
615
+ instanceLocation,
616
+ `${keywordLocation}/${encodePointer(key)}`
617
+ );
618
+ if (!result.valid) {
619
+ errors.push(
620
+ {
621
+ instanceLocation,
622
+ keyword: 'dependencies',
623
+ keywordLocation,
624
+ error: `Instance has "${key}" but does not match dependant schema.`
625
+ },
626
+ ...result.errors
627
+ );
628
+ }
629
+ }
630
+ }
631
+ }
632
+ }
633
+
634
+ const thisEvaluated = Object.create(null);
635
+
636
+ let stop = false;
637
+
638
+ if ($properties !== undefined) {
639
+ const keywordLocation = `${schemaLocation}/properties`;
640
+ for (const key in $properties) {
641
+ if (!(key in instance)) {
642
+ continue;
643
+ }
644
+ const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
645
+ const result = validate(
646
+ instance[key],
647
+ $properties[key],
648
+ draft,
649
+ lookup,
650
+ shortCircuit,
651
+ recursiveAnchor,
652
+ subInstancePointer,
653
+ `${keywordLocation}/${encodePointer(key)}`
654
+ );
655
+ if (result.valid) {
656
+ evaluated[key] = thisEvaluated[key] = true;
657
+ } else {
658
+ stop = shortCircuit;
659
+ errors.push(
660
+ {
661
+ instanceLocation,
662
+ keyword: 'properties',
663
+ keywordLocation,
664
+ error: `Property "${key}" does not match schema.`
665
+ },
666
+ ...result.errors
667
+ );
668
+ if (stop) break;
669
+ }
670
+ }
671
+ }
672
+
673
+ if (!stop && $patternProperties !== undefined) {
674
+ const keywordLocation = `${schemaLocation}/patternProperties`;
675
+ for (const pattern in $patternProperties) {
676
+ const regex = new RegExp(pattern, 'u');
677
+ const subSchema = $patternProperties[pattern];
678
+ for (const key in instance) {
679
+ if (!regex.test(key)) {
680
+ continue;
681
+ }
682
+ const subInstancePointer = `${instanceLocation}/${encodePointer(
683
+ key
684
+ )}`;
685
+ const result = validate(
686
+ instance[key],
687
+ subSchema,
688
+ draft,
689
+ lookup,
690
+ shortCircuit,
691
+ recursiveAnchor,
692
+ subInstancePointer,
693
+ `${keywordLocation}/${encodePointer(pattern)}`
694
+ );
695
+ if (result.valid) {
696
+ evaluated[key] = thisEvaluated[key] = true;
697
+ } else {
698
+ stop = shortCircuit;
699
+ errors.push(
700
+ {
701
+ instanceLocation,
702
+ keyword: 'patternProperties',
703
+ keywordLocation,
704
+ error: `Property "${key}" matches pattern "${pattern}" but does not match associated schema.`
705
+ },
706
+ ...result.errors
707
+ );
708
+ }
709
+ }
710
+ }
711
+ }
712
+
713
+ if (!stop && $additionalProperties !== undefined) {
714
+ const keywordLocation = `${schemaLocation}/additionalProperties`;
715
+ for (const key in instance) {
716
+ if (thisEvaluated[key]) {
717
+ continue;
718
+ }
719
+ const subInstancePointer = `${instanceLocation}/${encodePointer(key)}`;
720
+ const result = validate(
721
+ instance[key],
722
+ $additionalProperties,
723
+ draft,
724
+ lookup,
725
+ shortCircuit,
726
+ recursiveAnchor,
727
+ subInstancePointer,
728
+ keywordLocation
729
+ );
730
+ if (result.valid) {
731
+ evaluated[key] = true;
732
+ } else {
733
+ stop = shortCircuit;
734
+ errors.push(
735
+ {
736
+ instanceLocation,
737
+ keyword: 'additionalProperties',
738
+ keywordLocation,
739
+ error: `Property "${key}" does not match additional properties schema.`
740
+ },
741
+ ...result.errors
742
+ );
743
+ }
744
+ }
745
+ } else if (!stop && $unevaluatedProperties !== undefined) {
746
+ const keywordLocation = `${schemaLocation}/unevaluatedProperties`;
747
+ for (const key in instance) {
748
+ if (!evaluated[key]) {
749
+ const subInstancePointer = `${instanceLocation}/${encodePointer(
750
+ key
751
+ )}`;
752
+ const result = validate(
753
+ instance[key],
754
+ $unevaluatedProperties,
755
+ draft,
756
+ lookup,
757
+ shortCircuit,
758
+ recursiveAnchor,
759
+ subInstancePointer,
760
+ keywordLocation
761
+ );
762
+ if (result.valid) {
763
+ evaluated[key] = true;
764
+ } else {
765
+ errors.push(
766
+ {
767
+ instanceLocation,
768
+ keyword: 'unevaluatedProperties',
769
+ keywordLocation,
770
+ error: `Property "${key}" does not match unevaluated properties schema.`
771
+ },
772
+ ...result.errors
773
+ );
774
+ }
775
+ }
776
+ }
777
+ }
778
+ } else if (instanceType === 'array') {
779
+ if ($maxItems !== undefined && instance.length > $maxItems) {
780
+ errors.push({
781
+ instanceLocation,
782
+ keyword: 'maxItems',
783
+ keywordLocation: `${schemaLocation}/maxItems`,
784
+ error: `Array has too many items (${instance.length} > ${$maxItems}).`
785
+ });
786
+ }
787
+
788
+ if ($minItems !== undefined && instance.length < $minItems) {
789
+ errors.push({
790
+ instanceLocation,
791
+ keyword: 'minItems',
792
+ keywordLocation: `${schemaLocation}/minItems`,
793
+ error: `Array has too few items (${instance.length} < ${$minItems}).`
794
+ });
795
+ }
796
+
797
+ const length: number = instance.length;
798
+ let i = 0;
799
+ let stop = false;
800
+
801
+ if ($prefixItems !== undefined) {
802
+ const keywordLocation = `${schemaLocation}/prefixItems`;
803
+ const length2 = Math.min($prefixItems.length, length);
804
+ for (; i < length2; i++) {
805
+ const result = validate(
806
+ instance[i],
807
+ $prefixItems[i],
808
+ draft,
809
+ lookup,
810
+ shortCircuit,
811
+ recursiveAnchor,
812
+ `${instanceLocation}/${i}`,
813
+ `${keywordLocation}/${i}`
814
+ );
815
+ evaluated[i] = true;
816
+ if (!result.valid) {
817
+ stop = shortCircuit;
818
+ errors.push(
819
+ {
820
+ instanceLocation,
821
+ keyword: 'prefixItems',
822
+ keywordLocation,
823
+ error: `Items did not match schema.`
824
+ },
825
+ ...result.errors
826
+ );
827
+ if (stop) break;
828
+ }
829
+ }
830
+ }
831
+
832
+ if ($items !== undefined) {
833
+ const keywordLocation = `${schemaLocation}/items`;
834
+ if (Array.isArray($items)) {
835
+ const length2 = Math.min($items.length, length);
836
+ for (; i < length2; i++) {
837
+ const result = validate(
838
+ instance[i],
839
+ $items[i],
840
+ draft,
841
+ lookup,
842
+ shortCircuit,
843
+ recursiveAnchor,
844
+ `${instanceLocation}/${i}`,
845
+ `${keywordLocation}/${i}`
846
+ );
847
+ evaluated[i] = true;
848
+ if (!result.valid) {
849
+ stop = shortCircuit;
850
+ errors.push(
851
+ {
852
+ instanceLocation,
853
+ keyword: 'items',
854
+ keywordLocation,
855
+ error: `Items did not match schema.`
856
+ },
857
+ ...result.errors
858
+ );
859
+ if (stop) break;
860
+ }
861
+ }
862
+ } else {
863
+ for (; i < length; i++) {
864
+ const result = validate(
865
+ instance[i],
866
+ $items,
867
+ draft,
868
+ lookup,
869
+ shortCircuit,
870
+ recursiveAnchor,
871
+ `${instanceLocation}/${i}`,
872
+ keywordLocation
873
+ );
874
+ evaluated[i] = true;
875
+ if (!result.valid) {
876
+ stop = shortCircuit;
877
+ errors.push(
878
+ {
879
+ instanceLocation,
880
+ keyword: 'items',
881
+ keywordLocation,
882
+ error: `Items did not match schema.`
883
+ },
884
+ ...result.errors
885
+ );
886
+ if (stop) break;
887
+ }
888
+ }
889
+ }
890
+
891
+ if (!stop && $additionalItems !== undefined) {
892
+ const keywordLocation = `${schemaLocation}/additionalItems`;
893
+ for (; i < length; i++) {
894
+ const result = validate(
895
+ instance[i],
896
+ $additionalItems,
897
+ draft,
898
+ lookup,
899
+ shortCircuit,
900
+ recursiveAnchor,
901
+ `${instanceLocation}/${i}`,
902
+ keywordLocation
903
+ );
904
+ evaluated[i] = true;
905
+ if (!result.valid) {
906
+ stop = shortCircuit;
907
+ errors.push(
908
+ {
909
+ instanceLocation,
910
+ keyword: 'additionalItems',
911
+ keywordLocation,
912
+ error: `Items did not match additional items schema.`
913
+ },
914
+ ...result.errors
915
+ );
916
+ }
917
+ }
918
+ }
919
+ }
920
+
921
+ if ($contains !== undefined) {
922
+ if (length === 0 && $minContains === undefined) {
923
+ errors.push({
924
+ instanceLocation,
925
+ keyword: 'contains',
926
+ keywordLocation: `${schemaLocation}/contains`,
927
+ error: `Array is empty. It must contain at least one item matching the schema.`
928
+ });
929
+ } else if ($minContains !== undefined && length < $minContains) {
930
+ errors.push({
931
+ instanceLocation,
932
+ keyword: 'minContains',
933
+ keywordLocation: `${schemaLocation}/minContains`,
934
+ error: `Array has less items (${length}) than minContains (${$minContains}).`
935
+ });
936
+ } else {
937
+ const keywordLocation = `${schemaLocation}/contains`;
938
+ const errorsLength = errors.length;
939
+ let contained = 0;
940
+ for (let j = 0; j < length; j++) {
941
+ const result = validate(
942
+ instance[j],
943
+ $contains,
944
+ draft,
945
+ lookup,
946
+ shortCircuit,
947
+ recursiveAnchor,
948
+ `${instanceLocation}/${j}`,
949
+ keywordLocation
950
+ );
951
+ if (result.valid) {
952
+ evaluated[j] = true;
953
+ contained++;
954
+ } else {
955
+ errors.push(...result.errors);
956
+ }
957
+ }
958
+
959
+ if (contained >= ($minContains || 0)) {
960
+ errors.length = errorsLength;
961
+ }
962
+
963
+ if (
964
+ $minContains === undefined &&
965
+ $maxContains === undefined &&
966
+ contained === 0
967
+ ) {
968
+ errors.splice(errorsLength, 0, {
969
+ instanceLocation,
970
+ keyword: 'contains',
971
+ keywordLocation,
972
+ error: `Array does not contain item matching schema.`
973
+ });
974
+ } else if ($minContains !== undefined && contained < $minContains) {
975
+ errors.push({
976
+ instanceLocation,
977
+ keyword: 'minContains',
978
+ keywordLocation: `${schemaLocation}/minContains`,
979
+ error: `Array must contain at least ${$minContains} items matching schema. Only ${contained} items were found.`
980
+ });
981
+ } else if ($maxContains !== undefined && contained > $maxContains) {
982
+ errors.push({
983
+ instanceLocation,
984
+ keyword: 'maxContains',
985
+ keywordLocation: `${schemaLocation}/maxContains`,
986
+ error: `Array may contain at most ${$maxContains} items matching schema. ${contained} items were found.`
987
+ });
988
+ }
989
+ }
990
+ }
991
+
992
+ if (!stop && $unevaluatedItems !== undefined) {
993
+ const keywordLocation = `${schemaLocation}/unevaluatedItems`;
994
+ for (i; i < length; i++) {
995
+ if (evaluated[i]) {
996
+ continue;
997
+ }
998
+ const result = validate(
999
+ instance[i],
1000
+ $unevaluatedItems,
1001
+ draft,
1002
+ lookup,
1003
+ shortCircuit,
1004
+ recursiveAnchor,
1005
+ `${instanceLocation}/${i}`,
1006
+ keywordLocation
1007
+ );
1008
+ evaluated[i] = true;
1009
+ if (!result.valid) {
1010
+ errors.push(
1011
+ {
1012
+ instanceLocation,
1013
+ keyword: 'unevaluatedItems',
1014
+ keywordLocation,
1015
+ error: `Items did not match unevaluated items schema.`
1016
+ },
1017
+ ...result.errors
1018
+ );
1019
+ }
1020
+ }
1021
+ }
1022
+
1023
+ if ($uniqueItems) {
1024
+ for (let j = 0; j < length; j++) {
1025
+ const a = instance[j];
1026
+ const ao = typeof a === 'object' && a !== null;
1027
+ for (let k = 0; k < length; k++) {
1028
+ if (j === k) {
1029
+ continue;
1030
+ }
1031
+ const b = instance[k];
1032
+ const bo = typeof b === 'object' && b !== null;
1033
+ if (a === b || (ao && bo && deepCompareStrict(a, b))) {
1034
+ errors.push({
1035
+ instanceLocation,
1036
+ keyword: 'uniqueItems',
1037
+ keywordLocation: `${schemaLocation}/uniqueItems`,
1038
+ error: `Duplicate items at indexes ${j} and ${k}.`
1039
+ });
1040
+ j = Number.MAX_SAFE_INTEGER;
1041
+ k = Number.MAX_SAFE_INTEGER;
1042
+ }
1043
+ }
1044
+ }
1045
+ }
1046
+ } else if (instanceType === 'number') {
1047
+ if (draft === '4') {
1048
+ if (
1049
+ $minimum !== undefined &&
1050
+ (($exclusiveMinimum === true && instance <= $minimum) ||
1051
+ instance < $minimum)
1052
+ ) {
1053
+ errors.push({
1054
+ instanceLocation,
1055
+ keyword: 'minimum',
1056
+ keywordLocation: `${schemaLocation}/minimum`,
1057
+ error: `${instance} is less than ${
1058
+ $exclusiveMinimum ? 'or equal to ' : ''
1059
+ } ${$minimum}.`
1060
+ });
1061
+ }
1062
+ if (
1063
+ $maximum !== undefined &&
1064
+ (($exclusiveMaximum === true && instance >= $maximum) ||
1065
+ instance > $maximum)
1066
+ ) {
1067
+ errors.push({
1068
+ instanceLocation,
1069
+ keyword: 'maximum',
1070
+ keywordLocation: `${schemaLocation}/maximum`,
1071
+ error: `${instance} is greater than ${
1072
+ $exclusiveMaximum ? 'or equal to ' : ''
1073
+ } ${$maximum}.`
1074
+ });
1075
+ }
1076
+ } else {
1077
+ if ($minimum !== undefined && instance < $minimum) {
1078
+ errors.push({
1079
+ instanceLocation,
1080
+ keyword: 'minimum',
1081
+ keywordLocation: `${schemaLocation}/minimum`,
1082
+ error: `${instance} is less than ${$minimum}.`
1083
+ });
1084
+ }
1085
+ if ($maximum !== undefined && instance > $maximum) {
1086
+ errors.push({
1087
+ instanceLocation,
1088
+ keyword: 'maximum',
1089
+ keywordLocation: `${schemaLocation}/maximum`,
1090
+ error: `${instance} is greater than ${$maximum}.`
1091
+ });
1092
+ }
1093
+ if ($exclusiveMinimum !== undefined && instance <= $exclusiveMinimum) {
1094
+ errors.push({
1095
+ instanceLocation,
1096
+ keyword: 'exclusiveMinimum',
1097
+ keywordLocation: `${schemaLocation}/exclusiveMinimum`,
1098
+ error: `${instance} is less than ${$exclusiveMinimum}.`
1099
+ });
1100
+ }
1101
+ if ($exclusiveMaximum !== undefined && instance >= $exclusiveMaximum) {
1102
+ errors.push({
1103
+ instanceLocation,
1104
+ keyword: 'exclusiveMaximum',
1105
+ keywordLocation: `${schemaLocation}/exclusiveMaximum`,
1106
+ error: `${instance} is greater than or equal to ${$exclusiveMaximum}.`
1107
+ });
1108
+ }
1109
+ }
1110
+ if ($multipleOf !== undefined) {
1111
+ const remainder = instance % $multipleOf;
1112
+ if (
1113
+ Math.abs(0 - remainder) >= 1.1920929e-7 &&
1114
+ Math.abs($multipleOf - remainder) >= 1.1920929e-7
1115
+ ) {
1116
+ errors.push({
1117
+ instanceLocation,
1118
+ keyword: 'multipleOf',
1119
+ keywordLocation: `${schemaLocation}/multipleOf`,
1120
+ error: `${instance} is not a multiple of ${$multipleOf}.`
1121
+ });
1122
+ }
1123
+ }
1124
+ } else if (instanceType === 'string') {
1125
+ const length =
1126
+ $minLength === undefined && $maxLength === undefined
1127
+ ? 0
1128
+ : ucs2length(instance);
1129
+ if ($minLength !== undefined && length < $minLength) {
1130
+ errors.push({
1131
+ instanceLocation,
1132
+ keyword: 'minLength',
1133
+ keywordLocation: `${schemaLocation}/minLength`,
1134
+ error: `String is too short (${length} < ${$minLength}).`
1135
+ });
1136
+ }
1137
+ if ($maxLength !== undefined && length > $maxLength) {
1138
+ errors.push({
1139
+ instanceLocation,
1140
+ keyword: 'maxLength',
1141
+ keywordLocation: `${schemaLocation}/maxLength`,
1142
+ error: `String is too long (${length} > ${$maxLength}).`
1143
+ });
1144
+ }
1145
+ if ($pattern !== undefined && !new RegExp($pattern, 'u').test(instance)) {
1146
+ errors.push({
1147
+ instanceLocation,
1148
+ keyword: 'pattern',
1149
+ keywordLocation: `${schemaLocation}/pattern`,
1150
+ error: `String does not match pattern.`
1151
+ });
1152
+ }
1153
+ if (
1154
+ $format !== undefined &&
1155
+ format[$format] &&
1156
+ !format[$format](instance)
1157
+ ) {
1158
+ errors.push({
1159
+ instanceLocation,
1160
+ keyword: 'format',
1161
+ keywordLocation: `${schemaLocation}/format`,
1162
+ error: `String does not match format "${$format}".`
1163
+ });
1164
+ }
1165
+ }
1166
+
1167
+ return { valid: errors.length === 0, errors };
1168
+ }