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

Function safeParseAsync

packages/zod/src/v3/types.ts:298–318  ·  view source on GitHub ↗
(
    data: unknown,
    params?: util.InexactPartial<ParseParams>
  )

Source from the content-addressed store, hash-verified

296 }
297
298 async safeParseAsync(
299 data: unknown,
300 params?: util.InexactPartial<ParseParams>
301 ): Promise<SafeParseReturnType<Input, Output>> {
302 const ctx: ParseContext = {
303 common: {
304 issues: [],
305 contextualErrorMap: params?.errorMap,
306 async: true,
307 },
308 path: params?.path || [],
309 schemaErrorMap: this._def.errorMap,
310 parent: null,
311 data,
312 parsedType: getParsedType(data),
313 };
314
315 const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
316 const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
317 return handleResult(ctx, result);
318 }
319
320 /** Alias of safeParseAsync */
321 spa = this.safeParseAsync;

Callers 1

schemas.tsFile · 0.85

Calls 4

isAsyncFunction · 0.85
handleResultFunction · 0.85
getParsedTypeFunction · 0.50
_parseMethod · 0.45

Tested by

no test coverage detected