DO Transforms API
Definition and registration
Section titled “Definition and registration”defineTransform<TTarget, TContext>()
Section titled “defineTransform<TTarget, TContext>()”Starts a typed transform definition. Chain .caller(factory) and/or .callee(factory) to define its two boundaries.
registerTransform(transform, options?)
Section titled “registerTransform(transform, options?)”Binds callee options for use in applyTransforms. Parameterless transforms do not take an options argument.
applyTransforms(TargetClass, config)
Section titled “applyTransforms(TargetClass, config)”Registers transforms on all async methods or selected methods:
applyTransforms(TargetClass, { all: [registerTransform(globalTransform, options)], methods: { write: [registerTransform(writeTransform, options)], },});Caller wrapping
Section titled “Caller wrapping”.with(transform, options?)
Section titled “.with(transform, options?)”The Vite plugin adds typed .with(...) access to configured Durable Object and service bindings.
createTransformStub(rawStub)
Section titled “createTransformStub(rawStub)”Manually wraps one RPC target when automatic Vite wrapping is not used.
withTransforms(namespace)
Section titled “withTransforms(namespace)”Manually wraps a Durable Object namespace so stubs returned from it support transforms.
Context
Section titled “Context”createTransformContextTarget(target, context)
Section titled “createTransformContextTarget(target, context)”Returns a pipelined RPC target carrying typed context. Expose it from setContext() when caller transforms call next({ context }).
TransformContextTarget
Section titled “TransformContextTarget”The underlying context-target class. Most integrations should use createTransformContextTarget instead of constructing it directly.
doTransforms(options?)
Section titled “doTransforms(options?)”Import from @repo/do-transforms/vite. Reads Wrangler bindings, injects wrappers, and emits generated declarations.
doTransforms({ wrangler: './wrangler.jsonc' })Place it before cloudflare() in the Vite plugin array.
Return-type behavior
Section titled “Return-type behavior”| Transform | Resulting async return type |
|---|---|
betterResultCodec | Preserves or rehydrates Result<T, E> |
errorBoundary | Result<T, unknown> |
abortAsSuccess | Result<T | undefined, never> |
timeout | Original method type |
retry | Original method type |
largeObjectStream | Original method type |
Transform chains validate target compatibility, options, context compatibility, async method names, and transformed return types at compile time.