systemlynx 1.8.2 → 1.9.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 +1 -1
- 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 +11 -7
- 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 +82 -35
- package/systemlynx/ServerManager/components/Router.js +30 -11
- package/systemlynx/ServerManager/components/Server.js +22 -18
- 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
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
const { expect } = require("chai");
|
|
2
2
|
const request = require("request");
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
describe("
|
|
3
|
+
const createService = require("./Service");
|
|
4
|
+
const createClient = require("../Client/Client");
|
|
5
|
+
describe("createService", () => {
|
|
6
6
|
it("should return a new instance of a Service", () => {
|
|
7
|
-
const Service =
|
|
7
|
+
const Service = createService();
|
|
8
8
|
expect(Service)
|
|
9
9
|
.to.be.an("object")
|
|
10
|
-
.that.has.all.keys("startService", "module", "server", "WebSocket")
|
|
10
|
+
.that.has.all.keys("startService", "module", "server", "WebSocket", "before")
|
|
11
11
|
.that.respondsTo("startService")
|
|
12
|
-
.that.respondsTo("module")
|
|
12
|
+
.that.respondsTo("module")
|
|
13
|
+
.that.respondsTo("before");
|
|
13
14
|
});
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
describe("Service factory", () => {
|
|
17
18
|
it("should be able to use Service.startService to initiate a ServerManager instance that hosts the Service Connection Data", async () => {
|
|
18
|
-
const Service =
|
|
19
|
+
const Service = createService();
|
|
19
20
|
const route = "/testService";
|
|
20
21
|
const port = 5500;
|
|
21
22
|
const url = `http://localhost:${port}${route}`;
|
|
@@ -47,7 +48,7 @@ describe("Service factory", () => {
|
|
|
47
48
|
});
|
|
48
49
|
|
|
49
50
|
describe("Service.module(constructor)", () => {
|
|
50
|
-
const Service =
|
|
51
|
+
const Service = createService();
|
|
51
52
|
const port = 6542;
|
|
52
53
|
const route = "test/service";
|
|
53
54
|
const url = `http://localhost:${port}/${route}`;
|
|
@@ -60,13 +61,15 @@ describe("Service.module(constructor)", () => {
|
|
|
60
61
|
|
|
61
62
|
expect(mod)
|
|
62
63
|
.to.be.an("Object")
|
|
63
|
-
.that.has.all.keys("on", "emit", "test", "test2")
|
|
64
|
+
.that.has.all.keys("on", "emit", "$clearEvent", "before", "test", "test2")
|
|
64
65
|
.that.respondsTo("on")
|
|
65
66
|
.that.respondsTo("emit")
|
|
67
|
+
.that.respondsTo("$clearEvent")
|
|
68
|
+
.that.respondsTo("before")
|
|
66
69
|
.that.respondsTo("test")
|
|
67
70
|
.that.respondsTo("test2");
|
|
68
71
|
});
|
|
69
|
-
it("should 'Serve' Service connection data
|
|
72
|
+
it("should 'Serve' Service connection data", async () => {
|
|
70
73
|
await Service.startService({ route, port });
|
|
71
74
|
|
|
72
75
|
const results = await new Promise((resolve) =>
|
|
@@ -109,23 +112,69 @@ describe("Service.module(constructor)", () => {
|
|
|
109
112
|
});
|
|
110
113
|
|
|
111
114
|
describe("Service.module(object)", () => {
|
|
112
|
-
const Service =
|
|
115
|
+
const Service = createService();
|
|
113
116
|
const port = 6543;
|
|
114
117
|
const route = "test/service2";
|
|
115
118
|
const url = `http://localhost:${port}/${route}`;
|
|
116
|
-
it("should
|
|
119
|
+
it("should return a ServerModule instance created using an object as the constructor", () => {
|
|
117
120
|
const mod = Service.module("mod", {
|
|
118
|
-
action1: ()
|
|
119
|
-
|
|
121
|
+
action1: function () {
|
|
122
|
+
const { req } = this;
|
|
123
|
+
const { beforeAction1, beforeAction12, beforeModule, beforeService } = req;
|
|
124
|
+
return {
|
|
125
|
+
beforeAction1,
|
|
126
|
+
beforeModule,
|
|
127
|
+
beforeService,
|
|
128
|
+
beforeAction12,
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
action2: function () {
|
|
132
|
+
const { req } = this;
|
|
133
|
+
const { beforeAction1, beforeModule, beforeService } = req;
|
|
134
|
+
return { beforeAction1, beforeModule, beforeService };
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
Service.module("mod2", function () {
|
|
138
|
+
this.action3 = function () {
|
|
139
|
+
const { req } = this;
|
|
140
|
+
const { beforeAction3, beforeModule, beforeService } = req;
|
|
141
|
+
return { beforeAction3, beforeModule, beforeService };
|
|
142
|
+
};
|
|
143
|
+
this.before("action3", (req, res, next) => {
|
|
144
|
+
req.beforeAction3 = true;
|
|
145
|
+
next();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
mod.before(
|
|
149
|
+
"action1",
|
|
150
|
+
(req, res, next) => {
|
|
151
|
+
req.beforeAction1 = true;
|
|
152
|
+
next();
|
|
153
|
+
},
|
|
154
|
+
(req, res, next) => {
|
|
155
|
+
req.beforeAction12 = true;
|
|
156
|
+
next();
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
mod.before((req, res, next) => {
|
|
161
|
+
req.beforeModule = true;
|
|
162
|
+
next();
|
|
120
163
|
});
|
|
121
164
|
|
|
165
|
+
Service.before((req, res, next) => {
|
|
166
|
+
req.beforeService = true;
|
|
167
|
+
next();
|
|
168
|
+
});
|
|
122
169
|
expect(mod)
|
|
123
170
|
.to.be.an("Object")
|
|
124
|
-
.that.has.all.keys("action1", "action2", "on", "emit")
|
|
171
|
+
.that.has.all.keys("action1", "action2", "on", "emit", "$clearEvent", "before")
|
|
125
172
|
.that.respondsTo("action1")
|
|
126
173
|
.that.respondsTo("action2")
|
|
127
174
|
.that.respondsTo("on")
|
|
128
|
-
.that.respondsTo("emit")
|
|
175
|
+
.that.respondsTo("emit")
|
|
176
|
+
.that.respondsTo("$clearEvent")
|
|
177
|
+
.that.respondsTo("before");
|
|
129
178
|
});
|
|
130
179
|
it("should 'Serve' Service connection data created using an object as the constructor", async () => {
|
|
131
180
|
await Service.startService({ route, port });
|
|
@@ -167,4 +216,20 @@ describe("Service.module(object)", () => {
|
|
|
167
216
|
expect(results.host, "localhost");
|
|
168
217
|
expect(results.port, port);
|
|
169
218
|
});
|
|
219
|
+
|
|
220
|
+
it("should use SeverModule.before method to add a route handler before a target method", async () => {
|
|
221
|
+
const Client = createClient();
|
|
222
|
+
const { mod, mod2 } = await Client.loadService(url);
|
|
223
|
+
const result = await mod.action1();
|
|
224
|
+
expect(result).to.deep.equal({
|
|
225
|
+
beforeAction1: true,
|
|
226
|
+
beforeAction12: true,
|
|
227
|
+
beforeModule: true,
|
|
228
|
+
beforeService: true,
|
|
229
|
+
});
|
|
230
|
+
const result2 = await mod.action2();
|
|
231
|
+
expect(result2).to.deep.equal({ beforeModule: true, beforeService: true });
|
|
232
|
+
const result3 = await mod2.action3();
|
|
233
|
+
expect(result3).to.deep.equal({ beforeAction3: true, beforeService: true });
|
|
234
|
+
});
|
|
170
235
|
});
|
package/temp/.gitignore
DELETED