diff --git a/module/package-lock.json b/module/package-lock.json index 1495dbf6..fa18b462 100644 --- a/module/package-lock.json +++ b/module/package-lock.json @@ -68,13 +68,13 @@ "vite-plugin-static-copy": "0.16.0", "vite-plugin-turbosnap": "1.0.3", "wait-on": "7.0.1", - "zod": "3.21.4" + "zod": "^4.1.5" }, "peerDependencies": { "date-fns": "2.x", "react": "18.x", "react-dom": "18.x", - "zod": "3.*" + "zod": "^3.21.4 || ^4.0.0" } }, "node_modules/@adobe/css-tools": { @@ -23511,10 +23511,11 @@ } }, "node_modules/zod": { - "version": "3.21.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz", - "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==", + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.5.tgz", + "integrity": "sha512-rcUUZqlLJgBC33IT3PNMgsCq6TzLQEG/Ei/KTCU0PedSWRMAXoOUN+4t/0H+Q8bdnLPdqUYnvboJT0bn/229qg==", "dev": true, + "license": "MIT", "funding": { "url": "https://github.com/sponsors/colinhacks" } @@ -39534,9 +39535,9 @@ } }, "zod": { - "version": "3.21.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz", - "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==", + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.5.tgz", + "integrity": "sha512-rcUUZqlLJgBC33IT3PNMgsCq6TzLQEG/Ei/KTCU0PedSWRMAXoOUN+4t/0H+Q8bdnLPdqUYnvboJT0bn/229qg==", "dev": true } } diff --git a/module/package.json b/module/package.json index 4cce1c29..cea37a4e 100644 --- a/module/package.json +++ b/module/package.json @@ -21,7 +21,7 @@ "date-fns": "2.x", "react": "18.x", "react-dom": "18.x", - "zod": "3.*" + "zod": "^3.21.4 || ^4.0.0" }, "files": [ "dist" @@ -100,7 +100,7 @@ "vite-plugin-static-copy": "0.16.0", "vite-plugin-turbosnap": "1.0.3", "wait-on": "7.0.1", - "zod": "3.21.4" + "zod": "^4.1.5" }, "dependencies": { "@radix-ui/react-checkbox": "1.0.4", diff --git a/module/src/form/hooks/useForm.ts b/module/src/form/hooks/useForm.ts index 067398dd..07346699 100644 --- a/module/src/form/hooks/useForm.ts +++ b/module/src/form/hooks/useForm.ts @@ -118,7 +118,7 @@ export function useForm( let errors: IValidationError[] = []; if (!results.success) { - errors = getMyZodErrors(results.error.errors, keyChainString); + errors = getMyZodErrors(results.error.issues, keyChainString); if (errors.length && !silent) { clientValidationDispatcher({ type: 'add-validation', errors }); diff --git a/module/src/form/types.ts b/module/src/form/types.ts index fb87839f..e5fd8f56 100644 --- a/module/src/form/types.ts +++ b/module/src/form/types.ts @@ -8,10 +8,9 @@ import { type ZodBigInt, type ZodBoolean, type ZodDate, - type ZodEffects, + type ZodTransform, type ZodEnum, type ZodLiteral, - type ZodNativeEnum, type ZodNullable, type ZodNumber, type ZodObject, @@ -498,12 +497,7 @@ export interface IArrayOfZod { /** A function which defines the validation to apply to the array itself (e.g. `opts: arr => arr.min(1).max(5)`) */ opts?: ( arr: ZodArray - ) => - | ZodArray - | ZodNullable - | ZodOptional - | ZodOptional> - | ZodEffects; + ) => ZodTypeAny; } /** @@ -516,24 +510,27 @@ export interface IObjectOfZod { /** A function which defines the validation to apply to the object itself (e.g. `opts: ob => ob.required()`) */ opts?: ( ob: ZodObject - ) => - | ZodObject - | ZodNullable - | ZodOptional - | ZodOptional> - | ZodEffects; + ) => ZodTypeAny; } -type WithZodAdditions = +type WithZodAdditions = | T | ZodLiteral | ZodOptional | ZodNullable | ZodOptional> - | ZodEffects - | ZodUnion<[WithZodAdditions, ...ZodTypeAny[]]> - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- any required for zod native enum - | ZodNativeEnum + | ZodTransform + | ZodUnion<[T, ...ZodTypeAny[]]> + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- any required for zod enum + | ZodEnum; + +type WithZodAdditionsDate = + | T + | ZodOptional + | ZodNullable + | ZodOptional> + | ZodTransform + | ZodUnion<[T, ...ZodTypeAny[]]> // eslint-disable-next-line @typescript-eslint/no-explicit-any -- any required for zod enum | ZodEnum; @@ -548,7 +545,7 @@ export type ToZod = { bigint: ZodNullOrUndefined>; number: ZodNullOrUndefined>; boolean: ZodNullOrUndefined>; - date: ZodNullOrUndefined>; + date: ZodNullOrUndefined>; object: IObjectOfZod<{ [TKey in keyof TProp]: ToZod }>; rest: never; }[StringType]; diff --git a/module/src/form/utils/validation.ts b/module/src/form/utils/validation.ts index 8346be18..4dcefe03 100644 --- a/module/src/form/utils/validation.ts +++ b/module/src/form/utils/validation.ts @@ -123,9 +123,9 @@ export function zodFromValidationSchema(schema: IRootValidationSchema { return errors - .filter(e => (keyChainString ? isMyKeyChainItem(keyStringFromKeyChain(e.path, 'dots'), keyChainString) : true)) + .filter(e => (keyChainString ? isMyKeyChainItem(keyStringFromKeyChain(e.path as KeyChain, 'dots'), keyChainString) : true)) .map(e => ({ - key: keyStringFromKeyChain(e.path, 'dots'), + key: keyStringFromKeyChain(e.path as KeyChain, 'dots'), message: e.message, })); };