@naturalcycles/db-lib 9.4.0 → 9.4.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.
Files changed (43) hide show
  1. package/dist/adapter/cachedb/cache.db.d.ts +10 -10
  2. package/dist/adapter/cachedb/cache.db.model.d.ts +2 -2
  3. package/dist/adapter/file/file.db.d.ts +12 -12
  4. package/dist/adapter/file/file.db.model.d.ts +3 -3
  5. package/dist/adapter/file/inMemory.persistence.plugin.d.ts +1 -1
  6. package/dist/adapter/file/localFile.persistence.plugin.d.ts +4 -4
  7. package/dist/adapter/file/noop.persistence.plugin.d.ts +3 -3
  8. package/dist/adapter/inmemory/inMemory.db.d.ts +12 -12
  9. package/dist/adapter/inmemory/queryInMemory.d.ts +2 -2
  10. package/dist/base.common.db.d.ts +10 -10
  11. package/dist/common.db.d.ts +10 -10
  12. package/dist/commondao/common.dao.d.ts +19 -19
  13. package/dist/commondao/common.dao.js +1 -0
  14. package/dist/commondao/common.dao.model.d.ts +9 -9
  15. package/dist/db.model.d.ts +5 -5
  16. package/dist/pipeline/dbPipelineBackup.d.ts +1 -1
  17. package/dist/pipeline/dbPipelineCopy.d.ts +1 -1
  18. package/dist/pipeline/dbPipelineRestore.d.ts +1 -1
  19. package/dist/query/dbQuery.d.ts +7 -7
  20. package/dist/transaction/dbTransaction.util.d.ts +3 -3
  21. package/dist/validation/index.d.ts +2 -2
  22. package/package.json +1 -1
  23. package/src/adapter/cachedb/cache.db.model.ts +2 -2
  24. package/src/adapter/cachedb/cache.db.ts +14 -15
  25. package/src/adapter/file/file.db.model.ts +3 -3
  26. package/src/adapter/file/file.db.ts +15 -18
  27. package/src/adapter/file/inMemory.persistence.plugin.ts +1 -1
  28. package/src/adapter/file/localFile.persistence.plugin.ts +5 -5
  29. package/src/adapter/file/noop.persistence.plugin.ts +3 -3
  30. package/src/adapter/inmemory/inMemory.db.ts +17 -19
  31. package/src/adapter/inmemory/queryInMemory.ts +2 -5
  32. package/src/base.common.db.ts +10 -20
  33. package/src/common.db.ts +13 -20
  34. package/src/commondao/common.dao.model.ts +11 -17
  35. package/src/commondao/common.dao.ts +50 -42
  36. package/src/db.model.ts +5 -6
  37. package/src/pipeline/dbPipelineBackup.ts +1 -1
  38. package/src/pipeline/dbPipelineCopy.ts +11 -4
  39. package/src/pipeline/dbPipelineRestore.ts +5 -4
  40. package/src/query/dbQuery.ts +9 -11
  41. package/src/timeseries/commonTimeSeriesDao.ts +1 -1
  42. package/src/transaction/dbTransaction.util.ts +3 -3
  43. package/src/validation/index.ts +3 -3
@@ -1,4 +1,4 @@
1
- import { JsonSchemaObject, JsonSchemaRootObject, PartialObjectWithId, Saved } from '@naturalcycles/js-lib';
1
+ import { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { BaseCommonDB } from '../../base.common.db';
4
4
  import { CommonDB, CommonDBSupport } from '../../common.db';
@@ -20,13 +20,13 @@ export declare class CacheDB extends BaseCommonDB implements CommonDB {
20
20
  * Resets InMemory DB data
21
21
  */
22
22
  getTables(): Promise<string[]>;
23
- getTableSchema<ROW extends PartialObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
24
- createTable<ROW extends PartialObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CacheDBCreateOptions): Promise<void>;
25
- getByIds<ROW extends PartialObjectWithId>(table: string, ids: string[], opt?: CacheDBSaveOptions<ROW>): Promise<Saved<ROW>[]>;
26
- saveBatch<ROW extends PartialObjectWithId>(table: string, rows: ROW[], opt?: CacheDBSaveOptions<ROW>): Promise<void>;
27
- runQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBSaveOptions<ROW>): Promise<RunQueryResult<Saved<ROW>>>;
28
- runQueryCount<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
29
- streamQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBStreamOptions): ReadableTyped<Saved<ROW>>;
30
- deleteByQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
31
- updateByQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CacheDBOptions): Promise<number>;
23
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
24
+ createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CacheDBCreateOptions): Promise<void>;
25
+ getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CacheDBSaveOptions<ROW>): Promise<ROW[]>;
26
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CacheDBSaveOptions<ROW>): Promise<void>;
27
+ runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBSaveOptions<ROW>): Promise<RunQueryResult<ROW>>;
28
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
29
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBStreamOptions): ReadableTyped<ROW>;
30
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
31
+ updateByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CacheDBOptions): Promise<number>;
32
32
  }
@@ -1,4 +1,4 @@
1
- import { CommonLogger, PartialObjectWithId } from '@naturalcycles/js-lib';
1
+ import { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { CommonDB } from '../../common.db';
3
3
  import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions } from '../../db.model';
