@vertexvis/utils 1.0.2-testing.4 → 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 +282 -423
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +282 -423
- package/dist/browser.js.map +1 -1
- package/dist/bundle.cjs +282 -423
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.js +282 -423
- package/dist/bundle.js.map +1 -1
- package/package.json +6 -6
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
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
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
return
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
return
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
return
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
return
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
310
|
-
|
|
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
|
-
|
|
225
|
+
const fromNumber = (num) => {
|
|
318
226
|
// tslint:disable:no-bitwise
|
|
319
|
-
|
|
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
|
-
|
|
329
|
-
|
|
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
|
-
|
|
340
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
376
|
-
return
|
|
283
|
+
const toHexString = (color) => {
|
|
284
|
+
return `#${componentToHex(color.r)}${componentToHex(color.g)}${componentToHex(color.b)}`;
|
|
377
285
|
};
|
|
378
|
-
|
|
379
|
-
|
|
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
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
-
|
|
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
|
|
389
|
+
return (input) => {
|
|
485
390
|
if (input != null) {
|
|
486
391
|
return input;
|
|
487
392
|
}
|
|
488
393
|
else {
|
|
489
|
-
return { errors: [
|
|
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
|
|
502
|
-
|
|
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: [
|
|
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
|
|
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
|
|
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
|
|
545
|
-
|
|
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
|
|
474
|
+
return (inputs) => {
|
|
570
475
|
if (inputs.length > 0) {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
return tail.reduce(
|
|
574
|
-
|
|
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:
|
|
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
|
|
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
|
|
609
|
-
|
|
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
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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:
|
|
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
|
|
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
|
|
712
|
-
|
|
612
|
+
return (input) => {
|
|
613
|
+
const values = reader(input);
|
|
713
614
|
return ifValidThen(values, builder);
|
|
714
615
|
};
|
|
715
616
|
}
|
|
716
|
-
function compose() {
|
|
717
|
-
|
|
718
|
-
|
|
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
|
-
|
|
734
|
-
|
|
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
|
-
|
|
770
|
-
|
|
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
|
-
|
|
780
|
-
for (
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
848
|
-
var _a;
|
|
736
|
+
return pairs.reduce((result, pair) => {
|
|
849
737
|
if (pair != null) {
|
|
850
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
887
|
-
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
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
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1089
|
-
return
|
|
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
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
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
|
-
|
|
1126
|
-
|
|
998
|
+
const parseAndAddParams = (baseStr, params) => {
|
|
999
|
+
const base = parse(baseStr);
|
|
1127
1000
|
return params ? addQueryParams(params, base) : base;
|
|
1128
1001
|
};
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
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
|
-
|
|
1139
|
-
|
|
1140
|
-
return
|
|
1011
|
+
const replacePath = (path, uri) => {
|
|
1012
|
+
const pathWithForwardSlash = path[0] === '/' ? path : `/${path}`;
|
|
1013
|
+
return { ...uri, path: pathWithForwardSlash };
|
|
1141
1014
|
};
|
|
1142
|
-
|
|
1015
|
+
const pathAsArray = (uri) => {
|
|
1143
1016
|
return uri.path != null ? sanitizePath(uri.path.split('/')) : [];
|
|
1144
1017
|
};
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
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
|
-
|
|
1151
|
-
|
|
1023
|
+
const addQueryString = (query, uri) => {
|
|
1024
|
+
const queryArray = stringAsQueryArray(query);
|
|
1152
1025
|
return addQueryEntries(queryArray, uri);
|
|
1153
1026
|
};
|
|
1154
|
-
|
|
1027
|
+
const addQueryEntry = (query, uri) => {
|
|
1155
1028
|
if (query[1] != null) {
|
|
1156
|
-
|
|
1157
|
-
return
|
|
1158
|
-
|
|
1159
|
-
|
|
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
|
-
|
|
1166
|
-
return entries.reduce(
|
|
1041
|
+
const addQueryEntries = (entries, uri) => {
|
|
1042
|
+
return entries.reduce((result, entry) => addQueryEntry(entry, result), uri);
|
|
1167
1043
|
};
|
|
1168
|
-
|
|
1169
|
-
return mapAsEntries(params).reduce(
|
|
1044
|
+
const addQueryParams = (params, uri) => {
|
|
1045
|
+
return mapAsEntries(params).reduce((result, entry) => addQueryEntry(entry, result), uri);
|
|
1170
1046
|
};
|
|
1171
|
-
|
|
1172
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
1065
|
+
const stringAsQueryArray = (queryString) => {
|
|
1190
1066
|
return queryString
|
|
1191
1067
|
.split('&')
|
|
1192
|
-
.map(
|
|
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
|
-
|
|
1206
|
-
return queryAsArray(uri).reduce(
|
|
1207
|
-
|
|
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
|
-
|
|
1213
|
-
|
|
1084
|
+
const toString = (uri) => {
|
|
1085
|
+
let result = '';
|
|
1214
1086
|
if (uri.scheme != null && uri.scheme.length > 0) {
|
|
1215
|
-
result =
|
|
1087
|
+
result = `${uri.scheme}:`;
|
|
1216
1088
|
}
|
|
1217
1089
|
if (uri.authority != null && uri.authority.length > 0) {
|
|
1218
|
-
result +=
|
|
1090
|
+
result += `//${uri.authority}`;
|
|
1219
1091
|
}
|
|
1220
1092
|
result += uri.path;
|
|
1221
1093
|
if (uri.query != null && uri.query.length > 0) {
|
|
1222
|
-
result +=
|
|
1094
|
+
result += `?${uri.query}`;
|
|
1223
1095
|
}
|
|
1224
1096
|
if (uri.fragment != null && uri.fragment.length > 0) {
|
|
1225
|
-
result +=
|
|
1097
|
+
result += `#${uri.fragment}`;
|
|
1226
1098
|
}
|
|
1227
1099
|
return result;
|
|
1228
1100
|
};
|
|
1229
|
-
|
|
1230
|
-
return path.filter(
|
|
1101
|
+
const sanitizePath = (path) => {
|
|
1102
|
+
return path.filter((segment) => segment.length > 0);
|
|
1231
1103
|
};
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
1139
|
+
const hi = BigInt(1) << (ds * BigInt(4));
|
|
1268
1140
|
return (hi | (val & (hi - BigInt(1)))).toString(16).substring(1);
|
|
1269
1141
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
return
|
|
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
|
-
|
|
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(
|
|
1154
|
+
throw new Error(`Invalid UUID string ${id}`);
|
|
1283
1155
|
}
|
|
1284
|
-
|
|
1285
|
-
|
|
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
|
-
|
|
1297
|
-
|
|
1168
|
+
class EventDispatcher {
|
|
1169
|
+
constructor() {
|
|
1298
1170
|
this.listeners = [];
|
|
1299
1171
|
}
|
|
1300
|
-
|
|
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
|
-
|
|
1306
|
-
controller.signal.addEventListener('abort',
|
|
1307
|
-
(_a = opts.abort) === null || _a === void 0 ? void 0 : _a.addEventListener('abort',
|
|
1308
|
-
return { dispose:
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
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
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
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
|
-
|
|
1341
|
-
|
|
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
|
-
|
|
1349
|
-
|
|
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
|
-
|
|
1355
|
-
this.listeners.forEach(
|
|
1356
|
-
}
|
|
1357
|
-
|
|
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;
|