/** * Unified SQL object graph — the semantic IR over parsed programs. * * Nodes are database objects (keyed by qualified name) with the statements * that create them; edges are the references statements make to objects, * typed with `@pgsql/transform`'s edge taxonomy (`hard | fk | late`). * Programs are named (typically one per pgpm change), so ownership queries * answer change-level questions directly: * * - which objects live in a schema set (subsystem selection) * - which surviving statements still reach into a dropped object set * (cascade safety — every in-edge must originate from a statement that is * itself dropped, or be rebound) * - which programs create nothing outside a dropped set (whole-change * pruning by ownership, not survivor counting) * * Each program's intra-program edges come straight from * `buildStatementGraph`; references with no in-program producer (external * dependencies, which the statement graph deliberately omits) are added with * the same kind classification, so the object graph is a superset projection * of the statement graph over the same facts. * * Pure and I/O-free; built from `SqlProgram`s parsed once elsewhere. */ import { EdgeKind, SqlProgram } from '@pgpmjs/transform'; import { SqlObjectRef } from './refs'; /** Identifies one statement inside one named program. */ export interface StatementId { program: string; statement: number; } /** * How an edge constrains ordering — `@pgsql/transform`'s taxonomy: * `hard` (must exist at CREATE time), `fk` (a hard edge from a foreign-key * target), `late` (reached only inside a PL/pgSQL body, resolved at call * time). */ export type ObjectEdgeKind = EdgeKind; /** One reference from a statement to an object. */ export interface ObjectEdge { from: StatementId; /** Key of the referenced object (see `objectKey`). */ to: string; kind: ObjectEdgeKind; } /** A database object and the statements that create it. */ export interface ObjectNode { ref: SqlObjectRef; createdBy: StatementId[]; } export interface SqlObjectGraph { /** The named programs the graph was built from. */ programs: Map; /** Objects by key. */ objects: Map; /** All reference edges. */ edges: ObjectEdge[]; /** Edges into each object, by object key. */ incoming: Map; } export declare function objectKey(ref: SqlObjectRef): string; export declare function objectLabel(ref: SqlObjectRef): string; /** * Build the object graph from named programs (typically change name → * parsed deploy script). */ export declare function buildObjectGraph(programs: Map | Array<[string, SqlProgram]>): SqlObjectGraph; /** Keys of every object created in one of the given schemas. */ export declare function objectsInSchemas(graph: SqlObjectGraph, schemas: Iterable): Set; /** * Edges into `dropped` objects whose source statement is not itself dropped. * Each is a dangling dependency: dropping the object set is safe iff this is * empty or every edge's referenced object is rebound to a replacement. */ export declare function danglingEdges(graph: SqlObjectGraph, dropped: Set): ObjectEdge[]; /** * Programs every one of whose object-creating statements creates only * `dropped` objects — whole changes owned by the dropped set, prunable from * the plan by ownership (read from the graph, not counted from survivors). * Programs that create nothing are never pruned. */ export declare function prunablePrograms(graph: SqlObjectGraph, dropped: Set): string[];