forked from tedeh/jayson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
205 lines (153 loc) · 5.81 KB
/
index.d.ts
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import net = require('net');
import tls = require('tls');
import https = require('https');
import http = require('http');
import events = require('events');
export as namespace jayson;
interface Utils {
}
declare type RequestParamsLike = Array<any> | object;
interface JSONRPCError {
code: number;
message: string;
data?: object;
}
declare type JSONRPCErrorLike = Error | JSONRPCError;
interface JSONRPCVersionOneRequest {
method: string;
params: Array<any>;
id: JSONRPCIDLike;
}
interface JSONRPCVersionTwoRequest {
jsonrpc: number;
method: string;
params: RequestParamsLike;
id?: JSONRPCIDLike | null;
}
declare type JSONRPCIDLike = number | string;
declare type JSONRPCRequest = JSONRPCVersionOneRequest | JSONRPCVersionTwoRequest;
declare type JSONRPCRequestLike = JSONRPCRequest | string;
declare type JSONRPCResultLike = any;
interface JSONRPCCallbackTypePlain {
(err: JSONRPCErrorLike, result?: JSONRPCResultLike): void
}
interface JSONRPCCallbackTypeSugared {
(err: Error, error?: JSONRPCErrorLike, result?: JSONRPCResultLike): void
}
type JSONRPCCallbackType = JSONRPCCallbackTypePlain | JSONRPCCallbackTypeSugared;
interface JSONRPCCallbackTypeBatchPlain {
(err: JSONRPCErrorLike, results?: Array<JSONRPCResultLike>): void
}
interface JSONRPCCallbackTypeBatchSugared {
(err: Error, errors?: Array<JSONRPCErrorLike>, results?: Array<JSONRPCResultLike>): void
}
type JSONRPCCallbackTypeBatch = JSONRPCCallbackTypeBatchPlain | JSONRPCCallbackTypeBatchSugared;
interface MethodHandlerType {
(args: RequestParamsLike, callback: JSONRPCCallbackType): void;
(...args: any[]): void; // callback still expected to be last
}
declare type MethodOptionsParamsLike = Array<any> | Object | object;
interface MethodOptions {
handler?: MethodHandlerType;
collect?: boolean;
params?: MethodOptionsParamsLike;
}
declare class Method {
constructor(handler?: MethodHandlerType, options?: MethodOptions);
constructor(options: MethodOptions);
getHandler(): MethodHandlerType;
setHandler(handler: MethodHandlerType): void;
execute(server: Server, requestParams: RequestParamsLike, callback: JSONRPCCallbackType): any | Promise<any>;
}
declare type MethodLike = Function | Method | Client
declare type ServerRouterFunction = (method: string, params: RequestParamsLike) => MethodLike;
interface ServerOptions {
collect?: boolean;
params?: MethodOptionsParamsLike;
version?: number;
reviver?: JSONParseReviver;
replacer?: JSONStringifyReplacer;
encoding?: string;
router?: ServerRouterFunction;
methodConstructor?: Function;
}
declare class Server {
constructor(methods?: {[methodName: string]: MethodLike}, options?: object);
static errors: {[errorName: string]: number};
static errorMessages: {[errorMessage: string]: string};
static interfaces: {[interfaces: string]: Function};
http(options?: HttpServerOptions): HttpServer;
https(options?: HttpsServerOptions): HttpsServer;
tcp(options?: TcpServerOptions): TcpServer;
tls(options?: TlsServerOptions): TlsServer;
middleware(options?: MiddlewareServerOptions): Function;
method(name: string, definition: MethodLike): void;
methods(methods: {[methodName: string]: MethodLike}): void;
hasMethod(name: string): boolean;
removeMethod(name: string): void;
getMethod(name: string): MethodLike;
error(code?: number, message?: string, data?: object): JSONRPCError;
call(request: JSONRPCRequestLike | Array<JSONRPCRequestLike>, originalCallback?: JSONRPCCallbackType): void;
}
interface MiddlewareServerOptions extends ServerOptions {
}
interface HttpServerOptions extends ServerOptions {
}
declare class HttpServer extends http.Server {
constructor(server: Server, options?: HttpServerOptions);
}
interface HttpsServerOptions extends ServerOptions, https.ServerOptions {
}
declare class HttpsServer extends https.Server {
constructor(server: Server, options?: HttpsServerOptions);
}
interface TcpServerOptions extends ServerOptions {
}
declare class TcpServer extends net.Server {
constructor(server: Server, options?: TcpServerOptions);
}
interface TlsServerOptions extends tls.TlsOptions {
}
declare class TlsServer extends tls.Server {
constructor(server: Server, options?: TlsServerOptions);
}
declare type JSONParseReviver = (key: string, value: any) => any;
declare type JSONStringifyReplacer = (key: string, value: any) => any;
declare type IDGenerator = () => string;
interface ClientOptions {
version?: number;
reviver?: JSONParseReviver;
replacer?: JSONStringifyReplacer;
generator?: IDGenerator;
}
interface HttpClientOptions extends ClientOptions, http.RequestOptions {
}
declare class HttpClient extends Client {
constructor(options?: HttpClientOptions);
}
interface TlsClientOptions extends ClientOptions, tls.ConnectionOptions {
}
declare class TlsClient extends Client {
constructor(options?: TlsClientOptions);
}
interface TcpClientOptions extends ClientOptions, net.TcpSocketConnectOpts {
}
declare class TcpClient extends Client {
constructor(options?: TcpClientOptions);
}
interface HttpsClientOptions extends ClientOptions, https.RequestOptions {
}
declare class HttpsClient extends Client {
constructor(options?: HttpsClientOptions);
}
declare class Client extends events.EventEmitter {
constructor(server: Server, options?: ClientOptions);
constructor(options: ClientOptions);
static http(options?: HttpClientOptions): HttpClient;
static https(options?: HttpsClientOptions): HttpsClient;
static tcp(options?: TcpClientOptions): TcpClient;
static tls(options?: TlsClientOptions): TlsClient;
request(method: string, params: RequestParamsLike, id?: string, callback?: JSONRPCCallbackType): JSONRPCRequest;
request(method: string, params: RequestParamsLike, callback?: JSONRPCCallbackType): JSONRPCRequest;
request(method: Array<JSONRPCRequestLike>, callback?: JSONRPCCallbackTypeBatch): Array<JSONRPCRequest>;
}