JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 366
  • Score
    100M100P100Q97976F
  • License Apache-2.0

RPC message types and utilities for JSON RPC APIs

Package Exports

  • @jsonjoy.com/rpc-messages
  • @jsonjoy.com/rpc-messages/lib/index.js
  • @jsonjoy.com/rpc-messages/lib/validation
  • @jsonjoy.com/rpc-messages/lib/validation.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jsonjoy.com/rpc-messages) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@jsonjoy.com/rpc-messages

Message types for the JSON Reactive RPC protocol. JSON Rx is a lightweight bi-directional RPC protocol with reactive (Observable) request and response payloads. It supports notifications, request/response, and full bidirectional streaming over any message-passing transport (WebSocket, HTTP, IPC, etc.).

Usage

import {
  NotificationMessage,
  RequestDataMessage,
  RequestCompleteMessage,
  RequestErrorMessage,
  RequestUnsubscribeMessage,
  ResponseDataMessage,
  ResponseCompleteMessage,
  ResponseErrorMessage,
  ResponseUnsubscribeMessage,
} from '@jsonjoy.com/rpc-messages';

Messages

JSON Rx defines nine message types split between client-sent and server-sent messages.

Client to Server

Class Description
NotificationMessage Fire-and-forget notification; no response expected.
RequestDataMessage Initiates a subscription or emits a value into an existing one.
RequestCompleteMessage Starts and immediately completes a subscription (unary request).
RequestErrorMessage Starts and immediately completes a subscription with an error.
ResponseUnsubscribeMessage Client cancels an active response subscription.

Server to Client

Class Description
NotificationMessage Fire-and-forget notification from server.
ResponseDataMessage Emits a value in a response subscription.
ResponseCompleteMessage Completes a response subscription (with an optional final value).
ResponseErrorMessage Completes a response subscription with an error.
RequestUnsubscribeMessage Server asks client to stop a request subscription.

Communication patterns

  • Notification — client sends one NotificationMessage; server sends nothing back.
  • Request/response — client sends RequestCompleteMessage; server sends ResponseCompleteMessage. Both sides emit exactly one value.
  • Server-streaming — client sends RequestCompleteMessage; server sends zero or more ResponseDataMessages followed by ResponseCompleteMessage.
  • Client-streaming — client sends one or more RequestDataMessages followed by RequestCompleteMessage; server sends ResponseCompleteMessage.
  • Bidirectional streaming — client streams RequestDataMessages; server streams ResponseDataMessages.

Validation

Every message class exposes a validate() method that throws an RpcError (BAD_REQUEST) if the message fields are invalid (e.g. id out of range, method name contains illegal characters).