nest-devtools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/dashboard/index.html.d.ts +1 -0
- package/dist/dashboard/index.html.js +1052 -0
- package/dist/dashboard/index.html.js.map +1 -0
- package/dist/devtools.controller.d.ts +2 -0
- package/dist/devtools.controller.js +87 -0
- package/dist/devtools.controller.js.map +1 -0
- package/dist/devtools.module.d.ts +6 -0
- package/dist/devtools.module.js +55 -0
- package/dist/devtools.module.js.map +1 -0
- package/dist/devtools.realtime.d.ts +18 -0
- package/dist/devtools.realtime.js +111 -0
- package/dist/devtools.realtime.js.map +1 -0
- package/dist/devtools.store.d.ts +12 -0
- package/dist/devtools.store.js +51 -0
- package/dist/devtools.store.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/logger.capture.d.ts +23 -0
- package/dist/logger/logger.capture.js +246 -0
- package/dist/logger/logger.capture.js.map +1 -0
- package/dist/realtime/websocket.utils.d.ts +2 -0
- package/dist/realtime/websocket.utils.js +28 -0
- package/dist/realtime/websocket.utils.js.map +1 -0
- package/dist/request/request.interceptor.d.ts +13 -0
- package/dist/request/request.interceptor.js +74 -0
- package/dist/request/request.interceptor.js.map +1 -0
- package/dist/types.d.ts +41 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/headers.d.ts +2 -0
- package/dist/utils/headers.js +25 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/id.d.ts +1 -0
- package/dist/utils/id.js +9 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/path.d.ts +4 -0
- package/dist/utils/path.js +37 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/ring-buffer.d.ts +10 -0
- package/dist/utils/ring-buffer.js +41 -0
- package/dist/utils/ring-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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAkhCnB,CAAC;AAET,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,OAAO,kBAAkB,CAAC,OAAO,CAC/B,0BAA0B,EAC1B,IAAI,CAAC,SAAS,CAAC;QACb,QAAQ;KACT,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
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.createDevtoolsController = createDevtoolsController;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const constants_1 = require("./constants");
|
|
18
|
+
const index_html_1 = require("./dashboard/index.html");
|
|
19
|
+
const devtools_realtime_1 = require("./devtools.realtime");
|
|
20
|
+
const devtools_store_1 = require("./devtools.store");
|
|
21
|
+
function createDevtoolsController(controllerPath) {
|
|
22
|
+
let DevtoolsControllerHost = class DevtoolsControllerHost {
|
|
23
|
+
constructor(store, realtimeServer, options) {
|
|
24
|
+
this.store = store;
|
|
25
|
+
this.realtimeServer = realtimeServer;
|
|
26
|
+
this.options = options;
|
|
27
|
+
}
|
|
28
|
+
dashboard() {
|
|
29
|
+
return (0, index_html_1.renderDashboardHtml)(this.options.absolutePath);
|
|
30
|
+
}
|
|
31
|
+
getLogs() {
|
|
32
|
+
return this.store.getLogs();
|
|
33
|
+
}
|
|
34
|
+
getRequests() {
|
|
35
|
+
return this.store.getRequests();
|
|
36
|
+
}
|
|
37
|
+
clearLogs() {
|
|
38
|
+
this.store.clear('logs');
|
|
39
|
+
this.realtimeServer.broadcastClear('logs');
|
|
40
|
+
}
|
|
41
|
+
clearRequests() {
|
|
42
|
+
this.store.clear('requests');
|
|
43
|
+
this.realtimeServer.broadcastClear('requests');
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, common_1.Get)(),
|
|
48
|
+
(0, common_1.Header)('content-type', 'text/html; charset=utf-8'),
|
|
49
|
+
__metadata("design:type", Function),
|
|
50
|
+
__metadata("design:paramtypes", []),
|
|
51
|
+
__metadata("design:returntype", String)
|
|
52
|
+
], DevtoolsControllerHost.prototype, "dashboard", null);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, common_1.Get)('api/logs'),
|
|
55
|
+
__metadata("design:type", Function),
|
|
56
|
+
__metadata("design:paramtypes", []),
|
|
57
|
+
__metadata("design:returntype", void 0)
|
|
58
|
+
], DevtoolsControllerHost.prototype, "getLogs", null);
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, common_1.Get)('api/requests'),
|
|
61
|
+
__metadata("design:type", Function),
|
|
62
|
+
__metadata("design:paramtypes", []),
|
|
63
|
+
__metadata("design:returntype", void 0)
|
|
64
|
+
], DevtoolsControllerHost.prototype, "getRequests", null);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, common_1.Delete)('api/logs'),
|
|
67
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", []),
|
|
70
|
+
__metadata("design:returntype", void 0)
|
|
71
|
+
], DevtoolsControllerHost.prototype, "clearLogs", null);
|
|
72
|
+
__decorate([
|
|
73
|
+
(0, common_1.Delete)('api/requests'),
|
|
74
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
|
|
75
|
+
__metadata("design:type", Function),
|
|
76
|
+
__metadata("design:paramtypes", []),
|
|
77
|
+
__metadata("design:returntype", void 0)
|
|
78
|
+
], DevtoolsControllerHost.prototype, "clearRequests", null);
|
|
79
|
+
DevtoolsControllerHost = __decorate([
|
|
80
|
+
(0, common_1.Controller)(controllerPath),
|
|
81
|
+
__param(2, (0, common_1.Inject)(constants_1.DEVTOOLS_OPTIONS)),
|
|
82
|
+
__metadata("design:paramtypes", [devtools_store_1.DevtoolsStore,
|
|
83
|
+
devtools_realtime_1.DevtoolsRealtimeServer, Object])
|
|
84
|
+
], DevtoolsControllerHost);
|
|
85
|
+
return DevtoolsControllerHost;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=devtools.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.controller.js","sourceRoot":"","sources":["../src/devtools.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAQA,4DAyCC;AAjDD,2CAAqG;AAErG,2CAA+C;AAC/C,uDAA6D;AAC7D,2DAA6D;AAC7D,qDAAiD;AAGjD,SAAgB,wBAAwB,CAAC,cAAsB;IAC7D,IACM,sBAAsB,GAD5B,MACM,sBAAsB;QAC1B,YACmB,KAAoB,EACpB,cAAsC,EACZ,OAAgC;YAF1D,UAAK,GAAL,KAAK,CAAe;YACpB,mBAAc,GAAd,cAAc,CA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|
|
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 DevtoolsModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DevtoolsModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const core_1 = require("@nestjs/core");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const devtools_controller_1 = require("./devtools.controller");
|
|
15
|
+
const devtools_realtime_1 = require("./devtools.realtime");
|
|
16
|
+
const devtools_store_1 = require("./devtools.store");
|
|
17
|
+
const logger_capture_1 = require("./logger/logger.capture");
|
|
18
|
+
const request_interceptor_1 = require("./request/request.interceptor");
|
|
19
|
+
const path_1 = require("./utils/path");
|
|
20
|
+
let DevtoolsModule = DevtoolsModule_1 = class DevtoolsModule {
|
|
21
|
+
static forRoot(options) {
|
|
22
|
+
if (process.env.NODE_ENV === 'production') {
|
|
23
|
+
return {
|
|
24
|
+
module: DevtoolsModule_1,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const resolvedOptions = (0, path_1.normalizeDevtoolsOptions)(options);
|
|
28
|
+
const controller = (0, devtools_controller_1.createDevtoolsController)(resolvedOptions.controllerPath);
|
|
29
|
+
return {
|
|
30
|
+
module: DevtoolsModule_1,
|
|
31
|
+
controllers: [controller],
|
|
32
|
+
providers: this.createProviders(resolvedOptions),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static createProviders(options) {
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
provide: constants_1.DEVTOOLS_OPTIONS,
|
|
39
|
+
useValue: options,
|
|
40
|
+
},
|
|
41
|
+
devtools_store_1.DevtoolsStore,
|
|
42
|
+
devtools_realtime_1.DevtoolsRealtimeServer,
|
|
43
|
+
logger_capture_1.DevtoolsLoggerCapture,
|
|
44
|
+
{
|
|
45
|
+
provide: core_1.APP_INTERCEPTOR,
|
|
46
|
+
useClass: request_interceptor_1.RequestInterceptor,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.DevtoolsModule = DevtoolsModule;
|
|
52
|
+
exports.DevtoolsModule = DevtoolsModule = DevtoolsModule_1 = __decorate([
|
|
53
|
+
(0, common_1.Module)({})
|
|
54
|
+
], DevtoolsModule);
|
|
55
|
+
//# sourceMappingURL=devtools.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.module.js","sourceRoot":"","sources":["../src/devtools.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,uCAA+C;AAE/C,2CAA+C;AAC/C,+DAAiE;AACjE,2DAA6D;AAC7D,qDAAiD;AACjD,4DAAgE;AAChE,uEAAmE;AAEnE,uCAAwD;AAGjD,IAAM,cAAc,sBAApB,MAAM,cAAc;IACzB,MAAM,CAAC,OAAO,CAAC,OAAyB;QACtC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YAC1C,OAAO;gBACL,MAAM,EAAE,gBAAc;aACvB,CAAC;QACJ,CAAC;QAED,MAAM,eAAe,GAAG,IAAA,+BAAwB,EAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,UAAU,GAAG,IAAA,8CAAwB,EAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QAE5E,OAAO;YACL,MAAM,EAAE,gBAAc;YACtB,WAAW,EAAE,CAAC,UAAU,CAAC;YACzB,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC;SACjD,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,OAAgC;QAC7D,OAAO;YACL;gBACE,OAAO,EAAE,4BAAgB;gBACzB,QAAQ,EAAE,OAAO;aAClB;YACD,8BAAa;YACb,0CAAsB;YACtB,sCAAqB;YACrB;gBACE,OAAO,EAAE,sBAAe;gBACxB,QAAQ,EAAE,wCAAkB;aAC7B;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAjCY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,cAAc,CAiC1B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OnApplicationBootstrap, OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
3
|
+
import { LogEntry, RequestEntry, ResolvedDevtoolsOptions } from './types';
|
|
4
|
+
export declare class DevtoolsRealtimeServer implements OnApplicationBootstrap, OnModuleDestroy {
|
|
5
|
+
private readonly adapterHost;
|
|
6
|
+
private readonly options;
|
|
7
|
+
private readonly clients;
|
|
8
|
+
private httpServer?;
|
|
9
|
+
private boundUpgradeHandler?;
|
|
10
|
+
constructor(adapterHost: HttpAdapterHost, options: ResolvedDevtoolsOptions);
|
|
11
|
+
onApplicationBootstrap(): void;
|
|
12
|
+
onModuleDestroy(): void;
|
|
13
|
+
broadcastLog(entry: LogEntry): void;
|
|
14
|
+
broadcastRequest(entry: RequestEntry): void;
|
|
15
|
+
broadcastClear(kind: 'logs' | 'requests'): void;
|
|
16
|
+
private handleUpgrade;
|
|
17
|
+
private broadcast;
|
|
18
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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.DevtoolsRealtimeServer = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const core_1 = require("@nestjs/core");
|
|
18
|
+
const constants_1 = require("./constants");
|
|
19
|
+
const websocket_utils_1 = require("./realtime/websocket.utils");
|
|
20
|
+
let DevtoolsRealtimeServer = class DevtoolsRealtimeServer {
|
|
21
|
+
constructor(adapterHost, options) {
|
|
22
|
+
this.adapterHost = adapterHost;
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.clients = new Set();
|
|
25
|
+
}
|
|
26
|
+
onApplicationBootstrap() {
|
|
27
|
+
const server = this.adapterHost.httpAdapter?.getHttpServer?.();
|
|
28
|
+
if (!server || typeof server.on !== 'function') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.httpServer = server;
|
|
32
|
+
this.boundUpgradeHandler = this.handleUpgrade.bind(this);
|
|
33
|
+
server.on('upgrade', this.boundUpgradeHandler);
|
|
34
|
+
}
|
|
35
|
+
onModuleDestroy() {
|
|
36
|
+
if (this.httpServer && this.boundUpgradeHandler) {
|
|
37
|
+
this.httpServer.off('upgrade', this.boundUpgradeHandler);
|
|
38
|
+
}
|
|
39
|
+
for (const client of this.clients) {
|
|
40
|
+
client.destroy();
|
|
41
|
+
}
|
|
42
|
+
this.clients.clear();
|
|
43
|
+
}
|
|
44
|
+
broadcastLog(entry) {
|
|
45
|
+
this.broadcast({ type: 'log', payload: entry });
|
|
46
|
+
}
|
|
47
|
+
broadcastRequest(entry) {
|
|
48
|
+
this.broadcast({ type: 'request', payload: entry });
|
|
49
|
+
}
|
|
50
|
+
broadcastClear(kind) {
|
|
51
|
+
this.broadcast(kind === 'logs' ? { type: 'clear:logs' } : { type: 'clear:requests' });
|
|
52
|
+
}
|
|
53
|
+
handleUpgrade(request, socket, head) {
|
|
54
|
+
const requestUrl = new URL(request.url ?? '/', 'http://127.0.0.1');
|
|
55
|
+
if (requestUrl.pathname !== this.options.websocketPath) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const key = request.headers['sec-websocket-key'];
|
|
59
|
+
const version = request.headers['sec-websocket-version'];
|
|
60
|
+
if (request.method !== 'GET' || typeof key !== 'string' || version !== '13') {
|
|
61
|
+
socket.write('HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n');
|
|
62
|
+
socket.destroy();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (head.length > 0) {
|
|
66
|
+
socket.unshift(head);
|
|
67
|
+
}
|
|
68
|
+
const acceptValue = (0, websocket_utils_1.createWebSocketAcceptValue)(key);
|
|
69
|
+
socket.write([
|
|
70
|
+
'HTTP/1.1 101 Switching Protocols',
|
|
71
|
+
'Upgrade: websocket',
|
|
72
|
+
'Connection: Upgrade',
|
|
73
|
+
`Sec-WebSocket-Accept: ${acceptValue}`,
|
|
74
|
+
'\r\n',
|
|
75
|
+
].join('\r\n'));
|
|
76
|
+
const cleanup = () => {
|
|
77
|
+
this.clients.delete(socket);
|
|
78
|
+
};
|
|
79
|
+
socket.on('close', cleanup);
|
|
80
|
+
socket.on('end', cleanup);
|
|
81
|
+
socket.on('error', cleanup);
|
|
82
|
+
socket.setNoDelay(true);
|
|
83
|
+
this.clients.add(socket);
|
|
84
|
+
}
|
|
85
|
+
broadcast(message) {
|
|
86
|
+
if (this.clients.size === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const frame = (0, websocket_utils_1.encodeWebSocketTextFrame)(JSON.stringify(message));
|
|
90
|
+
for (const client of [...this.clients]) {
|
|
91
|
+
if (client.destroyed) {
|
|
92
|
+
this.clients.delete(client);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
client.write(frame);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
client.destroy();
|
|
100
|
+
this.clients.delete(client);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.DevtoolsRealtimeServer = DevtoolsRealtimeServer;
|
|
106
|
+
exports.DevtoolsRealtimeServer = DevtoolsRealtimeServer = __decorate([
|
|
107
|
+
(0, common_1.Injectable)(),
|
|
108
|
+
__param(1, (0, common_1.Inject)(constants_1.DEVTOOLS_OPTIONS)),
|
|
109
|
+
__metadata("design:paramtypes", [core_1.HttpAdapterHost, Object])
|
|
110
|
+
], DevtoolsRealtimeServer);
|
|
111
|
+
//# sourceMappingURL=devtools.realtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.realtime.js","sourceRoot":"","sources":["../src/devtools.realtime.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA6F;AAC7F,uCAA+C;AAI/C,2CAA+C;AAE/C,gEAAkG;AAG3F,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IASjC,YACmB,WAA4B,EACnB,OAAiD;QAD1D,gBAAW,GAAX,WAAW,CAAiB;QACF,YAAO,GAAP,OAAO,CAAyB;QAV5D,YAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAW1C,CAAC;IAEJ,sBAAsB;QACp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AAU,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAEO,SAAS,CAAC,OAAgC;QAChD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC5B,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,IAAA,0CAAwB,EAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAEhE,KAAK,MAAM,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;gBACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC5B,SAAS;YACX,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,CAAC,OAAO,EAAE,CAAC;gBACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAjHY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;IAYR,WAAA,IAAA,eAAM,EAAC,4BAAgB,CAAC,CAAA;qCADK,sBAAe;GAVpC,sBAAsB,CAiHlC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ResolvedDevtoolsOptions, LogEntry, RequestEntry } from './types';
|
|
2
|
+
export declare class DevtoolsStore {
|
|
3
|
+
private readonly options;
|
|
4
|
+
private readonly logs;
|
|
5
|
+
private readonly requests;
|
|
6
|
+
constructor(options: ResolvedDevtoolsOptions);
|
|
7
|
+
addLog(entry: LogEntry): void;
|
|
8
|
+
addRequest(entry: RequestEntry): void;
|
|
9
|
+
getLogs(): LogEntry[];
|
|
10
|
+
getRequests(): RequestEntry[];
|
|
11
|
+
clear(type: 'logs' | 'requests'): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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.DevtoolsStore = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const constants_1 = require("./constants");
|
|
18
|
+
const ring_buffer_1 = require("./utils/ring-buffer");
|
|
19
|
+
let DevtoolsStore = class DevtoolsStore {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
this.logs = new ring_buffer_1.RingBuffer(options.maxLogs);
|
|
23
|
+
this.requests = new ring_buffer_1.RingBuffer(options.maxRequests);
|
|
24
|
+
}
|
|
25
|
+
addLog(entry) {
|
|
26
|
+
this.logs.push(entry);
|
|
27
|
+
}
|
|
28
|
+
addRequest(entry) {
|
|
29
|
+
this.requests.push(entry);
|
|
30
|
+
}
|
|
31
|
+
getLogs() {
|
|
32
|
+
return this.logs.values();
|
|
33
|
+
}
|
|
34
|
+
getRequests() {
|
|
35
|
+
return this.requests.values();
|
|
36
|
+
}
|
|
37
|
+
clear(type) {
|
|
38
|
+
if (type === 'logs') {
|
|
39
|
+
this.logs.clear();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.requests.clear();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.DevtoolsStore = DevtoolsStore;
|
|
46
|
+
exports.DevtoolsStore = DevtoolsStore = __decorate([
|
|
47
|
+
(0, common_1.Injectable)(),
|
|
48
|
+
__param(0, (0, common_1.Inject)(constants_1.DEVTOOLS_OPTIONS)),
|
|
49
|
+
__metadata("design:paramtypes", [Object])
|
|
50
|
+
], DevtoolsStore);
|
|
51
|
+
//# sourceMappingURL=devtools.store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.store.js","sourceRoot":"","sources":["../src/devtools.store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,2CAA+C;AAE/C,qDAAiD;AAG1C,IAAM,aAAa,GAAnB,MAAM,aAAa;IAIxB,YAC6C,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;QAE3E,IAAI,CAAC,IAAI,GAAG,IAAI,wBAAU,CAAW,OAAO,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,IAAI,wBAAU,CAAe,OAAO,CAAC,WAAW,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,CAAC,KAAe;QACpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED,UAAU,CAAC,KAAmB;QAC5B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,IAAyB;QAC7B,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF,CAAA;AAnCY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,4BAAgB,CAAC,CAAA;;GALhB,aAAa,CAmCzB"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DevtoolsModule = void 0;
|
|
4
|
+
var devtools_module_1 = require("./devtools.module");
|
|
5
|
+
Object.defineProperty(exports, "DevtoolsModule", { enumerable: true, get: function () { return devtools_module_1.DevtoolsModule; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,iHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { DevtoolsRealtimeServer } from '../devtools.realtime';
|
|
3
|
+
import { DevtoolsStore } from '../devtools.store';
|
|
4
|
+
import { LogLevel } from '../types';
|
|
5
|
+
export interface CapturedLogPayload {
|
|
6
|
+
level: LogLevel;
|
|
7
|
+
context: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
type LoggerListener = (payload: CapturedLogPayload) => void;
|
|
11
|
+
type LoggerMethod = 'log' | 'warn' | 'error' | 'debug' | 'verbose';
|
|
12
|
+
export declare function createCapturedLogPayload(level: LoggerMethod, logger: unknown, args: unknown[]): CapturedLogPayload;
|
|
13
|
+
export declare function registerLoggerListener(listener: LoggerListener): () => void;
|
|
14
|
+
export declare function resetLoggerPatchStateForTests(): void;
|
|
15
|
+
export declare class DevtoolsLoggerCapture implements OnModuleInit, OnModuleDestroy {
|
|
16
|
+
private readonly store;
|
|
17
|
+
private readonly realtimeServer;
|
|
18
|
+
private unregister?;
|
|
19
|
+
constructor(store: DevtoolsStore, realtimeServer: DevtoolsRealtimeServer);
|
|
20
|
+
onModuleInit(): void;
|
|
21
|
+
onModuleDestroy(): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,246 @@
|
|
|
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.DevtoolsLoggerCapture = void 0;
|
|
13
|
+
exports.createCapturedLogPayload = createCapturedLogPayload;
|
|
14
|
+
exports.registerLoggerListener = registerLoggerListener;
|
|
15
|
+
exports.resetLoggerPatchStateForTests = resetLoggerPatchStateForTests;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const util_1 = require("util");
|
|
18
|
+
const devtools_realtime_1 = require("../devtools.realtime");
|
|
19
|
+
const devtools_store_1 = require("../devtools.store");
|
|
20
|
+
const id_1 = require("../utils/id");
|
|
21
|
+
const LOGGER_PATCH_STATE = Symbol.for('nest-devtools.logger-patch-state');
|
|
22
|
+
function getLoggerPatchState() {
|
|
23
|
+
const globalState = globalThis;
|
|
24
|
+
if (!globalState[LOGGER_PATCH_STATE]) {
|
|
25
|
+
globalState[LOGGER_PATCH_STATE] = {
|
|
26
|
+
listeners: new Set(),
|
|
27
|
+
originals: {
|
|
28
|
+
console: {
|
|
29
|
+
log: common_1.ConsoleLogger.prototype.log,
|
|
30
|
+
warn: common_1.ConsoleLogger.prototype.warn,
|
|
31
|
+
error: common_1.ConsoleLogger.prototype.error,
|
|
32
|
+
debug: common_1.ConsoleLogger.prototype.debug,
|
|
33
|
+
verbose: common_1.ConsoleLogger.prototype.verbose,
|
|
34
|
+
},
|
|
35
|
+
loggerInstance: {
|
|
36
|
+
log: common_1.Logger.prototype.log,
|
|
37
|
+
warn: common_1.Logger.prototype.warn,
|
|
38
|
+
error: common_1.Logger.prototype.error,
|
|
39
|
+
debug: common_1.Logger.prototype.debug,
|
|
40
|
+
verbose: common_1.Logger.prototype.verbose,
|
|
41
|
+
},
|
|
42
|
+
loggerStatic: {
|
|
43
|
+
log: common_1.Logger.log,
|
|
44
|
+
warn: common_1.Logger.warn,
|
|
45
|
+
error: common_1.Logger.error,
|
|
46
|
+
debug: common_1.Logger.debug,
|
|
47
|
+
verbose: common_1.Logger.verbose,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
patched: false,
|
|
51
|
+
suppressionDepth: 0,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return globalState[LOGGER_PATCH_STATE];
|
|
55
|
+
}
|
|
56
|
+
function getLoggerContext(logger) {
|
|
57
|
+
const context = logger?.context;
|
|
58
|
+
return typeof context === 'string' ? context : '';
|
|
59
|
+
}
|
|
60
|
+
function formatLogValue(value) {
|
|
61
|
+
if (value instanceof Error) {
|
|
62
|
+
return value.stack ?? value.message;
|
|
63
|
+
}
|
|
64
|
+
if (typeof value === 'string') {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
return (0, util_1.inspect)(value, {
|
|
68
|
+
depth: 5,
|
|
69
|
+
breakLength: 120,
|
|
70
|
+
compact: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function looksLikeStackTrace(value) {
|
|
74
|
+
return value.includes('\n') || value.includes(' at ') || value.startsWith('Error:');
|
|
75
|
+
}
|
|
76
|
+
function resolveStandardPayload(level, logger, args) {
|
|
77
|
+
const values = [...args];
|
|
78
|
+
let context = getLoggerContext(logger);
|
|
79
|
+
if (!context && values.length > 1 && typeof values[values.length - 1] === 'string') {
|
|
80
|
+
context = String(values.pop());
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
level,
|
|
84
|
+
context,
|
|
85
|
+
message: values.map((value) => formatLogValue(value)).join(' ').trim(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function resolveErrorPayload(logger, args) {
|
|
89
|
+
const [message, second, third, ...rest] = args;
|
|
90
|
+
let context = getLoggerContext(logger);
|
|
91
|
+
let stack;
|
|
92
|
+
if (typeof third === 'string') {
|
|
93
|
+
context = third;
|
|
94
|
+
}
|
|
95
|
+
if (second !== undefined) {
|
|
96
|
+
if (!context && typeof second === 'string' && !looksLikeStackTrace(second) && third === undefined) {
|
|
97
|
+
context = second;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
stack = formatLogValue(second);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (rest.length > 0) {
|
|
104
|
+
const restText = rest.map((value) => formatLogValue(value)).join('\n').trim();
|
|
105
|
+
stack = [stack, restText].filter(Boolean).join('\n');
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
level: 'error',
|
|
109
|
+
context,
|
|
110
|
+
message: [formatLogValue(message), stack].filter(Boolean).join('\n').trim(),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function createCapturedLogPayload(level, logger, args) {
|
|
114
|
+
if (level === 'error') {
|
|
115
|
+
return resolveErrorPayload(logger, args);
|
|
116
|
+
}
|
|
117
|
+
return resolveStandardPayload(level, logger, args);
|
|
118
|
+
}
|
|
119
|
+
function notifyListeners(payload) {
|
|
120
|
+
const state = getLoggerPatchState();
|
|
121
|
+
for (const listener of state.listeners) {
|
|
122
|
+
try {
|
|
123
|
+
listener(payload);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Ignore listener failures so logging continues to behave normally.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function patchLoggerMethods() {
|
|
131
|
+
const state = getLoggerPatchState();
|
|
132
|
+
if (state.patched) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const methods = ['log', 'warn', 'error', 'debug', 'verbose'];
|
|
136
|
+
for (const method of methods) {
|
|
137
|
+
common_1.ConsoleLogger.prototype[method] = function patchedConsoleLoggerMethod(...args) {
|
|
138
|
+
const payload = createCapturedLogPayload(method, this, args);
|
|
139
|
+
const original = state.originals.console[method];
|
|
140
|
+
const result = original.apply(this, args);
|
|
141
|
+
if (state.suppressionDepth === 0) {
|
|
142
|
+
notifyListeners(payload);
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
};
|
|
146
|
+
common_1.Logger.prototype[method] = function patchedNestLoggerMethod(...args) {
|
|
147
|
+
const payload = createCapturedLogPayload(method, this, args);
|
|
148
|
+
const original = state.originals.loggerInstance[method];
|
|
149
|
+
let result;
|
|
150
|
+
state.suppressionDepth += 1;
|
|
151
|
+
try {
|
|
152
|
+
result = original.apply(this, args);
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
state.suppressionDepth -= 1;
|
|
156
|
+
}
|
|
157
|
+
notifyListeners(payload);
|
|
158
|
+
return result;
|
|
159
|
+
};
|
|
160
|
+
common_1.Logger[method] = function patchedNestLoggerStaticMethod(...args) {
|
|
161
|
+
const payload = createCapturedLogPayload(method, { context: '' }, args);
|
|
162
|
+
const original = state.originals.loggerStatic[method];
|
|
163
|
+
let result;
|
|
164
|
+
state.suppressionDepth += 1;
|
|
165
|
+
try {
|
|
166
|
+
result = original.apply(this, args);
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
state.suppressionDepth -= 1;
|
|
170
|
+
}
|
|
171
|
+
notifyListeners(payload);
|
|
172
|
+
return result;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
state.patched = true;
|
|
176
|
+
}
|
|
177
|
+
function restoreLoggerMethodsIfUnused() {
|
|
178
|
+
const state = getLoggerPatchState();
|
|
179
|
+
if (state.listeners.size > 0 || !state.patched) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
common_1.ConsoleLogger.prototype.log = state.originals.console.log;
|
|
183
|
+
common_1.ConsoleLogger.prototype.warn = state.originals.console.warn;
|
|
184
|
+
common_1.ConsoleLogger.prototype.error = state.originals.console.error;
|
|
185
|
+
common_1.ConsoleLogger.prototype.debug = state.originals.console.debug;
|
|
186
|
+
common_1.ConsoleLogger.prototype.verbose = state.originals.console.verbose;
|
|
187
|
+
common_1.Logger.prototype.log = state.originals.loggerInstance.log;
|
|
188
|
+
common_1.Logger.prototype.warn = state.originals.loggerInstance.warn;
|
|
189
|
+
common_1.Logger.prototype.error = state.originals.loggerInstance.error;
|
|
190
|
+
common_1.Logger.prototype.debug = state.originals.loggerInstance.debug;
|
|
191
|
+
common_1.Logger.prototype.verbose = state.originals.loggerInstance.verbose;
|
|
192
|
+
common_1.Logger.log = state.originals.loggerStatic.log;
|
|
193
|
+
common_1.Logger.warn = state.originals.loggerStatic.warn;
|
|
194
|
+
common_1.Logger.error = state.originals.loggerStatic.error;
|
|
195
|
+
common_1.Logger.debug = state.originals.loggerStatic.debug;
|
|
196
|
+
common_1.Logger.verbose = state.originals.loggerStatic.verbose;
|
|
197
|
+
state.patched = false;
|
|
198
|
+
state.suppressionDepth = 0;
|
|
199
|
+
}
|
|
200
|
+
function registerLoggerListener(listener) {
|
|
201
|
+
const state = getLoggerPatchState();
|
|
202
|
+
patchLoggerMethods();
|
|
203
|
+
state.listeners.add(listener);
|
|
204
|
+
return () => {
|
|
205
|
+
state.listeners.delete(listener);
|
|
206
|
+
restoreLoggerMethodsIfUnused();
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function resetLoggerPatchStateForTests() {
|
|
210
|
+
const state = getLoggerPatchState();
|
|
211
|
+
state.listeners.clear();
|
|
212
|
+
restoreLoggerMethodsIfUnused();
|
|
213
|
+
}
|
|
214
|
+
let DevtoolsLoggerCapture = class DevtoolsLoggerCapture {
|
|
215
|
+
constructor(store, realtimeServer) {
|
|
216
|
+
this.store = store;
|
|
217
|
+
this.realtimeServer = realtimeServer;
|
|
218
|
+
}
|
|
219
|
+
onModuleInit() {
|
|
220
|
+
if (this.unregister) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this.unregister = registerLoggerListener((payload) => {
|
|
224
|
+
const entry = {
|
|
225
|
+
id: (0, id_1.createEntryId)('log'),
|
|
226
|
+
timestamp: new Date().toISOString(),
|
|
227
|
+
level: payload.level,
|
|
228
|
+
context: payload.context,
|
|
229
|
+
message: payload.message,
|
|
230
|
+
};
|
|
231
|
+
this.store.addLog(entry);
|
|
232
|
+
this.realtimeServer.broadcastLog(entry);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
onModuleDestroy() {
|
|
236
|
+
this.unregister?.();
|
|
237
|
+
this.unregister = undefined;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
exports.DevtoolsLoggerCapture = DevtoolsLoggerCapture;
|
|
241
|
+
exports.DevtoolsLoggerCapture = DevtoolsLoggerCapture = __decorate([
|
|
242
|
+
(0, common_1.Injectable)(),
|
|
243
|
+
__metadata("design:paramtypes", [devtools_store_1.DevtoolsStore,
|
|
244
|
+
devtools_realtime_1.DevtoolsRealtimeServer])
|
|
245
|
+
], DevtoolsLoggerCapture);
|
|
246
|
+
//# sourceMappingURL=logger.capture.js.map
|