Skip to content

Commit 5ebfb93

Browse files
Merge branch 'v4' into i18n/zh-tw
2 parents a9cf234 + 3d869ad commit 5ebfb93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2821
-5071
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
"**/dist": true,
1616
"**/lib": true
1717
},
18-
"search.exclude": {
19-
"./scratch": false
20-
},
2118
"search.useIgnoreFiles": false,
2219
"editor.guides.indentation": false
2320
}

biome.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
34
"formatter": {
45
"enabled": true,
56
"indentStyle": "space",

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@
4444
"zod3": "npm:zod@^3.0.0"
4545
},
4646
"lint-staged": {
47-
"packages/*/src/**/*.ts": ["biome format --write", "biome lint --write"],
48-
"packages/*/**/*.json": ["biome format --write", "biome lint --write"],
47+
"packages/*/src/**/*.ts": [
48+
"biome format --no-errors-on-unmatched --write",
49+
"biome lint --no-errors-on-unmatched --write"
50+
],
51+
"packages/*/**/*.json": [
52+
"biome format --no-errors-on-unmatched --write",
53+
"biome lint --no-errors-on-unmatched --write"
54+
],
4955
"packages/*/**/*.md": ["prettier --ignore-unknown --write"]
5056
},
5157
"scripts": {

packages/bench/error-handling.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { makeData, makeSchema } from "./benchUtil.js";
2+
import { metabench } from "./metabench.js";
3+
4+
import * as z4 from "zod4";
5+
import * as z from "zod";
6+
7+
const a = z4.object({ a: z4.string() });
8+
const b = z.object({ a: z.string() });
9+
10+
const DATA = makeData(10000, () => ({ b: `${Math.random()}` }));
11+
12+
const bench = metabench("safeparse error", {
13+
zod4() {
14+
for (const _ of DATA) {
15+
try{a.safeParse(_);} catch(e){e;}
16+
}
17+
},
18+
zod4new() {
19+
for (const _ of DATA) {
20+
try{b.safeParse(_);} catch(e){e;}
21+
}
22+
}
23+
});
24+
25+
await bench.run();

packages/bench/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
"valibot": "^1.0.0",
1010
"zod": "workspace:*",
1111
"zod3": "npm:zod@^3.23.7"
12+
},
13+
"scripts": {
14+
"bench": "tsx --conditions @zod/source index.ts"
1215
}
1316
}

packages/core/src/api.ts

Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,130 +1005,7 @@ export function _array<T extends schemas.$ZodType>(
10051005
}) as schemas.$ZodArray<T>;
10061006
}
10071007

