import * as Cause from "../Cause.ts"; import * as Context from "../Context.ts"; import * as Duration from "../Duration.ts"; import * as Effect from "../Effect.ts"; import * as Headers from "../http/Headers.ts"; import * as HttpClient from "../http/HttpClient.ts"; import * as Layer from "../Layer.ts"; import * as Queue from "../Queue.ts"; import * as Schedule from "../Schedule.ts"; import * as Scope from "../Scope.ts"; import * as Socket from "../socket/Socket.ts"; import * as Stream from "../Stream.ts"; import type * as Struct from "../Struct.ts"; import * as Worker from "../workers/Worker.ts"; import type { WorkerError } from "../workers/WorkerError.ts"; import * as Rpc from "./Rpc.ts"; import { RpcClientError } from "./RpcClientError.ts"; import type * as RpcGroup from "./RpcGroup.ts"; import type { FromClient, FromClientEncoded, FromServer, FromServerEncoded } from "./RpcMessage.ts"; import { RequestId } from "./RpcMessage.ts"; import * as RpcSchema from "./RpcSchema.ts"; import * as RpcSerialization from "./RpcSerialization.ts"; import { withRunClient } from "./Utils.ts"; /** * The object-shaped client generated from a union of RPC definitions, with one * method per RPC tag. * * @stability unstable * @category utility types * @since 4.0.0 */ export type RpcClient = Struct.Simplify>; /** * Type-level helpers for deriving RPC client call signatures from RPC * definitions. * * @stability unstable * @since 4.0.0 */ export declare namespace RpcClient { /** * Builds an object client type from an RPC union, mapping each RPC tag to a * method that accepts the RPC payload and returns either an `Effect` or * `Stream` based on the RPC success schema. * * @stability unstable * @category utility types * @since 4.0.0 */ type From = { readonly [Current in Rpcs as Current["_tag"]]: (input: Rpc.PayloadConstructor, options?: Rpc.Success extends Stream.Stream ? { readonly asQueue?: AsQueue | undefined; readonly streamBufferSize?: number | undefined; readonly headers?: Headers.Input | undefined; readonly context?: Context.Context | undefined; } : { readonly headers?: Headers.Input | undefined; readonly context?: Context.Context | undefined; readonly discard?: Discard | undefined; }) => Current extends Rpc.Rpc ? [_Success] extends [RpcSchema.Stream] ? AsQueue extends true ? Effect.Effect, never, Scope.Scope | _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] | _Middleware["error"]["DecodingServices"]> : Stream.Stream<_A["Type"], _E["Type"] | _Error["Type"] | E | _Middleware["error"]["Type"] | _Middleware["~ClientError"], _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] | _Middleware["error"]["DecodingServices"]> : Effect.Effect : never; }; /** * Builds a flattened RPC client function that accepts an RPC tag and payload, * returning the corresponding `Effect` or `Stream` for that RPC. * * @stability unstable * @category utility types * @since 4.0.0 */ type Flat = (tag: Tag, payload: Rpc.PayloadConstructor>, options?: Rpc.Success> extends Stream.Stream ? { readonly asQueue?: AsQueue | undefined; readonly streamBufferSize?: number | undefined; readonly headers?: Headers.Input | undefined; readonly context?: Context.Context | undefined; } : { readonly headers?: Headers.Input | undefined; readonly context?: Context.Context | undefined; readonly discard?: Discard | undefined; }) => Rpcs extends Rpc.Rpc ? [_Success] extends [RpcSchema.Stream] ? AsQueue extends true ? Effect.Effect, never, Scope.Scope | _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] | _Middleware["error"]["DecodingServices"]> : Stream.Stream<_A["Type"], _E["Type"] | _Error["Type"] | E | _Middleware["error"]["Type"] | _Middleware["~ClientError"], _Payload["EncodingServices"] | _Success["DecodingServices"] | _Error["DecodingServices"] | _Middleware["error"]["DecodingServices"]> : Effect.Effect : never; } /** * Derives the object-shaped RPC client type for all RPCs contained in an * `RpcGroup`. * * @stability unstable * @category utility types * @since 4.0.0 */ export type FromGroup = RpcClient, E>; /** * Creates an RPC client for an already-decoded message channel, returning the * client API together with a `write` function for delivering server messages * back to the client. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const makeNoSerialization: (group: RpcGroup.RpcGroup, options: { readonly onFromClient: (options: { readonly message: FromClient; readonly context: Context.Context; readonly discard: boolean; }) => Effect.Effect; readonly supportsAck?: boolean | undefined; readonly spanPrefix?: string | undefined; readonly spanAttributes?: Record | undefined; readonly generateRequestId?: (() => RequestId) | undefined; readonly disableTracing?: boolean | undefined; readonly flatten?: Flatten | undefined; }) => Effect.Effect<{ readonly client: Flatten extends true ? RpcClient.Flat : RpcClient; readonly write: (message: FromServer) => Effect.Effect; }, never, Scope.Scope | Rpc.MiddlewareClient>; /** * Creates a schema-aware RPC client for a group using the current client * `Protocol`, encoding requests and decoding server responses. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const make: (group: RpcGroup.RpcGroup, options?: { readonly spanPrefix?: string | undefined; readonly spanAttributes?: Record | undefined; readonly generateRequestId?: (() => RequestId) | undefined; readonly disableTracing?: boolean | undefined; readonly flatten?: Flatten | undefined; } | undefined) => Effect.Effect : RpcClient, never, Protocol | Rpc.MiddlewareClient | Scope.Scope>; /** * Fiber reference containing headers that are merged into outgoing RPC * client requests. * * **When to use** * * Use to set request headers that should be automatically merged into outgoing * RPC client messages. * * @stability unstable * @category services * @since 4.0.0 */ export declare const CurrentHeaders: Context.Reference; /** * Runs an effect with additional RPC client headers, merging them with the * current `CurrentHeaders` value for outgoing requests. * * @stability unstable * @category headers * @since 4.0.0 */ export declare const withHeaders: { /** * Runs an effect with additional RPC client headers, merging them with the * current `CurrentHeaders` value for outgoing requests. * * @stability unstable * @category headers * @since 4.0.0 */ (headers: Headers.Input): (effect: Effect.Effect) => Effect.Effect; /** * Runs an effect with additional RPC client headers, merging them with the * current `CurrentHeaders` value for outgoing requests. * * @stability unstable * @category headers * @since 4.0.0 */ (effect: Effect.Effect, headers: Headers.Input): Effect.Effect; }; declare const Protocol_base: Context.ServiceClass Effect.Effect) => Effect.Effect; readonly send: (clientId: number, request: FromClientEncoded, transferables?: ReadonlyArray) => Effect.Effect; readonly supportsAck: boolean; readonly supportsTransferables: boolean; /** * Builds the codec that fills the `unknown` holes of the protocol messages, * re-passed from the `RpcSerialization` backing this transport. */ readonly codecFor: RpcSerialization.CodecFor; }>; /** * Defines the service interface for an RPC client transport, responsible for running the * receive loop and sending encoded client messages. * * **When to use** * * Use to provide the transport boundary for RPC clients over HTTP, WebSocket, * workers, sockets, or custom protocols. * * @stability unstable * @category services * @since 4.0.0 */ export declare class Protocol extends Protocol_base { /** * Creates a client protocol service from the supplied RPC request runner. * * @stability unstable * @since 4.0.0 */ static make: typeof withRunClient; } /** * Creates a client `Protocol` that sends RPC requests through the supplied * `HttpClient` and decodes responses with the current `RpcSerialization`. * * **Details** * * Each request is sent as its own HTTP request unless `batch` is set. With * `batch`, the first request for a client opens a batch. Requests from the * same client made before `window` elapses join it, and the batch is sent once * the window elapses or it reaches `maxSize` requests, whichever comes first. * * @stability unstable * @category protocols * @since 4.0.0 */ export declare const makeProtocolHttp: (client: HttpClient.HttpClient, options?: { readonly batch?: { readonly window: Duration.Input; readonly maxSize?: number | undefined; } | undefined; }) => Effect.Effect; /** * Provides a client `Protocol` backed by `HttpClient`, targeting the configured * URL and optionally transforming the client before use. * * **Details** * * Set `batch` to send concurrent requests from the same client in a single * HTTP request. The first request for a client opens a batch. Requests from * the same client made before `window` elapses join it, and the batch is sent * once the window elapses or it reaches `maxSize` requests, whichever comes * first. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerProtocolHttp: (options: { readonly url: string; readonly transformClient?: (client: HttpClient.HttpClient.With) => HttpClient.HttpClient.With; readonly batch?: { readonly window: Duration.Input; readonly maxSize?: number | undefined; } | undefined; }) => Layer.Layer; /** * Creates a client `Protocol` over the current `Socket`, using the current * `RpcSerialization`, connection hooks, ping timeouts, and the configured retry * policy. * * **Details** * * `pingInterval` defaults to 5 seconds. `pingTimeout` defaults to the interval * and measures time since the last decoded server frame, not the last pong. * The timeout is checked on each ping tick; any decoded frame counts as liveness. * * @stability unstable * @category protocols * @since 4.0.0 */ export declare const makeProtocolSocket: (options?: { readonly pingInterval?: Duration.Input | undefined; readonly pingTimeout?: Duration.Input | undefined; readonly retryTransientErrors?: boolean | undefined; readonly retryPolicy?: Schedule.Schedule | undefined; /** * Runs for each retried `SocketOpenError` when `retryTransientErrors` is enabled. * A ping timeout fails in-flight calls and is reported through `onPingTimeout` * instead. The returned `Effect` cannot fail with a typed error or * require services; defects are logged and ignored so retries can continue. */ readonly onTransientError?: ((error: RpcClientError) => Effect.Effect) | undefined; /** * Runs when an open connection is dropped because no server frame arrived * within `pingTimeout`, before `ConnectionHooks.onDisconnect` and before * in-flight calls fail with a `SocketReadError`. Defects are logged and ignored. * * @since 4.0.3 */ readonly onPingTimeout?: Effect.Effect | undefined; }) => Effect.Effect; /** * Provides a client `Protocol` backed by the current `Socket` and * `RpcSerialization` services. * * **Details** * * `pingInterval` defaults to 5 seconds. `pingTimeout` defaults to the interval * and measures time since the last decoded server frame, not the last pong. * The timeout is checked on each ping tick; any decoded frame counts as liveness. * `retryPolicy` configures retries after socket errors. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerProtocolSocket: (options?: { readonly pingInterval?: Duration.Input | undefined; readonly pingTimeout?: Duration.Input | undefined; readonly retryTransientErrors?: boolean | undefined; readonly retryPolicy?: Schedule.Schedule | undefined; /** * Runs for each retried `SocketOpenError` when `retryTransientErrors` is enabled. * A ping timeout fails in-flight calls and is reported through `onPingTimeout` * instead. The returned `Effect` cannot fail with a typed error or * require services; defects are logged and ignored so retries can continue. */ readonly onTransientError?: ((error: RpcClientError) => Effect.Effect) | undefined; /** * Runs when an open connection is dropped because no server frame arrived * within `pingTimeout`, before `ConnectionHooks.onDisconnect` and before * in-flight calls fail with a `SocketReadError`. Defects are logged and ignored. * * @since 4.0.3 */ readonly onPingTimeout?: Effect.Effect | undefined; }) => Layer.Layer; /** * Creates a client `Protocol` backed by a pool of workers, routing RPC requests * to workers and supporting transferable values when the platform does. * * @stability unstable * @category protocols * @since 4.0.0 */ export declare const makeProtocolWorker: (options: { readonly size: number; readonly concurrency?: number | undefined; readonly targetUtilization?: number | undefined; } | { readonly minSize: number; readonly maxSize: number; readonly concurrency?: number | undefined; readonly targetUtilization?: number | undefined; readonly timeToLive: Duration.Input; }) => Effect.Effect; /** * Provides a client `Protocol` backed by a worker pool using the current worker * platform and spawner services. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerProtocolWorker: (options: { readonly size: number; readonly concurrency?: number | undefined; readonly targetUtilization?: number | undefined; } | { readonly minSize: number; readonly maxSize: number; readonly concurrency?: number | undefined; readonly targetUtilization?: number | undefined; readonly timeToLive: Duration.Input; }) => Layer.Layer; declare const ConnectionHooks_base: Context.ServiceClass; readonly onDisconnect: Effect.Effect; }>; /** * Represents optional client protocol hooks that run when a transport connects * and disconnects. * * **When to use** * * Use to run setup or cleanup effects when an RPC client transport opens or * closes. * * @stability unstable * @category services * @since 4.0.0 */ export declare class ConnectionHooks extends ConnectionHooks_base { } export {}; //# sourceMappingURL=RpcClient.d.ts.map