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

@db4/worker

v0.1.2

Published

Cloudflare Worker runtime for db4 - deploy your database to the edge with zero configuration

Downloads

8

Readme

@db4/worker

npm version license TypeScript

(GitHub, npm)

Cloudflare Worker runtime for db4 - deploy your database to the edge with zero configuration.

Description

@db4/worker is the Cloudflare Worker runtime for db4, enabling deployment of your database to the edge with zero configuration. It provides a complete db4 runtime with automatic Durable Object coordination, built-in WebSocket support for real-time subscriptions, and geographic routing for low-latency access.

Features

  • Complete db4 runtime for Cloudflare Workers
  • Automatic Durable Object coordination
  • Built-in WebSocket support for real-time subscriptions
  • Geographic routing for low-latency access
  • Automatic failover and replication

Installation

npm install @db4/worker

Usage

// src/index.ts
import { createDB4Worker } from '@db4/worker'
import schema from './schema'

const { worker, DB4DO } = createDB4Worker({ schema })

export default worker
export { DB4DO }

Wrangler Configuration

# wrangler.toml
name = "my-db4"
main = "src/index.ts"
compatibility_date = "2024-01-01"

[durable_objects]
bindings = [
  { name = "DB4_DO", class_name = "DB4DO" }
]

[[migrations]]
tag = "v1"
new_sqlite_classes = ["DB4DO"]

[vars]
DB4_SCHEMA = "User { id! name! email! }"

# R2 bucket for cold storage (optional)
[[r2_buckets]]
binding = "STORAGE"
bucket_name = "db4-storage"

# Cache API for warm tier
# (automatically available, no config needed)

Durable Object Bindings

The worker uses a single Durable Object binding with automatic sharding:

| Binding | Purpose | |---------|---------| | DB4_DO | Document storage with SQLite backing |

Sharding is handled automatically based on collection and document ID prefixes.

API

Worker creation and configuration:

function createDB4Worker(config: WorkerConfig): { worker: ExportedHandler; DB4DO: DurableObjectClass };

HTTP Endpoints

The worker exposes these HTTP endpoints:

GET    /health                    Health check
POST   /api/:collection           Create document
GET    /api/:collection           List/query documents
GET    /api/:collection/:id       Get document by ID
PUT    /api/:collection/:id       Update document
PATCH  /api/:collection/:id       Partial update document
DELETE /api/:collection/:id       Delete document
POST   /api/:collection/query     Execute complex query
POST   /api/:collection/stream    Streaming query (NDJSON)
POST   /api/:collection/batch     Batch create documents
PATCH  /api/:collection/batch     Batch update documents
DELETE /api/:collection/batch     Batch delete documents
POST   /batch                     Execute batch operations
POST   /rpc                       RPC endpoint
GET    /ws                        WebSocket for subscriptions
GET    /subscribe                 WebSocket for subscriptions (alias)
POST   /graphql                   GraphQL endpoint
GET    /graphql/schema            GraphQL schema introspection

Configuration Options

const { worker, DB4DO } = createDB4Worker({
  // Required: IceType schema
  schema: schemaDefinition,

  // Optional: Middleware
  middleware: [
    loggingMiddleware,
    rateLimitMiddleware
  ]
})

Environment Variables

| Variable | Description | |----------|-------------| | DB4_API_KEY | API key for authentication | | DB4_SCHEMA | Inline schema definition | | DB4_LOG_LEVEL | Logging verbosity (debug/info/warn/error) |

Deployment

# Development
wrangler dev

# Production
wrangler deploy

# With secrets
wrangler secret put DB4_API_KEY

Custom Request Handling

import { createDB4Worker } from '@db4/worker'

const { worker, DB4DO } = createDB4Worker({ schema })

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext) {
    const url = new URL(request.url)

    // Custom routes
    if (url.pathname === '/custom') {
      return new Response('Custom response')
    }

    // Default db4 handling
    return worker.fetch(request, env, ctx)
  }
}

export { DB4DO }

Performance

Benchmarked throughput on Cloudflare Workers:

| Workload | Throughput | |----------|------------| | Mixed OLTP | 70 ops/sec | | Batch operations | 1,970 docs/sec | | Point reads | 90 ops/sec |

Performance scales with Durable Object distribution. Batch operations benefit from reduced round-trip overhead by grouping multiple document writes into single transactions.

Documentation

For complete documentation, visit db4.dev/docs/worker

Related Packages

See Also

  • @db4/cli - CLI tools for development and deployment
  • @db4/rest - REST API with HTTP endpoints
  • @db4/auth - Authentication and authorization

License

MIT