import { type Id } from "../identifier.utils.js"; import { type ValueOf } from "../../type.utils.js"; import { type Consumer } from "../offset/offset.utils.js"; import { type ParsedHeaderEntry } from "./header.utils.js"; import { Transform } from "node:stream"; import { type IggyMessageHeader } from "./iggy-header.utils.js"; /** * Enumeration of message polling strategies. */ export declare const PollingStrategyKind: { /** Poll from a specific offset */ readonly Offset: 1; /** Poll from a specific timestamp */ readonly Timestamp: 2; /** Poll from the first message */ readonly First: 3; /** Poll from the last message */ readonly Last: 4; /** Poll the next unconsumed message */ readonly Next: 5; }; /** Type alias for the PollingStrategyKind object */ export type PollingStrategyKind = typeof PollingStrategyKind; /** String literal type of polling strategy names */ export type PollingStrategyKindId = keyof PollingStrategyKind; /** Numeric values of polling strategies */ export type PollingStrategyKindValue = ValueOf; /** Polling from a specific offset */ export type OffsetPollingStrategy = { kind: PollingStrategyKind["Offset"]; /** Offset to start polling from */ value: bigint; }; /** Polling from a specific timestamp */ export type TimestampPollingStrategy = { kind: PollingStrategyKind["Timestamp"]; /** Timestamp in microseconds */ value: bigint; }; /** Polling from the first message */ export type FirstPollingStrategy = { kind: PollingStrategyKind["First"]; value: 0n; }; /** Polling from the last message */ export type LastPollingStrategy = { kind: PollingStrategyKind["Last"]; value: 0n; }; /** Polling the next unconsumed message */ export type NextPollingStrategy = { kind: PollingStrategyKind["Next"]; value: 0n; }; /** Union of all polling strategy types */ export type PollingStrategy = OffsetPollingStrategy | TimestampPollingStrategy | FirstPollingStrategy | LastPollingStrategy | NextPollingStrategy; /** * Factory object for creating polling strategies. */ export declare const PollingStrategy: { Next: NextPollingStrategy; First: FirstPollingStrategy; Last: LastPollingStrategy; Offset: (n: bigint) => OffsetPollingStrategy; Timestamp: (n: bigint) => TimestampPollingStrategy; }; /** * Serializes a poll messages command payload. * * @param streamId - Stream identifier * @param topicId - Topic identifier * @param consumer - Consumer configuration * @param partitionId - Partition ID (null for all partitions) * @param pollingStrategy - Strategy for selecting messages * @param count - Maximum number of messages to poll * @param autocommit - Whether to auto-commit offset after polling * @returns Serialized command payload */ export declare const serializePollMessages: (streamId: Id, topicId: Id, consumer: Consumer, partitionId: number | null, pollingStrategy: PollingStrategy, // default to OffsetPollingStrategy count?: number, autocommit?: boolean) => Buffer; /** * Enumeration of message states. */ export declare const MessageState: { /** Message is available for consumption */ Available: number; /** Message is temporarily unavailable */ Unavailable: number; /** Message processing failed */ Poisoned: number; /** Message is scheduled for deletion */ MarkedForDeletion: number; }; /** Type alias for the MessageState object */ type MessageState = typeof MessageState; /** String literal type of message state names */ type MessageStateId = keyof MessageState; /** * Maps a numeric message state to its string identifier. * * @param k - Numeric state value * @returns State identifier string * @throws Error if the state is unknown */ export declare const mapMessageState: (k: number) => MessageStateId; /** * A polled message with headers, payload, and user headers. */ export type Message = { /** Iggy message header metadata */ headers: IggyMessageHeader; /** Message payload data */ payload: Buffer; /** User-defined headers */ userHeaders: ParsedHeaderEntry[]; }; /** * Response from a poll messages command. */ export type PollMessagesResponse = { /** Partition the messages came from */ partitionId: number; /** Current offset in the partition */ currentOffset: bigint; /** Number of messages returned */ count: number; /** Array of polled messages */ messages: Message[]; }; /** * A message frame decoded from a batch record, with absolute values * resolved against the record header. */ export type BatchMessage = { /** Frame checksum, passed through unverified */ checksum: bigint; /** Unique message identifier */ id: bigint; /** Absolute message offset within the partition */ offset: bigint; /** Server timestamp of the record in microseconds */ timestamp: bigint; /** Message origin timestamp in microseconds */ originTimestamp: bigint; /** Message payload data */ payload: Buffer; /** Raw user header bytes */ userHeaders: Buffer; }; /** * Deserializes batch records into message frames with absolute values. * Each record is [batch header][frames], walked by the record's batch * length. Records may be server-sliced, so the first frame of a record * can carry a non-zero offset delta. * * @param b - Buffer containing serialized batch records * @param pos - Starting position in the buffer * @returns Array of decoded message frames * @throws Error if a record or frame is malformed */ export declare const deserializeBatchMessages: (b: Buffer, pos?: number) => BatchMessage[]; /** * Deserializes an array of messages from a buffer of batch records. * * @param b - Buffer containing serialized batch records * @param pos - Starting position in the buffer * @returns Array of deserialized messages */ export declare const deserializeMessages: (b: Buffer, pos?: number) => Message[]; /** * Deserializes a poll messages response from a buffer. * * @param r - Response buffer * @param pos - Starting position * @returns Parsed PollMessagesResponse */ export declare const deserializePollMessages: (r: Buffer, pos?: number) => { partitionId: number; currentOffset: bigint; count: number; messages: Message[]; }; /** * Creates a Transform stream for deserializing poll messages responses. * * @returns Transform stream that outputs PollMessagesResponse objects */ export declare const deserializePollMessagesTransform: () => Transform; export {}; //# sourceMappingURL=poll.utils.d.ts.map