@naturalcycles/db-lib 10.62.0 → 10.64.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 +2 -2
- package/dist/commondao/common.dao.js +2 -2
- package/dist/kv/commonKeyValueDaoMemoCache.js +2 -4
- package/dist/model.util.js +3 -3
- package/dist/pipeline/dbPipelineBackup.js +2 -2
- package/dist/pipeline/dbPipelineCopy.js +2 -2
- package/dist/pipeline/dbPipelineRestore.js +2 -2
- package/dist/testing/timeSeriesTest.util.js +2 -1
- package/package.json +1 -1
- package/src/adapter/file/file.db.ts +2 -2
- package/src/commondao/common.dao.ts +2 -2
- package/src/kv/commonKeyValueDaoMemoCache.ts +2 -4
- package/src/model.util.ts +3 -3
- package/src/pipeline/dbPipelineBackup.ts +2 -2
- package/src/pipeline/dbPipelineCopy.ts +2 -2
- package/src/pipeline/dbPipelineRestore.ts +2 -2
- package/src/testing/timeSeriesTest.util.ts +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { _by, _sortBy } from '@naturalcycles/js-lib/array';
|
|
3
|
-
import { _since,
|
|
3
|
+
import { _since, nowUnixMillis } from '@naturalcycles/js-lib/datetime';
|
|
4
4
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
5
5
|
import { consoleLogger } from '@naturalcycles/js-lib/log';
|
|
6
6
|
import { _deepEquals, _filterUndefinedValues, _sortObjectDeep } from '@naturalcycles/js-lib/object';
|
|
@@ -167,7 +167,7 @@ export class FileDB extends BaseCommonDB {
|
|
|
167
167
|
if (this.cfg.logStarted) {
|
|
168
168
|
this.cfg.logger?.log(`>> ${op}`);
|
|
169
169
|
}
|
|
170
|
-
return
|
|
170
|
+
return nowUnixMillis();
|
|
171
171
|
}
|
|
172
172
|
logFinished(started, op) {
|
|
173
173
|
if (!this.cfg.logFinished)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _isTruthy } from '@naturalcycles/js-lib';
|
|
2
2
|
import { _uniqBy } from '@naturalcycles/js-lib/array/array.util.js';
|
|
3
|
-
import {
|
|
3
|
+
import { nowUnix } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
4
4
|
import { _assert, ErrorMode } from '@naturalcycles/js-lib/error';
|
|
5
5
|
import { consoleLogger } from '@naturalcycles/js-lib/log';
|
|
6
6
|
import { _deepJsonEquals } from '@naturalcycles/js-lib/object/deepEquals.js';
|
|
@@ -220,7 +220,7 @@ export class CommonDao {
|
|
|
220
220
|
* Mutates!
|
|
221
221
|
*/
|
|
222
222
|
assignIdCreatedUpdated(obj, opt = {}) {
|
|
223
|
-
const now =
|
|
223
|
+
const now = nowUnix();
|
|
224
224
|
if (this.cfg.useCreatedProperty) {
|
|
225
225
|
obj.created ||= obj.updated || now;
|
|
226
226
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nowUnix } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
2
2
|
import { MISS } from '@naturalcycles/js-lib/types';
|
|
3
3
|
/**
|
|
4
4
|
* AsyncMemoCache implementation, backed by CommonKeyValueDao.
|
|
@@ -17,9 +17,7 @@ export class CommonKeyValueDaoMemoCache {
|
|
|
17
17
|
return (await this.cfg.dao.getById(k)) || MISS;
|
|
18
18
|
}
|
|
19
19
|
async set(k, v) {
|
|
20
|
-
const opt = this.cfg.ttl
|
|
21
|
-
? { expireAt: (localTime.nowUnix() + this.cfg.ttl) }
|
|
22
|
-
: undefined;
|
|
20
|
+
const opt = this.cfg.ttl ? { expireAt: (nowUnix() + this.cfg.ttl) } : undefined;
|
|
23
21
|
await this.cfg.dao.save(k, v, opt);
|
|
24
22
|
}
|
|
25
23
|
async delete(k) {
|
package/dist/model.util.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nowUnix } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
2
2
|
import { stringId } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
export function createdUpdatedFields(existingObject) {
|
|
4
|
-
const now =
|
|
4
|
+
const now = nowUnix();
|
|
5
5
|
return {
|
|
6
6
|
created: existingObject?.created || now,
|
|
7
7
|
updated: now,
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
export function createdUpdatedIdFields(existingObject) {
|
|
11
|
-
const now =
|
|
11
|
+
const now = nowUnix();
|
|
12
12
|
return {
|
|
13
13
|
created: existingObject?.created || now,
|
|
14
14
|
id: existingObject?.id || stringId(),
|
|
@@ -45,7 +45,7 @@ export async function dbPipelineBackup(opt) {
|
|
|
45
45
|
if (protectFromOverwrite && fs2.pathExists(filePath)) {
|
|
46
46
|
throw new AppError(`dbPipelineBackup: output file exists: ${filePath}`);
|
|
47
47
|
}
|
|
48
|
-
const started =
|
|
48
|
+
const started = localTime.nowUnixMillis();
|
|
49
49
|
let rows = 0;
|
|
50
50
|
fs2.ensureFile(filePath);
|
|
51
51
|
// console.log(`>> ${grey(filePath)} started...`)
|
|
@@ -71,7 +71,7 @@ export async function dbPipelineBackup(opt) {
|
|
|
71
71
|
.toNDJsonFile(filePath);
|
|
72
72
|
const { size: sizeBytes } = await fs2.statAsync(filePath);
|
|
73
73
|
const stats = NDJsonStats.create({
|
|
74
|
-
tookMillis:
|
|
74
|
+
tookMillis: localTime.nowUnixMillis() - started,
|
|
75
75
|
rows,
|
|
76
76
|
sizeBytes,
|
|
77
77
|
});
|
|
@@ -26,7 +26,7 @@ export async function dbPipelineCopy(opt) {
|
|
|
26
26
|
}
|
|
27
27
|
const saveOptions = saveOptionsPerTable[table] || {};
|
|
28
28
|
const mapper = mapperPerTable[table] || _passthroughMapper;
|
|
29
|
-
const started =
|
|
29
|
+
const started = localTime.nowUnixMillis();
|
|
30
30
|
let rows = 0;
|
|
31
31
|
await dbInput
|
|
32
32
|
.streamQuery(q)
|
|
@@ -47,7 +47,7 @@ export async function dbPipelineCopy(opt) {
|
|
|
47
47
|
await dbOutput.saveBatch(table, dbms, saveOptions);
|
|
48
48
|
});
|
|
49
49
|
const stats = NDJsonStats.create({
|
|
50
|
-
tookMillis:
|
|
50
|
+
tookMillis: localTime.nowUnixMillis() - started,
|
|
51
51
|
rows,
|
|
52
52
|
sizeBytes: 0, // n/a
|
|
53
53
|
});
|
|
@@ -62,7 +62,7 @@ export async function dbPipelineRestore(opt) {
|
|
|
62
62
|
const zst = tablesToCompress.has(table);
|
|
63
63
|
const filePath = `${inputDirPath}/${table}.ndjson` + (zst ? '.zst' : '');
|
|
64
64
|
const saveOptions = saveOptionsPerTable[table] || {};
|
|
65
|
-
const started =
|
|
65
|
+
const started = localTime.nowUnixMillis();
|
|
66
66
|
let rows = 0;
|
|
67
67
|
const sizeBytes = sizeByTable[table];
|
|
68
68
|
console.log(`<< ${grey(filePath)} ${dimWhite(_hb(sizeBytes))} started...`);
|
|
@@ -86,7 +86,7 @@ export async function dbPipelineRestore(opt) {
|
|
|
86
86
|
await db.saveBatch(table, dbms, saveOptions);
|
|
87
87
|
});
|
|
88
88
|
const stats = NDJsonStats.create({
|
|
89
|
-
tookMillis:
|
|
89
|
+
tookMillis: localTime.nowUnixMillis() - started,
|
|
90
90
|
rows,
|
|
91
91
|
sizeBytes,
|
|
92
92
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _randomInt } from '@naturalcycles/js-lib';
|
|
2
2
|
import { _range } from '@naturalcycles/js-lib/array/range.js';
|
|
3
|
+
import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
3
4
|
export function createTestTimeSeries(count = 10) {
|
|
4
|
-
const ts =
|
|
5
|
+
const ts = nowUnixMillis();
|
|
5
6
|
return _range(1, count + 1).map(i => [ts - i * 60_000, _randomInt(10, 20)]);
|
|
6
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream'
|
|
2
2
|
import { _by, _sortBy } from '@naturalcycles/js-lib/array'
|
|
3
|
-
import { _since,
|
|
3
|
+
import { _since, nowUnixMillis } from '@naturalcycles/js-lib/datetime'
|
|
4
4
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
5
5
|
import { consoleLogger } from '@naturalcycles/js-lib/log'
|
|
6
6
|
import { _deepEquals, _filterUndefinedValues, _sortObjectDeep } from '@naturalcycles/js-lib/object'
|
|
@@ -236,7 +236,7 @@ export class FileDB extends BaseCommonDB implements CommonDB {
|
|
|
236
236
|
if (this.cfg.logStarted) {
|
|
237
237
|
this.cfg.logger?.log(`>> ${op}`)
|
|
238
238
|
}
|
|
239
|
-
return
|
|
239
|
+
return nowUnixMillis()
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
private logFinished(started: UnixTimestampMillis, op: string): void {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _isTruthy } from '@naturalcycles/js-lib'
|
|
2
2
|
import { _uniqBy } from '@naturalcycles/js-lib/array/array.util.js'
|
|
3
|
-
import {
|
|
3
|
+
import { nowUnix } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
4
4
|
import { _assert, ErrorMode } from '@naturalcycles/js-lib/error'
|
|
5
5
|
import { consoleLogger } from '@naturalcycles/js-lib/log'
|
|
6
6
|
import { _deepJsonEquals } from '@naturalcycles/js-lib/object/deepEquals.js'
|
|
@@ -312,7 +312,7 @@ export class CommonDao<
|
|
|
312
312
|
obj: Partial<T>,
|
|
313
313
|
opt: CommonDaoOptions = {},
|
|
314
314
|
): void {
|
|
315
|
-
const now =
|
|
315
|
+
const now = nowUnix()
|
|
316
316
|
|
|
317
317
|
if (this.cfg.useCreatedProperty) {
|
|
318
318
|
obj.created ||= obj.updated || now
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nowUnix } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
2
2
|
import type { AsyncMemoCache } from '@naturalcycles/js-lib/decorators'
|
|
3
3
|
import type { NumberOfSeconds, UnixTimestamp } from '@naturalcycles/js-lib/types'
|
|
4
4
|
import { MISS } from '@naturalcycles/js-lib/types'
|
|
@@ -29,9 +29,7 @@ export class CommonKeyValueDaoMemoCache<VALUE> implements AsyncMemoCache<string,
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
async set(k: string, v: VALUE): Promise<void> {
|
|
32
|
-
const opt = this.cfg.ttl
|
|
33
|
-
? { expireAt: (localTime.nowUnix() + this.cfg.ttl) as UnixTimestamp }
|
|
34
|
-
: undefined
|
|
32
|
+
const opt = this.cfg.ttl ? { expireAt: (nowUnix() + this.cfg.ttl) as UnixTimestamp } : undefined
|
|
35
33
|
|
|
36
34
|
await this.cfg.dao.save(k, v, opt)
|
|
37
35
|
}
|
package/src/model.util.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nowUnix } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
2
2
|
import type { CreatedUpdated, CreatedUpdatedId } from '@naturalcycles/js-lib/types'
|
|
3
3
|
import { stringId } from '@naturalcycles/nodejs-lib'
|
|
4
4
|
|
|
5
5
|
export function createdUpdatedFields(
|
|
6
6
|
existingObject?: Partial<CreatedUpdated> | null,
|
|
7
7
|
): CreatedUpdated {
|
|
8
|
-
const now =
|
|
8
|
+
const now = nowUnix()
|
|
9
9
|
return {
|
|
10
10
|
created: existingObject?.created || now,
|
|
11
11
|
updated: now,
|
|
@@ -15,7 +15,7 @@ export function createdUpdatedFields(
|
|
|
15
15
|
export function createdUpdatedIdFields(
|
|
16
16
|
existingObject?: Partial<CreatedUpdatedId> | null,
|
|
17
17
|
): CreatedUpdatedId {
|
|
18
|
-
const now =
|
|
18
|
+
const now = nowUnix()
|
|
19
19
|
return {
|
|
20
20
|
created: existingObject?.created || now,
|
|
21
21
|
id: existingObject?.id || stringId(),
|
|
@@ -192,7 +192,7 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
|
|
|
192
192
|
throw new AppError(`dbPipelineBackup: output file exists: ${filePath}`)
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
const started =
|
|
195
|
+
const started = localTime.nowUnixMillis()
|
|
196
196
|
let rows = 0
|
|
197
197
|
|
|
198
198
|
fs2.ensureFile(filePath)
|
|
@@ -224,7 +224,7 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
|
|
|
224
224
|
const { size: sizeBytes } = await fs2.statAsync(filePath)
|
|
225
225
|
|
|
226
226
|
const stats = NDJsonStats.create({
|
|
227
|
-
tookMillis:
|
|
227
|
+
tookMillis: localTime.nowUnixMillis() - started,
|
|
228
228
|
rows,
|
|
229
229
|
sizeBytes,
|
|
230
230
|
})
|
|
@@ -122,7 +122,7 @@ export async function dbPipelineCopy(opt: DBPipelineCopyOptions): Promise<NDJson
|
|
|
122
122
|
const saveOptions: CommonDBSaveOptions<any> = saveOptionsPerTable[table] || {}
|
|
123
123
|
const mapper = mapperPerTable[table] || _passthroughMapper
|
|
124
124
|
|
|
125
|
-
const started =
|
|
125
|
+
const started = localTime.nowUnixMillis()
|
|
126
126
|
let rows = 0
|
|
127
127
|
|
|
128
128
|
await dbInput
|
|
@@ -145,7 +145,7 @@ export async function dbPipelineCopy(opt: DBPipelineCopyOptions): Promise<NDJson
|
|
|
145
145
|
})
|
|
146
146
|
|
|
147
147
|
const stats = NDJsonStats.create({
|
|
148
|
-
tookMillis:
|
|
148
|
+
tookMillis: localTime.nowUnixMillis() - started,
|
|
149
149
|
rows,
|
|
150
150
|
sizeBytes: 0, // n/a
|
|
151
151
|
})
|
|
@@ -177,7 +177,7 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
|
|
|
177
177
|
const filePath = `${inputDirPath}/${table}.ndjson` + (zst ? '.zst' : '')
|
|
178
178
|
const saveOptions: CommonDBSaveOptions<any> = saveOptionsPerTable[table] || {}
|
|
179
179
|
|
|
180
|
-
const started =
|
|
180
|
+
const started = localTime.nowUnixMillis()
|
|
181
181
|
let rows = 0
|
|
182
182
|
|
|
183
183
|
const sizeBytes = sizeByTable[table]
|
|
@@ -205,7 +205,7 @@ export async function dbPipelineRestore(opt: DBPipelineRestoreOptions): Promise<
|
|
|
205
205
|
})
|
|
206
206
|
|
|
207
207
|
const stats = NDJsonStats.create({
|
|
208
|
-
tookMillis:
|
|
208
|
+
tookMillis: localTime.nowUnixMillis() - started,
|
|
209
209
|
rows,
|
|
210
210
|
sizeBytes,
|
|
211
211
|
})
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { _randomInt } from '@naturalcycles/js-lib'
|
|
2
2
|
import { _range } from '@naturalcycles/js-lib/array/range.js'
|
|
3
|
+
import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
3
4
|
import type { TimeSeriesDataPoint } from '../timeseries/timeSeries.model.js'
|
|
4
5
|
|
|
5
6
|
export function createTestTimeSeries(count = 10): TimeSeriesDataPoint[] {
|
|
6
|
-
const ts =
|
|
7
|
+
const ts = nowUnixMillis()
|
|
7
8
|
return _range(1, count + 1).map(i => [ts - i * 60_000, _randomInt(10, 20)])
|
|
8
9
|
}
|