import { type StatePrefixConfig } from "../state-prefix.js"; import type { PathwayChunkStore, PathwayChunkStoreResult, StorePathwayChunkPartInput } from "../types.js"; import type { PostgresPoolConfig } from "./postgres-adapter.js"; /** * Configuration for the PostgreSQL chunk store using a connection string */ export interface PostgresPathwayChunkStoreConnectionStringConfig extends StatePrefixConfig { /** Complete PostgreSQL connection string */ connectionString: string; /** These properties are not used when a connection string is provided */ host?: never; port?: never; user?: never; password?: never; database?: never; ssl?: never; /** Explicit table name. Overrides `statePrefix`. Default: `"pathway_chunks"`. */ tableName?: string; /** Time-to-live in milliseconds for parts of an incomplete chunk (default: 1 hour) */ ttlMs?: number; /** * Minimum time between two sweeps of expired rows, in milliseconds. * Defaults to 60 000. `0` sweeps on every `storePart` call (the pre-2.10.1 behaviour). */ cleanupIntervalMs?: number; /** Connection pool configuration */ pool?: PostgresPoolConfig; } /** * Configuration for the PostgreSQL chunk store using individual parameters */ export interface PostgresPathwayChunkStoreParametersConfig extends StatePrefixConfig { /** Not used when individual parameters are provided */ connectionString?: never; /** PostgreSQL server hostname */ host: string; /** PostgreSQL server port */ port: number; /** PostgreSQL username */ user: string; /** PostgreSQL password */ password: string; /** PostgreSQL database name */ database: string; /** Whether to use SSL for the connection */ ssl?: boolean; /** Explicit table name. Overrides `statePrefix`. Default: `"pathway_chunks"`. */ tableName?: string; /** Time-to-live in milliseconds for parts of an incomplete chunk (default: 1 hour) */ ttlMs?: number; /** * Minimum time between two sweeps of expired rows, in milliseconds. * Defaults to 60 000. `0` sweeps on every `storePart` call (the pre-2.10.1 behaviour). */ cleanupIntervalMs?: number; /** Connection pool configuration */ pool?: PostgresPoolConfig; } /** * Configuration options for the PostgreSQL chunk store */ export type PostgresPathwayChunkStoreConfig = PostgresPathwayChunkStoreConnectionStringConfig | PostgresPathwayChunkStoreParametersConfig; /** * PostgreSQL implementation of {@link PathwayChunkStore}. * * Parts of one oversized event are collected in a shared table so any instance * can receive any part. Assembly is serialized per chunk with a transaction-scoped * advisory lock, so exactly one caller observes `complete`. * * - Exact replays of a part are accepted and reported as `duplicate` * - A part with the same key but different data is rejected with an error * - Parts of incomplete chunks expire after `ttlMs` and are removed on the next write * * @example * ```typescript * const chunkStore = createPostgresPathwayChunkStore({ * connectionString: "postgres://user:password@localhost:5432/mydb", * statePrefix: "compute_api", // optional, yields compute_api_pathway_chunks * }) * * pathways.withPathwayChunkStore(chunkStore) * ``` */ export declare class PostgresPathwayChunkStore implements PathwayChunkStore { private config; /** Default time-to-live for parts of an incomplete chunk (1 hour) */ private static readonly DEFAULT_TTL_MS; private static readonly DEFAULT_CLEANUP_INTERVAL_MS; private static readonly DEFAULT_TABLE_NAME; private postgres; private readonly tableName; private readonly ttlMs; private readonly cleanupIntervalMs; private lastCleanupAt; private initialized; constructor(config: PostgresPathwayChunkStoreConfig); /** The resolved table name */ get table(): string; private initialize; /** * Records one part under a per-chunk advisory lock and reports completion * @param input The part to record * @returns The store result; exactly one caller per chunk receives `complete` * @throws {Error} When the same part arrives with different data */ storePart(input: StorePathwayChunkPartInput): Promise; /** * Removes every part of a chunk * @param chunkId The chunk to remove */ deleteChunk(chunkId: string): Promise; /** * Closes the database connection */ close(): Promise; private cleanupExpiredIfDue; private cleanupExpired; } /** * Creates a PostgreSQL chunk store * @param config The PostgreSQL configuration * @returns A new {@link PostgresPathwayChunkStore} */ export declare function createPostgresPathwayChunkStore(config: PostgresPathwayChunkStoreConfig): PostgresPathwayChunkStore; //# sourceMappingURL=postgres-pathway-chunk-store.d.ts.map