systemlynx 1.7.2 → 1.8.3
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/API.md +7 -0
- package/README.md +11 -5
- package/index.js +22 -23
- package/index.test.js +47 -17
- package/package.json +3 -4
- package/systemlynx/App/App.js +11 -6
- package/systemlynx/App/components/initializeApp.js +2 -2
- package/systemlynx/App/components/loadServices.js +3 -3
- package/systemlynx/App/tests/App.test.js +95 -31
- package/systemlynx/Client/Client.js +6 -3
- package/systemlynx/Client/components/ClientModule.js +9 -3
- package/systemlynx/Client/components/ServiceRequestHandler.js +23 -19
- package/systemlynx/Client/components/SocketDispatcher.js +2 -2
- package/systemlynx/Client/components/loadConnectionData.js +6 -4
- package/systemlynx/Client/tests/Client.test.js +27 -16
- package/systemlynx/Client/tests/SocketDispatcher.test.js +17 -6
- package/systemlynx/Dispatcher/Dispatcher.js +16 -1
- package/systemlynx/Dispatcher/Dispatcher.test.js +4 -3
- package/systemlynx/HttpClient/HttpClient.js +1 -1
- package/systemlynx/LoadBalancer/tests/LoadBalancer.test.js +30 -7
- package/systemlynx/ServerManager/ServerManager.js +75 -36
- package/systemlynx/ServerManager/components/Router.js +31 -12
- package/systemlynx/ServerManager/components/Server.js +23 -20
- package/systemlynx/ServerManager/components/SocketEmitter.js +2 -2
- package/systemlynx/ServerManager/components/WebSocketServer.js +2 -2
- package/systemlynx/ServerManager/components/clearFolder.js +10 -0
- package/systemlynx/ServerManager/components/parseMethods.js +1 -1
- package/systemlynx/ServerManager/tests/ServerManager.test.js +124 -11
- package/systemlynx/Service/Service.js +31 -12
- package/systemlynx/Service/Service.test.js +81 -16
- package/temp/.gitignore +0 -4
package/API.md
CHANGED
|
@@ -101,6 +101,13 @@ constr OrdersConstructor = function () {
|
|
|
101
101
|
const Users = Service.module("Users", UsersConstructor);
|
|
102
102
|
|
|
103
103
|
const Orders = Service.module("Orders", OrdersConstructor);
|
|
104
|
+
|
|
105
|
+
Orders.before('find', (req, res, next)=>{
|
|
106
|
+
|
|
107
|
+
})
|
|
108
|
+
Orders.before((req, res, next)=>{
|
|
109
|
+
|
|
110
|
+
})
|
|
104
111
|
```
|
|
105
112
|
|
|
106
113
|
## Service.startService(options)
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# SystemLynx JS   
|
|
2
2
|
|
|
3
|
-
SystemLynx is a framework for
|
|
3
|
+
SystemLynx is a NodeJS framework for building modular web APIs, built on top of ExpressJS and Socket.io. It allows you to create objects and load them from a server into a client application.
|
|
4
4
|
|
|
5
5
|
SystemLynx comes with the following objects that are used for web app development:
|
|
6
6
|
|
|
@@ -8,11 +8,9 @@ SystemLynx comes with the following objects that are used for web app developmen
|
|
|
8
8
|
const { App, Service, Client, LoadBalancer } = require("systemlynx");
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Call `require("systemlynx")` and destructrue from the object it returns. The main abstractions used for client-to-server interactions are the following:
|
|
12
|
-
|
|
13
11
|
- **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 **Service**,
|
|
15
|
-
- **App** -
|
|
12
|
+
- **Client** - Used in a client application to load a **Service**, providing access to all the objects hosted by the **Service**.
|
|
13
|
+
- **App** - provides a modular interface for creating and loading Services.
|
|
16
14
|
|
|
17
15
|
Find the full [API Documentation](https://github.com/Odion100/SystemLynx/blob/master/API.md#tasksjs-api-documentation) here.
|
|
18
16
|
|
|
@@ -173,3 +171,11 @@ Service.module("Orders", function () {
|
|
|
173
171
|
|
|
174
172
|
Service.startService({ route: "test/service", port: "4400", host: "localhost" });
|
|
175
173
|
```
|
|
174
|
+
|
|
175
|
+
# temp
|
|
176
|
+
|
|
177
|
+
/\* systemlynx
|
|
178
|
+
|
|
179
|
+
1. update systemlynx config to work to create universal values that are applied to every module. Every prop or method add to the this value or the App.config method will be applied to all this value through out the system. So we should use the SystemContext class that I already created to implement this.
|
|
180
|
+
2. any method that begins with a dollar sign will not be exposed to the client
|
|
181
|
+
\*/
|
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 createApp = require("./systemlynx/App/App");
|
|
4
|
+
const createLoadBalancer = require("./systemlynx/LoadBalancer/LoadBalancer");
|
|
5
|
+
const createService = require("./systemlynx/Service/Service");
|
|
6
|
+
const createServerManager = require("./systemlynx/ServerManager/ServerManager");
|
|
7
|
+
const createClient = require("./systemlynx/Client/Client");
|
|
8
|
+
const createHttpClient = require("./systemlynx/HttpClient/HttpClient");
|
|
9
|
+
const createDispatcher = require("./systemlynx/Dispatcher/Dispatcher");
|
|
10
10
|
|
|
11
|
-
const ServerManager = isNode ?
|
|
12
|
-
const Service = isNode ?
|
|
13
|
-
const LoadBalancer = isNode ?
|
|
11
|
+
const ServerManager = isNode ? createServerManager() : null;
|
|
12
|
+
const Service = isNode ? createService() : null;
|
|
13
|
+
const LoadBalancer = isNode ? createLoadBalancer() : null;
|
|
14
14
|
|
|
15
|
-
const App =
|
|
16
|
-
const HttpClient =
|
|
17
|
-
const Client =
|
|
18
|
-
const Dispatcher =
|
|
15
|
+
const App = createApp();
|
|
16
|
+
const HttpClient = createHttpClient();
|
|
17
|
+
const Client = createClient();
|
|
18
|
+
const Dispatcher = createDispatcher();
|
|
19
19
|
|
|
20
20
|
module.exports = {
|
|
21
21
|
//Export these pre-created objects for convenient object destructuring
|
|
@@ -28,13 +28,12 @@ module.exports = {
|
|
|
28
28
|
ServerManager,
|
|
29
29
|
Dispatcher,
|
|
30
30
|
//export all modules themselves
|
|
31
|
-
//all these modules export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
SystemLynxDispatcher,
|
|
31
|
+
//all these modules export a functions
|
|
32
|
+
createApp,
|
|
33
|
+
createLoadBalancer,
|
|
34
|
+
createService,
|
|
35
|
+
createClient,
|
|
36
|
+
createHttpClient,
|
|
37
|
+
createServerManager,
|
|
38
|
+
createDispatcher,
|
|
40
39
|
};
|
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
|
+
createApp,
|
|
10
|
+
createLoadBalancer,
|
|
11
|
+
createService,
|
|
12
|
+
createClient,
|
|
13
|
+
createHttpClient,
|
|
14
|
+
createServerManager,
|
|
15
15
|
} = require("./index");
|
|
16
16
|
|
|
17
17
|
describe("SystemLynxSystemLynx functions", () => {
|
|
18
18
|
it("should return aSystemLynx functions for each SystemLynx abstraction", () => {
|
|
19
|
-
expect(
|
|
20
|
-
expect(
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
19
|
+
expect(createApp).to.be.a("function");
|
|
20
|
+
expect(createLoadBalancer).to.be.a("function");
|
|
21
|
+
expect(createService).to.be.a("function");
|
|
22
|
+
expect(createClient).to.be.a("function");
|
|
23
|
+
expect(createHttpClient).to.be.a("function");
|
|
24
|
+
expect(createServerManager).to.be.a("function");
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it("should return an instance of each SystemLynx abstraction", () => {});
|
|
@@ -35,6 +35,8 @@ describe("SystemLynx Objects", () => {
|
|
|
35
35
|
"module",
|
|
36
36
|
"on",
|
|
37
37
|
"emit",
|
|
38
|
+
"$clearEvent",
|
|
39
|
+
"before",
|
|
38
40
|
"use",
|
|
39
41
|
"startService",
|
|
40
42
|
"loadService",
|
|
@@ -46,6 +48,8 @@ describe("SystemLynx Objects", () => {
|
|
|
46
48
|
.that.respondsTo("module")
|
|
47
49
|
.that.respondsTo("on")
|
|
48
50
|
.that.respondsTo("emit")
|
|
51
|
+
.that.respondsTo("$clearEvent")
|
|
52
|
+
.that.respondsTo("before")
|
|
49
53
|
.that.respondsTo("use")
|
|
50
54
|
.that.respondsTo("startService")
|
|
51
55
|
.that.respondsTo("loadService")
|
|
@@ -71,14 +75,33 @@ describe("SystemLynx Objects", () => {
|
|
|
71
75
|
it("should return a SystemLynx LoadBalancer", () => {
|
|
72
76
|
expect(LoadBalancer)
|
|
73
77
|
.to.be.an("object")
|
|
74
|
-
.that.has.all.keys(
|
|
78
|
+
.that.has.all.keys(
|
|
79
|
+
"startService",
|
|
80
|
+
"server",
|
|
81
|
+
"WebSocket",
|
|
82
|
+
"clones",
|
|
83
|
+
"module",
|
|
84
|
+
"before"
|
|
85
|
+
)
|
|
75
86
|
.that.respondsTo("startService")
|
|
76
|
-
.that.respondsTo("module")
|
|
87
|
+
.that.respondsTo("module")
|
|
88
|
+
.that.respondsTo("before");
|
|
77
89
|
expect(LoadBalancer.clones)
|
|
78
90
|
.to.be.an("object")
|
|
79
|
-
.that.has.all.keys(
|
|
91
|
+
.that.has.all.keys(
|
|
92
|
+
"before",
|
|
93
|
+
"on",
|
|
94
|
+
"emit",
|
|
95
|
+
"$clearEvent",
|
|
96
|
+
"clones",
|
|
97
|
+
"register",
|
|
98
|
+
"dispatch",
|
|
99
|
+
"assignDispatch"
|
|
100
|
+
)
|
|
80
101
|
.that.respondsTo("emit")
|
|
102
|
+
.that.respondsTo("$clearEvent")
|
|
81
103
|
.that.respondsTo("on")
|
|
104
|
+
.that.respondsTo("before")
|
|
82
105
|
.that.respondsTo("register")
|
|
83
106
|
.that.respondsTo("dispatch")
|
|
84
107
|
.that.respondsTo("assignDispatch")
|
|
@@ -89,9 +112,16 @@ describe("SystemLynx Objects", () => {
|
|
|
89
112
|
it("should return a SystemLynx ServerManager instance", () => {
|
|
90
113
|
expect(ServerManager)
|
|
91
114
|
.to.be.an("Object")
|
|
92
|
-
.that.has.all.keys([
|
|
115
|
+
.that.has.all.keys([
|
|
116
|
+
"startService",
|
|
117
|
+
"addModule",
|
|
118
|
+
"addRouteHandler",
|
|
119
|
+
"server",
|
|
120
|
+
"WebSocket",
|
|
121
|
+
])
|
|
93
122
|
.that.respondsTo("startService")
|
|
94
|
-
.that.respondsTo("addModule")
|
|
123
|
+
.that.respondsTo("addModule")
|
|
124
|
+
.that.respondsTo("addRouteHandler");
|
|
95
125
|
});
|
|
96
126
|
|
|
97
127
|
it("should return a new instance of a Service", () => {
|
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "systemlynx",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "node index.js",
|
|
8
|
-
"test": "jest --verbose
|
|
8
|
+
"test": "jest --verbose"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"
|
|
12
|
-
"express": "^4.16.4",
|
|
11
|
+
"express": "^4.18.2",
|
|
13
12
|
"mime": "^2.4.0",
|
|
14
13
|
"multer": "^1.4.2",
|
|
15
14
|
"request": "^2.88.0",
|
package/systemlynx/App/App.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { isNode } = require("../../utils/ProcessChecker");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const createService = require("../Service/Service");
|
|
4
|
+
const createDispatcher = require("../Dispatcher/Dispatcher");
|
|
5
5
|
const initializeApp = require("./components/initializeApp");
|
|
6
6
|
const SystemLynxContext = require("../utils/SystemContext");
|
|
7
7
|
const System = require("../utils/System");
|
|
8
8
|
|
|
9
|
-
module.exports = function
|
|
9
|
+
module.exports = function createApp(server, WebSocket, customClient) {
|
|
10
10
|
const system = new System();
|
|
11
11
|
const systemContext = SystemLynxContext(system);
|
|
12
|
-
const App =
|
|
12
|
+
const App = new createDispatcher(undefined, systemContext);
|
|
13
13
|
const plugins = [];
|
|
14
14
|
setTimeout(() => {
|
|
15
15
|
plugins.forEach((plugin) => {
|
|
16
16
|
if (typeof plugin === "function") plugin.apply({}, [App, system]);
|
|
17
17
|
});
|
|
18
|
-
initializeApp(system, App, systemContext);
|
|
18
|
+
initializeApp(system, App, customClient, systemContext);
|
|
19
19
|
}, 0);
|
|
20
20
|
|
|
21
21
|
if (isNode) {
|
|
22
|
-
system.Service =
|
|
22
|
+
system.Service = createService(server, WebSocket, systemContext);
|
|
23
23
|
|
|
24
24
|
App.startService = (options) => {
|
|
25
25
|
system.routing = options;
|
|
@@ -30,6 +30,11 @@ module.exports = function SystemLynxApp() {
|
|
|
30
30
|
system.modules.push({ name, __constructor });
|
|
31
31
|
return App;
|
|
32
32
|
};
|
|
33
|
+
|
|
34
|
+
App.before = (...args) => {
|
|
35
|
+
system.Service.before(...args);
|
|
36
|
+
return App;
|
|
37
|
+
};
|
|
33
38
|
App.server = system.Service.server;
|
|
34
39
|
App.WebSocket = system.Service.WebSocket;
|
|
35
40
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const loadModules = require("./loadModules");
|
|
2
2
|
const loadServices = require("./loadServices");
|
|
3
3
|
|
|
4
|
-
module.exports = async function initApp(system, App, systemContext) {
|
|
4
|
+
module.exports = async function initApp(system, App, customClient, systemContext) {
|
|
5
5
|
let configComplete = false;
|
|
6
6
|
const continuationERROR = () => {
|
|
7
7
|
if (!configComplete)
|
|
@@ -16,7 +16,7 @@ module.exports = async function initApp(system, App, systemContext) {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
|
-
await loadServices(system, App, systemContext);
|
|
19
|
+
await loadServices(system, App, customClient, systemContext);
|
|
20
20
|
} catch (err) {
|
|
21
21
|
throw `[SystemLynx][App][Error]: Initialization Error - failed to load all services`;
|
|
22
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const createClient = require("../../Client/Client");
|
|
2
2
|
|
|
3
|
-
module.exports = ({ services }, App, systemContext) => {
|
|
4
|
-
const Client =
|
|
3
|
+
module.exports = ({ services }, App, customClient, systemContext) => {
|
|
4
|
+
const Client = createClient(customClient, systemContext);
|
|
5
5
|
|
|
6
6
|
return Promise.all(
|
|
7
7
|
services.map((serviceData) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const { expect } = require("chai");
|
|
2
|
-
const
|
|
2
|
+
const createApp = require("../App");
|
|
3
3
|
const HttpClient = require("../../HttpClient/HttpClient")();
|
|
4
|
-
const
|
|
4
|
+
const createService = require("../../Service/Service");
|
|
5
5
|
|
|
6
|
-
describe("
|
|
6
|
+
describe("createApp()", () => {
|
|
7
7
|
it("should return a SystemLynx App", () => {
|
|
8
|
-
const App =
|
|
8
|
+
const App = createApp();
|
|
9
9
|
|
|
10
10
|
expect(App)
|
|
11
11
|
.to.be.an("object")
|
|
@@ -13,6 +13,8 @@ describe("SystemLynxApp()", () => {
|
|
|
13
13
|
"module",
|
|
14
14
|
"on",
|
|
15
15
|
"emit",
|
|
16
|
+
"before",
|
|
17
|
+
"$clearEvent",
|
|
16
18
|
"use",
|
|
17
19
|
"startService",
|
|
18
20
|
"loadService",
|
|
@@ -24,6 +26,8 @@ describe("SystemLynxApp()", () => {
|
|
|
24
26
|
.that.respondsTo("module")
|
|
25
27
|
.that.respondsTo("on")
|
|
26
28
|
.that.respondsTo("emit")
|
|
29
|
+
.that.respondsTo("$clearEvent")
|
|
30
|
+
.that.respondsTo("before")
|
|
27
31
|
.that.respondsTo("use")
|
|
28
32
|
.that.respondsTo("startService")
|
|
29
33
|
.that.respondsTo("loadService")
|
|
@@ -33,7 +37,7 @@ describe("SystemLynxApp()", () => {
|
|
|
33
37
|
});
|
|
34
38
|
describe("App: Loading Services", () => {
|
|
35
39
|
it("should be able to use App.loadService(str_url) to load as hosted Service", async () => {
|
|
36
|
-
const Service =
|
|
40
|
+
const Service = createService();
|
|
37
41
|
const route = "test-service";
|
|
38
42
|
const port = "8503";
|
|
39
43
|
|
|
@@ -45,7 +49,7 @@ describe("App: Loading Services", () => {
|
|
|
45
49
|
await Service.startService({ route, port });
|
|
46
50
|
|
|
47
51
|
await new Promise((resolve) => {
|
|
48
|
-
const App =
|
|
52
|
+
const App = createApp();
|
|
49
53
|
App.loadService("test", `http://localhost:${port}/${route}`).on(
|
|
50
54
|
"ready",
|
|
51
55
|
(system) => {
|
|
@@ -53,9 +57,17 @@ describe("App: Loading Services", () => {
|
|
|
53
57
|
|
|
54
58
|
expect(system.services[0].client)
|
|
55
59
|
.to.be.an("object")
|
|
56
|
-
.that.has.all.keys(
|
|
60
|
+
.that.has.all.keys(
|
|
61
|
+
"emit",
|
|
62
|
+
"on",
|
|
63
|
+
"$clearEvent",
|
|
64
|
+
"resetConnection",
|
|
65
|
+
"disconnect",
|
|
66
|
+
"mod"
|
|
67
|
+
)
|
|
57
68
|
.that.respondsTo("emit")
|
|
58
69
|
.that.respondsTo("on")
|
|
70
|
+
.that.respondsTo("$clearEvent")
|
|
59
71
|
.that.respondsTo("resetConnection")
|
|
60
72
|
.that.respondsTo("disconnect");
|
|
61
73
|
resolve();
|
|
@@ -65,7 +77,7 @@ describe("App: Loading Services", () => {
|
|
|
65
77
|
});
|
|
66
78
|
|
|
67
79
|
it("should be able to use App.loadService(...).onLoad(handler) to fire a callback when the Service connects", async () => {
|
|
68
|
-
const Service =
|
|
80
|
+
const Service = createService();
|
|
69
81
|
const route = "test-service";
|
|
70
82
|
const port = "8422";
|
|
71
83
|
const url = `http://localhost:${port}/${route}`;
|
|
@@ -78,12 +90,20 @@ describe("App: Loading Services", () => {
|
|
|
78
90
|
await Service.startService({ route, port });
|
|
79
91
|
|
|
80
92
|
await new Promise((resolve) => {
|
|
81
|
-
const App =
|
|
93
|
+
const App = createApp();
|
|
82
94
|
App.loadService("test", url).onLoad((test) => {
|
|
83
95
|
expect(test)
|
|
84
96
|
.to.be.an("object")
|
|
85
|
-
.that.has.all.keys(
|
|
97
|
+
.that.has.all.keys(
|
|
98
|
+
"emit",
|
|
99
|
+
"on",
|
|
100
|
+
"$clearEvent",
|
|
101
|
+
"resetConnection",
|
|
102
|
+
"disconnect",
|
|
103
|
+
"mod"
|
|
104
|
+
)
|
|
86
105
|
.that.respondsTo("emit")
|
|
106
|
+
.that.respondsTo("$clearEvent")
|
|
87
107
|
.that.respondsTo("on")
|
|
88
108
|
.that.respondsTo("resetConnection")
|
|
89
109
|
.that.respondsTo("disconnect");
|
|
@@ -93,7 +113,7 @@ describe("App: Loading Services", () => {
|
|
|
93
113
|
});
|
|
94
114
|
|
|
95
115
|
it('should use App.on("service_loaded[:name]", callback) to fire when a Service has loaded', async () => {
|
|
96
|
-
const Service =
|
|
116
|
+
const Service = createService();
|
|
97
117
|
const route = "test-service";
|
|
98
118
|
const port = "8423";
|
|
99
119
|
const url = `http://localhost:${port}/${route}`;
|
|
@@ -105,21 +125,37 @@ describe("App: Loading Services", () => {
|
|
|
105
125
|
await Service.startService({ route, port });
|
|
106
126
|
|
|
107
127
|
await new Promise((resolve) => {
|
|
108
|
-
const App =
|
|
128
|
+
const App = createApp();
|
|
109
129
|
App.loadService("test", url)
|
|
110
130
|
.on("service_loaded", (test) => {
|
|
111
131
|
expect(test)
|
|
112
132
|
.to.be.an("object")
|
|
113
|
-
.that.has.all.keys(
|
|
133
|
+
.that.has.all.keys(
|
|
134
|
+
"emit",
|
|
135
|
+
"on",
|
|
136
|
+
"$clearEvent",
|
|
137
|
+
"resetConnection",
|
|
138
|
+
"disconnect",
|
|
139
|
+
"mod"
|
|
140
|
+
)
|
|
114
141
|
.that.respondsTo("emit")
|
|
142
|
+
.that.respondsTo("$clearEvent")
|
|
115
143
|
.that.respondsTo("on")
|
|
116
144
|
.that.respondsTo("resetConnection");
|
|
117
145
|
})
|
|
118
146
|
.on("service_loaded:test", (test) => {
|
|
119
147
|
expect(test)
|
|
120
148
|
.to.be.an("object")
|
|
121
|
-
.that.has.all.keys(
|
|
149
|
+
.that.has.all.keys(
|
|
150
|
+
"emit",
|
|
151
|
+
"on",
|
|
152
|
+
"$clearEvent",
|
|
153
|
+
"resetConnection",
|
|
154
|
+
"disconnect",
|
|
155
|
+
"mod"
|
|
156
|
+
)
|
|
122
157
|
.that.respondsTo("emit")
|
|
158
|
+
.that.respondsTo("$clearEvent")
|
|
123
159
|
.that.respondsTo("on")
|
|
124
160
|
.that.respondsTo("resetConnection");
|
|
125
161
|
resolve();
|
|
@@ -128,7 +164,7 @@ describe("App: Loading Services", () => {
|
|
|
128
164
|
});
|
|
129
165
|
|
|
130
166
|
it("should be accessible to SystemObjects via the module.useService method", async () => {
|
|
131
|
-
const Service =
|
|
167
|
+
const Service = createService();
|
|
132
168
|
const route = "test-service";
|
|
133
169
|
const port = "8442";
|
|
134
170
|
const url = `http://localhost:${port}/${route}`;
|
|
@@ -141,14 +177,22 @@ describe("App: Loading Services", () => {
|
|
|
141
177
|
await Service.startService({ route, port });
|
|
142
178
|
|
|
143
179
|
await new Promise((resolve) => {
|
|
144
|
-
const App =
|
|
180
|
+
const App = createApp();
|
|
145
181
|
App.loadService("test", url)
|
|
146
182
|
.module("module_name", function () {
|
|
147
183
|
const test = this.useService("test");
|
|
148
184
|
expect(test)
|
|
149
185
|
.to.be.an("object")
|
|
150
|
-
.that.has.all.keys(
|
|
186
|
+
.that.has.all.keys(
|
|
187
|
+
"emit",
|
|
188
|
+
"on",
|
|
189
|
+
"$clearEvent",
|
|
190
|
+
"resetConnection",
|
|
191
|
+
"disconnect",
|
|
192
|
+
"mod"
|
|
193
|
+
)
|
|
151
194
|
.that.respondsTo("emit")
|
|
195
|
+
.that.respondsTo("$clearEvent")
|
|
152
196
|
.that.respondsTo("on")
|
|
153
197
|
.that.respondsTo("resetConnection");
|
|
154
198
|
resolve();
|
|
@@ -160,32 +204,52 @@ describe("App: Loading Services", () => {
|
|
|
160
204
|
|
|
161
205
|
describe("App SystemObjects: Initializing Modules, Modules and configurations", () => {
|
|
162
206
|
it("should be able to use App.module to initialize a module", async () => {
|
|
163
|
-
const App =
|
|
207
|
+
const App = createApp();
|
|
164
208
|
return new Promise((resolve) =>
|
|
165
209
|
App.module("test", function () {
|
|
166
210
|
expect(this)
|
|
167
211
|
.to.be.an("object")
|
|
168
|
-
.that.has.all.keys(
|
|
212
|
+
.that.has.all.keys(
|
|
213
|
+
"useModule",
|
|
214
|
+
"useService",
|
|
215
|
+
"useConfig",
|
|
216
|
+
"on",
|
|
217
|
+
"emit",
|
|
218
|
+
"$clearEvent",
|
|
219
|
+
"before"
|
|
220
|
+
)
|
|
169
221
|
.that.respondsTo("useModule")
|
|
170
222
|
.that.respondsTo("useService")
|
|
171
223
|
.that.respondsTo("useConfig")
|
|
172
224
|
.that.respondsTo("on")
|
|
173
|
-
.that.respondsTo("emit")
|
|
225
|
+
.that.respondsTo("emit")
|
|
226
|
+
.that.respondsTo("$clearEvent")
|
|
227
|
+
.that.respondsTo("before");
|
|
174
228
|
}).module("test2", function () {
|
|
175
229
|
expect(this)
|
|
176
230
|
.to.be.an("object")
|
|
177
|
-
.that.has.all.keys(
|
|
231
|
+
.that.has.all.keys(
|
|
232
|
+
"useModule",
|
|
233
|
+
"useService",
|
|
234
|
+
"useConfig",
|
|
235
|
+
"on",
|
|
236
|
+
"emit",
|
|
237
|
+
"$clearEvent",
|
|
238
|
+
"before"
|
|
239
|
+
)
|
|
178
240
|
.that.respondsTo("useModule")
|
|
179
241
|
.that.respondsTo("useService")
|
|
180
242
|
.that.respondsTo("useConfig")
|
|
181
243
|
.that.respondsTo("on")
|
|
182
|
-
.that.respondsTo("emit")
|
|
244
|
+
.that.respondsTo("emit")
|
|
245
|
+
.that.respondsTo("$clearEvent")
|
|
246
|
+
.that.respondsTo("before");
|
|
183
247
|
resolve();
|
|
184
248
|
})
|
|
185
249
|
);
|
|
186
250
|
});
|
|
187
251
|
it("should be able to use App.startService to start as Service", async () => {
|
|
188
|
-
const App =
|
|
252
|
+
const App = createApp();
|
|
189
253
|
const route = "test-service";
|
|
190
254
|
const port = "8493";
|
|
191
255
|
const url = `http://localhost:${port}/${route}`;
|
|
@@ -211,7 +275,7 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
|
|
|
211
275
|
expect(connData.serviceUrl).to.equal(url);
|
|
212
276
|
});
|
|
213
277
|
it("should be able to use App.module to add a hosted Module to the Service", async () => {
|
|
214
|
-
const App =
|
|
278
|
+
const App = createApp();
|
|
215
279
|
const route = "test-service";
|
|
216
280
|
const port = "8494";
|
|
217
281
|
const url = `http://localhost:${port}/${route}`;
|
|
@@ -256,7 +320,7 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
|
|
|
256
320
|
});
|
|
257
321
|
|
|
258
322
|
it('should be able to use App.on("ready", callback) fire a callback when App initialization is complete', async () => {
|
|
259
|
-
const App =
|
|
323
|
+
const App = createApp();
|
|
260
324
|
const route = "system-test";
|
|
261
325
|
const port = "4242";
|
|
262
326
|
App.startService({ route, port });
|
|
@@ -286,7 +350,7 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
|
|
|
286
350
|
});
|
|
287
351
|
|
|
288
352
|
it("should be able to use App.config(constructor) to construct a configuration module", async () => {
|
|
289
|
-
const App =
|
|
353
|
+
const App = createApp();
|
|
290
354
|
|
|
291
355
|
App.module("mod", function () {
|
|
292
356
|
this.test = () => {};
|
|
@@ -318,7 +382,7 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
|
|
|
318
382
|
});
|
|
319
383
|
describe("Use App.use(SystemLynxPlugin), to initializing Modules, and load Services", () => {
|
|
320
384
|
it("should allow for adding new modules and services before app initialization", async () => {
|
|
321
|
-
const Service =
|
|
385
|
+
const Service = createService();
|
|
322
386
|
const route = "test-service";
|
|
323
387
|
const port = "8520";
|
|
324
388
|
const pluginUrl = `http://localhost:${port}/${route}`;
|
|
@@ -333,7 +397,7 @@ describe("Use App.use(SystemLynxPlugin), to initializing Modules, and load Servi
|
|
|
333
397
|
App.module("plugin", { testMethod: (data) => data });
|
|
334
398
|
};
|
|
335
399
|
await new Promise((resolve) => {
|
|
336
|
-
const App =
|
|
400
|
+
const App = createApp();
|
|
337
401
|
App.module("testModule", { testFunction: () => data })
|
|
338
402
|
.use(plugin)
|
|
339
403
|
.on("ready", (system) => {
|
|
@@ -350,7 +414,7 @@ describe("Use App.use(SystemLynxPlugin), to initializing Modules, and load Servi
|
|
|
350
414
|
});
|
|
351
415
|
describe("SystemContext", () => {
|
|
352
416
|
it("should be able to use this.useModule and this.useService within modules and Module", () => {
|
|
353
|
-
const App =
|
|
417
|
+
const App = createApp();
|
|
354
418
|
App.module("mod1", function () {
|
|
355
419
|
expect(this)
|
|
356
420
|
.to.be.an("object")
|
|
@@ -406,7 +470,7 @@ describe("SystemContext", () => {
|
|
|
406
470
|
return new Promise((resolve) => App.on("ready", () => resolve()));
|
|
407
471
|
});
|
|
408
472
|
it("[SystemLynx][App][Client][on] should have access to systemContext during event callbacks.", async () => {
|
|
409
|
-
const AppBackend =
|
|
473
|
+
const AppBackend = createApp();
|
|
410
474
|
const eventName = "testing-this";
|
|
411
475
|
const _route = "test-service";
|
|
412
476
|
const _port = "8900";
|
|
@@ -426,7 +490,7 @@ describe("SystemContext", () => {
|
|
|
426
490
|
});
|
|
427
491
|
await AppBackend.startService({ route: _route, port: _port });
|
|
428
492
|
|
|
429
|
-
const AppClient =
|
|
493
|
+
const AppClient = createApp();
|
|
430
494
|
const route = "test-service";
|
|
431
495
|
const port = "8901";
|
|
432
496
|
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
const loadConnectionData = require("./components/loadConnectionData");
|
|
3
3
|
const SocketDispatcher = require("./components/SocketDispatcher");
|
|
4
4
|
const ClientModule = require("./components/ClientModule");
|
|
5
|
+
const HttpClient = require("../HttpClient/HttpClient");
|
|
5
6
|
|
|
6
|
-
module.exports = function
|
|
7
|
+
module.exports = function createClient(httpClient = HttpClient(), systemContext) {
|
|
7
8
|
const Client = {};
|
|
8
9
|
Client.loadedServices = {};
|
|
9
10
|
|
|
@@ -11,7 +12,7 @@ module.exports = function SystemLynxClient(systemContext) {
|
|
|
11
12
|
if (Client.loadedServices[url] && !options.forceReload)
|
|
12
13
|
return Client.loadedServices[url];
|
|
13
14
|
|
|
14
|
-
const connData = await loadConnectionData(url, options);
|
|
15
|
+
const connData = await loadConnectionData(httpClient, url, options);
|
|
15
16
|
const Service = Client.createService(connData);
|
|
16
17
|
Client.loadedServices[url] = Service;
|
|
17
18
|
await new Promise((resolve) => Service.on("connect", resolve));
|
|
@@ -23,12 +24,13 @@ module.exports = function SystemLynxClient(systemContext) {
|
|
|
23
24
|
if (Client.loadedServices[connData.serviceUrl])
|
|
24
25
|
return Client.loadedServices[connData.serviceUrl];
|
|
25
26
|
|
|
26
|
-
const Service = SocketDispatcher(connData.namespace, events, systemContext);
|
|
27
|
+
const Service = new SocketDispatcher(connData.namespace, events, systemContext);
|
|
27
28
|
|
|
28
29
|
Client.loadedServices[connData.serviceUrl] = Service;
|
|
29
30
|
|
|
30
31
|
Service.resetConnection = async (cb) => {
|
|
31
32
|
const { modules, host, port, namespace } = await loadConnectionData(
|
|
33
|
+
httpClient,
|
|
32
34
|
connData.serviceUrl
|
|
33
35
|
);
|
|
34
36
|
SocketDispatcher.apply(Service, [namespace, events, systemContext]);
|
|
@@ -47,6 +49,7 @@ module.exports = function SystemLynxClient(systemContext) {
|
|
|
47
49
|
connData.modules.forEach(
|
|
48
50
|
(mod) =>
|
|
49
51
|
(Service[mod.name] = ClientModule(
|
|
52
|
+
httpClient,
|
|
50
53
|
mod,
|
|
51
54
|
connData,
|
|
52
55
|
Service.resetConnection,
|