feat!: use zod v4 (#10922)

* feat: zod 4

* feat: zod v3, but v4

feat: validation error class

Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>

* chore: bump

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
This commit is contained in:
Almeida
2025-07-03 01:02:45 +01:00
committed by GitHub
parent 4dbeed933b
commit a5bd4cfe73
20 changed files with 183 additions and 199 deletions

View File

@@ -1,5 +1,5 @@
import type { z } from 'zod';
import { fromZodError } from 'zod-validation-error';
import type { z } from 'zod/v4';
import { ValidationError } from './ValidationError.js';
let validationEnabled = true;
@@ -35,21 +35,23 @@ export function isValidationEnabled() {
* @param value - The value to parse
* @param validationOverride - Force validation to run/not run regardless of your global preference
* @returns The result from parsing
* @throws {@link ValidationError}
* Throws if the value does not pass validation, if enabled.
* @internal
*/
export function validate<Validator extends z.ZodTypeAny>(
export function validate<Validator extends z.ZodType>(
validator: Validator,
value: unknown,
validationOverride?: boolean,
): z.output<Validator> {
if (validationOverride === false || !isValidationEnabled()) {
return value;
if (validationOverride === false || (validationOverride === undefined && !isValidationEnabled())) {
return value as z.output<Validator>;
}
const result = validator.safeParse(value);
if (!result.success) {
throw fromZodError(result.error);
throw new ValidationError(result.error);
}
return result.data;