@naturalcycles/db-lib 10.17.0 → 10.17.2

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.
@@ -113,8 +113,12 @@ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity
113
113
  /**
114
114
  * Used by e.g Firestore.
115
115
  */
116
- indexes?: CommonDaoIndex<DBM>[];
117
- ttl?: CommonDaoTTL<DBM>;
116
+ indexes?: CommonDaoIndexDefinition<DBM>[];
117
+ /**
118
+ * Defines the property that is used for TTL (auto-cleanup by the DB,
119
+ * e.g Datastore/Firestore).
120
+ */
121
+ ttl?: keyof DBM;
118
122
  /**
119
123
  * Defaults to true.
120
124
  * If set to false - load (read) operations will skip validation (and conversion).
@@ -182,28 +186,20 @@ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity
182
186
  */
183
187
  patchInTransaction?: boolean;
184
188
  }
189
+ /**
190
+ * Index can be defined in simple form, just as a property name: `abc`
191
+ *
192
+ * or as an object, when non-standard index order(s) are needed.
193
+ */
194
+ export type CommonDaoIndexDefinition<DBM extends BaseDBEntity> = keyof DBM | CommonDaoIndex<DBM>;
185
195
  export interface CommonDaoIndex<DBM extends BaseDBEntity> {
186
196
  /**
187
197
  * Name of the property to index.
188
198
  */
189
199
  name: keyof DBM;
190
- /**
191
- * Defaults to ['asc']
192
- */
193
- order?: CommonDaoIndexOrder[];
200
+ order: CommonDaoIndexOrder[];
194
201
  }
195
202
  export type CommonDaoIndexOrder = 'asc' | 'desc' | 'array-contains';
196
- /**
197
- * TTL definition - a map from Table name to an array of properties that should be used for TTL.
198
- * Example:
199
- *
200
- * {
201
- * myTable: ['deleteAt']
202
- * }
203
- */
204
- export interface CommonDaoTTL<DBM extends BaseDBEntity> {
205
- [table: string]: (keyof DBM)[];
206
- }
207
203
  /**
208
204
  * All properties default to undefined.
209
205
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.17.0",
4
+ "version": "10.17.2",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -139,9 +139,12 @@ export interface CommonDaoCfg<
139
139
  /**
140
140
  * Used by e.g Firestore.
141
141
  */
142
- indexes?: CommonDaoIndex<DBM>[]
143
-
144
- ttl?: CommonDaoTTL<DBM>
142
+ indexes?: CommonDaoIndexDefinition<DBM>[]
143
+ /**
144
+ * Defines the property that is used for TTL (auto-cleanup by the DB,
145
+ * e.g Datastore/Firestore).
146
+ */
147
+ ttl?: keyof DBM
145
148
 
146
149
  /**
147
150
  * Defaults to true.
@@ -224,31 +227,23 @@ export interface CommonDaoCfg<
224
227
  patchInTransaction?: boolean
225
228
  }
226
229
 
230
+ /**
231
+ * Index can be defined in simple form, just as a property name: `abc`
232
+ *
233
+ * or as an object, when non-standard index order(s) are needed.
234
+ */
235
+ export type CommonDaoIndexDefinition<DBM extends BaseDBEntity> = keyof DBM | CommonDaoIndex<DBM>
236
+
227
237
  export interface CommonDaoIndex<DBM extends BaseDBEntity> {
228
238
  /**
229
239
  * Name of the property to index.
230
240
  */
231
241
  name: keyof DBM
232
- /**
233
- * Defaults to ['asc']
234
- */
235
- order?: CommonDaoIndexOrder[]
242
+ order: CommonDaoIndexOrder[]
236
243
  }
237
244
 
238
245
  export type CommonDaoIndexOrder = 'asc' | 'desc' | 'array-contains'
239
246
 
240
- /**
241
- * TTL definition - a map from Table name to an array of properties that should be used for TTL.
242
- * Example:
243
- *
244
- * {
245
- * myTable: ['deleteAt']
246
- * }
247
- */
248
- export interface CommonDaoTTL<DBM extends BaseDBEntity> {
249
- [table: string]: (keyof DBM)[]
250
- }
251
-
252
247
  /**
253
248
  * All properties default to undefined.
254
249
  */