Skip to content

Commit 18e423f

Browse files
jorisredecsTrent Coxbluebill1049
authored
feat: add typeschema resolver (#699)
* feat(typeschema): add typeschema resolver * fix(arktype): exclude arktype from resolver bundle (#693) * perf(valibot): reduce bundle size * perf(vine): reduce bundle size * chore(deps): update dependencies * chore: migrate to Bun & Biome --------- Co-authored-by: Trent Cox <[email protected]> * Update node version (#680) * Update main.yml (#681) * perf(typeschemaResolver): save some bytes * perf(arktype): reduce bundle size * perf: reduce bundle size * chore: update deps * chore: update all deps --------- Co-authored-by: André Costa <[email protected]> Co-authored-by: Trent Cox <[email protected]> Co-authored-by: Beier (Bill) <[email protected]>
1 parent 4b9acb7 commit 18e423f

File tree

128 files changed

+1430
-8044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+1430
-8044
lines changed

.eslintrc.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/compressedSize.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v3
11-
- name: Setup pnpm
12-
uses: pnpm/action-setup@v2
13-
with:
14-
version: 9.0
10+
- name: Checkout repo
11+
uses: actions/checkout@v4
12+
13+
- name: Setup bun
14+
uses: oven-sh/setup-bun@v1
15+
1516
- uses: preactjs/compressed-size-action@v2
1617
with:
1718
repo-token: '${{ secrets.GITHUB_TOKEN }}'
19+
install-script: 'bun i'
20+
build-script: 'bun run build'

.github/workflows/main.yml

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,20 @@ jobs:
2020
- name: Checkout repo
2121
uses: actions/checkout@v4
2222

23-
- name: Setup pnpm
24-
uses: pnpm/action-setup@v2
25-
with:
26-
version: 9.0
23+
- name: Setup bun
24+
uses: oven-sh/setup-bun@v1
2725

28-
- name: Use Node.js ${{ matrix.node-version }}
29-
uses: actions/setup-node@v3
30-
with:
31-
node-version: ${{ matrix.node-version }}
32-
cache: 'pnpm'
33-
34-
- name: Install dependencies
35-
run: pnpm install
26+
- name: Install Dependencies
27+
run: bun install
3628

3729
- name: Lint
38-
run: |
39-
pnpm lint
40-
pnpm lint:types
41-
42-
- name: Test
43-
run: pnpm test
30+
run: bun lint
31+
32+
- name: TS
33+
run: bun lint:types
4434

4535
- name: Build
46-
run: pnpm build
36+
run: bun run build
4737

4838
publish-module:
4939
name: 'Publish Module to NPM on Node ${{ matrix.node }} and ${{ matrix.os }}'
@@ -53,22 +43,15 @@ jobs:
5343
steps:
5444
- name: Checkout repo
5545
uses: actions/checkout@v4
56-
- name: Setup pnpm
57-
uses: pnpm/action-setup@v2
58-
with:
59-
version: 9.0
6046

61-
- name: Use Node.js ${{ matrix.node-version }}
62-
uses: actions/setup-node@v4
63-
with:
64-
node-version: 20
65-
cache: 'pnpm'
47+
- name: Setup bun
48+
uses: oven-sh/setup-bun@v1
6649

67-
- name: Install dependencies
68-
run: pnpm install
50+
- name: Install Dependencies
51+
run: bun install
6952

7053
- name: Build
71-
run: pnpm build
54+
run: bun run build
7255

7356
- name: Publish
7457
run: npx semantic-release

.husky/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.husky/pre-commit

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
32

4-
pnpm lint:types
5-
pnpm lint-staged
3+
if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
4+
set -x
5+
fi
6+
7+
if [ "$LEFTHOOK" = "0" ]; then
8+
exit 0
9+
fi
10+
11+
call_lefthook()
12+
{
13+
if test -n "$LEFTHOOK_BIN"
14+
then
15+
"$LEFTHOOK_BIN" "$@"
16+
elif lefthook -h >/dev/null 2>&1
17+
then
18+
lefthook "$@"
19+
else
20+
dir="$(git rev-parse --show-toplevel)"
21+
if test -f "$dir/node_modules/lefthook/bin/index.js"
22+
then
23+
"$dir/node_modules/lefthook/bin/index.js" "$@"
24+
else
25+
osArch=$(uname | tr '[:upper:]' '[:lower:]')
26+
cpuArch=$(uname -m | sed 's/aarch64/arm64/')
27+
if test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
28+
then
29+
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
30+
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
31+
then
32+
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
33+
34+
elif bundle exec lefthook -h >/dev/null 2>&1
35+
then
36+
bundle exec lefthook "$@"
37+
elif yarn lefthook -h >/dev/null 2>&1
38+
then
39+
yarn lefthook "$@"
40+
elif pnpm lefthook -h >/dev/null 2>&1
41+
then
42+
pnpm lefthook "$@"
43+
elif swift package plugin lefthook >/dev/null 2>&1
44+
then
45+
swift package --disable-sandbox plugin lefthook "$@"
46+
elif command -v mint >/dev/null 2>&1
47+
then
48+
mint run csjones/lefthook-plugin "$@"
49+
elif command -v npx >/dev/null 2>&1
50+
then
51+
npx lefthook "$@"
52+
else
53+
echo "Can't find lefthook in PATH"
54+
fi
55+
fi
56+
fi
57+
}
58+
59+
call_lefthook run "pre-commit" "$@"

.husky/prepare-commit-msg

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
4+
set -x
5+
fi
6+
7+
if [ "$LEFTHOOK" = "0" ]; then
8+
exit 0
9+
fi
10+
11+
call_lefthook()
12+
{
13+
if test -n "$LEFTHOOK_BIN"
14+
then
15+
"$LEFTHOOK_BIN" "$@"
16+
elif lefthook -h >/dev/null 2>&1
17+
then
18+
lefthook "$@"
19+
else
20+
dir="$(git rev-parse --show-toplevel)"
21+
if test -f "$dir/node_modules/lefthook/bin/index.js"
22+
then
23+
"$dir/node_modules/lefthook/bin/index.js" "$@"
24+
else
25+
osArch=$(uname | tr '[:upper:]' '[:lower:]')
26+
cpuArch=$(uname -m | sed 's/aarch64/arm64/')
27+
if test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
28+
then
29+
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
30+
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
31+
then
32+
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
33+
34+
elif bundle exec lefthook -h >/dev/null 2>&1
35+
then
36+
bundle exec lefthook "$@"
37+
elif yarn lefthook -h >/dev/null 2>&1
38+
then
39+
yarn lefthook "$@"
40+
elif pnpm lefthook -h >/dev/null 2>&1
41+
then
42+
pnpm lefthook "$@"
43+
elif swift package plugin lefthook >/dev/null 2>&1
44+
then
45+
swift package --disable-sandbox plugin lefthook "$@"
46+
elif command -v mint >/dev/null 2>&1
47+
then
48+
mint run csjones/lefthook-plugin "$@"
49+
elif command -v npx >/dev/null 2>&1
50+
then
51+
npx lefthook "$@"
52+
else
53+
echo "Can't find lefthook in PATH"
54+
fi
55+
fi
56+
fi
57+
}
58+
59+
call_lefthook run "prepare-commit-msg" "$@"

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ Here is a quick guide to doing code contributions to the library.
1212

1313
3. Install packages by running:
1414

15-
> pnpm install
15+
> bun install
1616
1717
4. If you've added a code that should be tested, ensure the test suite still passes.
1818

19-
> pnpm test
19+
> bun test
2020
2121
5. Try to write some unit tests to cover as much of your code as possible.
2222

2323
6. Ensure your code lints without errors.
2424

25-
> pnpm lint
25+
> bun lint
2626
2727
7. Ensure build passes.
2828

29-
> pnpm build
29+
> bun run build
3030
3131
8. Push your branch: `git push -u origin your-meaningful-branch-name`
3232

@@ -36,7 +36,7 @@ Here is a quick guide to doing code contributions to the library.
3636

3737
## Coding style
3838

39-
Please follow the coding style of the project. React Hook Form uses eslint and prettier. If possible, enable their respective plugins in your editor to get real-time feedback. The linting can be run manually with the following command: `pnpm lint`
39+
Please follow the coding style of the project. React Hook Form uses eslint and prettier. If possible, enable their respective plugins in your editor to get real-time feedback. The linting can be run manually with the following command: `bun lint`
4040

4141
## License
4242

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
- [With `TypeCompiler`](#with-typecompiler)
4848
- [ArkType](#arktype)
4949
- [Valibot](#valibot)
50+
- [TypeSchema](#typeschema)
5051
- [effect-ts](#effect-ts)
5152
- [VineJS](#vinejs)
5253
- [Backers](#backers)
@@ -615,6 +616,38 @@ const App = () => {
615616
};
616617
```
617618

619+
### [TypeSchema](https://typeschema.com)
620+
621+
Universal adapter for schema validation, compatible with [any validation library](https://typeschema.com/#coverage)
622+
623+
[![npm](https://img.shields.io/bundlephobia/minzip/@typeschema/main?style=for-the-badge)](https://bundlephobia.com/result?p=@typeschema/main)
624+
625+
```typescript jsx
626+
import { useForm } from 'react-hook-form';
627+
import { typeschemaResolver } from '@hookform/resolvers/typeschema';
628+
import * as z from 'zod';
629+
630+
// Use your favorite validation library
631+
const schema = z.object({
632+
username: z.string().min(1, { message: 'Required' }),
633+
password: z.number().min(1, { message: 'Required' }),
634+
});
635+
636+
const App = () => {
637+
const { register, handleSubmit } = useForm({
638+
resolver: typeschemaResolver(schema),
639+
});
640+
641+
return (
642+
<form onSubmit={handleSubmit((d) => console.log(d))}>
643+
<input {...register('username')} />
644+
<input type="password" {...register('password')} />
645+
<input type="submit" />
646+
</form>
647+
);
648+
};
649+
```
650+
618651
### [effect-ts](https://github.com/Effect-TS/effect)
619652

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

ajv/src/__tests__/ajv.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { ajvResolver } from '..';
2-
import { fields, invalidData, invalidDataWithUndefined, schema, validData } from './__fixtures__/data';
2+
import {
3+
fields,
4+
invalidData,
5+
invalidDataWithUndefined,
6+
schema,
7+
validData,
8+
} from './__fixtures__/data';
39

410
const shouldUseNativeValidation = false;
511

ajv/src/ajv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
22
import Ajv, { DefinedError } from 'ajv';
33
import ajvErrors from 'ajv-errors';
4-
import { appendErrors, FieldError } from 'react-hook-form';
4+
import { FieldError, appendErrors } from 'react-hook-form';
55
import { Resolver } from './types';
66

77
const parseErrorSchema = (

0 commit comments

Comments
 (0)