orator 3.0.8 → 3.0.10

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": "3.0.8",
3
+ "version": "3.0.10",
4
4
  "description": "Unopinionated restful web API server container",
5
5
  "main": "source/Orator.js",
6
6
  "scripts": {
@@ -6,6 +6,8 @@ class OratorServiceServerBase
6
6
 
7
7
  this.log = pOrator.log;
8
8
 
9
+ this.ServiceServerType = 'Base';
10
+
9
11
  this.Name = this.orator.settings.Product;
10
12
  this.URL = 'BASE_SERVICE_SERVER';
11
13
  this.Port = this.orator.settings.ServicePort;
@@ -34,17 +36,19 @@ class OratorServiceServerBase
34
36
  * End of Service Lifecycle Functions
35
37
  */
36
38
 
37
- use(fHandlerFunction)
39
+ /*
40
+ * Content parsing functions
41
+ *************************************************************************/
42
+ bodyParser(pOptions)
38
43
  {
39
- if (typeof(fHandlerFunction) != 'function')
40
- {
41
- 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.`)
42
- return false;
43
- }
44
-
45
- return true;
44
+ return (pRequest, pResponse, fNext) =>
45
+ {
46
+ fNext();
47
+ };
46
48
  }
47
-
49
+ /*************************************************************************
50
+ * End of Service Lifecycle Functions
51
+ */
48
52
 
49
53
  /*
50
54
  * Service Route Creation Functions
@@ -68,6 +72,21 @@ class OratorServiceServerBase
68
72
 
69
73
  * This pattern and calling super is totally optional, obviously.
70
74
  *************************************************************************/
75
+ use(fHandlerFunction)
76
+ {
77
+ if (typeof(fHandlerFunction) != 'function')
78
+ {
79
+ 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.`)
80
+ return false;
81
+ }
82
+
83
+ return true;
84
+ }
85
+
86
+ doGet(pRoute, ...fRouteProcessingFunctions)
87
+ {
88
+ return true;
89
+ }
71
90
  get(pRoute, ...fRouteProcessingFunctions)
