nestjs-profiler 1.0.12 → 1.0.13

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.
Files changed (61) hide show
  1. package/analyzers/explain-analyzer.d.ts +5 -0
  2. package/analyzers/explain-analyzer.js +41 -0
  3. package/analyzers/explain-analyzer.js.map +1 -0
  4. package/collectors/cache-collector.d.ts +18 -0
  5. package/collectors/cache-collector.js +175 -0
  6. package/collectors/cache-collector.js.map +1 -0
  7. package/collectors/log-collector.d.ts +12 -0
  8. package/collectors/log-collector.js +66 -0
  9. package/collectors/log-collector.js.map +1 -0
  10. package/collectors/mongo-collector.d.ts +19 -0
  11. package/collectors/mongo-collector.js +200 -0
  12. package/collectors/mongo-collector.js.map +1 -0
  13. package/collectors/mysql-collector.d.ts +12 -0
  14. package/collectors/mysql-collector.js +128 -0
  15. package/collectors/mysql-collector.js.map +1 -0
  16. package/collectors/postgres-collector.d.ts +15 -0
  17. package/collectors/postgres-collector.js +201 -0
  18. package/collectors/postgres-collector.js.map +1 -0
  19. package/common/profiler-options.interface.d.ts +20 -0
  20. package/common/profiler-options.interface.js +3 -0
  21. package/common/profiler-options.interface.js.map +1 -0
  22. package/common/profiler.model.d.ts +67 -0
  23. package/common/profiler.model.js +3 -0
  24. package/common/profiler.model.js.map +1 -0
  25. package/controllers/profiler.controller.d.ts +34 -0
  26. package/controllers/profiler.controller.js +254 -0
  27. package/controllers/profiler.controller.js.map +1 -0
  28. package/interceptors/request-profiler.interceptor.d.ts +11 -0
  29. package/interceptors/request-profiler.interceptor.js +103 -0
  30. package/interceptors/request-profiler.interceptor.js.map +1 -0
  31. package/middleware/profiler.middleware.d.ts +4 -0
  32. package/middleware/profiler.middleware.js +21 -0
  33. package/middleware/profiler.middleware.js.map +1 -0
  34. package/package.json +5 -4
  35. package/profiler-logger.d.ts +12 -0
  36. package/profiler-logger.js +59 -0
  37. package/profiler-logger.js.map +1 -0
  38. package/profiler.module.d.ts +7 -0
  39. package/profiler.module.js +105 -0
  40. package/profiler.module.js.map +1 -0
  41. package/services/entity-explorer.service.d.ts +19 -0
  42. package/services/entity-explorer.service.js +111 -0
  43. package/services/entity-explorer.service.js.map +1 -0
  44. package/services/profiler.service.d.ts +31 -0
  45. package/services/profiler.service.js +216 -0
  46. package/services/profiler.service.js.map +1 -0
  47. package/services/route-explorer.service.d.ts +15 -0
  48. package/services/route-explorer.service.js +94 -0
  49. package/services/route-explorer.service.js.map +1 -0
  50. package/services/template-builder.service.d.ts +27 -0
  51. package/services/template-builder.service.js +348 -0
  52. package/services/template-builder.service.js.map +1 -0
  53. package/services/view.service.d.ts +17 -0
  54. package/services/view.service.js +196 -0
  55. package/services/view.service.js.map +1 -0
  56. package/storage/in-memory-profiler-storage.d.ts +9 -0
  57. package/storage/in-memory-profiler-storage.js +29 -0
  58. package/storage/in-memory-profiler-storage.js.map +1 -0
  59. package/storage/profiler-storage.interface.d.ts +6 -0
  60. package/storage/profiler-storage.interface.js +3 -0
  61. package/storage/profiler-storage.interface.js.map +1 -0
