Skip to content

Commit

Permalink
Document interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
derbenoo committed Jan 6, 2019
1 parent d0815c2 commit f389474
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/** Interface for options that can be passed during server initialization */
export interface IServerOptions {
/** Server host */
host?: string;
Expand All @@ -16,6 +16,7 @@ export interface IServerOptions {
logger?: ILogger;
}

/** Interface for a logger object used to print log messages */
export interface ILogger {
/** Logging function for info messages (default: console.log) */
info?: Function;
Expand All @@ -25,22 +26,42 @@ export interface ILogger {
err?: Function;
}

/** Interface for modules that are exposed via an RPC endpoint */
export interface IRpcModule {
/** Only the module's functions are relevant for RPC calls */
[x: string]: Function;
}

/** Interface for JSON-RPC 2.0 requests (https://www.jsonrpc.org/specification#request_object) */
export interface IRpcRequest {
/** A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0". */
jsonrpc: string;
id: number;
/** An identifier established by the client. If it is not included, it is assumed to be a notification. */
id: string | number | null;
/** A String containing the name of the method to be invoked. */
method: string;
params: undefined|Array<any>;
/** A structured value that holds the parameter values to be used during the invocation of the method. */
params: undefined | Array<any>;
}

/** Interface for JSON-RPC 2.0 responses (https://www.jsonrpc.org/specification#response_object) */
export interface IRpcResponse {
/** A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0". */
jsonrpc: string;
id: number;
/** Identifier whose value corresponds to the one given in the RPC request. */
id: string | number | null;
/** Result of the RPC call on successful execution. */
result?: Array<any>|Object;
/** Error that occurred during the execuetion of the RPC call. */
error?: IRpcError;
}

/** Interface for JSON-RPC 2.0 errors (https://www.jsonrpc.org/specification#error_object) */
export interface IRpcError {
/** A Number that indicates the error type that occurred. See RFC for possible values */
code: number;
/** A String providing a short description of the error. */
message: string;
data: any;
/** A Primitive or Structured value that contains additional information about the error. */
data?: any;
}

0 comments on commit f389474

Please sign in to comment.