@hookform/resolvers 4.1.2 → 5.0.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.
Files changed (159) hide show
  1. package/README.md +30 -0
  2. package/ajv/package.json +1 -1
  3. package/arktype/dist/arktype.d.ts +8 -20
  4. package/arktype/dist/arktype.js +1 -1
  5. package/arktype/dist/arktype.js.map +1 -1
  6. package/arktype/dist/arktype.mjs +1 -1
  7. package/arktype/dist/arktype.modern.mjs +1 -1
  8. package/arktype/dist/arktype.modern.mjs.map +1 -1
  9. package/arktype/dist/arktype.module.js +1 -1
  10. package/arktype/dist/arktype.module.js.map +1 -1
  11. package/arktype/dist/arktype.umd.js +1 -1
  12. package/arktype/dist/arktype.umd.js.map +1 -1
  13. package/arktype/package.json +1 -1
  14. package/arktype/src/__tests__/Form.tsx +0 -28
  15. package/arktype/src/__tests__/arktype.ts +56 -0
  16. package/arktype/src/arktype.ts +58 -22
  17. package/class-validator/src/__tests__/Form.tsx +0 -26
  18. package/computed-types/dist/computed-types.d.ts +2 -3
  19. package/computed-types/dist/computed-types.js.map +1 -1
  20. package/computed-types/dist/computed-types.modern.mjs.map +1 -1
  21. package/computed-types/dist/computed-types.module.js.map +1 -1
  22. package/computed-types/dist/computed-types.umd.js.map +1 -1
  23. package/computed-types/package.json +1 -1
  24. package/computed-types/src/__tests__/Form.tsx +0 -28
  25. package/computed-types/src/__tests__/computed-types.ts +55 -1
  26. package/computed-types/src/computed-types.ts +7 -5
  27. package/dist/resolvers.js +1 -1
  28. package/dist/resolvers.js.map +1 -1
  29. package/dist/resolvers.mjs +1 -1
  30. package/dist/resolvers.mjs.map +1 -1
  31. package/dist/resolvers.module.js +1 -1
  32. package/dist/resolvers.module.js.map +1 -1
  33. package/dist/resolvers.umd.js +1 -1
  34. package/dist/resolvers.umd.js.map +1 -1
  35. package/effect-ts/dist/effect-ts.d.ts +8 -16
  36. package/effect-ts/dist/effect-ts.js.map +1 -1
  37. package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
  38. package/effect-ts/dist/effect-ts.module.js.map +1 -1
  39. package/effect-ts/dist/effect-ts.umd.js.map +1 -1
  40. package/effect-ts/package.json +1 -1
  41. package/effect-ts/src/__tests__/effect-ts.ts +61 -0
  42. package/effect-ts/src/effect-ts.ts +21 -3
  43. package/fluentvalidation-ts/package.json +1 -1
  44. package/io-ts/dist/io-ts.d.ts +8 -17
  45. package/io-ts/dist/io-ts.js.map +1 -1
  46. package/io-ts/dist/io-ts.modern.mjs.map +1 -1
  47. package/io-ts/dist/io-ts.module.js.map +1 -1
  48. package/io-ts/dist/io-ts.umd.js.map +1 -1
  49. package/io-ts/package.json +1 -1
  50. package/io-ts/src/__tests__/__fixtures__/data.ts +3 -3
  51. package/io-ts/src/__tests__/io-ts.ts +54 -0
  52. package/io-ts/src/io-ts.ts +35 -8
  53. package/joi/package.json +1 -1
  54. package/nope/package.json +1 -1
  55. package/package.json +13 -13
  56. package/standard-schema/dist/standard-schema.d.ts +6 -23
  57. package/standard-schema/dist/standard-schema.js +1 -1
  58. package/standard-schema/dist/standard-schema.js.map +1 -1
  59. package/standard-schema/dist/standard-schema.mjs +1 -1
  60. package/standard-schema/dist/standard-schema.modern.mjs +1 -1
  61. package/standard-schema/dist/standard-schema.modern.mjs.map +1 -1
  62. package/standard-schema/dist/standard-schema.module.js +1 -1
  63. package/standard-schema/dist/standard-schema.module.js.map +1 -1
  64. package/standard-schema/dist/standard-schema.umd.js +1 -1
  65. package/standard-schema/dist/standard-schema.umd.js.map +1 -1
  66. package/standard-schema/package.json +1 -1
  67. package/standard-schema/src/__tests__/Form.tsx +0 -28
  68. package/standard-schema/src/__tests__/__fixtures__/data.ts +2 -2
  69. package/standard-schema/src/__tests__/standard-schema.ts +78 -1
  70. package/standard-schema/src/standard-schema.ts +32 -5
  71. package/superstruct/dist/superstruct.d.ts +6 -20
  72. package/superstruct/dist/superstruct.js.map +1 -1
  73. package/superstruct/dist/superstruct.modern.mjs.map +1 -1
  74. package/superstruct/dist/superstruct.module.js.map +1 -1
  75. package/superstruct/dist/superstruct.umd.js.map +1 -1
  76. package/superstruct/package.json +1 -1
  77. package/superstruct/src/__tests__/superstruct.ts +60 -0
  78. package/superstruct/src/superstruct.ts +20 -4
  79. package/typanion/dist/typanion.d.ts +8 -16
  80. package/typanion/dist/typanion.js.map +1 -1
  81. package/typanion/dist/typanion.modern.mjs.map +1 -1
  82. package/typanion/dist/typanion.module.js.map +1 -1
  83. package/typanion/dist/typanion.umd.js.map +1 -1
  84. package/typanion/package.json +1 -1
  85. package/typanion/src/__tests__/Form.tsx +0 -32
  86. package/typanion/src/__tests__/typanion.ts +49 -0
  87. package/typanion/src/typanion.ts +22 -4
  88. package/typebox/dist/typebox.d.ts +3 -3
  89. package/typebox/dist/typebox.js.map +1 -1
  90. package/typebox/dist/typebox.modern.mjs.map +1 -1
  91. package/typebox/dist/typebox.module.js.map +1 -1
  92. package/typebox/dist/typebox.umd.js.map +1 -1
  93. package/typebox/package.json +1 -1
  94. package/typebox/src/__tests__/Form-native-validation-compiler.tsx +1 -1
  95. package/typebox/src/__tests__/Form.tsx +0 -28
  96. package/typebox/src/__tests__/__fixtures__/data.ts +3 -3
  97. package/typebox/src/__tests__/typebox.ts +98 -0
  98. package/typebox/src/typebox.ts +7 -14
  99. package/typeschema/dist/index.d.ts +0 -1
  100. package/typeschema/dist/typeschema.d.ts +8 -19
  101. package/typeschema/dist/typeschema.js +1 -1
  102. package/typeschema/dist/typeschema.js.map +1 -1
  103. package/typeschema/dist/typeschema.mjs +1 -1
  104. package/typeschema/dist/typeschema.modern.mjs +1 -1
  105. package/typeschema/dist/typeschema.modern.mjs.map +1 -1
  106. package/typeschema/dist/typeschema.module.js +1 -1
  107. package/typeschema/dist/typeschema.module.js.map +1 -1
  108. package/typeschema/dist/typeschema.umd.js +1 -1
  109. package/typeschema/dist/typeschema.umd.js.map +1 -1
  110. package/typeschema/package.json +1 -1
  111. package/typeschema/src/__tests__/Form.tsx +2 -4
  112. package/typeschema/src/__tests__/__fixtures__/data.ts +1 -1
  113. package/typeschema/src/__tests__/typeschema.ts +77 -0
  114. package/typeschema/src/index.ts +0 -1
  115. package/typeschema/src/typeschema.ts +52 -25
  116. package/valibot/dist/valibot.d.ts +9 -30
  117. package/valibot/dist/valibot.js.map +1 -1
  118. package/valibot/dist/valibot.modern.mjs.map +1 -1
  119. package/valibot/dist/valibot.module.js.map +1 -1
  120. package/valibot/dist/valibot.umd.js.map +1 -1
  121. package/valibot/package.json +1 -1
  122. package/valibot/src/__tests__/valibot.ts +69 -3
  123. package/valibot/src/valibot.ts +29 -13
  124. package/vest/package.json +1 -1
  125. package/vine/dist/vine.d.ts +10 -24
  126. package/vine/dist/vine.js.map +1 -1
  127. package/vine/dist/vine.modern.mjs.map +1 -1
  128. package/vine/dist/vine.module.js.map +1 -1
  129. package/vine/dist/vine.umd.js.map +1 -1
  130. package/vine/package.json +1 -1
  131. package/vine/src/__tests__/Form.tsx +0 -28
  132. package/vine/src/__tests__/__fixtures__/data.ts +4 -4
  133. package/vine/src/__tests__/vine.ts +69 -0
  134. package/vine/src/vine.ts +26 -4
  135. package/yup/dist/yup.d.ts +7 -21
  136. package/yup/dist/yup.js +1 -1
  137. package/yup/dist/yup.js.map +1 -1
  138. package/yup/dist/yup.mjs +1 -1
  139. package/yup/dist/yup.modern.mjs +1 -1
  140. package/yup/dist/yup.modern.mjs.map +1 -1
  141. package/yup/dist/yup.module.js +1 -1
  142. package/yup/dist/yup.module.js.map +1 -1
  143. package/yup/dist/yup.umd.js +1 -1
  144. package/yup/dist/yup.umd.js.map +1 -1
  145. package/yup/package.json +1 -1
  146. package/yup/src/__tests__/yup.ts +66 -0
  147. package/yup/src/yup.ts +30 -8
  148. package/zod/dist/zod.d.ts +7 -22
  149. package/zod/dist/zod.js.map +1 -1
  150. package/zod/dist/zod.modern.mjs.map +1 -1
  151. package/zod/dist/zod.module.js.map +1 -1
  152. package/zod/dist/zod.umd.js.map +1 -1
  153. package/zod/package.json +1 -1
  154. package/zod/src/__tests__/Form.tsx +0 -28
  155. package/zod/src/__tests__/__fixtures__/data.ts +2 -2
  156. package/zod/src/__tests__/zod.ts +69 -0
  157. package/zod/src/zod.ts +29 -9
  158. package/typeschema/dist/types.d.ts +0 -9
  159. package/typeschema/src/types.ts +0 -18
