/** * Collects typed RPC definitions and server handlers. * * An `RpcGroup` stores RPC definitions by tag and keeps annotations shared by * the group. This module provides helpers for composing groups, applying * middleware or annotations, deriving handler types, and turning handler objects * into `Context` or `Layer` values used by RPC servers. * * @stability unstable * @since 4.0.0 */ import type * as Cause from "../Cause.ts"; import * as Context from "../Context.ts"; import * as Effect from "../Effect.ts"; import type { Headers } from "../http/Headers.ts"; import * as Layer from "../Layer.ts"; import type { Pipeable } from "../Pipeable.ts"; import type * as Queue from "../Queue.ts"; import type { Scope } from "../Scope.ts"; import * as Stream from "../Stream.ts"; import * as Rpc from "./Rpc.ts"; import type { RequestId } from "./RpcMessage.ts"; import type * as RpcMiddleware from "./RpcMiddleware.ts"; declare const TypeId = "~effect/rpc/RpcGroup"; /** * A collection of RPC definitions that can be composed, annotated, and * converted into server handlers or layers. * * @stability unstable * @category models * @since 4.0.0 */ export interface RpcGroup extends Pipeable { new (_: never): {}; readonly [TypeId]: typeof TypeId; readonly requests: ReadonlyMap; readonly annotations: Context.Context; /** * Add one or more procedures to the group. */ add>(...rpcs: Rpcs2): RpcGroup; /** * Merge this group with one or more other groups. */ merge>(...groups: Groups): RpcGroup>; /** * Omit one or more procedures from the group. */ omit>(...tags: Tags): RpcGroup>; /** * Add middleware to all the procedures added to the group until this point. */ middleware(middleware: M): RpcGroup>; /** * Add a prefix to the procedures in this group, returning a new group */ prefix(prefix: Prefix): RpcGroup>; /** * Implement the handlers for the procedures in this group, returning a * context object. */ toHandlers, EX = never, RX = never>(build: Handlers | Effect.Effect): Effect.Effect>, EX, RX | HandlersServices>; /** * Implement the handlers for the procedures in this group. */ toLayer, EX = never, RX = never>(build: Handlers | Effect.Effect): Layer.Layer, EX, Exclude | HandlersServices>; of>(handlers: Handlers): Handlers; /** * Implement a single handler from the group. */ toLayerHandler, EX = never, RX = never>(tag: Tag, build: Handler | Effect.Effect): Layer.Layer, EX, Exclude | HandlerServices>; /** * Retrieve a handler for a specific procedure in the group. */ accessHandler(tag: Tag): Effect.Effect<(payload: Rpc.Payload>, options: { readonly client: Rpc.ServerClient; readonly requestId: RequestId; readonly headers: Headers; }) => Rpc.ResultFrom, never>, never, Rpc.Handler>; /** * Annotate the group with a value. */ annotate(service: Context.Key, value: S): RpcGroup; /** * Annotate the Rpc's above this point with a value. */ annotateRpcs(service: Context.Key, value: S): RpcGroup; /** * Annotate the group with the provided annotations. */ annotateMerge(annotations: Context.Context): RpcGroup; /** * Annotate the Rpc's above this point with the provided annotations. */ annotateRpcsMerge(annotations: Context.Context): RpcGroup; } /** * An erased `RpcGroup` type for APIs that only need to know that a value is an * RPC group. * * @stability unstable * @category utility types * @since 4.0.0 */ export interface Any { readonly [TypeId]: typeof TypeId; } /** * Builds the object type of server handler functions required to implement each * RPC in a union. * * @stability unstable * @category utility types * @since 4.0.0 */ export type HandlersFrom = { readonly [Current in Rpc as Current["_tag"]]: Rpc.ToHandlerFn; }; /** * Extracts the server handler function type for a specific RPC tag from an RPC * union. * * @stability unstable * @category utility types * @since 4.0.0 */ export type HandlerFrom = Extract extends infer Current ? Current extends Rpc.Any ? Rpc.ToHandlerFn : never : never; /** * Computes the services required by all handlers in a handler object for an RPC * union. * * @stability unstable * @category utility types * @since 4.0.0 */ export type HandlersServices = keyof Handlers extends infer K ? K extends keyof Handlers & string ? HandlerServices : never : never; /** * Computes the services required by a single RPC handler, excluding services * provided by middleware and `Scope` where the server supplies it. * * @stability unstable * @category utility types * @since 4.0.0 */ export type HandlerServices = true extends Rpc.IsStream ? Handler extends (...args: any) => Stream.Stream | Rpc.Wrapper> | Effect.Effect, infer _EX, infer _R> | Rpc.Wrapper, infer _EX, infer _R>> ? Exclude, Scope> | Rpc.ExtractRequires : never : Handler extends (...args: any) => Effect.Effect | Rpc.Wrapper> ? Exclude, Scope> | Rpc.ExtractRequires : never; /** * Extracts the union of RPC definitions from an `RpcGroup`. * * @stability unstable * @category utility types * @since 4.0.0 */ export type Rpcs = Group extends RpcGroup ? string extends R["_tag"] ? never : R : never; /** * Creates an `RpcGroup` from one or more RPC definitions. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const make: >(...rpcs: Rpcs) => RpcGroup; export {}; //# sourceMappingURL=RpcGroup.d.ts.map