@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thanks for using Venloc Venok <3
|
|
3
|
+
* https://github.com/venloc-tech/svm
|
|
4
|
+
*/
|
|
5
|
+
import * as _venok_core from '@venok/core';
|
|
6
|
+
import { VenokParamsFactoryInterface, Type, PipeTransform, ExecutionContextHost, ArgumentsHost } from '@venok/core';
|
|
7
|
+
import { ReplaySubject, Subject, Observable } from 'rxjs';
|
|
8
|
+
import * as _venok_integration from '@venok/integration';
|
|
9
|
+
|
|
10
|
+
type WebsocketGatewayHandlerMetadata = {
|
|
11
|
+
callback: (...args: any[]) => void;
|
|
12
|
+
pattern: string;
|
|
13
|
+
isAckHandledManually: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type WebsocketGatewayMetadata = {
|
|
17
|
+
port: number;
|
|
18
|
+
options: object;
|
|
19
|
+
handleConnect: Function | undefined;
|
|
20
|
+
handleDisconnect: Function | undefined;
|
|
21
|
+
afterInit: Function | undefined;
|
|
22
|
+
observableServer: EventStreamsHost;
|
|
23
|
+
handlers: WebsocketGatewayHandlerMetadata[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type GatewayDefaultOptions = {
|
|
27
|
+
path?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @publicApi
|
|
32
|
+
*/
|
|
33
|
+
interface EventStreamsHost<T = any> {
|
|
34
|
+
server: T;
|
|
35
|
+
init: ReplaySubject<T>;
|
|
36
|
+
connection: Subject<any>;
|
|
37
|
+
disconnect: Subject<any>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare class SocketsContainer {
|
|
41
|
+
private readonly eventStreamsHosts;
|
|
42
|
+
getAll(): Map<string | RegExp, EventStreamsHost>;
|
|
43
|
+
get<T extends Record<string, any> = any>(options: T): EventStreamsHost;
|
|
44
|
+
add<T extends Record<string, any> = any>(options: T, host: EventStreamsHost): void;
|
|
45
|
+
clear(): void;
|
|
46
|
+
private generateHashByOptions;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare const VENOK_WS_ADAPTER_GET_OR_CREATE_SERVER: unique symbol;
|
|
50
|
+
declare const VENOK_WS_ADAPTER_BIND_CLIENT_CONNECT: unique symbol;
|
|
51
|
+
declare const VENOK_WS_ADAPTER_BIND_CLIENT_DISCONNECT: unique symbol;
|
|
52
|
+
declare const VENOK_WS_ADAPTER_BIND_MESSAGE_HANDLERS: unique symbol;
|
|
53
|
+
declare const VENOK_WS_ADAPTER_CREATE: unique symbol;
|
|
54
|
+
declare const VENOK_WS_ADAPTER_LISTEN: unique symbol;
|
|
55
|
+
|
|
56
|
+
declare abstract class AbstractWebsocketAdapter<Server = any, Client = any, Options extends Record<string, any> = any> {
|
|
57
|
+
protected socketsContainer: SocketsContainer;
|
|
58
|
+
protected mainServerApplyCallback: Function | null;
|
|
59
|
+
isAckSupported: boolean;
|
|
60
|
+
useCustomFactory: boolean;
|
|
61
|
+
setMainServerApplyCallback(fn: Function): void;
|
|
62
|
+
abstract getParamsFactory(): VenokParamsFactoryInterface;
|
|
63
|
+
abstract [VENOK_WS_ADAPTER_GET_OR_CREATE_SERVER](port: number, options: any): EventStreamsHost;
|
|
64
|
+
abstract [VENOK_WS_ADAPTER_BIND_CLIENT_CONNECT](server: Server, callback: Function): void;
|
|
65
|
+
abstract [VENOK_WS_ADAPTER_BIND_CLIENT_DISCONNECT](client: Client, callback: Function): void;
|
|
66
|
+
abstract [VENOK_WS_ADAPTER_BIND_MESSAGE_HANDLERS](client: Client, handlers: WebsocketGatewayHandlerMetadata[], transform: (data: any) => Observable<any>): void;
|
|
67
|
+
abstract [VENOK_WS_ADAPTER_CREATE](port: number, options?: Options): Server;
|
|
68
|
+
abstract close(server: Server): Promise<void>;
|
|
69
|
+
abstract closeAll(): Promise<void>;
|
|
70
|
+
abstract [VENOK_WS_ADAPTER_LISTEN](config: {
|
|
71
|
+
mainHttpServerPort: number;
|
|
72
|
+
}): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type WebsocketAppOptions = {
|
|
76
|
+
adapter: AbstractWebsocketAdapter;
|
|
77
|
+
httpPort?: number;
|
|
78
|
+
attachMainWebsocketServerToHttpServerCallback?: (...args: any[]) => void;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Decorator that marks a class as a Nest gateway that enables real-time, bidirectional
|
|
83
|
+
* and event-based communication between the browser and the server.
|
|
84
|
+
*
|
|
85
|
+
* @publicApi
|
|
86
|
+
*/
|
|
87
|
+
declare function WebSocketGateway(port?: number): ClassDecorator;
|
|
88
|
+
declare function WebSocketGateway<T extends GatewayDefaultOptions = GatewayDefaultOptions>(options?: T): ClassDecorator;
|
|
89
|
+
declare function WebSocketGateway<T extends GatewayDefaultOptions = GatewayDefaultOptions>(port?: number, options?: T): ClassDecorator;
|
|
90
|
+
declare namespace WebSocketGateway {
|
|
91
|
+
var KEY: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* WebSockets message body parameter decorator.
|
|
96
|
+
*
|
|
97
|
+
* @publicApi
|
|
98
|
+
*/
|
|
99
|
+
declare function MessageBody(): ParameterDecorator;
|
|
100
|
+
/**
|
|
101
|
+
* WebSockets message body parameter decorator.
|
|
102
|
+
*
|
|
103
|
+
* Example:
|
|
104
|
+
* ```ts
|
|
105
|
+
* create(@MessageBody(new ValidationPipe()) createDto: CreateCatDto)
|
|
106
|
+
* ```
|
|
107
|
+
* @param pipes one or more pipes - either instances or classes - to apply to
|
|
108
|
+
* the bound parameter.
|
|
109
|
+
*
|
|
110
|
+
* @publicApi
|
|
111
|
+
*/
|
|
112
|
+
declare function MessageBody(...pipes: (Type<PipeTransform> | PipeTransform)[]): ParameterDecorator;
|
|
113
|
+
/**
|
|
114
|
+
* WebSockets message body parameter decorator. Extracts a property from the
|
|
115
|
+
* message payload object. May also apply pipes to the bound parameter.
|
|
116
|
+
*
|
|
117
|
+
* For example, extracting all params:
|
|
118
|
+
* ```ts
|
|
119
|
+
* findMany(@MessageBody() ids: string[])
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* For example, extracting a single param:
|
|
123
|
+
* ```ts
|
|
124
|
+
* create(@MessageBody('data') createDto: { data: string })
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* For example, extracting a single param with pipe:
|
|
128
|
+
* ```ts
|
|
129
|
+
* create(@MessageBody('data', new ValidationPipe()) createDto: { data: string })
|
|
130
|
+
* ```
|
|
131
|
+
* @param propertyKey name of single property to extract from the message payload
|
|
132
|
+
* @param pipes one or more pipes - either instances or classes - to apply to
|
|
133
|
+
* the bound parameter.
|
|
134
|
+
*
|
|
135
|
+
* @publicApi
|
|
136
|
+
*/
|
|
137
|
+
declare function MessageBody(propertyKey: string | number, ...pipes: (Type<PipeTransform> | PipeTransform)[]): ParameterDecorator;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Attaches native Web Socket Server to a given property.
|
|
141
|
+
*
|
|
142
|
+
* @publicApi
|
|
143
|
+
*/
|
|
144
|
+
declare const WebsocketServer: () => PropertyDecorator;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @publicApi
|
|
148
|
+
*/
|
|
149
|
+
declare const Socket: () => ParameterDecorator;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Subscribes to messages that fulfils chosen pattern.
|
|
153
|
+
*
|
|
154
|
+
* @publicApi
|
|
155
|
+
*/
|
|
156
|
+
declare const SubscribeMessage: _venok_core.ReflectableMethodDecorator<string, string>;
|
|
157
|
+
|
|
158
|
+
declare class WsException extends Error {
|
|
159
|
+
private readonly error;
|
|
160
|
+
constructor(error: string | object);
|
|
161
|
+
initMessage(): void;
|
|
162
|
+
getError(): string | object;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
declare class EventStreamsFactory {
|
|
166
|
+
static create<T = any>(server: T): EventStreamsHost<T>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
declare class WebsocketArgumentsHost extends ExecutionContextHost {
|
|
170
|
+
static create(context: ArgumentsHost): WebsocketArgumentsHost;
|
|
171
|
+
getClient<T>(): T;
|
|
172
|
+
getData<T>(): T;
|
|
173
|
+
getPattern(): string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare class WebsocketConfig<T extends AbstractWebsocketAdapter = AbstractWebsocketAdapter> {
|
|
177
|
+
private readonly options;
|
|
178
|
+
private adapter;
|
|
179
|
+
constructor(options: Required<WebsocketAppOptions>);
|
|
180
|
+
setAdapter(websocketAdapter: T): void;
|
|
181
|
+
getAdapter(): T;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
declare const WebsocketConfigurableModuleClass: _venok_integration.ConfigurableModuleCls<WebsocketAppOptions, "register", "create", object>;
|
|
185
|
+
|
|
186
|
+
declare class WebsocketModule extends WebsocketConfigurableModuleClass {
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
declare class WsParamsFactory implements VenokParamsFactoryInterface {
|
|
190
|
+
exchangeKeyForValue(type: number, data: string | undefined, args: [any, any, ...any, string]): any;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
declare const MESSAGE_METADATA = "message";
|
|
194
|
+
declare const GATEWAY_SERVER_METADATA = "websockets:is_socket";
|
|
195
|
+
declare const GATEWAY_METADATA = "websockets:is_gateway";
|
|
196
|
+
declare const PORT_METADATA = "port";
|
|
197
|
+
declare const GATEWAY_OPTIONS = "websockets:gateway_options";
|
|
198
|
+
declare const PARAM_ARGS_METADATA = "__routeArguments__";
|
|
199
|
+
|
|
200
|
+
export { AbstractWebsocketAdapter, EventStreamsFactory, type EventStreamsHost, GATEWAY_METADATA, GATEWAY_OPTIONS, GATEWAY_SERVER_METADATA, type GatewayDefaultOptions, MESSAGE_METADATA, MessageBody, PARAM_ARGS_METADATA, PORT_METADATA, Socket, SubscribeMessage, VENOK_WS_ADAPTER_BIND_CLIENT_CONNECT, VENOK_WS_ADAPTER_BIND_CLIENT_DISCONNECT, VENOK_WS_ADAPTER_BIND_MESSAGE_HANDLERS, VENOK_WS_ADAPTER_CREATE, VENOK_WS_ADAPTER_GET_OR_CREATE_SERVER, VENOK_WS_ADAPTER_LISTEN, WebSocketGateway, type WebsocketAppOptions, WebsocketArgumentsHost, WebsocketConfig, type WebsocketGatewayHandlerMetadata, type WebsocketGatewayMetadata, WebsocketModule, WebsocketServer, WsException, WsParamsFactory };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// packages/websocket/src/index.ts
|
|
2
|
+
import"reflect-metadata";
|
|
3
|
+
|
|
4
|
+
export * from "./decorators/gateway.decorator.js";
|
|
5
|
+
export * from "./decorators/message-body.decorator.js";
|
|
6
|
+
export * from "./decorators/server.decorator.js";
|
|
7
|
+
export * from "./decorators/socket.decorator.js";
|
|
8
|
+
export * from "./decorators/subscribe-message.decorator.js";
|
|
9
|
+
export * from "./exceptions/ws.exception.js";
|
|
10
|
+
export * from "./helpers/event-stream-factory.helper.js";
|
|
11
|
+
export * from "./interfaces/index.js";
|
|
12
|
+
export * from "./websocket/adapter.js";
|
|
13
|
+
export * from "./websocket/arguments-host.js";
|
|
14
|
+
export * from "./websocket/config.js";
|
|
15
|
+
export * from "./websocket/module.js";
|
|
16
|
+
export * from "./websocket/params-factory.js";
|
|
17
|
+
export * from "./constants.js";
|
|
18
|
+
export * from "./symbols.js";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/symbols.js
ADDED
|
@@ -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/symbols.ts
|
|
18
|
+
var VENOK_WS_ADAPTER_GET_OR_CREATE_SERVER = Symbol("VENOK_WS_ADAPTER_GET_OR_CREATE_SERVER");
|
|
19
|
+
var VENOK_WS_ADAPTER_BIND_CLIENT_CONNECT = Symbol("VENOK_WS_ADAPTER_BIND_CLIENT_CONNECT");
|
|
20
|
+
var VENOK_WS_ADAPTER_BIND_CLIENT_DISCONNECT = Symbol("VENOK_WS_ADAPTER_BIND_CLIENT_DISCONNECT");
|
|
21
|
+
var VENOK_WS_ADAPTER_BIND_MESSAGE_HANDLERS = Symbol("VENOK_WS_ADAPTER_BIND_MESSAGE_HANDLERS");
|
|
22
|
+
var VENOK_WS_ADAPTER_CREATE = Symbol("VENOK_WS_ADAPTER_CREATE");
|
|
23
|
+
var VENOK_WS_ADAPTER_LISTEN = Symbol("VENOK_WS_ADAPTER_LISTEN");
|
|
24
|
+
export {
|
|
25
|
+
VENOK_WS_ADAPTER_LISTEN,
|
|
26
|
+
VENOK_WS_ADAPTER_GET_OR_CREATE_SERVER,
|
|
27
|
+
VENOK_WS_ADAPTER_CREATE,
|
|
28
|
+
VENOK_WS_ADAPTER_BIND_MESSAGE_HANDLERS,
|
|
29
|
+
VENOK_WS_ADAPTER_BIND_CLIENT_DISCONNECT,
|
|
30
|
+
VENOK_WS_ADAPTER_BIND_CLIENT_CONNECT
|
|
31
|
+
};
|
|
@@ -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/websocket/adapter.ts
|
|
18
|
+
import { SocketsContainer } from "../websocket/container.js";
|
|
19
|
+
|
|
20
|
+
class AbstractWebsocketAdapter {
|
|
21
|
+
socketsContainer = new SocketsContainer;
|
|
22
|
+
mainServerApplyCallback = null;
|
|
23
|
+
isAckSupported = false;
|
|
24
|
+
useCustomFactory = false;
|
|
25
|
+
setMainServerApplyCallback(fn) {
|
|
26
|
+
this.mainServerApplyCallback = fn;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
AbstractWebsocketAdapter
|
|
31
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
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/websocket/arguments-host.ts
|
|
18
|
+
import { ExecutionContextHost } from "@venok/core";
|
|
19
|
+
|
|
20
|
+
class WebsocketArgumentsHost extends ExecutionContextHost {
|
|
21
|
+
static create(context) {
|
|
22
|
+
const type = context.getType();
|
|
23
|
+
const websocketContext = new WebsocketArgumentsHost(context.getArgs());
|
|
24
|
+
websocketContext.setType(type);
|
|
25
|
+
return websocketContext;
|
|
26
|
+
}
|
|
27
|
+
getClient() {
|
|
28
|
+
return this.getArgByIndex(0);
|
|
29
|
+
}
|
|
30
|
+
getData() {
|
|
31
|
+
return this.getArgByIndex(1);
|
|
32
|
+
}
|
|
33
|
+
getPattern() {
|
|
34
|
+
return this.getArgByIndex(this.getArgs().length - 1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
WebsocketArgumentsHost
|
|
39
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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/websocket/config.ts
|
|
18
|
+
import { Inject, Injectable } from "@venok/core";
|
|
19
|
+
import { WEBSOCKET_APP_OPTIONS } from "../websocket/configurable-module.js";
|
|
20
|
+
class WebsocketConfig {
|
|
21
|
+
options;
|
|
22
|
+
adapter;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.adapter = this.options.adapter;
|
|
26
|
+
}
|
|
27
|
+
setAdapter(websocketAdapter) {
|
|
28
|
+
this.adapter = websocketAdapter;
|
|
29
|
+
}
|
|
30
|
+
getAdapter() {
|
|
31
|
+
return this.adapter;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
WebsocketConfig = __legacyDecorateClassTS([
|
|
35
|
+
Injectable(),
|
|
36
|
+
__legacyDecorateParamTS(0, Inject(WEBSOCKET_APP_OPTIONS)),
|
|
37
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
38
|
+
typeof Required === "undefined" ? Object : Required
|
|
39
|
+
])
|
|
40
|
+
], WebsocketConfig);
|
|
41
|
+
export {
|
|
42
|
+
WebsocketConfig
|
|
43
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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/websocket/configurable-module.ts
|
|
18
|
+
import { ConfigurableModuleBuilder } from "@venok/integration";
|
|
19
|
+
var {
|
|
20
|
+
ConfigurableModuleClass: WebsocketConfigurableModuleClass,
|
|
21
|
+
MODULE_OPTIONS_TOKEN: WEBSOCKET_APP_OPTIONS
|
|
22
|
+
} = new ConfigurableModuleBuilder().build();
|
|
23
|
+
export {
|
|
24
|
+
WebsocketConfigurableModuleClass,
|
|
25
|
+
WEBSOCKET_APP_OPTIONS
|
|
26
|
+
};
|
|
@@ -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/websocket/container.ts
|
|
18
|
+
import hash from "object-hash";
|
|
19
|
+
|
|
20
|
+
class SocketsContainer {
|
|
21
|
+
eventStreamsHosts = new Map;
|
|
22
|
+
getAll() {
|
|
23
|
+
return this.eventStreamsHosts;
|
|
24
|
+
}
|
|
25
|
+
get(options) {
|
|
26
|
+
const uniqueToken = this.generateHashByOptions(options);
|
|
27
|
+
return this.eventStreamsHosts.get(uniqueToken);
|
|
28
|
+
}
|
|
29
|
+
add(options, host) {
|
|
30
|
+
const uniqueToken = this.generateHashByOptions(options);
|
|
31
|
+
this.eventStreamsHosts.set(uniqueToken, host);
|
|
32
|
+
}
|
|
33
|
+
clear() {
|
|
34
|
+
this.eventStreamsHosts.clear();
|
|
35
|
+
}
|
|
36
|
+
generateHashByOptions(options) {
|
|
37
|
+
return hash(options, { ignoreUnknown: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
SocketsContainer
|
|
42
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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/websocket/context.ts
|
|
18
|
+
import { STATIC_CONTEXT, VenokContextCreator } from "@venok/core";
|
|
19
|
+
import { MESSAGE_METADATA } from "../constants.js";
|
|
20
|
+
|
|
21
|
+
class WebsocketContextCreator extends VenokContextCreator {
|
|
22
|
+
create(instance, callback, methodName, metadataKey, paramsFactory, contextId = STATIC_CONTEXT, inquirerId, options = {
|
|
23
|
+
interceptors: true,
|
|
24
|
+
guards: true,
|
|
25
|
+
filters: false,
|
|
26
|
+
callback: undefined
|
|
27
|
+
}, contextType = "websocket") {
|
|
28
|
+
const moduleKey = this.getContextModuleKey(instance.constructor);
|
|
29
|
+
const targetPattern = this.reflectCallbackPattern(callback);
|
|
30
|
+
const result = super.create(instance, callback, methodName, metadataKey, paramsFactory, contextId, inquirerId, options, contextType);
|
|
31
|
+
const exceptionFilter = this.filtersContextCreator.create(instance, callback, moduleKey, contextId, inquirerId);
|
|
32
|
+
return async (...args) => {
|
|
33
|
+
args.push(targetPattern);
|
|
34
|
+
return await this.venokProxy.createProxy(result, exceptionFilter)(...args);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
reflectCallbackPattern(callback) {
|
|
38
|
+
return Reflect.getMetadata(MESSAGE_METADATA, callback);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
WebsocketContextCreator
|
|
43
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
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/websocket/explorer.ts
|
|
18
|
+
import { Inject, isFunction, isUndefined, Logger, MetadataScanner } from "@venok/core";
|
|
19
|
+
import { ExplorerService } from "@venok/integration";
|
|
20
|
+
import { GATEWAY_SERVER_METADATA, MESSAGE_METADATA } from "../constants.js";
|
|
21
|
+
import { WebsocketContextCreator } from "../websocket/context.js";
|
|
22
|
+
import { WsParamsFactory } from "../websocket/params-factory.js";
|
|
23
|
+
import { WebsocketConfig } from "../websocket/config.js";
|
|
24
|
+
import { GatewayFinder } from "../websocket/finder.js";
|
|
25
|
+
import { InvalidSocketPortException } from "../errors/invalid-socket-port.exception.js";
|
|
26
|
+
import { AckNotSupportedException } from "../errors/ack-not-supported.exception.js";
|
|
27
|
+
import { WebsocketExceptionFiltersContext } from "../filters/context.js";
|
|
28
|
+
import { VENOK_WS_ADAPTER_GET_OR_CREATE_SERVER } from "../symbols.js";
|
|
29
|
+
class WebsocketExplorerService extends ExplorerService {
|
|
30
|
+
logger = new Logger(WebsocketExplorerService.name, { timestamp: true });
|
|
31
|
+
patternFinder = new GatewayFinder(new MetadataScanner);
|
|
32
|
+
paramsFactory;
|
|
33
|
+
onModuleInit() {
|
|
34
|
+
const adapter = this.websocketConfig.getAdapter();
|
|
35
|
+
this.paramsFactory = adapter.useCustomFactory ? adapter.getParamsFactory() : new WsParamsFactory;
|
|
36
|
+
}
|
|
37
|
+
getSettings() {
|
|
38
|
+
return {
|
|
39
|
+
contextType: "websocket",
|
|
40
|
+
isRequestScopeSupported: true,
|
|
41
|
+
exceptionsFilterClass: WebsocketExceptionFiltersContext,
|
|
42
|
+
contextCreatorClass: WebsocketContextCreator,
|
|
43
|
+
options: { guards: true, interceptors: true, filters: false }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
filterProperties(wrapper, metadataKey) {
|
|
47
|
+
if (!wrapper.metatype)
|
|
48
|
+
return;
|
|
49
|
+
const gateway = this.get(metadataKey, wrapper.metatype);
|
|
50
|
+
if (!gateway)
|
|
51
|
+
return;
|
|
52
|
+
const port = gateway.getPort();
|
|
53
|
+
const options = gateway.getOptions();
|
|
54
|
+
if (!Number.isInteger(port) || port < 0)
|
|
55
|
+
throw new InvalidSocketPortException(port, wrapper.metatype);
|
|
56
|
+
this.logGateway(wrapper.instance, port);
|
|
57
|
+
const handlers = this.patternFinder.getGatewayHandlers(wrapper.instance).map((handler) => ({ ...handler, callback: this.createCallback(wrapper, handler.methodName) }));
|
|
58
|
+
if (!handlers.length)
|
|
59
|
+
return;
|
|
60
|
+
const adapter = this.websocketConfig.getAdapter();
|
|
61
|
+
if (!adapter.isAckSupported && handlers.some((metadata) => metadata.isAckHandledManually)) {
|
|
62
|
+
const metadata = handlers.find((metadata2) => metadata2.isAckHandledManually);
|
|
63
|
+
throw new AckNotSupportedException(wrapper.metatype, metadata.pattern);
|
|
64
|
+
}
|
|
65
|
+
let handleConnect = wrapper.instance.handleConnect;
|
|
66
|
+
if (handleConnect) {
|
|
67
|
+
Reflect.defineMetadata(MESSAGE_METADATA, "connect", wrapper.instance["handleConnect"]);
|
|
68
|
+
handleConnect = (rxjsArgs) => this.createCallback(wrapper, "handleConnect")(...rxjsArgs);
|
|
69
|
+
}
|
|
70
|
+
let handleDisconnect = wrapper.instance.handleConnection;
|
|
71
|
+
if (handleDisconnect) {
|
|
72
|
+
Reflect.defineMetadata(MESSAGE_METADATA, "disconnect", wrapper.instance["handleDisconnect"]);
|
|
73
|
+
handleDisconnect = (rxjsArgs) => this.createCallback(wrapper, "handleDisconnect")(...rxjsArgs);
|
|
74
|
+
}
|
|
75
|
+
const afterInit = wrapper.instance.afterInit;
|
|
76
|
+
const observableServer = adapter[VENOK_WS_ADAPTER_GET_OR_CREATE_SERVER](port, options);
|
|
77
|
+
this.assignServerToProperties(wrapper.instance, observableServer.server);
|
|
78
|
+
this.logHandler(wrapper.instance, port, handlers);
|
|
79
|
+
return {
|
|
80
|
+
port,
|
|
81
|
+
options,
|
|
82
|
+
handleConnect,
|
|
83
|
+
handleDisconnect,
|
|
84
|
+
afterInit,
|
|
85
|
+
observableServer,
|
|
86
|
+
handlers
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
assignServerToProperties(instance, server) {
|
|
90
|
+
for (const propertyKey in instance) {
|
|
91
|
+
if (isFunction(propertyKey))
|
|
92
|
+
continue;
|
|
93
|
+
const property = String(propertyKey);
|
|
94
|
+
const isServer = Reflect.getMetadata(GATEWAY_SERVER_METADATA, instance, property);
|
|
95
|
+
if (!isUndefined(isServer))
|
|
96
|
+
Reflect.set(instance, propertyKey, server);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
logGateway(instance, port) {
|
|
100
|
+
const gatewayClassName = instance?.constructor?.name;
|
|
101
|
+
if (!gatewayClassName)
|
|
102
|
+
return;
|
|
103
|
+
this.logger.log(`${gatewayClassName} {${port}}:`);
|
|
104
|
+
}
|
|
105
|
+
logHandler(instance, port, handlers) {
|
|
106
|
+
const gatewayClassName = instance?.constructor?.name;
|
|
107
|
+
if (!gatewayClassName)
|
|
108
|
+
return;
|
|
109
|
+
handlers.forEach(({ pattern }) => this.logger.log(`Mapped {${gatewayClassName}:${port}, ${pattern}} handler`));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
__legacyDecorateClassTS([
|
|
113
|
+
Inject(WebsocketConfig),
|
|
114
|
+
__legacyMetadataTS("design:type", typeof WebsocketConfig === "undefined" ? Object : WebsocketConfig)
|
|
115
|
+
], WebsocketExplorerService.prototype, "websocketConfig", undefined);
|
|
116
|
+
export {
|
|
117
|
+
WebsocketExplorerService
|
|
118
|
+
};
|