@edifice.io/edifice-nestjs-core 1.0.0 → 1.0.3
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/README.md +41 -0
- package/dist/bin/generate-rest-clients.d.ts +2 -0
- package/dist/bin/generate-rest-clients.js +581 -0
- package/dist/bin/generate-rest-clients.js.map +1 -0
- package/dist/bin/generate-swagger-pdf.d.ts +1 -0
- package/dist/bin/generate-swagger-pdf.js +172 -0
- package/dist/bin/generate-swagger-pdf.js.map +1 -0
- package/dist/config/configuration.d.ts +6 -0
- package/dist/config/configuration.js +12 -0
- package/dist/config/configuration.js.map +1 -1
- package/dist/config/postgres.config.js +2 -0
- package/dist/config/postgres.config.js.map +1 -1
- package/dist/core.module.js +8 -0
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/performance/copy-metadata.utils.d.ts +1 -0
- package/dist/performance/copy-metadata.utils.js +9 -0
- package/dist/performance/copy-metadata.utils.js.map +1 -0
- package/dist/performance/correlation.interceptor.d.ts +5 -0
- package/dist/performance/correlation.interceptor.js +28 -0
- package/dist/performance/correlation.interceptor.js.map +1 -0
- package/dist/performance/index.d.ts +4 -0
- package/dist/performance/index.js +16 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/performance/performance-stats.d.ts +26 -0
- package/dist/performance/performance-stats.js +57 -0
- package/dist/performance/performance-stats.js.map +1 -0
- package/dist/performance/performance.decorator.d.ts +11 -0
- package/dist/performance/performance.decorator.js +56 -0
- package/dist/performance/performance.decorator.js.map +1 -0
- package/dist/performance/performance.module.d.ts +5 -0
- package/dist/performance/performance.module.js +38 -0
- package/dist/performance/performance.module.js.map +1 -0
- package/dist/session/query-param-token.middleware.d.ts +11 -0
- package/dist/session/query-param-token.middleware.js +68 -0
- package/dist/session/query-param-token.middleware.js.map +1 -0
- package/dist/session/session-middleware.utils.d.ts +17 -0
- package/dist/session/session-middleware.utils.js +82 -0
- package/dist/session/session-middleware.utils.js.map +1 -0
- package/dist/session/session.middleware.d.ts +0 -4
- package/dist/session/session.middleware.js +9 -45
- package/dist/session/session.middleware.js.map +1 -1
- package/dist/session/session.module.js +3 -2
- package/dist/session/session.module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/static-assets.utils.js +1 -1
- package/dist/utils/static-assets.utils.js.map +1 -1
- package/package.json +13 -6
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const wait_on_1 = __importDefault(require("wait-on"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
12
|
+
async function isServerRunning() {
|
|
13
|
+
try {
|
|
14
|
+
const response = await axios_1.default.get(`http://${host}:${port}/openapi-json`, {
|
|
15
|
+
timeout: 3000,
|
|
16
|
+
validateStatus: () => true,
|
|
17
|
+
});
|
|
18
|
+
return response.status >= 200 && response.status < 300;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error('Connection error:', error.message);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function generateSwaggerPdf() {
|
|
26
|
+
const apiUrl = `http://${host}:${port}`;
|
|
27
|
+
const swaggerJsonUrl = `${apiUrl}/openapi-json`;
|
|
28
|
+
const outputDir = path_1.default.resolve(process.cwd(), 'documentation');
|
|
29
|
+
const outputPath = path_1.default.join(outputDir, 'api-docs.pdf');
|
|
30
|
+
const tempJsonPath = path_1.default.join(outputDir, 'swagger-spec.json');
|
|
31
|
+
const htmlPath = path_1.default.join(outputDir, 'api-docs.html');
|
|
32
|
+
try {
|
|
33
|
+
console.log(`Fetching OpenAPI specification from ${swaggerJsonUrl}...`);
|
|
34
|
+
await fs_extra_1.default.ensureDir(outputDir);
|
|
35
|
+
const response = await axios_1.default.get(swaggerJsonUrl, { timeout: 5000 });
|
|
36
|
+
console.log('OpenAPI specification successfully retrieved.');
|
|
37
|
+
await fs_extra_1.default.writeJson(tempJsonPath, response.data, { spaces: 2 });
|
|
38
|
+
console.log(`Specification saved to ${tempJsonPath}`);
|
|
39
|
+
console.log('Generating documentation...');
|
|
40
|
+
let success = false;
|
|
41
|
+
if (!success) {
|
|
42
|
+
try {
|
|
43
|
+
console.log('Generating HTML with @redocly/cli...');
|
|
44
|
+
(0, child_process_1.execSync)(`npx @redocly/cli build-docs ${tempJsonPath} --output=${htmlPath}`, { stdio: 'inherit' });
|
|
45
|
+
success = true;
|
|
46
|
+
console.log('HTML documentation generated successfully with @redocly/cli.');
|
|
47
|
+
if (success && fs_extra_1.default.existsSync(htmlPath)) {
|
|
48
|
+
try {
|
|
49
|
+
console.log('Converting HTML to PDF with electron-pdf...');
|
|
50
|
+
(0, child_process_1.execSync)(`npx electron-pdf "${htmlPath}" "${outputPath}" --landscape=false --marginsType=1`, {
|
|
51
|
+
stdio: 'inherit',
|
|
52
|
+
});
|
|
53
|
+
console.log('PDF documentation generated successfully with electron-pdf.');
|
|
54
|
+
return outputPath;
|
|
55
|
+
}
|
|
56
|
+
catch (_) {
|
|
57
|
+
console.log('electron-pdf conversion failed, trying next method...');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (_) {
|
|
62
|
+
console.log('@redocly/cli failed, trying next method...');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!success) {
|
|
66
|
+
try {
|
|
67
|
+
console.log('Generating PDF with swagger-to-pdf...');
|
|
68
|
+
(0, child_process_1.execSync)(`npx swagger-to-pdf ${tempJsonPath} ${outputPath}`, {
|
|
69
|
+
stdio: 'inherit',
|
|
70
|
+
});
|
|
71
|
+
success = true;
|
|
72
|
+
console.log('PDF documentation generated successfully with swagger-to-pdf.');
|
|
73
|
+
return outputPath;
|
|
74
|
+
}
|
|
75
|
+
catch (_) {
|
|
76
|
+
console.log('swagger-to-pdf failed, trying next method...');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!success) {
|
|
80
|
+
throw new Error('All documentation generation methods failed.');
|
|
81
|
+
}
|
|
82
|
+
return outputPath;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('Error generating documentation:', error.message);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function run() {
|
|
90
|
+
console.log('Checking if server is already running...');
|
|
91
|
+
const serverAlreadyRunning = await isServerRunning();
|
|
92
|
+
let serverProcess = null;
|
|
93
|
+
try {
|
|
94
|
+
if (!serverAlreadyRunning) {
|
|
95
|
+
console.log('Starting server...');
|
|
96
|
+
serverProcess = (0, child_process_1.spawn)('pnpm', ['start'], {
|
|
97
|
+
shell: true,
|
|
98
|
+
stdio: 'pipe',
|
|
99
|
+
detached: true,
|
|
100
|
+
env: { ...process.env, PORT: port, HOST: host },
|
|
101
|
+
});
|
|
102
|
+
serverProcess.stdout.on('data', (data) => {
|
|
103
|
+
console.log(`[Server]: ${data.toString().trim()}`);
|
|
104
|
+
});
|
|
105
|
+
serverProcess.stderr.on('data', (data) => {
|
|
106
|
+
console.error(`[Server Error]: ${data.toString().trim()}`);
|
|
107
|
+
});
|
|
108
|
+
console.log('Waiting for server to be ready...');
|
|
109
|
+
await (0, wait_on_1.default)({
|
|
110
|
+
resources: [`http-get://${host}:${port}/openapi-json`],
|
|
111
|
+
delay: 1000,
|
|
112
|
+
interval: 1000,
|
|
113
|
+
timeout: 60000,
|
|
114
|
+
verbose: true,
|
|
115
|
+
});
|
|
116
|
+
console.log('Server is ready!');
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
console.log('Server is already running.');
|
|
120
|
+
}
|
|
121
|
+
console.log('Generating API documentation...');
|
|
122
|
+
const docPath = await generateSwaggerPdf();
|
|
123
|
+
if (fs_extra_1.default.existsSync(docPath)) {
|
|
124
|
+
console.log(`Documentation generated: ${docPath}`);
|
|
125
|
+
if (docPath.endsWith('.pdf')) {
|
|
126
|
+
console.log('PDF documentation was successfully generated.');
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.log('HTML documentation was generated. Use browser print function to create PDF if needed.');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
console.error('Error in run process:', error.message);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
if (serverProcess && !serverAlreadyRunning) {
|
|
139
|
+
console.log('Shutting down server...');
|
|
140
|
+
try {
|
|
141
|
+
if (process.platform === 'win32') {
|
|
142
|
+
(0, child_process_1.execSync)(`taskkill /pid ${serverProcess.pid} /T /F`);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
process.kill(-serverProcess.pid, 'SIGINT');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error('Error shutting down server:', error.message);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const argv = (0, yargs_1.default)(process.argv.slice(2))
|
|
155
|
+
.option('host', {
|
|
156
|
+
alias: 'h',
|
|
157
|
+
type: 'string',
|
|
158
|
+
description: 'Host of the API server',
|
|
159
|
+
default: '127.0.0.1',
|
|
160
|
+
})
|
|
161
|
+
.option('port', {
|
|
162
|
+
alias: 'p',
|
|
163
|
+
type: 'number',
|
|
164
|
+
description: 'Port of the API server',
|
|
165
|
+
default: 3002,
|
|
166
|
+
})
|
|
167
|
+
.help()
|
|
168
|
+
.parse();
|
|
169
|
+
const host = argv.host;
|
|
170
|
+
const port = argv.port;
|
|
171
|
+
run();
|
|
172
|
+
//# sourceMappingURL=generate-swagger-pdf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-swagger-pdf.js","sourceRoot":"","sources":["../../src/bin/generate-swagger-pdf.ts"],"names":[],"mappings":";;;;;AAAA,iDAAgD;AAChD,kDAA0B;AAC1B,sDAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AACxB,kDAA0B;AAG1B,KAAK,UAAU,eAAe;IAC5B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,UAAU,IAAI,IAAI,IAAI,eAAe,EAAE;YACtE,OAAO,EAAE,IAAI;YACb,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;SAC3B,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAGD,KAAK,UAAU,kBAAkB;IAC/B,MAAM,MAAM,GAAG,UAAU,IAAI,IAAI,IAAI,EAAE,CAAC;IACxC,MAAM,cAAc,GAAG,GAAG,MAAM,eAAe,CAAC;IAChD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IACxD,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,S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M,EAAE;IACd,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,wBAAwB;IACrC,OAAO,EAAE,IAAI;CACd,CAAC;KACD,IAAI,EAAE;KACN,KAAK,EAAE,CAAC;AAEX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;AACvB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;AAEvB,GAAG,EAAE,CAAC"}
|
|
@@ -38,6 +38,18 @@ exports.default = () => {
|
|
|
38
38
|
debug: process.env.DATABASE_DEBUG === 'true',
|
|
39
39
|
schema: process.env.DATABASE_SCHEMA,
|
|
40
40
|
ssl: process.env.DATABASE_SSL === 'true',
|
|
41
|
+
pool: {
|
|
42
|
+
min: process.env.DATABASE_POOL_MIN
|
|
43
|
+
? parseInt(process.env.DATABASE_POOL_MIN)
|
|
44
|
+
: 5,
|
|
45
|
+
max: process.env.DATABASE_POOL_MAX
|
|
46
|
+
? parseInt(process.env.DATABASE_POOL_MAX)
|
|
47
|
+
: 20,
|
|
48
|
+
idleTimeoutMillis: process.env.DATABASE_POOL_IDLE_TIMEOUT_MS
|
|
49
|
+
? parseInt(process.env.DATABASE_POOL_IDLE_TIMEOUT_MS)
|
|
50
|
+
: 10000,
|
|
51
|
+
},
|
|
52
|
+
keepAlive: process.env.DATABASE_KEEP_ALIVE !== 'false',
|
|
41
53
|
},
|
|
42
54
|
},
|
|
43
55
|
nats: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../src/config/configuration.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAC5B,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;AAExD,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC;AAE7C,MAAM,OAAO,GAAW,OAAO,CAAC,GAAG,CAAC,QAAS,CAAC;AAC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AAC,CAAC,IAAI;aACT;SACF;QACD,KAAK,EAAE;YACL,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,gCAAgC;gBAC3D,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC;gBACxD,CAAC,CAAC,KAAK;SACV;QACD,MAAM,EAAE;YACN,MAAM,EAAE;gBACN,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG;gBACvE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG;aACrE;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -25,11 +25,13 @@ function createPostgresOptions(configService) {
|
|
|
25
25
|
pool: {
|
|
26
26
|
min: configService.get('db.postgres.pool.min', 1),
|
|
27
27
|
max: configService.get('db.postgres.pool.max', 1),
|
|
28
|
+
idleTimeoutMillis: configService.get('db.postgres.pool.idleTimeoutMillis', 10000),
|
|
28
29
|
},
|
|
29
30
|
driverOptions: {
|
|
30
31
|
connection: {
|
|
31
32
|
schema,
|
|
32
33
|
ssl: sslOptions,
|
|
34
|
+
keepAlive: configService.get('db.postgres.keepAlive', true),
|
|
33
35
|
},
|
|
34
36
|
},
|
|
35
37
|
entities: [entitiesPath],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.config.js","sourceRoot":"","sources":["../../src/config/postgres.config.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"postgres.config.js","sourceRoot":"","sources":["../../src/config/postgres.config.ts"],"names":[],"mappings":";;AAIA,sDA0DC;AA7DD,sDAAyD;AAGzD,SAAgB,qBAAqB,CACnC,aAA4B;IAE5B,MAAM,MAAM,GAAW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,aAAa,CAAC,GAAG,CAAU,kBAAkB,EAAE,IAAI,CAAC,EAAE,CAAC;QACzD,OAAO,CAAC,UAAU,GAAG;YACnB,IAAI,EAAE,gBAAgB,EAAE;YACxB,MAAM,EAAE,kBAAkB;YAC1B,kBAAkB,EAAE,KAAK;YACzB,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,KAAK;YACjB,IAAI,EAAE,KAAK;YACX,QAAQ,EAAE,KAAK;YACf,SAAS,EAAE,GAAG,MAAM,uBAAuB;YAC3C,aAAa,EAAE,IAAI;SACpB,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,eAAe;IACtB,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IACnC,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IACD,OAAO,uBAAuB,CAAC;AACjC,CAAC;AAED,SAAS,gBAAgB;IACvB,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACpC,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,OAAO,sBAAsB,CAAC;IAChC,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
|
package/dist/core.module.js
CHANGED
|
@@ -20,6 +20,7 @@ const logging_config_1 = require("./config/logging.config");
|
|
|
20
20
|
const static_assets_utils_1 = require("./utils/static-assets.utils");
|
|
21
21
|
const logger_module_1 = require("./logger/logger.module");
|
|
22
22
|
const session_middleware_1 = require("./session/session.middleware");
|
|
23
|
+
const query_param_token_middleware_1 = require("./session/query-param-token.middleware");
|
|
23
24
|
const database_module_1 = require("./database/database.module");
|
|
24
25
|
const frontend_controller_1 = require("./frontend.controller");
|
|
25
26
|
const nats_1 = require("./nats");
|
|
@@ -32,11 +33,16 @@ const timeline_1 = require("./timeline");
|
|
|
32
33
|
const i18n_1 = require("./i18n");
|
|
33
34
|
const session_module_1 = require("./session/session.module");
|
|
34
35
|
const health_module_1 = require("./health/health.module");
|
|
36
|
+
const performance_module_1 = require("./performance/performance.module");
|
|
35
37
|
let CoreModule = CoreModule_1 = class CoreModule {
|
|
36
38
|
configure(consumer) {
|
|
37
39
|
CoreModule_1.configureSessionMiddleware(consumer);
|
|
38
40
|
}
|
|
39
41
|
static configureSessionMiddleware(consumer) {
|
|
42
|
+
consumer
|
|
43
|
+
.apply(query_param_token_middleware_1.QueryParamTokenMiddleware)
|
|
44
|
+
.exclude({ path: '/api/(.*)', method: common_1.RequestMethod.ALL }, { path: 'openapi', method: common_1.RequestMethod.ALL }, { path: 'openapi-json', method: common_1.RequestMethod.ALL }, { path: 'openapi/(.*)', method: common_1.RequestMethod.ALL })
|
|
45
|
+
.forRoutes('*');
|
|
40
46
|
consumer
|
|
41
47
|
.apply(session_middleware_1.SessionMiddleware)
|
|
42
48
|
.exclude({ path: 'openapi', method: common_1.RequestMethod.GET }, { path: 'openapi-json', method: common_1.RequestMethod.GET }, { path: '/api/conf/public', method: common_1.RequestMethod.GET }, { path: 'openapi/*', method: common_1.RequestMethod.GET })
|
|
@@ -70,6 +76,7 @@ exports.CoreModule = CoreModule = CoreModule_1 = __decorate([
|
|
|
70
76
|
health_module_1.HealthModule,
|
|
71
77
|
timeline_1.TimelineModule,
|
|
72
78
|
session_module_1.SessionModule,
|
|
79
|
+
performance_module_1.PerformanceModule,
|
|
73
80
|
],
|
|
74
81
|
controllers: [frontend_controller_1.FrontendController],
|
|
75
82
|
providers: [
|
|
@@ -93,6 +100,7 @@ exports.CoreModule = CoreModule = CoreModule_1 = __decorate([
|
|
|
93
100
|
i18n_1.I18nModule,
|
|
94
101
|
timeline_1.TimelineModule,
|
|
95
102
|
session_module_1.SessionModule,
|
|
103
|
+
performance_module_1.PerformanceModule,
|
|
96
104
|
],
|
|
97
105
|
})
|
|
98
106
|
], CoreModule);
|
package/dist/core.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.module.js","sourceRoot":"","sources":["../src/core.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAKwB;AACxB,2CAA6D;AAC7D,uDAAyD;AACzD,6CAA+D;AAE/D,2EAAmD;AACnD,4DAA8D;AAC9D,qEAAkE;AAClE,0DAAsD;AACtD,qEAAiE;AACjE,gEAA4D;AAC5D,+DAA2D;AAC3D,iCAAoC;AACpC,oEAAgE;AAChE,uCAAyC;AACzC,yEAAqE;AACrE,wDAAoD;AACpD,uDAAmD;AACnD,yCAA4C;AAC5C,iCAAoC;AACpC,6DAAyD;AACzD,0DAAsD;
|
|
1
|
+
{"version":3,"file":"core.module.js","sourceRoot":"","sources":["../src/core.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAKwB;AACxB,2CAA6D;AAC7D,uDAAyD;AACzD,6CAA+D;AAE/D,2EAAmD;AACnD,4DAA8D;AAC9D,qEAAkE;AAClE,0DAAsD;AACtD,qEAAiE;AACjE,yFAAmF;AACnF,gEAA4D;AAC5D,+DAA2D;AAC3D,iCAAoC;AACpC,oEAAgE;AAChE,uCAAyC;AACzC,yEAAqE;AACrE,wDAAoD;AACpD,uDAAmD;AACnD,yCAA4C;AAC5C,iCAAoC;AACpC,6DAAyD;AACzD,0DAAsD;AACtD,yEAAqE;AAkE9D,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,SAAS,CAAC,QAA4B;QAEpC,YAAU,CAAC,0BAA0B,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAkBD,MAAM,CAAC,0BAA0B,CAAC,QAA4B;QAI5D,QAAQ;aACL,KAAK,CAAC,wDAAyB,CAAC;aAChC,OAAO,CACN,EAAE,IAAI,EAAE,WAAW,E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AAE,SAAS;gBACzD,OAAO,EAAE,CAAC,OAAO,CAAC;aACnB,CAAC;YAGF,4BAAY;YACZ,0BAAW;YACX,iBAAU;YACV,4BAAY;YACZ,yBAAc;YACd,8BAAa;YACb,sCAAiB;SAClB;QACD,WAAW,EAAE,CAAC,wCAAkB,CAAC;QACjC,SAAS,EAAE;YAET;gBACE,OAAO,EAAE,gBAAS;gBAClB,QAAQ,EAAE,kCAAe;aAC1B;YACD;gBACE,OAAO,EAAE,gBAAS;gBAClB,QAAQ,EAAE,sBAAS;aACpB;SACF;QACD,OAAO,EAAE;YACP,qBAAY;YACZ,0BAAgB;YAChB,gCAAc;YACd,sCAAiB;YACjB,4BAAY;YACZ,iBAAU;YACV,0BAAW;YACX,iBAAU;YACV,yBAAc;YACd,8BAAa;YACb,sCAAiB;SAClB;KACF,CAAC;GACW,UAAU,CA+CtB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -26,4 +26,5 @@ __exportStar(require("./session"), exports);
|
|
|
26
26
|
__exportStar(require("./timeline"), exports);
|
|
27
27
|
__exportStar(require("./i18n"), exports);
|
|
28
28
|
__exportStar(require("./utils"), exports);
|
|
29
|
+
__exportStar(require("./performance"), exports);
|
|
29
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,kDAAgC;AAChC,gDAA8B;AAC9B,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,yCAAuB;AACvB,+CAA6B;AAC7B,4CAA0B;AAC1B,6CAA2B;AAC3B,yCAAuB;AACvB,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,kDAAgC;AAChC,gDAA8B;AAC9B,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,yCAAuB;AACvB,+CAA6B;AAC7B,4CAA0B;AAC1B,6CAA2B;AAC3B,yCAAuB;AACvB,0CAAwB;AACxB,gDAA8B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copyMetadata(source: Function, target: Function): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyMetadata = copyMetadata;
|
|
4
|
+
function copyMetadata(source, target) {
|
|
5
|
+
Reflect.getMetadataKeys(source).forEach((key) => {
|
|
6
|
+
Reflect.defineMetadata(key, Reflect.getMetadata(key, source), target);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=copy-metadata.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-metadata.utils.js","sourceRoot":"","sources":["../../src/performance/copy-metadata.utils.ts"],"names":[],"mappings":";;AAQA,oCASC;AATD,SAAgB,YAAY,CAE1B,MAAgB,EAEhB,MAAgB;IAEhB,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC9C,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class CorrelationInterceptor implements NestInterceptor {
|
|
4
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.CorrelationInterceptor = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
const performance_decorator_1 = require("./performance.decorator");
|
|
13
|
+
let CorrelationInterceptor = class CorrelationInterceptor {
|
|
14
|
+
intercept(context, next) {
|
|
15
|
+
if ((0, performance_decorator_1.isPerfLoggingEnabled)()) {
|
|
16
|
+
const correlationId = (0, crypto_1.randomBytes)(8).toString('hex');
|
|
17
|
+
return performance_decorator_1.perfContext.run({ correlationId }, () => next.handle());
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return next.handle();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.CorrelationInterceptor = CorrelationInterceptor;
|
|
25
|
+
exports.CorrelationInterceptor = CorrelationInterceptor = __decorate([
|
|
26
|
+
(0, common_1.Injectable)()
|
|
27
|
+
], CorrelationInterceptor);
|
|
28
|
+
//# sourceMappingURL=correlation.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation.interceptor.js","sourceRoot":"","sources":["../../src/performance/correlation.interceptor.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AAExB,mCAAqC;AAErC,mEAA4E;AAgBrE,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAQjC,SAAS,CAAC,OAAyB,EAAE,IAAiB;QAEpD,IAAI,IAAA,4CAAoB,GAAE,EAAE,CAAC;YAE3B,MAAM,aAAa,GAAG,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAIrD,OAAO,mCAAW,CAAC,GAAG,CAAC,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YAEN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF,CAAA;AAtBY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;GACA,sBAAsB,CAsBlC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Performance, perfContext, setPerfLoggingEnabled, isPerfLoggingEnabled, } from './performance.decorator';
|
|
2
|
+
export { CorrelationInterceptor } from './correlation.interceptor';
|
|
3
|
+
export { PerformanceStats, globalPerfStats } from './performance-stats';
|
|
4
|
+
export { copyMetadata } from './copy-metadata.utils';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyMetadata = exports.globalPerfStats = exports.PerformanceStats = exports.CorrelationInterceptor = exports.isPerfLoggingEnabled = exports.setPerfLoggingEnabled = exports.perfContext = exports.Performance = void 0;
|
|
4
|
+
var performance_decorator_1 = require("./performance.decorator");
|
|
5
|
+
Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return performance_decorator_1.Performance; } });
|
|
6
|
+
Object.defineProperty(exports, "perfContext", { enumerable: true, get: function () { return performance_decorator_1.perfContext; } });
|
|
7
|
+
Object.defineProperty(exports, "setPerfLoggingEnabled", { enumerable: true, get: function () { return performance_decorator_1.setPerfLoggingEnabled; } });
|
|
8
|
+
Object.defineProperty(exports, "isPerfLoggingEnabled", { enumerable: true, get: function () { return performance_decorator_1.isPerfLoggingEnabled; } });
|
|
9
|
+
var correlation_interceptor_1 = require("./correlation.interceptor");
|
|
10
|
+
Object.defineProperty(exports, "CorrelationInterceptor", { enumerable: true, get: function () { return correlation_interceptor_1.CorrelationInterceptor; } });
|
|
11
|
+
var performance_stats_1 = require("./performance-stats");
|
|
12
|
+
Object.defineProperty(exports, "PerformanceStats", { enumerable: true, get: function () { return performance_stats_1.PerformanceStats; } });
|
|
13
|
+
Object.defineProperty(exports, "globalPerfStats", { enumerable: true, get: function () { return performance_stats_1.globalPerfStats; } });
|
|
14
|
+
var copy_metadata_utils_1 = require("./copy-metadata.utils");
|
|
15
|
+
Object.defineProperty(exports, "copyMetadata", { enumerable: true, get: function () { return copy_metadata_utils_1.copyMetadata; } });
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/performance/index.ts"],"names":[],"mappings":";;;AAAA,iEAKiC;AAJ/B,oHAAA,WAAW,OAAA;AACX,oHAAA,WAAW,OAAA;AACX,8HAAA,qBAAqB,OAAA;AACrB,6HAAA,oBAAoB,OAAA;AAEtB,qEAAmE;AAA1D,iIAAA,sBAAsB,OAAA;AAC/B,yDAAwE;AAA/D,qHAAA,gBAAgB,OAAA;AAAE,oHAAA,eAAe,OAAA;AAC1C,6DAAqD;AAA5C,mHAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type Stats = {
|
|
2
|
+
count: number;
|
|
3
|
+
totalMs: number;
|
|
4
|
+
min: number;
|
|
5
|
+
max: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class PerformanceStats {
|
|
8
|
+
private statsMap;
|
|
9
|
+
private countSinceLastSummary;
|
|
10
|
+
private summaryEvery;
|
|
11
|
+
constructor(summaryEvery?: number);
|
|
12
|
+
setSummaryEvery(summaryEvery: number): void;
|
|
13
|
+
record(label: string, durationMs: number): Stats;
|
|
14
|
+
shouldSummarize(label: string): boolean;
|
|
15
|
+
resetSummaryCounter(label: string): void;
|
|
16
|
+
incrementSummaryCounter(label: string): void;
|
|
17
|
+
getStats(label: string): Stats | undefined;
|
|
18
|
+
toMeta(stats: Stats): {
|
|
19
|
+
count: number;
|
|
20
|
+
mean: number;
|
|
21
|
+
min: number;
|
|
22
|
+
max: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare const globalPerfStats: PerformanceStats;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalPerfStats = exports.PerformanceStats = void 0;
|
|
4
|
+
class PerformanceStats {
|
|
5
|
+
statsMap = new Map();
|
|
6
|
+
countSinceLastSummary = new Map();
|
|
7
|
+
summaryEvery;
|
|
8
|
+
constructor(summaryEvery = 1000) {
|
|
9
|
+
this.summaryEvery = summaryEvery;
|
|
10
|
+
}
|
|
11
|
+
setSummaryEvery(summaryEvery) {
|
|
12
|
+
if (summaryEvery > 0) {
|
|
13
|
+
this.summaryEvery = summaryEvery;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
record(label, durationMs) {
|
|
17
|
+
if (!this.statsMap.has(label)) {
|
|
18
|
+
this.statsMap.set(label, {
|
|
19
|
+
count: 0,
|
|
20
|
+
totalMs: 0,
|
|
21
|
+
min: Infinity,
|
|
22
|
+
max: -Infinity,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const stats = this.statsMap.get(label);
|
|
26
|
+
stats.count++;
|
|
27
|
+
stats.totalMs += durationMs;
|
|
28
|
+
stats.min = Math.min(stats.min, durationMs);
|
|
29
|
+
stats.max = Math.max(stats.max, durationMs);
|
|
30
|
+
return stats;
|
|
31
|
+
}
|
|
32
|
+
shouldSummarize(label) {
|
|
33
|
+
const count = this.countSinceLastSummary.get(label) ?? 0;
|
|
34
|
+
return count + 1 >= this.summaryEvery;
|
|
35
|
+
}
|
|
36
|
+
resetSummaryCounter(label) {
|
|
37
|
+
this.countSinceLastSummary.set(label, 0);
|
|
38
|
+
}
|
|
39
|
+
incrementSummaryCounter(label) {
|
|
40
|
+
const count = this.countSinceLastSummary.get(label) ?? 0;
|
|
41
|
+
this.countSinceLastSummary.set(label, count + 1);
|
|
42
|
+
}
|
|
43
|
+
getStats(label) {
|
|
44
|
+
return this.statsMap.get(label);
|
|
45
|
+
}
|
|
46
|
+
toMeta(stats) {
|
|
47
|
+
return {
|
|
48
|
+
count: stats.count,
|
|
49
|
+
mean: Math.round(stats.totalMs / stats.count),
|
|
50
|
+
min: stats.min === Infinity ? 0 : stats.min,
|
|
51
|
+
max: stats.max,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.PerformanceStats = PerformanceStats;
|
|
56
|
+
exports.globalPerfStats = new PerformanceStats();
|
|
57
|
+
//# sourceMappingURL=performance-stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance-stats.js","sourceRoot":"","sources":["../../src/performance/performance-stats.ts"],"names":[],"mappings":";;;AAmBA,MAAa,gBAAgB;IAEnB,QAAQ,GAAG,IAAI,GAAG,EAAiB,CAAC;IAGpC,qBAAqB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAGlD,YAAY,CAAS;IAM7B,YAAY,YAAY,GAAG,IAAI;QAC7B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAQD,eAAe,CAAC,YAAoB;QAClC,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACnC,CAAC;IACH,CAAC;IAUD,MAAM,CAAC,KAAa,EAAE,UAAkB;QACtC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,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K;YAClB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC;YAC7C,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG;YAC3C,GAAG,EAAE,KAAK,CAAC,GAAG;SACf,CAAC;IACJ,CAAC;CACF;AAjHD,4CAiHC;AAIY,QAAA,eAAe,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
export declare const perfContext: AsyncLocalStorage<{
|
|
3
|
+
correlationId: string;
|
|
4
|
+
}>;
|
|
5
|
+
interface PerfLoggingOptions {
|
|
6
|
+
summaryEvery?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function setPerfLoggingEnabled(enabled: boolean, options?: PerfLoggingOptions): void;
|
|
9
|
+
export declare function isPerfLoggingEnabled(): boolean;
|
|
10
|
+
export declare function Performance(label?: string): (target: object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.perfContext = void 0;
|
|
4
|
+
exports.setPerfLoggingEnabled = setPerfLoggingEnabled;
|
|
5
|
+
exports.isPerfLoggingEnabled = isPerfLoggingEnabled;
|
|
6
|
+
exports.Performance = Performance;
|
|
7
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
8
|
+
const async_hooks_1 = require("async_hooks");
|
|
9
|
+
const common_1 = require("@nestjs/common");
|
|
10
|
+
const performance_stats_1 = require("./performance-stats");
|
|
11
|
+
const copy_metadata_utils_1 = require("./copy-metadata.utils");
|
|
12
|
+
exports.perfContext = new async_hooks_1.AsyncLocalStorage();
|
|
13
|
+
let perfLoggingEnabled = false;
|
|
14
|
+
function setPerfLoggingEnabled(enabled, options) {
|
|
15
|
+
perfLoggingEnabled = enabled;
|
|
16
|
+
if (enabled && options?.summaryEvery) {
|
|
17
|
+
performance_stats_1.globalPerfStats.setSummaryEvery(options.summaryEvery);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function isPerfLoggingEnabled() {
|
|
21
|
+
return perfLoggingEnabled;
|
|
22
|
+
}
|
|
23
|
+
function Performance(label) {
|
|
24
|
+
const logger = new common_1.Logger('Performance');
|
|
25
|
+
return function (target, propertyKey, descriptor) {
|
|
26
|
+
const original = descriptor.value;
|
|
27
|
+
const wrapper = async function (...args) {
|
|
28
|
+
if (!perfLoggingEnabled) {
|
|
29
|
+
return original.apply(this, args);
|
|
30
|
+
}
|
|
31
|
+
const effectiveLabel = label ?? `${target.constructor.name}.${propertyKey}`;
|
|
32
|
+
const ctx = exports.perfContext.getStore();
|
|
33
|
+
const t0 = perf_hooks_1.performance.now();
|
|
34
|
+
const result = await original.apply(this, args);
|
|
35
|
+
const durationMs = Math.round(perf_hooks_1.performance.now() - t0);
|
|
36
|
+
const stats = performance_stats_1.globalPerfStats.record(effectiveLabel, durationMs);
|
|
37
|
+
const logMeta = {
|
|
38
|
+
durationMs,
|
|
39
|
+
...(ctx ? { correlationId: ctx.correlationId } : {}),
|
|
40
|
+
stats: performance_stats_1.globalPerfStats.toMeta(stats),
|
|
41
|
+
};
|
|
42
|
+
logger.log(logMeta, `${effectiveLabel}`);
|
|
43
|
+
performance_stats_1.globalPerfStats.incrementSummaryCounter(effectiveLabel);
|
|
44
|
+
if (performance_stats_1.globalPerfStats.shouldSummarize(effectiveLabel)) {
|
|
45
|
+
performance_stats_1.globalPerfStats.resetSummaryCounter(effectiveLabel);
|
|
46
|
+
logger.log(performance_stats_1.globalPerfStats.toMeta(stats), `${effectiveLabel} — stats`);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(wrapper, 'name', { value: original.name });
|
|
51
|
+
(0, copy_metadata_utils_1.copyMetadata)(original, wrapper);
|
|
52
|
+
descriptor.value = wrapper;
|
|
53
|
+
return descriptor;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=performance.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.decorator.js","sourceRoot":"","sources":["../../src/performance/performance.decorator.ts"],"names":[],"mappings":";;;AAiCA,sDAQC;AAMD,oDAEC;AAkBD,kCA+DC;AAlID,2CAAyC;AACzC,6CAAgD;AAChD,2CAAwC;AAExC,2DAAsD;AACtD,+DAAqD;AAMxC,QAAA,WAAW,GAAG,IAAI,+BAAiB,EAE5C,CAAC;AAGL,IAAI,kBAAkB,GAAG,KAAK,CAAC;AAiB/B,SAAgB,qBAAqB,CACnC,OAAgB,EAChB,OAA4B;IAE5B,kBAAkB,GAAG,OAAO,CAAC;IAC7B,IAAI,OAAO,IAAI,OAAO,EAAE,YAAY,EAAE,CAAC;QACrC,mCAAe,CAAC,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxD,CAAC;AACH,CAAC;AAMD,SAAgB,oBAAoB;IAClC,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAkBD,SAAgB,WAAW,CAAC,KAAc;IACxC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,aAAa,CAAC,CAAC;IAEzC,OAAO,UACL,MAAc,EACd,WAAmB,EACnB,UAA8B;QAE9B,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC;QAGlC,MAAM,OAAO,GAAG,KAAK,WAA0B,GAAG,IAAe;YAE/D,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACxB,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACpC,CAAC;YAGD,MAAM,cAAc,GAClB,KAAK,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,WAAW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,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PerformanceModule = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const config_1 = require("@nestjs/config");
|
|
16
|
+
const index_1 = require("./index");
|
|
17
|
+
let PerformanceModule = class PerformanceModule {
|
|
18
|
+
configService;
|
|
19
|
+
constructor(configService) {
|
|
20
|
+
this.configService = configService;
|
|
21
|
+
const perfLogging = this.configService.get('perfLogging') ?? false;
|
|
22
|
+
const perfSummaryEvery = this.configService.get('perfSummaryEvery');
|
|
23
|
+
(0, index_1.setPerfLoggingEnabled)(perfLogging, { summaryEvery: perfSummaryEvery });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.PerformanceModule = PerformanceModule;
|
|
27
|
+
exports.PerformanceModule = PerformanceModule = __decorate([
|
|
28
|
+
(0, common_1.Module)({
|
|
29
|
+
providers: [
|
|
30
|
+
{
|
|
31
|
+
provide: core_1.APP_INTERCEPTOR,
|
|
32
|
+
useClass: index_1.CorrelationInterceptor,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
}),
|
|
36
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
37
|
+
], PerformanceModule);
|
|
38
|
+
//# sourceMappingURL=performance.module.js.map
|