@naturalcycles/js-lib 14.109.2 → 14.110.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/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
- import type { PromiseDecoratorCfg, PromiseDecoratorResp } from './decorators/createPromiseDecorator';
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
- import type { MemoCache, AsyncMemoCache } from './decorators/memo.util';
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
- import type { Admin401ErrorData, Admin403ErrorData, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse } from './error/error.model';
20
+ export * from './error/error.model';
22
21
  export * from './error/error.util';
23
- import { ErrorMode } from './error/errorMode';
22
+ export * from './error/errorMode';
24
23
  export * from './error/http.error';
25
24
  export * from './error/try';
26
- import type { TryCatchOptions } from './error/tryCatch';
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
- import type { JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaAnyOf, JsonSchemaArray, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNot, JsonSchemaNull, JsonSchemaNumber, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaOneOf, JsonSchemaRef, JsonSchemaString, JsonSchemaTuple } from './json-schema/jsonSchema.model';
28
+ export * from './json-schema/jsonSchema.model';
31
29
  export * from './json-schema/jsonSchema.util';
32
- import type { JsonSchemaBuilder } from './json-schema/jsonSchemaBuilder';
33
- import { jsonSchema, JsonSchemaAnyBuilder } from './json-schema/jsonSchemaBuilder';
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
- import { AggregatedError } from './promise/AggregatedError';
43
- import type { DeferredPromise } from './promise/pDefer';
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
- import type { PMapOptions } from './promise/pMap';
49
- import { pMap } from './promise/pMap';
45
+ export * from './promise/pMap';
50
46
  export * from './promise/pProps';
51
- import type { PRetryOptions } from './promise/pRetry';
52
- import { pRetry, pRetryFn } from './promise/pRetry';
47
+ export * from './promise/pRetry';
53
48
  export * from './promise/pState';
