reduct-js
Version:
ReductStore Client SDK for Javascript/NodeJS/Typescript
174 lines (173 loc) • 6.34 kB
TypeScript
import { BucketSettings } from "./messages/BucketSettings";
import { BucketInfo } from "./messages/BucketInfo";
import { EntryInfo } from "./messages/EntryInfo";
import { LabelMap, ReadableRecord, WritableRecord } from "./Record";
import { Batch } from "./Batch";
import { QueryOptions } from "./messages/QueryEntry";
import { HttpClient } from "./http/HttpClient";
/**
* Options for writing records
*/
export interface WriteOptions {
ts?: bigint;
labels?: LabelMap;
contentType?: string;
}
/**
* Represents a bucket in ReductStore
*/
export declare class Bucket {
private name;
private readonly httpClient;
/**
* Create a bucket. Use Client.creatBucket or Client.getBucket instead it
* @constructor
* @param name
* @param httpClient
* @see {Client}
*/
constructor(name: string, httpClient: HttpClient);
/**
* Get bucket settings
* @async
* @return {Promise<BucketSettings>}
*/
getSettings(): Promise<BucketSettings>;
/**
* Set bucket settings
* @async
* @param settings {BucketSettings} new settings (you can set a part of settings)
*/
setSettings(settings: BucketSettings): Promise<void>;
/**
* Get information about a bucket
* @async
* @return {Promise<BucketInfo>}
*/
getInfo(): Promise<BucketInfo>;
/**
* Get entry list
* @async
* @return {Promise<EntryInfo>}
*/
getEntryList(): Promise<EntryInfo[]>;
/**
* Remove bucket
* @async
* @return {Promise<void>}
*/
remove(): Promise<void>;
/**
* Remove an entry
* @async
* @param entry {string} name of the entry
* @return {Promise<void>}
*/
removeEntry(entry: string): Promise<void>;
/**
* Remove a record
* @param entry {string} name of the entry
* @param ts {BigInt} timestamp of record in microseconds
*/
removeRecord(entry: string, ts: bigint): Promise<void>;
/**
* Remove a batch of records
* @param entry {string} name of the entry
* @param tsList {BigInt[]} list of timestamps of records in microseconds
*/
beginRemoveBatch(entry: string): Promise<Batch>;
/**
* Remove records by query
* @param entry {string} name of the entry
* @param start {BigInt} start point of the time period, if undefined, the query starts from the first record
* @param stop {BigInt} stop point of the time period. If undefined, the query stops at the last record
* @param options {QueryOptions} options for query. You can use only include, exclude, eachS, eachN other options are ignored
*/
removeQuery(entry: string, start?: bigint, stop?: bigint, options?: QueryOptions): Promise<number>;
/**
* Start writing a record into an entry
* @param entry name of the entry
* @param options {BigInt | WriteOptions} timestamp in microseconds for the record or options. It is current time if undefined.
* @return Promise<WritableRecord>
* @example
* const record = await bucket.beginWrite("entry", {
* ts: 12345667n
* labels: {label1: "value1", label2: "value2"}
* contentType: "text/plain"
* );
* await record.write("Hello!");
*/
beginWrite(entry: string, options?: bigint | WriteOptions): Promise<WritableRecord>;
/**
* Update labels of an existing record
*
* If a label has empty string value, it will be removed.
*
* @param entry {string} name of the entry
* @param ts {BigInt} timestamp of record in microseconds
* @param labels {LabelMap} labels to update
*/
update(entry: string, ts: bigint, labels: LabelMap): Promise<void>;
/**
* Start reading a record from an entry
* @param entry name of the entry
* @param ts {BigInt} timestamp of record in microseconds. Get the latest one, if undefined
* @param head {boolean} return only head of the record
* @return Promise<ReadableRecord>
*/
beginRead(entry: string, ts?: bigint, head?: boolean): Promise<ReadableRecord>;
/**
* Rename an entry
* @param entry entry name to rename
* @param newEntry new entry name
*/
renameEntry(entry: string, newEntry: string): Promise<void>;
/**
* Rename a bucket
* @param newName new name of the bucket
*/
rename(newName: string): Promise<void>;
/**
* Query records for a time interval as generator
* @param entry entry name
* @param entry {string} name of the entry
* @param start {BigInt} start point of the time period
* @param stop {BigInt} stop point of the time period
* @param options {QueryOptions} options options for query
* @example
* for await (const record in bucket.query("entry-1", start, stop)) {
* console.log(record.ts, record.size);
* console.log(record.labels);
* const content = await record.read();
* // or use pipe
* const fileStream = fs.createWriteStream(`ts_${record.size}.txt`);
* record.pipe(fileStream);
* }
*/
query(entry: string, start?: bigint, stop?: bigint, options?: QueryOptions): AsyncGenerator<ReadableRecord>;
getName(): string;
private readRecord;
private fetchAndParseBatchedRecords;
private readBatchedRecords;
/**
* Create a new batch for writing records to the database.
* @param entry
*/
beginWriteBatch(entry: string): Promise<Batch>;
/**
* Create a new batch for updating records in the database.
* @param entry
*/
beginUpdateBatch(entry: string): Promise<Batch>;
/**
* Create a query link for downloading records
* @param entry name of the entry
* @param start start point of the time period for the query
* @param stop stop point of the time period for the query
* @param query options for the query
* @param recordIndex index of the record to download (0 for the first record, 1 for the second, etc.)
* @param expireAt expiration time of the link. Default is 24 hours from now
* @param fileName name of the file to download. Default is `${entry}_${recordIndex}.bin`
*/
createQueryLink(entry: string, start?: bigint, stop?: bigint, query?: QueryOptions, recordIndex?: number, expireAt?: Date, fileName?: string): Promise<string>;
}