Class RPCClient<M>

Type Parameters

Hierarchy

  • RPCClient

Constructors

  • Type Parameters

    Parameters

    • obj: {
          idGen?: IdGen;
          logger?: Logger;
          manifest: M;
          middlewareFactory?: MiddlewareFactory<Uint8Array, JSONRPCRequest, JSONRPCResponse, Uint8Array>;
          streamFactory: StreamFactory;
          timeoutTime?: number;
          toError?: ToError;
      }
      • Optional idGen?: IdGen
      • Optional logger?: Logger
      • manifest: M

        Client manifest that defines the types for the rpc methods.

      • Optional middlewareFactory?: MiddlewareFactory<Uint8Array, JSONRPCRequest, JSONRPCResponse, Uint8Array>

        Middleware used to process the rpc messages. The middlewareFactory needs to be a function that creates a pair of transform streams that convert JSONRPCRequest to Uint8Array on the forward path and Uint8Array to JSONRPCResponse on the reverse path.

      • streamFactory: StreamFactory

        An arrow function that when called, creates a new stream for each rpc method call.

      • Optional timeoutTime?: number

        Timeout time used if no timeout timer was provided when making a call. Defaults to 60,000 milliseconds. for a client call.

      • Optional toError?: ToError

    Returns RPCClient<M>

Properties

callerTypes: Record<string, HandlerType>
idGen: IdGen
logger: Logger
methodsProxy: {} = ...

Type declaration

    middlewareFactory: MiddlewareFactory<Uint8Array, JSONRPCRequest, JSONRPCResponse, Uint8Array>
    onTimeoutCallback?: (() => void)

    Type declaration

      • (): void
      • Returns void

    streamFactory: StreamFactory
    timeoutTime: number
    toError: ToError

    Accessors

    Methods

    • Generic caller for Client streaming RPC calls. This returns a WritableStream for writing the input to and a Promise that resolves when the output is received. When finished the writable stream must be ended. Failing to do so will hold the connection open and result in a resource leak until the call times out.

      Type Parameters

      Parameters

      • method: string

        Method name of the RPC call

      • ctx: Partial<ContextTimedInput> = {}

        ContextTimed used for timeouts and cancellation.

      Returns Promise<{
          output: Promise<O>;
          writable: WritableStream<I>;
      }>

    • Generic caller for duplex RPC calls. This returns a ReadableWritablePair of the types specified. No validation is applied to these types so make sure they match the types of the handler you are calling. When finished the streams must be ended manually. Failing to do so will hold the connection open and result in a resource leak until the call times out.

      Type Parameters

      Parameters

      • method: string

        Method name of the RPC call

      • ctx: Partial<ContextTimedInput> = {}

        ContextTimed used for timeouts and cancellation.

      Returns Promise<RPCStream<O, I, POJO>>

    • Generic caller for raw RPC calls. This returns a ReadableWritablePair of the raw RPC stream. When finished the streams must be ended manually. Failing to do so will hold the connection open and result in a resource leak until the call times out. Raw streams don't support the keep alive timeout. Timeout will only apply
      to the creation of the stream.

      Parameters

      • method: string

        Method name of the RPC call

      • headerParams: JSONObject

        Parameters for the header message. The header is a single RPC message that is sent to specify the method for the RPC call. Any metadata of extra parameters is provided here.

      • ctx: Partial<ContextTimedInput> = {}

        ContextTimed used for timeouts and cancellation.

      Returns Promise<RPCStream<Uint8Array, Uint8Array, Record<string, JSONValue> & {
          command: string;
          result: JSONValue;
      }>>

    • Parameters

      • callback: (() => void)
          • (): void
          • Returns void

      Returns void

    • Generic caller for server streaming RPC calls. This returns a ReadableStream of the provided type. When finished, the readable needs to be cleaned up, otherwise cleanup happens mostly automatically.

      Type Parameters

      Parameters

      • method: string

        Method name of the RPC call

      • parameters: I

        Parameters to be provided with the RPC message. Matches the provided I type.

      • ctx: Partial<ContextTimedInput> = {}

        ContextTimed used for timeouts and cancellation.

      Returns Promise<ReadableStream<O>>

    • Generic caller for unary RPC calls. This returns the response in the provided type. No validation is done so make sure the types match the handler types.

      Type Parameters

      Parameters

      • method: string

        Method name of the RPC call

      • parameters: I

        Parameters to be provided with the RPC message. Matches the provided I type.

      • ctx: Partial<ContextTimedInput> = {}

        ContextTimed used for timeouts and cancellation.

      Returns Promise<O>

    Generated using TypeDoc