express-sweet 2.0.8 → 2.0.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/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [2.0.9] - 2025/8/12
5
+
6
+ ### Added
7
+
8
+ - Added `getConfig()` method to Database class to retrieve the current database configuration object containing all sequelize options.
9
+
10
+ ### Changed
11
+
12
+ - Updated `multer` dependency from v1.4.5-lts.1 to v2.0.2 for improved file upload handling and security enhancements.
13
+
4
14
  ## [2.0.8] - 2025/7/29
5
15
 
6
16
  ### Changed
@@ -12,12 +22,12 @@ All notable changes to this project will be documented in this file.
12
22
  ### Changed
13
23
 
14
24
  - Updated dependencies to address vulnerabilities
15
- - `express`: 4.19.2 => 4.21.2
16
- - `express-session`: 1.18.0 => 1.18.2
17
- - `body-parser`: 1.19.0 => 2.2.0
18
- - `cookie-parser`: 1.4.4 => 1.4.7
19
- - `morgan`: 1.10.0 => 1.10.1
20
- - `rollup`: 4.21.2 => 4.45.1
25
+ - `express`: 4.19.2 => 4.21.2
26
+ - `express-session`: 1.18.0 => 1.18.2
27
+ - `body-parser`: 1.19.0 => 2.2.0
28
+ - `cookie-parser`: 1.4.4 => 1.4.7
29
+ - `morgan`: 1.10.0 => 1.10.1
30
+ - `rollup`: 4.21.2 => 4.45.1
21
31
 
22
32
  ## [2.0.6] - 2025/2/9
23
33
 
@@ -31,18 +41,18 @@ All notable changes to this project will be documented in this file.
31
41
 
32
42
  - Added a Handlebars helper, available for use in views, to replace HTML tags in a string.
33
43
 
34
- Example:
44
+ Example:
35
45
 
36
- ```html
37
- {{!-- results in: lorem ipsum dolor sit amet --}}
38
- {{{stripTags '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>'}}}
46
+ ```html
47
+ {{!-- results in: lorem ipsum dolor sit amet --}}
48
+ {{{stripTags '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>'}}}
39
49
 
40
- {{!-- results in: lorem ipsum <strong>dolor</strong> sit amet --}}
41
- {{{stripTags '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>' '<strong>' ''}}}
50
+ {{!-- results in: lorem ipsum <strong>dolor</strong> sit amet --}}
51
+ {{{stripTags '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>' '<strong>' ''}}}
42
52
 
43
- {{!-- results in: 🍩lorem ipsum 🍩dolor🍩 🍩sit🍩 amet🍩 --}}
44
- {{{stripTags '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>' [] '🍩'}}}
45
- ```
53
+ {{!-- results in: 🍩lorem ipsum 🍩dolor🍩 🍩sit🍩 amet🍩 --}}
54
+ {{{stripTags '<a href="https://example.com">lorem ipsum <strong>dolor</strong> <em>sit</em> amet</a>' [] '🍩'}}}
55
+ ```
46
56
 
47
57
  ## [2.0.4] - 2025/1/14
48
58
 
@@ -57,19 +67,19 @@ All notable changes to this project will be documented in this file.
57
67
 
58
68
  - **`findObjectInArray` Handlebars helper:** This helper is added to the view, allowing you to find an object in an array based on a specified field name and value.
59
69
 
60
- Example:
70
+ Example:
61
71
 
62
- ```html
63
- {{!--
64
- items is an array of objects: [{id: 123, name: 'Item A'}, {id: 456, name: 'Item B'}]
65
- This code will output: "Item A"
66
- --}}
67
- {{#each items}}
68
- {{#if (eq id 123)}}
69
- {{lookup (findObjectInArray ../items 'id' id) 'name'}}
70
- {{/if}}
71
- {{/each}}
72
- ```
72
+ ```html
73
+ {{!--
74
+ items is an array of objects: [{id: 123, name: 'Item A'}, {id: 456, name: 'Item B'}]
75
+ This code will output: "Item A"
76
+ --}}
77
+ {{#each items}}
78
+ {{#if (eq id 123)}}
79
+ {{lookup (findObjectInArray ../items 'id' id) 'name'}}
80
+ {{/if}}
81
+ {{/each}}
82
+ ```
73
83
 
