@naturalcycles/js-lib 14.109.0 → 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.
Files changed (99) hide show
  1. package/dist/array/array.util.d.ts +2 -2
  2. package/dist/datetime/dateInterval.d.ts +2 -1
  3. package/dist/datetime/localDate.d.ts +1 -1
  4. package/dist/datetime/localTime.d.ts +3 -2
  5. package/dist/datetime/timeInterval.d.ts +4 -3
  6. package/dist/decorators/asyncMemo.decorator.d.ts +2 -2
  7. package/dist/decorators/debounce.d.ts +1 -1
  8. package/dist/decorators/debounce.decorator.d.ts +1 -1
  9. package/dist/decorators/decorator.util.d.ts +1 -1
  10. package/dist/decorators/logMethod.decorator.d.ts +1 -1
  11. package/dist/decorators/memo.decorator.d.ts +2 -2
  12. package/dist/decorators/memo.util.d.ts +1 -1
  13. package/dist/decorators/memoFn.d.ts +2 -2
  14. package/dist/decorators/memoFnAsync.d.ts +2 -2
  15. package/dist/decorators/memoSimple.decorator.d.ts +1 -1
  16. package/dist/decorators/retry.decorator.d.ts +1 -1
  17. package/dist/decorators/timeout.decorator.d.ts +1 -1
  18. package/dist/enum.util.d.ts +1 -1
  19. package/dist/error/app.error.d.ts +1 -1
  20. package/dist/error/assert.d.ts +1 -1
  21. package/dist/error/error.util.d.ts +4 -3
  22. package/dist/error/http.error.d.ts +1 -1
  23. package/dist/error/try.d.ts +1 -1
  24. package/dist/error/tryCatch.d.ts +2 -2
  25. package/dist/index.d.ts +20 -23
  26. package/dist/index.js +20 -26
  27. package/dist/is.util.d.ts +2 -2
  28. package/dist/json-schema/from-data/generateJsonSchemaFromData.d.ts +2 -2
  29. package/dist/json-schema/jsonSchema.cnst.d.ts +1 -1
  30. package/dist/json-schema/jsonSchema.model.d.ts +2 -2
  31. package/dist/json-schema/jsonSchema.util.d.ts +3 -2
  32. package/dist/json-schema/jsonSchemaBuilder.d.ts +2 -2
  33. package/dist/json-schema/jsonSchemas.d.ts +1 -1
  34. package/dist/lazy.d.ts +1 -1
  35. package/dist/object/object.util.d.ts +2 -2
  36. package/dist/object/sortObject.d.ts +1 -1
  37. package/dist/promise/pFilter.d.ts +1 -1
  38. package/dist/promise/pMap.d.ts +2 -1
  39. package/dist/promise/pQueue.d.ts +1 -1
  40. package/dist/promise/pRetry.d.ts +1 -1
  41. package/dist/promise/pTimeout.d.ts +2 -2
  42. package/dist/seq/seq.d.ts +2 -1
  43. package/dist/string/safeJsonStringify.d.ts +1 -1
  44. package/dist/string/stringifyAny.d.ts +1 -1
  45. package/dist/string/url.util.d.ts +1 -1
  46. package/dist/typeFest.d.ts +40 -3
  47. package/dist/types.d.ts +5 -13
  48. package/dist-esm/error/error.util.js +1 -1
  49. package/dist-esm/index.js +20 -12
  50. package/dist-esm/json-schema/from-data/generateJsonSchemaFromData.js +1 -1
  51. package/dist-esm/json-schema/jsonSchemaBuilder.js +1 -1
  52. package/dist-esm/seq/seq.js +1 -1
  53. package/package.json +2 -2
  54. package/src/array/array.util.ts +2 -2
  55. package/src/datetime/dateInterval.ts +2 -1
  56. package/src/datetime/localDate.ts +1 -1
  57. package/src/datetime/localTime.ts +3 -2
  58. package/src/datetime/timeInterval.ts +4 -3
  59. package/src/decorators/asyncMemo.decorator.ts +4 -3
  60. package/src/decorators/debounce.decorator.ts +2 -1
  61. package/src/decorators/debounce.ts +1 -1
  62. package/src/decorators/decorator.util.ts +1 -1
  63. package/src/decorators/logMethod.decorator.ts +2 -1
  64. package/src/decorators/memo.decorator.ts +4 -3
  65. package/src/decorators/memo.util.ts +1 -1
  66. package/src/decorators/memoFn.ts +3 -2
  67. package/src/decorators/memoFnAsync.ts +3 -2
  68. package/src/decorators/memoSimple.decorator.ts +3 -2
  69. package/src/decorators/retry.decorator.ts +2 -1
  70. package/src/decorators/timeout.decorator.ts +2 -1
  71. package/src/enum.util.ts +1 -1
  72. package/src/error/app.error.ts +1 -1
  73. package/src/error/assert.ts +2 -1
  74. package/src/error/error.util.ts +6 -6
  75. package/src/error/http.error.ts +1 -1
  76. package/src/error/try.ts +1 -1
  77. package/src/error/tryCatch.ts +3 -2
  78. package/src/index.ts +20 -244
  79. package/src/is.util.ts +2 -2
  80. package/src/json-schema/from-data/generateJsonSchemaFromData.ts +5 -4
  81. package/src/json-schema/jsonSchema.cnst.ts +1 -1
  82. package/src/json-schema/jsonSchema.model.ts +2 -2
  83. package/src/json-schema/jsonSchema.util.ts +3 -3
  84. package/src/json-schema/jsonSchemaBuilder.ts +3 -5
  85. package/src/json-schema/jsonSchemas.ts +1 -1
  86. package/src/lazy.ts +1 -1
  87. package/src/object/object.util.ts +2 -2
  88. package/src/object/sortObject.ts +2 -1
  89. package/src/promise/pFilter.ts +1 -1
  90. package/src/promise/pMap.ts +2 -1
  91. package/src/promise/pQueue.ts +3 -2
  92. package/src/promise/pRetry.ts +2 -1
  93. package/src/promise/pTimeout.ts +2 -2
  94. package/src/seq/seq.ts +2 -3
  95. package/src/string/safeJsonStringify.ts +1 -1
  96. package/src/string/stringifyAny.ts +1 -1
  97. package/src/string/url.util.ts +1 -1
  98. package/src/typeFest.ts +57 -7
  99. package/src/types.ts +8 -20
