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.
Files changed (31) hide show
  1. package/API.md +7 -0
  2. package/README.md +11 -5
  3. package/index.js +22 -23
  4. package/index.test.js +47 -17
  5. package/package.json +1 -1
  6. package/systemlynx/App/App.js +11 -6
  7. package/systemlynx/App/components/initializeApp.js +2 -2
  8. package/systemlynx/App/components/loadServices.js +3 -3
  9. package/systemlynx/App/tests/App.test.js +95 -31
  10. package/systemlynx/Client/Client.js +6 -3
  11. package/systemlynx/Client/components/ClientModule.js +9 -3
  12. package/systemlynx/Client/components/ServiceRequestHandler.js +23 -19
  13. package/systemlynx/Client/components/SocketDispatcher.js +2 -2
  14. package/systemlynx/Client/components/loadConnectionData.js +11 -7
  15. package/systemlynx/Client/tests/Client.test.js +27 -16
  16. package/systemlynx/Client/tests/SocketDispatcher.test.js +17 -6
  17. package/systemlynx/Dispatcher/Dispatcher.js +16 -1
  18. package/systemlynx/Dispatcher/Dispatcher.test.js +4 -3
  19. package/systemlynx/HttpClient/HttpClient.js +1 -1
  20. package/systemlynx/LoadBalancer/tests/LoadBalancer.test.js +30 -7
  21. package/systemlynx/ServerManager/ServerManager.js +82 -35
  22. package/systemlynx/ServerManager/components/Router.js +30 -11
  23. package/systemlynx/ServerManager/components/Server.js +22 -18
  24. package/systemlynx/ServerManager/components/SocketEmitter.js +2 -2
  25. package/systemlynx/ServerManager/components/WebSocketServer.js +2 -2
  26. package/systemlynx/ServerManager/components/clearFolder.js +10 -0
  27. package/systemlynx/ServerManager/components/parseMethods.js +1 -1
  28. package/systemlynx/ServerManager/tests/ServerManager.test.js +124 -11
  29. package/systemlynx/Service/Service.js +31 -12
  30. package/systemlynx/Service/Service.test.js +81 -16
  31. package/temp/.gitignore +0 -4
@@ -1,21 +1,22 @@
1
1
  const { expect } = require("chai");
2
2
  const request = require("request");
3
- const SystemLynxService = require("./Service");
4
-
5
- describe("SystemLynxService", () => {
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 = SystemLynxService();
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 = SystemLynxService();
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 = SystemLynxService();
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 created using the 'this' value of the constructor function", async () => {
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 = SystemLynxService();
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 be able to return a Service instance created using an object as the constructor", () => {
119
+ it("should return a ServerModule instance created using an object as the constructor", () => {
117
120
  const mod = Service.module("mod", {
118
- action1: () => {},
119
- action2: () => {},
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
@@ -1,4 +0,0 @@
1
- # Ignore everything in this directory
2
- *
3
- # Except this file
4
- !.gitignore