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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rozek/sds-persistence-node

v0.0.13

Published

SQLite persistence provider for shareable-data-store (Node.js)

Downloads

1,312

Readme

@rozek/sds-persistence-node

SQLite persistence provider for the shareable-data-store (SDS) family. Stores CRDT snapshots, incremental patches, and large value blobs in a local SQLite database — suitable for Node.js servers, Electron desktop apps, and Tauri (with a Node.js backend).


Prerequisites

| requirement | details | | --- | --- | | Node.js 22.5+ | required. Download from nodejs.org. |

This package targets Node.js only and is not intended for use in a browser context.

SQLite support is provided by the built-in node:sqlite module (available since Node.js 22.5) — no separate database driver, no native C++ addon, and no build toolchain is required.

Note on stability: node:sqlite is classified as Stability 1 — Experimental in the Node.js 22 and 24 documentation. In practice the API has been stable since its introduction, with no breaking changes across any release. The module is expected to reach Stability 2 — Stable with Node.js 26.


Installation

pnpm add @rozek/sds-persistence-node
# @rozek/sds-core is a peer dependency:
pnpm add @rozek/sds-core

Requires Node.js 22.5+. No native dependencies are needed — SQLite is provided by Node.js itself.


Concepts

The provider uses three SQLite tables:

| table | contents | | --- | --- | | snapshots | one compressed full-store snapshot per store_id | | patches | incremental CRDT patches keyed by (store_id, clock) | | blobs | large value blobs keyed by SHA-256 hash, with reference counting |

On startup SDS_SyncEngine calls loadSnapshot() to restore the last checkpoint, then loadPatchesSince(clock) to replay any patches recorded after that checkpoint. During operation every local mutation is appended via appendPatch(). When the accumulated patch size crosses 512 KB (managed by the sync engine), a new snapshot is written and old patches are pruned.


API reference

SDS_DesktopPersistenceProvider

import { SDS_DesktopPersistenceProvider } from '@rozek/sds-persistence-node'

class SDS_DesktopPersistenceProvider implements SDS_PersistenceProvider {
  constructor (DbPath:string, StoreId:string)

  loadSnapshot ():Promise<Uint8Array | undefined>
  saveSnapshot (Data:Uint8Array):Promise<void>

  loadPatchesSince (Clock:number):Promise<Uint8Array[]>
  appendPatch (Patch:Uint8Array, Clock:number):Promise<void>
  prunePatches (beforeClock:number):Promise<void>

  loadValue (ValueHash:string):Promise<Uint8Array | undefined>
  saveValue (ValueHash:string, Data:Uint8Array):Promise<void>
  releaseValue (ValueHash:string):Promise<void>

  close ():Promise<void>
}

| parameter | description | | --- | --- | | DbPath | path to the SQLite database file (created if it does not exist) | | StoreId | logical store identifier; multiple stores can share the same database file |

WAL mode is enabled automatically for better concurrent-read performance.


Usage

Standalone — persistence only

import { SDS_DataStore }                  from '@rozek/sds-core'
import { SDS_DesktopPersistenceProvider } from '@rozek/sds-persistence-node'
import { SDS_SyncEngine }                 from '@rozek/sds-sync-engine'

const Store       = SDS_DataStore.fromScratch()
const Persistence = new SDS_DesktopPersistenceProvider('./data/sds.db', 'my-store')

const SyncEngine = new SDS_SyncEngine(Store, { PersistenceProvider:Persistence })
await SyncEngine.start()   // restores snapshot + patches from SQLite

// work with the store normally …
const Data = Store.newItemAt('text/plain', Store.RootItem)
Data.Label = 'Persisted data'

await SyncEngine.stop()    // flushes final checkpoint and closes the DB

With network sync

import { SDS_DataStore }                  from '@rozek/sds-core'
import { SDS_DesktopPersistenceProvider } from '@rozek/sds-persistence-node'
import { SDS_WebSocketProvider }          from '@rozek/sds-network-websocket'
import { SDS_SyncEngine }                 from '@rozek/sds-sync-engine'

const Store       = SDS_DataStore.fromScratch()
const Persistence = new SDS_DesktopPersistenceProvider('./data/sds.db', 'my-store')
const Network     = new SDS_WebSocketProvider('my-store')

const SyncEngine = new SDS_SyncEngine(Store, {
  PersistenceProvider:Persistence,
  NetworkProvider: Network,
  PresenceProvider:Network,
})

await SyncEngine.start()
await SyncEngine.connectTo('wss://my-server.example.com', { Token:'<jwt>' })

Multiple stores in one database

const PersistenceA = new SDS_DesktopPersistenceProvider('./data/sds.db', 'store-a')
const PersistenceB = new SDS_DesktopPersistenceProvider('./data/sds.db', 'store-b')
// both use the same database file but different store_id values

Database schema

CREATE TABLE IF NOT EXISTS snapshots (
  store_id  TEXT    PRIMARY KEY,
  data      BLOB    NOT NULL,
  clock     INTEGER NOT NULL
);

CREATE TABLE IF NOT EXISTS patches (
  store_id  TEXT    NOT NULL,
  clock     INTEGER NOT NULL,
  data      BLOB    NOT NULL,
  PRIMARY KEY (store_id, clock)
);

CREATE TABLE IF NOT EXISTS blobs (
  hash      TEXT    PRIMARY KEY,
  data      BLOB    NOT NULL,
  ref_count INTEGER NOT NULL DEFAULT 0
);

License

MIT License © Andreas Rozek