zod 4.1.0-canary.20250723T221600 → 4.1.0-canary.20250724T211341
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/package.json +1 -1
- package/src/v3/types.ts +3 -1
- package/src/v4/classic/errors.ts +9 -2
- package/src/v4/classic/schemas.ts +10 -7
- package/src/v4/classic/tests/error-utils.test.ts +43 -0
- package/src/v4/classic/tests/file.test.ts +0 -1
- package/src/v4/classic/tests/literal.test.ts +25 -0
- package/src/v4/classic/tests/partial.test.ts +193 -0
- package/src/v4/classic/tests/pickomit.test.ts +5 -5
- package/src/v4/classic/tests/preprocess.test.ts +4 -15
- package/src/v4/classic/tests/record.test.ts +15 -1
- package/src/v4/classic/tests/recursive-types.test.ts +67 -0
- package/src/v4/classic/tests/string.test.ts +77 -0
- package/src/v4/classic/tests/template-literal.test.ts +3 -0
- package/src/v4/classic/tests/to-json-schema.test.ts +1 -0
- package/src/v4/classic/tests/transform.test.ts +104 -0
- package/src/v4/classic/tests/union.test.ts +90 -3
- package/src/v4/core/checks.ts +2 -2
- package/src/v4/core/errors.ts +8 -15
- package/src/v4/core/registries.ts +3 -2
- package/src/v4/core/schemas.ts +93 -95
- package/src/v4/core/tests/extend.test.ts +18 -0
- package/src/v4/core/to-json-schema.ts +1 -0
- package/src/v4/core/util.ts +135 -98
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/mini/schemas.ts +3 -1
- package/v3/types.cjs +2 -0
- package/v3/types.d.cts +4 -1
- package/v3/types.d.ts +4 -1
- package/v3/types.js +2 -0
- package/v4/classic/errors.cjs +9 -2
- package/v4/classic/errors.js +9 -2
- package/v4/classic/schemas.cjs +5 -3
- package/v4/classic/schemas.d.cts +2 -1
- package/v4/classic/schemas.d.ts +2 -1
- package/v4/classic/schemas.js +5 -3
- package/v4/core/checks.d.cts +2 -2
- package/v4/core/checks.d.ts +2 -2
- package/v4/core/errors.cjs +4 -9
- package/v4/core/errors.d.cts +4 -6
- package/v4/core/errors.d.ts +4 -6
- package/v4/core/errors.js +4 -9
- package/v4/core/registries.cjs +2 -1
- package/v4/core/registries.d.cts +1 -1
- package/v4/core/registries.d.ts +1 -1
- package/v4/core/registries.js +2 -1
- package/v4/core/schemas.cjs +51 -88
- package/v4/core/schemas.d.cts +8 -3
- package/v4/core/schemas.d.ts +8 -3
- package/v4/core/schemas.js +51 -88
- package/v4/core/to-json-schema.cjs +1 -0
- package/v4/core/to-json-schema.js +1 -0
- package/v4/core/util.cjs +123 -97
- package/v4/core/util.d.cts +2 -0
- package/v4/core/util.d.ts +2 -0
- package/v4/core/util.js +121 -97
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/mini/schemas.cjs +3 -1
- package/v4/mini/schemas.js +3 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { test } from "vitest";
|
|
2
|
+
import * as z from "zod/v4";
|
|
3
|
+
|
|
4
|
+
test("extend chaining preserves and overrides properties", () => {
|
|
5
|
+
const schema1 = z.object({
|
|
6
|
+
email: z.string(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const schema2 = schema1.extend({
|
|
10
|
+
email: schema1.shape.email.check(z.email()),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const schema3 = schema2.extend({
|
|
14
|
+
email: schema2.shape.email.or(z.literal("")),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
schema3.parse({ email: "test@example.com" });
|
|
18
|
+
});
|
package/src/v4/core/util.ts
CHANGED
|
@@ -283,6 +283,21 @@ export function assignProp<T extends object, K extends PropertyKey>(
|
|
|
283
283
|
});
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
export function mergeDefs(...defs: Record<string, any>[]): any {
|
|
287
|
+
const mergedDescriptors: Record<string, PropertyDescriptor> = {};
|
|
288
|
+
|
|
289
|
+
for (const def of defs) {
|
|
290
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
291
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function cloneDef(schema: schemas.$ZodType): any {
|
|
298
|
+
return mergeDefs(schema._zod.def);
|
|
299
|
+
}
|
|
300
|
+
|
|
286
301
|
export function getElementAtPath(obj: any, path: (string | number)[] | null | undefined): any {
|
|
287
302
|
if (!path) return obj;
|
|
288
303
|
return path.reduce((acc, key) => acc?.[key], obj);
|
|
@@ -314,15 +329,16 @@ export function esc(str: string): string {
|
|
|
314
329
|
return JSON.stringify(str);
|
|
315
330
|
}
|
|
316
331
|
|
|
317
|
-
export const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void =
|
|
318
|
-
? Error.captureStackTrace
|
|
319
|
-
|
|
332
|
+
export const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void = (
|
|
333
|
+
"captureStackTrace" in Error ? Error.captureStackTrace : (..._args: any[]) => {}
|
|
334
|
+
) as any;
|
|
320
335
|
|
|
321
336
|
export function isObject(data: any): data is Record<PropertyKey, unknown> {
|
|
322
337
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
323
338
|
}
|
|
324
339
|
|
|
325
340
|
export const allowsEval: { value: boolean } = cached(() => {
|
|
341
|
+
// @ts-ignore
|
|
326
342
|
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
|
|
327
343
|
return false;
|
|
328
344
|
}
|
|
@@ -409,6 +425,7 @@ export const getParsedType = (data: any): ParsedTypes => {
|
|
|
409
425
|
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
410
426
|
return "date";
|
|
411
427
|
}
|
|
428
|
+
// @ts-ignore
|
|
412
429
|
if (typeof File !== "undefined" && data instanceof File) {
|
|
413
430
|
return "file";
|
|
414
431
|
}
|
|
@@ -535,71 +552,81 @@ export const BIGINT_FORMAT_RANGES: Record<checks.$ZodBigIntFormats, [bigint, big
|
|
|
535
552
|
};
|
|
536
553
|
|
|
537
554
|
export function pick(schema: schemas.$ZodObject, mask: Record<string, unknown>): any {
|
|
538
|
-
const
|
|
539
|
-
const currDef = schema._zod.def; //.shape;
|
|
555
|
+
const currDef = schema._zod.def;
|
|
540
556
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
557
|
+
const def = mergeDefs(schema._zod.def, {
|
|
558
|
+
get shape() {
|
|
559
|
+
const newShape: Writeable<schemas.$ZodShape> = {};
|
|
560
|
+
for (const key in mask) {
|
|
561
|
+
if (!(key in currDef.shape)) {
|
|
562
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
563
|
+
}
|
|
564
|
+
if (!mask[key]) continue;
|
|
565
|
+
newShape[key] = currDef.shape[key]!;
|
|
566
|
+
}
|
|
550
567
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
568
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
569
|
+
return newShape;
|
|
570
|
+
},
|
|
554
571
|
checks: [],
|
|
555
|
-
})
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
return clone(schema, def) as any;
|
|
556
575
|
}
|
|
557
576
|
|
|
558
577
|
export function omit(schema: schemas.$ZodObject, mask: object): any {
|
|
559
|
-
const
|
|
560
|
-
const currDef = schema._zod.def; //.shape;
|
|
561
|
-
for (const key in mask) {
|
|
562
|
-
if (!(key in currDef.shape)) {
|
|
563
|
-
throw new Error(`Unrecognized key: "${key}"`);
|
|
564
|
-
}
|
|
565
|
-
if (!(mask as any)[key]) continue;
|
|
578
|
+
const currDef = schema._zod.def;
|
|
566
579
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
580
|
+
const def = mergeDefs(schema._zod.def, {
|
|
581
|
+
get shape() {
|
|
582
|
+
const newShape: Writeable<schemas.$ZodShape> = { ...schema._zod.def.shape };
|
|
583
|
+
for (const key in mask) {
|
|
584
|
+
if (!(key in currDef.shape)) {
|
|
585
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
586
|
+
}
|
|
587
|
+
if (!(mask as any)[key]) continue;
|
|
588
|
+
|
|
589
|
+
delete newShape[key];
|
|
590
|
+
}
|
|
591
|
+
assignProp(this, "shape", newShape); // self-caching
|
|
592
|
+
return newShape;
|
|
593
|
+
},
|
|
572
594
|
checks: [],
|
|
573
595
|
});
|
|
596
|
+
|
|
597
|
+
return clone(schema, def);
|
|
574
598
|
}
|
|
575
599
|
|
|
576
600
|
export function extend(schema: schemas.$ZodObject, shape: schemas.$ZodShape): any {
|
|
577
601
|
if (!isPlainObject(shape)) {
|
|
578
602
|
throw new Error("Invalid input to extend: expected a plain object");
|
|
579
603
|
}
|
|
580
|
-
|
|
581
|
-
|
|
604
|
+
|
|
605
|
+
const def = mergeDefs(schema._zod.def, {
|
|
582
606
|
get shape() {
|
|
583
607
|
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
584
608
|
assignProp(this, "shape", _shape); // self-caching
|
|
585
609
|
return _shape;
|
|
586
610
|
},
|
|
587
|
-
checks: [],
|
|
588
|
-
}
|
|
611
|
+
checks: [],
|
|
612
|
+
});
|
|
589
613
|
return clone(schema, def) as any;
|
|
590
614
|
}
|
|
591
615
|
|
|
592
616
|
export function merge(a: schemas.$ZodObject, b: schemas.$ZodObject): any {
|
|
593
|
-
|
|
594
|
-
...a._zod.def,
|
|
617
|
+
const def = mergeDefs(a._zod.def, {
|
|
595
618
|
get shape() {
|
|
596
619
|
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
|
597
620
|
assignProp(this, "shape", _shape); // self-caching
|
|
598
621
|
return _shape;
|
|
599
622
|
},
|
|
600
|
-
catchall
|
|
623
|
+
get catchall() {
|
|
624
|
+
return b._zod.def.catchall;
|
|
625
|
+
},
|
|
601
626
|
checks: [], // delete existing checks
|
|
602
|
-
})
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
return clone(a, def) as any;
|
|
603
630
|
}
|
|
604
631
|
|
|
605
632
|
export function partial(
|
|
@@ -607,40 +634,44 @@ export function partial(
|
|
|
607
634
|
schema: schemas.$ZodObject,
|
|
608
635
|
mask: object | undefined
|
|
609
636
|
): any {
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
if (
|
|
616
|
-
|
|
637
|
+
const def = mergeDefs(schema._zod.def, {
|
|
638
|
+
get shape() {
|
|
639
|
+
const oldShape = schema._zod.def.shape;
|
|
640
|
+
const shape: Writeable<schemas.$ZodShape> = { ...oldShape };
|
|
641
|
+
|
|
642
|
+
if (mask) {
|
|
643
|
+
for (const key in mask) {
|
|
644
|
+
if (!(key in oldShape)) {
|
|
645
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
646
|
+
}
|
|
647
|
+
if (!(mask as any)[key]) continue;
|
|
648
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
649
|
+
shape[key] = Class
|
|
650
|
+
? new Class({
|
|
651
|
+
type: "optional",
|
|
652
|
+
innerType: oldShape[key]!,
|
|
653
|
+
})
|
|
654
|
+
: oldShape[key]!;
|
|
655
|
+
}
|
|
656
|
+
} else {
|
|
657
|
+
for (const key in oldShape) {
|
|
658
|
+
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
659
|
+
shape[key] = Class
|
|
660
|
+
? new Class({
|
|
661
|
+
type: "optional",
|
|
662
|
+
innerType: oldShape[key]!,
|
|
663
|
+
})
|
|
664
|
+
: oldShape[key]!;
|
|
665
|
+
}
|
|
617
666
|
}
|
|
618
|
-
if (!(mask as any)[key]) continue;
|
|
619
|
-
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
620
|
-
shape[key] = Class
|
|
621
|
-
? new Class({
|
|
622
|
-
type: "optional",
|
|
623
|
-
innerType: oldShape[key]!,
|
|
624
|
-
})
|
|
625
|
-
: oldShape[key]!;
|
|
626
|
-
}
|
|
627
|
-
} else {
|
|
628
|
-
for (const key in oldShape) {
|
|
629
|
-
// if (oldShape[key]!._zod.optin === "optional") continue;
|
|
630
|
-
shape[key] = Class
|
|
631
|
-
? new Class({
|
|
632
|
-
type: "optional",
|
|
633
|
-
innerType: oldShape[key]!,
|
|
634
|
-
})
|
|
635
|
-
: oldShape[key]!;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
667
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
668
|
+
assignProp(this, "shape", shape); // self-caching
|
|
669
|
+
return shape;
|
|
670
|
+
},
|
|
642
671
|
checks: [],
|
|
643
|
-
})
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
return clone(schema, def) as any;
|
|
644
675
|
}
|
|
645
676
|
|
|
646
677
|
export function required(
|
|
@@ -648,44 +679,49 @@ export function required(
|
|
|
648
679
|
schema: schemas.$ZodObject,
|
|
649
680
|
mask: object | undefined
|
|
650
681
|
): any {
|
|
651
|
-
const
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
if (
|
|
657
|
-
|
|
682
|
+
const def = mergeDefs(schema._zod.def, {
|
|
683
|
+
get shape() {
|
|
684
|
+
const oldShape = schema._zod.def.shape;
|
|
685
|
+
const shape: Writeable<schemas.$ZodShape> = { ...oldShape };
|
|
686
|
+
|
|
687
|
+
if (mask) {
|
|
688
|
+
for (const key in mask) {
|
|
689
|
+
if (!(key in shape)) {
|
|
690
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
691
|
+
}
|
|
692
|
+
if (!(mask as any)[key]) continue;
|
|
693
|
+
// overwrite with non-optional
|
|
694
|
+
shape[key] = new Class({
|
|
695
|
+
type: "nonoptional",
|
|
696
|
+
innerType: oldShape[key]!,
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
} else {
|
|
700
|
+
for (const key in oldShape) {
|
|
701
|
+
// overwrite with non-optional
|
|
702
|
+
shape[key] = new Class({
|
|
703
|
+
type: "nonoptional",
|
|
704
|
+
innerType: oldShape[key]!,
|
|
705
|
+
});
|
|
706
|
+
}
|
|
658
707
|
}
|
|
659
|
-
if (!(mask as any)[key]) continue;
|
|
660
|
-
// overwrite with non-optional
|
|
661
|
-
shape[key] = new Class({
|
|
662
|
-
type: "nonoptional",
|
|
663
|
-
innerType: oldShape[key]!,
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
} else {
|
|
667
|
-
for (const key in oldShape) {
|
|
668
|
-
// overwrite with non-optional
|
|
669
|
-
shape[key] = new Class({
|
|
670
|
-
type: "nonoptional",
|
|
671
|
-
innerType: oldShape[key]!,
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
708
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
// optional: [],
|
|
709
|
+
assignProp(this, "shape", shape); // self-caching
|
|
710
|
+
return shape;
|
|
711
|
+
},
|
|
680
712
|
checks: [],
|
|
681
|
-
})
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
return clone(schema, def) as any;
|
|
682
716
|
}
|
|
683
717
|
|
|
684
718
|
export type Constructor<T, Def extends any[] = any[]> = new (...args: Def) => T;
|
|
685
719
|
|
|
686
720
|
export function aborted(x: schemas.ParsePayload, startIndex = 0): boolean {
|
|
687
721
|
for (let i = startIndex; i < x.issues.length; i++) {
|
|
688
|
-
if (x.issues[i]?.continue !== true)
|
|
722
|
+
if (x.issues[i]?.continue !== true) {
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
689
725
|
}
|
|
690
726
|
return false;
|
|
691
727
|
}
|
|
@@ -733,6 +769,7 @@ export function finalizeIssue(
|
|
|
733
769
|
export function getSizableOrigin(input: any): "set" | "map" | "file" | "unknown" {
|
|
734
770
|
if (input instanceof Set) return "set";
|
|
735
771
|
if (input instanceof Map) return "map";
|
|
772
|
+
// @ts-ignore
|
|
736
773
|
if (input instanceof File) return "file";
|
|
737
774
|
return "unknown";
|
|
738
775
|
}
|
package/src/v4/core/versions.ts
CHANGED
package/src/v4/mini/schemas.ts
CHANGED
|
@@ -1024,9 +1024,11 @@ export function partialRecord<Key extends core.$ZodRecordKey, Value extends Some
|
|
|
1024
1024
|
valueType: Value,
|
|
1025
1025
|
params?: string | core.$ZodRecordParams
|
|
1026
1026
|
): ZodMiniRecord<Key & core.$partial, Value> {
|
|
1027
|
+
const k = core.clone(keyType);
|
|
1028
|
+
k._zod.values = undefined;
|
|
1027
1029
|
return new ZodMiniRecord({
|
|
1028
1030
|
type: "record",
|
|
1029
|
-
keyType:
|
|
1031
|
+
keyType: k,
|
|
1030
1032
|
valueType: valueType as any,
|
|
1031
1033
|
...util.normalizeParams(params),
|
|
1032
1034
|
}) as any;
|
package/v3/types.cjs
CHANGED
|
@@ -459,6 +459,7 @@ function isValidJWT(jwt, alg) {
|
|
|
459
459
|
.replace(/-/g, "+")
|
|
460
460
|
.replace(/_/g, "/")
|
|
461
461
|
.padEnd(header.length + ((4 - (header.length % 4)) % 4), "=");
|
|
462
|
+
// @ts-ignore
|
|
462
463
|
const decoded = JSON.parse(atob(base64));
|
|
463
464
|
if (typeof decoded !== "object" || decoded === null)
|
|
464
465
|
return false;
|
|
@@ -639,6 +640,7 @@ class ZodString extends ZodType {
|
|
|
639
640
|
}
|
|
640
641
|
else if (check.kind === "url") {
|
|
641
642
|
try {
|
|
643
|
+
// @ts-ignore
|
|
642
644
|
new URL(input.data);
|
|
643
645
|
}
|
|
644
646
|
catch {
|
package/v3/types.d.cts
CHANGED
|
@@ -527,7 +527,10 @@ export type noUnrecognized<Obj extends object, Shape extends object> = {
|
|
|
527
527
|
[k in keyof Obj]: k extends keyof Shape ? Obj[k] : never;
|
|
528
528
|
};
|
|
529
529
|
export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny, Output = objectOutputType<T, Catchall, UnknownKeys>, Input = objectInputType<T, Catchall, UnknownKeys>> extends ZodType<Output, ZodObjectDef<T, UnknownKeys, Catchall>, Input> {
|
|
530
|
-
|
|
530
|
+
_cached: {
|
|
531
|
+
shape: T;
|
|
532
|
+
keys: string[];
|
|
533
|
+
} | null;
|
|
531
534
|
_getCached(): {
|
|
532
535
|
shape: T;
|
|
533
536
|
keys: string[];
|
package/v3/types.d.ts
CHANGED
|
@@ -527,7 +527,10 @@ export type noUnrecognized<Obj extends object, Shape extends object> = {
|
|
|
527
527
|
[k in keyof Obj]: k extends keyof Shape ? Obj[k] : never;
|
|
528
528
|
};
|
|
529
529
|
export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny, Output = objectOutputType<T, Catchall, UnknownKeys>, Input = objectInputType<T, Catchall, UnknownKeys>> extends ZodType<Output, ZodObjectDef<T, UnknownKeys, Catchall>, Input> {
|
|
530
|
-
|
|
530
|
+
_cached: {
|
|
531
|
+
shape: T;
|
|
532
|
+
keys: string[];
|
|
533
|
+
} | null;
|
|
531
534
|
_getCached(): {
|
|
532
535
|
shape: T;
|
|
533
536
|
keys: string[];
|
package/v3/types.js
CHANGED
|
@@ -450,6 +450,7 @@ function isValidJWT(jwt, alg) {
|
|
|
450
450
|
.replace(/-/g, "+")
|
|
451
451
|
.replace(/_/g, "/")
|
|
452
452
|
.padEnd(header.length + ((4 - (header.length % 4)) % 4), "=");
|
|
453
|
+
// @ts-ignore
|
|
453
454
|
const decoded = JSON.parse(atob(base64));
|
|
454
455
|
if (typeof decoded !== "object" || decoded === null)
|
|
455
456
|
return false;
|
|
@@ -630,6 +631,7 @@ export class ZodString extends ZodType {
|
|
|
630
631
|
}
|
|
631
632
|
else if (check.kind === "url") {
|
|
632
633
|
try {
|
|
634
|
+
// @ts-ignore
|
|
633
635
|
new URL(input.data);
|
|
634
636
|
}
|
|
635
637
|
catch {
|
package/v4/classic/errors.cjs
CHANGED
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.ZodRealError = exports.ZodError = void 0;
|
|
27
27
|
const core = __importStar(require("../core/index.cjs"));
|
|
28
28
|
const index_js_1 = require("../core/index.cjs");
|
|
29
|
+
const util = __importStar(require("../core/util.cjs"));
|
|
29
30
|
const initializer = (inst, issues) => {
|
|
30
31
|
index_js_1.$ZodError.init(inst, issues);
|
|
31
32
|
inst.name = "ZodError";
|
|
@@ -39,11 +40,17 @@ const initializer = (inst, issues) => {
|
|
|
39
40
|
// enumerable: false,
|
|
40
41
|
},
|
|
41
42
|
addIssue: {
|
|
42
|
-
value: (issue) =>
|
|
43
|
+
value: (issue) => {
|
|
44
|
+
inst.issues.push(issue);
|
|
45
|
+
inst.message = JSON.stringify(inst.issues, util.jsonStringifyReplacer, 2);
|
|
46
|
+
},
|
|
43
47
|
// enumerable: false,
|
|
44
48
|
},
|
|
45
49
|
addIssues: {
|
|
46
|
-
value: (issues) =>
|
|
50
|
+
value: (issues) => {
|
|
51
|
+
inst.issues.push(...issues);
|
|
52
|
+
inst.message = JSON.stringify(inst.issues, util.jsonStringifyReplacer, 2);
|
|
53
|
+
},
|
|
47
54
|
// enumerable: false,
|
|
48
55
|
},
|
|
49
56
|
isEmpty: {
|
package/v4/classic/errors.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as core from "../core/index.js";
|
|
2
2
|
import { $ZodError } from "../core/index.js";
|
|
3
|
+
import * as util from "../core/util.js";
|
|
3
4
|
const initializer = (inst, issues) => {
|
|
4
5
|
$ZodError.init(inst, issues);
|
|
5
6
|
inst.name = "ZodError";
|
|
@@ -13,11 +14,17 @@ const initializer = (inst, issues) => {
|
|
|
13
14
|
// enumerable: false,
|
|
14
15
|
},
|
|
15
16
|
addIssue: {
|
|
16
|
-
value: (issue) =>
|
|
17
|
+
value: (issue) => {
|
|
18
|
+
inst.issues.push(issue);
|
|
19
|
+
inst.message = JSON.stringify(inst.issues, util.jsonStringifyReplacer, 2);
|
|
20
|
+
},
|
|
17
21
|
// enumerable: false,
|
|
18
22
|
},
|
|
19
23
|
addIssues: {
|
|
20
|
-
value: (issues) =>
|
|
24
|
+
value: (issues) => {
|
|
25
|
+
inst.issues.push(...issues);
|
|
26
|
+
inst.message = JSON.stringify(inst.issues, util.jsonStringifyReplacer, 2);
|
|
27
|
+
},
|
|
21
28
|
// enumerable: false,
|
|
22
29
|
},
|
|
23
30
|
isEmpty: {
|
package/v4/classic/schemas.cjs
CHANGED
|
@@ -595,7 +595,6 @@ exports.ZodObject = core.$constructor("ZodObject", (inst, def) => {
|
|
|
595
595
|
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
596
596
|
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
|
|
597
597
|
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
598
|
-
// inst.nonstrict = () => inst.clone({ ...inst._zod.def, catchall: api.unknown() });
|
|
599
598
|
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
600
599
|
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
|
|
601
600
|
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
|
|
@@ -714,9 +713,11 @@ function record(keyType, valueType, params) {
|
|
|
714
713
|
}
|
|
715
714
|
// type alksjf = core.output<core.$ZodRecordKey>;
|
|
716
715
|
function partialRecord(keyType, valueType, params) {
|
|
716
|
+
const k = core.clone(keyType);
|
|
717
|
+
k._zod.values = undefined;
|
|
717
718
|
return new exports.ZodRecord({
|
|
718
719
|
type: "record",
|
|
719
|
-
keyType:
|
|
720
|
+
keyType: k,
|
|
720
721
|
valueType: valueType,
|
|
721
722
|
...index_js_1.util.normalizeParams(params),
|
|
722
723
|
});
|
|
@@ -857,7 +858,7 @@ exports.ZodTransform = core.$constructor("ZodTransform", (inst, def) => {
|
|
|
857
858
|
_issue.code ?? (_issue.code = "custom");
|
|
858
859
|
_issue.input ?? (_issue.input = payload.value);
|
|
859
860
|
_issue.inst ?? (_issue.inst = inst);
|
|
860
|
-
|
|
861
|
+
// _issue.continue ??= true;
|
|
861
862
|
payload.issues.push(index_js_1.util.issue(_issue));
|
|
862
863
|
}
|
|
863
864
|
};
|
|
@@ -993,6 +994,7 @@ function pipe(in_, out) {
|
|
|
993
994
|
exports.ZodReadonly = core.$constructor("ZodReadonly", (inst, def) => {
|
|
994
995
|
core.$ZodReadonly.init(inst, def);
|
|
995
996
|
exports.ZodType.init(inst, def);
|
|
997
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
996
998
|
});
|
|
997
999
|
function readonly(innerType) {
|
|
998
1000
|
return new exports.ZodReadonly({
|
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -413,7 +413,7 @@ out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.
|
|
|
413
413
|
strict(): ZodObject<Shape, core.$strict>;
|
|
414
414
|
/** This is the default behavior. This method call is likely unnecessary. */
|
|
415
415
|
strip(): ZodObject<Shape, core.$strip>;
|
|
416
|
-
extend<U extends core.$ZodLooseShape
|
|
416
|
+
extend<U extends core.$ZodLooseShape>(shape: U): ZodObject<util.Extend<Shape, U>, Config>;
|
|
417
417
|
/**
|
|
418
418
|
* @deprecated Use [`A.extend(B.shape)`](https://zod.dev/api?id=extend) instead.
|
|
419
419
|
*/
|
|
@@ -572,6 +572,7 @@ export interface ZodPipe<A extends core.SomeType = core.$ZodType, B extends core
|
|
|
572
572
|
export declare const ZodPipe: core.$constructor<ZodPipe>;
|
|
573
573
|
export declare function pipe<const A extends core.SomeType, B extends core.$ZodType<unknown, core.output<A>> = core.$ZodType<unknown, core.output<A>>>(in_: A, out: B | core.$ZodType<unknown, core.output<A>>): ZodPipe<A, B>;
|
|
574
574
|
export interface ZodReadonly<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodReadonlyInternals<T>>, core.$ZodReadonly<T> {
|
|
575
|
+
unwrap(): T;
|
|
575
576
|
}
|
|
576
577
|
export declare const ZodReadonly: core.$constructor<ZodReadonly>;
|
|
577
578
|
export declare function readonly<T extends core.SomeType>(innerType: T): ZodReadonly<T>;
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -413,7 +413,7 @@ out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.
|
|
|
413
413
|
strict(): ZodObject<Shape, core.$strict>;
|
|
414
414
|
/** This is the default behavior. This method call is likely unnecessary. */
|
|
415
415
|
strip(): ZodObject<Shape, core.$strip>;
|
|
416
|
-
extend<U extends core.$ZodLooseShape
|
|
416
|
+
extend<U extends core.$ZodLooseShape>(shape: U): ZodObject<util.Extend<Shape, U>, Config>;
|
|
417
417
|
/**
|
|
418
418
|
* @deprecated Use [`A.extend(B.shape)`](https://zod.dev/api?id=extend) instead.
|
|
419
419
|
*/
|
|
@@ -572,6 +572,7 @@ export interface ZodPipe<A extends core.SomeType = core.$ZodType, B extends core
|
|
|
572
572
|
export declare const ZodPipe: core.$constructor<ZodPipe>;
|
|
573
573
|
export declare function pipe<const A extends core.SomeType, B extends core.$ZodType<unknown, core.output<A>> = core.$ZodType<unknown, core.output<A>>>(in_: A, out: B | core.$ZodType<unknown, core.output<A>>): ZodPipe<A, B>;
|
|
574
574
|
export interface ZodReadonly<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodReadonlyInternals<T>>, core.$ZodReadonly<T> {
|
|
575
|
+
unwrap(): T;
|
|
575
576
|
}
|
|
576
577
|
export declare const ZodReadonly: core.$constructor<ZodReadonly>;
|
|
577
578
|
export declare function readonly<T extends core.SomeType>(innerType: T): ZodReadonly<T>;
|
package/v4/classic/schemas.js
CHANGED
|
@@ -490,7 +490,6 @@ export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def
|
|
|
490
490
|
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
491
491
|
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
|
|
492
492
|
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
493
|
-
// inst.nonstrict = () => inst.clone({ ...inst._zod.def, catchall: api.unknown() });
|
|
494
493
|
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
495
494
|
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
|
|
496
495
|
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
|
|
@@ -609,9 +608,11 @@ export function record(keyType, valueType, params) {
|
|
|
609
608
|
}
|
|
610
609
|
// type alksjf = core.output<core.$ZodRecordKey>;
|
|
611
610
|
export function partialRecord(keyType, valueType, params) {
|
|
611
|
+
const k = core.clone(keyType);
|
|
612
|
+
k._zod.values = undefined;
|
|
612
613
|
return new ZodRecord({
|
|
613
614
|
type: "record",
|
|
614
|
-
keyType:
|
|
615
|
+
keyType: k,
|
|
615
616
|
valueType: valueType,
|
|
616
617
|
...util.normalizeParams(params),
|
|
617
618
|
});
|
|
@@ -753,7 +754,7 @@ export const ZodTransform = /*@__PURE__*/ core.$constructor("ZodTransform", (ins
|
|
|
753
754
|
_issue.code ?? (_issue.code = "custom");
|
|
754
755
|
_issue.input ?? (_issue.input = payload.value);
|
|
755
756
|
_issue.inst ?? (_issue.inst = inst);
|
|
756
|
-
|
|
757
|
+
// _issue.continue ??= true;
|
|
757
758
|
payload.issues.push(util.issue(_issue));
|
|
758
759
|
}
|
|
759
760
|
};
|
|
@@ -890,6 +891,7 @@ export function pipe(in_, out) {
|
|
|
890
891
|
export const ZodReadonly = /*@__PURE__*/ core.$constructor("ZodReadonly", (inst, def) => {
|
|
891
892
|
core.$ZodReadonly.init(inst, def);
|
|
892
893
|
ZodType.init(inst, def);
|
|
894
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
893
895
|
});
|
|
894
896
|
export function readonly(innerType) {
|
|
895
897
|
return new ZodReadonly({
|
package/v4/core/checks.d.cts
CHANGED
|
@@ -254,11 +254,11 @@ export interface $ZodCheckMimeTypeDef extends $ZodCheckDef {
|
|
|
254
254
|
check: "mime_type";
|
|
255
255
|
mime: util.MimeTypes[];
|
|
256
256
|
}
|
|
257
|
-
export interface $ZodCheckMimeTypeInternals<T extends File = File> extends $ZodCheckInternals<T> {
|
|
257
|
+
export interface $ZodCheckMimeTypeInternals<T extends schemas.File = schemas.File> extends $ZodCheckInternals<T> {
|
|
258
258
|
def: $ZodCheckMimeTypeDef;
|
|
259
259
|
issc: errors.$ZodIssueInvalidValue;
|
|
260
260
|
}
|
|
261
|
-
export interface $ZodCheckMimeType<T extends File = File> extends $ZodCheck<T> {
|
|
261
|
+
export interface $ZodCheckMimeType<T extends schemas.File = schemas.File> extends $ZodCheck<T> {
|
|
262
262
|
_zod: $ZodCheckMimeTypeInternals<T>;
|
|
263
263
|
}
|
|
264
264
|
export declare const $ZodCheckMimeType: core.$constructor<$ZodCheckMimeType>;
|
package/v4/core/checks.d.ts
CHANGED
|
@@ -254,11 +254,11 @@ export interface $ZodCheckMimeTypeDef extends $ZodCheckDef {
|
|
|
254
254
|
check: "mime_type";
|
|
255
255
|
mime: util.MimeTypes[];
|
|
256
256
|
}
|
|
257
|
-
export interface $ZodCheckMimeTypeInternals<T extends File = File> extends $ZodCheckInternals<T> {
|
|
257
|
+
export interface $ZodCheckMimeTypeInternals<T extends schemas.File = schemas.File> extends $ZodCheckInternals<T> {
|
|
258
258
|
def: $ZodCheckMimeTypeDef;
|
|
259
259
|
issc: errors.$ZodIssueInvalidValue;
|
|
260
260
|
}
|
|
261
|
-
export interface $ZodCheckMimeType<T extends File = File> extends $ZodCheck<T> {
|
|
261
|
+
export interface $ZodCheckMimeType<T extends schemas.File = schemas.File> extends $ZodCheck<T> {
|
|
262
262
|
_zod: $ZodCheckMimeTypeInternals<T>;
|
|
263
263
|
}
|
|
264
264
|
export declare const $ZodCheckMimeType: core.$constructor<$ZodCheckMimeType>;
|