@arrirpc/schema 0.78.0 → 0.79.1
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 +57 -1
- package/dist/adapters.d.cts +2 -2
- package/dist/adapters.d.mts +2 -2
- package/dist/adapters.d.ts +2 -2
- package/dist/index.cjs +111 -90
- package/dist/index.d.cts +22 -9
- package/dist/index.d.mts +22 -9
- package/dist/index.d.ts +22 -9
- package/dist/index.mjs +111 -91
- package/dist/shared/{schema.hMebmI3A.d.cts → schema.CS4qvHhE.d.cts} +21 -14
- package/dist/shared/{schema.hMebmI3A.d.mts → schema.CS4qvHhE.d.mts} +21 -14
- package/dist/shared/{schema.hMebmI3A.d.ts → schema.CS4qvHhE.d.ts} +21 -14
- package/package.json +9 -8
package/dist/index.cjs
CHANGED
|
@@ -147,7 +147,7 @@ function booleanTemplate$2(input) {
|
|
|
147
147
|
else if (${input.val} === false || ${input.val} === 'false' || ${input.val} === 'FALSE' || ${input.val} === 0 || ${input.val} === '0') {
|
|
148
148
|
${input.targetVal} = false;
|
|
149
149
|
}`);
|
|
150
|
-
if (input.schema.
|
|
150
|
+
if (input.schema.isNullable) {
|
|
151
151
|
templateParts.push(`else if (${input.val} === null || ${input.val} === 'null') {
|
|
152
152
|
${input.targetVal} = null;
|
|
153
153
|
}`);
|
|
@@ -167,7 +167,7 @@ function booleanTemplate$2(input) {
|
|
|
167
167
|
if (${input.val} === 'false') {
|
|
168
168
|
${input.targetVal} = false;
|
|
169
169
|
}`);
|
|
170
|
-
if (input.schema.
|
|
170
|
+
if (input.schema.isNullable) {
|
|
171
171
|
templateParts.push(`if (${input.val} === 'null') {
|
|
172
172
|
${input.targetVal} = null;
|
|
173
173
|
}`);
|
|
@@ -182,7 +182,7 @@ function booleanTemplate$2(input) {
|
|
|
182
182
|
} else {
|
|
183
183
|
$fallback("${input.instancePath}", "${input.schemaPath}/type", "${errorMessage}");
|
|
184
184
|
}`;
|
|
185
|
-
if (input.schema.
|
|
185
|
+
if (input.schema.isNullable) {
|
|
186
186
|
templateParts.push(`if (${input.val} === null) {
|
|
187
187
|
${input.targetVal} = null;
|
|
188
188
|
} else {
|
|
@@ -200,7 +200,7 @@ function stringTemplate$2(input) {
|
|
|
200
200
|
} else {
|
|
201
201
|
$fallback("${input.instancePath}", "${input.schemaPath}/type", "${errorMessage}");
|
|
202
202
|
}`;
|
|
203
|
-
if (input.schema.
|
|
203
|
+
if (input.schema.isNullable) {
|
|
204
204
|
return `if (${input.val} === null) {
|
|
205
205
|
${input.targetVal} = ${input.val};
|
|
206
206
|
} else {
|
|
@@ -223,7 +223,7 @@ function floatTemplate$1(input) {
|
|
|
223
223
|
if (!Number.isNaN(${valName})) {
|
|
224
224
|
${input.targetVal} = ${valName};
|
|
225
225
|
}`);
|
|
226
|
-
if (input.schema.
|
|
226
|
+
if (input.schema.isNullable) {
|
|
227
227
|
templateParts.push(`else if (${input.val} === 'null') {
|
|
228
228
|
${input.targetVal} = null;
|
|
229
229
|
}`);
|
|
@@ -241,7 +241,7 @@ function floatTemplate$1(input) {
|
|
|
241
241
|
} else {
|
|
242
242
|
$fallback("${input.instancePath}", "${input.schemaPath}/type", "${errorMessage}");
|
|
243
243
|
}`;
|
|
244
|
-
if (input.schema.
|
|
244
|
+
if (input.schema.isNullable) {
|
|
245
245
|
templateParts.push(`${input.instancePath.length === 0 || input.shouldCoerce ? "else " : ""}if (${input.val} === null) {
|
|
246
246
|
${input.targetVal} = null;
|
|
247
247
|
} else {
|
|
@@ -263,7 +263,7 @@ function intTemplate$1(input, min, max) {
|
|
|
263
263
|
if (Number.isInteger(parsedVal) && parsedVal >= ${min} && parsedVal <= ${max}) {
|
|
264
264
|
${input.targetVal} = parsedVal;
|
|
265
265
|
}`);
|
|
266
|
-
if (input.schema.
|
|
266
|
+
if (input.schema.isNullable) {
|
|
267
267
|
templateParts.push(`else if (${input.val} === 'null') {
|
|
268
268
|
${input.targetVal} = null;
|
|
269
269
|
}`);
|
|
@@ -281,7 +281,7 @@ function intTemplate$1(input, min, max) {
|
|
|
281
281
|
$fallback("${input.instancePath}", "${input.schemaPath}", "Expected valid integer between ${min} and ${max}");
|
|
282
282
|
}`;
|
|
283
283
|
const prefix = shouldCoerce ? `else ` : "";
|
|
284
|
-
if (input.schema.
|
|
284
|
+
if (input.schema.isNullable) {
|
|
285
285
|
templateParts.push(`${prefix}if (${input.val} === null) {
|
|
286
286
|
${input.targetVal} = null;
|
|
287
287
|
} else {
|
|
@@ -297,7 +297,7 @@ function bigIntTemplate$2(input, isUnsigned) {
|
|
|
297
297
|
templateParts.push(
|
|
298
298
|
`if (typeof ${input.val} === 'string' || typeof ${input.val} === 'number') {`
|
|
299
299
|
);
|
|
300
|
-
if ((input.instancePath.length === 0 || input.shouldCoerce) && input.schema.
|
|
300
|
+
if ((input.instancePath.length === 0 || input.shouldCoerce) && input.schema.isNullable) {
|
|
301
301
|
templateParts.push(`if (${input.val} === 'null') {
|
|
302
302
|
${input.targetVal} = null;
|
|
303
303
|
} else {`);
|
|
@@ -316,7 +316,7 @@ function bigIntTemplate$2(input, isUnsigned) {
|
|
|
316
316
|
templateParts.push(`} catch(err) {
|
|
317
317
|
$fallback("${input.instancePath}", "${input.schemaPath}", \`Unable to parse BigInt from \${${input.val}}\`);
|
|
318
318
|
}`);
|
|
319
|
-
if ((input.instancePath.length === 0 || input.shouldCoerce) && input.schema.
|
|
319
|
+
if ((input.instancePath.length === 0 || input.shouldCoerce) && input.schema.isNullable) {
|
|
320
320
|
templateParts.push("}");
|
|
321
321
|
}
|
|
322
322
|
templateParts.push("}");
|
|
@@ -333,7 +333,7 @@ function bigIntTemplate$2(input, isUnsigned) {
|
|
|
333
333
|
${input.targetVal} = ${input.val};
|
|
334
334
|
}`);
|
|
335
335
|
}
|
|
336
|
-
if (input.schema.
|
|
336
|
+
if (input.schema.isNullable) {
|
|
337
337
|
templateParts.push(`else if (${input.val} === null) {
|
|
338
338
|
${input.targetVal} = null;
|
|
339
339
|
}`);
|
|
@@ -351,7 +351,7 @@ function timestampTemplate$2(input) {
|
|
|
351
351
|
const parsedVal = new Date(${input.val});
|
|
352
352
|
if (!Number.isNaN(parsedVal.getMonth())) {
|
|
353
353
|
${input.targetVal} = parsedVal;
|
|
354
|
-
} ${input.schema.
|
|
354
|
+
} ${input.schema.isNullable ? `else if (${input.val} === 'null') {
|
|
355
355
|
${input.targetVal} = null;
|
|
356
356
|
}` : ""} else {
|
|
357
357
|
$fallback("${input.instancePath}", "${input.schemaPath}", "Unable to coerce date");
|
|
@@ -368,7 +368,7 @@ function timestampTemplate$2(input) {
|
|
|
368
368
|
}
|
|
369
369
|
} else if (typeof ${input.val} === 'object' && ${input.val} instanceof Date) {
|
|
370
370
|
${input.targetVal} = ${input.val};
|
|
371
|
-
}${input.schema.
|
|
371
|
+
}${input.schema.isNullable ? ` else if (${input.val} === null) {
|
|
372
372
|
${input.targetVal} = null;
|
|
373
373
|
}` : ""} else {
|
|
374
374
|
$fallback("${input.instancePath}", "${input.schemaPath}", "Unable to parse date");
|
|
@@ -380,7 +380,7 @@ function timestampTemplate$2(input) {
|
|
|
380
380
|
if (!Number.isNaN(parsedVal.getMonth())) {
|
|
381
381
|
${input.targetVal} = parsedVal;
|
|
382
382
|
}`);
|
|
383
|
-
if (input.schema.
|
|
383
|
+
if (input.schema.isNullable) {
|
|
384
384
|
templateParts.push(`if (${input.val} === 'null') {
|
|
385
385
|
${input.targetVal} = null;
|
|
386
386
|
}`);
|
|
@@ -397,7 +397,7 @@ function timestampTemplate$2(input) {
|
|
|
397
397
|
} else {
|
|
398
398
|
$fallback("${input.instancePath}", "${input.schemaPath}", "Expected instanceof Date or ISO Date string")
|
|
399
399
|
}`;
|
|
400
|
-
if (input.schema.
|
|
400
|
+
if (input.schema.isNullable) {
|
|
401
401
|
templateParts.push(`if (${input.val} === null) {
|
|
402
402
|
${input.targetVal} = null
|
|
403
403
|
} else {
|
|
@@ -419,7 +419,7 @@ function enumTemplate$2(input) {
|
|
|
419
419
|
${input.targetVal} = ${input.val};
|
|
420
420
|
}
|
|
421
421
|
`);
|
|
422
|
-
if (input.instancePath.length === 0 && input.schema.
|
|
422
|
+
if (input.instancePath.length === 0 && input.schema.isNullable) {
|
|
423
423
|
templateParts.push(`else if (${input.val} === 'null') {
|
|
424
424
|
${input.targetVal} = null;
|
|
425
425
|
}`);
|
|
@@ -433,7 +433,7 @@ function enumTemplate$2(input) {
|
|
|
433
433
|
}`
|
|
434
434
|
);
|
|
435
435
|
const mainTemplate = templateParts.join("\n");
|
|
436
|
-
if (input.schema.
|
|
436
|
+
if (input.schema.isNullable) {
|
|
437
437
|
return `if (${input.val} === null) {
|
|
438
438
|
${input.targetVal} = null;
|
|
439
439
|
} else {
|
|
@@ -451,7 +451,7 @@ function objectTemplate$2(input) {
|
|
|
451
451
|
`${innerTargetVal}.${input.discriminatorKey} = "${input.discriminatorValue}";`
|
|
452
452
|
);
|
|
453
453
|
}
|
|
454
|
-
if (input.schema.
|
|
454
|
+
if (input.schema.isStrict) {
|
|
455
455
|
const keyVal = `_${depthStr}_keys`;
|
|
456
456
|
const optionalKeyVal = `_${depthStr}_optionalKeys`;
|
|
457
457
|
const keys = Object.keys(input.schema.properties).map((key) => `"${key}"`).join(",");
|
|
@@ -517,7 +517,7 @@ function objectTemplate$2(input) {
|
|
|
517
517
|
}
|
|
518
518
|
mainTemplate = `${input.targetVal} = ${fnName}(${input.val});`;
|
|
519
519
|
}
|
|
520
|
-
if (input.schema.
|
|
520
|
+
if (input.schema.isNullable) {
|
|
521
521
|
return `if (${input.val} === null) {
|
|
522
522
|
${input.targetVal} = null;
|
|
523
523
|
} else {
|
|
@@ -550,7 +550,7 @@ function arrayTemplate$2(input) {
|
|
|
550
550
|
} else {
|
|
551
551
|
$fallback("${input.instancePath}", "${input.schemaPath}", "Expected Array");
|
|
552
552
|
}`;
|
|
553
|
-
if (input.schema.
|
|
553
|
+
if (input.schema.isNullable) {
|
|
554
554
|
return `if (${input.val} === null) {
|
|
555
555
|
${input.targetVal} = null;
|
|
556
556
|
} else {
|
|
@@ -601,7 +601,7 @@ function discriminatorTemplate$2(input) {
|
|
|
601
601
|
}
|
|
602
602
|
mainTemplate = `${input.targetVal} = ${fnName}(${input.val});`;
|
|
603
603
|
}
|
|
604
|
-
if (input.schema.
|
|
604
|
+
if (input.schema.isNullable) {
|
|
605
605
|
return `if (${input.val} === null) {
|
|
606
606
|
${input.targetVal} = null;
|
|
607
607
|
} else {
|
|
@@ -640,7 +640,7 @@ function recordTemplate$2(input) {
|
|
|
640
640
|
} else {
|
|
641
641
|
$fallback("${input.instancePath}", "${input.schemaPath}", "Expected object.");
|
|
642
642
|
}`;
|
|
643
|
-
if (input.schema.
|
|
643
|
+
if (input.schema.isNullable) {
|
|
644
644
|
return `if (${input.val} === null) {
|
|
645
645
|
${input.targetVal} = null;
|
|
646
646
|
} else {
|
|
@@ -657,7 +657,7 @@ function refTemplate$2(input) {
|
|
|
657
657
|
if (!Object.keys(input.subFunctions).includes(fnName)) {
|
|
658
658
|
input.subFunctions[fnName] = "";
|
|
659
659
|
}
|
|
660
|
-
if (input.schema.
|
|
660
|
+
if (input.schema.isNullable) {
|
|
661
661
|
return `if (${input.val} === null) {
|
|
662
662
|
${input.targetVal} = null;
|
|
663
663
|
} else {
|
|
@@ -746,7 +746,7 @@ function scalarTemplate(input) {
|
|
|
746
746
|
}
|
|
747
747
|
function stringTemplate$1(input) {
|
|
748
748
|
if (input.instancePath.length === 0) {
|
|
749
|
-
if (input.schema.
|
|
749
|
+
if (input.schema.isNullable) {
|
|
750
750
|
return `if (typeof ${input.val} === 'string') {
|
|
751
751
|
return ${input.val};
|
|
752
752
|
}
|
|
@@ -786,7 +786,7 @@ if (${input.val}.length < 42) {
|
|
|
786
786
|
} else {
|
|
787
787
|
${input.targetVal} += JSON.stringify(${input.val});
|
|
788
788
|
}`;
|
|
789
|
-
if (input.schema.
|
|
789
|
+
if (input.schema.isNullable) {
|
|
790
790
|
return `if (typeof ${input.val} === 'string') {
|
|
791
791
|
${mainTemplate}
|
|
792
792
|
} else {
|
|
@@ -800,7 +800,7 @@ function booleanTemplate$1(input) {
|
|
|
800
800
|
return `return \`\${${input.val}}\`;`;
|
|
801
801
|
}
|
|
802
802
|
const mainTemplate = `${input.targetVal} += \`${input.outputPrefix}\${${input.val}}\`;`;
|
|
803
|
-
if (input.schema.
|
|
803
|
+
if (input.schema.isNullable) {
|
|
804
804
|
return `if (typeof ${input.val} === 'boolean') {
|
|
805
805
|
${mainTemplate}
|
|
806
806
|
} else {
|
|
@@ -811,7 +811,7 @@ function booleanTemplate$1(input) {
|
|
|
811
811
|
}
|
|
812
812
|
function timestampTemplate$1(input) {
|
|
813
813
|
if (input.instancePath.length === 0) {
|
|
814
|
-
if (input.schema.
|
|
814
|
+
if (input.schema.isNullable) {
|
|
815
815
|
return `if (typeof ${input.val} === 'object' && ${input.val} instanceof Date) {
|
|
816
816
|
return ${input.val}.toISOString();
|
|
817
817
|
}
|
|
@@ -820,7 +820,7 @@ function timestampTemplate$1(input) {
|
|
|
820
820
|
return `return ${input.val}.toISOString();`;
|
|
821
821
|
}
|
|
822
822
|
const mainTemplate = `${input.targetVal} += \`${input.outputPrefix}"\${${input.val}.toISOString()}"\`;`;
|
|
823
|
-
if (input.schema.
|
|
823
|
+
if (input.schema.isNullable) {
|
|
824
824
|
return `if (typeof ${input.val} === 'object' && ${input.val} instanceof Date) {
|
|
825
825
|
${mainTemplate}
|
|
826
826
|
} else {
|
|
@@ -831,7 +831,7 @@ function timestampTemplate$1(input) {
|
|
|
831
831
|
}
|
|
832
832
|
function numberTemplate(input) {
|
|
833
833
|
if (input.instancePath.length === 0) {
|
|
834
|
-
if (input.schema.
|
|
834
|
+
if (input.schema.isNullable) {
|
|
835
835
|
return `if (typeof ${input.val} === 'number' && !Number.isNaN(${input.val})) {
|
|
836
836
|
return \`\${${input.val}}\`;
|
|
837
837
|
}
|
|
@@ -844,7 +844,7 @@ function numberTemplate(input) {
|
|
|
844
844
|
throw new Error("Expected number at ${input.instancePath} got NaN");
|
|
845
845
|
}
|
|
846
846
|
${input.targetVal} += \`${input.outputPrefix}\${${input.val}}\`;`;
|
|
847
|
-
if (input.schema.
|
|
847
|
+
if (input.schema.isNullable) {
|
|
848
848
|
return `if (typeof ${input.val} === 'number' && !Number.isNaN(${input.val})) {
|
|
849
849
|
${mainTemplate}
|
|
850
850
|
} else {
|
|
@@ -855,7 +855,7 @@ function numberTemplate(input) {
|
|
|
855
855
|
}
|
|
856
856
|
function bigIntTemplate$1(input) {
|
|
857
857
|
if (input.instancePath.length === 0) {
|
|
858
|
-
if (input.schema.
|
|
858
|
+
if (input.schema.isNullable) {
|
|
859
859
|
return `if (typeof ${input.val} === 'bigint') {
|
|
860
860
|
return ${input.val}.toString();
|
|
861
861
|
}
|
|
@@ -864,7 +864,7 @@ function bigIntTemplate$1(input) {
|
|
|
864
864
|
return `return ${input.val}.toString();`;
|
|
865
865
|
}
|
|
866
866
|
const mainTemplate = `${input.targetVal} += \`${input.outputPrefix}"\${${input.val}.toString()}"\`;`;
|
|
867
|
-
if (input.schema.
|
|
867
|
+
if (input.schema.isNullable) {
|
|
868
868
|
return `if (typeof ${input.val} === 'bigint') {
|
|
869
869
|
${mainTemplate}
|
|
870
870
|
} else {
|
|
@@ -875,7 +875,7 @@ function bigIntTemplate$1(input) {
|
|
|
875
875
|
}
|
|
876
876
|
function enumTemplate$1(input) {
|
|
877
877
|
if (input.instancePath.length === 0) {
|
|
878
|
-
if (input.schema.
|
|
878
|
+
if (input.schema.isNullable) {
|
|
879
879
|
return `if (typeof ${input.val} === 'string') {
|
|
880
880
|
return ${input.val};
|
|
881
881
|
}
|
|
@@ -884,7 +884,7 @@ function enumTemplate$1(input) {
|
|
|
884
884
|
return `return ${input.val};`;
|
|
885
885
|
}
|
|
886
886
|
const mainTemplate = `${input.targetVal} += \`${input.outputPrefix}"\${${input.val}}"\``;
|
|
887
|
-
if (input.schema.
|
|
887
|
+
if (input.schema.isNullable) {
|
|
888
888
|
return `if (typeof ${input.val} === 'string') {
|
|
889
889
|
${mainTemplate}
|
|
890
890
|
} else {
|
|
@@ -991,7 +991,7 @@ function objectTemplate$1(input) {
|
|
|
991
991
|
}
|
|
992
992
|
mainTemplate = `${fnName}(${input.val});`;
|
|
993
993
|
}
|
|
994
|
-
if (input.schema.
|
|
994
|
+
if (input.schema.isNullable) {
|
|
995
995
|
return `if (typeof ${input.val} === 'object' && ${input.val} !== null) {
|
|
996
996
|
${input.targetVal} += '${input.outputPrefix}';
|
|
997
997
|
${mainTemplate.split("___val___").join(input.val)}
|
|
@@ -1032,7 +1032,7 @@ function arrayTemplate$1(input) {
|
|
|
1032
1032
|
}`);
|
|
1033
1033
|
templateParts.push(`${input.targetVal} += ']';`);
|
|
1034
1034
|
const mainTemplate = templateParts.join("\n");
|
|
1035
|
-
if (input.schema.
|
|
1035
|
+
if (input.schema.isNullable) {
|
|
1036
1036
|
return `if (Array.isArray(${input.val})) {
|
|
1037
1037
|
${mainTemplate}
|
|
1038
1038
|
} else {
|
|
@@ -1097,7 +1097,7 @@ function recordTemplate$1(input) {
|
|
|
1097
1097
|
}`);
|
|
1098
1098
|
templateParts.push(`${input.targetVal} += '}';`);
|
|
1099
1099
|
const mainTemplate = templateParts.join("\n");
|
|
1100
|
-
if (input.schema.
|
|
1100
|
+
if (input.schema.isNullable) {
|
|
1101
1101
|
return `if (typeof ${input.val} === 'object' && ${input.val} !== null) {
|
|
1102
1102
|
${mainTemplate}
|
|
1103
1103
|
} else {
|
|
@@ -1140,7 +1140,7 @@ function discriminatorTemplate$1(input) {
|
|
|
1140
1140
|
}
|
|
1141
1141
|
mainTemplate = `${fnName}(${input.val});`;
|
|
1142
1142
|
}
|
|
1143
|
-
if (input.schema.
|
|
1143
|
+
if (input.schema.isNullable) {
|
|
1144
1144
|
return `if (typeof ${input.val} === 'object' && ${input.val} !== null) {
|
|
1145
1145
|
${mainTemplate.split(inputPlaceholder).join(input.val)}
|
|
1146
1146
|
} else {
|
|
@@ -1154,7 +1154,7 @@ function anyTemplate(input) {
|
|
|
1154
1154
|
const mainTemplate = `if (typeof ${input.val} !== 'undefined') {
|
|
1155
1155
|
${input.targetVal} += '${input.outputPrefix}' + JSON.stringify(${input.val});
|
|
1156
1156
|
}`;
|
|
1157
|
-
if (input.schema.
|
|
1157
|
+
if (input.schema.isNullable) {
|
|
1158
1158
|
return `if (${input.val} === null) {
|
|
1159
1159
|
${input.targetVal} += '${input.outputPrefix}null';
|
|
1160
1160
|
} else {
|
|
@@ -1175,7 +1175,7 @@ function refTemplate$1(input) {
|
|
|
1175
1175
|
if (!Object.keys(input.subFunctions).includes(fnName)) {
|
|
1176
1176
|
input.subFunctions[fnName] = "";
|
|
1177
1177
|
}
|
|
1178
|
-
if (input.schema.
|
|
1178
|
+
if (input.schema.isNullable) {
|
|
1179
1179
|
return `if (${input.val} === null) {
|
|
1180
1180
|
${input.targetVal} += '${input.outputPrefix}null';
|
|
1181
1181
|
} else {
|
|
@@ -1252,38 +1252,38 @@ function schemaTemplate(input) {
|
|
|
1252
1252
|
return "true";
|
|
1253
1253
|
}
|
|
1254
1254
|
function booleanTemplate(input) {
|
|
1255
|
-
if (input.schema.
|
|
1255
|
+
if (input.schema.isNullable) {
|
|
1256
1256
|
return `(${input.val} === null || typeof ${input.val} === 'boolean')`;
|
|
1257
1257
|
}
|
|
1258
1258
|
return `typeof ${input.val} === 'boolean'`;
|
|
1259
1259
|
}
|
|
1260
1260
|
function floatTemplate(input) {
|
|
1261
|
-
if (input.schema.
|
|
1261
|
+
if (input.schema.isNullable) {
|
|
1262
1262
|
return `((typeof ${input.val} === 'number' && !Number.isNaN(${input.val})) || ${input.val} === null)`;
|
|
1263
1263
|
}
|
|
1264
1264
|
return `(typeof ${input.val} === 'number' && !Number.isNaN(${input.val}))`;
|
|
1265
1265
|
}
|
|
1266
1266
|
function intTemplate(input, min, max) {
|
|
1267
|
-
if (input.schema.
|
|
1267
|
+
if (input.schema.isNullable) {
|
|
1268
1268
|
return `((typeof ${input.val} === 'number' && Number.isInteger(${input.val}) && ${input.val} >= ${min} && ${input.val} <= ${max}) || ${input.val} === null)`;
|
|
1269
1269
|
}
|
|
1270
1270
|
return `(typeof ${input.val} === 'number' && Number.isInteger(${input.val}) && ${input.val} >= ${min} && ${input.val} <= ${max})`;
|
|
1271
1271
|
}
|
|
1272
1272
|
function bigIntTemplate(input, isUnsigned = false) {
|
|
1273
1273
|
const mainTemplate = isUnsigned ? `typeof ${input.val} === 'bigint' && ${input.val} >= BigInt("0")` : `typeof ${input.val} === 'bigint' && ${input.val} < BigInt("9223372036854775808") && ${input.val} > BigInt("-9223372036854775809")`;
|
|
1274
|
-
if (input.schema.
|
|
1274
|
+
if (input.schema.isNullable) {
|
|
1275
1275
|
return `(${mainTemplate}) || ${input.val} === null`;
|
|
1276
1276
|
}
|
|
1277
1277
|
return mainTemplate;
|
|
1278
1278
|
}
|
|
1279
1279
|
function stringTemplate(input) {
|
|
1280
|
-
if (input.schema.
|
|
1280
|
+
if (input.schema.isNullable) {
|
|
1281
1281
|
return `(typeof ${input.val} === 'string' || ${input.val} === null)`;
|
|
1282
1282
|
}
|
|
1283
1283
|
return `typeof ${input.val} === 'string'`;
|
|
1284
1284
|
}
|
|
1285
1285
|
function timestampTemplate(input) {
|
|
1286
|
-
if (input.schema.
|
|
1286
|
+
if (input.schema.isNullable) {
|
|
1287
1287
|
return `((typeof ${input.val} === 'object' && ${input.val} instanceof Date) || ${input.val} === null)`;
|
|
1288
1288
|
}
|
|
1289
1289
|
return `typeof ${input.val} === 'object' && ${input.val} instanceof Date`;
|
|
@@ -1297,7 +1297,7 @@ function objectTemplate(input) {
|
|
|
1297
1297
|
} else {
|
|
1298
1298
|
parts.push(`typeof ${input.val} === 'object' && ${input.val} !== null`);
|
|
1299
1299
|
}
|
|
1300
|
-
if (input.schema.
|
|
1300
|
+
if (input.schema.isStrict) {
|
|
1301
1301
|
const allowedKeys = Object.keys(input.schema.properties);
|
|
1302
1302
|
for (const key of Object.keys(input.schema.optionalProperties ?? {})) {
|
|
1303
1303
|
allowedKeys.push(key);
|
|
@@ -1341,14 +1341,14 @@ function objectTemplate(input) {
|
|
|
1341
1341
|
}
|
|
1342
1342
|
mainTemplate = `${fnName}(${input.val})`;
|
|
1343
1343
|
}
|
|
1344
|
-
if (input.schema.
|
|
1344
|
+
if (input.schema.isNullable) {
|
|
1345
1345
|
return `((${mainTemplate}) || ${input.val} === null)`;
|
|
1346
1346
|
}
|
|
1347
1347
|
return mainTemplate;
|
|
1348
1348
|
}
|
|
1349
1349
|
function enumTemplate(input) {
|
|
1350
1350
|
const enumPart = input.schema.enum.map((val) => `${input.val} === "${val}"`).join(" || ");
|
|
1351
|
-
if (input.schema.
|
|
1351
|
+
if (input.schema.isNullable) {
|
|
1352
1352
|
return `((typeof ${input.val} === 'string' && (${enumPart})) || ${input.val} === null)`;
|
|
1353
1353
|
}
|
|
1354
1354
|
return `(typeof ${input.val} === 'string' && (${enumPart}))`;
|
|
@@ -1360,7 +1360,7 @@ function arrayTemplate(input) {
|
|
|
1360
1360
|
schemaPath: `${input.schemaPath}/elements`,
|
|
1361
1361
|
schema: input.schema.elements,
|
|
1362
1362
|
subFunctions: input.subFunctions});
|
|
1363
|
-
if (input.schema.
|
|
1363
|
+
if (input.schema.isNullable) {
|
|
1364
1364
|
return `((Array.isArray(${input.val}) && ${input.val}.every((item) => ${innerTemplate})) || ${input.val} === null)`;
|
|
1365
1365
|
}
|
|
1366
1366
|
return `(Array.isArray(${input.val}) && ${input.val}.every((item) => ${innerTemplate}))`;
|
|
@@ -1373,7 +1373,7 @@ function recordTemplate(input) {
|
|
|
1373
1373
|
val: `${input.val}[key]`,
|
|
1374
1374
|
subFunctions: input.subFunctions});
|
|
1375
1375
|
const mainTemplate = `typeof ${input.val} === 'object' && ${input.val} !== null && Object.keys(${input.val}).every((key) => ${subTemplate})`;
|
|
1376
|
-
if (input.schema.
|
|
1376
|
+
if (input.schema.isNullable) {
|
|
1377
1377
|
return `((${mainTemplate}) || ${input.val} === null)`;
|
|
1378
1378
|
}
|
|
1379
1379
|
return mainTemplate;
|
|
@@ -1406,7 +1406,7 @@ function discriminatorTemplate(input) {
|
|
|
1406
1406
|
}
|
|
1407
1407
|
mainTemplate = `${fnName}(${input.val})`;
|
|
1408
1408
|
}
|
|
1409
|
-
if (input.schema.
|
|
1409
|
+
if (input.schema.isNullable) {
|
|
1410
1410
|
return `((${mainTemplate}) || ${input.val} === null)`;
|
|
1411
1411
|
}
|
|
1412
1412
|
return mainTemplate;
|
|
@@ -1419,7 +1419,7 @@ function refTemplate(input) {
|
|
|
1419
1419
|
if (!Object.keys(input.subFunctions).includes(fnName)) {
|
|
1420
1420
|
input.subFunctions[fnName] = "";
|
|
1421
1421
|
}
|
|
1422
|
-
if (input.schema.
|
|
1422
|
+
if (input.schema.isNullable) {
|
|
1423
1423
|
return `(${input.val} === null || ${fnName}(${input.val}))`;
|
|
1424
1424
|
}
|
|
1425
1425
|
return `${fnName}(${input.val})`;
|
|
@@ -1600,7 +1600,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1600
1600
|
switch (schema.type) {
|
|
1601
1601
|
case "float32":
|
|
1602
1602
|
case "float64":
|
|
1603
|
-
if (schema.
|
|
1603
|
+
if (schema.isNullable) {
|
|
1604
1604
|
return {
|
|
1605
1605
|
fn: nullableFloatDecoder,
|
|
1606
1606
|
code
|
|
@@ -1616,7 +1616,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1616
1616
|
return bigIntDecoder(
|
|
1617
1617
|
input2,
|
|
1618
1618
|
false,
|
|
1619
|
-
schema.
|
|
1619
|
+
schema.isNullable ?? false,
|
|
1620
1620
|
context
|
|
1621
1621
|
);
|
|
1622
1622
|
},
|
|
@@ -1628,14 +1628,14 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1628
1628
|
return bigIntDecoder(
|
|
1629
1629
|
input2,
|
|
1630
1630
|
true,
|
|
1631
|
-
schema.
|
|
1631
|
+
schema.isNullable ?? false,
|
|
1632
1632
|
context
|
|
1633
1633
|
);
|
|
1634
1634
|
},
|
|
1635
1635
|
code
|
|
1636
1636
|
};
|
|
1637
1637
|
case "int32":
|
|
1638
|
-
if (schema.
|
|
1638
|
+
if (schema.isNullable) {
|
|
1639
1639
|
return {
|
|
1640
1640
|
fn(input2, context) {
|
|
1641
1641
|
return nullableIntDecoder(
|
|
@@ -1655,7 +1655,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1655
1655
|
code
|
|
1656
1656
|
};
|
|
1657
1657
|
case "int16":
|
|
1658
|
-
if (schema.
|
|
1658
|
+
if (schema.isNullable) {
|
|
1659
1659
|
return {
|
|
1660
1660
|
fn(input2, context) {
|
|
1661
1661
|
return nullableIntDecoder(
|
|
@@ -1675,7 +1675,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1675
1675
|
code
|
|
1676
1676
|
};
|
|
1677
1677
|
case "int8":
|
|
1678
|
-
if (schema.
|
|
1678
|
+
if (schema.isNullable) {
|
|
1679
1679
|
return {
|
|
1680
1680
|
fn(input2, context) {
|
|
1681
1681
|
return nullableIntDecoder(
|
|
@@ -1695,7 +1695,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1695
1695
|
code
|
|
1696
1696
|
};
|
|
1697
1697
|
case "uint32":
|
|
1698
|
-
if (schema.
|
|
1698
|
+
if (schema.isNullable) {
|
|
1699
1699
|
return {
|
|
1700
1700
|
fn(input2, context) {
|
|
1701
1701
|
return nullableIntDecoder(
|
|
@@ -1715,7 +1715,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1715
1715
|
code
|
|
1716
1716
|
};
|
|
1717
1717
|
case "uint16":
|
|
1718
|
-
if (schema.
|
|
1718
|
+
if (schema.isNullable) {
|
|
1719
1719
|
return {
|
|
1720
1720
|
fn(input2, context) {
|
|
1721
1721
|
return nullableIntDecoder(
|
|
@@ -1735,7 +1735,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1735
1735
|
code
|
|
1736
1736
|
};
|
|
1737
1737
|
case "uint8":
|
|
1738
|
-
if (schema.
|
|
1738
|
+
if (schema.isNullable) {
|
|
1739
1739
|
return {
|
|
1740
1740
|
fn(input2, context) {
|
|
1741
1741
|
return nullableIntDecoder(
|
|
@@ -1756,7 +1756,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1756
1756
|
};
|
|
1757
1757
|
case "boolean":
|
|
1758
1758
|
if (shouldCoerce) {
|
|
1759
|
-
if (schema.
|
|
1759
|
+
if (schema.isNullable) {
|
|
1760
1760
|
return {
|
|
1761
1761
|
code,
|
|
1762
1762
|
fn(input2, context) {
|
|
@@ -1818,7 +1818,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1818
1818
|
}
|
|
1819
1819
|
};
|
|
1820
1820
|
}
|
|
1821
|
-
if (schema.
|
|
1821
|
+
if (schema.isNullable) {
|
|
1822
1822
|
return {
|
|
1823
1823
|
code,
|
|
1824
1824
|
fn(input2, context) {
|
|
@@ -1871,7 +1871,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1871
1871
|
code
|
|
1872
1872
|
};
|
|
1873
1873
|
case "string":
|
|
1874
|
-
if (schema.
|
|
1874
|
+
if (schema.isNullable) {
|
|
1875
1875
|
return {
|
|
1876
1876
|
fn(input2, context) {
|
|
1877
1877
|
if (typeof input2 === "string") {
|
|
@@ -1909,7 +1909,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1909
1909
|
};
|
|
1910
1910
|
case "timestamp":
|
|
1911
1911
|
if (shouldCoerce) {
|
|
1912
|
-
if (schema.
|
|
1912
|
+
if (schema.isNullable) {
|
|
1913
1913
|
return {
|
|
1914
1914
|
fn(input2, context) {
|
|
1915
1915
|
if (typeof input2 === "string") {
|
|
@@ -1970,7 +1970,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
1970
1970
|
code
|
|
1971
1971
|
};
|
|
1972
1972
|
}
|
|
1973
|
-
if (schema.
|
|
1973
|
+
if (schema.isNullable) {
|
|
1974
1974
|
return {
|
|
1975
1975
|
fn(input2, context) {
|
|
1976
1976
|
if (typeof input2 === "string") {
|
|
@@ -2021,7 +2021,7 @@ function getCompiledParser(input, schema, shouldCoerce) {
|
|
|
2021
2021
|
}
|
|
2022
2022
|
}
|
|
2023
2023
|
if (typeDefs.isSchemaFormEnum(schema)) {
|
|
2024
|
-
if (schema.
|
|
2024
|
+
if (schema.isNullable) {
|
|
2025
2025
|
return {
|
|
2026
2026
|
fn(input2, context) {
|
|
2027
2027
|
if (typeof input2 === "string") {
|
|
@@ -2237,7 +2237,7 @@ function getCompiledSerializer(schema) {
|
|
|
2237
2237
|
if (typeDefs.isSchemaFormType(schema)) {
|
|
2238
2238
|
switch (schema.type) {
|
|
2239
2239
|
case "string":
|
|
2240
|
-
if (schema.
|
|
2240
|
+
if (schema.isNullable) {
|
|
2241
2241
|
return {
|
|
2242
2242
|
fn(input) {
|
|
2243
2243
|
if (typeof input === "string") {
|
|
@@ -2255,7 +2255,7 @@ function getCompiledSerializer(schema) {
|
|
|
2255
2255
|
code
|
|
2256
2256
|
};
|
|
2257
2257
|
case "timestamp":
|
|
2258
|
-
if (schema.
|
|
2258
|
+
if (schema.isNullable) {
|
|
2259
2259
|
return {
|
|
2260
2260
|
fn(input) {
|
|
2261
2261
|
if (typeof input === "object" && input !== null) {
|
|
@@ -2273,7 +2273,7 @@ function getCompiledSerializer(schema) {
|
|
|
2273
2273
|
code
|
|
2274
2274
|
};
|
|
2275
2275
|
case "boolean":
|
|
2276
|
-
if (schema.
|
|
2276
|
+
if (schema.isNullable) {
|
|
2277
2277
|
return {
|
|
2278
2278
|
fn(input) {
|
|
2279
2279
|
if (typeof input === "boolean") {
|
|
@@ -2298,7 +2298,7 @@ function getCompiledSerializer(schema) {
|
|
|
2298
2298
|
case "uint8":
|
|
2299
2299
|
case "uint16":
|
|
2300
2300
|
case "uint32":
|
|
2301
|
-
if (schema.
|
|
2301
|
+
if (schema.isNullable) {
|
|
2302
2302
|
return {
|
|
2303
2303
|
fn(input) {
|
|
2304
2304
|
if (typeof input === "number") {
|
|
@@ -2317,7 +2317,7 @@ function getCompiledSerializer(schema) {
|
|
|
2317
2317
|
};
|
|
2318
2318
|
case "int64":
|
|
2319
2319
|
case "uint64":
|
|
2320
|
-
if (schema.
|
|
2320
|
+
if (schema.isNullable) {
|
|
2321
2321
|
return {
|
|
2322
2322
|
fn(input) {
|
|
2323
2323
|
if (typeof input === "bigint") {
|
|
@@ -2337,7 +2337,7 @@ function getCompiledSerializer(schema) {
|
|
|
2337
2337
|
}
|
|
2338
2338
|
}
|
|
2339
2339
|
if (typeDefs.isSchemaFormEnum(schema)) {
|
|
2340
|
-
if (schema.
|
|
2340
|
+
if (schema.isNullable) {
|
|
2341
2341
|
return {
|
|
2342
2342
|
fn(input) {
|
|
2343
2343
|
if (typeof input === "string" && schema.enum.includes(input)) {
|
|
@@ -2376,6 +2376,7 @@ function any(options = {}) {
|
|
|
2376
2376
|
};
|
|
2377
2377
|
const validator = {
|
|
2378
2378
|
output: void 0,
|
|
2379
|
+
optional: false,
|
|
2379
2380
|
parse,
|
|
2380
2381
|
coerce: (input, context) => {
|
|
2381
2382
|
if (context.instancePath.length === 0 && typeof input === "string") {
|
|
@@ -2414,6 +2415,7 @@ function array(schema, opts = {}) {
|
|
|
2414
2415
|
};
|
|
2415
2416
|
const validator = {
|
|
2416
2417
|
output: [],
|
|
2418
|
+
optional: false,
|
|
2417
2419
|
parse: parseType,
|
|
2418
2420
|
coerce(input, context) {
|
|
2419
2421
|
return parse$5(schema, input, context, true);
|
|
@@ -2520,6 +2522,7 @@ function parse$5(innerSchema, input, context, coerce = false) {
|
|
|
2520
2522
|
function boolean(opts = {}) {
|
|
2521
2523
|
const validator = {
|
|
2522
2524
|
output: false,
|
|
2525
|
+
optional: false,
|
|
2523
2526
|
parse: parse$4,
|
|
2524
2527
|
validate: validate$4,
|
|
2525
2528
|
serialize: serialize$2,
|
|
@@ -2608,6 +2611,7 @@ function discriminator(propA, propB, propC) {
|
|
|
2608
2611
|
};
|
|
2609
2612
|
const validator = {
|
|
2610
2613
|
output: {},
|
|
2614
|
+
optional: false,
|
|
2611
2615
|
validate: isType,
|
|
2612
2616
|
parse: parseType,
|
|
2613
2617
|
coerce: (input, context) => {
|
|
@@ -2777,6 +2781,7 @@ function enumerator(paramA, paramB) {
|
|
|
2777
2781
|
};
|
|
2778
2782
|
const validator = {
|
|
2779
2783
|
output: paramA[0] ?? "",
|
|
2784
|
+
optional: false,
|
|
2780
2785
|
parse,
|
|
2781
2786
|
coerce: (input, context) => {
|
|
2782
2787
|
if (isType(input)) {
|
|
@@ -2852,7 +2857,7 @@ function nullable(schema, opts = {}) {
|
|
|
2852
2857
|
};
|
|
2853
2858
|
const result = {
|
|
2854
2859
|
...schema,
|
|
2855
|
-
|
|
2860
|
+
isNullable: true,
|
|
2856
2861
|
metadata: {
|
|
2857
2862
|
id: opts.id ?? schema.metadata?.id,
|
|
2858
2863
|
description: opts.description ?? schema.metadata?.description,
|
|
@@ -2917,6 +2922,9 @@ function optional(input, opts = {}) {
|
|
|
2917
2922
|
adapters.hideInvalidProperties(result);
|
|
2918
2923
|
return result;
|
|
2919
2924
|
}
|
|
2925
|
+
function undefinable(input, opts = {}) {
|
|
2926
|
+
return optional(input, opts);
|
|
2927
|
+
}
|
|
2920
2928
|
function clone(input, opts = {}) {
|
|
2921
2929
|
const validator = {
|
|
2922
2930
|
...input[adapters.VALIDATOR_KEY]
|
|
@@ -3090,6 +3098,7 @@ function int64(opts = {}) {
|
|
|
3090
3098
|
}
|
|
3091
3099
|
const validator = {
|
|
3092
3100
|
output: BigInt("0"),
|
|
3101
|
+
optional: false,
|
|
3093
3102
|
validate: isType,
|
|
3094
3103
|
parse,
|
|
3095
3104
|
coerce: parse,
|
|
@@ -3151,6 +3160,7 @@ function uint64(opts = {}) {
|
|
|
3151
3160
|
}
|
|
3152
3161
|
const validator = {
|
|
3153
3162
|
output: BigInt("0"),
|
|
3163
|
+
optional: false,
|
|
3154
3164
|
validate: isType,
|
|
3155
3165
|
parse,
|
|
3156
3166
|
coerce: parse,
|
|
@@ -3240,6 +3250,7 @@ function numberScalarType(type, opts, numTypeMatcher) {
|
|
|
3240
3250
|
};
|
|
3241
3251
|
const validator = {
|
|
3242
3252
|
output: 0,
|
|
3253
|
+
optional: false,
|
|
3243
3254
|
validate,
|
|
3244
3255
|
parse,
|
|
3245
3256
|
serialize: serializeNumber,
|
|
@@ -3286,8 +3297,10 @@ function object(propA, propB) {
|
|
|
3286
3297
|
const schema = {
|
|
3287
3298
|
properties: {}
|
|
3288
3299
|
};
|
|
3289
|
-
if (typeof options.
|
|
3290
|
-
schema.
|
|
3300
|
+
if (typeof options.isStrict === "boolean") {
|
|
3301
|
+
schema.isStrict = options.isStrict;
|
|
3302
|
+
} else if (typeof options.strict === "boolean") {
|
|
3303
|
+
schema.isStrict = options.strict;
|
|
3291
3304
|
}
|
|
3292
3305
|
for (const key of Object.keys(input)) {
|
|
3293
3306
|
const prop = input[key];
|
|
@@ -3313,6 +3326,7 @@ function object(propA, propB) {
|
|
|
3313
3326
|
};
|
|
3314
3327
|
const validator = {
|
|
3315
3328
|
output: {},
|
|
3329
|
+
optional: false,
|
|
3316
3330
|
parse: decode,
|
|
3317
3331
|
coerce(input2, context) {
|
|
3318
3332
|
return decodeObjectSchema(
|
|
@@ -3372,7 +3386,7 @@ function decodeObjectSchema(schema, input, context, coerce = false) {
|
|
|
3372
3386
|
const inputKeys = Object.keys(parsedInput);
|
|
3373
3387
|
const requiredKeys = Object.keys(schema.properties);
|
|
3374
3388
|
const optionalKeys = Object.keys(optionalProps);
|
|
3375
|
-
if (schema.
|
|
3389
|
+
if (schema.isStrict) {
|
|
3376
3390
|
for (const key of inputKeys) {
|
|
3377
3391
|
if (!requiredKeys.includes(key) && !optionalKeys.includes(key) && key !== context.discriminatorKey) {
|
|
3378
3392
|
context.errors.push({
|
|
@@ -3461,7 +3475,7 @@ function validateObjectSchema(schema, input) {
|
|
|
3461
3475
|
if (!adapters.isObject(input)) {
|
|
3462
3476
|
return false;
|
|
3463
3477
|
}
|
|
3464
|
-
const allowedKeys = schema.
|
|
3478
|
+
const allowedKeys = schema.isStrict ? [] : void 0;
|
|
3465
3479
|
for (const key of Object.keys(schema.properties)) {
|
|
3466
3480
|
const propSchema = schema.properties[key];
|
|
3467
3481
|
const isValid = propSchema[adapters.VALIDATOR_KEY].validate(input[key]);
|
|
@@ -3486,10 +3500,10 @@ function validateObjectSchema(schema, input) {
|
|
|
3486
3500
|
function pick(inputSchema, keys, options = {}) {
|
|
3487
3501
|
const schema = {
|
|
3488
3502
|
properties: {},
|
|
3489
|
-
|
|
3503
|
+
isNullable: inputSchema.isNullable
|
|
3490
3504
|
};
|
|
3491
|
-
if (typeof options.
|
|
3492
|
-
schema.
|
|
3505
|
+
if (typeof options.isStrict === "boolean") {
|
|
3506
|
+
schema.isStrict = options.isStrict;
|
|
3493
3507
|
}
|
|
3494
3508
|
Object.keys(inputSchema.properties).forEach((key) => {
|
|
3495
3509
|
if (!schema.properties) {
|
|
@@ -3544,10 +3558,10 @@ function omit(inputSchema, keys, options = {}) {
|
|
|
3544
3558
|
properties: {
|
|
3545
3559
|
...inputSchema.properties
|
|
3546
3560
|
},
|
|
3547
|
-
|
|
3561
|
+
isNullable: inputSchema.isNullable
|
|
3548
3562
|
};
|
|
3549
|
-
if (typeof options.
|
|
3550
|
-
schema.
|
|
3563
|
+
if (typeof options.isStrict === "boolean") {
|
|
3564
|
+
schema.isStrict = options.isStrict;
|
|
3551
3565
|
}
|
|
3552
3566
|
Object.keys(inputSchema.properties).forEach((key) => {
|
|
3553
3567
|
if (keys.includes(key)) {
|
|
@@ -3650,12 +3664,13 @@ function extend(baseSchema, inputSchema, options = {}) {
|
|
|
3650
3664
|
description: options.description
|
|
3651
3665
|
}
|
|
3652
3666
|
};
|
|
3653
|
-
if (typeof options.
|
|
3654
|
-
schema.
|
|
3667
|
+
if (typeof options.isStrict === "boolean") {
|
|
3668
|
+
schema.isNullable = options.isStrict;
|
|
3655
3669
|
}
|
|
3656
3670
|
const isType = (input) => validateObjectSchema(schema, input);
|
|
3657
3671
|
const validator = {
|
|
3658
3672
|
output: {},
|
|
3673
|
+
optional: false,
|
|
3659
3674
|
parse(input, context) {
|
|
3660
3675
|
return decodeObjectSchema(schema, input, context, false);
|
|
3661
3676
|
},
|
|
@@ -3682,14 +3697,14 @@ function partial(schema, options = {}) {
|
|
|
3682
3697
|
const newSchema = {
|
|
3683
3698
|
properties: {},
|
|
3684
3699
|
optionalProperties: {},
|
|
3685
|
-
|
|
3700
|
+
isNullable: schema.isNullable,
|
|
3686
3701
|
metadata: {
|
|
3687
3702
|
id: options.id,
|
|
3688
3703
|
description: options.description
|
|
3689
3704
|
}
|
|
3690
3705
|
};
|
|
3691
|
-
if (typeof options.
|
|
3692
|
-
schema.
|
|
3706
|
+
if (typeof options.isStrict === "boolean") {
|
|
3707
|
+
schema.isStrict = options.isStrict;
|
|
3693
3708
|
}
|
|
3694
3709
|
for (const key of Object.keys(schema.properties)) {
|
|
3695
3710
|
const prop = schema.properties[key];
|
|
@@ -3738,6 +3753,7 @@ function partial(schema, options = {}) {
|
|
|
3738
3753
|
function string(opts = {}) {
|
|
3739
3754
|
const validator = {
|
|
3740
3755
|
output: "",
|
|
3756
|
+
optional: false,
|
|
3741
3757
|
parse: decode,
|
|
3742
3758
|
coerce: coerce$2,
|
|
3743
3759
|
validate: validate$2,
|
|
@@ -3841,6 +3857,7 @@ function record(schema, opts = {}) {
|
|
|
3841
3857
|
};
|
|
3842
3858
|
const validator = {
|
|
3843
3859
|
output: {},
|
|
3860
|
+
optional: false,
|
|
3844
3861
|
validate: validateFn,
|
|
3845
3862
|
parse: parseFn,
|
|
3846
3863
|
coerce(input, data) {
|
|
@@ -3964,6 +3981,7 @@ function recursive(propA, propB) {
|
|
|
3964
3981
|
const recursiveFns = {};
|
|
3965
3982
|
const validator = {
|
|
3966
3983
|
output: "",
|
|
3984
|
+
optional: false,
|
|
3967
3985
|
parse(input, context) {
|
|
3968
3986
|
if (context.depth >= context.maxDepth) {
|
|
3969
3987
|
context.errors.push({
|
|
@@ -4040,6 +4058,7 @@ function recursive(propA, propB) {
|
|
|
4040
4058
|
function timestamp(opts = {}) {
|
|
4041
4059
|
const validator = {
|
|
4042
4060
|
output: /* @__PURE__ */ new Date(),
|
|
4061
|
+
optional: false,
|
|
4043
4062
|
validate: validate$1,
|
|
4044
4063
|
parse: parse$1,
|
|
4045
4064
|
coerce: coerce$1,
|
|
@@ -4269,6 +4288,7 @@ const _namespace = {
|
|
|
4269
4288
|
uint32: uint32,
|
|
4270
4289
|
uint64: uint64,
|
|
4271
4290
|
uint8: uint8,
|
|
4291
|
+
undefinable: undefinable,
|
|
4272
4292
|
validate: validate
|
|
4273
4293
|
};
|
|
4274
4294
|
|
|
@@ -4353,5 +4373,6 @@ exports.uint64Min = uint64Min;
|
|
|
4353
4373
|
exports.uint8 = uint8;
|
|
4354
4374
|
exports.uint8Max = uint8Max;
|
|
4355
4375
|
exports.uint8Min = uint8Min;
|
|
4376
|
+
exports.undefinable = undefinable;
|
|
4356
4377
|
exports.validate = validate;
|
|
4357
4378
|
exports.validateObjectSchema = validateObjectSchema;
|