Options
All
  • Public
  • Public/Protected
  • All
Menu

Package json-rpc

@typed/json-rpc

A relative work-in-progress compared to the rest of the libraries in Typed, but is an attempt to abstract the building of JSON-RPC servers and client connects using @typed/effects, @typed/hooks, and the ecosystem.

Index

Type aliases

Batch

BatchRequest

BatchRequest: JsonRpcRequest[]

BatchResponse

BatchResponse: JsonRpcResponse[]

ConnectionEnv

ConnectionEnv: { connection: Connection }

Type declaration

ConnectionEvent

ConnectionEvent: Tuple<"add", Connection> | Tuple<"remove", Connection>

HandlerMap

HandlerMap<A>: ReadonlyMap<string, Tuple<A, any>>

Type parameters

  • A

Id

Id: string | number

IsNever

IsNever<A>: [A] extends [never] ? true : false

Type parameters

  • A

JsonRpcError

JsonRpcError<Code, ErrorData>: IsNever<ErrorData> extends true ? { code: Code; message: string } : { code: Code; data: ErrorData; message: string }

Type parameters

  • Code: number

  • ErrorData: Json

JsonRpcFailedResponse

JsonRpcFailedResponse<Code, ErrorData>: { error: JsonRpcError<Code, ErrorData>; id: Id; jsonrpc: "2.0" }

Type parameters

  • Code: number

  • ErrorData: Json

Type declaration

  • Readonly error: JsonRpcError<Code, ErrorData>
  • Readonly id: Id
  • Readonly jsonrpc: "2.0"

JsonRpcNotification

JsonRpcNotification<Method, Params>: IsNever<Params> extends true ? { jsonrpc: "2.0"; method: Method } : { jsonrpc: "2.0"; method: Method; params: Params }

Type parameters

JsonRpcRequest

JsonRpcRequest<Method, Params>: IsNever<Params> extends true ? { id: Id; jsonrpc: "2.0"; method: Method } : { id: Id; jsonrpc: "2.0"; method: Method; params: Params }

Type parameters

JsonRpcResponse

JsonRpcResponse<Result, Code, ErrorData>: JsonRpcSuccessfulResponse<Result> | JsonRpcFailedResponse<Code, ErrorData>

Type parameters

JsonRpcSuccessfulResponse

JsonRpcSuccessfulResponse<Result>: { id: Id; jsonrpc: "2.0"; result: Result }

Type parameters

Type declaration

  • Readonly id: Id
  • Readonly jsonrpc: "2.0"
  • Readonly result: Result

Message

NotificationHandler

NotificationHandler<E, A>: (notification: A) => HookEffects<E, void>

Type parameters

Type declaration

    • (notification: A): HookEffects<E, void>
    • Parameters

      • notification: A

      Returns HookEffects<E, void>

RequestHandler

RequestHandler<E, A, B>: (notification: A) => HookEffects<E, B>

Type parameters

Type declaration

    • (notification: A): HookEffects<E, B>
    • Parameters

      • notification: A

      Returns HookEffects<E, B>

SendRequest

SendRequest<E>: <A, B>(request: A, direction: MessageDirection) => Effects<E, B>

Type parameters

  • E

Type declaration

ServerChannel

ServerChannel<E>: Channel<E, ServerState>

Type parameters

  • E

ServerState

ServerState: { connectionEvents: Subscription<ConnectionEvent>; connections: ReadonlyArray<Connection>; notificationHandlers: HandlerMap<NotificationHandler<any, any>>; requestHandlers: HandlerMap<RequestHandler<any, any, any>> }

Type declaration

StructuredJson

StructuredJson: JsonObject | JsonArray

Variables

Const isMessage

isMessage: (x: unknown) => x is Message = or(isNotification,or(isRequest, or(isResponse, or(isBatchRequest, isBatchResponse))),)

Type declaration

    • (x: unknown): x is Message
    • Parameters

      • x: unknown

      Returns x is Message

Functions

Const createConnectionEventSubscription

createFailedResponse

createNotification

createRequest

createServer

createSuccessfulResponse

Const createTestConnection

Const createTestServerChannel

getOppositeDirection

getSubscription

isBatchRequest

  • isBatchRequest(x: unknown): x is BatchRequest

isBatchResponse

  • isBatchResponse(x: unknown): x is BatchResponse

Const isFailedResponse

  • isFailedResponse(x: unknown): x is JsonRpcFailedResponse

isNotification

  • isNotification(x: unknown): x is JsonRpcNotification

isRequest

  • isRequest(x: unknown): x is JsonRpcRequest

isResponse

  • isResponse(x: unknown): x is JsonRpcResponse

Const isSuccessfulResponse

  • isSuccessfulResponse(x: unknown): x is JsonRpcSuccessfulResponse

Const sendMessage

  • sendMessage(message: { id: Id; jsonrpc: "2.0"; method: Method; params: Params } | { id: Id; jsonrpc: "2.0"; result: Result } | { error: JsonRpcError<Code, ErrorData>; id: Id; jsonrpc: "2.0" } | { jsonrpc: "2.0"; method: Method; params: Params } | { id: Id; jsonrpc: "2.0"; method: Method; params: Params }[] | ({ id: Id; jsonrpc: "2.0"; result: Result } | { error: JsonRpcError<Code, ErrorData>; id: Id; jsonrpc: "2.0" })[], direction: MessageDirection): Generator<Env<{ connection: Connection }, any>, Disposable, any>
  • Parameters

    • message: { id: Id; jsonrpc: "2.0"; method: Method; params: Params } | { id: Id; jsonrpc: "2.0"; result: Result } | { error: JsonRpcError<Code, ErrorData>; id: Id; jsonrpc: "2.0" } | { jsonrpc: "2.0"; method: Method; params: Params } | { id: Id; jsonrpc: "2.0"; method: Method; params: Params }[] | ({ id: Id; jsonrpc: "2.0"; result: Result } | { error: JsonRpcError<Code, ErrorData>; id: Id; jsonrpc: "2.0" })[]
    • direction: MessageDirection

    Returns Generator<Env<{ connection: Connection }, any>, Disposable, any>

Const sendRequest

Const waitForResponse

Generated using TypeDoc