import Pg from "pg"; import { PGlite as Pglite } from "@electric-sql/pglite"; import { DbAdapter } from "./adapter.ts"; import { type TableDetails } from "./kinds/table.ts"; import { type ViewDetails } from "./kinds/view.ts"; import { type MaterializedViewDetails } from "./kinds/materialized-view.ts"; import { type EnumDetails } from "./kinds/enum.ts"; import { type CompositeTypeDetails } from "./kinds/composite.ts"; import { type FunctionDetails } from "./kinds/function.ts"; import { type DomainDetails } from "./kinds/domain.ts"; import { type RangeDetails } from "./kinds/range.ts"; import type { PgType } from "./pgtype.ts"; export { pgTypeKinds, type PgType, type Kind } from "./pgtype.ts"; import { Canonical } from "./canonicalise/index.ts"; export { Canonical }; export type { TableDetails, ViewDetails, MaterializedViewDetails, EnumDetails, CompositeTypeDetails, FunctionDetails, DomainDetails, RangeDetails, }; export type { TableColumn } from "./kinds/table.ts"; export type { ViewColumn } from "./kinds/view.ts"; export type { MaterializedViewColumn } from "./kinds/materialized-view.ts"; export type { FunctionParameter, FunctionReturnType } from "./kinds/function.ts"; export { FunctionReturnTypeKind } from "./kinds/function.ts"; /** * extractSchemas generates a record of all the schemas extracted, indexed by schema name. * The schemas are instances of this type. */ export type Schema = { name: string; table: TableDetails[]; view: ViewDetails[]; materializedView: MaterializedViewDetails[]; enum: EnumDetails[]; composite: CompositeTypeDetails[]; function: FunctionDetails[]; domain: DomainDetails[]; range: RangeDetails[]; }; export type SchemaType = TableDetails | ViewDetails | MaterializedViewDetails | EnumDetails | CompositeTypeDetails | FunctionDetails | DomainDetails | RangeDetails; /** * This is the options object that can be passed to `extractSchemas`. * @see extractSchemas */ export interface ExtractSchemaOptions { /** * Will contain an array of schema names to extract. * If undefined, all non-system schemas will be extracted. */ schemas?: string[]; /** * Filter function that you can use if you want to exclude * certain items from the schemas. */ typeFilter?: (pgType: PgType) => boolean; /** * extractShemas will always attempt to parse view definitions to * discover the "source" of each column, i.e. the table or view that it * is derived from. * If this option is set to `true`, it will attempt to follow this * source and copy values like indices, isNullable, etc. * so that the view data is closer to what the database reflects. */ resolveViews?: boolean; /** * Called with the number of types to extract. */ onProgressStart?: (total: number) => void; /** * Called once for each type that is extracted. */ onProgress?: () => void; /** * Called when all types have been extracted. */ onProgressEnd?: () => void; } export declare class Extractor { db: DbAdapter; /** * @param connectionConfig - Connection string or configuration object for Postgres connection */ constructor(opts: { pg?: Pg.Client | Pg.Pool | Pglite; uri?: string; config?: Pg.ConnectionConfig; }); getBuiltinTypes(): Promise<{ name: string; format: string; kind: string; }[]>; /** * Perform the extraction * @param options - Optional options * @returns A record of all the schemas extracted, indexed by schema name. */ extractSchemas(options?: ExtractSchemaOptions): Promise<{ schemas: Record; queryCount: number; }>; }