express-sweet 2.0.8 → 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 +244 -173
  2. package/README.md +1031 -2112
  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 +9 -9
  12. package/dist/build.mjs +9 -9
  13. package/package.json +11 -6
  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 -11
  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
@@ -1,6 +1,37 @@
1
1
  import express from 'express';
2
2
  /**
3
- * User authentication configuration interface.
3
+ * User authentication configuration interface using Passport.js.
4
+ * Defines configuration for user authentication, session management, and security settings.
5
+ * @see {@link https://www.passportjs.org/ | Passport.js}
6
+ * @example
7
+ * ```js
8
+ * // config/authentication.js
9
+ * export default {
10
+ * enabled: true,
11
+ * username: 'email',
12
+ * password: 'password',
13
+ * success_redirect: '/',
14
+ * failure_redirect: '/login',
15
+ * session_store: 'redis',
16
+ * redis_host: 'redis://localhost:6379',
17
+ * authenticate_user: async (username, password, req) => {
18
+ * const UserModel = require('../models/UserModel');
19
+ * return UserModel.findOne({
20
+ * where: { email: username, password },
21
+ * raw: true
22
+ * });
23
+ * },
24
+ * subscribe_user: async (id) => {
25
+ * const UserModel = require('../models/UserModel');
26
+ * return UserModel.findOne({
27
+ * where: { id },
28
+ * raw: true
29
+ * });
30
+ * },
31
+ * allow_unauthenticated: ['/api', /^\/public/],
32
+ * expiration: 24 * 3600000
33
+ * };
34
+ * ```
4
35
  */
