systemlynx 1.3.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 CHANGED
@@ -1,8 +1,8 @@
1
- # SystemLynx ![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)
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. It's a wrapper on top of ExpressJS and Socket.io. With SystemLynx, instead of creating a server with many endpoints, you can simply export objects from the server to the client application. Basically any objects added to 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 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 API development:
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");
@@ -22,7 +22,7 @@ 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 register an object to be hosted by a **SystemLynx Service**. This will allows you to load an instance of that object onto a client application, and call any methods on that object remotely.
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");
@@ -39,8 +39,7 @@ 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 **ServerModule** called
43
- "Orders". This time we use a constructor function as the second argument of the to **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.
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");
@@ -148,7 +147,7 @@ const response = await Orders.find("hello", "world");
148
147
  console.log(response);
149
148
  ```
150
149
 
151
- Now let's go to our server application and call the `this.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.
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.
152
151
 
153
152
  ```javascript
154
153
  const { Service } = require("systemlynx");
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 AppFactory = require("./systemlynx/App/App");
4
- const LoadBalancerFactory = require("./systemlynx/LoadBalancer/LoadBalancer");
5
- const ServiceFactory = require("./systemlynx/Service/Service");
6
- const ServerManagerFactory = require("./systemlynx/ServerManager/ServerManager");
7
- const ClientFactory = require("./systemlynx/Client/Client");
8
- const HttpClientFactory = require("./systemlynx/HttpClient/HttpClient");
9
- const DispatcherFactory = require("./systemlynx/Dispatcher/Dispatcher");
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 ? ServerManagerFactory() : null;
12
- const Service = isNode ? ServiceFactory() : null;
13
- const LoadBalancer = isNode ? LoadBalancerFactory() : null;
11
+ const ServerManager = isNode ? SystemLynxServerManager() : null;
12
+ const Service = isNode ? SystemLynxService() : null;
13
+ const LoadBalancer = isNode ? SystemLynxLoadBalancer() : null;
14
14
 
15
- const App = AppFactory();
16
- const HttpClient = HttpClientFactory();
17
- const Client = ClientFactory();
18
- const Dispatcher = DispatcherFactory();
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
- AppFactory,
34
- LoadBalancerFactory,
35
- ServiceFactory,
36
- ClientFactory,
37
- HttpClientFactory,
38
- ServerManagerFactory,
39
- DispatcherFactory,
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
- AppFactory,
10
- LoadBalancerFactory,
11
- ServiceFactory,
12
- ClientFactory,
13
- HttpClientFactory,
14
- ServerManagerFactory,
9
+ SystemLynxApp,
10
+ SystemLynxLoadBalancer,
11
+ SystemLynxService,
12
+ SystemLynxClient,
13
+ SystemLynxHttpClient,
14
+ SystemLynxServerManager,
15
15
  } = require("./index");
16
16
 
17
- describe("SystemLynx Factory functions", () => {
18
- it("should return a factory functions for each SystemLynx abstraction", () => {
19
- expect(AppFactory).to.be.a("function");
20
- expect(LoadBalancerFactory).to.be.a("function");
21
- expect(ServiceFactory).to.be.a("function");
22
- expect(ClientFactory).to.be.a("function");
23
- expect(HttpClientFactory).to.be.a("function");
24
- expect(ServerManagerFactory).to.be.a("function");
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systemlynx",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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 it first parameter."
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 `(AppERROR): Initialization Error - failed to load all services`;
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
  };
@@ -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(`(SystemLynxServiceError): Invalid route:${err}`);
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 loadConnectionData() Error: url:${url}, attempts:${errors.length}`;
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
- "SystemLynxDispatcher Error: object.on(eventName, callback) invalid parameters"
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);
@@ -63,7 +63,7 @@ module.exports = function SystemLynxServerManager() {
63
63
 
64
64
  return new Promise((resolve) =>
65
65
  server.listen(port, () => {
66
- console.log(`(SystemLynxService): ${route} --> Listening on ${host}:${port}`);
66
+ console.log(`[SystemLynx][Service]: Listening on ${serviceUrl}`);
67
67
  moduleQueue.forEach(({ name, object, reserved_methods }) =>
68
68
  ServerManager.addModule(name, object, reserved_methods)
69
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 `(ServerModule Error): ServerModule(name, constructor) function requires a non-async function as the constructor`;
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 = [...reserved_methods, ...Object.getOwnPropertyNames(ServerModule)];
22
- constructor.apply(ServerModule, [ServerManager.Server(), ServerManager.WebSocket()]);
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
  }