Reply
Defines reply values produced by clustered RPC execution.
Every reply belongs to a request and is either a final WithExit, which carries the final RPC Exit, or a streaming Chunk, which carries a non-empty batch of success values. This module includes runtime and encoded reply shapes, guards, per-RPC schema builders, ReplyWithContext for carrying encoding services, and serialization helpers for storage or transport.
Guards
Models
Represents a streaming RPC reply chunk for a request, carrying a non-empty batch of success values together with the reply id and sequence number.
Signature
declare class Chunk<R extends Rpc.Any> extends Readonly<{
readonly id: Snowflake;
readonly requestId: Snowflake;
readonly sequence: number;
readonly values: readonly [SuccessChunk<R>, SuccessChunk<R>];
}> & {
readonly _tag: "Chunk";
} & Pipeable {
constructor<R extends Any>(args: {
readonly id: Snowflake;
readonly requestId: Snowflake;
readonly sequence: number;
readonly values: readonly [SuccessChunk<R>, SuccessChunk<R>];
});
readonly "~effect/cluster/Reply": "~effect/cluster/Reply";
static readonly Any: declare<Chunk<never>, Chunk<never>>;
static readonly transform: Transformation<any, any>;
withRequestId(requestId: Snowflake): Chunk<R>;
static emptyFrom(requestId: Snowflake): Chunk<Any>;
static schema<R extends Any>(rpc: R): declareConstructor<Chunk<R>, Chunk<R>, readonly [SuccessExitSchema<R>]>;
static schemaFrom<Success extends Constraint>(success: Success): declareConstructor<Chunk<Any>, Chunk<Any>, readonly [Success]>;
}ChunkEncoded interface
Wire-format representation of a streaming reply chunk, including the request id, reply id, sequence number, and non-empty encoded values.
Signature
interface ChunkEncoded {
readonly _tag: "Chunk";
readonly id: string;
readonly requestId: string;
readonly sequence: number;
readonly values: readonly [unknown, unknown];
}JSON-serializable form of a cluster reply.
Signature
type Encoded = WithExitEncoded | ChunkEncoded;Runtime reply sent for an RPC request, either as a final exit or a chunk of a streaming success value.
Signature
type Reply<R extends Rpc.Any> = WithExit<R> | Chunk<R>;ReplyWithContext
Represents a cluster reply paired with the RPC definition and service context required to serialize it for transport.
When to use
Use to carry a runtime reply together with the RPC schema and services needed to encode it for storage or transport.
Signature
declare class ReplyWithContext<R extends Rpc.Any> extends Readonly<{
readonly context: Context<Services<R>>;
readonly reply: Reply<R>;
readonly rpc: R;
}> & {
readonly _tag: "ReplyWithContext";
} & Pipeable {
constructor<R extends Any>(args: {
readonly context: Context<Services<R>>;
readonly reply: Reply<R>;
readonly rpc: R;
});
static fromDefect(options: {
readonly defect: unknown;
readonly id: Snowflake;
readonly requestId: Snowflake;
}): ReplyWithContext<any>;
static interrupt(options: {
readonly id: Snowflake;
readonly requestId: Snowflake;
}): ReplyWithContext<any>;
}Represents a terminal RPC reply for a request, carrying the final Exit for the remote call.
When to use
Use to represent the final success, typed failure, defect, or interruption for a clustered RPC request.
Signature
declare class WithExit<R extends Rpc.Any> extends Readonly<{
readonly exit: Exit<R>;
readonly id: Snowflake;
readonly requestId: Snowflake;
}> & {
readonly _tag: "WithExit";
} & Pipeable {
constructor<R extends Any>(args: {
readonly exit: Exit<R>;
readonly id: Snowflake;
readonly requestId: Snowflake;
});
readonly "~effect/cluster/Reply": "~effect/cluster/Reply";
withRequestId(requestId: Snowflake): WithExit<R>;
static is(u: unknown): u is WithExit<any>;
static schema<R extends Any>(rpc: R): declareConstructor<WithExit<R>, WithExit<R>, readonly [Exit<SuccessExitSchema<R>, ErrorExitSchema<R>, DefectSchema>]>;
static schemaFrom<Success extends Constraint, Error extends Constraint, Defect extends Constraint>(exitSchema: Exit<Success, Error, Defect>): declareConstructor<WithExit<Any>, WithExit<Any>, readonly [Exit<Success, Error, Defect>]>;
}WithExitEncoded interface
Wire-format representation of a terminal reply containing the request id, reply id, and encoded RPC exit value.
Signature
interface WithExitEncoded<A = unknown, E = unknown> {
readonly _tag: "WithExit";
readonly exit: ExitEncoded<A, E>;
readonly id: string;
readonly requestId: string;
}Schemas
Schema for reply values that are already in encoded form.
Details
Per-RPC payload validation is performed by Reply(rpc).
Signature
declare const Encoded: Codec<Encoded, Encoded, never, never>;Builds the transport codec for replies to the specified RPC, covering terminal WithExit replies and streaming Chunk replies.
Signature
declare const Reply: <R extends Any>(
rpc: R,
) => Codec<WithExit<R> | Chunk<R>, Encoded, ServicesServer<R>, ServicesClient<R>>;Serialization
Serializes a ReplyWithContext into its encoded wire representation, using the reply's RPC schema and context and refailing encoding errors as MalformedMessage.
Signature
declare function serialize<R extends Any>(
self: ReplyWithContext<R>,
): Effect<Encoded, MalformedMessage>;serializeLastReceived
Serializes an outgoing request's last received reply when one exists, returning None when no reply has been received and refailing encoding errors as MalformedMessage.
Signature
declare function serializeLastReceived<R extends Any>(
self: OutgoingRequest<R>,
): Effect<Option<Encoded>, MalformedMessage>;serializeOrDefect
Serializes a ReplyWithContext, falling back to a serializable defect reply when the original reply cannot be encoded.
Signature
declare function serializeOrDefect<R extends Any>(self: ReplyWithContext<R>): Effect<Encoded>;
Returns
truewhen the supplied value is a runtime cluster reply, based on the reply type identifier.