Skip to content

Message.ts

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



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> | IncomingEnvelope

Source

Since v4.0.0

Represents an incoming control envelope carrying an AckChunk or Interrupt.

Signature

declare class IncomingEnvelope

Source

Since v4.0.0

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> | IncomingEnvelope

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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> | OutgoingEnvelope

Source

Since v4.0.0

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 OutgoingEnvelope

Source

Since v4.0.0

Creates an outgoing interrupt envelope for the supplied request.

Signature

declare const interrupt: (options: {
readonly address: EntityAddress
readonly id: Snowflake
readonly requestId: Snowflake
}) => OutgoingEnvelope

Source

Since v4.0.0

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>

Source

Since v4.0.0

Cached encoded envelope payload reused when sending the request.

Signature

encodedCache: Envelope.PartialRequest | undefined

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0

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>

Source

Since v4.0.0