@@ -0,0 +1,254 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ProfilerController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const profiler_service_1 = require("../services/profiler.service");
18
+ const view_service_1 = require("../services/view.service");
19
+ const template_builder_service_1 = require("../services/template-builder.service");
20
+ const entity_explorer_service_1 = require("../services/entity-explorer.service");
21
+ const route_explorer_service_1 = require("../services/route-explorer.service");
22
+ let ProfilerController = class ProfilerController {
23
+ constructor(profilerService, viewService, templateBuilder, entityExplorer, routeExplorer) {
24
+ this.profilerService = profilerService;
25
+ this.viewService = viewService;
26
+ this.templateBuilder = templateBuilder;
27
+ this.entityExplorer = entityExplorer;
28
+ this.routeExplorer = routeExplorer;
29
+ }
30
+ async dashboard(res) {
31
+ const profiles = await this.profilerService.getDashboardData();
32
+ const content = this.templateBuilder.buildDashboard(profiles);
33
+ const html = this.viewService.renderWithLayout('Requests', content, 'requests');
34
+ res.header('Content-Type', 'text/html');
35
+ res.send(html);
36
+ }
37
+ async listJson() {
38
+ return this.profilerService.getAllProfilesJson();
39
+ }
40
+ async debugQuery() {
41
+ const { Client } = require('pg');
42
+ const client = new Client({
43
+ host: process.env.DB_HOST || 'localhost',
44
+ port: 5432,
45
+ user: process.env.DB_USER || 'postgres',
46
+ password: process.env.DB_PASSWORD || 'postgres',
47
+ database: process.env.DB_NAME || 'postgres',
48
+ });
49
+ try {
50
+ await client.connect();
51
+ await client.query('SELECT 1 as test_query');
52
+ await client.end();
53
+ return { status: 'success', message: 'Query executed. Check profiler.' };
54
+ }
55
+ catch (e) {
56
+ return {
57
+ status: 'error',
58
+ message: `Connection failed: ${e.message}`,
59
+ tip: 'Pass correct credentials in URL: ?user=YOUR_USER&password=YOUR_PASS&database=YOUR_DB'
60
+ };
61
+ }
62
+ }
63
+ async detail(id, res) {
64
+ const profile = await this.profilerService.getProfileDetail(id);
65
+ if (!profile) {
66
+ const content = this.templateBuilder.buildNotFound(id);
67
+ const html = this.viewService.renderWithLayout('Profile Not Found', content);
68
+ res.header('Content-Type', 'text/html');
69
+ res.status(common_1.HttpStatus.NOT_FOUND).send(html);
70
+ return;
71
+ }
72
+ const content = this.templateBuilder.buildDetail(profile);
73
+ const html = this.viewService.renderWithLayout(`Request ${profile.id}`, content);
74
+ res.header('Content-Type', 'text/html');
75
+ res.send(html);
76
+ }
77
+ async detailJson(id) {
78
+ const profile = await this.profilerService.getProfileJson(id);
79
+ if (!profile)
80
+ throw new common_1.NotFoundException('Profile not found');
81
+ return profile;
82
+ }
83
+ async listQueries(res) {
84
+ const queries = await this.profilerService.getQueriesList();
85
+ const content = this.templateBuilder.buildQueriesList(queries);
86
+ const html = this.viewService.renderWithLayout('Database Queries', content, 'queries');
87
+ res.header('Content-Type', 'text/html');
88
+ res.send(html);
89
+ }
90
+ async listLogs(res, page = 1) {
91
+ const { logs, currentPage, totalPages, totalLogs } = await this.profilerService.getLogsList(page);
92
+ const content = this.templateBuilder.buildLogsList(logs, currentPage, totalPages, totalLogs);
93
+ const html = this.viewService.renderWithLayout('Application Logs', content, 'logs');
94
+ res.header('Content-Type', 'text/html');
95
+ res.send(html);
96
+ }
97
+ async listEntities(res) {
98
+ const entities = this.entityExplorer.getEntities();
99
+ const content = this.templateBuilder.buildEntitiesList(entities);
100
+ const html = this.viewService.renderWithLayout('Entity Explorer', content, 'entities');
101
+ res.header('Content-Type', 'text/html');
102
+ res.send(html);
103
+ }
104
+ async listRoutes(res) {
105
+ const routes = this.routeExplorer.getRoutes();
106
+ const content = this.templateBuilder.buildRoutesList(routes);
107
+ const html = this.viewService.renderWithLayout('Routes Explorer', content, 'routes');
108
+ res.header('Content-Type', 'text/html');
109
+ res.send(html);
110
+ }
111
+ async listCache(res) {
112
+ const cacheOps = await this.profilerService.getCacheList();
113
+ const content = this.templateBuilder.buildCacheList(cacheOps);
114
+ const html = this.viewService.renderWithLayout('Cache Operations', content, 'cache');
115
+ res.header('Content-Type', 'text/html');
116
+ res.send(html);
117
+ }
118
+ async serveAsset(file, res) {
119
+ const fs = require('fs');
120
+ const path = require('path');
121
+ const assetsPath = path.join(__dirname, '..', 'assets');
122
+ const filePath = path.join(assetsPath, file);
123
+ if (fs.existsSync(filePath)) {
124
+ const ext = path.extname(file);
125
+ let contentType = 'text/plain';
126
+ if (ext === '.png')
127
+ contentType = 'image/png';
128
+ if (ext === '.ico')
129
+ contentType = 'image/x-icon';
130
+ if (ext === '.svg')
131
+ contentType = 'image/svg+xml';
132
+ if (ext === '.css')
133
+ contentType = 'text/css';
134
+ if (ext === '.js')
135
+ contentType = 'text/javascript';
136
+ res.header('Content-Type', contentType);
137
+ res.header('Cache-Control', 'public, max-age=86400');
138
+ fs.createReadStream(filePath).pipe(res);
139
+ }
140
+ else {
141
+ res.status(common_1.HttpStatus.NOT_FOUND).send('Asset not found');
142
+ }
143
+ }
144
+ async serveJs(file, res) {
145
+ const fs = require('fs');
146
+ const path = require('path');
147
+ const jsPath = path.join(__dirname, '..', 'views', 'js');
148
+ const filePath = path.join(jsPath, file);
149
+ if (fs.existsSync(filePath)) {
150
+ res.header('Content-Type', 'text/javascript');
151
+ res.header('Cache-Control', 'public, max-age=86400');
152
+ fs.createReadStream(filePath).pipe(res);
153
+ }
154
+ else {
155
+ res.status(common_1.HttpStatus.NOT_FOUND).send('Script not found');
156
+ }
157
+ }
158
+ };
159
+ exports.ProfilerController = ProfilerController;
160
+ __decorate([
161
+ (0, common_1.Get)(),
162
+ __param(0, (0, common_1.Res)()),
163
+ __metadata("design:type", Function),
164
+ __metadata("design:paramtypes", [Object]),
165
+ __metadata("design:returntype", Promise)
166
+ ], ProfilerController.prototype, "dashboard", null);
167
+ __decorate([
168
+ (0, common_1.Get)('json'),
169
+ __metadata("design:type", Function),
170
+ __metadata("design:paramtypes", []),
171
+ __metadata("design:returntype", Promise)
172
+ ], ProfilerController.prototype, "listJson", null);
173
+ __decorate([
174
+ (0, common_1.Get)('debug/test-query'),
175
+ __metadata("design:type", Function),
176
+ __metadata("design:paramtypes", []),
177
+ __metadata("design:returntype", Promise)
178
+ ], ProfilerController.prototype, "debugQuery", null);
179
+ __decorate([
180
+ (0, common_1.Get)(':id'),
181
+ __param(0, (0, common_1.Param)('id')),
182
+ __param(1, (0, common_1.Res)()),
183
+ __metadata("design:type", Function),
184
+ __metadata("design:paramtypes", [String, Object]),
185
+ __metadata("design:returntype", Promise)
186
+ ], ProfilerController.prototype, "detail", null);
187
+ __decorate([
188
+ (0, common_1.Get)(':id/json'),
189
+ __param(0, (0, common_1.Param)('id')),
190
+ __metadata("design:type", Function),
191
+ __metadata("design:paramtypes", [String]),
192
+ __metadata("design:returntype", Promise)
193
+ ], ProfilerController.prototype, "detailJson", null);
194
+ __decorate([
195
+ (0, common_1.Get)('view/queries'),
196
+ __param(0, (0, common_1.Res)()),
197
+ __metadata("design:type", Function),
198
+ __metadata("design:paramtypes", [Object]),
199
+ __metadata("design:returntype", Promise)
200
+ ], ProfilerController.prototype, "listQueries", null);
201
+ __decorate([
202
+ (0, common_1.Get)('view/logs'),
203
+ __param(0, (0, common_1.Res)()),
204
+ __param(1, (0, common_1.Query)('page')),
205
+ __metadata("design:type", Function),
206
+ __metadata("design:paramtypes", [Object, Number]),
207
+ __metadata("design:returntype", Promise)
208
+ ], ProfilerController.prototype, "listLogs", null);
209
+ __decorate([
210
+ (0, common_1.Get)('view/entities'),
211
+ __param(0, (0, common_1.Res)()),
212
+ __metadata("design:type", Function),
213
+ __metadata("design:paramtypes", [Object]),
214
+ __metadata("design:returntype", Promise)
215
+ ], ProfilerController.prototype, "listEntities", null);
216
+ __decorate([
217
+ (0, common_1.Get)('view/routes'),
218
+ __param(0, (0, common_1.Res)()),
219
+ __metadata("design:type", Function),
220
+ __metadata("design:paramtypes", [Object]),
221
+ __metadata("design:returntype", Promise)
222
+ ], ProfilerController.prototype, "listRoutes", null);
223
+ __decorate([
224
+ (0, common_1.Get)('view/cache'),
225
+ __param(0, (0, common_1.Res)()),
226
+ __metadata("design:type", Function),
227
+ __metadata("design:paramtypes", [Object]),
228
+ __metadata("design:returntype", Promise)
229
+ ], ProfilerController.prototype, "listCache", null);
230
+ __decorate([
231
+ (0, common_1.Get)('assets/:file'),
232
+ __param(0, (0, common_1.Param)('file')),
233
+ __param(1, (0, common_1.Res)()),
234
+ __metadata("design:type", Function),
235
+ __metadata("design:paramtypes", [String, Object]),
236
+ __metadata("design:returntype", Promise)
237
+ ], ProfilerController.prototype, "serveAsset", null);
238
+ __decorate([
239
+ (0, common_1.Get)('js/:file'),
240
+ __param(0, (0, common_1.Param)('file')),
241
+ __param(1, (0, common_1.Res)()),
242
+ __metadata("design:type", Function),
243
+ __metadata("design:paramtypes", [String, Object]),
244
+ __metadata("design:returntype", Promise)
245
+ ], ProfilerController.prototype, "serveJs", null);
246
+ exports.ProfilerController = ProfilerController = __decorate([
247
+ (0, common_1.Controller)('__profiler'),
248
+ __metadata("design:paramtypes", [profiler_service_1.ProfilerService,
249
+ view_service_1.ViewService,
250
+ template_builder_service_1.TemplateBuilderService,
251
+ entity_explorer_service_1.EntityExplorerService,
252
+ route_explorer_service_1.RouteExplorerService])
253
+ ], ProfilerController);
254
+ //# sourceMappingURL=profiler.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.controller.js","sourceRoot":"","sources":["../../../libs/nestjs-profiler/src/controllers/profiler.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2G;AAE3G,mEAA+D;AAC/D,2DAAuD;AACvD,mFAA8E;AAC9E,iFAA4E;AAE5E,+EAA0E;AAGnE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC3B,YACqB,eAAgC,EAChC,WAAwB,EACxB,eAAuC,EACvC,cAAqC,EACrC,aAAmC;QAJnC,oBAAe,GAAf,eAAe,CAAiB;QAChC,gBAAW,GAAX,WAAW,CAAa;QACxB,oBAAe,GAAf,eAAe,CAAwB;QACvC,mBAAc,GAAd,cAAc,CAAuB;QACrC,kBAAa,GAAb,aAAa,CAAsB;IACpD,CAAC;IAGC,AAAN,KAAK,CAAC,SAAS,CAAQ,GAAa;QAChC,MAAM,QAAQ,GAAG,M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AOtB;AAGK;IADL,IAAA,YAAG,EAAC,YAAY,CAAC;IACD,WAAA,IAAA,YAAG,GAAE,CAAA;;;;mDAOrB;AAGK;IADL,IAAA,YAAG,EAAC,cAAc,CAAC;IACF,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;IAAgB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;oDAsBrD;AAGK;IADL,IAAA,YAAG,EAAC,UAAU,CAAC;IACD,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;IAAgB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;iDAchD;6BApKU,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,YAAY,CAAC;qCAGiB,kCAAe;QACnB,0BAAW;QACP,iDAAsB;QACvB,+CAAqB;QACtB,6CAAoB;GAN/C,kBAAkB,CAqK9B"}
@@ -0,0 +1,11 @@
1
+ import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
2
+ import { Observable } from 'rxjs';
3
+ import { ProfilerService } from '../services/profiler.service';
4
+ export declare class RequestProfilerInterceptor implements NestInterceptor {
5
+ private profiler;
6
+ private logger;
7
+ constructor(profiler: ProfilerService);
8
+ intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
9
+ private finishProfile;
10
+ private sanitizeHeaders;
11
+ }
@@ -0,0 +1,103 @@
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
+ var RequestProfilerInterceptor_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.RequestProfilerInterceptor = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const operators_1 = require("rxjs/operators");
16
+ const profiler_service_1 = require("../services/profiler.service");
17
+ let RequestProfilerInterceptor = RequestProfilerInterceptor_1 = class RequestProfilerInterceptor {
18
+ constructor(profiler) {
19
+ this.profiler = profiler;
20
+ this.logger = new common_1.Logger(RequestProfilerInterceptor_1.name);
21
+ }
22
+ intercept(context, next) {
23
+ const http = context.switchToHttp();
24
+ const req = http.getRequest();
25
+ const res = http.getResponse();
26
+ if (process.env.PROFILER_DEBUG) {
27
+ this.logger.debug(`Starting profile for ${req.method} ${req.url}`);
28
+ }
29
+ if (!req || !res || req.url.startsWith('/__profiler') || req.url.includes('favicon.ico') || req.method === 'OPTIONS') {
30
+ return next.handle();
31
+ }
32
+ if (req._profilerAttached) {
33
+ return next.handle();
34
+ }
35
+ req._profilerAttached = true;
36
+ const interceptorStartTime = Date.now();
37
+ const middlewareStartTime = req._profilerT0 || interceptorStartTime;
38
+ const profile = this.profiler.startRequest();
39
+ if (profile) {
40
+ profile.method = req.method;
41
+ profile.url = req.originalUrl || req.url;
42
+ profile.controller = context.getClass().name;
43
+ profile.handler = context.getHandler().name;
44
+ profile.requestHeaders = this.sanitizeHeaders(req.headers);
45
+ profile.requestBody = req.body;
46
+ }
47
+ return next.handle().pipe((0, operators_1.tap)({
48
+ next: () => {
49
+ if (profile) {
50
+ profile.statusCode = res.statusCode;
51
+ this.finishProfile(profile, interceptorStartTime, middlewareStartTime);
52
+ }
53
+ },
54
+ error: (err) => {
55
+ if (profile) {
56
+ const status = err.status || err.statusCode || 500;
57
+ profile.statusCode = status;
58
+ profile.exception = {
59
+ message: err.message,
60
+ stack: err.stack
61
+ };
62
+ profile.queries.push({
63
+ sql: 'ERROR_CONTEXT',
64
+ duration: 0,
65
+ startTime: Date.now(),
66
+ error: err.message,
67
+ database: 'postgres',
68
+ });
69
+ this.finishProfile(profile, interceptorStartTime, middlewareStartTime);
70
+ }
71
+ },
72
+ }));
73
+ }
74
+ finishProfile(profile, interceptorStartTime, middlewareStartTime) {
75
+ const endTime = Date.now();
76
+ const totalDuration = endTime - middlewareStartTime;
77
+ const middlewareDuration = interceptorStartTime - middlewareStartTime;
78
+ const handlerDuration = endTime - interceptorStartTime;
79
+ profile.timings = {
80
+ total: totalDuration,
81
+ middleware: Math.max(0, middlewareDuration),
82
+ handler: Math.max(0, handlerDuration)
83
+ };
84
+ profile.duration = totalDuration;
85
+ this.profiler.endRequest(profile);
86
+ }
87
+ sanitizeHeaders(headers) {
88
+ const sanitized = { ...headers };
89
+ const sensitive = ['authorization', 'cookie', 'set-cookie', 'x-api-key'];
90
+ sensitive.forEach(key => {
91
+ if (sanitized[key]) {
92
+ sanitized[key] = '*** MASKED ***';
93
+ }
94
+ });
95
+ return sanitized;
96
+ }
97
+ };
98
+ exports.RequestProfilerInterceptor = RequestProfilerInterceptor;
99
+ exports.RequestProfilerInterceptor = RequestProfilerInterceptor = RequestProfilerInterceptor_1 = __decorate([
100
+ (0, common_1.Injectable)(),
101
+ __metadata("design:paramtypes", [profiler_service_1.ProfilerService])
102
+ ], RequestProfilerInterceptor);
103
+ //# sourceMappingURL=request-profiler.interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-profiler.interceptor.js","sourceRoot":"","sources":["../../../libs/nestjs-profiler/src/interceptors/request-profiler.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoG;AAEpG,8CAAiD;AACjD,mEAA+D;AAGxD,IAAM,0BAA0B,kCAAhC,MAAM,0BAA0B;IAGnC,YAAoB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAFrC,WAAM,GAAG,IAAI,eAAM,CAAC,4BAA0B,CAAC,IAAI,CAAC,CAAC;IAEZ,CAAC;IAElD,SAAS,CAAC,OAAy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,EAAE,CAAC;QAC3B,MAAM,aAAa,GAAG,OAAO,GAAG,mBAAmB,CAAC;QACpD,MAAM,kBAAkB,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;QACtE,MAAM,eAAe,GAAG,OAAO,GAAG,oBAAoB,CAAC;QAEvD,OAAO,CAAC,OAAO,GAAG;YACd,KAAK,EAAE,aAAa;YACpB,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,CAAC;YAC3C,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,eAAe,CAAC;SACxC,CAAC;QAEF,OAAO,CAAC,QAAQ,GAAG,aAAa,CAAC;QAEjC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IAEO,eAAe,CAAC,OAAY;QAChC,MAAM,SAAS,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,CAAC,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;QAEzE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACpB,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;gBACjB,SAAS,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC;YACtC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ,CAAA;AAnGY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,mBAAU,GAAE;qCAIqB,kCAAe;GAHpC,0BAA0B,CAmGtC"}
@@ -0,0 +1,4 @@
1
+ import { NestMiddleware } from '@nestjs/common';
2
+ export declare class ProfilerMiddleware implements NestMiddleware {
3
+ use(req: any, res: any, next: () => void): void;
4
+ }
@@ -0,0 +1,21 @@
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.ProfilerMiddleware = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ let ProfilerMiddleware = class ProfilerMiddleware {
12
+ use(req, res, next) {
13
+ req._profilerT0 = Date.now();
14
+ next();
15
+ }
16
+ };
17
+ exports.ProfilerMiddleware = ProfilerMiddleware;
18
+ exports.ProfilerMiddleware = ProfilerMiddleware = __decorate([
19
+ (0, common_1.Injectable)()
20
+ ], ProfilerMiddleware);
21
+ //# sourceMappingURL=profiler.middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.middleware.js","sourceRoot":"","sources":["../../../libs/nestjs-profiler/src/middleware/profiler.middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4D;AAGrD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC3B,GAAG,CAAC,GAAQ,EAAE,GAAQ,EAAE,IAAgB;QACpC,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,IAAI,EAAE,CAAC;IACX,CAAC;CACJ,CAAA;AALY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAK9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-profiler",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "A NestJS module for profiling HTTP requests, database queries, and cache operations. Inspired by Symfony Profiler, it provides a web-based dashboard to inspect request duration, executed queries, log messages, and explain plans for slow queries.",
5
5
  "author": "Mohamed Raslan",
