nodester 0.2.5 → 0.2.8
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/.eslintrc.js +13 -0
- package/Readme.md +12 -4
- package/lib/application/index.js +61 -53
- package/lib/body/extract.js +10 -10
- package/lib/controllers/methods/index.js +29 -14
- package/lib/controllers/mixins/index.js +13 -13
- package/lib/database/connection.js +78 -17
- package/lib/database/migration.js +9 -3
- package/lib/errors/CustomError.js +7 -2
- package/lib/errors/NodesterError.js +10 -2
- package/lib/errors/NodesterQueryError.js +9 -2
- package/lib/errors/index.js +2 -2
- package/lib/facades/methods/index.js +15 -15
- package/lib/facades/mixins/index.js +12 -12
- package/lib/factories/responses/html.js +20 -9
- package/lib/factories/responses/rest.js +21 -19
- package/lib/http/codes/descriptions.js +4 -3
- package/lib/http/codes/index.js +3 -2
- package/lib/http/codes/symbols.js +3 -2
- package/lib/http/request/index.js +20 -250
- package/lib/http/request/utils.js +4 -4
- package/lib/http/response/headers.js +16 -19
- package/lib/http/response/index.js +25 -28
- package/lib/http/response/utils.js +7 -6
- package/lib/loggers/console.js +3 -4
- package/lib/loggers/dev.js +3 -4
- package/lib/middlewares/404/index.js +38 -0
- package/lib/middlewares/SearchParams/index.js +3 -3
- package/lib/middlewares/cookies/index.js +2 -2
- package/lib/middlewares/etag/index.js +10 -8
- package/lib/middlewares/formidable/index.js +2 -2
- package/lib/middlewares/ql/sequelize/index.js +2 -2
- package/lib/middlewares/ql/sequelize/interpreter/ModelsTree.js +25 -4
- package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +30 -18
- package/lib/middlewares/render/index.js +3 -3
- package/lib/models/associate.js +3 -2
- package/lib/models/define.js +37 -18
- package/lib/models/mixins.js +9 -9
- package/lib/query/traverse.js +40 -32
- package/lib/router/handlers.util.js +5 -5
- package/lib/router/index.js +84 -70
- package/lib/router/markers.js +5 -5
- package/lib/router/route.js +18 -19
- package/lib/router/routes.util.js +4 -4
- package/lib/router/utils.js +2 -2
- package/lib/stacks/MarkersStack.js +11 -9
- package/lib/stacks/MiddlewaresStack.js +25 -21
- package/lib/structures/Enum.js +8 -2
- package/lib/structures/Filter.js +31 -29
- package/lib/structures/Params.js +3 -3
- package/lib/tools/nql.tool.js +10 -2
- package/lib/tools/sql.tool.js +19 -2
- package/lib/utils/json.util.js +28 -27
- package/lib/utils/models.js +3 -2
- package/lib/utils/objects.util.js +10 -11
- package/lib/utils/path.util.js +9 -3
- package/lib/utils/sanitizations.util.js +3 -2
- package/lib/utils/types.util.js +11 -4
- package/lib/validators/arguments.js +28 -9
- package/lib/validators/dates.js +4 -5
- package/lib/validators/numbers.js +4 -4
- package/package.json +43 -39
- package/tests/nql.test.js +20 -7
- /package/lib/constants/{Operations.js → Operators.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -15,6 +15,13 @@ module.exports = {
|
|
|
15
15
|
migrate: _migrate
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @param {Sequelize} connection
|
|
20
|
+
* @param {boolean} force
|
|
21
|
+
*
|
|
22
|
+
* @alias migrate
|
|
23
|
+
* @access public
|
|
24
|
+
*/
|
|
18
25
|
async function _migrate(databaseConnection, force=false) {
|
|
19
26
|
try {
|
|
20
27
|
ensure(force, 'boolean', 'force');
|
|
@@ -48,4 +55,3 @@ async function _migrate(databaseConnection, force=false) {
|
|
|
48
55
|
return Promise.reject(error);
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
|
-
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @class
|
|
11
|
+
*
|
|
12
|
+
* @param {string} [message]
|
|
13
|
+
* @param {string|Int} [status]
|
|
14
|
+
*
|
|
15
|
+
* @access public
|
|
16
|
+
*/
|
|
9
17
|
module.exports = class NodesterError extends Error {
|
|
10
18
|
constructor(message, status) {
|
|
11
19
|
super(message);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -15,6 +15,13 @@ const {
|
|
|
15
15
|
const NodesterError = require('./NodesterError');
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @class
|
|
20
|
+
*
|
|
21
|
+
* @param {string} [message]
|
|
22
|
+
*
|
|
23
|
+
* @access public
|
|
24
|
+
*/
|
|
18
25
|
module.exports = class NodesterQueryError extends NodesterError {
|
|
19
26
|
constructor(message) {
|
|
20
27
|
super(message);
|
package/lib/errors/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -11,21 +11,21 @@ const log = require('nodester/loggers/dev');
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
module.exports = {
|
|
14
|
-
getOne:
|
|
15
|
-
getMany:
|
|
14
|
+
getOne: _getOne,
|
|
15
|
+
getMany: _getMany,
|
|
16
16
|
createOne: _createOne,
|
|
17
17
|
updateOne: _updateOne,
|
|
18
18
|
deleteOne: _deleteOne
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
23
|
*
|
|
24
24
|
* @param {Object} [params]
|
|
25
25
|
* @param {Object} params.query
|
|
26
26
|
*
|
|
27
27
|
* @alias getOne
|
|
28
|
-
* @
|
|
28
|
+
* @access public
|
|
29
29
|
*/
|
|
30
30
|
async function _getOne(params) {
|
|
31
31
|
try {
|
|
@@ -54,13 +54,13 @@ async function _getOne(params) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
/**
|
|
58
58
|
*
|
|
59
59
|
* @param {Object} [params]
|
|
60
60
|
* @param {Object} params.query
|
|
61
61
|
*
|
|
62
62
|
* @alias getMany
|
|
63
|
-
* @
|
|
63
|
+
* @access public
|
|
64
64
|
*/
|
|
65
65
|
async function _getMany(params) {
|
|
66
66
|
try {
|
|
@@ -89,13 +89,13 @@ async function _getMany(params) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
/**
|
|
93
93
|
*
|
|
94
94
|
* @param {Object} [params]
|
|
95
95
|
* @param {Object} params.data
|
|
96
96
|
*
|
|
97
97
|
* @alias createOne
|
|
98
|
-
* @
|
|
98
|
+
* @access public
|
|
99
99
|
*/
|
|
100
100
|
async function _createOne(params) {
|
|
101
101
|
try {
|
|
@@ -106,7 +106,7 @@ async function _createOne(params) {
|
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
const instance = await this.model.create({ ...data }, {
|
|
109
|
-
include: this.model.
|
|
109
|
+
include: this.model.getIncludesTree(data)
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
const result = {
|
|
@@ -126,14 +126,14 @@ async function _createOne(params) {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
/**
|
|
130
130
|
*
|
|
131
131
|
* @param {Object} [params]
|
|
132
132
|
* @param {Object} params.query
|
|
133
133
|
* @param {Object} params.data
|
|
134
134
|
*
|
|
135
135
|
* @alias updateOne
|
|
136
|
-
* @
|
|
136
|
+
* @access public
|
|
137
137
|
*/
|
|
138
138
|
async function _updateOne(params) {
|
|
139
139
|
try {
|
|
@@ -167,13 +167,13 @@ async function _updateOne(params) {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
|
|
170
|
-
|
|
170
|
+
/**
|
|
171
171
|
*
|
|
172
172
|
* @param {Object} [params]
|
|
173
173
|
* @param {Object} params.query
|
|
174
174
|
*
|
|
175
175
|
* @alias deleteOne
|
|
176
|
-
* @
|
|
176
|
+
* @access public
|
|
177
177
|
*/
|
|
178
178
|
async function _deleteOne(params) {
|
|
179
179
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -30,16 +30,16 @@ module.exports = {
|
|
|
30
30
|
/**
|
|
31
31
|
* Sets one of or all of CRUD methods to Facade.
|
|
32
32
|
*
|
|
33
|
-
* @param {
|
|
33
|
+
* @param {NodesterFacade} facade
|
|
34
34
|
* @param {Object} options
|
|
35
|
-
* @param {
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {Array}
|
|
35
|
+
* @param {Model} options.model
|
|
36
|
+
* @param {string} options.name
|
|
37
|
+
* @param {Array} options.only
|
|
38
38
|
*
|
|
39
|
-
* @return {
|
|
39
|
+
* @return {NodesterFacade} facade
|
|
40
40
|
*
|
|
41
|
-
* @api public
|
|
42
41
|
* @alias withDefaultCRUD
|
|
42
|
+
* @access public
|
|
43
43
|
*/
|
|
44
44
|
function _withDefaultCRUD(facade, options={}) {
|
|
45
45
|
ensure(facade, 'function|object,required', 'facade');
|
|
@@ -146,15 +146,15 @@ function _withDefaultCRUD(facade, options={}) {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
|
-
* Sets one of CRUD methods to Facade.
|
|
149
|
+
* Sets one of CRUD methods to a Facade.
|
|
150
150
|
*
|
|
151
|
-
* @param {
|
|
151
|
+
* @param {NodesterFacade} facade
|
|
152
152
|
* @param {Function} fn
|
|
153
153
|
*
|
|
154
|
-
* @return {
|
|
154
|
+
* @return {NodesterFacade} facade
|
|
155
155
|
*
|
|
156
|
-
* @api public
|
|
157
156
|
* @alias setMethod
|
|
157
|
+
* @access public
|
|
158
158
|
*/
|
|
159
159
|
function _setMethod(facade, fn) {
|
|
160
160
|
ensure(facade, 'function|object,required', 'facade');
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
|
+
* MIT Licensed
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* WARNING: Unfinihsed. Do not use!
|
|
3
10
|
*
|
|
4
11
|
*/
|
|
5
12
|
|
|
6
|
-
|
|
13
|
+
|
|
14
|
+
const Params = require('nodester/params');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
module.exports = HtmlResponseFactory
|
|
7
18
|
|
|
8
19
|
|
|
9
|
-
|
|
20
|
+
class HtmlResponseFactory {
|
|
10
21
|
constructor() {}
|
|
11
22
|
|
|
12
23
|
/**
|
|
13
24
|
* Sends rendererd HTML view with status code 200.
|
|
14
25
|
* Should be called on all successful respones.
|
|
15
26
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
27
|
+
* @param {Object} res
|
|
28
|
+
* @param {string} viewName
|
|
29
|
+
* @param {Object} params
|
|
19
30
|
*/
|
|
20
31
|
createOKResponse(params) {
|
|
21
32
|
const {
|
|
@@ -35,9 +46,9 @@ module.exports = class HtmlResponseFactory {
|
|
|
35
46
|
* Sends response with provided error code.
|
|
36
47
|
* Should be called on all failed respones.
|
|
37
48
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
49
|
+
* @param {Object} res
|
|
50
|
+
* @param {Object} error
|
|
51
|
+
* @param {Int} code
|
|
41
52
|
*/
|
|
42
53
|
createErrorResponse(params) {
|
|
43
54
|
const {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
9
|
* REST response factory.
|
|
10
10
|
*/
|
|
11
11
|
const Params = require('nodester/params');
|
|
@@ -18,26 +18,28 @@ module.exports = {
|
|
|
18
18
|
createErrorResponse: _createErrorResponse,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
22
|
* Format for all API responses will be JSON
|
|
23
|
+
* Status code is sent in header.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
23
26
|
* {
|
|
24
|
-
*
|
|
25
|
-
*
|
|
27
|
+
* content: {...}
|
|
28
|
+
* error: {...}
|
|
26
29
|
* }
|
|
27
|
-
* Status code is sent in header.
|
|
28
30
|
*
|
|
29
31
|
* If error is not present, error must be null.
|
|
30
32
|
* If error is present, content can be null (But it's not required).
|
|
31
33
|
*
|
|
32
34
|
* @param {ServerResponse} res
|
|
33
35
|
* @param {Object} [options]
|
|
34
|
-
* @param {Object} options.error
|
|
35
|
-
* @param {Object} options.content
|
|
36
|
-
* @param {Int} options.status
|
|
36
|
+
* @param {Object} [options.error]
|
|
37
|
+
* @param {Object} [options.content]
|
|
38
|
+
* @param {Int} [options.status]
|
|
37
39
|
*
|
|
38
40
|
* @alias createGenericResponse
|
|
39
|
-
* @
|
|
40
|
-
*/
|
|
41
|
+
* @access public
|
|
42
|
+
*/
|
|
41
43
|
function _createGenericResponse(res, options) {
|
|
42
44
|
try {
|
|
43
45
|
let {
|
|
@@ -112,11 +114,11 @@ function _createGenericResponse(res, options) {
|
|
|
112
114
|
*
|
|
113
115
|
* @param {ServerResponse} res
|
|
114
116
|
* @param {Object} [options]
|
|
115
|
-
* @param {Object} options.content
|
|
116
|
-
* @param {Object} options.status
|
|
117
|
+
* @param {Object} [options.content]
|
|
118
|
+
* @param {Object} [options.status]
|
|
117
119
|
*
|
|
118
120
|
* @alias createOKResponse
|
|
119
|
-
* @
|
|
121
|
+
* @access public
|
|
120
122
|
*/
|
|
121
123
|
function _createOKResponse(res, options={}) {
|
|
122
124
|
return _createGenericResponse(res, {
|
|
@@ -132,12 +134,12 @@ function _createOKResponse(res, options={}) {
|
|
|
132
134
|
*
|
|
133
135
|
* @param {ServerResponse} res
|
|
134
136
|
* @param {Object} [options]
|
|
135
|
-
* @param {Object} options.error
|
|
136
|
-
* @param {Object} options.content
|
|
137
|
-
* @param {Int} options.status
|
|
137
|
+
* @param {Object} [options.error]
|
|
138
|
+
* @param {Object} [options.content]
|
|
139
|
+
* @param {Int} [options.status]
|
|
138
140
|
*
|
|
139
141
|
* @alias createErrorResponse
|
|
140
|
-
* @
|
|
142
|
+
* @access public
|
|
141
143
|
*/
|
|
142
144
|
function _createErrorResponse(res, options) {
|
|
143
145
|
return _createGenericResponse(res, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
'use strict';
|
|
@@ -79,4 +79,5 @@ module.exports = new Enum({
|
|
|
79
79
|
508: 'Loop Detected',
|
|
80
80
|
510: 'Not Extended',
|
|
81
81
|
511: 'Network Authentication Required'
|
|
82
|
-
})
|
|
82
|
+
})
|
|
83
|
+
.withKeyPrefix('HTTP_CODE_DESCRIPTION_');
|
package/lib/http/codes/index.js
CHANGED