@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
32 lines (31 loc) • 1.6 kB
TypeScript
import type { StandardSchemaV1Issue } from '@tanstack/react-form';
export type { ErrorVisibility } from './visibility.js';
/** Anything a validator may return as an error. */
export type FormError = string | true | StandardSchemaV1Issue | {
message: string;
code?: string;
params?: Record<string, unknown>;
} | Error;
export interface NormalisedError {
message: string;
code?: string;
params?: Record<string, unknown>;
path?: string;
}
/**
* Turns any validator output into `{ message, code?, params?, path? }`: strings, Standard Schema
* issues, `{ message }` objects and `Error`s. `true` → `{ message: '' }` (invalid, no text).
* Anything else (falsy, numbers, arrays) → `null`.
*/
export declare function normaliseError(e: unknown): NormalisedError | null;
/** Flattens nested arrays (TanStack stores issue arrays per slot) and normalises, dropping non-errors. */
export declare function normaliseErrors(value: unknown): NormalisedError[];
/** Error-map slots, highest priority first (§4.2.3). */
export declare const ERROR_SLOT_PRIORITY: readonly ["onServer", "onSubmit", "onDynamic", "onChange", "onBlur", "onMount"];
/**
* All errors of an error map in slot priority, normalised and de-duplicated by message.
* The binding shows only the first (one message per field).
*/
export declare function pickErrors(errorMap: Partial<Record<string, unknown>> | undefined): NormalisedError[];
/** The first error of an error map, or `undefined`. */
export declare function pickError(errorMap: Partial<Record<string, unknown>> | undefined): NormalisedError | undefined;