systemlynx 1.1.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.
Files changed (41) hide show
  1. package/API.md +142 -0
  2. package/LICENSE +21 -0
  3. package/README.md +180 -0
  4. package/index.js +40 -0
  5. package/index.test.js +121 -0
  6. package/package.json +41 -0
  7. package/systemlynx/App/App.js +76 -0
  8. package/systemlynx/App/components/SystemObject.js +9 -0
  9. package/systemlynx/App/components/initializeApp.js +33 -0
  10. package/systemlynx/App/components/loadModules.js +14 -0
  11. package/systemlynx/App/components/loadServices.js +28 -0
  12. package/systemlynx/App/tests/App.test.js +354 -0
  13. package/systemlynx/Client/Client.js +42 -0
  14. package/systemlynx/Client/components/ClientModule.js +28 -0
  15. package/systemlynx/Client/components/ServiceRequestHandler.js +62 -0
  16. package/systemlynx/Client/components/SocketDispatcher.js +20 -0
  17. package/systemlynx/Client/components/loadConnectionData.js +18 -0
  18. package/systemlynx/Client/tests/Client.test.js +208 -0
  19. package/systemlynx/Client/tests/SocketDispatcher.test.js +54 -0
  20. package/systemlynx/Dispatcher/Dispatcher.js +21 -0
  21. package/systemlynx/Dispatcher/Dispatcher.test.js +21 -0
  22. package/systemlynx/HttpClient/HttpClient.js +44 -0
  23. package/systemlynx/HttpClient/HttpClient.test.js +143 -0
  24. package/systemlynx/HttpClient/test.file.json +1 -0
  25. package/systemlynx/HttpClient/test.server.js +34 -0
  26. package/systemlynx/LoadBalancer/LoadBalancer.js +7 -0
  27. package/systemlynx/LoadBalancer/components/CloneManager.js +49 -0
  28. package/systemlynx/LoadBalancer/components/Router.js +37 -0
  29. package/systemlynx/LoadBalancer/tests/LoadBalancer.test.js +142 -0
  30. package/systemlynx/ServerManager/ServerManager.js +113 -0
  31. package/systemlynx/ServerManager/components/Router.js +89 -0
  32. package/systemlynx/ServerManager/components/Server.js +52 -0
  33. package/systemlynx/ServerManager/components/SocketEmitter.js +19 -0
  34. package/systemlynx/ServerManager/components/WebSocketServer.js +7 -0
  35. package/systemlynx/ServerManager/components/parseMethods.js +19 -0
  36. package/systemlynx/ServerManager/tests/ServerManager.test.js +197 -0
  37. package/systemlynx/ServerManager/tests/SocketEmitter.test.js +29 -0
  38. package/systemlynx/Service/Service.js +28 -0
  39. package/systemlynx/Service/Service.test.js +176 -0
  40. package/temp/.gitignore +4 -0
  41. package/utils/ProcessChecker.js +18 -0
