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

@workkit/do

v0.2.0

Published

Durable Object abstractions for Cloudflare Workers — typed storage, state machines, alarm helpers, DO client utilities

Readme

@workkit/do

Typed Durable Object storage, state machines, alarms, and RPC clients

npm bundle size

Install

bun add @workkit/do

Usage

Before (raw DO API)

// Untyped storage — any key, any value
export class Counter {
  async fetch(request: Request) {
    const count = (await this.state.storage.get("count")) as number | undefined
    await this.state.storage.put("count", (count ?? 0) + 1)
    return new Response(String((count ?? 0) + 1))
  }
}

// Calling a DO from a Worker — manual fetch, manual JSON parsing
const id = env.COUNTER.idFromName("global")
const stub = env.COUNTER.get(id)
const resp = await stub.fetch(new Request("https://do/increment", {
  method: "POST",
  body: JSON.stringify({ amount: 5 }),
}))
const result = await resp.json()

After (workkit do)

import { typedStorage, createStateMachine, createDOClient, singleton } from "@workkit/do"

// Typed storage — schema-validated keys and values
const storage = typedStorage<{ count: number; name: string }>(state.storage)
const count = await storage.get("count") // number | undefined
await storage.put("count", 42) // type-checked

// State machine for complex DO logic
const machine = createStateMachine<OrderState, OrderEvent>({
  initial: "pending",
  transitions: {
    pending: { CONFIRM: "confirmed", CANCEL: "cancelled" },
    confirmed: { SHIP: "shipped" },
    shipped: { DELIVER: "delivered" },
  },
})

// RPC-style client — no manual fetch/JSON
interface CounterAPI {
  increment(amount: number): Promise<number>
  getCount(): Promise<number>
}

const counter = createDOClient<CounterAPI>(env.COUNTER, id)
const count = await counter.increment(5) // typed, no fetch boilerplate

// Singleton helper for well-known instances
const globalCounter = singleton<CounterAPI>(env.COUNTER, "global")

API

Storage

  • typedStorage<Schema>(storage) — Schema-typed wrapper around DurableObjectStorage
    • .get(key), .put(key, value), .delete(key), .list(), .transaction(fn)

State Machine

  • createStateMachine<State, Event>(config) — Define states, transitions, and side effects

Alarms

  • scheduleAlarm(storage, schedule) — Schedule a DO alarm
  • createAlarmHandler(config) — Create a typed alarm handler with multiple actions
  • parseDuration(str) — Parse "1h", "30m" to milliseconds

Client Helpers

  • createDOClient<T>(namespace, id) — RPC-style typed client for DO stubs
  • singleton<T>(namespace, name) — Get a named singleton DO instance

Versioned Storage

  • versionedStorage<Schema>(raw, options) — Wraps typedStorage with schema version tracking and forward-only migrations. Runs pending migrations sequentially in a transaction — if any migration fails, the entire transaction rolls back.
import { versionedStorage } from "@workkit/do"

const store = await versionedStorage<MySchema>(state.storage, {
  version: 3,
  migrations: [
    { from: 1, to: 2, migrate: async (s) => { await s.put("newField", "default") } },
    { from: 2, to: 3, migrate: async (s) => { await s.delete("oldField") } },
  ],
})

Event Sourcing

  • createEventStore<State, Event>(storage, options) — Immutable event log with reducer-based state materialization and periodic snapshots.
    • .append(event) — Append an event and return the materialized state
    • .getState() — Materialize current state from snapshot + replay
    • .getEvents(options?) — Query events with after and limit pagination
    • .rebuild() — Clear snapshots and replay all events from scratch
import { createEventStore } from "@workkit/do"

const store = createEventStore<OrderState, OrderEvent>(storage, {
  initialState: { status: "pending", items: [] },
  reducer: (state, event) => { /* return new state */ },
  snapshotEvery: 50,
})
await store.append({ type: "item_added", item: { sku: "A1", qty: 2 } })
const state = await store.getState()

Time Series

  • createTimeSeries<Value>(storage, options) — Bucketed metrics aggregation in DO storage with configurable granularity, retention, and custom reducers.
    • .record(value, at?) — Record a value into the current time bucket
    • .query(from, to) — Query entries in a date range
    • .rollup(granularity) — Aggregate fine-grained buckets into "hour" or "day" rollups
    • .prune() — Delete entries older than the retention period. Returns count deleted.
import { createTimeSeries } from "@workkit/do"

const ts = createTimeSeries(storage, {
  prefix: "api_requests",
  granularity: "minute",
  retention: "7d",
})
await ts.record(1)
const results = await ts.query(hourAgo, now)
const daily = await ts.rollup("day")
const pruned = await ts.prune()

License

MIT