telos-server 1.0.10 → 1.0.12

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
@@ -9,10 +9,11 @@ which operates on a declarative file system based CMS.
9
9
 
10
10
  ## 2 - Contents
11
11
 
12
- ### 2.1 - Content
12
+ ### 2.1 - Telos Folder
13
13
 
14
- Telos Server shall source its content and endpoints from a folder on disk, which by default shall
15
- be called "telos", and shall be stored in the same directory the server process runs from.
14
+ Telos Server shall source its content and endpoints from a Telos folder, stored on disk, which by
15
+ default shall be called "telos", and shall be stored in the same directory the server process runs
16
+ from.
16
17
 
17
18
  File names in the telos folder shall have their names segmented into chunks by periods, with the
18
19
  first chunk specifying the name of the file, the last chunk specifying the extension, and each
@@ -57,15 +58,41 @@ blank response.
57
58
 
58
59
  If a file has the property "private", it shall be inaccessible from the client.
59
60
 
60
- ##### 2.1.2.3 - Universal Preprocessor
61
+ ##### 2.1.2.3 - Task
62
+
63
+ If a JS file has the property "task", it shall serve as a script in a persistent background
64
+ process. It shall use Common JS to assign as the module exports a single function which, at regular
65
+ intervals, shall be invoked by an event handler responsive to the Telos engine.
66
+
67
+ ##### 2.1.2.4 - Universal Preprocessor
61
68
 
62
69
  If a file has the property "pup", it will be processed by the
