import type { FastifyInstance } from "fastify"; import type { ZodTypeAny } from "zod"; import type { ObjectManager } from "../object-manager.js"; import type { RouteShorthandOptions } from "fastify"; import type { SortAllowlist } from "../drizzle-fastify/filter-allowlist.js"; export type CrudVerb = "list" | "get" | "create" | "update" | "delete"; export interface CrudRoutesOptions { fastify: FastifyInstance; /** REST resource path, e.g. "/subscribers". */ path: string; /** Entity name from metadata, e.g. "Subscriber". */ entity: string; /** Zod schema for create payloads (typically `InsertSchema`). */ insertSchema: ZodTypeAny; /** Zod schema for update payloads (typically `UpdateSchema`). */ updateSchema: ZodTypeAny; /** * ObjectManager accessor. A function rather than the instance so callers * can keep their lazy-init pattern (load metadata once at startup). */ om: () => Promise; /** * Limit which verbs are mounted. Defaults to all five. Useful for * read-only resources (`expose: ["list", "get"]`). */ expose?: readonly CrudVerb[]; /** * Fastify route-level hooks applied to every mounted verb. The most common * use is `preHandler` for auth/authz: * * routeOptions: { preHandler: requireAdminAuth } * * Anything Fastify accepts on a route options object is valid here * (preHandler, onRequest, preValidation, preParsing, schema, etc.). */ routeOptions?: RouteShorthandOptions; /** * HTTP method for the update verb. Defaults to "patch" (semantic partial- * update). Set to "put" to preserve a legacy API contract that already * uses PUT for updates. */ updateMethod?: "patch" | "put"; /** * Per-entity sort allowlist (`SortAllowlist` from codegen). When set, * a `?sort=field:dir` referencing a field NOT in the allowlist (or an invalid * order) is rejected with HTTP 400 `{ error: "invalid_sort" }` — matching the * cross-port REST contract and the drizzle-fastify mount. When absent, `?sort` * is ignored (legacy back-compat: limit/offset only). */ sortAllowlist?: SortAllowlist; } /** * Mount the 5 standard REST endpoints for an entity: * * GET {path} → list, with ?limit & ?offset query params * GET {path}/:id → findById * POST {path} → create (validated via insertSchema) * PATCH {path}/:id → partial update (validated via updateSchema) * DELETE {path}/:id → delete */ export declare function mountCrudRoutes(opts: CrudRoutesOptions): void; type SingleVerbOptions = Omit; export declare function mountListRoute(opts: SingleVerbOptions): void; export declare function mountGetRoute(opts: SingleVerbOptions): void; export declare function mountCreateRoute(opts: SingleVerbOptions): void; export declare function mountUpdateRoute(opts: SingleVerbOptions): void; export declare function mountDeleteRoute(opts: SingleVerbOptions): void; export { parseId } from "../drizzle-fastify/util.js"; //# sourceMappingURL=index.d.ts.map