@naturalcycles/js-lib 14.235.0 → 14.237.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/datetime/localDate.d.ts +2 -1
- package/dist/datetime/localDate.js +7 -0
- package/dist/datetime/localTime.d.ts +67 -26
- package/dist/datetime/localTime.js +99 -33
- package/dist/datetime/wallTime.d.ts +33 -0
- package/dist/datetime/wallTime.js +48 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.js +1 -5
- package/dist-esm/array/range.js +4 -7
- package/dist-esm/datetime/localDate.js +7 -0
- package/dist-esm/datetime/localTime.js +105 -35
- package/dist-esm/datetime/wallTime.js +44 -0
- package/dist-esm/decorators/asyncMemo.decorator.js +1 -1
- package/dist-esm/decorators/createPromiseDecorator.js +10 -5
- package/dist-esm/decorators/debounce.js +6 -1
- package/dist-esm/decorators/memo.decorator.js +1 -1
- package/dist-esm/define.js +14 -2
- package/dist-esm/enum.util.js +1 -2
- package/dist-esm/error/assert.js +12 -3
- package/dist-esm/error/error.util.js +13 -8
- package/dist-esm/error/tryCatch.js +1 -1
- package/dist-esm/http/fetcher.js +74 -41
- package/dist-esm/index.js +1 -5
- package/dist-esm/iter/asyncIterable2.js +37 -122
- package/dist-esm/json-schema/jsonSchema.util.js +2 -3
- package/dist-esm/json-schema/jsonSchemaBuilder.js +1 -2
- package/dist-esm/math/math.util.js +1 -1
- package/dist-esm/object/object.util.js +4 -5
- package/dist-esm/polyfill.js +2 -3
- package/dist-esm/promise/abortable.js +1 -2
- package/dist-esm/promise/pMap.js +3 -3
- package/dist-esm/promise/pQueue.js +7 -2
- package/dist-esm/string/json.util.js +3 -3
- package/dist-esm/string/readingTime.js +4 -1
- package/dist-esm/string/safeJsonStringify.js +2 -2
- package/dist-esm/string/stringify.js +1 -1
- package/dist-esm/web.js +2 -4
- package/dist-esm/zod/zod.util.js +1 -2
- package/package.json +1 -1
- package/src/datetime/localDate.ts +9 -1
- package/src/datetime/localTime.ts +110 -37
- package/src/datetime/wallTime.ts +56 -0
- package/src/index.ts +1 -5
package/dist-esm/http/fetcher.js
CHANGED
|
@@ -41,19 +41,31 @@ export class Fetcher {
|
|
|
41
41
|
for (const method of HTTP_METHODS) {
|
|
42
42
|
const m = method.toLowerCase();
|
|
43
43
|
this[`${m}Void`] = async (url, opt) => {
|
|
44
|
-
return await this.fetch(
|
|
45
|
-
|
|
44
|
+
return await this.fetch({
|
|
45
|
+
url,
|
|
46
|
+
method,
|
|
47
|
+
responseType: 'void',
|
|
48
|
+
...opt,
|
|
49
|
+
});
|
|
46
50
|
};
|
|
47
51
|
if (method === 'HEAD')
|
|
48
52
|
return // responseType=text
|
|
49
53
|
;
|
|
50
54
|
this[`${m}Text`] = async (url, opt) => {
|
|
51
|
-
return await this.fetch(
|
|
52
|
-
|
|
55
|
+
return await this.fetch({
|
|
56
|
+
url,
|
|
57
|
+
method,
|
|
58
|
+
responseType: 'text',
|
|
59
|
+
...opt,
|
|
60
|
+
});
|
|
53
61
|
};
|
|
54
62
|
this[m] = async (url, opt) => {
|
|
55
|
-
return await this.fetch(
|
|
56
|
-
|
|
63
|
+
return await this.fetch({
|
|
64
|
+
url,
|
|
65
|
+
method,
|
|
66
|
+
responseType: 'json',
|
|
67
|
+
...opt,
|
|
68
|
+
});
|
|
57
69
|
};
|
|
58
70
|
}
|
|
59
71
|
}
|
|
@@ -89,7 +101,11 @@ export class Fetcher {
|
|
|
89
101
|
* https://css-tricks.com/web-streams-everywhere-and-fetch-for-node-js/
|
|
90
102
|
*/
|
|
91
103
|
async getReadableStream(url, opt) {
|
|
92
|
-
return await this.fetch(
|
|
104
|
+
return await this.fetch({
|
|
105
|
+
url,
|
|
106
|
+
responseType: 'readableStream',
|
|
107
|
+
...opt,
|
|
108
|
+
});
|
|
93
109
|
}
|
|
94
110
|
async fetch(opt) {
|
|
95
111
|
const res = await this.doFetch(opt);
|
|
@@ -135,7 +151,6 @@ export class Fetcher {
|
|
|
135
151
|
* Note: responseType defaults to `void`, so, override it if you expect different.
|
|
136
152
|
*/
|
|
137
153
|
async doFetch(opt) {
|
|
138
|
-
var _b, _c;
|
|
139
154
|
const req = this.normalizeOptions(opt);
|
|
140
155
|
const { logger } = this.cfg;
|
|
141
156
|
const { timeoutSeconds, init: { method }, } = req;
|
|
@@ -201,8 +216,8 @@ export class Fetcher {
|
|
|
201
216
|
// Separate Timeout will be introduced to "download and parse the body"
|
|
202
217
|
}
|
|
203
218
|
res.statusFamily = this.getStatusFamily(res);
|
|
204
|
-
res.statusCode =
|
|
205
|
-
if (
|
|
219
|
+
res.statusCode = res.fetchResponse?.status;
|
|
220
|
+
if (res.fetchResponse?.ok || !req.throwHttpErrors) {
|
|
206
221
|
try {
|
|
207
222
|
// We are applying a separate Timeout (as long as original Timeout for now) to "download and parse the body"
|
|
208
223
|
await pTimeout(async () => await this.onOkResponse(res), {
|
|
@@ -296,7 +311,6 @@ export class Fetcher {
|
|
|
296
311
|
return await globalThis.fetch(url, init);
|
|
297
312
|
}
|
|
298
313
|
async onNotOkResponse(res) {
|
|
299
|
-
var _b;
|
|
300
314
|
let cause;
|
|
301
315
|
if (res.err) {
|
|
302
316
|
// This is only possible on JSON.parse error, or CORS error,
|
|
@@ -315,7 +329,7 @@ export class Fetcher {
|
|
|
315
329
|
message: 'Fetch failed',
|
|
316
330
|
data: {},
|
|
317
331
|
});
|
|
318
|
-
let responseStatusCode =
|
|
332
|
+
let responseStatusCode = res.fetchResponse?.status || 0;
|
|
319
333
|
if (res.statusFamily === 2) {
|
|
320
334
|
// important to reset httpStatusCode to 0 in this case, as status 2xx can be misleading
|
|
321
335
|
res.statusFamily = undefined;
|
|
@@ -342,7 +356,6 @@ export class Fetcher {
|
|
|
342
356
|
await this.processRetry(res);
|
|
343
357
|
}
|
|
344
358
|
async processRetry(res) {
|
|
345
|
-
var _b;
|
|
346
359
|
const { retryStatus } = res;
|
|
347
360
|
if (!this.shouldRetry(res)) {
|
|
348
361
|
retryStatus.retryStopped = true;
|
|
@@ -362,7 +375,7 @@ export class Fetcher {
|
|
|
362
375
|
if (res.err && (!retryStatus.retryStopped || res.req.logResponse)) {
|
|
363
376
|
this.cfg.logger.error([
|
|
364
377
|
' <<',
|
|
365
|
-
|
|
378
|
+
res.fetchResponse?.status || 0,
|
|
366
379
|
res.signature,
|
|
367
380
|
count &&
|
|
368
381
|
(retryStatus.retryAttempt || !retryStatus.retryStopped) &&
|
|
@@ -385,12 +398,12 @@ export class Fetcher {
|
|
|
385
398
|
await pDelay(timeout);
|
|
386
399
|
}
|
|
387
400
|
getRetryTimeout(res) {
|
|
388
|
-
var _b;
|
|
389
401
|
let timeout = 0;
|
|
390
402
|
// Handling http 429 with specific retry headers
|
|
391
403
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
|
392
404
|
if (res.fetchResponse && [429, 503].includes(res.fetchResponse.status)) {
|
|
393
|
-
const retryAfterStr =
|
|
405
|
+
const retryAfterStr = res.fetchResponse.headers.get('retry-after') ??
|
|
406
|
+
res.fetchResponse.headers.get('x-ratelimit-reset');
|
|
394
407
|
if (retryAfterStr) {
|
|
395
408
|
if (Number(retryAfterStr)) {
|
|
396
409
|
timeout = Number(retryAfterStr) * 1000;
|
|
@@ -420,13 +433,12 @@ export class Fetcher {
|
|
|
420
433
|
* statusCode of 0 (or absense of it) will BE retried.
|
|
421
434
|
*/
|
|
422
435
|
shouldRetry(res) {
|
|
423
|
-
var _b, _c, _d, _e, _f;
|
|
424
436
|
const { retryPost, retry3xx, retry4xx, retry5xx } = res.req;
|
|
425
437
|
const { method } = res.req.init;
|
|
426
438
|
if (method === 'POST' && !retryPost)
|
|
427
439
|
return false;
|
|
428
440
|
const { statusFamily } = res;
|
|
429
|
-
const statusCode =
|
|
441
|
+
const statusCode = res.fetchResponse?.status || 0;
|
|
430
442
|
if (statusFamily === 5 && !retry5xx)
|
|
431
443
|
return false;
|
|
432
444
|
if ([408, 429].includes(statusCode)) {
|
|
@@ -438,14 +450,13 @@ export class Fetcher {
|
|
|
438
450
|
if (statusFamily === 3 && !retry3xx)
|
|
439
451
|
return false;
|
|
440
452
|
// should not retry on `unexpected redirect` in error.cause.cause
|
|
441
|
-
if (
|
|
453
|
+
if (res.err?.cause?.cause?.message?.includes('unexpected redirect')) {
|
|
442
454
|
return false;
|
|
443
455
|
}
|
|
444
456
|
return true; // default is true
|
|
445
457
|
}
|
|
446
458
|
getStatusFamily(res) {
|
|
447
|
-
|
|
448
|
-
const status = (_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status;
|
|
459
|
+
const status = res.fetchResponse?.status;
|
|
449
460
|
if (!status)
|
|
450
461
|
return;
|
|
451
462
|
if (status >= 500)
|
|
@@ -478,8 +489,7 @@ export class Fetcher {
|
|
|
478
489
|
return shortUrl;
|
|
479
490
|
}
|
|
480
491
|
normalizeCfg(cfg) {
|
|
481
|
-
|
|
482
|
-
if ((_b = cfg.baseUrl) === null || _b === void 0 ? void 0 : _b.endsWith('/')) {
|
|
492
|
+
if (cfg.baseUrl?.endsWith('/')) {
|
|
483
493
|
console.warn(`Fetcher: baseUrl should not end with slash: ${cfg.baseUrl}`);
|
|
484
494
|
cfg.baseUrl = cfg.baseUrl.slice(0, cfg.baseUrl.length - 1);
|
|
485
495
|
}
|
|
@@ -503,10 +513,13 @@ export class Fetcher {
|
|
|
503
513
|
logResponseBody: debug,
|
|
504
514
|
logWithBaseUrl: isServerSide(),
|
|
505
515
|
logWithSearchParams: true,
|
|
506
|
-
retry:
|
|
516
|
+
retry: { ...defRetryOptions },
|
|
507
517
|
init: {
|
|
508
518
|
method: cfg.method || 'GET',
|
|
509
|
-
headers: _filterNullishValues(
|
|
519
|
+
headers: _filterNullishValues({
|
|
520
|
+
'user-agent': _a.userAgent,
|
|
521
|
+
...cfg.headers,
|
|
522
|
+
}),
|
|
510
523
|
credentials: cfg.credentials,
|
|
511
524
|
redirect: cfg.redirect,
|
|
512
525
|
},
|
|
@@ -518,22 +531,39 @@ export class Fetcher {
|
|
|
518
531
|
}
|
|
519
532
|
normalizeOptions(opt) {
|
|
520
533
|
var _b;
|
|
521
|
-
const req =
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
534
|
+
const req = {
|
|
535
|
+
..._pick(this.cfg, [
|
|
536
|
+
'timeoutSeconds',
|
|
537
|
+
'retryPost',
|
|
538
|
+
'retry4xx',
|
|
539
|
+
'retry5xx',
|
|
540
|
+
'responseType',
|
|
541
|
+
'jsonReviver',
|
|
542
|
+
'logRequest',
|
|
543
|
+
'logRequestBody',
|
|
544
|
+
'logResponse',
|
|
545
|
+
'logResponseBody',
|
|
546
|
+
'debug',
|
|
547
|
+
'throwHttpErrors',
|
|
548
|
+
]),
|
|
549
|
+
started: Date.now(),
|
|
550
|
+
..._omit(opt, ['method', 'headers', 'credentials']),
|
|
551
|
+
inputUrl: opt.url || '',
|
|
552
|
+
fullUrl: opt.url || '',
|
|
553
|
+
retry: {
|
|
554
|
+
...this.cfg.retry,
|
|
555
|
+
..._filterUndefinedValues(opt.retry || {}),
|
|
556
|
+
},
|
|
557
|
+
init: _merge({
|
|
558
|
+
...this.cfg.init,
|
|
559
|
+
headers: { ...this.cfg.init.headers }, // this avoids mutation
|
|
560
|
+
method: opt.method || this.cfg.init.method,
|
|
561
|
+
credentials: opt.credentials || this.cfg.init.credentials,
|
|
562
|
+
redirect: opt.redirect || this.cfg.init.redirect || 'follow',
|
|
563
|
+
}, {
|
|
535
564
|
headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
|
|
536
|
-
})
|
|
565
|
+
}),
|
|
566
|
+
};
|
|
537
567
|
// Because all header values are stringified, so `a: undefined` becomes `undefined` as a string
|
|
538
568
|
_filterNullishValues(req.init.headers, true);
|
|
539
569
|
// setup url
|
|
@@ -545,7 +575,10 @@ export class Fetcher {
|
|
|
545
575
|
}
|
|
546
576
|
req.fullUrl = `${baseUrl}/${req.inputUrl}`;
|
|
547
577
|
}
|
|
548
|
-
const searchParams = _filterUndefinedValues(
|
|
578
|
+
const searchParams = _filterUndefinedValues({
|
|
579
|
+
...this.cfg.searchParams,
|
|
580
|
+
...opt.searchParams,
|
|
581
|
+
});
|
|
549
582
|
if (Object.keys(searchParams).length) {
|
|
550
583
|
const qs = new URLSearchParams(searchParams).toString();
|
|
551
584
|
req.fullUrl += (req.fullUrl.includes('?') ? '&' : '?') + qs;
|
package/dist-esm/index.js
CHANGED
|
@@ -26,7 +26,6 @@ export * from './json-schema/jsonSchema.cnst';
|
|
|
26
26
|
export * from './json-schema/jsonSchema.model';
|
|
27
27
|
export * from './json-schema/jsonSchema.util';
|
|
28
28
|
export * from './json-schema/jsonSchemaBuilder';
|
|
29
|
-
export * from './json-schema/jsonSchemaBuilder';
|
|
30
29
|
export * from './math/math.util';
|
|
31
30
|
export * from './math/sma';
|
|
32
31
|
export * from './number/createDeterministicRandom';
|
|
@@ -68,10 +67,7 @@ export * from './math/stack.util';
|
|
|
68
67
|
export * from './string/leven';
|
|
69
68
|
export * from './datetime/localDate';
|
|
70
69
|
export * from './datetime/localTime';
|
|
71
|
-
export * from './datetime/
|
|
72
|
-
export * from './datetime/timeInterval';
|
|
73
|
-
export * from './datetime/localDate';
|
|
74
|
-
export * from './datetime/localTime';
|
|
70
|
+
export * from './datetime/wallTime';
|
|
75
71
|
export * from './datetime/dateInterval';
|
|
76
72
|
export * from './datetime/timeInterval';
|
|
77
73
|
export * from './env';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
|
|
2
1
|
import { END, SKIP } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* Similar to Iterable2, but for AsyncIterable.
|
|
@@ -19,16 +18,14 @@ export class AsyncIterable2 {
|
|
|
19
18
|
}
|
|
20
19
|
static ofIterable(it) {
|
|
21
20
|
return new AsyncIterable2({
|
|
22
|
-
[Symbol.asyncIterator]() {
|
|
23
|
-
|
|
24
|
-
yield __await(yield* __asyncDelegator(__asyncValues(it)));
|
|
25
|
-
});
|
|
21
|
+
async *[Symbol.asyncIterator]() {
|
|
22
|
+
yield* it;
|
|
26
23
|
},
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
26
|
static empty() {
|
|
30
27
|
return new AsyncIterable2({
|
|
31
|
-
[Symbol.asyncIterator]() {
|
|
28
|
+
async *[Symbol.asyncIterator]() { },
|
|
32
29
|
});
|
|
33
30
|
}
|
|
34
31
|
[Symbol.asyncIterator]() {
|
|
@@ -37,151 +34,69 @@ export class AsyncIterable2 {
|
|
|
37
34
|
async toArray() {
|
|
38
35
|
// todo: Array.fromAsync is not yet available, use that when it's ready
|
|
39
36
|
// return await Array.fromAsync(this.it)
|
|
40
|
-
var _a, e_1, _b, _c;
|
|
41
37
|
const res = [];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
_c = _f.value;
|
|
45
|
-
_d = false;
|
|
46
|
-
const item = _c;
|
|
47
|
-
res.push(item);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
51
|
-
finally {
|
|
52
|
-
try {
|
|
53
|
-
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
|
|
54
|
-
}
|
|
55
|
-
finally { if (e_1) throw e_1.error; }
|
|
38
|
+
for await (const item of this.it) {
|
|
39
|
+
res.push(item);
|
|
56
40
|
}
|
|
57
41
|
return res;
|
|
58
42
|
}
|
|
59
43
|
async forEach(cb) {
|
|
60
|
-
var _a, e_2, _b, _c;
|
|
61
44
|
let i = 0;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_d = false;
|
|
66
|
-
const v = _c;
|
|
67
|
-
if ((await cb(v, i++)) === END)
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
72
|
-
finally {
|
|
73
|
-
try {
|
|
74
|
-
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
|
|
75
|
-
}
|
|
76
|
-
finally { if (e_2) throw e_2.error; }
|
|
45
|
+
for await (const v of this.it) {
|
|
46
|
+
if ((await cb(v, i++)) === END)
|
|
47
|
+
return;
|
|
77
48
|
}
|
|
78
49
|
}
|
|
79
50
|
async some(cb) {
|
|
80
51
|
return !!(await this.find(cb));
|
|
81
52
|
}
|
|
82
53
|
async every(cb) {
|
|
83
|
-
var _a, e_3, _b, _c;
|
|
84
54
|
let i = 0;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const v = _c;
|
|
90
|
-
const r = await cb(v, i++);
|
|
91
|
-
if (r === END || !r)
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
96
|
-
finally {
|
|
97
|
-
try {
|
|
98
|
-
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
|
|
99
|
-
}
|
|
100
|
-
finally { if (e_3) throw e_3.error; }
|
|
55
|
+
for await (const v of this.it) {
|
|
56
|
+
const r = await cb(v, i++);
|
|
57
|
+
if (r === END || !r)
|
|
58
|
+
return false;
|
|
101
59
|
}
|
|
102
60
|
return true;
|
|
103
61
|
}
|
|
104
62
|
async find(cb) {
|
|
105
|
-
var _a, e_4, _b, _c;
|
|
106
63
|
let i = 0;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (r === END)
|
|
114
|
-
return;
|
|
115
|
-
if (r)
|
|
116
|
-
return v;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
120
|
-
finally {
|
|
121
|
-
try {
|
|
122
|
-
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
|
|
123
|
-
}
|
|
124
|
-
finally { if (e_4) throw e_4.error; }
|
|
64
|
+
for await (const v of this.it) {
|
|
65
|
+
const r = await cb(v, i++);
|
|
66
|
+
if (r === END)
|
|
67
|
+
return;
|
|
68
|
+
if (r)
|
|
69
|
+
return v;
|
|
125
70
|
}
|
|
126
71
|
}
|
|
127
72
|
filter(cb) {
|
|
128
73
|
const { it } = this;
|
|
129
74
|
return new AsyncIterable2({
|
|
130
|
-
[Symbol.asyncIterator]() {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const r = yield __await(cb(v, i++));
|
|
140
|
-
if (r === END)
|
|
141
|
-
return yield __await(void 0);
|
|
142
|
-
if (r)
|
|
143
|
-
yield yield __await(v);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
147
|
-
finally {
|
|
148
|
-
try {
|
|
149
|
-
if (!_e && !_b && (_c = it_1.return)) yield __await(_c.call(it_1));
|
|
150
|
-
}
|
|
151
|
-
finally { if (e_5) throw e_5.error; }
|
|
152
|
-
}
|
|
153
|
-
});
|
|
75
|
+
async *[Symbol.asyncIterator]() {
|
|
76
|
+
let i = 0;
|
|
77
|
+
for await (const v of it) {
|
|
78
|
+
const r = await cb(v, i++);
|
|
79
|
+
if (r === END)
|
|
80
|
+
return;
|
|
81
|
+
if (r)
|
|
82
|
+
yield v;
|
|
83
|
+
}
|
|
154
84
|
},
|
|
155
85
|
});
|
|
156
86
|
}
|
|
157
87
|
map(mapper) {
|
|
158
88
|
const { it } = this;
|
|
159
89
|
return new AsyncIterable2({
|
|
160
|
-
[Symbol.asyncIterator]() {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (r === END)
|
|
171
|
-
return yield __await(void 0);
|
|
172
|
-
if (r === SKIP)
|
|
173
|
-
continue;
|
|
174
|
-
yield yield __await(r);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
178
|
-
finally {
|
|
179
|
-
try {
|
|
180
|
-
if (!_e && !_b && (_c = it_2.return)) yield __await(_c.call(it_2));
|
|
181
|
-
}
|
|
182
|
-
finally { if (e_6) throw e_6.error; }
|
|
183
|
-
}
|
|
184
|
-
});
|
|
90
|
+
async *[Symbol.asyncIterator]() {
|
|
91
|
+
let i = 0;
|
|
92
|
+
for await (const v of it) {
|
|
93
|
+
const r = await mapper(v, i++);
|
|
94
|
+
if (r === END)
|
|
95
|
+
return;
|
|
96
|
+
if (r === SKIP)
|
|
97
|
+
continue;
|
|
98
|
+
yield r;
|
|
99
|
+
}
|
|
185
100
|
},
|
|
186
101
|
});
|
|
187
102
|
}
|
|
@@ -6,7 +6,6 @@ import { _filterNullishValues } from '../object/object.util';
|
|
|
6
6
|
* API similar to Object.assign(s1, s2)
|
|
7
7
|
*/
|
|
8
8
|
export function mergeJsonSchemaObjects(s1, s2) {
|
|
9
|
-
var _a, _b;
|
|
10
9
|
// Merge `properties`
|
|
11
10
|
Object.entries(s2.properties).forEach(([k, v]) => {
|
|
12
11
|
;
|
|
@@ -18,8 +17,8 @@ export function mergeJsonSchemaObjects(s1, s2) {
|
|
|
18
17
|
s1.patternProperties[k] = v;
|
|
19
18
|
});
|
|
20
19
|
s1.propertyNames = s2.propertyNames || s1.propertyNames;
|
|
21
|
-
s1.minProperties =
|
|
22
|
-
s1.maxProperties =
|
|
20
|
+
s1.minProperties = s2.minProperties ?? s1.minProperties;
|
|
21
|
+
s1.maxProperties = s2.maxProperties ?? s1.maxProperties;
|
|
23
22
|
// Merge `required`
|
|
24
23
|
s1.required.push(...s2.required);
|
|
25
24
|
s1.required = _uniq(s1.required).sort();
|
|
@@ -250,12 +250,11 @@ export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
|
|
|
250
250
|
return this;
|
|
251
251
|
}
|
|
252
252
|
transformModify(t, add) {
|
|
253
|
-
var _a;
|
|
254
253
|
if (add) {
|
|
255
254
|
this.schema.transform = _uniq([...(this.schema.transform || []), t]);
|
|
256
255
|
}
|
|
257
256
|
else {
|
|
258
|
-
this.schema.transform =
|
|
257
|
+
this.schema.transform = this.schema.transform?.filter(s => s !== t);
|
|
259
258
|
}
|
|
260
259
|
return this;
|
|
261
260
|
}
|
|
@@ -14,7 +14,7 @@ export function _average(values) {
|
|
|
14
14
|
* Same as _average, but safely returns null if input array is empty or nullish.
|
|
15
15
|
*/
|
|
16
16
|
export function _averageOrNull(values) {
|
|
17
|
-
return
|
|
17
|
+
return values?.length ? values.reduce((a, b) => a + b) / values.length : null;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* valuesArray and weightsArray length is expected to be the same.
|
|
@@ -28,7 +28,7 @@ export function _omit(obj, props, mutate = false) {
|
|
|
28
28
|
return props.reduce((r, prop) => {
|
|
29
29
|
delete r[prop];
|
|
30
30
|
return r;
|
|
31
|
-
}, mutate ? obj :
|
|
31
|
+
}, mutate ? obj : { ...obj });
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Returns object with filtered keys from `props` array.
|
|
@@ -75,7 +75,7 @@ export function _filterObject(obj, predicate, mutate = false) {
|
|
|
75
75
|
if (!predicate(k, r[k], obj))
|
|
76
76
|
delete r[k];
|
|
77
77
|
return r;
|
|
78
|
-
}, mutate ? obj :
|
|
78
|
+
}, mutate ? obj : { ...obj });
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* var users = {
|
|
@@ -134,8 +134,7 @@ export function _mapObject(obj, mapper) {
|
|
|
134
134
|
}, {});
|
|
135
135
|
}
|
|
136
136
|
export function _findKeyByValue(obj, v) {
|
|
137
|
-
|
|
138
|
-
return (_a = Object.entries(obj).find(([_, value]) => value === v)) === null || _a === void 0 ? void 0 : _a[0];
|
|
137
|
+
return Object.entries(obj).find(([_, value]) => value === v)?.[0];
|
|
139
138
|
}
|
|
140
139
|
export function _objectNullValuesToUndefined(obj, mutate = false) {
|
|
141
140
|
return _mapValues(obj, (_k, v) => (v === null ? undefined : v), mutate);
|
|
@@ -277,7 +276,7 @@ export function _get(obj = {}, path = '') {
|
|
|
277
276
|
return path
|
|
278
277
|
.replaceAll(/\[([^\]]+)]/g, '.$1')
|
|
279
278
|
.split('.')
|
|
280
|
-
.reduce((o, p) => o
|
|
279
|
+
.reduce((o, p) => o?.[p], obj);
|
|
281
280
|
}
|
|
282
281
|
/**
|
|
283
282
|
* Sets the value at path of object. If a portion of path doesn’t exist it’s created. Arrays are created for
|
package/dist-esm/polyfill.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export function polyfillDispose() {
|
|
2
|
-
var _a, _b;
|
|
3
2
|
// @ts-expect-error polyfill
|
|
4
|
-
|
|
3
|
+
Symbol.dispose ?? (Symbol.dispose = Symbol('Symbol.dispose'));
|
|
5
4
|
// @ts-expect-error polyfill
|
|
6
|
-
|
|
5
|
+
Symbol.asyncDispose ?? (Symbol.asyncDispose = Symbol('Symbol.asyncDispose'));
|
|
7
6
|
}
|
|
@@ -15,11 +15,10 @@ export class Abortable {
|
|
|
15
15
|
this.aborted = false;
|
|
16
16
|
}
|
|
17
17
|
abort() {
|
|
18
|
-
var _a;
|
|
19
18
|
if (this.aborted)
|
|
20
19
|
return;
|
|
21
20
|
this.aborted = true;
|
|
22
|
-
|
|
21
|
+
this.onAbort?.();
|
|
23
22
|
this.onAbort = undefined; // cleanup listener
|
|
24
23
|
}
|
|
25
24
|
clear() {
|
package/dist-esm/promise/pMap.js
CHANGED
|
@@ -96,7 +96,7 @@ export async function pMap(iterable, mapper, opt = {}) {
|
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
98
98
|
// otherwise, suppress (but still log via logger)
|
|
99
|
-
logger
|
|
99
|
+
logger?.error(err);
|
|
100
100
|
}
|
|
101
101
|
resolvingCount--;
|
|
102
102
|
next();
|
|
@@ -134,7 +134,7 @@ async function pMap1(items, mapper, errorMode, logger) {
|
|
|
134
134
|
}
|
|
135
135
|
else {
|
|
136
136
|
// otherwise, suppress (but still log via logger)
|
|
137
|
-
logger
|
|
137
|
+
logger?.error(err);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -164,7 +164,7 @@ async function pMapAll(items, mapper, errorMode, logger) {
|
|
|
164
164
|
}
|
|
165
165
|
else {
|
|
166
166
|
// otherwise, suppress (but still log via logger)
|
|
167
|
-
logger
|
|
167
|
+
logger?.error(r.reason);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
if (errors.length) {
|
|
@@ -13,9 +13,14 @@ export class PQueue {
|
|
|
13
13
|
this.inFlight = 0;
|
|
14
14
|
this.queue = [];
|
|
15
15
|
this.onIdleListeners = [];
|
|
16
|
-
this.cfg =
|
|
16
|
+
this.cfg = {
|
|
17
17
|
// concurrency: Number.MAX_SAFE_INTEGER,
|
|
18
|
-
errorMode: ErrorMode.THROW_IMMEDIATELY,
|
|
18
|
+
errorMode: ErrorMode.THROW_IMMEDIATELY,
|
|
19
|
+
logger: console,
|
|
20
|
+
debug: false,
|
|
21
|
+
resolveOn: 'finish',
|
|
22
|
+
...cfg,
|
|
23
|
+
};
|
|
19
24
|
if (!cfg.debug) {
|
|
20
25
|
this.debug = () => { };
|
|
21
26
|
}
|
|
@@ -11,7 +11,7 @@ export function _jsonParseIfPossible(obj, reviver) {
|
|
|
11
11
|
try {
|
|
12
12
|
return JSON.parse(obj, reviver);
|
|
13
13
|
}
|
|
14
|
-
catch
|
|
14
|
+
catch { }
|
|
15
15
|
}
|
|
16
16
|
return obj;
|
|
17
17
|
}
|
|
@@ -25,7 +25,7 @@ export function _jsonParseOrUndefined(obj, reviver) {
|
|
|
25
25
|
try {
|
|
26
26
|
return JSON.parse(obj, reviver);
|
|
27
27
|
}
|
|
28
|
-
catch
|
|
28
|
+
catch { }
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
@@ -38,7 +38,7 @@ export function _jsonParse(s, reviver) {
|
|
|
38
38
|
try {
|
|
39
39
|
return JSON.parse(s, reviver);
|
|
40
40
|
}
|
|
41
|
-
catch
|
|
41
|
+
catch {
|
|
42
42
|
throw new JsonParseError({
|
|
43
43
|
text: s,
|
|
44
44
|
});
|
|
@@ -95,5 +95,8 @@ function readingTimeWithCount(words, options = {}) {
|
|
|
95
95
|
*/
|
|
96
96
|
export function readingTime(text, options = {}) {
|
|
97
97
|
const words = countWords(text, options);
|
|
98
|
-
return
|
|
98
|
+
return {
|
|
99
|
+
...readingTimeWithCount(words, options),
|
|
100
|
+
words,
|
|
101
|
+
};
|
|
99
102
|
}
|