63
70
  [Universal Preprocessor](https://github.com/Telos-Project/Universal-Preprocessor) before being
64
71
  fetched.
65
72
 
66
- ### 2.2 - Usage
73
+ ### 2.2 - Telos Engine
74
+
75
+ The Telos engine is a background process embedded in an associated bus module, which is integrated
76
+ into, but may be used independently of, Telos Server.
77
+
78
+ The Telos engine, at regular intervals, calls the bus net of Telos Origin with the following
79
+ object:
80
+
81
+ { tags: ["telos-engine"] }
82
+
83
+ The Telos engine also stores a reference to the initialization call object of Telos Origin, which
84
+ shall be returned from the Telos engine bus module query function if the following object is passed
85
+ to it:
86
+
87
+ { tags: ["telos-configuration"] }
88
+
89
+ The default interval for the Telos engine is 60 times per second. This may be altered using a
90
+ number assigned to the content.options.options.engineInterval field in the initialization call
91
+ object of Telos Origin specifying how long in seconds to wait between each interval.
92
+
93
+ ### 2.3 - Usage
67
94
 
68
- #### 2.2.1 - Setup
95
+ #### 2.3.1 - Setup
69
96
 
70
97
  First, create a folder for your project. Within this folder, create your "telos" folder, and
71
98
  populate it with the content you intend to serve.
@@ -83,12 +110,12 @@ the following command before uploading your project:
83
110
 
84
111
  npx telos-origin -m wrap
85
112
 
86
- #### 2.2.2 - Configuration
113
+ #### 2.3.2 - Configuration
87
114
 
88
115
  The default port can be reconfigured with a Telos Config utility with the desired port specified as
89
116
  a numerical field in the properties with the alias "port".
90
117
 
91
- #### 2.2.3 - Middleware
118
+ #### 2.3.3 - Middleware
92
119
 
93
120
  Telos Server may be extended through middleware referenced in the Telos Origin APInt.
94
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telos-server",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "An Extensible CMS Server for Telos Origin.",
5
5
  "main": "telosServer.json",
6
6
  "dependencies": {
@@ -1,7 +1,6 @@
1
1
  var fs = use("fs");
2
2
  var path = use("path");
3
3
  var pup = require("universal-preprocessor");
4
- var pupLangs = require("universal-preprocessor/pupLangs");
5
4
 
6
5
  let extensionTypes = {
7
6
  'txt': 'text/plain',
@@ -161,7 +160,7 @@ function middlewareText(packet, file) {
161
160
  function preprocess(string, file) {
162
161
 
163
162
  return (file != null ? file.meta.pup != null : true) ?
164
- pup.preprocess(pupLangs, string) : string;
163
+ pup.preprocess(string) : string;
165
164
  }
166
165
 
167
166
  module.exports = {
package/telosServer.js CHANGED
@@ -9,102 +9,127 @@ var telosServer = {
9
9
 
10
10
  serverUtils.processRequest(request, "http", (data) => {
11
11
 
12
- let responses = busNet.call(data);
12
+ (new Promise((resolve, reject) => {
13
13
 
14
- let status = 200;
14
+ let results = busNet.call(data);
15
+ let responses = [];
15
16
 
16
- let headers = {
17
- 'Content-Type': 'text/plain',
18
- 'Access-Control-Allow-Origin': '*',
19
- 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE'
20
- };
17
+ results.forEach(item => {
21
18
 
22
- let body = [];
23
- let file = false;
19
+ if(item instanceof Promise) {
24
20
 
25
- let max = -Infinity;
21
+ item.then((result => {
26
22
 
27
- responses.filter(item => item != null).forEach(item => {
23
+ responses.push(result);
28
24
 
29
- item.priority = item.priority != null ? item.priority : 0;
25
+ if(responses.length == results.length)
26
+ resolve(responses);
27
+ }));
28
+ }
29
+
30
+ else
31
+ responses.push(item);
30
32
 
31
- if(item.priority > max)
32
- max = item.priority;
33
- });
33
+ if(responses.length == results.length)
34
+ resolve(responses);
35
+ });
36
+ })).then((responses) => {
34
37
 
35
- responses.filter(
36
- item => {
38
+ let status = 200;
37
39
 
38
- if(item == null)
39
- return
40
+ let headers = {
41
+ 'Content-Type': 'text/plain',
42
+ 'Access-Control-Allow-Origin': '*',
43
+ 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE'
44
+ };
40
45
 
41
- if(item.priority != max)
42
- return false;
46
+ let body = [];
47
+ let file = false;
43
48
 
44
- delete item.priority;
49
+ let max = -Infinity;
45
50
 
46
- if(typeof item == "object") {
51
+ responses.filter(item => item != null).forEach(item => {
47
52
 
48
- if(item.file != null) {
49
-
50
- if(item.file)
51
- file = true;
53
+ item.priority = item.priority != null ? item.priority : 0;
54
+
55
+ if(item.priority > max)
56
+ max = item.priority;
57
+ });
58
+
59
+ responses.filter(
60
+ item => {
61
+
62
+ if(item == null)
63
+ return
52
64
 
53
- delete item.file;
65
+ if(item.priority != max)
66
+ return false;
67
+
68
+ delete item.priority;
69
+
70
+ if(typeof item == "object") {
71
+
72
+ if(item.file != null) {
73
+
74
+ if(item.file)
75
+ file = true;
76
+
77
+ delete item.file;
78
+ }
54
79
  }
80
+
81
+ return serverUtils.isHTTPJSON(item);
55
82
  }
56
-
57
- return serverUtils.isHTTPJSON(item);
58
- }
59
- ).filter(
60
- item => item.request == null
61
- ).forEach(item => {
83
+ ).filter(
84
+ item => item.request == null
85
+ ).forEach(item => {
62
86
 
63
- if(item.response != null) {
87
+ if(item.response != null) {
64
88
 
65
- if(item.response.status != null) {
89
+ if(item.response.status != null) {
66
90
 
67
- if(item.response.status > status)
68
- status = item.response.status;
91
+ if(item.response.status > status)
92
+ status = item.response.status;
93
+ }
69
94
  }
70
- }
71
95
 
72
- if(item.headers != null)
73
- Object.assign(headers, item.headers);
96
+ if(item.headers != null)
97
+ Object.assign(headers, item.headers);
74
98
 
75
- if(item.body != null)
76
- body.push("" + item.body);
77
- });
99
+ if(item.body != null)
100
+ body.push("" + item.body);
101
+ });
78
102
 
79
- response.writeHead(status, headers);
103
+ response.writeHead(status, headers);
80
104
 
81
- if(file) {
105
+ if(file) {
82
106
 
83
- if(body.length > 0) {
107
+ if(body.length > 0) {
84
108
 
85
- fs.readFile(body[0], function(error, data) {
109
+ fs.readFile(body[0], function(error, data) {
86
110
 
87
- if(error) {
88
- response.statusCode = 500;
89
- response.end(`ERROR: ${error}.`);
90
- }
91
-
92
- else
93
- response.end(data);
94
- });
111
+ if(error) {
112
+ response.statusCode = 500;
113
+ response.end(`ERROR: ${error}.`);
114
+ }
115
+
116
+ else
117
+ response.end(data);
118
+ });
119
+ }
95
120
  }
96
- }
97
121
 
98
- else {
122
+ else {
99
123
 
100
- if(body.length == 1)
101
- response.write(body[0]);
102
-
103
- else if(body.length > 1)
104
- response.write(JSON.stringify(body));
105
-
106
- response.end();
107
- }
124
+ if(body.length == 1)
125
+ response.write(body[0]);
126
+
127
+ else if(body.length > 1)
128
+ response.write(JSON.stringify(body));
129
+
130
+ response.end();
131
+ }
132
+ });
108
133
  });
109
134
  }),
110
135
  query: (packet) => {