package/zod/src/zod.ts CHANGED
@@ -4,6 +4,8 @@ import {
4
4
  FieldErrors,
5
5
  FieldValues,
6
6
  Resolver,
7
+ ResolverError,
8
+ ResolverSuccess,
7
9
  appendErrors,
8
10
  } from 'react-hook-form';
9
11
  import { ZodError, z } from 'zod';
@@ -61,14 +63,32 @@ function parseErrorSchema(
61
63
  return errors;
62
64
  }
63
65
 
66
+ export function zodResolver<Input extends FieldValues, Context, Output>(
67
+ schema: z.ZodSchema<Output, any, Input>,
68
+ schemaOptions?: Partial<z.ParseParams>,
69
+ resolverOptions?: {
70
+ mode?: 'async' | 'sync';
71
+ raw?: false;
72
+ },
73
+ ): Resolver<Input, Context, Output>;
74
+
75
+ export function zodResolver<Input extends FieldValues, Context, Output>(
76
+ schema: z.ZodSchema<Output, any, Input>,
77
+ schemaOptions: Partial<z.ParseParams> | undefined,
78
+ resolverOptions: {
79
+ mode?: 'async' | 'sync';
80
+ raw: true;
81
+ },
82
+ ): Resolver<Input, Context, Input>;
83
+
64
84
  /**
65
85
  * Creates a resolver function for react-hook-form that validates form data using a Zod schema
66
- * @param {z.ZodSchema<TFieldValues>} schema - The Zod schema used to validate the form data
86
+ * @param {z.ZodSchema<Input>} schema - The Zod schema used to validate the form data
67
87
  * @param {Partial<z.ParseParams>} [schemaOptions] - Optional configuration options for Zod parsing
68
88
  * @param {Object} [resolverOptions] - Optional resolver-specific configuration
69
89
  * @param {('async'|'sync')} [resolverOptions.mode='async'] - Validation mode. Use 'sync' for synchronous validation
70
90
  * @param {boolean} [resolverOptions.raw=false] - If true, returns the raw form values instead of the parsed data
71
- * @returns {Resolver<z.infer<typeof schema>>} A resolver function compatible with react-hook-form
91
+ * @returns {Resolver<z.output<typeof schema>>} A resolver function compatible with react-hook-form
72
92
  * @throws {Error} Throws if validation fails with a non-Zod error
73
93
  * @example
74
94
  * const schema = z.object({
@@ -80,15 +100,15 @@ function parseErrorSchema(
80
100
  * resolver: zodResolver(schema)
81
101
  * });
82
102
  */
