express-sweet-generator 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,69 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.0.12] - 2023/7/17
5
+ ### Changed
6
+ - The beforeRender option in the view configuration (config/view.js) can now specify asynchronous functions.
7
+
8
+ ### Added
9
+ - New Math-related view helpers have been added.
10
+
11
+ See [here](https://takuya-motoshima.github.io/express-sweet/#view-math-helper) how to use the helper.
12
+
13
+ Added view helpers:
14
+ |Helper|Description|
15
+ |--|--|
16
+ |add|Calculates the sum of two numbers.|
17
+ |sub|Calculates the difference of the given values.|
18
+ |multiply|Calculate the multiplication of the given values.|
19
+ |divide|Compute the division of the given values.|
20
+ |ceil|Round up the value.|
21
+ |floor|Rounds down a number.|
22
+ |abs|Returns an absolute value.|
23
+
24
+ ## [1.0.11] - 2023/7/12
25
+ ### Changed
26
+ - Moved the Ajax determination option (is_ajax) in the authentication configuration (config/authentication.js) to the basic configuration (config/config.js).
27
+
28
+ config/config.js:
29
+ ```js
30
+ /**
31
+ * How to determine if it is an ajax request.
32
+ * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
33
+ * 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)".
34
+ *
35
+ * @type {(req: express.Request) => boolean}
36
+ * @example
37
+ * is_ajax: req => {
38
+ * // If the request URL begins with /api, it is assumed to be Ajax.
39
+ * return /^\/api/.test(req.path);
40
+ * // return !!req.xhr;
41
+ * }
42
+ */
43
+ is_ajax: req => !!req.xhr,
44
+ ```
45
+ - The error handle option (error_handler) in the basic configuration (config/config.js) has been removed and an option to hook error handles (hook_handle_error) added instead.
46
+
47
+ config/config.js:
48
+ ```js
49
+ /**
50
+ * Hooks the default behavior on request errors.
51
+ * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
52
+ *
53
+ * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
54
+ * @example
55
+ * hook_handle_error: (err, req, res, next) => {
56
+ * if (err.status === 404)
57
+ * // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
58
+ * res.render('error-404');
59
+ * else
60
+ * // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
61
+ * res.render('error-unknown');
62
+ * },
63
+ */
64
+ hook_handle_error: undefined,
65
+ ```
66
+
4
67
  ## [1.0.10] - 2023/7/11
5
68
  ### Changed
6
69
  - The URL to redirect to when login fails (failure_redirect) option in the authentication configuration (config/authentication.js) can now be defined with a function.
@@ -197,4 +260,6 @@ All notable changes to this project will be documented in this file.
197
260
  [1.0.7]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.6...v1.0.7
198
261
  [1.0.8]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.7...v1.0.8
199
262
  [1.0.9]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.8...v1.0.9
200
- [1.0.10]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.9...v1.0.10
263
+ [1.0.10]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.9...v1.0.10
264
+ [1.0.11]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.10...v1.0.11
265
+ [1.0.12]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.11...v1.0.12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Express Sweet application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -106,19 +106,4 @@ module.exports = {
106
106
  * @type {number}
107
107
  */
108
108
  expiration: 24 * 3600000,
109
-
110
- /**
111
- * How to determine if it is an ajax request.
112
- * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
113
- * 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)".
114
- *
115
- * @type {(req: express.Request) => boolean}
116
- * @example
117
- * is_ajax: req => {
118
- * // If the request URL begins with /api, it is assumed to be Ajax.
119
- * return /^\/api/.test(req.path);
120
- * // return !!req.xhr;
121
- * }
122
- */
123
- is_ajax: req => !!req.xhr
124
109
  }
@@ -51,28 +51,34 @@ module.exports = {
51
51
  },
52
52
 
53
53
  /**
54
- * This is a hook for error handling.
55
- * For example, you can use it when you want to send an external notification of the error received by this hook.
56
- *
54
+ * How to determine if it is an ajax request.
55
+ * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
56
+ * 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)".
57
+ *
58
+ * @type {(req: express.Request) => boolean}
59
+ * @example
60
+ * is_ajax: req => {
61
+ * // If the request URL begins with /api, it is assumed to be Ajax.
62
+ * return /^\/api/.test(req.path);
63
+ * // return !!req.xhr;
64
+ * }
65
+ */
66
+ is_ajax: req => !!req.xhr,
67
+
68
+ /**
69
+ * Hooks the default behavior on request errors.
70
+ * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
71
+ *
72
+ * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
57
73
  * @example
58
- * error_handler: async err => {
59
- * // Notify system administrator of error.
60
- * return new Promise((resolve, reject) => {
61
- * const sendmail = require('sendmail')();
62
- * sendmail({
63
- * from: 'no-reply@example.com',
64
- * to: 'administrator@example.com',
65
- * subject: 'Error occurred',
66
- * text: err.message
67
- * }, err => {
68
- * err ? reject(err) : resolve();
69
- * });
70
- * });
71
- * }
72
- *
73
- * @type {(err: any): void|Promise<void>}
74
+ * hook_handle_error: (err, req, res, next) => {
75
+ * if (err.status === 404)
76
+ * // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
77
+ * res.render('error-404');
78
+ * else
79
+ * // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
80
+ * res.render('error-unknown');
81
+ * },
74
82
  */
75
- error_handler: err => {
76
- console.error(`An error has occurred. Error message: ${err.message}`);
77
- }
83
+ hook_handle_error: undefined,
78
84
  }
