express-sweet 2.0.9 → 3.0.0

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 (69) hide show
  1. package/CHANGELOG.md +60 -1
  2. package/README.md +1039 -2137
  3. package/configuration_sample/cjs/authentication.js +50 -15
  4. package/configuration_sample/cjs/config.js +38 -21
  5. package/configuration_sample/cjs/logging.js +41 -0
  6. package/configuration_sample/cjs/view.js +19 -1
  7. package/configuration_sample/esm/authentication.js +48 -15
  8. package/configuration_sample/esm/config.js +39 -22
  9. package/configuration_sample/esm/logging.js +41 -0
  10. package/configuration_sample/esm/view.js +20 -2
  11. package/dist/build.cjs +8 -8
  12. package/dist/build.mjs +4 -4
  13. package/package.json +9 -4
  14. package/types/database/DatabaseManager.d.ts +95 -0
  15. package/types/database/Model.d.ts +183 -20
  16. package/types/database/index.d.ts +47 -3
  17. package/types/database/loadModels.d.ts +19 -4
  18. package/types/handlebars_helpers/array.d.ts +3 -1
  19. package/types/handlebars_helpers/comparison.d.ts +55 -19
  20. package/types/handlebars_helpers/date.d.ts +3 -1
  21. package/types/handlebars_helpers/html.d.ts +6 -2
  22. package/types/handlebars_helpers/index.d.ts +73 -9
  23. package/types/handlebars_helpers/layouts.d.ts +5 -1
  24. package/types/handlebars_helpers/math.d.ts +21 -7
  25. package/types/handlebars_helpers/number.d.ts +3 -1
  26. package/types/handlebars_helpers/object.d.ts +6 -2
  27. package/types/handlebars_helpers/string.d.ts +9 -3
  28. package/types/index.d.ts +92 -5
  29. package/types/interfaces/AuthenticationConfig.d.ts +38 -1
  30. package/types/interfaces/BasicConfig.d.ts +26 -1
  31. package/types/interfaces/DatabaseConfig.d.ts +45 -1
  32. package/types/interfaces/LoggingConfig.d.ts +49 -0
  33. package/types/interfaces/ViewConfig.d.ts +21 -2
  34. package/types/interfaces/index.d.ts +25 -11
  35. package/types/middlewares/Authentication.d.ts +43 -6
  36. package/types/middlewares/CORS.d.ts +23 -5
  37. package/types/middlewares/Environment.d.ts +30 -4
  38. package/types/middlewares/ErrorHandler.d.ts +27 -5
  39. package/types/middlewares/Global.d.ts +20 -6
  40. package/types/middlewares/Http.d.ts +22 -5
  41. package/types/middlewares/Local.d.ts +35 -8
  42. package/types/middlewares/View.d.ts +39 -8
  43. package/types/middlewares/index.d.ts +47 -7
  44. package/types/mount.d.ts +16 -3
  45. package/types/routing/Router.d.ts +49 -7
  46. package/types/routing/index.d.ts +37 -1
  47. package/types/services/Authentication.d.ts +79 -16
  48. package/types/services/index.d.ts +33 -1
  49. package/types/types/global.d.ts +29 -8
  50. package/types/utils/Types.d.ts +5 -3
  51. package/types/utils/index.d.ts +71 -9
  52. package/types/utils/isArray.d.ts +12 -3
  53. package/types/utils/isAsyncFunction.d.ts +12 -5
  54. package/types/utils/isFunction.d.ts +13 -6
  55. package/types/utils/isObject.d.ts +14 -3
  56. package/types/utils/isString.d.ts +15 -4
  57. package/types/utils/loadAuthenticationConfig.d.ts +13 -3
  58. package/types/utils/loadBasicConfig.d.ts +13 -3
  59. package/types/utils/loadDatabaseConfig.d.ts +34 -3
  60. package/types/utils/loadLoggingConfig.d.ts +16 -0
  61. package/types/utils/loadViewConfig.d.ts +28 -3
  62. package/types/database/Database.d.ts +0 -18
  63. package/types/interfaces/BoundingBox.d.ts +0 -25
  64. package/types/interfaces/FaceDetails.d.ts +0 -30
  65. package/types/interfaces/FaceDetailsEmotions.d.ts +0 -40
  66. package/types/interfaces/FaceMatch.d.ts +0 -31
  67. package/types/interfaces/IndexFaceDetails.d.ts +0 -29
  68. package/types/interfaces/RekognitionOptions.d.ts +0 -26
  69. package/types/interfaces/SesOptions.d.ts +0 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet",
