Reply.ts
Reply.ts overview
Section titled “Reply.ts overview”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
Exports Grouped by Category
Section titled “Exports Grouped by Category”- guards
- models
- schemas
- serialization
guards
Section titled “guards”isReply
Section titled “isReply”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>Since v4.0.0
models
Section titled “models”Chunk (class)
Section titled “Chunk (class)”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>Since v4.0.0
emptyFrom (static method)
Section titled “emptyFrom (static method)”Creates an empty chunk reply for the supplied request id.
Signature
declare const emptyFrom: (requestId: Snowflake) => Chunk<Rpc.Any>Since v4.0.0
schema (static method)
Section titled “schema (static method)”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>]>Since v4.0.0
schemaFrom (static method)
Section titled “schemaFrom (static method)”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]>Since v4.0.0
withRequestId (method)
Section titled “withRequestId (method)”Returns a copy of this chunk associated with the supplied request id.
Signature
declare const withRequestId: (requestId: Snowflake) => Chunk<R>Since v4.0.0
[TypeId] (property)
Section titled “[TypeId] (property)”Marks this value as a runtime cluster reply.
Signature
readonly [TypeId]: "~effect/cluster/Reply"Since v4.0.0
ChunkEncoded (interface)
Section titled “ChunkEncoded (interface)”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>}Since v4.0.0
Encoded (type alias)
Section titled “Encoded (type alias)”JSON-serializable form of a cluster reply.
Signature
type Encoded = WithExitEncoded | ChunkEncodedSince v4.0.0
Reply (type alias)
Section titled “Reply (type alias)”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>Since v4.0.0
ReplyWithContext (class)
Section titled “ReplyWithContext (class)”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>Since v4.0.0
fromDefect (static method)
Section titled “fromDefect (static method)”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>Since v4.0.0
interrupt (static method)
Section titled “interrupt (static method)”Creates a terminal reply context that interrupts the supplied request.
Signature
declare const interrupt: (options: { readonly id: Snowflake; readonly requestId: Snowflake }) => ReplyWithContext<any>Since v4.0.0
WithExit (class)
Section titled “WithExit (class)”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>Since v4.0.0
is (static method)
Section titled “is (static method)”Returns true when the value is a terminal WithExit reply.
Signature
declare const is: (u: unknown) => u is WithExit<any>Since v4.0.0
schema (static method)
Section titled “schema (static method)”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>]>Since v4.0.0
schemaFrom (static method)
Section titled “schemaFrom (static method)”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>]>Since v4.0.0
withRequestId (method)
Section titled “withRequestId (method)”Returns a copy of this terminal reply associated with the supplied request id.
Signature
declare const withRequestId: (requestId: Snowflake) => WithExit<R>Since v4.0.0
[TypeId] (property)
Section titled “[TypeId] (property)”Marks this value as a runtime cluster reply.
Signature
readonly [TypeId]: "~effect/cluster/Reply"Since v4.0.0
WithExitEncoded (interface)
Section titled “WithExitEncoded (interface)”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>}Since v4.0.0
schemas
Section titled “schemas”Encoded
Section titled “Encoded”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>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>>Since v4.0.0
serialization
Section titled “serialization”serialize
Section titled “serialize”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>Since v4.0.0
serializeLastReceived
Section titled “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 const serializeLastReceived: <R extends Rpc.Any>( self: OutgoingRequest<R>) => Effect.Effect<Option.Option<Encoded>, MalformedMessage>Since v4.0.0