systemlynx 1.1.0 → 1.3.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
@@ -73,10 +73,10 @@ Welcome to the docs! Following is a list of the objects used and created when de
73
73
 
74
74
  ## App
75
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")`.
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("systemlynx")`.
77
77
 
78
78
  ```javascript
79
- const { App } = require("sht-tasks");
79
+ const { App } = require("systemlynx");
80
80
  ```
81
81
 
82
82
  ## App.ServerModule(name, constructor [,reserved_methods])
@@ -108,10 +108,10 @@ Use **App.ServerModule(name, constructor)** function to create or pass an object
108
108
 
109
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
110
 
111
- Call require("sht-tasks") and de-concatenate from the object it returns.
111
+ Call require("systemlynx") and de-concatenate from the object it returns.
112
112
 
113
113
  ```javascript
114
- const { Service } = require("sht-tasks");
114
+ const { Service } = require("systemlynx");
115
115
  ```
116
116
 
117
117
  The Service object has the following methods:
@@ -127,7 +127,7 @@ The Service object has the following methods:
127
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
128
 
129
129
  ```javascript
130
- const { Service } = require("sht-tasks");
130
+ const { Service } = require("systemlynx");
131
131
 
132
132
  const Users = {};
133
133
 
package/README.md CHANGED
@@ -5,14 +5,14 @@ SystemLynx is a framework for developing modular web APIs. It's a wrapper on top
5
5
  SystemLynx comes with the following objects that are used for web API development:
6
6
 
7
7
  ```javascript
8
- const { App, Service, Client, LoadBalancer } = require("sht-tasks");
8
+ const { App, Service, Client, LoadBalancer } = require("systemlynx");
9
9
  ```
10
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:
11
+ Call `require("systemlynx")` and de-concatenate 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
- - **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_.
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
16
 