4
4
  export interface CacheDBCfg {
@@ -47,7 +47,7 @@ export interface CacheDBOptions extends CommonDBOptions {
47
47
  */
48
48
  onlyCache?: boolean;
49
49
  }
50
- export interface CacheDBSaveOptions<ROW extends PartialObjectWithId> 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
  }
@@ -1,4 +1,4 @@
1
- import { JsonSchemaRootObject, Saved, PartialObjectWithId } from '@naturalcycles/js-lib';
1
+ import { JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { BaseCommonDB, CommonDBSupport, DBSaveBatchOperation } from '../..';
4
4
  import { CommonDB } from '../../common.db';
@@ -21,18 +21,18 @@ export declare class FileDB extends BaseCommonDB implements CommonDB {
21
21
  cfg: FileDBCfg;
22
22
  ping(): Promise<void>;
23
23
  getTables(): Promise<string[]>;
24
- getByIds<ROW extends PartialObjectWithId>(table: string, ids: string[], _opt?: CommonDBOptions): Promise<Saved<ROW>[]>;
25
- saveBatch<ROW extends PartialObjectWithId>(table: string, rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>;
26
- runQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<Saved<ROW>>>;
27
- runQueryCount<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
28
- streamQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
29
- deleteByQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
24
+ getByIds<ROW extends ObjectWithId>(table: string, ids: string[], _opt?: CommonDBOptions): Promise<ROW[]>;
25
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>;
26
+ runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
27
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
28
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
29
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
30
30
  deleteByIds(table: string, ids: string[], _opt?: CommonDBOptions): Promise<number>;
31
- getTableSchema<ROW extends PartialObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
32
- loadFile<ROW extends PartialObjectWithId>(table: string): Promise<Saved<ROW>[]>;
33
- saveFile<ROW extends PartialObjectWithId>(table: string, _rows: ROW[]): Promise<void>;
34
- saveFiles<ROW extends PartialObjectWithId>(ops: DBSaveBatchOperation<ROW>[]): Promise<void>;
35
- sortRows<ROW extends PartialObjectWithId>(rows: ROW[]): ROW[];
31
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
32
+ loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]>;
33
+ saveFile<ROW extends ObjectWithId>(table: string, _rows: ROW[]): Promise<void>;
34
+ saveFiles<ROW extends ObjectWithId>(ops: DBSaveBatchOperation<ROW>[]): Promise<void>;
35
+ sortRows<ROW extends ObjectWithId>(rows: ROW[]): ROW[];
36
36
  private logStarted;
37
37
  private logFinished;
38
38
  }
@@ -1,10 +1,10 @@
1
- import { CommonLogger, PartialObjectWithId, Saved } from '@naturalcycles/js-lib';
1
+ import { CommonLogger, ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { DBSaveBatchOperation } from '../../db.model';
3
3
  import type { DBQueryOrder } from '../../query/dbQuery';
4
4
  export interface FileDBPersistencePlugin {
5
5
  ping: () => Promise<void>;
6
6
  getTables: () => Promise<string[]>;
7
- loadFile: <ROW extends PartialObjectWithId>(table: string) => Promise<Saved<ROW>[]>;
7
+ loadFile: <ROW extends ObjectWithId>(table: string) => Promise<ROW[]>;
8
8
  saveFiles: (ops: DBSaveBatchOperation<any>[]) => Promise<void>;
9
9
  }
10
10
  export interface FileDBCfg {
@@ -12,7 +12,7 @@ export interface FileDBCfg {
12
12
  /**
13
13
  * @default undefined, which means "insertion order"
14
14
  */
15
- sortOnSave?: DBQueryOrder;
15
+ sortOnSave?: DBQueryOrder<any>;
16
16
  /**
17
17
  * @default true
18
18
  * If true - will run `sortObjectDeep()` on each object to achieve deterministic sort
@@ -9,5 +9,5 @@ export declare class InMemoryPersistencePlugin implements FileDBPersistencePlugi
9
9
  ping(): Promise<void>;
10
10
  getTables(): Promise<string[]>;
11
11
  loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]>;
12
- saveFiles(ops: DBSaveBatchOperation[]): Promise<void>;
12
+ saveFiles(ops: DBSaveBatchOperation<any>[]): Promise<void>;
13
13
  }
@@ -1,4 +1,4 @@
1
- import { PartialObjectWithId, Saved } from '@naturalcycles/js-lib';
1
+ import { ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { DBSaveBatchOperation } from '../../db.model';
3
3
  import { FileDBPersistencePlugin } from './file.db.model';
4
4
  export interface LocalFilePersistencePluginCfg {
@@ -19,7 +19,7 @@ export declare class LocalFilePersistencePlugin implements FileDBPersistencePlug
19
19
  cfg: LocalFilePersistencePluginCfg;
20
20
  ping(): Promise<void>;
21
21
  getTables(): Promise<string[]>;
22
- loadFile<ROW extends PartialObjectWithId>(table: string): Promise<Saved<ROW>[]>;
23
- saveFiles(ops: DBSaveBatchOperation[]): Promise<void>;
24
- saveFile<ROW extends PartialObjectWithId>(table: string, rows: ROW[]): Promise<void>;
22
+ loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]>;
23
+ saveFiles(ops: DBSaveBatchOperation<any>[]): Promise<void>;
24
+ saveFile<ROW extends ObjectWithId>(table: string, rows: ROW[]): Promise<void>;
25
25
  }
@@ -1,9 +1,9 @@
1
- import { PartialObjectWithId, Saved } from '@naturalcycles/js-lib';
1
+ import { ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { DBSaveBatchOperation } from '../../db.model';
3
3
  import { FileDBPersistencePlugin } from './file.db.model';
4
4
  export declare class NoopPersistencePlugin implements FileDBPersistencePlugin {
5
5
  ping(): Promise<void>;
6
6
  getTables(): Promise<string[]>;
7
- loadFile<ROW extends PartialObjectWithId>(_table: string): Promise<Saved<ROW>[]>;
8
- saveFiles(_ops: DBSaveBatchOperation[]): Promise<void>;
7
+ loadFile<ROW extends ObjectWithId>(_table: string): Promise<ROW[]>;
8
+ saveFiles(_ops: DBSaveBatchOperation<any>[]): Promise<void>;
9
9
  }
@@ -1,4 +1,4 @@
1
- import { JsonSchemaObject, StringMap, JsonSchemaRootObject, ObjectWithId, CommonLogger, PartialObjectWithId, Saved } from '@naturalcycles/js-lib';
1
+ import { JsonSchemaObject, StringMap, JsonSchemaRootObject, ObjectWithId, CommonLogger } from '@naturalcycles/js-lib';
2
2
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { CommonDB, CommonDBTransactionOptions, CommonDBType, DBOperation, DBPatch, DBTransactionFn } from '../..';
4
4
  import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, DBTransaction, RunQueryResult } from '../../db.model';
@@ -78,16 +78,16 @@ export declare class InMemoryDB implements CommonDB {
78
78
  */
79
79
  resetCache(_table?: string): Promise<void>;
80
80
  getTables(): Promise<string[]>;
81
- getTableSchema<ROW extends PartialObjectWithId>(_table: string): Promise<JsonSchemaRootObject<ROW>>;
82
- createTable<ROW extends PartialObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions): Promise<void>;
83
- getByIds<ROW extends PartialObjectWithId>(_table: string, ids: string[], _opt?: CommonDBOptions): Promise<Saved<ROW>[]>;
84
- saveBatch<ROW extends PartialObjectWithId>(_table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
85
- deleteByQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
81
+ getTableSchema<ROW extends ObjectWithId>(_table: string): Promise<JsonSchemaRootObject<ROW>>;
82
+ createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions): Promise<void>;
83
+ getByIds<ROW extends ObjectWithId>(_table: string, ids: string[], _opt?: CommonDBOptions): Promise<ROW[]>;
84
+ saveBatch<ROW extends ObjectWithId>(_table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
85
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
86
86
  deleteByIds(_table: string, ids: string[], _opt?: CommonDBOptions): Promise<number>;
87
- updateByQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>): Promise<number>;
88
- runQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<Saved<ROW>>>;
89
- runQueryCount<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
90
- streamQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): ReadableTyped<Saved<ROW>>;
87
+ updateByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>): Promise<number>;
88
+ runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
89
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
90
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): ReadableTyped<ROW>;
91
91
  runInTransaction(fn: DBTransactionFn, opt?: CommonDBTransactionOptions): Promise<void>;
