UNPKG

17.9 kBTypeScriptView Raw
1import { Message, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseMessage, ResponseError, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, _EM, ParameterStructures } from './messages';
2import type { Disposable } from './disposable';
3import { Event } from './events';
4import { CancellationToken, AbstractCancellationTokenSource } from './cancellation';
5import { MessageReader } from './messageReader';
6import { MessageWriter } from './messageWriter';
7export type ProgressToken = number | string;
8export declare namespace ProgressToken {
9 function is(value: any): value is number | string;
10}
11interface ProgressParams<T> {
12 /**
13 * The progress token provided by the client or server.
14 */
15 token: ProgressToken;
16 /**
17 * The progress data.
18 */
19 value: T;
20}
21export declare class ProgressType<PR> {
22 /**
23 * Clients must not use these properties. They are here to ensure correct typing.
24 * in TypeScript
25 */
26 readonly __: [PR, _EM] | undefined;
27 readonly _pr: PR | undefined;
28 constructor();
29}
30export type HandlerResult<R, E> = R | ResponseError<E> | Thenable<R> | Thenable<ResponseError<E>> | Thenable<R | ResponseError<E>>;
31export interface StarRequestHandler {
32 (method: string, params: any[] | object | undefined, token: CancellationToken): HandlerResult<any, any>;
33}
34export interface GenericRequestHandler<R, E> {
35 (...params: any[]): HandlerResult<R, E>;
36}
37export interface RequestHandler0<R, E> {
38 (token: CancellationToken): HandlerResult<R, E>;
39}
40export interface RequestHandler<P, R, E> {
41 (params: P, token: CancellationToken): HandlerResult<R, E>;
42}
43export interface RequestHandler1<P1, R, E> {
44 (p1: P1, token: CancellationToken): HandlerResult<R, E>;
45}
46export interface RequestHandler2<P1, P2, R, E> {
47 (p1: P1, p2: P2, token: CancellationToken): HandlerResult<R, E>;
48}
49export interface RequestHandler3<P1, P2, P3, R, E> {
50 (p1: P1, p2: P2, p3: P3, token: CancellationToken): HandlerResult<R, E>;
51}
52export interface RequestHandler4<P1, P2, P3, P4, R, E> {
53 (p1: P1, p2: P2, p3: P3, p4: P4, token: CancellationToken): HandlerResult<R, E>;
54}
55export interface RequestHandler5<P1, P2, P3, P4, P5, R, E> {
56 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, token: CancellationToken): HandlerResult<R, E>;
57}
58export interface RequestHandler6<P1, P2, P3, P4, P5, P6, R, E> {
59 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, token: CancellationToken): HandlerResult<R, E>;
60}
61export interface RequestHandler7<P1, P2, P3, P4, P5, P6, P7, R, E> {
62 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, token: CancellationToken): HandlerResult<R, E>;
63}
64export interface RequestHandler8<P1, P2, P3, P4, P5, P6, P7, P8, R, E> {
65 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, token: CancellationToken): HandlerResult<R, E>;
66}
67export interface RequestHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E> {
68 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, token: CancellationToken): HandlerResult<R, E>;
69}
70export interface StarNotificationHandler {
71 (method: string, params: any[] | object | undefined): void;
72}
73export interface GenericNotificationHandler {
74 (...params: any[]): void;
75}
76export interface NotificationHandler0 {
77 (): void;
78}
79export interface NotificationHandler<P> {
80 (params: P): void;
81}
82export interface NotificationHandler1<P1> {
83 (p1: P1): void;
84}
85export interface NotificationHandler2<P1, P2> {
86 (p1: P1, p2: P2): void;
87}
88export interface NotificationHandler3<P1, P2, P3> {
89 (p1: P1, p2: P2, p3: P3): void;
90}
91export interface NotificationHandler4<P1, P2, P3, P4> {
92 (p1: P1, p2: P2, p3: P3, p4: P4): void;
93}
94export interface NotificationHandler5<P1, P2, P3, P4, P5> {
95 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): void;
96}
97export interface NotificationHandler6<P1, P2, P3, P4, P5, P6> {
98 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): void;
99}
100export interface NotificationHandler7<P1, P2, P3, P4, P5, P6, P7> {
101 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): void;
102}
103export interface NotificationHandler8<P1, P2, P3, P4, P5, P6, P7, P8> {
104 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): void;
105}
106export interface NotificationHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9> {
107 (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): void;
108}
109export interface Logger {
110 error(message: string): void;
111 warn(message: string): void;
112 info(message: string): void;
113 log(message: string): void;
114}
115export declare const NullLogger: Logger;
116export declare enum Trace {
117 Off = 0,
118 Messages = 1,
119 Compact = 2,
120 Verbose = 3
121}
122export declare namespace TraceValues {
123 /**
124 * Turn tracing off.
125 */
126 const Off: 'off';
127 /**
128 * Trace messages only.
129 */
130 const Messages: 'messages';
131 /**
132 * Compact message tracing.
133 */
134 const Compact: 'compact';
135 /**
136 * Verbose message tracing.
137 */
138 const Verbose: 'verbose';
139}
140export type TraceValues = 'off' | 'messages' | 'compact' | 'verbose';
141export declare namespace Trace {
142 function fromString(value: string): Trace;
143 function toString(value: Trace): TraceValues;
144}
145export declare enum TraceFormat {
146 Text = "text",
147 JSON = "json"
148}
149export declare namespace TraceFormat {
150 function fromString(value: string): TraceFormat;
151}
152export interface TraceOptions {
153 sendNotification?: boolean;
154 traceFormat?: TraceFormat;
155}
156export interface SetTraceParams {
157 value: TraceValues;
158}
159export declare namespace SetTraceNotification {
160 const type: NotificationType<SetTraceParams>;
161}
162export interface LogTraceParams {
163 message: string;
164 verbose?: string;
165}
166export declare namespace LogTraceNotification {
167 const type: NotificationType<LogTraceParams>;
168}
169export interface Tracer {
170 log(dataObject: any): void;
171 log(message: string, data?: string): void;
172}
173export declare enum ConnectionErrors {
174 /**
175 * The connection is closed.
176 */
177 Closed = 1,
178 /**
179 * The connection got disposed.
180 */
181 Disposed = 2,
182 /**
183 * The connection is already in listening mode.
184 */
185 AlreadyListening = 3
186}
187export declare class ConnectionError extends Error {
188 readonly code: ConnectionErrors;
189 constructor(code: ConnectionErrors, message: string);
190}
191export type ConnectionStrategy = {
192 cancelUndispatched?: (message: Message, next: (message: Message) => ResponseMessage | undefined) => ResponseMessage | undefined;
193};
194export declare namespace ConnectionStrategy {
195 function is(value: any): value is ConnectionStrategy;
196}
197export type CancellationId = number | string;
198export interface IdCancellationReceiverStrategy {
199 kind?: 'id';
200 /**
201 * Creates a CancellationTokenSource from a cancellation id.
202 *
203 * @param id The cancellation id.
204 */
205 createCancellationTokenSource(id: CancellationId): AbstractCancellationTokenSource;
206 /**
207 * An optional method to dispose the strategy.
208 */
209 dispose?(): void;
210}
211export declare namespace IdCancellationReceiverStrategy {
212 function is(value: any): value is IdCancellationReceiverStrategy;
213}
214export interface RequestCancellationReceiverStrategy {
215 kind: 'request';
216 /**
217 * Create a cancellation token source from a given request message.
218 *
219 * @param requestMessage The request message.
220 */
221 createCancellationTokenSource(requestMessage: RequestMessage): AbstractCancellationTokenSource;
222 /**
223 * An optional method to dispose the strategy.
224 */
225 dispose?(): void;
226}
227export declare namespace RequestCancellationReceiverStrategy {
228 function is(value: any): value is RequestCancellationReceiverStrategy;
229}
230/**
231 * This will break with the next major version and will become
232 * export type CancellationReceiverStrategy = IdCancellationReceiverStrategy | RequestCancellationReceiverStrategy;
233 */
234export type CancellationReceiverStrategy = IdCancellationReceiverStrategy;
235export declare namespace CancellationReceiverStrategy {
236 const Message: CancellationReceiverStrategy;
237 function is(value: any): value is CancellationReceiverStrategy;
238}
239export interface CancellationSenderStrategy {
240 /**
241 * Hook to enable cancellation for the given request.
242 *
243 * @param request The request to enable cancellation for.
244 */
245 enableCancellation?(request: RequestMessage): void;
246 /**
247 * Send cancellation for the given cancellation id
248 *
249 * @param conn The connection used.
250 * @param id The cancellation id.
251 */
252 sendCancellation(conn: MessageConnection, id: CancellationId): Promise<void>;
253 /**
254 * Cleanup any cancellation state for the given cancellation id. After this
255 * method has been call no cancellation will be sent anymore for the given id.
256 *
257 * @param id The cancellation id.
258 */
259 cleanup(id: CancellationId): void;
260 /**
261 * An optional method to dispose the strategy.
262 */
263 dispose?(): void;
264}
265export declare namespace CancellationSenderStrategy {
266 const Message: CancellationSenderStrategy;
267 function is(value: any): value is CancellationSenderStrategy;
268}
269export interface CancellationStrategy {
270 receiver: CancellationReceiverStrategy | RequestCancellationReceiverStrategy;
271 sender: CancellationSenderStrategy;
272}
273export declare namespace CancellationStrategy {
274 const Message: CancellationStrategy;
275 function is(value: any): value is CancellationStrategy;
276}
277export interface MessageStrategy {
278 handleMessage(message: Message, next: (message: Message) => void): void;
279}
280export declare namespace MessageStrategy {
281 function is(value: any): value is MessageStrategy;
282}
283export interface ConnectionOptions {
284 cancellationStrategy?: CancellationStrategy;
285 connectionStrategy?: ConnectionStrategy;
286 messageStrategy?: MessageStrategy;
287}
288export declare namespace ConnectionOptions {
289 function is(value: any): value is ConnectionOptions;
290}
291export interface MessageConnection {
292 sendRequest<R, E>(type: RequestType0<R, E>, token?: CancellationToken): Promise<R>;
293 sendRequest<P, R, E>(type: RequestType<P, R, E>, params: P, token?: CancellationToken): Promise<R>;
294 sendRequest<P1, R, E>(type: RequestType1<P1, R, E>, p1: P1, token?: CancellationToken): Promise<R>;
295 sendRequest<P1, P2, R, E>(type: RequestType2<P1, P2, R, E>, p1: P1, p2: P2, token?: CancellationToken): Promise<R>;
296 sendRequest<P1, P2, P3, R, E>(type: RequestType3<P1, P2, P3, R, E>, p1: P1, p2: P2, p3: P3, token?: CancellationToken): Promise<R>;
297 sendRequest<P1, P2, P3, P4, R, E>(type: RequestType4<P1, P2, P3, P4, R, E>, p1: P1, p2: P2, p3: P3, p4: P4, token?: CancellationToken): Promise<R>;
298 sendRequest<P1, P2, P3, P4, P5, R, E>(type: RequestType5<P1, P2, P3, P4, P5, R, E>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, token?: CancellationToken): Promise<R>;
299 sendRequest<P1, P2, P3, P4, P5, P6, R, E>(type: RequestType6<P1, P2, P3, P4, P5, P6, R, E>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, token?: CancellationToken): Promise<R>;
300 sendRequest<P1, P2, P3, P4, P5, P6, P7, R, E>(type: RequestType7<P1, P2, P3, P4, P5, P6, P7, R, E>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, token?: CancellationToken): Promise<R>;
301 sendRequest<P1, P2, P3, P4, P5, P6, P7, P8, R, E>(type: RequestType8<P1, P2, P3, P4, P5, P6, P7, P8, R, E>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, token?: CancellationToken): Promise<R>;
302 sendRequest<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>(type: RequestType9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, token?: CancellationToken): Promise<R>;
303 sendRequest<R>(method: string, r0?: ParameterStructures | any, ...rest: any[]): Promise<R>;
304 onRequest<R, E>(type: RequestType0<R, E>, handler: RequestHandler0<R, E>): Disposable;
305 onRequest<P, R, E>(type: RequestType<P, R, E>, handler: RequestHandler<P, R, E>): Disposable;
306 onRequest<P1, R, E>(type: RequestType1<P1, R, E>, handler: RequestHandler1<P1, R, E>): Disposable;
307 onRequest<P1, P2, R, E>(type: RequestType2<P1, P2, R, E>, handler: RequestHandler2<P1, P2, R, E>): Disposable;
308 onRequest<P1, P2, P3, R, E>(type: RequestType3<P1, P2, P3, R, E>, handler: RequestHandler3<P1, P2, P3, R, E>): Disposable;
309 onRequest<P1, P2, P3, P4, R, E>(type: RequestType4<P1, P2, P3, P4, R, E>, handler: RequestHandler4<P1, P2, P3, P4, R, E>): Disposable;
310 onRequest<P1, P2, P3, P4, P5, R, E>(type: RequestType5<P1, P2, P3, P4, P5, R, E>, handler: RequestHandler5<P1, P2, P3, P4, P5, R, E>): Disposable;
311 onRequest<P1, P2, P3, P4, P5, P6, R, E>(type: RequestType6<P1, P2, P3, P4, P5, P6, R, E>, handler: RequestHandler6<P1, P2, P3, P4, P5, P6, R, E>): Disposable;
312 onRequest<P1, P2, P3, P4, P5, P6, P7, R, E>(type: RequestType7<P1, P2, P3, P4, P5, P6, P7, R, E>, handler: RequestHandler7<P1, P2, P3, P4, P5, P6, P7, R, E>): Disposable;
313 onRequest<P1, P2, P3, P4, P5, P6, P7, P8, R, E>(type: RequestType8<P1, P2, P3, P4, P5, P6, P7, P8, R, E>, handler: RequestHandler8<P1, P2, P3, P4, P5, P6, P7, P8, R, E>): Disposable;
314 onRequest<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>(type: RequestType9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>, handler: RequestHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9, R, E>): Disposable;
315 onRequest<R, E>(method: string, handler: GenericRequestHandler<R, E>): Disposable;
316 onRequest(handler: StarRequestHandler): Disposable;
317 hasPendingResponse(): boolean;
318 sendNotification(type: NotificationType0): Promise<void>;
319 sendNotification<P>(type: NotificationType<P>, params?: P): Promise<void>;
320 sendNotification<P1>(type: NotificationType1<P1>, p1: P1): Promise<void>;
321 sendNotification<P1, P2>(type: NotificationType2<P1, P2>, p1: P1, p2: P2): Promise<void>;
322 sendNotification<P1, P2, P3>(type: NotificationType3<P1, P2, P3>, p1: P1, p2: P2, p3: P3): Promise<void>;
323 sendNotification<P1, P2, P3, P4>(type: NotificationType4<P1, P2, P3, P4>, p1: P1, p2: P2, p3: P3, p4: P4): Promise<void>;
324 sendNotification<P1, P2, P3, P4, P5>(type: NotificationType5<P1, P2, P3, P4, P5>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): Promise<void>;
325 sendNotification<P1, P2, P3, P4, P5, P6>(type: NotificationType6<P1, P2, P3, P4, P5, P6>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): Promise<void>;
326 sendNotification<P1, P2, P3, P4, P5, P6, P7>(type: NotificationType7<P1, P2, P3, P4, P5, P6, P7>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): Promise<void>;
327 sendNotification<P1, P2, P3, P4, P5, P6, P7, P8>(type: NotificationType8<P1, P2, P3, P4, P5, P6, P7, P8>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): Promise<void>;
328 sendNotification<P1, P2, P3, P4, P5, P6, P7, P8, P9>(type: NotificationType9<P1, P2, P3, P4, P5, P6, P7, P8, P9>, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): Promise<void>;
329 sendNotification(method: string, r0?: ParameterStructures | any, ...rest: any[]): Promise<void>;
330 onNotification(type: NotificationType0, handler: NotificationHandler0): Disposable;
331 onNotification<P>(type: NotificationType<P>, handler: NotificationHandler<P>): Disposable;
332 onNotification<P1>(type: NotificationType1<P1>, handler: NotificationHandler1<P1>): Disposable;
333 onNotification<P1, P2>(type: NotificationType2<P1, P2>, handler: NotificationHandler2<P1, P2>): Disposable;
334 onNotification<P1, P2, P3>(type: NotificationType3<P1, P2, P3>, handler: NotificationHandler3<P1, P2, P3>): Disposable;
335 onNotification<P1, P2, P3, P4>(type: NotificationType4<P1, P2, P3, P4>, handler: NotificationHandler4<P1, P2, P3, P4>): Disposable;
336 onNotification<P1, P2, P3, P4, P5>(type: NotificationType5<P1, P2, P3, P4, P5>, handler: NotificationHandler5<P1, P2, P3, P4, P5>): Disposable;
337 onNotification<P1, P2, P3, P4, P5, P6>(type: NotificationType6<P1, P2, P3, P4, P5, P6>, handler: NotificationHandler6<P1, P2, P3, P4, P5, P6>): Disposable;
338 onNotification<P1, P2, P3, P4, P5, P6, P7>(type: NotificationType7<P1, P2, P3, P4, P5, P6, P7>, handler: NotificationHandler7<P1, P2, P3, P4, P5, P6, P7>): Disposable;
339 onNotification<P1, P2, P3, P4, P5, P6, P7, P8>(type: NotificationType8<P1, P2, P3, P4, P5, P6, P7, P8>, handler: NotificationHandler8<P1, P2, P3, P4, P5, P6, P7, P8>): Disposable;
340 onNotification<P1, P2, P3, P4, P5, P6, P7, P8, P9>(type: NotificationType9<P1, P2, P3, P4, P5, P6, P7, P8, P9>, handler: NotificationHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9>): Disposable;
341 onNotification(method: string, handler: GenericNotificationHandler): Disposable;
342 onNotification(handler: StarNotificationHandler): Disposable;
343 onUnhandledNotification: Event<NotificationMessage>;
344 onProgress<P>(type: ProgressType<P>, token: string | number, handler: NotificationHandler<P>): Disposable;
345 sendProgress<P>(type: ProgressType<P>, token: string | number, value: P): Promise<void>;
346 onUnhandledProgress: Event<ProgressParams<any>>;
347 trace(value: Trace, tracer: Tracer, sendNotification?: boolean): Promise<void>;
348 trace(value: Trace, tracer: Tracer, traceOptions?: TraceOptions): Promise<void>;
349 onError: Event<[Error, Message | undefined, number | undefined]>;
350 onClose: Event<void>;
351 listen(): void;
352 end(): void;
353 onDispose: Event<void>;
354 dispose(): void;
355 inspect(): void;
356}
357export declare function createMessageConnection(messageReader: MessageReader, messageWriter: MessageWriter, _logger?: Logger, options?: ConnectionOptions): MessageConnection;
358export {};