sitcod3 commited on
Commit
118cf05
·
verified ·
1 Parent(s): 3dc4fef

Upload folder using huggingface_hub (part 8)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. node_modules/@hookform/resolvers/typebox/dist/typebox.modern.mjs.map +1 -0
  2. node_modules/@hookform/resolvers/typebox/dist/typebox.module.js +2 -0
  3. node_modules/@hookform/resolvers/typebox/dist/typebox.module.js.map +1 -0
  4. node_modules/@hookform/resolvers/typebox/dist/typebox.umd.js +2 -0
  5. node_modules/@hookform/resolvers/typebox/dist/typebox.umd.js.map +1 -0
  6. node_modules/@hookform/resolvers/typebox/package.json +18 -0
  7. node_modules/@hookform/resolvers/typebox/src/__tests__/Form-compiler.tsx +53 -0
  8. node_modules/@hookform/resolvers/typebox/src/__tests__/Form-native-validation-compiler.tsx +86 -0
  9. node_modules/@hookform/resolvers/typebox/src/__tests__/Form-native-validation.tsx +83 -0
  10. node_modules/@hookform/resolvers/typebox/src/__tests__/Form.tsx +52 -0
  11. node_modules/@hookform/resolvers/typebox/src/__tests__/__fixtures__/data.ts +83 -0
  12. node_modules/@hookform/resolvers/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +188 -0
  13. node_modules/@hookform/resolvers/typebox/src/__tests__/__snapshots__/typebox.ts.snap +188 -0
  14. node_modules/@hookform/resolvers/typebox/src/__tests__/special-path-names.ts +21 -0
  15. node_modules/@hookform/resolvers/typebox/src/__tests__/typebox-compiler.ts +37 -0
  16. node_modules/@hookform/resolvers/typebox/src/__tests__/typebox.ts +145 -0
  17. node_modules/@hookform/resolvers/typebox/src/index.ts +1 -0
  18. node_modules/@hookform/resolvers/typebox/src/typebox.ts +94 -0
  19. node_modules/@hookform/resolvers/typeschema/dist/index.d.ts +1 -0
  20. node_modules/@hookform/resolvers/typeschema/dist/typeschema.d.ts +8 -0
  21. node_modules/@hookform/resolvers/typeschema/dist/typeschema.js +2 -0
  22. node_modules/@hookform/resolvers/typeschema/dist/typeschema.js.map +1 -0
  23. node_modules/@hookform/resolvers/typeschema/dist/typeschema.mjs +2 -0
  24. node_modules/@hookform/resolvers/typeschema/dist/typeschema.modern.mjs +2 -0
  25. node_modules/@hookform/resolvers/typeschema/dist/typeschema.modern.mjs.map +1 -0
  26. node_modules/@hookform/resolvers/typeschema/dist/typeschema.module.js +2 -0
  27. node_modules/@hookform/resolvers/typeschema/dist/typeschema.module.js.map +1 -0
  28. node_modules/@hookform/resolvers/typeschema/dist/typeschema.umd.js +2 -0
  29. node_modules/@hookform/resolvers/typeschema/dist/typeschema.umd.js.map +1 -0
  30. node_modules/@hookform/resolvers/typeschema/package.json +18 -0
  31. node_modules/@hookform/resolvers/typeschema/src/__tests__/Form-native-validation.tsx +81 -0
  32. node_modules/@hookform/resolvers/typeschema/src/__tests__/Form.tsx +50 -0
  33. node_modules/@hookform/resolvers/typeschema/src/__tests__/__fixtures__/data.ts +88 -0
  34. node_modules/@hookform/resolvers/typeschema/src/__tests__/__snapshots__/typeschema.ts.snap +225 -0
  35. node_modules/@hookform/resolvers/typeschema/src/__tests__/special-path-names.ts +21 -0
  36. node_modules/@hookform/resolvers/typeschema/src/__tests__/typeschema.ts +155 -0
  37. node_modules/@hookform/resolvers/typeschema/src/index.ts +1 -0
  38. node_modules/@hookform/resolvers/typeschema/src/typeschema.ts +117 -0
  39. node_modules/@hookform/resolvers/valibot/dist/index.d.ts +1 -0
  40. node_modules/@hookform/resolvers/valibot/dist/valibot.d.ts +10 -0
  41. node_modules/@hookform/resolvers/valibot/dist/valibot.js +2 -0
  42. node_modules/@hookform/resolvers/valibot/dist/valibot.js.map +1 -0
  43. node_modules/@hookform/resolvers/valibot/dist/valibot.mjs +2 -0
  44. node_modules/@hookform/resolvers/valibot/dist/valibot.modern.mjs +2 -0
  45. node_modules/@hookform/resolvers/valibot/dist/valibot.modern.mjs.map +1 -0
  46. node_modules/@hookform/resolvers/valibot/dist/valibot.module.js +2 -0
  47. node_modules/@hookform/resolvers/valibot/dist/valibot.module.js.map +1 -0
  48. node_modules/@hookform/resolvers/valibot/dist/valibot.umd.js +2 -0
  49. node_modules/@hookform/resolvers/valibot/dist/valibot.umd.js.map +1 -0
  50. node_modules/@hookform/resolvers/valibot/package.json +18 -0
