@naturalcycles/db-lib 8.42.1 → 8.43.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.
@@ -25,7 +25,7 @@ export declare class CacheDB extends BaseCommonDB implements CommonDB {
25
25
  createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CacheDBCreateOptions): Promise<void>;
26
26
  getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], opt?: CacheDBSaveOptions<ROW>): Promise<ROW[]>;
27
27
  deleteByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], opt?: CacheDBOptions): Promise<number>;
28
- saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], opt?: CacheDBSaveOptions<ROW>): Promise<void>;
28
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CacheDBSaveOptions<ROW>): Promise<void>;
29
29
  runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBSaveOptions<ROW>): Promise<RunQueryResult<ROW>>;
30
30
  runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
31
31
  streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBStreamOptions): Readable;
@@ -47,7 +47,7 @@ export interface CacheDBOptions {
47
47
  */
48
48
  onlyCache?: boolean;
49
49
  }
50
- export interface CacheDBSaveOptions<ROW extends Partial<ObjectWithId>> extends CacheDBOptions, CommonDBSaveOptions<ROW> {
50
+ export interface CacheDBSaveOptions<ROW extends ObjectWithId> extends CacheDBOptions, CommonDBSaveOptions<ROW> {
51
51
  }
52
52
  export interface CacheDBStreamOptions extends CacheDBOptions, CommonDBStreamOptions {
53
53
  }
@@ -22,7 +22,7 @@ export declare class FileDB extends BaseCommonDB implements CommonDB {
22
22
  ping(): Promise<void>;
23
23
  getTables(): Promise<string[]>;
24
24
  getByIds<ROW extends ObjectWithId>(table: string, ids: ROW['id'][], _opt?: CommonDBOptions): Promise<ROW[]>;
25
- saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>;
25
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>;
26
26
  /**
27
27
  * Implementation is optimized for loading/saving _whole files_.
28
28
  */
@@ -53,7 +53,7 @@ export declare class InMemoryDB implements CommonDB {
53
53
  getTableSchema<ROW extends ObjectWithId>(_table: string): Promise<JsonSchemaRootObject<ROW>>;
54
54
  createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions): Promise<void>;
55
55
  getByIds<ROW extends ObjectWithId>(_table: string, ids: ROW['id'][], _opt?: CommonDBOptions): Promise<ROW[]>;
56
- saveBatch<ROW extends Partial<ObjectWithId>>(_table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
56
+ saveBatch<ROW extends ObjectWithId>(_table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
57
57
  deleteByIds<ROW extends ObjectWithId>(_table: string, ids: ROW['id'][], _opt?: CommonDBOptions): Promise<number>;
58
58
  deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
59
59
  runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
@@ -18,7 +18,7 @@ export declare class BaseCommonDB implements CommonDB {
18
18
  getByIds<ROW extends ObjectWithId>(_table: string, _ids: ROW['id'][]): Promise<ROW[]>;
19
19
  runQuery<ROW extends ObjectWithId>(_q: DBQuery<ROW>): Promise<RunQueryResult<ROW>>;
20
20
  runQueryCount<ROW extends ObjectWithId>(_q: DBQuery<ROW>): Promise<number>;
21
- saveBatch<ROW extends Partial<ObjectWithId>>(_table: string, _rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>;
21
+ saveBatch<ROW extends ObjectWithId>(_table: string, _rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>;
22
22
  streamQuery<ROW extends ObjectWithId>(_q: DBQuery<ROW>): ReadableTyped<ROW>;
23
23
  /**
24
24
  * Naive implementation.
@@ -41,7 +41,7 @@ export interface CommonDB {
41
41
  /**
42
42
  * rows can have missing ids only if DB supports auto-generating them (like mysql auto_increment).
43
43
  */
44
- saveBatch<ROW extends Partial<ObjectWithId>>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
44
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
45
45
  /**
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).
@@ -1,4 +1,4 @@
1
- import { AsyncMapper, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, Saved, Unsaved } from '@naturalcycles/js-lib';
1
+ import { AnyObject, AsyncMapper, JsonSchemaObject, JsonSchemaRootObject, ObjectWithId, Saved, Unsaved } from '@naturalcycles/js-lib';
2
2
  import { AjvSchema, ObjectSchemaTyped, ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { DBDeleteByIdsOperation, DBModelType, DBOperation, DBSaveBatchOperation, RunQueryResult } from '../db.model';
4
4
  import { DBQuery, RunnableDBQuery } from '../query/dbQuery';
@@ -10,7 +10,7 @@ import { CommonDaoCfg, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoSaveOp
10
10
  * BM = Backend model (optimized for API access)
11
11
  * TM = Transport model (optimized to be sent over the wire)
12
12
  */
13
- export declare class CommonDao<BM extends Partial<ObjectWithId<ID>>, DBM extends ObjectWithId<ID> = Saved<BM>, TM = BM, ID extends string | number = DBM['id']> {
13
+ export declare class CommonDao<BM extends ObjectWithId<ID>, DBM extends ObjectWithId<ID> = BM, TM extends AnyObject = BM, ID extends string | number = string> {
14
14
  cfg: CommonDaoCfg<BM, DBM, TM, ID>;
15
15
  constructor(cfg: CommonDaoCfg<BM, DBM, TM, ID>);
16
16
  create(part?: Partial<BM>, opt?: CommonDaoOptions): Saved<BM>;
@@ -1,8 +1,8 @@
1
- import { CommonLogger, ErrorMode, ObjectWithId, Saved } from '@naturalcycles/js-lib';
1
+ import { CommonLogger, ErrorMode, ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchemaTyped, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
3
3
  import { CommonDB } from '../common.db';
4
4
  import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model';
5
- export interface CommonDaoHooks<BM extends Partial<ObjectWithId<ID>>, DBM extends ObjectWithId<ID>, TM, ID extends string | number> {
5
+ export interface CommonDaoHooks<BM extends ObjectWithId<ID>, DBM extends ObjectWithId<ID>, TM, ID extends string | number> {
6
6
  createId: (obj: DBM | BM) => ID;
7
7
  parseNaturalId: (id: ID) => Partial<DBM>;
8
8
  beforeCreate: (bm: Partial<BM>) => Partial<BM>;
@@ -38,7 +38,7 @@ export declare enum CommonDaoLogLevel {
38
38
  */
39
39
  DATA_FULL = 30
40
40
  }
41
- export interface CommonDaoCfg<BM extends Partial<ObjectWithId<ID>>, DBM extends ObjectWithId<ID> = Saved<BM>, TM = BM, ID extends string | number = DBM['id']> {
41
+ export interface CommonDaoCfg<BM extends ObjectWithId<ID>, DBM extends ObjectWithId<ID> = BM, TM = BM, ID extends string | number = string> {
42
42
  db: CommonDB;
43
43
  table: string;
44
44
  /**
@@ -181,7 +181,7 @@ export interface CommonDaoOptions extends CommonDBOptions {
181
181
  /**
182
182
  * All properties default to undefined.
183
183
  */
184
- export interface CommonDaoSaveOptions<DBM extends Partial<ObjectWithId>> extends CommonDaoOptions, CommonDBSaveOptions<DBM> {
184
+ export interface CommonDaoSaveOptions<DBM extends ObjectWithId> extends CommonDaoOptions, CommonDBSaveOptions<DBM> {
185
185
  /**
186
186
  * @default false
187
187
  *
@@ -13,7 +13,7 @@ export interface CommonDBOptions {
13
13
  /**
14
14
  * All properties default to undefined.
15
15
  */
16
- export interface CommonDBSaveOptions<ROW extends Partial<ObjectWithId> = AnyObjectWithId> extends CommonDBOptions {
16
+ export interface CommonDBSaveOptions<ROW extends ObjectWithId = AnyObjectWithId> extends CommonDBOptions {
17
17
  excludeFromIndexes?: (keyof ROW)[];
18
18
  /**
19
19
  * Default is `upsert`
@@ -41,7 +41,7 @@ export interface RunQueryResult<T> {
41
41
  endCursor?: string;
42
42
  }
43
43
  export declare type DBOperation = DBSaveBatchOperation | DBDeleteByIdsOperation;
44
- export interface DBSaveBatchOperation<ROW extends ObjectWithId = AnyObjectWithId> {
44
+ export interface DBSaveBatchOperation<ROW extends ObjectWithId = any> {
45
45
  type: 'saveBatch';
46
46
  table: string;
47
47
  rows: ROW[];
@@ -1,4 +1,4 @@
1
- import { AnyObjectWithId, ObjectWithId, AsyncMapper, Saved } from '@naturalcycles/js-lib';
1
+ import { AnyObjectWithId, ObjectWithId, AsyncMapper, Saved, AnyObject } from '@naturalcycles/js-lib';
2
2
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { CommonDaoOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from '..';
4
4
  import { CommonDao } from '../commondao/common.dao';
@@ -83,7 +83,7 @@ export declare class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
83
83
  /**
84
84
  * DBQuery that has additional method to support Fluent API style.
85
85
  */
86
- export declare class RunnableDBQuery<BM extends Partial<ObjectWithId<ID>>, DBM extends ObjectWithId<ID>, TM, ID extends string | number> extends DBQuery<DBM> {
86
+ export declare class RunnableDBQuery<BM extends ObjectWithId<ID>, DBM extends ObjectWithId<ID> = BM, TM extends AnyObject = BM, ID extends string | number = string> extends DBQuery<DBM> {
87
87
  dao: CommonDao<BM, DBM, TM, ID>;
88
88
  /**
89
89
  * Pass `table` to override table.
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
- import { BaseDBEntity, Saved } from '@naturalcycles/js-lib';
2
+ import { BaseDBEntity, Saved, JsonSchemaObject } from '@naturalcycles/js-lib';
3
3
  export declare const TEST_TABLE = "TEST_TABLE";
4
4
  export interface TestItemBM extends BaseDBEntity {
5
+ id: string;
5
6
  k1: string;
6
7
  k2?: string | null;
7
8
  k3?: number;
@@ -17,8 +18,8 @@ export interface TestItemTM {
17
18
  export declare const testItemBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemBM, TestItemBM>;
18
19
  export declare const testItemDBMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemDBM, TestItemDBM>;
19
20
  export declare const testItemTMSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<TestItemTM, TestItemTM>;
20
- export declare const testItemBMJsonSchema: import("@naturalcycles/js-lib").JsonSchemaObject<TestItemBM & Partial<import("@naturalcycles/js-lib").SavedDBEntity<string>>>;
21
- export declare const testItemDBMJsonSchema: import("@naturalcycles/js-lib").JsonSchemaObject<TestItemDBM>;
21
+ export declare const testItemBMJsonSchema: JsonSchemaObject<TestItemBM>;
22
+ export declare const testItemDBMJsonSchema: JsonSchemaObject<TestItemDBM>;
22
23
  export declare function createTestItemDBM(num?: number): TestItemDBM;
23
24
  export declare function createTestItemBM(num?: number): Saved<TestItemBM>;
24
25
  export declare function createTestItemsDBM(count?: number): TestItemDBM[];
@@ -25,6 +25,7 @@ exports.testItemTMSchema = (0, nodejs_lib_1.objectSchema)({
25
25
  });
26
26
  exports.testItemBMJsonSchema = js_lib_1.jsonSchema
27
27
  .rootObject({
28
+ id: js_lib_1.jsonSchema.string(),
28
29
  k1: js_lib_1.jsonSchema.string(),
29
30
  k2: js_lib_1.jsonSchema.oneOf([js_lib_1.jsonSchema.string(), js_lib_1.jsonSchema.null()]).optional(),
30
31
  k3: js_lib_1.jsonSchema.number().optional(),
@@ -1,4 +1,4 @@
1
- import { AnyObjectWithId, ObjectWithId } from '@naturalcycles/js-lib';
1
+ import { ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import type { CommonDB } from '../common.db';
3
3
  import type { CommonDBSaveOptions, DBOperation } from '../db.model';
4
4
  /**
@@ -11,8 +11,8 @@ export declare class DBTransaction {
11
11
  * Convenience method.
12
12
  */
13
13
  static create(ops?: DBOperation[]): DBTransaction;
14
- save<ROW extends ObjectWithId = AnyObjectWithId>(table: string, row: ROW): this;
15
- saveBatch<ROW extends ObjectWithId = AnyObjectWithId>(table: string, rows: ROW[]): this;
14
+ save<ROW extends ObjectWithId>(table: string, row: ROW): this;
15
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[]): this;
16
16
  deleteById(table: string, id: string): this;
17
17
  deleteByIds(table: string, ids: string[]): this;
18
18
  }
package/package.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "engines": {
42
42
  "node": ">=14.15"
43
43
  },
44
- "version": "8.42.1",
44
+ "version": "8.43.1",
45
45
  "description": "Lowest Common Denominator API to supported Databases",
46
46
  "keywords": [
47
47
  "db",
@@ -57,7 +57,7 @@ export interface CacheDBOptions {
57
57
  onlyCache?: boolean
58
58
  }
59
59
 
60
- export interface CacheDBSaveOptions<ROW extends Partial<ObjectWithId>>
60
+ export interface CacheDBSaveOptions<ROW extends ObjectWithId>
61
61
  extends CacheDBOptions,
62
62
  CommonDBSaveOptions<ROW> {}
63
63
 
@@ -147,7 +147,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
147
147
  return deletedIds
148
148
  }
149
149
 
150
- override async saveBatch<ROW extends Partial<ObjectWithId>>(
150
+ override async saveBatch<ROW extends ObjectWithId>(
151
151
  table: string,
152
152
  rows: ROW[],
153
153
  opt: CacheDBSaveOptions<ROW> = {},
@@ -73,7 +73,7 @@ export class FileDB extends BaseCommonDB implements CommonDB {
73
73
  return ids.map(id => byId[id]!).filter(Boolean)
74
74
  }
75
75
 
76
- override async saveBatch<ROW extends Partial<ObjectWithId>>(
76
+ override async saveBatch<ROW extends ObjectWithId>(
77
77
  table: string,
78
78
  rows: ROW[],
79
79
  _opt?: CommonDBSaveOptions<ROW>,
@@ -81,7 +81,7 @@ export class FileDB extends BaseCommonDB implements CommonDB {
81
81
  if (!rows.length) return // save some api calls
82
82
 
83
83
  // 1. Load the whole file
84
- const byId = _by(await this.loadFile<ROW & ObjectWithId>(table), r => r.id)
84
+ const byId = _by(await this.loadFile<ROW>(table), r => r.id)
85
85
 
86
86
  // 2. Merge with new data (using ids)
87
87
  let saved = 0
@@ -152,7 +152,7 @@ export class InMemoryDB implements CommonDB {
152
152
  return ids.map(id => this.data[table]![id]).filter(Boolean) as ROW[]
153
153
  }
154
154
 
155
- async saveBatch<ROW extends Partial<ObjectWithId>>(
155
+ async saveBatch<ROW extends ObjectWithId>(
156
156
  _table: string,
157
157
  rows: ROW[],
158
158
  opt: CommonDBSaveOptions<ROW> = {},
@@ -55,7 +55,7 @@ export class BaseCommonDB implements CommonDB {
55
55
  return 0
56
56
  }
57
57
 
58
- async saveBatch<ROW extends Partial<ObjectWithId>>(
58
+ async saveBatch<ROW extends ObjectWithId>(
59
59
  _table: string,
60
60
  _rows: ROW[],
61
61
  _opt?: CommonDBSaveOptions<ROW>,
package/src/common.db.ts CHANGED
@@ -73,7 +73,7 @@ export interface CommonDB {
73
73
  /**
74
74
  * rows can have missing ids only if DB supports auto-generating them (like mysql auto_increment).
75
75
  */
76
- saveBatch<ROW extends Partial<ObjectWithId>>(
76
+ saveBatch<ROW extends ObjectWithId>(
77
77
  table: string,
78
78
  rows: ROW[],
79
79
  opt?: CommonDBSaveOptions<ROW>,
@@ -1,4 +1,4 @@
1
- import { CommonLogger, ErrorMode, ObjectWithId, Saved } from '@naturalcycles/js-lib'
1
+ import { CommonLogger, ErrorMode, ObjectWithId } from '@naturalcycles/js-lib'
2
2
  import {
3
3
  AjvSchema,
4
4
  AjvValidationError,
@@ -11,7 +11,7 @@ import { CommonDB } from '../common.db'
11
11
  import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model'
12
12
 
13
13
  export interface CommonDaoHooks<
14
- BM extends Partial<ObjectWithId<ID>>,
14
+ BM extends ObjectWithId<ID>,
15
15
  DBM extends ObjectWithId<ID>,
16
16
  TM,
17
17
  ID extends string | number,
@@ -55,10 +55,10 @@ export enum CommonDaoLogLevel {
55
55
  }
56
56
 
57
57
  export interface CommonDaoCfg<
58
- BM extends Partial<ObjectWithId<ID>>,
59
- DBM extends ObjectWithId<ID> = Saved<BM>,
58
+ BM extends ObjectWithId<ID>,
59
+ DBM extends ObjectWithId<ID> = BM,
60
60
  TM = BM,
61
- ID extends string | number = DBM['id'],
61
+ ID extends string | number = string,
62
62
  > {
63
63
  db: CommonDB
64
64
  table: string
@@ -227,7 +227,7 @@ export interface CommonDaoOptions extends CommonDBOptions {
227
227
  /**
228
228
  * All properties default to undefined.
229
229
  */
230
- export interface CommonDaoSaveOptions<DBM extends Partial<ObjectWithId>>
230
+ export interface CommonDaoSaveOptions<DBM extends ObjectWithId>
231
231
  extends CommonDaoOptions,
232
232
  CommonDBSaveOptions<DBM> {
233
233
  /**
@@ -6,6 +6,7 @@ import {
6
6
  _since,
7
7
  _truncate,
8
8
  _uniqBy,
9
+ AnyObject,
9
10
  AppError,
10
11
  AsyncMapper,
11
12
  ErrorMode,
@@ -67,10 +68,10 @@ const isCI = !!process.env['CI']
67
68
  * TM = Transport model (optimized to be sent over the wire)
68
69
  */
69
70
  export class CommonDao<
70
- BM extends Partial<ObjectWithId<ID>>,
71
- DBM extends ObjectWithId<ID> = Saved<BM>,
72
- TM = BM,
73
- ID extends string | number = DBM['id'],
71
+ BM extends ObjectWithId<ID>,
72
+ DBM extends ObjectWithId<ID> = BM,
73
+ TM extends AnyObject = BM,
74
+ ID extends string | number = string,
74
75
  > {
75
76
  constructor(public cfg: CommonDaoCfg<BM, DBM, TM, ID>) {
76
77
  this.cfg = {
@@ -625,7 +626,7 @@ export class CommonDao<
625
626
  table: this.cfg.table,
626
627
  rows: [row],
627
628
  opt: {
628
- excludeFromIndexes: this.cfg.excludeFromIndexes as any,
629
+ excludeFromIndexes: this.cfg.excludeFromIndexes,
629
630
  ...opt,
630
631
  },
631
632
  }
@@ -641,7 +642,7 @@ export class CommonDao<
641
642
  table: this.cfg.table,
642
643
  rows,
643
644
  opt: {
644
- excludeFromIndexes: this.cfg.excludeFromIndexes as any,
645
+ excludeFromIndexes: this.cfg.excludeFromIndexes,
645
646
  ...opt,
646
647
  },
647
648
  }
package/src/db.model.ts CHANGED
@@ -16,7 +16,7 @@ export interface CommonDBOptions {}
16
16
  /**
17
17
  * All properties default to undefined.
18
18
  */
19
- export interface CommonDBSaveOptions<ROW extends Partial<ObjectWithId> = AnyObjectWithId>
19
+ export interface CommonDBSaveOptions<ROW extends ObjectWithId = AnyObjectWithId>
20
20
  extends CommonDBOptions {
21
21
  excludeFromIndexes?: (keyof ROW)[]
22
22
 
@@ -52,7 +52,7 @@ export interface RunQueryResult<T> {
52
52
 
53
53
  export type DBOperation = DBSaveBatchOperation | DBDeleteByIdsOperation
54
54
 
55
- export interface DBSaveBatchOperation<ROW extends ObjectWithId = AnyObjectWithId> {
55
+ export interface DBSaveBatchOperation<ROW extends ObjectWithId = any> {
56
56
  type: 'saveBatch'
57
57
  table: string
58
58
  rows: ROW[]
@@ -1,4 +1,11 @@
1
- import { AnyObjectWithId, ObjectWithId, AsyncMapper, _truncate, Saved } from '@naturalcycles/js-lib'
1
+ import {
2
+ AnyObjectWithId,
3
+ ObjectWithId,
4
+ AsyncMapper,
5
+ _truncate,
6
+ Saved,
7
+ AnyObject,
8
+ } from '@naturalcycles/js-lib'
2
9
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'
3
10
  import { CommonDaoOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from '..'
4
11
  import { CommonDao } from '../commondao/common.dao'
@@ -218,10 +225,10 @@ export class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
218
225
  * DBQuery that has additional method to support Fluent API style.
219
226
  */
220
227
  export class RunnableDBQuery<
221
- BM extends Partial<ObjectWithId<ID>>,
222
- DBM extends ObjectWithId<ID>,
223
- TM,
224
- ID extends string | number,
228
+ BM extends ObjectWithId<ID>,
229
+ DBM extends ObjectWithId<ID> = BM,
230
+ TM extends AnyObject = BM,
231
+ ID extends string | number = string,
225
232
  > extends DBQuery<DBM> {
226
233
  /**
227
234
  * Pass `table` to override table.
@@ -1,4 +1,4 @@
1
- import { jsonSchema, _range, BaseDBEntity, Saved } from '@naturalcycles/js-lib'
1
+ import { jsonSchema, _range, BaseDBEntity, Saved, JsonSchemaObject } from '@naturalcycles/js-lib'
2
2
  import {
3
3
  baseDBEntitySchema,
4
4
  binarySchema,
@@ -14,6 +14,7 @@ const MOCK_TS_2018_06_21 = 1529539200
14
14
  export const TEST_TABLE = 'TEST_TABLE'
15
15
 
16
16
  export interface TestItemBM extends BaseDBEntity {
17
+ id: string
17
18
  k1: string
18
19
  k2?: string | null
19
20
  k3?: number
@@ -49,8 +50,9 @@ export const testItemTMSchema = objectSchema<TestItemTM>({
49
50
  even: booleanSchema.optional(),
50
51
  })
51
52
 
52
- export const testItemBMJsonSchema = jsonSchema
53
+ export const testItemBMJsonSchema: JsonSchemaObject<TestItemBM> = jsonSchema
53
54
  .rootObject<TestItemBM>({
55
+ id: jsonSchema.string(), // todo: not strictly needed here
54
56
  k1: jsonSchema.string(),
55
57
  k2: jsonSchema.oneOf<string | null>([jsonSchema.string(), jsonSchema.null()]).optional(),
56
58
  k3: jsonSchema.number().optional(),
@@ -60,7 +62,7 @@ export const testItemBMJsonSchema = jsonSchema
60
62
  .baseDBEntity()
61
63
  .build()
62
64
 
63
- export const testItemDBMJsonSchema = jsonSchema
65
+ export const testItemDBMJsonSchema: JsonSchemaObject<TestItemDBM> = jsonSchema
64
66
  .rootObject<TestItemDBM>({
65
67
  // todo: figure out how to not copy-paste these 3 fields
66
68
  id: jsonSchema.string(),
@@ -1,4 +1,4 @@
1
- import { AnyObjectWithId, ObjectWithId } from '@naturalcycles/js-lib'
1
+ import { ObjectWithId } from '@naturalcycles/js-lib'
2
2
  import type { CommonDB } from '../common.db'
3
3
  import type { CommonDBSaveOptions, DBOperation } from '../db.model'
4
4
 
@@ -15,7 +15,7 @@ export class DBTransaction {
15
15
  return new DBTransaction(ops)
16
16
  }
17
17
 
18
- save<ROW extends ObjectWithId = AnyObjectWithId>(table: string, row: ROW): this {
18
+ save<ROW extends ObjectWithId>(table: string, row: ROW): this {
19
19
  this.ops.push({
20
20
  type: 'saveBatch',
21
21
  table,
@@ -24,7 +24,7 @@ export class DBTransaction {
24
24
  return this
25
25
  }
26
26
 
27
- saveBatch<ROW extends ObjectWithId = AnyObjectWithId>(table: string, rows: ROW[]): this {
27
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[]): this {
28
28
  this.ops.push({
29
29
  type: 'saveBatch',
30
30
  table,