express-sweet 2.0.9 → 3.0.1
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 +69 -1
- package/README.md +1039 -2137
- package/configuration_sample/cjs/authentication.js +50 -15
- package/configuration_sample/cjs/config.js +38 -21
- package/configuration_sample/cjs/database.js +90 -4
- package/configuration_sample/cjs/logging.js +41 -0
- package/configuration_sample/cjs/view.js +19 -1
- package/configuration_sample/esm/authentication.js +48 -15
- package/configuration_sample/esm/config.js +39 -22
- package/configuration_sample/esm/database.js +90 -4
- package/configuration_sample/esm/logging.js +41 -0
- package/configuration_sample/esm/view.js +20 -2
- package/dist/build.cjs +8 -8
- package/dist/build.mjs +4 -4
- package/package.json +9 -4
- package/types/database/DatabaseManager.d.ts +95 -0
- package/types/database/Model.d.ts +183 -20
- package/types/database/index.d.ts +47 -3
- package/types/database/loadModels.d.ts +19 -4
- package/types/handlebars_helpers/array.d.ts +3 -1
- package/types/handlebars_helpers/comparison.d.ts +55 -19
- package/types/handlebars_helpers/date.d.ts +3 -1
- package/types/handlebars_helpers/html.d.ts +6 -2
- package/types/handlebars_helpers/index.d.ts +73 -9
- package/types/handlebars_helpers/layouts.d.ts +5 -1
- package/types/handlebars_helpers/math.d.ts +21 -7
- package/types/handlebars_helpers/number.d.ts +3 -1
- package/types/handlebars_helpers/object.d.ts +6 -2
- package/types/handlebars_helpers/string.d.ts +9 -3
- package/types/index.d.ts +92 -5
- package/types/interfaces/AuthenticationConfig.d.ts +38 -1
- package/types/interfaces/BasicConfig.d.ts +26 -1
- package/types/interfaces/DatabaseConfig.d.ts +45 -1
- package/types/interfaces/LoggingConfig.d.ts +49 -0
- package/types/interfaces/ViewConfig.d.ts +21 -2
- package/types/interfaces/index.d.ts +25 -11
- package/types/middlewares/Authentication.d.ts +43 -6
- package/types/middlewares/CORS.d.ts +23 -5
- package/types/middlewares/Environment.d.ts +30 -4
- package/types/middlewares/ErrorHandler.d.ts +27 -5
- package/types/middlewares/Global.d.ts +20 -6
- package/types/middlewares/Http.d.ts +22 -5
- package/types/middlewares/Local.d.ts +35 -8
- package/types/middlewares/View.d.ts +39 -8
- package/types/middlewares/index.d.ts +47 -7
- package/types/mount.d.ts +16 -3
- package/types/routing/Router.d.ts +49 -7
- package/types/routing/index.d.ts +37 -1
- package/types/services/Authentication.d.ts +79 -16
- package/types/services/index.d.ts +33 -1
- package/types/types/global.d.ts +29 -8
- package/types/utils/Types.d.ts +5 -3
- package/types/utils/index.d.ts +71 -9
- package/types/utils/isArray.d.ts +12 -3
- package/types/utils/isAsyncFunction.d.ts +12 -5
- package/types/utils/isFunction.d.ts +13 -6
- package/types/utils/isObject.d.ts +14 -3
- package/types/utils/isString.d.ts +15 -4
- package/types/utils/loadAuthenticationConfig.d.ts +13 -3
- package/types/utils/loadBasicConfig.d.ts +13 -3
- package/types/utils/loadDatabaseConfig.d.ts +34 -3
- package/types/utils/loadLoggingConfig.d.ts +16 -0
- package/types/utils/loadViewConfig.d.ts +28 -3
- package/types/database/Database.d.ts +0 -18
- package/types/interfaces/BoundingBox.d.ts +0 -25
- package/types/interfaces/FaceDetails.d.ts +0 -30
- package/types/interfaces/FaceDetailsEmotions.d.ts +0 -40
- package/types/interfaces/FaceMatch.d.ts +0 -31
- package/types/interfaces/IndexFaceDetails.d.ts +0 -29
- package/types/interfaces/RekognitionOptions.d.ts +0 -26
- package/types/interfaces/SesOptions.d.ts +0 -27
|
@@ -1,18 +1,49 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
/**
|
|
3
|
-
* Enable Handlebars template engine.
|
|
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
|
+
* ```
|
|
4
21
|
*/
|
|
5
|
-
export default class {
|
|
22
|
+
export default class View {
|
|
6
23
|
/**
|
|
7
|
-
* Mount on application.
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
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
|
+
* ```
|
|
10
35
|
*/
|
|
11
36
|
static mount(app: express.Express): Promise<void>;
|
|
12
37
|
/**
|
|
13
|
-
* Mount middleware to be executed just before
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
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
|
+
* ```
|
|
16
47
|
*/
|
|
17
48
|
static mountBeforeRender(app: express.Express): Promise<void>;
|
|
18
49
|
}
|
|
@@ -1,7 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Express middleware components for Express Sweet.
|
|
3
|
+
*
|
|
4
|
+
* Provides a collection of middleware classes that handle various aspects of Express applications
|
|
5
|
+
* including CORS, authentication, view templating, error handling, and environment setup.
|
|
6
|
+
* These middleware are automatically mounted by the main mount function.
|
|
7
|
+
*
|
|
8
|
+
* @module middlewares
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* // Manual middleware mounting (usually not needed)
|
|
12
|
+
* import * as expx from 'express-sweet';
|
|
13
|
+
*
|
|
14
|
+
* const app = express();
|
|
15
|
+
* await expx.middlewares.Global.mount();
|
|
16
|
+
* await expx.middlewares.Environment.mount();
|
|
17
|
+
* await expx.middlewares.Http.mount(app);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Cross-Origin Resource Sharing (CORS) middleware
|
|
22
|
+
*/
|
|
23
|
+
export { default as CORS } from './CORS';
|
|
24
|
+
/**
|
|
25
|
+
* Environment variables loading middleware
|
|
26
|
+
*/
|
|
27
|
+
export { default as Environment } from './Environment';
|
|
28
|
+
/**
|
|
29
|
+
* Global variables setup middleware
|
|
30
|
+
*/
|
|
31
|
+
export { default as Global } from './Global';
|
|
32
|
+
/**
|
|
33
|
+
* HTTP parsing and static file serving middleware
|
|
34
|
+
*/
|
|
35
|
+
export { default as Http } from './Http';
|
|
36
|
+
/**
|
|
37
|
+
* Local template variables middleware
|
|
38
|
+
*/
|
|
39
|
+
export { default as Local } from './Local';
|
|
40
|
+
/**
|
|
41
|
+
* Handlebars view engine middleware
|
|
42
|
+
*/
|
|
43
|
+
export { default as View } from './View';
|
|
44
|
+
/**
|
|
45
|
+
* Error handling middleware
|
|
46
|
+
*/
|
|
47
|
+
export { default as ErrorHandler } from './ErrorHandler';
|
package/types/mount.d.ts
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
/**
|
|
3
|
-
* Mount extensions on your application.
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
3
|
+
* Mount Express Sweet extensions on your Express application.
|
|
4
|
+
* Initializes all middleware in a specific order: Global → Environment → Database → HTTP → View → CORS → Local → Authentication → Router → Error Handler.
|
|
5
|
+
* @param {express.Express} app Express application instance
|
|
6
|
+
* @returns {Promise<void>}
|
|
7
|
+
* @example
|
|
8
|
+
* ```js
|
|
9
|
+
* import express from 'express';
|
|
10
|
+
* import * as expx from 'express-sweet';
|
|
11
|
+
*
|
|
12
|
+
* const app = express();
|
|
13
|
+
* await expx.mount(app);
|
|
14
|
+
*
|
|
15
|
+
* app.listen(3000, () => {
|
|
16
|
+
* console.log('Server running on port 3000');
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
6
19
|
*/
|
|
7
20
|
declare const _default: (app: express.Express) => Promise<void>;
|
|
8
21
|
export default _default;
|
|
@@ -1,14 +1,56 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
/**
|
|
3
|
-
* Set up URL routing.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
+
* ```
|
|
6
40
|
*/
|
|
7
|
-
export default class {
|
|
41
|
+
export default class Router {
|
|
8
42
|
/**
|
|
9
|
-
* Mount on application.
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
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
|
+
* ```
|
|
12
54
|
*/
|
|
13
55
|
static mount(app: express.Express): Promise<void>;
|
|
14
56
|
}
|
package/types/routing/index.d.ts
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
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,32 +1,95 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
/**
|
|
3
|
-
* User authentication service.
|
|
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
|
+
* ```
|
|
4
29
|
*/
|
|
5
|
-
export default class {
|
|
30
|
+
export default class Authentication {
|
|
6
31
|
/**
|
|
7
|
-
* Authenticate the user.
|
|
8
|
-
*
|
|
9
|
-
* @param {express.
|
|
10
|
-
* @param {express.
|
|
11
|
-
* @
|
|
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
|
+
* ```
|
|
12
47
|
*/
|
|
13
48
|
static authenticate(req: express.Request, res: express.Response, next: express.NextFunction): Promise<boolean>;
|
|
14
49
|
/**
|
|
15
|
-
* Log out the user.
|
|
16
|
-
* @param {express.Request} req The
|
|
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
|
+
* ```
|
|
17
63
|
*/
|
|
18
64
|
static logout(req: express.Request): void;
|
|
19
65
|
/**
|
|
20
|
-
* Redirects to the page
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
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
|
+
* ```
|
|
23
77
|
*/
|
|
24
78
|
static successRedirect(res: express.Response): Promise<void>;
|
|
25
79
|
/**
|
|
26
|
-
* Redirects to the page
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @
|
|
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
|
+
* ```
|
|
30
93
|
*/
|
|
31
94
|
static failureRedirect(req: express.Request, res: express.Response): Promise<void>;
|
|
32
95
|
}
|
|
@@ -1 +1,33 @@
|
|
|
1
|
-
|
|
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';
|
package/types/types/global.d.ts
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
|
3
12
|
*/
|
|
4
13
|
declare global {
|
|
5
14
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
*/
|
|
9
24
|
var APP_DIR: string;
|
|
10
25
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
*/
|
|
15
36
|
var loadedEnv: boolean;
|
|
16
37
|
}
|
|
17
38
|
export {};
|
package/types/utils/Types.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Type judgment processing.
|
|
3
3
|
*/
|
|
4
|
-
export default class {
|
|
4
|
+
export default class Types {
|
|
5
5
|
/**
|
|
6
6
|
* Returns true for asynchronous functions, false otherwise.
|
|
7
7
|
* @param {Function} value.
|
|
8
|
-
* @
|
|
8
|
+
* @returns {boolean}
|
|
9
9
|
* @example
|
|
10
|
+
* ```js
|
|
10
11
|
* Types.isAsyncFunction(async () => {});// true
|
|
11
12
|
* Types.isAsyncFunction(() => {});// false
|
|
13
|
+
* ```
|
|
12
14
|
*/
|
|
13
15
|
static isAsyncFunction(value: Function): boolean;
|
|
14
16
|
/**
|
|
15
17
|
* Return true if `val` is a non-empty string.
|
|
16
18
|
* @param {any} `val` The value to check
|
|
17
|
-
* @
|
|
19
|
+
* @returns {Boolean}
|
|
18
20
|
* @api public
|
|
19
21
|
*/
|
|
20
22
|
static isString(value: any): boolean;
|
package/types/utils/index.d.ts
CHANGED
|
@@ -1,9 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for Express Sweet.
|
|
3
|
+
*
|
|
4
|
+
* Provides type checking functions and configuration loading utilities
|
|
5
|
+
* used throughout the Express Sweet framework.
|
|
6
|
+
*
|
|
7
|
+
* @module utils
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* // Using type checking utilities
|
|
11
|
+
* import * as expx from 'express-sweet';
|
|
12
|
+
*
|
|
13
|
+
* if (expx.utils.isArray(value)) {
|
|
14
|
+
* // Handle array
|
|
15
|
+
* }
|
|
16
|
+
* if (expx.utils.isAsyncFunction(handler)) {
|
|
17
|
+
* await handler();
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```js
|
|
23
|
+
* // Using configuration loaders
|
|
24
|
+
* import * as expx from 'express-sweet';
|
|
25
|
+
*
|
|
26
|
+
* const basicConfig = await expx.utils.loadBasicConfig();
|
|
27
|
+
* const dbConfig = await expx.utils.loadDatabaseConfig();
|
|
28
|
+
* const authConfig = await expx.utils.loadAuthenticationConfig();
|
|
29
|
+
* const loggingConfig = await expx.utils.loadLoggingConfig();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Check if value is an array using Object.prototype.toString
|
|
34
|
+
*/
|
|
35
|
+
export { default as isArray } from './isArray';
|
|
36
|
+
/**
|
|
37
|
+
* Check if value is specifically an async function
|
|
38
|
+
*/
|
|
39
|
+
export { default as isAsyncFunction } from './isAsyncFunction';
|
|
40
|
+
/**
|
|
41
|
+
* Check if value is a function (including async functions)
|
|
42
|
+
*/
|
|
43
|
+
export { default as isFunction } from './isFunction';
|
|
44
|
+
/**
|
|
45
|
+
* Check if value is a plain object (excludes arrays and null)
|
|
46
|
+
*/
|
|
47
|
+
export { default as isObject } from './isObject';
|
|
48
|
+
/**
|
|
49
|
+
* Check if value is a non-empty string
|
|
50
|
+
*/
|
|
51
|
+
export { default as isString } from './isString';
|
|
52
|
+
/**
|
|
53
|
+
* Load authentication configuration from config/authentication.js
|
|
54
|
+
*/
|
|
55
|
+
export { default as loadAuthenticationConfig } from './loadAuthenticationConfig';
|
|
56
|
+
/**
|
|
57
|
+
* Load basic application configuration from config/config.js
|
|
58
|
+
*/
|
|
59
|
+
export { default as loadBasicConfig } from './loadBasicConfig';
|
|
60
|
+
/**
|
|
61
|
+
* Load database configuration from config/database.js
|
|
62
|
+
*/
|
|
63
|
+
export { default as loadDatabaseConfig } from './loadDatabaseConfig';
|
|
64
|
+
/**
|
|
65
|
+
* Load view configuration from config/view.js
|
|
66
|
+
*/
|
|
67
|
+
export { default as loadViewConfig } from './loadViewConfig';
|
|
68
|
+
/**
|
|
69
|
+
* Load logging configuration from config/logging.js
|
|
70
|
+
*/
|
|
71
|
+
export { default as loadLoggingConfig } from './loadLoggingConfig';
|
package/types/utils/isArray.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Check if
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* Check if a value is an array using Object.prototype.toString.
|
|
3
|
+
* More reliable than instanceof Array for cross-frame scenarios.
|
|
4
|
+
* @param {any} value The value to check
|
|
5
|
+
* @returns {boolean} Returns true if value is an array, false otherwise
|
|
6
|
+
* @example
|
|
7
|
+
* ```js
|
|
8
|
+
* import isArray from '~/utils/isArray';
|
|
9
|
+
*
|
|
10
|
+
* isArray([1, 2, 3]); // true
|
|
11
|
+
* isArray('hello'); // false
|
|
12
|
+
* isArray({0: 'a', 1: 'b', length: 2}); // false (array-like object)
|
|
13
|
+
* ```
|
|
5
14
|
*/
|
|
6
15
|
declare const _default: (value: any) => boolean;
|
|
7
16
|
export default _default;
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* Check if a value is specifically an async function.
|
|
3
|
+
* Returns true only for async functions, false for regular functions and other values.
|
|
4
|
+
* @param {any} value The value to check
|
|
5
|
+
* @returns {boolean} Returns true if value is an async function, false otherwise
|
|
5
6
|
* @example
|
|
6
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import isAsyncFunction from '~/utils/isAsyncFunction';
|
|
9
|
+
*
|
|
10
|
+
* isAsyncFunction(async () => {}); // true
|
|
11
|
+
* isAsyncFunction(() => {}); // false
|
|
12
|
+
* isAsyncFunction(function() {}); // false
|
|
13
|
+
* isAsyncFunction(''); // false
|
|
14
|
+
* ```
|
|
8
15
|
*/
|
|
9
16
|
declare const _default: (value: any) => boolean;
|
|
10
17
|
export default _default;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* Check if a value is a function (including async functions).
|
|
3
|
+
* Returns true for both regular and async functions, false otherwise.
|
|
4
|
+
* @param {any} value The value to check
|
|
5
|
+
* @returns {boolean} Returns true if value is a function, false otherwise
|
|
5
6
|
* @example
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import isFunction from '~/utils/isFunction';
|
|
9
|
+
*
|
|
10
|
+
* isFunction(() => {}); // true
|
|
11
|
+
* isFunction(async () => {}); // true
|
|
12
|
+
* isFunction(function() {}); // true
|
|
13
|
+
* isFunction(''); // false
|
|
14
|
+
* isFunction({}); // false
|
|
15
|
+
* ```
|
|
9
16
|
*/
|
|
10
17
|
declare const _default: (value: any) => boolean;
|
|
11
18
|
export default _default;
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Check if
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* Check if a value is a plain object (excludes arrays and null).
|
|
3
|
+
* Returns true only for plain objects, false for arrays, null, or other types.
|
|
4
|
+
* @param {any} value The value to check
|
|
5
|
+
* @returns {boolean} Returns true if value is a plain object, false otherwise
|
|
6
|
+
* @example
|
|
7
|
+
* ```js
|
|
8
|
+
* import isObject from '~/utils/isObject';
|
|
9
|
+
*
|
|
10
|
+
* isObject({}); // true
|
|
11
|
+
* isObject({a: 1}); // true
|
|
12
|
+
* isObject([]); // false (array)
|
|
13
|
+
* isObject(null); // false
|
|
14
|
+
* isObject('string'); // false
|
|
15
|
+
* ```
|
|
5
16
|
*/
|
|
6
17
|
declare const _default: (value: any) => boolean;
|
|
7
18
|
export default _default;
|