express-sweet 3.0.2 → 5.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 (93) hide show
  1. package/CHANGELOG.md +224 -418
  2. package/LICENSE +1 -1
  3. package/README.md +211 -1026
  4. package/dist/build.cjs +37 -72
  5. package/dist/build.mjs +37 -72
  6. package/package.json +50 -64
  7. package/screenshots/avatar.png +0 -0
  8. package/screenshots/edit-profile.png +0 -0
  9. package/screenshots/hero-banner.png +0 -0
  10. package/screenshots/home.png +0 -0
  11. package/screenshots/mount-flow.mmd +11 -0
  12. package/screenshots/mount-flow.png +0 -0
  13. package/screenshots/new-person.png +0 -0
  14. package/screenshots/people.png +0 -0
  15. package/screenshots/sign-in.png +0 -0
  16. package/types/database/DatabaseManager.d.ts +15 -10
  17. package/types/database/Model.d.ts +29 -43
  18. package/types/database/index.d.ts +0 -1
  19. package/types/database/loadModels.d.ts +7 -13
  20. package/types/helpers/array.d.ts +21 -0
  21. package/types/helpers/comparison.d.ts +217 -0
  22. package/types/helpers/date.d.ts +20 -0
  23. package/types/helpers/html.d.ts +35 -0
  24. package/types/{handlebars_helpers → helpers}/index.d.ts +0 -2
  25. package/types/helpers/layouts.d.ts +29 -0
  26. package/types/helpers/math.d.ts +85 -0
  27. package/types/helpers/number.d.ts +19 -0
  28. package/types/helpers/object.d.ts +28 -0
  29. package/types/helpers/string.d.ts +45 -0
  30. package/types/index.d.ts +7 -52
  31. package/types/middleware/auth.d.ts +186 -0
  32. package/types/middleware/cors.d.ts +19 -0
  33. package/types/middleware/env.d.ts +24 -0
  34. package/types/middleware/error.d.ts +26 -0
  35. package/types/middleware/globals.d.ts +13 -0
  36. package/types/{middlewares → middleware}/index.d.ts +19 -12
  37. package/types/middleware/locals.d.ts +33 -0
  38. package/types/middleware/parser.d.ts +30 -0
  39. package/types/middleware/router.d.ts +31 -0
  40. package/types/middleware/views.d.ts +37 -0
  41. package/types/mount.d.ts +34 -3
  42. package/types/{interfaces/BasicConfig.d.ts → types/AppConfig.d.ts} +18 -25
  43. package/types/{interfaces → types}/AuthenticationConfig.d.ts +10 -11
  44. package/types/{interfaces → types}/DatabaseConfig.d.ts +1 -1
  45. package/types/{interfaces → types}/LoggingConfig.d.ts +0 -1
  46. package/types/types/UploadConfig.d.ts +72 -0
  47. package/types/{interfaces → types}/ViewConfig.d.ts +1 -2
  48. package/types/{interfaces → types}/index.d.ts +7 -4
  49. package/types/utils/index.d.ts +7 -4
  50. package/types/utils/loadAppConfig.d.ts +17 -0
  51. package/types/utils/loadAuthenticationConfig.d.ts +1 -1
  52. package/types/utils/loadLoggingConfig.d.ts +1 -1
  53. package/types/utils/loadUploadConfig.d.ts +20 -0
  54. package/types/utils/loadViewConfig.d.ts +1 -1
  55. package/configuration_sample/cjs/authentication.js +0 -138
  56. package/configuration_sample/cjs/config.js +0 -91
  57. package/configuration_sample/cjs/database.js +0 -121
  58. package/configuration_sample/cjs/logging.js +0 -41
  59. package/configuration_sample/cjs/view.js +0 -54
  60. package/configuration_sample/esm/authentication.js +0 -136
  61. package/configuration_sample/esm/config.js +0 -91
  62. package/configuration_sample/esm/database.js +0 -121
  63. package/configuration_sample/esm/logging.js +0 -41
  64. package/configuration_sample/esm/view.js +0 -54
  65. package/screencaps/belongs-to-many.png +0 -0
  66. package/screencaps/belongs-to.png +0 -0
  67. package/screencaps/demonstration.webp +0 -0
  68. package/screencaps/has-many.png +0 -0
  69. package/screencaps/has-one.png +0 -0
  70. package/types/handlebars_helpers/array.d.ts +0 -22
  71. package/types/handlebars_helpers/comparison.d.ts +0 -222
  72. package/types/handlebars_helpers/date.d.ts +0 -19
  73. package/types/handlebars_helpers/html.d.ts +0 -31
  74. package/types/handlebars_helpers/layouts.d.ts +0 -25
  75. package/types/handlebars_helpers/math.d.ts +0 -74
  76. package/types/handlebars_helpers/number.d.ts +0 -18
  77. package/types/handlebars_helpers/object.d.ts +0 -21
  78. package/types/handlebars_helpers/string.d.ts +0 -45
  79. package/types/middlewares/Authentication.d.ts +0 -52
  80. package/types/middlewares/CORS.d.ts +0 -30
  81. package/types/middlewares/Environment.d.ts +0 -36
  82. package/types/middlewares/ErrorHandler.d.ts +0 -34
  83. package/types/middlewares/Global.d.ts +0 -27
  84. package/types/middlewares/Http.d.ts +0 -29
  85. package/types/middlewares/Local.d.ts +0 -42
  86. package/types/middlewares/View.d.ts +0 -49
  87. package/types/routing/Router.d.ts +0 -56
  88. package/types/routing/index.d.ts +0 -37
  89. package/types/services/Authentication.d.ts +0 -95
  90. package/types/services/index.d.ts +0 -33
  91. package/types/types/global.d.ts +0 -38
  92. package/types/utils/Types.d.ts +0 -23
  93. package/types/utils/loadBasicConfig.d.ts +0 -17