74
84
  ## [2.0.3] - 2024/9/3
75
85
 
@@ -78,7 +88,7 @@ All notable changes to this project will be documented in this file.
78
88
  - Add `"type": "module"` to the `package.json` of the esm app generated by `express-sweet-generator`. It is fully esm compliant.
79
89
  - `require` was changed to dynamic import.
80
90
  - Template engine changed from `express-hbs` to `express-handlebars`.
81
- However, the `block` and `contentFor` helpers are still available.
91
+ However, the `block` and `contentFor` helpers are still available.
82
92
  - `database/Database` has been changed from a `sequelize.Sequelize` instance to a `sequelize.Sequelize` class. If you use it in the future, you need to instantiate it.
83
93
  - Return type of `mount()` changed from `void` to `Promise<void>`.
84
94
  - Return type of `middlewares/CORS.mount()` changed from `void` to `Promise<void>`.
@@ -99,24 +109,24 @@ All notable changes to this project will be documented in this file.
99
109
  - Return type of `database/Model.initialize()` changed from `typeof Model` to `Promise<typeof Model>`.
100
110
  - Return type of `database/loadModels()` changed from `void` to `Promise<void>`.
101
111
  - DB connection check method has been changed.
102
- - After:
103
- ```js
104
- const expressExtension = require('express-sweet');
105
-
106
- // Create Database instance.
107
- const config = await expressExtension.utils.loadDatabaseConfig();
108
- const database = new expressExtension.database.Database(config.database, config.username, config.password, config);
109
-
110
- // Check database connection.
111
- await database.isConnect();
112
- ```
113
- - Before:
114
- ```js
115
- const expressExtension = require('express-sweet');
116
-
117
- // Check database connection.
118
- await expressExtension.database.Database.isConnect();
119
- ```
112
+ - After:
113
+ ```js
114
+ const expx = require('express-sweet');
115
+
116
+ // Create Database instance.
117
+ const config = await expx.utils.loadDatabaseConfig();
118
+ const database = new expx.database.Database(config.database, config.username, config.password, config);
119
+
120
+ // Check database connection.
121
+ await database.isConnect();
122
+ ```
123
+ - Before:
124
+ ```js
125
+ const expx = require('express-sweet');
126
+
127
+ // Check database connection.
128
+ await expx.database.Database.isConnect();
129
+ ```
120
130
  - Update passport from 0.4.1 to 0.7.0
121
131
 
122
132
  ## [2.0.2] - 2024/9/1
@@ -139,7 +149,7 @@ All notable changes to this project will be documented in this file.
139
149
  ### Changed
140
150
 
141
151
  - EXPRESS SWEET version 2 no longer depends on the AWS SDK.
