import { Pgoutput } from 'pg-logical-replication'; import { DbLogger } from '../common'; export type LogicalReplicationOperation = 'begin' | 'commit' | 'delete' | 'insert' | 'message' | 'origin' | 'relation' | 'truncate' | 'type' | 'update'; export interface PgOutputScopedMessage { operation: LogicalReplicationOperation; tableName?: string; schemaName?: string; new?: Record; old?: Record; } export interface LogicalReplicatonMessageHandlerParams { scopedMessage: PgOutputScopedMessage; fullMessage: Pgoutput.Message; } export type LogicalReplicationMessageHandler = (params: LogicalReplicatonMessageHandlerParams) => Promise; /** * Configuration object to set up a logical replication service. */ export interface LogicalReplicationServiceConfig { connectionString: string; /** * Array of publication names for tables which changes would be watched. * Must be defined beforehand on database level, e.g. using `ensureReplicationSlotAndPublicationExist` */ publicationNames: string[]; /** * Name of the replication slot which will be streaming table changes. * Must be defined beforehand on database level, e.g. using `ensureReplicationSlotAndPublicationExist` */ replicationSlotName: string; /** * Decides how to react to detected table changes. */ messageHandler: LogicalReplicationMessageHandler; /** * An array of operations that will be handled and redirected to the * `messageHandler`. Other operations will be skipped, each producing a TRACE * log. */ operationsToWatch?: LogicalReplicationOperation[]; /** * Produces logs during the logical replication service runtime. If not * passed, console logs are used instead. */ logger?: DbLogger; /** * When logical replication service establishes a connection with a * replication slot - it can already be in use, e.g. by another instance of * the service. The logical replication service will then try to reconnect * once every 10 seconds for a total duration of 5 minutes. * * After the first 5 minutes, the delay of reconnection attempts will be * increased from 10 seconds to the value of this parameter. Default value is * 300000 (every 5 minutes). */ reconnectionIntervalInMs?: number; } /** * Creates a logical replication service and keeps it running until stopped. * Watches the table changes based on passed publication names and replication * slot, handling messages based on the passed message handler. By default * watches the "insert", "update", and "delete" operations. * * In case of errors, the service will try to recover for 20 attempts with an * incremental delay between attempts for a total of ~5 minutes. Any success * would reset the error attempts counter. Each failure will be logged with an * attempts counter value. If 5 minutes passes without any errors - the errors * counter is reset. If the counter increases over 20 in * the span of 5 minutes - causing error will be thrown to crash the process * to trigger a service reload that might resolve the issue. * * @param config Connection and processing config for the logical replication * service. * @returns a function to stop the logical replication service. */ export declare const createLogicalReplicationService: ({ connectionString, publicationNames, replicationSlotName, messageHandler, operationsToWatch, logger: passedLogger, reconnectionIntervalInMs, }: LogicalReplicationServiceConfig) => Promise<{ (): Promise; }>; //# sourceMappingURL=create-logical-replication-service.d.ts.map