Skip to main content

createTransformer

Construct a whole-pipe transformer.
Config fields:
  • transform: (required) (data: I, ctx: BatchContext) => O | Promise<O>. Called once per batch.
  • start: (optional) (ctx: StartContext) => void | Promise<void>. Called once when the pipe starts. Use this to load state, warm up caches, or query the portal for historical data before the main stream begins.
  • stop: (optional) (ctx: StopContext) => void | Promise<void>. Called once when the pipe stops.
  • rollback: (optional) (cursor: BlockCursor, ctx: HookContext) => void | Promise<void>. Called after the source detects a chain reorg and resolves the safe cursor. cursor identifies the last safe block; undo any internal state above it. See Fork handling.
  • profiler: (optional) { name: string; hidden?: boolean }. Overrides the transformer’s node name in the profiler tree.
Example:

Context variables

Each callback receives a context object. The fields differ by callback.

transform(data, ctx: BatchContext)

ctx is the full per-batch context. Fields:

ctx.stream: StreamInfo

ctx.batch: BatchMetadata

start(ctx: StartContext)

Fired once, before any batch. Use to warm up caches or run one-off queries.

rollback(cursor, ctx: HookContext)

Fired before the next batch whenever a reorg is detected, after the safe cursor has been resolved. cursor is the last block to keep; drop state produced for anything after it.

stop(ctx: StopContext)

Fired once when the pipe stops.

The OutputOf type helper

OutputOf<T> infers the output type of a query-transform combo, a transformer, a transform function, or a record of named outputs. Use it to type downstream transform functions without spelling out intermediate types:
It also works on a whole outputs record: OutputOf<typeof outputs> yields { name1: ..., name2: ... }.