thor-io.vnext 2.0.6 → 3.1.0-beta.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/.gitattributes +17 -17
- package/{index.d.ts → build/index.d.ts} +11 -8
- package/build/index.js +47 -0
- package/build/src/Connection/ClientInfo.d.ts +27 -0
- package/{src → build/src}/Connection/ClientInfo.js +7 -0
- package/build/src/Connection/Connection.d.ts +117 -0
- package/build/src/Connection/Connection.js +202 -0
- package/build/src/Connection/IClientInfo.d.ts +20 -0
- package/build/src/Controller/ControllerBase.d.ts +134 -0
- package/build/src/Controller/ControllerBase.js +543 -0
- package/build/src/Controller/Subscription.d.ts +27 -0
- package/build/src/Controller/Subscription.js +22 -0
- package/build/src/Controllers/BrokerController/Broker.js +145 -0
- package/build/src/Controllers/BrokerController/BrokerController.d.ts +61 -0
- package/build/src/Controllers/BrokerController/BrokerController.js +115 -0
- package/{src/Controllers/BrokerController/Broker.js → build/src/Controllers/BrokerController/BrokerrController.js} +74 -85
- package/build/src/Controllers/BrokerController/Models/PeerConnection.d.ts +7 -0
- package/build/src/Controllers/BrokerController/Models/PeerConnection.js +14 -0
- package/build/src/Controllers/BrokerController/Models/Signal.js +11 -0
- package/build/src/Decorators/CanInvoke.d.ts +10 -0
- package/build/src/Decorators/CanInvoke.js +22 -0
- package/build/src/Decorators/CanSet.d.ts +10 -0
- package/build/src/Decorators/CanSet.js +20 -0
- package/build/src/Decorators/ControllerProperties.d.ts +10 -0
- package/build/src/Decorators/ControllerProperties.js +20 -0
- package/build/src/Interfaces/IInterceptor.js +2 -0
- package/build/src/Interfaces/ITransport.d.ts +94 -0
- package/build/src/Interfaces/ITransportMessage.d.ts +41 -0
- package/build/src/Messages/BufferMessage.d.ts +38 -0
- package/{src → build/src}/Messages/BufferMessage.js +32 -2
- package/build/src/Messages/ErrorMessage.d.ts +29 -0
- package/build/src/Messages/ErrorMessage.js +22 -0
- package/build/src/Messages/PipeMessage.d.ts +46 -0
- package/build/src/Messages/PipeMessage.js +41 -0
- package/build/src/Messages/TextMessage.d.ts +88 -0
- package/build/src/Messages/TextMessage.js +94 -0
- package/build/src/Messages/WebSocketMessage.d.ts +34 -0
- package/build/src/Messages/WebSocketMessage.js +41 -0
- package/build/src/Plugin.js +32 -0
- package/build/src/Server/Plugin.d.ts +37 -0
- package/build/src/Server/Plugin.js +32 -0
- package/build/src/Server/ThorIOServer.d.ts +68 -0
- package/build/src/Server/ThorIOServer.js +131 -0
- package/build/src/Subscription.js +22 -0
- package/build/src/ThorIO.js +142 -0
- package/build/src/ThorIOServer.d.ts +64 -0
- package/build/src/ThorIOServer.js +131 -0
- package/build/src/Transports/BufferMessageTransport.d.ts +78 -0
- package/build/src/Transports/BufferMessageTransport.js +85 -0
- package/build/src/Transports/PipeMessageTransport.d.ts +79 -0
- package/build/src/Transports/PipeMessageTransport.js +90 -0
- package/build/src/Transports/WebSocketMessageTransport.d.ts +87 -0
- package/build/src/Transports/WebSocketMessageTransport.js +93 -0
- package/build/src/Utils/BufferUtils.d.ts +32 -0
- package/build/src/Utils/BufferUtils.js +57 -0
- package/build/src/Utils/StringUtils.d.ts +15 -0
- package/build/src/Utils/StringUtils.js +31 -0
- package/build/src/test.js +5 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +43 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1610 -0
- package/docs/classes/BrokerController.html +164 -0
- package/docs/classes/BufferMessage.html +11 -0
- package/docs/classes/BufferMessageTransport.html +31 -0
- package/docs/classes/BufferUtils.html +16 -0
- package/docs/classes/ClientInfo.html +11 -0
- package/docs/classes/Connection.html +42 -0
- package/docs/classes/ControllerBase.html +144 -0
- package/docs/classes/ErrorMessage.html +13 -0
- package/docs/classes/PeerConnection.html +4 -0
- package/docs/classes/PipeMessage.html +17 -0
- package/docs/classes/PipeMessageTransport.html +33 -0
- package/docs/classes/Plugin.html +13 -0
- package/docs/classes/Signal.html +5 -0
- package/docs/classes/StringUtils.html +9 -0
- package/docs/classes/Subscription.html +11 -0
- package/docs/classes/TextMessage.html +37 -0
- package/docs/classes/ThorIOServer.html +25 -0
- package/docs/classes/WebSocketMessage.html +18 -0
- package/docs/classes/WebSocketMessageTransport.html +35 -0
- package/docs/functions/CanInvoke.html +5 -0
- package/docs/functions/CanSet.html +5 -0
- package/docs/functions/ControllerProperties.html +5 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +24 -0
- package/docs/interfaces/ITransport.html +46 -0
- package/docs/interfaces/ITransportMessage.html +21 -0
- package/docs/modules.html +1 -0
- package/index.ts +32 -35
- package/licence +21 -21
- package/package.json +48 -49
- package/readme.md +32 -71
- package/src/Connection/ClientInfo.ts +34 -37
- package/src/Connection/Connection.ts +229 -278
- package/src/Connection/IClientInfo.ts +22 -0
- package/src/Controller/ControllerBase.ts +561 -458
- package/src/{Subscription.ts → Controller/Subscription.ts} +32 -34
- package/src/Controllers/BrokerController/BrokerController.ts +121 -0
- package/src/Controllers/BrokerController/Models/PeerConnection.ts +12 -34
- package/src/Controllers/BrokerController/Models/Signal.ts +11 -43
- package/src/Decorators/CanInvoke.ts +21 -13
- package/src/Decorators/CanSet.ts +19 -12
- package/src/Decorators/ControllerProperties.ts +19 -16
- package/src/Interfaces/ITransport.ts +107 -23
- package/src/Interfaces/ITransportMessage.ts +45 -41
- package/src/Messages/BufferMessage.ts +70 -69
- package/src/Messages/ErrorMessage.ts +34 -6
- package/src/Messages/PipeMessage.ts +56 -62
- package/src/Messages/TextMessage.ts +139 -93
- package/src/Messages/WebSocketMessage.ts +39 -41
- package/src/Server/Plugin.ts +56 -0
- package/src/Server/ThorIOServer.ts +121 -0
- package/src/ThorIOServer.ts +117 -0
- package/src/Transports/BufferMessageTransport.ts +109 -100
- package/src/Transports/PipeMessageTransport.ts +112 -104
- package/src/Transports/WebSocketMessageTransport.ts +122 -110
- package/src/Utils/BufferUtils.ts +55 -61
- package/src/Utils/StringUtils.ts +28 -17
- package/tsconfig.json +109 -18
- package/typedoc.json +6 -0
- package/index.js +0 -40
- package/src/Connection/ClientInfo.d.ts +0 -6
- package/src/Connection/Connection.d.ts +0 -24
- package/src/Connection/Connection.js +0 -129
- package/src/Controller/ControllerBase.d.ts +0 -43
- package/src/Controller/ControllerBase.js +0 -331
- package/src/Controllers/BrokerController/Broker.d.ts +0 -21
- package/src/Controllers/BrokerController/Broker.ts +0 -153
- package/src/Controllers/BrokerController/Models/PeerConnection.d.ts +0 -5
- package/src/Controllers/BrokerController/Models/PeerConnection.js +0 -9
- package/src/Controllers/BrokerController/Models/Signal.js +0 -10
- package/src/Decorators/CanInvoke.d.ts +0 -2
- package/src/Decorators/CanInvoke.js +0 -9
- package/src/Decorators/CanSet.d.ts +0 -1
- package/src/Decorators/CanSet.js +0 -8
- package/src/Decorators/ControllerProperties.d.ts +0 -1
- package/src/Decorators/ControllerProperties.js +0 -10
- package/src/Interfaces/IInterceptor.d.ts +0 -2
- package/src/Interfaces/IInterceptor.ts +0 -2
- package/src/Interfaces/ITransport.d.ts +0 -18
- package/src/Interfaces/ITransportMessage.d.ts +0 -8
- package/src/Messages/BufferMessage.d.ts +0 -10
- package/src/Messages/ErrorMessage.d.ts +0 -4
- package/src/Messages/ErrorMessage.js +0 -8
- package/src/Messages/PipeMessage.d.ts +0 -12
- package/src/Messages/PipeMessage.js +0 -20
- package/src/Messages/TextMessage.d.ts +0 -15
- package/src/Messages/TextMessage.js +0 -50
- package/src/Messages/WebSocketMessage.d.ts +0 -10
- package/src/Messages/WebSocketMessage.js +0 -15
- package/src/Plugin.d.ts +0 -6
- package/src/Plugin.js +0 -11
- package/src/Plugin.ts +0 -37
- package/src/Subscription.d.ts +0 -5
- package/src/Subscription.js +0 -9
- package/src/ThorIO.d.ts +0 -19
- package/src/ThorIO.js +0 -67
- package/src/ThorIO.ts +0 -153
- package/src/Transports/BufferMessageTransport.d.ts +0 -21
- package/src/Transports/BufferMessageTransport.js +0 -31
- package/src/Transports/PipeMessageTransport.d.ts +0 -20
- package/src/Transports/PipeMessageTransport.js +0 -33
- package/src/Transports/WebSocketMessageTransport.d.ts +0 -20
- package/src/Transports/WebSocketMessageTransport.js +0 -31
- package/src/Utils/BufferUtils.d.ts +0 -5
- package/src/Utils/BufferUtils.js +0 -29
- package/src/Utils/StringUtils.d.ts +0 -4
- package/src/Utils/StringUtils.js +0 -13
- /package/{src/Interfaces/IInterceptor.js → build/src/Connection/IClientInfo.js} +0 -0
- /package/{src → build/src}/Controllers/BrokerController/Models/Signal.d.ts +0 -0
- /package/{src → build/src}/Interfaces/ITransport.js +0 -0
- /package/{src → build/src}/Interfaces/ITransportMessage.js +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { IncomingMessage } from 'http';
|
|
2
|
+
import { ITransportMessage } from './ITransportMessage';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a transport interface for handling communication over various protocols.
|
|
5
|
+
* This could be used for WebSocket, HTTP, or any other transport mechanism.
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @interface ITransport
|
|
9
|
+
*/
|
|
10
|
+
export interface ITransport {
|
|
11
|
+
/**
|
|
12
|
+
* A unique identifier for the transport instance.
|
|
13
|
+
*
|
|
14
|
+
* @type {string}
|
|
15
|
+
* @memberOf ITransport
|
|
16
|
+
*/
|
|
17
|
+
id: string;
|
|
18
|
+
/**
|
|
19
|
+
* The underlying socket or connection object used for communication.
|
|
20
|
+
*
|
|
21
|
+
* @type {*}
|
|
22
|
+
* @memberOf ITransport
|
|
23
|
+
*/
|
|
24
|
+
socket: any;
|
|
25
|
+
/**
|
|
26
|
+
* The current state of the connection (e.g., open, closed, etc.).
|
|
27
|
+
* This is commonly used in WebSockets but can be adapted for other transport mechanisms.
|
|
28
|
+
*
|
|
29
|
+
* @readonly
|
|
30
|
+
* @type {number}
|
|
31
|
+
* @memberOf ITransport
|
|
32
|
+
*/
|
|
33
|
+
readyState: number;
|
|
34
|
+
/**
|
|
35
|
+
* Sends data over the transport connection.
|
|
36
|
+
*
|
|
37
|
+
* @param {any} data The data to send. It can be any type, depending on the transport.
|
|
38
|
+
* @memberOf ITransport
|
|
39
|
+
*/
|
|
40
|
+
send(data: any): void;
|
|
41
|
+
/**
|
|
42
|
+
* Closes the connection with a specified reason and optional message.
|
|
43
|
+
*
|
|
44
|
+
* @param {number} reason The reason code for closing the connection.
|
|
45
|
+
* @param {any} message An optional message to include with the close operation.
|
|
46
|
+
* @memberOf ITransport
|
|
47
|
+
*/
|
|
48
|
+
close(reason: number, message: any): void;
|
|
49
|
+
/**
|
|
50
|
+
* Adds an event listener to the transport, e.g., for handling incoming messages or state changes.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} topic The event name or topic to listen for.
|
|
53
|
+
* @param {Function} fn The callback function to invoke when the event occurs.
|
|
54
|
+
* @memberOf ITransport
|
|
55
|
+
*/
|
|
56
|
+
addEventListener(topic: string, fn: Function): void;
|
|
57
|
+
/**
|
|
58
|
+
* Sends a ping message to keep the connection alive or check its status.
|
|
59
|
+
*
|
|
60
|
+
* @memberOf ITransport
|
|
61
|
+
*/
|
|
62
|
+
ping(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Callback function that is invoked when a message is received.
|
|
65
|
+
* This function is optional and can be defined by the implementing class.
|
|
66
|
+
*
|
|
67
|
+
* @type {(message: ITransportMessage) => void}
|
|
68
|
+
* @memberOf ITransport
|
|
69
|
+
*/
|
|
70
|
+
onMessage?: (message: ITransportMessage) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Callback function that is invoked when the connection is closed.
|
|
73
|
+
* This function is optional and can be defined by the implementing class.
|
|
74
|
+
*
|
|
75
|
+
* @type {(e: any) => void}
|
|
76
|
+
* @memberOf ITransport
|
|
77
|
+
*/
|
|
78
|
+
onClose?: (e: any) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Callback function that is invoked when the connection is established or opened.
|
|
81
|
+
* This function is optional and can be defined by the implementing class.
|
|
82
|
+
*
|
|
83
|
+
* @type {(e: any) => void}
|
|
84
|
+
* @memberOf ITransport
|
|
85
|
+
*/
|
|
86
|
+
onOpen?: (e: any) => void;
|
|
87
|
+
/**
|
|
88
|
+
* The initial HTTP request (if applicable) associated with the transport connection.
|
|
89
|
+
*
|
|
90
|
+
* @type {IncomingMessage | any}
|
|
91
|
+
* @memberOf ITransport
|
|
92
|
+
*/
|
|
93
|
+
request: IncomingMessage | any;
|
|
94
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { TextMessage } from '../Messages/TextMessage';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a message that can be transported and converted to/from different formats.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @interface ITransportMessage
|
|
7
|
+
*/
|
|
8
|
+
export interface ITransportMessage {
|
|
9
|
+
/**
|
|
10
|
+
* Converts the transport message into a `TextMessage` instance.
|
|
11
|
+
*
|
|
12
|
+
* @returns {TextMessage} The corresponding `TextMessage` object.
|
|
13
|
+
* @memberOf ITransportMessage
|
|
14
|
+
*/
|
|
15
|
+
toMessage(): TextMessage;
|
|
16
|
+
/**
|
|
17
|
+
* Serializes the message into a `Buffer` format. Optionally accepts a `TextMessage`
|
|
18
|
+
* if the conversion needs to be done on a different message.
|
|
19
|
+
*
|
|
20
|
+
* @param {TextMessage} [message] The `TextMessage` to convert into a `Buffer`.
|
|
21
|
+
* If not provided, defaults to the current `data`.
|
|
22
|
+
* @returns {Buffer} A `Buffer` containing the serialized message data.
|
|
23
|
+
* @memberOf ITransportMessage
|
|
24
|
+
*/
|
|
25
|
+
toBuffer(message?: TextMessage): Buffer;
|
|
26
|
+
/**
|
|
27
|
+
* A flag indicating whether the message contains binary data.
|
|
28
|
+
*
|
|
29
|
+
* @type {boolean}
|
|
30
|
+
* @memberOf ITransportMessage
|
|
31
|
+
*/
|
|
32
|
+
isBinary: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The raw data associated with the transport message. This can be in various formats
|
|
35
|
+
* such as strings, buffers, etc.
|
|
36
|
+
*
|
|
37
|
+
* @type {*}
|
|
38
|
+
* @memberOf ITransportMessage
|
|
39
|
+
*/
|
|
40
|
+
data: any;
|
|
41
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ITransportMessage } from '../Interfaces/ITransportMessage';
|
|
2
|
+
import { TextMessage } from './TextMessage';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class BufferMessage
|
|
8
|
+
* @implements {ITransportMessage}
|
|
9
|
+
*/
|
|
10
|
+
export declare class BufferMessage implements ITransportMessage {
|
|
11
|
+
data: Buffer;
|
|
12
|
+
isBinary: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of BufferMessage.
|
|
15
|
+
*
|
|
16
|
+
* @param {Buffer} data
|
|
17
|
+
* @param {boolean} isBinary
|
|
18
|
+
*
|
|
19
|
+
* @memberOf BufferMessage
|
|
20
|
+
*/
|
|
21
|
+
constructor(data: Buffer, isBinary: boolean);
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
*
|
|
25
|
+
* @returns {TextMessage}
|
|
26
|
+
*
|
|
27
|
+
* @memberOf BufferMessage
|
|
28
|
+
*/
|
|
29
|
+
toMessage(): TextMessage;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*
|
|
33
|
+
* @returns {Buffer}
|
|
34
|
+
*
|
|
35
|
+
* @memberOf BufferMessage
|
|
36
|
+
*/
|
|
37
|
+
toBuffer(): Buffer;
|
|
38
|
+
}
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BufferMessage = void 0;
|
|
3
4
|
const TextMessage_1 = require("./TextMessage");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @class BufferMessage
|
|
10
|
+
* @implements {ITransportMessage}
|
|
11
|
+
*/
|
|
4
12
|
class BufferMessage {
|
|
5
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of BufferMessage.
|
|
15
|
+
*
|
|
16
|
+
* @param {Buffer} data
|
|
17
|
+
* @param {boolean} isBinary
|
|
18
|
+
*
|
|
19
|
+
* @memberOf BufferMessage
|
|
20
|
+
*/
|
|
21
|
+
constructor(data, isBinary) {
|
|
6
22
|
this.data = data;
|
|
7
|
-
this.
|
|
23
|
+
this.isBinary = isBinary;
|
|
8
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
*
|
|
28
|
+
* @returns {TextMessage}
|
|
29
|
+
*
|
|
30
|
+
* @memberOf BufferMessage
|
|
31
|
+
*/
|
|
9
32
|
toMessage() {
|
|
10
33
|
const headerLen = 3;
|
|
11
34
|
const tLen = this.data.readUInt8(0);
|
|
@@ -20,6 +43,13 @@ class BufferMessage {
|
|
|
20
43
|
let message = new TextMessage_1.TextMessage(topic, data, controller);
|
|
21
44
|
return message;
|
|
22
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
*
|
|
49
|
+
* @returns {Buffer}
|
|
50
|
+
*
|
|
51
|
+
* @memberOf BufferMessage
|
|
52
|
+
*/
|
|
23
53
|
toBuffer() {
|
|
24
54
|
let message = JSON.parse(this.data.toString());
|
|
25
55
|
const header = 3;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an error message with a timestamp.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @class ErrorMessage
|
|
6
|
+
*/
|
|
7
|
+
export declare class ErrorMessage {
|
|
8
|
+
/**
|
|
9
|
+
* The error message content.
|
|
10
|
+
*
|
|
11
|
+
* @type {string}
|
|
12
|
+
* @memberof ErrorMessage
|
|
13
|
+
*/
|
|
14
|
+
message: string;
|
|
15
|
+
/**
|
|
16
|
+
* The timestamp when the error message was created.
|
|
17
|
+
*
|
|
18
|
+
* @type {Date}
|
|
19
|
+
* @memberof ErrorMessage
|
|
20
|
+
*/
|
|
21
|
+
timestamp: Date;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of the ErrorMessage class.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} message The error message content.
|
|
26
|
+
* @memberof ErrorMessage
|
|
27
|
+
*/
|
|
28
|
+
constructor(message: string);
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents an error message with a timestamp.
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class ErrorMessage
|
|
9
|
+
*/
|
|
10
|
+
class ErrorMessage {
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of the ErrorMessage class.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} message The error message content.
|
|
15
|
+
* @memberof ErrorMessage
|
|
16
|
+
*/
|
|
17
|
+
constructor(message) {
|
|
18
|
+
this.message = message;
|
|
19
|
+
this.timestamp = new Date();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ErrorMessage = ErrorMessage;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ITransportMessage } from '../Interfaces/ITransportMessage';
|
|
2
|
+
import { TextMessage } from './TextMessage';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a message transported via pipes, encapsulating a `TextMessage`.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class PipeMessage
|
|
8
|
+
* @implements {ITransportMessage}
|
|
9
|
+
*/
|
|
10
|
+
export declare class PipeMessage implements ITransportMessage {
|
|
11
|
+
data: any;
|
|
12
|
+
isBinary: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The encapsulated `TextMessage` instance.
|
|
15
|
+
*
|
|
16
|
+
* @private
|
|
17
|
+
* @type {TextMessage}
|
|
18
|
+
*/
|
|
19
|
+
private message;
|
|
20
|
+
/**
|
|
21
|
+
* Array representation of the message components for serialization.
|
|
22
|
+
*
|
|
23
|
+
* @private
|
|
24
|
+
* @type {Array<string>}
|
|
25
|
+
*/
|
|
26
|
+
private arr;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an instance of `PipeMessage`.
|
|
29
|
+
*
|
|
30
|
+
* @param {*} data - The raw data representing the message.
|
|
31
|
+
* @param {boolean} isBinary - Indicates if the data is in binary format.
|
|
32
|
+
*/
|
|
33
|
+
constructor(data: any, isBinary: boolean);
|
|
34
|
+
/**
|
|
35
|
+
* Serializes the `PipeMessage` to a `Buffer`.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Buffer} A buffer containing the serialized message data.
|
|
38
|
+
*/
|
|
39
|
+
toBuffer(): Buffer;
|
|
40
|
+
/**
|
|
41
|
+
* Converts the `PipeMessage` back to a `TextMessage` instance.
|
|
42
|
+
*
|
|
43
|
+
* @returns {TextMessage} The encapsulated `TextMessage`.
|
|
44
|
+
*/
|
|
45
|
+
toMessage(): TextMessage;
|
|
46
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PipeMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents a message transported via pipes, encapsulating a `TextMessage`.
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class PipeMessage
|
|
9
|
+
* @implements {ITransportMessage}
|
|
10
|
+
*/
|
|
11
|
+
class PipeMessage {
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of `PipeMessage`.
|
|
14
|
+
*
|
|
15
|
+
* @param {*} data - The raw data representing the message.
|
|
16
|
+
* @param {boolean} isBinary - Indicates if the data is in binary format.
|
|
17
|
+
*/
|
|
18
|
+
constructor(data, isBinary) {
|
|
19
|
+
this.data = data;
|
|
20
|
+
this.isBinary = isBinary;
|
|
21
|
+
this.message = JSON.parse(data);
|
|
22
|
+
this.arr = [this.message.C, this.message.T, this.message.D];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Serializes the `PipeMessage` to a `Buffer`.
|
|
26
|
+
*
|
|
27
|
+
* @returns {Buffer} A buffer containing the serialized message data.
|
|
28
|
+
*/
|
|
29
|
+
toBuffer() {
|
|
30
|
+
return Buffer.from(this.arr.join("|"), 'utf-8');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Converts the `PipeMessage` back to a `TextMessage` instance.
|
|
34
|
+
*
|
|
35
|
+
* @returns {TextMessage} The encapsulated `TextMessage`.
|
|
36
|
+
*/
|
|
37
|
+
toMessage() {
|
|
38
|
+
return this.message;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.PipeMessage = PipeMessage;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a text message with optional binary data.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @class TextMessage
|
|
6
|
+
*/
|
|
7
|
+
export declare class TextMessage {
|
|
8
|
+
/**
|
|
9
|
+
* Binary data associated with the message (if any).
|
|
10
|
+
*
|
|
11
|
+
* @type {Buffer | undefined}
|
|
12
|
+
*/
|
|
13
|
+
B: Buffer | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Topic of the message.
|
|
16
|
+
*
|
|
17
|
+
* @type {string}
|
|
18
|
+
*/
|
|
19
|
+
T: string;
|
|
20
|
+
/**
|
|
21
|
+
* Data payload of the message.
|
|
22
|
+
*
|
|
23
|
+
* @type {any}
|
|
24
|
+
*/
|
|
25
|
+
D: any;
|
|
26
|
+
/**
|
|
27
|
+
* Controller of the message.
|
|
28
|
+
*
|
|
29
|
+
* @type {string}
|
|
30
|
+
*/
|
|
31
|
+
C: string;
|
|
32
|
+
/**
|
|
33
|
+
* Indicates whether the message contains binary data.
|
|
34
|
+
*
|
|
35
|
+
* @type {boolean}
|
|
36
|
+
*/
|
|
37
|
+
isBinary: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Unique identifier for the message.
|
|
40
|
+
*
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
43
|
+
I: string;
|
|
44
|
+
/**
|
|
45
|
+
* Indicates if this is the final message in a sequence.
|
|
46
|
+
*
|
|
47
|
+
* @type {boolean}
|
|
48
|
+
*/
|
|
49
|
+
F: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the JSON representation of the message.
|
|
52
|
+
*
|
|
53
|
+
* @readonly
|
|
54
|
+
* @type {any}
|
|
55
|
+
*/
|
|
56
|
+
get JSON(): any;
|
|
57
|
+
/**
|
|
58
|
+
* Creates an instance of `TextMessage`.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} topic - Topic of the message.
|
|
61
|
+
* @param {any} data - Data payload of the message.
|
|
62
|
+
* @param {string} controller - Controller of the message.
|
|
63
|
+
* @param {Buffer} [arrayBuffer] - Optional binary data.
|
|
64
|
+
* @param {string} [uuid] - Optional unique identifier.
|
|
65
|
+
* @param {boolean} [isFinal] - Indicates if this is the final message in a sequence.
|
|
66
|
+
*/
|
|
67
|
+
constructor(topic: string, data: any, controller: string, arrayBuffer?: Buffer, uuid?: string, isFinal?: boolean);
|
|
68
|
+
/**
|
|
69
|
+
* Returns a string representation of the message.
|
|
70
|
+
*
|
|
71
|
+
* @returns {string} The JSON string representation of the message.
|
|
72
|
+
*/
|
|
73
|
+
toString(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a `TextMessage` instance from a `Buffer`.
|
|
76
|
+
*
|
|
77
|
+
* @static
|
|
78
|
+
* @param {Buffer} buffer - The buffer containing the message data.
|
|
79
|
+
* @returns {TextMessage} The parsed `TextMessage` instance.
|
|
80
|
+
*/
|
|
81
|
+
static fromArrayBuffer(buffer: Buffer): TextMessage;
|
|
82
|
+
/**
|
|
83
|
+
* Converts the `TextMessage` to a `Buffer`.
|
|
84
|
+
*
|
|
85
|
+
* @returns {Buffer} The buffer representation of the message.
|
|
86
|
+
*/
|
|
87
|
+
toArrayBuffer(): Buffer;
|
|
88
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextMessage = void 0;
|
|
4
|
+
const BufferUtils_1 = require("../Utils/BufferUtils");
|
|
5
|
+
const StringUtils_1 = require("../Utils/StringUtils");
|
|
6
|
+
/**
|
|
7
|
+
* Represents a text message with optional binary data.
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @class TextMessage
|
|
11
|
+
*/
|
|
12
|
+
class TextMessage {
|
|
13
|
+
/**
|
|
14
|
+
* Gets the JSON representation of the message.
|
|
15
|
+
*
|
|
16
|
+
* @readonly
|
|
17
|
+
* @type {any}
|
|
18
|
+
*/
|
|
19
|
+
get JSON() {
|
|
20
|
+
return {
|
|
21
|
+
T: this.T,
|
|
22
|
+
D: JSON.stringify(this.D),
|
|
23
|
+
C: this.C,
|
|
24
|
+
I: this.I,
|
|
25
|
+
F: this.F,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates an instance of `TextMessage`.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} topic - Topic of the message.
|
|
32
|
+
* @param {any} data - Data payload of the message.
|
|
33
|
+
* @param {string} controller - Controller of the message.
|
|
34
|
+
* @param {Buffer} [arrayBuffer] - Optional binary data.
|
|
35
|
+
* @param {string} [uuid] - Optional unique identifier.
|
|
36
|
+
* @param {boolean} [isFinal] - Indicates if this is the final message in a sequence.
|
|
37
|
+
*/
|
|
38
|
+
constructor(topic, data, controller, arrayBuffer, uuid, isFinal) {
|
|
39
|
+
/**
|
|
40
|
+
* Indicates whether the message contains binary data.
|
|
41
|
+
*
|
|
42
|
+
* @type {boolean}
|
|
43
|
+
*/
|
|
44
|
+
this.isBinary = false;
|
|
45
|
+
this.D = data;
|
|
46
|
+
this.T = topic;
|
|
47
|
+
this.C = controller;
|
|
48
|
+
this.B = arrayBuffer;
|
|
49
|
+
this.I = uuid || StringUtils_1.StringUtils.newGuid();
|
|
50
|
+
this.F = isFinal !== null && isFinal !== void 0 ? isFinal : true; // Default to true if not provided
|
|
51
|
+
if (arrayBuffer) {
|
|
52
|
+
this.isBinary = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns a string representation of the message.
|
|
57
|
+
*
|
|
58
|
+
* @returns {string} The JSON string representation of the message.
|
|
59
|
+
*/
|
|
60
|
+
toString() {
|
|
61
|
+
return JSON.stringify(this.JSON);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a `TextMessage` instance from a `Buffer`.
|
|
65
|
+
*
|
|
66
|
+
* @static
|
|
67
|
+
* @param {Buffer} buffer - The buffer containing the message data.
|
|
68
|
+
* @returns {TextMessage} The parsed `TextMessage` instance.
|
|
69
|
+
*/
|
|
70
|
+
static fromArrayBuffer(buffer) {
|
|
71
|
+
const headerLen = 8;
|
|
72
|
+
const header = buffer.slice(0, headerLen);
|
|
73
|
+
const payloadLength = BufferUtils_1.BufferUtils.arrayToLong(header);
|
|
74
|
+
const message = buffer.slice(headerLen, payloadLength + headerLen);
|
|
75
|
+
const blobOffset = headerLen + payloadLength;
|
|
76
|
+
const blob = buffer.slice(blobOffset, buffer.byteLength);
|
|
77
|
+
const data = JSON.parse(message.toString());
|
|
78
|
+
return new TextMessage(data.T, data.D, data.C, blob, data.I, data.F);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Converts the `TextMessage` to a `Buffer`.
|
|
82
|
+
*
|
|
83
|
+
* @returns {Buffer} The buffer representation of the message.
|
|
84
|
+
*/
|
|
85
|
+
toArrayBuffer() {
|
|
86
|
+
const messagePayload = this.toString();
|
|
87
|
+
const payloadLength = messagePayload.length;
|
|
88
|
+
const header = Buffer.from(BufferUtils_1.BufferUtils.longToArray(payloadLength));
|
|
89
|
+
const message = Buffer.from(messagePayload, 'utf-8');
|
|
90
|
+
const blob = this.B ? Buffer.from(this.B) : Buffer.alloc(0);
|
|
91
|
+
return Buffer.concat([header, message, blob]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.TextMessage = TextMessage;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ITransportMessage } from '../Interfaces/ITransportMessage';
|
|
2
|
+
import { TextMessage } from './TextMessage';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a WebSocket message, encapsulating data and its type (binary or text).
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class WebSocketMessage
|
|
8
|
+
* @implements {ITransportMessage}
|
|
9
|
+
*/
|
|
10
|
+
export declare class WebSocketMessage implements ITransportMessage {
|
|
11
|
+
data: string;
|
|
12
|
+
isBinary: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of `WebSocketMessage`.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} data - The raw message data as a string.
|
|
17
|
+
* @param {boolean} isBinary - Indicates whether the message is binary.
|
|
18
|
+
*/
|
|
19
|
+
constructor(data: string, isBinary: boolean);
|
|
20
|
+
/**
|
|
21
|
+
* Converts the message to a `Buffer` object.
|
|
22
|
+
* **Note:** This method is not yet implemented.
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error} Throws an error indicating that the method is not implemented.
|
|
25
|
+
* @returns {Buffer}
|
|
26
|
+
*/
|
|
27
|
+
toBuffer(): Buffer;
|
|
28
|
+
/**
|
|
29
|
+
* Parses the raw string data and converts it into a `TextMessage` instance.
|
|
30
|
+
*
|
|
31
|
+
* @returns {TextMessage} The parsed `TextMessage` object.
|
|
32
|
+
*/
|
|
33
|
+
toMessage(): TextMessage;
|
|
34
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketMessage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents a WebSocket message, encapsulating data and its type (binary or text).
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class WebSocketMessage
|
|
9
|
+
* @implements {ITransportMessage}
|
|
10
|
+
*/
|
|
11
|
+
class WebSocketMessage {
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of `WebSocketMessage`.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} data - The raw message data as a string.
|
|
16
|
+
* @param {boolean} isBinary - Indicates whether the message is binary.
|
|
17
|
+
*/
|
|
18
|
+
constructor(data, isBinary) {
|
|
19
|
+
this.data = data;
|
|
20
|
+
this.isBinary = isBinary;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Converts the message to a `Buffer` object.
|
|
24
|
+
* **Note:** This method is not yet implemented.
|
|
25
|
+
*
|
|
26
|
+
* @throws {Error} Throws an error indicating that the method is not implemented.
|
|
27
|
+
* @returns {Buffer}
|
|
28
|
+
*/
|
|
29
|
+
toBuffer() {
|
|
30
|
+
throw new Error("toBuffer is not yet implemented");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parses the raw string data and converts it into a `TextMessage` instance.
|
|
34
|
+
*
|
|
35
|
+
* @returns {TextMessage} The parsed `TextMessage` object.
|
|
36
|
+
*/
|
|
37
|
+
toMessage() {
|
|
38
|
+
return JSON.parse(this.data);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.WebSocketMessage = WebSocketMessage;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Plugin = void 0;
|
|
4
|
+
const StringUtils_1 = require("./Utils/StringUtils");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a plugin with a specific type.
|
|
7
|
+
* @template T The type of the plugin instance.
|
|
8
|
+
*/
|
|
9
|
+
class Plugin {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of Plugin.
|
|
12
|
+
* @param {T} object The plugin instance.
|
|
13
|
+
*/
|
|
14
|
+
constructor(object) {
|
|
15
|
+
this.id = StringUtils_1.StringUtils.newGuid();
|
|
16
|
+
this.alias = Reflect.getMetadata("alias", object);
|
|
17
|
+
this.instance = object;
|
|
18
|
+
const metaData = Reflect.getMetadataKeys(object);
|
|
19
|
+
metaData.forEach(metaDataKey => {
|
|
20
|
+
console.info(`Controller settings ${metaDataKey} = `, Reflect.getOwnMetadata(metaDataKey, object));
|
|
21
|
+
});
|
|
22
|
+
console.info(`Created the plugin with an id of ${this.id}`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets the instance of the plugin.
|
|
26
|
+
* @returns {T} The plugin instance.
|
|
27
|
+
*/
|
|
28
|
+
getInstance() {
|
|
29
|
+
return this.instance;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Plugin = Plugin;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes the structure of a plugin descriptor.
|
|
3
|
+
*/
|
|
4
|
+
export interface PluginDescriptor {
|
|
5
|
+
name: string;
|
|
6
|
+
methods: string[];
|
|
7
|
+
properties: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Represents a plugin with a specific type.
|
|
11
|
+
* @template T The type of the plugin instance.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Plugin<T extends Object> {
|
|
14
|
+
/**
|
|
15
|
+
* The alias of the plugin.
|
|
16
|
+
*/
|
|
17
|
+
alias: string;
|
|
18
|
+
/**
|
|
19
|
+
* The instance of the plugin.
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
private instance;
|
|
23
|
+
/**
|
|
24
|
+
* The unique identifier of the plugin.
|
|
25
|
+
*/
|
|
26
|
+
id: string;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an instance of Plugin.
|
|
29
|
+
* @param {T} object The plugin instance.
|
|
30
|
+
*/
|
|
31
|
+
constructor(object: T);
|
|
32
|
+
/**
|
|
33
|
+
* Gets the instance of the plugin.
|
|
34
|
+
* @returns {T} The plugin instance.
|
|
35
|
+
*/
|
|
36
|
+
getInstance(): T;
|
|
37
|
+
}
|