nodester 0.2.6 → 0.2.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/.eslintrc.js +13 -0
- package/Readme.md +8 -4
- package/lib/application/index.js +61 -53
- package/lib/body/extract.js +4 -4
- 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 +12 -2
- package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +10 -2
- 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 +11 -3
- 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 +22 -20
- 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/.eslintrc.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
parserOptions: {
|
|
3
|
+
ecmaVersion: 2023, // or the latest version supported by ESLint
|
|
4
|
+
},
|
|
5
|
+
plugins: ['jsdoc'],
|
|
6
|
+
rules: {
|
|
7
|
+
'jsdoc/check-alignment': 'warn',
|
|
8
|
+
'jsdoc/check-indentation': 'warn',
|
|
9
|
+
'jsdoc/check-syntax': 'warn',
|
|
10
|
+
'jsdoc/require-param-type': 'warn',
|
|
11
|
+
'jsdoc/valid-types': 'warn',
|
|
12
|
+
},
|
|
13
|
+
};
|
package/Readme.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
The main reason of nodester's existence is the [nodester Query Language (NQL) ➡️](docs/nql/Introduction.md), an extension of standard REST API syntax, it lets you craft complex queries with hierarchical associations.
|
|
9
9
|
|
|
10
10
|
Building an application which allows users to build their own REST queries raises huge security concerns.
|
|
11
|
-
That's why nodester was not developped as a middleware. It's a framework equipped
|
|
11
|
+
That's why **nodester** was not developped as a middleware. It's a framework equipped with a set of technologies enabling you to fully customize the request-response flow down to the specific user and a database column.
|
|
12
12
|
Check out [core concepts documentation ➡️](docs/CoreConcepts.md) for more info.
|
|
13
13
|
|
|
14
14
|
|
|
@@ -71,6 +71,11 @@ Supported drivers:
|
|
|
71
71
|
[Application documentation ➡️](docs/App.md)
|
|
72
72
|
|
|
73
73
|
|
|
74
|
+
### Comments
|
|
75
|
+
|
|
76
|
+
We (contributors) use [JSDoc](https://jsdoc.app/) to describe the actual code.
|
|
77
|
+
|
|
78
|
+
|
|
74
79
|
## Philosophy
|
|
75
80
|
|
|
76
81
|
The Philosophy of `nodester` is to provide a developer with a tool that can build an app (or feature) in hours and scale it with ease for years.
|
|
@@ -80,9 +85,8 @@ The Philosophy of `nodester` is to provide a developer with a tool that can buil
|
|
|
80
85
|
The goal of `nodester` is to be a robust and flexible framework that makes development in iteratations easy, while laying the foundation for seamless scalability in the future.
|
|
81
86
|
|
|
82
87
|
|
|
83
|
-
##
|
|
84
|
-
|
|
85
|
-
MIT
|
|
88
|
+
## License
|
|
89
|
+
[MIT](LICENSE)
|
|
86
90
|
|
|
87
91
|
## Copyright
|
|
88
92
|
Copyright 2021-present [Mark Khramko](https://github.com/MarkKhramko)
|
package/lib/application/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -26,7 +26,7 @@ const Params = require('nodester/params');
|
|
|
26
26
|
const {
|
|
27
27
|
typeOf,
|
|
28
28
|
isConstructor
|
|
29
|
-
} = require('
|
|
29
|
+
} = require('nodester/utils/types');
|
|
30
30
|
const { merge } = require('../utils/objects.util');
|
|
31
31
|
|
|
32
32
|
// Arguments validator.
|
|
@@ -37,23 +37,32 @@ const consl = require('nodester/loggers/console');
|
|
|
37
37
|
const debug = require('debug')('nodester:application');
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Initialize new `NodesterApplication`.
|
|
42
|
+
*
|
|
43
|
+
* @class
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} [options]
|
|
46
|
+
* @param {string|Int} options.port
|
|
47
|
+
* @param {string} options.title
|
|
48
|
+
* @param {boolean} options.finalhandlerEnabled
|
|
49
|
+
* @param {Object} [options.middlewares={}]
|
|
50
|
+
* @param {Object} [options.middlewares.without=[]]
|
|
51
|
+
*
|
|
52
|
+
* @access public
|
|
53
|
+
*/
|
|
40
54
|
module.exports = class NodesterApplication extends Emitter {
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Initialize new `NodesterApplication`.
|
|
44
|
-
*
|
|
45
|
-
* @param {Object} [options]
|
|
46
|
-
* @param {String|Int} options.port
|
|
47
|
-
* @param {String} options.title
|
|
48
|
-
* @param {Boolean} options.finalhandlerEnabled
|
|
49
|
-
* @param {Object} options.middlewares
|
|
50
|
-
*
|
|
51
|
-
* @api public
|
|
52
|
-
*/
|
|
55
|
+
|
|
53
56
|
constructor(options={}) {
|
|
54
57
|
super();
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
try {
|
|
60
|
+
ensure(options, 'object', 'options');
|
|
61
|
+
}
|
|
62
|
+
catch(error) {
|
|
63
|
+
Error.captureStackTrace(error, this.constructor);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
57
66
|
|
|
58
67
|
// Unwrap options:
|
|
59
68
|
const {
|
|
@@ -117,7 +126,7 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
117
126
|
/**
|
|
118
127
|
* @return {MiddlewaresStack}
|
|
119
128
|
*
|
|
120
|
-
* @
|
|
129
|
+
* @access public
|
|
121
130
|
*/
|
|
122
131
|
get middlewaresStack() {
|
|
123
132
|
return this._router.middlewaresStack;
|
|
@@ -126,9 +135,9 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
126
135
|
/**
|
|
127
136
|
* Indicates whether user can add more middlewares or not.
|
|
128
137
|
*
|
|
129
|
-
* @return {
|
|
138
|
+
* @return {boolean} isLocked
|
|
130
139
|
*
|
|
131
|
-
* @
|
|
140
|
+
* @access public
|
|
132
141
|
*/
|
|
133
142
|
get isLocked() {
|
|
134
143
|
return this._router.isLocked;
|
|
@@ -137,9 +146,9 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
137
146
|
/**
|
|
138
147
|
* Indicates whether app is awaiting requests.
|
|
139
148
|
*
|
|
140
|
-
* @return {
|
|
149
|
+
* @return {boolean} isListening
|
|
141
150
|
*
|
|
142
|
-
* @
|
|
151
|
+
* @access public
|
|
143
152
|
*/
|
|
144
153
|
get isListening() {
|
|
145
154
|
return this._isListening;
|
|
@@ -147,10 +156,10 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
147
156
|
|
|
148
157
|
// Getters\
|
|
149
158
|
|
|
150
|
-
|
|
159
|
+
/**
|
|
151
160
|
* Expose the prototype that will get set on requests.
|
|
152
161
|
*
|
|
153
|
-
* @
|
|
162
|
+
* @access public
|
|
154
163
|
*/
|
|
155
164
|
get request() {
|
|
156
165
|
return Object.create(request, {
|
|
@@ -159,10 +168,10 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
159
168
|
}
|
|
160
169
|
|
|
161
170
|
|
|
162
|
-
|
|
171
|
+
/**
|
|
163
172
|
* Expose the prototype that will get set on responses.
|
|
164
173
|
*
|
|
165
|
-
* @
|
|
174
|
+
* @access public
|
|
166
175
|
*/
|
|
167
176
|
get response() {
|
|
168
177
|
return Object.create(response, {
|
|
@@ -171,12 +180,12 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
|
|
174
|
-
|
|
183
|
+
/**
|
|
175
184
|
* Sets (or overrides):
|
|
176
185
|
* - (database) main database of the application and tries to make connection
|
|
177
186
|
* - (router) default NodesterRouter
|
|
178
187
|
*
|
|
179
|
-
* @
|
|
188
|
+
* @access public
|
|
180
189
|
*/
|
|
181
190
|
get set() {
|
|
182
191
|
return {
|
|
@@ -191,12 +200,12 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
191
200
|
*
|
|
192
201
|
* @param {Sequilize} sequilizeConnection
|
|
193
202
|
* @param {Object} [options]
|
|
194
|
-
* @param {
|
|
195
|
-
* @param {
|
|
203
|
+
* @param {boolean} options.associateModels
|
|
204
|
+
* @param {boolean} options.crashOnError
|
|
196
205
|
*
|
|
197
206
|
* @return {sequilizeConnection.authenticate}
|
|
198
207
|
*
|
|
199
|
-
* @
|
|
208
|
+
* @access public
|
|
200
209
|
*/
|
|
201
210
|
async setDatabase(sequilizeConnection, options={}) {
|
|
202
211
|
try {
|
|
@@ -237,12 +246,12 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
237
246
|
}
|
|
238
247
|
|
|
239
248
|
|
|
240
|
-
|
|
249
|
+
/**
|
|
241
250
|
* Returns main database of the application.
|
|
242
251
|
*
|
|
243
252
|
* @return {SequilizeConnection} database
|
|
244
253
|
*
|
|
245
|
-
* @
|
|
254
|
+
* @access public
|
|
246
255
|
*/
|
|
247
256
|
get database() {
|
|
248
257
|
return this._database;
|
|
@@ -254,7 +263,7 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
254
263
|
*
|
|
255
264
|
* @param {NodesterRouter} newRouter
|
|
256
265
|
*
|
|
257
|
-
* @
|
|
266
|
+
* @access public
|
|
258
267
|
*/
|
|
259
268
|
setRouter(newRouter) {
|
|
260
269
|
if (isConstructor(newRouter)) {
|
|
@@ -266,23 +275,23 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
266
275
|
}
|
|
267
276
|
|
|
268
277
|
|
|
269
|
-
|
|
278
|
+
/**
|
|
270
279
|
* Returns NodesterRouter object.
|
|
271
280
|
*
|
|
272
281
|
* @return {NodesterRouter}
|
|
273
282
|
*
|
|
274
|
-
* @
|
|
283
|
+
* @access public
|
|
275
284
|
*/
|
|
276
285
|
get router() {
|
|
277
286
|
return this._router;
|
|
278
287
|
}
|
|
279
288
|
|
|
280
289
|
|
|
281
|
-
|
|
290
|
+
/**
|
|
282
291
|
* Adds:
|
|
283
292
|
* - (middleware) new middleware to the stack;
|
|
284
293
|
*
|
|
285
|
-
* @
|
|
294
|
+
* @access public
|
|
286
295
|
*/
|
|
287
296
|
get add() {
|
|
288
297
|
return {
|
|
@@ -294,12 +303,12 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
294
303
|
}
|
|
295
304
|
|
|
296
305
|
|
|
297
|
-
|
|
306
|
+
/**
|
|
298
307
|
* Proxy to router.use()
|
|
299
308
|
*
|
|
300
309
|
* @param {Function|NodesterRouter} fnOrRouter
|
|
301
310
|
*
|
|
302
|
-
* @
|
|
311
|
+
* @access public
|
|
303
312
|
*/
|
|
304
313
|
use(fnOrRouter) {
|
|
305
314
|
try {
|
|
@@ -314,11 +323,11 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
314
323
|
}
|
|
315
324
|
|
|
316
325
|
|
|
317
|
-
|
|
326
|
+
/**
|
|
318
327
|
*
|
|
319
|
-
* @param {
|
|
328
|
+
* @param {string} markerName
|
|
320
329
|
*
|
|
321
|
-
* @
|
|
330
|
+
* @access public
|
|
322
331
|
*/
|
|
323
332
|
only(markerName='') {
|
|
324
333
|
try {
|
|
@@ -336,7 +345,7 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
336
345
|
/**
|
|
337
346
|
* Sets beforeStart hook.
|
|
338
347
|
*
|
|
339
|
-
* @
|
|
348
|
+
* @access public
|
|
340
349
|
*/
|
|
341
350
|
beforeStart(fn) {
|
|
342
351
|
try {
|
|
@@ -358,7 +367,7 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
358
367
|
*
|
|
359
368
|
* @return {Function}
|
|
360
369
|
*
|
|
361
|
-
* @
|
|
370
|
+
* @access public
|
|
362
371
|
*/
|
|
363
372
|
async start() {
|
|
364
373
|
try {
|
|
@@ -389,15 +398,14 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
389
398
|
|
|
390
399
|
/**
|
|
391
400
|
* Shorthand for:
|
|
392
|
-
*
|
|
393
|
-
* http.createServer(app.start()).listen(...)
|
|
401
|
+
* http.createServer(app.start()).listen(...)
|
|
394
402
|
*
|
|
395
403
|
* @param {Integer|String} port
|
|
396
404
|
* @param {Mixed} ...
|
|
397
405
|
*
|
|
398
406
|
* @return {import('http').Server}
|
|
399
407
|
*
|
|
400
|
-
* @
|
|
408
|
+
* @access public
|
|
401
409
|
*/
|
|
402
410
|
async listen(port, ...args) {
|
|
403
411
|
try {
|
|
@@ -427,7 +435,7 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
427
435
|
/**
|
|
428
436
|
* Handles server request.
|
|
429
437
|
*
|
|
430
|
-
* @
|
|
438
|
+
* @access public
|
|
431
439
|
*/
|
|
432
440
|
handle(req, res) {
|
|
433
441
|
// Req & res with mixins:
|
|
@@ -445,12 +453,12 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
445
453
|
/**
|
|
446
454
|
* Extends Application & makes sure, that "key" param is not present already.
|
|
447
455
|
*
|
|
448
|
-
* @param {
|
|
449
|
-
* @param {
|
|
456
|
+
* @param {string} key
|
|
457
|
+
* @param {any} fnOrProperty
|
|
450
458
|
*
|
|
451
|
-
* @return {
|
|
459
|
+
* @return {any} fnOrProperty in Application
|
|
452
460
|
*
|
|
453
|
-
* @
|
|
461
|
+
* @access public
|
|
454
462
|
*/
|
|
455
463
|
extend(key='', fnOrProperty) {
|
|
456
464
|
ensure(key, 'string,required', 'key');
|
|
@@ -470,7 +478,7 @@ module.exports = class NodesterApplication extends Emitter {
|
|
|
470
478
|
/**
|
|
471
479
|
* Stops server
|
|
472
480
|
*
|
|
473
|
-
* @
|
|
481
|
+
* @access public
|
|
474
482
|
*/
|
|
475
483
|
stop() {
|
|
476
484
|
if (this._isListening !== true) {
|
package/lib/body/extract.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -12,14 +12,14 @@ const Sanitizations = require('nodester/utils/sanitizations');
|
|
|
12
12
|
|
|
13
13
|
module.exports = extract;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
16
|
* Extracts data from the body, based on the rules in "filter".
|
|
17
17
|
*
|
|
18
18
|
* @param {Object} body
|
|
19
19
|
* @param {NodesterFilter} filter
|
|
20
20
|
* @param {SequilizeModel} model
|
|
21
21
|
*
|
|
22
|
-
* @
|
|
22
|
+
* @access public
|
|
23
23
|
* @return {Object} filteredBody
|
|
24
24
|
*/
|
|
25
25
|
function extract(body, filter=null, model) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -7,17 +7,20 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
10
|
-
getOne:
|
|
11
|
-
getMany:
|
|
10
|
+
getOne: _getOne,
|
|
11
|
+
getMany: _getMany,
|
|
12
12
|
createOne: _createOne,
|
|
13
13
|
updateOne: _updateOne,
|
|
14
14
|
deleteOne: _deleteOne
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @param {IncomingMessage} req
|
|
20
|
+
* @param {ServerResponse} res
|
|
21
|
+
*
|
|
19
22
|
* @alias getOne
|
|
20
|
-
* @
|
|
23
|
+
* @access public
|
|
21
24
|
*/
|
|
22
25
|
async function _getOne(req, res) {
|
|
23
26
|
try {
|
|
@@ -52,9 +55,12 @@ async function _getOne(req, res) {
|
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
/**
|
|
59
|
+
* @param {IncomingMessage} req
|
|
60
|
+
* @param {ServerResponse} res
|
|
61
|
+
*
|
|
56
62
|
* @alias getMany
|
|
57
|
-
* @
|
|
63
|
+
* @access public
|
|
58
64
|
*/
|
|
59
65
|
async function _getMany(req, res) {
|
|
60
66
|
try {
|
|
@@ -86,9 +92,12 @@ async function _getMany(req, res) {
|
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
|
|
89
|
-
|
|
95
|
+
/**
|
|
96
|
+
* @param {IncomingMessage} req
|
|
97
|
+
* @param {ServerResponse} res
|
|
98
|
+
*
|
|
90
99
|
* @alias createOne
|
|
91
|
-
* @
|
|
100
|
+
* @access public
|
|
92
101
|
*/
|
|
93
102
|
async function _createOne(req, res) {
|
|
94
103
|
try {
|
|
@@ -124,9 +133,12 @@ async function _createOne(req, res) {
|
|
|
124
133
|
}
|
|
125
134
|
|
|
126
135
|
|
|
127
|
-
|
|
136
|
+
/**
|
|
137
|
+
* @param {IncomingMessage} req
|
|
138
|
+
* @param {ServerResponse} res
|
|
139
|
+
*
|
|
128
140
|
* @alias updateOne
|
|
129
|
-
* @
|
|
141
|
+
* @access public
|
|
130
142
|
*/
|
|
131
143
|
async function _updateOne(req, res) {
|
|
132
144
|
try {
|
|
@@ -162,9 +174,12 @@ async function _updateOne(req, res) {
|
|
|
162
174
|
}
|
|
163
175
|
|
|
164
176
|
|
|
165
|
-
|
|
177
|
+
/**
|
|
178
|
+
* @param {IncomingMessage} req
|
|
179
|
+
* @param {ServerResponse} res
|
|
180
|
+
*
|
|
166
181
|
* @alias deleteOne
|
|
167
|
-
* @
|
|
182
|
+
* @access public
|
|
168
183
|
*/
|
|
169
184
|
async function _deleteOne(req, res) {
|
|
170
185
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -40,14 +40,14 @@ module.exports = {
|
|
|
40
40
|
* Sets one of or all of CRUD methods to Controller.
|
|
41
41
|
*
|
|
42
42
|
* @param {Function|Object} controller
|
|
43
|
-
* @param {Object}
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
43
|
+
* @param {Object} options
|
|
44
|
+
* @param {NodesterFacade} options.facade
|
|
45
|
+
* @param {string} options.name
|
|
46
46
|
* @param {Array} options.only
|
|
47
47
|
*
|
|
48
48
|
* @return {Function|Object} controller
|
|
49
49
|
*
|
|
50
|
-
* @
|
|
50
|
+
* @access public
|
|
51
51
|
* @alias withDefaultCRUD
|
|
52
52
|
*/
|
|
53
53
|
function _withDefaultCRUD(controller, options={}) {
|
|
@@ -132,7 +132,7 @@ function _withDefaultCRUD(controller, options={}) {
|
|
|
132
132
|
*
|
|
133
133
|
* @return {Function|Object} controller
|
|
134
134
|
*
|
|
135
|
-
* @
|
|
135
|
+
* @access public
|
|
136
136
|
* @alias withDefaultErrorProcessing
|
|
137
137
|
*/
|
|
138
138
|
function _withDefaultErrorProcessing(controller, options={}) {
|
|
@@ -216,12 +216,12 @@ function _withDefaultErrorProcessing(controller, options={}) {
|
|
|
216
216
|
* Sets one of or all of CRUD methods to Controller.
|
|
217
217
|
*
|
|
218
218
|
* @param {Function|Object} controller
|
|
219
|
-
* @param {
|
|
220
|
-
* @param {
|
|
219
|
+
* @param {NodesterFacade} facade
|
|
220
|
+
* @param {string} facadeName
|
|
221
221
|
*
|
|
222
222
|
* @return {Function|Object} controller
|
|
223
223
|
*
|
|
224
|
-
* @
|
|
224
|
+
* @access public
|
|
225
225
|
* @alias setFacade
|
|
226
226
|
*/
|
|
227
227
|
function _setFacade(controller, facade, facadeName=null) {
|
|
@@ -243,12 +243,12 @@ function _setFacade(controller, facade, facadeName=null) {
|
|
|
243
243
|
/**
|
|
244
244
|
* Sets one of CRUD methods to Controller.
|
|
245
245
|
*
|
|
246
|
-
* @param {
|
|
246
|
+
* @param {Function|Object} controller
|
|
247
247
|
* @param {Function} fn
|
|
248
248
|
*
|
|
249
|
-
* @return {
|
|
249
|
+
* @return {Function|Object} controller
|
|
250
250
|
*
|
|
251
|
-
* @
|
|
251
|
+
* @access public
|
|
252
252
|
* @alias setMethod
|
|
253
253
|
*/
|
|
254
254
|
function _setMethod(controller, fn) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* nodester
|
|
3
3
|
* MIT Licensed
|
|
4
4
|
*/
|
|
5
|
+
|
|
5
6
|
'use strict';
|
|
6
7
|
|
|
7
|
-
//
|
|
8
|
+
// The one and only!
|
|
8
9
|
const Sequelize = require('sequelize');
|
|
9
10
|
|
|
10
11
|
|
|
@@ -12,27 +13,87 @@ module.exports = {
|
|
|
12
13
|
buildConnection: _buildConnection
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @param {object} [options={}] An object with options.
|
|
18
|
+
* @param {string} [options.name] The name of the database
|
|
19
|
+
* @param {string} [options.username=null] The username which is used to authenticate against the database.
|
|
20
|
+
* @param {string} [options.password=null] The password which is used to authenticate against the database. Supports SQLCipher encryption for SQLite.
|
|
21
|
+
* @param {string} [options.host='localhost'] The host of the relational database.
|
|
22
|
+
* @param {number} [options.port] The port of the relational database.
|
|
23
|
+
* @param {string} [options.username=null] The username which is used to authenticate against the database.
|
|
24
|
+
* @param {string} [options.password=null] The password which is used to authenticate against the database.
|
|
25
|
+
* @param {string} [options.database=null] The name of the database.
|
|
26
|
+
* @param {string} [options.dialect] The dialect of the database you are connecting to. One of mysql, postgres, sqlite, db2, mariadb and mssql.
|
|
27
|
+
* @param {string} [options.dialectModule=null] If specified, use this dialect library. For example, if you want to use pg.js instead of pg when connecting to a pg database, you should specify 'require("pg.js")' here
|
|
28
|
+
* @param {string} [options.dialectModulePath=null] If specified, load the dialect library from this path. For example, if you want to use pg.js instead of pg when connecting to a pg database, you should specify '/path/to/pg.js' here
|
|
29
|
+
* @param {object} [options.dialectOptions] An object of additional options, which are passed directly to the connection library
|
|
30
|
+
* @param {string} [options.storage] Only used by sqlite. Defaults to ':memory:'
|
|
31
|
+
* @param {string} [options.protocol='tcp'] The protocol of the relational database.
|
|
32
|
+
* @param {object} [options.define={}] Default options for model definitions. See {@link Model.init}.
|
|
33
|
+
* @param {object} [options.query={}] Default options for sequelize.query
|
|
34
|
+
* @param {string} [options.schema=null] A schema to use
|
|
35
|
+
* @param {object} [options.set={}] Default options for sequelize.set
|
|
36
|
+
* @param {object} [options.sync={}] Default options for sequelize.sync
|
|
37
|
+
* @param {string} [options.timezone='+00:00'] The timezone used when converting a date from the database into a JavaScript date. The timezone is also used to SET TIMEZONE when connecting to the server, to ensure that the result of NOW, CURRENT_TIMESTAMP and other time related functions have in the right timezone. For best cross platform performance use the format +/-HH:MM. Will also accept string versions of timezones supported by Intl.Locale (e.g. 'America/Los_Angeles'); this is useful to capture daylight savings time changes.
|
|
38
|
+
* @param {boolean} [options.keepDefaultTimezone=false] A flag that defines if the default timezone is used to convert dates from the database.
|
|
39
|
+
* @param {number|null} [options.defaultTimestampPrecision] The precision for the `createdAt`/`updatedAt`/`deletedAt` DATETIME columns that Sequelize adds to models. Can be a number between 0 and 6, or null to use the default precision of the database. Defaults to 6.
|
|
40
|
+
* @param {string|boolean} [options.clientMinMessages='warning'] (Deprecated) The PostgreSQL `client_min_messages` session parameter. Set to `false` to not override the database's default.
|
|
41
|
+
* @param {boolean} [options.standardConformingStrings=true] The PostgreSQL `standard_conforming_strings` session parameter. Set to `false` to not set the option. WARNING: Setting this to false may expose vulnerabilities and is not recommended!
|
|
42
|
+
* @param {Function} [options.logging=console.log] A function that gets executed every time Sequelize would log something. Function may receive multiple parameters but only first one is printed by `console.log`. To print all values use `(...msg) => console.log(msg)`
|
|
43
|
+
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
|
|
44
|
+
* @param {string} [options.queryLabel] A label to annotate queries in log output.
|
|
45
|
+
* @param {boolean} [options.omitNull=false] A flag that defines if null values should be passed as values to CREATE/UPDATE SQL queries or not.
|
|
46
|
+
* @param {boolean} [options.native=false] A flag that defines if native library shall be used or not. Currently only has an effect for postgres
|
|
47
|
+
* @param {boolean} [options.ssl=undefined] A flag that defines if connection should be over ssl or not
|
|
48
|
+
* @param {boolean} [options.replication=false] Use read / write replication. To enable replication, pass an object, with two properties, read and write. Write should be an object (a single server for handling writes), and read an array of object (several servers to handle reads). Each read/write server can have the following properties: `host`, `port`, `username`, `password`, `database`. Connection strings can be used instead of objects.
|
|
49
|
+
* @param {object} [options.pool] sequelize connection pool configuration
|
|
50
|
+
* @param {number} [options.pool.max=5] Maximum number of connection in pool
|
|
51
|
+
* @param {number} [options.pool.min=0] Minimum number of connection in pool
|
|
52
|
+
* @param {number} [options.pool.idle=10000] The maximum time, in milliseconds, that a connection can be idle before being released.
|
|
53
|
+
* @param {number} [options.pool.acquire=60000] The maximum time, in milliseconds, that pool will try to get connection before throwing error
|
|
54
|
+
* @param {number} [options.pool.evict=1000] The time interval, in milliseconds, after which sequelize-pool will remove idle connections.
|
|
55
|
+
* @param {Function} [options.pool.validate] A function that validates a connection. Called with client. The default function checks that client is an object, and that its state is not disconnected
|
|
56
|
+
* @param {number} [options.pool.maxUses=Infinity] The number of times a connection can be used before discarding it for a replacement, [`used for eventual cluster rebalancing`](https://github.com/sequelize/sequelize-pool).
|
|
57
|
+
* @param {boolean} [options.quoteIdentifiers=true] Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of them. WARNING: Setting this to false may expose vulnerabilities and is not recommended!
|
|
58
|
+
* @param {string} [options.transactionType='DEFERRED'] Set the default transaction type. See `Sequelize.Transaction.TYPES` for possible options. Sqlite only.
|
|
59
|
+
* @param {string} [options.isolationLevel] Set the default transaction isolation level. See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options.
|
|
60
|
+
* @param {object} [options.retry] Set of flags that control when a query is automatically retried. Accepts all options for [`retry-as-promised`](https://github.com/mickhansen/retry-as-promised).
|
|
61
|
+
* @param {Array} [options.retry.match] Only retry a query if the error matches one of these strings.
|
|
62
|
+
* @param {number} [options.retry.max] How many times a failing query is automatically retried. Set to 0 to disable retrying on SQL_BUSY error.
|
|
63
|
+
* @param {number} [options.retry.timeout] Maximum duration, in milliseconds, to retry until an error is thrown.
|
|
64
|
+
* @param {number} [options.retry.backoffBase=100] Initial backoff duration, in milliseconds.
|
|
65
|
+
* @param {number} [options.retry.backoffExponent=1.1] Exponent to increase backoff duration after each retry.
|
|
66
|
+
* @param {Function} [options.retry.report] Function that is executed after each retry, called with a message and the current retry options.
|
|
67
|
+
* @param {string} [options.retry.name='unknown'] Name used when composing error/reporting messages.
|
|
68
|
+
* @param {boolean} [options.noTypeValidation=false] Run built-in type validators on insert and update, and select with where clause, e.g. validate that arguments passed to integer fields are integer-like.
|
|
69
|
+
* @param {object} [options.hooks] An object of global hook functions that are called before and after certain lifecycle events. Global hooks will run after any model-specific hooks defined for the same event (See `Sequelize.Model.init()` for a list). Additionally, `beforeConnect()`, `afterConnect()`, `beforeDisconnect()`, and `afterDisconnect()` hooks may be defined here.
|
|
70
|
+
* @param {boolean} [options.minifyAliases=false] A flag that defines if aliases should be minified (mostly useful to avoid Postgres alias character limit of 64)
|
|
71
|
+
* @param {boolean} [options.logQueryParameters=false] A flag that defines if show bind parameters in log.
|
|
72
|
+
*
|
|
73
|
+
* @return {Sequelize} connection - Connection to the database.
|
|
74
|
+
*
|
|
75
|
+
* @alias buildConnection
|
|
76
|
+
* @access public
|
|
77
|
+
*/
|
|
78
|
+
function _buildConnection(options={}) {
|
|
16
79
|
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const password = opts.password;
|
|
21
|
-
|
|
80
|
+
const dbName = options.name;
|
|
81
|
+
const username = options.username;
|
|
82
|
+
const password = options.password;
|
|
22
83
|
|
|
23
84
|
const connection = new Sequelize(
|
|
24
85
|
dbName,
|
|
25
86
|
username,
|
|
26
87
|
password,
|
|
27
88
|
{
|
|
28
|
-
host:
|
|
29
|
-
port:
|
|
30
|
-
dialect:
|
|
31
|
-
pool:
|
|
32
|
-
charset:
|
|
33
|
-
collate:
|
|
34
|
-
timestamps:
|
|
35
|
-
logging:
|
|
89
|
+
host: options.host,
|
|
90
|
+
port: options.port,
|
|
91
|
+
dialect: options.dialect,
|
|
92
|
+
pool: options.pool,
|
|
93
|
+
charset: options.charset,
|
|
94
|
+
collate: options.collate,
|
|
95
|
+
timestamps: options.timestamps,
|
|
96
|
+
logging: options.logging
|
|
36
97
|
}
|
|
37
98
|
);
|
|
38
99
|
|
|
@@ -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
|
-
|