@rsdk/db.typeorm 6.0.0-next.2 → 6.0.0-next.20
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/providers/typeorm-logger.adapter.d.ts +3 -1
- package/dist/providers/typeorm-logger.adapter.js +7 -5
- package/dist/providers/typeorm-logger.adapter.js.map +1 -1
- package/dist/providers/typeorm.config.d.ts +1 -0
- package/dist/providers/typeorm.config.js +25 -8
- package/dist/providers/typeorm.config.js.map +1 -1
- package/dist/typeorm.errors-transformer.d.ts +2 -1
- package/dist/typeorm.errors-transformer.js +8 -7
- package/dist/typeorm.errors-transformer.js.map +1 -1
- package/dist/typeorm.plugin.js +1 -1
- package/dist/typeorm.plugin.js.map +1 -1
- package/dist/types.d.ts +18 -0
- package/dist/types.js.map +1 -1
- package/package.json +5 -4
- package/src/providers/typeorm-logger.adapter.ts +7 -3
- package/src/providers/typeorm.config.ts +20 -6
- package/src/typeorm.errors-transformer.ts +6 -9
- package/src/typeorm.plugin.ts +1 -1
- package/src/types.ts +21 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ILogger } from '@rsdk/logging';
|
|
2
2
|
import type { Logger } from 'typeorm';
|
|
3
|
+
import { TypeOrmPluginConfig } from './typeorm.config';
|
|
3
4
|
export declare class TypeOrmLoggerAdapter implements Logger {
|
|
5
|
+
private readonly config;
|
|
4
6
|
private platformLogger;
|
|
5
|
-
constructor(platformLogger: ILogger);
|
|
7
|
+
constructor(config: TypeOrmPluginConfig, platformLogger: ILogger);
|
|
6
8
|
logQuery(query: string, parameters?: any[]): any;
|
|
7
9
|
logMigration(message: string): any;
|
|
8
10
|
formatParts(...parts: (string | boolean | undefined)[]): string;
|
|
@@ -15,15 +15,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.TypeOrmLoggerAdapter = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
17
|
const core_1 = require("@rsdk/core");
|
|
18
|
-
const
|
|
18
|
+
const typeorm_config_1 = require("./typeorm.config");
|
|
19
19
|
let TypeOrmLoggerAdapter = class TypeOrmLoggerAdapter {
|
|
20
|
+
config;
|
|
20
21
|
platformLogger;
|
|
21
|
-
constructor(platformLogger) {
|
|
22
|
+
constructor(config, platformLogger) {
|
|
23
|
+
this.config = config;
|
|
22
24
|
this.platformLogger = platformLogger;
|
|
23
25
|
}
|
|
24
26
|
logQuery(query, parameters) {
|
|
25
27
|
const message = this.formatParts(`query: ${query}`, parameters && `parameters: ${JSON.stringify(parameters)}`);
|
|
26
|
-
if (query
|
|
28
|
+
if (this.config.traceOnlyQueriesPattern.test(query)) {
|
|
27
29
|
this.platformLogger.trace(message);
|
|
28
30
|
}
|
|
29
31
|
else {
|
|
@@ -62,7 +64,7 @@ let TypeOrmLoggerAdapter = class TypeOrmLoggerAdapter {
|
|
|
62
64
|
exports.TypeOrmLoggerAdapter = TypeOrmLoggerAdapter;
|
|
63
65
|
exports.TypeOrmLoggerAdapter = TypeOrmLoggerAdapter = __decorate([
|
|
64
66
|
(0, common_1.Injectable)(),
|
|
65
|
-
__param(
|
|
66
|
-
__metadata("design:paramtypes", [Object])
|
|
67
|
+
__param(1, (0, core_1.InjectLogger)('TypeOrm')),
|
|
68
|
+
__metadata("design:paramtypes", [typeorm_config_1.TypeOrmPluginConfig, Object])
|
|
67
69
|
], TypeOrmLoggerAdapter);
|
|
68
70
|
//# sourceMappingURL=typeorm-logger.adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm-logger.adapter.js","sourceRoot":"","sources":["../../src/providers/typeorm-logger.adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAA0C;
|
|
1
|
+
{"version":3,"file":"typeorm-logger.adapter.js","sourceRoot":"","sources":["../../src/providers/typeorm-logger.adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAA0C;AAI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AAE;YACjC,UAAU,KAAK,EAAE;YACjB,UAAU,IAAI,eAAe,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;SAC1D,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC,CAAC;QAE3C,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,cAAc,CAAC,OAAe;QAC5B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,GAAG,CAAC,KAA8B,EAAE,OAAY;QAC9C,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AA3DY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,mBAAY,EAAC,SAAS,CAAC,CAAA;qCADC,oCAAmB;GAFnC,oBAAoB,CA2DhC"}
|
|
@@ -21,16 +21,17 @@ let TypeOrmPluginConfig = class TypeOrmPluginConfig extends core_1.Config {
|
|
|
21
21
|
reconnectInterval;
|
|
22
22
|
keepAlive;
|
|
23
23
|
keepAliveInitialDelay;
|
|
24
|
+
traceOnlyQueriesPattern;
|
|
24
25
|
};
|
|
25
26
|
exports.TypeOrmPluginConfig = TypeOrmPluginConfig;
|
|
26
27
|
__decorate([
|
|
27
|
-
(0, core_1.Property)('URL', new
|
|
28
|
+
(0, core_1.Property)('URL', new common_1.UrlParser(), {
|
|
28
29
|
description: 'Database server url',
|
|
29
30
|
}),
|
|
30
31
|
__metadata("design:type", URL)
|
|
31
32
|
], TypeOrmPluginConfig.prototype, "url", void 0);
|
|
32
33
|
__decorate([
|
|
33
|
-
(0, core_1.Property)('SCHEMA', new
|
|
34
|
+
(0, core_1.Property)('SCHEMA', new common_1.StringParser(), {
|
|
34
35
|
description: (0, common_1.text) `
|
|
35
36
|
Use schema for all entities.
|
|
36
37
|
**Only for postgres at the moment!**
|
|
@@ -40,7 +41,7 @@ __decorate([
|
|
|
40
41
|
__metadata("design:type", String)
|
|
41
42
|
], TypeOrmPluginConfig.prototype, "schema", void 0);
|
|
42
43
|
__decorate([
|
|
43
|
-
(0, core_1.Property)('POOL_MIN', new
|
|
44
|
+
(0, core_1.Property)('POOL_MIN', new common_1.IntParser(), {
|
|
44
45
|
defaultValue: 1,
|
|
45
46
|
description: (0, common_1.text) `
|
|
46
47
|
Minimum connection pool size.
|
|
@@ -50,7 +51,7 @@ __decorate([
|
|
|
50
51
|
__metadata("design:type", Number)
|
|
51
52
|
], TypeOrmPluginConfig.prototype, "poolMin", void 0);
|
|
52
53
|
__decorate([
|
|
53
|
-
(0, core_1.Property)('POOL_MAX', new
|
|
54
|
+
(0, core_1.Property)('POOL_MAX', new common_1.IntParser(), {
|
|
54
55
|
defaultValue: 10,
|
|
55
56
|
description: (0, common_1.text) `
|
|
56
57
|
Maximum connection pool size.
|
|
@@ -60,21 +61,21 @@ __decorate([
|
|
|
60
61
|
__metadata("design:type", Number)
|
|
61
62
|
], TypeOrmPluginConfig.prototype, "poolMax", void 0);
|
|
62
63
|
__decorate([
|
|
63
|
-
(0, core_1.Property)('RECONNECT_ATTEMPTS', new
|
|
64
|
+
(0, core_1.Property)('RECONNECT_ATTEMPTS', new common_1.IntParser(), {
|
|
64
65
|
defaultValue: Number.POSITIVE_INFINITY,
|
|
65
66
|
description: 'Retry attempt count before give up',
|
|
66
67
|
}),
|
|
67
68
|
__metadata("design:type", Number)
|
|
68
69
|
], TypeOrmPluginConfig.prototype, "reconnectAttempts", void 0);
|
|
69
70
|
__decorate([
|
|
70
|
-
(0, core_1.Property)('RECONNECT_INTERVAL', new
|
|
71
|
+
(0, core_1.Property)('RECONNECT_INTERVAL', new common_1.TimespanParser(), {
|
|
71
72
|
defaultValue: new common_1.Timespan(1, 's'),
|
|
72
73
|
description: 'Delay between retries',
|
|
73
74
|
}),
|
|
74
75
|
__metadata("design:type", common_1.Timespan)
|
|
75
76
|
], TypeOrmPluginConfig.prototype, "reconnectInterval", void 0);
|
|
76
77
|
__decorate([
|
|
77
|
-
(0, core_1.Property)('KEEP_ALIVE', new
|
|
78
|
+
(0, core_1.Property)('KEEP_ALIVE', new common_1.BoolParser(), {
|
|
78
79
|
defaultValue: true,
|
|
79
80
|
description: (0, common_1.text) `
|
|
80
81
|
Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.
|
|
@@ -85,7 +86,7 @@ __decorate([
|
|
|
85
86
|
__metadata("design:type", Boolean)
|
|
86
87
|
], TypeOrmPluginConfig.prototype, "keepAlive", void 0);
|
|
87
88
|
__decorate([
|
|
88
|
-
(0, core_1.Property)('KEEP_ALIVE_INITIAL_DELAY', new
|
|
89
|
+
(0, core_1.Property)('KEEP_ALIVE_INITIAL_DELAY', new common_1.IntParser(), {
|
|
89
90
|
defaultValue: undefined,
|
|
90
91
|
description: (0, common_1.text) `
|
|
91
92
|
Set initialDelay (in milliseconds) to set the delay between the last data packet received and the first keepalive probe.
|
|
@@ -95,6 +96,22 @@ __decorate([
|
|
|
95
96
|
}),
|
|
96
97
|
__metadata("design:type", Number)
|
|
97
98
|
], TypeOrmPluginConfig.prototype, "keepAliveInitialDelay", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, core_1.Property)('TRACE_ONLY_QUERIES_PATTERN', new common_1.RegexParser(), {
|
|
101
|
+
defaultValue: /^SELECT 1$/,
|
|
102
|
+
description: (0, common_1.text) `
|
|
103
|
+
Regex pattern for SQL queries that should be logged with TRACE level instead of DEBUG.
|
|
104
|
+
This is useful to reduce log verbosity for health checks and transaction control queries.
|
|
105
|
+
|
|
106
|
+
Default pattern matches: SELECT 1 (health check query)
|
|
107
|
+
|
|
108
|
+
You can override this pattern via environment variable. Provide the regex pattern as a string.
|
|
109
|
+
|
|
110
|
+
Example: DB_TRACE_ONLY_QUERIES_PATTERN="^(START TRANSACTION|BEGIN|COMMIT|SAVEPOINT\\s+)$"
|
|
111
|
+
`,
|
|
112
|
+
}),
|
|
113
|
+
__metadata("design:type", RegExp)
|
|
114
|
+
], TypeOrmPluginConfig.prototype, "traceOnlyQueriesPattern", void 0);
|
|
98
115
|
exports.TypeOrmPluginConfig = TypeOrmPluginConfig = __decorate([
|
|
99
116
|
(0, core_1.ConfigSection)({
|
|
100
117
|
name: 'typeorm database config',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm.config.js","sourceRoot":"","sources":["../../src/providers/typeorm.config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"typeorm.config.js","sourceRoot":"","sources":["../../src/providers/typeorm.config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCASsB;AACtB,qCAAwE;AAOjE,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,aAAM;IAI7C,GAAG,CAAO;IASV,MAAM,CAAU;IAShB,OAAO,CAAU;IASjB,OAAO,CAAU;IAMjB,iBAAiB,CAAU;IAM3B,iBAAiB,CAAY;IAU7B,SAAS,CAAW;IAUpB,qBAAqB,CAAU;IAe/B,uBAAuB,CAAU;CAClC,CAAA;AA/EY,kDAAmB;AAI9B;IAHC,IAAA,eAAQ,EAAC,KAAK,EAAE,IAAI,kBAAS,EAAE,EAAE;QAChC,WAAW,EAAE,qBAAqB;KACnC,CAAC;8BACI,GAAG;gDAAC;AASV;IAPC,IAAA,eAAQ,EAAC,QAAQ,EAAE,IAAI,qBAAY,EAAE,EAAE;QACtC,WAAW,EAAE,IAAA,aAAI,EAAA;;;KAGhB;QACD,YAAY,EAAE,SAAS;KACxB,CAAC;;mDACc;AAShB;IAPC,IAAA,eAAQ,EAAC,UAAU,EAAE,IAAI,k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EAAE,gBAAS,CAAC,OAAO,CAAC;QACnD,MAAM,EAAE,IAAI;KACb,CAAC;GACW,mBAAmB,CA+E/B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IErrorsTransformer, PipelineException } from '@rsdk/core';
|
|
2
|
+
import { TypeORMError } from 'typeorm';
|
|
2
3
|
export declare class TypeOrmErrorTransformer implements IErrorsTransformer {
|
|
3
4
|
match(ex: unknown): boolean;
|
|
4
|
-
transform(ex:
|
|
5
|
+
transform(ex: TypeORMError): PipelineException;
|
|
5
6
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.TypeOrmErrorTransformer = void 0;
|
|
4
7
|
const core_1 = require("@rsdk/core");
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
5
9
|
const typeorm_1 = require("typeorm");
|
|
6
10
|
class TypeOrmErrorTransformer {
|
|
7
11
|
match(ex) {
|
|
@@ -10,15 +14,12 @@ class TypeOrmErrorTransformer {
|
|
|
10
14
|
transform(ex) {
|
|
11
15
|
if (ex instanceof typeorm_1.EntityNotFoundError) {
|
|
12
16
|
return new core_1.NotFoundException(ex.message, {
|
|
13
|
-
cause: ex,
|
|
17
|
+
cause: lodash_1.default.omit(ex, 'entityClass'),
|
|
14
18
|
});
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
throw new Error('unknown exception');
|
|
20
|
+
return new core_1.InternalException(ex.message, {
|
|
21
|
+
cause: lodash_1.default.omit(ex, 'entityClass'),
|
|
22
|
+
});
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
exports.TypeOrmErrorTransformer = TypeOrmErrorTransformer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm.errors-transformer.js","sourceRoot":"","sources":["../src/typeorm.errors-transformer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeorm.errors-transformer.js","sourceRoot":"","sources":["../src/typeorm.errors-transformer.ts"],"names":[],"mappings":";;;;;;AACA,qCAAkE;AAClE,oDAAuB;AACvB,qCAA4D;AAE5D,MAAa,uBAAuB;IAClC,KAAK,CAAC,EAAW;QACf,OAAO,EAAE,YAAY,sBAAY,CAAC;IACpC,CAAC;IAED,SAAS,CAAC,EAAgB;QACxB,IAAI,EAAE,YAAY,6BAAmB,EAAE,CAAC;YACtC,OAAO,IAAI,wBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE;gBACvC,KAAK,EAAE,gBAAC,CAAC,IAAI,CAAC,EAAE,EAAE,aAAa,CAAC;aACjC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,wBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE;YACvC,KAAK,EAAE,gBAAC,CAAC,IAAI,CAAC,EAAE,EAAE,aAAa,CAAC;SACjC,CAAC,CAAC;IACL,CAAC;CACF;AAhBD,0DAgBC"}
|
package/dist/typeorm.plugin.js
CHANGED
|
@@ -84,7 +84,7 @@ class TypeOrmPlugin {
|
|
|
84
84
|
];
|
|
85
85
|
}
|
|
86
86
|
errorTransformers() {
|
|
87
|
-
return [new typeorm_errors_transformer_1.TypeOrmErrorTransformer()];
|
|
87
|
+
return this.options.errorTransformers ?? [new typeorm_errors_transformer_1.TypeOrmErrorTransformer()];
|
|
88
88
|
}
|
|
89
89
|
getMigrationsOption() {
|
|
90
90
|
return [node_path_1.default.resolve(process.cwd(), 'dist/typeorm/migrations/**.js')];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm.plugin.js","sourceRoot":"","sources":["../src/typeorm.plugin.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;;;;AAIjD,6CAAgD;A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,EAAE;oBAC7C,aAAa,EAAE,MAAM,CAAC,iBAAiB;oBACvC,eAAe,EAAE,OAAO,GAAG,UAAU;oBACrC,KAAK,EAAE;wBACL,GAAG,EAAE,MAAM,CAAC,OAAO;wBACnB,GAAG,EAAE,MAAM,CAAC,OAAO;wBACnB,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,qBAAqB,EAAE,MAAM,CAAC,qBAAqB;qBACpD;oBACD,UAAU;oBACV,mBAAmB,EAAE,oBAAoB;oBACzC,GAAI,IAAI,CAAC,OAAO,CAAC,cAAsB;iBACxC,CAAC;gBACF,iBAAiB,EAAE,CAAC,OAA2B,EAAE,EAAE;oBACjD,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,MAAM,IAAI,oCAAuB,EAAE,CAAC;oBACtC,CAAC;oBACD,OAAO,wFAAwC,CAAC,MAAM,CACpD,OAAO,CACR,CAAC,UAAU,EAAE,CAAC;gBACjB,CAAC;aACF,CAAC;YACF,iDAAsB;SACvB,CAAC;IACJ,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,IAAI,CAAC,IAAI,oDAAuB,EAAE,CAAC,CAAC;IAC3E,CAAC;IAEO,mBAAmB;QACzB,OAAO,CAAC,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,+BAA+B,CAAC,CAAC,CAAC;IACxE,CAAC;;AApFH,sCAqFC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import type { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|
2
|
+
import type { IErrorsTransformer } from '@rsdk/core';
|
|
2
3
|
export interface TypeOrmPluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Тип драйвера
|
|
6
|
+
*/
|
|
3
7
|
type: NonNullable<TypeOrmModuleOptions['type']>;
|
|
8
|
+
/**
|
|
9
|
+
* Сущности. Если массив сущностей не задан - будет
|
|
10
|
+
* использована опция autoLoadEntities.
|
|
11
|
+
*/
|
|
4
12
|
entities?: (string | any)[];
|
|
13
|
+
/**
|
|
14
|
+
* Дополнительные конфигурационные параметры
|
|
15
|
+
*/
|
|
5
16
|
overrideConfig?: Partial<Omit<TypeOrmModuleOptions, 'type'>>;
|
|
17
|
+
/**
|
|
18
|
+
* Трансформеры ошибок.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: Если значение задаётся - трансформер по умолчанию
|
|
21
|
+
* не добавляется!
|
|
22
|
+
*/
|
|
23
|
+
errorTransformers?: IErrorsTransformer[];
|
|
6
24
|
}
|
|
7
25
|
export declare enum IsolationLevel {
|
|
8
26
|
READ_UNCOMMITTED = "READ UNCOMMITTED",
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA6BA,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,uDAAqC,CAAA;IACrC,mDAAiC,CAAA;IACjC,qDAAmC,CAAA;IACnC,+CAA6B,CAAA;AAC/B,CAAC,EALW,cAAc,8BAAd,cAAc,QAKzB;AAEY,QAAA,eAAe,GAA8B;IACxD,cAAc,CAAC,gBAAgB;IAC/B,cAAc,CAAC,cAAc;IAC7B,cAAc,CAAC,eAAe;IAC9B,cAAc,CAAC,YAAY;CAC5B,CAAC;AAEW,QAAA,uBAAuB,GAAG,cAAc,CAAC,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/db.typeorm",
|
|
3
|
-
"version": "6.0.0-next.
|
|
3
|
+
"version": "6.0.0-next.20",
|
|
4
4
|
"description": "TypeOrm module for platform",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"prepublishOnly": "npm run build"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@nestjs/common": "
|
|
18
|
-
"@nestjs/core": "
|
|
17
|
+
"@nestjs/common": "<=10.4.8",
|
|
18
|
+
"@nestjs/core": "<=10.4.8",
|
|
19
19
|
"@nestjs/typeorm": "^10.0.0",
|
|
20
20
|
"@rsdk/common": "*",
|
|
21
21
|
"@rsdk/common.nestjs": "*",
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
"@rsdk/db": "*",
|
|
25
25
|
"@rsdk/logging": "*",
|
|
26
26
|
"@rsdk/nest-tools": "*",
|
|
27
|
+
"lodash": "^4.17.21",
|
|
27
28
|
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
28
29
|
"rxjs": "^7.8.1",
|
|
29
30
|
"typeorm": "^0.3.12"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "8967e1d9b691808f5e0b4c6d6dff0fefae3b2c32"
|
|
32
33
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import { InjectLogger } from '@rsdk/core';
|
|
3
|
-
import { HEALTH_CHECK_QUERY } from '@rsdk/db';
|
|
4
3
|
import { ILogger } from '@rsdk/logging';
|
|
5
4
|
import type { Logger } from 'typeorm';
|
|
6
5
|
|
|
6
|
+
import { TypeOrmPluginConfig } from './typeorm.config';
|
|
7
|
+
|
|
7
8
|
@Injectable()
|
|
8
9
|
export class TypeOrmLoggerAdapter implements Logger {
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly config: TypeOrmPluginConfig,
|
|
12
|
+
@InjectLogger('TypeOrm') private platformLogger: ILogger,
|
|
13
|
+
) {}
|
|
10
14
|
|
|
11
15
|
logQuery(query: string, parameters?: any[]): any {
|
|
12
16
|
const message = this.formatParts(
|
|
@@ -14,7 +18,7 @@ export class TypeOrmLoggerAdapter implements Logger {
|
|
|
14
18
|
parameters && `parameters: ${JSON.stringify(parameters)}`,
|
|
15
19
|
);
|
|
16
20
|
|
|
17
|
-
if (query
|
|
21
|
+
if (this.config.traceOnlyQueriesPattern.test(query)) {
|
|
18
22
|
this.platformLogger.trace(message);
|
|
19
23
|
} else {
|
|
20
24
|
this.platformLogger.debug(message);
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { text, Timespan } from '@rsdk/common';
|
|
2
1
|
import {
|
|
3
2
|
BoolParser,
|
|
4
|
-
Config,
|
|
5
|
-
ConfigSection,
|
|
6
|
-
ConfigTag,
|
|
7
3
|
IntParser,
|
|
8
|
-
|
|
4
|
+
RegexParser,
|
|
9
5
|
StringParser,
|
|
6
|
+
text,
|
|
7
|
+
Timespan,
|
|
10
8
|
TimespanParser,
|
|
11
9
|
UrlParser,
|
|
12
|
-
} from '@rsdk/
|
|
10
|
+
} from '@rsdk/common';
|
|
11
|
+
import { Config, ConfigSection, ConfigTag, Property } from '@rsdk/core';
|
|
13
12
|
|
|
14
13
|
@ConfigSection({
|
|
15
14
|
name: 'typeorm database config',
|
|
@@ -80,4 +79,19 @@ export class TypeOrmPluginConfig extends Config {
|
|
|
80
79
|
`,
|
|
81
80
|
})
|
|
82
81
|
keepAliveInitialDelay!: number;
|
|
82
|
+
|
|
83
|
+
@Property('TRACE_ONLY_QUERIES_PATTERN', new RegexParser(), {
|
|
84
|
+
defaultValue: /^SELECT 1$/,
|
|
85
|
+
description: text`
|
|
86
|
+
Regex pattern for SQL queries that should be logged with TRACE level instead of DEBUG.
|
|
87
|
+
This is useful to reduce log verbosity for health checks and transaction control queries.
|
|
88
|
+
|
|
89
|
+
Default pattern matches: SELECT 1 (health check query)
|
|
90
|
+
|
|
91
|
+
You can override this pattern via environment variable. Provide the regex pattern as a string.
|
|
92
|
+
|
|
93
|
+
Example: DB_TRACE_ONLY_QUERIES_PATTERN="^(START TRANSACTION|BEGIN|COMMIT|SAVEPOINT\\s+)$"
|
|
94
|
+
`,
|
|
95
|
+
})
|
|
96
|
+
traceOnlyQueriesPattern!: RegExp;
|
|
83
97
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IErrorsTransformer, PipelineException } from '@rsdk/core';
|
|
2
2
|
import { InternalException, NotFoundException } from '@rsdk/core';
|
|
3
|
+
import _ from 'lodash';
|
|
3
4
|
import { EntityNotFoundError, TypeORMError } from 'typeorm';
|
|
4
5
|
|
|
5
6
|
export class TypeOrmErrorTransformer implements IErrorsTransformer {
|
|
@@ -7,19 +8,15 @@ export class TypeOrmErrorTransformer implements IErrorsTransformer {
|
|
|
7
8
|
return ex instanceof TypeORMError;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
transform(ex:
|
|
11
|
+
transform(ex: TypeORMError): PipelineException {
|
|
11
12
|
if (ex instanceof EntityNotFoundError) {
|
|
12
13
|
return new NotFoundException(ex.message, {
|
|
13
|
-
cause: ex,
|
|
14
|
+
cause: _.omit(ex, 'entityClass'),
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
throw new Error('unknown exception');
|
|
18
|
+
return new InternalException(ex.message, {
|
|
19
|
+
cause: _.omit(ex, 'entityClass'),
|
|
20
|
+
});
|
|
24
21
|
}
|
|
25
22
|
}
|
package/src/typeorm.plugin.ts
CHANGED
|
@@ -105,7 +105,7 @@ export class TypeOrmPlugin implements PlatformAppPlugin {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
errorTransformers(): IErrorsTransformer[] {
|
|
108
|
-
return [new TypeOrmErrorTransformer()];
|
|
108
|
+
return this.options.errorTransformers ?? [new TypeOrmErrorTransformer()];
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
private getMigrationsOption(): string[] {
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import type { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|
2
|
+
import type { IErrorsTransformer } from '@rsdk/core';
|
|
2
3
|
|
|
3
4
|
export interface TypeOrmPluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Тип драйвера
|
|
7
|
+
*/
|
|
4
8
|
type: NonNullable<TypeOrmModuleOptions['type']>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Сущности. Если массив сущностей не задан - будет
|
|
12
|
+
* использована опция autoLoadEntities.
|
|
13
|
+
*/
|
|
5
14
|
entities?: (string | any)[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Дополнительные конфигурационные параметры
|
|
18
|
+
*/
|
|
6
19
|
overrideConfig?: Partial<Omit<TypeOrmModuleOptions, 'type'>>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Трансформеры ошибок.
|
|
23
|
+
*
|
|
24
|
+
* NOTE: Если значение задаётся - трансформер по умолчанию
|
|
25
|
+
* не добавляется!
|
|
26
|
+
*/
|
|
27
|
+
errorTransformers?: IErrorsTransformer[];
|
|
7
28
|
}
|
|
8
29
|
|
|
9
30
|
export enum IsolationLevel {
|