@jderstd/hono 0.7.0-dev.0 → 0.7.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.
@@ -1 +1 @@
1
- {"version":3,"file":"on-error.js","names":["JderHttpException","HTTPException","res: Response","code: ResponseErrorCode","ResponseErrorCode","createJsonResponse"],"sources":["../src/handlers/on-error.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { HTTPResponseError } from \"hono/types\";\nimport type { StatusCode } from \"hono/utils/http-status\";\n\nimport { HTTPException } from \"hono/http-exception\";\n\nimport { createJsonResponse } from \"#/response\";\nimport { ResponseErrorCode } from \"#/response/error\";\nimport { JderHttpException } from \"#/response/error/http\";\n\n/** Options for `onErrorHandler` function. */\ntype OnErrorHandlerOptions = {\n /**\n * Whether show more information.\n * By default, it's `false`.\n */\n verbose?: boolean;\n};\n\n/**\n * On error handler.\n *\n * Following responses could be returned on error:\n *\n * ```jsonc\n * // Status: 400\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"bad_request\"\n * }\n * ]\n * }\n * ```\n *\n * ```jsonc\n * // Status: 500\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"server\"\n * }\n * ]\n * }\n * ```\n *\n * ### Examples\n *\n * Basic example of using `onErrorHandler` handler:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { onErrorHandler } from \"@jderstd/hono/on-error\";\n *\n * const app: Hono = new Hono();\n *\n * app.onError(onErrorHandler());\n * ```\n *\n * Show more information with `verbose` option:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { onErrorHandler } from \"@jderstd/hono/on-error\";\n *\n * const app: Hono = new Hono();\n *\n * app.onError(onErrorHandler({ verbose: true }));\n * ```\n */\nconst onErrorHandler = (\n options?: OnErrorHandlerOptions,\n): ((err: Error | HTTPResponseError, c: Context) => Response) => {\n return (err: Error | HTTPResponseError, c: Context): Response => {\n if (err instanceof JderHttpException) return err.getResponse();\n\n if (err instanceof HTTPException) {\n const res: Response = err.getResponse();\n\n const status: StatusCode = res.status as StatusCode;\n\n const code: ResponseErrorCode =\n status >= 500\n ? ResponseErrorCode.Server\n : ResponseErrorCode.BadRequest;\n\n return createJsonResponse(c, {\n status: res.status as StatusCode,\n errors: [\n {\n code,\n ...(options?.verbose && {\n message: err.message,\n }),\n },\n ],\n });\n }\n\n return createJsonResponse(c, {\n status: 500,\n errors: [\n {\n code: ResponseErrorCode.Server,\n ...(options?.verbose && {\n message: err.message,\n }),\n },\n ],\n });\n };\n};\n\nexport { onErrorHandler };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,MAAM,kBACF,YAC6D;AAC7D,SAAQ,KAAgC,MAAyB;AAC7D,MAAI,eAAeA,8CAAmB,QAAO,IAAI,aAAa;AAE9D,MAAI,eAAeC,mCAAe;GAC9B,MAAMC,MAAgB,IAAI,aAAa;GAIvC,MAAMC,OAFqB,IAAI,UAGjB,MACJC,+CAAkB,SAClBA,+CAAkB;AAE5B,UAAOC,iCAAmB,GAAG;IACzB,QAAQ,IAAI;IACZ,QAAQ,CACJ;KACI;KACA,GAAI,SAAS,WAAW,EACpB,SAAS,IAAI,SAChB;KACJ,CACJ;IACJ,CAAC;;AAGN,SAAOA,iCAAmB,GAAG;GACzB,QAAQ;GACR,QAAQ,CACJ;IACI,MAAMD,+CAAkB;IACxB,GAAI,SAAS,WAAW,EACpB,SAAS,IAAI,SAChB;IACJ,CACJ;GACJ,CAAC"}
1
+ {"version":3,"file":"on-error.js","names":["JderHttpException","HTTPException","res: Response","code: ResponseErrorCode","ResponseErrorCode","createJsonResponse"],"sources":["../src/handlers/on-error.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { HTTPResponseError } from \"hono/types\";\nimport type { StatusCode } from \"hono/utils/http-status\";\n\nimport { HTTPException } from \"hono/http-exception\";\n\nimport { createJsonResponse } from \"#/response\";\nimport { ResponseErrorCode } from \"#/response/error\";\nimport { JderHttpException } from \"#/response/error/http\";\n\n/** Options for `onErrorHandler` function. */\ntype OnErrorHandlerOptions = {\n /**\n * Whether show more information.\n * By default, it's `false`.\n */\n verbose?: boolean;\n};\n\n/**\n * On error handler.\n *\n * Following responses could be returned on error:\n *\n * ```jsonc\n * // Status: 400\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"bad_request\"\n * }\n * ]\n * }\n * ```\n *\n * ```jsonc\n * // Status: 500\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"server\"\n * }\n * ]\n * }\n * ```\n *\n * ### Examples\n *\n * Basic example of using `onErrorHandler` handler:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { onErrorHandler } from \"@jderstd/hono/on-error\";\n *\n * const app: Hono = new Hono();\n *\n * app.onError(onErrorHandler());\n * ```\n *\n * Show more information with `verbose` option:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { onErrorHandler } from \"@jderstd/hono/on-error\";\n *\n * const app: Hono = new Hono();\n *\n * app.onError(onErrorHandler({ verbose: true }));\n * ```\n */\nconst onErrorHandler = (\n options?: OnErrorHandlerOptions,\n): ((err: Error | HTTPResponseError, c: Context) => Response) => {\n return (err: Error | HTTPResponseError, c: Context): Response => {\n // HTTP Exception for JDER format response\n if (err instanceof JderHttpException) return err.getResponse();\n\n // HTTP Exception\n if (err instanceof HTTPException) {\n const res: Response = err.getResponse();\n\n const status: StatusCode = res.status as StatusCode;\n\n const code: ResponseErrorCode =\n status >= 500\n ? ResponseErrorCode.Server\n : ResponseErrorCode.BadRequest;\n\n return createJsonResponse(c, {\n status: res.status as StatusCode,\n errors: [\n {\n code,\n ...(options?.verbose && {\n message: err.message,\n }),\n },\n ],\n });\n }\n\n // Internal server error\n return createJsonResponse(c, {\n status: 500,\n errors: [\n {\n code: ResponseErrorCode.Server,\n ...(options?.verbose && {\n message: err.message,\n }),\n },\n ],\n });\n };\n};\n\nexport { onErrorHandler };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,MAAM,kBACF,YAC6D;AAC7D,SAAQ,KAAgC,MAAyB;AAE7D,MAAI,eAAeA,8CAAmB,QAAO,IAAI,aAAa;AAG9D,MAAI,eAAeC,mCAAe;GAC9B,MAAMC,MAAgB,IAAI,aAAa;GAIvC,MAAMC,OAFqB,IAAI,UAGjB,MACJC,+CAAkB,SAClBA,+CAAkB;AAE5B,UAAOC,iCAAmB,GAAG;IACzB,QAAQ,IAAI;IACZ,QAAQ,CACJ;KACI;KACA,GAAI,SAAS,WAAW,EACpB,SAAS,IAAI,SAChB;KACJ,CACJ;IACJ,CAAC;;AAIN,SAAOA,iCAAmB,GAAG;GACzB,QAAQ;GACR,QAAQ,CACJ;IACI,MAAMD,+CAAkB;IACxB,GAAI,SAAS,WAAW,EACpB,SAAS,IAAI,SAChB;IACJ,CACJ;GACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"on-error.mjs","names":["res: Response","code: ResponseErrorCode"],"sources":["../src/handlers/on-error.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { HTTPResponseError } from \"hono/types\";\nimport type { StatusCode } from \"hono/utils/http-status\";\n\nimport { HTTPException } from \"hono/http-exception\";\n\nimport { createJsonResponse } from \"#/response\";\nimport { ResponseErrorCode } from \"#/response/error\";\nimport { JderHttpException } from \"#/response/error/http\";\n\n/** Options for `onErrorHandler` function. */\ntype OnErrorHandlerOptions = {\n /**\n * Whether show more information.\n * By default, it's `false`.\n */\n verbose?: boolean;\n};\n\n/**\n * On error handler.\n *\n * Following responses could be returned on error:\n *\n * ```jsonc\n * // Status: 400\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"bad_request\"\n * }\n * ]\n * }\n * ```\n *\n * ```jsonc\n * // Status: 500\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"server\"\n * }\n * ]\n * }\n * ```\n *\n * ### Examples\n *\n * Basic example of using `onErrorHandler` handler:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { onErrorHandler } from \"@jderstd/hono/on-error\";\n *\n * const app: Hono = new Hono();\n *\n * app.onError(onErrorHandler());\n * ```\n *\n * Show more information with `verbose` option:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { onErrorHandler } from \"@jderstd/hono/on-error\";\n *\n * const app: Hono = new Hono();\n *\n * app.onError(onErrorHandler({ verbose: true }));\n * ```\n */\nconst onErrorHandler = (\n options?: OnErrorHandlerOptions,\n): ((err: Error | HTTPResponseError, c: Context) => Response) => {\n return (err: Error | HTTPResponseError, c: Context): Response => {\n if (err instanceof JderHttpException) return err.getResponse();\n\n if (err instanceof HTTPException) {\n const res: Response = err.getResponse();\n\n const status: StatusCode = res.status as StatusCode;\n\n const code: ResponseErrorCode =\n status >= 500\n ? ResponseErrorCode.Server\n : ResponseErrorCode.BadRequest;\n\n return createJsonResponse(c, {\n status: res.status as StatusCode,\n errors: [\n {\n code,\n ...(options?.verbose && {\n message: err.message,\n }),\n },\n ],\n });\n }\n\n return createJsonResponse(c, {\n status: 500,\n errors: [\n {\n code: ResponseErrorCode.Server,\n ...(options?.verbose && {\n message: err.message,\n }),\n },\n ],\n });\n };\n};\n\nexport { onErrorHandler };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,MAAM,kBACF,YAC6D;AAC7D,SAAQ,KAAgC,MAAyB;AAC7D,MAAI,eAAe,kBAAmB,QAAO,IAAI,aAAa;AAE9D,MAAI,eAAe,eAAe;GAC9B,MAAMA,MAAgB,IAAI,aAAa;GAIvC,MAAMC,OAFqB,IAAI,UAGjB,MACJ,kBAAkB,SAClB,kBAAkB;AAE5B,UAAO,mBAAmB,GAAG;IACzB,QAAQ,IAAI;IACZ,QAAQ,CACJ;KACI;KACA,GAAI,SAAS,WAAW,EACpB,SAAS,IAAI,SAChB;KACJ,CACJ;IACJ,CAAC;;AAGN,SAAO,mBAAmB,GAAG;GACzB,QAAQ;GACR,QAAQ,CACJ;IACI,MAAM,kBAAkB;IACxB,GAAI,SAAS,WAAW,EACpB,SAAS,IAAI,SAChB;IACJ,CACJ;GACJ,CAAC"}
1
+ {"version":3,"file":"on-error.mjs","names":["res: Response","code: ResponseErrorCode"],"sources":["../src/handlers/on-error.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { HTTPResponseError } from \"hono/types\";\nimport type { StatusCode } from \"hono/utils/http-status\";\n\nimport { HTTPException } from \"hono/http-exception\";\n\nimport { createJsonResponse } from \"#/response\";\nimport { ResponseErrorCode } from \"#/response/error\";\nimport { JderHttpException } from \"#/response/error/http\";\n\n/** Options for `onErrorHandler` function. */\ntype OnErrorHandlerOptions = {\n /**\n * Whether show more information.\n * By default, it's `false`.\n */\n verbose?: boolean;\n};\n\n/**\n * On error handler.\n *\n * Following responses could be returned on error:\n *\n * ```jsonc\n * // Status: 400\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"bad_request\"\n * }\n * ]\n * }\n * ```\n *\n * ```jsonc\n * // Status: 500\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"server\"\n * }\n * ]\n * }\n * ```\n *\n * ### Examples\n *\n * Basic example of using `onErrorHandler` handler:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { onErrorHandler } from \"@jderstd/hono/on-error\";\n *\n * const app: Hono = new Hono();\n *\n * app.onError(onErrorHandler());\n * ```\n *\n * Show more information with `verbose` option:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { onErrorHandler } from \"@jderstd/hono/on-error\";\n *\n * const app: Hono = new Hono();\n *\n * app.onError(onErrorHandler({ verbose: true }));\n * ```\n */\nconst onErrorHandler = (\n options?: OnErrorHandlerOptions,\n): ((err: Error | HTTPResponseError, c: Context) => Response) => {\n return (err: Error | HTTPResponseError, c: Context): Response => {\n // HTTP Exception for JDER format response\n if (err instanceof JderHttpException) return err.getResponse();\n\n // HTTP Exception\n if (err instanceof HTTPException) {\n const res: Response = err.getResponse();\n\n const status: StatusCode = res.status as StatusCode;\n\n const code: ResponseErrorCode =\n status >= 500\n ? ResponseErrorCode.Server\n : ResponseErrorCode.BadRequest;\n\n return createJsonResponse(c, {\n status: res.status as StatusCode,\n errors: [\n {\n code,\n ...(options?.verbose && {\n message: err.message,\n }),\n },\n ],\n });\n }\n\n // Internal server error\n return createJsonResponse(c, {\n status: 500,\n errors: [\n {\n code: ResponseErrorCode.Server,\n ...(options?.verbose && {\n message: err.message,\n }),\n },\n ],\n });\n };\n};\n\nexport { onErrorHandler };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,MAAM,kBACF,YAC6D;AAC7D,SAAQ,KAAgC,MAAyB;AAE7D,MAAI,eAAe,kBAAmB,QAAO,IAAI,aAAa;AAG9D,MAAI,eAAe,eAAe;GAC9B,MAAMA,MAAgB,IAAI,aAAa;GAIvC,MAAMC,OAFqB,IAAI,UAGjB,MACJ,kBAAkB,SAClB,kBAAkB;AAE5B,UAAO,mBAAmB,GAAG;IACzB,QAAQ,IAAI;IACZ,QAAQ,CACJ;KACI;KACA,GAAI,SAAS,WAAW,EACpB,SAAS,IAAI,SAChB;KACJ,CACJ;IACJ,CAAC;;AAIN,SAAO,mBAAmB,GAAG;GACzB,QAAQ;GACR,QAAQ,CACJ;IACI,MAAM,kBAAkB;IACxB,GAAI,SAAS,WAAW,EACpB,SAAS,IAAI,SAChB;IACJ,CACJ;GACJ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  const require_index = require('./response/json/index.js');
2
2
  const require_response_error_index = require('./response/error/index.js');
3
- let hono_http_exception = require("hono/http-exception");
3
+ const require_response_error_http = require('./response/error/http.js');
4
4
  let hono_timeout = require("hono/timeout");
5
5
 
6
6
  /** Default maximum time in milliseconds. */
@@ -56,7 +56,7 @@ const timeLimit = (options) => {
56
56
  const status = 504;
57
57
  const code = require_response_error_index.ResponseErrorCode.Timeout;
58
58
  return (0, hono_timeout.timeout)(options?.max ?? 5 * 1e3, (c) => {
59
- return new hono_http_exception.HTTPException(status, { res: require_index.createJsonResponse(c, {
59
+ return new require_response_error_http.JderHttpException(status, { res: require_index.createJsonResponse(c, {
60
60
  status,
61
61
  errors: [{
62
62
  code,
@@ -1 +1 @@
1
- {"version":3,"file":"time-limit.js","names":["status: StatusCode","code: ResponseErrorCode","ResponseErrorCode","HTTPException","createJsonResponse","getResponseErrorMessage"],"sources":["../src/middlewares/time-limit.ts"],"sourcesContent":["/**\n * Time limit module\n * @module middlewares/time-limit\n */\n\nimport type { Context, MiddlewareHandler } from \"hono\";\nimport type { StatusCode } from \"hono/utils/http-status\";\n\nimport { HTTPException } from \"hono/http-exception\";\nimport { timeout } from \"hono/timeout\";\n\nimport { getResponseErrorMessage, ResponseErrorCode } from \"#/response/error\";\nimport { createJsonResponse } from \"#/response/json\";\n\n/** Default maximum time in milliseconds. */\nconst TIME_LIMIT_MAX_DEFAULT = (5 * 1000) as 5000;\n\n/** Options for `timeLimit` middleware. */\ntype TimeLimitOptions = {\n /**\n * Maximum time in milliseconds.\n *\n * By default, it is `TIME_LIMIT_MAX_DEFAULT`.\n */\n max?: number;\n};\n\n/**\n * Time limit middleware.\n *\n * Following error will be returned if the request takes longer than the limit:\n *\n * ```jsonc\n * // Status: 504\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"timeout\",\n * \"message\": \"Request timeout\"\n * }\n * ]\n * }\n * ```\n *\n * For more information, please refer to\n * [Timeout](https://hono.dev/docs/middleware/builtin/timeout).\n *\n * ### Examples\n *\n * A example of using `timeLimit` middleware:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { timeLimit } from \"@jderstd/hono/time-limit\";\n *\n * const app: Hono = new Hono();\n *\n * app.use(timeLimit());\n * ```\n *\n * A example of using `timeLimit` middleware with options:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { timeLimit } from \"@jderstd/hono/time-limit\";\n *\n * const app: Hono = new Hono();\n *\n * app.use(timeLimit({\n * max: 10 * 1000, // 10s\n * }));\n * ```\n */\nconst timeLimit = (options?: TimeLimitOptions): MiddlewareHandler => {\n const status: StatusCode = 504;\n const code: ResponseErrorCode = ResponseErrorCode.Timeout;\n\n return timeout(options?.max ?? 5 * 1000, (c: Context): HTTPException => {\n return new HTTPException(status, {\n res: createJsonResponse(c, {\n status,\n errors: [\n {\n code,\n message: getResponseErrorMessage(code),\n },\n ],\n }),\n });\n });\n};\n\nexport type { TimeLimitOptions };\nexport { timeLimit, TIME_LIMIT_MAX_DEFAULT };\n"],"mappings":";;;;;;AAeA,MAAM,yBAA0B,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DpC,MAAM,aAAa,YAAkD;CACjE,MAAMA,SAAqB;CAC3B,MAAMC,OAA0BC,+CAAkB;AAElD,kCAAe,SAAS,OAAO,IAAI,MAAO,MAA8B;AACpE,SAAO,IAAIC,kCAAc,QAAQ,EAC7B,KAAKC,iCAAmB,GAAG;GACvB;GACA,QAAQ,CACJ;IACI;IACA,SAASC,qDAAwB,KAAK;IACzC,CACJ;GACJ,CAAC,EACL,CAAC;GACJ"}
1
+ {"version":3,"file":"time-limit.js","names":["status: StatusCode","code: ResponseErrorCode","ResponseErrorCode","JderHttpException","createJsonResponse","getResponseErrorMessage"],"sources":["../src/middlewares/time-limit.ts"],"sourcesContent":["/**\n * Time limit module\n * @module middlewares/time-limit\n */\n\nimport type { Context, MiddlewareHandler } from \"hono\";\nimport type { StatusCode } from \"hono/utils/http-status\";\n\nimport { timeout } from \"hono/timeout\";\n\nimport { getResponseErrorMessage, ResponseErrorCode } from \"#/response/error\";\nimport { JderHttpException } from \"#/response/error/http\";\nimport { createJsonResponse } from \"#/response/json\";\n\n/** Default maximum time in milliseconds. */\nconst TIME_LIMIT_MAX_DEFAULT = (5 * 1000) as 5000;\n\n/** Options for `timeLimit` middleware. */\ntype TimeLimitOptions = {\n /**\n * Maximum time in milliseconds.\n *\n * By default, it is `TIME_LIMIT_MAX_DEFAULT`.\n */\n max?: number;\n};\n\n/**\n * Time limit middleware.\n *\n * Following error will be returned if the request takes longer than the limit:\n *\n * ```jsonc\n * // Status: 504\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"timeout\",\n * \"message\": \"Request timeout\"\n * }\n * ]\n * }\n * ```\n *\n * For more information, please refer to\n * [Timeout](https://hono.dev/docs/middleware/builtin/timeout).\n *\n * ### Examples\n *\n * A example of using `timeLimit` middleware:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { timeLimit } from \"@jderstd/hono/time-limit\";\n *\n * const app: Hono = new Hono();\n *\n * app.use(timeLimit());\n * ```\n *\n * A example of using `timeLimit` middleware with options:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { timeLimit } from \"@jderstd/hono/time-limit\";\n *\n * const app: Hono = new Hono();\n *\n * app.use(timeLimit({\n * max: 10 * 1000, // 10s\n * }));\n * ```\n */\nconst timeLimit = (options?: TimeLimitOptions): MiddlewareHandler => {\n const status: StatusCode = 504;\n const code: ResponseErrorCode = ResponseErrorCode.Timeout;\n\n return timeout(\n options?.max ?? 5 * 1000,\n (c: Context): JderHttpException => {\n return new JderHttpException(status, {\n res: createJsonResponse(c, {\n status,\n errors: [\n {\n code,\n message: getResponseErrorMessage(code),\n },\n ],\n }),\n });\n },\n );\n};\n\nexport type { TimeLimitOptions };\nexport { timeLimit, TIME_LIMIT_MAX_DEFAULT };\n"],"mappings":";;;;;;AAeA,MAAM,yBAA0B,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DpC,MAAM,aAAa,YAAkD;CACjE,MAAMA,SAAqB;CAC3B,MAAMC,OAA0BC,+CAAkB;AAElD,kCACI,SAAS,OAAO,IAAI,MACnB,MAAkC;AAC/B,SAAO,IAAIC,8CAAkB,QAAQ,EACjC,KAAKC,iCAAmB,GAAG;GACvB;GACA,QAAQ,CACJ;IACI;IACA,SAASC,qDAAwB,KAAK;IACzC,CACJ;GACJ,CAAC,EACL,CAAC;GAET"}
@@ -1,6 +1,6 @@
1
1
  import { createJsonResponse } from "./response/json/index.mjs";
2
2
  import { ResponseErrorCode, getResponseErrorMessage } from "./response/error/index.mjs";
3
- import { HTTPException } from "hono/http-exception";
3
+ import { JderHttpException } from "./response/error/http.mjs";
4
4
  import { timeout } from "hono/timeout";
5
5
 
6
6
  /** Default maximum time in milliseconds. */
@@ -56,7 +56,7 @@ const timeLimit = (options) => {
56
56
  const status = 504;
57
57
  const code = ResponseErrorCode.Timeout;
58
58
  return timeout(options?.max ?? 5 * 1e3, (c) => {
59
- return new HTTPException(status, { res: createJsonResponse(c, {
59
+ return new JderHttpException(status, { res: createJsonResponse(c, {
60
60
  status,
61
61
  errors: [{
62
62
  code,
@@ -1 +1 @@
1
- {"version":3,"file":"time-limit.mjs","names":["status: StatusCode","code: ResponseErrorCode"],"sources":["../src/middlewares/time-limit.ts"],"sourcesContent":["/**\n * Time limit module\n * @module middlewares/time-limit\n */\n\nimport type { Context, MiddlewareHandler } from \"hono\";\nimport type { StatusCode } from \"hono/utils/http-status\";\n\nimport { HTTPException } from \"hono/http-exception\";\nimport { timeout } from \"hono/timeout\";\n\nimport { getResponseErrorMessage, ResponseErrorCode } from \"#/response/error\";\nimport { createJsonResponse } from \"#/response/json\";\n\n/** Default maximum time in milliseconds. */\nconst TIME_LIMIT_MAX_DEFAULT = (5 * 1000) as 5000;\n\n/** Options for `timeLimit` middleware. */\ntype TimeLimitOptions = {\n /**\n * Maximum time in milliseconds.\n *\n * By default, it is `TIME_LIMIT_MAX_DEFAULT`.\n */\n max?: number;\n};\n\n/**\n * Time limit middleware.\n *\n * Following error will be returned if the request takes longer than the limit:\n *\n * ```jsonc\n * // Status: 504\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"timeout\",\n * \"message\": \"Request timeout\"\n * }\n * ]\n * }\n * ```\n *\n * For more information, please refer to\n * [Timeout](https://hono.dev/docs/middleware/builtin/timeout).\n *\n * ### Examples\n *\n * A example of using `timeLimit` middleware:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { timeLimit } from \"@jderstd/hono/time-limit\";\n *\n * const app: Hono = new Hono();\n *\n * app.use(timeLimit());\n * ```\n *\n * A example of using `timeLimit` middleware with options:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { timeLimit } from \"@jderstd/hono/time-limit\";\n *\n * const app: Hono = new Hono();\n *\n * app.use(timeLimit({\n * max: 10 * 1000, // 10s\n * }));\n * ```\n */\nconst timeLimit = (options?: TimeLimitOptions): MiddlewareHandler => {\n const status: StatusCode = 504;\n const code: ResponseErrorCode = ResponseErrorCode.Timeout;\n\n return timeout(options?.max ?? 5 * 1000, (c: Context): HTTPException => {\n return new HTTPException(status, {\n res: createJsonResponse(c, {\n status,\n errors: [\n {\n code,\n message: getResponseErrorMessage(code),\n },\n ],\n }),\n });\n });\n};\n\nexport type { TimeLimitOptions };\nexport { timeLimit, TIME_LIMIT_MAX_DEFAULT };\n"],"mappings":";;;;;;AAeA,MAAM,yBAA0B,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DpC,MAAM,aAAa,YAAkD;CACjE,MAAMA,SAAqB;CAC3B,MAAMC,OAA0B,kBAAkB;AAElD,QAAO,QAAQ,SAAS,OAAO,IAAI,MAAO,MAA8B;AACpE,SAAO,IAAI,cAAc,QAAQ,EAC7B,KAAK,mBAAmB,GAAG;GACvB;GACA,QAAQ,CACJ;IACI;IACA,SAAS,wBAAwB,KAAK;IACzC,CACJ;GACJ,CAAC,EACL,CAAC;GACJ"}
1
+ {"version":3,"file":"time-limit.mjs","names":["status: StatusCode","code: ResponseErrorCode"],"sources":["../src/middlewares/time-limit.ts"],"sourcesContent":["/**\n * Time limit module\n * @module middlewares/time-limit\n */\n\nimport type { Context, MiddlewareHandler } from \"hono\";\nimport type { StatusCode } from \"hono/utils/http-status\";\n\nimport { timeout } from \"hono/timeout\";\n\nimport { getResponseErrorMessage, ResponseErrorCode } from \"#/response/error\";\nimport { JderHttpException } from \"#/response/error/http\";\nimport { createJsonResponse } from \"#/response/json\";\n\n/** Default maximum time in milliseconds. */\nconst TIME_LIMIT_MAX_DEFAULT = (5 * 1000) as 5000;\n\n/** Options for `timeLimit` middleware. */\ntype TimeLimitOptions = {\n /**\n * Maximum time in milliseconds.\n *\n * By default, it is `TIME_LIMIT_MAX_DEFAULT`.\n */\n max?: number;\n};\n\n/**\n * Time limit middleware.\n *\n * Following error will be returned if the request takes longer than the limit:\n *\n * ```jsonc\n * // Status: 504\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"timeout\",\n * \"message\": \"Request timeout\"\n * }\n * ]\n * }\n * ```\n *\n * For more information, please refer to\n * [Timeout](https://hono.dev/docs/middleware/builtin/timeout).\n *\n * ### Examples\n *\n * A example of using `timeLimit` middleware:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { timeLimit } from \"@jderstd/hono/time-limit\";\n *\n * const app: Hono = new Hono();\n *\n * app.use(timeLimit());\n * ```\n *\n * A example of using `timeLimit` middleware with options:\n *\n * ```ts\n * import { Hono } from \"hono\";\n * import { timeLimit } from \"@jderstd/hono/time-limit\";\n *\n * const app: Hono = new Hono();\n *\n * app.use(timeLimit({\n * max: 10 * 1000, // 10s\n * }));\n * ```\n */\nconst timeLimit = (options?: TimeLimitOptions): MiddlewareHandler => {\n const status: StatusCode = 504;\n const code: ResponseErrorCode = ResponseErrorCode.Timeout;\n\n return timeout(\n options?.max ?? 5 * 1000,\n (c: Context): JderHttpException => {\n return new JderHttpException(status, {\n res: createJsonResponse(c, {\n status,\n errors: [\n {\n code,\n message: getResponseErrorMessage(code),\n },\n ],\n }),\n });\n },\n );\n};\n\nexport type { TimeLimitOptions };\nexport { timeLimit, TIME_LIMIT_MAX_DEFAULT };\n"],"mappings":";;;;;;AAeA,MAAM,yBAA0B,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DpC,MAAM,aAAa,YAAkD;CACjE,MAAMA,SAAqB;CAC3B,MAAMC,OAA0B,kBAAkB;AAElD,QAAO,QACH,SAAS,OAAO,IAAI,MACnB,MAAkC;AAC/B,SAAO,IAAI,kBAAkB,QAAQ,EACjC,KAAK,mBAAmB,GAAG;GACvB;GACA,QAAQ,CACJ;IACI;IACA,SAAS,wBAAwB,KAAK;IACzC,CACJ;GACJ,CAAC,EACL,CAAC;GAET"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jderstd/hono",
3
- "version": "0.7.0-dev.0",
3
+ "version": "0.7.1",
4
4
  "description": "A response builder for Hono",
5
5
  "keywords": [
6
6
  "jder",