Skip to content

DO Transforms

@repo/do-transforms composes cross-cutting behavior around native Cloudflare RPC calls. A transform can run on the caller, the callee, or both while preserving target compatibility and updating async return types.

It supports:

  • Durable Object namespaces and stubs.
  • Named WorkerEntrypoint service bindings.
  • Context propagation through native RPC promise pipelining.
  • Global and per-method transform registration.
  • Automatic binding wrapping and generated types through Vite.

Caller

Change arguments, attach context, retry, time out, or decode results.

Callee

Authorize, observe, decode context, or encode results around target methods.

Typed chains

.with(...) checks target, options, context, and transformed return types.

Native transport

Context targets use Cloudflare RPC promise pipelining rather than a custom protocol.

Add the Vite plugin before Cloudflare’s plugin:

import { cloudflare } from '@cloudflare/vite-plugin';
import { doTransforms } from '@repo/do-transforms/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
doTransforms({ wrangler: './wrangler.jsonc' }),
cloudflare(),
],
});

The plugin reads Durable Object and service bindings from Wrangler, wraps binding access, and generates do-transforms.generated.d.ts.

import { retry, timeout } from '@repo/do-transforms';
const result = await env.MY_DO.get(id)
.with(retry, { retries: 3 })
.with(timeout, 5_000)
.loadReport();

Transforms execute in chain order around the RPC call. Keep retry safety in mind: repeated RPC calls can repeat side effects unless the method is idempotent.