systemlynx 1.5.0 → 1.7.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/API.md CHANGED
@@ -51,25 +51,84 @@ Welcome to the docs! Following is a list of the objects used and created when de
51
51
  ---
52
52
 
53
53
  <details>
54
- <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md">ClientModule</a></b></summary>
54
+ <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md">ServerModule</a></b></summary>
55
55
 
56
- - [**[created_method]([args...] [,callback])**]()
57
- - [**on(name, constructor [,options])**]()
58
- - [**emit()**]()
56
+ - [**...constructedMethods**]()
57
+ - [**on(name, callback)**]()
58
+ - [**emit(name, data)**]()
59
59
 
60
60
  </details>
61
61
 
62
62
  <details>
63
- <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md">module</a></b></summary>
63
+ <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md">ClientModule</a></b></summary>
64
64
 
65
- - [**[created_method]([args...] [,callback])**]()
66
- - [**on(name, constructor [,options])**]()
67
- - [**emit()**]()
65
+ - [**...loadedMethods**]()
66
+ - [**on(name, callback)**]()
67
+ - [**emit(name, data)**]()
68
68
 
69
69
  </details>
70
70
 
71
71
  ---
72
72
 
73
+ ## Service
74
+
75
+ In SystemLynx a **Service** is a class used to host objects that can be later loaded into a client application using a SystemLynx **Client.** Get a handle on a SystemLynx **Service** by de-structuring the SystemLynx export.
76
+
77
+ ```javascript
78
+ const { Service } = require(“systemlynx”)
79
+ ```
80
+
81
+ ## Service.module(name, constructor)
82
+
83
+ Use the `Service.module(name, constructor/object)` method to create a **ServerModule**, which is an object that is hosted by a **SystemLynx Service**. This will allows you to later load an instance of that object into a client application. The **Service.module(name, constructor)** method takes the (string) name assigned to the object as the first argument, and the object itself, or a constructor function, as the second argument, and will return the constructed **ServerModule.** See the examples below.
84
+
85
+ ```javascript
86
+ const { Service } = require("systemlynx");
87
+
88
+ const UsersConstructor = {
89
+ add:function(data) {
90
+ return { message: "You have successfully called Users.add(...)" };
91
+ }
92
+ };
93
+ constr OrdersConstructor = function () {
94
+ const Orders = this;
95
+
96
+ Orders.find = function (arg1, arg2) {
97
+ return { message: "You have successfully called the Orders.find(...)" };
98
+ };
99
+ }
100
+
101
+ const Users = Service.module("Users", UsersConstructor);
102
+
103
+ const Orders = Service.module("Orders", OrdersConstructor);
104
+ ```
105
+
106
+ ## Service.startService(options)
107
+
108
+ Use the `Service.startService(options)` method to setup hosting and routing for the **Service**. Calling this method will start an **ExpressJS** Server and a **Socket.io** WebSocket Server, and allow the modules created by the **Service** to be loaded into a client application. This method returns a promise that will resolve once the Express server is running.
109
+
110
+ ```javascript
111
+ const { Service } = require("systemlynx");
112
+ const route = "my-route/whatever";
113
+ const port = 8100;
114
+ const host = "localhost";
115
+
116
+ const promise = Service.startService({ route, port, host });
117
+ ```
118
+
119
+ Following is a list of options that can be passed to the **Service.startService(options)** method.
120
+
121
+ | Name | Type | O/R/C | Description |
122
+ | :------------ | :-----: | :---: | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
123
+ | route | string | R | The route from which the service can be loaded. |
124
+ | port | number | R | The port on which to start the Express server. |
125
+ | host | string | O | The host from which the **Service** can be reached. |
126
+ | socketPort | string | R | The port on which to start the Socket.io Websocket server. <br/><br/> Default value : **_random for digit number_** |
127
+ | useRest | boolean | O | When this is true a RESTful route will be created for any **ServerModule** method which is named after a REST method <br/><br/> Default value: `false` |
128
+ | useService | boolean | O | The route from which the service can be loaded. |
129
+ | staticRouting | boolean | O | The route from which the service can be loaded. |
130
+ | middleware | string | R | The route from which the service can be loaded. |
131
+
73
132
  ## App
