Message.ts
Message.ts overview
Section titled “Message.ts overview”Defines the message shapes moved through Effect Cluster.
Messages carry entity requests and control envelopes between callers, durable storage, transports, and runner handlers. This module includes incoming and outgoing variants for encoded stored requests, decoded local requests, acknowledgements, and interrupts. It also provides helpers for local delivery and for encoding or decoding request payloads with matching RPC schemas.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”incoming
Section titled “incoming”Incoming (type alias)
Section titled “Incoming (type alias)”Message read by a runner from storage or transport.
Details
An incoming message is either a persisted request with an encoded payload or an incoming control envelope.
Signature
type Incoming<R> = IncomingRequest<R> | IncomingEnvelopeSince v4.0.0
IncomingEnvelope (class)
Section titled “IncomingEnvelope (class)”Represents an incoming control envelope carrying an AckChunk or Interrupt.
Signature
declare class IncomingEnvelopeSince v4.0.0
IncomingLocal (type alias)
Section titled “IncomingLocal (type alias)”Locally decoded incoming message for in-process delivery.
Details
It is either a request with a decoded payload or an incoming control envelope.
Signature
type IncomingLocal<R> = IncomingRequestLocal<R> | IncomingEnvelopeSince v4.0.0
IncomingRequest (class)
Section titled “IncomingRequest (class)”Represents an incoming persisted request whose payload has not yet been decoded with the RPC schema.
Details
It carries the last reply that was sent and a callback for persisting encoded replies.
Signature
declare class IncomingRequest<R>Since v4.0.0
IncomingRequestLocal (class)
Section titled “IncomingRequestLocal (class)”Represents an incoming request for local delivery with a decoded payload.
Details
It includes dynamic annotations, the last sent reply, and a callback for replying with decoded replies.
Signature
declare class IncomingRequestLocal<R>Since v4.0.0
incomingLocalFromOutgoing
Section titled “incomingLocalFromOutgoing”Converts an outgoing message into a locally deliverable incoming message.
Details
Request messages keep their decoded payload and response callback, while control envelopes are wrapped as incoming envelopes.
Signature
declare const incomingLocalFromOutgoing: <R extends Rpc.Any>(self: Outgoing<R>) => IncomingLocal<R>Since v4.0.0
outgoing
Section titled “outgoing”Outgoing (type alias)
Section titled “Outgoing (type alias)”Message produced for storage or transport.
Details
An outgoing message is either an entity request or a control envelope.
Signature
type Outgoing<R> = OutgoingRequest<R> | OutgoingEnvelopeSince v4.0.0
OutgoingEnvelope (class)
Section titled “OutgoingEnvelope (class)”Represents an outgoing control envelope paired with RPC metadata.
When to use
Use to construct an interrupt envelope for an in-flight request.
Signature
declare class OutgoingEnvelopeSince v4.0.0
interrupt (static method)
Section titled “interrupt (static method)”Creates an outgoing interrupt envelope for the supplied request.
Signature
declare const interrupt: (options: { readonly address: EntityAddress readonly id: Snowflake readonly requestId: Snowflake}) => OutgoingEnvelopeSince v4.0.0
OutgoingRequest (class)
Section titled “OutgoingRequest (class)”Represents an outgoing entity request with decoded payload and RPC metadata.
Details
It carries the service context used for serialization, the last received reply, the reply callback, dynamic annotations, and an optional encoded request cache.
Signature
declare class OutgoingRequest<R>Since v4.0.0
encodedCache (property)
Section titled “encodedCache (property)”Cached encoded envelope payload reused when sending the request.
Signature
encodedCache: Envelope.PartialRequest | undefinedSince v4.0.0
serialization
Section titled “serialization”deserializeLocal
Section titled “deserializeLocal”Decodes a partial envelope back into a locally deliverable incoming message.
Details
Control envelopes pass through directly. Request envelopes require the original
OutgoingRequest so the payload can be decoded with the correct RPC schema and
context.
Signature
declare const deserializeLocal: <Rpc extends Rpc.Any>( self: Outgoing<Rpc>, encoded: Envelope.Partial) => Effect.Effect<IncomingLocal<Rpc>, MalformedMessage>Since v4.0.0
serialize
Section titled “serialize”Serializes an outgoing message into a partial envelope.
Details
Control envelopes pass through unchanged. Requests are encoded with their RPC payload schema, reusing the cached encoded request when available.
Signature
declare const serialize: <Rpc extends Rpc.Any>( message: Outgoing<Rpc>) => Effect.Effect<Envelope.Partial, MalformedMessage>Since v4.0.0
serializeEnvelope
Section titled “serializeEnvelope”Serializes an outgoing message into its JSON envelope representation.
Details
Schema encoding failures are converted to MalformedMessage.
Signature
declare const serializeEnvelope: <Rpc extends Rpc.Any>( message: Outgoing<Rpc>) => Effect.Effect<Envelope.Encoded, MalformedMessage, never>Since v4.0.0
serializeRequest
Section titled “serializeRequest”Encodes the payload of an OutgoingRequest with the request’s RPC payload
schema and service context.
Details
The result is a PartialRequest suitable for storage or transport.
Signature
declare const serializeRequest: <Rpc extends Rpc.Any>( self: OutgoingRequest<Rpc>) => Effect.Effect<Envelope.PartialRequest, MalformedMessage>Since v4.0.0