3
- "version": "2.0.9",
3
+ "version": "3.0.0",
4
4
  "description": "EXPRESS SWEET is a powerful Express.js extension that streamlines your workflow and boosts productivity with a suite of utilities and enhancements.",
5
5
  "type": "module",
6
6
  "main": "dist/build.cjs",
@@ -26,7 +26,11 @@
26
26
  "build": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js",
27
27
  "prebuild": "rm -rf dist types",
28
28
  "prewatch": "rm -rf dist types",
29
- "watch": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js --watch"
29
+ "watch": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js --watch",
30
+ "docs:build": "typedoc",
31
+ "docs:clean": "rm -rf docs",
32
+ "docs:watch": "typedoc --watch",
33
+ "docs:serve": "typedoc && npx serve docs -p 8080"
30
34
  },
31
35
  "repository": {
32
36
  "type": "git",
@@ -57,7 +61,7 @@
57
61
  "postgres",
58
62
  "mssql"
59
63
  ],
60
- "author": "Takuya Motoshima <developer.takuyamotoshima@gmail.com> (https://twitter.com/TakuyaMotoshima)",
64
+ "author": "Takuya Motoshima <developer.takuyamotoshima@gmail.com> (https://x.com/takuya_motech)",
61
65
  "license": "MIT",
62
66
  "bugs": {
63
67
  "url": "https://github.com/takuya-motoshima/express-sweet/issues",
@@ -81,7 +85,7 @@
81
85
  "passport": "^0.7.0",
82
86
  "passport-local": "^1.0.0",
83
87
  "redis": "^4.6.8",
84
- "sequelize": "^6.37.1",
88
+ "sequelize": "^6.37.7",
85
89
  "striptags": "^3.2.0"
86
90
  },
87
91
  "devDependencies": {
@@ -101,6 +105,7 @@
101
105
  "@types/passport-local": "^1.0.33",
102
106
  "rollup": "^4.45.1",
103
107
  "rollup-plugin-typescript2": "^0.36.0",
108
+ "typedoc": "^0.28.11",
104
109
  "typescript": "^5.5.4"
105
110
  }
106
111
  }
