zod 4.3.0-canary.20251222T061611 → 4.3.0-canary.20251222T205904
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/v4/classic/schemas.ts +11 -1
- package/src/v4/classic/tests/brand.test.ts +43 -0
- package/src/v4/classic/tests/map.test.ts +134 -0
- package/src/v4/core/core.ts +10 -2
- package/src/v4/locales/en.ts +1 -0
- package/src/v4/mini/schemas.ts +2 -2
- package/src/v4/mini/tests/brand.test.ts +43 -0
- package/v4/classic/schemas.cjs +4 -0
- package/v4/classic/schemas.d.cts +5 -1
- package/v4/classic/schemas.d.ts +5 -1
- package/v4/classic/schemas.js +4 -0
- package/v4/core/core.d.cts +14 -1
- package/v4/core/core.d.ts +14 -1
- package/v4/locales/en.cjs +1 -0
- package/v4/locales/en.js +1 -0
- package/v4/mini/schemas.d.cts +1 -1
- package/v4/mini/schemas.d.ts +1 -1
package/package.json
CHANGED
|
@@ -48,7 +48,9 @@ export interface ZodType<
|
|
|
48
48
|
: ["Incompatible schema"]
|
|
49
49
|
): this;
|
|
50
50
|
|
|
51
|
-
brand<T extends PropertyKey = PropertyKey
|
|
51
|
+
brand<T extends PropertyKey = PropertyKey, Dir extends "in" | "out" | "inout" = "out">(
|
|
52
|
+
value?: T
|
|
53
|
+
): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>;
|
|
52
54
|
|
|
53
55
|
// parsing
|
|
54
56
|
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
|
|
@@ -1538,6 +1540,10 @@ export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends
|
|
|
1538
1540
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
1539
1541
|
keyType: Key;
|
|
1540
1542
|
valueType: Value;
|
|
1543
|
+
min(minSize: number, params?: string | core.$ZodCheckMinSizeParams): this;
|
|
1544
|
+
nonempty(params?: string | core.$ZodCheckMinSizeParams): this;
|
|
1545
|
+
max(maxSize: number, params?: string | core.$ZodCheckMaxSizeParams): this;
|
|
1546
|
+
size(size: number, params?: string | core.$ZodCheckSizeEqualsParams): this;
|
|
1541
1547
|
}
|
|
1542
1548
|
export const ZodMap: core.$constructor<ZodMap> = /*@__PURE__*/ core.$constructor("ZodMap", (inst, def) => {
|
|
1543
1549
|
core.$ZodMap.init(inst, def);
|
|
@@ -1545,6 +1551,10 @@ export const ZodMap: core.$constructor<ZodMap> = /*@__PURE__*/ core.$constructor
|
|
|
1545
1551
|
inst._zod.processJSONSchema = (ctx, json, params) => processors.mapProcessor(inst, ctx, json, params);
|
|
1546
1552
|
inst.keyType = def.keyType;
|
|
1547
1553
|
inst.valueType = def.valueType;
|
|
1554
|
+
inst.min = (...args) => inst.check(core._minSize(...args));
|
|
1555
|
+
inst.nonempty = (params) => inst.check(core._minSize(1, params));
|
|
1556
|
+
inst.max = (...args) => inst.check(core._maxSize(...args));
|
|
1557
|
+
inst.size = (...args) => inst.check(core._size(...args));
|
|
1548
1558
|
});
|
|
1549
1559
|
|
|
1550
1560
|
export function map<Key extends core.SomeType, Value extends core.SomeType>(
|
|
@@ -61,3 +61,46 @@ test("branded record", () => {
|
|
|
61
61
|
type recordWithBrandedNumberKeys = z.infer<typeof recordWithBrandedNumberKeys>;
|
|
62
62
|
expectTypeOf<recordWithBrandedNumberKeys>().toEqualTypeOf<Record<string & z.core.$brand<"SomeBrand">, number>>();
|
|
63
63
|
});
|
|
64
|
+
|
|
65
|
+
test("brand direction: out (default)", () => {
|
|
66
|
+
const schema = z.string().brand<"A">();
|
|
67
|
+
type Input = z.input<typeof schema>;
|
|
68
|
+
type Output = z.output<typeof schema>;
|
|
69
|
+
|
|
70
|
+
// output is branded
|
|
71
|
+
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
72
|
+
// input is NOT branded (default behavior)
|
|
73
|
+
expectTypeOf<Input>().toEqualTypeOf<string>();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("brand direction: out (explicit)", () => {
|
|
77
|
+
const schema = z.string().brand<"A", "out">();
|
|
78
|
+
type Input = z.input<typeof schema>;
|
|
79
|
+
type Output = z.output<typeof schema>;
|
|
80
|
+
|
|
81
|
+
// output is branded
|
|
82
|
+
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
83
|
+
// input is NOT branded
|
|
84
|
+
expectTypeOf<Input>().toEqualTypeOf<string>();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("brand direction: in", () => {
|
|
88
|
+
const schema = z.string().brand<"A", "in">();
|
|
89
|
+
type Input = z.input<typeof schema>;
|
|
90
|
+
type Output = z.output<typeof schema>;
|
|
91
|
+
|
|
92
|
+
// input is branded
|
|
93
|
+
expectTypeOf<Input>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
94
|
+
// output is NOT branded
|
|
95
|
+
expectTypeOf<Output>().toEqualTypeOf<string>();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("brand direction: inout", () => {
|
|
99
|
+
const schema = z.string().brand<"A", "inout">();
|
|
100
|
+
type Input = z.input<typeof schema>;
|
|
101
|
+
type Output = z.output<typeof schema>;
|
|
102
|
+
|
|
103
|
+
// both are branded
|
|
104
|
+
expectTypeOf<Input>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
105
|
+
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
106
|
+
});
|
|
@@ -4,6 +4,12 @@ import * as z from "zod/v4";
|
|
|
4
4
|
const stringMap = z.map(z.string(), z.string());
|
|
5
5
|
type stringMap = z.infer<typeof stringMap>;
|
|
6
6
|
|
|
7
|
+
const minTwo = stringMap.min(2);
|
|
8
|
+
const maxTwo = stringMap.max(2);
|
|
9
|
+
const justTwo = stringMap.size(2);
|
|
10
|
+
const nonEmpty = stringMap.nonempty();
|
|
11
|
+
const nonEmptyMax = stringMap.nonempty().max(2);
|
|
12
|
+
|
|
7
13
|
test("type inference", () => {
|
|
8
14
|
expectTypeOf<stringMap>().toEqualTypeOf<Map<string, string>>();
|
|
9
15
|
});
|
|
@@ -24,6 +30,75 @@ test("valid parse", () => {
|
|
|
24
30
|
`);
|
|
25
31
|
});
|
|
26
32
|
|
|
33
|
+
test("valid parse: size-related methods", () => {
|
|
34
|
+
expect(() => {
|
|
35
|
+
minTwo.parse(
|
|
36
|
+
new Map([
|
|
37
|
+
["a", "b"],
|
|
38
|
+
["c", "d"],
|
|
39
|
+
])
|
|
40
|
+
);
|
|
41
|
+
minTwo.parse(
|
|
42
|
+
new Map([
|
|
43
|
+
["a", "b"],
|
|
44
|
+
["c", "d"],
|
|
45
|
+
["e", "f"],
|
|
46
|
+
])
|
|
47
|
+
);
|
|
48
|
+
maxTwo.parse(
|
|
49
|
+
new Map([
|
|
50
|
+
["a", "b"],
|
|
51
|
+
["c", "d"],
|
|
52
|
+
])
|
|
53
|
+
);
|
|
54
|
+
maxTwo.parse(new Map([["a", "b"]]));
|
|
55
|
+
justTwo.parse(
|
|
56
|
+
new Map([
|
|
57
|
+
["a", "b"],
|
|
58
|
+
["c", "d"],
|
|
59
|
+
])
|
|
60
|
+
);
|
|
61
|
+
nonEmpty.parse(new Map([["a", "b"]]));
|
|
62
|
+
nonEmptyMax.parse(
|
|
63
|
+
new Map([
|
|
64
|
+
["a", "b"],
|
|
65
|
+
["c", "d"],
|
|
66
|
+
])
|
|
67
|
+
);
|
|
68
|
+
}).not.toThrow();
|
|
69
|
+
|
|
70
|
+
const sizeZeroResult = stringMap.parse(new Map());
|
|
71
|
+
expect(sizeZeroResult.size).toBe(0);
|
|
72
|
+
|
|
73
|
+
const sizeTwoResult = minTwo.parse(
|
|
74
|
+
new Map([
|
|
75
|
+
["a", "b"],
|
|
76
|
+
["c", "d"],
|
|
77
|
+
])
|
|
78
|
+
);
|
|
79
|
+
expect(sizeTwoResult.size).toBe(2);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("failing when parsing empty map in nonempty ", () => {
|
|
83
|
+
const result = nonEmpty.safeParse(new Map());
|
|
84
|
+
expect(result.success).toEqual(false);
|
|
85
|
+
expect(result.error!.issues.length).toEqual(1);
|
|
86
|
+
expect(result.error!.issues[0].code).toEqual("too_small");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("failing when map is bigger than max() ", () => {
|
|
90
|
+
const result = maxTwo.safeParse(
|
|
91
|
+
new Map([
|
|
92
|
+
["a", "b"],
|
|
93
|
+
["c", "d"],
|
|
94
|
+
["e", "f"],
|
|
95
|
+
])
|
|
96
|
+
);
|
|
97
|
+
expect(result.success).toEqual(false);
|
|
98
|
+
expect(result.error!.issues.length).toEqual(1);
|
|
99
|
+
expect(result.error!.issues[0].code).toEqual("too_big");
|
|
100
|
+
});
|
|
101
|
+
|
|
27
102
|
test("valid parse async", async () => {
|
|
28
103
|
const asyncMap = z.map(
|
|
29
104
|
z.string().refine(async () => false, "bad key"),
|
|
@@ -194,3 +269,62 @@ test("map with object keys", () => {
|
|
|
194
269
|
]]
|
|
195
270
|
`);
|
|
196
271
|
});
|
|
272
|
+
|
|
273
|
+
test("min/max", async () => {
|
|
274
|
+
const schema = stringMap.min(4).max(5);
|
|
275
|
+
|
|
276
|
+
const r1 = schema.safeParse(
|
|
277
|
+
new Map([
|
|
278
|
+
["a", "a"],
|
|
279
|
+
["b", "b"],
|
|
280
|
+
["c", "c"],
|
|
281
|
+
["d", "d"],
|
|
282
|
+
])
|
|
283
|
+
);
|
|
284
|
+
expect(r1.success).toEqual(true);
|
|
285
|
+
|
|
286
|
+
const r2 = schema.safeParse(
|
|
287
|
+
new Map([
|
|
288
|
+
["a", "a"],
|
|
289
|
+
["b", "b"],
|
|
290
|
+
["c", "c"],
|
|
291
|
+
])
|
|
292
|
+
);
|
|
293
|
+
expect(r2.success).toEqual(false);
|
|
294
|
+
expect(r2.error!.issues).toMatchInlineSnapshot(`
|
|
295
|
+
[
|
|
296
|
+
{
|
|
297
|
+
"code": "too_small",
|
|
298
|
+
"inclusive": true,
|
|
299
|
+
"message": "Too small: expected map to have >=4 entries",
|
|
300
|
+
"minimum": 4,
|
|
301
|
+
"origin": "map",
|
|
302
|
+
"path": [],
|
|
303
|
+
},
|
|
304
|
+
]
|
|
305
|
+
`);
|
|
306
|
+
|
|
307
|
+
const r3 = schema.safeParse(
|
|
308
|
+
new Map([
|
|
309
|
+
["a", "a"],
|
|
310
|
+
["b", "b"],
|
|
311
|
+
["c", "c"],
|
|
312
|
+
["d", "d"],
|
|
313
|
+
["e", "e"],
|
|
314
|
+
["f", "f"],
|
|
315
|
+
])
|
|
316
|
+
);
|
|
317
|
+
expect(r3.success).toEqual(false);
|
|
318
|
+
expect(r3.error!.issues).toMatchInlineSnapshot(`
|
|
319
|
+
[
|
|
320
|
+
{
|
|
321
|
+
"code": "too_big",
|
|
322
|
+
"inclusive": true,
|
|
323
|
+
"maximum": 5,
|
|
324
|
+
"message": "Too big: expected map to have <=5 entries",
|
|
325
|
+
"origin": "map",
|
|
326
|
+
"path": [],
|
|
327
|
+
},
|
|
328
|
+
]
|
|
329
|
+
`);
|
|
330
|
+
});
|
package/src/v4/core/core.ts
CHANGED
|
@@ -82,8 +82,16 @@ export type $brand<T extends string | number | symbol = string | number | symbol
|
|
|
82
82
|
[$brand]: { [k in T]: true };
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
export type $ZodBranded<
|
|
86
|
-
|
|
85
|
+
export type $ZodBranded<
|
|
86
|
+
T extends schemas.SomeType,
|
|
87
|
+
Brand extends string | number | symbol,
|
|
88
|
+
Dir extends "in" | "out" | "inout" = "out",
|
|
89
|
+
> = T &
|
|
90
|
+
(Dir extends "inout"
|
|
91
|
+
? { _zod: { input: input<T> & $brand<Brand>; output: output<T> & $brand<Brand> } }
|
|
92
|
+
: Dir extends "in"
|
|
93
|
+
? { _zod: { input: input<T> & $brand<Brand> } }
|
|
94
|
+
: { _zod: { output: output<T> & $brand<Brand> } });
|
|
87
95
|
|
|
88
96
|
export class $ZodAsyncError extends Error {
|
|
89
97
|
constructor() {
|
package/src/v4/locales/en.ts
CHANGED
|
@@ -31,6 +31,7 @@ const error: () => errors.$ZodErrorMap = () => {
|
|
|
31
31
|
file: { unit: "bytes", verb: "to have" },
|
|
32
32
|
array: { unit: "items", verb: "to have" },
|
|
33
33
|
set: { unit: "items", verb: "to have" },
|
|
34
|
+
map: { unit: "entries", verb: "to have" },
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
function getSizing(origin: string): { unit: string; verb: string } | null {
|
package/src/v4/mini/schemas.ts
CHANGED
|
@@ -20,9 +20,9 @@ export interface ZodMiniType<
|
|
|
20
20
|
: [core.$replace<R["_meta"], this>]
|
|
21
21
|
: ["Incompatible schema"]
|
|
22
22
|
): this;
|
|
23
|
-
brand<T extends PropertyKey = PropertyKey>(
|
|
23
|
+
brand<T extends PropertyKey = PropertyKey, Dir extends "in" | "out" | "inout" = "out">(
|
|
24
24
|
value?: T
|
|
25
|
-
): PropertyKey extends T ? this : this
|
|
25
|
+
): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>;
|
|
26
26
|
|
|
27
27
|
def: Internals["def"];
|
|
28
28
|
|
|
@@ -49,3 +49,46 @@ test("branded types", () => {
|
|
|
49
49
|
// @ts-expect-error
|
|
50
50
|
doStuff({ name: "hello there!" });
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
test("brand direction: out (default)", () => {
|
|
54
|
+
const schema = z.string().brand<"A">();
|
|
55
|
+
type Input = z.input<typeof schema>;
|
|
56
|
+
type Output = z.output<typeof schema>;
|
|
57
|
+
|
|
58
|
+
// output is branded
|
|
59
|
+
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
60
|
+
// input is NOT branded (default behavior)
|
|
61
|
+
expectTypeOf<Input>().toEqualTypeOf<string>();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("brand direction: out (explicit)", () => {
|
|
65
|
+
const schema = z.string().brand<"A", "out">();
|
|
66
|
+
type Input = z.input<typeof schema>;
|
|
67
|
+
type Output = z.output<typeof schema>;
|
|
68
|
+
|
|
69
|
+
// output is branded
|
|
70
|
+
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
71
|
+
// input is NOT branded
|
|
72
|
+
expectTypeOf<Input>().toEqualTypeOf<string>();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("brand direction: in", () => {
|
|
76
|
+
const schema = z.string().brand<"A", "in">();
|
|
77
|
+
type Input = z.input<typeof schema>;
|
|
78
|
+
type Output = z.output<typeof schema>;
|
|
79
|
+
|
|
80
|
+
// input is branded
|
|
81
|
+
expectTypeOf<Input>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
82
|
+
// output is NOT branded
|
|
83
|
+
expectTypeOf<Output>().toEqualTypeOf<string>();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("brand direction: inout", () => {
|
|
87
|
+
const schema = z.string().brand<"A", "inout">();
|
|
88
|
+
type Input = z.input<typeof schema>;
|
|
89
|
+
type Output = z.output<typeof schema>;
|
|
90
|
+
|
|
91
|
+
// both are branded
|
|
92
|
+
expectTypeOf<Input>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
93
|
+
expectTypeOf<Output>().toEqualTypeOf<string & z.$brand<"A">>();
|
|
94
|
+
});
|
package/v4/classic/schemas.cjs
CHANGED
|
@@ -826,6 +826,10 @@ exports.ZodMap = core.$constructor("ZodMap", (inst, def) => {
|
|
|
826
826
|
inst._zod.processJSONSchema = (ctx, json, params) => processors.mapProcessor(inst, ctx, json, params);
|
|
827
827
|
inst.keyType = def.keyType;
|
|
828
828
|
inst.valueType = def.valueType;
|
|
829
|
+
inst.min = (...args) => inst.check(core._minSize(...args));
|
|
830
|
+
inst.nonempty = (params) => inst.check(core._minSize(1, params));
|
|
831
|
+
inst.max = (...args) => inst.check(core._maxSize(...args));
|
|
832
|
+
inst.size = (...args) => inst.check(core._size(...args));
|
|
829
833
|
});
|
|
830
834
|
function map(keyType, valueType, params) {
|
|
831
835
|
return new exports.ZodMap({
|
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -20,7 +20,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
|
|
|
20
20
|
parent: boolean;
|
|
21
21
|
}): this;
|
|
22
22
|
register<R extends core.$ZodRegistry>(registry: R, ...meta: this extends R["_schema"] ? undefined extends R["_meta"] ? [core.$replace<R["_meta"], this>?] : [core.$replace<R["_meta"], this>] : ["Incompatible schema"]): this;
|
|
23
|
-
brand<T extends PropertyKey = PropertyKey>(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T>;
|
|
23
|
+
brand<T extends PropertyKey = PropertyKey, Dir extends "in" | "out" | "inout" = "out">(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>;
|
|
24
24
|
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
|
|
25
25
|
safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): parse.ZodSafeParseResult<core.output<this>>;
|
|
26
26
|
parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>;
|
|
@@ -514,6 +514,10 @@ export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends
|
|
|
514
514
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
515
515
|
keyType: Key;
|
|
516
516
|
valueType: Value;
|
|
517
|
+
min(minSize: number, params?: string | core.$ZodCheckMinSizeParams): this;
|
|
518
|
+
nonempty(params?: string | core.$ZodCheckMinSizeParams): this;
|
|
519
|
+
max(maxSize: number, params?: string | core.$ZodCheckMaxSizeParams): this;
|
|
520
|
+
size(size: number, params?: string | core.$ZodCheckSizeEqualsParams): this;
|
|
517
521
|
}
|
|
518
522
|
export declare const ZodMap: core.$constructor<ZodMap>;
|
|
519
523
|
export declare function map<Key extends core.SomeType, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodMapParams): ZodMap<Key, Value>;
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
|
|
|
20
20
|
parent: boolean;
|
|
21
21
|
}): this;
|
|
22
22
|
register<R extends core.$ZodRegistry>(registry: R, ...meta: this extends R["_schema"] ? undefined extends R["_meta"] ? [core.$replace<R["_meta"], this>?] : [core.$replace<R["_meta"], this>] : ["Incompatible schema"]): this;
|
|
23
|
-
brand<T extends PropertyKey = PropertyKey>(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T>;
|
|
23
|
+
brand<T extends PropertyKey = PropertyKey, Dir extends "in" | "out" | "inout" = "out">(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>;
|
|
24
24
|
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
|
|
25
25
|
safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): parse.ZodSafeParseResult<core.output<this>>;
|
|
26
26
|
parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>;
|
|
@@ -514,6 +514,10 @@ export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends
|
|
|
514
514
|
"~standard": ZodStandardSchemaWithJSON<this>;
|
|
515
515
|
keyType: Key;
|
|
516
516
|
valueType: Value;
|
|
517
|
+
min(minSize: number, params?: string | core.$ZodCheckMinSizeParams): this;
|
|
518
|
+
nonempty(params?: string | core.$ZodCheckMinSizeParams): this;
|
|
519
|
+
max(maxSize: number, params?: string | core.$ZodCheckMaxSizeParams): this;
|
|
520
|
+
size(size: number, params?: string | core.$ZodCheckSizeEqualsParams): this;
|
|
517
521
|
}
|
|
518
522
|
export declare const ZodMap: core.$constructor<ZodMap>;
|
|
519
523
|
export declare function map<Key extends core.SomeType, Value extends core.SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodMapParams): ZodMap<Key, Value>;
|
package/v4/classic/schemas.js
CHANGED
|
@@ -709,6 +709,10 @@ export const ZodMap = /*@__PURE__*/ core.$constructor("ZodMap", (inst, def) => {
|
|
|
709
709
|
inst._zod.processJSONSchema = (ctx, json, params) => processors.mapProcessor(inst, ctx, json, params);
|
|
710
710
|
inst.keyType = def.keyType;
|
|
711
711
|
inst.valueType = def.valueType;
|
|
712
|
+
inst.min = (...args) => inst.check(core._minSize(...args));
|
|
713
|
+
inst.nonempty = (params) => inst.check(core._minSize(1, params));
|
|
714
|
+
inst.max = (...args) => inst.check(core._maxSize(...args));
|
|
715
|
+
inst.size = (...args) => inst.check(core._size(...args));
|
|
712
716
|
});
|
|
713
717
|
export function map(keyType, valueType, params) {
|
|
714
718
|
return new ZodMap({
|
package/v4/core/core.d.cts
CHANGED
|
@@ -22,7 +22,20 @@ export type $brand<T extends string | number | symbol = string | number | symbol
|
|
|
22
22
|
[k in T]: true;
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
export type $ZodBranded<T extends schemas.SomeType, Brand extends string | number | symbol
|
|
25
|
+
export type $ZodBranded<T extends schemas.SomeType, Brand extends string | number | symbol, Dir extends "in" | "out" | "inout" = "out"> = T & (Dir extends "inout" ? {
|
|
26
|
+
_zod: {
|
|
27
|
+
input: input<T> & $brand<Brand>;
|
|
28
|
+
output: output<T> & $brand<Brand>;
|
|
29
|
+
};
|
|
30
|
+
} : Dir extends "in" ? {
|
|
31
|
+
_zod: {
|
|
32
|
+
input: input<T> & $brand<Brand>;
|
|
33
|
+
};
|
|
34
|
+
} : {
|
|
35
|
+
_zod: {
|
|
36
|
+
output: output<T> & $brand<Brand>;
|
|
37
|
+
};
|
|
38
|
+
});
|
|
26
39
|
export declare class $ZodAsyncError extends Error {
|
|
27
40
|
constructor();
|
|
28
41
|
}
|
package/v4/core/core.d.ts
CHANGED
|
@@ -22,7 +22,20 @@ export type $brand<T extends string | number | symbol = string | number | symbol
|
|
|
22
22
|
[k in T]: true;
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
export type $ZodBranded<T extends schemas.SomeType, Brand extends string | number | symbol
|
|
25
|
+
export type $ZodBranded<T extends schemas.SomeType, Brand extends string | number | symbol, Dir extends "in" | "out" | "inout" = "out"> = T & (Dir extends "inout" ? {
|
|
26
|
+
_zod: {
|
|
27
|
+
input: input<T> & $brand<Brand>;
|
|
28
|
+
output: output<T> & $brand<Brand>;
|
|
29
|
+
};
|
|
30
|
+
} : Dir extends "in" ? {
|
|
31
|
+
_zod: {
|
|
32
|
+
input: input<T> & $brand<Brand>;
|
|
33
|
+
};
|
|
34
|
+
} : {
|
|
35
|
+
_zod: {
|
|
36
|
+
output: output<T> & $brand<Brand>;
|
|
37
|
+
};
|
|
38
|
+
});
|
|
26
39
|
export declare class $ZodAsyncError extends Error {
|
|
27
40
|
constructor();
|
|
28
41
|
}
|
package/v4/locales/en.cjs
CHANGED
|
@@ -53,6 +53,7 @@ const error = () => {
|
|
|
53
53
|
file: { unit: "bytes", verb: "to have" },
|
|
54
54
|
array: { unit: "items", verb: "to have" },
|
|
55
55
|
set: { unit: "items", verb: "to have" },
|
|
56
|
+
map: { unit: "entries", verb: "to have" },
|
|
56
57
|
};
|
|
57
58
|
function getSizing(origin) {
|
|
58
59
|
return Sizable[origin] ?? null;
|
package/v4/locales/en.js
CHANGED
|
@@ -25,6 +25,7 @@ const error = () => {
|
|
|
25
25
|
file: { unit: "bytes", verb: "to have" },
|
|
26
26
|
array: { unit: "items", verb: "to have" },
|
|
27
27
|
set: { unit: "items", verb: "to have" },
|
|
28
|
+
map: { unit: "entries", verb: "to have" },
|
|
28
29
|
};
|
|
29
30
|
function getSizing(origin) {
|
|
30
31
|
return Sizable[origin] ?? null;
|
package/v4/mini/schemas.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ export interface ZodMiniType<out Output = unknown, out Input = unknown, out Inte
|
|
|
8
8
|
parent: boolean;
|
|
9
9
|
}): this;
|
|
10
10
|
register<R extends core.$ZodRegistry>(registry: R, ...meta: this extends R["_schema"] ? undefined extends R["_meta"] ? [core.$replace<R["_meta"], this>?] : [core.$replace<R["_meta"], this>] : ["Incompatible schema"]): this;
|
|
11
|
-
brand<T extends PropertyKey = PropertyKey>(value?: T): PropertyKey extends T ? this : this
|
|
11
|
+
brand<T extends PropertyKey = PropertyKey, Dir extends "in" | "out" | "inout" = "out">(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>;
|
|
12
12
|
def: Internals["def"];
|
|
13
13
|
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
|
|
14
14
|
safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): util.SafeParseResult<core.output<this>>;
|
package/v4/mini/schemas.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface ZodMiniType<out Output = unknown, out Input = unknown, out Inte
|
|
|
8
8
|
parent: boolean;
|
|
9
9
|
}): this;
|
|
10
10
|
register<R extends core.$ZodRegistry>(registry: R, ...meta: this extends R["_schema"] ? undefined extends R["_meta"] ? [core.$replace<R["_meta"], this>?] : [core.$replace<R["_meta"], this>] : ["Incompatible schema"]): this;
|
|
11
|
-
brand<T extends PropertyKey = PropertyKey>(value?: T): PropertyKey extends T ? this : this
|
|
11
|
+
brand<T extends PropertyKey = PropertyKey, Dir extends "in" | "out" | "inout" = "out">(value?: T): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>;
|
|
12
12
|
def: Internals["def"];
|
|
13
13
|
parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>;
|
|
14
14
|
safeParse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): util.SafeParseResult<core.output<this>>;
|