@naturalcycles/db-lib 9.26.0 → 9.26.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.
- package/dist/adapter/file/file.db.js +1 -1
- package/dist/adapter/inmemory/inMemory.db.js +2 -2
- package/dist/commondao/common.dao.js +9 -14
- package/dist/commondao/common.dao.model.d.ts +10 -8
- package/package.json +1 -1
- package/src/adapter/file/file.db.ts +2 -1
- package/src/adapter/inmemory/inMemory.db.ts +3 -3
- package/src/commondao/common.dao.model.ts +10 -9
- package/src/commondao/common.dao.ts +10 -17
|
@@ -160,7 +160,7 @@ class FileDB extends __1.BaseCommonDB {
|
|
|
160
160
|
if (this.cfg.logStarted) {
|
|
161
161
|
this.cfg.logger?.log(`>> ${op}`);
|
|
162
162
|
}
|
|
163
|
-
return
|
|
163
|
+
return js_lib_1.localTime.nowUnixMillis();
|
|
164
164
|
}
|
|
165
165
|
logFinished(started, op) {
|
|
166
166
|
if (!this.cfg.logFinished)
|
|
@@ -166,7 +166,7 @@ class InMemoryDB {
|
|
|
166
166
|
async flushToDisk() {
|
|
167
167
|
(0, js_lib_1._assert)(this.cfg.persistenceEnabled, 'flushToDisk() called but persistenceEnabled=false');
|
|
168
168
|
const { persistentStoragePath, persistZip } = this.cfg;
|
|
169
|
-
const started =
|
|
169
|
+
const started = js_lib_1.localTime.nowUnixMillis();
|
|
170
170
|
await nodejs_lib_1.fs2.emptyDirAsync(persistentStoragePath);
|
|
171
171
|
let tables = 0;
|
|
172
172
|
// infinite concurrency for now
|
|
@@ -186,7 +186,7 @@ class InMemoryDB {
|
|
|
186
186
|
async restoreFromDisk() {
|
|
187
187
|
(0, js_lib_1._assert)(this.cfg.persistenceEnabled, 'restoreFromDisk() called but persistenceEnabled=false');
|
|
188
188
|
const { persistentStoragePath } = this.cfg;
|
|
189
|
-
const started =
|
|
189
|
+
const started = js_lib_1.localTime.nowUnixMillis();
|
|
190
190
|
await nodejs_lib_1.fs2.ensureDirAsync(persistentStoragePath);
|
|
191
191
|
this.data = {}; // empty it in the beginning!
|
|
192
192
|
const files = (await nodejs_lib_1.fs2.readdirAsync(persistentStoragePath)).filter(f => f.includes('.ndjson'));
|
|
@@ -978,19 +978,14 @@ class CommonDao {
|
|
|
978
978
|
}
|
|
979
979
|
else {
|
|
980
980
|
// Joi
|
|
981
|
-
const start =
|
|
981
|
+
const start = js_lib_1.localTime.nowUnixMillis();
|
|
982
982
|
const vr = (0, nodejs_lib_1.getValidationResult)(obj, schema, objectName);
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
error: !!vr.error,
|
|
990
|
-
table,
|
|
991
|
-
obj,
|
|
992
|
-
});
|
|
993
|
-
}
|
|
983
|
+
const tookMillis = js_lib_1.localTime.nowUnixMillis() - start;
|
|
984
|
+
this.cfg.onValidationTime?.({
|
|
985
|
+
tookMillis,
|
|
986
|
+
table,
|
|
987
|
+
obj,
|
|
988
|
+
});
|
|
994
989
|
error = vr.error;
|
|
995
990
|
convertedValue = vr.value;
|
|
996
991
|
}
|
|
@@ -1073,7 +1068,7 @@ class CommonDao {
|
|
|
1073
1068
|
if (this.cfg.logStarted || force) {
|
|
1074
1069
|
this.cfg.logger?.log(`>> ${table}.${op}`);
|
|
1075
1070
|
}
|
|
1076
|
-
return
|
|
1071
|
+
return js_lib_1.localTime.nowUnixMillis();
|
|
1077
1072
|
}
|
|
1078
1073
|
logSaveStarted(op, items, table) {
|
|
1079
1074
|
if (this.cfg.logStarted) {
|
|
@@ -1093,7 +1088,7 @@ class CommonDao {
|
|
|
1093
1088
|
}
|
|
1094
1089
|
this.cfg.logger?.log(...args);
|
|
1095
1090
|
}
|
|
1096
|
-
return
|
|
1091
|
+
return js_lib_1.localTime.nowUnixMillis();
|
|
1097
1092
|
}
|
|
1098
1093
|
}
|
|
1099
1094
|
exports.CommonDao = CommonDao;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseDBEntity, CommonLogger, ErrorMode, NumberOfMilliseconds, Promisable, UnixTimestamp, ZodError, ZodSchema } from '@naturalcycles/js-lib';
|
|
2
2
|
import { AjvSchema, AjvValidationError, JoiValidationError, ObjectSchema, TransformLogProgressOptions, TransformMapOptions } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import { CommonDB } from '../common.db';
|
|
4
4
|
import { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions } from '../db.model';
|
|
@@ -112,14 +112,11 @@ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
112
112
|
*/
|
|
113
113
|
validateOnSave?: boolean;
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
|
|
118
|
-
debugValidationTimeThreshhold?: NumberOfMilliseconds;
|
|
119
|
-
/**
|
|
120
|
-
* Called when debugValidationTimeThreshhold is crossed.
|
|
115
|
+
* The hook allows to get a callback, to instrument "validation time".
|
|
116
|
+
*
|
|
117
|
+
* @experimental
|
|
121
118
|
*/
|
|
122
|
-
|
|
119
|
+
onValidationTime?: (data: OnValidationTimeData) => void;
|
|
123
120
|
/**
|
|
124
121
|
* Defaults to false.
|
|
125
122
|
* Setting it to true will set saveMethod to `insert` for save/saveBatch, which will
|
|
@@ -288,3 +285,8 @@ export interface CommonDaoStreamOptions<IN> extends CommonDaoReadOptions, Transf
|
|
|
288
285
|
chunkConcurrency?: number;
|
|
289
286
|
}
|
|
290
287
|
export type CommonDaoCreateOptions = CommonDBCreateOptions;
|
|
288
|
+
export interface OnValidationTimeData {
|
|
289
|
+
tookMillis: NumberOfMilliseconds;
|
|
290
|
+
table: string;
|
|
291
|
+
obj: any;
|
|
292
|
+
}
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
_stringMapValues,
|
|
10
10
|
generateJsonSchemaFromData,
|
|
11
11
|
JsonSchemaRootObject,
|
|
12
|
+
localTime,
|
|
12
13
|
ObjectWithId,
|
|
13
14
|
UnixTimestampMillis,
|
|
14
15
|
} from '@naturalcycles/js-lib'
|
|
@@ -245,7 +246,7 @@ export class FileDB extends BaseCommonDB implements CommonDB {
|
|
|
245
246
|
if (this.cfg.logStarted) {
|
|
246
247
|
this.cfg.logger?.log(`>> ${op}`)
|
|
247
248
|
}
|
|
248
|
-
return
|
|
249
|
+
return localTime.nowUnixMillis()
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
private logFinished(started: UnixTimestampMillis, op: string): void {
|
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
generateJsonSchemaFromData,
|
|
14
14
|
JsonSchemaObject,
|
|
15
15
|
JsonSchemaRootObject,
|
|
16
|
+
localTime,
|
|
16
17
|
ObjectWithId,
|
|
17
18
|
pMap,
|
|
18
19
|
StringMap,
|
|
19
|
-
UnixTimestampMillis,
|
|
20
20
|
} from '@naturalcycles/js-lib'
|
|
21
21
|
import {
|
|
22
22
|
_pipeline,
|
|
@@ -315,7 +315,7 @@ export class InMemoryDB implements CommonDB {
|
|
|
315
315
|
_assert(this.cfg.persistenceEnabled, 'flushToDisk() called but persistenceEnabled=false')
|
|
316
316
|
const { persistentStoragePath, persistZip } = this.cfg
|
|
317
317
|
|
|
318
|
-
const started =
|
|
318
|
+
const started = localTime.nowUnixMillis()
|
|
319
319
|
|
|
320
320
|
await fs2.emptyDirAsync(persistentStoragePath)
|
|
321
321
|
|
|
@@ -344,7 +344,7 @@ export class InMemoryDB implements CommonDB {
|
|
|
344
344
|
_assert(this.cfg.persistenceEnabled, 'restoreFromDisk() called but persistenceEnabled=false')
|
|
345
345
|
const { persistentStoragePath } = this.cfg
|
|
346
346
|
|
|
347
|
-
const started =
|
|
347
|
+
const started = localTime.nowUnixMillis()
|
|
348
348
|
|
|
349
349
|
await fs2.ensureDirAsync(persistentStoragePath)
|
|
350
350
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AnyObject,
|
|
3
2
|
BaseDBEntity,
|
|
4
3
|
CommonLogger,
|
|
5
4
|
ErrorMode,
|
|
@@ -149,15 +148,11 @@ export interface CommonDaoCfg<
|
|
|
149
148
|
validateOnSave?: boolean
|
|
150
149
|
|
|
151
150
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
|
|
155
|
-
debugValidationTimeThreshhold?: NumberOfMilliseconds
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Called when debugValidationTimeThreshhold is crossed.
|
|
151
|
+
* The hook allows to get a callback, to instrument "validation time".
|
|
152
|
+
*
|
|
153
|
+
* @experimental
|
|
159
154
|
*/
|
|
160
|
-
|
|
155
|
+
onValidationTime?: (data: OnValidationTimeData) => void
|
|
161
156
|
|
|
162
157
|
/**
|
|
163
158
|
* Defaults to false.
|
|
@@ -365,3 +360,9 @@ export interface CommonDaoStreamOptions<IN>
|
|
|
365
360
|
}
|
|
366
361
|
|
|
367
362
|
export type CommonDaoCreateOptions = CommonDBCreateOptions
|
|
363
|
+
|
|
364
|
+
export interface OnValidationTimeData {
|
|
365
|
+
tookMillis: NumberOfMilliseconds
|
|
366
|
+
table: string
|
|
367
|
+
obj: any
|
|
368
|
+
}
|
|
@@ -1267,22 +1267,15 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1267
1267
|
})
|
|
1268
1268
|
} else {
|
|
1269
1269
|
// Joi
|
|
1270
|
-
const start =
|
|
1270
|
+
const start = localTime.nowUnixMillis()
|
|
1271
1271
|
const vr = getValidationResult(obj, schema, objectName)
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
)
|
|
1279
|
-
this.cfg.onValidationTimeThreshold?.({
|
|
1280
|
-
tookMillis,
|
|
1281
|
-
error: !!vr.error,
|
|
1282
|
-
table,
|
|
1283
|
-
obj,
|
|
1284
|
-
})
|
|
1285
|
-
}
|
|
1272
|
+
const tookMillis = localTime.nowUnixMillis() - start
|
|
1273
|
+
|
|
1274
|
+
this.cfg.onValidationTime?.({
|
|
1275
|
+
tookMillis,
|
|
1276
|
+
table,
|
|
1277
|
+
obj,
|
|
1278
|
+
})
|
|
1286
1279
|
|
|
1287
1280
|
error = vr.error
|
|
1288
1281
|
convertedValue = vr.value
|
|
@@ -1384,7 +1377,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1384
1377
|
if (this.cfg.logStarted || force) {
|
|
1385
1378
|
this.cfg.logger?.log(`>> ${table}.${op}`)
|
|
1386
1379
|
}
|
|
1387
|
-
return
|
|
1380
|
+
return localTime.nowUnixMillis()
|
|
1388
1381
|
}
|
|
1389
1382
|
|
|
1390
1383
|
protected logSaveStarted(op: string, items: any, table: string): UnixTimestampMillis {
|
|
@@ -1405,7 +1398,7 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1405
1398
|
this.cfg.logger?.log(...args)
|
|
1406
1399
|
}
|
|
1407
1400
|
|
|
1408
|
-
return
|
|
1401
|
+
return localTime.nowUnixMillis()
|
|
1409
1402
|
}
|
|
1410
1403
|
}
|
|
1411
1404
|
|