import { CastableBase, ReadonlyArray, ReadonlyPath, type JsonArray, type JsonObject, type array, type merge, type propwiseXor, type show } from "@ark/util"; import type { Prerequisite, errorContext } from "../kinds.ts"; import type { NodeKind } from "./implement.ts"; import type { StandardSchemaV1 } from "./standardSchema.ts"; import type { Traversal } from "./traversal.ts"; import { arkKind } from "./utils.ts"; export type ArkErrorResult = ArkError | ArkErrors; export declare class ArkError extends CastableBase> { readonly [arkKind] = "error"; path: ReadonlyPath; data: Prerequisite; private nodeConfig; protected input: ArkErrorContextInput; protected ctx: Traversal; constructor(input: ArkErrorContextInput, ctx: Traversal); transform(f: (input: ArkErrorContextInput) => ArkErrorContextInput): ArkError; hasCode(code: code): this is ArkError; get propString(): string; get expected(): string; get actual(): string; get problem(): string; get message(): string; get flat(): ArkError[]; toJSON(): JsonObject; toString(): string; throw(): never; } export declare namespace ArkErrors { type Handler = (errors: ArkErrors) => returns; } /** * A ReadonlyArray of `ArkError`s returned by a Type on invalid input. * * Subsequent errors added at an existing path are merged into an * ArkError intersection. */ export declare class ArkErrors extends ReadonlyArray implements StandardSchemaV1.FailureResult { readonly [arkKind] = "errors"; protected ctx: Traversal; constructor(ctx: Traversal); /** * Errors by a pathString representing their location. */ byPath: Record; /** * {@link byPath} flattened so that each value is an array of ArkError instances at that path. * * ✅ Since "intersection" errors will be flattened to their constituent `.errors`, * they will never be directly present in this representation. */ get flatByPath(): Record; /** * {@link byPath} flattened so that each value is an array of problem strings at that path. */ get flatProblemsByPath(): Record; /** * All pathStrings at which errors are present mapped to the errors occuring * at that path or any nested path within it. */ byAncestorPath: Record; count: number; private mutable; /** * Throw a TraversalError based on these errors. */ throw(): never; /** * Converts ArkErrors to TraversalError, a subclass of `Error` suitable for throwing with nice * formatting. */ toTraversalError(): TraversalError; /** * Append an ArkError to this array, ignoring duplicates. */ add(error: ArkError): void; transform(f: (e: ArkError) => ArkError): ArkErrors; /** * Add all errors from an ArkErrors instance, ignoring duplicates and * prefixing their paths with that of the current Traversal. */ merge(errors: ArkErrors): void; /** * @internal */ affectsPath(path: ReadonlyPath): boolean; /** * A human-readable summary of all errors. */ get summary(): string; /** * Alias of this ArkErrors instance for StandardSchema compatibility. */ get issues(): this; toJSON(): JsonArray; toString(): string; private addAncestorPaths; } export declare class TraversalError extends Error { readonly name = "TraversalError"; arkErrors: ArkErrors; constructor(errors: ArkErrors); } export interface DerivableErrorContext { expected: string; actual: string; problem: string; message: string; data: Prerequisite; path: array; propString: string; } export type DerivableErrorContextInput = Partial> & propwiseXor<{ path?: array; }, { relativePath?: array; prefixPath?: array; }>; export type ArkErrorCode = { [kind in NodeKind]: errorContext extends null ? never : kind; }[NodeKind]; type ArkErrorContextInputsByCode = { [code in ArkErrorCode]: errorContext & DerivableErrorContextInput; }; export type ArkErrorContextInput = merge; export type NodeErrorContextInput = ArkErrorContextInputsByCode[code] & { meta: ArkEnv.meta; }; export type MessageContext = Omit, "message">; export type ProblemContext = Omit, "problem">; export type CustomErrorInput = show<{ code?: undefined; } & DerivableErrorContextInput>; export type ArkErrorInput = string | ArkErrorContextInput | CustomErrorInput; export type ProblemConfig = string | ProblemWriter; export type ProblemWriter = (context: ProblemContext) => string; export type MessageConfig = string | MessageWriter; export type MessageWriter = (context: MessageContext) => string; export type getAssociatedDataForError = code extends NodeKind ? Prerequisite : unknown; export type ExpectedConfig = string | ExpectedWriter; export type ExpectedWriter = (source: errorContext) => string; export type ActualConfig = string | ActualWriter; export type ActualWriter = (data: getAssociatedDataForError) => string; export {};