Skip to content

API reference / @jsprismarine/management-protocol / jsonRpc

jsonRpc ​

Interfaces ​

RpcError ​

Defined in: jsonRpc.ts:24

The error member of a response.

Properties ​

code ​

readonly code: number

Defined in: jsonRpc.ts:25

data? ​

readonly optional data?: string

Defined in: jsonRpc.ts:27

message ​

readonly message: string

Defined in: jsonRpc.ts:26


RpcMethod ​

Defined in: jsonRpc.ts:58

A method the dispatcher can call.

Properties ​

beforeStart? ​

readonly optional beforeStart?: boolean

Defined in: jsonRpc.ts:62

Whether a client may call it before the server has started, as only rpc.discover may.

call ​

readonly call: (params) => unknown

Defined in: jsonRpc.ts:70

Runs the method.

Parameters ​
params ​

Readonly<Record<string, unknown>>

The parameter by name, checked against its schema, or nothing.

Returns ​

unknown

The result, sent as the response's result.

Throws ​

When the parameter is well-formed but names something the method cannot act on. Any other error becomes an internal error.

param? ​

readonly optional param?: RpcParam

Defined in: jsonRpc.ts:60

The parameter, when the method takes one. No method of the protocol takes more.


RpcNotification ​

Defined in: jsonRpc.ts:36

A notification the server sends: a method name and its parameters, and no id.

Properties ​

jsonrpc ​

readonly jsonrpc: "2.0"

Defined in: jsonRpc.ts:37

method ​

readonly method: string

Defined in: jsonRpc.ts:38

params? ​

readonly optional params?: readonly unknown[]

Defined in: jsonRpc.ts:39


RpcParam ​

Defined in: jsonRpc.ts:52

One parameter a method declares, as Mojang's document lists it.

Properties ​

name ​

readonly name: string

Defined in: jsonRpc.ts:53

schema ​

readonly schema: unknown

Defined in: jsonRpc.ts:54


RpcTable ​

Defined in: jsonRpc.ts:74

The methods one connection can call, by name, and the components their schemas refer to.

Properties ​

components ​

readonly components: Components

Defined in: jsonRpc.ts:76

methods ​

readonly methods: ReadonlyMap<string, RpcMethod>

Defined in: jsonRpc.ts:75

onInternalError? ​

readonly optional onInternalError?: (method, error) => void

Defined in: jsonRpc.ts:80

Told about an error a method threw that is not an InvalidParams, which the client sees no detail of.

Parameters ​
method ​

string

error ​

unknown

Returns ​

void

started ​

readonly started: () => boolean

Defined in: jsonRpc.ts:78

Whether the server has started; before it has, only beforeStart methods are dispatched.

Returns ​

boolean

Type Aliases ​

FrameAnswer ​

FrameAnswer = { kind: "reply"; text: string; } | { kind: "none"; } | { kind: "close"; }

Defined in: jsonRpc.ts:179

What a frame needs in reply.

Union Members ​

Type Literal ​

{ kind: "reply"; text: string; }

A frame to send back.


Type Literal ​

{ kind: "none"; }

Nothing: the frame was a notification, or a stray response.


Type Literal ​

{ kind: "close"; }

A batch held something that is not a request, which Java answers by closing the connection.


RpcId ​

RpcId = string | number | null

Defined in: jsonRpc.ts:21

A request id: what the client sent, echoed back on the response.


RpcResponse ​

RpcResponse = { id: RpcId; jsonrpc: "2.0"; result: unknown; } | { error: RpcError; id: RpcId; jsonrpc: "2.0"; }

Defined in: jsonRpc.ts:31

A response: a result or an error, for the request with the same id.

Variables ​

RPC_ERRORS ​

const RPC_ERRORS: object

Defined in: jsonRpc.ts:43

The five errors JSON-RPC 2.0 defines, by the name its specification gives them.

Type Declaration ​

internalError ​

readonly internalError: object

internalError.code ​

readonly code: -32603 = -32603

internalError.message ​

readonly message: "Internal error" = 'Internal error'

invalidParams ​

readonly invalidParams: object

invalidParams.code ​

readonly code: -32602 = -32602

invalidParams.message ​

readonly message: "Invalid params" = 'Invalid params'

invalidRequest ​

readonly invalidRequest: object

invalidRequest.code ​

readonly code: -32600 = -32600

invalidRequest.message ​

readonly message: "Invalid Request" = 'Invalid Request'

methodNotFound ​

readonly methodNotFound: object

methodNotFound.code ​

readonly code: -32601 = -32601

methodNotFound.message ​

readonly message: "Method not found" = 'Method not found'

parseError ​

readonly parseError: object

parseError.code ​

readonly code: -32700 = -32700

parseError.message ​

readonly message: "Parse error" = 'Parse error'

Functions ​

answerFrame() ​

answerFrame(text, table): Promise<FrameAnswer>

Defined in: jsonRpc.ts:194

Answers one frame: a request, a notification, or a batch of them.

Parameters ​

text ​

string

The frame, as the client sent it.

table ​

RpcTable

The methods the connection can call.

Returns ​

Promise<FrameAnswer>

What to send back, if anything.


notificationFrame() ​

notificationFrame(method, param?): string

Defined in: jsonRpc.ts:218

A notification frame. MSMP sends a notification's parameter as an array of one value, and no params at all for a notification that has none.

Parameters ​

method ​

string

param? ​

unknown

Returns ​

string