hono 4.0.10 → 4.1.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/dist/adapter/aws-lambda/handler.js +1 -1
- package/dist/adapter/bun/index.js +2 -0
- package/dist/adapter/bun/websocket.js +77 -0
- package/dist/adapter/cloudflare-workers/index.js +3 -1
- package/dist/adapter/cloudflare-workers/websocket.js +57 -0
- package/dist/adapter/deno/index.js +3 -1
- package/dist/adapter/deno/websocket.js +29 -0
- package/dist/adapter/lambda-edge/handler.js +1 -1
- package/dist/cjs/adapter/aws-lambda/handler.js +1 -1
- package/dist/cjs/adapter/bun/index.js +3 -0
- package/dist/cjs/adapter/bun/websocket.js +98 -0
- package/dist/cjs/adapter/cloudflare-workers/index.js +5 -2
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +80 -0
- package/dist/cjs/adapter/deno/index.js +5 -2
- package/dist/cjs/adapter/deno/websocket.js +52 -0
- package/dist/cjs/adapter/lambda-edge/handler.js +1 -1
- package/dist/cjs/client/client.js +68 -61
- package/dist/cjs/context.js +164 -188
- package/dist/cjs/helper/adapter/index.js +1 -1
- package/dist/cjs/helper/cookie/index.js +48 -8
- package/dist/cjs/helper/dev/index.js +3 -4
- package/dist/cjs/helper/factory/index.js +1 -3
- package/dist/cjs/helper/ssg/index.js +9 -159
- package/dist/cjs/helper/ssg/middleware.js +57 -0
- package/dist/cjs/helper/ssg/ssg.js +212 -0
- package/dist/cjs/helper/websocket/index.js +32 -0
- package/dist/cjs/helper.js +1 -0
- package/dist/cjs/hono-base.js +46 -65
- package/dist/cjs/http-exception.js +3 -1
- package/dist/cjs/jsx/base.js +7 -2
- package/dist/cjs/jsx/components.js +1 -1
- package/dist/cjs/jsx/dom/index.js +45 -3
- package/dist/cjs/jsx/dom/render.js +6 -6
- package/dist/cjs/jsx/hooks/index.js +25 -16
- package/dist/cjs/jsx/index.js +34 -2
- package/dist/cjs/middleware/body-limit/index.js +80 -0
- package/dist/cjs/middleware/logger/index.js +9 -7
- package/dist/cjs/request.js +29 -48
- package/dist/cjs/router/linear-router/router.js +3 -5
- package/dist/cjs/router/pattern-router/router.js +2 -4
- package/dist/cjs/router/reg-exp-router/node.js +3 -3
- package/dist/cjs/router/reg-exp-router/router.js +11 -12
- package/dist/cjs/router/reg-exp-router/trie.js +2 -4
- package/dist/cjs/router/smart-router/router.js +3 -3
- package/dist/cjs/router/trie-router/node.js +6 -2
- package/dist/cjs/router/trie-router/router.js +2 -1
- package/dist/cjs/test-utils/setup-vitest.js +2 -0
- package/dist/cjs/utils/color.js +32 -0
- package/dist/cjs/utils/concurrent.js +62 -0
- package/dist/cjs/utils/cookie.js +28 -1
- package/dist/cjs/utils/stream.js +5 -1
- package/dist/cjs/utils/url.js +2 -2
- package/dist/client/client.js +68 -61
- package/dist/context.js +164 -189
- package/dist/helper/adapter/index.js +1 -1
- package/dist/helper/cookie/index.js +48 -8
- package/dist/helper/dev/index.js +3 -4
- package/dist/helper/factory/index.js +1 -3
- package/dist/helper/ssg/index.js +3 -151
- package/dist/helper/ssg/middleware.js +29 -0
- package/dist/helper/ssg/ssg.js +187 -0
- package/dist/helper/websocket/index.js +9 -0
- package/dist/helper.js +1 -0
- package/dist/hono-base.js +45 -65
- package/dist/http-exception.js +3 -1
- package/dist/jsx/base.js +7 -2
- package/dist/jsx/components.js +1 -1
- package/dist/jsx/dom/index.js +44 -4
- package/dist/jsx/dom/render.js +6 -6
- package/dist/jsx/hooks/index.js +23 -16
- package/dist/jsx/index.js +34 -3
- package/dist/middleware/body-limit/index.js +57 -0
- package/dist/middleware/logger/index.js +9 -7
- package/dist/request.js +29 -49
- package/dist/router/linear-router/router.js +3 -5
- package/dist/router/pattern-router/router.js +2 -4
- package/dist/router/reg-exp-router/node.js +3 -3
- package/dist/router/reg-exp-router/router.js +11 -12
- package/dist/router/reg-exp-router/trie.js +2 -4
- package/dist/router/smart-router/router.js +3 -3
- package/dist/router/trie-router/node.js +6 -2
- package/dist/router/trie-router/router.js +2 -1
- package/dist/test-utils/setup-vitest.js +2 -0
- package/dist/types/adapter/bun/index.d.ts +1 -0
- package/dist/types/adapter/bun/websocket.d.ts +26 -0
- package/dist/types/adapter/cloudflare-workers/index.d.ts +1 -0
- package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -0
- package/dist/types/adapter/deno/index.d.ts +1 -0
- package/dist/types/adapter/deno/websocket.d.ts +2 -0
- package/dist/types/client/types.d.ts +9 -0
- package/dist/types/helper/cookie/index.d.ts +3 -1
- package/dist/types/helper/ssg/index.d.ts +2 -105
- package/dist/types/helper/ssg/middleware.d.ts +38 -0
- package/dist/types/helper/ssg/ssg.d.ts +70 -0
- package/dist/types/helper/websocket/index.d.ts +34 -0
- package/dist/types/http-exception.d.ts +1 -0
- package/dist/types/jsx/dom/index.d.ts +40 -7
- package/dist/types/jsx/hooks/index.d.ts +2 -0
- package/dist/types/jsx/index.d.ts +41 -5
- package/dist/types/middleware/body-limit/index.d.ts +28 -0
- package/dist/types/utils/color.d.ts +1 -0
- package/dist/types/utils/concurrent.d.ts +7 -0
- package/dist/types/utils/cookie.d.ts +2 -0
- package/dist/utils/color.js +9 -0
- package/dist/utils/concurrent.js +39 -0
- package/dist/utils/cookie.js +28 -1
- package/dist/utils/stream.js +5 -1
- package/dist/utils/url.js +2 -2
- package/package.json +18 -2
|
@@ -22,8 +22,10 @@ __export(http_exception_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(http_exception_exports);
|
|
24
24
|
class HTTPException extends Error {
|
|
25
|
+
res;
|
|
26
|
+
status;
|
|
25
27
|
constructor(status = 500, options) {
|
|
26
|
-
super(options?.message);
|
|
28
|
+
super(options?.message, { cause: options?.cause });
|
|
27
29
|
this.res = options?.res;
|
|
28
30
|
this.status = status;
|
|
29
31
|
}
|
package/dist/cjs/jsx/base.js
CHANGED
|
@@ -96,8 +96,13 @@ const childrenToStringToBuffer = (children, buffer) => {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
class JSXNode {
|
|
99
|
+
tag;
|
|
100
|
+
props;
|
|
101
|
+
key;
|
|
102
|
+
children;
|
|
103
|
+
isEscaped = true;
|
|
104
|
+
localContexts;
|
|
99
105
|
constructor(tag, props, children) {
|
|
100
|
-
this.isEscaped = true;
|
|
101
106
|
this.tag = tag;
|
|
102
107
|
this.props = props;
|
|
103
108
|
this.children = children;
|
|
@@ -249,7 +254,7 @@ const memo = (component, propsAreEqual = shallowEqual) => {
|
|
|
249
254
|
computed = void 0;
|
|
250
255
|
}
|
|
251
256
|
prevProps = props;
|
|
252
|
-
return computed
|
|
257
|
+
return computed ||= component(props);
|
|
253
258
|
};
|
|
254
259
|
};
|
|
255
260
|
const Fragment = ({
|
|
@@ -65,7 +65,7 @@ const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) =>
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
if (resArray.some((res) => res instanceof Promise)) {
|
|
68
|
-
fallbackStr
|
|
68
|
+
fallbackStr ||= await fallback?.toString();
|
|
69
69
|
const index = errorBoundaryCounter++;
|
|
70
70
|
const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
|
|
71
71
|
const caught = false;
|
|
@@ -22,7 +22,10 @@ __export(dom_exports, {
|
|
|
22
22
|
Suspense: () => import_components.Suspense,
|
|
23
23
|
cloneElement: () => cloneElement,
|
|
24
24
|
createContext: () => import_context2.createContext,
|
|
25
|
+
createElement: () => createElement,
|
|
26
|
+
default: () => dom_default,
|
|
25
27
|
isValidElement: () => import_base.isValidElement,
|
|
28
|
+
jsx: () => createElement,
|
|
26
29
|
memo: () => import_base.memo,
|
|
27
30
|
render: () => import_render.render,
|
|
28
31
|
startTransition: () => import_hooks.startTransition,
|
|
@@ -30,23 +33,34 @@ __export(dom_exports, {
|
|
|
30
33
|
use: () => import_hooks.use,
|
|
31
34
|
useCallback: () => import_hooks.useCallback,
|
|
32
35
|
useContext: () => import_context.useContext,
|
|
36
|
+
useDebugValue: () => import_hooks.useDebugValue,
|
|
33
37
|
useDeferredValue: () => import_hooks.useDeferredValue,
|
|
34
38
|
useEffect: () => import_hooks.useEffect,
|
|
35
39
|
useLayoutEffect: () => import_hooks.useLayoutEffect,
|
|
36
40
|
useMemo: () => import_hooks.useMemo,
|
|
41
|
+
useReducer: () => import_hooks.useReducer,
|
|
37
42
|
useRef: () => import_hooks.useRef,
|
|
38
43
|
useState: () => import_hooks.useState,
|
|
39
44
|
useTransition: () => import_hooks.useTransition,
|
|
40
45
|
useViewTransition: () => import_hooks.useViewTransition
|
|
41
46
|
});
|
|
42
47
|
module.exports = __toCommonJS(dom_exports);
|
|
48
|
+
var import_base = require("../base");
|
|
49
|
+
var import_context = require("../context");
|
|
43
50
|
var import_hooks = require("../hooks");
|
|
44
|
-
var import_render = require("./render");
|
|
45
51
|
var import_components = require("./components");
|
|
46
|
-
var import_context = require("../context");
|
|
47
52
|
var import_context2 = require("./context");
|
|
48
|
-
var import_base = require("../base");
|
|
49
53
|
var import_jsx_runtime = require("./jsx-runtime");
|
|
54
|
+
var import_render = require("./render");
|
|
55
|
+
const createElement = (tag, props, ...children) => {
|
|
56
|
+
const jsxProps = { ...props, children };
|
|
57
|
+
let key = void 0;
|
|
58
|
+
if ("key" in jsxProps) {
|
|
59
|
+
key = jsxProps.key;
|
|
60
|
+
delete jsxProps.key;
|
|
61
|
+
}
|
|
62
|
+
return (0, import_jsx_runtime.jsx)(tag, jsxProps, key);
|
|
63
|
+
};
|
|
50
64
|
const cloneElement = (element, props, ...children) => {
|
|
51
65
|
return (0, import_jsx_runtime.jsx)(
|
|
52
66
|
element.tag,
|
|
@@ -58,13 +72,39 @@ const cloneElement = (element, props, ...children) => {
|
|
|
58
72
|
element.key
|
|
59
73
|
);
|
|
60
74
|
};
|
|
75
|
+
var dom_default = {
|
|
76
|
+
useState: import_hooks.useState,
|
|
77
|
+
useEffect: import_hooks.useEffect,
|
|
78
|
+
useRef: import_hooks.useRef,
|
|
79
|
+
useCallback: import_hooks.useCallback,
|
|
80
|
+
use: import_hooks.use,
|
|
81
|
+
startTransition: import_hooks.startTransition,
|
|
82
|
+
useTransition: import_hooks.useTransition,
|
|
83
|
+
useDeferredValue: import_hooks.useDeferredValue,
|
|
84
|
+
startViewTransition: import_hooks.startViewTransition,
|
|
85
|
+
useViewTransition: import_hooks.useViewTransition,
|
|
86
|
+
useMemo: import_hooks.useMemo,
|
|
87
|
+
useLayoutEffect: import_hooks.useLayoutEffect,
|
|
88
|
+
useReducer: import_hooks.useReducer,
|
|
89
|
+
useDebugValue: import_hooks.useDebugValue,
|
|
90
|
+
Suspense: import_components.Suspense,
|
|
91
|
+
ErrorBoundary: import_components.ErrorBoundary,
|
|
92
|
+
createContext: import_context2.createContext,
|
|
93
|
+
useContext: import_context.useContext,
|
|
94
|
+
memo: import_base.memo,
|
|
95
|
+
isValidElement: import_base.isValidElement,
|
|
96
|
+
createElement,
|
|
97
|
+
cloneElement
|
|
98
|
+
};
|
|
61
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
100
|
0 && (module.exports = {
|
|
63
101
|
ErrorBoundary,
|
|
64
102
|
Suspense,
|
|
65
103
|
cloneElement,
|
|
66
104
|
createContext,
|
|
105
|
+
createElement,
|
|
67
106
|
isValidElement,
|
|
107
|
+
jsx,
|
|
68
108
|
memo,
|
|
69
109
|
render,
|
|
70
110
|
startTransition,
|
|
@@ -72,10 +112,12 @@ const cloneElement = (element, props, ...children) => {
|
|
|
72
112
|
use,
|
|
73
113
|
useCallback,
|
|
74
114
|
useContext,
|
|
115
|
+
useDebugValue,
|
|
75
116
|
useDeferredValue,
|
|
76
117
|
useEffect,
|
|
77
118
|
useLayoutEffect,
|
|
78
119
|
useMemo,
|
|
120
|
+
useReducer,
|
|
79
121
|
useRef,
|
|
80
122
|
useState,
|
|
81
123
|
useTransition,
|
|
@@ -48,7 +48,7 @@ const getEventSpec = (key) => {
|
|
|
48
48
|
return void 0;
|
|
49
49
|
};
|
|
50
50
|
const applyProps = (container, attributes, oldAttributes) => {
|
|
51
|
-
attributes
|
|
51
|
+
attributes ||= {};
|
|
52
52
|
for (const [key, value] of Object.entries(attributes)) {
|
|
53
53
|
if (!oldAttributes || oldAttributes[key] !== value) {
|
|
54
54
|
const eventSpec = getEventSpec(key);
|
|
@@ -230,9 +230,9 @@ const applyNodeObject = (node, container) => {
|
|
|
230
230
|
child.e.textContent = child[0];
|
|
231
231
|
}
|
|
232
232
|
child[1] = false;
|
|
233
|
-
el = child.e
|
|
233
|
+
el = child.e ||= document.createTextNode(child[0]);
|
|
234
234
|
} else {
|
|
235
|
-
el = child.e
|
|
235
|
+
el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
|
|
236
236
|
applyProps(el, child.props, child.pP);
|
|
237
237
|
applyNode(child, el);
|
|
238
238
|
}
|
|
@@ -251,10 +251,10 @@ const build = (context, node, topLevelErrorHandlerNode, children) => {
|
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
253
|
let errorHandler;
|
|
254
|
-
children
|
|
254
|
+
children ||= typeof node.tag == "function" ? invokeTag(context, node) : node.children;
|
|
255
255
|
if (children[0]?.tag === "") {
|
|
256
256
|
errorHandler = children[0][import_constants.DOM_ERROR_HANDLER];
|
|
257
|
-
topLevelErrorHandlerNode
|
|
257
|
+
topLevelErrorHandlerNode ||= node;
|
|
258
258
|
}
|
|
259
259
|
const oldVChildren = node.vC ? [...node.vC] : [];
|
|
260
260
|
const vChildren = [];
|
|
@@ -343,7 +343,7 @@ const buildNode = (node) => {
|
|
|
343
343
|
if (ns) {
|
|
344
344
|
;
|
|
345
345
|
node.n = ns;
|
|
346
|
-
nameSpaceContext
|
|
346
|
+
nameSpaceContext ||= (0, import_context2.createContext)("");
|
|
347
347
|
node.children = [
|
|
348
348
|
{
|
|
349
349
|
tag: nameSpaceContext.Provider,
|
|
@@ -23,10 +23,12 @@ __export(hooks_exports, {
|
|
|
23
23
|
startViewTransition: () => startViewTransition,
|
|
24
24
|
use: () => use,
|
|
25
25
|
useCallback: () => useCallback,
|
|
26
|
+
useDebugValue: () => useDebugValue,
|
|
26
27
|
useDeferredValue: () => useDeferredValue,
|
|
27
28
|
useEffect: () => useEffect,
|
|
28
29
|
useLayoutEffect: () => useLayoutEffect,
|
|
29
30
|
useMemo: () => useMemo,
|
|
31
|
+
useReducer: () => useReducer,
|
|
30
32
|
useRef: () => useRef,
|
|
31
33
|
useState: () => useState,
|
|
32
34
|
useTransition: () => useTransition,
|
|
@@ -131,7 +133,6 @@ const setShadow = (node) => {
|
|
|
131
133
|
node.s?.forEach(setShadow);
|
|
132
134
|
};
|
|
133
135
|
const useState = (initialState) => {
|
|
134
|
-
var _a;
|
|
135
136
|
const resolveInitialState = () => typeof initialState === "function" ? initialState() : initialState;
|
|
136
137
|
const buildData = import_render.buildDataStack.at(-1);
|
|
137
138
|
if (!buildData) {
|
|
@@ -139,9 +140,9 @@ const useState = (initialState) => {
|
|
|
139
140
|
}];
|
|
140
141
|
}
|
|
141
142
|
const [, node] = buildData;
|
|
142
|
-
const stateArray =
|
|
143
|
+
const stateArray = node[import_constants.DOM_STASH][1][STASH_SATE] ||= [];
|
|
143
144
|
const hookIndex = node[import_constants.DOM_STASH][0]++;
|
|
144
|
-
return stateArray[hookIndex]
|
|
145
|
+
return stateArray[hookIndex] ||= [
|
|
145
146
|
resolveInitialState(),
|
|
146
147
|
(newState) => {
|
|
147
148
|
const localUpdateHook = updateHook;
|
|
@@ -182,18 +183,26 @@ const useState = (initialState) => {
|
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
|
-
]
|
|
186
|
+
];
|
|
187
|
+
};
|
|
188
|
+
const useReducer = (reducer, initialArg, init) => {
|
|
189
|
+
const [state, setState] = useState(() => init ? init(initialArg) : initialArg);
|
|
190
|
+
return [
|
|
191
|
+
state,
|
|
192
|
+
(action) => {
|
|
193
|
+
setState((state2) => reducer(state2, action));
|
|
194
|
+
}
|
|
195
|
+
];
|
|
186
196
|
};
|
|
187
197
|
const useEffectCommon = (index, effect, deps) => {
|
|
188
|
-
var _a;
|
|
189
198
|
const buildData = import_render.buildDataStack.at(-1);
|
|
190
199
|
if (!buildData) {
|
|
191
200
|
return;
|
|
192
201
|
}
|
|
193
202
|
const [, node] = buildData;
|
|
194
|
-
const effectDepsArray =
|
|
203
|
+
const effectDepsArray = node[import_constants.DOM_STASH][1][STASH_EFFECT] ||= [];
|
|
195
204
|
const hookIndex = node[import_constants.DOM_STASH][0]++;
|
|
196
|
-
const [prevDeps, , prevCleanup] = effectDepsArray[hookIndex]
|
|
205
|
+
const [prevDeps, , prevCleanup] = effectDepsArray[hookIndex] ||= [];
|
|
197
206
|
if (isDepsChanged(prevDeps, deps)) {
|
|
198
207
|
if (prevCleanup) {
|
|
199
208
|
prevCleanup();
|
|
@@ -210,13 +219,12 @@ const useEffectCommon = (index, effect, deps) => {
|
|
|
210
219
|
const useEffect = (effect, deps) => useEffectCommon(3, effect, deps);
|
|
211
220
|
const useLayoutEffect = (effect, deps) => useEffectCommon(1, effect, deps);
|
|
212
221
|
const useCallback = (callback, deps) => {
|
|
213
|
-
var _a;
|
|
214
222
|
const buildData = import_render.buildDataStack.at(-1);
|
|
215
223
|
if (!buildData) {
|
|
216
224
|
return callback;
|
|
217
225
|
}
|
|
218
226
|
const [, node] = buildData;
|
|
219
|
-
const callbackArray =
|
|
227
|
+
const callbackArray = node[import_constants.DOM_STASH][1][STASH_CALLBACK] ||= [];
|
|
220
228
|
const hookIndex = node[import_constants.DOM_STASH][0]++;
|
|
221
229
|
const prevDeps = callbackArray[hookIndex];
|
|
222
230
|
if (isDepsChanged(prevDeps?.[1], deps)) {
|
|
@@ -227,18 +235,16 @@ const useCallback = (callback, deps) => {
|
|
|
227
235
|
return callback;
|
|
228
236
|
};
|
|
229
237
|
const useRef = (initialValue) => {
|
|
230
|
-
var _a;
|
|
231
238
|
const buildData = import_render.buildDataStack.at(-1);
|
|
232
239
|
if (!buildData) {
|
|
233
240
|
return { current: initialValue };
|
|
234
241
|
}
|
|
235
242
|
const [, node] = buildData;
|
|
236
|
-
const refArray =
|
|
243
|
+
const refArray = node[import_constants.DOM_STASH][1][STASH_REF] ||= [];
|
|
237
244
|
const hookIndex = node[import_constants.DOM_STASH][0]++;
|
|
238
|
-
return refArray[hookIndex]
|
|
245
|
+
return refArray[hookIndex] ||= { current: initialValue };
|
|
239
246
|
};
|
|
240
247
|
const use = (promise) => {
|
|
241
|
-
var _a;
|
|
242
248
|
const cachedRes = resolvedPromiseValueMap.get(promise);
|
|
243
249
|
if (cachedRes) {
|
|
244
250
|
if (cachedRes.length === 2) {
|
|
@@ -255,7 +261,7 @@ const use = (promise) => {
|
|
|
255
261
|
throw promise;
|
|
256
262
|
}
|
|
257
263
|
const [, node] = buildData;
|
|
258
|
-
const promiseArray =
|
|
264
|
+
const promiseArray = node[import_constants.DOM_STASH][1][STASH_USE] ||= [];
|
|
259
265
|
const hookIndex = node[import_constants.DOM_STASH][0]++;
|
|
260
266
|
promise.then(
|
|
261
267
|
(res2) => {
|
|
@@ -275,13 +281,12 @@ const use = (promise) => {
|
|
|
275
281
|
throw promise;
|
|
276
282
|
};
|
|
277
283
|
const useMemo = (factory, deps) => {
|
|
278
|
-
var _a;
|
|
279
284
|
const buildData = import_render.buildDataStack.at(-1);
|
|
280
285
|
if (!buildData) {
|
|
281
286
|
return factory();
|
|
282
287
|
}
|
|
283
288
|
const [, node] = buildData;
|
|
284
|
-
const memoArray =
|
|
289
|
+
const memoArray = node[import_constants.DOM_STASH][1][STASH_MEMO] ||= [];
|
|
285
290
|
const hookIndex = node[import_constants.DOM_STASH][0]++;
|
|
286
291
|
const prevDeps = memoArray[hookIndex];
|
|
287
292
|
if (isDepsChanged(prevDeps?.[1], deps)) {
|
|
@@ -289,6 +294,8 @@ const useMemo = (factory, deps) => {
|
|
|
289
294
|
}
|
|
290
295
|
return memoArray[hookIndex][0];
|
|
291
296
|
};
|
|
297
|
+
const useDebugValue = (value, formatter) => {
|
|
298
|
+
};
|
|
292
299
|
// Annotate the CommonJS export names for ESM import in node:
|
|
293
300
|
0 && (module.exports = {
|
|
294
301
|
STASH_EFFECT,
|
|
@@ -296,10 +303,12 @@ const useMemo = (factory, deps) => {
|
|
|
296
303
|
startViewTransition,
|
|
297
304
|
use,
|
|
298
305
|
useCallback,
|
|
306
|
+
useDebugValue,
|
|
299
307
|
useDeferredValue,
|
|
300
308
|
useEffect,
|
|
301
309
|
useLayoutEffect,
|
|
302
310
|
useMemo,
|
|
311
|
+
useReducer,
|
|
303
312
|
useRef,
|
|
304
313
|
useState,
|
|
305
314
|
useTransition,
|
package/dist/cjs/jsx/index.js
CHANGED
|
@@ -24,6 +24,8 @@ __export(jsx_exports, {
|
|
|
24
24
|
Suspense: () => import_streaming.Suspense,
|
|
25
25
|
cloneElement: () => import_base.cloneElement,
|
|
26
26
|
createContext: () => import_context.createContext,
|
|
27
|
+
createElement: () => import_base.jsx,
|
|
28
|
+
default: () => jsx_default,
|
|
27
29
|
isValidElement: () => import_base.isValidElement,
|
|
28
30
|
jsx: () => import_base.jsx,
|
|
29
31
|
memo: () => import_base.memo,
|
|
@@ -32,10 +34,12 @@ __export(jsx_exports, {
|
|
|
32
34
|
use: () => import_hooks.use,
|
|
33
35
|
useCallback: () => import_hooks.useCallback,
|
|
34
36
|
useContext: () => import_context.useContext,
|
|
37
|
+
useDebugValue: () => import_hooks.useDebugValue,
|
|
35
38
|
useDeferredValue: () => import_hooks.useDeferredValue,
|
|
36
39
|
useEffect: () => import_hooks.useEffect,
|
|
37
40
|
useLayoutEffect: () => import_hooks.useLayoutEffect,
|
|
38
41
|
useMemo: () => import_hooks.useMemo,
|
|
42
|
+
useReducer: () => import_hooks.useReducer,
|
|
39
43
|
useRef: () => import_hooks.useRef,
|
|
40
44
|
useState: () => import_hooks.useState,
|
|
41
45
|
useTransition: () => import_hooks.useTransition,
|
|
@@ -44,10 +48,35 @@ __export(jsx_exports, {
|
|
|
44
48
|
module.exports = __toCommonJS(jsx_exports);
|
|
45
49
|
var import_base = require("./base");
|
|
46
50
|
var import_components = require("./components");
|
|
47
|
-
var import_streaming = require("./streaming");
|
|
48
|
-
var import_hooks = require("./hooks");
|
|
49
51
|
var import_context = require("./context");
|
|
52
|
+
var import_hooks = require("./hooks");
|
|
53
|
+
var import_streaming = require("./streaming");
|
|
50
54
|
__reExport(jsx_exports, require("./types"), module.exports);
|
|
55
|
+
var jsx_default = {
|
|
56
|
+
memo: import_base.memo,
|
|
57
|
+
Fragment: import_base.Fragment,
|
|
58
|
+
isValidElement: import_base.isValidElement,
|
|
59
|
+
createElement: import_base.jsx,
|
|
60
|
+
cloneElement: import_base.cloneElement,
|
|
61
|
+
ErrorBoundary: import_components.ErrorBoundary,
|
|
62
|
+
createContext: import_context.createContext,
|
|
63
|
+
useContext: import_context.useContext,
|
|
64
|
+
useState: import_hooks.useState,
|
|
65
|
+
useEffect: import_hooks.useEffect,
|
|
66
|
+
useRef: import_hooks.useRef,
|
|
67
|
+
useCallback: import_hooks.useCallback,
|
|
68
|
+
useReducer: import_hooks.useReducer,
|
|
69
|
+
useDebugValue: import_hooks.useDebugValue,
|
|
70
|
+
use: import_hooks.use,
|
|
71
|
+
startTransition: import_hooks.startTransition,
|
|
72
|
+
useTransition: import_hooks.useTransition,
|
|
73
|
+
useDeferredValue: import_hooks.useDeferredValue,
|
|
74
|
+
startViewTransition: import_hooks.startViewTransition,
|
|
75
|
+
useViewTransition: import_hooks.useViewTransition,
|
|
76
|
+
useMemo: import_hooks.useMemo,
|
|
77
|
+
useLayoutEffect: import_hooks.useLayoutEffect,
|
|
78
|
+
Suspense: import_streaming.Suspense
|
|
79
|
+
};
|
|
51
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
81
|
0 && (module.exports = {
|
|
53
82
|
ErrorBoundary,
|
|
@@ -55,6 +84,7 @@ __reExport(jsx_exports, require("./types"), module.exports);
|
|
|
55
84
|
Suspense,
|
|
56
85
|
cloneElement,
|
|
57
86
|
createContext,
|
|
87
|
+
createElement,
|
|
58
88
|
isValidElement,
|
|
59
89
|
jsx,
|
|
60
90
|
memo,
|
|
@@ -63,10 +93,12 @@ __reExport(jsx_exports, require("./types"), module.exports);
|
|
|
63
93
|
use,
|
|
64
94
|
useCallback,
|
|
65
95
|
useContext,
|
|
96
|
+
useDebugValue,
|
|
66
97
|
useDeferredValue,
|
|
67
98
|
useEffect,
|
|
68
99
|
useLayoutEffect,
|
|
69
100
|
useMemo,
|
|
101
|
+
useReducer,
|
|
70
102
|
useRef,
|
|
71
103
|
useState,
|
|
72
104
|
useTransition,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var body_limit_exports = {};
|
|
20
|
+
__export(body_limit_exports, {
|
|
21
|
+
bodyLimit: () => bodyLimit
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(body_limit_exports);
|
|
24
|
+
var import_http_exception = require("../../http-exception");
|
|
25
|
+
const ERROR_MESSAGE = "Payload Too Large";
|
|
26
|
+
class BodyLimitError extends Error {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = "BodyLimitError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const bodyLimit = (options) => {
|
|
33
|
+
const onError = options.onError || (() => {
|
|
34
|
+
const res = new Response(ERROR_MESSAGE, {
|
|
35
|
+
status: 413
|
|
36
|
+
});
|
|
37
|
+
throw new import_http_exception.HTTPException(413, { res });
|
|
38
|
+
});
|
|
39
|
+
const maxSize = options.maxSize;
|
|
40
|
+
return async function bodyLimit2(c, next) {
|
|
41
|
+
if (!c.req.raw.body) {
|
|
42
|
+
return next();
|
|
43
|
+
}
|
|
44
|
+
if (c.req.raw.headers.has("content-length")) {
|
|
45
|
+
const contentLength = parseInt(c.req.raw.headers.get("content-length") || "0", 10);
|
|
46
|
+
return contentLength > maxSize ? onError(c) : next();
|
|
47
|
+
}
|
|
48
|
+
let size = 0;
|
|
49
|
+
const rawReader = c.req.raw.body.getReader();
|
|
50
|
+
const reader = new ReadableStream({
|
|
51
|
+
async start(controller) {
|
|
52
|
+
try {
|
|
53
|
+
for (; ; ) {
|
|
54
|
+
const { done, value } = await rawReader.read();
|
|
55
|
+
if (done) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
size += value.length;
|
|
59
|
+
if (size > maxSize) {
|
|
60
|
+
controller.error(new BodyLimitError(ERROR_MESSAGE));
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
controller.enqueue(value);
|
|
64
|
+
}
|
|
65
|
+
} finally {
|
|
66
|
+
controller.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
c.req.raw = new Request(c.req.raw, { body: reader });
|
|
71
|
+
await next();
|
|
72
|
+
if (c.error instanceof BodyLimitError) {
|
|
73
|
+
c.res = await onError(c);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
bodyLimit
|
|
80
|
+
});
|
|
@@ -21,6 +21,7 @@ __export(logger_exports, {
|
|
|
21
21
|
logger: () => logger
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(logger_exports);
|
|
24
|
+
var import_color = require("../../utils/color");
|
|
24
25
|
var import_url = require("../../utils/url");
|
|
25
26
|
var LogPrefix = /* @__PURE__ */ ((LogPrefix2) => {
|
|
26
27
|
LogPrefix2["Outgoing"] = "-->";
|
|
@@ -38,14 +39,15 @@ const time = (start) => {
|
|
|
38
39
|
return humanize([delta < 1e3 ? delta + "ms" : Math.round(delta / 1e3) + "s"]);
|
|
39
40
|
};
|
|
40
41
|
const colorStatus = (status) => {
|
|
42
|
+
const colorEnabled = (0, import_color.getColorEnabled)();
|
|
41
43
|
const out = {
|
|
42
|
-
7: `\x1B[35m${status}\x1B[0m`,
|
|
43
|
-
5: `\x1B[31m${status}\x1B[0m`,
|
|
44
|
-
4: `\x1B[33m${status}\x1B[0m`,
|
|
45
|
-
3: `\x1B[36m${status}\x1B[0m`,
|
|
46
|
-
2: `\x1B[32m${status}\x1B[0m`,
|
|
47
|
-
1: `\x1B[32m${status}\x1B[0m`,
|
|
48
|
-
0: `\x1B[33m${status}\x1B[0m`
|
|
44
|
+
7: colorEnabled ? `\x1B[35m${status}\x1B[0m` : `${status}`,
|
|
45
|
+
5: colorEnabled ? `\x1B[31m${status}\x1B[0m` : `${status}`,
|
|
46
|
+
4: colorEnabled ? `\x1B[33m${status}\x1B[0m` : `${status}`,
|
|
47
|
+
3: colorEnabled ? `\x1B[36m${status}\x1B[0m` : `${status}`,
|
|
48
|
+
2: colorEnabled ? `\x1B[32m${status}\x1B[0m` : `${status}`,
|
|
49
|
+
1: colorEnabled ? `\x1B[32m${status}\x1B[0m` : `${status}`,
|
|
50
|
+
0: colorEnabled ? `\x1B[33m${status}\x1B[0m` : `${status}`
|
|
49
51
|
};
|
|
50
52
|
const calculateStatus = status / 100 | 0;
|
|
51
53
|
return out[calculateStatus];
|
package/dist/cjs/request.js
CHANGED
|
@@ -16,24 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __accessCheck = (obj, member, msg) => {
|
|
20
|
-
if (!member.has(obj))
|
|
21
|
-
throw TypeError("Cannot " + msg);
|
|
22
|
-
};
|
|
23
|
-
var __privateGet = (obj, member, getter) => {
|
|
24
|
-
__accessCheck(obj, member, "read from private field");
|
|
25
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
26
|
-
};
|
|
27
|
-
var __privateAdd = (obj, member, value) => {
|
|
28
|
-
if (member.has(obj))
|
|
29
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
30
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
31
|
-
};
|
|
32
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
33
|
-
__accessCheck(obj, member, "write to private field");
|
|
34
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
35
|
-
return value;
|
|
36
|
-
};
|
|
37
19
|
var request_exports = {};
|
|
38
20
|
__export(request_exports, {
|
|
39
21
|
HonoRequest: () => HonoRequest
|
|
@@ -41,44 +23,32 @@ __export(request_exports, {
|
|
|
41
23
|
module.exports = __toCommonJS(request_exports);
|
|
42
24
|
var import_body = require("./utils/body");
|
|
43
25
|
var import_url = require("./utils/url");
|
|
44
|
-
var _validatedData, _matchResult;
|
|
45
26
|
class HonoRequest {
|
|
27
|
+
raw;
|
|
28
|
+
#validatedData;
|
|
29
|
+
#matchResult;
|
|
30
|
+
routeIndex = 0;
|
|
31
|
+
path;
|
|
32
|
+
bodyCache = {};
|
|
46
33
|
constructor(request, path = "/", matchResult = [[]]) {
|
|
47
|
-
__privateAdd(this, _validatedData, void 0);
|
|
48
|
-
__privateAdd(this, _matchResult, void 0);
|
|
49
|
-
this.routeIndex = 0;
|
|
50
|
-
this.bodyCache = {};
|
|
51
|
-
this.cachedBody = (key) => {
|
|
52
|
-
const { bodyCache, raw } = this;
|
|
53
|
-
const cachedBody = bodyCache[key];
|
|
54
|
-
if (cachedBody) {
|
|
55
|
-
return cachedBody;
|
|
56
|
-
}
|
|
57
|
-
if (bodyCache.arrayBuffer) {
|
|
58
|
-
return (async () => {
|
|
59
|
-
return await new Response(bodyCache.arrayBuffer)[key]();
|
|
60
|
-
})();
|
|
61
|
-
}
|
|
62
|
-
return bodyCache[key] = raw[key]();
|
|
63
|
-
};
|
|
64
34
|
this.raw = request;
|
|
65
35
|
this.path = path;
|
|
66
|
-
|
|
67
|
-
|
|
36
|
+
this.#matchResult = matchResult;
|
|
37
|
+
this.#validatedData = {};
|
|
68
38
|
}
|
|
69
39
|
param(key) {
|
|
70
40
|
return key ? this.getDecodedParam(key) : this.getAllDecodedParams();
|
|
71
41
|
}
|
|
72
42
|
getDecodedParam(key) {
|
|
73
|
-
const paramKey =
|
|
43
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
74
44
|
const param = this.getParamValue(paramKey);
|
|
75
45
|
return param ? /\%/.test(param) ? (0, import_url.decodeURIComponent_)(param) : param : void 0;
|
|
76
46
|
}
|
|
77
47
|
getAllDecodedParams() {
|
|
78
48
|
const decoded = {};
|
|
79
|
-
const keys = Object.keys(
|
|
49
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
80
50
|
for (const key of keys) {
|
|
81
|
-
const value = this.getParamValue(
|
|
51
|
+
const value = this.getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
82
52
|
if (value && typeof value === "string") {
|
|
83
53
|
decoded[key] = /\%/.test(value) ? (0, import_url.decodeURIComponent_)(value) : value;
|
|
84
54
|
}
|
|
@@ -86,7 +56,7 @@ class HonoRequest {
|
|
|
86
56
|
return decoded;
|
|
87
57
|
}
|
|
88
58
|
getParamValue(paramKey) {
|
|
89
|
-
return
|
|
59
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
90
60
|
}
|
|
91
61
|
query(key) {
|
|
92
62
|
return (0, import_url.getQueryParam)(this.url, key);
|
|
@@ -112,6 +82,19 @@ class HonoRequest {
|
|
|
112
82
|
this.bodyCache.parsedBody = parsedBody;
|
|
113
83
|
return parsedBody;
|
|
114
84
|
}
|
|
85
|
+
cachedBody = (key) => {
|
|
86
|
+
const { bodyCache, raw } = this;
|
|
87
|
+
const cachedBody = bodyCache[key];
|
|
88
|
+
if (cachedBody) {
|
|
89
|
+
return cachedBody;
|
|
90
|
+
}
|
|
91
|
+
if (bodyCache.arrayBuffer) {
|
|
92
|
+
return (async () => {
|
|
93
|
+
return await new Response(bodyCache.arrayBuffer)[key]();
|
|
94
|
+
})();
|
|
95
|
+
}
|
|
96
|
+
return bodyCache[key] = raw[key]();
|
|
97
|
+
};
|
|
115
98
|
json() {
|
|
116
99
|
return this.cachedBody("json");
|
|
117
100
|
}
|
|
@@ -128,10 +111,10 @@ class HonoRequest {
|
|
|
128
111
|
return this.cachedBody("formData");
|
|
129
112
|
}
|
|
130
113
|
addValidatedData(target, data) {
|
|
131
|
-
|
|
114
|
+
this.#validatedData[target] = data;
|
|
132
115
|
}
|
|
133
116
|
valid(target) {
|
|
134
|
-
return
|
|
117
|
+
return this.#validatedData[target];
|
|
135
118
|
}
|
|
136
119
|
get url() {
|
|
137
120
|
return this.raw.url;
|
|
@@ -140,14 +123,12 @@ class HonoRequest {
|
|
|
140
123
|
return this.raw.method;
|
|
141
124
|
}
|
|
142
125
|
get matchedRoutes() {
|
|
143
|
-
return
|
|
126
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
144
127
|
}
|
|
145
128
|
get routePath() {
|
|
146
|
-
return
|
|
129
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
147
130
|
}
|
|
148
131
|
}
|
|
149
|
-
_validatedData = new WeakMap();
|
|
150
|
-
_matchResult = new WeakMap();
|
|
151
132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
152
133
|
0 && (module.exports = {
|
|
153
134
|
HonoRequest
|
|
@@ -27,10 +27,8 @@ const emptyParams = {};
|
|
|
27
27
|
const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
28
28
|
const splitByStarRe = /\*/;
|
|
29
29
|
class LinearRouter {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.routes = [];
|
|
33
|
-
}
|
|
30
|
+
name = "LinearRouter";
|
|
31
|
+
routes = [];
|
|
34
32
|
add(method, path, handler) {
|
|
35
33
|
;
|
|
36
34
|
((0, import_url.checkOptionalParameter)(path) || [path]).forEach((p) => {
|
|
@@ -113,7 +111,7 @@ class LinearRouter {
|
|
|
113
111
|
value = path.slice(pos + 1, endValuePos);
|
|
114
112
|
pos = endValuePos;
|
|
115
113
|
}
|
|
116
|
-
params[name]
|
|
114
|
+
params[name] ||= value;
|
|
117
115
|
} else {
|
|
118
116
|
const index = path.indexOf(part, pos);
|
|
119
117
|
if (index !== pos) {
|