hono 4.3.11 → 4.4.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 +2 -3
- package/dist/adapter/aws-lambda/handler.js +12 -9
- package/dist/adapter/bun/conninfo.js +21 -0
- package/dist/adapter/bun/index.js +2 -0
- package/dist/adapter/bun/websocket.js +1 -3
- package/dist/adapter/cloudflare-workers/conninfo.js +10 -0
- package/dist/adapter/cloudflare-workers/websocket.js +2 -6
- package/dist/adapter/deno/conninfo.js +15 -0
- package/dist/adapter/deno/index.js +2 -0
- package/dist/adapter/lambda-edge/handler.js +3 -3
- package/dist/cjs/adapter/aws-lambda/handler.js +12 -9
- package/dist/cjs/adapter/bun/conninfo.js +44 -0
- package/dist/cjs/adapter/bun/index.js +3 -0
- package/dist/cjs/adapter/cloudflare-workers/conninfo.js +33 -0
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +2 -6
- package/dist/cjs/adapter/deno/conninfo.js +38 -0
- package/dist/cjs/adapter/deno/index.js +3 -0
- package/dist/cjs/adapter/lambda-edge/handler.js +3 -3
- package/dist/cjs/helper/conninfo/index.js +16 -0
- package/dist/cjs/helper/ssg/ssg.js +64 -3
- package/dist/cjs/helper/streaming/text.js +1 -1
- package/dist/cjs/hono-base.js +10 -6
- package/dist/cjs/jsx/base.js +5 -2
- package/dist/cjs/jsx/dom/client.js +68 -0
- package/dist/cjs/jsx/dom/index.js +8 -4
- package/dist/cjs/jsx/dom/jsx-dev-runtime.js +6 -20
- package/dist/cjs/jsx/dom/render.js +41 -25
- package/dist/cjs/jsx/dom/utils.js +15 -0
- package/dist/cjs/jsx/hooks/index.js +4 -1
- package/dist/cjs/jsx/index.js +8 -4
- package/dist/cjs/middleware/jwt/index.js +5 -82
- package/dist/cjs/middleware/jwt/jwt.js +111 -0
- package/dist/cjs/middleware/secure-headers/index.js +3 -123
- package/dist/cjs/middleware/secure-headers/secure-headers.js +150 -0
- package/dist/cjs/middleware/timeout/index.js +48 -0
- package/dist/cjs/middleware/timing/index.js +5 -89
- package/dist/cjs/middleware/timing/timing.js +118 -0
- package/dist/cjs/utils/body.js +34 -9
- package/dist/cjs/utils/jwt/jws.js +4 -5
- package/dist/cjs/utils/jwt/jwt.js +6 -7
- package/dist/cjs/utils/url.js +26 -2
- package/dist/helper/css/index.js +4 -4
- package/dist/helper/html/index.js +1 -1
- package/dist/helper/ssg/ssg.js +63 -5
- package/dist/helper/streaming/text.js +1 -1
- package/dist/hono-base.js +11 -7
- package/dist/jsx/base.js +3 -1
- package/dist/jsx/dom/client.js +44 -0
- package/dist/jsx/dom/css.js +4 -4
- package/dist/jsx/dom/index.js +25 -21
- package/dist/jsx/dom/jsx-dev-runtime.js +6 -20
- package/dist/jsx/dom/render.js +40 -26
- package/dist/jsx/dom/utils.js +14 -0
- package/dist/jsx/hooks/index.js +4 -2
- package/dist/jsx/index.js +22 -18
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/middleware/jsx-renderer/index.js +1 -1
- package/dist/middleware/jwt/index.js +1 -78
- package/dist/middleware/jwt/jwt.js +85 -0
- package/dist/middleware/secure-headers/index.js +1 -121
- package/dist/middleware/secure-headers/secure-headers.js +126 -0
- package/dist/middleware/timeout/index.js +25 -0
- package/dist/middleware/timing/index.js +1 -85
- package/dist/middleware/timing/timing.js +92 -0
- package/dist/request.js +1 -1
- package/dist/router/reg-exp-router/router.js +2 -2
- package/dist/router/smart-router/router.js +1 -1
- package/dist/router/trie-router/node.js +1 -1
- package/dist/types/adapter/aws-lambda/handler.d.ts +3 -3
- package/dist/types/adapter/aws-lambda/index.d.ts +4 -0
- package/dist/types/adapter/bun/conninfo.d.ts +7 -0
- package/dist/types/adapter/bun/index.d.ts +5 -0
- package/dist/types/adapter/bun/websocket.d.ts +2 -3
- package/dist/types/adapter/cloudflare-pages/index.d.ts +4 -0
- package/dist/types/adapter/cloudflare-workers/conninfo.d.ts +2 -0
- package/dist/types/adapter/cloudflare-workers/index.d.ts +4 -0
- package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +2 -2
- package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +1 -2
- package/dist/types/adapter/cloudflare-workers/utils.d.ts +1 -2
- package/dist/types/adapter/deno/conninfo.d.ts +7 -0
- package/dist/types/adapter/deno/index.d.ts +5 -0
- package/dist/types/adapter/lambda-edge/handler.d.ts +1 -2
- package/dist/types/adapter/lambda-edge/index.d.ts +4 -0
- package/dist/types/adapter/netlify/handler.d.ts +1 -7
- package/dist/types/adapter/netlify/index.d.ts +4 -0
- package/dist/types/adapter/netlify/mod.d.ts +0 -1
- package/dist/types/adapter/vercel/index.d.ts +4 -0
- package/dist/types/client/index.d.ts +4 -0
- package/dist/types/compose.d.ts +1 -1
- package/dist/types/helper/accepts/index.d.ts +4 -0
- package/dist/types/helper/adapter/index.d.ts +4 -0
- package/dist/types/helper/conninfo/index.d.ts +40 -0
- package/dist/types/helper/cookie/index.d.ts +5 -1
- package/dist/types/helper/css/index.d.ts +4 -0
- package/dist/types/helper/dev/index.d.ts +4 -0
- package/dist/types/helper/factory/index.d.ts +4 -0
- package/dist/types/helper/html/index.d.ts +4 -0
- package/dist/types/helper/ssg/index.d.ts +4 -0
- package/dist/types/helper/ssg/ssg.d.ts +6 -3
- package/dist/types/helper/streaming/index.d.ts +4 -0
- package/dist/types/helper/testing/index.d.ts +4 -0
- package/dist/types/helper/websocket/index.d.ts +4 -0
- package/dist/types/hono-base.d.ts +15 -15
- package/dist/types/http-exception.d.ts +4 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/jsx/base.d.ts +10 -11
- package/dist/types/jsx/components.d.ts +1 -1
- package/dist/types/jsx/context.d.ts +1 -1
- package/dist/types/jsx/dom/client.d.ts +26 -0
- package/dist/types/jsx/dom/components.d.ts +2 -2
- package/dist/types/jsx/dom/css.d.ts +31 -20
- package/dist/types/jsx/dom/index.d.ts +13 -7
- package/dist/types/jsx/dom/jsx-dev-runtime.d.ts +5 -1
- package/dist/types/jsx/dom/jsx-runtime.d.ts +4 -0
- package/dist/types/jsx/dom/render.d.ts +4 -3
- package/dist/types/jsx/dom/utils.d.ts +6 -0
- package/dist/types/jsx/hooks/index.d.ts +4 -0
- package/dist/types/jsx/index.d.ts +13 -7
- package/dist/types/jsx/intrinsic-elements.d.ts +629 -630
- package/dist/types/jsx/jsx-dev-runtime.d.ts +5 -0
- package/dist/types/jsx/jsx-runtime.d.ts +5 -0
- package/dist/types/jsx/streaming.d.ts +5 -1
- package/dist/types/jsx/types.d.ts +1 -0
- package/dist/types/middleware/basic-auth/index.d.ts +35 -0
- package/dist/types/middleware/bearer-auth/index.d.ts +33 -0
- package/dist/types/middleware/body-limit/index.d.ts +28 -11
- package/dist/types/middleware/cache/index.d.ts +29 -0
- package/dist/types/middleware/compress/index.d.ts +20 -0
- package/dist/types/middleware/cors/index.d.ts +43 -0
- package/dist/types/middleware/csrf/index.d.ts +41 -0
- package/dist/types/middleware/etag/index.d.ts +24 -0
- package/dist/types/middleware/jsx-renderer/index.d.ts +63 -2
- package/dist/types/middleware/jwt/index.d.ts +5 -17
- package/dist/types/middleware/jwt/jwt.d.ts +48 -0
- package/dist/types/middleware/logger/index.d.ts +20 -0
- package/dist/types/middleware/method-override/index.d.ts +22 -10
- package/dist/types/middleware/powered-by/index.d.ts +4 -0
- package/dist/types/middleware/pretty-json/index.d.ts +23 -0
- package/dist/types/middleware/secure-headers/index.d.ts +6 -64
- package/dist/types/middleware/secure-headers/secure-headers.d.ts +97 -0
- package/dist/types/middleware/serve-static/index.d.ts +4 -0
- package/dist/types/middleware/timeout/index.d.ts +31 -0
- package/dist/types/middleware/timing/index.d.ts +5 -29
- package/dist/types/middleware/timing/timing.d.ts +111 -0
- package/dist/types/middleware/trailing-slash/index.d.ts +29 -5
- package/dist/types/preset/quick.d.ts +4 -0
- package/dist/types/preset/tiny.d.ts +4 -0
- package/dist/types/request.d.ts +5 -4
- package/dist/types/router/linear-router/index.d.ts +4 -0
- package/dist/types/router/linear-router/router.d.ts +1 -1
- package/dist/types/router/pattern-router/index.d.ts +4 -0
- package/dist/types/router/reg-exp-router/index.d.ts +4 -0
- package/dist/types/router/reg-exp-router/router.d.ts +1 -1
- package/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/dist/types/router/smart-router/index.d.ts +4 -0
- package/dist/types/router/smart-router/router.d.ts +1 -1
- package/dist/types/router/trie-router/index.d.ts +4 -0
- package/dist/types/router.d.ts +4 -0
- package/dist/types/types.d.ts +4 -0
- package/dist/types/utils/body.d.ts +61 -3
- package/dist/types/utils/buffer.d.ts +4 -0
- package/dist/types/utils/color.d.ts +4 -0
- package/dist/types/utils/concurrent.d.ts +4 -0
- package/dist/types/utils/cookie.d.ts +4 -0
- package/dist/types/utils/crypto.d.ts +4 -0
- package/dist/types/utils/encode.d.ts +4 -0
- package/dist/types/utils/filepath.d.ts +4 -0
- package/dist/types/utils/handler.d.ts +4 -0
- package/dist/types/utils/html.d.ts +4 -0
- package/dist/types/utils/http-status.d.ts +4 -0
- package/dist/types/utils/jwt/index.d.ts +4 -0
- package/dist/types/utils/jwt/jwt.d.ts +3 -3
- package/dist/types/utils/mime.d.ts +4 -0
- package/dist/types/utils/stream.d.ts +4 -0
- package/dist/types/utils/types.d.ts +4 -0
- package/dist/types/utils/url.d.ts +4 -0
- package/dist/types/validator/index.d.ts +4 -0
- package/dist/types/validator/validator.d.ts +1 -1
- package/dist/utils/body.js +34 -9
- package/dist/utils/jwt/index.js +1 -1
- package/dist/utils/jwt/jws.js +1 -2
- package/dist/utils/jwt/jwt.js +5 -5
- package/dist/utils/url.js +26 -2
- package/package.json +27 -6
- package/dist/cjs/adapter/aws-lambda/awslambda.d.js +0 -1
- package/dist/cjs/helper.js +0 -44
- package/dist/helper.js +0 -18
- /package/dist/{adapter/aws-lambda/awslambda.d.js → helper/conninfo/index.js} +0 -0
package/dist/jsx/dom/render.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// src/jsx/dom/render.ts
|
|
2
2
|
import { toArray } from "../children.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DOM_ERROR_HANDLER, DOM_INTERNAL_TAG, DOM_RENDERER, DOM_STASH } from "../constants.js";
|
|
4
4
|
import { globalContexts as globalJSXContexts, useContext } from "../context.js";
|
|
5
5
|
import { STASH_EFFECT } from "../hooks/index.js";
|
|
6
6
|
import { styleObjectForEach } from "../utils.js";
|
|
7
7
|
import { createContext } from "./context.js";
|
|
8
|
+
import { newJSXNode } from "./utils.js";
|
|
8
9
|
var HONO_PORTAL_ELEMENT = "_hp";
|
|
9
10
|
var eventAliasMap = {
|
|
10
11
|
Change: "Input",
|
|
@@ -26,6 +27,7 @@ var getEventSpec = (key) => {
|
|
|
26
27
|
}
|
|
27
28
|
return void 0;
|
|
28
29
|
};
|
|
30
|
+
var toAttributeName = (element, key) => element instanceof SVGElement && /[A-Z]/.test(key) && (key in element.style || key.match(/^(?:o|pai|str|u|ve)/)) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
|
|
29
31
|
var applyProps = (container, attributes, oldAttributes) => {
|
|
30
32
|
attributes ||= {};
|
|
31
33
|
for (const [key, value] of Object.entries(attributes)) {
|
|
@@ -80,14 +82,15 @@ var applyProps = (container, attributes, oldAttributes) => {
|
|
|
80
82
|
;
|
|
81
83
|
container[key] = value;
|
|
82
84
|
}
|
|
85
|
+
const k = toAttributeName(container, key);
|
|
83
86
|
if (value === null || value === void 0 || value === false) {
|
|
84
|
-
container.removeAttribute(
|
|
87
|
+
container.removeAttribute(k);
|
|
85
88
|
} else if (value === true) {
|
|
86
|
-
container.setAttribute(
|
|
89
|
+
container.setAttribute(k, "");
|
|
87
90
|
} else if (typeof value === "string" || typeof value === "number") {
|
|
88
|
-
container.setAttribute(
|
|
91
|
+
container.setAttribute(k, value);
|
|
89
92
|
} else {
|
|
90
|
-
container.setAttribute(
|
|
93
|
+
container.setAttribute(k, value.toString());
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
}
|
|
@@ -105,7 +108,7 @@ var applyProps = (container, attributes, oldAttributes) => {
|
|
|
105
108
|
value.current = null;
|
|
106
109
|
}
|
|
107
110
|
} else {
|
|
108
|
-
container.removeAttribute(key);
|
|
111
|
+
container.removeAttribute(toAttributeName(container, key));
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
114
|
}
|
|
@@ -153,6 +156,8 @@ var getNextChildren = (node, container, nextChildren, childrenToRemove, callback
|
|
|
153
156
|
var findInsertBefore = (node) => {
|
|
154
157
|
if (!node) {
|
|
155
158
|
return null;
|
|
159
|
+
} else if (node.tag === HONO_PORTAL_ELEMENT) {
|
|
160
|
+
return findInsertBefore(node.nN);
|
|
156
161
|
} else if (node.e) {
|
|
157
162
|
return node.e;
|
|
158
163
|
}
|
|
@@ -214,7 +219,7 @@ var applyNodeObject = (node, container) => {
|
|
|
214
219
|
const callbacks = [];
|
|
215
220
|
getNextChildren(node, container, next, remove, callbacks);
|
|
216
221
|
const childNodes = container.childNodes;
|
|
217
|
-
let offset = findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ?? findChildNodeIndex(childNodes, next.find((n) => n.e)?.e) ?? childNodes.length;
|
|
222
|
+
let offset = findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ?? findChildNodeIndex(childNodes, next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e) ?? childNodes.length;
|
|
218
223
|
for (let i = 0, len = next.length; i < len; i++, offset++) {
|
|
219
224
|
const child = next[i];
|
|
220
225
|
let el;
|
|
@@ -229,11 +234,14 @@ var applyNodeObject = (node, container) => {
|
|
|
229
234
|
applyProps(el, child.props, child.pP);
|
|
230
235
|
applyNode(child, el);
|
|
231
236
|
}
|
|
232
|
-
if (
|
|
237
|
+
if (child.tag === HONO_PORTAL_ELEMENT) {
|
|
238
|
+
offset--;
|
|
239
|
+
} else if (childNodes[offset] !== el && childNodes[offset - 1] !== child.e) {
|
|
233
240
|
container.insertBefore(el, childNodes[offset] || null);
|
|
234
241
|
}
|
|
235
242
|
}
|
|
236
243
|
remove.forEach(removeNode);
|
|
244
|
+
callbacks.forEach(([, , , , cb]) => cb?.());
|
|
237
245
|
callbacks.forEach(([, cb]) => cb?.());
|
|
238
246
|
requestAnimationFrame(() => {
|
|
239
247
|
callbacks.forEach(([, , , cb]) => cb?.());
|
|
@@ -249,7 +257,7 @@ var build = (context, node, topLevelErrorHandlerNode, children) => {
|
|
|
249
257
|
}
|
|
250
258
|
const oldVChildren = node.vC ? [...node.vC] : [];
|
|
251
259
|
const vChildren = [];
|
|
252
|
-
|
|
260
|
+
node.vR = [];
|
|
253
261
|
let prevNode;
|
|
254
262
|
try {
|
|
255
263
|
children.flat().forEach((c) => {
|
|
@@ -263,24 +271,23 @@ var build = (context, node, topLevelErrorHandlerNode, children) => {
|
|
|
263
271
|
child[DOM_STASH][2] = globalJSXContexts.map((c2) => [c2, c2.values.at(-1)]);
|
|
264
272
|
}
|
|
265
273
|
let oldChild;
|
|
266
|
-
const i = oldVChildren.findIndex(
|
|
274
|
+
const i = oldVChildren.findIndex(
|
|
275
|
+
isNodeString(child) ? (c2) => isNodeString(c2) : child.key !== void 0 ? (c2) => c2.key === child.key : (c2) => c2.tag === child.tag
|
|
276
|
+
);
|
|
267
277
|
if (i !== -1) {
|
|
268
278
|
oldChild = oldVChildren[i];
|
|
269
279
|
oldVChildren.splice(i, 1);
|
|
270
280
|
}
|
|
271
281
|
if (oldChild) {
|
|
272
282
|
if (isNodeString(child)) {
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
oldChild.t = child.t;
|
|
278
|
-
oldChild.d = true;
|
|
279
|
-
}
|
|
280
|
-
child = oldChild;
|
|
283
|
+
if (oldChild.t !== child.t) {
|
|
284
|
+
;
|
|
285
|
+
oldChild.t = child.t;
|
|
286
|
+
oldChild.d = true;
|
|
281
287
|
}
|
|
288
|
+
child = oldChild;
|
|
282
289
|
} else if (oldChild.tag !== child.tag) {
|
|
283
|
-
|
|
290
|
+
node.vR.push(oldChild);
|
|
284
291
|
} else {
|
|
285
292
|
oldChild.pP = oldChild.props;
|
|
286
293
|
oldChild.props = child.props;
|
|
@@ -302,8 +309,7 @@ var build = (context, node, topLevelErrorHandlerNode, children) => {
|
|
|
302
309
|
}
|
|
303
310
|
});
|
|
304
311
|
node.vC = vChildren;
|
|
305
|
-
|
|
306
|
-
node.vR = vChildrenToRemove;
|
|
312
|
+
node.vR.push(...oldVChildren);
|
|
307
313
|
} catch (e) {
|
|
308
314
|
if (errorHandler) {
|
|
309
315
|
const fallbackUpdateFn = () => update([0, false, context[2]], topLevelErrorHandlerNode);
|
|
@@ -338,10 +344,14 @@ var buildNode = (node) => {
|
|
|
338
344
|
} else if (typeof node === "string" || typeof node === "number") {
|
|
339
345
|
return { t: node.toString(), d: true };
|
|
340
346
|
} else {
|
|
347
|
+
if ("vR" in node) {
|
|
348
|
+
node = newJSXNode({
|
|
349
|
+
tag: node.tag,
|
|
350
|
+
props: node.props,
|
|
351
|
+
key: node.key
|
|
352
|
+
});
|
|
353
|
+
}
|
|
341
354
|
if (typeof node.tag === "function") {
|
|
342
|
-
if (node[DOM_STASH]) {
|
|
343
|
-
node = { ...node };
|
|
344
|
-
}
|
|
345
355
|
;
|
|
346
356
|
node[DOM_STASH] = [0, []];
|
|
347
357
|
} else {
|
|
@@ -417,8 +427,7 @@ var update = async (context, node) => {
|
|
|
417
427
|
}
|
|
418
428
|
return promise;
|
|
419
429
|
};
|
|
420
|
-
var
|
|
421
|
-
const node = buildNode({ tag: "", props: { children: jsxNode } });
|
|
430
|
+
var renderNode = (node, container) => {
|
|
422
431
|
const context = [];
|
|
423
432
|
context[4] = true;
|
|
424
433
|
build(context, node, void 0);
|
|
@@ -428,6 +437,9 @@ var render = (jsxNode, container) => {
|
|
|
428
437
|
replaceContainer(node, fragment, container);
|
|
429
438
|
container.replaceChildren(fragment);
|
|
430
439
|
};
|
|
440
|
+
var render = (jsxNode, container) => {
|
|
441
|
+
renderNode(buildNode({ tag: "", props: { children: jsxNode } }), container);
|
|
442
|
+
};
|
|
431
443
|
var flushSync = (callback) => {
|
|
432
444
|
const set = /* @__PURE__ */ new Set();
|
|
433
445
|
currentUpdateSets.push(set);
|
|
@@ -452,8 +464,10 @@ var createPortal = (children, container, key) => ({
|
|
|
452
464
|
export {
|
|
453
465
|
build,
|
|
454
466
|
buildDataStack,
|
|
467
|
+
buildNode,
|
|
455
468
|
createPortal,
|
|
456
469
|
flushSync,
|
|
457
470
|
render,
|
|
471
|
+
renderNode,
|
|
458
472
|
update
|
|
459
473
|
};
|
package/dist/jsx/dom/utils.js
CHANGED
|
@@ -5,6 +5,20 @@ var setInternalTagFlag = (fn) => {
|
|
|
5
5
|
fn[DOM_INTERNAL_TAG] = true;
|
|
6
6
|
return fn;
|
|
7
7
|
};
|
|
8
|
+
var JSXNodeCompatPrototype = {
|
|
9
|
+
type: {
|
|
10
|
+
get() {
|
|
11
|
+
return this.tag;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
ref: {
|
|
15
|
+
get() {
|
|
16
|
+
return this.props?.ref;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var newJSXNode = (obj) => Object.defineProperties(obj, JSXNodeCompatPrototype);
|
|
8
21
|
export {
|
|
22
|
+
newJSXNode,
|
|
9
23
|
setInternalTagFlag
|
|
10
24
|
};
|
package/dist/jsx/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/jsx/hooks/index.ts
|
|
2
2
|
import { DOM_STASH } from "../constants.js";
|
|
3
|
-
import { buildDataStack, update
|
|
3
|
+
import { build, buildDataStack, update } from "../dom/render.js";
|
|
4
4
|
var STASH_SATE = 0;
|
|
5
5
|
var STASH_EFFECT = 1;
|
|
6
6
|
var STASH_CALLBACK = 2;
|
|
@@ -175,13 +175,14 @@ var useEffectCommon = (index, effect, deps) => {
|
|
|
175
175
|
data[index] = void 0;
|
|
176
176
|
data[2] = effect();
|
|
177
177
|
};
|
|
178
|
-
const data = [deps, void 0, void 0, void 0];
|
|
178
|
+
const data = [deps, void 0, void 0, void 0, void 0];
|
|
179
179
|
data[index] = runner;
|
|
180
180
|
effectDepsArray[hookIndex] = data;
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
var useEffect = (effect, deps) => useEffectCommon(3, effect, deps);
|
|
184
184
|
var useLayoutEffect = (effect, deps) => useEffectCommon(1, effect, deps);
|
|
185
|
+
var useInsertionEffect = (effect, deps) => useEffectCommon(4, effect, deps);
|
|
185
186
|
var useCallback = (callback, deps) => {
|
|
186
187
|
const buildData = buildDataStack.at(-1);
|
|
187
188
|
if (!buildData) {
|
|
@@ -314,6 +315,7 @@ export {
|
|
|
314
315
|
useEffect,
|
|
315
316
|
useId,
|
|
316
317
|
useImperativeHandle,
|
|
318
|
+
useInsertionEffect,
|
|
317
319
|
useLayoutEffect,
|
|
318
320
|
useMemo,
|
|
319
321
|
useReducer,
|
package/dist/jsx/index.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
// src/jsx/index.ts
|
|
2
|
-
import {
|
|
2
|
+
import { Fragment, cloneElement, isValidElement, jsx, memo, reactAPICompatVersion } from "./base.js";
|
|
3
3
|
import { Children } from "./children.js";
|
|
4
4
|
import { ErrorBoundary } from "./components.js";
|
|
5
5
|
import { createContext, useContext } from "./context.js";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
useRef,
|
|
10
|
-
useCallback,
|
|
11
|
-
use,
|
|
7
|
+
createRef,
|
|
8
|
+
forwardRef,
|
|
12
9
|
startTransition,
|
|
13
|
-
useTransition,
|
|
14
|
-
useDeferredValue,
|
|
15
10
|
startViewTransition,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
useLayoutEffect,
|
|
19
|
-
useReducer,
|
|
20
|
-
useId,
|
|
11
|
+
use,
|
|
12
|
+
useCallback,
|
|
21
13
|
useDebugValue,
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
useDeferredValue,
|
|
15
|
+
useEffect,
|
|
16
|
+
useId,
|
|
24
17
|
useImperativeHandle,
|
|
25
|
-
|
|
18
|
+
useInsertionEffect,
|
|
19
|
+
useLayoutEffect,
|
|
20
|
+
useMemo,
|
|
21
|
+
useReducer,
|
|
22
|
+
useRef,
|
|
23
|
+
useState,
|
|
24
|
+
useSyncExternalStore,
|
|
25
|
+
useTransition,
|
|
26
|
+
useViewTransition
|
|
26
27
|
} from "./hooks/index.js";
|
|
27
28
|
import { Suspense } from "./streaming.js";
|
|
28
|
-
export * from "./types.js";
|
|
29
29
|
var jsx_default = {
|
|
30
|
+
version: reactAPICompatVersion,
|
|
30
31
|
memo,
|
|
31
32
|
Fragment,
|
|
32
33
|
isValidElement,
|
|
@@ -50,6 +51,7 @@ var jsx_default = {
|
|
|
50
51
|
useViewTransition,
|
|
51
52
|
useMemo,
|
|
52
53
|
useLayoutEffect,
|
|
54
|
+
useInsertionEffect,
|
|
53
55
|
createRef,
|
|
54
56
|
forwardRef,
|
|
55
57
|
useImperativeHandle,
|
|
@@ -81,6 +83,7 @@ export {
|
|
|
81
83
|
useEffect,
|
|
82
84
|
useId,
|
|
83
85
|
useImperativeHandle,
|
|
86
|
+
useInsertionEffect,
|
|
84
87
|
useLayoutEffect,
|
|
85
88
|
useMemo,
|
|
86
89
|
useReducer,
|
|
@@ -88,5 +91,6 @@ export {
|
|
|
88
91
|
useState,
|
|
89
92
|
useSyncExternalStore,
|
|
90
93
|
useTransition,
|
|
91
|
-
useViewTransition
|
|
94
|
+
useViewTransition,
|
|
95
|
+
reactAPICompatVersion as version
|
|
92
96
|
};
|
package/dist/jsx/jsx-runtime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/jsx/jsx-runtime.ts
|
|
2
2
|
import { jsxDEV, Fragment } from "./jsx-dev-runtime.js";
|
|
3
3
|
import { jsxDEV as jsxDEV2 } from "./jsx-dev-runtime.js";
|
|
4
|
-
import {
|
|
4
|
+
import { html, raw } from "../helper/html/index.js";
|
|
5
5
|
var jsxAttr = (name, value) => typeof value === "string" ? raw(name + '="' + html`${value}` + '"') : html`${name}="${value}"`;
|
|
6
6
|
var jsxEscape = (value) => value;
|
|
7
7
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/middleware/jsx-renderer/index.ts
|
|
2
2
|
import { html, raw } from "../../helper/html/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Fragment, createContext, jsx, useContext } from "../../jsx/index.js";
|
|
4
4
|
import { renderToReadableStream } from "../../jsx/streaming.js";
|
|
5
5
|
var RequestContext = createContext(null);
|
|
6
6
|
var createRenderer = (c, Layout, component, options) => (children, props) => {
|
|
@@ -1,82 +1,5 @@
|
|
|
1
1
|
// src/middleware/jwt/index.ts
|
|
2
|
-
import {
|
|
3
|
-
import { HTTPException } from "../../http-exception.js";
|
|
4
|
-
import { Jwt } from "../../utils/jwt/index.js";
|
|
5
|
-
import "../../context.js";
|
|
6
|
-
var jwt = (options) => {
|
|
7
|
-
if (!options || !options.secret) {
|
|
8
|
-
throw new Error('JWT auth middleware requires options for "secret');
|
|
9
|
-
}
|
|
10
|
-
if (!crypto.subtle || !crypto.subtle.importKey) {
|
|
11
|
-
throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
|
12
|
-
}
|
|
13
|
-
return async function jwt2(ctx, next) {
|
|
14
|
-
const credentials = ctx.req.raw.headers.get("Authorization");
|
|
15
|
-
let token;
|
|
16
|
-
if (credentials) {
|
|
17
|
-
const parts = credentials.split(/\s+/);
|
|
18
|
-
if (parts.length !== 2) {
|
|
19
|
-
const errDescription = "invalid credentials structure";
|
|
20
|
-
throw new HTTPException(401, {
|
|
21
|
-
message: errDescription,
|
|
22
|
-
res: unauthorizedResponse({
|
|
23
|
-
ctx,
|
|
24
|
-
error: "invalid_request",
|
|
25
|
-
errDescription
|
|
26
|
-
})
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
token = parts[1];
|
|
30
|
-
}
|
|
31
|
-
} else if (options.cookie) {
|
|
32
|
-
token = getCookie(ctx)[options.cookie];
|
|
33
|
-
}
|
|
34
|
-
if (!token) {
|
|
35
|
-
const errDescription = "no authorization included in request";
|
|
36
|
-
throw new HTTPException(401, {
|
|
37
|
-
message: errDescription,
|
|
38
|
-
res: unauthorizedResponse({
|
|
39
|
-
ctx,
|
|
40
|
-
error: "invalid_request",
|
|
41
|
-
errDescription
|
|
42
|
-
})
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
let payload;
|
|
46
|
-
let cause;
|
|
47
|
-
try {
|
|
48
|
-
payload = await Jwt.verify(token, options.secret, options.alg);
|
|
49
|
-
} catch (e) {
|
|
50
|
-
cause = e;
|
|
51
|
-
}
|
|
52
|
-
if (!payload) {
|
|
53
|
-
throw new HTTPException(401, {
|
|
54
|
-
message: "Unauthorized",
|
|
55
|
-
res: unauthorizedResponse({
|
|
56
|
-
ctx,
|
|
57
|
-
error: "invalid_token",
|
|
58
|
-
statusText: "Unauthorized",
|
|
59
|
-
errDescription: "token verification failure"
|
|
60
|
-
}),
|
|
61
|
-
cause
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
ctx.set("jwtPayload", payload);
|
|
65
|
-
await next();
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
function unauthorizedResponse(opts) {
|
|
69
|
-
return new Response("Unauthorized", {
|
|
70
|
-
status: 401,
|
|
71
|
-
statusText: opts.statusText,
|
|
72
|
-
headers: {
|
|
73
|
-
"WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
var verify = Jwt.verify;
|
|
78
|
-
var decode = Jwt.decode;
|
|
79
|
-
var sign = Jwt.sign;
|
|
2
|
+
import { jwt, verify, decode, sign } from "./jwt.js";
|
|
80
3
|
export {
|
|
81
4
|
decode,
|
|
82
5
|
jwt,
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/middleware/jwt/jwt.ts
|
|
2
|
+
import { getCookie } from "../../helper/cookie/index.js";
|
|
3
|
+
import { HTTPException } from "../../http-exception.js";
|
|
4
|
+
import { Jwt } from "../../utils/jwt/index.js";
|
|
5
|
+
import "../../context.js";
|
|
6
|
+
var jwt = (options) => {
|
|
7
|
+
if (!options || !options.secret) {
|
|
8
|
+
throw new Error('JWT auth middleware requires options for "secret"');
|
|
9
|
+
}
|
|
10
|
+
if (!crypto.subtle || !crypto.subtle.importKey) {
|
|
11
|
+
throw new Error("`crypto.subtle.importKey` is undefined. JWT auth middleware requires it.");
|
|
12
|
+
}
|
|
13
|
+
return async function jwt2(ctx, next) {
|
|
14
|
+
const credentials = ctx.req.raw.headers.get("Authorization");
|
|
15
|
+
let token;
|
|
16
|
+
if (credentials) {
|
|
17
|
+
const parts = credentials.split(/\s+/);
|
|
18
|
+
if (parts.length !== 2) {
|
|
19
|
+
const errDescription = "invalid credentials structure";
|
|
20
|
+
throw new HTTPException(401, {
|
|
21
|
+
message: errDescription,
|
|
22
|
+
res: unauthorizedResponse({
|
|
23
|
+
ctx,
|
|
24
|
+
error: "invalid_request",
|
|
25
|
+
errDescription
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
token = parts[1];
|
|
30
|
+
}
|
|
31
|
+
} else if (options.cookie) {
|
|
32
|
+
token = getCookie(ctx)[options.cookie];
|
|
33
|
+
}
|
|
34
|
+
if (!token) {
|
|
35
|
+
const errDescription = "no authorization included in request";
|
|
36
|
+
throw new HTTPException(401, {
|
|
37
|
+
message: errDescription,
|
|
38
|
+
res: unauthorizedResponse({
|
|
39
|
+
ctx,
|
|
40
|
+
error: "invalid_request",
|
|
41
|
+
errDescription
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
let payload;
|
|
46
|
+
let cause;
|
|
47
|
+
try {
|
|
48
|
+
payload = await Jwt.verify(token, options.secret, options.alg);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
cause = e;
|
|
51
|
+
}
|
|
52
|
+
if (!payload) {
|
|
53
|
+
throw new HTTPException(401, {
|
|
54
|
+
message: "Unauthorized",
|
|
55
|
+
res: unauthorizedResponse({
|
|
56
|
+
ctx,
|
|
57
|
+
error: "invalid_token",
|
|
58
|
+
statusText: "Unauthorized",
|
|
59
|
+
errDescription: "token verification failure"
|
|
60
|
+
}),
|
|
61
|
+
cause
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
ctx.set("jwtPayload", payload);
|
|
65
|
+
await next();
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
function unauthorizedResponse(opts) {
|
|
69
|
+
return new Response("Unauthorized", {
|
|
70
|
+
status: 401,
|
|
71
|
+
statusText: opts.statusText,
|
|
72
|
+
headers: {
|
|
73
|
+
"WWW-Authenticate": `Bearer realm="${opts.ctx.req.url}",error="${opts.error}",error_description="${opts.errDescription}"`
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
var verify = Jwt.verify;
|
|
78
|
+
var decode = Jwt.decode;
|
|
79
|
+
var sign = Jwt.sign;
|
|
80
|
+
export {
|
|
81
|
+
decode,
|
|
82
|
+
jwt,
|
|
83
|
+
sign,
|
|
84
|
+
verify
|
|
85
|
+
};
|
|
@@ -1,125 +1,5 @@
|
|
|
1
1
|
// src/middleware/secure-headers/index.ts
|
|
2
|
-
import {
|
|
3
|
-
var HEADERS_MAP = {
|
|
4
|
-
crossOriginEmbedderPolicy: ["Cross-Origin-Embedder-Policy", "require-corp"],
|
|
5
|
-
crossOriginResourcePolicy: ["Cross-Origin-Resource-Policy", "same-origin"],
|
|
6
|
-
crossOriginOpenerPolicy: ["Cross-Origin-Opener-Policy", "same-origin"],
|
|
7
|
-
originAgentCluster: ["Origin-Agent-Cluster", "?1"],
|
|
8
|
-
referrerPolicy: ["Referrer-Policy", "no-referrer"],
|
|
9
|
-
strictTransportSecurity: ["Strict-Transport-Security", "max-age=15552000; includeSubDomains"],
|
|
10
|
-
xContentTypeOptions: ["X-Content-Type-Options", "nosniff"],
|
|
11
|
-
xDnsPrefetchControl: ["X-DNS-Prefetch-Control", "off"],
|
|
12
|
-
xDownloadOptions: ["X-Download-Options", "noopen"],
|
|
13
|
-
xFrameOptions: ["X-Frame-Options", "SAMEORIGIN"],
|
|
14
|
-
xPermittedCrossDomainPolicies: ["X-Permitted-Cross-Domain-Policies", "none"],
|
|
15
|
-
xXssProtection: ["X-XSS-Protection", "0"]
|
|
16
|
-
};
|
|
17
|
-
var DEFAULT_OPTIONS = {
|
|
18
|
-
crossOriginEmbedderPolicy: false,
|
|
19
|
-
crossOriginResourcePolicy: true,
|
|
20
|
-
crossOriginOpenerPolicy: true,
|
|
21
|
-
originAgentCluster: true,
|
|
22
|
-
referrerPolicy: true,
|
|
23
|
-
strictTransportSecurity: true,
|
|
24
|
-
xContentTypeOptions: true,
|
|
25
|
-
xDnsPrefetchControl: true,
|
|
26
|
-
xDownloadOptions: true,
|
|
27
|
-
xFrameOptions: true,
|
|
28
|
-
xPermittedCrossDomainPolicies: true,
|
|
29
|
-
xXssProtection: true
|
|
30
|
-
};
|
|
31
|
-
var generateNonce = () => {
|
|
32
|
-
const buffer = new Uint8Array(16);
|
|
33
|
-
crypto.getRandomValues(buffer);
|
|
34
|
-
return encodeBase64(buffer);
|
|
35
|
-
};
|
|
36
|
-
var NONCE = (ctx) => {
|
|
37
|
-
const nonce = ctx.get("secureHeadersNonce") || (() => {
|
|
38
|
-
const newNonce = generateNonce();
|
|
39
|
-
ctx.set("secureHeadersNonce", newNonce);
|
|
40
|
-
return newNonce;
|
|
41
|
-
})();
|
|
42
|
-
return `'nonce-${nonce}'`;
|
|
43
|
-
};
|
|
44
|
-
var secureHeaders = (customOptions) => {
|
|
45
|
-
const options = { ...DEFAULT_OPTIONS, ...customOptions };
|
|
46
|
-
const headersToSet = getFilteredHeaders(options);
|
|
47
|
-
const callbacks = [];
|
|
48
|
-
if (options.contentSecurityPolicy) {
|
|
49
|
-
const [callback, value] = getCSPDirectives(options.contentSecurityPolicy);
|
|
50
|
-
if (callback) {
|
|
51
|
-
callbacks.push(callback);
|
|
52
|
-
}
|
|
53
|
-
headersToSet.push(["Content-Security-Policy", value]);
|
|
54
|
-
}
|
|
55
|
-
if (options.reportingEndpoints) {
|
|
56
|
-
headersToSet.push(["Reporting-Endpoints", getReportingEndpoints(options.reportingEndpoints)]);
|
|
57
|
-
}
|
|
58
|
-
if (options.reportTo) {
|
|
59
|
-
headersToSet.push(["Report-To", getReportToOptions(options.reportTo)]);
|
|
60
|
-
}
|
|
61
|
-
return async function secureHeaders2(ctx, next) {
|
|
62
|
-
const headersToSetForReq = callbacks.length === 0 ? headersToSet : callbacks.reduce((acc, cb) => cb(ctx, acc), headersToSet);
|
|
63
|
-
await next();
|
|
64
|
-
setHeaders(ctx, headersToSetForReq);
|
|
65
|
-
ctx.res.headers.delete("X-Powered-By");
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
function getFilteredHeaders(options) {
|
|
69
|
-
return Object.entries(HEADERS_MAP).filter(([key]) => options[key]).map(([key, defaultValue]) => {
|
|
70
|
-
const overrideValue = options[key];
|
|
71
|
-
return typeof overrideValue === "string" ? [defaultValue[0], overrideValue] : defaultValue;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
function getCSPDirectives(contentSecurityPolicy) {
|
|
75
|
-
const callbacks = [];
|
|
76
|
-
const resultValues = [];
|
|
77
|
-
for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
|
|
78
|
-
const valueArray = Array.isArray(value) ? value : [value];
|
|
79
|
-
valueArray.forEach((value2, i) => {
|
|
80
|
-
if (typeof value2 === "function") {
|
|
81
|
-
const index = i * 2 + 2 + resultValues.length;
|
|
82
|
-
callbacks.push((ctx, values) => {
|
|
83
|
-
values[index] = value2(ctx, directive);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
resultValues.push(
|
|
88
|
-
directive.replace(
|
|
89
|
-
/[A-Z]+(?![a-z])|[A-Z]/g,
|
|
90
|
-
(match, offset) => offset ? "-" + match.toLowerCase() : match.toLowerCase()
|
|
91
|
-
),
|
|
92
|
-
...valueArray.flatMap((value2) => [" ", value2]),
|
|
93
|
-
"; "
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
resultValues.pop();
|
|
97
|
-
return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
|
|
98
|
-
(ctx, headersToSet) => headersToSet.map((values) => {
|
|
99
|
-
if (values[0] === "Content-Security-Policy") {
|
|
100
|
-
const clone = values[1].slice();
|
|
101
|
-
callbacks.forEach((cb) => {
|
|
102
|
-
cb(ctx, clone);
|
|
103
|
-
});
|
|
104
|
-
return [values[0], clone.join("")];
|
|
105
|
-
} else {
|
|
106
|
-
return values;
|
|
107
|
-
}
|
|
108
|
-
}),
|
|
109
|
-
resultValues
|
|
110
|
-
];
|
|
111
|
-
}
|
|
112
|
-
function getReportingEndpoints(reportingEndpoints = []) {
|
|
113
|
-
return reportingEndpoints.map((endpoint) => `${endpoint.name}="${endpoint.url}"`).join(", ");
|
|
114
|
-
}
|
|
115
|
-
function getReportToOptions(reportTo = []) {
|
|
116
|
-
return reportTo.map((option) => JSON.stringify(option)).join(", ");
|
|
117
|
-
}
|
|
118
|
-
function setHeaders(ctx, headersToSet) {
|
|
119
|
-
headersToSet.forEach(([header, value]) => {
|
|
120
|
-
ctx.res.headers.set(header, value);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
2
|
+
import { NONCE, secureHeaders } from "./secure-headers.js";
|
|
123
3
|
export {
|
|
124
4
|
NONCE,
|
|
125
5
|
secureHeaders
|