nodester 0.4.7 → 0.4.9
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/lib/middlewares/ql/sequelize/index.js +0 -8
- package/lib/query/traverse/index.js +1 -1
- package/lib/structures/Filter.js +17 -3
- package/package.json +1 -1
- package/lib/constants/Operators.js +0 -23
- package/lib/middlewares/404/index.js +0 -38
- package/lib/middlewares/etag/index.js +0 -81
- package/lib/middlewares/render/index.js +0 -62
- package/lib/utils/queries.util.js +0 -240
- package/tests/ast.js +0 -18
|
@@ -13,10 +13,6 @@ const { decodeQueryString } = require('./decoder');
|
|
|
13
13
|
const QueryLexer = require('./interpreter/QueryLexer');
|
|
14
14
|
const { createErrorResponse } = require('nodester/factories/responses/rest');
|
|
15
15
|
|
|
16
|
-
const {
|
|
17
|
-
AST_ModelsTree
|
|
18
|
-
} = require('nodester/tools/nql');
|
|
19
|
-
|
|
20
16
|
|
|
21
17
|
module.exports = function initNodesterQL() {
|
|
22
18
|
return nqlHandle;
|
|
@@ -42,10 +38,6 @@ function nqlHandle(req, res, next) {
|
|
|
42
38
|
const decoded = decodeQueryString(queryString);
|
|
43
39
|
const lexer = new QueryLexer(decoded);
|
|
44
40
|
|
|
45
|
-
console.log(
|
|
46
|
-
AST_ModelsTree(lexer.tree)
|
|
47
|
-
);
|
|
48
|
-
|
|
49
41
|
// Go on!
|
|
50
42
|
req.nquery = lexer.query;
|
|
51
43
|
return next();
|
|
@@ -345,7 +345,7 @@ function traverse(queryNode, filter=null, model=null, association=null) {
|
|
|
345
345
|
|
|
346
346
|
// Combine included orders into one at the top level:
|
|
347
347
|
// - Why?
|
|
348
|
-
// - Sequelize
|
|
348
|
+
// - Sequelize ignores included orders for association types like:
|
|
349
349
|
// • HasMany
|
|
350
350
|
_traverseIncludedOrders(newQuery, _model);
|
|
351
351
|
|
package/lib/structures/Filter.js
CHANGED
|
@@ -91,6 +91,7 @@ module.exports = class NodesterFilter {
|
|
|
91
91
|
const { associations } = this.model;
|
|
92
92
|
for (const [ includeName, includeFilter ] of Object.entries(includes)) {
|
|
93
93
|
const association = associations[includeName];
|
|
94
|
+
|
|
94
95
|
// Validate association by name:
|
|
95
96
|
if (association === undefined) {
|
|
96
97
|
const error = new TypeError(`No include named '${ includeName }'.`);
|
|
@@ -98,10 +99,23 @@ module.exports = class NodesterFilter {
|
|
|
98
99
|
throw error;
|
|
99
100
|
}
|
|
100
101
|
|
|
102
|
+
const { associationType } = association;
|
|
103
|
+
|
|
101
104
|
// If singular association:
|
|
102
|
-
// Fix of "Only HasMany associations support include.separate"
|
|
103
|
-
if ('HasMany' !==
|
|
104
|
-
// Empty bounds
|
|
105
|
+
// (Fix of sequilize error "Only HasMany associations support include.separate")
|
|
106
|
+
if ('HasMany' !== associationType) {
|
|
107
|
+
// Empty bounds:
|
|
108
|
+
if (!!includeFilter.statics.clauses.limit) {
|
|
109
|
+
const msg = [
|
|
110
|
+
`(nodester) warning: include "${ includeName }" has`,
|
|
111
|
+
`association type of "${ associationType }", but has a filter clause "limit",`,
|
|
112
|
+
`which is forbidden on any association type except for "HasMany".`,
|
|
113
|
+
`It was automatically removed from clauses.`
|
|
114
|
+
].join(' ');
|
|
115
|
+
console.warn(msg);
|
|
116
|
+
}
|
|
117
|
+
delete includeFilter.statics.clauses.limit;
|
|
118
|
+
|
|
105
119
|
includeFilter.noBounds = true;
|
|
106
120
|
}
|
|
107
121
|
|
package/package.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const Enum = require('nodester/enum');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
module.exports = new Enum({
|
|
5
|
-
and: Symbol.for('and'),
|
|
6
|
-
between: Symbol.for('between'),
|
|
7
|
-
contains: Symbol.for('contains'),
|
|
8
|
-
eq: Symbol.for('eq'),
|
|
9
|
-
ne: Symbol.for('ne'),
|
|
10
|
-
gte: Symbol.for('gte'),
|
|
11
|
-
gt: Symbol.for('gt'),
|
|
12
|
-
lte: Symbol.for('lte'),
|
|
13
|
-
lt: Symbol.for('lt'),
|
|
14
|
-
not: Symbol.for('not'),
|
|
15
|
-
is: Symbol.for('is'),
|
|
16
|
-
in: Symbol.for('in'),
|
|
17
|
-
notIn: Symbol.for('notIn'),
|
|
18
|
-
like: Symbol.for('like'),
|
|
19
|
-
notLike: Symbol.for('notLike'),
|
|
20
|
-
notBetween: Symbol.for('notBetween'),
|
|
21
|
-
or: Symbol.for('or'),
|
|
22
|
-
xor: Symbol.for('xor'),
|
|
23
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* nodester
|
|
3
|
-
* MIT Licensed
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
HTTP_CODE_NOT_FOUND
|
|
10
|
-
} = require('nodester/http/codes');
|
|
11
|
-
|
|
12
|
-
const { createErrorResponse } = require('nodester/factories/responses/rest');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Initialize `404` middleware.
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} [options]
|
|
19
|
-
*
|
|
20
|
-
* @return {Function}
|
|
21
|
-
*
|
|
22
|
-
* @access public
|
|
23
|
-
*/
|
|
24
|
-
module.exports = function init404Middleware(options={}) {
|
|
25
|
-
const context = {
|
|
26
|
-
options
|
|
27
|
-
}
|
|
28
|
-
return handle.bind(context);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function handle(req, res, next) {
|
|
32
|
-
const err = new Error('Route not found');
|
|
33
|
-
|
|
34
|
-
return createErrorResponse(res, {
|
|
35
|
-
error: err,
|
|
36
|
-
status: HTTP_CODE_NOT_FOUND
|
|
37
|
-
});
|
|
38
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* nodester
|
|
3
|
-
* MIT Licensed
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
const calculate = require('etag');
|
|
9
|
-
const Stream = require('stream');
|
|
10
|
-
|
|
11
|
-
// Utils:
|
|
12
|
-
const promisify = require('util').promisify;
|
|
13
|
-
const fs = require('fs');
|
|
14
|
-
const getFileStats = promisify(fs.stat);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
module.exports = initETagMiddleware;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Initialize `etag` middleware.
|
|
21
|
-
*
|
|
22
|
-
* @param {Object} [options]
|
|
23
|
-
* @param {boolean} options.weak
|
|
24
|
-
*
|
|
25
|
-
* @return {Function}
|
|
26
|
-
*
|
|
27
|
-
* @access public
|
|
28
|
-
*/
|
|
29
|
-
function initETagMiddleware(options) {
|
|
30
|
-
const context = {
|
|
31
|
-
options
|
|
32
|
-
}
|
|
33
|
-
return handle.bind(context);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Add ETag header field.
|
|
38
|
-
*/
|
|
39
|
-
function handle(req, res, next) {
|
|
40
|
-
// console.log('e', req.headers);
|
|
41
|
-
return next();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function _getResponseEntity(res) {
|
|
45
|
-
// If body is not defined:
|
|
46
|
-
const { body } = res;
|
|
47
|
-
if (!body || res.get('etag'))
|
|
48
|
-
return;
|
|
49
|
-
|
|
50
|
-
// Status code.
|
|
51
|
-
const status = res.statusCode / 100 | 0;
|
|
52
|
-
|
|
53
|
-
console.log('getResponseEntity', status, { tag: res.get('etag') });
|
|
54
|
-
|
|
55
|
-
// 2xx
|
|
56
|
-
if (status !== 2)
|
|
57
|
-
return;
|
|
58
|
-
|
|
59
|
-
if (body instanceof Stream) {
|
|
60
|
-
if (!body.path)
|
|
61
|
-
return;
|
|
62
|
-
|
|
63
|
-
const stats = await getFileStats(body.path);
|
|
64
|
-
return stats;
|
|
65
|
-
}
|
|
66
|
-
else if (typeof body === 'string' || Buffer.isBuffer(body)) {
|
|
67
|
-
return body;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return JSON.stringify(body);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function _setEtag(res, entity, options) {
|
|
75
|
-
console.log('setEtag', typeof res, entity);
|
|
76
|
-
|
|
77
|
-
if (!entity)
|
|
78
|
-
return;
|
|
79
|
-
|
|
80
|
-
res.etag = calculate(entity, options);
|
|
81
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* nodester
|
|
3
|
-
* MIT Licensed
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
module.exports = function initRenderMiddleware() {
|
|
10
|
-
return handle;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function handle(req, res, next) {
|
|
15
|
-
const context = { req, res, next };
|
|
16
|
-
res.render = _render.bind(context);
|
|
17
|
-
next();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Render `view` with the given `options` and optional callback `fn`.
|
|
23
|
-
* When a callback function is given a response will _not_ be made
|
|
24
|
-
* automatically, otherwise a response of _200_ and _text/html_ is given.
|
|
25
|
-
*
|
|
26
|
-
* Options:
|
|
27
|
-
*
|
|
28
|
-
* - `cache` boolean hinting to the engine it should cache
|
|
29
|
-
* - `filename` filename of the view being rendered
|
|
30
|
-
*
|
|
31
|
-
* @alias render
|
|
32
|
-
* @access public
|
|
33
|
-
*/
|
|
34
|
-
function _render(view, options, callback) {
|
|
35
|
-
const app = this.req.app;
|
|
36
|
-
let done = callback;
|
|
37
|
-
let opts = options || {};
|
|
38
|
-
|
|
39
|
-
const req = this.req;
|
|
40
|
-
const res = this.res;
|
|
41
|
-
const next = this.next;
|
|
42
|
-
|
|
43
|
-
// support callback function as second arg
|
|
44
|
-
if (typeof options === 'function') {
|
|
45
|
-
done = options;
|
|
46
|
-
opts = {};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// merge res.locals
|
|
50
|
-
opts._locals = res.locals;
|
|
51
|
-
|
|
52
|
-
// default callback to respond
|
|
53
|
-
done = done || function (err, str) {
|
|
54
|
-
if (err)
|
|
55
|
-
return next(err);
|
|
56
|
-
|
|
57
|
-
res.send(str);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// render
|
|
61
|
-
app.render(view, opts, done);
|
|
62
|
-
};
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
// Constants.
|
|
2
|
-
const SubIncludesQueryRegex = /\([^)]*\)/g;
|
|
3
|
-
|
|
4
|
-
// Sequelize.
|
|
5
|
-
const Op = require('sequelize').Op;
|
|
6
|
-
|
|
7
|
-
// Utils.
|
|
8
|
-
const {
|
|
9
|
-
splitByDot,
|
|
10
|
-
splitByAmpersand
|
|
11
|
-
} = require('nodester/utils/strings.util');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
parseQueryParams: _parseQueryParams,
|
|
16
|
-
deleteQuerySortParams: _deleteQuerySortParams,
|
|
17
|
-
|
|
18
|
-
// SubIncludes Query:
|
|
19
|
-
hasSubIncludesQuery: _hasSubIncludesQuery,
|
|
20
|
-
cutSubIncludesQuery: _cutSubIncludesQuery,
|
|
21
|
-
parseSubIncludesQuery: _parseSubIncludesQuery
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function _parseQueryParams(
|
|
25
|
-
requestQueryObject={},
|
|
26
|
-
sequilizeQuery=null
|
|
27
|
-
) {
|
|
28
|
-
const skip = parseInt(requestQueryObject?.skip ?? 0);
|
|
29
|
-
const limit = parseInt(requestQueryObject?.limit ?? 50);
|
|
30
|
-
|
|
31
|
-
sequilizeQuery.offset = skip;
|
|
32
|
-
sequilizeQuery.limit = limit;
|
|
33
|
-
|
|
34
|
-
const order = requestQueryObject?.order;
|
|
35
|
-
|
|
36
|
-
// If order is set:
|
|
37
|
-
if (!!order) {
|
|
38
|
-
const orderBy = requestQueryObject?.order_by ?? 'id';
|
|
39
|
-
|
|
40
|
-
sequilizeQuery.order = [
|
|
41
|
-
[ orderBy, order ]
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Clear sort params.
|
|
46
|
-
_deleteQuerySortParams(requestQueryObject);
|
|
47
|
-
|
|
48
|
-
// Get include names.
|
|
49
|
-
const _includes = sequilizeQuery?.include?.map( include => include.association ) ?? [];
|
|
50
|
-
|
|
51
|
-
// Count query keys.
|
|
52
|
-
const keysCount = Object.keys(requestQueryObject).length;
|
|
53
|
-
|
|
54
|
-
// If query has no keys,
|
|
55
|
-
// stop further execution:
|
|
56
|
-
if (keysCount === 0) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// This container is a reference to current "where".
|
|
61
|
-
let container = null;
|
|
62
|
-
let isContainerArray = false;
|
|
63
|
-
|
|
64
|
-
// If query has only 1 key:
|
|
65
|
-
if (keysCount === 1) {
|
|
66
|
-
// Define empty query's where.
|
|
67
|
-
sequilizeQuery.where = {};
|
|
68
|
-
container = sequilizeQuery.where;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
// Define conjuction of params in query's where.
|
|
72
|
-
sequilizeQuery.where = {
|
|
73
|
-
[Op.and]: []
|
|
74
|
-
};
|
|
75
|
-
container = sequilizeQuery.where[Op.and];
|
|
76
|
-
isContainerArray = true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Go through query's keys:
|
|
80
|
-
Object.keys(requestQueryObject)
|
|
81
|
-
.forEach((queryKey) => {
|
|
82
|
-
|
|
83
|
-
// Parse value of this key:
|
|
84
|
-
const value = requestQueryObject[queryKey];
|
|
85
|
-
// If value is not a number, parse it further.
|
|
86
|
-
const parsedValue = isNaN( value ) ? _parseHTTPQueryValue( `${ requestQueryObject[queryKey] }` ) : value;
|
|
87
|
-
|
|
88
|
-
// If we got nested key:
|
|
89
|
-
if (queryKey.indexOf('.') !== -1) {
|
|
90
|
-
|
|
91
|
-
// If this key is included as association:
|
|
92
|
-
const associationIndex = _includes.indexOf(queryKey.split('.')[0]);
|
|
93
|
-
if (associationIndex > -1) {
|
|
94
|
-
sequilizeQuery.include[associationIndex].where = { [`$${queryKey}$`]: parsedValue };
|
|
95
|
-
}
|
|
96
|
-
// Use special sequelize syntax for nested SELECT:
|
|
97
|
-
else if (isContainerArray) {
|
|
98
|
-
const selectObject = { [`$${queryKey}$`]: parsedValue };
|
|
99
|
-
container.push(selectObject);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
container[`$${queryKey}$`] = parsedValue;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// On regular key, set regular key-value pair:
|
|
106
|
-
else {
|
|
107
|
-
if (isContainerArray) {
|
|
108
|
-
const selectObject = { [queryKey]: parsedValue };
|
|
109
|
-
container.push(selectObject);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
container[queryKey] = parsedValue;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function _parseHTTPQueryValue(
|
|
119
|
-
value='',
|
|
120
|
-
isNumber=false
|
|
121
|
-
) {
|
|
122
|
-
// If value matches "and()":
|
|
123
|
-
if (value.slice(0, 4) === 'and(') {
|
|
124
|
-
// Remove "and()".
|
|
125
|
-
const clearValuesString = value.substr(4, value.length - 'and()'.length);
|
|
126
|
-
|
|
127
|
-
const clearValues = clearValuesString.split(',');
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
[Op.and]: clearValues.map(cv => _parseHTTPQueryValue(cv))
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// If value matches "like(value)":
|
|
134
|
-
else if (value.slice(0, 5) === 'like(') {
|
|
135
|
-
// Remove "like()".
|
|
136
|
-
const clearValue = value.substr(5, value.length - 'like()'.length);
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
[Op.like]: `%${ _parseHTTPQueryValue(clearValue) }%`
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// If value matches "notLike(value)":
|
|
143
|
-
else if (value.slice(0, 8) === 'notLike(') {
|
|
144
|
-
// Remove "notLike()".
|
|
145
|
-
const clearValue = value.substr(8, value.length - 'notLike()'.length);
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
[Op.notLike]: `%${ _parseHTTPQueryValue(clearValue) }%`
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// If value matches "not(value)":
|
|
152
|
-
else if (value.slice(0, 4) === 'not(') {
|
|
153
|
-
// Remove "not()".
|
|
154
|
-
const clearValue = value.substr(4, value.length - 'not()'.length);
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
[Op.not]: _parseHTTPQueryValue(clearValue)
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
// If value matches "or()":
|
|
161
|
-
else if (value.slice(0, 3) === 'or(') {
|
|
162
|
-
// Remove "or()".
|
|
163
|
-
const clearValuesString = value.substr(3, value.length - 'or()'.length);
|
|
164
|
-
|
|
165
|
-
const clearValues = clearValuesString.split(',');
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
[Op.or]: clearValues.map(cv => _parseHTTPQueryValue(cv))
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
// If value is a number:
|
|
172
|
-
// else if (!isNaN(value)) {
|
|
173
|
-
// const number = parseFloat(value);
|
|
174
|
-
// return number;
|
|
175
|
-
// }
|
|
176
|
-
// For default, just set this value in "where"
|
|
177
|
-
return value;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function _deleteQuerySortParams(requestQueryObject={}) {
|
|
181
|
-
delete requestQueryObject.skip;
|
|
182
|
-
delete requestQueryObject.limit;
|
|
183
|
-
delete requestQueryObject.order;
|
|
184
|
-
delete requestQueryObject.order_by;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// If string has nested query "()":
|
|
188
|
-
function _hasSubIncludesQuery(string='') {
|
|
189
|
-
return SubIncludesQueryRegex.test(string);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function _cutSubIncludesQuery(string='') {
|
|
193
|
-
const query = string.match(SubIncludesQueryRegex)[0];
|
|
194
|
-
const newString = string.replace(SubIncludesQueryRegex, '');
|
|
195
|
-
|
|
196
|
-
return [ query, newString ];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function _parseSubIncludesQuery(
|
|
200
|
-
associationName,
|
|
201
|
-
subIncludesQuery='',
|
|
202
|
-
sequilizeQuery=null
|
|
203
|
-
) {
|
|
204
|
-
const query = {};
|
|
205
|
-
|
|
206
|
-
// Magic trick to make everything work (DO NOT REMOVE).
|
|
207
|
-
sequilizeQuery.separate = true;
|
|
208
|
-
|
|
209
|
-
// If first "("" & ")" are set, cut them:
|
|
210
|
-
const subIncludesQueryRegex = /\([^)]*\)/g;
|
|
211
|
-
const clearQuery = subIncludesQueryRegex.test(subIncludesQuery) ?
|
|
212
|
-
subIncludesQuery.substr(1, subIncludesQuery.length - 2)
|
|
213
|
-
:
|
|
214
|
-
subIncludesQuery;
|
|
215
|
-
|
|
216
|
-
const keyValues = splitByAmpersand(clearQuery).map(kv => {
|
|
217
|
-
const keyValue = kv.split('=');
|
|
218
|
-
query[keyValue[0]] = keyValue[1];
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (!!query.skip) {
|
|
223
|
-
const skip = parseInt(query.skip ?? 0);
|
|
224
|
-
sequilizeQuery[`$${ associationName }.offset$`] = skip;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (!!query.limit) {
|
|
228
|
-
const limit = parseInt(query.limit ?? 50);
|
|
229
|
-
sequilizeQuery[`$${ associationName }.limit$`] = limit;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// If order is set:
|
|
233
|
-
if (!!query.order) {
|
|
234
|
-
const orderBy = query?.order_by ?? 'id';
|
|
235
|
-
|
|
236
|
-
sequilizeQuery.order = [
|
|
237
|
-
[ orderBy, query.order ]
|
|
238
|
-
];
|
|
239
|
-
}
|
|
240
|
-
}
|
package/tests/ast.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const { ModelsTree } = require('../lib/middlewares/ql/sequelize/interpreter/ModelsTree');
|
|
2
|
-
const { AST_ModelsTree } = require('../lib/tools/nql.tool');
|
|
3
|
-
|
|
4
|
-
const tree = new ModelsTree();
|
|
5
|
-
tree.node.addWhere({ id: ['1000'] });
|
|
6
|
-
tree.include('comments').use('comments');
|
|
7
|
-
tree.node.order = 'desc';
|
|
8
|
-
tree.up();
|
|
9
|
-
tree.include('users');
|
|
10
|
-
tree.include('likes') && tree.use('likes');
|
|
11
|
-
tree.node.order = 'rand';
|
|
12
|
-
tree.up();
|
|
13
|
-
tree.include('reposts');
|
|
14
|
-
|
|
15
|
-
console.debug(
|
|
16
|
-
AST_ModelsTree(tree)
|
|
17
|
-
);
|
|
18
|
-
|