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/adapter/utils.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { hasHeaderShorthand
|
|
1
|
+
import { hasHeaderShorthand } from "../universal/constants.mjs";
|
|
2
2
|
import { StatusMap } from "../constants.mjs";
|
|
3
|
-
import { isByteStream, isNotEmpty, nullObject } from "../utils.mjs";
|
|
3
|
+
import { isByteStream, isNotEmpty, nullObject, sseData } from "../utils.mjs";
|
|
4
4
|
import { skipClone } from "./skip-clone.mjs";
|
|
5
5
|
import { serializeCookie } from "../cookie/serialize.mjs";
|
|
6
6
|
import { isBorrowedResponse } from "./response-ownership.mjs";
|
|
@@ -13,25 +13,19 @@ function materializeSetHeaders(set) {
|
|
|
13
13
|
if (headers["\0"] !== headers) return headers;
|
|
14
14
|
return set.headers = Object.assign(nullObject(), headers);
|
|
15
15
|
}
|
|
16
|
-
const sseFormat = (data) =>
|
|
16
|
+
const sseFormat = (data) => sseData(data) + "\n";
|
|
17
17
|
const identityFormat = (data) => data;
|
|
18
18
|
const textEncoder = new TextEncoder();
|
|
19
|
-
const encodeChunk = (s) => textEncoder.encode(s);
|
|
20
19
|
function normalizeContentType(contentType) {
|
|
21
20
|
if (contentType === "application/json") return contentType;
|
|
22
21
|
const end = contentType.indexOf(";");
|
|
23
22
|
return (end === -1 ? contentType : contentType.slice(0, end)).trim().toLowerCase();
|
|
24
23
|
}
|
|
25
24
|
function handleFile(response, set, request, size = response.size) {
|
|
26
|
-
if (!isBun && response instanceof Promise) return response.then((res) => handleFile(res, set, request, size));
|
|
27
25
|
const rangeHeader = request?.headers.get("range");
|
|
28
26
|
if (rangeHeader) {
|
|
29
27
|
const match = /bytes=(\d*)-(\d*)/.exec(rangeHeader);
|
|
30
28
|
if (match) {
|
|
31
|
-
if (!match[1] && !match[2]) return new Response(null, {
|
|
32
|
-
status: 416,
|
|
33
|
-
headers: mergeHeaders(new Headers({ "content-range": `bytes */${size}` }), set?.headers ?? nullObject())
|
|
34
|
-
});
|
|
35
29
|
let start;
|
|
36
30
|
let end;
|
|
37
31
|
if (!match[1] && match[2]) {
|
|
@@ -42,7 +36,7 @@ function handleFile(response, set, request, size = response.size) {
|
|
|
42
36
|
start = match[1] ? parseInt(match[1]) : 0;
|
|
43
37
|
end = match[2] ? Math.min(parseInt(match[2]), size - 1) : size - 1;
|
|
44
38
|
}
|
|
45
|
-
if (start >= size || start > end) return new Response(null, {
|
|
39
|
+
if (!match[1] && !match[2] || start >= size || start > end) return new Response(null, {
|
|
46
40
|
status: 416,
|
|
47
41
|
headers: mergeHeaders(new Headers({ "content-range": `bytes */${size}` }), set?.headers ?? nullObject())
|
|
48
42
|
});
|
|
@@ -74,13 +68,9 @@ function handleFile(response, set, request, size = response.size) {
|
|
|
74
68
|
}
|
|
75
69
|
return new Response(body, set);
|
|
76
70
|
}
|
|
77
|
-
if (isNotEmpty(set.headers)) return new Response(body, {
|
|
78
|
-
status: set.status,
|
|
79
|
-
headers: Object.assign(defaultHeader, set.headers)
|
|
80
|
-
});
|
|
81
71
|
return new Response(body, {
|
|
82
72
|
status: set.status,
|
|
83
|
-
headers: defaultHeader
|
|
73
|
+
headers: Object.assign(defaultHeader, set.headers)
|
|
84
74
|
});
|
|
85
75
|
}
|
|
86
76
|
function normalizeHeaders(set) {
|
|
@@ -123,27 +113,9 @@ function responseToSetHeaders(response, set) {
|
|
|
123
113
|
if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
124
114
|
return set;
|
|
125
115
|
}
|
|
126
|
-
function enqueueBinaryChunk(controller, chunk) {
|
|
127
|
-
if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
|
|
128
|
-
controller.enqueue(new Uint8Array(buffer));
|
|
129
|
-
return true;
|
|
130
|
-
});
|
|
131
|
-
if (chunk instanceof Uint8Array) {
|
|
132
|
-
controller.enqueue(chunk);
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
if (chunk instanceof ArrayBuffer) {
|
|
136
|
-
controller.enqueue(new Uint8Array(chunk));
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
if (ArrayBuffer.isView(chunk)) {
|
|
140
|
-
controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
116
|
function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
146
117
|
return async (generator, set, request, skipFormat, owned = false) => {
|
|
118
|
+
if (request === null) return void 0;
|
|
147
119
|
if (isByteStream(generator)) {
|
|
148
120
|
if (generator.locked) throw new TypeError("Cannot transfer a locked or consumed byte stream");
|
|
149
121
|
if (set) {
|
|
@@ -157,10 +129,12 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
157
129
|
return new Response(generator, { headers: { "content-type": "application/octet-stream" } });
|
|
158
130
|
}
|
|
159
131
|
const typedSSE = !skipFormat && "sse" in generator && generator.sse === true;
|
|
132
|
+
const sourceIterator = typeof generator.next === "function" ? generator : void 0;
|
|
160
133
|
let init = typedSSE ? void 0 : generator.next?.();
|
|
161
134
|
if (set) handleSet(set);
|
|
162
135
|
if (init instanceof Promise) init = await init;
|
|
163
|
-
|
|
136
|
+
const yieldedStream = init?.value instanceof ReadableStream;
|
|
137
|
+
if (yieldedStream) generator = init.value;
|
|
164
138
|
else if (init && (typeof init?.done === "undefined" || init?.done)) {
|
|
165
139
|
if (set) return mapResponse(init.value, set, request, owned);
|
|
166
140
|
return mapCompactResponse(init.value, request, owned);
|
|
@@ -194,8 +168,32 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
194
168
|
connection: "keep-alive"
|
|
195
169
|
}
|
|
196
170
|
};
|
|
197
|
-
const
|
|
171
|
+
const sourceStream = generator instanceof ReadableStream ? generator : void 0;
|
|
172
|
+
let streamReader;
|
|
173
|
+
const iterator = sourceStream ? {
|
|
174
|
+
next: () => (streamReader ??= sourceStream.getReader()).read(),
|
|
175
|
+
async return() {
|
|
176
|
+
if (!streamReader) {
|
|
177
|
+
await sourceStream.cancel();
|
|
178
|
+
return {
|
|
179
|
+
done: true,
|
|
180
|
+
value: void 0
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
await streamReader.cancel();
|
|
185
|
+
} finally {
|
|
186
|
+
streamReader.releaseLock();
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
done: true,
|
|
190
|
+
value: void 0
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
} : sourceIterator ?? generator[Symbol.asyncIterator]();
|
|
194
|
+
const outerIterator = yieldedStream && !init.done ? sourceIterator : void 0;
|
|
198
195
|
let end = false;
|
|
196
|
+
let finalizing;
|
|
199
197
|
const signal = request?.signal;
|
|
200
198
|
let onAbort;
|
|
201
199
|
const cleanupAbort = () => {
|
|
@@ -204,71 +202,93 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
204
202
|
onAbort = void 0;
|
|
205
203
|
}
|
|
206
204
|
};
|
|
207
|
-
const safeReturn = () => {
|
|
205
|
+
const safeReturn = async (target) => {
|
|
208
206
|
try {
|
|
209
|
-
|
|
210
|
-
if (r && typeof r.then === "function") r.catch(() => {});
|
|
207
|
+
await target?.return?.();
|
|
211
208
|
} catch {}
|
|
212
209
|
};
|
|
213
|
-
const
|
|
210
|
+
const finalize = (mode, controller, error) => {
|
|
211
|
+
if (end) return finalizing;
|
|
212
|
+
end = true;
|
|
213
|
+
cleanupAbort();
|
|
214
|
+
finalizing = safeReturn(iterator).then(() => safeReturn(outerIterator));
|
|
215
|
+
if (!controller) return finalizing;
|
|
214
216
|
try {
|
|
215
|
-
controller.
|
|
217
|
+
if (mode === "error") controller.error(error);
|
|
218
|
+
else controller.close();
|
|
216
219
|
} catch {}
|
|
217
|
-
cleanupAbort();
|
|
218
220
|
};
|
|
219
|
-
const enqueueValue =
|
|
221
|
+
const enqueueValue = (controller, value) => {
|
|
220
222
|
if (value.toSSE) {
|
|
221
|
-
controller.enqueue(
|
|
223
|
+
controller.enqueue(textEncoder.encode(value.toSSE()));
|
|
222
224
|
return;
|
|
223
225
|
}
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
+
let p;
|
|
227
|
+
if (value instanceof Blob) p = value.arrayBuffer().then((buffer) => {
|
|
228
|
+
controller.enqueue(new Uint8Array(buffer));
|
|
229
|
+
});
|
|
230
|
+
else if (value instanceof Uint8Array) {
|
|
231
|
+
controller.enqueue(value);
|
|
232
|
+
p = true;
|
|
233
|
+
} else if (value instanceof ArrayBuffer) {
|
|
234
|
+
controller.enqueue(new Uint8Array(value));
|
|
235
|
+
p = true;
|
|
236
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
237
|
+
controller.enqueue(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
238
|
+
p = true;
|
|
239
|
+
} else p = false;
|
|
240
|
+
if (p !== false) return p === true ? void 0 : p;
|
|
226
241
|
if (typeof value === "object") try {
|
|
227
|
-
controller.enqueue(
|
|
242
|
+
controller.enqueue(textEncoder.encode(format(JSON.stringify(value))));
|
|
228
243
|
} catch {
|
|
229
|
-
controller.enqueue(
|
|
244
|
+
controller.enqueue(textEncoder.encode(format(value.toString())));
|
|
230
245
|
}
|
|
231
|
-
else controller.enqueue(
|
|
246
|
+
else controller.enqueue(textEncoder.encode(format(value.toString())));
|
|
232
247
|
};
|
|
233
248
|
return new Response(new ReadableStream({
|
|
234
|
-
|
|
249
|
+
start(controller) {
|
|
235
250
|
if (signal) {
|
|
236
|
-
onAbort = () =>
|
|
237
|
-
cleanupAbort();
|
|
238
|
-
end = true;
|
|
239
|
-
safeReturn();
|
|
240
|
-
try {
|
|
241
|
-
controller.close();
|
|
242
|
-
} catch {}
|
|
243
|
-
};
|
|
251
|
+
onAbort = () => finalize("close", controller);
|
|
244
252
|
if (signal.aborted) onAbort();
|
|
245
253
|
else signal.addEventListener("abort", onAbort, { once: true });
|
|
246
254
|
}
|
|
247
255
|
if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (end) {
|
|
252
|
-
closeSafely(controller);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
256
|
+
const fail = (error) => {
|
|
257
|
+
finalize("error", controller, error);
|
|
258
|
+
};
|
|
255
259
|
try {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
+
return enqueueValue(controller, init.value)?.catch(fail);
|
|
261
|
+
} catch (error) {
|
|
262
|
+
fail(error);
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
pull(controller) {
|
|
266
|
+
if (end) return;
|
|
267
|
+
const fail = (error) => {
|
|
268
|
+
finalize("error", controller, error);
|
|
269
|
+
};
|
|
270
|
+
const step = (result) => {
|
|
271
|
+
while (true) {
|
|
272
|
+
if (result.done || end) {
|
|
273
|
+
finalize("close", controller);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const chunk = result.value;
|
|
277
|
+
if (chunk !== void 0 && chunk !== null) return enqueueValue(controller, chunk);
|
|
278
|
+
const next = iterator.next();
|
|
279
|
+
if (typeof next.then === "function") return Promise.resolve(next).then(step);
|
|
280
|
+
result = next;
|
|
260
281
|
}
|
|
261
|
-
|
|
262
|
-
|
|
282
|
+
};
|
|
283
|
+
try {
|
|
284
|
+
const next = iterator.next();
|
|
285
|
+
return (typeof next.then === "function" ? Promise.resolve(next).then(step) : step(next))?.catch(fail);
|
|
263
286
|
} catch (error) {
|
|
264
|
-
|
|
265
|
-
controller.error(error);
|
|
287
|
+
fail(error);
|
|
266
288
|
}
|
|
267
289
|
},
|
|
268
290
|
cancel() {
|
|
269
|
-
|
|
270
|
-
cleanupAbort();
|
|
271
|
-
safeReturn();
|
|
291
|
+
finalize("close");
|
|
272
292
|
}
|
|
273
293
|
}, typedSSE ? { highWaterMark: 0 } : void 0), set);
|
|
274
294
|
};
|
|
@@ -283,7 +303,7 @@ function handleSet(set) {
|
|
|
283
303
|
const proto = Object.getPrototypeOf(set.headers);
|
|
284
304
|
if (proto !== null && proto !== Object.prototype) {
|
|
285
305
|
const flat = Object.create(null);
|
|
286
|
-
for (const key
|
|
306
|
+
for (const key of Object.keys(set.headers)) flat[key] = set.headers[key];
|
|
287
307
|
set.headers = flat;
|
|
288
308
|
}
|
|
289
309
|
if (set.cookie && isNotEmpty(set.cookie)) {
|
|
@@ -291,8 +311,11 @@ function handleSet(set) {
|
|
|
291
311
|
const cookie = serializeCookie(set.cookie);
|
|
292
312
|
if (cookie) {
|
|
293
313
|
const existing = set.headers[setCookie];
|
|
294
|
-
if (
|
|
295
|
-
|
|
314
|
+
if (existing) {
|
|
315
|
+
const kept = typeof existing === "string" ? [existing] : existing;
|
|
316
|
+
const added = (typeof cookie === "string" ? [cookie] : cookie).filter((value) => !kept.includes(value));
|
|
317
|
+
set.headers[setCookie] = added.length ? kept.concat(added) : existing;
|
|
318
|
+
} else set.headers[setCookie] = cookie;
|
|
296
319
|
}
|
|
297
320
|
}
|
|
298
321
|
if (set.headers[setCookie] && Array.isArray(set.headers[setCookie])) set.headers = parseSetCookies(new Headers(set.headers), set.headers[setCookie]);
|
|
@@ -310,7 +333,7 @@ function applySetHeaders(target, setHeaders, present) {
|
|
|
310
333
|
for (const key of setHeaders.keys()) if (key !== setCookie && !present.has(key)) target.set(key, setHeaders.get(key) ?? "");
|
|
311
334
|
} else {
|
|
312
335
|
let cookies;
|
|
313
|
-
for (const key
|
|
336
|
+
for (const key of Object.keys(setHeaders)) if (key === setCookie) {
|
|
314
337
|
const cookie = setHeaders[key];
|
|
315
338
|
cookies ??= target.getSetCookie();
|
|
316
339
|
if (!cookies.includes(cookie)) {
|
|
@@ -348,7 +371,6 @@ function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = fals
|
|
|
348
371
|
}
|
|
349
372
|
});
|
|
350
373
|
}
|
|
351
|
-
const warnedStreamBorrows = /* @__PURE__ */ new WeakSet();
|
|
352
374
|
function createResponseHandler(handler) {
|
|
353
375
|
const handleStream = createStreamHandler(handler);
|
|
354
376
|
return (response, set, request, owned = false) => {
|
|
@@ -360,25 +382,21 @@ function createResponseHandler(handler) {
|
|
|
360
382
|
const borrowed = !owned || explicitlyBorrowed;
|
|
361
383
|
const mustClone = owned && explicitlyBorrowed;
|
|
362
384
|
if (!borrowed && response.bodyUsed) throw new TypeError("Cannot reuse a consumed Response across requests");
|
|
385
|
+
let status;
|
|
363
386
|
if (set) {
|
|
364
|
-
|
|
387
|
+
status = mergeStatus(response.status, set.status);
|
|
365
388
|
const statusUnchanged = status === void 0 || status === response.status;
|
|
366
389
|
if (!mustClone && statusUnchanged && !set.cookie && !isNotEmpty(set.headers)) return response;
|
|
367
390
|
} else if (!mustClone) return response;
|
|
368
391
|
if (!borrowed && response.body?.locked) throw new TypeError("Cannot patch a Response whose body is locked");
|
|
369
392
|
let body = response.body;
|
|
370
393
|
if (borrowed) {
|
|
371
|
-
const bodyBefore = body;
|
|
372
394
|
const cloned = response.clone();
|
|
373
|
-
if (explicitlyBorrowed && bodyBefore && response.body !== bodyBefore && !warnedStreamBorrows.has(response)) {
|
|
374
|
-
warnedStreamBorrows.add(response);
|
|
375
|
-
console.warn("[elysia] borrow() was called on a stream-backed Response");
|
|
376
|
-
}
|
|
377
395
|
body = cloned.body && response.body ? cancelPropagatingBody(cloned.body, response.body, explicitlyBorrowed) : cloned.body;
|
|
378
396
|
}
|
|
379
397
|
const newResponse = new Response(body, set ? {
|
|
380
398
|
headers: mergeHeaders(response.headers, set.headers),
|
|
381
|
-
status
|
|
399
|
+
status,
|
|
382
400
|
statusText: response.statusText
|
|
383
401
|
} : {
|
|
384
402
|
headers: response.headers,
|
|
@@ -403,6 +421,46 @@ const doneResult = {
|
|
|
403
421
|
value: void 0
|
|
404
422
|
};
|
|
405
423
|
/**
|
|
424
|
+
* A returned `ReadableStream` is consumed after the handler returns, so
|
|
425
|
+
* afterResponse, `defer()` and derive dispose must wait for it the way a tee'd
|
|
426
|
+
* generator is waited on
|
|
427
|
+
*
|
|
428
|
+
* A returned `Response` is not observed, reading `.body` would move
|
|
429
|
+
* every Response on these routes off Bun's native send path; a `bytes()`
|
|
430
|
+
* stream keeps its exact-stream contract and releases early as before
|
|
431
|
+
*/
|
|
432
|
+
function observeStream(source) {
|
|
433
|
+
if (source.locked || isByteStream(source)) return;
|
|
434
|
+
const reader = source.getReader();
|
|
435
|
+
const [value, observer] = tee({ [Symbol.asyncIterator]: () => ({
|
|
436
|
+
next: () => reader.read(),
|
|
437
|
+
return: (reason) => reader.cancel(reason).then(() => ({
|
|
438
|
+
done: true,
|
|
439
|
+
value: void 0
|
|
440
|
+
}))
|
|
441
|
+
}) });
|
|
442
|
+
const body = new ReadableStream({
|
|
443
|
+
async pull(controller) {
|
|
444
|
+
try {
|
|
445
|
+
const result = await value.next();
|
|
446
|
+
if (result.done) controller.close();
|
|
447
|
+
else controller.enqueue(result.value);
|
|
448
|
+
} catch (error) {
|
|
449
|
+
controller.error(error);
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
cancel(reason) {
|
|
453
|
+
return value.return?.(reason);
|
|
454
|
+
}
|
|
455
|
+
}, { highWaterMark: 0 });
|
|
456
|
+
if (source.sse === true) body.sse = true;
|
|
457
|
+
return [
|
|
458
|
+
body,
|
|
459
|
+
observer,
|
|
460
|
+
value
|
|
461
|
+
];
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
406
464
|
* Split async source into `branches` independent iterators
|
|
407
465
|
*
|
|
408
466
|
* A producer drains the source ahead of consumers
|
|
@@ -523,7 +581,7 @@ function tee(source, branches = 2, cap = 64, capBytes = 1 << 22) {
|
|
|
523
581
|
wakeAll();
|
|
524
582
|
}
|
|
525
583
|
})();
|
|
526
|
-
const makeBranch = (me) => ({
|
|
584
|
+
const makeBranch = (me) => Object.assign(Object.create(null), {
|
|
527
585
|
[Symbol.asyncIterator]() {
|
|
528
586
|
return this;
|
|
529
587
|
},
|
|
@@ -557,4 +615,4 @@ function tee(source, branches = 2, cap = 64, capBytes = 1 << 22) {
|
|
|
557
615
|
}
|
|
558
616
|
|
|
559
617
|
//#endregion
|
|
560
|
-
export { createResponseHandler, createStreamHandler, handleFile, handleSet, materializeSetHeaders, normalizeContentType, parseSetCookies, responseToSetHeaders, streamResponse, tee };
|
|
618
|
+
export { createResponseHandler, createStreamHandler, handleFile, handleSet, materializeSetHeaders, normalizeContentType, observeStream, parseSetCookies, responseToSetHeaders, streamResponse, tee };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MaybePromise } from "../../types.js";
|
|
2
1
|
import { Context } from "../../context.js";
|
|
2
|
+
import { MaybePromise } from "../../types.js";
|
|
3
3
|
|
|
4
4
|
//#region src/adapter/web-standard/handler.d.ts
|
|
5
5
|
declare function mapResponse(response: unknown, set: Context['set'], request?: Request, owned?: boolean): Response;
|
|
@@ -2,17 +2,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_universal_constants = require('../../universal/constants.js');
|
|
3
3
|
const require_universal_file = require('../../universal/file.js');
|
|
4
4
|
const require_utils = require('../../utils.js');
|
|
5
|
+
const require_universal_is_production = require('../../universal/is-production.js');
|
|
5
6
|
const require_error = require('../../error.js');
|
|
6
7
|
const require_adapter_default_headers = require('../default-headers.js');
|
|
7
8
|
const require_adapter_utils = require('../utils.js');
|
|
9
|
+
const require_cookie_cookie = require('../../cookie/cookie.js');
|
|
8
10
|
|
|
9
11
|
//#region src/adapter/web-standard/handler.ts
|
|
10
12
|
const textPlainInit = { headers: { "content-type": "text/plain" } };
|
|
11
13
|
function handleElysiaFile(file, set = { headers: require_utils.nullObject() }, request) {
|
|
12
|
-
const
|
|
13
|
-
const contentType = require_universal_file.mime[path.slice(path.lastIndexOf(".") + 1).toLowerCase()];
|
|
14
|
+
const contentType = file.type;
|
|
14
15
|
const headers = require_adapter_utils.materializeSetHeaders(set);
|
|
15
|
-
if (contentType) headers["content-type"] = contentType;
|
|
16
|
+
if (contentType !== "application/octet-stream") headers["content-type"] = contentType;
|
|
16
17
|
const stats = file.stats;
|
|
17
18
|
if (stats) return stats.then((stat) => {
|
|
18
19
|
const size = stat.size;
|
|
@@ -22,12 +23,16 @@ function handleElysiaFile(file, set = { headers: require_utils.nullObject() }, r
|
|
|
22
23
|
return require_adapter_utils.handleFile(file.value, set, request);
|
|
23
24
|
}
|
|
24
25
|
function responseTag(response) {
|
|
26
|
+
if (typeof response === "string") return "String";
|
|
25
27
|
if (response == null) return;
|
|
26
|
-
|
|
28
|
+
const constructor = Object.getPrototypeOf(response)?.constructor;
|
|
29
|
+
if (typeof constructor !== "function") return typeof response.next === "function" ? "" : void 0;
|
|
30
|
+
return constructor.name;
|
|
27
31
|
}
|
|
28
32
|
function mapResponseWithSet(response, set, request, owned) {
|
|
29
33
|
require_adapter_utils.handleSet(set);
|
|
30
34
|
const headers = set.headers;
|
|
35
|
+
if (!require_universal_constants.isBun && (set.status === 204 || set.status === 304 || set.status === 205) && !(response instanceof Response) && !(response instanceof require_error.ElysiaStatus)) return new Response(null, set);
|
|
31
36
|
switch (responseTag(response)) {
|
|
32
37
|
case "String":
|
|
33
38
|
if (!require_universal_constants.isBun && !headers["content-type"]) require_adapter_utils.materializeSetHeaders(set)["content-type"] = "text/plain";
|
|
@@ -38,14 +43,11 @@ function mapResponseWithSet(response, set, request, owned) {
|
|
|
38
43
|
if (typeof response?.next === "function") return handleStream(response, set, request, void 0, owned);
|
|
39
44
|
return Response.json(response, set);
|
|
40
45
|
case "Number":
|
|
41
|
-
case "Boolean": return new Response(
|
|
46
|
+
case "Boolean": return new Response(String(response), set);
|
|
42
47
|
case "ElysiaFile": return handleElysiaFile(response, set, request);
|
|
43
48
|
case "File":
|
|
44
49
|
case "Blob": return require_adapter_utils.handleFile(response, set, request);
|
|
45
|
-
case "ElysiaStatus":
|
|
46
|
-
set.status = response.code;
|
|
47
|
-
if (response.headers) Object.assign(require_adapter_utils.materializeSetHeaders(set), response.headers);
|
|
48
|
-
return mapResponseWithSet(response.response, set, request, owned);
|
|
50
|
+
case "ElysiaStatus": return withStatus(response, set, request, owned);
|
|
49
51
|
case void 0: return response ? Response.json(response, set) : new Response(null, set);
|
|
50
52
|
case "Response": return handleResponse(response, set, request, owned);
|
|
51
53
|
case "Error": return errorToResponse(response, set, request, owned);
|
|
@@ -55,14 +57,24 @@ function mapResponseWithSet(response, set, request, owned) {
|
|
|
55
57
|
default: return mapFallback(response, set, request, owned);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
60
|
+
function withStatus(response, set, request, owned) {
|
|
61
|
+
if (set) set.status = response.status;
|
|
62
|
+
else set = {
|
|
63
|
+
status: response.status,
|
|
64
|
+
headers: require_utils.nullObject()
|
|
65
|
+
};
|
|
66
|
+
if (response.headers) Object.assign(require_adapter_utils.materializeSetHeaders(set), response.headers);
|
|
67
|
+
return mapResponseWithSet(response.response, set, request, owned);
|
|
68
|
+
}
|
|
69
|
+
const checkRemovedSetRedirect = !require_universal_is_production.isProduction();
|
|
58
70
|
function mapResponse(response, set, request, owned) {
|
|
71
|
+
if (checkRemovedSetRedirect && Object.hasOwn(set, "redirect") && !require_universal_is_production.isProduction()) {
|
|
72
|
+
delete set.redirect;
|
|
73
|
+
throw new Error("[Elysia] set.redirect was removed in 2.0 — return redirect(url) instead");
|
|
74
|
+
}
|
|
59
75
|
const headers = set.headers;
|
|
60
76
|
if (set.status !== void 0 || set.cookie || headers["\0"] === headers || require_utils.isNotEmpty(headers)) return mapResponseWithSet(response, set, request, owned);
|
|
61
|
-
if (response instanceof require_error.ElysiaStatus)
|
|
62
|
-
set.status = response.code;
|
|
63
|
-
if (response.headers) Object.assign(set.headers, response.headers);
|
|
64
|
-
return mapResponse(response.response, set, request, owned);
|
|
65
|
-
}
|
|
77
|
+
if (response instanceof require_error.ElysiaStatus) return withStatus(response, set, request, owned);
|
|
66
78
|
if (response instanceof Response) return owned ? handleResponse(response, void 0, request, true) : response;
|
|
67
79
|
if (response instanceof Promise) return response.then((x) => mapResponse(x, set, request, owned));
|
|
68
80
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
|
@@ -76,14 +88,11 @@ function mapCompactResponse(response, request, owned) {
|
|
|
76
88
|
case "ElysiaForm": return new Response(require_utils.formToFormData(response));
|
|
77
89
|
case "Object": return Response.json(response);
|
|
78
90
|
case "Number":
|
|
79
|
-
case "Boolean": return new Response(
|
|
91
|
+
case "Boolean": return new Response(String(response));
|
|
80
92
|
case "ElysiaFile": return handleElysiaFile(response, void 0, request);
|
|
81
93
|
case "File":
|
|
82
94
|
case "Blob": return require_adapter_utils.handleFile(response, void 0, request);
|
|
83
|
-
case "ElysiaStatus": return
|
|
84
|
-
status: response.code,
|
|
85
|
-
headers: response.headers ? Object.assign(require_utils.nullObject(), response.headers) : require_utils.nullObject()
|
|
86
|
-
}, request, owned);
|
|
95
|
+
case "ElysiaStatus": return withStatus(response, void 0, request, owned);
|
|
87
96
|
case void 0: return response ? Response.json(response) : new Response("");
|
|
88
97
|
case "Response": return owned ? handleResponse(response, void 0, request, true) : response;
|
|
89
98
|
case "Error": return errorToResponse(response, void 0, request, owned);
|
|
@@ -115,28 +124,30 @@ function errorToResponse(error, set, request, owned = false) {
|
|
|
115
124
|
}
|
|
116
125
|
function mapFallback(response, set, request, owned = false) {
|
|
117
126
|
if (response instanceof Response) return handleResponse(response, set, request, owned);
|
|
118
|
-
if (response instanceof Promise) return response.then((x) => set ? mapResponse(x, set, request, owned) : mapCompactResponse(x, request, owned));
|
|
119
127
|
if (response instanceof Error) return errorToResponse(response, set, request, owned);
|
|
120
|
-
if (response instanceof require_error.ElysiaStatus)
|
|
121
|
-
set
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
if (response instanceof require_universal_file.ElysiaFile) return handleElysiaFile(response,
|
|
128
|
+
if (response instanceof require_error.ElysiaStatus) {
|
|
129
|
+
if (set && response.headers) {
|
|
130
|
+
set.status = response.status;
|
|
131
|
+
set.headers = {
|
|
132
|
+
...set.headers,
|
|
133
|
+
...response.headers
|
|
134
|
+
};
|
|
135
|
+
return mapResponse(response.response, set, request, owned);
|
|
136
|
+
}
|
|
137
|
+
return withStatus(response, set, request, owned);
|
|
138
|
+
}
|
|
139
|
+
if (response instanceof require_universal_file.ElysiaFile) return handleElysiaFile(response, set, request);
|
|
132
140
|
if (require_utils.isElysiaForm(response)) return new Response(require_utils.formToFormData(response), set);
|
|
133
141
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
|
134
|
-
if (typeof response?.then === "function") return response.then((x) =>
|
|
135
|
-
if (Array.isArray(response)) return Response.json(response);
|
|
136
|
-
if (typeof response?.toResponse === "function") return
|
|
137
|
-
if (responseTag(response) === "Cookie") return
|
|
142
|
+
if (typeof response?.then === "function") return response.then((x) => remap(x, set, request, owned));
|
|
143
|
+
if (Array.isArray(response)) return Response.json(response, set);
|
|
144
|
+
if (typeof response?.toResponse === "function") return remap(response.toResponse(), set, request, owned);
|
|
145
|
+
if (responseTag(response) === "Cookie" && require_cookie_cookie.Cookie.isCookie(response)) return remap(response.value, set, request, owned);
|
|
138
146
|
return new Response(response, set);
|
|
139
147
|
}
|
|
148
|
+
function remap(response, set, request, owned) {
|
|
149
|
+
return set ? mapResponse(response, set, request, owned) : mapCompactResponse(response, request, owned);
|
|
150
|
+
}
|
|
140
151
|
const handleResponse = require_adapter_utils.createResponseHandler({
|
|
141
152
|
mapResponse,
|
|
142
153
|
mapCompactResponse
|