@naturalcycles/db-lib 8.50.0 → 8.50.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.
@@ -21,14 +21,14 @@ export declare class CacheDB extends BaseCommonDB implements CommonDB {
21
21
  * Resets InMemory DB data
22
22
  */
23
23
  getTables(): Promise<string[]>;
24
- getTableSchema<ROW extends Partial<ObjectWithId>>(table: string): Promise<JsonSchemaRootObject<ROW>>;
25
- createTable<ROW extends Partial<ObjectWithId>>(table: string, schema: JsonSchemaObject<ROW>, opt?: CacheDBCreateOptions): Promise<void>;
26
- getByIds<ROW extends Partial<ObjectWithId>>(table: string, ids: ROW['id'][], opt?: CacheDBSaveOptions<ROW>): Promise<ROW[]>;
24
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
25
+ createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CacheDBCreateOptions): Promise<void>;
26
+ getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], opt?: CacheDBSaveOptions<ROW>): Promise<ROW[]>;
27
27
  saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], opt?: CacheDBSaveOptions<ROW>): Promise<void>;
28
- runQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, opt?: CacheDBSaveOptions<ROW>): Promise<RunQueryResult<ROW>>;
29
- runQueryCount<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
30
- streamQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, opt?: CacheDBStreamOptions): Readable;
31
- deleteByQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
32
- updateByQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CacheDBOptions): Promise<number>;
28
+ runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBSaveOptions<ROW>): Promise<RunQueryResult<ROW>>;
29
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
30
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBStreamOptions): Readable;
31
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
32
+ updateByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CacheDBOptions): Promise<number>;
33
33
  commitTransaction(tx: DBTransaction, opt?: CommonDBOptions): Promise<void>;
34
34
  }
@@ -11,15 +11,15 @@ import { DBTransaction } from './transaction/dbTransaction';
11
11
  export declare class BaseCommonDB implements CommonDB {
12
12
  ping(): Promise<void>;
13
13
  getTables(): Promise<string[]>;
14
- getTableSchema<ROW extends Partial<ObjectWithId>>(table: string): Promise<JsonSchemaRootObject<ROW>>;
15
- createTable<ROW extends Partial<ObjectWithId>>(table: string, schema: JsonSchemaObject<ROW>): Promise<void>;
16
- getByIds<ROW extends Partial<ObjectWithId>>(table: string, ids: ROW['id'][]): Promise<ROW[]>;
17
- deleteByQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>): Promise<number>;
18
- updateByQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CommonDBOptions): Promise<number>;
19
- runQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>): Promise<RunQueryResult<ROW>>;
20
- runQueryCount<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>): Promise<number>;
14
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
15
+ createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>): Promise<void>;
16
+ getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][]): Promise<ROW[]>;
17
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<number>;
18
+ updateByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CommonDBOptions): Promise<number>;
19
+ runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<RunQueryResult<ROW>>;
20
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<number>;
21
21
  saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
22
- streamQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>): ReadableTyped<ROW>;
22
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): ReadableTyped<ROW>;
23
23
  /**
24
24
  * Naive implementation.
25
25
  * Doesn't support rollback on error, hence doesn't pass dbTest.
@@ -21,23 +21,23 @@ export interface CommonDB {
21
21
  *
22
22
  * This is important for the code to rely on it, and it's verified by dbTest
23
23
  */
24
- getTableSchema<ROW extends Partial<ObjectWithId>>(table: string): Promise<JsonSchemaRootObject<ROW>>;
24
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
25
25
  /**
26
26
  * Will do like `create table ...` for mysql.
27
27
  * Caution! dropIfExists defaults to false. If set to true - will actually DROP the table!
28
28
  */
29
- createTable<ROW extends Partial<ObjectWithId>>(table: string, schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions): Promise<void>;
29
+ createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions): Promise<void>;
30
30
  /**
31
31
  * Order of items returned is not guaranteed to match order of ids.
32
32
  * (Such limitation exists because Datastore doesn't support it).
33
33
  */