17
17
  Find the full [API Documentation](https://github.com/Odion100/SystemLynx/blob/tasksjs2.0/API.md#tasksjs-api-documentation) here.
18
18
 
@@ -22,16 +22,16 @@ 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 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
26
 
27
27
  ```javascript
28
- const { Service } = require("sht-tasks");
28
+ const { Service } = require("systemlynx");
29
29
 
30
30
  const Users = {};
31
31
 
32
- Users.add = function (data, callback) {
32
+ Users.add = function (data) {
33
33
  console.log(data);
34
- callback(null, { message: "You have successfully called the Users.add method" });
34
+ return { message: "You have successfully called the Users.add method" };
35
35
  };
36
36
 
37
37
  Service.ServerModule("Users", Users);
@@ -39,17 +39,17 @@ 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".
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.
44
44
 
45
45
  ```javascript
46
- const { Service } = require("sht-tasks");
46
+ const { Service } = require("systemlynx");
47
47
 
48
48
  const Users = {};
49
49
 
50
- Users.add = function (data, callback) {
50
+ Users.add = function (data) {
51
51
  console.log(data);
52
- callback(null, { message: "You have successfully called the Users.add method" });
52
+ return { message: "You have successfully called the Users.add method" };
53
53
  };
54
54
 
55
55
  Service.ServerModule("Users", Users);
@@ -57,27 +57,25 @@ Service.ServerModule("Users", Users);
57
57
  Service.ServerModule("Orders", function () {
58
58
  const Orders = this;
59
59
 
60
- Orders.find = function (arg1, arg2, callback) {
60
+ Orders.find = async function (arg1, arg2) {
61
61
  console.log(data);
62
- callback(null, { message: "You have successfully called the Orders.find method" });
62
+ return { message: "You have successfully called the Orders.find method" };
63
63
  };
64
64
  });
65
65
  ```
66
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
67
  ## Service.startService(options)
70
68
 
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.
69
+ 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
70
 
73
71
  ```javascript
74
- const { Service } = require("sht-tasks");
72
+ const { Service } = require("systemlynx");
75
73
 
76
74
  const Users = {};
77
75
 
78
- Users.add = function (data, callback) {
76
+ Users.add = function (data) {
79
77
  console.log(data);
80
- callback(null, { message: "You have successfully called the Users.add method" });
78
+ return { message: "You have successfully called the Users.add method" };
81
79
  };
82
80
 
83
81
  Service.ServerModule("Users", Users);
@@ -85,9 +83,9 @@ Service.ServerModule("Users", Users);
85
83
  Service.ServerModule("Orders", function () {
86
84
  const Orders = this;
87
85
 
88
- Orders.find = function (arg1, arg2, callback) {
86
+ Orders.find = function (arg1, arg2) {
89
87
  console.log(data);
90
- callback(null, { message: "You have successfully called the Orders.find method" });
88
+ return { message: "You have successfully called the Orders.find method" };
91
89
  };
92
90
  });
93
91
 
@@ -98,29 +96,28 @@ Now lets see how these objects can be loaded into a client application.
98
96
 
99
97
  ## Client.loadService(url, [options])
100
98
 
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.**
99
+ 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
100
 
103
101
  ```javascript
104
- const { Client } = require("sht-tasks");
102
+ const { Client } = require("systemlynx");
105
103
 
106
104
  const { Users, Orders } = await Client.loadService("http://localhost:4400/test/service");
107
105
 
108
106
  console.log(Users, Orders);
109
107
  ```
110
108
 
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.
109
+ 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 same way we would remotely. In the example below, noticed that both the `User.add` and `Orders.find` methods will return a promise.
112
110
 
113
111
  ```javascript
114
- const { Client } = require("sht-tasks");
112
+ const { Client } = require("systemlynx");
115
113
 
116
114
  const { Users, Orders } = await Client.loadService("http://localhost:4400/test/service");
117
115
 
118
116
  console.log(Users, Orders);
119
117
 
120
- Users.add({ message: "Users.add Test" }, function (err, results) {
121
- if (err) console.log(err);
122
- else console.log(results);
123
- });
118
+ const results = await Users.add({ message: "Users.add Test" });
119
+
120
+ console.log(results);
124
121
 
125
122
  const response = await Orders.find("hello", "world");
126
123
 
@@ -129,19 +126,18 @@ console.log(response);
129
126
 
130
127
  ## Sending and Receiving Websocket Events
131
128
 
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_.
129
+ 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
130
 
134
131
  ```javascript
135
- const { Client } = require("sht-tasks");
132
+ const { Client } = require("systemlynx");
136
133
 
137
134
  const { Users, Orders } = await Client.loadService("http://localhost:4400/test/service");
138
135
 
139
136
  console.log(Users, Orders);
140
137
 
141
- Users.add({ message: "Users.add Test" }, function (err, results) {
142
- if (err) console.log(err);
143
- else console.log(results);
144
- });
138
+ const results = await Users.add({ message: "Users.add Test" });
139
+
140
+ console.log(results);
145
141
 
146
142
  Users.on("new_user", function (event) {
147
143
  console.log(event);
@@ -152,17 +148,17 @@ const response = await Orders.find("hello", "world");
152
148
  console.log(response);
153
149
  ```
154
150
 
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.
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.
156
152
 
157
153
  ```javascript
158
- const { Service } = require("sht-tasks");
154
+ const { Service } = require("systemlynx");
159
155
 
160
156
  const Users = {};
161
157
 
162
- Users.add = function (data, callback) {
158
+ Users.add = function (data) {
163
159
  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" });
160
+ return { message: "You have successfully called the Users.add method" };
161
+ this.emit("new_user", { message: "new_user event test" });
166
162
  };
167
163
 
168
164
  Service.ServerModule("Users", Users);
@@ -170,9 +166,9 @@ Service.ServerModule("Users", Users);
170
166
  Service.ServerModule("Orders", function () {
171
167
  const Orders = this;
172
168
 
173
- Orders.find = function (arg1, arg2, callback) {
169
+ Orders.find = function (arg1, arg2) {
174
170
  console.log(data);
175
- callback(null, { message: "You have successfully called the Orders.find method" });
171
+ return { message: "You have successfully called the Orders.find method" };
176
172
  };
177
173
  });
178
174
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systemlynx",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,5 +10,5 @@ module.exports = async function loadModules(system) {
10
10
  system.Service.ServerModule(name, __constructor)
11
11
  );
12
12
  if (system.routing) await system.Service.startService(system.routing);
13
- system.App.emit("init_complete", system);
13
+ system.App.emit("ready", system);
14
14
  };
@@ -45,7 +45,7 @@ describe("App: Loading Services", () => {
45
45
  await new Promise((resolve) => {
46
46
  const App = AppFactory();
47
47
  App.loadService("test", `http://localhost:${port}/${route}`).on(
48
- "init_complete",
48
+ "ready",
49
49
  (system) => {
50
50
  expect(system.Services[0]).to.be.an("object");
51
51
 
@@ -151,7 +151,7 @@ describe("App: Loading Services", () => {
151
151
  .that.respondsTo("resetConnection");
152
152
  resolve();
153
153
  })
154
- .on("init_complete", resolve);
154
+ .on("ready", resolve);
155
155
  });
156
156
  });
157
157
  });
@@ -189,7 +189,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
189
189
  const url = `http://localhost:${port}/${route}`;
190
190
 
191
191
  await new Promise((resolve) =>
192
- App.startService({ route, port }).on("init_complete", resolve)
192
+ App.startService({ route, port }).on("ready", resolve)
193
193
  );
194
194
  const connData = await HttpClient.request({ url });
195
195
 
@@ -223,7 +223,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
223
223
  this.test = () => {};
224
224
  this.test2 = () => {};
225
225
  })
226
- .on("init_complete", resolve)
226
+ .on("ready", resolve)
227
227
  );
228
228
 
229
229
  const connData = await HttpClient.request({ url });
@@ -253,7 +253,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
253
253
  ]);
254
254
  });