1008-
// ZodObjectLike
1009-
export type $ZodObjectLikeParams = util.TypeParams<schemas.$ZodObjectLike, "shape" | "catchall">;
1010-
1011-
export type $ZodInterfaceParams = util.TypeParams<schemas.$ZodInterface, "shape">;
1012-
export function _interface<T extends schemas.$ZodLooseShape>(
1013-
Class: util.SchemaClass<schemas.$ZodInterface>,
1014-
shape: T,
1015-
params?: $ZodInterfaceParams
1016-
): schemas.$ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, {}>> {
1017-
const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1018-
const def: schemas.$ZodInterfaceDef = {
1019-
type: "interface",
1020-
get shape() {
1021-
const _shape = cleaned.value.shape;
1022-
util.assignProp(this, "shape", _shape);
1023-
return _shape;
1024-
// return cleaned.value.shape;
1025-
},
1026-
get optional() {
1027-
return cleaned.value.optional;
1028-
},
1029-
...util.normalizeParams(params),
1030-
};
1031-
return new Class(def) as any;
1032-
}
1033-
1034-
// strictInterface
1035-
export function _strictInterface<T extends schemas.$ZodLooseShape>(
1036-
Class: util.SchemaClass<schemas.$ZodInterface>,
1037-
shape: T,
1038-
params?: $ZodInterfaceParams
1039-
): schemas.$ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, {}>> {
1040-
const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1041-
const def: schemas.$ZodInterfaceDef = {
1042-
type: "interface",
1043-
get shape() {
1044-
const _shape = cleaned.value.shape;
1045-
util.assignProp(this, "shape", _shape);
1046-
return _shape;
1047-
// return cleaned.value.shape;
1048-
},
1049-
get optional() {
1050-
return cleaned.value.optional;
1051-
},
1052-
catchall: _never(schemas.$ZodNever),
1053-
...util.normalizeParams(params),
1054-
};
1055-
return new Class(def) as any;
1056-
}
1057-
1058-
// looseInterface
1059-
export function _looseInterface<T extends schemas.$ZodLooseShape>(
1060-
Class: util.SchemaClass<schemas.$ZodInterface>,
1061-
shape: T,
1062-
params?: $ZodInterfaceParams
1063-
): schemas.$ZodInterface<util.CleanInterfaceShape<T>, util.InitInterfaceParams<T, Record<string, unknown>>> {
1064-
const cleaned = util.cached(() => util.cleanInterfaceShape(shape));
1065-
const def: schemas.$ZodInterfaceDef = {
1066-
type: "interface",
1067-
get optional() {
1068-
return cleaned.value.optional;
1069-
},
1070-
get shape() {
1071-
const _shape = cleaned.value.shape;
1072-
util.assignProp(this, "shape", _shape);
1073-
return _shape;
1074-
// return cleaned.value.shape;
1075-
},
1076-
catchall: _unknown(schemas.$ZodUnknown),
1077-
...util.normalizeParams(params),
1078-
};
1079-
return new Class(def) as any;
1080-
}
1081-
10821008
export type $ZodObjectParams = util.TypeParams<schemas.$ZodObject, "shape" | "catchall">;
1083-
export function _object<T extends schemas.$ZodShape = Record<never, schemas.$ZodObject>>(
1084-
Class: util.SchemaClass<schemas.$ZodObject>,
1085-
shape?: T,
1086-
params?: $ZodObjectLikeParams
1087-
): schemas.$ZodObject<T, {}> {
1088-
const def: schemas.$ZodObjectDef = {
1089-
type: "object",
1090-
shape: shape ?? {},
1091-
get optional() {
1092-
return util.optionalObjectKeys(shape ?? {});
1093-
},
1094-
...util.normalizeParams(params),
1095-
};
1096-
return new Class(def) as any;
1097-
}
1098-
1099-
// strictObject
1100-
export function _strictObject<T extends schemas.$ZodShape>(
1101-
Class: util.SchemaClass<schemas.$ZodObject>,
1102-
shape: T,
1103-
params?: $ZodObjectParams
1104-
): schemas.$ZodObject<T, {}> {
1105-
return new Class({
1106-
type: "object",
1107-
shape: shape as schemas.$ZodShape,
1108-
get optional() {
1109-
return util.optionalObjectKeys(shape);
1110-
},
1111-
catchall: _never(schemas.$ZodNever),
1112-
...util.normalizeParams(params),
1113-
}) as any;
1114-
}
1115-
1116-
// looseObject
1117-
export function _looseObject<T extends schemas.$ZodShape>(
1118-
Class: util.SchemaClass<schemas.$ZodObject>,
1119-
shape: T,
1120-
params?: $ZodObjectParams
1121-
): schemas.$ZodObject<T, { [k: string]: unknown }> {
1122-
return new Class({
1123-
type: "object",
1124-
shape: shape as schemas.$ZodShape,
1125-
get optional() {
1126-
return util.optionalObjectKeys(shape);
1127-
},
1128-
catchall: _unknown(schemas.$ZodUnknown),
1129-
...util.normalizeParams(params),
1130-
}) as any;
1131-
}
11321009

11331010
// ZodUnion
11341011
export type $ZodUnionParams = util.TypeParams<schemas.$ZodUnion, "options">;
@@ -1609,6 +1486,7 @@ export function _stringbool(
16091486
def: {
16101487
check: "custom",
16111488
},
1489+
onattach: [],
16121490
},
16131491
},
16141492
],

0 commit comments

Comments
 (0)