thor-io.vnext 2.0.5-beta.3 → 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.
Files changed (185) hide show
  1. package/.gitattributes +17 -17
  2. package/build/index.d.ts +24 -0
  3. package/build/index.js +47 -0
  4. package/build/src/Connection/ClientInfo.d.ts +27 -0
  5. package/{src/Client → build/src/Connection}/ClientInfo.js +7 -0
  6. package/build/src/Connection/Connection.d.ts +117 -0
  7. package/build/src/Connection/Connection.js +202 -0
  8. package/build/src/Connection/IClientInfo.d.ts +20 -0
  9. package/build/src/Controller/ControllerBase.d.ts +134 -0
  10. package/build/src/Controller/ControllerBase.js +543 -0
  11. package/build/src/Controller/Subscription.d.ts +27 -0
  12. package/build/src/Controller/Subscription.js +22 -0
  13. package/build/src/Controllers/BrokerController/Broker.js +145 -0
  14. package/build/src/Controllers/BrokerController/BrokerController.d.ts +61 -0
  15. package/build/src/Controllers/BrokerController/BrokerController.js +115 -0
  16. package/{src/Controllers/BrokerController/Broker.js → build/src/Controllers/BrokerController/BrokerrController.js} +74 -85
  17. package/build/src/Controllers/BrokerController/Models/PeerConnection.d.ts +7 -0
  18. package/build/src/Controllers/BrokerController/Models/PeerConnection.js +14 -0
  19. package/build/src/Controllers/BrokerController/Models/Signal.js +11 -0
  20. package/build/src/Decorators/CanInvoke.d.ts +10 -0
  21. package/build/src/Decorators/CanInvoke.js +22 -0
  22. package/build/src/Decorators/CanSet.d.ts +10 -0
  23. package/build/src/Decorators/CanSet.js +20 -0
  24. package/build/src/Decorators/ControllerProperties.d.ts +10 -0
  25. package/build/src/Decorators/ControllerProperties.js +20 -0
  26. package/{src/Controllers/BrokerController/Models/InstantMessage.js → build/src/Interfaces/IInterceptor.js} +2 -5
  27. package/build/src/Interfaces/ITransport.d.ts +94 -0
  28. package/build/src/Interfaces/ITransportMessage.d.ts +41 -0
  29. package/build/src/Messages/BufferMessage.d.ts +38 -0
  30. package/{src → build/src}/Messages/BufferMessage.js +32 -2
  31. package/build/src/Messages/ErrorMessage.d.ts +29 -0
  32. package/build/src/Messages/ErrorMessage.js +22 -0
  33. package/build/src/Messages/PipeMessage.d.ts +46 -0
  34. package/build/src/Messages/PipeMessage.js +41 -0
  35. package/build/src/Messages/TextMessage.d.ts +88 -0
  36. package/build/src/Messages/TextMessage.js +94 -0
  37. package/build/src/Messages/WebSocketMessage.d.ts +34 -0
  38. package/build/src/Messages/WebSocketMessage.js +41 -0
  39. package/build/src/Plugin.js +32 -0
  40. package/build/src/Server/Plugin.d.ts +37 -0
  41. package/build/src/Server/Plugin.js +32 -0
  42. package/build/src/Server/ThorIOServer.d.ts +68 -0
  43. package/build/src/Server/ThorIOServer.js +131 -0
  44. package/build/src/Subscription.js +22 -0
  45. package/build/src/ThorIO.js +142 -0
  46. package/build/src/ThorIOServer.d.ts +64 -0
  47. package/build/src/ThorIOServer.js +131 -0
  48. package/build/src/Transports/BufferMessageTransport.d.ts +78 -0
  49. package/build/src/Transports/BufferMessageTransport.js +85 -0
  50. package/build/src/Transports/PipeMessageTransport.d.ts +79 -0
  51. package/build/src/Transports/PipeMessageTransport.js +90 -0
  52. package/build/src/Transports/WebSocketMessageTransport.d.ts +87 -0
  53. package/build/src/Transports/WebSocketMessageTransport.js +93 -0
  54. package/build/src/Utils/BufferUtils.d.ts +32 -0
  55. package/build/src/Utils/BufferUtils.js +57 -0
  56. package/build/src/Utils/StringUtils.d.ts +15 -0
  57. package/build/src/Utils/StringUtils.js +31 -0
  58. package/build/src/test.js +5 -0
  59. package/docs/.nojekyll +1 -0
  60. package/docs/assets/hierarchy.js +1 -0
  61. package/docs/assets/highlight.css +43 -0
  62. package/docs/assets/icons.js +18 -0
  63. package/docs/assets/icons.svg +1 -0
  64. package/docs/assets/main.js +60 -0
  65. package/docs/assets/navigation.js +1 -0
  66. package/docs/assets/search.js +1 -0
  67. package/docs/assets/style.css +1610 -0
  68. package/docs/classes/BrokerController.html +164 -0
  69. package/docs/classes/BufferMessage.html +11 -0
  70. package/docs/classes/BufferMessageTransport.html +31 -0
  71. package/docs/classes/BufferUtils.html +16 -0
  72. package/docs/classes/ClientInfo.html +11 -0
  73. package/docs/classes/Connection.html +42 -0
  74. package/docs/classes/ControllerBase.html +144 -0
  75. package/docs/classes/ErrorMessage.html +13 -0
  76. package/docs/classes/PeerConnection.html +4 -0
  77. package/docs/classes/PipeMessage.html +17 -0
  78. package/docs/classes/PipeMessageTransport.html +33 -0
  79. package/docs/classes/Plugin.html +13 -0
  80. package/docs/classes/Signal.html +5 -0
  81. package/docs/classes/StringUtils.html +9 -0
  82. package/docs/classes/Subscription.html +11 -0
  83. package/docs/classes/TextMessage.html +37 -0
  84. package/docs/classes/ThorIOServer.html +25 -0
  85. package/docs/classes/WebSocketMessage.html +18 -0
  86. package/docs/classes/WebSocketMessageTransport.html +35 -0
  87. package/docs/functions/CanInvoke.html +5 -0
  88. package/docs/functions/CanSet.html +5 -0
  89. package/docs/functions/ControllerProperties.html +5 -0
  90. package/docs/hierarchy.html +1 -0
  91. package/docs/index.html +24 -0
  92. package/docs/interfaces/ITransport.html +46 -0
  93. package/docs/interfaces/ITransportMessage.html +21 -0
  94. package/docs/modules.html +1 -0
  95. package/index.ts +32 -37
  96. package/licence +21 -21
  97. package/package.json +48 -50
  98. package/readme.md +32 -1
  99. package/src/{Client → Connection}/ClientInfo.ts +34 -43
  100. package/src/Connection/Connection.ts +229 -0
  101. package/src/Connection/IClientInfo.ts +22 -0
  102. package/src/Controller/ControllerBase.ts +561 -457
  103. package/src/{Subscription.ts → Controller/Subscription.ts} +32 -34
  104. package/src/Controllers/BrokerController/BrokerController.ts +121 -0
  105. package/src/Controllers/BrokerController/Models/PeerConnection.ts +12 -34
  106. package/src/Controllers/BrokerController/Models/Signal.ts +11 -43
  107. package/src/Decorators/CanInvoke.ts +21 -13
  108. package/src/Decorators/CanSet.ts +19 -12
  109. package/src/Decorators/ControllerProperties.ts +19 -16
  110. package/src/Interfaces/ITransport.ts +107 -23
  111. package/src/Interfaces/ITransportMessage.ts +45 -41
  112. package/src/Messages/BufferMessage.ts +70 -69
  113. package/src/Messages/ErrorMessage.ts +34 -6
  114. package/src/Messages/PipeMessage.ts +56 -62
  115. package/src/Messages/TextMessage.ts +139 -93
  116. package/src/Messages/WebSocketMessage.ts +39 -41
  117. package/src/Server/Plugin.ts +56 -0
  118. package/src/Server/ThorIOServer.ts +121 -0
  119. package/src/ThorIOServer.ts +117 -0
  120. package/src/Transports/BufferMessageTransport.ts +109 -100
  121. package/src/Transports/PipeMessageTransport.ts +112 -104
  122. package/src/Transports/WebSocketMessageTransport.ts +122 -110
  123. package/src/Utils/BufferUtils.ts +55 -61
  124. package/src/Utils/StringUtils.ts +28 -17
  125. package/tsconfig.json +109 -19
  126. package/typedoc.json +6 -0
  127. package/index.d.ts +0 -24
  128. package/index.js +0 -46
  129. package/src/Client/ClientInfo.d.ts +0 -6
  130. package/src/Connection.d.ts +0 -24
  131. package/src/Connection.js +0 -121
  132. package/src/Connection.ts +0 -263
  133. package/src/Controller/ControllerBase.d.ts +0 -43
  134. package/src/Controller/ControllerBase.js +0 -331
  135. package/src/Controllers/BrokerController/Broker.d.ts +0 -21
  136. package/src/Controllers/BrokerController/Broker.ts +0 -153
  137. package/src/Controllers/BrokerController/Models/InstantMessage.d.ts +0 -3
  138. package/src/Controllers/BrokerController/Models/InstantMessage.ts +0 -15
  139. package/src/Controllers/BrokerController/Models/PeerConnection.d.ts +0 -5
  140. package/src/Controllers/BrokerController/Models/PeerConnection.js +0 -9
  141. package/src/Controllers/BrokerController/Models/Signal.js +0 -10
  142. package/src/Decorators/CanInvoke.d.ts +0 -2
  143. package/src/Decorators/CanInvoke.js +0 -9
  144. package/src/Decorators/CanSet.d.ts +0 -1
  145. package/src/Decorators/CanSet.js +0 -8
  146. package/src/Decorators/ControllerProperties.d.ts +0 -1
  147. package/src/Decorators/ControllerProperties.js +0 -10
  148. package/src/Interfaces/IInterceptor.d.ts +0 -2
  149. package/src/Interfaces/IInterceptor.ts +0 -2
  150. package/src/Interfaces/ITransport.d.ts +0 -18
  151. package/src/Interfaces/ITransportMessage.d.ts +0 -8
  152. package/src/Listener.d.ts +0 -5
  153. package/src/Listener.js +0 -9
  154. package/src/Listener.ts +0 -34
  155. package/src/Messages/BufferMessage.d.ts +0 -10
  156. package/src/Messages/ErrorMessage.d.ts +0 -4
  157. package/src/Messages/ErrorMessage.js +0 -8
  158. package/src/Messages/PipeMessage.d.ts +0 -12
  159. package/src/Messages/PipeMessage.js +0 -20
  160. package/src/Messages/TextMessage.d.ts +0 -15
  161. package/src/Messages/TextMessage.js +0 -50
  162. package/src/Messages/WebSocketMessage.d.ts +0 -10
  163. package/src/Messages/WebSocketMessage.js +0 -15
  164. package/src/Plugin.d.ts +0 -6
  165. package/src/Plugin.js +0 -11
  166. package/src/Plugin.ts +0 -37
  167. package/src/Subscription.d.ts +0 -5
  168. package/src/Subscription.js +0 -9
  169. package/src/ThorIO.d.ts +0 -18
  170. package/src/ThorIO.js +0 -65
  171. package/src/ThorIO.ts +0 -148
  172. package/src/Transports/BufferMessageTransport.d.ts +0 -21
  173. package/src/Transports/BufferMessageTransport.js +0 -31
  174. package/src/Transports/PipeMessageTransport.d.ts +0 -20
  175. package/src/Transports/PipeMessageTransport.js +0 -33
  176. package/src/Transports/WebSocketMessageTransport.d.ts +0 -20
  177. package/src/Transports/WebSocketMessageTransport.js +0 -31
  178. package/src/Utils/BufferUtils.d.ts +0 -5
  179. package/src/Utils/BufferUtils.js +0 -29
  180. package/src/Utils/StringUtils.d.ts +0 -4
  181. package/src/Utils/StringUtils.js +0 -13
  182. /package/{src/Interfaces/IInterceptor.js → build/src/Connection/IClientInfo.js} +0 -0
  183. /package/{src → build/src}/Controllers/BrokerController/Models/Signal.d.ts +0 -0
  184. /package/{src → build/src}/Interfaces/ITransport.js +0 -0
  185. /package/{src → build/src}/Interfaces/ITransportMessage.js +0 -0
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferMessageTransport = void 0;
4
+ const BufferMessage_1 = require("../Messages/BufferMessage");
5
+ const StringUtils_1 = require("../Utils/StringUtils");
6
+ /**
7
+ * A transport implementation for handling buffer-based messages over a socket.
8
+ *
9
+ * @export
10
+ * @class BufferMessageTransport
11
+ * @implements {ITransport}
12
+ */
13
+ class BufferMessageTransport {
14
+ /**
15
+ * The underlying socket used for communication.
16
+ *
17
+ * @type {net.Socket}
18
+ */
19
+ constructor(socket) {
20
+ this.socket = socket;
21
+ /**
22
+ * Event handler for receiving transport messages.
23
+ *
24
+ * @type {(message: ITransportMessage) => void}
25
+ */
26
+ this.onMessage = (message) => { };
27
+ /**
28
+ * Event handler for when the transport connection is closed.
29
+ *
30
+ * @type {() => void}
31
+ */
32
+ this.onClose = () => { };
33
+ /**
34
+ * Event handler for when the transport connection is opened.
35
+ *
36
+ * @type {() => void}
37
+ */
38
+ this.onOpen = () => { };
39
+ this.id = StringUtils_1.StringUtils.newGuid();
40
+ this.socket.addListener("data", (buffer) => {
41
+ const bm = new BufferMessage_1.BufferMessage(buffer, false);
42
+ this.onMessage(bm);
43
+ });
44
+ }
45
+ /**
46
+ * The ready state of the transport connection.
47
+ *
48
+ * @readonly
49
+ * @type {number}
50
+ */
51
+ get readyState() {
52
+ return 1; // Open
53
+ }
54
+ /**
55
+ * Sends a string message over the transport.
56
+ *
57
+ * @param {string} data - The message to send.
58
+ */
59
+ send(data) {
60
+ const bm = new BufferMessage_1.BufferMessage(Buffer.from(data), false);
61
+ this.socket.write(bm.toBuffer());
62
+ }
63
+ /**
64
+ * Adds an event listener to the underlying socket.
65
+ *
66
+ * @param {string} name - The name of the event.
67
+ * @param {Function} fn - The callback function to invoke when the event occurs.
68
+ */
69
+ addEventListener(name, fn) {
70
+ this.socket.addListener(name, fn);
71
+ }
72
+ /**
73
+ * Sends a ping message (no-op for this transport).
74
+ */
75
+ ping() {
76
+ return;
77
+ }
78
+ /**
79
+ * Closes the transport connection and destroys the socket.
80
+ */
81
+ close() {
82
+ this.socket.destroy();
83
+ }
84
+ }
85
+ exports.BufferMessageTransport = BufferMessageTransport;
@@ -0,0 +1,79 @@
1
+ import * as net from 'net';
2
+ import { ITransport } from '../Interfaces/ITransport';
3
+ /**
4
+ * A transport implementation for handling pipe-based messages over a socket.
5
+ *
6
+ * @export
7
+ * @class PipeMessageTransport
8
+ * @implements {ITransport}
9
+ */
10
+ export declare class PipeMessageTransport implements ITransport {
11
+ socket: net.Socket;
12
+ /**
13
+ * Unique identifier for this transport instance.
14
+ *
15
+ * @type {string}
16
+ */
17
+ id: string;
18
+ /**
19
+ * Event handler for receiving transport messages.
20
+ *
21
+ * @type {(message: any) => void}
22
+ */
23
+ onMessage: (message: any) => void;
24
+ /**
25
+ * Sends data over the transport.
26
+ *
27
+ * @param {any} data - The data to send.
28
+ */
29
+ send(data: any): void;
30
+ /**
31
+ * Closes the transport connection and destroys the socket.
32
+ *
33
+ * @param {number} reason - The reason code for closing the connection.
34
+ * @param {any} message - An optional message describing the closure.
35
+ */
36
+ close(reason: number, message: any): void;
37
+ /**
38
+ * Adds an event listener to the underlying socket.
39
+ *
40
+ * @param {string} name - The name of the event.
41
+ * @param {Function} fn - The callback function to invoke when the event occurs.
42
+ */
43
+ addEventListener(name: string, fn: any): void;
44
+ /**
45
+ * The ready state of the transport connection.
46
+ *
47
+ * @readonly
48
+ * @type {number}
49
+ */
50
+ get readyState(): number;
51
+ /**
52
+ * Sends a ping message (no-op for this transport).
53
+ */
54
+ ping(): void;
55
+ /**
56
+ * Creates an instance of PipeMessageTransport.
57
+ *
58
+ * @param {net.Socket} socket - The underlying socket used for communication.
59
+ */
60
+ constructor(socket: net.Socket);
61
+ /**
62
+ * The incoming request associated with the transport (if any).
63
+ *
64
+ * @type {any}
65
+ */
66
+ request: any;
67
+ /**
68
+ * Event handler for when the transport connection is closed.
69
+ *
70
+ * @type {() => void}
71
+ */
72
+ onClose: () => void;
73
+ /**
74
+ * Event handler for when the transport connection is opened.
75
+ *
76
+ * @type {() => void}
77
+ */
78
+ onOpen: () => void;
79
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PipeMessageTransport = void 0;
4
+ const PipeMessage_1 = require("../Messages/PipeMessage");
5
+ const TextMessage_1 = require("../Messages/TextMessage");
6
+ const StringUtils_1 = require("../Utils/StringUtils");
7
+ /**
8
+ * A transport implementation for handling pipe-based messages over a socket.
9
+ *
10
+ * @export
11
+ * @class PipeMessageTransport
12
+ * @implements {ITransport}
13
+ */
14
+ class PipeMessageTransport {
15
+ /**
16
+ * Sends data over the transport.
17
+ *
18
+ * @param {any} data - The data to send.
19
+ */
20
+ send(data) {
21
+ const message = new PipeMessage_1.PipeMessage(data, false);
22
+ this.socket.write(message.toBuffer());
23
+ }
24
+ /**
25
+ * Closes the transport connection and destroys the socket.
26
+ *
27
+ * @param {number} reason - The reason code for closing the connection.
28
+ * @param {any} message - An optional message describing the closure.
29
+ */
30
+ close(reason, message) {
31
+ this.socket.destroy();
32
+ }
33
+ /**
34
+ * Adds an event listener to the underlying socket.
35
+ *
36
+ * @param {string} name - The name of the event.
37
+ * @param {Function} fn - The callback function to invoke when the event occurs.
38
+ */
39
+ addEventListener(name, fn) {
40
+ this.socket.addListener(name, fn);
41
+ }
42
+ /**
43
+ * The ready state of the transport connection.
44
+ *
45
+ * @readonly
46
+ * @type {number}
47
+ */
48
+ get readyState() {
49
+ return 1; // Open
50
+ }
51
+ /**
52
+ * Sends a ping message (no-op for this transport).
53
+ */
54
+ ping() {
55
+ return;
56
+ }
57
+ /**
58
+ * Creates an instance of PipeMessageTransport.
59
+ *
60
+ * @param {net.Socket} socket - The underlying socket used for communication.
61
+ */
62
+ constructor(socket) {
63
+ this.socket = socket;
64
+ /**
65
+ * Event handler for receiving transport messages.
66
+ *
67
+ * @type {(message: any) => void}
68
+ */
69
+ this.onMessage = () => { };
70
+ /**
71
+ * Event handler for when the transport connection is closed.
72
+ *
73
+ * @type {() => void}
74
+ */
75
+ this.onClose = () => { };
76
+ /**
77
+ * Event handler for when the transport connection is opened.
78
+ *
79
+ * @type {() => void}
80
+ */
81
+ this.onOpen = () => { };
82
+ this.id = StringUtils_1.StringUtils.newGuid();
83
+ socket.addListener("data", (buffer) => {
84
+ const args = buffer.toString().split("|");
85
+ const message = new TextMessage_1.TextMessage(args[1], args[2], args[0]);
86
+ this.onMessage(new PipeMessage_1.PipeMessage(message.toString(), false));
87
+ });
88
+ }
89
+ }
90
+ exports.PipeMessageTransport = PipeMessageTransport;
@@ -0,0 +1,87 @@
1
+ import { IncomingMessage } from 'http';
2
+ import { ITransport } from '../Interfaces/ITransport';
3
+ import { ITransportMessage } from '../Interfaces/ITransportMessage';
4
+ /**
5
+ * A transport class for handling WebSocket communication and converting messages
6
+ * to/from the `WebSocketMessage` format.
7
+ *
8
+ * @export
9
+ * @class WebSocketMessageTransport
10
+ * @implements {ITransport}
11
+ */
12
+ export declare class WebSocketMessageTransport implements ITransport {
13
+ /**
14
+ * The HTTP request associated with the WebSocket connection.
15
+ *
16
+ * @type {IncomingMessage | Request}
17
+ */
18
+ request: IncomingMessage | Request;
19
+ /**
20
+ * The WebSocket instance used for communication.
21
+ *
22
+ * @type {WebSocket}
23
+ */
24
+ socket: WebSocket;
25
+ /**
26
+ * Callback for handling incoming messages. Defaults to creating a `WebSocketMessage`.
27
+ *
28
+ * @type {(message: ITransportMessage) => void}
29
+ */
30
+ onMessage: (message: ITransportMessage) => void;
31
+ /**
32
+ * Sends data through the WebSocket connection.
33
+ *
34
+ * @param {any} data - The data to be sent.
35
+ */
36
+ send(data: any): void;
37
+ /**
38
+ * Closes the WebSocket connection.
39
+ *
40
+ * @param {number} reason - The reason code for closing the connection.
41
+ * @param {string} message - Optional message providing details about the closure.
42
+ */
43
+ close(reason: number, message: string): void;
44
+ /**
45
+ * Adds an event listener to the WebSocket instance.
46
+ *
47
+ * @param {string} name - The event name.
48
+ * @param {Function} fn - The callback function to execute when the event occurs.
49
+ */
50
+ addEventListener(name: string, fn: any): void;
51
+ /**
52
+ * Creates an instance of `WebSocketMessageTransport`.
53
+ *
54
+ * @param {WebSocket} socket - The WebSocket object to use for communication.
55
+ * @param {IncomingMessage} req - The initial HTTP request associated with the connection.
56
+ */
57
+ constructor(socket: WebSocket, req: IncomingMessage);
58
+ /**
59
+ * Unique identifier for this transport instance.
60
+ *
61
+ * @type {string}
62
+ */
63
+ id: string;
64
+ /**
65
+ * Callback for handling the WebSocket `close` event.
66
+ *
67
+ * @type {(ev: CloseEvent) => void}
68
+ */
69
+ onClose: (ev: CloseEvent) => void;
70
+ /**
71
+ * Callback for handling the WebSocket `open` event.
72
+ *
73
+ * @type {(ev: Event) => void}
74
+ */
75
+ onOpen: (ev: Event) => void;
76
+ /**
77
+ * The current ready state of the WebSocket connection.
78
+ *
79
+ * @readonly
80
+ * @type {number}
81
+ */
82
+ get readyState(): number;
83
+ /**
84
+ * Sends a ping message to maintain the connection or test latency.
85
+ */
86
+ ping(): void;
87
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebSocketMessageTransport = void 0;
4
+ const WebSocketMessage_1 = require("../Messages/WebSocketMessage");
5
+ const StringUtils_1 = require("../Utils/StringUtils");
6
+ /**
7
+ * A transport class for handling WebSocket communication and converting messages
8
+ * to/from the `WebSocketMessage` format.
9
+ *
10
+ * @export
11
+ * @class WebSocketMessageTransport
12
+ * @implements {ITransport}
13
+ */
14
+ class WebSocketMessageTransport {
15
+ /**
16
+ * Sends data through the WebSocket connection.
17
+ *
18
+ * @param {any} data - The data to be sent.
19
+ */
20
+ send(data) {
21
+ this.socket.send(data);
22
+ }
23
+ /**
24
+ * Closes the WebSocket connection.
25
+ *
26
+ * @param {number} reason - The reason code for closing the connection.
27
+ * @param {string} message - Optional message providing details about the closure.
28
+ */
29
+ close(reason, message) {
30
+ this.socket.close(reason, message);
31
+ }
32
+ /**
33
+ * Adds an event listener to the WebSocket instance.
34
+ *
35
+ * @param {string} name - The event name.
36
+ * @param {Function} fn - The callback function to execute when the event occurs.
37
+ */
38
+ addEventListener(name, fn) {
39
+ this.socket.addEventListener(name, fn);
40
+ }
41
+ /**
42
+ * Creates an instance of `WebSocketMessageTransport`.
43
+ *
44
+ * @param {WebSocket} socket - The WebSocket object to use for communication.
45
+ * @param {IncomingMessage} req - The initial HTTP request associated with the connection.
46
+ */
47
+ constructor(socket, req) {
48
+ /**
49
+ * Callback for handling incoming messages. Defaults to creating a `WebSocketMessage`.
50
+ *
51
+ * @type {(message: ITransportMessage) => void}
52
+ */
53
+ this.onMessage = (message) => {
54
+ // Default implementation
55
+ };
56
+ /**
57
+ * Callback for handling the WebSocket `close` event.
58
+ *
59
+ * @type {(ev: CloseEvent) => void}
60
+ */
61
+ this.onClose = (ev) => { };
62
+ /**
63
+ * Callback for handling the WebSocket `open` event.
64
+ *
65
+ * @type {(ev: Event) => void}
66
+ */
67
+ this.onOpen = (ev) => { };
68
+ this.id = StringUtils_1.StringUtils.newGuid();
69
+ this.request = req;
70
+ this.socket = socket;
71
+ this.socket.addEventListener("message", (event) => {
72
+ this.onMessage(new WebSocketMessage_1.WebSocketMessage(event.data, typeof event.data !== "string"));
73
+ });
74
+ }
75
+ /**
76
+ * The current ready state of the WebSocket connection.
77
+ *
78
+ * @readonly
79
+ * @type {number}
80
+ */
81
+ get readyState() {
82
+ return this.socket.readyState;
83
+ }
84
+ /**
85
+ * Sends a ping message to maintain the connection or test latency.
86
+ */
87
+ ping() {
88
+ var _a, _b;
89
+ // Assumes the WebSocket implementation supports ping.
90
+ (_b = (_a = this.socket).ping) === null || _b === void 0 ? void 0 : _b.call(_a);
91
+ }
92
+ }
93
+ exports.WebSocketMessageTransport = WebSocketMessageTransport;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Utility class for buffer and binary operations.
3
+ *
4
+ * @export
5
+ * @class BufferUtils
6
+ */
7
+ export declare class BufferUtils {
8
+ /**
9
+ * Converts a string into a `Uint8Array` buffer.
10
+ *
11
+ * @static
12
+ * @param {string} str - The input string to convert.
13
+ * @returns {Uint8Array} The resulting buffer as a `Uint8Array`.
14
+ */
15
+ static stringToBuffer(str: string): Uint8Array;
16
+ /**
17
+ * Converts a `Uint8Array` to a long integer.
18
+ *
19
+ * @static
20
+ * @param {Uint8Array} byteArray - The input byte array.
21
+ * @returns {number} The resulting long integer.
22
+ */
23
+ static arrayToLong(byteArray: Uint8Array): number;
24
+ /**
25
+ * Converts a long integer to an array of bytes.
26
+ *
27
+ * @static
28
+ * @param {number} long - The long integer to convert.
29
+ * @returns {Array<number>} The resulting array of bytes.
30
+ */
31
+ static longToArray(long: number): Array<number>;
32
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferUtils = void 0;
4
+ /**
5
+ * Utility class for buffer and binary operations.
6
+ *
7
+ * @export
8
+ * @class BufferUtils
9
+ */
10
+ class BufferUtils {
11
+ /**
12
+ * Converts a string into a `Uint8Array` buffer.
13
+ *
14
+ * @static
15
+ * @param {string} str - The input string to convert.
16
+ * @returns {Uint8Array} The resulting buffer as a `Uint8Array`.
17
+ */
18
+ static stringToBuffer(str) {
19
+ let len = str.length;
20
+ let arr = new Array(len);
21
+ for (let i = 0; i < len; i++) {
22
+ arr[i] = str.charCodeAt(i) & 0xFF;
23
+ }
24
+ return new Uint8Array(arr);
25
+ }
26
+ /**
27
+ * Converts a `Uint8Array` to a long integer.
28
+ *
29
+ * @static
30
+ * @param {Uint8Array} byteArray - The input byte array.
31
+ * @returns {number} The resulting long integer.
32
+ */
33
+ static arrayToLong(byteArray) {
34
+ let value = 0;
35
+ for (let i = byteArray.byteLength - 1; i >= 0; i--) {
36
+ value = (value * 256) + byteArray[i];
37
+ }
38
+ return value;
39
+ }
40
+ /**
41
+ * Converts a long integer to an array of bytes.
42
+ *
43
+ * @static
44
+ * @param {number} long - The long integer to convert.
45
+ * @returns {Array<number>} The resulting array of bytes.
46
+ */
47
+ static longToArray(long) {
48
+ const byteArray = [0, 0, 0, 0, 0, 0, 0, 0];
49
+ for (let index = 0; index < byteArray.length; index++) {
50
+ const byte = long & 0xff;
51
+ byteArray[index] = byte;
52
+ long = (long - byte) / 256;
53
+ }
54
+ return byteArray;
55
+ }
56
+ }
57
+ exports.BufferUtils = BufferUtils;
@@ -0,0 +1,15 @@
1
+ export declare class StringUtils {
2
+ /**
3
+ * Generates a GUID/UUID-like string.
4
+ *
5
+ * @returns {string} A GUID/UUID-like string.
6
+ */
7
+ static newGuid(): string;
8
+ /**
9
+ * Extracts key-value parameters from a query string.
10
+ *
11
+ * @param {string} query - The query string to parse.
12
+ * @returns {Record<string, string>} An object containing the parsed key-value pairs.
13
+ */
14
+ static getParamsFromString(query: string): Record<string, string>;
15
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringUtils = void 0;
4
+ class StringUtils {
5
+ /**
6
+ * Generates a GUID/UUID-like string.
7
+ *
8
+ * @returns {string} A GUID/UUID-like string.
9
+ */
10
+ static newGuid() {
11
+ const s4 = () => {
12
+ return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
13
+ };
14
+ return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
15
+ }
16
+ /**
17
+ * Extracts key-value parameters from a query string.
18
+ *
19
+ * @param {string} query - The query string to parse.
20
+ * @returns {Record<string, string>} An object containing the parsed key-value pairs.
21
+ */
22
+ static getParamsFromString(query) {
23
+ const params = {};
24
+ query.replace(/^\?/, '').split('&').forEach(param => {
25
+ const [key, value] = param.split('=');
26
+ params[decodeURIComponent(key)] = decodeURIComponent(value || '');
27
+ });
28
+ return params;
29
+ }
30
+ }
31
+ exports.StringUtils = StringUtils;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const BrokerController_1 = require("./Controllers/BrokerController/BrokerController");
4
+ const ThorIOServer_1 = require("./ThorIOServer");
5
+ const thorio = ThorIOServer_1.ThorIOServer.createInstance([BrokerController_1.BrokerController]);
package/docs/.nojekyll ADDED
@@ -0,0 +1 @@
1
+ TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
@@ -0,0 +1 @@
1
+ window.hierarchyData = "eJyN0rFqwzAQBuB3ufnS2JZcKRq7ZSgUWugQPLj2ORFx5CApU9C7FxMa3NSuNAmk//iO013BDoN3oHZCcpQ5rxAsdT01Xg/GgboCE9l4mPpEoOBNn+mVnKv3BAhHbVpQeSERLrYHBU1fO0duPYk9HfypB7w9gQLv2tVYt7pdBAQm2UT4pK/3oTmST2AeswnWhk+sl0vXkU2AfgXjCs/K+Zl92Nq482B94vDu+QSTiX+mmAQvFiXooliaaxI9XxF3hZz+5/avVZTPP5Y2nmxXN+TW2zhxT4+PB923lgyoHRcF8qxEzkQVEGQ+7z/uVKyN2GotdMM2HJnIkElWhRC+AV/rRJE="
@@ -0,0 +1,43 @@
1
+ :root {
2
+ --light-hl-0: #000000;
3
+ --dark-hl-0: #D4D4D4;
4
+ --light-hl-1: #795E26;
5
+ --dark-hl-1: #DCDCAA;
6
+ --light-hl-2: #A31515;
7
+ --dark-hl-2: #CE9178;
8
+ --light-code-background: #FFFFFF;
9
+ --dark-code-background: #1E1E1E;
10
+ }
11
+
12
+ @media (prefers-color-scheme: light) { :root {
13
+ --hl-0: var(--light-hl-0);
14
+ --hl-1: var(--light-hl-1);
15
+ --hl-2: var(--light-hl-2);
16
+ --code-background: var(--light-code-background);
17
+ } }
18
+
19
+ @media (prefers-color-scheme: dark) { :root {
20
+ --hl-0: var(--dark-hl-0);
21
+ --hl-1: var(--dark-hl-1);
22
+ --hl-2: var(--dark-hl-2);
23
+ --code-background: var(--dark-code-background);
24
+ } }
25
+
26
+ :root[data-theme='light'] {
27
+ --hl-0: var(--light-hl-0);
28
+ --hl-1: var(--light-hl-1);
29
+ --hl-2: var(--light-hl-2);
30
+ --code-background: var(--light-code-background);
31
+ }
32
+
33
+ :root[data-theme='dark'] {
34
+ --hl-0: var(--dark-hl-0);
35
+ --hl-1: var(--dark-hl-1);
36
+ --hl-2: var(--dark-hl-2);
37
+ --code-background: var(--dark-code-background);
38
+ }
39
+
40
+ .hl-0 { color: var(--hl-0); }
41
+ .hl-1 { color: var(--hl-1); }
42
+ .hl-2 { color: var(--hl-2); }
43
+ pre, code { background: var(--code-background); }