@@ -1,42 +0,0 @@
1
- import express from 'express';
2
- /**
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
- * ```
26
- */
27
- export default class Local {
28
- /**
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
- * ```
40
- */
41
- static mount(app: express.Express): Promise<void>;
42
- }
@@ -1,49 +0,0 @@
1
- import express from 'express';
2
- /**
3
- * Enable Handlebars template engine with custom helpers and configuration.
4
- * Sets up view engine, layouts, partials, and before-render hooks.
5
- *
6
- * @see {@link https://handlebarsjs.com/guide/ | Handlebars Guide}
7
- * @example
8
- * ```js
9
- * // View configuration in config/view.js
10
- * export default {
11
- * views_dir: 'views',
12
- * partials_dir: 'views/partials',
13
- * layouts_dir: 'views/layout',
14
- * default_layout: 'views/layout/default',
15
- * extension: '.hbs',
16
- * beforeRender: (req, res) => {
17
- * res.locals.extra = 'Extra';
18
- * }
19
- * };
20
- * ```
21
- */
22
- export default class View {
23
- /**
24
- * Mount Handlebars view engine on Express application.
25
- * Configures template engine, helpers, layouts, and partials.
26
- * @param {express.Express} app Express application instance
27
- * @returns {Promise<void>}
28
- * @example
29
- * ```js
30
- * // This method is called automatically by express-sweet.mount()
31
- * import View from './middlewares/View';
32
- *
33
- * await View.mount(app);
34
- * ```
35
- */
36
- static mount(app: express.Express): Promise<void>;
37
- /**
38
- * Mount middleware to be executed just before rendering the view.
39
- * Allows setting view variables and executing beforeRender hooks from configuration.
40
- * @param {express.Express} app Express application instance
41
- * @returns {Promise<void>}
42
- * @example
43
- * ```js
44
- * // Called automatically after authentication middleware setup
45
- * await View.mountBeforeRender(app);
46
- * ```
47
- */
48
- static mountBeforeRender(app: express.Express): Promise<void>;
49
- }
@@ -1,56 +0,0 @@
1
- import express from 'express';
2
- /**
3
- * Set up URL routing based on file structure in the routes directory.
4
- * Automatically maps route files to URL endpoints using file-based routing.
5
- * Supports nested routing and default routes.
6
- *
7
- * @example
8
- * ```js
9
- * // Basic routing: routes/user.js responds to GET /user
10
- * import {Router} from 'express';
11
- *
12
- * const router = Router();
13
- * router.get('/', (req, res) => {
14
- * res.send('Hello World');
15
- * });
16
- *
17
- * export default router;
18
- * ```
19
- *
20
- * @example
21
- * ```js
22
- * // Nested routing: routes/api/users.js responds to GET /api/users
23
- * import {Router} from 'express';
24
- *
25
- * const router = Router();
26
- * router.get('/', (req, res) => {
27
- * res.send('Hello World');
28
- * });
29
- *
30
- * export default router;
31
- * ```
32
- *
33
- * @example
34
- * ```js
35
- * // Default routing configuration in config/config.js
36
- * export default {
37
- * default_router: '/blog' // routes/blog.js handles root URL "/"
38
- * };
39
- * ```
40
- */
41
- export default class Router {
42
- /**
43
- * Mount file-based routing on Express application.
44
- * Scans the routes directory and automatically maps files to URL endpoints.
45
- * @param {express.Express} app Express application instance
46
- * @returns {Promise<void>}
47
- * @example
48
- * ```js
49
- * // This method is called automatically by express-sweet.mount()
50
- * import Router from './routing/Router';
51
- *
52
- * await Router.mount(app);
53
- * ```
54
- */
55
- static mount(app: express.Express): Promise<void>;
56
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * File-based routing system for Express Sweet.
3
- *
4
- * Provides automatic route mapping based on file structure in the routes directory.
5
- * Routes are automatically mounted based on their file path and name.
6
- *
7
- * @module routing
8
- * @example
9
- * ```bash
10
- * // File-based routing structure
11
- * routes/
12
- * ├── index.js // responds to GET /
13
- * ├── users.js // responds to GET /users
14
- * ├── api/
15
- * │ ├── auth.js // responds to GET /api/auth
16
- * │ └── users.js // responds to GET /api/users
17
- * └── admin/
18
- * └── dashboard.js // responds to GET /admin/dashboard
19
- * ```
20
- *
21
- * @example
22
- * ```js
23
- * // Basic route file (routes/users.js)
24
- * import {Router} from 'express';
25
- *
26
- * const router = Router();
27
- * router.get('/', (req, res) => {
28
- * res.send('Users list');
29
- * });
30
- *
31
- * export default router;
32
- * ```
33
- */
34
- /**
35
- * File-based routing class that automatically maps route files to URL endpoints
36
- */
37
- export { default as Router } from './Router';
@@ -1,95 +0,0 @@
1
- import express from 'express';
2
- /**
3
- * User authentication service using Passport.js.
4
- * Provides methods for user authentication, logout, and redirect handling.
5
- *
6
- * @see {@link https://www.passportjs.org/ | Passport.js}
7
- * @example
8
- * ```js
9
- * // Using in async request handler
10
- * import * as expx from 'express-sweet';
11
- *
12
- * router.post('/login', async (req, res, next) => {
13
- * const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
14
- * res.json(isAuthenticated);
15
- * });
16
- * ```
17
- *
18
- * @example
19
- * ```js
20
- * // Using in sync request handler
21
- * router.post('/login', async (req, res, next) => {
22
- * const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
23
- * if (isAuthenticated)
24
- * await expx.services.Authentication.successRedirect(res);
25
- * else
26
- * await expx.services.Authentication.failureRedirect(req, res);
27
- * });
28
- * ```
29
- */
30
- export default class Authentication {
31
- /**
32
- * Authenticate the user using username and password from request body.
33
- * Uses Passport.js local strategy for authentication.
34
- * @param {express.Request} req The HTTP request object containing user credentials
35
- * @param {express.Response} res The HTTP response object
36
- * @param {express.NextFunction} next The next middleware function
37
- * @returns {Promise<boolean>} Returns true if authentication is successful, false otherwise
38
- * @example
39
- * ```js
40
- * // For asynchronous requests
41
- * const router = Router();
42
- * router.post('/login', async (req, res, next) => {
43
- * const isAuthenticated = await Authentication.authenticate(req, res, next);
44
- * res.json(isAuthenticated);
45
- * });
46
- * ```
47
- */
48
- static authenticate(req: express.Request, res: express.Response, next: express.NextFunction): Promise<boolean>;
49
- /**
50
- * Log out the user by removing req.user property and clearing the login session.
51
- * @param {express.Request} req The HTTP request object
52
- * @example
53
- * ```js
54
- * import {Router} from 'express';
55
- * import * as expx from 'express-sweet';
56
- *
57
- * const router = Router();
58
- * router.get('/logout', (req, res) => {
59
- * expx.services.Authentication.logout(req);
60
- * res.redirect('/');
61
- * });
62
- * ```
63
- */
64
- static logout(req: express.Request): void;
65
- /**
66
- * Redirects to the success page after successful authentication.
67
- * Uses the URL specified in "success_redirect" of config/authentication.js.
68
- * @param {express.Response} res The HTTP response object
69
- * @returns {Promise<void>}
70
- * @example
71
- * ```js
72
- * // For synchronous login handling
73
- * const isAuthenticated = await Authentication.authenticate(req, res, next);
74
- * if (isAuthenticated)
75
- * await Authentication.successRedirect(res);
76
- * ```
77
- */
78
- static successRedirect(res: express.Response): Promise<void>;
79
- /**
80
- * Redirects to the failure page after authentication failure.
81
- * Uses the URL specified in "failure_redirect" of config/authentication.js.
82
- * Supports both static URLs and dynamic URL functions.
83
- * @param {express.Request} req The HTTP request object
84
- * @param {express.Response} res The HTTP response object
85
- * @returns {Promise<void>}
86
- * @example
87
- * ```js
88
- * // For synchronous login handling
89
- * const isAuthenticated = await Authentication.authenticate(req, res, next);
90
- * if (!isAuthenticated)
91
- * await Authentication.failureRedirect(req, res);
92
- * ```
93
- */
94
- static failureRedirect(req: express.Request, res: express.Response): Promise<void>;
95
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Business logic services for Express Sweet.
3
- *
4
- * Provides high-level service classes for common application functionality
5
- * such as user authentication, authorization, and other business operations.
6
- *
7
- * @module services
8
- * @example
9
- * ```js
10
- * // Using authentication service in routes
11
- * import * as expx from 'express-sweet';
12
- * import {Router} from 'express';
13
- *
14
- * const router = Router();
15
- *
16
- * router.post('/login', async (req, res, next) => {
17
- * const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
18
- * if (isAuthenticated)
19
- * await expx.services.Authentication.successRedirect(res);
20
- * else
21
- * await expx.services.Authentication.failureRedirect(req, res);
22
- * });
23
- *
24
- * router.get('/logout', (req, res) => {
25
- * expx.services.Authentication.logout(req);
26
- * res.redirect('/');
27
- * });
28
- * ```
29
- */
30
- /**
31
- * User authentication service using Passport.js
32
- */
33
- export { default as Authentication } from './Authentication';
@@ -1,38 +0,0 @@
1
- /**
2
- * Global type declarations for Express Sweet.
3
- *
4
- * Extends the global namespace with Express Sweet specific variables
5
- * that are accessible throughout the application runtime.
6
- *
7
- * @module global
8
- * @example
9
- * // Accessing global variables anywhere in the application
10
- * console.log(global.APP_DIR); // "/path/to/your/app"
11
- * console.log(global.loadedEnv); // true or false
12
- */
13
- declare global {
14
- /**
15
- * Application root directory path.
16
- * Set by the Global middleware during application initialization.
17
- * Contains the absolute path to the directory where the main application file is located.
18
- * @type {string}
19
- * @example
20
- * // Access in routes or models
21
- * const configPath = `${global.APP_DIR}/config/custom.json`;
22
- * const publicPath = `${global.APP_DIR}/public/uploads`;
23
- */
24
- var APP_DIR: string;
25
- /**
26
- * Environment variables loading flag.
27
- * Set by the Environment middleware to prevent multiple loading of .env files.
28
- * True if environment variables have already been loaded from .env file.
29
- * @type {boolean}
30
- * @example
31
- * // Check if environment variables are loaded
32
- * if (global.loadedEnv) {
33
- * console.log('Environment variables already loaded');
34
- * }
35
- */
36
- var loadedEnv: boolean;
37
- }
38
- export {};
@@ -1,23 +0,0 @@
1
- /**
2
- * Type judgment processing.
3
- */
4
- export default class Types {
5
- /**
6
- * Returns true for asynchronous functions, false otherwise.
7
- * @param {Function} value.
8
- * @returns {boolean}
9
- * @example
10
- * ```js
11
- * Types.isAsyncFunction(async () => {});// true
12
- * Types.isAsyncFunction(() => {});// false
13
- * ```
14
- */
15
- static isAsyncFunction(value: Function): boolean;
16
- /**
17
- * Return true if `val` is a non-empty string.
18
- * @param {any} `val` The value to check
19
- * @returns {Boolean}
20
- * @api public
21
- */
22
- static isString(value: any): boolean;
23
- }
@@ -1,17 +0,0 @@
1
- import BasicConfig from '~/interfaces/BasicConfig';
2
- /**
3
- * Load basic application configuration from config/config.js file.
4
- * Returns default configuration if config file doesn't exist.
5
- * @returns {Promise<BasicConfig>} The loaded basic configuration with defaults
6
- * @example
7
- * ```js
8
- * import loadBasicConfig from '~/utils/loadBasicConfig';
9
- *
10
- * const config = await loadBasicConfig();
11
- * console.log(config.cors_enabled); // false (default)
12
- * console.log(config.max_body_size); // '100kb' (default)
13
- * console.log(config.router_dir); // '/path/to/app/routes' (default)
14
- * ```
15
- */
16
- declare const _default: () => Promise<BasicConfig>;
17
- export default _default;