@vertexvis/utils 1.0.2-testing.4 → 1.1.0

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/dist/bundle.js CHANGED
@@ -1,4 +1,3 @@
1
- import { __awaiter, __generator, __asyncValues, __assign, __extends, __read, __spreadArray, __values } from 'tslib';
2
1
  import fastDeepEqual from 'fast-deep-equal';
3
2
 
4
3
  /**
@@ -10,17 +9,13 @@ import fastDeepEqual from 'fast-deep-equal';
10
9
  * @param opts Options to pass to `addEventListener`.
11
10
  * @returns A promise that resolves with the first event emitted of `type`.
12
11
  */
13
- function once(target, type, opts) {
14
- return __awaiter(this, void 0, Promise, function () {
15
- return __generator(this, function (_a) {
16
- return [2 /*return*/, new Promise(function (resolve) {
17
- function handler(event) {
18
- target.removeEventListener(type, handler);
19
- resolve(event);
20
- }
21
- target.addEventListener(type, handler, opts);
22
- })];
23
- });
12
+ async function once(target, type, opts) {
13
+ return new Promise((resolve) => {
14
+ function handler(event) {
15
+ target.removeEventListener(type, handler);
16
+ resolve(event);
17
+ }
18
+ target.addEventListener(type, handler, opts);
24
19
  });
25
20
  }
26
21
 
@@ -36,109 +31,51 @@ var eventTargets = /*#__PURE__*/Object.freeze({
36
31
  * @returns A promise that resolves with an array of results yielded by the
37
32
  * generator.
38
33
  */
39
- function asArray(generator) {
40
- return __awaiter(this, void 0, Promise, function () {
41
- var res, next, e_1_1;
42
- var _a, generator_1, generator_1_1;
43
- var _b, e_1, _c, _d;
44
- return __generator(this, function (_e) {
45
- switch (_e.label) {
46
- case 0:
47
- res = [];
48
- _e.label = 1;
49
- case 1:
50
- _e.trys.push([1, 6, 7, 12]);
51
- _a = true, generator_1 = __asyncValues(generator);
52
- _e.label = 2;
53
- case 2: return [4 /*yield*/, generator_1.next()];
54
- case 3:
55
- if (!(generator_1_1 = _e.sent(), _b = generator_1_1.done, !_b)) return [3 /*break*/, 5];
56
- _d = generator_1_1.value;
57
- _a = false;
58
- next = _d;
59
- res.push(next);
60
- _e.label = 4;
61
- case 4:
62
- _a = true;
63
- return [3 /*break*/, 2];
64
- case 5: return [3 /*break*/, 12];
65
- case 6:
66
- e_1_1 = _e.sent();
67
- e_1 = { error: e_1_1 };
68
- return [3 /*break*/, 12];
69
- case 7:
70
- _e.trys.push([7, , 10, 11]);
71
- if (!(!_a && !_b && (_c = generator_1.return))) return [3 /*break*/, 9];
72
- return [4 /*yield*/, _c.call(generator_1)];
73
- case 8:
74
- _e.sent();
75
- _e.label = 9;
76
- case 9: return [3 /*break*/, 11];
77
- case 10:
78
- if (e_1) throw e_1.error;
79
- return [7 /*endfinally*/];
80
- case 11: return [7 /*endfinally*/];
81
- case 12: return [2 /*return*/, res];
82
- }
83
- });
84
- });
85
- }
86
- function delay() {
87
- var args = [];
88
- for (var _i = 0; _i < arguments.length; _i++) {
89
- args[_i] = arguments[_i];
34
+ async function asArray(generator) {
35
+ const res = [];
36
+ for await (const next of generator) {
37
+ res.push(next);
90
38
  }
91
- return __awaiter(this, void 0, Promise, function () {
92
- var ms, promise, delay_1;
93
- return __generator(this, function (_a) {
94
- switch (_a.label) {
95
- case 0:
96
- ms = args[0];
97
- if (!(typeof ms === 'number')) return [3 /*break*/, 4];
98
- promise = args[1];
99
- delay_1 = new Promise(function (resolve) { return setTimeout(resolve, ms); });
100
- if (!(promise != null)) return [3 /*break*/, 2];
101
- return [4 /*yield*/, delay_1];
102
- case 1:
103
- _a.sent();
104
- return [2 /*return*/, promise];
105
- case 2: return [2 /*return*/, delay_1];
106
- case 3: return [3 /*break*/, 5];
107
- case 4: return [2 /*return*/, Promise.reject(new TypeError('First argument to `delay` must be a number'))];
108
- case 5: return [2 /*return*/];
109
- }
110
- });
111
- });
39
+ return res;
112
40
  }
113
- function timeout() {
114
- var args = [];
115
- for (var _i = 0; _i < arguments.length; _i++) {
116
- args[_i] = arguments[_i];
41
+ async function delay(...args) {
42
+ const ms = args[0];
43
+ if (typeof ms === 'number') {
44
+ const promise = args[1];
45
+ const delay = new Promise((resolve) => setTimeout(resolve, ms));
46
+ if (promise != null) {
47
+ await delay;
48
+ return promise;
49
+ }
50
+ else {
51
+ return delay;
52
+ }
117
53
  }
118
- return __awaiter(this, void 0, Promise, function () {
119
- var ms, promise, timer_1, timeout_1, res;
120
- return __generator(this, function (_a) {
121
- switch (_a.label) {
122
- case 0:
123
- ms = args[0];
124
- if (!(typeof ms === 'number')) return [3 /*break*/, 4];
125
- promise = args[1];
126
- timeout_1 = new Promise(function (_, reject) {
127
- timer_1 = setTimeout(function () { return reject(new Error("Promise timed out after ".concat(ms, "ms"))); }, ms);
128
- });
129
- if (!(promise != null)) return [3 /*break*/, 2];
130
- return [4 /*yield*/, Promise.race([promise, timeout_1])];
131
- case 1:
132
- res = _a.sent();
133
- clearTimeout(timer_1);
134
- return [2 /*return*/, res];
135
- case 2: return [2 /*return*/, timeout_1];
136
- case 3: return [3 /*break*/, 5];
137
- case 4: return [2 /*return*/, Promise.reject('First argument to `timeout` must be a number')];
138
- case 5: return [2 /*return*/];
139
- }
54
+ else {
55
+ return Promise.reject(new TypeError('First argument to `delay` must be a number'));
56
+ }
57
+ }
58
+ async function timeout(...args) {
59
+ const ms = args[0];
60
+ if (typeof ms === 'number') {
61
+ const promise = args[1];
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ let timer;
64
+ const timeout = new Promise((_, reject) => {
65
+ timer = setTimeout(() => reject(new Error(`Promise timed out after ${ms}ms`)), ms);
140
66
  });
141
- });
67
+ if (promise != null) {
68
+ const res = await Promise.race([promise, timeout]);
69
+ clearTimeout(timer);
70
+ return res;
71
+ }
72
+ else {
73
+ return timeout;
74
+ }
75
+ }
76
+ else {
77
+ return Promise.reject('First argument to `timeout` must be a number');
78
+ }
142
79
  }
143
80
  /**
144
81
  * Executes and reattempts execution of an asynchronous function if it throws an
@@ -155,43 +92,25 @@ function timeout() {
155
92
  * @returns A promise that resolves with a successful value, or the original
156
93
  * rejected value if the process fails.
157
94
  */
158
- function retry(process_1) {
159
- return __awaiter(this, arguments, Promise, function (process, opts) {
160
- function execute(attempt, process, opts) {
161
- return __awaiter(this, void 0, Promise, function () {
162
- var _a, delaysInMs, _b, maxRetries, delayInMs, e_2;
163
- return __generator(this, function (_c) {
164
- switch (_c.label) {
165
- case 0:
166
- _a = opts.delaysInMs, delaysInMs = _a === void 0 ? [] : _a, _b = opts.maxRetries, maxRetries = _b === void 0 ? 1 : _b;
167
- _c.label = 1;
168
- case 1:
169
- _c.trys.push([1, 4, , 8]);
170
- delayInMs = attempt === 0 || delaysInMs.length === 0
171
- ? 0
172
- : delaysInMs[Math.min(attempt - 1, delaysInMs.length - 1)];
173
- return [4 /*yield*/, delay(delayInMs)];
174
- case 2:
175
- _c.sent();
176
- return [4 /*yield*/, process()];
177
- case 3: return [2 /*return*/, _c.sent()];
178
- case 4:
179
- e_2 = _c.sent();
180
- if (!(attempt < maxRetries)) return [3 /*break*/, 6];
181
- return [4 /*yield*/, execute(attempt + 1, process, opts)];
182
- case 5: return [2 /*return*/, _c.sent()];
183
- case 6: throw e_2;
184
- case 7: return [3 /*break*/, 8];
185
- case 8: return [2 /*return*/];
186
- }
187
- });
188
- });
95
+ async function retry(process, opts = {}) {
96
+ async function execute(attempt, process, opts) {
97
+ const { delaysInMs = [], maxRetries = 1 } = opts;
98
+ try {
99
+ const delayInMs = attempt === 0 || delaysInMs.length === 0
100
+ ? 0
101
+ : delaysInMs[Math.min(attempt - 1, delaysInMs.length - 1)];
102
+ await delay(delayInMs);
103
+ return await process();
189
104
  }
190
- if (opts === void 0) { opts = {}; }
191
- return __generator(this, function (_a) {
192
- return [2 /*return*/, execute(0, process, opts)];
193
- });
194
- });
105
+ catch (e) {
106
+ if (attempt < maxRetries) {
107
+ return await execute(attempt + 1, process, opts);
108
+ }
109
+ else
110
+ throw e;
111
+ }
112
+ }
113
+ return execute(0, process, opts);
195
114
  }
196
115
  /**
197
116
  * Returns a promise that either resolves with the result of `promise`, or a
@@ -205,27 +124,17 @@ function retry(process_1) {
205
124
  * @returns A value indicating if the process was aborted, or the value of
206
125
  * `promise`.
207
126
  */
208
- function abort(signal, promise) {
209
- return __awaiter(this, void 0, Promise, function () {
210
- var controller, pendingAbort, result;
211
- return __generator(this, function (_a) {
212
- switch (_a.label) {
213
- case 0:
214
- controller = new AbortController();
215
- pendingAbort = once(signal, 'abort', { signal: controller.signal });
216
- return [4 /*yield*/, Promise.race([promise, pendingAbort])];
217
- case 1:
218
- result = _a.sent();
219
- if (isAbortEvent(result)) {
220
- return [2 /*return*/, { aborted: true }];
221
- }
222
- else {
223
- controller.abort();
224
- return [2 /*return*/, { aborted: false, result: result }];
225
- }
226
- }
227
- });
228
- });
127
+ async function abort(signal, promise) {
128
+ const controller = new AbortController();
129
+ const pendingAbort = once(signal, 'abort', { signal: controller.signal });
130
+ const result = await Promise.race([promise, pendingAbort]);
131
+ if (isAbortEvent(result)) {
132
+ return { aborted: true };
133
+ }
134
+ else {
135
+ controller.abort();
136
+ return { aborted: false, result };
137
+ }
229
138
  }
230
139
  function isAbortEvent(obj) {
231
140
  if (obj instanceof Event) {
@@ -247,7 +156,7 @@ var async = /*#__PURE__*/Object.freeze({
247
156
  /**
248
157
  * Returns a new `BinaryReader` for an `ArrayBuffer`.
249
158
  */
250
- var fromArrayBuffer = function (buffer) {
159
+ const fromArrayBuffer = (buffer) => {
251
160
  return { offset: 0, data: new DataView(buffer) };
252
161
  };
253
162
  /**
@@ -255,27 +164,27 @@ var fromArrayBuffer = function (buffer) {
255
164
  * reader's offset. The returned reader will have its offset adjusted so it can
256
165
  * be passed to the next helper.
257
166
  */
258
- var readInt32 = function (reader) {
259
- var value = reader.data.getInt32(reader.offset);
260
- return __assign(__assign({}, reader), { offset: reader.offset + 4, value: value });
167
+ const readInt32 = (reader) => {
168
+ const value = reader.data.getInt32(reader.offset);
169
+ return { ...reader, offset: reader.offset + 4, value };
261
170
  };
262
171
  /**
263
172
  * Returns a `BinaryReader` that contains the read UTF-8 string at the given
264
173
  * reader's offset. The returned reader will have its offset adjusted so it can
265
174
  * be passed to the next helper.
266
175
  */
267
- var readUtf8String = function (length, reader) {
268
- var value = String.fromCharCode.apply(null, Array.from(new Uint8Array(reader.data.buffer, reader.offset, length)));
269
- return __assign(__assign({}, reader), { offset: reader.offset + length, value: value });
176
+ const readUtf8String = (length, reader) => {
177
+ const value = String.fromCharCode.apply(null, Array.from(new Uint8Array(reader.data.buffer, reader.offset, length)));
178
+ return { ...reader, offset: reader.offset + length, value };
270
179
  };
271
180
  /**
272
181
  * Returns a `BinaryReader` that contains the a signed `Int8Array` start from
273
182
  * the given reader's offset to the given length. The returned reader will have
274
183
  * its offset adjusted so it can be passed to the next helper.
275
184
  */
276
- var readInt8Array = function (length, reader) {
277
- var value = new Int8Array(reader.data.buffer, reader.offset, length);
278
- return __assign(__assign({}, reader), { offset: reader.offset + length, value: value });
185
+ const readInt8Array = (length, reader) => {
186
+ const value = new Int8Array(reader.data.buffer, reader.offset, length);
187
+ return { ...reader, offset: reader.offset + length, value };
279
188
  };
280
189
  /**
281
190
  * Returns a `BinaryReader` that contains the a signed `Int8Array` sliced from
@@ -283,9 +192,9 @@ var readInt8Array = function (length, reader) {
283
192
  * an offset of zero, so downstream operations will not bee effected by the
284
193
  * previous offset
285
194
  */
286
- var sliceInt8Array = function (length, reader) {
287
- var value = new Int8Array(reader.data.buffer.slice(reader.offset, length + reader.offset));
288
- return __assign(__assign({}, reader), { offset: 0, value: value });
195
+ const sliceInt8Array = (length, reader) => {
196
+ const value = new Int8Array(reader.data.buffer.slice(reader.offset, length + reader.offset));
197
+ return { ...reader, offset: 0, value };
289
198
  };
290
199
 
291
200
  var binaryReader = /*#__PURE__*/Object.freeze({
@@ -297,24 +206,23 @@ var binaryReader = /*#__PURE__*/Object.freeze({
297
206
  sliceInt8Array: sliceInt8Array
298
207
  });
299
208
 
300
- var rgbRegex = /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
301
- var rgbaRegex = /rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(.+)\s*\)/;
302
- var hexRegex = /^(#|0x)?([A-Fa-f0-9]{6})$/;
209
+ const rgbRegex = /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
210
+ const rgbaRegex = /rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(.+)\s*\)/;
211
+ const hexRegex = /^(#|0x)?([A-Fa-f0-9]{6})$/;
303
212
  /**
304
213
  * Constructs a new color with the given red, green, blue and alpha values. If
305
214
  * alpha is undefined, defaults to 1.
306
215
  */
307
- var create$2 = function (r, g, b, a) {
308
- if (a === void 0) { a = 255; }
309
- return { r: r, g: g, b: b, a: a };
216
+ const create$2 = (r, g, b, a = 255) => {
217
+ return { r, g, b, a };
310
218
  };
311
219
  /**
312
220
  * Converts a numeric color value containing red, green and blue values to a
313
221
  * `Color`. The alpha channel will default to fully opaque.
314
222
  */
315
- var fromNumber = function (num) {
223
+ const fromNumber = (num) => {
316
224
  // tslint:disable:no-bitwise
317
- var normalized = num & 0xffffff;
225
+ const normalized = num & 0xffffff;
318
226
  return create$2((normalized >> 16) & 0xff, (normalized >> 8) & 0xff, normalized & 0xff);
319
227
  // tslint:enable:no-bitwise
320
228
  };
@@ -323,8 +231,8 @@ var fromNumber = function (num) {
323
231
  * be parsed. Supports hex strings in the format of `"#00FF00"`, `"0x00FF00"` or
324
232
  * `"00FF00"`.
325
233
  */
326
- var fromHexString = function (str) {
327
- var match = hexRegex.exec(str);
234
+ const fromHexString = (str) => {
235
+ const match = hexRegex.exec(str);
328
236
  if (match != null) {
329
237
  return fromNumber(parseInt(match[2], 16));
330
238
  }
@@ -334,12 +242,12 @@ var fromHexString = function (str) {
334
242
  * supports `rgb(255, 255, 255)`, `rgba(255, 255, 255, 0.5)` or `"#FFFFFF"`.
335
243
  * Returns `undefined` if the color cannot be parsed.
336
244
  */
337
- var fromCss = function (css) {
338
- var rgbMatch = rgbRegex.exec(css);
245
+ const fromCss = (css) => {
246
+ const rgbMatch = rgbRegex.exec(css);
339
247
  if (rgbMatch != null) {
340
248
  return create$2(parseInt(rgbMatch[1]), parseInt(rgbMatch[2]), parseInt(rgbMatch[3]));
341
249
  }
342
- var rgbaMatch = rgbaRegex.exec(css);
250
+ const rgbaMatch = rgbaRegex.exec(css);
343
251
  if (rgbaMatch != null) {
344
252
  return create$2(parseInt(rgbaMatch[1]), parseInt(rgbaMatch[2]), parseInt(rgbaMatch[3]), Math.floor(parseFloat(rgbaMatch[4]) * 255));
345
253
  }
@@ -351,30 +259,30 @@ var fromCss = function (css) {
351
259
  * Converts an array of four values to a `Color`. The sequence of the array is
352
260
  * expected to be `[r, g, b]` or `[r, g, b, a]`.
353
261
  */
354
- var fromArray = function (rgba) {
262
+ const fromArray = (rgba) => {
355
263
  return create$2(rgba[0], rgba[1], rgba[2], rgba[3]);
356
264
  };
357
265
  /**
358
266
  * Returns `true` if the color's alpha channel is 0.
359
267
  */
360
- var isInvisible = function (color) {
268
+ const isInvisible = (color) => {
361
269
  return color.a === 0;
362
270
  };
363
271
  /**
364
272
  * Returns `true` if the alpha channel of this color is fully opaque (255).
365
273
  */
366
- var isOpaque = function (color) {
274
+ const isOpaque = (color) => {
367
275
  return color.a === 255;
368
276
  };
369
277
  /**
370
278
  * Converts a `Color` to a hex string. The returned string will be prefixed with
371
279
  * `#`.
372
280
  */
373
- var toHexString = function (color) {
374
- return "#".concat(componentToHex(color.r)).concat(componentToHex(color.g)).concat(componentToHex(color.b));
281
+ const toHexString = (color) => {
282
+ return `#${componentToHex(color.r)}${componentToHex(color.g)}${componentToHex(color.b)}`;
375
283
  };
376
- var componentToHex = function (num) {
377
- var hex = num.toString(16);
284
+ const componentToHex = (num) => {
285
+ const hex = num.toString(16);
378
286
  return hex.length === 1 ? '0' + hex : hex;
379
287
  };
380
288
 
@@ -463,28 +371,25 @@ var color = /*#__PURE__*/Object.freeze({
463
371
  *
464
372
  * @see {@link ifInvalidThrow} - for throwing errors on invalid input.
465
373
  */
466
- var MapperValidationError = /** @class */ (function (_super) {
467
- __extends(MapperValidationError, _super);
468
- function MapperValidationError(errors) {
469
- var _this = _super.call(this, 'Validation error mapping object.') || this;
470
- _this.errors = errors;
471
- Object.setPrototypeOf(_this, MapperValidationError.prototype);
472
- return _this;
374
+ class MapperValidationError extends Error {
375
+ constructor(errors) {
376
+ super('Validation error mapping object.');
377
+ this.errors = errors;
378
+ Object.setPrototypeOf(this, MapperValidationError.prototype);
473
379
  }
474
- return MapperValidationError;
475
- }(Error));
380
+ }
476
381
  /**
477
382
  * Returns a mapper that asserts the input is not null or not undefined.
478
383
  *
479
384
  * @param name A name to report when invalid.
480
385
  */
481
386
  function required(name) {
482
- return function (input) {
387
+ return (input) => {
483
388
  if (input != null) {
484
389
  return input;
485
390
  }
486
391
  else {
487
- return { errors: ["".concat(name, " is required.")] };
392
+ return { errors: [`${name} is required.`] };
488
393
  }
489
394
  };
490
395
  }
@@ -496,13 +401,13 @@ function required(name) {
496
401
  * @returns A mapper that returns the property's value.
497
402
  */
498
403
  function requiredProp(prop) {
499
- return function (obj) {
500
- var value = obj[prop];
404
+ return (obj) => {
405
+ const value = obj[prop];
501
406
  if (value != null) {
502
407
  return value;
503
408
  }
504
409
  else {
505
- return { errors: ["".concat(String(prop), " is required")] };
410
+ return { errors: [`${String(prop)} is required`] };
506
411
  }
507
412
  };
508
413
  }
@@ -513,7 +418,7 @@ function requiredProp(prop) {
513
418
  * @param mapper A mapping function.
514
419
  */
515
420
  function ifDefined(mapper) {
516
- return function (input) {
421
+ return (input) => {
517
422
  if (input != null) {
518
423
  return mapper(input);
519
424
  }
@@ -528,7 +433,7 @@ function ifDefined(mapper) {
528
433
  * @param prop The property to extract.
529
434
  */
530
435
  function getProp(prop) {
531
- return function (input) {
436
+ return (input) => {
532
437
  return input[prop];
533
438
  };
534
439
  }
@@ -539,8 +444,8 @@ function getProp(prop) {
539
444
  * @param mapper A function that will be invoked with the property's value.
540
445
  */
541
446
  function mapProp(prop, mapper) {
542
- return function (input) {
543
- var value = input[prop];
447
+ return (input) => {
448
+ const value = input[prop];
544
449
  return mapper(value);
545
450
  };
546
451
  }
@@ -564,22 +469,22 @@ function mapRequiredProp(prop, mapper) {
564
469
  * @returns
565
470
  */
566
471
  function mapArray(mapper) {
567
- return function (inputs) {
472
+ return (inputs) => {
568
473
  if (inputs.length > 0) {
569
- var _a = __read(inputs), head = _a[0], tail = _a.slice(1);
570
- var first = mapper(head);
571
- return tail.reduce(function (res, input) {
572
- var value = mapper(input);
474
+ const [head, ...tail] = inputs;
475
+ const first = mapper(head);
476
+ return tail.reduce((res, input) => {
477
+ const value = mapper(input);
573
478
  if (isInvalid(value)) {
574
479
  return isInvalid(res)
575
- ? { errors: __spreadArray(__spreadArray([], __read(res.errors), false), __read(value.errors), false) }
480
+ ? { errors: [...res.errors, ...value.errors] }
576
481
  : value;
577
482
  }
578
483
  else if (isInvalid(res)) {
579
484
  return res;
580
485
  }
581
486
  else {
582
- return __spreadArray(__spreadArray([], __read(res), false), [value], false);
487
+ return [...res, value];
583
488
  }
584
489
  }, isInvalid(first) ? first : [first]);
585
490
  }
@@ -603,8 +508,8 @@ function isInvalid(obj) {
603
508
  * @throws {@link MapperValidationError} If the input is invalid.
604
509
  */
605
510
  function ifInvalidThrow(mapper) {
606
- return function (input) {
607
- var value = mapper(input);
511
+ return (input) => {
512
+ const value = mapper(input);
608
513
  if (isInvalid(value)) {
609
514
  throw new MapperValidationError(value.errors);
610
515
  }
@@ -620,24 +525,20 @@ function ifValidThen(obj, f) {
620
525
  return f(obj);
621
526
  }
622
527
  }
623
- function read() {
624
- var mappers = [];
625
- for (var _i = 0; _i < arguments.length; _i++) {
626
- mappers[_i] = arguments[_i];
627
- }
628
- return function (input) {
629
- return mappers.reduce(function (res, decoder) {
630
- var value = decoder(input);
528
+ function read(...mappers) {
529
+ return (input) => {
530
+ return mappers.reduce((res, decoder) => {
531
+ const value = decoder(input);
631
532
  if (isInvalid(value)) {
632
533
  return isInvalid(res)
633
- ? { errors: __spreadArray(__spreadArray([], __read(res.errors), false), __read(value.errors), false) }
534
+ ? { errors: [...res.errors, ...value.errors] }
634
535
  : value;
635
536
  }
636
537
  else if (isInvalid(res)) {
637
538
  return res;
638
539
  }
639
540
  else {
640
- return __spreadArray(__spreadArray([], __read(res), false), [value], false);
541
+ return [...res, value];
641
542
  }
642
543
  }, []);
643
544
  };
@@ -706,18 +607,14 @@ function read() {
706
607
  * @see {@link read} - a helper function to read and validate input values.
707
608
  */
708
609
  function defineMapper(reader, builder) {
709
- return function (input) {
710
- var values = reader(input);
610
+ return (input) => {
611
+ const values = reader(input);
711
612
  return ifValidThen(values, builder);
712
613
  };
713
614
  }
714
- function compose() {
715
- var decoders = [];
716
- for (var _i = 0; _i < arguments.length; _i++) {
717
- decoders[_i] = arguments[_i];
718
- }
719
- return function (input) {
720
- return decoders.reduce(function (last, decoder) {
615
+ function compose(...decoders) {
616
+ return (input) => {
617
+ return decoders.reduce((last, decoder) => {
721
618
  if (isInvalid(last)) {
722
619
  return last;
723
620
  }
@@ -727,13 +624,9 @@ function compose() {
727
624
  }, input);
728
625
  };
729
626
  }
730
- function pickFirst() {
731
- var decoders = [];
732
- for (var _i = 0; _i < arguments.length; _i++) {
733
- decoders[_i] = arguments[_i];
734
- }
735
- return function (input) {
736
- return decoders.reduce(function (value, decoder) {
627
+ function pickFirst(...decoders) {
628
+ return (input) => {
629
+ return decoders.reduce((value, decoder) => {
737
630
  if (value === undefined) {
738
631
  return decoder(input);
739
632
  }
@@ -763,19 +656,15 @@ var mapper = /*#__PURE__*/Object.freeze({
763
656
  requiredProp: requiredProp
764
657
  });
765
658
 
766
- function defaults() {
767
- var objects = [];
768
- for (var _i = 0; _i < arguments.length; _i++) {
769
- objects[_i] = arguments[_i];
770
- }
771
- var _a = __read(objects), a = _a[0], other = _a.slice(1);
772
- var result = __assign({}, a);
659
+ function defaults(...objects) {
660
+ const [a, ...other] = objects;
661
+ const result = { ...a };
773
662
  if (other.length === 0) {
774
663
  return result;
775
664
  }
776
665
  else if (other.length === 1) {
777
- var b = other[0];
778
- for (var key in b) {
666
+ const b = other[0];
667
+ for (const key in b) {
779
668
  if (result[key] == null) {
780
669
  result[key] = b[key];
781
670
  }
@@ -786,7 +675,7 @@ function defaults() {
786
675
  return result;
787
676
  }
788
677
  else {
789
- return other.reduce(function (result, next) { return defaults(result, next); }, a);
678
+ return other.reduce((result, next) => defaults(result, next), a);
790
679
  }
791
680
  }
792
681
  /**
@@ -812,7 +701,7 @@ function isPlainObject(obj) {
812
701
  if (obj == null || typeof obj !== 'object') {
813
702
  return false;
814
703
  }
815
- var prototype = Object.getPrototypeOf(obj);
704
+ const prototype = Object.getPrototypeOf(obj);
816
705
  return prototype != null && prototype.constructor === Object;
817
706
  }
818
707
  /**
@@ -834,7 +723,7 @@ function isEqual$1(a, b) {
834
723
  }
835
724
  function toPairs(obj) {
836
725
  if (obj != null) {
837
- return Object.keys(obj).map(function (key) { return [key, obj[key]]; });
726
+ return Object.keys(obj).map((key) => [key, obj[key]]);
838
727
  }
839
728
  else {
840
729
  return [];
@@ -842,10 +731,9 @@ function toPairs(obj) {
842
731
  }
843
732
  function fromPairs(pairs) {
844
733
  if (Array.isArray(pairs)) {
845
- return pairs.reduce(function (result, pair) {
846
- var _a;
734
+ return pairs.reduce((result, pair) => {
847
735
  if (pair != null) {
848
- return __assign(__assign({}, result), (_a = {}, _a[pair[0]] = pair[1], _a));
736
+ return { ...result, [pair[0]]: pair[1] };
849
737
  }
850
738
  else {
851
739
  return result;
@@ -870,25 +758,25 @@ var objects = /*#__PURE__*/Object.freeze({
870
758
  /**
871
759
  * Returns a new `Range` with the given start and end points.
872
760
  */
873
- var create$1 = function (start, end) { return ({ start: start, end: end }); };
761
+ const create$1 = (start, end) => ({ start, end });
874
762
  /**
875
763
  * Returns a new `Range` with the start and end points at the given position.
876
764
  */
877
- var at = function (position) { return ({
765
+ const at = (position) => ({
878
766
  start: position,
879
767
  end: position,
880
- }); };
768
+ });
881
769
  /**
882
770
  * Returns a new `Range` with the given start point and length.
883
771
  */
884
- var withLength = function (start, len) { return ({
885
- start: start,
772
+ const withLength = (start, len) => ({
773
+ start,
886
774
  end: start + len - 1,
887
- }); };
775
+ });
888
776
  /**
889
777
  * Returns a range with the start and end points shifted by the given distance.
890
778
  */
891
- var add = function (distance, range) {
779
+ const add = (distance, range) => {
892
780
  return create$1(range.start + distance, range.end + distance);
893
781
  };
894
782
  /**
@@ -896,7 +784,7 @@ var add = function (distance, range) {
896
784
  * of `to`. The function will try to maintain the length of the range, but will
897
785
  * shrink the range if its length is greater than `to`.
898
786
  */
899
- var constrain = function (range, to) {
787
+ const constrain = (range, to) => {
900
788
  if (contains(range, to)) {
901
789
  return range;
902
790
  }
@@ -913,7 +801,7 @@ var constrain = function (range, to) {
913
801
  /**
914
802
  * Checks if the given number or range is contained within another range.
915
803
  */
916
- var contains = function (numOrRange, range) {
804
+ const contains = (numOrRange, range) => {
917
805
  if (typeof numOrRange === 'number') {
918
806
  return range.start <= numOrRange && numOrRange <= range.end;
919
807
  }
@@ -927,7 +815,7 @@ var contains = function (numOrRange, range) {
927
815
  * @param other
928
816
  * @param range
929
817
  */
930
- var intersection = function (other, range) {
818
+ const intersection = (other, range) => {
931
819
  if (intersects(other, range)) {
932
820
  return create$1(Math.max(other.start, range.start), Math.min(other.end, range.end));
933
821
  }
@@ -935,54 +823,54 @@ var intersection = function (other, range) {
935
823
  /**
936
824
  * Returns `true` if `other` intersects with `range`.
937
825
  */
938
- var intersects = function (other, range) {
826
+ const intersects = (other, range) => {
939
827
  return ((other.start <= range.end && other.end >= range.start) ||
940
828
  (range.start <= other.end && range.end >= other.start));
941
829
  };
942
830
  /**
943
831
  * Checks if a range has the same starting point as another range.
944
832
  */
945
- var isAt = function (other, range) {
833
+ const isAt = (other, range) => {
946
834
  return other.start === range.start;
947
835
  };
948
836
  /**
949
837
  * Returns `true` if a range's start point is after the starting point of
950
838
  * another range.
951
839
  */
952
- var isAfter = function (other, range) {
840
+ const isAfter = (other, range) => {
953
841
  return other.start > range.start;
954
842
  };
955
843
  /**
956
844
  * Returns `true` if a range start at or is after another range.
957
845
  */
958
- var isAtOrAfter = function (other, range) {
846
+ const isAtOrAfter = (other, range) => {
959
847
  return isAt(other, range) || isAfter(other, range);
960
848
  };
961
849
  /**
962
850
  * Returns `true` if a range's starting point is before another range's starting
963
851
  * point.
964
852
  */
965
- var isBefore = function (other, range) {
853
+ const isBefore = (other, range) => {
966
854
  return other.start < range.start;
967
855
  };
968
856
  /**
969
857
  * Returns `true` if a range's starting point is at or before another range's
970
858
  * starting point.
971
859
  */
972
- var isAtOrBefore = function (other, range) {
860
+ const isAtOrBefore = (other, range) => {
973
861
  return isAt(other, range) || isBefore(other, range);
974
862
  };
975
863
  /**
976
864
  * Returns the length of a range.
977
865
  */
978
- var length = function (range) {
866
+ const length = (range) => {
979
867
  return range.end - range.start + 1;
980
868
  };
981
869
  /**
982
870
  * Returns a `Range` with its start and end points subtracted by the given
983
871
  * distance.
984
872
  */
985
- var subtract = function (distance, range) {
873
+ const subtract = (distance, range) => {
986
874
  return add(distance * -1, range);
987
875
  };
988
876
  /**
@@ -993,7 +881,7 @@ var subtract = function (distance, range) {
993
881
  * If `other` does not intersect with `to`, then the range cannot be truncated
994
882
  * and `undefined` is returned.
995
883
  */
996
- var truncate = function (other, to) {
884
+ const truncate = (other, to) => {
997
885
  if (intersects(to, other)) {
998
886
  return create$1(Math.max(other.start, to.start), Math.min(other.end, to.end));
999
887
  }
@@ -1020,22 +908,11 @@ var range = /*#__PURE__*/Object.freeze({
1020
908
  });
1021
909
 
1022
910
  function diffSet(a, b) {
1023
- var e_1, _a;
1024
- var res = new Set();
1025
- try {
1026
- for (var b_1 = __values(b), b_1_1 = b_1.next(); !b_1_1.done; b_1_1 = b_1.next()) {
1027
- var item = b_1_1.value;
1028
- if (!a.has(item)) {
1029
- res.add(item);
1030
- }
1031
- }
1032
- }
1033
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1034
- finally {
1035
- try {
1036
- if (b_1_1 && !b_1_1.done && (_a = b_1.return)) _a.call(b_1);
911
+ const res = new Set();
912
+ for (const item of b) {
913
+ if (!a.has(item)) {
914
+ res.add(item);
1037
915
  }
1038
- finally { if (e_1) throw e_1.error; }
1039
916
  }
1040
917
  return res;
1041
918
  }
@@ -1045,9 +922,9 @@ var sets = /*#__PURE__*/Object.freeze({
1045
922
  diffSet: diffSet
1046
923
  });
1047
924
 
1048
- var trimStartRegex = /^\W+/;
1049
- var trimEndRegex = /\W+$/;
1050
- var trimStartAndEndRegex = /^\W+|\W+$/g;
925
+ const trimStartRegex = /^\W+/;
926
+ const trimEndRegex = /\W+$/;
927
+ const trimStartAndEndRegex = /^\W+|\W+$/g;
1051
928
  function trimStart(str) {
1052
929
  return str.replace(trimStartRegex, '');
1053
930
  }
@@ -1068,7 +945,7 @@ var strings = /*#__PURE__*/Object.freeze({
1068
945
  /**
1069
946
  * A comparator that sorts a number or string in ascending order.
1070
947
  */
1071
- var asc = function (a, b) {
948
+ const asc = (a, b) => {
1072
949
  if (a < b) {
1073
950
  return -1;
1074
951
  }
@@ -1083,12 +960,8 @@ var asc = function (a, b) {
1083
960
  * A comparator that plucks the first element of an array and passes that value
1084
961
  * to the given comparator for sorting.
1085
962
  */
1086
- var head = function (comparator) {
1087
- return function (_a, _b) {
1088
- var _c = __read(_a, 1), a = _c[0];
1089
- var _d = __read(_b, 1), b = _d[0];
1090
- return comparator(a, b);
1091
- };
963
+ const head = (comparator) => {
964
+ return ([a], [b]) => comparator(a, b);
1092
965
  };
1093
966
 
1094
967
  /**
@@ -1099,9 +972,9 @@ var head = function (comparator) {
1099
972
  *
1100
973
  * @param uri The URI to parse.
1101
974
  */
1102
- var parse = function (uri) {
1103
- var regex = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
1104
- var match = regex.exec(uri);
975
+ const parse = (uri) => {
976
+ const regex = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
977
+ const match = regex.exec(uri);
1105
978
  if (match != null) {
1106
979
  return {
1107
980
  scheme: match[2],
@@ -1120,54 +993,57 @@ var parse = function (uri) {
1120
993
  * @param base
1121
994
  * @param params
1122
995
  */
1123
- var parseAndAddParams = function (baseStr, params) {
1124
- var base = parse(baseStr);
996
+ const parseAndAddParams = (baseStr, params) => {
997
+ const base = parse(baseStr);
1125
998
  return params ? addQueryParams(params, base) : base;
1126
999
  };
1127
- var isEqual = function (a, b) {
1128
- var queryA = JSON.stringify(sortByQueryName(queryAsArray(a)));
1129
- var queryB = JSON.stringify(sortByQueryName(queryAsArray(b)));
1000
+ const isEqual = (a, b) => {
1001
+ const queryA = JSON.stringify(sortByQueryName(queryAsArray(a)));
1002
+ const queryB = JSON.stringify(sortByQueryName(queryAsArray(b)));
1130
1003
  return (a.scheme === b.scheme &&
1131
1004
  a.authority === b.authority &&
1132
1005
  a.path === b.path &&
1133
1006
  a.fragment === b.fragment &&
1134
1007
  queryA === queryB);
1135
1008
  };
1136
- var replacePath = function (path, uri) {
1137
- var pathWithForwardSlash = path[0] === '/' ? path : "/".concat(path);
1138
- return __assign(__assign({}, uri), { path: pathWithForwardSlash });
1009
+ const replacePath = (path, uri) => {
1010
+ const pathWithForwardSlash = path[0] === '/' ? path : `/${path}`;
1011
+ return { ...uri, path: pathWithForwardSlash };
1139
1012
  };
1140
- var pathAsArray = function (uri) {
1013
+ const pathAsArray = (uri) => {
1141
1014
  return uri.path != null ? sanitizePath(uri.path.split('/')) : [];
1142
1015
  };
1143
- var appendPath = function (path, uri) {
1144
- var beforeParts = pathAsArray(uri);
1145
- var afterParts = sanitizePath(path.split('/'));
1016
+ const appendPath = (path, uri) => {
1017
+ const beforeParts = pathAsArray(uri);
1018
+ const afterParts = sanitizePath(path.split('/'));
1146
1019
  return replacePath(beforeParts.concat(afterParts).join('/'), uri);
1147
1020
  };
1148
- var addQueryString = function (query, uri) {
1149
- var queryArray = stringAsQueryArray(query);
1021
+ const addQueryString = (query, uri) => {
1022
+ const queryArray = stringAsQueryArray(query);
1150
1023
  return addQueryEntries(queryArray, uri);
1151
1024
  };
1152
- var addQueryEntry = function (query, uri) {
1025
+ const addQueryEntry = (query, uri) => {
1153
1026
  if (query[1] != null) {
1154
- var newQuery = __spreadArray(__spreadArray([], __read(queryAsArray(uri)), false), [query], false);
1155
- return __assign(__assign({}, uri), { query: newQuery
1156
- .map(function (entry) { return entry.map(encodeURIComponent).join('='); })
1157
- .join('&') });
1027
+ const newQuery = [...queryAsArray(uri), query];
1028
+ return {
1029
+ ...uri,
1030
+ query: newQuery
1031
+ .map((entry) => entry.map(encodeURIComponent).join('='))
1032
+ .join('&'),
1033
+ };
1158
1034
  }
1159
1035
  else {
1160
1036
  return uri;
1161
1037
  }
1162
1038
  };
1163
- var addQueryEntries = function (entries, uri) {
1164
- return entries.reduce(function (result, entry) { return addQueryEntry(entry, result); }, uri);
1039
+ const addQueryEntries = (entries, uri) => {
1040
+ return entries.reduce((result, entry) => addQueryEntry(entry, result), uri);
1165
1041
  };
1166
- var addQueryParams = function (params, uri) {
1167
- return mapAsEntries(params).reduce(function (result, entry) { return addQueryEntry(entry, result); }, uri);
1042
+ const addQueryParams = (params, uri) => {
1043
+ return mapAsEntries(params).reduce((result, entry) => addQueryEntry(entry, result), uri);
1168
1044
  };
1169
- var replaceFragment = function (fragment, uri) {
1170
- return __assign(__assign({}, uri), { fragment: fragment });
1045
+ const replaceFragment = (fragment, uri) => {
1046
+ return { ...uri, fragment };
1171
1047
  };
1172
1048
  /**
1173
1049
  * Return an array of name/value pairs representing the query string of a URI.
@@ -1176,7 +1052,7 @@ var replaceFragment = function (fragment, uri) {
1176
1052
  *
1177
1053
  * @param uri A URI to return the query string for.
1178
1054
  */
1179
- var queryAsArray = function (uri) {
1055
+ const queryAsArray = (uri) => {
1180
1056
  if (uri.query != null) {
1181
1057
  return stringAsQueryArray(uri.query);
1182
1058
  }
@@ -1184,12 +1060,10 @@ var queryAsArray = function (uri) {
1184
1060
  return [];
1185
1061
  }
1186
1062
  };
1187
- var stringAsQueryArray = function (queryString) {
1063
+ const stringAsQueryArray = (queryString) => {
1188
1064
  return queryString
1189
1065
  .split('&')
1190
- .map(function (param) {
1191
- return param.split('=').map(function (value) { return decodeURIComponent(value); });
1192
- });
1066
+ .map((param) => param.split('=').map((value) => decodeURIComponent(value)));
1193
1067
  };
1194
1068
  /**
1195
1069
  * Return a map containing a URI's query string names and their values. The
@@ -1200,41 +1074,39 @@ var stringAsQueryArray = function (queryString) {
1200
1074
  *
1201
1075
  * @param uri A URI to return the query string for.
1202
1076
  */
1203
- var queryAsMap = function (uri) {
1204
- return queryAsArray(uri).reduce(function (map, _a) {
1205
- var _b;
1206
- var _c = __read(_a, 2), name = _c[0], value = _c[1];
1207
- return __assign(__assign({}, map), (_b = {}, _b[name] = value, _b));
1077
+ const queryAsMap = (uri) => {
1078
+ return queryAsArray(uri).reduce((map, [name, value]) => {
1079
+ return { ...map, [name]: value };
1208
1080
  }, {});
1209
1081
  };
1210
- var toString = function (uri) {
1211
- var result = '';
1082
+ const toString = (uri) => {
1083
+ let result = '';
1212
1084
  if (uri.scheme != null && uri.scheme.length > 0) {
1213
- result = "".concat(uri.scheme, ":");
1085
+ result = `${uri.scheme}:`;
1214
1086
  }
1215
1087
  if (uri.authority != null && uri.authority.length > 0) {
1216
- result += "//".concat(uri.authority);
1088
+ result += `//${uri.authority}`;
1217
1089
  }
1218
1090
  result += uri.path;
1219
1091
  if (uri.query != null && uri.query.length > 0) {
1220
- result += "?".concat(uri.query);
1092
+ result += `?${uri.query}`;
1221
1093
  }
1222
1094
  if (uri.fragment != null && uri.fragment.length > 0) {
1223
- result += "#".concat(uri.fragment);
1095
+ result += `#${uri.fragment}`;
1224
1096
  }
1225
1097
  return result;
1226
1098
  };
1227
- var sanitizePath = function (path) {
1228
- return path.filter(function (segment) { return segment.length > 0; });
1099
+ const sanitizePath = (path) => {
1100
+ return path.filter((segment) => segment.length > 0);
1229
1101
  };
1230
- var mapAsEntries = function (map) {
1231
- var entries = [];
1232
- for (var key in map) {
1102
+ const mapAsEntries = (map) => {
1103
+ const entries = [];
1104
+ for (const key in map) {
1233
1105
  entries.push([key, map[key]]);
1234
1106
  }
1235
1107
  return entries;
1236
1108
  };
1237
- var sortByQueryName = function (entries) {
1109
+ const sortByQueryName = (entries) => {
1238
1110
  return entries.concat().sort(head(asc));
1239
1111
  };
1240
1112
  /* eslint-enable @typescript-eslint/no-explicit-any */
@@ -1262,25 +1134,25 @@ function create() {
1262
1134
  }
1263
1135
  function fromMsbLsb(msb, lsb) {
1264
1136
  function digits(val, ds) {
1265
- var hi = BigInt(1) << (ds * BigInt(4));
1137
+ const hi = BigInt(1) << (ds * BigInt(4));
1266
1138
  return (hi | (val & (hi - BigInt(1)))).toString(16).substring(1);
1267
1139
  }
1268
- var msbB = typeof msb === 'string' ? BigInt(msb) : msb;
1269
- var lsbB = typeof lsb === 'string' ? BigInt(lsb) : lsb;
1270
- var sec1 = digits(msbB >> BigInt(32), BigInt(8));
1271
- var sec2 = digits(msbB >> BigInt(16), BigInt(4));
1272
- var sec3 = digits(msbB, BigInt(4));
1273
- var sec4 = digits(lsbB >> BigInt(48), BigInt(4));
1274
- var sec5 = digits(lsbB, BigInt(12));
1275
- return "".concat(sec1, "-").concat(sec2, "-").concat(sec3, "-").concat(sec4, "-").concat(sec5);
1140
+ const msbB = typeof msb === 'string' ? BigInt(msb) : msb;
1141
+ const lsbB = typeof lsb === 'string' ? BigInt(lsb) : lsb;
1142
+ const sec1 = digits(msbB >> BigInt(32), BigInt(8));
1143
+ const sec2 = digits(msbB >> BigInt(16), BigInt(4));
1144
+ const sec3 = digits(msbB, BigInt(4));
1145
+ const sec4 = digits(lsbB >> BigInt(48), BigInt(4));
1146
+ const sec5 = digits(lsbB, BigInt(12));
1147
+ return `${sec1}-${sec2}-${sec3}-${sec4}-${sec5}`;
1276
1148
  }
1277
1149
  function toMsbLsb(id) {
1278
- var _a = __read(id.split('-'), 5), c1 = _a[0], c2 = _a[1], c3 = _a[2], c4 = _a[3], c5 = _a[4];
1150
+ const [c1, c2, c3, c4, c5] = id.split('-');
1279
1151
  if (c1 == null || c2 == null || c3 == null || c4 == null || c5 == null) {
1280
- throw new Error("Invalid UUID string ".concat(id));
1152
+ throw new Error(`Invalid UUID string ${id}`);
1281
1153
  }
1282
- var msb = BigInt.asIntN(64, BigInt("0x".concat(c1 + c2 + c3)));
1283
- var lsb = BigInt.asIntN(64, BigInt("0x".concat(c4 + c5)));
1154
+ const msb = BigInt.asIntN(64, BigInt(`0x${c1 + c2 + c3}`));
1155
+ const lsb = BigInt.asIntN(64, BigInt(`0x${c4 + c5}`));
1284
1156
  return { msb: msb.toString(), lsb: lsb.toString() };
1285
1157
  }
1286
1158
 
@@ -1291,69 +1163,56 @@ var uuid = /*#__PURE__*/Object.freeze({
1291
1163
  toMsbLsb: toMsbLsb
1292
1164
  });
1293
1165
 
1294
- var EventDispatcher = /** @class */ (function () {
1295
- function EventDispatcher() {
1166
+ class EventDispatcher {
1167
+ constructor() {
1296
1168
  this.listeners = [];
1297
1169
  }
1298
- EventDispatcher.prototype.on = function (listener, opts) {
1299
- var _this = this;
1170
+ on(listener, opts = {}) {
1300
1171
  var _a;
1301
- if (opts === void 0) { opts = {}; }
1302
1172
  this.listeners.push(listener);
1303
- var controller = new AbortController();
1304
- controller.signal.addEventListener('abort', function () { return _this.off(listener); });
1305
- (_a = opts.abort) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', function () { return controller.abort(); });
1306
- return { dispose: function () { return controller.abort(); } };
1307
- };
1308
- EventDispatcher.prototype.once = function (opts) {
1309
- var _this = this;
1310
- if (opts === void 0) { opts = {}; }
1311
- return new Promise(function (resolve) {
1312
- var subscription = _this.on(function (event) {
1173
+ const controller = new AbortController();
1174
+ controller.signal.addEventListener('abort', () => this.off(listener));
1175
+ (_a = opts.abort) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => controller.abort());
1176
+ return { dispose: () => controller.abort() };
1177
+ }
1178
+ once(opts = {}) {
1179
+ return new Promise((resolve) => {
1180
+ const subscription = this.on((event) => {
1313
1181
  subscription.dispose();
1314
1182
  resolve(event);
1315
1183
  }, opts);
1316
1184
  });
1317
- };
1318
- EventDispatcher.prototype.onceWhen = function (predicate_1) {
1319
- return __awaiter(this, arguments, Promise, function (predicate, opts) {
1320
- var controller;
1321
- var _this = this;
1322
- var _a;
1323
- if (opts === void 0) { opts = {}; }
1324
- return __generator(this, function (_b) {
1325
- controller = new AbortController();
1326
- (_a = opts.abort) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', function () { return controller.abort(); });
1327
- return [2 /*return*/, new Promise(function (resolve) {
1328
- _this.when(predicate, function (event) {
1329
- if (predicate(event)) {
1330
- controller.abort();
1331
- resolve(event);
1332
- }
1333
- }, __assign(__assign({}, opts), { abort: controller.signal }));
1334
- })];
1335
- });
1185
+ }
1186
+ async onceWhen(predicate, opts = {}) {
1187
+ var _a;
1188
+ const controller = new AbortController();
1189
+ (_a = opts.abort) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', () => controller.abort());
1190
+ return new Promise((resolve) => {
1191
+ this.when(predicate, (event) => {
1192
+ if (predicate(event)) {
1193
+ controller.abort();
1194
+ resolve(event);
1195
+ }
1196
+ }, { ...opts, abort: controller.signal });
1336
1197
  });
1337
- };
1338
- EventDispatcher.prototype.when = function (predicate, listener, opts) {
1339
- if (opts === void 0) { opts = {}; }
1340
- return this.on(function (event) {
1198
+ }
1199
+ when(predicate, listener, opts = {}) {
1200
+ return this.on((event) => {
1341
1201
  if (predicate(event)) {
1342
1202
  listener(event);
1343
1203
  }
1344
1204
  }, opts);
1345
- };
1346
- EventDispatcher.prototype.off = function (listener) {
1347
- var index = this.listeners.indexOf(listener);
1205
+ }
1206
+ off(listener) {
1207
+ const index = this.listeners.indexOf(listener);
1348
1208
  if (index !== -1) {
1349
1209
  this.listeners.splice(index, 1);
1350
1210
  }
1351
- };
1352
- EventDispatcher.prototype.emit = function (event) {
1353
- this.listeners.forEach(function (listener) { return listener(event); });
1354
- };
1355
- return EventDispatcher;
1356
- }());
1211
+ }
1212
+ emit(event) {
1213
+ this.listeners.forEach((listener) => listener(event));
1214
+ }
1215
+ }
1357
1216
 
1358
1217
  export { async as Async, binaryReader as BinaryReader, color as Color, EventDispatcher, eventTargets as EventTargets, mapper as Mapper, objects as Objects, range as Range, sets as Sets, strings as Strings, uuid as UUID, uri as Uri };
1359
1218
  //# sourceMappingURL=bundle.js.map