import { ILogger } from '../../../logger'; import { KeyType } from '../../../../modules/key'; import { StreamService } from '../../index'; import { KeyStoreParams, StringAnyType } from '../../../../types'; import { PostgresClientType } from '../../../../types/postgres'; import { PublishMessageConfig, StreamConfig, StreamMessage, StreamStats } from '../../../../types/stream'; import { ProviderClient, ProviderTransaction } from '../../../../types/provider'; /** * Resolved stream target containing the table name and simplified stream name. */ export interface StreamTarget { tableName: string; streamName: string; isEngine: boolean; } /** * PostgreSQL Stream Service * * Uses separate `engine_streams` and `worker_streams` tables for * security isolation and independent scaling. The `worker_streams` * table includes a `workflow_name` column for routing. */ declare class PostgresStreamService extends StreamService { namespace: string; appId: string; logger: ILogger; /** * When true, all worker stream operations use SECURITY DEFINER * stored procedures instead of raw SQL. Enabled when the worker * connects with scoped `workerCredentials`. */ securedMode: boolean; private scoutManager; private liveness; private notificationManager; constructor(streamClient: PostgresClientType & ProviderClient, storeClient: ProviderClient, config?: StreamConfig); init(namespace: string, appId: string, logger: ILogger): Promise; private isNotificationsEnabled; private checkForMissedMessages; /** * Notification-driven fetch with coalescing. NOTIFYs that arrive while * a fetch is in flight set fetchPending instead of issuing concurrent * claim queries (a burst of N inserts otherwise triggers N claims per * consumer, most returning empty). The drain loop re-fetches while the * batch came back full or a NOTIFY arrived mid-fetch. */ private fetchAndDeliverMessages; private getConsumerKey; /** * Resolves a conjoined stream key (e.g., `hmsh:appId:x:topic`) into * the correct table name and simplified stream name. */ resolveStreamTarget(streamKey: string): StreamTarget; mintKey(type: KeyType, params: KeyStoreParams): string; transact(): ProviderTransaction; getEngineTableName(): string; getWorkerTableName(): string; safeName(appId: string): string; createStream(streamName: string): Promise; deleteStream(streamName: string): Promise; createConsumerGroup(streamName: string, groupName: string): Promise; deleteConsumerGroup(streamName: string, groupName: string): Promise; /** * `publishMessages` can be roped into a transaction by the `store` * service. The `stream` provider generates SQL and params that are * added to the transaction for atomic execution. */ publishMessages(streamName: string, messages: string[], options?: PublishMessageConfig): Promise; /** * Schedule a NOTIFY for a worker stream after a delay. Used to wake up * consumers when a visibility-delayed retry message becomes visible, * avoiding the need to wait for the scout's fallback poll. */ scheduleStreamNotify(streamName: string, delayMs: number): void; _publishMessages(streamName: string, messages: string[], options?: PublishMessageConfig): { sql: string; params: any[]; }; consumeMessages(streamName: string, groupName: string, consumerName: string, options?: { batchSize?: number; blockTimeout?: number; autoAck?: boolean; reservationTimeout?: number; enableBackoff?: boolean; initialBackoff?: number; maxBackoff?: number; maxRetries?: number; enableNotifications?: boolean; notificationCallback?: (messages: StreamMessage[]) => void; }): Promise; private shouldUseNotifications; private setupNotificationConsumer; stopNotificationConsumer(streamName: string, groupName: string): Promise; private fetchMessages; /** * Refreshes an owned reservation (heartbeat). Called by the consumer * while an activity callback is still running so the message stays * leased past the base reservation window. Returns 0 when the lease * is no longer this consumer's to hold (reclaimed, acked, or expired). */ extendReservation(streamName: string, messageId: string, consumerName: string): Promise; /** * Soft-deletes every live stream row that belongs to a job, across the * worker and engine stream tables. Called by the engine when a job is * interrupted or scrubbed so its queued, reserved, and scheduled-retry * messages are never delivered again. */ expireJobMessages(jid: string): Promise; ackAndDelete(streamName: string, groupName: string, messageIds: string[]): Promise; deadLetterMessages(streamName: string, groupName: string, messageIds: string[]): Promise; acknowledgeMessages(streamName: string, groupName: string, messageIds: string[], options?: StringAnyType): Promise; deleteMessages(streamName: string, groupName: string, messageIds: string[], options?: StringAnyType): Promise; retryMessages(streamName: string, groupName: string, options?: { consumerName?: string; minIdleTime?: number; messageIds?: string[]; delay?: number; maxRetries?: number; limit?: number; }): Promise; isScout(): boolean; getStreamStats(streamName: string): Promise; getStreamDepth(streamName: string): Promise; getStreamDepths(streamNames: { stream: string; }[]): Promise<{ stream: string; depth: number; }[]>; trimStream(streamName: string, options: { maxLen?: number; maxAge?: number; exactLimit?: boolean; }): Promise; getProviderSpecificFeatures(): { supportsReservationExtension: boolean; supportsBatching: boolean; supportsDeadLetterQueue: boolean; supportsOrdering: boolean; supportsTrimming: boolean; supportsRetry: boolean; supportsNotifications: boolean; supportsParallelProcessing: boolean; maxMessageSize: number; maxBatchSize: number; }; cleanup(): Promise; } export { PostgresStreamService };