Skip to content

A package for dynamic state tracking for Cloudflare's Durable Objects using SQLite

License

Notifications You must be signed in to change notification settings

zebp/diffable-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a1a14c3 · Dec 28, 2024

History

12 Commits
Dec 25, 2024
Dec 28, 2024
Dec 28, 2024
Dec 28, 2024
Dec 25, 2024
Dec 25, 2024
Dec 28, 2024
Dec 28, 2024
Dec 28, 2024
Dec 28, 2024
Dec 28, 2024
Dec 25, 2024
Dec 25, 2024
Dec 28, 2024

Repository files navigation

diffable-objects

A package for dynamic state tracking for Cloudflare's Durable Objects using SQLite.

downloads npm version MIT license

Installation

# NPM
$ npm install --save diffable-objects
# Yarn
$ yarn add diffable-objects
# PNPM
$ pnpm add diffable-objects
# Bun
$ bun add diffable-objects

Example

For complete examples see the examples directory.

Basic example of diffable-objects.

import { DurableObject } from "cloudflare:workers";
export { diffable, state } from "diffable-objects";

export class SampleObject extends DurableObject {
  // Within a durale object we can register a property to
  // have its values automatically tracked and persisted.
  #state = state(this.ctx, "state", { count: 0 });

  increment() {
    this.#state.count++;
  }
}

// Currently requires wrangler@next
export class DecoratorObject extends DurableObject {
  // You can also use decorators if you'd prefer a simpler
  // (but more magic) syntax.
  @diffable
  #state = { count: 0 };

  // Snapshot policies are configrable via an options object.
  @diffable({ snapshotPolicy: "every-change" })
  #stateWithOptions = { count: 0 };

  increment() {
    this.#state.count++;
    this.#stateWithOptions.count++;
  }
}

License

Distributed under the MIT License. See LICENSE for more information.

About

A package for dynamic state tracking for Cloudflare's Durable Objects using SQLite

Resources

License

Stars

Watchers

Forks

Packages

No packages published