34
- getByIds<ROW extends Partial<ObjectWithId>>(table: string, ids: ROW['id'][], opt?: CommonDBOptions): Promise<ROW[]>;
34
+ getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], opt?: CommonDBOptions): Promise<ROW[]>;
35
35
  /**
36
36
  * Order by 'id' is not supported by all implementations (for example, Datastore doesn't support it).
37
37
  */
38
- runQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
39
- runQueryCount<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>;
40
- streamQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
38
+ runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
39
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>;
40
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
41
41
  /**
42
42
  * rows can have missing ids only if DB supports auto-generating them (like mysql auto_increment).
43
43
  */
@@ -46,7 +46,7 @@ export interface CommonDB {
46
46
  * Returns number of deleted items.
47
47
  * Not supported by all implementations (e.g Datastore will always return same number as number of ids).
48
48
  */
49
- deleteByQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>;
49
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>;
50
50
  /**
51
51
  * Applies patch to the rows returned by the query.
52
52
  *
@@ -65,7 +65,7 @@ export interface CommonDB {
65
65
  *
66
66
  * Returns number of rows affected.
67
67
  */
68
- updateByQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CommonDBOptions): Promise<number>;
68
+ updateByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CommonDBOptions): Promise<number>;
69
69
  /**
70
70
  * Should be implemented as a Transaction (best effort), which means that
71
71
  * either ALL or NONE of the operations should be applied.
@@ -9,7 +9,7 @@ import { CommonDaoCfg, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoSaveOp
9
9
  * DBM = Database model (how it's stored in DB)
10
10
  * BM = Backend model (optimized for API access)
11
11
  */
