RPC transforms API
Definition and installation
Section titled “Definition and installation”defineTransform<TTarget, TContext>()
Section titled “defineTransform<TTarget, TContext>()”Starts a transform definition. Chain .caller(factory) and/or .callee(factory).
registerTransform(transform, options?)
Section titled “registerTransform(transform, options?)”Binds callee options for applyTransforms. Parameterless transforms omit options.
applyTransforms(TargetClass, config)
Section titled “applyTransforms(TargetClass, config)”Installs transforms on all async methods or selected methods. Installation mutates the prototype and is cumulative.
Caller wrapping
Section titled “Caller wrapping”.with(transform, options?)
Section titled “.with(transform, options?)”Added to configured bindings by the Vite plugin. Returns a target with transformed async method types.
createTransformStub(rawTarget)
Section titled “createTransformStub(rawTarget)”Manually wraps one Durable Object stub or Worker service binding.
withTransforms(namespace)
Section titled “withTransforms(namespace)”Manually wraps a Durable Object namespace so returned stubs expose .with().
Context
Section titled “Context”createTransformContextTarget(target, context)
Section titled “createTransformContextTarget(target, context)”Creates a promise-pipelined target carrying typed context. Return it from setContext() when a caller transform invokes next({ context }).
TransformContextTarget
Section titled “TransformContextTarget”The underlying context-target class. Prefer the factory in normal integrations.
doTransforms(options?)
Section titled “doTransforms(options?)”Import from @durability/transforms/vite:
doTransforms({ wrangler: './wrangler.jsonc' })The plugin validates Wrangler configuration, wraps matching bindings, and emits do-transforms.generated.d.ts by default.
Built-in return types
Section titled “Built-in return types”| Transform | Caller-visible return |
|---|---|
betterResultCodec | Preserved or rehydrated Result<T, E> |
errorBoundary | Result<T, unknown> |
abortAsSuccess | Result<T | undefined, never> |
timeout | Original method return type |
retry | Original method return type |
largeObjectStream | Original method return type after runtime validation |
Built-in errors
Section titled “Built-in errors”CallerTimeoutErrorLargeObjectEncodeLimitErrorLargeObjectDecodeLimitErrorLargeObjectValidationError
Transform chains check target compatibility, caller and callee options, context compatibility, async method names, and transformed return types at compile time.