/** * Field builder functions for creating form field definitions. * * Each function creates a field descriptor that captures both schema information * (name, type) and UI hints (label, placeholder, etc.). */ import type { ArrayField, BooleanField, DynamicEnumField, DynamicSchemaField, EnumOptionValue, FormElement, MetadataPolicyInput, NumberField, ObjectField, StaticEnumField, TextField } from "@formspec/core"; declare const FIELD_POLICY_BRAND: unique symbol; /** * Branded field element produced by a policy-scoped builder namespace. * * @public */ export type FieldBuilderElement = Element & { readonly [FIELD_POLICY_BRAND]: Policy extends undefined ? { readonly __formspecDefaultFieldPolicy: true; } : Policy; }; /** * Input element accepted by policy-scoped composite field builders. * * @public */ export type FieldBuilderInputElement = Policy extends undefined ? FormElement : FieldBuilderElement; /** * Field-specific metadata policy extracted from a broader metadata policy input. * * @public */ export type FieldMetadataPolicy = Policy extends { readonly field?: infer FieldPolicy; } ? FieldPolicy : undefined; /** * Whether a specific metadata key is required by the active policy. * * @public */ export type IsRequiredMetadata = FieldMetadataPolicy extends Record ? FieldMetadataPolicy[Key] extends { readonly mode: "require-explicit"; } ? true : false : false; /** * Label/displayName config shape under a required-or-optional policy. * * @public */ export type LabelDisplayNameConfig = Required extends true ? { readonly label: string; readonly displayName?: never; } | { readonly label?: never; readonly displayName: string; } : { readonly label?: string; readonly displayName?: never; } | { readonly label?: never; readonly displayName?: string; } | { readonly label?: undefined; readonly displayName?: undefined; }; /** * apiName config shape under a required-or-optional policy. * * @public */ export type ApiNameConfig = Required extends true ? { readonly apiName: string; } : { readonly apiName?: string; }; /** * Whether the active policy requires any explicit field metadata. * * @public */ export type HasRequiredMetadata = IsRequiredMetadata extends true ? true : IsRequiredMetadata extends true ? true : false; /** * Base field config augmented with metadata requirements from the active policy. * * @public */ export type MetadataAwareFieldConfig = Omit & ApiNameConfig> & LabelDisplayNameConfig>; /** * Optional-or-required config tuple driven by the active metadata policy. * * @public */ export type MaybeRequiredConfigArg = HasRequiredMetadata extends true ? readonly [config: Config] : readonly [config?: Config]; /** * Argument tuple for policy-scoped array field builders. * * @public */ export type ArrayBuilderArgs[], Policy> = HasRequiredMetadata extends true ? readonly [config: ArrayFieldConfig, ...items: Items] : readonly [...items: Items] | readonly [config: ArrayFieldConfig, ...items: Items]; /** * Argument tuple for policy-scoped object field builders. * * @public */ export type ObjectBuilderArgs[], Policy> = HasRequiredMetadata extends true ? readonly [config: ObjectFieldConfig, ...properties: Properties] : readonly [...properties: Properties] | readonly [config: ObjectFieldConfig, ...properties: Properties]; /** * Config accepted by policy-scoped text field builders. * * @public */ export type TextFieldConfig = MetadataAwareFieldConfig, "_type" | "_field" | "name">, Policy>; /** * Config accepted by policy-scoped number field builders. * * @public */ export type NumberFieldConfig = MetadataAwareFieldConfig, "_type" | "_field" | "name">, Policy>; /** * Config accepted by policy-scoped boolean field builders. * * @public */ export type BooleanFieldConfig = MetadataAwareFieldConfig, "_type" | "_field" | "name">, Policy>; /** * Config accepted by policy-scoped static enum field builders. * * @public */ export type StaticEnumFieldConfig = MetadataAwareFieldConfig, "_type" | "_field" | "name" | "options">, Policy>; /** * Config accepted by policy-scoped dynamic enum field builders. * * @public */ export type DynamicEnumFieldConfig = MetadataAwareFieldConfig, "_type" | "_field" | "name" | "source">, Policy>; /** * Config accepted by policy-scoped dynamic schema field builders. * * @public */ export type DynamicSchemaFieldConfig = MetadataAwareFieldConfig, "_type" | "_field" | "name" | "schemaSource">, Policy>; /** * Config accepted by policy-scoped array field builders. * * @public */ export type ArrayFieldConfig = MetadataAwareFieldConfig, "_type" | "_field" | "name" | "items">, Policy>; /** * Config accepted by policy-scoped object field builders. * * @public */ export type ObjectFieldConfig = MetadataAwareFieldConfig, "_type" | "_field" | "name" | "properties">, Policy>; /** * Namespace of field builder functions produced by the DSL. * * @public */ export interface FieldBuilderNamespace { /** Builds a text field. */ readonly text: (name: N, ...args: MaybeRequiredConfigArg, Policy>) => FieldBuilderElement>; /** Builds a number field. */ readonly number: (name: N, ...args: MaybeRequiredConfigArg, Policy>) => FieldBuilderElement>; /** Builds a boolean field. */ readonly boolean: (name: N, ...args: MaybeRequiredConfigArg, Policy>) => FieldBuilderElement>; /** Builds a static enum field. */ readonly enum: (name: N, options: O, ...args: MaybeRequiredConfigArg, Policy>) => FieldBuilderElement>; /** Builds a dynamic enum field. */ readonly dynamicEnum: (name: N, source: Source, ...args: MaybeRequiredConfigArg, Policy>) => FieldBuilderElement>; /** Builds a dynamic schema field. */ readonly dynamicSchema: (name: N, schemaSource: string, ...args: MaybeRequiredConfigArg, Policy>) => FieldBuilderElement>; /** Builds an array field, optionally with config as the second argument. */ readonly array: []>(name: N, ...args: ArrayBuilderArgs) => FieldBuilderElement>; /** Builds an array field with an explicit config object. */ readonly arrayWithConfig: []>(name: N, config: ArrayFieldConfig, ...items: Items) => FieldBuilderElement>; /** Builds an object field, optionally with config as the second argument. */ readonly object: []>(name: N, ...args: ObjectBuilderArgs) => FieldBuilderElement>; /** Builds an object field with an explicit config object. */ readonly objectWithConfig: []>(name: N, config: ObjectFieldConfig, ...properties: Properties) => FieldBuilderElement>; } /** * Field builder namespace containing functions to create each field type. * * @example * ```typescript * import { field } from "@formspec/dsl"; * * field.text("name", { label: "Full Name" }); * field.number("age", { min: 0, max: 150 }); * field.enum("status", ["draft", "sent", "paid"]); * field.dynamicEnum("country", "countries", { label: "Country" }); * ``` * * @public */ export declare function createFieldBuilders(): FieldBuilderNamespace; /** * Field builder namespace containing functions to create each field type. * * @public */ export declare const field: FieldBuilderNamespace; export {}; //# sourceMappingURL=field.d.ts.map