@naturalcycles/js-lib 14.235.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.
@@ -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
- return __asyncGenerator(this, arguments, function* _a() {
31
- for (let i = fromIncl; i < toExcl; i += step) {
32
- yield yield __await(i);
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((_a = c.year) !== null && _a !== void 0 ? _a : d.getFullYear(), c.month ? c.month - 1 : d.getMonth(), c.day || d.getDate());
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 !== null && now !== void 0 ? now : new Date()).plus(-n, unit));
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 !== null && now !== void 0 ? now : new Date()).plus(-n, unit));
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 !== null && now !== void 0 ? now : new Date()).plus(-n, unit));
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 !== null && now !== void 0 ? now : new Date()).plus(-n, unit));
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 Object.assign(Object.assign({}, this.dateComponents()), this.timeComponents());
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 (method === null || method === void 0 ? void 0 : method.getInstanceCache) === 'function', 'method is not an AsyncMemo instance');
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(Object.assign(Object.assign({}, resp), { res }));
48
+ res = cfg.thenFn({
49
+ ...resp,
50
+ res,
51
+ });
50
52
  }
51
- (_a = cfg.finallyFn) === null || _a === void 0 ? void 0 : _a.call(cfg, resp);
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(Object.assign(Object.assign({}, resp), { err }));
68
+ cfg.catchFn({
69
+ ...resp,
70
+ err,
71
+ });
67
72
  handled = true;
68
73
  }
69
- (_b = cfg.finallyFn) === null || _b === void 0 ? void 0 : _b.call(cfg, resp);
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, Object.assign(Object.assign({ leading: true, trailing: true }, opt), { maxWait: 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 (method === null || method === void 0 ? void 0 : method.getInstanceCache) === 'function', 'method is not a Memo instance');
80
+ _assert(typeof method?.getInstanceCache === 'function', 'method is not a Memo instance');
81
81
  return method;
82
82
  }
@@ -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, Object.assign({ writable: true, configurable: true, enumerable: true }, pd));
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) => (Object.assign({ writable: true, configurable: true, enumerable: true }, 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.
@@ -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
- var _a;
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);
@@ -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', Object.assign({ userFriendly: true }, errorData));
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, Object.assign({ userFriendly: true }, errorData));
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, Object.assign({ userFriendly: true }, errorData));
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 = Object.assign(Object.assign({}, e.data), errorData);
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: Object.assign({}, e.data), // empty by default
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 === null || o === void 0 ? void 0 : o.error);
174
+ return _isErrorObject(o?.error);
172
175
  }
173
176
  export function _isHttpRequestErrorObject(o) {
174
- var _a;
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 = Object.assign(Object.assign({}, err.data), 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, Object.assign(Object.assign({}, opt), { name: 'HttpRequestError' }));
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, Object.assign(Object.assign({}, opt), { name: 'TimeoutError' }));
320
+ super(message, data, { ...opt, name: 'TimeoutError' });
316
321
  }
317
322
  }