92
92
  /**
93
93
  * Flushes all tables (all namespaces) at once.
@@ -104,8 +104,8 @@ export declare class InMemoryDBTransaction implements DBTransaction {
104
104
  constructor(db: InMemoryDB, opt: Required<CommonDBTransactionOptions>);
105
105
  ops: DBOperation[];
106
106
  writeOperationHappened: boolean;
107
- getByIds<ROW extends PartialObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
108
- saveBatch<ROW extends PartialObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
107
+ getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
108
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
109
109
  deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number>;
110
110
  commit(): Promise<void>;
111
111
  rollback(): Promise<void>;
@@ -1,3 +1,3 @@
1
- import { PartialObjectWithId } from '@naturalcycles/js-lib';
1
+ import { ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { DBQuery } from '../../query/dbQuery';
3
- export declare function queryInMemory<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, rows?: ROW[]): ROW[];
3
+ export declare function queryInMemory<ROW extends ObjectWithId>(q: DBQuery<ROW>, rows?: ROW[]): ROW[];
@@ -1,4 +1,4 @@
1
- import { JsonSchemaObject, JsonSchemaRootObject, PartialObjectWithId, Saved } from '@naturalcycles/js-lib';
1
+ import { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { CommonDB, CommonDBSupport, CommonDBType } from './common.db';
4
4
  import { CommonDBOptions, CommonDBSaveOptions, CommonDBTransactionOptions, DBPatch, DBTransactionFn, RunQueryResult } from './db.model';
@@ -12,15 +12,15 @@ export declare class BaseCommonDB implements CommonDB {
12
12
  support: CommonDBSupport;
13
13
  ping(): Promise<void>;
14
14
  getTables(): Promise<string[]>;
15
- getTableSchema<ROW extends PartialObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
16
- createTable<ROW extends PartialObjectWithId>(table: string, schema: JsonSchemaObject<ROW>): Promise<void>;
17
- getByIds<ROW extends PartialObjectWithId>(table: string, ids: string[]): Promise<Saved<ROW>[]>;
18
- deleteByQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>): Promise<number>;
19
- updateByQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CommonDBOptions): Promise<number>;
20
- runQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>): Promise<RunQueryResult<Saved<ROW>>>;
21
- runQueryCount<ROW extends PartialObjectWithId>(q: DBQuery<ROW>): Promise<number>;
22
- saveBatch<ROW extends PartialObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
23
- streamQuery<ROW extends PartialObjectWithId>(q: DBQuery<ROW>): ReadableTyped<Saved<ROW>>;
15
+ getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
16
+ createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>): Promise<void>;
17
+ getByIds<ROW extends ObjectWithId>(table: string, ids: string[]): Promise<ROW[]>;
18
+ deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<number>;
19
+ updateByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CommonDBOptions): Promise<number>;
20
+ runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<RunQueryResult<ROW>>;
21
+ runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>): Promise<number>;
22
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
23
+ streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>): ReadableTyped<ROW>;
24
24
  deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number>;
25
25
  runInTransaction(fn: DBTransactionFn, opt?: CommonDBTransactionOptions): Promise<void>;
26
26
  }
@@ -1,4 +1,4 @@
1
- import { JsonSchemaObject, JsonSchemaRootObject, PartialObjectWithId, Saved } from '@naturalcycles/js-lib';
1
+ import { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBTransactionOptions, DBPatch, DBTransactionFn, RunQueryResult } from './db.model';
4
4
  import { DBQuery } from './query/dbQuery';
@@ -47,27 +47,27 @@ export interface CommonDB {
47
47
  *
48
48
  * This is important for the code to rely on it, and it's verified by dbTest
49
49
  */
