Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zod sync validation #114

Merged
merged 1 commit into from
Jan 21, 2021
Merged

Zod sync validation #114

merged 1 commit into from
Jan 21, 2021

Conversation

jorisre
Copy link
Member

@jorisre jorisre commented Jan 20, 2021

Related to #88

Starting with Zod, same for others resolvers coming :)

@jorisre jorisre changed the base branch from master to beta January 20, 2021 21:59
@github-actions
Copy link
Contributor

Size Change: -8.09 kB (-36%) 🎉

Total Size: 14.5 kB

Filename Size Change
dist/ie11/_virtual/_tslib.js 0 B -1.04 kB (removed) 🏆
dist/ie11/joi.js 0 B -610 B (removed) 🏆
dist/ie11/superstruct.js 0 B -513 B (removed) 🏆
dist/ie11/utils/convertArrayToPathName.js 0 B -218 B (removed) 🏆
dist/ie11/vest.js 0 B -557 B (removed) 🏆
dist/ie11/yup.js 0 B -648 B (removed) 🏆
dist/ie11/zod.js 0 B -519 B (removed) 🏆
dist/joi.js 0 B -550 B (removed) 🏆
dist/superstruct.js 0 B -541 B (removed) 🏆
dist/umd/index.js 0 B -1.48 kB (removed) 🏆
dist/utils/convertArrayToPathName.js 0 B -197 B (removed) 🏆
dist/vest.js 0 B -494 B (removed) 🏆
dist/yup.js 0 B -973 B (removed) 🏆
dist/zod.js 0 B -544 B (removed) 🏆
dist/resolvers.js 169 B +169 B (new file) 🆕
dist/resolvers.modern.js 177 B +177 B (new file) 🆕
dist/resolvers.module.js 182 B +182 B (new file) 🆕
dist/resolvers.umd.js 260 B +260 B (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
joi/dist/joi.js 604 B 0 B
joi/dist/joi.modern.js 503 B 0 B
joi/dist/joi.module.js 616 B 0 B
joi/dist/joi.umd.js 704 B 0 B
superstruct/dist/superstruct.js 991 B 0 B
superstruct/dist/superstruct.modern.js 928 B 0 B
superstruct/dist/superstruct.module.js 1.01 kB 0 B
superstruct/dist/superstruct.umd.js 1.09 kB 0 B
vest/dist/vest.js 494 B 0 B
vest/dist/vest.modern.js 442 B 0 B
vest/dist/vest.module.js 506 B 0 B
vest/dist/vest.umd.js 592 B 0 B
yup/dist/yup.js 695 B 0 B
yup/dist/yup.modern.js 602 B 0 B
yup/dist/yup.module.js 704 B 0 B
yup/dist/yup.umd.js 791 B 0 B
zod/dist/zod.js 616 B 0 B
zod/dist/zod.modern.js 503 B 0 B
zod/dist/zod.module.js 628 B 0 B
zod/dist/zod.umd.js 719 B 0 B

compressed-size-action

@@ -8,7 +8,8 @@ import type { ParseParams } from 'zod/lib/src/parser';

export type Resolver = <T extends z.ZodSchema<any, any>>(
schema: T,
options?: ParseParams,
schemaOptions?: ParseParams,
resolverOptions?: { mode: 'async' | 'sync' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to use this feature, i guess users will have to this:

resolver: async (data, options) => await zodResolver(schema, options, 'async')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No they have to this:

useForm({
  resolver: zodResolver(schema, options, {mode: 'sync'})
})

Or if you prefer, we can do the following:

interface Options {
  schema?: ParseParams;
  resolver?: { mode: 'async' | 'sync' }
}

export type Resolver = <T extends z.ZodSchema<any, any>>(
  schema: T,
  options?: Options
) => { ... }

So user will have to this:

useForm({
  resolver: zodResolver(schema, {
    resolver: { mode: 'sync' },
    schema: schemaZodOptions
  })
})

I think I prefer this one, what do you think ?

FYI: async is the default mode

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great:

useForm({
  resolver: zodResolver(schema, options, {mode: 'sync'})
})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options is optional so it could be:

useForm({
  resolver: zodResolver(schema, undefined, { mode: 'sync' })
})

@jorisre jorisre merged commit 22e7545 into beta Jan 21, 2021
@jorisre jorisre deleted the zod-sync-validation branch January 21, 2021 08:58
@jorisre jorisre mentioned this pull request Jan 21, 2021
5 tasks
@github-actions
Copy link
Contributor

🎉 This PR is included in version 2.0.0-beta.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

jorisre added a commit that referenced this pull request Apr 2, 2021
* feat: V2 init

BREAKING CHANGE: there will be some breaking changes in the next versions

* feat: improve modules support

* fix: yup resolver typescript errors

* Fix: vest validate all criteria + better TypeSript support + add tests

* test: add components test to ensure TypeScript is working as expected

Related to #97

* chore: improve zod resolvers types

* chore(eslint): remove warnings

* test: add severals tests & improve typings

* chore: setup compressed-size

* test: update describe

* feat: add Zod sync validation (#114)

* feat: add Joi sync validation (#116)

* feat: add Joi sync validation

* fix(joi): sync error

* test: add validateAllCriteria test

* test(joi): update test description

* feat: add Yup sync validation (#115)

* feat: add Yup sync validation

* test(zod): add tests

* test(zod): update tests

* test(yup): add validateAllCriteria test

* feat: add Vest sync validation + update to v3 (#117)

* feat: update to react-hook-form v7

BREAKING CHANGE: Require react-hook-form >= 7

* chore: fix typescript error (#123)

* chore: update deps

* chore: fix TypeScript error

* refactor: replace deprecated transformToNestObject (#125)

* fix: pass down Joi context (#124)

* fix: zod union error + reduce size (#126)

* test: extract fixtures

* fix: zod resolver union error + reduce resolver size

* feat: add error's ref (#127)

* feat: add error's ref

* test: add error's ref + extract fixtures

* test: add nested test

* refactor: rename toNestObject to toNestError

* Reduce superstruct resolver size (#128)

* test: extract test's fixtures

* test: jest fixtures config

* perf: reduce superstruct resolver size

* feat: add error's ref

* test: add error's ref + extract fixtures

* test: add nested test

* refactor: rename toNestObject to toNestError

* refactor: remove duplicate line

* chore: update superstruct peer dep

* perf: reduce vest resolver size (#129)

* test: extract test's fixtures

* test: jest fixtures config

* perf: reduce superstruct resolver size

* feat: add error's ref

* test: add error's ref + extract fixtures

* test: add nested test

* refactor: rename toNestObject to toNestError

* refactor: remove duplicate line

* perf: recude vest resolver bundle size

* perf: reduce joi resolver's size (#131)

* perf: reduce Joi resolver's size

* perf: reduce Vest resolver's size

* perf: reduce yup resolver's size (#130)

* refactor: remove convertArrayToPathName (#132)

* perf: reduce joi and yup bundle size (#134)

* fix(types): add Lazy schema support to resolver

* docs: v2 doc (#136)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants