@naturalcycles/js-lib 14.98.0 → 14.98.1

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/types.d.ts CHANGED
@@ -24,14 +24,37 @@ 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 ObjectWithId> = Merge<T, BaseDBEntity<T['id']>>;
35
58
  /**
36
59
  * Convenience type shorthand.
37
60
  * Because `Function` type is discouraged by eslint.
@@ -136,29 +159,6 @@ export declare type UnixTimestamp = number;
136
159
  * Same as `number`, but with semantic meaning that it's an Integer.
137
160
  */
138
161
  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
162
  /**
163
163
  * Named type for JSON.parse / JSON.stringify second argument
164
164
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.98.0",
3
+ "version": "14.98.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
package/src/types.ts CHANGED
@@ -29,18 +29,51 @@ export interface CreatedUpdated {
29
29
  updated: number
30
30
  }
31
31
 
32
- export interface CreatedUpdatedId<ID extends string | number = string> extends CreatedUpdated {
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 ObjectWithId> = Merge<T, BaseDBEntity<T['id']>>
76
+
44
77
  /**
45
78
  * Convenience type shorthand.
46
79
  * Because `Function` type is discouraged by eslint.
@@ -183,34 +216,6 @@ export type UnixTimestamp = number
183
216
  */
184
217
  export type Integer = number
185
218
 
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
219
  /**
215
220
  * Named type for JSON.parse / JSON.stringify second argument
216
221
  */