@naturalcycles/js-lib 14.98.0 → 14.98.3
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/datetime/localDate.d.ts +5 -1
- package/dist/datetime/localDate.js +6 -0
- package/dist/datetime/localTime.d.ts +1 -1
- package/dist/datetime/localTime.js +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/types.d.ts +30 -27
- package/dist-esm/datetime/localDate.js +6 -0
- package/dist-esm/datetime/localTime.js +3 -2
- package/package.json +2 -2
- package/src/datetime/localDate.ts +8 -1
- package/src/datetime/localTime.ts +3 -2
- package/src/index.ts +2 -0
- package/src/promise/pRetry.ts +2 -2
- package/src/types.ts +44 -32
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IsoDateString, UnixTimestampNumber } from '../types';
|
|
1
|
+
import { IsoDateString, IsoDateTimeString, UnixTimestampNumber } from '../types';
|
|
2
2
|
import { LocalTime } from './localTime';
|
|
3
3
|
export declare type LocalDateUnit = 'year' | 'month' | 'day';
|
|
4
4
|
export declare type Inclusiveness = '()' | '[]' | '[)' | '(]';
|
|
@@ -80,6 +80,10 @@ export declare class LocalDate {
|
|
|
80
80
|
toDate(): Date;
|
|
81
81
|
toLocalTime(): LocalTime;
|
|
82
82
|
toISODate(): IsoDateString;
|
|
83
|
+
/**
|
|
84
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
85
|
+
*/
|
|
86
|
+
toISODateTime(): IsoDateTimeString;
|
|
83
87
|
toString(): IsoDateString;
|
|
84
88
|
toStringCompact(): string;
|
|
85
89
|
unix(): UnixTimestampNumber;
|
|
@@ -334,6 +334,12 @@ class LocalDate {
|
|
|
334
334
|
toISODate() {
|
|
335
335
|
return this.toString();
|
|
336
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
339
|
+
*/
|
|
340
|
+
toISODateTime() {
|
|
341
|
+
return this.toString() + 'T00:00:00';
|
|
342
|
+
}
|
|
337
343
|
toString() {
|
|
338
344
|
return [
|
|
339
345
|
String(this.$year).padStart(4, '0'),
|
|
@@ -83,7 +83,7 @@ export declare class LocalTime {
|
|
|
83
83
|
toLocalDate(): LocalDate;
|
|
84
84
|
toPretty(seconds?: boolean): IsoDateTimeString;
|
|
85
85
|
/**
|
|
86
|
-
* Returns e.g: `1984-06-21T17:56:21
|
|
86
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
87
87
|
*/
|
|
88
88
|
toISODateTime(): IsoDateTimeString;
|
|
89
89
|
/**
|
|
@@ -219,8 +219,9 @@ class LocalTime {
|
|
|
219
219
|
if (unit === 'second')
|
|
220
220
|
return this;
|
|
221
221
|
const d = mutate ? this.$date : new Date(this.$date);
|
|
222
|
+
d.setMilliseconds(0);
|
|
223
|
+
d.setSeconds(0);
|
|
222
224
|
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
223
|
-
this.utcMode ? d.setUTCSeconds(0) : d.setSeconds(0);
|
|
224
225
|
if (unit !== 'minute') {
|
|
225
226
|
this.utcMode ? d.setUTCMinutes(0) : d.setMinutes(0);
|
|
226
227
|
if (unit !== 'hour') {
|
|
@@ -371,7 +372,7 @@ class LocalTime {
|
|
|
371
372
|
// .join(' ')
|
|
372
373
|
}
|
|
373
374
|
/**
|
|
374
|
-
* Returns e.g: `1984-06-21T17:56:21
|
|
375
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
375
376
|
*/
|
|
376
377
|
toISODateTime() {
|
|
377
378
|
return this.$date.toISOString().slice(0, 19);
|
package/dist/index.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export * from './string/string.util';
|
|
|
51
51
|
import { JsonStringifyFunction, StringifyAnyOptions, _stringifyAny } from './string/stringifyAny';
|
|
52
52
|
export * from './time/time.util';
|
|
53
53
|
import { Class, ConditionalExcept, ConditionalPick, Merge, Promisable, ReadonlyDeep, Simplify } from './typeFest';
|
|
54
|
-
import { AsyncMapper, AsyncPredicate, BaseDBEntity, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, Saved, Unsaved, BatchResult, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, KeyValueTuple, Mapper, ObjectMapper, ObjectPredicate, Predicate, PromiseMap, AnyObject, AnyFunction, Reviver, SavedDBEntity, StringMap, UnixTimestampNumber, UnixTimestamp, Integer, ValueOf, ValuesOf, AbortableMapper, AbortableAsyncPredicate, AbortableAsyncMapper, AbortablePredicate, END, SKIP, _noop, _objectKeys, _passNothingPredicate, _passthroughMapper, _passthroughPredicate, _passUndefinedMapper, _stringMapEntries, _stringMapValues } from './types';
|
|
54
|
+
import { AsyncMapper, AsyncPredicate, BaseDBEntity, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, Saved, Unsaved, UnsavedId, BatchResult, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, KeyValueTuple, Mapper, ObjectMapper, ObjectPredicate, Predicate, PromiseMap, AnyObject, AnyFunction, Reviver, SavedDBEntity, StringMap, UnixTimestampNumber, UnixTimestamp, Integer, ValueOf, ValuesOf, AbortableMapper, AbortableAsyncPredicate, AbortableAsyncMapper, AbortablePredicate, END, SKIP, _noop, _objectKeys, _passNothingPredicate, _passthroughMapper, _passthroughPredicate, _passUndefinedMapper, _stringMapEntries, _stringMapValues } from './types';
|
|
55
55
|
export * from './unit/size.util';
|
|
56
56
|
import { is } from './vendor/is';
|
|
57
57
|
import { CommonLogLevel, CommonLogFunction, CommonLogger, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, CommonLogWithLevelFunction, commonLoggerCreate } from './log/commonLogger';
|
|
@@ -68,5 +68,5 @@ import { LocalDateConfig, LocalDateUnit, Inclusiveness } from './datetime/localD
|
|
|
68
68
|
import { LocalTimeConfig, LocalTimeUnit, LocalTimeComponents } from './datetime/localTime';
|
|
69
69
|
import { DateIntervalConfig, DateIntervalString } from './datetime/dateInterval';
|
|
70
70
|
import { TimeIntervalConfig, TimeIntervalString } from './datetime/timeInterval';
|
|
71
|
-
export type { DateIntervalConfig, DateIntervalString, TimeIntervalConfig, TimeIntervalString, LocalDateConfig, LocalDateUnit, Inclusiveness, LocalTimeConfig, LocalTimeUnit, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestampNumber, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
|
|
71
|
+
export type { DateIntervalConfig, DateIntervalString, TimeIntervalConfig, TimeIntervalString, LocalDateConfig, LocalDateUnit, Inclusiveness, LocalTimeConfig, LocalTimeUnit, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateString, IsoDateTimeString, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestampNumber, 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, };
|
|
72
72
|
export { is, _createPromiseDecorator, _stringMapValues, _stringMapEntries, _objectKeys, pMap, _passthroughMapper, _passUndefinedMapper, _passthroughPredicate, _passNothingPredicate, _noop, ErrorMode, pDefer, AggregatedError, pRetry, pRetryFn, pTimeout, pTimeoutFn, _tryCatch, _TryCatch, _stringifyAny, jsonSchema, JsonSchemaAnyBuilder, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, commonLoggerCreate, PQueue, END, SKIP, };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Merge, Promisable } from './typeFest';
|
|
1
|
+
import { Except, Merge, Promisable } from './typeFest';
|
|
2
2
|
/**
|
|
3
3
|
* Map from String to String (or <T>).
|
|
4
4
|
*
|
|
@@ -24,14 +24,40 @@ export interface CreatedUpdated {
|
|
|
24
24
|
created: number;
|
|
25
25
|
updated: number;
|
|
26
26
|
}
|
|
27
|
-
export interface CreatedUpdatedId<ID extends string | number = string> extends CreatedUpdated {
|
|
27
|
+
export interface CreatedUpdatedId<ID extends string | number = string | number> extends CreatedUpdated {
|
|
28
28
|
id: ID;
|
|
29
29
|
}
|
|
30
|
-
export interface ObjectWithId<ID extends string | number = string> {
|
|
30
|
+
export interface ObjectWithId<ID extends string | number = string | number> {
|
|
31
31
|
id: ID;
|
|
32
32
|
}
|
|
33
|
-
export interface AnyObjectWithId<ID extends string | number = string> extends AnyObject, ObjectWithId<ID> {
|
|
33
|
+
export interface AnyObjectWithId<ID extends string | number = string | number> extends AnyObject, ObjectWithId<ID> {
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Base interface for any Entity that was saved to DB.
|
|
37
|
+
*/
|
|
38
|
+
export interface SavedDBEntity<ID extends string | number = string> {
|
|
39
|
+
id: ID;
|
|
40
|
+
/**
|
|
41
|
+
* unixTimestamp of when the entity was first created (in the DB).
|
|
42
|
+
*/
|
|
43
|
+
created: UnixTimestampNumber;
|
|
44
|
+
/**
|
|
45
|
+
* unixTimestamp of when the entity was last updated (in the DB).
|
|
46
|
+
*/
|
|
47
|
+
updated: UnixTimestampNumber;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Base interface for any Entity that can be saved to DB.
|
|
51
|
+
* This interface fits when entity was NOT YET saved to DB,
|
|
52
|
+
* hence `id`, `created` and `updated` fields CAN BE undefined (yet).
|
|
53
|
+
* When it's known to be saved - `SavedDBEntity` interface can be used instead.
|
|
54
|
+
*/
|
|
55
|
+
export declare type BaseDBEntity<ID extends string | number = string> = Partial<SavedDBEntity<ID>>;
|
|
56
|
+
export declare type Saved<T extends Partial<ObjectWithId>> = Merge<T, SavedDBEntity<Exclude<T['id'], undefined>>>;
|
|
57
|
+
export declare type Unsaved<T extends Partial<ObjectWithId>> = Merge<T, BaseDBEntity<Exclude<T['id'], undefined>>>;
|
|
58
|
+
export declare type UnsavedId<T extends Partial<ObjectWithId>> = Except<T, 'id'> & {
|
|
59
|
+
id: Exclude<T['id'], undefined>;
|
|
60
|
+
};
|
|
35
61
|
/**
|
|
36
62
|
* Convenience type shorthand.
|
|
37
63
|
* Because `Function` type is discouraged by eslint.
|
|
@@ -136,29 +162,6 @@ export declare type UnixTimestamp = number;
|
|
|
136
162
|
* Same as `number`, but with semantic meaning that it's an Integer.
|
|
137
163
|
*/
|
|
138
164
|
export declare type Integer = number;
|
|
139
|
-
/**
|
|
140
|
-
* Base interface for any Entity that was saved to DB.
|
|
141
|
-
*/
|
|
142
|
-
export interface SavedDBEntity<ID extends string | number = string> {
|
|
143
|
-
id: ID;
|
|
144
|
-
/**
|
|
145
|
-
* unixTimestamp of when the entity was first created (in the DB).
|
|
146
|
-
*/
|
|
147
|
-
created: UnixTimestampNumber;
|
|
148
|
-
/**
|
|
149
|
-
* unixTimestamp of when the entity was last updated (in the DB).
|
|
150
|
-
*/
|
|
151
|
-
updated: UnixTimestampNumber;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Base interface for any Entity that can be saved to DB.
|
|
155
|
-
* This interface fits when entity was NOT YET saved to DB,
|
|
156
|
-
* hence `id`, `created` and `updated` fields CAN BE undefined (yet).
|
|
157
|
-
* When it's known to be saved - `SavedDBEntity` interface can be used instead.
|
|
158
|
-
*/
|
|
159
|
-
export declare type BaseDBEntity<ID extends string | number = string> = Partial<SavedDBEntity<ID>>;
|
|
160
|
-
export declare type Saved<E, ID extends string | number = string> = Merge<E, SavedDBEntity<ID>>;
|
|
161
|
-
export declare type Unsaved<E, ID extends string | number = string> = Merge<E, BaseDBEntity<ID>>;
|
|
162
165
|
/**
|
|
163
166
|
* Named type for JSON.parse / JSON.stringify second argument
|
|
164
167
|
*/
|
|
@@ -331,6 +331,12 @@ export class LocalDate {
|
|
|
331
331
|
toISODate() {
|
|
332
332
|
return this.toString();
|
|
333
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
336
|
+
*/
|
|
337
|
+
toISODateTime() {
|
|
338
|
+
return this.toString() + 'T00:00:00';
|
|
339
|
+
}
|
|
334
340
|
toString() {
|
|
335
341
|
return [
|
|
336
342
|
String(this.$year).padStart(4, '0'),
|
|
@@ -216,8 +216,9 @@ export class LocalTime {
|
|
|
216
216
|
if (unit === 'second')
|
|
217
217
|
return this;
|
|
218
218
|
const d = mutate ? this.$date : new Date(this.$date);
|
|
219
|
+
d.setMilliseconds(0);
|
|
220
|
+
d.setSeconds(0);
|
|
219
221
|
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
220
|
-
this.utcMode ? d.setUTCSeconds(0) : d.setSeconds(0);
|
|
221
222
|
if (unit !== 'minute') {
|
|
222
223
|
this.utcMode ? d.setUTCMinutes(0) : d.setMinutes(0);
|
|
223
224
|
if (unit !== 'hour') {
|
|
@@ -368,7 +369,7 @@ export class LocalTime {
|
|
|
368
369
|
// .join(' ')
|
|
369
370
|
}
|
|
370
371
|
/**
|
|
371
|
-
* Returns e.g: `1984-06-21T17:56:21
|
|
372
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
372
373
|
*/
|
|
373
374
|
toISODateTime() {
|
|
374
375
|
return this.$date.toISOString().slice(0, 19);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.98.
|
|
3
|
+
"version": "14.98.3",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"build-prod": "build-prod-esm-cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@naturalcycles/nodejs-lib": "^12.33.4",
|
|
17
17
|
"@naturalcycles/time-lib": "^3.5.1",
|
|
18
18
|
"@types/node": "^17.0.4",
|
|
19
|
-
"jest": "^
|
|
19
|
+
"jest": "^28.0.3",
|
|
20
20
|
"patch-package": "^6.2.1",
|
|
21
21
|
"prettier": "^2.1.2",
|
|
22
22
|
"rxjs": "^7.0.1",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _assert } from '../error/assert'
|
|
2
|
-
import { IsoDateString, UnixTimestampNumber } from '../types'
|
|
2
|
+
import { IsoDateString, IsoDateTimeString, UnixTimestampNumber } from '../types'
|
|
3
3
|
import { LocalTime } from './localTime'
|
|
4
4
|
|
|
5
5
|
export type LocalDateUnit = 'year' | 'month' | 'day'
|
|
@@ -400,6 +400,13 @@ export class LocalDate {
|
|
|
400
400
|
return this.toString()
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
+
/**
|
|
404
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
405
|
+
*/
|
|
406
|
+
toISODateTime(): IsoDateTimeString {
|
|
407
|
+
return this.toString() + 'T00:00:00'
|
|
408
|
+
}
|
|
409
|
+
|
|
403
410
|
toString(): IsoDateString {
|
|
404
411
|
return [
|
|
405
412
|
String(this.$year).padStart(4, '0'),
|
|
@@ -267,9 +267,10 @@ export class LocalTime {
|
|
|
267
267
|
if (unit === 'second') return this
|
|
268
268
|
|
|
269
269
|
const d = mutate ? this.$date : new Date(this.$date)
|
|
270
|
+
d.setMilliseconds(0)
|
|
271
|
+
d.setSeconds(0)
|
|
270
272
|
|
|
271
273
|
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
272
|
-
this.utcMode ? d.setUTCSeconds(0) : d.setSeconds(0)
|
|
273
274
|
if (unit !== 'minute') {
|
|
274
275
|
this.utcMode ? d.setUTCMinutes(0) : d.setMinutes(0)
|
|
275
276
|
if (unit !== 'hour') {
|
|
@@ -458,7 +459,7 @@ export class LocalTime {
|
|
|
458
459
|
}
|
|
459
460
|
|
|
460
461
|
/**
|
|
461
|
-
* Returns e.g: `1984-06-21T17:56:21
|
|
462
|
+
* Returns e.g: `1984-06-21T17:56:21`
|
|
462
463
|
*/
|
|
463
464
|
toISODateTime(): IsoDateTimeString {
|
|
464
465
|
return this.$date.toISOString().slice(0, 19)
|
package/src/index.ts
CHANGED
|
@@ -102,6 +102,7 @@ import {
|
|
|
102
102
|
AnyObjectWithId,
|
|
103
103
|
Saved,
|
|
104
104
|
Unsaved,
|
|
105
|
+
UnsavedId,
|
|
105
106
|
BatchResult,
|
|
106
107
|
InstanceId,
|
|
107
108
|
IsoDate,
|
|
@@ -232,6 +233,7 @@ export type {
|
|
|
232
233
|
SavedDBEntity,
|
|
233
234
|
Saved,
|
|
234
235
|
Unsaved,
|
|
236
|
+
UnsavedId,
|
|
235
237
|
CreatedUpdated,
|
|
236
238
|
CreatedUpdatedId,
|
|
237
239
|
ObjectWithId,
|
package/src/promise/pRetry.ts
CHANGED
|
@@ -169,7 +169,7 @@ export async function pRetry<T>(
|
|
|
169
169
|
|
|
170
170
|
const r = await fn(attempt)
|
|
171
171
|
|
|
172
|
-
clearTimeout(timer
|
|
172
|
+
clearTimeout(timer)
|
|
173
173
|
|
|
174
174
|
if (logSuccess) {
|
|
175
175
|
logger.log(`${fname} attempt #${attempt} succeeded in ${_since(started)}`)
|
|
@@ -177,7 +177,7 @@ export async function pRetry<T>(
|
|
|
177
177
|
|
|
178
178
|
resolve(r)
|
|
179
179
|
} catch (err) {
|
|
180
|
-
clearTimeout(timer
|
|
180
|
+
clearTimeout(timer)
|
|
181
181
|
|
|
182
182
|
if (logFailures) {
|
|
183
183
|
logger.warn(
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Merge, Promisable } from './typeFest'
|
|
1
|
+
import { Except, Merge, Promisable } from './typeFest'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Map from String to String (or <T>).
|
|
@@ -29,18 +29,58 @@ export interface CreatedUpdated {
|
|
|
29
29
|
updated: number
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export interface CreatedUpdatedId<ID extends string | number = string
|
|
32
|
+
export interface CreatedUpdatedId<ID extends string | number = string | number>
|
|
33
|
+
extends CreatedUpdated {
|
|
33
34
|
id: ID
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export interface ObjectWithId<ID extends string | number = string> {
|
|
37
|
+
export interface ObjectWithId<ID extends string | number = string | number> {
|
|
37
38
|
id: ID
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export interface AnyObjectWithId<ID extends string | number = string>
|
|
41
|
+
export interface AnyObjectWithId<ID extends string | number = string | number>
|
|
41
42
|
extends AnyObject,
|
|
42
43
|
ObjectWithId<ID> {}
|
|
43
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Base interface for any Entity that was saved to DB.
|
|
47
|
+
*/
|
|
48
|
+
export interface SavedDBEntity<ID extends string | number = string> {
|
|
49
|
+
id: ID
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* unixTimestamp of when the entity was first created (in the DB).
|
|
53
|
+
*/
|
|
54
|
+
created: UnixTimestampNumber
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* unixTimestamp of when the entity was last updated (in the DB).
|
|
58
|
+
*/
|
|
59
|
+
updated: UnixTimestampNumber
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Base interface for any Entity that can be saved to DB.
|
|
64
|
+
* This interface fits when entity was NOT YET saved to DB,
|
|
65
|
+
* hence `id`, `created` and `updated` fields CAN BE undefined (yet).
|
|
66
|
+
* When it's known to be saved - `SavedDBEntity` interface can be used instead.
|
|
67
|
+
*/
|
|
68
|
+
export type BaseDBEntity<ID extends string | number = string> = Partial<SavedDBEntity<ID>>
|
|
69
|
+
|
|
70
|
+
export type Saved<T extends Partial<ObjectWithId>> = Merge<
|
|
71
|
+
T,
|
|
72
|
+
SavedDBEntity<Exclude<T['id'], undefined>>
|
|
73
|
+
>
|
|
74
|
+
|
|
75
|
+
export type Unsaved<T extends Partial<ObjectWithId>> = Merge<
|
|
76
|
+
T,
|
|
77
|
+
BaseDBEntity<Exclude<T['id'], undefined>>
|
|
78
|
+
>
|
|
79
|
+
|
|
80
|
+
export type UnsavedId<T extends Partial<ObjectWithId>> = Except<T, 'id'> & {
|
|
81
|
+
id: Exclude<T['id'], undefined>
|
|
82
|
+
}
|
|
83
|
+
|
|
44
84
|
/**
|
|
45
85
|
* Convenience type shorthand.
|
|
46
86
|
* Because `Function` type is discouraged by eslint.
|
|
@@ -183,34 +223,6 @@ export type UnixTimestamp = number
|
|
|
183
223
|
*/
|
|
184
224
|
export type Integer = number
|
|
185
225
|
|
|
186
|
-
/**
|
|
187
|
-
* Base interface for any Entity that was saved to DB.
|
|
188
|
-
*/
|
|
189
|
-
export interface SavedDBEntity<ID extends string | number = string> {
|
|
190
|
-
id: ID
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* unixTimestamp of when the entity was first created (in the DB).
|
|
194
|
-
*/
|
|
195
|
-
created: UnixTimestampNumber
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* unixTimestamp of when the entity was last updated (in the DB).
|
|
199
|
-
*/
|
|
200
|
-
updated: UnixTimestampNumber
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Base interface for any Entity that can be saved to DB.
|
|
205
|
-
* This interface fits when entity was NOT YET saved to DB,
|
|
206
|
-
* hence `id`, `created` and `updated` fields CAN BE undefined (yet).
|
|
207
|
-
* When it's known to be saved - `SavedDBEntity` interface can be used instead.
|
|
208
|
-
*/
|
|
209
|
-
export type BaseDBEntity<ID extends string | number = string> = Partial<SavedDBEntity<ID>>
|
|
210
|
-
|
|
211
|
-
export type Saved<E, ID extends string | number = string> = Merge<E, SavedDBEntity<ID>>
|
|
212
|
-
export type Unsaved<E, ID extends string | number = string> = Merge<E, BaseDBEntity<ID>>
|
|
213
|
-
|
|
214
226
|
/**
|
|
215
227
|
* Named type for JSON.parse / JSON.stringify second argument
|
|
216
228
|
*/
|