node_modules/@hookform/resolvers/typebox/dist/typebox.modern.mjs.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"typebox.modern.mjs","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Static, StaticDecode, TObject } from '@sinclair/typebox';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport { FieldError, Resolver, appendErrors } from 'react-hook-form';\n\nfunction parseErrorSchema(\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) {\n // See the matching comment in the zod resolver's `parseZod3Issues`.\n const errors: Record<string, FieldError> = Object.create(null);\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 *\n * // Schemas using a custom/third-party `Kind` (e.g. ElysiaJS's `t.Files()`) must have\n * // that kind registered with TypeBox's own `TypeRegistry` before validating, since\n * // this resolver validates via `@sinclair/typebox`'s `Value.Errors`/`Value.Check`:\n * // TypeRegistry.Set('Files', (schema, value) => Array.isArray(value));\n */\nexport function typeboxResolver<Schema extends TObject, Context>(\n schema: Schema | TypeCheck<Schema>,\n): Resolver<Static<Schema>, Context, StaticDecode<Schema>> {\n return async (values: Static<Schema>, _, 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: {},\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","Object","create","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,SAASA,EACPC,EACAC,GAGA,MAAMC,EAAqCC,OAAOC,OAAO,MACzD,KAAOJ,EAAQK,QAAU,CACvB,MAAMC,EAAQN,EAAQ,IAChBO,KAAEA,EAAIC,QAAEA,EAAOC,KAAEA,GAASH,EAC1BI,EAAQD,EAAKE,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKV,EAAOQ,KACVR,EAAOQ,GAAS,CAAEF,UAASD,KAAM,GAAKA,IAGpCN,EAA0B,CAC5B,MAAMY,EAAQX,EAAOQ,GAAOG,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCL,EAAOQ,GAASK,EACdL,EACAT,EACAC,EACA,GAAKK,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAR,EAAQiB,OACV,CAEA,OAAOf,CACT,CAuBgB,SAAAgB,EACdC,GAEA,OAAOC,MAAOC,EAAwBC,EAAGC,KACvC,MAAMrB,EAASsB,MAAMC,KACnBN,aAAkBO,EACdP,EAAOQ,OAAON,GACdO,EAAMD,OAAOR,EAAQE,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAuB,CAAA,EAAIP,GAE3DrB,EAAOG,OAOL,CACLgB,OAAQ,CAAE,EACVnB,OAAQ6B,EACNhC,EACEG,GACCqB,EAAQM,2BAAsD,QAAzBN,EAAQS,cAEhDT,IAbK,CACLrB,OAAQ,CAAA,EACRmB,SAaH,CAEL"}
node_modules/@hookform/resolvers/typebox/dist/typebox.module.js ADDED
@@ -0,0 +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";function a(r,e){for(var o=Object.create(null);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 l=o[n].types,m=l&&l[""+a];o[n]=s(n,e,o,""+a,m?[].concat(m,t.message):t.message)}r.shift()}return o}function i(s){return function(i,n,l){try{var m=Array.from(s instanceof o?s.Errors(i):t.Errors(s,i));return l.shouldUseNativeValidation&&r({},l),Promise.resolve(m.length?{values:{},errors:e(a(m,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:i})}catch(r){return Promise.reject(r)}}}export{i as typeboxResolver};
2
+ //# sourceMappingURL=typebox.module.js.map
node_modules/@hookform/resolvers/typebox/dist/typebox.module.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"typebox.module.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Static, StaticDecode, TObject } from '@sinclair/typebox';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport { FieldError, Resolver, appendErrors } from 'react-hook-form';\n\nfunction parseErrorSchema(\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) {\n // See the matching comment in the zod resolver's `parseZod3Issues`.\n const errors: Record<string, FieldError> = Object.create(null);\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 *\n * // Schemas using a custom/third-party `Kind` (e.g. ElysiaJS's `t.Files()`) must have\n * // that kind registered with TypeBox's own `TypeRegistry` before validating, since\n * // this resolver validates via `@sinclair/typebox`'s `Value.Errors`/`Value.Check`:\n * // TypeRegistry.Set('Files', (schema, value) => Array.isArray(value));\n */\nexport function typeboxResolver<Schema extends TObject, Context>(\n schema: Schema | TypeCheck<Schema>,\n): Resolver<Static<Schema>, Context, StaticDecode<Schema>> {\n return async (values: Static<Schema>, _, 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: {},\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","Object","create","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,SAASA,EACPC,EACAC,GAIA,IADA,IAAMC,EAAqCC,OAAOC,OAAO,MAClDJ,EAAQK,QAAU,CACvB,IAAMC,EAAQN,EAAQ,GACdO,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKV,EAAOO,KACVP,EAAOO,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCN,EAA0B,CAC5B,IAAMY,EAAQX,EAAOO,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCL,EAAOO,GAASM,EACdN,EACAR,EACAC,EACA,GAAKK,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAR,EAAQiB,OACV,CAEA,OAAOf,CACT,CAuBM,SAAUgB,EACdC,GAEA,OAAcC,SAAAA,EAAwBC,EAAGC,GAAO,IAC9C,IAAMpB,EAASqB,MAAMC,KACnBL,aAAkBM,EACdN,EAAOO,OAAON,GACdO,EAAMD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAuB,CAAE,EAAEP,GAShEQ,QAAAC,QAPK7B,EAAOG,OAOL,CACLe,OAAQ,CAAE,EACVlB,OAAQ8B,EACNjC,EACEG,GACCoB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLpB,OAAQ,GACRkB,OAAAA,GAcN,CAAC,MAAAc,GAAAJ,OAAAA,QAAAK,OAAAD,EACH,CAAA,CAAA"}
node_modules/@hookform/resolvers/typebox/dist/typebox.umd.js ADDED
@@ -0,0 +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,t,s){function i(e,r){for(var o=Object.create(null);e.length;){var t=e[0],i=t.type,a=t.message,l=t.path.substring(1).replace(/\//g,".");if(o[l]||(o[l]={message:a,type:""+i}),r){var n=o[l].types,c=n&&n[""+i];o[l]=s.appendErrors(l,r,o,""+i,c?[].concat(c,t.message):t.message)}e.shift()}return o}e.typeboxResolver=function(e){return function(s,a,l){try{var n=Array.from(e instanceof o.TypeCheck?e.Errors(s):t.Value.Errors(e,s));return l.shouldUseNativeValidation&&r.validateFieldsNatively({},l),Promise.resolve(n.length?{values:{},errors:r.toNestErrors(i(n,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:s})}catch(e){return Promise.reject(e)}}}});
2
+ //# sourceMappingURL=typebox.umd.js.map
node_modules/@hookform/resolvers/typebox/dist/typebox.umd.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"typebox.umd.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Static, StaticDecode, TObject } from '@sinclair/typebox';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport { FieldError, Resolver, appendErrors } from 'react-hook-form';\n\nfunction parseErrorSchema(\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) {\n // See the matching comment in the zod resolver's `parseZod3Issues`.\n const errors: Record<string, FieldError> = Object.create(null);\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 *\n * // Schemas using a custom/third-party `Kind` (e.g. ElysiaJS's `t.Files()`) must have\n * // that kind registered with TypeBox's own `TypeRegistry` before validating, since\n * // this resolver validates via `@sinclair/typebox`'s `Value.Errors`/`Value.Check`:\n * // TypeRegistry.Set('Files', (schema, value) => Array.isArray(value));\n */\nexport function typeboxResolver<Schema extends TObject, Context>(\n schema: Schema | TypeCheck<Schema>,\n): Resolver<Static<Schema>, Context, StaticDecode<Schema>> {\n return async (values: Static<Schema>, _, 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: {},\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","Object","create","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,SAASA,EACPC,EACAC,GAIA,IADA,IAAMC,EAAqCC,OAAOC,OAAO,MAClDJ,EAAQK,QAAU,CACvB,IAAMC,EAAQN,EAAQ,GACdO,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKV,EAAOO,KACVP,EAAOO,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCN,EAA0B,CAC5B,IAAMY,EAAQX,EAAOO,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCL,EAAOO,GAASM,EAAAA,aACdN,EACAR,EACAC,EACA,GAAKK,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAR,EAAQiB,OACV,CAEA,OAAOf,CACT,mBAuBM,SACJgB,GAEA,OAAcC,SAAAA,EAAwBC,EAAGC,GAAO,IAC9C,IAAMnB,EAASoB,MAAMC,KACnBL,aAAkBM,EAASA,UACvBN,EAAOO,OAAON,GACdO,EAAKA,MAACD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEP,GAShEQ,QAAAC,QAPK5B,EAAOG,OAOL,CACLc,OAAQ,CAAE,EACVjB,OAAQ6B,EAAAA,aACNhC,EACEG,GACCmB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLnB,OAAQ,GACRiB,OAAAA,GAcN,CAAC,MAAAc,GAAAJ,OAAAA,QAAAK,OAAAD,EACH,CAAA,CAAA"}
node_modules/@hookform/resolvers/typebox/package.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@hookform/resolvers/typebox",
3
+ "amdName": "hookformResolversTypebox",
4
+ "version": "1.0.0",
5
+ "private": true,
6
+ "description": "React Hook Form validation resolver: typebox",
7
+ "main": "dist/typebox.js",
8
+ "module": "dist/typebox.module.js",
9
+ "umd:main": "dist/typebox.umd.js",
10
+ "source": "src/index.ts",
11
+ "types": "dist/index.d.ts",
12
+ "license": "MIT",
13
+ "peerDependencies": {
14
+ "react-hook-form": "^7.55.0",
15
+ "@hookform/resolvers": "^2.0.0",
16
+ "@sinclair/typebox": "^0.25.24"
17
+ }
18
+ }
node_modules/@hookform/resolvers/typebox/src/__tests__/Form-compiler.tsx ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Static, Type } from '@sinclair/typebox';
2
+ import { TypeCompiler } from '@sinclair/typebox/compiler';
3
+ import { render, screen } from '@testing-library/react';
4
+ import user from '@testing-library/user-event';
5
+ import React from 'react';
6
+ import { useForm } from 'react-hook-form';
7
+ import { typeboxResolver } from '..';
8
+
9
+ const schema = Type.Object({
10
+ username: Type.String({ minLength: 1 }),
11
+ password: Type.String({ minLength: 1 }),
12
+ });
13
+
14
+ const typecheck = TypeCompiler.Compile(schema);
15
+
16
+ function TestComponent({
17
+ onSubmit,
18
+ }: { onSubmit: (data: Static<typeof schema>) => void }) {
19
+ const {
20
+ register,
21
+ handleSubmit,
22
+ formState: { errors },
23
+ } = useForm({
24
+ resolver: typeboxResolver(typecheck), // Useful to check TypeScript regressions
25
+ });
26
+
27
+ return (
28
+ <form onSubmit={handleSubmit(onSubmit)}>
29
+ <input {...register('username')} />
30
+ {errors.username && <span role="alert">{errors.username.message}</span>}
31
+
32
+ <input {...register('password')} />
33
+ {errors.password && <span role="alert">{errors.password.message}</span>}
34
+
35
+ <button type="submit">submit</button>
36
+ </form>
37
+ );
38
+ }
39
+
40
+ test("form's validation with Typebox (with compiler) and TypeScript's integration", async () => {
41
+ const handleSubmit = vi.fn();
42
+ render(<TestComponent onSubmit={handleSubmit} />);
43
+
44
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
45
+
46
+ await user.click(screen.getByText(/submit/i));
47
+
48
+ expect(
49
+ screen.getAllByText(/Expected string length greater or equal to 1/i),
50
+ ).toHaveLength(2);
51
+
52
+ expect(handleSubmit).not.toHaveBeenCalled();
53
+ });
node_modules/@hookform/resolvers/typebox/src/__tests__/Form-native-validation-compiler.tsx ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import React from 'react';
4
+ import { useForm } from 'react-hook-form';
5
+ import { typeboxResolver } from '..';
6
+
7
+ import { Static, Type } from '@sinclair/typebox';
8
+ import { TypeCompiler } from '@sinclair/typebox/compiler';
9
+
10
+ const schema = Type.Object({
11
+ username: Type.String({ minLength: 1 }),
12
+ password: Type.String({ minLength: 1 }),
13
+ });
14
+
15
+ const typecheck = TypeCompiler.Compile(schema);
16
+
17
+ type FormData = Static<typeof schema>;
18
+
19
+ interface Props {
20
+ onSubmit: (data: FormData) => void;
21
+ }
22
+
23
+ function TestComponent({ onSubmit }: Props) {
24
+ const { register, handleSubmit } = useForm({
25
+ resolver: typeboxResolver(typecheck),
26
+ shouldUseNativeValidation: true,
27
+ });
28
+
29
+ return (
30
+ <form onSubmit={handleSubmit(onSubmit)}>
31
+ <input {...register('username')} placeholder="username" />
32
+
33
+ <input {...register('password')} placeholder="password" />
34
+
35
+ <button type="submit">submit</button>
36
+ </form>
37
+ );
38
+ }
39
+
40
+ test("form's native validation with Typebox (with compiler)", async () => {
41
+ const handleSubmit = vi.fn();
42
+ render(<TestComponent onSubmit={handleSubmit} />);
43
+
44
+ // username
45
+ let usernameField = screen.getByPlaceholderText(
46
+ /username/i,
47
+ ) as HTMLInputElement;
48
+ expect(usernameField.validity.valid).toBe(true);
49
+ expect(usernameField.validationMessage).toBe('');
50
+
51
+ // password
52
+ let passwordField = screen.getByPlaceholderText(
53
+ /password/i,
54
+ ) as HTMLInputElement;
55
+ expect(passwordField.validity.valid).toBe(true);
56
+ expect(passwordField.validationMessage).toBe('');
57
+
58
+ await user.click(screen.getByText(/submit/i));
59
+
60
+ // username
61
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
62
+ expect(usernameField.validity.valid).toBe(false);
63
+ expect(usernameField.validationMessage).toBe(
64
+ 'Expected string length greater or equal to 1',
65
+ );
66
+
67
+ // password
68
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
69
+ expect(passwordField.validity.valid).toBe(false);
70
+ expect(passwordField.validationMessage).toBe(
71
+ 'Expected string length greater or equal to 1',
72
+ );
73
+
74
+ await user.type(screen.getByPlaceholderText(/username/i), 'joe');
75
+ await user.type(screen.getByPlaceholderText(/password/i), 'password');
76
+
77
+ // username
78
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
79
+ expect(usernameField.validity.valid).toBe(true);
80
+ expect(usernameField.validationMessage).toBe('');
81
+
82
+ // password
83
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
84
+ expect(passwordField.validity.valid).toBe(true);
85
+ expect(passwordField.validationMessage).toBe('');
86
+ });
node_modules/@hookform/resolvers/typebox/src/__tests__/Form-native-validation.tsx ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import React from 'react';
4
+ import { useForm } from 'react-hook-form';
5
+ import { typeboxResolver } from '..';
6
+
7
+ import { Static, Type } from '@sinclair/typebox';
8
+
9
+ const schema = Type.Object({
10
+ username: Type.String({ minLength: 1 }),
11
+ password: Type.String({ minLength: 1 }),
12
+ });
13
+
14
+ type FormData = Static<typeof schema>;
15
+
16
+ interface Props {
17
+ onSubmit: (data: FormData) => void;
18
+ }
19
+
20
+ function TestComponent({ onSubmit }: Props) {
21
+ const { register, handleSubmit } = useForm<FormData>({
22
+ resolver: typeboxResolver(schema),
23
+ shouldUseNativeValidation: true,
24
+ });
25
+
26
+ return (
27
+ <form onSubmit={handleSubmit(onSubmit)}>
28
+ <input {...register('username')} placeholder="username" />
29
+
30
+ <input {...register('password')} placeholder="password" />
31
+
32
+ <button type="submit">submit</button>
33
+ </form>
34
+ );
35
+ }
36
+
37
+ test("form's native validation with Typebox", async () => {
38
+ const handleSubmit = vi.fn();
39
+ render(<TestComponent onSubmit={handleSubmit} />);
40
+
41
+ // username
42
+ let usernameField = screen.getByPlaceholderText(
43
+ /username/i,
44
+ ) as HTMLInputElement;
45
+ expect(usernameField.validity.valid).toBe(true);
46
+ expect(usernameField.validationMessage).toBe('');
47
+
48
+ // password
49
+ let passwordField = screen.getByPlaceholderText(
50
+ /password/i,
51
+ ) as HTMLInputElement;
52
+ expect(passwordField.validity.valid).toBe(true);
53
+ expect(passwordField.validationMessage).toBe('');
54
+
55
+ await user.click(screen.getByText(/submit/i));
56
+
57
+ // username
58
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
59
+ expect(usernameField.validity.valid).toBe(false);
60
+ expect(usernameField.validationMessage).toBe(
61
+ 'Expected string length greater or equal to 1',
62
+ );
63
+
64
+ // password
65
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
66
+ expect(passwordField.validity.valid).toBe(false);
67
+ expect(passwordField.validationMessage).toBe(
68
+ 'Expected string length greater or equal to 1',
69
+ );
70
+
71
+ await user.type(screen.getByPlaceholderText(/username/i), 'joe');
72
+ await user.type(screen.getByPlaceholderText(/password/i), 'password');
73
+
74
+ // username
75
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
76
+ expect(usernameField.validity.valid).toBe(true);
77
+ expect(usernameField.validationMessage).toBe('');
78
+
79
+ // password
80
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
81
+ expect(passwordField.validity.valid).toBe(true);
82
+ expect(passwordField.validationMessage).toBe('');
83
+ });
node_modules/@hookform/resolvers/typebox/src/__tests__/Form.tsx ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Static, Type } from '@sinclair/typebox';
2
+ import { render, screen } from '@testing-library/react';
3
+ import user from '@testing-library/user-event';
4
+ import React from 'react';
5
+ import { useForm } from 'react-hook-form';
6
+ import { typeboxResolver } from '..';
7
+
8
+ const schema = Type.Object({
9
+ username: Type.String({ minLength: 1 }),
10
+ password: Type.String({ minLength: 1 }),
11
+ });
12
+
13
+ function TestComponent({
14
+ onSubmit,
15
+ }: {
16
+ onSubmit: (data: Static<typeof schema>) => void;
17
+ }) {
18
+ const {
19
+ register,
20
+ handleSubmit,
21
+ formState: { errors },
22
+ } = useForm({
23
+ resolver: typeboxResolver(schema), // Useful to check TypeScript regressions
24
+ });
25
+
26
+ return (
27
+ <form onSubmit={handleSubmit(onSubmit)}>
28
+ <input {...register('username')} />
29
+ {errors.username && <span role="alert">{errors.username.message}</span>}
30
+
31
+ <input {...register('password')} />
32
+ {errors.password && <span role="alert">{errors.password.message}</span>}
33
+
34
+ <button type="submit">submit</button>
35
+ </form>
36
+ );
37
+ }
38
+
39
+ test("form's validation with Typebox and TypeScript's integration", async () => {
40
+ const handleSubmit = vi.fn();
41
+ render(<TestComponent onSubmit={handleSubmit} />);
42
+
43
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
44
+
45
+ await user.click(screen.getByText(/submit/i));
46
+
47
+ expect(
48
+ screen.getAllByText(/Expected string length greater or equal to 1/i),
49
+ ).toHaveLength(2);
50
+
51
+ expect(handleSubmit).not.toHaveBeenCalled();
52
+ });
node_modules/@hookform/resolvers/typebox/src/__tests__/__fixtures__/data.ts ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { StaticDecode, Type } from '@sinclair/typebox';
2
+ import { Field, InternalFieldName } from 'react-hook-form';
3
+
4
+ export const schema = Type.Object({
5
+ username: Type.String({
6
+ minLength: 3,
7
+ maxLength: 30,
8
+ pattern: '^[a-zA-Z0-9]+$',
9
+ }),
10
+ password: Type.String({
11
+ minLength: 8,
12
+ pattern: '^(.*[A-Za-z\\d].*)$',
13
+ }),
14
+ repeatPassword: Type.String(),
15
+ accessToken: Type.Union([Type.String(), Type.Number()]),
16
+ birthYear: Type.Optional(
17
+ Type.Number({
18
+ minimum: 1900,
19
+ maximum: 2013,
20
+ }),
21
+ ),
22
+ email: Type.Optional(
23
+ Type.RegExp(
24
+ /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
25
+ ),
26
+ ),
27
+ tags: Type.Array(Type.String()),
28
+ enabled: Type.Boolean(),
29
+ like: Type.Optional(
30
+ Type.Array(
31
+ Type.Object({
32
+ id: Type.Number(),
33
+ name: Type.String({ minLength: 4, maxLength: 4 }),
34
+ }),
35
+ ),
36
+ ),
37
+ dateStr: Type.Date(),
38
+ });
39
+
40
+ export const validData: StaticDecode<typeof schema> = {
41
+ username: 'Doe',
42
+ password: 'Password123_',
43
+ repeatPassword: 'Password123_',
44
+ birthYear: 2000,
45
+ email: 'google@gmail.com',
46
+ tags: ['tag1', 'tag2'],
47
+ enabled: true,
48
+ accessToken: 'accessToken',
49
+ like: [
50
+ {
51
+ id: 1,
52
+ name: 'name',
53
+ },
54
+ ],
55
+ dateStr: new Date(),
56
+ };
57
+
58
+ export const invalidData = {
59
+ password: '___',
60
+ email: '',
61
+ birthYear: 'birthYear',
62
+ like: [{ id: 'z' }],
63
+ url: 'abc',
64
+ } as unknown as StaticDecode<typeof schema>;
65
+
66
+ export const fields: Record<InternalFieldName, Field['_f']> = {
67
+ username: {
68
+ ref: { name: 'username' },
69
+ name: 'username',
70
+ },
71
+ password: {
72
+ ref: { name: 'password' },
73
+ name: 'password',
74
+ },
75
+ email: {
76
+ ref: { name: 'email' },
77
+ name: 'email',
78
+ },
79
+ birthday: {
80
+ ref: { name: 'birthday' },
81
+ name: 'birthday',
82
+ },
83
+ };
node_modules/@hookform/resolvers/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`typeboxResolver (with compiler) > should return a single error from typeboxResolver when validation fails 1`] = `
4
+ {
5
+ "errors": {
6
+ "accessToken": {
7
+ "message": "Expected required property",
8
+ "ref": undefined,
9
+ "type": "45",
10
+ },
11
+ "birthYear": {
12
+ "message": "Expected number",
13
+ "ref": undefined,
14
+ "type": "41",
15
+ },
16
+ "dateStr": {
17
+ "message": "Expected required property",
18
+ "ref": undefined,
19
+ "type": "45",
20
+ },
21
+ "email": {
22
+ "message": "Expected string to match regular expression",
23
+ "ref": {
24
+ "name": "email",
25
+ },
26
+ "type": "48",
27
+ },
28
+ "enabled": {
29
+ "message": "Expected required property",
30
+ "ref": undefined,
31
+ "type": "45",
32
+ },
33
+ "like": [
34
+ {
35
+ "id": {
36
+ "message": "Expected number",
37
+ "ref": undefined,
38
+ "type": "41",
39
+ },
40
+ "name": {
41
+ "message": "Expected required property",
42
+ "ref": undefined,
43
+ "type": "45",
44
+ },
45
+ },
46
+ ],
47
+ "password": {
48
+ "message": "Expected string length greater or equal to 8",
49
+ "ref": {
50
+ "name": "password",
51
+ },
52
+ "type": "52",
53
+ },
54
+ "repeatPassword": {
55
+ "message": "Expected required property",
56
+ "ref": undefined,
57
+ "type": "45",
58
+ },
59
+ "tags": {
60
+ "message": "Expected required property",
61
+ "ref": undefined,
62
+ "type": "45",
63
+ },
64
+ "username": {
65
+ "message": "Expected required property",
66
+ "ref": {
67
+ "name": "username",
68
+ },
69
+ "type": "45",
70
+ },
71
+ },
72
+ "values": {},
73
+ }
74
+ `;
75
+
76
+ exports[`typeboxResolver (with compiler) > should return all the errors from typeboxResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
77
+ {
78
+ "errors": {
79
+ "accessToken": {
80
+ "message": "Expected required property",
81
+ "ref": undefined,
82
+ "type": "45",
83
+ "types": {
84
+ "45": "Expected required property",
85
+ "62": "Expected union value",
86
+ },
87
+ },
88
+ "birthYear": {
89
+ "message": "Expected number",
90
+ "ref": undefined,
91
+ "type": "41",
92
+ "types": {
93
+ "41": "Expected number",
94
+ },
95
+ },
96
+ "dateStr": {
97
+ "message": "Expected required property",
98
+ "ref": undefined,
99
+ "type": "45",
100
+ "types": {
101
+ "20": "Expected Date",
102
+ "45": "Expected required property",
103
+ },
104
+ },
105
+ "email": {
106
+ "message": "Expected string to match regular expression",
107
+ "ref": {
108
+ "name": "email",
109
+ },
110
+ "type": "48",
111
+ "types": {
112
+ "48": "Expected string to match regular expression",
113
+ },
114
+ },
115
+ "enabled": {
116
+ "message": "Expected required property",
117
+ "ref": undefined,
118
+ "type": "45",
119
+ "types": {
120
+ "14": "Expected boolean",
121
+ "45": "Expected required property",
122
+ },
123
+ },
124
+ "like": [
125
+ {
126
+ "id": {
127
+ "message": "Expected number",
128
+ "ref": undefined,
129
+ "type": "41",
130
+ "types": {
131
+ "41": "Expected number",
132
+ },
133
+ },
134
+ "name": {
135
+ "message": "Expected required property",
136
+ "ref": undefined,
137
+ "type": "45",
138
+ "types": {
139
+ "45": "Expected required property",
140
+ "54": "Expected string",
141
+ },
142
+ },
143
+ },
144
+ ],
145
+ "password": {
146
+ "message": "Expected string length greater or equal to 8",
147
+ "ref": {
148
+ "name": "password",
149
+ },
150
+ "type": "52",
151
+ "types": {
152
+ "52": "Expected string length greater or equal to 8",
153
+ "53": "Expected string to match '^(.*[A-Za-z\\d].*)$'",
154
+ },
155
+ },
156
+ "repeatPassword": {
157
+ "message": "Expected required property",
158
+ "ref": undefined,
159
+ "type": "45",
160
+ "types": {
161
+ "45": "Expected required property",
162
+ "54": "Expected string",
163
+ },
164
+ },
165
+ "tags": {
166
+ "message": "Expected required property",
167
+ "ref": undefined,
168
+ "type": "45",
169
+ "types": {
170
+ "45": "Expected required property",
171
+ "6": "Expected array",
172
+ },
173
+ },
174
+ "username": {
175
+ "message": "Expected required property",
176
+ "ref": {
177
+ "name": "username",
178
+ },
179
+ "type": "45",
180
+ "types": {
181
+ "45": "Expected required property",
182
+ "54": "Expected string",
183
+ },
184
+ },
185
+ },
186
+ "values": {},
187
+ }
188
+ `;
node_modules/@hookform/resolvers/typebox/src/__tests__/__snapshots__/typebox.ts.snap ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`typeboxResolver > should return a single error from typeboxResolver when validation fails 1`] = `
4
+ {
5
+ "errors": {
6
+ "accessToken": {
7
+ "message": "Expected required property",
8
+ "ref": undefined,
9
+ "type": "45",
10
+ },
11
+ "birthYear": {
12
+ "message": "Expected number",
13
+ "ref": undefined,
14
+ "type": "41",
15
+ },
16
+ "dateStr": {
17
+ "message": "Expected required property",
18
+ "ref": undefined,
19
+ "type": "45",
20
+ },
21
+ "email": {
22
+ "message": "Expected string to match regular expression",
23
+ "ref": {
24
+ "name": "email",
25
+ },
26
+ "type": "48",
27
+ },
28
+ "enabled": {
29
+ "message": "Expected required property",
30
+ "ref": undefined,
31
+ "type": "45",
32
+ },
33
+ "like": [
34
+ {
35
+ "id": {
36
+ "message": "Expected number",
37
+ "ref": undefined,
38
+ "type": "41",
39
+ },
40
+ "name": {
41
+ "message": "Expected required property",
42
+ "ref": undefined,
43
+ "type": "45",
44
+ },
45
+ },
46
+ ],
47
+ "password": {
48
+ "message": "Expected string length greater or equal to 8",
49
+ "ref": {
50
+ "name": "password",
51
+ },
52
+ "type": "52",
53
+ },
54
+ "repeatPassword": {
55
+ "message": "Expected required property",
56
+ "ref": undefined,
57
+ "type": "45",
58
+ },
59
+ "tags": {
60
+ "message": "Expected required property",
61
+ "ref": undefined,
62
+ "type": "45",
63
+ },
64
+ "username": {
65
+ "message": "Expected required property",
66
+ "ref": {
67
+ "name": "username",
68
+ },
69
+ "type": "45",
70
+ },
71
+ },
72
+ "values": {},
73
+ }
74
+ `;
75
+
76
+ exports[`typeboxResolver > should return all the errors from typeboxResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
77
+ {
78
+ "errors": {
79
+ "accessToken": {
80
+ "message": "Expected required property",
81
+ "ref": undefined,
82
+ "type": "45",
83
+ "types": {
84
+ "45": "Expected required property",
85
+ "62": "Expected union value",
86
+ },
87
+ },
88
+ "birthYear": {
89
+ "message": "Expected number",
90
+ "ref": undefined,
91
+ "type": "41",
92
+ "types": {
93
+ "41": "Expected number",
94
+ },
95
+ },
96
+ "dateStr": {
97
+ "message": "Expected required property",
98
+ "ref": undefined,
99
+ "type": "45",
100
+ "types": {
101
+ "20": "Expected Date",
102
+ "45": "Expected required property",
103
+ },
104
+ },
105
+ "email": {
106
+ "message": "Expected string to match regular expression",
107
+ "ref": {
108
+ "name": "email",
109
+ },
110
+ "type": "48",
111
+ "types": {
112
+ "48": "Expected string to match regular expression",
113
+ },
114
+ },
115
+ "enabled": {
116
+ "message": "Expected required property",
117
+ "ref": undefined,
118
+ "type": "45",
119
+ "types": {
120
+ "14": "Expected boolean",
121
+ "45": "Expected required property",
122
+ },
123
+ },
124
+ "like": [
125
+ {
126
+ "id": {
127
+ "message": "Expected number",
128
+ "ref": undefined,
129
+ "type": "41",
130
+ "types": {
131
+ "41": "Expected number",
132
+ },
133
+ },
134
+ "name": {
135
+ "message": "Expected required property",
136
+ "ref": undefined,
137
+ "type": "45",
138
+ "types": {
139
+ "45": "Expected required property",
140
+ "54": "Expected string",
141
+ },
142
+ },
143
+ },
144
+ ],
145
+ "password": {
146
+ "message": "Expected string length greater or equal to 8",
147
+ "ref": {
148
+ "name": "password",
149
+ },
150
+ "type": "52",
151
+ "types": {
152
+ "52": "Expected string length greater or equal to 8",
153
+ "53": "Expected string to match '^(.*[A-Za-z\\d].*)$'",
154
+ },
155
+ },
156
+ "repeatPassword": {
157
+ "message": "Expected required property",
158
+ "ref": undefined,
159
+ "type": "45",
160
+ "types": {
161
+ "45": "Expected required property",
162
+ "54": "Expected string",
163
+ },
164
+ },
165
+ "tags": {
166
+ "message": "Expected required property",
167
+ "ref": undefined,
168
+ "type": "45",
169
+ "types": {
170
+ "45": "Expected required property",
171
+ "6": "Expected array",
172
+ },
173
+ },
174
+ "username": {
175
+ "message": "Expected required property",
176
+ "ref": {
177
+ "name": "username",
178
+ },
179
+ "type": "45",
180
+ "types": {
181
+ "45": "Expected required property",
182
+ "54": "Expected string",
183
+ },
184
+ },
185
+ },
186
+ "values": {},
187
+ }
188
+ `;
node_modules/@hookform/resolvers/typebox/src/__tests__/special-path-names.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Type } from '@sinclair/typebox';
2
+ import { typeboxResolver } from '..';
3
+
4
+ const shouldUseNativeValidation = false;
5
+
6
+ describe('typeboxResolver special path names', () => {
7
+ it.each(['hasOwnProperty', 'toString'])(
8
+ 'reports a validation error for a field named "%s"',
9
+ async (name) => {
10
+ const schema = Type.Object({ [name]: Type.String({ minLength: 1 }) });
11
+
12
+ const result = await typeboxResolver(schema as any)(
13
+ { [name]: '' } as any,
14
+ undefined,
15
+ { fields: {}, shouldUseNativeValidation } as any,
16
+ );
17
+
18
+ expect(result.errors[name]).toBeDefined();
19
+ },
20
+ );
21
+ });
node_modules/@hookform/resolvers/typebox/src/__tests__/typebox-compiler.ts ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { TypeCompiler } from '@sinclair/typebox/compiler';
2
+ import { typeboxResolver } from '..';
3
+ import { fields, invalidData, schema, validData } from './__fixtures__/data';
4
+
5
+ const shouldUseNativeValidation = false;
6
+
7
+ describe('typeboxResolver (with compiler)', () => {
8
+ const typecheck = TypeCompiler.Compile(schema);
9
+
10
+ it('should return a single error from typeboxResolver when validation fails', async () => {
11
+ const result = await typeboxResolver(typecheck)(invalidData, undefined, {
12
+ fields,
13
+ shouldUseNativeValidation,
14
+ });
15
+
16
+ expect(result).toMatchSnapshot();
17
+ });
18
+
19
+ it('should return all the errors from typeboxResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
20
+ const result = await typeboxResolver(typecheck)(invalidData, undefined, {
21
+ fields,
22
+ criteriaMode: 'all',
23
+ shouldUseNativeValidation,
24
+ });
25
+
26
+ expect(result).toMatchSnapshot();
27
+ });
28
+
29
+ it('should validate with success', async () => {
30
+ const result = await typeboxResolver(typecheck)(validData, undefined, {
31
+ fields,
32
+ shouldUseNativeValidation,
33
+ });
34
+
35
+ expect(result).toEqual({ errors: {}, values: validData });
36
+ });
37
+ });
node_modules/@hookform/resolvers/typebox/src/__tests__/typebox.ts ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Type } from '@sinclair/typebox';
2
+ import { TypeCompiler } from '@sinclair/typebox/compiler';
3
+ import { renderHook } from '@testing-library/react';
4
+ import { Resolver, SubmitHandler, useForm } from 'react-hook-form';
5
+ import { typeboxResolver } from '..';
6
+ import { fields, invalidData, schema, validData } from './__fixtures__/data';
7
+
8
+ const shouldUseNativeValidation = false;
9
+
10
+ describe('typeboxResolver', () => {
11
+ it('should return a single error from typeboxResolver when validation fails', async () => {
12
+ const result = await typeboxResolver(schema)(invalidData, undefined, {
13
+ fields,
14
+ shouldUseNativeValidation,
15
+ });
16
+
17
+ expect(result).toMatchSnapshot();
18
+ });
19
+
20
+ it('should return all the errors from typeboxResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
21
+ const result = await typeboxResolver(schema)(invalidData, undefined, {
22
+ fields,
23
+ criteriaMode: 'all',
24
+ shouldUseNativeValidation,
25
+ });
26
+
27
+ expect(result).toMatchSnapshot();
28
+ });
29
+
30
+ it('should validate with success', async () => {
31
+ const result = await typeboxResolver(schema)(validData, undefined, {
32
+ fields,
33
+ shouldUseNativeValidation,
34
+ });
35
+
36
+ expect(result).toEqual({ errors: {}, values: validData });
37
+ });
38
+
39
+ /**
40
+ * Type inference tests
41
+ */
42
+ it('should correctly infer the output type from a typebox schema', () => {
43
+ const resolver = typeboxResolver(Type.Object({ id: Type.Number() }));
44
+
45
+ expectTypeOf(resolver).toEqualTypeOf<
46
+ Resolver<{ id: number }, unknown, { id: number }>
47
+ >();
48
+ });
49
+
50
+ it('should correctly infer the output type from a typebox schema with TypeCompiler', () => {
51
+ const typecheck = TypeCompiler.Compile(Type.Object({ id: Type.Number() }));
52
+ const resolver = typeboxResolver(typecheck);
53
+
54
+ expectTypeOf(resolver).toEqualTypeOf<
55
+ Resolver<{ id: number }, unknown, { id: number }>
56
+ >();
57
+ });
58
+
59
+ it('should correctly infer the output type from a typebox schema using a transform', () => {
60
+ const resolver = typeboxResolver(
61
+ Type.Object({
62
+ id: Type.Transform(Type.Number())
63
+ .Decode((v) => String(v))
64
+ .Encode((v) => Number.parseInt(v)),
65
+ }),
66
+ );
67
+
68
+ expectTypeOf(resolver).toEqualTypeOf<
69
+ Resolver<{ id: number }, unknown, { id: string }>
70
+ >();
71
+ });
72
+
73
+ it('should correctly infer the output type from a typebox schema for the handleSubmit function in useForm', () => {
74
+ const schema = Type.Object({ id: Type.Number() });
75
+
76
+ const {
77
+ result: { current: form },
78
+ } = renderHook(() =>
79
+ useForm({
80
+ resolver: typeboxResolver(schema),
81
+ defaultValues: {
82
+ id: 3,
83
+ },
84
+ }),
85
+ );
86
+
87
+ expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
88
+
89
+ expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
90
+ SubmitHandler<{
91
+ id: number;
92
+ }>
93
+ >();
94
+ });
95
+
96
+ it('should correctly infer the output type from a typebox schema with TypeCompiler for the handleSubmit function in useForm', () => {
97
+ const typecheck = TypeCompiler.Compile(Type.Object({ id: Type.Number() }));
98
+
99
+ const {
100
+ result: { current: form },
101
+ } = renderHook(() =>
102
+ useForm({
103
+ resolver: typeboxResolver(typecheck),
104
+ defaultValues: {
105
+ id: 3,
106
+ },
107
+ }),
108
+ );
109
+
110
+ expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
111
+
112
+ expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
113
+ SubmitHandler<{
114
+ id: number;
115
+ }>
116
+ >();
117
+ });
118
+
119
+ it('should correctly infer the output type from a typebox schema with a transform for the handleSubmit function in useForm', () => {
120
+ const schema = Type.Object({
121
+ id: Type.Transform(Type.Number())
122
+ .Decode((v) => String(v))
123
+ .Encode((v) => Number.parseInt(v)),
124
+ });
125
+
126
+ const {
127
+ result: { current: form },
128
+ } = renderHook(() =>
129
+ useForm({
130
+ resolver: typeboxResolver(schema),
131
+ defaultValues: {
132
+ id: 3,
133
+ },
134
+ }),
135
+ );
136
+
137
+ expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
138
+
139
+ expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
140
+ SubmitHandler<{
141
+ id: string;
142
+ }>
143
+ >();
144
+ });
145
+ });
node_modules/@hookform/resolvers/typebox/src/index.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export * from './typebox';
node_modules/@hookform/resolvers/typebox/src/typebox.ts ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
2
+ import { Static, StaticDecode, TObject } from '@sinclair/typebox';
3
+ import { TypeCheck } from '@sinclair/typebox/compiler';
4
+ import { Value, type ValueError } from '@sinclair/typebox/value';
5
+ import { FieldError, Resolver, appendErrors } from 'react-hook-form';
6
+
7
+ function parseErrorSchema(
8
+ _errors: ValueError[],
9
+ validateAllFieldCriteria: boolean,
10
+ ) {
11
+ // See the matching comment in the zod resolver's `parseZod3Issues`.
12
+ const errors: Record<string, FieldError> = Object.create(null);
13
+ for (; _errors.length; ) {
14
+ const error = _errors[0];
15
+ const { type, message, path } = error;
16
+ const _path = path.substring(1).replace(/\//g, '.');
17
+
18
+ if (!errors[_path]) {
19
+ errors[_path] = { message, type: '' + type };
20
+ }
21
+
22
+ if (validateAllFieldCriteria) {
23
+ const types = errors[_path].types;
24
+ const messages = types && types['' + type];
25
+
26
+ errors[_path] = appendErrors(
27
+ _path,
28
+ validateAllFieldCriteria,
29
+ errors,
30
+ '' + type,
31
+ messages
32
+ ? ([] as string[]).concat(messages as string[], error.message)
33
+ : error.message,
34
+ ) as FieldError;
35
+ }
36
+
37
+ _errors.shift();
38
+ }
39
+
40
+ return errors;
41
+ }
42
+
43
+ /**
44
+ * Creates a resolver for react-hook-form using Typebox schema validation
45
+ * @param {Schema | TypeCheck<Schema>} schema - The Typebox schema to validate against
46
+ * @param {Object} options - Additional resolver configuration
47
+ * @param {string} [options.mode='async'] - Validation mode
48
+ * @returns {Resolver<Static<Schema>>} A resolver function compatible with react-hook-form
49
+ * @example
50
+ * const schema = Type.Object({
51
+ * name: Type.String(),
52
+ * age: Type.Number()
53
+ * });
54
+ *
55
+ * useForm({
56
+ * resolver: typeboxResolver(schema)
57
+ * });
58
+ *
59
+ * // Schemas using a custom/third-party `Kind` (e.g. ElysiaJS's `t.Files()`) must have
60
+ * // that kind registered with TypeBox's own `TypeRegistry` before validating, since
61
+ * // this resolver validates via `@sinclair/typebox`'s `Value.Errors`/`Value.Check`:
62
+ * // TypeRegistry.Set('Files', (schema, value) => Array.isArray(value));
63
+ */
64
+ export function typeboxResolver<Schema extends TObject, Context>(
65
+ schema: Schema | TypeCheck<Schema>,
66
+ ): Resolver<Static<Schema>, Context, StaticDecode<Schema>> {
67
+ return async (values: Static<Schema>, _, options) => {
68
+ const errors = Array.from(
69
+ schema instanceof TypeCheck
70
+ ? schema.Errors(values)
71
+ : Value.Errors(schema, values),
72
+ );
73
+
74
+ options.shouldUseNativeValidation && validateFieldsNatively({}, options);
75
+
76
+ if (!errors.length) {
77
+ return {
78
+ errors: {},
79
+ values,
80
+ };
81
+ }
82
+
83
+ return {
84
+ values: {},
85
+ errors: toNestErrors(
86
+ parseErrorSchema(
87
+ errors,
88
+ !options.shouldUseNativeValidation && options.criteriaMode === 'all',
89
+ ),
90
+ options,
91
+ ),
92
+ };
93
+ };
94
+ }
node_modules/@hookform/resolvers/typeschema/dist/index.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export * from './typeschema';
node_modules/@hookform/resolvers/typeschema/dist/typeschema.d.ts ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import { FieldValues, Resolver } from 'react-hook-form';
3
+ export declare function typeschemaResolver<Input extends FieldValues, Context, Output>(schema: StandardSchemaV1<Input, Output>, _schemaOptions?: never, resolverOptions?: {
4
+ raw?: false;
5
+ }): Resolver<Input, Context, Output>;
6
+ export declare function typeschemaResolver<Input extends FieldValues, Context, Output>(schema: StandardSchemaV1<Input, Output>, _schemaOptions: never | undefined, resolverOptions: {
7
+ raw: true;
8
+ }): Resolver<Input, Context, Input>;
node_modules/@hookform/resolvers/typeschema/dist/typeschema.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ var e=require("@hookform/resolvers"),r=require("react-hook-form");function t(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}exports.typeschemaResolver=function(n,a,o){return void 0===o&&(o={}),function(a,i,s){try{var u=function(){if(l.issues){var n=function(e,n){for(var a,o=Object.assign([],e),i=Object.create(null),s=function(e){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(o);!(a=s()).done;){var u=a.value;if(u.path){var l=u.path.join(".");if(i[l]||(i[l]={message:u.message,type:""}),n){var c=i[l].types,v=c&&c[""];i[l]=r.appendErrors(l,n,i,"",v?[].concat(v,u.message):u.message)}}}return i}(l.issues,!s.shouldUseNativeValidation&&"all"===s.criteriaMode);return{values:{},errors:e.toNestErrors(n,s)}}return s.shouldUseNativeValidation&&e.validateFieldsNatively({},s),{values:o.raw?Object.assign({},a):l.value,errors:{}}},l=n["~standard"].validate(a),c=function(){if(l instanceof Promise)return Promise.resolve(l).then(function(e){l=e})}();return Promise.resolve(c&&c.then?c.then(u):u())}catch(e){return Promise.reject(e)}}};
2
+ //# sourceMappingURL=typeschema.js.map
node_modules/@hookform/resolvers/typeschema/dist/typeschema.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"typeschema.js","sources":["../src/typeschema.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nconst parseErrorSchema = (\n typeschemaErrors: readonly StandardSchemaV1.Issue[],\n validateAllFieldCriteria: boolean,\n): FieldErrors => {\n // Need to pass generics so that the array isn't typed as \"never[]\"\n const schemaErrors = Object.assign(\n [] as typeof typeschemaErrors,\n typeschemaErrors,\n );\n // See the matching comment in the zod resolver's `parseZod3Issues`.\n const errors: Record<string, FieldError> = Object.create(null);\n\n for (const error of schemaErrors) {\n if (!error.path) {\n continue;\n }\n const _path = error.path.join('.');\n\n if (!errors[_path]) {\n errors[_path] = { message: error.message, type: '' };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[''];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '',\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n }\n\n return errors;\n};\n\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions?: {\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions: never | undefined,\n resolverOptions: {\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form using TypeSchema validation\n * @param {any} schema - The TypeSchema to validate against\n * @param {any} _ - Unused parameter\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {string} [resolverOptions.mode='async'] - Validation mode\n * @returns {Resolver} A resolver function compatible with react-hook-form\n * @example\n * const schema = z.object({\n * name: z.string().required(),\n * age: z.number().required(),\n * });\n *\n * useForm({\n * resolver: typeschemaResolver(schema)\n * });\n */\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions: {\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values, _, options) => {\n let result = schema['~standard'].validate(values);\n if (result instanceof Promise) {\n result = await result;\n }\n\n if (result.issues) {\n const errors = parseErrorSchema(\n result.issues,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n );\n\n return {\n values: {},\n errors: toNestErrors(errors, options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.value,\n errors: {},\n };\n };\n}\n"],"names":["schema","_schemaOptions","resolverOptions","values","_","options","_temp2","result","issues","errors","typeschemaErrors","validateAllFieldCriteria","_step","schemaErrors","Object","assign","create","_iterator","_createForOfIteratorHelperLoose","done","error","value","path","_path","join","message","type","types","messages","appendErrors","concat","parseErrorSchema","shouldUseNativeValidation","criteriaMode","toNestErrors","validateFieldsNatively","raw","validate","_temp","Promise","resolve","then","_result","e","reject"],"mappings":"4MAqFEA,EACAC,EACAC,GAIA,gBAJAA,IAAAA,EAEI,CAAA,YAEUC,EAAQC,EAAGC,GAAW,IAAA,IAAAC,EAAAA,WAMlC,GAAIC,EAAOC,OAAQ,CACjB,IAAMC,EAxFa,SACvBC,EACAC,GAUA,IAPA,IAOgCC,EAP1BC,EAAeC,OAAOC,OAC1B,GACAL,GAGID,EAAqCK,OAAOE,OAAO,MAEzDC,2pBAAAC,CAAoBL,KAAYD,EAAAK,KAAAE,MAAE,CAAA,IAAvBC,EAAKR,EAAAS,MACd,GAAKD,EAAME,KAAX,CAGA,IAAMC,EAAQH,EAAME,KAAKE,KAAK,KAM9B,GAJKf,EAAOc,KACVd,EAAOc,GAAS,CAAEE,QAASL,EAAMK,QAASC,KAAM,KAG9Cf,EAA0B,CAC5B,IAAMgB,EAAQlB,EAAOc,GAAOI,MACtBC,EAAWD,GAASA,EAAM,IAEhClB,EAAOc,GAASM,EAAYA,aAC1BN,EACAZ,EACAF,EACA,GACAmB,EACK,GAAgBE,OAAOF,EAAsBR,EAAMK,SACpDL,EAAMK,QAEd,CApBA,CAqBF,CAEA,OAAOhB,CACT,CAiDqBsB,CACbxB,EAAOC,QACNH,EAAQ2B,2BAAsD,QAAzB3B,EAAQ4B,cAGhD,MAAO,CACL9B,OAAQ,CAAA,EACRM,OAAQyB,eAAazB,EAAQJ,GAEjC,CAIA,OAFAA,EAAQ2B,2BAA6BG,EAAsBA,uBAAC,GAAI9B,GAEzD,CACLF,OAAQD,EAAgBkC,IAAMtB,OAAOC,OAAO,CAAA,EAAIZ,GAAUI,EAAOc,MACjEZ,OAAQ,GACR,EAtBEF,EAASP,EAAO,aAAaqC,SAASlC,GAAQmC,EAC9C/B,WAAAA,GAAAA,aAAkBgC,QAAOA,OAAAA,QAAAC,QACZjC,GAAMkC,cAAAC,GAArBnC,EAAMmC,CAAgB,EAAAH,CADpBhC,GACoBgC,OAAAA,QAAAC,QAAAF,GAAAA,EAAAG,KAAAH,EAAAG,KAAAnC,GAAAA,IAqB1B,CAAC,MAAAqC,GAAAJ,OAAAA,QAAAK,OAAAD,EACH,CAAA,CAAA"}
node_modules/@hookform/resolvers/typeschema/dist/typeschema.mjs ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as r,validateFieldsNatively as e}from"@hookform/resolvers";import{appendErrors as t}from"react-hook-form";function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=Array(e);t<e;t++)n[t]=r[t];return n}function o(o,a,i){return void 0===i&&(i={}),function(a,s,u){try{var l=function(){if(c.issues){var o=function(r,e){for(var o,a=Object.assign([],r),i=Object.create(null),s=function(r){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(e)return(e=e.call(r)).next.bind(e);if(Array.isArray(r)||(e=function(r,e){if(r){if("string"==typeof r)return n(r,e);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(r,e):void 0}}(r))){e&&(r=e);var t=0;return function(){return t>=r.length?{done:!0}:{done:!1,value:r[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(a);!(o=s()).done;){var u=o.value;if(u.path){var l=u.path.join(".");if(i[l]||(i[l]={message:u.message,type:""}),e){var c=i[l].types,f=c&&c[""];i[l]=t(l,e,i,"",f?[].concat(f,u.message):u.message)}}}return i}(c.issues,!u.shouldUseNativeValidation&&"all"===u.criteriaMode);return{values:{},errors:r(o,u)}}return u.shouldUseNativeValidation&&e({},u),{values:i.raw?Object.assign({},a):c.value,errors:{}}},c=o["~standard"].validate(a),f=function(){if(c instanceof Promise)return Promise.resolve(c).then(function(r){c=r})}();return Promise.resolve(f&&f.then?f.then(l):l())}catch(r){return Promise.reject(r)}}}export{o as typeschemaResolver};
2
+ //# sourceMappingURL=typeschema.module.js.map
node_modules/@hookform/resolvers/typeschema/dist/typeschema.modern.mjs ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as e,validateFieldsNatively as s}from"@hookform/resolvers";import{appendErrors as t}from"react-hook-form";function o(o,a,r={}){return async(a,i,n)=>{let c=o["~standard"].validate(a);if(c instanceof Promise&&(c=await c),c.issues){const s=((e,s)=>{const o=Object.assign([],e),a=Object.create(null);for(const e of o){if(!e.path)continue;const o=e.path.join(".");if(a[o]||(a[o]={message:e.message,type:""}),s){const r=a[o].types,i=r&&r[""];a[o]=t(o,s,a,"",i?[].concat(i,e.message):e.message)}}return a})(c.issues,!n.shouldUseNativeValidation&&"all"===n.criteriaMode);return{values:{},errors:e(s,n)}}return n.shouldUseNativeValidation&&s({},n),{values:r.raw?Object.assign({},a):c.value,errors:{}}}}export{o as typeschemaResolver};
2
+ //# sourceMappingURL=typeschema.modern.mjs.map
node_modules/@hookform/resolvers/typeschema/dist/typeschema.modern.mjs.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"typeschema.modern.mjs","sources":["../src/typeschema.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nconst parseErrorSchema = (\n typeschemaErrors: readonly StandardSchemaV1.Issue[],\n validateAllFieldCriteria: boolean,\n): FieldErrors => {\n // Need to pass generics so that the array isn't typed as \"never[]\"\n const schemaErrors = Object.assign(\n [] as typeof typeschemaErrors,\n typeschemaErrors,\n );\n // See the matching comment in the zod resolver's `parseZod3Issues`.\n const errors: Record<string, FieldError> = Object.create(null);\n\n for (const error of schemaErrors) {\n if (!error.path) {\n continue;\n }\n const _path = error.path.join('.');\n\n if (!errors[_path]) {\n errors[_path] = { message: error.message, type: '' };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[''];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '',\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n }\n\n return errors;\n};\n\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions?: {\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions: never | undefined,\n resolverOptions: {\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form using TypeSchema validation\n * @param {any} schema - The TypeSchema to validate against\n * @param {any} _ - Unused parameter\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {string} [resolverOptions.mode='async'] - Validation mode\n * @returns {Resolver} A resolver function compatible with react-hook-form\n * @example\n * const schema = z.object({\n * name: z.string().required(),\n * age: z.number().required(),\n * });\n *\n * useForm({\n * resolver: typeschemaResolver(schema)\n * });\n */\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions: {\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values, _, options) => {\n let result = schema['~standard'].validate(values);\n if (result instanceof Promise) {\n result = await result;\n }\n\n if (result.issues) {\n const errors = parseErrorSchema(\n result.issues,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n );\n\n return {\n values: {},\n errors: toNestErrors(errors, options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.value,\n errors: {},\n };\n };\n}\n"],"names":["typeschemaResolver","schema","_schemaOptions","resolverOptions","values","_","options","result","validate","Promise","issues","errors","parseErrorSchema","typeschemaErrors","validateAllFieldCriteria","schemaErrors","Object","assign","create","error","path","_path","join","message","type","types","messages","appendErrors","concat","shouldUseNativeValidation","criteriaMode","toNestErrors","validateFieldsNatively","raw","value"],"mappings":"uIAoFgBA,EACdC,EACAC,EACAC,EAEI,CAAE,GAEN,aAAcC,EAAQC,EAAGC,KACvB,IAAIC,EAASN,EAAO,aAAaO,SAASJ,GAK1C,GAJIG,aAAkBE,UACpBF,QAAeA,GAGbA,EAAOG,OAAQ,CACjB,MAAMC,EAxFaC,EACvBC,EACAC,KAGA,MAAMC,EAAeC,OAAOC,OAC1B,GACAJ,GAGIF,EAAqCK,OAAOE,OAAO,MAEzD,IAAK,MAAMC,KAASJ,EAAc,CAChC,IAAKI,EAAMC,KACT,SAEF,MAAMC,EAAQF,EAAMC,KAAKE,KAAK,KAM9B,GAJKX,EAAOU,KACVV,EAAOU,GAAS,CAAEE,QAASJ,EAAMI,QAASC,KAAM,KAG9CV,EAA0B,CAC5B,MAAMW,EAAQd,EAAOU,GAAOI,MACtBC,EAAWD,GAASA,EAAM,IAEhCd,EAAOU,GAASM,EACdN,EACAP,EACAH,EACA,GACAe,EACK,GAAgBE,OAAOF,EAAsBP,EAAMI,SACpDJ,EAAMI,QAEd,CACF,CAEA,OAAOZ,CAAM,EAkDMC,CACbL,EAAOG,QACNJ,EAAQuB,2BAAsD,QAAzBvB,EAAQwB,cAGhD,MAAO,CACL1B,OAAQ,CAAE,EACVO,OAAQoB,EAAapB,EAAQL,GAEjC,CAIA,OAFAA,EAAQuB,2BAA6BG,EAAuB,CAAA,EAAI1B,GAEzD,CACLF,OAAQD,EAAgB8B,IAAMjB,OAAOC,OAAO,CAAA,EAAIb,GAAUG,EAAO2B,MACjEvB,OAAQ,CAAA,EACT,CAEL"}
node_modules/@hookform/resolvers/typeschema/dist/typeschema.module.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as r,validateFieldsNatively as e}from"@hookform/resolvers";import{appendErrors as t}from"react-hook-form";function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=Array(e);t<e;t++)n[t]=r[t];return n}function o(o,a,i){return void 0===i&&(i={}),function(a,s,u){try{var l=function(){if(c.issues){var o=function(r,e){for(var o,a=Object.assign([],r),i=Object.create(null),s=function(r){var e="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(e)return(e=e.call(r)).next.bind(e);if(Array.isArray(r)||(e=function(r,e){if(r){if("string"==typeof r)return n(r,e);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(r,e):void 0}}(r))){e&&(r=e);var t=0;return function(){return t>=r.length?{done:!0}:{done:!1,value:r[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(a);!(o=s()).done;){var u=o.value;if(u.path){var l=u.path.join(".");if(i[l]||(i[l]={message:u.message,type:""}),e){var c=i[l].types,f=c&&c[""];i[l]=t(l,e,i,"",f?[].concat(f,u.message):u.message)}}}return i}(c.issues,!u.shouldUseNativeValidation&&"all"===u.criteriaMode);return{values:{},errors:r(o,u)}}return u.shouldUseNativeValidation&&e({},u),{values:i.raw?Object.assign({},a):c.value,errors:{}}},c=o["~standard"].validate(a),f=function(){if(c instanceof Promise)return Promise.resolve(c).then(function(r){c=r})}();return Promise.resolve(f&&f.then?f.then(l):l())}catch(r){return Promise.reject(r)}}}export{o as typeschemaResolver};
2
+ //# sourceMappingURL=typeschema.module.js.map
node_modules/@hookform/resolvers/typeschema/dist/typeschema.module.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"typeschema.module.js","sources":["../src/typeschema.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nconst parseErrorSchema = (\n typeschemaErrors: readonly StandardSchemaV1.Issue[],\n validateAllFieldCriteria: boolean,\n): FieldErrors => {\n // Need to pass generics so that the array isn't typed as \"never[]\"\n const schemaErrors = Object.assign(\n [] as typeof typeschemaErrors,\n typeschemaErrors,\n );\n // See the matching comment in the zod resolver's `parseZod3Issues`.\n const errors: Record<string, FieldError> = Object.create(null);\n\n for (const error of schemaErrors) {\n if (!error.path) {\n continue;\n }\n const _path = error.path.join('.');\n\n if (!errors[_path]) {\n errors[_path] = { message: error.message, type: '' };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[''];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '',\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n }\n\n return errors;\n};\n\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions?: {\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions: never | undefined,\n resolverOptions: {\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form using TypeSchema validation\n * @param {any} schema - The TypeSchema to validate against\n * @param {any} _ - Unused parameter\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {string} [resolverOptions.mode='async'] - Validation mode\n * @returns {Resolver} A resolver function compatible with react-hook-form\n * @example\n * const schema = z.object({\n * name: z.string().required(),\n * age: z.number().required(),\n * });\n *\n * useForm({\n * resolver: typeschemaResolver(schema)\n * });\n */\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions: {\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values, _, options) => {\n let result = schema['~standard'].validate(values);\n if (result instanceof Promise) {\n result = await result;\n }\n\n if (result.issues) {\n const errors = parseErrorSchema(\n result.issues,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n );\n\n return {\n values: {},\n errors: toNestErrors(errors, options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.value,\n errors: {},\n };\n };\n}\n"],"names":["typeschemaResolver","schema","_schemaOptions","resolverOptions","values","_","options","_temp2","result","issues","errors","typeschemaErrors","validateAllFieldCriteria","_step","schemaErrors","Object","assign","create","_iterator","_createForOfIteratorHelperLoose","done","error","value","path","_path","join","message","type","types","messages","appendErrors","concat","parseErrorSchema","shouldUseNativeValidation","criteriaMode","toNestErrors","validateFieldsNatively","raw","validate","_temp","Promise","resolve","then","_result","e","reject"],"mappings":"6OAoFgBA,EACdC,EACAC,EACAC,GAIA,gBAJAA,IAAAA,EAEI,CAAA,YAEUC,EAAQC,EAAGC,GAAW,IAAA,IAAAC,EAAAA,WAMlC,GAAIC,EAAOC,OAAQ,CACjB,IAAMC,EAxFa,SACvBC,EACAC,GAUA,IAPA,IAOgCC,EAP1BC,EAAeC,OAAOC,OAC1B,GACAL,GAGID,EAAqCK,OAAOE,OAAO,MAEzDC,2pBAAAC,CAAoBL,KAAYD,EAAAK,KAAAE,MAAE,CAAA,IAAvBC,EAAKR,EAAAS,MACd,GAAKD,EAAME,KAAX,CAGA,IAAMC,EAAQH,EAAME,KAAKE,KAAK,KAM9B,GAJKf,EAAOc,KACVd,EAAOc,GAAS,CAAEE,QAASL,EAAMK,QAASC,KAAM,KAG9Cf,EAA0B,CAC5B,IAAMgB,EAAQlB,EAAOc,GAAOI,MACtBC,EAAWD,GAASA,EAAM,IAEhClB,EAAOc,GAASM,EACdN,EACAZ,EACAF,EACA,GACAmB,EACK,GAAgBE,OAAOF,EAAsBR,EAAMK,SACpDL,EAAMK,QAEd,CApBA,CAqBF,CAEA,OAAOhB,CACT,CAiDqBsB,CACbxB,EAAOC,QACNH,EAAQ2B,2BAAsD,QAAzB3B,EAAQ4B,cAGhD,MAAO,CACL9B,OAAQ,CAAA,EACRM,OAAQyB,EAAazB,EAAQJ,GAEjC,CAIA,OAFAA,EAAQ2B,2BAA6BG,EAAuB,GAAI9B,GAEzD,CACLF,OAAQD,EAAgBkC,IAAMtB,OAAOC,OAAO,CAAA,EAAIZ,GAAUI,EAAOc,MACjEZ,OAAQ,GACR,EAtBEF,EAASP,EAAO,aAAaqC,SAASlC,GAAQmC,EAC9C/B,WAAAA,GAAAA,aAAkBgC,QAAOA,OAAAA,QAAAC,QACZjC,GAAMkC,cAAAC,GAArBnC,EAAMmC,CAAgB,EAAAH,CADpBhC,GACoBgC,OAAAA,QAAAC,QAAAF,GAAAA,EAAAG,KAAAH,EAAAG,KAAAnC,GAAAA,IAqB1B,CAAC,MAAAqC,GAAAJ,OAAAA,QAAAK,OAAAD,EACH,CAAA,CAAA"}
node_modules/@hookform/resolvers/typeschema/dist/typeschema.umd.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form"],r):r((e||self).hookformResolversTypeschema={},e.hookformResolvers,e.ReactHookForm)}(this,function(e,r,t){function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=Array(r);t<r;t++)o[t]=e[t];return o}e.typeschemaResolver=function(e,n,a){return void 0===a&&(a={}),function(n,i,s){try{var l=function(){if(u.issues){var e=function(e,r){for(var n,a=Object.assign([],e),i=Object.create(null),s=function(e){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,r){if(e){if("string"==typeof e)return o(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):void 0}}(e))){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(a);!(n=s()).done;){var l=n.value;if(l.path){var u=l.path.join(".");if(i[u]||(i[u]={message:l.message,type:""}),r){var f=i[u].types,c=f&&f[""];i[u]=t.appendErrors(u,r,i,"",c?[].concat(c,l.message):l.message)}}}return i}(u.issues,!s.shouldUseNativeValidation&&"all"===s.criteriaMode);return{values:{},errors:r.toNestErrors(e,s)}}return s.shouldUseNativeValidation&&r.validateFieldsNatively({},s),{values:a.raw?Object.assign({},n):u.value,errors:{}}},u=e["~standard"].validate(n),f=function(){if(u instanceof Promise)return Promise.resolve(u).then(function(e){u=e})}();return Promise.resolve(f&&f.then?f.then(l):l())}catch(e){return Promise.reject(e)}}}});
2
+ //# sourceMappingURL=typeschema.umd.js.map
node_modules/@hookform/resolvers/typeschema/dist/typeschema.umd.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"typeschema.umd.js","sources":["../src/typeschema.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n FieldError,\n FieldErrors,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\n\nconst parseErrorSchema = (\n typeschemaErrors: readonly StandardSchemaV1.Issue[],\n validateAllFieldCriteria: boolean,\n): FieldErrors => {\n // Need to pass generics so that the array isn't typed as \"never[]\"\n const schemaErrors = Object.assign(\n [] as typeof typeschemaErrors,\n typeschemaErrors,\n );\n // See the matching comment in the zod resolver's `parseZod3Issues`.\n const errors: Record<string, FieldError> = Object.create(null);\n\n for (const error of schemaErrors) {\n if (!error.path) {\n continue;\n }\n const _path = error.path.join('.');\n\n if (!errors[_path]) {\n errors[_path] = { message: error.message, type: '' };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types[''];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '',\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n }\n\n return errors;\n};\n\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions?: {\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions: never | undefined,\n resolverOptions: {\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form using TypeSchema validation\n * @param {any} schema - The TypeSchema to validate against\n * @param {any} _ - Unused parameter\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {string} [resolverOptions.mode='async'] - Validation mode\n * @returns {Resolver} A resolver function compatible with react-hook-form\n * @example\n * const schema = z.object({\n * name: z.string().required(),\n * age: z.number().required(),\n * });\n *\n * useForm({\n * resolver: typeschemaResolver(schema)\n * });\n */\nexport function typeschemaResolver<Input extends FieldValues, Context, Output>(\n schema: StandardSchemaV1<Input, Output>,\n _schemaOptions?: never,\n resolverOptions: {\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values, _, options) => {\n let result = schema['~standard'].validate(values);\n if (result instanceof Promise) {\n result = await result;\n }\n\n if (result.issues) {\n const errors = parseErrorSchema(\n result.issues,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n );\n\n return {\n values: {},\n errors: toNestErrors(errors, options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.value,\n errors: {},\n };\n };\n}\n"],"names":["schema","_schemaOptions","resolverOptions","values","_","options","_temp2","result","issues","errors","typeschemaErrors","validateAllFieldCriteria","_step","schemaErrors","Object","assign","create","_iterator","_createForOfIteratorHelperLoose","done","error","value","path","_path","join","message","type","types","messages","appendErrors","concat","parseErrorSchema","shouldUseNativeValidation","criteriaMode","toNestErrors","validateFieldsNatively","raw","validate","_temp","Promise","resolve","then","_result","e","reject"],"mappings":"mgBAqFEA,EACAC,EACAC,GAIA,gBAJAA,IAAAA,EAEI,CAAA,YAEUC,EAAQC,EAAGC,GAAW,IAAA,IAAAC,EAAAA,WAMlC,GAAIC,EAAOC,OAAQ,CACjB,IAAMC,EAxFa,SACvBC,EACAC,GAUA,IAPA,IAOgCC,EAP1BC,EAAeC,OAAOC,OAC1B,GACAL,GAGID,EAAqCK,OAAOE,OAAO,MAEzDC,2pBAAAC,CAAoBL,KAAYD,EAAAK,KAAAE,MAAE,CAAA,IAAvBC,EAAKR,EAAAS,MACd,GAAKD,EAAME,KAAX,CAGA,IAAMC,EAAQH,EAAME,KAAKE,KAAK,KAM9B,GAJKf,EAAOc,KACVd,EAAOc,GAAS,CAAEE,QAASL,EAAMK,QAASC,KAAM,KAG9Cf,EAA0B,CAC5B,IAAMgB,EAAQlB,EAAOc,GAAOI,MACtBC,EAAWD,GAASA,EAAM,IAEhClB,EAAOc,GAASM,EAAYA,aAC1BN,EACAZ,EACAF,EACA,GACAmB,EACK,GAAgBE,OAAOF,EAAsBR,EAAMK,SACpDL,EAAMK,QAEd,CApBA,CAqBF,CAEA,OAAOhB,CACT,CAiDqBsB,CACbxB,EAAOC,QACNH,EAAQ2B,2BAAsD,QAAzB3B,EAAQ4B,cAGhD,MAAO,CACL9B,OAAQ,CAAA,EACRM,OAAQyB,eAAazB,EAAQJ,GAEjC,CAIA,OAFAA,EAAQ2B,2BAA6BG,EAAsBA,uBAAC,GAAI9B,GAEzD,CACLF,OAAQD,EAAgBkC,IAAMtB,OAAOC,OAAO,CAAA,EAAIZ,GAAUI,EAAOc,MACjEZ,OAAQ,GACR,EAtBEF,EAASP,EAAO,aAAaqC,SAASlC,GAAQmC,EAC9C/B,WAAAA,GAAAA,aAAkBgC,QAAOA,OAAAA,QAAAC,QACZjC,GAAMkC,cAAAC,GAArBnC,EAAMmC,CAAgB,EAAAH,CADpBhC,GACoBgC,OAAAA,QAAAC,QAAAF,GAAAA,EAAAG,KAAAH,EAAAG,KAAAnC,GAAAA,IAqB1B,CAAC,MAAAqC,GAAAJ,OAAAA,QAAAK,OAAAD,EACH,CAAA,CAAA"}
node_modules/@hookform/resolvers/typeschema/package.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@hookform/resolvers/typeschema",
3
+ "amdName": "hookformResolversTypeschema",
4
+ "version": "1.0.0",
5
+ "private": true,
6
+ "description": "React Hook Form validation resolver: typeschema",
7
+ "main": "dist/typeschema.js",
8
+ "module": "dist/typeschema.module.js",
9
+ "umd:main": "dist/typeschema.umd.js",
10
+ "source": "src/index.ts",
11
+ "types": "dist/index.d.ts",
12
+ "license": "MIT",
13
+ "peerDependencies": {
14
+ "react-hook-form": "^7.55.0",
15
+ "@hookform/resolvers": "^2.0.0",
16
+ "@typeschema/main": "^0.13.7"
17
+ }
18
+ }
node_modules/@hookform/resolvers/typeschema/src/__tests__/Form-native-validation.tsx ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import React from 'react';
4
+ import { useForm } from 'react-hook-form';
5
+ import { z } from 'zod/v3';
6
+ import { typeschemaResolver } from '..';
7
+
8
+ const USERNAME_REQUIRED_MESSAGE = 'username field is required';
9
+ const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
10
+
11
+ const schema = z.object({
12
+ username: z.string().min(1, { message: USERNAME_REQUIRED_MESSAGE }),
13
+ password: z.string().min(1, { message: PASSWORD_REQUIRED_MESSAGE }),
14
+ });
15
+
16
+ type FormData = z.infer<typeof schema>;
17
+
18
+ interface Props {
19
+ onSubmit: (data: FormData) => void;
20
+ }
21
+
22
+ function TestComponent({ onSubmit }: Props) {
23
+ const { register, handleSubmit } = useForm<FormData>({
24
+ resolver: typeschemaResolver(schema),
25
+ shouldUseNativeValidation: true,
26
+ });
27
+
28
+ return (
29
+ <form onSubmit={handleSubmit(onSubmit)}>
30
+ <input {...register('username')} placeholder="username" />
31
+
32
+ <input {...register('password')} placeholder="password" />
33
+
34
+ <button type="submit">submit</button>
35
+ </form>
36
+ );
37
+ }
38
+
39
+ test("form's native validation with TypeSchema", async () => {
40
+ const handleSubmit = vi.fn();
41
+ render(<TestComponent onSubmit={handleSubmit} />);
42
+
43
+ // username
44
+ let usernameField = screen.getByPlaceholderText(
45
+ /username/i,
46
+ ) as HTMLInputElement;
47
+ expect(usernameField.validity.valid).toBe(true);
48
+ expect(usernameField.validationMessage).toBe('');
49
+
50
+ // password
51
+ let passwordField = screen.getByPlaceholderText(
52
+ /password/i,
53
+ ) as HTMLInputElement;
54
+ expect(passwordField.validity.valid).toBe(true);
55
+ expect(passwordField.validationMessage).toBe('');
56
+
57
+ await user.click(screen.getByText(/submit/i));
58
+
59
+ // username
60
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
61
+ expect(usernameField.validity.valid).toBe(false);
62
+ expect(usernameField.validationMessage).toBe(USERNAME_REQUIRED_MESSAGE);
63
+
64
+ // password
65
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
66
+ expect(passwordField.validity.valid).toBe(false);
67
+ expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
68
+
69
+ await user.type(screen.getByPlaceholderText(/username/i), 'joe');
70
+ await user.type(screen.getByPlaceholderText(/password/i), 'password');
71
+
72
+ // username
73
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
74
+ expect(usernameField.validity.valid).toBe(true);
75
+ expect(usernameField.validationMessage).toBe('');
76
+
77
+ // password
78
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
79
+ expect(passwordField.validity.valid).toBe(true);
80
+ expect(passwordField.validationMessage).toBe('');
81
+ });
node_modules/@hookform/resolvers/typeschema/src/__tests__/Form.tsx ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import React from 'react';
4
+ import { useForm } from 'react-hook-form';
5
+ import { z } from 'zod/v3';
6
+ import { typeschemaResolver } from '..';
7
+
8
+ const schema = z.object({
9
+ username: z.string().min(1, { message: 'username field is required' }),
10
+ password: z.string().min(1, { message: 'password field is required' }),
11
+ });
12
+
13
+ interface Props {
14
+ onSubmit: (data: z.infer<typeof schema>) => void;
15
+ }
16
+
17
+ function TestComponent({ onSubmit }: Props) {
18
+ const {
19
+ register,
20
+ handleSubmit,
21
+ formState: { errors },
22
+ } = useForm({
23
+ resolver: typeschemaResolver(schema), // Useful to check TypeScript regressions
24
+ });
25
+
26
+ return (
27
+ <form onSubmit={handleSubmit(onSubmit)}>
28
+ <input {...register('username')} />
29
+ {errors.username && <span role="alert">{errors.username.message}</span>}
30
+
31
+ <input {...register('password')} />
32
+ {errors.password && <span role="alert">{errors.password.message}</span>}
33
+
34
+ <button type="submit">submit</button>
35
+ </form>
36
+ );
37
+ }
38
+
39
+ test("form's validation with TypeSchema and TypeScript's integration", async () => {
40
+ const handleSubmit = vi.fn();
41
+ render(<TestComponent onSubmit={handleSubmit} />);
42
+
43
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
44
+
45
+ await user.click(screen.getByText(/submit/i));
46
+
47
+ expect(screen.getByText(/username field is required/i)).toBeInTheDocument();
48
+ expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
49
+ expect(handleSubmit).not.toHaveBeenCalled();
50
+ });
node_modules/@hookform/resolvers/typeschema/src/__tests__/__fixtures__/data.ts ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Field, InternalFieldName } from 'react-hook-form';
2
+ import { z } from 'zod/v3';
3
+
4
+ export const schema = z
5
+ .object({
6
+ username: z.string().regex(/^\w+$/).min(3).max(30),
7
+ password: z
8
+ .string()
9
+ .regex(new RegExp('.*[A-Z].*'), 'One uppercase character')
10
+ .regex(new RegExp('.*[a-z].*'), 'One lowercase character')
11
+ .regex(new RegExp('.*\\d.*'), 'One number')
12
+ .regex(
13
+ new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
14
+ 'One special character',
15
+ )
16
+ .min(8, 'Must be at least 8 characters in length'),
17
+ repeatPassword: z.string(),
18
+ accessToken: z.union([z.string(), z.number()]),
19
+ birthYear: z.number().min(1900).max(2013).optional(),
20
+ email: z.string().email().optional(),
21
+ tags: z.array(z.string()),
22
+ enabled: z.boolean(),
23
+ url: z.string().url('Custom error url').or(z.literal('')),
24
+ like: z
25
+ .array(
26
+ z.object({
27
+ id: z.number(),
28
+ name: z.string().length(4),
29
+ }),
30
+ )
31
+ .optional(),
32
+ dateStr: z
33
+ .string()
34
+ .transform((value) => new Date(value))
35
+ .refine((value) => !isNaN(value.getTime()), {
36
+ message: 'Invalid date',
37
+ }),
38
+ })
39
+ .refine((obj) => obj.password === obj.repeatPassword, {
40
+ message: 'Passwords do not match',
41
+ path: ['confirm'],
42
+ });
43
+
44
+ export const validData: z.input<typeof schema> = {
45
+ username: 'Doe',
46
+ password: 'Password123_',
47
+ repeatPassword: 'Password123_',
48
+ birthYear: 2000,
49
+ email: 'john@doe.com',
50
+ tags: ['tag1', 'tag2'],
51
+ enabled: true,
52
+ accessToken: 'accessToken',
53
+ url: 'https://react-hook-form.com/',
54
+ like: [
55
+ {
56
+ id: 1,
57
+ name: 'name',
58
+ },
59
+ ],
60
+ dateStr: '2020-01-01',
61
+ };
62
+
63
+ export const invalidData = {
64
+ password: '___',
65
+ email: '',
66
+ birthYear: 'birthYear',
67
+ like: [{ id: 'z' }],
68
+ url: 'abc',
69
+ } as unknown as z.input<typeof schema>;
70
+
71
+ export const fields: Record<InternalFieldName, Field['_f']> = {
72
+ username: {
73
+ ref: { name: 'username' },
74
+ name: 'username',
75
+ },
76
+ password: {
77
+ ref: { name: 'password' },
78
+ name: 'password',
79
+ },
80
+ email: {
81
+ ref: { name: 'email' },
82
+ name: 'email',
83
+ },
84
+ birthday: {
85
+ ref: { name: 'birthday' },
86
+ name: 'birthday',
87
+ },
88
+ };
node_modules/@hookform/resolvers/typeschema/src/__tests__/__snapshots__/typeschema.ts.snap ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`typeschemaResolver > should return a single error from typeschemaResolver when validation fails 1`] = `
4
+ {
5
+ "errors": {
6
+ "accessToken": {
7
+ "message": "Invalid input",
8
+ "ref": undefined,
9
+ "type": "",
10
+ },
11
+ "birthYear": {
12
+ "message": "Expected number, received string",
13
+ "ref": undefined,
14
+ "type": "",
15
+ },
16
+ "dateStr": {
17
+ "message": "Required",
18
+ "ref": undefined,
19
+ "type": "",
20
+ },
21
+ "email": {
22
+ "message": "Invalid email",
23
+ "ref": {
24
+ "name": "email",
25
+ },
26
+ "type": "",
27
+ },
28
+ "enabled": {
29
+ "message": "Required",
30
+ "ref": undefined,
31
+ "type": "",
32
+ },
33
+ "like": [
34
+ {
35
+ "id": {
36
+ "message": "Expected number, received string",
37
+ "ref": undefined,
38
+ "type": "",
39
+ },
40
+ "name": {
41
+ "message": "Required",
42
+ "ref": undefined,
43
+ "type": "",
44
+ },
45
+ },
46
+ ],
47
+ "password": {
48
+ "message": "One uppercase character",
49
+ "ref": {
50
+ "name": "password",
51
+ },
52
+ "type": "",
53
+ },
54
+ "repeatPassword": {
55
+ "message": "Required",
56
+ "ref": undefined,
57
+ "type": "",
58
+ },
59
+ "tags": {
60
+ "message": "Required",
61
+ "ref": undefined,
62
+ "type": "",
63
+ },
64
+ "url": {
65
+ "message": "Custom error url",
66
+ "ref": undefined,
67
+ "type": "",
68
+ },
69
+ "username": {
70
+ "message": "Required",
71
+ "ref": {
72
+ "name": "username",
73
+ },
74
+ "type": "",
75
+ },
76
+ },
77
+ "values": {},
78
+ }
79
+ `;
80
+
81
+ exports[`typeschemaResolver > should return all the errors from typeschemaResolver when validation fails with \`validateAllFieldCriteria\` set to true 1`] = `
82
+ {
83
+ "errors": {
84
+ "accessToken": {
85
+ "message": "Invalid input",
86
+ "ref": undefined,
87
+ "type": "",
88
+ "types": {
89
+ "": "Invalid input",
90
+ },
91
+ },
92
+ "birthYear": {
93
+ "message": "Expected number, received string",
94
+ "ref": undefined,
95
+ "type": "",
96
+ "types": {
97
+ "": "Expected number, received string",
98
+ },
99
+ },
100
+ "dateStr": {
101
+ "message": "Required",
102
+ "ref": undefined,
103
+ "type": "",
104
+ "types": {
105
+ "": "Required",
106
+ },
107
+ },
108
+ "email": {
109
+ "message": "Invalid email",
110
+ "ref": {
111
+ "name": "email",
112
+ },
113
+ "type": "",
114
+ "types": {
115
+ "": "Invalid email",
116
+ },
117
+ },
118
+ "enabled": {
119
+ "message": "Required",
120
+ "ref": undefined,
121
+ "type": "",
122
+ "types": {
123
+ "": "Required",
124
+ },
125
+ },
126
+ "like": [
127
+ {
128
+ "id": {
129
+ "message": "Expected number, received string",
130
+ "ref": undefined,
131
+ "type": "",
132
+ "types": {
133
+ "": "Expected number, received string",
134
+ },
135
+ },
136
+ "name": {
137
+ "message": "Required",
138
+ "ref": undefined,
139
+ "type": "",
140
+ "types": {
141
+ "": "Required",
142
+ },
143
+ },
144
+ },
145
+ ],
146
+ "password": {
147
+ "message": "One uppercase character",
148
+ "ref": {
149
+ "name": "password",
150
+ },
151
+ "type": "",
152
+ "types": {
153
+ "": [
154
+ "One uppercase character",
155
+ "One lowercase character",
156
+ "One number",
157
+ "Must be at least 8 characters in length",
158
+ ],
159
+ },
160
+ },
161
+ "repeatPassword": {
162
+ "message": "Required",
163
+ "ref": undefined,
164
+ "type": "",
165
+ "types": {
166
+ "": "Required",
167
+ },
168
+ },
169
+ "tags": {
170
+ "message": "Required",
171
+ "ref": undefined,
172
+ "type": "",
173
+ "types": {
174
+ "": "Required",
175
+ },
176
+ },
177
+ "url": {
178
+ "message": "Custom error url",
179
+ "ref": undefined,
180
+ "type": "",
181
+ "types": {
182
+ "": "Custom error url",
183
+ },
184
+ },
185
+ "username": {
186
+ "message": "Required",
187
+ "ref": {
188
+ "name": "username",
189
+ },
190
+ "type": "",
191
+ "types": {
192
+ "": "Required",
193
+ },
194
+ },
195
+ },
196
+ "values": {},
197
+ }
198
+ `;
199
+
200
+ exports[`typeschemaResolver > should return parsed values from typeschemaResolver when validation pass 1`] = `
201
+ {
202
+ "errors": {},
203
+ "values": {
204
+ "accessToken": "accessToken",
205
+ "birthYear": 2000,
206
+ "dateStr": 2020-01-01T00:00:00.000Z,
207
+ "email": "john@doe.com",
208
+ "enabled": true,
209
+ "like": [
210
+ {
211
+ "id": 1,
212
+ "name": "name",
213
+ },
214
+ ],
215
+ "password": "Password123_",
216
+ "repeatPassword": "Password123_",
217
+ "tags": [
218
+ "tag1",
219
+ "tag2",
220
+ ],
221
+ "url": "https://react-hook-form.com/",
222
+ "username": "Doe",
223
+ },
224
+ }
225
+ `;
node_modules/@hookform/resolvers/typeschema/src/__tests__/special-path-names.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { z } from 'zod/v3';
2
+ import { typeschemaResolver } from '..';
3
+
4
+ const shouldUseNativeValidation = false;
5
+
6
+ describe('typeschemaResolver special path names', () => {
7
+ it.each(['hasOwnProperty', 'toString'])(
8
+ 'reports a validation error for a field named "%s"',
9
+ async (name) => {
10
+ const schema = z.object({ [name]: z.string().min(1) });
11
+
12
+ const result = await typeschemaResolver(schema as any)(
13
+ { [name]: '' } as any,
14
+ undefined,
15
+ { fields: {}, shouldUseNativeValidation } as any,
16
+ );
17
+
18
+ expect(result.errors[name]).toBeDefined();
19
+ },
20
+ );
21
+ });
node_modules/@hookform/resolvers/typeschema/src/__tests__/typeschema.ts ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { renderHook } from '@testing-library/react';
2
+ import { Resolver, SubmitHandler, useForm } from 'react-hook-form';
3
+ import { z } from 'zod/v3';
4
+ import { typeschemaResolver } from '..';
5
+ import { fields, invalidData, schema, validData } from './__fixtures__/data';
6
+
7
+ const shouldUseNativeValidation = false;
8
+
9
+ vi.mock('@typeschema/main', async (importOriginal) => {
10
+ const module: object = await importOriginal();
11
+ return { ...module };
12
+ });
13
+
14
+ describe('typeschemaResolver', () => {
15
+ it('should return values from typeschemaResolver when validation pass & raw=true', async () => {
16
+ const validateSpy = vi.spyOn(schema['~standard'], 'validate');
17
+
18
+ const result = await typeschemaResolver(schema, undefined, { raw: true })(
19
+ validData,
20
+ undefined,
21
+ { fields, shouldUseNativeValidation },
22
+ );
23
+
24
+ expect(validateSpy).toHaveBeenCalledTimes(1);
25
+ expect(result).toEqual({ errors: {}, values: validData });
26
+ });
27
+
28
+ it('should return parsed values from typeschemaResolver when validation pass', async () => {
29
+ const validateSpy = vi.spyOn(schema['~standard'], 'validate');
30
+
31
+ const result = await typeschemaResolver(schema)(validData, undefined, {
32
+ fields,
33
+ shouldUseNativeValidation,
34
+ });
35
+
36
+ expect(validateSpy).toHaveBeenCalledTimes(1);
37
+ expect(result.errors).toEqual({});
38
+ expect(result).toMatchSnapshot();
39
+ });
40
+
41
+ it('should return a single error from typeschemaResolver when validation fails', async () => {
42
+ const result = await typeschemaResolver(schema)(invalidData, undefined, {
43
+ fields,
44
+ shouldUseNativeValidation,
45
+ });
46
+
47
+ expect(result).toMatchSnapshot();
48
+ });
49
+
50
+ it('should return all the errors from typeschemaResolver when validation fails with `validateAllFieldCriteria` set to true', async () => {
51
+ const result = await typeschemaResolver(schema)(invalidData, undefined, {
52
+ fields,
53
+ criteriaMode: 'all',
54
+ shouldUseNativeValidation,
55
+ });
56
+
57
+ expect(result).toMatchSnapshot();
58
+ });
59
+
60
+ it('should throw any error unrelated to TypeSchema', async () => {
61
+ const schemaWithCustomError = schema.refine(() => {
62
+ throw Error('custom error');
63
+ });
64
+ const promise = typeschemaResolver(schemaWithCustomError)(
65
+ validData,
66
+ undefined,
67
+ { fields, shouldUseNativeValidation },
68
+ );
69
+
70
+ await expect(promise).rejects.toThrow('custom error');
71
+ });
72
+
73
+ /**
74
+ * Type inference tests
75
+ */
76
+ it('should correctly infer the output type from a typeschema schema', () => {
77
+ const resolver = typeschemaResolver(z.object({ id: z.number() }));
78
+
79
+ expectTypeOf(resolver).toEqualTypeOf<
80
+ Resolver<{ id: number }, unknown, { id: number }>
81
+ >();
82
+ });
83
+
84
+ it('should correctly infer the output type from a typeschema schema using a transform', () => {
85
+ const resolver = typeschemaResolver(
86
+ z.object({ id: z.number().transform((val) => String(val)) }),
87
+ );
88
+
89
+ expectTypeOf(resolver).toEqualTypeOf<
90
+ Resolver<{ id: number }, unknown, { id: string }>
91
+ >();
92
+ });
93
+
94
+ it('should correctly infer the output type from a typeschema schema when a different input type is specified', () => {
95
+ const schema = z.object({ id: z.number() }).transform(({ id }) => {
96
+ return { id: String(id) };
97
+ });
98
+
99
+ const resolver = typeschemaResolver<
100
+ { id: number },
101
+ any,
102
+ z.output<typeof schema>
103
+ >(schema);
104
+
105
+ expectTypeOf(resolver).toEqualTypeOf<
106
+ Resolver<{ id: number }, any, { id: string }>
107
+ >();
108
+ });
109
+
110
+ it('should correctly infer the output type from a typeschema schema for the handleSubmit function in useForm', () => {
111
+ const schema = z.object({ id: z.number() });
112
+
113
+ const {
114
+ result: { current: form },
115
+ } = renderHook(() =>
116
+ useForm({
117
+ resolver: typeschemaResolver(schema),
118
+ defaultValues: {
119
+ id: 3,
120
+ },
121
+ }),
122
+ );
123
+
124
+ expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
125
+
126
+ expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
127
+ SubmitHandler<{
128
+ id: number;
129
+ }>
130
+ >();
131
+ });
132
+
133
+ it('should correctly infer the output type from a typeschema schema with a transform for the handleSubmit function in useForm', () => {
134
+ const schema = z.object({ id: z.number().transform((val) => String(val)) });
135
+
136
+ const {
137
+ result: { current: form },
138
+ } = renderHook(() =>
139
+ useForm({
140
+ resolver: typeschemaResolver(schema),
141
+ defaultValues: {
142
+ id: 3,
143
+ },
144
+ }),
145
+ );
146
+
147
+ expectTypeOf(form.watch('id')).toEqualTypeOf<number>();
148
+
149
+ expectTypeOf(form.handleSubmit).parameter(0).toEqualTypeOf<
150
+ SubmitHandler<{
151
+ id: string;
152
+ }>
153
+ >();
154
+ });
155
+ });
node_modules/@hookform/resolvers/typeschema/src/index.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export * from './typeschema';
node_modules/@hookform/resolvers/typeschema/src/typeschema.ts ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
2
+ import { StandardSchemaV1 } from '@standard-schema/spec';
3
+ import {
4
+ FieldError,
5
+ FieldErrors,
6
+ FieldValues,
7
+ Resolver,
8
+ appendErrors,
9
+ } from 'react-hook-form';
10
+
11
+ const parseErrorSchema = (
12
+ typeschemaErrors: readonly StandardSchemaV1.Issue[],
13
+ validateAllFieldCriteria: boolean,
14
+ ): FieldErrors => {
15
+ // Need to pass generics so that the array isn't typed as "never[]"
16
+ const schemaErrors = Object.assign(
17
+ [] as typeof typeschemaErrors,
18
+ typeschemaErrors,
19
+ );
20
+ // See the matching comment in the zod resolver's `parseZod3Issues`.
21
+ const errors: Record<string, FieldError> = Object.create(null);
22
+
23
+ for (const error of schemaErrors) {
24
+ if (!error.path) {
25
+ continue;
26
+ }
27
+ const _path = error.path.join('.');
28
+
29
+ if (!errors[_path]) {
30
+ errors[_path] = { message: error.message, type: '' };
31
+ }
32
+
33
+ if (validateAllFieldCriteria) {
34
+ const types = errors[_path].types;
35
+ const messages = types && types[''];
36
+
37
+ errors[_path] = appendErrors(
38
+ _path,
39
+ validateAllFieldCriteria,
40
+ errors,
41
+ '',
42
+ messages
43
+ ? ([] as string[]).concat(messages as string[], error.message)
44
+ : error.message,
45
+ ) as FieldError;
46
+ }
47
+ }
48
+
49
+ return errors;
50
+ };
51
+
52
+ export function typeschemaResolver<Input extends FieldValues, Context, Output>(
53
+ schema: StandardSchemaV1<Input, Output>,
54
+ _schemaOptions?: never,
55
+ resolverOptions?: {
56
+ raw?: false;
57
+ },
58
+ ): Resolver<Input, Context, Output>;
59
+
60
+ export function typeschemaResolver<Input extends FieldValues, Context, Output>(
61
+ schema: StandardSchemaV1<Input, Output>,
62
+ _schemaOptions: never | undefined,
63
+ resolverOptions: {
64
+ raw: true;
65
+ },
66
+ ): Resolver<Input, Context, Input>;
67
+
68
+ /**
69
+ * Creates a resolver for react-hook-form using TypeSchema validation
70
+ * @param {any} schema - The TypeSchema to validate against
71
+ * @param {any} _ - Unused parameter
72
+ * @param {Object} resolverOptions - Additional resolver configuration
73
+ * @param {string} [resolverOptions.mode='async'] - Validation mode
74
+ * @returns {Resolver} A resolver function compatible with react-hook-form
75
+ * @example
76
+ * const schema = z.object({
77
+ * name: z.string().required(),
78
+ * age: z.number().required(),
79
+ * });
80
+ *
81
+ * useForm({
82
+ * resolver: typeschemaResolver(schema)
83
+ * });
84
+ */
85
+ export function typeschemaResolver<Input extends FieldValues, Context, Output>(
86
+ schema: StandardSchemaV1<Input, Output>,
87
+ _schemaOptions?: never,
88
+ resolverOptions: {
89
+ raw?: boolean;
90
+ } = {},
91
+ ): Resolver<Input, Context, Output | Input> {
92
+ return async (values, _, options) => {
93
+ let result = schema['~standard'].validate(values);
94
+ if (result instanceof Promise) {
95
+ result = await result;
96
+ }
97
+
98
+ if (result.issues) {
99
+ const errors = parseErrorSchema(
100
+ result.issues,
101
+ !options.shouldUseNativeValidation && options.criteriaMode === 'all',
102
+ );
103
+
104
+ return {
105
+ values: {},
106
+ errors: toNestErrors(errors, options),
107
+ };
108
+ }
109
+
110
+ options.shouldUseNativeValidation && validateFieldsNatively({}, options);
111
+
112
+ return {
113
+ values: resolverOptions.raw ? Object.assign({}, values) : result.value,
114
+ errors: {},
115
+ };
116
+ };
117
+ }
node_modules/@hookform/resolvers/valibot/dist/index.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export * from './valibot';
node_modules/@hookform/resolvers/valibot/dist/valibot.d.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import { FieldValues, Resolver } from 'react-hook-form';
2
+ import { BaseSchema, BaseSchemaAsync, Config, InferIssue } from 'valibot';
3
+ export declare function valibotResolver<Input extends FieldValues, Context, Output>(schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>, schemaOptions?: Partial<Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>>, resolverOptions?: {
4
+ mode?: 'async' | 'sync';
5
+ raw?: false;
6
+ }): Resolver<Input, Context, Output>;
7
+ export declare function valibotResolver<Input extends FieldValues, Context, Output>(schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>, schemaOptions: Partial<Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>> | undefined, resolverOptions: {
8
+ mode?: 'async' | 'sync';
9
+ raw: true;
10
+ }): Resolver<Input, Context, Input>;
node_modules/@hookform/resolvers/valibot/dist/valibot.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ var e=require("@hookform/resolvers"),r=require("react-hook-form"),s=require("valibot");exports.valibotResolver=function(t,a,o){return void 0===o&&(o={}),function(i,u,n){try{var c=!n.shouldUseNativeValidation&&"all"===n.criteriaMode;return Promise.resolve(s.safeParseAsync(t,i,Object.assign({},a,{abortPipeEarly:!c}))).then(function(t){if(t.issues){for(var a=Object.create(null);t.issues.length;){var u=t.issues[0],l=s.getDotPath(u);if(l&&(a[l]||(a[l]={message:u.message,type:u.type}),c)){var v=a[l].types,f=v&&v[u.type];a[l]=r.appendErrors(l,c,a,u.type,f?[].concat(f,u.message):u.message)}t.issues.shift()}return{values:{},errors:e.toNestErrors(a,n)}}return{values:o.raw?Object.assign({},i):t.output,errors:{}}})}catch(e){return Promise.reject(e)}}};
2
+ //# sourceMappingURL=valibot.js.map
node_modules/@hookform/resolvers/valibot/dist/valibot.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"valibot.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport { BaseSchema, BaseSchemaAsync, Config, InferIssue } from 'valibot';\n\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions?: Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >,\n resolverOptions?: {\n mode?: 'async' | 'sync';\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions:\n | Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >\n | undefined,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form using Valibot schema validation\n * @param {BaseSchema<TFieldValues, TFieldValues, any> | BaseSchemaAsync<TFieldValues, TFieldValues, any>} schema - The Valibot schema to validate against\n * @param {Partial<Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>>} [schemaOptions] - Optional Valibot validation options\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('sync' | 'async')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values rather than validated results\n * @returns {Resolver<InferOutput<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = valibot.object({\n * name: valibot.string().minLength(2),\n * age: valibot.number().min(18)\n * });\n *\n * useForm({\n * resolver: valibotResolver(schema)\n * });\n */\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions?: Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >,\n resolverOptions: {\n /**\n * @default async\n */\n mode?: 'sync' | 'async';\n /**\n * Return the raw input values rather than the parsed values.\n * @default false\n */\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values: Input, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(\n schema,\n values,\n Object.assign({}, schemaOptions, {\n abortPipeEarly: !validateAllFieldCriteria,\n }),\n );\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object. A null-prototype object avoids false-positive\n // hits from inherited members (e.g. `toString`, `constructor`) when a\n // field is named after one of them — a plain `{}` would make\n // `!errors[path]` truthy-skip those paths and silently drop their\n // errors.\n const errors: Record<string, FieldError> = Object.create(null);\n\n // Iterate over issues to add them to errors object\n for (; result.issues.length; ) {\n const issue = result.issues[0];\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n\n result.issues.shift();\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.output,\n errors: {},\n };\n };\n}\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","Object","assign","abortPipeEarly","then","result","issues","errors","create","length","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","shift","toNestErrors","raw","output","e","reject"],"mappings":"+GAoDM,SACJA,EACAC,EAGAC,GAYA,gBAZAA,IAAAA,EAUI,CAAE,GAEQC,SAAAA,EAAeC,EAAGC,OAE9B,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAcA,eACjCX,EACAG,EACAS,OAAOC,OAAO,CAAA,EAAIZ,EAAe,CAC/Ba,gBAAiBR,MAEpBS,KAAA,SANKC,GASN,GAAIA,EAAOC,OAAQ,CASjB,IAHA,IAAMC,EAAqCN,OAAOO,OAAO,MAGlDH,EAAOC,OAAOG,QAAU,CAC7B,IAAMC,EAAQL,EAAOC,OAAO,GAEtBK,EAAOC,EAAUA,WAACF,GAExB,GAAIC,IAEGJ,EAAOI,KACVJ,EAAOI,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDnB,GAA0B,CAC5B,IAAMoB,EAAQR,EAAOI,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCP,EAAOI,GAAQM,EAAYA,aACzBN,EACAhB,EACAY,EACAG,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEd,CAGFR,EAAOC,OAAOa,OAChB,CAGA,MAAO,CACL3B,OAAQ,GACRe,OAAQa,EAAAA,aAAab,EAAQb,GAEjC,CAGA,MAAO,CACLF,OAAQD,EAAgB8B,IAAMpB,OAAOC,OAAO,CAAE,EAAEV,GAAUa,EAAOiB,OACjEf,OAAQ,GACR,EACJ,CAAC,MAAAgB,UAAAzB,QAAA0B,OAAAD,EACH,CAAA,CAAA"}
node_modules/@hookform/resolvers/valibot/dist/valibot.mjs ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as e}from"@hookform/resolvers";import{appendErrors as r}from"react-hook-form";import{safeParseAsync as s,getDotPath as t}from"valibot";function o(o,a,i){return void 0===i&&(i={}),function(n,u,c){try{var m=!c.shouldUseNativeValidation&&"all"===c.criteriaMode;return Promise.resolve(s(o,n,Object.assign({},a,{abortPipeEarly:!m}))).then(function(s){if(s.issues){for(var o=Object.create(null);s.issues.length;){var a=s.issues[0],u=t(a);if(u&&(o[u]||(o[u]={message:a.message,type:a.type}),m)){var l=o[u].types,f=l&&l[a.type];o[u]=r(u,m,o,a.type,f?[].concat(f,a.message):a.message)}s.issues.shift()}return{values:{},errors:e(o,c)}}return{values:i.raw?Object.assign({},n):s.output,errors:{}}})}catch(e){return Promise.reject(e)}}}export{o as valibotResolver};
2
+ //# sourceMappingURL=valibot.module.js.map
node_modules/@hookform/resolvers/valibot/dist/valibot.modern.mjs ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as e}from"@hookform/resolvers";import{appendErrors as s}from"react-hook-form";import{safeParseAsync as t,getDotPath as r}from"valibot";function o(o,a,i={}){return async(n,c,u)=>{const l=!u.shouldUseNativeValidation&&"all"===u.criteriaMode,m=await t(o,n,Object.assign({},a,{abortPipeEarly:!l}));if(m.issues){const t=Object.create(null);for(;m.issues.length;){const e=m.issues[0],o=r(e);if(o&&(t[o]||(t[o]={message:e.message,type:e.type}),l)){const r=t[o].types,a=r&&r[e.type];t[o]=s(o,l,t,e.type,a?[].concat(a,e.message):e.message)}m.issues.shift()}return{values:{},errors:e(t,u)}}return{values:i.raw?Object.assign({},n):m.output,errors:{}}}}export{o as valibotResolver};
2
+ //# sourceMappingURL=valibot.modern.mjs.map
node_modules/@hookform/resolvers/valibot/dist/valibot.modern.mjs.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport { BaseSchema, BaseSchemaAsync, Config, InferIssue } from 'valibot';\n\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions?: Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >,\n resolverOptions?: {\n mode?: 'async' | 'sync';\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions:\n | Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >\n | undefined,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form using Valibot schema validation\n * @param {BaseSchema<TFieldValues, TFieldValues, any> | BaseSchemaAsync<TFieldValues, TFieldValues, any>} schema - The Valibot schema to validate against\n * @param {Partial<Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>>} [schemaOptions] - Optional Valibot validation options\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('sync' | 'async')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values rather than validated results\n * @returns {Resolver<InferOutput<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = valibot.object({\n * name: valibot.string().minLength(2),\n * age: valibot.number().min(18)\n * });\n *\n * useForm({\n * resolver: valibotResolver(schema)\n * });\n */\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions?: Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >,\n resolverOptions: {\n /**\n * @default async\n */\n mode?: 'sync' | 'async';\n /**\n * Return the raw input values rather than the parsed values.\n * @default false\n */\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values: Input, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(\n schema,\n values,\n Object.assign({}, schemaOptions, {\n abortPipeEarly: !validateAllFieldCriteria,\n }),\n );\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object. A null-prototype object avoids false-positive\n // hits from inherited members (e.g. `toString`, `constructor`) when a\n // field is named after one of them — a plain `{}` would make\n // `!errors[path]` truthy-skip those paths and silently drop their\n // errors.\n const errors: Record<string, FieldError> = Object.create(null);\n\n // Iterate over issues to add them to errors object\n for (; result.issues.length; ) {\n const issue = result.issues[0];\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n\n result.issues.shift();\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.output,\n errors: {},\n };\n };\n}\n"],"names":["valibotResolver","schema","schemaOptions","resolverOptions","async","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","result","safeParseAsync","Object","assign","abortPipeEarly","issues","errors","create","length","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","shift","toNestErrors","raw","output"],"mappings":"2JAoDgB,SAAAA,EACdC,EACAC,EAGAC,EAUI,CAAA,GAEJ,OAAOC,MAAOC,EAAeC,EAAGC,KAE9B,MAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAG1CC,QAAeC,EACnBX,EACAI,EACAQ,OAAOC,OAAO,CAAA,EAAIZ,EAAe,CAC/Ba,gBAAiBP,KAKrB,GAAIG,EAAOK,OAAQ,CAMjB,MAAMC,EAAqCJ,OAAOK,OAAO,MAGzD,KAAOP,EAAOK,OAAOG,QAAU,CAC7B,MAAMC,EAAQT,EAAOK,OAAO,GAEtBK,EAAOC,EAAWF,GAExB,GAAIC,IAEGJ,EAAOI,KACVJ,EAAOI,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDhB,GAA0B,CAC5B,MAAMiB,EAAQR,EAAOI,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCP,EAAOI,GAAQM,EACbN,EACAb,EACAS,EACAG,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEd,CAGFZ,EAAOK,OAAOa,OAChB,CAGA,MAAO,CACLxB,OAAQ,CAAE,EACVY,OAAQa,EAAab,EAAQV,GAEjC,CAGA,MAAO,CACLF,OAAQF,EAAgB4B,IAAMlB,OAAOC,OAAO,CAAA,EAAIT,GAAUM,EAAOqB,OACjEf,OAAQ,GACT,CAEL"}
node_modules/@hookform/resolvers/valibot/dist/valibot.module.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as e}from"@hookform/resolvers";import{appendErrors as r}from"react-hook-form";import{safeParseAsync as s,getDotPath as t}from"valibot";function o(o,a,i){return void 0===i&&(i={}),function(n,u,c){try{var m=!c.shouldUseNativeValidation&&"all"===c.criteriaMode;return Promise.resolve(s(o,n,Object.assign({},a,{abortPipeEarly:!m}))).then(function(s){if(s.issues){for(var o=Object.create(null);s.issues.length;){var a=s.issues[0],u=t(a);if(u&&(o[u]||(o[u]={message:a.message,type:a.type}),m)){var l=o[u].types,f=l&&l[a.type];o[u]=r(u,m,o,a.type,f?[].concat(f,a.message):a.message)}s.issues.shift()}return{values:{},errors:e(o,c)}}return{values:i.raw?Object.assign({},n):s.output,errors:{}}})}catch(e){return Promise.reject(e)}}}export{o as valibotResolver};
2
+ //# sourceMappingURL=valibot.module.js.map
node_modules/@hookform/resolvers/valibot/dist/valibot.module.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"valibot.module.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport { BaseSchema, BaseSchemaAsync, Config, InferIssue } from 'valibot';\n\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions?: Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >,\n resolverOptions?: {\n mode?: 'async' | 'sync';\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions:\n | Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >\n | undefined,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form using Valibot schema validation\n * @param {BaseSchema<TFieldValues, TFieldValues, any> | BaseSchemaAsync<TFieldValues, TFieldValues, any>} schema - The Valibot schema to validate against\n * @param {Partial<Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>>} [schemaOptions] - Optional Valibot validation options\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('sync' | 'async')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values rather than validated results\n * @returns {Resolver<InferOutput<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = valibot.object({\n * name: valibot.string().minLength(2),\n * age: valibot.number().min(18)\n * });\n *\n * useForm({\n * resolver: valibotResolver(schema)\n * });\n */\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions?: Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >,\n resolverOptions: {\n /**\n * @default async\n */\n mode?: 'sync' | 'async';\n /**\n * Return the raw input values rather than the parsed values.\n * @default false\n */\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values: Input, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(\n schema,\n values,\n Object.assign({}, schemaOptions, {\n abortPipeEarly: !validateAllFieldCriteria,\n }),\n );\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object. A null-prototype object avoids false-positive\n // hits from inherited members (e.g. `toString`, `constructor`) when a\n // field is named after one of them — a plain `{}` would make\n // `!errors[path]` truthy-skip those paths and silently drop their\n // errors.\n const errors: Record<string, FieldError> = Object.create(null);\n\n // Iterate over issues to add them to errors object\n for (; result.issues.length; ) {\n const issue = result.issues[0];\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n\n result.issues.shift();\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.output,\n errors: {},\n };\n };\n}\n"],"names":["valibotResolver","schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","Object","assign","abortPipeEarly","then","result","issues","errors","create","length","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","shift","toNestErrors","raw","output","e","reject"],"mappings":"2JAoDM,SAAUA,EACdC,EACAC,EAGAC,GAYA,gBAZAA,IAAAA,EAUI,CAAE,GAEQC,SAAAA,EAAeC,EAAGC,OAE9B,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EACnBX,EACAG,EACAS,OAAOC,OAAO,CAAA,EAAIZ,EAAe,CAC/Ba,gBAAiBR,MAEpBS,KAAA,SANKC,GASN,GAAIA,EAAOC,OAAQ,CASjB,IAHA,IAAMC,EAAqCN,OAAOO,OAAO,MAGlDH,EAAOC,OAAOG,QAAU,CAC7B,IAAMC,EAAQL,EAAOC,OAAO,GAEtBK,EAAOC,EAAWF,GAExB,GAAIC,IAEGJ,EAAOI,KACVJ,EAAOI,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDnB,GAA0B,CAC5B,IAAMoB,EAAQR,EAAOI,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCP,EAAOI,GAAQM,EACbN,EACAhB,EACAY,EACAG,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEd,CAGFR,EAAOC,OAAOa,OAChB,CAGA,MAAO,CACL3B,OAAQ,GACRe,OAAQa,EAAab,EAAQb,GAEjC,CAGA,MAAO,CACLF,OAAQD,EAAgB8B,IAAMpB,OAAOC,OAAO,CAAE,EAAEV,GAAUa,EAAOiB,OACjEf,OAAQ,GACR,EACJ,CAAC,MAAAgB,UAAAzB,QAAA0B,OAAAD,EACH,CAAA,CAAA"}
node_modules/@hookform/resolvers/valibot/dist/valibot.umd.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@hookform/resolvers"),require("react-hook-form"),require("valibot")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form","valibot"],o):o((e||self).hookformResolversValibot={},e.hookformResolvers,e.ReactHookForm,e.valibot)}(this,function(e,o,r,s){e.valibotResolver=function(e,t,i){return void 0===i&&(i={}),function(a,n,f){try{var l=!f.shouldUseNativeValidation&&"all"===f.criteriaMode;return Promise.resolve(s.safeParseAsync(e,a,Object.assign({},t,{abortPipeEarly:!l}))).then(function(e){if(e.issues){for(var t=Object.create(null);e.issues.length;){var n=e.issues[0],u=s.getDotPath(n);if(u&&(t[u]||(t[u]={message:n.message,type:n.type}),l)){var c=t[u].types,v=c&&c[n.type];t[u]=r.appendErrors(u,l,t,n.type,v?[].concat(v,n.message):n.message)}e.issues.shift()}return{values:{},errors:o.toNestErrors(t,f)}}return{values:i.raw?Object.assign({},a):e.output,errors:{}}})}catch(e){return Promise.reject(e)}}}});
2
+ //# sourceMappingURL=valibot.umd.js.map
node_modules/@hookform/resolvers/valibot/dist/valibot.umd.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"valibot.umd.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport {\n FieldError,\n FieldValues,\n Resolver,\n appendErrors,\n} from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport { BaseSchema, BaseSchemaAsync, Config, InferIssue } from 'valibot';\n\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions?: Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >,\n resolverOptions?: {\n mode?: 'async' | 'sync';\n raw?: false;\n },\n): Resolver<Input, Context, Output>;\n\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions:\n | Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >\n | undefined,\n resolverOptions: {\n mode?: 'async' | 'sync';\n raw: true;\n },\n): Resolver<Input, Context, Input>;\n\n/**\n * Creates a resolver for react-hook-form using Valibot schema validation\n * @param {BaseSchema<TFieldValues, TFieldValues, any> | BaseSchemaAsync<TFieldValues, TFieldValues, any>} schema - The Valibot schema to validate against\n * @param {Partial<Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>>} [schemaOptions] - Optional Valibot validation options\n * @param {Object} resolverOptions - Additional resolver configuration\n * @param {('sync' | 'async')} [resolverOptions.mode] - Validation mode\n * @param {boolean} [resolverOptions.raw] - If true, returns raw values rather than validated results\n * @returns {Resolver<InferOutput<typeof schema>>} A resolver function compatible with react-hook-form\n * @example\n * const schema = valibot.object({\n * name: valibot.string().minLength(2),\n * age: valibot.number().min(18)\n * });\n *\n * useForm({\n * resolver: valibotResolver(schema)\n * });\n */\nexport function valibotResolver<Input extends FieldValues, Context, Output>(\n schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,\n schemaOptions?: Partial<\n Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>\n >,\n resolverOptions: {\n /**\n * @default async\n */\n mode?: 'sync' | 'async';\n /**\n * Return the raw input values rather than the parsed values.\n * @default false\n */\n raw?: boolean;\n } = {},\n): Resolver<Input, Context, Output | Input> {\n return async (values: Input, _, options) => {\n // Check if we should validate all field criteria\n const validateAllFieldCriteria =\n !options.shouldUseNativeValidation && options.criteriaMode === 'all';\n\n // Parse values with Valibot schema\n const result = await safeParseAsync(\n schema,\n values,\n Object.assign({}, schemaOptions, {\n abortPipeEarly: !validateAllFieldCriteria,\n }),\n );\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object. A null-prototype object avoids false-positive\n // hits from inherited members (e.g. `toString`, `constructor`) when a\n // field is named after one of them — a plain `{}` would make\n // `!errors[path]` truthy-skip those paths and silently drop their\n // errors.\n const errors: Record<string, FieldError> = Object.create(null);\n\n // Iterate over issues to add them to errors object\n for (; result.issues.length; ) {\n const issue = result.issues[0];\n // Create dot path from issue\n const path = getDotPath(issue);\n\n if (path) {\n // Add first error of path to errors object\n if (!errors[path]) {\n errors[path] = { message: issue.message, type: issue.type };\n }\n\n // If configured, add all errors of path to errors object\n if (validateAllFieldCriteria) {\n const types = errors[path].types;\n const messages = types && types[issue.type];\n errors[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n errors,\n issue.type,\n messages\n ? ([] as string[]).concat(\n messages as string | string[],\n issue.message,\n )\n : issue.message,\n ) as FieldError;\n }\n }\n\n result.issues.shift();\n }\n\n // Return resolver result with errors\n return {\n values: {},\n errors: toNestErrors(errors, options),\n } as const;\n }\n\n // Otherwise, return resolver result with values\n return {\n values: resolverOptions.raw ? Object.assign({}, values) : result.output,\n errors: {},\n };\n };\n}\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","Object","assign","abortPipeEarly","then","result","issues","errors","create","length","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","shift","toNestErrors","raw","output","e","reject"],"mappings":"ubAoDM,SACJA,EACAC,EAGAC,GAYA,gBAZAA,IAAAA,EAUI,CAAE,GAEQC,SAAAA,EAAeC,EAAGC,OAE9B,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAcA,eACjCX,EACAG,EACAS,OAAOC,OAAO,CAAA,EAAIZ,EAAe,CAC/Ba,gBAAiBR,MAEpBS,KAAA,SANKC,GASN,GAAIA,EAAOC,OAAQ,CASjB,IAHA,IAAMC,EAAqCN,OAAOO,OAAO,MAGlDH,EAAOC,OAAOG,QAAU,CAC7B,IAAMC,EAAQL,EAAOC,OAAO,GAEtBK,EAAOC,EAAUA,WAACF,GAExB,GAAIC,IAEGJ,EAAOI,KACVJ,EAAOI,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDnB,GAA0B,CAC5B,IAAMoB,EAAQR,EAAOI,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCP,EAAOI,GAAQM,EAAYA,aACzBN,EACAhB,EACAY,EACAG,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEd,CAGFR,EAAOC,OAAOa,OAChB,CAGA,MAAO,CACL3B,OAAQ,GACRe,OAAQa,EAAAA,aAAab,EAAQb,GAEjC,CAGA,MAAO,CACLF,OAAQD,EAAgB8B,IAAMpB,OAAOC,OAAO,CAAE,EAAEV,GAAUa,EAAOiB,OACjEf,OAAQ,GACR,EACJ,CAAC,MAAAgB,UAAAzB,QAAA0B,OAAAD,EACH,CAAA,CAAA"}
node_modules/@hookform/resolvers/valibot/package.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@hookform/resolvers/valibot",
3
+ "amdName": "hookformResolversValibot",
4
+ "version": "1.0.0",
5
+ "private": true,
6
+ "description": "React Hook Form validation resolver: valibot",
7
+ "main": "dist/valibot.js",
8
+ "module": "dist/valibot.module.js",
9
+ "umd:main": "dist/valibot.umd.js",
10
+ "source": "src/index.ts",
11
+ "types": "dist/index.d.ts",
12
+ "license": "MIT",
13
+ "peerDependencies": {
14
+ "@hookform/resolvers": "^2.0.0",
15
+ "react-hook-form": "^7.55.0",
16
+ "valibot": ">=0.31.0 || ^1.0.0-beta.4 || ^1.0.0-rc"
17
+ }
18
+ }