255
255
 
256
- it('should be able to use App.on("init_complete", callback) fire a callback when App initialization is complete', async () => {
256
+ it('should be able to use App.on("ready", callback) fire a callback when App initialization is complete', async () => {
257
257
  const App = AppFactory();
258
258
 
259
259
  App.ServerModule("mod", function () {
@@ -265,7 +265,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
265
265
  });
266
266
 
267
267
  await new Promise((resolve) =>
268
- App.on("init_complete", (system) => {
268
+ App.on("ready", (system) => {
269
269
  expect(system)
270
270
  .to.be.an("object")
271
271
  .that.has.all.keys(
@@ -303,7 +303,7 @@ describe("App SystemObjects: Initializing Modules, ServerModules and configurat
303
303
  });
304
304
 
305
305
  await new Promise((resolve) =>
306
- App.on("init_complete", ({ configurations }) => {
306
+ App.on("ready", ({ configurations }) => {
307
307
  expect(configurations)
308
308
  .to.be.an("object")
309
309
  .that.has.all.keys("module", "__constructor")
@@ -349,6 +349,6 @@ describe("SystemObjects", () => {
349
349
  this.configPassed = true;
350
350
  next();
351
351
  });
352
- return new Promise((resolve) => App.on("init_complete", () => resolve()));
352
+ return new Promise((resolve) => App.on("ready", () => resolve()));
353
353
  });
354
354
  });
@@ -16,10 +16,7 @@ module.exports = function SystemLynxServerManager() {
16
16
  useREST: false,
17
17
  useService: true,
18
18
  staticRouting: false,
19
- validateArgs: true,
20
19
  middleware: [],
21
- useCallbacks: true,
22
- useReturnValues: false,
23
20
  };
24
21
  const server = SystemLynxServer();
25
22
  const router = SystemLynxRouter(server, () => serverConfigurations);