systemlynx 1.2.0 → 1.4.0
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/README.md +33 -38
- package/index.js +21 -21
- package/index.test.js +14 -14
- package/package.json +1 -1
- package/systemlynx/App/App.js +1 -2
- package/systemlynx/App/components/initializeApp.js +2 -2
- package/systemlynx/App/components/loadModules.js +1 -1
- package/systemlynx/App/tests/App.test.js +8 -8
- package/systemlynx/Client/components/ServiceRequestHandler.js +1 -1
- package/systemlynx/Client/components/loadConnectionData.js +1 -1
- package/systemlynx/Dispatcher/Dispatcher.js +1 -1
- package/systemlynx/ServerManager/ServerManager.js +1 -4
- package/systemlynx/Service/Service.js +9 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# SystemLynx   
|
|
1
|
+
# SystemLynx JS   
|
|
2
2
|
|
|
3
|
-
SystemLynx is a framework for developing modular web APIs. It's a wrapper on top of ExpressJS and Socket.io. With SystemLynx, instead of
|
|
3
|
+
SystemLynx is a framework for developing modular web APIs in NodeJS. It's a wrapper on top of ExpressJS and Socket.io. With SystemLynx, instead of developing a server with endpoints, you can simply export objects from a server into a client application. Basically any objects hosted by a SystemLynx Service can be loaded and used by a SystemLynx Client.
|
|
4
4
|
|
|
5
|
-
SystemLynx comes with the following objects that are used for web
|
|
5
|
+
SystemLynx comes with the following objects that are used for web app development:
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
8
|
const { App, Service, Client, LoadBalancer } = require("systemlynx");
|
|
@@ -11,8 +11,8 @@ const { App, Service, Client, LoadBalancer } = require("systemlynx");
|
|
|
11
11
|
Call `require("systemlynx")` and de-concatenate from the object it returns. The main abstractions used for client-to-server interactions are the following:
|
|
12
12
|
|
|
13
13
|
- **Service** - Used to create and host objects that can be loaded and used by a SystemLynx Client.
|
|
14
|
-
- **Client** - Used in a client application to load a
|
|
15
|
-
- **App** - Provides a modular interface and lifecycle methods for asynchronously creating and loading
|
|
14
|
+
- **Client** - Used in a client application to load a **Service**, which contains all the objects added to the **Service**.
|
|
15
|
+
- **App** - Provides a modular interface and lifecycle methods for asynchronously creating and loading **Services**.
|
|
16
16
|
|
|
17
17
|
Find the full [API Documentation](https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#tasksjs-api-documentation) here.
|
|
18
18
|
|
|
@@ -22,16 +22,16 @@ Find the full [API Documentation](https://github.com/Odion100/SystemLynx/blob/ta
|
|
|
22
22
|
|
|
23
23
|
## Service.ServerModule(name, constructor [,options])
|
|
24
24
|
|
|
25
|
-
Use the `Service.ServerModule(name, constructor/object)` method to
|
|
25
|
+
Use the `Service.ServerModule(name, constructor/object)` method to add an object to be hosted by a **SystemLynx Service**. This will allows you to load an instance of that object into a client application, and call any methods on that object remotely.
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
28
|
const { Service } = require("systemlynx");
|
|
29
29
|
|
|
30
30
|
const Users = {};
|
|
31
31
|
|
|
32
|
-
Users.add = function (data
|
|
32
|
+
Users.add = function (data) {
|
|
33
33
|
console.log(data);
|
|
34
|
-
|
|
34
|
+
return { message: "You have successfully called the Users.add method" };
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
Service.ServerModule("Users", Users);
|
|
@@ -39,17 +39,16 @@ Service.ServerModule("Users", Users);
|
|
|
39
39
|
|
|
40
40
|
In the code above we assigned an object to the variable `Users` and gave it an add method. The `Service.ServerModule(name, constructor/object)` function takes the name assigned to the object as the first argument and the object itself as the second argument.
|
|
41
41
|
|
|
42
|
-
Alternatively, you can use a constructor function instead of an object as the second argument. In the example below we create another
|
|
43
|
-
"Orders".
|
|
42
|
+
Alternatively, you can use a constructor function instead of an object as the second argument. In the example below we create another **ServerModule** called "Orders". This time we use a constructor function as the second argument of the to **Service.ServerModule** function. The `this` value is the initial instance of the **ServerModule** object. Every method added to the `this` value will be accessible when the object is loaded by a **SystemLynx Client**. Note: **ServerModule** methods can be synchronous or asynchronous functions.
|
|
44
43
|
|
|
45
44
|
```javascript
|
|
46
45
|
const { Service } = require("systemlynx");
|
|
47
46
|
|
|
48
47
|
const Users = {};
|
|
49
48
|
|
|
50
|
-
Users.add = function (data
|
|
49
|
+
Users.add = function (data) {
|
|
51
50
|
console.log(data);
|
|
52
|
-
|
|
51
|
+
return { message: "You have successfully called the Users.add method" };
|
|
53
52
|
};
|
|
54
53
|
|
|
55
54
|
Service.ServerModule("Users", Users);
|
|
@@ -57,27 +56,25 @@ Service.ServerModule("Users", Users);
|
|
|
57
56
|
Service.ServerModule("Orders", function () {
|
|
58
57
|
const Orders = this;
|
|
59
58
|
|
|
60
|
-
Orders.find = function (arg1, arg2
|
|
59
|
+
Orders.find = async function (arg1, arg2) {
|
|
61
60
|
console.log(data);
|
|
62
|
-
|
|
61
|
+
return { message: "You have successfully called the Orders.find method" };
|
|
63
62
|
};
|
|
64
63
|
});
|
|
65
64
|
```
|
|
66
65
|
|
|
67
|
-
In the _ServerModule_ constructor function above, the `this` value is the initial instance of the _ServerModule_ object. Every method added to the `this` value will be accessible when the object is loaded by a _SystemLynx Client_. Notice that the method we created, `Orders.find = function(arg1, arg2, callback)...`, has 3 parameters including a callback function as the last argument. By defualt all _ServerModule_ methods will recieve a callback function as its last argument. Use the first parameter of the callback function to respond with an error, and the second parameter to send a success response. Note: _ServerModule_ methods can be configured to work with synchronous return values instead of asynchronous callbacks (read more about Service configuration [here](https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#apploadserviceurl)).
|
|
68
|
-
|
|
69
66
|
## Service.startService(options)
|
|
70
67
|
|
|
71
|
-
Before we can access the objects hosted by this
|
|
68
|
+
Before we can access the objects hosted by this **Service** from a client application, we need to call the `Service.startService(options)` function. This will start an **ExpressJS** Server and a **Socket.io** WebSocket Server, and set up routing for the **Service**. In the example below we added the `Service.startService(options)` function at the bottom, but the order does not matter.
|
|
72
69
|
|
|
73
70
|
```javascript
|
|
74
71
|
const { Service } = require("systemlynx");
|
|
75
72
|
|
|
76
73
|
const Users = {};
|
|
77
74
|
|
|
78
|
-
Users.add = function (data
|
|
75
|
+
Users.add = function (data) {
|
|
79
76
|
console.log(data);
|
|
80
|
-
|
|
77
|
+
return { message: "You have successfully called the Users.add method" };
|
|
81
78
|
};
|
|
82
79
|
|
|
83
80
|
Service.ServerModule("Users", Users);
|
|
@@ -85,9 +82,9 @@ Service.ServerModule("Users", Users);
|
|
|
85
82
|
Service.ServerModule("Orders", function () {
|
|
86
83
|
const Orders = this;
|
|
87
84
|
|
|
88
|
-
Orders.find = function (arg1, arg2
|
|
85
|
+
Orders.find = function (arg1, arg2) {
|
|
89
86
|
console.log(data);
|
|
90
|
-
|
|
87
|
+
return { message: "You have successfully called the Orders.find method" };
|
|
91
88
|
};
|
|
92
89
|
});
|
|
93
90
|
|
|
@@ -98,7 +95,7 @@ Now lets see how these objects can be loaded into a client application.
|
|
|
98
95
|
|
|
99
96
|
## Client.loadService(url, [options])
|
|
100
97
|
|
|
101
|
-
The `Client.loadService(url)` function can be used to load a SystemLynx
|
|
98
|
+
The `Client.loadService(url)` function can be used to load a SystemLynx **Service**. This method requires the url (string) of the **Service** you want to load as the first argument, and will return a promise that will resolve into an object that containing all the modules hosted by that service. See below. **NOTE: You must be within an async function in order to use the `await` keyword when returning a promise.**
|
|
102
99
|
|
|
103
100
|
```javascript
|
|
104
101
|
const { Client } = require("systemlynx");
|
|
@@ -108,7 +105,7 @@ const { Users, Orders } = await Client.loadService("http://localhost:4400/test/s
|
|
|
108
105
|
console.log(Users, Orders);
|
|
109
106
|
```
|
|
110
107
|
|
|
111
|
-
Now that we've loaded the
|
|
108
|
+
Now that we've loaded the **Service** that we created in the previous example, and have a handle on the **Users** and **Orders** objects hosted by the **Service**, we can now call any method on those objects in the same way we would remotely. In the example below, noticed that both the `User.add` and `Orders.find` methods will return a promise.
|
|
112
109
|
|
|
113
110
|
```javascript
|
|
114
111
|
const { Client } = require("systemlynx");
|
|
@@ -117,10 +114,9 @@ const { Users, Orders } = await Client.loadService("http://localhost:4400/test/s
|
|
|
117
114
|
|
|
118
115
|
console.log(Users, Orders);
|
|
119
116
|
|
|
120
|
-
Users.add({ message: "Users.add Test" }
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
117
|
+
const results = await Users.add({ message: "Users.add Test" });
|
|
118
|
+
|
|
119
|
+
console.log(results);
|
|
124
120
|
|
|
125
121
|
const response = await Orders.find("hello", "world");
|
|
126
122
|
|
|
@@ -129,7 +125,7 @@ console.log(response);
|
|
|
129
125
|
|
|
130
126
|
## Sending and Receiving Websocket Events
|
|
131
127
|
|
|
132
|
-
We can also receive WebSocket events emitted from the remote objects we've loaded using the `Client.loadService(url)` function. In the example below we're using the `Users.on(event_name, callback)` method to listen for events coming from the "Users"
|
|
128
|
+
We can also receive WebSocket events emitted from the remote objects we've loaded using the `Client.loadService(url)` function. In the example below we're using the `Users.on(event_name, callback)` method to listen for events coming from the "Users" **ServerModule**.
|
|
133
129
|
|
|
134
130
|
```javascript
|
|
135
131
|
const { Client } = require("systemlynx");
|
|
@@ -138,10 +134,9 @@ const { Users, Orders } = await Client.loadService("http://localhost:4400/test/s
|
|
|
138
134
|
|
|
139
135
|
console.log(Users, Orders);
|
|
140
136
|
|
|
141
|
-
Users.add({ message: "Users.add Test" }
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
137
|
+
const results = await Users.add({ message: "Users.add Test" });
|
|
138
|
+
|
|
139
|
+
console.log(results);
|
|
145
140
|
|
|
146
141
|
Users.on("new_user", function (event) {
|
|
147
142
|
console.log(event);
|
|
@@ -152,17 +147,17 @@ const response = await Orders.find("hello", "world");
|
|
|
152
147
|
console.log(response);
|
|
153
148
|
```
|
|
154
149
|
|
|
155
|
-
Now let's go to our server application and call the `Users.emit(event_name, data)` method to emit a websocket event that can be received by its corresponding Clients. Below, notice that we've added `
|
|
150
|
+
Now let's go to our server application and call the `Users.emit(event_name, data)` method to emit a websocket event that can be received by its corresponding Clients. Below, notice that we've added `this.emit("new_user", { message:"new_user event test" })` at the end of the `Users.add` method, so the `new_user` event will be emitted every time this method is called. The `this` value of a **ServerModule** method will always be scoped to the **ServerModule** itself.
|
|
156
151
|
|
|
157
152
|
```javascript
|
|
158
153
|
const { Service } = require("systemlynx");
|
|
159
154
|
|
|
160
155
|
const Users = {};
|
|
161
156
|
|
|
162
|
-
Users.add = function (data
|
|
157
|
+
Users.add = function (data) {
|
|
163
158
|
console.log(data);
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
return { message: "You have successfully called the Users.add method" };
|
|
160
|
+
this.emit("new_user", { message: "new_user event test" });
|
|
166
161
|
};
|
|
167
162
|
|
|
168
163
|
Service.ServerModule("Users", Users);
|
|
@@ -170,9 +165,9 @@ Service.ServerModule("Users", Users);
|
|
|
170
165
|
Service.ServerModule("Orders", function () {
|
|
171
166
|
const Orders = this;
|
|
172
167
|
|
|
173
|
-
Orders.find = function (arg1, arg2
|
|
168
|
+
Orders.find = function (arg1, arg2) {
|
|
174
169
|
console.log(data);
|
|
175
|
-
|
|
170
|
+
return { message: "You have successfully called the Orders.find method" };
|
|
176
171
|
};
|
|
177
172
|
});
|
|
178
173
|
|
package/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
//These are all the abstractions that make up SystemLynx
|
|
2
2
|
const { isNode } = require("./utils/ProcessChecker");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
3
|
+
const SystemLynxApp = require("./systemlynx/App/App");
|
|
4
|
+
const SystemLynxLoadBalancer = require("./systemlynx/LoadBalancer/LoadBalancer");
|
|
5
|
+
const SystemLynxService = require("./systemlynx/Service/Service");
|
|
6
|
+
const SystemLynxServerManager = require("./systemlynx/ServerManager/ServerManager");
|
|
7
|
+
const SystemLynxClient = require("./systemlynx/Client/Client");
|
|
8
|
+
const SystemLynxHttpClient = require("./systemlynx/HttpClient/HttpClient");
|
|
9
|
+
const SystemLynxDispatcher = require("./systemlynx/Dispatcher/Dispatcher");
|
|
10
10
|
|
|
11
|
-
const ServerManager = isNode ?
|
|
12
|
-
const Service = isNode ?
|
|
13
|
-
const LoadBalancer = isNode ?
|
|
11
|
+
const ServerManager = isNode ? SystemLynxServerManager() : null;
|
|
12
|
+
const Service = isNode ? SystemLynxService() : null;
|
|
13
|
+
const LoadBalancer = isNode ? SystemLynxLoadBalancer() : null;
|
|
14
14
|
|
|
15
|
-
const App =
|
|
16
|
-
const HttpClient =
|
|
17
|
-
const Client =
|
|
18
|
-
const Dispatcher =
|
|
15
|
+
const App = SystemLynxApp();
|
|
16
|
+
const HttpClient = SystemLynxHttpClient();
|
|
17
|
+
const Client = SystemLynxClient();
|
|
18
|
+
const Dispatcher = SystemLynxDispatcher();
|
|
19
19
|
|
|
20
20
|
module.exports = {
|
|
21
21
|
//Export these pre-created objects for convenient object destructuring
|
|
@@ -30,11 +30,11 @@ module.exports = {
|
|
|
30
30
|
//export all modules themselves
|
|
31
31
|
//all these modules export factory functions
|
|
32
32
|
//to ensure non-singleton behavior
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
SystemLynxApp,
|
|
34
|
+
SystemLynxLoadBalancer,
|
|
35
|
+
SystemLynxService,
|
|
36
|
+
SystemLynxClient,
|
|
37
|
+
SystemLynxHttpClient,
|
|
38
|
+
SystemLynxServerManager,
|
|
39
|
+
SystemLynxDispatcher,
|
|
40
40
|
};
|
package/index.test.js
CHANGED
|
@@ -6,22 +6,22 @@ const {
|
|
|
6
6
|
Client,
|
|
7
7
|
Service,
|
|
8
8
|
ServerManager,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
SystemLynxApp,
|
|
10
|
+
SystemLynxLoadBalancer,
|
|
11
|
+
SystemLynxService,
|
|
12
|
+
SystemLynxClient,
|
|
13
|
+
SystemLynxHttpClient,
|
|
14
|
+
SystemLynxServerManager,
|
|
15
15
|
} = require("./index");
|
|
16
16
|
|
|
17
|
-
describe("
|
|
18
|
-
it("should return
|
|
19
|
-
expect(
|
|
20
|
-
expect(
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
17
|
+
describe("SystemLynxSystemLynx functions", () => {
|
|
18
|
+
it("should return aSystemLynx functions for each SystemLynx abstraction", () => {
|
|
19
|
+
expect(SystemLynxApp).to.be.a("function");
|
|
20
|
+
expect(SystemLynxLoadBalancer).to.be.a("function");
|
|
21
|
+
expect(SystemLynxService).to.be.a("function");
|
|
22
|
+
expect(SystemLynxClient).to.be.a("function");
|
|
23
|
+
expect(SystemLynxHttpClient).to.be.a("function");
|
|
24
|
+
expect(SystemLynxServerManager).to.be.a("function");
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it("should return an instance of each SystemLynx abstraction", () => {});
|
package/package.json
CHANGED
package/systemlynx/App/App.js
CHANGED
|
@@ -4,7 +4,6 @@ const ServiceFactory = require("../Service/Service");
|
|
|
4
4
|
const SystemObject = require("./components/SystemObject");
|
|
5
5
|
const Dispatcher = require("../Dispatcher/Dispatcher");
|
|
6
6
|
const initializeApp = require("./components/initializeApp");
|
|
7
|
-
const URL = require("url");
|
|
8
7
|
|
|
9
8
|
module.exports = function SystemLynxApp() {
|
|
10
9
|
const App = Dispatcher();
|
|
@@ -67,7 +66,7 @@ module.exports = function SystemLynxApp() {
|
|
|
67
66
|
system.configurations = { __constructor, module: SystemObject(system) };
|
|
68
67
|
else
|
|
69
68
|
throw Error(
|
|
70
|
-
"App.config methods requires a constructor function as
|
|
69
|
+
"[SystemLynx][App][Error]: App.config(...) methods requires a constructor function as its first parameter."
|
|
71
70
|
);
|
|
72
71
|
return App;
|
|
73
72
|
};
|
|
@@ -18,7 +18,7 @@ module.exports = async function initApp(system) {
|
|
|
18
18
|
try {
|
|
19
19
|
await loadServices(system);
|
|
20
20
|
} catch (err) {
|
|
21
|
-
throw `
|
|
21
|
+
throw `[SystemLynx][App][Error]: Initialization Error - failed to load all services`;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
if (typeof system.configurations.__constructor === "function") {
|
|
@@ -27,7 +27,7 @@ module.exports = async function initApp(system) {
|
|
|
27
27
|
() => {
|
|
28
28
|
configComplete = true;
|
|
29
29
|
loadModules(system);
|
|
30
|
-
}
|
|
30
|
+
},
|
|
31
31
|
]);
|
|
32
32
|
} else loadModules(system);
|
|
33
33
|
};
|
|
@@ -10,5 +10,5 @@ module.exports = async function loadModules(system) {
|
|
|
10
10
|
system.Service.ServerModule(name, __constructor)
|
|
11
11
|
);
|
|
12
12
|
if (system.routing) await system.Service.startService(system.routing);
|
|
13
|
-
system.App.emit("
|
|
13
|
+
system.App.emit("ready", system);
|
|
14
14
|
};
|
|
@@ -45,7 +45,7 @@ describe("App: Loading Services", () => {
|
|
|
45
45
|
await new Promise((resolve) => {
|
|
46
46
|
const App = AppFactory();
|
|
47
47
|
App.loadService("test", `http://localhost:${port}/${route}`).on(
|
|
48
|
-
"
|
|
48
|
+
"ready",
|
|
49
49
|
(system) => {
|
|
50
50
|
expect(system.Services[0]).to.be.an("object");
|
|
51
51
|
|
|
@@ -151,7 +151,7 @@ describe("App: Loading Services", () => {
|
|
|
151
151
|
.that.respondsTo("resetConnection");
|
|
152
152
|
resolve();
|
|
153
153
|
})
|
|
154
|
-
.on("
|
|
154
|
+
.on("ready", resolve);
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
});
|
|
@@ -189,7 +189,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
|
|
|
189
189
|
const url = `http://localhost:${port}/${route}`;
|
|
190
190
|
|
|
191
191
|
await new Promise((resolve) =>
|
|
192
|
-
App.startService({ route, port }).on("
|
|
192
|
+
App.startService({ route, port }).on("ready", resolve)
|
|
193
193
|
);
|
|
194
194
|
const connData = await HttpClient.request({ url });
|
|
195
195
|
|
|
@@ -223,7 +223,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
|
|
|
223
223
|
this.test = () => {};
|
|
224
224
|
this.test2 = () => {};
|
|
225
225
|
})
|
|
226
|
-
.on("
|
|
226
|
+
.on("ready", resolve)
|
|
227
227
|
);
|
|
228
228
|
|
|
229
229
|
const connData = await HttpClient.request({ url });
|
|
@@ -253,7 +253,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
|
|
|
253
253
|
]);
|
|
254
254
|
});
|
|
255
255
|
|
|
256
|
-
it('should be able to use App.on("
|
|
256
|
+
it('should be able to use App.on("ready", callback) fire a callback when App initialization is complete', async () => {
|
|
257
257
|
const App = AppFactory();
|
|
258
258
|
|
|
259
259
|
App.ServerModule("mod", function () {
|
|
@@ -265,7 +265,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
|
|
|
265
265
|
});
|
|
266
266
|
|
|
267
267
|
await new Promise((resolve) =>
|
|
268
|
-
App.on("
|
|
268
|
+
App.on("ready", (system) => {
|
|
269
269
|
expect(system)
|
|
270
270
|
.to.be.an("object")
|
|
271
271
|
.that.has.all.keys(
|
|
@@ -303,7 +303,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
|
|
|
303
303
|
});
|
|
304
304
|
|
|
305
305
|
await new Promise((resolve) =>
|
|
306
|
-
App.on("
|
|
306
|
+
App.on("ready", ({ configurations }) => {
|
|
307
307
|
expect(configurations)
|
|
308
308
|
.to.be.an("object")
|
|
309
309
|
.that.has.all.keys("module", "__constructor")
|
|
@@ -349,6 +349,6 @@ describe("SystemObjects", () => {
|
|
|
349
349
|
this.configPassed = true;
|
|
350
350
|
next();
|
|
351
351
|
});
|
|
352
|
-
return new Promise((resolve) => App.on("
|
|
352
|
+
return new Promise((resolve) => App.on("ready", () => resolve()));
|
|
353
353
|
});
|
|
354
354
|
});
|
|
@@ -49,7 +49,7 @@ module.exports = function ServiceRequestHandler(method, fn, resetConnection) {
|
|
|
49
49
|
console.log(err);
|
|
50
50
|
errCount++;
|
|
51
51
|
resetConnection(() => tryRequest(cb, errCount));
|
|
52
|
-
} else throw Error(`
|
|
52
|
+
} else throw Error(`[SystemLynx][Service][Error]: Invalid route:${err}`);
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
return new Promise((resolve, reject) =>
|
|
@@ -11,7 +11,7 @@ module.exports = function loadConnectionData(url, { limit = 10, wait = 150 } = {
|
|
|
11
11
|
if (errors.length < limit)
|
|
12
12
|
setTimeout(() => getData(resolve), errors.length * wait);
|
|
13
13
|
else
|
|
14
|
-
throw `SystemLynx
|
|
14
|
+
throw `[SystemLynx][Client][Error]: Failed to load Service @${url} after ${errors.length} attempts.`;
|
|
15
15
|
} else resolve(results);
|
|
16
16
|
});
|
|
17
17
|
});
|
|
@@ -10,7 +10,7 @@ module.exports = function SystemLynxDispatcher(events = {}) {
|
|
|
10
10
|
Dispatcher.on = (eventName, callback) => {
|
|
11
11
|
if (typeof callback !== "function")
|
|
12
12
|
throw Error(
|
|
13
|
-
"
|
|
13
|
+
"[SystemLynx][EventHandler][Error]: EventHandler.on(eventName, callback) received invalid parameters"
|
|
14
14
|
);
|
|
15
15
|
if (!events[eventName]) events[eventName] = [];
|
|
16
16
|
events[eventName].push(callback);
|
|
@@ -16,10 +16,7 @@ module.exports = function SystemLynxServerManager() {
|
|
|
16
16
|
useREST: false,
|
|
17
17
|
useService: true,
|
|
18
18
|
staticRouting: false,
|
|
19
|
-
validateArgs: true,
|
|
20
19
|
middleware: [],
|
|
21
|
-
useCallbacks: true,
|
|
22
|
-
useReturnValues: false,
|
|
23
20
|
};
|
|
24
21
|
const server = SystemLynxServer();
|
|
25
22
|
const router = SystemLynxRouter(server, () => serverConfigurations);
|
|
@@ -66,7 +63,7 @@ module.exports = function SystemLynxServerManager() {
|
|
|
66
63
|
|
|
67
64
|
return new Promise((resolve) =>
|
|
68
65
|
server.listen(port, () => {
|
|
69
|
-
console.log(`
|
|
66
|
+
console.log(`[SystemLynx][Service]: Listening on ${serviceUrl}`);
|
|
70
67
|
moduleQueue.forEach(({ name, object, reserved_methods }) =>
|
|
71
68
|
ServerManager.addModule(name, object, reserved_methods)
|
|
72
69
|
);
|
|
@@ -15,11 +15,17 @@ module.exports = function ServiceFactory({ defaultModule = {} } = {}) {
|
|
|
15
15
|
|
|
16
16
|
if (typeof constructor === "function") {
|
|
17
17
|
if (constructor.constructor.name === "AsyncFunction")
|
|
18
|
-
throw `
|
|
18
|
+
throw `[SystemLynx][ServerModule][Error]: ServerModule(name, constructor) function cannot receive an async function as the constructor`;
|
|
19
19
|
|
|
20
20
|
const ServerModule = Dispatcher.apply({ ...Service.defaultModule });
|
|
21
|
-
const exclude_methods = [
|
|
22
|
-
|
|
21
|
+
const exclude_methods = [
|
|
22
|
+
...reserved_methods,
|
|
23
|
+
...Object.getOwnPropertyNames(ServerModule),
|
|
24
|
+
];
|
|
25
|
+
constructor.apply(ServerModule, [
|
|
26
|
+
ServerManager.Server(),
|
|
27
|
+
ServerManager.WebSocket(),
|
|
28
|
+
]);
|
|
23
29
|
ServerManager.addModule(name, ServerModule, exclude_methods);
|
|
24
30
|
return ServerModule;
|
|
25
31
|
}
|