MCPcopy
hub / github.com/colinhacks/zod / "~validate"

Function "~validate"

packages/zod/src/v3/types.ts:247–290  ·  view source on GitHub ↗
(data: unknown)

Source from the content-addressed store, hash-verified

245 }
246
247 "~validate"(data: unknown): StandardSchemaV1.Result<Output> | Promise<StandardSchemaV1.Result<Output>> {
248 const ctx: ParseContext = {
249 common: {
250 issues: [],
251 async: !!(this["~standard"] as any).async,
252 },
253 path: [],
254 schemaErrorMap: this._def.errorMap,
255 parent: null,
256 data,
257 parsedType: getParsedType(data),
258 };
259
260 if (!(this["~standard"] as any).async) {
261 try {
262 const result = this._parseSync({ data, path: [], parent: ctx });
263 return isValid(result)
264 ? {
265 value: result.value,
266 }
267 : {
268 issues: ctx.common.issues,
269 };
270 } catch (err: any) {
271 if ((err as Error)?.message?.toLowerCase()?.includes("encountered")) {
272 (this["~standard"] as any).async = true;
273 }
274 (ctx as any).common = {
275 issues: [],
276 async: true,
277 };
278 }
279 }
280
281 return this._parseAsync({ data, path: [], parent: ctx }).then((result) =>
282 isValid(result)
283 ? {
284 value: result.value,
285 }
286 : {
287 issues: ctx.common.issues,
288 }
289 );
290 }
291
292 async parseAsync(data: unknown, params?: util.InexactPartial<ParseParams>): Promise<Output> {
293 const result = await this.safeParseAsync(data, params);

Callers

nothing calls this directly

Calls 4

isValidFunction · 0.85
includesMethod · 0.65
toLowerCaseMethod · 0.65
getParsedTypeFunction · 0.50

Tested by

no test coverage detected