6
6
  "main": "./index.js",
@@ -17,11 +17,12 @@
17
17
  "access": "public"
18
18
  },
19
19
  "files": [
20
- "index.js",
21
- "index.d.ts",
22
- "index.js.map",
20
+ "**/*.js",
21
+ "**/*.d.ts",
22
+ "**/*.js.map",
23
23
  "src/assets",
24
24
  "src/views",
25
+ "package.json",
25
26
  "README.md"
26
27
  ],
27
28
  "peerDependencies": {
@@ -0,0 +1,12 @@
1
+ import { ConsoleLogger } from '@nestjs/common';
2
+ import { ProfilerService } from './services/profiler.service';
3
+ export declare class ProfilerLogger extends ConsoleLogger {
4
+ private profiler;
5
+ constructor(profiler: ProfilerService);
6
+ log(message: any, ...optionalParams: any[]): void;
7
+ error(message: any, ...optionalParams: any[]): void;
8
+ warn(message: any, ...optionalParams: any[]): void;
9
+ debug(message: any, ...optionalParams: any[]): void;
10
+ verbose(message: any, ...optionalParams: any[]): void;
11
+ private captureLog;
12
+ }
@@ -0,0 +1,59 @@
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.ProfilerLogger = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const profiler_service_1 = require("./services/profiler.service");
15
+ let ProfilerLogger = class ProfilerLogger extends common_1.ConsoleLogger {
16
+ constructor(profiler) {
17
+ super();
18
+ this.profiler = profiler;
19
+ }
20
+ log(message, ...optionalParams) {
21
+ super.log(message, ...optionalParams);
22
+ this.captureLog('log', message, optionalParams);
23
+ }
24
+ error(message, ...optionalParams) {
25
+ super.error(message, ...optionalParams);
26
+ this.captureLog('error', message, optionalParams);
27
+ }
28
+ warn(message, ...optionalParams) {
29
+ super.warn(message, ...optionalParams);
30
+ this.captureLog('warn', message, optionalParams);
31
+ }
32
+ debug(message, ...optionalParams) {
33
+ super.debug(message, ...optionalParams);
34
+ this.captureLog('debug', message, optionalParams);
35
+ }
36
+ verbose(message, ...optionalParams) {
37
+ super.verbose(message, ...optionalParams);
38
+ this.captureLog('verbose', message, optionalParams);
39
+ }
40
+ captureLog(level, message, params) {
41
+ try {
42
+ const context = params.length > 0 ? params[params.length - 1] : undefined;
43
+ const msgStr = typeof message === 'object' ? JSON.stringify(message) : String(message);
44
+ this.profiler.addLog({
45
+ level,
46
+ message: msgStr,
47
+ context: typeof context === 'string' ? context : undefined,
48
+ timestamp: Date.now()
49
+ });
50
+ }
51
+ catch (e) { }
52
+ }
53
+ };
54
+ exports.ProfilerLogger = ProfilerLogger;
55
+ exports.ProfilerLogger = ProfilerLogger = __decorate([
56
+ (0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
57
+ __metadata("design:paramtypes", [profiler_service_1.ProfilerService])
58
+ ], ProfilerLogger);
59
+ //# sourceMappingURL=profiler-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler-logger.js","sourceRoot":"","sources":["../../libs/nestjs-profiler/src/profiler-logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAkE;AAClE,kEAA8D;AAGvD,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,sBAAa;IAC7C,YAAoB,QAAyB;QACzC,KAAK,EAAE,CAAC;QADQ,aAAQ,GAAR,QAAQ,CAAiB;IAE7C,CAAC;IAED,GAAG,CAAC,OAAY,EAAE,GAAG,cAAqB;QACtC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,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AAC,CAAC;YAEvF,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;gBACjB,KAAK;gBACL,OAAO,EAAE,MAAM;gBACf,OAAO,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;gBAC1D,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACxB,CAAC,CAAC;QACP,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,CAAC;CACJ,CAAA;AA5CY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,SAAS,EAAE,CAAC;qCAEL,kCAAe;GADpC,cAAc,CA4C1B"}
@@ -0,0 +1,7 @@
1
+ import { DynamicModule, MiddlewareConsumer, NestModule } from '@nestjs/common';
2
+ import { ProfilerOptions } from './common/profiler-options.interface';
3
+ export declare class ProfilerModule implements NestModule {
4
+ configure(consumer: MiddlewareConsumer): void;
5
+ static forRoot(options?: ProfilerOptions): DynamicModule;
6
+ static initialize(app: any): void;
7
+ }
@@ -0,0 +1,105 @@
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 ProfilerModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ProfilerModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const profiler_service_1 = require("./services/profiler.service");
13
+ const view_service_1 = require("./services/view.service");
14
+ const template_builder_service_1 = require("./services/template-builder.service");
15
+ const entity_explorer_service_1 = require("./services/entity-explorer.service");
16
+ const route_explorer_service_1 = require("./services/route-explorer.service");
17
+ const postgres_collector_1 = require("./collectors/postgres-collector");
18
+ const mongo_collector_1 = require("./collectors/mongo-collector");
19
+ const mysql_collector_1 = require("./collectors/mysql-collector");
20
+ const log_collector_1 = require("./collectors/log-collector");
21
+ const cache_collector_1 = require("./collectors/cache-collector");
22
+ const explain_analyzer_1 = require("./analyzers/explain-analyzer");
23
+ const in_memory_profiler_storage_1 = require("./storage/in-memory-profiler-storage");
24
+ const profiler_controller_1 = require("./controllers/profiler.controller");
25
+ const request_profiler_interceptor_1 = require("./interceptors/request-profiler.interceptor");
26
+ const core_1 = require("@nestjs/core");
27
+ const profiler_logger_1 = require("./profiler-logger");
28
+ const profiler_middleware_1 = require("./middleware/profiler.middleware");
29
+ let ProfilerModule = ProfilerModule_1 = class ProfilerModule {
30
+ configure(consumer) {
31
+ consumer
32
+ .apply(profiler_middleware_1.ProfilerMiddleware)
33
+ .exclude({ path: '__profiler/(.*)', method: common_1.RequestMethod.ALL })
34
+ .forRoutes({ path: '*', method: common_1.RequestMethod.ALL });
35
+ }
36
+ static forRoot(options = {}) {
37
+ const optionsProvider = {
38
+ provide: 'PROFILER_OPTIONS',
39
+ useValue: options,
40
+ };
41
+ const storageProvider = {
42
+ provide: 'PROFILER_STORAGE',
43
+ useValue: typeof options.storage === 'object' && options.storage !== null
44
+ ? options.storage
45
+ : new in_memory_profiler_storage_1.InMemoryProfilerStorage(),
46
+ };
47
+ return {
48
+ module: ProfilerModule_1,
49
+ imports: [],
50
+ providers: [
51
+ optionsProvider,
52
+ storageProvider,
53
+ profiler_service_1.ProfilerService,
54
+ view_service_1.ViewService,
55
+ template_builder_service_1.TemplateBuilderService,
56
+ entity_explorer_service_1.EntityExplorerService,
57
+ route_explorer_service_1.RouteExplorerService,
58
+ postgres_collector_1.PostgresCollector,
59
+ mongo_collector_1.MongoCollector,
60
+ mysql_collector_1.MysqlCollector,
61
+ log_collector_1.LogCollector,
62
+ cache_collector_1.CacheCollector,
63
+ explain_analyzer_1.ExplainAnalyzer,
64
+ {
65
+ provide: core_1.APP_INTERCEPTOR,
66
+ useClass: request_profiler_interceptor_1.RequestProfilerInterceptor,
67
+ },
68
+ ],
69
+ exports: [profiler_service_1.ProfilerService],
70
+ };
71
+ }
72
+ static initialize(app) {
73
+ try {
74
+ const container = app.container;
75
+ const modulesContainer = container.getModules();
76
+ const entityExplorer = app.get(entity_explorer_service_1.EntityExplorerService);
77
+ entityExplorer.initialize(modulesContainer);
78
+ const routeExplorer = app.get(route_explorer_service_1.RouteExplorerService);
79
+ const globalPrefix = app.config?.getGlobalPrefix
80
+ ? app.config.getGlobalPrefix()
81
+ : '';
82
+ routeExplorer.initialize(modulesContainer, globalPrefix);
83
+ }
84
+ catch (e) {
85
+ console.warn('Profiler: Could not initialize Explorers. Ensure ProfilerModule is imported.', e);
86
+ }
87
+ }
88
+ };
89
+ exports.ProfilerModule = ProfilerModule;
90
+ exports.ProfilerModule = ProfilerModule = ProfilerModule_1 = __decorate([
91
+ (0, common_1.Global)(),
92
+ (0, common_1.Module)({
93
+ controllers: [profiler_controller_1.ProfilerController],
94
+ providers: [
95
+ profiler_service_1.ProfilerService,
96
+ profiler_logger_1.ProfilerLogger,
97
+ view_service_1.ViewService,
98
+ template_builder_service_1.TemplateBuilderService,
99
+ entity_explorer_service_1.EntityExplorerService,
100
+ route_explorer_service_1.RouteExplorerService,
101
+ ],
102
+ exports: [profiler_service_1.ProfilerService, entity_explorer_service_1.EntityExplorerService, route_explorer_service_1.RouteExplorerService],
103
+ })
104
+ ], ProfilerModule);
105
+ //# sourceMappingURL=profiler.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.module.js","sourceRoot":"","sources":["../../libs/nestjs-profiler/src/profiler.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAQwB;AAExB,kEAA8D;AAC9D,0DAAsD;AACtD,kFAA6E;AAC7E,gFA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