@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.
@@ -36,9 +36,7 @@ function queryInMemory(q, rows = []) {
36
36
  if (descending) {
37
37
  return a[name] < b[name] ? 1 : -1;
38
38
  }
39
- else {
40
- return a[name] > b[name] ? 1 : -1;
41
- }
39
+ return a[name] > b[name] ? 1 : -1;
42
40
  });
43
41
  }
44
42
  // .offset()
@@ -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: () => ID;
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: (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;
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: (err: JoiValidationError | AjvValidationError) => Error | false;
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?: (v: T) => Promise<Buffer>;
25
- mapBufferToValue?: (b: Buffer) => Promise<T>;
26
- beforeCreate?: (v: Partial<T>) => Partial<T>;
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
- if (!tables) {
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
- if (!tables) {
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
@@ -41,7 +41,7 @@
41
41
  "engines": {
42
42
  "node": ">=14.15"
43
43
  },
44
- "version": "8.49.0",
44
+ "version": "8.49.1",
45
45
  "description": "Lowest Common Denominator API to supported Databases",
46
46
  "keywords": [
47
47
  "db",
@@ -39,9 +39,8 @@ export function queryInMemory<ROW extends ObjectWithId>(q: DBQuery<ROW>, rows: R
39
39
 
40
40
  if (descending) {
41
41
  return a[name] < b[name] ? 1 : -1
42
- } else {
43
- return a[name] > b[name] ? 1 : -1
44
42
  }
43
+ return a[name] > b[name] ? 1 : -1
45
44
  })
46
45
  }
47
46
 
@@ -16,20 +16,20 @@ export interface CommonDaoHooks<
16
16
  TM,
17
17
  ID extends string | number,
18
18
  > {
19
- createRandomId: () => ID
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: (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
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: (err: JoiValidationError | AjvValidationError) => Error | false
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?: (v: T) => Promise<Buffer>
36
- mapBufferToValue?: (b: Buffer) => Promise<T>
37
- beforeCreate?: (v: Partial<T>) => Partial<T>
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
- if (!tables) {
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
- if (!tables) {
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