/** * SQL → TypeScript codegen for extension-owned tables (S4-01). * * The aim: extensions' `ctx.db` is currently typed `any`, so a column rename * is a silent runtime failure. This module parses an extension's migration * SQL files and emits a `.d.ts` describing every table the extension owns, * keyed for Kysely. Result: `ctx.db.selectFrom('zv_forms')` autocompletes * column names in editors and `tsc` catches typos. * * Scope intentionally narrow: * - Handles `CREATE TABLE [IF NOT EXISTS]` and `ALTER TABLE … ADD COLUMN`. * - Maps the common Postgres types we see in extension migrations to TS. * - Ignores constraint-only ALTER TABLE statements (PRIMARY KEY, FK). * - Ignores CREATE INDEX, CREATE TYPE, CREATE FUNCTION, etc. * * Anything more exotic falls back to `unknown` so downstream code still * compiles. The migration author is free to widen this module's regex when * a real case arises. */ export interface Column { name: string; /** TypeScript type (e.g. 'string', 'number | null', 'Record'). */ tsType: string; /** The raw Postgres type as parsed — useful for codegen comments. */ pgType: string; nullable: boolean; } export interface Table { name: string; columns: Column[]; } export interface ParsedSchema { tables: Table[]; } /** * Parse a single CREATE TABLE body — the text between the outer parens — * into a list of columns. Constraint-only clauses (PRIMARY KEY (…), FOREIGN * KEY (…), CHECK (…), UNIQUE (…), CONSTRAINT …) are skipped. */ export declare function parseColumnList(body: string): Column[]; /** * Parse one or more migration SQL strings into a normalized schema. Tables * are merged across files: `CREATE TABLE foo (...)` followed by * `ALTER TABLE foo ADD COLUMN bar text` produces a single `foo` table with * `bar` appended. Last write wins for column re-declarations. */ export declare function parseSchema(sqlChunks: string[]): ParsedSchema; export interface CodegenOptions { /** Top-level interface name (default: `ExtensionSchema`). */ interfaceName?: string; /** Optional banner line above the file body (e.g. provenance comment). */ banner?: string; } /** * Emit a Kysely-friendly `.d.ts`-style module body for a parsed schema. * The result is plain TypeScript; callers write it wherever (typically * `/.zveltio/db.d.ts`). */ export declare function emitTypeScript(schema: ParsedSchema, opts?: CodegenOptions): string; //# sourceMappingURL=schema-codegen.d.ts.map