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
package/.gitattributes CHANGED
@@ -1,17 +1,17 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
3
-
4
- # Custom for Visual Studio
5
- *.cs diff=csharp
6
-
7
- # Standard to msysgit
8
- *.doc diff=astextplain
9
- *.DOC diff=astextplain
10
- *.docx diff=astextplain
11
- *.DOCX diff=astextplain
12
- *.dot diff=astextplain
13
- *.DOT diff=astextplain
14
- *.pdf diff=astextplain
15
- *.PDF diff=astextplain
16
- *.rtf diff=astextplain
17
- *.RTF diff=astextplain
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
3
+
4
+ # Custom for Visual Studio
5
+ *.cs diff=csharp
6
+
7
+ # Standard to msysgit
8
+ *.doc diff=astextplain
9
+ *.DOC diff=astextplain
10
+ *.docx diff=astextplain
11
+ *.DOCX diff=astextplain
12
+ *.dot diff=astextplain
13
+ *.DOT diff=astextplain
14
+ *.pdf diff=astextplain
15
+ *.PDF diff=astextplain
16
+ *.rtf diff=astextplain
17
+ *.RTF diff=astextplain
@@ -0,0 +1,24 @@
1
+ export { ThorIOServer } from './src/Server/ThorIOServer';
2
+ export { Connection } from './src/Connection/Connection';
3
+ export { ControllerBase } from './src/Controller/ControllerBase';
4
+ export { Subscription } from './src/Controller/Subscription';
5
+ export { BufferUtils } from './src/Utils/BufferUtils';
6
+ export { Plugin } from './src/Server/Plugin';
7
+ export { TextMessage } from './src/Messages/TextMessage';
8
+ export { ErrorMessage } from './src/Messages/ErrorMessage';
9
+ export { PipeMessage } from './src/Messages/PipeMessage';
10
+ export { WebSocketMessage } from './src/Messages/WebSocketMessage';
11
+ export { BufferMessage } from './src/Messages/BufferMessage';
12
+ export { PipeMessageTransport } from './src/Transports/PipeMessageTransport';
13
+ export { WebSocketMessageTransport, } from './src/Transports/WebSocketMessageTransport';
14
+ export { BufferMessageTransport, } from './src/Transports/BufferMessageTransport';
15
+ export { CanSetGet as CanSet } from './src/Decorators/CanSet';
16
+ export { CanInvoke } from './src/Decorators/CanInvoke';
17
+ export { ControllerProperties } from './src/Decorators/ControllerProperties';
18
+ export { BrokerController, } from './src/Controllers/BrokerController/BrokerController';
19
+ export { Signal } from './src/Controllers/BrokerController/Models/Signal';
20
+ export { PeerConnection, } from './src/Controllers/BrokerController/Models/PeerConnection';
21
+ export { ITransport } from './src/Interfaces/ITransport';
22
+ export { ITransportMessage } from './src/Interfaces/ITransportMessage';
23
+ export { StringUtils } from './src/Utils/StringUtils';
24
+ export { ClientInfo } from './src/Connection/ClientInfo';
package/build/index.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientInfo = exports.StringUtils = exports.PeerConnection = exports.Signal = exports.BrokerController = exports.ControllerProperties = exports.CanInvoke = exports.CanSet = exports.BufferMessageTransport = exports.WebSocketMessageTransport = exports.PipeMessageTransport = exports.BufferMessage = exports.WebSocketMessage = exports.PipeMessage = exports.ErrorMessage = exports.TextMessage = exports.Plugin = exports.BufferUtils = exports.Subscription = exports.ControllerBase = exports.Connection = exports.ThorIOServer = void 0;
4
+ var ThorIOServer_1 = require("./src/Server/ThorIOServer");
5
+ Object.defineProperty(exports, "ThorIOServer", { enumerable: true, get: function () { return ThorIOServer_1.ThorIOServer; } });
6
+ var Connection_1 = require("./src/Connection/Connection");
7
+ Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return Connection_1.Connection; } });
8
+ var ControllerBase_1 = require("./src/Controller/ControllerBase");
9
+ Object.defineProperty(exports, "ControllerBase", { enumerable: true, get: function () { return ControllerBase_1.ControllerBase; } });
10
+ var Subscription_1 = require("./src/Controller/Subscription");
11
+ Object.defineProperty(exports, "Subscription", { enumerable: true, get: function () { return Subscription_1.Subscription; } });
12
+ var BufferUtils_1 = require("./src/Utils/BufferUtils");
13
+ Object.defineProperty(exports, "BufferUtils", { enumerable: true, get: function () { return BufferUtils_1.BufferUtils; } });
14
+ var Plugin_1 = require("./src/Server/Plugin");
15
+ Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return Plugin_1.Plugin; } });
16
+ var TextMessage_1 = require("./src/Messages/TextMessage");
17
+ Object.defineProperty(exports, "TextMessage", { enumerable: true, get: function () { return TextMessage_1.TextMessage; } });
18
+ var ErrorMessage_1 = require("./src/Messages/ErrorMessage");
19
+ Object.defineProperty(exports, "ErrorMessage", { enumerable: true, get: function () { return ErrorMessage_1.ErrorMessage; } });
20
+ var PipeMessage_1 = require("./src/Messages/PipeMessage");
21
+ Object.defineProperty(exports, "PipeMessage", { enumerable: true, get: function () { return PipeMessage_1.PipeMessage; } });
22
+ var WebSocketMessage_1 = require("./src/Messages/WebSocketMessage");
23
+ Object.defineProperty(exports, "WebSocketMessage", { enumerable: true, get: function () { return WebSocketMessage_1.WebSocketMessage; } });
24
+ var BufferMessage_1 = require("./src/Messages/BufferMessage");
25
+ Object.defineProperty(exports, "BufferMessage", { enumerable: true, get: function () { return BufferMessage_1.BufferMessage; } });
26
+ var PipeMessageTransport_1 = require("./src/Transports/PipeMessageTransport");
27
+ Object.defineProperty(exports, "PipeMessageTransport", { enumerable: true, get: function () { return PipeMessageTransport_1.PipeMessageTransport; } });
28
+ var WebSocketMessageTransport_1 = require("./src/Transports/WebSocketMessageTransport");
29
+ Object.defineProperty(exports, "WebSocketMessageTransport", { enumerable: true, get: function () { return WebSocketMessageTransport_1.WebSocketMessageTransport; } });
30
+ var BufferMessageTransport_1 = require("./src/Transports/BufferMessageTransport");
31
+ Object.defineProperty(exports, "BufferMessageTransport", { enumerable: true, get: function () { return BufferMessageTransport_1.BufferMessageTransport; } });
32
+ var CanSet_1 = require("./src/Decorators/CanSet");
33
+ Object.defineProperty(exports, "CanSet", { enumerable: true, get: function () { return CanSet_1.CanSetGet; } });
34
+ var CanInvoke_1 = require("./src/Decorators/CanInvoke");
35
+ Object.defineProperty(exports, "CanInvoke", { enumerable: true, get: function () { return CanInvoke_1.CanInvoke; } });
36
+ var ControllerProperties_1 = require("./src/Decorators/ControllerProperties");
37
+ Object.defineProperty(exports, "ControllerProperties", { enumerable: true, get: function () { return ControllerProperties_1.ControllerProperties; } });
38
+ var BrokerController_1 = require("./src/Controllers/BrokerController/BrokerController");
39
+ Object.defineProperty(exports, "BrokerController", { enumerable: true, get: function () { return BrokerController_1.BrokerController; } });
40
+ var Signal_1 = require("./src/Controllers/BrokerController/Models/Signal");
41
+ Object.defineProperty(exports, "Signal", { enumerable: true, get: function () { return Signal_1.Signal; } });
42
+ var PeerConnection_1 = require("./src/Controllers/BrokerController/Models/PeerConnection");
43
+ Object.defineProperty(exports, "PeerConnection", { enumerable: true, get: function () { return PeerConnection_1.PeerConnection; } });
44
+ var StringUtils_1 = require("./src/Utils/StringUtils");
45
+ Object.defineProperty(exports, "StringUtils", { enumerable: true, get: function () { return StringUtils_1.StringUtils; } });
46
+ var ClientInfo_1 = require("./src/Connection/ClientInfo");
47
+ Object.defineProperty(exports, "ClientInfo", { enumerable: true, get: function () { return ClientInfo_1.ClientInfo; } });
@@ -0,0 +1,27 @@
1
+ export declare class ClientInfo {
2
+ /**
3
+ * The client identifier.
4
+ *
5
+ * @type {string}
6
+ */
7
+ CI: string;
8
+ /**
9
+ * The controller identifier.
10
+ *
11
+ * @type {string}
12
+ */
13
+ C: string;
14
+ /**
15
+ * The timestamp when the instance was created.
16
+ *
17
+ * @type {Date}
18
+ */
19
+ TS: Date;
20
+ /**
21
+ * Creates an instance of ClientInfo.
22
+ *
23
+ * @param {string} ci - The client identifier.
24
+ * @param {string} controller - The controller identifier.
25
+ */
26
+ constructor(ci: string, controller: string);
27
+ }
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientInfo = void 0;
3
4
  class ClientInfo {
5
+ /**
6
+ * Creates an instance of ClientInfo.
7
+ *
8
+ * @param {string} ci - The client identifier.
9
+ * @param {string} controller - The controller identifier.
10
+ */
4
11
  constructor(ci, controller) {
5
12
  this.CI = ci;
6
13
  this.C = controller;
@@ -0,0 +1,117 @@
1
+ import { ControllerBase } from '../Controller/ControllerBase';
2
+ import { ITransport } from '../Interfaces/ITransport';
3
+ import { Plugin } from '../Server/Plugin';
4
+ import { ClientInfo } from './ClientInfo';
5
+ export declare class Connection {
6
+ transport: ITransport;
7
+ connections: Map<string, Connection>;
8
+ private controllers;
9
+ /**
10
+ * An array to store errors.
11
+ * @public
12
+ * @type {Array<any>}
13
+ */
14
+ errors: Array<any>;
15
+ /**
16
+ * The ping pong interval.
17
+ * @public
18
+ * @type {number}
19
+ */
20
+ pingPongInterval: number;
21
+ /**
22
+ * A map to store the controller instances.
23
+ * @public
24
+ * @type {Map<string, ControllerBase>}
25
+ */
26
+ controllerInstances: Map<string, ControllerBase>;
27
+ /**
28
+ * Client information.
29
+ * @public
30
+ * @type {ClientInfo | undefined}
31
+ */
32
+ clientInfo: ClientInfo | undefined;
33
+ /**
34
+ * Tries to invoke a method or set/get a property on the controller.
35
+ * @private
36
+ * @param {ControllerBase} controller The controller instance.
37
+ * @param {string} methodOrProperty The method or property name.
38
+ * @param {string} data The data to be passed to the method or property.
39
+ * @param {Buffer} [buffer] An optional buffer.
40
+ */
41
+ private tryInvokeMethod;
42
+ /**
43
+ * Getter for the connection ID.
44
+ * @public
45
+ * @returns {string} The connection ID.
46
+ */
47
+ get id(): string;
48
+ /**
49
+ * Constructor for the Connection class.
50
+ * @param {ITransport} transport The transport instance.
51
+ * @param {Map<string, Connection>} connections A map of connections.
52
+ * @param {Map<string, Plugin<ControllerBase>>} controllers A map of controllers.
53
+ * @constructor
54
+ */
55
+ constructor(transport: ITransport, connections: Map<string, Connection>, controllers: Map<string, Plugin<ControllerBase>>);
56
+ /**
57
+ * Sets up the transport event listeners.
58
+ * @private
59
+ * @param {ITransport} transport The transport instance.
60
+ */
61
+ private setupTransport;
62
+ /**
63
+ * Adds an error to the errors array.
64
+ * @private
65
+ * @param {any} error The error to be added.
66
+ */
67
+ private addError;
68
+ /**
69
+ * Checks if a controller with the given alias exists.
70
+ * @public
71
+ * @param {string} alias The controller alias.
72
+ * @returns {boolean} True if the controller exists, false otherwise.
73
+ */
74
+ hasController(alias: string): boolean;
75
+ /**
76
+ * Removes a controller from the controllerInstances.
77
+ * @public
78
+ * @param {string} alias The alias of the controller to be removed.
79
+ * @returns {boolean} True if the controller was removed successfully, false otherwise.
80
+ */
81
+ tryRemoveControllerInstance(alias: string): boolean;
82
+ /**
83
+ * Gets a controller instance from the controllerInstances map.
84
+ * @public
85
+ * @param {string} alias The alias of the controller to be retrieved.
86
+ * @returns {ControllerBase | undefined} The controller instance if found, otherwise undefined.
87
+ */
88
+ tryGetController(alias: string): ControllerBase | undefined;
89
+ /**
90
+ * Adds a controller instance to the controllerInstances map.
91
+ * @private
92
+ * @param {ControllerBase} controller The controller instance to be added.
93
+ * @returns {ControllerBase} The added controller instance.
94
+ */
95
+ private addControllerInstance;
96
+ /**
97
+ * Finds and resolves a controller by alias.
98
+ * @public
99
+ * @param {string} alias The alias of the controller to be resolved.
100
+ * @returns {ControllerBase} The resolved controller instance.
101
+ * @throws {Error} If the controller cannot be resolved.
102
+ */
103
+ tryResolveController(alias: string): ControllerBase;
104
+ /**
105
+ * Locates a controller by alias. If registered, returns it; otherwise, creates an instance.
106
+ * @public
107
+ * @param {string} alias The alias of the controller to be located.
108
+ * @returns {ControllerBase | undefined} The located controller instance, or undefined if not found.
109
+ */
110
+ tryCreateControllerInstance(alias: string): ControllerBase | undefined;
111
+ /**
112
+ * Initializes a newly created controller instance.
113
+ * @private
114
+ * @param {ControllerBase} controllerInstance The controller instance to initialize.
115
+ */
116
+ private initializeControllerInstance;
117
+ }
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Connection = void 0;
4
+ const TextMessage_1 = require("../Messages/TextMessage");
5
+ const ClientInfo_1 = require("./ClientInfo");
6
+ class Connection {
7
+ /**
8
+ * Tries to invoke a method or set/get a property on the controller.
9
+ * @private
10
+ * @param {ControllerBase} controller The controller instance.
11
+ * @param {string} methodOrProperty The method or property name.
12
+ * @param {string} data The data to be passed to the method or property.
13
+ * @param {Buffer} [buffer] An optional buffer.
14
+ */
15
+ tryInvokeMethod(controller, methodOrProperty, data, buffer) {
16
+ if (controller.canInvokeMethod(methodOrProperty)) {
17
+ controller.invokeMethod(methodOrProperty, data, buffer);
18
+ }
19
+ else if (controller.canSetProperty(methodOrProperty)) {
20
+ controller.setProperty(methodOrProperty, JSON.parse(data));
21
+ }
22
+ else if (controller.canGetProperty(methodOrProperty)) {
23
+ const { resultId } = JSON.parse(data);
24
+ controller.getProperty(methodOrProperty, resultId);
25
+ }
26
+ }
27
+ /**
28
+ * Getter for the connection ID.
29
+ * @public
30
+ * @returns {string} The connection ID.
31
+ */
32
+ get id() {
33
+ return this.transport.id;
34
+ }
35
+ /**
36
+ * Constructor for the Connection class.
37
+ * @param {ITransport} transport The transport instance.
38
+ * @param {Map<string, Connection>} connections A map of connections.
39
+ * @param {Map<string, Plugin<ControllerBase>>} controllers A map of controllers.
40
+ * @constructor
41
+ */
42
+ constructor(transport, connections, controllers) {
43
+ this.transport = transport;
44
+ this.connections = connections;
45
+ this.controllers = controllers;
46
+ /**
47
+ * An array to store errors.
48
+ * @public
49
+ * @type {Array<any>}
50
+ */
51
+ this.errors = [];
52
+ /**
53
+ * The ping pong interval.
54
+ * @public
55
+ * @type {number}
56
+ */
57
+ this.pingPongInterval = 60;
58
+ /**
59
+ * A map to store the controller instances.
60
+ * @public
61
+ * @type {Map<string, ControllerBase>}
62
+ */
63
+ this.controllerInstances = new Map();
64
+ try {
65
+ this.setupTransport(transport);
66
+ }
67
+ catch (error) {
68
+ console.log('Error in Connection constructor', error);
69
+ }
70
+ }
71
+ /**
72
+ * Sets up the transport event listeners.
73
+ * @private
74
+ * @param {ITransport} transport The transport instance.
75
+ */
76
+ setupTransport(transport) {
77
+ if (transport) {
78
+ this.transport.onMessage = (event) => {
79
+ try {
80
+ const message = event.isBinary ? TextMessage_1.TextMessage.fromArrayBuffer(event.data) : event.toMessage();
81
+ const controller = this.tryCreateControllerInstance(message.C);
82
+ if (controller) {
83
+ this.tryInvokeMethod(controller, message.T, message.D, message.B);
84
+ }
85
+ }
86
+ catch (error) {
87
+ this.addError(error);
88
+ }
89
+ };
90
+ }
91
+ }
92
+ /**
93
+ * Adds an error to the errors array.
94
+ * @private
95
+ * @param {any} error The error to be added.
96
+ */
97
+ addError(error) {
98
+ this.errors.push(error);
99
+ }
100
+ /**
101
+ * Checks if a controller with the given alias exists.
102
+ * @public
103
+ * @param {string} alias The controller alias.
104
+ * @returns {boolean} True if the controller exists, false otherwise.
105
+ */
106
+ hasController(alias) {
107
+ return this.controllerInstances.has(alias);
108
+ }
109
+ /**
110
+ * Removes a controller from the controllerInstances.
111
+ * @public
112
+ * @param {string} alias The alias of the controller to be removed.
113
+ * @returns {boolean} True if the controller was removed successfully, false otherwise.
114
+ */
115
+ tryRemoveControllerInstance(alias) {
116
+ return this.controllerInstances.delete(alias);
117
+ }
118
+ /**
119
+ * Gets a controller instance from the controllerInstances map.
120
+ * @public
121
+ * @param {string} alias The alias of the controller to be retrieved.
122
+ * @returns {ControllerBase | undefined} The controller instance if found, otherwise undefined.
123
+ */
124
+ tryGetController(alias) {
125
+ try {
126
+ const match = this.controllerInstances.get(alias);
127
+ if (!match)
128
+ throw new Error(`Cannot locate the requested controller ${alias}`);
129
+ return match;
130
+ }
131
+ catch (error) {
132
+ this.addError(error);
133
+ return undefined;
134
+ }
135
+ }
136
+ /**
137
+ * Adds a controller instance to the controllerInstances map.
138
+ * @private
139
+ * @param {ControllerBase} controller The controller instance to be added.
140
+ * @returns {ControllerBase} The added controller instance.
141
+ */
142
+ addControllerInstance(controller) {
143
+ if (!controller.alias)
144
+ throw `Cannot add Controller instance`;
145
+ this.controllerInstances.set(controller.alias, controller);
146
+ return controller;
147
+ }
148
+ /**
149
+ * Finds and resolves a controller by alias.
150
+ * @public
151
+ * @param {string} alias The alias of the controller to be resolved.
152
+ * @returns {ControllerBase} The resolved controller instance.
153
+ * @throws {Error} If the controller cannot be resolved.
154
+ */
155
+ tryResolveController(alias) {
156
+ const plugin = this.controllers.get(alias);
157
+ if (!plugin) {
158
+ throw new Error(`Cannot resolve ${alias}, controller unknown.`);
159
+ }
160
+ return plugin.getInstance();
161
+ }
162
+ /**
163
+ * Locates a controller by alias. If registered, returns it; otherwise, creates an instance.
164
+ * @public
165
+ * @param {string} alias The alias of the controller to be located.
166
+ * @returns {ControllerBase | undefined} The located controller instance, or undefined if not found.
167
+ */
168
+ tryCreateControllerInstance(alias) {
169
+ try {
170
+ let instancedController = this.tryGetController(alias);
171
+ if (instancedController) {
172
+ return instancedController;
173
+ }
174
+ else {
175
+ const resolvedController = this.tryResolveController(alias);
176
+ const controllerInstance = new resolvedController(this);
177
+ this.addControllerInstance(controllerInstance);
178
+ this.initializeControllerInstance(controllerInstance);
179
+ return controllerInstance;
180
+ }
181
+ }
182
+ catch (error) {
183
+ this.transport.close(1011, `Cannot locate the specified controller, it may be sealed or the alias is unknown '${alias}'. Connection closed.`);
184
+ return undefined;
185
+ }
186
+ }
187
+ /**
188
+ * Initializes a newly created controller instance.
189
+ * @private
190
+ * @param {ControllerBase} controllerInstance The controller instance to initialize.
191
+ */
192
+ initializeControllerInstance(controllerInstance) {
193
+ controllerInstance.invoke(new ClientInfo_1.ClientInfo(this.id, controllerInstance.alias), '___open', controllerInstance.alias);
194
+ if (controllerInstance.onopen)
195
+ controllerInstance.onopen();
196
+ this.transport.onClose = (e) => {
197
+ if (controllerInstance.onclose)
198
+ controllerInstance.onclose();
199
+ };
200
+ }
201
+ }
202
+ exports.Connection = Connection;
@@ -0,0 +1,20 @@
1
+ export interface IClientInfo {
2
+ /**
3
+ * The client identifier.
4
+ *
5
+ * @type {string}
6
+ */
7
+ CI: string;
8
+ /**
9
+ * The controller identifier.
10
+ *
11
+ * @type {string}
12
+ */
13
+ C: string;
14
+ /**
15
+ * The timestamp when the instance was created.
16
+ *
17
+ * @type {Date}
18
+ */
19
+ TS: Date;
20
+ }
@@ -0,0 +1,134 @@
1
+ import { URLSearchParams } from 'url';
2
+ import { Connection } from '../Connection/Connection';
3
+ import { Subscription } from './Subscription';
4
+ export interface ControllerBase {
5
+ subscriptions: Array<Subscription>;
6
+ connection: Connection;
7
+ disbaleHeartbeat(): void;
8
+ canInvokeMethod(method: string): boolean;
9
+ canSetProperty(property: string): boolean;
10
+ canGetProperty(property: string): boolean;
11
+ getProperty(propertyName: string, topic: string): any;
12
+ setProperty(propertyName: string, propertyValue: any): void;
13
+ invokeError(ex: any): void;
14
+ invokeMethod(method: string, data: any, buffer?: Buffer): void;
15
+ findOn<T>(alias: string, predicate: (item: any) => boolean): ControllerBase[] | undefined;
16
+ getConnections(alias?: string): Connection[];
17
+ onopen(): void;
18
+ onclose(): void;
19
+ find<T, U>(array: T[], predicate: (item: any) => boolean, selector?: (item: T) => U): U[];
20
+ invokeToOthers(data: any, topic: string, controller?: string, buffer?: Buffer): void;
21
+ invokeToAll(data: any, topic: string, controller?: string, buffer?: Buffer): void;
22
+ invokeTo<T>(predicate: (item: T) => boolean, data: any, topic: string, controller?: string, buffer?: Buffer): void;
23
+ invoke(data: any, topic: string, controller?: string, buffer?: Buffer): ControllerBase;
24
+ publish(data: any, topic: string, controller?: string): ControllerBase;
25
+ publishToAll(data: any, topic: string, controller?: string): void;
26
+ hasSubscription(topic: string): boolean;
27
+ addSubscription(topic: string): Subscription;
28
+ removeSubscription(topic: string): void;
29
+ getSubscription(topic: string): Subscription | undefined;
30
+ instance(connection: Connection): ControllerBase;
31
+ new (connection: Connection): ControllerBase;
32
+ }
33
+ /**
34
+ * ControllerBase
35
+ *
36
+ * Base class for all controllers.
37
+ */
38
+ export declare class ControllerBase implements ControllerBase {
39
+ /**
40
+ * Gets the name of the controller.
41
+ * @returns {string} The alias of the controller.
42
+ */
43
+ getName(): string;
44
+ /**
45
+ * The alias of the controller.
46
+ * @type {string}
47
+ */
48
+ alias: string;
49
+ /**
50
+ * An array of subscriptions for the controller.
51
+ * @type {Array<Subscription>}
52
+ */
53
+ subscriptions: Array<Subscription>;
54
+ /**
55
+ * The connection associated with the controller.
56
+ * @type {Connection}
57
+ */
58
+ connection: Connection;
59
+ /**
60
+ * Timestamp of the last pong received.
61
+ * @type {Date | undefined}
62
+ */
63
+ private lastPong;
64
+ /**
65
+ * Timestamp of the last ping sent.
66
+ * @type {Date | undefined}
67
+ */
68
+ private lastPing;
69
+ /**
70
+ * Interval for sending heartbeats.
71
+ * @type {number}
72
+ */
73
+ private heartbeatInterval;
74
+ /**
75
+ * NodeJS.Timeout object for the heartbeat interval.
76
+ * @type {NodeJS.Timeout | undefined}
77
+ */
78
+ private interval;
79
+ /**
80
+ * Creates a new instance of ControllerBase.
81
+ *
82
+ * @param {Connection} connection The connection associated with the controller.
83
+ */
84
+ constructor(connection: Connection);
85
+ /**
86
+ * Enables the heartbeat mechanism.
87
+ */
88
+ private enableHeartbeat;
89
+ /**
90
+ * Connects the controller.
91
+ *
92
+ * **Note:** This method is marked as @CanInvoke(true), but its purpose is unclear.
93
+ * Consider reviewing and potentially removing this method.
94
+ */
95
+ ___connect(): void;
96
+ /**
97
+ * Closes the connection associated with the controller.
98
+ */
99
+ ___close(): void;
100
+ /**
101
+ * Subscribes the controller to a specific topic.
102
+ *
103
+ * @param {Subscription} subscription The subscription object.
104
+ * @param {string} topic The topic to subscribe to.
105
+ * @param {string} controller The controller alias.
106
+ * @returns {Subscription} The created or existing subscription.
107
+ */
108
+ ___subscribe(subscription: Subscription, topic: string, controller: string): Subscription;
109
+ /**
110
+ * Unsubscribes the controller from a specific topic.
111
+ *
112
+ * @param {Subscription} subscription The subscription to unsubscribe.
113
+ * @returns {boolean} True if the subscription was successfully unsubscribed, false otherwise.
114
+ */
115
+ ___unsubscribe(subscription: Subscription): boolean;
116
+ /**
117
+ * Gets the query parameters from the request.
118
+ *
119
+ * @returns {URLSearchParams} The URLSearchParams object containing the query parameters.
120
+ */
121
+ get queryParameters(): URLSearchParams;
122
+ /**
123
+ * Gets the headers from the request.
124
+ *
125
+ * @returns {Map<string, string>} A Map containing the request headers.
126
+ */
127
+ get headers(): Map<string, string>;
128
+ /**
129
+ * Gets the underlying request object.
130
+ *
131
+ * @returns {any} The request object.
132
+ */
133
+ get request(): any;
134
+ }