@naturalcycles/db-lib 10.4.1 → 10.5.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/file/file.db.js +1 -1
- package/dist/commondao/common.dao.d.ts +4 -4
- package/dist/query/dbQuery.d.ts +4 -4
- package/dist/testing/keyValueDBTest.js +1 -1
- package/dist/testing/keyValueDaoTest.js +1 -1
- package/package.json +2 -2
- package/src/adapter/file/file.db.ts +1 -1
- package/src/commondao/common.dao.ts +4 -4
- package/src/query/dbQuery.ts +4 -4
- package/src/testing/keyValueDBTest.ts +1 -1
- package/src/testing/keyValueDaoTest.ts +1 -1
|
@@ -148,7 +148,7 @@ export class FileDB extends BaseCommonDB {
|
|
|
148
148
|
sortRows(rows) {
|
|
149
149
|
rows = rows.map(r => _filterUndefinedValues(r));
|
|
150
150
|
if (this.cfg.sortOnSave) {
|
|
151
|
-
_sortBy(rows, r => r[this.cfg.sortOnSave.name], true);
|
|
151
|
+
_sortBy(rows, r => r[this.cfg.sortOnSave.name], { mutate: true });
|
|
152
152
|
if (this.cfg.sortOnSave.descending)
|
|
153
153
|
rows.reverse(); // mutates
|
|
154
154
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Transform } from 'node:stream';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AsyncIndexedMapper, BaseDBEntity, CommonLogger, JsonSchemaObject, JsonSchemaRootObject, StringMap, UnixTimestampMillis, Unsaved } from '@naturalcycles/js-lib';
|
|
3
3
|
import { ZodType } from '@naturalcycles/js-lib/zod';
|
|
4
4
|
import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv';
|
|
5
5
|
import { type ObjectSchema } from '@naturalcycles/nodejs-lib/joi';
|
|
@@ -55,8 +55,8 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
55
55
|
runQueryAsDBM(q: DBQuery<DBM>, opt?: CommonDaoReadOptions): Promise<DBM[]>;
|
|
56
56
|
runQueryExtendedAsDBM(q: DBQuery<DBM>, opt?: CommonDaoReadOptions): Promise<RunQueryResult<DBM>>;
|
|
57
57
|
runQueryCount(q: DBQuery<DBM>, opt?: CommonDaoReadOptions): Promise<number>;
|
|
58
|
-
streamQueryForEach(q: DBQuery<DBM>, mapper:
|
|
59
|
-
streamQueryAsDBMForEach(q: DBQuery<DBM>, mapper:
|
|
58
|
+
streamQueryForEach(q: DBQuery<DBM>, mapper: AsyncIndexedMapper<BM, void>, opt?: CommonDaoStreamForEachOptions<BM>): Promise<void>;
|
|
59
|
+
streamQueryAsDBMForEach(q: DBQuery<DBM>, mapper: AsyncIndexedMapper<DBM, void>, opt?: CommonDaoStreamForEachOptions<DBM>): Promise<void>;
|
|
60
60
|
/**
|
|
61
61
|
* Stream as Readable, to be able to .pipe() it further with support of backpressure.
|
|
62
62
|
*/
|
|
@@ -73,7 +73,7 @@ export declare class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
73
73
|
streamQuery(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM>;
|
|
74
74
|
queryIds(q: DBQuery<DBM>, opt?: CommonDaoReadOptions): Promise<ID[]>;
|
|
75
75
|
streamQueryIds(q: DBQuery<DBM>, opt?: CommonDaoStreamOptions<ID>): ReadableTyped<ID>;
|
|
76
|
-
streamQueryIdsForEach(q: DBQuery<DBM>, mapper:
|
|
76
|
+
streamQueryIdsForEach(q: DBQuery<DBM>, mapper: AsyncIndexedMapper<ID, void>, opt?: CommonDaoStreamForEachOptions<ID>): Promise<void>;
|
|
77
77
|
/**
|
|
78
78
|
* Mutates!
|
|
79
79
|
* "Returns", just to have a type of "Saved"
|
package/dist/query/dbQuery.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AsyncIndexedMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib';
|
|
2
2
|
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
3
3
|
import type { CommonDao } from '../commondao/common.dao.js';
|
|
4
4
|
import type { CommonDaoOptions, CommonDaoReadOptions, CommonDaoStreamDeleteOptions, CommonDaoStreamForEachOptions, CommonDaoStreamOptions } from '../commondao/common.dao.model.js';
|
|
@@ -100,12 +100,12 @@ export declare class RunnableDBQuery<BM extends BaseDBEntity, DBM extends BaseDB
|
|
|
100
100
|
runQueryExtendedAsDBM(opt?: CommonDaoReadOptions): Promise<RunQueryResult<DBM>>;
|
|
101
101
|
runQueryCount(opt?: CommonDaoReadOptions): Promise<number>;
|
|
102
102
|
patchByQuery(patch: Partial<DBM>, opt?: CommonDaoOptions): Promise<number>;
|
|
103
|
-
streamQueryForEach(mapper:
|
|
104
|
-
streamQueryAsDBMForEach(mapper:
|
|
103
|
+
streamQueryForEach(mapper: AsyncIndexedMapper<BM, void>, opt?: CommonDaoStreamForEachOptions<BM>): Promise<void>;
|
|
104
|
+
streamQueryAsDBMForEach(mapper: AsyncIndexedMapper<DBM, void>, opt?: CommonDaoStreamForEachOptions<DBM>): Promise<void>;
|
|
105
105
|
streamQuery(opt?: CommonDaoStreamOptions<BM>): ReadableTyped<BM>;
|
|
106
106
|
streamQueryAsDBM(opt?: CommonDaoStreamOptions<DBM>): ReadableTyped<DBM>;
|
|
107
107
|
queryIds(opt?: CommonDaoReadOptions): Promise<ID[]>;
|
|
108
108
|
streamQueryIds(opt?: CommonDaoStreamOptions<ID>): ReadableTyped<ID>;
|
|
109
|
-
streamQueryIdsForEach(mapper:
|
|
109
|
+
streamQueryIdsForEach(mapper: AsyncIndexedMapper<ID, void>, opt?: CommonDaoStreamForEachOptions<ID>): Promise<void>;
|
|
110
110
|
deleteByQuery(opt?: CommonDaoStreamDeleteOptions<DBM>): Promise<number>;
|
|
111
111
|
}
|
|
@@ -39,7 +39,7 @@ export async function runCommonKeyValueDBTest(db) {
|
|
|
39
39
|
test('saveBatch, then getByIds', async () => {
|
|
40
40
|
await db.saveBatch(TEST_TABLE, testEntries);
|
|
41
41
|
const entries = await db.getByIds(TEST_TABLE, testIds);
|
|
42
|
-
_sortBy(entries, e => e[0], true);
|
|
42
|
+
_sortBy(entries, e => e[0], { mutate: true });
|
|
43
43
|
expect(entries).toEqual(testEntries);
|
|
44
44
|
});
|
|
45
45
|
if (support.count) {
|
|
@@ -41,7 +41,7 @@ export async function runCommonKeyValueDaoTest(db) {
|
|
|
41
41
|
await dao.saveBatch(testEntries);
|
|
42
42
|
const entries = await dao.getByIds(testIds);
|
|
43
43
|
// console.log(typeof entries[0]![1], entries[0]![1])
|
|
44
|
-
_sortBy(entries, e => e[0], true);
|
|
44
|
+
_sortBy(entries, e => e[0], { mutate: true });
|
|
45
45
|
expect(entries).toEqual(testEntries); // Jest doesn't allow to compare Buffers directly
|
|
46
46
|
// expect(entries.map(e => e[0])).toEqual(testEntries.map(e => e[0]))
|
|
47
47
|
// expect(entries.map(e => e[1].toString())).toEqual(testEntries.map(e => e[1].toString()))
|
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.5.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": "19.
|
|
10
|
+
"@naturalcycles/dev-lib": "19.5.0"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
@@ -228,7 +228,7 @@ export class FileDB extends BaseCommonDB implements CommonDB {
|
|
|
228
228
|
rows = rows.map(r => _filterUndefinedValues(r))
|
|
229
229
|
|
|
230
230
|
if (this.cfg.sortOnSave) {
|
|
231
|
-
_sortBy(rows, r => r[this.cfg.sortOnSave!.name as keyof ROW], true)
|
|
231
|
+
_sortBy(rows, r => r[this.cfg.sortOnSave!.name as keyof ROW] as string, { mutate: true })
|
|
232
232
|
if (this.cfg.sortOnSave.descending) rows.reverse() // mutates
|
|
233
233
|
}
|
|
234
234
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Transform } from 'node:stream'
|
|
2
2
|
import type {
|
|
3
|
-
|
|
3
|
+
AsyncIndexedMapper,
|
|
4
4
|
BaseDBEntity,
|
|
5
5
|
CommonLogger,
|
|
6
6
|
JsonSchemaObject,
|
|
@@ -358,7 +358,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
358
358
|
|
|
359
359
|
async streamQueryForEach(
|
|
360
360
|
q: DBQuery<DBM>,
|
|
361
|
-
mapper:
|
|
361
|
+
mapper: AsyncIndexedMapper<BM, void>,
|
|
362
362
|
opt: CommonDaoStreamForEachOptions<BM> = {},
|
|
363
363
|
): Promise<void> {
|
|
364
364
|
this.validateQueryIndexes(q) // throws if query uses `excludeFromIndexes` property
|
|
@@ -408,7 +408,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
408
408
|
|
|
409
409
|
async streamQueryAsDBMForEach(
|
|
410
410
|
q: DBQuery<DBM>,
|
|
411
|
-
mapper:
|
|
411
|
+
mapper: AsyncIndexedMapper<DBM, void>,
|
|
412
412
|
opt: CommonDaoStreamForEachOptions<DBM> = {},
|
|
413
413
|
): Promise<void> {
|
|
414
414
|
this.validateQueryIndexes(q) // throws if query uses `excludeFromIndexes` property
|
|
@@ -581,7 +581,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
581
581
|
|
|
582
582
|
async streamQueryIdsForEach(
|
|
583
583
|
q: DBQuery<DBM>,
|
|
584
|
-
mapper:
|
|
584
|
+
mapper: AsyncIndexedMapper<ID, void>,
|
|
585
585
|
opt: CommonDaoStreamForEachOptions<ID> = {},
|
|
586
586
|
): Promise<void> {
|
|
587
587
|
this.validateQueryIndexes(q) // throws if query uses `excludeFromIndexes` property
|
package/src/query/dbQuery.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AsyncIndexedMapper, BaseDBEntity, ObjectWithId } from '@naturalcycles/js-lib'
|
|
2
2
|
import { _objectAssign, _truncate } from '@naturalcycles/js-lib'
|
|
3
3
|
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream'
|
|
4
4
|
import type { CommonDao } from '../commondao/common.dao.js'
|
|
@@ -276,14 +276,14 @@ export class RunnableDBQuery<
|
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
async streamQueryForEach(
|
|
279
|
-
mapper:
|
|
279
|
+
mapper: AsyncIndexedMapper<BM, void>,
|
|
280
280
|
opt?: CommonDaoStreamForEachOptions<BM>,
|
|
281
281
|
): Promise<void> {
|
|
282
282
|
await this.dao.streamQueryForEach(this, mapper, opt)
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
async streamQueryAsDBMForEach(
|
|
286
|
-
mapper:
|
|
286
|
+
mapper: AsyncIndexedMapper<DBM, void>,
|
|
287
287
|
opt?: CommonDaoStreamForEachOptions<DBM>,
|
|
288
288
|
): Promise<void> {
|
|
289
289
|
await this.dao.streamQueryAsDBMForEach(this, mapper, opt)
|
|
@@ -306,7 +306,7 @@ export class RunnableDBQuery<
|
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
async streamQueryIdsForEach(
|
|
309
|
-
mapper:
|
|
309
|
+
mapper: AsyncIndexedMapper<ID, void>,
|
|
310
310
|
opt?: CommonDaoStreamForEachOptions<ID>,
|
|
311
311
|
): Promise<void> {
|
|
312
312
|
await this.dao.streamQueryIdsForEach(this, mapper, opt)
|
|
@@ -54,7 +54,7 @@ export async function runCommonKeyValueDBTest(db: CommonKeyValueDB): Promise<voi
|
|
|
54
54
|
await db.saveBatch(TEST_TABLE, testEntries)
|
|
55
55
|
|
|
56
56
|
const entries = await db.getByIds(TEST_TABLE, testIds)
|
|
57
|
-
_sortBy(entries, e => e[0], true)
|
|
57
|
+
_sortBy(entries, e => e[0], { mutate: true })
|
|
58
58
|
expect(entries).toEqual(testEntries)
|
|
59
59
|
})
|
|
60
60
|
|
|
@@ -54,7 +54,7 @@ export async function runCommonKeyValueDaoTest(db: CommonKeyValueDB): Promise<vo
|
|
|
54
54
|
const entries = await dao.getByIds(testIds)
|
|
55
55
|
// console.log(typeof entries[0]![1], entries[0]![1])
|
|
56
56
|
|
|
57
|
-
_sortBy(entries, e => e[0], true)
|
|
57
|
+
_sortBy(entries, e => e[0], { mutate: true })
|
|
58
58
|
expect(entries).toEqual(testEntries) // Jest doesn't allow to compare Buffers directly
|
|
59
59
|
// expect(entries.map(e => e[0])).toEqual(testEntries.map(e => e[0]))
|
|
60
60
|
// expect(entries.map(e => e[1].toString())).toEqual(testEntries.map(e => e[1].toString()))
|