Event Flow
For engineers integrating modules and transports, this page describes the concrete runtime event flow.
Request/response flow (runtime + schema + transport)
Ordering guarantee
Runtime executes hook chains in the same order modules are passed to runtime(...).
runtime(moduleA, moduleB, moduleC);
Parameters
runtime(...modules):
modules(RuntimeModule[]): ordered module list; order defines hook execution.
emitReceive(input):
input(EmitInput): event input withevent,payloadorerror, and optional envelope metadata/context.
For each chain (onReceive, onSend, onError), execution order is:
moduleAmoduleBmoduleC
Field-by-field forwarding behavior
Incoming frame -> server runtime
node-ws-transportdecodes wire event.statusbecomesreceiving.contextis merged with{ transport: 'ws', clientId }.- Envelope is forwarded to
registry.emitReceive.
Schema execution
schemaModulereadsenvelope.event.envelope.payloadis decoded.- Operation/field operation runs with schema-validated input.
- Response is emitted with:
event: same operation event namepayload: encoded outputmetadata: copied/merged metadatacontext: copied context
- Runtime assigns default
status: sendingto this new outbound envelope.
Outbound frame -> client runtime
node-ws-transportencodes envelope.- Client transport decodes envelope.
- If
metadata.correlationIdmatches pending request:- resolve/reject request promise
- Otherwise emit to runtime via
emitReceive.
Publish/subscription flow
Publish metadata behavior:
metafrom publish call is merged into envelope metadata.keyis mapped to metadata askey.ackconfig is normalized and stored under metadataack.
Error flow
Important details:
- Runtime does not throw across module boundaries for delivery control.
schemaModulepreserves incomingstatusin emitted error envelopes.- Reliability modules (retry/DLQ) should listen on
onErrorand re-emit envelopes viaemitSend/emitReceive.
Module author rules for predictable behavior
- Always pass full envelope data through runtime channels.
- Never assume another module exists.
- Keep transformations pure and immutable.
- If you add context data, merge into
contextinstead of replacing. - If your module serializes, document exactly which fields are encoded and where.