/** * Fluent schema-style builder for form field configuration. * * @module bquery/forms */ import type { FieldConfig, FormConfig, Validator } from './types'; /** * Fluent builder for a single field's validator chain. * * Builders are immutable: every chain method returns a new builder, so the * same starting point can be reused safely. */ export type FieldSchema = { /** Underlying validator list (frozen). */ readonly validators: readonly Validator[]; /** Append a `required()` validator. */ required: (message?: string) => FieldSchema; /** Append a `min()` validator. */ min: (limit: number, message?: string) => FieldSchema; /** Append a `max()` validator. */ max: (limit: number, message?: string) => FieldSchema; /** Append a `minLength()` validator. */ minLength: (limit: number, message?: string) => FieldSchema; /** Append a `maxLength()` validator. */ maxLength: (limit: number, message?: string) => FieldSchema; /** Append a `length()` validator. */ length: (exact: number, message?: string) => FieldSchema; /** Append an `email()` validator. */ email: (message?: string) => FieldSchema; /** Append a `url()` validator. */ url: (message?: string) => FieldSchema; /** Append a `pattern()` validator. */ pattern: (regex: RegExp, message?: string) => FieldSchema; /** Append an `integer()` validator. */ integer: (message?: string) => FieldSchema; /** Append a `numeric()` validator. */ numeric: (message?: string) => FieldSchema; /** Append a `between()` validator. */ between: (minLimit: number, maxLimit: number, message?: string) => FieldSchema; /** Append a `oneOf()` validator. */ oneOf: (values: readonly T[], message?: string) => FieldSchema; /** Append a `notOneOf()` validator. */ notOneOf: (values: readonly T[], message?: string) => FieldSchema; /** Append a `matchField()` validator. */ matchField: (ref: { readonly value: T; }, message?: string) => FieldSchema; /** Append an arbitrary custom validator. */ custom: (validator: Validator) => FieldSchema; /** Finalize as a {@link FieldConfig} with the given initial value. */ toConfig: (initialValue: T, extras?: Omit, 'initialValue' | 'validators'>) => FieldConfig; }; /** * Start a fluent field schema chain. * * @example * ```ts * import { field, schema } from '@bquery/bquery/forms'; * * const form = createForm(schema({ * name: field().required().minLength(2), * email: field().required().email(), * age: field().integer().between(0, 150), * })); * ``` */ export declare const field: () => FieldSchema; /** * A schema entry can be either a fluent builder (with optional initial value), * a fully-formed {@link FieldConfig}, or just a plain initial value (no validators). */ export type SchemaEntry = FieldSchema | FieldConfig | T; /** * Schema-style declaration helper that converts a map of fluent field * builders, raw {@link FieldConfig}s, or plain initial values into a * `FormConfig['fields']` object ready for {@link createForm}. * * @param shape - Map of field name → {@link SchemaEntry} * @param defaults - Optional initial values, used when an entry is a `FieldSchema` without an initial value * @returns Partial form config containing `fields`; merge with `onSubmit`, `crossValidators`, etc. * * @example * ```ts * import { createForm, schema, field } from '@bquery/bquery/forms'; * * const form = createForm({ * ...schema({ * name: field().required(), * email: field().required().email(), * }, { name: '', email: '' }), * onSubmit: async (values) => { ... }, * }); * ``` */ export declare const schema: >(shape: { [K in keyof T]: SchemaEntry; }, defaults?: Partial) => Pick, "fields">; //# sourceMappingURL=schema.d.ts.map