mirror of
https://github.com/morluto/rea.git
synced 2026-10-31 20:06:14 +00:00
Move shared request parsing into its application owner, migrate all consumers, and remove six duplicated admission blocks while preserving cancellation and validation policy. Keep operator-selected JavaScript paths in verifier parent Evidence while retaining canonical comparison guards. Validated with 204 passing tests, 3 Linux-x64-only skips, typecheck, lint, and test discovery.
25 lines
908 B
TypeScript
25 lines
908 B
TypeScript
import type { z } from "zod";
|
|
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
|
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
|
import { err, ok, type Result } from "../domain/result.js";
|
|
|
|
/** Validate an application request, honoring cancellation before admission when supplied. */
|
|
export const parseAnalysisInput = <T>(
|
|
operation: string,
|
|
rawInput: unknown,
|
|
schema: z.ZodType<T>,
|
|
signal?: AbortSignal,
|
|
): Result<T, AnalysisError> => {
|
|
if (signal?.aborted)
|
|
return err(new AnalysisCancelledError(operation, { cause: signal.reason }));
|
|
const input = schema.safeParse(rawInput);
|
|
if (!input.success)
|
|
return err(
|
|
analysisInputErrorFromIssues(operation, input.error.issues, rawInput, {
|
|
cause: input.error,
|
|
}),
|
|
);
|
|
return ok(input.data);
|
|
};
|