Class default

JSON-RPC server implementation.

Hierarchy

  • default

Constructors

Properties

methods: JRPC_METHOD[] = []

Methods

  • Adds a method to the server.

    Throws

    If the handler parameter is not a function.

    Throws

    If a method with the same name already exists.

    Throws

    If the method name starts with "rpc.", which is reserved.

    Parameters

    • schema: JRPC_SCHEMA_METHOD

      The schema of the method.

    • handler: Function

      The handler function for the method.

    Returns void

  • Private

    Creates a JSON-RPC error response object.

    Returns

    A JSON-RPC error response object.

    Parameters

    • request: null | JRPC_REQUEST

      The JSON-RPC request object (optional).

    • code: string

      The error code.

    • message: string

      The error message.

    • Optional data: object

      Additional error data (optional).

    Returns JRPC_RESPONSE

  • Private

    Creates a JSON-RPC response object.

    Returns

    A JSON-RPC response object.

    Parameters

    • request: JRPC_REQUEST

      The JSON-RPC request object.

    • result: object | unknown[]

      The result of the request.

    Returns JRPC_RESPONSE

  • Executes a JSON-RPC request string and returns the corresponding response object(s).

    Returns

    A promise that resolves with the corresponding JSON-RPC response object(s) (if any).

    Throws

    If an error occurs while executing the request.

    Parameters

    • request: string

      The JSON-RPC request string.

    Returns Promise<void | JRPC_RESPONSE | JRPC_RESPONSE[]>

  • Private

    Finds a method with a given name.

    Returns

    The method with the given name or null if it doesn't exist.

    Parameters

    • name: string

      The name of the method.

    Returns null | JRPC_METHOD

  • Private

    Handles a single JSON-RPC request object

    Returns

    A promise that resolves to the corresponding JSON-RPC response object, or void if the request is a notification.

    Throws

    If the handler function throws a custom error.

    Throws

    If the request is invalid or there's an error while processing the request.

    Parameters

    • request: JRPC_REQUEST

      The JSON-RPC request object to handle.

    Returns Promise<void | JRPC_RESPONSE>

  • Private

    Checks if a method with a given name exists.

    Returns

    true if a method with the given name exists, false otherwise.

    Parameters

    • name: string

      The name of the method.

    Returns boolean

  • Private

    Parses a JSON-RPC request string and returns the corresponding request object(s).

    Returns

    The corresponding JSON-RPC request object(s).

    Throws

    If the request string cannot be parsed.

    Parameters

    • request: string

      The JSON-RPC request string.

    Returns JRPC_REQUEST | JRPC_REQUEST[]

  • Private

    Validates a JSON-RPC request object against its corresponding method schema.

    Returns

    true if the request is valid, false otherwise.

    Throws

    If the request is invalid.

    Parameters

    • request: JRPC_REQUEST

      The JSON-RPC request object to validate.

    Returns boolean

Generated using TypeDoc