nodester 0.2.6 → 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.
Files changed (62) hide show
  1. package/.eslintrc.js +13 -0
  2. package/Readme.md +8 -4
  3. package/lib/application/index.js +61 -53
  4. package/lib/body/extract.js +4 -4
  5. package/lib/controllers/methods/index.js +29 -14
  6. package/lib/controllers/mixins/index.js +13 -13
  7. package/lib/database/connection.js +78 -17
  8. package/lib/database/migration.js +9 -3
  9. package/lib/errors/CustomError.js +7 -2
  10. package/lib/errors/NodesterError.js +10 -2
  11. package/lib/errors/NodesterQueryError.js +9 -2
  12. package/lib/errors/index.js +2 -2
  13. package/lib/facades/methods/index.js +15 -15
  14. package/lib/facades/mixins/index.js +12 -12
  15. package/lib/factories/responses/html.js +20 -9
  16. package/lib/factories/responses/rest.js +21 -19
  17. package/lib/http/codes/descriptions.js +4 -3
  18. package/lib/http/codes/index.js +3 -2
  19. package/lib/http/codes/symbols.js +3 -2
  20. package/lib/http/request/index.js +20 -250
  21. package/lib/http/request/utils.js +4 -4
  22. package/lib/http/response/headers.js +16 -19
  23. package/lib/http/response/index.js +25 -28
  24. package/lib/http/response/utils.js +7 -6
  25. package/lib/loggers/console.js +3 -4
  26. package/lib/loggers/dev.js +3 -4
  27. package/lib/middlewares/404/index.js +38 -0
  28. package/lib/middlewares/SearchParams/index.js +3 -3
  29. package/lib/middlewares/cookies/index.js +2 -2
  30. package/lib/middlewares/etag/index.js +10 -8
  31. package/lib/middlewares/formidable/index.js +2 -2
  32. package/lib/middlewares/ql/sequelize/index.js +2 -2
  33. package/lib/middlewares/ql/sequelize/interpreter/ModelsTree.js +12 -2
  34. package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +10 -2
  35. package/lib/middlewares/render/index.js +3 -3
  36. package/lib/models/associate.js +3 -2
  37. package/lib/models/define.js +37 -18
  38. package/lib/models/mixins.js +9 -9
  39. package/lib/query/traverse.js +11 -3
  40. package/lib/router/handlers.util.js +5 -5
  41. package/lib/router/index.js +84 -70
  42. package/lib/router/markers.js +5 -5
  43. package/lib/router/route.js +18 -19
  44. package/lib/router/routes.util.js +4 -4
  45. package/lib/router/utils.js +2 -2
  46. package/lib/stacks/MarkersStack.js +11 -9
  47. package/lib/stacks/MiddlewaresStack.js +25 -21
  48. package/lib/structures/Enum.js +8 -2
  49. package/lib/structures/Filter.js +22 -20
  50. package/lib/structures/Params.js +3 -3
  51. package/lib/tools/nql.tool.js +10 -2
  52. package/lib/tools/sql.tool.js +19 -2
  53. package/lib/utils/json.util.js +28 -27
  54. package/lib/utils/models.js +3 -2
  55. package/lib/utils/objects.util.js +10 -11
  56. package/lib/utils/path.util.js +9 -3
  57. package/lib/utils/sanitizations.util.js +3 -2
  58. package/lib/utils/types.util.js +11 -4
  59. package/lib/validators/arguments.js +28 -9
  60. package/lib/validators/dates.js +4 -5
  61. package/lib/validators/numbers.js +4 -4
  62. package/package.json +43 -39
@@ -1,11 +1,16 @@
1
- /*!
2
- * /nodester
1
+ /**
2
+ * nodester
3
3
  * MIT Licensed
4
4
  */
5
5
 
6
6
  'use strict';
7
7
 
8
8
 
9
+ /**
10
+ * @class
11
+ *
12
+ * @access public
13
+ */
9
14
  module.exports = class CustomError extends Error {
10
15
  constructor(message) {
11
16
  super(message);
@@ -1,11 +1,19 @@
1
- /*!
2
- * /nodester
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
- * /nodester
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);
@@ -1,5 +1,5 @@
1
- /*!
2
- * /nodester
1
+ /**
2
+ * nodester
3
3
  * MIT Licensed
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
- /*!
2
- * /nodester
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: _getOne,
15
- getMany: _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
- * @api public
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
- * @api public
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
- * @api public
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.getIncludesList(data)
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
- * @api public
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
- * @api public
176
+ * @access public
177
177
  */
178
178
  async function _deleteOne(params) {
179
179
  try {
@@ -1,5 +1,5 @@
1
- /*!
2
- * /nodester
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 {Function|Object} facade
33
+ * @param {NodesterFacade} facade
34
34
  * @param {Object} options
35
- * @param {Function|Object} options.model
36
- * @param {String} options.name
37
- * @param {Array} options.only
35
+ * @param {Model} options.model
36
+ * @param {string} options.name
37
+ * @param {Array} options.only
38
38
  *
39
- * @return {Function|Object} facade
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 {Facade} facade
151
+ * @param {NodesterFacade} facade
152
152
  * @param {Function} fn
153
153
  *
154
- * @return {Facade} facade
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
- const Params = require('../../params/Params');
13
+
14
+ const Params = require('nodester/params');
15
+
16
+
17
+ module.exports = HtmlResponseFactory
7
18
 
8
19
 
9
- module.exports = class HtmlResponseFactory {
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 <Object> res
17
- * @param <String> viewName
18
- * @param <Object> params
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 <Object> res
39
- * @param <Object> error
40
- * @param <Int> code
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
- * /nodester
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
- * content: {...}
25
- * error: {...}
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 (optional)
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
- * @api public
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 (optional)
116
- * @param {Object} options.status (optional)
117
+ * @param {Object} [options.content]
118
+ * @param {Object} [options.status]
117
119
  *
118
120
  * @alias createOKResponse
119
- * @api public
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 (optional)
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
- * @api public
142
+ * @access public
141
143
  */
142
144
  function _createErrorResponse(res, options) {
143
145
  return _createGenericResponse(res, {
@@ -1,5 +1,5 @@
1
- /*!
2
- * /nodester
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_');
@@ -1,7 +1,8 @@
1
- /*!
2
- * /nodester
1
+ /**
2
+ * nodester
3
3
  * MIT Licensed
4
4
  */
5
+
5
6
  'use strict';
6
7
 
7
8
  const Enum = require('nodester/enum');
@@ -1,7 +1,8 @@
1
- /*!
2
- * /nodester
1
+ /**
2
+ * nodester
3
3
  * MIT Licensed
4
4
  */
5
+
5
6
  'use strict';
6
7
 
7
8
  const Enum = require('nodester/enum');