74
133
 
75
134
  **App** combinds the both functionalites of SystemLynx Service and Client into one object, while also providing a module interface and lifecycle events. Access the App instance by deconcatanating from the object return when loading SystemLynx `require("systemlynx")`.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SystemLynx JS ![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg) ![JS 100%](https://img.shields.io/badge/JavaScript-100%25-green)
2
2
 
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.
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 creating a server with many endpoints, you can simply create objects and load those 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
5
  SystemLynx comes with the following objects that are used for web app development:
6
6
 
@@ -8,13 +8,13 @@ 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 de-concatenate from the object it returns. The main abstractions used for client-to-server interactions are the following:
11
+ Call `require("systemlynx")` and destructrue 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
14
  - **Client** - Used in a client application to load a **Service**, which contains all the objects added to the **Service**.
15
15
  - **App** - Provides a modular interface and lifecycle methods for asynchronously creating and loading **Services**.
16
16
 
17
- Find the full [API Documentation](https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#tasksjs-api-documentation) here.
17
+ Find the full [API Documentation](https://github.com/Odion100/SystemLynx/blob/master/API.md#tasksjs-api-documentation) here.
18
18
 
19
19
  ---
20
20
 
@@ -57,7 +57,7 @@ Service.module("Orders", function () {
57
57
  const Orders = this;
58
58
 
59
59
  Orders.find = async function (arg1, arg2) {
60
- console.log(data);
60
+ console.log(arg1, arg2);
61
61
  return { message: "You have successfully called the Orders.find method" };
62
62
  };
63
63
  });
@@ -82,8 +82,8 @@ Service.module("Users", Users);
82
82
  Service.module("Orders", function () {
83
83
  const Orders = this;
84
84
 
85
- Orders.find = function (arg1, arg2) {
86
- console.log(data);
85
+ Orders.find = async function (arg1, arg2) {
86
+ console.log(arg1, arg2);
87
87
  return { message: "You have successfully called the Orders.find method" };
88
88
  };
89
89
  });
@@ -165,8 +165,8 @@ Service.module("Users", Users);
165
165
  Service.module("Orders", function () {
166
166
  const Orders = this;
167
167
 
168
- Orders.find = function (arg1, arg2) {
169
- console.log(data);
168
+ Orders.find = async function (arg1, arg2) {
169
+ console.log(arg1, arg2);
170
170
  return { message: "You have successfully called the Orders.find method" };
171
171
  };
172
172
  });
package/index.test.js CHANGED
@@ -35,6 +35,7 @@ describe("SystemLynx Objects", () => {
35
35
  "module",
36
36
  "on",
37
37
  "emit",
38
+ "use",
38
39
  "startService",
39
40
  "loadService",
40
41
  "onLoad",
@@ -43,6 +44,7 @@ describe("SystemLynx Objects", () => {
43
44
  .that.respondsTo("module")
44
45
  .that.respondsTo("on")
45
46
  .that.respondsTo("emit")
47
+ .that.respondsTo("use")
46
48
  .that.respondsTo("startService")
47
49
  .that.respondsTo("loadService")
48
50
  .that.respondsTo("onLoad")
@@ -67,14 +69,7 @@ describe("SystemLynx Objects", () => {
67
69
  it("should return a SystemLynx LoadBalancer", () => {
68
70
  expect(LoadBalancer)
69
71
  .to.be.an("object")
70
- .that.has.all.keys(
71
- "startService",
72
- "Server",
73
- "WebSocket",
74
- "defaultModule",
75
- "clones",
76
- "module"
77
- )
72
+ .that.has.all.keys("startService", "Server", "WebSocket", "clones", "module")
78
73
  .that.respondsTo("startService")
79
74
  .that.respondsTo("Server")
80
75
  .that.respondsTo("WebSocket")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systemlynx",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,9 +9,7 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "body-parser": "^1.18.3",
12
- "chai-as-promised": "^7.1.1",
13
12
  "express": "^4.16.4",
14
- "jest": "^24.9.0",
15
13
  "mime": "^2.4.0",
16
14
  "multer": "^1.4.2",
17
15
  "request": "^2.88.0",
@@ -30,7 +28,9 @@
30
28
  "homepage": "https://github.com/Odion100/SystemLynx#readme",
31
29
  "devDependencies": {
32
30
  "chai": "^4.3.4",
31
+ "chai-as-promised": "^7.1.1",
33
32
  "cz-conventional-changelog": "^3.3.0",
33
+ "jest": "^24.9.0",
34
34
  "mocha": "^6.2.0"
35
35
  },
36
36
  "config": {
@@ -1,22 +1,25 @@
1
1
  "use strict";
2
2
  const { isNode } = require("../../utils/ProcessChecker");
3
- const ServiceFactory = require("../Service/Service");
4
- const SystemObject = require("./components/SystemObject");
5
- const Dispatcher = require("../Dispatcher/Dispatcher");
3
+ const SystemLynxService = require("../Service/Service");
4
+ const SystemLynxDispatcher = require("../Dispatcher/Dispatcher");
6
5
  const initializeApp = require("./components/initializeApp");
6
+ const SystemLynxContext = require("../utils/SystemContext");
7
+ const System = require("../utils/System");
7
8
 
8
9
  module.exports = function SystemLynxApp() {
9
- const { on, emit } = Dispatcher();
10
- const App = { emit };
11
- const system = { Services: [], Modules: [], configurations: {}, App, routing: null };
12
- const systemObject = SystemObject(system);
13
- setTimeout(() => initializeApp(system), 0);
14
-
15
- App.on = (name, callback) => on(name, callback.bind(systemObject));
10
+ const system = new System();
11
+ const systemContext = SystemLynxContext(system);
12
+ const App = SystemLynxDispatcher(undefined, systemContext);
13
+ const plugins = [];
14
+ setTimeout(() => {
15
+ plugins.forEach((plugin) => {
16
+ if (typeof plugin === "function") plugin.apply({}, [App, system]);
17
+ });
18
+ initializeApp(system, App, systemContext);
19
+ }, 0);
16
20
 
17
21
  if (isNode) {
18
- system.Service = ServiceFactory();
19
- system.Service.defaultModule = systemObject;
22
+ system.Service = SystemLynxService(systemContext);
20
23
 
21
24
  App.startService = (options) => {
22
25
  system.routing = options;
@@ -24,33 +27,25 @@ module.exports = function SystemLynxApp() {
24
27
  };
25
28
 
26
29
  App.module = (name, __constructor) => {
27
- system.Modules.push({
28
- name,
29
- __constructor,
30
- });
30
+ system.modules.push({ name, __constructor });
31
31
  return App;
32
32
  };
33
33
  }
34
34
 
35
35
  App.loadService = (name, url) => {
36
- system.Services.push({
37
- name,
38
- url,
39
- onLoad: null,
40
- client: {},
41
- });
36
+ system.services.push({ name, url, onLoad: null, client: {} });
42
37
  return App;
43
38
  };
44
39
 
45
40
  App.onLoad = (handler) => {
46
- const service = system.Services[system.Services.length - 1];
41
+ const service = system.services[system.services.length - 1];
47
42
  service.onLoad = handler;
48
43
  return App;
49
44
  };
50
45
 
51
46
  App.config = (__constructor) => {
52
47
  if (typeof __constructor === "function")
53
- system.configurations = { __constructor, module: SystemObject(system) };
48
+ system.configurations = { __constructor, module: SystemLynxContext(system) };
54
49
  else
55
50
  throw Error(
56
51
  "[SystemLynx][App][Error]: App.config(...) methods requires a constructor function as its first parameter."
@@ -58,5 +53,9 @@ module.exports = function SystemLynxApp() {
58
53
  return App;
59
54
  };
60
55
 
56
+ App.use = (plugin) => {
57
+ plugins.push(plugin);
58
+ return App;
59
+ };
61
60
  return App;
62
61
  };
@@ -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) {
4
+ module.exports = async function initApp(system, App, systemContext) {
5
5
  let configComplete = false;
6
6
  const continuationERROR = () => {
7
7
  if (!configComplete)
@@ -16,7 +16,7 @@ module.exports = async function initApp(system) {
16
16
  };
17
17
 
18
18
  try {
19
- await loadServices(system);
19
+ await loadServices(system, App, systemContext);
20
20
  } catch (err) {
21
21
  throw `[SystemLynx][App][Error]: Initialization Error - failed to load all services`;
22
22
  }
@@ -26,8 +26,8 @@ module.exports = async function initApp(system) {
26
26
  system.configurations.__constructor.apply(system.configurations.module, [
27
27
  () => {
28
28
  configComplete = true;
29
- loadModules(system);
29
+ loadModules(system, App);
30
30
  },
31
31
  ]);
32
- } else loadModules(system);
32
+ } else loadModules(system, App);
33
33
  };
@@ -1,10 +1,10 @@
1
- const Dispatcher = require("../../Dispatcher/Dispatcher");
2
-
3
- module.exports = async function loadModules(system) {
4
- system.Modules.forEach(
1
+ module.exports = async function loadModules(system, App) {
2
+ system.modules.forEach(
5
3
  (mod) => (mod.module = system.Service.module(mod.name, mod.__constructor))
6
4
  );
7
5
 
8
- if (system.routing) await system.Service.startService(system.routing);
9
- system.App.emit("ready", system);
6
+ if (system.routing) {
7
+ system.connectionData = await system.Service.startService(system.routing);
8
+ }
9
+ App.emit("ready", system);
10
10
  };
@@ -1,11 +1,14 @@
1
- const Client = require("../../Client/Client")();
2
- module.exports = ({ Services, App }) => {
1
+ const SystemLynxClient = require("../../Client/Client");
2
+
3
+ module.exports = ({ services }, App, systemContext) => {
4
+ const Client = SystemLynxClient(systemContext);
5
+
3
6
  return Promise.all(
4
- Services.map(serviceData => {
7
+ services.map((serviceData) => {
5
8
  const { url, limit, wait, name, onLoad } = serviceData;
6
- return new Promise(resolve => {
9
+ return new Promise((resolve) => {
7
10
  Client.loadService(url, { limit, wait })
8
- .then(service => {
11
+ .then((service) => {
9
12
  serviceData.client = service;
10
13
  if (typeof onLoad === "function") {
11
14
  onLoad(serviceData.client);
@@ -17,7 +20,7 @@ module.exports = ({ Services, App }) => {
17
20
  );
18
21
  resolve();
19
22
  })
20
- .catch(err => {
23
+ .catch((err) => {
21
24
  console.warn(err);
22
25
  App.emit("failed_connection", { err, ...serviceData });
23
26
  resolve();
@@ -1,11 +1,11 @@
1
1
  const { expect } = require("chai");
2
- const AppFactory = require("../App");
2
+ const SystemLynxApp = require("../App");
3
3
  const HttpClient = require("../../HttpClient/HttpClient")();
4
- const ServiceFactory = require("../../Service/Service");
4
+ const SystemLynxService = require("../../Service/Service");
5
5
 
6
- describe("App Factory", () => {
6
+ describe("SystemLynxApp()", () => {
7
7
  it("should return a SystemLynx App", () => {
8
- const App = AppFactory();
8
+ const App = SystemLynxApp();
9
9
 
10
10
  expect(App)
11
11
  .to.be.an("object")
@@ -13,6 +13,7 @@ describe("App Factory", () => {
13
13
  "module",
14
14
  "on",
15
15
  "emit",
16
+ "use",
16
17
  "startService",
17
18
  "loadService",
18
19
  "onLoad",
@@ -21,6 +22,7 @@ describe("App Factory", () => {
21
22
  .that.respondsTo("module")
22
23
  .that.respondsTo("on")
23
24
  .that.respondsTo("emit")
25
+ .that.respondsTo("use")
24
26
  .that.respondsTo("startService")
25
27
  .that.respondsTo("loadService")
26
28
  .that.respondsTo("onLoad")
@@ -29,7 +31,7 @@ describe("App Factory", () => {
29
31
  });
30
32
  describe("App: Loading Services", () => {
31
33
  it("should be able to use App.loadService(str_url) to load as hosted Service", async () => {
32
- const Service = ServiceFactory();
34
+ const Service = SystemLynxService();
33
35
  const route = "test-service";
34
36
  const port = "8503";
35
37
 
@@ -41,13 +43,13 @@ describe("App: Loading Services", () => {
41
43
  await Service.startService({ route, port });
42
44
 
43
45
  await new Promise((resolve) => {
44
- const App = AppFactory();
46
+ const App = SystemLynxApp();
45
47
  App.loadService("test", `http://localhost:${port}/${route}`).on(
46
48
  "ready",
47
49
  (system) => {
48
- expect(system.Services[0]).to.be.an("object");
50
+ expect(system.services[0]).to.be.an("object");
49
51
 
50
- expect(system.Services[0].client)
52
+ expect(system.services[0].client)
51
53
  .to.be.an("object")
52
54
  .that.has.all.keys("emit", "on", "resetConnection", "disconnect", "mod")
53
55
  .that.respondsTo("emit")
@@ -61,7 +63,7 @@ describe("App: Loading Services", () => {
61
63
  });
62
64
 
63
65
  it("should be able to use App.loadService(...).onLoad(handler) to fire a callback when the Service connects", async () => {
64
- const Service = ServiceFactory();
66
+ const Service = SystemLynxService();
65
67
  const route = "test-service";
66
68
  const port = "8422";
67
69
  const url = `http://localhost:${port}/${route}`;
@@ -74,7 +76,7 @@ describe("App: Loading Services", () => {
74
76
  await Service.startService({ route, port });
75
77
 
76
78
  await new Promise((resolve) => {
77
- const App = AppFactory();
79
+ const App = SystemLynxApp();
78
80
  App.loadService("test", url).onLoad((test) => {
79
81
  expect(test)
80
82
  .to.be.an("object")
@@ -89,7 +91,7 @@ describe("App: Loading Services", () => {
89
91
  });
90
92
 
91
93
  it('should use App.on("service_loaded[:name]", callback) to fire when a Service has loaded', async () => {
92
- const Service = ServiceFactory();
94
+ const Service = SystemLynxService();
93
95
  const route = "test-service";
94
96
  const port = "8423";
95
97
  const url = `http://localhost:${port}/${route}`;
@@ -101,7 +103,7 @@ describe("App: Loading Services", () => {
101
103
  await Service.startService({ route, port });
102
104
 
103
105
  await new Promise((resolve) => {
104
- const App = AppFactory();
106
+ const App = SystemLynxApp();
105
107
  App.loadService("test", url)
106
108
  .on("service_loaded", (test) => {
107
109
  expect(test)
@@ -124,7 +126,7 @@ describe("App: Loading Services", () => {
124
126
  });
125
127
 
126
128
  it("should be accessible to SystemObjects via the module.useService method", async () => {
127
- const Service = ServiceFactory();
129
+ const Service = SystemLynxService();
128
130
  const route = "test-service";
129
131
  const port = "8442";
130
132
  const url = `http://localhost:${port}/${route}`;
@@ -137,7 +139,7 @@ describe("App: Loading Services", () => {
137
139
  await Service.startService({ route, port });
138
140
 
139
141
  await new Promise((resolve) => {
140
- const App = AppFactory();
142
+ const App = SystemLynxApp();
141
143
  App.loadService("test", url)
142
144
  .module("module_name", function () {
143
145
  const test = this.useService("test");
@@ -156,7 +158,7 @@ describe("App: Loading Services", () => {
156
158
 
157
159
  describe("App SystemObjects: Initializing Modules, Modules and configurations", () => {
158
160
  it("should be able to use App.module to initialize a module", async () => {
159
- const App = AppFactory();
161
+ const App = SystemLynxApp();
160
162
  return new Promise((resolve) =>
161
163
  App.module("test", function () {
162
164
  expect(this)
@@ -181,7 +183,7 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
181
183
  );
182
184
  });
183
185
  it("should be able to use App.startService to start as Service", async () => {
184
- const App = AppFactory();
186
+ const App = SystemLynxApp();
185
187
  const route = "test-service";
186
188
  const port = "8493";
187
189
  const url = `http://localhost:${port}/${route}`;
@@ -207,7 +209,7 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
207
209
  expect(connData.serviceUrl).to.equal(url);
208
210
  });
209
211
  it("should be able to use App.module to add a hosted Module to the Service", async () => {
210
- const App = AppFactory();
212
+ const App = SystemLynxApp();
211
213
  const route = "test-service";
212
214
  const port = "8494";
213
215
  const url = `http://localhost:${port}/${route}`;
@@ -252,8 +254,10 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
252
254
  });
253
255
 
254
256
  it('should be able to use App.on("ready", callback) fire a callback when App initialization is complete', async () => {
255
- const App = AppFactory();
256
-
257
+ const App = SystemLynxApp();
258
+ const route = "system-test";
259
+ const port = "4242";
260
+ App.startService({ route, port });
257
261
  App.module("mod", function () {
258
262
  this.test = () => {};
259
263
  this.test2 = () => {};
@@ -267,11 +271,11 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
267
271
  expect(system)
268
272
  .to.be.an("object")
269
273
  .that.has.all.keys(
270
- "Services",
274
+ "services",
271
275
  "Service",
272
- "Modules",
276
+ "modules",
277
+ "connectionData",
273
278
  "configurations",
274
- "App",
275
279
  "routing"
276
280
  );
277
281
  resolve();
@@ -279,8 +283,8 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
279
283
  );
280
284
  });
281
285
 
282
- it("should be able to use App.config(constructor) to construct a configuartion module", async () => {
283
- const App = AppFactory();
286
+ it("should be able to use App.config(constructor) to construct a configuration module", async () => {
287
+ const App = SystemLynxApp();
284
288
 
285
289
  App.module("mod", function () {
286
290
  this.test = () => {};
@@ -310,10 +314,41 @@ describe("App SystemObjects: Initializing Modules, Modules and configurations",
310
314
  );
311
315
  });
312
316
  });
317
+ describe("Use App.use(SystemLynxPlugin), to initializing Modules, and load Services", () => {
318
+ it("should allow for adding new modules and services before app initialization", async () => {
319
+ const Service = SystemLynxService();
320
+ const route = "test-service";
321
+ const port = "8520";
322
+ const pluginUrl = `http://localhost:${port}/${route}`;
323
+ Service.module("mod", function () {
324
+ this.test = () => {};
325
+ this.test2 = () => {};
326
+ });
327
+ await Service.startService({ route, port });
313
328
 
314
- describe("SystemObjects", () => {
329
+ const plugin = (App, system) => {
330
+ App.loadService("PluginService", pluginUrl);
331
+ App.module("plugin", { testMethod: (data) => data });
332
+ };
333
+ await new Promise((resolve) => {
334
+ const App = SystemLynxApp();
335
+ App.module("testModule", { testFunction: () => data })
336
+ .use(plugin)
337
+ .on("ready", (system) => {
338
+ expect(system.services).to.have.lengthOf(1);
339
+ expect(system.services[0]).to.be.an("object");
340
+ expect(system.services[0]).to.have.property("name", "PluginService");
341
+ expect(system.services[0]).to.have.property("url", pluginUrl);
342
+ expect(system.modules).to.have.lengthOf(2);
343
+ expect(system.modules[1]).to.have.property("name", "plugin");
344
+ resolve();
345
+ });
346
+ });
347
+ });
348
+ });
349
+ describe("SystemContext", () => {
315
350
  it("should be able to use this.useModule and this.useService within modules and Module", () => {
316
- const App = AppFactory();
351
+ const App = SystemLynxApp();
317
352
  App.module("mod1", function () {
318
353
  expect(this)
319
354
  .to.be.an("object")
@@ -333,6 +368,7 @@ describe("SystemObjects", () => {
333
368
  const config = this.useConfig();
334
369
  expect(mod1.testPassed).to.equal(true);
335
370
  expect(config.configPassed).to.equal(true);
371
+ this.testPassed = true;
336
372
  })
337
373
  .config(function (next) {
338
374
  expect(this)
@@ -353,7 +389,68 @@ describe("SystemObjects", () => {
353
389
  const config = this.useConfig();
354
390
  expect(mod1.testPassed).to.equal(true);
355
391
  expect(config.configPassed).to.equal(true);
392
+ })
393
+ .on("ready", function () {
394
+ expect(this)
395
+ .to.be.an("object")
396
+ .that.respondsTo("useService")
397
+ .that.respondsTo("useModule")
398
+ .that.respondsTo("useConfig");
399
+ const mod2 = this.useModule("mod2");
400
+ const config = this.useConfig();
401
+ expect(mod2.testPassed).to.equal(true);
402
+ expect(config.configPassed).to.equal(true);
356
403
  });
357
404
  return new Promise((resolve) => App.on("ready", () => resolve()));
358
405
  });
406
+ it("[SystemLynx][App][Client][on] should have access to systemContext during event callbacks.", async () => {
407
+ const AppBackend = SystemLynxApp();
408
+ const eventName = "testing-this";
409
+ const _route = "test-service";
410
+ const _port = "8900";
411
+ const _url = `http://localhost:${_port}/${_route}`;
412
+ AppBackend.module("EventTesterModule", function () {
413
+ this.sendEvent = () => this.emit(eventName, { testPassed: true });
414
+
415
+ //testing local event callback context
416
+ this.on(eventName, function () {
417
+ console.log("Aww man... here we go again!", this);
418
+ expect(this)
419
+ .to.be.an("object")
420
+ .that.respondsTo("useService")
421
+ .that.respondsTo("useModule")
422
+ .that.respondsTo("useConfig");
423
+ });
424
+ });
425
+ await AppBackend.startService({ route: _route, port: _port });
426
+
427
+ const AppClient = SystemLynxApp();
428
+ const route = "test-service";
429
+ const port = "8901";
430
+
431
+ AppClient.startService({ route, port }).loadService("buAPI", _url);
432
+ await new Promise((resolve) =>
433
+ AppClient.on("ready", function () {
434
+ const { EventTesterModule } = this.useService("buAPI");
435
+ EventTesterModule.on(eventName, function (data, event) {
436
+ console.log("Ladies and gentleman... another one!");
437
+ expect(this)
438
+ .to.be.an("object")
439
+ .that.respondsTo("useService")
440
+ .that.respondsTo("useModule")
441
+ .that.respondsTo("useConfig");
442
+ expect(data).to.deep.equal({ testPassed: true });
443
+ expect(event)
444
+ .to.be.an("object")
445
+ .that.has.all.keys("id", "name", "data", "type");
446
+ expect(event.name).to.equal(eventName);
447
+ expect(event.data).to.deep.equal({ testPassed: true });
448
+ expect(event.id).to.be.a("string");
449
+ expect(event.type).to.equal("WebSocket");
450
+ resolve();
451
+ });
452
+ EventTesterModule.sendEvent(eventName);
453
+ })
454
+ );
455
+ });
359
456
  });