import { t as StandardSchemaV1 } from "./standard-DIedMFAS.js"; import "./index-BUFkuwVT.js"; import { i as ValidationBuilder } from "./rule-DYNYH_ha.js"; import { SQLiteColumn, SQLiteColumnBuilderBase, SQLiteTableWithColumns } from "drizzle-orm/sqlite-core"; //#region src/core/forms/types.d.ts /** * Input semantics a public form needs, on top of the content field vocabulary. Each * maps to a stored column type and a rendered input; `email`/`url`/`select`/ * `number` also carry a built-in format/coercion check. */ type FormFieldType = "text" | "email" | "tel" | "url" | "textarea" | "number" | "select" | "checkbox" | "date" | "file"; /** One declared form field. */ interface FormField { type: FormFieldType; /** Human label for the rendered input and the review column header. */ label: string; /** * Required → a `NOT NULL` column and a required check at submit. (Kept as an * explicit flag, not buried in `validation`, so column derivation can read it.) */ required?: boolean; /** `select` options (also the allowlist the server validates against). */ options?: readonly string[]; /** Placeholder text for the rendered input. */ placeholder?: string; /** Help/hint text rendered under the input, and linked to it for screen readers. */ help?: string; /** * The browser's autofill token, passed through as the control's * `autocomplete`: `"name"`, `"email"`, `"tel"`, `"postal-code"`, and so on. * Set it on any field that asks for something the visitor's browser already * knows. */ autocomplete?: string; /** * The on-screen keyboard to offer, passed through as `inputmode`. Use * `"numeric"` on a `text` field for digits that aren't a quantity (a postal * code, an order number) rather than `type: "number"`, which adds spinner * buttons and changes on a scroll. */ inputmode?: "none" | "text" | "decimal" | "numeric" | "tel" | "search" | "email" | "url"; /** * Extra validation, reusing the shared `Rule` builder—for example, * `(r) => r.max(5000)`. Composed after the type's built-in check. */ validation?: ValidationBuilder; /** * Bring-your-own validation (#98): any Standard Schema * (https://standardschema.dev): Zod, Valibot, ArkType, or the built-in * `louise-toolkit/schema` `s.*` builder. Run in the same shared client+server * pass as `validation`, on the coerced value, and skipped for empty values so * an optional field stays optional. `validation` (the zero-dep `Rule` engine) * remains the default; this is for consumers who'd rather reuse a validator * they already have. */ schema?: StandardSchemaV1; } /** Anti-spam options for a form's public capture route. */ interface FormSpamConfig { /** Require a Cloudflare Turnstile token (`cf-turnstile-response`). Verified * server-side when `formRoute` is given a `turnstileSecret`. */ turnstile?: boolean; /** Fixed-window rate limit, keyed by client (typically IP). Enforced when * `formRoute` is given a KV binding. */ rateLimit?: { max: number; windowSec: number; }; /** * Honeypot: a decoy field name a bot fills but a human never sees. Any * non-empty value silently rejects the submission. The render helper emits it * hidden + `autocomplete="off"`. Default off. */ honeypot?: string; /** * Minimum seconds between the form rendering and its submit—a bot posts * near-instantly. Enforced against a `louise_ts` timestamp the render helper * stamps at mount. Default off. */ minSeconds?: number; } /** A minimal mailer the site provides so `formRoute` can send an email * notification without coupling to any one email binding. Wrap your `EMAIL` * binding + `louise-toolkit/email` templates here. */ type FormMailer = (message: { to: string; subject: string; text: string; }) => void | Promise; /** Where a successful submission is announced (Tier 3). */ interface FormNotifyConfig { /** POST `{ form, values }` to this webhook URL (fire-and-forget). */ webhook?: string; /** Email a notification. Requires a `mailer` on the route config. */ email?: { to: string; subject?: string; }; } /** A declared form: fields + optional spam/notify policy. */ interface FormConfig { /** Form + table name. A bare SQL identifier (`^[A-Za-z_][A-Za-z0-9_]*$`). */ name: string; fields: Record; spam?: FormSpamConfig; notify?: FormNotifyConfig; /** Submit button label for the render helper. Default `"Send"`. */ submitLabel?: string; /** * The site's BCP 47 locale, such as `"en-US"` or `"de-DE"`. A `number` field * reads its grouping and decimal separators, so a visitor can type `1,000`. * A site fact, so there's no default: without it, a number must be written * without separators, because a comma is a decimal point in some locales. */ locale?: string; } /** A review column derived from a form field—key + label for the panel. */ interface FormReviewColumn { key: string; label: string; type: FormFieldType; } type AnyFormTable = SQLiteTableWithColumns; type FormColumns = Record; /** * The product of {@link defineForm}: the original config plus everything derived * from it—the Drizzle `columns`/`table`, and the `reviewColumns` the Settings * uses to render the submissions list. */ interface FormDefinition extends FormConfig { /** Derived Drizzle column builders—spread into your own * `sqliteTable(name, { ...columns, /* extras *\/ })`, or use {@link table}. */ columns: Record; /** The ready-made Drizzle table for this form. */ table: AnyFormTable; /** Field key → review column (label + type) for the submissions panel. */ reviewColumns: FormReviewColumn[]; } //#endregion export { FormField as a, FormNotifyConfig as c, FormDefinition as i, FormReviewColumn as l, FormColumns as n, FormFieldType as o, FormConfig as r, FormMailer as s, AnyFormTable as t, FormSpamConfig as u };