50
- getTableSchema: <ROW extends PartialObjectWithId>(table: string) => Promise<JsonSchemaRootObject<ROW>>;
50
+ getTableSchema: <ROW extends ObjectWithId>(table: string) => Promise<JsonSchemaRootObject<ROW>>;
51
51
  /**
52
52
  * Will do like `create table ...` for mysql.
53
53
  * Caution! dropIfExists defaults to false. If set to true - will actually DROP the table!
54
54
  */
55
- createTable: <ROW extends PartialObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions) => Promise<void>;
55
+ createTable: <ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions) => Promise<void>;
56
56
  /**
57
57
  * Order of items returned is not guaranteed to match order of ids.
58
58
  * (Such limitation exists because Datastore doesn't support it).
59
59
  */
60
- getByIds: <ROW extends PartialObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions) => Promise<Saved<ROW>[]>;
60
+ getByIds: <ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions) => Promise<ROW[]>;
61
61
  /**
62
62
  * Order by 'id' is not supported by all implementations (for example, Datastore doesn't support it).
63
63
  */
64
- runQuery: <ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions) => Promise<RunQueryResult<Saved<ROW>>>;
65
- runQueryCount: <ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions) => Promise<number>;
66
- streamQuery: <ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions) => ReadableTyped<Saved<ROW>>;
64
+ runQuery: <ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions) => Promise<RunQueryResult<ROW>>;
65
+ runQueryCount: <ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions) => Promise<number>;
66
+ streamQuery: <ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions) => ReadableTyped<ROW>;
67
67
  /**
68
68
  * rows can have missing ids only if DB supports auto-generating them (like mysql auto_increment).
69
69
  */
70
- saveBatch: <ROW extends PartialObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>) => Promise<void>;
70
+ saveBatch: <ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>) => Promise<void>;
71
71
  /**
72
72
  * Returns number of deleted items.
73
73
  * Not supported by all implementations (e.g Datastore will always return same number as number of ids).
@@ -77,7 +77,7 @@ export interface CommonDB {
77
77
  * Returns number of deleted items.
78
78
  * Not supported by all implementations (e.g Datastore will always return same number as number of ids).
79
79
  */
80
- deleteByQuery: <ROW extends PartialObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions) => Promise<number>;
80
+ deleteByQuery: <ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions) => Promise<number>;
81
81
  /**
82
82
  * Applies patch to the rows returned by the query.
83
83
  *
@@ -96,7 +96,7 @@ export interface CommonDB {
96
96
  *
97
97
  * Returns number of rows affected.
98
98
  */
99
- updateByQuery: <ROW extends PartialObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CommonDBOptions) => Promise<number>;
99
+ updateByQuery: <ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: DBPatch<ROW>, opt?: CommonDBOptions) => Promise<number>;
100
100
  /**
101
101
  * Should be implemented as a Transaction (best effort), which means that
102
102
  * either ALL or NONE of the operations should be applied.
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Transform } from 'node:stream';
3
- import { AnyObject, AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, PartialObjectWithId, Saved, UnixTimestampMillisNumber, ZodSchema } from '@naturalcycles/js-lib';
3
+ import { AnyObject, AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, Saved, UnixTimestampMillisNumber, UnsavedId, ZodSchema } from '@naturalcycles/js-lib';
4
4
  import { AjvSchema, ObjectSchema, ReadableTyped } from '@naturalcycles/nodejs-lib';
5
5
  import { CommonDBTransactionOptions, DBModelType, DBPatch, DBTransaction, RunQueryResult } from '../db.model';
6
6
  import { DBQuery, RunnableDBQuery } from '../query/dbQuery';
@@ -12,7 +12,7 @@ import { CommonDaoCfg, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoSaveBa
12
12
  * BM = Backend model (optimized for API access)
13
13
  * TM = Transport model (optimized to be sent over the wire)
14
14
  */
