v1.0 with SW PWA enabled
This commit is contained in:
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,
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user