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

@canvas-js/okra-node

v0.6.0

Published

Native NodeJS bindings for Okra over LMDB

Downloads

4,402

Readme

@canvas-js/okra-node

NPM version TypeScript types

Install

npm i @canvas-js/okra-node

The following targets are supported:

  • x86_64-linux-gnu
  • x86_64-linux-musl
  • aarch64-linux-gnu
  • aarch64-linux-musl
  • x86_64-macos
  • aarch64-macos

Usage

First open an Environment.

import { Environment } from "@canvas-js/okra-node"

const env = new Environment("./path/to/data/directory")
try {
	// ...
} finally {
	env.close()
}

With the environment, you can open transactions, which are either read-write or read-only.

await env.read(async (txn) => {
	/* ... */
})

await env.write(async (txn) => {
	/* ... */
})

With a transaction, you can open multiple named databases and/or trees. A Database is a named database in the LMDB key/value store. A Tree is a Okra tree that wraps an underlying Database. Trees need to be closed before the transaction commits, so they're only accessible within an txn.openTree(name, async (tree) => { ... }) callback. Databases don't have to be closed, so txn.database(name) returns a class directly.

Both Database and Tree implement the KeyValueStore interface.

const auxillaryDB = txn.database("my-auxillary-db")
auxillaryDB.set(key1, value1)

await txn.openTree("my-okra-tree", async (tree) => {
	// ...
	tree.set(key2, value2)
	// ...
	const root = tree.getRoot()
	// ...
})

API

import { KeyValueStore, Bound, Entry, Node, Key, Source, Target, Awaitable } from "@canvas-js/okra"

export interface EnvironmentOptions {
	mapSize?: number
	databases?: number
}

export declare class Environment {
	public readonly path: string

	public constructor(path: string, options?: EnvironmentOptions)

	public close(): void

	public read<T>(callback: (txn: Transaction) => Awaitable<T>): Promise<T>
	public write<T>(callback: (txn: Transaction) => Awaitable<T>): Promise<T>

	public resize(mapSize: number): void
}

export declare class Transaction {
	public database(name: string | null = null): Database

	public async openTree(name: string | null, callback: (tree: Tree) => Awaitable<T>): Promise<T>
}

export declare class Database implements KeyValueStore {
	public get(key: Uint8Array): Uint8Array | null
	public set(key: Uint8Array, value: Uint8Array): void
	public delete(key: Uint8Array): void

	public entries(
		lowerBound?: Bound<Uint8Array> | null,
		upperBound?: Bound<Uint8Array> | null,
		options?: { reverse?: boolean }
	): AsyncIterableIterator<Entry>
}

export declare class Tree implements KeyValueStore, Source, Target {
	public get(key: Uint8Array): Uint8Array | null
	public set(key: Uint8Array, value: Uint8Array): void
	public delete(key: Uint8Array): void

	public entries(
		lowerBound?: Bound<Uint8Array> | null,
		upperBound?: Bound<Uint8Array> | null,
		options?: { reverse?: boolean }
	): AsyncIterableIterator<Entry>

	public getRoot(): Node
	public getNode(level: number, key: Key): Node | null
	public getChildren(level: number, key: Key): Node[]

	public nodes(
		level: number,
		lowerBound?: Bound<Key> | null,
		upperBound?: Bound<Key> | null,
		options?: { reverse?: boolean }
	): AsyncIterableIterator<Node>
}