318
323
  /**
@@ -27,7 +27,7 @@ export function _tryCatch(fn, opt = {}) {
27
27
  try {
28
28
  return await onError(_anyToError(err)); // eslint-disable-line @typescript-eslint/return-await
29
29
  }
30
- catch (_a) { }
30
+ catch { }
31
31
  }
32
32
  // returns undefined, but doesn't rethrow
33
33
  }
@@ -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(Object.assign({ url,
45
- method, responseType: 'void' }, opt));
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(Object.assign({ url,
52
- method, responseType: 'text' }, opt));
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(Object.assign({ url,
56
- method, responseType: 'json' }, opt));
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(Object.assign({ url, responseType: 'readableStream' }, opt));
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 = (_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status;
205
- if (((_c = res.fetchResponse) === null || _c === void 0 ? void 0 : _c.ok) || !req.throwHttpErrors) {
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 = ((_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status) || 0;
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
- ((_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status) || 0,
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 = (_b = res.fetchResponse.headers.get('retry-after')) !== null && _b !== void 0 ? _b : res.fetchResponse.headers.get('x-ratelimit-reset');
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 = ((_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status) || 0;
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 ((_f = (_e = (_d = (_c = res.err) === null || _c === void 0 ? void 0 : _c.cause) === null || _d === void 0 ? void 0 : _d.cause) === null || _e === void 0 ? void 0 : _e.message) === null || _f === void 0 ? void 0 : _f.includes('unexpected redirect')) {
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
- var _b;
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
- var _b;
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: Object.assign({}, defRetryOptions),
516
+ retry: { ...defRetryOptions },
507
517
  init: {
508
518
  method: cfg.method || 'GET',
509
- headers: _filterNullishValues(Object.assign({ 'user-agent': _a.userAgent }, cfg.headers)),
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 = Object.assign(Object.assign(Object.assign(Object.assign({}, _pick(this.cfg, [
522
- 'timeoutSeconds',
523
- 'retryPost',
524
- 'retry4xx',
525
- 'retry5xx',
526
- 'responseType',
527
- 'jsonReviver',
528
- 'logRequest',
529
- 'logRequestBody',
530
- 'logResponse',
531
- 'logResponseBody',
532
- 'debug',
533
- 'throwHttpErrors',
534
- ])), { started: Date.now() }), _omit(opt, ['method', 'headers', 'credentials'])), { inputUrl: opt.url || '', fullUrl: opt.url || '', retry: Object.assign(Object.assign({}, this.cfg.retry), _filterUndefinedValues(opt.retry || {})), init: _merge(Object.assign(Object.assign({}, this.cfg.init), { headers: Object.assign({}, this.cfg.init.headers), method: opt.method || this.cfg.init.method, credentials: opt.credentials || this.cfg.init.credentials, redirect: opt.redirect || this.cfg.init.redirect || 'follow' }), {
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(Object.assign(Object.assign({}, this.cfg.searchParams), opt.searchParams));
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
- return __asyncGenerator(this, arguments, function* _a() {
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]() { return __asyncGenerator(this, arguments, function* _a() { }); },
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
- try {
43
- for (var _d = true, _e = __asyncValues(this.it), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
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
- try {
63
- for (var _d = true, _e = __asyncValues(this.it), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
64
- _c = _f.value;
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
- try {
86
- for (var _d = true, _e = __asyncValues(this.it), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
87
- _c = _f.value;
88
- _d = false;
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
- try {
108
- for (var _d = true, _e = __asyncValues(this.it), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
109
- _c = _f.value;
110
- _d = false;
111
- const v = _c;
112
- const r = await cb(v, i++);
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
- return __asyncGenerator(this, arguments, function* _a() {
132
- var _b, e_5, _c, _d;
133
- let i = 0;
134
- try {
135
- for (var _e = true, it_1 = __asyncValues(it), it_1_1; it_1_1 = yield __await(it_1.next()), _b = it_1_1.done, !_b; _e = true) {
136
- _d = it_1_1.value;
137
- _e = false;
138
- const v = _d;
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
- return __asyncGenerator(this, arguments, function* _a() {
162
- var _b, e_6, _c, _d;
163
- let i = 0;
164
- try {
165
- for (var _e = true, it_2 = __asyncValues(it), it_2_1; it_2_1 = yield __await(it_2.next()), _b = it_2_1.done, !_b; _e = true) {
166
- _d = it_2_1.value;
167
- _e = false;
168
- const v = _d;
169
- const r = yield __await(mapper(v, i++));
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 = (_a = s2.minProperties) !== null && _a !== void 0 ? _a : s1.minProperties;
22
- s1.maxProperties = (_b = s2.maxProperties) !== null && _b !== void 0 ? _b : 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 = (_a = this.schema.transform) === null || _a === void 0 ? void 0 : _a.filter(s => s !== t);
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 (values === null || values === void 0 ? void 0 : values.length) ? values.reduce((a, b) => a + b) / values.length : null;
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 : Object.assign({}, 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 : Object.assign({}, 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
- var _a;
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 === null || o === void 0 ? void 0 : o[p], obj);
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
@@ -1,7 +1,6 @@
1
1
  export function polyfillDispose() {
2
- var _a, _b;
3
2
  // @ts-expect-error polyfill
4
- (_a = Symbol.dispose) !== null && _a !== void 0 ? _a : (Symbol.dispose = Symbol('Symbol.dispose'));
3
+ Symbol.dispose ?? (Symbol.dispose = Symbol('Symbol.dispose'));
5
4
  // @ts-expect-error polyfill
6
- (_b = Symbol.asyncDispose) !== null && _b !== void 0 ? _b : (Symbol.asyncDispose = Symbol('Symbol.asyncDispose'));
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
- (_a = this.onAbort) === null || _a === void 0 ? void 0 : _a.call(this);
21
+ this.onAbort?.();
23
22
  this.onAbort = undefined; // cleanup listener
24
23
  }
25
24
  clear() {
@@ -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 === null || logger === void 0 ? void 0 : logger.error(err);
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 === null || logger === void 0 ? void 0 : logger.error(err);
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 === null || logger === void 0 ? void 0 : logger.error(r.reason);
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 = Object.assign({
16
+ this.cfg = {
17
17
  // concurrency: Number.MAX_SAFE_INTEGER,
18
- errorMode: ErrorMode.THROW_IMMEDIATELY, logger: console, debug: false, resolveOn: 'finish' }, cfg);
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 (_a) { }
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 (_a) { }
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 (_a) {
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 Object.assign(Object.assign({}, readingTimeWithCount(words, options)), { words });
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 (_a) {
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 !== null && cycleReplacer !== void 0 ? cycleReplacer : (cycleReplacer = function (key, value) {
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('.') + ']';
@@ -117,7 +117,7 @@ export function _stringify(obj, opt = {}) {
117
117
  const { stringifyFn = globalStringifyFunction } = opt;
118
118
  s = stringifyFn(obj, undefined, 2);
119
119
  }
120
- catch (_a) {
120
+ catch {
121
121
  s = String(obj); // fallback
122
122
  }
123
123
  }
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
- var _a;
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
- var _a;
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 = {};
@@ -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 || ((_a = this.value.constructor) === null || _a === void 0 ? void 0 : _a.name);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.235.0",
3
+ "version": "14.236.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build-prod": "build-prod-esm-cjs",