@viplance/nestjs-logger 0.4.0 → 0.4.2
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 +23 -3
- package/dist/defaults.js +1 -1
- package/dist/entities/log.entity.d.ts +2 -2
- package/dist/entities/log.entity.js +1 -1
- package/dist/guards/access.guard.d.ts +1 -1
- package/dist/guards/access.guard.js +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/interceptors/log.interceptor.d.ts +4 -4
- package/dist/log.module.d.ts +1 -1
- package/dist/log.module.js +7 -7
- package/dist/services/log.service.d.ts +8 -8
- package/dist/services/log.service.js +33 -29
- package/dist/services/log.service.js.map +1 -1
- package/dist/services/memory-db.service.d.ts +1 -1
- package/dist/services/memory-db.service.js +5 -5
- package/dist/services/ws.service.d.ts +3 -3
- package/dist/services/ws.service.js +14 -14
- package/dist/types/index.d.ts +3 -3
- package/dist/types/options.type.d.ts +1 -0
- package/dist/utils/entity2table.d.ts +1 -1
- package/dist/utils/entity2table.js +6 -6
- package/package.json +4 -1
- package/public/scripts/common.js +28 -28
- package/public/scripts/details-popup.js +10 -10
- package/public/scripts/json-viewer.js +4 -4
- package/src/defaults.ts +1 -1
- package/src/entities/log.entity.ts +3 -3
- package/src/guards/access.guard.ts +5 -5
- package/src/index.ts +4 -4
- package/src/interceptors/log.interceptor.ts +5 -5
- package/src/log.module.ts +18 -18
- package/src/services/log.service.ts +44 -40
- package/src/services/memory-db.service.ts +9 -9
- package/src/services/ws.d.ts +1 -1
- package/src/services/ws.service.ts +19 -19
- package/src/types/index.ts +3 -3
- package/src/types/log.type.ts +5 -5
- package/src/types/options.type.ts +1 -0
- package/src/utils/entity2table.ts +8 -8
- package/public/json.html +0 -0
package/README.md
CHANGED
|
@@ -67,16 +67,36 @@ Enable a WebSocket connection to receive the logs in real time.<br />
|
|
|
67
67
|
|
|
68
68
|
### Additional information
|
|
69
69
|
|
|
70
|
-
- `path`, `key` and `
|
|
71
|
-
- The
|
|
70
|
+
- `path`, `key`, `database` and `websocket` properties are optional.
|
|
71
|
+
- The log UI could be available at `your_application_url`/`path`?key=`key` or WebSocket port
|
|
72
72
|
- The log API could be available at `your_application_url`/`path`/api?key=`key`
|
|
73
73
|
- By default the logs will be stored in memory and deleted when the application stops.<br />
|
|
74
74
|
<br />
|
|
75
75
|
|
|
76
|
+
### The LogModule options:
|
|
77
|
+
- path?: string;
|
|
78
|
+
- key?: string; // access key
|
|
79
|
+
- join?: boolean; // merge the message duplicates
|
|
80
|
+
- maxRecords?: number; // max log records
|
|
81
|
+
- maxAge?: number; // in days
|
|
82
|
+
- maxSize?: number; // in megabytes
|
|
83
|
+
- database?: DataSourceOptions & {
|
|
84
|
+
host?: string;
|
|
85
|
+
port?: string;
|
|
86
|
+
table?: string;
|
|
87
|
+
collection?: string;
|
|
88
|
+
};
|
|
89
|
+
- websocket?: {
|
|
90
|
+
port?: number;
|
|
91
|
+
namespace?: string;
|
|
92
|
+
host?: string;
|
|
93
|
+
secure?: boolean;
|
|
94
|
+
};
|
|
95
|
+
|
|
76
96
|
### The LogService methods:
|
|
77
97
|
- log(message: string)
|
|
78
98
|
- error(message: string)
|
|
79
99
|
- warn(message: string)
|
|
80
100
|
- debug(message: string)
|
|
81
101
|
- verbose(message: string)
|
|
82
|
-
- addBreadcrumb(breadcrumb: any)
|
|
102
|
+
- addBreadcrumb(breadcrumb: any) - adds extra details to the logs for the current request
|
package/dist/defaults.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataSourceOptions, EntitySchema } from
|
|
2
|
-
export declare function createLogEntity(name: string, dbType: DataSourceOptions[
|
|
1
|
+
import { DataSourceOptions, EntitySchema } from 'typeorm';
|
|
2
|
+
export declare function createLogEntity(name: string, dbType: DataSourceOptions['type'] | 'memory'): EntitySchema<{
|
|
3
3
|
_id: unknown;
|
|
4
4
|
type: unknown;
|
|
5
5
|
message: unknown;
|
|
@@ -18,9 +18,9 @@ let LogAccessGuard = class LogAccessGuard {
|
|
|
18
18
|
const req = !!context.switchToHttp
|
|
19
19
|
? context.switchToHttp().getRequest()
|
|
20
20
|
: context; // hook for using as method
|
|
21
|
-
const params = node_querystring_1.default.parse(req.url.split(
|
|
21
|
+
const params = node_querystring_1.default.parse(req.url.split('?')[1]);
|
|
22
22
|
if (log_service_1.LogService.options.key && params.key !== log_service_1.LogService.options.key) {
|
|
23
|
-
throw new common_1.HttpException(
|
|
23
|
+
throw new common_1.HttpException('Unauthorized', 401);
|
|
24
24
|
}
|
|
25
25
|
return true;
|
|
26
26
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from './interceptors/log.interceptor';
|
|
2
|
+
export * from './log.module';
|
|
3
|
+
export * from './types/index';
|
|
4
|
+
export * from './services/log.service';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CallHandler, NestInterceptor } from
|
|
2
|
-
import { Observable } from
|
|
3
|
-
import { LogService } from
|
|
4
|
-
import { ExecutionContextHost } from
|
|
1
|
+
import type { CallHandler, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { LogService } from '../services/log.service';
|
|
4
|
+
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
|
|
5
5
|
export declare class LogInterceptor implements NestInterceptor {
|
|
6
6
|
private readonly logService;
|
|
7
7
|
constructor(logService: LogService);
|
package/dist/log.module.d.ts
CHANGED
package/dist/log.module.js
CHANGED
|
@@ -31,12 +31,12 @@ let LogModule = class LogModule {
|
|
|
31
31
|
}
|
|
32
32
|
app.useGlobalInterceptors(new log_interceptor_1.LogInterceptor(logService)); // intercept all errors
|
|
33
33
|
if (options === null || options === void 0 ? void 0 : options.path) {
|
|
34
|
-
app.useStaticAssets((0, node_path_1.join)(__dirname,
|
|
34
|
+
app.useStaticAssets((0, node_path_1.join)(__dirname, '..', 'public'), {
|
|
35
35
|
prefix: options.path,
|
|
36
36
|
});
|
|
37
37
|
const httpAdapter = app.getHttpAdapter();
|
|
38
38
|
// frontend settings endpoint
|
|
39
|
-
httpAdapter.get((0, node_path_1.join)(options.path,
|
|
39
|
+
httpAdapter.get((0, node_path_1.join)(options.path, 'settings'), async (req, res) => {
|
|
40
40
|
var _a, _b, _c, _d;
|
|
41
41
|
logAccessGuard.canActivate(req);
|
|
42
42
|
const result = {};
|
|
@@ -44,22 +44,22 @@ let LogModule = class LogModule {
|
|
|
44
44
|
result.websocket = {
|
|
45
45
|
namespace: (_a = options.websocket) === null || _a === void 0 ? void 0 : _a.namespace,
|
|
46
46
|
port: (_b = options.websocket) === null || _b === void 0 ? void 0 : _b.port,
|
|
47
|
-
host: ((_c = options.websocket) === null || _c === void 0 ? void 0 : _c.host) || ((_d = req.headers) === null || _d === void 0 ? void 0 : _d.host.split(
|
|
47
|
+
host: ((_c = options.websocket) === null || _c === void 0 ? void 0 : _c.host) || ((_d = req.headers) === null || _d === void 0 ? void 0 : _d.host.split(':')[0]),
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
res.json(result);
|
|
51
51
|
});
|
|
52
52
|
// get all logs endpoint
|
|
53
|
-
httpAdapter.get((0, node_path_1.join)(options.path,
|
|
53
|
+
httpAdapter.get((0, node_path_1.join)(options.path, 'api'), async (req, res) => {
|
|
54
54
|
logAccessGuard.canActivate(req);
|
|
55
55
|
res.json(await logService.getAll());
|
|
56
56
|
});
|
|
57
57
|
// delete log endpoint
|
|
58
|
-
httpAdapter.delete((0, node_path_1.join)(options.path,
|
|
58
|
+
httpAdapter.delete((0, node_path_1.join)(options.path, 'api'), async (req, res) => {
|
|
59
59
|
logAccessGuard.canActivate(req);
|
|
60
|
-
const params = node_querystring_1.default.parse(req.url.split(
|
|
60
|
+
const params = node_querystring_1.default.parse(req.url.split('?')[1]);
|
|
61
61
|
if (!params.id) {
|
|
62
|
-
throw new common_1.HttpException(
|
|
62
|
+
throw new common_1.HttpException('id is required', 400);
|
|
63
63
|
}
|
|
64
64
|
res.json(await logService.delete(params.id.toString()));
|
|
65
65
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { LoggerService, OnApplicationShutdown } from
|
|
2
|
-
import { MemoryDbService } from
|
|
3
|
-
import { LogModuleOptions } from
|
|
4
|
-
import { DataSource, EntitySchema } from
|
|
5
|
-
import { ExecutionContextHost } from
|
|
6
|
-
import { setInterval } from
|
|
7
|
-
import { WsService } from
|
|
8
|
-
import { Subscription } from
|
|
1
|
+
import { LoggerService, OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import { MemoryDbService } from './memory-db.service';
|
|
3
|
+
import { LogModuleOptions } from '../types';
|
|
4
|
+
import { DataSource, EntitySchema } from 'typeorm';
|
|
5
|
+
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
|
|
6
|
+
import { setInterval } from 'timers';
|
|
7
|
+
import { WsService } from './ws.service';
|
|
8
|
+
import { Subscription } from 'rxjs';
|
|
9
9
|
export declare class LogService implements LoggerService, OnApplicationShutdown {
|
|
10
10
|
private readonly memoryDbService;
|
|
11
11
|
private readonly wsService;
|
|
@@ -33,7 +33,7 @@ let LogService = LogService_1 = class LogService {
|
|
|
33
33
|
}
|
|
34
34
|
async connectDb(options) {
|
|
35
35
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
36
|
-
LogService_1.Log = (0, log_entity_1.createLogEntity)(((_a = options.database) === null || _a === void 0 ? void 0 : _a.collection) || ((_b = options.database) === null || _b === void 0 ? void 0 : _b.table) || defaults_1.defaultTable, ((_c = options.database) === null || _c === void 0 ? void 0 : _c.type) ||
|
|
36
|
+
LogService_1.Log = (0, log_entity_1.createLogEntity)(((_a = options.database) === null || _a === void 0 ? void 0 : _a.collection) || ((_b = options.database) === null || _b === void 0 ? void 0 : _b.table) || defaults_1.defaultTable, ((_c = options.database) === null || _c === void 0 ? void 0 : _c.type) || 'mongodb');
|
|
37
37
|
if (!LogService_1.options) {
|
|
38
38
|
this.setOptions(options);
|
|
39
39
|
}
|
|
@@ -46,7 +46,7 @@ let LogService = LogService_1 = class LogService {
|
|
|
46
46
|
};
|
|
47
47
|
LogService_1.connection = new typeorm_1.DataSource(dataSourceOptions);
|
|
48
48
|
await LogService_1.connection.initialize();
|
|
49
|
-
if (dataSourceOptions.type !==
|
|
49
|
+
if (dataSourceOptions.type !== 'mongodb') {
|
|
50
50
|
const queryRunner = LogService_1.connection.createQueryRunner();
|
|
51
51
|
try {
|
|
52
52
|
await queryRunner.connect();
|
|
@@ -68,13 +68,13 @@ let LogService = LogService_1 = class LogService {
|
|
|
68
68
|
if (options.websocket && !LogService_1.subscription) {
|
|
69
69
|
LogService_1.subscription = this.wsService.onMessage.subscribe(async (message) => {
|
|
70
70
|
switch (message.action) {
|
|
71
|
-
case
|
|
71
|
+
case 'getLogs':
|
|
72
72
|
this.wsService.sendMessage({
|
|
73
|
-
action:
|
|
73
|
+
action: 'list',
|
|
74
74
|
data: await this.getAll(),
|
|
75
75
|
});
|
|
76
76
|
break;
|
|
77
|
-
case
|
|
77
|
+
case 'delete':
|
|
78
78
|
this.delete(message.data._id);
|
|
79
79
|
break;
|
|
80
80
|
}
|
|
@@ -126,36 +126,40 @@ let LogService = LogService_1 = class LogService {
|
|
|
126
126
|
async getAll() {
|
|
127
127
|
return this.getConnection().find(LogService_1.Log, {
|
|
128
128
|
select: [
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
'_id',
|
|
130
|
+
'type',
|
|
131
|
+
'message',
|
|
132
|
+
'count',
|
|
133
|
+
'createdAt',
|
|
134
|
+
'updatedAt',
|
|
135
|
+
'context',
|
|
136
|
+
'trace',
|
|
137
|
+
'breadcrumbs',
|
|
138
138
|
],
|
|
139
|
-
order: { updatedAt:
|
|
139
|
+
order: { updatedAt: 'DESC' },
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
async delete(_id) {
|
|
143
143
|
this.wsService.sendMessage({
|
|
144
|
-
action:
|
|
144
|
+
action: 'delete',
|
|
145
145
|
data: { _id },
|
|
146
146
|
});
|
|
147
147
|
return this.getConnection().delete(LogService_1.Log, _id);
|
|
148
148
|
}
|
|
149
149
|
async smartInsert(data) {
|
|
150
|
+
var _a;
|
|
150
151
|
const currentDate = new Date();
|
|
151
152
|
const connection = this.getConnection();
|
|
152
153
|
// find the same log in DB
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
let log;
|
|
155
|
+
if ((_a = LogService_1.options) === null || _a === void 0 ? void 0 : _a.join) {
|
|
156
|
+
log = await connection.findOne(LogService_1.Log, {
|
|
157
|
+
where: {
|
|
158
|
+
type: data.type,
|
|
159
|
+
message: data.message,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
159
163
|
const context = data.context ? this.parseContext(data.context) : undefined;
|
|
160
164
|
if (log) {
|
|
161
165
|
const updatedLog = {
|
|
@@ -166,10 +170,10 @@ let LogService = LogService_1 = class LogService {
|
|
|
166
170
|
updatedAt: currentDate,
|
|
167
171
|
};
|
|
168
172
|
this.wsService.sendMessage({
|
|
169
|
-
action:
|
|
173
|
+
action: 'update',
|
|
170
174
|
data: { ...log, ...updatedLog },
|
|
171
175
|
});
|
|
172
|
-
await connection.update(LogService_1.Log, log[
|
|
176
|
+
await connection.update(LogService_1.Log, log['_id'], {
|
|
173
177
|
context,
|
|
174
178
|
trace: data.trace,
|
|
175
179
|
breadcrumbs: this.breadcrumbs,
|
|
@@ -191,7 +195,7 @@ let LogService = LogService_1 = class LogService {
|
|
|
191
195
|
const res = await connection.insert(LogService_1.Log, insertedLog);
|
|
192
196
|
const _id = this.getNewObjectId(res);
|
|
193
197
|
this.wsService.sendMessage({
|
|
194
|
-
action:
|
|
198
|
+
action: 'insert',
|
|
195
199
|
data: { _id, ...insertedLog },
|
|
196
200
|
});
|
|
197
201
|
return { _id, ...insertedLog };
|
|
@@ -237,9 +241,9 @@ let LogService = LogService_1 = class LogService {
|
|
|
237
241
|
var _a, _b;
|
|
238
242
|
if ((_a = LogService_1.options) === null || _a === void 0 ? void 0 : _a.maxSize) {
|
|
239
243
|
const latest = await this.getConnection().find(LogService_1.Log, {
|
|
240
|
-
order: { updatedAt:
|
|
244
|
+
order: { updatedAt: 'DESC' },
|
|
241
245
|
take: (_b = LogService_1.options) === null || _b === void 0 ? void 0 : _b.maxSize,
|
|
242
|
-
select: [
|
|
246
|
+
select: ['_id'],
|
|
243
247
|
});
|
|
244
248
|
const latestIds = latest.map((item) => item.id);
|
|
245
249
|
await LogService_1.connection
|
|
@@ -247,13 +251,13 @@ let LogService = LogService_1 = class LogService {
|
|
|
247
251
|
.createQueryBuilder()
|
|
248
252
|
.delete()
|
|
249
253
|
.from(LogService_1.Log)
|
|
250
|
-
.where(
|
|
254
|
+
.where('_id NOT IN (:...ids)', { ids: latestIds })
|
|
251
255
|
.execute();
|
|
252
256
|
}
|
|
253
257
|
}
|
|
254
258
|
};
|
|
255
259
|
exports.LogService = LogService;
|
|
256
|
-
LogService.Log = (0, log_entity_1.createLogEntity)(defaults_1.defaultTable,
|
|
260
|
+
LogService.Log = (0, log_entity_1.createLogEntity)(defaults_1.defaultTable, 'memory');
|
|
257
261
|
exports.LogService = LogService = LogService_1 = __decorate([
|
|
258
262
|
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
259
263
|
__metadata("design:paramtypes", [memory_db_service_1.MemoryDbService,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.service.js","sourceRoot":"","sources":["../../src/services/log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAKwB;AACxB,2DAAsD;AACtD,0CAA2C;AAC3C,oCAA8D;AAC9D,qCAKiB;AACjB,uDAAyD;AAEzD,mCAAq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;AAzSU,gCAAU;AAGd,cAAG,GAAiB,IAAA,4BAAe,EAAC,uBAAY,EAAE,QAAQ,CAAC,AAAxD,CAAyD;qBAHxD,UAAU;IADtB,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,SAAS,EAAE,CAAC;qCAWD,mCAAe;QACrB,sBAAS;GAX5B,UAAU,CA0StB"}
|
|
@@ -26,8 +26,8 @@ let MemoryDbService = class MemoryDbService {
|
|
|
26
26
|
insert(entity, data) {
|
|
27
27
|
const table = this.getTableName(entity);
|
|
28
28
|
// generate new random _id
|
|
29
|
-
const randomData = (0, crypto_1.randomBytes)(24).toString(
|
|
30
|
-
const _id = (0, crypto_1.createHash)(
|
|
29
|
+
const randomData = (0, crypto_1.randomBytes)(24).toString('hex');
|
|
30
|
+
const _id = (0, crypto_1.createHash)('sha256').update(randomData).digest('hex');
|
|
31
31
|
this.db[table].push({
|
|
32
32
|
...data,
|
|
33
33
|
_id, // unique index
|
|
@@ -37,7 +37,7 @@ let MemoryDbService = class MemoryDbService {
|
|
|
37
37
|
async update(entity, condition, data) {
|
|
38
38
|
const table = this.getTableName(entity);
|
|
39
39
|
let index = null;
|
|
40
|
-
if (typeof condition ===
|
|
40
|
+
if (typeof condition === 'string') {
|
|
41
41
|
index = this.findIndex(entity, { where: { _id: condition } });
|
|
42
42
|
}
|
|
43
43
|
if (condition === null || condition === void 0 ? void 0 : condition.where) {
|
|
@@ -94,8 +94,8 @@ let MemoryDbService = class MemoryDbService {
|
|
|
94
94
|
// handle null or non-object values
|
|
95
95
|
if (obj1 == null ||
|
|
96
96
|
obj2 == null ||
|
|
97
|
-
typeof obj1 !==
|
|
98
|
-
typeof obj2 !==
|
|
97
|
+
typeof obj1 !== 'object' ||
|
|
98
|
+
typeof obj2 !== 'object') {
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
101
|
// compare keys length
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LogModuleOptions } from
|
|
2
|
-
import { Subject } from
|
|
1
|
+
import { LogModuleOptions } from '../types';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
3
3
|
export declare class WsService {
|
|
4
4
|
onMessage: Subject<any>;
|
|
5
5
|
private ws;
|
|
@@ -7,7 +7,7 @@ export declare class WsService {
|
|
|
7
7
|
private connectionTimeout;
|
|
8
8
|
private options;
|
|
9
9
|
private key;
|
|
10
|
-
setupConnection(options: LogModuleOptions[
|
|
10
|
+
setupConnection(options: LogModuleOptions['websocket'], key?: string): void;
|
|
11
11
|
sendMessage(message: any): void;
|
|
12
12
|
private handleError;
|
|
13
13
|
private closeConnection;
|
|
@@ -18,9 +18,9 @@ let WsService = class WsService {
|
|
|
18
18
|
this.connectionTimeout = 500;
|
|
19
19
|
this.options = {
|
|
20
20
|
port: 8080,
|
|
21
|
-
host:
|
|
21
|
+
host: 'localhost',
|
|
22
22
|
};
|
|
23
|
-
this.key =
|
|
23
|
+
this.key = '';
|
|
24
24
|
this.handleError = () => {
|
|
25
25
|
const serverUrl = this.getServerUrl();
|
|
26
26
|
console.error(`Server ${serverUrl} is not available.`);
|
|
@@ -29,13 +29,13 @@ let WsService = class WsService {
|
|
|
29
29
|
this.closeConnection = (connection) => {
|
|
30
30
|
clearTimeout(connection.pingTimeout);
|
|
31
31
|
if (this.connected) {
|
|
32
|
-
console.log(
|
|
32
|
+
console.log('Connection has been closed by server.');
|
|
33
33
|
this.connected = false;
|
|
34
34
|
this.handleError();
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
this.ping = (connection) => {
|
|
38
|
-
console.log(
|
|
38
|
+
console.log('Ping remote server.');
|
|
39
39
|
clearTimeout(connection.pingTimeout);
|
|
40
40
|
connection.pingTimeout = setTimeout(() => {
|
|
41
41
|
connection.terminate();
|
|
@@ -44,8 +44,8 @@ let WsService = class WsService {
|
|
|
44
44
|
this.handleMessage = (message) => {
|
|
45
45
|
try {
|
|
46
46
|
const data = JSON.parse((message.data || message).toString());
|
|
47
|
-
if (this.key !==
|
|
48
|
-
throw new Error(
|
|
47
|
+
if (this.key !== '' && data.key !== this.key) {
|
|
48
|
+
throw new Error('WebSocket unauthorized');
|
|
49
49
|
}
|
|
50
50
|
if (this.options)
|
|
51
51
|
if (data.action) {
|
|
@@ -58,7 +58,7 @@ let WsService = class WsService {
|
|
|
58
58
|
};
|
|
59
59
|
this.getServerUrl = () => {
|
|
60
60
|
var _a, _b, _c;
|
|
61
|
-
return `${((_a = this.options) === null || _a === void 0 ? void 0 : _a.secure) ?
|
|
61
|
+
return `${((_a = this.options) === null || _a === void 0 ? void 0 : _a.secure) ? 'wss' : 'ws'}://${(_b = this.options) === null || _b === void 0 ? void 0 : _b.host}:${(_c = this.options) === null || _c === void 0 ? void 0 : _c.port}`;
|
|
62
62
|
};
|
|
63
63
|
this.handleOpenConnection = async () => {
|
|
64
64
|
this.connected = true;
|
|
@@ -66,7 +66,7 @@ let WsService = class WsService {
|
|
|
66
66
|
console.log(`${serverUrl} has been connected.`);
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
-
setupConnection(options, key =
|
|
69
|
+
setupConnection(options, key = '') {
|
|
70
70
|
var _a;
|
|
71
71
|
this.options = {
|
|
72
72
|
...this.options,
|
|
@@ -84,12 +84,12 @@ let WsService = class WsService {
|
|
|
84
84
|
port: (_a = this.options) === null || _a === void 0 ? void 0 : _a.port,
|
|
85
85
|
});
|
|
86
86
|
console.log(`Logs WebSocket server is listening on port ${this.options.port}`);
|
|
87
|
-
wsServer.on(
|
|
88
|
-
wsServer.on(
|
|
89
|
-
wsServer.on(
|
|
90
|
-
wsServer.on(
|
|
91
|
-
wsServer.on(
|
|
92
|
-
wsServer.on(
|
|
87
|
+
wsServer.on('error', this.handleError);
|
|
88
|
+
wsServer.on('open', () => this.handleOpenConnection());
|
|
89
|
+
wsServer.on('ping', () => this.ping(this.ws));
|
|
90
|
+
wsServer.on('close', () => this.closeConnection(this.ws));
|
|
91
|
+
wsServer.on('message', this.handleMessage);
|
|
92
|
+
wsServer.on('connection', (connection) => {
|
|
93
93
|
this.ws = connection;
|
|
94
94
|
connection.onmessage = this.handleMessage;
|
|
95
95
|
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from './context.type';
|
|
2
|
+
export * from './log.type';
|
|
3
|
+
export * from './options.type';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EntitySchema, Table } from
|
|
1
|
+
import { EntitySchema, Table } from 'typeorm';
|
|
2
2
|
export declare function entity2table(entity: EntitySchema): Table;
|
|
@@ -11,7 +11,7 @@ function entity2table(entity) {
|
|
|
11
11
|
type: resolveColumnType(col === null || col === void 0 ? void 0 : col.type),
|
|
12
12
|
isPrimary: !!(col === null || col === void 0 ? void 0 : col.primary),
|
|
13
13
|
isGenerated: !!(col === null || col === void 0 ? void 0 : col.generated),
|
|
14
|
-
generationStrategy: (col === null || col === void 0 ? void 0 : col.generated) ?
|
|
14
|
+
generationStrategy: (col === null || col === void 0 ? void 0 : col.generated) ? 'increment' : undefined,
|
|
15
15
|
isUnique: !!(col === null || col === void 0 ? void 0 : col.unique),
|
|
16
16
|
isNullable: !!(col === null || col === void 0 ? void 0 : col.nullable),
|
|
17
17
|
default: col === null || col === void 0 ? void 0 : col.default,
|
|
@@ -21,15 +21,15 @@ function entity2table(entity) {
|
|
|
21
21
|
function resolveColumnType(type) {
|
|
22
22
|
switch (type) {
|
|
23
23
|
case String:
|
|
24
|
-
return
|
|
24
|
+
return 'text';
|
|
25
25
|
case Number:
|
|
26
|
-
return
|
|
26
|
+
return 'int';
|
|
27
27
|
case Date:
|
|
28
|
-
return
|
|
28
|
+
return 'timestamp';
|
|
29
29
|
case Boolean:
|
|
30
|
-
return
|
|
30
|
+
return 'boolean';
|
|
31
31
|
default:
|
|
32
|
-
return
|
|
32
|
+
return 'text';
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
//# sourceMappingURL=entity2table.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viplance/nestjs-logger",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "NestJS internal logging system",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"mariadb",
|
|
22
22
|
"sqlite",
|
|
23
23
|
"memory",
|
|
24
|
+
"websocket",
|
|
25
|
+
"realtime",
|
|
26
|
+
"UI",
|
|
24
27
|
"free"
|
|
25
28
|
],
|
|
26
29
|
"author": "Dzmitry Sharko",
|