@naturalcycles/db-lib 9.24.2 → 9.25.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.
|
@@ -968,7 +968,19 @@ class CommonDao {
|
|
|
968
968
|
}
|
|
969
969
|
else {
|
|
970
970
|
// Joi
|
|
971
|
+
const start = performance.now();
|
|
971
972
|
const vr = (0, nodejs_lib_1.getValidationResult)(obj, schema, objectName);
|
|
973
|
+
const end = performance.now();
|
|
974
|
+
const tookMillis = end - start;
|
|
975
|
+
if (this.cfg.debugValidationTimeThreshhold &&
|
|
976
|
+
tookMillis >= this.cfg.debugValidationTimeThreshhold) {
|
|
977
|
+
this.cfg.onValidationTimeThreshold?.({
|
|
978
|
+
tookMillis,
|
|
979
|
+
error: !!vr.error,
|
|
980
|
+
table,
|
|
981
|
+
obj,
|
|
982
|
+
});
|
|
983
|
+
}
|
|
972
984
|
error = vr.error;
|
|
973
985
|
convertedValue = vr.value;
|
|
974
986
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseDBEntity, CommonLogger, ErrorMode, Promisable, UnixTimestamp, ZodError, ZodSchema } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AnyObject, 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';
|
|
@@ -111,6 +111,15 @@ export interface CommonDaoCfg<BM extends BaseDBEntity, DBM extends BaseDBEntity
|
|
|
111
111
|
* If set to false - save (write) operations will skip validation (and conversion).
|
|
112
112
|
*/
|
|
113
113
|
validateOnSave?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Defaults to undefined == disabled.
|
|
116
|
+
* If set - enable the monitoring of validation time and will alert on crossing the threshold.
|
|
117
|
+
*/
|
|
118
|
+
debugValidationTimeThreshhold?: NumberOfMilliseconds;
|
|
119
|
+
/**
|
|
120
|
+
* Called when debugValidationTimeThreshhold is crossed.
|
|
121
|
+
*/
|
|
122
|
+
onValidationTimeThreshold?: (info: AnyObject) => void;
|
|
114
123
|
/**
|
|
115
124
|
* Defaults to false.
|
|
116
125
|
* Setting it to true will set saveMethod to `insert` for save/saveBatch, which will
|
package/package.json
CHANGED
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"url": "https://github.com/NaturalCycles/db-lib"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
46
|
+
"node": ">=22.10.0"
|
|
47
47
|
},
|
|
48
|
-
"version": "9.
|
|
48
|
+
"version": "9.25.0",
|
|
49
49
|
"description": "Lowest Common Denominator API to supported Databases",
|
|
50
50
|
"keywords": [
|
|
51
51
|
"db",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AnyObject,
|
|
2
3
|
BaseDBEntity,
|
|
3
4
|
CommonLogger,
|
|
4
5
|
ErrorMode,
|
|
6
|
+
NumberOfMilliseconds,
|
|
5
7
|
Promisable,
|
|
6
8
|
UnixTimestamp,
|
|
7
9
|
ZodError,
|
|
@@ -146,6 +148,17 @@ export interface CommonDaoCfg<
|
|
|
146
148
|
*/
|
|
147
149
|
validateOnSave?: boolean
|
|
148
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Defaults to undefined == disabled.
|
|
153
|
+
* If set - enable the monitoring of validation time and will alert on crossing the threshold.
|
|
154
|
+
*/
|
|
155
|
+
debugValidationTimeThreshhold?: NumberOfMilliseconds
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Called when debugValidationTimeThreshhold is crossed.
|
|
159
|
+
*/
|
|
160
|
+
onValidationTimeThreshold?: (info: AnyObject) => void
|
|
161
|
+
|
|
149
162
|
/**
|
|
150
163
|
* Defaults to false.
|
|
151
164
|
* Setting it to true will set saveMethod to `insert` for save/saveBatch, which will
|
|
@@ -1257,7 +1257,23 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM, I
|
|
|
1257
1257
|
})
|
|
1258
1258
|
} else {
|
|
1259
1259
|
// Joi
|
|
1260
|
+
const start = performance.now()
|
|
1260
1261
|
const vr = getValidationResult(obj, schema, objectName)
|
|
1262
|
+
const end = performance.now()
|
|
1263
|
+
const tookMillis = end - start
|
|
1264
|
+
|
|
1265
|
+
if (
|
|
1266
|
+
this.cfg.debugValidationTimeThreshhold &&
|
|
1267
|
+
tookMillis >= this.cfg.debugValidationTimeThreshhold
|
|
1268
|
+
) {
|
|
1269
|
+
this.cfg.onValidationTimeThreshold?.({
|
|
1270
|
+
tookMillis,
|
|
1271
|
+
error: !!vr.error,
|
|
1272
|
+
table,
|
|
1273
|
+
obj,
|
|
1274
|
+
})
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1261
1277
|
error = vr.error
|
|
1262
1278
|
convertedValue = vr.value
|
|
1263
1279
|
}
|