@hookform/resolvers 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -5
- package/package.json +11 -11
- package/typebox/dist/typebox.js +1 -1
- package/typebox/dist/typebox.js.map +1 -1
- package/typebox/dist/typebox.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs.map +1 -1
- package/typebox/dist/typebox.module.js +1 -1
- package/typebox/dist/typebox.module.js.map +1 -1
- package/typebox/dist/typebox.umd.js +1 -1
- package/typebox/dist/typebox.umd.js.map +1 -1
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +56 -56
- package/typebox/src/typebox.ts +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
```
|
|
30
30
|
type Options = {
|
|
31
31
|
mode: 'async' | 'sync',
|
|
32
|
-
|
|
32
|
+
raw?: boolean
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
resolver(schema: object, schemaOptions?: object, resolverOptions: Options)
|
|
@@ -494,12 +494,27 @@ Thanks goes to all our backers! [[Become a backer](https://opencollective.com/re
|
|
|
494
494
|
<img src="https://opencollective.com/react-hook-form/backers.svg?width=950" />
|
|
495
495
|
</a>
|
|
496
496
|
|
|
497
|
-
|
|
497
|
+
### Sponsors
|
|
498
498
|
|
|
499
|
-
Thanks
|
|
499
|
+
Thanks go to these kind and lovely sponsors!
|
|
500
500
|
|
|
501
|
-
<a href=
|
|
502
|
-
<img src="https://opencollective.com/
|
|
501
|
+
<a target="_blank" href='https://wantedlyinc.com'>
|
|
502
|
+
<img width="94" src="https://images.opencollective.com/wantedly/d94e44e/logo/256.png" />
|
|
503
|
+
</a>
|
|
504
|
+
<a target="_blank" href='https://toss.im'>
|
|
505
|
+
<img width="94" src="https://images.opencollective.com/toss/3ed69b3/logo/256.png" />
|
|
506
|
+
</a>
|
|
507
|
+
<a target="_blank" href="https://graphcms.com">
|
|
508
|
+
<img width="94" src="https://avatars.githubusercontent.com/u/31031438" />
|
|
509
|
+
</a>
|
|
510
|
+
<a target="_blank" href="https://www.beekai.com/">
|
|
511
|
+
<img width="94" src="https://www.beekai.com/marketing/logo/logo.svg" />
|
|
512
|
+
</a>
|
|
513
|
+
<a target="_blank" href="https://kanamekey.com">
|
|
514
|
+
<img width="94" src="https://images.opencollective.com/kaname/d15fd98/logo/256.png" />
|
|
515
|
+
</a>
|
|
516
|
+
<a target="_blank" href="https://formcarry.com/">
|
|
517
|
+
<img width="94" src="https://images.opencollective.com/formcarry/a40a4ea/logo/256.png" />
|
|
503
518
|
</a>
|
|
504
519
|
|
|
505
520
|
## Contributors
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hookform/resolvers",
|
|
3
3
|
"amdName": "hookformResolvers",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox and Typanion",
|
|
6
6
|
"main": "dist/resolvers.js",
|
|
7
7
|
"module": "dist/resolvers.module.js",
|
|
@@ -186,16 +186,16 @@
|
|
|
186
186
|
},
|
|
187
187
|
"homepage": "https://react-hook-form.com",
|
|
188
188
|
"devDependencies": {
|
|
189
|
-
"@sinclair/typebox": "^0.
|
|
189
|
+
"@sinclair/typebox": "^0.26.3",
|
|
190
190
|
"@testing-library/dom": "^9.0.1",
|
|
191
191
|
"@testing-library/jest-dom": "^5.16.5",
|
|
192
192
|
"@testing-library/react": "^14.0.0",
|
|
193
193
|
"@testing-library/user-event": "^14.4.3",
|
|
194
|
-
"@types/node": "^18.15.
|
|
194
|
+
"@types/node": "^18.15.7",
|
|
195
195
|
"@types/react": "^18.0.28",
|
|
196
196
|
"@types/testing-library__jest-dom": "^5.14.5",
|
|
197
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
198
|
-
"@typescript-eslint/parser": "^5.
|
|
197
|
+
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
|
198
|
+
"@typescript-eslint/parser": "^5.56.0",
|
|
199
199
|
"@vitejs/plugin-react": "^3.1.0",
|
|
200
200
|
"ajv": "^8.12.0",
|
|
201
201
|
"ajv-errors": "^3.0.0",
|
|
@@ -205,12 +205,12 @@
|
|
|
205
205
|
"computed-types": "^1.11.2",
|
|
206
206
|
"cross-env": "^7.0.3",
|
|
207
207
|
"eslint": "^8.36.0",
|
|
208
|
-
"eslint-config-prettier": "^8.
|
|
208
|
+
"eslint-config-prettier": "^8.8.0",
|
|
209
209
|
"fp-ts": "^2.13.1",
|
|
210
210
|
"husky": "^8.0.3",
|
|
211
211
|
"io-ts": "^2.2.20",
|
|
212
212
|
"io-ts-types": "^0.5.19",
|
|
213
|
-
"joi": "^17.
|
|
213
|
+
"joi": "^17.9.1",
|
|
214
214
|
"jsdom": "^21.1.1",
|
|
215
215
|
"lint-staged": "^13.2.0",
|
|
216
216
|
"microbundle": "^0.15.1",
|
|
@@ -218,18 +218,18 @@
|
|
|
218
218
|
"newtype-ts": "^0.3.5",
|
|
219
219
|
"nope-validator": "^1.0.4",
|
|
220
220
|
"npm-run-all": "^4.1.5",
|
|
221
|
-
"prettier": "^2.8.
|
|
221
|
+
"prettier": "^2.8.7",
|
|
222
222
|
"react": "^18.2.0",
|
|
223
223
|
"react-dom": "^18.2.0",
|
|
224
|
-
"react-hook-form": "^7.43.
|
|
224
|
+
"react-hook-form": "^7.43.7",
|
|
225
225
|
"reflect-metadata": "^0.1.13",
|
|
226
226
|
"superstruct": "^1.0.3",
|
|
227
227
|
"typanion": "^3.12.1",
|
|
228
228
|
"typescript": "^5.0.2",
|
|
229
229
|
"vest": "^4.6.9",
|
|
230
|
-
"vite": "^4.2.
|
|
230
|
+
"vite": "^4.2.1",
|
|
231
231
|
"vite-tsconfig-paths": "^4.0.7",
|
|
232
|
-
"vitest": "^0.29.
|
|
232
|
+
"vitest": "^0.29.7",
|
|
233
233
|
"yup": "^1.0.2",
|
|
234
234
|
"zod": "^3.21.4"
|
|
235
235
|
},
|
package/typebox/dist/typebox.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("react-hook-form"),r=require("@hookform/resolvers"),
|
|
1
|
+
var e=require("react-hook-form"),r=require("@hookform/resolvers"),a=require("@sinclair/typebox/value"),s=function(r,a){for(var s={};r.length;){var t=r[0],o=t.type,i=t.message,l=t.path.substring(1).replace(/\//g,".");if(s[l]||(s[l]={message:i,type:""+o}),a){var n=s[l].types,u=n&&n[""+o];s[l]=e.appendErrors(l,a,s,""+o,u?[].concat(u,t.message):t.message)}r.shift()}return s};exports.typeboxResolver=function(e){return function(t,o,i){try{var l=Array.from(a.Value.Errors(e,t));return i.shouldUseNativeValidation&&r.validateFieldsNatively({},i),Promise.resolve(l.length?{values:{},errors:r.toNestError(s(l,!i.shouldUseNativeValidation&&"all"===i.criteriaMode),i)}:{errors:{},values:t})}catch(e){return Promise.reject(e)}}};
|
|
2
2
|
//# sourceMappingURL=typebox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors =
|
|
1
|
+
{"version":3,"file":"typebox.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(Value.Errors(schema, values));\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","schema","values","_","options","Array","from","Value","Errors","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestError","criteriaMode","e","reject"],"mappings":"uGAKMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EAAYA,aAC1BN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAQe,OACT,CAED,OAAOb,CACT,0BAGE,SAACc,GAAM,OAAA,SAAYC,EAAQC,EAAGC,GAAW,IACvC,IAAMjB,EAASkB,MAAMC,KAAKC,EAAAA,MAAMC,OAAOP,EAAQC,IAI/C,OAFAE,EAAQK,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIN,GAShEO,QAAAC,QAPKzB,EAAOC,OAOL,CACLc,OAAQ,CAAE,EACVf,OAAQ0B,EAAAA,YACN7B,EACEG,GACCiB,EAAQK,2BAAsD,QAAzBL,EAAQU,cAEhDV,IAbK,CACLjB,OAAQ,GACRe,OAAAA,GAcN,CAAC,MAAAa,GAAAJ,OAAAA,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
|
package/typebox/dist/typebox.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";import{Value as t}from"@sinclair/typebox/value";var a=function(e,o){for(var t={};e.length;){var a=e[0],s=a.type,i=a.message,n=a.path.substring(1).replace(/\//g,".");if(t[n]||(t[n]={message:i,type:""+s}),o){var l=t[n].types,
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";import{Value as t}from"@sinclair/typebox/value";var a=function(e,o){for(var t={};e.length;){var a=e[0],s=a.type,i=a.message,n=a.path.substring(1).replace(/\//g,".");if(t[n]||(t[n]={message:i,type:""+s}),o){var l=t[n].types,m=l&&l[""+s];t[n]=r(n,o,t,""+s,m?[].concat(m,a.message):a.message)}e.shift()}return t},s=function(r){return function(s,i,n){try{var l=Array.from(t.Errors(r,s));return n.shouldUseNativeValidation&&e({},n),Promise.resolve(l.length?{values:{},errors:o(a(l,!n.shouldUseNativeValidation&&"all"===n.criteriaMode),n)}:{errors:{},values:s})}catch(r){return Promise.reject(r)}}};export{s as typeboxResolver};
|
|
2
2
|
//# sourceMappingURL=typebox.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";import{Value as s}from"@sinclair/typebox/value";const t=(e,o)=>{const s={};for(;e.length;){const t=e[0],{type:a,message:i,path:n}=t,l=n.substring(1).replace(/\//g,".");if(s[l]||(s[l]={message:i,type:""+a}),o){const e=s[l].types,i=e&&e[""+a];s[l]=r(l,o,s,""+a,i?[].concat(i,t.message):t.message)}e.shift()}return s},a=r=>async(a,i,n)=>{const l=Array.from(s.Errors(r,a));return n.shouldUseNativeValidation&&e({},n),l.length?{values:{},errors:o(t(l,!n.shouldUseNativeValidation&&"all"===n.criteriaMode),n)}:{errors:{},values:a}};export{a as typeboxResolver};
|
|
2
2
|
//# sourceMappingURL=typebox.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.modern.mjs","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors =
|
|
1
|
+
{"version":3,"file":"typebox.modern.mjs","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(Value.Errors(schema, values));\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","path","_path","substring","replace","types","messages","appendErrors","concat","shift","typeboxResolver","schema","async","values","_","options","Array","from","Value","Errors","shouldUseNativeValidation","validateFieldsNatively","toNestError","criteriaMode"],"mappings":"6KAKA,MAAMA,EAAmBA,CACvBC,EACAC,KAEA,MAAMC,EAAqC,CAAA,EAC3C,KAAOF,EAAQG,QAAU,CACvB,MAAMC,EAAQJ,EAAQ,IAChBK,KAAEA,EAAIC,QAAEA,EAAOC,KAAEA,GAASH,EAC1BI,EAAQD,EAAKE,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOM,KACVN,EAAOM,GAAS,CAAEF,UAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,MAAMU,EAAQT,EAAOM,GAAOG,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOM,GAASK,EACdL,EACAP,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAQe,OACT,CAED,OAAOb,GAGIc,EACVC,GAAWC,MAAOC,EAAQC,EAAGC,KAC5B,MAAMnB,EAASoB,MAAMC,KAAKC,EAAMC,OAAOR,EAAQE,IAI/C,OAFAE,EAAQK,2BAA6BC,EAAuB,CAAE,EAAEN,GAE3DnB,EAAOC,OAOL,CACLgB,OAAQ,CAAA,EACRjB,OAAQ0B,EACN7B,EACEG,GACCmB,EAAQK,2BAAsD,QAAzBL,EAAQQ,cAEhDR,IAbK,CACLnB,OAAQ,CAAA,EACRiB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";import{Value as t}from"@sinclair/typebox/value";var a=function(e,o){for(var t={};e.length;){var a=e[0],s=a.type,i=a.message,n=a.path.substring(1).replace(/\//g,".");if(t[n]||(t[n]={message:i,type:""+s}),o){var l=t[n].types,
|
|
1
|
+
import{appendErrors as r}from"react-hook-form";import{validateFieldsNatively as e,toNestError as o}from"@hookform/resolvers";import{Value as t}from"@sinclair/typebox/value";var a=function(e,o){for(var t={};e.length;){var a=e[0],s=a.type,i=a.message,n=a.path.substring(1).replace(/\//g,".");if(t[n]||(t[n]={message:i,type:""+s}),o){var l=t[n].types,m=l&&l[""+s];t[n]=r(n,o,t,""+s,m?[].concat(m,a.message):a.message)}e.shift()}return t},s=function(r){return function(s,i,n){try{var l=Array.from(t.Errors(r,s));return n.shouldUseNativeValidation&&e({},n),Promise.resolve(l.length?{values:{},errors:o(a(l,!n.shouldUseNativeValidation&&"all"===n.criteriaMode),n)}:{errors:{},values:s})}catch(r){return Promise.reject(r)}}};export{s as typeboxResolver};
|
|
2
2
|
//# sourceMappingURL=typebox.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.module.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors =
|
|
1
|
+
{"version":3,"file":"typebox.module.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(Value.Errors(schema, values));\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","typeboxResolver","schema","values","_","options","Array","from","Value","Errors","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestError","criteriaMode","e","reject"],"mappings":"6KAKA,IAAMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EACdN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAQe,OACT,CAED,OAAOb,CACT,EAEac,EACX,SAACC,GAAM,OAAA,SAAYC,EAAQC,EAAGC,GAAW,IACvC,IAAMlB,EAASmB,MAAMC,KAAKC,EAAMC,OAAOP,EAAQC,IAI/C,OAFAE,EAAQK,2BAA6BC,EAAuB,CAAA,EAAIN,GAShEO,QAAAC,QAPK1B,EAAOC,OAOL,CACLe,OAAQ,CAAE,EACVhB,OAAQ2B,EACN9B,EACEG,GACCkB,EAAQK,2BAAsD,QAAzBL,EAAQU,cAEhDV,IAbK,CACLlB,OAAQ,GACRgB,OAAAA,GAcN,CAAC,MAAAa,GAAAJ,OAAAA,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react-hook-form"),require("@hookform/resolvers"),require("@sinclair/typebox/value")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers","@sinclair/typebox/value"],r):r((e||self).hookformResolversTypebox={},e.ReactHookForm,e.hookformResolvers,e.value)}(this,function(e,r,o,t){var s=function(e,o){for(var t={};e.length;){var s=e[0],a=s.type,i=s.message,
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react-hook-form"),require("@hookform/resolvers"),require("@sinclair/typebox/value")):"function"==typeof define&&define.amd?define(["exports","react-hook-form","@hookform/resolvers","@sinclair/typebox/value"],r):r((e||self).hookformResolversTypebox={},e.ReactHookForm,e.hookformResolvers,e.value)}(this,function(e,r,o,t){var s=function(e,o){for(var t={};e.length;){var s=e[0],a=s.type,i=s.message,l=s.path.substring(1).replace(/\//g,".");if(t[l]||(t[l]={message:i,type:""+a}),o){var n=t[l].types,f=n&&n[""+a];t[l]=r.appendErrors(l,o,t,""+a,f?[].concat(f,s.message):s.message)}e.shift()}return t};e.typeboxResolver=function(e){return function(r,a,i){try{var l=Array.from(t.Value.Errors(e,r));return i.shouldUseNativeValidation&&o.validateFieldsNatively({},i),Promise.resolve(l.length?{values:{},errors:o.toNestError(s(l,!i.shouldUseNativeValidation&&"all"===i.criteriaMode),i)}:{errors:{},values:r})}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=typebox.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.umd.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors =
|
|
1
|
+
{"version":3,"file":"typebox.umd.js","sources":["../src/typebox.ts"],"sourcesContent":["import { appendErrors, FieldError, FieldErrors } from 'react-hook-form';\nimport { toNestError, validateFieldsNatively } from '@hookform/resolvers';\nimport type { Resolver } from './types';\nimport { Value, ValueError } from '@sinclair/typebox/value';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(Value.Errors(schema, values));\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestError(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","schema","values","_","options","Array","from","Value","Errors","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestError","criteriaMode","e","reject"],"mappings":"mcAKA,IAAMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,CAAE,EACtCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EAAYA,aAC1BN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEb,CAEDN,EAAQe,OACT,CAED,OAAOb,CACT,oBAGE,SAACc,GAAM,OAAA,SAAYC,EAAQC,EAAGC,GAAW,IACvC,IAAMjB,EAASkB,MAAMC,KAAKC,EAAAA,MAAMC,OAAOP,EAAQC,IAI/C,OAFAE,EAAQK,2BAA6BC,EAAAA,uBAAuB,CAAA,EAAIN,GAShEO,QAAAC,QAPKzB,EAAOC,OAOL,CACLc,OAAQ,CAAE,EACVf,OAAQ0B,EAAAA,YACN7B,EACEG,GACCiB,EAAQK,2BAAsD,QAAzBL,EAAQU,cAEhDV,IAbK,CACLjB,OAAQ,GACRe,OAAAA,GAcN,CAAC,MAAAa,GAAAJ,OAAAA,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -4,43 +4,43 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
|
|
|
4
4
|
{
|
|
5
5
|
"errors": {
|
|
6
6
|
"accessToken": {
|
|
7
|
-
"message": "Expected
|
|
7
|
+
"message": "Expected string",
|
|
8
8
|
"ref": undefined,
|
|
9
|
-
"type": "
|
|
9
|
+
"type": "43",
|
|
10
10
|
},
|
|
11
11
|
"birthYear": {
|
|
12
12
|
"message": "Expected number",
|
|
13
13
|
"ref": undefined,
|
|
14
|
-
"type": "
|
|
14
|
+
"type": "29",
|
|
15
15
|
},
|
|
16
16
|
"dateStr": {
|
|
17
|
-
"message": "Expected
|
|
17
|
+
"message": "Expected Date object",
|
|
18
18
|
"ref": undefined,
|
|
19
|
-
"type": "
|
|
19
|
+
"type": "11",
|
|
20
20
|
},
|
|
21
21
|
"email": {
|
|
22
22
|
"message": "Expected string to match format 'email'",
|
|
23
23
|
"ref": {
|
|
24
24
|
"name": "email",
|
|
25
25
|
},
|
|
26
|
-
"type": "
|
|
26
|
+
"type": "48",
|
|
27
27
|
},
|
|
28
28
|
"enabled": {
|
|
29
|
-
"message": "Expected
|
|
29
|
+
"message": "Expected boolean",
|
|
30
30
|
"ref": undefined,
|
|
31
|
-
"type": "
|
|
31
|
+
"type": "10",
|
|
32
32
|
},
|
|
33
33
|
"like": [
|
|
34
34
|
{
|
|
35
35
|
"id": {
|
|
36
36
|
"message": "Expected number",
|
|
37
37
|
"ref": undefined,
|
|
38
|
-
"type": "
|
|
38
|
+
"type": "29",
|
|
39
39
|
},
|
|
40
40
|
"name": {
|
|
41
|
-
"message": "Expected
|
|
41
|
+
"message": "Expected string",
|
|
42
42
|
"ref": undefined,
|
|
43
|
-
"type": "
|
|
43
|
+
"type": "43",
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
],
|
|
@@ -49,24 +49,24 @@ exports[`typeboxResolver > should return a single error from typeboxResolver whe
|
|
|
49
49
|
"ref": {
|
|
50
50
|
"name": "password",
|
|
51
51
|
},
|
|
52
|
-
"type": "
|
|
52
|
+
"type": "44",
|
|
53
53
|
},
|
|
54
54
|
"repeatPassword": {
|
|
55
|
-
"message": "Expected
|
|
55
|
+
"message": "Expected string",
|
|
56
56
|
"ref": undefined,
|
|
57
|
-
"type": "
|
|
57
|
+
"type": "43",
|
|
58
58
|
},
|
|
59
59
|
"tags": {
|
|
60
|
-
"message": "Expected
|
|
60
|
+
"message": "Expected array",
|
|
61
61
|
"ref": undefined,
|
|
62
|
-
"type": "
|
|
62
|
+
"type": "0",
|
|
63
63
|
},
|
|
64
64
|
"username": {
|
|
65
|
-
"message": "Expected
|
|
65
|
+
"message": "Expected string",
|
|
66
66
|
"ref": {
|
|
67
67
|
"name": "username",
|
|
68
68
|
},
|
|
69
|
-
"type": "
|
|
69
|
+
"type": "43",
|
|
70
70
|
},
|
|
71
71
|
},
|
|
72
72
|
"values": {},
|
|
@@ -77,31 +77,31 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
|
|
|
77
77
|
{
|
|
78
78
|
"errors": {
|
|
79
79
|
"accessToken": {
|
|
80
|
-
"message": "Expected
|
|
80
|
+
"message": "Expected string",
|
|
81
81
|
"ref": undefined,
|
|
82
|
-
"type": "
|
|
82
|
+
"type": "43",
|
|
83
83
|
"types": {
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
84
|
+
"29": "Expected number",
|
|
85
|
+
"39": "Expected required property",
|
|
86
|
+
"43": "Expected string",
|
|
87
|
+
"53": "Expected value of union",
|
|
88
88
|
},
|
|
89
89
|
},
|
|
90
90
|
"birthYear": {
|
|
91
91
|
"message": "Expected number",
|
|
92
92
|
"ref": undefined,
|
|
93
|
-
"type": "
|
|
93
|
+
"type": "29",
|
|
94
94
|
"types": {
|
|
95
|
-
"
|
|
95
|
+
"29": "Expected number",
|
|
96
96
|
},
|
|
97
97
|
},
|
|
98
98
|
"dateStr": {
|
|
99
|
-
"message": "Expected
|
|
99
|
+
"message": "Expected Date object",
|
|
100
100
|
"ref": undefined,
|
|
101
|
-
"type": "
|
|
101
|
+
"type": "11",
|
|
102
102
|
"types": {
|
|
103
|
-
"
|
|
104
|
-
"
|
|
103
|
+
"11": "Expected Date object",
|
|
104
|
+
"39": "Expected required property",
|
|
105
105
|
},
|
|
106
106
|
},
|
|
107
107
|
"email": {
|
|
@@ -109,18 +109,18 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
|
|
|
109
109
|
"ref": {
|
|
110
110
|
"name": "email",
|
|
111
111
|
},
|
|
112
|
-
"type": "
|
|
112
|
+
"type": "48",
|
|
113
113
|
"types": {
|
|
114
|
-
"
|
|
114
|
+
"48": "Expected string to match format 'email'",
|
|
115
115
|
},
|
|
116
116
|
},
|
|
117
117
|
"enabled": {
|
|
118
|
-
"message": "Expected
|
|
118
|
+
"message": "Expected boolean",
|
|
119
119
|
"ref": undefined,
|
|
120
|
-
"type": "
|
|
120
|
+
"type": "10",
|
|
121
121
|
"types": {
|
|
122
|
-
"
|
|
123
|
-
"
|
|
122
|
+
"10": "Expected boolean",
|
|
123
|
+
"39": "Expected required property",
|
|
124
124
|
},
|
|
125
125
|
},
|
|
126
126
|
"like": [
|
|
@@ -128,18 +128,18 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
|
|
|
128
128
|
"id": {
|
|
129
129
|
"message": "Expected number",
|
|
130
130
|
"ref": undefined,
|
|
131
|
-
"type": "
|
|
131
|
+
"type": "29",
|
|
132
132
|
"types": {
|
|
133
|
-
"
|
|
133
|
+
"29": "Expected number",
|
|
134
134
|
},
|
|
135
135
|
},
|
|
136
136
|
"name": {
|
|
137
|
-
"message": "Expected
|
|
137
|
+
"message": "Expected string",
|
|
138
138
|
"ref": undefined,
|
|
139
|
-
"type": "
|
|
139
|
+
"type": "43",
|
|
140
140
|
"types": {
|
|
141
|
-
"
|
|
142
|
-
"
|
|
141
|
+
"39": "Expected required property",
|
|
142
|
+
"43": "Expected string",
|
|
143
143
|
},
|
|
144
144
|
},
|
|
145
145
|
},
|
|
@@ -149,39 +149,39 @@ exports[`typeboxResolver > should return all the errors from typeboxResolver whe
|
|
|
149
149
|
"ref": {
|
|
150
150
|
"name": "password",
|
|
151
151
|
},
|
|
152
|
-
"type": "
|
|
152
|
+
"type": "44",
|
|
153
153
|
"types": {
|
|
154
|
-
"
|
|
155
|
-
"
|
|
154
|
+
"44": "Expected string length greater or equal to 8",
|
|
155
|
+
"46": "Expected string to match pattern ^(.*[A-Za-z\\\\d].*)$",
|
|
156
156
|
},
|
|
157
157
|
},
|
|
158
158
|
"repeatPassword": {
|
|
159
|
-
"message": "Expected
|
|
159
|
+
"message": "Expected string",
|
|
160
160
|
"ref": undefined,
|
|
161
|
-
"type": "
|
|
161
|
+
"type": "43",
|
|
162
162
|
"types": {
|
|
163
|
-
"
|
|
164
|
-
"
|
|
163
|
+
"39": "Expected required property",
|
|
164
|
+
"43": "Expected string",
|
|
165
165
|
},
|
|
166
166
|
},
|
|
167
167
|
"tags": {
|
|
168
|
-
"message": "Expected
|
|
168
|
+
"message": "Expected array",
|
|
169
169
|
"ref": undefined,
|
|
170
|
-
"type": "
|
|
170
|
+
"type": "0",
|
|
171
171
|
"types": {
|
|
172
172
|
"0": "Expected array",
|
|
173
|
-
"
|
|
173
|
+
"39": "Expected required property",
|
|
174
174
|
},
|
|
175
175
|
},
|
|
176
176
|
"username": {
|
|
177
|
-
"message": "Expected
|
|
177
|
+
"message": "Expected string",
|
|
178
178
|
"ref": {
|
|
179
179
|
"name": "username",
|
|
180
180
|
},
|
|
181
|
-
"type": "
|
|
181
|
+
"type": "43",
|
|
182
182
|
"types": {
|
|
183
|
-
"
|
|
184
|
-
"
|
|
183
|
+
"39": "Expected required property",
|
|
184
|
+
"43": "Expected string",
|
|
185
185
|
},
|
|
186
186
|
},
|
|
187
187
|
},
|
package/typebox/src/typebox.ts
CHANGED
|
@@ -40,7 +40,7 @@ const parseErrorSchema = (
|
|
|
40
40
|
|
|
41
41
|
export const typeboxResolver: Resolver =
|
|
42
42
|
(schema) => async (values, _, options) => {
|
|
43
|
-
const errors =
|
|
43
|
+
const errors = Array.from(Value.Errors(schema, values));
|
|
44
44
|
|
|
45
45
|
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
|
|
46
46
|
|