import { ILogger } from '../../../logger'; import { PostgresClientType } from '../../../../types/postgres'; import { PublishMessageConfig, StreamMessage } from '../../../../types/stream'; import { ProviderClient, ProviderTransaction } from '../../../../types/provider'; export declare function getMessagePriority(msgType: string | undefined): number; /** * Publish messages to a stream. Can be used within a transaction. * * When a transaction is provided, the SQL is added to the transaction * and executed atomically with other operations. */ export declare function publishMessages(client: PostgresClientType & ProviderClient, tableName: string, streamName: string, isEngine: boolean, messages: string[], options: PublishMessageConfig | undefined, logger: ILogger): Promise; /** * Build SQL for publishing messages with retry policies and visibility delays. * Routes to engine_streams or worker_streams based on isEngine flag. * Worker messages include a workflow_name column extracted from metadata.wfn. */ export declare function buildPublishSQL(tableName: string, streamName: string, isEngine: boolean, messages: string[], options?: PublishMessageConfig): { sql: string; params: any[]; }; /** * Job-liveness context for the delivery guard. `keyPrefix` is the minted * job-key prefix (`hmsh::j:`) so `keyPrefix || jid` addresses the * jobs row. `enabled` is mutated to false (self-disable) when the jobs * table is not visible from the stream connection. */ export interface JobLivenessContext { jobsTable: string; keyPrefix: string; enabled: boolean; } /** * Soft-delete every live stream row that belongs to a job. Called when a * job is interrupted so its queued, reserved, and scheduled-retry * messages are never delivered again. Uses the partial jid indexes * (idx_*_streams_jid_created); runs once per interrupt. */ export declare function expireJobMessages(client: PostgresClientType & ProviderClient, tableNames: string[], jid: string, logger: ILogger): Promise; /** * Refresh an owned reservation (heartbeat). Scoped to the owning * consumer and to live rows: a message that was reclaimed by another * consumer, acked, or expired (job interrupted) reports 0 so the * stale consumer can abandon its execution. */ export declare function extendReservation(client: PostgresClientType & ProviderClient, tableName: string, streamName: string, messageId: string, consumerName: string, logger: ILogger): Promise; /** * Fetch messages from the stream with optional exponential backoff. * Uses SKIP LOCKED for high-concurrency consumption. * No group_name filter needed - the table itself determines engine vs worker. */ export declare function fetchMessages(client: PostgresClientType & ProviderClient, tableName: string, streamName: string, isEngine: boolean, consumerName: string, options: { batchSize?: number; blockTimeout?: number; autoAck?: boolean; reservationTimeout?: number; enableBackoff?: boolean; initialBackoff?: number; maxBackoff?: number; maxRetries?: number; }, logger: ILogger, liveness?: JobLivenessContext): Promise; /** * Acknowledge messages (no-op for PostgreSQL - uses soft delete pattern). */ export declare function acknowledgeMessages(messageIds: string[]): Promise; /** * Delete messages by soft-deleting them (setting expired_at). * No group_name needed - stream_name + table is sufficient. */ export declare function deleteMessages(client: PostgresClientType & ProviderClient, tableName: string, streamName: string, messageIds: string[], logger: ILogger): Promise; /** * Acknowledge and delete messages in one operation. */ export declare function ackAndDelete(client: PostgresClientType & ProviderClient, tableName: string, streamName: string, messageIds: string[], logger: ILogger): Promise; /** * Move messages to the dead-letter state by setting dead_lettered_at * and expired_at. The message payload is preserved for inspection. */ export declare function deadLetterMessages(client: PostgresClientType & ProviderClient, tableName: string, streamName: string, messageIds: string[], logger: ILogger): Promise; /** * Retry messages (placeholder for future implementation). */ export declare function retryMessages(streamName: string, groupName: string, options?: { consumerName?: string; minIdleTime?: number; messageIds?: string[]; delay?: number; maxRetries?: number; limit?: number; }): Promise;