@decoyhq/transformer
Write Decoy Transformer workers in TypeScript. A worker can turn an app's wire format (msgpack envelopes, binary headers in front of protobuf, compression) into the JSON that Cases match and Behaviors render, and back. HTTP, gRPC, and WebSocket Routes can use workers. See Configure a Transformer Pipeline for setup.
This example adapts binary and text WebSocket messages. Save it as workers/envelope.ts:
workers/envelope.ts
Register the worker and name its Pipeline in decoy.yaml:
decoy.yaml (excerpt)
defineTransformerreturns the transformer, and serves it over stdin/stdout when Decoy started the process (DECOY_TRANSFORMER=1). A unit test can import the file and callinputdirectly.- A package can export a factory that takes typed options and returns
defineTransformer(...); users call it from their own worker file. - On WebSockets,
miss(reason)ininputskips the frame: Decoy logs the reason and keeps the socket open. Any other throw is a worker error, shown with the Transformer, Behavior and value that failed. - WebSocket input sets
ctx.frameto'text'or'binary'. WebSocket input and output supplyctx.connectionas{ id, route, session }and share actx.statemap per connection. HTTP, gRPC and startup checks get a fresh state map for each call. - HTTP workers receive
ctx.requeston input and output, including Passthrough output. It is a read-only snapshot of the original method, path, and headers (lowercase names). The headers can include cookies and credentials; avoid logging them. Startup checks have no request context. ctx.protobuf.has/decode/encodeuse the protos Decoy already compiled.console.loggoes to stderr while serving, since stdout carries the protocol. Decoy prints each stderr line with the worker's label.
To implement a worker in another language, see the wire protocol.