@naturalcycles/js-lib 14.104.0 → 14.104.1
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-esm/datetime/localTime.js +2 -1
- package/dist-esm/decorators/createPromiseDecorator.js +5 -10
- package/dist-esm/decorators/debounce.js +1 -6
- package/dist-esm/error/assert.js +3 -12
- package/dist-esm/error/error.util.js +7 -8
- package/dist-esm/error/tryCatch.js +1 -1
- package/dist-esm/json-schema/jsonSchema.util.js +3 -2
- package/dist-esm/json-schema/jsonSchemaBuilder.js +2 -1
- package/dist-esm/math/math.util.js +1 -1
- package/dist-esm/object/object.util.js +4 -3
- package/dist-esm/promise/pMap.js +27 -15
- package/dist-esm/promise/pQueue.js +2 -7
- package/dist-esm/promise/pRetry.js +1 -4
- package/dist-esm/promise/pTimeout.js +1 -4
- package/dist-esm/string/json.util.js +1 -1
- package/dist-esm/string/safeJsonStringify.js +1 -1
- package/dist-esm/string/stringifyAny.js +1 -1
- package/dist-esm/vendor/is.js +8 -7
- package/package.json +1 -5
|
@@ -179,10 +179,11 @@ export class LocalTime {
|
|
|
179
179
|
return v === undefined ? this.get('second') : this.set('second', v);
|
|
180
180
|
}
|
|
181
181
|
setComponents(c, mutate = false) {
|
|
182
|
+
var _a;
|
|
182
183
|
const d = mutate ? this.$date : new Date(this.$date);
|
|
183
184
|
// Year, month and day set all-at-once, to avoid 30/31 (and 28/29) mishap
|
|
184
185
|
if (c.day || c.month !== undefined || c.year !== undefined) {
|
|
185
|
-
d.setFullYear(c.year
|
|
186
|
+
d.setFullYear((_a = c.year) !== null && _a !== void 0 ? _a : d.getFullYear(), c.month ? c.month - 1 : d.getMonth(), c.day || d.getDate());
|
|
186
187
|
}
|
|
187
188
|
if (c.hour !== undefined) {
|
|
188
189
|
d.setHours(c.hour);
|
|
@@ -19,6 +19,7 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
19
19
|
const key = String(propertyKey);
|
|
20
20
|
const methodSignature = _getTargetMethodSignature(target, key);
|
|
21
21
|
pd.value = async function (...args) {
|
|
22
|
+
var _a, _b;
|
|
22
23
|
// console.log(`@${cfg.decoratorName} called inside function`)
|
|
23
24
|
const started = Date.now();
|
|
24
25
|
try {
|
|
@@ -46,12 +47,9 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
46
47
|
started,
|
|
47
48
|
};
|
|
48
49
|
if (cfg.thenFn) {
|
|
49
|
-
res = cfg.thenFn({
|
|
50
|
-
...resp,
|
|
51
|
-
res,
|
|
52
|
-
});
|
|
50
|
+
res = cfg.thenFn(Object.assign(Object.assign({}, resp), { res }));
|
|
53
51
|
}
|
|
54
|
-
cfg.finallyFn
|
|
52
|
+
(_a = cfg.finallyFn) === null || _a === void 0 ? void 0 : _a.call(cfg, resp);
|
|
55
53
|
return res;
|
|
56
54
|
}
|
|
57
55
|
catch (err) {
|
|
@@ -66,13 +64,10 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
|
|
|
66
64
|
};
|
|
67
65
|
let handled = false;
|
|
68
66
|
if (cfg.catchFn) {
|
|
69
|
-
cfg.catchFn({
|
|
70
|
-
...resp,
|
|
71
|
-
err,
|
|
72
|
-
});
|
|
67
|
+
cfg.catchFn(Object.assign(Object.assign({}, resp), { err }));
|
|
73
68
|
handled = true;
|
|
74
69
|
}
|
|
75
|
-
cfg.finallyFn
|
|
70
|
+
(_b = cfg.finallyFn) === null || _b === void 0 ? void 0 : _b.call(cfg, resp);
|
|
76
71
|
if (!handled) {
|
|
77
72
|
throw err; // rethrow
|
|
78
73
|
}
|
|
@@ -105,10 +105,5 @@ 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, {
|
|
109
|
-
leading: true,
|
|
110
|
-
trailing: true,
|
|
111
|
-
...opt,
|
|
112
|
-
maxWait: wait,
|
|
113
|
-
});
|
|
108
|
+
return _debounce(func, wait, Object.assign(Object.assign({ leading: true, trailing: true }, opt), { maxWait: wait }));
|
|
114
109
|
}
|
package/dist-esm/error/assert.js
CHANGED
|
@@ -18,10 +18,7 @@ import { AppError } from './app.error';
|
|
|
18
18
|
export function _assert(condition, // will be evaluated as Boolean
|
|
19
19
|
message, errorData) {
|
|
20
20
|
if (!condition) {
|
|
21
|
-
throw new AssertionError(message || 'see stacktrace', {
|
|
22
|
-
userFriendly: true,
|
|
23
|
-
...errorData,
|
|
24
|
-
});
|
|
21
|
+
throw new AssertionError(message || 'see stacktrace', Object.assign({ userFriendly: true }, errorData));
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
24
|
/**
|
|
@@ -39,10 +36,7 @@ export function _assertEquals(actual, expected, message, errorData) {
|
|
|
39
36
|
]
|
|
40
37
|
.filter(Boolean)
|
|
41
38
|
.join('\n');
|
|
42
|
-
throw new AssertionError(msg, {
|
|
43
|
-
userFriendly: true,
|
|
44
|
-
...errorData,
|
|
45
|
-
});
|
|
39
|
+
throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
|
|
46
40
|
}
|
|
47
41
|
}
|
|
48
42
|
/**
|
|
@@ -60,10 +54,7 @@ export function _assertDeepEquals(actual, expected, message, errorData) {
|
|
|
60
54
|
]
|
|
61
55
|
.filter(Boolean)
|
|
62
56
|
.join('\n');
|
|
63
|
-
throw new AssertionError(msg, {
|
|
64
|
-
userFriendly: true,
|
|
65
|
-
...errorData,
|
|
66
|
-
});
|
|
57
|
+
throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
|
|
67
58
|
}
|
|
68
59
|
}
|
|
69
60
|
export function _assertIsError(err, message) {
|
|
@@ -21,8 +21,9 @@ export function _anyToError(o, errorClass = Error, opt) {
|
|
|
21
21
|
* Objects (not Errors) get converted to prettified JSON string (via `_stringifyAny`).
|
|
22
22
|
*/
|
|
23
23
|
export function _anyToErrorObject(o, opt) {
|
|
24
|
+
var _a;
|
|
24
25
|
if (o instanceof Error) {
|
|
25
|
-
return _errorToErrorObject(o, opt
|
|
26
|
+
return _errorToErrorObject(o, (_a = opt === null || opt === void 0 ? void 0 : opt.includeErrorStack) !== null && _a !== void 0 ? _a : true);
|
|
26
27
|
}
|
|
27
28
|
o = _jsonParseIfPossible(o);
|
|
28
29
|
if (_isHttpErrorResponse(o)) {
|
|
@@ -35,10 +36,7 @@ export function _anyToErrorObject(o, opt) {
|
|
|
35
36
|
// so, fair to return `data: {}` in the end
|
|
36
37
|
// Also we're sure it includes no "error name", e.g no `Error: ...`,
|
|
37
38
|
// so, fair to include `name: 'Error'`
|
|
38
|
-
const message = _stringifyAny(o, {
|
|
39
|
-
includeErrorData: true,
|
|
40
|
-
...opt,
|
|
41
|
-
});
|
|
39
|
+
const message = _stringifyAny(o, Object.assign({ includeErrorData: true }, opt));
|
|
42
40
|
return {
|
|
43
41
|
name: 'Error',
|
|
44
42
|
message,
|
|
@@ -49,7 +47,7 @@ export function _errorToErrorObject(e, includeErrorStack = true) {
|
|
|
49
47
|
const obj = {
|
|
50
48
|
name: e.name,
|
|
51
49
|
message: e.message,
|
|
52
|
-
data: {
|
|
50
|
+
data: Object.assign({}, e.data), // empty by default
|
|
53
51
|
};
|
|
54
52
|
if (includeErrorStack) {
|
|
55
53
|
obj.stack = e.stack;
|
|
@@ -83,13 +81,14 @@ export function _errorObjectToError(o, errorClass = Error) {
|
|
|
83
81
|
return err;
|
|
84
82
|
}
|
|
85
83
|
export function _isHttpErrorResponse(o) {
|
|
86
|
-
return _isHttpErrorObject(o
|
|
84
|
+
return _isHttpErrorObject(o === null || o === void 0 ? void 0 : o.error);
|
|
87
85
|
}
|
|
88
86
|
export function _isHttpErrorObject(o) {
|
|
87
|
+
var _a;
|
|
89
88
|
return (!!o &&
|
|
90
89
|
typeof o.name === 'string' &&
|
|
91
90
|
typeof o.message === 'string' &&
|
|
92
|
-
typeof o.data
|
|
91
|
+
typeof ((_a = o.data) === null || _a === void 0 ? void 0 : _a.httpStatusCode) === 'number');
|
|
93
92
|
}
|
|
94
93
|
/**
|
|
95
94
|
* Note: any instance of AppError is also automatically an ErrorObject
|
|
@@ -6,6 +6,7 @@ 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;
|
|
9
10
|
// Merge `properties`
|
|
10
11
|
Object.entries(s2.properties).forEach(([k, v]) => {
|
|
11
12
|
;
|
|
@@ -17,8 +18,8 @@ export function mergeJsonSchemaObjects(s1, s2) {
|
|
|
17
18
|
s1.patternProperties[k] = v;
|
|
18
19
|
});
|
|
19
20
|
s1.propertyNames = s2.propertyNames || s1.propertyNames;
|
|
20
|
-
s1.minProperties = s2.minProperties
|
|
21
|
-
s1.maxProperties = s2.maxProperties
|
|
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;
|
|
22
23
|
// Merge `required`
|
|
23
24
|
s1.required.push(...s2.required);
|
|
24
25
|
s1.required = _uniq(s1.required).sort();
|
|
@@ -250,11 +250,12 @@ export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
|
|
|
250
250
|
return this;
|
|
251
251
|
}
|
|
252
252
|
transformModify(t, add) {
|
|
253
|
+
var _a;
|
|
253
254
|
if (add) {
|
|
254
255
|
this.schema.transform = _uniq([...(this.schema.transform || []), t]);
|
|
255
256
|
}
|
|
256
257
|
else {
|
|
257
|
-
this.schema.transform = this.schema.transform
|
|
258
|
+
this.schema.transform = (_a = this.schema.transform) === null || _a === void 0 ? void 0 : _a.filter(s => s !== t);
|
|
258
259
|
}
|
|
259
260
|
return this;
|
|
260
261
|
}
|
|
@@ -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
|
|
17
|
+
return (values === null || values === void 0 ? void 0 : 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.
|
|
@@ -29,7 +29,7 @@ export function _omit(obj, props, mutate = false) {
|
|
|
29
29
|
return props.reduce((r, prop) => {
|
|
30
30
|
delete r[prop];
|
|
31
31
|
return r;
|
|
32
|
-
}, mutate ? obj : {
|
|
32
|
+
}, mutate ? obj : Object.assign({}, obj));
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Returns object with filtered keys from `props` array.
|
|
@@ -76,7 +76,7 @@ export function _filterObject(obj, predicate, mutate = false) {
|
|
|
76
76
|
if (!predicate(k, r[k], obj))
|
|
77
77
|
delete r[k];
|
|
78
78
|
return r;
|
|
79
|
-
}, mutate ? obj : {
|
|
79
|
+
}, mutate ? obj : Object.assign({}, obj));
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* var users = {
|
|
@@ -137,7 +137,8 @@ export function _mapObject(obj, mapper) {
|
|
|
137
137
|
}, {});
|
|
138
138
|
}
|
|
139
139
|
export function _findKeyByValue(obj, v) {
|
|
140
|
-
|
|
140
|
+
var _a;
|
|
141
|
+
return (_a = Object.entries(obj).find(([_, value]) => value === v)) === null || _a === void 0 ? void 0 : _a[0];
|
|
141
142
|
}
|
|
142
143
|
export function _objectNullValuesToUndefined(obj, mutate = false) {
|
|
143
144
|
return _mapValues(obj, (_k, v) => (v === null ? undefined : v), mutate);
|
package/dist-esm/promise/pMap.js
CHANGED
|
@@ -6,6 +6,7 @@ Improvements:
|
|
|
6
6
|
- Included Typescript typings (no need for @types/p-map)
|
|
7
7
|
- Compatible with pProps (that had typings issues)
|
|
8
8
|
*/
|
|
9
|
+
import { __asyncValues } from "tslib";
|
|
9
10
|
import { END, ErrorMode, SKIP } from '..';
|
|
10
11
|
import { AggregatedError } from './AggregatedError';
|
|
11
12
|
/**
|
|
@@ -35,6 +36,7 @@ import { AggregatedError } from './AggregatedError';
|
|
|
35
36
|
* })();
|
|
36
37
|
*/
|
|
37
38
|
export async function pMap(iterable, mapper, opt = {}) {
|
|
39
|
+
var e_1, _a;
|
|
38
40
|
const ret = [];
|
|
39
41
|
// const iterator = iterable[Symbol.iterator]()
|
|
40
42
|
const items = [...iterable];
|
|
@@ -48,23 +50,33 @@ export async function pMap(iterable, mapper, opt = {}) {
|
|
|
48
50
|
let currentIndex = 0;
|
|
49
51
|
// Special cases that are able to preserve async stack traces
|
|
50
52
|
if (concurrency === 1) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (errorMode === ErrorMode.THROW_IMMEDIATELY)
|
|
62
|
-
throw err;
|
|
63
|
-
if (errorMode === ErrorMode.THROW_AGGREGATED) {
|
|
64
|
-
errors.push(err);
|
|
53
|
+
try {
|
|
54
|
+
// Special case for concurrency == 1
|
|
55
|
+
for (var items_1 = __asyncValues(items), items_1_1; items_1_1 = await items_1.next(), !items_1_1.done;) {
|
|
56
|
+
const item = items_1_1.value;
|
|
57
|
+
try {
|
|
58
|
+
const r = await mapper(item, currentIndex++);
|
|
59
|
+
if (r === END)
|
|
60
|
+
break;
|
|
61
|
+
if (r !== SKIP)
|
|
62
|
+
ret.push(r);
|
|
65
63
|
}
|
|
66
|
-
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (errorMode === ErrorMode.THROW_IMMEDIATELY)
|
|
66
|
+
throw err;
|
|
67
|
+
if (errorMode === ErrorMode.THROW_AGGREGATED) {
|
|
68
|
+
errors.push(err);
|
|
69
|
+
}
|
|
70
|
+
// otherwise, suppress completely
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
75
|
+
finally {
|
|
76
|
+
try {
|
|
77
|
+
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) await _a.call(items_1);
|
|
67
78
|
}
|
|
79
|
+
finally { if (e_1) throw e_1.error; }
|
|
68
80
|
}
|
|
69
81
|
if (errors.length) {
|
|
70
82
|
throw new AggregatedError(errors, ret);
|
|
@@ -13,14 +13,9 @@ export class PQueue {
|
|
|
13
13
|
this.inFlight = 0;
|
|
14
14
|
this.queue = [];
|
|
15
15
|
this.onIdleListeners = [];
|
|
16
|
-
this.cfg = {
|
|
16
|
+
this.cfg = Object.assign({
|
|
17
17
|
// concurrency: Number.MAX_SAFE_INTEGER,
|
|
18
|
-
errorMode: ErrorMode.THROW_IMMEDIATELY,
|
|
19
|
-
logger: console,
|
|
20
|
-
debug: false,
|
|
21
|
-
resolveOn: 'finish',
|
|
22
|
-
...cfg,
|
|
23
|
-
};
|
|
18
|
+
errorMode: ErrorMode.THROW_IMMEDIATELY, logger: console, debug: false, resolveOn: 'finish' }, cfg);
|
|
24
19
|
if (!cfg.debug) {
|
|
25
20
|
this.debug = () => { };
|
|
26
21
|
}
|
|
@@ -32,10 +32,7 @@ export async function pTimeout(promise, opt) {
|
|
|
32
32
|
catch (err) {
|
|
33
33
|
if (fakeError)
|
|
34
34
|
err.stack = fakeError.stack; // keep original stack
|
|
35
|
-
err.data = {
|
|
36
|
-
...err.data,
|
|
37
|
-
...opt.errorData,
|
|
38
|
-
};
|
|
35
|
+
err.data = Object.assign(Object.assign({}, err.data), opt.errorData);
|
|
39
36
|
reject(err);
|
|
40
37
|
}
|
|
41
38
|
return;
|
|
@@ -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 (_a) {
|
|
12
12
|
// Native failed - resort to the "safe" serializer
|
|
13
13
|
return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
|
|
14
14
|
}
|
package/dist-esm/vendor/is.js
CHANGED
|
@@ -138,15 +138,15 @@ is.array = (value, assertion) => {
|
|
|
138
138
|
}
|
|
139
139
|
return value.every(assertion);
|
|
140
140
|
};
|
|
141
|
-
is.buffer = (value) => value
|
|
141
|
+
is.buffer = (value) => { var _a, _b, _c; return (_c = (_b = (_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.isBuffer) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : false; };
|
|
142
142
|
is.nullOrUndefined = (value) => is.null_(value) || is.undefined(value);
|
|
143
143
|
is.object = (value) => !is.null_(value) && (typeof value === 'object' || is.function_(value));
|
|
144
|
-
is.iterable = (value) => is.function_(value
|
|
145
|
-
is.asyncIterable = (value) => is.function_(value
|
|
144
|
+
is.iterable = (value) => is.function_(value === null || value === void 0 ? void 0 : value[Symbol.iterator]);
|
|
145
|
+
is.asyncIterable = (value) => is.function_(value === null || value === void 0 ? void 0 : value[Symbol.asyncIterator]);
|
|
146
146
|
is.generator = (value) => is.iterable(value) && is.function_(value.next) && is.function_(value.throw);
|
|
147
147
|
is.asyncGenerator = (value) => is.asyncIterable(value) && is.function_(value.next) && is.function_(value.throw);
|
|
148
148
|
is.nativePromise = (value) => isObjectOfType('Promise')(value);
|
|
149
|
-
const hasPromiseAPI = (value) => is.function_(value
|
|
149
|
+
const hasPromiseAPI = (value) => is.function_(value === null || value === void 0 ? void 0 : value.then) && is.function_(value === null || value === void 0 ? void 0 : value.catch);
|
|
150
150
|
is.promise = (value) => is.nativePromise(value) || hasPromiseAPI(value);
|
|
151
151
|
is.generatorFunction = isObjectOfType('GeneratorFunction');
|
|
152
152
|
is.asyncGeneratorFunction = (value) => getObjectType(value) === 'AsyncGeneratorFunction';
|
|
@@ -184,7 +184,7 @@ is.urlString = (value) => {
|
|
|
184
184
|
new URL(value); // eslint-disable-line no-new
|
|
185
185
|
return true;
|
|
186
186
|
}
|
|
187
|
-
catch {
|
|
187
|
+
catch (_a) {
|
|
188
188
|
return false;
|
|
189
189
|
}
|
|
190
190
|
};
|
|
@@ -235,13 +235,14 @@ is.domElement = (value) => {
|
|
|
235
235
|
DOM_PROPERTIES_TO_CHECK.every(property => property in value));
|
|
236
236
|
};
|
|
237
237
|
is.observable = (value) => {
|
|
238
|
+
var _a, _b, _c, _d;
|
|
238
239
|
if (!value) {
|
|
239
240
|
return false;
|
|
240
241
|
}
|
|
241
|
-
if (value === value[Symbol.observable]
|
|
242
|
+
if (value === ((_b = (_a = value)[Symbol.observable]) === null || _b === void 0 ? void 0 : _b.call(_a))) {
|
|
242
243
|
return true;
|
|
243
244
|
}
|
|
244
|
-
if (value === value['@@observable']
|
|
245
|
+
if (value === ((_d = (_c = value)['@@observable']) === null || _d === void 0 ? void 0 : _d.call(_c))) {
|
|
245
246
|
return true;
|
|
246
247
|
}
|
|
247
248
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.104.
|
|
3
|
+
"version": "14.104.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"build-prod": "build-prod-esm-cjs",
|
|
@@ -36,10 +36,6 @@
|
|
|
36
36
|
"module": "dist-esm/index.js",
|
|
37
37
|
"types": "dist/index.d.ts",
|
|
38
38
|
"sideEffects": false,
|
|
39
|
-
"exports": {
|
|
40
|
-
"import": "./dist-esm/index.js",
|
|
41
|
-
"require": "./dist/index.js"
|
|
42
|
-
},
|
|
43
39
|
"engines": {
|
|
44
40
|
"node": ">=14.15.0"
|
|
45
41
|
},
|