@@ -44,7 +44,7 @@ module.exports = {
44
44
  * res.locals.message = 'Hello World';
45
45
  * }
46
46
  *
47
- * @type {(res: express.Response) => void}
47
+ * @type {(res: express.Response) => Promise<void>|void}
48
48
  */
49
49
  beforeRender: (req, res) => {}
50
50
  }
@@ -15,7 +15,6 @@ export default class extends Modal {
15
15
  let user;
16
16
  if (this.#mode === 'update')
17
17
  user = (await this.#userApi.getUser(this.#userId)).data;
18
- console.log('user=', user);
19
18
  const node = this.render(user);
20
19
  const instance = new bootstrap.Modal(node);
21
20
  this.#ref = selectRef(node);
@@ -106,19 +106,4 @@ export default {
106
106
  * @type {number}
107
107
  */
108
108
  expiration: 24 * 3600000,
109
-
110
- /**
111
- * How to determine if it is an ajax request.
112
- * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
113
- * 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)".
114
- *
115
- * @type {(req: express.Request) => boolean}
116
- * @example
117
- * is_ajax: req => {
118
- * // If the request URL begins with /api, it is assumed to be Ajax.
119
- * return /^\/api/.test(req.path);
120
- * // return !!req.xhr;
121
- * }
122
- */
123
- is_ajax: req => !!req.xhr
124
109
  }
@@ -51,28 +51,34 @@ export default {
51
51
  },
52
52
 
53
53
  /**
54
- * This is a hook for error handling.
55
- * For example, you can use it when you want to send an external notification of the error received by this hook.
56
- *
54
+ * How to determine if it is an ajax request.
55
+ * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
56
+ * 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)".
57
+ *
58
+ * @type {(req: express.Request) => boolean}
59
+ * @example
60
+ * is_ajax: req => {
61
+ * // If the request URL begins with /api, it is assumed to be Ajax.
62
+ * return /^\/api/.test(req.path);
63
+ * // return !!req.xhr;
64
+ * }
65
+ */
66
+ is_ajax: req => !!req.xhr,
67
+
68
+ /**
69
+ * Hooks the default behavior on request errors.
70
+ * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
71
+ *
72
+ * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
57
73
  * @example
58
- * error_handler: async err => {
59
- * // Notify system administrator of error.
60
- * return new Promise((resolve, reject) => {
61
- * const sendmail = require('sendmail')();
62
- * sendmail({
63
- * from: 'no-reply@example.com',
64
- * to: 'administrator@example.com',
65
- * subject: 'Error occurred',
66
- * text: err.message
67
- * }, err => {
68
- * err ? reject(err) : resolve();
69
- * });
70
- * });
71
- * }
72
- *
73
- * @type {(err: any): void|Promise<void>}
74
+ * hook_handle_error: (err, req, res, next) => {
75
+ * if (err.status === 404)
76
+ * // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
77
+ * res.render('error-404');
78
+ * else
79
+ * // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
80
+ * res.render('error-unknown');
81
+ * },
74
82
  */
75
- error_handler: err => {
76
- console.error(`An error has occurred. Error message: ${err.message}`);
77
- }
83
+ hook_handle_error: undefined,
78
84
  }
@@ -44,7 +44,7 @@ export default {
44
44
  * res.locals.message = 'Hello World';
45
45
  * }
46
46
  *
47
- * @type {(res: express.Response) => void}
47
+ * @type {(res: express.Response) => Promise<void>|void}
48
48
  */
49
49
  beforeRender: (req, res) => {}
50
50
  }