@hookform/resolvers 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/ajv/dist/ajv.js.map +1 -1
- package/ajv/dist/ajv.modern.mjs.map +1 -1
- package/ajv/dist/ajv.module.js.map +1 -1
- package/ajv/dist/ajv.umd.js.map +1 -1
- package/ajv/dist/types.d.ts +1 -1
- package/ajv/src/__tests__/ajv.ts +7 -1
- package/ajv/src/ajv.ts +1 -1
- package/ajv/src/types.ts +1 -5
- package/arktype/dist/arktype.js +1 -1
- package/arktype/dist/arktype.js.map +1 -1
- package/arktype/dist/arktype.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs +1 -1
- package/arktype/dist/arktype.modern.mjs.map +1 -1
- package/arktype/dist/arktype.module.js +1 -1
- package/arktype/dist/arktype.module.js.map +1 -1
- package/arktype/dist/arktype.umd.js +1 -1
- package/arktype/dist/arktype.umd.js.map +1 -1
- package/arktype/dist/types.d.ts +1 -1
- package/arktype/package.json +2 -1
- package/arktype/src/__tests__/Form-native-validation.tsx +5 -5
- package/arktype/src/__tests__/Form.tsx +2 -2
- package/arktype/src/__tests__/__fixtures__/data.ts +1 -1
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +29 -29
- package/arktype/src/__tests__/arktype.ts +1 -1
- package/arktype/src/arktype.ts +2 -2
- package/arktype/src/types.ts +1 -1
- package/class-validator/dist/class-validator.js.map +1 -1
- package/class-validator/dist/class-validator.modern.mjs.map +1 -1
- package/class-validator/dist/class-validator.module.js.map +1 -1
- package/class-validator/dist/class-validator.umd.js.map +1 -1
- package/class-validator/dist/types.d.ts +2 -2
- package/class-validator/src/__tests__/Form-native-validation.tsx +2 -2
- package/class-validator/src/__tests__/Form.tsx +2 -2
- package/class-validator/src/__tests__/__snapshots__/class-validator.ts.snap +2 -2
- package/class-validator/src/__tests__/class-validator.ts +4 -4
- package/class-validator/src/class-validator.ts +2 -2
- package/class-validator/src/types.ts +2 -2
- package/computed-types/dist/computed-types.js.map +1 -1
- package/computed-types/dist/computed-types.modern.mjs.map +1 -1
- package/computed-types/dist/computed-types.module.js.map +1 -1
- package/computed-types/dist/computed-types.umd.js.map +1 -1
- package/computed-types/dist/types.d.ts +1 -1
- package/computed-types/src/__tests__/Form-native-validation.tsx +2 -2
- package/computed-types/src/__tests__/Form.tsx +2 -2
- package/computed-types/src/__tests__/__fixtures__/data.ts +1 -1
- package/computed-types/src/__tests__/__snapshots__/computed-types.ts.snap +6 -6
- package/computed-types/src/__tests__/computed-types.ts +1 -1
- package/computed-types/src/computed-types.ts +2 -2
- package/computed-types/src/types.ts +1 -1
- package/dist/resolvers.js +1 -1
- package/dist/resolvers.js.map +1 -1
- package/dist/resolvers.mjs +1 -1
- package/dist/resolvers.mjs.map +1 -1
- package/dist/resolvers.module.js +1 -1
- package/dist/resolvers.module.js.map +1 -1
- package/dist/resolvers.umd.js +1 -1
- package/dist/resolvers.umd.js.map +1 -1
- package/dist/toNestErrors.d.ts +1 -6
- package/dist/validateFieldsNatively.d.ts +1 -1
- package/effect-ts/dist/effect-ts.js +1 -1
- package/effect-ts/dist/effect-ts.js.map +1 -1
- package/effect-ts/dist/effect-ts.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs +1 -1
- package/effect-ts/dist/effect-ts.modern.mjs.map +1 -1
- package/effect-ts/dist/effect-ts.module.js +1 -1
- package/effect-ts/dist/effect-ts.module.js.map +1 -1
- package/effect-ts/dist/effect-ts.umd.js +1 -1
- package/effect-ts/dist/effect-ts.umd.js.map +1 -1
- package/effect-ts/src/__tests__/Form-native-validation.tsx +2 -2
- package/effect-ts/src/__tests__/Form.tsx +2 -2
- package/effect-ts/src/__tests__/__snapshots__/effect-ts.ts.snap +2 -2
- package/effect-ts/src/__tests__/effect-ts.ts +1 -1
- package/effect-ts/src/effect-ts.ts +1 -1
- package/io-ts/dist/errorsToRecord.d.ts +0 -1
- package/io-ts/dist/io-ts.js +1 -1
- package/io-ts/dist/io-ts.js.map +1 -1
- package/io-ts/dist/io-ts.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs +1 -1
- package/io-ts/dist/io-ts.modern.mjs.map +1 -1
- package/io-ts/dist/io-ts.module.js +1 -1
- package/io-ts/dist/io-ts.module.js.map +1 -1
- package/io-ts/dist/io-ts.umd.js +1 -1
- package/io-ts/dist/io-ts.umd.js.map +1 -1
- package/io-ts/src/__tests__/Form-native-validation.tsx +2 -2
- package/io-ts/src/__tests__/Form.tsx +2 -2
- package/io-ts/src/__tests__/__snapshots__/io-ts.ts.snap +9 -9
- package/io-ts/src/__tests__/errorsToRecord.ts +29 -19
- package/io-ts/src/__tests__/io-ts.ts +1 -1
- package/io-ts/src/errorsToRecord.ts +19 -10
- package/io-ts/src/io-ts.ts +1 -1
- package/joi/dist/joi.js +1 -1
- package/joi/dist/joi.js.map +1 -1
- package/joi/dist/joi.mjs +1 -1
- package/joi/dist/joi.modern.mjs +1 -1
- package/joi/dist/joi.modern.mjs.map +1 -1
- package/joi/dist/joi.module.js +1 -1
- package/joi/dist/joi.module.js.map +1 -1
- package/joi/dist/joi.umd.js +1 -1
- package/joi/dist/joi.umd.js.map +1 -1
- package/joi/dist/types.d.ts +1 -1
- package/joi/src/__tests__/Form-native-validation.tsx +2 -2
- package/joi/src/__tests__/Form.tsx +2 -2
- package/joi/src/__tests__/__snapshots__/joi.ts.snap +56 -56
- package/joi/src/__tests__/joi.ts +1 -1
- package/joi/src/joi.ts +1 -1
- package/joi/src/types.ts +1 -5
- package/nope/dist/nope.js.map +1 -1
- package/nope/dist/nope.modern.mjs.map +1 -1
- package/nope/dist/nope.module.js.map +1 -1
- package/nope/dist/nope.umd.js.map +1 -1
- package/nope/dist/types.d.ts +1 -1
- package/nope/src/__tests__/Form-native-validation.tsx +2 -2
- package/nope/src/__tests__/Form.tsx +2 -2
- package/nope/src/__tests__/__fixtures__/data.ts +1 -1
- package/nope/src/__tests__/nope.ts +1 -1
- package/nope/src/nope.ts +1 -1
- package/nope/src/types.ts +2 -2
- package/package.json +54 -51
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/dist/types.d.ts +1 -1
- package/superstruct/src/__tests__/Form-native-validation.tsx +2 -2
- package/superstruct/src/__tests__/Form.tsx +2 -2
- package/superstruct/src/__tests__/__fixtures__/data.ts +8 -8
- package/superstruct/src/__tests__/__snapshots__/superstruct.ts.snap +4 -4
- package/superstruct/src/__tests__/superstruct.ts +1 -1
- package/superstruct/src/superstruct.ts +1 -1
- package/superstruct/src/types.ts +1 -1
- package/typanion/dist/typanion.js.map +1 -1
- package/typanion/dist/typanion.modern.mjs.map +1 -1
- package/typanion/dist/typanion.module.js.map +1 -1
- package/typanion/dist/typanion.umd.js.map +1 -1
- package/typanion/dist/types.d.ts +1 -1
- package/typanion/src/__tests__/Form-native-validation.tsx +1 -1
- package/typanion/src/__tests__/Form.tsx +1 -1
- package/typanion/src/__tests__/__fixtures__/data.ts +12 -7
- package/typanion/src/__tests__/__snapshots__/typanion.ts.snap +4 -4
- package/typanion/src/__tests__/typanion.ts +1 -1
- package/typanion/src/typanion.ts +1 -1
- package/typanion/src/types.ts +4 -4
- package/typebox/dist/typebox.js +1 -1
- package/typebox/dist/typebox.js.map +1 -1
- package/typebox/dist/typebox.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs +1 -1
- package/typebox/dist/typebox.modern.mjs.map +1 -1
- package/typebox/dist/typebox.module.js +1 -1
- package/typebox/dist/typebox.module.js.map +1 -1
- package/typebox/dist/typebox.umd.js +1 -1
- package/typebox/dist/typebox.umd.js.map +1 -1
- package/typebox/dist/types.d.ts +3 -2
- package/typebox/src/__tests__/Form-compiler.tsx +57 -0
- package/typebox/src/__tests__/Form-native-validation-compiler.tsx +86 -0
- package/typebox/src/__tests__/Form-native-validation.tsx +4 -4
- package/typebox/src/__tests__/Form.tsx +3 -3
- package/typebox/src/__tests__/__fixtures__/data.ts +6 -2
- package/typebox/src/__tests__/__snapshots__/typebox-compiler.ts.snap +188 -0
- package/typebox/src/__tests__/__snapshots__/typebox.ts.snap +13 -13
- package/typebox/src/__tests__/typebox-compiler.ts +37 -0
- package/typebox/src/__tests__/typebox.ts +1 -1
- package/typebox/src/typebox.ts +8 -3
- package/typebox/src/types.ts +3 -2
- package/typeschema/dist/index.d.ts +2 -0
- package/typeschema/dist/types.d.ts +9 -0
- package/typeschema/dist/typeschema.d.ts +2 -0
- package/typeschema/dist/typeschema.js +2 -0
- package/typeschema/dist/typeschema.js.map +1 -0
- package/typeschema/dist/typeschema.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs +2 -0
- package/typeschema/dist/typeschema.modern.mjs.map +1 -0
- package/typeschema/dist/typeschema.module.js +2 -0
- package/typeschema/dist/typeschema.module.js.map +1 -0
- package/typeschema/dist/typeschema.umd.js +2 -0
- package/typeschema/dist/typeschema.umd.js.map +1 -0
- package/typeschema/package.json +18 -0
- package/typeschema/src/__tests__/Form-native-validation.tsx +82 -0
- package/typeschema/src/__tests__/Form.tsx +53 -0
- package/typeschema/src/__tests__/__fixtures__/data.ts +88 -0
- package/typeschema/src/__tests__/__snapshots__/typeschema.ts.snap +225 -0
- package/typeschema/src/__tests__/typeschema.ts +70 -0
- package/typeschema/src/index.ts +2 -0
- package/typeschema/src/types.ts +18 -0
- package/typeschema/src/typeschema.ts +70 -0
- package/valibot/dist/types.d.ts +1 -1
- package/valibot/dist/valibot.js +1 -1
- package/valibot/dist/valibot.js.map +1 -1
- package/valibot/dist/valibot.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs +1 -1
- package/valibot/dist/valibot.modern.mjs.map +1 -1
- package/valibot/dist/valibot.module.js +1 -1
- package/valibot/dist/valibot.module.js.map +1 -1
- package/valibot/dist/valibot.umd.js +1 -1
- package/valibot/dist/valibot.umd.js.map +1 -1
- package/valibot/src/__tests__/Form-native-validation.tsx +2 -2
- package/valibot/src/__tests__/Form.tsx +1 -1
- package/valibot/src/__tests__/valibot.ts +4 -4
- package/valibot/src/types.ts +1 -1
- package/valibot/src/valibot.ts +12 -6
- package/vest/dist/types.d.ts +2 -2
- package/vest/dist/vest.js.map +1 -1
- package/vest/dist/vest.modern.mjs.map +1 -1
- package/vest/dist/vest.module.js.map +1 -1
- package/vest/dist/vest.umd.js.map +1 -1
- package/vest/src/__tests__/Form-native-validation.tsx +1 -1
- package/vest/src/__tests__/Form.tsx +1 -1
- package/vest/src/__tests__/__snapshots__/vest.ts.snap +0 -6
- package/vest/src/__tests__/vest.ts +14 -8
- package/vest/src/types.ts +11 -4
- package/vest/src/vest.ts +1 -1
- package/vine/dist/types.d.ts +1 -1
- package/vine/dist/vine.js +1 -1
- package/vine/dist/vine.js.map +1 -1
- package/vine/dist/vine.mjs +1 -1
- package/vine/dist/vine.modern.mjs +1 -1
- package/vine/dist/vine.modern.mjs.map +1 -1
- package/vine/dist/vine.module.js +1 -1
- package/vine/dist/vine.module.js.map +1 -1
- package/vine/dist/vine.umd.js +1 -1
- package/vine/dist/vine.umd.js.map +1 -1
- package/vine/src/__tests__/Form-native-validation.tsx +9 -5
- package/vine/src/__tests__/Form.tsx +9 -5
- package/vine/src/__tests__/__fixtures__/data.ts +4 -2
- package/vine/src/__tests__/vine.ts +1 -1
- package/vine/src/types.ts +1 -1
- package/vine/src/vine.ts +10 -8
- package/yup/dist/yup.d.ts +1 -1
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/Form-native-validation.tsx +1 -1
- package/yup/src/__tests__/Form.tsx +1 -1
- package/yup/src/__tests__/__snapshots__/yup.ts.snap +13 -13
- package/yup/src/__tests__/yup.ts +9 -7
- package/yup/src/yup.ts +2 -2
- package/zod/dist/types.d.ts +1 -1
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/Form-native-validation.tsx +2 -2
- package/zod/src/__tests__/Form.tsx +1 -1
- package/zod/src/__tests__/zod.ts +1 -1
- package/zod/src/types.ts +1 -1
- package/zod/src/zod.ts +4 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hookform/resolvers",
|
|
3
3
|
"amdName": "hookformResolvers",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.8.0",
|
|
5
5
|
"description": "React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion, Effect-TS and VineJS",
|
|
6
6
|
"main": "dist/resolvers.js",
|
|
7
7
|
"module": "dist/resolvers.module.js",
|
|
@@ -99,6 +99,12 @@
|
|
|
99
99
|
"import": "./valibot/dist/valibot.mjs",
|
|
100
100
|
"require": "./valibot/dist/valibot.js"
|
|
101
101
|
},
|
|
102
|
+
"./typeschema": {
|
|
103
|
+
"types": "./typeschema/dist/index.d.ts",
|
|
104
|
+
"umd": "./typeschema/dist/typeschema.umd.js",
|
|
105
|
+
"import": "./typeschema/dist/typeschema.mjs",
|
|
106
|
+
"require": "./typeschema/dist/typeschema.js"
|
|
107
|
+
},
|
|
102
108
|
"./effect-ts": {
|
|
103
109
|
"types": "./effect-ts/dist/index.d.ts",
|
|
104
110
|
"umd": "./effect-ts/dist/effect-ts.umd.js",
|
|
@@ -158,6 +164,12 @@
|
|
|
158
164
|
"valibot/package.json",
|
|
159
165
|
"valibot/src",
|
|
160
166
|
"valibot/dist",
|
|
167
|
+
"typeschema/package.json",
|
|
168
|
+
"typeschema/src",
|
|
169
|
+
"typeschema/dist",
|
|
170
|
+
"effect-ts/package.json",
|
|
171
|
+
"effect-ts/src",
|
|
172
|
+
"effect-ts/dist",
|
|
161
173
|
"effect-ts/package.json",
|
|
162
174
|
"effect-ts/src",
|
|
163
175
|
"effect-ts/dist",
|
|
@@ -169,7 +181,7 @@
|
|
|
169
181
|
"access": "public"
|
|
170
182
|
},
|
|
171
183
|
"scripts": {
|
|
172
|
-
"prepare": "run-s build:src build && check-export-map
|
|
184
|
+
"prepare": "run-s build:src build && check-export-map",
|
|
173
185
|
"build": "cross-env npm-run-all --parallel 'build:*'",
|
|
174
186
|
"build:src": "microbundle build --globals react-hook-form=ReactHookForm",
|
|
175
187
|
"build:zod": "microbundle --cwd zod --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
@@ -183,13 +195,14 @@
|
|
|
183
195
|
"build:computed-types": "microbundle --cwd computed-types --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
184
196
|
"build:typanion": "microbundle --cwd typanion --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
185
197
|
"build:ajv": "microbundle --cwd ajv --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
186
|
-
"build:typebox": "microbundle --cwd typebox --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@sinclair/typebox/value=value",
|
|
198
|
+
"build:typebox": "microbundle --cwd typebox --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@sinclair/typebox/value=value,@sinclair/typebox/compiler=compiler",
|
|
187
199
|
"build:arktype": "microbundle --cwd arktype --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
188
200
|
"build:valibot": "microbundle --cwd valibot --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm",
|
|
189
|
-
"build:
|
|
201
|
+
"build:typeschema": "microbundle --cwd typeschema --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@typeschema/main=main",
|
|
202
|
+
"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",
|
|
190
203
|
"build:vine": "microbundle --cwd vine --globals @hookform/resolvers=hookformResolvers,react-hook-form=ReactHookForm,@vinejs/vine=vine",
|
|
191
204
|
"postbuild": "node ./config/node-13-exports.js",
|
|
192
|
-
"lint": "
|
|
205
|
+
"lint": "bunx @biomejs/biome check --write --vcs-use-ignore-file=true .",
|
|
193
206
|
"lint:types": "tsc",
|
|
194
207
|
"test": "vitest run",
|
|
195
208
|
"test:watch": "vitest watch",
|
|
@@ -218,6 +231,7 @@
|
|
|
218
231
|
"ajv",
|
|
219
232
|
"TypeBox",
|
|
220
233
|
"arktype",
|
|
234
|
+
"typeschema",
|
|
221
235
|
"vine"
|
|
222
236
|
],
|
|
223
237
|
"repository": {
|
|
@@ -231,66 +245,55 @@
|
|
|
231
245
|
},
|
|
232
246
|
"homepage": "https://react-hook-form.com",
|
|
233
247
|
"devDependencies": {
|
|
234
|
-
"@effect/schema": "^0.
|
|
235
|
-
"@sinclair/typebox": "^0.
|
|
236
|
-
"@testing-library/dom": "^
|
|
237
|
-
"@testing-library/jest-dom": "^6.
|
|
238
|
-
"@testing-library/react": "^
|
|
239
|
-
"@testing-library/user-event": "^14.
|
|
240
|
-
"@types/node": "^20.
|
|
241
|
-
"@types/react": "^18.
|
|
242
|
-
"@
|
|
243
|
-
"@
|
|
244
|
-
"@
|
|
245
|
-
"@
|
|
246
|
-
"
|
|
248
|
+
"@effect/schema": "^0.68.15",
|
|
249
|
+
"@sinclair/typebox": "^0.32.34",
|
|
250
|
+
"@testing-library/dom": "^10.3.0",
|
|
251
|
+
"@testing-library/jest-dom": "^6.4.6",
|
|
252
|
+
"@testing-library/react": "^16.0.0",
|
|
253
|
+
"@testing-library/user-event": "^14.5.2",
|
|
254
|
+
"@types/node": "^20.14.9",
|
|
255
|
+
"@types/react": "^18.3.3",
|
|
256
|
+
"@typeschema/core": "^0.13.2",
|
|
257
|
+
"@typeschema/main": "^0.13.10",
|
|
258
|
+
"@typeschema/zod": "^0.13.3",
|
|
259
|
+
"@vinejs/vine": "^2.1.0",
|
|
260
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
261
|
+
"ajv": "^8.16.0",
|
|
247
262
|
"ajv-errors": "^3.0.0",
|
|
248
|
-
"arktype": "2.0.0-dev.
|
|
249
|
-
"check-export-map": "^1.3.
|
|
263
|
+
"arktype": "2.0.0-dev.26",
|
|
264
|
+
"check-export-map": "^1.3.1",
|
|
250
265
|
"class-transformer": "^0.5.1",
|
|
251
|
-
"class-validator": "^0.14.
|
|
266
|
+
"class-validator": "^0.14.1",
|
|
252
267
|
"computed-types": "^1.11.2",
|
|
253
268
|
"cross-env": "^7.0.3",
|
|
254
|
-
"effect": "^3.
|
|
255
|
-
"
|
|
256
|
-
"
|
|
257
|
-
"fp-ts": "^2.16.1",
|
|
258
|
-
"husky": "^8.0.3",
|
|
259
|
-
"io-ts": "^2.2.20",
|
|
269
|
+
"effect": "^3.4.6",
|
|
270
|
+
"fp-ts": "^2.16.7",
|
|
271
|
+
"io-ts": "^2.2.21",
|
|
260
272
|
"io-ts-types": "^0.5.19",
|
|
261
|
-
"joi": "^17.
|
|
262
|
-
"jsdom": "^
|
|
263
|
-
"
|
|
273
|
+
"joi": "^17.13.3",
|
|
274
|
+
"jsdom": "^24.1.0",
|
|
275
|
+
"lefthook": "^1.6.18",
|
|
264
276
|
"microbundle": "^0.15.1",
|
|
265
277
|
"monocle-ts": "^2.3.13",
|
|
266
278
|
"newtype-ts": "^0.3.5",
|
|
267
279
|
"nope-validator": "^1.0.4",
|
|
268
280
|
"npm-run-all": "^4.1.5",
|
|
269
|
-
"
|
|
270
|
-
"react": "^18.
|
|
271
|
-
"react-
|
|
272
|
-
"
|
|
273
|
-
"
|
|
274
|
-
"superstruct": "^1.0.3",
|
|
281
|
+
"react": "^18.3.1",
|
|
282
|
+
"react-dom": "^18.3.1",
|
|
283
|
+
"react-hook-form": "^7.52.1",
|
|
284
|
+
"reflect-metadata": "^0.2.2",
|
|
285
|
+
"superstruct": "^1.0.4",
|
|
275
286
|
"typanion": "^3.14.0",
|
|
276
|
-
"typescript": "^5.
|
|
287
|
+
"typescript": "^5.5.3",
|
|
277
288
|
"valibot": "0.35.0",
|
|
278
|
-
"vest": "^
|
|
279
|
-
"vite": "^
|
|
280
|
-
"vite-tsconfig-paths": "^4.2
|
|
281
|
-
"vitest": "^
|
|
282
|
-
"yup": "^1.
|
|
283
|
-
"zod": "^3.
|
|
289
|
+
"vest": "^5.3.0",
|
|
290
|
+
"vite": "^5.3.3",
|
|
291
|
+
"vite-tsconfig-paths": "^4.3.2",
|
|
292
|
+
"vitest": "^1.6.0",
|
|
293
|
+
"yup": "^1.4.0",
|
|
294
|
+
"zod": "^3.23.8"
|
|
284
295
|
},
|
|
285
296
|
"peerDependencies": {
|
|
286
297
|
"react-hook-form": "^7.0.0"
|
|
287
|
-
},
|
|
288
|
-
"lint-staged": {
|
|
289
|
-
"*.{js,ts}": [
|
|
290
|
-
"pnpm lint --fix"
|
|
291
|
-
],
|
|
292
|
-
"*.{md,json,yml}": [
|
|
293
|
-
"prettier --write"
|
|
294
|
-
]
|
|
295
298
|
}
|
|
296
299
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.js","sources":["../src/superstruct.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"superstruct.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const result = validate(values, schema, schemaOptions);\n\n if (result[0]) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(result[0]), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result[1],\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","error","result","validate","errors","toNestErrors","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"0FAiBE,SAACA,EAAQC,EAAeC,GACxB,YADwBA,IAAAA,IAAAA,EAAkB,CAAA,GAC1C,SAACC,EAAQC,EAAGC,GACV,IAbsBC,EAahBC,EAASC,EAAQA,SAACL,EAAQH,EAAQC,GAExC,OAAIM,EAAO,GACF,CACLJ,OAAQ,CAAE,EACVM,OAAQC,EAAAA,cAlBUJ,EAkBoBC,EAAO,GAjBnDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,GACT,OAACO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,CAAQ,EAChB,CAAA,IAWsDR,KAItDA,EAAQa,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEd,GAEzD,CACLF,OAAQD,EAAgBkB,IAAMjB,EAASI,EAAO,GAC9CE,OAAQ,CAAA,GAEZ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.modern.mjs","sources":["../src/superstruct.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"superstruct.modern.mjs","sources":["../src/superstruct.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const result = validate(values, schema, schemaOptions);\n\n if (result[0]) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(result[0]), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result[1],\n errors: {},\n };\n };\n"],"names":["superstructResolver","schema","schemaOptions","resolverOptions","values","_","options","result","validate","errors","toNestErrors","error","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"sHAMA,MAUaA,EACXA,CAACC,EAAQC,EAAeC,EAAkB,CAAE,IAC5C,CAACC,EAAQC,EAAGC,KACV,MAAMC,EAASC,EAASJ,EAAQH,EAAQC,GAExC,OAAIK,EAAO,GACF,CACLH,OAAQ,CAAA,EACRK,OAAQC,GAlBUC,EAkBoBJ,EAAO,GAjBnDI,EAAMC,WAAWC,OACf,CAACC,EAAUH,KACRG,EAASH,EAAMI,KAAKC,KAAK,MAAQ,CAChCC,QAASN,EAAMM,QACfC,KAAMP,EAAMO,QACRJ,EACR,CAAA,IAWsDR,KAItDA,EAAQa,2BAA6BC,EAAuB,CAAE,EAAEd,GAEzD,CACLF,OAAQD,EAAgBkB,IAAMjB,EAASG,EAAO,GAC9CE,OAAQ,KA1BYE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.module.js","sources":["../src/superstruct.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"superstruct.module.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const result = validate(values, schema, schemaOptions);\n\n if (result[0]) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(result[0]), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result[1],\n errors: {},\n };\n };\n"],"names":["superstructResolver","schema","schemaOptions","resolverOptions","values","_","options","error","result","validate","errors","toNestErrors","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"sHAMA,IAUaA,EACX,SAACC,EAAQC,EAAeC,GACxB,YADwBA,IAAAA,IAAAA,EAAkB,CAAA,GAC1C,SAACC,EAAQC,EAAGC,GACV,IAbsBC,EAahBC,EAASC,EAASL,EAAQH,EAAQC,GAExC,OAAIM,EAAO,GACF,CACLJ,OAAQ,CAAE,EACVM,OAAQC,GAlBUJ,EAkBoBC,EAAO,GAjBnDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,GACT,OAACO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,CAAQ,EAChB,CAAA,IAWsDR,KAItDA,EAAQa,2BAA6BC,EAAuB,CAAE,EAAEd,GAEzD,CACLF,OAAQD,EAAgBkB,IAAMjB,EAASI,EAAO,GAC9CE,OAAQ,CAAA,GAEZ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.umd.js","sources":["../src/superstruct.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"superstruct.umd.js","sources":["../src/superstruct.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { FieldError } from 'react-hook-form';\n\nimport { StructError, validate } from 'superstruct';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (error: StructError) =>\n error.failures().reduce<Record<string, FieldError>>(\n (previous, error) =>\n (previous[error.path.join('.')] = {\n message: error.message,\n type: error.type,\n }) && previous,\n {},\n );\n\nexport const superstructResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const result = validate(values, schema, schemaOptions);\n\n if (result[0]) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(result[0]), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.raw ? values : result[1],\n errors: {},\n };\n };\n"],"names":["schema","schemaOptions","resolverOptions","values","_","options","error","result","validate","errors","toNestErrors","failures","reduce","previous","path","join","message","type","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"4YAiBE,SAACA,EAAQC,EAAeC,GACxB,YADwBA,IAAAA,IAAAA,EAAkB,CAAA,GAC1C,SAACC,EAAQC,EAAGC,GACV,IAbsBC,EAahBC,EAASC,EAAQA,SAACL,EAAQH,EAAQC,GAExC,OAAIM,EAAO,GACF,CACLJ,OAAQ,CAAE,EACVM,OAAQC,EAAAA,cAlBUJ,EAkBoBC,EAAO,GAjBnDD,EAAMK,WAAWC,OACf,SAACC,EAAUP,GACT,OAACO,EAASP,EAAMQ,KAAKC,KAAK,MAAQ,CAChCC,QAASV,EAAMU,QACfC,KAAMX,EAAMW,QACRJ,CAAQ,EAChB,CAAA,IAWsDR,KAItDA,EAAQa,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEd,GAEzD,CACLF,OAAQD,EAAgBkB,IAAMjB,EAASI,EAAO,GAC9CE,OAAQ,CAAA,GAEZ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
-
import {
|
|
2
|
+
import { Struct, validate } from 'superstruct';
|
|
3
3
|
type Options = Parameters<typeof validate>[2];
|
|
4
4
|
export type Resolver = <T extends Struct<any, any>>(schema: T, options?: Options, factoryOptions?: {
|
|
5
5
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
|
-
import {
|
|
5
|
+
import { Infer, object, size, string } from 'superstruct';
|
|
6
6
|
import { superstructResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const schema = object({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
|
-
import {
|
|
5
|
+
import { Infer, object, size, string } from 'superstruct';
|
|
6
6
|
import { superstructResolver } from '..';
|
|
7
7
|
|
|
8
8
|
const schema = object({
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
Infer,
|
|
4
|
+
array,
|
|
5
|
+
boolean,
|
|
6
|
+
define,
|
|
7
|
+
max,
|
|
8
|
+
min,
|
|
4
9
|
number,
|
|
5
|
-
|
|
10
|
+
object,
|
|
6
11
|
optional,
|
|
7
12
|
pattern,
|
|
8
13
|
size,
|
|
14
|
+
string,
|
|
9
15
|
union,
|
|
10
|
-
min,
|
|
11
|
-
max,
|
|
12
|
-
Infer,
|
|
13
|
-
define,
|
|
14
|
-
array,
|
|
15
|
-
boolean,
|
|
16
16
|
} from 'superstruct';
|
|
17
17
|
|
|
18
18
|
const Password = define(
|
|
@@ -4,12 +4,12 @@ exports[`superstructResolver > should return a single error from superstructReso
|
|
|
4
4
|
{
|
|
5
5
|
"errors": {
|
|
6
6
|
"birthYear": {
|
|
7
|
-
"message": "Expected a number, but received:
|
|
7
|
+
"message": "Expected a number, but received: "birthYear"",
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
"type": "number",
|
|
10
10
|
},
|
|
11
11
|
"email": {
|
|
12
|
-
"message": "Expected a string matching \`/^[
|
|
12
|
+
"message": "Expected a string matching \`/^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$/\` but received """,
|
|
13
13
|
"ref": {
|
|
14
14
|
"name": "email",
|
|
15
15
|
},
|
|
@@ -23,7 +23,7 @@ exports[`superstructResolver > should return a single error from superstructReso
|
|
|
23
23
|
"like": [
|
|
24
24
|
{
|
|
25
25
|
"id": {
|
|
26
|
-
"message": "Expected a number, but received:
|
|
26
|
+
"message": "Expected a number, but received: "z"",
|
|
27
27
|
"ref": undefined,
|
|
28
28
|
"type": "number",
|
|
29
29
|
},
|
|
@@ -35,7 +35,7 @@ exports[`superstructResolver > should return a single error from superstructReso
|
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
37
|
"password": {
|
|
38
|
-
"message": "Expected a string matching \`/^[a-zA-Z0-9]{3,30}/\` but received
|
|
38
|
+
"message": "Expected a string matching \`/^[a-zA-Z0-9]{3,30}/\` but received "___"",
|
|
39
39
|
"ref": {
|
|
40
40
|
"name": "password",
|
|
41
41
|
},
|
package/superstruct/src/types.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typanion.js","sources":["../src/typanion.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"typanion.js","sources":["../src/typanion.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const fieldIndex = error.indexOf(':');\n\n const field = error.slice(1, fieldIndex);\n const message = error.slice(fieldIndex + 1).trim();\n\n acc[field] = {\n message,\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestErrors(parsedErrors, options) };\n };\n"],"names":["validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","reduce","acc","error","fieldIndex","indexOf","field","slice","message","trim","parseErrors","shouldUseNativeValidation","validateFieldsNatively","toNestErrors"],"mappings":"8DAoBE,SAACA,EAAWC,eAAgB,IAAhBA,IAAAA,EAAmB,CAAE,GAChCC,SAAAA,EAAQC,EAAGC,GACV,IAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,GACA,CACEC,OAAQJ,GAEVJ,IAGES,EA7BU,SAACD,EAAkBC,GACrC,YADqCA,IAAAA,IAAAA,EAA4B,CAAE,GAC5DD,EAAOE,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAaD,EAAME,QAAQ,KAE3BC,EAAQH,EAAMI,MAAM,EAAGH,GACvBI,EAAUL,EAAMI,MAAMH,EAAa,GAAGK,OAM5C,OAJAP,EAAII,GAAS,CACXE,QAAAA,GAGKN,CACT,EAAGF,EACL,CAgByBU,CAAYf,GAEjC,OAAIC,GACFF,EAAQiB,2BACNC,yBAAuBZ,EAAcN,GAEhC,CAAEF,OAAAA,EAAQO,OAAQ,CAAA,IAGpB,CAAEP,OAAQ,GAAIO,OAAQc,EAAYA,aAACb,EAAcN,GAC1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typanion.modern.mjs","sources":["../src/typanion.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"typanion.modern.mjs","sources":["../src/typanion.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const fieldIndex = error.indexOf(':');\n\n const field = error.slice(1, fieldIndex);\n const message = error.slice(fieldIndex + 1).trim();\n\n acc[field] = {\n message,\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestErrors(parsedErrors, options) };\n };\n"],"names":["typanionResolver","validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","parseErrors","reduce","acc","error","fieldIndex","indexOf","field","slice","message","trim","shouldUseNativeValidation","validateFieldsNatively","toNestErrors"],"mappings":"+EAIA,MAeaA,EACXA,CAACC,EAAWC,EAAmB,CAAE,IACjC,CAACC,EAAQC,EAAGC,KACV,MAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,GACA,CACEC,OAAQJ,GAEVJ,IAGES,EA7BUC,EAACF,EAAkBC,EAA4B,CAAA,IAC1DD,EAAOG,OAAO,CAACC,EAAKC,KACzB,MAAMC,EAAaD,EAAME,QAAQ,KAE3BC,EAAQH,EAAMI,MAAM,EAAGH,GACvBI,EAAUL,EAAMI,MAAMH,EAAa,GAAGK,OAM5C,OAJAP,EAAII,GAAS,CACXE,WAGKN,GACNH,GAiBoBC,CAAYN,GAEjC,OAAIC,GACFF,EAAQiB,2BACNC,EAAuBZ,EAAcN,GAEhC,CAAEF,SAAQO,OAAQ,KAGpB,CAAEP,OAAQ,CAAA,EAAIO,OAAQc,EAAab,EAAcN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typanion.module.js","sources":["../src/typanion.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"typanion.module.js","sources":["../src/typanion.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const fieldIndex = error.indexOf(':');\n\n const field = error.slice(1, fieldIndex);\n const message = error.slice(fieldIndex + 1).trim();\n\n acc[field] = {\n message,\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestErrors(parsedErrors, options) };\n };\n"],"names":["typanionResolver","validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","reduce","acc","error","fieldIndex","indexOf","field","slice","message","trim","parseErrors","shouldUseNativeValidation","validateFieldsNatively","toNestErrors"],"mappings":"+EAIA,IAeaA,EACX,SAACC,EAAWC,eAAgB,IAAhBA,IAAAA,EAAmB,CAAE,GAChCC,SAAAA,EAAQC,EAAGC,GACV,IAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,GACA,CACEC,OAAQJ,GAEVJ,IAGES,EA7BU,SAACD,EAAkBC,GACrC,YADqCA,IAAAA,IAAAA,EAA4B,CAAE,GAC5DD,EAAOE,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAaD,EAAME,QAAQ,KAE3BC,EAAQH,EAAMI,MAAM,EAAGH,GACvBI,EAAUL,EAAMI,MAAMH,EAAa,GAAGK,OAM5C,OAJAP,EAAII,GAAS,CACXE,QAAAA,GAGKN,CACT,EAAGF,EACL,CAgByBU,CAAYf,GAEjC,OAAIC,GACFF,EAAQiB,2BACNC,EAAuBZ,EAAcN,GAEhC,CAAEF,OAAAA,EAAQO,OAAQ,CAAA,IAGpB,CAAEP,OAAQ,GAAIO,OAAQc,EAAab,EAAcN,GAC1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typanion.umd.js","sources":["../src/typanion.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"typanion.umd.js","sources":["../src/typanion.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport type { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {\n return errors.reduce((acc, error) => {\n const fieldIndex = error.indexOf(':');\n\n const field = error.slice(1, fieldIndex);\n const message = error.slice(fieldIndex + 1).trim();\n\n acc[field] = {\n message,\n } as FieldError;\n\n return acc;\n }, parsedErrors);\n};\n\nexport const typanionResolver: Resolver =\n (validator, validatorOptions = {}) =>\n (values, _, options) => {\n const rawErrors: string[] = [];\n const isValid = validator(\n values,\n Object.assign(\n {},\n {\n errors: rawErrors,\n },\n validatorOptions,\n ),\n );\n const parsedErrors = parseErrors(rawErrors);\n\n if (isValid) {\n options.shouldUseNativeValidation &&\n validateFieldsNatively(parsedErrors, options);\n\n return { values, errors: {} };\n }\n\n return { values: {}, errors: toNestErrors(parsedErrors, options) };\n };\n"],"names":["validator","validatorOptions","values","_","options","rawErrors","isValid","Object","assign","errors","parsedErrors","reduce","acc","error","fieldIndex","indexOf","field","slice","message","trim","parseErrors","shouldUseNativeValidation","validateFieldsNatively","toNestErrors"],"mappings":"iVAoBE,SAACA,EAAWC,eAAgB,IAAhBA,IAAAA,EAAmB,CAAE,GAChCC,SAAAA,EAAQC,EAAGC,GACV,IAAMC,EAAsB,GACtBC,EAAUN,EACdE,EACAK,OAAOC,OACL,GACA,CACEC,OAAQJ,GAEVJ,IAGES,EA7BU,SAACD,EAAkBC,GACrC,YADqCA,IAAAA,IAAAA,EAA4B,CAAE,GAC5DD,EAAOE,OAAO,SAACC,EAAKC,GACzB,IAAMC,EAAaD,EAAME,QAAQ,KAE3BC,EAAQH,EAAMI,MAAM,EAAGH,GACvBI,EAAUL,EAAMI,MAAMH,EAAa,GAAGK,OAM5C,OAJAP,EAAII,GAAS,CACXE,QAAAA,GAGKN,CACT,EAAGF,EACL,CAgByBU,CAAYf,GAEjC,OAAIC,GACFF,EAAQiB,2BACNC,yBAAuBZ,EAAcN,GAEhC,CAAEF,OAAAA,EAAQO,OAAQ,CAAA,IAGpB,CAAEP,OAAQ,GAAIO,OAAQc,EAAYA,aAACb,EAAcN,GAC1D,CAAC"}
|
package/typanion/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
|
|
2
|
-
import {
|
|
2
|
+
import { AnyStrictValidator, ValidationState } from 'typanion';
|
|
3
3
|
type ValidateOptions = Pick<ValidationState, 'coercions' | 'coercion'>;
|
|
4
4
|
type RHFResolver = <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
|
|
5
5
|
export type Resolver = <UnknownValidator extends AnyStrictValidator>(validator: UnknownValidator, validatorOptions?: ValidateOptions, resolverOptions?: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import * as t from 'typanion';
|
|
6
6
|
import { typanionResolver } from '..';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { render, screen } from '@testing-library/react';
|
|
3
2
|
import user from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
4
|
import { useForm } from 'react-hook-form';
|
|
5
5
|
import * as t from 'typanion';
|
|
6
6
|
import { typanionResolver } from '..';
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Field, InternalFieldName } from 'react-hook-form';
|
|
2
2
|
import * as t from 'typanion';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
4
|
export const isSchema = t.isObject({
|
|
7
5
|
username: t.applyCascade(t.isString(), [
|
|
8
6
|
t.matchesRegExp(/^\w+$/),
|
|
@@ -13,24 +11,31 @@ export const isSchema = t.isObject({
|
|
|
13
11
|
t.matchesRegExp(new RegExp('.*[A-Z].*')), // one uppercase character
|
|
14
12
|
t.matchesRegExp(new RegExp('.*[a-z].*')), // one lowercase character
|
|
15
13
|
t.matchesRegExp(new RegExp('.*\\d.*')), // one number
|
|
16
|
-
t.matchesRegExp(
|
|
14
|
+
t.matchesRegExp(
|
|
15
|
+
new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
|
|
16
|
+
), // one special character
|
|
17
17
|
t.hasMinLength(8), // Must be at least 8 characters in length
|
|
18
18
|
]),
|
|
19
19
|
repeatPassword: t.applyCascade(t.isString(), [
|
|
20
20
|
t.matchesRegExp(new RegExp('.*[A-Z].*')), // one uppercase character
|
|
21
21
|
t.matchesRegExp(new RegExp('.*[a-z].*')), // one lowercase character
|
|
22
22
|
t.matchesRegExp(new RegExp('.*\\d.*')), // one number
|
|
23
|
-
t.matchesRegExp(
|
|
23
|
+
t.matchesRegExp(
|
|
24
|
+
new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'),
|
|
25
|
+
), // one special character
|
|
24
26
|
t.hasMinLength(8), // Must be at least 8 characters in length
|
|
25
27
|
]),
|
|
26
28
|
accessToken: t.isString(),
|
|
27
|
-
birthYear: t.applyCascade(t.isNumber(), [
|
|
29
|
+
birthYear: t.applyCascade(t.isNumber(), [
|
|
30
|
+
t.isInteger(),
|
|
31
|
+
t.isInInclusiveRange(1900, 2013),
|
|
32
|
+
]),
|
|
28
33
|
email: t.applyCascade(t.isString(), [t.matchesRegExp(/^\S+@\S+$/)]),
|
|
29
|
-
tags: t.isArray(t.isString()),
|
|
34
|
+
tags: t.isArray(t.isString()),
|
|
30
35
|
enabled: t.isBoolean(),
|
|
31
36
|
like: t.isObject({
|
|
32
37
|
id: t.applyCascade(t.isNumber(), [t.isInteger(), t.isPositive()]),
|
|
33
|
-
name: t.applyCascade(t.isString(), [t.hasMinLength(4)])
|
|
38
|
+
name: t.applyCascade(t.isString(), [t.hasMinLength(4)]),
|
|
34
39
|
}),
|
|
35
40
|
});
|
|
36
41
|
|
|
@@ -8,11 +8,11 @@ exports[`typanionResolver > should return a single error from typanionResolver w
|
|
|
8
8
|
"ref": undefined,
|
|
9
9
|
},
|
|
10
10
|
"birthYear": {
|
|
11
|
-
"message": "Expected a number (got
|
|
11
|
+
"message": "Expected a number (got "birthYear")",
|
|
12
12
|
"ref": undefined,
|
|
13
13
|
},
|
|
14
14
|
"email": {
|
|
15
|
-
"message": "Expected to match the pattern
|
|
15
|
+
"message": "Expected to match the pattern /^\\S+@\\S+$/ (got an empty string)",
|
|
16
16
|
"ref": {
|
|
17
17
|
"name": "email",
|
|
18
18
|
},
|
|
@@ -23,7 +23,7 @@ exports[`typanionResolver > should return a single error from typanionResolver w
|
|
|
23
23
|
},
|
|
24
24
|
"like": {
|
|
25
25
|
"id": {
|
|
26
|
-
"message": "Expected a number (got
|
|
26
|
+
"message": "Expected a number (got "z")",
|
|
27
27
|
"ref": undefined,
|
|
28
28
|
},
|
|
29
29
|
"name": {
|
|
@@ -32,7 +32,7 @@ exports[`typanionResolver > should return a single error from typanionResolver w
|
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
34
|
"password": {
|
|
35
|
-
"message": "Expected to match the pattern /.*[A-Z].*/ (got
|
|
35
|
+
"message": "Expected to match the pattern /.*[A-Z].*/ (got "___")",
|
|
36
36
|
"ref": {
|
|
37
37
|
"name": "password",
|
|
38
38
|
},
|
package/typanion/src/typanion.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FieldError, FieldErrors } from 'react-hook-form';
|
|
2
1
|
import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
|
|
2
|
+
import type { FieldError, FieldErrors } from 'react-hook-form';
|
|
3
3
|
import type { Resolver } from './types';
|
|
4
4
|
|
|
5
5
|
const parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {
|
package/typanion/src/types.ts
CHANGED
|
@@ -3,9 +3,9 @@ import type {
|
|
|
3
3
|
ResolverOptions,
|
|
4
4
|
ResolverResult,
|
|
5
5
|
} from 'react-hook-form';
|
|
6
|
-
import {
|
|
6
|
+
import { AnyStrictValidator, ValidationState } from 'typanion';
|
|
7
7
|
|
|
8
|
-
type ValidateOptions = Pick<ValidationState, 'coercions' | 'coercion'
|
|
8
|
+
type ValidateOptions = Pick<ValidationState, 'coercions' | 'coercion'>;
|
|
9
9
|
|
|
10
10
|
type RHFResolver = <TFieldValues extends FieldValues, TContext>(
|
|
11
11
|
values: TFieldValues,
|
|
@@ -16,5 +16,5 @@ type RHFResolver = <TFieldValues extends FieldValues, TContext>(
|
|
|
16
16
|
export type Resolver = <UnknownValidator extends AnyStrictValidator>(
|
|
17
17
|
validator: UnknownValidator,
|
|
18
18
|
validatorOptions?: ValidateOptions,
|
|
19
|
-
resolverOptions?: { mode?: 'async' | 'sync'
|
|
20
|
-
)=> RHFResolver
|
|
19
|
+
resolverOptions?: { mode?: 'async' | 'sync'; rawValues?: boolean },
|
|
20
|
+
) => RHFResolver;
|
package/typebox/dist/typebox.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("
|
|
1
|
+
var e=require("@hookform/resolvers"),r=require("@sinclair/typebox/compiler"),s=require("@sinclair/typebox/value"),o=require("react-hook-form"),a=function(e,r){for(var s={};e.length;){var a=e[0],t=a.type,i=a.message,l=a.path.substring(1).replace(/\//g,".");if(s[l]||(s[l]={message:i,type:""+t}),r){var n=s[l].types,u=n&&n[""+t];s[l]=o.appendErrors(l,r,s,""+t,u?[].concat(u,a.message):a.message)}e.shift()}return s};exports.typeboxResolver=function(o){return function(t,i,l){try{var n=Array.from(o instanceof r.TypeCheck?o.Errors(t):s.Value.Errors(o,t));return l.shouldUseNativeValidation&&e.validateFieldsNatively({},l),Promise.resolve(n.length?{values:{},errors:e.toNestErrors(a(n,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:t})}catch(e){return Promise.reject(e)}}};
|
|
2
2
|
//# sourceMappingURL=typebox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typebox.js","sources":["../src/typebox.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"typebox.js","sources":["../src/typebox.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { TypeCheck } from '@sinclair/typebox/compiler';\nimport { Value, type ValueError } from '@sinclair/typebox/value';\nimport { FieldError, FieldErrors, appendErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (\n _errors: ValueError[],\n validateAllFieldCriteria: boolean,\n) => {\n const errors: Record<string, FieldError> = {};\n for (; _errors.length; ) {\n const error = _errors[0];\n const { type, message, path } = error;\n const _path = path.substring(1).replace(/\\//g, '.');\n\n if (!errors[_path]) {\n errors[_path] = { message, type: '' + type };\n }\n\n if (validateAllFieldCriteria) {\n const types = errors[_path].types;\n const messages = types && types['' + type];\n\n errors[_path] = appendErrors(\n _path,\n validateAllFieldCriteria,\n errors,\n '' + type,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message,\n ) as FieldError;\n }\n\n _errors.shift();\n }\n\n return errors;\n};\n\nexport const typeboxResolver: Resolver =\n (schema) => async (values, _, options) => {\n const errors = Array.from(\n schema instanceof TypeCheck\n ? schema.Errors(values)\n : Value.Errors(schema, values),\n );\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n if (!errors.length) {\n return {\n errors: {} as FieldErrors,\n values,\n };\n }\n\n return {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n errors,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","_errors","validateAllFieldCriteria","errors","length","error","type","message","_path","path","substring","replace","types","messages","appendErrors","concat","shift","schema","values","_","options","Array","from","TypeCheck","Errors","Value","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","toNestErrors","criteriaMode","e","reject"],"mappings":"+IAMMA,EAAmB,SACvBC,EACAC,GAGA,IADA,IAAMC,EAAqC,GACpCF,EAAQG,QAAU,CACvB,IAAMC,EAAQJ,EAAQ,GACdK,EAAwBD,EAAxBC,KAAMC,EAAkBF,EAAlBE,QACRC,EAD0BH,EAATI,KACJC,UAAU,GAAGC,QAAQ,MAAO,KAM/C,GAJKR,EAAOK,KACVL,EAAOK,GAAS,CAAED,QAAAA,EAASD,KAAM,GAAKA,IAGpCJ,EAA0B,CAC5B,IAAMU,EAAQT,EAAOK,GAAOI,MACtBC,EAAWD,GAASA,EAAM,GAAKN,GAErCH,EAAOK,GAASM,EAAAA,aACdN,EACAN,EACAC,EACA,GAAKG,EACLO,EACK,GAAgBE,OAAOF,EAAsBR,EAAME,SACpDF,EAAME,QAEd,CAEAN,EAAQe,OACV,CAEA,OAAOb,CACT,0BAGE,SAACc,GAAkBC,OAAAA,SAAAA,EAAQC,EAAGC,GAAO,IACnC,IAAMjB,EAASkB,MAAMC,KACnBL,aAAkBM,EAASA,UACvBN,EAAOO,OAAON,GACdO,EAAKA,MAACD,OAAOP,EAAQC,IAK3B,OAFAE,EAAQM,2BAA6BC,EAAsBA,uBAAC,GAAIP,GAShEQ,QAAAC,QAPK1B,EAAOC,OAOL,CACLc,OAAQ,CAAA,EACRf,OAAQ2B,EAAYA,aAClB9B,EACEG,GACCiB,EAAQM,2BAAsD,QAAzBN,EAAQW,cAEhDX,IAbK,CACLjB,OAAQ,CAAA,EACRe,OAAAA,GAcN,CAAC,MAAAc,GAAA,OAAAJ,QAAAK,OAAAD,EAAA,CAAA,CAAA"}
|
package/typebox/dist/typebox.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{TypeCheck as o}from"@sinclair/typebox/compiler";import{Value as t}from"@sinclair/typebox/value";import{appendErrors as s}from"react-hook-form";var a=function(r,e){for(var o={};r.length;){var t=r[0],a=t.type,i=t.message,n=t.path.substring(1).replace(/\//g,".");if(o[n]||(o[n]={message:i,type:""+a}),e){var m=o[n].types,l=m&&m[""+a];o[n]=s(n,e,o,""+a,l?[].concat(l,t.message):t.message)}r.shift()}return o},i=function(s){return function(i,n,m){try{var l=Array.from(s instanceof o?s.Errors(i):t.Errors(s,i));return m.shouldUseNativeValidation&&r({},m),Promise.resolve(l.length?{values:{},errors:e(a(l,!m.shouldUseNativeValidation&&"all"===m.criteriaMode),m)}:{errors:{},values:i})}catch(r){return Promise.reject(r)}}};export{i as typeboxResolver};
|
|
2
2
|
//# sourceMappingURL=typebox.module.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{validateFieldsNatively as r,toNestErrors as o}from"@hookform/resolvers";import{TypeCheck as e}from"@sinclair/typebox/compiler";import{Value as s}from"@sinclair/typebox/value";import{appendErrors as t}from"react-hook-form";const a=(r,o)=>{const e={};for(;r.length;){const s=r[0],{type:a,message:i,path:n}=s,l=n.substring(1).replace(/\//g,".");if(e[l]||(e[l]={message:i,type:""+a}),o){const r=e[l].types,i=r&&r[""+a];e[l]=t(l,o,e,""+a,i?[].concat(i,s.message):s.message)}r.shift()}return e},i=t=>async(i,n,l)=>{const m=Array.from(t instanceof e?t.Errors(i):s.Errors(t,i));return l.shouldUseNativeValidation&&r({},l),m.length?{values:{},errors:o(a(m,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}:{errors:{},values:i}};export{i as typeboxResolver};
|
|
2
2
|
//# sourceMappingURL=typebox.modern.mjs.map
|