Skip to main content
Version: 1.18.x

ReductStore Client SDK for JavaScript

npm npm GitHub Workflow Status

This package provides an asynchronous HTTP client for interacting with ReductStore in JavaScript.

Features

  • Supports the ReductStore HTTP API v1.18
  • Bucket management
  • API Token management
  • Write, read and query data
  • Labeling records
  • Batching records for read and write operations
  • Replication management

Install

To install this package, run the following command:

npm install reduct-js

Example

Here is an example of how to use this package to create a bucket, write data to it, and read data from it:

const { Client, QuotaType } = require("reduct-js");

const main = async () => {
// 1. Create a ReductStore client
const client = new Client("http://localhost:8383", { apiToken: "my-token" });

// 2. Get or create a bucket with 1Gb quota
const bucket = await client.getOrCreateBucket("my-bucket", {
quotaType: QuotaType.FIFO,
quotaSize: BigInt(1e9),
});

// 3. Write some data with timestamps in the 'entry-1' entry
const us = (dateString) => BigInt(Date.parse(dateString) * 1000);
await (
await bucket.beginWrite("sensor-1", { ts: us("2024-01-01T10:00:00Z") })
).write("<Blob data>");

// 4. Query the data by time range
for await (const record of bucket.query("sensor-1")) {
console.log(record.ts, record.size);
}
};

main().catch(console.error);

The SDK supports the following ReductStore API versions:

  • v1.18
  • v1.17
  • v1.16

It can work with newer and older versions, but it is not guaranteed that all features will work as expected because the API may change and some features may be deprecated or the SDK may not support them yet.

Modules