import { Result } from "@openally/result"; import * as utils from "../../utils/stream/index.js"; import type { Data, Entry, Group } from "../../types/index.js"; import { RedisAdapter } from "../adapter/redis.adapter.js"; export interface GetRangeOptions { /** * Reference to the minimal ID we pull from */ min: string; /** * Reference to the maximal ID we pull to */ max: string; /** * Number of max entries pulled out */ count?: number; } export interface XINFOStreamData { length: number; radixTreeKeys: number; radixTreeNodes: number; lastGeneratedId: string; entries: Entry[]; groups?: Group[]; } export interface ConsumeOptions { lastId: string; count?: number; block?: number; } export interface PushOptions { id?: string; metadata?: string; } export type DelEntryResponse = Result; export interface StreamOptions { redis: RedisAdapter; streamName: string; /** * Interval of time between two iteration on the stream */ frequency: number; /** * Reference to the minimal ID we iterate from */ lastId?: string; /** * Number of entries it must pull at each iteration */ count?: number; } /** * * @description Shared method used to work on a Redis Stream */ export declare class Stream { streamName: string; lastId: string; protected frequency: number; protected count?: number; protected redis: RedisAdapter; constructor(options: StreamOptions); streamExist(): Promise; /** * * @description In order to create a new Redis stream, we must push a first entry */ init(): Promise; getInfo(): Promise; getLength(): Promise; getGroupsData(): Promise; /** * * @description Push a new entry on the stream, if no ID provided, use the special ID "*". * Using the special ID "*", Redis generate IDs as follow 1526985685298-0, the first part * being a timestamp, and the second an increment. * @param {data: { key: string; value: string | Buffer | number }, options: { id?: string; metadata?: string }} [options] * @returns {Promise} * @example * ```ts * // Push an Entry with a custom ID * const entryId = await push({ foo: "bar" }, { id: "any-custom-id" }); * console.log(entryId) // "any-custom-string" * ``` * @example * ```ts * // Push an Entry without a custom ID * const entryId = await push({ foo: "bar" }, { metadata: "" }); * console.log(entryId) // 1526985685298-0 * ``` */ push(data: Data, options?: PushOptions): Promise; delEntry(entryId: string): Promise; handleEntries(entries: utils.XEntries, cursor?: string): Promise; /** * * @description Return a range of elements in a stream, with IDs matching the specified IDs interval. * @param {{ min: string; max: string; count?: number; }} [options={ min: "-", max: "+" }] * @returns {Promise} * @example * ```ts * // Return all entries * await getRange({ min: "-", max: "+" }) * ``` * @example * ```ts * // Return single Entry * await getRange({ min: "1526985685298-0", max: "1526985685298-0" }) * ``` * @example * ```ts * // Return entries between those timestamp (inclusive) * await getRange({ min: "1526985054069", max: "1526985055069"}) * ``` * @example * ```ts * // Return Entry with id 1526985676425-0 & 1526985685298-0 * await getRange({ min: "-", max: "+", count: 2}) * // Return two next Entry, "(" excluding the given id * await getRange({ min: "(1526985685298-0", max: "+", count: 2 }) * ``` */ getRange(options?: GetRangeOptions): Promise; /** * * @description Return a range of elements in a stream, with IDs matching the specified IDs interval, * in reverse order (from greater to smaller IDs). * @param {{ min: string; max: string; count?: number; }} [options={ min: "-", max: "+" }] * @returns {Promise} * @example * ```ts * // Return all entries * await getRevRange({ min: "-", max: "+" }) * ``` * @example * ```ts * // Return single Entry * await getRevRange({ min: "1526985685298-0", max: "1526985685298-0" }) * ``` * @example * ```ts * // Return entries between those timestamp (inclusive) * await getRevRange({ min: "1526985054069", max: "1526985055069"}) * ``` * @example * ```ts * // Return Entry with id 1526985676425-0 & 1526985685298-0 * await getRevRange({ min: "-", max: "+", count: 2}) * // Return two next Entry, "(" excluding the given id * await getRevRange({ min: "(1526985685298-0", max: "+", count: 2 }) * ``` */ getRevRange(options?: GetRangeOptions): Promise; /** * * @description Trim the stream, if the threshold is a number, then it is considered as a max-length, * if the threshold is a string, then it is considered as a reference to an ID/Timestamp. * @param {(number | string)} threshold * @returns {Promise} * @example * ```ts * // Given a number, it acts like a max-lenght * for (let index = 0; index < 1000; index++) await push({ data: { key: "foo", value: "bar" }}) * const nbEvictedEntry = await trim(900) * console.log(nbEvictedEntry) // 100 * ``` */ trim(threshold: number | string): Promise; /** * * @description Check whenever a given group exist for the initialized Stream. * @param {string} name * @returns {Promise} */ groupExist(name: string): Promise; /** * * @description Create a new group related to the initialized Stream. * @param {string} name */ createGroup(name: string): Promise; /** * * @description Delete a group related to the initialized Stream. * @param {string} name */ deleteGroup(name: string): Promise; /** * * @description Return Consumer data for a given group related to the initialized Stream. * @param {string} groupName * @param {string} consumerName * @returns {Promise} */ getConsumerData(groupName: string, consumerName: string): Promise; /** * * @description Check whenever a consumer exist for a given group related to the initialized Stream. * @param {string} groupName * @param {string} consumerName * @returns {Promise} */ consumerExist(groupName: string, consumerName: string): Promise; /** * * @description Create a new consumer for a given group related to the initialized Stream. * @param {string} groupName * @param {string} consumerName */ createConsumer(groupName: string, consumerName: string): Promise; /** * * @description Delete a consumer for a given group related to the initialized Stream. * @param {string} groupName * @param {string} consumerName */ deleteConsumer(groupName: string, consumerName: string): Promise; } //# sourceMappingURL=Stream.class.d.ts.map