Files
reverse-engineering-anything/src/domain/zodCollectionSteps.ts
T
morluto 84ee604c6d perf(ci): optimize semantic graph construction, directory containment checks, gate checkouts, and boundary stragglers (#11851)
* perf(javascript): avoid redundant semantic graph validation and node hashing

* perf(resources): deduplicate directory containment checks and root lstat calls

* perf(ci): trace script fixture modules, sparse-checkout gate jobs, and parallelize built doc checks

* perf(tests): memoize live MCP doctor expectations and reuse CLI and verifier compilation

* fix(ci): enforce containment after skipped entries, validate interned contexts, and supervise doc and verifier teardowns

* fix(docs): decode buffered check output once to preserve multi-byte UTF-8
2026-11-17 14:57:30 -05:00

39 lines
1.2 KiB
TypeScript

import { z } from "zod";
/**
* An array schema's own constraints, such as a minimum length, without its
* element schema. Pair it with {@link parseElementSteps} to validate a large
* collection in cooperative steps.
*/
export const arrayContainerSchema = (
array: z.ZodArray<z.ZodType>,
): z.ZodType<unknown[]> => array.clone({ ...array.def, element: z.unknown() });
/** Elements validated between yields, in the issues and paths a whole-array parse reports. */
export function* parseElementSteps<Element extends z.ZodType>(
element: Element,
values: readonly unknown[],
path: readonly PropertyKey[],
issues: z.core.$ZodIssue[],
isPrevalidated?: (value: unknown) => value is z.output<Element>,
): Generator<void, z.output<Element>[]> {
const parsed: z.output<Element>[] = [];
for (const [index, value] of values.entries()) {
if (index % 64 === 0) yield;
if (isPrevalidated?.(value) === true) {
parsed.push(value);
continue;
}
const result = element.safeParse(value);
if (result.success) parsed.push(result.data);
else
issues.push(
...result.error.issues.map((issue) => ({
...issue,
path: [...path, index, ...issue.path],
})),
);
}
return parsed;
}