83
- export function zodResolver<TFieldValues extends FieldValues>(
84
- schema: z.ZodSchema<TFieldValues, any, any>,
103
+ export function zodResolver<Input extends FieldValues, Context, Output>(
104
+ schema: z.ZodSchema<Output, any, Input>,
85
105
  schemaOptions?: Partial<z.ParseParams>,
86
106
  resolverOptions: {
87
107
  mode?: 'async' | 'sync';
88
108
  raw?: boolean;
89
109
  } = {},
90
- ): Resolver<z.infer<typeof schema>> {
91
- return async (values, _, options) => {
110
+ ): Resolver<Input, Context, Output | Input> {
111
+ return async (values: Input, _, options) => {
92
112
  try {
93
113
  const data = await schema[
94
114
  resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'
@@ -99,8 +119,8 @@ export function zodResolver<TFieldValues extends FieldValues>(
99
119
  return {
100
120
  errors: {} as FieldErrors,
101
121
  values: resolverOptions.raw ? Object.assign({}, values) : data,
102
- };
103
- } catch (error: any) {
122
+ } satisfies ResolverSuccess<Output | Input>;
123
+ } catch (error) {
104
124
  if (isZodError(error)) {
105
125
  return {
106
126
  values: {},
@@ -112,7 +132,7 @@ export function zodResolver<TFieldValues extends FieldValues>(
112
132
  ),
113
133
  options,
114
134
  ),
115
- };
135
+ } satisfies ResolverError<Input>;
116
136
  }
117
137
 
118
138
  throw error;
@@ -1,9 +0,0 @@
1
- import type { Schema } from '@typeschema/main';
2
- import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
3
- export type Resolver = <T extends Schema>(schema: T, schemaOptions?: never, factoryOptions?: {
4
- /**
5
- * Return the raw input values rather than the parsed values.
6
- * @default false
7
- */
8
- raw?: boolean;
9
- }) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
@@ -1,18 +0,0 @@
1
- import type { Schema } from '@typeschema/main';
2
- import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
3
-
4
- export type Resolver = <T extends Schema>(
5
- schema: T,
6
- schemaOptions?: never,
7
- factoryOptions?: {
8
- /**
9
- * Return the raw input values rather than the parsed values.
10
- * @default false
11
- */
12
- raw?: boolean;
13
- },
14
- ) => <TFieldValues extends FieldValues, TContext>(
15
- values: TFieldValues,
16
- context: TContext | undefined,
17
- options: ResolverOptions<TFieldValues>,
18
- ) => Promise<ResolverResult<TFieldValues>>;