RpcServer.ts overview

Since v1.0.0


Exports Grouped by Category


Interruption

fiberIdClientInterrupt

Fiber id used for client interruptions.

Signature

declare const fiberIdClientInterrupt: FiberId.Runtime

Source

Since v1.0.0

fiberIdTransientInterrupt

Fiber id used for transient interruptions.

Signature

declare const fiberIdTransientInterrupt: FiberId.Runtime

Source

Since v1.0.0

constructors

toWebHandler

Construct an http web handler from an RpcGroup.

Signature

declare const toWebHandler: <Rpcs extends Rpc.Any, LE>(
  group: RpcGroup.RpcGroup<Rpcs>,
  options: {
    readonly layer: Layer.Layer<
      | Rpc.ToHandler<Rpcs>
      | Rpc.Middleware<Rpcs>
      | RpcSerialization.RpcSerialization
      | HttpRouter.HttpRouter.DefaultServices,
      LE
    >
    readonly disableTracing?: boolean | undefined
    readonly spanPrefix?: string | undefined
    readonly spanAttributes?: Record<string, unknown> | undefined
    readonly disableFatalDefects?: boolean | undefined
    readonly middleware?: (httpApp: HttpApp.Default) => HttpApp.Default<never, HttpRouter.HttpRouter.DefaultServices>
    readonly memoMap?: Layer.MemoMap
  }
) => {
  readonly handler: (request: globalThis.Request, context?: Context.Context<never> | undefined) => Promise<Response>
  readonly dispose: () => Promise<void>
}

Source

Since v1.0.0

http app

toHttpApp

Signature

declare const toHttpApp: <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<
  HttpApp.Default<never, Scope.Scope>,
  never,
  Scope.Scope | RpcSerialization.RpcSerialization | Rpc.ToHandler<Rpcs> | Rpc.Context<Rpcs> | Rpc.Middleware<Rpcs>
>

Source

Since v1.0.0

toHttpAppWebsocket

Signature

declare const toHttpAppWebsocket: <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<
  HttpApp.Default<never, Scope.Scope>,
  never,
  Scope.Scope | RpcSerialization.RpcSerialization | Rpc.ToHandler<Rpcs> | Rpc.Context<Rpcs> | Rpc.Middleware<Rpcs>
>

Source

Since v1.0.0

protocol

Protocol (class)

Signature

declare class Protocol

Source

Since v1.0.0

layerHttpRouter

Create a RPC server that registers a HTTP route with a HttpLayerRouter.

It defaults to using websockets for communication, but can be configured to use HTTP.

Signature

declare const layerHttpRouter: <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
  | HttpLayerRouter.HttpRouter
  | Rpc.ToHandler<Rpcs>
  | Rpc.Context<Rpcs>
  | Rpc.Middleware<Rpcs>
>

Source

Since v1.0.0

layerProtocolHttp

A rpc protocol that uses streaming http for communication.

Signature

declare const layerProtocolHttp: <I = HttpRouter.Default>(options: {
  readonly path: HttpRouter.PathInput
  readonly routerTag?: HttpRouter.HttpRouter.TagClass<I, string, any, any>
}) => Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization>

Source

Since v1.0.0

layerProtocolHttpRouter

A rpc protocol that uses streaming http for communication.

Uses a HttpLayerRouter to provide the http endpoint.

Signature

declare const layerProtocolHttpRouter: (options: {
  readonly path: HttpRouter.PathInput
}) => Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | HttpLayerRouter.HttpRouter>

Source

Since v1.0.0

layerProtocolSocketServer

A rpc protocol that uses SocketServer for communication.

Signature

declare const layerProtocolSocketServer: Layer.Layer<
  Protocol,
  never,
  RpcSerialization.RpcSerialization | SocketServer.SocketServer
>

Source

Since v1.0.0

layerProtocolStdio

Create a protocol that uses the provided Stream and Sink for communication.

Signature

declare const layerProtocolStdio: <EIn, EOut, RIn, ROut>(options: {
  readonly stdin: Stream.Stream<Uint8Array, EIn, RIn>
  readonly stdout: Sink.Sink<void, Uint8Array | string, unknown, EOut, ROut>
}) => Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | RIn | ROut>

Source

Since v1.0.0

layerProtocolWebsocket

A rpc protocol that uses websockets for communication.

Signature

declare const layerProtocolWebsocket: <I = HttpRouter.Default>(options: {
  readonly path: HttpRouter.PathInput
  readonly routerTag?: HttpRouter.HttpRouter.TagClass<I, string, any, any>
}) => Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization>

Source

Since v1.0.0

layerProtocolWebsocketRouter

