@hookform/resolvers 5.4.1 → 5.4.3
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/arktype/src/__tests__/__snapshots__/arktype.ts.snap +11 -11
- package/arktype/src/__tests__/arktype.ts +15 -6
- package/computed-types/src/__tests__/computed-types.ts +15 -6
- package/effect-ts/src/__tests__/effect-ts.ts +15 -6
- package/io-ts/src/__tests__/io-ts.ts +15 -6
- package/package.json +1 -1
- package/standard-schema/dist/standard-schema.js +1 -1
- package/standard-schema/dist/standard-schema.js.map +1 -1
- package/standard-schema/dist/standard-schema.mjs +1 -1
- package/standard-schema/dist/standard-schema.modern.mjs +1 -1
- package/standard-schema/dist/standard-schema.modern.mjs.map +1 -1
- package/standard-schema/dist/standard-schema.module.js +1 -1
- package/standard-schema/dist/standard-schema.module.js.map +1 -1
- package/standard-schema/dist/standard-schema.umd.js +1 -1
- package/standard-schema/dist/standard-schema.umd.js.map +1 -1
- package/standard-schema/src/__tests__/__snapshots__/standard-schema.ts.snap +31 -0
- package/standard-schema/src/__tests__/standard-schema.ts +126 -13
- package/standard-schema/src/standard-schema.ts +62 -14
- package/superstruct/dist/superstruct.d.ts +5 -0
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/src/__tests__/superstruct.ts +22 -8
- package/superstruct/src/superstruct.ts +13 -0
- package/typanion/src/__tests__/typanion.ts +8 -3
- package/typebox/src/__tests__/typebox.ts +31 -18
- package/typeschema/dist/typeschema.js +1 -1
- package/typeschema/dist/typeschema.js.map +1 -1
- package/typeschema/dist/typeschema.mjs +1 -1
- package/typeschema/dist/typeschema.modern.mjs +1 -1
- package/typeschema/dist/typeschema.modern.mjs.map +1 -1
- package/typeschema/dist/typeschema.module.js +1 -1
- package/typeschema/dist/typeschema.module.js.map +1 -1
- package/typeschema/dist/typeschema.umd.js +1 -1
- package/typeschema/dist/typeschema.umd.js.map +1 -1
- package/typeschema/src/__tests__/typeschema.ts +23 -15
- package/typeschema/src/typeschema.ts +6 -6
- package/valibot/src/__tests__/valibot.ts +15 -6
- package/vine/src/__tests__/vine.ts +15 -6
- package/yup/dist/yup.d.ts +2 -2
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/yup.ts +15 -6
- package/yup/src/yup.ts +10 -2
- package/zod/dist/zod.d.ts +8 -2
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/__snapshots__/zod-v3.ts.snap +430 -0
- package/zod/src/__tests__/__snapshots__/zod-v4-mini.ts.snap +472 -0
- package/zod/src/__tests__/__snapshots__/zod-v4.ts.snap +434 -0
- package/zod/src/__tests__/zod-v3.ts +45 -6
- package/zod/src/__tests__/zod-v4-mini.ts +21 -11
- package/zod/src/__tests__/zod-v4.ts +47 -11
- package/zod/src/zod.ts +28 -5
package/zod/src/zod.ts
CHANGED
|
@@ -40,7 +40,14 @@ function parseZod3Issues(
|
|
|
40
40
|
|
|
41
41
|
if (!errors[_path]) {
|
|
42
42
|
if ('unionErrors' in error) {
|
|
43
|
-
|
|
43
|
+
// Surface the error from whichever union member came closest to
|
|
44
|
+
// matching (fewest issues), rather than always the first member —
|
|
45
|
+
// the first member isn't necessarily the one the input was meant for.
|
|
46
|
+
const closestUnionError = error.unionErrors.reduce(
|
|
47
|
+
(closest, current) =>
|
|
48
|
+
current.errors.length < closest.errors.length ? current : closest,
|
|
49
|
+
);
|
|
50
|
+
const unionError = closestUnionError.errors[0];
|
|
44
51
|
|
|
45
52
|
errors[_path] = {
|
|
46
53
|
message: unionError.message,
|
|
@@ -91,7 +98,13 @@ function parseZod4Issues(
|
|
|
91
98
|
|
|
92
99
|
if (!errors[_path]) {
|
|
93
100
|
if (error.code === 'invalid_union' && error.errors.length > 0) {
|
|
94
|
-
|
|
101
|
+
// Surface the error from whichever union member came closest to
|
|
102
|
+
// matching (fewest issues), rather than always the first member —
|
|
103
|
+
// the first member isn't necessarily the one the input was meant for.
|
|
104
|
+
const closestBranch = error.errors.reduce((closest, branch) =>
|
|
105
|
+
branch.length < closest.length ? branch : closest,
|
|
106
|
+
);
|
|
107
|
+
const unionError = closestBranch[0];
|
|
95
108
|
|
|
96
109
|
errors[_path] = {
|
|
97
110
|
message: unionError.message,
|
|
@@ -149,6 +162,16 @@ interface Zod3Type<O = unknown, I = unknown> {
|
|
|
149
162
|
};
|
|
150
163
|
}
|
|
151
164
|
|
|
165
|
+
// minimal interface to avoid assignability issues between zod v4 patch/minor
|
|
166
|
+
// releases, which brand the full `$ZodType` shape with an exact version literal
|
|
167
|
+
// (e.g. `_zod.version.minor`)
|
|
168
|
+
interface Zod4Type<Output = unknown, Input = unknown> {
|
|
169
|
+
_zod: {
|
|
170
|
+
output: Output;
|
|
171
|
+
input: Input;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
152
175
|
// some type magic to make versions pre-3.25.0 still work
|
|
153
176
|
type IsUnresolved<T> = PropertyKey extends keyof T ? true : false;
|
|
154
177
|
type UnresolvedFallback<T, Fallback> = IsUnresolved<typeof z3> extends true
|
|
@@ -201,7 +224,7 @@ export function zodResolver<
|
|
|
201
224
|
Input extends FieldValues,
|
|
202
225
|
Context,
|
|
203
226
|
Output,
|
|
204
|
-
T extends
|
|
227
|
+
T extends Zod4Type<Output, Input> = Zod4Type<Output, Input>,
|
|
205
228
|
>(
|
|
206
229
|
schema: T,
|
|
207
230
|
schemaOptions?: Zod4ParseParams, // already partial
|
|
@@ -211,9 +234,9 @@ export function zodResolver<
|
|
|
211
234
|
Input extends FieldValues,
|
|
212
235
|
Context,
|
|
213
236
|
Output,
|
|
214
|
-
T extends
|
|
237
|
+
T extends Zod4Type<Output, Input> = Zod4Type<Output, Input>,
|
|
215
238
|
>(
|
|
216
|
-
schema:
|
|
239
|
+
schema: Zod4Type<Output, Input>,
|
|
217
240
|
schemaOptions: Zod4ParseParams | undefined, // already partial
|
|
218
241
|
resolverOptions: RawResolverOptions,
|
|
219
242
|
): Resolver<z4.input<T>, Context, z4.input<T>>;
|