-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
84 lines (73 loc) · 2.09 KB
/
index.d.ts
File metadata and controls
84 lines (73 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* TypeScript type definitions for jrpc
*/
export interface ClientOptions {
transport: 'http' | 'https' | 'socket' | 'tcp' | 'http2';
host?: string;
port?: number;
path?: string;
timeout?: number;
protocol?: 'http' | 'https';
}
export interface ServerOptions {
transport: 'http' | 'https' | 'socket' | 'tcp' | 'http2';
port: number;
host?: string;
path?: string;
}
export interface BatchRequest {
method: string;
params?: any[] | object;
id?: string | number;
}
export interface CallOptions {
timeout?: number;
}
export class Client {
constructor(options: ClientOptions);
call(method: string, params?: any[] | object, options?: CallOptions): Promise<any>;
notify(method: string, params?: any[] | object): Promise<void>;
batch(requests: BatchRequest[]): Promise<any[]>;
close(): Promise<void>;
}
export class Server {
constructor(options: ServerOptions);
register(name: string, handler: (...args: any[]) => any | Promise<any>): void;
unregister(name: string): void;
listen(): Promise<void>;
close(): Promise<void>;
}
export class RpcError extends Error {
code: number;
data?: any;
constructor(code: number, message?: string, data?: any);
toJSON(): object;
}
export const ErrorCodes: {
PARSE_ERROR: -32700;
INVALID_REQUEST: -32600;
METHOD_NOT_FOUND: -32601;
INVALID_PARAMS: -32602;
INTERNAL_ERROR: -32603;
SERVER_ERROR: -32000;
TIMEOUT_ERROR: -32001;
CONNECTION_ERROR: -32002;
SERVICE_UNAVAILABLE: -32003;
};
export const ErrorMessages: {
[code: number]: string;
};
export class Codec {
encodeRequest(method: string, params?: any[] | object, id?: string | number | null): object;
encodeResponse(result: any, id: string | number): object;
encodeError(code: number, message: string, id: string | number, data?: any): object;
decode(json: string): object;
encode(obj: object): string;
generateId(): number;
encodeBatch(requests: BatchRequest[]): object[];
}
export class Validator {
static validateRequest(request: object): boolean;
static validateResponse(response: object): boolean;
static isNotification(request: object): boolean;
}