@nestjs/websockets 8.3.1 → 8.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 +1 -1
- package/adapters/ws-adapter.js +1 -1
- package/context/exception-filters-context.js +1 -1
- package/context/ws-context-creator.js +1 -1
- package/context/ws-proxy.js +2 -2
- package/decorators/connected-socket.decorator.js +1 -1
- package/decorators/message-body.decorator.js +1 -1
- package/errors/ws-exception.js +3 -3
- package/exceptions/base-ws-exception-filter.js +2 -2
- package/exceptions/ws-exceptions-handler.js +1 -1
- package/gateway-metadata-explorer.js +3 -3
- package/interfaces/gateway-metadata.interface.d.ts +5 -5
- package/package.json +4 -4
- package/socket-module.js +4 -5
- package/socket-server-provider.js +2 -2
- package/utils/param.utils.js +3 -3
- package/web-sockets-controller.js +8 -8
- package/CHANGELOG.md +0 -12
package/Readme.md
CHANGED
|
@@ -54,7 +54,7 @@ With official support, you can get expert help straight from Nest core team. We
|
|
|
54
54
|
|
|
55
55
|
## Support
|
|
56
56
|
|
|
57
|
-
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support
|
|
57
|
+
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support from the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
|
58
58
|
|
|
59
59
|
#### Principal Sponsors
|
|
60
60
|
<table style="text-align:center;"><tr>
|
package/adapters/ws-adapter.js
CHANGED
|
@@ -20,7 +20,7 @@ class AbstractWsAdapter {
|
|
|
20
20
|
client.on(constants_1.DISCONNECT_EVENT, callback);
|
|
21
21
|
}
|
|
22
22
|
async close(server) {
|
|
23
|
-
const isCallable = server && shared_utils_1.isFunction(server.close);
|
|
23
|
+
const isCallable = server && (0, shared_utils_1.isFunction)(server.close);
|
|
24
24
|
isCallable && (await new Promise(resolve => server.close(resolve)));
|
|
25
25
|
}
|
|
26
26
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
@@ -13,7 +13,7 @@ class ExceptionFiltersContext extends base_exception_filter_context_1.BaseExcept
|
|
|
13
13
|
this.moduleContext = moduleKey;
|
|
14
14
|
const exceptionHandler = new ws_exceptions_handler_1.WsExceptionsHandler();
|
|
15
15
|
const filters = this.createContext(instance, callback, constants_1.EXCEPTION_FILTERS_METADATA);
|
|
16
|
-
if (shared_utils_1.isEmpty(filters)) {
|
|
16
|
+
if ((0, shared_utils_1.isEmpty)(filters)) {
|
|
17
17
|
return exceptionHandler;
|
|
18
18
|
}
|
|
19
19
|
exceptionHandler.setCustomFilters(filters.reverse());
|
|
@@ -109,7 +109,7 @@ class WsContextCreator {
|
|
|
109
109
|
return paramsOptions.length ? pipesFn : null;
|
|
110
110
|
}
|
|
111
111
|
async getParamValue(value, { metatype, type, data }, pipes) {
|
|
112
|
-
return shared_utils_1.isEmpty(pipes)
|
|
112
|
+
return (0, shared_utils_1.isEmpty)(pipes)
|
|
113
113
|
? value
|
|
114
114
|
: this.pipesConsumer.apply(value, { metatype, type, data }, pipes);
|
|
115
115
|
}
|
package/context/ws-proxy.js
CHANGED
|
@@ -9,9 +9,9 @@ class WsProxy {
|
|
|
9
9
|
return async (...args) => {
|
|
10
10
|
try {
|
|
11
11
|
const result = await targetCallback(...args);
|
|
12
|
-
return !rxjs_1.isObservable(result)
|
|
12
|
+
return !(0, rxjs_1.isObservable)(result)
|
|
13
13
|
? result
|
|
14
|
-
: result.pipe(operators_1.catchError(error => {
|
|
14
|
+
: result.pipe((0, operators_1.catchError)(error => {
|
|
15
15
|
this.handleError(exceptionsHandler, args, error);
|
|
16
16
|
return rxjs_1.EMPTY;
|
|
17
17
|
}));
|
|
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ConnectedSocket = void 0;
|
|
4
4
|
const ws_paramtype_enum_1 = require("../enums/ws-paramtype.enum");
|
|
5
5
|
const param_utils_1 = require("../utils/param.utils");
|
|
6
|
-
exports.ConnectedSocket = param_utils_1.createWsParamDecorator(ws_paramtype_enum_1.WsParamtype.SOCKET);
|
|
6
|
+
exports.ConnectedSocket = (0, param_utils_1.createWsParamDecorator)(ws_paramtype_enum_1.WsParamtype.SOCKET);
|
|
@@ -4,6 +4,6 @@ exports.MessageBody = void 0;
|
|
|
4
4
|
const ws_paramtype_enum_1 = require("../enums/ws-paramtype.enum");
|
|
5
5
|
const param_utils_1 = require("../utils/param.utils");
|
|
6
6
|
function MessageBody(propertyOrPipe, ...pipes) {
|
|
7
|
-
return param_utils_1.createPipesWsParamDecorator(ws_paramtype_enum_1.WsParamtype.PAYLOAD)(propertyOrPipe, ...pipes);
|
|
7
|
+
return (0, param_utils_1.createPipesWsParamDecorator)(ws_paramtype_enum_1.WsParamtype.PAYLOAD)(propertyOrPipe, ...pipes);
|
|
8
8
|
}
|
|
9
9
|
exports.MessageBody = MessageBody;
|
package/errors/ws-exception.js
CHANGED
|
@@ -9,11 +9,11 @@ class WsException extends Error {
|
|
|
9
9
|
this.initMessage();
|
|
10
10
|
}
|
|
11
11
|
initMessage() {
|
|
12
|
-
if (shared_utils_1.isString(this.error)) {
|
|
12
|
+
if ((0, shared_utils_1.isString)(this.error)) {
|
|
13
13
|
this.message = this.error;
|
|
14
14
|
}
|
|
15
|
-
else if (shared_utils_1.isObject(this.error) &&
|
|
16
|
-
shared_utils_1.isString(this.error.message)) {
|
|
15
|
+
else if ((0, shared_utils_1.isObject)(this.error) &&
|
|
16
|
+
(0, shared_utils_1.isString)(this.error.message)) {
|
|
17
17
|
this.message = this.error.message;
|
|
18
18
|
}
|
|
19
19
|
else if (this.constructor) {
|
|
@@ -16,7 +16,7 @@ class BaseWsExceptionFilter {
|
|
|
16
16
|
}
|
|
17
17
|
const status = 'error';
|
|
18
18
|
const result = exception.getError();
|
|
19
|
-
const message = shared_utils_1.isObject(result)
|
|
19
|
+
const message = (0, shared_utils_1.isObject)(result)
|
|
20
20
|
? result
|
|
21
21
|
: {
|
|
22
22
|
status,
|
|
@@ -36,7 +36,7 @@ class BaseWsExceptionFilter {
|
|
|
36
36
|
return BaseWsExceptionFilter.logger.error(exception);
|
|
37
37
|
}
|
|
38
38
|
isExceptionObject(err) {
|
|
39
|
-
return shared_utils_1.isObject(err) && !!err.message;
|
|
39
|
+
return (0, shared_utils_1.isObject)(err) && !!err.message;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
exports.BaseWsExceptionFilter = BaseWsExceptionFilter;
|
|
@@ -23,7 +23,7 @@ class WsExceptionsHandler extends base_ws_exception_filter_1.BaseWsExceptionFilt
|
|
|
23
23
|
this.filters = filters;
|
|
24
24
|
}
|
|
25
25
|
invokeCustomFilters(exception, args) {
|
|
26
|
-
if (shared_utils_1.isEmpty(this.filters))
|
|
26
|
+
if ((0, shared_utils_1.isEmpty)(this.filters))
|
|
27
27
|
return false;
|
|
28
28
|
const filter = this.filters.find(({ exceptionMetatypes }) => {
|
|
29
29
|
const hasMetatype = !exceptionMetatypes.length ||
|
|
@@ -14,7 +14,7 @@ class GatewayMetadataExplorer {
|
|
|
14
14
|
exploreMethodMetadata(instancePrototype, methodName) {
|
|
15
15
|
const callback = instancePrototype[methodName];
|
|
16
16
|
const isMessageMapping = Reflect.getMetadata(constants_1.MESSAGE_MAPPING_METADATA, callback);
|
|
17
|
-
if (shared_utils_1.isUndefined(isMessageMapping)) {
|
|
17
|
+
if ((0, shared_utils_1.isUndefined)(isMessageMapping)) {
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
const message = Reflect.getMetadata(constants_1.MESSAGE_METADATA, callback);
|
|
@@ -26,12 +26,12 @@ class GatewayMetadataExplorer {
|
|
|
26
26
|
}
|
|
27
27
|
*scanForServerHooks(instance) {
|
|
28
28
|
for (const propertyKey in instance) {
|
|
29
|
-
if (shared_utils_1.isFunction(propertyKey)) {
|
|
29
|
+
if ((0, shared_utils_1.isFunction)(propertyKey)) {
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
32
|
const property = String(propertyKey);
|
|
33
33
|
const isServer = Reflect.getMetadata(constants_1.GATEWAY_SERVER_METADATA, instance, property);
|
|
34
|
-
if (!shared_utils_1.isUndefined(isServer)) {
|
|
34
|
+
if (!(0, shared_utils_1.isUndefined)(isServer)) {
|
|
35
35
|
yield property;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -29,22 +29,22 @@ export interface GatewayMetadata {
|
|
|
29
29
|
parser?: any;
|
|
30
30
|
/**
|
|
31
31
|
* How many ms before a client without namespace is closed
|
|
32
|
-
* @default
|
|
32
|
+
* @default 45_000
|
|
33
33
|
*/
|
|
34
34
|
connectTimeout?: number;
|
|
35
35
|
/**
|
|
36
36
|
* How many ms without a pong packet to consider the connection closed
|
|
37
|
-
* @default
|
|
37
|
+
* @default 20_000
|
|
38
38
|
*/
|
|
39
39
|
pingTimeout?: number;
|
|
40
40
|
/**
|
|
41
41
|
* How many ms before sending a new ping packet
|
|
42
|
-
* @default
|
|
42
|
+
* @default 25_000
|
|
43
43
|
*/
|
|
44
44
|
pingInterval?: number;
|
|
45
45
|
/**
|
|
46
46
|
* How many ms before an uncompleted transport upgrade is cancelled
|
|
47
|
-
* @default
|
|
47
|
+
* @default 10_000
|
|
48
48
|
*/
|
|
49
49
|
upgradeTimeout?: number;
|
|
50
50
|
/**
|
|
@@ -111,7 +111,7 @@ export interface GatewayMetadata {
|
|
|
111
111
|
destroyUpgrade?: boolean;
|
|
112
112
|
/**
|
|
113
113
|
* Milliseconds after which unhandled requests are ended
|
|
114
|
-
* @default
|
|
114
|
+
* @default 1_000
|
|
115
115
|
*/
|
|
116
116
|
destroyUpgradeTimeout?: number;
|
|
117
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/websockets",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.2",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@websockets)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"iterare": "1.2.1",
|
|
16
|
-
"object-hash": "
|
|
16
|
+
"object-hash": "3.0.0",
|
|
17
17
|
"tslib": "2.3.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@nestjs/common": "8.
|
|
21
|
-
"@nestjs/core": "8.
|
|
20
|
+
"@nestjs/common": "8.4.2",
|
|
21
|
+
"@nestjs/core": "8.4.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@nestjs/common": "^8.0.0",
|
package/socket-module.js
CHANGED
|
@@ -30,7 +30,7 @@ class SocketModule {
|
|
|
30
30
|
modules.forEach(({ providers }, moduleName) => this.connectAllGateways(providers, moduleName));
|
|
31
31
|
}
|
|
32
32
|
connectAllGateways(providers, moduleName) {
|
|
33
|
-
iterare_1.iterate(providers.values())
|
|
33
|
+
(0, iterare_1.iterate)(providers.values())
|
|
34
34
|
.filter(wrapper => wrapper && !wrapper.isNotMetatype)
|
|
35
35
|
.forEach(wrapper => this.connectGatewayToServer(wrapper, moduleName));
|
|
36
36
|
}
|
|
@@ -46,7 +46,6 @@ class SocketModule {
|
|
|
46
46
|
this.webSocketsController.connectGatewayToServer(instance, metatype, moduleName);
|
|
47
47
|
}
|
|
48
48
|
async close() {
|
|
49
|
-
var _a;
|
|
50
49
|
if (!this.applicationConfig) {
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
@@ -55,10 +54,10 @@ class SocketModule {
|
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
const servers = this.socketsContainer.getAll();
|
|
58
|
-
await Promise.all(iterare_1.iterate(servers.values())
|
|
57
|
+
await Promise.all((0, iterare_1.iterate)(servers.values())
|
|
59
58
|
.filter(({ server }) => server)
|
|
60
59
|
.map(async ({ server }) => adapter.close(server)));
|
|
61
|
-
await (
|
|
60
|
+
await (adapter === null || adapter === void 0 ? void 0 : adapter.dispose());
|
|
62
61
|
this.socketsContainer.clear();
|
|
63
62
|
}
|
|
64
63
|
initializeAdapter() {
|
|
@@ -67,7 +66,7 @@ class SocketModule {
|
|
|
67
66
|
this.isAdapterInitialized = true;
|
|
68
67
|
return;
|
|
69
68
|
}
|
|
70
|
-
const { IoAdapter } = load_adapter_1.loadAdapter('@nestjs/platform-socket.io', 'WebSockets', () => require('@nestjs/platform-socket.io'));
|
|
69
|
+
const { IoAdapter } = (0, load_adapter_1.loadAdapter)('@nestjs/platform-socket.io', 'WebSockets', () => require('@nestjs/platform-socket.io'));
|
|
71
70
|
const ioAdapter = new IoAdapter(this.httpServer);
|
|
72
71
|
this.applicationConfig.setIoAdapter(ioAdapter);
|
|
73
72
|
this.isAdapterInitialized = true;
|
|
@@ -43,10 +43,10 @@ class SocketServerProvider {
|
|
|
43
43
|
return adapter.create(port, Object.assign(Object.assign({}, options), { namespace: this.validateNamespace(options.namespace || ''), server }));
|
|
44
44
|
}
|
|
45
45
|
validateNamespace(namespace) {
|
|
46
|
-
if (!shared_utils_1.isString(namespace)) {
|
|
46
|
+
if (!(0, shared_utils_1.isString)(namespace)) {
|
|
47
47
|
return namespace;
|
|
48
48
|
}
|
|
49
|
-
return shared_utils_1.addLeadingSlash(namespace);
|
|
49
|
+
return (0, shared_utils_1.addLeadingSlash)(namespace);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
exports.SocketServerProvider = SocketServerProvider;
|
package/utils/param.utils.js
CHANGED
|
@@ -8,15 +8,15 @@ const constants_1 = require("../constants");
|
|
|
8
8
|
function createWsParamDecorator(paramtype) {
|
|
9
9
|
return (...pipes) => (target, key, index) => {
|
|
10
10
|
const args = Reflect.getMetadata(constants_1.PARAM_ARGS_METADATA, target.constructor, key) || {};
|
|
11
|
-
Reflect.defineMetadata(constants_1.PARAM_ARGS_METADATA, route_params_decorator_1.assignMetadata(args, paramtype, index, undefined, ...pipes), target.constructor, key);
|
|
11
|
+
Reflect.defineMetadata(constants_1.PARAM_ARGS_METADATA, (0, route_params_decorator_1.assignMetadata)(args, paramtype, index, undefined, ...pipes), target.constructor, key);
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
exports.createWsParamDecorator = createWsParamDecorator;
|
|
15
15
|
const createPipesWsParamDecorator = (paramtype) => (data, ...pipes) => (target, key, index) => {
|
|
16
16
|
const args = Reflect.getMetadata(constants_1.PARAM_ARGS_METADATA, target.constructor, key) || {};
|
|
17
|
-
const hasParamData = shared_utils_1.isNil(data) || shared_utils_1.isString(data);
|
|
17
|
+
const hasParamData = (0, shared_utils_1.isNil)(data) || (0, shared_utils_1.isString)(data);
|
|
18
18
|
const paramData = hasParamData ? data : undefined;
|
|
19
19
|
const paramPipes = hasParamData ? pipes : [data, ...pipes];
|
|
20
|
-
Reflect.defineMetadata(constants_1.PARAM_ARGS_METADATA, route_params_decorator_1.assignMetadata(args, paramtype, index, paramData, ...paramPipes), target.constructor, key);
|
|
20
|
+
Reflect.defineMetadata(constants_1.PARAM_ARGS_METADATA, (0, route_params_decorator_1.assignMetadata)(args, paramtype, index, paramData, ...paramPipes), target.constructor, key);
|
|
21
21
|
};
|
|
22
22
|
exports.createPipesWsParamDecorator = createPipesWsParamDecorator;
|
|
@@ -68,14 +68,14 @@ class WebSocketsController {
|
|
|
68
68
|
subscribeConnectionEvent(instance, event) {
|
|
69
69
|
if (instance.handleConnection) {
|
|
70
70
|
event
|
|
71
|
-
.pipe(operators_1.distinctUntilChanged((prev, curr) => compare_element_util_1.compareElementAt(prev, curr, 0)))
|
|
71
|
+
.pipe((0, operators_1.distinctUntilChanged)((prev, curr) => (0, compare_element_util_1.compareElementAt)(prev, curr, 0)))
|
|
72
72
|
.subscribe((args) => instance.handleConnection(...args));
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
subscribeDisconnectEvent(instance, event) {
|
|
76
76
|
if (instance.handleDisconnect) {
|
|
77
77
|
event
|
|
78
|
-
.pipe(operators_1.distinctUntilChanged())
|
|
78
|
+
.pipe((0, operators_1.distinctUntilChanged)())
|
|
79
79
|
.subscribe(instance.handleDisconnect.bind(instance));
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -85,17 +85,17 @@ class WebSocketsController {
|
|
|
85
85
|
message,
|
|
86
86
|
callback: callback.bind(instance, client),
|
|
87
87
|
}));
|
|
88
|
-
adapter.bindMessageHandlers(client, handlers, data => rxjs_1.from(this.pickResult(data)).pipe(operators_1.mergeAll()));
|
|
88
|
+
adapter.bindMessageHandlers(client, handlers, data => (0, rxjs_1.from)(this.pickResult(data)).pipe((0, operators_1.mergeAll)()));
|
|
89
89
|
}
|
|
90
90
|
async pickResult(deferredResult) {
|
|
91
91
|
const result = await deferredResult;
|
|
92
|
-
if (result && shared_utils_1.isFunction(result.subscribe)) {
|
|
92
|
+
if (result && (0, shared_utils_1.isFunction)(result.subscribe)) {
|
|
93
93
|
return result;
|
|
94
94
|
}
|
|
95
95
|
if (result instanceof Promise) {
|
|
96
|
-
return rxjs_1.from(result);
|
|
96
|
+
return (0, rxjs_1.from)(result);
|
|
97
97
|
}
|
|
98
|
-
return rxjs_1.of(result);
|
|
98
|
+
return (0, rxjs_1.of)(result);
|
|
99
99
|
}
|
|
100
100
|
assignServerToProperties(instance, server) {
|
|
101
101
|
for (const propertyKey of this.metadataExplorer.scanForServerHooks(instance)) {
|
|
@@ -103,8 +103,8 @@ class WebSocketsController {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
printSubscriptionLogs(instance, subscribersMap) {
|
|
106
|
-
var _a
|
|
107
|
-
const gatewayClassName = (
|
|
106
|
+
var _a;
|
|
107
|
+
const gatewayClassName = (_a = instance === null || instance === void 0 ? void 0 : instance.constructor) === null || _a === void 0 ? void 0 : _a.name;
|
|
108
108
|
if (!gatewayClassName) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
<a name="8.2.0"></a>
|
|
7
|
-
# [8.2.0](https://github.com/nestjs/nest/compare/v8.1.2...v8.2.0) (2021-11-08)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
**Note:** Version bump only for package @nestjs/websockets
|