Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

Reply unstable

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.

13 exports Since v4.0.0 Source

Guards

isReply

unstable
Since v4.0.0

Returns true when the supplied value is a runtime cluster reply, based on the reply type identifier.

Signature

declare function isReply(u: unknown): u is Reply<Any>

Models

Chunk

unstable
Since v4.0.0

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 unstable
Since v4.0.0

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];
}

Encoded

type unstable
Since v4.0.0

JSON-serializable form of a cluster reply.

Signature

type Encoded = WithExitEncoded | ChunkEncoded

Reply

type unstable
Since v4.0.0

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>
Since v4.0.0

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>;
}

WithExit

unstable
Since v4.0.0

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 unstable
Since v4.0.0

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

Encoded

unstable
Since v4.0.0

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>

Reply

unstable
Since v4.0.0

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, codecFor: CodecFor) => Codec<WithExit<R> | Chunk<R>, Encoded, ServicesClient<R>, ServicesServer<R>>

Serialization

serialize

unstable
Since v4.0.0

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>, codecFor: CodecFor): Effect<Encoded, MalformedMessage>
Since v4.0.0

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>, codecFor: CodecFor): Effect<Option<Encoded>, MalformedMessage>
Since v4.0.0

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>, codecFor: CodecFor): Effect<Encoded>