orator 4.0.0 → 4.0.2
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orator",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Unopinionated API behavior container - REST or IPC",
|
|
5
5
|
"main": "source/Orator.js",
|
|
6
6
|
"scripts": {
|
|
@@ -51,11 +51,12 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/stevenvelozo/orator",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"fable": "^3.0.
|
|
55
|
-
"quackage": "^1.0.
|
|
54
|
+
"fable": "^3.0.96",
|
|
55
|
+
"quackage": "^1.0.24"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"fable-serviceproviderbase": "^3.0.
|
|
59
|
-
"find-my-way": "^7.
|
|
58
|
+
"fable-serviceproviderbase": "^3.0.12",
|
|
59
|
+
"find-my-way": "^7.7.0",
|
|
60
|
+
"orator-serviceserver-base": "^1.0.0"
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
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');
|
|
@@ -15,7 +13,6 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
|
|
|
15
13
|
super(pFable, pOptions, pServiceHash);
|
|
16
14
|
|
|
17
15
|
this.router = libFindMyWay(this.options);
|
|
18
|
-
//this.router.addConstraintStrategy(libOratorServiceServerIPCCustomConstrainer);
|
|
19
16
|
|
|
20
17
|
this.ServiceServerType = 'IPC';
|
|
21
18
|
|
package/source/Orator.js
CHANGED
|
@@ -118,7 +118,7 @@ class Orator extends libFableServiceProviderBase
|
|
|
118
118
|
|
|
119
119
|
initialize(fCallback)
|
|
120
120
|
{
|
|
121
|
-
// I hate this --
|
|
121
|
+
// I hate this -- as long as we want to be "mostly" backwards compatible it needs to do it though
|
|
122
122
|
let tmpCallback = (typeof(fCallback) === 'function') ? fCallback : () => {};
|
|
123
123
|
|
|
124
124
|
if (!this.initializeTimestamp)
|
|
@@ -165,7 +165,7 @@ class Orator extends libFableServiceProviderBase
|
|
|
165
165
|
this.options.ServicePort,
|
|
166
166
|
(pError) =>
|
|
167
167
|
{
|
|
168
|
-
this.log.info(`${this.serviceServer.Name} listening
|
|
168
|
+
this.log.info(`${this.serviceServer.Name} listening on port ${this.options.ServicePort}`);
|
|
169
169
|
return fNext(pError);
|
|
170
170
|
}
|
|
171
171
|
);
|
|
@@ -257,7 +257,7 @@ class Orator extends libFableServiceProviderBase
|
|
|
257
257
|
// this accessor function is called.
|
|
258
258
|
if (!this.serviceServer)
|
|
259
259
|
{
|
|
260
|
-
this.
|
|
260
|
+
this.initialize();
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
return this.serviceServer;
|
|
@@ -268,5 +268,5 @@ class Orator extends libFableServiceProviderBase
|
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
module.exports = Orator;
|
|
271
|
-
module.exports.ServiceServerBase = require('
|
|
271
|
+
module.exports.ServiceServerBase = require('orator-serviceserver-base');
|
|
272
272
|
module.exports.ServiceServerIPC = require('./Orator-ServiceServer-IPC.js');
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
const libFableServiceProviderBase = require('fable-serviceproviderbase');
|
|
2
|
-
|
|
3
|
-
class OratorServiceServerBase extends libFableServiceProviderBase
|
|
4
|
-
{
|
|
5
|
-
constructor(pFable, pOptions, pServiceHash)
|
|
6
|
-
{
|
|
7
|
-
super(pFable, pOptions, pServiceHash);
|
|
8
|
-
|
|
9
|
-
this.serviceType = 'OratorServiceServer';
|
|
10
|
-
|
|
11
|
-
this.ServiceServerType = 'Base';
|
|
12
|
-
|
|
13
|
-
this.Name = this.fable.settings.Product;
|
|
14
|
-
this.URL = 'BASE_SERVICE_SERVER';
|
|
15
|
-
this.Port = this.options.ServicePort;
|
|
16
|
-
|
|
17
|
-
this.Active = false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
* Service Lifecycle Functions
|
|
22
|
-
*************************************************************************/
|
|
23
|
-
listen(pPort, fCallback)
|
|
24
|
-
{
|
|
25
|
-
// Sometimes, listen does not listen on network calls.
|
|
26
|
-
this.Active = true;
|
|
27
|
-
|
|
28
|
-
return fCallback();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
close(fCallback)
|
|
32
|
-
{
|
|
33
|
-
this.Active = false;
|
|
34
|
-
|
|
35
|
-
return fCallback();
|
|
36
|
-
}
|
|
37
|
-
/*************************************************************************
|
|
38
|
-
* End of Service Lifecycle Functions
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
* Content parsing functions
|
|
43
|
-
*************************************************************************/
|
|
44
|
-
bodyParser(pOptions)
|
|
45
|
-
{
|
|
46
|
-
return (pRequest, pResponse, fNext) =>
|
|
47
|
-
{
|
|
48
|
-
fNext();
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/*************************************************************************
|
|
52
|
-
* End of Service Lifecycle Functions
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
|
-
/*
|
|
56
|
-
* Service Route Creation Functions
|
|
57
|
-
*
|
|
58
|
-
* These base functions provide basic validation for the routes, but don't actually
|
|
59
|
-
* do anything with them. The design intent here is to allow derived classes to call
|
|
60
|
-
* these functions to validate that they conform to expected standards.
|
|
61
|
-
*
|
|
62
|
-
* Something like:
|
|
63
|
-
|
|
64
|
-
get (pRoute, ...fRouteProcessingFunctions)
|
|
65
|
-
{
|
|
66
|
-
if (!super.get(pRoute, ...fRouteProcessingFunctions))
|
|
67
|
-
{
|
|
68
|
-
this.log.error(`Restify provider failed to map route [${pRoute}]!`);
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//...now we can do our actual get mapping function!....
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
* This pattern and calling super is totally optional, obviously.
|
|
76
|
-
*************************************************************************/
|
|
77
|
-
use(fHandlerFunction)
|
|
78
|
-
{
|
|
79
|
-
if (typeof(fHandlerFunction) != 'function')
|
|
80
|
-
{
|
|
81
|
-
this.log.error(`Orator USE global handler mapping failed -- parameter was expected to be a function with prototype function(Request, Response, Next) but type was ${typeof(fHandlerFunction)} instead of a string.`)
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
doGet(pRoute, ...fRouteProcessingFunctions)
|
|
89
|
-
{
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
get(pRoute, ...fRouteProcessingFunctions)
|
|
93
|
-
{
|
|
94
|
-
if (typeof(pRoute) != 'string')
|
|
95
|
-
{
|
|
96
|
-
this.log.error(`Orator GET Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
return this.doGet(pRoute, ...fRouteProcessingFunctions);
|
|
100
|
-
}
|
|
101
|
-
getWithBodyParser(pRoute, ...fRouteProcessingFunctions)
|
|
102
|
-
{
|
|
103
|
-
return this.get(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
doPut(pRoute, ...fRouteProcessingFunctions)
|
|
107
|
-
{
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
put(pRoute, ...fRouteProcessingFunctions)
|
|
111
|
-
{
|
|
112
|
-
if (typeof(pRoute) != 'string')
|
|
113
|
-
{
|
|
114
|
-
this.log.error(`Orator PUT Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return this.doPut(pRoute, ...fRouteProcessingFunctions);
|
|
118
|
-
}
|
|
119
|
-
putWithBodyParser(pRoute, ...fRouteProcessingFunctions)
|
|
120
|
-
{
|
|
121
|
-
return this.put(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
doPost(pRoute, ...fRouteProcessingFunctions)
|
|
125
|
-
{
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
post(pRoute, ...fRouteProcessingFunctions)
|
|
129
|
-
{
|
|
130
|
-
if (typeof(pRoute) != 'string')
|
|
131
|
-
{
|
|
132
|
-
this.log.error(`Orator POST Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
return this.doPost(pRoute, ...fRouteProcessingFunctions);
|
|
136
|
-
}
|
|
137
|
-
postWithBodyParser(pRoute, ...fRouteProcessingFunctions)
|
|
138
|
-
{
|
|
139
|
-
return this.post(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
doDel(pRoute, ...fRouteProcessingFunctions)
|
|
143
|
-
{
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
del(pRoute, ...fRouteProcessingFunctions)
|
|
147
|
-
{
|
|
148
|
-
if (typeof(pRoute) != 'string')
|
|
149
|
-
{
|
|
150
|
-
this.log.error(`Orator DEL Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
return this.doDel(pRoute, ...fRouteProcessingFunctions);
|
|
154
|
-
}
|
|
155
|
-
delWithBodyParser(pRoute, ...fRouteProcessingFunctions)
|
|
156
|
-
{
|
|
157
|
-
return this.del(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
doPatch(pRoute, ...fRouteProcessingFunctions)
|
|
161
|
-
{
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
patch(pRoute, ...fRouteProcessingFunctions)
|
|
165
|
-
{
|
|
166
|
-
if (typeof(pRoute) != 'string')
|
|
167
|
-
{
|
|
168
|
-
this.log.error(`Orator PATCH Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
return this.doPatch(pRoute, ...fRouteProcessingFunctions);
|
|
172
|
-
}
|
|
173
|
-
patchWithBodyParser(pRoute, ...fRouteProcessingFunctions)
|
|
174
|
-
{
|
|
175
|
-
return this.patch(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
doOpts(pRoute, ...fRouteProcessingFunctions)
|
|
179
|
-
{
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
opts(pRoute, ...fRouteProcessingFunctions)
|
|
183
|
-
{
|
|
184
|
-
if (typeof(pRoute) != 'string')
|
|
185
|
-
{
|
|
186
|
-
this.log.error(`Orator OPTS Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
return this.doOpts(pRoute, ...fRouteProcessingFunctions);
|
|
190
|
-
}
|
|
191
|
-
optsWithBodyParser(pRoute, ...fRouteProcessingFunctions)
|
|
192
|
-
{
|
|
193
|
-
return this.opts(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
doHead(pRoute, ...fRouteProcessingFunctions)
|
|
197
|
-
{
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
head(pRoute, ...fRouteProcessingFunctions)
|
|
201
|
-
{
|
|
202
|
-
if (typeof(pRoute) != 'string')
|
|
203
|
-
{
|
|
204
|
-
this.log.error(`Orator HEAD Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
headWithBodyParser(pRoute, ...fRouteProcessingFunctions)
|
|
211
|
-
{
|
|
212
|
-
return this.head(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
|
|
213
|
-
}
|
|
214
|
-
/*************************************************************************
|
|
215
|
-
* End of Service Route Creation Functions
|
|
216
|
-
*/
|
|
217
|
-
|
|
218
|
-
// Programmatically invoke a route
|
|
219
|
-
invoke(pMethod, pRoute, pData, fCallback)
|
|
220
|
-
{
|
|
221
|
-
// The base class version of this does nothing
|
|
222
|
-
this.log.debug(`Orator invoke called for route [${pRoute}] and landed on the base class; the service provider likely does not implement programmatic invoke capabilities.`, pData);
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
module.exports = OratorServiceServerBase;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
// This is taken directly from the find-my-way documentation for custom constraints and only mildly edited
|
|
4
|
-
const ipcResponseTypeStrategy = (
|
|
5
|
-
{
|
|
6
|
-
// strategy name for referencing in the route handler `constraints` options
|
|
7
|
-
name: 'ipc',
|
|
8
|
-
isAsync: true,
|
|
9
|
-
|
|
10
|
-
// storage factory for storing routes in the find-my-way route tree
|
|
11
|
-
storage:
|
|
12
|
-
()=>
|
|
13
|
-
{
|
|
14
|
-
let handlers = {};
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
{
|
|
18
|
-
get: (type) => { return handlers[type] || null },
|
|
19
|
-
set: (type, store) => { handlers[type] = store }
|
|
20
|
-
});
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
// function to get the value of the constraint from each incoming request
|
|
24
|
-
deriveConstraint: (pRequest, pContext, fDone) =>
|
|
25
|
-
{
|
|
26
|
-
// If we wanted to deny the IPC request based on a constraint, we would do:
|
|
27
|
-
// fDone(new Error(`The request was denied because ____ in the Request object wasn't right...`));
|
|
28
|
-
return fDone(null, 'IPC');
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
// optional flag marking if handlers without constraints can match requests that have a value for this constraint
|
|
32
|
-
mustMatchWhenDerived: true
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
module.exports = ipcResponseTypeStrategy;
|