hono-utils 0.1.0 → 0.2.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.
- package/README.md +23 -12
- package/dist/index.cjs +36 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +35 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as hono from 'hono';
|
|
2
|
-
import { Env, Context } from 'hono';
|
|
2
|
+
import { Env, Context, ErrorHandler, NotFoundHandler } from 'hono';
|
|
3
3
|
import { Logger, Details } from 'hierarchical-area-logger';
|
|
4
4
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
|
5
5
|
import { ContentfulStatusCode, SuccessStatusCode, ClientErrorStatusCode } from 'hono/utils/http-status';
|
|
@@ -354,4 +354,8 @@ declare namespace sha {
|
|
|
354
354
|
export { sha_generateSalt as generateSalt, sha_hash as hash };
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
|
|
357
|
+
declare const onError: ErrorHandler;
|
|
358
|
+
|
|
359
|
+
declare const onNotFound: NotFoundHandler;
|
|
360
|
+
|
|
361
|
+
export { type ContextFn, type HonoI18nVariables, type HonoIsBotVariables, type HonoLanguageVariables, type HonoLoggerVariables, type HonoResponseVariables, type MessageHandlers, pbkdf2 as PBKDF2, QueueHandler, sha as SHA, type WrappableMiddleware, i18n, isBot, jsonValidator, logger, onError, onNotFound, queue, response, withLogger };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as hono from 'hono';
|
|
2
|
-
import { Env, Context } from 'hono';
|
|
2
|
+
import { Env, Context, ErrorHandler, NotFoundHandler } from 'hono';
|
|
3
3
|
import { Logger, Details } from 'hierarchical-area-logger';
|
|
4
4
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
|
5
5
|
import { ContentfulStatusCode, SuccessStatusCode, ClientErrorStatusCode } from 'hono/utils/http-status';
|
|
@@ -354,4 +354,8 @@ declare namespace sha {
|
|
|
354
354
|
export { sha_generateSalt as generateSalt, sha_hash as hash };
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
|
|
357
|
+
declare const onError: ErrorHandler;
|
|
358
|
+
|
|
359
|
+
declare const onNotFound: NotFoundHandler;
|
|
360
|
+
|
|
361
|
+
export { type ContextFn, type HonoI18nVariables, type HonoIsBotVariables, type HonoLanguageVariables, type HonoLoggerVariables, type HonoResponseVariables, type MessageHandlers, pbkdf2 as PBKDF2, QueueHandler, sha as SHA, type WrappableMiddleware, i18n, isBot, jsonValidator, logger, onError, onNotFound, queue, response, withLogger };
|
package/dist/index.js
CHANGED
|
@@ -13929,22 +13929,18 @@ var setResponseHandlers = (c) => {
|
|
|
13929
13929
|
return {
|
|
13930
13930
|
raw: (data) => {
|
|
13931
13931
|
const { status, ...rest } = data;
|
|
13932
|
-
|
|
13933
|
-
return c.json(content, status || 200);
|
|
13932
|
+
return c.json(rest, status || 200);
|
|
13934
13933
|
},
|
|
13935
13934
|
success: (message, data, status) => {
|
|
13936
13935
|
const statusCode = status || (method === "POST" ? 201 : 200);
|
|
13937
13936
|
if (data) {
|
|
13938
|
-
|
|
13939
|
-
return c.json(content2, statusCode);
|
|
13937
|
+
return c.json({ message, data }, statusCode);
|
|
13940
13938
|
}
|
|
13941
|
-
|
|
13942
|
-
return c.json(content, statusCode);
|
|
13939
|
+
return c.json({ message }, statusCode);
|
|
13943
13940
|
},
|
|
13944
13941
|
error: (message, status) => {
|
|
13945
|
-
const content = { message };
|
|
13946
13942
|
throw new HTTPException3(status, {
|
|
13947
|
-
message
|
|
13943
|
+
message
|
|
13948
13944
|
});
|
|
13949
13945
|
},
|
|
13950
13946
|
websocket: (socket) => {
|
|
@@ -14116,6 +14112,35 @@ var QueueHandler = class {
|
|
|
14116
14112
|
};
|
|
14117
14113
|
}
|
|
14118
14114
|
};
|
|
14115
|
+
|
|
14116
|
+
// src/router/constants.ts
|
|
14117
|
+
var defaultMessageMap = {
|
|
14118
|
+
internalError: "internal-error",
|
|
14119
|
+
notFound: "not-found"
|
|
14120
|
+
};
|
|
14121
|
+
|
|
14122
|
+
// src/router/onError.ts
|
|
14123
|
+
var onError = (err, { json: json2, var: { logger: logger2 } }) => {
|
|
14124
|
+
try {
|
|
14125
|
+
const { error: error48 } = logger2.getArea(`error`);
|
|
14126
|
+
error48(err.message, err);
|
|
14127
|
+
const status = "status" in err ? err.status : 500;
|
|
14128
|
+
return json2({ message: err.message }, status);
|
|
14129
|
+
} catch (err2) {
|
|
14130
|
+
console.error(err2);
|
|
14131
|
+
return json2({ message: defaultMessageMap.internalError }, 500);
|
|
14132
|
+
}
|
|
14133
|
+
};
|
|
14134
|
+
|
|
14135
|
+
// src/router/onNotFound.ts
|
|
14136
|
+
var onNotFound = async (c) => {
|
|
14137
|
+
return c.json(
|
|
14138
|
+
{
|
|
14139
|
+
message: defaultMessageMap.notFound
|
|
14140
|
+
},
|
|
14141
|
+
404
|
|
14142
|
+
);
|
|
14143
|
+
};
|
|
14119
14144
|
export {
|
|
14120
14145
|
pbkdf2_exports as PBKDF2,
|
|
14121
14146
|
QueueHandler,
|
|
@@ -14124,6 +14149,8 @@ export {
|
|
|
14124
14149
|
isBot,
|
|
14125
14150
|
jsonValidator,
|
|
14126
14151
|
logger,
|
|
14152
|
+
onError,
|
|
14153
|
+
onNotFound,
|
|
14127
14154
|
queue,
|
|
14128
14155
|
response,
|
|
14129
14156
|
withLogger
|