54
- import type { PTimeoutOptions } from './promise/pTimeout';
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
- import type { JsonStringifyFunction, StringifyAnyOptions } from './string/stringifyAny';
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
- import type { Class, ConditionalExcept, ConditionalPick, Merge, Promisable, ReadonlyDeep, Simplify } from './typeFest';
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
- import type { LocalDateConfig, LocalDateFormatter, LocalDateUnit, LocalDateUnitStrict, Inclusiveness } from './datetime/localDate';
84
- import type { LocalTimeConfig, LocalTimeFormatter, LocalTimeUnit, LocalTimeComponents, ISODayOfWeek } from './datetime/localTime';
85
- import type { DateIntervalConfig, DateIntervalString } from './datetime/dateInterval';
86
- import type { TimeIntervalConfig, TimeIntervalString } from './datetime/timeInterval';
87
- export type { DateIntervalConfig, DateIntervalString, TimeIntervalConfig, TimeIntervalString, LocalDateConfig, LocalDateFormatter, LocalDateUnit, LocalDateUnitStrict, Inclusiveness, LocalTimeConfig, LocalTimeFormatter, LocalTimeUnit, ISODayOfWeek, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyEnum, NumberEnum, StringEnum, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, Reviver, FalsyValue, NullishValue, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestampNumber, UnixTimestampMillisNumber, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, UnsavedId, 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, };
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.JsonSchemaAnyBuilder = exports.jsonSchema = exports._stringifyAny = exports._TryCatch = exports._tryCatch = exports.pTimeoutFn = exports.pTimeout = exports.pRetryFn = exports.pRetry = exports.AggregatedError = exports.pDefer = exports.ErrorMode = exports.pMap = exports._createPromiseDecorator = exports.is = void 0;
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
- const createPromiseDecorator_1 = require("./decorators/createPromiseDecorator");
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
- const errorMode_1 = require("./error/errorMode");
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
- const tryCatch_1 = require("./error/tryCatch");
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
- const jsonSchemaBuilder_1 = require("./json-schema/jsonSchemaBuilder");
36
- Object.defineProperty(exports, "jsonSchema", { enumerable: true, get: function () { return jsonSchemaBuilder_1.jsonSchema; } });
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
- const AggregatedError_1 = require("./promise/AggregatedError");
47
- Object.defineProperty(exports, "AggregatedError", { enumerable: true, get: function () { return AggregatedError_1.AggregatedError; } });
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
- const pMap_1 = require("./promise/pMap");
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
- const pRetry_1 = require("./promise/pRetry");
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
- const pTimeout_1 = require("./promise/pTimeout");
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
- const stringifyAny_1 = require("./string/stringifyAny");
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);
@@ -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> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
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
- declare type Merge_<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
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<FirstType, SecondType> = Simplify<Merge_<FirstType, SecondType>>;
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 { Except, Merge, Promisable } from './typeFest';
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>> = Merge<T, SavedDBEntity<Exclude<T['id'], undefined>>>;
60
- export declare type Unsaved<T extends Partial<ObjectWithId>> = Merge<T, BaseDBEntity<Exclude<T['id'], undefined>>>;
61
- export declare type UnsavedId<T extends Partial<ObjectWithId>> = Except<T, 'id'> & {
62
- id: Exclude<T['id'], undefined>;
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
- import { _createPromiseDecorator } from './decorators/createPromiseDecorator';
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
- import { ErrorMode } from './error/errorMode';
22
+ export * from './error/errorMode';
21
23
  export * from './error/http.error';
22
24
  export * from './error/try';
23
- import { _TryCatch, _tryCatch } from './error/tryCatch';
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
- import { jsonSchema, JsonSchemaAnyBuilder } from './json-schema/jsonSchemaBuilder';
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
- import { AggregatedError } from './promise/AggregatedError';
37
- import { pDefer } from './promise/pDefer';
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
- import { pMap } from './promise/pMap';
45
+ export * from './promise/pMap';
42
46
  export * from './promise/pProps';
43
- import { pRetry, pRetryFn } from './promise/pRetry';
47
+ export * from './promise/pRetry';
44
48
  export * from './promise/pState';
45
- import { pTimeout, pTimeoutFn } from './promise/pTimeout';
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
- import { _stringifyAny } from './string/stringifyAny';
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 { 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.109.2",
3
+ "version": "14.110.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
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
- import type { PromiseDecoratorCfg, PromiseDecoratorResp } from './decorators/createPromiseDecorator'
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
- import type { MemoCache, AsyncMemoCache } from './decorators/memo.util'
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
- import type {
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
- import { ErrorMode } from './error/errorMode'
22
+ export * from './error/errorMode'
31
23
  export * from './error/http.error'
32
24
  export * from './error/try'
33
- import type { TryCatchOptions } from './error/tryCatch'
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
- import type {
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
- import type { JsonSchemaBuilder } from './json-schema/jsonSchemaBuilder'
58
- import { jsonSchema, JsonSchemaAnyBuilder } from './json-schema/jsonSchemaBuilder'
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
- import { AggregatedError } from './promise/AggregatedError'
68
- import type { DeferredPromise } from './promise/pDefer'
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
- import type { PMapOptions } from './promise/pMap'
74
- import { pMap } from './promise/pMap'
45
+ export * from './promise/pMap'
75
46
  export * from './promise/pProps'
76
- import type { PRetryOptions } from './promise/pRetry'
77
- import { pRetry, pRetryFn } from './promise/pRetry'
47
+ export * from './promise/pRetry'
78
48
  export * from './promise/pState'
79
- import type { PTimeoutOptions } from './promise/pTimeout'
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
- import type { JsonStringifyFunction, StringifyAnyOptions } from './string/stringifyAny'
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
- import type {
165
- LocalDateConfig,
166
- LocalDateFormatter,
167
- LocalDateUnit,
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 }
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> = Pick<
39
- ObjectType,
40
- Exclude<keyof ObjectType, KeysType>
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
- type Merge_<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> &
103
- SecondType
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<FirstType, SecondType> = Simplify<Merge_<FirstType, SecondType>>
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 { Except, Merge, Promisable } from './typeFest'
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>> = Merge<
75
- T,
76
- SavedDBEntity<Exclude<T['id'], undefined>>
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>> = Merge<
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>> = Except<T, 'id'> & {
85
- id: Exclude<T['id'], undefined>
72
+ export type UnsavedId<T extends Partial<ObjectWithId>> = Omit<T, 'id'> & {
73
+ id?: T['id']
86
74
  }
87
75
 
88
76
  /**