72
91
  {
73
92
  if (typeof(pRoute) != 'string')
@@ -75,10 +94,17 @@ class OratorServiceServerBase
75
94
  this.log.error(`Orator GET Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
76
95
  return false;
77
96
  }
97
+ return this.doGet(pRoute, ...fRouteProcessingFunctions);
98
+ }
99
+ getWithBodyParser(pRoute, ...fRouteProcessingFunctions)
100
+ {
101
+ return this.get(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
102
+ }
78
103
 
104
+ doPut(pRoute, ...fRouteProcessingFunctions)
105
+ {
79
106
  return true;
80
107
  }
81
-
82
108
  put(pRoute, ...fRouteProcessingFunctions)
83
109
  {
84
110
  if (typeof(pRoute) != 'string')
@@ -86,10 +112,17 @@ class OratorServiceServerBase
86
112
  this.log.error(`Orator PUT Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
87
113
  return false;
88
114
  }
115
+ return this.doPut(pRoute, ...fRouteProcessingFunctions);
116
+ }
117
+ putWithBodyParser(pRoute, ...fRouteProcessingFunctions)
118
+ {
119
+ return this.put(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
120
+ }
89
121
 
122
+ doPost(pRoute, ...fRouteProcessingFunctions)
123
+ {
90
124
  return true;
91
125
  }
92
-
93
126
  post(pRoute, ...fRouteProcessingFunctions)
94
127
  {
95
128
  if (typeof(pRoute) != 'string')
@@ -97,10 +130,17 @@ class OratorServiceServerBase
97
130
  this.log.error(`Orator POST Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
98
131
  return false;
99
132
  }
133
+ return this.doPost(pRoute, ...fRouteProcessingFunctions);
134
+ }
135
+ postWithBodyParser(pRoute, ...fRouteProcessingFunctions)
136
+ {
137
+ return this.post(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
138
+ }
100
139
 
140
+ doDel(pRoute, ...fRouteProcessingFunctions)
141
+ {
101
142
  return true;
102
143
  }
103
-
104
144
  del(pRoute, ...fRouteProcessingFunctions)
105
145
  {
106
146
  if (typeof(pRoute) != 'string')
@@ -108,10 +148,17 @@ class OratorServiceServerBase
108
148
  this.log.error(`Orator DEL Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
109
149
  return false;
110
150
  }
151
+ return this.doDel(pRoute, ...fRouteProcessingFunctions);
152
+ }
153
+ delWithBodyParser(pRoute, ...fRouteProcessingFunctions)
154
+ {
155
+ return this.del(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
156
+ }
111
157
 
158
+ doPatch(pRoute, ...fRouteProcessingFunctions)
159
+ {
112
160
  return true;
113
161
  }
114
-
115
162
  patch(pRoute, ...fRouteProcessingFunctions)
116
163
  {
117
164
  if (typeof(pRoute) != 'string')
@@ -119,10 +166,17 @@ class OratorServiceServerBase
119
166
  this.log.error(`Orator PATCH Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
120
167
  return false;
121
168
  }
169
+ return this.doPatch(pRoute, ...fRouteProcessingFunctions);
170
+ }
171
+ patchWithBodyParser(pRoute, ...fRouteProcessingFunctions)
172
+ {
173
+ return this.patch(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
174
+ }
122
175
 
176
+ doOpts(pRoute, ...fRouteProcessingFunctions)
177
+ {
123
178
  return true;
124
179
  }
125
-
126
180
  opts(pRoute, ...fRouteProcessingFunctions)
127
181
  {
128
182
  if (typeof(pRoute) != 'string')
@@ -130,10 +184,17 @@ class OratorServiceServerBase
130
184
  this.log.error(`Orator OPTS Route mapping failed -- route parameter was ${typeof(pRoute)} instead of a string.`)
131
185
  return false;
132
186
  }
187
+ return this.doOpts(pRoute, ...fRouteProcessingFunctions);
188
+ }
189
+ optsWithBodyParser(pRoute, ...fRouteProcessingFunctions)
190
+ {
191
+ return this.opts(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
192
+ }
133
193
 
194
+ doHead(pRoute, ...fRouteProcessingFunctions)
195
+ {
134
196
  return true;
135
197
  }
136
-
137
198
  head(pRoute, ...fRouteProcessingFunctions)
138
199
  {
139
200
  if (typeof(pRoute) != 'string')
@@ -144,6 +205,10 @@ class OratorServiceServerBase
144
205
 
145
206
  return true;
146
207
  }
208
+ headWithBodyParser(pRoute, ...fRouteProcessingFunctions)
209
+ {
210
+ return this.head(pRoute, this.bodyParser(), ...fRouteProcessingFunctions);
211
+ }
147
212
  /*************************************************************************
148
213
  * End of Service Route Creation Functions
149
214
  */
@@ -21,6 +21,8 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
21
21
  this.router = libFindMyWay(this.routerOptions);
22
22
  this.router.addConstraintStrategy(libOratorServiceServerIPCCustomConstrainer);
23
23
 
24
+ this.ServiceServerType = 'IPC';
25
+
24
26
  this.URL = 'IPC';
25
27
 
26
28
  this.preBehaviorFunctions = [];
@@ -163,48 +165,48 @@ class OratorServiceServerIPC extends libOratorServiceServerBase
163
165
  return true;
164
166
  }
165
167
 
166
- get(pRoute, ...fRouteProcessingFunctions)
168
+ // This is the virtualized "body parser"
169
+ bodyParser()
167
170
  {
168
- if (!super.get(pRoute, ...fRouteProcessingFunctions))
171
+ return (pRequest, pResponse, fNext) =>
169
172
  {
170
- this.log.error(`IPC provider failed to map GET route [${pRoute}]!`);
171
- return false;
172
- }
173
+ return fNext();
174
+ };
175
+ }
173
176
 
177
+ doGet(pRoute, ...fRouteProcessingFunctions)
178
+ {
174
179
  return this.addRouteProcessor('GET', pRoute, Array.from(fRouteProcessingFunctions));
175
180
  }
176
181
 
177
- put(pRoute, ...fRouteProcessingFunctions)
182
+ doPut(pRoute, ...fRouteProcessingFunctions)
178
183
  {
179
- if (!super.get(pRoute, ...fRouteProcessingFunctions))
180
- {
181
- this.log.error(`IPC provider failed to map PUT route [${pRoute}]!`);
182
- return false;
183
- }
184
+ return this.addRouteProcessor('PUT', pRoute, Array.from(fRouteProcessingFunctions));
185
+ }
184
186
 
185
- return true;
187
+ doPost(pRoute, ...fRouteProcessingFunctions)
188
+ {
189
+ return this.addRouteProcessor('POST', pRoute, Array.from(fRouteProcessingFunctions));
186
190
  }
187
191
 
188
- post(pRoute, ...fRouteProcessingFunctions)
192
+ doDel(pRoute, ...fRouteProcessingFunctions)
189
193
  {
190
- if (!super.get(pRoute, ...fRouteProcessingFunctions))
191
- {
192
- this.log.error(`IPC provider failed to map POST route [${pRoute}]!`);
193
- return false;
194
- }
194
+ return this.addRouteProcessor('DEL', pRoute, Array.from(fRouteProcessingFunctions));
195
+ }
195
196
 
196
- return true;
197
+ doPatch(pRoute, ...fRouteProcessingFunctions)
198
+ {
199
+ return this.addRouteProcessor('PATCH', pRoute, Array.from(fRouteProcessingFunctions));
197
200
  }
198
201
 
199
- del(pRoute, ...fRouteProcessingFunctions)
202
+ doOpts(pRoute, ...fRouteProcessingFunctions)
200
203
  {
201
- if (!super.get(pRoute, ...fRouteProcessingFunctions))
202
- {
203
- this.log.error(`IPC provider failed to map DEL route [${pRoute}]!`);
204
- return false;
205
- }
204
+ return this.addRouteProcessor('OPTS', pRoute, Array.from(fRouteProcessingFunctions));
205
+ }
206
206
 
207
- return true;
207
+ doHead(pRoute, ...fRouteProcessingFunctions)
208
+ {
209
+ return this.addRouteProcessor('HEAD', pRoute, Array.from(fRouteProcessingFunctions));
208
210
  }
209
211
  /*************************************************************************
210
212
  * End of Service Route Creation Functions
@@ -40,7 +40,12 @@ suite
40
40
  Expect(tmpOrator).to.be.an('object', 'Orator should initialize as an object directly from the require statement.');
41
41
  Expect(tmpOrator.startService).to.be.an('function');
42
42
  Expect(tmpOrator.settings).to.be.an('object');
43
- fDone();
43
+ tmpOrator.initializeServiceServer(
44
+ (pError)=>
45
+ {
46
+ Expect(tmpOrator.serviceServer.ServiceServerType).to.equal('IPC', 'The default service server provider should be IPC.');
47
+ fDone();
48
+ });
44
49
  }
45
50
  );
46
51