12
- export declare class CommonDao<BM extends Partial<ObjectWithId<ID>>, DBM extends Partial<ObjectWithId<ID>> = BM, ID extends string | number = NonNullable<BM['id']>> {
12
+ export declare class CommonDao<BM extends ObjectWithId<ID>, DBM extends ObjectWithId<ID> = BM, ID extends string | number = BM['id']> {
13
13
  cfg: CommonDaoCfg<BM, DBM, ID>;
14
14
  constructor(cfg: CommonDaoCfg<BM, DBM, ID>);
15
15
  create(part?: Partial<BM>, opt?: CommonDaoOptions): Saved<BM>;
@@ -44,7 +44,7 @@ export declare enum CommonDaoLogLevel {
44
44
  */
45
45
  DATA_FULL = 30
46
46
  }
47
- export interface CommonDaoCfg<BM extends Partial<ObjectWithId<ID>>, DBM extends Partial<ObjectWithId<ID>> = BM, ID extends string | number = NonNullable<BM['id']>> {
47
+ export interface CommonDaoCfg<BM extends ObjectWithId<ID>, DBM extends ObjectWithId<ID> = BM, ID extends string | number = BM['id']> {
48
48
  db: CommonDB;
49
49
  table: string;
50
50
  /**
@@ -84,7 +84,7 @@ export declare class DBQuery<ROW extends Partial<ObjectWithId> = AnyObjectWithId
84
84
  /**
85
85
  * DBQuery that has additional method to support Fluent API style.
86
86
  */
87
- export declare class RunnableDBQuery<BM extends Partial<ObjectWithId<ID>>, DBM extends Partial<ObjectWithId<ID>> = BM, ID extends string | number = NonNullable<BM['id']>> extends DBQuery<DBM> {
87
+ export declare class RunnableDBQuery<BM extends ObjectWithId<ID>, DBM extends ObjectWithId<ID> = BM, ID extends string | number = BM['id']> extends DBQuery<DBM> {
88
88
  dao: CommonDao<BM, DBM, ID>;
89
89
  /**
90
90
  * Pass `table` to override table.
package/package.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "engines": {
42
42
  "node": ">=14.15"
43
43
  },
44
- "version": "8.50.0",
44
+ "version": "8.50.1",
45
45
  "description": "Lowest Common Denominator API to supported Databases",
46
46
  "keywords": [
47
47
  "db",
@@ -53,13 +53,13 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
53
53
  return await this.cfg.downstreamDB.getTables()
54
54
  }
55
55
 
56
- override async getTableSchema<ROW extends Partial<ObjectWithId>>(
56
+ override async getTableSchema<ROW extends ObjectWithId>(
57
57
  table: string,
58
58
  ): Promise<JsonSchemaRootObject<ROW>> {
59
59
  return await this.cfg.downstreamDB.getTableSchema<ROW>(table)
60
60
  }
61
61
 
62
- override async createTable<ROW extends Partial<ObjectWithId>>(
62
+ override async createTable<ROW extends ObjectWithId>(
63
63
  table: string,
64
64
  schema: JsonSchemaObject<ROW>,
65
65
  opt: CacheDBCreateOptions = {},
@@ -73,7 +73,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
73
73
  }
74
74
  }
75
75
 
76
- override async getByIds<ROW extends Partial<ObjectWithId>>(
76
+ override async getByIds<ROW extends ObjectWithId>(
77
77
  table: string,
78
78
  ids: ROW['id'][],
79
79
  opt: CacheDBSaveOptions<ROW> = {},
@@ -84,9 +84,9 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
84
84
  if (!opt.skipCache && !this.cfg.skipCache) {
85
85
  const results = await this.cfg.cacheDB.getByIds<ROW>(table, ids, opt)
86
86
 
87
- results.forEach(r => (resultMap[r.id!] = r))
87
+ results.forEach(r => (resultMap[r.id] = r))
88
88
 
89
- missingIds.push(...ids.filter(id => !resultMap[id!]))
89
+ missingIds.push(...ids.filter(id => !resultMap[id]))
90
90
 
91
91
  if (this.cfg.logCached) {
92
92
  this.cfg.logger?.log(
@@ -99,7 +99,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
99
99
 
100
100
  if (missingIds.length && !opt.onlyCache && !this.cfg.onlyCache) {
101
101
  const results = await this.cfg.downstreamDB.getByIds<ROW>(table, missingIds, opt)
102
- results.forEach(r => (resultMap[r.id!] = r))
102
+ results.forEach(r => (resultMap[r.id] = r))
103
103
 
104
104
  if (this.cfg.logDownstream) {
105
105
  this.cfg.logger?.log(
@@ -116,7 +116,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
116
116
  }
117
117
 
118
118
  // return in right order
119
- return ids.map(id => resultMap[id!]).filter(_isTruthy)
119
+ return ids.map(id => resultMap[id]).filter(_isTruthy)
120
120
  }
121
121
 
122
122
  override async saveBatch<ROW extends Partial<ObjectWithId>>(
@@ -148,7 +148,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
148
148
  }
149
149
  }
150
150
 
151
- override async runQuery<ROW extends Partial<ObjectWithId>>(
151
+ override async runQuery<ROW extends ObjectWithId>(
152
152
  q: DBQuery<ROW>,
153
153
  opt: CacheDBSaveOptions<ROW> = {},
154
154
  ): Promise<RunQueryResult<ROW>> {
@@ -178,7 +178,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
178
178
  return { rows, ...queryResult }
179
179
  }
180
180
 
181
- override async runQueryCount<ROW extends Partial<ObjectWithId>>(
181
+ override async runQueryCount<ROW extends ObjectWithId>(
182
182
  q: DBQuery<ROW>,
183
183
  opt: CacheDBOptions = {},
184
184
  ): Promise<number> {
@@ -195,7 +195,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
195
195
  return count
196
196
  }
197
197
 
198
- override streamQuery<ROW extends Partial<ObjectWithId>>(
198
+ override streamQuery<ROW extends ObjectWithId>(
199
199
  q: DBQuery<ROW>,
200
200
  opt: CacheDBStreamOptions = {},
201
201
  ): Readable {
@@ -234,7 +234,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
234
234
  return stream
235
235
  }
236
236
 
237
- override async deleteByQuery<ROW extends Partial<ObjectWithId>>(
237
+ override async deleteByQuery<ROW extends ObjectWithId>(
238
238
  q: DBQuery<ROW>,
239
239
  opt: CacheDBOptions = {},
240
240
  ): Promise<number> {
@@ -266,7 +266,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
266
266
  return deletedIds
267
267
  }
268
268
 
269
- override async updateByQuery<ROW extends Partial<ObjectWithId>>(
269
+ override async updateByQuery<ROW extends ObjectWithId>(
270
270
  q: DBQuery<ROW>,
271
271
  patch: DBPatch<ROW>,
272
272
  opt: CacheDBOptions = {},
@@ -20,31 +20,28 @@ export class BaseCommonDB implements CommonDB {
20
20
  throw new Error('getTables is not implemented')
21
21
  }
22
22
 
23
- async getTableSchema<ROW extends Partial<ObjectWithId>>(
23
+ async getTableSchema<ROW extends ObjectWithId>(
24
24
  table: string,
25
25
  ): Promise<JsonSchemaRootObject<ROW>> {
26
26
  throw new Error('getTableSchema is not implemented')
27
27
  }
28
28
 
29
- async createTable<ROW extends Partial<ObjectWithId>>(
29
+ async createTable<ROW extends ObjectWithId>(
30
30
  table: string,
31
31
  schema: JsonSchemaObject<ROW>,
32
32
  ): Promise<void> {
33
33
  // no-op
34
34
  }
35
35
 
36
- async getByIds<ROW extends Partial<ObjectWithId>>(
37
- table: string,
38
- ids: ROW['id'][],
39
- ): Promise<ROW[]> {
36
+ async getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][]): Promise<ROW[]> {
40
37
  throw new Error('getByIds is not implemented')
41
38
  }
42
39
 
43
- async deleteByQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>): Promise<number> {
40
+ async deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<number> {
44
41
  throw new Error('deleteByQuery is not implemented')
45
42
  }
46
43
 
47
- async updateByQuery<ROW extends Partial<ObjectWithId>>(
44
+ async updateByQuery<ROW extends ObjectWithId>(
48
45
  q: DBQuery<ROW>,
49
46
  patch: DBPatch<ROW>,
50
47
  opt?: CommonDBOptions,
@@ -52,11 +49,11 @@ export class BaseCommonDB implements CommonDB {
52
49
  throw new Error('updateByQuery is not implemented')
53
50
  }
54
51
 
55
- async runQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>): Promise<RunQueryResult<ROW>> {
52
+ async runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<RunQueryResult<ROW>> {
56
53
  throw new Error('runQuery is not implemented')
57
54
  }
58
55
 
59
- async runQueryCount<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>): Promise<number> {
56
+ async runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<number> {
60
57
  throw new Error('runQueryCount is not implemented')
61
58
  }
62
59
 
@@ -68,7 +65,7 @@ export class BaseCommonDB implements CommonDB {
68
65
  throw new Error('saveBatch is not implemented')
69
66
  }
70
67
 
71
- streamQuery<ROW extends Partial<ObjectWithId>>(q: DBQuery<ROW>): ReadableTyped<ROW> {
68
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): ReadableTyped<ROW> {
72
69
  throw new Error('streamQuery is not implemented')
73
70
  }
74
71
 
package/src/common.db.ts CHANGED
@@ -31,15 +31,13 @@ export interface CommonDB {
31
31
  *
32
32
  * This is important for the code to rely on it, and it's verified by dbTest
33
33
  */
34
- getTableSchema<ROW extends Partial<ObjectWithId>>(
35
- table: string,
36
- ): Promise<JsonSchemaRootObject<ROW>>
34
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>
37
35
 
38
36
  /**
39
37
  * Will do like `create table ...` for mysql.
40
38
  * Caution! dropIfExists defaults to false. If set to true - will actually DROP the table!
41
39
  */
42
- createTable<ROW extends Partial<ObjectWithId>>(
40
+ createTable<ROW extends ObjectWithId>(
43
41
  table: string,
44
42
  schema: JsonSchemaObject<ROW>,
45
43
  opt?: CommonDBCreateOptions,
@@ -50,7 +48,7 @@ export interface CommonDB {
50
48
  * Order of items returned is not guaranteed to match order of ids.
51
49
  * (Such limitation exists because Datastore doesn't support it).
52
50
  */
53
- getByIds<ROW extends Partial<ObjectWithId>>(
51
+ getByIds<ROW extends ObjectWithId>(
54
52
  table: string,
55
53
  ids: ROW['id'][],
56
54
  opt?: CommonDBOptions,
@@ -60,17 +58,14 @@ export interface CommonDB {
60
58
  /**
61
59
  * Order by 'id' is not supported by all implementations (for example, Datastore doesn't support it).
62
60
  */
63
- runQuery<ROW extends Partial<ObjectWithId>>(
61
+ runQuery<ROW extends ObjectWithId>(
64
62
  q: DBQuery<ROW>,
65
63
  opt?: CommonDBOptions,
66
64
  ): Promise<RunQueryResult<ROW>>
67
65
 
68
- runQueryCount<ROW extends Partial<ObjectWithId>>(
69
- q: DBQuery<ROW>,
70
- opt?: CommonDBOptions,
71
- ): Promise<number>
66
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>
72
67
 
73
- streamQuery<ROW extends Partial<ObjectWithId>>(
68
+ streamQuery<ROW extends ObjectWithId>(
74
69
  q: DBQuery<ROW>,
75
70
  opt?: CommonDBStreamOptions,
76
71
  ): ReadableTyped<ROW>
@@ -90,10 +85,7 @@ export interface CommonDB {
90
85
  * Returns number of deleted items.
91
86
  * Not supported by all implementations (e.g Datastore will always return same number as number of ids).
92
87
  */
93
- deleteByQuery<ROW extends Partial<ObjectWithId>>(
94
- q: DBQuery<ROW>,
95
- opt?: CommonDBOptions,
96
- ): Promise<number>
88
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>
97
89
 
98
90
  /**
99
91
  * Applies patch to the rows returned by the query.
@@ -113,7 +105,7 @@ export interface CommonDB {
113
105
  *
114
106
  * Returns number of rows affected.
115
107
  */
116
- updateByQuery<ROW extends Partial<ObjectWithId>>(
108
+ updateByQuery<ROW extends ObjectWithId>(
117
109
  q: DBQuery<ROW>,
118
110
  patch: DBPatch<ROW>,
119
111
  opt?: CommonDBOptions,
@@ -61,9 +61,9 @@ export enum CommonDaoLogLevel {
61
61
  }
62
62
 
63
63
  export interface CommonDaoCfg<
64
- BM extends Partial<ObjectWithId<ID>>,
65
- DBM extends Partial<ObjectWithId<ID>> = BM,
66
- ID extends string | number = NonNullable<BM['id']>,
64
+ BM extends ObjectWithId<ID>,
65
+ DBM extends ObjectWithId<ID> = BM,
66
+ ID extends string | number = BM['id'],
67
67
  > {
68
68
  db: CommonDB
69
69
  table: string
@@ -64,9 +64,9 @@ const isCI = !!process.env['CI']
64
64
  * BM = Backend model (optimized for API access)
65
65
  */
66
66
  export class CommonDao<
67
- BM extends Partial<ObjectWithId<ID>>,
68
- DBM extends Partial<ObjectWithId<ID>> = BM,
69
- ID extends string | number = NonNullable<BM['id']>,
67
+ BM extends ObjectWithId<ID>,
68
+ DBM extends ObjectWithId<ID> = BM,
69
+ ID extends string | number = BM['id'],
70
70
  > {
71
71
  constructor(public cfg: CommonDaoCfg<BM, DBM, ID>) {
72
72
  this.cfg = {
@@ -486,7 +486,7 @@ export class CommonDao<
486
486
  async queryIds(q: DBQuery<DBM>, opt: CommonDaoOptions = {}): Promise<ID[]> {
487
487
  q.table = opt.table || q.table
488
488
  const { rows } = await this.cfg.db.runQuery(q.select(['id']), opt)
489
- return rows.map(r => r.id!)
489
+ return rows.map(r => r.id)
490
490
  }
491
491
 
492
492
  streamQueryIds(q: DBQuery<DBM>, opt: CommonDaoStreamOptions = {}): ReadableTyped<ID> {
@@ -497,7 +497,7 @@ export class CommonDao<
497
497
  .streamQuery<DBM>(q.select(['id']), opt)
498
498
  .on('error', err => stream.emit('error', err))
499
499
  .pipe(
500
- transformMapSimple<DBM, ID>(objectWithId => objectWithId.id!, {
500
+ transformMapSimple<DBM, ID>(objectWithId => objectWithId.id, {
501
501
  errorMode: ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
502
502
  }),
503
503
  )
@@ -519,7 +519,7 @@ export class CommonDao<
519
519
 
520
520
  await _pipeline([
521
521
  this.cfg.db.streamQuery<DBM>(q.select(['id']), opt),
522
- transformMapSimple<DBM, ID>(objectWithId => objectWithId.id!),
522
+ transformMapSimple<DBM, ID>(objectWithId => objectWithId.id),
523
523
  transformTap(() => count++),
524
524
  transformMap<ID, void>(mapper, {
525
525
  ...opt,
@@ -845,7 +845,7 @@ export class CommonDao<
845
845
 
846
846
  await _pipeline([
847
847
  this.cfg.db.streamQuery<DBM>(q.select(['id']), opt),
848
- transformMapSimple<DBM, ID>(objectWithId => objectWithId.id!, {
848
+ transformMapSimple<DBM, ID>(objectWithId => objectWithId.id, {
849
849
  errorMode: ErrorMode.SUPPRESS,
850
850
  }),
851
851
  transformBuffer<string>({ batchSize }),
@@ -909,7 +909,7 @@ export class CommonDao<
909
909
 
910
910
  // optimization: no need to run full joi DBM validation, cause BM validation will be run
911
911
  // const dbm = this.anyToDBM(_dbm, opt)
912
- let dbm: DBM = { ..._dbm, ...this.cfg.hooks!.parseNaturalId!(_dbm.id!) }
912
+ let dbm: DBM = { ..._dbm, ...this.cfg.hooks!.parseNaturalId!(_dbm.id) }
913
913
 
914
914
  if (opt.anonymize) {
915
915
  dbm = this.cfg.hooks!.anonymize!(dbm)
@@ -965,7 +965,7 @@ export class CommonDao<
965
965
  // this shouldn't be happening on load! but should on save!
966
966
  // this.assignIdCreatedUpdated(dbm, opt)
967
967
 
968
- dbm = { ...dbm, ...this.cfg.hooks!.parseNaturalId!(dbm.id!) }
968
+ dbm = { ...dbm, ...this.cfg.hooks!.parseNaturalId!(dbm.id) }
969
969
 
970
970
  if (opt.anonymize) {
971
971
  dbm = this.cfg.hooks!.anonymize!(dbm)
@@ -235,9 +235,9 @@ export class DBQuery<ROW extends Partial<ObjectWithId> = AnyObjectWithId> {
235
235
  * DBQuery that has additional method to support Fluent API style.
236
236
  */
237
237
  export class RunnableDBQuery<
238
- BM extends Partial<ObjectWithId<ID>>,
239
- DBM extends Partial<ObjectWithId<ID>> = BM,
240
- ID extends string | number = NonNullable<BM['id']>,
238
+ BM extends ObjectWithId<ID>,
239
+ DBM extends ObjectWithId<ID> = BM,
240
+ ID extends string | number = BM['id'],
241
241
  > extends DBQuery<DBM> {
242
242
  /**
243
243
  * Pass `table` to override table.