package/src/index.ts CHANGED
@@ -2,18 +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 {
6
- PromiseDecoratorCfg,
7
- PromiseDecoratorResp,
8
- _createPromiseDecorator,
9
- } from './decorators/createPromiseDecorator'
5
+ export * from './decorators/createPromiseDecorator'
10
6
  export * from './decorators/debounce'
11
7
  export * from './decorators/debounce.decorator'
12
8
  export * from './decorators/decorator.util'
13
9
  export * from './decorators/logMethod.decorator'
14
10
  export * from './decorators/memo.decorator'
15
11
  export * from './decorators/asyncMemo.decorator'
16
- import { MemoCache, AsyncMemoCache } from './decorators/memo.util'
12
+ export * from './decorators/memo.util'
17
13
  export * from './decorators/memoFn'
18
14
  export * from './decorators/memoFnAsync'
19
15
  export * from './decorators/retry.decorator'
@@ -21,46 +17,18 @@ export * from './decorators/timeout.decorator'
21
17
  export * from './error/app.error'
22
18
  export * from './error/assert'
23
19
  export * from './enum.util'
24
- import {
25
- Admin401ErrorData,
26
- Admin403ErrorData,
27
- ErrorData,
28
- ErrorObject,
29
- HttpErrorData,
30
- HttpErrorResponse,
31
- } from './error/error.model'
20
+ export * from './error/error.model'
32
21
  export * from './error/error.util'
33
- import { ErrorMode } from './error/errorMode'
22
+ export * from './error/errorMode'
34
23
  export * from './error/http.error'
35
24
  export * from './error/try'
36
- import { TryCatchOptions, _TryCatch, _tryCatch } from './error/tryCatch'
25
+ export * from './error/tryCatch'
37
26
  export * from './json-schema/from-data/generateJsonSchemaFromData'
