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/debug/Harness.js +4 -8
- package/dist/orator.compatible.js +4889 -0
- package/dist/orator.compatible.min.js +17 -0
- package/dist/orator.compatible.min.js.map +1 -0
- package/dist/orator.js +977 -1725
- package/dist/orator.min.js +3 -24
- package/dist/orator.min.js.map +1 -1
- package/package.json +59 -66
- package/source/Orator-Default-ServiceServer-Web.js +4 -0
- package/source/Orator-Default-ServiceServer.js +4 -0
- package/source/Orator-ServiceServer-IPC-SynthesizedResponse.js +18 -1
- package/source/Orator-ServiceServer-IPC.js +108 -83
- package/source/Orator.js +141 -34
- package/test/Orator_basic_tests.js +43 -18
- package/test_legacy/Orator_basic_tests.js +1 -1
- package/test_legacy/Orator_cluster_test.js.deferred +1 -1
- package/test_legacy/Orator_logging_tests.js +1 -1
- package/source/Orator-Default-ServiceServers-Node.js +0 -21
- package/source/Orator-Default-ServiceServers-Web.js +0 -21
- package/source/Orator-ServiceServer-Base.js +0 -225
- package/source/Orator-ServiceServer-IPC-RouterConstrainer.js +0 -35
- /package/{test → debug/site}/Test.css +0 -0
- /package/{test → debug/site}/Test.html +0 -0
package/package.json
CHANGED
|
@@ -1,69 +1,62 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
}
|
|
@@ -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('
|
|
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(
|
|
11
|
+
constructor(pFable, pOptions, pServiceHash)
|
|
17
12
|
{
|
|
18
|
-
|
|
13
|
+
super(pFable, pOptions, pServiceHash);
|
|
19
14
|
|
|
20
|
-
this.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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.
|
|
77
|
+
this.postBehaviorFunctions.push(fHandlerFunction);
|
|
78
|
+
return true;
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
executePostBehaviorFunctions(pRequest, pResponse, fNext)
|
|
84
82
|
{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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,
|
|
121
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
});
|
|
270
|
+
return tmpCallback(pError, tmpSynthesizedResponseData.responseData, tmpSynthesizedResponseData);
|
|
271
|
+
}
|
|
272
|
+
);
|
|
248
273
|
}
|
|
249
274
|
}
|
|
250
275
|
|