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

chronodb

v1.0.2

Published

ChronoDB: Local-first TypeScript database with snapshots and optional cloud sync (cloud sync not fully implemented yet)

Readme

ChronoDB

ChronoDB is a local-first, file-based TypeScript database engine with schema validation, indexing, transactions, and snapshot-based versioning designed for simplicity, predictability, and offline-first applications.

ChronoDB stores data as plain JSON files, adds strong schema guarantees, and tracks changes through snapshots that can later be synced to the cloud (cloud sync is not fully integrated yet).


✨ Key Features

  • 📁 File-based storage (JSON)
  • 🧩 Schema validation (primitive, enum, defaults, custom validators)
  • 🔐 Strict mode (reject unknown fields)
  • 🆔 Auto-generated IDs
  • createdAt / updatedAt timestamps
  • 🔍 Indexed fields for faster lookups
  • 📦 Collections API (CRUD)
  • 🔁 Transactions with rollback
  • 🕒 Automatic & manual snapshots
  • ☁️ Optional cloud sync (not fully integrated yet)
  • 🧠 Type-safe (TypeScript-first)

📦 Installation

npm install chronodb

or

yarn add chronodb

🚀 Quick Start

import ChronoDB from "chronodb";

const db = await ChronoDB.open({ cloudSync: false });

const users = db.col("users", {
    schema: {
        name: {
            type: "string",
            important: true,
        },
        email: {
            type: "string",
            distinct: true,
        },
        role: {
            type: "enum",
            values: ["admin", "user"],
            default: "user",
        },
        age: "number"
    }
});

📂 Storage Structure

ChronoDB stores everything as files:

data/
├─ users.json
├─ users.json.index.json
├─ .__state.json
└─ .snapshots/
   └─ meta.json
  • collection.json → actual documents
  • .index.json → auto-generated indexes
  • .snapshots/meta.json → snapshot history
  • .__state.json → transaction state backup

🧱 Collections

A collection represents a single JSON-backed dataset.

const users = db.col("users");

Creating with Schema & Indexes

const posts = db.col("posts", {
    schema: {
        title: "string",
        published: "boolean",
        views: { type: "number", default: 0 },
    },
    indexes: ["published"],
});

📐 Schema System

ChronoDB enforces schemas at write-time.

Primitive Shorthand

{
    name: "string",
    age: "number"
}

Field Schema

{
    email: {
        type: "string",
        distinct: true,
        validate: v => v.includes("@")
    }
}

Enum Schema

{
    status: {
        type: "enum",
        values: ["draft", "published"]
    }
}

Supported Rules

| Rule | Description | | ----------- | ---------------- | | type | Field type | | important | Required field | | distinct | Must be unique | | nullable | Allow null | | default | Default value | | validate | Custom validator |

In strict mode, unknown fields are rejected.


🆕 Creating Documents

Add One

const user = await users.add({
    name: "Alice",
    email: "[email protected]",
});

Automatically adds:

{
    id,
    createdAt,
    updatedAt
}

Add Many

await users.addMany([
    { name: "Bob", email: "[email protected]" },
    { name: "Jane", email: "[email protected]" },
]);

Validation is done atomically across the batch.


📖 Reading Data

Get All

await users.getAll();

Get One

await users.getOne({ email: "[email protected]" });

Get Many

await users.getMany({ role: "admin" });

✏️ Updating

Update by ID

await users.updateById(id, {
    name: "Alice Updated"
});

Update Many

await users.updateMany({ role: "guest" }, {
    role: "user"
});
  • Schema is revalidated
  • updatedAt is refreshed for all matching documents
  • Distinct fields are respected
  • Supports updating multiple documents at once

🗑 Deleting

Delete by ID

await users.deleteById(id);

Delete Many

await users.deleteMany({ role: "guest" });

Delete All

await users.deleteAll();

🔍 Indexing

Indexes are automatically rebuilt on write.

db.col("users", {
    indexes: ["email", "role"]
});

Indexes are stored in:

users.json.index.json

Indexing is transparent and requires no manual queries.


🔁 Transactions

ChronoDB supports safe transactions with rollback.

await db.transaction(async () => {
    await users.add({ name: "A", email: "[email protected]" });
    await users.add({ name: "B", email: "[email protected]" }); // ❌ duplicate
});

If any error occurs:

  • State is restored
  • No partial writes remain

🕒 Snapshots (Versioning)

ChronoDB tracks changes using snapshots.

When Snapshots Are Created

  • On every data change
  • On manual trigger
  • On time intervals

Snapshot Metadata

{
    snapshotId: string;
    timestamp: number;
    version: number;
    reason: "change" | "interval" | "manual";
}

List Snapshots

await db.snapshots.list();

Delete Snapshot

await db.snapshots.delete(snapshotId);

Delete All Snapshots

await db.snapshots.deleteAll();

Auto Snapshot Interval

await db.snapshots.setInterval(60000); // every 1 min

Snapshots are metadata-first and designed to power restore & future cloud sync.


☁️ Cloud Sync (Optional, Not Fully Integrated)

ChronoDB supports pluggable cloud sync, but the feature is still in progress.

new ChronoDB("./data", {
    cloudSync: true
});
  • Snapshots are planned to be synced, not raw files
  • Cloud logic is abstracted via CloudSync
  • Authentication & providers are user-defined

Currently, cloud sync is not fully functional.


🧠 Philosophy

ChronoDB is built around:

  • Predictability over magic
  • Local-first by default
  • Explicit schemas
  • Durable writes
  • Offline-safe design
  • Composable cloud sync

It is ideal for:

  • Desktop apps
  • CLI tools
  • Embedded databases
  • Offline-first apps
  • Developer tooling

🛠 Roadmap (Planned)

  • Snapshot restore / rewind
  • Differential snapshot storage
  • Conflict resolution strategies
  • Cloud providers (S3, Firebase, custom APIs)
  • Query operators ($gt, $in, $or)
  • Read-only replicas

📜 License

MIT © You