15
- export declare class CommonDao<BM extends PartialObjectWithId, DBM extends PartialObjectWithId = BM, TM extends AnyObject = BM> {
15
+ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, TM extends AnyObject = BM> {
16
16
  cfg: CommonDaoCfg<BM, DBM, TM>;
17
17
  constructor(cfg: CommonDaoCfg<BM, DBM, TM>);
18
18
  create(part?: Partial<BM>, opt?: CommonDaoOptions): Saved<BM>;
@@ -82,11 +82,11 @@ export declare class CommonDao<BM extends PartialObjectWithId, DBM extends Parti
82
82
  * Mutates!
83
83
  * "Returns", just to have a type of "Saved"
84
84
  */
85
- assignIdCreatedUpdated<T extends BaseDBEntity>(obj: T, opt?: CommonDaoOptions): Saved<T>;
85
+ assignIdCreatedUpdated<T extends BaseDBEntity>(obj: Partial<T>, opt?: CommonDaoOptions): T;
86
86
  /**
87
87
  * Mutates with id, created, updated
88
88
  */
89
- save(bm: BM, opt?: CommonDaoSaveOptions<BM, DBM>): Promise<Saved<BM>>;
89
+ save(bm: UnsavedId<BM>, opt?: CommonDaoSaveOptions<BM, DBM>): Promise<Saved<BM>>;
90
90
  /**
91
91
  * 1. Applies the patch
92
92
  * 2. If object is the same after patching - skips saving it
@@ -95,7 +95,7 @@ export declare class CommonDao<BM extends PartialObjectWithId, DBM extends Parti
95
95
  * Similar to `save` with skipIfEquals.
96
96
  * Similar to `patch`, but doesn't load the object from the Database.
97
97
  */
98
- savePatch(bm: Saved<BM>, patch: Partial<BM>, opt: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
98
+ savePatch(bm: BM, patch: Partial<BM>, opt: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
99
99
  /**
100
100
  * Convenience method to replace 3 operations (loading+patching+saving) with one:
101
101
  *
@@ -116,14 +116,14 @@ export declare class CommonDao<BM extends PartialObjectWithId, DBM extends Parti
116
116
  * Otherwise, similar behavior as patchById.
117
117
  * It still loads the row from the DB.
118
118
  */
119
- patch(bm: Saved<BM>, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
119
+ patch(bm: BM, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
120
120
  /**
121
121
  * Like patch, but runs all operations within a Transaction.
122
122
  */
123
- patchInTransaction(bm: Saved<BM>, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
124
- saveAsDBM(dbm: DBM, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<DBM>>;
125
- saveBatch(bms: BM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>;
126
- saveBatchAsDBM(dbms: DBM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<DBM>[]>;
123
+ patchInTransaction(bm: BM, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
124
+ saveAsDBM(dbm: UnsavedId<DBM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<DBM>>;
125
+ saveBatch(bms: UnsavedId<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>;
126
+ saveBatchAsDBM(dbms: UnsavedId<DBM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<DBM>[]>;
127
127
  /**
128
128
  * "Streaming" is implemented by buffering incoming rows into **batches**
129
129
  * (of size opt.batchSize, which defaults to 500),
@@ -147,8 +147,8 @@ export declare class CommonDao<BM extends PartialObjectWithId, DBM extends Parti
147
147
  updateByIds(ids: string[], patch: DBPatch<DBM>, opt?: CommonDaoOptions): Promise<number>;
148
148
  updateByQuery(q: DBQuery<DBM>, patch: DBPatch<DBM>, opt?: CommonDaoOptions): Promise<number>;
149
149
  dbmToBM(_dbm: undefined, opt?: CommonDaoOptions): Promise<undefined>;
150
- dbmToBM(_dbm?: Saved<DBM>, opt?: CommonDaoOptions): Promise<Saved<BM>>;
151
- dbmsToBM(dbms: Saved<DBM>[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
150
+ dbmToBM(_dbm?: DBM, opt?: CommonDaoOptions): Promise<Saved<BM>>;
151
+ dbmsToBM(dbms: DBM[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
152
152
  /**
153
153
  * Mutates object with properties: id, created, updated.
154
154
  * Returns DBM (new reference).
@@ -158,10 +158,10 @@ export declare class CommonDao<BM extends PartialObjectWithId, DBM extends Parti
158
158
  bmsToDBM(bms: BM[], opt?: CommonDaoOptions): Promise<Saved<DBM>[]>;
159
159
  anyToDBM(dbm: undefined, opt?: CommonDaoOptions): undefined;
160
160
  anyToDBM(dbm?: any, opt?: CommonDaoOptions): Saved<DBM>;
161
- anyToDBMs(entities: Saved<DBM>[], opt?: CommonDaoOptions): Saved<DBM>[];
161
+ anyToDBMs(entities: DBM[], opt?: CommonDaoOptions): Saved<DBM>[];
162
162
  bmToTM(bm: undefined, opt?: CommonDaoOptions): TM | undefined;
163
- bmToTM(bm?: Saved<BM>, opt?: CommonDaoOptions): TM;
164
- bmsToTM(bms: Saved<BM>[], opt?: CommonDaoOptions): TM[];
163
+ bmToTM(bm?: BM, opt?: CommonDaoOptions): TM;
164
+ bmsToTM(bms: BM[], opt?: CommonDaoOptions): TM[];
165
165
  /**
166
166
  * Returns *converted value*.
167
167
  * Validates (unless `skipValidation=true` passed).
@@ -199,10 +199,10 @@ export declare class CommonDaoTransaction {
199
199
  * Perform a graceful rollback without throwing/re-throwing any error.
200
200
  */
201
201
  rollback(): Promise<void>;
202
- getById<BM extends PartialObjectWithId, DBM extends PartialObjectWithId>(dao: CommonDao<BM, DBM, any>, id?: string | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
203
- getByIds<BM extends PartialObjectWithId, DBM extends PartialObjectWithId>(dao: CommonDao<BM, DBM, any>, ids: string[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
204
- save<BM extends PartialObjectWithId, DBM extends PartialObjectWithId>(dao: CommonDao<BM, DBM, any>, bm: BM, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
205
- saveBatch<BM extends PartialObjectWithId, DBM extends PartialObjectWithId>(dao: CommonDao<BM, DBM, any>, bms: BM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>;
202
+ getById<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, id?: string | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
203
+ getByIds<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, ids: string[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
204
+ save<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, bm: UnsavedId<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
205
+ saveBatch<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, bms: UnsavedId<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>;
206
206
  deleteById(dao: CommonDao<any>, id?: string | null, opt?: CommonDaoOptions): Promise<number>;
207
207
  deleteByIds(dao: CommonDao<any>, ids: string[], opt?: CommonDaoOptions): Promise<number>;
208
208
  }
@@ -508,6 +508,7 @@ class CommonDao {
508
508
  }
509
509
  const idWasGenerated = !bm.id && this.cfg.generateId;
510
510
  this.assignIdCreatedUpdated(bm, opt); // mutates
511
+ (0, js_lib_1._typeCast)(bm);
511
512
  let dbm = await this.bmToDBM(bm, opt);
512
513
  if (this.cfg.hooks.beforeSave) {
513
514
  dbm = (await this.cfg.hooks.beforeSave(dbm));
@@ -1,8 +1,8 @@
1
- import { AnyObject, CommonLogger, ErrorMode, PartialObjectWithId, Promisable, Saved, ZodError, ZodSchema } from '@naturalcycles/js-lib';
1
+ import { AnyObject, BaseDBEntity, CommonLogger, ErrorMode, Promisable, Saved, ZodError, ZodSchema } from '@naturalcycles/js-lib';
2
2
  import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchema, 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 PartialObjectWithId, DBM extends PartialObjectWithId, TM> {
5
+ export interface CommonDaoHooks<BM extends BaseDBEntity, DBM extends BaseDBEntity, TM> {
6
6
  /**
7
7
  * Allows to override the id generation function.
8
8
  * By default it uses `stringId` from nodejs-lib
@@ -38,7 +38,7 @@ export interface CommonDaoHooks<BM extends PartialObjectWithId, DBM extends Part
38
38
  * as it only validates "final state", not intermediate
39
39
  */
40
40
  beforeDBMValidate: (dbm: Partial<DBM>) => Partial<DBM>;
41
- beforeDBMToBM: (dbm: Saved<DBM>) => Partial<BM> | Promise<Partial<BM>>;
41
+ beforeDBMToBM: (dbm: DBM) => Partial<BM> | Promise<Partial<BM>>;
42
42
  beforeBMToDBM: (bm: BM) => Partial<DBM> | Promise<Partial<DBM>>;
43
43
  beforeBMToTM: (bm: BM) => Partial<TM>;
44
44
  /**
@@ -77,7 +77,7 @@ export interface CommonDaoHooks<BM extends PartialObjectWithId, DBM extends Part
77
77
  * It still applies to BM "transitively", during dbmToBM
78
78
  * (e.g after loaded from the Database).
79
79
  */
80
- anonymize: (dbm: Saved<DBM>) => Saved<DBM>;
80
+ anonymize: (dbm: DBM) => DBM;
81
81
  /**
82
82
  * If hook is defined - allows to prevent or modify the error thrown.
83
83
  * Return `false` to prevent throwing an error.
@@ -104,7 +104,7 @@ export declare enum CommonDaoLogLevel {
104
104
  */
105
105
  DATA_FULL = 30
106
106
  }
107
- export interface CommonDaoCfg<BM extends PartialObjectWithId, DBM extends PartialObjectWithId = BM, TM extends AnyObject = BM> {
107
+ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, TM extends AnyObject = BM> {
108
108
  db: CommonDB;
109
109
  table: string;
110
110
  /**
@@ -230,7 +230,7 @@ export interface CommonDaoOptions extends CommonDBOptions {
230
230
  */
231
231
  table?: string;
232
232
  }
233
- export interface CommonDaoSaveOptions<BM extends PartialObjectWithId, DBM extends PartialObjectWithId> extends CommonDaoSaveBatchOptions<DBM> {
233
+ export interface CommonDaoSaveOptions<BM extends BaseDBEntity, DBM extends BaseDBEntity> extends CommonDaoSaveBatchOptions<DBM> {
234
234
  /**
235
235
  * If provided - a check will be made.
236
236
  * If the object for saving equals to the object passed to `skipIfEquals` - save operation will be skipped.
@@ -244,7 +244,7 @@ export interface CommonDaoSaveOptions<BM extends PartialObjectWithId, DBM extend
244
244
  /**
245
245
  * All properties default to undefined.
246
246
  */
247
- export interface CommonDaoSaveBatchOptions<DBM extends PartialObjectWithId> extends CommonDaoOptions, CommonDBSaveOptions<DBM> {
247
+ export interface CommonDaoSaveBatchOptions<DBM extends BaseDBEntity> extends CommonDaoOptions, CommonDBSaveOptions<DBM> {
248
248
  /**
249
249
  * @default false
250
250
  *
@@ -256,9 +256,9 @@ export interface CommonDaoSaveBatchOptions<DBM extends PartialObjectWithId> exte
256
256
  */
257
257
  ensureUniqueId?: boolean;
258
258
  }
259
- export interface CommonDaoStreamDeleteOptions<DBM extends PartialObjectWithId> extends CommonDaoStreamOptions<DBM> {
259
+ export interface CommonDaoStreamDeleteOptions<DBM extends BaseDBEntity> extends CommonDaoStreamOptions<DBM> {
260
260
  }
261
- export interface CommonDaoStreamSaveOptions<DBM extends PartialObjectWithId> extends CommonDaoSaveBatchOptions<DBM>, CommonDaoStreamOptions<DBM> {
261
+ export interface CommonDaoStreamSaveOptions<DBM extends BaseDBEntity> extends CommonDaoSaveBatchOptions<DBM>, CommonDaoStreamOptions<DBM> {
262
262
  }
263
263
  export interface CommonDaoStreamForEachOptions<IN> extends CommonDaoStreamOptions<IN>, TransformMapOptions<IN, any> {
264
264
  }
@@ -1,4 +1,4 @@
1
- import type { PartialObjectWithId } from '@naturalcycles/js-lib';
1
+ import { ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { CommonDB } from './common.db';
3
3
  /**
4
4
  * Similar to SQL INSERT, UPDATE.
@@ -48,7 +48,7 @@ export interface CommonDBOptions {
48
48
  /**
49
49
  * All properties default to undefined.
50
50
  */
51
- export interface CommonDBSaveOptions<ROW extends PartialObjectWithId = any> extends CommonDBOptions {
51
+ export interface CommonDBSaveOptions<ROW extends ObjectWithId> extends CommonDBOptions {
52
52
  excludeFromIndexes?: (keyof ROW)[];
53
53
  /**
54
54
  * Default is `upsert`
@@ -75,8 +75,8 @@ export interface RunQueryResult<T> {
75
75
  rows: T[];
76
76
  endCursor?: string;
77
77
  }
78
- export type DBOperation = DBSaveBatchOperation | DBDeleteByIdsOperation;
79
- export interface DBSaveBatchOperation<ROW extends PartialObjectWithId = any> {
78
+ export type DBOperation = DBSaveBatchOperation<any> | DBDeleteByIdsOperation;
79
+ export interface DBSaveBatchOperation<ROW extends ObjectWithId> {
80
80
  type: 'saveBatch';
81
81
  table: string;
82
82
  rows: ROW[];
@@ -109,4 +109,4 @@ export declare class DBIncrement {
109
109
  private constructor();
110
110
  static of(amount: number): DBIncrement;
111
111
  }
112
- export type DBPatch<ROW extends PartialObjectWithId> = Partial<Record<keyof ROW, ROW[keyof ROW] | DBIncrement>>;
112
+ export type DBPatch<ROW extends ObjectWithId> = Partial<Record<keyof ROW, ROW[keyof ROW] | DBIncrement>>;
@@ -46,7 +46,7 @@ export interface DBPipelineBackupOptions extends TransformLogProgressOptions {
46
46
  * But if queryPerTable is set for a table - it will override the Query that is ran for that table
47
47
  * (and ignore sinceUpdated, sinceUpdatedPerTable, limit, and any other properties that modify the query).
48
48
  */
49
- queryPerTable?: StringMap<DBQuery>;
49
+ queryPerTable?: StringMap<DBQuery<any>>;
50
50
  /**
51
51
  * Directory path to store dumped files. Will create `${tableName}.ndjson` (or .ndjson.gz if gzip=true) files.
52
52
  * All parent directories will be created.
@@ -55,7 +55,7 @@ export interface DBPipelineCopyOptions extends TransformLogProgressOptions {
55
55
  * `metric` will be set to table name
56
56
  */
57
57
  transformMapOptions?: TransformMapOptions;
58
- saveOptionsPerTable?: Record<string, CommonDBSaveOptions>;
58
+ saveOptionsPerTable?: Record<string, CommonDBSaveOptions<any>>;
59
59
  }
60
60
  /**
61
61
  * Pipeline from input stream(s) to CommonDB .saveBatch().
@@ -68,7 +68,7 @@ export interface DBPipelineRestoreOptions extends TransformLogProgressOptions {
68
68
  * `metric` will be set to table name
69
69
  */
70
70
  transformMapOptions?: TransformMapOptions;
71
- saveOptionsPerTable?: Record<string, CommonDBSaveOptions>;
71
+ saveOptionsPerTable?: Record<string, CommonDBSaveOptions<any>>;
72
72
  }
73
73
  /**
74
74
  * Pipeline from NDJSON files in a folder (optionally gzipped) to CommonDB.
@@ -1,4 +1,4 @@
1
- import { AsyncMapper, Saved, AnyObject, PartialObjectWithId, AnyPartialObjectWithId } from '@naturalcycles/js-lib';
1
+ import { AsyncMapper, Saved, AnyObject, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import { CommonDaoOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions, DBPatch } from '..';
4
4
  import { CommonDao } from '../commondao/common.dao';
@@ -24,12 +24,12 @@ import { RunQueryResult } from '../db.model';
24
24
  */
25
25
  export type DBQueryFilterOperator = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';
26
26
  export declare const dbQueryFilterOperatorValues: DBQueryFilterOperator[];
27
- export interface DBQueryFilter<ROW extends PartialObjectWithId = AnyPartialObjectWithId> {
27
+ export interface DBQueryFilter<ROW extends ObjectWithId> {
28
28
  name: keyof ROW;
29
29
  op: DBQueryFilterOperator;
30
30
  val: any;
31
31
  }
32
- export interface DBQueryOrder<ROW extends PartialObjectWithId = AnyPartialObjectWithId> {
32
+ export interface DBQueryOrder<ROW extends ObjectWithId> {
33
33
  name: keyof ROW;
34
34
  descending?: boolean;
35
35
  }
@@ -43,14 +43,14 @@ export interface DBQueryOrder<ROW extends PartialObjectWithId = AnyPartialObject
43
43
  *
44
44
  * <DBM> is the type of **queried** object (so e.g `key of DBM` can be used), not **returned** object.
45
45
  */
46
- export declare class DBQuery<ROW extends PartialObjectWithId = AnyPartialObjectWithId> {
46
+ export declare class DBQuery<ROW extends ObjectWithId> {
47
47
  table: string;
48
48
  constructor(table: string);
49
49
  /**
50
50
  * Convenience method.
51
51
  */
52
- static create<ROW extends PartialObjectWithId = AnyPartialObjectWithId>(table: string): DBQuery<ROW>;
53
- static fromPlainObject<ROW extends PartialObjectWithId = AnyPartialObjectWithId>(obj: Partial<DBQuery<ROW>> & {
52
+ static create<ROW extends ObjectWithId>(table: string): DBQuery<ROW>;
53
+ static fromPlainObject<ROW extends ObjectWithId>(obj: Partial<DBQuery<ROW>> & {
54
54
  table: string;
55
55
  }): DBQuery<ROW>;
56
56
  _filters: DBQueryFilter<ROW>[];
@@ -84,7 +84,7 @@ export declare class DBQuery<ROW extends PartialObjectWithId = AnyPartialObjectW
84
84
  /**
85
85
  * DBQuery that has additional method to support Fluent API style.
86
86
  */
87
- export declare class RunnableDBQuery<BM extends PartialObjectWithId, DBM extends PartialObjectWithId = BM, TM extends AnyObject = BM> extends DBQuery<DBM> {
87
+ export declare class RunnableDBQuery<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, TM extends AnyObject = BM> extends DBQuery<DBM> {
88
88
  dao: CommonDao<BM, DBM, TM>;
89
89
  /**
90
90
  * Pass `table` to override table.
@@ -1,4 +1,4 @@
1
- import { PartialObjectWithId } from '@naturalcycles/js-lib';
1
+ import { ObjectWithId } from '@naturalcycles/js-lib';
2
2
  import type { CommonDB } from '../common.db';
3
3
  import { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model';
4
4
  /**
@@ -22,7 +22,7 @@ export declare class FakeDBTransaction implements DBTransaction {
22
22
  protected db: CommonDB;
23
23
  constructor(db: CommonDB);
24
24
  rollback(): Promise<void>;
25
- getByIds<ROW extends PartialObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
26
- saveBatch<ROW extends PartialObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
25
+ getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
26
+ saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
27
27
  deleteByIds(table: string, ids: string[], opt?: CommonDBOptions | undefined): Promise<number>;
28
28
  }
@@ -3,6 +3,6 @@ import { DBQuery, DBQueryFilter, DBQueryFilterOperator, DBQueryOrder } from '../
3
3
  export declare const commonDBOptionsSchema: import("joi").ObjectSchema<CommonDBOptions>;
4
4
  export declare const commonDBSaveOptionsSchema: import("joi").ObjectSchema<CommonDBSaveOptions<any>>;
5
5
  export declare const dbQueryFilterOperatorSchema: import("@naturalcycles/nodejs-lib/dist/validation/joi/string.extensions").StringSchema<DBQueryFilterOperator>;
6
- export declare const dbQueryFilterSchema: import("joi").ObjectSchema<DBQueryFilter<import("@naturalcycles/js-lib").AnyPartialObjectWithId>>;
7
- export declare const dbQueryOrderSchema: import("joi").ObjectSchema<DBQueryOrder<import("@naturalcycles/js-lib").AnyPartialObjectWithId>>;
6
+ export declare const dbQueryFilterSchema: import("joi").ObjectSchema<DBQueryFilter<any>>;
7
+ export declare const dbQueryOrderSchema: import("joi").ObjectSchema<DBQueryOrder<any>>;
8
8
  export declare const dbQuerySchema: import("joi").ObjectSchema<DBQuery<any>>;