nodester 0.1.0 → 0.1.5
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 +3 -2
- package/lib/application/index.js +1 -1
- package/lib/body/extract.js +78 -0
- package/lib/constants/ErrorCodes.js +19 -0
- package/lib/constants/Operations.js +1 -1
- package/lib/controllers/mixins/index.js +59 -20
- package/lib/facades/methods/index.js +16 -10
- 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/{queries/Colander.js → filters/Filter.js} +37 -12
- package/lib/http/codes/descriptions.js +82 -0
- package/lib/http/codes/index.js +70 -145
- package/lib/http/codes/symbols.js +82 -0
- package/lib/loggers/dev.js +28 -0
- package/lib/middlewares/ql/sequelize/index.js +2 -2
- package/lib/middlewares/ql/sequelize/interpreter/ModelsTree.js +24 -1
- package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +67 -15
- package/lib/models/define.js +7 -4
- package/lib/models/mixins.js +1 -1
- package/lib/{queries → query}/traverse.js +108 -30
- package/lib/router/index.js +3 -3
- package/lib/router/routes.util.js +5 -1
- package/lib/stacks/MarkersStack.js +1 -1
- package/lib/stacks/MiddlewareStack.js +1 -1
- package/lib/utils/models.js +14 -0
- package/package.json +28 -4
- package/lib/preprocessors/BodyPreprocessor.js +0 -61
- package/lib/preprocessors/IncludesPreprocessor.js +0 -55
- package/lib/preprocessors/QueryPreprocessor.js +0 -64
- package/lib/queries/NodesterQueryParams.js +0 -139
- /package/lib/{logger → loggers}/console.js +0 -0
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// Dictionary of unsafe characters:
|
|
2
|
-
const NOT_ALLOWED = [
|
|
3
|
-
'{',
|
|
4
|
-
'}',
|
|
5
|
-
// `\`,
|
|
6
|
-
'^',
|
|
7
|
-
'~',
|
|
8
|
-
'[',
|
|
9
|
-
']',
|
|
10
|
-
'`'
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
const util = require('util');
|
|
14
|
-
|
|
15
|
-
/*
|
|
16
|
-
* NodesterQueryParams is a ready-to-use replacement for URLSearchParams.
|
|
17
|
-
* The only difference is that NodesterQueryParams
|
|
18
|
-
* respects nested "&" during parsing.
|
|
19
|
-
*/
|
|
20
|
-
module.exports = class NodesterQueryParams {
|
|
21
|
-
constructor(queryString='') {
|
|
22
|
-
// Type validateion:
|
|
23
|
-
if (typeof queryString !== 'string') {
|
|
24
|
-
const err = new TypeError(`'query' must be a String.`);
|
|
25
|
-
throw err;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// You never know if it's encoded or not.
|
|
29
|
-
const decoded = decodeURI(queryString);
|
|
30
|
-
|
|
31
|
-
// Indicates, how deep the char is inside different ().
|
|
32
|
-
let deep = 0;
|
|
33
|
-
|
|
34
|
-
const paramLevels = {};
|
|
35
|
-
|
|
36
|
-
// Current query parameter.
|
|
37
|
-
let param = '';
|
|
38
|
-
|
|
39
|
-
// Current query token.
|
|
40
|
-
let token = '';
|
|
41
|
-
|
|
42
|
-
this._map = new Map();
|
|
43
|
-
|
|
44
|
-
for (let i=0; i < decoded.length; i++) {
|
|
45
|
-
const char = decoded[i];
|
|
46
|
-
|
|
47
|
-
// Validate char:
|
|
48
|
-
if (NOT_ALLOWED.indexOf(char) > -1) {
|
|
49
|
-
const err = new TypeError(`Invalid query token at ${ i }: '${ char }'`);
|
|
50
|
-
throw err;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (char === '(') {
|
|
54
|
-
// Error If there is nothing behind:
|
|
55
|
-
if (param.length === 0) {
|
|
56
|
-
const err = new TypeError(`Invalid query token at ${ i }: '${ char }'`);
|
|
57
|
-
throw err;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// If not special token, go deeper:
|
|
61
|
-
if (['and', 'or', 'xor', 'not', '!', '|', 'like'].indexOf(token) === -1) {
|
|
62
|
-
this.append(param, token);
|
|
63
|
-
deep++;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// will set ( in token later.
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (char === ')') {
|
|
70
|
-
// If sub-level:
|
|
71
|
-
if (deep > 0) {
|
|
72
|
-
deep--
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// & can mean the end of key=value pair:
|
|
77
|
-
if (char === '&') {
|
|
78
|
-
// If top-level:
|
|
79
|
-
if (deep === 0) {
|
|
80
|
-
this.append(param, token);
|
|
81
|
-
param = '';
|
|
82
|
-
token = '';
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// If sub-level do nothing.
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// = can mean the end of param name:
|
|
90
|
-
if (char === '=') {
|
|
91
|
-
// If top-level:
|
|
92
|
-
if (deep === 0) {
|
|
93
|
-
param = token;
|
|
94
|
-
token = '';
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Continue building token:
|
|
99
|
-
if (char !== '=' || deep > 0 ) {
|
|
100
|
-
token += char;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// If last char:
|
|
104
|
-
if (i === decoded.length-1) {
|
|
105
|
-
// Validate:
|
|
106
|
-
if (deep > 0) {
|
|
107
|
-
const err = new TypeError(`Missing ')' at ${ i }`);
|
|
108
|
-
throw err;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
this.append(param, token);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
append(...args) {
|
|
117
|
-
return this._map.set(...args);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
get(...args) {
|
|
121
|
-
return this._map.get(...args);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
delete(...args) {
|
|
125
|
-
return this._map.delete(...args);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
entries(...args) {
|
|
129
|
-
return this._map.entries(...args);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
toString() {
|
|
133
|
-
return this._map.toString();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
[util.inspect.custom](depth, opts) {
|
|
137
|
-
return this._map;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
File without changes
|