@cmdless/ui-runtime 0.0.0 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -34
- package/out/main/bin.js +57 -0
- package/out/main/index.js +3369 -0
- package/out/preload/index.mjs +6 -0
- package/package.json +37 -7
|
@@ -0,0 +1,3369 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { app, BrowserWindow, dialog, shell } from "electron";
|
|
4
|
+
import { electronApp, optimizer } from "@electron-toolkit/utils";
|
|
5
|
+
import { Command, Argument } from "commander";
|
|
6
|
+
import { types, cmdlessIPC, createElectronIPC } from "@cmdless/ui-sdk";
|
|
7
|
+
import { BinChannel, CmdlessEnv, getEphemeralPrefix, MessageSocketWaiter, CmdlessUI, binOutput, runAsMcp } from "@cmdless/ui-sdk/node";
|
|
8
|
+
import __cjs_mod__ from "node:module";
|
|
9
|
+
const __filename = import.meta.filename;
|
|
10
|
+
const __dirname = import.meta.dirname;
|
|
11
|
+
const require2 = __cjs_mod__.createRequire(import.meta.url);
|
|
12
|
+
var api = {};
|
|
13
|
+
var messages = {};
|
|
14
|
+
var is = {};
|
|
15
|
+
var hasRequiredIs;
|
|
16
|
+
function requireIs() {
|
|
17
|
+
if (hasRequiredIs) return is;
|
|
18
|
+
hasRequiredIs = 1;
|
|
19
|
+
Object.defineProperty(is, "__esModule", { value: true });
|
|
20
|
+
is.boolean = boolean;
|
|
21
|
+
is.string = string;
|
|
22
|
+
is.number = number;
|
|
23
|
+
is.error = error;
|
|
24
|
+
is.func = func;
|
|
25
|
+
is.array = array;
|
|
26
|
+
is.stringArray = stringArray;
|
|
27
|
+
function boolean(value) {
|
|
28
|
+
return value === true || value === false;
|
|
29
|
+
}
|
|
30
|
+
function string(value) {
|
|
31
|
+
return typeof value === "string" || value instanceof String;
|
|
32
|
+
}
|
|
33
|
+
function number(value) {
|
|
34
|
+
return typeof value === "number" || value instanceof Number;
|
|
35
|
+
}
|
|
36
|
+
function error(value) {
|
|
37
|
+
return value instanceof Error;
|
|
38
|
+
}
|
|
39
|
+
function func(value) {
|
|
40
|
+
return typeof value === "function";
|
|
41
|
+
}
|
|
42
|
+
function array(value) {
|
|
43
|
+
return Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
function stringArray(value) {
|
|
46
|
+
return array(value) && value.every((elem) => string(elem));
|
|
47
|
+
}
|
|
48
|
+
return is;
|
|
49
|
+
}
|
|
50
|
+
var hasRequiredMessages;
|
|
51
|
+
function requireMessages() {
|
|
52
|
+
if (hasRequiredMessages) return messages;
|
|
53
|
+
hasRequiredMessages = 1;
|
|
54
|
+
var __createBinding = messages && messages.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
55
|
+
if (k2 === void 0) k2 = k;
|
|
56
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
57
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
58
|
+
desc = { enumerable: true, get: function() {
|
|
59
|
+
return m[k];
|
|
60
|
+
} };
|
|
61
|
+
}
|
|
62
|
+
Object.defineProperty(o, k2, desc);
|
|
63
|
+
}) : (function(o, m, k, k2) {
|
|
64
|
+
if (k2 === void 0) k2 = k;
|
|
65
|
+
o[k2] = m[k];
|
|
66
|
+
}));
|
|
67
|
+
var __setModuleDefault = messages && messages.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
68
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
69
|
+
}) : function(o, v) {
|
|
70
|
+
o["default"] = v;
|
|
71
|
+
});
|
|
72
|
+
var __importStar = messages && messages.__importStar || /* @__PURE__ */ (function() {
|
|
73
|
+
var ownKeys = function(o) {
|
|
74
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
75
|
+
var ar = [];
|
|
76
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
77
|
+
return ar;
|
|
78
|
+
};
|
|
79
|
+
return ownKeys(o);
|
|
80
|
+
};
|
|
81
|
+
return function(mod) {
|
|
82
|
+
if (mod && mod.__esModule) return mod;
|
|
83
|
+
var result = {};
|
|
84
|
+
if (mod != null) {
|
|
85
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
86
|
+
}
|
|
87
|
+
__setModuleDefault(result, mod);
|
|
88
|
+
return result;
|
|
89
|
+
};
|
|
90
|
+
})();
|
|
91
|
+
Object.defineProperty(messages, "__esModule", { value: true });
|
|
92
|
+
messages.Message = messages.NotificationType9 = messages.NotificationType8 = messages.NotificationType7 = messages.NotificationType6 = messages.NotificationType5 = messages.NotificationType4 = messages.NotificationType3 = messages.NotificationType2 = messages.NotificationType1 = messages.NotificationType0 = messages.NotificationType = messages.RequestType9 = messages.RequestType8 = messages.RequestType7 = messages.RequestType6 = messages.RequestType5 = messages.RequestType4 = messages.RequestType3 = messages.RequestType2 = messages.RequestType1 = messages.RequestType = messages.RequestType0 = messages.AbstractMessageSignature = messages.ParameterStructures = messages.ResponseError = messages.ErrorCodes = void 0;
|
|
93
|
+
const is2 = __importStar(requireIs());
|
|
94
|
+
var ErrorCodes;
|
|
95
|
+
(function(ErrorCodes2) {
|
|
96
|
+
ErrorCodes2.ParseError = -32700;
|
|
97
|
+
ErrorCodes2.InvalidRequest = -32600;
|
|
98
|
+
ErrorCodes2.MethodNotFound = -32601;
|
|
99
|
+
ErrorCodes2.InvalidParams = -32602;
|
|
100
|
+
ErrorCodes2.InternalError = -32603;
|
|
101
|
+
ErrorCodes2.jsonrpcReservedErrorRangeStart = -32099;
|
|
102
|
+
ErrorCodes2.serverErrorStart = -32099;
|
|
103
|
+
ErrorCodes2.MessageWriteError = -32099;
|
|
104
|
+
ErrorCodes2.MessageReadError = -32098;
|
|
105
|
+
ErrorCodes2.PendingResponseRejected = -32097;
|
|
106
|
+
ErrorCodes2.ConnectionInactive = -32096;
|
|
107
|
+
ErrorCodes2.ServerNotInitialized = -32002;
|
|
108
|
+
ErrorCodes2.UnknownErrorCode = -32001;
|
|
109
|
+
ErrorCodes2.jsonrpcReservedErrorRangeEnd = -32e3;
|
|
110
|
+
ErrorCodes2.serverErrorEnd = -32e3;
|
|
111
|
+
})(ErrorCodes || (messages.ErrorCodes = ErrorCodes = {}));
|
|
112
|
+
class ResponseError extends Error {
|
|
113
|
+
code;
|
|
114
|
+
data;
|
|
115
|
+
constructor(code, message, data) {
|
|
116
|
+
super(message);
|
|
117
|
+
this.code = is2.number(code) ? code : ErrorCodes.UnknownErrorCode;
|
|
118
|
+
this.data = data;
|
|
119
|
+
Object.setPrototypeOf(this, ResponseError.prototype);
|
|
120
|
+
}
|
|
121
|
+
toJson() {
|
|
122
|
+
const result = {
|
|
123
|
+
code: this.code,
|
|
124
|
+
message: this.message
|
|
125
|
+
};
|
|
126
|
+
if (this.data !== void 0) {
|
|
127
|
+
result.data = this.data;
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
messages.ResponseError = ResponseError;
|
|
133
|
+
class ParameterStructures {
|
|
134
|
+
kind;
|
|
135
|
+
/**
|
|
136
|
+
* The parameter structure is automatically inferred on the number of parameters
|
|
137
|
+
* and the parameter type in case of a single param.
|
|
138
|
+
*/
|
|
139
|
+
static auto = new ParameterStructures("auto");
|
|
140
|
+
/**
|
|
141
|
+
* Forces `byPosition` parameter structure. This is useful if you have a single
|
|
142
|
+
* parameter which has a literal type.
|
|
143
|
+
*/
|
|
144
|
+
static byPosition = new ParameterStructures("byPosition");
|
|
145
|
+
/**
|
|
146
|
+
* Forces `byName` parameter structure. This is only useful when having a single
|
|
147
|
+
* parameter. The library will report errors if used with a different number of
|
|
148
|
+
* parameters.
|
|
149
|
+
*/
|
|
150
|
+
static byName = new ParameterStructures("byName");
|
|
151
|
+
constructor(kind) {
|
|
152
|
+
this.kind = kind;
|
|
153
|
+
}
|
|
154
|
+
static is(value) {
|
|
155
|
+
return value === ParameterStructures.auto || value === ParameterStructures.byName || value === ParameterStructures.byPosition;
|
|
156
|
+
}
|
|
157
|
+
toString() {
|
|
158
|
+
return this.kind;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
messages.ParameterStructures = ParameterStructures;
|
|
162
|
+
class AbstractMessageSignature {
|
|
163
|
+
method;
|
|
164
|
+
numberOfParams;
|
|
165
|
+
constructor(method, numberOfParams) {
|
|
166
|
+
this.method = method;
|
|
167
|
+
this.numberOfParams = numberOfParams;
|
|
168
|
+
}
|
|
169
|
+
get parameterStructures() {
|
|
170
|
+
return ParameterStructures.auto;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
messages.AbstractMessageSignature = AbstractMessageSignature;
|
|
174
|
+
class RequestType0 extends AbstractMessageSignature {
|
|
175
|
+
/**
|
|
176
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
177
|
+
*/
|
|
178
|
+
_;
|
|
179
|
+
constructor(method) {
|
|
180
|
+
super(method, 0);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
messages.RequestType0 = RequestType0;
|
|
184
|
+
class RequestType extends AbstractMessageSignature {
|
|
185
|
+
_parameterStructures;
|
|
186
|
+
/**
|
|
187
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
188
|
+
*/
|
|
189
|
+
_;
|
|
190
|
+
constructor(method, _parameterStructures = ParameterStructures.auto) {
|
|
191
|
+
super(method, 1);
|
|
192
|
+
this._parameterStructures = _parameterStructures;
|
|
193
|
+
}
|
|
194
|
+
get parameterStructures() {
|
|
195
|
+
return this._parameterStructures;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
messages.RequestType = RequestType;
|
|
199
|
+
class RequestType1 extends AbstractMessageSignature {
|
|
200
|
+
_parameterStructures;
|
|
201
|
+
/**
|
|
202
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
203
|
+
*/
|
|
204
|
+
_;
|
|
205
|
+
constructor(method, _parameterStructures = ParameterStructures.auto) {
|
|
206
|
+
super(method, 1);
|
|
207
|
+
this._parameterStructures = _parameterStructures;
|
|
208
|
+
}
|
|
209
|
+
get parameterStructures() {
|
|
210
|
+
return this._parameterStructures;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
messages.RequestType1 = RequestType1;
|
|
214
|
+
class RequestType2 extends AbstractMessageSignature {
|
|
215
|
+
/**
|
|
216
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
217
|
+
*/
|
|
218
|
+
_;
|
|
219
|
+
constructor(method) {
|
|
220
|
+
super(method, 2);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
messages.RequestType2 = RequestType2;
|
|
224
|
+
class RequestType3 extends AbstractMessageSignature {
|
|
225
|
+
/**
|
|
226
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
227
|
+
*/
|
|
228
|
+
_;
|
|
229
|
+
constructor(method) {
|
|
230
|
+
super(method, 3);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
messages.RequestType3 = RequestType3;
|
|
234
|
+
class RequestType4 extends AbstractMessageSignature {
|
|
235
|
+
/**
|
|
236
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
237
|
+
*/
|
|
238
|
+
_;
|
|
239
|
+
constructor(method) {
|
|
240
|
+
super(method, 4);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
messages.RequestType4 = RequestType4;
|
|
244
|
+
class RequestType5 extends AbstractMessageSignature {
|
|
245
|
+
/**
|
|
246
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
247
|
+
*/
|
|
248
|
+
_;
|
|
249
|
+
constructor(method) {
|
|
250
|
+
super(method, 5);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
messages.RequestType5 = RequestType5;
|
|
254
|
+
class RequestType6 extends AbstractMessageSignature {
|
|
255
|
+
/**
|
|
256
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
257
|
+
*/
|
|
258
|
+
_;
|
|
259
|
+
constructor(method) {
|
|
260
|
+
super(method, 6);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
messages.RequestType6 = RequestType6;
|
|
264
|
+
class RequestType7 extends AbstractMessageSignature {
|
|
265
|
+
/**
|
|
266
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
267
|
+
*/
|
|
268
|
+
_;
|
|
269
|
+
constructor(method) {
|
|
270
|
+
super(method, 7);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
messages.RequestType7 = RequestType7;
|
|
274
|
+
class RequestType8 extends AbstractMessageSignature {
|
|
275
|
+
/**
|
|
276
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
277
|
+
*/
|
|
278
|
+
_;
|
|
279
|
+
constructor(method) {
|
|
280
|
+
super(method, 8);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
messages.RequestType8 = RequestType8;
|
|
284
|
+
class RequestType9 extends AbstractMessageSignature {
|
|
285
|
+
/**
|
|
286
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
287
|
+
*/
|
|
288
|
+
_;
|
|
289
|
+
constructor(method) {
|
|
290
|
+
super(method, 9);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
messages.RequestType9 = RequestType9;
|
|
294
|
+
class NotificationType extends AbstractMessageSignature {
|
|
295
|
+
_parameterStructures;
|
|
296
|
+
/**
|
|
297
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
298
|
+
*/
|
|
299
|
+
_;
|
|
300
|
+
constructor(method, _parameterStructures = ParameterStructures.auto) {
|
|
301
|
+
super(method, 1);
|
|
302
|
+
this._parameterStructures = _parameterStructures;
|
|
303
|
+
}
|
|
304
|
+
get parameterStructures() {
|
|
305
|
+
return this._parameterStructures;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
messages.NotificationType = NotificationType;
|
|
309
|
+
class NotificationType0 extends AbstractMessageSignature {
|
|
310
|
+
/**
|
|
311
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
312
|
+
*/
|
|
313
|
+
_;
|
|
314
|
+
constructor(method) {
|
|
315
|
+
super(method, 0);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
messages.NotificationType0 = NotificationType0;
|
|
319
|
+
class NotificationType1 extends AbstractMessageSignature {
|
|
320
|
+
_parameterStructures;
|
|
321
|
+
/**
|
|
322
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
323
|
+
*/
|
|
324
|
+
_;
|
|
325
|
+
constructor(method, _parameterStructures = ParameterStructures.auto) {
|
|
326
|
+
super(method, 1);
|
|
327
|
+
this._parameterStructures = _parameterStructures;
|
|
328
|
+
}
|
|
329
|
+
get parameterStructures() {
|
|
330
|
+
return this._parameterStructures;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
messages.NotificationType1 = NotificationType1;
|
|
334
|
+
class NotificationType2 extends AbstractMessageSignature {
|
|
335
|
+
/**
|
|
336
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
337
|
+
*/
|
|
338
|
+
_;
|
|
339
|
+
constructor(method) {
|
|
340
|
+
super(method, 2);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
messages.NotificationType2 = NotificationType2;
|
|
344
|
+
class NotificationType3 extends AbstractMessageSignature {
|
|
345
|
+
/**
|
|
346
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
347
|
+
*/
|
|
348
|
+
_;
|
|
349
|
+
constructor(method) {
|
|
350
|
+
super(method, 3);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
messages.NotificationType3 = NotificationType3;
|
|
354
|
+
class NotificationType4 extends AbstractMessageSignature {
|
|
355
|
+
/**
|
|
356
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
357
|
+
*/
|
|
358
|
+
_;
|
|
359
|
+
constructor(method) {
|
|
360
|
+
super(method, 4);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
messages.NotificationType4 = NotificationType4;
|
|
364
|
+
class NotificationType5 extends AbstractMessageSignature {
|
|
365
|
+
/**
|
|
366
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
367
|
+
*/
|
|
368
|
+
_;
|
|
369
|
+
constructor(method) {
|
|
370
|
+
super(method, 5);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
messages.NotificationType5 = NotificationType5;
|
|
374
|
+
class NotificationType6 extends AbstractMessageSignature {
|
|
375
|
+
/**
|
|
376
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
377
|
+
*/
|
|
378
|
+
_;
|
|
379
|
+
constructor(method) {
|
|
380
|
+
super(method, 6);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
messages.NotificationType6 = NotificationType6;
|
|
384
|
+
class NotificationType7 extends AbstractMessageSignature {
|
|
385
|
+
/**
|
|
386
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
387
|
+
*/
|
|
388
|
+
_;
|
|
389
|
+
constructor(method) {
|
|
390
|
+
super(method, 7);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
messages.NotificationType7 = NotificationType7;
|
|
394
|
+
class NotificationType8 extends AbstractMessageSignature {
|
|
395
|
+
/**
|
|
396
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
397
|
+
*/
|
|
398
|
+
_;
|
|
399
|
+
constructor(method) {
|
|
400
|
+
super(method, 8);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
messages.NotificationType8 = NotificationType8;
|
|
404
|
+
class NotificationType9 extends AbstractMessageSignature {
|
|
405
|
+
/**
|
|
406
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
407
|
+
*/
|
|
408
|
+
_;
|
|
409
|
+
constructor(method) {
|
|
410
|
+
super(method, 9);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
messages.NotificationType9 = NotificationType9;
|
|
414
|
+
var Message;
|
|
415
|
+
(function(Message2) {
|
|
416
|
+
function isRequest(message) {
|
|
417
|
+
const candidate = message;
|
|
418
|
+
return candidate && is2.string(candidate.method) && (is2.string(candidate.id) || is2.number(candidate.id));
|
|
419
|
+
}
|
|
420
|
+
Message2.isRequest = isRequest;
|
|
421
|
+
function isNotification(message) {
|
|
422
|
+
const candidate = message;
|
|
423
|
+
return candidate && is2.string(candidate.method) && message.id === void 0;
|
|
424
|
+
}
|
|
425
|
+
Message2.isNotification = isNotification;
|
|
426
|
+
function isResponse(message) {
|
|
427
|
+
const candidate = message;
|
|
428
|
+
return candidate && (candidate.result !== void 0 || !!candidate.error) && (is2.string(candidate.id) || is2.number(candidate.id) || candidate.id === null);
|
|
429
|
+
}
|
|
430
|
+
Message2.isResponse = isResponse;
|
|
431
|
+
})(Message || (messages.Message = Message = {}));
|
|
432
|
+
return messages;
|
|
433
|
+
}
|
|
434
|
+
var linkedMap = {};
|
|
435
|
+
var hasRequiredLinkedMap;
|
|
436
|
+
function requireLinkedMap() {
|
|
437
|
+
if (hasRequiredLinkedMap) return linkedMap;
|
|
438
|
+
hasRequiredLinkedMap = 1;
|
|
439
|
+
Object.defineProperty(linkedMap, "__esModule", { value: true });
|
|
440
|
+
linkedMap.LRUCache = linkedMap.LinkedMap = linkedMap.Touch = void 0;
|
|
441
|
+
var Touch;
|
|
442
|
+
(function(Touch2) {
|
|
443
|
+
Touch2.None = 0;
|
|
444
|
+
Touch2.First = 1;
|
|
445
|
+
Touch2.AsOld = Touch2.First;
|
|
446
|
+
Touch2.Last = 2;
|
|
447
|
+
Touch2.AsNew = Touch2.Last;
|
|
448
|
+
})(Touch || (linkedMap.Touch = Touch = {}));
|
|
449
|
+
class LinkedMap {
|
|
450
|
+
[Symbol.toStringTag] = "LinkedMap";
|
|
451
|
+
_map;
|
|
452
|
+
_head;
|
|
453
|
+
_tail;
|
|
454
|
+
_size;
|
|
455
|
+
_state;
|
|
456
|
+
constructor() {
|
|
457
|
+
this._map = /* @__PURE__ */ new Map();
|
|
458
|
+
this._head = void 0;
|
|
459
|
+
this._tail = void 0;
|
|
460
|
+
this._size = 0;
|
|
461
|
+
this._state = 0;
|
|
462
|
+
}
|
|
463
|
+
clear() {
|
|
464
|
+
this._map.clear();
|
|
465
|
+
this._head = void 0;
|
|
466
|
+
this._tail = void 0;
|
|
467
|
+
this._size = 0;
|
|
468
|
+
this._state++;
|
|
469
|
+
}
|
|
470
|
+
isEmpty() {
|
|
471
|
+
return !this._head && !this._tail;
|
|
472
|
+
}
|
|
473
|
+
get size() {
|
|
474
|
+
return this._size;
|
|
475
|
+
}
|
|
476
|
+
get first() {
|
|
477
|
+
return this._head?.value;
|
|
478
|
+
}
|
|
479
|
+
get last() {
|
|
480
|
+
return this._tail?.value;
|
|
481
|
+
}
|
|
482
|
+
before(key) {
|
|
483
|
+
const item = this._map.get(key);
|
|
484
|
+
return item ? item.previous?.value : void 0;
|
|
485
|
+
}
|
|
486
|
+
after(key) {
|
|
487
|
+
const item = this._map.get(key);
|
|
488
|
+
return item ? item.next?.value : void 0;
|
|
489
|
+
}
|
|
490
|
+
has(key) {
|
|
491
|
+
return this._map.has(key);
|
|
492
|
+
}
|
|
493
|
+
get(key, touch = Touch.None) {
|
|
494
|
+
const item = this._map.get(key);
|
|
495
|
+
if (!item) {
|
|
496
|
+
return void 0;
|
|
497
|
+
}
|
|
498
|
+
if (touch !== Touch.None) {
|
|
499
|
+
this.touch(item, touch);
|
|
500
|
+
}
|
|
501
|
+
return item.value;
|
|
502
|
+
}
|
|
503
|
+
set(key, value, touch = Touch.None) {
|
|
504
|
+
let item = this._map.get(key);
|
|
505
|
+
if (item) {
|
|
506
|
+
item.value = value;
|
|
507
|
+
if (touch !== Touch.None) {
|
|
508
|
+
this.touch(item, touch);
|
|
509
|
+
}
|
|
510
|
+
} else {
|
|
511
|
+
item = { key, value, next: void 0, previous: void 0 };
|
|
512
|
+
switch (touch) {
|
|
513
|
+
case Touch.None:
|
|
514
|
+
this.addItemLast(item);
|
|
515
|
+
break;
|
|
516
|
+
case Touch.First:
|
|
517
|
+
this.addItemFirst(item);
|
|
518
|
+
break;
|
|
519
|
+
case Touch.Last:
|
|
520
|
+
this.addItemLast(item);
|
|
521
|
+
break;
|
|
522
|
+
default:
|
|
523
|
+
this.addItemLast(item);
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
this._map.set(key, item);
|
|
527
|
+
this._size++;
|
|
528
|
+
}
|
|
529
|
+
return this;
|
|
530
|
+
}
|
|
531
|
+
delete(key) {
|
|
532
|
+
return !!this.remove(key);
|
|
533
|
+
}
|
|
534
|
+
remove(key) {
|
|
535
|
+
const item = this._map.get(key);
|
|
536
|
+
if (!item) {
|
|
537
|
+
return void 0;
|
|
538
|
+
}
|
|
539
|
+
this._map.delete(key);
|
|
540
|
+
this.removeItem(item);
|
|
541
|
+
this._size--;
|
|
542
|
+
return item.value;
|
|
543
|
+
}
|
|
544
|
+
shift() {
|
|
545
|
+
if (!this._head && !this._tail) {
|
|
546
|
+
return void 0;
|
|
547
|
+
}
|
|
548
|
+
if (!this._head || !this._tail) {
|
|
549
|
+
throw new Error("Invalid list");
|
|
550
|
+
}
|
|
551
|
+
const item = this._head;
|
|
552
|
+
this._map.delete(item.key);
|
|
553
|
+
this.removeItem(item);
|
|
554
|
+
this._size--;
|
|
555
|
+
return item.value;
|
|
556
|
+
}
|
|
557
|
+
forEach(callbackfn, thisArg) {
|
|
558
|
+
const state = this._state;
|
|
559
|
+
let current = this._head;
|
|
560
|
+
while (current) {
|
|
561
|
+
if (thisArg) {
|
|
562
|
+
callbackfn.bind(thisArg)(current.value, current.key, this);
|
|
563
|
+
} else {
|
|
564
|
+
callbackfn(current.value, current.key, this);
|
|
565
|
+
}
|
|
566
|
+
if (this._state !== state) {
|
|
567
|
+
throw new Error(`LinkedMap got modified during iteration.`);
|
|
568
|
+
}
|
|
569
|
+
current = current.next;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
keys() {
|
|
573
|
+
const state = this._state;
|
|
574
|
+
let current = this._head;
|
|
575
|
+
const iterator = {
|
|
576
|
+
[Symbol.iterator]: () => {
|
|
577
|
+
return iterator;
|
|
578
|
+
},
|
|
579
|
+
next: () => {
|
|
580
|
+
if (this._state !== state) {
|
|
581
|
+
throw new Error(`LinkedMap got modified during iteration.`);
|
|
582
|
+
}
|
|
583
|
+
if (current) {
|
|
584
|
+
const result = { value: current.key, done: false };
|
|
585
|
+
current = current.next;
|
|
586
|
+
return result;
|
|
587
|
+
} else {
|
|
588
|
+
return { value: void 0, done: true };
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
return iterator;
|
|
593
|
+
}
|
|
594
|
+
values() {
|
|
595
|
+
const state = this._state;
|
|
596
|
+
let current = this._head;
|
|
597
|
+
const iterator = {
|
|
598
|
+
[Symbol.iterator]: () => {
|
|
599
|
+
return iterator;
|
|
600
|
+
},
|
|
601
|
+
next: () => {
|
|
602
|
+
if (this._state !== state) {
|
|
603
|
+
throw new Error(`LinkedMap got modified during iteration.`);
|
|
604
|
+
}
|
|
605
|
+
if (current) {
|
|
606
|
+
const result = { value: current.value, done: false };
|
|
607
|
+
current = current.next;
|
|
608
|
+
return result;
|
|
609
|
+
} else {
|
|
610
|
+
return { value: void 0, done: true };
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
return iterator;
|
|
615
|
+
}
|
|
616
|
+
entries() {
|
|
617
|
+
const state = this._state;
|
|
618
|
+
let current = this._head;
|
|
619
|
+
const iterator = {
|
|
620
|
+
[Symbol.iterator]: () => {
|
|
621
|
+
return iterator;
|
|
622
|
+
},
|
|
623
|
+
next: () => {
|
|
624
|
+
if (this._state !== state) {
|
|
625
|
+
throw new Error(`LinkedMap got modified during iteration.`);
|
|
626
|
+
}
|
|
627
|
+
if (current) {
|
|
628
|
+
const result = { value: [current.key, current.value], done: false };
|
|
629
|
+
current = current.next;
|
|
630
|
+
return result;
|
|
631
|
+
} else {
|
|
632
|
+
return { value: void 0, done: true };
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
return iterator;
|
|
637
|
+
}
|
|
638
|
+
[Symbol.iterator]() {
|
|
639
|
+
return this.entries();
|
|
640
|
+
}
|
|
641
|
+
trimOld(newSize) {
|
|
642
|
+
if (newSize >= this.size) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (newSize === 0) {
|
|
646
|
+
this.clear();
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
let current = this._head;
|
|
650
|
+
let currentSize = this.size;
|
|
651
|
+
while (current && currentSize > newSize) {
|
|
652
|
+
this._map.delete(current.key);
|
|
653
|
+
current = current.next;
|
|
654
|
+
currentSize--;
|
|
655
|
+
}
|
|
656
|
+
this._head = current;
|
|
657
|
+
this._size = currentSize;
|
|
658
|
+
if (current) {
|
|
659
|
+
current.previous = void 0;
|
|
660
|
+
}
|
|
661
|
+
this._state++;
|
|
662
|
+
}
|
|
663
|
+
addItemFirst(item) {
|
|
664
|
+
if (!this._head && !this._tail) {
|
|
665
|
+
this._tail = item;
|
|
666
|
+
} else if (!this._head) {
|
|
667
|
+
throw new Error("Invalid list");
|
|
668
|
+
} else {
|
|
669
|
+
item.next = this._head;
|
|
670
|
+
this._head.previous = item;
|
|
671
|
+
}
|
|
672
|
+
this._head = item;
|
|
673
|
+
this._state++;
|
|
674
|
+
}
|
|
675
|
+
addItemLast(item) {
|
|
676
|
+
if (!this._head && !this._tail) {
|
|
677
|
+
this._head = item;
|
|
678
|
+
} else if (!this._tail) {
|
|
679
|
+
throw new Error("Invalid list");
|
|
680
|
+
} else {
|
|
681
|
+
item.previous = this._tail;
|
|
682
|
+
this._tail.next = item;
|
|
683
|
+
}
|
|
684
|
+
this._tail = item;
|
|
685
|
+
this._state++;
|
|
686
|
+
}
|
|
687
|
+
removeItem(item) {
|
|
688
|
+
if (item === this._head && item === this._tail) {
|
|
689
|
+
this._head = void 0;
|
|
690
|
+
this._tail = void 0;
|
|
691
|
+
} else if (item === this._head) {
|
|
692
|
+
if (!item.next) {
|
|
693
|
+
throw new Error("Invalid list");
|
|
694
|
+
}
|
|
695
|
+
item.next.previous = void 0;
|
|
696
|
+
this._head = item.next;
|
|
697
|
+
} else if (item === this._tail) {
|
|
698
|
+
if (!item.previous) {
|
|
699
|
+
throw new Error("Invalid list");
|
|
700
|
+
}
|
|
701
|
+
item.previous.next = void 0;
|
|
702
|
+
this._tail = item.previous;
|
|
703
|
+
} else {
|
|
704
|
+
const next = item.next;
|
|
705
|
+
const previous = item.previous;
|
|
706
|
+
if (!next || !previous) {
|
|
707
|
+
throw new Error("Invalid list");
|
|
708
|
+
}
|
|
709
|
+
next.previous = previous;
|
|
710
|
+
previous.next = next;
|
|
711
|
+
}
|
|
712
|
+
item.next = void 0;
|
|
713
|
+
item.previous = void 0;
|
|
714
|
+
this._state++;
|
|
715
|
+
}
|
|
716
|
+
touch(item, touch) {
|
|
717
|
+
if (!this._head || !this._tail) {
|
|
718
|
+
throw new Error("Invalid list");
|
|
719
|
+
}
|
|
720
|
+
if (touch !== Touch.First && touch !== Touch.Last) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (touch === Touch.First) {
|
|
724
|
+
if (item === this._head) {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
const next = item.next;
|
|
728
|
+
const previous = item.previous;
|
|
729
|
+
if (item === this._tail) {
|
|
730
|
+
previous.next = void 0;
|
|
731
|
+
this._tail = previous;
|
|
732
|
+
} else {
|
|
733
|
+
next.previous = previous;
|
|
734
|
+
previous.next = next;
|
|
735
|
+
}
|
|
736
|
+
item.previous = void 0;
|
|
737
|
+
item.next = this._head;
|
|
738
|
+
this._head.previous = item;
|
|
739
|
+
this._head = item;
|
|
740
|
+
this._state++;
|
|
741
|
+
} else if (touch === Touch.Last) {
|
|
742
|
+
if (item === this._tail) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
const next = item.next;
|
|
746
|
+
const previous = item.previous;
|
|
747
|
+
if (item === this._head) {
|
|
748
|
+
next.previous = void 0;
|
|
749
|
+
this._head = next;
|
|
750
|
+
} else {
|
|
751
|
+
next.previous = previous;
|
|
752
|
+
previous.next = next;
|
|
753
|
+
}
|
|
754
|
+
item.next = void 0;
|
|
755
|
+
item.previous = this._tail;
|
|
756
|
+
this._tail.next = item;
|
|
757
|
+
this._tail = item;
|
|
758
|
+
this._state++;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
toJSON() {
|
|
762
|
+
const data = [];
|
|
763
|
+
this.forEach((value, key) => {
|
|
764
|
+
data.push([key, value]);
|
|
765
|
+
});
|
|
766
|
+
return data;
|
|
767
|
+
}
|
|
768
|
+
fromJSON(data) {
|
|
769
|
+
this.clear();
|
|
770
|
+
for (const [key, value] of data) {
|
|
771
|
+
this.set(key, value);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
linkedMap.LinkedMap = LinkedMap;
|
|
776
|
+
class LRUCache extends LinkedMap {
|
|
777
|
+
_limit;
|
|
778
|
+
_ratio;
|
|
779
|
+
constructor(limit, ratio = 1) {
|
|
780
|
+
super();
|
|
781
|
+
this._limit = limit;
|
|
782
|
+
this._ratio = Math.min(Math.max(0, ratio), 1);
|
|
783
|
+
}
|
|
784
|
+
get limit() {
|
|
785
|
+
return this._limit;
|
|
786
|
+
}
|
|
787
|
+
set limit(limit) {
|
|
788
|
+
this._limit = limit;
|
|
789
|
+
this.checkTrim();
|
|
790
|
+
}
|
|
791
|
+
get ratio() {
|
|
792
|
+
return this._ratio;
|
|
793
|
+
}
|
|
794
|
+
set ratio(ratio) {
|
|
795
|
+
this._ratio = Math.min(Math.max(0, ratio), 1);
|
|
796
|
+
this.checkTrim();
|
|
797
|
+
}
|
|
798
|
+
get(key, touch = Touch.AsNew) {
|
|
799
|
+
return super.get(key, touch);
|
|
800
|
+
}
|
|
801
|
+
peek(key) {
|
|
802
|
+
return super.get(key, Touch.None);
|
|
803
|
+
}
|
|
804
|
+
set(key, value) {
|
|
805
|
+
super.set(key, value, Touch.Last);
|
|
806
|
+
this.checkTrim();
|
|
807
|
+
return this;
|
|
808
|
+
}
|
|
809
|
+
checkTrim() {
|
|
810
|
+
if (this.size > this._limit) {
|
|
811
|
+
this.trimOld(Math.round(this._limit * this._ratio));
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
linkedMap.LRUCache = LRUCache;
|
|
816
|
+
return linkedMap;
|
|
817
|
+
}
|
|
818
|
+
var disposable = {};
|
|
819
|
+
var hasRequiredDisposable;
|
|
820
|
+
function requireDisposable() {
|
|
821
|
+
if (hasRequiredDisposable) return disposable;
|
|
822
|
+
hasRequiredDisposable = 1;
|
|
823
|
+
Object.defineProperty(disposable, "__esModule", { value: true });
|
|
824
|
+
disposable.Disposable = void 0;
|
|
825
|
+
var Disposable;
|
|
826
|
+
(function(Disposable2) {
|
|
827
|
+
function create(func) {
|
|
828
|
+
return {
|
|
829
|
+
dispose: func
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
Disposable2.create = create;
|
|
833
|
+
})(Disposable || (disposable.Disposable = Disposable = {}));
|
|
834
|
+
return disposable;
|
|
835
|
+
}
|
|
836
|
+
var events = {};
|
|
837
|
+
var ral = {};
|
|
838
|
+
var hasRequiredRal;
|
|
839
|
+
function requireRal() {
|
|
840
|
+
if (hasRequiredRal) return ral;
|
|
841
|
+
hasRequiredRal = 1;
|
|
842
|
+
Object.defineProperty(ral, "__esModule", { value: true });
|
|
843
|
+
let _ral;
|
|
844
|
+
function RAL() {
|
|
845
|
+
if (_ral === void 0) {
|
|
846
|
+
throw new Error(`No runtime abstraction layer installed`);
|
|
847
|
+
}
|
|
848
|
+
return _ral;
|
|
849
|
+
}
|
|
850
|
+
(function(RAL2) {
|
|
851
|
+
function install(ral2) {
|
|
852
|
+
if (ral2 === void 0) {
|
|
853
|
+
throw new Error(`No runtime abstraction layer provided`);
|
|
854
|
+
}
|
|
855
|
+
_ral = ral2;
|
|
856
|
+
}
|
|
857
|
+
RAL2.install = install;
|
|
858
|
+
})(RAL || (RAL = {}));
|
|
859
|
+
ral.default = RAL;
|
|
860
|
+
return ral;
|
|
861
|
+
}
|
|
862
|
+
var hasRequiredEvents;
|
|
863
|
+
function requireEvents() {
|
|
864
|
+
if (hasRequiredEvents) return events;
|
|
865
|
+
hasRequiredEvents = 1;
|
|
866
|
+
var __importDefault = events && events.__importDefault || function(mod) {
|
|
867
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
868
|
+
};
|
|
869
|
+
Object.defineProperty(events, "__esModule", { value: true });
|
|
870
|
+
events.Emitter = events.Event = void 0;
|
|
871
|
+
const ral_1 = __importDefault(requireRal());
|
|
872
|
+
var Event;
|
|
873
|
+
(function(Event2) {
|
|
874
|
+
const _disposable = { dispose() {
|
|
875
|
+
} };
|
|
876
|
+
Event2.None = function() {
|
|
877
|
+
return _disposable;
|
|
878
|
+
};
|
|
879
|
+
})(Event || (events.Event = Event = {}));
|
|
880
|
+
class CallbackList {
|
|
881
|
+
_callbacks;
|
|
882
|
+
_contexts;
|
|
883
|
+
add(callback, context = null, bucket) {
|
|
884
|
+
if (!this._callbacks) {
|
|
885
|
+
this._callbacks = [];
|
|
886
|
+
this._contexts = [];
|
|
887
|
+
}
|
|
888
|
+
this._callbacks.push(callback);
|
|
889
|
+
this._contexts.push(context);
|
|
890
|
+
if (Array.isArray(bucket)) {
|
|
891
|
+
bucket.push({ dispose: () => this.remove(callback, context) });
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
remove(callback, context = null) {
|
|
895
|
+
if (!this._callbacks) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
let foundCallbackWithDifferentContext = false;
|
|
899
|
+
for (let i = 0, len = this._callbacks.length; i < len; i++) {
|
|
900
|
+
if (this._callbacks[i] === callback) {
|
|
901
|
+
if (this._contexts[i] === context) {
|
|
902
|
+
this._callbacks.splice(i, 1);
|
|
903
|
+
this._contexts.splice(i, 1);
|
|
904
|
+
return;
|
|
905
|
+
} else {
|
|
906
|
+
foundCallbackWithDifferentContext = true;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
if (foundCallbackWithDifferentContext) {
|
|
911
|
+
throw new Error("When adding a listener with a context, you should remove it with the same context");
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
invoke(...args) {
|
|
915
|
+
if (!this._callbacks) {
|
|
916
|
+
return [];
|
|
917
|
+
}
|
|
918
|
+
const ret = [], callbacks = this._callbacks.slice(0), contexts = this._contexts.slice(0);
|
|
919
|
+
for (let i = 0, len = callbacks.length; i < len; i++) {
|
|
920
|
+
try {
|
|
921
|
+
ret.push(callbacks[i].apply(contexts[i], args));
|
|
922
|
+
} catch (e) {
|
|
923
|
+
(0, ral_1.default)().console.error(e);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return ret;
|
|
927
|
+
}
|
|
928
|
+
isEmpty() {
|
|
929
|
+
return !this._callbacks || this._callbacks.length === 0;
|
|
930
|
+
}
|
|
931
|
+
dispose() {
|
|
932
|
+
this._callbacks = void 0;
|
|
933
|
+
this._contexts = void 0;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
class Emitter {
|
|
937
|
+
_options;
|
|
938
|
+
static _noop = function() {
|
|
939
|
+
};
|
|
940
|
+
_event;
|
|
941
|
+
_callbacks;
|
|
942
|
+
constructor(_options) {
|
|
943
|
+
this._options = _options;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* For the public to allow to subscribe
|
|
947
|
+
* to events from this Emitter
|
|
948
|
+
*/
|
|
949
|
+
get event() {
|
|
950
|
+
if (!this._event) {
|
|
951
|
+
this._event = (listener, thisArgs, disposables) => {
|
|
952
|
+
if (!this._callbacks) {
|
|
953
|
+
this._callbacks = new CallbackList();
|
|
954
|
+
}
|
|
955
|
+
if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
|
|
956
|
+
this._options.onFirstListenerAdd(this);
|
|
957
|
+
}
|
|
958
|
+
this._callbacks.add(listener, thisArgs);
|
|
959
|
+
const result = {
|
|
960
|
+
dispose: () => {
|
|
961
|
+
if (!this._callbacks) {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
this._callbacks.remove(listener, thisArgs);
|
|
965
|
+
result.dispose = Emitter._noop;
|
|
966
|
+
if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
|
|
967
|
+
this._options.onLastListenerRemove(this);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
if (Array.isArray(disposables)) {
|
|
972
|
+
disposables.push(result);
|
|
973
|
+
}
|
|
974
|
+
return result;
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
return this._event;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* To be kept private to fire an event to
|
|
981
|
+
* subscribers
|
|
982
|
+
*/
|
|
983
|
+
fire(event) {
|
|
984
|
+
if (this._callbacks) {
|
|
985
|
+
this._callbacks.invoke.call(this._callbacks, event);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
dispose() {
|
|
989
|
+
if (this._callbacks) {
|
|
990
|
+
this._callbacks.dispose();
|
|
991
|
+
this._callbacks = void 0;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
events.Emitter = Emitter;
|
|
996
|
+
return events;
|
|
997
|
+
}
|
|
998
|
+
var cancellation = {};
|
|
999
|
+
var hasRequiredCancellation;
|
|
1000
|
+
function requireCancellation() {
|
|
1001
|
+
if (hasRequiredCancellation) return cancellation;
|
|
1002
|
+
hasRequiredCancellation = 1;
|
|
1003
|
+
var __createBinding = cancellation && cancellation.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1004
|
+
if (k2 === void 0) k2 = k;
|
|
1005
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1006
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1007
|
+
desc = { enumerable: true, get: function() {
|
|
1008
|
+
return m[k];
|
|
1009
|
+
} };
|
|
1010
|
+
}
|
|
1011
|
+
Object.defineProperty(o, k2, desc);
|
|
1012
|
+
}) : (function(o, m, k, k2) {
|
|
1013
|
+
if (k2 === void 0) k2 = k;
|
|
1014
|
+
o[k2] = m[k];
|
|
1015
|
+
}));
|
|
1016
|
+
var __setModuleDefault = cancellation && cancellation.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1017
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1018
|
+
}) : function(o, v) {
|
|
1019
|
+
o["default"] = v;
|
|
1020
|
+
});
|
|
1021
|
+
var __importStar = cancellation && cancellation.__importStar || /* @__PURE__ */ (function() {
|
|
1022
|
+
var ownKeys = function(o) {
|
|
1023
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1024
|
+
var ar = [];
|
|
1025
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1026
|
+
return ar;
|
|
1027
|
+
};
|
|
1028
|
+
return ownKeys(o);
|
|
1029
|
+
};
|
|
1030
|
+
return function(mod) {
|
|
1031
|
+
if (mod && mod.__esModule) return mod;
|
|
1032
|
+
var result = {};
|
|
1033
|
+
if (mod != null) {
|
|
1034
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1035
|
+
}
|
|
1036
|
+
__setModuleDefault(result, mod);
|
|
1037
|
+
return result;
|
|
1038
|
+
};
|
|
1039
|
+
})();
|
|
1040
|
+
var __importDefault = cancellation && cancellation.__importDefault || function(mod) {
|
|
1041
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1042
|
+
};
|
|
1043
|
+
Object.defineProperty(cancellation, "__esModule", { value: true });
|
|
1044
|
+
cancellation.CancellationTokenSource = cancellation.CancellationToken = void 0;
|
|
1045
|
+
const ral_1 = __importDefault(requireRal());
|
|
1046
|
+
const Is = __importStar(requireIs());
|
|
1047
|
+
const events_1 = requireEvents();
|
|
1048
|
+
var CancellationToken;
|
|
1049
|
+
(function(CancellationToken2) {
|
|
1050
|
+
CancellationToken2.None = Object.freeze({
|
|
1051
|
+
isCancellationRequested: false,
|
|
1052
|
+
onCancellationRequested: events_1.Event.None
|
|
1053
|
+
});
|
|
1054
|
+
CancellationToken2.Cancelled = Object.freeze({
|
|
1055
|
+
isCancellationRequested: true,
|
|
1056
|
+
onCancellationRequested: events_1.Event.None
|
|
1057
|
+
});
|
|
1058
|
+
function is2(value) {
|
|
1059
|
+
const candidate = value;
|
|
1060
|
+
return candidate && (candidate === CancellationToken2.None || candidate === CancellationToken2.Cancelled || Is.boolean(candidate.isCancellationRequested) && !!candidate.onCancellationRequested);
|
|
1061
|
+
}
|
|
1062
|
+
CancellationToken2.is = is2;
|
|
1063
|
+
})(CancellationToken || (cancellation.CancellationToken = CancellationToken = {}));
|
|
1064
|
+
const shortcutEvent = Object.freeze(function(callback, context) {
|
|
1065
|
+
const handle2 = (0, ral_1.default)().timer.setTimeout(callback.bind(context), 0);
|
|
1066
|
+
return { dispose() {
|
|
1067
|
+
handle2.dispose();
|
|
1068
|
+
} };
|
|
1069
|
+
});
|
|
1070
|
+
class MutableToken {
|
|
1071
|
+
_isCancelled = false;
|
|
1072
|
+
_emitter;
|
|
1073
|
+
cancel() {
|
|
1074
|
+
if (!this._isCancelled) {
|
|
1075
|
+
this._isCancelled = true;
|
|
1076
|
+
if (this._emitter) {
|
|
1077
|
+
this._emitter.fire(void 0);
|
|
1078
|
+
this.dispose();
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
get isCancellationRequested() {
|
|
1083
|
+
return this._isCancelled;
|
|
1084
|
+
}
|
|
1085
|
+
get onCancellationRequested() {
|
|
1086
|
+
if (this._isCancelled) {
|
|
1087
|
+
return shortcutEvent;
|
|
1088
|
+
}
|
|
1089
|
+
if (!this._emitter) {
|
|
1090
|
+
this._emitter = new events_1.Emitter();
|
|
1091
|
+
}
|
|
1092
|
+
return this._emitter.event;
|
|
1093
|
+
}
|
|
1094
|
+
dispose() {
|
|
1095
|
+
if (this._emitter) {
|
|
1096
|
+
this._emitter.dispose();
|
|
1097
|
+
this._emitter = void 0;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
class CancellationTokenSource {
|
|
1102
|
+
_token;
|
|
1103
|
+
get token() {
|
|
1104
|
+
if (!this._token) {
|
|
1105
|
+
this._token = new MutableToken();
|
|
1106
|
+
}
|
|
1107
|
+
return this._token;
|
|
1108
|
+
}
|
|
1109
|
+
cancel() {
|
|
1110
|
+
if (!this._token) {
|
|
1111
|
+
this._token = CancellationToken.Cancelled;
|
|
1112
|
+
} else {
|
|
1113
|
+
this._token.cancel();
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
dispose() {
|
|
1117
|
+
if (!this._token) {
|
|
1118
|
+
this._token = CancellationToken.None;
|
|
1119
|
+
} else if (this._token instanceof MutableToken) {
|
|
1120
|
+
this._token.dispose();
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
cancellation.CancellationTokenSource = CancellationTokenSource;
|
|
1125
|
+
return cancellation;
|
|
1126
|
+
}
|
|
1127
|
+
var sharedArrayCancellation = {};
|
|
1128
|
+
var hasRequiredSharedArrayCancellation;
|
|
1129
|
+
function requireSharedArrayCancellation() {
|
|
1130
|
+
if (hasRequiredSharedArrayCancellation) return sharedArrayCancellation;
|
|
1131
|
+
hasRequiredSharedArrayCancellation = 1;
|
|
1132
|
+
Object.defineProperty(sharedArrayCancellation, "__esModule", { value: true });
|
|
1133
|
+
sharedArrayCancellation.SharedArrayReceiverStrategy = sharedArrayCancellation.SharedArraySenderStrategy = void 0;
|
|
1134
|
+
const cancellation_1 = requireCancellation();
|
|
1135
|
+
var CancellationState;
|
|
1136
|
+
(function(CancellationState2) {
|
|
1137
|
+
CancellationState2.Continue = 0;
|
|
1138
|
+
CancellationState2.Cancelled = 1;
|
|
1139
|
+
})(CancellationState || (CancellationState = {}));
|
|
1140
|
+
class SharedArraySenderStrategy {
|
|
1141
|
+
buffers;
|
|
1142
|
+
constructor() {
|
|
1143
|
+
this.buffers = /* @__PURE__ */ new Map();
|
|
1144
|
+
}
|
|
1145
|
+
enableCancellation(request) {
|
|
1146
|
+
if (request.id === null) {
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
const buffer = new SharedArrayBuffer(4);
|
|
1150
|
+
const data = new Int32Array(buffer, 0, 1);
|
|
1151
|
+
data[0] = CancellationState.Continue;
|
|
1152
|
+
this.buffers.set(request.id, buffer);
|
|
1153
|
+
request.$cancellationData = buffer;
|
|
1154
|
+
}
|
|
1155
|
+
async sendCancellation(_conn, id) {
|
|
1156
|
+
const buffer = this.buffers.get(id);
|
|
1157
|
+
if (buffer === void 0) {
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
const data = new Int32Array(buffer, 0, 1);
|
|
1161
|
+
Atomics.store(data, 0, CancellationState.Cancelled);
|
|
1162
|
+
}
|
|
1163
|
+
cleanup(id) {
|
|
1164
|
+
this.buffers.delete(id);
|
|
1165
|
+
}
|
|
1166
|
+
dispose() {
|
|
1167
|
+
this.buffers.clear();
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
sharedArrayCancellation.SharedArraySenderStrategy = SharedArraySenderStrategy;
|
|
1171
|
+
class SharedArrayBufferCancellationToken {
|
|
1172
|
+
data;
|
|
1173
|
+
constructor(buffer) {
|
|
1174
|
+
this.data = new Int32Array(buffer, 0, 1);
|
|
1175
|
+
}
|
|
1176
|
+
get isCancellationRequested() {
|
|
1177
|
+
return Atomics.load(this.data, 0) === CancellationState.Cancelled;
|
|
1178
|
+
}
|
|
1179
|
+
get onCancellationRequested() {
|
|
1180
|
+
throw new Error(`Cancellation over SharedArrayBuffer doesn't support cancellation events`);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
class SharedArrayBufferCancellationTokenSource {
|
|
1184
|
+
token;
|
|
1185
|
+
constructor(buffer) {
|
|
1186
|
+
this.token = new SharedArrayBufferCancellationToken(buffer);
|
|
1187
|
+
}
|
|
1188
|
+
cancel() {
|
|
1189
|
+
}
|
|
1190
|
+
dispose() {
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
class SharedArrayReceiverStrategy {
|
|
1194
|
+
kind = "request";
|
|
1195
|
+
createCancellationTokenSource(request) {
|
|
1196
|
+
const buffer = request.$cancellationData;
|
|
1197
|
+
if (buffer === void 0) {
|
|
1198
|
+
return new cancellation_1.CancellationTokenSource();
|
|
1199
|
+
}
|
|
1200
|
+
return new SharedArrayBufferCancellationTokenSource(buffer);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
sharedArrayCancellation.SharedArrayReceiverStrategy = SharedArrayReceiverStrategy;
|
|
1204
|
+
return sharedArrayCancellation;
|
|
1205
|
+
}
|
|
1206
|
+
var messageReader = {};
|
|
1207
|
+
var semaphore = {};
|
|
1208
|
+
var hasRequiredSemaphore;
|
|
1209
|
+
function requireSemaphore() {
|
|
1210
|
+
if (hasRequiredSemaphore) return semaphore;
|
|
1211
|
+
hasRequiredSemaphore = 1;
|
|
1212
|
+
var __importDefault = semaphore && semaphore.__importDefault || function(mod) {
|
|
1213
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1214
|
+
};
|
|
1215
|
+
Object.defineProperty(semaphore, "__esModule", { value: true });
|
|
1216
|
+
semaphore.Semaphore = void 0;
|
|
1217
|
+
const ral_1 = __importDefault(requireRal());
|
|
1218
|
+
class Semaphore {
|
|
1219
|
+
_capacity;
|
|
1220
|
+
_active;
|
|
1221
|
+
_waiting;
|
|
1222
|
+
constructor(capacity = 1) {
|
|
1223
|
+
if (capacity <= 0) {
|
|
1224
|
+
throw new Error("Capacity must be greater than 0");
|
|
1225
|
+
}
|
|
1226
|
+
this._capacity = capacity;
|
|
1227
|
+
this._active = 0;
|
|
1228
|
+
this._waiting = [];
|
|
1229
|
+
}
|
|
1230
|
+
lock(thunk) {
|
|
1231
|
+
return new Promise((resolve2, reject) => {
|
|
1232
|
+
this._waiting.push({ thunk, resolve: resolve2, reject });
|
|
1233
|
+
this.runNext();
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
get active() {
|
|
1237
|
+
return this._active;
|
|
1238
|
+
}
|
|
1239
|
+
runNext() {
|
|
1240
|
+
if (this._waiting.length === 0 || this._active === this._capacity) {
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
(0, ral_1.default)().timer.setImmediate(() => this.doRunNext());
|
|
1244
|
+
}
|
|
1245
|
+
doRunNext() {
|
|
1246
|
+
if (this._waiting.length === 0 || this._active === this._capacity) {
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
const next = this._waiting.shift();
|
|
1250
|
+
this._active++;
|
|
1251
|
+
if (this._active > this._capacity) {
|
|
1252
|
+
throw new Error(`Too many thunks active`);
|
|
1253
|
+
}
|
|
1254
|
+
try {
|
|
1255
|
+
const result = next.thunk();
|
|
1256
|
+
if (result instanceof Promise) {
|
|
1257
|
+
result.then((value) => {
|
|
1258
|
+
this._active--;
|
|
1259
|
+
next.resolve(value);
|
|
1260
|
+
this.runNext();
|
|
1261
|
+
}, (err) => {
|
|
1262
|
+
this._active--;
|
|
1263
|
+
next.reject(err);
|
|
1264
|
+
this.runNext();
|
|
1265
|
+
});
|
|
1266
|
+
} else {
|
|
1267
|
+
this._active--;
|
|
1268
|
+
next.resolve(result);
|
|
1269
|
+
this.runNext();
|
|
1270
|
+
}
|
|
1271
|
+
} catch (err) {
|
|
1272
|
+
this._active--;
|
|
1273
|
+
next.reject(err);
|
|
1274
|
+
this.runNext();
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
semaphore.Semaphore = Semaphore;
|
|
1279
|
+
return semaphore;
|
|
1280
|
+
}
|
|
1281
|
+
var hasRequiredMessageReader;
|
|
1282
|
+
function requireMessageReader() {
|
|
1283
|
+
if (hasRequiredMessageReader) return messageReader;
|
|
1284
|
+
hasRequiredMessageReader = 1;
|
|
1285
|
+
var __createBinding = messageReader && messageReader.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1286
|
+
if (k2 === void 0) k2 = k;
|
|
1287
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1288
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1289
|
+
desc = { enumerable: true, get: function() {
|
|
1290
|
+
return m[k];
|
|
1291
|
+
} };
|
|
1292
|
+
}
|
|
1293
|
+
Object.defineProperty(o, k2, desc);
|
|
1294
|
+
}) : (function(o, m, k, k2) {
|
|
1295
|
+
if (k2 === void 0) k2 = k;
|
|
1296
|
+
o[k2] = m[k];
|
|
1297
|
+
}));
|
|
1298
|
+
var __setModuleDefault = messageReader && messageReader.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1299
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1300
|
+
}) : function(o, v) {
|
|
1301
|
+
o["default"] = v;
|
|
1302
|
+
});
|
|
1303
|
+
var __importStar = messageReader && messageReader.__importStar || /* @__PURE__ */ (function() {
|
|
1304
|
+
var ownKeys = function(o) {
|
|
1305
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1306
|
+
var ar = [];
|
|
1307
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1308
|
+
return ar;
|
|
1309
|
+
};
|
|
1310
|
+
return ownKeys(o);
|
|
1311
|
+
};
|
|
1312
|
+
return function(mod) {
|
|
1313
|
+
if (mod && mod.__esModule) return mod;
|
|
1314
|
+
var result = {};
|
|
1315
|
+
if (mod != null) {
|
|
1316
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1317
|
+
}
|
|
1318
|
+
__setModuleDefault(result, mod);
|
|
1319
|
+
return result;
|
|
1320
|
+
};
|
|
1321
|
+
})();
|
|
1322
|
+
var __importDefault = messageReader && messageReader.__importDefault || function(mod) {
|
|
1323
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1324
|
+
};
|
|
1325
|
+
Object.defineProperty(messageReader, "__esModule", { value: true });
|
|
1326
|
+
messageReader.ReadableStreamMessageReader = messageReader.AbstractMessageReader = messageReader.MessageReader = void 0;
|
|
1327
|
+
const ral_1 = __importDefault(requireRal());
|
|
1328
|
+
const Is = __importStar(requireIs());
|
|
1329
|
+
const events_1 = requireEvents();
|
|
1330
|
+
const semaphore_1 = requireSemaphore();
|
|
1331
|
+
var MessageReader;
|
|
1332
|
+
(function(MessageReader2) {
|
|
1333
|
+
function is2(value) {
|
|
1334
|
+
const candidate = value;
|
|
1335
|
+
return candidate && Is.func(candidate.listen) && Is.func(candidate.dispose) && Is.func(candidate.onError) && Is.func(candidate.onClose) && Is.func(candidate.onPartialMessage);
|
|
1336
|
+
}
|
|
1337
|
+
MessageReader2.is = is2;
|
|
1338
|
+
})(MessageReader || (messageReader.MessageReader = MessageReader = {}));
|
|
1339
|
+
class AbstractMessageReader {
|
|
1340
|
+
errorEmitter;
|
|
1341
|
+
closeEmitter;
|
|
1342
|
+
partialMessageEmitter;
|
|
1343
|
+
constructor() {
|
|
1344
|
+
this.errorEmitter = new events_1.Emitter();
|
|
1345
|
+
this.closeEmitter = new events_1.Emitter();
|
|
1346
|
+
this.partialMessageEmitter = new events_1.Emitter();
|
|
1347
|
+
}
|
|
1348
|
+
dispose() {
|
|
1349
|
+
this.errorEmitter.dispose();
|
|
1350
|
+
this.closeEmitter.dispose();
|
|
1351
|
+
this.partialMessageEmitter.dispose();
|
|
1352
|
+
}
|
|
1353
|
+
get onError() {
|
|
1354
|
+
return this.errorEmitter.event;
|
|
1355
|
+
}
|
|
1356
|
+
fireError(error) {
|
|
1357
|
+
this.errorEmitter.fire(this.asError(error));
|
|
1358
|
+
}
|
|
1359
|
+
get onClose() {
|
|
1360
|
+
return this.closeEmitter.event;
|
|
1361
|
+
}
|
|
1362
|
+
fireClose() {
|
|
1363
|
+
this.closeEmitter.fire(void 0);
|
|
1364
|
+
}
|
|
1365
|
+
get onPartialMessage() {
|
|
1366
|
+
return this.partialMessageEmitter.event;
|
|
1367
|
+
}
|
|
1368
|
+
firePartialMessage(info) {
|
|
1369
|
+
this.partialMessageEmitter.fire(info);
|
|
1370
|
+
}
|
|
1371
|
+
asError(error) {
|
|
1372
|
+
if (error instanceof Error) {
|
|
1373
|
+
return error;
|
|
1374
|
+
} else {
|
|
1375
|
+
return new Error(`Reader received error. Reason: ${Is.string(error.message) ? error.message : "unknown"}`);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
messageReader.AbstractMessageReader = AbstractMessageReader;
|
|
1380
|
+
var ResolvedMessageReaderOptions;
|
|
1381
|
+
(function(ResolvedMessageReaderOptions2) {
|
|
1382
|
+
function fromOptions(options) {
|
|
1383
|
+
let charset;
|
|
1384
|
+
let contentDecoder;
|
|
1385
|
+
const contentDecoders = /* @__PURE__ */ new Map();
|
|
1386
|
+
let contentTypeDecoder;
|
|
1387
|
+
const contentTypeDecoders = /* @__PURE__ */ new Map();
|
|
1388
|
+
if (options === void 0 || typeof options === "string") {
|
|
1389
|
+
charset = options ?? "utf-8";
|
|
1390
|
+
} else {
|
|
1391
|
+
charset = options.charset ?? "utf-8";
|
|
1392
|
+
if (options.contentDecoder !== void 0) {
|
|
1393
|
+
contentDecoder = options.contentDecoder;
|
|
1394
|
+
contentDecoders.set(contentDecoder.name, contentDecoder);
|
|
1395
|
+
}
|
|
1396
|
+
if (options.contentDecoders !== void 0) {
|
|
1397
|
+
for (const decoder of options.contentDecoders) {
|
|
1398
|
+
contentDecoders.set(decoder.name, decoder);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
if (options.contentTypeDecoder !== void 0) {
|
|
1402
|
+
contentTypeDecoder = options.contentTypeDecoder;
|
|
1403
|
+
contentTypeDecoders.set(contentTypeDecoder.name, contentTypeDecoder);
|
|
1404
|
+
}
|
|
1405
|
+
if (options.contentTypeDecoders !== void 0) {
|
|
1406
|
+
for (const decoder of options.contentTypeDecoders) {
|
|
1407
|
+
contentTypeDecoders.set(decoder.name, decoder);
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
if (contentTypeDecoder === void 0) {
|
|
1412
|
+
contentTypeDecoder = (0, ral_1.default)().applicationJson.decoder;
|
|
1413
|
+
contentTypeDecoders.set(contentTypeDecoder.name, contentTypeDecoder);
|
|
1414
|
+
}
|
|
1415
|
+
return { charset, contentDecoder, contentDecoders, contentTypeDecoder, contentTypeDecoders };
|
|
1416
|
+
}
|
|
1417
|
+
ResolvedMessageReaderOptions2.fromOptions = fromOptions;
|
|
1418
|
+
})(ResolvedMessageReaderOptions || (ResolvedMessageReaderOptions = {}));
|
|
1419
|
+
class ReadableStreamMessageReader extends AbstractMessageReader {
|
|
1420
|
+
readable;
|
|
1421
|
+
options;
|
|
1422
|
+
callback;
|
|
1423
|
+
nextMessageLength;
|
|
1424
|
+
messageToken;
|
|
1425
|
+
buffer;
|
|
1426
|
+
partialMessageTimer;
|
|
1427
|
+
_partialMessageTimeout;
|
|
1428
|
+
readSemaphore;
|
|
1429
|
+
constructor(readable, options) {
|
|
1430
|
+
super();
|
|
1431
|
+
this.readable = readable;
|
|
1432
|
+
this.options = ResolvedMessageReaderOptions.fromOptions(options);
|
|
1433
|
+
this.buffer = (0, ral_1.default)().messageBuffer.create(this.options.charset);
|
|
1434
|
+
this._partialMessageTimeout = 1e4;
|
|
1435
|
+
this.nextMessageLength = -1;
|
|
1436
|
+
this.messageToken = 0;
|
|
1437
|
+
this.readSemaphore = new semaphore_1.Semaphore(1);
|
|
1438
|
+
}
|
|
1439
|
+
set partialMessageTimeout(timeout) {
|
|
1440
|
+
this._partialMessageTimeout = timeout;
|
|
1441
|
+
}
|
|
1442
|
+
get partialMessageTimeout() {
|
|
1443
|
+
return this._partialMessageTimeout;
|
|
1444
|
+
}
|
|
1445
|
+
listen(callback) {
|
|
1446
|
+
this.nextMessageLength = -1;
|
|
1447
|
+
this.messageToken = 0;
|
|
1448
|
+
this.partialMessageTimer = void 0;
|
|
1449
|
+
this.callback = callback;
|
|
1450
|
+
const result = this.readable.onData((data) => {
|
|
1451
|
+
this.onData(data);
|
|
1452
|
+
});
|
|
1453
|
+
this.readable.onError((error) => this.fireError(error));
|
|
1454
|
+
this.readable.onClose(() => this.fireClose());
|
|
1455
|
+
return result;
|
|
1456
|
+
}
|
|
1457
|
+
onData(data) {
|
|
1458
|
+
try {
|
|
1459
|
+
this.buffer.append(data);
|
|
1460
|
+
while (true) {
|
|
1461
|
+
if (this.nextMessageLength === -1) {
|
|
1462
|
+
const headers = this.buffer.tryReadHeaders(true);
|
|
1463
|
+
if (!headers) {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
const contentLength = headers.get("content-length");
|
|
1467
|
+
if (!contentLength) {
|
|
1468
|
+
this.fireError(new Error(`Header must provide a Content-Length property.
|
|
1469
|
+
${JSON.stringify(Object.fromEntries(headers))}`));
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
const length = parseInt(contentLength);
|
|
1473
|
+
if (isNaN(length)) {
|
|
1474
|
+
this.fireError(new Error(`Content-Length value must be a number. Got ${contentLength}`));
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
this.nextMessageLength = length;
|
|
1478
|
+
}
|
|
1479
|
+
const body = this.buffer.tryReadBody(this.nextMessageLength);
|
|
1480
|
+
if (body === void 0) {
|
|
1481
|
+
this.setPartialMessageTimer();
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
this.clearPartialMessageTimer();
|
|
1485
|
+
this.nextMessageLength = -1;
|
|
1486
|
+
this.readSemaphore.lock(async () => {
|
|
1487
|
+
const bytes = this.options.contentDecoder !== void 0 ? await this.options.contentDecoder.decode(body) : body;
|
|
1488
|
+
const message = await this.options.contentTypeDecoder.decode(bytes, this.options);
|
|
1489
|
+
this.callback(message);
|
|
1490
|
+
}).catch((error) => {
|
|
1491
|
+
this.fireError(error);
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
} catch (error) {
|
|
1495
|
+
this.fireError(error);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
clearPartialMessageTimer() {
|
|
1499
|
+
if (this.partialMessageTimer) {
|
|
1500
|
+
this.partialMessageTimer.dispose();
|
|
1501
|
+
this.partialMessageTimer = void 0;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
setPartialMessageTimer() {
|
|
1505
|
+
this.clearPartialMessageTimer();
|
|
1506
|
+
if (this._partialMessageTimeout <= 0) {
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
this.partialMessageTimer = (0, ral_1.default)().timer.setTimeout((token, timeout) => {
|
|
1510
|
+
this.partialMessageTimer = void 0;
|
|
1511
|
+
if (token === this.messageToken) {
|
|
1512
|
+
this.firePartialMessage({ messageToken: token, waitingTime: timeout });
|
|
1513
|
+
this.setPartialMessageTimer();
|
|
1514
|
+
}
|
|
1515
|
+
}, this._partialMessageTimeout, this.messageToken, this._partialMessageTimeout);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
messageReader.ReadableStreamMessageReader = ReadableStreamMessageReader;
|
|
1519
|
+
return messageReader;
|
|
1520
|
+
}
|
|
1521
|
+
var messageWriter = {};
|
|
1522
|
+
var hasRequiredMessageWriter;
|
|
1523
|
+
function requireMessageWriter() {
|
|
1524
|
+
if (hasRequiredMessageWriter) return messageWriter;
|
|
1525
|
+
hasRequiredMessageWriter = 1;
|
|
1526
|
+
var __createBinding = messageWriter && messageWriter.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1527
|
+
if (k2 === void 0) k2 = k;
|
|
1528
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1529
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1530
|
+
desc = { enumerable: true, get: function() {
|
|
1531
|
+
return m[k];
|
|
1532
|
+
} };
|
|
1533
|
+
}
|
|
1534
|
+
Object.defineProperty(o, k2, desc);
|
|
1535
|
+
}) : (function(o, m, k, k2) {
|
|
1536
|
+
if (k2 === void 0) k2 = k;
|
|
1537
|
+
o[k2] = m[k];
|
|
1538
|
+
}));
|
|
1539
|
+
var __setModuleDefault = messageWriter && messageWriter.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1540
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1541
|
+
}) : function(o, v) {
|
|
1542
|
+
o["default"] = v;
|
|
1543
|
+
});
|
|
1544
|
+
var __importStar = messageWriter && messageWriter.__importStar || /* @__PURE__ */ (function() {
|
|
1545
|
+
var ownKeys = function(o) {
|
|
1546
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1547
|
+
var ar = [];
|
|
1548
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1549
|
+
return ar;
|
|
1550
|
+
};
|
|
1551
|
+
return ownKeys(o);
|
|
1552
|
+
};
|
|
1553
|
+
return function(mod) {
|
|
1554
|
+
if (mod && mod.__esModule) return mod;
|
|
1555
|
+
var result = {};
|
|
1556
|
+
if (mod != null) {
|
|
1557
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1558
|
+
}
|
|
1559
|
+
__setModuleDefault(result, mod);
|
|
1560
|
+
return result;
|
|
1561
|
+
};
|
|
1562
|
+
})();
|
|
1563
|
+
var __importDefault = messageWriter && messageWriter.__importDefault || function(mod) {
|
|
1564
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1565
|
+
};
|
|
1566
|
+
Object.defineProperty(messageWriter, "__esModule", { value: true });
|
|
1567
|
+
messageWriter.WriteableStreamMessageWriter = messageWriter.AbstractMessageWriter = messageWriter.MessageWriter = void 0;
|
|
1568
|
+
const ral_1 = __importDefault(requireRal());
|
|
1569
|
+
const Is = __importStar(requireIs());
|
|
1570
|
+
const semaphore_1 = requireSemaphore();
|
|
1571
|
+
const events_1 = requireEvents();
|
|
1572
|
+
const ContentLength = "Content-Length: ";
|
|
1573
|
+
const CRLF = "\r\n";
|
|
1574
|
+
var MessageWriter;
|
|
1575
|
+
(function(MessageWriter2) {
|
|
1576
|
+
function is2(value) {
|
|
1577
|
+
const candidate = value;
|
|
1578
|
+
return candidate && Is.func(candidate.dispose) && Is.func(candidate.onClose) && Is.func(candidate.onError) && Is.func(candidate.write);
|
|
1579
|
+
}
|
|
1580
|
+
MessageWriter2.is = is2;
|
|
1581
|
+
})(MessageWriter || (messageWriter.MessageWriter = MessageWriter = {}));
|
|
1582
|
+
class AbstractMessageWriter {
|
|
1583
|
+
errorEmitter;
|
|
1584
|
+
closeEmitter;
|
|
1585
|
+
constructor() {
|
|
1586
|
+
this.errorEmitter = new events_1.Emitter();
|
|
1587
|
+
this.closeEmitter = new events_1.Emitter();
|
|
1588
|
+
}
|
|
1589
|
+
dispose() {
|
|
1590
|
+
this.errorEmitter.dispose();
|
|
1591
|
+
this.closeEmitter.dispose();
|
|
1592
|
+
}
|
|
1593
|
+
get onError() {
|
|
1594
|
+
return this.errorEmitter.event;
|
|
1595
|
+
}
|
|
1596
|
+
fireError(error, message, count) {
|
|
1597
|
+
this.errorEmitter.fire([this.asError(error), message, count]);
|
|
1598
|
+
}
|
|
1599
|
+
get onClose() {
|
|
1600
|
+
return this.closeEmitter.event;
|
|
1601
|
+
}
|
|
1602
|
+
fireClose() {
|
|
1603
|
+
this.closeEmitter.fire(void 0);
|
|
1604
|
+
}
|
|
1605
|
+
asError(error) {
|
|
1606
|
+
if (error instanceof Error) {
|
|
1607
|
+
return error;
|
|
1608
|
+
} else {
|
|
1609
|
+
return new Error(`Writer received error. Reason: ${Is.string(error.message) ? error.message : "unknown"}`);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
messageWriter.AbstractMessageWriter = AbstractMessageWriter;
|
|
1614
|
+
var ResolvedMessageWriterOptions;
|
|
1615
|
+
(function(ResolvedMessageWriterOptions2) {
|
|
1616
|
+
function fromOptions(options) {
|
|
1617
|
+
if (options === void 0 || typeof options === "string") {
|
|
1618
|
+
return { charset: options ?? "utf-8", contentTypeEncoder: (0, ral_1.default)().applicationJson.encoder };
|
|
1619
|
+
} else {
|
|
1620
|
+
return { charset: options.charset ?? "utf-8", contentEncoder: options.contentEncoder, contentTypeEncoder: options.contentTypeEncoder ?? (0, ral_1.default)().applicationJson.encoder };
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
ResolvedMessageWriterOptions2.fromOptions = fromOptions;
|
|
1624
|
+
})(ResolvedMessageWriterOptions || (ResolvedMessageWriterOptions = {}));
|
|
1625
|
+
class WriteableStreamMessageWriter extends AbstractMessageWriter {
|
|
1626
|
+
writable;
|
|
1627
|
+
options;
|
|
1628
|
+
errorCount;
|
|
1629
|
+
writeSemaphore;
|
|
1630
|
+
constructor(writable, options) {
|
|
1631
|
+
super();
|
|
1632
|
+
this.writable = writable;
|
|
1633
|
+
this.options = ResolvedMessageWriterOptions.fromOptions(options);
|
|
1634
|
+
this.errorCount = 0;
|
|
1635
|
+
this.writeSemaphore = new semaphore_1.Semaphore(1);
|
|
1636
|
+
this.writable.onError((error) => this.fireError(error));
|
|
1637
|
+
this.writable.onClose(() => this.fireClose());
|
|
1638
|
+
}
|
|
1639
|
+
async write(msg) {
|
|
1640
|
+
return this.writeSemaphore.lock(async () => {
|
|
1641
|
+
const payload = this.options.contentTypeEncoder.encode(msg, this.options).then((buffer) => {
|
|
1642
|
+
if (this.options.contentEncoder !== void 0) {
|
|
1643
|
+
return this.options.contentEncoder.encode(buffer);
|
|
1644
|
+
} else {
|
|
1645
|
+
return buffer;
|
|
1646
|
+
}
|
|
1647
|
+
});
|
|
1648
|
+
return payload.then((buffer) => {
|
|
1649
|
+
const headers = [];
|
|
1650
|
+
headers.push(ContentLength, buffer.byteLength.toString(), CRLF);
|
|
1651
|
+
headers.push(CRLF);
|
|
1652
|
+
return this.doWrite(msg, headers, buffer);
|
|
1653
|
+
}, (error) => {
|
|
1654
|
+
this.fireError(error);
|
|
1655
|
+
throw error;
|
|
1656
|
+
});
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
async doWrite(msg, headers, data) {
|
|
1660
|
+
try {
|
|
1661
|
+
await this.writable.write(headers.join(""), "ascii");
|
|
1662
|
+
return this.writable.write(data);
|
|
1663
|
+
} catch (error) {
|
|
1664
|
+
this.handleError(error, msg);
|
|
1665
|
+
return Promise.reject(error);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
handleError(error, msg) {
|
|
1669
|
+
this.errorCount++;
|
|
1670
|
+
this.fireError(error, msg, this.errorCount);
|
|
1671
|
+
}
|
|
1672
|
+
end() {
|
|
1673
|
+
this.writable.end();
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
messageWriter.WriteableStreamMessageWriter = WriteableStreamMessageWriter;
|
|
1677
|
+
return messageWriter;
|
|
1678
|
+
}
|
|
1679
|
+
var messageBuffer = {};
|
|
1680
|
+
var hasRequiredMessageBuffer;
|
|
1681
|
+
function requireMessageBuffer() {
|
|
1682
|
+
if (hasRequiredMessageBuffer) return messageBuffer;
|
|
1683
|
+
hasRequiredMessageBuffer = 1;
|
|
1684
|
+
Object.defineProperty(messageBuffer, "__esModule", { value: true });
|
|
1685
|
+
messageBuffer.AbstractMessageBuffer = void 0;
|
|
1686
|
+
const CR = 13;
|
|
1687
|
+
const LF = 10;
|
|
1688
|
+
const CRLF = "\r\n";
|
|
1689
|
+
class AbstractMessageBuffer {
|
|
1690
|
+
_encoding;
|
|
1691
|
+
_chunks;
|
|
1692
|
+
_totalLength;
|
|
1693
|
+
constructor(encoding = "utf-8") {
|
|
1694
|
+
this._encoding = encoding;
|
|
1695
|
+
this._chunks = [];
|
|
1696
|
+
this._totalLength = 0;
|
|
1697
|
+
}
|
|
1698
|
+
get encoding() {
|
|
1699
|
+
return this._encoding;
|
|
1700
|
+
}
|
|
1701
|
+
append(chunk) {
|
|
1702
|
+
const toAppend = typeof chunk === "string" ? this.fromString(chunk, this._encoding) : chunk;
|
|
1703
|
+
this._chunks.push(toAppend);
|
|
1704
|
+
this._totalLength += toAppend.byteLength;
|
|
1705
|
+
}
|
|
1706
|
+
tryReadHeaders(lowerCaseKeys = false) {
|
|
1707
|
+
if (this._chunks.length === 0) {
|
|
1708
|
+
return void 0;
|
|
1709
|
+
}
|
|
1710
|
+
let state = 0;
|
|
1711
|
+
let chunkIndex = 0;
|
|
1712
|
+
let offset = 0;
|
|
1713
|
+
let chunkBytesRead = 0;
|
|
1714
|
+
row: while (chunkIndex < this._chunks.length) {
|
|
1715
|
+
const chunk = this._chunks[chunkIndex];
|
|
1716
|
+
offset = 0;
|
|
1717
|
+
while (offset < chunk.length) {
|
|
1718
|
+
const value = chunk[offset];
|
|
1719
|
+
switch (value) {
|
|
1720
|
+
case CR:
|
|
1721
|
+
switch (state) {
|
|
1722
|
+
case 0:
|
|
1723
|
+
state = 1;
|
|
1724
|
+
break;
|
|
1725
|
+
case 2:
|
|
1726
|
+
state = 3;
|
|
1727
|
+
break;
|
|
1728
|
+
default:
|
|
1729
|
+
state = 0;
|
|
1730
|
+
}
|
|
1731
|
+
break;
|
|
1732
|
+
case LF:
|
|
1733
|
+
switch (state) {
|
|
1734
|
+
case 1:
|
|
1735
|
+
state = 2;
|
|
1736
|
+
break;
|
|
1737
|
+
case 3:
|
|
1738
|
+
state = 4;
|
|
1739
|
+
offset++;
|
|
1740
|
+
break row;
|
|
1741
|
+
default:
|
|
1742
|
+
state = 0;
|
|
1743
|
+
}
|
|
1744
|
+
break;
|
|
1745
|
+
default:
|
|
1746
|
+
state = 0;
|
|
1747
|
+
}
|
|
1748
|
+
offset++;
|
|
1749
|
+
}
|
|
1750
|
+
chunkBytesRead += chunk.byteLength;
|
|
1751
|
+
chunkIndex++;
|
|
1752
|
+
}
|
|
1753
|
+
if (state !== 4) {
|
|
1754
|
+
return void 0;
|
|
1755
|
+
}
|
|
1756
|
+
const buffer = this._read(chunkBytesRead + offset);
|
|
1757
|
+
const result = /* @__PURE__ */ new Map();
|
|
1758
|
+
const headers = this.toString(buffer, "ascii").split(CRLF);
|
|
1759
|
+
if (headers.length < 2) {
|
|
1760
|
+
return result;
|
|
1761
|
+
}
|
|
1762
|
+
for (let i = 0; i < headers.length - 2; i++) {
|
|
1763
|
+
const header = headers[i];
|
|
1764
|
+
const index = header.indexOf(":");
|
|
1765
|
+
if (index === -1) {
|
|
1766
|
+
throw new Error(`Message header must separate key and value using ':'
|
|
1767
|
+
${header}`);
|
|
1768
|
+
}
|
|
1769
|
+
const key = header.substr(0, index);
|
|
1770
|
+
const value = header.substr(index + 1).trim();
|
|
1771
|
+
result.set(lowerCaseKeys ? key.toLowerCase() : key, value);
|
|
1772
|
+
}
|
|
1773
|
+
return result;
|
|
1774
|
+
}
|
|
1775
|
+
tryReadBody(length) {
|
|
1776
|
+
if (this._totalLength < length) {
|
|
1777
|
+
return void 0;
|
|
1778
|
+
}
|
|
1779
|
+
return this._read(length);
|
|
1780
|
+
}
|
|
1781
|
+
get numberOfBytes() {
|
|
1782
|
+
return this._totalLength;
|
|
1783
|
+
}
|
|
1784
|
+
_read(byteCount) {
|
|
1785
|
+
if (byteCount === 0) {
|
|
1786
|
+
return this.emptyBuffer();
|
|
1787
|
+
}
|
|
1788
|
+
if (byteCount > this._totalLength) {
|
|
1789
|
+
throw new Error(`Cannot read so many bytes!`);
|
|
1790
|
+
}
|
|
1791
|
+
if (this._chunks[0].byteLength === byteCount) {
|
|
1792
|
+
const chunk = this._chunks[0];
|
|
1793
|
+
this._chunks.shift();
|
|
1794
|
+
this._totalLength -= byteCount;
|
|
1795
|
+
return this.asNative(chunk);
|
|
1796
|
+
}
|
|
1797
|
+
if (this._chunks[0].byteLength > byteCount) {
|
|
1798
|
+
const chunk = this._chunks[0];
|
|
1799
|
+
const result2 = this.asNative(chunk, byteCount);
|
|
1800
|
+
this._chunks[0] = chunk.slice(byteCount);
|
|
1801
|
+
this._totalLength -= byteCount;
|
|
1802
|
+
return result2;
|
|
1803
|
+
}
|
|
1804
|
+
const result = this.allocNative(byteCount);
|
|
1805
|
+
let resultOffset = 0;
|
|
1806
|
+
const chunkIndex = 0;
|
|
1807
|
+
while (byteCount > 0) {
|
|
1808
|
+
const chunk = this._chunks[chunkIndex];
|
|
1809
|
+
if (chunk.byteLength > byteCount) {
|
|
1810
|
+
const chunkPart = chunk.slice(0, byteCount);
|
|
1811
|
+
result.set(chunkPart, resultOffset);
|
|
1812
|
+
resultOffset += byteCount;
|
|
1813
|
+
this._chunks[chunkIndex] = chunk.slice(byteCount);
|
|
1814
|
+
this._totalLength -= byteCount;
|
|
1815
|
+
byteCount -= byteCount;
|
|
1816
|
+
} else {
|
|
1817
|
+
result.set(chunk, resultOffset);
|
|
1818
|
+
resultOffset += chunk.byteLength;
|
|
1819
|
+
this._chunks.shift();
|
|
1820
|
+
this._totalLength -= chunk.byteLength;
|
|
1821
|
+
byteCount -= chunk.byteLength;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
return result;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
messageBuffer.AbstractMessageBuffer = AbstractMessageBuffer;
|
|
1828
|
+
return messageBuffer;
|
|
1829
|
+
}
|
|
1830
|
+
var connection = {};
|
|
1831
|
+
var hasRequiredConnection;
|
|
1832
|
+
function requireConnection() {
|
|
1833
|
+
if (hasRequiredConnection) return connection;
|
|
1834
|
+
hasRequiredConnection = 1;
|
|
1835
|
+
(function(exports) {
|
|
1836
|
+
var __createBinding = connection && connection.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1837
|
+
if (k2 === void 0) k2 = k;
|
|
1838
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1839
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1840
|
+
desc = { enumerable: true, get: function() {
|
|
1841
|
+
return m[k];
|
|
1842
|
+
} };
|
|
1843
|
+
}
|
|
1844
|
+
Object.defineProperty(o, k2, desc);
|
|
1845
|
+
}) : (function(o, m, k, k2) {
|
|
1846
|
+
if (k2 === void 0) k2 = k;
|
|
1847
|
+
o[k2] = m[k];
|
|
1848
|
+
}));
|
|
1849
|
+
var __setModuleDefault = connection && connection.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1850
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1851
|
+
}) : function(o, v) {
|
|
1852
|
+
o["default"] = v;
|
|
1853
|
+
});
|
|
1854
|
+
var __importStar = connection && connection.__importStar || /* @__PURE__ */ (function() {
|
|
1855
|
+
var ownKeys = function(o) {
|
|
1856
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1857
|
+
var ar = [];
|
|
1858
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1859
|
+
return ar;
|
|
1860
|
+
};
|
|
1861
|
+
return ownKeys(o);
|
|
1862
|
+
};
|
|
1863
|
+
return function(mod) {
|
|
1864
|
+
if (mod && mod.__esModule) return mod;
|
|
1865
|
+
var result = {};
|
|
1866
|
+
if (mod != null) {
|
|
1867
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1868
|
+
}
|
|
1869
|
+
__setModuleDefault(result, mod);
|
|
1870
|
+
return result;
|
|
1871
|
+
};
|
|
1872
|
+
})();
|
|
1873
|
+
var __importDefault = connection && connection.__importDefault || function(mod) {
|
|
1874
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1875
|
+
};
|
|
1876
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1877
|
+
exports.ConnectionOptions = exports.MessageStrategy = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.RequestCancellationReceiverStrategy = exports.IdCancellationReceiverStrategy = exports.ConnectionStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = exports.TraceValues = exports.TraceValue = exports.Trace = exports.NullLogger = exports.ProgressType = exports.ProgressToken = void 0;
|
|
1878
|
+
exports.createMessageConnection = createMessageConnection;
|
|
1879
|
+
const ral_1 = __importDefault(requireRal());
|
|
1880
|
+
const Is = __importStar(requireIs());
|
|
1881
|
+
const messages_1 = requireMessages();
|
|
1882
|
+
const linkedMap_1 = requireLinkedMap();
|
|
1883
|
+
const events_1 = requireEvents();
|
|
1884
|
+
const cancellation_1 = requireCancellation();
|
|
1885
|
+
var CancelNotification;
|
|
1886
|
+
(function(CancelNotification2) {
|
|
1887
|
+
CancelNotification2.type = new messages_1.NotificationType("$/cancelRequest");
|
|
1888
|
+
})(CancelNotification || (CancelNotification = {}));
|
|
1889
|
+
var ProgressToken;
|
|
1890
|
+
(function(ProgressToken2) {
|
|
1891
|
+
function is2(value) {
|
|
1892
|
+
return typeof value === "string" || typeof value === "number";
|
|
1893
|
+
}
|
|
1894
|
+
ProgressToken2.is = is2;
|
|
1895
|
+
})(ProgressToken || (exports.ProgressToken = ProgressToken = {}));
|
|
1896
|
+
var ProgressNotification;
|
|
1897
|
+
(function(ProgressNotification2) {
|
|
1898
|
+
ProgressNotification2.type = new messages_1.NotificationType("$/progress");
|
|
1899
|
+
})(ProgressNotification || (ProgressNotification = {}));
|
|
1900
|
+
class ProgressType {
|
|
1901
|
+
/**
|
|
1902
|
+
* Clients must not use these properties. They are here to ensure correct typing.
|
|
1903
|
+
* in TypeScript
|
|
1904
|
+
*/
|
|
1905
|
+
__;
|
|
1906
|
+
_pr;
|
|
1907
|
+
constructor() {
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
exports.ProgressType = ProgressType;
|
|
1911
|
+
var StarRequestHandler;
|
|
1912
|
+
(function(StarRequestHandler2) {
|
|
1913
|
+
function is2(value) {
|
|
1914
|
+
return Is.func(value);
|
|
1915
|
+
}
|
|
1916
|
+
StarRequestHandler2.is = is2;
|
|
1917
|
+
})(StarRequestHandler || (StarRequestHandler = {}));
|
|
1918
|
+
exports.NullLogger = Object.freeze({
|
|
1919
|
+
error: () => {
|
|
1920
|
+
},
|
|
1921
|
+
warn: () => {
|
|
1922
|
+
},
|
|
1923
|
+
info: () => {
|
|
1924
|
+
},
|
|
1925
|
+
log: () => {
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
var Trace;
|
|
1929
|
+
(function(Trace2) {
|
|
1930
|
+
Trace2[Trace2["Off"] = 0] = "Off";
|
|
1931
|
+
Trace2[Trace2["Messages"] = 1] = "Messages";
|
|
1932
|
+
Trace2[Trace2["Compact"] = 2] = "Compact";
|
|
1933
|
+
Trace2[Trace2["Verbose"] = 3] = "Verbose";
|
|
1934
|
+
})(Trace || (exports.Trace = Trace = {}));
|
|
1935
|
+
var TraceValue;
|
|
1936
|
+
(function(TraceValue2) {
|
|
1937
|
+
TraceValue2.Off = "off";
|
|
1938
|
+
TraceValue2.Messages = "messages";
|
|
1939
|
+
TraceValue2.Compact = "compact";
|
|
1940
|
+
TraceValue2.Verbose = "verbose";
|
|
1941
|
+
})(TraceValue || (exports.TraceValue = TraceValue = {}));
|
|
1942
|
+
exports.TraceValues = TraceValue;
|
|
1943
|
+
(function(Trace2) {
|
|
1944
|
+
function fromString(value) {
|
|
1945
|
+
if (!Is.string(value)) {
|
|
1946
|
+
return Trace2.Off;
|
|
1947
|
+
}
|
|
1948
|
+
value = value.toLowerCase();
|
|
1949
|
+
switch (value) {
|
|
1950
|
+
case "off":
|
|
1951
|
+
return Trace2.Off;
|
|
1952
|
+
case "messages":
|
|
1953
|
+
return Trace2.Messages;
|
|
1954
|
+
case "compact":
|
|
1955
|
+
return Trace2.Compact;
|
|
1956
|
+
case "verbose":
|
|
1957
|
+
return Trace2.Verbose;
|
|
1958
|
+
default:
|
|
1959
|
+
return Trace2.Off;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
Trace2.fromString = fromString;
|
|
1963
|
+
function toString(value) {
|
|
1964
|
+
switch (value) {
|
|
1965
|
+
case Trace2.Off:
|
|
1966
|
+
return "off";
|
|
1967
|
+
case Trace2.Messages:
|
|
1968
|
+
return "messages";
|
|
1969
|
+
case Trace2.Compact:
|
|
1970
|
+
return "compact";
|
|
1971
|
+
case Trace2.Verbose:
|
|
1972
|
+
return "verbose";
|
|
1973
|
+
default:
|
|
1974
|
+
return "off";
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
Trace2.toString = toString;
|
|
1978
|
+
})(Trace || (exports.Trace = Trace = {}));
|
|
1979
|
+
var TraceFormat;
|
|
1980
|
+
(function(TraceFormat2) {
|
|
1981
|
+
TraceFormat2["Text"] = "text";
|
|
1982
|
+
TraceFormat2["JSON"] = "json";
|
|
1983
|
+
})(TraceFormat || (exports.TraceFormat = TraceFormat = {}));
|
|
1984
|
+
(function(TraceFormat2) {
|
|
1985
|
+
function fromString(value) {
|
|
1986
|
+
if (!Is.string(value)) {
|
|
1987
|
+
return TraceFormat2.Text;
|
|
1988
|
+
}
|
|
1989
|
+
value = value.toLowerCase();
|
|
1990
|
+
if (value === "json") {
|
|
1991
|
+
return TraceFormat2.JSON;
|
|
1992
|
+
} else {
|
|
1993
|
+
return TraceFormat2.Text;
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
TraceFormat2.fromString = fromString;
|
|
1997
|
+
})(TraceFormat || (exports.TraceFormat = TraceFormat = {}));
|
|
1998
|
+
var SetTraceNotification;
|
|
1999
|
+
(function(SetTraceNotification2) {
|
|
2000
|
+
SetTraceNotification2.type = new messages_1.NotificationType("$/setTrace");
|
|
2001
|
+
})(SetTraceNotification || (exports.SetTraceNotification = SetTraceNotification = {}));
|
|
2002
|
+
var LogTraceNotification;
|
|
2003
|
+
(function(LogTraceNotification2) {
|
|
2004
|
+
LogTraceNotification2.type = new messages_1.NotificationType("$/logTrace");
|
|
2005
|
+
})(LogTraceNotification || (exports.LogTraceNotification = LogTraceNotification = {}));
|
|
2006
|
+
var ConnectionErrors;
|
|
2007
|
+
(function(ConnectionErrors2) {
|
|
2008
|
+
ConnectionErrors2[ConnectionErrors2["Closed"] = 1] = "Closed";
|
|
2009
|
+
ConnectionErrors2[ConnectionErrors2["Disposed"] = 2] = "Disposed";
|
|
2010
|
+
ConnectionErrors2[ConnectionErrors2["AlreadyListening"] = 3] = "AlreadyListening";
|
|
2011
|
+
})(ConnectionErrors || (exports.ConnectionErrors = ConnectionErrors = {}));
|
|
2012
|
+
class ConnectionError extends Error {
|
|
2013
|
+
code;
|
|
2014
|
+
constructor(code, message) {
|
|
2015
|
+
super(message);
|
|
2016
|
+
this.code = code;
|
|
2017
|
+
Object.setPrototypeOf(this, ConnectionError.prototype);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
exports.ConnectionError = ConnectionError;
|
|
2021
|
+
var ConnectionStrategy;
|
|
2022
|
+
(function(ConnectionStrategy2) {
|
|
2023
|
+
function is2(value) {
|
|
2024
|
+
const candidate = value;
|
|
2025
|
+
return candidate && Is.func(candidate.cancelUndispatched);
|
|
2026
|
+
}
|
|
2027
|
+
ConnectionStrategy2.is = is2;
|
|
2028
|
+
})(ConnectionStrategy || (exports.ConnectionStrategy = ConnectionStrategy = {}));
|
|
2029
|
+
var IdCancellationReceiverStrategy;
|
|
2030
|
+
(function(IdCancellationReceiverStrategy2) {
|
|
2031
|
+
function is2(value) {
|
|
2032
|
+
const candidate = value;
|
|
2033
|
+
return candidate && (candidate.kind === void 0 || candidate.kind === "id") && Is.func(candidate.createCancellationTokenSource) && (candidate.dispose === void 0 || Is.func(candidate.dispose));
|
|
2034
|
+
}
|
|
2035
|
+
IdCancellationReceiverStrategy2.is = is2;
|
|
2036
|
+
})(IdCancellationReceiverStrategy || (exports.IdCancellationReceiverStrategy = IdCancellationReceiverStrategy = {}));
|
|
2037
|
+
var RequestCancellationReceiverStrategy;
|
|
2038
|
+
(function(RequestCancellationReceiverStrategy2) {
|
|
2039
|
+
function is2(value) {
|
|
2040
|
+
const candidate = value;
|
|
2041
|
+
return candidate && candidate.kind === "request" && Is.func(candidate.createCancellationTokenSource) && (candidate.dispose === void 0 || Is.func(candidate.dispose));
|
|
2042
|
+
}
|
|
2043
|
+
RequestCancellationReceiverStrategy2.is = is2;
|
|
2044
|
+
})(RequestCancellationReceiverStrategy || (exports.RequestCancellationReceiverStrategy = RequestCancellationReceiverStrategy = {}));
|
|
2045
|
+
var CancellationReceiverStrategy;
|
|
2046
|
+
(function(CancellationReceiverStrategy2) {
|
|
2047
|
+
CancellationReceiverStrategy2.Message = Object.freeze({
|
|
2048
|
+
createCancellationTokenSource(_) {
|
|
2049
|
+
return new cancellation_1.CancellationTokenSource();
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
2052
|
+
function is2(value) {
|
|
2053
|
+
return IdCancellationReceiverStrategy.is(value) || RequestCancellationReceiverStrategy.is(value);
|
|
2054
|
+
}
|
|
2055
|
+
CancellationReceiverStrategy2.is = is2;
|
|
2056
|
+
})(CancellationReceiverStrategy || (exports.CancellationReceiverStrategy = CancellationReceiverStrategy = {}));
|
|
2057
|
+
var CancellationSenderStrategy;
|
|
2058
|
+
(function(CancellationSenderStrategy2) {
|
|
2059
|
+
CancellationSenderStrategy2.Message = Object.freeze({
|
|
2060
|
+
sendCancellation(conn, id) {
|
|
2061
|
+
return conn.sendNotification(CancelNotification.type, { id });
|
|
2062
|
+
},
|
|
2063
|
+
cleanup(_) {
|
|
2064
|
+
}
|
|
2065
|
+
});
|
|
2066
|
+
function is2(value) {
|
|
2067
|
+
const candidate = value;
|
|
2068
|
+
return candidate && Is.func(candidate.sendCancellation) && Is.func(candidate.cleanup);
|
|
2069
|
+
}
|
|
2070
|
+
CancellationSenderStrategy2.is = is2;
|
|
2071
|
+
})(CancellationSenderStrategy || (exports.CancellationSenderStrategy = CancellationSenderStrategy = {}));
|
|
2072
|
+
var CancellationStrategy;
|
|
2073
|
+
(function(CancellationStrategy2) {
|
|
2074
|
+
CancellationStrategy2.Message = Object.freeze({
|
|
2075
|
+
receiver: CancellationReceiverStrategy.Message,
|
|
2076
|
+
sender: CancellationSenderStrategy.Message
|
|
2077
|
+
});
|
|
2078
|
+
function is2(value) {
|
|
2079
|
+
const candidate = value;
|
|
2080
|
+
return candidate && CancellationReceiverStrategy.is(candidate.receiver) && CancellationSenderStrategy.is(candidate.sender);
|
|
2081
|
+
}
|
|
2082
|
+
CancellationStrategy2.is = is2;
|
|
2083
|
+
})(CancellationStrategy || (exports.CancellationStrategy = CancellationStrategy = {}));
|
|
2084
|
+
var MessageStrategy;
|
|
2085
|
+
(function(MessageStrategy2) {
|
|
2086
|
+
function is2(value) {
|
|
2087
|
+
const candidate = value;
|
|
2088
|
+
return candidate && Is.func(candidate.handleMessage);
|
|
2089
|
+
}
|
|
2090
|
+
MessageStrategy2.is = is2;
|
|
2091
|
+
})(MessageStrategy || (exports.MessageStrategy = MessageStrategy = {}));
|
|
2092
|
+
var ConnectionOptions;
|
|
2093
|
+
(function(ConnectionOptions2) {
|
|
2094
|
+
function is2(value) {
|
|
2095
|
+
const candidate = value;
|
|
2096
|
+
return candidate && (CancellationStrategy.is(candidate.cancellationStrategy) || ConnectionStrategy.is(candidate.connectionStrategy) || MessageStrategy.is(candidate.messageStrategy) || Is.number(candidate.maxParallelism));
|
|
2097
|
+
}
|
|
2098
|
+
ConnectionOptions2.is = is2;
|
|
2099
|
+
})(ConnectionOptions || (exports.ConnectionOptions = ConnectionOptions = {}));
|
|
2100
|
+
var ConnectionState;
|
|
2101
|
+
(function(ConnectionState2) {
|
|
2102
|
+
ConnectionState2[ConnectionState2["New"] = 1] = "New";
|
|
2103
|
+
ConnectionState2[ConnectionState2["Listening"] = 2] = "Listening";
|
|
2104
|
+
ConnectionState2[ConnectionState2["Closed"] = 3] = "Closed";
|
|
2105
|
+
ConnectionState2[ConnectionState2["Disposed"] = 4] = "Disposed";
|
|
2106
|
+
})(ConnectionState || (ConnectionState = {}));
|
|
2107
|
+
function createMessageConnection(messageReader2, messageWriter2, _logger, options) {
|
|
2108
|
+
const logger = _logger !== void 0 ? _logger : exports.NullLogger;
|
|
2109
|
+
let sequenceNumber = 0;
|
|
2110
|
+
let notificationSequenceNumber = 0;
|
|
2111
|
+
let unknownResponseSequenceNumber = 0;
|
|
2112
|
+
const version = "2.0";
|
|
2113
|
+
const maxParallelism = options?.maxParallelism ?? -1;
|
|
2114
|
+
let inFlight = 0;
|
|
2115
|
+
let starRequestHandler = void 0;
|
|
2116
|
+
const requestHandlers = /* @__PURE__ */ new Map();
|
|
2117
|
+
let starNotificationHandler = void 0;
|
|
2118
|
+
const notificationHandlers = /* @__PURE__ */ new Map();
|
|
2119
|
+
const progressHandlers = /* @__PURE__ */ new Map();
|
|
2120
|
+
let timer;
|
|
2121
|
+
let messageQueue = new linkedMap_1.LinkedMap();
|
|
2122
|
+
let responsePromises = /* @__PURE__ */ new Map();
|
|
2123
|
+
let knownCanceledRequests = /* @__PURE__ */ new Set();
|
|
2124
|
+
let requestTokens = /* @__PURE__ */ new Map();
|
|
2125
|
+
let trace = Trace.Off;
|
|
2126
|
+
let traceFormat = TraceFormat.Text;
|
|
2127
|
+
let tracer;
|
|
2128
|
+
let state = ConnectionState.New;
|
|
2129
|
+
const errorEmitter = new events_1.Emitter();
|
|
2130
|
+
const closeEmitter = new events_1.Emitter();
|
|
2131
|
+
const unhandledNotificationEmitter = new events_1.Emitter();
|
|
2132
|
+
const unhandledProgressEmitter = new events_1.Emitter();
|
|
2133
|
+
const disposeEmitter = new events_1.Emitter();
|
|
2134
|
+
const cancellationStrategy = options && options.cancellationStrategy ? options.cancellationStrategy : CancellationStrategy.Message;
|
|
2135
|
+
function cancelUndispatched(_message) {
|
|
2136
|
+
return void 0;
|
|
2137
|
+
}
|
|
2138
|
+
function isListening() {
|
|
2139
|
+
return state === ConnectionState.Listening;
|
|
2140
|
+
}
|
|
2141
|
+
function isClosed() {
|
|
2142
|
+
return state === ConnectionState.Closed;
|
|
2143
|
+
}
|
|
2144
|
+
function isDisposed() {
|
|
2145
|
+
return state === ConnectionState.Disposed;
|
|
2146
|
+
}
|
|
2147
|
+
function closeHandler() {
|
|
2148
|
+
if (state === ConnectionState.New || state === ConnectionState.Listening) {
|
|
2149
|
+
state = ConnectionState.Closed;
|
|
2150
|
+
closeEmitter.fire(void 0);
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
function readErrorHandler(error) {
|
|
2154
|
+
errorEmitter.fire([error, void 0, void 0]);
|
|
2155
|
+
}
|
|
2156
|
+
function writeErrorHandler(data) {
|
|
2157
|
+
errorEmitter.fire(data);
|
|
2158
|
+
}
|
|
2159
|
+
messageReader2.onClose(closeHandler);
|
|
2160
|
+
messageReader2.onError(readErrorHandler);
|
|
2161
|
+
messageWriter2.onClose(closeHandler);
|
|
2162
|
+
messageWriter2.onError(writeErrorHandler);
|
|
2163
|
+
function createRequestQueueKey(id) {
|
|
2164
|
+
if (id === null) {
|
|
2165
|
+
throw new Error(`Can't send requests with id null since the response can't be correlated.`);
|
|
2166
|
+
}
|
|
2167
|
+
return "req-" + id.toString();
|
|
2168
|
+
}
|
|
2169
|
+
function createResponseQueueKey(id) {
|
|
2170
|
+
if (id === null) {
|
|
2171
|
+
return "res-unknown-" + (++unknownResponseSequenceNumber).toString();
|
|
2172
|
+
} else {
|
|
2173
|
+
return "res-" + id.toString();
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
function createNotificationQueueKey() {
|
|
2177
|
+
return "not-" + (++notificationSequenceNumber).toString();
|
|
2178
|
+
}
|
|
2179
|
+
function addMessageToQueue(queue, message) {
|
|
2180
|
+
if (messages_1.Message.isRequest(message)) {
|
|
2181
|
+
queue.set(createRequestQueueKey(message.id), message);
|
|
2182
|
+
} else if (messages_1.Message.isResponse(message)) {
|
|
2183
|
+
if (maxParallelism === -1) {
|
|
2184
|
+
queue.set(createResponseQueueKey(message.id), message);
|
|
2185
|
+
} else {
|
|
2186
|
+
handleResponse(message);
|
|
2187
|
+
}
|
|
2188
|
+
} else {
|
|
2189
|
+
queue.set(createNotificationQueueKey(), message);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
function triggerMessageQueue() {
|
|
2193
|
+
if (timer || messageQueue.size === 0) {
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
if (maxParallelism !== -1 && inFlight >= maxParallelism) {
|
|
2197
|
+
return;
|
|
2198
|
+
}
|
|
2199
|
+
timer = (0, ral_1.default)().timer.setImmediate(async () => {
|
|
2200
|
+
timer = void 0;
|
|
2201
|
+
if (messageQueue.size === 0) {
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
if (maxParallelism !== -1 && inFlight >= maxParallelism) {
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
2207
|
+
const message = messageQueue.shift();
|
|
2208
|
+
let result;
|
|
2209
|
+
try {
|
|
2210
|
+
inFlight++;
|
|
2211
|
+
const messageStrategy = options?.messageStrategy;
|
|
2212
|
+
if (MessageStrategy.is(messageStrategy)) {
|
|
2213
|
+
result = messageStrategy.handleMessage(message, handleMessage);
|
|
2214
|
+
} else {
|
|
2215
|
+
result = handleMessage(message);
|
|
2216
|
+
}
|
|
2217
|
+
} catch (error) {
|
|
2218
|
+
logger.error(`Processing message queue failed: ${error.toString()}`);
|
|
2219
|
+
} finally {
|
|
2220
|
+
if (result instanceof Promise) {
|
|
2221
|
+
result.then(() => {
|
|
2222
|
+
inFlight--;
|
|
2223
|
+
triggerMessageQueue();
|
|
2224
|
+
}).catch((error) => {
|
|
2225
|
+
logger.error(`Processing message queue failed: ${error.toString()}`);
|
|
2226
|
+
});
|
|
2227
|
+
} else {
|
|
2228
|
+
inFlight--;
|
|
2229
|
+
}
|
|
2230
|
+
triggerMessageQueue();
|
|
2231
|
+
}
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2234
|
+
async function handleMessage(message) {
|
|
2235
|
+
if (messages_1.Message.isRequest(message)) {
|
|
2236
|
+
return handleRequest(message);
|
|
2237
|
+
} else if (messages_1.Message.isNotification(message)) {
|
|
2238
|
+
return handleNotification(message);
|
|
2239
|
+
} else if (messages_1.Message.isResponse(message)) {
|
|
2240
|
+
return handleResponse(message);
|
|
2241
|
+
} else {
|
|
2242
|
+
return handleInvalidMessage(message);
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
const callback = (message) => {
|
|
2246
|
+
try {
|
|
2247
|
+
if (messages_1.Message.isNotification(message) && message.method === CancelNotification.type.method) {
|
|
2248
|
+
const cancelId = message.params.id;
|
|
2249
|
+
const key = createRequestQueueKey(cancelId);
|
|
2250
|
+
const toCancel = messageQueue.get(key);
|
|
2251
|
+
if (messages_1.Message.isRequest(toCancel)) {
|
|
2252
|
+
const strategy = options?.connectionStrategy;
|
|
2253
|
+
const response = strategy && strategy.cancelUndispatched ? strategy.cancelUndispatched(toCancel, cancelUndispatched) : cancelUndispatched(toCancel);
|
|
2254
|
+
if (response && (response.error !== void 0 || response.result !== void 0)) {
|
|
2255
|
+
messageQueue.delete(key);
|
|
2256
|
+
requestTokens.delete(cancelId);
|
|
2257
|
+
response.id = toCancel.id;
|
|
2258
|
+
traceSendingResponse(response, message.method, Date.now());
|
|
2259
|
+
messageWriter2.write(response).catch(() => logger.error(`Sending response for canceled message failed.`));
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
const cancellationToken = requestTokens.get(cancelId);
|
|
2264
|
+
if (cancellationToken !== void 0) {
|
|
2265
|
+
cancellationToken.cancel();
|
|
2266
|
+
traceReceivedNotification(message);
|
|
2267
|
+
return;
|
|
2268
|
+
} else {
|
|
2269
|
+
knownCanceledRequests.add(cancelId);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
addMessageToQueue(messageQueue, message);
|
|
2273
|
+
} finally {
|
|
2274
|
+
triggerMessageQueue();
|
|
2275
|
+
}
|
|
2276
|
+
};
|
|
2277
|
+
async function handleRequest(requestMessage) {
|
|
2278
|
+
if (isDisposed()) {
|
|
2279
|
+
return Promise.resolve();
|
|
2280
|
+
}
|
|
2281
|
+
function reply(resultOrError, method, startTime2) {
|
|
2282
|
+
const message = {
|
|
2283
|
+
jsonrpc: version,
|
|
2284
|
+
id: requestMessage.id
|
|
2285
|
+
};
|
|
2286
|
+
if (resultOrError instanceof messages_1.ResponseError) {
|
|
2287
|
+
message.error = resultOrError.toJson();
|
|
2288
|
+
} else {
|
|
2289
|
+
message.result = resultOrError === void 0 ? null : resultOrError;
|
|
2290
|
+
}
|
|
2291
|
+
traceSendingResponse(message, method, startTime2);
|
|
2292
|
+
return messageWriter2.write(message);
|
|
2293
|
+
}
|
|
2294
|
+
function replyError(error, method, startTime2) {
|
|
2295
|
+
const message = {
|
|
2296
|
+
jsonrpc: version,
|
|
2297
|
+
id: requestMessage.id,
|
|
2298
|
+
error: error.toJson()
|
|
2299
|
+
};
|
|
2300
|
+
traceSendingResponse(message, method, startTime2);
|
|
2301
|
+
return messageWriter2.write(message);
|
|
2302
|
+
}
|
|
2303
|
+
traceReceivedRequest(requestMessage);
|
|
2304
|
+
const element = requestHandlers.get(requestMessage.method);
|
|
2305
|
+
let type;
|
|
2306
|
+
let requestHandler;
|
|
2307
|
+
if (element) {
|
|
2308
|
+
type = element.type;
|
|
2309
|
+
requestHandler = element.handler;
|
|
2310
|
+
}
|
|
2311
|
+
const startTime = Date.now();
|
|
2312
|
+
if (requestHandler || starRequestHandler) {
|
|
2313
|
+
const tokenKey = requestMessage.id ?? String(Date.now());
|
|
2314
|
+
const cancellationSource = IdCancellationReceiverStrategy.is(cancellationStrategy.receiver) ? cancellationStrategy.receiver.createCancellationTokenSource(tokenKey) : cancellationStrategy.receiver.createCancellationTokenSource(requestMessage);
|
|
2315
|
+
if (requestMessage.id !== null && knownCanceledRequests.has(requestMessage.id)) {
|
|
2316
|
+
cancellationSource.cancel();
|
|
2317
|
+
}
|
|
2318
|
+
if (requestMessage.id !== null) {
|
|
2319
|
+
requestTokens.set(tokenKey, cancellationSource);
|
|
2320
|
+
}
|
|
2321
|
+
try {
|
|
2322
|
+
let handlerResult;
|
|
2323
|
+
if (requestHandler) {
|
|
2324
|
+
if (requestMessage.params === void 0) {
|
|
2325
|
+
if (type !== void 0 && type.numberOfParams !== 0) {
|
|
2326
|
+
return replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines ${type.numberOfParams} params but received none.`), requestMessage.method, startTime);
|
|
2327
|
+
}
|
|
2328
|
+
handlerResult = requestHandler(cancellationSource.token);
|
|
2329
|
+
} else if (Array.isArray(requestMessage.params)) {
|
|
2330
|
+
if (type !== void 0 && type.parameterStructures === messages_1.ParameterStructures.byName) {
|
|
2331
|
+
return replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines parameters by name but received parameters by position`), requestMessage.method, startTime);
|
|
2332
|
+
}
|
|
2333
|
+
handlerResult = requestHandler(...requestMessage.params, cancellationSource.token);
|
|
2334
|
+
} else {
|
|
2335
|
+
if (type !== void 0 && type.parameterStructures === messages_1.ParameterStructures.byPosition) {
|
|
2336
|
+
return replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines parameters by position but received parameters by name`), requestMessage.method, startTime);
|
|
2337
|
+
}
|
|
2338
|
+
handlerResult = requestHandler(requestMessage.params, cancellationSource.token);
|
|
2339
|
+
}
|
|
2340
|
+
} else if (starRequestHandler) {
|
|
2341
|
+
handlerResult = starRequestHandler(requestMessage.method, requestMessage.params, cancellationSource.token);
|
|
2342
|
+
}
|
|
2343
|
+
const resultOrError = await handlerResult;
|
|
2344
|
+
await reply(resultOrError, requestMessage.method, startTime);
|
|
2345
|
+
} catch (error) {
|
|
2346
|
+
if (error instanceof messages_1.ResponseError) {
|
|
2347
|
+
await reply(error, requestMessage.method, startTime);
|
|
2348
|
+
} else if (error && Is.string(error.message)) {
|
|
2349
|
+
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed with message: ${error.message}`), requestMessage.method, startTime);
|
|
2350
|
+
} else {
|
|
2351
|
+
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed unexpectedly without providing any details.`), requestMessage.method, startTime);
|
|
2352
|
+
}
|
|
2353
|
+
} finally {
|
|
2354
|
+
requestTokens.delete(tokenKey);
|
|
2355
|
+
}
|
|
2356
|
+
} else {
|
|
2357
|
+
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.MethodNotFound, `Unhandled method ${requestMessage.method}`), requestMessage.method, startTime);
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
function handleResponse(responseMessage) {
|
|
2361
|
+
if (isDisposed()) {
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
if (responseMessage.id === null) {
|
|
2365
|
+
if (responseMessage.error) {
|
|
2366
|
+
logger.error(`Received response message without id: Error is:
|
|
2367
|
+
${JSON.stringify(responseMessage.error, void 0, 4)}`);
|
|
2368
|
+
} else {
|
|
2369
|
+
logger.error(`Received response message without id. No further error information provided.`);
|
|
2370
|
+
}
|
|
2371
|
+
} else {
|
|
2372
|
+
const key = responseMessage.id;
|
|
2373
|
+
const responsePromise = responsePromises.get(key);
|
|
2374
|
+
traceReceivedResponse(responseMessage, responsePromise);
|
|
2375
|
+
if (responsePromise !== void 0) {
|
|
2376
|
+
responsePromises.delete(key);
|
|
2377
|
+
try {
|
|
2378
|
+
if (responseMessage.error) {
|
|
2379
|
+
const error = responseMessage.error;
|
|
2380
|
+
responsePromise.reject(new messages_1.ResponseError(error.code, error.message, error.data));
|
|
2381
|
+
} else if (responseMessage.result !== void 0) {
|
|
2382
|
+
responsePromise.resolve(responseMessage.result);
|
|
2383
|
+
} else {
|
|
2384
|
+
throw new Error("Should never happen.");
|
|
2385
|
+
}
|
|
2386
|
+
} catch (error) {
|
|
2387
|
+
if (error.message) {
|
|
2388
|
+
logger.error(`Response handler '${responsePromise.method}' failed with message: ${error.message}`);
|
|
2389
|
+
} else {
|
|
2390
|
+
logger.error(`Response handler '${responsePromise.method}' failed unexpectedly.`);
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
async function handleNotification(message) {
|
|
2397
|
+
if (isDisposed()) {
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
let type = void 0;
|
|
2401
|
+
let notificationHandler;
|
|
2402
|
+
if (message.method === CancelNotification.type.method) {
|
|
2403
|
+
const cancelId = message.params.id;
|
|
2404
|
+
knownCanceledRequests.delete(cancelId);
|
|
2405
|
+
traceReceivedNotification(message);
|
|
2406
|
+
return;
|
|
2407
|
+
} else {
|
|
2408
|
+
const element = notificationHandlers.get(message.method);
|
|
2409
|
+
if (element) {
|
|
2410
|
+
notificationHandler = element.handler;
|
|
2411
|
+
type = element.type;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
if (notificationHandler || starNotificationHandler) {
|
|
2415
|
+
try {
|
|
2416
|
+
traceReceivedNotification(message);
|
|
2417
|
+
if (notificationHandler) {
|
|
2418
|
+
if (message.params === void 0) {
|
|
2419
|
+
if (type !== void 0) {
|
|
2420
|
+
if (type.numberOfParams !== 0 && type.parameterStructures !== messages_1.ParameterStructures.byName) {
|
|
2421
|
+
logger.error(`Notification ${message.method} defines ${type.numberOfParams} params but received none.`);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
await notificationHandler();
|
|
2425
|
+
} else if (Array.isArray(message.params)) {
|
|
2426
|
+
const params = message.params;
|
|
2427
|
+
if (message.method === ProgressNotification.type.method && params.length === 2 && ProgressToken.is(params[0])) {
|
|
2428
|
+
await notificationHandler({ token: params[0], value: params[1] });
|
|
2429
|
+
} else {
|
|
2430
|
+
if (type !== void 0) {
|
|
2431
|
+
if (type.parameterStructures === messages_1.ParameterStructures.byName) {
|
|
2432
|
+
logger.error(`Notification ${message.method} defines parameters by name but received parameters by position`);
|
|
2433
|
+
}
|
|
2434
|
+
if (type.numberOfParams !== message.params.length) {
|
|
2435
|
+
logger.error(`Notification ${message.method} defines ${type.numberOfParams} params but received ${params.length} arguments`);
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
await notificationHandler(...params);
|
|
2439
|
+
}
|
|
2440
|
+
} else {
|
|
2441
|
+
if (type !== void 0 && type.parameterStructures === messages_1.ParameterStructures.byPosition) {
|
|
2442
|
+
logger.error(`Notification ${message.method} defines parameters by position but received parameters by name`);
|
|
2443
|
+
}
|
|
2444
|
+
await notificationHandler(message.params);
|
|
2445
|
+
}
|
|
2446
|
+
} else if (starNotificationHandler) {
|
|
2447
|
+
await starNotificationHandler(message.method, message.params);
|
|
2448
|
+
}
|
|
2449
|
+
} catch (error) {
|
|
2450
|
+
if (error.message) {
|
|
2451
|
+
logger.error(`Notification handler '${message.method}' failed with message: ${error.message}`);
|
|
2452
|
+
} else {
|
|
2453
|
+
logger.error(`Notification handler '${message.method}' failed unexpectedly.`);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
} else {
|
|
2457
|
+
unhandledNotificationEmitter.fire(message);
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
function handleInvalidMessage(message) {
|
|
2461
|
+
if (!message) {
|
|
2462
|
+
logger.error("Received empty message.");
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
logger.error(`Received message which is neither a response nor a notification message:
|
|
2466
|
+
${JSON.stringify(message, null, 4)}`);
|
|
2467
|
+
const responseMessage = message;
|
|
2468
|
+
if (Is.string(responseMessage.id) || Is.number(responseMessage.id)) {
|
|
2469
|
+
const key = responseMessage.id;
|
|
2470
|
+
const responseHandler = responsePromises.get(key);
|
|
2471
|
+
if (responseHandler) {
|
|
2472
|
+
responseHandler.reject(new Error("The received response has neither a result nor an error property."));
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
function stringifyTrace(params) {
|
|
2477
|
+
if (params === void 0 || params === null) {
|
|
2478
|
+
return void 0;
|
|
2479
|
+
}
|
|
2480
|
+
switch (trace) {
|
|
2481
|
+
case Trace.Verbose:
|
|
2482
|
+
return JSON.stringify(params, null, 4);
|
|
2483
|
+
case Trace.Compact:
|
|
2484
|
+
return JSON.stringify(params);
|
|
2485
|
+
default:
|
|
2486
|
+
return void 0;
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
function traceSendingRequest(message) {
|
|
2490
|
+
if (trace === Trace.Off || !tracer) {
|
|
2491
|
+
return;
|
|
2492
|
+
}
|
|
2493
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2494
|
+
let data = void 0;
|
|
2495
|
+
if ((trace === Trace.Verbose || trace === Trace.Compact) && message.params) {
|
|
2496
|
+
data = `Params: ${stringifyTrace(message.params)}`;
|
|
2497
|
+
}
|
|
2498
|
+
tracer.log(`Sending request '${message.method} - (${message.id})'.`, data);
|
|
2499
|
+
} else {
|
|
2500
|
+
logLSPMessage("send-request", message);
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
function traceSendingNotification(message) {
|
|
2504
|
+
if (trace === Trace.Off || !tracer) {
|
|
2505
|
+
return;
|
|
2506
|
+
}
|
|
2507
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2508
|
+
let data = void 0;
|
|
2509
|
+
if (trace === Trace.Verbose || trace === Trace.Compact) {
|
|
2510
|
+
if (message.params) {
|
|
2511
|
+
data = `Params: ${stringifyTrace(message.params)}`;
|
|
2512
|
+
} else {
|
|
2513
|
+
data = "No parameters provided.";
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
tracer.log(`Sending notification '${message.method}'.`, data);
|
|
2517
|
+
} else {
|
|
2518
|
+
logLSPMessage("send-notification", message);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
function traceSendingResponse(message, method, startTime) {
|
|
2522
|
+
if (trace === Trace.Off || !tracer) {
|
|
2523
|
+
return;
|
|
2524
|
+
}
|
|
2525
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2526
|
+
let data = void 0;
|
|
2527
|
+
if (trace === Trace.Verbose || trace === Trace.Compact) {
|
|
2528
|
+
if (message.error && message.error.data) {
|
|
2529
|
+
data = `Error data: ${stringifyTrace(message.error.data)}`;
|
|
2530
|
+
} else {
|
|
2531
|
+
if (message.result) {
|
|
2532
|
+
data = `Result: ${stringifyTrace(message.result)}`;
|
|
2533
|
+
} else if (message.error === void 0) {
|
|
2534
|
+
data = "No result returned.";
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
tracer.log(`Sending response '${method} - (${message.id})'. Processing request took ${Date.now() - startTime}ms`, data);
|
|
2539
|
+
} else {
|
|
2540
|
+
logLSPMessage("send-response", message);
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
function traceReceivedRequest(message) {
|
|
2544
|
+
if (trace === Trace.Off || !tracer) {
|
|
2545
|
+
return;
|
|
2546
|
+
}
|
|
2547
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2548
|
+
let data = void 0;
|
|
2549
|
+
if ((trace === Trace.Verbose || trace === Trace.Compact) && message.params) {
|
|
2550
|
+
data = `Params: ${stringifyTrace(message.params)}`;
|
|
2551
|
+
}
|
|
2552
|
+
tracer.log(`Received request '${message.method} - (${message.id})'.`, data);
|
|
2553
|
+
} else {
|
|
2554
|
+
logLSPMessage("receive-request", message);
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
function traceReceivedNotification(message) {
|
|
2558
|
+
if (trace === Trace.Off || !tracer || message.method === LogTraceNotification.type.method) {
|
|
2559
|
+
return;
|
|
2560
|
+
}
|
|
2561
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2562
|
+
let data = void 0;
|
|
2563
|
+
if (trace === Trace.Verbose || trace === Trace.Compact) {
|
|
2564
|
+
if (message.params) {
|
|
2565
|
+
data = `Params: ${stringifyTrace(message.params)}`;
|
|
2566
|
+
} else {
|
|
2567
|
+
data = "No parameters provided.";
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
tracer.log(`Received notification '${message.method}'.`, data);
|
|
2571
|
+
} else {
|
|
2572
|
+
logLSPMessage("receive-notification", message);
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
function traceReceivedResponse(message, responsePromise) {
|
|
2576
|
+
if (trace === Trace.Off || !tracer) {
|
|
2577
|
+
return;
|
|
2578
|
+
}
|
|
2579
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2580
|
+
let data = void 0;
|
|
2581
|
+
if (trace === Trace.Verbose || trace === Trace.Compact) {
|
|
2582
|
+
if (message.error && message.error.data) {
|
|
2583
|
+
data = `Error data: ${stringifyTrace(message.error.data)}`;
|
|
2584
|
+
} else {
|
|
2585
|
+
if (message.result) {
|
|
2586
|
+
data = `Result: ${stringifyTrace(message.result)}`;
|
|
2587
|
+
} else if (message.error === void 0) {
|
|
2588
|
+
data = "No result returned.";
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
if (responsePromise) {
|
|
2593
|
+
const error = message.error ? ` Request failed: ${message.error.message} (${message.error.code}).` : "";
|
|
2594
|
+
tracer.log(`Received response '${responsePromise.method} - (${message.id})' in ${Date.now() - responsePromise.timerStart}ms.${error}`, data);
|
|
2595
|
+
} else {
|
|
2596
|
+
tracer.log(`Received response ${message.id} without active response promise.`, data);
|
|
2597
|
+
}
|
|
2598
|
+
} else {
|
|
2599
|
+
logLSPMessage("receive-response", message);
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
function logLSPMessage(type, message) {
|
|
2603
|
+
if (!tracer || trace === Trace.Off) {
|
|
2604
|
+
return;
|
|
2605
|
+
}
|
|
2606
|
+
const lspMessage = {
|
|
2607
|
+
isLSPMessage: true,
|
|
2608
|
+
type,
|
|
2609
|
+
message,
|
|
2610
|
+
timestamp: Date.now()
|
|
2611
|
+
};
|
|
2612
|
+
tracer.log(lspMessage);
|
|
2613
|
+
}
|
|
2614
|
+
function throwIfClosedOrDisposed() {
|
|
2615
|
+
if (isClosed()) {
|
|
2616
|
+
throw new ConnectionError(ConnectionErrors.Closed, "Connection is closed.");
|
|
2617
|
+
}
|
|
2618
|
+
if (isDisposed()) {
|
|
2619
|
+
throw new ConnectionError(ConnectionErrors.Disposed, "Connection is disposed.");
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
function throwIfListening() {
|
|
2623
|
+
if (isListening()) {
|
|
2624
|
+
throw new ConnectionError(ConnectionErrors.AlreadyListening, "Connection is already listening");
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
function throwIfNotListening() {
|
|
2628
|
+
if (!isListening()) {
|
|
2629
|
+
throw new Error("Call listen() first.");
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
function undefinedToNull(param) {
|
|
2633
|
+
if (param === void 0) {
|
|
2634
|
+
return null;
|
|
2635
|
+
} else {
|
|
2636
|
+
return param;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
function nullToUndefined(param) {
|
|
2640
|
+
if (param === null) {
|
|
2641
|
+
return void 0;
|
|
2642
|
+
} else {
|
|
2643
|
+
return param;
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
function isNamedParam(param) {
|
|
2647
|
+
return param !== void 0 && param !== null && !Array.isArray(param) && typeof param === "object";
|
|
2648
|
+
}
|
|
2649
|
+
function computeSingleParam(parameterStructures, param) {
|
|
2650
|
+
switch (parameterStructures) {
|
|
2651
|
+
case messages_1.ParameterStructures.auto:
|
|
2652
|
+
if (isNamedParam(param)) {
|
|
2653
|
+
return nullToUndefined(param);
|
|
2654
|
+
} else {
|
|
2655
|
+
return [undefinedToNull(param)];
|
|
2656
|
+
}
|
|
2657
|
+
case messages_1.ParameterStructures.byName:
|
|
2658
|
+
if (!isNamedParam(param)) {
|
|
2659
|
+
throw new Error(`Received parameters by name but param is not an object literal.`);
|
|
2660
|
+
}
|
|
2661
|
+
return nullToUndefined(param);
|
|
2662
|
+
case messages_1.ParameterStructures.byPosition:
|
|
2663
|
+
return [undefinedToNull(param)];
|
|
2664
|
+
default:
|
|
2665
|
+
throw new Error(`Unknown parameter structure ${parameterStructures.toString()}`);
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
function computeMessageParams(type, params) {
|
|
2669
|
+
let result;
|
|
2670
|
+
const numberOfParams = type.numberOfParams;
|
|
2671
|
+
switch (numberOfParams) {
|
|
2672
|
+
case 0:
|
|
2673
|
+
result = void 0;
|
|
2674
|
+
break;
|
|
2675
|
+
case 1:
|
|
2676
|
+
result = computeSingleParam(type.parameterStructures, params[0]);
|
|
2677
|
+
break;
|
|
2678
|
+
default:
|
|
2679
|
+
result = [];
|
|
2680
|
+
for (let i = 0; i < params.length && i < numberOfParams; i++) {
|
|
2681
|
+
result.push(undefinedToNull(params[i]));
|
|
2682
|
+
}
|
|
2683
|
+
if (params.length < numberOfParams) {
|
|
2684
|
+
for (let i = params.length; i < numberOfParams; i++) {
|
|
2685
|
+
result.push(null);
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
break;
|
|
2689
|
+
}
|
|
2690
|
+
return result;
|
|
2691
|
+
}
|
|
2692
|
+
const connection2 = {
|
|
2693
|
+
sendNotification: (type, ...args) => {
|
|
2694
|
+
throwIfClosedOrDisposed();
|
|
2695
|
+
let method;
|
|
2696
|
+
let messageParams;
|
|
2697
|
+
if (Is.string(type)) {
|
|
2698
|
+
method = type;
|
|
2699
|
+
const first = args[0];
|
|
2700
|
+
let paramStart = 0;
|
|
2701
|
+
let parameterStructures = messages_1.ParameterStructures.auto;
|
|
2702
|
+
if (messages_1.ParameterStructures.is(first)) {
|
|
2703
|
+
paramStart = 1;
|
|
2704
|
+
parameterStructures = first;
|
|
2705
|
+
}
|
|
2706
|
+
const paramEnd = args.length;
|
|
2707
|
+
const numberOfParams = paramEnd - paramStart;
|
|
2708
|
+
switch (numberOfParams) {
|
|
2709
|
+
case 0:
|
|
2710
|
+
messageParams = void 0;
|
|
2711
|
+
break;
|
|
2712
|
+
case 1:
|
|
2713
|
+
messageParams = computeSingleParam(parameterStructures, args[paramStart]);
|
|
2714
|
+
break;
|
|
2715
|
+
default:
|
|
2716
|
+
if (parameterStructures === messages_1.ParameterStructures.byName) {
|
|
2717
|
+
throw new Error(`Received ${numberOfParams} parameters for 'by Name' notification parameter structure.`);
|
|
2718
|
+
}
|
|
2719
|
+
messageParams = args.slice(paramStart, paramEnd).map((value) => undefinedToNull(value));
|
|
2720
|
+
break;
|
|
2721
|
+
}
|
|
2722
|
+
} else {
|
|
2723
|
+
const params = args;
|
|
2724
|
+
method = type.method;
|
|
2725
|
+
messageParams = computeMessageParams(type, params);
|
|
2726
|
+
}
|
|
2727
|
+
const notificationMessage = {
|
|
2728
|
+
jsonrpc: version,
|
|
2729
|
+
method,
|
|
2730
|
+
params: messageParams
|
|
2731
|
+
};
|
|
2732
|
+
traceSendingNotification(notificationMessage);
|
|
2733
|
+
return messageWriter2.write(notificationMessage).catch((error) => {
|
|
2734
|
+
logger.error(`Sending notification failed.`);
|
|
2735
|
+
throw error;
|
|
2736
|
+
});
|
|
2737
|
+
},
|
|
2738
|
+
onNotification: (type, handler) => {
|
|
2739
|
+
throwIfClosedOrDisposed();
|
|
2740
|
+
let method;
|
|
2741
|
+
if (Is.func(type)) {
|
|
2742
|
+
starNotificationHandler = type;
|
|
2743
|
+
} else if (handler) {
|
|
2744
|
+
if (Is.string(type)) {
|
|
2745
|
+
method = type;
|
|
2746
|
+
notificationHandlers.set(type, { type: void 0, handler });
|
|
2747
|
+
} else {
|
|
2748
|
+
method = type.method;
|
|
2749
|
+
notificationHandlers.set(type.method, { type, handler });
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
return {
|
|
2753
|
+
dispose: () => {
|
|
2754
|
+
if (method !== void 0) {
|
|
2755
|
+
if (notificationHandlers.get(method)?.handler === handler) {
|
|
2756
|
+
notificationHandlers.delete(method);
|
|
2757
|
+
}
|
|
2758
|
+
} else if (starNotificationHandler === type) {
|
|
2759
|
+
starNotificationHandler = void 0;
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
};
|
|
2763
|
+
},
|
|
2764
|
+
onProgress: (_type, token, handler) => {
|
|
2765
|
+
if (progressHandlers.has(token)) {
|
|
2766
|
+
throw new Error(`Progress handler for token ${token} already registered`);
|
|
2767
|
+
}
|
|
2768
|
+
progressHandlers.set(token, handler);
|
|
2769
|
+
return {
|
|
2770
|
+
dispose: () => {
|
|
2771
|
+
if (progressHandlers.get(token) === handler) {
|
|
2772
|
+
progressHandlers.delete(token);
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
};
|
|
2776
|
+
},
|
|
2777
|
+
sendProgress: (_type, token, value) => {
|
|
2778
|
+
return connection2.sendNotification(ProgressNotification.type, { token, value });
|
|
2779
|
+
},
|
|
2780
|
+
onUnhandledProgress: unhandledProgressEmitter.event,
|
|
2781
|
+
sendRequest: (type, ...args) => {
|
|
2782
|
+
throwIfClosedOrDisposed();
|
|
2783
|
+
throwIfNotListening();
|
|
2784
|
+
function sendCancellation(connection3, id2) {
|
|
2785
|
+
const p = cancellationStrategy.sender.sendCancellation(connection3, id2);
|
|
2786
|
+
if (p === void 0) {
|
|
2787
|
+
logger.log(`Received no promise from cancellation strategy when cancelling id ${id2}`);
|
|
2788
|
+
} else {
|
|
2789
|
+
p.catch(() => {
|
|
2790
|
+
logger.log(`Sending cancellation messages for id ${id2} failed.`);
|
|
2791
|
+
});
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
let method;
|
|
2795
|
+
let messageParams;
|
|
2796
|
+
let token = void 0;
|
|
2797
|
+
if (Is.string(type)) {
|
|
2798
|
+
method = type;
|
|
2799
|
+
const first = args[0];
|
|
2800
|
+
const last = args[args.length - 1];
|
|
2801
|
+
let paramStart = 0;
|
|
2802
|
+
let parameterStructures = messages_1.ParameterStructures.auto;
|
|
2803
|
+
if (messages_1.ParameterStructures.is(first)) {
|
|
2804
|
+
paramStart = 1;
|
|
2805
|
+
parameterStructures = first;
|
|
2806
|
+
}
|
|
2807
|
+
let paramEnd = args.length;
|
|
2808
|
+
if (cancellation_1.CancellationToken.is(last)) {
|
|
2809
|
+
paramEnd = paramEnd - 1;
|
|
2810
|
+
token = last;
|
|
2811
|
+
}
|
|
2812
|
+
const numberOfParams = paramEnd - paramStart;
|
|
2813
|
+
switch (numberOfParams) {
|
|
2814
|
+
case 0:
|
|
2815
|
+
messageParams = void 0;
|
|
2816
|
+
break;
|
|
2817
|
+
case 1:
|
|
2818
|
+
messageParams = computeSingleParam(parameterStructures, args[paramStart]);
|
|
2819
|
+
break;
|
|
2820
|
+
default:
|
|
2821
|
+
if (parameterStructures === messages_1.ParameterStructures.byName) {
|
|
2822
|
+
throw new Error(`Received ${numberOfParams} parameters for 'by Name' request parameter structure.`);
|
|
2823
|
+
}
|
|
2824
|
+
messageParams = args.slice(paramStart, paramEnd).map((value) => undefinedToNull(value));
|
|
2825
|
+
break;
|
|
2826
|
+
}
|
|
2827
|
+
} else {
|
|
2828
|
+
const params = args;
|
|
2829
|
+
method = type.method;
|
|
2830
|
+
messageParams = computeMessageParams(type, params);
|
|
2831
|
+
const numberOfParams = type.numberOfParams;
|
|
2832
|
+
token = cancellation_1.CancellationToken.is(params[numberOfParams]) ? params[numberOfParams] : void 0;
|
|
2833
|
+
}
|
|
2834
|
+
const id = sequenceNumber++;
|
|
2835
|
+
let disposable2;
|
|
2836
|
+
let tokenWasCancelled = false;
|
|
2837
|
+
if (token !== void 0) {
|
|
2838
|
+
if (token.isCancellationRequested) {
|
|
2839
|
+
tokenWasCancelled = true;
|
|
2840
|
+
} else {
|
|
2841
|
+
disposable2 = token.onCancellationRequested(() => {
|
|
2842
|
+
sendCancellation(connection2, id);
|
|
2843
|
+
});
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
const requestMessage = {
|
|
2847
|
+
jsonrpc: version,
|
|
2848
|
+
id,
|
|
2849
|
+
method,
|
|
2850
|
+
params: messageParams
|
|
2851
|
+
};
|
|
2852
|
+
traceSendingRequest(requestMessage);
|
|
2853
|
+
if (typeof cancellationStrategy.sender.enableCancellation === "function") {
|
|
2854
|
+
cancellationStrategy.sender.enableCancellation(requestMessage);
|
|
2855
|
+
}
|
|
2856
|
+
return new Promise(async (resolve2, reject) => {
|
|
2857
|
+
const resolveWithCleanup = (r) => {
|
|
2858
|
+
resolve2(r);
|
|
2859
|
+
cancellationStrategy.sender.cleanup(id);
|
|
2860
|
+
disposable2?.dispose();
|
|
2861
|
+
};
|
|
2862
|
+
const rejectWithCleanup = (r) => {
|
|
2863
|
+
reject(r);
|
|
2864
|
+
cancellationStrategy.sender.cleanup(id);
|
|
2865
|
+
disposable2?.dispose();
|
|
2866
|
+
};
|
|
2867
|
+
const responsePromise = { method, timerStart: Date.now(), resolve: resolveWithCleanup, reject: rejectWithCleanup };
|
|
2868
|
+
try {
|
|
2869
|
+
responsePromises.set(id, responsePromise);
|
|
2870
|
+
await messageWriter2.write(requestMessage);
|
|
2871
|
+
if (tokenWasCancelled) {
|
|
2872
|
+
sendCancellation(connection2, id);
|
|
2873
|
+
}
|
|
2874
|
+
} catch (error) {
|
|
2875
|
+
responsePromises.delete(id);
|
|
2876
|
+
responsePromise.reject(new messages_1.ResponseError(messages_1.ErrorCodes.MessageWriteError, error.message ? error.message : "Unknown reason"));
|
|
2877
|
+
logger.error(`Sending request failed.`);
|
|
2878
|
+
throw error;
|
|
2879
|
+
}
|
|
2880
|
+
});
|
|
2881
|
+
},
|
|
2882
|
+
onRequest: (type, handler) => {
|
|
2883
|
+
throwIfClosedOrDisposed();
|
|
2884
|
+
let method = null;
|
|
2885
|
+
if (StarRequestHandler.is(type)) {
|
|
2886
|
+
method = void 0;
|
|
2887
|
+
starRequestHandler = type;
|
|
2888
|
+
} else if (Is.string(type)) {
|
|
2889
|
+
method = null;
|
|
2890
|
+
if (handler !== void 0) {
|
|
2891
|
+
method = type;
|
|
2892
|
+
requestHandlers.set(type, { handler, type: void 0 });
|
|
2893
|
+
}
|
|
2894
|
+
} else {
|
|
2895
|
+
if (handler !== void 0) {
|
|
2896
|
+
method = type.method;
|
|
2897
|
+
requestHandlers.set(type.method, { type, handler });
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
return {
|
|
2901
|
+
dispose: () => {
|
|
2902
|
+
if (method === null) {
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
if (method !== void 0) {
|
|
2906
|
+
if (requestHandlers.get(method)?.handler === handler) {
|
|
2907
|
+
requestHandlers.delete(method);
|
|
2908
|
+
}
|
|
2909
|
+
} else if (starRequestHandler === type) {
|
|
2910
|
+
starRequestHandler = void 0;
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
};
|
|
2914
|
+
},
|
|
2915
|
+
hasPendingResponse: () => {
|
|
2916
|
+
return responsePromises.size > 0;
|
|
2917
|
+
},
|
|
2918
|
+
trace: async (_value, _tracer, sendNotificationOrTraceOptions) => {
|
|
2919
|
+
let _sendNotification = false;
|
|
2920
|
+
let _traceFormat = TraceFormat.Text;
|
|
2921
|
+
if (sendNotificationOrTraceOptions !== void 0) {
|
|
2922
|
+
if (Is.boolean(sendNotificationOrTraceOptions)) {
|
|
2923
|
+
_sendNotification = sendNotificationOrTraceOptions;
|
|
2924
|
+
} else {
|
|
2925
|
+
_sendNotification = sendNotificationOrTraceOptions.sendNotification || false;
|
|
2926
|
+
_traceFormat = sendNotificationOrTraceOptions.traceFormat || TraceFormat.Text;
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
trace = _value;
|
|
2930
|
+
traceFormat = _traceFormat;
|
|
2931
|
+
if (trace === Trace.Off) {
|
|
2932
|
+
tracer = void 0;
|
|
2933
|
+
} else {
|
|
2934
|
+
tracer = _tracer;
|
|
2935
|
+
}
|
|
2936
|
+
if (_sendNotification && !isClosed() && !isDisposed()) {
|
|
2937
|
+
await connection2.sendNotification(SetTraceNotification.type, { value: Trace.toString(_value) });
|
|
2938
|
+
}
|
|
2939
|
+
},
|
|
2940
|
+
onError: errorEmitter.event,
|
|
2941
|
+
onClose: closeEmitter.event,
|
|
2942
|
+
onUnhandledNotification: unhandledNotificationEmitter.event,
|
|
2943
|
+
onDispose: disposeEmitter.event,
|
|
2944
|
+
end: () => {
|
|
2945
|
+
messageWriter2.end();
|
|
2946
|
+
},
|
|
2947
|
+
dispose: () => {
|
|
2948
|
+
if (isDisposed()) {
|
|
2949
|
+
return;
|
|
2950
|
+
}
|
|
2951
|
+
state = ConnectionState.Disposed;
|
|
2952
|
+
disposeEmitter.fire(void 0);
|
|
2953
|
+
const error = new messages_1.ResponseError(messages_1.ErrorCodes.PendingResponseRejected, "Pending response rejected since connection got disposed");
|
|
2954
|
+
for (const promise of responsePromises.values()) {
|
|
2955
|
+
promise.reject(error);
|
|
2956
|
+
}
|
|
2957
|
+
responsePromises = /* @__PURE__ */ new Map();
|
|
2958
|
+
requestTokens = /* @__PURE__ */ new Map();
|
|
2959
|
+
knownCanceledRequests = /* @__PURE__ */ new Set();
|
|
2960
|
+
messageQueue = new linkedMap_1.LinkedMap();
|
|
2961
|
+
if (Is.func(messageWriter2.dispose)) {
|
|
2962
|
+
messageWriter2.dispose();
|
|
2963
|
+
}
|
|
2964
|
+
if (Is.func(messageReader2.dispose)) {
|
|
2965
|
+
messageReader2.dispose();
|
|
2966
|
+
}
|
|
2967
|
+
},
|
|
2968
|
+
listen: () => {
|
|
2969
|
+
throwIfClosedOrDisposed();
|
|
2970
|
+
throwIfListening();
|
|
2971
|
+
state = ConnectionState.Listening;
|
|
2972
|
+
messageReader2.listen(callback);
|
|
2973
|
+
},
|
|
2974
|
+
inspect: () => {
|
|
2975
|
+
(0, ral_1.default)().console.log("inspect");
|
|
2976
|
+
}
|
|
2977
|
+
};
|
|
2978
|
+
connection2.onNotification(LogTraceNotification.type, (params) => {
|
|
2979
|
+
if (trace === Trace.Off || !tracer) {
|
|
2980
|
+
return;
|
|
2981
|
+
}
|
|
2982
|
+
const verbose = trace === Trace.Verbose || trace === Trace.Compact;
|
|
2983
|
+
tracer.log(params.message, verbose ? params.verbose : void 0);
|
|
2984
|
+
});
|
|
2985
|
+
connection2.onNotification(ProgressNotification.type, async (params) => {
|
|
2986
|
+
const handler = progressHandlers.get(params.token);
|
|
2987
|
+
if (handler) {
|
|
2988
|
+
await handler(params.value);
|
|
2989
|
+
} else {
|
|
2990
|
+
unhandledProgressEmitter.fire(params);
|
|
2991
|
+
}
|
|
2992
|
+
});
|
|
2993
|
+
return connection2;
|
|
2994
|
+
}
|
|
2995
|
+
})(connection);
|
|
2996
|
+
return connection;
|
|
2997
|
+
}
|
|
2998
|
+
var hasRequiredApi;
|
|
2999
|
+
function requireApi() {
|
|
3000
|
+
if (hasRequiredApi) return api;
|
|
3001
|
+
hasRequiredApi = 1;
|
|
3002
|
+
(function(exports) {
|
|
3003
|
+
var __importDefault = api && api.__importDefault || function(mod) {
|
|
3004
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
3005
|
+
};
|
|
3006
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3007
|
+
exports.ProgressType = exports.ProgressToken = exports.createMessageConnection = exports.NullLogger = exports.ConnectionOptions = exports.ConnectionStrategy = exports.AbstractMessageBuffer = exports.WriteableStreamMessageWriter = exports.AbstractMessageWriter = exports.MessageWriter = exports.ReadableStreamMessageReader = exports.AbstractMessageReader = exports.MessageReader = exports.SharedArrayReceiverStrategy = exports.SharedArraySenderStrategy = exports.CancellationToken = exports.CancellationTokenSource = exports.Emitter = exports.Event = exports.Disposable = exports.LRUCache = exports.Touch = exports.LinkedMap = exports.ParameterStructures = exports.NotificationType9 = exports.NotificationType8 = exports.NotificationType7 = exports.NotificationType6 = exports.NotificationType5 = exports.NotificationType4 = exports.NotificationType3 = exports.NotificationType2 = exports.NotificationType1 = exports.NotificationType0 = exports.NotificationType = exports.ErrorCodes = exports.ResponseError = exports.RequestType9 = exports.RequestType8 = exports.RequestType7 = exports.RequestType6 = exports.RequestType5 = exports.RequestType4 = exports.RequestType3 = exports.RequestType2 = exports.RequestType1 = exports.RequestType0 = exports.RequestType = exports.Message = exports.RAL = void 0;
|
|
3008
|
+
exports.MessageStrategy = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.RequestCancellationReceiverStrategy = exports.IdCancellationReceiverStrategy = exports.CancellationReceiverStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = exports.TraceValues = exports.TraceValue = exports.Trace = void 0;
|
|
3009
|
+
const messages_1 = requireMessages();
|
|
3010
|
+
Object.defineProperty(exports, "Message", { enumerable: true, get: function() {
|
|
3011
|
+
return messages_1.Message;
|
|
3012
|
+
} });
|
|
3013
|
+
Object.defineProperty(exports, "RequestType", { enumerable: true, get: function() {
|
|
3014
|
+
return messages_1.RequestType;
|
|
3015
|
+
} });
|
|
3016
|
+
Object.defineProperty(exports, "RequestType0", { enumerable: true, get: function() {
|
|
3017
|
+
return messages_1.RequestType0;
|
|
3018
|
+
} });
|
|
3019
|
+
Object.defineProperty(exports, "RequestType1", { enumerable: true, get: function() {
|
|
3020
|
+
return messages_1.RequestType1;
|
|
3021
|
+
} });
|
|
3022
|
+
Object.defineProperty(exports, "RequestType2", { enumerable: true, get: function() {
|
|
3023
|
+
return messages_1.RequestType2;
|
|
3024
|
+
} });
|
|
3025
|
+
Object.defineProperty(exports, "RequestType3", { enumerable: true, get: function() {
|
|
3026
|
+
return messages_1.RequestType3;
|
|
3027
|
+
} });
|
|
3028
|
+
Object.defineProperty(exports, "RequestType4", { enumerable: true, get: function() {
|
|
3029
|
+
return messages_1.RequestType4;
|
|
3030
|
+
} });
|
|
3031
|
+
Object.defineProperty(exports, "RequestType5", { enumerable: true, get: function() {
|
|
3032
|
+
return messages_1.RequestType5;
|
|
3033
|
+
} });
|
|
3034
|
+
Object.defineProperty(exports, "RequestType6", { enumerable: true, get: function() {
|
|
3035
|
+
return messages_1.RequestType6;
|
|
3036
|
+
} });
|
|
3037
|
+
Object.defineProperty(exports, "RequestType7", { enumerable: true, get: function() {
|
|
3038
|
+
return messages_1.RequestType7;
|
|
3039
|
+
} });
|
|
3040
|
+
Object.defineProperty(exports, "RequestType8", { enumerable: true, get: function() {
|
|
3041
|
+
return messages_1.RequestType8;
|
|
3042
|
+
} });
|
|
3043
|
+
Object.defineProperty(exports, "RequestType9", { enumerable: true, get: function() {
|
|
3044
|
+
return messages_1.RequestType9;
|
|
3045
|
+
} });
|
|
3046
|
+
Object.defineProperty(exports, "ResponseError", { enumerable: true, get: function() {
|
|
3047
|
+
return messages_1.ResponseError;
|
|
3048
|
+
} });
|
|
3049
|
+
Object.defineProperty(exports, "ErrorCodes", { enumerable: true, get: function() {
|
|
3050
|
+
return messages_1.ErrorCodes;
|
|
3051
|
+
} });
|
|
3052
|
+
Object.defineProperty(exports, "NotificationType", { enumerable: true, get: function() {
|
|
3053
|
+
return messages_1.NotificationType;
|
|
3054
|
+
} });
|
|
3055
|
+
Object.defineProperty(exports, "NotificationType0", { enumerable: true, get: function() {
|
|
3056
|
+
return messages_1.NotificationType0;
|
|
3057
|
+
} });
|
|
3058
|
+
Object.defineProperty(exports, "NotificationType1", { enumerable: true, get: function() {
|
|
3059
|
+
return messages_1.NotificationType1;
|
|
3060
|
+
} });
|
|
3061
|
+
Object.defineProperty(exports, "NotificationType2", { enumerable: true, get: function() {
|
|
3062
|
+
return messages_1.NotificationType2;
|
|
3063
|
+
} });
|
|
3064
|
+
Object.defineProperty(exports, "NotificationType3", { enumerable: true, get: function() {
|
|
3065
|
+
return messages_1.NotificationType3;
|
|
3066
|
+
} });
|
|
3067
|
+
Object.defineProperty(exports, "NotificationType4", { enumerable: true, get: function() {
|
|
3068
|
+
return messages_1.NotificationType4;
|
|
3069
|
+
} });
|
|
3070
|
+
Object.defineProperty(exports, "NotificationType5", { enumerable: true, get: function() {
|
|
3071
|
+
return messages_1.NotificationType5;
|
|
3072
|
+
} });
|
|
3073
|
+
Object.defineProperty(exports, "NotificationType6", { enumerable: true, get: function() {
|
|
3074
|
+
return messages_1.NotificationType6;
|
|
3075
|
+
} });
|
|
3076
|
+
Object.defineProperty(exports, "NotificationType7", { enumerable: true, get: function() {
|
|
3077
|
+
return messages_1.NotificationType7;
|
|
3078
|
+
} });
|
|
3079
|
+
Object.defineProperty(exports, "NotificationType8", { enumerable: true, get: function() {
|
|
3080
|
+
return messages_1.NotificationType8;
|
|
3081
|
+
} });
|
|
3082
|
+
Object.defineProperty(exports, "NotificationType9", { enumerable: true, get: function() {
|
|
3083
|
+
return messages_1.NotificationType9;
|
|
3084
|
+
} });
|
|
3085
|
+
Object.defineProperty(exports, "ParameterStructures", { enumerable: true, get: function() {
|
|
3086
|
+
return messages_1.ParameterStructures;
|
|
3087
|
+
} });
|
|
3088
|
+
const linkedMap_1 = requireLinkedMap();
|
|
3089
|
+
Object.defineProperty(exports, "LinkedMap", { enumerable: true, get: function() {
|
|
3090
|
+
return linkedMap_1.LinkedMap;
|
|
3091
|
+
} });
|
|
3092
|
+
Object.defineProperty(exports, "LRUCache", { enumerable: true, get: function() {
|
|
3093
|
+
return linkedMap_1.LRUCache;
|
|
3094
|
+
} });
|
|
3095
|
+
Object.defineProperty(exports, "Touch", { enumerable: true, get: function() {
|
|
3096
|
+
return linkedMap_1.Touch;
|
|
3097
|
+
} });
|
|
3098
|
+
const disposable_1 = requireDisposable();
|
|
3099
|
+
Object.defineProperty(exports, "Disposable", { enumerable: true, get: function() {
|
|
3100
|
+
return disposable_1.Disposable;
|
|
3101
|
+
} });
|
|
3102
|
+
const events_1 = requireEvents();
|
|
3103
|
+
Object.defineProperty(exports, "Event", { enumerable: true, get: function() {
|
|
3104
|
+
return events_1.Event;
|
|
3105
|
+
} });
|
|
3106
|
+
Object.defineProperty(exports, "Emitter", { enumerable: true, get: function() {
|
|
3107
|
+
return events_1.Emitter;
|
|
3108
|
+
} });
|
|
3109
|
+
const cancellation_1 = requireCancellation();
|
|
3110
|
+
Object.defineProperty(exports, "CancellationTokenSource", { enumerable: true, get: function() {
|
|
3111
|
+
return cancellation_1.CancellationTokenSource;
|
|
3112
|
+
} });
|
|
3113
|
+
Object.defineProperty(exports, "CancellationToken", { enumerable: true, get: function() {
|
|
3114
|
+
return cancellation_1.CancellationToken;
|
|
3115
|
+
} });
|
|
3116
|
+
const sharedArrayCancellation_1 = requireSharedArrayCancellation();
|
|
3117
|
+
Object.defineProperty(exports, "SharedArraySenderStrategy", { enumerable: true, get: function() {
|
|
3118
|
+
return sharedArrayCancellation_1.SharedArraySenderStrategy;
|
|
3119
|
+
} });
|
|
3120
|
+
Object.defineProperty(exports, "SharedArrayReceiverStrategy", { enumerable: true, get: function() {
|
|
3121
|
+
return sharedArrayCancellation_1.SharedArrayReceiverStrategy;
|
|
3122
|
+
} });
|
|
3123
|
+
const messageReader_1 = requireMessageReader();
|
|
3124
|
+
Object.defineProperty(exports, "MessageReader", { enumerable: true, get: function() {
|
|
3125
|
+
return messageReader_1.MessageReader;
|
|
3126
|
+
} });
|
|
3127
|
+
Object.defineProperty(exports, "AbstractMessageReader", { enumerable: true, get: function() {
|
|
3128
|
+
return messageReader_1.AbstractMessageReader;
|
|
3129
|
+
} });
|
|
3130
|
+
Object.defineProperty(exports, "ReadableStreamMessageReader", { enumerable: true, get: function() {
|
|
3131
|
+
return messageReader_1.ReadableStreamMessageReader;
|
|
3132
|
+
} });
|
|
3133
|
+
const messageWriter_1 = requireMessageWriter();
|
|
3134
|
+
Object.defineProperty(exports, "MessageWriter", { enumerable: true, get: function() {
|
|
3135
|
+
return messageWriter_1.MessageWriter;
|
|
3136
|
+
} });
|
|
3137
|
+
Object.defineProperty(exports, "AbstractMessageWriter", { enumerable: true, get: function() {
|
|
3138
|
+
return messageWriter_1.AbstractMessageWriter;
|
|
3139
|
+
} });
|
|
3140
|
+
Object.defineProperty(exports, "WriteableStreamMessageWriter", { enumerable: true, get: function() {
|
|
3141
|
+
return messageWriter_1.WriteableStreamMessageWriter;
|
|
3142
|
+
} });
|
|
3143
|
+
const messageBuffer_1 = requireMessageBuffer();
|
|
3144
|
+
Object.defineProperty(exports, "AbstractMessageBuffer", { enumerable: true, get: function() {
|
|
3145
|
+
return messageBuffer_1.AbstractMessageBuffer;
|
|
3146
|
+
} });
|
|
3147
|
+
const connection_1 = requireConnection();
|
|
3148
|
+
Object.defineProperty(exports, "ConnectionStrategy", { enumerable: true, get: function() {
|
|
3149
|
+
return connection_1.ConnectionStrategy;
|
|
3150
|
+
} });
|
|
3151
|
+
Object.defineProperty(exports, "ConnectionOptions", { enumerable: true, get: function() {
|
|
3152
|
+
return connection_1.ConnectionOptions;
|
|
3153
|
+
} });
|
|
3154
|
+
Object.defineProperty(exports, "NullLogger", { enumerable: true, get: function() {
|
|
3155
|
+
return connection_1.NullLogger;
|
|
3156
|
+
} });
|
|
3157
|
+
Object.defineProperty(exports, "createMessageConnection", { enumerable: true, get: function() {
|
|
3158
|
+
return connection_1.createMessageConnection;
|
|
3159
|
+
} });
|
|
3160
|
+
Object.defineProperty(exports, "ProgressToken", { enumerable: true, get: function() {
|
|
3161
|
+
return connection_1.ProgressToken;
|
|
3162
|
+
} });
|
|
3163
|
+
Object.defineProperty(exports, "ProgressType", { enumerable: true, get: function() {
|
|
3164
|
+
return connection_1.ProgressType;
|
|
3165
|
+
} });
|
|
3166
|
+
Object.defineProperty(exports, "Trace", { enumerable: true, get: function() {
|
|
3167
|
+
return connection_1.Trace;
|
|
3168
|
+
} });
|
|
3169
|
+
Object.defineProperty(exports, "TraceValue", { enumerable: true, get: function() {
|
|
3170
|
+
return connection_1.TraceValue;
|
|
3171
|
+
} });
|
|
3172
|
+
Object.defineProperty(exports, "TraceFormat", { enumerable: true, get: function() {
|
|
3173
|
+
return connection_1.TraceFormat;
|
|
3174
|
+
} });
|
|
3175
|
+
Object.defineProperty(exports, "SetTraceNotification", { enumerable: true, get: function() {
|
|
3176
|
+
return connection_1.SetTraceNotification;
|
|
3177
|
+
} });
|
|
3178
|
+
Object.defineProperty(exports, "LogTraceNotification", { enumerable: true, get: function() {
|
|
3179
|
+
return connection_1.LogTraceNotification;
|
|
3180
|
+
} });
|
|
3181
|
+
Object.defineProperty(exports, "ConnectionErrors", { enumerable: true, get: function() {
|
|
3182
|
+
return connection_1.ConnectionErrors;
|
|
3183
|
+
} });
|
|
3184
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function() {
|
|
3185
|
+
return connection_1.ConnectionError;
|
|
3186
|
+
} });
|
|
3187
|
+
Object.defineProperty(exports, "CancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3188
|
+
return connection_1.CancellationReceiverStrategy;
|
|
3189
|
+
} });
|
|
3190
|
+
Object.defineProperty(exports, "IdCancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3191
|
+
return connection_1.IdCancellationReceiverStrategy;
|
|
3192
|
+
} });
|
|
3193
|
+
Object.defineProperty(exports, "RequestCancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3194
|
+
return connection_1.RequestCancellationReceiverStrategy;
|
|
3195
|
+
} });
|
|
3196
|
+
Object.defineProperty(exports, "CancellationSenderStrategy", { enumerable: true, get: function() {
|
|
3197
|
+
return connection_1.CancellationSenderStrategy;
|
|
3198
|
+
} });
|
|
3199
|
+
Object.defineProperty(exports, "CancellationStrategy", { enumerable: true, get: function() {
|
|
3200
|
+
return connection_1.CancellationStrategy;
|
|
3201
|
+
} });
|
|
3202
|
+
Object.defineProperty(exports, "MessageStrategy", { enumerable: true, get: function() {
|
|
3203
|
+
return connection_1.MessageStrategy;
|
|
3204
|
+
} });
|
|
3205
|
+
Object.defineProperty(exports, "TraceValues", { enumerable: true, get: function() {
|
|
3206
|
+
return connection_1.TraceValues;
|
|
3207
|
+
} });
|
|
3208
|
+
const ral_1 = __importDefault(requireRal());
|
|
3209
|
+
exports.RAL = ral_1.default;
|
|
3210
|
+
})(api);
|
|
3211
|
+
return api;
|
|
3212
|
+
}
|
|
3213
|
+
requireApi();
|
|
3214
|
+
function asElectronIPC(receiver, sender) {
|
|
3215
|
+
return {
|
|
3216
|
+
on: receiver.on.bind(receiver),
|
|
3217
|
+
off: receiver.off.bind(receiver),
|
|
3218
|
+
send: sender.send.bind(sender)
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3221
|
+
let send;
|
|
3222
|
+
let resolved = false;
|
|
3223
|
+
function resolve(value, exitCode = 0) {
|
|
3224
|
+
if (resolved) return;
|
|
3225
|
+
resolved = true;
|
|
3226
|
+
const message = { type: "resolve", value };
|
|
3227
|
+
send(message);
|
|
3228
|
+
app.exit(exitCode);
|
|
3229
|
+
}
|
|
3230
|
+
const __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
3231
|
+
const preloadPath = path.join(__dirname$1, "../preload/index.mjs");
|
|
3232
|
+
const mcpHandlesByWindow = /* @__PURE__ */ new Map();
|
|
3233
|
+
function findMcpHandle(win, key) {
|
|
3234
|
+
for (let current = win; current; current = current.getParentWindow()) {
|
|
3235
|
+
const handle2 = mcpHandlesByWindow.get(current.id)?.get(key);
|
|
3236
|
+
if (handle2) return handle2;
|
|
3237
|
+
}
|
|
3238
|
+
return void 0;
|
|
3239
|
+
}
|
|
3240
|
+
function getMcpAddress(win, packageName, version) {
|
|
3241
|
+
const key = `${packageName}@${version ?? ""}`;
|
|
3242
|
+
const existing = findMcpHandle(win, key);
|
|
3243
|
+
if (existing) return existing.then(({ address }) => address);
|
|
3244
|
+
const handle2 = runAsMcp(import.meta, packageName, version);
|
|
3245
|
+
let owned = mcpHandlesByWindow.get(win.id);
|
|
3246
|
+
if (!owned) mcpHandlesByWindow.set(win.id, owned = /* @__PURE__ */ new Map());
|
|
3247
|
+
owned.set(key, handle2);
|
|
3248
|
+
handle2.catch(() => owned.delete(key));
|
|
3249
|
+
return handle2.then(({ address }) => address);
|
|
3250
|
+
}
|
|
3251
|
+
function disposeWindowMcpHandles(windowId) {
|
|
3252
|
+
const owned = mcpHandlesByWindow.get(windowId);
|
|
3253
|
+
if (!owned) return;
|
|
3254
|
+
mcpHandlesByWindow.delete(windowId);
|
|
3255
|
+
for (const handle2 of owned.values())
|
|
3256
|
+
handle2.then(({ dispose }) => dispose()).catch(() => {
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
3259
|
+
app.on("before-quit", () => {
|
|
3260
|
+
for (const windowId of [...mcpHandlesByWindow.keys()])
|
|
3261
|
+
disposeWindowMcpHandles(windowId);
|
|
3262
|
+
});
|
|
3263
|
+
async function createWindow(parameters, finish = resolve, parent) {
|
|
3264
|
+
const { app: app2, address, type, source, width, height } = parameters;
|
|
3265
|
+
const win = new BrowserWindow({
|
|
3266
|
+
parent,
|
|
3267
|
+
width: width ?? 900,
|
|
3268
|
+
height: height ?? 670,
|
|
3269
|
+
show: false,
|
|
3270
|
+
autoHideMenuBar: true,
|
|
3271
|
+
title: app2,
|
|
3272
|
+
webPreferences: {
|
|
3273
|
+
preload: preloadPath,
|
|
3274
|
+
contextIsolation: true,
|
|
3275
|
+
nodeIntegration: false,
|
|
3276
|
+
sandbox: true
|
|
3277
|
+
}
|
|
3278
|
+
});
|
|
3279
|
+
const ui = new CmdlessUI((parameters2) => new Promise((resolve2, reject) => {
|
|
3280
|
+
try {
|
|
3281
|
+
handle(parameters2, (value, exitCode = 0) => {
|
|
3282
|
+
if (exitCode !== 0) {
|
|
3283
|
+
reject(new Error(`UI command exited with code ${exitCode}`));
|
|
3284
|
+
return;
|
|
3285
|
+
}
|
|
3286
|
+
resolve2(binOutput(value));
|
|
3287
|
+
}, win);
|
|
3288
|
+
} catch (error) {
|
|
3289
|
+
reject(error);
|
|
3290
|
+
}
|
|
3291
|
+
}));
|
|
3292
|
+
const ipc = cmdlessIPC.createServer(createElectronIPC(asElectronIPC(win.webContents.ipc, win.webContents)));
|
|
3293
|
+
ipc.onNotification.resolve(({ value, exitCode }) => finish(value, exitCode));
|
|
3294
|
+
ipc.onRequest.ui((parameters2) => ui.run(parameters2));
|
|
3295
|
+
ipc.onRequest.connectionInfo(() => ({ address, windowId: win.id }));
|
|
3296
|
+
ipc.onRequest.mcpAddress(({ packageName, version }) => getMcpAddress(win, packageName, version).then((address2) => ({ address: address2 })));
|
|
3297
|
+
ipc.listen();
|
|
3298
|
+
win.on("closed", () => {
|
|
3299
|
+
finish(null);
|
|
3300
|
+
disposeWindowMcpHandles(win.id);
|
|
3301
|
+
});
|
|
3302
|
+
win.on("ready-to-show", () => win.show());
|
|
3303
|
+
win.webContents.setWindowOpenHandler((details) => {
|
|
3304
|
+
shell.openExternal(details.url);
|
|
3305
|
+
return { action: "deny" };
|
|
3306
|
+
});
|
|
3307
|
+
if (type === "url") await win.loadURL(source);
|
|
3308
|
+
else await win.loadFile(source);
|
|
3309
|
+
return win;
|
|
3310
|
+
}
|
|
3311
|
+
function handle(parameters, finish = resolve, parent) {
|
|
3312
|
+
if (!parent && parameters.parent)
|
|
3313
|
+
parent = BrowserWindow.fromId(parameters.parent) ?? void 0;
|
|
3314
|
+
switch (parameters.kind) {
|
|
3315
|
+
case "show":
|
|
3316
|
+
createWindow(parameters, finish, parent);
|
|
3317
|
+
break;
|
|
3318
|
+
case "message-box":
|
|
3319
|
+
const messageBox = parent ? dialog.showMessageBox(parent, parameters) : dialog.showMessageBox(parameters);
|
|
3320
|
+
messageBox.then(finish);
|
|
3321
|
+
break;
|
|
3322
|
+
default:
|
|
3323
|
+
throw new Error(`Unsupported kind: ${JSON.stringify(parameters, null, 2)}`);
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
async function run(parameters, finish = resolve) {
|
|
3327
|
+
const appName = parameters.app || CmdlessEnv.app || `${getEphemeralPrefix()}${crypto.randomUUID()}`;
|
|
3328
|
+
parameters.app = CmdlessEnv.app = appName;
|
|
3329
|
+
app.setName(appName);
|
|
3330
|
+
app.setPath("userData", path.join(app.getPath("appData"), appName));
|
|
3331
|
+
if (appName.startsWith(getEphemeralPrefix())) {
|
|
3332
|
+
const message = { type: "cleanup", appName, userData: app.getPath("userData") };
|
|
3333
|
+
send(message);
|
|
3334
|
+
}
|
|
3335
|
+
const waiter = new MessageSocketWaiter().start();
|
|
3336
|
+
const additionalData = { ...parameters, id: waiter.id };
|
|
3337
|
+
if (!app.requestSingleInstanceLock(additionalData)) {
|
|
3338
|
+
return waiter.withResult((message) => finish(message.value, message.exitCode));
|
|
3339
|
+
}
|
|
3340
|
+
waiter.stop();
|
|
3341
|
+
app.on("second-instance", (_, __, ___, data) => {
|
|
3342
|
+
const { id, ...parameters2 } = data;
|
|
3343
|
+
const resolve2 = waiter.connect(id);
|
|
3344
|
+
handle(parameters2, (value, exitCode = 0) => resolve2({ value, exitCode }));
|
|
3345
|
+
});
|
|
3346
|
+
await app.whenReady();
|
|
3347
|
+
electronApp.setAppUserModelId("dev.cmdless.ui");
|
|
3348
|
+
app.on("browser-window-created", (_, window) => {
|
|
3349
|
+
optimizer.watchWindowShortcuts(window);
|
|
3350
|
+
});
|
|
3351
|
+
app.on("window-all-closed", () => finish(null));
|
|
3352
|
+
handle(parameters, finish);
|
|
3353
|
+
}
|
|
3354
|
+
function cli() {
|
|
3355
|
+
const program = new Command();
|
|
3356
|
+
program.command("show").description("Show content inside of an Electron browser window").addArgument(new Argument("<type>", "Source type to show in the window").choices(types.ShowTypes)).argument("<source>", "File or URL to open in the window").option("--app <name>", "App name, used to group processes and parent windows and dialogs").option("--parent <id>", "ID of the Electron Browsser Window to use as the parent for the window", Number).option("--width <number>", "Width of the window", Number).option("--height <number>", "Height of the window", Number).option("--address <address>", "Backend address").action((type, source, options) => run({ kind: "show", type, source, ...options }));
|
|
3357
|
+
program.command("message-box").description("Display a simple Electron message box").addArgument(new Argument("<type>", "Type of message").choices(types.MessageBoxTypes).default("none")).argument("<message>", "Message to display in the message box").option("--app <name>", "App name, used to group processes and parent windows and dialogs").option("--parent <id>", "ID of the Electron Browsser Window to use as the parent for the dialog", Number).action((type, message, options) => run({ kind: "message-box", type, message, ...options }));
|
|
3358
|
+
return program;
|
|
3359
|
+
}
|
|
3360
|
+
async function main() {
|
|
3361
|
+
send = await BinChannel.connect();
|
|
3362
|
+
process.on("SIGINT", () => resolve(null));
|
|
3363
|
+
process.on("SIGTERM", () => resolve(null));
|
|
3364
|
+
await cli().parseAsync();
|
|
3365
|
+
}
|
|
3366
|
+
void main().catch((error) => {
|
|
3367
|
+
console.error(error);
|
|
3368
|
+
app.exit(1);
|
|
3369
|
+
});
|