A rpc protocol that uses websockets for communication.

Uses a HttpLayerRouter to provide the websocket endpoint.

Signature

declare const layerProtocolWebsocketRouter: (options: {
  readonly path: HttpLayerRouter.PathInput
}) => Layer.Layer<Protocol, never, RpcSerialization.RpcSerialization | HttpLayerRouter.HttpRouter>

Source

Since v1.0.0

layerProtocolWorkerRunner

Signature

declare const layerProtocolWorkerRunner: Layer.Layer<Protocol, WorkerError, WorkerRunner.PlatformRunner>

Source

Since v1.0.0

makeProtocolHttp

Signature

declare const makeProtocolHttp: <I = HttpRouter.Default>(options: {
  readonly path: HttpRouter.PathInput
  readonly routerTag?: HttpRouter.HttpRouter.TagClass<I, string, any, any>
}) => Effect.Effect<
  {
    readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>
    readonly disconnects: Mailbox.ReadonlyMailbox<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,
  RpcSerialization.RpcSerialization | I
>

Source

Since v1.0.0

makeProtocolHttpRouter

Signature

declare const makeProtocolHttpRouter: (options: {
  readonly path: HttpRouter.PathInput
}) => Effect.Effect<
  {
    readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>
    readonly disconnects: Mailbox.ReadonlyMailbox<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,
  RpcSerialization.RpcSerialization | HttpLayerRouter.HttpRouter
>

Source

Since v1.0.0

makeProtocolSocketServer

Signature

declare const makeProtocolSocketServer: Effect.Effect<
  {
    readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>
    readonly disconnects: Mailbox.ReadonlyMailbox<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
>

Source

Since v1.0.0

makeProtocolStdio

Create a protocol that uses the provided Stream and Sink for communication.

Signature

declare const makeProtocolStdio: <EIn, EOut, RIn, ROut>(options: {
  readonly stdin: Stream.Stream<Uint8Array, EIn, RIn>
  readonly stdout: Sink.Sink<void, Uint8Array | string, unknown, EOut, ROut>
}) => Effect.Effect<
  {
    readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>
    readonly disconnects: Mailbox.ReadonlyMailbox<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 | RIn | Exclude<ROut, Scope.Scope>
>

Source

Since v1.0.0

makeProtocolWebsocket

Signature

declare const makeProtocolWebsocket: <I = HttpRouter.Default>(options: {
  readonly path: HttpRouter.PathInput
  readonly routerTag?: Context.Tag<I, HttpRouter.HttpRouter.Service<any, any>>
}) => Effect.Effect<Protocol["Type"], never, RpcSerialization.RpcSerialization | I>

Source

Since v1.0.0

makeProtocolWebsocketRouter

Signature

declare const makeProtocolWebsocketRouter: (options: {
  readonly path: HttpRouter.PathInput
}) => Effect.Effect<Protocol["Type"], never, RpcSerialization.RpcSerialization | HttpLayerRouter.HttpRouter>

Source

Since v1.0.0

makeProtocolWithHttpApp

Signature

declare const makeProtocolWithHttpApp: Effect.Effect<
  { readonly protocol: Protocol["Type"]; readonly httpApp: HttpApp.Default<never, Scope.Scope> },
  never,
  RpcSerialization.RpcSerialization
>

Source

Since v1.0.0

makeProtocolWithHttpAppWebsocket

Signature

declare const makeProtocolWithHttpAppWebsocket: Effect.Effect<
  { readonly protocol: Protocol["Type"]; readonly httpApp: HttpApp.Default<never, Scope.Scope> },
  never,
  RpcSerialization.RpcSerialization
>

Source

Since v1.0.0

makeProtocolWorkerRunner

Signature

declare const makeProtocolWorkerRunner: Effect.Effect<
  {
    readonly run: (f: (clientId: number, data: FromClientEncoded) => Effect.Effect<void>) => Effect.Effect<never>
    readonly disconnects: Mailbox.ReadonlyMailbox<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
  },
  WorkerError,
  Scope.Scope | WorkerRunner.PlatformRunner
>

Source

Since v1.0.0

server

RpcServer (interface)

Signature

export interface RpcServer<A extends Rpc.Any> {
  readonly write: (clientId: number, message: FromClient<A>) => Effect.Effect<void>
  readonly disconnect: (clientId: number) => Effect.Effect<void>
}

Source

Since v1.0.0

layer

Signature

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.Context<Rpcs> | Rpc.Middleware<Rpcs>>

Source

Since v1.0.0

make

Signature

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.Context<Rpcs>>

Source

Since v1.0.0

makeNoSerialization

Signature

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>

Source

Since v1.0.0