orator 3.0.11 → 4.0.1

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/package.json CHANGED
@@ -1,69 +1,62 @@
1
1
  {
2
- "name": "orator",
3
- "version": "3.0.11",
4
- "description": "Unopinionated restful web API server container",
5
- "main": "source/Orator.js",
6
- "scripts": {
7
- "start": "node source/Orator.js",
8
- "coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
9
- "test": "./node_modules/mocha/bin/_mocha --exit -u tdd -R spec",
10
- "build": "./node_modules/.bin/gulp build",
11
- "docker-dev-build-image": "docker build ./ -f Dockerfile_LUXURYCode -t retold/orator:local",
12
- "docker-dev-run": "docker run -it -d --name retold-orator-dev -p 40000:8080 -p 48086:8086 -p 48088:8088 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/orator\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" retold/orator:local"
13
- },
14
- "browser": {
15
- "./source/Orator-Default-ServiceServers-Node.js": "./source/Orator-Default-ServiceServers-Web.js"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "https://github.com/stevenvelozo/orator.git"
20
- },
21
- "keywords": [
22
- "rest",
23
- "api",
24
- "logging"
25
- ],
26
- "author": "Steven Velozo <steven@velozo.com> (http://velozo.com/)",
27
- "license": "MIT",
28
- "bugs": {
29
- "url": "https://github.com/stevenvelozo/orator/issues"
30
- },
31
- "mocha": {
32
- "diff": true,
33
- "extension": [
34
- "js"
2
+ "name": "orator",
3
+ "version": "4.0.1",
4
+ "description": "Unopinionated API behavior container - REST or IPC",
5
+ "main": "source/Orator.js",
6
+ "scripts": {
7
+ "start": "node source/Orator.js",
8
+ "coverage": "npx nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
9
+ "test": "npx mocha -u tdd -R spec",
10
+ "build": "npx quack build",
11
+ "docker-dev-build-image": "docker build ./ -f Dockerfile_LUXURYCode -t retold/orator:local",
12
+ "docker-dev-run": "docker run -it -d --name orator-dev -p 15277:8080 -p 34566:8086 -v \"$PWD/.config:/home/coder/.config\" -v \"$PWD:/home/coder/orator\" -u \"$(id -u):$(id -g)\" -e \"DOCKER_USER=$USER\" orator-image:local",
13
+ "tests": "npx mocha -u tdd --exit -R spec --grep",
14
+ "docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t orator-image:local",
15
+ "docker-dev-shell": "docker exec -it orator-dev /bin/bash"
16
+ },
17
+ "browser": {
18
+ "./source/Orator-Default-ServiceServer.js": "./source/Orator-Default-ServiceServer-Web.js"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/stevenvelozo/orator.git"
23
+ },
24
+ "keywords": [
25
+ "rest",
26
+ "api",
27
+ "logging"
35
28
  ],
36
- "package": "./package.json",
37
- "reporter": "spec",
38
- "slow": "75",
39
- "timeout": "5000",
40
- "ui": "tdd",
41
- "watch-files": [
42
- "source/**/*.js",
43
- "test/**/*.js"
44
- ],
45
- "watch-ignore": [
46
- "lib/vendor"
47
- ]
48
- },
49
- "homepage": "https://github.com/stevenvelozo/orator",
50
- "devDependencies": {
51
- "browserify": "^17.0.0",
52
- "chai": "4.3.7",
53
- "fable": "^3.0.11",
54
- "gulp": "^4.0.2",
55
- "gulp-babel": "^8.0.0",
56
- "gulp-sourcemaps": "^3.0.0",
57
- "gulp-terser": "^2.1.0",
58
- "gulp-util": "^3.0.8",
59
- "mocha": "10.2.0",
60
- "nyc": "^15.1.0",
61
- "vinyl-buffer": "^1.0.1",
62
- "vinyl-source-stream": "^2.0.0",
63
- "orator-serviceserver-restify": "^1.0.1"
64
- },
65
- "dependencies": {
66
- "async": "^3.2.4",
67
- "find-my-way": "^7.5.0"
68
- }
29
+ "author": "Steven Velozo <steven@velozo.com> (http://velozo.com/)",
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://github.com/stevenvelozo/orator/issues"
33
+ },
34
+ "mocha": {
35
+ "diff": true,
36
+ "extension": [
37
+ "js"
38
+ ],
39
+ "package": "./package.json",
40
+ "reporter": "spec",
41
+ "slow": "75",
42
+ "timeout": "5000",
43
+ "ui": "tdd",
44
+ "watch-files": [
45
+ "source/**/*.js",
46
+ "test/**/*.js"
47
+ ],
48
+ "watch-ignore": [
49
+ "lib/vendor"
50
+ ]
51
+ },
52
+ "homepage": "https://github.com/stevenvelozo/orator",
53
+ "devDependencies": {
54
+ "fable": "^3.0.73",
55
+ "quackage": "^1.0.17"
56
+ },
57
+ "dependencies": {
58
+ "fable-serviceproviderbase": "^3.0.10",
59
+ "find-my-way": "^7.5.0",
60
+ "orator-serviceserver-base": "^1.0.0"
61
+ }
69
62
  }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Default Service Server
