@naturalcycles/db-lib 8.16.1 → 8.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/adapter/cachedb/cache.db.d.ts +8 -8
- package/dist/adapter/cachedb/cache.db.model.d.ts +4 -4
- package/dist/adapter/file/file.db.d.ts +3 -3
- package/dist/adapter/inmemory/inMemory.db.d.ts +3 -3
- package/dist/base.common.db.d.ts +3 -3
- package/dist/common.db.d.ts +3 -3
- package/dist/commondao/common.dao.d.ts +10 -10
- package/dist/commondao/common.dao.js +6 -4
- package/dist/commondao/common.dao.model.d.ts +2 -2
- package/dist/db.model.d.ts +5 -22
- package/dist/db.model.js +1 -14
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -3
- package/dist/query/dbQuery.d.ts +16 -16
- package/dist/query/dbQuery.js +0 -11
- package/dist/testing/test.model.d.ts +1 -2
- package/dist/testing/test.model.js +2 -3
- package/dist/timeseries/commonTimeSeriesDao.js +1 -1
- package/dist/transaction/dbTransaction.d.ts +3 -3
- package/dist/validation/index.d.ts +3 -3
- package/package.json +1 -1
- package/src/adapter/cachedb/cache.db.model.ts +13 -4
- package/src/adapter/cachedb/cache.db.ts +11 -11
- package/src/adapter/file/file.db.ts +11 -5
- package/src/adapter/inmemory/inMemory.db.ts +4 -4
- package/src/base.common.db.ts +6 -3
- package/src/common.db.ts +7 -3
- package/src/commondao/common.dao.model.ts +4 -2
- package/src/commondao/common.dao.ts +24 -13
- package/src/db.model.ts +6 -41
- package/src/index.ts +2 -14
- package/src/pipeline/dbPipelineRestore.ts +2 -1
- package/src/query/dbQuery.ts +16 -28
- package/src/testing/test.model.ts +3 -2
- package/src/timeseries/commonTimeSeriesDao.ts +2 -1
- package/src/transaction/dbTransaction.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [8.19.0](https://github.com/NaturalCycles/db-lib/compare/v8.18.0...v8.19.0) (2021-10-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* better-typed Queries, excludeFromIndexes ([b7a37ba](https://github.com/NaturalCycles/db-lib/commit/b7a37ba0ed28d5047f4cea5a5f5900f7d1fe5da4))
|
|
7
|
+
|
|
8
|
+
# [8.18.0](https://github.com/NaturalCycles/db-lib/compare/v8.17.0...v8.18.0) (2021-10-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* stop exporting Saved, Unsaved, {base,saved}DBEntitySchema ([0894b20](https://github.com/NaturalCycles/db-lib/commit/0894b20b221136150feab4ee30e1208e0cc238f4))
|
|
14
|
+
|
|
15
|
+
# [8.17.0](https://github.com/NaturalCycles/db-lib/compare/v8.16.2...v8.17.0) (2021-10-15)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* use BaseDBEntity, SavedDBEntity from js-lib ([93210d1](https://github.com/NaturalCycles/db-lib/commit/93210d15ad154b64e9232571f3cc0fe23565ced6))
|
|
21
|
+
|
|
22
|
+
## [8.16.2](https://github.com/NaturalCycles/db-lib/compare/v8.16.1...v8.16.2) (2021-10-04)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* unnecessary await ([11282ba](https://github.com/NaturalCycles/db-lib/commit/11282ba44982c174b1b9eeb052c911c30ee22076))
|
|
28
|
+
|
|
1
29
|
## [8.16.1](https://github.com/NaturalCycles/db-lib/compare/v8.16.0...v8.16.1) (2021-10-04)
|
|
2
30
|
|
|
3
31
|
|
|
@@ -23,12 +23,12 @@ export declare class CacheDB extends BaseCommonDB implements CommonDB {
|
|
|
23
23
|
*/
|
|
24
24
|
getTables(): Promise<string[]>;
|
|
25
25
|
getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
|
|
26
|
-
createTable(table: string, schema: JsonSchemaObject
|
|
27
|
-
getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CacheDBOptions): Promise<ROW[]>;
|
|
28
|
-
deleteByIds(table: string, ids: string[], opt?: CacheDBOptions): Promise<number>;
|
|
29
|
-
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CacheDBOptions): Promise<void>;
|
|
30
|
-
runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<RunQueryResult<ROW>>;
|
|
31
|
-
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
|
|
32
|
-
streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBStreamOptions): Readable;
|
|
33
|
-
deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
|
|
26
|
+
createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CacheDBCreateOptions<ROW>): Promise<void>;
|
|
27
|
+
getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CacheDBOptions<ROW>): Promise<ROW[]>;
|
|
28
|
+
deleteByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CacheDBOptions<ROW>): Promise<number>;
|
|
29
|
+
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CacheDBOptions<ROW>): Promise<void>;
|
|
30
|
+
runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions<ROW>): Promise<RunQueryResult<ROW>>;
|
|
31
|
+
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions<ROW>): Promise<number>;
|
|
32
|
+
streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBStreamOptions<ROW>): Readable;
|
|
33
|
+
deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions<ROW>): Promise<number>;
|
|
34
34
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonDB } from '../../common.db';
|
|
2
|
-
import { CommonDBCreateOptions, CommonDBSaveOptions, CommonDBStreamOptions } from '../../db.model';
|
|
2
|
+
import { CommonDBCreateOptions, CommonDBSaveOptions, CommonDBStreamOptions, ObjectWithId } from '../../db.model';
|
|
3
3
|
export interface CacheDBCfg {
|
|
4
4
|
name: string;
|
|
5
5
|
cacheDB: CommonDB;
|
|
@@ -32,7 +32,7 @@ export interface CacheDBCfg {
|
|
|
32
32
|
*/
|
|
33
33
|
logDownstream?: boolean;
|
|
34
34
|
}
|
|
35
|
-
export interface CacheDBOptions extends CommonDBSaveOptions {
|
|
35
|
+
export interface CacheDBOptions<ROW extends ObjectWithId> extends CommonDBSaveOptions<ROW> {
|
|
36
36
|
/**
|
|
37
37
|
* @default false
|
|
38
38
|
*/
|
|
@@ -42,7 +42,7 @@ export interface CacheDBOptions extends CommonDBSaveOptions {
|
|
|
42
42
|
*/
|
|
43
43
|
onlyCache?: boolean;
|
|
44
44
|
}
|
|
45
|
-
export interface CacheDBStreamOptions extends CacheDBOptions
|
|
45
|
+
export interface CacheDBStreamOptions<ROW extends ObjectWithId> extends CacheDBOptions<ROW>, CommonDBStreamOptions {
|
|
46
46
|
}
|
|
47
|
-
export interface CacheDBCreateOptions extends CacheDBOptions
|
|
47
|
+
export interface CacheDBCreateOptions<ROW extends ObjectWithId> extends CacheDBOptions<ROW>, CommonDBCreateOptions {
|
|
48
48
|
}
|
|
@@ -22,11 +22,11 @@ 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: string[], _opt?: CommonDBOptions): Promise<ROW[]>;
|
|
25
|
-
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], _opt?: CommonDBSaveOptions): 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
|
*/
|
|
29
|
-
commitTransaction(tx: DBTransaction, _opt?:
|
|
29
|
+
commitTransaction(tx: DBTransaction, _opt?: CommonDBOptions): Promise<void>;
|
|
30
30
|
runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
|
|
31
31
|
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
|
|
32
32
|
streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
|
|
@@ -35,7 +35,7 @@ export declare class FileDB extends BaseCommonDB implements CommonDB {
|
|
|
35
35
|
getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
|
|
36
36
|
loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]>;
|
|
37
37
|
saveFile<ROW extends ObjectWithId>(table: string, _rows: ROW[]): Promise<void>;
|
|
38
|
-
saveFiles(ops: DBSaveBatchOperation[]): Promise<void>;
|
|
38
|
+
saveFiles<ROW extends ObjectWithId>(ops: DBSaveBatchOperation<ROW>[]): Promise<void>;
|
|
39
39
|
/**
|
|
40
40
|
* Mutates
|
|
41
41
|
*/
|
|
@@ -47,15 +47,15 @@ export declare class InMemoryDB implements CommonDB {
|
|
|
47
47
|
resetCache(_table?: string): Promise<void>;
|
|
48
48
|
getTables(): Promise<string[]>;
|
|
49
49
|
getTableSchema<ROW extends ObjectWithId>(_table: string): Promise<JsonSchemaRootObject<ROW>>;
|
|
50
|
-
createTable(_table: string, _schema: JsonSchemaObject
|
|
50
|
+
createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions): Promise<void>;
|
|
51
51
|
getByIds<ROW extends ObjectWithId>(_table: string, ids: string[], _opt?: CommonDBOptions): Promise<ROW[]>;
|
|
52
|
-
saveBatch<ROW extends ObjectWithId>(_table: string, rows: ROW[], _opt?: CommonDBSaveOptions): Promise<void>;
|
|
52
|
+
saveBatch<ROW extends ObjectWithId>(_table: string, rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>;
|
|
53
53
|
deleteByIds(_table: string, ids: string[], _opt?: CommonDBOptions): Promise<number>;
|
|
54
54
|
deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
|
|
55
55
|
runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
|
|
56
56
|
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
|
|
57
57
|
streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): ReadableTyped<ROW>;
|
|
58
|
-
commitTransaction(tx: DBTransaction, opt?:
|
|
58
|
+
commitTransaction(tx: DBTransaction, opt?: CommonDBOptions): Promise<void>;
|
|
59
59
|
/**
|
|
60
60
|
* Flushes all tables (all namespaces) at once.
|
|
61
61
|
*/
|
package/dist/base.common.db.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib';
|
|
2
2
|
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDB } from './common.db';
|
|
4
|
-
import {
|
|
4
|
+
import { CommonDBOptions, ObjectWithId, RunQueryResult } from './db.model';
|
|
5
5
|
import { DBQuery } from './query/dbQuery';
|
|
6
6
|
import { DBTransaction } from './transaction/dbTransaction';
|
|
7
7
|
/**
|
|
@@ -12,7 +12,7 @@ export declare class BaseCommonDB implements CommonDB {
|
|
|
12
12
|
ping(): Promise<void>;
|
|
13
13
|
getTables(): Promise<string[]>;
|
|
14
14
|
getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
|
|
15
|
-
createTable(_table: string, _schema: JsonSchemaObject): Promise<void>;
|
|
15
|
+
createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>): Promise<void>;
|
|
16
16
|
deleteByIds(_table: string, _ids: string[]): Promise<number>;
|
|
17
17
|
deleteByQuery<ROW extends ObjectWithId>(_q: DBQuery<ROW>): Promise<number>;
|
|
18
18
|
getByIds<ROW extends ObjectWithId>(_table: string, _ids: string[]): Promise<ROW[]>;
|
|
@@ -24,5 +24,5 @@ export declare class BaseCommonDB implements CommonDB {
|
|
|
24
24
|
* Naive implementation.
|
|
25
25
|
* To be extended.
|
|
26
26
|
*/
|
|
27
|
-
commitTransaction(tx: DBTransaction, opt?:
|
|
27
|
+
commitTransaction(tx: DBTransaction, opt?: CommonDBOptions): Promise<void>;
|
|
28
28
|
}
|
package/dist/common.db.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface CommonDB {
|
|
|
26
26
|
* Will do like `create table ...` for mysql.
|
|
27
27
|
* Caution! dropIfExists defaults to false. If set to true - will actually DROP the table!
|
|
28
28
|
*/
|
|
29
|
-
createTable(table: string, schema: JsonSchemaObject
|
|
29
|
+
createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CommonDBCreateOptions): Promise<void>;
|
|
30
30
|
/**
|
|
31
31
|
* Order of items returned is not guaranteed to match order of ids.
|
|
32
32
|
* (Such limitation exists because Datastore doesn't support it).
|
|
@@ -38,7 +38,7 @@ export interface CommonDB {
|
|
|
38
38
|
runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
|
|
39
39
|
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBOptions): Promise<number>;
|
|
40
40
|
streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions): ReadableTyped<ROW>;
|
|
41
|
-
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions): Promise<void>;
|
|
41
|
+
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
|
|
42
42
|
/**
|
|
43
43
|
* @returns number of deleted items.
|
|
44
44
|
* Not supported by all implementations (e.g Datastore will always return same number as number of ids).
|
|
@@ -49,5 +49,5 @@ export interface CommonDB {
|
|
|
49
49
|
* Should be implemented as a Transaction (best effort), which means that
|
|
50
50
|
* either ALL or NONE of the operations should be applied.
|
|
51
51
|
*/
|
|
52
|
-
commitTransaction(tx: DBTransaction, opt?:
|
|
52
|
+
commitTransaction(tx: DBTransaction, opt?: CommonDBOptions): Promise<void>;
|
|
53
53
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AsyncMapper, JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AsyncMapper, JsonSchemaObject, JsonSchemaRootObject, Saved } from '@naturalcycles/js-lib';
|
|
2
2
|
import { AjvSchema, ObjectSchemaTyped, ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
|
-
import { DBModelType, ObjectWithId, RunQueryResult
|
|
3
|
+
import { DBModelType, ObjectWithId, RunQueryResult } from '../db.model';
|
|
4
4
|
import { DBQuery, RunnableDBQuery } from '../query/dbQuery';
|
|
5
5
|
import { CommonDaoCfg, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoSaveOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from './common.dao.model';
|
|
6
6
|
/**
|
|
@@ -32,8 +32,8 @@ export declare class CommonDao<BM extends Partial<ObjectWithId>, DBM extends Obj
|
|
|
32
32
|
* Throws if readOnly is true
|
|
33
33
|
*/
|
|
34
34
|
private requireWriteAccess;
|
|
35
|
-
getBy(by:
|
|
36
|
-
getOneBy(by:
|
|
35
|
+
getBy(by: keyof DBM, value: any, limit?: number, opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
|
|
36
|
+
getOneBy(by: keyof DBM, value: any, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
|
|
37
37
|
getAll(opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
|
|
38
38
|
/**
|
|
39
39
|
* Pass `table` to override table
|
|
@@ -74,7 +74,7 @@ export declare class CommonDao<BM extends Partial<ObjectWithId>, DBM extends Obj
|
|
|
74
74
|
/**
|
|
75
75
|
* Mutates with id, created, updated
|
|
76
76
|
*/
|
|
77
|
-
save(bm: BM, opt?: CommonDaoSaveOptions): Promise<Saved<BM>>;
|
|
77
|
+
save(bm: BM, opt?: CommonDaoSaveOptions<DBM>): Promise<Saved<BM>>;
|
|
78
78
|
/**
|
|
79
79
|
* Mutates id if needed
|
|
80
80
|
*/
|
|
@@ -87,11 +87,11 @@ export declare class CommonDao<BM extends Partial<ObjectWithId>, DBM extends Obj
|
|
|
87
87
|
*
|
|
88
88
|
* Convenience method to replace 3 operations (loading+patching+saving) with one.
|
|
89
89
|
*/
|
|
90
|
-
patch(id: string, patch: Partial<BM>, opt?: CommonDaoSaveOptions): Promise<Saved<BM>>;
|
|
91
|
-
patchAsDBM(id: string, patch: Partial<DBM>, opt?: CommonDaoSaveOptions): Promise<DBM>;
|
|
92
|
-
saveAsDBM(dbm: DBM, opt?: CommonDaoSaveOptions): Promise<DBM>;
|
|
93
|
-
saveBatch(bms: BM[], opt?: CommonDaoSaveOptions): Promise<Saved<BM>[]>;
|
|
94
|
-
saveBatchAsDBM(dbms: DBM[], opt?: CommonDaoSaveOptions): Promise<DBM[]>;
|
|
90
|
+
patch(id: string, patch: Partial<BM>, opt?: CommonDaoSaveOptions<DBM>): Promise<Saved<BM>>;
|
|
91
|
+
patchAsDBM(id: string, patch: Partial<DBM>, opt?: CommonDaoSaveOptions<DBM>): Promise<DBM>;
|
|
92
|
+
saveAsDBM(dbm: DBM, opt?: CommonDaoSaveOptions<DBM>): Promise<DBM>;
|
|
93
|
+
saveBatch(bms: BM[], opt?: CommonDaoSaveOptions<DBM>): Promise<Saved<BM>[]>;
|
|
94
|
+
saveBatchAsDBM(dbms: DBM[], opt?: CommonDaoSaveOptions<DBM>): Promise<DBM[]>;
|
|
95
95
|
/**
|
|
96
96
|
* @returns number of deleted items
|
|
97
97
|
*/
|
|
@@ -155,10 +155,10 @@ class CommonDao {
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
async getBy(by, value, limit = 0, opt) {
|
|
158
|
-
return await this.query().
|
|
158
|
+
return await this.query().filterEq(by, value).limit(limit).runQuery(opt);
|
|
159
159
|
}
|
|
160
160
|
async getOneBy(by, value, opt) {
|
|
161
|
-
const [bm] = await this.query().
|
|
161
|
+
const [bm] = await this.query().filterEq(by, value).limit(1).runQuery(opt);
|
|
162
162
|
return bm || null;
|
|
163
163
|
}
|
|
164
164
|
async getAll(opt) {
|
|
@@ -548,7 +548,8 @@ class CommonDao {
|
|
|
548
548
|
// DBM > BM
|
|
549
549
|
const bm = await this.cfg.hooks.beforeDBMToBM(dbm);
|
|
550
550
|
// Validate/convert BM
|
|
551
|
-
return
|
|
551
|
+
// eslint-disable-next-line @typescript-eslint/return-await
|
|
552
|
+
return this.validateAndConvert(bm, this.cfg.bmSchema, db_model_1.DBModelType.BM, opt);
|
|
552
553
|
}
|
|
553
554
|
async dbmsToBM(dbms, opt = {}) {
|
|
554
555
|
return await (0, js_lib_1.pMap)(dbms, async (dbm) => await this.dbmToBM(dbm, opt));
|
|
@@ -565,7 +566,8 @@ class CommonDao {
|
|
|
565
566
|
// BM > DBM
|
|
566
567
|
const dbm = { ...(await this.cfg.hooks.beforeBMToDBM(bm)) };
|
|
567
568
|
// Validate/convert DBM
|
|
568
|
-
return
|
|
569
|
+
// eslint-disable-next-line @typescript-eslint/return-await
|
|
570
|
+
return this.validateAndConvert(dbm, this.cfg.dbmSchema, db_model_1.DBModelType.DBM, opt);
|
|
569
571
|
}
|
|
570
572
|
async bmsToDBM(bms, opt = {}) {
|
|
571
573
|
// try/catch?
|
|
@@ -47,7 +47,7 @@ export interface CommonDaoCfg<BM extends Partial<ObjectWithId>, DBM extends Obje
|
|
|
47
47
|
dbmSchema?: ObjectSchemaTyped<DBM> | AjvSchema<DBM>;
|
|
48
48
|
bmSchema?: ObjectSchemaTyped<BM> | AjvSchema<BM>;
|
|
49
49
|
tmSchema?: ObjectSchemaTyped<TM> | AjvSchema<TM>;
|
|
50
|
-
excludeFromIndexes?:
|
|
50
|
+
excludeFromIndexes?: (keyof DBM)[];
|
|
51
51
|
/**
|
|
52
52
|
* @default to false
|
|
53
53
|
* Set to true to limit DB writing (will throw an error is such case).
|
|
@@ -116,7 +116,7 @@ export interface CommonDaoOptions extends CommonDBOptions {
|
|
|
116
116
|
/**
|
|
117
117
|
* All properties default to undefined.
|
|
118
118
|
*/
|
|
119
|
-
export interface CommonDaoSaveOptions extends CommonDaoOptions, CommonDBSaveOptions {
|
|
119
|
+
export interface CommonDaoSaveOptions<DBM extends ObjectWithId> extends CommonDaoOptions, CommonDBSaveOptions<DBM> {
|
|
120
120
|
/**
|
|
121
121
|
* @default false
|
|
122
122
|
*
|
package/dist/db.model.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AnyObject } from '@naturalcycles/js-lib';
|
|
2
2
|
import { CommonDB } from './common.db';
|
|
3
3
|
export interface CommonDBOptions {
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* All properties default to undefined.
|
|
7
7
|
*/
|
|
8
|
-
export interface CommonDBSaveOptions extends CommonDBOptions {
|
|
9
|
-
excludeFromIndexes?:
|
|
8
|
+
export interface CommonDBSaveOptions<ROW extends ObjectWithId = AnyObjectWithId> extends CommonDBOptions {
|
|
9
|
+
excludeFromIndexes?: (keyof ROW)[];
|
|
10
10
|
}
|
|
11
11
|
export declare type CommonDBStreamOptions = CommonDBOptions;
|
|
12
12
|
export interface CommonDBCreateOptions extends CommonDBOptions {
|
|
@@ -21,7 +21,7 @@ export interface RunQueryResult<T> {
|
|
|
21
21
|
endCursor?: string;
|
|
22
22
|
}
|
|
23
23
|
export declare type DBOperation = DBSaveBatchOperation | DBDeleteByIdsOperation;
|
|
24
|
-
export interface DBSaveBatchOperation<ROW extends ObjectWithId =
|
|
24
|
+
export interface DBSaveBatchOperation<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
25
25
|
type: 'saveBatch';
|
|
26
26
|
table: string;
|
|
27
27
|
rows: ROW[];
|
|
@@ -47,28 +47,11 @@ export interface CreatedUpdated {
|
|
|
47
47
|
export interface CreatedUpdatedId extends CreatedUpdated {
|
|
48
48
|
id: string;
|
|
49
49
|
}
|
|
50
|
-
export interface CreatedUpdatedVer {
|
|
51
|
-
created: number;
|
|
52
|
-
updated: number;
|
|
53
|
-
_ver?: number;
|
|
54
|
-
}
|
|
55
50
|
export interface ObjectWithId {
|
|
56
51
|
id: string;
|
|
57
52
|
}
|
|
58
|
-
export interface
|
|
59
|
-
id?: string;
|
|
60
|
-
created?: number;
|
|
61
|
-
updated?: number;
|
|
62
|
-
}
|
|
63
|
-
export interface SavedDBEntity {
|
|
64
|
-
id: string;
|
|
65
|
-
created: number;
|
|
66
|
-
updated: number;
|
|
53
|
+
export interface AnyObjectWithId extends AnyObject, ObjectWithId {
|
|
67
54
|
}
|
|
68
|
-
export declare type Saved<E> = Merge<E, SavedDBEntity>;
|
|
69
|
-
export declare type Unsaved<E> = Merge<E, BaseDBEntity>;
|
|
70
|
-
export declare const baseDBEntitySchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<BaseDBEntity, BaseDBEntity>;
|
|
71
|
-
export declare const savedDBEntitySchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<SavedDBEntity, SavedDBEntity>;
|
|
72
55
|
/**
|
|
73
56
|
* Interface for a module (lib) that implements CommonDB.
|
|
74
57
|
*
|
package/dist/db.model.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
3
|
+
exports.DBModelType = exports.DBRelation = void 0;
|
|
5
4
|
var DBRelation;
|
|
6
5
|
(function (DBRelation) {
|
|
7
6
|
DBRelation["ONE_TO_ONE"] = "ONE_TO_ONE";
|
|
@@ -13,15 +12,3 @@ var DBModelType;
|
|
|
13
12
|
DBModelType["BM"] = "BM";
|
|
14
13
|
DBModelType["TM"] = "TM";
|
|
15
14
|
})(DBModelType = exports.DBModelType || (exports.DBModelType = {}));
|
|
16
|
-
exports.baseDBEntitySchema = (0, nodejs_lib_1.objectSchema)({
|
|
17
|
-
id: nodejs_lib_1.stringSchema.optional(),
|
|
18
|
-
created: nodejs_lib_1.unixTimestampSchema.optional(),
|
|
19
|
-
updated: nodejs_lib_1.unixTimestampSchema.optional(),
|
|
20
|
-
// _ver: verSchema.optional(),
|
|
21
|
-
});
|
|
22
|
-
exports.savedDBEntitySchema = (0, nodejs_lib_1.objectSchema)({
|
|
23
|
-
id: nodejs_lib_1.stringSchema,
|
|
24
|
-
created: nodejs_lib_1.unixTimestampSchema,
|
|
25
|
-
updated: nodejs_lib_1.unixTimestampSchema,
|
|
26
|
-
// _ver: verSchema.optional(),
|
|
27
|
-
});
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { DBLibError } from './cnst';
|
|
|
6
6
|
import { CommonDB } from './common.db';
|
|
7
7
|
import { CommonDao } from './commondao/common.dao';
|
|
8
8
|
import { CommonDaoAnonymizeHook, CommonDaoBeforeBMToDBMHook, CommonDaoBeforeBMToTMHook, CommonDaoBeforeCreateHook, CommonDaoBeforeDBMToBMHook, CommonDaoBeforeDBMValidateHook, CommonDaoBeforeTMToBMHook, CommonDaoCfg, CommonDaoCreateIdHook, CommonDaoCreateOptions, CommonDaoLogLevel, CommonDaoOptions, CommonDaoParseNaturalIdHook, CommonDaoSaveOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from './commondao/common.dao.model';
|
|
9
|
-
import {
|
|
9
|
+
import { AnyObjectWithId, CommonDBAdapter, CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, CreatedUpdated, CreatedUpdatedId, DBDeleteByIdsOperation, DBModelType, DBOperation, DBRelation, DBSaveBatchOperation, ObjectWithId, RunQueryResult } from './db.model';
|
|
10
10
|
import { getDB } from './getDB';
|
|
11
11
|
import { CommonKeyValueDao, CommonKeyValueDaoCfg } from './kv/commonKeyValueDao';
|
|
12
12
|
import { CommonKeyValueDB, KeyValueDBTuple } from './kv/commonKeyValueDB';
|
|
@@ -17,5 +17,5 @@ import { dbPipelineRestore, DBPipelineRestoreOptions } from './pipeline/dbPipeli
|
|
|
17
17
|
import { DBQuery, DBQueryFilter, DBQueryFilterOperator, dbQueryFilterOperatorValues, DBQueryOrder, RunnableDBQuery } from './query/dbQuery';
|
|
18
18
|
import { DBTransaction, RunnableDBTransaction } from './transaction/dbTransaction';
|
|
19
19
|
import { commitDBTransactionSimple, mergeDBOperations } from './transaction/dbTransaction.util';
|
|
20
|
-
export type { DBQueryFilterOperator, DBQueryFilter, DBQueryOrder, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoSaveOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBCreateOptions, CommonDB, RunQueryResult, CreatedUpdated, CreatedUpdatedId,
|
|
21
|
-
export { DBQuery, dbQueryFilterOperatorValues, RunnableDBQuery, CommonDaoLogLevel, DBRelation, DBModelType,
|
|
20
|
+
export type { DBQueryFilterOperator, DBQueryFilter, DBQueryOrder, CommonDaoCreateOptions, CommonDaoOptions, CommonDaoSaveOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, CommonDBCreateOptions, CommonDB, RunQueryResult, CreatedUpdated, CreatedUpdatedId, AnyObjectWithId, ObjectWithId, CommonDaoCfg, CommonDaoCreateIdHook, CommonDaoParseNaturalIdHook, CommonDaoBeforeCreateHook, CommonDaoBeforeDBMValidateHook, CommonDaoBeforeDBMToBMHook, CommonDaoBeforeBMToDBMHook, CommonDaoBeforeTMToBMHook, CommonDaoBeforeBMToTMHook, CommonDaoAnonymizeHook, InMemoryDBCfg, InMemoryKeyValueDBCfg, DBPipelineBackupOptions, DBPipelineRestoreOptions, DBPipelineCopyOptions, CommonDBAdapter, DBOperation, DBSaveBatchOperation, DBDeleteByIdsOperation, CommonKeyValueDB, CommonKeyValueDaoCfg, KeyValueDBTuple, };
|
|
21
|
+
export { DBQuery, dbQueryFilterOperatorValues, RunnableDBQuery, CommonDaoLogLevel, DBRelation, DBModelType, CommonDao, createdUpdatedFields, createdUpdatedIdFields, idField, InMemoryDB, InMemoryKeyValueDB, queryInMemory, serializeJsonField, deserializeJsonField, dbPipelineBackup, dbPipelineRestore, dbPipelineCopy, getDB, DBLibError, BaseCommonDB, DBTransaction, RunnableDBTransaction, mergeDBOperations, commitDBTransactionSimple, CommonKeyValueDao, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommonKeyValueDao = exports.commitDBTransactionSimple = exports.mergeDBOperations = exports.RunnableDBTransaction = exports.DBTransaction = exports.BaseCommonDB = exports.DBLibError = exports.getDB = exports.dbPipelineCopy = exports.dbPipelineRestore = exports.dbPipelineBackup = exports.deserializeJsonField = exports.serializeJsonField = exports.queryInMemory = exports.InMemoryKeyValueDB = exports.InMemoryDB = exports.idField = exports.createdUpdatedIdFields = exports.createdUpdatedFields = exports.CommonDao = exports.
|
|
3
|
+
exports.CommonKeyValueDao = exports.commitDBTransactionSimple = exports.mergeDBOperations = exports.RunnableDBTransaction = exports.DBTransaction = exports.BaseCommonDB = exports.DBLibError = exports.getDB = exports.dbPipelineCopy = exports.dbPipelineRestore = exports.dbPipelineBackup = exports.deserializeJsonField = exports.serializeJsonField = exports.queryInMemory = exports.InMemoryKeyValueDB = exports.InMemoryDB = exports.idField = exports.createdUpdatedIdFields = exports.createdUpdatedFields = exports.CommonDao = exports.DBModelType = exports.DBRelation = exports.CommonDaoLogLevel = exports.RunnableDBQuery = exports.dbQueryFilterOperatorValues = exports.DBQuery = void 0;
|
|
4
4
|
const inMemory_db_1 = require("./adapter/inmemory/inMemory.db");
|
|
5
5
|
Object.defineProperty(exports, "InMemoryDB", { enumerable: true, get: function () { return inMemory_db_1.InMemoryDB; } });
|
|
6
6
|
const inMemoryKeyValueDB_1 = require("./adapter/inmemory/inMemoryKeyValueDB");
|
|
@@ -16,10 +16,8 @@ Object.defineProperty(exports, "CommonDao", { enumerable: true, get: function ()
|
|
|
16
16
|
const common_dao_model_1 = require("./commondao/common.dao.model");
|
|
17
17
|
Object.defineProperty(exports, "CommonDaoLogLevel", { enumerable: true, get: function () { return common_dao_model_1.CommonDaoLogLevel; } });
|
|
18
18
|
const db_model_1 = require("./db.model");
|
|
19
|
-
Object.defineProperty(exports, "baseDBEntitySchema", { enumerable: true, get: function () { return db_model_1.baseDBEntitySchema; } });
|
|
20
19
|
Object.defineProperty(exports, "DBModelType", { enumerable: true, get: function () { return db_model_1.DBModelType; } });
|
|
21
20
|
Object.defineProperty(exports, "DBRelation", { enumerable: true, get: function () { return db_model_1.DBRelation; } });
|
|
22
|
-
Object.defineProperty(exports, "savedDBEntitySchema", { enumerable: true, get: function () { return db_model_1.savedDBEntitySchema; } });
|
|
23
21
|
const getDB_1 = require("./getDB");
|
|
24
22
|
Object.defineProperty(exports, "getDB", { enumerable: true, get: function () { return getDB_1.getDB; } });
|
|
25
23
|
const commonKeyValueDao_1 = require("./kv/commonKeyValueDao");
|
package/dist/query/dbQuery.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AsyncMapper } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AsyncMapper, Saved } 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';
|
|
5
|
-
import { ObjectWithId, RunQueryResult
|
|
5
|
+
import { AnyObjectWithId, ObjectWithId, RunQueryResult } from '../db.model';
|
|
6
6
|
/**
|
|
7
7
|
* Modeled after Firestore operators (WhereFilterOp type)
|
|
8
8
|
*
|
|
@@ -24,13 +24,13 @@ import { ObjectWithId, RunQueryResult, Saved } from '../db.model';
|
|
|
24
24
|
*/
|
|
25
25
|
export declare type DBQueryFilterOperator = '<' | '<=' | '==' | '>=' | '>' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';
|
|
26
26
|
export declare const dbQueryFilterOperatorValues: string[];
|
|
27
|
-
export interface DBQueryFilter {
|
|
28
|
-
name:
|
|
27
|
+
export interface DBQueryFilter<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
28
|
+
name: keyof ROW;
|
|
29
29
|
op: DBQueryFilterOperator;
|
|
30
30
|
val: any;
|
|
31
31
|
}
|
|
32
|
-
export interface DBQueryOrder {
|
|
33
|
-
name:
|
|
32
|
+
export interface DBQueryOrder<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
33
|
+
name: keyof ROW;
|
|
34
34
|
descending?: boolean;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
@@ -43,33 +43,33 @@ export interface DBQueryOrder {
|
|
|
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 ObjectWithId> {
|
|
46
|
+
export declare class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
47
47
|
table: string;
|
|
48
48
|
constructor(table: string);
|
|
49
49
|
/**
|
|
50
50
|
* Convenience method.
|
|
51
51
|
*/
|
|
52
|
-
static create<ROW extends ObjectWithId =
|
|
53
|
-
static fromPlainObject<ROW extends ObjectWithId =
|
|
52
|
+
static create<ROW extends ObjectWithId = AnyObjectWithId>(table: string): DBQuery<ROW>;
|
|
53
|
+
static fromPlainObject<ROW extends ObjectWithId = AnyObjectWithId>(obj: Partial<DBQuery<ROW>> & {
|
|
54
54
|
table: string;
|
|
55
55
|
}): DBQuery<ROW>;
|
|
56
|
-
_filters: DBQueryFilter[];
|
|
56
|
+
_filters: DBQueryFilter<ROW>[];
|
|
57
57
|
_limitValue: number;
|
|
58
58
|
_offsetValue: number;
|
|
59
|
-
_orders: DBQueryOrder[];
|
|
59
|
+
_orders: DBQueryOrder<ROW>[];
|
|
60
60
|
_startCursor?: string;
|
|
61
61
|
_endCursor?: string;
|
|
62
62
|
/**
|
|
63
63
|
* If defined - only those fields will be selected.
|
|
64
64
|
* In undefined - all fields (*) will be returned.
|
|
65
65
|
*/
|
|
66
|
-
_selectedFieldNames?:
|
|
67
|
-
filter(name:
|
|
68
|
-
filterEq(name:
|
|
66
|
+
_selectedFieldNames?: (keyof ROW)[];
|
|
67
|
+
filter(name: keyof ROW, op: DBQueryFilterOperator, val: any): this;
|
|
68
|
+
filterEq(name: keyof ROW, val: any): this;
|
|
69
69
|
limit(limit: number): this;
|
|
70
70
|
offset(offset: number): this;
|
|
71
|
-
order(name:
|
|
72
|
-
select(fieldNames:
|
|
71
|
+
order(name: keyof ROW, descending?: boolean): this;
|
|
72
|
+
select(fieldNames: (keyof ROW)[]): this;
|
|
73
73
|
startCursor(startCursor?: string): this;
|
|
74
74
|
endCursor(endCursor?: string): this;
|
|
75
75
|
clone(): DBQuery<ROW>;
|
package/dist/query/dbQuery.js
CHANGED
|
@@ -13,17 +13,6 @@ exports.dbQueryFilterOperatorValues = [
|
|
|
13
13
|
'array-contains',
|
|
14
14
|
'array-contains-any',
|
|
15
15
|
];
|
|
16
|
-
// export interface DBQueryData {
|
|
17
|
-
// _filters: DBQueryFilter[]
|
|
18
|
-
// _limitValue: number
|
|
19
|
-
// _orders: DBQueryOrder[]
|
|
20
|
-
//
|
|
21
|
-
// /**
|
|
22
|
-
// * If defined - only those fields will be selected.
|
|
23
|
-
// * In undefined - all fields (*) will be returned.
|
|
24
|
-
// */
|
|
25
|
-
// _selectedFieldNames?: string[]
|
|
26
|
-
// }
|
|
27
16
|
/**
|
|
28
17
|
* Lowest Common Denominator Query object.
|
|
29
18
|
* To be executed by CommonDao / CommonDB.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { JsonSchemaObject } from '@naturalcycles/js-lib';
|
|
3
|
-
import { BaseDBEntity, Saved } from '../db.model';
|
|
2
|
+
import { JsonSchemaObject, BaseDBEntity, Saved } from '@naturalcycles/js-lib';
|
|
4
3
|
export declare const TEST_TABLE = "TEST_TABLE";
|
|
5
4
|
export interface TestItemBM extends BaseDBEntity {
|
|
6
5
|
k1: string;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getTestItemSchema = exports.createTestItemsBM = exports.createTestItemsDBM = exports.createTestItemBM = exports.createTestItemDBM = exports.testItemDBMJsonSchema = exports.testItemBMJsonSchema = exports.testItemTMSchema = exports.testItemDBMSchema = exports.testItemBMSchema = exports.TEST_TABLE = void 0;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
|
-
const db_model_1 = require("../db.model");
|
|
7
6
|
const MOCK_TS_2018_06_21 = 1529539200;
|
|
8
7
|
exports.TEST_TABLE = 'TEST_TABLE';
|
|
9
8
|
exports.testItemBMSchema = (0, nodejs_lib_1.objectSchema)({
|
|
@@ -12,14 +11,14 @@ exports.testItemBMSchema = (0, nodejs_lib_1.objectSchema)({
|
|
|
12
11
|
k3: nodejs_lib_1.numberSchema.optional(),
|
|
13
12
|
even: nodejs_lib_1.booleanSchema.optional(),
|
|
14
13
|
b1: nodejs_lib_1.binarySchema.optional(),
|
|
15
|
-
}).concat(
|
|
14
|
+
}).concat(nodejs_lib_1.baseDBEntitySchema);
|
|
16
15
|
exports.testItemDBMSchema = (0, nodejs_lib_1.objectSchema)({
|
|
17
16
|
k1: nodejs_lib_1.stringSchema,
|
|
18
17
|
k2: nodejs_lib_1.stringSchema.optional(),
|
|
19
18
|
k3: nodejs_lib_1.numberSchema.optional(),
|
|
20
19
|
even: nodejs_lib_1.booleanSchema.optional(),
|
|
21
20
|
b1: nodejs_lib_1.binarySchema.optional(),
|
|
22
|
-
}).concat(
|
|
21
|
+
}).concat(nodejs_lib_1.savedDBEntitySchema);
|
|
23
22
|
exports.testItemTMSchema = (0, nodejs_lib_1.objectSchema)({
|
|
24
23
|
k1: nodejs_lib_1.stringSchema,
|
|
25
24
|
even: nodejs_lib_1.booleanSchema.optional(),
|
|
@@ -66,7 +66,7 @@ class CommonTimeSeriesDao {
|
|
|
66
66
|
dbq.filter('ts', '>=', q.fromIncl);
|
|
67
67
|
if (q.toExcl)
|
|
68
68
|
dbq.filter('ts', '<', q.toExcl);
|
|
69
|
-
const
|
|
69
|
+
const rows = (await this.cfg.db.runQuery(dbq)).rows;
|
|
70
70
|
// todo: query from aggregated tables when step is above 'hour'
|
|
71
71
|
return rows
|
|
72
72
|
.filter(r => r.v !== null && r.v !== undefined) // can be 0
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { CommonDB } from '../common.db';
|
|
2
|
-
import type { CommonDBSaveOptions, DBOperation, ObjectWithId } from '../db.model';
|
|
2
|
+
import type { AnyObjectWithId, CommonDBSaveOptions, DBOperation, ObjectWithId } from '../db.model';
|
|
3
3
|
/**
|
|
4
4
|
* Convenience class that stores the list of DBOperations and provides a fluent API to add them.
|
|
5
5
|
*/
|
|
6
6
|
export declare class DBTransaction {
|
|
7
7
|
ops: DBOperation[];
|
|
8
|
-
saveBatch<ROW extends ObjectWithId =
|
|
8
|
+
saveBatch<ROW extends ObjectWithId = AnyObjectWithId>(table: string, rows: ROW[]): this;
|
|
9
9
|
deleteByIds(table: string, ids: string[]): this;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
@@ -15,5 +15,5 @@ export declare class DBTransaction {
|
|
|
15
15
|
export declare class RunnableDBTransaction extends DBTransaction {
|
|
16
16
|
db: CommonDB;
|
|
17
17
|
constructor(db: CommonDB);
|
|
18
|
-
commit(opt?: CommonDBSaveOptions): Promise<void>;
|
|
18
|
+
commit<ROW extends ObjectWithId>(opt?: CommonDBSaveOptions<ROW>): Promise<void>;
|
|
19
19
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CommonDBOptions, CommonDBSaveOptions } from '../db.model';
|
|
2
2
|
import { DBQuery, DBQueryFilter, DBQueryOrder } from '../query/dbQuery';
|
|
3
3
|
export declare const commonDBOptionsSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<CommonDBOptions, CommonDBOptions>;
|
|
4
|
-
export declare const commonDBSaveOptionsSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<CommonDBSaveOptions
|
|
4
|
+
export declare const commonDBSaveOptionsSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<CommonDBSaveOptions<import("../db.model").AnyObjectWithId>, CommonDBSaveOptions<import("../db.model").AnyObjectWithId>>;
|
|
5
5
|
export declare const dbQueryFilterOperatorSchema: import("@naturalcycles/nodejs-lib/dist/validation/joi/string.extensions").ExtendedStringSchema;
|
|
6
|
-
export declare const dbQueryFilterSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQueryFilter
|
|
7
|
-
export declare const dbQueryOrderSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQueryOrder
|
|
6
|
+
export declare const dbQueryFilterSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQueryFilter<import("../db.model").AnyObjectWithId>, DBQueryFilter<import("../db.model").AnyObjectWithId>>;
|
|
7
|
+
export declare const dbQueryOrderSchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQueryOrder<import("../db.model").AnyObjectWithId>, DBQueryOrder<import("../db.model").AnyObjectWithId>>;
|
|
8
8
|
export declare const dbQuerySchema: import("@naturalcycles/nodejs-lib").ObjectSchemaTyped<DBQuery<any>, DBQuery<any>>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { CommonDB } from '../../common.db'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CommonDBCreateOptions,
|
|
4
|
+
CommonDBSaveOptions,
|
|
5
|
+
CommonDBStreamOptions,
|
|
6
|
+
ObjectWithId,
|
|
7
|
+
} from '../../db.model'
|
|
3
8
|
|
|
4
9
|
export interface CacheDBCfg {
|
|
5
10
|
name: string
|
|
@@ -39,7 +44,7 @@ export interface CacheDBCfg {
|
|
|
39
44
|
logDownstream?: boolean
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
export interface CacheDBOptions extends CommonDBSaveOptions {
|
|
47
|
+
export interface CacheDBOptions<ROW extends ObjectWithId> extends CommonDBSaveOptions<ROW> {
|
|
43
48
|
/**
|
|
44
49
|
* @default false
|
|
45
50
|
*/
|
|
@@ -51,5 +56,9 @@ export interface CacheDBOptions extends CommonDBSaveOptions {
|
|
|
51
56
|
onlyCache?: boolean
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
export interface CacheDBStreamOptions extends
|
|
55
|
-
|
|
59
|
+
export interface CacheDBStreamOptions<ROW extends ObjectWithId>
|
|
60
|
+
extends CacheDBOptions<ROW>,
|
|
61
|
+
CommonDBStreamOptions {}
|
|
62
|
+
export interface CacheDBCreateOptions<ROW extends ObjectWithId>
|
|
63
|
+
extends CacheDBOptions<ROW>,
|
|
64
|
+
CommonDBCreateOptions {}
|