@naturalcycles/db-lib 10.27.0 → 10.28.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.js +1 -1
- package/dist/commondao/common.dao.d.ts +2 -2
- package/dist/commondao/common.dao.js +4 -6
- package/dist/inmemory/queryInMemory.js +2 -2
- package/dist/pipeline/dbPipelineRestore.d.ts +1 -2
- package/dist/pipeline/dbPipelineRestore.js +1 -2
- package/dist/testing/commonDBTest.js +2 -2
- package/dist/testing/commonDaoTest.js +4 -4
- package/package.json +2 -2
- package/src/adapter/cachedb/cache.db.ts +1 -1
- package/src/commondao/common.dao.ts +6 -4
- package/src/inmemory/queryInMemory.ts +2 -2
- package/src/pipeline/dbPipelineRestore.ts +1 -1
- package/src/testing/commonDBTest.ts +2 -2
- package/src/testing/commonDaoTest.ts +4 -4
- package/src/testing/test.model.ts +1 -1
|
@@ -103,7 +103,7 @@ export class CacheDB extends BaseCommonDB {
|
|
|
103
103
|
this.cfg.logger?.log(`${q.table}.runQuery ${rows.length} rows from downstream`);
|
|
104
104
|
}
|
|
105
105
|
// Don't save to cache if it was a projection query
|
|
106
|
-
if (!opt.skipCache && !
|
|
106
|
+
if (!opt.skipCache && !this.cfg.skipCache && !q._selectedFieldNames) {
|
|
107
107
|
const cacheResult = this.cfg.cacheDB.saveBatch(q.table, rows, opt);
|
|
108
108
|
if (this.cfg.awaitCache)
|
|
109
109
|
await cacheResult;
|
|
@@ -152,7 +152,7 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
152
152
|
* Load rows (by their ids) from Multiple tables at once.
|
|
153
153
|
* An optimized way to load data, minimizing DB round-trips.
|
|
154
154
|
*
|
|
155
|
-
* @experimental
|
|
155
|
+
* @experimental
|
|
156
156
|
*/
|
|
157
157
|
static multiGet<MAP extends Record<string, DaoWithIds<AnyDao> | DaoWithId<AnyDao>>>(inputMap: MAP, opt?: CommonDaoReadOptions): Promise<{
|
|
158
158
|
[K in keyof MAP]: MAP[K] extends DaoWithIds<any> ? InferBM<MAP[K]['dao']>[] : InferBM<MAP[K]['dao']> | null;
|
|
@@ -161,7 +161,7 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
161
161
|
private static multiGetMapByTableById;
|
|
162
162
|
private static prepareMultiGetOutput;
|
|
163
163
|
/**
|
|
164
|
-
* @experimental
|
|
164
|
+
* @experimental
|
|
165
165
|
*/
|
|
166
166
|
static multiDelete(inputs: (DaoWithId<AnyDao> | DaoWithIds<AnyDao>)[], opt?: CommonDaoOptions): Promise<NonNegativeInteger>;
|
|
167
167
|
static multiSave(inputs: (DaoWithRows<AnyDao> | DaoWithRow<AnyDao>)[], opt?: CommonDaoSaveBatchOptions<any>): Promise<void>;
|
|
@@ -5,11 +5,9 @@ import { _assert, ErrorMode } from '@naturalcycles/js-lib/error';
|
|
|
5
5
|
import { _deepJsonEquals } from '@naturalcycles/js-lib/object/deepEquals.js';
|
|
6
6
|
import { _filterUndefinedValues, _objectAssignExact, } from '@naturalcycles/js-lib/object/object.util.js';
|
|
7
7
|
import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
|
|
8
|
-
import { _stringMapEntries, _stringMapValues, } from '@naturalcycles/js-lib/types';
|
|
9
|
-
import { _passthroughPredicate, _typeCast } from '@naturalcycles/js-lib/types';
|
|
8
|
+
import { _passthroughPredicate, _stringMapEntries, _stringMapValues, _typeCast, } from '@naturalcycles/js-lib/types';
|
|
10
9
|
import { stringId } from '@naturalcycles/nodejs-lib';
|
|
11
|
-
import { transformFlatten } from '@naturalcycles/nodejs-lib/stream';
|
|
12
|
-
import { transformChunk, transformLogProgress, transformMap, } from '@naturalcycles/nodejs-lib/stream';
|
|
10
|
+
import { transformChunk, transformFlatten, transformLogProgress, transformMap, } from '@naturalcycles/nodejs-lib/stream';
|
|
13
11
|
import { DBLibError } from '../cnst.js';
|
|
14
12
|
import { RunnableDBQuery } from '../query/dbQuery.js';
|
|
15
13
|
import { CommonDaoTransaction } from './commonDaoTransaction.js';
|
|
@@ -648,7 +646,7 @@ export class CommonDao {
|
|
|
648
646
|
* Load rows (by their ids) from Multiple tables at once.
|
|
649
647
|
* An optimized way to load data, minimizing DB round-trips.
|
|
650
648
|
*
|
|
651
|
-
* @experimental
|
|
649
|
+
* @experimental
|
|
652
650
|
*/
|
|
653
651
|
static async multiGet(inputMap, opt = {}) {
|
|
654
652
|
const db = Object.values(inputMap)[0]?.dao.cfg.db;
|
|
@@ -718,7 +716,7 @@ export class CommonDao {
|
|
|
718
716
|
return bmsByProp;
|
|
719
717
|
}
|
|
720
718
|
/**
|
|
721
|
-
* @experimental
|
|
719
|
+
* @experimental
|
|
722
720
|
*/
|
|
723
721
|
static async multiDelete(inputs, opt = {}) {
|
|
724
722
|
if (!inputs.length)
|
|
@@ -15,7 +15,7 @@ const FILTER_FNS = {
|
|
|
15
15
|
// But should be careful here..
|
|
16
16
|
export function queryInMemory(q, rows = []) {
|
|
17
17
|
// .filter
|
|
18
|
-
//
|
|
18
|
+
// oxlint-disable-next-line unicorn/no-array-reduce
|
|
19
19
|
rows = q._filters.reduce((rows, filter) => {
|
|
20
20
|
return rows.filter(row => {
|
|
21
21
|
const value = _get(row, filter.name);
|
|
@@ -31,7 +31,7 @@ export function queryInMemory(q, rows = []) {
|
|
|
31
31
|
if (order) {
|
|
32
32
|
const { name, descending } = order;
|
|
33
33
|
rows = rows.sort((a, b) => {
|
|
34
|
-
//
|
|
34
|
+
// oxlint-disable-next-line eqeqeq
|
|
35
35
|
if (a[name] == b[name])
|
|
36
36
|
return 0;
|
|
37
37
|
if (descending) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ErrorMode } from '@naturalcycles/js-lib/error/errorMode.js';
|
|
2
2
|
import type { AsyncMapper, UnixTimestamp } from '@naturalcycles/js-lib/types';
|
|
3
|
-
import { type TransformLogProgressOptions, type TransformMapOptions } from '@naturalcycles/nodejs-lib/stream';
|
|
4
|
-
import { NDJsonStats } from '@naturalcycles/nodejs-lib/stream';
|
|
3
|
+
import { NDJsonStats, type TransformLogProgressOptions, type TransformMapOptions } from '@naturalcycles/nodejs-lib/stream';
|
|
5
4
|
import type { CommonDB } from '../commondb/common.db.js';
|
|
6
5
|
import type { CommonDBSaveOptions } from '../db.model.js';
|
|
7
6
|
export interface DBPipelineRestoreOptions extends TransformLogProgressOptions {
|
|
@@ -6,8 +6,7 @@ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
|
|
|
6
6
|
import { _passthroughMapper } from '@naturalcycles/js-lib/types';
|
|
7
7
|
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/colors';
|
|
8
8
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
9
|
-
import { Pipeline, } from '@naturalcycles/nodejs-lib/stream';
|
|
10
|
-
import { NDJsonStats } from '@naturalcycles/nodejs-lib/stream';
|
|
9
|
+
import { NDJsonStats, Pipeline, } from '@naturalcycles/nodejs-lib/stream';
|
|
11
10
|
/**
|
|
12
11
|
* Pipeline from NDJSON files in a folder (optionally gzipped) to CommonDB.
|
|
13
12
|
* Allows to define a mapper and a predicate to map/filter objects between input and output.
|
|
@@ -258,8 +258,8 @@ export async function runCommonDBTest(db, quirks = {}) {
|
|
|
258
258
|
await tx.saveBatch(TEST_TABLE, [{ ...items[0], k1: 5, id: null }]);
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
|
-
catch (
|
|
262
|
-
err =
|
|
261
|
+
catch (err2) {
|
|
262
|
+
err = err2;
|
|
263
263
|
}
|
|
264
264
|
expect(err).toBeDefined();
|
|
265
265
|
const { rows } = await db.runQuery(queryAll());
|
|
@@ -309,8 +309,8 @@ export async function runCommonDaoTest(db, quirks = {}) {
|
|
|
309
309
|
await tx.save(dao, { ...items[0], k1: 5 }); // it should fail here
|
|
310
310
|
});
|
|
311
311
|
}
|
|
312
|
-
catch (
|
|
313
|
-
err =
|
|
312
|
+
catch (err2) {
|
|
313
|
+
err = err2;
|
|
314
314
|
}
|
|
315
315
|
expect(err).toBeDefined();
|
|
316
316
|
expect(err).toBeInstanceOf(Error);
|
|
@@ -327,8 +327,8 @@ export async function runCommonDaoTest(db, quirks = {}) {
|
|
|
327
327
|
await tx.save(dao, { ...items[0], k1: 5 }); // it should fail here
|
|
328
328
|
await tx.commit();
|
|
329
329
|
}
|
|
330
|
-
catch (
|
|
331
|
-
err =
|
|
330
|
+
catch (err2) {
|
|
331
|
+
err = err2;
|
|
332
332
|
}
|
|
333
333
|
expect(err).toBeDefined();
|
|
334
334
|
expect(err).toBeInstanceOf(Error);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/db-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "10.
|
|
4
|
+
"version": "10.28.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@naturalcycles/nodejs-lib": "^15"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@naturalcycles/dev-lib": "
|
|
10
|
+
"@naturalcycles/dev-lib": "18.4.2"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
@@ -162,7 +162,7 @@ export class CacheDB extends BaseCommonDB implements CommonDB {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// Don't save to cache if it was a projection query
|
|
165
|
-
if (!opt.skipCache && !
|
|
165
|
+
if (!opt.skipCache && !this.cfg.skipCache && !q._selectedFieldNames) {
|
|
166
166
|
const cacheResult = this.cfg.cacheDB.saveBatch(q.table, rows as any, opt)
|
|
167
167
|
if (this.cfg.awaitCache) await cacheResult
|
|
168
168
|
}
|
|
@@ -11,19 +11,21 @@ import {
|
|
|
11
11
|
} from '@naturalcycles/js-lib/object/object.util.js'
|
|
12
12
|
import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
|
|
13
13
|
import {
|
|
14
|
+
_passthroughPredicate,
|
|
14
15
|
_stringMapEntries,
|
|
15
16
|
_stringMapValues,
|
|
17
|
+
_typeCast,
|
|
16
18
|
type BaseDBEntity,
|
|
17
19
|
type NonNegativeInteger,
|
|
18
20
|
type ObjectWithId,
|
|
19
21
|
type StringMap,
|
|
20
22
|
type Unsaved,
|
|
21
23
|
} from '@naturalcycles/js-lib/types'
|
|
22
|
-
import { _passthroughPredicate, _typeCast } from '@naturalcycles/js-lib/types'
|
|
23
24
|
import { stringId } from '@naturalcycles/nodejs-lib'
|
|
24
|
-
import { type Pipeline, transformFlatten } from '@naturalcycles/nodejs-lib/stream'
|
|
25
25
|
import {
|
|
26
|
+
type Pipeline,
|
|
26
27
|
transformChunk,
|
|
28
|
+
transformFlatten,
|
|
27
29
|
transformLogProgress,
|
|
28
30
|
transformMap,
|
|
29
31
|
} from '@naturalcycles/nodejs-lib/stream'
|
|
@@ -857,7 +859,7 @@ export class CommonDao<
|
|
|
857
859
|
* Load rows (by their ids) from Multiple tables at once.
|
|
858
860
|
* An optimized way to load data, minimizing DB round-trips.
|
|
859
861
|
*
|
|
860
|
-
* @experimental
|
|
862
|
+
* @experimental
|
|
861
863
|
*/
|
|
862
864
|
static async multiGet<MAP extends Record<string, DaoWithIds<AnyDao> | DaoWithId<AnyDao>>>(
|
|
863
865
|
inputMap: MAP,
|
|
@@ -953,7 +955,7 @@ export class CommonDao<
|
|
|
953
955
|
}
|
|
954
956
|
|
|
955
957
|
/**
|
|
956
|
-
* @experimental
|
|
958
|
+
* @experimental
|
|
957
959
|
*/
|
|
958
960
|
static async multiDelete(
|
|
959
961
|
inputs: (DaoWithId<AnyDao> | DaoWithIds<AnyDao>)[],
|
|
@@ -21,7 +21,7 @@ const FILTER_FNS: Record<DBQueryFilterOperator, FilterFn> = {
|
|
|
21
21
|
// But should be careful here..
|
|
22
22
|
export function queryInMemory<ROW extends ObjectWithId>(q: DBQuery<ROW>, rows: ROW[] = []): ROW[] {
|
|
23
23
|
// .filter
|
|
24
|
-
//
|
|
24
|
+
// oxlint-disable-next-line unicorn/no-array-reduce
|
|
25
25
|
rows = q._filters.reduce((rows, filter) => {
|
|
26
26
|
return rows.filter(row => {
|
|
27
27
|
const value = _get(row, filter.name as string)
|
|
@@ -39,7 +39,7 @@ export function queryInMemory<ROW extends ObjectWithId>(q: DBQuery<ROW>, rows: R
|
|
|
39
39
|
if (order) {
|
|
40
40
|
const { name, descending } = order
|
|
41
41
|
rows = rows.sort((a, b) => {
|
|
42
|
-
//
|
|
42
|
+
// oxlint-disable-next-line eqeqeq
|
|
43
43
|
if (a[name] == b[name]) return 0
|
|
44
44
|
|
|
45
45
|
if (descending) {
|
|
@@ -9,11 +9,11 @@ import { _passthroughMapper } from '@naturalcycles/js-lib/types'
|
|
|
9
9
|
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/colors'
|
|
10
10
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
|
|
11
11
|
import {
|
|
12
|
+
NDJsonStats,
|
|
12
13
|
Pipeline,
|
|
13
14
|
type TransformLogProgressOptions,
|
|
14
15
|
type TransformMapOptions,
|
|
15
16
|
} from '@naturalcycles/nodejs-lib/stream'
|
|
16
|
-
import { NDJsonStats } from '@naturalcycles/nodejs-lib/stream'
|
|
17
17
|
import type { CommonDB } from '../commondb/common.db.js'
|
|
18
18
|
import type { CommonDBSaveOptions } from '../db.model.js'
|
|
19
19
|
|
|
@@ -354,8 +354,8 @@ export async function runCommonDBTest(
|
|
|
354
354
|
// It should fail on id == null
|
|
355
355
|
await tx.saveBatch(TEST_TABLE, [{ ...items[0]!, k1: 5, id: null as any }])
|
|
356
356
|
})
|
|
357
|
-
} catch (
|
|
358
|
-
err =
|
|
357
|
+
} catch (err2) {
|
|
358
|
+
err = err2
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
expect(err).toBeDefined()
|
|
@@ -412,8 +412,8 @@ export async function runCommonDaoTest(
|
|
|
412
412
|
await tx.deleteById(dao, items[2]!.id)
|
|
413
413
|
await tx.save(dao, { ...items[0]!, k1: 5 as any }) // it should fail here
|
|
414
414
|
})
|
|
415
|
-
} catch (
|
|
416
|
-
err =
|
|
415
|
+
} catch (err2) {
|
|
416
|
+
err = err2
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
expect(err).toBeDefined()
|
|
@@ -433,8 +433,8 @@ export async function runCommonDaoTest(
|
|
|
433
433
|
await tx.deleteById(dao, items[2]!.id)
|
|
434
434
|
await tx.save(dao, { ...items[0]!, k1: 5 as any }) // it should fail here
|
|
435
435
|
await tx.commit()
|
|
436
|
-
} catch (
|
|
437
|
-
err =
|
|
436
|
+
} catch (err2) {
|
|
437
|
+
err = err2
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
expect(err).toBeDefined()
|
|
@@ -58,7 +58,7 @@ export const testItemBMJsonSchema: JsonSchemaObject<TestItemBM> = j
|
|
|
58
58
|
created: j.unixTimestamp(),
|
|
59
59
|
updated: j.unixTimestamp(),
|
|
60
60
|
k1: j.string(),
|
|
61
|
-
k2: j.oneOf
|
|
61
|
+
k2: j.oneOf([j.string(), j.null()]).optional(),
|
|
62
62
|
k3: j.number().optional(),
|
|
63
63
|
even: j.boolean().optional(),
|
|
64
64
|
b1: j.buffer().optional(),
|