@venok/websocket 2.1.0-next.1
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.js +32 -0
- package/dist/decorators/gateway.decorator.js +40 -0
- package/dist/decorators/message-body.decorator.js +32 -0
- package/dist/decorators/server.decorator.js +27 -0
- package/dist/decorators/socket.decorator.js +23 -0
- package/dist/decorators/subscribe-message.decorator.js +23 -0
- package/dist/enums/ws-paramtype.js +27 -0
- package/dist/errors/ack-not-supported.exception.js +27 -0
- package/dist/errors/invalid-socket-port.exception.js +27 -0
- package/dist/exceptions/ws.exception.js +42 -0
- package/dist/filters/context.js +28 -0
- package/dist/filters/filter.js +72 -0
- package/dist/helpers/discovery.helper.js +51 -0
- package/dist/helpers/event-stream-factory.helper.js +31 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +18 -0
- package/dist/interfaces/event-stream-host.interface.js +0 -0
- package/dist/interfaces/index.js +4 -0
- package/dist/interfaces/options.interface.js +0 -0
- package/dist/interfaces/websocket/gateway-handler-metadata.interfcae.js +0 -0
- package/dist/interfaces/websocket/gateway-metadata.interface.js +0 -0
- package/dist/interfaces/websocket/gateway-options.interface.js +0 -0
- package/dist/interfaces/websocket/index.js +4 -0
- package/dist/symbols.js +31 -0
- package/dist/websocket/adapter.js +31 -0
- package/dist/websocket/arguments-host.js +39 -0
- package/dist/websocket/config.js +43 -0
- package/dist/websocket/configurable-module.js +26 -0
- package/dist/websocket/container.js +42 -0
- package/dist/websocket/context.js +43 -0
- package/dist/websocket/explorer.js +118 -0
- package/dist/websocket/finder.js +57 -0
- package/dist/websocket/module.js +34 -0
- package/dist/websocket/params-factory.js +41 -0
- package/dist/websocket/starter-module.js +100 -0
- package/package.json +49 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/constants.ts
|
|
18
|
+
import { ROUTE_ARGS_METADATA } from "@venok/core";
|
|
19
|
+
var MESSAGE_METADATA = "message";
|
|
20
|
+
var GATEWAY_SERVER_METADATA = "websockets:is_socket";
|
|
21
|
+
var GATEWAY_METADATA = "websockets:is_gateway";
|
|
22
|
+
var PORT_METADATA = "port";
|
|
23
|
+
var GATEWAY_OPTIONS = "websockets:gateway_options";
|
|
24
|
+
var PARAM_ARGS_METADATA = ROUTE_ARGS_METADATA;
|
|
25
|
+
export {
|
|
26
|
+
PORT_METADATA,
|
|
27
|
+
PARAM_ARGS_METADATA,
|
|
28
|
+
MESSAGE_METADATA,
|
|
29
|
+
GATEWAY_SERVER_METADATA,
|
|
30
|
+
GATEWAY_OPTIONS,
|
|
31
|
+
GATEWAY_METADATA
|
|
32
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/decorators/gateway.decorator.ts
|
|
18
|
+
import { Reflector } from "@venok/core";
|
|
19
|
+
import { WebsocketGatewayDiscovery } from "../helpers/discovery.helper.js";
|
|
20
|
+
import { GATEWAY_METADATA, GATEWAY_OPTIONS, PORT_METADATA } from "../constants.js";
|
|
21
|
+
var internalGateway = Reflector.createDecorator({
|
|
22
|
+
type: "class",
|
|
23
|
+
key: GATEWAY_METADATA,
|
|
24
|
+
transform: (options) => {
|
|
25
|
+
return new WebsocketGatewayDiscovery(options);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
function WebSocketGateway(portOrOptions, options) {
|
|
29
|
+
const isPortInt = Number.isInteger(portOrOptions);
|
|
30
|
+
const port = isPortInt ? portOrOptions : 0;
|
|
31
|
+
const gatewayOptions = isPortInt ? options || {} : portOrOptions || {};
|
|
32
|
+
return internalGateway({
|
|
33
|
+
[PORT_METADATA]: port,
|
|
34
|
+
[GATEWAY_OPTIONS]: gatewayOptions
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
WebSocketGateway["KEY"] = internalGateway.KEY;
|
|
38
|
+
export {
|
|
39
|
+
WebSocketGateway
|
|
40
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/decorators/message-body.decorator.ts
|
|
18
|
+
import { createNativeParamDecorator, isFunction, isNumber, isString } from "@venok/core";
|
|
19
|
+
import { WsParamtype } from "../enums/ws-paramtype.js";
|
|
20
|
+
var isPipe = (pipe) => {
|
|
21
|
+
return pipe && (isFunction(pipe) && pipe.prototype && isFunction(pipe.prototype.transform) || isFunction(pipe.transform));
|
|
22
|
+
};
|
|
23
|
+
function MessageBody(propertyOrPipe, ...pipes) {
|
|
24
|
+
if (!isPipe(propertyOrPipe)) {
|
|
25
|
+
if (!isString(propertyOrPipe) && !isNumber(propertyOrPipe))
|
|
26
|
+
return createNativeParamDecorator(WsParamtype.PAYLOAD)(undefined, ...pipes);
|
|
27
|
+
}
|
|
28
|
+
return createNativeParamDecorator(WsParamtype.PAYLOAD)(propertyOrPipe, ...pipes);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
MessageBody
|
|
32
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/decorators/server.decorator.ts
|
|
18
|
+
import { GATEWAY_SERVER_METADATA } from "../constants.js";
|
|
19
|
+
var WebsocketServer = () => {
|
|
20
|
+
return (target, propertyKey) => {
|
|
21
|
+
Reflect.set(target, propertyKey, null);
|
|
22
|
+
Reflect.defineMetadata(GATEWAY_SERVER_METADATA, true, target, propertyKey);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
WebsocketServer
|
|
27
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/decorators/socket.decorator.ts
|
|
18
|
+
import { createNativeParamDecoratorWithoutPipes } from "@venok/core";
|
|
19
|
+
import { WsParamtype } from "../enums/ws-paramtype.js";
|
|
20
|
+
var Socket = createNativeParamDecoratorWithoutPipes(WsParamtype.SOCKET);
|
|
21
|
+
export {
|
|
22
|
+
Socket
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/decorators/subscribe-message.decorator.ts
|
|
18
|
+
import { Reflector } from "@venok/core";
|
|
19
|
+
import { MESSAGE_METADATA } from "../constants.js";
|
|
20
|
+
var SubscribeMessage = Reflector.createDecorator({ type: "method", key: MESSAGE_METADATA });
|
|
21
|
+
export {
|
|
22
|
+
SubscribeMessage
|
|
23
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/enums/ws-paramtype.ts
|
|
18
|
+
var WsParamtype;
|
|
19
|
+
((WsParamtype2) => {
|
|
20
|
+
WsParamtype2[WsParamtype2["SOCKET"] = 0] = "SOCKET";
|
|
21
|
+
WsParamtype2[WsParamtype2["PAYLOAD"] = 1] = "PAYLOAD";
|
|
22
|
+
WsParamtype2[WsParamtype2["ACK"] = 2] = "ACK";
|
|
23
|
+
WsParamtype2[WsParamtype2["PATTERN"] = 3] = "PATTERN";
|
|
24
|
+
})(WsParamtype ||= {});
|
|
25
|
+
export {
|
|
26
|
+
WsParamtype
|
|
27
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/errors/ack-not-supported.exception.ts
|
|
18
|
+
import { RuntimeException } from "@venok/core";
|
|
19
|
+
|
|
20
|
+
class AckNotSupportedException extends RuntimeException {
|
|
21
|
+
constructor(type, pattern) {
|
|
22
|
+
super(`Ack don't supported with your adapter. Remove @Ack decorator from gateway (${type}) handler with pattern: (${pattern})`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
AckNotSupportedException
|
|
27
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/errors/invalid-socket-port.exception.ts
|
|
18
|
+
import { RuntimeException } from "@venok/core";
|
|
19
|
+
|
|
20
|
+
class InvalidSocketPortException extends RuntimeException {
|
|
21
|
+
constructor(port, type) {
|
|
22
|
+
super(`Invalid port (${port}) in gateway ${type}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
InvalidSocketPortException
|
|
27
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/exceptions/ws.exception.ts
|
|
18
|
+
import { isObject, isString } from "@venok/core";
|
|
19
|
+
|
|
20
|
+
class WsException extends Error {
|
|
21
|
+
error;
|
|
22
|
+
constructor(error) {
|
|
23
|
+
super();
|
|
24
|
+
this.error = error;
|
|
25
|
+
this.initMessage();
|
|
26
|
+
}
|
|
27
|
+
initMessage() {
|
|
28
|
+
if (isString(this.error)) {
|
|
29
|
+
this.message = this.error;
|
|
30
|
+
} else if (isObject(this.error) && isString(this.error.message)) {
|
|
31
|
+
this.message = this.error.message;
|
|
32
|
+
} else if (this.constructor) {
|
|
33
|
+
this.message = this.constructor.name.match(/[A-Z][a-z]+|[0-9]+/g).join(" ");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getError() {
|
|
37
|
+
return this.error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
WsException
|
|
42
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/filters/context.ts
|
|
18
|
+
import { VenokExceptionFilterContext } from "@venok/core";
|
|
19
|
+
import { WebsocketExceptionFilter } from "../filters/filter.js";
|
|
20
|
+
|
|
21
|
+
class WebsocketExceptionFiltersContext extends VenokExceptionFilterContext {
|
|
22
|
+
getExceptionFilter() {
|
|
23
|
+
return new WebsocketExceptionFilter;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
WebsocketExceptionFiltersContext
|
|
28
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/filters/filter.ts
|
|
18
|
+
import { isObject, Logger, MESSAGES } from "@venok/core";
|
|
19
|
+
import { WsException } from "../exceptions/ws.exception.js";
|
|
20
|
+
import { WebsocketArgumentsHost } from "../websocket/arguments-host.js";
|
|
21
|
+
|
|
22
|
+
class WebsocketExceptionFilter {
|
|
23
|
+
options;
|
|
24
|
+
static logger = new Logger("WsExceptionsHandler");
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.options.includeCause = this.options.includeCause ?? true;
|
|
28
|
+
this.options.causeFactory = this.options.causeFactory ?? ((pattern, data) => ({ pattern, data }));
|
|
29
|
+
}
|
|
30
|
+
catch(exception, host) {
|
|
31
|
+
const websocketContext = WebsocketArgumentsHost.create(host);
|
|
32
|
+
const client = websocketContext.getClient();
|
|
33
|
+
const pattern = websocketContext.getPattern();
|
|
34
|
+
const data = websocketContext.getData();
|
|
35
|
+
this.handleError(client, exception, { pattern, data });
|
|
36
|
+
}
|
|
37
|
+
handleError(client, exception, cause) {
|
|
38
|
+
if (!(exception instanceof WsException))
|
|
39
|
+
return this.handleUnknownError(exception, client, cause);
|
|
40
|
+
const status = "error";
|
|
41
|
+
const result = exception.getError();
|
|
42
|
+
if (isObject(result))
|
|
43
|
+
return client.emit("exception", result);
|
|
44
|
+
const payload = {
|
|
45
|
+
status,
|
|
46
|
+
message: result
|
|
47
|
+
};
|
|
48
|
+
if (this.options?.includeCause && cause) {
|
|
49
|
+
payload.cause = this.options.causeFactory(cause.pattern, cause.data);
|
|
50
|
+
}
|
|
51
|
+
client.emit("exception", payload);
|
|
52
|
+
}
|
|
53
|
+
handleUnknownError(exception, client, data) {
|
|
54
|
+
const status = "error";
|
|
55
|
+
const payload = {
|
|
56
|
+
status,
|
|
57
|
+
message: MESSAGES.UNKNOWN_EXCEPTION_MESSAGE
|
|
58
|
+
};
|
|
59
|
+
if (this.options?.includeCause && data) {
|
|
60
|
+
payload.cause = this.options.causeFactory(data.pattern, data.data);
|
|
61
|
+
}
|
|
62
|
+
client.emit("exception", payload);
|
|
63
|
+
const logger = WebsocketExceptionFilter.logger;
|
|
64
|
+
logger.error(exception);
|
|
65
|
+
}
|
|
66
|
+
isExceptionObject(err) {
|
|
67
|
+
return isObject(err) && !!err.message;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
WebsocketExceptionFilter
|
|
72
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/helpers/discovery.helper.ts
|
|
18
|
+
import { GATEWAY_OPTIONS, PORT_METADATA } from "../constants.js";
|
|
19
|
+
|
|
20
|
+
class VenokBaseDiscovery {
|
|
21
|
+
meta;
|
|
22
|
+
discovery;
|
|
23
|
+
constructor(meta) {
|
|
24
|
+
this.meta = meta;
|
|
25
|
+
}
|
|
26
|
+
getClass() {
|
|
27
|
+
return this.discovery.class;
|
|
28
|
+
}
|
|
29
|
+
getHandler() {
|
|
30
|
+
return this.discovery.handler;
|
|
31
|
+
}
|
|
32
|
+
setDiscovery(discovery) {
|
|
33
|
+
this.discovery ??= discovery;
|
|
34
|
+
}
|
|
35
|
+
getMeta() {
|
|
36
|
+
return this.meta;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class WebsocketGatewayDiscovery extends VenokBaseDiscovery {
|
|
41
|
+
getPort() {
|
|
42
|
+
return this.meta[PORT_METADATA];
|
|
43
|
+
}
|
|
44
|
+
getOptions() {
|
|
45
|
+
return this.meta[GATEWAY_OPTIONS];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
WebsocketGatewayDiscovery,
|
|
50
|
+
VenokBaseDiscovery
|
|
51
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
4
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else
|
|
6
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
7
|
+
if (d = decorators[i])
|
|
8
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
+
};
|
|
11
|
+
var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
var __legacyMetadataTS = (k, v) => {
|
|
13
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
14
|
+
return Reflect.metadata(k, v);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/websocket/src/helpers/event-stream-factory.helper.ts
|
|
18
|
+
import { ReplaySubject, Subject } from "rxjs";
|
|
19
|
+
|
|
20
|
+
class EventStreamsFactory {
|
|
21
|
+
static create(server) {
|
|
22
|
+
const init = new ReplaySubject;
|
|
23
|
+
init.next(server);
|
|
24
|
+
const connection = new Subject;
|
|
25
|
+
const disconnect = new Subject;
|
|
26
|
+
return { init, connection, disconnect, server };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
EventStreamsFactory
|
|
31
|
+
};
|