import { i as ContentItem } from "./types-C4ZXxSAE.mjs"; import { t as Database } from "./types-BCOU_CXE.mjs"; import { Kysely } from "kysely"; import { z } from "zod"; //#region src/api/types.d.ts /** * List response with cursor pagination */ interface ListResponse { items: T[]; nextCursor?: string; /** * Total number of rows matching the filters, ignoring pagination. Used * by the admin to render a stable pagination denominator. Optional so * callers that don't surface a row count don't pay for the extra query. */ total?: number; } /** * Content API responses */ interface ContentListResponse extends ListResponse {} interface ContentResponse { item: ContentItem; /** Opaque revision token for optimistic concurrency */ _rev?: string; } /** * Manifest API response */ interface ManifestResponse { version: string; hash: string; collections: Record; }>; plugins: Record; widgets?: string[]; }>; } interface FieldDescriptor { kind: string; label?: string; required?: boolean; /** * For `select` / `multiSelect`: the list of enum choices. * For `json` fields driven by a plugin `widget`: arbitrary widget config. */ options?: Array<{ value: string; label: string; }> | Record; } /** * Discriminated union for handler results. * * Handlers return `ApiResult` -- either `{ success: true, data: T }` or * `{ success: false, error: { code, message } }`. The `success` literal * enables TypeScript narrowing on `.data`. * * The generic `E` parameter defaults to `ErrorCode` but can be narrowed to * `OAuthErrorCode` for OAuth token-endpoint handlers. * * Use `unwrapResult()` from `error.ts` to convert to an HTTP Response. */ type ApiResult = { success: true; data: T; } | { success: false; error: { code: E; message: string; details?: Record; }; }; /** * API request context */ interface ApiContext { userId?: string; userRole?: string; } //#endregion //#region src/api/error.d.ts /** * Create a standardized error response. * * Always returns `{ success: false, error: { code, message } }` with correct * Content-Type. Use this for all error responses in API routes. */ declare function apiError(code: string, message: string, status: number, details?: Record): Response; /** * Create a standardized success response. * * Always returns `{ success: true, data: T }` with correct status code. * Use this for all success responses in API routes. */ declare function apiSuccess(data: T, status?: number): Response; /** * Handle an unknown error in a catch block. * * - Logs the full error server-side * - Returns a generic message to the client (never leaks error.message) * - Use `fallbackMessage` for the public-facing message * - Use `fallbackCode` for the error code */ declare function handleError(error: unknown, fallbackMessage: string, fallbackCode: string): Response; //#endregion //#region src/api/parse.d.ts /** * Result of parsing: either the validated data or an error Response. * Routes should check `if (result instanceof Response) return result;` */ type ParseResult = T | Response; /** * Parse and validate a JSON request body against a Zod schema. * * Returns the validated data on success, or a 400 Response on failure. * Replaces all `(await request.json()) as T` casts. */ declare function parseBody(request: Request, schema: T): Promise>>; /** * Parse and validate URL search params against a Zod schema. * * Converts searchParams to a plain object before validation. * Zod coercion handles string -> number/boolean conversion. * Replaces manual `url.searchParams.get()` + `parseInt()` patterns. */ declare function parseQuery(url: URL, schema: T): ParseResult>; /** * Type guard to check if a ParseResult is an error Response. * Usage: `if (isParseError(result)) return result;` */ declare function isParseError(result: ParseResult): result is Response; //#endregion //#region src/database/repositories/options.d.ts /** * Options repository for key-value settings storage * * Used for site settings, plugin configuration, and other arbitrary key-value data. * Values are stored as JSON for flexibility. */ declare class OptionsRepository { private db; constructor(db: Kysely); /** * Get an option value */ get(name: string): Promise; /** * Get an option value with a default */ getOrDefault(name: string, defaultValue: T): Promise; /** * Set an option value (creates or updates) */ set(name: string, value: T): Promise; /** * Set an option value only if no row with that name exists. Atomic at the * database level via INSERT ... ON CONFLICT DO NOTHING, so concurrent * callers can't race past the check. * * Returns true when the row was inserted, false when a row already * existed (regardless of its value — even an empty string or null). */ setIfAbsent(name: string, value: T): Promise; /** * Delete an option */ delete(name: string): Promise; /** * Check if an option exists */ exists(name: string): Promise; /** * Get multiple options at once */ getMany(names: string[]): Promise>; /** * Set multiple options at once */ setMany(options: Record): Promise; /** * Get all options (use sparingly) */ getAll(): Promise>; /** * Get all options matching a prefix */ getByPrefix(prefix: string): Promise>; /** * Delete all options matching a prefix */ deleteByPrefix(prefix: string): Promise; } //#endregion export { parseQuery as a, handleError as c, ContentListResponse as d, ContentResponse as f, ManifestResponse as h, parseBody as i, ApiContext as l, ListResponse as m, ParseResult as n, apiError as o, FieldDescriptor as p, isParseError as r, apiSuccess as s, OptionsRepository as t, ApiResult as u }; //# sourceMappingURL=options-B5K8QEV1.d.mts.map