@hookform/resolvers 3.10.0 → 4.1.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 (303) hide show
  1. package/README.md +108 -6
  2. package/ajv/dist/ajv.d.ts +20 -0
  3. package/ajv/dist/ajv.js +1 -1
  4. package/ajv/dist/ajv.js.map +1 -1
  5. package/ajv/dist/ajv.mjs +1 -1
  6. package/ajv/dist/ajv.modern.mjs +1 -1
  7. package/ajv/dist/ajv.modern.mjs.map +1 -1
  8. package/ajv/dist/ajv.module.js +1 -1
  9. package/ajv/dist/ajv.module.js.map +1 -1
  10. package/ajv/dist/ajv.umd.js +1 -1
  11. package/ajv/dist/ajv.umd.js.map +1 -1
  12. package/ajv/dist/types.d.ts +8 -0
  13. package/ajv/src/__tests__/__fixtures__/data-errors.ts +216 -0
  14. package/ajv/src/__tests__/__snapshots__/ajv-errors.ts.snap +462 -0
  15. package/ajv/src/__tests__/__snapshots__/ajv.ts.snap +6 -6
  16. package/ajv/src/__tests__/ajv-errors.ts +227 -0
  17. package/ajv/src/ajv.ts +47 -14
  18. package/ajv/src/types.ts +8 -0
  19. package/arktype/dist/arktype.d.ts +20 -2
  20. package/arktype/dist/arktype.js +1 -1
  21. package/arktype/dist/arktype.js.map +1 -1
  22. package/arktype/dist/arktype.mjs +1 -1
  23. package/arktype/dist/arktype.modern.mjs +1 -1
  24. package/arktype/dist/arktype.modern.mjs.map +1 -1
  25. package/arktype/dist/arktype.module.js +1 -1
  26. package/arktype/dist/arktype.module.js.map +1 -1
  27. package/arktype/dist/arktype.umd.js +1 -1
  28. package/arktype/dist/arktype.umd.js.map +1 -1
  29. package/arktype/dist/index.d.ts +0 -1
  30. package/arktype/package.json +1 -1
  31. package/arktype/src/__tests__/Form-native-validation.tsx +3 -3
  32. package/arktype/src/__tests__/Form.tsx +34 -8
  33. package/arktype/src/__tests__/__fixtures__/data.ts +2 -2
  34. package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +22 -415
  35. package/arktype/src/arktype.ts +46 -15
  36. package/arktype/src/index.ts +0 -1
  37. package/class-validator/dist/class-validator.d.ts +29 -2
  38. package/class-validator/dist/class-validator.js +1 -1
  39. package/class-validator/dist/class-validator.js.map +1 -1
  40. package/class-validator/dist/class-validator.mjs +1 -1
  41. package/class-validator/dist/class-validator.modern.mjs +1 -1
  42. package/class-validator/dist/class-validator.modern.mjs.map +1 -1
  43. package/class-validator/dist/class-validator.module.js +1 -1
  44. package/class-validator/dist/class-validator.module.js.map +1 -1
  45. package/class-validator/dist/class-validator.umd.js +1 -1
  46. package/class-validator/dist/class-validator.umd.js.map +1 -1
  47. package/class-validator/dist/index.d.ts +0 -1
  48. package/class-validator/src/__tests__/Form.tsx +26 -0
  49. package/class-validator/src/__tests__/__fixtures__/data.ts +1 -1
  50. package/class-validator/src/__tests__/class-validator.ts +22 -11
  51. package/class-validator/src/class-validator.ts +47 -13
  52. package/class-validator/src/index.ts +0 -1
  53. package/computed-types/dist/computed-types.d.ts +18 -2
  54. package/computed-types/dist/computed-types.js.map +1 -1
  55. package/computed-types/dist/computed-types.mjs +1 -1
  56. package/computed-types/dist/computed-types.modern.mjs +1 -1
  57. package/computed-types/dist/computed-types.modern.mjs.map +1 -1
  58. package/computed-types/dist/computed-types.module.js +1 -1
  59. package/computed-types/dist/computed-types.module.js.map +1 -1
  60. package/computed-types/dist/computed-types.umd.js.map +1 -1
  61. package/computed-types/dist/index.d.ts +0 -1
  62. package/computed-types/src/__tests__/Form-native-validation.tsx +2 -4
  63. package/computed-types/src/__tests__/Form.tsx +30 -6
  64. package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
  65. package/computed-types/src/__tests__/computed-types.ts +2 -0
  66. package/computed-types/src/computed-types.ts +24 -7
  67. package/computed-types/src/index.ts +0 -1
  68. package/dist/resolvers.js +1 -1
  69. package/dist/resolvers.js.map +1 -1
  70. package/dist/resolvers.mjs +1 -1
  71. package/dist/resolvers.mjs.map +1 -1
  72. package/dist/resolvers.module.js +1 -1
  73. package/dist/resolvers.module.js.map +1 -1
  74. package/dist/resolvers.umd.js +1 -1
  75. package/dist/resolvers.umd.js.map +1 -1
  76. package/effect-ts/dist/effect-ts.d.ts +19 -2
  77. package/effect-ts/dist/effect-ts.js +1 -1
  78. package/effect-ts/dist/effect-ts.js.map +1 -1
  79. package/effect-ts/dist/effect-ts.mjs +1 -1
  80. package/effect-ts/dist/effect-ts.modern.mjs +1 -1
  81. package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
  82. package/effect-ts/dist/effect-ts.module.js +1 -1
  83. package/effect-ts/dist/effect-ts.module.js.map +1 -1
  84. package/effect-ts/dist/effect-ts.umd.js +1 -1
  85. package/effect-ts/dist/effect-ts.umd.js.map +1 -1
  86. package/effect-ts/dist/index.d.ts +0 -1
  87. package/effect-ts/src/__tests__/Form.tsx +30 -4
  88. package/effect-ts/src/__tests__/__fixtures__/data.ts +1 -1
  89. package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +35 -1
  90. package/effect-ts/src/__tests__/effect-ts.ts +61 -0
  91. package/effect-ts/src/effect-ts.ts +60 -13
  92. package/effect-ts/src/index.ts +0 -1
  93. package/fluentvalidation-ts/dist/fluentvalidation-ts.d.ts +21 -0
  94. package/fluentvalidation-ts/dist/fluentvalidation-ts.js +1 -1
  95. package/fluentvalidation-ts/dist/fluentvalidation-ts.js.map +1 -1
  96. package/fluentvalidation-ts/dist/fluentvalidation-ts.mjs +1 -1
  97. package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs +1 -1
  98. package/fluentvalidation-ts/dist/fluentvalidation-ts.modern.mjs.map +1 -1
  99. package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js +1 -1
  100. package/fluentvalidation-ts/dist/fluentvalidation-ts.module.js.map +1 -1
  101. package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js +1 -1
  102. package/fluentvalidation-ts/dist/fluentvalidation-ts.umd.js.map +1 -1
  103. package/fluentvalidation-ts/src/fluentvalidation-ts.ts +24 -3
  104. package/io-ts/dist/errorsToRecord.d.ts +5 -1
  105. package/io-ts/dist/index.d.ts +0 -1
  106. package/io-ts/dist/io-ts.d.ts +19 -2
  107. package/io-ts/dist/io-ts.js +1 -1
  108. package/io-ts/dist/io-ts.js.map +1 -1
  109. package/io-ts/dist/io-ts.mjs +1 -1
  110. package/io-ts/dist/io-ts.modern.mjs +1 -1
  111. package/io-ts/dist/io-ts.modern.mjs.map +1 -1
  112. package/io-ts/dist/io-ts.module.js +1 -1
  113. package/io-ts/dist/io-ts.module.js.map +1 -1
  114. package/io-ts/dist/io-ts.umd.js +1 -1
  115. package/io-ts/dist/io-ts.umd.js.map +1 -1
  116. package/io-ts/src/__tests__/Form-native-validation.tsx +4 -11
  117. package/io-ts/src/__tests__/Form.tsx +30 -6
  118. package/io-ts/src/__tests__/__fixtures__/data.ts +2 -19
  119. package/io-ts/src/errorsToRecord.ts +4 -1
  120. package/io-ts/src/index.ts +0 -1
  121. package/io-ts/src/io-ts.ts +47 -25
  122. package/joi/dist/joi.d.ts +17 -0
  123. package/joi/dist/joi.js.map +1 -1
  124. package/joi/dist/joi.modern.mjs.map +1 -1
  125. package/joi/dist/joi.module.js.map +1 -1
  126. package/joi/dist/joi.umd.js.map +1 -1
  127. package/joi/src/joi.ts +17 -0
  128. package/nope/dist/nope.d.ts +17 -0
  129. package/nope/dist/nope.js +1 -1
  130. package/nope/dist/nope.js.map +1 -1
  131. package/nope/dist/nope.mjs +1 -1
  132. package/nope/dist/nope.modern.mjs.map +1 -1
  133. package/nope/dist/nope.module.js +1 -1
  134. package/nope/dist/nope.module.js.map +1 -1
  135. package/nope/dist/nope.umd.js +1 -1
  136. package/nope/dist/nope.umd.js.map +1 -1
  137. package/nope/src/nope.ts +17 -0
  138. package/package.json +49 -34
  139. package/standard-schema/dist/index.d.ts +1 -0
  140. package/standard-schema/dist/standard-schema.d.ts +25 -0
  141. package/standard-schema/dist/standard-schema.js +2 -0
  142. package/standard-schema/dist/standard-schema.js.map +1 -0
  143. package/standard-schema/dist/standard-schema.mjs +2 -0
  144. package/standard-schema/dist/standard-schema.modern.mjs +2 -0
  145. package/standard-schema/dist/standard-schema.modern.mjs.map +1 -0
  146. package/standard-schema/dist/standard-schema.module.js +2 -0
  147. package/standard-schema/dist/standard-schema.module.js.map +1 -0
  148. package/standard-schema/dist/standard-schema.umd.js +2 -0
  149. package/standard-schema/dist/standard-schema.umd.js.map +1 -0
  150. package/standard-schema/package.json +18 -0
  151. package/standard-schema/src/__tests__/Form-native-validation.tsx +82 -0
  152. package/standard-schema/src/__tests__/Form.tsx +82 -0
  153. package/standard-schema/src/__tests__/__fixtures__/data.ts +88 -0
  154. package/standard-schema/src/__tests__/__snapshots__/standard-schema.ts.snap +250 -0
  155. package/standard-schema/src/__tests__/standard-schema.ts +56 -0
  156. package/standard-schema/src/index.ts +1 -0
  157. package/standard-schema/src/standard-schema.ts +88 -0
  158. package/superstruct/dist/index.d.ts +0 -1
  159. package/superstruct/dist/superstruct.d.ts +22 -2
  160. package/superstruct/dist/superstruct.js +1 -1
  161. package/superstruct/dist/superstruct.js.map +1 -1
  162. package/superstruct/dist/superstruct.mjs +1 -1
  163. package/superstruct/dist/superstruct.modern.mjs +1 -1
  164. package/superstruct/dist/superstruct.modern.mjs.map +1 -1
  165. package/superstruct/dist/superstruct.module.js +1 -1
  166. package/superstruct/dist/superstruct.module.js.map +1 -1
  167. package/superstruct/dist/superstruct.umd.js +1 -1
  168. package/superstruct/dist/superstruct.umd.js.map +1 -1
  169. package/superstruct/src/__tests__/Form.tsx +26 -0
  170. package/superstruct/src/__tests__/__fixtures__/data.ts +1 -1
  171. package/superstruct/src/index.ts +0 -1
  172. package/superstruct/src/superstruct.ts +32 -10
  173. package/typanion/dist/index.d.ts +0 -1
  174. package/typanion/dist/typanion.d.ts +18 -2
  175. package/typanion/dist/typanion.js.map +1 -1
  176. package/typanion/dist/typanion.mjs +1 -1
  177. package/typanion/dist/typanion.modern.mjs +1 -1
  178. package/typanion/dist/typanion.modern.mjs.map +1 -1
  179. package/typanion/dist/typanion.module.js +1 -1
  180. package/typanion/dist/typanion.module.js.map +1 -1
  181. package/typanion/dist/typanion.umd.js.map +1 -1
  182. package/typanion/src/__tests__/Form-native-validation.tsx +6 -14
  183. package/typanion/src/__tests__/Form.tsx +32 -8
  184. package/typanion/src/__tests__/__fixtures__/data.ts +9 -9
  185. package/typanion/src/__tests__/typanion.ts +3 -3
  186. package/typanion/src/index.ts +0 -1
  187. package/typanion/src/typanion.ts +32 -9
  188. package/typebox/dist/index.d.ts +0 -1
  189. package/typebox/dist/typebox.d.ts +20 -2
  190. package/typebox/dist/typebox.js +1 -1
  191. package/typebox/dist/typebox.js.map +1 -1
  192. package/typebox/dist/typebox.mjs +1 -1
  193. package/typebox/dist/typebox.modern.mjs +1 -1
  194. package/typebox/dist/typebox.modern.mjs.map +1 -1
  195. package/typebox/dist/typebox.module.js +1 -1
  196. package/typebox/dist/typebox.module.js.map +1 -1
  197. package/typebox/dist/typebox.umd.js +1 -1
  198. package/typebox/dist/typebox.umd.js.map +1 -1
  199. package/typebox/src/__tests__/Form-compiler.tsx +4 -8
  200. package/typebox/src/__tests__/Form.tsx +32 -6
  201. package/typebox/src/__tests__/__fixtures__/data.ts +1 -1
  202. package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +21 -21
  203. package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +21 -21
  204. package/typebox/src/index.ts +0 -1
  205. package/typebox/src/typebox.ts +33 -7
  206. package/typeschema/dist/typeschema.d.ts +17 -0
  207. package/typeschema/dist/typeschema.js +1 -1
  208. package/typeschema/dist/typeschema.js.map +1 -1
  209. package/typeschema/dist/typeschema.mjs +1 -1
  210. package/typeschema/dist/typeschema.modern.mjs +1 -1
  211. package/typeschema/dist/typeschema.modern.mjs.map +1 -1
  212. package/typeschema/dist/typeschema.module.js +1 -1
  213. package/typeschema/dist/typeschema.module.js.map +1 -1
  214. package/typeschema/dist/typeschema.umd.js +1 -1
  215. package/typeschema/dist/typeschema.umd.js.map +1 -1
  216. package/typeschema/src/typeschema.ts +20 -1
  217. package/valibot/dist/index.d.ts +0 -1
  218. package/valibot/dist/valibot.d.ts +31 -2
  219. package/valibot/dist/valibot.js +1 -1
  220. package/valibot/dist/valibot.js.map +1 -1
  221. package/valibot/dist/valibot.mjs +1 -1
  222. package/valibot/dist/valibot.modern.mjs +1 -1
  223. package/valibot/dist/valibot.modern.mjs.map +1 -1
  224. package/valibot/dist/valibot.module.js +1 -1
  225. package/valibot/dist/valibot.module.js.map +1 -1
  226. package/valibot/dist/valibot.umd.js +1 -1
  227. package/valibot/dist/valibot.umd.js.map +1 -1
  228. package/valibot/package.json +1 -1
  229. package/valibot/src/__tests__/Form.tsx +26 -0
  230. package/valibot/src/__tests__/__fixtures__/data.ts +7 -3
  231. package/valibot/src/__tests__/valibot.ts +1 -1
  232. package/valibot/src/index.ts +0 -1
  233. package/valibot/src/valibot.ts +55 -6
  234. package/vest/dist/vest.d.ts +18 -0
  235. package/vest/dist/vest.js.map +1 -1
  236. package/vest/dist/vest.modern.mjs.map +1 -1
  237. package/vest/dist/vest.module.js.map +1 -1
  238. package/vest/dist/vest.umd.js.map +1 -1
  239. package/vest/src/vest.ts +18 -0
  240. package/vine/dist/index.d.ts +0 -1
  241. package/vine/dist/vine.d.ts +25 -2
  242. package/vine/dist/vine.js +1 -1
  243. package/vine/dist/vine.js.map +1 -1
  244. package/vine/dist/vine.mjs +1 -1
  245. package/vine/dist/vine.modern.mjs +1 -1
  246. package/vine/dist/vine.modern.mjs.map +1 -1
  247. package/vine/dist/vine.module.js +1 -1
  248. package/vine/dist/vine.module.js.map +1 -1
  249. package/vine/dist/vine.umd.js +1 -1
  250. package/vine/dist/vine.umd.js.map +1 -1
  251. package/vine/src/__tests__/Form-native-validation.tsx +2 -4
  252. package/vine/src/__tests__/Form.tsx +30 -6
  253. package/vine/src/__tests__/__fixtures__/data.ts +1 -1
  254. package/vine/src/index.ts +0 -1
  255. package/vine/src/vine.ts +38 -10
  256. package/yup/dist/yup.d.ts +18 -7
  257. package/yup/dist/yup.js +1 -1
  258. package/yup/dist/yup.js.map +1 -1
  259. package/yup/dist/yup.mjs +1 -1
  260. package/yup/dist/yup.modern.mjs +1 -1
  261. package/yup/dist/yup.modern.mjs.map +1 -1
  262. package/yup/dist/yup.module.js +1 -1
  263. package/yup/dist/yup.module.js.map +1 -1
  264. package/yup/dist/yup.umd.js +1 -1
  265. package/yup/dist/yup.umd.js.map +1 -1
  266. package/yup/src/yup.ts +22 -11
  267. package/zod/dist/index.d.ts +0 -1
  268. package/zod/dist/zod.d.ts +25 -2
  269. package/zod/dist/zod.js +1 -1
  270. package/zod/dist/zod.js.map +1 -1
  271. package/zod/dist/zod.mjs +1 -1
  272. package/zod/dist/zod.modern.mjs +1 -1
  273. package/zod/dist/zod.modern.mjs.map +1 -1
  274. package/zod/dist/zod.module.js +1 -1
  275. package/zod/dist/zod.module.js.map +1 -1
  276. package/zod/dist/zod.umd.js +1 -1
  277. package/zod/dist/zod.umd.js.map +1 -1
  278. package/zod/src/__tests__/Form.tsx +30 -6
  279. package/zod/src/__tests__/__fixtures__/data.ts +3 -3
  280. package/zod/src/index.ts +0 -1
  281. package/zod/src/zod.ts +40 -9
  282. package/arktype/dist/types.d.ts +0 -9
  283. package/arktype/src/types.ts +0 -18
  284. package/class-validator/dist/types.d.ts +0 -12
  285. package/class-validator/src/types.ts +0 -16
  286. package/computed-types/dist/types.d.ts +0 -2
  287. package/computed-types/src/types.ts +0 -13
  288. package/effect-ts/dist/types.d.ts +0 -4
  289. package/effect-ts/src/types.ts +0 -12
  290. package/io-ts/dist/types.d.ts +0 -7
  291. package/io-ts/src/types.ts +0 -18
  292. package/superstruct/dist/types.d.ts +0 -11
  293. package/superstruct/src/types.ts +0 -20
  294. package/typanion/dist/types.d.ts +0 -9
  295. package/typanion/src/types.ts +0 -20
  296. package/typebox/dist/types.d.ts +0 -4
  297. package/typebox/src/types.ts +0 -11
  298. package/valibot/dist/types.d.ts +0 -13
  299. package/valibot/src/types.ts +0 -34
  300. package/vine/dist/types.d.ts +0 -6
  301. package/vine/src/types.ts +0 -13
  302. package/zod/dist/types.d.ts +0 -13
  303. package/zod/src/types.ts +0 -22