package/API.md ADDED
@@ -0,0 +1,142 @@
1
+ **IN WORKING PROGRESS**
2
+
3
+ # SystemLynx API Documentation
4
+
5
+ Welcome to the docs! Following is a list of the objects used and created when developing web APIs with SystemLynx. SystemLynx is an end-to-end framework for developing modular, microservices software systems in NodeJS. Check out [**Quick Start**](https://github.com/Odion100/SystemLynx#quick-start) for an example of how simple it is to develope object-orientated APIs with SystemLynx.
6
+
7
+ <details>
8
+ <summary><b><a href="https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#app">App</a></b></summary>
9
+
10
+ - [**startService(options)**](https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#appstartserviceoptions)
11
+ - [**loadService(name, url)**](https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#apploadserviceurl)
12
+ - [**onLoad(callback)**](https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md#apponloadcallback)
13
+ - [**ServerModule(name, constructor [,reserved_methods])**]()
14
+ - [**Module(name, constructor)**](https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md#appmodulename-constructor)
15
+ - [**config(constructor)**](https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md#appconfigconstructor)
16
+ - [**on(event, callback)**]()
17
+ - [**emit(event, payload)**]()
18
+
19
+ </details>
20
+
21
+ <details>
22
+ <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md#client">Client</a></b></summary>
23
+
24
+ - [**loadService(url)**]()
25
+
26
+ </details>
27
+
28
+ <details>
29
+ <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md#service">Service</a></b></summary>
30
+
31
+ - [**startService(options)**]()
32
+ - [**ServerModule(name, constructor [,options])**]()
33
+ - [**Server()**]()
34
+ - [**WebSocket()**]()
35
+
36
+ </details>
37
+
38
+ <details>
39
+ <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md#service">LoadBalancer</a></b></summary>
40
+
41
+ - [**startService(options)**]()
42
+ - [**ServerModule(name, constructor [,options])**]()
43
+ - [**Server()**]()
44
+ - [**WebSocket()**]()
45
+ - [**clones**]()
46
+ - [**register(options)**]()
47
+ - [**dispatch(event)**]()
48
+ - [**assignDispatch(event)**]()
49
+
50
+ </details>
51
+
52
+ ---
53
+
54
+ <details>
55
+ <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md">ClientModule</a></b></summary>
56
+
57
+ - [**[created_method]([args...] [,callback])**]()
58
+ - [**on(name, constructor [,options])**]()
59
+ - [**emit()**]()
60
+
61
+ </details>
62
+
63
+ <details>
64
+ <summary><b><a href="https://github.com/Odion100/SystemLynx/tasksjs2.0/API.md">ServerModule</a></b></summary>
65
+
66
+ - [**[created_method]([args...] [,callback])**]()
67
+ - [**on(name, constructor [,options])**]()
68
+ - [**emit()**]()
69
+
70
+ </details>
71
+
72
+ ---
73
+
74
+ ## App
75
+
76
+ **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("sht-tasks")`.
77
+
78
+ ```javascript
79
+ const { App } = require("sht-tasks");
80
+ ```
81
+
82
+ ## App.ServerModule(name, constructor [,reserved_methods])
83
+
84
+ Use **App.ServerModule(name, constructor)** function to create or pass an object that can be loaded by a SystemLynx Client.
85
+
86
+ - **_name_** (string) - name assigned to the module or object
87
+ - **_constructor_** (object/function) -
88
+
89
+ ## App.startService(options)
90
+
91
+ ## App.loadService(name, url)
92
+
93
+ ## App.onLoad(callback)
94
+
95
+ ## App.Module(name, constructor)
96
+
97
+ ## App.config(constructor)
98
+
99
+ ---
100
+
101
+ ## Client
102
+
103
+ ## Client.loadService(url)
104
+
105
+ ---
106
+
107
+ ## Service
108
+
109
+ Service is a SystemLynx abstraction used to server objects that can be loaded by a SystemLynx Client using the `Client.loadService(url)` method.
110
+
111
+ Call require("sht-tasks") and de-concatenate from the object it returns.
112
+
113
+ ```javascript
114
+ const { Service } = require("sht-tasks");
115
+ ```
116
+
117
+ The Service object has the following methods:
118
+
119
+ - **_Service.ServerModule(name, constructor [,reserved_methods])_** - Used to create or pass an object that is hosted by the Service.
120
+ - **_Service.startService(options)_** - Used
121
+ - **_Service.Server()_** - Returns the expressJS app instance used to handle routing to the _Services_.
122
+ - **_Service.WebSocket()_** - Returns socket.io WebSocket instance used to emit events from the _Services_.
123
+
124
+ ## Service.ServerModule(name, constructor [,reserved_methods])
125
+
126
+ - **Name** - String -
127
+ Use the `Service.ServerModule(name, constructor, [,options])` 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.
128
+
129
+ ```javascript
130
+ const { Service } = require("sht-tasks");
131
+
132
+ const Users = {};
133
+
134
+ Users.add = function (data, callback) {
135
+ console.log(data);
136
+ callback(null, { message: "You have successfully called the Users.add method" });
137
+ };
138
+ ```
139
+
140
+ Service.startService
141
+
142
+ ---
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Odion100
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,180 @@
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)
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.
4
+
5
+ SystemLynx comes with the following objects that are used for web API development:
6
+
7
+ ```javascript
8
+ const { App, Service, Client, LoadBalancer } = require("sht-tasks");
9
+ ```
10
+
11
+ Call `require("sht-tasks")` and de-concatenate from the object it returns. The main abstractions used for client-to-server interactions are the following:
12
+
13
+ - **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_, which contains all the objects added to the _Service_.
15
+ - **App** - Provides a modular interface and lifecycle methods for asynchronously creating and loading _Services_.
16
+
17
+ Find the full [API Documentation](https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#tasksjs-api-documentation) here.
18
+
19
+ ---
20
+
21
+ # Quick Start
22
+
23
+ ## Service.ServerModule(name, constructor [,options])
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.
26
+
27
+ ```javascript
28
+ const { Service } = require("sht-tasks");
29
+
30
+ const Users = {};
31
+
32
+ Users.add = function (data, callback) {
33
+ console.log(data);
34
+ callback(null, { message: "You have successfully called the Users.add method" });
35
+ };
36
+
37
+ Service.ServerModule("Users", Users);
38
+ ```
39
+
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
+
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".
44
+
45
+ ```javascript
46
+ const { Service } = require("sht-tasks");
47
+
48
+ const Users = {};
49
+
50
+ Users.add = function (data, callback) {
51
+ console.log(data);
52
+ callback(null, { message: "You have successfully called the Users.add method" });
53
+ };
54
+
55
+ Service.ServerModule("Users", Users);
56
+
57
+ Service.ServerModule("Orders", function () {
58
+ const Orders = this;
59
+
60
+ Orders.find = function (arg1, arg2, callback) {
61
+ console.log(data);
62
+ callback(null, { message: "You have successfully called the Orders.find method" });
63
+ };
64
+ });
65
+ ```
66
+
67
+ In the _ServerModule_ constructor function above, 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_. Notice that the method we created, `Orders.find = function(arg1, arg2, callback)...`, has 3 parameters including a callback function as the last argument. By defualt all _ServerModule_ methods will recieve a callback function as its last argument. Use the first parameter of the callback function to respond with an error, and the second parameter to send a success response. Note: _ServerModule_ methods can be configured to work with synchronous return values instead of asynchronous callbacks (read more about Service configuration [here](https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#apploadserviceurl)).
68
+
69
+ ## Service.startService(options)
70
+
71
+ Before we can access the objects hosted by this _Service_ from a client application, we need to call the `Service.startService(options)` function. This will start an **ExpressJS** Server and a **Socket.io** WebSocket Server, and set up routing for the _Service_. In the example below we added the `Service.startService(options)` function at the bottom, but the order does not matter.
72
+
73
+ ```javascript
74
+ const { Service } = require("sht-tasks");
75
+
76
+ const Users = {};
77
+
78
+ Users.add = function (data, callback) {
79
+ console.log(data);
80
+ callback(null, { message: "You have successfully called the Users.add method" });
81
+ };
82
+
83
+ Service.ServerModule("Users", Users);
84
+
85
+ Service.ServerModule("Orders", function () {
86
+ const Orders = this;
87
+
88
+ Orders.find = function (arg1, arg2, callback) {
89
+ console.log(data);
90
+ callback(null, { message: "You have successfully called the Orders.find method" });
91
+ };
92
+ });
93
+
94
+ Service.startService({ route: "test/service", port: "4400", host: "localhost" });
95
+ ```
96
+
97
+ Now lets see how these objects can be loaded into a client application.
98
+
99
+ ## Client.loadService(url, [options])
100
+
101
+ The `Client.loadService(url)` function can be used to load a SystemLynx _Service_. This method requires the url (string) of the _Service_ you want to load as the first argument, and will return a promise that will resolve into an object that containing all the modules hosted by that service. See below. **NOTE: You must be within an async function in order to use the `await` keyword when returning a promise.**
102
+
103
+ ```javascript
104
+ const { Client } = require("sht-tasks");
105
+
106
+ const { Users, Orders } = await Client.loadService("http://localhost:4400/test/service");
107
+
108
+ console.log(Users, Orders);
109
+ ```
110
+
111
+ Now that we've loaded the _Service_ that we created in the previous example, and have a handle on the _Users_ and _Orders_ objects hosted by the _Service_, we can now call any method on those objects. In the example below, we demonstrate that when a methods for the ServerModule objects is called from the client, it can optionally take a callback as the last argument or, if a callback is not used, it will return a promise. With the `Users.add(data, callback)` method we used a callback, but with the `Orders.find(arg1, arg2, callback)` method we left out the callback function and used the `await` keyword to return a promise.
112
+
113
+ ```javascript
114
+ const { Client } = require("sht-tasks");
115
+
116
+ const { Users, Orders } = await Client.loadService("http://localhost:4400/test/service");
117
+
118
+ console.log(Users, Orders);
119
+
120
+ Users.add({ message: "Users.add Test" }, function (err, results) {
121
+ if (err) console.log(err);
122
+ else console.log(results);
123
+ });
124
+
125
+ const response = await Orders.find("hello", "world");
126
+
127
+ console.log(response);
128
+ ```
129
+
130
+ ## Sending and Receiving Websocket Events
131
+
132
+ We can also receive WebSocket events emitted from the remote objects we've loaded using the `Client.loadService(url)` function. In the example below we're using the `Users.on(event_name, callback)` method to listen for events coming from the "Users" _ServerModule_.
133
+
134
+ ```javascript
135
+ const { Client } = require("sht-tasks");
136
+
137
+ const { Users, Orders } = await Client.loadService("http://localhost:4400/test/service");
138
+
139
+ console.log(Users, Orders);
140
+
141
+ Users.add({ message: "Users.add Test" }, function (err, results) {
142
+ if (err) console.log(err);
143
+ else console.log(results);
144
+ });
145
+
146
+ Users.on("new_user", function (event) {
147
+ console.log(event);
148
+ });
149
+
150
+ const response = await Orders.find("hello", "world");
151
+
152
+ console.log(response);
153
+ ```
154
+
155
+ 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 `Users.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.
156
+
157
+ ```javascript
158
+ const { Service } = require("sht-tasks");
159
+
160
+ const Users = {};
161
+
162
+ Users.add = function (data, callback) {
163
+ console.log(data);
164
+ callback(null, { message: "You have successfully called the Users.add method" });
165
+ Users.emit("new_user", { message: "new_user event test" });
166
+ };
167
+
168
+ Service.ServerModule("Users", Users);
169
+
170
+ Service.ServerModule("Orders", function () {
171
+ const Orders = this;
172
+
173
+ Orders.find = function (arg1, arg2, callback) {
174
+ console.log(data);
175
+ callback(null, { message: "You have successfully called the Orders.find method" });
176
+ };
177
+ });
178
+
179
+ Service.startService({ route: "test/service", port: "4400", host: "localhost" });
180
+ ```
package/index.js ADDED
@@ -0,0 +1,40 @@
1
+ //These are all the abstractions that make up SystemLynx
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");
10
+
11
+ const ServerManager = isNode ? ServerManagerFactory() : null;
12
+ const Service = isNode ? ServiceFactory() : null;
13
+ const LoadBalancer = isNode ? LoadBalancerFactory() : null;
14
+
15
+ const App = AppFactory();
16
+ const HttpClient = HttpClientFactory();
17
+ const Client = ClientFactory();
18
+ const Dispatcher = DispatcherFactory();
19
+
20
+ module.exports = {
21
+ //Export these pre-created objects for convenient object destructuring
22
+ //These are the main utilities for app development
23
+ App,
24
+ HttpClient,
25
+ LoadBalancer,
26
+ Client,
27
+ Service,
28
+ ServerManager,
29
+ Dispatcher,
30
+ //export all modules themselves
31
+ //all these modules export factory functions
32
+ //to ensure non-singleton behavior
33
+ AppFactory,
34
+ LoadBalancerFactory,
35
+ ServiceFactory,
36
+ ClientFactory,
37
+ HttpClientFactory,
38
+ ServerManagerFactory,
39
+ DispatcherFactory,
40
+ };
package/index.test.js ADDED
@@ -0,0 +1,121 @@
1
+ const { expect } = require("chai");
2
+ const {
3
+ App,
4
+ HttpClient,
5
+ LoadBalancer,
6
+ Client,
7
+ Service,
8
+ ServerManager,
9
+ AppFactory,
10
+ LoadBalancerFactory,
11
+ ServiceFactory,
12
+ ClientFactory,
13
+ HttpClientFactory,
14
+ ServerManagerFactory,
15
+ } = require("./index");
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");
25
+ });
26
+
27
+ it("should return an instance of each SystemLynx abstraction", () => {});
28
+ });
29
+
30
+ describe("SystemLynx Objects", () => {
31
+ it("should return a SystemLynx App", () => {
32
+ expect(App)
33
+ .to.be.an("object")
34
+ .that.has.all.keys(
35
+ "module",
36
+ "ServerModule",
37
+ "on",
38
+ "emit",
39
+ "startService",
40
+ "loadService",
41
+ "onLoad",
42
+ "config"
43
+ )
44
+ .that.respondsTo("module")
45
+ .that.respondsTo("ServerModule")
46
+ .that.respondsTo("on")
47
+ .that.respondsTo("emit")
48
+ .that.respondsTo("startService")
49
+ .that.respondsTo("loadService")
50
+ .that.respondsTo("onLoad")
51
+ .that.respondsTo("config");
52
+ });
53
+
54
+ it("should return a SystemLynx Client", () => {
55
+ expect(Client)
56
+ .to.be.an("object")
57
+ .that.has.property("loadService")
58
+ .that.is.a("function");
59
+ });
60
+
61
+ it("should return a HttpClient instance", () => {
62
+ expect(HttpClient)
63
+ .to.be.an("Object")
64
+ .that.has.all.keys("request", "upload")
65
+ .that.respondsTo("request")
66
+ .that.respondsTo("upload");
67
+ });
68
+
69
+ it("should return a SystemLynx LoadBalancer", () => {
70
+ expect(LoadBalancer)
71
+ .to.be.an("object")
72
+ .that.has.all.keys(
73
+ "startService",
74
+ "Server",
75
+ "WebSocket",
76
+ "defaultModule",
77
+ "ServerModule",
78
+ "clones"
79
+ )
80
+ .that.respondsTo("startService")
81
+ .that.respondsTo("Server")
82
+ .that.respondsTo("WebSocket")
83
+ .that.respondsTo("ServerModule");
84
+ expect(LoadBalancer.clones)
85
+ .to.be.an("object")
86
+ .that.has.all.keys("on", "emit", "clones", "register", "dispatch", "assignDispatch")
87
+ .that.respondsTo("emit")
88
+ .that.respondsTo("on")
89
+ .that.respondsTo("register")
90
+ .that.respondsTo("dispatch")
91
+ .that.respondsTo("assignDispatch")
92
+ .that.has.property("clones")
93
+ .that.is.an("array");
94
+ });
95
+
96
+ it("should return a SystemLynx ServerManager instance", () => {
97
+ expect(ServerManager)
98
+ .to.be.an("Object")
99
+ .that.has.all.keys(["startService", "addModule", "Server", "WebSocket"])
100
+ .that.respondsTo("startService")
101
+ .that.respondsTo("addModule")
102
+ .that.respondsTo("Server")
103
+ .that.respondsTo("WebSocket");
104
+ });
105
+
106
+ it("should return a new instance of a Service", () => {
107
+ expect(Service)
108
+ .to.be.an("object")
109
+ .that.has.all.keys(
110
+ "startService",
111
+ "ServerModule",
112
+ "Server",
113
+ "WebSocket",
114
+ "defaultModule"
115
+ )
116
+ .that.respondsTo("startService")
117
+ .that.respondsTo("ServerModule")
118
+ .that.respondsTo("Server")
119
+ .that.respondsTo("WebSocket");
120
+ });
121
+ });
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "systemlynx",
3
+ "version": "1.1.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js",
8
+ "test": "jest --verbose --testPathIgnorePatterns 'client-setup.test.js'"
9
+ },
10
+ "dependencies": {
11
+ "body-parser": "^1.18.3",
12
+ "chai-as-promised": "^7.1.1",
13
+ "express": "^4.16.4",
14
+ "jest": "^24.9.0",
15
+ "mime": "^2.4.0",
16
+ "multer": "^1.4.2",
17
+ "request": "^2.88.0",
18
+ "shortid": "^2.2.14",
19
+ "socket.io": "^2.2.0"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Odion100/SystemLynx.git"
24
+ },
25
+ "author": "odion edwards",
26
+ "license": "ISC",
27
+ "bugs": {
28
+ "url": "https://github.com/Odion100/SystemLynx/issues"
29
+ },
30
+ "homepage": "https://github.com/Odion100/SystemLynx#readme",
31
+ "devDependencies": {
32
+ "chai": "^4.3.4",
33
+ "cz-conventional-changelog": "^3.3.0",
34
+ "mocha": "^6.2.0"
35
+ },
36
+ "config": {
37
+ "commitizen": {
38
+ "path": "./node_modules/cz-conventional-changelog"
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ const { isNode } = require("../../utils/ProcessChecker");
3
+ const ServiceFactory = require("../Service/Service");
4
+ const SystemObject = require("./components/SystemObject");
5
+ const Dispatcher = require("../Dispatcher/Dispatcher");
6
+ const initializeApp = require("./components/initializeApp");
7
+ const URL = require("url");
8
+
9
+ module.exports = function SystemLynxApp() {
10
+ const App = Dispatcher();
11
+ const system = {
12
+ Services: [],
13
+ Modules: [],
14
+ ServerModules: [],
15
+ configurations: {},
16
+ App,
17
+ routing: null,
18
+ };
19
+ SystemObject.apply(system, [system]);
20
+ setTimeout(() => initializeApp(system), 0);
21
+
22
+ if (isNode) {
23
+ system.Service = ServiceFactory();
24
+ system.Service.defaultModule = SystemObject(system);
25
+
26
+ App.startService = (options) => {
27
+ system.routing = options;
28
+ return App;
29
+ };
30
+
31
+ App.ServerModule = (name, __constructor) => {
32
+ system.ServerModules.push({
33
+ name,
34
+ __constructor,
35
+ });
36
+ return App;
37
+ };
38
+ }
39
+
40
+ App.loadService = (name, url) => {
41
+ system.Services.push({
42
+ name,
43
+ url,
44
+ onLoad: null,
45
+ client: {},
46
+ });
47
+ return App;
48
+ };
49
+
50
+ App.onLoad = (handler) => {
51
+ const service = system.Services[system.Services.length - 1];
52
+ service.onLoad = handler;
53
+ return App;
54
+ };
55
+
56
+ App.module = (name, __constructor) => {
57
+ system.Modules.push({
58
+ name,
59
+ __constructor,
60
+ module: SystemObject(system),
61
+ });
62
+ return App;
63
+ };
64
+
65
+ App.config = (__constructor) => {
66
+ if (typeof __constructor === "function")
67
+ system.configurations = { __constructor, module: SystemObject(system) };
68
+ else
69
+ throw Error(
70
+ "App.config methods requires a constructor function as it first parameter."
71
+ );
72
+ return App;
73
+ };
74
+
75
+ return App;
76
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ module.exports = function SystemObject(system) {
3
+ const App = this || {};
4
+ App.useModule = modName => (system.Modules.find(mod => mod.name === modName) || {}).module || {};
5
+ App.useService = serviceName =>
6
+ (system.Services.find(mod => mod.name === serviceName) || {}).client || {};
7
+ App.useConfig = () => system.configurations.module || {};
8
+ return App;
9
+ };
@@ -0,0 +1,33 @@
1
+ const loadModules = require("./loadModules");
2
+ const loadServices = require("./loadServices");
3
+
4
+ module.exports = async function initApp(system) {
5
+ let configComplete = false;
6
+ const continuationERROR = () => {
7
+ if (!configComplete)
8
+ console.warn(
9
+ `
10
+ continuationERROR: Failed to call continuation function in App Configuariotn module
11
+
12
+ Fix: Must call next function during App.config( constructor(=>next) )
13
+
14
+ `
15
+ );
16
+ };
17
+
18
+ try {
19
+ await loadServices(system);
20
+ } catch (err) {
21
+ throw `(AppERROR): Initialization Error - failed to load all services`;
22
+ }
23
+
24
+ if (typeof system.configurations.__constructor === "function") {
25
+ setTimeout(continuationERROR, 0);
26
+ system.configurations.__constructor.apply(system.configurations.module, [
27
+ () => {
28
+ configComplete = true;
29
+ loadModules(system);
30
+ }
31
+ ]);
32
+ } else loadModules(system);
33
+ };
@@ -0,0 +1,14 @@
1
+ const Dispatcher = require("../../Dispatcher/Dispatcher");
2
+
3
+ module.exports = async function loadModules(system) {
4
+ system.Modules.forEach((mod) => {
5
+ Dispatcher.apply(mod.module);
6
+ mod.__constructor.apply(mod.module);
7
+ });
8
+
9
+ system.ServerModules.forEach(({ name, __constructor }) =>
10
+ system.Service.ServerModule(name, __constructor)
11
+ );
12
+ if (system.routing) await system.Service.startService(system.routing);
13
+ system.App.emit("init_complete", system);
14
+ };