142
- The `services.AWSRekognitionClient` and `services.AWSSesClient` have been migrated to the [AWS SDK Extension](https://www.npmjs.com/package/aws-sdk-extension) NPM package, so please install from there if needed.
152
+ The `services.AWSRekognitionClient` and `services.AWSSesClient` have been migrated to the [AWS SDK Extension](https://www.npmjs.com/package/aws-sdk-extension) NPM package, so please install from there if needed.
143
153
 
144
154
  ## [1.1.1] - 2024/3/23
145
155
 
@@ -155,12 +165,12 @@ All notable changes to this project will be documented in this file.
155
165
  ### Changed
156
166
 
157
167
  - Updated EXPRESS SWEET's dependency packages.
158
- - [express](https://www.npmjs.com/package/express) from v4.18.2 to v4.18.3
159
- - [multer](https://www.npmjs.com/package/multer) from v1.4.4 to v1.4.5-lts.1
160
- - [express-session](https://www.npmjs.com/package/express-session) from v1.17.3 to v1.18.0
161
- - [sequelize](https://www.npmjs.com/package/sequelize) from v6.32.0 to v6.37.1
162
- - [mariadb](https://www.npmjs.com/package/mariadb) from v2.4.0 to v3.2.3
163
- - [moment](https://www.npmjs.com/package/moment) from v2.29.4 to v2.30.1
168
+ - [express](https://www.npmjs.com/package/express) from v4.18.2 to v4.18.3
169
+ - [multer](https://www.npmjs.com/package/multer) from v1.4.4 to v1.4.5-lts.1
170
+ - [express-session](https://www.npmjs.com/package/express-session) from v1.17.3 to v1.18.0
171
+ - [sequelize](https://www.npmjs.com/package/sequelize) from v6.32.0 to v6.37.1
172
+ - [mariadb](https://www.npmjs.com/package/mariadb) from v2.4.0 to v3.2.3
173
+ - [moment](https://www.npmjs.com/package/moment) from v2.29.4 to v2.30.1
164
174
 
165
175
  ## [1.0.44] - 2023/12/30
166
176
 
@@ -180,10 +190,10 @@ All notable changes to this project will be documented in this file.
180
190
 
181
191
  - Update TypeScript version from 4.8.4 to 5.2.2.
182
192
  - Update redis dependency package used for user authentication.
183
- - Updated redis package version from 4.3.1 to 4.6.8.
184
- [Here](https://github.com/redis/node-redis/blob/master/CHANGELOG.md) are the changes.
185
- - Updated connect-redis package version from 6.1.3 to 7.1.0.
186
- [Here](https://github.com/tj/connect-redis/releases) are the changes.
193
+ - Updated redis package version from 4.3.1 to 4.6.8.
194
+ [Here](https://github.com/redis/node-redis/blob/master/CHANGELOG.md) are the changes.
195
+ - Updated connect-redis package version from 6.1.3 to 7.1.0.
196
+ [Here](https://github.com/tj/connect-redis/releases) are the changes.
187
197
 
188
198
 
189
199
  ## [1.0.41] - 2023/8/4
@@ -203,73 +213,73 @@ All notable changes to this project will be documented in this file.
203
213
  ### Changed
204
214
 
205
215
  - Changed exception class name.
206
- <table>
207
- <thead>
208
- <tr>
209
- <th>Before Class Name</th>
210
- <th>After class name</th>
211
- <th>Instance member</th>
212
- <th>Description</th>
213
- </tr>
214
- </thead>
215
- <tbody>
216
- <tr>
217
- <td>CollectionCreationError</td>
218
- <td>FaceCollectionCreateFailed</td>
219
- <td>
220
- <ul>
221
- <li>name: Error Name.</li>
222
- <li>collectionId: Collection ID.</li>
223
- <li>httpStatusCode: HTTP status code.</li>
224
- </ul>
225
- </td>
226
- <td>Thrown when face collection creation (<code>AWSRekognitionClient.createCollection()</code>) fails.</td>
227
- </tr>
228
- <tr>
229
- <td>CollectionDeletionError</td>
230
- <td>FaceCollectionDeleteFailed</td>
231
- <td>
232
- <ul>
233
- <li>name: Error Name.</li>
234
- <li>collectionId: Collection ID.</li>
235
- <li>httpStatusCode: HTTP status code.</li>
236
- </ul>
237
- </td>
238
- <td>Thrown when deleting a face collection (<code>AWSRekognitionClient.deleteCollection()</code>) fails.</td>
239
- </tr>
240
- <tr>
241
- <td>FaceIndexError</td>
242
- <td>FaceIndexFailed</td>
243
- <td>
244
- <ul>
245
- <li>name: Error Name.</li>
246
- <li>collectionId: Collection ID.</li>
247
- </ul>
248
- </td>
249
- <td>Thrown when face indexing (<code>AWSRekognitionClient.indexFace()</code>) fails.</td>
250
- </tr>
251
- <tr>
252
- <td>MissingFaceInImageError</td>
253
- <td>FaceMissingInPhoto</td>
254
- <td>
255
- <ul>
256
- <li>name: Error Name.</li>
257
- </ul>
258
- </td>
259
- <td>Thrown if the face to index (<code>AWSRekognitionClient.indexFace()</code>) is not in the photo.</td>
260
- </tr>
261
- <tr>
262
- <td>MultipleFacesInImageError</td>
263
- <td>FacesMultipleInPhoto</td>
264
- <td>
265
- <ul>
266
- <li>name: Error Name.</li>
267
- </ul>
268
- </td>
269
- <td>Thrown when there are multiple faces to index (<code>AWSRekognitionClient.indexFace()</code>) in a photo.</td>
270
- </tr>
271
- </tbody>
272
- </table>
216
+ <table>
217
+ <thead>
218
+ <tr>
219
+ <th>Before Class Name</th>
220
+ <th>After class name</th>
221
+ <th>Instance member</th>
222
+ <th>Description</th>
223
+ </tr>
224
+ </thead>
225
+ <tbody>
226
+ <tr>
227
+ <td>CollectionCreationError</td>
228
+ <td>FaceCollectionCreateFailed</td>
229
+ <td>
230
+ <ul>
231
+ <li>name: Error Name.</li>
232
+ <li>collectionId: Collection ID.</li>
233
+ <li>httpStatusCode: HTTP status code.</li>
234
+ </ul>
235
+ </td>
236
+ <td>Thrown when face collection creation (<code>AWSRekognitionClient.createCollection()</code>) fails.</td>
237
+ </tr>
238
+ <tr>
239
+ <td>CollectionDeletionError</td>
240
+ <td>FaceCollectionDeleteFailed</td>
241
+ <td>
242
+ <ul>
243
+ <li>name: Error Name.</li>
244
+ <li>collectionId: Collection ID.</li>
245
+ <li>httpStatusCode: HTTP status code.</li>
246
+ </ul>
247
+ </td>
248
+ <td>Thrown when deleting a face collection (<code>AWSRekognitionClient.deleteCollection()</code>) fails.</td>
249
+ </tr>
250
+ <tr>
251
+ <td>FaceIndexError</td>
252
+ <td>FaceIndexFailed</td>
253
+ <td>
254
+ <ul>
255
+ <li>name: Error Name.</li>
256
+ <li>collectionId: Collection ID.</li>
257
+ </ul>
258
+ </td>
259
+ <td>Thrown when face indexing (<code>AWSRekognitionClient.indexFace()</code>) fails.</td>
260
+ </tr>
261
+ <tr>
262
+ <td>MissingFaceInImageError</td>
263
+ <td>FaceMissingInPhoto</td>
264
+ <td>
265
+ <ul>
266
+ <li>name: Error Name.</li>
267
+ </ul>
268
+ </td>
269
+ <td>Thrown if the face to index (<code>AWSRekognitionClient.indexFace()</code>) is not in the photo.</td>
270
+ </tr>
271
+ <tr>
272
+ <td>MultipleFacesInImageError</td>
273
+ <td>FacesMultipleInPhoto</td>
274
+ <td>
275
+ <ul>
276
+ <li>name: Error Name.</li>
277
+ </ul>
278
+ </td>
279
+ <td>Thrown when there are multiple faces to index (<code>AWSRekognitionClient.indexFace()</code>) in a photo.</td>
280
+ </tr>
281
+ </tbody>
282
+ </table>
273
283
 
274
284
  ## [1.0.38] - 2023/7/17
275
285
 
@@ -324,14 +334,14 @@ All notable changes to this project will be documented in this file.
324
334
  ### Changed
325
335
 
326
336
  - Changed helper function names in the view (Handlebars) from SnakeCase to CamelCase.
327
- |After|Before|Description|
328
- |--|--|--|
329
- |notEmpty|not_empty|Check that it is not empty.|
330
- |formatDate|format_date|Use moment to format the date.|
331
- |cacheBusting|cache_busting|Returns the Assets path containing the file update time parameter.|
332
- |jsonStringify|json_stringify|Stringify an object using JSON.stringify.|
333
- |jsonParse|json_parse|Parses the given string using JSON.parse.|
334
- |formatBytes|format_bytes|Convert bytes to just the right units(KB, MB, GB, TB, PB, EB, ZB, YB).|
337
+ |After|Before|Description|
338
+ |--|--|--|
339
+ |notEmpty|not_empty|Check that it is not empty.|
340
+ |formatDate|format_date|Use moment to format the date.|
341
+ |cacheBusting|cache_busting|Returns the Assets path containing the file update time parameter.|
342
+ |jsonStringify|json_stringify|Stringify an object using JSON.stringify.|
343
+ |jsonParse|json_parse|Parses the given string using JSON.parse.|
344
+ |formatBytes|format_bytes|Convert bytes to just the right units(KB, MB, GB, TB, PB, EB, ZB, YB).|
335
345
 
336
346
  ### Added
337
347
 
@@ -371,10 +381,10 @@ All notable changes to this project will be documented in this file.
371
381
 
372
382
  - Update Sequelize from v5 to v6.
373
383
  - Changed the framework debug log to output only when the environment variable EXPRESS_DEBUG is defined.
374
- .env:
375
- ```
376
- EXPRESS_DEBUG=true
377
- ```
384
+ .env:
385
+ ```
386
+ EXPRESS_DEBUG=true
387
+ ```
378
388
 
379
389
  ## [1.0.25] - 2022/11/24
380
390
 
@@ -423,11 +433,11 @@ All notable changes to this project will be documented in this file.
423
433
  ### Added
424
434
 
425
435
  - User authentication sessions can now be stored in redis. To use redis for session storage, simply add the following option to config/authentication.js. Please give it a try.
426
- config/authentication.js:
427
- ```json
428
- session_store: 'redis',
429
- redis_host: 'redis://localhost:6379'
430
- ```
436
+ config/authentication.js:
437
+ ```json
438
+ session_store: 'redis',
439
+ redis_host: 'redis://localhost:6379'
440
+ ```
431
441
 
432
442
  ## [1.0.17] - 2022/5/17
433
443
 
@@ -458,40 +468,40 @@ All notable changes to this project will be documented in this file.
458
468
  ### Added
459
469
 
460
470
  - The model's begin method now accepts the transaction option.
461
- ```js
462
- let transaction;
463
- try {
464
- transaction = await BookModel.begin({
465
- isolationLevel: BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
466
- type: BookModel.Transaction.TYPES.DEFERRED,
467
- });
468
- const book = await BookModel.findOne({where: {id: 1}}, {transaction});
469
- book.title = 'When Im Gone';
470
- await book.save({transaction});
471
- await transaction.commit();
472
-
473
- // Load updated data.
474
- await book.reload();
475
- } catch (error) {
476
- if (transaction)
477
- await transaction.rollback();
478
- }
479
- ```
471
+ ```js
472
+ let transaction;
473
+ try {
474
+ transaction = await BookModel.begin({
475
+ isolationLevel: BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
476
+ type: BookModel.Transaction.TYPES.DEFERRED,
477
+ });
478
+ const book = await BookModel.findOne({where: {id: 1}}, {transaction});
479
+ book.title = 'When Im Gone';
480
+ await book.save({transaction});
481
+ await transaction.commit();
482
+
483
+ // Load updated data.
484
+ await book.reload();
485
+ } catch (error) {
486
+ if (transaction)
487
+ await transaction.rollback();
488
+ }
489
+ ```
480
490
 
481
491
  ## [1.0.12] - 2021/11/16
482
492
 
483
493
  ### Added
484
494
 
485
495
  - Added a method to the model that can execute raw SQL. As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can use the Model.query method.
486
- ```js
487
- // By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).
488
- // Note that since this is a raw query, the metadata are dialect specific.
489
- const [results, metadata] = await BookModel.query("UPDATE book SET title = 'When Im Gone' WHERE id = 1");
496
+ ```js
497
+ // By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).
498
+ // Note that since this is a raw query, the metadata are dialect specific.
499
+ const [results, metadata] = await BookModel.query("UPDATE book SET title = 'When Im Gone' WHERE id = 1");
490
500
 
491
- // In cases where you don't need to access the metadata you can pass in a query type to tell sequelize how to format the results. For example, for a simple select query you could do:
492
- // We didn't need to destructure the result here - the results were returned directly
493
- const users = await BookModel.query("SELECT * FROM book", {type: BookModel.QueryTypes.SELECT});
494
- ```
501
+ // In cases where you don't need to access the metadata you can pass in a query type to tell sequelize how to format the results. For example, for a simple select query you could do:
502
+ // We didn't need to destructure the result here - the results were returned directly
503
+ const users = await BookModel.query("SELECT * FROM book", {type: BookModel.QueryTypes.SELECT});
504
+ ```
495
505
 
496
506
  ## [1.0.11] - 2021/11/10
497
507
 
@@ -548,10 +558,10 @@ All notable changes to this project will be documented in this file.
548
558
  ### Changed
549
559
 
550
560
  - Change the current URL path of a local variable.app.locals.currentPath is a USVString containing an initial '/' followed by the path of the URL not including the query string or fragment.
551
- ```js
552
- // For example, when the current URL is "https://example.com/docs/api?q=value", "/docs/api" is set for "app.locals.currentPath".
553
- console.log(app.locals.currentPath);
554
- ```
561
+ ```js
562
+ // For example, when the current URL is "https://example.com/docs/api?q=value", "/docs/api" is set for "app.locals.currentPath".
563
+ console.log(app.locals.currentPath);
564
+ ```
555
565
 
556
566
  ## [1.0.2] - 2021//6/10
557
567
 
@@ -623,4 +633,6 @@ All notable changes to this project will be documented in this file.
623
633
  [2.0.4]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.3...v2.0.4
624
634
  [2.0.5]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.4...v2.0.5
625
635
  [2.0.6]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.5...v2.0.6
626
- [2.0.7]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.6...v2.0.7
636
+ [2.0.7]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.6...v2.0.7
637
+ [2.0.8]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.7...v2.0.8
638
+ [2.0.9]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.8...v2.0.9
package/README.md CHANGED
@@ -1173,9 +1173,9 @@ To take advantage of EXPRESS SWEET’s model, you would simply create a new mode
1173
1173
  This class provides convenient access to the database connection, the Query Builder, and a number of additional convenience methods.
1174
1174
  For more information, see [reference](#model-class).
1175
1175
  ```js
1176
- import * as expressExtension from 'express-sweet';
1176
+ import * as expx from 'express-sweet';
1177
1177
 
1178
- export default class extends expressExtension.database.Model {
1178
+ export default class extends expx.database.Model {
1179
1179
  static get table() {
1180
1180
  return 'user';
1181
1181
  }
@@ -1216,15 +1216,32 @@ For more information on database configuration, see [Database configuration](#co
1216
1216
  `Promise<boolean>` Returns `true` if it can connect to the database, `false` if it cannot.
1217
1217
 
1218
1218
  ```js
1219
- import * as expressExtension from 'express-sweet';
1219
+ import * as expx from 'express-sweet';
1220
1220
 
1221
1221
  // Create Database instance.
1222
- const config = await expressExtension.utils.loadDatabaseConfig();
1223
- const database = new expressExtension.database.Database(config.database, config.username, config.password, config);
1222
+ const config = await expx.utils.loadDatabaseConfig();
1223
+ const database = new expx.database.Database(config.database, config.username, config.password, config);
1224
1224
 
1225
1225
  // Check database connection.
1226
1226
  await database.isConnect();
1227
1227
  ```
1228
+ - `public getConfig()`
1229
+ Returns the current database configuration object containing all sequelize options.
1230
+
1231
+ **Return:**
1232
+ `object` Database configuration object containing all sequelize options.
1233
+
1234
+ ```js
1235
+ import * as expx from 'express-sweet';
1236
+
1237
+ // Create Database instance.
1238
+ const config = await expx.utils.loadDatabaseConfig();
1239
+ const database = new expx.database.Database(config.database, config.username, config.password, config);
1240
+
1241
+ // Get database configuration.
1242
+ const currentConfig = database.getConfig();
1243
+ console.log(currentConfig);
1244
+ ```
1228
1245
 
1229
1246
  #### Model Class extends [sequelize.Model](https://sequelize.org/api/v6/class/src/model.js~model)
1230
1247
  This is a class that abstracts the tables in the database.
@@ -1234,9 +1251,9 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1234
1251
  - `protected static table: string`
1235
1252
  The name of the table that the model accesses. This member must be defined in a subclass.
1236
1253
  ```js
1237
- import * as expressExtension from 'express-sweet';
1254
+ import * as expx from 'express-sweet';
1238
1255
 
1239
- export default class extends expressExtension.database.Model {
1256
+ export default class extends expx.database.Model {
1240
1257
  static get table() {
1241
1258
  return 'user';
1242
1259
  }
@@ -1245,9 +1262,9 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1245
1262
  - `protected static attributes: sequelize.ModelAttributes`
1246
1263
  List of columns in the table accessed by this model. This member must be defined in a subclass.
1247
1264
  ```js
1248
- import * as expressExtension from 'express-sweet';
1265
+ import * as expx from 'express-sweet';
1249
1266
 
1250
- export default class extends expressExtension.database.Model {
1267
+ export default class extends expx.database.Model {
1251
1268
  static get attributes() {
1252
1269
  return {
1253
1270
  id: {
@@ -1383,10 +1400,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1383
1400
  See the [here](https://sequelize.org/api/v6/class/src/associations/base.js~association) for more information.
1384
1401
  If you omit the alias (`as`) option, the associated name will be hasOne, singular for belongsTo, and plural for hasMany.
1385
1402
  ```js
1386
- import * as expressExtension from 'express-sweet';
1403
+ import * as expx from 'express-sweet';
1387
1404
  import ProfileModel from './ProfileModel';
1388
1405
 
1389
- export default class extends expressExtension.database.Model {
1406
+ export default class extends expx.database.Model {
1390
1407
  static association() {
1391
1408
  // User has one profile.
1392
1409
  this.hasOne(ProfileModel, {
@@ -1629,10 +1646,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1629
1646
 
1630
1647
  This is a user model that defines an association in which the user has one profile.
1631
1648
  ```js
1632
- import * as expressExtension from 'express-sweet';
1649
+ import * as expx from 'express-sweet';
1633
1650
  import ProfileModel from './ProfileModel';
1634
1651
 
1635
- export default class extends expressExtension.database.Model {
1652
+ export default class extends expx.database.Model {
1636
1653
  static association() {
1637
1654
  // User has one profile.
1638
1655
  this.hasOne(ProfileModel, {
@@ -1707,10 +1724,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1707
1724
 
1708
1725
  This is a profile model that defines an association whose profile belongs to one user.
1709
1726
  ```js
1710
- import * as expressExtension from 'express-sweet';
1727
+ import * as expx from 'express-sweet';
1711
1728
  import UserModel from './UserModel';
1712
1729
 
1713
- export default class extends expressExtension.database.Model {
1730
+ export default class extends expx.database.Model {
1714
1731
  static association() {
1715
1732
  // Profile belongs to one user.
1716
1733
  this.belongsTo(UserModel, {
@@ -1784,10 +1801,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1784
1801
 
1785
1802
  This is a user model that defines an association in which the user has many comments.
1786
1803
  ```js
1787
- import * as expressExtension from 'express-sweet';
1804
+ import * as expx from 'express-sweet';
1788
1805
  import CommentModel from './CommentModel';
1789
1806
 
1790
- export default class extends expressExtension.database.Model {
1807
+ export default class extends expx.database.Model {
1791
1808
  static association() {
1792
1809
  // User has many comments.
1793
1810
  this.hasMany(CommentModel, {
@@ -1919,10 +1936,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1919
1936
 
1920
1937
  This is a user model that defines an association where users and books have a many-to-many relationship.
1921
1938
  ```js
1922
- import * as expressExtension from 'express-sweet';
1939
+ import * as expx from 'express-sweet';
1923
1940
  import BookModel from './BookModel';
1924
1941
 
1925
- export default class extends expressExtension.database.Model {
1942
+ export default class extends expx.database.Model {
1926
1943
  static association() {
1927
1944
  // Users have many books, and books belong to many users.
1928
1945
  this.belongsToMany(BookModel, {
@@ -2151,11 +2168,11 @@ The post-authentication logic depends on whether the login request is received a
2151
2168
  If you redirect to /, the page will automatically switch to the URL specified in `success_redirect` of `config/authentication.js`.
2152
2169
  ```js
2153
2170
  import {Router} from 'express';
2154
- import * as expressExtension from 'express-sweet';
2171
+ import * as expx from 'express-sweet';
2155
2172
 
2156
2173
  const router = Router();
2157
2174
  router.post('/login', async (req, res, next) => {
2158
- const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
2175
+ const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
2159
2176
  res.json(isAuthenticated);
2160
2177
  });
2161
2178
  export default router;
@@ -2185,15 +2202,15 @@ The post-authentication logic depends on whether the login request is received a
2185
2202
  If it fails, redirect to the page with the URL specified by `failure_redirect` in `config/authentication.js`.
2186
2203
  ```js
2187
2204
  import {Router} from 'express';
2188
- import * as expressExtension from 'express-sweet';
2205
+ import * as expx from 'express-sweet';
2189
2206
 
2190
2207
  const router = Router();
2191
2208
  router.post('/login', async (req, res, next) => {
2192
- const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
2209
+ const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
2193
2210
  if (isAuthenticated)
2194
- await expressExtension.services.Authentication.successRedirect(res);
2211
+ await expx.services.Authentication.successRedirect(res);
2195
2212
  else
2196
- await expressExtension.services.Authentication.failureRedirect(req, res);
2213
+ await expx.services.Authentication.failureRedirect(req, res);
2197
2214
  });
2198
2215
  export default router;
2199
2216
  ```
@@ -2212,11 +2229,11 @@ If you want to log out the user, call the `services/Authentication.logout()` met
2212
2229
  Invoking `logout()` will remove the `req.user` property and clear the login session (if any).
2213
2230
  ```js
2214
2231
  import {Router} from 'express';
2215
- import * as expressExtension from 'express-sweet';
2232
+ import * as expx from 'express-sweet';
2216
2233
 
2217
2234
  const router = Router();
2218
2235
  router.get('/logout', (req, res) => {
2219
- expressExtension.services.Authentication.logout(req);
2236
+ expx.services.Authentication.logout(req);
2220
2237
  res.redirect('/');
2221
2238
  });
2222
2239
  export default router;