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

@teeny.dev/durable

v0.0.24

Published

## Overview

Readme

@teeny.dev/durable

Overview

@teeny.dev/durable is a library designed to simplify the management of Durable Objects in Cloudflare Workers. It provides utilities for creating typed storage and alarm management within Durable Objects.

Installation

To install the package, use npm:

npm install @teeny.dev/durable

Usage

Typed Storage

The createTypedStorage function allows you to create a typed storage interface for your Durable Object.

import {createTypedStorage} from '@teeny.dev/durable'
import {z} from 'zod'

const MetaSchema = z.object({
	feedUrl: z.string(),
})
const BlogSchema = z.object({
	title: z.string(),
	description: z.string(),
	id: z.string(),
})

class FeedStorage extends DurableObject {
	storage

	constructor(state: DurableObjectState, env: Env) {
		super(state, env)
		this.storage = createTypedStorage(state.storage, {
			meta: MetaSchema,
			blog: BlogSchema,
		})
	}

	// Usage:
	createBlogPost(title: string, description: string) {
		const id = crypto.randomUUID()
		await this.storage.blog.put(id, {title, description, id})
	}
}

Alarm Manager

The createAlarmManager function helps you manage alarms within your Durable Object.

import {createAlarmManager} from '@teeny.dev/durable'
import {z} from 'zod'

const AlarmSchema = z.object({url: z.string()})
class FeedStorage extends DurableObject {
	alarm: AlarmManager<typeof AlarmSchema>

	constructor(state: DurableObjectState, env: Env) {
		super(state, env)
		this.alarm = createAlarmManager({
			storage: state.storage,
			payloadParser: AlarmSchema,
			async handler(ctx) {},
		})
	}

	// Usage:
	createFeedSubscription(feedUrl: string) {
		await this.alarm.scheduleEvery(24 * 60 * 60 * 1000, {url: feedUrl})
	}
}

SQL Migrations and Statements

The prepareSqlite utility allows you to manage SQL migrations and add typing to statements within your Durable Object.

import {prepareSqlite} from '@teeny.dev/durable'

class FeedStorage extends DurableObject {
	sql
	constructor(ctx: DurableObjectState, env: Env) {
		super(ctx, env)
		this.sql = prepareSqlite(inst.ctx, {
			migrations: {
				['001_initalize']: [
					'CREATE TABLE pasta (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)',
					'INSERT INTO pasta (name, key) VALUES ("spaghetti"), ("fettuccine")',
				],
				['002_add_tastyness']: {
					description: 'Add tastyness column and insert more recommendations',
					commands: [
						'ALTER TABLE pasta ADD tastyness INTEGER NOT NULL DEFAULT -1',
						'INSERT INTO pasta (name, tastyness) VALUES ("angel hair", 7)',
					],
				},
			},
			statements: {
				getAllPasta: 'SELECT * FROM pasta',
				getPastaCount: stmt<{'count(*)': number}>('SELECT count(*) FROM pasta'),
				getPastaByNameAndTastyness: stmt<
					{name: string; tastyness: number},
					[number, string]
				>('SELECT * FROM pasta WHERE tastyness = ? AND name = ?'),
			},
		})
	}

	findPasta(args: {name: string; tastyness: number}) {
		return this.sql.getPastaByNameAndTastyness(args.tastyness, args.name)
	}
}

Internal

Testing

This package uses Vitest for testing. You can run the tests using the following commands:

npm run test:types
npm run test:vitest

Scripts

  • gen:wrangler: Generate Wrangler types.
  • build: Build the project using tsup.
  • test:types: Run TypeScript type checks.
  • test:vitest: Run tests using Vitest.
  • test: Run both type checks and tests.
  • release: Release the package using release-it.

License