/** * Collection Schema Export API Route Handler for Next.js * * This route handler can be re-exported in your Next.js application to provide * collection export endpoints at /api/collections/schema/[slug]/export. * * Exports UI-created collections to code-first format (defineCollection syntax) * for version control and customization. * * Services are auto-initialized on first request using environment variables: * - DB_DIALECT: Database dialect ("postgresql" | "mysql" | "sqlite") * - DATABASE_URL: Database connection string * * The JSON path returns `{ code }` via `respondData`; the `?download=true` * path returns the raw code as `text/plain` with a `Content-Disposition` * attachment header (binary/text-stream responses bypass JSON envelopes). * * @example * ```typescript * // In your Next.js app: app/api/collections/schema/[slug]/export/route.ts * export { GET } from 'nextly/api/collections-schema-export'; * ``` * * @module api/collections-schema-export */ /** * Context object for dynamic route handlers. * Next.js 15+ requires params to be a Promise. */ interface RouteContext { params: Promise<{ slug: string; }>; } /** * GET handler for exporting a collection to code-first format. * * Requires authentication and read permission for the collection. * Generates `defineCollection()` code from the collection's field config. * * Query Parameters: * - includeAccess: Include access control placeholder comments (default: true) * - includeHooks: Include hooks placeholder comments (default: true) * - format: Output format - "typescript" or "javascript" (default: "typescript") * - download: If "true", returns as downloadable file instead of JSON * * Response Codes: * - 200 OK: Code generated successfully (JSON or file download) * - 401 Unauthorized: Authentication required * - 403 Forbidden: Caller lacks read permission for this collection * - 404 Not Found: Collection with slug does not exist * - 500 Internal Server Error: Export failed */ declare const GET: (request: Request, context: RouteContext) => Promise; export { GET };