Message
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.
Converting
incomingLocalFromOutgoing
Signature
declare function incomingLocalFromOutgoing<R extends Any>(self: Outgoing<R>): IncomingLocal<R>;Models
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 extends Rpc.Any> = IncomingRequest<R> | IncomingEnvelope;IncomingEnvelope
Represents an incoming control envelope carrying an AckChunk or Interrupt.
Signature
declare class IncomingEnvelope extends Readonly<{
readonly _tag: "IncomingEnvelope";
readonly envelope: AckChunk | Interrupt;
}> & {
readonly _tag: "IncomingEnvelope";
} & Pipeable {
constructor(args: {
readonly envelope: AckChunk | Interrupt;
});
}IncomingLocal type
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 extends Rpc.Any> = IncomingRequestLocal<R> | IncomingEnvelope;IncomingRequest
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 extends Rpc.Any> extends Readonly<{
readonly envelope: PartialRequest;
readonly lastSentReply: Option<Encoded>;
readonly respond: (reply: ReplyWithContext<R>) => Effect<void, MalformedMessage | PersistenceError>;
}> & {
readonly _tag: "IncomingRequest";
} & Pipeable {
constructor<R extends Any>(args: {
readonly envelope: PartialRequest;
readonly lastSentReply: Option<Encoded>;
readonly respond: (reply: ReplyWithContext<R>) => Effect<void, MalformedMessage | PersistenceError>;
});
}IncomingRequestLocal
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 extends Rpc.Any> extends Readonly<{
readonly annotations: Context<never>;
readonly envelope: Request<R>;
readonly lastSentReply: Option<Reply<R>>;
readonly respond: (reply: Reply<R>) => Effect<void, MalformedMessage | PersistenceError>;
}> & {
readonly _tag: "IncomingRequestLocal";
} & Pipeable {
constructor<R extends Any>(args: {
readonly annotations: Context<never>;
readonly envelope: Request<R>;
readonly lastSentReply: Option<Reply<R>>;
readonly respond: (reply: Reply<R>) => Effect<void, MalformedMessage | PersistenceError>;
});
}Message produced for storage or transport.
Details
An outgoing message is either an entity request or a control envelope.
Signature
type Outgoing<R extends Rpc.Any> = OutgoingRequest<R> | OutgoingEnvelope;OutgoingEnvelope
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 extends Readonly<{
readonly envelope: AckChunk | Interrupt;
readonly rpc: AnyWithProps;
}> & {
readonly _tag: "OutgoingEnvelope";
} & Pipeable {
constructor(args: {
readonly envelope: AckChunk | Interrupt;
readonly rpc: AnyWithProps;
});
static interrupt(options: {
readonly address: EntityAddress;
readonly id: Snowflake;
readonly requestId: Snowflake;
}): OutgoingEnvelope;
}OutgoingRequest
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 extends Rpc.Any> extends Readonly<{
readonly annotations: Context<never>;
readonly context: Context<Services<R>>;
readonly envelope: Request<R>;
readonly lastReceivedReply: Option<Reply<R>>;
readonly respond: (reply: Reply<R>) => Effect<void>;
readonly rpc: R;
}> & {
readonly _tag: "OutgoingRequest";
} & Pipeable {
constructor<R extends Any>(args: {
readonly annotations: Context<never>;
readonly context: Context<Services<R>>;
readonly envelope: Request<R>;
readonly lastReceivedReply: Option<Reply<R>>;
readonly respond: (reply: Reply<R>) => Effect<void>;
readonly rpc: R;
});
encodedCache?: PartialRequest;
}Serialization
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 function deserializeLocal<Rpc extends Any>(
self: Outgoing<Rpc>,
encoded: AckChunk | Interrupt | PartialRequest,
): Effect<IncomingLocal<Rpc>, MalformedMessage>;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 function serialize<Rpc extends Any>(
message: Outgoing<Rpc>,
): Effect<AckChunk | Interrupt | PartialRequest, MalformedMessage>;serializeEnvelope
Serializes an outgoing message into its JSON envelope representation.
Details
Schema encoding failures are converted to MalformedMessage.
Signature
declare function serializeEnvelope<Rpc extends Any>(
message: Outgoing<Rpc>,
): Effect<Encoded, MalformedMessage, never>;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 function serializeRequest<Rpc extends Any>(
self: OutgoingRequest<Rpc>,
): Effect<PartialRequest, MalformedMessage>;
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.