@hookform/resolvers 3.5.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -33
- package/package.json +17 -5
- package/valibot/dist/types.d.ts +2 -2
- package/valibot/dist/valibot.js +1 -1
- package/valibot/dist/valibot.js.map +1 -1
- package/valibot/dist/valibot.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs.map +1 -1
- package/valibot/dist/valibot.module.js +1 -1
- package/valibot/dist/valibot.module.js.map +1 -1
- package/valibot/dist/valibot.umd.js +1 -1
- package/valibot/dist/valibot.umd.js.map +1 -1
- package/valibot/package.json +2 -2
- package/valibot/src/__tests__/Form-native-validation.tsx +14 -14
- package/valibot/src/__tests__/Form.tsx +11 -11
- package/valibot/src/__tests__/__fixtures__/data.ts +43 -53
- package/valibot/src/__tests__/__snapshots__/valibot.ts.snap +50 -50
- package/valibot/src/__tests__/valibot.ts +13 -11
- package/valibot/src/types.ts +15 -3
- package/valibot/src/valibot.ts +55 -77
- package/vine/dist/index.d.ts +2 -0
- package/vine/dist/types.d.ts +6 -0
- package/vine/dist/vine.d.ts +2 -0
- package/vine/dist/vine.js +2 -0
- package/vine/dist/vine.js.map +1 -0
- package/vine/dist/vine.mjs +2 -0
- package/vine/dist/vine.modern.mjs +2 -0
- package/vine/dist/vine.modern.mjs.map +1 -0
- package/vine/dist/vine.module.js +2 -0
- package/vine/dist/vine.module.js.map +1 -0
- package/vine/dist/vine.umd.js +2 -0
- package/vine/dist/vine.umd.js.map +1 -0
- package/vine/package.json +18 -0
- package/vine/src/__tests__/Form-native-validation.tsx +81 -0
- package/vine/src/__tests__/Form.tsx +55 -0
- package/vine/src/__tests__/__fixtures__/data.ts +74 -0
- package/vine/src/__tests__/__snapshots__/vine.ts.snap +180 -0
- package/vine/src/__tests__/vine.ts +53 -0
- package/vine/src/index.ts +2 -0
- package/vine/src/types.ts +13 -0
- package/vine/src/vine.ts +66 -0
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/zod.ts +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
- [ArkType](#arktype)
|
|
47
47
|
- [Valibot](#valibot)
|
|
48
48
|
- [effect-ts](#effect-ts)
|
|
49
|
+
- [VineJS](#vinejs)
|
|
49
50
|
- [Backers](#backers)
|
|
50
51
|
- [Sponsors](#sponsors)
|
|
51
52
|
- [Contributors](#contributors)
|
|
@@ -552,14 +553,15 @@ The modular and type safe schema library for validating structural data
|
|
|
552
553
|
```typescript jsx
|
|
553
554
|
import { useForm } from 'react-hook-form';
|
|
554
555
|
import { valibotResolver } from '@hookform/resolvers/valibot';
|
|
555
|
-
import
|
|
556
|
+
import * as v from 'valibot';
|
|
556
557
|
|
|
557
|
-
const schema = object({
|
|
558
|
-
username:
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
558
|
+
const schema = v.object({
|
|
559
|
+
username: v.pipe(
|
|
560
|
+
v.string('username is required'),
|
|
561
|
+
v.minLength(3, 'Needs to be at least 3 characters'),
|
|
562
|
+
v.endsWith('cool', 'Needs to end with `cool`'),
|
|
563
|
+
),
|
|
564
|
+
password: v.string('password is required'),
|
|
563
565
|
});
|
|
564
566
|
|
|
565
567
|
const App = () => {
|
|
@@ -581,7 +583,7 @@ const App = () => {
|
|
|
581
583
|
|
|
582
584
|
A powerful TypeScript framework that provides a fully-fledged functional effect system with a rich standard library.
|
|
583
585
|
|
|
584
|
-
[](https://bundlephobia.com/result?p=effect)
|
|
585
587
|
|
|
586
588
|
```typescript jsx
|
|
587
589
|
import React from 'react';
|
|
@@ -628,40 +630,52 @@ function TestComponent({ onSubmit }: Props) {
|
|
|
628
630
|
}
|
|
629
631
|
```
|
|
630
632
|
|
|
631
|
-
|
|
633
|
+
### [VineJS](https://github.com/vinejs/vine)
|
|
632
634
|
|
|
633
|
-
|
|
635
|
+
VineJS is a form data validation library for Node.js
|
|
634
636
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
637
|
+
[](https://bundlephobia.com/result?p=@vinejs/vine)
|
|
638
|
+
|
|
639
|
+
```typescript jsx
|
|
640
|
+
import { useForm } from 'react-hook-form';
|
|
641
|
+
import { vineResolver } from '@hookform/resolvers/vine';
|
|
642
|
+
import vine from '@vinejs/vine';
|
|
638
643
|
|
|
639
|
-
|
|
644
|
+
const schema = vine.compile(
|
|
645
|
+
vine.object({
|
|
646
|
+
username: vine.string().minLength(1),
|
|
647
|
+
password: vine.string().minLength(1),
|
|
648
|
+
}),
|
|
649
|
+
);
|
|
640
650
|
|
|
641
|
-
|
|
651
|
+
const App = () => {
|
|
652
|
+
const { register, handleSubmit } = useForm({
|
|
653
|
+
resolver: vineResolver(schema),
|
|
654
|
+
});
|
|
642
655
|
|
|
643
|
-
|
|
644
|
-
<
|
|
645
|
-
|
|
646
|
-
<
|
|
647
|
-
|
|
648
|
-
</
|
|
649
|
-
<
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
656
|
+
return (
|
|
657
|
+
<form onSubmit={handleSubmit((d) => console.log(d))}>
|
|
658
|
+
<input {...register('username')} />
|
|
659
|
+
{errors.username && <span role="alert">{errors.username.message}</span>}
|
|
660
|
+
<input {...register('password')} />
|
|
661
|
+
{errors.password && <span role="alert">{errors.password.message}</span>}
|
|
662
|
+
<button type="submit">submit</button>
|
|
663
|
+
</form>
|
|
664
|
+
);
|
|
665
|
+
};
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
## Backers
|
|
669
|
+
|
|
670
|
+
Thanks go to all our backers! [[Become a backer](https://opencollective.com/react-hook-form#backer)].
|
|
671
|
+
|
|
672
|
+
<a href="https://opencollective.com/react-hook-form#backers">
|
|
673
|
+
<img src="https://opencollective.com/react-hook-form/backers.svg?width=950" />
|
|
660
674
|
</a>
|
|
661
675
|
|
|
662
676
|
## Contributors
|
|
663
677
|
|
|
664
|
-
Thanks
|
|
678
|
+
Thanks go to these wonderful people! [[Become a contributor](CONTRIBUTING.md)].
|
|
665
679
|
|
|
666
680
|
<a href="https://github.com/react-hook-form/react-hook-form/graphs/contributors">
|
|
667
681
|
<img src="https://opencollective.com/react-hook-form/contributors.svg?width=950" />
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hookform/resolvers",
|
|
3
3
|
"amdName": "hookformResolvers",
|
|
4
|
-
"version": "3.
|
|
5
|
-
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion
|
|
4
|
+
"version": "3.7.0",
|
|
5
|
+
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion, Effect-TS and VineJS",
|
|
6
6
|
"main": "dist/resolvers.js",
|
|
7
7
|
"module": "dist/resolvers.module.js",
|
|
8
8
|
"umd:main": "dist/resolvers.umd.js",
|
|
@@ -105,6 +105,12 @@
|
|
|
105
105
|
"import": "./effect-ts/dist/effect-ts.mjs",
|
|
106
106
|
"require": "./effect-ts/dist/effect-ts.js"
|
|
107
107
|
},
|
|
108
|
+
"./vine": {
|
|
109
|
+
"types": "./vine/dist/index.d.ts",
|
|
110
|
+
"umd": "./vine/dist/vine.umd.js",
|
|
111
|
+
"import": "./vine/dist/vine.mjs",
|
|
112
|
+
"require": "./vine/dist/vine.js"
|
|
113
|
+
},
|
|
108
114
|
"./package.json": "./package.json",
|
|
109
115
|
"./*": "./*"
|
|
110
116
|
},
|
|
@@ -154,7 +160,10 @@
|
|
|
154
160
|
"valibot/dist",
|
|
155
161
|
"effect-ts/package.json",
|
|
156
162
|
"effect-ts/src",
|
|
157
|
-
"effect-ts/dist"
|
|
163
|
+
"effect-ts/dist",
|
|
164
|
+
"vine/package.json",
|
|
165
|
+
"vine/src",
|
|
166
|
+
"vine/dist"
|
|
158
167
|
],
|
|
159
168
|
"publishConfig": {
|
|
160
169
|
"access": "public"
|
|
@@ -178,6 +187,7 @@
|
|
|
178
187
|
"build:arktype": "microbundle --cwd arktype --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
179
188
|
"build:valibot": "microbundle --cwd valibot --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
180
189
|
"build:effect-ts": "microbundle --cwd effect-ts --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@effect/schema=EffectSchema,@effect/schema/AST=EffectSchemaAST,@effect/schema/ArrayFormatter=EffectSchemaArrayFormatter",
|
|
190
|
+
"build:vine": "microbundle --cwd vine --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@vinejs/vine=vine",
|
|
181
191
|
"postbuild": "node ./config/node-13-exports.js",
|
|
182
192
|
"lint": "eslint . --ext .ts,.js --ignore-path .gitignore",
|
|
183
193
|
"lint:types": "tsc",
|
|
@@ -207,7 +217,8 @@
|
|
|
207
217
|
"typanion",
|
|
208
218
|
"ajv",
|
|
209
219
|
"TypeBox",
|
|
210
|
-
"arktype"
|
|
220
|
+
"arktype",
|
|
221
|
+
"vine"
|
|
211
222
|
],
|
|
212
223
|
"repository": {
|
|
213
224
|
"type": "git",
|
|
@@ -230,6 +241,7 @@
|
|
|
230
241
|
"@types/react": "^18.2.20",
|
|
231
242
|
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
|
232
243
|
"@typescript-eslint/parser": "^6.4.1",
|
|
244
|
+
"@vinejs/vine": "^2.0.0",
|
|
233
245
|
"@vitejs/plugin-react": "^4.0.4",
|
|
234
246
|
"ajv": "^8.12.0",
|
|
235
247
|
"ajv-errors": "^3.0.0",
|
|
@@ -262,7 +274,7 @@
|
|
|
262
274
|
"superstruct": "^1.0.3",
|
|
263
275
|
"typanion": "^3.14.0",
|
|
264
276
|
"typescript": "^5.1.6",
|
|
265
|
-
"valibot": "
|
|
277
|
+
"valibot": "0.35.0",
|
|
266
278
|
"vest": "^4.6.11",
|
|
267
279
|
"vite": "^4.4.9",
|
|
268
280
|
"vite-tsconfig-paths": "^4.2.0",
|
package/valibot/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FieldValues, ResolverResult, ResolverOptions } from 'react-hook-form';
|
|
2
|
-
import { BaseSchema, BaseSchemaAsync,
|
|
3
|
-
export type Resolver = <T extends BaseSchema | BaseSchemaAsync
|
|
2
|
+
import { BaseIssue, BaseSchema, BaseSchemaAsync, Config, InferIssue } from 'valibot';
|
|
3
|
+
export type Resolver = <T extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(schema: T, schemaOptions?: Partial<Omit<Config<InferIssue<T>>, 'abortPipeEarly' | 'skipPipe'>>, resolverOptions?: {
|
|
4
4
|
/**
|
|
5
5
|
* @default async
|
|
6
6
|
*/
|
package/valibot/dist/valibot.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r=require("@hookform/resolvers"),e=require("
|
|
1
|
+
var r=require("@hookform/resolvers"),e=require("react-hook-form"),t=require("valibot");function o(){return o=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},o.apply(this,arguments)}function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,o=new Array(e);t<e;t++)o[t]=r[t];return o}exports.valibotResolver=function(a,i,s){return void 0===s&&(s={}),function(u,l,c){try{var f=!c.shouldUseNativeValidation&&"all"===c.criteriaMode;return Promise.resolve(t.safeParseAsync(a,u,o({},i,{abortPipeEarly:!f}))).then(function(o){if(o.issues){for(var a,i={},l=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return n(r,e);var t=Object.prototype.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))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}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.issues);!(a=l()).done;){var v=a.value,y=t.getDotPath(v);if(y&&(i[y]||(i[y]={message:v.message,type:v.type}),f)){var p=i[y].types,m=p&&p[v.type];i[y]=e.appendErrors(y,f,i,v.type,m?[].concat(m,v.message):v.message)}}return{values:{},errors:r.toNestErrors(i,c)}}return{values:s.raw?u:o.output,errors:{}}})}catch(r){return Promise.reject(r)}}};
|
|
2
2
|
//# sourceMappingURL=valibot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport
|
|
1
|
+
{"version":3,"file":"valibot.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, appendErrors, FieldValues } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, 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(schema, values, {\n ...schemaOptions,\n abortPipeEarly: !validateAllFieldCriteria,\n });\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (const issue of result.issues) {\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\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 ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","_extends","abortPipeEarly","then","result","issues","_step","errors","_iterator","_createForOfIteratorHelperLoose","done","issue","value","path","getDotPath","message","type","types","messages","appendErrors","concat","toNestErrors","raw","output","e","reject"],"mappings":"6bAME,SAACA,EAAQC,EAAeC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAcA,eAACX,EAAQG,EAAMS,EAAA,CAAA,EAC7CX,EAAa,CAChBY,gBAAiBP,MACjBQ,KAAA,SAHIC,GAMN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAGiCC,EAH3BC,EAAqC,CAAE,EAG7CC,2qBAAAC,CAAoBL,EAAOC,UAAMC,EAAAE,KAAAE,MAAE,KAAxBC,EAAKL,EAAAM,MAERC,EAAOC,EAAUA,WAACH,GAExB,GAAIE,IAEGN,EAAOM,KACVN,EAAOM,GAAQ,CAAEE,QAASJ,EAAMI,QAASC,KAAML,EAAMK,OAInDrB,GAA0B,CAC5B,IAAMsB,EAAQV,EAAOM,GAAMI,MACrBC,EAAWD,GAASA,EAAMN,EAAMK,MACtCT,EAAOM,GAAQM,EAAAA,aACbN,EACAlB,EACAY,EACAI,EAAMK,KACNE,EACK,GAAgBE,OACfF,EACAP,EAAMI,SAERJ,EAAMI,QAEb,CAEJ,CAGD,MAAO,CACLvB,OAAQ,GACRe,OAAQc,EAAAA,aAAad,EAAQb,GAEhC,CAGD,MAAO,CACLF,OAAQD,EAAgB+B,IAAM9B,EAAUY,EAAOmB,OAC/ChB,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAiB,GAAA1B,OAAAA,QAAA2B,OAAAD,EAAA,CAAA,CAAA"}
|
package/valibot/dist/valibot.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as r}from"@hookform/resolvers";import{
|
|
1
|
+
import{toNestErrors as r}from"@hookform/resolvers";import{appendErrors as e}from"react-hook-form";import{safeParseAsync as t,getDotPath as o}from"valibot";function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},n.apply(this,arguments)}function a(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,o=new Array(e);t<e;t++)o[t]=r[t];return o}var i=function(i,s,u){return void 0===u&&(u={}),function(l,c,f){try{var m=!f.shouldUseNativeValidation&&"all"===f.criteriaMode;return Promise.resolve(t(i,l,n({},s,{abortPipeEarly:!m}))).then(function(t){if(t.issues){for(var n,i={},s=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return a(r,e);var t=Object.prototype.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)?a(r,e):void 0}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t.issues);!(n=s()).done;){var c=n.value,p=o(c);if(p&&(i[p]||(i[p]={message:c.message,type:c.type}),m)){var v=i[p].types,y=v&&v[c.type];i[p]=e(p,m,i,c.type,y?[].concat(y,c.message):c.message)}}return{values:{},errors:r(i,f)}}return{values:u.raw?l:t.output,errors:{}}})}catch(r){return Promise.reject(r)}}};export{i as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as
|
|
1
|
+
import{toNestErrors as r}from"@hookform/resolvers";import{appendErrors as t}from"react-hook-form";import{safeParseAsync as e,getDotPath as o}from"valibot";function s(){return s=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=e[o])}return r},s.apply(this,arguments)}const a=(a,n,i={})=>async(c,p,f)=>{const l=!f.shouldUseNativeValidation&&"all"===f.criteriaMode,u=await e(a,c,s({},n,{abortPipeEarly:!l}));if(u.issues){const e={};for(const r of u.issues){const s=o(r);if(s&&(e[s]||(e[s]={message:r.message,type:r.type}),l)){const o=e[s].types,a=o&&o[r.type];e[s]=t(s,l,e,r.type,a?[].concat(a,r.message):r.message)}}return{values:{},errors:r(e,f)}}return{values:i.raw?c:u.output,errors:{}}};export{a as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport
|
|
1
|
+
{"version":3,"file":"valibot.modern.mjs","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, appendErrors, FieldValues } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, 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(schema, values, {\n ...schemaOptions,\n abortPipeEarly: !validateAllFieldCriteria,\n });\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (const issue of result.issues) {\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\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 ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["valibotResolver","schema","schemaOptions","resolverOptions","async","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","result","safeParseAsync","_extends","abortPipeEarly","issues","errors","issue","path","getDotPath","message","type","types","messages","appendErrors","concat","toNestErrors","raw","output"],"mappings":"+XAKa,MAAAA,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAE,IAC5CC,MAAOC,EAAQC,EAAGC,KAEhB,MAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAG1CC,QAAeC,EAAeX,EAAQI,EAAMQ,EAAA,GAC7CX,EAAa,CAChBY,gBAAiBN,KAInB,GAAIG,EAAOI,OAAQ,CAEjB,MAAMC,EAAqC,CAAA,EAG3C,IAAK,MAAMC,KAASN,EAAOI,OAAQ,CAEjC,MAAMG,EAAOC,EAAWF,GAExB,GAAIC,IAEGF,EAAOE,KACVF,EAAOE,GAAQ,CAAEE,QAASH,EAAMG,QAASC,KAAMJ,EAAMI,OAInDb,GAA0B,CAC5B,MAAMc,EAAQN,EAAOE,GAAMI,MACrBC,EAAWD,GAASA,EAAML,EAAMI,MACtCL,EAAOE,GAAQM,EACbN,EACAV,EACAQ,EACAC,EAAMI,KACNE,EACK,GAAgBE,OACfF,EACAN,EAAMG,SAERH,EAAMG,QAEb,CAEJ,CAGD,MAAO,CACLf,OAAQ,CAAA,EACRW,OAAQU,EAAaV,EAAQT,GAEhC,CAGD,MAAO,CACLF,OAAQF,EAAgBwB,IAAMtB,EAAUM,EAAOiB,OAC/CZ,OAAQ,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toNestErrors as r}from"@hookform/resolvers";import{
|
|
1
|
+
import{toNestErrors as r}from"@hookform/resolvers";import{appendErrors as e}from"react-hook-form";import{safeParseAsync as t,getDotPath as o}from"valibot";function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o])}return r},n.apply(this,arguments)}function a(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,o=new Array(e);t<e;t++)o[t]=r[t];return o}var i=function(i,s,u){return void 0===u&&(u={}),function(l,c,f){try{var m=!f.shouldUseNativeValidation&&"all"===f.criteriaMode;return Promise.resolve(t(i,l,n({},s,{abortPipeEarly:!m}))).then(function(t){if(t.issues){for(var n,i={},s=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return a(r,e);var t=Object.prototype.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)?a(r,e):void 0}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t.issues);!(n=s()).done;){var c=n.value,p=o(c);if(p&&(i[p]||(i[p]={message:c.message,type:c.type}),m)){var v=i[p].types,y=v&&v[c.type];i[p]=e(p,m,i,c.type,y?[].concat(y,c.message):c.message)}}return{values:{},errors:r(i,f)}}return{values:u.raw?l:t.output,errors:{}}})}catch(r){return Promise.reject(r)}}};export{i as valibotResolver};
|
|
2
2
|
//# sourceMappingURL=valibot.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.module.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport
|
|
1
|
+
{"version":3,"file":"valibot.module.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, appendErrors, FieldValues } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, 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(schema, values, {\n ...schemaOptions,\n abortPipeEarly: !validateAllFieldCriteria,\n });\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (const issue of result.issues) {\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\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 ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["valibotResolver","schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","_extends","abortPipeEarly","then","result","issues","_step","errors","_iterator","_createForOfIteratorHelperLoose","done","issue","value","path","getDotPath","message","type","types","messages","appendErrors","concat","toNestErrors","raw","output","e","reject"],"mappings":"yeAKa,IAAAA,EACX,SAACC,EAAQC,EAAeC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAeX,EAAQG,EAAMS,EAAA,CAAA,EAC7CX,EAAa,CAChBY,gBAAiBP,MACjBQ,KAAA,SAHIC,GAMN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAGiCC,EAH3BC,EAAqC,CAAE,EAG7CC,2qBAAAC,CAAoBL,EAAOC,UAAMC,EAAAE,KAAAE,MAAE,KAAxBC,EAAKL,EAAAM,MAERC,EAAOC,EAAWH,GAExB,GAAIE,IAEGN,EAAOM,KACVN,EAAOM,GAAQ,CAAEE,QAASJ,EAAMI,QAASC,KAAML,EAAMK,OAInDrB,GAA0B,CAC5B,IAAMsB,EAAQV,EAAOM,GAAMI,MACrBC,EAAWD,GAASA,EAAMN,EAAMK,MACtCT,EAAOM,GAAQM,EACbN,EACAlB,EACAY,EACAI,EAAMK,KACNE,EACK,GAAgBE,OACfF,EACAP,EAAMI,SAERJ,EAAMI,QAEb,CAEJ,CAGD,MAAO,CACLvB,OAAQ,GACRe,OAAQc,EAAad,EAAQb,GAEhC,CAGD,MAAO,CACLF,OAAQD,EAAgB+B,IAAM9B,EAAUY,EAAOmB,OAC/ChB,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAiB,GAAA1B,OAAAA,QAAA2B,OAAAD,EAAA,CAAA,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(r
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("react-hook-form"),require("valibot")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","react-hook-form","valibot"],r):r((e||self).hookformResolversValibot={},e.hookformResolvers,e.ReactHookForm,e.valibot)}(this,function(e,r,t,o){function n(){return n=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},n.apply(this,arguments)}function a(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}e.valibotResolver=function(e,i,s){return void 0===s&&(s={}),function(l,u,f){try{var c=!f.shouldUseNativeValidation&&"all"===f.criteriaMode;return Promise.resolve(o.safeParseAsync(e,l,n({},i,{abortPipeEarly:!c}))).then(function(e){if(e.issues){for(var n,i={},u=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return a(e,r);var t=Object.prototype.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)?a(e,r):void 0}}(e))){t&&(e=t);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.issues);!(n=u()).done;){var v=n.value,p=o.getDotPath(v);if(p&&(i[p]||(i[p]={message:v.message,type:v.type}),c)){var y=i[p].types,d=y&&y[v.type];i[p]=t.appendErrors(p,c,i,v.type,d?[].concat(d,v.message):v.message)}}return{values:{},errors:r.toNestErrors(i,f)}}return{values:s.raw?l:e.output,errors:{}}})}catch(e){return Promise.reject(e)}}}});
|
|
2
2
|
//# sourceMappingURL=valibot.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valibot.umd.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport
|
|
1
|
+
{"version":3,"file":"valibot.umd.js","sources":["../src/valibot.ts"],"sourcesContent":["import { toNestErrors } from '@hookform/resolvers';\nimport { FieldError, appendErrors, FieldValues } from 'react-hook-form';\nimport { getDotPath, safeParseAsync } from 'valibot';\nimport type { Resolver } from './types';\n\nexport const valibotResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, 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(schema, values, {\n ...schemaOptions,\n abortPipeEarly: !validateAllFieldCriteria,\n });\n\n // If there are issues, return them as errors\n if (result.issues) {\n // Create errors object\n const errors: Record<string, FieldError> = {};\n\n // Iterate over issues to add them to errors object\n for (const issue of result.issues) {\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\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 ? values : (result.output as FieldValues),\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","validateAllFieldCriteria","shouldUseNativeValidation","criteriaMode","Promise","resolve","safeParseAsync","_extends","abortPipeEarly","then","result","issues","_step","errors","_iterator","_createForOfIteratorHelperLoose","done","issue","value","path","getDotPath","message","type","types","messages","appendErrors","concat","toNestErrors","raw","output","e","reject"],"mappings":"qwBAME,SAACA,EAAQC,EAAeC,GAAoB,YAApBA,IAAAA,IAAAA,EAAkB,CAAE,GAAA,SACrCC,EAAQC,EAAGC,GAAO,IAEvB,IAAMC,GACHD,EAAQE,2BAAsD,QAAzBF,EAAQG,aAAuB,OAAAC,QAAAC,QAGlDC,EAAcA,eAACX,EAAQG,EAAMS,EAAA,CAAA,EAC7CX,EAAa,CAChBY,gBAAiBP,MACjBQ,KAAA,SAHIC,GAMN,GAAIA,EAAOC,OAAQ,CAKjB,IAHA,IAGiCC,EAH3BC,EAAqC,CAAE,EAG7CC,2qBAAAC,CAAoBL,EAAOC,UAAMC,EAAAE,KAAAE,MAAE,KAAxBC,EAAKL,EAAAM,MAERC,EAAOC,EAAUA,WAACH,GAExB,GAAIE,IAEGN,EAAOM,KACVN,EAAOM,GAAQ,CAAEE,QAASJ,EAAMI,QAASC,KAAML,EAAMK,OAInDrB,GAA0B,CAC5B,IAAMsB,EAAQV,EAAOM,GAAMI,MACrBC,EAAWD,GAASA,EAAMN,EAAMK,MACtCT,EAAOM,GAAQM,EAAAA,aACbN,EACAlB,EACAY,EACAI,EAAMK,KACNE,EACK,GAAgBE,OACfF,EACAP,EAAMI,SAERJ,EAAMI,QAEb,CAEJ,CAGD,MAAO,CACLvB,OAAQ,GACRe,OAAQc,EAAAA,aAAad,EAAQb,GAEhC,CAGD,MAAO,CACLF,OAAQD,EAAgB+B,IAAM9B,EAAUY,EAAOmB,OAC/ChB,OAAQ,CAAA,EACR,EACJ,CAAC,MAAAiB,GAAA1B,OAAAA,QAAA2B,OAAAD,EAAA,CAAA,CAAA"}
|
package/valibot/package.json
CHANGED
|
@@ -2,22 +2,22 @@ import React from 'react';
|
|
|
2
2
|
import { useForm } from 'react-hook-form';
|
|
3
3
|
import { render, screen } from '@testing-library/react';
|
|
4
4
|
import user from '@testing-library/user-event';
|
|
5
|
-
import
|
|
5
|
+
import * as v from 'valibot';
|
|
6
6
|
import { valibotResolver } from '..';
|
|
7
7
|
|
|
8
|
-
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
|
9
|
-
const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
|
|
10
|
-
|
|
11
|
-
const schema =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
8
|
+
const USERNAME_REQUIRED_MESSAGE = 'username field is v.required';
|
|
9
|
+
const PASSWORD_REQUIRED_MESSAGE = 'password field is v.required';
|
|
10
|
+
|
|
11
|
+
const schema = v.object({
|
|
12
|
+
username: v.pipe(
|
|
13
|
+
v.string(USERNAME_REQUIRED_MESSAGE),
|
|
14
|
+
v.minLength(2, USERNAME_REQUIRED_MESSAGE),
|
|
15
|
+
),
|
|
16
|
+
password: v.pipe(
|
|
17
|
+
v.string(PASSWORD_REQUIRED_MESSAGE),
|
|
18
|
+
v.minLength(2, PASSWORD_REQUIRED_MESSAGE),
|
|
19
|
+
),
|
|
20
|
+
});
|
|
21
21
|
|
|
22
22
|
type FormData = { username: string; password: string };
|
|
23
23
|
|
|
@@ -2,22 +2,22 @@ import React from 'react';
|
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import user from '@testing-library/user-event';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
|
-
import
|
|
5
|
+
import * as v from 'valibot';
|
|
6
6
|
import { valibotResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
|
9
9
|
const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
|
|
10
10
|
|
|
11
|
-
const schema =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
11
|
+
const schema = v.object({
|
|
12
|
+
username: v.pipe(
|
|
13
|
+
v.string(USERNAME_REQUIRED_MESSAGE),
|
|
14
|
+
v.minLength(2, USERNAME_REQUIRED_MESSAGE),
|
|
15
|
+
),
|
|
16
|
+
password: v.pipe(
|
|
17
|
+
v.string(PASSWORD_REQUIRED_MESSAGE),
|
|
18
|
+
v.minLength(2, PASSWORD_REQUIRED_MESSAGE),
|
|
19
|
+
),
|
|
20
|
+
});
|
|
21
21
|
|
|
22
22
|
type FormData = { username: string; password: string };
|
|
23
23
|
|
|
@@ -1,62 +1,52 @@
|
|
|
1
1
|
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
|
-
import
|
|
3
|
-
object,
|
|
4
|
-
string,
|
|
5
|
-
minLength,
|
|
6
|
-
maxLength,
|
|
7
|
-
regex,
|
|
8
|
-
number,
|
|
9
|
-
minValue,
|
|
10
|
-
maxValue,
|
|
11
|
-
email,
|
|
12
|
-
array,
|
|
13
|
-
boolean,
|
|
14
|
-
required,
|
|
15
|
-
union,
|
|
16
|
-
variant,
|
|
17
|
-
literal,
|
|
18
|
-
} from 'valibot';
|
|
2
|
+
import * as v from 'valibot';
|
|
19
3
|
|
|
20
|
-
export const schema =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
[
|
|
36
|
-
string('Access token should be a string'),
|
|
37
|
-
number('Access token should be a number'),
|
|
38
|
-
],
|
|
39
|
-
'access token is required',
|
|
4
|
+
export const schema = v.object({
|
|
5
|
+
username: v.pipe(
|
|
6
|
+
v.string(),
|
|
7
|
+
v.minLength(2),
|
|
8
|
+
v.maxLength(30),
|
|
9
|
+
v.regex(/^\w+$/),
|
|
10
|
+
),
|
|
11
|
+
password: v.pipe(
|
|
12
|
+
v.string('New Password is required'),
|
|
13
|
+
v.regex(new RegExp('.*[A-Z].*'), 'One uppercase character'),
|
|
14
|
+
v.regex(new RegExp('.*[a-z].*'), 'One lowercase character'),
|
|
15
|
+
v.regex(new RegExp('.*\\d.*'), 'One number'),
|
|
16
|
+
v.regex(
|
|
17
|
+
new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
|
|
18
|
+
'One special character',
|
|
40
19
|
),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
20
|
+
v.minLength(8, 'Must be at least 8 characters in length'),
|
|
21
|
+
),
|
|
22
|
+
repeatPassword: v.string('Repeat Password is required'),
|
|
23
|
+
accessToken: v.union(
|
|
24
|
+
[
|
|
25
|
+
v.string('Access token should be a string'),
|
|
26
|
+
v.number('Access token should be a number'),
|
|
27
|
+
],
|
|
28
|
+
'access token is required',
|
|
29
|
+
),
|
|
30
|
+
birthYear: v.pipe(
|
|
31
|
+
v.number('Please enter your birth year'),
|
|
32
|
+
v.minValue(1900),
|
|
33
|
+
v.maxValue(2013),
|
|
34
|
+
),
|
|
35
|
+
email: v.pipe(v.string(), v.email('Invalid email address')),
|
|
36
|
+
tags: v.array(v.string('Tags should be strings')),
|
|
37
|
+
enabled: v.boolean(),
|
|
38
|
+
like: v.object({
|
|
39
|
+
id: v.number('Like id is required'),
|
|
40
|
+
name: v.pipe(
|
|
41
|
+
v.string('Like name is required'),
|
|
42
|
+
v.minLength(4, 'Too short'),
|
|
53
43
|
),
|
|
54
44
|
}),
|
|
55
|
-
);
|
|
45
|
+
});
|
|
56
46
|
|
|
57
|
-
export const schemaError = variant('type', [
|
|
58
|
-
object({ type: literal('a') }),
|
|
59
|
-
object({ type: literal('b') }),
|
|
47
|
+
export const schemaError = v.variant('type', [
|
|
48
|
+
v.object({ type: v.literal('a') }),
|
|
49
|
+
v.object({ type: v.literal('b') }),
|
|
60
50
|
]);
|
|
61
51
|
|
|
62
52
|
export const validSchemaErrorData = { type: 'a' };
|