@naturalcycles/db-lib 9.4.0 → 9.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/cachedb/cache.db.d.ts +10 -10
- package/dist/adapter/cachedb/cache.db.model.d.ts +2 -2
- package/dist/adapter/file/file.db.d.ts +12 -12
- package/dist/adapter/file/file.db.model.d.ts +3 -3
- package/dist/adapter/file/inMemory.persistence.plugin.d.ts +1 -1
- package/dist/adapter/file/localFile.persistence.plugin.d.ts +4 -4
- package/dist/adapter/file/noop.persistence.plugin.d.ts +3 -3
- package/dist/adapter/inmemory/inMemory.db.d.ts +12 -12
- package/dist/adapter/inmemory/queryInMemory.d.ts +2 -2
- package/dist/base.common.db.d.ts +10 -10
- package/dist/common.db.d.ts +10 -10
- package/dist/commondao/common.dao.d.ts +45 -45
- package/dist/commondao/common.dao.js +3 -2
- package/dist/commondao/common.dao.model.d.ts +11 -11
- package/dist/db.model.d.ts +5 -5
- package/dist/pipeline/dbPipelineBackup.d.ts +1 -1
- package/dist/pipeline/dbPipelineCopy.d.ts +1 -1
- package/dist/pipeline/dbPipelineRestore.d.ts +1 -1
- package/dist/query/dbQuery.d.ts +15 -15
- package/dist/testing/test.model.d.ts +5 -5
- package/dist/testing/test.model.js +3 -0
- package/dist/transaction/dbTransaction.util.d.ts +3 -3
- package/dist/validation/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/adapter/cachedb/cache.db.model.ts +2 -2
- package/src/adapter/cachedb/cache.db.ts +14 -15
- package/src/adapter/file/file.db.model.ts +3 -3
- package/src/adapter/file/file.db.ts +15 -18
- package/src/adapter/file/inMemory.persistence.plugin.ts +1 -1
- package/src/adapter/file/localFile.persistence.plugin.ts +5 -5
- package/src/adapter/file/noop.persistence.plugin.ts +3 -3
- package/src/adapter/inmemory/inMemory.db.ts +17 -19
- package/src/adapter/inmemory/queryInMemory.ts +2 -5
- package/src/base.common.db.ts +10 -20
- package/src/common.db.ts +13 -20
- package/src/commondao/common.dao.model.ts +13 -20
- package/src/commondao/common.dao.ts +87 -107
- package/src/db.model.ts +5 -6
- package/src/pipeline/dbPipelineBackup.ts +1 -1
- package/src/pipeline/dbPipelineCopy.ts +11 -4
- package/src/pipeline/dbPipelineRestore.ts +4 -4
- package/src/query/dbQuery.ts +18 -21
- package/src/testing/test.model.ts +8 -5
- package/src/timeseries/commonTimeSeriesDao.ts +1 -1
- package/src/transaction/dbTransaction.util.ts +3 -3
- package/src/validation/index.ts +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchemaObject, JsonSchemaRootObject,
|
|
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
|
|
24
|
-
createTable<ROW extends
|
|
25
|
-
getByIds<ROW extends
|
|
26
|
-
saveBatch<ROW extends
|
|
27
|
-
runQuery<ROW extends
|
|
28
|
-
runQueryCount<ROW extends
|
|
29
|
-
streamQuery<ROW extends
|
|
30
|
-
deleteByQuery<ROW extends
|
|
31
|
-
updateByQuery<ROW extends
|
|
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,
|
|
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
|
|
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,
|
|
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
|
|
25
|
-
saveBatch<ROW extends
|
|
26
|
-
runQuery<ROW extends
|
|
27
|
-
runQueryCount<ROW extends
|
|
28
|
-
streamQuery<ROW extends
|
|
29
|
-
deleteByQuery<ROW extends
|
|
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
|
|
32
|
-
loadFile<ROW extends
|
|
33
|
-
saveFile<ROW extends
|
|
34
|
-
saveFiles<ROW extends
|
|
35
|
-
sortRows<ROW extends
|
|
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,
|
|
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
|
|
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 {
|
|
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
|
|
23
|
-
saveFiles(ops: DBSaveBatchOperation[]): Promise<void>;
|
|
24
|
-
saveFile<ROW extends
|
|
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 {
|
|
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
|
|
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
|
|
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
|
|
82
|
-
createTable<ROW extends
|
|
83
|
-
getByIds<ROW extends
|
|
84
|
-
saveBatch<ROW extends
|
|
85
|
-
deleteByQuery<ROW extends
|
|
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
|
|
88
|
-
runQuery<ROW extends
|
|
89
|
-
runQueryCount<ROW extends
|
|
90
|
-
streamQuery<ROW extends
|
|
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
|
|
108
|
-
saveBatch<ROW extends
|
|
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 {
|
|
1
|
+
import { ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
2
|
import { DBQuery } from '../../query/dbQuery';
|
|
3
|
-
export declare function queryInMemory<ROW extends
|
|
3
|
+
export declare function queryInMemory<ROW extends ObjectWithId>(q: DBQuery<ROW>, rows?: ROW[]): ROW[];
|
package/dist/base.common.db.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchemaObject, JsonSchemaRootObject,
|
|
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
|
|
16
|
-
createTable<ROW extends
|
|
17
|
-
getByIds<ROW extends
|
|
18
|
-
deleteByQuery<ROW extends
|
|
19
|
-
updateByQuery<ROW extends
|
|
20
|
-
runQuery<ROW extends
|
|
21
|
-
runQueryCount<ROW extends
|
|
22
|
-
saveBatch<ROW extends
|
|
23
|
-
streamQuery<ROW extends
|
|
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
|
}
|
package/dist/common.db.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchemaObject, JsonSchemaRootObject,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
65
|
-
runQueryCount: <ROW extends
|
|
66
|
-
streamQuery: <ROW extends
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
3
|
+
import { AnyObject, AsyncMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, UnixTimestampMillisNumber, Unsaved, 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,22 +12,22 @@ 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
|
|
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
|
-
create(part?: Partial<BM>, opt?: CommonDaoOptions):
|
|
18
|
+
create(part?: Partial<BM>, opt?: CommonDaoOptions): BM;
|
|
19
19
|
getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
20
|
-
getById(id?: string | null, opt?: CommonDaoOptions): Promise<
|
|
21
|
-
getByIdOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<
|
|
22
|
-
getByIdAsDBMOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<
|
|
20
|
+
getById(id?: string | null, opt?: CommonDaoOptions): Promise<BM | null>;
|
|
21
|
+
getByIdOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<BM>;
|
|
22
|
+
getByIdAsDBMOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<DBM>;
|
|
23
23
|
getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
24
|
-
getByIdAsDBM(id?: string | null, opt?: CommonDaoOptions): Promise<
|
|
24
|
+
getByIdAsDBM(id?: string | null, opt?: CommonDaoOptions): Promise<DBM | null>;
|
|
25
25
|
getByIdAsTM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
26
26
|
getByIdAsTM(id?: string | null, opt?: CommonDaoOptions): Promise<TM | null>;
|
|
27
|
-
getByIds(ids: string[], opt?: CommonDaoOptions): Promise<
|
|
28
|
-
getByIdsAsDBM(ids: string[], opt?: CommonDaoOptions): Promise<
|
|
29
|
-
requireById(id: string, opt?: CommonDaoOptions): Promise<
|
|
30
|
-
requireByIdAsDBM(id: string, opt?: CommonDaoOptions): Promise<
|
|
27
|
+
getByIds(ids: string[], opt?: CommonDaoOptions): Promise<BM[]>;
|
|
28
|
+
getByIdsAsDBM(ids: string[], opt?: CommonDaoOptions): Promise<DBM[]>;
|
|
29
|
+
requireById(id: string, opt?: CommonDaoOptions): Promise<BM>;
|
|
30
|
+
requireByIdAsDBM(id: string, opt?: CommonDaoOptions): Promise<DBM>;
|
|
31
31
|
private throwRequiredError;
|
|
32
32
|
/**
|
|
33
33
|
* Throws if readOnly is true
|
|
@@ -38,33 +38,33 @@ export declare class CommonDao<BM extends PartialObjectWithId, DBM extends Parti
|
|
|
38
38
|
*/
|
|
39
39
|
private requireObjectMutability;
|
|
40
40
|
private ensureUniqueId;
|
|
41
|
-
getBy(by: keyof DBM, value: any, limit?: number, opt?: CommonDaoOptions): Promise<
|
|
42
|
-
getOneBy(by: keyof DBM, value: any, opt?: CommonDaoOptions): Promise<
|
|
43
|
-
getAll(opt?: CommonDaoOptions): Promise<
|
|
41
|
+
getBy(by: keyof DBM, value: any, limit?: number, opt?: CommonDaoOptions): Promise<BM[]>;
|
|
42
|
+
getOneBy(by: keyof DBM, value: any, opt?: CommonDaoOptions): Promise<BM | null>;
|
|
43
|
+
getAll(opt?: CommonDaoOptions): Promise<BM[]>;
|
|
44
44
|
/**
|
|
45
45
|
* Pass `table` to override table
|
|
46
46
|
*/
|
|
47
47
|
query(table?: string): RunnableDBQuery<BM, DBM, TM>;
|
|
48
|
-
runQuery(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<
|
|
48
|
+
runQuery(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<BM[]>;
|
|
49
49
|
runQuerySingleColumn<T = any>(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<T[]>;
|
|
50
50
|
/**
|
|
51
51
|
* Convenience method that runs multiple queries in parallel and then merges their results together.
|
|
52
52
|
* Does deduplication by id.
|
|
53
53
|
* Order is not guaranteed, as queries run in parallel.
|
|
54
54
|
*/
|
|
55
|
-
runUnionQueries(queries: DBQuery<DBM>[], opt?: CommonDaoOptions): Promise<
|
|
56
|
-
runQueryExtended(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<
|
|
57
|
-
runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<
|
|
58
|
-
runQueryExtendedAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<
|
|
55
|
+
runUnionQueries(queries: DBQuery<DBM>[], opt?: CommonDaoOptions): Promise<BM[]>;
|
|
56
|
+
runQueryExtended(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<BM>>;
|
|
57
|
+
runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<DBM[]>;
|
|
58
|
+
runQueryExtendedAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<DBM>>;
|
|
59
59
|
runQueryAsTM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<TM[]>;
|
|
60
60
|
runQueryExtendedAsTM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<TM>>;
|
|
61
61
|
runQueryCount(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<number>;
|
|
62
|
-
streamQueryForEach(q: DBQuery<DBM>, mapper: AsyncMapper<
|
|
63
|
-
streamQueryAsDBMForEach(q: DBQuery<DBM>, mapper: AsyncMapper<
|
|
62
|
+
streamQueryForEach(q: DBQuery<DBM>, mapper: AsyncMapper<BM, void>, opt?: CommonDaoStreamForEachOptions<BM>): Promise<void>;
|
|
63
|
+
streamQueryAsDBMForEach(q: DBQuery<DBM>, mapper: AsyncMapper<DBM, void>, opt?: CommonDaoStreamForEachOptions<DBM>): Promise<void>;
|
|
64
64
|
/**
|
|
65
65
|
* Stream as Readable, to be able to .pipe() it further with support of backpressure.
|
|
66
66
|
*/
|
|
67
|
-
streamQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<
|
|
67
|
+
streamQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM>;
|
|
68
68
|
/**
|
|
69
69
|
* Stream as Readable, to be able to .pipe() it further with support of backpressure.
|
|
70
70
|
*
|
|
@@ -74,7 +74,7 @@ export declare class CommonDao<BM extends PartialObjectWithId, DBM extends Parti
|
|
|
74
74
|
*
|
|
75
75
|
* You can do `.pipe(transformNoOp)` to make it "valid again".
|
|
76
76
|
*/
|
|
77
|
-
streamQuery(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<
|
|
77
|
+
streamQuery(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM>;
|
|
78
78
|
queryIds(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<string[]>;
|
|
79
79
|
streamQueryIds(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<string>): ReadableTyped<string>;
|
|
80
80
|
streamQueryIdsForEach(q: DBQuery<DBM>, mapper: AsyncMapper<string, void>, opt?: CommonDaoStreamForEachOptions<string>): Promise<void>;
|
|
@@ -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
|
|
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
|
|
89
|
+
save(bm: Unsaved<BM>, opt?: CommonDaoSaveOptions<BM, DBM>): Promise<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:
|
|
98
|
+
savePatch(bm: BM, patch: Partial<BM>, opt: CommonDaoSaveBatchOptions<DBM>): Promise<BM>;
|
|
99
99
|
/**
|
|
100
100
|
* Convenience method to replace 3 operations (loading+patching+saving) with one:
|
|
101
101
|
*
|
|
@@ -105,25 +105,25 @@ export declare class CommonDao<BM extends PartialObjectWithId, DBM extends Parti
|
|
|
105
105
|
* 2. Applies the patch on top of loaded data.
|
|
106
106
|
* 3. Saves (as fast as possible since the read) with the Patch applied, but only if the data has changed.
|
|
107
107
|
*/
|
|
108
|
-
patchById(id: string, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<
|
|
108
|
+
patchById(id: string, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>;
|
|
109
109
|
/**
|
|
110
110
|
* Like patchById, but runs all operations within a Transaction.
|
|
111
111
|
*/
|
|
112
|
-
patchByIdInTransaction(id: string, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<
|
|
112
|
+
patchByIdInTransaction(id: string, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>;
|
|
113
113
|
/**
|
|
114
114
|
* Same as patchById, but takes the whole object as input.
|
|
115
115
|
* This "whole object" is mutated with the patch and returned.
|
|
116
116
|
* Otherwise, similar behavior as patchById.
|
|
117
117
|
* It still loads the row from the DB.
|
|
118
118
|
*/
|
|
119
|
-
patch(bm:
|
|
119
|
+
patch(bm: BM, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>;
|
|
120
120
|
/**
|
|
121
121
|
* Like patch, but runs all operations within a Transaction.
|
|
122
122
|
*/
|
|
123
|
-
patchInTransaction(bm:
|
|
124
|
-
saveAsDBM(dbm: DBM
|
|
125
|
-
saveBatch(bms: BM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<
|
|
126
|
-
saveBatchAsDBM(dbms: DBM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<
|
|
123
|
+
patchInTransaction(bm: BM, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>;
|
|
124
|
+
saveAsDBM(dbm: Unsaved<DBM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<DBM>;
|
|
125
|
+
saveBatch(bms: Unsaved<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM[]>;
|
|
126
|
+
saveBatchAsDBM(dbms: Unsaved<DBM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<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,21 +147,21 @@ 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?:
|
|
151
|
-
dbmsToBM(dbms:
|
|
150
|
+
dbmToBM(_dbm?: DBM, opt?: CommonDaoOptions): Promise<BM>;
|
|
151
|
+
dbmsToBM(dbms: DBM[], opt?: CommonDaoOptions): Promise<BM[]>;
|
|
152
152
|
/**
|
|
153
153
|
* Mutates object with properties: id, created, updated.
|
|
154
154
|
* Returns DBM (new reference).
|
|
155
155
|
*/
|
|
156
156
|
bmToDBM(bm: undefined, opt?: CommonDaoOptions): Promise<undefined>;
|
|
157
|
-
bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<
|
|
158
|
-
bmsToDBM(bms: BM[], opt?: CommonDaoOptions): Promise<
|
|
157
|
+
bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<DBM>;
|
|
158
|
+
bmsToDBM(bms: BM[], opt?: CommonDaoOptions): Promise<DBM[]>;
|
|
159
159
|
anyToDBM(dbm: undefined, opt?: CommonDaoOptions): undefined;
|
|
160
|
-
anyToDBM(dbm?: any, opt?: CommonDaoOptions):
|
|
161
|
-
anyToDBMs(entities:
|
|
160
|
+
anyToDBM(dbm?: any, opt?: CommonDaoOptions): DBM;
|
|
161
|
+
anyToDBMs(entities: DBM[], opt?: CommonDaoOptions): DBM[];
|
|
162
162
|
bmToTM(bm: undefined, opt?: CommonDaoOptions): TM | undefined;
|
|
163
|
-
bmToTM(bm?:
|
|
164
|
-
bmsToTM(bms:
|
|
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
|
|
203
|
-
getByIds<BM extends
|
|
204
|
-
save<BM extends
|
|
205
|
-
saveBatch<BM extends
|
|
202
|
+
getById<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, id?: string | null, opt?: CommonDaoOptions): Promise<BM | null>;
|
|
203
|
+
getByIds<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, ids: string[], opt?: CommonDaoOptions): Promise<BM[]>;
|
|
204
|
+
save<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, bm: Unsaved<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<BM>;
|
|
205
|
+
saveBatch<BM extends BaseDBEntity, DBM extends BaseDBEntity>(dao: CommonDao<BM, DBM, any>, bms: Unsaved<BM>[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<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
|
}
|
|
@@ -419,7 +419,7 @@ class CommonDao {
|
|
|
419
419
|
return (stream
|
|
420
420
|
// optimization: 1 validation is enough
|
|
421
421
|
// .pipe(transformMap<any, DBM>(dbm => this.anyToDBM(dbm, opt), safeOpt))
|
|
422
|
-
// .pipe(transformMap<DBM,
|
|
422
|
+
// .pipe(transformMap<DBM, BM>(dbm => this.dbmToBM(dbm, opt), safeOpt))
|
|
423
423
|
.on('error', err => stream.emit('error', err))
|
|
424
424
|
.pipe((0, nodejs_lib_1.transformMap)(async (dbm) => {
|
|
425
425
|
if (this.cfg.hooks.afterLoad) {
|
|
@@ -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));
|
|
@@ -1116,7 +1117,7 @@ class CommonDaoTransaction {
|
|
|
1116
1117
|
// dao: CommonDao<BM, DBM, any>,
|
|
1117
1118
|
// q: DBQuery<DBM>,
|
|
1118
1119
|
// opt?: CommonDaoOptions,
|
|
1119
|
-
// ): Promise<
|
|
1120
|
+
// ): Promise<BM[]> {
|
|
1120
1121
|
// try {
|
|
1121
1122
|
// return await dao.runQuery(q, { ...opt, tx: this.tx })
|
|
1122
1123
|
// } catch (err) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AnyObject, CommonLogger, ErrorMode,
|
|
1
|
+
import { AnyObject, BaseDBEntity, CommonLogger, ErrorMode, Promisable, 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
|
|
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:
|
|
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
|
/**
|
|
@@ -53,7 +53,7 @@ export interface CommonDaoHooks<BM extends PartialObjectWithId, DBM extends Part
|
|
|
53
53
|
*
|
|
54
54
|
* You can do validations as needed here and throw errors, they will be propagated.
|
|
55
55
|
*/
|
|
56
|
-
afterLoad?: (dbm:
|
|
56
|
+
afterLoad?: (dbm: DBM) => Promisable<DBM | null>;
|
|
57
57
|
/**
|
|
58
58
|
* Allows to access the DBM just before it's supposed to be saved to the DB.
|
|
59
59
|
*
|
|
@@ -67,7 +67,7 @@ export interface CommonDaoHooks<BM extends PartialObjectWithId, DBM extends Part
|
|
|
67
67
|
*
|
|
68
68
|
* You can do validations as needed here and throw errors, they will be propagated.
|
|
69
69
|
*/
|
|
70
|
-
beforeSave?: (dbm:
|
|
70
|
+
beforeSave?: (dbm: DBM) => Promisable<DBM | null>;
|
|
71
71
|
/**
|
|
72
72
|
* Called in:
|
|
73
73
|
* - dbmToBM (applied before DBM becomes BM)
|
|
@@ -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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
259
|
+
export interface CommonDaoStreamDeleteOptions<DBM extends BaseDBEntity> extends CommonDaoStreamOptions<DBM> {
|
|
260
260
|
}
|
|
261
|
-
export interface CommonDaoStreamSaveOptions<DBM extends
|
|
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
|
}
|