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

Function runChecks

packages/zod/src/v4/core/schemas.ts:218–260  ·  view source on GitHub ↗
(
      payload: ParsePayload,
      checks: checks.$ZodCheck<never>[],
      ctx?: ParseContextInternal | undefined
    )

Source from the content-addressed store, hash-verified

216 });
217 } else {
218 const runChecks = (
219 payload: ParsePayload,
220 checks: checks.$ZodCheck<never>[],
221 ctx?: ParseContextInternal | undefined
222 ): util.MaybeAsync<ParsePayload> => {
223 let isAborted = util.aborted(payload);
224
225 let asyncResult!: Promise<unknown> | undefined;
226 for (const ch of checks) {
227 if (ch._zod.def.when) {
228 if (util.explicitlyAborted(payload)) continue;
229 const shouldRun = ch._zod.def.when(payload);
230 if (!shouldRun) continue;
231 } else if (isAborted) {
232 continue;
233 }
234 const currLen = payload.issues.length;
235 const _ = ch._zod.check(payload as any) as any as ParsePayload;
236
237 if (_ instanceof Promise && ctx?.async === false) {
238 throw new core.$ZodAsyncError();
239 }
240 if (asyncResult || _ instanceof Promise) {
241 asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
242 await _;
243 const nextLen = payload.issues.length;
244 if (nextLen === currLen) return;
245 if (!isAborted) isAborted = util.aborted(payload, currLen);
246 });
247 } else {
248 const nextLen = payload.issues.length;
249 if (nextLen === currLen) continue;
250 if (!isAborted) isAborted = util.aborted(payload, currLen);
251 }
252 }
253
254 if (asyncResult) {
255 return asyncResult.then(() => {
256 return payload;
257 });
258 }
259 return payload;
260 };
261
262 const handleCanaryResult = (canary: ParsePayload, payload: ParsePayload, ctx: ParseContextInternal) => {
263 // abort if the canary is aborted

Callers 2

handleCanaryResultFunction · 0.85
schemas.tsFile · 0.85

Calls 1

checkMethod · 0.65

Tested by

no test coverage detected