zod 4.1.4 → 4.1.6-beta.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/package.json +2 -2
- package/src/v4/classic/schemas.ts +5 -5
- package/src/v4/classic/tests/codec.test.ts +36 -6
- package/src/v4/classic/tests/function.test.ts +40 -0
- package/src/v4/core/schemas.ts +8 -5
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/mini/schemas.ts +2 -2
- package/src/v4/mini/tests/codec.test.ts +36 -6
- package/v4/classic/schemas.d.cts +5 -5
- package/v4/classic/schemas.d.ts +5 -5
- package/v4/core/schemas.cjs +3 -1
- package/v4/core/schemas.d.cts +4 -4
- package/v4/core/schemas.d.ts +4 -4
- package/v4/core/schemas.js +3 -1
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/mini/schemas.d.cts +2 -2
- package/v4/mini/schemas.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.6-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Colin McDonnell <zod@colinhacks.com>",
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"scripts": {
|
|
127
127
|
"clean": "git clean -xdf . -e node_modules",
|
|
128
128
|
"build": "zshy --project tsconfig.build.json",
|
|
129
|
-
"postbuild": "pnpm biome check --write .",
|
|
129
|
+
"postbuild": "tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .",
|
|
130
130
|
"test:watch": "pnpm vitest",
|
|
131
131
|
"test": "pnpm vitest run",
|
|
132
132
|
"prepublishOnly": "tsx ../../scripts/check-versions.ts"
|
|
@@ -89,7 +89,7 @@ export interface ZodType<
|
|
|
89
89
|
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
|
|
90
90
|
nullable(): ZodNullable<this>;
|
|
91
91
|
nullish(): ZodOptional<ZodNullable<this>>;
|
|
92
|
-
default(def: core.output<this
|
|
92
|
+
default(def: util.NoUndefined<core.output<this>>): ZodDefault<this>;
|
|
93
93
|
default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>;
|
|
94
94
|
prefault(def: () => core.input<this>): ZodPrefault<this>;
|
|
95
95
|
prefault(def: core.input<this>): ZodPrefault<this>;
|
|
@@ -1931,8 +1931,8 @@ export function codec<const A extends core.SomeType, B extends core.SomeType = c
|
|
|
1931
1931
|
in_: A,
|
|
1932
1932
|
out: B,
|
|
1933
1933
|
params: {
|
|
1934
|
-
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.input<B
|
|
1935
|
-
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.output<A
|
|
1934
|
+
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.util.MaybeAsync<core.input<B>>;
|
|
1935
|
+
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
1936
1936
|
}
|
|
1937
1937
|
): ZodCodec<A, B> {
|
|
1938
1938
|
return new ZodCodec({
|
|
@@ -2059,11 +2059,11 @@ export const ZodFunction: core.$constructor<ZodFunction> = /*@__PURE__*/ core.$c
|
|
|
2059
2059
|
);
|
|
2060
2060
|
|
|
2061
2061
|
export function _function(): ZodFunction;
|
|
2062
|
-
export function _function<const In extends
|
|
2062
|
+
export function _function<const In extends ReadonlyArray<core.$ZodType>>(params: {
|
|
2063
2063
|
input: In;
|
|
2064
2064
|
}): ZodFunction<ZodTuple<In, null>, core.$ZodFunctionOut>;
|
|
2065
2065
|
export function _function<
|
|
2066
|
-
const In extends
|
|
2066
|
+
const In extends ReadonlyArray<core.$ZodType>,
|
|
2067
2067
|
const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut,
|
|
2068
2068
|
>(params: {
|
|
2069
2069
|
input: In;
|
|
@@ -414,11 +414,11 @@ test("codec type enforcement - correct encode/decode signatures", () => {
|
|
|
414
414
|
encode: (value: number) => String(value), // core.input<B> -> core.output<A>
|
|
415
415
|
});
|
|
416
416
|
|
|
417
|
-
// These should compile without errors - correct types
|
|
418
|
-
expectTypeOf<(value: string, payload: z.core.ParsePayload<string>) => number
|
|
417
|
+
// These should compile without errors - correct types (async support)
|
|
418
|
+
expectTypeOf<(value: string, payload: z.core.ParsePayload<string>) => z.core.util.MaybeAsync<number>>(
|
|
419
419
|
stringToNumberCodec.def.transform
|
|
420
420
|
).toBeFunction();
|
|
421
|
-
expectTypeOf<(value: number, payload: z.core.ParsePayload<number>) => string
|
|
421
|
+
expectTypeOf<(value: number, payload: z.core.ParsePayload<number>) => z.core.util.MaybeAsync<string>>(
|
|
422
422
|
stringToNumberCodec.def.reverseTransform
|
|
423
423
|
).toBeFunction();
|
|
424
424
|
|
|
@@ -468,11 +468,11 @@ test("codec type enforcement - complex types", () => {
|
|
|
468
468
|
}
|
|
469
469
|
);
|
|
470
470
|
|
|
471
|
-
// Verify correct types are inferred
|
|
472
|
-
expectTypeOf<(input: UserInput, payload: z.core.ParsePayload<UserInput>) => User
|
|
471
|
+
// Verify correct types are inferred (async support)
|
|
472
|
+
expectTypeOf<(input: UserInput, payload: z.core.ParsePayload<UserInput>) => z.core.util.MaybeAsync<User>>(
|
|
473
473
|
userCodec.def.transform
|
|
474
474
|
).toBeFunction();
|
|
475
|
-
expectTypeOf<(user: User, payload: z.core.ParsePayload<User>) => UserInput
|
|
475
|
+
expectTypeOf<(user: User, payload: z.core.ParsePayload<User>) => z.core.util.MaybeAsync<UserInput>>(
|
|
476
476
|
userCodec.def.reverseTransform
|
|
477
477
|
).toBeFunction();
|
|
478
478
|
|
|
@@ -530,3 +530,33 @@ test("codex with overwrites", () => {
|
|
|
530
530
|
}
|
|
531
531
|
`);
|
|
532
532
|
});
|
|
533
|
+
|
|
534
|
+
test("async codec functionality", async () => {
|
|
535
|
+
// Test that async encode/decode functions work properly
|
|
536
|
+
const asyncCodec = z.codec(z.string(), z.number(), {
|
|
537
|
+
decode: async (str) => {
|
|
538
|
+
await new Promise((resolve) => setTimeout(resolve, 1)); // Simulate async work
|
|
539
|
+
return Number.parseFloat(str);
|
|
540
|
+
},
|
|
541
|
+
encode: async (num) => {
|
|
542
|
+
await new Promise((resolve) => setTimeout(resolve, 1)); // Simulate async work
|
|
543
|
+
return num.toString();
|
|
544
|
+
},
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
// Test async decode/encode
|
|
548
|
+
const decoded = await z.decodeAsync(asyncCodec, "42.5");
|
|
549
|
+
expect(decoded).toBe(42.5);
|
|
550
|
+
|
|
551
|
+
const encoded = await z.encodeAsync(asyncCodec, 42.5);
|
|
552
|
+
expect(encoded).toBe("42.5");
|
|
553
|
+
|
|
554
|
+
// Test that both sync and async work
|
|
555
|
+
const mixedCodec = z.codec(z.string(), z.number(), {
|
|
556
|
+
decode: async (str) => Number.parseFloat(str),
|
|
557
|
+
encode: (num) => num.toString(), // sync encode
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
const mixedResult = await z.decodeAsync(mixedCodec, "123");
|
|
561
|
+
expect(mixedResult).toBe(123);
|
|
562
|
+
});
|
|
@@ -130,6 +130,46 @@ test("valid function run", () => {
|
|
|
130
130
|
});
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
+
const args3 = [
|
|
134
|
+
z.object({
|
|
135
|
+
f1: z.number(),
|
|
136
|
+
f2: z.string().nullable(),
|
|
137
|
+
f3: z.array(z.boolean().optional()).optional(),
|
|
138
|
+
}),
|
|
139
|
+
] as const;
|
|
140
|
+
const returns3 = z.union([z.string(), z.number()]);
|
|
141
|
+
|
|
142
|
+
const func3 = z.function({
|
|
143
|
+
input: args3,
|
|
144
|
+
output: returns3,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("function inference 3", () => {
|
|
148
|
+
type func3 = (typeof func3)["_input"];
|
|
149
|
+
|
|
150
|
+
expectTypeOf<func3>().toEqualTypeOf<
|
|
151
|
+
(arg: {
|
|
152
|
+
f3?: (boolean | undefined)[] | undefined;
|
|
153
|
+
f1: number;
|
|
154
|
+
f2: string | null;
|
|
155
|
+
}) => string | number
|
|
156
|
+
>();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("valid function run", () => {
|
|
160
|
+
const validFunc3Instance = func3.implement((_x) => {
|
|
161
|
+
_x.f2;
|
|
162
|
+
_x.f3![0];
|
|
163
|
+
return "adf" as any;
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
validFunc3Instance({
|
|
167
|
+
f1: 21,
|
|
168
|
+
f2: "asdf",
|
|
169
|
+
f3: [true, false],
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
133
173
|
test("input validation error", () => {
|
|
134
174
|
const schema = z.function({
|
|
135
175
|
input: z.tuple([z.string()]),
|
package/src/v4/core/schemas.ts
CHANGED
|
@@ -1862,6 +1862,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
|
|
|
1862
1862
|
|
|
1863
1863
|
const proms: Promise<any>[] = [];
|
|
1864
1864
|
const shape = value.shape;
|
|
1865
|
+
|
|
1865
1866
|
for (const key of value.keys) {
|
|
1866
1867
|
const el = shape[key]!;
|
|
1867
1868
|
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
|
@@ -1907,7 +1908,7 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
|
|
|
1907
1908
|
}
|
|
1908
1909
|
|
|
1909
1910
|
// A: preserve key order {
|
|
1910
|
-
doc.write(`const newResult = {}
|
|
1911
|
+
doc.write(`const newResult = {};`);
|
|
1911
1912
|
for (const key of normalized.keys) {
|
|
1912
1913
|
const id = ids[key];
|
|
1913
1914
|
const k = util.esc(key);
|
|
@@ -1920,6 +1921,7 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
|
|
|
1920
1921
|
})));
|
|
1921
1922
|
}
|
|
1922
1923
|
|
|
1924
|
+
|
|
1923
1925
|
if (${id}.value === undefined) {
|
|
1924
1926
|
if (${k} in input) {
|
|
1925
1927
|
newResult[${k}] = undefined;
|
|
@@ -1927,6 +1929,7 @@ export const $ZodObjectJIT: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$
|
|
|
1927
1929
|
} else {
|
|
1928
1930
|
newResult[${k}] = ${id}.value;
|
|
1929
1931
|
}
|
|
1932
|
+
|
|
1930
1933
|
`);
|
|
1931
1934
|
}
|
|
1932
1935
|
|
|
@@ -3590,9 +3593,9 @@ export interface $ZodPipeDef<A extends SomeType = $ZodType, B extends SomeType =
|
|
|
3590
3593
|
in: A;
|
|
3591
3594
|
out: B;
|
|
3592
3595
|
/** Only defined inside $ZodCodec instances. */
|
|
3593
|
-
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => core.input<B
|
|
3596
|
+
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
|
3594
3597
|
/** Only defined inside $ZodCodec instances. */
|
|
3595
|
-
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => core.output<A
|
|
3598
|
+
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
|
3596
3599
|
}
|
|
3597
3600
|
|
|
3598
3601
|
export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
|
|
@@ -3650,8 +3653,8 @@ function handlePipeResult(left: ParsePayload, next: $ZodType, ctx: ParseContextI
|
|
|
3650
3653
|
////////////////////////////////////////////
|
|
3651
3654
|
////////////////////////////////////////////
|
|
3652
3655
|
export interface $ZodCodecDef<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodPipeDef<A, B> {
|
|
3653
|
-
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => core.input<B
|
|
3654
|
-
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => core.output<A
|
|
3656
|
+
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
|
3657
|
+
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
|
3655
3658
|
}
|
|
3656
3659
|
|
|
3657
3660
|
export interface $ZodCodecInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
|
package/src/v4/core/versions.ts
CHANGED
package/src/v4/mini/schemas.ts
CHANGED
|
@@ -1460,8 +1460,8 @@ export function codec<const A extends SomeType, B extends core.SomeType = core.$
|
|
|
1460
1460
|
in_: A,
|
|
1461
1461
|
out: B,
|
|
1462
1462
|
params: {
|
|
1463
|
-
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.input<B
|
|
1464
|
-
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.output<A
|
|
1463
|
+
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.util.MaybeAsync<core.input<B>>;
|
|
1464
|
+
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
1465
1465
|
}
|
|
1466
1466
|
): ZodMiniCodec<A, B> {
|
|
1467
1467
|
return new ZodMiniCodec({
|
|
@@ -409,11 +409,11 @@ test("codec type enforcement - correct encode/decode signatures", () => {
|
|
|
409
409
|
encode: (value: number) => String(value), // core.input<B> -> core.output<A>
|
|
410
410
|
});
|
|
411
411
|
|
|
412
|
-
// These should compile without errors - correct types
|
|
413
|
-
expectTypeOf<(value: string, payload: z.core.ParsePayload<string>) => number
|
|
412
|
+
// These should compile without errors - correct types (async support)
|
|
413
|
+
expectTypeOf<(value: string, payload: z.core.ParsePayload<string>) => z.core.util.MaybeAsync<number>>(
|
|
414
414
|
stringToNumberCodec.def.transform
|
|
415
415
|
).toBeFunction();
|
|
416
|
-
expectTypeOf<(value: number, payload: z.core.ParsePayload<number>) => string
|
|
416
|
+
expectTypeOf<(value: number, payload: z.core.ParsePayload<number>) => z.core.util.MaybeAsync<string>>(
|
|
417
417
|
stringToNumberCodec.def.reverseTransform
|
|
418
418
|
).toBeFunction();
|
|
419
419
|
|
|
@@ -450,6 +450,36 @@ test("codec type enforcement - correct encode/decode signatures", () => {
|
|
|
450
450
|
});
|
|
451
451
|
});
|
|
452
452
|
|
|
453
|
+
test("async codec functionality", async () => {
|
|
454
|
+
// Test that async encode/decode functions work properly
|
|
455
|
+
const asyncCodec = z.codec(z.string(), z.number(), {
|
|
456
|
+
decode: async (str) => {
|
|
457
|
+
await new Promise((resolve) => setTimeout(resolve, 1)); // Simulate async work
|
|
458
|
+
return Number.parseFloat(str);
|
|
459
|
+
},
|
|
460
|
+
encode: async (num) => {
|
|
461
|
+
await new Promise((resolve) => setTimeout(resolve, 1)); // Simulate async work
|
|
462
|
+
return num.toString();
|
|
463
|
+
},
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
// Test async decode/encode
|
|
467
|
+
const decoded = await z.decodeAsync(asyncCodec, "42.5");
|
|
468
|
+
expect(decoded).toBe(42.5);
|
|
469
|
+
|
|
470
|
+
const encoded = await z.encodeAsync(asyncCodec, 42.5);
|
|
471
|
+
expect(encoded).toBe("42.5");
|
|
472
|
+
|
|
473
|
+
// Test that both sync and async work
|
|
474
|
+
const mixedCodec = z.codec(z.string(), z.number(), {
|
|
475
|
+
decode: async (str) => Number.parseFloat(str),
|
|
476
|
+
encode: (num) => num.toString(), // sync encode
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
const mixedResult = await z.decodeAsync(mixedCodec, "123");
|
|
480
|
+
expect(mixedResult).toBe(123);
|
|
481
|
+
});
|
|
482
|
+
|
|
453
483
|
test("codec type enforcement - complex types", () => {
|
|
454
484
|
type User = { id: number; name: string };
|
|
455
485
|
type UserInput = { id: string; name: string };
|
|
@@ -463,11 +493,11 @@ test("codec type enforcement - complex types", () => {
|
|
|
463
493
|
}
|
|
464
494
|
);
|
|
465
495
|
|
|
466
|
-
// Verify correct types are inferred
|
|
467
|
-
expectTypeOf<(input: UserInput, payload: z.core.ParsePayload<UserInput>) => User
|
|
496
|
+
// Verify correct types are inferred (async support)
|
|
497
|
+
expectTypeOf<(input: UserInput, payload: z.core.ParsePayload<UserInput>) => z.core.util.MaybeAsync<User>>(
|
|
468
498
|
userCodec.def.transform
|
|
469
499
|
).toBeFunction();
|
|
470
|
-
expectTypeOf<(user: User, payload: z.core.ParsePayload<User>) => UserInput
|
|
500
|
+
expectTypeOf<(user: User, payload: z.core.ParsePayload<User>) => z.core.util.MaybeAsync<UserInput>>(
|
|
471
501
|
userCodec.def.reverseTransform
|
|
472
502
|
).toBeFunction();
|
|
473
503
|
|
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -36,7 +36,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
|
|
|
36
36
|
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
|
|
37
37
|
nullable(): ZodNullable<this>;
|
|
38
38
|
nullish(): ZodOptional<ZodNullable<this>>;
|
|
39
|
-
default(def: core.output<this
|
|
39
|
+
default(def: util.NoUndefined<core.output<this>>): ZodDefault<this>;
|
|
40
40
|
default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>;
|
|
41
41
|
prefault(def: () => core.input<this>): ZodPrefault<this>;
|
|
42
42
|
prefault(def: core.input<this>): ZodPrefault<this>;
|
|
@@ -591,8 +591,8 @@ export interface ZodCodec<A extends core.SomeType = core.$ZodType, B extends cor
|
|
|
591
591
|
}
|
|
592
592
|
export declare const ZodCodec: core.$constructor<ZodCodec>;
|
|
593
593
|
export declare function codec<const A extends core.SomeType, B extends core.SomeType = core.$ZodType>(in_: A, out: B, params: {
|
|
594
|
-
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.input<B
|
|
595
|
-
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.output<A
|
|
594
|
+
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.util.MaybeAsync<core.input<B>>;
|
|
595
|
+
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
596
596
|
}): ZodCodec<A, B>;
|
|
597
597
|
export interface ZodReadonly<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodReadonlyInternals<T>>, core.$ZodReadonly<T> {
|
|
598
598
|
unwrap(): T;
|
|
@@ -624,10 +624,10 @@ export interface ZodFunction<Args extends core.$ZodFunctionIn = core.$ZodFunctio
|
|
|
624
624
|
}
|
|
625
625
|
export declare const ZodFunction: core.$constructor<ZodFunction>;
|
|
626
626
|
export declare function _function(): ZodFunction;
|
|
627
|
-
export declare function _function<const In extends
|
|
627
|
+
export declare function _function<const In extends ReadonlyArray<core.$ZodType>>(params: {
|
|
628
628
|
input: In;
|
|
629
629
|
}): ZodFunction<ZodTuple<In, null>, core.$ZodFunctionOut>;
|
|
630
|
-
export declare function _function<const In extends
|
|
630
|
+
export declare function _function<const In extends ReadonlyArray<core.$ZodType>, const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut>(params: {
|
|
631
631
|
input: In;
|
|
632
632
|
output: Out;
|
|
633
633
|
}): ZodFunction<ZodTuple<In, null>, Out>;
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
|
|
|
36
36
|
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
|
|
37
37
|
nullable(): ZodNullable<this>;
|
|
38
38
|
nullish(): ZodOptional<ZodNullable<this>>;
|
|
39
|
-
default(def: core.output<this
|
|
39
|
+
default(def: util.NoUndefined<core.output<this>>): ZodDefault<this>;
|
|
40
40
|
default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>;
|
|
41
41
|
prefault(def: () => core.input<this>): ZodPrefault<this>;
|
|
42
42
|
prefault(def: core.input<this>): ZodPrefault<this>;
|
|
@@ -591,8 +591,8 @@ export interface ZodCodec<A extends core.SomeType = core.$ZodType, B extends cor
|
|
|
591
591
|
}
|
|
592
592
|
export declare const ZodCodec: core.$constructor<ZodCodec>;
|
|
593
593
|
export declare function codec<const A extends core.SomeType, B extends core.SomeType = core.$ZodType>(in_: A, out: B, params: {
|
|
594
|
-
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.input<B
|
|
595
|
-
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.output<A
|
|
594
|
+
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.util.MaybeAsync<core.input<B>>;
|
|
595
|
+
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
596
596
|
}): ZodCodec<A, B>;
|
|
597
597
|
export interface ZodReadonly<T extends core.SomeType = core.$ZodType> extends _ZodType<core.$ZodReadonlyInternals<T>>, core.$ZodReadonly<T> {
|
|
598
598
|
unwrap(): T;
|
|
@@ -624,10 +624,10 @@ export interface ZodFunction<Args extends core.$ZodFunctionIn = core.$ZodFunctio
|
|
|
624
624
|
}
|
|
625
625
|
export declare const ZodFunction: core.$constructor<ZodFunction>;
|
|
626
626
|
export declare function _function(): ZodFunction;
|
|
627
|
-
export declare function _function<const In extends
|
|
627
|
+
export declare function _function<const In extends ReadonlyArray<core.$ZodType>>(params: {
|
|
628
628
|
input: In;
|
|
629
629
|
}): ZodFunction<ZodTuple<In, null>, core.$ZodFunctionOut>;
|
|
630
|
-
export declare function _function<const In extends
|
|
630
|
+
export declare function _function<const In extends ReadonlyArray<core.$ZodType>, const Out extends core.$ZodFunctionOut = core.$ZodFunctionOut>(params: {
|
|
631
631
|
input: In;
|
|
632
632
|
output: Out;
|
|
633
633
|
}): ZodFunction<ZodTuple<In, null>, Out>;
|
package/v4/core/schemas.cjs
CHANGED
|
@@ -864,7 +864,7 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
|
|
864
864
|
ids[key] = `key_${counter++}`;
|
|
865
865
|
}
|
|
866
866
|
// A: preserve key order {
|
|
867
|
-
doc.write(`const newResult = {}
|
|
867
|
+
doc.write(`const newResult = {};`);
|
|
868
868
|
for (const key of normalized.keys) {
|
|
869
869
|
const id = ids[key];
|
|
870
870
|
const k = util.esc(key);
|
|
@@ -877,6 +877,7 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
|
|
877
877
|
})));
|
|
878
878
|
}
|
|
879
879
|
|
|
880
|
+
|
|
880
881
|
if (${id}.value === undefined) {
|
|
881
882
|
if (${k} in input) {
|
|
882
883
|
newResult[${k}] = undefined;
|
|
@@ -884,6 +885,7 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
|
|
884
885
|
} else {
|
|
885
886
|
newResult[${k}] = ${id}.value;
|
|
886
887
|
}
|
|
888
|
+
|
|
887
889
|
`);
|
|
888
890
|
}
|
|
889
891
|
doc.write(`payload.value = newResult;`);
|
package/v4/core/schemas.d.cts
CHANGED
|
@@ -945,9 +945,9 @@ export interface $ZodPipeDef<A extends SomeType = $ZodType, B extends SomeType =
|
|
|
945
945
|
in: A;
|
|
946
946
|
out: B;
|
|
947
947
|
/** Only defined inside $ZodCodec instances. */
|
|
948
|
-
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => core.input<B
|
|
948
|
+
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
|
949
949
|
/** Only defined inside $ZodCodec instances. */
|
|
950
|
-
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => core.output<A
|
|
950
|
+
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
|
951
951
|
}
|
|
952
952
|
export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
|
953
953
|
def: $ZodPipeDef<A, B>;
|
|
@@ -962,8 +962,8 @@ export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $Z
|
|
|
962
962
|
}
|
|
963
963
|
export declare const $ZodPipe: core.$constructor<$ZodPipe>;
|
|
964
964
|
export interface $ZodCodecDef<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodPipeDef<A, B> {
|
|
965
|
-
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => core.input<B
|
|
966
|
-
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => core.output<A
|
|
965
|
+
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
|
966
|
+
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
|
967
967
|
}
|
|
968
968
|
export interface $ZodCodecInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
|
969
969
|
def: $ZodCodecDef<A, B>;
|
package/v4/core/schemas.d.ts
CHANGED
|
@@ -945,9 +945,9 @@ export interface $ZodPipeDef<A extends SomeType = $ZodType, B extends SomeType =
|
|
|
945
945
|
in: A;
|
|
946
946
|
out: B;
|
|
947
947
|
/** Only defined inside $ZodCodec instances. */
|
|
948
|
-
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => core.input<B
|
|
948
|
+
transform?: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
|
949
949
|
/** Only defined inside $ZodCodec instances. */
|
|
950
|
-
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => core.output<A
|
|
950
|
+
reverseTransform?: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
|
951
951
|
}
|
|
952
952
|
export interface $ZodPipeInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
|
953
953
|
def: $ZodPipeDef<A, B>;
|
|
@@ -962,8 +962,8 @@ export interface $ZodPipe<A extends SomeType = $ZodType, B extends SomeType = $Z
|
|
|
962
962
|
}
|
|
963
963
|
export declare const $ZodPipe: core.$constructor<$ZodPipe>;
|
|
964
964
|
export interface $ZodCodecDef<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodPipeDef<A, B> {
|
|
965
|
-
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => core.input<B
|
|
966
|
-
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => core.output<A
|
|
965
|
+
transform: (value: core.output<A>, payload: ParsePayload<core.output<A>>) => util.MaybeAsync<core.input<B>>;
|
|
966
|
+
reverseTransform: (value: core.input<B>, payload: ParsePayload<core.input<B>>) => util.MaybeAsync<core.output<A>>;
|
|
967
967
|
}
|
|
968
968
|
export interface $ZodCodecInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<B>, core.input<A>> {
|
|
969
969
|
def: $ZodCodecDef<A, B>;
|
package/v4/core/schemas.js
CHANGED
|
@@ -833,7 +833,7 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
|
|
|
833
833
|
ids[key] = `key_${counter++}`;
|
|
834
834
|
}
|
|
835
835
|
// A: preserve key order {
|
|
836
|
-
doc.write(`const newResult = {}
|
|
836
|
+
doc.write(`const newResult = {};`);
|
|
837
837
|
for (const key of normalized.keys) {
|
|
838
838
|
const id = ids[key];
|
|
839
839
|
const k = util.esc(key);
|
|
@@ -846,6 +846,7 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
|
|
|
846
846
|
})));
|
|
847
847
|
}
|
|
848
848
|
|
|
849
|
+
|
|
849
850
|
if (${id}.value === undefined) {
|
|
850
851
|
if (${k} in input) {
|
|
851
852
|
newResult[${k}] = undefined;
|
|
@@ -853,6 +854,7 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
|
|
|
853
854
|
} else {
|
|
854
855
|
newResult[${k}] = ${id}.value;
|
|
855
856
|
}
|
|
857
|
+
|
|
856
858
|
`);
|
|
857
859
|
}
|
|
858
860
|
doc.write(`payload.value = newResult;`);
|
package/v4/core/versions.cjs
CHANGED
package/v4/core/versions.js
CHANGED
package/v4/mini/schemas.d.cts
CHANGED
|
@@ -326,8 +326,8 @@ export interface ZodMiniCodec<A extends SomeType = core.$ZodType, B extends Some
|
|
|
326
326
|
}
|
|
327
327
|
export declare const ZodMiniCodec: core.$constructor<ZodMiniCodec>;
|
|
328
328
|
export declare function codec<const A extends SomeType, B extends core.SomeType = core.$ZodType>(in_: A, out: B, params: {
|
|
329
|
-
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.input<B
|
|
330
|
-
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.output<A
|
|
329
|
+
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.util.MaybeAsync<core.input<B>>;
|
|
330
|
+
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
331
331
|
}): ZodMiniCodec<A, B>;
|
|
332
332
|
export interface ZodMiniReadonly<T extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodReadonlyInternals<T>> {
|
|
333
333
|
}
|
package/v4/mini/schemas.d.ts
CHANGED
|
@@ -326,8 +326,8 @@ export interface ZodMiniCodec<A extends SomeType = core.$ZodType, B extends Some
|
|
|
326
326
|
}
|
|
327
327
|
export declare const ZodMiniCodec: core.$constructor<ZodMiniCodec>;
|
|
328
328
|
export declare function codec<const A extends SomeType, B extends core.SomeType = core.$ZodType>(in_: A, out: B, params: {
|
|
329
|
-
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.input<B
|
|
330
|
-
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.output<A
|
|
329
|
+
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.util.MaybeAsync<core.input<B>>;
|
|
330
|
+
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
331
331
|
}): ZodMiniCodec<A, B>;
|
|
332
332
|
export interface ZodMiniReadonly<T extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodReadonlyInternals<T>> {
|
|
333
333
|
}
|