@hookform/resolvers 3.9.0 → 3.10.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 +3 -3
- package/effect-ts/dist/effect-ts.js +1 -1
- package/effect-ts/dist/effect-ts.js.map +1 -1
- package/effect-ts/dist/effect-ts.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
- package/effect-ts/dist/effect-ts.module.js +1 -1
- package/effect-ts/dist/effect-ts.module.js.map +1 -1
- package/effect-ts/dist/effect-ts.umd.js +1 -1
- package/effect-ts/dist/effect-ts.umd.js.map +1 -1
- package/effect-ts/dist/types.d.ts +2 -2
- package/effect-ts/package.json +1 -2
- package/effect-ts/src/__tests__/Form-native-validation.tsx +3 -3
- package/effect-ts/src/__tests__/Form.tsx +3 -3
- package/effect-ts/src/__tests__/__fixtures__/data.ts +2 -2
- package/effect-ts/src/effect-ts.ts +6 -4
- package/effect-ts/src/types.ts +2 -2
- package/package.json +6 -7
- package/valibot/package.json +1 -1
package/README.md
CHANGED
|
@@ -653,13 +653,13 @@ const App = () => {
|
|
|
653
653
|
|
|
654
654
|
A powerful TypeScript framework that provides a fully-fledged functional effect system with a rich standard library.
|
|
655
655
|
|
|
656
|
-
[](https://bundlephobia.com/result?p=effect)
|
|
657
657
|
|
|
658
658
|
```typescript jsx
|
|
659
659
|
import React from 'react';
|
|
660
660
|
import { useForm } from 'react-hook-form';
|
|
661
661
|
import { effectTsResolver } from '@hookform/resolvers/effect-ts';
|
|
662
|
-
import { Schema } from '
|
|
662
|
+
import { Schema } from 'effect';
|
|
663
663
|
|
|
664
664
|
const schema = Schema.Struct({
|
|
665
665
|
username: Schema.String.pipe(
|
|
@@ -670,7 +670,7 @@ const schema = Schema.Struct({
|
|
|
670
670
|
),
|
|
671
671
|
});
|
|
672
672
|
|
|
673
|
-
type FormData =
|
|
673
|
+
type FormData = typeof schema.Type;
|
|
674
674
|
|
|
675
675
|
interface Props {
|
|
676
676
|
onSubmit: (data: FormData) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("@
|
|
1
|
+
var e=require("@hookform/resolvers"),r=require("effect"),t=require("effect/ParseResult");exports.effectTsResolver=function(n,o){return void 0===o&&(o={errors:"all",onExcessProperty:"ignore"}),function(f,u,s){return t.decodeUnknown(n,o)(f).pipe(r.Effect.catchAll(function(e){return r.Effect.flip(t.ArrayFormatter.formatIssue(e))}),r.Effect.mapError(function(r){var t=r.reduce(function(e,r){return e[r.path.join(".")]={message:r.message,type:r._tag},e},{});return e.toNestErrors(t,s)}),r.Effect.tap(function(){return r.Effect.sync(function(){return s.shouldUseNativeValidation&&e.validateFieldsNatively({},s)})}),r.Effect.match({onFailure:function(e){return{errors:e,values:{}}},onSuccess:function(e){return{errors:{},values:e}}}),r.Effect.runPromise)}};
|
|
2
2
|
//# sourceMappingURL=effect-ts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-ts.js","sources":["../src/effect-ts.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"effect-ts.js","sources":["../src/effect-ts.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Effect } from 'effect';\n\nimport { ArrayFormatter, decodeUnknown } from 'effect/ParseResult';\nimport type { FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nexport const effectTsResolver: Resolver =\n (schema, config = { errors: 'all', onExcessProperty: 'ignore' }) =>\n (values, _, options) => {\n return decodeUnknown(\n schema,\n config,\n )(values).pipe(\n Effect.catchAll((parseIssue) =>\n Effect.flip(ArrayFormatter.formatIssue(parseIssue)),\n ),\n Effect.mapError((issues) => {\n const errors = issues.reduce((acc, current) => {\n const key = current.path.join('.');\n acc[key] = { message: current.message, type: current._tag };\n return acc;\n }, {} as FieldErrors);\n\n return toNestErrors(errors, options);\n }),\n Effect.tap(() =>\n Effect.sync(\n () =>\n options.shouldUseNativeValidation &&\n validateFieldsNatively({}, options),\n ),\n ),\n Effect.match({\n onFailure: (errors) => ({ errors, values: {} }),\n onSuccess: (result) => ({ errors: {}, values: result }),\n }),\n Effect.runPromise,\n );\n };\n"],"names":["schema","config","errors","onExcessProperty","values","_","options","decodeUnknown","pipe","Effect","catchAll","parseIssue","flip","ArrayFormatter","formatIssue","mapError","issues","reduce","acc","current","path","join","message","type","_tag","toNestErrors","tap","sync","shouldUseNativeValidation","validateFieldsNatively","match","onFailure","onSuccess","result","runPromise"],"mappings":"kHAQE,SAACA,EAAQC,GAAsD,YAAtDA,IAAAA,IAAAA,EAAS,CAAEC,OAAQ,MAAOC,iBAAkB,WACpDC,SAAAA,EAAQC,EAAGC,GACV,OAAOC,EAAAA,cACLP,EACAC,EAFKM,CAGLH,GAAQI,KACRC,EAAAA,OAAOC,SAAS,SAACC,GACf,OAAAF,EAAAA,OAAOG,KAAKC,EAAcA,eAACC,YAAYH,GAAY,GAErDF,EAAAA,OAAOM,SAAS,SAACC,GACf,IAAMd,EAASc,EAAOC,OAAO,SAACC,EAAKC,GAGjC,OADAD,EADYC,EAAQC,KAAKC,KAAK,MACnB,CAAEC,QAASH,EAAQG,QAASC,KAAMJ,EAAQK,MAC9CN,CACT,EAAG,CAAiB,GAEpB,OAAOO,EAAAA,aAAavB,EAAQI,EAC9B,GACAG,EAAAA,OAAOiB,IAAI,WAAA,OACTjB,EAAAA,OAAOkB,KACL,WAAA,OACErB,EAAQsB,2BACRC,EAAAA,uBAAuB,CAAA,EAAIvB,EAAQ,EACtC,GAEHG,EAAAA,OAAOqB,MAAM,CACXC,UAAW,SAAC7B,GAAM,MAAM,CAAEA,OAAAA,EAAQE,OAAQ,CAAA,EAAI,EAC9C4B,UAAW,SAACC,GAAY,MAAA,CAAE/B,OAAQ,CAAA,EAAIE,OAAQ6B,EAAQ,IAExDxB,EAAMA,OAACyB,WAEX,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{toNestErrors as r,validateFieldsNatively as e}from"@hookform/resolvers";import{Effect as n}from"effect";import{decodeUnknown as o,ArrayFormatter as t}from"effect/ParseResult";var u=function(u,s){return void 0===s&&(s={errors:"all",onExcessProperty:"ignore"}),function(i,a,c){return o(u,s)(i).pipe(n.catchAll(function(r){return n.flip(t.formatIssue(r))}),n.mapError(function(e){var n=e.reduce(function(r,e){return r[e.path.join(".")]={message:e.message,type:e._tag},r},{});return r(n,c)}),n.tap(function(){return n.sync(function(){return c.shouldUseNativeValidation&&e({},c)})}),n.match({onFailure:function(r){return{errors:r,values:{}}},onSuccess:function(r){return{errors:{},values:r}}}),n.runPromise)}};export{u as effectTsResolver};
|
|
2
2
|
//# sourceMappingURL=effect-ts.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{toNestErrors as r,validateFieldsNatively as e}from"@hookform/resolvers";import{Effect as o}from"effect";import{decodeUnknown as s,ArrayFormatter as t}from"effect/ParseResult";const a=(a,m={errors:"all",onExcessProperty:"ignore"})=>(c,i,l)=>s(a,m)(c).pipe(o.catchAll(r=>o.flip(t.formatIssue(r))),o.mapError(e=>{const o=e.reduce((r,e)=>(r[e.path.join(".")]={message:e.message,type:e._tag},r),{});return r(o,l)}),o.tap(()=>o.sync(()=>l.shouldUseNativeValidation&&e({},l))),o.match({onFailure:r=>({errors:r,values:{}}),onSuccess:r=>({errors:{},values:r})}),o.runPromise);export{a as effectTsResolver};
|
|
2
2
|
//# sourceMappingURL=effect-ts.modern.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-ts.modern.mjs","sources":["../src/effect-ts.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"effect-ts.modern.mjs","sources":["../src/effect-ts.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Effect } from 'effect';\n\nimport { ArrayFormatter, decodeUnknown } from 'effect/ParseResult';\nimport type { FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nexport const effectTsResolver: Resolver =\n (schema, config = { errors: 'all', onExcessProperty: 'ignore' }) =>\n (values, _, options) => {\n return decodeUnknown(\n schema,\n config,\n )(values).pipe(\n Effect.catchAll((parseIssue) =>\n Effect.flip(ArrayFormatter.formatIssue(parseIssue)),\n ),\n Effect.mapError((issues) => {\n const errors = issues.reduce((acc, current) => {\n const key = current.path.join('.');\n acc[key] = { message: current.message, type: current._tag };\n return acc;\n }, {} as FieldErrors);\n\n return toNestErrors(errors, options);\n }),\n Effect.tap(() =>\n Effect.sync(\n () =>\n options.shouldUseNativeValidation &&\n validateFieldsNatively({}, options),\n ),\n ),\n Effect.match({\n onFailure: (errors) => ({ errors, values: {} }),\n onSuccess: (result) => ({ errors: {}, values: result }),\n }),\n Effect.runPromise,\n );\n };\n"],"names":["effectTsResolver","schema","config","errors","onExcessProperty","values","_","options","decodeUnknown","pipe","Effect","catchAll","parseIssue","flip","ArrayFormatter","formatIssue","mapError","issues","reduce","acc","current","path","join","message","type","_tag","toNestErrors","tap","sync","shouldUseNativeValidation","validateFieldsNatively","match","onFailure","onSuccess","result","runPromise"],"mappings":"sLAOa,MAAAA,EACXA,CAACC,EAAQC,EAAS,CAAEC,OAAQ,MAAOC,iBAAkB,YACrD,CAACC,EAAQC,EAAGC,IACHC,EACLP,EACAC,EAFKM,CAGLH,GAAQI,KACRC,EAAOC,SAAUC,GACfF,EAAOG,KAAKC,EAAeC,YAAYH,KAEzCF,EAAOM,SAAUC,IACf,MAAMd,EAASc,EAAOC,OAAO,CAACC,EAAKC,KAEjCD,EADYC,EAAQC,KAAKC,KAAK,MACnB,CAAEC,QAASH,EAAQG,QAASC,KAAMJ,EAAQK,MAC9CN,GACN,CAAA,GAEH,OAAOO,EAAavB,EAAQI,EAAO,GAErCG,EAAOiB,IAAI,IACTjB,EAAOkB,KACL,IACErB,EAAQsB,2BACRC,EAAuB,CAAE,EAAEvB,KAGjCG,EAAOqB,MAAM,CACXC,UAAY7B,IAAY,CAAEA,SAAQE,OAAQ,KAC1C4B,UAAYC,IAAM,CAAQ/B,OAAQ,GAAIE,OAAQ6B,MAEhDxB,EAAOyB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{toNestErrors as r,validateFieldsNatively as e}from"@hookform/resolvers";import{Effect as n}from"effect";import{decodeUnknown as o,ArrayFormatter as t}from"effect/ParseResult";var u=function(u,s){return void 0===s&&(s={errors:"all",onExcessProperty:"ignore"}),function(i,a,c){return o(u,s)(i).pipe(n.catchAll(function(r){return n.flip(t.formatIssue(r))}),n.mapError(function(e){var n=e.reduce(function(r,e){return r[e.path.join(".")]={message:e.message,type:e._tag},r},{});return r(n,c)}),n.tap(function(){return n.sync(function(){return c.shouldUseNativeValidation&&e({},c)})}),n.match({onFailure:function(r){return{errors:r,values:{}}},onSuccess:function(r){return{errors:{},values:r}}}),n.runPromise)}};export{u as effectTsResolver};
|
|
2
2
|
//# sourceMappingURL=effect-ts.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-ts.module.js","sources":["../src/effect-ts.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"effect-ts.module.js","sources":["../src/effect-ts.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Effect } from 'effect';\n\nimport { ArrayFormatter, decodeUnknown } from 'effect/ParseResult';\nimport type { FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nexport const effectTsResolver: Resolver =\n (schema, config = { errors: 'all', onExcessProperty: 'ignore' }) =>\n (values, _, options) => {\n return decodeUnknown(\n schema,\n config,\n )(values).pipe(\n Effect.catchAll((parseIssue) =>\n Effect.flip(ArrayFormatter.formatIssue(parseIssue)),\n ),\n Effect.mapError((issues) => {\n const errors = issues.reduce((acc, current) => {\n const key = current.path.join('.');\n acc[key] = { message: current.message, type: current._tag };\n return acc;\n }, {} as FieldErrors);\n\n return toNestErrors(errors, options);\n }),\n Effect.tap(() =>\n Effect.sync(\n () =>\n options.shouldUseNativeValidation &&\n validateFieldsNatively({}, options),\n ),\n ),\n Effect.match({\n onFailure: (errors) => ({ errors, values: {} }),\n onSuccess: (result) => ({ errors: {}, values: result }),\n }),\n Effect.runPromise,\n );\n };\n"],"names":["effectTsResolver","schema","config","errors","onExcessProperty","values","_","options","decodeUnknown","pipe","Effect","catchAll","parseIssue","flip","ArrayFormatter","formatIssue","mapError","issues","reduce","acc","current","path","join","message","type","_tag","toNestErrors","tap","sync","shouldUseNativeValidation","validateFieldsNatively","match","onFailure","onSuccess","result","runPromise"],"mappings":"sLAOa,IAAAA,EACX,SAACC,EAAQC,GAAsD,YAAtDA,IAAAA,IAAAA,EAAS,CAAEC,OAAQ,MAAOC,iBAAkB,WACpDC,SAAAA,EAAQC,EAAGC,GACV,OAAOC,EACLP,EACAC,EAFKM,CAGLH,GAAQI,KACRC,EAAOC,SAAS,SAACC,GACf,OAAAF,EAAOG,KAAKC,EAAeC,YAAYH,GAAY,GAErDF,EAAOM,SAAS,SAACC,GACf,IAAMd,EAASc,EAAOC,OAAO,SAACC,EAAKC,GAGjC,OADAD,EADYC,EAAQC,KAAKC,KAAK,MACnB,CAAEC,QAASH,EAAQG,QAASC,KAAMJ,EAAQK,MAC9CN,CACT,EAAG,CAAiB,GAEpB,OAAOO,EAAavB,EAAQI,EAC9B,GACAG,EAAOiB,IAAI,WAAA,OACTjB,EAAOkB,KACL,WAAA,OACErB,EAAQsB,2BACRC,EAAuB,CAAA,EAAIvB,EAAQ,EACtC,GAEHG,EAAOqB,MAAM,CACXC,UAAW,SAAC7B,GAAM,MAAM,CAAEA,OAAAA,EAAQE,OAAQ,CAAA,EAAI,EAC9C4B,UAAW,SAACC,GAAY,MAAA,CAAE/B,OAAQ,CAAA,EAAIE,OAAQ6B,EAAQ,IAExDxB,EAAOyB,WAEX,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("effect"),require("effect/ParseResult")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","effect","effect/ParseResult"],r):r((e||self).hookformResolversEffectTs={},e.hookformResolvers,e.Effect,e.EffectParseResult)}(this,function(e,r,t,o){e.effectTsResolver=function(e,f){return void 0===f&&(f={errors:"all",onExcessProperty:"ignore"}),function(n,s,u){return o.decodeUnknown(e,f)(n).pipe(t.Effect.catchAll(function(e){return t.Effect.flip(o.ArrayFormatter.formatIssue(e))}),t.Effect.mapError(function(e){var t=e.reduce(function(e,r){return e[r.path.join(".")]={message:r.message,type:r._tag},e},{});return r.toNestErrors(t,u)}),t.Effect.tap(function(){return t.Effect.sync(function(){return u.shouldUseNativeValidation&&r.validateFieldsNatively({},u)})}),t.Effect.match({onFailure:function(e){return{errors:e,values:{}}},onSuccess:function(e){return{errors:{},values:e}}}),t.Effect.runPromise)}}});
|
|
2
2
|
//# sourceMappingURL=effect-ts.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-ts.umd.js","sources":["../src/effect-ts.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"effect-ts.umd.js","sources":["../src/effect-ts.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { Effect } from 'effect';\n\nimport { ArrayFormatter, decodeUnknown } from 'effect/ParseResult';\nimport type { FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nexport const effectTsResolver: Resolver =\n (schema, config = { errors: 'all', onExcessProperty: 'ignore' }) =>\n (values, _, options) => {\n return decodeUnknown(\n schema,\n config,\n )(values).pipe(\n Effect.catchAll((parseIssue) =>\n Effect.flip(ArrayFormatter.formatIssue(parseIssue)),\n ),\n Effect.mapError((issues) => {\n const errors = issues.reduce((acc, current) => {\n const key = current.path.join('.');\n acc[key] = { message: current.message, type: current._tag };\n return acc;\n }, {} as FieldErrors);\n\n return toNestErrors(errors, options);\n }),\n Effect.tap(() =>\n Effect.sync(\n () =>\n options.shouldUseNativeValidation &&\n validateFieldsNatively({}, options),\n ),\n ),\n Effect.match({\n onFailure: (errors) => ({ errors, values: {} }),\n onSuccess: (result) => ({ errors: {}, values: result }),\n }),\n Effect.runPromise,\n );\n };\n"],"names":["schema","config","errors","onExcessProperty","values","_","options","decodeUnknown","pipe","Effect","catchAll","parseIssue","flip","ArrayFormatter","formatIssue","mapError","issues","reduce","acc","current","path","join","message","type","_tag","toNestErrors","tap","sync","shouldUseNativeValidation","validateFieldsNatively","match","onFailure","onSuccess","result","runPromise"],"mappings":"gcAQE,SAACA,EAAQC,GAAsD,YAAtDA,IAAAA,IAAAA,EAAS,CAAEC,OAAQ,MAAOC,iBAAkB,WACpDC,SAAAA,EAAQC,EAAGC,GACV,OAAOC,EAAAA,cACLP,EACAC,EAFKM,CAGLH,GAAQI,KACRC,EAAAA,OAAOC,SAAS,SAACC,GACf,OAAAF,EAAAA,OAAOG,KAAKC,EAAcA,eAACC,YAAYH,GAAY,GAErDF,EAAAA,OAAOM,SAAS,SAACC,GACf,IAAMd,EAASc,EAAOC,OAAO,SAACC,EAAKC,GAGjC,OADAD,EADYC,EAAQC,KAAKC,KAAK,MACnB,CAAEC,QAASH,EAAQG,QAASC,KAAMJ,EAAQK,MAC9CN,CACT,EAAG,CAAiB,GAEpB,OAAOO,EAAAA,aAAavB,EAAQI,EAC9B,GACAG,EAAAA,OAAOiB,IAAI,WAAA,OACTjB,EAAAA,OAAOkB,KACL,WAAA,OACErB,EAAQsB,2BACRC,EAAAA,uBAAuB,CAAA,EAAIvB,EAAQ,EACtC,GAEHG,EAAAA,OAAOqB,MAAM,CACXC,UAAW,SAAC7B,GAAM,MAAM,CAAEA,OAAAA,EAAQE,OAAQ,CAAA,EAAI,EAC9C4B,UAAW,SAACC,GAAY,MAAA,CAAE/B,OAAQ,CAAA,EAAIE,OAAQ6B,EAAQ,IAExDxB,EAAMA,OAACyB,WAEX,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from '
|
|
2
|
-
import { ParseOptions } from '
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { ParseOptions } from 'effect/SchemaAST';
|
|
3
3
|
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
4
4
|
export type Resolver = <A extends FieldValues, I, TContext>(schema: Schema.Schema<A, I>, config?: ParseOptions) => (values: FieldValues, _context: TContext | undefined, options: ResolverOptions<A>) => Promise<ResolverResult<A>>;
|
package/effect-ts/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Schema } from '@effect/schema';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import { Schema } from 'effect';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { effectTsResolver } from '..';
|
|
@@ -10,10 +10,10 @@ const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
|
|
|
10
10
|
|
|
11
11
|
const schema = Schema.Struct({
|
|
12
12
|
username: Schema.String.pipe(
|
|
13
|
-
Schema.
|
|
13
|
+
Schema.nonEmptyString({ message: () => USERNAME_REQUIRED_MESSAGE }),
|
|
14
14
|
),
|
|
15
15
|
password: Schema.String.pipe(
|
|
16
|
-
Schema.
|
|
16
|
+
Schema.nonEmptyString({ message: () => PASSWORD_REQUIRED_MESSAGE }),
|
|
17
17
|
),
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Schema } from '@effect/schema';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import { Schema } from 'effect';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { useForm } from 'react-hook-form';
|
|
6
6
|
import { effectTsResolver } from '..';
|
|
@@ -10,10 +10,10 @@ const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
|
|
|
10
10
|
|
|
11
11
|
const schema = Schema.Struct({
|
|
12
12
|
username: Schema.String.pipe(
|
|
13
|
-
Schema.
|
|
13
|
+
Schema.nonEmptyString({ message: () => USERNAME_REQUIRED_MESSAGE }),
|
|
14
14
|
),
|
|
15
15
|
password: Schema.String.pipe(
|
|
16
|
-
Schema.
|
|
16
|
+
Schema.nonEmptyString({ message: () => PASSWORD_REQUIRED_MESSAGE }),
|
|
17
17
|
),
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Schema } from '
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
2
|
import { Field, InternalFieldName } from 'react-hook-form';
|
|
3
3
|
|
|
4
4
|
export const schema = Schema.Struct({
|
|
5
5
|
username: Schema.String.pipe(
|
|
6
|
-
Schema.
|
|
6
|
+
Schema.nonEmptyString({ message: () => 'A username is required' }),
|
|
7
7
|
),
|
|
8
8
|
password: Schema.String.pipe(
|
|
9
9
|
Schema.pattern(new RegExp('.*[A-Z].*'), {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { formatIssue } from '@effect/schema/ArrayFormatter';
|
|
2
|
-
import { decodeUnknown } from '@effect/schema/ParseResult';
|
|
3
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
4
|
-
import
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
|
|
4
|
+
import { ArrayFormatter, decodeUnknown } from 'effect/ParseResult';
|
|
5
5
|
import type { FieldErrors } from 'react-hook-form';
|
|
6
6
|
import type { Resolver } from './types';
|
|
7
7
|
|
|
@@ -12,7 +12,9 @@ export const effectTsResolver: Resolver =
|
|
|
12
12
|
schema,
|
|
13
13
|
config,
|
|
14
14
|
)(values).pipe(
|
|
15
|
-
Effect.catchAll((parseIssue) =>
|
|
15
|
+
Effect.catchAll((parseIssue) =>
|
|
16
|
+
Effect.flip(ArrayFormatter.formatIssue(parseIssue)),
|
|
17
|
+
),
|
|
16
18
|
Effect.mapError((issues) => {
|
|
17
19
|
const errors = issues.reduce((acc, current) => {
|
|
18
20
|
const key = current.path.join('.');
|
package/effect-ts/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Schema } from '
|
|
2
|
-
import { ParseOptions } from '
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import { ParseOptions } from 'effect/SchemaAST';
|
|
3
3
|
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
4
4
|
|
|
5
5
|
export type Resolver = <A extends FieldValues, I, TContext>(
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hookform/resolvers",
|
|
3
3
|
"amdName": "hookformResolvers",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.10.0",
|
|
5
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",
|
|
@@ -208,7 +208,7 @@
|
|
|
208
208
|
"build:arktype": "microbundle --cwd arktype --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
209
209
|
"build:valibot": "microbundle --cwd valibot --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
210
210
|
"build:typeschema": "microbundle --cwd typeschema --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@typeschema/main=main",
|
|
211
|
-
"build:effect-ts": "microbundle --cwd effect-ts --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm
|
|
211
|
+
"build:effect-ts": "microbundle --cwd effect-ts --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,effect=Effect,effect/SchemaAST=EffectSchemaAST,effect/ParseResult=EffectParseResult",
|
|
212
212
|
"build:vine": "microbundle --cwd vine --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@vinejs/vine=vine",
|
|
213
213
|
"build:fluentvalidation-ts": "microbundle --cwd fluentvalidation-ts --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
214
214
|
"postbuild": "node ./config/node-13-exports.js && check-export-map",
|
|
@@ -256,7 +256,6 @@
|
|
|
256
256
|
},
|
|
257
257
|
"homepage": "https://react-hook-form.com",
|
|
258
258
|
"devDependencies": {
|
|
259
|
-
"@effect/schema": "^0.68.17",
|
|
260
259
|
"@sinclair/typebox": "^0.32.34",
|
|
261
260
|
"@testing-library/dom": "^10.3.1",
|
|
262
261
|
"@testing-library/jest-dom": "^6.4.6",
|
|
@@ -277,7 +276,8 @@
|
|
|
277
276
|
"class-validator": "^0.14.1",
|
|
278
277
|
"computed-types": "^1.11.2",
|
|
279
278
|
"cross-env": "^7.0.3",
|
|
280
|
-
"effect": "^3.
|
|
279
|
+
"effect": "^3.10.3",
|
|
280
|
+
"fluentvalidation-ts": "^3.2.0",
|
|
281
281
|
"fp-ts": "^2.16.7",
|
|
282
282
|
"io-ts": "^2.2.21",
|
|
283
283
|
"io-ts-types": "^0.5.19",
|
|
@@ -296,14 +296,13 @@
|
|
|
296
296
|
"superstruct": "^1.0.4",
|
|
297
297
|
"typanion": "^3.14.0",
|
|
298
298
|
"typescript": "^5.5.3",
|
|
299
|
-
"valibot": "0.
|
|
299
|
+
"valibot": "^1.0.0-beta.0",
|
|
300
300
|
"vest": "^5.3.0",
|
|
301
301
|
"vite": "^5.3.3",
|
|
302
302
|
"vite-tsconfig-paths": "^4.3.2",
|
|
303
303
|
"vitest": "^1.6.0",
|
|
304
304
|
"yup": "^1.4.0",
|
|
305
|
-
"zod": "^3.23.8"
|
|
306
|
-
"fluentvalidation-ts": "^3.2.0"
|
|
305
|
+
"zod": "^3.23.8"
|
|
307
306
|
},
|
|
308
307
|
"peerDependencies": {
|
|
309
308
|
"react-hook-form": "^7.0.0"
|