38
27
  export * from './json-schema/jsonSchema.cnst'
39
- import {
40
- JsonSchema,
41
- JsonSchemaAllOf,
42
- JsonSchemaAny,
43
- JsonSchemaAnyOf,
44
- JsonSchemaArray,
45
- JsonSchemaBoolean,
46
- JsonSchemaConst,
47
- JsonSchemaEnum,
48
- JsonSchemaNot,
49
- JsonSchemaNull,
50
- JsonSchemaNumber,
51
- JsonSchemaRootObject,
52
- JsonSchemaObject,
53
- JsonSchemaOneOf,
54
- JsonSchemaRef,
55
- JsonSchemaString,
56
- JsonSchemaTuple,
57
- } from './json-schema/jsonSchema.model'
28
+ export * from './json-schema/jsonSchema.model'
58
29
  export * from './json-schema/jsonSchema.util'
59
- import {
60
- jsonSchema,
61
- JsonSchemaAnyBuilder,
62
- JsonSchemaBuilder,
63
- } from './json-schema/jsonSchemaBuilder'
30
+ export * from './json-schema/jsonSchemaBuilder'
31
+ export * from './json-schema/jsonSchemaBuilder'
64
32
  export * from './math/math.util'
65
33
  export * from './math/sma'
66
34
  export * from './number/createDeterministicRandom'
@@ -69,90 +37,31 @@ export * from './object/deepEquals'
69
37
  export * from './object/object.util'
70
38
  export * from './object/sortObject'
71
39
  export * from './object/sortObjectDeep'
72
- import { AggregatedError } from './promise/AggregatedError'
73
- import { DeferredPromise, pDefer } from './promise/pDefer'
40
+ export * from './promise/AggregatedError'
41
+ export * from './promise/pDefer'
74
42
  export * from './promise/pDelay'
75
43
  export * from './promise/pFilter'
76
44
  export * from './promise/pHang'
77
- import { pMap, PMapOptions } from './promise/pMap'
45
+ export * from './promise/pMap'
78
46
  export * from './promise/pProps'
79
- import { pRetry, pRetryFn, PRetryOptions } from './promise/pRetry'
47
+ export * from './promise/pRetry'
80
48
  export * from './promise/pState'
81
- import { pTimeout, pTimeoutFn, PTimeoutOptions } from './promise/pTimeout'
49
+ export * from './promise/pTimeout'
82
50
  export * from './string/case'
83
51
  export * from './string/json.util'
84
52
  export * from './string/string.util'
85
53
  export * from './string/readingTime'
86
54
  export * from './string/escape'
87
55
  export * from './string/pupa'