@@ -1,8 +1,13 @@
1
1
  import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
2
- import type { FieldError, FieldErrors } from 'react-hook-form';
3
- import type { Resolver } from './types';
2
+ import type {
3
+ FieldError,
4
+ FieldErrors,
5
+ FieldValues,
6
+ Resolver,
7
+ } from 'react-hook-form';
8
+ import * as t from 'typanion';
4
9
 
5
- const parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {
10
+ function parseErrors(errors: string[], parsedErrors: FieldErrors = {}) {
6
11
  return errors.reduce((acc, error) => {
7
12
  const fieldIndex = error.indexOf(':');
8
13
 
@@ -15,20 +20,37 @@ const parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {
15
20
 
16
21
  return acc;
17
22
  }, parsedErrors);
18
- };
23
+ }
19
24
 
20
- export const typanionResolver: Resolver =
21
- (validator, validatorOptions = {}) =>
22
- (values, _, options) => {
25
+ /**
26
+ * Creates a resolver for react-hook-form using Typanion schema validation
27
+ * @param {t.StrictValidator<TFieldValues, TFieldValues>} schema - The Typanion schema to validate against
28
+ * @param {Pick<t.ValidationState, 'coercions' | 'coercion'>} [schemaOptions] - Optional Typanion validation options
29
+ * @returns {Resolver<t.InferType<typeof schema>>} A resolver function compatible with react-hook-form
30
+ * @example
31
+ * const schema = t.isObject({
32
+ * name: t.isString(),
33
+ * age: t.isInteger()
34
+ * });
35
+ *
36
+ * useForm({
37
+ * resolver: typanionResolver(schema)
38
+ * });
39
+ */
40
+ export function typanionResolver<TFieldValues extends FieldValues>(
41
+ schema: t.StrictValidator<TFieldValues, TFieldValues>,
42
+ schemaOptions: Pick<t.ValidationState, 'coercions' | 'coercion'> = {},
43
+ ): Resolver<t.InferType<typeof schema>> {
44
+ return (values, _, options) => {
23
45
  const rawErrors: string[] = [];
24
- const isValid = validator(
46
+ const isValid = schema(
25
47
  values,
26
48
  Object.assign(
27
49
  {},
28
50
  {
29
51
  errors: rawErrors,
30
52
  },
31
- validatorOptions,
53
+ schemaOptions,
32
54
  ),
33
55
  );
34
56
  const parsedErrors = parseErrors(rawErrors);
@@ -42,3 +64,4 @@ export const typanionResolver: Resolver =
42
64
 
43
65
  return { values: {}, errors: toNestErrors(parsedErrors, options) };
44
66
  };
67
+ }
@@ -1,2 +1 @@
1
1
  export * from './typebox';
2
- export * from './types';
@@ -1,2 +1,20 @@
1
- import type { Resolver } from './types';
2
- export declare const typeboxResolver: Resolver;
1
+ import { Static, Type } from '@sinclair/typebox';
2
+ import { TypeCheck } from '@sinclair/typebox/compiler';
3
+ import { FieldValues, Resolver } from 'react-hook-form';
4
+ /**
5
+ * Creates a resolver for react-hook-form using Typebox schema validation
6
+ * @param {Schema | TypeCheck<Schema>} schema - The Typebox schema to validate against
7
+ * @param {Object} options - Additional resolver configuration
8
+ * @param {string} [options.mode='async'] - Validation mode
9
+ * @returns {Resolver<Static<Schema>>} A resolver function compatible with react-hook-form
10
+ * @example
11
+ * const schema = Type.Object({
12
+ * name: Type.String(),
13
+ * age: Type.Number()
14
+ * });
15
+ *
16
+ * useForm({
17
+ * resolver: typeboxResolver(schema)
18
+ * });
19
+ */
20
+ export declare function typeboxResolver<TFieldValues extends FieldValues, Schema extends ReturnType<typeof Type.Object<TFieldValues>>>(schema: Schema | TypeCheck<Schema>): Resolver<Static<Schema>>;
@@ -1,2 +1,2 @@
1
- var e=require("@hookform/resolvers"),r=require("@sinclair/typebox/compiler"),s=require("@sinclair/typebox/value"),o=require("react-hook-form"),a=function(e,r){for(var s={};e.length;){var a=e[0],t=a.type,i=a.message,l=a.path.substring(1).replace(/\//g,".");if(s[l]||(s[l]={message:i,type:""+t}),r){var n=s[l].types,u=n&&n[""+t];s[l]=o.appendErrors(l,r,s,""+t,u?[].concat(u,a.message):a.message)}e.shift()}return s};exports.typeboxResolver=function(o){return function(t,i,l){try{var n=Array.from(o instanceof r.TypeCheck?o.Errors(t):s.Value.Errors(o,t));return l.shouldUseNativeValidation&&e.validateFieldsNatively({},l),Promise.resolve(n.length?{values:{},errors:e.toNestErrors(a(n,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:t})}catch(e){return Promise.reject(e)}}};
1
+ var e=require("@hookform/resolvers"),r=require("@sinclair/typebox/compiler"),s=require("@sinclair/typebox/value"),o=require("react-hook-form");function a(e,r){for(var s={};e.length;){var a=e[0],t=a.type,i=a.message,l=a.path.substring(1).replace(/\//g,".");if(s[l]||(s[l]={message:i,type:""+t}),r){var n=s[l].types,u=n&&n[""+t];s[l]=o.appendErrors(l,r,s,""+t,u?[].concat(u,a.message):a.message)}e.shift()}return s}exports.typeboxResolver=function(o){return function(t,i,l){try{var n=Array.from(o instanceof r.TypeCheck?o.Errors(t):s.Value.Errors(o,t));return l.shouldUseNativeValidation&&e.validateFieldsNatively({},l),Promise.resolve(n.length?{values:{},errors:e.toNestErrors(a(n,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:t})}catch(e){return Promise.reject(e)}}};
2
2
  //# sourceMappingURL=typebox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typebox.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","schema","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"+IAMMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,GACpCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EAAAA,aACdN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,CACT,0BAGE,SAACc,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAO,IACnC,IAAMjB,EAASkB,MAAMC,KACnBL,aAAkBM,EAASA,UACvBN,EAAOO,OAAON,GACdO,EAAKA,MAACD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAsBA,uBAAC,GAAIP,GAShEQ,QAAAC,QAPK1B,EAAOC,OAOL,CACLc,OAAQ,CAAA,EACRf,OAAQ2B,EAAYA,aAClB9B,EACEG,GACCiB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLjB,OAAQ,CAAA,EACRe,OAAAA,GAcN,CAAC,MAAAc,GAAA,OAAAJ,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"typebox.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Static, Type } from '@sinclair/typebox';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nfunction parseErrorSchema(\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n}\n\n/**\n * Creates a resolver for react-hook-form using Typebox schema validation\n * @param {Schema | TypeCheck<Schema>} schema - The Typebox schema to validate against\n * @param {Object} options - Additional resolver configuration\n * @param {string} [options.mode='async'] - Validation mode\n * @returns {Resolver<Static<Schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Type.Object({\n * name: Type.String(),\n * age: Type.Number()\n * });\n *\n * useForm({\n * resolver: typeboxResolver(schema)\n * });\n */\nexport function typeboxResolver<\n TFieldValues extends FieldValues,\n Schema extends ReturnType<typeof Type.Object<TFieldValues>>,\n>(schema: Schema | TypeCheck<Schema>): Resolver<Static<Schema>> {\n return async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n}\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","schema","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"+IAYA,SAASA,EACPC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EAAYA,aAC1BN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,CACT,yBAkBgB,SAGdc,GACA,OAAcC,SAAAA,EAAQC,EAAGC,GAAO,IAC9B,IAAMjB,EAASkB,MAAMC,KACnBL,aAAkBM,YACdN,EAAOO,OAAON,GACdO,QAAMD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEP,GAShEQ,QAAAC,QAPK1B,EAAOC,OAOL,CACLc,OAAQ,CAAE,EACVf,OAAQ2B,EAAAA,aACN9B,EACEG,GACCiB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLjB,OAAQ,GACRe,OAAAA,GAcN,CAAC,MAAAc,UAAAJ,QAAAK,OAAAD,EACH,CAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{TypeCheck as o}from"@sinclair/typebox/compiler";import{Value as t}from"@sinclair/typebox/value";import{appendErrors as s}from"react-hook-form";var a=function(r,e){for(var o={};r.length;){var t=r[0],a=t.type,i=t.message,n=t.path.substring(1).replace(/\//g,".");if(o[n]||(o[n]={message:i,type:""+a}),e){var m=o[n].types,l=m&&m[""+a];o[n]=s(n,e,o,""+a,l?[].concat(l,t.message):t.message)}r.shift()}return o},i=function(s){return function(i,n,m){try{var l=Array.from(s instanceof o?s.Errors(i):t.Errors(s,i));return m.shouldUseNativeValidation&&r({},m),Promise.resolve(l.length?{values:{},errors:e(a(l,!m.shouldUseNativeValidation&&"all"===m.criteriaMode),m)}:{errors:{},values:i})}catch(r){return Promise.reject(r)}}};export{i as typeboxResolver};
1
+ import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{TypeCheck as o}from"@sinclair/typebox/compiler";import{Value as t}from"@sinclair/typebox/value";import{appendErrors as s}from"react-hook-form";function a(r,e){for(var o={};r.length;){var t=r[0],a=t.type,i=t.message,n=t.path.substring(1).replace(/\//g,".");if(o[n]||(o[n]={message:i,type:""+a}),e){var m=o[n].types,l=m&&m[""+a];o[n]=s(n,e,o,""+a,l?[].concat(l,t.message):t.message)}r.shift()}return o}function i(s){return function(i,n,m){try{var l=Array.from(s instanceof o?s.Errors(i):t.Errors(s,i));return m.shouldUseNativeValidation&&r({},m),Promise.resolve(l.length?{values:{},errors:e(a(l,!m.shouldUseNativeValidation&&"all"===m.criteriaMode),m)}:{errors:{},values:i})}catch(r){return Promise.reject(r)}}}export{i as typeboxResolver};
2
2
  //# sourceMappingURL=typebox.module.js.map
@@ -1,2 +1,2 @@
1
- import{validateFieldsNatively as r,toNestErrors as o}from"@hookform/resolvers";import{TypeCheck as e}from"@sinclair/typebox/compiler";import{Value as s}from"@sinclair/typebox/value";import{appendErrors as t}from"react-hook-form";const a=(r,o)=>{const e={};for(;r.length;){const s=r[0],{type:a,message:i,path:n}=s,l=n.substring(1).replace(/\//g,".");if(e[l]||(e[l]={message:i,type:""+a}),o){const r=e[l].types,i=r&&r[""+a];e[l]=t(l,o,e,""+a,i?[].concat(i,s.message):s.message)}r.shift()}return e},i=t=>async(i,n,l)=>{const m=Array.from(t instanceof e?t.Errors(i):s.Errors(t,i));return l.shouldUseNativeValidation&&r({},l),m.length?{values:{},errors:o(a(m,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:i}};export{i as typeboxResolver};
1
+ import{validateFieldsNatively as r,toNestErrors as o}from"@hookform/resolvers";import{TypeCheck as e}from"@sinclair/typebox/compiler";import{Value as s}from"@sinclair/typebox/value";import{appendErrors as t}from"react-hook-form";function a(r,o){const e={};for(;r.length;){const s=r[0],{type:a,message:i,path:n}=s,c=n.substring(1).replace(/\//g,".");if(e[c]||(e[c]={message:i,type:""+a}),o){const r=e[c].types,i=r&&r[""+a];e[c]=t(c,o,e,""+a,i?[].concat(i,s.message):s.message)}r.shift()}return e}function i(t){return async(i,n,c)=>{const l=Array.from(t instanceof e?t.Errors(i):s.Errors(t,i));return c.shouldUseNativeValidation&&r({},c),l.length?{values:{},errors:o(a(l,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)}:{errors:{},values:i}}}export{i as typeboxResolver};
2
2
  //# sourceMappingURL=typebox.modern.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"typebox.modern.mjs","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","path","_path","substring","replace","types","messages","appendErrors","concat","shift","typeboxResolver","schema","async","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","toNestErrors","criteriaMode"],"mappings":"qOAMA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,CAAE,EAC7C,KAAOF,EAAQG,QAAU,CACvB,MAAMC,EAAQJ,EAAQ,IAChBK,KAAEA,EAAIC,QAAEA,EAAOC,KAAEA,GAASH,EAC1BI,EAAQD,EAAKE,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOM,KACVN,EAAOM,GAAS,CAAEF,UAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,MAAMU,EAAQT,EAAOM,GAAOG,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOM,GAASK,EACdL,EACAP,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,GAGIc,EACVC,GAAWC,MAAOC,EAAQC,EAAGC,KAC5B,MAAMnB,EAASoB,MAAMC,KACnBN,aAAkBO,EACdP,EAAOQ,OAAON,GACdO,EAAMD,OAAOR,EAAQE,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAuB,CAAE,EAAEP,GAE3DnB,EAAOC,OAOL,CACLgB,OAAQ,CAAE,EACVjB,OAAQ2B,EACN9B,EACEG,GACCmB,EAAQM,2BAAsD,QAAzBN,EAAQS,cAEhDT,IAbK,CACLnB,OAAQ,CAAiB,EACzBiB"}
1
+ {"version":3,"file":"typebox.modern.mjs","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Static, Type } from '@sinclair/typebox';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nfunction parseErrorSchema(\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n}\n\n/**\n * Creates a resolver for react-hook-form using Typebox schema validation\n * @param {Schema | TypeCheck<Schema>} schema - The Typebox schema to validate against\n * @param {Object} options - Additional resolver configuration\n * @param {string} [options.mode='async'] - Validation mode\n * @returns {Resolver<Static<Schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Type.Object({\n * name: Type.String(),\n * age: Type.Number()\n * });\n *\n * useForm({\n * resolver: typeboxResolver(schema)\n * });\n */\nexport function typeboxResolver<\n TFieldValues extends FieldValues,\n Schema extends ReturnType<typeof Type.Object<TFieldValues>>,\n>(schema: Schema | TypeCheck<Schema>): Resolver<Static<Schema>> {\n return async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n}\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","path","_path","substring","replace","types","messages","appendErrors","concat","shift","typeboxResolver","schema","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","toNestErrors","criteriaMode"],"mappings":"qOAYA,SAASA,EACPC,EACAC,GAEA,MAAMC,EAAqC,CAAA,EAC3C,KAAOF,EAAQG,QAAU,CACvB,MAAMC,EAAQJ,EAAQ,IAChBK,KAAEA,EAAIC,QAAEA,EAAOC,KAAEA,GAASH,EAC1BI,EAAQD,EAAKE,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOM,KACVN,EAAOM,GAAS,CAAEF,UAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,MAAMU,EAAQT,EAAOM,GAAOG,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOM,GAASK,EACdL,EACAP,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,CACT,CAkBM,SAAUc,EAGdC,GACA,OAAcC,MAAAA,EAAQC,EAAGC,KACvB,MAAMlB,EAASmB,MAAMC,KACnBL,aAAkBM,EACdN,EAAOO,OAAON,GACdO,EAAMD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAuB,CAAE,EAAEP,GAE3DlB,EAAOC,OAOL,CACLe,OAAQ,CAAA,EACRhB,OAAQ0B,EACN7B,EACEG,GACCkB,EAAQM,2BAAsD,QAAzBN,EAAQS,cAEhDT,IAbK,CACLlB,OAAQ,CAAiB,EACzBgB,UAeR"}
@@ -1,2 +1,2 @@
1
- import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{TypeCheck as o}from"@sinclair/typebox/compiler";import{Value as t}from"@sinclair/typebox/value";import{appendErrors as s}from"react-hook-form";var a=function(r,e){for(var o={};r.length;){var t=r[0],a=t.type,i=t.message,n=t.path.substring(1).replace(/\//g,".");if(o[n]||(o[n]={message:i,type:""+a}),e){var m=o[n].types,l=m&&m[""+a];o[n]=s(n,e,o,""+a,l?[].concat(l,t.message):t.message)}r.shift()}return o},i=function(s){return function(i,n,m){try{var l=Array.from(s instanceof o?s.Errors(i):t.Errors(s,i));return m.shouldUseNativeValidation&&r({},m),Promise.resolve(l.length?{values:{},errors:e(a(l,!m.shouldUseNativeValidation&&"all"===m.criteriaMode),m)}:{errors:{},values:i})}catch(r){return Promise.reject(r)}}};export{i as typeboxResolver};
1
+ import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{TypeCheck as o}from"@sinclair/typebox/compiler";import{Value as t}from"@sinclair/typebox/value";import{appendErrors as s}from"react-hook-form";function a(r,e){for(var o={};r.length;){var t=r[0],a=t.type,i=t.message,n=t.path.substring(1).replace(/\//g,".");if(o[n]||(o[n]={message:i,type:""+a}),e){var m=o[n].types,l=m&&m[""+a];o[n]=s(n,e,o,""+a,l?[].concat(l,t.message):t.message)}r.shift()}return o}function i(s){return function(i,n,m){try{var l=Array.from(s instanceof o?s.Errors(i):t.Errors(s,i));return m.shouldUseNativeValidation&&r({},m),Promise.resolve(l.length?{values:{},errors:e(a(l,!m.shouldUseNativeValidation&&"all"===m.criteriaMode),m)}:{errors:{},values:i})}catch(r){return Promise.reject(r)}}}export{i as typeboxResolver};
2
2
  //# sourceMappingURL=typebox.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typebox.module.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","typeboxResolver","schema","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"qOAMA,IAAMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,GACpCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EACdN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,CACT,EAEac,EACX,SAACC,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAO,IACnC,IAAMlB,EAASmB,MAAMC,KACnBL,aAAkBM,EACdN,EAAOO,OAAON,GACdO,EAAMD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAuB,GAAIP,GAShEQ,QAAAC,QAPK3B,EAAOC,OAOL,CACLe,OAAQ,CAAA,EACRhB,OAAQ4B,EACN/B,EACEG,GACCkB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLlB,OAAQ,CAAA,EACRgB,OAAAA,GAcN,CAAC,MAAAc,GAAA,OAAAJ,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"typebox.module.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Static, Type } from '@sinclair/typebox';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nfunction parseErrorSchema(\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n}\n\n/**\n * Creates a resolver for react-hook-form using Typebox schema validation\n * @param {Schema | TypeCheck<Schema>} schema - The Typebox schema to validate against\n * @param {Object} options - Additional resolver configuration\n * @param {string} [options.mode='async'] - Validation mode\n * @returns {Resolver<Static<Schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Type.Object({\n * name: Type.String(),\n * age: Type.Number()\n * });\n *\n * useForm({\n * resolver: typeboxResolver(schema)\n * });\n */\nexport function typeboxResolver<\n TFieldValues extends FieldValues,\n Schema extends ReturnType<typeof Type.Object<TFieldValues>>,\n>(schema: Schema | TypeCheck<Schema>): Resolver<Static<Schema>> {\n return async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n}\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","typeboxResolver","schema","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"qOAYA,SAASA,EACPC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EACdN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,CACT,CAkBgB,SAAAc,EAGdC,GACA,OAAcC,SAAAA,EAAQC,EAAGC,GAAO,IAC9B,IAAMlB,EAASmB,MAAMC,KACnBL,aAAkBM,EACdN,EAAOO,OAAON,GACdO,EAAMD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAuB,CAAE,EAAEP,GAShEQ,QAAAC,QAPK3B,EAAOC,OAOL,CACLe,OAAQ,CAAE,EACVhB,OAAQ4B,EACN/B,EACEG,GACCkB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLlB,OAAQ,GACRgB,OAAAA,GAcN,CAAC,MAAAc,UAAAJ,QAAAK,OAAAD,EACH,CAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("@sinclair/typebox/compiler"),require("@sinclair/typebox/value"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","@sinclair/typebox/compiler","@sinclair/typebox/value","react-hook-form"],r):r((e||self).hookformResolversTypebox={},e.hookformResolvers,e.compiler,e.value,e.ReactHookForm)}(this,function(e,r,o,s,t){var i=function(e,r){for(var o={};e.length;){var s=e[0],i=s.type,a=s.message,l=s.path.substring(1).replace(/\//g,".");if(o[l]||(o[l]={message:a,type:""+i}),r){var n=o[l].types,f=n&&n[""+i];o[l]=t.appendErrors(l,r,o,""+i,f?[].concat(f,s.message):s.message)}e.shift()}return o};e.typeboxResolver=function(e){return function(t,a,l){try{var n=Array.from(e instanceof o.TypeCheck?e.Errors(t):s.Value.Errors(e,t));return l.shouldUseNativeValidation&&r.validateFieldsNatively({},l),Promise.resolve(n.length?{values:{},errors:r.toNestErrors(i(n,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:t})}catch(e){return Promise.reject(e)}}}});
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("@sinclair/typebox/compiler"),require("@sinclair/typebox/value"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","@sinclair/typebox/compiler","@sinclair/typebox/value","react-hook-form"],r):r((e||self).hookformResolversTypebox={},e.hookformResolvers,e.compiler,e.value,e.ReactHookForm)}(this,function(e,r,o,s,t){function i(e,r){for(var o={};e.length;){var s=e[0],i=s.type,a=s.message,l=s.path.substring(1).replace(/\//g,".");if(o[l]||(o[l]={message:a,type:""+i}),r){var n=o[l].types,f=n&&n[""+i];o[l]=t.appendErrors(l,r,o,""+i,f?[].concat(f,s.message):s.message)}e.shift()}return o}e.typeboxResolver=function(e){return function(t,a,l){try{var n=Array.from(e instanceof o.TypeCheck?e.Errors(t):s.Value.Errors(e,t));return l.shouldUseNativeValidation&&r.validateFieldsNatively({},l),Promise.resolve(n.length?{values:{},errors:r.toNestErrors(i(n,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:t})}catch(e){return Promise.reject(e)}}}});
2
2
  //# sourceMappingURL=typebox.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typebox.umd.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","schema","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"mhBAMA,IAAMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,GACpCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EAAAA,aACdN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,CACT,oBAGE,SAACc,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAO,IACnC,IAAMjB,EAASkB,MAAMC,KACnBL,aAAkBM,EAASA,UACvBN,EAAOO,OAAON,GACdO,EAAKA,MAACD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAsBA,uBAAC,GAAIP,GAShEQ,QAAAC,QAPK1B,EAAOC,OAOL,CACLc,OAAQ,CAAA,EACRf,OAAQ2B,EAAYA,aAClB9B,EACEG,GACCiB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLjB,OAAQ,CAAA,EACRe,OAAAA,GAcN,CAAC,MAAAc,GAAA,OAAAJ,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"typebox.umd.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Static, Type } from '@sinclair/typebox';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nfunction parseErrorSchema(\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n}\n\n/**\n * Creates a resolver for react-hook-form using Typebox schema validation\n * @param {Schema | TypeCheck<Schema>} schema - The Typebox schema to validate against\n * @param {Object} options - Additional resolver configuration\n * @param {string} [options.mode='async'] - Validation mode\n * @returns {Resolver<Static<Schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = Type.Object({\n * name: Type.String(),\n * age: Type.Number()\n * });\n *\n * useForm({\n * resolver: typeboxResolver(schema)\n * });\n */\nexport function typeboxResolver<\n TFieldValues extends FieldValues,\n Schema extends ReturnType<typeof Type.Object<TFieldValues>>,\n>(schema: Schema | TypeCheck<Schema>): Resolver<Static<Schema>> {\n return async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n}\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","schema","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"mhBAYA,SAASA,EACPC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EAAYA,aAC1BN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,CACT,mBAkBgB,SAGdc,GACA,OAAcC,SAAAA,EAAQC,EAAGC,GAAO,IAC9B,IAAMjB,EAASkB,MAAMC,KACnBL,aAAkBM,YACdN,EAAOO,OAAON,GACdO,QAAMD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEP,GAShEQ,QAAAC,QAPK1B,EAAOC,OAOL,CACLc,OAAQ,CAAE,EACVf,OAAQ2B,EAAAA,aACN9B,EACEG,GACCiB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLjB,OAAQ,GACRe,OAAAA,GAcN,CAAC,MAAAc,UAAAJ,QAAAK,OAAAD,EACH,CAAA,CAAA"}
@@ -13,18 +13,14 @@ const schema = Type.Object({
13
13
 
14
14
  const typecheck = TypeCompiler.Compile(schema);
15
15
 
16
- type FormData = Static<typeof schema> & { unusedProperty: string };
17
-
18
- interface Props {
19
- onSubmit: (data: FormData) => void;
20
- }
21
-
22
- function TestComponent({ onSubmit }: Props) {
16
+ function TestComponent({
17
+ onSubmit,
18
+ }: { onSubmit: (data: Static<typeof schema>) => void }) {
23
19
  const {
24
20
  register,
25
21
  handleSubmit,
26
22
  formState: { errors },
27
- } = useForm<FormData>({
23
+ } = useForm({
28
24
  resolver: typeboxResolver(typecheck), // Useful to check TypeScript regressions
29
25
  });
30
26
 
@@ -12,16 +12,16 @@ const schema = Type.Object({
12
12
 
13
13
  type FormData = Static<typeof schema> & { unusedProperty: string };
14
14
 
15
- interface Props {
16
- onSubmit: (data: FormData) => void;
17
- }
18
-
19
- function TestComponent({ onSubmit }: Props) {
15
+ function TestComponent({
16
+ onSubmit,
17
+ }: {
18
+ onSubmit: (data: Static<typeof schema>) => void;
19
+ }) {
20
20
  const {
21
21
  register,
22
22
  handleSubmit,
23
23
  formState: { errors },
24
- } = useForm<FormData>({
24
+ } = useForm({
25
25
  resolver: typeboxResolver(schema), // Useful to check TypeScript regressions
26
26
  });
27
27
 
@@ -52,3 +52,29 @@ test("form's validation with Typebox and TypeScript's integration", async () =>
52
52
 
53
53
  expect(handleSubmit).not.toHaveBeenCalled();
54
54
  });
55
+
56
+ export function TestComponentManualType({
57
+ onSubmit,
58
+ }: {
59
+ onSubmit: (data: FormData) => void;
60
+ }) {
61
+ const {
62
+ register,
63
+ handleSubmit,
64
+ formState: { errors },
65
+ } = useForm<Static<typeof schema>, undefined, FormData>({
66
+ resolver: typeboxResolver(schema), // Useful to check TypeScript regressions
67
+ });
68
+
69
+ return (
70
+ <form onSubmit={handleSubmit(onSubmit)}>
71
+ <input {...register('username')} />
72
+ {errors.username && <span role="alert">{errors.username.message}</span>}
73
+
74
+ <input {...register('password')} />
75
+ {errors.password && <span role="alert">{errors.password.message}</span>}
76
+
77
+ <button type="submit">submit</button>
78
+ </form>
79
+ );
80
+ }
@@ -61,7 +61,7 @@ export const invalidData = {
61
61
  birthYear: 'birthYear',
62
62
  like: [{ id: 'z' }],
63
63
  url: 'abc',
64
- };
64
+ } as any as Static<typeof schema>;
65
65
 
66
66
  export const fields: Record<InternalFieldName, Field['_f']> = {
67
67
  username: {
@@ -4,7 +4,7 @@ exports[`typeboxResolver (with compiler) > should return a single error from typ
4
4
  {
5
5
  "errors": {
6
6
  "accessToken": {
7
- "message": "Required property",
7
+ "message": "Expected required property",
8
8
  "ref": undefined,
9
9
  "type": "45",
10
10
  },
@@ -14,7 +14,7 @@ exports[`typeboxResolver (with compiler) > should return a single error from typ
14
14
  "type": "41",
15
15
  },
16
16
  "dateStr": {
17
- "message": "Required property",
17
+ "message": "Expected required property",
18
18
  "ref": undefined,
19
19
  "type": "45",
20
20
  },
@@ -26,7 +26,7 @@ exports[`typeboxResolver (with compiler) > should return a single error from typ
26
26
  "type": "48",
27
27
  },
28
28
  "enabled": {
29
- "message": "Required property",
29
+ "message": "Expected required property",
30
30
  "ref": undefined,
31
31
  "type": "45",
32
32
  },
@@ -38,7 +38,7 @@ exports[`typeboxResolver (with compiler) > should return a single error from typ
38
38
  "type": "41",
39
39
  },
40
40
  "name": {
41
- "message": "Required property",
41
+ "message": "Expected required property",
42
42
  "ref": undefined,
43
43
  "type": "45",
44
44
  },
@@ -52,17 +52,17 @@ exports[`typeboxResolver (with compiler) > should return a single error from typ
52
52
  "type": "52",
53
53
  },
54
54
  "repeatPassword": {
55
- "message": "Required property",
55
+ "message": "Expected required property",
56
56
  "ref": undefined,
57
57
  "type": "45",
58
58
  },
59
59
  "tags": {
60
- "message": "Required property",
60
+ "message": "Expected required property",
61
61
  "ref": undefined,
62
62
  "type": "45",
63
63
  },
64
64
  "username": {
65
- "message": "Required property",
65
+ "message": "Expected required property",
66
66
  "ref": {
67
67
  "name": "username",
68
68
  },
@@ -77,11 +77,11 @@ exports[`typeboxResolver (with compiler) > should return all the errors from typ
77
77
  {
78
78
  "errors": {
79
79
  "accessToken": {
80
- "message": "Required property",
80
+ "message": "Expected required property",
81
81
  "ref": undefined,
82
82
  "type": "45",
83
83
  "types": {
84
- "45": "Required property",
84
+ "45": "Expected required property",
85
85
  "62": "Expected union value",
86
86
  },
87
87
  },
@@ -94,12 +94,12 @@ exports[`typeboxResolver (with compiler) > should return all the errors from typ
94
94
  },
95
95
  },
96
96
  "dateStr": {
97
- "message": "Required property",
97
+ "message": "Expected required property",
98
98
  "ref": undefined,
99
99
  "type": "45",
100
100
  "types": {
101
101
  "20": "Expected Date",
102
- "45": "Required property",
102
+ "45": "Expected required property",
103
103
  },
104
104
  },
105
105
  "email": {
@@ -113,12 +113,12 @@ exports[`typeboxResolver (with compiler) > should return all the errors from typ
113
113
  },
114
114
  },
115
115
  "enabled": {
116
- "message": "Required property",
116
+ "message": "Expected required property",
117
117
  "ref": undefined,
118
118
  "type": "45",
119
119
  "types": {
120
120
  "14": "Expected boolean",
121
- "45": "Required property",
121
+ "45": "Expected required property",
122
122
  },
123
123
  },
124
124
  "like": [
@@ -132,11 +132,11 @@ exports[`typeboxResolver (with compiler) > should return all the errors from typ
132
132
  },
133
133
  },
134
134
  "name": {
135
- "message": "Required property",
135
+ "message": "Expected required property",
136
136
  "ref": undefined,
137
137
  "type": "45",
138
138
  "types": {
139
- "45": "Required property",
139
+ "45": "Expected required property",
140
140
  "54": "Expected string",
141
141
  },
142
142
  },
@@ -154,31 +154,31 @@ exports[`typeboxResolver (with compiler) > should return all the errors from typ
154
154
  },
155
155
  },
156
156
  "repeatPassword": {
157
- "message": "Required property",
157
+ "message": "Expected required property",
158
158
  "ref": undefined,
159
159
  "type": "45",
160
160
  "types": {
161
- "45": "Required property",
161
+ "45": "Expected required property",
162
162
  "54": "Expected string",
163
163
  },
164
164
  },
165
165
  "tags": {
166
- "message": "Required property",
166
+ "message": "Expected required property",
167
167
  "ref": undefined,
168
168
  "type": "45",
169
169
  "types": {
170
- "45": "Required property",
170
+ "45": "Expected required property",
171
171
  "6": "Expected array",
172
172
  },
173
173
  },
174
174
  "username": {
175
- "message": "Required property",
175
+ "message": "Expected required property",
176
176
  "ref": {
177
177
  "name": "username",
178
178
  },
179
179
  "type": "45",
180
180
  "types": {
181
- "45": "Required property",
181
+ "45": "Expected required property",
182
182
  "54": "Expected string",
183
183
  },
184
184
  },
@@ -4,7 +4,7 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
4
4
  {
5
5
  "errors": {
6
6
  "accessToken": {
7
- "message": "Required property",
7
+ "message": "Expected required property",
8
8
  "ref": undefined,
9
9
  "type": "45",
10
10
  },
@@ -14,7 +14,7 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
14
14
  "type": "41",
15
15
  },
16
16
  "dateStr": {
17
- "message": "Required property",
17
+ "message": "Expected required property",
18
18
  "ref": undefined,
19
19
  "type": "45",
20
20
  },
@@ -26,7 +26,7 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
26
26
  "type": "48",
27
27
  },
28
28
  "enabled": {
29
- "message": "Required property",
29
+ "message": "Expected required property",
30
30
  "ref": undefined,
31
31
  "type": "45",
32
32
  },
@@ -38,7 +38,7 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
38
38
  "type": "41",
39
39
  },
40
40
  "name": {
41
- "message": "Required property",
41
+ "message": "Expected required property",
42
42
  "ref": undefined,
43
43
  "type": "45",
44
44
  },
@@ -52,17 +52,17 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
52
52
  "type": "52",
53
53
  },
54
54
  "repeatPassword": {
55
- "message": "Required property",
55
+ "message": "Expected required property",
56
56
  "ref": undefined,
57
57
  "type": "45",
58
58
  },
59
59
  "tags": {
60
- "message": "Required property",
60
+ "message": "Expected required property",
61
61
  "ref": undefined,
62
62
  "type": "45",
63
63
  },
64
64
  "username": {
65
- "message": "Required property",
65
+ "message": "Expected required property",
66
66
  "ref": {
67
67
  "name": "username",
68
68
  },
@@ -77,11 +77,11 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
77
77
  {
78
78
  "errors": {
79
79
  "accessToken": {
80
- "message": "Required property",
80
+ "message": "Expected required property",
81
81
  "ref": undefined,
82
82
  "type": "45",
83
83
  "types": {
84
- "45": "Required property",
84
+ "45": "Expected required property",
85
85
  "62": "Expected union value",
86
86
  },
87
87
  },
@@ -94,12 +94,12 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
94
94
  },
95
95
  },
96
96
  "dateStr": {
97
- "message": "Required property",
97
+ "message": "Expected required property",
98
98
  "ref": undefined,
99
99
  "type": "45",
100
100
  "types": {
101
101
  "20": "Expected Date",
102
- "45": "Required property",
102
+ "45": "Expected required property",
103
103
  },
104
104
  },
105
105
  "email": {
@@ -113,12 +113,12 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
113
113
  },
114
114
  },
115
115
  "enabled": {
116
- "message": "Required property",
116
+ "message": "Expected required property",
117
117
  "ref": undefined,
118
118
  "type": "45",
119
119
  "types": {
120
120
  "14": "Expected boolean",
121
- "45": "Required property",
121
+ "45": "Expected required property",
122
122
  },
123
123
  },
124
124
  "like": [
@@ -132,11 +132,11 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
132
132
  },
133
133
  },
134
134
  "name": {
135
- "message": "Required property",
135
+ "message": "Expected required property",
136
136
  "ref": undefined,
137
137
  "type": "45",
138
138
  "types": {
139
- "45": "Required property",
139
+ "45": "Expected required property",
140
140
  "54": "Expected string",
141
141
  },
142
142
  },
@@ -154,31 +154,31 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
154
154
  },
155
155
  },
156
156
  "repeatPassword": {
157
- "message": "Required property",
157
+ "message": "Expected required property",
158
158
  "ref": undefined,
159
159
  "type": "45",
160
160
  "types": {
161
- "45": "Required property",
161
+ "45": "Expected required property",
162
162
  "54": "Expected string",
163
163
  },
164
164
  },
165
165
  "tags": {
166
- "message": "Required property",
166
+ "message": "Expected required property",
167
167
  "ref": undefined,
168
168
  "type": "45",
169
169
  "types": {
170
- "45": "Required property",
170
+ "45": "Expected required property",
171
171
  "6": "Expected array",
172
172
  },
173
173
  },
174
174
  "username": {
175
- "message": "Required property",
175
+ "message": "Expected required property",
176
176
  "ref": {
177
177
  "name": "username",
178
178
  },
179
179
  "type": "45",
180
180
  "types": {
181
- "45": "Required property",
181
+ "45": "Expected required property",
182
182
  "54": "Expected string",
183
183
  },
184
184
  },
@@ -1,2 +1 @@
1
1
  export * from './typebox';
2
- export * from './types';