@@ -0,0 +1,95 @@
1
+ import sequelize from 'sequelize';
2
+ /**
3
+ * Database manager class for handling Sequelize database connections.
4
+ * Implements singleton pattern to ensure single database connection across the application.
5
+ * @example
6
+ * ```js
7
+ * // Get database instance
8
+ * const db = await DatabaseManager.getInstance();
9
+ *
10
+ * // Check connection
11
+ * const isConnected = await DatabaseManager.isConnected();
12
+ *
13
+ * // Get configuration
14
+ * const config = await DatabaseManager.getConfig();
15
+ * ```
16
+ */
17
+ export default class DatabaseManager {
18
+ /**
19
+ * Singleton Sequelize instance
20
+ */
21
+ private static instance;
22
+ /**
23
+ * Cached database configuration
24
+ */
25
+ private static config;
26
+ /**
27
+ * Gets the singleton Sequelize database instance.
28
+ * Creates a new instance on first call, returns cached instance on subsequent calls.
29
+ * @returns {Promise<sequelize.Sequelize>} The Sequelize database instance
30
+ * @throws {Error} When database configuration loading fails
31
+ * @example
32
+ * ```js
33
+ * const sequelize = await DatabaseManager.getInstance();
34
+ * const users = await sequelize.models.User.findAll();
35
+ * ```
36
+ */
37
+ static getInstance(): Promise<sequelize.Sequelize>;
38
+ /**
39
+ * Tests the database connection.
40
+ * @returns {Promise<boolean>} Returns true if connection is successful, false otherwise
41
+ * @example
42
+ * ```js
43
+ * const canConnect = await DatabaseManager.isConnected();
44
+ * if (canConnect) {
45
+ * console.log('Database is accessible');
46
+ * } else {
47
+ * console.error('Cannot connect to database');
48
+ * }
49
+ * ```
50
+ */
51
+ static isConnected(): Promise<boolean>;
52
+ /**
53
+ * Gets the original database configuration loaded from config files.
54
+ * This returns the raw configuration before Sequelize processing.
55
+ * @returns {Promise<object>} Database configuration object containing all loaded options
56
+ * @throws {Error} When configuration loading fails
57
+ * @see {@link https://sequelize.org/docs/v6/other-topics/dialect-specific-things/ | Sequelize Dialect Options}
58
+ * @example
59
+ * ```js
60
+ * const config = await DatabaseManager.getConfig();
61
+ * console.log('Database name:', config.database);
62
+ * console.log('Host:', config.host);
63
+ * console.log('Port:', config.port);
64
+ * ```
65
+ */
66
+ static getConfig(): Promise<object>;
67
+ /**
68
+ * Gets the runtime Sequelize options after initialization.
69
+ * This returns the actual options used by the Sequelize instance,
70
+ * which may include defaults and processed values.
71
+ * @returns {Promise<object>} Sequelize runtime options object
72
+ * @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#instance-constructor-options | Sequelize Constructor Options}
73
+ * @example
74
+ * ```js
75
+ * const options = await DatabaseManager.getSequelizeOptions();
76
+ * console.log('Connection pool settings:', options.pool);
77
+ * console.log('Dialect:', options.dialect);
78
+ * ```
79
+ */
80
+ static getSequelizeOptions(): Promise<object>;
81
+ /**
82
+ * Closes the database connection and resets the singleton instance.
83
+ * Useful for testing or graceful application shutdown.
84
+ * @returns {Promise<void>}
85
+ * @example
86
+ * ```js
87
+ * // Graceful shutdown
88
+ * process.on('SIGTERM', async () => {
89
+ * await DatabaseManager.close();
90
+ * process.exit(0);
91
+ * });
92
+ * ```
93
+ */
94
+ static close(): Promise<void>;
95
+ }
@@ -1,30 +1,119 @@
1
1
  import sequelize from 'sequelize';
2
- import Database from '~/database/Database';
2
+ declare const Model_base: any;
3
3
  /**
4
- * Model base class.
4
+ * Model base class that extends Sequelize.Model for database operations.
5
+ * This is a class that abstracts the tables in the database and provides
6
+ * convenient access to the database connection, Query Builder, and additional methods.
7
+ *
8
+ * @extends {sequelize.Model}
9
+ * @see {@link https://sequelize.org/api/v6/class/src/model.js~model | Sequelize Model}
10
+ * @example
11
+ * ```js
12
+ * // Creating a custom model
13
+ * import * as expx from 'express-sweet';
14
+ *
15
+ * export default class extends expx.database.Model {
16
+ * static get table() {
17
+ * return 'user';
18
+ * }
19
+ *
20
+ * static get attributes() {
21
+ * return {
22
+ * id: {
23
+ * type: this.DataTypes.INTEGER,
24
+ * primaryKey: true,
25
+ * autoIncrement: true
26
+ * },
27
+ * name: this.DataTypes.STRING,
28
+ * email: this.DataTypes.STRING,
29
+ * password: this.DataTypes.STRING,
30
+ * icon: this.DataTypes.STRING,
31
+ * created: this.DataTypes.DATE,
32
+ * modified: this.DataTypes.DATE
33
+ * };
34
+ * }
35
+ * }
36
+ * ```
37
+ *
38
+ * @example
39
+ * ```js
40
+ * // Basic CRUD operations
41
+ * import BookModel from '../models/BookModel';
42
+ *
43
+ * // INSERT INTO book (title) VALUES ('Beautiful')
44
+ * await BookModel.create({title: 'Beautiful'});
45
+ *
46
+ * // SELECT * FROM book
47
+ * await BookModel.findAll();
48
+ *
49
+ * // UPDATE book SET title = 'Beautiful' WHERE id= 1
50
+ * await BookModel.update({title: 'Beautiful'}, {where: {id: 1}});
51
+ *
52
+ * // DELETE FROM book WHERE id= 1
53
+ * await BookModel.destroy({where: {id: 1}});
54
+ * ```
5
55
  */
