@ydbjs/topic
Version:
YDB Topics client for publish-subscribe messaging. Provides at-least-once delivery, exactly-once publishing, FIFO guarantees, and scalable message processing for unstructured data.
96 lines • 3.75 kB
TypeScript
import type { StreamReadMessage_InitRequest_TopicReadSettings } from '@ydbjs/api/topic';
import type { Driver } from '@ydbjs/core';
import type { StringValue } from 'ms';
import type { CodecMap } from '../codec.js';
import type { TopicPartitionSession } from '../partition-session.js';
import type { TX } from '../tx.js';
export type TopicReaderSource = {
/**
* Topic path.
*/
path: string;
/**
* Partitions that will be read by this session.
* If list is empty - then session will read all partitions.
*/
partitionIds?: bigint[];
/**
* Skip all messages that has write timestamp smaller than now - max_lag.
* Zero means infinite lag.
*/
maxLag?: number | StringValue | import('@bufbuild/protobuf/wkt').Duration;
/**
* Read data only after this timestamp from this topic.
* Read only messages with 'written_at' value greater or equal than this timestamp.
*/
readFrom?: number | Date | import('@bufbuild/protobuf/wkt').Timestamp;
};
export type onPartitionSessionStartCallback = (partitionSession: TopicPartitionSession, committedOffset: bigint, partitionOffsets: {
start: bigint;
end: bigint;
}) => Promise<void | undefined | {
readOffset?: bigint;
commitOffset?: bigint;
}>;
export type onPartitionSessionStopCallback = (partitionSession: TopicPartitionSession, committedOffset: bigint) => Promise<void>;
export type onCommittedOffsetCallback = (partitionSession: TopicPartitionSession, committedOffset: bigint) => void;
export type TopicReaderOptions = {
topic: string | TopicReaderSource | TopicReaderSource[];
consumer: string;
codecMap?: CodecMap;
maxBufferBytes?: bigint;
updateTokenIntervalMs?: number;
onPartitionSessionStart?: onPartitionSessionStartCallback;
onPartitionSessionStop?: onPartitionSessionStopCallback;
onCommittedOffset?: onCommittedOffsetCallback;
};
export interface TopicReader extends AsyncDisposable, Disposable {
read(options?: {
limit?: number;
waitMs?: number;
signal?: AbortSignal;
}): AsyncIterable<import('../message.js').TopicMessage[]>;
commit(input: import('../message.js').TopicMessage | import('../message.js').TopicMessage[]): Promise<void>;
close(): Promise<void>;
destroy(reason?: Error): void;
}
export interface TopicTxReader {
read(options?: {
limit?: number;
waitMs?: number;
signal?: AbortSignal;
}): AsyncIterable<import('../message.js').TopicMessage[]>;
close(): Promise<void>;
destroy(reason?: Error): void;
}
export type TopicReaderState = TopicBaseReaderState & {
readonly options: TopicReaderOptions;
readonly pendingCommits: Map<bigint, TopicCommitPromise[]>;
};
export type TopicBaseReaderState = {
readonly driver: Driver;
readonly topicsReadSettings: StreamReadMessage_InitRequest_TopicReadSettings[];
readonly controller: AbortController;
disposed: boolean;
readonly outgoingQueue: import('../queue.js').AsyncPriorityQueue<import('@ydbjs/api/topic').StreamReadMessage_FromClient>;
readonly buffer: import('@ydbjs/api/topic').StreamReadMessage_ReadResponse[];
readonly partitionSessions: Map<bigint, TopicPartitionSession>;
readonly codecs: CodecMap;
readonly maxBufferSize: bigint;
freeBufferSize: bigint;
};
export type TopicTxReaderState = TopicBaseReaderState & {
readonly tx: TX;
readonly options: TopicReaderOptions;
readonly readOffsets: Map<bigint, {
firstOffset: bigint;
lastOffset: bigint;
}>;
};
export type TopicCommitPromise = {
partitionSessionId: bigint;
offset: bigint;
resolve: () => void;
reject: (reason?: any) => void;
};
//# sourceMappingURL=types.d.ts.map