88
- import { JsonStringifyFunction, StringifyAnyOptions, _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 {
93
- Class,
94
- ConditionalExcept,
95
- ConditionalPick,
96
- Merge,
97
- Promisable,
98
- ReadonlyDeep,
99
- Simplify,
100
- } from './typeFest'
101
- import {
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 {
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 { 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 {
165
- LocalDateConfig,
166
- LocalDateFormatter,
167
- LocalDateUnit,
168
- LocalDateUnitStrict,
169
- Inclusiveness,
170
- } from './datetime/localDate'
171
- import {
172
- LocalTimeConfig,
173
- LocalTimeFormatter,
174
- LocalTimeUnit,
175
- LocalTimeComponents,
176
- ISODayOfWeek,
177
- } from './datetime/localTime'
178
- import { DateIntervalConfig, DateIntervalString } from './datetime/dateInterval'
179
- import { 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/is.util.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Primitive } from './typeFest'
2
- import { AnyObject, FalsyValue, NullishValue } from './types'
1
+ import type { Primitive } from './typeFest'
2
+ import type { AnyObject, FalsyValue, NullishValue } from './types'
3
3
 
4
4
  type Nullish<T> = T extends NullishValue ? T : never
5
5
  type Truthy<T> = T extends FalsyValue ? never : T
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  JsonSchema,
3
3
  JsonSchemaArray,
4
4
  JsonSchemaBoolean,
@@ -8,10 +8,9 @@ import {
8
8
  JsonSchemaOneOf,
9
9
  JsonSchemaString,
10
10
  StringMap,
11
- _stringMapEntries,
12
- _uniq,
13
11
  AnyObject,
14
12
  } from '../..'
13
+ import { _stringMapEntries, _uniq } from '../..'
15
14
 
16
15
  type PrimitiveType = 'undefined' | 'null' | 'boolean' | 'string' | 'number'
17
16
  type Type = PrimitiveType | 'array' | 'object'
@@ -21,7 +20,9 @@ type Type = PrimitiveType | 'array' | 'object'
21
20
  *
22
21
  * `additionalProperties` is set to `true`, cause it's safer.
23
22
  */
24
- export function generateJsonSchemaFromData<T = unknown>(rows: AnyObject[]): JsonSchemaObject<T> {
23
+ export function generateJsonSchemaFromData<T extends AnyObject = AnyObject>(
24
+ rows: AnyObject[],
25
+ ): JsonSchemaObject<T> {
25
26
  return objectToJsonSchema(rows as any) as JsonSchemaObject<T>
26
27
  }
27
28
 
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  JsonSchema,
3
3
  JsonSchemaAny,
4
4
  JsonSchemaNumber,
@@ -1,4 +1,4 @@
1
- import { AnyObject, StringMap } from '../types'
1
+ import type { AnyObject, StringMap } from '../types'
2
2
 
3
3
  // eslint-disable-next-line unused-imports/no-unused-vars
4
4
  export type JsonSchema<T = unknown> =
@@ -14,7 +14,7 @@ export type JsonSchema<T = unknown> =
14
14
  | JsonSchemaNumber
15
15
  | JsonSchemaBoolean
16
16
  | JsonSchemaNull
17
- | JsonSchemaObject<T>
17
+ | JsonSchemaObject
18
18
  | JsonSchemaArray<T>
19
19
  | JsonSchemaTuple<T>
20
20
 
@@ -1,13 +1,13 @@
1
- import { _uniq } from '../index'
1
+ import { _uniq, AnyObject } from '../index'
2
2
  import { _filterNullishValues } from '../object/object.util'
3
- import { JsonSchemaObject } from './jsonSchema.model'
3
+ import type { JsonSchemaObject } from './jsonSchema.model'
4
4
 
5
5
  /**
6
6
  * Merges s2 into s1 (mutates s1) and returns s1.
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> {
@@ -1,18 +1,16 @@
1
1
  import { _uniq } from '../array/array.util'
2
- import {
2
+ import type {
3
3
  BaseDBEntity,
4
4
  JsonSchemaAllOf,
5
5
  JsonSchemaArray,
6
6
  JsonSchemaOneOf,
7
7
  JsonSchemaTuple,
8
- mergeJsonSchemaObjects,
9
8
  SavedDBEntity,
10
- _deepCopy,
11
- _sortObject,
12
9
  AnyObject,
13
10
  } from '../index'
11
+ import { mergeJsonSchemaObjects, _deepCopy, _sortObject } from '../index'
14
12
  import { JSON_SCHEMA_ORDER } from './jsonSchema.cnst'
15
- import {
13
+ import type {
16
14
  JsonSchema,
17
15
  JsonSchemaAny,
18
16
  JsonSchemaBoolean,
@@ -1,4 +1,4 @@
1
- import { BaseDBEntity, SavedDBEntity } from '../types'
1
+ import type { BaseDBEntity, SavedDBEntity } from '../types'
2
2
  import { jsonSchema } from './jsonSchemaBuilder'
3
3
 
4
4
  export const baseDBEntityJsonSchema = jsonSchema.object<BaseDBEntity>({
package/src/lazy.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyFunction, AnyObject } from './types'
1
+ import type { AnyFunction, AnyObject } from './types'
2
2
 
3
3
  /**
4
4
  * const value = lazyValue(() => expensiveComputation())
@@ -1,6 +1,6 @@
1
1
  import { _isEmpty, _isObject } from '../is.util'
2
- import { PropertyPath } from '../lodash.types'
3
- import { AnyObject, ObjectMapper, ObjectPredicate, StringMap, ValueOf } from '../types'
2
+ import type { PropertyPath } from '../lodash.types'
3
+ import type { AnyObject, ObjectMapper, ObjectPredicate, StringMap, ValueOf } from '../types'
4
4
 
5
5
  /**
6
6
  * Returns clone of `obj` with only `props` preserved.
@@ -1,4 +1,5 @@
1
- import { _omit, AnyObject } from '../index'
1
+ import type { AnyObject } from '../index'
2
+ import { _omit } from '../index'
2
3
 
3
4
  /**
4
5
  * Returns new object with keys sorder in the given order.
@@ -1,4 +1,4 @@
1
- import { AsyncPredicate } from '../types'
1
+ import type { AsyncPredicate } from '../types'
2
2
 
3
3
  export async function pFilter<T>(iterable: Iterable<T>, filterFn: AsyncPredicate<T>): Promise<T[]> {
4
4
  const items = [...iterable]
@@ -7,7 +7,8 @@ Improvements:
7
7
  - Compatible with pProps (that had typings issues)
8
8
  */
9
9
 
10
- import { AbortableAsyncMapper, END, ErrorMode, SKIP } from '..'
10
+ import type { AbortableAsyncMapper } from '..'
11
+ import { END, ErrorMode, SKIP } from '..'
11
12
  import { AggregatedError } from './AggregatedError'
12
13
 
13
14
  export interface PMapOptions {
@@ -1,6 +1,7 @@
1
1
  import { ErrorMode } from '../error/errorMode'
2
- import { CommonLogger } from '../log/commonLogger'
3
- import { DeferredPromise, pDefer } from './pDefer'
2
+ import type { CommonLogger } from '../log/commonLogger'
3
+ import type { DeferredPromise } from './pDefer'
4
+ import { pDefer } from './pDefer'
4
5
 
5
6
  export interface PQueueCfg {
6
7
  concurrency: number
@@ -1,4 +1,5 @@
1
- import { _since, _stringifyAny, AnyFunction, AppError, CommonLogger, ErrorData } from '..'
1
+ import type { AnyFunction, AppError, CommonLogger, ErrorData } from '..'
2
+ import { _since, _stringifyAny } from '..'
2
3
  import { TimeoutError } from './pTimeout'
3
4
 
4
5
  export interface PRetryOptions {
@@ -1,6 +1,6 @@
1
1
  import { AppError } from '../error/app.error'
2
- import { ErrorData } from '../error/error.model'
3
- import { AnyFunction } from '../types'
2
+ import type { ErrorData } from '../error/error.model'
3
+ import type { AnyFunction } from '../types'
4
4
 
5
5
  export class TimeoutError extends AppError {}
6
6
 
package/src/seq/seq.ts CHANGED
@@ -1,11 +1,10 @@
1
- import {
1
+ import type {
2
2
  AbortableAsyncMapper,
3
3
  AbortableAsyncPredicate,
4
4
  AbortableMapper,
5
5
  AbortablePredicate,
6
- END,
7
- SKIP,
8
6
  } from '../types'
7
+ import { END, SKIP } from '../types'
9
8
 
10
9
  /**
11
10
  * Inspired by Kotlin Sequences.
@@ -1,4 +1,4 @@
1
- import { Reviver } from '../types'
1
+ import type { Reviver } from '../types'
2
2
 
3
3
  /**
4
4
  * JSON.stringify that avoids circular references, prints them as [Circular ~]
@@ -1,5 +1,5 @@
1
1
  import { _isErrorObject, _isHttpErrorObject, _isHttpErrorResponse } from '../error/error.util'
2
- import { Reviver } from '../types'
2
+ import type { Reviver } from '../types'
3
3
  import { _jsonParseIfPossible } from './json.util'
4
4
  import { _safeJsonStringify } from './safeJsonStringify'
5
5
 
@@ -1,4 +1,4 @@
1
- import { StringMap } from '../types'
1
+ import type { StringMap } from '../types'
2
2
 
3
3
  /**
4
4
  * Parses `location.search` string (e.g `?a=1&b=2`) into a StringMap, e.g:
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 { 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
  /**