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

Xet Storage Details

Size:
9.15 kB
·
Xet hash:
dd1d601ac26ea9126fdbdfd10600c590d35bb6221fe7dcd2f40fa637c0b1e11e

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.