@naturalcycles/db-lib 10.15.1 → 10.16.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/commondao/common.dao.d.ts +1 -1
- package/dist/commondao/common.dao.js +3 -2
- package/dist/commondao/common.dao.model.d.ts +5 -2
- package/dist/pipeline/dbPipelineBackup.js +2 -2
- package/dist/pipeline/dbPipelineCopy.d.ts +1 -1
- package/dist/pipeline/dbPipelineCopy.js +2 -1
- package/dist/pipeline/dbPipelineRestore.js +2 -2
- package/package.json +1 -1
- package/src/commondao/common.dao.model.ts +5 -2
- package/src/commondao/common.dao.ts +3 -3
- package/src/pipeline/dbPipelineBackup.ts +2 -1
- package/src/pipeline/dbPipelineCopy.ts +5 -4
- package/src/pipeline/dbPipelineRestore.ts +2 -1
|
@@ -2,7 +2,7 @@ import type { Transform } from 'node:stream';
|
|
|
2
2
|
import type { JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib/json-schema';
|
|
3
3
|
import type { CommonLogger } from '@naturalcycles/js-lib/log';
|
|
4
4
|
import type { AsyncIndexedMapper, BaseDBEntity, StringMap, UnixTimestampMillis, Unsaved } from '@naturalcycles/js-lib/types';
|
|
5
|
-
import type
|
|
5
|
+
import { type ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
|
|
6
6
|
import type { CommonDBTransactionOptions, DBTransaction, RunQueryResult } from '../db.model.js';
|
|
7
7
|
import type { DBQuery } from '../query/dbQuery.js';
|
|
8
8
|
import { RunnableDBQuery } from '../query/dbQuery.js';
|
|
@@ -9,6 +9,7 @@ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
|
|
|
9
9
|
import { _truncate } from '@naturalcycles/js-lib/string/string.util.js';
|
|
10
10
|
import { _passthroughPredicate, _typeCast, SKIP } from '@naturalcycles/js-lib/types';
|
|
11
11
|
import { stringId } from '@naturalcycles/nodejs-lib';
|
|
12
|
+
import { transformFlatten } from '@naturalcycles/nodejs-lib/stream';
|
|
12
13
|
import { _pipeline, transformChunk, transformLogProgress, transformMap, transformNoOp, writableVoid, } from '@naturalcycles/nodejs-lib/stream';
|
|
13
14
|
import { DBLibError } from '../cnst.js';
|
|
14
15
|
import { RunnableDBQuery } from '../query/dbQuery.js';
|
|
@@ -473,7 +474,7 @@ export class CommonDao {
|
|
|
473
474
|
obj.created ||= obj.updated || now;
|
|
474
475
|
}
|
|
475
476
|
if (this.cfg.useUpdatedProperty) {
|
|
476
|
-
obj.updated = opt.
|
|
477
|
+
obj.updated = opt.preserveUpdated && obj.updated ? obj.updated : now;
|
|
477
478
|
}
|
|
478
479
|
if (this.cfg.generateId) {
|
|
479
480
|
obj.id ||= (this.cfg.hooks.createNaturalId?.(obj) ||
|
|
@@ -766,8 +767,8 @@ export class CommonDao {
|
|
|
766
767
|
}, {
|
|
767
768
|
concurrency: chunkConcurrency,
|
|
768
769
|
errorMode,
|
|
769
|
-
flattenArrayOutput: true,
|
|
770
770
|
}),
|
|
771
|
+
transformFlatten(),
|
|
771
772
|
transformLogProgress({
|
|
772
773
|
metric: 'saved',
|
|
773
774
|
...opt,
|
|
@@ -202,9 +202,12 @@ export interface CommonDaoOptions extends CommonDBOptions {
|
|
|
202
202
|
*/
|
|
203
203
|
mutateInput?: boolean;
|
|
204
204
|
/**
|
|
205
|
-
*
|
|
205
|
+
* Defaults to false.
|
|
206
|
+
*
|
|
207
|
+
* If false (default) - will set `updated` property to the current timestamp.
|
|
208
|
+
* If true - will NOT set it (preserve the original value).
|
|
206
209
|
*/
|
|
207
|
-
|
|
210
|
+
preserveUpdated?: boolean;
|
|
208
211
|
/**
|
|
209
212
|
* @default false (for streams). Setting to true enables deletion of immutable objects
|
|
210
213
|
*/
|
|
@@ -4,7 +4,7 @@ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
|
|
|
4
4
|
import { _passthroughMapper } from '@naturalcycles/js-lib/types';
|
|
5
5
|
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/colors';
|
|
6
6
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2';
|
|
7
|
-
import { createWriteStreamAsNDJSON, } from '@naturalcycles/nodejs-lib/stream';
|
|
7
|
+
import { createWriteStreamAsNDJSON, transformFlatten, } from '@naturalcycles/nodejs-lib/stream';
|
|
8
8
|
import { _pipeline, NDJsonStats, transformLogProgress, transformMap, transformTap, } from '@naturalcycles/nodejs-lib/stream';
|
|
9
9
|
import { DBQuery } from '../query/dbQuery.js';
|
|
10
10
|
/**
|
|
@@ -65,10 +65,10 @@ export async function dbPipelineBackup(opt) {
|
|
|
65
65
|
}),
|
|
66
66
|
transformMap(mapperPerTable[table] || _passthroughMapper, {
|
|
67
67
|
errorMode,
|
|
68
|
-
flattenArrayOutput: true,
|
|
69
68
|
...transformMapOptions,
|
|
70
69
|
metric: table,
|
|
71
70
|
}),
|
|
71
|
+
transformFlatten(),
|
|
72
72
|
transformTap(() => {
|
|
73
73
|
rows++;
|
|
74
74
|
}),
|
|
@@ -1,6 +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
|
|
3
|
+
import { type TransformLogProgressOptions, type TransformMapOptions } from '@naturalcycles/nodejs-lib/stream';
|
|
4
4
|
import { NDJsonStats } from '@naturalcycles/nodejs-lib/stream';
|
|
5
5
|
import type { CommonDB } from '../commondb/common.db.js';
|
|
6
6
|
import type { CommonDBSaveOptions } from '../db.model.js';
|
|
@@ -3,6 +3,7 @@ import { ErrorMode } from '@naturalcycles/js-lib/error/errorMode.js';
|
|
|
3
3
|
import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
|
|
4
4
|
import { _passthroughMapper } from '@naturalcycles/js-lib/types';
|
|
5
5
|
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/colors';
|
|
6
|
+
import { transformFlatten, } from '@naturalcycles/nodejs-lib/stream';
|
|
6
7
|
import { _pipeline, NDJsonStats, transformChunk, transformLogProgress, transformMap, transformTap, writableForEach, } from '@naturalcycles/nodejs-lib/stream';
|
|
7
8
|
import { DBQuery } from '../query/dbQuery.js';
|
|
8
9
|
/**
|
|
@@ -38,10 +39,10 @@ export async function dbPipelineCopy(opt) {
|
|
|
38
39
|
}),
|
|
39
40
|
transformMap(mapper, {
|
|
40
41
|
errorMode,
|
|
41
|
-
flattenArrayOutput: true,
|
|
42
42
|
...transformMapOptions,
|
|
43
43
|
metric: table,
|
|
44
44
|
}),
|
|
45
|
+
transformFlatten(),
|
|
45
46
|
transformTap(() => rows++),
|
|
46
47
|
transformChunk({ chunkSize }),
|
|
47
48
|
writableForEach(async (dbms) => {
|
|
@@ -6,7 +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 { createReadStreamAsNDJSON, } from '@naturalcycles/nodejs-lib/stream';
|
|
9
|
+
import { createReadStreamAsNDJSON, transformFlatten, } from '@naturalcycles/nodejs-lib/stream';
|
|
10
10
|
import { _pipeline, NDJsonStats, transformChunk, transformFilterSync, transformLogProgress, transformMap, transformTap, writableForEach, } from '@naturalcycles/nodejs-lib/stream';
|
|
11
11
|
/**
|
|
12
12
|
* Pipeline from NDJSON files in a folder (optionally gzipped) to CommonDB.
|
|
@@ -80,10 +80,10 @@ export async function dbPipelineRestore(opt) {
|
|
|
80
80
|
: []),
|
|
81
81
|
transformMap(mapperPerTable[table] || _passthroughMapper, {
|
|
82
82
|
errorMode,
|
|
83
|
-
flattenArrayOutput: true,
|
|
84
83
|
...transformMapOptions,
|
|
85
84
|
metric: table,
|
|
86
85
|
}),
|
|
86
|
+
transformFlatten(),
|
|
87
87
|
transformChunk({ chunkSize }),
|
|
88
88
|
writableForEach(async (dbms) => {
|
|
89
89
|
await db.saveBatch(table, dbms, saveOptions);
|
package/package.json
CHANGED
|
@@ -244,9 +244,12 @@ export interface CommonDaoOptions extends CommonDBOptions {
|
|
|
244
244
|
mutateInput?: boolean
|
|
245
245
|
|
|
246
246
|
/**
|
|
247
|
-
*
|
|
247
|
+
* Defaults to false.
|
|
248
|
+
*
|
|
249
|
+
* If false (default) - will set `updated` property to the current timestamp.
|
|
250
|
+
* If true - will NOT set it (preserve the original value).
|
|
248
251
|
*/
|
|
249
|
-
|
|
252
|
+
preserveUpdated?: boolean
|
|
250
253
|
|
|
251
254
|
/**
|
|
252
255
|
* @default false (for streams). Setting to true enables deletion of immutable objects
|
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
} from '@naturalcycles/js-lib/types'
|
|
25
25
|
import { _passthroughPredicate, _typeCast, SKIP } from '@naturalcycles/js-lib/types'
|
|
26
26
|
import { stringId } from '@naturalcycles/nodejs-lib'
|
|
27
|
-
import type
|
|
27
|
+
import { type ReadableTyped, transformFlatten } from '@naturalcycles/nodejs-lib/stream'
|
|
28
28
|
import {
|
|
29
29
|
_pipeline,
|
|
30
30
|
transformChunk,
|
|
@@ -617,7 +617,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
617
617
|
}
|
|
618
618
|
|
|
619
619
|
if (this.cfg.useUpdatedProperty) {
|
|
620
|
-
obj.updated = opt.
|
|
620
|
+
obj.updated = opt.preserveUpdated && obj.updated ? obj.updated : now
|
|
621
621
|
}
|
|
622
622
|
|
|
623
623
|
if (this.cfg.generateId) {
|
|
@@ -983,9 +983,9 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
983
983
|
{
|
|
984
984
|
concurrency: chunkConcurrency,
|
|
985
985
|
errorMode,
|
|
986
|
-
flattenArrayOutput: true,
|
|
987
986
|
},
|
|
988
987
|
),
|
|
988
|
+
transformFlatten(),
|
|
989
989
|
transformLogProgress({
|
|
990
990
|
metric: 'saved',
|
|
991
991
|
...opt,
|
|
@@ -7,6 +7,7 @@ import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/col
|
|
|
7
7
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
|
|
8
8
|
import {
|
|
9
9
|
createWriteStreamAsNDJSON,
|
|
10
|
+
transformFlatten,
|
|
10
11
|
type TransformLogProgressOptions,
|
|
11
12
|
type TransformMapOptions,
|
|
12
13
|
} from '@naturalcycles/nodejs-lib/stream'
|
|
@@ -220,10 +221,10 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
|
|
|
220
221
|
}),
|
|
221
222
|
transformMap(mapperPerTable[table] || _passthroughMapper, {
|
|
222
223
|
errorMode,
|
|
223
|
-
flattenArrayOutput: true,
|
|
224
224
|
...transformMapOptions,
|
|
225
225
|
metric: table,
|
|
226
226
|
}),
|
|
227
|
+
transformFlatten(),
|
|
227
228
|
transformTap(() => {
|
|
228
229
|
rows++
|
|
229
230
|
}),
|
|
@@ -4,9 +4,10 @@ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
|
|
|
4
4
|
import type { AsyncMapper, BaseDBEntity, UnixTimestamp } from '@naturalcycles/js-lib/types'
|
|
5
5
|
import { _passthroughMapper } from '@naturalcycles/js-lib/types'
|
|
6
6
|
import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/colors'
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import {
|
|
8
|
+
transformFlatten,
|
|
9
|
+
type TransformLogProgressOptions,
|
|
10
|
+
type TransformMapOptions,
|
|
10
11
|
} from '@naturalcycles/nodejs-lib/stream'
|
|
11
12
|
import {
|
|
12
13
|
_pipeline,
|
|
@@ -144,10 +145,10 @@ export async function dbPipelineCopy(opt: DBPipelineCopyOptions): Promise<NDJson
|
|
|
144
145
|
}),
|
|
145
146
|
transformMap(mapper, {
|
|
146
147
|
errorMode,
|
|
147
|
-
flattenArrayOutput: true,
|
|
148
148
|
...transformMapOptions,
|
|
149
149
|
metric: table,
|
|
150
150
|
}),
|
|
151
|
+
transformFlatten(),
|
|
151
152
|
transformTap(() => rows++),
|
|
152
153
|
transformChunk({ chunkSize }),
|
|
153
154
|
writableForEach(async dbms => {
|
|
@@ -10,6 +10,7 @@ import { boldWhite, dimWhite, grey, yellow } from '@naturalcycles/nodejs-lib/col
|
|
|
10
10
|
import { fs2 } from '@naturalcycles/nodejs-lib/fs2'
|
|
11
11
|
import {
|
|
12
12
|
createReadStreamAsNDJSON,
|
|
13
|
+
transformFlatten,
|
|
13
14
|
type TransformLogProgressOptions,
|
|
14
15
|
type TransformMapOptions,
|
|
15
16
|
} from '@naturalcycles/nodejs-lib/stream'
|
|
@@ -207,10 +208,10 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
|
|
|
207
208
|
: []),
|
|
208
209
|
transformMap(mapperPerTable[table] || _passthroughMapper, {
|
|
209
210
|
errorMode,
|
|
210
|
-
flattenArrayOutput: true,
|
|
211
211
|
...transformMapOptions,
|
|
212
212
|
metric: table,
|
|
213
213
|
}),
|
|
214
|
+
transformFlatten(),
|
|
214
215
|
transformChunk({ chunkSize }),
|
|
215
216
|
writableForEach(async dbms => {
|
|
216
217
|
await db.saveBatch(table, dbms, saveOptions)
|