UNPKG

reduct-js

Version:

ReductStore Client SDK for Javascript/NodeJS/Typescript

76 lines (75 loc) 2.03 kB
/// <reference types="node" /> /// <reference types="node" /> import { LabelMap } from "./Record"; import { APIError } from "./APIError"; import { HttpClient } from "./http/HttpClient"; /** * Represents a batch of records for writing */ export declare enum BatchType { WRITE = 0, UPDATE = 1, REMOVE = 2 } export declare class Batch { private readonly bucketName; private readonly entryName; private readonly httpClient; private readonly type; private readonly records; private totalSize; private lastAccess; constructor(bucketName: string, entryName: string, httpClient: HttpClient, type: BatchType); /** * Add record to batch * @param ts timestamp of record as a UNIX timestamp in microseconds * @param data {Buffer | string} data to write * @param contentType default: application/octet-stream * @param labels default: {} */ add(ts: bigint, data: Buffer | string, contentType?: string, labels?: LabelMap): void; /** * Add only labels to batch * Use for updating labels * @param ts timestamp of record as a UNIX timestamp in microseconds * @param labels */ addOnlyLabels(ts: bigint, labels: LabelMap): void; /** * Add only timestamp to batch * Use for removing records * @param ts timestamp of record as a UNIX timestamp in microseconds */ addOnlyTimestamp(ts: bigint): void; /** * Write batch to entry */ write(): Promise<Map<bigint, APIError>>; /** * Get records in batch sorted by timestamp */ items(): IterableIterator<[ bigint, { data: Buffer; contentType: string; labels: LabelMap; } ]>; /** * Get total size of batch */ size(): bigint; /** * Get last access time of batch */ lastAccessTime(): number; /** * Get number of records in batch */ recordCount(): number; /** * Clear batch */ clear(): void; }