/** * API Client for Quickback Compiler Service * * Handles communication with the remote compiler API. */ import type { LoadedConfig } from './file-loader.js'; export interface CompilerInput { config: LoadedConfig; features: Array<{ name: string; schema: { tableName: string; columns: any; source: string; }; tables?: Array<{ fileName: string; tableName: string; source: string; hasResourceConfig: boolean; }>; resourceSource?: string; /** * One file per action keyed by relative path under the feature dir * (e.g. `actions/advance.ts`, `actions/profiles/publish.ts`). Each * file is `export default defineAction({...})`. The compiler runs * the discovery walker over these to build the action tree. */ actionFiles?: Record; /** * Feature-local helpers under `/lib/` keyed by relative * path (e.g. `lib/inputs.ts`). Copied verbatim into the generated * output; action files import them via `../lib/...`. */ featureLibFiles?: Record; /** Feature areas: ancestor area directory names, outermost first. */ areaPath?: string[]; }>; /** * Feature areas (`features/**\/_area.ts`): executed area definitions with * their directory positions. The compiler folds each area's namespace + * authz vocabulary into `config.authz` and enforces subtree visibility. */ areas?: Array<{ dirPath: string[]; definition: Record; }>; /** * Project-level shared lib at `quickback/lib/` keyed by relative path * (e.g. `lib/inputs.ts`). Aliased as `~/lib/*` in the generated * project; cross-feature shared helpers live here. */ projectLib?: Record; /** * Project-level auth hooks at `quickback/hooks/` keyed by relative * path (e.g. `hooks/after-user-create.ts`). Wired into Better Auth's * `databaseHooks` by the compiler. */ projectHooks?: Record; /** * User-authored Better Auth plugin source files at `quickback/plugins/` * keyed by relative path (e.g. `plugins/long-session.ts`). Referenced * from `defineAuth("better-auth", { customPlugins: [{ from, export }] })` * with a relative `from`. The compiler copies referenced files into * the generated output and rewrites the emitted import paths. */ projectPlugins?: Record; /** * Project-level Hono middlewares at `quickback/middlewares/` keyed by * relative path (e.g. `middlewares/request-logger.ts`). v0.19+: each * file's default export is a Hono middleware handler; the compiler * mounts them via `app.use('*', mw)` after platform middleware (auth, * db, services) and before route registration. Declarative cross- * cutting slot for non-authz concerns. */ projectMiddlewares?: Record; /** * High-fidelity JSON Schemas for action `input:` Zod schemas, harvested * on the user's machine (`z.toJSONSchema(action.input)`) and keyed by the * action's compiler staging path (`src/features//`). * The compiler stamps these into `openapi.json` / `mcp.ts` without ever * executing user code. Absent → the compiler's static parser supplies a * lower-fidelity input schema. */ actionInputSchemas?: Record; actionOutputSchemas?: Record; /** * Compiler-owned v1 migration history. Protocol v2 forbids this field and * keeps the history on the CLI host. */ existingFiles?: Record; migration?: { version: 2; owner: 'cli'; schema: { engineVersion: string; schemaHash: string; [key: string]: unknown; }; priorState: { auditSchemaLatched: boolean; existingNonIdPkTables: string[]; }; existingRuntimeState?: { wranglerToml?: string; }; }; } export interface GeneratedFile { path: string; content: string; type: string; feature?: string; } export interface PostCompileCommand { description: string; command: string; phase?: 'dependency-install' | 'schema-prepare' | 'migration-generate'; optional?: boolean; cwd?: 'output' | 'project'; } export type ClientMigrationPostprocessor = 'd1-safety' | 'update-journal' | 'reorder-pg-constraints' | 'harden-audit' | 'append-rls' | 'append-triggers'; export interface ClientMigrationTarget { id: 'features' | 'auth' | 'audit' | 'webhooks' | 'files'; dialect: 'sqlite' | 'postgresql'; configPath: string; outPath: string; renameHints?: { tables?: Record; columns?: Record>; }; autoCreateRenames?: boolean; postprocessors: ClientMigrationPostprocessor[]; } export interface ClientMigrationPlan { protocolVersion: 2; drizzleVersion: '0.31.10'; targets: ClientMigrationTarget[]; } export interface CompilerCapabilities { migrationProtocol: readonly [1, 2]; schemaEngineVersion: string; } export interface CompilerOutput { files: GeneratedFile[]; meta: { fileCount: number; features: string[]; timestamp: string; version: string; capabilities?: CompilerCapabilities; schema?: { engineVersion: string; schemaHash: string; }; /** * Compiler-owned migrations handed to the CLI to append. The compiler * still decides WHAT these say (content and hash); client ownership only * moves where they are written. Present when migration generation is * CLI-owned; undefined on targets that render neither. */ rlsJournalMigration?: { sql: string; hash: string; }; triggerJournalMigration?: { createSql: string; hash: string; names: string[]; }; timings?: { parseMs: number; generateMs: number; installMs: number; commandsMs: number; collectMs: number; totalMs: number; commands: Array<{ description: string; ms: number; success: boolean; }>; }; }; commands?: PostCompileCommand[]; warnings?: string[]; /** * Output-root-relative paths this compile no longer emits, which the CLI * should delete. The file manifest can only ADD, and `prepareGeneratedDir` * only wipes `src/` — so a path that moves OUTSIDE `src/` would otherwise * leave an orphan on disk forever (v0.60 moved the spec blobs out of the * project root and hit exactly this). * * The compiler resolves these against its own manifest, so an entry here is * never a path the same compile wrote. Absent on older compilers. */ retiredPaths?: Array<{ path: string; since: string; reason: string; }>; migrationPlan?: ClientMigrationPlan; migrationInputs?: GeneratedFile[]; /** * Schema-driven kitchen-sink block to splice into the user's * quickback.config.ts. Server-rendered every compile to reflect * the current set of options Quickback supports. * * `block` includes both `// [quickback:options-start]` and * `// [quickback:options-end]` sentinels, pre-indented to match * the surrounding object literal. `omittedKeys` lists the * top-level keys the user has already set, which the server * has therefore excluded from the block. */ syncedConfig?: { block: string; omittedKeys: string[]; }; } export interface ApiError { error: string; code?: string; hint?: string; message?: string; details?: { command?: string; exitCode?: number | null; purpose?: string; causes?: string[]; fixes?: string[]; }; stderr?: string; stdout?: string; } export interface CallCompilerOptions { verbose?: boolean; } /** * Call the compiler API. * Automatically ensures the container is ready before sending the request. * Pass `onStatus` to receive progress updates (e.g. for spinner text). */ export declare function callCompiler(input: CompilerInput, onStatus?: (message: string) => void, options?: CallCompilerOptions): Promise; /** * Check API health */ export declare function checkHealth(): Promise<{ status: string; version: string; capabilities?: CompilerCapabilities; }>; /** * Wait for the compiler container to be ready. * * Cloud containers may need a cold start — and right after a service deploy * the FIRST request pays a fresh image pull, which routinely exceeds a * minute (observed on the v0.52.0 rollout: two healthy retries both missed * the old 60s budget). Default budget is now 4 minutes, with progress * surfaced so a long warm-up doesn't look like a hang. */ export declare function waitForReady(maxAttempts?: number, intervalMs?: number, onStatus?: (message: string) => void): Promise; /** * Get the API URL (for debugging) */ export declare function getApiUrl(): string; //# sourceMappingURL=api-client.d.ts.map