MCPcopy
hub / github.com/colinhacks/zod / processCreateParams

Function processCreateParams

packages/zod/src/v3/types.ts:123–143  ·  view source on GitHub ↗
(params: RawCreateParams)

Source from the content-addressed store, hash-verified

121 description?: string | undefined;
122};
123function processCreateParams(params: RawCreateParams): ProcessedCreateParams {
124 if (!params) return {};
125 const { errorMap, invalid_type_error, required_error, description } = params;
126 if (errorMap && (invalid_type_error || required_error)) {
127 throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
128 }
129 if (errorMap) return { errorMap: errorMap, description };
130 const customMap: ZodErrorMap = (iss, ctx) => {
131 const { message } = params;
132
133 if (iss.code === "invalid_enum_value") {
134 return { message: message ?? ctx.defaultError };
135 }
136 if (typeof ctx.data === "undefined") {
137 return { message: message ?? required_error ?? ctx.defaultError };
138 }
139 if (iss.code !== "invalid_type") return { message: ctx.defaultError };
140 return { message: message ?? invalid_type_error ?? ctx.defaultError };
141 };
142 return { errorMap: customMap, description };
143}
144
145export type SafeParseSuccess<Output> = {
146 success: true;

Callers 15

transformFunction · 0.85
defaultFunction · 0.85
brandFunction · 0.85
catchFunction · 0.85
ZodStringClass · 0.85
ZodNumberClass · 0.85
ZodBigIntClass · 0.85
ZodBooleanClass · 0.85
ZodDateClass · 0.85
ZodSymbolClass · 0.85
ZodUndefinedClass · 0.85
ZodNullClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected