@naturalcycles/js-lib 14.109.1 → 14.111.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/error/error.util.d.ts +2 -2
- package/dist/index.d.ts +20 -31
- package/dist/index.js +20 -25
- package/dist/json-schema/from-data/generateJsonSchemaFromData.d.ts +1 -1
- package/dist/json-schema/jsonSchema.model.d.ts +1 -1
- package/dist/json-schema/jsonSchema.util.d.ts +2 -1
- package/dist/object/object.util.d.ts +11 -11
- package/dist/object/object.util.js +12 -13
- package/dist/typeFest.d.ts +40 -3
- package/dist/types.d.ts +5 -13
- package/dist-esm/index.js +20 -11
- package/dist-esm/object/object.util.js +12 -13
- package/package.json +2 -2
- package/src/error/error.util.ts +4 -2
- package/src/index.ts +20 -244
- package/src/json-schema/from-data/generateJsonSchemaFromData.ts +3 -1
- package/src/json-schema/jsonSchema.model.ts +1 -1
- package/src/json-schema/jsonSchema.util.ts +2 -2
- package/src/object/object.util.ts +14 -20
- package/src/typeFest.ts +57 -7
- package/src/types.ts +8 -20
|
@@ -17,8 +17,8 @@ export declare function _anyToError<ERROR_TYPE extends Error = Error>(o: any, er
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function _anyToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(o: any, opt?: StringifyAnyOptions): ErrorObject<DATA_TYPE>;
|
|
19
19
|
export declare function _errorToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(e: AppError<DATA_TYPE> | Error, includeErrorStack?: boolean): ErrorObject<DATA_TYPE>;
|
|
20
|
-
export declare function _errorObjectToAppError<DATA_TYPE>(o: ErrorObject<DATA_TYPE>): AppError<DATA_TYPE>;
|
|
21
|
-
export declare function _errorObjectToError<DATA_TYPE, ERROR_TYPE extends Error>(o: ErrorObject<DATA_TYPE>, errorClass?: Class<ERROR_TYPE>): ERROR_TYPE;
|
|
20
|
+
export declare function _errorObjectToAppError<DATA_TYPE extends ErrorData>(o: ErrorObject<DATA_TYPE>): AppError<DATA_TYPE>;
|
|
21
|
+
export declare function _errorObjectToError<DATA_TYPE extends ErrorData, ERROR_TYPE extends Error>(o: ErrorObject<DATA_TYPE>, errorClass?: Class<ERROR_TYPE>): ERROR_TYPE;
|
|
22
22
|
export declare function _isHttpErrorResponse(o: any): o is HttpErrorResponse;
|
|
23
23
|
export declare function _isHttpErrorObject(o: any): o is ErrorObject<HttpErrorData>;
|
|
24
24
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,14 @@ export * from './array/array.util';
|
|
|
2
2
|
export * from './lazy';
|
|
3
3
|
export * from './string/url.util';
|
|
4
4
|
export * from './array/range';
|
|
5
|
-
|
|
6
|
-
import { _createPromiseDecorator } from './decorators/createPromiseDecorator';
|
|
5
|
+
export * from './decorators/createPromiseDecorator';
|
|
7
6
|
export * from './decorators/debounce';
|
|
8
7
|
export * from './decorators/debounce.decorator';
|
|
9
8
|
export * from './decorators/decorator.util';
|
|
10
9
|
export * from './decorators/logMethod.decorator';
|
|
11
10
|
export * from './decorators/memo.decorator';
|
|
12
11
|
export * from './decorators/asyncMemo.decorator';
|
|
13
|
-
|
|
12
|
+
export * from './decorators/memo.util';
|
|
14
13
|
export * from './decorators/memoFn';
|
|
15
14
|
export * from './decorators/memoFnAsync';
|
|
16
15
|
export * from './decorators/retry.decorator';
|
|
@@ -18,19 +17,18 @@ export * from './decorators/timeout.decorator';
|
|
|
18
17
|
export * from './error/app.error';
|
|
19
18
|
export * from './error/assert';
|
|
20
19
|
export * from './enum.util';
|
|
21
|
-
|
|
20
|
+
export * from './error/error.model';
|
|
22
21
|
export * from './error/error.util';
|
|
23
|
-
|
|
22
|
+
export * from './error/errorMode';
|
|
24
23
|
export * from './error/http.error';
|
|
25
24
|
export * from './error/try';
|
|
26
|
-
|
|
27
|
-
import { _TryCatch, _tryCatch } from './error/tryCatch';
|
|
25
|
+
export * from './error/tryCatch';
|
|
28
26
|
export * from './json-schema/from-data/generateJsonSchemaFromData';
|
|
29
27
|
export * from './json-schema/jsonSchema.cnst';
|
|
30
|
-
|
|
28
|
+
export * from './json-schema/jsonSchema.model';
|
|
31
29
|
export * from './json-schema/jsonSchema.util';
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
export * from './json-schema/jsonSchemaBuilder';
|
|
31
|
+
export * from './json-schema/jsonSchemaBuilder';
|
|
34
32
|
export * from './math/math.util';
|
|
35
33
|
export * from './math/sma';
|
|
36
34
|
export * from './number/createDeterministicRandom';
|
|
@@ -39,39 +37,31 @@ export * from './object/deepEquals';
|
|
|
39
37
|
export * from './object/object.util';
|
|
40
38
|
export * from './object/sortObject';
|
|
41
39
|
export * from './object/sortObjectDeep';
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
import { pDefer } from './promise/pDefer';
|
|
40
|
+
export * from './promise/AggregatedError';
|
|
41
|
+
export * from './promise/pDefer';
|
|
45
42
|
export * from './promise/pDelay';
|
|
46
43
|
export * from './promise/pFilter';
|
|
47
44
|
export * from './promise/pHang';
|
|
48
|
-
|
|
49
|
-
import { pMap } from './promise/pMap';
|
|
45
|
+
export * from './promise/pMap';
|
|
50
46
|
export * from './promise/pProps';
|
|
51
|
-
|
|
52
|
-
import { pRetry, pRetryFn } from './promise/pRetry';
|
|
47
|
+
export * from './promise/pRetry';
|
|
53
48
|
export * from './promise/pState';
|
|
54
|
-
|
|
55
|
-
import { pTimeout, pTimeoutFn } from './promise/pTimeout';
|
|
49
|
+
export * from './promise/pTimeout';
|
|
56
50
|
export * from './string/case';
|
|
57
51
|
export * from './string/json.util';
|
|
58
52
|
export * from './string/string.util';
|
|
59
53
|
export * from './string/readingTime';
|
|
60
54
|
export * from './string/escape';
|
|
61
55
|
export * from './string/pupa';
|
|
62
|
-
|
|
63
|
-
import { _stringifyAny } from './string/stringifyAny';
|
|
56
|
+
export * from './string/stringifyAny';
|
|
64
57
|
export * from './time/time.util';
|
|
65
58
|
export * from './is.util';
|
|
66
|
-
|
|
67
|
-
import type { AsyncMapper, AsyncPredicate, BaseDBEntity, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, Saved, Unsaved, UnsavedId, BatchResult, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, KeyValueTuple, Mapper, ObjectMapper, ObjectPredicate, Predicate, PromiseMap, AnyObject, AnyEnum, NumberEnum, StringEnum, AnyFunction, Reviver, SavedDBEntity, StringMap, UnixTimestampNumber, UnixTimestampMillisNumber, UnixTimestamp, Integer, ValueOf, ValuesOf, AbortableMapper, AbortableAsyncPredicate, AbortableAsyncMapper, AbortablePredicate, NullishValue, FalsyValue } from './types';
|
|
59
|
+
export * from './typeFest';
|
|
68
60
|
export * from './types';
|
|
69
61
|
export * from './unit/size.util';
|
|
70
62
|
import { is } from './vendor/is';
|
|
71
|
-
import type { CommonLogLevel, CommonLogFunction, CommonLogger, CommonLogWithLevelFunction } from './log/commonLogger';
|
|
72
63
|
export * from './log/commonLogger';
|
|
73
64
|
export * from './string/safeJsonStringify';
|
|
74
|
-
import type { PQueueCfg } from './promise/pQueue';
|
|
75
65
|
export * from './promise/pQueue';
|
|
76
66
|
export * from './seq/seq';
|
|
77
67
|
export * from './math/stack.util';
|
|
@@ -80,9 +70,8 @@ export * from './datetime/localDate';
|
|
|
80
70
|
export * from './datetime/localTime';
|
|
81
71
|
export * from './datetime/dateInterval';
|
|
82
72
|
export * from './datetime/timeInterval';
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export
|
|
88
|
-
export { is, _createPromiseDecorator, pMap, ErrorMode, pDefer, AggregatedError, pRetry, pRetryFn, pTimeout, pTimeoutFn, _tryCatch, _TryCatch, _stringifyAny, jsonSchema, JsonSchemaAnyBuilder, };
|
|
73
|
+
export * from './datetime/localDate';
|
|
74
|
+
export * from './datetime/localTime';
|
|
75
|
+
export * from './datetime/dateInterval';
|
|
76
|
+
export * from './datetime/timeInterval';
|
|
77
|
+
export { is };
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.is = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./array/array.util"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./lazy"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./string/url.util"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./array/range"), exports);
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, "_createPromiseDecorator", { enumerable: true, get: function () { return createPromiseDecorator_1._createPromiseDecorator; } });
|
|
9
|
+
tslib_1.__exportStar(require("./decorators/createPromiseDecorator"), exports);
|
|
11
10
|
tslib_1.__exportStar(require("./decorators/debounce"), exports);
|
|
12
11
|
tslib_1.__exportStar(require("./decorators/debounce.decorator"), exports);
|
|
13
12
|
tslib_1.__exportStar(require("./decorators/decorator.util"), exports);
|
|
14
13
|
tslib_1.__exportStar(require("./decorators/logMethod.decorator"), exports);
|
|
15
14
|
tslib_1.__exportStar(require("./decorators/memo.decorator"), exports);
|
|
16
15
|
tslib_1.__exportStar(require("./decorators/asyncMemo.decorator"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./decorators/memo.util"), exports);
|
|
17
17
|
tslib_1.__exportStar(require("./decorators/memoFn"), exports);
|
|
18
18
|
tslib_1.__exportStar(require("./decorators/memoFnAsync"), exports);
|
|
19
19
|
tslib_1.__exportStar(require("./decorators/retry.decorator"), exports);
|
|
@@ -21,20 +21,18 @@ tslib_1.__exportStar(require("./decorators/timeout.decorator"), exports);
|
|
|
21
21
|
tslib_1.__exportStar(require("./error/app.error"), exports);
|
|
22
22
|
tslib_1.__exportStar(require("./error/assert"), exports);
|
|
23
23
|
tslib_1.__exportStar(require("./enum.util"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./error/error.model"), exports);
|
|
24
25
|
tslib_1.__exportStar(require("./error/error.util"), exports);
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(exports, "ErrorMode", { enumerable: true, get: function () { return errorMode_1.ErrorMode; } });
|
|
26
|
+
tslib_1.__exportStar(require("./error/errorMode"), exports);
|
|
27
27
|
tslib_1.__exportStar(require("./error/http.error"), exports);
|
|
28
28
|
tslib_1.__exportStar(require("./error/try"), exports);
|
|
29
|
-
|
|
30
|
-
Object.defineProperty(exports, "_TryCatch", { enumerable: true, get: function () { return tryCatch_1._TryCatch; } });
|
|
31
|
-
Object.defineProperty(exports, "_tryCatch", { enumerable: true, get: function () { return tryCatch_1._tryCatch; } });
|
|
29
|
+
tslib_1.__exportStar(require("./error/tryCatch"), exports);
|
|
32
30
|
tslib_1.__exportStar(require("./json-schema/from-data/generateJsonSchemaFromData"), exports);
|
|
33
31
|
tslib_1.__exportStar(require("./json-schema/jsonSchema.cnst"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./json-schema/jsonSchema.model"), exports);
|
|
34
33
|
tslib_1.__exportStar(require("./json-schema/jsonSchema.util"), exports);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Object.defineProperty(exports, "JsonSchemaAnyBuilder", { enumerable: true, get: function () { return jsonSchemaBuilder_1.JsonSchemaAnyBuilder; } });
|
|
34
|
+
tslib_1.__exportStar(require("./json-schema/jsonSchemaBuilder"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./json-schema/jsonSchemaBuilder"), exports);
|
|
38
36
|
tslib_1.__exportStar(require("./math/math.util"), exports);
|
|
39
37
|
tslib_1.__exportStar(require("./math/sma"), exports);
|
|
40
38
|
tslib_1.__exportStar(require("./number/createDeterministicRandom"), exports);
|
|
@@ -43,33 +41,26 @@ tslib_1.__exportStar(require("./object/deepEquals"), exports);
|
|
|
43
41
|
tslib_1.__exportStar(require("./object/object.util"), exports);
|
|
44
42
|
tslib_1.__exportStar(require("./object/sortObject"), exports);
|
|
45
43
|
tslib_1.__exportStar(require("./object/sortObjectDeep"), exports);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const pDefer_1 = require("./promise/pDefer");
|
|
49
|
-
Object.defineProperty(exports, "pDefer", { enumerable: true, get: function () { return pDefer_1.pDefer; } });
|
|
44
|
+
tslib_1.__exportStar(require("./promise/AggregatedError"), exports);
|
|
45
|
+
tslib_1.__exportStar(require("./promise/pDefer"), exports);
|
|
50
46
|
tslib_1.__exportStar(require("./promise/pDelay"), exports);
|
|
51
47
|
tslib_1.__exportStar(require("./promise/pFilter"), exports);
|
|
52
48
|
tslib_1.__exportStar(require("./promise/pHang"), exports);
|
|
53
|
-
|
|
54
|
-
Object.defineProperty(exports, "pMap", { enumerable: true, get: function () { return pMap_1.pMap; } });
|
|
49
|
+
tslib_1.__exportStar(require("./promise/pMap"), exports);
|
|
55
50
|
tslib_1.__exportStar(require("./promise/pProps"), exports);
|
|
56
|
-
|
|
57
|
-
Object.defineProperty(exports, "pRetry", { enumerable: true, get: function () { return pRetry_1.pRetry; } });
|
|
58
|
-
Object.defineProperty(exports, "pRetryFn", { enumerable: true, get: function () { return pRetry_1.pRetryFn; } });
|
|
51
|
+
tslib_1.__exportStar(require("./promise/pRetry"), exports);
|
|
59
52
|
tslib_1.__exportStar(require("./promise/pState"), exports);
|
|
60
|
-
|
|
61
|
-
Object.defineProperty(exports, "pTimeout", { enumerable: true, get: function () { return pTimeout_1.pTimeout; } });
|
|
62
|
-
Object.defineProperty(exports, "pTimeoutFn", { enumerable: true, get: function () { return pTimeout_1.pTimeoutFn; } });
|
|
53
|
+
tslib_1.__exportStar(require("./promise/pTimeout"), exports);
|
|
63
54
|
tslib_1.__exportStar(require("./string/case"), exports);
|
|
64
55
|
tslib_1.__exportStar(require("./string/json.util"), exports);
|
|
65
56
|
tslib_1.__exportStar(require("./string/string.util"), exports);
|
|
66
57
|
tslib_1.__exportStar(require("./string/readingTime"), exports);
|
|
67
58
|
tslib_1.__exportStar(require("./string/escape"), exports);
|
|
68
59
|
tslib_1.__exportStar(require("./string/pupa"), exports);
|
|
69
|
-
|
|
70
|
-
Object.defineProperty(exports, "_stringifyAny", { enumerable: true, get: function () { return stringifyAny_1._stringifyAny; } });
|
|
60
|
+
tslib_1.__exportStar(require("./string/stringifyAny"), exports);
|
|
71
61
|
tslib_1.__exportStar(require("./time/time.util"), exports);
|
|
72
62
|
tslib_1.__exportStar(require("./is.util"), exports);
|
|
63
|
+
tslib_1.__exportStar(require("./typeFest"), exports);
|
|
73
64
|
tslib_1.__exportStar(require("./types"), exports);
|
|
74
65
|
tslib_1.__exportStar(require("./unit/size.util"), exports);
|
|
75
66
|
const is_1 = require("./vendor/is");
|
|
@@ -84,3 +75,7 @@ tslib_1.__exportStar(require("./datetime/localDate"), exports);
|
|
|
84
75
|
tslib_1.__exportStar(require("./datetime/localTime"), exports);
|
|
85
76
|
tslib_1.__exportStar(require("./datetime/dateInterval"), exports);
|
|
86
77
|
tslib_1.__exportStar(require("./datetime/timeInterval"), exports);
|
|
78
|
+
tslib_1.__exportStar(require("./datetime/localDate"), exports);
|
|
79
|
+
tslib_1.__exportStar(require("./datetime/localTime"), exports);
|
|
80
|
+
tslib_1.__exportStar(require("./datetime/dateInterval"), exports);
|
|
81
|
+
tslib_1.__exportStar(require("./datetime/timeInterval"), exports);
|
|
@@ -4,4 +4,4 @@ import type { JsonSchemaObject, AnyObject } from '../..';
|
|
|
4
4
|
*
|
|
5
5
|
* `additionalProperties` is set to `true`, cause it's safer.
|
|
6
6
|
*/
|
|
7
|
-
export declare function generateJsonSchemaFromData<T =
|
|
7
|
+
export declare function generateJsonSchemaFromData<T extends AnyObject = AnyObject>(rows: AnyObject[]): JsonSchemaObject<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyObject, StringMap } from '../types';
|
|
2
|
-
export declare type JsonSchema<T = unknown> = JsonSchemaAny<T> | JsonSchemaOneOf<T> | JsonSchemaAllOf<T> | JsonSchemaAnyOf<T> | JsonSchemaNot<T> | JsonSchemaRef<T> | JsonSchemaConst<T> | JsonSchemaEnum<T> | JsonSchemaString | JsonSchemaNumber | JsonSchemaBoolean | JsonSchemaNull | JsonSchemaObject
|
|
2
|
+
export declare type JsonSchema<T = unknown> = JsonSchemaAny<T> | JsonSchemaOneOf<T> | JsonSchemaAllOf<T> | JsonSchemaAnyOf<T> | JsonSchemaNot<T> | JsonSchemaRef<T> | JsonSchemaConst<T> | JsonSchemaEnum<T> | JsonSchemaString | JsonSchemaNumber | JsonSchemaBoolean | JsonSchemaNull | JsonSchemaObject | JsonSchemaArray<T> | JsonSchemaTuple<T>;
|
|
3
3
|
export interface JsonSchemaAny<T = unknown> {
|
|
4
4
|
$schema?: string;
|
|
5
5
|
$id?: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { AnyObject } from '../index';
|
|
1
2
|
import type { JsonSchemaObject } from './jsonSchema.model';
|
|
2
3
|
/**
|
|
3
4
|
* Merges s2 into s1 (mutates s1) and returns s1.
|
|
4
5
|
* Does not mutate s2.
|
|
5
6
|
* API similar to Object.assign(s1, s2)
|
|
6
7
|
*/
|
|
7
|
-
export declare function mergeJsonSchemaObjects<T1, T2>(s1: JsonSchemaObject<T1>, s2: JsonSchemaObject<T2>): JsonSchemaObject<T1 & T2>;
|
|
8
|
+
export declare function mergeJsonSchemaObjects<T1 extends AnyObject, T2 extends AnyObject>(s1: JsonSchemaObject<T1>, s2: JsonSchemaObject<T2>): JsonSchemaObject<T1 & T2>;
|
|
@@ -135,19 +135,19 @@ export declare function _invert<T extends AnyObject>(o: T): {
|
|
|
135
135
|
};
|
|
136
136
|
export declare function _invertMap<K, V>(m: ReadonlyMap<K, V>): Map<V, K>;
|
|
137
137
|
/**
|
|
138
|
-
* Gets the property value at path of object.
|
|
139
|
-
* in its place.
|
|
138
|
+
* Gets the property value at path of object.
|
|
140
139
|
*
|
|
141
|
-
* @
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
140
|
+
* @example
|
|
141
|
+
* const obj = {a: 'a', b: 'b', c: { cc: 'cc' }}
|
|
142
|
+
* _get(obj, 'a') // 'a'
|
|
143
|
+
* _get(obj, 'c.cc') // 'cc'
|
|
144
|
+
* _get(obj, 'c[cc]') // 'cc'
|
|
145
|
+
* _get(obj, 'unknown.path') // undefined
|
|
145
146
|
*/
|
|
146
|
-
export declare function _get<T extends AnyObject>(obj?: T, path?: string
|
|
147
|
+
export declare function _get<T extends AnyObject>(obj?: T, path?: string): unknown;
|
|
147
148
|
/**
|
|
148
149
|
* Sets the value at path of object. If a portion of path doesn’t exist it’s created. Arrays are created for
|
|
149
|
-
* missing index properties while objects are created for all other missing properties.
|
|
150
|
-
* customize path creation.
|
|
150
|
+
* missing index properties while objects are created for all other missing properties.
|
|
151
151
|
*
|
|
152
152
|
* @param obj The object to modify.
|
|
153
153
|
* @param path The path of the property to set.
|
|
@@ -156,7 +156,7 @@ export declare function _get<T extends AnyObject>(obj?: T, path?: string, def?:
|
|
|
156
156
|
*
|
|
157
157
|
* Based on: https://stackoverflow.com/a/54733755/4919972
|
|
158
158
|
*/
|
|
159
|
-
export declare function _set<
|
|
159
|
+
export declare function _set<T extends AnyObject>(obj: T, path: PropertyPath, value: any): T;
|
|
160
160
|
/**
|
|
161
161
|
* Checks if `path` is a direct property of `object` (not null, not undefined).
|
|
162
162
|
*
|
|
@@ -181,4 +181,4 @@ export declare function _set<IN extends AnyObject, OUT = IN>(obj: IN, path: Prop
|
|
|
181
181
|
* _.has(other, 'a');
|
|
182
182
|
* // => false
|
|
183
183
|
*/
|
|
184
|
-
export declare function _has<T extends AnyObject>(obj: T, path
|
|
184
|
+
export declare function _has<T extends AnyObject>(obj: T, path: string): boolean;
|
|
@@ -286,26 +286,25 @@ function _invertMap(m) {
|
|
|
286
286
|
}
|
|
287
287
|
exports._invertMap = _invertMap;
|
|
288
288
|
/**
|
|
289
|
-
* Gets the property value at path of object.
|
|
290
|
-
* in its place.
|
|
289
|
+
* Gets the property value at path of object.
|
|
291
290
|
*
|
|
292
|
-
* @
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
291
|
+
* @example
|
|
292
|
+
* const obj = {a: 'a', b: 'b', c: { cc: 'cc' }}
|
|
293
|
+
* _get(obj, 'a') // 'a'
|
|
294
|
+
* _get(obj, 'c.cc') // 'cc'
|
|
295
|
+
* _get(obj, 'c[cc]') // 'cc'
|
|
296
|
+
* _get(obj, 'unknown.path') // undefined
|
|
296
297
|
*/
|
|
297
|
-
function _get(obj = {}, path = ''
|
|
298
|
-
|
|
298
|
+
function _get(obj = {}, path = '') {
|
|
299
|
+
return path
|
|
299
300
|
.replace(/\[([^\]]+)]/g, '.$1')
|
|
300
301
|
.split('.')
|
|
301
|
-
.reduce((o, p) => o[p], obj);
|
|
302
|
-
return res === undefined ? def : res;
|
|
302
|
+
.reduce((o, p) => o?.[p], obj);
|
|
303
303
|
}
|
|
304
304
|
exports._get = _get;
|
|
305
305
|
/**
|
|
306
306
|
* Sets the value at path of object. If a portion of path doesn’t exist it’s created. Arrays are created for
|
|
307
|
-
* missing index properties while objects are created for all other missing properties.
|
|
308
|
-
* customize path creation.
|
|
307
|
+
* missing index properties while objects are created for all other missing properties.
|
|
309
308
|
*
|
|
310
309
|
* @param obj The object to modify.
|
|
311
310
|
* @param path The path of the property to set.
|
|
@@ -336,7 +335,7 @@ function _set(obj, path, value) {
|
|
|
336
335
|
? [] // Yes: assign a new array object
|
|
337
336
|
: {}), // No: assign a new plain object
|
|
338
337
|
obj)[path[path.length - 1]] = value; // Finally assign the value to the last key
|
|
339
|
-
return obj; //
|
|
338
|
+
return obj; // allow chaining
|
|
340
339
|
}
|
|
341
340
|
exports._set = _set;
|
|
342
341
|
/**
|
package/dist/typeFest.d.ts
CHANGED
|
@@ -10,6 +10,19 @@ export declare type Primitive = null | undefined | string | number | boolean | s
|
|
|
10
10
|
export declare type Simplify<T> = {
|
|
11
11
|
[KeyType in keyof T]: T[KeyType];
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
Returns a boolean for whether the two given types are equal.
|
|
15
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
16
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
17
|
+
*/
|
|
18
|
+
export declare type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
|
|
19
|
+
/**
|
|
20
|
+
* Filter out keys from an object.
|
|
21
|
+
* Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
22
|
+
* Returns `never` if `Key` extends `Exclude`.
|
|
23
|
+
* Returns `Key` otherwise.
|
|
24
|
+
*/
|
|
25
|
+
declare type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : KeyType extends ExcludeType ? never : KeyType;
|
|
13
26
|
/**
|
|
14
27
|
Create a type from an object type without certain keys.
|
|
15
28
|
|
|
@@ -33,7 +46,9 @@ export declare type Simplify<T> = {
|
|
|
33
46
|
|
|
34
47
|
@category Utilities
|
|
35
48
|
*/
|
|
36
|
-
export declare type Except<ObjectType, KeysType extends keyof ObjectType> =
|
|
49
|
+
export declare type Except<ObjectType, KeysType extends keyof ObjectType> = {
|
|
50
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
51
|
+
};
|
|
37
52
|
/**
|
|
38
53
|
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
|
39
54
|
|
|
@@ -82,7 +97,27 @@ interface ReadonlySetDeep<ItemType> extends ReadonlySet<ReadonlyDeep<ItemType>>
|
|
|
82
97
|
declare type ReadonlyObjectDeep<ObjectType extends object> = {
|
|
83
98
|
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>;
|
|
84
99
|
};
|
|
85
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
102
|
+
* This is the counterpart of `OmitIndexSignature`.
|
|
103
|
+
* When you use a type that will iterate through an object that has indexed keys and explicitly defined keys you end up with a type where only the indexed keys are kept. This is because `keyof` of an indexed type always returns `string | number | symbol`, because every key is possible in that object. With this type, you can save the indexed keys and reinject them later, like in the second example below.
|
|
104
|
+
*/
|
|
105
|
+
export declare type PickIndexSignature<ObjectType> = {
|
|
106
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType];
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
110
|
+
* This is the counterpart of `PickIndexSignature`.
|
|
111
|
+
* Use-cases:
|
|
112
|
+
* - Remove overly permissive signatures from third-party types.
|
|
113
|
+
*
|
|
114
|
+
* This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
115
|
+
* It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
116
|
+
* (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
117
|
+
*/
|
|
118
|
+
export declare type OmitIndexSignature<ObjectType> = {
|
|
119
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType];
|
|
120
|
+
};
|
|
86
121
|
/**
|
|
87
122
|
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
88
123
|
|
|
@@ -104,7 +139,9 @@ declare type Merge_<FirstType, SecondType> = Except<FirstType, Extract<keyof Fir
|
|
|
104
139
|
|
|
105
140
|
@category Utilities
|
|
106
141
|
*/
|
|
107
|
-
export declare type Merge<
|
|
142
|
+
export declare type Merge<Destination, Source> = {
|
|
143
|
+
[Key in keyof OmitIndexSignature<Destination & Source>]: Key extends keyof Source ? Source[Key] : Key extends keyof Destination ? Destination[Key] : never;
|
|
144
|
+
} & PickIndexSignature<Destination & Source>;
|
|
108
145
|
/**
|
|
109
146
|
Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
110
147
|
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Promisable } from './typeFest';
|
|
2
2
|
/**
|
|
3
3
|
* Map from String to String (or <T>).
|
|
4
4
|
*
|
|
@@ -7,14 +7,6 @@ import type { Except, Merge, Promisable } from './typeFest';
|
|
|
7
7
|
export interface StringMap<T = string> {
|
|
8
8
|
[k: string | number]: T | undefined;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Object to be passed to pProps to resolve all promises into properties.
|
|
12
|
-
*
|
|
13
|
-
* Alternative: Record<String, Promise<any>>
|
|
14
|
-
*/
|
|
15
|
-
export interface PromiseMap {
|
|
16
|
-
[prop: string]: Promise<any> | undefined;
|
|
17
|
-
}
|
|
18
10
|
/**
|
|
19
11
|
* Convenience shorthand for `Record<string, any>`.
|
|
20
12
|
* Because `object` type is not safe/recommended to be used (e.g discouraged by eslint-typescript due to: https://github.com/microsoft/TypeScript/issues/21732)
|
|
@@ -56,10 +48,10 @@ export interface SavedDBEntity<ID extends string | number = string> {
|
|
|
56
48
|
* When it's known to be saved - `SavedDBEntity` interface can be used instead.
|
|
57
49
|
*/
|
|
58
50
|
export declare type BaseDBEntity<ID extends string | number = string> = Partial<SavedDBEntity<ID>>;
|
|
59
|
-
export declare type Saved<T extends Partial<ObjectWithId>> =
|
|
60
|
-
export declare type Unsaved<T extends Partial<ObjectWithId>> =
|
|
61
|
-
export declare type UnsavedId<T extends Partial<ObjectWithId>> =
|
|
62
|
-
id
|
|
51
|
+
export declare type Saved<T extends Partial<ObjectWithId>> = Omit<T, 'id' | 'created' | 'updated'> & SavedDBEntity<NonNullable<T['id']>>;
|
|
52
|
+
export declare type Unsaved<T extends Partial<ObjectWithId>> = Omit<T, 'id' | 'created' | 'updated'> & BaseDBEntity<NonNullable<T['id']>>;
|
|
53
|
+
export declare type UnsavedId<T extends Partial<ObjectWithId>> = Omit<T, 'id'> & {
|
|
54
|
+
id?: T['id'];
|
|
63
55
|
};
|
|
64
56
|
/**
|
|
65
57
|
* Convenience type shorthand.
|
package/dist-esm/index.js
CHANGED
|
@@ -2,13 +2,14 @@ export * from './array/array.util';
|
|
|
2
2
|
export * from './lazy';
|
|
3
3
|
export * from './string/url.util';
|
|
4
4
|
export * from './array/range';
|
|
5
|
-
|
|
5
|
+
export * from './decorators/createPromiseDecorator';
|
|
6
6
|
export * from './decorators/debounce';
|
|
7
7
|
export * from './decorators/debounce.decorator';
|
|
8
8
|
export * from './decorators/decorator.util';
|
|
9
9
|
export * from './decorators/logMethod.decorator';
|
|
10
10
|
export * from './decorators/memo.decorator';
|
|
11
11
|
export * from './decorators/asyncMemo.decorator';
|
|
12
|
+
export * from './decorators/memo.util';
|
|
12
13
|
export * from './decorators/memoFn';
|
|
13
14
|
export * from './decorators/memoFnAsync';
|
|
14
15
|
export * from './decorators/retry.decorator';
|
|
@@ -16,15 +17,18 @@ export * from './decorators/timeout.decorator';
|
|
|
16
17
|
export * from './error/app.error';
|
|
17
18
|
export * from './error/assert';
|
|
18
19
|
export * from './enum.util';
|
|
20
|
+
export * from './error/error.model';
|
|
19
21
|
export * from './error/error.util';
|
|
20
|
-
|
|
22
|
+
export * from './error/errorMode';
|
|
21
23
|
export * from './error/http.error';
|
|
22
24
|
export * from './error/try';
|
|
23
|
-
|
|
25
|
+
export * from './error/tryCatch';
|
|
24
26
|
export * from './json-schema/from-data/generateJsonSchemaFromData';
|
|
25
27
|
export * from './json-schema/jsonSchema.cnst';
|
|
28
|
+
export * from './json-schema/jsonSchema.model';
|
|
26
29
|
export * from './json-schema/jsonSchema.util';
|
|
27
|
-
|
|
30
|
+
export * from './json-schema/jsonSchemaBuilder';
|
|
31
|
+
export * from './json-schema/jsonSchemaBuilder';
|
|
28
32
|
export * from './math/math.util';
|
|
29
33
|
export * from './math/sma';
|
|
30
34
|
export * from './number/createDeterministicRandom';
|
|
@@ -33,25 +37,26 @@ export * from './object/deepEquals';
|
|
|
33
37
|
export * from './object/object.util';
|
|
34
38
|
export * from './object/sortObject';
|
|
35
39
|
export * from './object/sortObjectDeep';
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
export * from './promise/AggregatedError';
|
|
41
|
+
export * from './promise/pDefer';
|
|
38
42
|
export * from './promise/pDelay';
|
|
39
43
|
export * from './promise/pFilter';
|
|
40
44
|
export * from './promise/pHang';
|
|
41
|
-
|
|
45
|
+
export * from './promise/pMap';
|
|
42
46
|
export * from './promise/pProps';
|
|
43
|
-
|
|
47
|
+
export * from './promise/pRetry';
|
|
44
48
|
export * from './promise/pState';
|
|
45
|
-
|
|
49
|
+
export * from './promise/pTimeout';
|
|
46
50
|
export * from './string/case';
|
|
47
51
|
export * from './string/json.util';
|
|
48
52
|
export * from './string/string.util';
|
|
49
53
|
export * from './string/readingTime';
|
|
50
54
|
export * from './string/escape';
|
|
51
55
|
export * from './string/pupa';
|
|
52
|
-
|
|
56
|
+
export * from './string/stringifyAny';
|
|
53
57
|
export * from './time/time.util';
|
|
54
58
|
export * from './is.util';
|
|
59
|
+
export * from './typeFest';
|
|
55
60
|
export * from './types';
|
|
56
61
|
export * from './unit/size.util';
|
|
57
62
|
import { is } from './vendor/is';
|
|
@@ -65,4 +70,8 @@ export * from './datetime/localDate';
|
|
|
65
70
|
export * from './datetime/localTime';
|
|
66
71
|
export * from './datetime/dateInterval';
|
|
67
72
|
export * from './datetime/timeInterval';
|
|
68
|
-
export
|
|
73
|
+
export * from './datetime/localDate';
|
|
74
|
+
export * from './datetime/localTime';
|
|
75
|
+
export * from './datetime/dateInterval';
|
|
76
|
+
export * from './datetime/timeInterval';
|
|
77
|
+
export { is };
|
|
@@ -263,25 +263,24 @@ export function _invertMap(m) {
|
|
|
263
263
|
return inv;
|
|
264
264
|
}
|
|
265
265
|
/**
|
|
266
|
-
* Gets the property value at path of object.
|
|
267
|
-
* in its place.
|
|
266
|
+
* Gets the property value at path of object.
|
|
268
267
|
*
|
|
269
|
-
* @
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
268
|
+
* @example
|
|
269
|
+
* const obj = {a: 'a', b: 'b', c: { cc: 'cc' }}
|
|
270
|
+
* _get(obj, 'a') // 'a'
|
|
271
|
+
* _get(obj, 'c.cc') // 'cc'
|
|
272
|
+
* _get(obj, 'c[cc]') // 'cc'
|
|
273
|
+
* _get(obj, 'unknown.path') // undefined
|
|
273
274
|
*/
|
|
274
|
-
export function _get(obj = {}, path = ''
|
|
275
|
-
|
|
275
|
+
export function _get(obj = {}, path = '') {
|
|
276
|
+
return path
|
|
276
277
|
.replace(/\[([^\]]+)]/g, '.$1')
|
|
277
278
|
.split('.')
|
|
278
|
-
.reduce((o, p) => o[p], obj);
|
|
279
|
-
return res === undefined ? def : res;
|
|
279
|
+
.reduce((o, p) => o === null || o === void 0 ? void 0 : o[p], obj);
|
|
280
280
|
}
|
|
281
281
|
/**
|
|
282
282
|
* Sets the value at path of object. If a portion of path doesn’t exist it’s created. Arrays are created for
|
|
283
|
-
* missing index properties while objects are created for all other missing properties.
|
|
284
|
-
* customize path creation.
|
|
283
|
+
* missing index properties while objects are created for all other missing properties.
|
|
285
284
|
*
|
|
286
285
|
* @param obj The object to modify.
|
|
287
286
|
* @param path The path of the property to set.
|
|
@@ -312,7 +311,7 @@ export function _set(obj, path, value) {
|
|
|
312
311
|
? [] // Yes: assign a new array object
|
|
313
312
|
: {}), // No: assign a new plain object
|
|
314
313
|
obj)[path[path.length - 1]] = value; // Finally assign the value to the last key
|
|
315
|
-
return obj; //
|
|
314
|
+
return obj; // allow chaining
|
|
316
315
|
}
|
|
317
316
|
/**
|
|
318
317
|
* Checks if `path` is a direct property of `object` (not null, not undefined).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.111.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"build-prod": "build-prod-esm-cjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@naturalcycles/time-lib": "^3.5.1",
|
|
18
18
|
"@types/node": "^18.0.0",
|
|
19
19
|
"expect-type": "^0.13.0",
|
|
20
|
-
"jest": "^
|
|
20
|
+
"jest": "^29.0.0",
|
|
21
21
|
"prettier": "^2.1.2",
|
|
22
22
|
"rxjs": "^7.0.1",
|
|
23
23
|
"vuepress": "^1.7.1",
|
package/src/error/error.util.ts
CHANGED
|
@@ -87,11 +87,13 @@ export function _errorToErrorObject<DATA_TYPE extends ErrorData = ErrorData>(
|
|
|
87
87
|
return obj
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
export function _errorObjectToAppError<DATA_TYPE
|
|
90
|
+
export function _errorObjectToAppError<DATA_TYPE extends ErrorData>(
|
|
91
|
+
o: ErrorObject<DATA_TYPE>,
|
|
92
|
+
): AppError<DATA_TYPE> {
|
|
91
93
|
return _errorObjectToError(o, AppError)
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
export function _errorObjectToError<DATA_TYPE, ERROR_TYPE extends Error>(
|
|
96
|
+
export function _errorObjectToError<DATA_TYPE extends ErrorData, ERROR_TYPE extends Error>(
|
|
95
97
|
o: ErrorObject<DATA_TYPE>,
|
|
96
98
|
errorClass: Class<ERROR_TYPE> = Error as any,
|
|
97
99
|
): ERROR_TYPE {
|
package/src/index.ts
CHANGED
|
@@ -2,15 +2,14 @@ export * from './array/array.util'
|
|
|
2
2
|
export * from './lazy'
|
|
3
3
|
export * from './string/url.util'
|
|
4
4
|
export * from './array/range'
|
|
5
|
-
|
|
6
|
-
import { _createPromiseDecorator } from './decorators/createPromiseDecorator'
|
|
5
|
+
export * from './decorators/createPromiseDecorator'
|
|
7
6
|
export * from './decorators/debounce'
|
|
8
7
|
export * from './decorators/debounce.decorator'
|
|
9
8
|
export * from './decorators/decorator.util'
|
|
10
9
|
export * from './decorators/logMethod.decorator'
|
|
11
10
|
export * from './decorators/memo.decorator'
|
|
12
11
|
export * from './decorators/asyncMemo.decorator'
|
|
13
|
-
|
|
12
|
+
export * from './decorators/memo.util'
|
|
14
13
|
export * from './decorators/memoFn'
|
|
15
14
|
export * from './decorators/memoFnAsync'
|
|
16
15
|
export * from './decorators/retry.decorator'
|
|
@@ -18,44 +17,18 @@ export * from './decorators/timeout.decorator'
|
|
|
18
17
|
export * from './error/app.error'
|
|
19
18
|
export * from './error/assert'
|
|
20
19
|
export * from './enum.util'
|
|
21
|
-
|
|
22
|
-
Admin401ErrorData,
|
|
23
|
-
Admin403ErrorData,
|
|
24
|
-
ErrorData,
|
|
25
|
-
ErrorObject,
|
|
26
|
-
HttpErrorData,
|
|
27
|
-
HttpErrorResponse,
|
|
28
|
-
} from './error/error.model'
|
|
20
|
+
export * from './error/error.model'
|
|
29
21
|
export * from './error/error.util'
|
|
30
|
-
|
|
22
|
+
export * from './error/errorMode'
|
|
31
23
|
export * from './error/http.error'
|
|
32
24
|
export * from './error/try'
|
|
33
|
-
|
|
34
|
-
import { _TryCatch, _tryCatch } from './error/tryCatch'
|
|
25
|
+
export * from './error/tryCatch'
|
|
35
26
|
export * from './json-schema/from-data/generateJsonSchemaFromData'
|
|
36
27
|
export * from './json-schema/jsonSchema.cnst'
|
|
37
|
-
|
|
38
|
-
JsonSchema,
|
|
39
|
-
JsonSchemaAllOf,
|
|
40
|
-
JsonSchemaAny,
|
|
41
|
-
JsonSchemaAnyOf,
|
|
42
|
-
JsonSchemaArray,
|
|
43
|
-
JsonSchemaBoolean,
|
|
44
|
-
JsonSchemaConst,
|
|
45
|
-
JsonSchemaEnum,
|
|
46
|
-
JsonSchemaNot,
|
|
47
|
-
JsonSchemaNull,
|
|
48
|
-
JsonSchemaNumber,
|
|
49
|
-
JsonSchemaRootObject,
|
|
50
|
-
JsonSchemaObject,
|
|
51
|
-
JsonSchemaOneOf,
|
|
52
|
-
JsonSchemaRef,
|
|
53
|
-
JsonSchemaString,
|
|
54
|
-
JsonSchemaTuple,
|
|
55
|
-
} from './json-schema/jsonSchema.model'
|
|
28
|
+
export * from './json-schema/jsonSchema.model'
|
|
56
29
|
export * from './json-schema/jsonSchema.util'
|
|
57
|
-
|
|
58
|
-
|
|
30
|
+
export * from './json-schema/jsonSchemaBuilder'
|
|
31
|
+
export * from './json-schema/jsonSchemaBuilder'
|
|
59
32
|
export * from './math/math.util'
|
|
60
33
|
export * from './math/sma'
|
|
61
34
|
export * from './number/createDeterministicRandom'
|
|
@@ -64,95 +37,31 @@ export * from './object/deepEquals'
|
|
|
64
37
|
export * from './object/object.util'
|
|
65
38
|
export * from './object/sortObject'
|
|
66
39
|
export * from './object/sortObjectDeep'
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
import { pDefer } from './promise/pDefer'
|
|
40
|
+
export * from './promise/AggregatedError'
|
|
41
|
+
export * from './promise/pDefer'
|
|
70
42
|
export * from './promise/pDelay'
|
|
71
43
|
export * from './promise/pFilter'
|
|
72
44
|
export * from './promise/pHang'
|
|
73
|
-
|
|
74
|
-
import { pMap } from './promise/pMap'
|
|
45
|
+
export * from './promise/pMap'
|
|
75
46
|
export * from './promise/pProps'
|
|
76
|
-
|
|
77
|
-
import { pRetry, pRetryFn } from './promise/pRetry'
|
|
47
|
+
export * from './promise/pRetry'
|
|
78
48
|
export * from './promise/pState'
|
|
79
|
-
|
|
80
|
-
import { pTimeout, pTimeoutFn } from './promise/pTimeout'
|
|
49
|
+
export * from './promise/pTimeout'
|
|
81
50
|
export * from './string/case'
|
|
82
51
|
export * from './string/json.util'
|
|
83
52
|
export * from './string/string.util'
|
|
84
53
|
export * from './string/readingTime'
|
|
85
54
|
export * from './string/escape'
|
|
86
55
|
export * from './string/pupa'
|
|
87
|
-
|
|
88
|
-
import { _stringifyAny } from './string/stringifyAny'
|
|
56
|
+
export * from './string/stringifyAny'
|
|
89
57
|
export * from './time/time.util'
|
|
90
58
|
export * from './is.util'
|
|
91
|
-
|
|
92
|
-
import type {
|
|
93
|
-
Class,
|
|
94
|
-
ConditionalExcept,
|
|
95
|
-
ConditionalPick,
|
|
96
|
-
Merge,
|
|
97
|
-
Promisable,
|
|
98
|
-
ReadonlyDeep,
|
|
99
|
-
Simplify,
|
|
100
|
-
} from './typeFest'
|
|
101
|
-
import type {
|
|
102
|
-
AsyncMapper,
|
|
103
|
-
AsyncPredicate,
|
|
104
|
-
BaseDBEntity,
|
|
105
|
-
CreatedUpdated,
|
|
106
|
-
CreatedUpdatedId,
|
|
107
|
-
ObjectWithId,
|
|
108
|
-
AnyObjectWithId,
|
|
109
|
-
Saved,
|
|
110
|
-
Unsaved,
|
|
111
|
-
UnsavedId,
|
|
112
|
-
BatchResult,
|
|
113
|
-
InstanceId,
|
|
114
|
-
IsoDate,
|
|
115
|
-
IsoDateString,
|
|
116
|
-
IsoDateTimeString,
|
|
117
|
-
KeyValueTuple,
|
|
118
|
-
Mapper,
|
|
119
|
-
ObjectMapper,
|
|
120
|
-
ObjectPredicate,
|
|
121
|
-
Predicate,
|
|
122
|
-
PromiseMap,
|
|
123
|
-
AnyObject,
|
|
124
|
-
AnyEnum,
|
|
125
|
-
NumberEnum,
|
|
126
|
-
StringEnum,
|
|
127
|
-
AnyFunction,
|
|
128
|
-
Reviver,
|
|
129
|
-
SavedDBEntity,
|
|
130
|
-
StringMap,
|
|
131
|
-
UnixTimestampNumber,
|
|
132
|
-
UnixTimestampMillisNumber,
|
|
133
|
-
UnixTimestamp,
|
|
134
|
-
Integer,
|
|
135
|
-
ValueOf,
|
|
136
|
-
ValuesOf,
|
|
137
|
-
AbortableMapper,
|
|
138
|
-
AbortableAsyncPredicate,
|
|
139
|
-
AbortableAsyncMapper,
|
|
140
|
-
AbortablePredicate,
|
|
141
|
-
NullishValue,
|
|
142
|
-
FalsyValue,
|
|
143
|
-
} from './types'
|
|
59
|
+
export * from './typeFest'
|
|
144
60
|
export * from './types'
|
|
145
61
|
export * from './unit/size.util'
|
|
146
62
|
import { is } from './vendor/is'
|
|
147
|
-
import type {
|
|
148
|
-
CommonLogLevel,
|
|
149
|
-
CommonLogFunction,
|
|
150
|
-
CommonLogger,
|
|
151
|
-
CommonLogWithLevelFunction,
|
|
152
|
-
} from './log/commonLogger'
|
|
153
63
|
export * from './log/commonLogger'
|
|
154
64
|
export * from './string/safeJsonStringify'
|
|
155
|
-
import type { PQueueCfg } from './promise/pQueue'
|
|
156
65
|
export * from './promise/pQueue'
|
|
157
66
|
export * from './seq/seq'
|
|
158
67
|
export * from './math/stack.util'
|
|
@@ -161,142 +70,9 @@ export * from './datetime/localDate'
|
|
|
161
70
|
export * from './datetime/localTime'
|
|
162
71
|
export * from './datetime/dateInterval'
|
|
163
72
|
export * from './datetime/timeInterval'
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
LocalDateUnitStrict,
|
|
169
|
-
Inclusiveness,
|
|
170
|
-
} from './datetime/localDate'
|
|
171
|
-
import type {
|
|
172
|
-
LocalTimeConfig,
|
|
173
|
-
LocalTimeFormatter,
|
|
174
|
-
LocalTimeUnit,
|
|
175
|
-
LocalTimeComponents,
|
|
176
|
-
ISODayOfWeek,
|
|
177
|
-
} from './datetime/localTime'
|
|
178
|
-
import type { DateIntervalConfig, DateIntervalString } from './datetime/dateInterval'
|
|
179
|
-
import type { TimeIntervalConfig, TimeIntervalString } from './datetime/timeInterval'
|
|
180
|
-
|
|
181
|
-
export type {
|
|
182
|
-
DateIntervalConfig,
|
|
183
|
-
DateIntervalString,
|
|
184
|
-
TimeIntervalConfig,
|
|
185
|
-
TimeIntervalString,
|
|
186
|
-
LocalDateConfig,
|
|
187
|
-
LocalDateFormatter,
|
|
188
|
-
LocalDateUnit,
|
|
189
|
-
LocalDateUnitStrict,
|
|
190
|
-
Inclusiveness,
|
|
191
|
-
LocalTimeConfig,
|
|
192
|
-
LocalTimeFormatter,
|
|
193
|
-
LocalTimeUnit,
|
|
194
|
-
ISODayOfWeek,
|
|
195
|
-
LocalTimeComponents,
|
|
196
|
-
AbortableMapper,
|
|
197
|
-
AbortablePredicate,
|
|
198
|
-
AbortableAsyncPredicate,
|
|
199
|
-
AbortableAsyncMapper,
|
|
200
|
-
PQueueCfg,
|
|
201
|
-
MemoCache,
|
|
202
|
-
AsyncMemoCache,
|
|
203
|
-
PromiseDecoratorCfg,
|
|
204
|
-
PromiseDecoratorResp,
|
|
205
|
-
ErrorData,
|
|
206
|
-
ErrorObject,
|
|
207
|
-
HttpErrorData,
|
|
208
|
-
HttpErrorResponse,
|
|
209
|
-
Admin401ErrorData,
|
|
210
|
-
Admin403ErrorData,
|
|
211
|
-
StringMap,
|
|
212
|
-
PromiseMap,
|
|
213
|
-
AnyObject,
|
|
214
|
-
AnyEnum,
|
|
215
|
-
NumberEnum,
|
|
216
|
-
StringEnum,
|
|
217
|
-
AnyFunction,
|
|
218
|
-
ValuesOf,
|
|
219
|
-
ValueOf,
|
|
220
|
-
KeyValueTuple,
|
|
221
|
-
ObjectMapper,
|
|
222
|
-
ObjectPredicate,
|
|
223
|
-
InstanceId,
|
|
224
|
-
IsoDate,
|
|
225
|
-
IsoDateString,
|
|
226
|
-
IsoDateTimeString,
|
|
227
|
-
Reviver,
|
|
228
|
-
FalsyValue,
|
|
229
|
-
NullishValue,
|
|
230
|
-
PMapOptions,
|
|
231
|
-
Mapper,
|
|
232
|
-
AsyncMapper,
|
|
233
|
-
Predicate,
|
|
234
|
-
AsyncPredicate,
|
|
235
|
-
BatchResult,
|
|
236
|
-
DeferredPromise,
|
|
237
|
-
PRetryOptions,
|
|
238
|
-
PTimeoutOptions,
|
|
239
|
-
TryCatchOptions,
|
|
240
|
-
StringifyAnyOptions,
|
|
241
|
-
JsonStringifyFunction,
|
|
242
|
-
Merge,
|
|
243
|
-
ReadonlyDeep,
|
|
244
|
-
Promisable,
|
|
245
|
-
Simplify,
|
|
246
|
-
ConditionalPick,
|
|
247
|
-
ConditionalExcept,
|
|
248
|
-
Class,
|
|
249
|
-
UnixTimestampNumber,
|
|
250
|
-
UnixTimestampMillisNumber,
|
|
251
|
-
UnixTimestamp,
|
|
252
|
-
Integer,
|
|
253
|
-
BaseDBEntity,
|
|
254
|
-
SavedDBEntity,
|
|
255
|
-
Saved,
|
|
256
|
-
Unsaved,
|
|
257
|
-
UnsavedId,
|
|
258
|
-
CreatedUpdated,
|
|
259
|
-
CreatedUpdatedId,
|
|
260
|
-
ObjectWithId,
|
|
261
|
-
AnyObjectWithId,
|
|
262
|
-
JsonSchema,
|
|
263
|
-
JsonSchemaAny,
|
|
264
|
-
JsonSchemaOneOf,
|
|
265
|
-
JsonSchemaAllOf,
|
|
266
|
-
JsonSchemaAnyOf,
|
|
267
|
-
JsonSchemaNot,
|
|
268
|
-
JsonSchemaRef,
|
|
269
|
-
JsonSchemaConst,
|
|
270
|
-
JsonSchemaEnum,
|
|
271
|
-
JsonSchemaString,
|
|
272
|
-
JsonSchemaNumber,
|
|
273
|
-
JsonSchemaBoolean,
|
|
274
|
-
JsonSchemaNull,
|
|
275
|
-
JsonSchemaRootObject,
|
|
276
|
-
JsonSchemaObject,
|
|
277
|
-
JsonSchemaArray,
|
|
278
|
-
JsonSchemaTuple,
|
|
279
|
-
JsonSchemaBuilder,
|
|
280
|
-
CommonLogLevel,
|
|
281
|
-
CommonLogWithLevelFunction,
|
|
282
|
-
CommonLogFunction,
|
|
283
|
-
CommonLogger,
|
|
284
|
-
}
|
|
73
|
+
export * from './datetime/localDate'
|
|
74
|
+
export * from './datetime/localTime'
|
|
75
|
+
export * from './datetime/dateInterval'
|
|
76
|
+
export * from './datetime/timeInterval'
|
|
285
77
|
|
|
286
|
-
export {
|
|
287
|
-
is,
|
|
288
|
-
_createPromiseDecorator,
|
|
289
|
-
pMap,
|
|
290
|
-
ErrorMode,
|
|
291
|
-
pDefer,
|
|
292
|
-
AggregatedError,
|
|
293
|
-
pRetry,
|
|
294
|
-
pRetryFn,
|
|
295
|
-
pTimeout,
|
|
296
|
-
pTimeoutFn,
|
|
297
|
-
_tryCatch,
|
|
298
|
-
_TryCatch,
|
|
299
|
-
_stringifyAny,
|
|
300
|
-
jsonSchema,
|
|
301
|
-
JsonSchemaAnyBuilder,
|
|
302
|
-
}
|
|
78
|
+
export { is }
|
|
@@ -20,7 +20,9 @@ type Type = PrimitiveType | 'array' | 'object'
|
|
|
20
20
|
*
|
|
21
21
|
* `additionalProperties` is set to `true`, cause it's safer.
|
|
22
22
|
*/
|
|
23
|
-
export function generateJsonSchemaFromData<T =
|
|
23
|
+
export function generateJsonSchemaFromData<T extends AnyObject = AnyObject>(
|
|
24
|
+
rows: AnyObject[],
|
|
25
|
+
): JsonSchemaObject<T> {
|
|
24
26
|
return objectToJsonSchema(rows as any) as JsonSchemaObject<T>
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _uniq } from '../index'
|
|
1
|
+
import { _uniq, AnyObject } from '../index'
|
|
2
2
|
import { _filterNullishValues } from '../object/object.util'
|
|
3
3
|
import type { JsonSchemaObject } from './jsonSchema.model'
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ import type { JsonSchemaObject } from './jsonSchema.model'
|
|
|
7
7
|
* Does not mutate s2.
|
|
8
8
|
* API similar to Object.assign(s1, s2)
|
|
9
9
|
*/
|
|
10
|
-
export function mergeJsonSchemaObjects<T1, T2>(
|
|
10
|
+
export function mergeJsonSchemaObjects<T1 extends AnyObject, T2 extends AnyObject>(
|
|
11
11
|
s1: JsonSchemaObject<T1>,
|
|
12
12
|
s2: JsonSchemaObject<T2>,
|
|
13
13
|
): JsonSchemaObject<T1 & T2> {
|
|
@@ -311,27 +311,25 @@ export function _invertMap<K, V>(m: ReadonlyMap<K, V>): Map<V, K> {
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
/**
|
|
314
|
-
* Gets the property value at path of object.
|
|
315
|
-
* in its place.
|
|
314
|
+
* Gets the property value at path of object.
|
|
316
315
|
*
|
|
317
|
-
* @
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
316
|
+
* @example
|
|
317
|
+
* const obj = {a: 'a', b: 'b', c: { cc: 'cc' }}
|
|
318
|
+
* _get(obj, 'a') // 'a'
|
|
319
|
+
* _get(obj, 'c.cc') // 'cc'
|
|
320
|
+
* _get(obj, 'c[cc]') // 'cc'
|
|
321
|
+
* _get(obj, 'unknown.path') // undefined
|
|
321
322
|
*/
|
|
322
|
-
export function _get<T extends AnyObject>(obj = {} as T, path = ''
|
|
323
|
-
|
|
323
|
+
export function _get<T extends AnyObject>(obj = {} as T, path = ''): unknown {
|
|
324
|
+
return path
|
|
324
325
|
.replace(/\[([^\]]+)]/g, '.$1')
|
|
325
326
|
.split('.')
|
|
326
|
-
.reduce((o, p) => o[p], obj)
|
|
327
|
-
|
|
328
|
-
return res === undefined ? def : res
|
|
327
|
+
.reduce((o, p) => o?.[p], obj)
|
|
329
328
|
}
|
|
330
329
|
|
|
331
330
|
/**
|
|
332
331
|
* Sets the value at path of object. If a portion of path doesn’t exist it’s created. Arrays are created for
|
|
333
|
-
* missing index properties while objects are created for all other missing properties.
|
|
334
|
-
* customize path creation.
|
|
332
|
+
* missing index properties while objects are created for all other missing properties.
|
|
335
333
|
*
|
|
336
334
|
* @param obj The object to modify.
|
|
337
335
|
* @param path The path of the property to set.
|
|
@@ -340,11 +338,7 @@ export function _get<T extends AnyObject>(obj = {} as T, path = '', def?: any):
|
|
|
340
338
|
*
|
|
341
339
|
* Based on: https://stackoverflow.com/a/54733755/4919972
|
|
342
340
|
*/
|
|
343
|
-
export function _set<
|
|
344
|
-
obj: IN,
|
|
345
|
-
path: PropertyPath,
|
|
346
|
-
value?: any,
|
|
347
|
-
): OUT {
|
|
341
|
+
export function _set<T extends AnyObject>(obj: T, path: PropertyPath, value: any): T {
|
|
348
342
|
if (!obj || Object(obj) !== obj || !path) return obj as any // When obj is not an object
|
|
349
343
|
|
|
350
344
|
// If not yet an array, get the keys from the string-path
|
|
@@ -373,7 +367,7 @@ export function _set<IN extends AnyObject, OUT = IN>(
|
|
|
373
367
|
obj,
|
|
374
368
|
)[path[path.length - 1]!] = value // Finally assign the value to the last key
|
|
375
369
|
|
|
376
|
-
return obj
|
|
370
|
+
return obj // allow chaining
|
|
377
371
|
}
|
|
378
372
|
|
|
379
373
|
/**
|
|
@@ -400,7 +394,7 @@ export function _set<IN extends AnyObject, OUT = IN>(
|
|
|
400
394
|
* _.has(other, 'a');
|
|
401
395
|
* // => false
|
|
402
396
|
*/
|
|
403
|
-
export function _has<T extends AnyObject>(obj: T, path
|
|
397
|
+
export function _has<T extends AnyObject>(obj: T, path: string): boolean {
|
|
404
398
|
const v = _get(obj, path)
|
|
405
399
|
return v !== undefined && v !== null
|
|
406
400
|
}
|
package/src/typeFest.ts
CHANGED
|
@@ -12,6 +12,27 @@ export type Primitive = null | undefined | string | number | boolean | symbol |
|
|
|
12
12
|
*/
|
|
13
13
|
export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] }
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
Returns a boolean for whether the two given types are equal.
|
|
17
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
18
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
19
|
+
*/
|
|
20
|
+
export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2
|
|
21
|
+
? true
|
|
22
|
+
: false
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Filter out keys from an object.
|
|
26
|
+
* Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
27
|
+
* Returns `never` if `Key` extends `Exclude`.
|
|
28
|
+
* Returns `Key` otherwise.
|
|
29
|
+
*/
|
|
30
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true
|
|
31
|
+
? never
|
|
32
|
+
: KeyType extends ExcludeType
|
|
33
|
+
? never
|
|
34
|
+
: KeyType
|
|
35
|
+
|
|
15
36
|
/**
|
|
16
37
|
Create a type from an object type without certain keys.
|
|
17
38
|
|
|
@@ -35,10 +56,9 @@ export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] }
|
|
|
35
56
|
|
|
36
57
|
@category Utilities
|
|
37
58
|
*/
|
|
38
|
-
export type Except<ObjectType, KeysType extends keyof ObjectType> =
|
|
39
|
-
ObjectType,
|
|
40
|
-
|
|
41
|
-
>
|
|
59
|
+
export type Except<ObjectType, KeysType extends keyof ObjectType> = {
|
|
60
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType]
|
|
61
|
+
}
|
|
42
62
|
|
|
43
63
|
/**
|
|
44
64
|
Convert `object`s, `Map`s, `Set`s, and `Array`s and all of their keys/elements into immutable structures recursively.
|
|
@@ -99,8 +119,32 @@ type ReadonlyObjectDeep<ObjectType extends object> = {
|
|
|
99
119
|
readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
|
|
100
120
|
}
|
|
101
121
|
|
|
102
|
-
|
|
103
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
124
|
+
* This is the counterpart of `OmitIndexSignature`.
|
|
125
|
+
* When you use a type that will iterate through an object that has indexed keys and explicitly defined keys you end up with a type where only the indexed keys are kept. This is because `keyof` of an indexed type always returns `string | number | symbol`, because every key is possible in that object. With this type, you can save the indexed keys and reinject them later, like in the second example below.
|
|
126
|
+
*/
|
|
127
|
+
export type PickIndexSignature<ObjectType> = {
|
|
128
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
129
|
+
? KeyType
|
|
130
|
+
: never]: ObjectType[KeyType]
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
135
|
+
* This is the counterpart of `PickIndexSignature`.
|
|
136
|
+
* Use-cases:
|
|
137
|
+
* - Remove overly permissive signatures from third-party types.
|
|
138
|
+
*
|
|
139
|
+
* This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
140
|
+
* It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
141
|
+
* (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
142
|
+
*/
|
|
143
|
+
export type OmitIndexSignature<ObjectType> = {
|
|
144
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
145
|
+
? never
|
|
146
|
+
: KeyType]: ObjectType[KeyType]
|
|
147
|
+
}
|
|
104
148
|
|
|
105
149
|
/**
|
|
106
150
|
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
@@ -123,7 +167,13 @@ type Merge_<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType,
|
|
|
123
167
|
|
|
124
168
|
@category Utilities
|
|
125
169
|
*/
|
|
126
|
-
export type Merge<
|
|
170
|
+
export type Merge<Destination, Source> = {
|
|
171
|
+
[Key in keyof OmitIndexSignature<Destination & Source>]: Key extends keyof Source
|
|
172
|
+
? Source[Key]
|
|
173
|
+
: Key extends keyof Destination
|
|
174
|
+
? Destination[Key]
|
|
175
|
+
: never
|
|
176
|
+
} & PickIndexSignature<Destination & Source>
|
|
127
177
|
|
|
128
178
|
/**
|
|
129
179
|
Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Promisable } from './typeFest'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Map from String to String (or <T>).
|
|
@@ -9,15 +9,6 @@ export interface StringMap<T = string> {
|
|
|
9
9
|
[k: string | number]: T | undefined
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Object to be passed to pProps to resolve all promises into properties.
|
|
14
|
-
*
|
|
15
|
-
* Alternative: Record<String, Promise<any>>
|
|
16
|
-
*/
|
|
17
|
-
export interface PromiseMap {
|
|
18
|
-
[prop: string]: Promise<any> | undefined
|
|
19
|
-
}
|
|
20
|
-
|
|
21
12
|
/**
|
|
22
13
|
* Convenience shorthand for `Record<string, any>`.
|
|
23
14
|
* Because `object` type is not safe/recommended to be used (e.g discouraged by eslint-typescript due to: https://github.com/microsoft/TypeScript/issues/21732)
|
|
@@ -71,18 +62,15 @@ export interface SavedDBEntity<ID extends string | number = string> {
|
|
|
71
62
|
*/
|
|
72
63
|
export type BaseDBEntity<ID extends string | number = string> = Partial<SavedDBEntity<ID>>
|
|
73
64
|
|
|
74
|
-
export type Saved<T extends Partial<ObjectWithId>> =
|
|
75
|
-
|
|
76
|
-
SavedDBEntity<
|
|
77
|
-
>
|
|
65
|
+
// export type Saved<T extends Partial<ObjectWithId>> = Omit<T, 'id' | 'created' | 'updated'> & SavedDBEntity<NonNullable<T['id']>>
|
|
66
|
+
export type Saved<T extends Partial<ObjectWithId>> = Omit<T, 'id' | 'created' | 'updated'> &
|
|
67
|
+
SavedDBEntity<NonNullable<T['id']>>
|
|
78
68
|
|
|
79
|
-
export type Unsaved<T extends Partial<ObjectWithId>> =
|
|
80
|
-
T
|
|
81
|
-
BaseDBEntity<Exclude<T['id'], undefined>>
|
|
82
|
-
>
|
|
69
|
+
export type Unsaved<T extends Partial<ObjectWithId>> = Omit<T, 'id' | 'created' | 'updated'> &
|
|
70
|
+
BaseDBEntity<NonNullable<T['id']>>
|
|
83
71
|
|
|
84
|
-
export type UnsavedId<T extends Partial<ObjectWithId>> =
|
|
85
|
-
id
|
|
72
|
+
export type UnsavedId<T extends Partial<ObjectWithId>> = Omit<T, 'id'> & {
|
|
73
|
+
id?: T['id']
|
|
86
74
|
}
|
|
87
75
|
|
|
88
76
|
/**
|