nodester 0.0.9 → 0.1.4
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/Readme.md +16 -2
- package/lib/application/index.js +29 -8
- package/lib/constants/ErrorCodes.js +19 -0
- package/lib/constants/Operations.js +1 -1
- package/lib/controllers/methods/index.js +34 -10
- package/lib/controllers/mixins/index.js +72 -24
- package/lib/database/connection.js +34 -0
- package/lib/database/migration.js +42 -0
- package/lib/database/utils.js +19 -0
- package/lib/facades/methods/index.js +180 -0
- package/lib/facades/mixins/index.js +111 -0
- package/lib/factories/errors/CustomError.js +7 -0
- package/lib/factories/errors/NodesterQueryError.js +23 -0
- package/lib/factories/errors/index.js +10 -3
- package/lib/loggers/dev.js +28 -0
- package/lib/middlewares/formidable/index.js +37 -0
- package/lib/middlewares/ql/sequelize/interpreter/ModelsTree.js +26 -3
- package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +67 -15
- package/lib/models/define.js +49 -1
- package/lib/models/mixins.js +76 -67
- package/lib/params/Params.js +10 -7
- package/lib/queries/Colander.js +107 -0
- package/lib/queries/NodesterQueryParams.js +6 -0
- package/lib/queries/traverse.js +381 -0
- package/lib/router/handlers.util.js +22 -2
- package/lib/router/index.js +97 -76
- package/lib/router/markers.js +78 -0
- package/lib/router/route.js +4 -4
- package/lib/router/routes.util.js +35 -5
- package/lib/router/utils.js +30 -0
- package/lib/stacks/MarkersStack.js +1 -1
- package/lib/stacks/MiddlewareStack.js +1 -1
- package/lib/utils/models.js +14 -0
- package/package.json +36 -7
- package/tests/nql.test.js +3 -3
- package/lib/_/n_controllers/Controller.js +0 -474
- package/lib/_/n_controllers/JWTController.js +0 -240
- package/lib/_/n_controllers/ServiceController.js +0 -109
- package/lib/_/n_controllers/WebController.js +0 -75
- package/lib/_facades/Facade.js +0 -388
- package/lib/_facades/FacadeParams.js +0 -11
- package/lib/_facades/ServiceFacade.js +0 -17
- package/lib/_facades/jwt.facade.js +0 -273
- package/lib/models/Extractor.js +0 -320
- package/lib/preprocessors/IncludesPreprocessor.js +0 -55
- package/lib/preprocessors/QueryPreprocessor.js +0 -64
- package/lib/utils/forms.util.js +0 -22
- /package/lib/{logger → loggers}/console.js +0 -0
package/lib/router/index.js
CHANGED
|
@@ -6,17 +6,23 @@
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
const MiddlewareStack = require('../stacks/MiddlewareStack');
|
|
9
|
-
const MarkersStack = require('../stacks/MarkersStack');
|
|
10
9
|
const Route = require('./route');
|
|
10
|
+
// Markers:
|
|
11
|
+
const MarkersStack = require('../stacks/MarkersStack');
|
|
12
|
+
const MarkerMethods = require('./markers');
|
|
11
13
|
// Utils:
|
|
12
14
|
const { typeOf } = require('../utils/types.util');
|
|
13
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
validateParsedRouteMethood,
|
|
17
|
+
wrapRouteHandler
|
|
18
|
+
} = require('./routes.util');
|
|
19
|
+
const { parseProviderFileNames } = require('./utils');
|
|
14
20
|
// File system:
|
|
15
21
|
const Path = require('path');
|
|
16
22
|
const fs = require('fs');
|
|
17
23
|
const commonExtensions = require('common-js-file-extensions');
|
|
18
24
|
// Debug & console:
|
|
19
|
-
const consl = require('
|
|
25
|
+
const consl = require('nodester/loggers/console');
|
|
20
26
|
const debug = require('debug')('nodester:router');
|
|
21
27
|
|
|
22
28
|
|
|
@@ -34,14 +40,17 @@ module.exports = class NodesterRouter {
|
|
|
34
40
|
* @api public
|
|
35
41
|
*/
|
|
36
42
|
constructor(opts={}) {
|
|
43
|
+
// Reference to the controllers stack.
|
|
44
|
+
this._controllers = new Map();
|
|
45
|
+
|
|
37
46
|
// Reference to middlewares stack.
|
|
38
47
|
this._middlewares = new MiddlewareStack({ finalhandlerEnabled: !!opts.finalhandlerEnabled });
|
|
39
48
|
|
|
40
49
|
// Reference to the markers stack.
|
|
41
50
|
this._markers = new MarkersStack();
|
|
42
51
|
|
|
43
|
-
// Reference to the
|
|
44
|
-
this.
|
|
52
|
+
// Reference to the providers stack.
|
|
53
|
+
this._providers = new Map();
|
|
45
54
|
|
|
46
55
|
this.codeFileExtensions = commonExtensions.code;
|
|
47
56
|
this.paths = {};
|
|
@@ -55,29 +64,20 @@ module.exports = class NodesterRouter {
|
|
|
55
64
|
this.codeFileExtensions = [...opts.codeFileExtensions];
|
|
56
65
|
}
|
|
57
66
|
|
|
58
|
-
// If "controllersPath" was set,
|
|
67
|
+
// If "controllersPath" was set,
|
|
68
|
+
// cache all controllers in directory:
|
|
59
69
|
if (!!opts.controllersPath) {
|
|
60
70
|
// Save path.
|
|
61
71
|
this.paths.controllers = opts.controllersPath;
|
|
62
72
|
|
|
63
|
-
const availableFileExtensions = this.codeFileExtensions;
|
|
64
73
|
// Only get files, which have available file extensions:
|
|
74
|
+
const availableFileExtensions = this.codeFileExtensions;
|
|
65
75
|
const fileNames = fs.readdirSync(this.paths.controllers);
|
|
66
|
-
for (const fileName of fileNames) {
|
|
67
|
-
|
|
68
|
-
const nameParts = fileName.split('.');
|
|
69
|
-
const extension = nameParts.pop();
|
|
70
|
-
if (availableFileExtensions.indexOf(extension) === -1) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
// but second part is not "controller":
|
|
76
|
-
if (nameParts.length > 1 && nameParts[1] !== 'controller')
|
|
77
|
-
continue;
|
|
77
|
+
const controllersNames = parseProviderFileNames(fileNames, availableFileExtensions, 'controller');
|
|
78
78
|
|
|
79
|
+
for (const { fileName, controllerName } of controllersNames) {
|
|
79
80
|
const controller = require(Path.join(this.paths.controllers, fileName));
|
|
80
|
-
const controllerName = nameParts[0];
|
|
81
81
|
this.addController(controller, controllerName);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -94,6 +94,37 @@ module.exports = class NodesterRouter {
|
|
|
94
94
|
this.addController(controllerDefinition, controllerName);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
// If "providersPath" was set,
|
|
99
|
+
// cache all providers in directory:
|
|
100
|
+
if (!!opts.providersPath) {
|
|
101
|
+
// Save path.
|
|
102
|
+
this.paths.providers = opts.providersPath;
|
|
103
|
+
|
|
104
|
+
// Only get files, which have available file extensions:
|
|
105
|
+
const availableFileExtensions = this.codeFileExtensions;
|
|
106
|
+
const fileNames = fs.readdirSync(this.paths.providers);
|
|
107
|
+
|
|
108
|
+
const providersNames = parseProviderFileNames(fileNames, availableFileExtensions, 'provider');
|
|
109
|
+
|
|
110
|
+
for (const { fileName, providerName } of providersNames) {
|
|
111
|
+
const provider = require(Path.join(this.paths.providers, fileName));
|
|
112
|
+
this.addProvider(provider, providerName);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// If "providers" were provided as an Object:
|
|
117
|
+
if (!!opts.providers) {
|
|
118
|
+
if (typeOf(opts.providers) !== 'Object') {
|
|
119
|
+
const err = new TypeError(`"providers" must be an Object.`);
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const entities = Object.entities(opts.providers);
|
|
124
|
+
for (const [providerName, providerDefinition] of entities) {
|
|
125
|
+
this.addProvider(providerDefinition, providerName);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
97
128
|
}
|
|
98
129
|
|
|
99
130
|
|
|
@@ -111,6 +142,7 @@ module.exports = class NodesterRouter {
|
|
|
111
142
|
controller: this.addController.bind(this),
|
|
112
143
|
middleware: this.addMiddleware.bind(this),
|
|
113
144
|
marker: this.addMarker.bind(this),
|
|
145
|
+
provider: this.addProvider.bind(this),
|
|
114
146
|
route: this.addRoute.bind(this),
|
|
115
147
|
routes: this.addRoutes.bind(this),
|
|
116
148
|
}
|
|
@@ -182,6 +214,33 @@ module.exports = class NodesterRouter {
|
|
|
182
214
|
}
|
|
183
215
|
|
|
184
216
|
|
|
217
|
+
/*
|
|
218
|
+
* Adds new provider to the providers stack.
|
|
219
|
+
*
|
|
220
|
+
* @param {Function|Object} provider
|
|
221
|
+
* @param {String} providerName
|
|
222
|
+
*
|
|
223
|
+
* @api public
|
|
224
|
+
*/
|
|
225
|
+
addProvider(fnOrObject, providerName=null) {
|
|
226
|
+
const providerType = typeOf(fnOrObject);
|
|
227
|
+
const name = providerName ?? fnOrObject?.name ?? fnOrObject.constructor.name;
|
|
228
|
+
|
|
229
|
+
// If provider was exported as Object:
|
|
230
|
+
if (providerType === 'Object') {
|
|
231
|
+
this._providers.set(name, fnOrObject);
|
|
232
|
+
}
|
|
233
|
+
// If provider was exported as a constructor function:
|
|
234
|
+
else if (providerType === 'function') {
|
|
235
|
+
this._providers.set(name, new fnOrObject());
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const err = new TypeError(`Please check how you exported ${ name }, it should be either Object or constructor function.`);
|
|
239
|
+
throw err;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
185
244
|
/*
|
|
186
245
|
* Creates route middleware and adds it to the stack.
|
|
187
246
|
*
|
|
@@ -191,21 +250,19 @@ module.exports = class NodesterRouter {
|
|
|
191
250
|
* @api public
|
|
192
251
|
*/
|
|
193
252
|
addRoute(route='', handler) {
|
|
194
|
-
const
|
|
195
|
-
|
|
253
|
+
const parsedRoute = new Route(route);
|
|
254
|
+
// Will throw exception if not valid.
|
|
255
|
+
validateParsedRouteMethood(parsedRoute);
|
|
196
256
|
|
|
197
|
-
|
|
198
|
-
if (parsed.method === undefined) {
|
|
199
|
-
const err = new TypeError(`"route" should start with one of the following methods: [GET, POST, PUT, DELETE, QUERY, HEADER, OPTIONS]`);
|
|
200
|
-
throw err;
|
|
201
|
-
}
|
|
257
|
+
const handlerType = typeOf(handler);
|
|
202
258
|
|
|
203
|
-
if (handlerType === 'Object' && !this.paths.controllers) {
|
|
204
|
-
const
|
|
259
|
+
if (handlerType === 'Object' && !this.paths.controllers && !this.paths.providers) {
|
|
260
|
+
const msg = `Please set "controllersPath" or "providersPath" during Router initialization.`;
|
|
261
|
+
const err = new TypeError(msg);
|
|
205
262
|
throw err;
|
|
206
263
|
}
|
|
207
264
|
|
|
208
|
-
const wrapped = wrapRouteHandler.call(this,
|
|
265
|
+
const wrapped = wrapRouteHandler.call(this, parsedRoute, handler);
|
|
209
266
|
return this.addMiddleware(wrapped);
|
|
210
267
|
}
|
|
211
268
|
|
|
@@ -228,11 +285,18 @@ module.exports = class NodesterRouter {
|
|
|
228
285
|
/*
|
|
229
286
|
* Proxy to .add.middleware()
|
|
230
287
|
*
|
|
231
|
-
* @param {Function}
|
|
288
|
+
* @param {Function|NodesterRouter} fnOrRouter
|
|
232
289
|
*
|
|
233
290
|
* @api public
|
|
234
291
|
*/
|
|
235
|
-
use(
|
|
292
|
+
use(fnOrRouter) {
|
|
293
|
+
let fn = fnOrRouter;
|
|
294
|
+
|
|
295
|
+
// If Router:
|
|
296
|
+
if (fnOrRouter instanceof NodesterRouter) {
|
|
297
|
+
fn = fnOrRouter.handle.bind(fnOrRouter);
|
|
298
|
+
}
|
|
299
|
+
|
|
236
300
|
return this.add.middleware(fn);
|
|
237
301
|
}
|
|
238
302
|
|
|
@@ -249,51 +313,8 @@ module.exports = class NodesterRouter {
|
|
|
249
313
|
const markerFn = this._markers.get(markerName);
|
|
250
314
|
|
|
251
315
|
return {
|
|
252
|
-
route: (route, fn) =>
|
|
253
|
-
|
|
254
|
-
// ToDo: move it to separate validator:
|
|
255
|
-
if (parsed.method === undefined) {
|
|
256
|
-
const err = new TypeError(`"route" should start with one of the following methods: [GET, POST, PUT, DELETE, QUERY, HEADER, OPTIONS]`);
|
|
257
|
-
throw err;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const wrapped = async (req, res, next) => {
|
|
261
|
-
const matched = await markerFn.call(self, req, res);
|
|
262
|
-
// Skip, if marker's condition was not matched:
|
|
263
|
-
if (!matched) {
|
|
264
|
-
return next();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// Wrap and call:
|
|
268
|
-
const routeHandler = wrapRouteHandler.call(self, parsed, fn);
|
|
269
|
-
await routeHandler.call(self, req, res, next);
|
|
270
|
-
|
|
271
|
-
// If response was not sent,
|
|
272
|
-
// go to next one:
|
|
273
|
-
if (res.headersSent === false) {
|
|
274
|
-
next();
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
return self.add.route(wrapped);
|
|
278
|
-
},
|
|
279
|
-
use: (fn) => {
|
|
280
|
-
const wrapped = async (req, res, next) => {
|
|
281
|
-
const matched = await markerFn.call(self, req, res);
|
|
282
|
-
// Skip, if marker's condition was not matched:
|
|
283
|
-
if (!matched) {
|
|
284
|
-
return next();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
await fn.call(self, req, res, next);
|
|
288
|
-
|
|
289
|
-
// If response was not sent,
|
|
290
|
-
// go to next one:
|
|
291
|
-
if (res.headersSent === false) {
|
|
292
|
-
next();
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
return self.use(wrapped);
|
|
296
|
-
}
|
|
316
|
+
route: (route, fn) => MarkerMethods.onlyRoute.call(self, route, fn, markerFn),
|
|
317
|
+
use: (fnOrRouter) => MarkerMethods.onlyUse.call(self, fnOrRouter, markerFn),
|
|
297
318
|
}
|
|
298
319
|
}
|
|
299
320
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const Route = require('./route');
|
|
2
|
+
// Utils.
|
|
3
|
+
const {
|
|
4
|
+
validateParsedRouteMethood,
|
|
5
|
+
wrapRouteHandler
|
|
6
|
+
} = require('./routes.util');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
onlyRoute: _onlyRoute,
|
|
11
|
+
onlyUse: _onlyUse
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
*
|
|
16
|
+
* @param {String} route
|
|
17
|
+
* @param {Function} fn
|
|
18
|
+
* @param {Function} markerFn
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
function _onlyRoute(route, fn, markerFn) {
|
|
22
|
+
const parsedRoute = new Route(route);
|
|
23
|
+
// Will throw exception if not valid.
|
|
24
|
+
validateParsedRouteMethood(parsedRoute);
|
|
25
|
+
|
|
26
|
+
const wrapped = async (req, res, next) => {
|
|
27
|
+
const matched = await markerFn.call(this, req, res);
|
|
28
|
+
// Skip, if marker's condition was not matched:
|
|
29
|
+
if (!matched) {
|
|
30
|
+
return next();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Wrap and call:
|
|
34
|
+
const routeHandler = wrapRouteHandler.call(this, parsedRoute, fn);
|
|
35
|
+
await routeHandler.call(this, req, res, next);
|
|
36
|
+
|
|
37
|
+
// If response was not sent,
|
|
38
|
+
// go to the next one:
|
|
39
|
+
if (res.headersSent === false) {
|
|
40
|
+
next();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return this.add.route(route, wrapped);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
*
|
|
49
|
+
* @param {Function} fnOrRouter
|
|
50
|
+
* @param {Function} markerFn
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
function _onlyUse(fnOrRouter, markerFn) {
|
|
54
|
+
|
|
55
|
+
const wrapped = async (req, res, next) => {
|
|
56
|
+
const matched = await markerFn.call(this, req, res);
|
|
57
|
+
|
|
58
|
+
// Skip, if marker's condition was not matched:
|
|
59
|
+
if (!matched) {
|
|
60
|
+
return next();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const isRouter = fnOrRouter.constructor.name === 'NodesterRouter';
|
|
64
|
+
|
|
65
|
+
const fn = isRouter ? fnOrRouter.handle.bind(fnOrRouter) : fnOrRouter;
|
|
66
|
+
await fn.call(this, req, res, next);
|
|
67
|
+
|
|
68
|
+
// If regular handler function:
|
|
69
|
+
if (!isRouter) {
|
|
70
|
+
// If response was not sent,
|
|
71
|
+
// go to the next one:
|
|
72
|
+
if (res.headersSent === false) {
|
|
73
|
+
next();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return this.use(wrapped);
|
|
78
|
+
}
|
package/lib/router/route.js
CHANGED
|
@@ -40,17 +40,17 @@ module.exports = class NodesterRoute {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// Parse:
|
|
43
|
+
const collapsedSpaces = routeStringOrOpts.replace(/\s\s+/g, ' ');
|
|
43
44
|
const parts = routeStringOrOpts.split(' ');
|
|
44
|
-
const cleared = parts.filter(p => p.length > 0);
|
|
45
45
|
|
|
46
46
|
// Set method:
|
|
47
|
-
if (
|
|
48
|
-
const method =
|
|
47
|
+
if (parts[0].indexOf('/') === -1) {
|
|
48
|
+
const method = parts.shift().toUpperCase();
|
|
49
49
|
this.method = method;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Build route one again and set it:
|
|
53
|
-
const clearRoute =
|
|
53
|
+
const clearRoute = parts.join('');
|
|
54
54
|
this.route = clearRoute;
|
|
55
55
|
|
|
56
56
|
// Parse path parts:
|
|
@@ -11,10 +11,21 @@ const { parseRouteHandler } = require('./handlers.util');
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
module.exports = {
|
|
14
|
+
validateParsedRouteMethood: _validateParsedRouteMethood,
|
|
14
15
|
wrapRouteHandler: _wrapRouteHandler
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
|
|
19
|
+
function _validateParsedRouteMethood(parsedRoute) {
|
|
20
|
+
if (!parsedRoute || parsedRoute?.method === undefined) {
|
|
21
|
+
const err = new TypeError(`"route" should start with one of the following methods: [GET, POST, PUT, DELETE, QUERY, HEADER, OPTIONS]`);
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
18
29
|
/**
|
|
19
30
|
* Wraps route handler.
|
|
20
31
|
*
|
|
@@ -48,17 +59,36 @@ function _wrapRouteHandler(routeInstance, handler) {
|
|
|
48
59
|
else {
|
|
49
60
|
const parsedHandler = parseRouteHandler(handler);
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
let providedAction = null;
|
|
63
|
+
|
|
64
|
+
// If Controller:
|
|
65
|
+
if (parsedHandler.controllerName !== undefined) {
|
|
66
|
+
// Get method (action) from Controller:
|
|
67
|
+
const controller = this._controllers.get(parsedHandler.controllerName);
|
|
68
|
+
const controllerAction = controller[parsedHandler.actionName];
|
|
54
69
|
|
|
55
|
-
|
|
70
|
+
providedAction = controllerAction;
|
|
71
|
+
}
|
|
72
|
+
// If Controller\
|
|
73
|
+
|
|
74
|
+
// If Provider:
|
|
75
|
+
else {
|
|
76
|
+
// Get method (action) from Provider:
|
|
77
|
+
const provider = this._providers.get(parsedHandler.providerName);
|
|
78
|
+
const providerAction = provider[parsedHandler.actionName];
|
|
79
|
+
|
|
80
|
+
providedAction = providerAction;
|
|
81
|
+
}
|
|
82
|
+
// If Provider\
|
|
83
|
+
|
|
84
|
+
// If User set any handler before,
|
|
85
|
+
// call it first:
|
|
56
86
|
if (typeOf(parsedHandler.before) === 'function') {
|
|
57
87
|
// Expose nquery first.
|
|
58
88
|
await parsedHandler.before(req.nquery, req, res);
|
|
59
89
|
}
|
|
60
90
|
|
|
61
|
-
await
|
|
91
|
+
await providedAction(req, res);
|
|
62
92
|
}
|
|
63
93
|
};
|
|
64
94
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
parseProviderFileNames: _parseProviderFileNames
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function _parseProviderFileNames(fileNames, availableFileExtensions, term='controller') {
|
|
7
|
+
const resultNames = [];
|
|
8
|
+
|
|
9
|
+
for (const fileName of fileNames) {
|
|
10
|
+
|
|
11
|
+
const nameParts = fileName.split('.');
|
|
12
|
+
const extension = nameParts.pop();
|
|
13
|
+
if (availableFileExtensions.indexOf(extension) === -1) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// If the name format is <model>.<term>,
|
|
18
|
+
// but second part is not "term":
|
|
19
|
+
if (nameParts.length > 1 && nameParts[1] !== term)
|
|
20
|
+
continue;
|
|
21
|
+
|
|
22
|
+
const result = {
|
|
23
|
+
fileName: fileName,
|
|
24
|
+
[`${ term }Name`]: nameParts[0]
|
|
25
|
+
}
|
|
26
|
+
resultNames.push(result);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return resultNames;
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,21 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodester",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A boilerplate framework for Node.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/application/index.js",
|
|
7
|
+
|
|
8
|
+
"./constants/ErrorCodes": "./lib/constants/ErrorCodes.js",
|
|
9
|
+
|
|
10
|
+
"./controllers/methods": "./lib/controllers/methods/index.js",
|
|
7
11
|
"./controllers/mixins": "./lib/controllers/mixins/index.js",
|
|
8
|
-
|
|
12
|
+
|
|
13
|
+
"./database/connection": "./lib/database/connection.js",
|
|
14
|
+
"./database/migration": "./lib/database/migration.js",
|
|
15
|
+
"./database/utils": "./lib/database/utils.js",
|
|
16
|
+
|
|
9
17
|
"./enum": "./lib/enums/Enum.js",
|
|
18
|
+
|
|
19
|
+
"./facades/methods": "./lib/facades/methods/index.js",
|
|
20
|
+
"./facades/mixins": "./lib/facades/mixins/index.js",
|
|
21
|
+
|
|
10
22
|
"./factories/errors": "./lib/factories/errors/index.js",
|
|
11
23
|
"./factories/responses/rest": "./lib/factories/responses/rest/index.js",
|
|
24
|
+
|
|
12
25
|
"./http/codes": "./lib/http/codes/index.js",
|
|
26
|
+
"./loggers/console": "./lib/loggers/console.js",
|
|
27
|
+
"./loggers/dev": "./lib/loggers/dev.js",
|
|
28
|
+
|
|
29
|
+
"./middlewares/formidable": "./lib/middlewares/formidable/index.js",
|
|
30
|
+
|
|
13
31
|
"./models/associate": "./lib/models/associate.js",
|
|
14
32
|
"./models/define": "./lib/models/define.js",
|
|
33
|
+
|
|
15
34
|
"./params": "./lib/params/Params.js",
|
|
35
|
+
|
|
16
36
|
"./ql/sequelize": "./lib/middlewares/ql/sequelize",
|
|
37
|
+
"./queries/Colander": "./lib/queries/Colander.js",
|
|
38
|
+
"./queries/traverse": "./lib/queries/traverse.js",
|
|
39
|
+
|
|
17
40
|
"./route": "./lib/router/route.js",
|
|
18
|
-
"./router": "./lib/router/index.js"
|
|
41
|
+
"./router": "./lib/router/index.js",
|
|
42
|
+
|
|
43
|
+
"./utils/sql": "./lib/utils/sql.util.js",
|
|
44
|
+
"./utils/strings": "./lib/utils/strings.util.js"
|
|
19
45
|
},
|
|
20
46
|
"directories": {
|
|
21
47
|
"doc": "docs"
|
|
@@ -24,9 +50,8 @@
|
|
|
24
50
|
"lib"
|
|
25
51
|
],
|
|
26
52
|
"scripts": {
|
|
27
|
-
"
|
|
28
|
-
"examples:
|
|
29
|
-
"test": "jest"
|
|
53
|
+
"test": "jest",
|
|
54
|
+
"examples:rest": "node ./examples/rest/index.js"
|
|
30
55
|
},
|
|
31
56
|
"author": "Mark Khramko <markkhramko@gmail.com>",
|
|
32
57
|
"license": "MIT",
|
|
@@ -50,6 +75,7 @@
|
|
|
50
75
|
"dependencies": {
|
|
51
76
|
"@js-temporal/polyfill": "^0.4.3",
|
|
52
77
|
"accepts": "^1.3.8",
|
|
78
|
+
"body-parser": "^1.20.2",
|
|
53
79
|
"common-js-file-extensions": "^1.0.4",
|
|
54
80
|
"content-disposition": "^0.5.4",
|
|
55
81
|
"content-type": "^1.0.5",
|
|
@@ -58,10 +84,13 @@
|
|
|
58
84
|
"debug": "^4.3.4",
|
|
59
85
|
"etag": "^1.8.1",
|
|
60
86
|
"finalhandler": "^1.2.0",
|
|
61
|
-
"formidable": "^
|
|
87
|
+
"formidable": "^3.5.1",
|
|
62
88
|
"fresh": "^0.5.2",
|
|
63
89
|
"http-errors": "^2.0.0",
|
|
64
90
|
"inflection": "^2.0.1",
|
|
91
|
+
"mysql2": "^3.6.0",
|
|
92
|
+
"pg": "^8.11.3",
|
|
93
|
+
"pg-hstore": "^2.3.4",
|
|
65
94
|
"proxy-addr": "^2.0.7",
|
|
66
95
|
"qs": "^6.11.0",
|
|
67
96
|
"range-parser": "^1.2.1",
|
package/tests/nql.test.js
CHANGED
|
@@ -73,7 +73,7 @@ describe('nodester Query Language', () => {
|
|
|
73
73
|
tree.node.limit = 3;
|
|
74
74
|
tree.node.skip = 10;
|
|
75
75
|
tree.node.order = 'desc';
|
|
76
|
-
tree.node.
|
|
76
|
+
tree.node.order_by = 'index';
|
|
77
77
|
const expected = tree.root.toObject();
|
|
78
78
|
|
|
79
79
|
expect(result).toMatchObject(expected);
|
|
@@ -103,7 +103,7 @@ describe('nodester Query Language', () => {
|
|
|
103
103
|
tree.node.limit = 3;
|
|
104
104
|
tree.node.skip = 10;
|
|
105
105
|
tree.node.order = 'desc';
|
|
106
|
-
tree.node.
|
|
106
|
+
tree.node.order_by = 'index';
|
|
107
107
|
const expected = tree.root.toObject();
|
|
108
108
|
|
|
109
109
|
expect(result).toMatchObject(expected);
|
|
@@ -157,7 +157,7 @@ describe('nodester Query Language', () => {
|
|
|
157
157
|
tree.include('users');
|
|
158
158
|
tree.include('likes') && tree.use('likes');
|
|
159
159
|
tree.node.order = 'rand';
|
|
160
|
-
tree.node.
|
|
160
|
+
tree.node.order_by = 'position';
|
|
161
161
|
tree.up();
|
|
162
162
|
const expected = tree.root.toObject();
|
|
163
163
|
|