reduct-js
Version:
ReductStore Client SDK for Javascript/NodeJS/Typescript
76 lines (75 loc) • 2.21 kB
TypeScript
import { Buffer } from "buffer";
import { APIError } from "./APIError";
import { HttpClient } from "./http/HttpClient";
import { LabelMap } from "./Record";
type RecordBatchItem = {
entry: string;
timestamp: bigint;
data: Buffer;
contentType: string;
labels: LabelMap;
};
export declare enum RecordBatchType {
WRITE = 0,
UPDATE = 1,
REMOVE = 2
}
/**
* Batch of records to write them in one request (batch protocol v2).
*/
export declare class RecordBatch {
private readonly bucketName;
private readonly httpClient;
private readonly type;
private readonly records;
private totalSize;
private lastAccess;
constructor(bucketName: string, httpClient: HttpClient, type: RecordBatchType);
/**
* Add record to batch with entry name.
* @param entry name of entry
* @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(entry: string, ts: bigint, data: Buffer | string, contentType?: string, labels?: LabelMap): void;
/**
* Add labels to batch for update.
* @param entry name of entry
* @param ts timestamp of record as a UNIX timestamp in microseconds
* @param labels labels to update
*/
addOnlyLabels(entry: string, ts: bigint, labels: LabelMap): void;
/**
* Add timestamps to batch for removal.
* @param entry name of entry
* @param ts timestamp of record as a UNIX timestamp in microseconds
*/
addOnlyTimestamp(entry: string, ts: bigint): void;
/**
* Send batch request (Multi-entry API).
*/
send(): Promise<Map<string, Map<bigint, APIError>>>;
/**
* Get records in batch sorted by timestamp and entry name.
*/
items(): Array<[[string, bigint], RecordBatchItem]>;
/**
* 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;
}
export {};