nodester 0.1.5 → 0.2.1
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 +25 -61
- package/lib/application/index.js +185 -63
- package/lib/body/extract.js +15 -4
- package/lib/constants/Bounds.js +15 -0
- package/lib/constants/Clauses.js +13 -0
- package/lib/constants/ResponseFormats.js +2 -2
- package/lib/controllers/methods/index.js +7 -0
- package/lib/controllers/mixins/index.js +36 -36
- package/lib/database/connection.js +6 -0
- package/lib/database/migration.js +14 -4
- package/lib/facades/methods/index.js +10 -9
- package/lib/facades/mixins/index.js +67 -13
- package/lib/factories/responses/rest.js +25 -13
- package/lib/http/{request.js → request/index.js} +53 -75
- package/lib/http/request/utils.js +27 -0
- package/lib/http/response/headers.js +138 -0
- package/lib/http/response/index.js +248 -0
- package/lib/http/response/utils.js +38 -0
- package/lib/middlewares/SearchParams/index.js +25 -0
- package/lib/middlewares/cookies/index.js +44 -0
- package/lib/middlewares/etag/index.js +32 -15
- package/lib/middlewares/formidable/index.js +30 -25
- package/lib/middlewares/ql/sequelize/index.js +11 -2
- package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +10 -2
- package/lib/middlewares/render/index.js +62 -0
- package/lib/models/associate.js +25 -1
- package/lib/models/define.js +19 -15
- package/lib/models/mixins.js +7 -0
- package/lib/query/traverse.js +97 -63
- package/lib/router/handlers.util.js +1 -0
- package/lib/router/index.js +193 -98
- package/lib/router/markers.js +7 -0
- package/lib/router/route.js +5 -0
- package/lib/router/routes.util.js +12 -14
- package/lib/router/utils.js +7 -0
- package/lib/stacks/MarkersStack.js +41 -3
- package/lib/stacks/MiddlewaresStack.js +200 -0
- package/lib/structures/Enum.js +46 -0
- package/lib/structures/Filter.js +157 -0
- package/lib/structures/Params.js +55 -0
- package/lib/tools/sql.tool.js +7 -0
- package/lib/utils/objects.util.js +31 -24
- package/lib/utils/sanitizations.util.js +10 -4
- package/lib/validators/arguments.js +68 -0
- package/lib/validators/dates.js +7 -0
- package/lib/validators/numbers.js +7 -0
- package/package.json +11 -8
- package/tests/index.test.js +4 -4
- package/tests/nql.test.js +18 -1
- package/lib/database/utils.js +0 -19
- package/lib/enums/Enum.js +0 -16
- package/lib/filters/Filter.js +0 -109
- package/lib/http/response.js +0 -1074
- package/lib/http/utils.js +0 -254
- package/lib/params/Params.js +0 -37
- package/lib/policies/Role.js +0 -77
- package/lib/policies/RoleExtracting.js +0 -97
- package/lib/services/includes.service.js +0 -79
- package/lib/services/jwt.service.js +0 -147
- package/lib/stacks/MiddlewareStack.js +0 -159
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodester",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A boilerplate framework for Node.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/application/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"./database/migration": "./lib/database/migration.js",
|
|
17
17
|
"./database/utils": "./lib/database/utils.js",
|
|
18
18
|
|
|
19
|
-
"./enum": "./lib/
|
|
19
|
+
"./enum": "./lib/structures/Enum.js",
|
|
20
20
|
|
|
21
21
|
"./facades/methods": "./lib/facades/methods/index.js",
|
|
22
22
|
"./facades/mixins": "./lib/facades/mixins/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"./factories/errors": "./lib/factories/errors/index.js",
|
|
25
25
|
"./factories/responses/rest": "./lib/factories/responses/rest/index.js",
|
|
26
26
|
|
|
27
|
-
"./filter": "./lib/
|
|
27
|
+
"./filter": "./lib/structures/Filter.js",
|
|
28
28
|
|
|
29
29
|
"./http/codes": "./lib/http/codes/index.js",
|
|
30
30
|
"./http/codes/descriptions": "./lib/http/codes/descriptions.js",
|
|
@@ -33,19 +33,24 @@
|
|
|
33
33
|
"./loggers/console": "./lib/loggers/console.js",
|
|
34
34
|
"./loggers/dev": "./lib/loggers/dev.js",
|
|
35
35
|
|
|
36
|
+
"./middlewares/cookies": "./lib/middlewares/cookies/index.js",
|
|
36
37
|
"./middlewares/formidable": "./lib/middlewares/formidable/index.js",
|
|
38
|
+
"./middlewares/SearchParams": "./lib/middlewares/SearchParams/index.js",
|
|
37
39
|
|
|
38
40
|
"./models/associate": "./lib/models/associate.js",
|
|
39
41
|
"./models/define": "./lib/models/define.js",
|
|
40
42
|
|
|
41
|
-
"./params": "./lib/
|
|
43
|
+
"./params": "./lib/structures/Params.js",
|
|
42
44
|
|
|
43
|
-
"./ql/sequelize": "./lib/middlewares/ql/sequelize",
|
|
45
|
+
"./ql/sequelize": "./lib/middlewares/ql/sequelize/index.js",
|
|
44
46
|
"./query/traverse": "./lib/query/traverse.js",
|
|
45
47
|
|
|
46
48
|
"./route": "./lib/router/route.js",
|
|
47
49
|
"./router": "./lib/router/index.js",
|
|
48
50
|
|
|
51
|
+
"./stacks/markers": "./lib/stacks/MarkersStack.js",
|
|
52
|
+
"./stacks/middlewares": "./lib/stacks/MiddlewaresStack.js",
|
|
53
|
+
|
|
49
54
|
"./utils/sql": "./lib/utils/sql.util.js",
|
|
50
55
|
"./utils/strings": "./lib/utils/strings.util.js",
|
|
51
56
|
"./utils/sanitizations": "./lib/utils/sanitizations.util.js"
|
|
@@ -84,8 +89,6 @@
|
|
|
84
89
|
"accepts": "^1.3.8",
|
|
85
90
|
"body-parser": "^1.20.2",
|
|
86
91
|
"common-js-file-extensions": "^1.0.4",
|
|
87
|
-
"content-disposition": "^0.5.4",
|
|
88
|
-
"content-type": "^1.0.5",
|
|
89
92
|
"cookie": "^0.5.0",
|
|
90
93
|
"cookie-signature": "^1.2.0",
|
|
91
94
|
"debug": "^4.3.4",
|
|
@@ -95,13 +98,13 @@
|
|
|
95
98
|
"fresh": "^0.5.2",
|
|
96
99
|
"http-errors": "^2.0.0",
|
|
97
100
|
"inflection": "^2.0.1",
|
|
101
|
+
"mime": "^3.0.0",
|
|
98
102
|
"mysql2": "^3.6.0",
|
|
99
103
|
"pg": "^8.11.3",
|
|
100
104
|
"pg-hstore": "^2.3.4",
|
|
101
105
|
"proxy-addr": "^2.0.7",
|
|
102
106
|
"qs": "^6.11.0",
|
|
103
107
|
"range-parser": "^1.2.1",
|
|
104
|
-
"send": "^0.18.0",
|
|
105
108
|
"sequelize": "^6.6.5",
|
|
106
109
|
"type-is": "^1.6.18",
|
|
107
110
|
"vary": "^1.1.2"
|
package/tests/index.test.js
CHANGED
|
@@ -27,13 +27,13 @@ describe('nodester application', () => {
|
|
|
27
27
|
test('Application start', () => {
|
|
28
28
|
app.listen(PORT, function() {
|
|
29
29
|
expect(app.port).toBe(PORT);
|
|
30
|
-
expect(app.
|
|
31
|
-
expect(app.
|
|
30
|
+
expect(app.isLocked).toBe(true);
|
|
31
|
+
expect(app.isListening).toBe(true);
|
|
32
|
+
expect(app.middlewaresStack.length).toBe(4);
|
|
32
33
|
|
|
33
34
|
app.stop();
|
|
34
35
|
|
|
35
|
-
expect(app.
|
|
36
|
-
expect(app.router._middlewares.isLocked).toBe(false);
|
|
36
|
+
expect(app.isLocked).toBe(false);
|
|
37
37
|
expect(app.isListening).toBe(false);
|
|
38
38
|
});
|
|
39
39
|
});
|
package/tests/nql.test.js
CHANGED
|
@@ -49,6 +49,9 @@ describe('nodester Query Language', () => {
|
|
|
49
49
|
|
|
50
50
|
// Like simple.
|
|
51
51
|
'title=like(some_text)',
|
|
52
|
+
|
|
53
|
+
// Subinclude and isolated Horizontal.
|
|
54
|
+
'in=comments.user,likes',
|
|
52
55
|
];
|
|
53
56
|
|
|
54
57
|
it('query "Simple where"', () => {
|
|
@@ -262,7 +265,6 @@ describe('nodester Query Language', () => {
|
|
|
262
265
|
|
|
263
266
|
expect(result).toMatchObject(expected);
|
|
264
267
|
});
|
|
265
|
-
|
|
266
268
|
|
|
267
269
|
test('Token "Like" simple', () => {
|
|
268
270
|
const lexer = new QueryLexer( queryStrings[14] );
|
|
@@ -274,4 +276,19 @@ describe('nodester Query Language', () => {
|
|
|
274
276
|
|
|
275
277
|
expect(result).toMatchObject(expected);
|
|
276
278
|
});
|
|
279
|
+
|
|
280
|
+
it('query "Subinclude and isolated Horizontal"', () => {
|
|
281
|
+
const lexer = new QueryLexer( queryStrings[15] );
|
|
282
|
+
result = lexer.query;
|
|
283
|
+
|
|
284
|
+
const tree = new ModelsTree();
|
|
285
|
+
tree.include('comments').use('comments');
|
|
286
|
+
tree.include('user');
|
|
287
|
+
tree.up();
|
|
288
|
+
tree.include('likes');
|
|
289
|
+
const expected = tree.root.toObject();
|
|
290
|
+
|
|
291
|
+
expect(result).toMatchObject(expected);
|
|
292
|
+
});
|
|
293
|
+
|
|
277
294
|
});
|
package/lib/database/utils.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = {
|
|
3
|
-
associateModels: _associateModels
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
async function _associateModels(models) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
try {
|
|
9
|
-
Object.keys(models).map(modelName => (
|
|
10
|
-
models[modelName].associate(models)
|
|
11
|
-
));
|
|
12
|
-
|
|
13
|
-
return resolve(models);
|
|
14
|
-
}
|
|
15
|
-
catch(error) {
|
|
16
|
-
reject(error);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
package/lib/enums/Enum.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = Enum;
|
|
3
|
-
|
|
4
|
-
function Enum(constantsList = {}, writable=false) {
|
|
5
|
-
const def = (key, value) => Object.defineProperty(this, key, { value, writable: !!writable });
|
|
6
|
-
|
|
7
|
-
// Set list.
|
|
8
|
-
def('list', constantsList);
|
|
9
|
-
|
|
10
|
-
// Set getters:
|
|
11
|
-
Object.keys(constantsList)
|
|
12
|
-
.forEach(key => def(key, constantsList[key]) );
|
|
13
|
-
|
|
14
|
-
// Set constants in static array.
|
|
15
|
-
def('asArray', Object.values(constantsList) );
|
|
16
|
-
}
|
package/lib/filters/Filter.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* /nodester
|
|
3
|
-
* MIT Licensed
|
|
4
|
-
*/
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
const CLAUSES = ['limit', 'skip', 'order', 'order_by'];
|
|
8
|
-
|
|
9
|
-
const { isModel } = require('../utils/models');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
module.exports = class Filter {
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
*
|
|
16
|
-
* @param {Model} model
|
|
17
|
-
* @param {Object} opts
|
|
18
|
-
* - @param {Array} fields
|
|
19
|
-
* - @param {Array} clauses
|
|
20
|
-
* - @param {Object} includes
|
|
21
|
-
* - @param {Object} statics
|
|
22
|
-
* -- @param {Object} attributes
|
|
23
|
-
* -- @param {Object} clauses
|
|
24
|
-
*
|
|
25
|
-
* @param {Boolean} noLimit
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
constructor(model=null, opts=null) {
|
|
29
|
-
this._model = model;
|
|
30
|
-
|
|
31
|
-
this._fields = [];
|
|
32
|
-
this._clauses = [];
|
|
33
|
-
this._includes = {};
|
|
34
|
-
|
|
35
|
-
this._statics = {
|
|
36
|
-
attributes: {},
|
|
37
|
-
clauses: {}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// noLimit=false
|
|
41
|
-
// if (noLimit === true) {
|
|
42
|
-
// delete this._statics.clauses.limit;
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
// If model is present:
|
|
46
|
-
if (isModel(this._model)) {
|
|
47
|
-
this._fields = Object.keys(this._model.tableAttributes);
|
|
48
|
-
this._clauses = CLAUSES;
|
|
49
|
-
|
|
50
|
-
// ...and no options are provided,
|
|
51
|
-
// set default statics:
|
|
52
|
-
if (!opts) {
|
|
53
|
-
this.statics.clauses.limit = 3;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// If options are defined:
|
|
58
|
-
if (!!opts) {
|
|
59
|
-
const {
|
|
60
|
-
fields,
|
|
61
|
-
clauses,
|
|
62
|
-
includes,
|
|
63
|
-
statics,
|
|
64
|
-
} = opts;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// If fields are array:
|
|
68
|
-
if (Array.isArray(fields)) {
|
|
69
|
-
this._fields = fields;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (Array.isArray(clauses)) {
|
|
73
|
-
this._clauses = clauses;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (typeof includes === 'object') {
|
|
77
|
-
this._includes = includes;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (typeof statics === 'object') {
|
|
81
|
-
if (typeof statics.attributes === 'object') {
|
|
82
|
-
this._statics.attributes = statics.attributes;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (typeof statics.clauses === 'object') {
|
|
86
|
-
this._statics.clauses = statics.clauses;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Getters:
|
|
93
|
-
get fields() {
|
|
94
|
-
return this._fields;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get clauses() {
|
|
98
|
-
return this._clauses;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get includes() {
|
|
102
|
-
return this._includes;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
get statics() {
|
|
106
|
-
return this._statics;
|
|
107
|
-
}
|
|
108
|
-
// Getters\
|
|
109
|
-
}
|