@naturalcycles/js-lib 14.234.0 → 14.236.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/number/number.util.d.ts +4 -1
- package/dist/number/number.util.js +3 -1
- package/dist-esm/array/range.js +4 -7
- package/dist-esm/datetime/localTime.js +9 -7
- 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/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/number/number.util.js +3 -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/number/number.util.ts +7 -5
|
@@ -22,8 +22,11 @@ export declare function _runLessOften(percent: number): boolean;
|
|
|
22
22
|
* _isBetween(3, 1, 5) // true
|
|
23
23
|
* _isBetween(5, 1, 5) // false
|
|
24
24
|
* _isBetween(7, 1, 5) // false
|
|
25
|
+
*
|
|
26
|
+
* Also works with strings:
|
|
27
|
+
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
25
28
|
*/
|
|
26
|
-
export declare function _isBetween(x:
|
|
29
|
+
export declare function _isBetween<T extends number | string>(x: T, min: T, max: T, incl?: Inclusiveness): boolean;
|
|
27
30
|
export declare function _clamp(x: number, minIncl: number, maxIncl: number): number;
|
|
28
31
|
/**
|
|
29
32
|
* This function exists, because in JS you cannot just .sort() numbers,
|
|
@@ -34,6 +34,9 @@ exports._runLessOften = _runLessOften;
|
|
|
34
34
|
* _isBetween(3, 1, 5) // true
|
|
35
35
|
* _isBetween(5, 1, 5) // false
|
|
36
36
|
* _isBetween(7, 1, 5) // false
|
|
37
|
+
*
|
|
38
|
+
* Also works with strings:
|
|
39
|
+
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
37
40
|
*/
|
|
38
41
|
function _isBetween(x, min, max, incl = '[)') {
|
|
39
42
|
if (incl === '[)') {
|
|
@@ -45,7 +48,6 @@ function _isBetween(x, min, max, incl = '[)') {
|
|
|
45
48
|
else if (incl === '(]') {
|
|
46
49
|
return x > min && x <= max;
|
|
47
50
|
}
|
|
48
|
-
// ()
|
|
49
51
|
return x > min && x < max;
|
|
50
52
|
}
|
|
51
53
|
exports._isBetween = _isBetween;
|
package/dist-esm/array/range.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __asyncGenerator, __await } from "tslib";
|
|
2
1
|
import { AsyncIterable2 } from '../iter/asyncIterable2';
|
|
3
2
|
import { Iterable2 } from '../iter/iterable2';
|
|
4
3
|
export function _range(fromIncl, toExcl, step = 1) {
|
|
@@ -26,12 +25,10 @@ export function _rangeAsyncIterable(fromIncl, toExcl, step = 1) {
|
|
|
26
25
|
fromIncl = 0;
|
|
27
26
|
}
|
|
28
27
|
return AsyncIterable2.of({
|
|
29
|
-
[Symbol.asyncIterator]() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
});
|
|
28
|
+
async *[Symbol.asyncIterator]() {
|
|
29
|
+
for (let i = fromIncl; i < toExcl; i += step) {
|
|
30
|
+
yield i;
|
|
31
|
+
}
|
|
35
32
|
},
|
|
36
33
|
});
|
|
37
34
|
}
|
|
@@ -112,11 +112,10 @@ export class LocalTime {
|
|
|
112
112
|
return v === undefined ? this.get('second') : this.set('second', v);
|
|
113
113
|
}
|
|
114
114
|
setComponents(c, mutate = false) {
|
|
115
|
-
var _a;
|
|
116
115
|
const d = mutate ? this.$date : new Date(this.$date);
|
|
117
116
|
// Year, month and day set all-at-once, to avoid 30/31 (and 28/29) mishap
|
|
118
117
|
if (c.day || c.month !== undefined || c.year !== undefined) {
|
|
119
|
-
d.setFullYear(
|
|
118
|
+
d.setFullYear(c.year ?? d.getFullYear(), c.month ? c.month - 1 : d.getMonth(), c.day || d.getDate());
|
|
120
119
|
}
|
|
121
120
|
if (c.hour !== undefined) {
|
|
122
121
|
d.setHours(c.hour);
|
|
@@ -317,13 +316,13 @@ export class LocalTime {
|
|
|
317
316
|
* Third argument allows to override "now".
|
|
318
317
|
*/
|
|
319
318
|
isOlderThan(n, unit, now) {
|
|
320
|
-
return this.isBefore(localTime.of(now
|
|
319
|
+
return this.isBefore(localTime.of(now ?? new Date()).plus(-n, unit));
|
|
321
320
|
}
|
|
322
321
|
/**
|
|
323
322
|
* Checks if this localTime is same or older (<=) than "now" by X units.
|
|
324
323
|
*/
|
|
325
324
|
isSameOrOlderThan(n, unit, now) {
|
|
326
|
-
return this.isSameOrBefore(localTime.of(now
|
|
325
|
+
return this.isSameOrBefore(localTime.of(now ?? new Date()).plus(-n, unit));
|
|
327
326
|
}
|
|
328
327
|
/**
|
|
329
328
|
* Checks if this localTime is younger (>) than "now" by X units.
|
|
@@ -335,13 +334,13 @@ export class LocalTime {
|
|
|
335
334
|
* Third argument allows to override "now".
|
|
336
335
|
*/
|
|
337
336
|
isYoungerThan(n, unit, now) {
|
|
338
|
-
return this.isAfter(localTime.of(now
|
|
337
|
+
return this.isAfter(localTime.of(now ?? new Date()).plus(-n, unit));
|
|
339
338
|
}
|
|
340
339
|
/**
|
|
341
340
|
* Checks if this localTime is same or younger (>=) than "now" by X units.
|
|
342
341
|
*/
|
|
343
342
|
isSameOrYoungerThan(n, unit, now) {
|
|
344
|
-
return this.isSameOrAfter(localTime.of(now
|
|
343
|
+
return this.isSameOrAfter(localTime.of(now ?? new Date()).plus(-n, unit));
|
|
345
344
|
}
|
|
346
345
|
/**
|
|
347
346
|
* Returns 1 if this > d
|
|
@@ -356,7 +355,10 @@ export class LocalTime {
|
|
|
356
355
|
return t1 < t2 ? -1 : 1;
|
|
357
356
|
}
|
|
358
357
|
components() {
|
|
359
|
-
return
|
|
358
|
+
return {
|
|
359
|
+
...this.dateComponents(),
|
|
360
|
+
...this.timeComponents(),
|
|
361
|
+
};
|
|
360
362
|
}
|
|
361
363
|
dateComponents() {
|
|
362
364
|
return {
|
|
@@ -108,6 +108,6 @@ export const _AsyncMemo = (opt) => (target, key, descriptor) => {
|
|
|
108
108
|
e.g `clear` to clear the cache, or get its underlying data.
|
|
109
109
|
*/
|
|
110
110
|
export function _getAsyncMemo(method) {
|
|
111
|
-
_assert(typeof
|
|
111
|
+
_assert(typeof method?.getInstanceCache === 'function', 'method is not an AsyncMemo instance');
|
|
112
112
|
return method;
|
|
113
113
|
}
|
|
@@ -18,7 +18,6 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
18
18
|
const key = String(propertyKey);
|
|
19
19
|
const methodSignature = _getTargetMethodSignature(target, key);
|
|
20
20
|
pd.value = async function (...args) {
|
|
21
|
-
var _a, _b;
|
|
22
21
|
// console.log(`@${cfg.decoratorName} called inside function`)
|
|
23
22
|
const started = Date.now();
|
|
24
23
|
try {
|
|
@@ -46,9 +45,12 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
46
45
|
started,
|
|
47
46
|
};
|
|
48
47
|
if (cfg.thenFn) {
|
|
49
|
-
res = cfg.thenFn(
|
|
48
|
+
res = cfg.thenFn({
|
|
49
|
+
...resp,
|
|
50
|
+
res,
|
|
51
|
+
});
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
cfg.finallyFn?.(resp);
|
|
52
54
|
return res;
|
|
53
55
|
}
|
|
54
56
|
catch (err) {
|
|
@@ -63,10 +65,13 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
63
65
|
};
|
|
64
66
|
let handled = false;
|
|
65
67
|
if (cfg.catchFn) {
|
|
66
|
-
cfg.catchFn(
|
|
68
|
+
cfg.catchFn({
|
|
69
|
+
...resp,
|
|
70
|
+
err,
|
|
71
|
+
});
|
|
67
72
|
handled = true;
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
cfg.finallyFn?.(resp);
|
|
70
75
|
if (!handled) {
|
|
71
76
|
throw err; // rethrow
|
|
72
77
|
}
|
|
@@ -105,5 +105,10 @@ export function _debounce(func, wait, opt = {}) {
|
|
|
105
105
|
return debounced;
|
|
106
106
|
}
|
|
107
107
|
export function _throttle(func, wait, opt = {}) {
|
|
108
|
-
return _debounce(func, wait,
|
|
108
|
+
return _debounce(func, wait, {
|
|
109
|
+
leading: true,
|
|
110
|
+
trailing: true,
|
|
111
|
+
...opt,
|
|
112
|
+
maxWait: wait,
|
|
113
|
+
});
|
|
109
114
|
}
|
|
@@ -77,6 +77,6 @@ export const _Memo = (opt = {}) => (target, key, descriptor) => {
|
|
|
77
77
|
e.g `clear` to clear the cache, or get its underlying data.
|
|
78
78
|
*/
|
|
79
79
|
export function _getMemo(method) {
|
|
80
|
-
_assert(typeof
|
|
80
|
+
_assert(typeof method?.getInstanceCache === 'function', 'method is not a Memo instance');
|
|
81
81
|
return method;
|
|
82
82
|
}
|
package/dist-esm/define.js
CHANGED
|
@@ -76,14 +76,26 @@ export function _defineLazyProps(obj, props) {
|
|
|
76
76
|
*
|
|
77
77
|
*/
|
|
78
78
|
export function _defineProperty(obj, prop, pd) {
|
|
79
|
-
return Object.defineProperty(obj, prop,
|
|
79
|
+
return Object.defineProperty(obj, prop, {
|
|
80
|
+
writable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
enumerable: true,
|
|
83
|
+
// value: obj[prop], // existing value is already kept by default
|
|
84
|
+
...pd,
|
|
85
|
+
});
|
|
80
86
|
}
|
|
81
87
|
/**
|
|
82
88
|
* Object.defineProperties with better defaults.
|
|
83
89
|
* See _defineProperty for exact defaults definition.
|
|
84
90
|
*/
|
|
85
91
|
export function _defineProps(obj, props) {
|
|
86
|
-
return Object.defineProperties(obj, _mapValues(props, (k, pd) => (
|
|
92
|
+
return Object.defineProperties(obj, _mapValues(props, (k, pd) => ({
|
|
93
|
+
writable: true,
|
|
94
|
+
configurable: true,
|
|
95
|
+
enumerable: true,
|
|
96
|
+
// value: obj[k], // existing value is already kept by default
|
|
97
|
+
...pd,
|
|
98
|
+
})));
|
|
87
99
|
}
|
|
88
100
|
/**
|
|
89
101
|
* Like _defineProps, but skips props with nullish values.
|
package/dist-esm/enum.util.js
CHANGED
|
@@ -147,8 +147,7 @@ export function _numberEnumKey(en, v) {
|
|
|
147
147
|
export function _stringEnumKeyOrUndefined(en,
|
|
148
148
|
// v: T[keyof T] | undefined | null, // cannot make it type-safe :(
|
|
149
149
|
v) {
|
|
150
|
-
|
|
151
|
-
return (_a = Object.entries(en).find(([_, v2]) => v2 === v)) === null || _a === void 0 ? void 0 : _a[0];
|
|
150
|
+
return Object.entries(en).find(([_, v2]) => v2 === v)?.[0];
|
|
152
151
|
}
|
|
153
152
|
export function _stringEnumKey(en, v) {
|
|
154
153
|
const r = _stringEnumKeyOrUndefined(en, v);
|
package/dist-esm/error/assert.js
CHANGED
|
@@ -17,7 +17,10 @@ import { _deepEquals, _isErrorObject, _stringify, AssertionError } from '..';
|
|
|
17
17
|
export function _assert(condition, // will be evaluated as Boolean
|
|
18
18
|
message, errorData) {
|
|
19
19
|
if (!condition) {
|
|
20
|
-
throw new AssertionError(message || 'condition failed',
|
|
20
|
+
throw new AssertionError(message || 'condition failed', {
|
|
21
|
+
userFriendly: true,
|
|
22
|
+
...errorData,
|
|
23
|
+
});
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
@@ -32,7 +35,10 @@ export function _assertEquals(actual, expected, message, errorData) {
|
|
|
32
35
|
['not equal', `expected: ${_stringify(expected)}`, `got : ${_stringify(actual)}`]
|
|
33
36
|
.filter(Boolean)
|
|
34
37
|
.join('\n');
|
|
35
|
-
throw new AssertionError(msg,
|
|
38
|
+
throw new AssertionError(msg, {
|
|
39
|
+
userFriendly: true,
|
|
40
|
+
...errorData,
|
|
41
|
+
});
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
@@ -47,7 +53,10 @@ export function _assertDeepEquals(actual, expected, message, errorData) {
|
|
|
47
53
|
[`not deeply equal`, `expected: ${_stringify(expected)}`, `got : ${_stringify(actual)}`]
|
|
48
54
|
.filter(Boolean)
|
|
49
55
|
.join('\n');
|
|
50
|
-
throw new AssertionError(msg,
|
|
56
|
+
throw new AssertionError(msg, {
|
|
57
|
+
userFriendly: true,
|
|
58
|
+
...errorData,
|
|
59
|
+
});
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
62
|
export function _assertIsError(err, errorClass = Error) {
|
|
@@ -19,7 +19,10 @@ export function _anyToError(o, errorClass = Error, errorData) {
|
|
|
19
19
|
}
|
|
20
20
|
if (errorData) {
|
|
21
21
|
;
|
|
22
|
-
e.data =
|
|
22
|
+
e.data = {
|
|
23
|
+
...e.data,
|
|
24
|
+
...errorData,
|
|
25
|
+
};
|
|
23
26
|
}
|
|
24
27
|
return e;
|
|
25
28
|
}
|
|
@@ -73,7 +76,7 @@ export function _errorLikeToErrorObject(e) {
|
|
|
73
76
|
const obj = {
|
|
74
77
|
name: e.name,
|
|
75
78
|
message: e.message,
|
|
76
|
-
data:
|
|
79
|
+
data: { ...e.data }, // empty by default
|
|
77
80
|
};
|
|
78
81
|
if (e.stack)
|
|
79
82
|
obj.stack = e.stack;
|
|
@@ -168,11 +171,10 @@ export function _errorSnippet(err, opt = {}) {
|
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
export function _isBackendErrorResponseObject(o) {
|
|
171
|
-
return _isErrorObject(o
|
|
174
|
+
return _isErrorObject(o?.error);
|
|
172
175
|
}
|
|
173
176
|
export function _isHttpRequestErrorObject(o) {
|
|
174
|
-
|
|
175
|
-
return !!o && o.name === 'HttpRequestError' && typeof ((_a = o.data) === null || _a === void 0 ? void 0 : _a.requestUrl) === 'string';
|
|
177
|
+
return !!o && o.name === 'HttpRequestError' && typeof o.data?.requestUrl === 'string';
|
|
176
178
|
}
|
|
177
179
|
/**
|
|
178
180
|
* Note: any instance of AppError is also automatically an ErrorObject
|
|
@@ -204,7 +206,10 @@ export function _isErrorLike(o) {
|
|
|
204
206
|
export function _errorDataAppend(err, data) {
|
|
205
207
|
if (!data)
|
|
206
208
|
return err;
|
|
207
|
-
err.data =
|
|
209
|
+
err.data = {
|
|
210
|
+
...err.data,
|
|
211
|
+
...data,
|
|
212
|
+
};
|
|
208
213
|
return err;
|
|
209
214
|
}
|
|
210
215
|
/**
|
|
@@ -294,7 +299,7 @@ export class HttpRequestError extends AppError {
|
|
|
294
299
|
enumerable: false,
|
|
295
300
|
});
|
|
296
301
|
}
|
|
297
|
-
super(message, data,
|
|
302
|
+
super(message, data, { ...opt, name: 'HttpRequestError' });
|
|
298
303
|
}
|
|
299
304
|
}
|
|
300
305
|
export class AssertionError extends AppError {
|
|
@@ -312,7 +317,7 @@ export class JsonParseError extends AppError {
|
|
|
312
317
|
}
|
|
313
318
|
export class TimeoutError extends AppError {
|
|
314
319
|
constructor(message, data, opt) {
|
|
315
|
-
super(message, data,
|
|
320
|
+
super(message, data, { ...opt, name: 'TimeoutError' });
|
|
316
321
|
}
|
|
317
322
|
}
|
|
318
323
|
/**
|
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;
|
|
@@ -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,6 +28,9 @@ export function _runLessOften(percent) {
|
|
|
28
28
|
* _isBetween(3, 1, 5) // true
|
|
29
29
|
* _isBetween(5, 1, 5) // false
|
|
30
30
|
* _isBetween(7, 1, 5) // false
|
|
31
|
+
*
|
|
32
|
+
* Also works with strings:
|
|
33
|
+
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
31
34
|
*/
|
|
32
35
|
export function _isBetween(x, min, max, incl = '[)') {
|
|
33
36
|
if (incl === '[)') {
|
|
@@ -39,7 +42,6 @@ export function _isBetween(x, min, max, incl = '[)') {
|
|
|
39
42
|
else if (incl === '(]') {
|
|
40
43
|
return x > min && x <= max;
|
|
41
44
|
}
|
|
42
|
-
// ()
|
|
43
45
|
return x > min && x < max;
|
|
44
46
|
}
|
|
45
47
|
export function _clamp(x, minIncl, maxIncl) {
|
|
@@ -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
|
}
|
|
@@ -8,7 +8,7 @@ export function _safeJsonStringify(obj, replacer, spaces, cycleReplacer) {
|
|
|
8
8
|
// Try native first (as it's ~3 times faster)
|
|
9
9
|
return JSON.stringify(obj, replacer, spaces);
|
|
10
10
|
}
|
|
11
|
-
catch
|
|
11
|
+
catch {
|
|
12
12
|
// Native failed - resort to the "safe" serializer
|
|
13
13
|
return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
|
|
14
14
|
}
|
|
@@ -17,7 +17,7 @@ export function _safeJsonStringify(obj, replacer, spaces, cycleReplacer) {
|
|
|
17
17
|
function serializer(replacer, cycleReplacer) {
|
|
18
18
|
const stack = [];
|
|
19
19
|
const keys = [];
|
|
20
|
-
cycleReplacer
|
|
20
|
+
cycleReplacer ?? (cycleReplacer = function (key, value) {
|
|
21
21
|
if (stack[0] === value)
|
|
22
22
|
return '[Circular ~]';
|
|
23
23
|
return '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']';
|
package/dist-esm/web.js
CHANGED
|
@@ -14,8 +14,7 @@ export class InMemoryWebStorage {
|
|
|
14
14
|
// but can be implemented with Proxy
|
|
15
15
|
// [ name: string ]: any
|
|
16
16
|
getItem(key) {
|
|
17
|
-
|
|
18
|
-
return (_a = this.data[key]) !== null && _a !== void 0 ? _a : null;
|
|
17
|
+
return this.data[key] ?? null;
|
|
19
18
|
}
|
|
20
19
|
setItem(key, value) {
|
|
21
20
|
this.data[key] = String(value);
|
|
@@ -24,8 +23,7 @@ export class InMemoryWebStorage {
|
|
|
24
23
|
delete this.data[key];
|
|
25
24
|
}
|
|
26
25
|
key(index) {
|
|
27
|
-
|
|
28
|
-
return (_a = Object.keys(this.data)[index]) !== null && _a !== void 0 ? _a : null;
|
|
26
|
+
return Object.keys(this.data)[index] ?? null;
|
|
29
27
|
}
|
|
30
28
|
clear() {
|
|
31
29
|
this.data = {};
|
package/dist-esm/zod/zod.util.js
CHANGED
|
@@ -31,10 +31,9 @@ export class ZodValidationError extends ZodError {
|
|
|
31
31
|
return this.annotate();
|
|
32
32
|
}
|
|
33
33
|
annotate() {
|
|
34
|
-
var _a;
|
|
35
34
|
let objectTitle = this.schema.description;
|
|
36
35
|
if (typeof this.value === 'object' && this.value) {
|
|
37
|
-
const objectName = this.schema.description ||
|
|
36
|
+
const objectName = this.schema.description || this.value.constructor?.name;
|
|
38
37
|
const objectId = this.value['id'];
|
|
39
38
|
objectTitle = [objectName, objectId].filter(Boolean).join('.');
|
|
40
39
|
}
|
package/package.json
CHANGED
|
@@ -34,11 +34,14 @@ export function _runLessOften(percent: number): boolean {
|
|
|
34
34
|
* _isBetween(3, 1, 5) // true
|
|
35
35
|
* _isBetween(5, 1, 5) // false
|
|
36
36
|
* _isBetween(7, 1, 5) // false
|
|
37
|
+
*
|
|
38
|
+
* Also works with strings:
|
|
39
|
+
* _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
|
|
37
40
|
*/
|
|
38
|
-
export function _isBetween(
|
|
39
|
-
x:
|
|
40
|
-
min:
|
|
41
|
-
max:
|
|
41
|
+
export function _isBetween<T extends number | string>(
|
|
42
|
+
x: T,
|
|
43
|
+
min: T,
|
|
44
|
+
max: T,
|
|
42
45
|
incl: Inclusiveness = '[)',
|
|
43
46
|
): boolean {
|
|
44
47
|
if (incl === '[)') {
|
|
@@ -48,7 +51,6 @@ export function _isBetween(
|
|
|
48
51
|
} else if (incl === '(]') {
|
|
49
52
|
return x > min && x <= max
|
|
50
53
|
}
|
|
51
|
-
// ()
|
|
52
54
|
return x > min && x < max
|
|
53
55
|
}
|
|
54
56
|
|