elysia 2.0.0-beta.2 → 2.0.0-beta.21
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/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/handler/fetch.js
CHANGED
|
@@ -13,8 +13,8 @@ let deuri = require("deuri");
|
|
|
13
13
|
deuri = require_runtime.__toESM(deuri);
|
|
14
14
|
|
|
15
15
|
//#region src/handler/fetch.ts
|
|
16
|
-
function extractPath(url, context
|
|
17
|
-
const s = url.indexOf("/",
|
|
16
|
+
function extractPath(url, context) {
|
|
17
|
+
const s = url.indexOf("/", require_utils.authorityEnd(url));
|
|
18
18
|
const q = context.qi = url.indexOf("?", s);
|
|
19
19
|
return context.path = q === -1 ? url.slice(s) : url.substring(s, q);
|
|
20
20
|
}
|
|
@@ -23,7 +23,7 @@ function notFound(context) {
|
|
|
23
23
|
if (set.cookie || require_utils.isNotEmpty(set.headers)) {
|
|
24
24
|
require_adapter_utils.handleSet(set);
|
|
25
25
|
if (!set.headers["content-type"]) require_adapter_utils.materializeSetHeaders(set)["content-type"] = require_error.PROBLEM_JSON;
|
|
26
|
-
return new Response(require_handler_utils.
|
|
26
|
+
return new Response(require_handler_utils.getNotFoundBody(), {
|
|
27
27
|
status: 404,
|
|
28
28
|
headers: set.headers
|
|
29
29
|
});
|
|
@@ -37,12 +37,16 @@ function decodeParams(params) {
|
|
|
37
37
|
}
|
|
38
38
|
return params;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
function
|
|
42
|
-
if (
|
|
40
|
+
const warnedPathMutation = /* @__PURE__ */ new WeakSet();
|
|
41
|
+
function warnPathMutation(app) {
|
|
42
|
+
if (warnedPathMutation.has(app)) return;
|
|
43
|
+
warnedPathMutation.add(app);
|
|
44
|
+
console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
|
|
45
|
+
}
|
|
46
|
+
function finalizeError(context, handleError, afterResponse, error, sign) {
|
|
43
47
|
let resp;
|
|
44
48
|
try {
|
|
45
|
-
resp = handleError(context, error);
|
|
49
|
+
resp = handleError(context, error, sign);
|
|
46
50
|
} catch (errorPipelineThrow) {
|
|
47
51
|
if (!require_universal_is_production.isProduction()) console.error(errorPipelineThrow);
|
|
48
52
|
resp = require_error.internalServerErrorResponse(error);
|
|
@@ -67,23 +71,19 @@ function dispatchResult(result, context, handleError, afterResponse) {
|
|
|
67
71
|
}
|
|
68
72
|
function findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS, hasDynamicWS) {
|
|
69
73
|
const path = context.path;
|
|
70
|
-
|
|
74
|
+
const method = request.method;
|
|
75
|
+
if (hasWS && method === "GET") {
|
|
71
76
|
const handler = map["WS"]?.[path];
|
|
72
77
|
const found = handler === void 0 && hasDynamicWS ? router?.find("WS", path) : void 0;
|
|
73
78
|
if (handler !== void 0 || found) {
|
|
74
79
|
const upgrade = request.headers.get("upgrade");
|
|
75
80
|
if (upgrade && upgrade.toLowerCase() === "websocket") {
|
|
76
|
-
if (handler)
|
|
77
|
-
const r = handler(context);
|
|
78
|
-
return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
|
|
79
|
-
}
|
|
81
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
80
82
|
context.params = path.indexOf("%") === -1 ? found.params : decodeParams(found.params);
|
|
81
|
-
|
|
82
|
-
return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
|
|
83
|
+
return dispatchResult(found.store(context), context, handleError, afterResponse);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
|
-
const method = request.method;
|
|
87
87
|
const methodMap = map[method];
|
|
88
88
|
let handler = methodMap?.[path];
|
|
89
89
|
if (!handler) if (!strictPath && path.length > 1 && path.charCodeAt(path.length - 1) === 47) {
|
|
@@ -100,7 +100,7 @@ function findRoute(context, request, map, router, hasError, handleError, afterRe
|
|
|
100
100
|
context.params = path.indexOf("%") === -1 ? found.params : decodeParams(found.params);
|
|
101
101
|
return dispatchResult(found.store(context), context, handleError, afterResponse);
|
|
102
102
|
}
|
|
103
|
-
if (hasError) return finalizeError(context, handleError, afterResponse,
|
|
103
|
+
if (hasError) return finalizeError(context, handleError, afterResponse, new require_error.NotFound());
|
|
104
104
|
afterResponse?.(context, 404);
|
|
105
105
|
return notFound(context);
|
|
106
106
|
}
|
|
@@ -111,10 +111,10 @@ function createFetchHandler(app) {
|
|
|
111
111
|
const hasWS = !!app["~hasWS"];
|
|
112
112
|
const hasDynamicWS = hasWS && !!app["~hasDynamicWS"];
|
|
113
113
|
const strictPath = !!app["~config"]?.strictPath;
|
|
114
|
-
const pathStart = app["~config"]?.handler?.standardHostname === false ? 7 : 11;
|
|
115
114
|
const hook = require_utils.flattenChain(app["~hookChain"]);
|
|
116
115
|
const hasError = !!hook?.error;
|
|
117
116
|
const abortSignal = app["~config"]?.abortSignal !== false;
|
|
117
|
+
const watchPath = !require_universal_is_production.isProduction();
|
|
118
118
|
/**
|
|
119
119
|
* Arm `context['~sig']` unless this request is provably the untouched
|
|
120
120
|
* `Request` the Bun adapter received, in which case materializing
|
|
@@ -130,31 +130,38 @@ function createFetchHandler(app) {
|
|
|
130
130
|
return (context["~sig"] = request.signal).aborted;
|
|
131
131
|
};
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* never reaches it.
|
|
133
|
+
* Peek after each callback. The actual await branch arms deferred requests;
|
|
134
|
+
* immediate callbacks must not materialize a signal just for this check.
|
|
136
135
|
*/
|
|
137
|
-
const armedAbort = (
|
|
136
|
+
const armedAbort = (context) => abortSignal && context["~sig"]?.aborted === true;
|
|
138
137
|
const baseMapResponse = (app["~config"]?.adapter ?? require_adapter_constants.defaultAdapter).response.map;
|
|
138
|
+
function finalMap(response, set, request, sign) {
|
|
139
|
+
if (!sign) return baseMapResponse(response, set, request, true);
|
|
140
|
+
let pending;
|
|
141
|
+
try {
|
|
142
|
+
pending = sign(set);
|
|
143
|
+
} catch {}
|
|
144
|
+
return pending ? pending.then(() => baseMapResponse(response, set, request, true), () => baseMapResponse(response, set, request, true)) : baseMapResponse(response, set, request, true);
|
|
145
|
+
}
|
|
139
146
|
const mapResponseHooks = hook?.mapResponse;
|
|
140
|
-
const mapResponse = mapResponseHooks?.length ? (response, set, context) => {
|
|
147
|
+
const mapResponse = mapResponseHooks?.length ? (response, set, context, sign) => {
|
|
141
148
|
if (!context) return baseMapResponse(response, set, void 0, true);
|
|
142
149
|
context.responseValue = response;
|
|
143
150
|
const request = context.request;
|
|
144
151
|
const run = (i) => {
|
|
145
152
|
for (; i < mapResponseHooks.length; i++) {
|
|
146
153
|
const result = mapResponseHooks[i](context);
|
|
147
|
-
if (result
|
|
148
|
-
if (resolved !== void 0) return
|
|
154
|
+
if (typeof result?.then === "function") return Promise.resolve(result).then((resolved) => {
|
|
155
|
+
if (resolved !== void 0) return finalMap(resolved, set, request, sign);
|
|
149
156
|
return run(i + 1);
|
|
150
157
|
});
|
|
151
|
-
if (result !== void 0) return
|
|
158
|
+
if (result !== void 0) return finalMap(result, set, request, sign);
|
|
152
159
|
}
|
|
153
|
-
return
|
|
160
|
+
return finalMap(response, set, request, sign);
|
|
154
161
|
};
|
|
155
162
|
return run(0);
|
|
156
|
-
} : (response, set, context) =>
|
|
157
|
-
const handleError = require_handler_error.createErrorHandler(hook?.error, mapResponse,
|
|
163
|
+
} : (response, set, context, sign) => finalMap(response, set, context?.request, sign);
|
|
164
|
+
const handleError = require_handler_error.createErrorHandler(hook?.error, mapResponse, app["~config"]?.allowUnsafeValidationDetails);
|
|
158
165
|
const traceHandlers = hook?.trace;
|
|
159
166
|
const hasTrace = !!traceHandlers?.length;
|
|
160
167
|
const traceProvider = hasTrace ? app["~resolvedCapability"]("trace") : void 0;
|
|
@@ -166,11 +173,32 @@ function createFetchHandler(app) {
|
|
|
166
173
|
const afterResponse = (context, status) => {
|
|
167
174
|
if (context._arf) return;
|
|
168
175
|
const queue = context["~afterResponse"];
|
|
169
|
-
if (!afterResponses?.length && !traceAfterResponsePhase && !queue?.length) return;
|
|
176
|
+
if (!afterResponses?.length && !traceAfterResponsePhase && !queue?.length && !context["~dispose"]) return;
|
|
170
177
|
context._arf = true;
|
|
171
178
|
if (status !== void 0) context.set.status = status;
|
|
172
179
|
queueMicrotask(async () => {
|
|
173
180
|
if (afterResponses?.length || queue?.length) require_adapter_utils.materializeSetHeaders(context.set);
|
|
181
|
+
let cache;
|
|
182
|
+
let reports;
|
|
183
|
+
if (traceAfterResponsePhase) {
|
|
184
|
+
cache = context.trace;
|
|
185
|
+
if (!cache && tracerFactories) {
|
|
186
|
+
context.rid ??= require_utils.requestId();
|
|
187
|
+
cache = tracerFactories.map((f) => f(context));
|
|
188
|
+
context.trace = cache;
|
|
189
|
+
}
|
|
190
|
+
if (cache) {
|
|
191
|
+
const total = afterResponses?.length ?? 0;
|
|
192
|
+
reports = new Array(cache.length);
|
|
193
|
+
for (let i = 0; i < cache.length; i++) reports[i] = cache[i].b(7, total) || cache[i].begin(7, {
|
|
194
|
+
id: context.rid ?? "",
|
|
195
|
+
event: "afterResponse",
|
|
196
|
+
name: "afterResponse",
|
|
197
|
+
begin: performance.now(),
|
|
198
|
+
total
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
174
202
|
if (afterResponses) for (let i = 0; i < afterResponses.length; i++) try {
|
|
175
203
|
await afterResponses[i](context);
|
|
176
204
|
} catch (e) {
|
|
@@ -185,39 +213,19 @@ function createFetchHandler(app) {
|
|
|
185
213
|
console.error(e);
|
|
186
214
|
}
|
|
187
215
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (!cache && tracerFactories) {
|
|
191
|
-
context.rid ??= require_utils.requestId();
|
|
192
|
-
cache = tracerFactories.map((f) => f(context));
|
|
193
|
-
context.trace = cache;
|
|
194
|
-
}
|
|
195
|
-
if (cache) for (let i = 0; i < cache.length; i++) {
|
|
196
|
-
const fast = cache[i].b(7, afterResponses?.length ?? 0);
|
|
197
|
-
if (fast) {
|
|
198
|
-
cache[i].r(fast);
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
cache[i].begin(7, {
|
|
202
|
-
id: context.rid ?? "",
|
|
203
|
-
event: "afterResponse",
|
|
204
|
-
name: "afterResponse",
|
|
205
|
-
begin: performance.now(),
|
|
206
|
-
total: afterResponses?.length ?? 0
|
|
207
|
-
}).resolve();
|
|
208
|
-
}
|
|
209
|
-
}
|
|
216
|
+
await require_handler_utils.drainDisposables(context);
|
|
217
|
+
if (reports) for (let i = 0; i < reports.length; i++) cache[i].r(reports[i]);
|
|
210
218
|
});
|
|
211
219
|
};
|
|
212
|
-
|
|
220
|
+
const fail = (context, error, sign) => finalizeError(context, handleError, afterResponse, error, sign);
|
|
221
|
+
app["~finalizeError"] = fail;
|
|
213
222
|
if (traceRequestPhase) {
|
|
214
223
|
const onRequests = hook?.request ?? [];
|
|
215
|
-
const asyncIndexes = onRequests.length ? require_handler_utils.getAsyncIndexes(onRequests) : void 0;
|
|
216
224
|
return async (request, server) => {
|
|
217
225
|
const context = new Context(request);
|
|
218
226
|
require_adapter_utils.materializeSetHeaders(context.set);
|
|
219
227
|
if (armEager(request, context)) return require_handler_utils.emptyResponse.clone();
|
|
220
|
-
extractPath(request.url, context
|
|
228
|
+
const path = extractPath(request.url, context);
|
|
221
229
|
context.server = server ?? null;
|
|
222
230
|
context.rid = require_utils.requestId();
|
|
223
231
|
const traceLength = tracerFactories.length;
|
|
@@ -235,15 +243,20 @@ function createFetchHandler(app) {
|
|
|
235
243
|
try {
|
|
236
244
|
const endReports = new Array(traceLength);
|
|
237
245
|
for (let i = 0; i < onRequests.length; i++) {
|
|
238
|
-
for (let j = 0; j < traceLength; j++) endReports[j] = requestReports[j].
|
|
246
|
+
for (let j = 0; j < traceLength; j++) endReports[j] = requestReports[j].shift?.()?.({
|
|
239
247
|
id: context.rid,
|
|
240
248
|
event: "request",
|
|
241
249
|
name: onRequests[i].name || "anonymous",
|
|
242
250
|
begin: performance.now()
|
|
243
251
|
});
|
|
244
|
-
|
|
252
|
+
let result = onRequests[i](context);
|
|
253
|
+
if (typeof result?.then === "function") {
|
|
254
|
+
if (abortSignal) context["~sig"] ??= request.signal;
|
|
255
|
+
result = await result;
|
|
256
|
+
}
|
|
257
|
+
if (watchPath && context.path !== path) warnPathMutation(app);
|
|
245
258
|
for (let i = 0; i < traceLength; i++) endReports[i]?.();
|
|
246
|
-
if (armedAbort(
|
|
259
|
+
if (armedAbort(context)) {
|
|
247
260
|
for (let j = 0; j < traceLength; j++) trace[j].r(requestReports[j]);
|
|
248
261
|
return require_handler_utils.emptyResponse.clone();
|
|
249
262
|
}
|
|
@@ -258,24 +271,27 @@ function createFetchHandler(app) {
|
|
|
258
271
|
return await findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS, hasDynamicWS);
|
|
259
272
|
} catch (error) {
|
|
260
273
|
for (let i = 0; i < traceLength; i++) trace[i].r(requestReports[i], error);
|
|
261
|
-
return
|
|
274
|
+
return fail(context, error);
|
|
262
275
|
}
|
|
263
276
|
};
|
|
264
277
|
}
|
|
265
278
|
if (hook?.request) {
|
|
266
279
|
const onRequests = hook.request;
|
|
267
|
-
|
|
268
|
-
if (asyncIndexes) return async (request, server) => {
|
|
280
|
+
if (require_handler_utils.hasAsync(onRequests)) return async (request, server) => {
|
|
269
281
|
const context = new Context(request);
|
|
270
282
|
require_adapter_utils.materializeSetHeaders(context.set);
|
|
271
283
|
if (armEager(request, context)) return require_handler_utils.emptyResponse.clone();
|
|
272
|
-
extractPath(request.url, context
|
|
284
|
+
const path = extractPath(request.url, context);
|
|
273
285
|
context.server = server ?? null;
|
|
274
286
|
try {
|
|
275
287
|
for (let i = 0; i < onRequests.length; i++) {
|
|
276
|
-
let result =
|
|
277
|
-
if (result
|
|
278
|
-
|
|
288
|
+
let result = onRequests[i](context);
|
|
289
|
+
if (typeof result?.then === "function") {
|
|
290
|
+
if (abortSignal) context["~sig"] ??= request.signal;
|
|
291
|
+
result = await result;
|
|
292
|
+
}
|
|
293
|
+
if (watchPath && context.path !== path) warnPathMutation(app);
|
|
294
|
+
if (armedAbort(context)) return require_handler_utils.emptyResponse.clone();
|
|
279
295
|
if (result !== void 0) {
|
|
280
296
|
const response = await mapResponse(result, context.set, context);
|
|
281
297
|
afterResponse?.(context);
|
|
@@ -284,18 +300,19 @@ function createFetchHandler(app) {
|
|
|
284
300
|
}
|
|
285
301
|
return findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS, hasDynamicWS);
|
|
286
302
|
} catch (error) {
|
|
287
|
-
return
|
|
303
|
+
return fail(context, error);
|
|
288
304
|
}
|
|
289
305
|
};
|
|
290
306
|
return (request, server) => {
|
|
291
307
|
const context = new Context(request);
|
|
292
308
|
require_adapter_utils.materializeSetHeaders(context.set);
|
|
293
309
|
if (armEager(request, context)) return require_handler_utils.emptyResponse.clone();
|
|
294
|
-
extractPath(request.url, context
|
|
310
|
+
const path = extractPath(request.url, context);
|
|
295
311
|
context.server = server ?? null;
|
|
296
312
|
try {
|
|
297
313
|
for (let i = 0; i < onRequests.length; i++) {
|
|
298
314
|
const result = onRequests[i](context);
|
|
315
|
+
if (watchPath && context.path !== path) warnPathMutation(app);
|
|
299
316
|
if (abortSignal && context["~sig"]?.aborted) return require_handler_utils.emptyResponse.clone();
|
|
300
317
|
if (result !== void 0) {
|
|
301
318
|
const response = mapResponse(result, context.set, context);
|
|
@@ -309,57 +326,19 @@ function createFetchHandler(app) {
|
|
|
309
326
|
}
|
|
310
327
|
return findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS, hasDynamicWS);
|
|
311
328
|
} catch (error) {
|
|
312
|
-
return
|
|
329
|
+
return fail(context, error);
|
|
313
330
|
}
|
|
314
331
|
};
|
|
315
332
|
}
|
|
316
333
|
return (request, server) => {
|
|
317
334
|
const context = new Context(request);
|
|
318
|
-
|
|
335
|
+
extractPath(request.url, context);
|
|
319
336
|
context.server = server ?? null;
|
|
320
|
-
const method = request.method;
|
|
321
|
-
if (hasWS && method === "GET") {
|
|
322
|
-
const handler = map["WS"]?.[path];
|
|
323
|
-
const found = handler === void 0 && hasDynamicWS ? router?.find("WS", path) : void 0;
|
|
324
|
-
if (handler !== void 0 || found) {
|
|
325
|
-
const upgrade = request.headers.get("upgrade");
|
|
326
|
-
if (upgrade && upgrade.toLowerCase() === "websocket") try {
|
|
327
|
-
if (handler) {
|
|
328
|
-
const r = handler(context);
|
|
329
|
-
return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
|
|
330
|
-
}
|
|
331
|
-
context.params = path.indexOf("%") === -1 ? found.params : decodeParams(found.params);
|
|
332
|
-
const r = found.store(context);
|
|
333
|
-
return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
|
|
334
|
-
} catch (error) {
|
|
335
|
-
return finalizeError(context, handleError, afterResponse, error);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
337
|
try {
|
|
340
|
-
|
|
341
|
-
let handler = methodMap?.[path];
|
|
342
|
-
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
343
|
-
if (!strictPath && path.length > 1 && path.charCodeAt(path.length - 1) === 47) {
|
|
344
|
-
const loose = path.slice(0, -1);
|
|
345
|
-
handler = methodMap?.[loose];
|
|
346
|
-
if (!handler) {
|
|
347
|
-
const anyMap = map["*"];
|
|
348
|
-
handler = anyMap?.[path] ?? anyMap?.[loose];
|
|
349
|
-
}
|
|
350
|
-
} else handler = map["*"]?.[path];
|
|
351
|
-
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
352
|
-
const result = router?.find(method, path) ?? router?.find("*", path);
|
|
353
|
-
if (result) {
|
|
354
|
-
context.params = path.indexOf("%") === -1 ? result.params : decodeParams(result.params);
|
|
355
|
-
return dispatchResult(result.store(context), context, handleError, afterResponse);
|
|
356
|
-
}
|
|
338
|
+
return findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS, hasDynamicWS);
|
|
357
339
|
} catch (error) {
|
|
358
|
-
return
|
|
340
|
+
return fail(context, error);
|
|
359
341
|
}
|
|
360
|
-
if (hasError) return finalizeError(context, handleError, afterResponse, notFoundBody);
|
|
361
|
-
afterResponse?.(context, 404);
|
|
362
|
-
return notFound(context);
|
|
363
342
|
};
|
|
364
343
|
}
|
|
365
344
|
function applyHoc(app, fetch) {
|