6
- export default class Model extends sequelize.Model {
56
+ export default class Model extends Model_base {
7
57
  /**
8
58
  * The name of the table that the model accesses.
9
59
  * This member must be defined in a subclass.
10
60
  * @type {string}
61
+ * @example
62
+ * ```js
63
+ * import * as expx from 'express-sweet';
64
+ *
65
+ * export default class extends expx.database.Model {
66
+ * static get table() {
67
+ * return 'user';
68
+ * }
69
+ * }
70
+ * ```
11
71
  */
12
72
  protected static table: string;
13
73
  /**
14
74
  * List of columns in the table accessed by this model.
15
75
  * This member must be defined in a subclass.
16
76
  * @type {sequelize.ModelAttributes}
77
+ * @see {@link https://sequelize.org/api/v6/variable/index.html#static-variable-DataTypes | Sequelize DataTypes}
78
+ * @example
79
+ * ```js
80
+ * import * as expx from 'express-sweet';
81
+ *
82
+ * export default class extends expx.database.Model {
83
+ * static get attributes() {
84
+ * return {
85
+ * id: {
86
+ * type: this.DataTypes.INTEGER,
87
+ * primaryKey: true,
88
+ * autoIncrement: true
89
+ * },
90
+ * name: this.DataTypes.STRING,
91
+ * email: this.DataTypes.STRING,
92
+ * password: this.DataTypes.STRING,
93
+ * icon: this.DataTypes.STRING,
94
+ * created: this.DataTypes.DATE,
95
+ * modified: this.DataTypes.DATE
96
+ * };
97
+ * }
98
+ * }
99
+ * ```
17
100
  */
18
101
  protected static attributes: sequelize.ModelAttributes;
19
102
  /**
20
103
  * Database instance.
21
- * @type {Database}
104
+ * Shared Sequelize instance managed by DatabaseManager.
105
+ * @type {sequelize.Sequelize}
22
106
  */
23
- protected static database: Database;
107
+ protected static db: sequelize.Sequelize;
24
108
  /**
25
- * Column type.
26
- * @see https://sequelize.org/api/v6/variable/index.html#static-variable-DataTypes
109
+ * A convenience class holding commonly used data types.
110
+ * This is an alias for `sequelize.DataTypes`.
27
111
  * @type {sequelize.DataTypes}
112
+ * @see {@link https://sequelize.org/api/v6/variable/index.html#static-variable-DataTypes | Sequelize DataTypes}
113
+ * @example
114
+ * ```js
115
+ * {id: this.DataTypes.INTEGER}
116
+ * ```
28
117
  */
29
118
  static readonly DataTypes: {
30
119
  [key: string]: any;
@@ -41,6 +130,7 @@ export default class Model extends sequelize.Model {
41
130
  * Operator.
42
131
  * @type {sequelize.Op}
43
132
  * @example
133
+ * ```js
44
134
  * // Sequelize provides several operators.
45
135
  * Post.findAll({
46
136
  * where: {
@@ -87,6 +177,7 @@ export default class Model extends sequelize.Model {
87
177
  * }
88
178
  * }
89
179
  * });
180
+ * ```
90
181
  */
91
182
  static readonly Op: {
92
183
  [key: string]: any;
@@ -96,27 +187,65 @@ export default class Model extends sequelize.Model {
96
187
  * order parts, and as default values in column definitions. If you want to refer to columns in your
97
188
  * function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings.
98
189
  * @type {sequelize.fn}
190
+ * @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#static-method-fn | Sequelize fn}
99
191
  * @example
100
- * // Convert a user's username to upper case
101
- * Post.update({
102
- * username: this.fn('upper', this.col('username'))
103
- * })
192
+ * ```js
193
+ * import BookModel from '../models/BookModel';
194
+ *
195
+ * // SELECT upper(`title`) AS `title` FROM `book` AS `book`;
196
+ * const books = await BookModel.findAll({
197
+ * attributes: [[BookModel.fn('upper', BookModel.col('title')), 'title']],
198
+ * raw: true
199
+ * });
200
+ * ```
104
201
  */
105
202
  static readonly fn: (fn: string, ...args: unknown[]) => any;
106
203
  /**
107
204
  * Creates a object representing a column in the DB. This is often useful in conjunction with
108
205
  * `sequelize.fn`, since raw string arguments to fn will be escaped.
109
206
  * @type {sequelize.col}
207
+ * @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#static-method-col | Sequelize col}
110
208
  */
111
209
  static readonly col: (col: string) => any;
112
210
  /**
113
211
  * Creates a object representing a literal, i.e. something that will not be escaped.
114
212
  * @type {sequelize.literal}
213
+ * @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#static-method-literal | Sequelize literal}
214
+ * @example
215
+ * ```js
216
+ * import BookModel from '../models/BookModel';
217
+ *
218
+ * // SELECT `id`, `title`, (SELECT COUNT(*) FROM comment WHERE comment.bookId = book.id) AS `count` FROM `book` AS `book`;
219
+ * const books = await BookModel.findAll({
220
+ * attributes: [
221
+ * 'id',
222
+ * 'title',
223
+ * [BookModel.literal(`(SELECT COUNT(*) FROM comment WHERE comment.bookId = book.id)`), 'count']
224
+ * ],
225
+ * raw: true
226
+ * });
227
+ * ```
115
228
  */
116
229
  static readonly literal: (val: string) => any;
117
230
  /**
118
231
  * A way of specifying attr = condition.
232
+ * The attr can either be an object taken from Model.rawAttributes or an object from sequelize utility functions.
119
233
  * @type {sequelize.where}
234
+ * @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#static-method-where | Sequelize where}
235
+ * @example
236
+ * ```js
237
+ * import BookModel from '../models/BookModel';
238
+ *
239
+ * // SELECT `title` FROM `book` AS `book` WHERE CHAR_LENGTH(`title`) <= 10;
240
+ * const books = await BookModel.findAll({
241
+ * attributes: ['title'],
242
+ * where: BookModel.where(
243
+ * BookModel.fn('CHAR_LENGTH', BookModel.col('title')),
244
+ * {[BookModel.Op.lte]: 10}
245
+ * ),
246
+ * raw: true
247
+ * });
248
+ * ```
120
249
  */
121
250
  static readonly where: (attr: sequelize.AttributeType, comparator: string, logic: sequelize.LogicType) => sequelize.Utils.Where;
122
251
  /**
@@ -125,32 +254,52 @@ export default class Model extends sequelize.Model {
125
254
  * @see https://sequelize.org/api/v6/class/src/transaction.js~transaction
126
255
  * @type {sequelize.Transaction}
127
256
  * @example
257
+ * ```js
128
258
  * BookModel.Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED // "READ UNCOMMITTED"
129
259
  * BookModel.Transaction.ISOLATION_LEVELS.READ_COMMITTED // "READ COMMITTED"
130
260
  * BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ // "REPEATABLE READ"
131
261
  * BookModel.Transaction.ISOLATION_LEVELS.SERIALIZABLE // "SERIALIZABLE"
262
+ * ```
132
263
  */
133
264
  static readonly Transaction: (typeof sequelize.Transaction);
134
265
  /**
135
- * Initialize the model that represents the table in the DB with attributes and options.
136
- * This method is called automatically from within the "express-sweet.mount" method, so you don't have to run it yourself.
137
- * @return {Promise<typeof Model>} Returns this model class itself.
266
+ * Initializes the model with attributes and options.
267
+ * This method is called automatically from within the "express-sweet.mount" method.
268
+ * @override
269
+ * @returns {Promise<any>} Returns this model class itself.
138
270
  */
139
- static initialize(): Promise<typeof Model>;
271
+ static init(): Promise<any>;
140
272
  /**
141
273
  * Associate the model.
142
274
  * Define associations with other models such as "hasOne", "hasMany", "belongsTo", "belongsToMany".
143
275
  * If you omit the alias (as) option, the associated name will be hasOne, singular for belongsTo, and plural for hasMany.
144
276
  * This method is called automatically from within the "express-sweet.mount" method, so you don't have to run it yourself.
145
- * @see https://sequelize.org/api/v6/class/src/associations/base.js~association
277
+ * @see {@link https://sequelize.org/api/v6/class/src/associations/base.js~association | Sequelize Associations}
278
+ * @example
279
+ * ```js
280
+ * import * as expx from 'express-sweet';
281
+ * import ProfileModel from './ProfileModel';
282
+ *
283
+ * export default class extends expx.database.Model {
284
+ * static association() {
285
+ * // User has one profile.
286
+ * this.hasOne(ProfileModel, {
287
+ * foreignKey: 'userId', // profile.userId
288
+ * sourceKey: 'id', // user.id
289
+ * as: 'profile'
290
+ * });
291
+ * }
292
+ * }
293
+ * ```
146
294
  */
147
295
  static association(): void;
148
296
  /**
149
297
  * Starts a transaction and returns a transaction object to identify the running transaction.
150
298
  * @see https://sequelize.org/api/v6/class/src/transaction.js~transaction
151
- * @param {sequelize.TransactionOptions} options? Options provided when the transaction is created.
152
- * @return {Promise<sequelize.Transaction>} Returns a transaction object to identify the transaction being executed.
299
+ * @param {sequelize.TransactionOptions} options Options provided when the transaction is created.
300
+ * @returns {Promise<sequelize.Transaction>} Returns a transaction object to identify the transaction being executed.
153
301
  * @example
302
+ * ```js
154
303
  * // Simple transaction usage example.
155
304
  * let transaction;
156
305
  * try {
@@ -180,10 +329,21 @@ export default class Model extends sequelize.Model {
180
329
  * if (transaction)
181
330
  * await transaction.rollback();
182
331
  * }
332
+ * ```
183
333
  */
184
334
  static begin(options?: sequelize.TransactionOptions): Promise<sequelize.Transaction>;
185
335
  /**
186
336
  * Returns data that matches the ID.
337
+ * This is a convenience method that wraps findOne with ID condition.
338
+ * @param {number} id The ID to search for
339
+ * @returns {Promise<object|null>} Returns the model instance or null if not found
340
+ * @example
341
+ * ```js
342
+ * import BookModel from '../models/BookModel';
343
+ *
344
+ * // SELECT * FROM book WHERE id = 1 LIMIT 1;
345
+ * const book = await BookModel.findById(1);
346
+ * ```
187
347
  */
188
348
  static findById(id: number): Promise<{} | null>;
189
349
  /**
@@ -192,9 +352,10 @@ export default class Model extends sequelize.Model {
192
352
  * @see https://sequelize.org/master/manual/raw-queries.html
193
353
  * @param {string} sql SQL string.
194
354
  * @param {object} options Query options.
195
- * @return {Promise<any>} By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc.
355
+ * @returns {Promise<any>} By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc.
196
356
  * If you are running a type of query where you don't need the metadata, for example a SELECT query, you can pass in a query type to make sequelize format the results:
197
357
  * @example
358
+ * ```js
198
359
  * // By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).
199
360
  * // Note that since this is a raw query, the metadata are dialect specific.
200
361
  * const [results, metadata] = await BookModel.query("UPDATE book SET title = 'When Im Gone' WHERE id = 1");
@@ -202,6 +363,8 @@ export default class Model extends sequelize.Model {
202
363
  * // 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:
203
364
  * // We didn't need to destructure the result here - the results were returned directly
204
365
  * const users = await BookModel.query("SELECT * FROM book", {type: BookModel.QueryTypes.SELECT});
366
+ * ```
205
367
  */
206
- static query(sql: string, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPDATE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKUPDATE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.INSERT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPSERT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.DELETE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKDELETE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.SHOWTABLES> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.DESCRIBE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW>): Promise<any>;
368
+ static query(sql: string, options: sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPDATE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKUPDATE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.INSERT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.UPSERT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.DELETE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.BULKDELETE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.SHOWTABLES> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.DESCRIBE> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.SELECT> | sequelize.QueryOptionsWithType<sequelize.QueryTypes.RAW>): Promise<any>;
207
369
  }
370
+ export {};
@@ -1,3 +1,47 @@
1
- export { default as Database } from '~/database/Database';
2
- export { default as Model } from '~/database/Model';
3
- export { default as loadModels } from '~/database/loadModels';
1
+ /**
2
+ * Database utilities and ORM functionality for Express Sweet.
3
+ *
4
+ * Provides Sequelize-based database abstraction with singleton connection management,
5
+ * custom Model base class, and automatic model loading system.
6
+ *
7
+ * @module database
8
+ * @example
9
+ * ```js
10
+ * // Using DatabaseManager
11
+ * import * as expx from 'express-sweet';
12
+ *
13
+ * const db = await expx.database.DatabaseManager.getInstance();
14
+ * const isConnected = await expx.database.DatabaseManager.isConnected();
15
+ * ```
16
+ *
17
+ * @example
18
+ * ```js
19
+ * // Creating a custom model
20
+ * import * as expx from 'express-sweet';
21
+ *
22
+ * export default class extends expx.database.Model {
23
+ * static get table() {
24
+ * return 'users';
25
+ * }
26
+ * static get attributes() {
27
+ * return {
28
+ * id: { type: this.DataTypes.INTEGER, primaryKey: true },
29
+ * name: this.DataTypes.STRING,
30
+ * email: this.DataTypes.STRING
31
+ * };
32
+ * }
33
+ * }
34
+ * ```
35
+ */
36
+ /**
37
+ * Singleton database connection manager for Sequelize
38
+ */
39
+ export { default as DatabaseManager } from './DatabaseManager';
40
+ /**
41
+ * Base model class extending Sequelize.Model
42
+ */
43
+ export { default as Model } from './Model';
44
+ /**
45
+ * Automatic model loading and association function
46
+ */
47
+ export { default as loadModels } from './loadModels';
@@ -1,8 +1,23 @@
1
1
  /**
2
- * Model initialization and association.
3
- * All models must be pre-loaded before associating models.So it loads and caches all defined models in advance.
4
- * This must be done before any method that may load other models is called.
5
- * @return {Promise<void>}
2
+ * Model initialization and association for Sequelize models.
3
+ * Loads all model files from the models/ directory, initializes them, then sets up associations.
4
+ * All models must be pre-loaded before associating to prevent circular dependency issues.
5
+ * @returns {Promise<void>}
6
+ * @example
7
+ * ```js
8
+ * // This function is called automatically by express-sweet.mount()
9
+ * import loadModels from '~/database/loadModels';
10
+ * await loadModels();
11
+ * ```
12
+ *
13
+ * @example
14
+ * ```bash
15
+ * // Model file structure
16
+ * models/
17
+ * ├── UserModel.js
18
+ * ├── ProfileModel.js
19
+ * └── BookModel.js
20
+ * ```
6
21
  */
7
22
  declare const _default: () => Promise<void>;
8
23
  export default _default;
@@ -3,8 +3,9 @@
3
3
  * @param {Array<{[key: string]: any}>} array The array of objects to search.
4
4
  * @param {string} fieldName The name of the field to search.
5
5
  * @param {*} fieldValue The value to search for.
6
- * @return {object|null} The first object in the array that matches the criteria, or null if no match is found.
6
+ * @returns {object|null} The first object in the array that matches the criteria, or null if no match is found.
7
7
  * @example
8
+ * ```handlebars
8
9
  * {{!--
9
10
  * items is an array of objects: [{id: 123, name: 'Item A'}, {id: 456, name: 'Item B'}]
10
11
  * This code will output: "Item A"
@@ -14,6 +15,7 @@
14
15
  * {{lookup (findObjectInArray ../items 'id' id) 'name'}}
15
16
  * {{/if}}
16
17
  * {{/each}}
18
+ * ```
17
19
  */
18
20
  export declare const findObjectInArray: (array: Array<{
19
21
  [key: string]: any;