/** * Scoped PostgreSQL Plugin * * Wraps the standard postgres() plugin to provide per-project * schema isolation. Each project gets its own Postgres schema * (project_{projectId}), and every connection checkout runs * SET search_path to route queries to the correct schema. * * If ctx._projectId is null (shared services like auth), * returns the raw pool unscoped. */ import type { HealthCheckResult, NginxResult, PostgresOptions, ScopedPluginContext } from "./types.js"; interface PgQueryResult { rows: Record[]; rowCount: number | null; command: string; fields: unknown[]; } interface PgClient { query(text: string, params?: unknown[]): Promise; release(err?: Error | boolean): void; } interface PgPool { query(text: string, params?: unknown[]): Promise; connect(): Promise; end(): Promise; on(event: string, listener: (client: PgClient) => void): void; totalCount: number; idleCount: number; waitingCount: number; } interface ScopedPostgresPlugin { name: "postgres"; version: string; inject: "pg"; validate(): void; env(): Record; connect(ctx: ScopedPluginContext): Promise; healthCheck(pool: ScopedPool | PgPool): Promise; disconnect(pool: ScopedPool | PgPool): Promise; metrics(pool: ScopedPool | PgPool): Record; nginx(): NginxResult; } /** * Create a ScopedPool that wraps a pg.Pool and sets the search_path * on every connection checkout. */ declare class ScopedPool { _pool: PgPool; _schemaName: string; _schemaCreated: boolean; constructor(pool: PgPool, schemaName: string); /** * Ensure the project schema exists (idempotent). */ _ensureSchema(): Promise; /** * Get a scoped connection from the pool. * Sets search_path before returning the client. */ connect(): Promise; /** * Run a query with the scoped search_path. * Acquires a connection via connect() which explicitly sets search_path, * preventing race conditions with idle connections whose search_path was reset. */ query(text: string, params?: unknown[]): Promise; get totalCount(): number; get idleCount(): number; get waitingCount(): number; end(): Promise; } /** * Create a scoped Postgres plugin. */ export declare function scopedPostgres(options?: PostgresOptions): ScopedPostgresPlugin; export {}; //# sourceMappingURL=ScopedPostgres.d.ts.map