@proximaone/stream-client-js-v1
TypeScript icon, indicating that this package has built-in type declarations

0.7.3 • Public • Published

StreamDB Client JS

Installation

StreamDB Client requires Node.js v12+ to run.

Install @proximaone/streamdb-client-js package

yarn add @proximaone/streamdb-client-js

Install the dependencies and devDependencies.

yarn install

Client Usage

Client for StreamDB uses generated gRPC stubs to provide fast access to data.

Installation

import { StreamClient } from "../src";
import { map } from "rxjs";


async function main() {
    console.log(`Running stream client for a simple example...`)
    const client = new StreamClient({});
    const name = "eth-main-blockheader0.new-runtime"
    console.log(`Getting stream: ${name}...`)
    const stream =  await client.getStream(name)
    console.log(`Success! Fetched stream ${stream.toString()}`)
    const height = stream.stats.start.height
    const offset = await client.findOffset(name, {height: Number(height)})
    console.log(`Consuming stream ${name} from offset ${offset}`)
    const pausable = await client.streamEvents(name, offset) 
    pausable.observable.pipe(map(event => {
            const e =  {
              offset: event.offset,
              payload: decodeJson(event.payload),
              undo: event.undo,
              timestamp: event.timestamp,
            };
            console.log(e)
            return e
    }))
}
function decodeJson(binary: Uint8Array | string): any {
    const buffer =
      typeof binary == "string"
        ? Buffer.from(binary, "base64")
        : Buffer.from(binary);
    return JSON.parse(buffer.toString("utf8"));
  }

  main().catch(err => console.error(err));

Dependents (0)

Package Sidebar

Install

npm i @proximaone/stream-client-js-v1

Weekly Downloads

0

Version

0.7.3

License

MIT

Unpacked Size

213 kB

Total Files

68

Last publish

Collaborators

  • ivan.proxima
  • chasesmith