@conduit-client/jsonschema-validate 5.67.0-dev1

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/LICENSE.txt ADDED
@@ -0,0 +1,27 @@
1
+ *Attorney/Client Privileged + Confidential*
2
+
3
+ Terms of Use for Public Code (Non-OSS)
4
+
5
+ *NOTE:* Before publishing code under this license/these Terms of Use, please review https://salesforce.quip.com/WFfvAMKB18AL and confirm that you’ve completed all prerequisites described therein. *These Terms of Use may not be used or modified without input from IP and Product Legal.*
6
+
7
+ *Terms of Use*
8
+
9
+ Copyright 2022 Salesforce, Inc. All rights reserved.
10
+
11
+ These Terms of Use govern the download, installation, and/or use of this software provided by Salesforce, Inc. (“Salesforce”) (the “Software”), were last updated on April 15, 2022, ** and constitute a legally binding agreement between you and Salesforce. If you do not agree to these Terms of Use, do not install or use the Software.
12
+
13
+ Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the Software and derivative works subject to these Terms. These Terms shall be included in all copies or substantial portions of the Software.
14
+
15
+ Subject to the limited rights expressly granted hereunder, Salesforce reserves all rights, title, and interest in and to all intellectual property subsisting in the Software. No rights are granted to you hereunder other than as expressly set forth herein. Users residing in countries on the United States Office of Foreign Assets Control sanction list, or which are otherwise subject to a US export embargo, may not use the Software.
16
+
17
+ Implementation of the Software may require development work, for which you are responsible. The Software may contain bugs, errors and incompatibilities and is made available on an AS IS basis without support, updates, or service level commitments.
18
+
19
+ Salesforce reserves the right at any time to modify, suspend, or discontinue, the Software (or any part thereof) with or without notice. You agree that Salesforce shall not be liable to you or to any third party for any modification, suspension, or discontinuance.
20
+
21
+ You agree to defend Salesforce against any claim, demand, suit or proceeding made or brought against Salesforce by a third party arising out of or accruing from (a) your use of the Software, and (b) any application you develop with the Software that infringes any copyright, trademark, trade secret, trade dress, patent, or other intellectual property right of any person or defames any person or violates their rights of publicity or privacy (each a “Claim Against Salesforce”), and will indemnify Salesforce from any damages, attorney fees, and costs finally awarded against Salesforce as a result of, or for any amounts paid by Salesforce under a settlement approved by you in writing of, a Claim Against Salesforce, provided Salesforce (x) promptly gives you written notice of the Claim Against Salesforce, (y) gives you sole control of the defense and settlement of the Claim Against Salesforce (except that you may not settle any Claim Against Salesforce unless it unconditionally releases Salesforce of all liability), and (z) gives you all reasonable assistance, at your expense.
22
+
23
+ WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA, OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
24
+
25
+ These Terms of Use shall be governed exclusively by the internal laws of the State of California, without regard to its conflicts of laws rules. Each party hereby consents to the exclusive jurisdiction of the state and federal courts located in San Francisco County, California to adjudicate any dispute arising out of or relating to these Terms of Use and the download, installation, and/or use of the Software. Except as expressly stated herein, these Terms of Use constitute the entire agreement between the parties, and supersede all prior and contemporaneous agreements, proposals, or representations, written or oral, concerning their subject matter. No modification, amendment, or waiver of any provision of these Terms of Use shall be effective unless it is by an update to these Terms of Use that Salesforce makes available, or is in writing and signed by the party against whom the modification, amendment, or waiver is to be asserted.
26
+
27
+ _*Data Privacy*_: Salesforce may collect, process, and store device, system, and other information related to your use of the Software. This information includes, but is not limited to, IP address, user metrics, and other data (“Usage Data”). Salesforce may use Usage Data for analytics, product development, and marketing purposes. You acknowledge that files generated in conjunction with the Software may contain sensitive or confidential data, and you are solely responsible for anonymizing and protecting such data.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ This software is provided as-is with no support provided.
package/dist/index.js ADDED
@@ -0,0 +1,444 @@
1
+ /*!
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ /*!
7
+ * Copyright (c) 2022, Salesforce, Inc.,
8
+ * All rights reserved.
9
+ * For full license text, see the LICENSE.txt file
10
+ */
11
+ const { isArray } = Array;
12
+ const { stringify } = JSON;
13
+ class Ok {
14
+ constructor(value) {
15
+ this.value = value;
16
+ }
17
+ isOk() {
18
+ return true;
19
+ }
20
+ isErr() {
21
+ return !this.isOk();
22
+ }
23
+ }
24
+ class Err {
25
+ constructor(error) {
26
+ this.error = error;
27
+ }
28
+ isOk() {
29
+ return false;
30
+ }
31
+ isErr() {
32
+ return !this.isOk();
33
+ }
34
+ }
35
+ const ok = (value) => new Ok(value);
36
+ const err = (err2) => new Err(err2);
37
+ function deepEquals(x, y) {
38
+ if (x === void 0) {
39
+ return y === void 0;
40
+ } else if (x === null) {
41
+ return y === null;
42
+ } else if (y === null) {
43
+ return x === null;
44
+ } else if (isArray(x)) {
45
+ if (!isArray(y) || x.length !== y.length) {
46
+ return false;
47
+ }
48
+ for (let i = 0; i < x.length; ++i) {
49
+ if (!deepEquals(x[i], y[i])) {
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ } else if (typeof x === "object") {
55
+ if (typeof y !== "object") {
56
+ return false;
57
+ }
58
+ const xkeys = Object.keys(x);
59
+ const ykeys = Object.keys(y);
60
+ if (xkeys.length !== ykeys.length) {
61
+ return false;
62
+ }
63
+ for (let i = 0; i < xkeys.length; ++i) {
64
+ const key = xkeys[i];
65
+ if (!deepEquals(x[key], y[key])) {
66
+ return false;
67
+ }
68
+ }
69
+ return true;
70
+ }
71
+ return x === y;
72
+ }
73
+ class JsonSchemaViolationError extends Error {
74
+ constructor(message, validationErrors) {
75
+ super(message);
76
+ this.validationErrors = [];
77
+ this.validationErrors = validationErrors || [];
78
+ }
79
+ }
80
+ class MinItemsViolationError extends JsonSchemaViolationError {
81
+ }
82
+ class MaxItemsViolationError extends JsonSchemaViolationError {
83
+ }
84
+ class IncorrectTypeError extends JsonSchemaViolationError {
85
+ }
86
+ class AdditionalPropertiesError extends JsonSchemaViolationError {
87
+ }
88
+ class MissingRequiredPropertyError extends JsonSchemaViolationError {
89
+ }
90
+ class InvalidRefError extends JsonSchemaViolationError {
91
+ }
92
+ class JsonSchemaErrorCollector {
93
+ constructor() {
94
+ this.errors = [];
95
+ }
96
+ add(error) {
97
+ this.errors.push(error);
98
+ }
99
+ append(response) {
100
+ if (response.isErr()) {
101
+ this.errors.push(...response.error);
102
+ }
103
+ }
104
+ hasErrors() {
105
+ return this.errors.length > 0;
106
+ }
107
+ prepend(error) {
108
+ this.errors.unshift(error);
109
+ }
110
+ toValidationResponse() {
111
+ return !this.hasErrors() ? ok(true) : err(this.errors);
112
+ }
113
+ }
114
+ function createThrowableError(errors) {
115
+ if (errors[0] instanceof MinItemsViolationError) {
116
+ return new MinItemsViolationError(errors[0].message, errors);
117
+ }
118
+ if (errors[0] instanceof MaxItemsViolationError) {
119
+ return new MaxItemsViolationError(errors[0].message, errors);
120
+ }
121
+ if (errors[0] instanceof IncorrectTypeError) {
122
+ return new IncorrectTypeError(errors[0].message, errors);
123
+ }
124
+ if (errors[0] instanceof AdditionalPropertiesError) {
125
+ return new AdditionalPropertiesError(errors[0].message, errors);
126
+ }
127
+ if (errors[0] instanceof MissingRequiredPropertyError) {
128
+ return new MissingRequiredPropertyError(errors[0].message, errors);
129
+ }
130
+ if (errors[0] instanceof InvalidRefError) {
131
+ return new InvalidRefError(errors[0].message, errors);
132
+ }
133
+ return new JsonSchemaViolationError(errors[0].message, errors);
134
+ }
135
+ function assertIsValid(data, schema) {
136
+ const validationResponse = validateJsonSchema(data, schema);
137
+ if (validationResponse.isErr()) {
138
+ throw createThrowableError(validationResponse.error);
139
+ }
140
+ }
141
+ function incorrectTypeError(expected, actual, path) {
142
+ return new IncorrectTypeError(
143
+ `Expected type ${expected} at path '${path}', found type ${actual}.`
144
+ );
145
+ }
146
+ function validSchemaResponse() {
147
+ return ok(true);
148
+ }
149
+ function invalidSchemaResponseWithError(error) {
150
+ return err([error]);
151
+ }
152
+ function validateJsonSchema(data, schema, path = "$", document = schema) {
153
+ if (schema === true) return validSchemaResponse();
154
+ if (schema === false)
155
+ return invalidSchemaResponseWithError(
156
+ new JsonSchemaViolationError(`Data at ${path} has schema 'false'`)
157
+ );
158
+ const dataType = data === null ? "null" : Array.isArray(data) ? "array" : typeof data;
159
+ const errorCollector = new JsonSchemaErrorCollector();
160
+ if ("anyOf" in schema) {
161
+ errorCollector.append(validateAnyOf(data, schema, path, document));
162
+ } else if ("oneOf" in schema) {
163
+ errorCollector.append(validateOneOf(data, schema, path, document));
164
+ } else if ("allOf" in schema) {
165
+ errorCollector.append(validateAllOf(data, schema, path, document));
166
+ } else if ("not" in schema) {
167
+ errorCollector.append(validateNot(data, schema, path, document));
168
+ } else if ("$ref" in schema) {
169
+ errorCollector.append(validateRef(data, schema, path, document));
170
+ } else if ("type" in schema) {
171
+ if (schema.type === "object") {
172
+ if (dataType !== "object") {
173
+ errorCollector.add(incorrectTypeError("object", dataType, path));
174
+ } else {
175
+ errorCollector.append(
176
+ validateObject(data, schema, path, document)
177
+ );
178
+ }
179
+ } else if (schema.type === "array") {
180
+ if (dataType !== "array") {
181
+ errorCollector.add(incorrectTypeError("array", dataType, path));
182
+ } else {
183
+ errorCollector.append(
184
+ validateArray(data, schema, path, document)
185
+ );
186
+ }
187
+ } else {
188
+ errorCollector.append(
189
+ validateScalar(data, schema, path)
190
+ );
191
+ }
192
+ }
193
+ if (schema.enum) {
194
+ errorCollector.append(validateEnum(data, schema.enum, path));
195
+ }
196
+ if (schema.const) {
197
+ errorCollector.append(validateConst(data, schema.const, path));
198
+ }
199
+ return errorCollector.toValidationResponse();
200
+ }
201
+ function validateAnyOf(data, schema, path, document) {
202
+ let isValid = false;
203
+ const errorCollector = new JsonSchemaErrorCollector();
204
+ for (let i = 0, { length } = schema.anyOf; i < length; i++) {
205
+ const element = schema.anyOf[i];
206
+ const validationResponse = validateJsonSchema(
207
+ data,
208
+ element,
209
+ `${path}.anyOf[${i}]`,
210
+ document
211
+ );
212
+ if (validationResponse.isOk()) {
213
+ isValid = true;
214
+ break;
215
+ } else {
216
+ errorCollector.append(validationResponse);
217
+ }
218
+ }
219
+ if (!isValid) {
220
+ errorCollector.prepend(
221
+ new JsonSchemaViolationError(`Data at ${path} did not match any subschema in anyOf.`)
222
+ );
223
+ return errorCollector.toValidationResponse();
224
+ }
225
+ return validSchemaResponse();
226
+ }
227
+ function validateOneOf(data, schema, path, document) {
228
+ let validSubShemaPaths = [];
229
+ const errorCollector = new JsonSchemaErrorCollector();
230
+ for (let i = 0, { length } = schema.oneOf; i < length; i++) {
231
+ const element = schema.oneOf[i];
232
+ const oneOfPath = `${path}.oneOf[${i}]`;
233
+ const validationResponse = validateJsonSchema(data, element, oneOfPath, document);
234
+ if (validationResponse.isOk()) {
235
+ validSubShemaPaths.push(oneOfPath);
236
+ } else {
237
+ errorCollector.append(validationResponse);
238
+ }
239
+ }
240
+ if (validSubShemaPaths.length === 0) {
241
+ errorCollector.prepend(
242
+ new JsonSchemaViolationError(`Data at ${path} did not match any subschema in oneOf.`)
243
+ );
244
+ return errorCollector.toValidationResponse();
245
+ } else if (validSubShemaPaths.length > 1) {
246
+ errorCollector.prepend(
247
+ new JsonSchemaViolationError(
248
+ `Data at ${path} matched multiple subschemas: [${validSubShemaPaths.join(", ")}].`
249
+ )
250
+ );
251
+ return errorCollector.toValidationResponse();
252
+ }
253
+ return validSchemaResponse();
254
+ }
255
+ function validateAllOf(data, schema, path, document) {
256
+ let isValid = true;
257
+ const errorCollector = new JsonSchemaErrorCollector();
258
+ for (let i = 0, { length } = schema.allOf; i < length; i++) {
259
+ const element = schema.allOf[i];
260
+ const validationResponse = validateJsonSchema(
261
+ data,
262
+ element,
263
+ `${path}.allOf[${i}]`,
264
+ document
265
+ );
266
+ if (!validationResponse.isOk()) {
267
+ errorCollector.append(validationResponse);
268
+ isValid = false;
269
+ }
270
+ }
271
+ if (!isValid) {
272
+ errorCollector.prepend(
273
+ new JsonSchemaViolationError(`Data at ${path} did not match some subschemas in allOf.`)
274
+ );
275
+ }
276
+ return errorCollector.toValidationResponse();
277
+ }
278
+ function validateNot(data, schema, path, document) {
279
+ const validationResponse = validateJsonSchema(data, schema.not, path, document);
280
+ if (validationResponse.isOk()) {
281
+ return invalidSchemaResponseWithError(
282
+ new JsonSchemaViolationError(
283
+ `Data at ${path} validated against the schema of a not clause.`
284
+ )
285
+ );
286
+ }
287
+ return validSchemaResponse();
288
+ }
289
+ function validateObject(data, schema, path, document) {
290
+ const schemaKeys = Object.keys(schema.properties);
291
+ const requiredKeys = new Set(schema.required);
292
+ const schemaKeySet = new Set(schemaKeys);
293
+ const errorCollector = new JsonSchemaErrorCollector();
294
+ Object.keys(data).forEach((key) => {
295
+ if (!schemaKeySet.has(key)) {
296
+ errorCollector.append(
297
+ validateJsonSchema(
298
+ data[key],
299
+ schema.additionalProperties,
300
+ `${path}.additionalProperties[${key}]`,
301
+ document
302
+ )
303
+ );
304
+ }
305
+ });
306
+ for (let i = 0, length = schemaKeys.length; i < length; i++) {
307
+ const key = schemaKeys[i];
308
+ const keyInData = key in data && data[key] !== void 0;
309
+ if (requiredKeys.has(key) && !keyInData) {
310
+ errorCollector.add(
311
+ new MissingRequiredPropertyError(
312
+ `Object at path '${path}' is missing required property '${key}'.`
313
+ )
314
+ );
315
+ }
316
+ if (keyInData) {
317
+ errorCollector.append(
318
+ validateJsonSchema(
319
+ data[key],
320
+ schema.properties[key],
321
+ `${path}.${key}`,
322
+ document
323
+ )
324
+ );
325
+ }
326
+ }
327
+ return errorCollector.toValidationResponse();
328
+ }
329
+ function validateArray(data, schema, path, document) {
330
+ if (schema.minItems !== void 0 && data.length < schema.minItems) {
331
+ return invalidSchemaResponseWithError(
332
+ new MinItemsViolationError(
333
+ `Array at path '${path}' fails minItems constraint. Has ${data.length} items, needs at least ${schema.minItems}.`
334
+ )
335
+ );
336
+ }
337
+ if (schema.maxItems !== void 0 && data.length > schema.maxItems) {
338
+ return invalidSchemaResponseWithError(
339
+ new MaxItemsViolationError(
340
+ `Array at path '${path}' fails maxItems constraint. Has ${data.length} items, needs at most ${schema.maxItems}.`
341
+ )
342
+ );
343
+ }
344
+ const errorCollector = new JsonSchemaErrorCollector();
345
+ data.forEach(
346
+ (element, index) => errorCollector.append(
347
+ validateJsonSchema(element, schema.items, `${path}[${index}]`, document)
348
+ )
349
+ );
350
+ return errorCollector.toValidationResponse();
351
+ }
352
+ function validateScalar(data, schema, path) {
353
+ const schemaDataType = schema.type;
354
+ const dataType = typeof data;
355
+ if (schemaDataType === "integer") {
356
+ if (dataType !== "number" || !Number.isInteger(data)) {
357
+ return invalidSchemaResponseWithError(incorrectTypeError("integer", dataType, path));
358
+ }
359
+ } else if (schemaDataType === "number") {
360
+ if (dataType !== "number") {
361
+ return invalidSchemaResponseWithError(incorrectTypeError("number", dataType, path));
362
+ }
363
+ } else if (schemaDataType === "string") {
364
+ if (dataType !== "string") {
365
+ return invalidSchemaResponseWithError(incorrectTypeError("string", dataType, path));
366
+ }
367
+ } else if (schemaDataType === "boolean") {
368
+ if (dataType !== "boolean") {
369
+ return invalidSchemaResponseWithError(incorrectTypeError("boolean", dataType, path));
370
+ }
371
+ } else if (schemaDataType === "null") {
372
+ if (data !== null) {
373
+ return invalidSchemaResponseWithError(incorrectTypeError("null", dataType, path));
374
+ }
375
+ } else {
376
+ return invalidSchemaResponseWithError(
377
+ new IncorrectTypeError(`Unknown schema data type: ${schemaDataType}.`)
378
+ );
379
+ }
380
+ return validSchemaResponse();
381
+ }
382
+ function validateRef(data, schema, path, document) {
383
+ if (!schema.$ref.startsWith("#")) {
384
+ return invalidSchemaResponseWithError(
385
+ new InvalidRefError(
386
+ `$ref values that do not refer to the current document are unsupported (must start with '#')`
387
+ )
388
+ );
389
+ }
390
+ try {
391
+ const schemaToValidate = findSchemaAtPath(document, schema.$ref);
392
+ return validateJsonSchema(data, schemaToValidate, path, document);
393
+ } catch (e) {
394
+ return invalidSchemaResponseWithError(e);
395
+ }
396
+ }
397
+ function validateEnum(data, enumValue, path) {
398
+ if (!enumValue.some((value) => deepEquals(value, data))) {
399
+ return invalidSchemaResponseWithError(
400
+ new JsonSchemaViolationError(
401
+ `Data at ${path} did not match any values in enum. Expected value in: [${enumValue.map((value) => stringify(value)).join()}]`
402
+ )
403
+ );
404
+ }
405
+ return validSchemaResponse();
406
+ }
407
+ function validateConst(data, constValue, path) {
408
+ if (!deepEquals(constValue, data)) {
409
+ return invalidSchemaResponseWithError(
410
+ new JsonSchemaViolationError(
411
+ `Data at ${path} did not match const. Expected: ${stringify(constValue)}`
412
+ )
413
+ );
414
+ }
415
+ return validSchemaResponse();
416
+ }
417
+ function findSchemaAtPath(document, ref) {
418
+ if (ref === "#") return document;
419
+ const keys = ref.replace(/^#\//, "").split("/");
420
+ let current = document;
421
+ let path = "#";
422
+ for (const key of keys) {
423
+ path = `${path}/${key}`;
424
+ if (current[key] === void 0) {
425
+ throw new InvalidRefError(
426
+ `Invalid $ref value '${ref}'. Cannot find target schema at '${path}'`
427
+ );
428
+ }
429
+ current = current[key];
430
+ }
431
+ return current;
432
+ }
433
+ export {
434
+ AdditionalPropertiesError,
435
+ IncorrectTypeError,
436
+ InvalidRefError,
437
+ JsonSchemaViolationError,
438
+ MaxItemsViolationError,
439
+ MinItemsViolationError,
440
+ MissingRequiredPropertyError,
441
+ assertIsValid,
442
+ validateJsonSchema
443
+ };
444
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../utils/dist/index.js","../src/index.ts"],"sourcesContent":["/*!\n * Copyright (c) 2022, Salesforce, Inc.,\n * All rights reserved.\n * For full license text, see the LICENSE.txt file\n */\nfunction bfs(start, predicate, getChildren) {\n const queue = [...start];\n const visited = /* @__PURE__ */ new Set([...start]);\n const matches2 = /* @__PURE__ */ new Set();\n while (queue.length) {\n const curr = queue.shift();\n if (predicate(curr)) {\n matches2.add(curr);\n }\n const children = getChildren(curr);\n for (const child of children) {\n if (!visited.has(child)) {\n visited.add(child);\n queue.push(child);\n }\n }\n }\n return matches2;\n}\nfunction lineFormatter(position, message, filePath) {\n return `${message} (${filePath}:${position.line}:${position.column})`;\n}\nclass DefaultFileParserLogger {\n constructor(services, filePath) {\n this.services = services;\n this.filePath = filePath;\n }\n trace(position, message) {\n this.services.logger.trace(this.format(position, message));\n }\n debug(position, message) {\n this.services.logger.debug(this.format(position, message));\n }\n info(position, message) {\n this.services.logger.info(this.format(position, message));\n }\n warn(position, message) {\n this.services.logger.warn(this.format(position, message));\n }\n error(position, message) {\n this.services.logger.error(this.format(position, message));\n }\n format(position, message) {\n return lineFormatter(position, message, this.filePath);\n }\n}\nfunction matches(test, s) {\n if (test === void 0) {\n return false;\n } else if (typeof test === \"string\") {\n return s === test;\n } else if (test instanceof RegExp) {\n return test.test(s);\n } else if (typeof test === \"function\") {\n return test(s);\n }\n return test.some((m) => matches(m, s));\n}\nfunction includes(incexc, s) {\n if (matches(incexc.exclude, s)) {\n return false;\n }\n if (matches(incexc.include, s)) {\n return true;\n }\n if (incexc.include) {\n return false;\n }\n return true;\n}\nconst { create, freeze, keys, entries } = Object;\nconst { hasOwnProperty } = Object.prototype;\nconst { isArray } = Array;\nconst { push, indexOf, slice } = Array.prototype;\nconst { stringify, parse } = JSON;\nconst WeakSetConstructor = WeakSet;\nconst LogLevelMap = {\n TRACE: 4,\n DEBUG: 3,\n INFO: 2,\n WARN: 1,\n ERROR: 0\n};\nclass ConsoleLogger {\n constructor(level = \"WARN\", printer = console.log, formatter = (level2, message) => `${level2}: ${message}`) {\n this.level = level;\n this.printer = printer;\n this.formatter = formatter;\n this.messages = [];\n }\n trace(message) {\n this.log(\"TRACE\", message);\n }\n debug(message) {\n this.log(\"DEBUG\", message);\n }\n info(message) {\n this.log(\"INFO\", message);\n }\n warn(message) {\n this.log(\"WARN\", message);\n }\n error(message) {\n this.log(\"ERROR\", message);\n }\n log(level, message) {\n if (LogLevelMap[level] > LogLevelMap[this.level]) {\n return;\n }\n this.printer(this.formatter(level, message));\n }\n}\nfunction loggerService(level, printer, formatter) {\n return new ConsoleLogger(level, printer, formatter);\n}\nclass Ok {\n constructor(value) {\n this.value = value;\n }\n isOk() {\n return true;\n }\n isErr() {\n return !this.isOk();\n }\n}\nclass Err {\n constructor(error) {\n this.error = error;\n }\n isOk() {\n return false;\n }\n isErr() {\n return !this.isOk();\n }\n}\nconst ok = (value) => new Ok(value);\nconst err = (err2) => new Err(err2);\nclass DataNotFoundError extends Error {\n constructor(message) {\n super(message);\n this.name = \"DataNotFoundError\";\n }\n}\nclass DataIncompleteError extends Error {\n constructor(message, partialData) {\n super(message);\n this.partialData = partialData;\n this.name = \"DataIncompleteError\";\n }\n}\nfunction isDataNotFoundError(error) {\n return error instanceof DataNotFoundError || error.name === \"DataNotFoundError\";\n}\nfunction isDataIncompleteError(error) {\n return error instanceof DataIncompleteError || error.name === \"DataIncompleteError\";\n}\nfunction isCacheHitOrError(value) {\n if (value.isErr() && (isDataIncompleteError(value.error) || isDataNotFoundError(value.error))) {\n return false;\n }\n return true;\n}\nfunction isCacheMiss(value) {\n return !isCacheHitOrError(value);\n}\nfunction isResult(value) {\n return value != null && typeof value === \"object\" && \"isOk\" in value && \"isErr\" in value && typeof value.isOk === \"function\" && typeof value.isErr === \"function\" && (value.isOk() === true && value.isErr() === false && \"value\" in value || value.isOk() === false && value.isErr() === true && \"error\" in value);\n}\nfunction setOverlaps(setA, setB) {\n for (const element of setA) {\n if (setB.has(element)) {\n return true;\n }\n }\n return false;\n}\nfunction setDifference(setA, setB) {\n const differenceSet = /* @__PURE__ */ new Set();\n for (const element of setA) {\n if (!setB.has(element)) {\n differenceSet.add(element);\n }\n }\n return differenceSet;\n}\nfunction addAllToSet(targetSet, sourceSet) {\n for (const element of sourceSet) {\n targetSet.add(element);\n }\n}\nconst toTypeScriptSafeIdentifier = (s) => s.length >= 1 ? s[0].replace(/[^$_\\p{ID_Start}]/u, \"_\") + s.slice(1).replace(/[^$\\u200c\\u200d\\p{ID_Continue}]/gu, \"_\") : \"\";\nfunction isSubscribable(obj) {\n return typeof obj === \"object\" && obj !== null && \"subscribe\" in obj && typeof obj.subscribe === \"function\" && \"refresh\" in obj && typeof obj.refresh === \"function\";\n}\nfunction isSubscribableResult(x) {\n if (!isResult(x)) {\n return false;\n }\n return isSubscribable(x.isOk() ? x.value : x.error);\n}\nfunction buildSubscribableResult(result, subscribe, refresh) {\n if (result.isOk()) {\n return ok({ data: result.value, subscribe, refresh });\n } else {\n return err({ failure: result.error, subscribe, refresh });\n }\n}\nfunction resolvedPromiseLike(result) {\n if (isPromiseLike(result)) {\n return result.then((nextResult) => nextResult);\n }\n return {\n then: (onFulfilled, _onRejected) => {\n try {\n return resolvedPromiseLike(onFulfilled(result));\n } catch (e) {\n if (onFulfilled === void 0) {\n return resolvedPromiseLike(result);\n }\n return rejectedPromiseLike(e);\n }\n }\n };\n}\nfunction rejectedPromiseLike(reason) {\n if (isPromiseLike(reason)) {\n return reason.then((nextResult) => nextResult);\n }\n return {\n then: (_onFulfilled, onRejected) => {\n if (typeof onRejected === \"function\") {\n try {\n return resolvedPromiseLike(onRejected(reason));\n } catch (e) {\n return rejectedPromiseLike(e);\n }\n }\n return rejectedPromiseLike(reason);\n }\n };\n}\nfunction isPromiseLike(x) {\n return typeof (x == null ? void 0 : x.then) === \"function\";\n}\nfunction racesync(values) {\n for (const value of values) {\n let settled = void 0;\n if (isPromiseLike(value)) {\n value.then(\n (_) => {\n settled = value;\n },\n (_) => {\n settled = value;\n }\n );\n } else {\n settled = resolvedPromiseLike(value);\n }\n if (settled !== void 0) {\n return settled;\n }\n }\n return Promise.race(values);\n}\nfunction withResolvers() {\n let resolve, reject;\n const promise = new Promise((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { promise, resolve, reject };\n}\nfunction deepEquals(x, y) {\n if (x === void 0) {\n return y === void 0;\n } else if (x === null) {\n return y === null;\n } else if (y === null) {\n return x === null;\n } else if (isArray(x)) {\n if (!isArray(y) || x.length !== y.length) {\n return false;\n }\n for (let i = 0; i < x.length; ++i) {\n if (!deepEquals(x[i], y[i])) {\n return false;\n }\n }\n return true;\n } else if (typeof x === \"object\") {\n if (typeof y !== \"object\") {\n return false;\n }\n const xkeys = Object.keys(x);\n const ykeys = Object.keys(y);\n if (xkeys.length !== ykeys.length) {\n return false;\n }\n for (let i = 0; i < xkeys.length; ++i) {\n const key = xkeys[i];\n if (!deepEquals(x[key], y[key])) {\n return false;\n }\n }\n return true;\n }\n return x === y;\n}\nfunction stableJSONStringify(node) {\n if (node && node.toJSON && typeof node.toJSON === \"function\") {\n node = node.toJSON();\n }\n if (node === void 0) {\n return;\n }\n if (typeof node === \"number\") {\n return isFinite(node) ? \"\" + node : \"null\";\n }\n if (typeof node !== \"object\") {\n return stringify(node);\n }\n let i;\n let out;\n if (isArray(node)) {\n out = \"[\";\n for (i = 0; i < node.length; i++) {\n if (i) {\n out += \",\";\n }\n out += stableJSONStringify(node[i]) || \"null\";\n }\n return out + \"]\";\n }\n if (node === null) {\n return \"null\";\n }\n const objKeys = keys(node).sort();\n out = \"\";\n for (i = 0; i < objKeys.length; i++) {\n const key = objKeys[i];\n const value = stableJSONStringify(node[key]);\n if (!value) {\n continue;\n }\n if (out) {\n out += \",\";\n }\n out += stringify(key) + \":\" + value;\n }\n return \"{\" + out + \"}\";\n}\nfunction toError(x) {\n if (x instanceof Error) {\n return x;\n }\n return new Error(typeof x === \"string\" ? x : JSON.stringify(x));\n}\nfunction deepCopy(x) {\n const stringified = stringify(x);\n return stringified ? parse(stringified) : void 0;\n}\nfunction readableStreamToAsyncIterable(stream) {\n if (stream.locked) {\n return err(new Error(\"ReadableStream is already locked\"));\n }\n if (Symbol.asyncIterator in stream) {\n return ok(stream);\n }\n const reader = stream.getReader();\n return ok({\n [Symbol.asyncIterator]: () => ({\n next: async () => {\n try {\n const result = await reader.read();\n if (result.done) {\n try {\n reader.releaseLock();\n } catch {\n }\n return { done: true, value: void 0 };\n }\n return {\n done: false,\n value: result.value\n };\n } catch (e) {\n try {\n reader.releaseLock();\n } catch {\n }\n throw e;\n }\n },\n return: async (value) => {\n try {\n await reader.cancel();\n } catch {\n }\n try {\n reader.releaseLock();\n } catch {\n }\n return { done: true, value };\n },\n throw: async (exception) => {\n try {\n await reader.cancel();\n } catch {\n }\n try {\n reader.releaseLock();\n } catch {\n }\n throw exception;\n }\n })\n });\n}\nfunction satisfies(provided, requested) {\n const providedN = provided.split(\".\").map((s) => parseInt(s));\n const requestedN = requested.split(\".\").map((s) => parseInt(s));\n return providedN[0] === requestedN[0] && providedN[1] >= requestedN[1];\n}\nfunction stringIsVersion(s) {\n const versionParts = s.split(\".\");\n return (versionParts.length === 2 || versionParts.length === 3) && versionParts.every((part) => part.match(/^\\d+$/));\n}\nvar HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {\n HttpStatusCode2[HttpStatusCode2[\"Ok\"] = 200] = \"Ok\";\n HttpStatusCode2[HttpStatusCode2[\"Created\"] = 201] = \"Created\";\n HttpStatusCode2[HttpStatusCode2[\"NoContent\"] = 204] = \"NoContent\";\n HttpStatusCode2[HttpStatusCode2[\"NotModified\"] = 304] = \"NotModified\";\n HttpStatusCode2[HttpStatusCode2[\"BadRequest\"] = 400] = \"BadRequest\";\n HttpStatusCode2[HttpStatusCode2[\"Unauthorized\"] = 401] = \"Unauthorized\";\n HttpStatusCode2[HttpStatusCode2[\"Forbidden\"] = 403] = \"Forbidden\";\n HttpStatusCode2[HttpStatusCode2[\"NotFound\"] = 404] = \"NotFound\";\n HttpStatusCode2[HttpStatusCode2[\"ServerError\"] = 500] = \"ServerError\";\n HttpStatusCode2[HttpStatusCode2[\"GatewayTimeout\"] = 504] = \"GatewayTimeout\";\n return HttpStatusCode2;\n})(HttpStatusCode || {});\nfunction getFetchResponseFromAuraError(err2) {\n if (err2.data !== void 0 && err2.data.statusCode !== void 0) {\n let data = {};\n data = err2.data;\n if (err2.id !== void 0) {\n data.id = err2.id;\n }\n return new FetchResponse(data.statusCode, data);\n }\n return new FetchResponse(500, {\n error: err2.message\n });\n}\nasync function coerceResponseToFetchResponse(response) {\n const { status } = response;\n const responseHeaders = {};\n response.headers.forEach((value, key) => {\n responseHeaders[key] = value;\n });\n let responseBody = null;\n if (status !== 204) {\n const contentType = responseHeaders[\"content-type\"];\n responseBody = contentType && contentType.startsWith(\"application/json\") ? await response.json() : await response.text();\n }\n return new FetchResponse(status, responseBody, responseHeaders);\n}\nfunction getStatusText(status) {\n switch (status) {\n case 200:\n return \"OK\";\n case 201:\n return \"Created\";\n case 304:\n return \"Not Modified\";\n case 400:\n return \"Bad Request\";\n case 404:\n return \"Not Found\";\n case 500:\n return \"Server Error\";\n default:\n return `Unexpected HTTP Status Code: ${status}`;\n }\n}\nclass FetchResponse extends Error {\n constructor(status, body, headers) {\n super();\n this.status = status;\n this.body = body;\n this.headers = headers || {};\n this.ok = status >= 200 && this.status <= 299;\n this.statusText = getStatusText(status);\n }\n}\nconst deeplyFrozen = new WeakSetConstructor();\nfunction deepFreeze(value) {\n if (typeof value !== \"object\" || value === null || deeplyFrozen.has(value)) {\n return;\n }\n deeplyFrozen.add(value);\n if (isArray(value)) {\n for (let i = 0, len = value.length; i < len; i += 1) {\n deepFreeze(value[i]);\n }\n } else {\n const keys$1 = keys(value);\n for (let i = 0, len = keys$1.length; i < len; i += 1) {\n deepFreeze(value[keys$1[i]]);\n }\n }\n freeze(value);\n}\nfunction isScalar(value) {\n return typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\" || value === null || value === void 0;\n}\nfunction isScalarObject(value) {\n return Object.values(value).every((value2) => isScalar(value2));\n}\nfunction isScalarArray(value) {\n return value.every((item) => isScalar(item));\n}\nfunction encodeQueryParam(paramName, value, explode) {\n switch (typeof value) {\n case \"string\":\n return [`${paramName}=${encodeURIComponent(value)}`];\n case \"number\":\n case \"boolean\":\n return [`${paramName}=${value}`];\n case \"object\":\n if (value === null) {\n return [];\n }\n if (isArray(value)) {\n if (!isScalarArray(value)) {\n throw new Error(`Unsupported non-scalar array type for ${paramName}`);\n }\n if (explode) {\n return value.map(\n (item) => `${paramName}=${item ? encodeURIComponent(item) : item}`\n );\n }\n return [\n `${paramName}=${value.map((item) => item ? encodeURIComponent(item) : item).join(\",\")}`\n ];\n }\n if (!isScalarObject(value)) {\n throw new Error(`Unsupported non-scalar object type for ${paramName}`);\n }\n if (explode) {\n return entries(value).map(\n ([key, value2]) => `${key}=${value2 ? encodeURIComponent(value2) : value2}`\n );\n }\n return [\n `${paramName}=${entries(value).flat().map((item) => item ? encodeURIComponent(item) : item).join(\",\")}`\n ];\n default:\n return [];\n }\n}\nclass InternalError extends Error {\n constructor(data) {\n super();\n this.data = data;\n this.type = \"internal\";\n }\n}\nclass UserVisibleError extends Error {\n constructor(data) {\n super();\n this.data = data;\n this.type = \"user-visible\";\n }\n}\nfunction applyDecorators(baseCommand, decorators, options) {\n if (!decorators || decorators.length === 0) {\n return baseCommand;\n }\n return decorators.reduce((command, decorator) => decorator(command, options), baseCommand);\n}\nexport {\n isArray as ArrayIsArray,\n indexOf as ArrayPrototypeIndexOf,\n push as ArrayPrototypePush,\n slice as ArrayPrototypeSlice,\n ConsoleLogger,\n DataIncompleteError,\n DataNotFoundError,\n DefaultFileParserLogger,\n Err,\n FetchResponse,\n HttpStatusCode,\n InternalError,\n parse as JSONParse,\n stringify as JSONStringify,\n LogLevelMap,\n create as ObjectCreate,\n entries as ObjectEntries,\n freeze as ObjectFreeze,\n keys as ObjectKeys,\n hasOwnProperty as ObjectPrototypeHasOwnProperty,\n Ok,\n UserVisibleError,\n WeakSetConstructor,\n addAllToSet,\n applyDecorators,\n bfs,\n buildSubscribableResult,\n coerceResponseToFetchResponse,\n deepCopy,\n deepEquals,\n deepFreeze,\n encodeQueryParam,\n err,\n getFetchResponseFromAuraError,\n includes,\n isCacheHitOrError,\n isCacheMiss,\n isDataIncompleteError,\n isDataNotFoundError,\n isPromiseLike,\n isResult,\n isSubscribable,\n isSubscribableResult,\n lineFormatter,\n loggerService,\n ok,\n racesync,\n readableStreamToAsyncIterable,\n rejectedPromiseLike,\n resolvedPromiseLike,\n satisfies,\n setDifference,\n setOverlaps,\n stableJSONStringify,\n stringIsVersion,\n toError,\n toTypeScriptSafeIdentifier,\n withResolvers\n};\n//# sourceMappingURL=index.js.map\n","import { deepEquals, err, JSONStringify, ok } from '@conduit-client/utils';\nimport type { Result } from '@conduit-client/utils';\n\n// Based on https://json-schema.org/understanding-json-schema/\nexport type JSONSchema =\n | ObjectType\n | ArrayType\n | ScalarType\n | AnyOf\n | OneOf\n | AllOf\n | Not\n | RefType\n | EnumType\n | ConstType\n | boolean /* booleans are used to indicate if schema matches anything or nothing */;\n\nexport type BaseType = {\n enum?: any[]; // Enum can hold an array of allowed values of any type.\n const?: any; // Const represents a single allowed value.\n};\n\nexport type RefType = BaseType & { $ref: string };\n\nexport type EnumType = BaseType & {\n enum: any[];\n};\n\nexport type ConstType = BaseType & {\n const: any;\n};\n\n// Based on https://json-schema.org/understanding-json-schema/reference/object.html\nexport type ObjectType = BaseType & {\n type: 'object';\n properties: Record<string, JSONSchema>;\n required: string[];\n additionalProperties: JSONSchema;\n};\n\n// Based on https://json-schema.org/understanding-json-schema/reference/array.html\nexport type ArrayType = BaseType & {\n type: 'array';\n items: JSONSchema;\n minItems?: number;\n maxItems?: number;\n};\n\nexport type AnyOf = BaseType & {\n anyOf: JSONSchema[];\n};\n\nexport type OneOf = BaseType & {\n oneOf: JSONSchema[];\n};\n\nexport type AllOf = BaseType & {\n allOf: JSONSchema[];\n};\n\nexport type Not = BaseType & {\n not: JSONSchema;\n};\n\ntype ScalarType = IntegerType | NumberType | StringType | BooleanType | NullType;\n\nexport type IntegerType = BaseType & { type: 'integer' };\nexport type NumberType = BaseType & { type: 'number' };\nexport type StringType = BaseType & { type: 'string' };\nexport type BooleanType = BaseType & { type: 'boolean' };\nexport type NullType = BaseType & { type: 'null' };\nexport type JsonSchemaValidationError =\n | JsonSchemaViolationError\n | MinItemsViolationError\n | MaxItemsViolationError\n | IncorrectTypeError\n | AdditionalPropertiesError\n | MissingRequiredPropertyError\n | InvalidRefError;\n\nexport interface JsonSchemaValidationResponse {\n isValid: boolean;\n errors: Array<JsonSchemaValidationError>;\n}\n\nexport class JsonSchemaViolationError extends Error {\n public validationErrors: JsonSchemaValidationError[] = [];\n constructor(message?: string, validationErrors?: Array<JsonSchemaValidationError>) {\n super(message);\n this.validationErrors = validationErrors || [];\n }\n}\nexport class MinItemsViolationError extends JsonSchemaViolationError {}\nexport class MaxItemsViolationError extends JsonSchemaViolationError {}\nexport class IncorrectTypeError extends JsonSchemaViolationError {}\nexport class AdditionalPropertiesError extends JsonSchemaViolationError {}\nexport class MissingRequiredPropertyError extends JsonSchemaViolationError {}\nexport class InvalidRefError extends JsonSchemaViolationError {}\n\nclass JsonSchemaErrorCollector {\n errors: Array<JsonSchemaValidationError>;\n constructor() {\n this.errors = [];\n }\n add(error: JsonSchemaValidationError) {\n this.errors.push(error);\n }\n append(response: Result<boolean, JsonSchemaValidationError[]>) {\n if (response.isErr()) {\n this.errors.push(...response.error);\n }\n }\n hasErrors() {\n return this.errors.length > 0;\n }\n prepend(error: JsonSchemaValidationError) {\n this.errors.unshift(error);\n }\n toValidationResponse(): Result<boolean, JsonSchemaViolationError[]> {\n return !this.hasErrors() ? ok(true) : err(this.errors);\n }\n}\n\nfunction createThrowableError(errors: Array<JsonSchemaValidationError>): JsonSchemaValidationError {\n if (errors[0] instanceof MinItemsViolationError) {\n return new MinItemsViolationError(errors[0].message, errors);\n }\n if (errors[0] instanceof MaxItemsViolationError) {\n return new MaxItemsViolationError(errors[0].message, errors);\n }\n if (errors[0] instanceof IncorrectTypeError) {\n return new IncorrectTypeError(errors[0].message, errors);\n }\n if (errors[0] instanceof AdditionalPropertiesError) {\n return new AdditionalPropertiesError(errors[0].message, errors);\n }\n if (errors[0] instanceof MissingRequiredPropertyError) {\n return new MissingRequiredPropertyError(errors[0].message, errors);\n }\n if (errors[0] instanceof InvalidRefError) {\n return new InvalidRefError(errors[0].message, errors);\n }\n // any non-specific validation errors\n return new JsonSchemaViolationError(errors[0].message, errors);\n}\n\n/**\n * Validates a value against a schema in a TypeScript-friendly way.\n *\n * @typeParam Type TypeScript type that matches schema\n * @param data data to be checked\n * @param schema JSONSchema that matches Type\n */\nexport function assertIsValid<Type>(data: unknown, schema: JSONSchema): asserts data is Type {\n const validationResponse = validateJsonSchema(data, schema);\n if (validationResponse.isErr()) {\n throw createThrowableError(validationResponse.error);\n }\n}\n\nfunction incorrectTypeError(expected: string, actual: string, path: string): IncorrectTypeError {\n return new IncorrectTypeError(\n `Expected type ${expected} at path '${path}', found type ${actual}.`\n );\n}\n\nfunction validSchemaResponse(): Result<boolean, JsonSchemaValidationError[]> {\n return ok(true);\n}\n\nfunction invalidSchemaResponseWithError(\n error: JsonSchemaValidationError\n): Result<boolean, JsonSchemaViolationError[]> {\n return err([error]);\n}\n\nexport function validateJsonSchema(\n data: unknown,\n schema: JSONSchema,\n path: string = '$',\n document: JSONSchema = schema\n): Result<boolean, JsonSchemaValidationError[]> {\n if (schema === true) return validSchemaResponse();\n if (schema === false)\n return invalidSchemaResponseWithError(\n new JsonSchemaViolationError(`Data at ${path} has schema 'false'`)\n );\n\n const dataType = data === null ? 'null' : Array.isArray(data) ? 'array' : typeof data;\n const errorCollector = new JsonSchemaErrorCollector();\n if ('anyOf' in schema) {\n errorCollector.append(validateAnyOf(data, schema, path, document));\n } else if ('oneOf' in schema) {\n errorCollector.append(validateOneOf(data, schema, path, document));\n } else if ('allOf' in schema) {\n errorCollector.append(validateAllOf(data, schema, path, document));\n } else if ('not' in schema) {\n errorCollector.append(validateNot(data, schema, path, document));\n } else if ('$ref' in schema) {\n errorCollector.append(validateRef(data, schema, path, document));\n } else if ('type' in schema) {\n if (schema.type === 'object') {\n if (dataType !== 'object') {\n errorCollector.add(incorrectTypeError('object', dataType, path));\n } else {\n errorCollector.append(\n validateObject(data as Record<string, unknown>, schema, path, document)\n );\n }\n } else if (schema.type === 'array') {\n if (dataType !== 'array') {\n errorCollector.add(incorrectTypeError('array', dataType, path));\n } else {\n errorCollector.append(\n validateArray(data as Array<unknown>, schema, path, document)\n );\n }\n } else {\n errorCollector.append(\n validateScalar(data as string | number | boolean | null, schema, path)\n );\n }\n }\n if (schema.enum) {\n errorCollector.append(validateEnum(data, schema.enum, path));\n }\n if (schema.const) {\n errorCollector.append(validateConst(data, schema.const, path));\n }\n\n return errorCollector.toValidationResponse();\n}\n\nfunction validateAnyOf(\n data: unknown,\n schema: AnyOf,\n path: string,\n document: JSONSchema\n): Result<boolean, JsonSchemaValidationError[]> {\n let isValid = false;\n const errorCollector = new JsonSchemaErrorCollector();\n\n for (let i = 0, { length } = schema.anyOf; i < length; i++) {\n const element = schema.anyOf[i];\n const validationResponse = validateJsonSchema(\n data,\n element,\n `${path}.anyOf[${i}]`,\n document\n );\n if (validationResponse.isOk()) {\n isValid = true;\n break;\n } else {\n errorCollector.append(validationResponse);\n }\n }\n\n if (!isValid) {\n errorCollector.prepend(\n new JsonSchemaViolationError(`Data at ${path} did not match any subschema in anyOf.`)\n );\n return errorCollector.toValidationResponse();\n }\n\n return validSchemaResponse();\n}\n\nfunction validateOneOf(\n data: unknown,\n schema: OneOf,\n path: string,\n document: JSONSchema\n): Result<boolean, JsonSchemaValidationError[]> {\n let validSubShemaPaths: string[] = [];\n const errorCollector = new JsonSchemaErrorCollector();\n\n for (let i = 0, { length } = schema.oneOf; i < length; i++) {\n const element = schema.oneOf[i];\n const oneOfPath = `${path}.oneOf[${i}]`;\n const validationResponse = validateJsonSchema(data, element, oneOfPath, document);\n if (validationResponse.isOk()) {\n validSubShemaPaths.push(oneOfPath);\n } else {\n errorCollector.append(validationResponse);\n }\n }\n\n if (validSubShemaPaths.length === 0) {\n errorCollector.prepend(\n new JsonSchemaViolationError(`Data at ${path} did not match any subschema in oneOf.`)\n );\n return errorCollector.toValidationResponse();\n } else if (validSubShemaPaths.length > 1) {\n errorCollector.prepend(\n new JsonSchemaViolationError(\n `Data at ${path} matched multiple subschemas: [${validSubShemaPaths.join(', ')}].`\n )\n );\n return errorCollector.toValidationResponse();\n }\n\n return validSchemaResponse();\n}\n\nfunction validateAllOf(\n data: unknown,\n schema: AllOf,\n path: string,\n document: JSONSchema\n): Result<boolean, JsonSchemaValidationError[]> {\n let isValid = true;\n const errorCollector = new JsonSchemaErrorCollector();\n\n for (let i = 0, { length } = schema.allOf; i < length; i++) {\n const element = schema.allOf[i];\n const validationResponse = validateJsonSchema(\n data,\n element,\n `${path}.allOf[${i}]`,\n document\n );\n if (!validationResponse.isOk()) {\n errorCollector.append(validationResponse);\n isValid = false;\n }\n }\n\n if (!isValid) {\n errorCollector.prepend(\n new JsonSchemaViolationError(`Data at ${path} did not match some subschemas in allOf.`)\n );\n }\n return errorCollector.toValidationResponse();\n}\n\nfunction validateNot(data: unknown, schema: Not, path: string, document: JSONSchema) {\n const validationResponse = validateJsonSchema(data, schema.not, path, document);\n if (validationResponse.isOk()) {\n return invalidSchemaResponseWithError(\n new JsonSchemaViolationError(\n `Data at ${path} validated against the schema of a not clause.`\n )\n );\n }\n return validSchemaResponse();\n}\n\nfunction validateObject(\n data: Record<string, unknown>,\n schema: ObjectType,\n path: string,\n document: JSONSchema\n): Result<boolean, JsonSchemaValidationError[]> {\n const schemaKeys = Object.keys(schema.properties);\n const requiredKeys = new Set(schema.required);\n\n const schemaKeySet = new Set(schemaKeys);\n const errorCollector = new JsonSchemaErrorCollector();\n Object.keys(data).forEach((key) => {\n if (!schemaKeySet.has(key)) {\n errorCollector.append(\n validateJsonSchema(\n data[key],\n schema.additionalProperties,\n `${path}.additionalProperties[${key}]`,\n document\n )\n );\n }\n });\n\n for (let i = 0, length = schemaKeys.length; i < length; i++) {\n const key = schemaKeys[i];\n const keyInData = key in data && (data as any)[key] !== undefined;\n if (requiredKeys.has(key) && !keyInData) {\n errorCollector.add(\n new MissingRequiredPropertyError(\n `Object at path '${path}' is missing required property '${key}'.`\n )\n );\n }\n\n if (keyInData) {\n errorCollector.append(\n validateJsonSchema(\n (data as any)[key] as unknown,\n schema.properties[key],\n `${path}.${key}`,\n document\n )\n );\n }\n }\n return errorCollector.toValidationResponse();\n}\n\nfunction validateArray(\n data: Array<unknown>,\n schema: ArrayType,\n path: string,\n document: JSONSchema\n): Result<boolean, JsonSchemaValidationError[]> {\n if (schema.minItems !== undefined && data.length < schema.minItems) {\n return invalidSchemaResponseWithError(\n new MinItemsViolationError(\n `Array at path '${path}' fails minItems constraint. Has ${data.length} items, needs at least ${schema.minItems}.`\n )\n );\n }\n\n if (schema.maxItems !== undefined && data.length > schema.maxItems) {\n return invalidSchemaResponseWithError(\n new MaxItemsViolationError(\n `Array at path '${path}' fails maxItems constraint. Has ${data.length} items, needs at most ${schema.maxItems}.`\n )\n );\n }\n const errorCollector = new JsonSchemaErrorCollector();\n data.forEach((element, index) =>\n errorCollector.append(\n validateJsonSchema(element, schema.items, `${path}[${index}]`, document)\n )\n );\n return errorCollector.toValidationResponse();\n}\n\nfunction validateScalar(\n data: number | string | boolean | null,\n schema: ScalarType,\n path: string\n): Result<boolean, JsonSchemaValidationError[]> {\n const schemaDataType = schema.type;\n const dataType = typeof data;\n\n if (schemaDataType === 'integer') {\n if (dataType !== 'number' || !Number.isInteger(data)) {\n return invalidSchemaResponseWithError(incorrectTypeError('integer', dataType, path));\n }\n } else if (schemaDataType === 'number') {\n if (dataType !== 'number') {\n return invalidSchemaResponseWithError(incorrectTypeError('number', dataType, path));\n }\n } else if (schemaDataType === 'string') {\n if (dataType !== 'string') {\n return invalidSchemaResponseWithError(incorrectTypeError('string', dataType, path));\n }\n } else if (schemaDataType === 'boolean') {\n if (dataType !== 'boolean') {\n return invalidSchemaResponseWithError(incorrectTypeError('boolean', dataType, path));\n }\n } else if (schemaDataType === 'null') {\n if (data !== null) {\n return invalidSchemaResponseWithError(incorrectTypeError('null', dataType, path));\n }\n } else {\n return invalidSchemaResponseWithError(\n new IncorrectTypeError(`Unknown schema data type: ${schemaDataType}.`)\n );\n }\n return validSchemaResponse();\n}\nfunction validateRef(\n data: unknown,\n schema: RefType,\n path: string,\n document: JSONSchema\n): Result<boolean, JsonSchemaValidationError[]> {\n if (!schema.$ref.startsWith('#')) {\n return invalidSchemaResponseWithError(\n new InvalidRefError(\n `$ref values that do not refer to the current document are unsupported (must start with '#')`\n )\n );\n }\n try {\n const schemaToValidate = findSchemaAtPath(document, schema.$ref);\n return validateJsonSchema(data, schemaToValidate, path, document);\n } catch (e) {\n return invalidSchemaResponseWithError(e as InvalidRefError);\n }\n}\n\nfunction validateEnum(\n data: unknown,\n enumValue: any[],\n path: string\n): Result<boolean, JsonSchemaValidationError[]> {\n if (!enumValue.some((value) => deepEquals(value, data))) {\n return invalidSchemaResponseWithError(\n new JsonSchemaViolationError(\n `Data at ${path} did not match any values in enum. Expected value in: [${enumValue.map((value) => JSONStringify(value)).join()}]`\n )\n );\n }\n return validSchemaResponse();\n}\n\nfunction validateConst(\n data: unknown,\n constValue: any,\n path: string\n): Result<boolean, JsonSchemaValidationError[]> {\n if (!deepEquals(constValue, data)) {\n return invalidSchemaResponseWithError(\n new JsonSchemaViolationError(\n `Data at ${path} did not match const. Expected: ${JSONStringify(constValue)}`\n )\n );\n }\n return validSchemaResponse();\n}\n\nfunction findSchemaAtPath(document: JSONSchema, ref: string): JSONSchema {\n if (ref === '#') return document;\n\n const keys = ref.replace(/^#\\//, '').split('/');\n let current: any = document; // document is JSONSchema but doesn't like dereferencing w/ string\n\n let path: string = '#';\n for (const key of keys) {\n path = `${path}/${key}`;\n if (current[key] === undefined) {\n throw new InvalidRefError(\n `Invalid $ref value '${ref}'. Cannot find target schema at '${path}'`\n );\n }\n current = current[key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AA,EACpE,SAAS,GAAG;AACR,WAAO,+BAA+B,CAAoB;AAAA,EAC9D;AACJ;AAEA,SAAS,aACL,MACA,WACA,MAC4C;AAC5C,MAAI,CAAC,UAAU,KAAK,CAAC,UAAU,WAAW,OAAO,IAAI,CAAC,GAAG;AACrD,WAAO;AAAA,MACH,IAAI;AAAA,QACA,WAAW,IAAI,0DAA0D,UAAU,IAAI,CAAC,UAAUA,UAAc,KAAK,CAAC,EAAE,KAAA,CAAM;AAAA,MAAA;AAAA,IAClI;AAAA,EAER;AACA,SAAO,oBAAA;AACX;AAEA,SAAS,cACL,MACA,YACA,MAC4C;AAC5C,MAAI,CAAC,WAAW,YAAY,IAAI,GAAG;AAC/B,WAAO;AAAA,MACH,IAAI;AAAA,QACA,WAAW,IAAI,mCAAmCA,UAAc,UAAU,CAAC;AAAA,MAAA;AAAA,IAC/E;AAAA,EAER;AACA,SAAO,oBAAA;AACX;AAEA,SAAS,iBAAiB,UAAsB,KAAyB;AACrE,MAAI,QAAQ,IAAK,QAAO;AAExB,QAAM,OAAO,IAAI,QAAQ,QAAQ,EAAE,EAAE,MAAM,GAAG;AAC9C,MAAI,UAAe;AAEnB,MAAI,OAAe;AACnB,aAAW,OAAO,MAAM;AACpB,WAAO,GAAG,IAAI,IAAI,GAAG;AACrB,QAAI,QAAQ,GAAG,MAAM,QAAW;AAC5B,YAAM,IAAI;AAAA,QACN,uBAAuB,GAAG,oCAAoC,IAAI;AAAA,MAAA;AAAA,IAE1E;AACA,cAAU,QAAQ,GAAG;AAAA,EACzB;AAEA,SAAO;AACX;"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,86 @@
1
+ import type { Result } from '@conduit-client/utils';
2
+ export type JSONSchema = ObjectType | ArrayType | ScalarType | AnyOf | OneOf | AllOf | Not | RefType | EnumType | ConstType | boolean;
3
+ export type BaseType = {
4
+ enum?: any[];
5
+ const?: any;
6
+ };
7
+ export type RefType = BaseType & {
8
+ $ref: string;
9
+ };
10
+ export type EnumType = BaseType & {
11
+ enum: any[];
12
+ };
13
+ export type ConstType = BaseType & {
14
+ const: any;
15
+ };
16
+ export type ObjectType = BaseType & {
17
+ type: 'object';
18
+ properties: Record<string, JSONSchema>;
19
+ required: string[];
20
+ additionalProperties: JSONSchema;
21
+ };
22
+ export type ArrayType = BaseType & {
23
+ type: 'array';
24
+ items: JSONSchema;
25
+ minItems?: number;
26
+ maxItems?: number;
27
+ };
28
+ export type AnyOf = BaseType & {
29
+ anyOf: JSONSchema[];
30
+ };
31
+ export type OneOf = BaseType & {
32
+ oneOf: JSONSchema[];
33
+ };
34
+ export type AllOf = BaseType & {
35
+ allOf: JSONSchema[];
36
+ };
37
+ export type Not = BaseType & {
38
+ not: JSONSchema;
39
+ };
40
+ type ScalarType = IntegerType | NumberType | StringType | BooleanType | NullType;
41
+ export type IntegerType = BaseType & {
42
+ type: 'integer';
43
+ };
44
+ export type NumberType = BaseType & {
45
+ type: 'number';
46
+ };
47
+ export type StringType = BaseType & {
48
+ type: 'string';
49
+ };
50
+ export type BooleanType = BaseType & {
51
+ type: 'boolean';
52
+ };
53
+ export type NullType = BaseType & {
54
+ type: 'null';
55
+ };
56
+ export type JsonSchemaValidationError = JsonSchemaViolationError | MinItemsViolationError | MaxItemsViolationError | IncorrectTypeError | AdditionalPropertiesError | MissingRequiredPropertyError | InvalidRefError;
57
+ export interface JsonSchemaValidationResponse {
58
+ isValid: boolean;
59
+ errors: Array<JsonSchemaValidationError>;
60
+ }
61
+ export declare class JsonSchemaViolationError extends Error {
62
+ validationErrors: JsonSchemaValidationError[];
63
+ constructor(message?: string, validationErrors?: Array<JsonSchemaValidationError>);
64
+ }
65
+ export declare class MinItemsViolationError extends JsonSchemaViolationError {
66
+ }
67
+ export declare class MaxItemsViolationError extends JsonSchemaViolationError {
68
+ }
69
+ export declare class IncorrectTypeError extends JsonSchemaViolationError {
70
+ }
71
+ export declare class AdditionalPropertiesError extends JsonSchemaViolationError {
72
+ }
73
+ export declare class MissingRequiredPropertyError extends JsonSchemaViolationError {
74
+ }
75
+ export declare class InvalidRefError extends JsonSchemaViolationError {
76
+ }
77
+ /**
78
+ * Validates a value against a schema in a TypeScript-friendly way.
79
+ *
80
+ * @typeParam Type TypeScript type that matches schema
81
+ * @param data data to be checked
82
+ * @param schema JSONSchema that matches Type
83
+ */
84
+ export declare function assertIsValid<Type>(data: unknown, schema: JSONSchema): asserts data is Type;
85
+ export declare function validateJsonSchema(data: unknown, schema: JSONSchema, path?: string, document?: JSONSchema): Result<boolean, JsonSchemaValidationError[]>;
86
+ export {};
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@conduit-client/jsonschema-validate",
3
+ "version": "5.67.0-dev1",
4
+ "private": false,
5
+ "description": "Luvio Next JSON Schema Validation",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/salesforce-experience-platform-emu/luvio-next.git",
10
+ "directory": "packages/@conduit-client/jsonschema-validate"
11
+ },
12
+ "license": "SEE LICENSE IN LICENSE.txt",
13
+ "main": "dist/index.js",
14
+ "types": "dist/types/index.d.ts",
15
+ "files": [
16
+ "dist/"
17
+ ],
18
+ "scripts": {
19
+ "build": "vite build && tsc --build --emitDeclarationOnly",
20
+ "clean": "rm -rf dist",
21
+ "test": "vitest run",
22
+ "test:size": "size-limit",
23
+ "watch": "npm run build --watch"
24
+ },
25
+ "dependencies": {
26
+ "@conduit-client/utils": "5.67.0-dev1"
27
+ },
28
+ "volta": {
29
+ "extends": "../../../package.json"
30
+ },
31
+ "size-limit": [
32
+ {
33
+ "path": "./dist/index.js",
34
+ "limit": "5 kB"
35
+ }
36
+ ]
37
+ }