Skip to content

Commit

Permalink
chore: update to effet 3.10 (#720)
Browse files Browse the repository at this point in the history
* chore: update to effet 3.10

* fix: remove package-lock and regenerate bun

* fix: remove @effect/schema from the peerDependencies.

* chore(effect-ts): adjusts microbundle build

* docs: update effect README

---------

Co-authored-by: André König <[email protected]>
Co-authored-by: Louis Orleans <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2024
1 parent 3ab415e commit e523dde
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,13 @@ const App = () => {

A powerful TypeScript framework that provides a fully-fledged functional effect system with a rich standard library.

[![npm](https://img.shields.io/bundlephobia/minzip/@effect/schema?style=for-the-badge)](https://bundlephobia.com/result?p=effect)
[![npm](https://img.shields.io/bundlephobia/minzip/effect?style=for-the-badge)](https://bundlephobia.com/result?p=effect)

```typescript jsx
import React from 'react';
import { useForm } from 'react-hook-form';
import { effectTsResolver } from '@hookform/resolvers/effect-ts';
import { Schema } from '@effect/schema';
import { Schema } from 'effect';

const schema = Schema.Struct({
username: Schema.String.pipe(
Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions effect-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"license": "MIT",
"peerDependencies": {
"@hookform/resolvers": "^2.0.0",
"@effect/schema": "^0.66.14",
"effect": "^3.1.2",
"effect": "^3.10.3",
"react-hook-form": "^7.0.0"
}
}
6 changes: 3 additions & 3 deletions effect-ts/src/__tests__/Form-native-validation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema } from '@effect/schema';
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 '..';
Expand All @@ -10,10 +10,10 @@ const PASSWORD_REQUIRED_MESSAGE = 'password field is required';

const schema = Schema.Struct({
username: Schema.String.pipe(
Schema.nonEmpty({ message: () => USERNAME_REQUIRED_MESSAGE }),
Schema.nonEmptyString({ message: () => USERNAME_REQUIRED_MESSAGE }),
),
password: Schema.String.pipe(
Schema.nonEmpty({ message: () => PASSWORD_REQUIRED_MESSAGE }),
Schema.nonEmptyString({ message: () => PASSWORD_REQUIRED_MESSAGE }),
),
});

Expand Down
6 changes: 3 additions & 3 deletions effect-ts/src/__tests__/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema } from '@effect/schema';
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 '..';
Expand All @@ -10,10 +10,10 @@ const PASSWORD_REQUIRED_MESSAGE = 'password field is required';

const schema = Schema.Struct({
username: Schema.String.pipe(
Schema.nonEmpty({ message: () => USERNAME_REQUIRED_MESSAGE }),
Schema.nonEmptyString({ message: () => USERNAME_REQUIRED_MESSAGE }),
),
password: Schema.String.pipe(
Schema.nonEmpty({ message: () => PASSWORD_REQUIRED_MESSAGE }),
Schema.nonEmptyString({ message: () => PASSWORD_REQUIRED_MESSAGE }),
),
});

Expand Down
4 changes: 2 additions & 2 deletions effect-ts/src/__tests__/__fixtures__/data.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Schema } from '@effect/schema';
import { Schema } from 'effect';
import { Field, InternalFieldName } from 'react-hook-form';

export const schema = Schema.Struct({
username: Schema.String.pipe(
Schema.nonEmpty({ message: () => 'A username is required' }),
Schema.nonEmptyString({ message: () => 'A username is required' }),
),
password: Schema.String.pipe(
Schema.pattern(new RegExp('.*[A-Z].*'), {
Expand Down
10 changes: 6 additions & 4 deletions effect-ts/src/effect-ts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { formatIssue } from '@effect/schema/ArrayFormatter';
import { decodeUnknown } from '@effect/schema/ParseResult';
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import * as Effect from 'effect/Effect';
import { Effect } from 'effect';

import { ArrayFormatter, decodeUnknown } from 'effect/ParseResult';
import type { FieldErrors } from 'react-hook-form';
import type { Resolver } from './types';

Expand All @@ -12,7 +12,9 @@ export const effectTsResolver: Resolver =
schema,
config,
)(values).pipe(
Effect.catchAll((parseIssue) => Effect.flip(formatIssue(parseIssue))),
Effect.catchAll((parseIssue) =>
Effect.flip(ArrayFormatter.formatIssue(parseIssue)),
),
Effect.mapError((issues) => {
const errors = issues.reduce((acc, current) => {
const key = current.path.join('.');
Expand Down
4 changes: 2 additions & 2 deletions effect-ts/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Schema } from '@effect/schema';
import { ParseOptions } from '@effect/schema/AST';
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>(
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
"build:arktype": "microbundle --cwd arktype --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
"build:valibot": "microbundle --cwd valibot --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
"build:typeschema": "microbundle --cwd typeschema --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@typeschema/main=main",
"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,@effect/schema/ParseResult=EffectSchemaArrayFormatter,effect/Effect=Effect",
"build:effect-ts": "microbundle --cwd effect-ts --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,effect=Effect,effect/SchemaAST=EffectSchemaAST,effect/ParseResult=EffectParseResult",
"build:vine": "microbundle --cwd vine --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@vinejs/vine=vine",
"build:fluentvalidation-ts": "microbundle --cwd fluentvalidation-ts --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
"postbuild": "node ./config/node-13-exports.js && check-export-map",
Expand Down Expand Up @@ -256,7 +256,6 @@
},
"homepage": "https://react-hook-form.com",
"devDependencies": {
"@effect/schema": "^0.68.17",
"@sinclair/typebox": "^0.32.34",
"@testing-library/dom": "^10.3.1",
"@testing-library/jest-dom": "^6.4.6",
Expand All @@ -277,7 +276,7 @@
"class-validator": "^0.14.1",
"computed-types": "^1.11.2",
"cross-env": "^7.0.3",
"effect": "^3.4.7",
"effect": "^3.10.3",
"fluentvalidation-ts": "^3.2.0",
"fp-ts": "^2.16.7",
"io-ts": "^2.2.21",
Expand Down Expand Up @@ -308,4 +307,4 @@
"peerDependencies": {
"react-hook-form": "^7.0.0"
}
}
}

0 comments on commit e523dde

Please sign in to comment.