npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

immudb-node

v1.1.1

Published

Node.js SDK for immudb written in TypeScript

Downloads

543

Readme

immudb-node License

Slack Discuss at immudb@googlegroups.com

Official immudb client for nodejs.

Contents

Introduction

immudb-node implements a grpc immudb client. A minimalist API is exposed for applications while cryptographic verifications and state update protocol implementation are fully implemented by this client. Latest validated immudb state may be kept in the local filesystem when initialising the client with the rootPath option. Please read immudb research paper for details on how immutability is ensured by immudb.

Prerequisites

immudb-node assumes an already running immudb server. Running immudb is quite simple, please refer to the following link for downloading and running it: https://docs.immudb.io/quickstart.html

Installation

Just include immudb-node as a dependency in your project:

const ImmudbClient = require('immudb-node')

Supported Versions

immudb-node supports the latest immudb release.

Quickstart

Check out some examples

Testing

Create a .env file based on a .env.example in the project root and replace the /path/to/immudb/ with your local path to immudb.

You can use either of the following commands to check that all the unit tests pass:

  • npm run test: automatically download the latest immudb release, run it and then run tests
  • npm run test:dev: connect to an already running immudb on the host:port from the .env file on your machine and then run tests

Step by step guide

Creating a Client

The following code snippets shows how to create a client.

Using default configuration:

const config = {
  address: '127.0.0.1:3322',
  rootPath: '.',
}

ImmudbClient(config, (err, cl) => {
  if (err) {
    return console.log(err)
  }

  // Interact with the client.
})

User sessions

Use login and logout methods to initiate and terminate user sessions:

try {
  await cl.login({ username: 'usr1', password: 'pwd1' })

  // Interact with immudb using logged user.

  await cl.logout()
} catch (err) {
  console.log(err)
}

Or with callbacks

cl.login({ username: 'usr1', password: 'pwd1' }, (err, res) => {
  if (err) {
    return console.log(err)
  }

  // Interact with immudb using logged user.

  cl.logout(null, (err, res) => {
    if (err) {
      return console.log(err)
    })
    // Logged out.
})

Creating a database

Creating a new database is quite simple:

cl.createDatabase('db1')

Setting the active database

Specify the active database with:

cl.useDatabase('db1')

Traditional read and write

immudb provides read and write operations that behave as a traditional key-value store i.e. no cryptographic verification is done. These operations may be used when validating can be postponed:

let res = await cl.set({ key: 'key1', value: 'value1' })
console.log(res.index)

res = await cl.get({ key: 'key1' })
console.log(res.key, res.value, res.index)

Verified or Safe read and write

immudb provides built-in cryptographic verification for any entry. The client implements the mathematical validations while the application uses as a traditional read or write operation:

try {
  let res = await cl.verifiedSet({ key: 'key1', value: 'value1' })
  console.log(res.index)

  res = await cl.verifiedGet({ key: 'key1' })
  console.log(res.key, res.value, res.index)
} catch (err) {
  if (err.clientErr == cl.proofErr) {
    // Proof does not verify.
  }
  console.log(err)
}

Multi-key read and write

Transactional multi-key read and write operations are supported by immudb and immudb-node.

Atomic multi-key write (all entries are persisted or none):

  req = {
    keys: [{
      key: 'key1',
      value: 'value1'
    },{
      key: 'key2',
      value: 'value2'
    }]
  }
  res = await cl.setAll(req)

Atomic multi-key read (all entries are retrieved or none):

    req = {
      keys: [{
        key: 'key1',
      },{
        key: 'key2',
      }],
    }
    res = await cl.getAll(req)

Closing the client

To programatically close the connection with immudb server use the shutdown operation:

cl.shutdown()

Note: after shutdown, a new client needs to be created to establish a new connection.

Contributing

We welcome contributions. Feel free to join the team!

To report bugs or get help, use GitHub's issues.