/** * Convert a Postgres DDL blob (e.g., a spec's schema proposal) into a * Mermaid `erDiagram` block. Deliberately shallow — regex-based, not a * full SQL parser. Designed for the shapes `create table` and * `alter table add column` typically emitted by refine proposals. * * What it captures: * - New table declarations (`create table foo (...)`) with their columns * - `references` clauses as FK relationships * - `alter table ... add column` entries merged into existing tables * * What it ignores: * - Indexes, policies, triggers, functions — irrelevant for an ERD * - Check constraints — too complex for a shallow parser * - Computed / generated columns — rare in refine proposals * * Falls back gracefully: if the DDL doesn't produce any entities, returns * an empty diagram with a comment pointing the reader at the raw SQL * block in the PR body for manual review. */ interface ErdEntity { name: string; columns: ErdColumn[]; } interface ErdColumn { name: string; /** Normalised Postgres type family (uuid / text / int / timestamptz / etc.) */ type: string; /** PK / FK / null markers rolled into a single display hint */ hints: string[]; } interface ErdRelationship { from: string; to: string; /** Cardinality sketch — one-to-many until we detect otherwise (rare in refine DDL) */ shape: "||--o{" | "}o--||" | "||--||"; label: string; } /** * Parse a column definition line like: * `recipient_id uuid not null references profiles(id) on delete cascade,` * into its constituent parts. Returns null if the line isn't a column. */ declare function parseColumnLine(line: string): { column: ErdColumn; references?: { table: string; }; } | null; /** * Shallow Postgres DDL → { entities, relationships }. * * Accepts multiple statements; only `create table` and `alter table add * column` shapes produce output. Everything else is ignored. */ declare function parseDdl(ddl: string): { entities: Map; relationships: ErdRelationship[]; }; /** * Render entities + relationships into a Mermaid `erDiagram` block. The * returned string is wrapped in triple-backtick `mermaid` fence so it's * ready to drop into a PR body or a `.mmd` file section. */ export declare function ddlToMermaidErd(ddl: string): string; /** * Test-only access to the parser — keeps the public surface minimal. */ /** * Promoted in 0.18.0-α.6 — entity-first foundation. `slowcook init entities` * needs the structured entities + relationships (not just the rendered Mermaid * string) to emit TypeScript interfaces + zod schemas under src/lib/entities/. */ export { parseDdl }; export type { ErdEntity, ErdColumn, ErdRelationship }; export declare const __internals: { parseDdl: typeof parseDdl; parseColumnLine: typeof parseColumnLine; }; //# sourceMappingURL=mermaid.d.ts.map