import { FactoryStorage } from '@mastra/core/storage'; import type { CollectionSchema, FactoryAuthDatabase, FactoryStorageOps, MastraCompositeStore, RetentionConfig } from '@mastra/core/storage'; import type { Pool } from 'pg'; import { PostgresStore } from './index.js'; export type PgFactoryStorageConfig = { connectionString: string; /** Identifier for the wrapped agent-state store. @default 'pg-factory' */ id?: string; /** Retention config forwarded to the wrapped {@link PostgresStore}. */ retention?: RetentionConfig; } | { /** Wrap an existing store; its pool is shared for app-table ops. */ store: PostgresStore; }; /** * PostgreSQL {@link FactoryStorage} backend: one database powering agent state * (via a wrapped {@link PostgresStore}) and app-owned collections (via * {@link FactoryStorageOps}), sharing a single pool. * * Supports serializable app-table transactions for cross-replica invariant * enforcement and `authDatabase()` exposing the shared pool. */ /** * A pool-level `error` listener only covers *idle* clients: pg hands ownership * of a client to the borrower for the duration of a checkout and takes its own * listener off. So a backend restart or network blip that lands on a client * mid-transaction reaches an emitter with no listener, and Node escalates that * to an uncaughtException that kills the process — the pool handler logs the * idle siblings and the borrowed one still brings everything down. * * Attach a listener once per physical connection instead. `connect` fires when * the pool establishes a client, so the client stays covered for its whole life * and there is nothing to remove on release. * * That listener outlives the checkout, so it also sees the failures the pool is * already reporting through its own idle listener. Follow `acquire`/`release` * to tell the two apart and stay quiet while the client is idle — otherwise one * dropped connection is announced twice, the second time as the wrong thing. * * The pool still discards the failed connection; this only keeps the failure * reportable instead of fatal. */ export declare function guardCheckedOutClientErrors(pool: Pool, warn?: (message?: any, ...optionalParams: any[]) => void): void; export declare class PgFactoryStorage extends FactoryStorage { #private; readonly ops: FactoryStorageOps; constructor(config: PgFactoryStorageConfig); getMastraStorage(): MastraCompositeStore; protected initStorage(): Promise; withTransaction(fn: (ops: FactoryStorageOps) => Promise, options?: { isolationLevel?: 'serializable'; }): Promise; ensureCollections(schemas: CollectionSchema[]): Promise; close(): Promise; authDatabase(): FactoryAuthDatabase; } //# sourceMappingURL=factory-storage.d.ts.map