UNPKG

@mitcsutt/kiln-forms

Version:

Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui

26 lines (25 loc) • 1.45 kB
import type { AnyFormApi, StandardSchemaV1, StandardSchemaV1Issue } from '@tanstack/react-form'; import { type FormRuntime } from './formRuntime.js'; /** Issues routed to TanStack's form-validator shape: path-less → `form`, the rest by field path. */ export interface RoutedIssues { form?: StandardSchemaV1Issue[]; fields: Record<string, StandardSchemaV1Issue[]>; } /** * Routes issues by path (`['guests', 0, 'name']` → `guests[0].name`) and drops issues whose path * is inactive or under an inactive prefix (§5.3). Returns `undefined` when nothing is left — an * empty object would count as "errored" in TanStack. */ export declare function routeIssues(issues: readonly StandardSchemaV1Issue[] | undefined, runtime?: FormRuntime): RoutedIssues | undefined; /** A TanStack form validator (sync slot) for a whole-form Standard Schema. */ export declare function schemaValidator(schema: StandardSchemaV1): ({ value, formApi, }: { value: unknown; formApi: AnyFormApi; }) => RoutedIssues | undefined; /** A TanStack form validator (async slot) for a whole-form Standard Schema. */ export declare function schemaValidatorAsync(schema: StandardSchemaV1): ({ value, formApi, }: { value: unknown; formApi: AnyFormApi; }) => Promise<RoutedIssues | undefined>; /** True for any Standard Schema object (zod 4, valibot, arktype…). */ export declare function isStandardSchema(value: unknown): value is StandardSchemaV1;