Registry / database / diffable-objects

diffable-objects

JSON →
library0.1.1jsnpmunverified

A lightweight library for tracking and persisting state changes in Cloudflare Durable Objects using SQLite, version 0.1.1. It simplifies state management by automatically diffing property assignments and storing only mutations, reducing bandwidth and storage costs. Key differentiators from manual state handling include decorator-based or explicit state registration, configurable snapshot policies (e.g., every-change), and tight integration with Cloudflare Workers. The package is in early development with decorator support requiring wrangler@next. Ships TypeScript types and is designed for serverless environments.

databasedevops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Decorator for automatic state tracking; ESM-only, requires wrangler@next for decorator support

import { diffable } from 'diffable-objects'

Function to register a property for explicit state tracking; named export, not default

import { state } from 'diffable-objects'

DurableObject base class is from the Cloudflare workers runtime, not from this package

import { DurableObject } from 'cloudflare:workers'

Demonstrates explicit state tracking with `state()`: creates a Durable Object with a tracked state object, mutates it, and retrieves it.

import { DurableObject } from 'cloudflare:workers'; import { state } from 'diffable-objects'; export class MyObject extends DurableObject { #myState = state(this.ctx, 'myState', { count: 0, items: [] }); increment() { this.#myState.count++; } addItem(item: string) { this.#myState.items.push(item); } getState() { return this.#myState; } }
Debug
Known footguns
breakingDecorator support requires wrangler@next and is experimental
gotchaState mutations must be done on the tracked object itself, not on a copy
deprecatedSnapshot policy 'every-n-seconds' is deprecated in favor of 'periodic'
gotchaThe 'state' function requires 'this.ctx' to be the Durable Object's context, not the storage
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources