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