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.
Files changed (64) hide show
  1. package/.eslintrc.js +13 -0
  2. package/Readme.md +12 -4
  3. package/lib/application/index.js +61 -53
  4. package/lib/body/extract.js +10 -10
  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 +25 -4
  34. package/lib/middlewares/ql/sequelize/interpreter/QueryLexer.js +30 -18
  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 +40 -32
  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 +31 -29
  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
  63. package/tests/nql.test.js +20 -7
  64. /package/lib/constants/{Operations.js → Operators.js} +0 -0
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
@@ -5,7 +5,11 @@
5
5
 
6
6
  > **nodester** is a Node.js framework designed to solve the problem of a complex data querying over HTTP.
7
7
 
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.
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
+
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 with a set of technologies enabling you to fully customize the request-response flow down to the specific user and a database column.
12
+ Check out [core concepts documentation ➡️](docs/CoreConcepts.md) for more info.
9
13
 
10
14
 
11
15
  ## Installation
@@ -67,6 +71,11 @@ Supported drivers:
67
71
  [Application documentation ➡️](docs/App.md)
68
72
 
69
73
 
74
+ ### Comments
75
+
76
+ We (contributors) use [JSDoc](https://jsdoc.app/) to describe the actual code.
77
+
78
+
70
79
  ## Philosophy
71
80
 
72
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.
@@ -76,9 +85,8 @@ The Philosophy of `nodester` is to provide a developer with a tool that can buil
76
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.
77
86
 
78
87
 
79
- ## LICENSE
80
-
81
- MIT
88
+ ## License
89
+ [MIT](LICENSE)
82
90
 
83
91
  ## Copyright
84
92
  Copyright 2021-present [Mark Khramko](https://github.com/MarkKhramko)
@@ -1,5 +1,5 @@
1
- /*!
2
- * /nodester
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('../utils/types.util');
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
- ensure(options, 'object', 'options');
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
- * @api public
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 {Boolean} isLocked
138
+ * @return {boolean} isLocked
130
139
  *
131
- * @api public
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 {Boolean} isListening
149
+ * @return {boolean} isListening
141
150
  *
142
- * @api public
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
- * @api public
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
- * @api public
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
- * @api public
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 {Boolean} options.associateModels
195
- * @param {Boolean} options.crashOnError
203
+ * @param {boolean} options.associateModels
204
+ * @param {boolean} options.crashOnError
196
205
  *
197
206
  * @return {sequilizeConnection.authenticate}
198
207
  *
199
- * @api public
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
- * @api public
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
- * @api public
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
- * @api public
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
- * @api public
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
- * @api public
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 {String} markerName
328
+ * @param {string} markerName
320
329
  *
321
- * @api public
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
- * @api public
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
- * @api public
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
- * @api public
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
- * @api public
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 {String} key
449
- * @param {Any} fnOrProperty
456
+ * @param {string} key
457
+ * @param {any} fnOrProperty
450
458
  *
451
- * @return {Any} fnOrProperty in Application
459
+ * @return {any} fnOrProperty in Application
452
460
  *
453
- * @api public
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
- * @api public
481
+ * @access public
474
482
  */
475
483
  stop() {
476
484
  if (this._isListening !== true) {
@@ -1,5 +1,5 @@
1
- /*!
2
- * /nodester
1
+ /**
2
+ * nodester
3
3
  * MIT Licensed
4
4
  */
5
5
 
@@ -12,20 +12,20 @@ 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
- * @api public
22
+ * @access public
23
23
  * @return {Object} filteredBody
24
24
  */
25
25
  function extract(body, filter=null, model) {
26
26
 
27
27
  const sequelize = model.sequelize;
28
- const modelFields = Object.keys(model.tableAttributes);
28
+ const modelAttributes = Object.keys(model.tableAttributes);
29
29
  const availableIncludes = Object.keys(model.associations);
30
30
 
31
31
  const bodyEntries = Object.entries(body);
@@ -38,15 +38,15 @@ function extract(body, filter=null, model) {
38
38
 
39
39
  for (const [key, value] of bodyEntries) {
40
40
  const isInclude = availableIncludes.indexOf(key) > -1;
41
- const isField = modelFields.indexOf(key) > -1;
41
+ const isAttribute = modelAttributes.indexOf(key) > -1;
42
42
 
43
- if ((!isField || filter.fields.indexOf(key) === -1) && !isInclude) {
44
- const err = new Error(`Field '${ key }' is not available.`);
43
+ if ((!isAttribute || filter.attributes.indexOf(key) === -1) && !isInclude) {
44
+ const err = new Error(`Attribute '${ key }' is not available.`);
45
45
  err.status = httpCodes.NOT_ACCEPTABLE;
46
46
  throw err;
47
47
  }
48
48
 
49
- if (isField) {
49
+ if (isAttribute) {
50
50
  const column = model.rawAttributes[key];
51
51
  const typeName = column.type.constructor.name;
52
52
  // Optional validation.
@@ -80,7 +80,7 @@ function extract(body, filter=null, model) {
80
80
  continue;
81
81
  }
82
82
 
83
- const err = new Error(`Unknown field '${ key }'.`);
83
+ const err = new Error(`Unknown attribute '${ key }'.`);
84
84
  err.status = httpCodes.NOT_ACCEPTABLE;
85
85
  throw err;
86
86
  }
@@ -1,5 +1,5 @@
1
- /*!
2
- * /nodester
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: _getOne,
11
- getMany: _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
- * @api public
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
- * @api public
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
- * @api public
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
- * @api public
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
- * @api public
182
+ * @access public
168
183
  */
169
184
  async function _deleteOne(req, res) {
170
185
  try {
@@ -1,5 +1,5 @@
1
- /*!
2
- * /nodester
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} options
44
- * @param {Function|Object} options.facade
45
- * @param {String} options.name
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
- * @api public
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
- * @api public
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 {Function|Object} facade
220
- * @param {String} facadeName
219
+ * @param {NodesterFacade} facade
220
+ * @param {string} facadeName
221
221
  *
222
222
  * @return {Function|Object} controller
223
223
  *
224
- * @api public
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 {Controller} controller
246
+ * @param {Function|Object} controller
247
247
  * @param {Function} fn
248
248
  *
249
- * @return {Controller} controller
249
+ * @return {Function|Object} controller
250
250
  *
251
- * @api public
251
+ * @access public
252
252
  * @alias setMethod
253
253
  */
254
254
  function _setMethod(controller, fn) {
@@ -1,10 +1,11 @@
1
- /*!
2
- * /nodester
1
+ /**
2
+ * nodester
3
3
  * MIT Licensed
4
4
  */
5
+
5
6
  'use strict';
6
7
 
7
- // ORM.
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
- function _buildConnection(opts={}) {
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 dbName = opts.name;
19
- const username = opts.username;
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: opts.host,
29
- port: opts.port,
30
- dialect: opts.dialect,
31
- pool: opts.pool,
32
- charset: opts.charset,
33
- collate: opts.collate,
34
- timestamps: opts.timestamps,
35
- logging: opts.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