import type { PostgresRelationship } from "../types.ts"; import type { Queryable } from "./index.ts"; /** * Port of `postgres-meta/src/lib/PostgresMetaRelationships.ts`. * * The relationships used for type generation come in two parts: * 1. table↔table m2o/o2o relationships, read directly from `pg_constraint` * (`TABLE_RELATIONSHIPS_SQL`); and * 2. relationships that involve a view on either side, which PostgREST derives * by mapping a base table's foreign key columns onto the view columns that * select them (`VIEWS_KEY_DEPENDENCIES_SQL` + the cartesian-product * expansion below). This second part is pure TypeScript, not SQL — ported * verbatim from upstream. * * Adapted from: * https://github.com/PostgREST/postgrest/blob/f9f0f79fa914ac00c11fbf7f4c558e14821e67e2/src/PostgREST/SchemaCache.hs#L392 */ type ColDep = { table_column: string; view_columns: string[]; }; export type ViewKeyDependency = { table_schema: string; table_name: string; view_schema: string; view_name: string; constraint_name: string; constraint_type: "f" | "f_ref" | "p" | "p_ref"; column_dependencies: ColDep[]; }; /** * Expand the table↔table relationships into the view↔table / table↔view / * view↔view relationships implied by the view key dependencies. Pure function * (no database) so the cartesian-product expansion can be unit-tested directly. * * Ported verbatim from `PostgresMetaRelationships.list()` (the body of the * `allViewM2oAndO2oRelationships` block). */ export declare function expandViewRelationships(allTableM2oAndO2oRelationships: PostgresRelationship[], viewsKeyDependencies: ViewKeyDependency[]): PostgresRelationship[]; /** * List all relationships (table↔table plus the view-derived ones) for the * schemas selected by `schemaFilter`, the `IN (…)`/`NOT IN (…)` fragment * `introspect()` builds with the system schemas excluded. Errors from the * injected `Queryable` propagate by throwing — callers adapt. */ export declare function listRelationships(db: Queryable, schemaFilter: string): Promise; export {};