zod-error
Version:
Utilities to format and customize Zod error messages
84 lines (83 loc) • 2.27 kB
TypeScript
import { z } from 'zod';
export declare type EnableCode = {
enabled: true;
label?: string | null;
transform?: (params: TransformComponentParams) => string;
};
export declare type DisableCode = {
enabled: false;
};
export declare type CodeOptions = EnableCode | DisableCode;
export declare type EnablePathOptions = {
enabled: true;
label?: string | null;
transform?: (params: TransformComponentParams) => string;
};
export declare type DisablePath = {
enabled: false;
};
export declare type ObjectNotation = EnablePathOptions & {
type: 'objectNotation';
arraySquareBrackets?: boolean;
};
export declare type ZodPathArray = EnablePathOptions & {
type: 'zodPathArray';
};
export declare type Breadcrumbs = EnablePathOptions & {
type: 'breadcrumbs';
delimeter?: string;
arraySquareBrackets?: boolean;
};
export declare type PathOptions = ObjectNotation | ZodPathArray | Breadcrumbs | DisablePath;
export declare type EnableMessage = {
enabled: true;
label?: string | null;
transform?: (params: TransformComponentParams) => string;
};
export declare type DisableMessage = {
enabled: false;
};
export declare type MessageOptions = EnableMessage | DisableMessage;
export declare type DelimiterOptions = {
error?: string;
component?: string;
};
export declare type TransformComponentParams = {
component: string;
label: string;
value: string;
};
export declare type TransformErrorParams = {
codeComponent: string;
errorMessage: string;
index: number;
issue: z.ZodIssue;
messageComponent: string;
pathComponent: string;
};
export declare type SafeParseSuccess<T> = {
success: true;
data: T;
};
export declare type SafeParseFail = {
success: false;
error: {
message: string;
};
};
export declare type SafeParseReturnType<T> = SafeParseSuccess<T> | SafeParseFail;
export declare type Labels = {
code: string;
path: string;
message: string;
};
export interface ErrorMessageOptions {
code?: CodeOptions;
delimiter?: DelimiterOptions;
maxErrors?: number;
message?: MessageOptions;
path?: PathOptions;
prefix?: string;
suffix?: string;
transform?: (params: TransformErrorParams) => string;
}