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
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { isBun } from "../../universal/constants.mjs";
|
|
2
|
-
import { ElysiaFile
|
|
2
|
+
import { ElysiaFile } from "../../universal/file.mjs";
|
|
3
3
|
import { formToFormData, isElysiaForm, isNotEmpty, nullObject } from "../../utils.mjs";
|
|
4
|
+
import { isProduction } from "../../universal/is-production.mjs";
|
|
4
5
|
import { ElysiaStatus, PROBLEM_JSON, internalServerErrorBody } from "../../error.mjs";
|
|
5
6
|
import { defaultHeaders } from "../default-headers.mjs";
|
|
6
7
|
import { createResponseHandler, createStreamHandler, handleFile, handleSet, materializeSetHeaders } from "../utils.mjs";
|
|
8
|
+
import { Cookie } from "../../cookie/cookie.mjs";
|
|
7
9
|
|
|
8
10
|
//#region src/adapter/web-standard/handler.ts
|
|
9
11
|
const textPlainInit = { headers: { "content-type": "text/plain" } };
|
|
10
12
|
function handleElysiaFile(file, set = { headers: nullObject() }, request) {
|
|
11
|
-
const
|
|
12
|
-
const contentType = mime[path.slice(path.lastIndexOf(".") + 1).toLowerCase()];
|
|
13
|
+
const contentType = file.type;
|
|
13
14
|
const headers = materializeSetHeaders(set);
|
|
14
|
-
if (contentType) headers["content-type"] = contentType;
|
|
15
|
+
if (contentType !== "application/octet-stream") headers["content-type"] = contentType;
|
|
15
16
|
const stats = file.stats;
|
|
16
17
|
if (stats) return stats.then((stat) => {
|
|
17
18
|
const size = stat.size;
|
|
@@ -21,12 +22,16 @@ function handleElysiaFile(file, set = { headers: nullObject() }, request) {
|
|
|
21
22
|
return handleFile(file.value, set, request);
|
|
22
23
|
}
|
|
23
24
|
function responseTag(response) {
|
|
25
|
+
if (typeof response === "string") return "String";
|
|
24
26
|
if (response == null) return;
|
|
25
|
-
|
|
27
|
+
const constructor = Object.getPrototypeOf(response)?.constructor;
|
|
28
|
+
if (typeof constructor !== "function") return typeof response.next === "function" ? "" : void 0;
|
|
29
|
+
return constructor.name;
|
|
26
30
|
}
|
|
27
31
|
function mapResponseWithSet(response, set, request, owned) {
|
|
28
32
|
handleSet(set);
|
|
29
33
|
const headers = set.headers;
|
|
34
|
+
if (!isBun && (set.status === 204 || set.status === 304 || set.status === 205) && !(response instanceof Response) && !(response instanceof ElysiaStatus)) return new Response(null, set);
|
|
30
35
|
switch (responseTag(response)) {
|
|
31
36
|
case "String":
|
|
32
37
|
if (!isBun && !headers["content-type"]) materializeSetHeaders(set)["content-type"] = "text/plain";
|
|
@@ -37,14 +42,11 @@ function mapResponseWithSet(response, set, request, owned) {
|
|
|
37
42
|
if (typeof response?.next === "function") return handleStream(response, set, request, void 0, owned);
|
|
38
43
|
return Response.json(response, set);
|
|
39
44
|
case "Number":
|
|
40
|
-
case "Boolean": return new Response(
|
|
45
|
+
case "Boolean": return new Response(String(response), set);
|
|
41
46
|
case "ElysiaFile": return handleElysiaFile(response, set, request);
|
|
42
47
|
case "File":
|
|
43
48
|
case "Blob": return handleFile(response, set, request);
|
|
44
|
-
case "ElysiaStatus":
|
|
45
|
-
set.status = response.code;
|
|
46
|
-
if (response.headers) Object.assign(materializeSetHeaders(set), response.headers);
|
|
47
|
-
return mapResponseWithSet(response.response, set, request, owned);
|
|
49
|
+
case "ElysiaStatus": return withStatus(response, set, request, owned);
|
|
48
50
|
case void 0: return response ? Response.json(response, set) : new Response(null, set);
|
|
49
51
|
case "Response": return handleResponse(response, set, request, owned);
|
|
50
52
|
case "Error": return errorToResponse(response, set, request, owned);
|
|
@@ -54,14 +56,24 @@ function mapResponseWithSet(response, set, request, owned) {
|
|
|
54
56
|
default: return mapFallback(response, set, request, owned);
|
|
55
57
|
}
|
|
56
58
|
}
|
|
59
|
+
function withStatus(response, set, request, owned) {
|
|
60
|
+
if (set) set.status = response.status;
|
|
61
|
+
else set = {
|
|
62
|
+
status: response.status,
|
|
63
|
+
headers: nullObject()
|
|
64
|
+
};
|
|
65
|
+
if (response.headers) Object.assign(materializeSetHeaders(set), response.headers);
|
|
66
|
+
return mapResponseWithSet(response.response, set, request, owned);
|
|
67
|
+
}
|
|
68
|
+
const checkRemovedSetRedirect = !isProduction();
|
|
57
69
|
function mapResponse(response, set, request, owned) {
|
|
70
|
+
if (checkRemovedSetRedirect && Object.hasOwn(set, "redirect") && !isProduction()) {
|
|
71
|
+
delete set.redirect;
|
|
72
|
+
throw new Error("[Elysia] set.redirect was removed in 2.0 — return redirect(url) instead");
|
|
73
|
+
}
|
|
58
74
|
const headers = set.headers;
|
|
59
75
|
if (set.status !== void 0 || set.cookie || headers["\0"] === headers || isNotEmpty(headers)) return mapResponseWithSet(response, set, request, owned);
|
|
60
|
-
if (response instanceof ElysiaStatus)
|
|
61
|
-
set.status = response.code;
|
|
62
|
-
if (response.headers) Object.assign(set.headers, response.headers);
|
|
63
|
-
return mapResponse(response.response, set, request, owned);
|
|
64
|
-
}
|
|
76
|
+
if (response instanceof ElysiaStatus) return withStatus(response, set, request, owned);
|
|
65
77
|
if (response instanceof Response) return owned ? handleResponse(response, void 0, request, true) : response;
|
|
66
78
|
if (response instanceof Promise) return response.then((x) => mapResponse(x, set, request, owned));
|
|
67
79
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
|
@@ -75,14 +87,11 @@ function mapCompactResponse(response, request, owned) {
|
|
|
75
87
|
case "ElysiaForm": return new Response(formToFormData(response));
|
|
76
88
|
case "Object": return Response.json(response);
|
|
77
89
|
case "Number":
|
|
78
|
-
case "Boolean": return new Response(
|
|
90
|
+
case "Boolean": return new Response(String(response));
|
|
79
91
|
case "ElysiaFile": return handleElysiaFile(response, void 0, request);
|
|
80
92
|
case "File":
|
|
81
93
|
case "Blob": return handleFile(response, void 0, request);
|
|
82
|
-
case "ElysiaStatus": return
|
|
83
|
-
status: response.code,
|
|
84
|
-
headers: response.headers ? Object.assign(nullObject(), response.headers) : nullObject()
|
|
85
|
-
}, request, owned);
|
|
94
|
+
case "ElysiaStatus": return withStatus(response, void 0, request, owned);
|
|
86
95
|
case void 0: return response ? Response.json(response) : new Response("");
|
|
87
96
|
case "Response": return owned ? handleResponse(response, void 0, request, true) : response;
|
|
88
97
|
case "Error": return errorToResponse(response, void 0, request, owned);
|
|
@@ -114,28 +123,30 @@ function errorToResponse(error, set, request, owned = false) {
|
|
|
114
123
|
}
|
|
115
124
|
function mapFallback(response, set, request, owned = false) {
|
|
116
125
|
if (response instanceof Response) return handleResponse(response, set, request, owned);
|
|
117
|
-
if (response instanceof Promise) return response.then((x) => set ? mapResponse(x, set, request, owned) : mapCompactResponse(x, request, owned));
|
|
118
126
|
if (response instanceof Error) return errorToResponse(response, set, request, owned);
|
|
119
|
-
if (response instanceof ElysiaStatus)
|
|
120
|
-
set
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
if (response instanceof ElysiaFile) return handleElysiaFile(response,
|
|
127
|
+
if (response instanceof ElysiaStatus) {
|
|
128
|
+
if (set && response.headers) {
|
|
129
|
+
set.status = response.status;
|
|
130
|
+
set.headers = {
|
|
131
|
+
...set.headers,
|
|
132
|
+
...response.headers
|
|
133
|
+
};
|
|
134
|
+
return mapResponse(response.response, set, request, owned);
|
|
135
|
+
}
|
|
136
|
+
return withStatus(response, set, request, owned);
|
|
137
|
+
}
|
|
138
|
+
if (response instanceof ElysiaFile) return handleElysiaFile(response, set, request);
|
|
131
139
|
if (isElysiaForm(response)) return new Response(formToFormData(response), set);
|
|
132
140
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
|
133
|
-
if (typeof response?.then === "function") return response.then((x) =>
|
|
134
|
-
if (Array.isArray(response)) return Response.json(response);
|
|
135
|
-
if (typeof response?.toResponse === "function") return
|
|
136
|
-
if (responseTag(response) === "Cookie") return
|
|
141
|
+
if (typeof response?.then === "function") return response.then((x) => remap(x, set, request, owned));
|
|
142
|
+
if (Array.isArray(response)) return Response.json(response, set);
|
|
143
|
+
if (typeof response?.toResponse === "function") return remap(response.toResponse(), set, request, owned);
|
|
144
|
+
if (responseTag(response) === "Cookie" && Cookie.isCookie(response)) return remap(response.value, set, request, owned);
|
|
137
145
|
return new Response(response, set);
|
|
138
146
|
}
|
|
147
|
+
function remap(response, set, request, owned) {
|
|
148
|
+
return set ? mapResponse(response, set, request, owned) : mapCompactResponse(response, request, owned);
|
|
149
|
+
}
|
|
139
150
|
const handleResponse = createResponseHandler({
|
|
140
151
|
mapResponse,
|
|
141
152
|
mapCompactResponse
|
|
@@ -1,49 +1,21 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_universal_constants = require('../../universal/constants.js');
|
|
3
2
|
const require_adapter_index = require('../index.js');
|
|
4
|
-
const require_adapter_utils = require('../utils.js');
|
|
5
3
|
const require_adapter_web_standard_handler = require('./handler.js');
|
|
6
4
|
const require_adapter_web_standard_utils = require('./utils.js');
|
|
7
5
|
const require_parse_query = require('../../parse-query.js');
|
|
8
6
|
|
|
9
7
|
//#region src/adapter/web-standard/index.ts
|
|
10
|
-
function
|
|
11
|
-
for (let i = 0; i < ct.length; i++) {
|
|
12
|
-
const code = ct.charCodeAt(i);
|
|
13
|
-
if (code >= 65 && code <= 90) return ct.toLowerCase();
|
|
14
|
-
}
|
|
15
|
-
return ct;
|
|
16
|
-
}
|
|
17
|
-
function parseFormData(context, contentType) {
|
|
18
|
-
contentType ??= context.request.headers.get("content-type") ?? "";
|
|
19
|
-
const ct = lowercaseContentType(contentType);
|
|
20
|
-
if (require_universal_constants.isBun && ct !== contentType) {
|
|
21
|
-
const fullCt = context.request.headers.get("content-type") ?? "";
|
|
22
|
-
const semi = fullCt.indexOf(";");
|
|
23
|
-
const fixedCt = semi === -1 ? lowercaseContentType(fullCt) : lowercaseContentType(fullCt.slice(0, semi)) + fullCt.slice(semi);
|
|
24
|
-
const headers = new Headers(context.request.headers);
|
|
25
|
-
headers.set("content-type", fixedCt);
|
|
26
|
-
return new Request(context.request.url, {
|
|
27
|
-
method: context.request.method,
|
|
28
|
-
headers,
|
|
29
|
-
body: context.request.body,
|
|
30
|
-
duplex: "half"
|
|
31
|
-
}).formData().then(require_adapter_web_standard_utils.formDataToObject);
|
|
32
|
-
}
|
|
8
|
+
function parseFormData(context) {
|
|
33
9
|
return context.request.formData().then(require_adapter_web_standard_utils.formDataToObject);
|
|
34
10
|
}
|
|
35
11
|
const WebStandardAdapter = require_adapter_index.createAdapter({
|
|
36
|
-
name: "web-standard",
|
|
37
|
-
runtime: "unknown",
|
|
38
|
-
isWebStandard: true,
|
|
39
12
|
parse: {
|
|
40
13
|
arrayBuffer: (context) => context.request.arrayBuffer(),
|
|
41
14
|
formData: parseFormData,
|
|
42
15
|
json: (context) => context.request.json(),
|
|
43
16
|
text: (context) => context.request.text(),
|
|
44
17
|
urlencoded: (context) => context.request.text().then(require_parse_query.parseQuery),
|
|
45
|
-
default(context,
|
|
46
|
-
const ct = normalized ? contentType : require_adapter_utils.normalizeContentType(contentType);
|
|
18
|
+
default(context, ct) {
|
|
47
19
|
switch (ct.charCodeAt(12)) {
|
|
48
20
|
case 106:
|
|
49
21
|
if (ct === "application/json") return context.request.json();
|
|
@@ -1,48 +1,20 @@
|
|
|
1
|
-
import { isBun } from "../../universal/constants.mjs";
|
|
2
1
|
import { createAdapter } from "../index.mjs";
|
|
3
|
-
import { normalizeContentType } from "../utils.mjs";
|
|
4
2
|
import { mapCompactResponse, mapResponse } from "./handler.mjs";
|
|
5
3
|
import { formDataToObject } from "./utils.mjs";
|
|
6
4
|
import { parseQuery } from "../../parse-query.mjs";
|
|
7
5
|
|
|
8
6
|
//#region src/adapter/web-standard/index.ts
|
|
9
|
-
function
|
|
10
|
-
for (let i = 0; i < ct.length; i++) {
|
|
11
|
-
const code = ct.charCodeAt(i);
|
|
12
|
-
if (code >= 65 && code <= 90) return ct.toLowerCase();
|
|
13
|
-
}
|
|
14
|
-
return ct;
|
|
15
|
-
}
|
|
16
|
-
function parseFormData(context, contentType) {
|
|
17
|
-
contentType ??= context.request.headers.get("content-type") ?? "";
|
|
18
|
-
const ct = lowercaseContentType(contentType);
|
|
19
|
-
if (isBun && ct !== contentType) {
|
|
20
|
-
const fullCt = context.request.headers.get("content-type") ?? "";
|
|
21
|
-
const semi = fullCt.indexOf(";");
|
|
22
|
-
const fixedCt = semi === -1 ? lowercaseContentType(fullCt) : lowercaseContentType(fullCt.slice(0, semi)) + fullCt.slice(semi);
|
|
23
|
-
const headers = new Headers(context.request.headers);
|
|
24
|
-
headers.set("content-type", fixedCt);
|
|
25
|
-
return new Request(context.request.url, {
|
|
26
|
-
method: context.request.method,
|
|
27
|
-
headers,
|
|
28
|
-
body: context.request.body,
|
|
29
|
-
duplex: "half"
|
|
30
|
-
}).formData().then(formDataToObject);
|
|
31
|
-
}
|
|
7
|
+
function parseFormData(context) {
|
|
32
8
|
return context.request.formData().then(formDataToObject);
|
|
33
9
|
}
|
|
34
10
|
const WebStandardAdapter = createAdapter({
|
|
35
|
-
name: "web-standard",
|
|
36
|
-
runtime: "unknown",
|
|
37
|
-
isWebStandard: true,
|
|
38
11
|
parse: {
|
|
39
12
|
arrayBuffer: (context) => context.request.arrayBuffer(),
|
|
40
13
|
formData: parseFormData,
|
|
41
14
|
json: (context) => context.request.json(),
|
|
42
15
|
text: (context) => context.request.text(),
|
|
43
16
|
urlencoded: (context) => context.request.text().then(parseQuery),
|
|
44
|
-
default(context,
|
|
45
|
-
const ct = normalized ? contentType : normalizeContentType(contentType);
|
|
17
|
+
default(context, ct) {
|
|
46
18
|
switch (ct.charCodeAt(12)) {
|
|
47
19
|
case 106:
|
|
48
20
|
if (ct === "application/json") return context.request.json();
|
|
@@ -32,7 +32,7 @@ function resolveValue(entries) {
|
|
|
32
32
|
return typeof v === "string" ? tryParseJson(v) ?? v : v;
|
|
33
33
|
}
|
|
34
34
|
let jsonObj;
|
|
35
|
-
let
|
|
35
|
+
let files;
|
|
36
36
|
const result = new Array(length);
|
|
37
37
|
for (let i = 0; i < length; i++) {
|
|
38
38
|
const e = entries[i];
|
|
@@ -41,26 +41,13 @@ function resolveValue(entries) {
|
|
|
41
41
|
if (jsonObj === void 0 && parsed && !Array.isArray(parsed)) jsonObj = parsed;
|
|
42
42
|
result[i] = parsed ?? e;
|
|
43
43
|
} else {
|
|
44
|
-
if (HAS_FILE && e instanceof File)
|
|
44
|
+
if (HAS_FILE && e instanceof File) (files ??= []).push(e);
|
|
45
45
|
result[i] = e;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
if (
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
if (HAS_FILE && e instanceof File) {
|
|
52
|
-
jsonObj.file = e;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else if (!("files" in jsonObj)) {
|
|
57
|
-
const files = [];
|
|
58
|
-
for (let i = 0; i < length; i++) {
|
|
59
|
-
const e = entries[i];
|
|
60
|
-
if (HAS_FILE && e instanceof File) files.push(e);
|
|
61
|
-
}
|
|
62
|
-
jsonObj.files = files;
|
|
63
|
-
}
|
|
48
|
+
if (files && jsonObj) {
|
|
49
|
+
if (files.length === 1 && !("file" in jsonObj)) jsonObj.file = files[0];
|
|
50
|
+
else if (!("files" in jsonObj)) jsonObj.files = files;
|
|
64
51
|
return jsonObj;
|
|
65
52
|
}
|
|
66
53
|
return result;
|
|
@@ -31,7 +31,7 @@ function resolveValue(entries) {
|
|
|
31
31
|
return typeof v === "string" ? tryParseJson(v) ?? v : v;
|
|
32
32
|
}
|
|
33
33
|
let jsonObj;
|
|
34
|
-
let
|
|
34
|
+
let files;
|
|
35
35
|
const result = new Array(length);
|
|
36
36
|
for (let i = 0; i < length; i++) {
|
|
37
37
|
const e = entries[i];
|
|
@@ -40,26 +40,13 @@ function resolveValue(entries) {
|
|
|
40
40
|
if (jsonObj === void 0 && parsed && !Array.isArray(parsed)) jsonObj = parsed;
|
|
41
41
|
result[i] = parsed ?? e;
|
|
42
42
|
} else {
|
|
43
|
-
if (HAS_FILE && e instanceof File)
|
|
43
|
+
if (HAS_FILE && e instanceof File) (files ??= []).push(e);
|
|
44
44
|
result[i] = e;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
if (
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
if (HAS_FILE && e instanceof File) {
|
|
51
|
-
jsonObj.file = e;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if (!("files" in jsonObj)) {
|
|
56
|
-
const files = [];
|
|
57
|
-
for (let i = 0; i < length; i++) {
|
|
58
|
-
const e = entries[i];
|
|
59
|
-
if (HAS_FILE && e instanceof File) files.push(e);
|
|
60
|
-
}
|
|
61
|
-
jsonObj.files = files;
|
|
62
|
-
}
|
|
47
|
+
if (files && jsonObj) {
|
|
48
|
+
if (files.length === 1 && !("file" in jsonObj)) jsonObj.file = files[0];
|
|
49
|
+
else if (!("files" in jsonObj)) jsonObj.files = files;
|
|
63
50
|
return jsonObj;
|
|
64
51
|
}
|
|
65
52
|
return result;
|