nodester 0.2.6 → 0.2.8
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/.eslintrc.js +13 -0
- package/Readme.md +8 -4
- package/lib/application/index.js +61 -53
- package/lib/body/extract.js +4 -4
- package/lib/controllers/methods/index.js +29 -14
- package/lib/controllers/mixins/index.js +13 -13
- package/lib/database/connection.js +78 -17
- package/lib/database/migration.js +9 -3
- package/lib/errors/CustomError.js +7 -2
- package/lib/errors/NodesterError.js +10 -2
- package/lib/errors/NodesterQueryError.js +9 -2
- package/lib/errors/index.js +2 -2
- package/lib/facades/methods/index.js +15 -15
- package/lib/facades/mixins/index.js +12 -12
- package/lib/factories/responses/html.js +20 -9
- package/lib/factories/responses/rest.js +21 -19
- package/lib/http/codes/descriptions.js +4 -3
- package/lib/http/codes/index.js +3 -2
- package/lib/http/codes/symbols.js +3 -2
- package/lib/http/request/index.js +20 -250
- package/lib/http/request/utils.js +4 -4
- package/lib/http/response/headers.js +16 -19
- package/lib/http/response/index.js +25 -28
- package/lib/http/response/utils.js +7 -6
- package/lib/loggers/console.js +3 -4
- package/lib/loggers/dev.js +3 -4
- package/lib/middlewares/404/index.js +38 -0
- package/lib/middlewares/SearchParams/index.js +3 -3
- package/lib/middlewares/cookies/index.js +2 -2
- package/lib/middlewares/etag/index.js +10 -8
- package/lib/middlewares/formidable/index.js +2 -2
- package/lib/middlewares/ql/sequelize/index.js +2 -2
- package/lib/middlewares/ql/sequelize/interpreter/ModelsTree.js +12 -2
- package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +10 -2
- package/lib/middlewares/render/index.js +3 -3
- package/lib/models/associate.js +3 -2
- package/lib/models/define.js +37 -18
- package/lib/models/mixins.js +9 -9
- package/lib/query/traverse.js +11 -3
- package/lib/router/handlers.util.js +5 -5
- package/lib/router/index.js +84 -70
- package/lib/router/markers.js +5 -5
- package/lib/router/route.js +18 -19
- package/lib/router/routes.util.js +4 -4
- package/lib/router/utils.js +2 -2
- package/lib/stacks/MarkersStack.js +11 -9
- package/lib/stacks/MiddlewaresStack.js +25 -21
- package/lib/structures/Enum.js +8 -2
- package/lib/structures/Filter.js +22 -20
- package/lib/structures/Params.js +3 -3
- package/lib/tools/nql.tool.js +10 -2
- package/lib/tools/sql.tool.js +19 -2
- package/lib/utils/json.util.js +28 -27
- package/lib/utils/models.js +3 -2
- package/lib/utils/objects.util.js +10 -11
- package/lib/utils/path.util.js +9 -3
- package/lib/utils/sanitizations.util.js +3 -2
- package/lib/utils/types.util.js +11 -4
- package/lib/validators/arguments.js +28 -9
- package/lib/validators/dates.js +4 -5
- package/lib/validators/numbers.js +4 -4
- package/package.json +43 -39
package/lib/router/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ const MarkersStack = require('../stacks/MarkersStack');
|
|
|
13
13
|
const MarkerMethods = require('./markers');
|
|
14
14
|
|
|
15
15
|
// Utils:
|
|
16
|
-
const { typeOf } = require('
|
|
16
|
+
const { typeOf } = require('nodester/utils/types');
|
|
17
17
|
const {
|
|
18
18
|
validateParsedRouteMethood,
|
|
19
19
|
wrapRouteHandler
|
|
@@ -32,25 +32,26 @@ const consl = require('nodester/loggers/console');
|
|
|
32
32
|
const debug = require('debug')('nodester:router');
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* @class
|
|
37
|
+
* @classdesc Main routing middleware
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} [options]
|
|
40
|
+
* @param {Array} [options.codeFileExtensions]
|
|
41
|
+
* @param {string} [options.controllersPath]
|
|
42
|
+
* @param {Object} [options.controllers]
|
|
43
|
+
* @param {boolean} [options.finalhandlerEnabled]
|
|
44
|
+
*
|
|
45
|
+
* @access public
|
|
46
|
+
*/
|
|
35
47
|
module.exports = class NodesterRouter {
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
* Initialize a new `NodesterRouter`.
|
|
39
|
-
*
|
|
40
|
-
* @param {Object} [opts]
|
|
41
|
-
* @param {Array} opts.codeFileExtensions
|
|
42
|
-
* @param {String} opts.controllersPath
|
|
43
|
-
* @param {Object} opts.controllers
|
|
44
|
-
* @param {Boolean} opts.finalhandlerEnabled
|
|
45
|
-
*
|
|
46
|
-
* @api public
|
|
47
|
-
*/
|
|
48
|
-
constructor(opts={}) {
|
|
49
|
+
constructor(options={}) {
|
|
49
50
|
// Reference to the controllers stack.
|
|
50
51
|
this._controllers = new Map();
|
|
51
52
|
|
|
52
53
|
// Reference to middlewares stack.
|
|
53
|
-
this._middlewares = new MiddlewaresStack({ finalhandlerEnabled: !!
|
|
54
|
+
this._middlewares = new MiddlewaresStack({ finalhandlerEnabled: !!options.finalhandlerEnabled });
|
|
54
55
|
|
|
55
56
|
// Reference to the markers stack.
|
|
56
57
|
this._markers = new MarkersStack();
|
|
@@ -63,19 +64,30 @@ module.exports = class NodesterRouter {
|
|
|
63
64
|
|
|
64
65
|
// Options:
|
|
65
66
|
// if "codeFileExtensions" was set:
|
|
66
|
-
if (!!
|
|
67
|
-
|
|
67
|
+
if (!!options.codeFileExtensions) {
|
|
68
|
+
ensure(options.codeFileExtensions, 'array', 'options.codeFileExtensions');
|
|
69
|
+
this.codeFileExtensions = [...options.codeFileExtensions];
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
// If "controllersPath" was set,
|
|
71
73
|
// cache all controllers in directory:
|
|
72
|
-
if (!!
|
|
74
|
+
if (!!options.controllersPath) {
|
|
75
|
+
ensure(options.controllersPath, 'string', 'options.controllersPath');
|
|
76
|
+
|
|
73
77
|
// Save path.
|
|
74
|
-
this.paths.controllers =
|
|
78
|
+
this.paths.controllers = options.controllersPath;
|
|
75
79
|
|
|
76
80
|
// Only get files, which have available file extensions:
|
|
77
81
|
const availableFileExtensions = this.codeFileExtensions;
|
|
78
|
-
|
|
82
|
+
|
|
83
|
+
let fileNames;
|
|
84
|
+
try {
|
|
85
|
+
fileNames = fs.readdirSync(this.paths.controllers);
|
|
86
|
+
}
|
|
87
|
+
catch(error) {
|
|
88
|
+
Error.captureStackTrace(error, this.constructor);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
79
91
|
|
|
80
92
|
const controllersNames = parseProviderFileNames(fileNames, availableFileExtensions, 'controller');
|
|
81
93
|
|
|
@@ -86,10 +98,10 @@ module.exports = class NodesterRouter {
|
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
// If "controllers" were provided as an Object:
|
|
89
|
-
if (!!
|
|
90
|
-
ensure(
|
|
101
|
+
if (!!options.controllers) {
|
|
102
|
+
ensure(options.controllers, 'object', 'options.controllers');
|
|
91
103
|
|
|
92
|
-
const entities = Object.entities(
|
|
104
|
+
const entities = Object.entities(options.controllers);
|
|
93
105
|
for (const [controllerName, controllerDefinition] of entities) {
|
|
94
106
|
this.addController(controllerDefinition, controllerName);
|
|
95
107
|
}
|
|
@@ -97,9 +109,11 @@ module.exports = class NodesterRouter {
|
|
|
97
109
|
|
|
98
110
|
// If "providersPath" was set,
|
|
99
111
|
// cache all providers in directory:
|
|
100
|
-
if (!!
|
|
112
|
+
if (!!options.providersPath) {
|
|
113
|
+
ensure(options.providersPath, 'string', 'options.providersPath');
|
|
114
|
+
|
|
101
115
|
// Save path.
|
|
102
|
-
this.paths.providers =
|
|
116
|
+
this.paths.providers = options.providersPath;
|
|
103
117
|
|
|
104
118
|
// Only get files, which have available file extensions:
|
|
105
119
|
const availableFileExtensions = this.codeFileExtensions;
|
|
@@ -114,10 +128,10 @@ module.exports = class NodesterRouter {
|
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
// If "providers" were provided as an Object:
|
|
117
|
-
if (!!
|
|
118
|
-
ensure(
|
|
131
|
+
if (!!options.providers) {
|
|
132
|
+
ensure(options.providers, 'object', 'options.providers');
|
|
119
133
|
|
|
120
|
-
const entities = Object.entities(
|
|
134
|
+
const entities = Object.entities(options.providers);
|
|
121
135
|
for (const [providerName, providerDefinition] of entities) {
|
|
122
136
|
this.addProvider(providerDefinition, providerName);
|
|
123
137
|
}
|
|
@@ -129,7 +143,7 @@ module.exports = class NodesterRouter {
|
|
|
129
143
|
/**
|
|
130
144
|
* @return {MiddlewaresStack}
|
|
131
145
|
*
|
|
132
|
-
* @
|
|
146
|
+
* @access public
|
|
133
147
|
*/
|
|
134
148
|
get middlewaresStack() {
|
|
135
149
|
return this._middlewares;
|
|
@@ -138,9 +152,9 @@ module.exports = class NodesterRouter {
|
|
|
138
152
|
/**
|
|
139
153
|
* Indicates whether user can add more middlewares or not.
|
|
140
154
|
*
|
|
141
|
-
* @return {
|
|
155
|
+
* @return {boolean} isLocked
|
|
142
156
|
*
|
|
143
|
-
* @
|
|
157
|
+
* @access public
|
|
144
158
|
*/
|
|
145
159
|
get isLocked() {
|
|
146
160
|
return this._middlewares.isLocked;
|
|
@@ -148,7 +162,7 @@ module.exports = class NodesterRouter {
|
|
|
148
162
|
|
|
149
163
|
// Getters\
|
|
150
164
|
|
|
151
|
-
|
|
165
|
+
/**
|
|
152
166
|
* Adds:
|
|
153
167
|
* - (controller) new Controller to the stack;
|
|
154
168
|
* - (middleware) new Middleware to the stack;
|
|
@@ -157,7 +171,7 @@ module.exports = class NodesterRouter {
|
|
|
157
171
|
* - (route) new Route to the stack;
|
|
158
172
|
* - (routes) array[Route] to the stack;
|
|
159
173
|
*
|
|
160
|
-
* @
|
|
174
|
+
* @access public
|
|
161
175
|
*/
|
|
162
176
|
get add() {
|
|
163
177
|
return {
|
|
@@ -171,13 +185,13 @@ module.exports = class NodesterRouter {
|
|
|
171
185
|
}
|
|
172
186
|
|
|
173
187
|
|
|
174
|
-
|
|
188
|
+
/**
|
|
175
189
|
* Adds new controller to the controllers stack.
|
|
176
190
|
*
|
|
177
191
|
* @param {Function|Object} controller
|
|
178
|
-
* @param {
|
|
192
|
+
* @param {string} controllerName
|
|
179
193
|
*
|
|
180
|
-
* @
|
|
194
|
+
* @access public
|
|
181
195
|
*/
|
|
182
196
|
addController(controller, controllerName=null) {
|
|
183
197
|
try {
|
|
@@ -206,15 +220,15 @@ module.exports = class NodesterRouter {
|
|
|
206
220
|
}
|
|
207
221
|
|
|
208
222
|
|
|
209
|
-
|
|
223
|
+
/**
|
|
210
224
|
* Adds new middleware to the stack.
|
|
211
225
|
*
|
|
212
226
|
* @param {Function} fn
|
|
213
|
-
* @param {
|
|
227
|
+
* @param {Int} index (0 or undefined)
|
|
214
228
|
*
|
|
215
|
-
* @return {
|
|
229
|
+
* @return {Int} index of the new middleware
|
|
216
230
|
*
|
|
217
|
-
* @
|
|
231
|
+
* @access public
|
|
218
232
|
*/
|
|
219
233
|
addMiddleware(fn, index) {
|
|
220
234
|
try {
|
|
@@ -230,13 +244,13 @@ module.exports = class NodesterRouter {
|
|
|
230
244
|
}
|
|
231
245
|
|
|
232
246
|
|
|
233
|
-
|
|
247
|
+
/**
|
|
234
248
|
* Adds new marker to the stack.
|
|
235
249
|
*
|
|
236
|
-
* @param {
|
|
250
|
+
* @param {string} markerName
|
|
237
251
|
* @param {Function} fn
|
|
238
252
|
*
|
|
239
|
-
* @
|
|
253
|
+
* @access public
|
|
240
254
|
*/
|
|
241
255
|
addMarker(markerName='', fn) {
|
|
242
256
|
try {
|
|
@@ -262,13 +276,13 @@ module.exports = class NodesterRouter {
|
|
|
262
276
|
}
|
|
263
277
|
|
|
264
278
|
|
|
265
|
-
|
|
279
|
+
/**
|
|
266
280
|
* Adds new provider to the providers stack.
|
|
267
281
|
*
|
|
268
282
|
* @param {Function|Object} provider
|
|
269
|
-
* @param {
|
|
283
|
+
* @param {string} providerName
|
|
270
284
|
*
|
|
271
|
-
* @
|
|
285
|
+
* @access public
|
|
272
286
|
*/
|
|
273
287
|
addProvider(provider, providerName=null) {
|
|
274
288
|
try {
|
|
@@ -298,13 +312,13 @@ module.exports = class NodesterRouter {
|
|
|
298
312
|
}
|
|
299
313
|
|
|
300
314
|
|
|
301
|
-
|
|
315
|
+
/**
|
|
302
316
|
* Creates route middleware and adds it to the stack.
|
|
303
317
|
*
|
|
304
|
-
* @param {
|
|
318
|
+
* @param {string} route
|
|
305
319
|
* @param {Object|Function} handler
|
|
306
320
|
*
|
|
307
|
-
* @
|
|
321
|
+
* @access public
|
|
308
322
|
*/
|
|
309
323
|
addRoute(route='', handler) {
|
|
310
324
|
try {
|
|
@@ -333,13 +347,13 @@ module.exports = class NodesterRouter {
|
|
|
333
347
|
}
|
|
334
348
|
|
|
335
349
|
|
|
336
|
-
|
|
350
|
+
/**
|
|
337
351
|
* Loops through provided "routes" object
|
|
338
352
|
* and adds them throught "addRoute".
|
|
339
353
|
*
|
|
340
354
|
* @param {Object} routes
|
|
341
355
|
*
|
|
342
|
-
* @
|
|
356
|
+
* @access public
|
|
343
357
|
*/
|
|
344
358
|
addRoutes(routes={}) {
|
|
345
359
|
try {
|
|
@@ -356,12 +370,12 @@ module.exports = class NodesterRouter {
|
|
|
356
370
|
}
|
|
357
371
|
|
|
358
372
|
|
|
359
|
-
|
|
373
|
+
/**
|
|
360
374
|
* Proxy to .add.middleware()
|
|
361
375
|
*
|
|
362
376
|
* @param {Function|NodesterRouter} fnOrRouter
|
|
363
377
|
*
|
|
364
|
-
* @
|
|
378
|
+
* @access public
|
|
365
379
|
*/
|
|
366
380
|
use(fnOrRouter) {
|
|
367
381
|
try {
|
|
@@ -383,12 +397,12 @@ module.exports = class NodesterRouter {
|
|
|
383
397
|
}
|
|
384
398
|
|
|
385
399
|
|
|
386
|
-
|
|
400
|
+
/**
|
|
387
401
|
* Adds middlewares, which only fires for set marker.
|
|
388
402
|
*
|
|
389
|
-
* @param {
|
|
403
|
+
* @param {string} markerName
|
|
390
404
|
*
|
|
391
|
-
* @
|
|
405
|
+
* @access public
|
|
392
406
|
*/
|
|
393
407
|
only(markerName='') {
|
|
394
408
|
try {
|
|
@@ -412,17 +426,17 @@ module.exports = class NodesterRouter {
|
|
|
412
426
|
/**
|
|
413
427
|
* Handles server request.
|
|
414
428
|
*
|
|
415
|
-
* @
|
|
429
|
+
* @access public
|
|
416
430
|
*/
|
|
417
431
|
handle(req, res, next) {
|
|
418
432
|
return this._middlewares.process(req, res, next)
|
|
419
433
|
}
|
|
420
434
|
|
|
421
435
|
|
|
422
|
-
|
|
436
|
+
/**
|
|
423
437
|
* Prepare router for processing.
|
|
424
438
|
*
|
|
425
|
-
* @
|
|
439
|
+
* @access public
|
|
426
440
|
*/
|
|
427
441
|
lock() {
|
|
428
442
|
// Stack is ready.
|
|
@@ -431,10 +445,10 @@ module.exports = class NodesterRouter {
|
|
|
431
445
|
}
|
|
432
446
|
|
|
433
447
|
|
|
434
|
-
|
|
448
|
+
/**
|
|
435
449
|
* Unlocks router.
|
|
436
450
|
*
|
|
437
|
-
* @
|
|
451
|
+
* @access public
|
|
438
452
|
*/
|
|
439
453
|
unlock() {
|
|
440
454
|
this._middlewares.unlock();
|
|
@@ -442,7 +456,7 @@ module.exports = class NodesterRouter {
|
|
|
442
456
|
}
|
|
443
457
|
|
|
444
458
|
|
|
445
|
-
|
|
459
|
+
/**
|
|
446
460
|
* Removes something
|
|
447
461
|
*/
|
|
448
462
|
get remove() {
|
|
@@ -455,11 +469,11 @@ module.exports = class NodesterRouter {
|
|
|
455
469
|
/**
|
|
456
470
|
* Removes middleware at index.
|
|
457
471
|
*
|
|
458
|
-
* @param {
|
|
472
|
+
* @param {Int} index
|
|
459
473
|
*
|
|
460
|
-
* @return {
|
|
474
|
+
* @return {Int} middlewares stack length
|
|
461
475
|
*
|
|
462
|
-
* @
|
|
476
|
+
* @access public
|
|
463
477
|
*/
|
|
464
478
|
removeMiddleware(index=-1) {
|
|
465
479
|
try {
|
|
@@ -479,12 +493,12 @@ module.exports = class NodesterRouter {
|
|
|
479
493
|
/**
|
|
480
494
|
* Extends Router & makes sure, that "key" param is not present already.
|
|
481
495
|
*
|
|
482
|
-
* @param {
|
|
483
|
-
* @param {
|
|
496
|
+
* @param {string} key
|
|
497
|
+
* @param {any} fnOrProperty
|
|
484
498
|
*
|
|
485
|
-
* @return {
|
|
499
|
+
* @return {any} fnOrProperty in Router
|
|
486
500
|
*
|
|
487
|
-
* @
|
|
501
|
+
* @access public
|
|
488
502
|
*/
|
|
489
503
|
extend(key='', fnOrProperty) {
|
|
490
504
|
ensure(key, 'string,required', 'key');
|
package/lib/router/markers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -18,9 +18,9 @@ module.exports = {
|
|
|
18
18
|
onlyUse: _onlyUse
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
22
|
*
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {string} route
|
|
24
24
|
* @param {Function} fn
|
|
25
25
|
* @param {Function} markerFn
|
|
26
26
|
*
|
|
@@ -51,7 +51,7 @@ function _onlyRoute(route, fn, markerFn) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
55
|
*
|
|
56
56
|
* @param {Function} fnOrRouter
|
|
57
57
|
* @param {Function} markerFn
|
package/lib/router/route.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
// Utils.
|
|
9
|
-
const { typeOf } = require('
|
|
9
|
+
const { typeOf } = require('nodester/utils/types');
|
|
10
10
|
|
|
11
11
|
// Arguments validator.
|
|
12
12
|
const { ensure } = require('nodester/validators/arguments');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Initialize a new `NodesterRoute`.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object|String} routeStringOrOpts
|
|
19
|
+
* @param {string} [routeStringOrOpts.method]
|
|
20
|
+
* @param {string} [routeStringOrOpts.route]
|
|
21
|
+
* @param {Array} [routeStringOrOpts.parts]
|
|
22
|
+
* @param {Object} [routeStringOrOpts.params]
|
|
23
|
+
*
|
|
24
|
+
* @access public
|
|
25
|
+
*/
|
|
15
26
|
module.exports = class NodesterRoute {
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Initialize a new `NodesterRoute`.
|
|
19
|
-
*
|
|
20
|
-
* @param {Object|String} routeStringOrOpts
|
|
21
|
-
* - {String} method
|
|
22
|
-
* - {String} route
|
|
23
|
-
* - {Array} parts
|
|
24
|
-
* - {Object} params
|
|
25
|
-
*
|
|
26
|
-
* @api public
|
|
27
|
-
*/
|
|
27
|
+
|
|
28
28
|
constructor(routeStringOrOpts={}) {
|
|
29
29
|
ensure(routeStringOrOpts, 'object|string,required', 'routeStringOrOpts');
|
|
30
30
|
|
|
@@ -67,12 +67,11 @@ module.exports = class NodesterRoute {
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* @param {
|
|
70
|
+
* @param {string} routeToTest
|
|
71
71
|
*
|
|
72
|
-
* @return {
|
|
72
|
+
* @return {boolean}
|
|
73
73
|
*
|
|
74
|
-
* @
|
|
75
|
-
* @private
|
|
74
|
+
* @access private
|
|
76
75
|
*/
|
|
77
76
|
matches(routeToTest='') {
|
|
78
77
|
const {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
// Utils:
|
|
9
|
-
const { typeOf } = require('
|
|
9
|
+
const { typeOf } = require('nodester/utils/types');
|
|
10
10
|
const { parseRouteHandler } = require('./handlers.util');
|
|
11
11
|
|
|
12
12
|
|
|
@@ -33,7 +33,7 @@ function _validateParsedRouteMethood(parsedRoute) {
|
|
|
33
33
|
* @param {Function} handler
|
|
34
34
|
*
|
|
35
35
|
* @alias wrapRouteHandler
|
|
36
|
-
* @
|
|
36
|
+
* @access public
|
|
37
37
|
*/
|
|
38
38
|
function _wrapRouteHandler(routeInstance, handler) {
|
|
39
39
|
const handlerType = typeOf(handler);
|
package/lib/router/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -13,11 +13,11 @@ const consl = require('nodester/loggers/console');
|
|
|
13
13
|
const debug = require('debug')('nodester:MiddlewareStack');
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
17
|
* Creates new MarkersStack.
|
|
18
|
+
* @class
|
|
18
19
|
*
|
|
19
20
|
* @return {MarkersStack}
|
|
20
|
-
*
|
|
21
21
|
*/
|
|
22
22
|
module.exports = class MarkersStack {
|
|
23
23
|
constructor() {
|
|
@@ -31,12 +31,12 @@ module.exports = class MarkersStack {
|
|
|
31
31
|
/**
|
|
32
32
|
* Add the given middleware `fn` to the stack.
|
|
33
33
|
*
|
|
34
|
-
* @param {
|
|
34
|
+
* @param {string} markerName
|
|
35
35
|
* @param {Function} fn
|
|
36
36
|
*
|
|
37
|
-
* @return {
|
|
37
|
+
* @return {Int} index - of the new middleware
|
|
38
38
|
*
|
|
39
|
-
* @
|
|
39
|
+
* @access public
|
|
40
40
|
*/
|
|
41
41
|
add(markerName='', fn) {
|
|
42
42
|
try {
|
|
@@ -55,9 +55,11 @@ module.exports = class MarkersStack {
|
|
|
55
55
|
/**
|
|
56
56
|
* Get middleware function by marker name.
|
|
57
57
|
*
|
|
58
|
-
* @param {
|
|
58
|
+
* @param {string} markerName
|
|
59
|
+
*
|
|
60
|
+
* @return {Function} marker
|
|
59
61
|
*
|
|
60
|
-
* @
|
|
62
|
+
* @access public
|
|
61
63
|
*/
|
|
62
64
|
get(markerName='') {
|
|
63
65
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -15,14 +15,13 @@ const consl = require('nodester/loggers/console');
|
|
|
15
15
|
const debug = require('debug')('nodester:MiddlewaresStack');
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
19
|
* Creates new MiddlewaresStack.
|
|
20
|
-
*
|
|
20
|
+
* @class
|
|
21
21
|
* @param {Object} [opts]
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {boolean} opts.finalhandlerEnabled
|
|
23
23
|
*
|
|
24
24
|
* @return {MiddlewaresStack}
|
|
25
|
-
*
|
|
26
25
|
*/
|
|
27
26
|
module.exports = class MiddlewaresStack {
|
|
28
27
|
constructor(opts={}) {
|
|
@@ -56,9 +55,9 @@ module.exports = class MiddlewaresStack {
|
|
|
56
55
|
/**
|
|
57
56
|
* Indicates whether user can add more middlewares or not.
|
|
58
57
|
*
|
|
59
|
-
* @return {
|
|
58
|
+
* @return {boolean} isLocked
|
|
60
59
|
*
|
|
61
|
-
* @
|
|
60
|
+
* @access public
|
|
62
61
|
*/
|
|
63
62
|
get isLocked() {
|
|
64
63
|
return this._isLocked === true;
|
|
@@ -70,11 +69,11 @@ module.exports = class MiddlewaresStack {
|
|
|
70
69
|
* Add the given middleware `fn` to the stack.
|
|
71
70
|
*
|
|
72
71
|
* @param {Function} fn
|
|
73
|
-
* @param {
|
|
72
|
+
* @param {Int} index (0 or undefined)
|
|
74
73
|
*
|
|
75
|
-
* @return {
|
|
74
|
+
* @return {Int} index of the new middleware
|
|
76
75
|
*
|
|
77
|
-
* @
|
|
76
|
+
* @access public
|
|
78
77
|
*/
|
|
79
78
|
add(fn, index) {
|
|
80
79
|
try {
|
|
@@ -109,11 +108,11 @@ module.exports = class MiddlewaresStack {
|
|
|
109
108
|
/**
|
|
110
109
|
* Removes middleware at index.
|
|
111
110
|
*
|
|
112
|
-
* @param {
|
|
111
|
+
* @param {Int} index
|
|
113
112
|
*
|
|
114
113
|
* @return {MiddlewaresStack} self
|
|
115
114
|
*
|
|
116
|
-
* @
|
|
115
|
+
* @access public
|
|
117
116
|
*/
|
|
118
117
|
remove(index=-1) {
|
|
119
118
|
try {
|
|
@@ -135,10 +134,10 @@ module.exports = class MiddlewaresStack {
|
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
|
|
138
|
-
|
|
137
|
+
/**
|
|
139
138
|
* Prepare stack for processing.
|
|
140
139
|
*
|
|
141
|
-
* @
|
|
140
|
+
* @access public
|
|
142
141
|
*/
|
|
143
142
|
lock() {
|
|
144
143
|
if (this._finalhandlerEnabled) {
|
|
@@ -153,14 +152,14 @@ module.exports = class MiddlewaresStack {
|
|
|
153
152
|
}
|
|
154
153
|
|
|
155
154
|
|
|
156
|
-
|
|
155
|
+
/**
|
|
157
156
|
* Unlocks stack.
|
|
158
157
|
*
|
|
159
|
-
* @
|
|
158
|
+
* @access public
|
|
160
159
|
*/
|
|
161
160
|
unlock() {
|
|
162
161
|
this._isLocked = false;
|
|
163
|
-
|
|
162
|
+
|
|
164
163
|
if (this._finalhandlerEnabled) {
|
|
165
164
|
this._middlewares.pop();
|
|
166
165
|
}
|
|
@@ -169,10 +168,15 @@ module.exports = class MiddlewaresStack {
|
|
|
169
168
|
}
|
|
170
169
|
|
|
171
170
|
|
|
172
|
-
|
|
173
|
-
*
|
|
171
|
+
/**
|
|
172
|
+
* Call the first middleware in the stack.
|
|
173
|
+
* Every N-th middleware will be called by the previous one in the stack by invoking next().
|
|
174
|
+
*
|
|
175
|
+
* @param {IncomingMessage} req
|
|
176
|
+
* @param {ServerResponse} res
|
|
177
|
+
* @param {Function} next
|
|
174
178
|
*
|
|
175
|
-
* @
|
|
179
|
+
* @access public
|
|
176
180
|
*/
|
|
177
181
|
process(req, res, next) {
|
|
178
182
|
let middlewareOffset = -1;
|
package/lib/structures/Enum.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @class
|
|
11
|
+
* @classdesc Convinient structure to describe a set of constants.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} constantsList
|
|
14
|
+
*/
|
|
9
15
|
module.exports = function Enum(constantsList={}) {
|
|
10
16
|
_setGetters(this, constantsList);
|
|
11
17
|
|