5
36
  export default interface AuthenticationConfig {
6
37
  /**
@@ -58,6 +89,7 @@ export default interface AuthenticationConfig {
58
89
  * URL to redirect after log off, defaults to `/login`.
59
90
  * @type {string|((req: express.Request, res: express.Response) => string)}
60
91
  * @example
92
+ * ```js
61
93
  * // Set the URL to redirect to in case of login failure as a string.
62
94
  * failure_redirect: '/login',
63
95
  *
@@ -66,6 +98,7 @@ export default interface AuthenticationConfig {
66
98
  * // If the role stored in the cookie is admin, redirect to the admin login screen.
67
99
  * return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
68
100
  * },
101
+ * ```
69
102
  */
70
103
  failure_redirect: string | ((req: express.Request, res: express.Response) => string);
71
104
  /**
@@ -75,6 +108,7 @@ export default interface AuthenticationConfig {
75
108
  * Note that the user information must include an ID value that can identify the user.
76
109
  * @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
77
110
  * @example
111
+ * ```js
78
112
  * authenticate_user: async (username, password, req) => {
79
113
  * const UserModel = require('../models/UserModel');
80
114
  * return UserModel.findOne({
@@ -85,6 +119,7 @@ export default interface AuthenticationConfig {
85
119
  * raw: true
86
120
  * });
87
121
  * }
122
+ * ```
88
123
  */
89
124
  authenticate_user: (username: string, password: string, req: express.Request) => Promise<{
90
125
  [key: string]: any;
@@ -95,6 +130,7 @@ export default interface AuthenticationConfig {
95
130
  * The returned data will be set in the req.user property and the view's session variable.
96
131
  * @type {(id: number|string) => Promise<{[key: string]: any}>}
97
132
  * @example
133
+ * ```js
98
134
  * subscribe_user: async (id) => {
99
135
  * const UserModel = require('../models/UserModel');
100
136
  * return UserModel.findOne({
@@ -102,6 +138,7 @@ export default interface AuthenticationConfig {
102
138
  * raw: true
103
139
  * });
104
140
  * }
141
+ * ```
105
142
  */
106
143
  subscribe_user: (id: number | string) => Promise<{
107
144
  [key: string]: any;
@@ -1,6 +1,25 @@
1
1
  import express from 'express';
2
2
  /**
3
- * EXPRESS SWEET basic configuration interface.
3
+ * Express Sweet basic application configuration interface.
4
+ * Defines configuration options for environment, CORS, routing, error handling, and more.
5
+ * @see {@link https://expressjs.com/ | Express.js}
6
+ * @example
7
+ * ```js
8
+ * // config/config.js
9
+ * export default {
10
+ * env_path: '.env',
11
+ * cors_enabled: true,
12
+ * max_body_size: '100kb',
13
+ * router_dir: 'routes',
14
+ * default_router: '/blog',
15
+ * rewrite_base_url: baseUrl => `${baseUrl}/admin`,
16
+ * is_ajax: req => /^\/api/.test(req.path),
17
+ * hook_handle_error: (error, req, res, next) => {
18
+ * if (error.status === 404) res.render('error/404');
19
+ * else res.render('error/500');
20
+ * }
21
+ * };
22
+ * ```
4
23
  */
5
24
  export default interface BasicConfig {
6
25
  /**
@@ -34,9 +53,11 @@ export default interface BasicConfig {
34
53
  * The default value is the referrer's origin (eg https://example.com).
35
54
  * @type {(baseUrl: string): string}
36
55
  * @example
56
+ * ```js
37
57
  * rewrite_base_url: baseUrl => {
38
58
  * return `${baseUrl}/admin`;
39
59
  * }
60
+ * ```
40
61
  */
41
62
  rewrite_base_url?: (baseUrl: string) => string;
42
63
  /**
@@ -45,11 +66,13 @@ export default interface BasicConfig {
45
66
  * For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^\/api\//.test(req.path)".
46
67
  * @type {(req: express.Request) => boolean}
47
68
  * @example
69
+ * ```js
48
70
  * is_ajax: req => {
49
71
  * // If the request URL begins with /api, it is assumed to be Ajax.
50
72
  * return /^\/api/.test(req.path);
51
73
  * // return !!req.xhr;
52
74
  * }
75
+ * ```
53
76
  */
54
77
  is_ajax: (req: express.Request) => boolean;
55
78
  /**
@@ -57,6 +80,7 @@ export default interface BasicConfig {
57
80
  * If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
58
81
  * @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
59
82
  * @example
83
+ * ```js
60
84
  * hook_handle_error: (error, req, res, next) => {
61
85
  * if (error.status === 404)
62
86
  * // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
@@ -65,6 +89,7 @@ export default interface BasicConfig {
65
89
  * // For other errors, unknown error screen (views/error/500.hbs) is displayed.
66
90
  * res.render('error/500');
67
91
  * },
92
+ * ```
68
93
  */
69
94
  hook_handle_error?: (error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void;
70
95
  }
@@ -1,7 +1,51 @@
1
1
  import sequelize from 'sequelize';
2
2
  /**
3
- * Database configuration.
3
+ * Database configuration interface for Sequelize connections.
4
+ * Defines environment-specific database configurations (development, test, production).
5
+ * Each environment contains Sequelize connection options.
6
+ * @see {@link https://sequelize.org/docs/v6/other-topics/migrations/#configuration | Sequelize Configuration}
7
+ * @example
8
+ * ```js
9
+ * // config/database.js
10
+ * export default {
11
+ * development: {
12
+ * username: 'root',
13
+ * password: 'password',
14
+ * database: 'myapp_dev',
15
+ * host: 'localhost',
16
+ * dialect: 'mariadb',
17
+ * logging: console.log
18
+ * },
19
+ * test: {
20
+ * username: 'root',
21
+ * password: 'password',
22
+ * database: 'myapp_test',
23
+ * host: 'localhost',
24
+ * dialect: 'mariadb',
25
+ * logging: false
26
+ * },
27
+ * production: {
28
+ * username: 'root',
29
+ * password: 'password',
30
+ * database: 'myapp_prod',
31
+ * host: 'localhost',
32
+ * dialect: 'mariadb',
33
+ * logging: false,
34
+ * pool: {
35
+ * max: 5,
36
+ * min: 0,
37
+ * acquire: 30000,
38
+ * idle: 10000
39
+ * }
40
+ * }
41
+ * };
42
+ * ```
4
43
  */
5
44
  export default interface DatabaseConfig {
45
+ /**
46
+ * Environment-specific database configuration.
47
+ * Key represents environment name (development, test, production, etc.)
48
+ * Value contains Sequelize connection options for that environment.
49
+ */
6
50
  [key: string]: sequelize.Options;
7
51
  }
@@ -0,0 +1,49 @@
1
+ import express from 'express';
2
+ /**
3
+ * Logging configuration interface using Morgan.
4
+ * Defines configuration for HTTP request logging middleware.
5
+ * @see {@link https://www.npmjs.com/package/morgan | Morgan}
6
+ * @example
7
+ * ```js
8
+ * // config/logging.js
9
+ * export default {
10
+ * format: 'combined',
11
+ * skip: (req, res) => {
12
+ * return req.path === '/health';
13
+ * }
14
+ * };
15
+ * ```
16
+ */
17
+ export default interface LoggingConfig {
18
+ /**
19
+ * Morgan logging format. Common formats: 'combined', 'common', 'dev', 'short', 'tiny'
20
+ * You can also define custom format string, defaults to 'combined'.
21
+ * @type {string}
22
+ * @example
23
+ * ```js
24
+ * // Use predefined format
25
+ * format: 'combined',
26
+ *
27
+ * // Use custom format
28
+ * format: ':method :url :status :res[content-length] - :response-time ms',
29
+ * ```
30
+ */
31
+ format: string;
32
+ /**
33
+ * Function to determine if logging should be skipped for a request.
34
+ * Return true to skip logging, false to log the request, defaults to none (undefined).
35
+ * @type {(req: express.Request, res: express.Response) => boolean}
36
+ * @example
37
+ * ```js
38
+ * // Skip logging for successful requests
39
+ * skip: (req, res) => res.statusCode < 400,
40
+ *
41
+ * // Skip logging for specific routes
42
+ * skip: (req, res) => req.path === '/health',
43
+ *
44
+ * // Skip logging in test environment
45
+ * skip: (req, res) => process.env.NODE_ENV === 'test',
46
+ * ```
47
+ */
48
+ skip?: (req: express.Request, res: express.Response) => boolean;
49
+ }
@@ -1,8 +1,25 @@
1
1
  import express from 'express';
2
2
  /**
3
- * View's configuration interface.
3
+ * Handlebars view engine configuration interface.
4
+ * Defines configuration for template directories, layouts, partials, and rendering hooks.
5
+ * @see {@link https://handlebarsjs.com/guide/ | Handlebars Guide}
6
+ * @example
7
+ * ```js
8
+ * // config/view.js
9
+ * export default {
10
+ * views_dir: 'views',
11
+ * partials_dir: 'views/partials',
12
+ * layouts_dir: 'views/layout',
13
+ * default_layout: 'views/layout/default',
14
+ * extension: '.hbs',
15
+ * beforeRender: (req, res) => {
16
+ * res.locals.siteName = 'My Website';
17
+ * res.locals.currentYear = new Date().getFullYear();
18
+ * }
19
+ * };
20
+ * ```
4
21
  */
5
- export default interface SesOptions {
22
+ export default interface ViewConfig {
6
23
  /**
7
24
  * Absolute path to the directory where the view files are located, defaults to `<application root directory>/views`.
8
25
  * @type {string}
@@ -33,10 +50,12 @@ export default interface SesOptions {
33
50
  * For example, you can set your own local variables that can be used within the view.
34
51
  * @type {(res: express.Response) => Promise<void>|void}
35
52
  * @example
53
+ * ```js
36
54
  * // The message set here can be referenced in the view as {{message}}.
37
55
  * beforeRender: (req, res) => {
38
56
  * res.locals.extra = 'Extra';
39
57
  * }
58
+ * ```
40
59
  */
41
60
  beforeRender?: (req: express.Request, res: express.Response) => Promise<void> | void;
42
61
  }
@@ -1,11 +1,25 @@
1
- export { default as AuthenticationConfig } from '~/interfaces/AuthenticationConfig';
2
- export { default as BasicConfig } from '~/interfaces/BasicConfig';
3
- export { default as BoundingBox } from '~/interfaces/BoundingBox';
4
- export { default as DatabaseConfig } from '~/interfaces/DatabaseConfig';
5
- export { default as FaceDetails } from '~/interfaces/FaceDetails';
6
- export { default as FaceDetailsEmotions } from '~/interfaces/FaceDetailsEmotions';
7
- export { default as FaceMatch } from '~/interfaces/FaceMatch';
8
- export { default as IndexFaceDetails } from '~/interfaces/IndexFaceDetails';
9
- export { default as RekognitionOptions } from '~/interfaces/RekognitionOptions';
10
- export { default as SesOptions } from '~/interfaces/SesOptions';
11
- export { default as ViewConfig } from '~/interfaces/ViewConfig';
1
+ /**
2
+ * Express Sweet configuration interfaces.
3
+ * Exports all configuration interfaces for type-safe configuration setup.
4
+ * @module interfaces
5
+ */
6
+ /**
7
+ * User authentication configuration interface using Passport.js
8
+ */
9
+ export { default as AuthenticationConfig } from './AuthenticationConfig';
10
+ /**
11
+ * Basic application configuration interface
12
+ */
13
+ export { default as BasicConfig } from './BasicConfig';
14
+ /**
15
+ * Database configuration interface for Sequelize connections
16
+ */
17
+ export { default as DatabaseConfig } from './DatabaseConfig';
18
+ /**
19
+ * Handlebars view engine configuration interface
20
+ */
21
+ export { default as ViewConfig } from './ViewConfig';
22
+ /**
23
+ * Logging configuration interface using Morgan
24
+ */
25
+ export { default as LoggingConfig } from './LoggingConfig';
@@ -1,15 +1,52 @@
1
1
  import express from 'express';
2
2
  /**
3
- * Incorporate user authentication into your application.
4
- * If an unauthenticated user makes a request to a URL that allows access only if authenticated, the user will be redirected to the page specified by "failure_redirect".
3
+ * Incorporate user authentication into your application using Passport.js middleware.
4
+ * Provides username/password authentication with session management and route protection.
5
+ * If an unauthenticated user makes a request to a URL that allows access only if authenticated,
6
+ * the user will be redirected to the page specified by "failure_redirect".
5
7
  * If that access is asynchronous, a 401 error is returned.
8
+ *
9
+ * @see {@link https://www.passportjs.org/ | Passport.js}
10
+ * @example
11
+ * ```js
12
+ * // Authentication configuration in config/authentication.js
13
+ * export default {
14
+ * enabled: true,
15
+ * username: 'email',
16
+ * password: 'password',
17
+ * success_redirect: '/',
18
+ * failure_redirect: '/login',
19
+ * authenticate_user: async (username, password, req) => {
20
+ * const UserModel = require('../models/UserModel');
21
+ * return UserModel.findOne({
22
+ * where: { email: username, password },
23
+ * raw: true
24
+ * });
25
+ * },
26
+ * subscribe_user: async (id) => {
27
+ * const UserModel = require('../models/UserModel');
28
+ * return UserModel.findOne({
29
+ * where: { id },
30
+ * raw: true
31
+ * });
32
+ * }
33
+ * }
34
+ * ```
6
35
  */
7
- export default class {
36
+ export default class Authentication {
8
37
  #private;
9
38
  /**
10
- * Mount on application.
11
- * @param {express.Express} app Express application instance.
12
- * @return {Promise<void>}
39
+ * Mount authentication middleware on Express application.
40
+ * Sets up Passport.js with local strategy, session management, and route protection.
41
+ * @param {express.Express} app Express application instance
42
+ * @returns {Promise<void>}
43
+ * @example
44
+ * ```js
45
+ * // This method is called automatically by express-sweet.mount()
46
+ * import Authentication from './middlewares/Authentication';
47
+ *
48
+ * await Authentication.mount(app);
49
+ * ```
13
50
  */
14
51
  static mount(app: express.Express): Promise<void>;
15
52
  }
@@ -1,12 +1,30 @@
1
1
  import express from 'express';
2
2
  /**
3
- * Enables the CORS.
3
+ * Enables Cross-Origin Resource Sharing (CORS) middleware.
4
+ * Allows requests from another domain to the application by setting appropriate headers.
5
+ *
6
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS | MDN CORS}
7
+ * @example
8
+ * ```js
9
+ * // Enable CORS in config/config.js
10
+ * export default {
11
+ * cors_enabled: true
12
+ * };
13
+ * ```
4
14
  */
5
- export default class {
15
+ export default class CORS {
6
16
  /**
7
- * Mount on application.
8
- * @param {express.Express} app Express application instance.
9
- * @return {Promise<void>}
17
+ * Mount CORS middleware on Express application.
18
+ * Sets appropriate CORS headers to allow cross-origin requests.
19
+ * @param {express.Express} app Express application instance
20
+ * @returns {Promise<void>}
21
+ * @example
22
+ * ```js
23
+ * // This method is called automatically by express-sweet.mount()
24
+ * import CORS from './middlewares/CORS';
25
+ *
26
+ * await CORS.mount(app);
27
+ * ```
10
28
  */
11
29
  static mount(app: express.Express): Promise<void>;
12
30
  }
@@ -1,10 +1,36 @@
1
1
  /**
2
- * Mount environment variables. Read the environment variable file in options.path and set it in "process.env".
2
+ * Mount environment variables from .env file.
3
+ * Reads the environment variable file specified in config and sets variables in process.env.
4
+ * Prevents multiple loading with a global flag.
5
+ *
6
+ * @example
7
+ * ```js
8
+ * // Environment variables configuration in config/config.js
9
+ * export default {
10
+ * env_path: '.env' // Path to environment file
11
+ * };
12
+ * ```
13
+ *
14
+ * @example
15
+ * ```bash
16
+ * // .env file contents
17
+ * NODE_ENV=development
18
+ * DATABASE_URL=mysql://localhost/mydb
19
+ * SECRET_KEY=mysecret
20
+ * ```
3
21
  */
4
- export default class {
22
+ export default class Environment {
5
23
  /**
6
- * Mount on application.
7
- * @return {Promise<void>}
24
+ * Mount environment variables on application.
25
+ * Loads .env file and sets variables in process.env if not already loaded.
26
+ * @returns {Promise<void>}
27
+ * @example
28
+ * ```js
29
+ * // This method is called automatically by express-sweet.mount()
30
+ * import Environment from './middlewares/Environment';
31
+ *
32
+ * await Environment.mount();
33
+ * ```
8
34
  */
9
35
  static mount(): Promise<void>;
10
36
  }
@@ -1,12 +1,34 @@
1
1
  import express from 'express';
2
2
  /**
3
- * Error handling.
3
+ * Error handling middleware for Express applications.
4
+ * Catches 404 errors and provides customizable error handling through hooks.
5
+ *
6
+ * @example
7
+ * ```js
8
+ * // Custom error handling in config/config.js
9
+ * export default {
10
+ * hook_handle_error: (error, req, res, next) => {
11
+ * if (error.status === 404)
12
+ * res.render('error/404');
13
+ * else
14
+ * res.render('error/500');
15
+ * }
16
+ * };
17
+ * ```
4
18
  */
5
- export default class {
19
+ export default class ErrorHandler {
6
20
  /**
7
- * Mount on application.
8
- * @param {express.Express} app Express application instance.
9
- * @return {Promise<void>}
21
+ * Mount error handling middleware on Express application.
22
+ * Sets up 404 error catching and custom error handling hooks.
23
+ * @param {express.Express} app Express application instance
24
+ * @returns {Promise<void>}
25
+ * @example
26
+ * ```js
27
+ * // This method is called automatically by express-sweet.mount()
28
+ * import ErrorHandler from './middlewares/ErrorHandler';
29
+ *
30
+ * await ErrorHandler.mount(app);
31
+ * ```
10
32
  */
11
33
  static mount(app: express.Express): Promise<void>;
12
34
  }
@@ -1,13 +1,27 @@
1
1
  /**
2
- * Set global variables.
3
- * It can be accessed like "global.xxx" in all router and model classes.
2
+ * Set global variables accessible throughout the application.
3
+ * Variables can be accessed like "global.xxx" in all router and model classes.
4
4
  *
5
- * Below is a description of the variables.
6
- * APP_DIR: The directory where app.js is located.
5
+ * Global variables set:
6
+ * - APP_DIR: The directory where app.js is located (process.cwd())
7
+ *
8
+ * @example
9
+ * ```js
10
+ * // Access in any router or model
11
+ * console.log(global.APP_DIR); // "/path/to/your/app"
12
+ * ```
7
13
  */
8
- export default class {
14
+ export default class Global {
9
15
  /**
10
- * Mount on application.
16
+ * Mount global variables on application.
17
+ * Sets up global.APP_DIR for access throughout the application.
18
+ * @example
19
+ * ```js
20
+ * // This method is called automatically by express-sweet.mount()
21
+ * import Global from './middlewares/Global';
22
+ *
23
+ * Global.mount();
24
+ * ```
11
25
  */
12
26
  static mount(): void;
13
27
  }
@@ -1,12 +1,29 @@
1
1
  import express from 'express';
2
2
  /**
3
- * Defines all the requisites in HTTP.
3
+ * HTTP middleware setup for Express application.
4
+ * Configures JSON/URL-encoded parsing, file uploads, cookie parsing, static files, and request logging.
5
+ *
6
+ * @example
7
+ * ```js
8
+ * // Body size configuration in config/config.js
9
+ * export default {
10
+ * max_body_size: '100mb' // Controls request body size limit
11
+ * };
12
+ * ```
4
13
  */
5
- export default class {
14
+ export default class Http {
6
15
  /**
7
- * Mount on application.
8
- * @param {express.Express} app Express application instance.
9
- * @return {Promise<void>}
16
+ * Mount HTTP middleware on Express application.
17
+ * Sets up request parsing, file uploads, cookies, static files, and logging.
18
+ * @param {express.Express} app Express application instance
19
+ * @returns {Promise<void>}
20
+ * @example
21
+ * ```js
22
+ * // This method is called automatically by express-sweet.mount()
23
+ * import Http from './middlewares/Http';
24
+ *
25
+ * await Http.mount(app);
26
+ * ```
10
27
  */
11
28
  static mount(app: express.Express): Promise<void>;
12
29
  }
@@ -1,15 +1,42 @@
1
1
  import express from 'express';
2
2
  /**
3
- * Set local variables.
4
- * It can be accessed in all views as {{var}} or {{{var}}}.
5
- * Below is a description of the variables.
6
- * baseUrl: The base URL for this application.
3
+ * Set local variables accessible in Handlebars views.
4
+ * Variables can be accessed in all views as {{var}} or {{{var}}}.
5
+ *
6
+ * Local variables set:
7
+ * - baseUrl: The base URL for this application (can be rewritten via config hook)
8
+ * - currentPath: The current request path
9
+ *
10
+ * @example
11
+ * ```handlebars
12
+ * // Using in Handlebars templates
13
+ * <a href="{{baseUrl}}/home">Home</a>
14
+ * {{#if (eq currentPath '/dashboard')}}Active{{/if}}
15
+ * ```
16
+ *
17
+ * @example
18
+ * // Base URL rewriting in config/config.js
19
+ * ```js
20
+ * export default {
21
+ * rewrite_base_url: baseUrl => {
22
+ * return `${baseUrl}/admin`;
23
+ * }
24
+ * };
25
+ * ```
7
26
  */
8
- export default class {
27
+ export default class Local {
9
28
  /**
10
- * Mount on application.
11
- * @param {express.Express} app Express application instance.
12
- * @return {Promise<void>}
29
+ * Mount local variables middleware on Express application.
30
+ * Sets up baseUrl and currentPath variables for use in views.
31
+ * @param {express.Express} app Express application instance
32
+ * @returns {Promise<void>}
33
+ * @example
34
+ * ```js
35
+ * // This method is called automatically by express-sweet.mount()
36
+ * import Local from './middlewares/Local';
37
+ *
38
+ * await Local.mount(app);
39
+ * ```
13
40
  */
14
41
  static mount(app: express.Express): Promise<void>;
15
42
  }