import type { FastifyInstance, RouteShorthandOptions } from "fastify"; import type { ZodTypeAny } from "zod"; import type { FilterAllowlist, SortAllowlist } from "./filter-allowlist.js"; export type { FilterAllowlist, SortAllowlist } from "./filter-allowlist.js"; export { isTruthyFlag, contractErrorCode, parseId, coerceIdForColumn } from "./util.js"; type AnyDrizzle = any; type AnyTable = any; export type CrudVerb = "list" | "get" | "create" | "update" | "delete"; export interface CrudRoutesOptions { fastify: FastifyInstance; /** REST resource path, e.g. "/subscribers". */ path: string; /** User's Drizzle instance. */ db: AnyDrizzle; /** Drizzle table const. The helper requires this to have an `id` column. */ table: AnyTable; /** * #214 write-through entity — the Drizzle VIEW const to READ through (a * `@role:replica @kind:view` replica carrying derived `origin.passthrough` * columns the base table excludes, per #213). When set, list/get and the * post-write re-read on create/update SELECT from this view (read-your-writes * returns the derived fields), while every WRITE still targets `table`. The * view must expose the same `id` column. Absent → ordinary single-table CRUD. */ readView?: AnyTable; /** Zod schema for create payloads (typically `InsertSchema`). */ insertSchema: ZodTypeAny; /** Zod schema for update payloads (typically `UpdateSchema`). */ updateSchema: ZodTypeAny; /** Limit which verbs are mounted. Defaults to all five. */ expose?: readonly CrudVerb[]; /** * Fastify route-level hooks applied to every mounted verb (preHandler, * onRequest, schema validation, etc.). Most common use is auth: * routeOptions: { preHandler: requireAuthHook } */ routeOptions?: RouteShorthandOptions; /** * HTTP method for the update verb. Defaults to "patch". Set to "put" to * preserve a legacy API contract that already uses PUT for updates. */ updateMethod?: "patch" | "put"; filterAllowlist?: FilterAllowlist; sortAllowlist?: SortAllowlist; /** Dialect — required if filterAllowlist or sortAllowlist is set (for dialect-specific `like` lowering: SQLite lowers to GLOB to stay case-sensitive; ADR-0049). */ dialect?: "sqlite" | "postgres"; /** * FR-017 TPH — scope this route set to a single subtype of a single-table- * inheritance base. When set: * - list/get filter to `eq(table[column], value)`; * - a get/update/delete targeting a row of another subtype 404s; * - create injects `{ [column]: value }` AFTER body validation (the body * omits the discriminator — the URL already names the subtype); * - update strips `column` from the patch (a row's subtype is immutable). * Absent → ordinary single-table CRUD, behaviour unchanged. */ discriminator?: { column: string; value: string; }; } export declare function mountCrudRoutes(opts: CrudRoutesOptions): void; type VerbOptions = Omit; export declare function mountListRoute(opts: VerbOptions): void; export declare function mountGetRoute(opts: VerbOptions): void; export declare function mountCreateRoute(opts: VerbOptions): void; export declare function mountUpdateRoute(opts: VerbOptions): void; export declare function mountDeleteRoute(opts: VerbOptions): void; export { mountReadOnlyCrudRoutes, type MountReadOnlyOptions } from "./mount-read-only.js"; export { mountM2mRoute, type M2mRouteOptions } from "./mount-m2m.js"; //# sourceMappingURL=index.d.ts.map