@mondart/nestjs-common-module 2.4.0 → 2.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/strategy/index.d.ts +1 -0
- package/dist/strategy/index.js +1 -0
- package/dist/strategy/type-orm-logger.strategy.d.ts +10 -0
- package/dist/strategy/type-orm-logger.strategy.js +75 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/validators/is-date-range.validator.d.ts +1 -1
- package/dist/validators/is-date-range.validator.js +19 -12
- package/package.json +2 -1
package/dist/strategy/index.d.ts
CHANGED
package/dist/strategy/index.js
CHANGED
|
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./type-orm-naming.strategy"), exports);
|
|
18
|
+
__exportStar(require("./type-orm-logger.strategy"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AdvancedConsoleLogger } from 'typeorm';
|
|
2
|
+
export declare class TypeOrmLoggerStrategy extends AdvancedConsoleLogger {
|
|
3
|
+
private logger;
|
|
4
|
+
logQuery(query: string, params?: unknown[]): void;
|
|
5
|
+
logQueryError(error: string | Error, query: string, params?: unknown[]): void;
|
|
6
|
+
logQuerySlow(time: number, query: string, params?: unknown[]): void;
|
|
7
|
+
logSchemaBuild(msg: string): void;
|
|
8
|
+
logMigration(msg: string): void;
|
|
9
|
+
log(level: 'log' | 'info' | 'warn', msg: any): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeOrmLoggerStrategy = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const Sentry = require("@sentry/nestjs");
|
|
7
|
+
class TypeOrmLoggerStrategy extends typeorm_1.AdvancedConsoleLogger {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.logger = new common_1.Logger('TypeOrmModuleLogger');
|
|
11
|
+
}
|
|
12
|
+
logQuery(query, params) {
|
|
13
|
+
if (!this.isLogEnabledFor('query')) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this.logger.debug(`Query: ${query} -- ${JSON.stringify(params)}`);
|
|
17
|
+
}
|
|
18
|
+
logQueryError(error, query, params) {
|
|
19
|
+
Sentry.captureException(error, {
|
|
20
|
+
extra: {
|
|
21
|
+
query,
|
|
22
|
+
params,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
if (!this.isLogEnabledFor('query-error')) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.logger.error(`Query Error: ${query}`, error);
|
|
29
|
+
}
|
|
30
|
+
logQuerySlow(time, query, params) {
|
|
31
|
+
Sentry.captureMessage('Slow SQL Query', {
|
|
32
|
+
level: 'warning',
|
|
33
|
+
extra: {
|
|
34
|
+
durationMs: time,
|
|
35
|
+
query,
|
|
36
|
+
params,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (!this.isLogEnabledFor('query-slow')) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.logger.warn(`Slow Query (${time} ms): ${query}`);
|
|
43
|
+
}
|
|
44
|
+
logSchemaBuild(msg) {
|
|
45
|
+
if (!this.isLogEnabledFor('schema-build')) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this.logger.log(msg);
|
|
49
|
+
}
|
|
50
|
+
logMigration(msg) {
|
|
51
|
+
if (!this.isLogEnabledFor('migration')) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.logger.log(msg);
|
|
55
|
+
}
|
|
56
|
+
log(level, msg) {
|
|
57
|
+
if (level === 'warn') {
|
|
58
|
+
Sentry.captureMessage('Query Warning', {
|
|
59
|
+
level: 'warning',
|
|
60
|
+
extra: {
|
|
61
|
+
msg,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
if (!this.isLogEnabledFor('warn')) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
return this.logger.warn(msg);
|
|
68
|
+
}
|
|
69
|
+
if (!this.isLogEnabledFor('log') || !this.isLogEnabledFor('info')) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
return this.logger.log(msg);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.TypeOrmLoggerStrategy = TypeOrmLoggerStrategy;
|