@naturalcycles/js-lib 14.73.0 → 14.76.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/decorators/logMethod.decorator.js +1 -3
- package/dist/decorators/timeout.decorator.js +9 -1
- package/dist/error/try.d.ts +20 -0
- package/dist/error/try.js +47 -1
- package/dist/index.d.ts +20 -20
- package/dist/index.js +20 -52
- package/dist/math/math.util.d.ts +4 -0
- package/dist/math/math.util.js +18 -1
- package/dist/math/stack.util.d.ts +3 -2
- package/dist/math/stack.util.js +8 -5
- package/dist/promise/pTimeout.d.ts +10 -1
- package/dist/promise/pTimeout.js +43 -29
- package/dist/seq/seq.d.ts +30 -7
- package/dist/seq/seq.js +126 -9
- package/dist/string/stringifyAny.js +12 -10
- package/dist/unit/size.util.d.ts +6 -0
- package/dist/unit/size.util.js +33 -10
- package/dist-esm/decorators/logMethod.decorator.js +2 -4
- package/dist-esm/decorators/timeout.decorator.js +9 -1
- package/dist-esm/error/try.js +43 -0
- package/dist-esm/index.js +20 -20
- package/dist-esm/math/math.util.js +16 -0
- package/dist-esm/math/stack.util.js +9 -6
- package/dist-esm/promise/pTimeout.js +40 -28
- package/dist-esm/seq/seq.js +124 -8
- package/dist-esm/string/stringifyAny.js +12 -10
- package/dist-esm/unit/size.util.js +31 -9
- package/package.json +1 -1
- package/src/decorators/logMethod.decorator.ts +2 -4
- package/src/decorators/timeout.decorator.ts +12 -1
- package/src/error/try.ts +44 -0
- package/src/index.ts +20 -60
- package/src/math/math.util.ts +21 -0
- package/src/math/stack.util.ts +11 -7
- package/src/promise/pTimeout.ts +41 -29
- package/src/seq/seq.ts +144 -13
- package/src/string/stringifyAny.ts +13 -9
- package/src/unit/size.util.ts +22 -6
|
@@ -20,9 +20,7 @@ const decorator_util_1 = require("./decorator.util");
|
|
|
20
20
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
21
21
|
function _LogMethod(opt = {}) {
|
|
22
22
|
return (target, key, descriptor) => {
|
|
23
|
-
|
|
24
|
-
throw new TypeError('@_LogMethod can be applied only to methods');
|
|
25
|
-
}
|
|
23
|
+
(0, __1._assert)(typeof descriptor.value === 'function', '@_LogMethod can be applied only to methods');
|
|
26
24
|
const originalFn = descriptor.value;
|
|
27
25
|
const keyStr = String(key);
|
|
28
26
|
const { avg, noLogArgs, logStart, logResult, noLogResultLength, logger = console } = opt;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._Timeout = void 0;
|
|
4
|
+
const assert_1 = require("../error/assert");
|
|
4
5
|
const pTimeout_1 = require("../promise/pTimeout");
|
|
6
|
+
const decorator_util_1 = require("./decorator.util");
|
|
5
7
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
6
8
|
function _Timeout(opt) {
|
|
7
9
|
return (target, key, descriptor) => {
|
|
10
|
+
(0, assert_1._assert)(typeof descriptor.value === 'function', '@_Timeout can be applied only to methods');
|
|
8
11
|
const originalFn = descriptor.value;
|
|
9
|
-
|
|
12
|
+
const keyStr = String(key);
|
|
13
|
+
descriptor.value = async function (...args) {
|
|
14
|
+
const ctx = this;
|
|
15
|
+
opt.name || (opt.name = (0, decorator_util_1._getMethodSignature)(ctx, keyStr));
|
|
16
|
+
return await (0, pTimeout_1.pTimeout)(originalFn.apply(this, args), opt);
|
|
17
|
+
};
|
|
10
18
|
return descriptor;
|
|
11
19
|
};
|
|
12
20
|
}
|
package/dist/error/try.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AnyFunction } from '../types';
|
|
2
|
+
import { AppError } from './app.error';
|
|
1
3
|
/**
|
|
2
4
|
* Calls a function, returns a Tuple of [error, value].
|
|
3
5
|
* Allows to write shorter code that avoids `try/catch`.
|
|
@@ -22,3 +24,21 @@ export declare function _try<ERR = unknown, RETURN = void>(fn: () => RETURN): [e
|
|
|
22
24
|
* but you should check for `err` presense first!
|
|
23
25
|
*/
|
|
24
26
|
export declare function pTry<ERR = unknown, RETURN = void>(promise: Promise<RETURN>): Promise<[err: ERR | null, value: Awaited<RETURN>]>;
|
|
27
|
+
/**
|
|
28
|
+
* It is thrown when Error was expected, but didn't happen
|
|
29
|
+
* ("pass" happened instead).
|
|
30
|
+
* "Pass" means "no error".
|
|
31
|
+
*/
|
|
32
|
+
export declare class UnexpectedPassError extends AppError {
|
|
33
|
+
constructor();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Calls `fn`, expects is to throw, catches the expected error and returns.
|
|
37
|
+
* If error was NOT thrown - throws UnexpectedPassError instead.
|
|
38
|
+
*/
|
|
39
|
+
export declare function _expectedError<ERR = Error>(fn: AnyFunction): ERR;
|
|
40
|
+
/**
|
|
41
|
+
* Awaits passed `promise`, expects is to throw (reject), catches the expected error and returns.
|
|
42
|
+
* If error was NOT thrown - throws UnexpectedPassError instead.
|
|
43
|
+
*/
|
|
44
|
+
export declare function pExpectedError<ERR = Error>(promise: Promise<any>): Promise<ERR>;
|
package/dist/error/try.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pTry = exports._try = void 0;
|
|
3
|
+
exports.pExpectedError = exports._expectedError = exports.UnexpectedPassError = exports.pTry = exports._try = void 0;
|
|
4
|
+
const app_error_1 = require("./app.error");
|
|
4
5
|
/**
|
|
5
6
|
* Calls a function, returns a Tuple of [error, value].
|
|
6
7
|
* Allows to write shorter code that avoids `try/catch`.
|
|
@@ -43,3 +44,48 @@ async function pTry(promise) {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
exports.pTry = pTry;
|
|
47
|
+
/**
|
|
48
|
+
* It is thrown when Error was expected, but didn't happen
|
|
49
|
+
* ("pass" happened instead).
|
|
50
|
+
* "Pass" means "no error".
|
|
51
|
+
*/
|
|
52
|
+
class UnexpectedPassError extends app_error_1.AppError {
|
|
53
|
+
constructor() {
|
|
54
|
+
super('_expectedError passed unexpectedly');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.UnexpectedPassError = UnexpectedPassError;
|
|
58
|
+
/**
|
|
59
|
+
* Calls `fn`, expects is to throw, catches the expected error and returns.
|
|
60
|
+
* If error was NOT thrown - throws UnexpectedPassError instead.
|
|
61
|
+
*/
|
|
62
|
+
function _expectedError(fn) {
|
|
63
|
+
try {
|
|
64
|
+
fn();
|
|
65
|
+
// Unexpected!
|
|
66
|
+
throw new UnexpectedPassError();
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (err instanceof UnexpectedPassError)
|
|
70
|
+
throw err; // re-throw
|
|
71
|
+
return err; // this is expected!
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports._expectedError = _expectedError;
|
|
75
|
+
/**
|
|
76
|
+
* Awaits passed `promise`, expects is to throw (reject), catches the expected error and returns.
|
|
77
|
+
* If error was NOT thrown - throws UnexpectedPassError instead.
|
|
78
|
+
*/
|
|
79
|
+
async function pExpectedError(promise) {
|
|
80
|
+
try {
|
|
81
|
+
await promise;
|
|
82
|
+
// Unexpected!
|
|
83
|
+
throw new UnexpectedPassError();
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
if (err instanceof UnexpectedPassError)
|
|
87
|
+
throw err; // re-throw
|
|
88
|
+
return err; // this is expected!
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.pExpectedError = pExpectedError;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,27 +3,27 @@ export * from './lazy';
|
|
|
3
3
|
export * from './string/url.util';
|
|
4
4
|
export * from './array/range';
|
|
5
5
|
import { PromiseDecoratorCfg, PromiseDecoratorResp, _createPromiseDecorator } from './decorators/createPromiseDecorator';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export * from './decorators/debounce';
|
|
7
|
+
export * from './decorators/debounce.decorator';
|
|
8
|
+
export * from './decorators/decorator.util';
|
|
9
|
+
export * from './decorators/logMethod.decorator';
|
|
10
|
+
export * from './decorators/memo.decorator';
|
|
11
11
|
import { MemoCache } from './decorators/memo.util';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export * from './decorators/memoFn';
|
|
13
|
+
export * from './decorators/retry.decorator';
|
|
14
|
+
export * from './decorators/timeout.decorator';
|
|
15
|
+
export * from './error/app.error';
|
|
16
|
+
export * from './error/assert';
|
|
17
17
|
import { Admin401ErrorData, Admin403ErrorData, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse } from './error/error.model';
|
|
18
18
|
export * from './error/error.util';
|
|
19
19
|
import { ErrorMode } from './error/errorMode';
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
export * from './error/http.error';
|
|
21
|
+
export * from './error/try';
|
|
22
22
|
import { TryCatchOptions, _TryCatch, _tryCatch } from './error/tryCatch';
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
export * from './json-schema/from-data/generateJsonSchemaFromData';
|
|
24
|
+
export * from './json-schema/jsonSchema.cnst';
|
|
25
25
|
import { JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNot, JsonSchemaNull, JsonSchemaNumber, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaOneOf, JsonSchemaRef, JsonSchemaString, JsonSchemaTuple } from './json-schema/jsonSchema.model';
|
|
26
|
-
|
|
26
|
+
export * from './json-schema/jsonSchema.util';
|
|
27
27
|
import { jsonSchema, JsonSchemaAnyBuilder, JsonSchemaBuilder } from './json-schema/jsonSchemaBuilder';
|
|
28
28
|
export * from './math/math.util';
|
|
29
29
|
export * from './math/sma';
|
|
@@ -43,21 +43,21 @@ import { pMap, PMapOptions } from './promise/pMap';
|
|
|
43
43
|
export * from './promise/pProps';
|
|
44
44
|
import { pRetry, PRetryOptions } from './promise/pRetry';
|
|
45
45
|
export * from './promise/pState';
|
|
46
|
-
import { pTimeout, PTimeoutOptions } from './promise/pTimeout';
|
|
46
|
+
import { pTimeout, pTimeoutFn, PTimeoutOptions } from './promise/pTimeout';
|
|
47
47
|
export * from './promise/pTuple';
|
|
48
48
|
export * from './string/case';
|
|
49
49
|
export * from './string/json.util';
|
|
50
50
|
export * from './string/string.util';
|
|
51
51
|
import { JsonStringifyFunction, StringifyAnyOptions, _stringifyAny } from './string/stringifyAny';
|
|
52
|
-
|
|
52
|
+
export * from './time/time.util';
|
|
53
53
|
import { Class, ConditionalExcept, ConditionalPick, Merge, Promisable, ReadonlyDeep, Simplify } from './typeFest';
|
|
54
54
|
import { AsyncMapper, AsyncPredicate, BaseDBEntity, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, Saved, Unsaved, BatchResult, InstanceId, IsoDate, IsoDateTime, KeyValueTuple, Mapper, ObjectMapper, ObjectPredicate, Predicate, PromiseMap, AnyObject, AnyFunction, Reviver, SavedDBEntity, StringMap, UnixTimestamp, ValueOf, ValuesOf, AbortableMapper, AbortableAsyncPredicate, AbortableAsyncMapper, AbortablePredicate, END, SKIP, _noop, _objectKeys, _passNothingPredicate, _passthroughMapper, _passthroughPredicate, _passUndefinedMapper, _stringMapEntries, _stringMapValues } from './types';
|
|
55
|
-
|
|
55
|
+
export * from './unit/size.util';
|
|
56
56
|
import { is } from './vendor/is';
|
|
57
57
|
import { CommonLogLevel, CommonLogFunction, CommonLogger, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, CommonLogWithLevelFunction, commonLoggerCreate } from './log/commonLogger';
|
|
58
|
-
|
|
58
|
+
export * from './string/safeJsonStringify';
|
|
59
59
|
import { PQueue, PQueueCfg } from './promise/pQueue';
|
|
60
60
|
export * from './seq/seq';
|
|
61
61
|
export * from './math/stack.util';
|
|
62
62
|
export type { AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateTime, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestamp, BaseDBEntity, SavedDBEntity, Saved, Unsaved, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
|
|
63
|
-
export { is,
|
|
63
|
+
export { is, _createPromiseDecorator, _stringMapValues, _stringMapEntries, _objectKeys, pMap, _passthroughMapper, _passUndefinedMapper, _passthroughPredicate, _passNothingPredicate, _noop, ErrorMode, pDefer, AggregatedError, pRetry, pTimeout, pTimeoutFn, _tryCatch, _TryCatch, _stringifyAny, jsonSchema, JsonSchemaAnyBuilder, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, commonLoggerCreate, PQueue, END, SKIP, };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.SKIP = exports.END = exports.PQueue = exports._safeJsonStringify = exports.commonLoggerCreate = exports.commonLoggerPrefix = exports.commonLoggerPipe = exports.commonLogLevelNumber = exports.commonLoggerNoop = exports.commonLoggerMinLevel = exports.generateJsonSchemaFromData = exports.JSON_SCHEMA_ORDER = void 0;
|
|
3
|
+
exports.SKIP = exports.END = exports.PQueue = exports.commonLoggerCreate = exports.commonLoggerPrefix = exports.commonLoggerPipe = exports.commonLogLevelNumber = exports.commonLoggerNoop = exports.commonLoggerMinLevel = exports.JsonSchemaAnyBuilder = exports.jsonSchema = exports._stringifyAny = exports._TryCatch = exports._tryCatch = exports.pTimeoutFn = exports.pTimeout = exports.pRetry = exports.AggregatedError = exports.pDefer = exports.ErrorMode = exports._noop = exports._passNothingPredicate = exports._passthroughPredicate = exports._passUndefinedMapper = exports._passthroughMapper = exports.pMap = exports._objectKeys = exports._stringMapEntries = exports._stringMapValues = exports._createPromiseDecorator = exports.is = void 0;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
6
5
|
(0, tslib_1.__exportStar)(require("./array/array.util"), exports);
|
|
7
6
|
(0, tslib_1.__exportStar)(require("./lazy"), exports);
|
|
@@ -9,52 +8,27 @@ const tslib_1 = require("tslib");
|
|
|
9
8
|
(0, tslib_1.__exportStar)(require("./array/range"), exports);
|
|
10
9
|
const createPromiseDecorator_1 = require("./decorators/createPromiseDecorator");
|
|
11
10
|
Object.defineProperty(exports, "_createPromiseDecorator", { enumerable: true, get: function () { return createPromiseDecorator_1._createPromiseDecorator; } });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const memo_decorator_1 = require("./decorators/memo.decorator");
|
|
23
|
-
Object.defineProperty(exports, "_Memo", { enumerable: true, get: function () { return memo_decorator_1._Memo; } });
|
|
24
|
-
const memoFn_1 = require("./decorators/memoFn");
|
|
25
|
-
Object.defineProperty(exports, "_memoFn", { enumerable: true, get: function () { return memoFn_1._memoFn; } });
|
|
26
|
-
const retry_decorator_1 = require("./decorators/retry.decorator");
|
|
27
|
-
Object.defineProperty(exports, "_Retry", { enumerable: true, get: function () { return retry_decorator_1._Retry; } });
|
|
28
|
-
const timeout_decorator_1 = require("./decorators/timeout.decorator");
|
|
29
|
-
Object.defineProperty(exports, "_Timeout", { enumerable: true, get: function () { return timeout_decorator_1._Timeout; } });
|
|
30
|
-
const app_error_1 = require("./error/app.error");
|
|
31
|
-
Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return app_error_1.AppError; } });
|
|
32
|
-
const assert_1 = require("./error/assert");
|
|
33
|
-
Object.defineProperty(exports, "AssertionError", { enumerable: true, get: function () { return assert_1.AssertionError; } });
|
|
34
|
-
Object.defineProperty(exports, "_assert", { enumerable: true, get: function () { return assert_1._assert; } });
|
|
35
|
-
Object.defineProperty(exports, "_assertDeepEquals", { enumerable: true, get: function () { return assert_1._assertDeepEquals; } });
|
|
36
|
-
Object.defineProperty(exports, "_assertEquals", { enumerable: true, get: function () { return assert_1._assertEquals; } });
|
|
37
|
-
Object.defineProperty(exports, "_assertIsError", { enumerable: true, get: function () { return assert_1._assertIsError; } });
|
|
38
|
-
Object.defineProperty(exports, "_assertIsNumber", { enumerable: true, get: function () { return assert_1._assertIsNumber; } });
|
|
39
|
-
Object.defineProperty(exports, "_assertIsString", { enumerable: true, get: function () { return assert_1._assertIsString; } });
|
|
40
|
-
Object.defineProperty(exports, "_assertTypeOf", { enumerable: true, get: function () { return assert_1._assertTypeOf; } });
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./decorators/debounce"), exports);
|
|
12
|
+
(0, tslib_1.__exportStar)(require("./decorators/debounce.decorator"), exports);
|
|
13
|
+
(0, tslib_1.__exportStar)(require("./decorators/decorator.util"), exports);
|
|
14
|
+
(0, tslib_1.__exportStar)(require("./decorators/logMethod.decorator"), exports);
|
|
15
|
+
(0, tslib_1.__exportStar)(require("./decorators/memo.decorator"), exports);
|
|
16
|
+
(0, tslib_1.__exportStar)(require("./decorators/memoFn"), exports);
|
|
17
|
+
(0, tslib_1.__exportStar)(require("./decorators/retry.decorator"), exports);
|
|
18
|
+
(0, tslib_1.__exportStar)(require("./decorators/timeout.decorator"), exports);
|
|
19
|
+
(0, tslib_1.__exportStar)(require("./error/app.error"), exports);
|
|
20
|
+
(0, tslib_1.__exportStar)(require("./error/assert"), exports);
|
|
41
21
|
(0, tslib_1.__exportStar)(require("./error/error.util"), exports);
|
|
42
22
|
const errorMode_1 = require("./error/errorMode");
|
|
43
23
|
Object.defineProperty(exports, "ErrorMode", { enumerable: true, get: function () { return errorMode_1.ErrorMode; } });
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const try_1 = require("./error/try");
|
|
47
|
-
Object.defineProperty(exports, "_try", { enumerable: true, get: function () { return try_1._try; } });
|
|
48
|
-
Object.defineProperty(exports, "pTry", { enumerable: true, get: function () { return try_1.pTry; } });
|
|
24
|
+
(0, tslib_1.__exportStar)(require("./error/http.error"), exports);
|
|
25
|
+
(0, tslib_1.__exportStar)(require("./error/try"), exports);
|
|
49
26
|
const tryCatch_1 = require("./error/tryCatch");
|
|
50
27
|
Object.defineProperty(exports, "_TryCatch", { enumerable: true, get: function () { return tryCatch_1._TryCatch; } });
|
|
51
28
|
Object.defineProperty(exports, "_tryCatch", { enumerable: true, get: function () { return tryCatch_1._tryCatch; } });
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Object.defineProperty(exports, "JSON_SCHEMA_ORDER", { enumerable: true, get: function () { return jsonSchema_cnst_1.JSON_SCHEMA_ORDER; } });
|
|
56
|
-
const jsonSchema_util_1 = require("./json-schema/jsonSchema.util");
|
|
57
|
-
Object.defineProperty(exports, "mergeJsonSchemaObjects", { enumerable: true, get: function () { return jsonSchema_util_1.mergeJsonSchemaObjects; } });
|
|
29
|
+
(0, tslib_1.__exportStar)(require("./json-schema/from-data/generateJsonSchemaFromData"), exports);
|
|
30
|
+
(0, tslib_1.__exportStar)(require("./json-schema/jsonSchema.cnst"), exports);
|
|
31
|
+
(0, tslib_1.__exportStar)(require("./json-schema/jsonSchema.util"), exports);
|
|
58
32
|
const jsonSchemaBuilder_1 = require("./json-schema/jsonSchemaBuilder");
|
|
59
33
|
Object.defineProperty(exports, "jsonSchema", { enumerable: true, get: function () { return jsonSchemaBuilder_1.jsonSchema; } });
|
|
60
34
|
Object.defineProperty(exports, "JsonSchemaAnyBuilder", { enumerable: true, get: function () { return jsonSchemaBuilder_1.JsonSchemaAnyBuilder; } });
|
|
@@ -82,15 +56,14 @@ Object.defineProperty(exports, "pRetry", { enumerable: true, get: function () {
|
|
|
82
56
|
(0, tslib_1.__exportStar)(require("./promise/pState"), exports);
|
|
83
57
|
const pTimeout_1 = require("./promise/pTimeout");
|
|
84
58
|
Object.defineProperty(exports, "pTimeout", { enumerable: true, get: function () { return pTimeout_1.pTimeout; } });
|
|
59
|
+
Object.defineProperty(exports, "pTimeoutFn", { enumerable: true, get: function () { return pTimeout_1.pTimeoutFn; } });
|
|
85
60
|
(0, tslib_1.__exportStar)(require("./promise/pTuple"), exports);
|
|
86
61
|
(0, tslib_1.__exportStar)(require("./string/case"), exports);
|
|
87
62
|
(0, tslib_1.__exportStar)(require("./string/json.util"), exports);
|
|
88
63
|
(0, tslib_1.__exportStar)(require("./string/string.util"), exports);
|
|
89
64
|
const stringifyAny_1 = require("./string/stringifyAny");
|
|
90
65
|
Object.defineProperty(exports, "_stringifyAny", { enumerable: true, get: function () { return stringifyAny_1._stringifyAny; } });
|
|
91
|
-
|
|
92
|
-
Object.defineProperty(exports, "_ms", { enumerable: true, get: function () { return time_util_1._ms; } });
|
|
93
|
-
Object.defineProperty(exports, "_since", { enumerable: true, get: function () { return time_util_1._since; } });
|
|
66
|
+
(0, tslib_1.__exportStar)(require("./time/time.util"), exports);
|
|
94
67
|
const types_1 = require("./types");
|
|
95
68
|
Object.defineProperty(exports, "END", { enumerable: true, get: function () { return types_1.END; } });
|
|
96
69
|
Object.defineProperty(exports, "SKIP", { enumerable: true, get: function () { return types_1.SKIP; } });
|
|
@@ -102,11 +75,7 @@ Object.defineProperty(exports, "_passthroughPredicate", { enumerable: true, get:
|
|
|
102
75
|
Object.defineProperty(exports, "_passUndefinedMapper", { enumerable: true, get: function () { return types_1._passUndefinedMapper; } });
|
|
103
76
|
Object.defineProperty(exports, "_stringMapEntries", { enumerable: true, get: function () { return types_1._stringMapEntries; } });
|
|
104
77
|
Object.defineProperty(exports, "_stringMapValues", { enumerable: true, get: function () { return types_1._stringMapValues; } });
|
|
105
|
-
|
|
106
|
-
Object.defineProperty(exports, "_gb", { enumerable: true, get: function () { return size_util_1._gb; } });
|
|
107
|
-
Object.defineProperty(exports, "_hb", { enumerable: true, get: function () { return size_util_1._hb; } });
|
|
108
|
-
Object.defineProperty(exports, "_kb", { enumerable: true, get: function () { return size_util_1._kb; } });
|
|
109
|
-
Object.defineProperty(exports, "_mb", { enumerable: true, get: function () { return size_util_1._mb; } });
|
|
78
|
+
(0, tslib_1.__exportStar)(require("./unit/size.util"), exports);
|
|
110
79
|
const is_1 = require("./vendor/is");
|
|
111
80
|
Object.defineProperty(exports, "is", { enumerable: true, get: function () { return is_1.is; } });
|
|
112
81
|
const commonLogger_1 = require("./log/commonLogger");
|
|
@@ -116,8 +85,7 @@ Object.defineProperty(exports, "commonLogLevelNumber", { enumerable: true, get:
|
|
|
116
85
|
Object.defineProperty(exports, "commonLoggerPipe", { enumerable: true, get: function () { return commonLogger_1.commonLoggerPipe; } });
|
|
117
86
|
Object.defineProperty(exports, "commonLoggerPrefix", { enumerable: true, get: function () { return commonLogger_1.commonLoggerPrefix; } });
|
|
118
87
|
Object.defineProperty(exports, "commonLoggerCreate", { enumerable: true, get: function () { return commonLogger_1.commonLoggerCreate; } });
|
|
119
|
-
|
|
120
|
-
Object.defineProperty(exports, "_safeJsonStringify", { enumerable: true, get: function () { return safeJsonStringify_1._safeJsonStringify; } });
|
|
88
|
+
(0, tslib_1.__exportStar)(require("./string/safeJsonStringify"), exports);
|
|
121
89
|
const pQueue_1 = require("./promise/pQueue");
|
|
122
90
|
Object.defineProperty(exports, "PQueue", { enumerable: true, get: function () { return pQueue_1.PQueue; } });
|
|
123
91
|
(0, tslib_1.__exportStar)(require("./seq/seq"), exports);
|
package/dist/math/math.util.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export declare function _averageWeighted(values: number[], weights: number[]): n
|
|
|
24
24
|
* // 3
|
|
25
25
|
*/
|
|
26
26
|
export declare function _percentile(values: number[], pc: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* A tiny bit more efficient function than calling _percentile individually.
|
|
29
|
+
*/
|
|
30
|
+
export declare function _percentiles(values: number[], pcs: number[]): Record<number, number>;
|
|
27
31
|
/**
|
|
28
32
|
* @example
|
|
29
33
|
*
|
package/dist/math/math.util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._median = exports._percentile = exports._averageWeighted = exports._average = void 0;
|
|
3
|
+
exports._median = exports._percentiles = exports._percentile = exports._averageWeighted = exports._average = void 0;
|
|
4
4
|
const number_util_1 = require("../number/number.util");
|
|
5
5
|
/**
|
|
6
6
|
* @returns Average of the array of numbers
|
|
@@ -45,6 +45,23 @@ function _percentile(values, pc) {
|
|
|
45
45
|
return _averageWeighted([sorted[floorPos], sorted[ceilPos]], [1 - dec, dec]);
|
|
46
46
|
}
|
|
47
47
|
exports._percentile = _percentile;
|
|
48
|
+
/**
|
|
49
|
+
* A tiny bit more efficient function than calling _percentile individually.
|
|
50
|
+
*/
|
|
51
|
+
function _percentiles(values, pcs) {
|
|
52
|
+
const r = {};
|
|
53
|
+
const sorted = (0, number_util_1._sortNumbers)(values);
|
|
54
|
+
pcs.forEach(pc => {
|
|
55
|
+
// Floating pos in the range of [0; length - 1]
|
|
56
|
+
const pos = ((values.length - 1) * pc) / 100;
|
|
57
|
+
const dec = pos % 1;
|
|
58
|
+
const floorPos = Math.floor(pos);
|
|
59
|
+
const ceilPos = Math.ceil(pos);
|
|
60
|
+
r[pc] = _averageWeighted([sorted[floorPos], sorted[ceilPos]], [1 - dec, dec]);
|
|
61
|
+
});
|
|
62
|
+
return r;
|
|
63
|
+
}
|
|
64
|
+
exports._percentiles = _percentiles;
|
|
48
65
|
/**
|
|
49
66
|
* @example
|
|
50
67
|
*
|
|
@@ -35,6 +35,8 @@ export declare class NumberStack extends Stack<number> {
|
|
|
35
35
|
* Returns null if Stack is empty.
|
|
36
36
|
*/
|
|
37
37
|
avgOrNull(): number | null;
|
|
38
|
+
median(): number;
|
|
39
|
+
medianOrNull(): number | null;
|
|
38
40
|
/**
|
|
39
41
|
* `pc` is a number from 0 to 100 inclusive.
|
|
40
42
|
*/
|
|
@@ -44,6 +46,5 @@ export declare class NumberStack extends Stack<number> {
|
|
|
44
46
|
* Returns null if Stack is empty.
|
|
45
47
|
*/
|
|
46
48
|
percentileOrNull(pc: number): number | null;
|
|
47
|
-
|
|
48
|
-
medianOrNull(): number | null;
|
|
49
|
+
percentiles(pcs: number[]): Record<number, number>;
|
|
49
50
|
}
|
package/dist/math/stack.util.js
CHANGED
|
@@ -60,6 +60,12 @@ class NumberStack extends Stack {
|
|
|
60
60
|
avgOrNull() {
|
|
61
61
|
return this.items.length === 0 ? null : (0, index_1._average)(this.items);
|
|
62
62
|
}
|
|
63
|
+
median() {
|
|
64
|
+
return (0, index_1._percentile)(this.items, 50);
|
|
65
|
+
}
|
|
66
|
+
medianOrNull() {
|
|
67
|
+
return this.items.length === 0 ? null : (0, index_1._percentile)(this.items, 50);
|
|
68
|
+
}
|
|
63
69
|
/**
|
|
64
70
|
* `pc` is a number from 0 to 100 inclusive.
|
|
65
71
|
*/
|
|
@@ -74,11 +80,8 @@ class NumberStack extends Stack {
|
|
|
74
80
|
percentileOrNull(pc) {
|
|
75
81
|
return this.items.length === 0 ? null : (0, index_1._percentile)(this.items, pc);
|
|
76
82
|
}
|
|
77
|
-
|
|
78
|
-
return (0, index_1.
|
|
79
|
-
}
|
|
80
|
-
medianOrNull() {
|
|
81
|
-
return this.items.length === 0 ? null : (0, index_1._percentile)(this.items, 50);
|
|
83
|
+
percentiles(pcs) {
|
|
84
|
+
return (0, index_1._percentiles)(this.items, pcs);
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
exports.NumberStack = NumberStack;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { AppError } from '../error/app.error';
|
|
1
2
|
import { AnyFunction } from '../types';
|
|
3
|
+
export declare class TimeoutError extends AppError {
|
|
4
|
+
}
|
|
2
5
|
export interface PTimeoutOptions {
|
|
3
6
|
/**
|
|
4
7
|
* Timeout in milliseconds.
|
|
@@ -20,4 +23,10 @@ export interface PTimeoutOptions {
|
|
|
20
23
|
* Throws an Error if the Function is not resolved in a certain time.
|
|
21
24
|
* If the Function rejects - passes this rejection further.
|
|
22
25
|
*/
|
|
23
|
-
export declare function
|
|
26
|
+
export declare function pTimeoutFn<T extends AnyFunction>(fn: T, opt: PTimeoutOptions): T;
|
|
27
|
+
/**
|
|
28
|
+
* Decorates a Function with a timeout and immediately calls it.
|
|
29
|
+
* Throws an Error if the Function is not resolved in a certain time.
|
|
30
|
+
* If the Function rejects - passes this rejection further.
|
|
31
|
+
*/
|
|
32
|
+
export declare function pTimeout<T>(promise: Promise<T>, opt: PTimeoutOptions): Promise<T>;
|
package/dist/promise/pTimeout.js
CHANGED
|
@@ -1,41 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pTimeout = void 0;
|
|
3
|
+
exports.pTimeout = exports.pTimeoutFn = exports.TimeoutError = void 0;
|
|
4
|
+
const app_error_1 = require("../error/app.error");
|
|
5
|
+
class TimeoutError extends app_error_1.AppError {
|
|
6
|
+
}
|
|
7
|
+
exports.TimeoutError = TimeoutError;
|
|
4
8
|
/**
|
|
5
9
|
* Decorates a Function with a timeout.
|
|
6
10
|
* Throws an Error if the Function is not resolved in a certain time.
|
|
7
11
|
* If the Function rejects - passes this rejection further.
|
|
8
12
|
*/
|
|
9
|
-
function
|
|
10
|
-
|
|
13
|
+
function pTimeoutFn(fn, opt) {
|
|
14
|
+
opt.name || (opt.name = fn.name);
|
|
15
|
+
return async function pTimeoutInternalFn(...args) {
|
|
16
|
+
return await pTimeout(fn.apply(this, args), opt);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.pTimeoutFn = pTimeoutFn;
|
|
20
|
+
/**
|
|
21
|
+
* Decorates a Function with a timeout and immediately calls it.
|
|
22
|
+
* Throws an Error if the Function is not resolved in a certain time.
|
|
23
|
+
* If the Function rejects - passes this rejection further.
|
|
24
|
+
*/
|
|
25
|
+
async function pTimeout(promise, opt) {
|
|
26
|
+
// todo: check how we can automatically infer function name (only applicable to named functions)
|
|
11
27
|
const { timeout, name, onTimeout } = opt;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
resolve(onTimeout());
|
|
20
|
-
}
|
|
21
|
-
catch (err) {
|
|
22
|
-
reject(err);
|
|
23
|
-
}
|
|
24
|
-
return;
|
|
28
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
29
|
+
return await new Promise(async (resolve, reject) => {
|
|
30
|
+
// Prepare the timeout timer
|
|
31
|
+
const timer = setTimeout(() => {
|
|
32
|
+
if (onTimeout) {
|
|
33
|
+
try {
|
|
34
|
+
resolve(onTimeout());
|
|
25
35
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
resolve(await fn.apply(this, args));
|
|
31
|
-
}
|
|
32
|
-
catch (err) {
|
|
33
|
-
reject(err);
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
36
|
-
clearTimeout(timer);
|
|
36
|
+
catch (err) {
|
|
37
|
+
reject(err);
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
reject(new TimeoutError(`"${name || 'pTimeout function'}" timed out after ${timeout} ms`));
|
|
42
|
+
}, timeout);
|
|
43
|
+
// Execute the Function
|
|
44
|
+
try {
|
|
45
|
+
resolve(await promise);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
reject(err);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
40
54
|
}
|
|
41
55
|
exports.pTimeout = pTimeout;
|
package/dist/seq/seq.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbortableMapper, AbortablePredicate, END } from '../types';
|
|
1
|
+
import { AbortableAsyncMapper, AbortableAsyncPredicate, AbortableMapper, AbortablePredicate, END } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Inspired by Kotlin Sequences.
|
|
4
4
|
* Similar to arrays, but with lazy evaluation, abortable.
|
|
@@ -7,14 +7,14 @@ import { AbortableMapper, AbortablePredicate, END } from '../types';
|
|
|
7
7
|
*
|
|
8
8
|
* @experimental
|
|
9
9
|
*/
|
|
10
|
-
export declare class
|
|
10
|
+
export declare class Sequence<T> implements Iterable<T> {
|
|
11
11
|
private nextFn;
|
|
12
12
|
private constructor();
|
|
13
13
|
[Symbol.iterator](): Iterator<T>;
|
|
14
|
-
static create<T>(initialValue: T | typeof END, nextFn: AbortableMapper<T, T>):
|
|
15
|
-
static range(minIncl: number, maxExcl: number, step?: number):
|
|
16
|
-
static from<T>(a: Iterable<T>):
|
|
17
|
-
static empty<T = any>():
|
|
14
|
+
static create<T>(initialValue: T | typeof END, nextFn: AbortableMapper<T, T>): Sequence<T>;
|
|
15
|
+
static range(minIncl: number, maxExcl: number, step?: number): Sequence<number>;
|
|
16
|
+
static from<T>(a: Iterable<T>): Sequence<T>;
|
|
17
|
+
static empty<T = any>(): Sequence<T>;
|
|
18
18
|
private currentValue;
|
|
19
19
|
private sentInitialValue;
|
|
20
20
|
private i;
|
|
@@ -23,8 +23,31 @@ export declare class Seq<T> implements Iterable<T> {
|
|
|
23
23
|
some(predicate: AbortablePredicate<T>): boolean;
|
|
24
24
|
every(predicate: AbortablePredicate<T>): boolean;
|
|
25
25
|
toArray(): T[];
|
|
26
|
+
forEach(fn: (v: T, i: number) => void): void;
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Convenience function to create a Sequence.
|
|
29
30
|
*/
|
|
30
|
-
export declare function _seq<T>(initialValue: T | typeof END, nextFn: AbortableMapper<T, T>):
|
|
31
|
+
export declare function _seq<T>(initialValue: T | typeof END, nextFn: AbortableMapper<T, T>): Sequence<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Experimental.
|
|
34
|
+
* Feasibility to be proven.
|
|
35
|
+
*
|
|
36
|
+
* @experimental
|
|
37
|
+
*/
|
|
38
|
+
export declare class AsyncSequence<T> implements AsyncIterable<T> {
|
|
39
|
+
private nextFn;
|
|
40
|
+
private constructor();
|
|
41
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
42
|
+
static create<T>(initialValue: T | typeof END, nextFn: AbortableAsyncMapper<T, T>): AsyncSequence<T>;
|
|
43
|
+
static from<T>(a: AsyncIterable<T>): Promise<AsyncSequence<T>>;
|
|
44
|
+
static empty<T = any>(): AsyncSequence<T>;
|
|
45
|
+
private currentValue;
|
|
46
|
+
private sentInitialValue;
|
|
47
|
+
private i;
|
|
48
|
+
next(): Promise<T | typeof END>;
|
|
49
|
+
find(predicate: AbortableAsyncPredicate<T>): Promise<T | undefined>;
|
|
50
|
+
some(predicate: AbortableAsyncPredicate<T>): Promise<boolean>;
|
|
51
|
+
every(predicate: AbortableAsyncPredicate<T>): Promise<boolean>;
|
|
52
|
+
toArray(): Promise<T[]>;
|
|
53
|
+
}
|