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

@syncraft-labs/core

v0.2.0

Published

Local-first state synchronization engine — core library.

Downloads

511

Readme

@syncraft-labs/core

Local-first state synchronization engine — framework-agnostic core library.

npm version License: MIT TypeScript

@syncraft-labs/core is the engine behind Syncraft Labs. It provides a type-safe, framework-agnostic store that combines in-memory caching for instant reads, IndexedDB for offline persistence, and an outbox queue for eventual synchronization.

Install

npm install @syncraft-labs/core

Quick Start

import { createSyncStore } from "@syncraft-labs/core";

interface AppState {
  count: number;
}

const store = createSyncStore<AppState>({
  storageKey: "my-counter",
  initialState: { count: 0 },
});

// 1. Hydrate from IndexedDB
await store.hydrate();

// 2. Read state (synchronous after hydration)
const state = store.getSnapshot(); // { count: 0 }

// 3. Mutate with Immer drafts — instant + durable
await store.set((draft) => {
  draft.count += 1;
});

// 4. Subscribe to changes
const unsubscribe = store.subscribe((newState) => {
  console.log("State:", newState.count);
});

// 5. Clean up when done
unsubscribe();
store.destroy();

API

createSyncStore<T>(config): SyncStore<T>

Create a new store instance. Each store manages one slice of state identified by storageKey.

Config: SyncStoreConfig<T>

| Property | Type | Default | Description | |----------|------|---------|-------------| | storageKey | string | required | Unique key for IndexedDB database name | | initialState | T | undefined | Default state when no persisted data exists | | maxOutboxSize | number | 1000 | Maximum outbox entries before set() throws |

Returns: SyncStore<T>

| Method | Signature | Description | |--------|-----------|-------------| | get() | () => Promise<T \| undefined> | Async read — memory → IndexedDB fallback | | getSnapshot() | () => T \| undefined | Synchronous read from memory (fast path) | | set(updater) | (updater: DraftUpdater<T>) => Promise<void> | Mutate via Immer draft. Optimistic + durable | | subscribe(listener) | (listener: SyncListener<T>) => Unsubscribe | Listen to state changes | | hydrate() | () => Promise<T \| undefined> | Load from IndexedDB (call once on init) | | getOutbox() | () => Promise<readonly OutboxEntry<T>[]> | Read pending mutations | | clearOutbox(ids) | (ids: readonly string[]) => Promise<void> | Remove synced entries by ID | | destroy() | () => void | Close IndexedDB connection, clear listeners | | isHydrating | boolean (getter) | true until hydrate() completes |

Types

DraftUpdater<T>

type DraftUpdater<T> = (draft: T) => void | T;

Two patterns:

  • Mutate the draft (most common): (draft) => { draft.count += 1; }
  • Replace entirely: () => freshDataFromServer

OutboxEntry<T>

interface OutboxEntry<T> {
  readonly id: string;           // UUID v4
  readonly timestamp: number;    // Unix ms
  readonly patches: Patch[];     // Immer patches (what changed)
  readonly inversePatches: Patch[]; // Undo patches (for rollback)
  readonly snapshot: T;          // Full state after mutation
}

SyncListener<T>

type SyncListener<T> = (state: T) => void;

Unsubscribe

type Unsubscribe = () => void;

Data Flow

store.set(draft => { draft.count++ })
        │
        ▼
┌─────────────────────────────┐
│  Immer produceWithPatches   │  → nextState, patches, inversePatches
└─────────────────────────────┘
        │
        ├──▶ Update in-memory cache (instant, optimistic)
        ├──▶ Notify all subscribers (triggers UI re-render)
        ├──▶ Write to IndexedDB (durable)
        └──▶ Append OutboxEntry to IndexedDB (for eventual sync)

        If IndexedDB write fails:
        └──▶ Rollback memory + re-notify subscribers

Storage Schema

Each storageKey maps to its own IndexedDB database:

Database: "syncraft-labs_{storageKey}"
├── state store      (key: "current", value: T)
└── outbox store     (key: entry.id, value: OutboxEntry<T>)

Optimistic Updates & Rollback

When you call store.set():

  1. Memory updates instantly — the UI sees the change immediately
  2. IndexedDB writes async — persists for durability
  3. If persistence fails — memory is rolled back to the previous state, subscribers are re-notified

This ensures the UI is never stuck showing data that isn't actually persisted.

Framework Integrations

License

MIT © Denis Listiadi