/** * 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. * * @stability unstable * @since 4.0.0 */ import type { NonEmptyReadonlyArray } from "../Array.ts"; import * as Context from "../Context.ts"; import * as Effect from "../Effect.ts"; import * as Option from "../Option.ts"; import * as Rpc from "../rpc/Rpc.ts"; import type * as RpcMessage from "../rpc/RpcMessage.ts"; import type * as RpcSerialization from "../rpc/RpcSerialization.ts"; import * as Schema from "../Schema.ts"; import * as SchemaTransformation from "../SchemaTransformation.ts"; import { MalformedMessage } from "./ClusterError.ts"; import type { OutgoingRequest } from "./Message.ts"; import { Snowflake } from "./Snowflake.ts"; declare const TypeId = "~effect/cluster/Reply"; /** * Returns `true` when the supplied value is a runtime cluster reply, based on the * reply type identifier. * * @stability unstable * @category guards * @since 4.0.0 */ export declare const isReply: (u: unknown) => u is Reply; /** * Runtime reply sent for an RPC request, either as a final exit or a chunk of a * streaming success value. * * @stability unstable * @category models * @since 4.0.0 */ export type Reply = WithExit | Chunk; /** * JSON-serializable form of a cluster reply. * * @stability unstable * @category models * @since 4.0.0 */ export type Encoded = WithExitEncoded | ChunkEncoded; /** * Schema for reply values that are already in encoded form. * * **Details** * * Per-RPC payload validation is performed by `Reply(rpc)`. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const Encoded: Schema.Codec; declare const ReplyWithContext_base: new = {}>(args: import("../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly & { readonly _tag: "ReplyWithContext"; } & import("../Pipeable.ts").Pipeable; /** * 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. * * @stability unstable * @category models * @since 4.0.0 */ export declare class ReplyWithContext extends ReplyWithContext_base<{ readonly reply: Reply; readonly context: Context.Context>; readonly rpc: R; }> { /** * Creates a terminal reply context that dies with the supplied defect. * * @stability unstable * @since 4.0.0 */ static fromDefect(options: { readonly id: Snowflake; readonly requestId: Snowflake; readonly defect: unknown; }): ReplyWithContext; /** * Creates a terminal reply context that interrupts the supplied request. * * @stability unstable * @since 4.0.0 */ static interrupt(options: { readonly id: Snowflake; readonly requestId: Snowflake; }): ReplyWithContext; } /** * Wire-format representation of a terminal reply containing the request id, reply * id, and encoded RPC exit value. * * @stability unstable * @category models * @since 4.0.0 */ export interface WithExitEncoded { readonly _tag: "WithExit"; readonly requestId: string; readonly id: string; readonly exit: RpcMessage.ExitEncoded; } /** * Wire-format representation of a streaming reply chunk, including the request id, * reply id, sequence number, and non-empty encoded values. * * @stability unstable * @category models * @since 4.0.0 */ export interface ChunkEncoded { readonly _tag: "Chunk"; readonly requestId: string; readonly id: string; readonly sequence: number; readonly values: NonEmptyReadonlyArray; } declare const Chunk_base: new = {}>(args: import("../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly & { readonly _tag: "Chunk"; } & import("../Pipeable.ts").Pipeable; /** * 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. * * @stability unstable * @category models * @since 4.0.0 */ export declare class Chunk extends Chunk_base<{ readonly requestId: Snowflake; readonly id: Snowflake; readonly sequence: number; readonly values: NonEmptyReadonlyArray>; }> { /** * Marks this value as a runtime cluster reply. * * @stability unstable * @since 4.0.0 */ readonly [TypeId] = "~effect/cluster/Reply"; /** * Creates an empty chunk reply for the supplied request id. * * @stability unstable * @since 4.0.0 */ static emptyFrom(requestId: Snowflake): Chunk; /** * Schema that accepts any runtime chunk reply without validating payload values. * * @stability unstable * @since 4.0.0 */ static readonly Any: Schema.declare, Chunk>; /** * Transformation between encoded chunk records and `Chunk` instances. * * @stability unstable * @since 4.0.0 */ static readonly transform: SchemaTransformation.Transformation; /** * Builds a chunk schema from the streaming success schema of an RPC. * * @stability unstable * @since 4.0.0 */ static schema(rpc: R): Schema.declareConstructor, Chunk, readonly [Rpc.SuccessExitSchema]>; /** * Builds a chunk schema that validates each success value with the supplied schema. * * @stability unstable * @since 4.0.0 */ static schemaFrom(success: Success): Schema.declareConstructor, Chunk, readonly [Success]>; /** * Returns a copy of this chunk associated with the supplied request id. * * @stability unstable * @since 4.0.0 */ withRequestId(requestId: Snowflake): Chunk; } declare const WithExit_base: new = {}>(args: import("../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly & { readonly _tag: "WithExit"; } & import("../Pipeable.ts").Pipeable; /** * 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. * * @stability unstable * @category models * @since 4.0.0 */ export declare class WithExit extends WithExit_base<{ readonly requestId: Snowflake; readonly id: Snowflake; readonly exit: Rpc.Exit; }> { /** * Marks this value as a runtime cluster reply. * * @stability unstable * @since 4.0.0 */ readonly [TypeId] = "~effect/cluster/Reply"; /** * Returns `true` when the value is a terminal `WithExit` reply. * * @stability unstable * @since 4.0.0 */ static is(u: unknown): u is WithExit; /** * Builds a terminal reply schema from the exit schema of an RPC. * * @stability unstable * @since 4.0.0 */ static schema(rpc: R): Schema.declareConstructor, WithExit, readonly [Schema.Exit, Rpc.ErrorExitSchema, Rpc.DefectSchema>]>; /** * Builds a terminal reply schema that validates the encoded exit value. * * @stability unstable * @since 4.0.0 */ static schemaFrom(exitSchema: Schema.Exit): Schema.declareConstructor, WithExit, readonly [Schema.Exit]>; /** * Returns a copy of this terminal reply associated with the supplied request id. * * @stability unstable * @since 4.0.0 */ withRequestId(requestId: Snowflake): WithExit; } /** * Builds the transport codec for replies to the specified RPC, covering terminal * `WithExit` replies and streaming `Chunk` replies. * * @stability unstable * @category schemas * @since 4.0.0 */ export declare const Reply: (rpc: R, codecFor: RpcSerialization.CodecFor) => Schema.Codec | Chunk, Encoded, Rpc.ServicesClient, Rpc.ServicesServer>; /** * Serializes a `ReplyWithContext` into its encoded wire representation, using the * reply's RPC schema and context and refailing encoding errors as * `MalformedMessage`. * * @stability unstable * @category serialization * @since 4.0.0 */ export declare const serialize: (self: ReplyWithContext, codecFor: RpcSerialization.CodecFor) => Effect.Effect; /** * Serializes a `ReplyWithContext`, falling back to a serializable defect reply * when the original reply cannot be encoded. * * @stability unstable * @category serialization * @since 4.0.0 */ export declare const serializeOrDefect: (self: ReplyWithContext, codecFor: RpcSerialization.CodecFor) => Effect.Effect; /** * 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`. * * @stability unstable * @category serialization * @since 4.0.0 */ export declare const serializeLastReceived: (self: OutgoingRequest, codecFor: RpcSerialization.CodecFor) => Effect.Effect, MalformedMessage>; export {}; //# sourceMappingURL=Reply.d.ts.map