EdgeAIG's picture
download
raw
14.3 kB
import * as Context from "../../Context.ts";
import * as Effect from "../../Effect.ts";
import * as Layer from "../../Layer.ts";
import * as Option from "../../Option.ts";
import * as Queue from "../../Queue.ts";
import * as Scope from "../../Scope.ts";
import { Stdio } from "../../Stdio.ts";
import * as HttpRouter from "../http/HttpRouter.ts";
import * as HttpServerRequest from "../http/HttpServerRequest.ts";
import * as HttpServerResponse from "../http/HttpServerResponse.ts";
import * as SocketServer from "../socket/SocketServer.ts";
import type { WorkerError } from "../workers/WorkerError.ts";
import * as WorkerRunner from "../workers/WorkerRunner.ts";
import * as Rpc from "./Rpc.ts";
import type * as RpcGroup from "./RpcGroup.ts";
import type { FromClient, FromClientEncoded, FromServer, FromServerEncoded } from "./RpcMessage.ts";
import * as RpcSerialization from "./RpcSerialization.ts";
/**
* The decoded RPC server boundary, accepting client messages for a client id
* and allowing that client to be disconnected.
*
* @category server
* @since 4.0.0
*/
export interface RpcServer<A extends Rpc.Any> {
readonly write: (clientId: number, message: FromClient<A>) => Effect.Effect<void>;
readonly disconnect: (clientId: number) => Effect.Effect<void>;
}
/**
* Creates an RPC server for an already-decoded message channel, running
* handlers for a group and sending decoded server responses through
* `onFromServer`.
*
* @category server
* @since 4.0.0
*/
export declare const makeNoSerialization: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options: {
readonly onFromServer: (response: FromServer<Rpcs>) => Effect.Effect<void>;
readonly disableTracing?: boolean | undefined;
readonly disableSpanPropagation?: boolean | undefined;
readonly spanPrefix?: string | undefined;
readonly spanAttributes?: Record<string, unknown> | undefined;
readonly disableClientAcks?: boolean | undefined;
readonly concurrency?: number | "unbounded" | undefined;
readonly disableFatalDefects?: boolean | undefined;
}) => Effect.Effect<RpcServer<Rpcs>, never, Rpc.ToHandler<Rpcs> | Rpc.Middleware<Rpcs> | Scope.Scope>;
/**
* Runs an RPC server for a group using the current server `Protocol`, decoding
* requests, invoking handlers, encoding responses, and managing in-flight
* request lifetime.
*
* @category server
* @since 4.0.0
*/
export declare const make: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options?: {
readonly disableTracing?: boolean | undefined;
readonly spanPrefix?: string | undefined;
readonly spanAttributes?: Record<string, unknown> | undefined;
readonly concurrency?: number | "unbounded" | undefined;
readonly disableFatalDefects?: boolean | undefined;
} | undefined) => Effect.Effect<never, never, Protocol | Rpc.ToHandler<Rpcs> | Rpc.Middleware<Rpcs> | Rpc.ServicesServer<Rpcs>>;
/**
* Provides a scoped layer that starts an RPC server for a group using the
* current server `Protocol`.
*
* @category server
* @since 4.0.0
*/
export declare const layer: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options?: {
readonly disableTracing?: boolean | undefined;
readonly spanPrefix?: string | undefined;
readonly spanAttributes?: Record<string, unknown> | undefined;
readonly concurrency?: number | "unbounded" | undefined;
readonly disableFatalDefects?: boolean | undefined;
}) => Layer.Layer<never, never, Protocol | Rpc.ToHandler<Rpcs> | Rpc.Middleware<Rpcs> | Rpc.ServicesServer<Rpcs>>;
/**
* Creates a RPC server that registers a HTTP route with a `HttpRouter`.
*
* **Details**
*
* Defaults to using websockets for communication, but can be configured to use
* HTTP.
*
* @category protocols
* @since 4.0.0
*/
export declare const layerHttp: <Rpcs extends Rpc.Any>(options: {
readonly group: RpcGroup.RpcGroup<Rpcs>;
readonly path: HttpRouter.PathInput;
readonly protocol?: "http" | "websocket" | undefined;
readonly disableTracing?: boolean | undefined;
readonly spanPrefix?: string | undefined;
readonly spanAttributes?: Record<string, unknown> | undefined;
readonly concurrency?: number | "unbounded" | undefined;
readonly disableFatalDefects?: boolean | undefined;
}) => Layer.Layer<never, never, RpcSerialization.RpcSerialization | HttpRouter.HttpRouter | Rpc.ToHandler<Rpcs> | Rpc.Middleware<Rpcs> | Rpc.ServicesServer<Rpcs>>;
declare const Protocol_base: Context.ServiceClass<Protocol, "effect/rpc/RpcServer/Protocol", {
readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>;
readonly disconnects: Queue.Dequeue<number>;
readonly send: (clientId: number, response: FromServerEncoded, transferables?: ReadonlyArray<globalThis.Transferable>) => Effect.Effect<void>;
readonly end: (clientId: number) => Effect.Effect<void>;
readonly clientIds: Effect.Effect<ReadonlySet<number>>;
readonly initialMessage: Effect.Effect<Option.Option<unknown>>;
readonly supportsAck: boolean;
readonly supportsTransferables: boolean;
readonly supportsSpanPropagation: boolean;
}>;
/**
* Defines the service interface for an RPC server transport, responsible for receiving
* encoded client messages, sending encoded responses, tracking clients, and
* declaring transport capabilities.
*
* **When to use**
*
* Use to provide the transport boundary for RPC servers over HTTP, WebSocket,
* workers, sockets, or custom protocols.
*
* @category protocols
* @since 4.0.0
*/
export declare class Protocol extends Protocol_base {
/**
* Creates a server protocol service from the supplied RPC implementation.
*
* @since 4.0.0
*/
static make: <EX, RX>(f: (write: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<Omit<{
readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>;
readonly disconnects: Queue.Dequeue<number>;
readonly send: (clientId: number, response: FromServerEncoded, transferables?: ReadonlyArray<globalThis.Transferable>) => Effect.Effect<void>;
readonly end: (clientId: number) => Effect.Effect<void>;
readonly clientIds: Effect.Effect<ReadonlySet<number>>;
readonly initialMessage: Effect.Effect<Option.Option<unknown>>;
readonly supportsAck: boolean;
readonly supportsTransferables: boolean;
readonly supportsSpanPropagation: boolean;
}, "run">, EX, RX>) => Effect.Effect<{
readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>;
readonly disconnects: Queue.Dequeue<number>;
readonly send: (clientId: number, response: FromServerEncoded, transferables?: ReadonlyArray<globalThis.Transferable>) => Effect.Effect<void>;
readonly end: (clientId: number) => Effect.Effect<void>;
readonly clientIds: Effect.Effect<ReadonlySet<number>>;
readonly initialMessage: Effect.Effect<Option.Option<unknown>>;
readonly supportsAck: boolean;
readonly supportsTransferables: boolean;
readonly supportsSpanPropagation: boolean;
}, EX, RX>;
}
/**
* Creates a server `Protocol` backed by the current `SocketServer`, accepting
* socket connections and routing decoded RPC messages.
*
* @category protocols
* @since 4.0.0
*/
export declare const makeProtocolSocketServer: Effect.Effect<{
readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>;
readonly disconnects: Queue.Dequeue<number>;
readonly send: (clientId: number, response: FromServerEncoded, transferables?: ReadonlyArray<globalThis.Transferable>) => Effect.Effect<void>;
readonly end: (clientId: number) => Effect.Effect<void>;
readonly clientIds: Effect.Effect<ReadonlySet<number>>;
readonly initialMessage: Effect.Effect<Option.Option<unknown>>;
readonly supportsAck: boolean;
readonly supportsTransferables: boolean;
readonly supportsSpanPropagation: boolean;
}, never, Scope.Scope | RpcSerialization.RpcSerialization | SocketServer.SocketServer>;
/**
* RPC protocol that uses `SocketServer` for communication.
*
* @category protocols
* @since 4.0.0
*/
export declare const layerProtocolSocketServer: Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | SocketServer.SocketServer>;
/**
* Creates a websocket server `Protocol` together with an HTTP effect that
* upgrades the current request to a websocket and attaches it to the protocol.
*
* @category protocols
* @since 4.0.0
*/
export declare const makeProtocolWithHttpEffectWebsocket: Effect.Effect<{
readonly protocol: Protocol["Service"];
readonly httpEffect: Effect.Effect<HttpServerResponse.HttpServerResponse, never, Scope.Scope | HttpServerRequest.HttpServerRequest>;
}, never, RpcSerialization.RpcSerialization>;
/**
* Creates a websocket server `Protocol` and registers its upgrade handler as a
* GET route on the current `HttpRouter`.
*
* @category protocols
* @since 4.0.0
*/
export declare const makeProtocolWebsocket: (options: {
readonly path: HttpRouter.PathInput;
}) => Effect.Effect<Protocol["Service"], never, RpcSerialization.RpcSerialization | HttpRouter.HttpRouter>;
/**
* RPC protocol that uses WebSockets for communication.
*
* @category protocols
* @since 4.0.0
*/
export declare const layerProtocolWebsocket: (options: {
readonly path: HttpRouter.PathInput;
}) => Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | HttpRouter.HttpRouter>;
/**
* Creates an HTTP request/response server `Protocol` together with an HTTP
* effect that decodes the current request and streams or returns encoded RPC
* responses.
*
* @category protocols
* @since 4.0.0
*/
export declare const makeProtocolWithHttpEffect: Effect.Effect<{
readonly protocol: Protocol["Service"];
readonly httpEffect: Effect.Effect<HttpServerResponse.HttpServerResponse, never, Scope.Scope | HttpServerRequest.HttpServerRequest>;
}, never, RpcSerialization.RpcSerialization>;
/**
* Creates an HTTP server `Protocol` and registers its request handler as a POST
* route on the current `HttpRouter`.
*
* @category protocols
* @since 4.0.0
*/
export declare const makeProtocolHttp: (options: {
readonly path: HttpRouter.PathInput;
}) => Effect.Effect<Protocol["Service"], never, RpcSerialization.RpcSerialization | HttpRouter.HttpRouter>;
/**
* Provides a server `Protocol` that uses HTTP POST requests for RPC
* communication.
*
* @category protocols
* @since 4.0.0
*/
export declare const layerProtocolHttp: (options: {
readonly path: HttpRouter.PathInput;
}) => Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | HttpRouter.HttpRouter>;
/**
* Starts an RPC server for a group and returns the HTTP request/response effect
* that serves the non-websocket HTTP RPC protocol.
*
* @category http app
* @since 4.0.0
*/
export declare const toHttpEffect: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options?: {
readonly disableTracing?: boolean | undefined;
readonly spanPrefix?: string | undefined;
readonly spanAttributes?: Record<string, unknown> | undefined;
readonly disableFatalDefects?: boolean | undefined;
} | undefined) => Effect.Effect<Effect.Effect<HttpServerResponse.HttpServerResponse, never, Scope.Scope | HttpServerRequest.HttpServerRequest>, never, Scope.Scope | RpcSerialization.RpcSerialization | Rpc.ToHandler<Rpcs> | Rpc.Middleware<Rpcs> | Rpc.ServicesServer<Rpcs>>;
/**
* Starts an RPC server for a group and returns the HTTP effect that upgrades
* requests to the websocket RPC protocol.
*
* @category http app
* @since 4.0.0
*/
export declare const toHttpEffectWebsocket: <Rpcs extends Rpc.Any>(group: RpcGroup.RpcGroup<Rpcs>, options?: {
readonly disableTracing?: boolean | undefined;
readonly spanPrefix?: string | undefined;
readonly spanAttributes?: Record<string, unknown> | undefined;
readonly disableFatalDefects?: boolean | undefined;
} | undefined) => Effect.Effect<Effect.Effect<HttpServerResponse.HttpServerResponse, never, Scope.Scope | HttpServerRequest.HttpServerRequest>, never, Scope.Scope | RpcSerialization.RpcSerialization | Rpc.ToHandler<Rpcs> | Rpc.Middleware<Rpcs> | Rpc.ServicesServer<Rpcs>>;
/**
* Creates a server `Protocol` that reads RPC messages from `Stdio.stdin` and
* writes encoded responses to `Stdio.stdout`.
*
* @category protocols
* @since 4.0.0
*/
export declare const makeProtocolStdio: Effect.Effect<{
readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>;
readonly disconnects: Queue.Dequeue<number>;
readonly send: (clientId: number, response: FromServerEncoded, transferables?: ReadonlyArray<globalThis.Transferable>) => Effect.Effect<void>;
readonly end: (clientId: number) => Effect.Effect<void>;
readonly clientIds: Effect.Effect<ReadonlySet<number>>;
readonly initialMessage: Effect.Effect<Option.Option<unknown>>;
readonly supportsAck: boolean;
readonly supportsTransferables: boolean;
readonly supportsSpanPropagation: boolean;
}, never, Scope.Scope | Stdio | RpcSerialization.RpcSerialization>;
/**
* Provides a server `Protocol` that reads RPC messages from `Stdio.stdin` and
* writes encoded responses to `Stdio.stdout`.
*
* @category protocols
* @since 4.0.0
*/
export declare const layerProtocolStdio: Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | Stdio>;
/**
* Creates a server `Protocol` backed by `WorkerRunnerPlatform`, routing worker
* messages to the RPC server and server responses back to workers.
*
* @category protocols
* @since 4.0.0
*/
export declare const makeProtocolWorkerRunner: Effect.Effect<Protocol["Service"], WorkerError, WorkerRunner.WorkerRunnerPlatform | Scope.Scope>;
/**
* Provides a server `Protocol` backed by the current `WorkerRunnerPlatform`.
*
* @category protocols
* @since 4.0.0
*/
export declare const layerProtocolWorkerRunner: Layer.Layer<Protocol, WorkerError, WorkerRunner.WorkerRunnerPlatform>;
export {};
//# sourceMappingURL=RpcServer.d.ts.map

Xet Storage Details

Size:
14.3 kB
·
Xet hash:
318b2331d4856320f3490b538a945cde35e2209920d2d4a116e5a376fa9859ca

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