@cmdless/ui-runtime 0.0.0 → 0.0.5
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 +13 -35
- package/out/main/bin.js +40 -0
- package/out/main/cleanup.js +20 -0
- package/out/main/host.js +79 -0
- package/out/main/hosting.js +448 -0
- package/out/preload/index.cjs +4601 -0
- package/out/renderer/assets/Card-BUDQ1UVY.js +15054 -0
- package/out/renderer/assets/Form-B5fhb-x2.css +1121 -0
- package/out/renderer/assets/Form-CE3B5mnl.js +26 -0
- package/out/renderer/assets/Mantine.context-oJEjRkJu.js +574 -0
- package/out/renderer/assets/MantineThemeProvider-DHX5fzKn.js +995 -0
- package/out/renderer/assets/SchemaInput-CACjraGT.js +69 -0
- package/out/renderer/assets/preload-helper-DVzrZ_Op.js +64 -0
- package/out/renderer/assets/use-media-query-d0EeyoH9.js +34 -0
- package/out/renderer/assets/validator-_xTzn1fv.js +31760 -0
- package/out/renderer/assets/view-Chm2p5Ws.js +20542 -0
- package/out/renderer/assets/view-DptMSuIE.css +10034 -0
- package/out/renderer/view.html +21 -0
- package/package.json +54 -7
|
@@ -0,0 +1,4601 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const electron = require("electron");
|
|
3
|
+
var main = {};
|
|
4
|
+
var ril = {};
|
|
5
|
+
var api = {};
|
|
6
|
+
var messages = {};
|
|
7
|
+
var is = {};
|
|
8
|
+
var hasRequiredIs;
|
|
9
|
+
function requireIs() {
|
|
10
|
+
if (hasRequiredIs) return is;
|
|
11
|
+
hasRequiredIs = 1;
|
|
12
|
+
Object.defineProperty(is, "__esModule", { value: true });
|
|
13
|
+
is.boolean = boolean;
|
|
14
|
+
is.string = string;
|
|
15
|
+
is.number = number;
|
|
16
|
+
is.error = error;
|
|
17
|
+
is.func = func;
|
|
18
|
+
is.array = array;
|
|
19
|
+
is.stringArray = stringArray;
|
|
20
|
+
function boolean(value) {
|
|
21
|
+
return value === true || value === false;
|
|
22
|
+
}
|
|
23
|
+
function string(value) {
|
|
24
|
+
return typeof value === "string" || value instanceof String;
|
|
25
|
+
}
|
|
26
|
+
function number(value) {
|
|
27
|
+
return typeof value === "number" || value instanceof Number;
|
|
28
|
+
}
|
|
29
|
+
function error(value) {
|
|
30
|
+
return value instanceof Error;
|
|
31
|
+
}
|
|
32
|
+
function func(value) {
|
|
33
|
+
return typeof value === "function";
|
|
34
|
+
}
|
|
35
|
+
function array(value) {
|
|
36
|
+
return Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
function stringArray(value) {
|
|
39
|
+
return array(value) && value.every((elem) => string(elem));
|
|
40
|
+
}
|
|
41
|
+
return is;
|
|
42
|
+
}
|
|
43
|
+
var hasRequiredMessages;
|
|
44
|
+
function requireMessages() {
|
|
45
|
+
if (hasRequiredMessages) return messages;
|
|
46
|
+
hasRequiredMessages = 1;
|
|
47
|
+
var __createBinding = messages && messages.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
48
|
+
if (k2 === void 0) k2 = k;
|
|
49
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
50
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
51
|
+
desc = { enumerable: true, get: function() {
|
|
52
|
+
return m[k];
|
|
53
|
+
} };
|
|
54
|
+
}
|
|
55
|
+
Object.defineProperty(o, k2, desc);
|
|
56
|
+
}) : (function(o, m, k, k2) {
|
|
57
|
+
if (k2 === void 0) k2 = k;
|
|
58
|
+
o[k2] = m[k];
|
|
59
|
+
}));
|
|
60
|
+
var __setModuleDefault = messages && messages.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
61
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
62
|
+
}) : function(o, v) {
|
|
63
|
+
o["default"] = v;
|
|
64
|
+
});
|
|
65
|
+
var __importStar = messages && messages.__importStar || /* @__PURE__ */ (function() {
|
|
66
|
+
var ownKeys = function(o) {
|
|
67
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
68
|
+
var ar = [];
|
|
69
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
70
|
+
return ar;
|
|
71
|
+
};
|
|
72
|
+
return ownKeys(o);
|
|
73
|
+
};
|
|
74
|
+
return function(mod) {
|
|
75
|
+
if (mod && mod.__esModule) return mod;
|
|
76
|
+
var result = {};
|
|
77
|
+
if (mod != null) {
|
|
78
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
79
|
+
}
|
|
80
|
+
__setModuleDefault(result, mod);
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
})();
|
|
84
|
+
Object.defineProperty(messages, "__esModule", { value: true });
|
|
85
|
+
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;
|
|
86
|
+
const is2 = __importStar(requireIs());
|
|
87
|
+
var ErrorCodes;
|
|
88
|
+
(function(ErrorCodes2) {
|
|
89
|
+
ErrorCodes2.ParseError = -32700;
|
|
90
|
+
ErrorCodes2.InvalidRequest = -32600;
|
|
91
|
+
ErrorCodes2.MethodNotFound = -32601;
|
|
92
|
+
ErrorCodes2.InvalidParams = -32602;
|
|
93
|
+
ErrorCodes2.InternalError = -32603;
|
|
94
|
+
ErrorCodes2.jsonrpcReservedErrorRangeStart = -32099;
|
|
95
|
+
ErrorCodes2.serverErrorStart = -32099;
|
|
96
|
+
ErrorCodes2.MessageWriteError = -32099;
|
|
97
|
+
ErrorCodes2.MessageReadError = -32098;
|
|
98
|
+
ErrorCodes2.PendingResponseRejected = -32097;
|
|
99
|
+
ErrorCodes2.ConnectionInactive = -32096;
|
|
100
|
+
ErrorCodes2.ServerNotInitialized = -32002;
|
|
101
|
+
ErrorCodes2.UnknownErrorCode = -32001;
|
|
102
|
+
ErrorCodes2.jsonrpcReservedErrorRangeEnd = -32e3;
|
|
103
|
+
ErrorCodes2.serverErrorEnd = -32e3;
|
|
104
|
+
})(ErrorCodes || (messages.ErrorCodes = ErrorCodes = {}));
|
|
105
|
+
class ResponseError extends Error {
|
|
106
|
+
code;
|
|
107
|
+
data;
|
|
108
|
+
constructor(code, message, data) {
|
|
109
|
+
super(message);
|
|
110
|
+
this.code = is2.number(code) ? code : ErrorCodes.UnknownErrorCode;
|
|
111
|
+
this.data = data;
|
|
112
|
+
Object.setPrototypeOf(this, ResponseError.prototype);
|
|
113
|
+
}
|
|
114
|
+
toJson() {
|
|
115
|
+
const result = {
|
|
116
|
+
code: this.code,
|
|
117
|
+
message: this.message
|
|
118
|
+
};
|
|
119
|
+
if (this.data !== void 0) {
|
|
120
|
+
result.data = this.data;
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
messages.ResponseError = ResponseError;
|
|
126
|
+
class ParameterStructures {
|
|
127
|
+
kind;
|
|
128
|
+
/**
|
|
129
|
+
* The parameter structure is automatically inferred on the number of parameters
|
|
130
|
+
* and the parameter type in case of a single param.
|
|
131
|
+
*/
|
|
132
|
+
static auto = new ParameterStructures("auto");
|
|
133
|
+
/**
|
|
134
|
+
* Forces `byPosition` parameter structure. This is useful if you have a single
|
|
135
|
+
* parameter which has a literal type.
|
|
136
|
+
*/
|
|
137
|
+
static byPosition = new ParameterStructures("byPosition");
|
|
138
|
+
/**
|
|
139
|
+
* Forces `byName` parameter structure. This is only useful when having a single
|
|
140
|
+
* parameter. The library will report errors if used with a different number of
|
|
141
|
+
* parameters.
|
|
142
|
+
*/
|
|
143
|
+
static byName = new ParameterStructures("byName");
|
|
144
|
+
constructor(kind) {
|
|
145
|
+
this.kind = kind;
|
|
146
|
+
}
|
|
147
|
+
static is(value) {
|
|
148
|
+
return value === ParameterStructures.auto || value === ParameterStructures.byName || value === ParameterStructures.byPosition;
|
|
149
|
+
}
|
|
150
|
+
toString() {
|
|
151
|
+
return this.kind;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
messages.ParameterStructures = ParameterStructures;
|
|
155
|
+
class AbstractMessageSignature {
|
|
156
|
+
method;
|
|
157
|
+
numberOfParams;
|
|
158
|
+
constructor(method, numberOfParams) {
|
|
159
|
+
this.method = method;
|
|
160
|
+
this.numberOfParams = numberOfParams;
|
|
161
|
+
}
|
|
162
|
+
get parameterStructures() {
|
|
163
|
+
return ParameterStructures.auto;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
messages.AbstractMessageSignature = AbstractMessageSignature;
|
|
167
|
+
class RequestType0 extends AbstractMessageSignature {
|
|
168
|
+
/**
|
|
169
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
170
|
+
*/
|
|
171
|
+
_;
|
|
172
|
+
constructor(method) {
|
|
173
|
+
super(method, 0);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
messages.RequestType0 = RequestType0;
|
|
177
|
+
class RequestType extends AbstractMessageSignature {
|
|
178
|
+
_parameterStructures;
|
|
179
|
+
/**
|
|
180
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
181
|
+
*/
|
|
182
|
+
_;
|
|
183
|
+
constructor(method, _parameterStructures = ParameterStructures.auto) {
|
|
184
|
+
super(method, 1);
|
|
185
|
+
this._parameterStructures = _parameterStructures;
|
|
186
|
+
}
|
|
187
|
+
get parameterStructures() {
|
|
188
|
+
return this._parameterStructures;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
messages.RequestType = RequestType;
|
|
192
|
+
class RequestType1 extends AbstractMessageSignature {
|
|
193
|
+
_parameterStructures;
|
|
194
|
+
/**
|
|
195
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
196
|
+
*/
|
|
197
|
+
_;
|
|
198
|
+
constructor(method, _parameterStructures = ParameterStructures.auto) {
|
|
199
|
+
super(method, 1);
|
|
200
|
+
this._parameterStructures = _parameterStructures;
|
|
201
|
+
}
|
|
202
|
+
get parameterStructures() {
|
|
203
|
+
return this._parameterStructures;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
messages.RequestType1 = RequestType1;
|
|
207
|
+
class RequestType2 extends AbstractMessageSignature {
|
|
208
|
+
/**
|
|
209
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
210
|
+
*/
|
|
211
|
+
_;
|
|
212
|
+
constructor(method) {
|
|
213
|
+
super(method, 2);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
messages.RequestType2 = RequestType2;
|
|
217
|
+
class RequestType3 extends AbstractMessageSignature {
|
|
218
|
+
/**
|
|
219
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
220
|
+
*/
|
|
221
|
+
_;
|
|
222
|
+
constructor(method) {
|
|
223
|
+
super(method, 3);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
messages.RequestType3 = RequestType3;
|
|
227
|
+
class RequestType4 extends AbstractMessageSignature {
|
|
228
|
+
/**
|
|
229
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
230
|
+
*/
|
|
231
|
+
_;
|
|
232
|
+
constructor(method) {
|
|
233
|
+
super(method, 4);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
messages.RequestType4 = RequestType4;
|
|
237
|
+
class RequestType5 extends AbstractMessageSignature {
|
|
238
|
+
/**
|
|
239
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
240
|
+
*/
|
|
241
|
+
_;
|
|
242
|
+
constructor(method) {
|
|
243
|
+
super(method, 5);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
messages.RequestType5 = RequestType5;
|
|
247
|
+
class RequestType6 extends AbstractMessageSignature {
|
|
248
|
+
/**
|
|
249
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
250
|
+
*/
|
|
251
|
+
_;
|
|
252
|
+
constructor(method) {
|
|
253
|
+
super(method, 6);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
messages.RequestType6 = RequestType6;
|
|
257
|
+
class RequestType7 extends AbstractMessageSignature {
|
|
258
|
+
/**
|
|
259
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
260
|
+
*/
|
|
261
|
+
_;
|
|
262
|
+
constructor(method) {
|
|
263
|
+
super(method, 7);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
messages.RequestType7 = RequestType7;
|
|
267
|
+
class RequestType8 extends AbstractMessageSignature {
|
|
268
|
+
/**
|
|
269
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
270
|
+
*/
|
|
271
|
+
_;
|
|
272
|
+
constructor(method) {
|
|
273
|
+
super(method, 8);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
messages.RequestType8 = RequestType8;
|
|
277
|
+
class RequestType9 extends AbstractMessageSignature {
|
|
278
|
+
/**
|
|
279
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
280
|
+
*/
|
|
281
|
+
_;
|
|
282
|
+
constructor(method) {
|
|
283
|
+
super(method, 9);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
messages.RequestType9 = RequestType9;
|
|
287
|
+
class NotificationType extends AbstractMessageSignature {
|
|
288
|
+
_parameterStructures;
|
|
289
|
+
/**
|
|
290
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
291
|
+
*/
|
|
292
|
+
_;
|
|
293
|
+
constructor(method, _parameterStructures = ParameterStructures.auto) {
|
|
294
|
+
super(method, 1);
|
|
295
|
+
this._parameterStructures = _parameterStructures;
|
|
296
|
+
}
|
|
297
|
+
get parameterStructures() {
|
|
298
|
+
return this._parameterStructures;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
messages.NotificationType = NotificationType;
|
|
302
|
+
class NotificationType0 extends AbstractMessageSignature {
|
|
303
|
+
/**
|
|
304
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
305
|
+
*/
|
|
306
|
+
_;
|
|
307
|
+
constructor(method) {
|
|
308
|
+
super(method, 0);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
messages.NotificationType0 = NotificationType0;
|
|
312
|
+
class NotificationType1 extends AbstractMessageSignature {
|
|
313
|
+
_parameterStructures;
|
|
314
|
+
/**
|
|
315
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
316
|
+
*/
|
|
317
|
+
_;
|
|
318
|
+
constructor(method, _parameterStructures = ParameterStructures.auto) {
|
|
319
|
+
super(method, 1);
|
|
320
|
+
this._parameterStructures = _parameterStructures;
|
|
321
|
+
}
|
|
322
|
+
get parameterStructures() {
|
|
323
|
+
return this._parameterStructures;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
messages.NotificationType1 = NotificationType1;
|
|
327
|
+
class NotificationType2 extends AbstractMessageSignature {
|
|
328
|
+
/**
|
|
329
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
330
|
+
*/
|
|
331
|
+
_;
|
|
332
|
+
constructor(method) {
|
|
333
|
+
super(method, 2);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
messages.NotificationType2 = NotificationType2;
|
|
337
|
+
class NotificationType3 extends AbstractMessageSignature {
|
|
338
|
+
/**
|
|
339
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
340
|
+
*/
|
|
341
|
+
_;
|
|
342
|
+
constructor(method) {
|
|
343
|
+
super(method, 3);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
messages.NotificationType3 = NotificationType3;
|
|
347
|
+
class NotificationType4 extends AbstractMessageSignature {
|
|
348
|
+
/**
|
|
349
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
350
|
+
*/
|
|
351
|
+
_;
|
|
352
|
+
constructor(method) {
|
|
353
|
+
super(method, 4);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
messages.NotificationType4 = NotificationType4;
|
|
357
|
+
class NotificationType5 extends AbstractMessageSignature {
|
|
358
|
+
/**
|
|
359
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
360
|
+
*/
|
|
361
|
+
_;
|
|
362
|
+
constructor(method) {
|
|
363
|
+
super(method, 5);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
messages.NotificationType5 = NotificationType5;
|
|
367
|
+
class NotificationType6 extends AbstractMessageSignature {
|
|
368
|
+
/**
|
|
369
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
370
|
+
*/
|
|
371
|
+
_;
|
|
372
|
+
constructor(method) {
|
|
373
|
+
super(method, 6);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
messages.NotificationType6 = NotificationType6;
|
|
377
|
+
class NotificationType7 extends AbstractMessageSignature {
|
|
378
|
+
/**
|
|
379
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
380
|
+
*/
|
|
381
|
+
_;
|
|
382
|
+
constructor(method) {
|
|
383
|
+
super(method, 7);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
messages.NotificationType7 = NotificationType7;
|
|
387
|
+
class NotificationType8 extends AbstractMessageSignature {
|
|
388
|
+
/**
|
|
389
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
390
|
+
*/
|
|
391
|
+
_;
|
|
392
|
+
constructor(method) {
|
|
393
|
+
super(method, 8);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
messages.NotificationType8 = NotificationType8;
|
|
397
|
+
class NotificationType9 extends AbstractMessageSignature {
|
|
398
|
+
/**
|
|
399
|
+
* Clients must not use this property. It is here to ensure correct typing.
|
|
400
|
+
*/
|
|
401
|
+
_;
|
|
402
|
+
constructor(method) {
|
|
403
|
+
super(method, 9);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
messages.NotificationType9 = NotificationType9;
|
|
407
|
+
var Message;
|
|
408
|
+
(function(Message2) {
|
|
409
|
+
function isRequest(message) {
|
|
410
|
+
const candidate = message;
|
|
411
|
+
return candidate && is2.string(candidate.method) && (is2.string(candidate.id) || is2.number(candidate.id));
|
|
412
|
+
}
|
|
413
|
+
Message2.isRequest = isRequest;
|
|
414
|
+
function isNotification(message) {
|
|
415
|
+
const candidate = message;
|
|
416
|
+
return candidate && is2.string(candidate.method) && message.id === void 0;
|
|
417
|
+
}
|
|
418
|
+
Message2.isNotification = isNotification;
|
|
419
|
+
function isResponse(message) {
|
|
420
|
+
const candidate = message;
|
|
421
|
+
return candidate && (candidate.result !== void 0 || !!candidate.error) && (is2.string(candidate.id) || is2.number(candidate.id) || candidate.id === null);
|
|
422
|
+
}
|
|
423
|
+
Message2.isResponse = isResponse;
|
|
424
|
+
})(Message || (messages.Message = Message = {}));
|
|
425
|
+
return messages;
|
|
426
|
+
}
|
|
427
|
+
var linkedMap = {};
|
|
428
|
+
var hasRequiredLinkedMap;
|
|
429
|
+
function requireLinkedMap() {
|
|
430
|
+
if (hasRequiredLinkedMap) return linkedMap;
|
|
431
|
+
hasRequiredLinkedMap = 1;
|
|
432
|
+
Object.defineProperty(linkedMap, "__esModule", { value: true });
|
|
433
|
+
linkedMap.LRUCache = linkedMap.LinkedMap = linkedMap.Touch = void 0;
|
|
434
|
+
var Touch;
|
|
435
|
+
(function(Touch2) {
|
|
436
|
+
Touch2.None = 0;
|
|
437
|
+
Touch2.First = 1;
|
|
438
|
+
Touch2.AsOld = Touch2.First;
|
|
439
|
+
Touch2.Last = 2;
|
|
440
|
+
Touch2.AsNew = Touch2.Last;
|
|
441
|
+
})(Touch || (linkedMap.Touch = Touch = {}));
|
|
442
|
+
class LinkedMap {
|
|
443
|
+
[Symbol.toStringTag] = "LinkedMap";
|
|
444
|
+
_map;
|
|
445
|
+
_head;
|
|
446
|
+
_tail;
|
|
447
|
+
_size;
|
|
448
|
+
_state;
|
|
449
|
+
constructor() {
|
|
450
|
+
this._map = /* @__PURE__ */ new Map();
|
|
451
|
+
this._head = void 0;
|
|
452
|
+
this._tail = void 0;
|
|
453
|
+
this._size = 0;
|
|
454
|
+
this._state = 0;
|
|
455
|
+
}
|
|
456
|
+
clear() {
|
|
457
|
+
this._map.clear();
|
|
458
|
+
this._head = void 0;
|
|
459
|
+
this._tail = void 0;
|
|
460
|
+
this._size = 0;
|
|
461
|
+
this._state++;
|
|
462
|
+
}
|
|
463
|
+
isEmpty() {
|
|
464
|
+
return !this._head && !this._tail;
|
|
465
|
+
}
|
|
466
|
+
get size() {
|
|
467
|
+
return this._size;
|
|
468
|
+
}
|
|
469
|
+
get first() {
|
|
470
|
+
return this._head?.value;
|
|
471
|
+
}
|
|
472
|
+
get last() {
|
|
473
|
+
return this._tail?.value;
|
|
474
|
+
}
|
|
475
|
+
before(key) {
|
|
476
|
+
const item = this._map.get(key);
|
|
477
|
+
return item ? item.previous?.value : void 0;
|
|
478
|
+
}
|
|
479
|
+
after(key) {
|
|
480
|
+
const item = this._map.get(key);
|
|
481
|
+
return item ? item.next?.value : void 0;
|
|
482
|
+
}
|
|
483
|
+
has(key) {
|
|
484
|
+
return this._map.has(key);
|
|
485
|
+
}
|
|
486
|
+
get(key, touch = Touch.None) {
|
|
487
|
+
const item = this._map.get(key);
|
|
488
|
+
if (!item) {
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
if (touch !== Touch.None) {
|
|
492
|
+
this.touch(item, touch);
|
|
493
|
+
}
|
|
494
|
+
return item.value;
|
|
495
|
+
}
|
|
496
|
+
set(key, value, touch = Touch.None) {
|
|
497
|
+
let item = this._map.get(key);
|
|
498
|
+
if (item) {
|
|
499
|
+
item.value = value;
|
|
500
|
+
if (touch !== Touch.None) {
|
|
501
|
+
this.touch(item, touch);
|
|
502
|
+
}
|
|
503
|
+
} else {
|
|
504
|
+
item = { key, value, next: void 0, previous: void 0 };
|
|
505
|
+
switch (touch) {
|
|
506
|
+
case Touch.None:
|
|
507
|
+
this.addItemLast(item);
|
|
508
|
+
break;
|
|
509
|
+
case Touch.First:
|
|
510
|
+
this.addItemFirst(item);
|
|
511
|
+
break;
|
|
512
|
+
case Touch.Last:
|
|
513
|
+
this.addItemLast(item);
|
|
514
|
+
break;
|
|
515
|
+
default:
|
|
516
|
+
this.addItemLast(item);
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
this._map.set(key, item);
|
|
520
|
+
this._size++;
|
|
521
|
+
}
|
|
522
|
+
return this;
|
|
523
|
+
}
|
|
524
|
+
delete(key) {
|
|
525
|
+
return !!this.remove(key);
|
|
526
|
+
}
|
|
527
|
+
remove(key) {
|
|
528
|
+
const item = this._map.get(key);
|
|
529
|
+
if (!item) {
|
|
530
|
+
return void 0;
|
|
531
|
+
}
|
|
532
|
+
this._map.delete(key);
|
|
533
|
+
this.removeItem(item);
|
|
534
|
+
this._size--;
|
|
535
|
+
return item.value;
|
|
536
|
+
}
|
|
537
|
+
shift() {
|
|
538
|
+
if (!this._head && !this._tail) {
|
|
539
|
+
return void 0;
|
|
540
|
+
}
|
|
541
|
+
if (!this._head || !this._tail) {
|
|
542
|
+
throw new Error("Invalid list");
|
|
543
|
+
}
|
|
544
|
+
const item = this._head;
|
|
545
|
+
this._map.delete(item.key);
|
|
546
|
+
this.removeItem(item);
|
|
547
|
+
this._size--;
|
|
548
|
+
return item.value;
|
|
549
|
+
}
|
|
550
|
+
forEach(callbackfn, thisArg) {
|
|
551
|
+
const state2 = this._state;
|
|
552
|
+
let current = this._head;
|
|
553
|
+
while (current) {
|
|
554
|
+
if (thisArg) {
|
|
555
|
+
callbackfn.bind(thisArg)(current.value, current.key, this);
|
|
556
|
+
} else {
|
|
557
|
+
callbackfn(current.value, current.key, this);
|
|
558
|
+
}
|
|
559
|
+
if (this._state !== state2) {
|
|
560
|
+
throw new Error(`LinkedMap got modified during iteration.`);
|
|
561
|
+
}
|
|
562
|
+
current = current.next;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
keys() {
|
|
566
|
+
const state2 = this._state;
|
|
567
|
+
let current = this._head;
|
|
568
|
+
const iterator = {
|
|
569
|
+
[Symbol.iterator]: () => {
|
|
570
|
+
return iterator;
|
|
571
|
+
},
|
|
572
|
+
next: () => {
|
|
573
|
+
if (this._state !== state2) {
|
|
574
|
+
throw new Error(`LinkedMap got modified during iteration.`);
|
|
575
|
+
}
|
|
576
|
+
if (current) {
|
|
577
|
+
const result = { value: current.key, done: false };
|
|
578
|
+
current = current.next;
|
|
579
|
+
return result;
|
|
580
|
+
} else {
|
|
581
|
+
return { value: void 0, done: true };
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
return iterator;
|
|
586
|
+
}
|
|
587
|
+
values() {
|
|
588
|
+
const state2 = this._state;
|
|
589
|
+
let current = this._head;
|
|
590
|
+
const iterator = {
|
|
591
|
+
[Symbol.iterator]: () => {
|
|
592
|
+
return iterator;
|
|
593
|
+
},
|
|
594
|
+
next: () => {
|
|
595
|
+
if (this._state !== state2) {
|
|
596
|
+
throw new Error(`LinkedMap got modified during iteration.`);
|
|
597
|
+
}
|
|
598
|
+
if (current) {
|
|
599
|
+
const result = { value: current.value, done: false };
|
|
600
|
+
current = current.next;
|
|
601
|
+
return result;
|
|
602
|
+
} else {
|
|
603
|
+
return { value: void 0, done: true };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
return iterator;
|
|
608
|
+
}
|
|
609
|
+
entries() {
|
|
610
|
+
const state2 = this._state;
|
|
611
|
+
let current = this._head;
|
|
612
|
+
const iterator = {
|
|
613
|
+
[Symbol.iterator]: () => {
|
|
614
|
+
return iterator;
|
|
615
|
+
},
|
|
616
|
+
next: () => {
|
|
617
|
+
if (this._state !== state2) {
|
|
618
|
+
throw new Error(`LinkedMap got modified during iteration.`);
|
|
619
|
+
}
|
|
620
|
+
if (current) {
|
|
621
|
+
const result = { value: [current.key, current.value], done: false };
|
|
622
|
+
current = current.next;
|
|
623
|
+
return result;
|
|
624
|
+
} else {
|
|
625
|
+
return { value: void 0, done: true };
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
return iterator;
|
|
630
|
+
}
|
|
631
|
+
[Symbol.iterator]() {
|
|
632
|
+
return this.entries();
|
|
633
|
+
}
|
|
634
|
+
trimOld(newSize) {
|
|
635
|
+
if (newSize >= this.size) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (newSize === 0) {
|
|
639
|
+
this.clear();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
let current = this._head;
|
|
643
|
+
let currentSize = this.size;
|
|
644
|
+
while (current && currentSize > newSize) {
|
|
645
|
+
this._map.delete(current.key);
|
|
646
|
+
current = current.next;
|
|
647
|
+
currentSize--;
|
|
648
|
+
}
|
|
649
|
+
this._head = current;
|
|
650
|
+
this._size = currentSize;
|
|
651
|
+
if (current) {
|
|
652
|
+
current.previous = void 0;
|
|
653
|
+
}
|
|
654
|
+
this._state++;
|
|
655
|
+
}
|
|
656
|
+
addItemFirst(item) {
|
|
657
|
+
if (!this._head && !this._tail) {
|
|
658
|
+
this._tail = item;
|
|
659
|
+
} else if (!this._head) {
|
|
660
|
+
throw new Error("Invalid list");
|
|
661
|
+
} else {
|
|
662
|
+
item.next = this._head;
|
|
663
|
+
this._head.previous = item;
|
|
664
|
+
}
|
|
665
|
+
this._head = item;
|
|
666
|
+
this._state++;
|
|
667
|
+
}
|
|
668
|
+
addItemLast(item) {
|
|
669
|
+
if (!this._head && !this._tail) {
|
|
670
|
+
this._head = item;
|
|
671
|
+
} else if (!this._tail) {
|
|
672
|
+
throw new Error("Invalid list");
|
|
673
|
+
} else {
|
|
674
|
+
item.previous = this._tail;
|
|
675
|
+
this._tail.next = item;
|
|
676
|
+
}
|
|
677
|
+
this._tail = item;
|
|
678
|
+
this._state++;
|
|
679
|
+
}
|
|
680
|
+
removeItem(item) {
|
|
681
|
+
if (item === this._head && item === this._tail) {
|
|
682
|
+
this._head = void 0;
|
|
683
|
+
this._tail = void 0;
|
|
684
|
+
} else if (item === this._head) {
|
|
685
|
+
if (!item.next) {
|
|
686
|
+
throw new Error("Invalid list");
|
|
687
|
+
}
|
|
688
|
+
item.next.previous = void 0;
|
|
689
|
+
this._head = item.next;
|
|
690
|
+
} else if (item === this._tail) {
|
|
691
|
+
if (!item.previous) {
|
|
692
|
+
throw new Error("Invalid list");
|
|
693
|
+
}
|
|
694
|
+
item.previous.next = void 0;
|
|
695
|
+
this._tail = item.previous;
|
|
696
|
+
} else {
|
|
697
|
+
const next = item.next;
|
|
698
|
+
const previous = item.previous;
|
|
699
|
+
if (!next || !previous) {
|
|
700
|
+
throw new Error("Invalid list");
|
|
701
|
+
}
|
|
702
|
+
next.previous = previous;
|
|
703
|
+
previous.next = next;
|
|
704
|
+
}
|
|
705
|
+
item.next = void 0;
|
|
706
|
+
item.previous = void 0;
|
|
707
|
+
this._state++;
|
|
708
|
+
}
|
|
709
|
+
touch(item, touch) {
|
|
710
|
+
if (!this._head || !this._tail) {
|
|
711
|
+
throw new Error("Invalid list");
|
|
712
|
+
}
|
|
713
|
+
if (touch !== Touch.First && touch !== Touch.Last) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
if (touch === Touch.First) {
|
|
717
|
+
if (item === this._head) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
const next = item.next;
|
|
721
|
+
const previous = item.previous;
|
|
722
|
+
if (item === this._tail) {
|
|
723
|
+
previous.next = void 0;
|
|
724
|
+
this._tail = previous;
|
|
725
|
+
} else {
|
|
726
|
+
next.previous = previous;
|
|
727
|
+
previous.next = next;
|
|
728
|
+
}
|
|
729
|
+
item.previous = void 0;
|
|
730
|
+
item.next = this._head;
|
|
731
|
+
this._head.previous = item;
|
|
732
|
+
this._head = item;
|
|
733
|
+
this._state++;
|
|
734
|
+
} else if (touch === Touch.Last) {
|
|
735
|
+
if (item === this._tail) {
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
const next = item.next;
|
|
739
|
+
const previous = item.previous;
|
|
740
|
+
if (item === this._head) {
|
|
741
|
+
next.previous = void 0;
|
|
742
|
+
this._head = next;
|
|
743
|
+
} else {
|
|
744
|
+
next.previous = previous;
|
|
745
|
+
previous.next = next;
|
|
746
|
+
}
|
|
747
|
+
item.next = void 0;
|
|
748
|
+
item.previous = this._tail;
|
|
749
|
+
this._tail.next = item;
|
|
750
|
+
this._tail = item;
|
|
751
|
+
this._state++;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
toJSON() {
|
|
755
|
+
const data = [];
|
|
756
|
+
this.forEach((value, key) => {
|
|
757
|
+
data.push([key, value]);
|
|
758
|
+
});
|
|
759
|
+
return data;
|
|
760
|
+
}
|
|
761
|
+
fromJSON(data) {
|
|
762
|
+
this.clear();
|
|
763
|
+
for (const [key, value] of data) {
|
|
764
|
+
this.set(key, value);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
linkedMap.LinkedMap = LinkedMap;
|
|
769
|
+
class LRUCache extends LinkedMap {
|
|
770
|
+
_limit;
|
|
771
|
+
_ratio;
|
|
772
|
+
constructor(limit, ratio = 1) {
|
|
773
|
+
super();
|
|
774
|
+
this._limit = limit;
|
|
775
|
+
this._ratio = Math.min(Math.max(0, ratio), 1);
|
|
776
|
+
}
|
|
777
|
+
get limit() {
|
|
778
|
+
return this._limit;
|
|
779
|
+
}
|
|
780
|
+
set limit(limit) {
|
|
781
|
+
this._limit = limit;
|
|
782
|
+
this.checkTrim();
|
|
783
|
+
}
|
|
784
|
+
get ratio() {
|
|
785
|
+
return this._ratio;
|
|
786
|
+
}
|
|
787
|
+
set ratio(ratio) {
|
|
788
|
+
this._ratio = Math.min(Math.max(0, ratio), 1);
|
|
789
|
+
this.checkTrim();
|
|
790
|
+
}
|
|
791
|
+
get(key, touch = Touch.AsNew) {
|
|
792
|
+
return super.get(key, touch);
|
|
793
|
+
}
|
|
794
|
+
peek(key) {
|
|
795
|
+
return super.get(key, Touch.None);
|
|
796
|
+
}
|
|
797
|
+
set(key, value) {
|
|
798
|
+
super.set(key, value, Touch.Last);
|
|
799
|
+
this.checkTrim();
|
|
800
|
+
return this;
|
|
801
|
+
}
|
|
802
|
+
checkTrim() {
|
|
803
|
+
if (this.size > this._limit) {
|
|
804
|
+
this.trimOld(Math.round(this._limit * this._ratio));
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
linkedMap.LRUCache = LRUCache;
|
|
809
|
+
return linkedMap;
|
|
810
|
+
}
|
|
811
|
+
var disposable = {};
|
|
812
|
+
var hasRequiredDisposable;
|
|
813
|
+
function requireDisposable() {
|
|
814
|
+
if (hasRequiredDisposable) return disposable;
|
|
815
|
+
hasRequiredDisposable = 1;
|
|
816
|
+
Object.defineProperty(disposable, "__esModule", { value: true });
|
|
817
|
+
disposable.Disposable = void 0;
|
|
818
|
+
var Disposable;
|
|
819
|
+
(function(Disposable2) {
|
|
820
|
+
function create(func) {
|
|
821
|
+
return {
|
|
822
|
+
dispose: func
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
Disposable2.create = create;
|
|
826
|
+
})(Disposable || (disposable.Disposable = Disposable = {}));
|
|
827
|
+
return disposable;
|
|
828
|
+
}
|
|
829
|
+
var events = {};
|
|
830
|
+
var ral = {};
|
|
831
|
+
var hasRequiredRal;
|
|
832
|
+
function requireRal() {
|
|
833
|
+
if (hasRequiredRal) return ral;
|
|
834
|
+
hasRequiredRal = 1;
|
|
835
|
+
Object.defineProperty(ral, "__esModule", { value: true });
|
|
836
|
+
let _ral;
|
|
837
|
+
function RAL() {
|
|
838
|
+
if (_ral === void 0) {
|
|
839
|
+
throw new Error(`No runtime abstraction layer installed`);
|
|
840
|
+
}
|
|
841
|
+
return _ral;
|
|
842
|
+
}
|
|
843
|
+
(function(RAL2) {
|
|
844
|
+
function install(ral2) {
|
|
845
|
+
if (ral2 === void 0) {
|
|
846
|
+
throw new Error(`No runtime abstraction layer provided`);
|
|
847
|
+
}
|
|
848
|
+
_ral = ral2;
|
|
849
|
+
}
|
|
850
|
+
RAL2.install = install;
|
|
851
|
+
})(RAL || (RAL = {}));
|
|
852
|
+
ral.default = RAL;
|
|
853
|
+
return ral;
|
|
854
|
+
}
|
|
855
|
+
var hasRequiredEvents;
|
|
856
|
+
function requireEvents() {
|
|
857
|
+
if (hasRequiredEvents) return events;
|
|
858
|
+
hasRequiredEvents = 1;
|
|
859
|
+
var __importDefault = events && events.__importDefault || function(mod) {
|
|
860
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
861
|
+
};
|
|
862
|
+
Object.defineProperty(events, "__esModule", { value: true });
|
|
863
|
+
events.Emitter = events.Event = void 0;
|
|
864
|
+
const ral_1 = __importDefault(requireRal());
|
|
865
|
+
var Event;
|
|
866
|
+
(function(Event2) {
|
|
867
|
+
const _disposable = { dispose() {
|
|
868
|
+
} };
|
|
869
|
+
Event2.None = function() {
|
|
870
|
+
return _disposable;
|
|
871
|
+
};
|
|
872
|
+
})(Event || (events.Event = Event = {}));
|
|
873
|
+
class CallbackList {
|
|
874
|
+
_callbacks;
|
|
875
|
+
_contexts;
|
|
876
|
+
add(callback, context = null, bucket) {
|
|
877
|
+
if (!this._callbacks) {
|
|
878
|
+
this._callbacks = [];
|
|
879
|
+
this._contexts = [];
|
|
880
|
+
}
|
|
881
|
+
this._callbacks.push(callback);
|
|
882
|
+
this._contexts.push(context);
|
|
883
|
+
if (Array.isArray(bucket)) {
|
|
884
|
+
bucket.push({ dispose: () => this.remove(callback, context) });
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
remove(callback, context = null) {
|
|
888
|
+
if (!this._callbacks) {
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
let foundCallbackWithDifferentContext = false;
|
|
892
|
+
for (let i = 0, len = this._callbacks.length; i < len; i++) {
|
|
893
|
+
if (this._callbacks[i] === callback) {
|
|
894
|
+
if (this._contexts[i] === context) {
|
|
895
|
+
this._callbacks.splice(i, 1);
|
|
896
|
+
this._contexts.splice(i, 1);
|
|
897
|
+
return;
|
|
898
|
+
} else {
|
|
899
|
+
foundCallbackWithDifferentContext = true;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (foundCallbackWithDifferentContext) {
|
|
904
|
+
throw new Error("When adding a listener with a context, you should remove it with the same context");
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
invoke(...args) {
|
|
908
|
+
if (!this._callbacks) {
|
|
909
|
+
return [];
|
|
910
|
+
}
|
|
911
|
+
const ret = [], callbacks = this._callbacks.slice(0), contexts = this._contexts.slice(0);
|
|
912
|
+
for (let i = 0, len = callbacks.length; i < len; i++) {
|
|
913
|
+
try {
|
|
914
|
+
ret.push(callbacks[i].apply(contexts[i], args));
|
|
915
|
+
} catch (e) {
|
|
916
|
+
(0, ral_1.default)().console.error(e);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return ret;
|
|
920
|
+
}
|
|
921
|
+
isEmpty() {
|
|
922
|
+
return !this._callbacks || this._callbacks.length === 0;
|
|
923
|
+
}
|
|
924
|
+
dispose() {
|
|
925
|
+
this._callbacks = void 0;
|
|
926
|
+
this._contexts = void 0;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
class Emitter {
|
|
930
|
+
_options;
|
|
931
|
+
static _noop = function() {
|
|
932
|
+
};
|
|
933
|
+
_event;
|
|
934
|
+
_callbacks;
|
|
935
|
+
constructor(_options) {
|
|
936
|
+
this._options = _options;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* For the public to allow to subscribe
|
|
940
|
+
* to events from this Emitter
|
|
941
|
+
*/
|
|
942
|
+
get event() {
|
|
943
|
+
if (!this._event) {
|
|
944
|
+
this._event = (listener, thisArgs, disposables) => {
|
|
945
|
+
if (!this._callbacks) {
|
|
946
|
+
this._callbacks = new CallbackList();
|
|
947
|
+
}
|
|
948
|
+
if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
|
|
949
|
+
this._options.onFirstListenerAdd(this);
|
|
950
|
+
}
|
|
951
|
+
this._callbacks.add(listener, thisArgs);
|
|
952
|
+
const result = {
|
|
953
|
+
dispose: () => {
|
|
954
|
+
if (!this._callbacks) {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
this._callbacks.remove(listener, thisArgs);
|
|
958
|
+
result.dispose = Emitter._noop;
|
|
959
|
+
if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
|
|
960
|
+
this._options.onLastListenerRemove(this);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
if (Array.isArray(disposables)) {
|
|
965
|
+
disposables.push(result);
|
|
966
|
+
}
|
|
967
|
+
return result;
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
return this._event;
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* To be kept private to fire an event to
|
|
974
|
+
* subscribers
|
|
975
|
+
*/
|
|
976
|
+
fire(event) {
|
|
977
|
+
if (this._callbacks) {
|
|
978
|
+
this._callbacks.invoke.call(this._callbacks, event);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
dispose() {
|
|
982
|
+
if (this._callbacks) {
|
|
983
|
+
this._callbacks.dispose();
|
|
984
|
+
this._callbacks = void 0;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
events.Emitter = Emitter;
|
|
989
|
+
return events;
|
|
990
|
+
}
|
|
991
|
+
var cancellation = {};
|
|
992
|
+
var hasRequiredCancellation;
|
|
993
|
+
function requireCancellation() {
|
|
994
|
+
if (hasRequiredCancellation) return cancellation;
|
|
995
|
+
hasRequiredCancellation = 1;
|
|
996
|
+
var __createBinding = cancellation && cancellation.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
997
|
+
if (k2 === void 0) k2 = k;
|
|
998
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
999
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1000
|
+
desc = { enumerable: true, get: function() {
|
|
1001
|
+
return m[k];
|
|
1002
|
+
} };
|
|
1003
|
+
}
|
|
1004
|
+
Object.defineProperty(o, k2, desc);
|
|
1005
|
+
}) : (function(o, m, k, k2) {
|
|
1006
|
+
if (k2 === void 0) k2 = k;
|
|
1007
|
+
o[k2] = m[k];
|
|
1008
|
+
}));
|
|
1009
|
+
var __setModuleDefault = cancellation && cancellation.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1010
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1011
|
+
}) : function(o, v) {
|
|
1012
|
+
o["default"] = v;
|
|
1013
|
+
});
|
|
1014
|
+
var __importStar = cancellation && cancellation.__importStar || /* @__PURE__ */ (function() {
|
|
1015
|
+
var ownKeys = function(o) {
|
|
1016
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1017
|
+
var ar = [];
|
|
1018
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1019
|
+
return ar;
|
|
1020
|
+
};
|
|
1021
|
+
return ownKeys(o);
|
|
1022
|
+
};
|
|
1023
|
+
return function(mod) {
|
|
1024
|
+
if (mod && mod.__esModule) return mod;
|
|
1025
|
+
var result = {};
|
|
1026
|
+
if (mod != null) {
|
|
1027
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1028
|
+
}
|
|
1029
|
+
__setModuleDefault(result, mod);
|
|
1030
|
+
return result;
|
|
1031
|
+
};
|
|
1032
|
+
})();
|
|
1033
|
+
var __importDefault = cancellation && cancellation.__importDefault || function(mod) {
|
|
1034
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1035
|
+
};
|
|
1036
|
+
Object.defineProperty(cancellation, "__esModule", { value: true });
|
|
1037
|
+
cancellation.CancellationTokenSource = cancellation.CancellationToken = void 0;
|
|
1038
|
+
const ral_1 = __importDefault(requireRal());
|
|
1039
|
+
const Is = __importStar(requireIs());
|
|
1040
|
+
const events_1 = requireEvents();
|
|
1041
|
+
var CancellationToken;
|
|
1042
|
+
(function(CancellationToken2) {
|
|
1043
|
+
CancellationToken2.None = Object.freeze({
|
|
1044
|
+
isCancellationRequested: false,
|
|
1045
|
+
onCancellationRequested: events_1.Event.None
|
|
1046
|
+
});
|
|
1047
|
+
CancellationToken2.Cancelled = Object.freeze({
|
|
1048
|
+
isCancellationRequested: true,
|
|
1049
|
+
onCancellationRequested: events_1.Event.None
|
|
1050
|
+
});
|
|
1051
|
+
function is2(value) {
|
|
1052
|
+
const candidate = value;
|
|
1053
|
+
return candidate && (candidate === CancellationToken2.None || candidate === CancellationToken2.Cancelled || Is.boolean(candidate.isCancellationRequested) && !!candidate.onCancellationRequested);
|
|
1054
|
+
}
|
|
1055
|
+
CancellationToken2.is = is2;
|
|
1056
|
+
})(CancellationToken || (cancellation.CancellationToken = CancellationToken = {}));
|
|
1057
|
+
const shortcutEvent = Object.freeze(function(callback, context) {
|
|
1058
|
+
const handle = (0, ral_1.default)().timer.setTimeout(callback.bind(context), 0);
|
|
1059
|
+
return { dispose() {
|
|
1060
|
+
handle.dispose();
|
|
1061
|
+
} };
|
|
1062
|
+
});
|
|
1063
|
+
class MutableToken {
|
|
1064
|
+
_isCancelled = false;
|
|
1065
|
+
_emitter;
|
|
1066
|
+
cancel() {
|
|
1067
|
+
if (!this._isCancelled) {
|
|
1068
|
+
this._isCancelled = true;
|
|
1069
|
+
if (this._emitter) {
|
|
1070
|
+
this._emitter.fire(void 0);
|
|
1071
|
+
this.dispose();
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
get isCancellationRequested() {
|
|
1076
|
+
return this._isCancelled;
|
|
1077
|
+
}
|
|
1078
|
+
get onCancellationRequested() {
|
|
1079
|
+
if (this._isCancelled) {
|
|
1080
|
+
return shortcutEvent;
|
|
1081
|
+
}
|
|
1082
|
+
if (!this._emitter) {
|
|
1083
|
+
this._emitter = new events_1.Emitter();
|
|
1084
|
+
}
|
|
1085
|
+
return this._emitter.event;
|
|
1086
|
+
}
|
|
1087
|
+
dispose() {
|
|
1088
|
+
if (this._emitter) {
|
|
1089
|
+
this._emitter.dispose();
|
|
1090
|
+
this._emitter = void 0;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
class CancellationTokenSource {
|
|
1095
|
+
_token;
|
|
1096
|
+
get token() {
|
|
1097
|
+
if (!this._token) {
|
|
1098
|
+
this._token = new MutableToken();
|
|
1099
|
+
}
|
|
1100
|
+
return this._token;
|
|
1101
|
+
}
|
|
1102
|
+
cancel() {
|
|
1103
|
+
if (!this._token) {
|
|
1104
|
+
this._token = CancellationToken.Cancelled;
|
|
1105
|
+
} else {
|
|
1106
|
+
this._token.cancel();
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
dispose() {
|
|
1110
|
+
if (!this._token) {
|
|
1111
|
+
this._token = CancellationToken.None;
|
|
1112
|
+
} else if (this._token instanceof MutableToken) {
|
|
1113
|
+
this._token.dispose();
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
cancellation.CancellationTokenSource = CancellationTokenSource;
|
|
1118
|
+
return cancellation;
|
|
1119
|
+
}
|
|
1120
|
+
var sharedArrayCancellation = {};
|
|
1121
|
+
var hasRequiredSharedArrayCancellation;
|
|
1122
|
+
function requireSharedArrayCancellation() {
|
|
1123
|
+
if (hasRequiredSharedArrayCancellation) return sharedArrayCancellation;
|
|
1124
|
+
hasRequiredSharedArrayCancellation = 1;
|
|
1125
|
+
Object.defineProperty(sharedArrayCancellation, "__esModule", { value: true });
|
|
1126
|
+
sharedArrayCancellation.SharedArrayReceiverStrategy = sharedArrayCancellation.SharedArraySenderStrategy = void 0;
|
|
1127
|
+
const cancellation_1 = requireCancellation();
|
|
1128
|
+
var CancellationState;
|
|
1129
|
+
(function(CancellationState2) {
|
|
1130
|
+
CancellationState2.Continue = 0;
|
|
1131
|
+
CancellationState2.Cancelled = 1;
|
|
1132
|
+
})(CancellationState || (CancellationState = {}));
|
|
1133
|
+
class SharedArraySenderStrategy {
|
|
1134
|
+
buffers;
|
|
1135
|
+
constructor() {
|
|
1136
|
+
this.buffers = /* @__PURE__ */ new Map();
|
|
1137
|
+
}
|
|
1138
|
+
enableCancellation(request2) {
|
|
1139
|
+
if (request2.id === null) {
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
const buffer = new SharedArrayBuffer(4);
|
|
1143
|
+
const data = new Int32Array(buffer, 0, 1);
|
|
1144
|
+
data[0] = CancellationState.Continue;
|
|
1145
|
+
this.buffers.set(request2.id, buffer);
|
|
1146
|
+
request2.$cancellationData = buffer;
|
|
1147
|
+
}
|
|
1148
|
+
async sendCancellation(_conn, id) {
|
|
1149
|
+
const buffer = this.buffers.get(id);
|
|
1150
|
+
if (buffer === void 0) {
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
const data = new Int32Array(buffer, 0, 1);
|
|
1154
|
+
Atomics.store(data, 0, CancellationState.Cancelled);
|
|
1155
|
+
}
|
|
1156
|
+
cleanup(id) {
|
|
1157
|
+
this.buffers.delete(id);
|
|
1158
|
+
}
|
|
1159
|
+
dispose() {
|
|
1160
|
+
this.buffers.clear();
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
sharedArrayCancellation.SharedArraySenderStrategy = SharedArraySenderStrategy;
|
|
1164
|
+
class SharedArrayBufferCancellationToken {
|
|
1165
|
+
data;
|
|
1166
|
+
constructor(buffer) {
|
|
1167
|
+
this.data = new Int32Array(buffer, 0, 1);
|
|
1168
|
+
}
|
|
1169
|
+
get isCancellationRequested() {
|
|
1170
|
+
return Atomics.load(this.data, 0) === CancellationState.Cancelled;
|
|
1171
|
+
}
|
|
1172
|
+
get onCancellationRequested() {
|
|
1173
|
+
throw new Error(`Cancellation over SharedArrayBuffer doesn't support cancellation events`);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
class SharedArrayBufferCancellationTokenSource {
|
|
1177
|
+
token;
|
|
1178
|
+
constructor(buffer) {
|
|
1179
|
+
this.token = new SharedArrayBufferCancellationToken(buffer);
|
|
1180
|
+
}
|
|
1181
|
+
cancel() {
|
|
1182
|
+
}
|
|
1183
|
+
dispose() {
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
class SharedArrayReceiverStrategy {
|
|
1187
|
+
kind = "request";
|
|
1188
|
+
createCancellationTokenSource(request2) {
|
|
1189
|
+
const buffer = request2.$cancellationData;
|
|
1190
|
+
if (buffer === void 0) {
|
|
1191
|
+
return new cancellation_1.CancellationTokenSource();
|
|
1192
|
+
}
|
|
1193
|
+
return new SharedArrayBufferCancellationTokenSource(buffer);
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
sharedArrayCancellation.SharedArrayReceiverStrategy = SharedArrayReceiverStrategy;
|
|
1197
|
+
return sharedArrayCancellation;
|
|
1198
|
+
}
|
|
1199
|
+
var messageReader = {};
|
|
1200
|
+
var semaphore = {};
|
|
1201
|
+
var hasRequiredSemaphore;
|
|
1202
|
+
function requireSemaphore() {
|
|
1203
|
+
if (hasRequiredSemaphore) return semaphore;
|
|
1204
|
+
hasRequiredSemaphore = 1;
|
|
1205
|
+
var __importDefault = semaphore && semaphore.__importDefault || function(mod) {
|
|
1206
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1207
|
+
};
|
|
1208
|
+
Object.defineProperty(semaphore, "__esModule", { value: true });
|
|
1209
|
+
semaphore.Semaphore = void 0;
|
|
1210
|
+
const ral_1 = __importDefault(requireRal());
|
|
1211
|
+
class Semaphore {
|
|
1212
|
+
_capacity;
|
|
1213
|
+
_active;
|
|
1214
|
+
_waiting;
|
|
1215
|
+
constructor(capacity = 1) {
|
|
1216
|
+
if (capacity <= 0) {
|
|
1217
|
+
throw new Error("Capacity must be greater than 0");
|
|
1218
|
+
}
|
|
1219
|
+
this._capacity = capacity;
|
|
1220
|
+
this._active = 0;
|
|
1221
|
+
this._waiting = [];
|
|
1222
|
+
}
|
|
1223
|
+
lock(thunk) {
|
|
1224
|
+
return new Promise((resolve, reject) => {
|
|
1225
|
+
this._waiting.push({ thunk, resolve, reject });
|
|
1226
|
+
this.runNext();
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
get active() {
|
|
1230
|
+
return this._active;
|
|
1231
|
+
}
|
|
1232
|
+
runNext() {
|
|
1233
|
+
if (this._waiting.length === 0 || this._active === this._capacity) {
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
(0, ral_1.default)().timer.setImmediate(() => this.doRunNext());
|
|
1237
|
+
}
|
|
1238
|
+
doRunNext() {
|
|
1239
|
+
if (this._waiting.length === 0 || this._active === this._capacity) {
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
const next = this._waiting.shift();
|
|
1243
|
+
this._active++;
|
|
1244
|
+
if (this._active > this._capacity) {
|
|
1245
|
+
throw new Error(`Too many thunks active`);
|
|
1246
|
+
}
|
|
1247
|
+
try {
|
|
1248
|
+
const result = next.thunk();
|
|
1249
|
+
if (result instanceof Promise) {
|
|
1250
|
+
result.then((value) => {
|
|
1251
|
+
this._active--;
|
|
1252
|
+
next.resolve(value);
|
|
1253
|
+
this.runNext();
|
|
1254
|
+
}, (err) => {
|
|
1255
|
+
this._active--;
|
|
1256
|
+
next.reject(err);
|
|
1257
|
+
this.runNext();
|
|
1258
|
+
});
|
|
1259
|
+
} else {
|
|
1260
|
+
this._active--;
|
|
1261
|
+
next.resolve(result);
|
|
1262
|
+
this.runNext();
|
|
1263
|
+
}
|
|
1264
|
+
} catch (err) {
|
|
1265
|
+
this._active--;
|
|
1266
|
+
next.reject(err);
|
|
1267
|
+
this.runNext();
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
semaphore.Semaphore = Semaphore;
|
|
1272
|
+
return semaphore;
|
|
1273
|
+
}
|
|
1274
|
+
var hasRequiredMessageReader;
|
|
1275
|
+
function requireMessageReader() {
|
|
1276
|
+
if (hasRequiredMessageReader) return messageReader;
|
|
1277
|
+
hasRequiredMessageReader = 1;
|
|
1278
|
+
var __createBinding = messageReader && messageReader.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1279
|
+
if (k2 === void 0) k2 = k;
|
|
1280
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1281
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1282
|
+
desc = { enumerable: true, get: function() {
|
|
1283
|
+
return m[k];
|
|
1284
|
+
} };
|
|
1285
|
+
}
|
|
1286
|
+
Object.defineProperty(o, k2, desc);
|
|
1287
|
+
}) : (function(o, m, k, k2) {
|
|
1288
|
+
if (k2 === void 0) k2 = k;
|
|
1289
|
+
o[k2] = m[k];
|
|
1290
|
+
}));
|
|
1291
|
+
var __setModuleDefault = messageReader && messageReader.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1292
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1293
|
+
}) : function(o, v) {
|
|
1294
|
+
o["default"] = v;
|
|
1295
|
+
});
|
|
1296
|
+
var __importStar = messageReader && messageReader.__importStar || /* @__PURE__ */ (function() {
|
|
1297
|
+
var ownKeys = function(o) {
|
|
1298
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1299
|
+
var ar = [];
|
|
1300
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1301
|
+
return ar;
|
|
1302
|
+
};
|
|
1303
|
+
return ownKeys(o);
|
|
1304
|
+
};
|
|
1305
|
+
return function(mod) {
|
|
1306
|
+
if (mod && mod.__esModule) return mod;
|
|
1307
|
+
var result = {};
|
|
1308
|
+
if (mod != null) {
|
|
1309
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1310
|
+
}
|
|
1311
|
+
__setModuleDefault(result, mod);
|
|
1312
|
+
return result;
|
|
1313
|
+
};
|
|
1314
|
+
})();
|
|
1315
|
+
var __importDefault = messageReader && messageReader.__importDefault || function(mod) {
|
|
1316
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1317
|
+
};
|
|
1318
|
+
Object.defineProperty(messageReader, "__esModule", { value: true });
|
|
1319
|
+
messageReader.ReadableStreamMessageReader = messageReader.AbstractMessageReader = messageReader.MessageReader = void 0;
|
|
1320
|
+
const ral_1 = __importDefault(requireRal());
|
|
1321
|
+
const Is = __importStar(requireIs());
|
|
1322
|
+
const events_1 = requireEvents();
|
|
1323
|
+
const semaphore_1 = requireSemaphore();
|
|
1324
|
+
var MessageReader;
|
|
1325
|
+
(function(MessageReader2) {
|
|
1326
|
+
function is2(value) {
|
|
1327
|
+
const candidate = value;
|
|
1328
|
+
return candidate && Is.func(candidate.listen) && Is.func(candidate.dispose) && Is.func(candidate.onError) && Is.func(candidate.onClose) && Is.func(candidate.onPartialMessage);
|
|
1329
|
+
}
|
|
1330
|
+
MessageReader2.is = is2;
|
|
1331
|
+
})(MessageReader || (messageReader.MessageReader = MessageReader = {}));
|
|
1332
|
+
class AbstractMessageReader {
|
|
1333
|
+
errorEmitter;
|
|
1334
|
+
closeEmitter;
|
|
1335
|
+
partialMessageEmitter;
|
|
1336
|
+
constructor() {
|
|
1337
|
+
this.errorEmitter = new events_1.Emitter();
|
|
1338
|
+
this.closeEmitter = new events_1.Emitter();
|
|
1339
|
+
this.partialMessageEmitter = new events_1.Emitter();
|
|
1340
|
+
}
|
|
1341
|
+
dispose() {
|
|
1342
|
+
this.errorEmitter.dispose();
|
|
1343
|
+
this.closeEmitter.dispose();
|
|
1344
|
+
this.partialMessageEmitter.dispose();
|
|
1345
|
+
}
|
|
1346
|
+
get onError() {
|
|
1347
|
+
return this.errorEmitter.event;
|
|
1348
|
+
}
|
|
1349
|
+
fireError(error) {
|
|
1350
|
+
this.errorEmitter.fire(this.asError(error));
|
|
1351
|
+
}
|
|
1352
|
+
get onClose() {
|
|
1353
|
+
return this.closeEmitter.event;
|
|
1354
|
+
}
|
|
1355
|
+
fireClose() {
|
|
1356
|
+
this.closeEmitter.fire(void 0);
|
|
1357
|
+
}
|
|
1358
|
+
get onPartialMessage() {
|
|
1359
|
+
return this.partialMessageEmitter.event;
|
|
1360
|
+
}
|
|
1361
|
+
firePartialMessage(info) {
|
|
1362
|
+
this.partialMessageEmitter.fire(info);
|
|
1363
|
+
}
|
|
1364
|
+
asError(error) {
|
|
1365
|
+
if (error instanceof Error) {
|
|
1366
|
+
return error;
|
|
1367
|
+
} else {
|
|
1368
|
+
return new Error(`Reader received error. Reason: ${Is.string(error.message) ? error.message : "unknown"}`);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
messageReader.AbstractMessageReader = AbstractMessageReader;
|
|
1373
|
+
var ResolvedMessageReaderOptions;
|
|
1374
|
+
(function(ResolvedMessageReaderOptions2) {
|
|
1375
|
+
function fromOptions(options) {
|
|
1376
|
+
let charset;
|
|
1377
|
+
let contentDecoder;
|
|
1378
|
+
const contentDecoders = /* @__PURE__ */ new Map();
|
|
1379
|
+
let contentTypeDecoder;
|
|
1380
|
+
const contentTypeDecoders = /* @__PURE__ */ new Map();
|
|
1381
|
+
if (options === void 0 || typeof options === "string") {
|
|
1382
|
+
charset = options ?? "utf-8";
|
|
1383
|
+
} else {
|
|
1384
|
+
charset = options.charset ?? "utf-8";
|
|
1385
|
+
if (options.contentDecoder !== void 0) {
|
|
1386
|
+
contentDecoder = options.contentDecoder;
|
|
1387
|
+
contentDecoders.set(contentDecoder.name, contentDecoder);
|
|
1388
|
+
}
|
|
1389
|
+
if (options.contentDecoders !== void 0) {
|
|
1390
|
+
for (const decoder of options.contentDecoders) {
|
|
1391
|
+
contentDecoders.set(decoder.name, decoder);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
if (options.contentTypeDecoder !== void 0) {
|
|
1395
|
+
contentTypeDecoder = options.contentTypeDecoder;
|
|
1396
|
+
contentTypeDecoders.set(contentTypeDecoder.name, contentTypeDecoder);
|
|
1397
|
+
}
|
|
1398
|
+
if (options.contentTypeDecoders !== void 0) {
|
|
1399
|
+
for (const decoder of options.contentTypeDecoders) {
|
|
1400
|
+
contentTypeDecoders.set(decoder.name, decoder);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
if (contentTypeDecoder === void 0) {
|
|
1405
|
+
contentTypeDecoder = (0, ral_1.default)().applicationJson.decoder;
|
|
1406
|
+
contentTypeDecoders.set(contentTypeDecoder.name, contentTypeDecoder);
|
|
1407
|
+
}
|
|
1408
|
+
return { charset, contentDecoder, contentDecoders, contentTypeDecoder, contentTypeDecoders };
|
|
1409
|
+
}
|
|
1410
|
+
ResolvedMessageReaderOptions2.fromOptions = fromOptions;
|
|
1411
|
+
})(ResolvedMessageReaderOptions || (ResolvedMessageReaderOptions = {}));
|
|
1412
|
+
class ReadableStreamMessageReader extends AbstractMessageReader {
|
|
1413
|
+
readable;
|
|
1414
|
+
options;
|
|
1415
|
+
callback;
|
|
1416
|
+
nextMessageLength;
|
|
1417
|
+
messageToken;
|
|
1418
|
+
buffer;
|
|
1419
|
+
partialMessageTimer;
|
|
1420
|
+
_partialMessageTimeout;
|
|
1421
|
+
readSemaphore;
|
|
1422
|
+
constructor(readable, options) {
|
|
1423
|
+
super();
|
|
1424
|
+
this.readable = readable;
|
|
1425
|
+
this.options = ResolvedMessageReaderOptions.fromOptions(options);
|
|
1426
|
+
this.buffer = (0, ral_1.default)().messageBuffer.create(this.options.charset);
|
|
1427
|
+
this._partialMessageTimeout = 1e4;
|
|
1428
|
+
this.nextMessageLength = -1;
|
|
1429
|
+
this.messageToken = 0;
|
|
1430
|
+
this.readSemaphore = new semaphore_1.Semaphore(1);
|
|
1431
|
+
}
|
|
1432
|
+
set partialMessageTimeout(timeout) {
|
|
1433
|
+
this._partialMessageTimeout = timeout;
|
|
1434
|
+
}
|
|
1435
|
+
get partialMessageTimeout() {
|
|
1436
|
+
return this._partialMessageTimeout;
|
|
1437
|
+
}
|
|
1438
|
+
listen(callback) {
|
|
1439
|
+
this.nextMessageLength = -1;
|
|
1440
|
+
this.messageToken = 0;
|
|
1441
|
+
this.partialMessageTimer = void 0;
|
|
1442
|
+
this.callback = callback;
|
|
1443
|
+
const result = this.readable.onData((data) => {
|
|
1444
|
+
this.onData(data);
|
|
1445
|
+
});
|
|
1446
|
+
this.readable.onError((error) => this.fireError(error));
|
|
1447
|
+
this.readable.onClose(() => this.fireClose());
|
|
1448
|
+
return result;
|
|
1449
|
+
}
|
|
1450
|
+
onData(data) {
|
|
1451
|
+
try {
|
|
1452
|
+
this.buffer.append(data);
|
|
1453
|
+
while (true) {
|
|
1454
|
+
if (this.nextMessageLength === -1) {
|
|
1455
|
+
const headers = this.buffer.tryReadHeaders(true);
|
|
1456
|
+
if (!headers) {
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
const contentLength = headers.get("content-length");
|
|
1460
|
+
if (!contentLength) {
|
|
1461
|
+
this.fireError(new Error(`Header must provide a Content-Length property.
|
|
1462
|
+
${JSON.stringify(Object.fromEntries(headers))}`));
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
const length = parseInt(contentLength);
|
|
1466
|
+
if (isNaN(length)) {
|
|
1467
|
+
this.fireError(new Error(`Content-Length value must be a number. Got ${contentLength}`));
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
this.nextMessageLength = length;
|
|
1471
|
+
}
|
|
1472
|
+
const body = this.buffer.tryReadBody(this.nextMessageLength);
|
|
1473
|
+
if (body === void 0) {
|
|
1474
|
+
this.setPartialMessageTimer();
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
this.clearPartialMessageTimer();
|
|
1478
|
+
this.nextMessageLength = -1;
|
|
1479
|
+
this.readSemaphore.lock(async () => {
|
|
1480
|
+
const bytes = this.options.contentDecoder !== void 0 ? await this.options.contentDecoder.decode(body) : body;
|
|
1481
|
+
const message = await this.options.contentTypeDecoder.decode(bytes, this.options);
|
|
1482
|
+
this.callback(message);
|
|
1483
|
+
}).catch((error) => {
|
|
1484
|
+
this.fireError(error);
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
} catch (error) {
|
|
1488
|
+
this.fireError(error);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
clearPartialMessageTimer() {
|
|
1492
|
+
if (this.partialMessageTimer) {
|
|
1493
|
+
this.partialMessageTimer.dispose();
|
|
1494
|
+
this.partialMessageTimer = void 0;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
setPartialMessageTimer() {
|
|
1498
|
+
this.clearPartialMessageTimer();
|
|
1499
|
+
if (this._partialMessageTimeout <= 0) {
|
|
1500
|
+
return;
|
|
1501
|
+
}
|
|
1502
|
+
this.partialMessageTimer = (0, ral_1.default)().timer.setTimeout((token, timeout) => {
|
|
1503
|
+
this.partialMessageTimer = void 0;
|
|
1504
|
+
if (token === this.messageToken) {
|
|
1505
|
+
this.firePartialMessage({ messageToken: token, waitingTime: timeout });
|
|
1506
|
+
this.setPartialMessageTimer();
|
|
1507
|
+
}
|
|
1508
|
+
}, this._partialMessageTimeout, this.messageToken, this._partialMessageTimeout);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
messageReader.ReadableStreamMessageReader = ReadableStreamMessageReader;
|
|
1512
|
+
return messageReader;
|
|
1513
|
+
}
|
|
1514
|
+
var messageWriter = {};
|
|
1515
|
+
var hasRequiredMessageWriter;
|
|
1516
|
+
function requireMessageWriter() {
|
|
1517
|
+
if (hasRequiredMessageWriter) return messageWriter;
|
|
1518
|
+
hasRequiredMessageWriter = 1;
|
|
1519
|
+
var __createBinding = messageWriter && messageWriter.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1520
|
+
if (k2 === void 0) k2 = k;
|
|
1521
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1522
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1523
|
+
desc = { enumerable: true, get: function() {
|
|
1524
|
+
return m[k];
|
|
1525
|
+
} };
|
|
1526
|
+
}
|
|
1527
|
+
Object.defineProperty(o, k2, desc);
|
|
1528
|
+
}) : (function(o, m, k, k2) {
|
|
1529
|
+
if (k2 === void 0) k2 = k;
|
|
1530
|
+
o[k2] = m[k];
|
|
1531
|
+
}));
|
|
1532
|
+
var __setModuleDefault = messageWriter && messageWriter.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1533
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1534
|
+
}) : function(o, v) {
|
|
1535
|
+
o["default"] = v;
|
|
1536
|
+
});
|
|
1537
|
+
var __importStar = messageWriter && messageWriter.__importStar || /* @__PURE__ */ (function() {
|
|
1538
|
+
var ownKeys = function(o) {
|
|
1539
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1540
|
+
var ar = [];
|
|
1541
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1542
|
+
return ar;
|
|
1543
|
+
};
|
|
1544
|
+
return ownKeys(o);
|
|
1545
|
+
};
|
|
1546
|
+
return function(mod) {
|
|
1547
|
+
if (mod && mod.__esModule) return mod;
|
|
1548
|
+
var result = {};
|
|
1549
|
+
if (mod != null) {
|
|
1550
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1551
|
+
}
|
|
1552
|
+
__setModuleDefault(result, mod);
|
|
1553
|
+
return result;
|
|
1554
|
+
};
|
|
1555
|
+
})();
|
|
1556
|
+
var __importDefault = messageWriter && messageWriter.__importDefault || function(mod) {
|
|
1557
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1558
|
+
};
|
|
1559
|
+
Object.defineProperty(messageWriter, "__esModule", { value: true });
|
|
1560
|
+
messageWriter.WriteableStreamMessageWriter = messageWriter.AbstractMessageWriter = messageWriter.MessageWriter = void 0;
|
|
1561
|
+
const ral_1 = __importDefault(requireRal());
|
|
1562
|
+
const Is = __importStar(requireIs());
|
|
1563
|
+
const semaphore_1 = requireSemaphore();
|
|
1564
|
+
const events_1 = requireEvents();
|
|
1565
|
+
const ContentLength = "Content-Length: ";
|
|
1566
|
+
const CRLF = "\r\n";
|
|
1567
|
+
var MessageWriter;
|
|
1568
|
+
(function(MessageWriter2) {
|
|
1569
|
+
function is2(value) {
|
|
1570
|
+
const candidate = value;
|
|
1571
|
+
return candidate && Is.func(candidate.dispose) && Is.func(candidate.onClose) && Is.func(candidate.onError) && Is.func(candidate.write);
|
|
1572
|
+
}
|
|
1573
|
+
MessageWriter2.is = is2;
|
|
1574
|
+
})(MessageWriter || (messageWriter.MessageWriter = MessageWriter = {}));
|
|
1575
|
+
class AbstractMessageWriter {
|
|
1576
|
+
errorEmitter;
|
|
1577
|
+
closeEmitter;
|
|
1578
|
+
constructor() {
|
|
1579
|
+
this.errorEmitter = new events_1.Emitter();
|
|
1580
|
+
this.closeEmitter = new events_1.Emitter();
|
|
1581
|
+
}
|
|
1582
|
+
dispose() {
|
|
1583
|
+
this.errorEmitter.dispose();
|
|
1584
|
+
this.closeEmitter.dispose();
|
|
1585
|
+
}
|
|
1586
|
+
get onError() {
|
|
1587
|
+
return this.errorEmitter.event;
|
|
1588
|
+
}
|
|
1589
|
+
fireError(error, message, count) {
|
|
1590
|
+
this.errorEmitter.fire([this.asError(error), message, count]);
|
|
1591
|
+
}
|
|
1592
|
+
get onClose() {
|
|
1593
|
+
return this.closeEmitter.event;
|
|
1594
|
+
}
|
|
1595
|
+
fireClose() {
|
|
1596
|
+
this.closeEmitter.fire(void 0);
|
|
1597
|
+
}
|
|
1598
|
+
asError(error) {
|
|
1599
|
+
if (error instanceof Error) {
|
|
1600
|
+
return error;
|
|
1601
|
+
} else {
|
|
1602
|
+
return new Error(`Writer received error. Reason: ${Is.string(error.message) ? error.message : "unknown"}`);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
messageWriter.AbstractMessageWriter = AbstractMessageWriter;
|
|
1607
|
+
var ResolvedMessageWriterOptions;
|
|
1608
|
+
(function(ResolvedMessageWriterOptions2) {
|
|
1609
|
+
function fromOptions(options) {
|
|
1610
|
+
if (options === void 0 || typeof options === "string") {
|
|
1611
|
+
return { charset: options ?? "utf-8", contentTypeEncoder: (0, ral_1.default)().applicationJson.encoder };
|
|
1612
|
+
} else {
|
|
1613
|
+
return { charset: options.charset ?? "utf-8", contentEncoder: options.contentEncoder, contentTypeEncoder: options.contentTypeEncoder ?? (0, ral_1.default)().applicationJson.encoder };
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
ResolvedMessageWriterOptions2.fromOptions = fromOptions;
|
|
1617
|
+
})(ResolvedMessageWriterOptions || (ResolvedMessageWriterOptions = {}));
|
|
1618
|
+
class WriteableStreamMessageWriter extends AbstractMessageWriter {
|
|
1619
|
+
writable;
|
|
1620
|
+
options;
|
|
1621
|
+
errorCount;
|
|
1622
|
+
writeSemaphore;
|
|
1623
|
+
constructor(writable, options) {
|
|
1624
|
+
super();
|
|
1625
|
+
this.writable = writable;
|
|
1626
|
+
this.options = ResolvedMessageWriterOptions.fromOptions(options);
|
|
1627
|
+
this.errorCount = 0;
|
|
1628
|
+
this.writeSemaphore = new semaphore_1.Semaphore(1);
|
|
1629
|
+
this.writable.onError((error) => this.fireError(error));
|
|
1630
|
+
this.writable.onClose(() => this.fireClose());
|
|
1631
|
+
}
|
|
1632
|
+
async write(msg) {
|
|
1633
|
+
return this.writeSemaphore.lock(async () => {
|
|
1634
|
+
const payload = this.options.contentTypeEncoder.encode(msg, this.options).then((buffer) => {
|
|
1635
|
+
if (this.options.contentEncoder !== void 0) {
|
|
1636
|
+
return this.options.contentEncoder.encode(buffer);
|
|
1637
|
+
} else {
|
|
1638
|
+
return buffer;
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
return payload.then((buffer) => {
|
|
1642
|
+
const headers = [];
|
|
1643
|
+
headers.push(ContentLength, buffer.byteLength.toString(), CRLF);
|
|
1644
|
+
headers.push(CRLF);
|
|
1645
|
+
return this.doWrite(msg, headers, buffer);
|
|
1646
|
+
}, (error) => {
|
|
1647
|
+
this.fireError(error);
|
|
1648
|
+
throw error;
|
|
1649
|
+
});
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
async doWrite(msg, headers, data) {
|
|
1653
|
+
try {
|
|
1654
|
+
await this.writable.write(headers.join(""), "ascii");
|
|
1655
|
+
return this.writable.write(data);
|
|
1656
|
+
} catch (error) {
|
|
1657
|
+
this.handleError(error, msg);
|
|
1658
|
+
return Promise.reject(error);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
handleError(error, msg) {
|
|
1662
|
+
this.errorCount++;
|
|
1663
|
+
this.fireError(error, msg, this.errorCount);
|
|
1664
|
+
}
|
|
1665
|
+
end() {
|
|
1666
|
+
this.writable.end();
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
messageWriter.WriteableStreamMessageWriter = WriteableStreamMessageWriter;
|
|
1670
|
+
return messageWriter;
|
|
1671
|
+
}
|
|
1672
|
+
var messageBuffer = {};
|
|
1673
|
+
var hasRequiredMessageBuffer;
|
|
1674
|
+
function requireMessageBuffer() {
|
|
1675
|
+
if (hasRequiredMessageBuffer) return messageBuffer;
|
|
1676
|
+
hasRequiredMessageBuffer = 1;
|
|
1677
|
+
Object.defineProperty(messageBuffer, "__esModule", { value: true });
|
|
1678
|
+
messageBuffer.AbstractMessageBuffer = void 0;
|
|
1679
|
+
const CR = 13;
|
|
1680
|
+
const LF = 10;
|
|
1681
|
+
const CRLF = "\r\n";
|
|
1682
|
+
class AbstractMessageBuffer {
|
|
1683
|
+
_encoding;
|
|
1684
|
+
_chunks;
|
|
1685
|
+
_totalLength;
|
|
1686
|
+
constructor(encoding = "utf-8") {
|
|
1687
|
+
this._encoding = encoding;
|
|
1688
|
+
this._chunks = [];
|
|
1689
|
+
this._totalLength = 0;
|
|
1690
|
+
}
|
|
1691
|
+
get encoding() {
|
|
1692
|
+
return this._encoding;
|
|
1693
|
+
}
|
|
1694
|
+
append(chunk) {
|
|
1695
|
+
const toAppend = typeof chunk === "string" ? this.fromString(chunk, this._encoding) : chunk;
|
|
1696
|
+
this._chunks.push(toAppend);
|
|
1697
|
+
this._totalLength += toAppend.byteLength;
|
|
1698
|
+
}
|
|
1699
|
+
tryReadHeaders(lowerCaseKeys = false) {
|
|
1700
|
+
if (this._chunks.length === 0) {
|
|
1701
|
+
return void 0;
|
|
1702
|
+
}
|
|
1703
|
+
let state2 = 0;
|
|
1704
|
+
let chunkIndex = 0;
|
|
1705
|
+
let offset = 0;
|
|
1706
|
+
let chunkBytesRead = 0;
|
|
1707
|
+
row: while (chunkIndex < this._chunks.length) {
|
|
1708
|
+
const chunk = this._chunks[chunkIndex];
|
|
1709
|
+
offset = 0;
|
|
1710
|
+
while (offset < chunk.length) {
|
|
1711
|
+
const value = chunk[offset];
|
|
1712
|
+
switch (value) {
|
|
1713
|
+
case CR:
|
|
1714
|
+
switch (state2) {
|
|
1715
|
+
case 0:
|
|
1716
|
+
state2 = 1;
|
|
1717
|
+
break;
|
|
1718
|
+
case 2:
|
|
1719
|
+
state2 = 3;
|
|
1720
|
+
break;
|
|
1721
|
+
default:
|
|
1722
|
+
state2 = 0;
|
|
1723
|
+
}
|
|
1724
|
+
break;
|
|
1725
|
+
case LF:
|
|
1726
|
+
switch (state2) {
|
|
1727
|
+
case 1:
|
|
1728
|
+
state2 = 2;
|
|
1729
|
+
break;
|
|
1730
|
+
case 3:
|
|
1731
|
+
state2 = 4;
|
|
1732
|
+
offset++;
|
|
1733
|
+
break row;
|
|
1734
|
+
default:
|
|
1735
|
+
state2 = 0;
|
|
1736
|
+
}
|
|
1737
|
+
break;
|
|
1738
|
+
default:
|
|
1739
|
+
state2 = 0;
|
|
1740
|
+
}
|
|
1741
|
+
offset++;
|
|
1742
|
+
}
|
|
1743
|
+
chunkBytesRead += chunk.byteLength;
|
|
1744
|
+
chunkIndex++;
|
|
1745
|
+
}
|
|
1746
|
+
if (state2 !== 4) {
|
|
1747
|
+
return void 0;
|
|
1748
|
+
}
|
|
1749
|
+
const buffer = this._read(chunkBytesRead + offset);
|
|
1750
|
+
const result = /* @__PURE__ */ new Map();
|
|
1751
|
+
const headers = this.toString(buffer, "ascii").split(CRLF);
|
|
1752
|
+
if (headers.length < 2) {
|
|
1753
|
+
return result;
|
|
1754
|
+
}
|
|
1755
|
+
for (let i = 0; i < headers.length - 2; i++) {
|
|
1756
|
+
const header = headers[i];
|
|
1757
|
+
const index = header.indexOf(":");
|
|
1758
|
+
if (index === -1) {
|
|
1759
|
+
throw new Error(`Message header must separate key and value using ':'
|
|
1760
|
+
${header}`);
|
|
1761
|
+
}
|
|
1762
|
+
const key = header.substr(0, index);
|
|
1763
|
+
const value = header.substr(index + 1).trim();
|
|
1764
|
+
result.set(lowerCaseKeys ? key.toLowerCase() : key, value);
|
|
1765
|
+
}
|
|
1766
|
+
return result;
|
|
1767
|
+
}
|
|
1768
|
+
tryReadBody(length) {
|
|
1769
|
+
if (this._totalLength < length) {
|
|
1770
|
+
return void 0;
|
|
1771
|
+
}
|
|
1772
|
+
return this._read(length);
|
|
1773
|
+
}
|
|
1774
|
+
get numberOfBytes() {
|
|
1775
|
+
return this._totalLength;
|
|
1776
|
+
}
|
|
1777
|
+
_read(byteCount) {
|
|
1778
|
+
if (byteCount === 0) {
|
|
1779
|
+
return this.emptyBuffer();
|
|
1780
|
+
}
|
|
1781
|
+
if (byteCount > this._totalLength) {
|
|
1782
|
+
throw new Error(`Cannot read so many bytes!`);
|
|
1783
|
+
}
|
|
1784
|
+
if (this._chunks[0].byteLength === byteCount) {
|
|
1785
|
+
const chunk = this._chunks[0];
|
|
1786
|
+
this._chunks.shift();
|
|
1787
|
+
this._totalLength -= byteCount;
|
|
1788
|
+
return this.asNative(chunk);
|
|
1789
|
+
}
|
|
1790
|
+
if (this._chunks[0].byteLength > byteCount) {
|
|
1791
|
+
const chunk = this._chunks[0];
|
|
1792
|
+
const result2 = this.asNative(chunk, byteCount);
|
|
1793
|
+
this._chunks[0] = chunk.slice(byteCount);
|
|
1794
|
+
this._totalLength -= byteCount;
|
|
1795
|
+
return result2;
|
|
1796
|
+
}
|
|
1797
|
+
const result = this.allocNative(byteCount);
|
|
1798
|
+
let resultOffset = 0;
|
|
1799
|
+
const chunkIndex = 0;
|
|
1800
|
+
while (byteCount > 0) {
|
|
1801
|
+
const chunk = this._chunks[chunkIndex];
|
|
1802
|
+
if (chunk.byteLength > byteCount) {
|
|
1803
|
+
const chunkPart = chunk.slice(0, byteCount);
|
|
1804
|
+
result.set(chunkPart, resultOffset);
|
|
1805
|
+
resultOffset += byteCount;
|
|
1806
|
+
this._chunks[chunkIndex] = chunk.slice(byteCount);
|
|
1807
|
+
this._totalLength -= byteCount;
|
|
1808
|
+
byteCount -= byteCount;
|
|
1809
|
+
} else {
|
|
1810
|
+
result.set(chunk, resultOffset);
|
|
1811
|
+
resultOffset += chunk.byteLength;
|
|
1812
|
+
this._chunks.shift();
|
|
1813
|
+
this._totalLength -= chunk.byteLength;
|
|
1814
|
+
byteCount -= chunk.byteLength;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
return result;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
messageBuffer.AbstractMessageBuffer = AbstractMessageBuffer;
|
|
1821
|
+
return messageBuffer;
|
|
1822
|
+
}
|
|
1823
|
+
var connection = {};
|
|
1824
|
+
var hasRequiredConnection;
|
|
1825
|
+
function requireConnection() {
|
|
1826
|
+
if (hasRequiredConnection) return connection;
|
|
1827
|
+
hasRequiredConnection = 1;
|
|
1828
|
+
(function(exports2) {
|
|
1829
|
+
var __createBinding = connection && connection.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1830
|
+
if (k2 === void 0) k2 = k;
|
|
1831
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1832
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1833
|
+
desc = { enumerable: true, get: function() {
|
|
1834
|
+
return m[k];
|
|
1835
|
+
} };
|
|
1836
|
+
}
|
|
1837
|
+
Object.defineProperty(o, k2, desc);
|
|
1838
|
+
}) : (function(o, m, k, k2) {
|
|
1839
|
+
if (k2 === void 0) k2 = k;
|
|
1840
|
+
o[k2] = m[k];
|
|
1841
|
+
}));
|
|
1842
|
+
var __setModuleDefault = connection && connection.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1843
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1844
|
+
}) : function(o, v) {
|
|
1845
|
+
o["default"] = v;
|
|
1846
|
+
});
|
|
1847
|
+
var __importStar = connection && connection.__importStar || /* @__PURE__ */ (function() {
|
|
1848
|
+
var ownKeys = function(o) {
|
|
1849
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1850
|
+
var ar = [];
|
|
1851
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1852
|
+
return ar;
|
|
1853
|
+
};
|
|
1854
|
+
return ownKeys(o);
|
|
1855
|
+
};
|
|
1856
|
+
return function(mod) {
|
|
1857
|
+
if (mod && mod.__esModule) return mod;
|
|
1858
|
+
var result = {};
|
|
1859
|
+
if (mod != null) {
|
|
1860
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1861
|
+
}
|
|
1862
|
+
__setModuleDefault(result, mod);
|
|
1863
|
+
return result;
|
|
1864
|
+
};
|
|
1865
|
+
})();
|
|
1866
|
+
var __importDefault = connection && connection.__importDefault || function(mod) {
|
|
1867
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
1868
|
+
};
|
|
1869
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
1870
|
+
exports2.ConnectionOptions = exports2.MessageStrategy = exports2.CancellationStrategy = exports2.CancellationSenderStrategy = exports2.CancellationReceiverStrategy = exports2.RequestCancellationReceiverStrategy = exports2.IdCancellationReceiverStrategy = exports2.ConnectionStrategy = exports2.ConnectionError = exports2.ConnectionErrors = exports2.LogTraceNotification = exports2.SetTraceNotification = exports2.TraceFormat = exports2.TraceValues = exports2.TraceValue = exports2.Trace = exports2.NullLogger = exports2.ProgressType = exports2.ProgressToken = void 0;
|
|
1871
|
+
exports2.createMessageConnection = createMessageConnection;
|
|
1872
|
+
const ral_1 = __importDefault(requireRal());
|
|
1873
|
+
const Is = __importStar(requireIs());
|
|
1874
|
+
const messages_1 = requireMessages();
|
|
1875
|
+
const linkedMap_1 = requireLinkedMap();
|
|
1876
|
+
const events_1 = requireEvents();
|
|
1877
|
+
const cancellation_1 = requireCancellation();
|
|
1878
|
+
var CancelNotification;
|
|
1879
|
+
(function(CancelNotification2) {
|
|
1880
|
+
CancelNotification2.type = new messages_1.NotificationType("$/cancelRequest");
|
|
1881
|
+
})(CancelNotification || (CancelNotification = {}));
|
|
1882
|
+
var ProgressToken;
|
|
1883
|
+
(function(ProgressToken2) {
|
|
1884
|
+
function is2(value) {
|
|
1885
|
+
return typeof value === "string" || typeof value === "number";
|
|
1886
|
+
}
|
|
1887
|
+
ProgressToken2.is = is2;
|
|
1888
|
+
})(ProgressToken || (exports2.ProgressToken = ProgressToken = {}));
|
|
1889
|
+
var ProgressNotification;
|
|
1890
|
+
(function(ProgressNotification2) {
|
|
1891
|
+
ProgressNotification2.type = new messages_1.NotificationType("$/progress");
|
|
1892
|
+
})(ProgressNotification || (ProgressNotification = {}));
|
|
1893
|
+
class ProgressType {
|
|
1894
|
+
/**
|
|
1895
|
+
* Clients must not use these properties. They are here to ensure correct typing.
|
|
1896
|
+
* in TypeScript
|
|
1897
|
+
*/
|
|
1898
|
+
__;
|
|
1899
|
+
_pr;
|
|
1900
|
+
constructor() {
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
exports2.ProgressType = ProgressType;
|
|
1904
|
+
var StarRequestHandler;
|
|
1905
|
+
(function(StarRequestHandler2) {
|
|
1906
|
+
function is2(value) {
|
|
1907
|
+
return Is.func(value);
|
|
1908
|
+
}
|
|
1909
|
+
StarRequestHandler2.is = is2;
|
|
1910
|
+
})(StarRequestHandler || (StarRequestHandler = {}));
|
|
1911
|
+
exports2.NullLogger = Object.freeze({
|
|
1912
|
+
error: () => {
|
|
1913
|
+
},
|
|
1914
|
+
warn: () => {
|
|
1915
|
+
},
|
|
1916
|
+
info: () => {
|
|
1917
|
+
},
|
|
1918
|
+
log: () => {
|
|
1919
|
+
}
|
|
1920
|
+
});
|
|
1921
|
+
var Trace;
|
|
1922
|
+
(function(Trace2) {
|
|
1923
|
+
Trace2[Trace2["Off"] = 0] = "Off";
|
|
1924
|
+
Trace2[Trace2["Messages"] = 1] = "Messages";
|
|
1925
|
+
Trace2[Trace2["Compact"] = 2] = "Compact";
|
|
1926
|
+
Trace2[Trace2["Verbose"] = 3] = "Verbose";
|
|
1927
|
+
})(Trace || (exports2.Trace = Trace = {}));
|
|
1928
|
+
var TraceValue;
|
|
1929
|
+
(function(TraceValue2) {
|
|
1930
|
+
TraceValue2.Off = "off";
|
|
1931
|
+
TraceValue2.Messages = "messages";
|
|
1932
|
+
TraceValue2.Compact = "compact";
|
|
1933
|
+
TraceValue2.Verbose = "verbose";
|
|
1934
|
+
})(TraceValue || (exports2.TraceValue = TraceValue = {}));
|
|
1935
|
+
exports2.TraceValues = TraceValue;
|
|
1936
|
+
(function(Trace2) {
|
|
1937
|
+
function fromString(value) {
|
|
1938
|
+
if (!Is.string(value)) {
|
|
1939
|
+
return Trace2.Off;
|
|
1940
|
+
}
|
|
1941
|
+
value = value.toLowerCase();
|
|
1942
|
+
switch (value) {
|
|
1943
|
+
case "off":
|
|
1944
|
+
return Trace2.Off;
|
|
1945
|
+
case "messages":
|
|
1946
|
+
return Trace2.Messages;
|
|
1947
|
+
case "compact":
|
|
1948
|
+
return Trace2.Compact;
|
|
1949
|
+
case "verbose":
|
|
1950
|
+
return Trace2.Verbose;
|
|
1951
|
+
default:
|
|
1952
|
+
return Trace2.Off;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
Trace2.fromString = fromString;
|
|
1956
|
+
function toString(value) {
|
|
1957
|
+
switch (value) {
|
|
1958
|
+
case Trace2.Off:
|
|
1959
|
+
return "off";
|
|
1960
|
+
case Trace2.Messages:
|
|
1961
|
+
return "messages";
|
|
1962
|
+
case Trace2.Compact:
|
|
1963
|
+
return "compact";
|
|
1964
|
+
case Trace2.Verbose:
|
|
1965
|
+
return "verbose";
|
|
1966
|
+
default:
|
|
1967
|
+
return "off";
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
Trace2.toString = toString;
|
|
1971
|
+
})(Trace || (exports2.Trace = Trace = {}));
|
|
1972
|
+
var TraceFormat;
|
|
1973
|
+
(function(TraceFormat2) {
|
|
1974
|
+
TraceFormat2["Text"] = "text";
|
|
1975
|
+
TraceFormat2["JSON"] = "json";
|
|
1976
|
+
})(TraceFormat || (exports2.TraceFormat = TraceFormat = {}));
|
|
1977
|
+
(function(TraceFormat2) {
|
|
1978
|
+
function fromString(value) {
|
|
1979
|
+
if (!Is.string(value)) {
|
|
1980
|
+
return TraceFormat2.Text;
|
|
1981
|
+
}
|
|
1982
|
+
value = value.toLowerCase();
|
|
1983
|
+
if (value === "json") {
|
|
1984
|
+
return TraceFormat2.JSON;
|
|
1985
|
+
} else {
|
|
1986
|
+
return TraceFormat2.Text;
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
TraceFormat2.fromString = fromString;
|
|
1990
|
+
})(TraceFormat || (exports2.TraceFormat = TraceFormat = {}));
|
|
1991
|
+
var SetTraceNotification;
|
|
1992
|
+
(function(SetTraceNotification2) {
|
|
1993
|
+
SetTraceNotification2.type = new messages_1.NotificationType("$/setTrace");
|
|
1994
|
+
})(SetTraceNotification || (exports2.SetTraceNotification = SetTraceNotification = {}));
|
|
1995
|
+
var LogTraceNotification;
|
|
1996
|
+
(function(LogTraceNotification2) {
|
|
1997
|
+
LogTraceNotification2.type = new messages_1.NotificationType("$/logTrace");
|
|
1998
|
+
})(LogTraceNotification || (exports2.LogTraceNotification = LogTraceNotification = {}));
|
|
1999
|
+
var ConnectionErrors;
|
|
2000
|
+
(function(ConnectionErrors2) {
|
|
2001
|
+
ConnectionErrors2[ConnectionErrors2["Closed"] = 1] = "Closed";
|
|
2002
|
+
ConnectionErrors2[ConnectionErrors2["Disposed"] = 2] = "Disposed";
|
|
2003
|
+
ConnectionErrors2[ConnectionErrors2["AlreadyListening"] = 3] = "AlreadyListening";
|
|
2004
|
+
})(ConnectionErrors || (exports2.ConnectionErrors = ConnectionErrors = {}));
|
|
2005
|
+
class ConnectionError extends Error {
|
|
2006
|
+
code;
|
|
2007
|
+
constructor(code, message) {
|
|
2008
|
+
super(message);
|
|
2009
|
+
this.code = code;
|
|
2010
|
+
Object.setPrototypeOf(this, ConnectionError.prototype);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
exports2.ConnectionError = ConnectionError;
|
|
2014
|
+
var ConnectionStrategy;
|
|
2015
|
+
(function(ConnectionStrategy2) {
|
|
2016
|
+
function is2(value) {
|
|
2017
|
+
const candidate = value;
|
|
2018
|
+
return candidate && Is.func(candidate.cancelUndispatched);
|
|
2019
|
+
}
|
|
2020
|
+
ConnectionStrategy2.is = is2;
|
|
2021
|
+
})(ConnectionStrategy || (exports2.ConnectionStrategy = ConnectionStrategy = {}));
|
|
2022
|
+
var IdCancellationReceiverStrategy;
|
|
2023
|
+
(function(IdCancellationReceiverStrategy2) {
|
|
2024
|
+
function is2(value) {
|
|
2025
|
+
const candidate = value;
|
|
2026
|
+
return candidate && (candidate.kind === void 0 || candidate.kind === "id") && Is.func(candidate.createCancellationTokenSource) && (candidate.dispose === void 0 || Is.func(candidate.dispose));
|
|
2027
|
+
}
|
|
2028
|
+
IdCancellationReceiverStrategy2.is = is2;
|
|
2029
|
+
})(IdCancellationReceiverStrategy || (exports2.IdCancellationReceiverStrategy = IdCancellationReceiverStrategy = {}));
|
|
2030
|
+
var RequestCancellationReceiverStrategy;
|
|
2031
|
+
(function(RequestCancellationReceiverStrategy2) {
|
|
2032
|
+
function is2(value) {
|
|
2033
|
+
const candidate = value;
|
|
2034
|
+
return candidate && candidate.kind === "request" && Is.func(candidate.createCancellationTokenSource) && (candidate.dispose === void 0 || Is.func(candidate.dispose));
|
|
2035
|
+
}
|
|
2036
|
+
RequestCancellationReceiverStrategy2.is = is2;
|
|
2037
|
+
})(RequestCancellationReceiverStrategy || (exports2.RequestCancellationReceiverStrategy = RequestCancellationReceiverStrategy = {}));
|
|
2038
|
+
var CancellationReceiverStrategy;
|
|
2039
|
+
(function(CancellationReceiverStrategy2) {
|
|
2040
|
+
CancellationReceiverStrategy2.Message = Object.freeze({
|
|
2041
|
+
createCancellationTokenSource(_) {
|
|
2042
|
+
return new cancellation_1.CancellationTokenSource();
|
|
2043
|
+
}
|
|
2044
|
+
});
|
|
2045
|
+
function is2(value) {
|
|
2046
|
+
return IdCancellationReceiverStrategy.is(value) || RequestCancellationReceiverStrategy.is(value);
|
|
2047
|
+
}
|
|
2048
|
+
CancellationReceiverStrategy2.is = is2;
|
|
2049
|
+
})(CancellationReceiverStrategy || (exports2.CancellationReceiverStrategy = CancellationReceiverStrategy = {}));
|
|
2050
|
+
var CancellationSenderStrategy;
|
|
2051
|
+
(function(CancellationSenderStrategy2) {
|
|
2052
|
+
CancellationSenderStrategy2.Message = Object.freeze({
|
|
2053
|
+
sendCancellation(conn, id) {
|
|
2054
|
+
return conn.sendNotification(CancelNotification.type, { id });
|
|
2055
|
+
},
|
|
2056
|
+
cleanup(_) {
|
|
2057
|
+
}
|
|
2058
|
+
});
|
|
2059
|
+
function is2(value) {
|
|
2060
|
+
const candidate = value;
|
|
2061
|
+
return candidate && Is.func(candidate.sendCancellation) && Is.func(candidate.cleanup);
|
|
2062
|
+
}
|
|
2063
|
+
CancellationSenderStrategy2.is = is2;
|
|
2064
|
+
})(CancellationSenderStrategy || (exports2.CancellationSenderStrategy = CancellationSenderStrategy = {}));
|
|
2065
|
+
var CancellationStrategy;
|
|
2066
|
+
(function(CancellationStrategy2) {
|
|
2067
|
+
CancellationStrategy2.Message = Object.freeze({
|
|
2068
|
+
receiver: CancellationReceiverStrategy.Message,
|
|
2069
|
+
sender: CancellationSenderStrategy.Message
|
|
2070
|
+
});
|
|
2071
|
+
function is2(value) {
|
|
2072
|
+
const candidate = value;
|
|
2073
|
+
return candidate && CancellationReceiverStrategy.is(candidate.receiver) && CancellationSenderStrategy.is(candidate.sender);
|
|
2074
|
+
}
|
|
2075
|
+
CancellationStrategy2.is = is2;
|
|
2076
|
+
})(CancellationStrategy || (exports2.CancellationStrategy = CancellationStrategy = {}));
|
|
2077
|
+
var MessageStrategy;
|
|
2078
|
+
(function(MessageStrategy2) {
|
|
2079
|
+
function is2(value) {
|
|
2080
|
+
const candidate = value;
|
|
2081
|
+
return candidate && Is.func(candidate.handleMessage);
|
|
2082
|
+
}
|
|
2083
|
+
MessageStrategy2.is = is2;
|
|
2084
|
+
})(MessageStrategy || (exports2.MessageStrategy = MessageStrategy = {}));
|
|
2085
|
+
var ConnectionOptions;
|
|
2086
|
+
(function(ConnectionOptions2) {
|
|
2087
|
+
function is2(value) {
|
|
2088
|
+
const candidate = value;
|
|
2089
|
+
return candidate && (CancellationStrategy.is(candidate.cancellationStrategy) || ConnectionStrategy.is(candidate.connectionStrategy) || MessageStrategy.is(candidate.messageStrategy) || Is.number(candidate.maxParallelism));
|
|
2090
|
+
}
|
|
2091
|
+
ConnectionOptions2.is = is2;
|
|
2092
|
+
})(ConnectionOptions || (exports2.ConnectionOptions = ConnectionOptions = {}));
|
|
2093
|
+
var ConnectionState;
|
|
2094
|
+
(function(ConnectionState2) {
|
|
2095
|
+
ConnectionState2[ConnectionState2["New"] = 1] = "New";
|
|
2096
|
+
ConnectionState2[ConnectionState2["Listening"] = 2] = "Listening";
|
|
2097
|
+
ConnectionState2[ConnectionState2["Closed"] = 3] = "Closed";
|
|
2098
|
+
ConnectionState2[ConnectionState2["Disposed"] = 4] = "Disposed";
|
|
2099
|
+
})(ConnectionState || (ConnectionState = {}));
|
|
2100
|
+
function createMessageConnection(messageReader2, messageWriter2, _logger, options) {
|
|
2101
|
+
const logger = _logger !== void 0 ? _logger : exports2.NullLogger;
|
|
2102
|
+
let sequenceNumber = 0;
|
|
2103
|
+
let notificationSequenceNumber = 0;
|
|
2104
|
+
let unknownResponseSequenceNumber = 0;
|
|
2105
|
+
const version = "2.0";
|
|
2106
|
+
const maxParallelism = options?.maxParallelism ?? -1;
|
|
2107
|
+
let inFlight = 0;
|
|
2108
|
+
let starRequestHandler = void 0;
|
|
2109
|
+
const requestHandlers = /* @__PURE__ */ new Map();
|
|
2110
|
+
let starNotificationHandler = void 0;
|
|
2111
|
+
const notificationHandlers = /* @__PURE__ */ new Map();
|
|
2112
|
+
const progressHandlers = /* @__PURE__ */ new Map();
|
|
2113
|
+
let timer;
|
|
2114
|
+
let messageQueue = new linkedMap_1.LinkedMap();
|
|
2115
|
+
let responsePromises = /* @__PURE__ */ new Map();
|
|
2116
|
+
let knownCanceledRequests = /* @__PURE__ */ new Set();
|
|
2117
|
+
let requestTokens = /* @__PURE__ */ new Map();
|
|
2118
|
+
let trace = Trace.Off;
|
|
2119
|
+
let traceFormat = TraceFormat.Text;
|
|
2120
|
+
let tracer;
|
|
2121
|
+
let state2 = ConnectionState.New;
|
|
2122
|
+
const errorEmitter = new events_1.Emitter();
|
|
2123
|
+
const closeEmitter = new events_1.Emitter();
|
|
2124
|
+
const unhandledNotificationEmitter = new events_1.Emitter();
|
|
2125
|
+
const unhandledProgressEmitter = new events_1.Emitter();
|
|
2126
|
+
const disposeEmitter = new events_1.Emitter();
|
|
2127
|
+
const cancellationStrategy = options && options.cancellationStrategy ? options.cancellationStrategy : CancellationStrategy.Message;
|
|
2128
|
+
function cancelUndispatched(_message) {
|
|
2129
|
+
return void 0;
|
|
2130
|
+
}
|
|
2131
|
+
function isListening() {
|
|
2132
|
+
return state2 === ConnectionState.Listening;
|
|
2133
|
+
}
|
|
2134
|
+
function isClosed() {
|
|
2135
|
+
return state2 === ConnectionState.Closed;
|
|
2136
|
+
}
|
|
2137
|
+
function isDisposed() {
|
|
2138
|
+
return state2 === ConnectionState.Disposed;
|
|
2139
|
+
}
|
|
2140
|
+
function closeHandler() {
|
|
2141
|
+
if (state2 === ConnectionState.New || state2 === ConnectionState.Listening) {
|
|
2142
|
+
state2 = ConnectionState.Closed;
|
|
2143
|
+
closeEmitter.fire(void 0);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
function readErrorHandler(error) {
|
|
2147
|
+
errorEmitter.fire([error, void 0, void 0]);
|
|
2148
|
+
}
|
|
2149
|
+
function writeErrorHandler(data) {
|
|
2150
|
+
errorEmitter.fire(data);
|
|
2151
|
+
}
|
|
2152
|
+
messageReader2.onClose(closeHandler);
|
|
2153
|
+
messageReader2.onError(readErrorHandler);
|
|
2154
|
+
messageWriter2.onClose(closeHandler);
|
|
2155
|
+
messageWriter2.onError(writeErrorHandler);
|
|
2156
|
+
function createRequestQueueKey(id) {
|
|
2157
|
+
if (id === null) {
|
|
2158
|
+
throw new Error(`Can't send requests with id null since the response can't be correlated.`);
|
|
2159
|
+
}
|
|
2160
|
+
return "req-" + id.toString();
|
|
2161
|
+
}
|
|
2162
|
+
function createResponseQueueKey(id) {
|
|
2163
|
+
if (id === null) {
|
|
2164
|
+
return "res-unknown-" + (++unknownResponseSequenceNumber).toString();
|
|
2165
|
+
} else {
|
|
2166
|
+
return "res-" + id.toString();
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
function createNotificationQueueKey() {
|
|
2170
|
+
return "not-" + (++notificationSequenceNumber).toString();
|
|
2171
|
+
}
|
|
2172
|
+
function addMessageToQueue(queue, message) {
|
|
2173
|
+
if (messages_1.Message.isRequest(message)) {
|
|
2174
|
+
queue.set(createRequestQueueKey(message.id), message);
|
|
2175
|
+
} else if (messages_1.Message.isResponse(message)) {
|
|
2176
|
+
if (maxParallelism === -1) {
|
|
2177
|
+
queue.set(createResponseQueueKey(message.id), message);
|
|
2178
|
+
} else {
|
|
2179
|
+
handleResponse(message);
|
|
2180
|
+
}
|
|
2181
|
+
} else {
|
|
2182
|
+
queue.set(createNotificationQueueKey(), message);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
function triggerMessageQueue() {
|
|
2186
|
+
if (timer || messageQueue.size === 0) {
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
if (maxParallelism !== -1 && inFlight >= maxParallelism) {
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
timer = (0, ral_1.default)().timer.setImmediate(async () => {
|
|
2193
|
+
timer = void 0;
|
|
2194
|
+
if (messageQueue.size === 0) {
|
|
2195
|
+
return;
|
|
2196
|
+
}
|
|
2197
|
+
if (maxParallelism !== -1 && inFlight >= maxParallelism) {
|
|
2198
|
+
return;
|
|
2199
|
+
}
|
|
2200
|
+
const message = messageQueue.shift();
|
|
2201
|
+
let result;
|
|
2202
|
+
try {
|
|
2203
|
+
inFlight++;
|
|
2204
|
+
const messageStrategy = options?.messageStrategy;
|
|
2205
|
+
if (MessageStrategy.is(messageStrategy)) {
|
|
2206
|
+
result = messageStrategy.handleMessage(message, handleMessage);
|
|
2207
|
+
} else {
|
|
2208
|
+
result = handleMessage(message);
|
|
2209
|
+
}
|
|
2210
|
+
} catch (error) {
|
|
2211
|
+
logger.error(`Processing message queue failed: ${error.toString()}`);
|
|
2212
|
+
} finally {
|
|
2213
|
+
if (result instanceof Promise) {
|
|
2214
|
+
result.then(() => {
|
|
2215
|
+
inFlight--;
|
|
2216
|
+
triggerMessageQueue();
|
|
2217
|
+
}).catch((error) => {
|
|
2218
|
+
logger.error(`Processing message queue failed: ${error.toString()}`);
|
|
2219
|
+
});
|
|
2220
|
+
} else {
|
|
2221
|
+
inFlight--;
|
|
2222
|
+
}
|
|
2223
|
+
triggerMessageQueue();
|
|
2224
|
+
}
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
async function handleMessage(message) {
|
|
2228
|
+
if (messages_1.Message.isRequest(message)) {
|
|
2229
|
+
return handleRequest(message);
|
|
2230
|
+
} else if (messages_1.Message.isNotification(message)) {
|
|
2231
|
+
return handleNotification(message);
|
|
2232
|
+
} else if (messages_1.Message.isResponse(message)) {
|
|
2233
|
+
return handleResponse(message);
|
|
2234
|
+
} else {
|
|
2235
|
+
return handleInvalidMessage(message);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
const callback = (message) => {
|
|
2239
|
+
try {
|
|
2240
|
+
if (messages_1.Message.isNotification(message) && message.method === CancelNotification.type.method) {
|
|
2241
|
+
const cancelId = message.params.id;
|
|
2242
|
+
const key = createRequestQueueKey(cancelId);
|
|
2243
|
+
const toCancel = messageQueue.get(key);
|
|
2244
|
+
if (messages_1.Message.isRequest(toCancel)) {
|
|
2245
|
+
const strategy = options?.connectionStrategy;
|
|
2246
|
+
const response = strategy && strategy.cancelUndispatched ? strategy.cancelUndispatched(toCancel, cancelUndispatched) : cancelUndispatched(toCancel);
|
|
2247
|
+
if (response && (response.error !== void 0 || response.result !== void 0)) {
|
|
2248
|
+
messageQueue.delete(key);
|
|
2249
|
+
requestTokens.delete(cancelId);
|
|
2250
|
+
response.id = toCancel.id;
|
|
2251
|
+
traceSendingResponse(response, message.method, Date.now());
|
|
2252
|
+
messageWriter2.write(response).catch(() => logger.error(`Sending response for canceled message failed.`));
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
const cancellationToken = requestTokens.get(cancelId);
|
|
2257
|
+
if (cancellationToken !== void 0) {
|
|
2258
|
+
cancellationToken.cancel();
|
|
2259
|
+
traceReceivedNotification(message);
|
|
2260
|
+
return;
|
|
2261
|
+
} else {
|
|
2262
|
+
knownCanceledRequests.add(cancelId);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
addMessageToQueue(messageQueue, message);
|
|
2266
|
+
} finally {
|
|
2267
|
+
triggerMessageQueue();
|
|
2268
|
+
}
|
|
2269
|
+
};
|
|
2270
|
+
async function handleRequest(requestMessage) {
|
|
2271
|
+
if (isDisposed()) {
|
|
2272
|
+
return Promise.resolve();
|
|
2273
|
+
}
|
|
2274
|
+
function reply(resultOrError, method, startTime2) {
|
|
2275
|
+
const message = {
|
|
2276
|
+
jsonrpc: version,
|
|
2277
|
+
id: requestMessage.id
|
|
2278
|
+
};
|
|
2279
|
+
if (resultOrError instanceof messages_1.ResponseError) {
|
|
2280
|
+
message.error = resultOrError.toJson();
|
|
2281
|
+
} else {
|
|
2282
|
+
message.result = resultOrError === void 0 ? null : resultOrError;
|
|
2283
|
+
}
|
|
2284
|
+
traceSendingResponse(message, method, startTime2);
|
|
2285
|
+
return messageWriter2.write(message);
|
|
2286
|
+
}
|
|
2287
|
+
function replyError(error, method, startTime2) {
|
|
2288
|
+
const message = {
|
|
2289
|
+
jsonrpc: version,
|
|
2290
|
+
id: requestMessage.id,
|
|
2291
|
+
error: error.toJson()
|
|
2292
|
+
};
|
|
2293
|
+
traceSendingResponse(message, method, startTime2);
|
|
2294
|
+
return messageWriter2.write(message);
|
|
2295
|
+
}
|
|
2296
|
+
traceReceivedRequest(requestMessage);
|
|
2297
|
+
const element = requestHandlers.get(requestMessage.method);
|
|
2298
|
+
let type;
|
|
2299
|
+
let requestHandler;
|
|
2300
|
+
if (element) {
|
|
2301
|
+
type = element.type;
|
|
2302
|
+
requestHandler = element.handler;
|
|
2303
|
+
}
|
|
2304
|
+
const startTime = Date.now();
|
|
2305
|
+
if (requestHandler || starRequestHandler) {
|
|
2306
|
+
const tokenKey = requestMessage.id ?? String(Date.now());
|
|
2307
|
+
const cancellationSource = IdCancellationReceiverStrategy.is(cancellationStrategy.receiver) ? cancellationStrategy.receiver.createCancellationTokenSource(tokenKey) : cancellationStrategy.receiver.createCancellationTokenSource(requestMessage);
|
|
2308
|
+
if (requestMessage.id !== null && knownCanceledRequests.has(requestMessage.id)) {
|
|
2309
|
+
cancellationSource.cancel();
|
|
2310
|
+
}
|
|
2311
|
+
if (requestMessage.id !== null) {
|
|
2312
|
+
requestTokens.set(tokenKey, cancellationSource);
|
|
2313
|
+
}
|
|
2314
|
+
try {
|
|
2315
|
+
let handlerResult;
|
|
2316
|
+
if (requestHandler) {
|
|
2317
|
+
if (requestMessage.params === void 0) {
|
|
2318
|
+
if (type !== void 0 && type.numberOfParams !== 0) {
|
|
2319
|
+
return replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines ${type.numberOfParams} params but received none.`), requestMessage.method, startTime);
|
|
2320
|
+
}
|
|
2321
|
+
handlerResult = requestHandler(cancellationSource.token);
|
|
2322
|
+
} else if (Array.isArray(requestMessage.params)) {
|
|
2323
|
+
if (type !== void 0 && type.parameterStructures === messages_1.ParameterStructures.byName) {
|
|
2324
|
+
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);
|
|
2325
|
+
}
|
|
2326
|
+
handlerResult = requestHandler(...requestMessage.params, cancellationSource.token);
|
|
2327
|
+
} else {
|
|
2328
|
+
if (type !== void 0 && type.parameterStructures === messages_1.ParameterStructures.byPosition) {
|
|
2329
|
+
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);
|
|
2330
|
+
}
|
|
2331
|
+
handlerResult = requestHandler(requestMessage.params, cancellationSource.token);
|
|
2332
|
+
}
|
|
2333
|
+
} else if (starRequestHandler) {
|
|
2334
|
+
handlerResult = starRequestHandler(requestMessage.method, requestMessage.params, cancellationSource.token);
|
|
2335
|
+
}
|
|
2336
|
+
const resultOrError = await handlerResult;
|
|
2337
|
+
await reply(resultOrError, requestMessage.method, startTime);
|
|
2338
|
+
} catch (error) {
|
|
2339
|
+
if (error instanceof messages_1.ResponseError) {
|
|
2340
|
+
await reply(error, requestMessage.method, startTime);
|
|
2341
|
+
} else if (error && Is.string(error.message)) {
|
|
2342
|
+
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed with message: ${error.message}`), requestMessage.method, startTime);
|
|
2343
|
+
} else {
|
|
2344
|
+
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed unexpectedly without providing any details.`), requestMessage.method, startTime);
|
|
2345
|
+
}
|
|
2346
|
+
} finally {
|
|
2347
|
+
requestTokens.delete(tokenKey);
|
|
2348
|
+
}
|
|
2349
|
+
} else {
|
|
2350
|
+
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.MethodNotFound, `Unhandled method ${requestMessage.method}`), requestMessage.method, startTime);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
function handleResponse(responseMessage) {
|
|
2354
|
+
if (isDisposed()) {
|
|
2355
|
+
return;
|
|
2356
|
+
}
|
|
2357
|
+
if (responseMessage.id === null) {
|
|
2358
|
+
if (responseMessage.error) {
|
|
2359
|
+
logger.error(`Received response message without id: Error is:
|
|
2360
|
+
${JSON.stringify(responseMessage.error, void 0, 4)}`);
|
|
2361
|
+
} else {
|
|
2362
|
+
logger.error(`Received response message without id. No further error information provided.`);
|
|
2363
|
+
}
|
|
2364
|
+
} else {
|
|
2365
|
+
const key = responseMessage.id;
|
|
2366
|
+
const responsePromise = responsePromises.get(key);
|
|
2367
|
+
traceReceivedResponse(responseMessage, responsePromise);
|
|
2368
|
+
if (responsePromise !== void 0) {
|
|
2369
|
+
responsePromises.delete(key);
|
|
2370
|
+
try {
|
|
2371
|
+
if (responseMessage.error) {
|
|
2372
|
+
const error = responseMessage.error;
|
|
2373
|
+
responsePromise.reject(new messages_1.ResponseError(error.code, error.message, error.data));
|
|
2374
|
+
} else if (responseMessage.result !== void 0) {
|
|
2375
|
+
responsePromise.resolve(responseMessage.result);
|
|
2376
|
+
} else {
|
|
2377
|
+
throw new Error("Should never happen.");
|
|
2378
|
+
}
|
|
2379
|
+
} catch (error) {
|
|
2380
|
+
if (error.message) {
|
|
2381
|
+
logger.error(`Response handler '${responsePromise.method}' failed with message: ${error.message}`);
|
|
2382
|
+
} else {
|
|
2383
|
+
logger.error(`Response handler '${responsePromise.method}' failed unexpectedly.`);
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
async function handleNotification(message) {
|
|
2390
|
+
if (isDisposed()) {
|
|
2391
|
+
return;
|
|
2392
|
+
}
|
|
2393
|
+
let type = void 0;
|
|
2394
|
+
let notificationHandler;
|
|
2395
|
+
if (message.method === CancelNotification.type.method) {
|
|
2396
|
+
const cancelId = message.params.id;
|
|
2397
|
+
knownCanceledRequests.delete(cancelId);
|
|
2398
|
+
traceReceivedNotification(message);
|
|
2399
|
+
return;
|
|
2400
|
+
} else {
|
|
2401
|
+
const element = notificationHandlers.get(message.method);
|
|
2402
|
+
if (element) {
|
|
2403
|
+
notificationHandler = element.handler;
|
|
2404
|
+
type = element.type;
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
if (notificationHandler || starNotificationHandler) {
|
|
2408
|
+
try {
|
|
2409
|
+
traceReceivedNotification(message);
|
|
2410
|
+
if (notificationHandler) {
|
|
2411
|
+
if (message.params === void 0) {
|
|
2412
|
+
if (type !== void 0) {
|
|
2413
|
+
if (type.numberOfParams !== 0 && type.parameterStructures !== messages_1.ParameterStructures.byName) {
|
|
2414
|
+
logger.error(`Notification ${message.method} defines ${type.numberOfParams} params but received none.`);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
await notificationHandler();
|
|
2418
|
+
} else if (Array.isArray(message.params)) {
|
|
2419
|
+
const params = message.params;
|
|
2420
|
+
if (message.method === ProgressNotification.type.method && params.length === 2 && ProgressToken.is(params[0])) {
|
|
2421
|
+
await notificationHandler({ token: params[0], value: params[1] });
|
|
2422
|
+
} else {
|
|
2423
|
+
if (type !== void 0) {
|
|
2424
|
+
if (type.parameterStructures === messages_1.ParameterStructures.byName) {
|
|
2425
|
+
logger.error(`Notification ${message.method} defines parameters by name but received parameters by position`);
|
|
2426
|
+
}
|
|
2427
|
+
if (type.numberOfParams !== message.params.length) {
|
|
2428
|
+
logger.error(`Notification ${message.method} defines ${type.numberOfParams} params but received ${params.length} arguments`);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
await notificationHandler(...params);
|
|
2432
|
+
}
|
|
2433
|
+
} else {
|
|
2434
|
+
if (type !== void 0 && type.parameterStructures === messages_1.ParameterStructures.byPosition) {
|
|
2435
|
+
logger.error(`Notification ${message.method} defines parameters by position but received parameters by name`);
|
|
2436
|
+
}
|
|
2437
|
+
await notificationHandler(message.params);
|
|
2438
|
+
}
|
|
2439
|
+
} else if (starNotificationHandler) {
|
|
2440
|
+
await starNotificationHandler(message.method, message.params);
|
|
2441
|
+
}
|
|
2442
|
+
} catch (error) {
|
|
2443
|
+
if (error.message) {
|
|
2444
|
+
logger.error(`Notification handler '${message.method}' failed with message: ${error.message}`);
|
|
2445
|
+
} else {
|
|
2446
|
+
logger.error(`Notification handler '${message.method}' failed unexpectedly.`);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
} else {
|
|
2450
|
+
unhandledNotificationEmitter.fire(message);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
function handleInvalidMessage(message) {
|
|
2454
|
+
if (!message) {
|
|
2455
|
+
logger.error("Received empty message.");
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2458
|
+
logger.error(`Received message which is neither a response nor a notification message:
|
|
2459
|
+
${JSON.stringify(message, null, 4)}`);
|
|
2460
|
+
const responseMessage = message;
|
|
2461
|
+
if (Is.string(responseMessage.id) || Is.number(responseMessage.id)) {
|
|
2462
|
+
const key = responseMessage.id;
|
|
2463
|
+
const responseHandler = responsePromises.get(key);
|
|
2464
|
+
if (responseHandler) {
|
|
2465
|
+
responseHandler.reject(new Error("The received response has neither a result nor an error property."));
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
function stringifyTrace(params) {
|
|
2470
|
+
if (params === void 0 || params === null) {
|
|
2471
|
+
return void 0;
|
|
2472
|
+
}
|
|
2473
|
+
switch (trace) {
|
|
2474
|
+
case Trace.Verbose:
|
|
2475
|
+
return JSON.stringify(params, null, 4);
|
|
2476
|
+
case Trace.Compact:
|
|
2477
|
+
return JSON.stringify(params);
|
|
2478
|
+
default:
|
|
2479
|
+
return void 0;
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
function traceSendingRequest(message) {
|
|
2483
|
+
if (trace === Trace.Off || !tracer) {
|
|
2484
|
+
return;
|
|
2485
|
+
}
|
|
2486
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2487
|
+
let data = void 0;
|
|
2488
|
+
if ((trace === Trace.Verbose || trace === Trace.Compact) && message.params) {
|
|
2489
|
+
data = `Params: ${stringifyTrace(message.params)}`;
|
|
2490
|
+
}
|
|
2491
|
+
tracer.log(`Sending request '${message.method} - (${message.id})'.`, data);
|
|
2492
|
+
} else {
|
|
2493
|
+
logLSPMessage("send-request", message);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
function traceSendingNotification(message) {
|
|
2497
|
+
if (trace === Trace.Off || !tracer) {
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2501
|
+
let data = void 0;
|
|
2502
|
+
if (trace === Trace.Verbose || trace === Trace.Compact) {
|
|
2503
|
+
if (message.params) {
|
|
2504
|
+
data = `Params: ${stringifyTrace(message.params)}`;
|
|
2505
|
+
} else {
|
|
2506
|
+
data = "No parameters provided.";
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
tracer.log(`Sending notification '${message.method}'.`, data);
|
|
2510
|
+
} else {
|
|
2511
|
+
logLSPMessage("send-notification", message);
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
function traceSendingResponse(message, method, startTime) {
|
|
2515
|
+
if (trace === Trace.Off || !tracer) {
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2519
|
+
let data = void 0;
|
|
2520
|
+
if (trace === Trace.Verbose || trace === Trace.Compact) {
|
|
2521
|
+
if (message.error && message.error.data) {
|
|
2522
|
+
data = `Error data: ${stringifyTrace(message.error.data)}`;
|
|
2523
|
+
} else {
|
|
2524
|
+
if (message.result) {
|
|
2525
|
+
data = `Result: ${stringifyTrace(message.result)}`;
|
|
2526
|
+
} else if (message.error === void 0) {
|
|
2527
|
+
data = "No result returned.";
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
tracer.log(`Sending response '${method} - (${message.id})'. Processing request took ${Date.now() - startTime}ms`, data);
|
|
2532
|
+
} else {
|
|
2533
|
+
logLSPMessage("send-response", message);
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
function traceReceivedRequest(message) {
|
|
2537
|
+
if (trace === Trace.Off || !tracer) {
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2541
|
+
let data = void 0;
|
|
2542
|
+
if ((trace === Trace.Verbose || trace === Trace.Compact) && message.params) {
|
|
2543
|
+
data = `Params: ${stringifyTrace(message.params)}`;
|
|
2544
|
+
}
|
|
2545
|
+
tracer.log(`Received request '${message.method} - (${message.id})'.`, data);
|
|
2546
|
+
} else {
|
|
2547
|
+
logLSPMessage("receive-request", message);
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
function traceReceivedNotification(message) {
|
|
2551
|
+
if (trace === Trace.Off || !tracer || message.method === LogTraceNotification.type.method) {
|
|
2552
|
+
return;
|
|
2553
|
+
}
|
|
2554
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2555
|
+
let data = void 0;
|
|
2556
|
+
if (trace === Trace.Verbose || trace === Trace.Compact) {
|
|
2557
|
+
if (message.params) {
|
|
2558
|
+
data = `Params: ${stringifyTrace(message.params)}`;
|
|
2559
|
+
} else {
|
|
2560
|
+
data = "No parameters provided.";
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
tracer.log(`Received notification '${message.method}'.`, data);
|
|
2564
|
+
} else {
|
|
2565
|
+
logLSPMessage("receive-notification", message);
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
function traceReceivedResponse(message, responsePromise) {
|
|
2569
|
+
if (trace === Trace.Off || !tracer) {
|
|
2570
|
+
return;
|
|
2571
|
+
}
|
|
2572
|
+
if (traceFormat === TraceFormat.Text) {
|
|
2573
|
+
let data = void 0;
|
|
2574
|
+
if (trace === Trace.Verbose || trace === Trace.Compact) {
|
|
2575
|
+
if (message.error && message.error.data) {
|
|
2576
|
+
data = `Error data: ${stringifyTrace(message.error.data)}`;
|
|
2577
|
+
} else {
|
|
2578
|
+
if (message.result) {
|
|
2579
|
+
data = `Result: ${stringifyTrace(message.result)}`;
|
|
2580
|
+
} else if (message.error === void 0) {
|
|
2581
|
+
data = "No result returned.";
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
if (responsePromise) {
|
|
2586
|
+
const error = message.error ? ` Request failed: ${message.error.message} (${message.error.code}).` : "";
|
|
2587
|
+
tracer.log(`Received response '${responsePromise.method} - (${message.id})' in ${Date.now() - responsePromise.timerStart}ms.${error}`, data);
|
|
2588
|
+
} else {
|
|
2589
|
+
tracer.log(`Received response ${message.id} without active response promise.`, data);
|
|
2590
|
+
}
|
|
2591
|
+
} else {
|
|
2592
|
+
logLSPMessage("receive-response", message);
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
function logLSPMessage(type, message) {
|
|
2596
|
+
if (!tracer || trace === Trace.Off) {
|
|
2597
|
+
return;
|
|
2598
|
+
}
|
|
2599
|
+
const lspMessage = {
|
|
2600
|
+
isLSPMessage: true,
|
|
2601
|
+
type,
|
|
2602
|
+
message,
|
|
2603
|
+
timestamp: Date.now()
|
|
2604
|
+
};
|
|
2605
|
+
tracer.log(lspMessage);
|
|
2606
|
+
}
|
|
2607
|
+
function throwIfClosedOrDisposed() {
|
|
2608
|
+
if (isClosed()) {
|
|
2609
|
+
throw new ConnectionError(ConnectionErrors.Closed, "Connection is closed.");
|
|
2610
|
+
}
|
|
2611
|
+
if (isDisposed()) {
|
|
2612
|
+
throw new ConnectionError(ConnectionErrors.Disposed, "Connection is disposed.");
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
function throwIfListening() {
|
|
2616
|
+
if (isListening()) {
|
|
2617
|
+
throw new ConnectionError(ConnectionErrors.AlreadyListening, "Connection is already listening");
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
function throwIfNotListening() {
|
|
2621
|
+
if (!isListening()) {
|
|
2622
|
+
throw new Error("Call listen() first.");
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
function undefinedToNull(param) {
|
|
2626
|
+
if (param === void 0) {
|
|
2627
|
+
return null;
|
|
2628
|
+
} else {
|
|
2629
|
+
return param;
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
function nullToUndefined(param) {
|
|
2633
|
+
if (param === null) {
|
|
2634
|
+
return void 0;
|
|
2635
|
+
} else {
|
|
2636
|
+
return param;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
function isNamedParam(param) {
|
|
2640
|
+
return param !== void 0 && param !== null && !Array.isArray(param) && typeof param === "object";
|
|
2641
|
+
}
|
|
2642
|
+
function computeSingleParam(parameterStructures, param) {
|
|
2643
|
+
switch (parameterStructures) {
|
|
2644
|
+
case messages_1.ParameterStructures.auto:
|
|
2645
|
+
if (isNamedParam(param)) {
|
|
2646
|
+
return nullToUndefined(param);
|
|
2647
|
+
} else {
|
|
2648
|
+
return [undefinedToNull(param)];
|
|
2649
|
+
}
|
|
2650
|
+
case messages_1.ParameterStructures.byName:
|
|
2651
|
+
if (!isNamedParam(param)) {
|
|
2652
|
+
throw new Error(`Received parameters by name but param is not an object literal.`);
|
|
2653
|
+
}
|
|
2654
|
+
return nullToUndefined(param);
|
|
2655
|
+
case messages_1.ParameterStructures.byPosition:
|
|
2656
|
+
return [undefinedToNull(param)];
|
|
2657
|
+
default:
|
|
2658
|
+
throw new Error(`Unknown parameter structure ${parameterStructures.toString()}`);
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
function computeMessageParams(type, params) {
|
|
2662
|
+
let result;
|
|
2663
|
+
const numberOfParams = type.numberOfParams;
|
|
2664
|
+
switch (numberOfParams) {
|
|
2665
|
+
case 0:
|
|
2666
|
+
result = void 0;
|
|
2667
|
+
break;
|
|
2668
|
+
case 1:
|
|
2669
|
+
result = computeSingleParam(type.parameterStructures, params[0]);
|
|
2670
|
+
break;
|
|
2671
|
+
default:
|
|
2672
|
+
result = [];
|
|
2673
|
+
for (let i = 0; i < params.length && i < numberOfParams; i++) {
|
|
2674
|
+
result.push(undefinedToNull(params[i]));
|
|
2675
|
+
}
|
|
2676
|
+
if (params.length < numberOfParams) {
|
|
2677
|
+
for (let i = params.length; i < numberOfParams; i++) {
|
|
2678
|
+
result.push(null);
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
break;
|
|
2682
|
+
}
|
|
2683
|
+
return result;
|
|
2684
|
+
}
|
|
2685
|
+
const connection2 = {
|
|
2686
|
+
sendNotification: (type, ...args) => {
|
|
2687
|
+
throwIfClosedOrDisposed();
|
|
2688
|
+
let method;
|
|
2689
|
+
let messageParams;
|
|
2690
|
+
if (Is.string(type)) {
|
|
2691
|
+
method = type;
|
|
2692
|
+
const first = args[0];
|
|
2693
|
+
let paramStart = 0;
|
|
2694
|
+
let parameterStructures = messages_1.ParameterStructures.auto;
|
|
2695
|
+
if (messages_1.ParameterStructures.is(first)) {
|
|
2696
|
+
paramStart = 1;
|
|
2697
|
+
parameterStructures = first;
|
|
2698
|
+
}
|
|
2699
|
+
const paramEnd = args.length;
|
|
2700
|
+
const numberOfParams = paramEnd - paramStart;
|
|
2701
|
+
switch (numberOfParams) {
|
|
2702
|
+
case 0:
|
|
2703
|
+
messageParams = void 0;
|
|
2704
|
+
break;
|
|
2705
|
+
case 1:
|
|
2706
|
+
messageParams = computeSingleParam(parameterStructures, args[paramStart]);
|
|
2707
|
+
break;
|
|
2708
|
+
default:
|
|
2709
|
+
if (parameterStructures === messages_1.ParameterStructures.byName) {
|
|
2710
|
+
throw new Error(`Received ${numberOfParams} parameters for 'by Name' notification parameter structure.`);
|
|
2711
|
+
}
|
|
2712
|
+
messageParams = args.slice(paramStart, paramEnd).map((value) => undefinedToNull(value));
|
|
2713
|
+
break;
|
|
2714
|
+
}
|
|
2715
|
+
} else {
|
|
2716
|
+
const params = args;
|
|
2717
|
+
method = type.method;
|
|
2718
|
+
messageParams = computeMessageParams(type, params);
|
|
2719
|
+
}
|
|
2720
|
+
const notificationMessage = {
|
|
2721
|
+
jsonrpc: version,
|
|
2722
|
+
method,
|
|
2723
|
+
params: messageParams
|
|
2724
|
+
};
|
|
2725
|
+
traceSendingNotification(notificationMessage);
|
|
2726
|
+
return messageWriter2.write(notificationMessage).catch((error) => {
|
|
2727
|
+
logger.error(`Sending notification failed.`);
|
|
2728
|
+
throw error;
|
|
2729
|
+
});
|
|
2730
|
+
},
|
|
2731
|
+
onNotification: (type, handler) => {
|
|
2732
|
+
throwIfClosedOrDisposed();
|
|
2733
|
+
let method;
|
|
2734
|
+
if (Is.func(type)) {
|
|
2735
|
+
starNotificationHandler = type;
|
|
2736
|
+
} else if (handler) {
|
|
2737
|
+
if (Is.string(type)) {
|
|
2738
|
+
method = type;
|
|
2739
|
+
notificationHandlers.set(type, { type: void 0, handler });
|
|
2740
|
+
} else {
|
|
2741
|
+
method = type.method;
|
|
2742
|
+
notificationHandlers.set(type.method, { type, handler });
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
return {
|
|
2746
|
+
dispose: () => {
|
|
2747
|
+
if (method !== void 0) {
|
|
2748
|
+
if (notificationHandlers.get(method)?.handler === handler) {
|
|
2749
|
+
notificationHandlers.delete(method);
|
|
2750
|
+
}
|
|
2751
|
+
} else if (starNotificationHandler === type) {
|
|
2752
|
+
starNotificationHandler = void 0;
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
};
|
|
2756
|
+
},
|
|
2757
|
+
onProgress: (_type, token, handler) => {
|
|
2758
|
+
if (progressHandlers.has(token)) {
|
|
2759
|
+
throw new Error(`Progress handler for token ${token} already registered`);
|
|
2760
|
+
}
|
|
2761
|
+
progressHandlers.set(token, handler);
|
|
2762
|
+
return {
|
|
2763
|
+
dispose: () => {
|
|
2764
|
+
if (progressHandlers.get(token) === handler) {
|
|
2765
|
+
progressHandlers.delete(token);
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
};
|
|
2769
|
+
},
|
|
2770
|
+
sendProgress: (_type, token, value) => {
|
|
2771
|
+
return connection2.sendNotification(ProgressNotification.type, { token, value });
|
|
2772
|
+
},
|
|
2773
|
+
onUnhandledProgress: unhandledProgressEmitter.event,
|
|
2774
|
+
sendRequest: (type, ...args) => {
|
|
2775
|
+
throwIfClosedOrDisposed();
|
|
2776
|
+
throwIfNotListening();
|
|
2777
|
+
function sendCancellation(connection3, id2) {
|
|
2778
|
+
const p = cancellationStrategy.sender.sendCancellation(connection3, id2);
|
|
2779
|
+
if (p === void 0) {
|
|
2780
|
+
logger.log(`Received no promise from cancellation strategy when cancelling id ${id2}`);
|
|
2781
|
+
} else {
|
|
2782
|
+
p.catch(() => {
|
|
2783
|
+
logger.log(`Sending cancellation messages for id ${id2} failed.`);
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
let method;
|
|
2788
|
+
let messageParams;
|
|
2789
|
+
let token = void 0;
|
|
2790
|
+
if (Is.string(type)) {
|
|
2791
|
+
method = type;
|
|
2792
|
+
const first = args[0];
|
|
2793
|
+
const last = args[args.length - 1];
|
|
2794
|
+
let paramStart = 0;
|
|
2795
|
+
let parameterStructures = messages_1.ParameterStructures.auto;
|
|
2796
|
+
if (messages_1.ParameterStructures.is(first)) {
|
|
2797
|
+
paramStart = 1;
|
|
2798
|
+
parameterStructures = first;
|
|
2799
|
+
}
|
|
2800
|
+
let paramEnd = args.length;
|
|
2801
|
+
if (cancellation_1.CancellationToken.is(last)) {
|
|
2802
|
+
paramEnd = paramEnd - 1;
|
|
2803
|
+
token = last;
|
|
2804
|
+
}
|
|
2805
|
+
const numberOfParams = paramEnd - paramStart;
|
|
2806
|
+
switch (numberOfParams) {
|
|
2807
|
+
case 0:
|
|
2808
|
+
messageParams = void 0;
|
|
2809
|
+
break;
|
|
2810
|
+
case 1:
|
|
2811
|
+
messageParams = computeSingleParam(parameterStructures, args[paramStart]);
|
|
2812
|
+
break;
|
|
2813
|
+
default:
|
|
2814
|
+
if (parameterStructures === messages_1.ParameterStructures.byName) {
|
|
2815
|
+
throw new Error(`Received ${numberOfParams} parameters for 'by Name' request parameter structure.`);
|
|
2816
|
+
}
|
|
2817
|
+
messageParams = args.slice(paramStart, paramEnd).map((value) => undefinedToNull(value));
|
|
2818
|
+
break;
|
|
2819
|
+
}
|
|
2820
|
+
} else {
|
|
2821
|
+
const params = args;
|
|
2822
|
+
method = type.method;
|
|
2823
|
+
messageParams = computeMessageParams(type, params);
|
|
2824
|
+
const numberOfParams = type.numberOfParams;
|
|
2825
|
+
token = cancellation_1.CancellationToken.is(params[numberOfParams]) ? params[numberOfParams] : void 0;
|
|
2826
|
+
}
|
|
2827
|
+
const id = sequenceNumber++;
|
|
2828
|
+
let disposable2;
|
|
2829
|
+
let tokenWasCancelled = false;
|
|
2830
|
+
if (token !== void 0) {
|
|
2831
|
+
if (token.isCancellationRequested) {
|
|
2832
|
+
tokenWasCancelled = true;
|
|
2833
|
+
} else {
|
|
2834
|
+
disposable2 = token.onCancellationRequested(() => {
|
|
2835
|
+
sendCancellation(connection2, id);
|
|
2836
|
+
});
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
const requestMessage = {
|
|
2840
|
+
jsonrpc: version,
|
|
2841
|
+
id,
|
|
2842
|
+
method,
|
|
2843
|
+
params: messageParams
|
|
2844
|
+
};
|
|
2845
|
+
traceSendingRequest(requestMessage);
|
|
2846
|
+
if (typeof cancellationStrategy.sender.enableCancellation === "function") {
|
|
2847
|
+
cancellationStrategy.sender.enableCancellation(requestMessage);
|
|
2848
|
+
}
|
|
2849
|
+
return new Promise(async (resolve, reject) => {
|
|
2850
|
+
const resolveWithCleanup = (r) => {
|
|
2851
|
+
resolve(r);
|
|
2852
|
+
cancellationStrategy.sender.cleanup(id);
|
|
2853
|
+
disposable2?.dispose();
|
|
2854
|
+
};
|
|
2855
|
+
const rejectWithCleanup = (r) => {
|
|
2856
|
+
reject(r);
|
|
2857
|
+
cancellationStrategy.sender.cleanup(id);
|
|
2858
|
+
disposable2?.dispose();
|
|
2859
|
+
};
|
|
2860
|
+
const responsePromise = { method, timerStart: Date.now(), resolve: resolveWithCleanup, reject: rejectWithCleanup };
|
|
2861
|
+
try {
|
|
2862
|
+
responsePromises.set(id, responsePromise);
|
|
2863
|
+
await messageWriter2.write(requestMessage);
|
|
2864
|
+
if (tokenWasCancelled) {
|
|
2865
|
+
sendCancellation(connection2, id);
|
|
2866
|
+
}
|
|
2867
|
+
} catch (error) {
|
|
2868
|
+
responsePromises.delete(id);
|
|
2869
|
+
responsePromise.reject(new messages_1.ResponseError(messages_1.ErrorCodes.MessageWriteError, error.message ? error.message : "Unknown reason"));
|
|
2870
|
+
logger.error(`Sending request failed.`);
|
|
2871
|
+
throw error;
|
|
2872
|
+
}
|
|
2873
|
+
});
|
|
2874
|
+
},
|
|
2875
|
+
onRequest: (type, handler) => {
|
|
2876
|
+
throwIfClosedOrDisposed();
|
|
2877
|
+
let method = null;
|
|
2878
|
+
if (StarRequestHandler.is(type)) {
|
|
2879
|
+
method = void 0;
|
|
2880
|
+
starRequestHandler = type;
|
|
2881
|
+
} else if (Is.string(type)) {
|
|
2882
|
+
method = null;
|
|
2883
|
+
if (handler !== void 0) {
|
|
2884
|
+
method = type;
|
|
2885
|
+
requestHandlers.set(type, { handler, type: void 0 });
|
|
2886
|
+
}
|
|
2887
|
+
} else {
|
|
2888
|
+
if (handler !== void 0) {
|
|
2889
|
+
method = type.method;
|
|
2890
|
+
requestHandlers.set(type.method, { type, handler });
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
return {
|
|
2894
|
+
dispose: () => {
|
|
2895
|
+
if (method === null) {
|
|
2896
|
+
return;
|
|
2897
|
+
}
|
|
2898
|
+
if (method !== void 0) {
|
|
2899
|
+
if (requestHandlers.get(method)?.handler === handler) {
|
|
2900
|
+
requestHandlers.delete(method);
|
|
2901
|
+
}
|
|
2902
|
+
} else if (starRequestHandler === type) {
|
|
2903
|
+
starRequestHandler = void 0;
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
};
|
|
2907
|
+
},
|
|
2908
|
+
hasPendingResponse: () => {
|
|
2909
|
+
return responsePromises.size > 0;
|
|
2910
|
+
},
|
|
2911
|
+
trace: async (_value, _tracer, sendNotificationOrTraceOptions) => {
|
|
2912
|
+
let _sendNotification = false;
|
|
2913
|
+
let _traceFormat = TraceFormat.Text;
|
|
2914
|
+
if (sendNotificationOrTraceOptions !== void 0) {
|
|
2915
|
+
if (Is.boolean(sendNotificationOrTraceOptions)) {
|
|
2916
|
+
_sendNotification = sendNotificationOrTraceOptions;
|
|
2917
|
+
} else {
|
|
2918
|
+
_sendNotification = sendNotificationOrTraceOptions.sendNotification || false;
|
|
2919
|
+
_traceFormat = sendNotificationOrTraceOptions.traceFormat || TraceFormat.Text;
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
trace = _value;
|
|
2923
|
+
traceFormat = _traceFormat;
|
|
2924
|
+
if (trace === Trace.Off) {
|
|
2925
|
+
tracer = void 0;
|
|
2926
|
+
} else {
|
|
2927
|
+
tracer = _tracer;
|
|
2928
|
+
}
|
|
2929
|
+
if (_sendNotification && !isClosed() && !isDisposed()) {
|
|
2930
|
+
await connection2.sendNotification(SetTraceNotification.type, { value: Trace.toString(_value) });
|
|
2931
|
+
}
|
|
2932
|
+
},
|
|
2933
|
+
onError: errorEmitter.event,
|
|
2934
|
+
onClose: closeEmitter.event,
|
|
2935
|
+
onUnhandledNotification: unhandledNotificationEmitter.event,
|
|
2936
|
+
onDispose: disposeEmitter.event,
|
|
2937
|
+
end: () => {
|
|
2938
|
+
messageWriter2.end();
|
|
2939
|
+
},
|
|
2940
|
+
dispose: () => {
|
|
2941
|
+
if (isDisposed()) {
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2944
|
+
state2 = ConnectionState.Disposed;
|
|
2945
|
+
disposeEmitter.fire(void 0);
|
|
2946
|
+
const error = new messages_1.ResponseError(messages_1.ErrorCodes.PendingResponseRejected, "Pending response rejected since connection got disposed");
|
|
2947
|
+
for (const promise of responsePromises.values()) {
|
|
2948
|
+
promise.reject(error);
|
|
2949
|
+
}
|
|
2950
|
+
responsePromises = /* @__PURE__ */ new Map();
|
|
2951
|
+
requestTokens = /* @__PURE__ */ new Map();
|
|
2952
|
+
knownCanceledRequests = /* @__PURE__ */ new Set();
|
|
2953
|
+
messageQueue = new linkedMap_1.LinkedMap();
|
|
2954
|
+
if (Is.func(messageWriter2.dispose)) {
|
|
2955
|
+
messageWriter2.dispose();
|
|
2956
|
+
}
|
|
2957
|
+
if (Is.func(messageReader2.dispose)) {
|
|
2958
|
+
messageReader2.dispose();
|
|
2959
|
+
}
|
|
2960
|
+
},
|
|
2961
|
+
listen: () => {
|
|
2962
|
+
throwIfClosedOrDisposed();
|
|
2963
|
+
throwIfListening();
|
|
2964
|
+
state2 = ConnectionState.Listening;
|
|
2965
|
+
messageReader2.listen(callback);
|
|
2966
|
+
},
|
|
2967
|
+
inspect: () => {
|
|
2968
|
+
(0, ral_1.default)().console.log("inspect");
|
|
2969
|
+
}
|
|
2970
|
+
};
|
|
2971
|
+
connection2.onNotification(LogTraceNotification.type, (params) => {
|
|
2972
|
+
if (trace === Trace.Off || !tracer) {
|
|
2973
|
+
return;
|
|
2974
|
+
}
|
|
2975
|
+
const verbose = trace === Trace.Verbose || trace === Trace.Compact;
|
|
2976
|
+
tracer.log(params.message, verbose ? params.verbose : void 0);
|
|
2977
|
+
});
|
|
2978
|
+
connection2.onNotification(ProgressNotification.type, async (params) => {
|
|
2979
|
+
const handler = progressHandlers.get(params.token);
|
|
2980
|
+
if (handler) {
|
|
2981
|
+
await handler(params.value);
|
|
2982
|
+
} else {
|
|
2983
|
+
unhandledProgressEmitter.fire(params);
|
|
2984
|
+
}
|
|
2985
|
+
});
|
|
2986
|
+
return connection2;
|
|
2987
|
+
}
|
|
2988
|
+
})(connection);
|
|
2989
|
+
return connection;
|
|
2990
|
+
}
|
|
2991
|
+
var hasRequiredApi;
|
|
2992
|
+
function requireApi() {
|
|
2993
|
+
if (hasRequiredApi) return api;
|
|
2994
|
+
hasRequiredApi = 1;
|
|
2995
|
+
(function(exports2) {
|
|
2996
|
+
var __importDefault = api && api.__importDefault || function(mod) {
|
|
2997
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
2998
|
+
};
|
|
2999
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3000
|
+
exports2.ProgressType = exports2.ProgressToken = exports2.createMessageConnection = exports2.NullLogger = exports2.ConnectionOptions = exports2.ConnectionStrategy = exports2.AbstractMessageBuffer = exports2.WriteableStreamMessageWriter = exports2.AbstractMessageWriter = exports2.MessageWriter = exports2.ReadableStreamMessageReader = exports2.AbstractMessageReader = exports2.MessageReader = exports2.SharedArrayReceiverStrategy = exports2.SharedArraySenderStrategy = exports2.CancellationToken = exports2.CancellationTokenSource = exports2.Emitter = exports2.Event = exports2.Disposable = exports2.LRUCache = exports2.Touch = exports2.LinkedMap = exports2.ParameterStructures = exports2.NotificationType9 = exports2.NotificationType8 = exports2.NotificationType7 = exports2.NotificationType6 = exports2.NotificationType5 = exports2.NotificationType4 = exports2.NotificationType3 = exports2.NotificationType2 = exports2.NotificationType1 = exports2.NotificationType0 = exports2.NotificationType = exports2.ErrorCodes = exports2.ResponseError = exports2.RequestType9 = exports2.RequestType8 = exports2.RequestType7 = exports2.RequestType6 = exports2.RequestType5 = exports2.RequestType4 = exports2.RequestType3 = exports2.RequestType2 = exports2.RequestType1 = exports2.RequestType0 = exports2.RequestType = exports2.Message = exports2.RAL = void 0;
|
|
3001
|
+
exports2.MessageStrategy = exports2.CancellationStrategy = exports2.CancellationSenderStrategy = exports2.RequestCancellationReceiverStrategy = exports2.IdCancellationReceiverStrategy = exports2.CancellationReceiverStrategy = exports2.ConnectionError = exports2.ConnectionErrors = exports2.LogTraceNotification = exports2.SetTraceNotification = exports2.TraceFormat = exports2.TraceValues = exports2.TraceValue = exports2.Trace = void 0;
|
|
3002
|
+
const messages_1 = requireMessages();
|
|
3003
|
+
Object.defineProperty(exports2, "Message", { enumerable: true, get: function() {
|
|
3004
|
+
return messages_1.Message;
|
|
3005
|
+
} });
|
|
3006
|
+
Object.defineProperty(exports2, "RequestType", { enumerable: true, get: function() {
|
|
3007
|
+
return messages_1.RequestType;
|
|
3008
|
+
} });
|
|
3009
|
+
Object.defineProperty(exports2, "RequestType0", { enumerable: true, get: function() {
|
|
3010
|
+
return messages_1.RequestType0;
|
|
3011
|
+
} });
|
|
3012
|
+
Object.defineProperty(exports2, "RequestType1", { enumerable: true, get: function() {
|
|
3013
|
+
return messages_1.RequestType1;
|
|
3014
|
+
} });
|
|
3015
|
+
Object.defineProperty(exports2, "RequestType2", { enumerable: true, get: function() {
|
|
3016
|
+
return messages_1.RequestType2;
|
|
3017
|
+
} });
|
|
3018
|
+
Object.defineProperty(exports2, "RequestType3", { enumerable: true, get: function() {
|
|
3019
|
+
return messages_1.RequestType3;
|
|
3020
|
+
} });
|
|
3021
|
+
Object.defineProperty(exports2, "RequestType4", { enumerable: true, get: function() {
|
|
3022
|
+
return messages_1.RequestType4;
|
|
3023
|
+
} });
|
|
3024
|
+
Object.defineProperty(exports2, "RequestType5", { enumerable: true, get: function() {
|
|
3025
|
+
return messages_1.RequestType5;
|
|
3026
|
+
} });
|
|
3027
|
+
Object.defineProperty(exports2, "RequestType6", { enumerable: true, get: function() {
|
|
3028
|
+
return messages_1.RequestType6;
|
|
3029
|
+
} });
|
|
3030
|
+
Object.defineProperty(exports2, "RequestType7", { enumerable: true, get: function() {
|
|
3031
|
+
return messages_1.RequestType7;
|
|
3032
|
+
} });
|
|
3033
|
+
Object.defineProperty(exports2, "RequestType8", { enumerable: true, get: function() {
|
|
3034
|
+
return messages_1.RequestType8;
|
|
3035
|
+
} });
|
|
3036
|
+
Object.defineProperty(exports2, "RequestType9", { enumerable: true, get: function() {
|
|
3037
|
+
return messages_1.RequestType9;
|
|
3038
|
+
} });
|
|
3039
|
+
Object.defineProperty(exports2, "ResponseError", { enumerable: true, get: function() {
|
|
3040
|
+
return messages_1.ResponseError;
|
|
3041
|
+
} });
|
|
3042
|
+
Object.defineProperty(exports2, "ErrorCodes", { enumerable: true, get: function() {
|
|
3043
|
+
return messages_1.ErrorCodes;
|
|
3044
|
+
} });
|
|
3045
|
+
Object.defineProperty(exports2, "NotificationType", { enumerable: true, get: function() {
|
|
3046
|
+
return messages_1.NotificationType;
|
|
3047
|
+
} });
|
|
3048
|
+
Object.defineProperty(exports2, "NotificationType0", { enumerable: true, get: function() {
|
|
3049
|
+
return messages_1.NotificationType0;
|
|
3050
|
+
} });
|
|
3051
|
+
Object.defineProperty(exports2, "NotificationType1", { enumerable: true, get: function() {
|
|
3052
|
+
return messages_1.NotificationType1;
|
|
3053
|
+
} });
|
|
3054
|
+
Object.defineProperty(exports2, "NotificationType2", { enumerable: true, get: function() {
|
|
3055
|
+
return messages_1.NotificationType2;
|
|
3056
|
+
} });
|
|
3057
|
+
Object.defineProperty(exports2, "NotificationType3", { enumerable: true, get: function() {
|
|
3058
|
+
return messages_1.NotificationType3;
|
|
3059
|
+
} });
|
|
3060
|
+
Object.defineProperty(exports2, "NotificationType4", { enumerable: true, get: function() {
|
|
3061
|
+
return messages_1.NotificationType4;
|
|
3062
|
+
} });
|
|
3063
|
+
Object.defineProperty(exports2, "NotificationType5", { enumerable: true, get: function() {
|
|
3064
|
+
return messages_1.NotificationType5;
|
|
3065
|
+
} });
|
|
3066
|
+
Object.defineProperty(exports2, "NotificationType6", { enumerable: true, get: function() {
|
|
3067
|
+
return messages_1.NotificationType6;
|
|
3068
|
+
} });
|
|
3069
|
+
Object.defineProperty(exports2, "NotificationType7", { enumerable: true, get: function() {
|
|
3070
|
+
return messages_1.NotificationType7;
|
|
3071
|
+
} });
|
|
3072
|
+
Object.defineProperty(exports2, "NotificationType8", { enumerable: true, get: function() {
|
|
3073
|
+
return messages_1.NotificationType8;
|
|
3074
|
+
} });
|
|
3075
|
+
Object.defineProperty(exports2, "NotificationType9", { enumerable: true, get: function() {
|
|
3076
|
+
return messages_1.NotificationType9;
|
|
3077
|
+
} });
|
|
3078
|
+
Object.defineProperty(exports2, "ParameterStructures", { enumerable: true, get: function() {
|
|
3079
|
+
return messages_1.ParameterStructures;
|
|
3080
|
+
} });
|
|
3081
|
+
const linkedMap_1 = requireLinkedMap();
|
|
3082
|
+
Object.defineProperty(exports2, "LinkedMap", { enumerable: true, get: function() {
|
|
3083
|
+
return linkedMap_1.LinkedMap;
|
|
3084
|
+
} });
|
|
3085
|
+
Object.defineProperty(exports2, "LRUCache", { enumerable: true, get: function() {
|
|
3086
|
+
return linkedMap_1.LRUCache;
|
|
3087
|
+
} });
|
|
3088
|
+
Object.defineProperty(exports2, "Touch", { enumerable: true, get: function() {
|
|
3089
|
+
return linkedMap_1.Touch;
|
|
3090
|
+
} });
|
|
3091
|
+
const disposable_1 = requireDisposable();
|
|
3092
|
+
Object.defineProperty(exports2, "Disposable", { enumerable: true, get: function() {
|
|
3093
|
+
return disposable_1.Disposable;
|
|
3094
|
+
} });
|
|
3095
|
+
const events_1 = requireEvents();
|
|
3096
|
+
Object.defineProperty(exports2, "Event", { enumerable: true, get: function() {
|
|
3097
|
+
return events_1.Event;
|
|
3098
|
+
} });
|
|
3099
|
+
Object.defineProperty(exports2, "Emitter", { enumerable: true, get: function() {
|
|
3100
|
+
return events_1.Emitter;
|
|
3101
|
+
} });
|
|
3102
|
+
const cancellation_1 = requireCancellation();
|
|
3103
|
+
Object.defineProperty(exports2, "CancellationTokenSource", { enumerable: true, get: function() {
|
|
3104
|
+
return cancellation_1.CancellationTokenSource;
|
|
3105
|
+
} });
|
|
3106
|
+
Object.defineProperty(exports2, "CancellationToken", { enumerable: true, get: function() {
|
|
3107
|
+
return cancellation_1.CancellationToken;
|
|
3108
|
+
} });
|
|
3109
|
+
const sharedArrayCancellation_1 = requireSharedArrayCancellation();
|
|
3110
|
+
Object.defineProperty(exports2, "SharedArraySenderStrategy", { enumerable: true, get: function() {
|
|
3111
|
+
return sharedArrayCancellation_1.SharedArraySenderStrategy;
|
|
3112
|
+
} });
|
|
3113
|
+
Object.defineProperty(exports2, "SharedArrayReceiverStrategy", { enumerable: true, get: function() {
|
|
3114
|
+
return sharedArrayCancellation_1.SharedArrayReceiverStrategy;
|
|
3115
|
+
} });
|
|
3116
|
+
const messageReader_1 = requireMessageReader();
|
|
3117
|
+
Object.defineProperty(exports2, "MessageReader", { enumerable: true, get: function() {
|
|
3118
|
+
return messageReader_1.MessageReader;
|
|
3119
|
+
} });
|
|
3120
|
+
Object.defineProperty(exports2, "AbstractMessageReader", { enumerable: true, get: function() {
|
|
3121
|
+
return messageReader_1.AbstractMessageReader;
|
|
3122
|
+
} });
|
|
3123
|
+
Object.defineProperty(exports2, "ReadableStreamMessageReader", { enumerable: true, get: function() {
|
|
3124
|
+
return messageReader_1.ReadableStreamMessageReader;
|
|
3125
|
+
} });
|
|
3126
|
+
const messageWriter_1 = requireMessageWriter();
|
|
3127
|
+
Object.defineProperty(exports2, "MessageWriter", { enumerable: true, get: function() {
|
|
3128
|
+
return messageWriter_1.MessageWriter;
|
|
3129
|
+
} });
|
|
3130
|
+
Object.defineProperty(exports2, "AbstractMessageWriter", { enumerable: true, get: function() {
|
|
3131
|
+
return messageWriter_1.AbstractMessageWriter;
|
|
3132
|
+
} });
|
|
3133
|
+
Object.defineProperty(exports2, "WriteableStreamMessageWriter", { enumerable: true, get: function() {
|
|
3134
|
+
return messageWriter_1.WriteableStreamMessageWriter;
|
|
3135
|
+
} });
|
|
3136
|
+
const messageBuffer_1 = requireMessageBuffer();
|
|
3137
|
+
Object.defineProperty(exports2, "AbstractMessageBuffer", { enumerable: true, get: function() {
|
|
3138
|
+
return messageBuffer_1.AbstractMessageBuffer;
|
|
3139
|
+
} });
|
|
3140
|
+
const connection_1 = requireConnection();
|
|
3141
|
+
Object.defineProperty(exports2, "ConnectionStrategy", { enumerable: true, get: function() {
|
|
3142
|
+
return connection_1.ConnectionStrategy;
|
|
3143
|
+
} });
|
|
3144
|
+
Object.defineProperty(exports2, "ConnectionOptions", { enumerable: true, get: function() {
|
|
3145
|
+
return connection_1.ConnectionOptions;
|
|
3146
|
+
} });
|
|
3147
|
+
Object.defineProperty(exports2, "NullLogger", { enumerable: true, get: function() {
|
|
3148
|
+
return connection_1.NullLogger;
|
|
3149
|
+
} });
|
|
3150
|
+
Object.defineProperty(exports2, "createMessageConnection", { enumerable: true, get: function() {
|
|
3151
|
+
return connection_1.createMessageConnection;
|
|
3152
|
+
} });
|
|
3153
|
+
Object.defineProperty(exports2, "ProgressToken", { enumerable: true, get: function() {
|
|
3154
|
+
return connection_1.ProgressToken;
|
|
3155
|
+
} });
|
|
3156
|
+
Object.defineProperty(exports2, "ProgressType", { enumerable: true, get: function() {
|
|
3157
|
+
return connection_1.ProgressType;
|
|
3158
|
+
} });
|
|
3159
|
+
Object.defineProperty(exports2, "Trace", { enumerable: true, get: function() {
|
|
3160
|
+
return connection_1.Trace;
|
|
3161
|
+
} });
|
|
3162
|
+
Object.defineProperty(exports2, "TraceValue", { enumerable: true, get: function() {
|
|
3163
|
+
return connection_1.TraceValue;
|
|
3164
|
+
} });
|
|
3165
|
+
Object.defineProperty(exports2, "TraceFormat", { enumerable: true, get: function() {
|
|
3166
|
+
return connection_1.TraceFormat;
|
|
3167
|
+
} });
|
|
3168
|
+
Object.defineProperty(exports2, "SetTraceNotification", { enumerable: true, get: function() {
|
|
3169
|
+
return connection_1.SetTraceNotification;
|
|
3170
|
+
} });
|
|
3171
|
+
Object.defineProperty(exports2, "LogTraceNotification", { enumerable: true, get: function() {
|
|
3172
|
+
return connection_1.LogTraceNotification;
|
|
3173
|
+
} });
|
|
3174
|
+
Object.defineProperty(exports2, "ConnectionErrors", { enumerable: true, get: function() {
|
|
3175
|
+
return connection_1.ConnectionErrors;
|
|
3176
|
+
} });
|
|
3177
|
+
Object.defineProperty(exports2, "ConnectionError", { enumerable: true, get: function() {
|
|
3178
|
+
return connection_1.ConnectionError;
|
|
3179
|
+
} });
|
|
3180
|
+
Object.defineProperty(exports2, "CancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3181
|
+
return connection_1.CancellationReceiverStrategy;
|
|
3182
|
+
} });
|
|
3183
|
+
Object.defineProperty(exports2, "IdCancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3184
|
+
return connection_1.IdCancellationReceiverStrategy;
|
|
3185
|
+
} });
|
|
3186
|
+
Object.defineProperty(exports2, "RequestCancellationReceiverStrategy", { enumerable: true, get: function() {
|
|
3187
|
+
return connection_1.RequestCancellationReceiverStrategy;
|
|
3188
|
+
} });
|
|
3189
|
+
Object.defineProperty(exports2, "CancellationSenderStrategy", { enumerable: true, get: function() {
|
|
3190
|
+
return connection_1.CancellationSenderStrategy;
|
|
3191
|
+
} });
|
|
3192
|
+
Object.defineProperty(exports2, "CancellationStrategy", { enumerable: true, get: function() {
|
|
3193
|
+
return connection_1.CancellationStrategy;
|
|
3194
|
+
} });
|
|
3195
|
+
Object.defineProperty(exports2, "MessageStrategy", { enumerable: true, get: function() {
|
|
3196
|
+
return connection_1.MessageStrategy;
|
|
3197
|
+
} });
|
|
3198
|
+
Object.defineProperty(exports2, "TraceValues", { enumerable: true, get: function() {
|
|
3199
|
+
return connection_1.TraceValues;
|
|
3200
|
+
} });
|
|
3201
|
+
const ral_1 = __importDefault(requireRal());
|
|
3202
|
+
exports2.RAL = ral_1.default;
|
|
3203
|
+
})(api);
|
|
3204
|
+
return api;
|
|
3205
|
+
}
|
|
3206
|
+
var hasRequiredRil;
|
|
3207
|
+
function requireRil() {
|
|
3208
|
+
if (hasRequiredRil) return ril;
|
|
3209
|
+
hasRequiredRil = 1;
|
|
3210
|
+
Object.defineProperty(ril, "__esModule", { value: true });
|
|
3211
|
+
ril.PromiseImpl = ril.QueueMicrotaskImpl = void 0;
|
|
3212
|
+
const api_1 = requireApi();
|
|
3213
|
+
class MessageBuffer extends api_1.AbstractMessageBuffer {
|
|
3214
|
+
static emptyBuffer = new Uint8Array(0);
|
|
3215
|
+
asciiDecoder;
|
|
3216
|
+
constructor(encoding = "utf-8") {
|
|
3217
|
+
super(encoding);
|
|
3218
|
+
this.asciiDecoder = new TextDecoder("ascii");
|
|
3219
|
+
}
|
|
3220
|
+
emptyBuffer() {
|
|
3221
|
+
return MessageBuffer.emptyBuffer;
|
|
3222
|
+
}
|
|
3223
|
+
fromString(value, _encoding) {
|
|
3224
|
+
return new TextEncoder().encode(value);
|
|
3225
|
+
}
|
|
3226
|
+
toString(value, encoding) {
|
|
3227
|
+
if (encoding === "ascii") {
|
|
3228
|
+
return this.asciiDecoder.decode(value);
|
|
3229
|
+
} else {
|
|
3230
|
+
return new TextDecoder(encoding).decode(value);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
asNative(buffer, length) {
|
|
3234
|
+
if (length === void 0) {
|
|
3235
|
+
return buffer;
|
|
3236
|
+
} else {
|
|
3237
|
+
return buffer.slice(0, length);
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
allocNative(length) {
|
|
3241
|
+
return new Uint8Array(length);
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
class ReadableStreamWrapper {
|
|
3245
|
+
socket;
|
|
3246
|
+
_onData;
|
|
3247
|
+
_messageListener;
|
|
3248
|
+
constructor(socket) {
|
|
3249
|
+
this.socket = socket;
|
|
3250
|
+
this._onData = new api_1.Emitter();
|
|
3251
|
+
this._messageListener = (event) => {
|
|
3252
|
+
const blob = event.data;
|
|
3253
|
+
blob.arrayBuffer().then((buffer) => {
|
|
3254
|
+
this._onData.fire(new Uint8Array(buffer));
|
|
3255
|
+
}, () => {
|
|
3256
|
+
(0, api_1.RAL)().console.error(`Converting blob to array buffer failed.`);
|
|
3257
|
+
});
|
|
3258
|
+
};
|
|
3259
|
+
this.socket.addEventListener("message", this._messageListener);
|
|
3260
|
+
}
|
|
3261
|
+
onClose(listener) {
|
|
3262
|
+
this.socket.addEventListener("close", listener);
|
|
3263
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("close", listener));
|
|
3264
|
+
}
|
|
3265
|
+
onError(listener) {
|
|
3266
|
+
this.socket.addEventListener("error", listener);
|
|
3267
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("error", listener));
|
|
3268
|
+
}
|
|
3269
|
+
onEnd(listener) {
|
|
3270
|
+
this.socket.addEventListener("end", listener);
|
|
3271
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("end", listener));
|
|
3272
|
+
}
|
|
3273
|
+
onData(listener) {
|
|
3274
|
+
return this._onData.event(listener);
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
class WritableStreamWrapper {
|
|
3278
|
+
socket;
|
|
3279
|
+
constructor(socket) {
|
|
3280
|
+
this.socket = socket;
|
|
3281
|
+
}
|
|
3282
|
+
onClose(listener) {
|
|
3283
|
+
this.socket.addEventListener("close", listener);
|
|
3284
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("close", listener));
|
|
3285
|
+
}
|
|
3286
|
+
onError(listener) {
|
|
3287
|
+
this.socket.addEventListener("error", listener);
|
|
3288
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("error", listener));
|
|
3289
|
+
}
|
|
3290
|
+
onEnd(listener) {
|
|
3291
|
+
this.socket.addEventListener("end", listener);
|
|
3292
|
+
return api_1.Disposable.create(() => this.socket.removeEventListener("end", listener));
|
|
3293
|
+
}
|
|
3294
|
+
write(data, encoding) {
|
|
3295
|
+
if (typeof data === "string") {
|
|
3296
|
+
if (encoding !== void 0 && encoding !== "utf-8") {
|
|
3297
|
+
throw new Error(`In a Browser environments only utf-8 text encoding is supported. But got encoding: ${encoding}`);
|
|
3298
|
+
}
|
|
3299
|
+
this.socket.send(data);
|
|
3300
|
+
} else {
|
|
3301
|
+
if (data.buffer instanceof ArrayBuffer) {
|
|
3302
|
+
this.socket.send(data.buffer);
|
|
3303
|
+
} else {
|
|
3304
|
+
this.socket.send(new Uint8Array(data.buffer).slice().buffer);
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
return Promise.resolve();
|
|
3308
|
+
}
|
|
3309
|
+
end() {
|
|
3310
|
+
this.socket.close();
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
class QueueMicrotaskImpl {
|
|
3314
|
+
isDisposed;
|
|
3315
|
+
constructor(callback, ...args) {
|
|
3316
|
+
this.isDisposed = false;
|
|
3317
|
+
queueMicrotask(() => {
|
|
3318
|
+
if (!this.isDisposed) {
|
|
3319
|
+
callback(...args);
|
|
3320
|
+
}
|
|
3321
|
+
});
|
|
3322
|
+
}
|
|
3323
|
+
dispose() {
|
|
3324
|
+
this.isDisposed = true;
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
ril.QueueMicrotaskImpl = QueueMicrotaskImpl;
|
|
3328
|
+
class PromiseImpl {
|
|
3329
|
+
isDisposed;
|
|
3330
|
+
constructor(callback, ...args) {
|
|
3331
|
+
this.isDisposed = false;
|
|
3332
|
+
Promise.resolve().then(() => {
|
|
3333
|
+
if (!this.isDisposed) {
|
|
3334
|
+
callback(...args);
|
|
3335
|
+
}
|
|
3336
|
+
}, () => {
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
dispose() {
|
|
3340
|
+
this.isDisposed = true;
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
ril.PromiseImpl = PromiseImpl;
|
|
3344
|
+
const _textEncoder = new TextEncoder();
|
|
3345
|
+
const _ril = Object.freeze({
|
|
3346
|
+
messageBuffer: Object.freeze({
|
|
3347
|
+
create: (encoding) => new MessageBuffer(encoding)
|
|
3348
|
+
}),
|
|
3349
|
+
applicationJson: Object.freeze({
|
|
3350
|
+
encoder: Object.freeze({
|
|
3351
|
+
name: "application/json",
|
|
3352
|
+
encode: (msg, options) => {
|
|
3353
|
+
if (options.charset !== "utf-8") {
|
|
3354
|
+
throw new Error(`In a Browser environments only utf-8 text encoding is supported. But got encoding: ${options.charset}`);
|
|
3355
|
+
}
|
|
3356
|
+
return Promise.resolve(_textEncoder.encode(JSON.stringify(msg, void 0, 0)));
|
|
3357
|
+
}
|
|
3358
|
+
}),
|
|
3359
|
+
decoder: Object.freeze({
|
|
3360
|
+
name: "application/json",
|
|
3361
|
+
decode: (buffer, options) => {
|
|
3362
|
+
if (!(buffer instanceof Uint8Array)) {
|
|
3363
|
+
throw new Error(`In a Browser environments only Uint8Arrays are supported.`);
|
|
3364
|
+
}
|
|
3365
|
+
return Promise.resolve(JSON.parse(new TextDecoder(options.charset).decode(buffer)));
|
|
3366
|
+
}
|
|
3367
|
+
})
|
|
3368
|
+
}),
|
|
3369
|
+
stream: Object.freeze({
|
|
3370
|
+
asReadableStream: (socket) => new ReadableStreamWrapper(socket),
|
|
3371
|
+
asWritableStream: (socket) => new WritableStreamWrapper(socket)
|
|
3372
|
+
}),
|
|
3373
|
+
console,
|
|
3374
|
+
timer: Object.freeze({
|
|
3375
|
+
setTimeout(callback, ms, ...args) {
|
|
3376
|
+
const handle = setTimeout(callback, ms, ...args);
|
|
3377
|
+
return { dispose: () => clearTimeout(handle) };
|
|
3378
|
+
},
|
|
3379
|
+
setImmediate(callback, ...args) {
|
|
3380
|
+
if (typeof globalThis.queueMicrotask === "function") {
|
|
3381
|
+
return new QueueMicrotaskImpl(callback, ...args);
|
|
3382
|
+
} else if (Promise !== void 0) {
|
|
3383
|
+
return new PromiseImpl(callback, ...args);
|
|
3384
|
+
} else {
|
|
3385
|
+
const handle = setTimeout(callback, 0, ...args);
|
|
3386
|
+
return { dispose: () => clearTimeout(handle) };
|
|
3387
|
+
}
|
|
3388
|
+
},
|
|
3389
|
+
setInterval(callback, ms, ...args) {
|
|
3390
|
+
const handle = setInterval(callback, ms, ...args);
|
|
3391
|
+
return { dispose: () => clearInterval(handle) };
|
|
3392
|
+
}
|
|
3393
|
+
})
|
|
3394
|
+
});
|
|
3395
|
+
function RIL() {
|
|
3396
|
+
return _ril;
|
|
3397
|
+
}
|
|
3398
|
+
(function(RIL2) {
|
|
3399
|
+
function install() {
|
|
3400
|
+
api_1.RAL.install(_ril);
|
|
3401
|
+
}
|
|
3402
|
+
RIL2.install = install;
|
|
3403
|
+
})(RIL || (RIL = {}));
|
|
3404
|
+
ril.default = RIL;
|
|
3405
|
+
return ril;
|
|
3406
|
+
}
|
|
3407
|
+
var hasRequiredMain;
|
|
3408
|
+
function requireMain() {
|
|
3409
|
+
if (hasRequiredMain) return main;
|
|
3410
|
+
hasRequiredMain = 1;
|
|
3411
|
+
(function(exports2) {
|
|
3412
|
+
var __createBinding = main && main.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
3413
|
+
if (k2 === void 0) k2 = k;
|
|
3414
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3415
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3416
|
+
desc = { enumerable: true, get: function() {
|
|
3417
|
+
return m[k];
|
|
3418
|
+
} };
|
|
3419
|
+
}
|
|
3420
|
+
Object.defineProperty(o, k2, desc);
|
|
3421
|
+
}) : (function(o, m, k, k2) {
|
|
3422
|
+
if (k2 === void 0) k2 = k;
|
|
3423
|
+
o[k2] = m[k];
|
|
3424
|
+
}));
|
|
3425
|
+
var __exportStar = main && main.__exportStar || function(m, exports3) {
|
|
3426
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
3427
|
+
};
|
|
3428
|
+
var __importDefault = main && main.__importDefault || function(mod) {
|
|
3429
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
3430
|
+
};
|
|
3431
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3432
|
+
exports2.BrowserMessageWriter = exports2.BrowserMessageReader = void 0;
|
|
3433
|
+
exports2.createMessageConnection = createMessageConnection;
|
|
3434
|
+
const ril_1 = __importDefault(requireRil());
|
|
3435
|
+
ril_1.default.install();
|
|
3436
|
+
const api_1 = requireApi();
|
|
3437
|
+
__exportStar(requireApi(), exports2);
|
|
3438
|
+
class BrowserMessageReader extends api_1.AbstractMessageReader {
|
|
3439
|
+
_onData;
|
|
3440
|
+
_messageListener;
|
|
3441
|
+
constructor(port) {
|
|
3442
|
+
super();
|
|
3443
|
+
this._onData = new api_1.Emitter();
|
|
3444
|
+
this._messageListener = (event) => {
|
|
3445
|
+
this._onData.fire(event.data);
|
|
3446
|
+
};
|
|
3447
|
+
port.addEventListener("error", (event) => this.fireError(event));
|
|
3448
|
+
port.onmessage = this._messageListener;
|
|
3449
|
+
}
|
|
3450
|
+
listen(callback) {
|
|
3451
|
+
return this._onData.event(callback);
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
exports2.BrowserMessageReader = BrowserMessageReader;
|
|
3455
|
+
class BrowserMessageWriter extends api_1.AbstractMessageWriter {
|
|
3456
|
+
port;
|
|
3457
|
+
errorCount;
|
|
3458
|
+
constructor(port) {
|
|
3459
|
+
super();
|
|
3460
|
+
this.port = port;
|
|
3461
|
+
this.errorCount = 0;
|
|
3462
|
+
port.addEventListener("error", (event) => this.fireError(event));
|
|
3463
|
+
}
|
|
3464
|
+
write(msg) {
|
|
3465
|
+
try {
|
|
3466
|
+
this.port.postMessage(msg);
|
|
3467
|
+
return Promise.resolve();
|
|
3468
|
+
} catch (error) {
|
|
3469
|
+
this.handleError(error, msg);
|
|
3470
|
+
return Promise.reject(error);
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
handleError(error, msg) {
|
|
3474
|
+
this.errorCount++;
|
|
3475
|
+
this.fireError(error, msg, this.errorCount);
|
|
3476
|
+
}
|
|
3477
|
+
end() {
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
exports2.BrowserMessageWriter = BrowserMessageWriter;
|
|
3481
|
+
function createMessageConnection(reader, writer, logger, options) {
|
|
3482
|
+
if (logger === void 0) {
|
|
3483
|
+
logger = api_1.NullLogger;
|
|
3484
|
+
}
|
|
3485
|
+
if (api_1.ConnectionStrategy.is(options)) {
|
|
3486
|
+
options = { connectionStrategy: options };
|
|
3487
|
+
}
|
|
3488
|
+
return (0, api_1.createMessageConnection)(reader, writer, logger, options);
|
|
3489
|
+
}
|
|
3490
|
+
})(main);
|
|
3491
|
+
return main;
|
|
3492
|
+
}
|
|
3493
|
+
requireMain();
|
|
3494
|
+
var apiExports = requireApi();
|
|
3495
|
+
function defineSplitConnection(Reader, Writer) {
|
|
3496
|
+
return function create(input, output) {
|
|
3497
|
+
return apiExports.createMessageConnection(new Reader(input), new Writer(output));
|
|
3498
|
+
};
|
|
3499
|
+
}
|
|
3500
|
+
class CallbackMessageReader extends apiExports.AbstractMessageReader {
|
|
3501
|
+
callback;
|
|
3502
|
+
unsubscribe;
|
|
3503
|
+
constructor(receiver) {
|
|
3504
|
+
super();
|
|
3505
|
+
this.unsubscribe = apiExports.Disposable.create(receiver.subscribe((message) => this.callback?.(message)));
|
|
3506
|
+
}
|
|
3507
|
+
listen(callback) {
|
|
3508
|
+
this.callback = callback;
|
|
3509
|
+
return apiExports.Disposable.create(() => {
|
|
3510
|
+
this.callback = void 0;
|
|
3511
|
+
});
|
|
3512
|
+
}
|
|
3513
|
+
dispose() {
|
|
3514
|
+
super.dispose();
|
|
3515
|
+
this.unsubscribe.dispose();
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
class CallbackMessageWriter extends apiExports.AbstractMessageWriter {
|
|
3519
|
+
sender;
|
|
3520
|
+
constructor(sender) {
|
|
3521
|
+
super();
|
|
3522
|
+
this.sender = sender;
|
|
3523
|
+
}
|
|
3524
|
+
write(message) {
|
|
3525
|
+
this.sender.send(message);
|
|
3526
|
+
return Promise.resolve();
|
|
3527
|
+
}
|
|
3528
|
+
end() {
|
|
3529
|
+
}
|
|
3530
|
+
dispose() {
|
|
3531
|
+
super.dispose();
|
|
3532
|
+
this.sender.dispose?.();
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
const createCallback = defineSplitConnection(CallbackMessageReader, CallbackMessageWriter);
|
|
3536
|
+
function splitSourceFor(create) {
|
|
3537
|
+
return function(input, output) {
|
|
3538
|
+
return (source) => create(input(source), output(source));
|
|
3539
|
+
};
|
|
3540
|
+
}
|
|
3541
|
+
function forElectronIPC(channel2) {
|
|
3542
|
+
return splitSourceFor(createCallback)((source) => ({
|
|
3543
|
+
subscribe: (callback) => {
|
|
3544
|
+
const listener = (_event, message) => callback(message);
|
|
3545
|
+
source.on(channel2, listener);
|
|
3546
|
+
return () => source.off(channel2, listener);
|
|
3547
|
+
}
|
|
3548
|
+
}), (source) => ({
|
|
3549
|
+
send: (message) => source.send(channel2, message)
|
|
3550
|
+
}));
|
|
3551
|
+
}
|
|
3552
|
+
var __extends = /* @__PURE__ */ (function() {
|
|
3553
|
+
var extendStatics = function(d, b) {
|
|
3554
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
3555
|
+
d2.__proto__ = b2;
|
|
3556
|
+
} || function(d2, b2) {
|
|
3557
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
3558
|
+
};
|
|
3559
|
+
return extendStatics(d, b);
|
|
3560
|
+
};
|
|
3561
|
+
return function(d, b) {
|
|
3562
|
+
extendStatics(d, b);
|
|
3563
|
+
function __() {
|
|
3564
|
+
this.constructor = d;
|
|
3565
|
+
}
|
|
3566
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
3567
|
+
};
|
|
3568
|
+
})();
|
|
3569
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
3570
|
+
function hasOwnProperty(obj, key) {
|
|
3571
|
+
return _hasOwnProperty.call(obj, key);
|
|
3572
|
+
}
|
|
3573
|
+
function _objectKeys(obj) {
|
|
3574
|
+
if (Array.isArray(obj)) {
|
|
3575
|
+
var keys_1 = new Array(obj.length);
|
|
3576
|
+
for (var k = 0; k < keys_1.length; k++) {
|
|
3577
|
+
keys_1[k] = "" + k;
|
|
3578
|
+
}
|
|
3579
|
+
return keys_1;
|
|
3580
|
+
}
|
|
3581
|
+
if (Object.keys) {
|
|
3582
|
+
return Object.keys(obj);
|
|
3583
|
+
}
|
|
3584
|
+
var keys = [];
|
|
3585
|
+
for (var i in obj) {
|
|
3586
|
+
if (hasOwnProperty(obj, i)) {
|
|
3587
|
+
keys.push(i);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
return keys;
|
|
3591
|
+
}
|
|
3592
|
+
function _deepClone(obj) {
|
|
3593
|
+
switch (typeof obj) {
|
|
3594
|
+
case "object":
|
|
3595
|
+
return JSON.parse(JSON.stringify(obj));
|
|
3596
|
+
//Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
|
3597
|
+
case "undefined":
|
|
3598
|
+
return null;
|
|
3599
|
+
//this is how JSON.stringify behaves for array items
|
|
3600
|
+
default:
|
|
3601
|
+
return obj;
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
function isInteger(str) {
|
|
3605
|
+
var i = 0;
|
|
3606
|
+
var len = str.length;
|
|
3607
|
+
var charCode;
|
|
3608
|
+
while (i < len) {
|
|
3609
|
+
charCode = str.charCodeAt(i);
|
|
3610
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
3611
|
+
i++;
|
|
3612
|
+
continue;
|
|
3613
|
+
}
|
|
3614
|
+
return false;
|
|
3615
|
+
}
|
|
3616
|
+
return true;
|
|
3617
|
+
}
|
|
3618
|
+
function escapePathComponent(path) {
|
|
3619
|
+
if (path.indexOf("/") === -1 && path.indexOf("~") === -1)
|
|
3620
|
+
return path;
|
|
3621
|
+
return path.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
3622
|
+
}
|
|
3623
|
+
function unescapePathComponent(path) {
|
|
3624
|
+
return path.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
3625
|
+
}
|
|
3626
|
+
function hasUndefined(obj) {
|
|
3627
|
+
if (obj === void 0) {
|
|
3628
|
+
return true;
|
|
3629
|
+
}
|
|
3630
|
+
if (obj) {
|
|
3631
|
+
if (Array.isArray(obj)) {
|
|
3632
|
+
for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) {
|
|
3633
|
+
if (hasUndefined(obj[i_1])) {
|
|
3634
|
+
return true;
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
} else if (typeof obj === "object") {
|
|
3638
|
+
var objKeys = _objectKeys(obj);
|
|
3639
|
+
var objKeysLength = objKeys.length;
|
|
3640
|
+
for (var i = 0; i < objKeysLength; i++) {
|
|
3641
|
+
if (hasUndefined(obj[objKeys[i]])) {
|
|
3642
|
+
return true;
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
return false;
|
|
3648
|
+
}
|
|
3649
|
+
function patchErrorMessageFormatter(message, args) {
|
|
3650
|
+
var messageParts = [message];
|
|
3651
|
+
for (var key in args) {
|
|
3652
|
+
var value = typeof args[key] === "object" ? JSON.stringify(args[key], null, 2) : args[key];
|
|
3653
|
+
if (typeof value !== "undefined") {
|
|
3654
|
+
messageParts.push(key + ": " + value);
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
return messageParts.join("\n");
|
|
3658
|
+
}
|
|
3659
|
+
var PatchError = (
|
|
3660
|
+
/** @class */
|
|
3661
|
+
(function(_super) {
|
|
3662
|
+
__extends(PatchError2, _super);
|
|
3663
|
+
function PatchError2(message, name, index, operation, tree) {
|
|
3664
|
+
var _newTarget = this.constructor;
|
|
3665
|
+
var _this = _super.call(this, patchErrorMessageFormatter(message, { name, index, operation, tree })) || this;
|
|
3666
|
+
_this.name = name;
|
|
3667
|
+
_this.index = index;
|
|
3668
|
+
_this.operation = operation;
|
|
3669
|
+
_this.tree = tree;
|
|
3670
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
3671
|
+
_this.message = patchErrorMessageFormatter(message, { name, index, operation, tree });
|
|
3672
|
+
return _this;
|
|
3673
|
+
}
|
|
3674
|
+
return PatchError2;
|
|
3675
|
+
})(Error)
|
|
3676
|
+
);
|
|
3677
|
+
var JsonPatchError = PatchError;
|
|
3678
|
+
var deepClone = _deepClone;
|
|
3679
|
+
var objOps = {
|
|
3680
|
+
add: function(obj, key, document) {
|
|
3681
|
+
obj[key] = this.value;
|
|
3682
|
+
return { newDocument: document };
|
|
3683
|
+
},
|
|
3684
|
+
remove: function(obj, key, document) {
|
|
3685
|
+
var removed = obj[key];
|
|
3686
|
+
delete obj[key];
|
|
3687
|
+
return { newDocument: document, removed };
|
|
3688
|
+
},
|
|
3689
|
+
replace: function(obj, key, document) {
|
|
3690
|
+
var removed = obj[key];
|
|
3691
|
+
obj[key] = this.value;
|
|
3692
|
+
return { newDocument: document, removed };
|
|
3693
|
+
},
|
|
3694
|
+
move: function(obj, key, document) {
|
|
3695
|
+
var removed = getValueByPointer(document, this.path);
|
|
3696
|
+
if (removed) {
|
|
3697
|
+
removed = _deepClone(removed);
|
|
3698
|
+
}
|
|
3699
|
+
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
|
|
3700
|
+
applyOperation(document, { op: "add", path: this.path, value: originalValue });
|
|
3701
|
+
return { newDocument: document, removed };
|
|
3702
|
+
},
|
|
3703
|
+
copy: function(obj, key, document) {
|
|
3704
|
+
var valueToCopy = getValueByPointer(document, this.from);
|
|
3705
|
+
applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) });
|
|
3706
|
+
return { newDocument: document };
|
|
3707
|
+
},
|
|
3708
|
+
test: function(obj, key, document) {
|
|
3709
|
+
return { newDocument: document, test: _areEquals(obj[key], this.value) };
|
|
3710
|
+
},
|
|
3711
|
+
_get: function(obj, key, document) {
|
|
3712
|
+
this.value = obj[key];
|
|
3713
|
+
return { newDocument: document };
|
|
3714
|
+
}
|
|
3715
|
+
};
|
|
3716
|
+
var arrOps = {
|
|
3717
|
+
add: function(arr, i, document) {
|
|
3718
|
+
if (isInteger(i)) {
|
|
3719
|
+
arr.splice(i, 0, this.value);
|
|
3720
|
+
} else {
|
|
3721
|
+
arr[i] = this.value;
|
|
3722
|
+
}
|
|
3723
|
+
return { newDocument: document, index: i };
|
|
3724
|
+
},
|
|
3725
|
+
remove: function(arr, i, document) {
|
|
3726
|
+
var removedList = arr.splice(i, 1);
|
|
3727
|
+
return { newDocument: document, removed: removedList[0] };
|
|
3728
|
+
},
|
|
3729
|
+
replace: function(arr, i, document) {
|
|
3730
|
+
var removed = arr[i];
|
|
3731
|
+
arr[i] = this.value;
|
|
3732
|
+
return { newDocument: document, removed };
|
|
3733
|
+
},
|
|
3734
|
+
move: objOps.move,
|
|
3735
|
+
copy: objOps.copy,
|
|
3736
|
+
test: objOps.test,
|
|
3737
|
+
_get: objOps._get
|
|
3738
|
+
};
|
|
3739
|
+
function getValueByPointer(document, pointer) {
|
|
3740
|
+
if (pointer == "") {
|
|
3741
|
+
return document;
|
|
3742
|
+
}
|
|
3743
|
+
var getOriginalDestination = { op: "_get", path: pointer };
|
|
3744
|
+
applyOperation(document, getOriginalDestination);
|
|
3745
|
+
return getOriginalDestination.value;
|
|
3746
|
+
}
|
|
3747
|
+
function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
|
|
3748
|
+
if (validateOperation === void 0) {
|
|
3749
|
+
validateOperation = false;
|
|
3750
|
+
}
|
|
3751
|
+
if (mutateDocument === void 0) {
|
|
3752
|
+
mutateDocument = true;
|
|
3753
|
+
}
|
|
3754
|
+
if (banPrototypeModifications === void 0) {
|
|
3755
|
+
banPrototypeModifications = true;
|
|
3756
|
+
}
|
|
3757
|
+
if (index === void 0) {
|
|
3758
|
+
index = 0;
|
|
3759
|
+
}
|
|
3760
|
+
if (validateOperation) {
|
|
3761
|
+
if (typeof validateOperation == "function") {
|
|
3762
|
+
validateOperation(operation, 0, document, operation.path);
|
|
3763
|
+
} else {
|
|
3764
|
+
validator(operation, 0);
|
|
3765
|
+
}
|
|
3766
|
+
}
|
|
3767
|
+
if (operation.path === "") {
|
|
3768
|
+
var returnValue = { newDocument: document };
|
|
3769
|
+
if (operation.op === "add") {
|
|
3770
|
+
returnValue.newDocument = operation.value;
|
|
3771
|
+
return returnValue;
|
|
3772
|
+
} else if (operation.op === "replace") {
|
|
3773
|
+
returnValue.newDocument = operation.value;
|
|
3774
|
+
returnValue.removed = document;
|
|
3775
|
+
return returnValue;
|
|
3776
|
+
} else if (operation.op === "move" || operation.op === "copy") {
|
|
3777
|
+
returnValue.newDocument = getValueByPointer(document, operation.from);
|
|
3778
|
+
if (operation.op === "move") {
|
|
3779
|
+
returnValue.removed = document;
|
|
3780
|
+
}
|
|
3781
|
+
return returnValue;
|
|
3782
|
+
} else if (operation.op === "test") {
|
|
3783
|
+
returnValue.test = _areEquals(document, operation.value);
|
|
3784
|
+
if (returnValue.test === false) {
|
|
3785
|
+
throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
|
|
3786
|
+
}
|
|
3787
|
+
returnValue.newDocument = document;
|
|
3788
|
+
return returnValue;
|
|
3789
|
+
} else if (operation.op === "remove") {
|
|
3790
|
+
returnValue.removed = document;
|
|
3791
|
+
returnValue.newDocument = null;
|
|
3792
|
+
return returnValue;
|
|
3793
|
+
} else if (operation.op === "_get") {
|
|
3794
|
+
operation.value = document;
|
|
3795
|
+
return returnValue;
|
|
3796
|
+
} else {
|
|
3797
|
+
if (validateOperation) {
|
|
3798
|
+
throw new JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", index, operation, document);
|
|
3799
|
+
} else {
|
|
3800
|
+
return returnValue;
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
} else {
|
|
3804
|
+
if (!mutateDocument) {
|
|
3805
|
+
document = _deepClone(document);
|
|
3806
|
+
}
|
|
3807
|
+
var path = operation.path || "";
|
|
3808
|
+
var keys = path.split("/");
|
|
3809
|
+
var obj = document;
|
|
3810
|
+
var t = 1;
|
|
3811
|
+
var len = keys.length;
|
|
3812
|
+
var existingPathFragment = void 0;
|
|
3813
|
+
var key = void 0;
|
|
3814
|
+
var validateFunction = void 0;
|
|
3815
|
+
if (typeof validateOperation == "function") {
|
|
3816
|
+
validateFunction = validateOperation;
|
|
3817
|
+
} else {
|
|
3818
|
+
validateFunction = validator;
|
|
3819
|
+
}
|
|
3820
|
+
while (true) {
|
|
3821
|
+
key = keys[t];
|
|
3822
|
+
if (key && key.indexOf("~") != -1) {
|
|
3823
|
+
key = unescapePathComponent(key);
|
|
3824
|
+
}
|
|
3825
|
+
if (banPrototypeModifications && (key == "__proto__" || key == "prototype" && t > 0 && keys[t - 1] == "constructor")) {
|
|
3826
|
+
throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");
|
|
3827
|
+
}
|
|
3828
|
+
if (validateOperation) {
|
|
3829
|
+
if (existingPathFragment === void 0) {
|
|
3830
|
+
if (obj[key] === void 0) {
|
|
3831
|
+
existingPathFragment = keys.slice(0, t).join("/");
|
|
3832
|
+
} else if (t == len - 1) {
|
|
3833
|
+
existingPathFragment = operation.path;
|
|
3834
|
+
}
|
|
3835
|
+
if (existingPathFragment !== void 0) {
|
|
3836
|
+
validateFunction(operation, 0, document, existingPathFragment);
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
t++;
|
|
3841
|
+
if (Array.isArray(obj)) {
|
|
3842
|
+
if (key === "-") {
|
|
3843
|
+
key = obj.length;
|
|
3844
|
+
} else {
|
|
3845
|
+
if (validateOperation && !isInteger(key)) {
|
|
3846
|
+
throw new JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", index, operation, document);
|
|
3847
|
+
} else if (isInteger(key)) {
|
|
3848
|
+
key = ~~key;
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
if (t >= len) {
|
|
3852
|
+
if (validateOperation && operation.op === "add" && key > obj.length) {
|
|
3853
|
+
throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
|
|
3854
|
+
}
|
|
3855
|
+
var returnValue = arrOps[operation.op].call(operation, obj, key, document);
|
|
3856
|
+
if (returnValue.test === false) {
|
|
3857
|
+
throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
|
|
3858
|
+
}
|
|
3859
|
+
return returnValue;
|
|
3860
|
+
}
|
|
3861
|
+
} else {
|
|
3862
|
+
if (t >= len) {
|
|
3863
|
+
var returnValue = objOps[operation.op].call(operation, obj, key, document);
|
|
3864
|
+
if (returnValue.test === false) {
|
|
3865
|
+
throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
|
|
3866
|
+
}
|
|
3867
|
+
return returnValue;
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
obj = obj[key];
|
|
3871
|
+
if (validateOperation && t < len && (!obj || typeof obj !== "object")) {
|
|
3872
|
+
throw new JsonPatchError("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", index, operation, document);
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
|
|
3878
|
+
if (mutateDocument === void 0) {
|
|
3879
|
+
mutateDocument = true;
|
|
3880
|
+
}
|
|
3881
|
+
if (banPrototypeModifications === void 0) {
|
|
3882
|
+
banPrototypeModifications = true;
|
|
3883
|
+
}
|
|
3884
|
+
if (validateOperation) {
|
|
3885
|
+
if (!Array.isArray(patch)) {
|
|
3886
|
+
throw new JsonPatchError("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3889
|
+
if (!mutateDocument) {
|
|
3890
|
+
document = _deepClone(document);
|
|
3891
|
+
}
|
|
3892
|
+
var results = new Array(patch.length);
|
|
3893
|
+
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
|
|
3894
|
+
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
|
|
3895
|
+
document = results[i].newDocument;
|
|
3896
|
+
}
|
|
3897
|
+
results.newDocument = document;
|
|
3898
|
+
return results;
|
|
3899
|
+
}
|
|
3900
|
+
function applyReducer(document, operation, index) {
|
|
3901
|
+
var operationResult = applyOperation(document, operation);
|
|
3902
|
+
if (operationResult.test === false) {
|
|
3903
|
+
throw new JsonPatchError("Test operation failed", "TEST_OPERATION_FAILED", index, operation, document);
|
|
3904
|
+
}
|
|
3905
|
+
return operationResult.newDocument;
|
|
3906
|
+
}
|
|
3907
|
+
function validator(operation, index, document, existingPathFragment) {
|
|
3908
|
+
if (typeof operation !== "object" || operation === null || Array.isArray(operation)) {
|
|
3909
|
+
throw new JsonPatchError("Operation is not an object", "OPERATION_NOT_AN_OBJECT", index, operation, document);
|
|
3910
|
+
} else if (!objOps[operation.op]) {
|
|
3911
|
+
throw new JsonPatchError("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", index, operation, document);
|
|
3912
|
+
} else if (typeof operation.path !== "string") {
|
|
3913
|
+
throw new JsonPatchError("Operation `path` property is not a string", "OPERATION_PATH_INVALID", index, operation, document);
|
|
3914
|
+
} else if (operation.path.indexOf("/") !== 0 && operation.path.length > 0) {
|
|
3915
|
+
throw new JsonPatchError('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", index, operation, document);
|
|
3916
|
+
} else if ((operation.op === "move" || operation.op === "copy") && typeof operation.from !== "string") {
|
|
3917
|
+
throw new JsonPatchError("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", index, operation, document);
|
|
3918
|
+
} else if ((operation.op === "add" || operation.op === "replace" || operation.op === "test") && operation.value === void 0) {
|
|
3919
|
+
throw new JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", index, operation, document);
|
|
3920
|
+
} else if ((operation.op === "add" || operation.op === "replace" || operation.op === "test") && hasUndefined(operation.value)) {
|
|
3921
|
+
throw new JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", index, operation, document);
|
|
3922
|
+
} else if (document) {
|
|
3923
|
+
if (operation.op == "add") {
|
|
3924
|
+
var pathLen = operation.path.split("/").length;
|
|
3925
|
+
var existingPathLen = existingPathFragment.split("/").length;
|
|
3926
|
+
if (pathLen !== existingPathLen + 1 && pathLen !== existingPathLen) {
|
|
3927
|
+
throw new JsonPatchError("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", index, operation, document);
|
|
3928
|
+
}
|
|
3929
|
+
} else if (operation.op === "replace" || operation.op === "remove" || operation.op === "_get") {
|
|
3930
|
+
if (operation.path !== existingPathFragment) {
|
|
3931
|
+
throw new JsonPatchError("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", index, operation, document);
|
|
3932
|
+
}
|
|
3933
|
+
} else if (operation.op === "move" || operation.op === "copy") {
|
|
3934
|
+
var existingValue = { op: "_get", path: operation.from, value: void 0 };
|
|
3935
|
+
var error = validate([existingValue], document);
|
|
3936
|
+
if (error && error.name === "OPERATION_PATH_UNRESOLVABLE") {
|
|
3937
|
+
throw new JsonPatchError("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", index, operation, document);
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
3941
|
+
}
|
|
3942
|
+
function validate(sequence, document, externalValidator) {
|
|
3943
|
+
try {
|
|
3944
|
+
if (!Array.isArray(sequence)) {
|
|
3945
|
+
throw new JsonPatchError("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
|
|
3946
|
+
}
|
|
3947
|
+
if (document) {
|
|
3948
|
+
applyPatch(_deepClone(document), _deepClone(sequence), externalValidator || true);
|
|
3949
|
+
} else {
|
|
3950
|
+
externalValidator = externalValidator || validator;
|
|
3951
|
+
for (var i = 0; i < sequence.length; i++) {
|
|
3952
|
+
externalValidator(sequence[i], i, document, void 0);
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
} catch (e) {
|
|
3956
|
+
if (e instanceof JsonPatchError) {
|
|
3957
|
+
return e;
|
|
3958
|
+
} else {
|
|
3959
|
+
throw e;
|
|
3960
|
+
}
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
function _areEquals(a, b) {
|
|
3964
|
+
if (a === b)
|
|
3965
|
+
return true;
|
|
3966
|
+
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
3967
|
+
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
|
|
3968
|
+
if (arrA && arrB) {
|
|
3969
|
+
length = a.length;
|
|
3970
|
+
if (length != b.length)
|
|
3971
|
+
return false;
|
|
3972
|
+
for (i = length; i-- !== 0; )
|
|
3973
|
+
if (!_areEquals(a[i], b[i]))
|
|
3974
|
+
return false;
|
|
3975
|
+
return true;
|
|
3976
|
+
}
|
|
3977
|
+
if (arrA != arrB)
|
|
3978
|
+
return false;
|
|
3979
|
+
var keys = Object.keys(a);
|
|
3980
|
+
length = keys.length;
|
|
3981
|
+
if (length !== Object.keys(b).length)
|
|
3982
|
+
return false;
|
|
3983
|
+
for (i = length; i-- !== 0; )
|
|
3984
|
+
if (!b.hasOwnProperty(keys[i]))
|
|
3985
|
+
return false;
|
|
3986
|
+
for (i = length; i-- !== 0; ) {
|
|
3987
|
+
key = keys[i];
|
|
3988
|
+
if (!_areEquals(a[key], b[key]))
|
|
3989
|
+
return false;
|
|
3990
|
+
}
|
|
3991
|
+
return true;
|
|
3992
|
+
}
|
|
3993
|
+
return a !== a && b !== b;
|
|
3994
|
+
}
|
|
3995
|
+
const core = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3996
|
+
__proto__: null,
|
|
3997
|
+
JsonPatchError,
|
|
3998
|
+
_areEquals,
|
|
3999
|
+
applyOperation,
|
|
4000
|
+
applyPatch,
|
|
4001
|
+
applyReducer,
|
|
4002
|
+
deepClone,
|
|
4003
|
+
getValueByPointer,
|
|
4004
|
+
validate,
|
|
4005
|
+
validator
|
|
4006
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
4007
|
+
var beforeDict = /* @__PURE__ */ new WeakMap();
|
|
4008
|
+
var Mirror = (
|
|
4009
|
+
/** @class */
|
|
4010
|
+
/* @__PURE__ */ (function() {
|
|
4011
|
+
function Mirror2(obj) {
|
|
4012
|
+
this.observers = /* @__PURE__ */ new Map();
|
|
4013
|
+
this.obj = obj;
|
|
4014
|
+
}
|
|
4015
|
+
return Mirror2;
|
|
4016
|
+
})()
|
|
4017
|
+
);
|
|
4018
|
+
var ObserverInfo = (
|
|
4019
|
+
/** @class */
|
|
4020
|
+
/* @__PURE__ */ (function() {
|
|
4021
|
+
function ObserverInfo2(callback, observer) {
|
|
4022
|
+
this.callback = callback;
|
|
4023
|
+
this.observer = observer;
|
|
4024
|
+
}
|
|
4025
|
+
return ObserverInfo2;
|
|
4026
|
+
})()
|
|
4027
|
+
);
|
|
4028
|
+
function getMirror(obj) {
|
|
4029
|
+
return beforeDict.get(obj);
|
|
4030
|
+
}
|
|
4031
|
+
function getObserverFromMirror(mirror, callback) {
|
|
4032
|
+
return mirror.observers.get(callback);
|
|
4033
|
+
}
|
|
4034
|
+
function removeObserverFromMirror(mirror, observer) {
|
|
4035
|
+
mirror.observers.delete(observer.callback);
|
|
4036
|
+
}
|
|
4037
|
+
function unobserve(root, observer) {
|
|
4038
|
+
observer.unobserve();
|
|
4039
|
+
}
|
|
4040
|
+
function observe(obj, callback) {
|
|
4041
|
+
var patches = [];
|
|
4042
|
+
var observer;
|
|
4043
|
+
var mirror = getMirror(obj);
|
|
4044
|
+
if (!mirror) {
|
|
4045
|
+
mirror = new Mirror(obj);
|
|
4046
|
+
beforeDict.set(obj, mirror);
|
|
4047
|
+
} else {
|
|
4048
|
+
var observerInfo = getObserverFromMirror(mirror, callback);
|
|
4049
|
+
observer = observerInfo && observerInfo.observer;
|
|
4050
|
+
}
|
|
4051
|
+
if (observer) {
|
|
4052
|
+
return observer;
|
|
4053
|
+
}
|
|
4054
|
+
observer = {};
|
|
4055
|
+
mirror.value = _deepClone(obj);
|
|
4056
|
+
if (callback) {
|
|
4057
|
+
observer.callback = callback;
|
|
4058
|
+
observer.next = null;
|
|
4059
|
+
var dirtyCheck = function() {
|
|
4060
|
+
generate(observer);
|
|
4061
|
+
};
|
|
4062
|
+
var fastCheck = function() {
|
|
4063
|
+
clearTimeout(observer.next);
|
|
4064
|
+
observer.next = setTimeout(dirtyCheck);
|
|
4065
|
+
};
|
|
4066
|
+
if (typeof window !== "undefined") {
|
|
4067
|
+
window.addEventListener("mouseup", fastCheck);
|
|
4068
|
+
window.addEventListener("keyup", fastCheck);
|
|
4069
|
+
window.addEventListener("mousedown", fastCheck);
|
|
4070
|
+
window.addEventListener("keydown", fastCheck);
|
|
4071
|
+
window.addEventListener("change", fastCheck);
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
observer.patches = patches;
|
|
4075
|
+
observer.object = obj;
|
|
4076
|
+
observer.unobserve = function() {
|
|
4077
|
+
generate(observer);
|
|
4078
|
+
clearTimeout(observer.next);
|
|
4079
|
+
removeObserverFromMirror(mirror, observer);
|
|
4080
|
+
if (typeof window !== "undefined") {
|
|
4081
|
+
window.removeEventListener("mouseup", fastCheck);
|
|
4082
|
+
window.removeEventListener("keyup", fastCheck);
|
|
4083
|
+
window.removeEventListener("mousedown", fastCheck);
|
|
4084
|
+
window.removeEventListener("keydown", fastCheck);
|
|
4085
|
+
window.removeEventListener("change", fastCheck);
|
|
4086
|
+
}
|
|
4087
|
+
};
|
|
4088
|
+
mirror.observers.set(callback, new ObserverInfo(callback, observer));
|
|
4089
|
+
return observer;
|
|
4090
|
+
}
|
|
4091
|
+
function generate(observer, invertible) {
|
|
4092
|
+
if (invertible === void 0) {
|
|
4093
|
+
invertible = false;
|
|
4094
|
+
}
|
|
4095
|
+
var mirror = beforeDict.get(observer.object);
|
|
4096
|
+
_generate(mirror.value, observer.object, observer.patches, "", invertible);
|
|
4097
|
+
if (observer.patches.length) {
|
|
4098
|
+
applyPatch(mirror.value, observer.patches);
|
|
4099
|
+
}
|
|
4100
|
+
var temp = observer.patches;
|
|
4101
|
+
if (temp.length > 0) {
|
|
4102
|
+
observer.patches = [];
|
|
4103
|
+
if (observer.callback) {
|
|
4104
|
+
observer.callback(temp);
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
return temp;
|
|
4108
|
+
}
|
|
4109
|
+
function _generate(mirror, obj, patches, path, invertible) {
|
|
4110
|
+
if (obj === mirror) {
|
|
4111
|
+
return;
|
|
4112
|
+
}
|
|
4113
|
+
if (typeof obj.toJSON === "function") {
|
|
4114
|
+
obj = obj.toJSON();
|
|
4115
|
+
}
|
|
4116
|
+
var newKeys = _objectKeys(obj);
|
|
4117
|
+
var oldKeys = _objectKeys(mirror);
|
|
4118
|
+
var deleted = false;
|
|
4119
|
+
for (var t = oldKeys.length - 1; t >= 0; t--) {
|
|
4120
|
+
var key = oldKeys[t];
|
|
4121
|
+
var oldVal = mirror[key];
|
|
4122
|
+
if (hasOwnProperty(obj, key) && !(obj[key] === void 0 && oldVal !== void 0 && Array.isArray(obj) === false)) {
|
|
4123
|
+
var newVal = obj[key];
|
|
4124
|
+
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null && Array.isArray(oldVal) === Array.isArray(newVal)) {
|
|
4125
|
+
_generate(oldVal, newVal, patches, path + "/" + escapePathComponent(key), invertible);
|
|
4126
|
+
} else {
|
|
4127
|
+
if (oldVal !== newVal) {
|
|
4128
|
+
if (invertible) {
|
|
4129
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
|
4130
|
+
}
|
|
4131
|
+
patches.push({ op: "replace", path: path + "/" + escapePathComponent(key), value: _deepClone(newVal) });
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
} else if (Array.isArray(mirror) === Array.isArray(obj)) {
|
|
4135
|
+
if (invertible) {
|
|
4136
|
+
patches.push({ op: "test", path: path + "/" + escapePathComponent(key), value: _deepClone(oldVal) });
|
|
4137
|
+
}
|
|
4138
|
+
patches.push({ op: "remove", path: path + "/" + escapePathComponent(key) });
|
|
4139
|
+
deleted = true;
|
|
4140
|
+
} else {
|
|
4141
|
+
if (invertible) {
|
|
4142
|
+
patches.push({ op: "test", path, value: mirror });
|
|
4143
|
+
}
|
|
4144
|
+
patches.push({ op: "replace", path, value: obj });
|
|
4145
|
+
}
|
|
4146
|
+
}
|
|
4147
|
+
if (!deleted && newKeys.length == oldKeys.length) {
|
|
4148
|
+
return;
|
|
4149
|
+
}
|
|
4150
|
+
for (var t = 0; t < newKeys.length; t++) {
|
|
4151
|
+
var key = newKeys[t];
|
|
4152
|
+
if (!hasOwnProperty(mirror, key) && obj[key] !== void 0) {
|
|
4153
|
+
patches.push({ op: "add", path: path + "/" + escapePathComponent(key), value: _deepClone(obj[key]) });
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
}
|
|
4157
|
+
function compare(tree1, tree2, invertible) {
|
|
4158
|
+
if (invertible === void 0) {
|
|
4159
|
+
invertible = false;
|
|
4160
|
+
}
|
|
4161
|
+
var patches = [];
|
|
4162
|
+
_generate(tree1, tree2, patches, "", invertible);
|
|
4163
|
+
return patches;
|
|
4164
|
+
}
|
|
4165
|
+
const duplex = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4166
|
+
__proto__: null,
|
|
4167
|
+
compare,
|
|
4168
|
+
generate,
|
|
4169
|
+
observe,
|
|
4170
|
+
unobserve
|
|
4171
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
4172
|
+
const jsonpatch = Object.assign({}, core, duplex, {
|
|
4173
|
+
JsonPatchError: PatchError,
|
|
4174
|
+
deepClone: _deepClone,
|
|
4175
|
+
escapePathComponent,
|
|
4176
|
+
unescapePathComponent
|
|
4177
|
+
});
|
|
4178
|
+
const isContainer = (value) => typeof value === "object" && value !== null;
|
|
4179
|
+
function diff(prev, next) {
|
|
4180
|
+
if (isContainer(prev) && isContainer(next) && Array.isArray(prev) === Array.isArray(next))
|
|
4181
|
+
return jsonpatch.compare(prev, next);
|
|
4182
|
+
return Object.is(prev, next) ? [] : [{ op: "replace", path: "", value: next }];
|
|
4183
|
+
}
|
|
4184
|
+
function createSaver(save) {
|
|
4185
|
+
let running = Promise.resolve();
|
|
4186
|
+
let queued;
|
|
4187
|
+
return (change) => {
|
|
4188
|
+
if (queued) {
|
|
4189
|
+
queued.change = { state: change.state, previous: queued.change.previous, ops: [...queued.change.ops, ...change.ops] };
|
|
4190
|
+
return queued.saved;
|
|
4191
|
+
}
|
|
4192
|
+
const entry = { change };
|
|
4193
|
+
entry.saved = running.then(() => {
|
|
4194
|
+
if (queued === entry)
|
|
4195
|
+
queued = void 0;
|
|
4196
|
+
return save(entry.change);
|
|
4197
|
+
});
|
|
4198
|
+
queued = entry;
|
|
4199
|
+
running = entry.saved.catch(() => {
|
|
4200
|
+
});
|
|
4201
|
+
return entry.saved;
|
|
4202
|
+
};
|
|
4203
|
+
}
|
|
4204
|
+
async function createStore(channels, storage) {
|
|
4205
|
+
const names = Object.keys(channels);
|
|
4206
|
+
const state2 = {};
|
|
4207
|
+
const seqs = /* @__PURE__ */ new Map();
|
|
4208
|
+
const savers = /* @__PURE__ */ new Map();
|
|
4209
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
4210
|
+
for (const channel2 of names) {
|
|
4211
|
+
const channelStorage = storage[channel2];
|
|
4212
|
+
if (!channelStorage)
|
|
4213
|
+
throw new Error(`no storage for state channel: ${String(channel2)}`);
|
|
4214
|
+
state2[channel2] = structuredClone(await channelStorage.load());
|
|
4215
|
+
seqs.set(channel2, 0);
|
|
4216
|
+
if (channelStorage.save)
|
|
4217
|
+
savers.set(channel2, createSaver(channelStorage.save.bind(channelStorage)));
|
|
4218
|
+
}
|
|
4219
|
+
function assertChannel(channel2) {
|
|
4220
|
+
if (!seqs.has(channel2))
|
|
4221
|
+
throw new Error(`unknown state channel: ${String(channel2)}`);
|
|
4222
|
+
}
|
|
4223
|
+
function set(partial) {
|
|
4224
|
+
const saves = [];
|
|
4225
|
+
for (const channel2 of Object.keys(partial)) {
|
|
4226
|
+
assertChannel(channel2);
|
|
4227
|
+
const next = structuredClone(partial[channel2]);
|
|
4228
|
+
const previous = state2[channel2];
|
|
4229
|
+
const ops = diff(previous, next);
|
|
4230
|
+
if (ops.length === 0)
|
|
4231
|
+
continue;
|
|
4232
|
+
state2[channel2] = next;
|
|
4233
|
+
const seq = seqs.get(channel2) + 1;
|
|
4234
|
+
seqs.set(channel2, seq);
|
|
4235
|
+
for (const listener of listeners.get(channel2) ?? [])
|
|
4236
|
+
listener({ seq, ops });
|
|
4237
|
+
const save = savers.get(channel2);
|
|
4238
|
+
if (save)
|
|
4239
|
+
saves.push(save({ state: next, previous, ops }));
|
|
4240
|
+
}
|
|
4241
|
+
const saved = Promise.all(saves).then(() => {
|
|
4242
|
+
});
|
|
4243
|
+
saved.catch(() => {
|
|
4244
|
+
});
|
|
4245
|
+
return saved;
|
|
4246
|
+
}
|
|
4247
|
+
return {
|
|
4248
|
+
get state() {
|
|
4249
|
+
return state2;
|
|
4250
|
+
},
|
|
4251
|
+
seq: (channel2) => {
|
|
4252
|
+
assertChannel(channel2);
|
|
4253
|
+
return seqs.get(channel2);
|
|
4254
|
+
},
|
|
4255
|
+
set,
|
|
4256
|
+
update(channel2, edit) {
|
|
4257
|
+
assertChannel(channel2);
|
|
4258
|
+
const draft = structuredClone(state2[channel2]);
|
|
4259
|
+
const result = edit(draft);
|
|
4260
|
+
return set({ [channel2]: result === void 0 ? draft : result });
|
|
4261
|
+
},
|
|
4262
|
+
watch(channel2, listener) {
|
|
4263
|
+
assertChannel(channel2);
|
|
4264
|
+
let channelListeners = listeners.get(channel2);
|
|
4265
|
+
if (!channelListeners)
|
|
4266
|
+
listeners.set(channel2, channelListeners = /* @__PURE__ */ new Set());
|
|
4267
|
+
channelListeners.add(listener);
|
|
4268
|
+
return {
|
|
4269
|
+
state: structuredClone(state2[channel2]),
|
|
4270
|
+
seq: seqs.get(channel2),
|
|
4271
|
+
dispose: () => {
|
|
4272
|
+
channelListeners.delete(listener);
|
|
4273
|
+
}
|
|
4274
|
+
};
|
|
4275
|
+
}
|
|
4276
|
+
};
|
|
4277
|
+
}
|
|
4278
|
+
const subscribeType = new apiExports.RequestType("$/state/subscribe");
|
|
4279
|
+
const unsubscribeType = new apiExports.NotificationType("$/state/unsubscribe");
|
|
4280
|
+
const patchType = new apiExports.NotificationType("$/state/patch");
|
|
4281
|
+
function serveStore(connection2, store) {
|
|
4282
|
+
const watches = /* @__PURE__ */ new Map();
|
|
4283
|
+
const unsubscribe = (channel2) => {
|
|
4284
|
+
watches.get(channel2)?.();
|
|
4285
|
+
watches.delete(channel2);
|
|
4286
|
+
};
|
|
4287
|
+
connection2.onRequest(subscribeType, ({ channel: channel2 }) => {
|
|
4288
|
+
unsubscribe(channel2);
|
|
4289
|
+
const watch = store.watch(channel2, (patch) => connection2.sendNotification(patchType, { channel: channel2, ...patch }));
|
|
4290
|
+
watches.set(channel2, watch.dispose);
|
|
4291
|
+
return { state: watch.state, seq: watch.seq };
|
|
4292
|
+
});
|
|
4293
|
+
connection2.onNotification(unsubscribeType, ({ channel: channel2 }) => unsubscribe(channel2));
|
|
4294
|
+
const closeAll = () => {
|
|
4295
|
+
for (const channel2 of [...watches.keys()])
|
|
4296
|
+
unsubscribe(channel2);
|
|
4297
|
+
};
|
|
4298
|
+
connection2.onClose(closeAll);
|
|
4299
|
+
connection2.onDispose(closeAll);
|
|
4300
|
+
}
|
|
4301
|
+
function mirrorState(connection2, channels) {
|
|
4302
|
+
const mirrors = /* @__PURE__ */ new Map();
|
|
4303
|
+
const notify = (mirror) => {
|
|
4304
|
+
for (const listener of mirror.listeners)
|
|
4305
|
+
listener(mirror.state);
|
|
4306
|
+
};
|
|
4307
|
+
function apply(mirror, patch) {
|
|
4308
|
+
if (patch.seq <= mirror.seq)
|
|
4309
|
+
return;
|
|
4310
|
+
if (patch.seq !== mirror.seq + 1) {
|
|
4311
|
+
void resubscribe(patch.channel, mirror);
|
|
4312
|
+
return;
|
|
4313
|
+
}
|
|
4314
|
+
mirror.state = jsonpatch.applyPatch(mirror.state, patch.ops, false, false).newDocument;
|
|
4315
|
+
mirror.seq = patch.seq;
|
|
4316
|
+
notify(mirror);
|
|
4317
|
+
}
|
|
4318
|
+
async function resubscribe(channel2, mirror) {
|
|
4319
|
+
if (mirror.pending)
|
|
4320
|
+
return mirror.pending;
|
|
4321
|
+
mirror.pending = (async () => {
|
|
4322
|
+
try {
|
|
4323
|
+
const { state: state3, seq } = await connection2.sendRequest(subscribeType, { channel: channel2 });
|
|
4324
|
+
mirror.state = state3;
|
|
4325
|
+
mirror.seq = seq;
|
|
4326
|
+
} finally {
|
|
4327
|
+
mirror.pending = void 0;
|
|
4328
|
+
}
|
|
4329
|
+
const queued = mirror.queued.splice(0);
|
|
4330
|
+
notify(mirror);
|
|
4331
|
+
for (const patch of queued)
|
|
4332
|
+
apply(mirror, patch);
|
|
4333
|
+
})();
|
|
4334
|
+
return mirror.pending;
|
|
4335
|
+
}
|
|
4336
|
+
connection2.onNotification(patchType, (patch) => {
|
|
4337
|
+
const mirror = mirrors.get(patch.channel);
|
|
4338
|
+
if (!mirror)
|
|
4339
|
+
return;
|
|
4340
|
+
if (mirror.pending)
|
|
4341
|
+
mirror.queued.push(patch);
|
|
4342
|
+
else
|
|
4343
|
+
apply(mirror, patch);
|
|
4344
|
+
});
|
|
4345
|
+
const state2 = {};
|
|
4346
|
+
for (const channel2 of Object.keys(channels)) {
|
|
4347
|
+
state2[channel2] = {
|
|
4348
|
+
get current() {
|
|
4349
|
+
return mirrors.get(channel2)?.state;
|
|
4350
|
+
},
|
|
4351
|
+
async subscribe(listener) {
|
|
4352
|
+
let mirror = mirrors.get(channel2);
|
|
4353
|
+
if (!mirror) {
|
|
4354
|
+
mirror = { listeners: /* @__PURE__ */ new Set(), seq: 0, queued: [] };
|
|
4355
|
+
mirrors.set(channel2, mirror);
|
|
4356
|
+
mirror.listeners.add(listener);
|
|
4357
|
+
try {
|
|
4358
|
+
await resubscribe(channel2, mirror);
|
|
4359
|
+
} catch (error) {
|
|
4360
|
+
mirrors.delete(channel2);
|
|
4361
|
+
throw error;
|
|
4362
|
+
}
|
|
4363
|
+
} else {
|
|
4364
|
+
mirror.listeners.add(listener);
|
|
4365
|
+
if (mirror.pending)
|
|
4366
|
+
await mirror.pending;
|
|
4367
|
+
else
|
|
4368
|
+
listener(mirror.state);
|
|
4369
|
+
}
|
|
4370
|
+
const subscribed = mirror;
|
|
4371
|
+
return () => {
|
|
4372
|
+
subscribed.listeners.delete(listener);
|
|
4373
|
+
if (subscribed.listeners.size > 0 || mirrors.get(channel2) !== subscribed)
|
|
4374
|
+
return;
|
|
4375
|
+
mirrors.delete(channel2);
|
|
4376
|
+
void connection2.sendNotification(unsubscribeType, { channel: channel2 }).catch(() => {
|
|
4377
|
+
});
|
|
4378
|
+
};
|
|
4379
|
+
}
|
|
4380
|
+
};
|
|
4381
|
+
}
|
|
4382
|
+
return state2;
|
|
4383
|
+
}
|
|
4384
|
+
const versionType = new apiExports.RequestType0("$/version");
|
|
4385
|
+
class ProtocolMismatch extends Error {
|
|
4386
|
+
}
|
|
4387
|
+
function serveVersion(connection2, identity) {
|
|
4388
|
+
connection2.onRequest(versionType, () => identity);
|
|
4389
|
+
}
|
|
4390
|
+
async function checkVersion(connection2, identity) {
|
|
4391
|
+
let theirs;
|
|
4392
|
+
try {
|
|
4393
|
+
theirs = await connection2.sendRequest(versionType);
|
|
4394
|
+
} catch (error) {
|
|
4395
|
+
if (error instanceof apiExports.ResponseError && error.code === apiExports.ErrorCodes.MethodNotFound)
|
|
4396
|
+
throw new ProtocolMismatch(`${identity.name} doesn't say which protocol it speaks, so it's older than this client (protocol ${identity.version}) - update it`);
|
|
4397
|
+
throw error;
|
|
4398
|
+
}
|
|
4399
|
+
if (theirs.name !== identity.name)
|
|
4400
|
+
throw new ProtocolMismatch(`expected ${identity.name}, but this is ${theirs.name}`);
|
|
4401
|
+
if (theirs.version !== identity.version)
|
|
4402
|
+
throw new ProtocolMismatch(`${identity.name} speaks protocol ${theirs.version}, but this client speaks ${identity.version} - update whichever is older`);
|
|
4403
|
+
}
|
|
4404
|
+
function mergeSides(a, b) {
|
|
4405
|
+
return {
|
|
4406
|
+
requests: { ...a.requests, ...b.requests },
|
|
4407
|
+
notifications: { ...a.notifications, ...b.notifications }
|
|
4408
|
+
};
|
|
4409
|
+
}
|
|
4410
|
+
function channel(outgoing, incoming) {
|
|
4411
|
+
return { outgoing, incoming };
|
|
4412
|
+
}
|
|
4413
|
+
function peer({ outgoing, incoming }, connection2) {
|
|
4414
|
+
const request2 = {};
|
|
4415
|
+
const notify = {};
|
|
4416
|
+
const onRequest = {};
|
|
4417
|
+
const onNotification = {};
|
|
4418
|
+
for (const [name, definition] of Object.entries(outgoing.requests)) {
|
|
4419
|
+
request2[name] = (params) => connection2.sendRequest(definition.type, params);
|
|
4420
|
+
}
|
|
4421
|
+
for (const [name, definition] of Object.entries(outgoing.notifications)) {
|
|
4422
|
+
notify[name] = (params) => connection2.sendNotification(definition.type, params);
|
|
4423
|
+
}
|
|
4424
|
+
for (const [name, definition] of Object.entries(incoming.requests)) {
|
|
4425
|
+
onRequest[name] = (handler) => connection2.onRequest(definition.type, handler);
|
|
4426
|
+
}
|
|
4427
|
+
for (const [name, definition] of Object.entries(incoming.notifications)) {
|
|
4428
|
+
onNotification[name] = (handler) => connection2.onNotification(definition.type, handler);
|
|
4429
|
+
}
|
|
4430
|
+
return {
|
|
4431
|
+
request: request2,
|
|
4432
|
+
notify,
|
|
4433
|
+
onRequest,
|
|
4434
|
+
onNotification,
|
|
4435
|
+
listen: () => connection2.listen(),
|
|
4436
|
+
dispose: () => connection2.dispose(),
|
|
4437
|
+
onClose: (listener) => {
|
|
4438
|
+
let ended = false;
|
|
4439
|
+
const end = () => {
|
|
4440
|
+
if (ended)
|
|
4441
|
+
return;
|
|
4442
|
+
ended = true;
|
|
4443
|
+
listener();
|
|
4444
|
+
};
|
|
4445
|
+
const closed = connection2.onClose(end);
|
|
4446
|
+
const disposed = connection2.onDispose(end);
|
|
4447
|
+
return { dispose: () => {
|
|
4448
|
+
closed.dispose();
|
|
4449
|
+
disposed.dispose();
|
|
4450
|
+
} };
|
|
4451
|
+
}
|
|
4452
|
+
};
|
|
4453
|
+
}
|
|
4454
|
+
function createRpcClient(channel2, connection2, states, identity) {
|
|
4455
|
+
return {
|
|
4456
|
+
...peer(channel2, connection2),
|
|
4457
|
+
state: mirrorState(connection2, states),
|
|
4458
|
+
checkVersion: async () => {
|
|
4459
|
+
if (identity)
|
|
4460
|
+
await checkVersion(connection2, identity);
|
|
4461
|
+
}
|
|
4462
|
+
};
|
|
4463
|
+
}
|
|
4464
|
+
function createRpcServer(channel2, connection2, store, identity) {
|
|
4465
|
+
if (store)
|
|
4466
|
+
serveStore(connection2, store);
|
|
4467
|
+
if (identity)
|
|
4468
|
+
serveVersion(connection2, identity);
|
|
4469
|
+
const state2 = store ? { get current() {
|
|
4470
|
+
return store.state;
|
|
4471
|
+
}, set: store.set, update: store.update } : {};
|
|
4472
|
+
return { ...peer(channel2, connection2), state: state2 };
|
|
4473
|
+
}
|
|
4474
|
+
function protocol(client, server, state2, identity, name) {
|
|
4475
|
+
function createServer(connection2, ...[store]) {
|
|
4476
|
+
return createRpcServer(server, connection2, store, identity);
|
|
4477
|
+
}
|
|
4478
|
+
return {
|
|
4479
|
+
client,
|
|
4480
|
+
server,
|
|
4481
|
+
state: state2,
|
|
4482
|
+
name,
|
|
4483
|
+
identity,
|
|
4484
|
+
createClient(connection2) {
|
|
4485
|
+
return createRpcClient(client, connection2, state2, identity);
|
|
4486
|
+
},
|
|
4487
|
+
createStore(storage) {
|
|
4488
|
+
return createStore(state2, storage);
|
|
4489
|
+
},
|
|
4490
|
+
createServer,
|
|
4491
|
+
accept(configure, ...store) {
|
|
4492
|
+
return (connection2) => {
|
|
4493
|
+
const rpc = createServer(connection2, ...store);
|
|
4494
|
+
configure?.(rpc);
|
|
4495
|
+
return rpc;
|
|
4496
|
+
};
|
|
4497
|
+
},
|
|
4498
|
+
defineHost({ configure, state: storage }) {
|
|
4499
|
+
return async () => {
|
|
4500
|
+
const store = storage ? await createStore(state2, storage) : void 0;
|
|
4501
|
+
const accept = (connection2) => {
|
|
4502
|
+
const rpc = createServer(connection2, ...[store]);
|
|
4503
|
+
configure?.(rpc, store);
|
|
4504
|
+
return rpc;
|
|
4505
|
+
};
|
|
4506
|
+
return { store, accept };
|
|
4507
|
+
};
|
|
4508
|
+
}
|
|
4509
|
+
};
|
|
4510
|
+
}
|
|
4511
|
+
function side(value) {
|
|
4512
|
+
return {
|
|
4513
|
+
requests: value?.requests ?? {},
|
|
4514
|
+
notifications: value?.notifications ?? {}
|
|
4515
|
+
};
|
|
4516
|
+
}
|
|
4517
|
+
function getSide(spec, key) {
|
|
4518
|
+
return spec[key] ?? side();
|
|
4519
|
+
}
|
|
4520
|
+
function request(method) {
|
|
4521
|
+
return { type: new apiExports.RequestType(method) };
|
|
4522
|
+
}
|
|
4523
|
+
function notification(method) {
|
|
4524
|
+
return { type: new apiExports.NotificationType(method) };
|
|
4525
|
+
}
|
|
4526
|
+
function state(name) {
|
|
4527
|
+
return { name };
|
|
4528
|
+
}
|
|
4529
|
+
function defineProtocol(factory) {
|
|
4530
|
+
const spec = factory({ side, request, notification, state });
|
|
4531
|
+
const clientToServer = getSide(spec, "clientToServer");
|
|
4532
|
+
const serverToClient = getSide(spec, "serverToClient");
|
|
4533
|
+
const eitherToEither = getSide(spec, "eitherToEither");
|
|
4534
|
+
const client = channel(mergeSides(clientToServer, eitherToEither), mergeSides(serverToClient, eitherToEither));
|
|
4535
|
+
const server = channel(mergeSides(serverToClient, eitherToEither), mergeSides(clientToServer, eitherToEither));
|
|
4536
|
+
const identity = spec.name !== void 0 && spec.version !== void 0 ? { name: spec.name, version: spec.version } : void 0;
|
|
4537
|
+
return protocol(client, server, spec.state ?? {}, identity, spec.name);
|
|
4538
|
+
}
|
|
4539
|
+
const cmdlessIPC = defineProtocol(({ side: side2, request: request2, notification: notification2 }) => ({
|
|
4540
|
+
clientToServer: side2({
|
|
4541
|
+
requests: {
|
|
4542
|
+
connect: request2("connect")
|
|
4543
|
+
},
|
|
4544
|
+
notifications: {
|
|
4545
|
+
resolve: notification2("resolve")
|
|
4546
|
+
}
|
|
4547
|
+
})
|
|
4548
|
+
}));
|
|
4549
|
+
const createElectronIPC = forElectronIPC("cmdless:rpc");
|
|
4550
|
+
const cmdlessViewIPC = defineProtocol(({ side: side2, request: request2, notification: notification2 }) => ({
|
|
4551
|
+
clientToServer: side2({
|
|
4552
|
+
requests: {
|
|
4553
|
+
props: request2("view/props")
|
|
4554
|
+
},
|
|
4555
|
+
notifications: {
|
|
4556
|
+
event: notification2("view/event"),
|
|
4557
|
+
close: notification2("view/close"),
|
|
4558
|
+
resize: notification2("view/resize")
|
|
4559
|
+
}
|
|
4560
|
+
}),
|
|
4561
|
+
serverToClient: side2({
|
|
4562
|
+
notifications: {
|
|
4563
|
+
update: notification2("view/update")
|
|
4564
|
+
}
|
|
4565
|
+
})
|
|
4566
|
+
}));
|
|
4567
|
+
const createElectronViewIPC = forElectronIPC("cmdless:view");
|
|
4568
|
+
const ipc = cmdlessIPC.createClient(createElectronIPC(electron.ipcRenderer));
|
|
4569
|
+
const view = cmdlessViewIPC.createClient(createElectronViewIPC(electron.ipcRenderer));
|
|
4570
|
+
async function connect() {
|
|
4571
|
+
const { url, token } = await ipc.request.connect();
|
|
4572
|
+
const socket = new WebSocket(`${url}/?token=${encodeURIComponent(token)}`);
|
|
4573
|
+
await new Promise((resolve, reject) => {
|
|
4574
|
+
socket.addEventListener("open", () => resolve(), { once: true });
|
|
4575
|
+
socket.addEventListener("error", () => reject(new Error("couldn't reach the window's backend")), { once: true });
|
|
4576
|
+
});
|
|
4577
|
+
const early = [];
|
|
4578
|
+
let deliver;
|
|
4579
|
+
socket.addEventListener("message", (event) => {
|
|
4580
|
+
const message = String(event.data);
|
|
4581
|
+
if (deliver) deliver(message);
|
|
4582
|
+
else early.push(message);
|
|
4583
|
+
});
|
|
4584
|
+
return {
|
|
4585
|
+
send: (message) => socket.send(message),
|
|
4586
|
+
onMessage: (listener) => {
|
|
4587
|
+
deliver = listener;
|
|
4588
|
+
for (const message of early.splice(0)) listener(message);
|
|
4589
|
+
},
|
|
4590
|
+
onClose: (listener) => socket.addEventListener("close", (event) => listener(event.code, event.reason)),
|
|
4591
|
+
close: () => socket.close()
|
|
4592
|
+
};
|
|
4593
|
+
}
|
|
4594
|
+
const cmdless = {
|
|
4595
|
+
resolve: (value, exitCode) => ipc.notify.resolve({ value, exitCode }),
|
|
4596
|
+
connect,
|
|
4597
|
+
view
|
|
4598
|
+
};
|
|
4599
|
+
electron.contextBridge.exposeInMainWorld("cmdless", cmdless);
|
|
4600
|
+
ipc.listen();
|
|
4601
|
+
view.listen();
|