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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zgdb/runtime

v1.0.9

Published

The `@zgdb/runtime` package provides the core engine and necessary utilities for databases generated by `@zgdb/cli`. It offers a flexible, storage-agnostic foundation with built-in support for both synchronous and asynchronous operations, ensuring transac

Readme

@zgdb/runtime

@ZGDB Homepage

@zgdb/runtime

The @zgdb/runtime package provides the core engine and necessary utilities for databases generated by @zgdb/cli. It offers a flexible, storage-agnostic foundation with built-in support for both synchronous and asynchronous operations, ensuring transactional integrity and type safety.

This package is the powerhouse behind your generated client, handling data serialization, storage abstraction, and transactional logic.

Core Concepts

Store Adapters (StoreAdapter & SyncStoreAdapter)

These interfaces define a standardized contract for how the zgdb client interacts with an underlying key-value storage system. The StoreAdapter is for asynchronous backends, requiring methods like get, set, and transact, while the SyncStoreAdapter provides a synchronous equivalent with get, set, and transactSync. This design makes the runtime storage-agnostic, allowing developers to plug in different storage solutions by creating a class that implements one of these interfaces.

Transactional Clients (TransactionClient & TransactionClientSync)

These type interfaces define the API for performing database operations within a safe, all-or-nothing transaction. The client provides type-safe methods like getNode, createNode, and updateNode that can be used inside a transact or transactSync block. This ensures that a series of mutations to the graph are treated as a single atomic unit, maintaining data consistency and integrity.

Client Factories (createAsyncClient & createSyncClient)

These are the primary factory functions used to initialize a zgdb client instance. They take a storage adapter (either sync or async) and a set of generated helper functions (for serialization and data manipulation) as arguments. The factory then returns a client object equipped with a transact or transactSync method, which serves as the main entry point for executing database operations.

KeyEncoder

The KeyEncoder is a utility class responsible for creating and parsing the hierarchical string keys used to store and retrieve data from the underlying key-value store. It provides static methods to generate specific key formats for nodes (e.g., n:<type>:<id>), edges, and indexes. This structured key scheme is fundamental to how zgdb organizes data and enables efficient data lookups and range scans within the storage layer.

In-Memory Adapters (MapStoreAdapter & MapStoreAdapterSync)

These are concrete, ready-to-use implementations of the store adapter interfaces that use a simple JavaScript Map for in-memory storage. The MapStoreAdapter provides an asynchronous, transactional store by buffering writes and committing them on success. The MapStoreAdapterSync offers a synchronous alternative, ensuring atomicity by creating a cheap backup of the data before a transaction and rolling back to it if an error occurs. These adapters are ideal for testing, development, and applications that require high-speed, non-persistent data management.

Core Data Types (NodeData & Edge)

These interfaces define the primary structures within the graph. NodeData represents a single entity or object in your database, containing a unique id, type, timestamps, user-defined fields, and relationIds to link to other nodes. Edge represents a directed connection between two nodes (from and to), which also has its own id, type, and can contain arbitrary data. These types form the backbone of the graph and are what the generated type-safe clients operate on.