Skip to content

Reply.ts

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.

Since v4.0.0



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

Signature

declare const isReply: (u: unknown) => u is Reply<Rpc.Any>

Source

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>

Source

Since v4.0.0

Creates an empty chunk reply for the supplied request id.

Signature

declare const emptyFrom: (requestId: Snowflake) => Chunk<Rpc.Any>

Source

Since v4.0.0

Builds a chunk schema from the streaming success schema of an RPC.

Signature

declare const schema: <R extends Rpc.Any>(
rpc: R
) => Schema.declareConstructor<Chunk<R>, Chunk<R>, readonly [Rpc.SuccessExitSchema<R>]>

Source

Since v4.0.0

Builds a chunk schema that validates each success value with the supplied schema.

Signature

declare const schemaFrom: <Success extends Schema.Constraint>(
success: Success
) => Schema.declareConstructor<Chunk<Rpc.Any>, Chunk<Rpc.Any>, readonly [Success]>

Source

Since v4.0.0

Returns a copy of this chunk associated with the supplied request id.

Signature

declare const withRequestId: (requestId: Snowflake) => Chunk<R>

Source

Since v4.0.0

Marks this value as a runtime cluster reply.

Signature

readonly [TypeId]: "~effect/cluster/Reply"

Source

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

export interface ChunkEncoded {
readonly _tag: "Chunk"
readonly requestId: string
readonly id: string
readonly sequence: number
readonly values: NonEmptyReadonlyArray<unknown>
}

Source

Since v4.0.0

JSON-serializable form of a cluster reply.

Signature

type Encoded = WithExitEncoded | ChunkEncoded

Source

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> = WithExit<R> | Chunk<R>

Source

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>

Source

Since v4.0.0

Creates a terminal reply context that dies with the supplied defect.

Signature

declare const fromDefect: (options: {
readonly id: Snowflake
readonly requestId: Snowflake
readonly defect: unknown
}) => ReplyWithContext<any>

Source

Since v4.0.0

Creates a terminal reply context that interrupts the supplied request.

Signature

declare const interrupt: (options: { readonly id: Snowflake; readonly requestId: Snowflake }) => ReplyWithContext<any>

Source

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>

Source

Since v4.0.0

Returns true when the value is a terminal WithExit reply.

Signature

declare const is: (u: unknown) => u is WithExit<any>

Source

Since v4.0.0

Builds a terminal reply schema from the exit schema of an RPC.

Signature

declare const schema: <R extends Rpc.Any>(
rpc: R
) => Schema.declareConstructor<
WithExit<R>,
WithExit<R>,
readonly [Schema.Exit<Rpc.SuccessExitSchema<R>, Rpc.ErrorExitSchema<R>, Rpc.DefectSchema>]
>

Source

Since v4.0.0

Builds a terminal reply schema that validates the encoded exit value.

Signature

declare const schemaFrom: <
Success extends Schema.Constraint,
Error extends Schema.Constraint,
Defect extends Schema.Constraint
>(
exitSchema: Schema.Exit<Success, Error, Defect>
) => Schema.declareConstructor<WithExit<Rpc.Any>, WithExit<Rpc.Any>, readonly [Schema.Exit<Success, Error, Defect>]>

Source

Since v4.0.0

Returns a copy of this terminal reply associated with the supplied request id.

Signature

declare const withRequestId: (requestId: Snowflake) => WithExit<R>

Source

Since v4.0.0

Marks this value as a runtime cluster reply.

Signature

readonly [TypeId]: "~effect/cluster/Reply"

Source

Since v4.0.0

Wire-format representation of a terminal reply containing the request id, reply id, and encoded RPC exit value.

Signature

export interface WithExitEncoded<A = unknown, E = unknown> {
readonly _tag: "WithExit"
readonly requestId: string
readonly id: string
readonly exit: RpcMessage.ExitEncoded<A, E>
}

Source

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: Schema.Codec<Encoded, Encoded, never, never>

Source

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 Rpc.Any>(
rpc: R
) => Schema.Codec<WithExit<R> | Chunk<R>, Encoded, Rpc.ServicesServer<R>, Rpc.ServicesClient<R>>

Source

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 const serialize: <R extends Rpc.Any>(self: ReplyWithContext<R>) => Effect.Effect<Encoded, MalformedMessage>

Source

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 const serializeLastReceived: <R extends Rpc.Any>(
self: OutgoingRequest<R>
) => Effect.Effect<Option.Option<Encoded>, MalformedMessage>

Source

Since v4.0.0