@naturalcycles/db-lib 9.2.1 → 9.3.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/dist/adapter/cachedb/cache.db.d.ts +11 -12
- 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 +2 -2
- package/dist/adapter/file/localFile.persistence.plugin.d.ts +3 -3
- package/dist/adapter/file/noop.persistence.plugin.d.ts +2 -2
- 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 +24 -25
- package/dist/commondao/common.dao.js +10 -10
- package/dist/commondao/common.dao.model.d.ts +13 -13
- package/dist/db.model.d.ts +4 -4
- package/dist/query/dbQuery.d.ts +9 -9
- package/dist/testing/test.model.d.ts +3 -4
- package/dist/testing/test.model.js +1 -1
- 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 +18 -16
- package/src/adapter/file/file.db.model.ts +2 -2
- package/src/adapter/file/file.db.ts +17 -15
- package/src/adapter/file/localFile.persistence.plugin.ts +4 -4
- package/src/adapter/file/noop.persistence.plugin.ts +2 -2
- package/src/adapter/inmemory/inMemory.db.ts +20 -18
- package/src/adapter/inmemory/queryInMemory.ts +5 -2
- package/src/base.common.db.ts +20 -10
- package/src/common.db.ts +20 -13
- package/src/commondao/common.dao.model.ts +21 -15
- package/src/commondao/common.dao.ts +68 -66
- package/src/db.model.ts +4 -4
- package/src/query/dbQuery.ts +13 -11
- package/src/testing/test.model.ts +4 -6
- package/src/transaction/dbTransaction.util.ts +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { JsonSchemaObject, JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib';
|
|
1
|
+
import { JsonSchemaObject, JsonSchemaRootObject, PartialObjectWithId, Saved } from '@naturalcycles/js-lib';
|
|
2
|
+
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
4
3
|
import { BaseCommonDB } from '../../base.common.db';
|
|
5
4
|
import { CommonDB, CommonDBSupport } from '../../common.db';
|
|
6
5
|
import { DBPatch, RunQueryResult } from '../../db.model';
|
|
@@ -21,13 +20,13 @@ export declare class CacheDB extends BaseCommonDB implements CommonDB {
|
|
|
21
20
|
* Resets InMemory DB data
|
|
22
21
|
*/
|
|
23
22
|
getTables(): Promise<string[]>;
|
|
24
|
-
getTableSchema<ROW extends
|
|
25
|
-
createTable<ROW extends
|
|
26
|
-
getByIds<ROW extends
|
|
27
|
-
saveBatch<ROW extends
|
|
28
|
-
runQuery<ROW extends
|
|
29
|
-
runQueryCount<ROW extends
|
|
30
|
-
streamQuery<ROW extends
|
|
31
|
-
deleteByQuery<ROW extends
|
|
32
|
-
updateByQuery<ROW extends
|
|
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>;
|
|
33
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonLogger,
|
|
1
|
+
import { CommonLogger, PartialObjectWithId } 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 PartialObjectWithId> 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, Saved, PartialObjectWithId } 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 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>;
|
|
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 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[];
|
|
36
36
|
private logStarted;
|
|
37
37
|
private logFinished;
|
|
38
38
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CommonLogger,
|
|
1
|
+
import { CommonLogger, PartialObjectWithId, Saved } 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 PartialObjectWithId>(table: string) => Promise<Saved<ROW>[]>;
|
|
8
8
|
saveFiles: (ops: DBSaveBatchOperation<any>[]) => Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
export interface FileDBCfg {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PartialObjectWithId, Saved } 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
|
|
22
|
+
loadFile<ROW extends PartialObjectWithId>(table: string): Promise<Saved<ROW>[]>;
|
|
23
23
|
saveFiles(ops: DBSaveBatchOperation[]): Promise<void>;
|
|
24
|
-
saveFile<ROW extends
|
|
24
|
+
saveFile<ROW extends PartialObjectWithId>(table: string, rows: ROW[]): Promise<void>;
|
|
25
25
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PartialObjectWithId, Saved } 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
|
|
7
|
+
loadFile<ROW extends PartialObjectWithId>(_table: string): Promise<Saved<ROW>[]>;
|
|
8
8
|
saveFiles(_ops: DBSaveBatchOperation[]): Promise<void>;
|
|
9
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchemaObject, StringMap, JsonSchemaRootObject, ObjectWithId, CommonLogger } from '@naturalcycles/js-lib';
|
|
1
|
+
import { JsonSchemaObject, StringMap, JsonSchemaRootObject, ObjectWithId, CommonLogger, PartialObjectWithId, Saved } 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 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>;
|
|
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 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>>;
|
|
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 PartialObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
|
|
108
|
+
saveBatch<ROW extends PartialObjectWithId>(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 { PartialObjectWithId } 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 PartialObjectWithId>(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, PartialObjectWithId, Saved } 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 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>>;
|
|
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, PartialObjectWithId, Saved } 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 PartialObjectWithId>(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 PartialObjectWithId>(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 PartialObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions) => Promise<Saved<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 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>>;
|
|
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 PartialObjectWithId>(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 PartialObjectWithId>(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 PartialObjectWithId>(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, CommonLogger, JsonSchemaObject, JsonSchemaRootObject,
|
|
3
|
+
import { AnyObject, AsyncMapper, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, PartialObjectWithId, Saved, UnixTimestampMillisNumber, 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 PartialObjectWithId, DBM extends PartialObjectWithId = 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>;
|
|
19
19
|
getById(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
20
20
|
getById(id?: string | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
|
|
21
21
|
getByIdOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<Saved<BM>>;
|
|
22
|
-
getByIdAsDBMOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<DBM
|
|
22
|
+
getByIdAsDBMOrEmpty(id: string, part?: Partial<BM>, opt?: CommonDaoOptions): Promise<Saved<DBM>>;
|
|
23
23
|
getByIdAsDBM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
24
|
-
getByIdAsDBM(id?: string | null, opt?: CommonDaoOptions): Promise<DBM | null>;
|
|
24
|
+
getByIdAsDBM(id?: string | null, opt?: CommonDaoOptions): Promise<Saved<DBM> | null>;
|
|
25
25
|
getByIdAsTM(id: undefined | null, opt?: CommonDaoOptions): Promise<null>;
|
|
26
26
|
getByIdAsTM(id?: string | null, opt?: CommonDaoOptions): Promise<TM | null>;
|
|
27
27
|
getByIds(ids: string[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
|
|
28
|
-
getByIdsAsDBM(ids: string[], opt?: CommonDaoOptions): Promise<DBM[]>;
|
|
28
|
+
getByIdsAsDBM(ids: string[], opt?: CommonDaoOptions): Promise<Saved<DBM>[]>;
|
|
29
29
|
requireById(id: string, opt?: CommonDaoOptions): Promise<Saved<BM>>;
|
|
30
|
-
requireByIdAsDBM(id: string, opt?: CommonDaoOptions): Promise<DBM
|
|
30
|
+
requireByIdAsDBM(id: string, opt?: CommonDaoOptions): Promise<Saved<DBM>>;
|
|
31
31
|
private throwRequiredError;
|
|
32
32
|
/**
|
|
33
33
|
* Throws if readOnly is true
|
|
@@ -54,8 +54,8 @@ export declare class CommonDao<BM extends Partial<ObjectWithId>, DBM extends Obj
|
|
|
54
54
|
*/
|
|
55
55
|
runUnionQueries(queries: DBQuery<DBM>[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
|
|
56
56
|
runQueryExtended(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<BM>>>;
|
|
57
|
-
runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<DBM[]>;
|
|
58
|
-
runQueryExtendedAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<DBM
|
|
57
|
+
runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<Saved<DBM>[]>;
|
|
58
|
+
runQueryExtendedAsDBM(q: DBQuery<DBM>, opt?: CommonDaoOptions): Promise<RunQueryResult<Saved<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>;
|
|
@@ -82,13 +82,12 @@ export declare class CommonDao<BM extends Partial<ObjectWithId>, DBM extends Obj
|
|
|
82
82
|
* Mutates!
|
|
83
83
|
* "Returns", just to have a type of "Saved"
|
|
84
84
|
*/
|
|
85
|
-
assignIdCreatedUpdated(obj: DBM
|
|
86
|
-
assignIdCreatedUpdated(obj: BM
|
|
87
|
-
assignIdCreatedUpdated(obj: Unsaved<BM>, opt?: CommonDaoOptions): Saved<BM>;
|
|
85
|
+
assignIdCreatedUpdated(obj: Partial<DBM>, opt?: CommonDaoOptions): Saved<Partial<DBM>>;
|
|
86
|
+
assignIdCreatedUpdated(obj: Partial<BM>, opt?: CommonDaoOptions): Saved<Partial<BM>>;
|
|
88
87
|
/**
|
|
89
88
|
* Mutates with id, created, updated
|
|
90
89
|
*/
|
|
91
|
-
save(bm:
|
|
90
|
+
save(bm: BM, opt?: CommonDaoSaveOptions<BM, DBM>): Promise<Saved<BM>>;
|
|
92
91
|
/**
|
|
93
92
|
* 1. Applies the patch
|
|
94
93
|
* 2. If object is the same after patching - skips saving it
|
|
@@ -115,9 +114,9 @@ export declare class CommonDao<BM extends Partial<ObjectWithId>, DBM extends Obj
|
|
|
115
114
|
* It still loads the row from the DB.
|
|
116
115
|
*/
|
|
117
116
|
patch(bm: Saved<BM>, patch: Partial<BM>, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
|
|
118
|
-
saveAsDBM(dbm: DBM, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<DBM
|
|
119
|
-
saveBatch(bms:
|
|
120
|
-
saveBatchAsDBM(dbms: DBM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<DBM[]>;
|
|
117
|
+
saveAsDBM(dbm: DBM, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<DBM>>;
|
|
118
|
+
saveBatch(bms: BM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>;
|
|
119
|
+
saveBatchAsDBM(dbms: DBM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<DBM>[]>;
|
|
121
120
|
/**
|
|
122
121
|
* "Streaming" is implemented by buffering incoming rows into **batches**
|
|
123
122
|
* (of size opt.batchSize, which defaults to 500),
|
|
@@ -141,18 +140,18 @@ export declare class CommonDao<BM extends Partial<ObjectWithId>, DBM extends Obj
|
|
|
141
140
|
updateByIds(ids: string[], patch: DBPatch<DBM>, opt?: CommonDaoOptions): Promise<number>;
|
|
142
141
|
updateByQuery(q: DBQuery<DBM>, patch: DBPatch<DBM>, opt?: CommonDaoOptions): Promise<number>;
|
|
143
142
|
dbmToBM(_dbm: undefined, opt?: CommonDaoOptions): Promise<undefined>;
|
|
144
|
-
dbmToBM(_dbm?: DBM
|
|
145
|
-
dbmsToBM(dbms: DBM[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
|
|
143
|
+
dbmToBM(_dbm?: Saved<DBM>, opt?: CommonDaoOptions): Promise<Saved<BM>>;
|
|
144
|
+
dbmsToBM(dbms: Saved<DBM>[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
|
|
146
145
|
/**
|
|
147
146
|
* Mutates object with properties: id, created, updated.
|
|
148
147
|
* Returns DBM (new reference).
|
|
149
148
|
*/
|
|
150
149
|
bmToDBM(bm: undefined, opt?: CommonDaoOptions): Promise<undefined>;
|
|
151
|
-
bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<DBM
|
|
152
|
-
bmsToDBM(bms: BM[], opt?: CommonDaoOptions): Promise<DBM[]>;
|
|
150
|
+
bmToDBM(bm?: BM, opt?: CommonDaoOptions): Promise<Saved<DBM>>;
|
|
151
|
+
bmsToDBM(bms: BM[], opt?: CommonDaoOptions): Promise<Saved<DBM>[]>;
|
|
153
152
|
anyToDBM(dbm: undefined, opt?: CommonDaoOptions): undefined;
|
|
154
|
-
anyToDBM(dbm?: any, opt?: CommonDaoOptions): DBM
|
|
155
|
-
anyToDBMs(entities: DBM[], opt?: CommonDaoOptions): DBM[];
|
|
153
|
+
anyToDBM(dbm?: any, opt?: CommonDaoOptions): Saved<DBM>;
|
|
154
|
+
anyToDBMs(entities: Saved<DBM>[], opt?: CommonDaoOptions): Saved<DBM>[];
|
|
156
155
|
bmToTM(bm: undefined, opt?: CommonDaoOptions): TM | undefined;
|
|
157
156
|
bmToTM(bm?: Saved<BM>, opt?: CommonDaoOptions): TM;
|
|
158
157
|
bmsToTM(bms: Saved<BM>[], opt?: CommonDaoOptions): TM[];
|
|
@@ -193,10 +192,10 @@ export declare class CommonDaoTransaction {
|
|
|
193
192
|
* Perform a graceful rollback without throwing/re-throwing any error.
|
|
194
193
|
*/
|
|
195
194
|
rollback(): Promise<void>;
|
|
196
|
-
getById<BM extends
|
|
197
|
-
getByIds<BM extends
|
|
198
|
-
save<BM extends
|
|
199
|
-
saveBatch<BM extends
|
|
195
|
+
getById<BM extends PartialObjectWithId, DBM extends PartialObjectWithId>(dao: CommonDao<BM, DBM, any>, id?: string | null, opt?: CommonDaoOptions): Promise<Saved<BM> | null>;
|
|
196
|
+
getByIds<BM extends PartialObjectWithId, DBM extends PartialObjectWithId>(dao: CommonDao<BM, DBM, any>, ids: string[], opt?: CommonDaoOptions): Promise<Saved<BM>[]>;
|
|
197
|
+
save<BM extends PartialObjectWithId, DBM extends PartialObjectWithId>(dao: CommonDao<BM, DBM, any>, bm: BM, opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>>;
|
|
198
|
+
saveBatch<BM extends PartialObjectWithId, DBM extends PartialObjectWithId>(dao: CommonDao<BM, DBM, any>, bms: BM[], opt?: CommonDaoSaveBatchOptions<DBM>): Promise<Saved<BM>[]>;
|
|
200
199
|
deleteById(dao: CommonDao<any>, id?: string | null, opt?: CommonDaoOptions): Promise<number>;
|
|
201
200
|
deleteByIds(dao: CommonDao<any>, ids: string[], opt?: CommonDaoOptions): Promise<number>;
|
|
202
201
|
}
|
|
@@ -26,8 +26,8 @@ class CommonDao {
|
|
|
26
26
|
logLevel: isGAE || isCI ? common_dao_model_1.CommonDaoLogLevel.NONE : common_dao_model_1.CommonDaoLogLevel.OPERATIONS,
|
|
27
27
|
createId: true,
|
|
28
28
|
assignGeneratedIds: false,
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
useCreatedProperty: true,
|
|
30
|
+
useUpdatedProperty: true,
|
|
31
31
|
logger: console,
|
|
32
32
|
...cfg,
|
|
33
33
|
hooks: {
|
|
@@ -447,7 +447,7 @@ class CommonDao {
|
|
|
447
447
|
const stream = this.cfg.db
|
|
448
448
|
.streamQuery(q.select(['id']), opt)
|
|
449
449
|
.on('error', err => stream.emit('error', err))
|
|
450
|
-
.pipe((0, nodejs_lib_1.transformMapSimple)(
|
|
450
|
+
.pipe((0, nodejs_lib_1.transformMapSimple)(r => r.id, {
|
|
451
451
|
errorMode: js_lib_1.ErrorMode.SUPPRESS, // cause .pipe() cannot propagate errors
|
|
452
452
|
}));
|
|
453
453
|
return stream;
|
|
@@ -460,9 +460,9 @@ class CommonDao {
|
|
|
460
460
|
let count = 0;
|
|
461
461
|
await (0, nodejs_lib_1._pipeline)([
|
|
462
462
|
this.cfg.db.streamQuery(q.select(['id']), opt),
|
|
463
|
-
(0, nodejs_lib_1.transformMapSimple)(
|
|
463
|
+
(0, nodejs_lib_1.transformMapSimple)(r => {
|
|
464
464
|
count++;
|
|
465
|
-
return
|
|
465
|
+
return r.id;
|
|
466
466
|
}),
|
|
467
467
|
(0, nodejs_lib_1.transformMap)(mapper, {
|
|
468
468
|
...opt,
|
|
@@ -481,11 +481,11 @@ class CommonDao {
|
|
|
481
481
|
}
|
|
482
482
|
assignIdCreatedUpdated(obj, opt = {}) {
|
|
483
483
|
const now = Math.floor(Date.now() / 1000);
|
|
484
|
-
if (this.cfg.
|
|
484
|
+
if (this.cfg.useCreatedProperty) {
|
|
485
485
|
;
|
|
486
486
|
obj['created'] ||= obj['updated'] || now;
|
|
487
487
|
}
|
|
488
|
-
if (this.cfg.
|
|
488
|
+
if (this.cfg.useUpdatedProperty) {
|
|
489
489
|
;
|
|
490
490
|
obj['updated'] =
|
|
491
491
|
opt.preserveUpdatedCreated && obj['updated'] ? obj['updated'] : now;
|
|
@@ -801,7 +801,7 @@ class CommonDao {
|
|
|
801
801
|
const { batchSize, batchConcurrency = 16 } = opt;
|
|
802
802
|
await (0, nodejs_lib_1._pipeline)([
|
|
803
803
|
this.cfg.db.streamQuery(q.select(['id']), opt),
|
|
804
|
-
(0, nodejs_lib_1.transformMapSimple)(
|
|
804
|
+
(0, nodejs_lib_1.transformMapSimple)(r => r.id, {
|
|
805
805
|
errorMode: js_lib_1.ErrorMode.SUPPRESS,
|
|
806
806
|
}),
|
|
807
807
|
(0, nodejs_lib_1.transformBuffer)({ batchSize }),
|
|
@@ -998,7 +998,7 @@ class CommonDao {
|
|
|
998
998
|
await fn(daoTx);
|
|
999
999
|
}
|
|
1000
1000
|
catch (err) {
|
|
1001
|
-
await daoTx.rollback();
|
|
1001
|
+
await daoTx.rollback(); // graceful rollback that "never throws"
|
|
1002
1002
|
throw err;
|
|
1003
1003
|
}
|
|
1004
1004
|
}, opt);
|
|
@@ -1088,7 +1088,7 @@ class CommonDaoTransaction {
|
|
|
1088
1088
|
return await dao.getByIds(ids, { ...opt, tx: this.tx });
|
|
1089
1089
|
}
|
|
1090
1090
|
// todo: Queries inside Transaction are not supported yet
|
|
1091
|
-
// async runQuery<BM extends
|
|
1091
|
+
// async runQuery<BM extends PartialObjectWithId, DBM extends ObjectWithId>(
|
|
1092
1092
|
// dao: CommonDao<BM, DBM, any>,
|
|
1093
1093
|
// q: DBQuery<DBM>,
|
|
1094
1094
|
// opt?: CommonDaoOptions,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CommonLogger, ErrorMode,
|
|
1
|
+
import { CommonLogger, ErrorMode, PartialObjectWithId, 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
|
|
5
|
+
export interface CommonDaoHooks<BM extends PartialObjectWithId, DBM extends PartialObjectWithId, 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 Partial<ObjectWithId>, DBM extends Ob
|
|
|
38
38
|
* as it only validates "final state", not intermediate
|
|
39
39
|
*/
|
|
40
40
|
beforeDBMValidate: (dbm: Partial<DBM>) => Partial<DBM>;
|
|
41
|
-
beforeDBMToBM: (dbm: DBM) => Partial<BM> | Promise<Partial<BM>>;
|
|
41
|
+
beforeDBMToBM: (dbm: Saved<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 Partial<ObjectWithId>, DBM extends Ob
|
|
|
53
53
|
*
|
|
54
54
|
* You can do validations as needed here and throw errors, they will be propagated.
|
|
55
55
|
*/
|
|
56
|
-
afterLoad?: (dbm: DBM) => Promisable<DBM | null>;
|
|
56
|
+
afterLoad?: (dbm: Saved<DBM>) => Promisable<Saved<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 Partial<ObjectWithId>, DBM extends Ob
|
|
|
67
67
|
*
|
|
68
68
|
* You can do validations as needed here and throw errors, they will be propagated.
|
|
69
69
|
*/
|
|
70
|
-
beforeSave?: (dbm: DBM) => Promisable<DBM | null>;
|
|
70
|
+
beforeSave?: (dbm: Saved<DBM>) => Promisable<Saved<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 Partial<ObjectWithId>, DBM extends Ob
|
|
|
77
77
|
* It still applies to BM "transitively", during dbmToBM
|
|
78
78
|
* (e.g after loaded from the Database).
|
|
79
79
|
*/
|
|
80
|
-
anonymize: (dbm: DBM) => DBM
|
|
80
|
+
anonymize: (dbm: Saved<DBM>) => Saved<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 PartialObjectWithId, DBM extends PartialObjectWithId = BM, TM = BM> {
|
|
108
108
|
db: CommonDB;
|
|
109
109
|
table: string;
|
|
110
110
|
/**
|
|
@@ -157,12 +157,12 @@ export interface CommonDaoCfg<BM extends Partial<ObjectWithId>, DBM extends Obje
|
|
|
157
157
|
* Defaults to true
|
|
158
158
|
* Set to false to disable `created` field management.
|
|
159
159
|
*/
|
|
160
|
-
|
|
160
|
+
useCreatedProperty?: boolean;
|
|
161
161
|
/**
|
|
162
162
|
* Defaults to true
|
|
163
163
|
* Set to false to disable `updated` field management.
|
|
164
164
|
*/
|
|
165
|
-
|
|
165
|
+
useUpdatedProperty?: boolean;
|
|
166
166
|
/**
|
|
167
167
|
* Default is false.
|
|
168
168
|
* If true - will run `_filterNullishValues` inside `validateAndConvert` function
|
|
@@ -223,7 +223,7 @@ export interface CommonDaoOptions extends CommonDBOptions {
|
|
|
223
223
|
*/
|
|
224
224
|
table?: string;
|
|
225
225
|
}
|
|
226
|
-
export interface CommonDaoSaveOptions<BM extends
|
|
226
|
+
export interface CommonDaoSaveOptions<BM extends PartialObjectWithId, DBM extends PartialObjectWithId> extends CommonDaoSaveBatchOptions<DBM> {
|
|
227
227
|
/**
|
|
228
228
|
* If provided - a check will be made.
|
|
229
229
|
* If the object for saving equals to the object passed to `skipIfEquals` - save operation will be skipped.
|
|
@@ -237,7 +237,7 @@ export interface CommonDaoSaveOptions<BM extends Partial<ObjectWithId>, DBM exte
|
|
|
237
237
|
/**
|
|
238
238
|
* All properties default to undefined.
|
|
239
239
|
*/
|
|
240
|
-
export interface CommonDaoSaveBatchOptions<DBM extends
|
|
240
|
+
export interface CommonDaoSaveBatchOptions<DBM extends PartialObjectWithId> extends CommonDaoOptions, CommonDBSaveOptions<DBM> {
|
|
241
241
|
/**
|
|
242
242
|
* @default false
|
|
243
243
|
*
|
|
@@ -249,9 +249,9 @@ export interface CommonDaoSaveBatchOptions<DBM extends ObjectWithId> extends Com
|
|
|
249
249
|
*/
|
|
250
250
|
ensureUniqueId?: boolean;
|
|
251
251
|
}
|
|
252
|
-
export interface CommonDaoStreamDeleteOptions<DBM extends
|
|
252
|
+
export interface CommonDaoStreamDeleteOptions<DBM extends PartialObjectWithId> extends CommonDaoStreamOptions<DBM> {
|
|
253
253
|
}
|
|
254
|
-
export interface CommonDaoStreamSaveOptions<DBM extends
|
|
254
|
+
export interface CommonDaoStreamSaveOptions<DBM extends PartialObjectWithId> extends CommonDaoSaveBatchOptions<DBM>, CommonDaoStreamOptions<DBM> {
|
|
255
255
|
}
|
|
256
256
|
export interface CommonDaoStreamForEachOptions<IN> extends CommonDaoStreamOptions<IN>, TransformMapOptions<IN, any> {
|
|
257
257
|
}
|
package/dist/db.model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PartialObjectWithId } 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
|
|
51
|
+
export interface CommonDBSaveOptions<ROW extends PartialObjectWithId = any> extends CommonDBOptions {
|
|
52
52
|
excludeFromIndexes?: (keyof ROW)[];
|
|
53
53
|
/**
|
|
54
54
|
* Default is `upsert`
|
|
@@ -76,7 +76,7 @@ export interface RunQueryResult<T> {
|
|
|
76
76
|
endCursor?: string;
|
|
77
77
|
}
|
|
78
78
|
export type DBOperation = DBSaveBatchOperation | DBDeleteByIdsOperation;
|
|
79
|
-
export interface DBSaveBatchOperation<ROW extends
|
|
79
|
+
export interface DBSaveBatchOperation<ROW extends PartialObjectWithId = any> {
|
|
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
|
|
112
|
+
export type DBPatch<ROW extends PartialObjectWithId> = Partial<Record<keyof ROW, ROW[keyof ROW] | DBIncrement>>;
|