v1.0 with SW PWA enabled
This commit is contained in:
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.d.ts
generated
vendored
Normal file
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import type { Resolver } from './types';
|
||||
export declare const effectTsResolver: Resolver;
|
||||
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.js
generated
vendored
Normal file
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
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)}};
|
||||
//# sourceMappingURL=effect-ts.js.map
|
||||
1
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.js.map
generated
vendored
Normal file
1
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.js.map
generated
vendored
Normal file
@ -0,0 +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"}
|
||||
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.mjs
generated
vendored
Normal file
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.mjs
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
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};
|
||||
//# sourceMappingURL=effect-ts.module.js.map
|
||||
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.modern.mjs
generated
vendored
Normal file
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.modern.mjs
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
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};
|
||||
//# sourceMappingURL=effect-ts.modern.mjs.map
|
||||
1
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.modern.mjs.map
generated
vendored
Normal file
1
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.modern.mjs.map
generated
vendored
Normal file
@ -0,0 +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"}
|
||||
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.module.js
generated
vendored
Normal file
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.module.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
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};
|
||||
//# sourceMappingURL=effect-ts.module.js.map
|
||||
1
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.module.js.map
generated
vendored
Normal file
1
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.module.js.map
generated
vendored
Normal file
@ -0,0 +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"}
|
||||
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.umd.js
generated
vendored
Normal file
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.umd.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
!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)}}});
|
||||
//# sourceMappingURL=effect-ts.umd.js.map
|
||||
1
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.umd.js.map
generated
vendored
Normal file
1
frontend/node_modules/@hookform/resolvers/effect-ts/dist/effect-ts.umd.js.map
generated
vendored
Normal file
@ -0,0 +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"}
|
||||
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/index.d.ts
generated
vendored
Normal file
2
frontend/node_modules/@hookform/resolvers/effect-ts/dist/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './effect-ts';
|
||||
export * from './types';
|
||||
4
frontend/node_modules/@hookform/resolvers/effect-ts/dist/types.d.ts
generated
vendored
Normal file
4
frontend/node_modules/@hookform/resolvers/effect-ts/dist/types.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import { Schema } from 'effect';
|
||||
import { ParseOptions } from 'effect/SchemaAST';
|
||||
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
||||
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>>;
|
||||
18
frontend/node_modules/@hookform/resolvers/effect-ts/package.json
generated
vendored
Normal file
18
frontend/node_modules/@hookform/resolvers/effect-ts/package.json
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@hookform/resolvers/effect-ts",
|
||||
"amdName": "hookformResolversEffectTs",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "React Hook Form validation resolver: effect-ts",
|
||||
"main": "dist/effect-ts.js",
|
||||
"module": "dist/effect-ts.module.js",
|
||||
"umd:main": "dist/effect-ts.umd.js",
|
||||
"source": "src/index.ts",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@hookform/resolvers": "^2.0.0",
|
||||
"effect": "^3.10.3",
|
||||
"react-hook-form": "^7.0.0"
|
||||
}
|
||||
}
|
||||
88
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/Form-native-validation.tsx
generated
vendored
Normal file
88
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/Form-native-validation.tsx
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import user from '@testing-library/user-event';
|
||||
import { Schema } from 'effect';
|
||||
import React from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { effectTsResolver } from '..';
|
||||
|
||||
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
||||
const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
|
||||
|
||||
const schema = Schema.Struct({
|
||||
username: Schema.String.pipe(
|
||||
Schema.nonEmptyString({ message: () => USERNAME_REQUIRED_MESSAGE }),
|
||||
),
|
||||
password: Schema.String.pipe(
|
||||
Schema.nonEmptyString({ message: () => PASSWORD_REQUIRED_MESSAGE }),
|
||||
),
|
||||
});
|
||||
|
||||
interface FormData {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
onSubmit: (data: FormData) => void;
|
||||
}
|
||||
|
||||
function TestComponent({ onSubmit }: Props) {
|
||||
const { register, handleSubmit } = useForm<FormData>({
|
||||
resolver: effectTsResolver(schema),
|
||||
shouldUseNativeValidation: true,
|
||||
});
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<input {...register('username')} placeholder="username" />
|
||||
|
||||
<input {...register('password')} placeholder="password" />
|
||||
|
||||
<button type="submit">submit</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
test("form's native validation with effect-ts", async () => {
|
||||
const handleSubmit = vi.fn();
|
||||
render(<TestComponent onSubmit={handleSubmit} />);
|
||||
|
||||
// username
|
||||
let usernameField = screen.getByPlaceholderText(
|
||||
/username/i,
|
||||
) as HTMLInputElement;
|
||||
expect(usernameField.validity.valid).toBe(true);
|
||||
expect(usernameField.validationMessage).toBe('');
|
||||
|
||||
// password
|
||||
let passwordField = screen.getByPlaceholderText(
|
||||
/password/i,
|
||||
) as HTMLInputElement;
|
||||
expect(passwordField.validity.valid).toBe(true);
|
||||
expect(passwordField.validationMessage).toBe('');
|
||||
|
||||
await user.click(screen.getByText(/submit/i));
|
||||
|
||||
// username
|
||||
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
||||
expect(usernameField.validity.valid).toBe(false);
|
||||
expect(usernameField.validationMessage).toBe(USERNAME_REQUIRED_MESSAGE);
|
||||
|
||||
// password
|
||||
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
|
||||
expect(passwordField.validity.valid).toBe(false);
|
||||
expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
|
||||
|
||||
await user.type(screen.getByPlaceholderText(/username/i), 'joe');
|
||||
await user.type(screen.getByPlaceholderText(/password/i), 'password');
|
||||
|
||||
// username
|
||||
usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
|
||||
expect(usernameField.validity.valid).toBe(true);
|
||||
expect(usernameField.validationMessage).toBe('');
|
||||
|
||||
// password
|
||||
passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
|
||||
expect(passwordField.validity.valid).toBe(true);
|
||||
expect(passwordField.validationMessage).toBe('');
|
||||
});
|
||||
59
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/Form.tsx
generated
vendored
Normal file
59
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/Form.tsx
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import user from '@testing-library/user-event';
|
||||
import { Schema } from 'effect';
|
||||
import React from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { effectTsResolver } from '..';
|
||||
|
||||
const USERNAME_REQUIRED_MESSAGE = 'username field is required';
|
||||
const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
|
||||
|
||||
const schema = Schema.Struct({
|
||||
username: Schema.String.pipe(
|
||||
Schema.nonEmptyString({ message: () => USERNAME_REQUIRED_MESSAGE }),
|
||||
),
|
||||
password: Schema.String.pipe(
|
||||
Schema.nonEmptyString({ message: () => PASSWORD_REQUIRED_MESSAGE }),
|
||||
),
|
||||
});
|
||||
|
||||
type FormData = Schema.Schema.Type<typeof schema>;
|
||||
|
||||
interface Props {
|
||||
onSubmit: (data: FormData) => void;
|
||||
}
|
||||
|
||||
function TestComponent({ onSubmit }: Props) {
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: effectTsResolver(schema),
|
||||
});
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<input {...register('username')} />
|
||||
{errors.username && <span role="alert">{errors.username.message}</span>}
|
||||
|
||||
<input {...register('password')} />
|
||||
{errors.password && <span role="alert">{errors.password.message}</span>}
|
||||
|
||||
<button type="submit">submit</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
test("form's validation with Zod and TypeScript's integration", async () => {
|
||||
const handleSubmit = vi.fn();
|
||||
render(<TestComponent onSubmit={handleSubmit} />);
|
||||
|
||||
expect(screen.queryAllByRole('alert')).toHaveLength(0);
|
||||
|
||||
await user.click(screen.getByText(/submit/i));
|
||||
|
||||
expect(screen.getByText(/username field is required/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
|
||||
expect(handleSubmit).not.toHaveBeenCalled();
|
||||
});
|
||||
124
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/__fixtures__/data.ts
generated
vendored
Normal file
124
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/__fixtures__/data.ts
generated
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
import { Schema } from 'effect';
|
||||
import { Field, InternalFieldName } from 'react-hook-form';
|
||||
|
||||
export const schema = Schema.Struct({
|
||||
username: Schema.String.pipe(
|
||||
Schema.nonEmptyString({ message: () => 'A username is required' }),
|
||||
),
|
||||
password: Schema.String.pipe(
|
||||
Schema.pattern(new RegExp('.*[A-Z].*'), {
|
||||
message: () => 'At least 1 uppercase letter.',
|
||||
}),
|
||||
Schema.pattern(new RegExp('.*[a-z].*'), {
|
||||
message: () => 'At least 1 lowercase letter.',
|
||||
}),
|
||||
Schema.pattern(new RegExp('.*\\d.*'), {
|
||||
message: () => 'At least 1 number.',
|
||||
}),
|
||||
Schema.pattern(
|
||||
new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
|
||||
{
|
||||
message: () => 'At least 1 special character.',
|
||||
},
|
||||
),
|
||||
Schema.minLength(8, { message: () => 'Must be at least 8 characters.' }),
|
||||
),
|
||||
accessToken: Schema.Union(Schema.String, Schema.Number),
|
||||
birthYear: Schema.Number.pipe(
|
||||
Schema.greaterThan(1900, {
|
||||
message: () => 'Must be greater than the year 1900',
|
||||
}),
|
||||
Schema.filter((value) => value < new Date().getFullYear(), {
|
||||
message: () => 'Must be before the current year.',
|
||||
}),
|
||||
),
|
||||
email: Schema.String.pipe(
|
||||
Schema.pattern(
|
||||
new RegExp(
|
||||
/^(?!\.)(?!.*\.\.)([A-Z0-9_+-.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i,
|
||||
),
|
||||
{
|
||||
message: () => 'A valid email address is required.',
|
||||
},
|
||||
),
|
||||
),
|
||||
tags: Schema.Array(
|
||||
Schema.Struct({
|
||||
name: Schema.String,
|
||||
}),
|
||||
),
|
||||
luckyNumbers: Schema.Array(Schema.Number),
|
||||
enabled: Schema.Boolean,
|
||||
animal: Schema.Union(Schema.String, Schema.Literal('bird', 'snake')),
|
||||
vehicles: Schema.Array(
|
||||
Schema.Union(
|
||||
Schema.Struct({
|
||||
type: Schema.Literal('car'),
|
||||
brand: Schema.String,
|
||||
horsepower: Schema.Number,
|
||||
}),
|
||||
Schema.Struct({
|
||||
type: Schema.Literal('bike'),
|
||||
speed: Schema.Number,
|
||||
}),
|
||||
),
|
||||
),
|
||||
});
|
||||
|
||||
export const validData: Schema.Schema.Type<typeof schema> = {
|
||||
accessToken: 'abcd1234',
|
||||
animal: 'dog',
|
||||
birthYear: 2000,
|
||||
email: 'johnDoe@here.there',
|
||||
enabled: true,
|
||||
luckyNumbers: [1, 2, 3, 4, 5],
|
||||
password: 'Super#Secret123',
|
||||
tags: [{ name: 'move' }, { name: 'over' }, { name: 'zod' }, { name: ';)' }],
|
||||
username: 'johnDoe',
|
||||
vehicles: [
|
||||
{ type: 'bike', speed: 5 },
|
||||
{ type: 'car', brand: 'BMW', horsepower: 150 },
|
||||
],
|
||||
};
|
||||
|
||||
export const invalidData = {
|
||||
username: 'test',
|
||||
password: 'Password123',
|
||||
repeatPassword: 'Password123',
|
||||
birthYear: 2000,
|
||||
accessToken: '1015d809-e99d-41ec-b161-981a3c243df8',
|
||||
email: 'john@doe.com',
|
||||
tags: [{ name: 'test' }],
|
||||
enabled: true,
|
||||
animal: ['dog'],
|
||||
luckyNumbers: [1, 2, '3'],
|
||||
like: [
|
||||
{
|
||||
id: '1',
|
||||
name: 'name',
|
||||
},
|
||||
],
|
||||
vehicles: [
|
||||
{ type: 'car', brand: 'BMW', horsepower: 150 },
|
||||
{ type: 'car', brand: 'Mercedes' },
|
||||
],
|
||||
};
|
||||
|
||||
export const fields: Record<InternalFieldName, Field['_f']> = {
|
||||
username: {
|
||||
ref: { name: 'username' },
|
||||
name: 'username',
|
||||
},
|
||||
password: {
|
||||
ref: { name: 'password' },
|
||||
name: 'password',
|
||||
},
|
||||
email: {
|
||||
ref: { name: 'email' },
|
||||
name: 'email',
|
||||
},
|
||||
birthday: {
|
||||
ref: { name: 'birthday' },
|
||||
name: 'birthday',
|
||||
},
|
||||
};
|
||||
40
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap
generated
vendored
Normal file
40
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`effectTsResolver > should return a single error from effectTsResolver when validation fails 1`] = `
|
||||
{
|
||||
"errors": {
|
||||
"animal": {
|
||||
"message": "Expected "snake", actual ["dog"]",
|
||||
"ref": undefined,
|
||||
"type": "Type",
|
||||
},
|
||||
"luckyNumbers": [
|
||||
,
|
||||
,
|
||||
{
|
||||
"message": "Expected number, actual "3"",
|
||||
"ref": undefined,
|
||||
"type": "Type",
|
||||
},
|
||||
],
|
||||
"password": {
|
||||
"message": "At least 1 special character.",
|
||||
"ref": {
|
||||
"name": "password",
|
||||
},
|
||||
"type": "Refinement",
|
||||
},
|
||||
"vehicles": [
|
||||
,
|
||||
{
|
||||
"horsepower": {
|
||||
"message": "is missing",
|
||||
"ref": undefined,
|
||||
"type": "Missing",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
"values": {},
|
||||
}
|
||||
`;
|
||||
24
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/effect-ts.ts
generated
vendored
Normal file
24
frontend/node_modules/@hookform/resolvers/effect-ts/src/__tests__/effect-ts.ts
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
import { effectTsResolver } from '..';
|
||||
import { fields, invalidData, schema, validData } from './__fixtures__/data';
|
||||
|
||||
const shouldUseNativeValidation = false;
|
||||
|
||||
describe('effectTsResolver', () => {
|
||||
it('should return values from effectTsResolver when validation pass', async () => {
|
||||
const result = await effectTsResolver(schema)(validData, undefined, {
|
||||
fields,
|
||||
shouldUseNativeValidation,
|
||||
});
|
||||
|
||||
expect(result).toEqual({ errors: {}, values: validData });
|
||||
});
|
||||
|
||||
it('should return a single error from effectTsResolver when validation fails', async () => {
|
||||
const result = await effectTsResolver(schema)(invalidData, undefined, {
|
||||
fields,
|
||||
shouldUseNativeValidation,
|
||||
});
|
||||
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
40
frontend/node_modules/@hookform/resolvers/effect-ts/src/effect-ts.ts
generated
vendored
Normal file
40
frontend/node_modules/@hookform/resolvers/effect-ts/src/effect-ts.ts
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
||||
import { Effect } from 'effect';
|
||||
|
||||
import { ArrayFormatter, decodeUnknown } from 'effect/ParseResult';
|
||||
import type { FieldErrors } from 'react-hook-form';
|
||||
import type { Resolver } from './types';
|
||||
|
||||
export const effectTsResolver: Resolver =
|
||||
(schema, config = { errors: 'all', onExcessProperty: 'ignore' }) =>
|
||||
(values, _, options) => {
|
||||
return decodeUnknown(
|
||||
schema,
|
||||
config,
|
||||
)(values).pipe(
|
||||
Effect.catchAll((parseIssue) =>
|
||||
Effect.flip(ArrayFormatter.formatIssue(parseIssue)),
|
||||
),
|
||||
Effect.mapError((issues) => {
|
||||
const errors = issues.reduce((acc, current) => {
|
||||
const key = current.path.join('.');
|
||||
acc[key] = { message: current.message, type: current._tag };
|
||||
return acc;
|
||||
}, {} as FieldErrors);
|
||||
|
||||
return toNestErrors(errors, options);
|
||||
}),
|
||||
Effect.tap(() =>
|
||||
Effect.sync(
|
||||
() =>
|
||||
options.shouldUseNativeValidation &&
|
||||
validateFieldsNatively({}, options),
|
||||
),
|
||||
),
|
||||
Effect.match({
|
||||
onFailure: (errors) => ({ errors, values: {} }),
|
||||
onSuccess: (result) => ({ errors: {}, values: result }),
|
||||
}),
|
||||
Effect.runPromise,
|
||||
);
|
||||
};
|
||||
2
frontend/node_modules/@hookform/resolvers/effect-ts/src/index.ts
generated
vendored
Normal file
2
frontend/node_modules/@hookform/resolvers/effect-ts/src/index.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './effect-ts';
|
||||
export * from './types';
|
||||
12
frontend/node_modules/@hookform/resolvers/effect-ts/src/types.ts
generated
vendored
Normal file
12
frontend/node_modules/@hookform/resolvers/effect-ts/src/types.ts
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { Schema } from 'effect';
|
||||
import { ParseOptions } from 'effect/SchemaAST';
|
||||
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
||||
|
||||
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>>;
|
||||
Reference in New Issue
Block a user