Typed TypeScript wrappers and helpers for Cloudflare bindings and APIs — one tree-shakeable module per service.
- KV
- R2
- D1
- Env
import { getBinding } from '@rtorcato/cf-common/env'
import { createKvStore } from '@rtorcato/cf-common/kv'
export default {
async fetch(req, env) {
const users = createKvStore<User>(getBinding(env, 'USERS'))
const hit = await users.get('u:42') // User | null
if (!hit) await users.put('u:42', { id: 42 }, { ttl: 3600 })
return Response.json(hit ?? { id: 42 })
},
}
import { getBinding } from '@rtorcato/cf-common/env'
import { createR2Store } from '@rtorcato/cf-common/r2'
export default {
async fetch(req, env) {
const docs = createR2Store<Doc>(getBinding(env, 'DOCS'))
await docs.putJSON('a.json', { title: 'Hello' }) // sets content-type
const doc = await docs.getJSON('a.json') // Doc | null
return Response.json(doc)
},
}
import { getBinding } from '@rtorcato/cf-common/env'
import { execute, queryFirst } from '@rtorcato/cf-common/d1'
export default {
async fetch(req, env) {
const db = getBinding<D1Database>(env, 'DB')
await execute(db, 'INSERT INTO users (id, name) VALUES (?, ?)', 42, 'Ada')
const user = await queryFirst<User>(db, 'SELECT * FROM users WHERE id = ?', 42)
return Response.json(user) // User | null
},
}
import { getBinding, getEnv, requireEnv } from '@rtorcato/cf-common/env'
export default {
async fetch(req, env) {
const apiKey = requireEnv(env, 'API_KEY') // throws a non-exposed 500 if unset
const region = getEnv(env, 'REGION', 'auto')
const cache = getBinding<KVNamespace>(env, 'CACHE') // typed binding or 500
await cache.put('last-region', region)
return Response.json({ region, hasKey: apiKey.length > 0 })
},
}
npm install @rtorcato/cf-commonUse with AI
A skill ships with the package so coding agents use cf-common correctly — whichever tool you're in.
npx skills add https://github.com/rtorcato/cf-common --skill cf-common/plugin marketplace add rtorcato/cf-common/plugin install cf-common@cf-commonAGENTS.md. It ships in the npm tarball, so it is already in your node_modules.node_modules/@rtorcato/cf-common/AGENTS.mdOne module per Cloudflare service
Shipped modules open their guide. The rest are on the roadmap.
Typed CloudflareError model + result helpers.
Typed env access and getBinding helpers.
Typed get/put/list with JSON + TTL helpers.
Object get/put/list, presigned URLs, multipart.
Typed query helper, batch, migration runner.
Typed producer/consumer, batch ack helpers.
Base class + typed storage accessor.
match/put wrappers with key + TTL helpers.
Typed run() per model family.
Upsert/query helpers with typed metadata.
Connection helper.
Account-level client over fetch, typed responses.
Sibling projects
More from @rtorcato — same conventions, same release pipeline.
Tree-shakeable TypeScript utilities — tiny bundles, full type safety, CLI included.
Framework-agnostic building blocks for Node.js APIs — errors, auth, rate limiting, OpenAPI, Express + Hono.
Tree-shakeable TypeScript wrappers around 40+ browser Web APIs — one subpath per spec.
Shared, tree-shakeable TypeScript database utilities for Node projects.
Published React 19 component library — shared UI primitives.
SwiftUI package of reusable views and helpers to build apps faster.
Shared, tree-shakeable TypeScript helpers for Supabase — client, auth, and database utilities.
One wizard to scaffold TypeScript, linting, testing, and releases for any JS project.
Turns ai-ready GitHub issues into reviewed PRs — one worktree per issue, two agent reviewers.
Banner, social card and favicon for any repo.
Read-only view of a Buzz agent hive: what is running and what needs you.