@arrirpc/schema 0.70.1 → 0.71.0
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/README.md +41 -39
- package/dist/index.cjs +35 -28
- package/dist/index.d.cts +17 -10
- package/dist/index.d.mts +17 -10
- package/dist/index.d.ts +17 -10
- package/dist/index.mjs +35 -30
- package/dist/shared/{schema.TlNJgMz1.cjs → schema.BcsXcrqv.cjs} +380 -256
- package/dist/shared/{schema.C-0ZU_OQ.d.cts → schema.DLX0nTwB.d.cts} +4 -3
- package/dist/shared/{schema.C-0ZU_OQ.d.mts → schema.DLX0nTwB.d.mts} +4 -3
- package/dist/shared/{schema.C-0ZU_OQ.d.ts → schema.DLX0nTwB.d.ts} +4 -3
- package/dist/shared/{schema.lowJcmic.mjs → schema.O5uzRO_D.mjs} +379 -257
- package/dist/testSuites.cjs +10 -10
- package/dist/testSuites.d.cts +6 -5
- package/dist/testSuites.d.mts +6 -5
- package/dist/testSuites.d.ts +6 -5
- package/dist/testSuites.mjs +10 -10
- package/package.json +3 -2
|
@@ -67,24 +67,70 @@ function isARefSchema(input) {
|
|
|
67
67
|
return isASchema(input) && isSchemaFormRef(input);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
function
|
|
70
|
+
function createStandardSchemaProperty(validate, parse) {
|
|
71
71
|
return {
|
|
72
|
+
version: 1,
|
|
73
|
+
vendor: "arri",
|
|
74
|
+
validate(input) {
|
|
75
|
+
if (validate(input)) {
|
|
76
|
+
return {
|
|
77
|
+
value: input
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const ctx = {
|
|
81
|
+
instancePath: "",
|
|
82
|
+
schemaPath: "",
|
|
83
|
+
errors: []
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
const result = parse(input, ctx);
|
|
87
|
+
if (!result || ctx.errors.length) {
|
|
88
|
+
return {
|
|
89
|
+
issues: ctx.errors.map((err) => ({
|
|
90
|
+
message: err.message ?? "Unknown error",
|
|
91
|
+
path: err.instancePath.split("/").filter((val) => val.length > 0)
|
|
92
|
+
}))
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
value: result
|
|
97
|
+
};
|
|
98
|
+
} catch (err) {
|
|
99
|
+
return {
|
|
100
|
+
issues: [
|
|
101
|
+
{
|
|
102
|
+
message: err instanceof Error ? err.message : `${err}`
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function hideInvalidProperties(schema) {
|
|
111
|
+
Object.defineProperty(schema, "~standard", { enumerable: false });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function any(options = {}) {
|
|
115
|
+
const validate = (input) => true;
|
|
116
|
+
const parse = (input, context) => {
|
|
117
|
+
if (context.instancePath.length === 0 && typeof input === "string") {
|
|
118
|
+
try {
|
|
119
|
+
return JSON.parse(input);
|
|
120
|
+
} catch {
|
|
121
|
+
return input;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return input;
|
|
125
|
+
};
|
|
126
|
+
const result = {
|
|
72
127
|
metadata: {
|
|
73
128
|
id: options.id,
|
|
74
129
|
description: options.description,
|
|
75
130
|
isDeprecated: options.isDeprecated,
|
|
76
131
|
[SCHEMA_METADATA]: {
|
|
77
|
-
output:
|
|
78
|
-
parse
|
|
79
|
-
if (context.instancePath.length === 0 && typeof input === "string") {
|
|
80
|
-
try {
|
|
81
|
-
return JSON.parse(input);
|
|
82
|
-
} catch {
|
|
83
|
-
return input;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return input;
|
|
87
|
-
},
|
|
132
|
+
output: undefined,
|
|
133
|
+
parse,
|
|
88
134
|
coerce: (input, context) => {
|
|
89
135
|
if (context.instancePath.length === 0 && typeof input === "string") {
|
|
90
136
|
try {
|
|
@@ -95,17 +141,26 @@ function any(options = {}) {
|
|
|
95
141
|
}
|
|
96
142
|
return input;
|
|
97
143
|
},
|
|
98
|
-
validate
|
|
144
|
+
validate,
|
|
99
145
|
serialize(input) {
|
|
100
146
|
return JSON.stringify(input);
|
|
101
147
|
}
|
|
102
148
|
}
|
|
103
|
-
}
|
|
149
|
+
},
|
|
150
|
+
"~standard": createStandardSchemaProperty(validate, parse)
|
|
104
151
|
};
|
|
152
|
+
hideInvalidProperties(result);
|
|
153
|
+
return result;
|
|
105
154
|
}
|
|
106
155
|
|
|
107
156
|
function array(schema, opts = {}) {
|
|
108
|
-
|
|
157
|
+
const validateType = (input) => {
|
|
158
|
+
return validate$5(schema, input);
|
|
159
|
+
};
|
|
160
|
+
const parseType = (input, context) => {
|
|
161
|
+
return parse$6(schema, input, context, false);
|
|
162
|
+
};
|
|
163
|
+
const result = {
|
|
109
164
|
elements: schema,
|
|
110
165
|
metadata: {
|
|
111
166
|
id: opts.id,
|
|
@@ -113,15 +168,11 @@ function array(schema, opts = {}) {
|
|
|
113
168
|
isDeprecated: opts.isDeprecated,
|
|
114
169
|
[SCHEMA_METADATA]: {
|
|
115
170
|
output: [],
|
|
116
|
-
parse
|
|
117
|
-
return parse$6(schema, input, context, false);
|
|
118
|
-
},
|
|
171
|
+
parse: parseType,
|
|
119
172
|
coerce(input, context) {
|
|
120
173
|
return parse$6(schema, input, context, true);
|
|
121
174
|
},
|
|
122
|
-
validate
|
|
123
|
-
return validate$5(schema, input);
|
|
124
|
-
},
|
|
175
|
+
validate: validateType,
|
|
125
176
|
serialize(input, context) {
|
|
126
177
|
const strParts = [];
|
|
127
178
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -137,8 +188,11 @@ function array(schema, opts = {}) {
|
|
|
137
188
|
return `[${strParts.join(",")}]`;
|
|
138
189
|
}
|
|
139
190
|
}
|
|
140
|
-
}
|
|
191
|
+
},
|
|
192
|
+
"~standard": createStandardSchemaProperty(validateType, parseType)
|
|
141
193
|
};
|
|
194
|
+
hideInvalidProperties(result);
|
|
195
|
+
return result;
|
|
142
196
|
}
|
|
143
197
|
function validate$5(innerSchema, input) {
|
|
144
198
|
if (!Array.isArray(input)) {
|
|
@@ -163,7 +217,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
|
|
|
163
217
|
schemaPath: `${data.schemaPath}/elements`,
|
|
164
218
|
message: `Error at ${data.instancePath}. Invalid JSON.`
|
|
165
219
|
});
|
|
166
|
-
return
|
|
220
|
+
return undefined;
|
|
167
221
|
}
|
|
168
222
|
}
|
|
169
223
|
if (!Array.isArray(parsedInput)) {
|
|
@@ -172,7 +226,7 @@ function parse$6(innerSchema, input, data, coerce = false) {
|
|
|
172
226
|
schemaPath: `${data.schemaPath}/elements`,
|
|
173
227
|
message: `Error at ${data.instancePath}. Expected array. Got ${typeof input}.`
|
|
174
228
|
});
|
|
175
|
-
return
|
|
229
|
+
return undefined;
|
|
176
230
|
}
|
|
177
231
|
const result = [];
|
|
178
232
|
for (let i = 0; i < parsedInput.length; i++) {
|
|
@@ -200,13 +254,13 @@ function parse$6(innerSchema, input, data, coerce = false) {
|
|
|
200
254
|
}
|
|
201
255
|
}
|
|
202
256
|
if (data.errors.length) {
|
|
203
|
-
return
|
|
257
|
+
return undefined;
|
|
204
258
|
}
|
|
205
259
|
return result;
|
|
206
260
|
}
|
|
207
261
|
|
|
208
262
|
function boolean(opts = {}) {
|
|
209
|
-
|
|
263
|
+
const result = {
|
|
210
264
|
type: "boolean",
|
|
211
265
|
metadata: {
|
|
212
266
|
id: opts.id,
|
|
@@ -238,11 +292,14 @@ function boolean(opts = {}) {
|
|
|
238
292
|
schemaPath: context.schemaPath,
|
|
239
293
|
message: `Error at ${context.instancePath}. Unable to coerce ${input} to boolean.`
|
|
240
294
|
});
|
|
241
|
-
return
|
|
295
|
+
return undefined;
|
|
242
296
|
}
|
|
243
297
|
}
|
|
244
|
-
}
|
|
298
|
+
},
|
|
299
|
+
"~standard": createStandardSchemaProperty(validate$4, parse$5)
|
|
245
300
|
};
|
|
301
|
+
hideInvalidProperties(result);
|
|
302
|
+
return result;
|
|
246
303
|
}
|
|
247
304
|
function validate$4(input) {
|
|
248
305
|
return typeof input === "boolean";
|
|
@@ -263,14 +320,14 @@ function parse$5(input, data) {
|
|
|
263
320
|
schemaPath: `${data.schemaPath}/type`,
|
|
264
321
|
message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
|
|
265
322
|
});
|
|
266
|
-
return
|
|
323
|
+
return undefined;
|
|
267
324
|
}
|
|
268
325
|
data.errors.push({
|
|
269
326
|
instancePath: data.instancePath,
|
|
270
327
|
schemaPath: `${data.schemaPath}/type`,
|
|
271
328
|
message: `Error at ${data.instancePath}. Expected boolean. Got ${typeof input}.`
|
|
272
329
|
});
|
|
273
|
-
return
|
|
330
|
+
return undefined;
|
|
274
331
|
}
|
|
275
332
|
function serialize$2(input) {
|
|
276
333
|
return `${input}`;
|
|
@@ -401,7 +458,13 @@ function discriminator(propA, propB, propC) {
|
|
|
401
458
|
if (isIdShorthand) {
|
|
402
459
|
opts.id = propA;
|
|
403
460
|
}
|
|
404
|
-
|
|
461
|
+
const isType = (input) => {
|
|
462
|
+
return validate$2(discriminator2, mapping, input);
|
|
463
|
+
};
|
|
464
|
+
const parseType = (input, context) => {
|
|
465
|
+
return parse$3(discriminator2, mapping, input, context, false);
|
|
466
|
+
};
|
|
467
|
+
const result = {
|
|
405
468
|
discriminator: discriminator2,
|
|
406
469
|
mapping,
|
|
407
470
|
metadata: {
|
|
@@ -410,12 +473,8 @@ function discriminator(propA, propB, propC) {
|
|
|
410
473
|
isDeprecated: opts.isDeprecated,
|
|
411
474
|
[SCHEMA_METADATA]: {
|
|
412
475
|
output: {},
|
|
413
|
-
validate
|
|
414
|
-
|
|
415
|
-
},
|
|
416
|
-
parse(input, context) {
|
|
417
|
-
return parse$3(discriminator2, mapping, input, context, false);
|
|
418
|
-
},
|
|
476
|
+
validate: isType,
|
|
477
|
+
parse: parseType,
|
|
419
478
|
coerce: (input, context) => {
|
|
420
479
|
return parse$3(discriminator2, mapping, input, context, true);
|
|
421
480
|
},
|
|
@@ -428,18 +487,21 @@ function discriminator(propA, propB, propC) {
|
|
|
428
487
|
context
|
|
429
488
|
);
|
|
430
489
|
}
|
|
431
|
-
const
|
|
490
|
+
const result2 = targetSchema.metadata[SCHEMA_METADATA].serialize(input, {
|
|
432
491
|
instancePath: context.instancePath,
|
|
433
492
|
schemaPath: `${context.schemaPath}/mapping/${discriminatorVal}`,
|
|
434
493
|
errors: context.errors,
|
|
435
494
|
discriminatorKey: discriminator2,
|
|
436
495
|
discriminatorValue: discriminatorVal
|
|
437
496
|
});
|
|
438
|
-
return
|
|
497
|
+
return result2;
|
|
439
498
|
}
|
|
440
499
|
}
|
|
441
|
-
}
|
|
500
|
+
},
|
|
501
|
+
"~standard": createStandardSchemaProperty(isType, parseType)
|
|
442
502
|
};
|
|
503
|
+
hideInvalidProperties(result);
|
|
504
|
+
return result;
|
|
443
505
|
}
|
|
444
506
|
function validate$2(discriminator2, mapping, input) {
|
|
445
507
|
if (!isObject(input)) {
|
|
@@ -469,7 +531,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
|
|
|
469
531
|
schemaPath: `${data.schemaPath}/discriminator`,
|
|
470
532
|
message: `Error at ${data.instancePath}. Expected object. Got ${typeof parsedInput}.`
|
|
471
533
|
});
|
|
472
|
-
return
|
|
534
|
+
return undefined;
|
|
473
535
|
}
|
|
474
536
|
if (!(discriminator2 in parsedInput)) {
|
|
475
537
|
data.errors.push({
|
|
@@ -477,7 +539,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
|
|
|
477
539
|
schemaPath: `${data.schemaPath}/discriminator`,
|
|
478
540
|
message: `Error at ${data.instancePath}/${discriminator2}. Discriminator field "${discriminator2}" cannot be undefined`
|
|
479
541
|
});
|
|
480
|
-
return
|
|
542
|
+
return undefined;
|
|
481
543
|
}
|
|
482
544
|
const acceptedDiscriminatorVals = Object.keys(mapping);
|
|
483
545
|
const discriminatorVal = parsedInput[discriminator2];
|
|
@@ -489,7 +551,7 @@ function parse$3(discriminator2, mapping, input, data, coerce = false) {
|
|
|
489
551
|
", "
|
|
490
552
|
)}]`
|
|
491
553
|
});
|
|
492
|
-
return
|
|
554
|
+
return undefined;
|
|
493
555
|
}
|
|
494
556
|
const targetSchema = mapping[parsedInput[discriminator2]];
|
|
495
557
|
if (!targetSchema) {
|
|
@@ -546,7 +608,20 @@ function enumerator(paramA, paramB) {
|
|
|
546
608
|
}
|
|
547
609
|
return false;
|
|
548
610
|
};
|
|
549
|
-
|
|
611
|
+
const parse = (input, context) => {
|
|
612
|
+
if (isType(input)) {
|
|
613
|
+
return input;
|
|
614
|
+
}
|
|
615
|
+
context.errors.push({
|
|
616
|
+
instancePath: context.instancePath,
|
|
617
|
+
schemaPath: `${context.schemaPath}/enum`,
|
|
618
|
+
message: `Error at ${context.instancePath}. Invalid enum value. Expected one of the following values: [${enumVal.join(
|
|
619
|
+
", "
|
|
620
|
+
)}]`
|
|
621
|
+
});
|
|
622
|
+
return undefined;
|
|
623
|
+
};
|
|
624
|
+
const result = {
|
|
550
625
|
enum: enumVal,
|
|
551
626
|
metadata: {
|
|
552
627
|
id: meta?.id,
|
|
@@ -554,19 +629,7 @@ function enumerator(paramA, paramB) {
|
|
|
554
629
|
isDeprecated: meta?.isDeprecated,
|
|
555
630
|
[SCHEMA_METADATA]: {
|
|
556
631
|
output: paramA[0] ?? "",
|
|
557
|
-
parse
|
|
558
|
-
if (isType(input)) {
|
|
559
|
-
return input;
|
|
560
|
-
}
|
|
561
|
-
context.errors.push({
|
|
562
|
-
instancePath: context.instancePath,
|
|
563
|
-
schemaPath: `${context.schemaPath}/enum`,
|
|
564
|
-
message: `Error at ${context.instancePath}. Invalid enum value. Expected one of the following values: [${enumVal.join(
|
|
565
|
-
", "
|
|
566
|
-
)}]`
|
|
567
|
-
});
|
|
568
|
-
return void 0;
|
|
569
|
-
},
|
|
632
|
+
parse,
|
|
570
633
|
coerce: (input, context) => {
|
|
571
634
|
if (isType(input)) {
|
|
572
635
|
return input;
|
|
@@ -578,7 +641,7 @@ function enumerator(paramA, paramB) {
|
|
|
578
641
|
", "
|
|
579
642
|
)}]`
|
|
580
643
|
});
|
|
581
|
-
return
|
|
644
|
+
return undefined;
|
|
582
645
|
},
|
|
583
646
|
validate: isType,
|
|
584
647
|
serialize(input, context) {
|
|
@@ -588,8 +651,11 @@ function enumerator(paramA, paramB) {
|
|
|
588
651
|
return `"${input}"`;
|
|
589
652
|
}
|
|
590
653
|
}
|
|
591
|
-
}
|
|
654
|
+
},
|
|
655
|
+
"~standard": createStandardSchemaProperty(isType, parse)
|
|
592
656
|
};
|
|
657
|
+
hideInvalidProperties(result);
|
|
658
|
+
return result;
|
|
593
659
|
}
|
|
594
660
|
|
|
595
661
|
function nullable(schema, opts = {}) {
|
|
@@ -599,7 +665,16 @@ function nullable(schema, opts = {}) {
|
|
|
599
665
|
}
|
|
600
666
|
return schema.metadata[SCHEMA_METADATA].validate(val);
|
|
601
667
|
};
|
|
602
|
-
|
|
668
|
+
const parse = (val, data) => {
|
|
669
|
+
if (data.instancePath.length === 0 && typeof val === "string" && val === "null") {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
if (val === null) {
|
|
673
|
+
return null;
|
|
674
|
+
}
|
|
675
|
+
return schema.metadata[SCHEMA_METADATA].parse(val, data);
|
|
676
|
+
};
|
|
677
|
+
const result = {
|
|
603
678
|
...schema,
|
|
604
679
|
nullable: true,
|
|
605
680
|
metadata: {
|
|
@@ -610,15 +685,7 @@ function nullable(schema, opts = {}) {
|
|
|
610
685
|
output: null,
|
|
611
686
|
optional: schema.metadata[SCHEMA_METADATA].optional,
|
|
612
687
|
validate: isType,
|
|
613
|
-
parse
|
|
614
|
-
if (data.instancePath.length === 0 && typeof val === "string" && val === "null") {
|
|
615
|
-
return null;
|
|
616
|
-
}
|
|
617
|
-
if (val === null) {
|
|
618
|
-
return null;
|
|
619
|
-
}
|
|
620
|
-
return schema.metadata[SCHEMA_METADATA].parse(val, data);
|
|
621
|
-
},
|
|
688
|
+
parse,
|
|
622
689
|
coerce(val, data) {
|
|
623
690
|
if (val === null) {
|
|
624
691
|
return null;
|
|
@@ -640,39 +707,42 @@ function nullable(schema, opts = {}) {
|
|
|
640
707
|
}
|
|
641
708
|
}
|
|
642
709
|
};
|
|
710
|
+
hideInvalidProperties(result);
|
|
711
|
+
return result;
|
|
643
712
|
}
|
|
644
713
|
function optional(input, opts = {}) {
|
|
645
714
|
const isType = (val) => {
|
|
646
|
-
if (val ===
|
|
715
|
+
if (val === undefined) {
|
|
647
716
|
return true;
|
|
648
717
|
}
|
|
649
718
|
return input.metadata[SCHEMA_METADATA].validate(val);
|
|
650
719
|
};
|
|
651
|
-
|
|
720
|
+
const parse = (val, context) => {
|
|
721
|
+
if (typeof val === "undefined") {
|
|
722
|
+
return undefined;
|
|
723
|
+
}
|
|
724
|
+
if (context.instancePath.length === 0 && val === "undefined") {
|
|
725
|
+
return undefined;
|
|
726
|
+
}
|
|
727
|
+
return input.metadata[SCHEMA_METADATA].parse(val, context);
|
|
728
|
+
};
|
|
729
|
+
const result = {
|
|
652
730
|
...input,
|
|
653
731
|
metadata: {
|
|
654
732
|
id: opts.id ?? input.metadata.id,
|
|
655
733
|
description: opts.description ?? input.metadata.description,
|
|
656
734
|
isDeprecated: opts.isDeprecated ?? input.metadata.isDeprecated,
|
|
657
735
|
[SCHEMA_METADATA]: {
|
|
658
|
-
output:
|
|
736
|
+
output: undefined,
|
|
659
737
|
optional: true,
|
|
660
738
|
validate: isType,
|
|
661
|
-
parse
|
|
662
|
-
if (typeof val === "undefined") {
|
|
663
|
-
return void 0;
|
|
664
|
-
}
|
|
665
|
-
if (data.instancePath.length === 0 && val === "undefined") {
|
|
666
|
-
return void 0;
|
|
667
|
-
}
|
|
668
|
-
return input.metadata[SCHEMA_METADATA].parse(val, data);
|
|
669
|
-
},
|
|
739
|
+
parse,
|
|
670
740
|
coerce: (val, data) => {
|
|
671
741
|
if (typeof val === "undefined") {
|
|
672
|
-
return
|
|
742
|
+
return undefined;
|
|
673
743
|
}
|
|
674
744
|
if (val === "undefined") {
|
|
675
|
-
return
|
|
745
|
+
return undefined;
|
|
676
746
|
}
|
|
677
747
|
return input.metadata[SCHEMA_METADATA].coerce(val, data);
|
|
678
748
|
},
|
|
@@ -683,8 +753,11 @@ function optional(input, opts = {}) {
|
|
|
683
753
|
return input.metadata[SCHEMA_METADATA].serialize(val, data);
|
|
684
754
|
}
|
|
685
755
|
}
|
|
686
|
-
}
|
|
756
|
+
},
|
|
757
|
+
"~standard": createStandardSchemaProperty(isType, parse)
|
|
687
758
|
};
|
|
759
|
+
hideInvalidProperties(result);
|
|
760
|
+
return result;
|
|
688
761
|
}
|
|
689
762
|
function clone(input, opts = {}) {
|
|
690
763
|
const schema = {
|
|
@@ -696,8 +769,10 @@ function clone(input, opts = {}) {
|
|
|
696
769
|
[SCHEMA_METADATA]: {
|
|
697
770
|
...input.metadata[SCHEMA_METADATA]
|
|
698
771
|
}
|
|
699
|
-
}
|
|
772
|
+
},
|
|
773
|
+
"~standard": input["~standard"]
|
|
700
774
|
};
|
|
775
|
+
hideInvalidProperties(schema);
|
|
701
776
|
return schema;
|
|
702
777
|
}
|
|
703
778
|
|
|
@@ -713,7 +788,7 @@ function coerceNumber(input, options) {
|
|
|
713
788
|
schemaPath: `${options.schemaPath}/type`,
|
|
714
789
|
message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} into a number`
|
|
715
790
|
});
|
|
716
|
-
return
|
|
791
|
+
return undefined;
|
|
717
792
|
}
|
|
718
793
|
return parseNumber(parsedInput, options);
|
|
719
794
|
}
|
|
@@ -838,7 +913,7 @@ function int64(opts = {}) {
|
|
|
838
913
|
schemaPath: `${data.schemaPath}/type`,
|
|
839
914
|
instancePath: data.instancePath
|
|
840
915
|
});
|
|
841
|
-
return
|
|
916
|
+
return undefined;
|
|
842
917
|
}
|
|
843
918
|
}
|
|
844
919
|
if (isType(input)) {
|
|
@@ -849,9 +924,9 @@ function int64(opts = {}) {
|
|
|
849
924
|
schemaPath: `${data.schemaPath}/type`,
|
|
850
925
|
instancePath: data.instancePath
|
|
851
926
|
});
|
|
852
|
-
return
|
|
927
|
+
return undefined;
|
|
853
928
|
}
|
|
854
|
-
|
|
929
|
+
const result = {
|
|
855
930
|
type: "int64",
|
|
856
931
|
metadata: {
|
|
857
932
|
id: opts.id,
|
|
@@ -869,8 +944,11 @@ function int64(opts = {}) {
|
|
|
869
944
|
return `"${input.toString()}"`;
|
|
870
945
|
}
|
|
871
946
|
}
|
|
872
|
-
}
|
|
947
|
+
},
|
|
948
|
+
"~standard": createStandardSchemaProperty(isType, parse)
|
|
873
949
|
};
|
|
950
|
+
hideInvalidProperties(result);
|
|
951
|
+
return result;
|
|
874
952
|
}
|
|
875
953
|
function uint64(opts = {}) {
|
|
876
954
|
function isType(input) {
|
|
@@ -895,7 +973,7 @@ function uint64(opts = {}) {
|
|
|
895
973
|
schemaPath: `${data.schemaPath}/type`,
|
|
896
974
|
instancePath: data.instancePath
|
|
897
975
|
});
|
|
898
|
-
return
|
|
976
|
+
return undefined;
|
|
899
977
|
}
|
|
900
978
|
}
|
|
901
979
|
if (isType(input)) {
|
|
@@ -906,9 +984,9 @@ function uint64(opts = {}) {
|
|
|
906
984
|
schemaPath: `${data.schemaPath}/type`,
|
|
907
985
|
instancePath: data.instancePath
|
|
908
986
|
});
|
|
909
|
-
return
|
|
987
|
+
return undefined;
|
|
910
988
|
}
|
|
911
|
-
|
|
989
|
+
const result = {
|
|
912
990
|
type: "uint64",
|
|
913
991
|
metadata: {
|
|
914
992
|
id: opts.id,
|
|
@@ -926,11 +1004,14 @@ function uint64(opts = {}) {
|
|
|
926
1004
|
return `"${input.toString()}"`;
|
|
927
1005
|
}
|
|
928
1006
|
}
|
|
929
|
-
}
|
|
1007
|
+
},
|
|
1008
|
+
"~standard": createStandardSchemaProperty(isType, parse)
|
|
930
1009
|
};
|
|
1010
|
+
hideInvalidProperties(result);
|
|
1011
|
+
return result;
|
|
931
1012
|
}
|
|
932
1013
|
function validateNumber(input) {
|
|
933
|
-
return typeof input === "number"
|
|
1014
|
+
return typeof input === "number";
|
|
934
1015
|
}
|
|
935
1016
|
function validateInt(input, minVal, maxValue) {
|
|
936
1017
|
return Number.isInteger(input) && input >= minVal && input <= maxValue;
|
|
@@ -947,7 +1028,7 @@ function parseNumber(input, options) {
|
|
|
947
1028
|
schemaPath: `${options.schemaPath}/type`,
|
|
948
1029
|
message: `Error at ${options.instancePath}. Invalid number.`
|
|
949
1030
|
});
|
|
950
|
-
return
|
|
1031
|
+
return undefined;
|
|
951
1032
|
}
|
|
952
1033
|
return result;
|
|
953
1034
|
}
|
|
@@ -959,10 +1040,41 @@ function parseNumber(input, options) {
|
|
|
959
1040
|
schemaPath: `${options.schemaPath}/type`,
|
|
960
1041
|
message: `Error at ${options.instancePath}. Invalid number.`
|
|
961
1042
|
});
|
|
962
|
-
return
|
|
1043
|
+
return undefined;
|
|
963
1044
|
}
|
|
964
1045
|
function numberScalarType(type, opts, numTypeMatcher) {
|
|
965
|
-
|
|
1046
|
+
const validate = (input) => {
|
|
1047
|
+
const isNum = validateNumber(input);
|
|
1048
|
+
if (!isNum) {
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
1051
|
+
return numTypeMatcher(input).success;
|
|
1052
|
+
};
|
|
1053
|
+
const parse = (input, context) => {
|
|
1054
|
+
const result2 = parseNumber(input, context);
|
|
1055
|
+
if (context.errors.length) {
|
|
1056
|
+
return undefined;
|
|
1057
|
+
}
|
|
1058
|
+
if (typeof result2 !== "number") {
|
|
1059
|
+
context?.errors.push({
|
|
1060
|
+
instancePath: context.instancePath,
|
|
1061
|
+
schemaPath: `${context.schemaPath}/type`,
|
|
1062
|
+
message: `Error at ${context.instancePath}. Invalid number.`
|
|
1063
|
+
});
|
|
1064
|
+
return undefined;
|
|
1065
|
+
}
|
|
1066
|
+
const matchResult = numTypeMatcher(result2);
|
|
1067
|
+
if (matchResult.success) {
|
|
1068
|
+
return result2;
|
|
1069
|
+
}
|
|
1070
|
+
context?.errors.push({
|
|
1071
|
+
instancePath: context.instancePath,
|
|
1072
|
+
schemaPath: `${context.schemaPath}/type`,
|
|
1073
|
+
message: `Error at ${context.instancePath}. ${matchResult.message}`
|
|
1074
|
+
});
|
|
1075
|
+
return undefined;
|
|
1076
|
+
};
|
|
1077
|
+
const result = {
|
|
966
1078
|
type,
|
|
967
1079
|
metadata: {
|
|
968
1080
|
id: opts.id,
|
|
@@ -970,62 +1082,36 @@ function numberScalarType(type, opts, numTypeMatcher) {
|
|
|
970
1082
|
isDeprecated: opts.isDeprecated,
|
|
971
1083
|
[SCHEMA_METADATA]: {
|
|
972
1084
|
output: 0,
|
|
973
|
-
validate
|
|
974
|
-
|
|
975
|
-
if (!isNum) {
|
|
976
|
-
return false;
|
|
977
|
-
}
|
|
978
|
-
return numTypeMatcher(input).success;
|
|
979
|
-
},
|
|
980
|
-
parse(input, options) {
|
|
981
|
-
const result = parseNumber(input, options);
|
|
982
|
-
if (options.errors.length) {
|
|
983
|
-
return void 0;
|
|
984
|
-
}
|
|
985
|
-
if (typeof result !== "number") {
|
|
986
|
-
options?.errors.push({
|
|
987
|
-
instancePath: options.instancePath,
|
|
988
|
-
schemaPath: `${options.schemaPath}/type`,
|
|
989
|
-
message: `Error at ${options.instancePath}. Invalid number.`
|
|
990
|
-
});
|
|
991
|
-
return void 0;
|
|
992
|
-
}
|
|
993
|
-
const matchResult = numTypeMatcher(result);
|
|
994
|
-
if (matchResult.success) {
|
|
995
|
-
return result;
|
|
996
|
-
}
|
|
997
|
-
options?.errors.push({
|
|
998
|
-
instancePath: options.instancePath,
|
|
999
|
-
schemaPath: `${options.schemaPath}/type`,
|
|
1000
|
-
message: `Error at ${options.instancePath}. ${matchResult.message}`
|
|
1001
|
-
});
|
|
1002
|
-
return void 0;
|
|
1003
|
-
},
|
|
1085
|
+
validate,
|
|
1086
|
+
parse,
|
|
1004
1087
|
serialize: serializeNumber,
|
|
1005
1088
|
coerce(input, options) {
|
|
1006
|
-
const
|
|
1007
|
-
if (typeof
|
|
1089
|
+
const result2 = coerceNumber(input, options);
|
|
1090
|
+
if (typeof result2 !== "number") {
|
|
1008
1091
|
options.errors.push({
|
|
1009
1092
|
instancePath: options.instancePath,
|
|
1010
1093
|
schemaPath: `${options.schemaPath}/type`,
|
|
1011
1094
|
message: `Error at ${options.instancePath}. Unable to coerce ${typeof input} to ${type}.`
|
|
1012
1095
|
});
|
|
1013
|
-
return
|
|
1096
|
+
return undefined;
|
|
1014
1097
|
}
|
|
1015
|
-
const matchResult = numTypeMatcher(
|
|
1098
|
+
const matchResult = numTypeMatcher(result2);
|
|
1016
1099
|
if (matchResult.success) {
|
|
1017
|
-
return
|
|
1100
|
+
return result2;
|
|
1018
1101
|
}
|
|
1019
1102
|
options.errors.push({
|
|
1020
1103
|
instancePath: options.instancePath,
|
|
1021
1104
|
schemaPath: `${options.schemaPath}/type`,
|
|
1022
1105
|
message: `Error at ${options.instancePath}. ${matchResult.message}`
|
|
1023
1106
|
});
|
|
1024
|
-
return
|
|
1107
|
+
return undefined;
|
|
1025
1108
|
}
|
|
1026
1109
|
}
|
|
1027
|
-
}
|
|
1110
|
+
},
|
|
1111
|
+
"~standard": createStandardSchemaProperty(validate, parse)
|
|
1028
1112
|
};
|
|
1113
|
+
hideInvalidProperties(result);
|
|
1114
|
+
return result;
|
|
1029
1115
|
}
|
|
1030
1116
|
|
|
1031
1117
|
function object(propA, propB) {
|
|
@@ -1049,6 +1135,17 @@ function object(propA, propB) {
|
|
|
1049
1135
|
}
|
|
1050
1136
|
schema.properties[key] = prop;
|
|
1051
1137
|
}
|
|
1138
|
+
const validate = (input2) => {
|
|
1139
|
+
return validateObjectSchema(schema, input2);
|
|
1140
|
+
};
|
|
1141
|
+
const parse = (input2, context) => {
|
|
1142
|
+
return parseObjectSchema(
|
|
1143
|
+
schema,
|
|
1144
|
+
input2,
|
|
1145
|
+
context,
|
|
1146
|
+
false
|
|
1147
|
+
);
|
|
1148
|
+
};
|
|
1052
1149
|
const result = {
|
|
1053
1150
|
...schema,
|
|
1054
1151
|
metadata: {
|
|
@@ -1057,14 +1154,7 @@ function object(propA, propB) {
|
|
|
1057
1154
|
isDeprecated: options.isDeprecated,
|
|
1058
1155
|
[SCHEMA_METADATA]: {
|
|
1059
1156
|
output: {},
|
|
1060
|
-
parse
|
|
1061
|
-
return parseObjectSchema(
|
|
1062
|
-
schema,
|
|
1063
|
-
input2,
|
|
1064
|
-
context,
|
|
1065
|
-
false
|
|
1066
|
-
);
|
|
1067
|
-
},
|
|
1157
|
+
parse,
|
|
1068
1158
|
coerce(input2, context) {
|
|
1069
1159
|
return parseObjectSchema(
|
|
1070
1160
|
schema,
|
|
@@ -1073,9 +1163,7 @@ function object(propA, propB) {
|
|
|
1073
1163
|
true
|
|
1074
1164
|
);
|
|
1075
1165
|
},
|
|
1076
|
-
validate
|
|
1077
|
-
return validateObjectSchema(schema, input2);
|
|
1078
|
-
},
|
|
1166
|
+
validate,
|
|
1079
1167
|
serialize(input2, context) {
|
|
1080
1168
|
return serializeObject(
|
|
1081
1169
|
schema,
|
|
@@ -1084,8 +1172,10 @@ function object(propA, propB) {
|
|
|
1084
1172
|
);
|
|
1085
1173
|
}
|
|
1086
1174
|
}
|
|
1087
|
-
}
|
|
1175
|
+
},
|
|
1176
|
+
"~standard": createStandardSchemaProperty(validate, parse)
|
|
1088
1177
|
};
|
|
1178
|
+
hideInvalidProperties(result);
|
|
1089
1179
|
return result;
|
|
1090
1180
|
}
|
|
1091
1181
|
function parseObjectSchema(schema, input, data, coerce = false) {
|
|
@@ -1100,7 +1190,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
|
|
|
1100
1190
|
schemaPath: `${data.schemaPath}/properties`,
|
|
1101
1191
|
message: `Error at ${data.instancePath}. Invalid JSON.`
|
|
1102
1192
|
});
|
|
1103
|
-
return
|
|
1193
|
+
return undefined;
|
|
1104
1194
|
}
|
|
1105
1195
|
}
|
|
1106
1196
|
if (!isObject(parsedInput)) {
|
|
@@ -1109,7 +1199,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
|
|
|
1109
1199
|
schemaPath: `${data.schemaPath}/properties`,
|
|
1110
1200
|
message: `Error at ${data.instancePath}. Expected object`
|
|
1111
1201
|
});
|
|
1112
|
-
return
|
|
1202
|
+
return undefined;
|
|
1113
1203
|
}
|
|
1114
1204
|
const result = {};
|
|
1115
1205
|
const optionalProps = schema.optionalProperties ?? {};
|
|
@@ -1128,7 +1218,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
|
|
|
1128
1218
|
}
|
|
1129
1219
|
}
|
|
1130
1220
|
if (data.errors.length) {
|
|
1131
|
-
return
|
|
1221
|
+
return undefined;
|
|
1132
1222
|
}
|
|
1133
1223
|
if (data.discriminatorKey) {
|
|
1134
1224
|
result[data.discriminatorKey] = data.discriminatorValue;
|
|
@@ -1153,7 +1243,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
|
|
|
1153
1243
|
for (const key of optionalKeys) {
|
|
1154
1244
|
const val = parsedInput[key];
|
|
1155
1245
|
const prop = optionalProps[key];
|
|
1156
|
-
if (val ===
|
|
1246
|
+
if (val === undefined) {
|
|
1157
1247
|
continue;
|
|
1158
1248
|
}
|
|
1159
1249
|
if (coerce) {
|
|
@@ -1173,7 +1263,7 @@ function parseObjectSchema(schema, input, data, coerce = false) {
|
|
|
1173
1263
|
}
|
|
1174
1264
|
}
|
|
1175
1265
|
if (data.errors.length) {
|
|
1176
|
-
return
|
|
1266
|
+
return undefined;
|
|
1177
1267
|
}
|
|
1178
1268
|
return result;
|
|
1179
1269
|
}
|
|
@@ -1181,17 +1271,28 @@ function validateObjectSchema(schema, input) {
|
|
|
1181
1271
|
if (!isObject(input)) {
|
|
1182
1272
|
return false;
|
|
1183
1273
|
}
|
|
1184
|
-
const
|
|
1185
|
-
for (const key of Object.keys(
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1188
|
-
|
|
1274
|
+
const allowedKeys = schema.strict ? [] : undefined;
|
|
1275
|
+
for (const key of Object.keys(schema.properties)) {
|
|
1276
|
+
const propSchema = schema.properties[key];
|
|
1277
|
+
const isValid = propSchema.metadata[SCHEMA_METADATA].validate(
|
|
1278
|
+
input[key]
|
|
1279
|
+
);
|
|
1280
|
+
if (!isValid) return false;
|
|
1281
|
+
allowedKeys?.push(key);
|
|
1282
|
+
}
|
|
1283
|
+
if (schema.optionalProperties) {
|
|
1284
|
+
for (const key of Object.keys(schema.optionalProperties)) {
|
|
1285
|
+
const propsSchema = schema.optionalProperties[key];
|
|
1286
|
+
const isValid = propsSchema.metadata[SCHEMA_METADATA].validate(
|
|
1287
|
+
input[key]
|
|
1288
|
+
);
|
|
1289
|
+
if (!isValid) return false;
|
|
1290
|
+
allowedKeys?.push(key);
|
|
1189
1291
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
}
|
|
1292
|
+
}
|
|
1293
|
+
if (allowedKeys) {
|
|
1294
|
+
for (const key of Object.keys(input)) {
|
|
1295
|
+
if (!allowedKeys.includes(key)) return false;
|
|
1195
1296
|
}
|
|
1196
1297
|
}
|
|
1197
1298
|
return true;
|
|
@@ -1223,7 +1324,13 @@ function pick(inputSchema, keys, options = {}) {
|
|
|
1223
1324
|
}
|
|
1224
1325
|
});
|
|
1225
1326
|
}
|
|
1226
|
-
|
|
1327
|
+
const parse = (input, context) => {
|
|
1328
|
+
return parseObjectSchema(schema, input, context, false);
|
|
1329
|
+
};
|
|
1330
|
+
const validate = (input) => {
|
|
1331
|
+
return validateObjectSchema(schema, input);
|
|
1332
|
+
};
|
|
1333
|
+
const result = {
|
|
1227
1334
|
...schema,
|
|
1228
1335
|
metadata: {
|
|
1229
1336
|
id: options.id,
|
|
@@ -1231,14 +1338,7 @@ function pick(inputSchema, keys, options = {}) {
|
|
|
1231
1338
|
isDeprecated: options.isDeprecated,
|
|
1232
1339
|
[SCHEMA_METADATA]: {
|
|
1233
1340
|
output: {},
|
|
1234
|
-
parse
|
|
1235
|
-
return parseObjectSchema(
|
|
1236
|
-
schema,
|
|
1237
|
-
input,
|
|
1238
|
-
context,
|
|
1239
|
-
true
|
|
1240
|
-
);
|
|
1241
|
-
},
|
|
1341
|
+
parse,
|
|
1242
1342
|
coerce(input, context) {
|
|
1243
1343
|
return parseObjectSchema(
|
|
1244
1344
|
schema,
|
|
@@ -1247,15 +1347,16 @@ function pick(inputSchema, keys, options = {}) {
|
|
|
1247
1347
|
false
|
|
1248
1348
|
);
|
|
1249
1349
|
},
|
|
1250
|
-
validate
|
|
1251
|
-
return validateObjectSchema(schema, input);
|
|
1252
|
-
},
|
|
1350
|
+
validate,
|
|
1253
1351
|
serialize(input, context) {
|
|
1254
1352
|
return serializeObject(schema, input, context);
|
|
1255
1353
|
}
|
|
1256
1354
|
}
|
|
1257
|
-
}
|
|
1355
|
+
},
|
|
1356
|
+
"~standard": createStandardSchemaProperty(validate, parse)
|
|
1258
1357
|
};
|
|
1358
|
+
hideInvalidProperties(result);
|
|
1359
|
+
return result;
|
|
1259
1360
|
}
|
|
1260
1361
|
function omit(inputSchema, keys, options = {}) {
|
|
1261
1362
|
const schema = {
|
|
@@ -1285,7 +1386,9 @@ function omit(inputSchema, keys, options = {}) {
|
|
|
1285
1386
|
}
|
|
1286
1387
|
});
|
|
1287
1388
|
}
|
|
1288
|
-
|
|
1389
|
+
const validate = (input) => validateObjectSchema(schema, input);
|
|
1390
|
+
const parse = (input, context) => parseObjectSchema(schema, input, context, false);
|
|
1391
|
+
const result = {
|
|
1289
1392
|
...schema,
|
|
1290
1393
|
metadata: {
|
|
1291
1394
|
id: options.id,
|
|
@@ -1293,12 +1396,8 @@ function omit(inputSchema, keys, options = {}) {
|
|
|
1293
1396
|
isDeprecated: options.isDeprecated,
|
|
1294
1397
|
[SCHEMA_METADATA]: {
|
|
1295
1398
|
output: {},
|
|
1296
|
-
validate
|
|
1297
|
-
|
|
1298
|
-
},
|
|
1299
|
-
parse(input, data) {
|
|
1300
|
-
return parseObjectSchema(schema, input, data, false);
|
|
1301
|
-
},
|
|
1399
|
+
validate,
|
|
1400
|
+
parse,
|
|
1302
1401
|
serialize(input, context) {
|
|
1303
1402
|
return serializeObject(schema, input, context);
|
|
1304
1403
|
},
|
|
@@ -1311,8 +1410,11 @@ function omit(inputSchema, keys, options = {}) {
|
|
|
1311
1410
|
);
|
|
1312
1411
|
}
|
|
1313
1412
|
}
|
|
1314
|
-
}
|
|
1413
|
+
},
|
|
1414
|
+
"~standard": createStandardSchemaProperty(validate, parse)
|
|
1315
1415
|
};
|
|
1416
|
+
hideInvalidProperties(result);
|
|
1417
|
+
return result;
|
|
1316
1418
|
}
|
|
1317
1419
|
function serializeObject(schema, input, data) {
|
|
1318
1420
|
const strParts = [];
|
|
@@ -1409,23 +1511,20 @@ function partial(schema, options = {}) {
|
|
|
1409
1511
|
}
|
|
1410
1512
|
}
|
|
1411
1513
|
}
|
|
1514
|
+
const validate = (input) => {
|
|
1515
|
+
return validateObjectSchema(newSchema, input);
|
|
1516
|
+
};
|
|
1517
|
+
const parse = (input, context) => {
|
|
1518
|
+
return parseObjectSchema(newSchema, input, context, false);
|
|
1519
|
+
};
|
|
1412
1520
|
const meta = {
|
|
1413
1521
|
id: options.id,
|
|
1414
1522
|
description: options.description,
|
|
1415
1523
|
[SCHEMA_METADATA]: {
|
|
1416
1524
|
output: {},
|
|
1417
1525
|
optional: schema.metadata[SCHEMA_METADATA].optional,
|
|
1418
|
-
validate
|
|
1419
|
-
|
|
1420
|
-
},
|
|
1421
|
-
parse(input, context) {
|
|
1422
|
-
return parseObjectSchema(
|
|
1423
|
-
newSchema,
|
|
1424
|
-
input,
|
|
1425
|
-
context,
|
|
1426
|
-
false
|
|
1427
|
-
);
|
|
1428
|
-
},
|
|
1526
|
+
validate,
|
|
1527
|
+
parse,
|
|
1429
1528
|
coerce(input, context) {
|
|
1430
1529
|
return parseObjectSchema(
|
|
1431
1530
|
newSchema,
|
|
@@ -1440,11 +1539,16 @@ function partial(schema, options = {}) {
|
|
|
1440
1539
|
}
|
|
1441
1540
|
};
|
|
1442
1541
|
newSchema.metadata = meta;
|
|
1542
|
+
newSchema["~standard"] = createStandardSchemaProperty(
|
|
1543
|
+
validate,
|
|
1544
|
+
parse
|
|
1545
|
+
);
|
|
1546
|
+
hideInvalidProperties(newSchema);
|
|
1443
1547
|
return newSchema;
|
|
1444
1548
|
}
|
|
1445
1549
|
|
|
1446
1550
|
function string(opts = {}) {
|
|
1447
|
-
|
|
1551
|
+
const result = {
|
|
1448
1552
|
type: "string",
|
|
1449
1553
|
metadata: {
|
|
1450
1554
|
id: opts.id,
|
|
@@ -1468,8 +1572,11 @@ function string(opts = {}) {
|
|
|
1468
1572
|
return JSON.stringify(input);
|
|
1469
1573
|
}
|
|
1470
1574
|
}
|
|
1471
|
-
}
|
|
1575
|
+
},
|
|
1576
|
+
"~standard": createStandardSchemaProperty(validate$1, parse$2)
|
|
1472
1577
|
};
|
|
1578
|
+
hideInvalidProperties(result);
|
|
1579
|
+
return result;
|
|
1473
1580
|
}
|
|
1474
1581
|
function serializeString(input) {
|
|
1475
1582
|
if (input.length < 42) {
|
|
@@ -1492,7 +1599,7 @@ function parse$2(input, context) {
|
|
|
1492
1599
|
schemaPath: `${context.schemaPath}/type`,
|
|
1493
1600
|
message: `Error at ${context.instancePath}. Expected 'string' got ${typeof input}.`
|
|
1494
1601
|
});
|
|
1495
|
-
return
|
|
1602
|
+
return undefined;
|
|
1496
1603
|
}
|
|
1497
1604
|
function coerce$1(input, context) {
|
|
1498
1605
|
return parse$2(input, context);
|
|
@@ -1527,7 +1634,23 @@ function serializeSmallString(input) {
|
|
|
1527
1634
|
}
|
|
1528
1635
|
|
|
1529
1636
|
function record(schema, opts = {}) {
|
|
1530
|
-
|
|
1637
|
+
const validateFn = (input) => {
|
|
1638
|
+
if (!isObject(input)) {
|
|
1639
|
+
return false;
|
|
1640
|
+
}
|
|
1641
|
+
for (const key of Object.keys(input)) {
|
|
1642
|
+
const val = input[key];
|
|
1643
|
+
const isValid = schema.metadata[SCHEMA_METADATA].validate(val);
|
|
1644
|
+
if (!isValid) {
|
|
1645
|
+
return false;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
return true;
|
|
1649
|
+
};
|
|
1650
|
+
const parseFn = (input, ctx) => {
|
|
1651
|
+
return parse$1(schema, input, ctx, false);
|
|
1652
|
+
};
|
|
1653
|
+
const result = {
|
|
1531
1654
|
values: schema,
|
|
1532
1655
|
metadata: {
|
|
1533
1656
|
id: opts.id,
|
|
@@ -1535,35 +1658,21 @@ function record(schema, opts = {}) {
|
|
|
1535
1658
|
isDeprecated: opts.isDeprecated,
|
|
1536
1659
|
[SCHEMA_METADATA]: {
|
|
1537
1660
|
output: {},
|
|
1538
|
-
validate
|
|
1539
|
-
|
|
1540
|
-
return false;
|
|
1541
|
-
}
|
|
1542
|
-
for (const key of Object.keys(input)) {
|
|
1543
|
-
const val = input[key];
|
|
1544
|
-
const isValid = schema.metadata[SCHEMA_METADATA].validate(val);
|
|
1545
|
-
if (!isValid) {
|
|
1546
|
-
return false;
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
return true;
|
|
1550
|
-
},
|
|
1551
|
-
parse(input, context) {
|
|
1552
|
-
return parse$1(schema, input, context, false);
|
|
1553
|
-
},
|
|
1661
|
+
validate: validateFn,
|
|
1662
|
+
parse: parseFn,
|
|
1554
1663
|
coerce(input, data) {
|
|
1555
1664
|
return parse$1(schema, input, data, true);
|
|
1556
1665
|
},
|
|
1557
1666
|
serialize(input, context) {
|
|
1558
|
-
let
|
|
1667
|
+
let result2 = "{";
|
|
1559
1668
|
const keys = Object.keys(input);
|
|
1560
1669
|
for (let i = 0; i < keys.length; i++) {
|
|
1561
1670
|
const key = keys[i];
|
|
1562
1671
|
const val = input[key];
|
|
1563
|
-
if (i > 0)
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1672
|
+
if (i > 0) result2 += ",";
|
|
1673
|
+
result2 += serializeString(key);
|
|
1674
|
+
result2 += ":";
|
|
1675
|
+
result2 += schema.metadata[SCHEMA_METADATA].serialize(
|
|
1567
1676
|
val,
|
|
1568
1677
|
{
|
|
1569
1678
|
instancePath: `${context.instancePath}/${key}`,
|
|
@@ -1572,12 +1681,15 @@ function record(schema, opts = {}) {
|
|
|
1572
1681
|
}
|
|
1573
1682
|
);
|
|
1574
1683
|
}
|
|
1575
|
-
|
|
1576
|
-
return
|
|
1684
|
+
result2 += "}";
|
|
1685
|
+
return result2;
|
|
1577
1686
|
}
|
|
1578
1687
|
}
|
|
1579
|
-
}
|
|
1688
|
+
},
|
|
1689
|
+
"~standard": createStandardSchemaProperty(validateFn, parseFn)
|
|
1580
1690
|
};
|
|
1691
|
+
hideInvalidProperties(result);
|
|
1692
|
+
return result;
|
|
1581
1693
|
}
|
|
1582
1694
|
function parse$1(schema, input, data, coerce = false) {
|
|
1583
1695
|
let parsedInput = input;
|
|
@@ -1590,7 +1702,7 @@ function parse$1(schema, input, data, coerce = false) {
|
|
|
1590
1702
|
schemaPath: `${data.schemaPath}/values`,
|
|
1591
1703
|
message: `Error at ${data.instancePath} Expected object`
|
|
1592
1704
|
});
|
|
1593
|
-
return
|
|
1705
|
+
return undefined;
|
|
1594
1706
|
}
|
|
1595
1707
|
const result = {};
|
|
1596
1708
|
for (const key of Object.keys(parsedInput)) {
|
|
@@ -1610,7 +1722,7 @@ function parse$1(schema, input, data, coerce = false) {
|
|
|
1610
1722
|
}
|
|
1611
1723
|
}
|
|
1612
1724
|
if (data.errors.length) {
|
|
1613
|
-
return
|
|
1725
|
+
return undefined;
|
|
1614
1726
|
}
|
|
1615
1727
|
return result;
|
|
1616
1728
|
}
|
|
@@ -1628,36 +1740,43 @@ function recursive(propA, propB) {
|
|
|
1628
1740
|
);
|
|
1629
1741
|
}
|
|
1630
1742
|
const id = options.id ?? `TypeRef${recursiveTypeCount}`;
|
|
1631
|
-
const
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
if (recursiveFns[id]) {
|
|
1655
|
-
return recursiveFns[id].coerce(input, context);
|
|
1656
|
-
}
|
|
1743
|
+
const metadata = {
|
|
1744
|
+
[SCHEMA_METADATA]: {
|
|
1745
|
+
output: "",
|
|
1746
|
+
parse(input, context) {
|
|
1747
|
+
if (recursiveFns[id]) {
|
|
1748
|
+
return recursiveFns[id].parse(input, context);
|
|
1749
|
+
}
|
|
1750
|
+
},
|
|
1751
|
+
serialize(input, context) {
|
|
1752
|
+
if (recursiveFns[id]) {
|
|
1753
|
+
return recursiveFns[id].serialize(input, context);
|
|
1754
|
+
}
|
|
1755
|
+
return "";
|
|
1756
|
+
},
|
|
1757
|
+
validate(input) {
|
|
1758
|
+
if (recursiveFns[id]) {
|
|
1759
|
+
return recursiveFns[id].validate(input);
|
|
1760
|
+
}
|
|
1761
|
+
return false;
|
|
1762
|
+
},
|
|
1763
|
+
coerce(input, context) {
|
|
1764
|
+
if (recursiveFns[id]) {
|
|
1765
|
+
return recursiveFns[id].coerce(input, context);
|
|
1657
1766
|
}
|
|
1658
1767
|
}
|
|
1659
1768
|
}
|
|
1660
|
-
}
|
|
1769
|
+
};
|
|
1770
|
+
const schema = {
|
|
1771
|
+
ref: id,
|
|
1772
|
+
metadata,
|
|
1773
|
+
"~standard": createStandardSchemaProperty(
|
|
1774
|
+
metadata[SCHEMA_METADATA].validate,
|
|
1775
|
+
metadata[SCHEMA_METADATA].parse
|
|
1776
|
+
)
|
|
1777
|
+
};
|
|
1778
|
+
hideInvalidProperties(schema);
|
|
1779
|
+
const mainSchema = callback(schema);
|
|
1661
1780
|
mainSchema.metadata.id = id;
|
|
1662
1781
|
mainSchema.metadata.description = options?.description ?? mainSchema.metadata.description;
|
|
1663
1782
|
mainSchema.metadata.isDeprecated = options?.isDeprecated ?? mainSchema.metadata.isDeprecated;
|
|
@@ -1671,7 +1790,7 @@ function recursive(propA, propB) {
|
|
|
1671
1790
|
}
|
|
1672
1791
|
|
|
1673
1792
|
function timestamp(opts = {}) {
|
|
1674
|
-
|
|
1793
|
+
const result = {
|
|
1675
1794
|
type: "timestamp",
|
|
1676
1795
|
metadata: {
|
|
1677
1796
|
id: opts.id,
|
|
@@ -1684,8 +1803,11 @@ function timestamp(opts = {}) {
|
|
|
1684
1803
|
coerce,
|
|
1685
1804
|
serialize
|
|
1686
1805
|
}
|
|
1687
|
-
}
|
|
1806
|
+
},
|
|
1807
|
+
"~standard": createStandardSchemaProperty(validate, parse)
|
|
1688
1808
|
};
|
|
1809
|
+
hideInvalidProperties(result);
|
|
1810
|
+
return result;
|
|
1689
1811
|
}
|
|
1690
1812
|
function validate(input) {
|
|
1691
1813
|
return typeof input === "object" && input instanceof Date;
|
|
@@ -1702,7 +1824,7 @@ function parse(input, data) {
|
|
|
1702
1824
|
instancePath: data.instancePath,
|
|
1703
1825
|
schemaPath: `${data.schemaPath}/type`
|
|
1704
1826
|
});
|
|
1705
|
-
return
|
|
1827
|
+
return undefined;
|
|
1706
1828
|
}
|
|
1707
1829
|
return new Date(result);
|
|
1708
1830
|
}
|
|
@@ -1711,7 +1833,7 @@ function parse(input, data) {
|
|
|
1711
1833
|
instancePath: data.instancePath,
|
|
1712
1834
|
schemaPath: `${data.schemaPath}/type`
|
|
1713
1835
|
});
|
|
1714
|
-
return
|
|
1836
|
+
return undefined;
|
|
1715
1837
|
}
|
|
1716
1838
|
function coerce(input, options) {
|
|
1717
1839
|
if (typeof input === "number") {
|
|
@@ -1726,4 +1848,4 @@ function serialize(input, data) {
|
|
|
1726
1848
|
return `"${input.toISOString()}"`;
|
|
1727
1849
|
}
|
|
1728
1850
|
|
|
1729
|
-
export {
|
|
1851
|
+
export { uint32 as $, discriminator as A, enumerator as B, extend as C, float32 as D, float64 as E, int16 as F, int32 as G, int64 as H, int8 as I, nullable as J, number as K, object as L, omit as M, optional as N, parse$4 as O, partial as P, pick as Q, record as R, recursive as S, safeCoerce as T, safeParse as U, ValidationError as V, serialize$1 as W, string as X, stringEnum as Y, timestamp as Z, uint16 as _, uint8Min as a, uint64 as a0, uint8 as a1, validate$3 as a2, SCHEMA_METADATA as a3, int64Min as a4, int64Max as a5, uint64Min as a6, uint64Max as a7, parseObjectSchema as a8, validateObjectSchema as a9, serializeObject as aa, serializeString as ab, STR_ESCAPE as ac, serializeSmallString as ad, sanitizeJson as ae, isValidationError as af, isASchema as ag, NumberTypeValues as ah, isObject as ai, hideInvalidProperties as aj, uint16Max as b, uint16Min as c, uint32Max as d, uint32Min as e, int8Min as f, int16Max as g, int16Min as h, int8Max as i, int32Max as j, int32Min as k, isAScalarSchema as l, isAObjectSchema as m, isAStringEnumSchema as n, isAAraySchema as o, isARecordSchema as p, isADiscriminatorSchema as q, isARefSchema as r, errors as s, createStandardSchemaProperty as t, uint8Max as u, any as v, array as w, boolean as x, clone as y, coerce$2 as z };
|