goobs-frontend
Version:
A comprehensive React-based libary for building modern web applications
44 lines • 2.24 kB
TypeScript
/**
* =============================================================================
* FORM SCHEMA INTROSPECTION — zod-native, defensive
* =============================================================================
*
* Helpers that read structure out of a zod schema WITHOUT hard-coupling the
* form surface to a specific zod minor version. Everything here is wrapped in
* try/catch and falls back to a safe default — schema introspection must never
* throw during render (FieldShell calls `deriveRequiredFromSchema` on every
* render when bound).
*
* zod v4 specifics this relies on (verified against zod ^4.4.3):
* - `schema.shape` is the per-field record on an object schema.
* - A field schema exposes `isOptional()` / `isNullable()` predicates.
* - `fieldSchema.safeParse(undefined).success === true` is an
* optional-detection FALLBACK for schemas whose `isOptional` is unreliable.
* - The internal kind is at `fieldSchema._zod.def.type`, with wrapper kinds
* (`optional` / `nullable` / `default`) exposing `def.innerType`.
*/
/** The field kinds AutoFields knows how to render. */
export type FieldKind = 'text' | 'email' | 'number' | 'date' | 'enum' | 'boolean' | 'stringArray';
/**
* Whether a field is required (not optional and not nullable). Defensive:
* returns `false` for anything it can't introspect, and never throws.
*
* Detection order:
* 1. `isOptional()` / `isNullable()` predicates when present.
* 2. `safeParse(undefined).success` as an optional-detection fallback —
* a schema that accepts `undefined` is treated as not-required.
*/
export declare function deriveRequiredFromSchema(schema: unknown, name: string): boolean;
/**
* Turn a camelCase / snake_case field key into a human label.
* 'contractName' -> 'Contract Name'
* 'address_line_1' -> 'Address Line 1'
* 'customerId' -> 'Customer Id'
*/
export declare function humanize(key: string): string;
/**
* Map a zod field schema to the goobs field kind AutoFields renders. Defensive:
* unknown / unintrospectable schemas fall back to `'text'`, and it never throws.
*/
export declare function zodTypeToFieldKind(fieldSchema: unknown): FieldKind;
//# sourceMappingURL=schema.d.ts.map