hono-utils 0.2.0 → 0.3.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 +10 -1
- package/dist/index.cjs +53 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -4
- package/dist/index.d.ts +21 -4
- package/dist/index.js +52 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Hono Utils - Utilities for Hono framework
|
|
4
4
|
|
|
5
|
-
A collection of helpers to simplify building Hono-based applications, including crypto helpers, middleware utilities, and
|
|
5
|
+
A collection of helpers to simplify building Hono-based applications, including crypto helpers, middleware utilities, queue integration and RPC client.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -37,6 +37,12 @@ import { QueueHandler } from 'hono-utils';
|
|
|
37
37
|
import { pbkdf2, sha } from 'hono-utils';
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
### Client
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { createTypedClient } from 'hono-utils';
|
|
44
|
+
```
|
|
45
|
+
|
|
40
46
|
### Router
|
|
41
47
|
|
|
42
48
|
```ts
|
|
@@ -45,6 +51,9 @@ import { onError, onNotFound } from 'hono-utils';
|
|
|
45
51
|
|
|
46
52
|
## Detailed Documentation
|
|
47
53
|
|
|
54
|
+
- Client
|
|
55
|
+
- [createTypedClient](docs/client/createTypedClient.md)
|
|
56
|
+
|
|
48
57
|
- Crypto
|
|
49
58
|
- [pbkdf2](docs/crypto/pbkdf2.md)
|
|
50
59
|
- [sha](docs/crypto/sha.md)
|
package/dist/index.cjs
CHANGED
|
@@ -14120,14 +14120,18 @@ var defaultMessageMap = {
|
|
|
14120
14120
|
};
|
|
14121
14121
|
|
|
14122
14122
|
// src/router/onError.ts
|
|
14123
|
-
var onError = (err, { json: json2,
|
|
14123
|
+
var onError = (parseError) => async (err, { json: json2, env, get }) => {
|
|
14124
14124
|
try {
|
|
14125
|
-
const { error: error48 } = logger2.getArea(`error`);
|
|
14126
|
-
error48(err.message, err);
|
|
14127
14125
|
const status = "status" in err ? err.status : 500;
|
|
14128
|
-
return json2(
|
|
14129
|
-
|
|
14130
|
-
|
|
14126
|
+
return json2(
|
|
14127
|
+
{
|
|
14128
|
+
message: !parseError ? err.message : await parseError(err, env, get)
|
|
14129
|
+
},
|
|
14130
|
+
status
|
|
14131
|
+
);
|
|
14132
|
+
} catch (error48) {
|
|
14133
|
+
console.error("Failed on error handler:", err);
|
|
14134
|
+
console.error("Failed to parse error:", error48);
|
|
14131
14135
|
return json2({ message: defaultMessageMap.internalError }, 500);
|
|
14132
14136
|
}
|
|
14133
14137
|
};
|
|
@@ -14142,6 +14146,48 @@ var onNotFound = async (c) => {
|
|
|
14142
14146
|
);
|
|
14143
14147
|
};
|
|
14144
14148
|
|
|
14149
|
+
// src/client/createTypedClient.ts
|
|
14150
|
+
var _client = require('hono/client');
|
|
14151
|
+
|
|
14152
|
+
|
|
14153
|
+
var createTypedClient = (options) => {
|
|
14154
|
+
const client = _client.hc.call(void 0, options.url, {
|
|
14155
|
+
headers: options.headers,
|
|
14156
|
+
fetch: options.fetch
|
|
14157
|
+
});
|
|
14158
|
+
const rpcClient = async (fn) => {
|
|
14159
|
+
_optionalChain([options, 'access', _189 => _189.callbacks, 'optionalAccess', _190 => _190.onStart, 'optionalCall', _191 => _191()]);
|
|
14160
|
+
let responseHeaders = new Headers();
|
|
14161
|
+
try {
|
|
14162
|
+
const response2 = await fn(client);
|
|
14163
|
+
responseHeaders = response2.headers;
|
|
14164
|
+
const data = await _client.parseResponse.call(void 0, response2);
|
|
14165
|
+
_optionalChain([options, 'access', _192 => _192.callbacks, 'optionalAccess', _193 => _193.onSuccess, 'optionalCall', _194 => _194(data, responseHeaders)]);
|
|
14166
|
+
return data;
|
|
14167
|
+
} catch (err) {
|
|
14168
|
+
const errorBody = { message: err.message };
|
|
14169
|
+
let status = 500;
|
|
14170
|
+
if (err instanceof _client.DetailedError) {
|
|
14171
|
+
const { detail, statusCode } = err;
|
|
14172
|
+
status = _nullishCoalesce(statusCode, () => ( 500));
|
|
14173
|
+
if (!detail) {
|
|
14174
|
+
_optionalChain([options, 'access', _195 => _195.callbacks, 'optionalAccess', _196 => _196.errorHandler, 'optionalCall', _197 => _197(500, {
|
|
14175
|
+
message: "Fetch malformed"
|
|
14176
|
+
})]);
|
|
14177
|
+
throw new (0, _httpexception.HTTPException)(500, { message: "Fetch malformed" });
|
|
14178
|
+
}
|
|
14179
|
+
}
|
|
14180
|
+
_optionalChain([options, 'access', _198 => _198.callbacks, 'optionalAccess', _199 => _199.onError, 'optionalCall', _200 => _200(errorBody, responseHeaders)]);
|
|
14181
|
+
_optionalChain([options, 'access', _201 => _201.callbacks, 'optionalAccess', _202 => _202.errorHandler, 'optionalCall', _203 => _203(status, errorBody)]);
|
|
14182
|
+
throw new (0, _httpexception.HTTPException)(status, errorBody);
|
|
14183
|
+
} finally {
|
|
14184
|
+
_optionalChain([options, 'access', _204 => _204.callbacks, 'optionalAccess', _205 => _205.onEnd, 'optionalCall', _206 => _206()]);
|
|
14185
|
+
}
|
|
14186
|
+
};
|
|
14187
|
+
return rpcClient;
|
|
14188
|
+
};
|
|
14189
|
+
|
|
14190
|
+
|
|
14145
14191
|
|
|
14146
14192
|
|
|
14147
14193
|
|
|
@@ -14154,5 +14200,5 @@ var onNotFound = async (c) => {
|
|
|
14154
14200
|
|
|
14155
14201
|
|
|
14156
14202
|
|
|
14157
|
-
exports.PBKDF2 = pbkdf2_exports; exports.QueueHandler = QueueHandler; exports.SHA = sha_exports; exports.i18n = i18n; exports.isBot = isBot; exports.jsonValidator = jsonValidator; exports.logger = logger; exports.onError = onError; exports.onNotFound = onNotFound; exports.queue = queue; exports.response = response; exports.withLogger = withLogger;
|
|
14203
|
+
exports.PBKDF2 = pbkdf2_exports; exports.QueueHandler = QueueHandler; exports.SHA = sha_exports; exports.createTypedClient = createTypedClient; exports.i18n = i18n; exports.isBot = isBot; exports.jsonValidator = jsonValidator; exports.logger = logger; exports.onError = onError; exports.onNotFound = onNotFound; exports.queue = queue; exports.response = response; exports.withLogger = withLogger;
|
|
14158
14204
|
//# sourceMappingURL=index.cjs.map
|