@naturalcycles/db-lib 9.4.1 → 9.5.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/src/db.model.ts CHANGED
@@ -112,7 +112,6 @@ export enum DBRelation {
112
112
  export enum DBModelType {
113
113
  DBM = 'DBM',
114
114
  BM = 'BM',
115
- TM = 'TM',
116
115
  }
117
116
 
118
117
  /**
@@ -10,7 +10,6 @@ import {
10
10
  localTime,
11
11
  JsonSchemaObject,
12
12
  BaseDBEntity,
13
- Saved,
14
13
  } from '@naturalcycles/js-lib'
15
14
  import {
16
15
  NDJsonStats,
@@ -217,7 +216,7 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
217
216
  }),
218
217
  transformLimit({ limit }),
219
218
  ...(sinceUpdated
220
- ? [transformFilterSync<Saved<BaseDBEntity>>(r => r.updated >= sinceUpdated)]
219
+ ? [transformFilterSync<BaseDBEntity>(r => r.updated >= sinceUpdated)]
221
220
  : []),
222
221
  transformMap(mapperPerTable[table] || _passthroughMapper, {
223
222
  errorMode,
@@ -1,8 +1,6 @@
1
1
  import {
2
2
  AsyncMapper,
3
3
  _truncate,
4
- Saved,
5
- AnyObject,
6
4
  _objectAssign,
7
5
  BaseDBEntity,
8
6
  ObjectWithId,
@@ -239,19 +237,18 @@ export class DBQuery<ROW extends ObjectWithId> {
239
237
  export class RunnableDBQuery<
240
238
  BM extends BaseDBEntity,
241
239
  DBM extends BaseDBEntity = BM,
242
- TM extends AnyObject = BM,
243
240
  > extends DBQuery<DBM> {
244
241
  /**
245
242
  * Pass `table` to override table.
246
243
  */
247
244
  constructor(
248
- public dao: CommonDao<BM, DBM, TM>,
245
+ public dao: CommonDao<BM, DBM>,
249
246
  table?: string,
250
247
  ) {
251
248
  super(table || dao.cfg.table)
252
249
  }
253
250
 
254
- async runQuery(opt?: CommonDaoOptions): Promise<Saved<BM>[]> {
251
+ async runQuery(opt?: CommonDaoOptions): Promise<BM[]> {
255
252
  return await this.dao.runQuery(this, opt)
256
253
  }
257
254
 
@@ -259,26 +256,18 @@ export class RunnableDBQuery<
259
256
  return await this.dao.runQuerySingleColumn<T>(this, opt)
260
257
  }
261
258
 
262
- async runQueryAsDBM(opt?: CommonDaoOptions): Promise<Saved<DBM>[]> {
259
+ async runQueryAsDBM(opt?: CommonDaoOptions): Promise<DBM[]> {
263
260
  return await this.dao.runQueryAsDBM(this, opt)
264
261
  }
265
262
 
266
- async runQueryAsTM(opt?: CommonDaoOptions): Promise<TM[]> {
267
- return await this.dao.runQueryAsTM(this, opt)
268
- }
269
-
270
- async runQueryExtended(opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<BM>>> {
263
+ async runQueryExtended(opt?: CommonDaoOptions): Promise<RunQueryResult<BM>> {
271
264
  return await this.dao.runQueryExtended(this, opt)
272
265
  }
273
266
 
274
- async runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<DBM>>> {
267
+ async runQueryExtendedAsDBM(opt?: CommonDaoOptions): Promise<RunQueryResult<DBM>> {
275
268
  return await this.dao.runQueryExtendedAsDBM(this, opt)
276
269
  }
277
270
 
278
- async runQueryExtendedAsTM(opt?: CommonDaoOptions): Promise<RunQueryResult<TM>> {
279
- return await this.dao.runQueryExtendedAsTM(this, opt)
280
- }
281
-
282
271
  async runQueryCount(opt?: CommonDaoOptions): Promise<number> {
283
272
  return await this.dao.runQueryCount(this, opt)
284
273
  }
@@ -288,24 +277,24 @@ export class RunnableDBQuery<
288
277
  }
289
278
 
290
279
  async streamQueryForEach(
291
- mapper: AsyncMapper<Saved<BM>, void>,
292
- opt?: CommonDaoStreamForEachOptions<Saved<BM>>,
280
+ mapper: AsyncMapper<BM, void>,
281
+ opt?: CommonDaoStreamForEachOptions<BM>,
293
282
  ): Promise<void> {
294
283
  await this.dao.streamQueryForEach(this, mapper, opt)
295
284
  }
296
285
 
297
286
  async streamQueryAsDBMForEach(
298
- mapper: AsyncMapper<Saved<DBM>, void>,
287
+ mapper: AsyncMapper<DBM, void>,
299
288
  opt?: CommonDaoStreamForEachOptions<DBM>,
300
289
  ): Promise<void> {
301
290
  await this.dao.streamQueryAsDBMForEach(this, mapper, opt)
302
291
  }
303
292
 
304
- streamQuery(opt?: CommonDaoStreamOptions<Saved<BM>>): ReadableTyped<Saved<BM>> {
293
+ streamQuery(opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM> {
305
294
  return this.dao.streamQuery(this, opt)
306
295
  }
307
296
 
308
- streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<Saved<DBM>> {
297
+ streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM> {
309
298
  return this.dao.streamQueryAsDBM(this, opt)
310
299
  }
311
300
 
@@ -9,7 +9,6 @@ import {
9
9
  createTestItemsBM,
10
10
  testItemBMSchema,
11
11
  testItemDBMSchema,
12
- testItemTMSchema,
13
12
  TEST_TABLE,
14
13
  createTestItemBM,
15
14
  testItemDBMJsonSchema,
@@ -23,7 +22,6 @@ export function runCommonDaoTest(db: CommonDB, quirks: CommonDBImplementationQui
23
22
  db,
24
23
  dbmSchema: testItemDBMSchema,
25
24
  bmSchema: testItemBMSchema,
26
- tmSchema: testItemTMSchema,
27
25
  logStarted: true,
28
26
  logLevel: CommonDaoLogLevel.DATA_FULL,
29
27
  })
@@ -1,4 +1,4 @@
1
- import { jsonSchema, _range, BaseDBEntity, Saved, JsonSchemaObject } from '@naturalcycles/js-lib'
1
+ import { jsonSchema, _range, BaseDBEntity, JsonSchemaObject } from '@naturalcycles/js-lib'
2
2
  import {
3
3
  baseDBEntitySchema,
4
4
  binarySchema,
@@ -50,7 +50,10 @@ export const testItemTMSchema = objectSchema<TestItemTM>({
50
50
 
51
51
  export const testItemBMJsonSchema: JsonSchemaObject<TestItemBM> = jsonSchema
52
52
  .rootObject<TestItemBM>({
53
+ // todo: figure out how to not copy-paste these 3 fields
53
54
  id: jsonSchema.string(), // todo: not strictly needed here
55
+ created: jsonSchema.unixTimestamp(),
56
+ updated: jsonSchema.unixTimestamp(),
54
57
  k1: jsonSchema.string(),
55
58
  k2: jsonSchema.oneOf<string | null>([jsonSchema.string(), jsonSchema.null()]).optional(),
56
59
  k3: jsonSchema.number().optional(),
@@ -74,7 +77,7 @@ export const testItemDBMJsonSchema: JsonSchemaObject<TestItemDBM> = jsonSchema
74
77
  })
75
78
  .build()
76
79
 
77
- export function createTestItemDBM(num = 1): Saved<TestItemDBM> {
80
+ export function createTestItemDBM(num = 1): TestItemDBM {
78
81
  return {
79
82
  id: `id${num}`,
80
83
  k1: `v${num}`,
@@ -86,14 +89,14 @@ export function createTestItemDBM(num = 1): Saved<TestItemDBM> {
86
89
  }
87
90
  }
88
91
 
89
- export function createTestItemBM(num = 1): Saved<TestItemBM> {
92
+ export function createTestItemBM(num = 1): TestItemBM {
90
93
  return createTestItemDBM(num)
91
94
  }
92
95
 
93
- export function createTestItemsDBM(count = 1): Saved<TestItemDBM>[] {
96
+ export function createTestItemsDBM(count = 1): TestItemDBM[] {
94
97
  return _range(1, count + 1).map(num => createTestItemDBM(num))
95
98
  }
96
99
 
97
- export function createTestItemsBM(count = 1): Saved<TestItemBM>[] {
100
+ export function createTestItemsBM(count = 1): TestItemBM[] {
98
101
  return _range(1, count + 1).map(num => createTestItemBM(num))
99
102
  }