@naturalcycles/db-lib 8.49.0 → 8.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/inmemory/queryInMemory.js +1 -3
- package/dist/commondao/common.dao.model.d.ts +11 -11
- package/dist/kv/commonKeyValueDao.d.ts +3 -3
- package/dist/pipeline/dbPipelineBackup.js +1 -3
- package/dist/pipeline/dbPipelineCopy.js +1 -3
- package/package.json +1 -1
- package/src/adapter/inmemory/queryInMemory.ts +1 -2
- package/src/commondao/common.dao.model.ts +11 -11
- package/src/kv/commonKeyValueDao.ts +3 -3
- package/src/pipeline/dbPipelineBackup.ts +1 -3
- package/src/pipeline/dbPipelineCopy.ts +1 -3
|
@@ -3,27 +3,27 @@ import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchemaTyped, T
|
|
|
3
3
|
import { CommonDB } from '../common.db';
|
|
4
4
|
import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model';
|
|
5
5
|
export interface CommonDaoHooks<BM extends Partial<ObjectWithId<ID>>, DBM extends ObjectWithId<ID>, TM, ID extends string | number> {
|
|
6
|
-
createRandomId
|
|
6
|
+
createRandomId(): ID;
|
|
7
7
|
/**
|
|
8
8
|
* createNaturalId hook is called (tried) first.
|
|
9
9
|
* If it doesn't exist - createRandomId is called.
|
|
10
10
|
*/
|
|
11
|
-
createNaturalId
|
|
12
|
-
parseNaturalId
|
|
13
|
-
beforeCreate
|
|
14
|
-
beforeDBMValidate
|
|
15
|
-
beforeDBMToBM
|
|
16
|
-
beforeBMToDBM
|
|
17
|
-
beforeTMToBM
|
|
18
|
-
beforeBMToTM
|
|
19
|
-
anonymize
|
|
11
|
+
createNaturalId(obj: DBM | BM): ID;
|
|
12
|
+
parseNaturalId(id: ID): Partial<DBM>;
|
|
13
|
+
beforeCreate(bm: Partial<BM>): Partial<BM>;
|
|
14
|
+
beforeDBMValidate(dbm: Partial<DBM>): Partial<DBM>;
|
|
15
|
+
beforeDBMToBM(dbm: DBM): Partial<BM> | Promise<Partial<BM>>;
|
|
16
|
+
beforeBMToDBM(bm: BM): Partial<DBM> | Promise<Partial<DBM>>;
|
|
17
|
+
beforeTMToBM(tm: TM): Partial<BM>;
|
|
18
|
+
beforeBMToTM(bm: BM): Partial<TM>;
|
|
19
|
+
anonymize(dbm: DBM): DBM;
|
|
20
20
|
/**
|
|
21
21
|
* If hook is defined - allows to prevent or modify the error thrown.
|
|
22
22
|
* Return `false` to prevent throwing an error.
|
|
23
23
|
* Return original `err` to pass the error through (will be thrown in CommonDao).
|
|
24
24
|
* Return modified/new `Error` if needed.
|
|
25
25
|
*/
|
|
26
|
-
onValidationError
|
|
26
|
+
onValidationError(err: JoiValidationError | AjvValidationError): Error | false;
|
|
27
27
|
}
|
|
28
28
|
export declare enum CommonDaoLogLevel {
|
|
29
29
|
/**
|
|
@@ -21,9 +21,9 @@ export interface CommonKeyValueDaoCfg<T> {
|
|
|
21
21
|
*/
|
|
22
22
|
logStarted?: boolean;
|
|
23
23
|
hooks?: {
|
|
24
|
-
mapValueToBuffer
|
|
25
|
-
mapBufferToValue
|
|
26
|
-
beforeCreate
|
|
24
|
+
mapValueToBuffer?(v: T): Promise<Buffer>;
|
|
25
|
+
mapBufferToValue?(b: Buffer): Promise<T>;
|
|
26
|
+
beforeCreate?(v: Partial<T>): Partial<T>;
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
29
|
* Set to `true` to conveniently enable zipping+JSON.stringify
|
|
@@ -24,9 +24,7 @@ async function dbPipelineBackup(opt) {
|
|
|
24
24
|
const sinceUpdatedStr = sinceUpdated ? ' since ' + (0, colors_1.grey)((0, js_lib_1.localTime)(sinceUpdated).toPretty()) : '';
|
|
25
25
|
console.log(`>> ${(0, colors_1.dimWhite)('dbPipelineBackup')} started in ${(0, colors_1.grey)(outputDirPath)}...${sinceUpdatedStr}`);
|
|
26
26
|
fs.ensureDirSync(outputDirPath);
|
|
27
|
-
|
|
28
|
-
tables = await db.getTables();
|
|
29
|
-
}
|
|
27
|
+
tables ||= await db.getTables();
|
|
30
28
|
console.log(`${(0, colors_1.yellow)(tables.length)} ${(0, colors_1.boldWhite)('table(s)')}:\n` + tables.join('\n'));
|
|
31
29
|
const statsPerTable = {};
|
|
32
30
|
await (0, js_lib_1.pMap)(tables, async (table) => {
|
|
@@ -16,9 +16,7 @@ async function dbPipelineCopy(opt) {
|
|
|
16
16
|
let { tables } = opt;
|
|
17
17
|
const sinceUpdatedStr = sinceUpdated ? ' since ' + (0, colors_1.grey)((0, js_lib_1.localTime)(sinceUpdated).toPretty()) : '';
|
|
18
18
|
console.log(`>> ${(0, colors_1.dimWhite)('dbPipelineCopy')} started...${sinceUpdatedStr}`);
|
|
19
|
-
|
|
20
|
-
tables = await dbInput.getTables();
|
|
21
|
-
}
|
|
19
|
+
tables ||= await dbInput.getTables();
|
|
22
20
|
console.log(`${(0, colors_1.yellow)(tables.length)} ${(0, colors_1.boldWhite)('table(s)')}:\n` + tables.join('\n'));
|
|
23
21
|
const statsPerTable = {};
|
|
24
22
|
await (0, js_lib_1.pMap)(tables, async (table) => {
|
package/package.json
CHANGED
|
@@ -16,20 +16,20 @@ export interface CommonDaoHooks<
|
|
|
16
16
|
TM,
|
|
17
17
|
ID extends string | number,
|
|
18
18
|
> {
|
|
19
|
-
createRandomId
|
|
19
|
+
createRandomId(): ID
|
|
20
20
|
/**
|
|
21
21
|
* createNaturalId hook is called (tried) first.
|
|
22
22
|
* If it doesn't exist - createRandomId is called.
|
|
23
23
|
*/
|
|
24
|
-
createNaturalId
|
|
25
|
-
parseNaturalId
|
|
26
|
-
beforeCreate
|
|
27
|
-
beforeDBMValidate
|
|
28
|
-
beforeDBMToBM
|
|
29
|
-
beforeBMToDBM
|
|
30
|
-
beforeTMToBM
|
|
31
|
-
beforeBMToTM
|
|
32
|
-
anonymize
|
|
24
|
+
createNaturalId(obj: DBM | BM): ID
|
|
25
|
+
parseNaturalId(id: ID): Partial<DBM>
|
|
26
|
+
beforeCreate(bm: Partial<BM>): Partial<BM>
|
|
27
|
+
beforeDBMValidate(dbm: Partial<DBM>): Partial<DBM>
|
|
28
|
+
beforeDBMToBM(dbm: DBM): Partial<BM> | Promise<Partial<BM>>
|
|
29
|
+
beforeBMToDBM(bm: BM): Partial<DBM> | Promise<Partial<DBM>>
|
|
30
|
+
beforeTMToBM(tm: TM): Partial<BM>
|
|
31
|
+
beforeBMToTM(bm: BM): Partial<TM>
|
|
32
|
+
anonymize(dbm: DBM): DBM
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* If hook is defined - allows to prevent or modify the error thrown.
|
|
@@ -37,7 +37,7 @@ export interface CommonDaoHooks<
|
|
|
37
37
|
* Return original `err` to pass the error through (will be thrown in CommonDao).
|
|
38
38
|
* Return modified/new `Error` if needed.
|
|
39
39
|
*/
|
|
40
|
-
onValidationError
|
|
40
|
+
onValidationError(err: JoiValidationError | AjvValidationError): Error | false
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export enum CommonDaoLogLevel {
|
|
@@ -32,9 +32,9 @@ export interface CommonKeyValueDaoCfg<T> {
|
|
|
32
32
|
logStarted?: boolean
|
|
33
33
|
|
|
34
34
|
hooks?: {
|
|
35
|
-
mapValueToBuffer
|
|
36
|
-
mapBufferToValue
|
|
37
|
-
beforeCreate
|
|
35
|
+
mapValueToBuffer?(v: T): Promise<Buffer>
|
|
36
|
+
mapBufferToValue?(b: Buffer): Promise<T>
|
|
37
|
+
beforeCreate?(v: Partial<T>): Partial<T>
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -158,9 +158,7 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
|
|
|
158
158
|
|
|
159
159
|
fs.ensureDirSync(outputDirPath)
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
tables = await db.getTables()
|
|
163
|
-
}
|
|
161
|
+
tables ||= await db.getTables()
|
|
164
162
|
|
|
165
163
|
console.log(`${yellow(tables.length)} ${boldWhite('table(s)')}:\n` + tables.join('\n'))
|
|
166
164
|
|
|
@@ -106,9 +106,7 @@ export async function dbPipelineCopy(opt: DBPipelineCopyOptions): Promise<NDJson
|
|
|
106
106
|
|
|
107
107
|
console.log(`>> ${dimWhite('dbPipelineCopy')} started...${sinceUpdatedStr}`)
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
tables = await dbInput.getTables()
|
|
111
|
-
}
|
|
109
|
+
tables ||= await dbInput.getTables()
|
|
112
110
|
|
|
113
111
|
console.log(`${yellow(tables.length)} ${boldWhite('table(s)')}:\n` + tables.join('\n'))
|
|
114
112
|
|