3
+ */
4
+ module.exports = require('./Orator-ServiceServer-IPC.js')
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Default Service Server
3
+ */
4
+ module.exports = require('./Orator-ServiceServer-IPC.js')
@@ -1,9 +1,26 @@
1
1
  class OratorServiceServerIPCSynthesizedResponse
2
2
  {
3
- constructor(pLog, pRequestGUID)
3
+ constructor(pHandler, pLog, pRequestGUID)
4
4
  {
5
5
  this.log = pLog;
6
6
 
7
+ if (pHandler.hasOwnProperty('params'))
8
+ {
9
+ this.params = pHandler.params;
10
+ }
11
+ else
12
+ {
13
+ this.params = {};
14
+ }
15
+ if (pHandler.hasOwnProperty('searchParams'))
16
+ {
17
+ this.searchParams = pHandler.searchParams;
18
+ }
19
+ else
20
+ {
21
+ this.searchParams = {};
22
+ }
23
+
7
24
  this.requestGUID = pRequestGUID;
8
25
 
9
26
  this.responseData = null;
@@ -1,29 +1,23 @@
1
- const libOratorServiceServerBase = require('./Orator-ServiceServer-Base.js');
1
+ const libOratorServiceServerBase = require('orator-serviceserver-base');
2
2
 
3
3
  // A synthesized response object, for simple IPC.
4
4
  const libOratorServiceServerIPCSynthesizedResponse = require('./Orator-ServiceServer-IPC-SynthesizedResponse.js');
5
- // A simple constrainer for the find-my-way router since we aren't using any kind of headers to pass version or host
6
- const libOratorServiceServerIPCCustomConstrainer = require('./Orator-ServiceServer-IPC-RouterConstrainer.js');
7
5
 
8
6
  // This library is the default router for our services
9
7
  const libFindMyWay = require('find-my-way');
10
- //const libAsync = require('async');
11
- const libAsyncWaterfall = require("async/waterfall");
12
- const libAsyncEachOfSeries = require('async/eachOfSeries')
13
8
 
14
9
  class OratorServiceServerIPC extends libOratorServiceServerBase
15
10
  {
16
- constructor(pOrator)
11
+ constructor(pFable, pOptions, pServiceHash)
17
12
  {
18
- super(pOrator);
13
+ super(pFable, pOptions, pServiceHash);
19
14
 
20
- this.routerOptions = (this.orator.settings.hasOwnProperty('router_options') && (typeof(this.orator.settings.router_options) == 'object')) ? this.orator.settings.router_options : {};
21
- this.router = libFindMyWay(this.routerOptions);
22
- this.router.addConstraintStrategy(libOratorServiceServerIPCCustomConstrainer);
15
+ this.router = libFindMyWay(this.options);
23
16
 
24
17
  this.ServiceServerType = 'IPC';
25
18
 
26
19
  this.URL = 'IPC';
20
+ this.Port = 0;
27
21
 
28
22
  this.preBehaviorFunctions = [];
29
23
  this.behaviorMap = {};
@@ -32,16 +26,10 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
32
26
 
33
27
  use(fHandlerFunction)
34
28
  {
35
- if (!super.use(fHandlerFunction))
36
- {
37
- this.log.error(`IPC provider failed to map USE handler function!`);
38
- return false;
39
- }
40
-
41
- this.preBehaviorFunctions.push(fHandlerFunction);
29
+ return this.addPreBehaviorFunction(fHandlerFunction);
42
30
  }
43
31
 
44
- addPostBehaviorFunction(fHandlerFunction)
32
+ addPreBehaviorFunction(fHandlerFunction)
45
33
  {
46
34
  if (!super.use(fHandlerFunction))
47
35
  {
@@ -50,15 +38,24 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
50
38
  }
51
39
 
52
40
  this.preBehaviorFunctions.push(fHandlerFunction);
41
+ return true;
53
42
  }
54
43
 
55
44
  executePreBehaviorFunctions(pRequest, pResponse, fNext)
56
45
  {
57
- libAsyncEachOfSeries(this.preBehaviorFunctions,
58
- (fBehaviorFunction, pFunctionIndex, fCallback) =>
59
- {
60
- return fBehaviorFunction(pRequest, pResponse, fCallback);
61
- },
46
+ let tmpAnticipate = this.fable.serviceManager.instantiateServiceProviderWithoutRegistration('Anticipate');
47
+
48
+ for (let i = 0; i < this.preBehaviorFunctions.length; i++)
49
+ {
50
+ let tmpPreBehaviorFunction = this.preBehaviorFunctions[i];
51
+ tmpAnticipate.anticipate(
52
+ (fStageComplete) =>
53
+ {
54
+ return tmpPreBehaviorFunction(pRequest, pResponse, fStageComplete);
55
+ });
56
+ }
57
+
58
+ tmpAnticipate.wait(
62
59
  (pError) =>
63
60
  {
64
61
  if (pError)
@@ -77,16 +74,25 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
77
74
  return false;
78
75
  }
79
76
 
80
- this.preBehaviorFunctions.push(fHandlerFunction);
77
+ this.postBehaviorFunctions.push(fHandlerFunction);
78
+ return true;
81
79
  }
82
80
 
83
81
  executePostBehaviorFunctions(pRequest, pResponse, fNext)
84
82
  {
85
- libAsyncEachOfSeries(this.postBehaviorFunctions,
86
- (fBehaviorFunction, pFunctionIndex, fCallback) =>
87
- {
88
- return fBehaviorFunction(pRequest, pResponse, fCallback);
89
- },
83
+ let tmpAnticipate = this.fable.serviceManager.instantiateServiceProviderWithoutRegistration('Anticipate');
84
+
85
+ for (let i = 0; i < this.postBehaviorFunctions.length; i++)
86
+ {
87
+ let tmpPostBehaviorFunction = this.postBehaviorFunctions[i];
88
+ tmpAnticipate.anticipate(
89
+ (fStageComplete) =>
90
+ {
91
+ return tmpPostBehaviorFunction(pRequest, pResponse, fStageComplete);
92
+ });
93
+ }
94
+
95
+ tmpAnticipate.wait(
90
96
  (pError) =>
91
97
  {
92
98
  if (pError)
@@ -117,52 +123,55 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
117
123
  {
118
124
  // We have a constrainer on IPC so we can control channels eventually, if we like.
119
125
  // For now it just makes sure it was added with an IPC service server.
120
- this.router.on(pMethod, pRoute, { constraints: { "ipc": "IPC" } },
121
- (pRequest, pResponse, pParameters) =>
126
+ this.router.on(pMethod, pRoute, this.buildFindMyWayHandler(pRouteFunctionArray));
127
+ return true;
128
+ }
129
+
130
+ buildFindMyWayHandler(pRouteFunctionArray)
131
+ {
132
+ let tmpRouteFunctionArray = pRouteFunctionArray;
133
+ return (
134
+ (pRequest, pResponse, pData) =>
122
135
  {
123
- libAsyncWaterfall(
124
- [
125
- (fStageComplete)=>
126
- {
127
- // Added to make this mimic what we saw with route parsing in the old restify
128
- pRequest.params = pParameters;
129
- return fStageComplete();
130
- },
131
- (fStageComplete)=>
132
- {
133
- return this.executePreBehaviorFunctions(pRequest, pResponse, fStageComplete);
134
- },
135
- (fStageComplete)=>
136
- {
137
- libAsyncEachOfSeries(pRouteFunctionArray,
138
- (fBehaviorFunction, pFunctionIndex, fCallback) =>
139
- {
140
- return fBehaviorFunction(pRequest, pResponse, fCallback);
141
- },
142
- (pBehaviorFunctionError) =>
143
- {
144
- if (pBehaviorFunctionError)
145
- {
146
- this.log.error(`IPC Provider behavior function ${pFunctionIndex} failed with error: ${pBehaviorFunctionError}`, pBehaviorFunctionError);
147
- return fNext(pError);
148
- }
149
- });
150
- },
151
- (fStageComplete)=>
152
- {
153
- return this.executePostBehaviorFunctions(pRequest, pResponse, fStageComplete);
154
- }
155
- ],
156
- (pRequestError)=>
136
+ let tmpAnticipate = this.fable.serviceManager.instantiateServiceProviderWithoutRegistration('Anticipate');
137
+
138
+ tmpAnticipate.anticipate(
139
+ (fNext)=>
157
140
  {
158
- if (pRequestError)
141
+ return this.executePreBehaviorFunctions(pRequest, pResponse, fNext);
142
+ });
143
+
144
+ for (let i = 0; i < tmpRouteFunctionArray.length; i++)
145
+ {
146
+ let tmpRouteFunction = tmpRouteFunctionArray[i];
147
+ tmpAnticipate.anticipate(
148
+ (fNext) =>
159
149
  {
160
- this.log.error(`IPC Provider behavior function ${pFunctionIndex} failed with error: ${pBehaviorFunctionError}`, pBehaviorFunctionError);
161
- }
150
+ return tmpRouteFunction(pRequest, pResponse, fNext);
151
+ });
152
+ }
153
+
154
+ tmpAnticipate.anticipate(
155
+ (fStageComplete)=>
156
+ {
157
+ return this.executePostBehaviorFunctions(pRequest, pResponse, fStageComplete);
162
158
  });
163
- });
164
159
 
165
- return true;
160
+ return new Promise(
161
+ (fResolve, fReject) =>
162
+ {
163
+ tmpAnticipate.wait(
164
+ (pBehaviorFunctionError) =>
165
+ {
166
+ if (pBehaviorFunctionError)
167
+ {
168
+ this.log.error(`IPC Provider behavior function ${pFunctionIndex} failed with error: ${pBehaviorFunctionError}`, pBehaviorFunctionError);
169
+ return fReject(pBehaviorFunctionError);
170
+ }
171
+ return fResolve();
172
+ });
173
+ });
174
+ });
166
175
  }
167
176
 
168
177
  // This is the virtualized "body parser"
@@ -218,33 +227,49 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
218
227
  // If the data is skipped and a callback is parameter 3, do the right thing
219
228
  let tmpCallback = (typeof(fCallback) == 'function') ? fCallback :
220
229
  (typeof(pData) == 'function') ? pData :
221
- // This is here in case the developer passed no callback and just wants to fire and forget the IPC call which might not be async safe
222
- ()=>{};
230
+ false;
231
+
232
+ if (!tmpCallback)
233
+ {
234
+ throw new Error(`IPC Provider invoke() called without a callback function.`);
235
+ }
223
236
 
224
237
  // Create a bare minimum request object for IPC to pass to our router
225
238
  let tmpRequest = (
226
239
  {
227
240
  method: pMethod,
228
241
  url: pRoute,
229
- guid: this.orator.fable.getUUID()
242
+ guid: this.fable.getUUID()
230
243
  });
231
244
 
245
+ // For now, dealing with no handler constraints.
246
+ let tmpHandler = this.router.find( tmpRequest.method, tmpRequest.url);
247
+
232
248
  // Create a container for the IPC response data to be aggregated to from send() methodds
233
- let tmpSynthesizedResponseData = new libOratorServiceServerIPCSynthesizedResponse(this.log, tmpRequest.guid);
249
+ let tmpSynthesizedResponseData = new libOratorServiceServerIPCSynthesizedResponse(tmpHandler, this.log, tmpRequest.guid);
250
+
251
+ // Map parsed params back to the request object
252
+ tmpRequest.params = tmpSynthesizedResponseData.params;
253
+ tmpRequest.searchParams = tmpSynthesizedResponseData.searchParams;
234
254
 
235
- return this.router.lookup(
236
- tmpRequest,
237
- tmpSynthesizedResponseData,
238
- (pError, pResults)=>
255
+ //params: handle._createParamsObject(params)//,
256
+ //searchParams: this.querystringParser(querystring)
257
+
258
+ tmpHandler.handler(tmpRequest, tmpSynthesizedResponseData, pData).then(
259
+ (pResults)=>
239
260
  {
261
+ return tmpCallback(null, tmpSynthesizedResponseData.responseData, tmpSynthesizedResponseData, pResults);
262
+ },
263
+ (pError)=>
264
+ {
265
+ this.log.trace('IPC Response Received', {Error: pError});
240
266
  if (pError)
241
267
  {
242
268
  this.log.error(`IPC Request Error Request GUID [${tmpRequest.guid}] handling route [${pRoute}]: ${pError}`, {Error: pError, Route: pRoute, Data: pData});
243
269
  }
244
-
245
- // by default, send data back through
246
- return tmpCallback(pError, tmpSynthesizedResponseData.responseData, tmpSynthesizedResponseData, pResults);
247
- });
270
+ return tmpCallback(pError, tmpSynthesizedResponseData.responseData, tmpSynthesizedResponseData);
271
+ }
272
+ );
248
273
  }
249
274
  }
250
275