nodester 0.2.2 → 0.2.3

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.
@@ -17,7 +17,7 @@ module.exports = function initNodesterQL() {
17
17
  return nqlHandle;
18
18
  };
19
19
 
20
- async function nqlHandle(req, res, next) {
20
+ function nqlHandle(req, res, next) {
21
21
  // Object, which will be populated with parsed query.
22
22
  req.nquery = {};
23
23
 
@@ -125,8 +125,12 @@ module.exports = class QueryLexer {
125
125
  // Structure of a value depends on OP:
126
126
  let fullOp = {};
127
127
  switch (tree.node.op) {
128
- case 'not':
129
- case 'like':
128
+ case OP_TOKENS.NOT:
129
+ case OP_TOKENS.LIKE:
130
+ case OP_TOKENS.GREATER:
131
+ case OP_TOKENS.GREATER_OR_EQUAL:
132
+ case OP_TOKENS.LOWER:
133
+ case OP_TOKENS.LOWER_OR_EQUAL:
130
134
  fullOp = { [tree.node.activeParam]: { [tree.node.op]: [token] } };
131
135
  break;
132
136
  default:
@@ -192,6 +196,7 @@ module.exports = class QueryLexer {
192
196
  }
193
197
 
194
198
  // , can mean n-th value in value array,
199
+ // or it can be n-th key-value pair in subquery,
195
200
  // or horizontal include:
196
201
  if (char === ',') {
197
202
  debug('char', char, { token, node: tree.node });
@@ -470,8 +475,7 @@ module.exports = class QueryLexer {
470
475
  treeNode.order_by = token;
471
476
  break;
472
477
  case 'fields':
473
- if (token)
474
- value.push(token);
478
+ if (token) value.push(token);
475
479
  treeNode.fields = value;
476
480
  break;
477
481
  case 'includes':
@@ -479,8 +483,7 @@ module.exports = class QueryLexer {
479
483
  treeNode.include(node);
480
484
  break;
481
485
  default:
482
- if (token)
483
- value.push(token);
486
+ if (token) value.push(token);
484
487
  treeNode.addWhere({ [param]: value });
485
488
  break;
486
489
  }
@@ -31,7 +31,9 @@ module.exports = class MiddlewaresStack {
31
31
 
32
32
  // Indicates whether we can add more middlewares or no.
33
33
  this._isLocked = false;
34
- this.finalhandlerEnabled = !!opts.finalhandlerEnabled;
34
+
35
+ // TODO: disable/enable it in the process().
36
+ this._finalhandlerEnabled = !!opts.finalhandlerEnabled;
35
37
 
36
38
 
37
39
  const env = process.env.NODE_ENV || 'development';
@@ -139,7 +141,7 @@ module.exports = class MiddlewaresStack {
139
141
  * @api public
140
142
  */
141
143
  lock() {
142
- if (this.finalhandlerEnabled) {
144
+ if (this._finalhandlerEnabled) {
143
145
  // Add final handler to the stack.
144
146
  this.add((req, res)=>this.finalhandler(req, res)());
145
147
  }
@@ -159,7 +161,7 @@ module.exports = class MiddlewaresStack {
159
161
  unlock() {
160
162
  this._isLocked = false;
161
163
 
162
- if (this.finalhandlerEnabled) {
164
+ if (this._finalhandlerEnabled) {
163
165
  this._middlewares.pop();
164
166
  }
165
167
 
@@ -185,7 +187,15 @@ module.exports = class MiddlewaresStack {
185
187
  return next.call(null, req, res, next, ...args);
186
188
  }
187
189
  else if (!!fn) {
188
- return await fn.call(null, req, res, _next, ...args);
190
+ // Check for a middleware (fn) type (async or sync):
191
+ // 👇 Why it's important
192
+ // https://stackoverflow.com/questions/60330963/why-an-async-function-takes-more-time-to-execute-than-a-sync-one
193
+ if (fn.constructor.name === 'AsyncFunction') {
194
+ return await fn.call(null, req, res, _next, ...args);
195
+ }
196
+ else {
197
+ return fn.call(null, req, res, _next, ...args);
198
+ }
189
199
  }
190
200
  }
191
201
  catch(error) {
@@ -22,10 +22,10 @@ function _toAST_ModelsTreeNode(node, spacing=0) {
22
22
 
23
23
  ast += `${ spaces }model: ${ node.model }\n\n`;
24
24
 
25
- ast += `${ spaces }fields: [\n${ node.fields.map(f => ` • ${ f },\n`) }`;
25
+ ast += `${ spaces }fields (${ node.fields.length }): [\n${ node.fields.map(f => ` • ${ f },\n`) }`;
26
26
  ast += `${ spaces }]\n\n`;
27
27
 
28
- ast += `${ spaces }functions: [\n${ node.functions.map(f => ` • ${ f },\n`) }`;
28
+ ast += `${ spaces }functions (${ node.functions.length }): [\n${ node.functions.map(f => ` • ${ f },\n`) }`;
29
29
  ast += `${ spaces }]\n\n`;
30
30
 
31
31
  ast += `${ spaces }where: ${ JSON.stringify(node.where) }\n\n`;
@@ -34,7 +34,7 @@ function _toAST_ModelsTreeNode(node, spacing=0) {
34
34
  c => ast += `${ spaces }${ c }: ${ node[c] }\n\n`
35
35
  );
36
36
 
37
- ast += `${ spaces }includes: [\n`
37
+ ast += `${ spaces }includes (${ node.includes.length }): [\n`
38
38
  node.includes.map(n => ast += _toAST_ModelsTreeNode(n, spacing + 2));
39
39
  ast += `${ spaces }]\n`;
40
40
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodester",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "A versatile REST framework for Node.js",
5
5
  "exports": {
6
6
  ".": "./lib/application/index.js",