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/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ListenCallback, Serve } from "../universal/server.js";
|
|
2
|
-
import { MaybePromise } from "../types.js";
|
|
3
2
|
import { Context } from "../context.js";
|
|
3
|
+
import { MaybePromise } from "../types.js";
|
|
4
4
|
import { AnyElysia } from "../base.js";
|
|
5
5
|
|
|
6
6
|
//#region src/adapter/types.d.ts
|
|
@@ -10,25 +10,6 @@ import { AnyElysia } from "../base.js";
|
|
|
10
10
|
* @since 2.0.0
|
|
11
11
|
*/
|
|
12
12
|
interface ElysiaAdapterOptions<App extends AnyElysia | void = void> {
|
|
13
|
-
/**
|
|
14
|
-
* Name of the adapter, preferably runtime
|
|
15
|
-
*/
|
|
16
|
-
name: string;
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @param app
|
|
20
|
-
*/
|
|
21
|
-
runtime: 'node' | 'deno' | 'bun' | 'cloudflare-worker' | 'browser' | 'vercel' | 'netlify' | 'lambda' | 'fastly' | 'edge' | 'unknown' | (string & {});
|
|
22
|
-
/**
|
|
23
|
-
* Whether this adapter is web standard
|
|
24
|
-
*/
|
|
25
|
-
isWebStandard: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Whether this adapter supports WebSocket.
|
|
28
|
-
*
|
|
29
|
-
* `.ws()` throws on non-Bun runtimes unless this is set.
|
|
30
|
-
*/
|
|
31
|
-
websocket?: boolean;
|
|
32
13
|
listen?(app: AnyElysia, options: string | number | Partial<Serve>, callback?: ListenCallback): void;
|
|
33
14
|
parse: {
|
|
34
15
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
@@ -36,7 +17,7 @@ interface ElysiaAdapterOptions<App extends AnyElysia | void = void> {
|
|
|
36
17
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
37
18
|
arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
|
|
38
19
|
formData: (context: Context) => MaybePromise<Record<string, unknown>>;
|
|
39
|
-
default: (context: Context, contentType: string
|
|
20
|
+
default: (context: Context, contentType: string) => MaybePromise<any>;
|
|
40
21
|
};
|
|
41
22
|
response: {
|
|
42
23
|
/**
|
package/dist/adapter/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseCookie } from "../cookie/types.js";
|
|
2
|
-
import { ElysiaFile } from "../universal/file.js";
|
|
3
2
|
import { StatusMap } from "../constants.js";
|
|
4
|
-
import { HTTPHeaders } from "../types.js";
|
|
5
3
|
import { Context } from "../context.js";
|
|
4
|
+
import { ElysiaFile } from "../universal/file.js";
|
|
5
|
+
import { HTTPHeaders } from "../types.js";
|
|
6
6
|
//#region src/adapter/utils.d.ts
|
|
7
7
|
declare function materializeSetHeaders(set: Context['set']): any;
|
|
8
8
|
declare function normalizeContentType(contentType: string): string;
|
|
@@ -12,6 +12,7 @@ declare function responseToSetHeaders(response: Response, set?: Context['set']):
|
|
|
12
12
|
headers: HTTPHeaders;
|
|
13
13
|
status?: number | keyof StatusMap;
|
|
14
14
|
cookie?: Record<string, BaseCookie>;
|
|
15
|
+
redirect?: never;
|
|
15
16
|
} | {
|
|
16
17
|
headers: any;
|
|
17
18
|
status: number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required";
|
|
@@ -27,6 +28,16 @@ declare function createStreamHandler({
|
|
|
27
28
|
declare function streamResponse(response: Response): AsyncGenerator<any, void, any>;
|
|
28
29
|
declare function handleSet(set: Context['set']): void;
|
|
29
30
|
declare function createResponseHandler(handler: CreateHandlerParameter): (response: Response, set?: Context["set"], request?: Request, owned?: boolean) => any;
|
|
31
|
+
/**
|
|
32
|
+
* A returned `ReadableStream` is consumed after the handler returns, so
|
|
33
|
+
* afterResponse, `defer()` and derive dispose must wait for it the way a tee'd
|
|
34
|
+
* generator is waited on
|
|
35
|
+
*
|
|
36
|
+
* A returned `Response` is not observed, reading `.body` would move
|
|
37
|
+
* every Response on these routes off Bun's native send path; a `bytes()`
|
|
38
|
+
* stream keeps its exact-stream contract and releases early as before
|
|
39
|
+
*/
|
|
40
|
+
declare function observeStream(source: ReadableStream): [ReadableStream, AsyncIterable<unknown>, AsyncIterableIterator<unknown>] | undefined;
|
|
30
41
|
/**
|
|
31
42
|
* Split async source into `branches` independent iterators
|
|
32
43
|
*
|
|
@@ -47,4 +58,4 @@ declare function createResponseHandler(handler: CreateHandlerParameter): (respon
|
|
|
47
58
|
*/
|
|
48
59
|
declare function tee<T>(source: AsyncIterable<T>, branches?: number, cap?: number, capBytes?: number): AsyncIterableIterator<T>[];
|
|
49
60
|
//#endregion
|
|
50
|
-
export { createResponseHandler, createStreamHandler, handleFile, handleSet, materializeSetHeaders, normalizeContentType, parseSetCookies, responseToSetHeaders, streamResponse, tee };
|
|
61
|
+
export { createResponseHandler, createStreamHandler, handleFile, handleSet, materializeSetHeaders, normalizeContentType, observeStream, parseSetCookies, responseToSetHeaders, streamResponse, tee };
|
package/dist/adapter/utils.js
CHANGED
|
@@ -14,25 +14,19 @@ function materializeSetHeaders(set) {
|
|
|
14
14
|
if (headers["\0"] !== headers) return headers;
|
|
15
15
|
return set.headers = Object.assign(require_utils.nullObject(), headers);
|
|
16
16
|
}
|
|
17
|
-
const sseFormat = (data) =>
|
|
17
|
+
const sseFormat = (data) => require_utils.sseData(data) + "\n";
|
|
18
18
|
const identityFormat = (data) => data;
|
|
19
19
|
const textEncoder = new TextEncoder();
|
|
20
|
-
const encodeChunk = (s) => textEncoder.encode(s);
|
|
21
20
|
function normalizeContentType(contentType) {
|
|
22
21
|
if (contentType === "application/json") return contentType;
|
|
23
22
|
const end = contentType.indexOf(";");
|
|
24
23
|
return (end === -1 ? contentType : contentType.slice(0, end)).trim().toLowerCase();
|
|
25
24
|
}
|
|
26
25
|
function handleFile(response, set, request, size = response.size) {
|
|
27
|
-
if (!require_universal_constants.isBun && response instanceof Promise) return response.then((res) => handleFile(res, set, request, size));
|
|
28
26
|
const rangeHeader = request?.headers.get("range");
|
|
29
27
|
if (rangeHeader) {
|
|
30
28
|
const match = /bytes=(\d*)-(\d*)/.exec(rangeHeader);
|
|
31
29
|
if (match) {
|
|
32
|
-
if (!match[1] && !match[2]) return new Response(null, {
|
|
33
|
-
status: 416,
|
|
34
|
-
headers: mergeHeaders(new Headers({ "content-range": `bytes */${size}` }), set?.headers ?? require_utils.nullObject())
|
|
35
|
-
});
|
|
36
30
|
let start;
|
|
37
31
|
let end;
|
|
38
32
|
if (!match[1] && match[2]) {
|
|
@@ -43,7 +37,7 @@ function handleFile(response, set, request, size = response.size) {
|
|
|
43
37
|
start = match[1] ? parseInt(match[1]) : 0;
|
|
44
38
|
end = match[2] ? Math.min(parseInt(match[2]), size - 1) : size - 1;
|
|
45
39
|
}
|
|
46
|
-
if (start >= size || start > end) return new Response(null, {
|
|
40
|
+
if (!match[1] && !match[2] || start >= size || start > end) return new Response(null, {
|
|
47
41
|
status: 416,
|
|
48
42
|
headers: mergeHeaders(new Headers({ "content-range": `bytes */${size}` }), set?.headers ?? require_utils.nullObject())
|
|
49
43
|
});
|
|
@@ -75,13 +69,9 @@ function handleFile(response, set, request, size = response.size) {
|
|
|
75
69
|
}
|
|
76
70
|
return new Response(body, set);
|
|
77
71
|
}
|
|
78
|
-
if (require_utils.isNotEmpty(set.headers)) return new Response(body, {
|
|
79
|
-
status: set.status,
|
|
80
|
-
headers: Object.assign(defaultHeader, set.headers)
|
|
81
|
-
});
|
|
82
72
|
return new Response(body, {
|
|
83
73
|
status: set.status,
|
|
84
|
-
headers: defaultHeader
|
|
74
|
+
headers: Object.assign(defaultHeader, set.headers)
|
|
85
75
|
});
|
|
86
76
|
}
|
|
87
77
|
function normalizeHeaders(set) {
|
|
@@ -124,27 +114,9 @@ function responseToSetHeaders(response, set) {
|
|
|
124
114
|
if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
125
115
|
return set;
|
|
126
116
|
}
|
|
127
|
-
function enqueueBinaryChunk(controller, chunk) {
|
|
128
|
-
if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
|
|
129
|
-
controller.enqueue(new Uint8Array(buffer));
|
|
130
|
-
return true;
|
|
131
|
-
});
|
|
132
|
-
if (chunk instanceof Uint8Array) {
|
|
133
|
-
controller.enqueue(chunk);
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
if (chunk instanceof ArrayBuffer) {
|
|
137
|
-
controller.enqueue(new Uint8Array(chunk));
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
if (ArrayBuffer.isView(chunk)) {
|
|
141
|
-
controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
117
|
function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
147
118
|
return async (generator, set, request, skipFormat, owned = false) => {
|
|
119
|
+
if (request === null) return void 0;
|
|
148
120
|
if (require_utils.isByteStream(generator)) {
|
|
149
121
|
if (generator.locked) throw new TypeError("Cannot transfer a locked or consumed byte stream");
|
|
150
122
|
if (set) {
|
|
@@ -158,10 +130,12 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
158
130
|
return new Response(generator, { headers: { "content-type": "application/octet-stream" } });
|
|
159
131
|
}
|
|
160
132
|
const typedSSE = !skipFormat && "sse" in generator && generator.sse === true;
|
|
133
|
+
const sourceIterator = typeof generator.next === "function" ? generator : void 0;
|
|
161
134
|
let init = typedSSE ? void 0 : generator.next?.();
|
|
162
135
|
if (set) handleSet(set);
|
|
163
136
|
if (init instanceof Promise) init = await init;
|
|
164
|
-
|
|
137
|
+
const yieldedStream = init?.value instanceof ReadableStream;
|
|
138
|
+
if (yieldedStream) generator = init.value;
|
|
165
139
|
else if (init && (typeof init?.done === "undefined" || init?.done)) {
|
|
166
140
|
if (set) return mapResponse(init.value, set, request, owned);
|
|
167
141
|
return mapCompactResponse(init.value, request, owned);
|
|
@@ -195,8 +169,32 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
195
169
|
connection: "keep-alive"
|
|
196
170
|
}
|
|
197
171
|
};
|
|
198
|
-
const
|
|
172
|
+
const sourceStream = generator instanceof ReadableStream ? generator : void 0;
|
|
173
|
+
let streamReader;
|
|
174
|
+
const iterator = sourceStream ? {
|
|
175
|
+
next: () => (streamReader ??= sourceStream.getReader()).read(),
|
|
176
|
+
async return() {
|
|
177
|
+
if (!streamReader) {
|
|
178
|
+
await sourceStream.cancel();
|
|
179
|
+
return {
|
|
180
|
+
done: true,
|
|
181
|
+
value: void 0
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
await streamReader.cancel();
|
|
186
|
+
} finally {
|
|
187
|
+
streamReader.releaseLock();
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
done: true,
|
|
191
|
+
value: void 0
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
} : sourceIterator ?? generator[Symbol.asyncIterator]();
|
|
195
|
+
const outerIterator = yieldedStream && !init.done ? sourceIterator : void 0;
|
|
199
196
|
let end = false;
|
|
197
|
+
let finalizing;
|
|
200
198
|
const signal = request?.signal;
|
|
201
199
|
let onAbort;
|
|
202
200
|
const cleanupAbort = () => {
|
|
@@ -205,71 +203,93 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
205
203
|
onAbort = void 0;
|
|
206
204
|
}
|
|
207
205
|
};
|
|
208
|
-
const safeReturn = () => {
|
|
206
|
+
const safeReturn = async (target) => {
|
|
209
207
|
try {
|
|
210
|
-
|
|
211
|
-
if (r && typeof r.then === "function") r.catch(() => {});
|
|
208
|
+
await target?.return?.();
|
|
212
209
|
} catch {}
|
|
213
210
|
};
|
|
214
|
-
const
|
|
211
|
+
const finalize = (mode, controller, error) => {
|
|
212
|
+
if (end) return finalizing;
|
|
213
|
+
end = true;
|
|
214
|
+
cleanupAbort();
|
|
215
|
+
finalizing = safeReturn(iterator).then(() => safeReturn(outerIterator));
|
|
216
|
+
if (!controller) return finalizing;
|
|
215
217
|
try {
|
|
216
|
-
controller.
|
|
218
|
+
if (mode === "error") controller.error(error);
|
|
219
|
+
else controller.close();
|
|
217
220
|
} catch {}
|
|
218
|
-
cleanupAbort();
|
|
219
221
|
};
|
|
220
|
-
const enqueueValue =
|
|
222
|
+
const enqueueValue = (controller, value) => {
|
|
221
223
|
if (value.toSSE) {
|
|
222
|
-
controller.enqueue(
|
|
224
|
+
controller.enqueue(textEncoder.encode(value.toSSE()));
|
|
223
225
|
return;
|
|
224
226
|
}
|
|
225
|
-
|
|
226
|
-
if (
|
|
227
|
+
let p;
|
|
228
|
+
if (value instanceof Blob) p = value.arrayBuffer().then((buffer) => {
|
|
229
|
+
controller.enqueue(new Uint8Array(buffer));
|
|
230
|
+
});
|
|
231
|
+
else if (value instanceof Uint8Array) {
|
|
232
|
+
controller.enqueue(value);
|
|
233
|
+
p = true;
|
|
234
|
+
} else if (value instanceof ArrayBuffer) {
|
|
235
|
+
controller.enqueue(new Uint8Array(value));
|
|
236
|
+
p = true;
|
|
237
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
238
|
+
controller.enqueue(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
239
|
+
p = true;
|
|
240
|
+
} else p = false;
|
|
241
|
+
if (p !== false) return p === true ? void 0 : p;
|
|
227
242
|
if (typeof value === "object") try {
|
|
228
|
-
controller.enqueue(
|
|
243
|
+
controller.enqueue(textEncoder.encode(format(JSON.stringify(value))));
|
|
229
244
|
} catch {
|
|
230
|
-
controller.enqueue(
|
|
245
|
+
controller.enqueue(textEncoder.encode(format(value.toString())));
|
|
231
246
|
}
|
|
232
|
-
else controller.enqueue(
|
|
247
|
+
else controller.enqueue(textEncoder.encode(format(value.toString())));
|
|
233
248
|
};
|
|
234
249
|
return new Response(new ReadableStream({
|
|
235
|
-
|
|
250
|
+
start(controller) {
|
|
236
251
|
if (signal) {
|
|
237
|
-
onAbort = () =>
|
|
238
|
-
cleanupAbort();
|
|
239
|
-
end = true;
|
|
240
|
-
safeReturn();
|
|
241
|
-
try {
|
|
242
|
-
controller.close();
|
|
243
|
-
} catch {}
|
|
244
|
-
};
|
|
252
|
+
onAbort = () => finalize("close", controller);
|
|
245
253
|
if (signal.aborted) onAbort();
|
|
246
254
|
else signal.addEventListener("abort", onAbort, { once: true });
|
|
247
255
|
}
|
|
248
256
|
if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (end) {
|
|
253
|
-
closeSafely(controller);
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
257
|
+
const fail = (error) => {
|
|
258
|
+
finalize("error", controller, error);
|
|
259
|
+
};
|
|
256
260
|
try {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
+
return enqueueValue(controller, init.value)?.catch(fail);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
fail(error);
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
pull(controller) {
|
|
267
|
+
if (end) return;
|
|
268
|
+
const fail = (error) => {
|
|
269
|
+
finalize("error", controller, error);
|
|
270
|
+
};
|
|
271
|
+
const step = (result) => {
|
|
272
|
+
while (true) {
|
|
273
|
+
if (result.done || end) {
|
|
274
|
+
finalize("close", controller);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const chunk = result.value;
|
|
278
|
+
if (chunk !== void 0 && chunk !== null) return enqueueValue(controller, chunk);
|
|
279
|
+
const next = iterator.next();
|
|
280
|
+
if (typeof next.then === "function") return Promise.resolve(next).then(step);
|
|
281
|
+
result = next;
|
|
261
282
|
}
|
|
262
|
-
|
|
263
|
-
|
|
283
|
+
};
|
|
284
|
+
try {
|
|
285
|
+
const next = iterator.next();
|
|
286
|
+
return (typeof next.then === "function" ? Promise.resolve(next).then(step) : step(next))?.catch(fail);
|
|
264
287
|
} catch (error) {
|
|
265
|
-
|
|
266
|
-
controller.error(error);
|
|
288
|
+
fail(error);
|
|
267
289
|
}
|
|
268
290
|
},
|
|
269
291
|
cancel() {
|
|
270
|
-
|
|
271
|
-
cleanupAbort();
|
|
272
|
-
safeReturn();
|
|
292
|
+
finalize("close");
|
|
273
293
|
}
|
|
274
294
|
}, typedSSE ? { highWaterMark: 0 } : void 0), set);
|
|
275
295
|
};
|
|
@@ -284,7 +304,7 @@ function handleSet(set) {
|
|
|
284
304
|
const proto = Object.getPrototypeOf(set.headers);
|
|
285
305
|
if (proto !== null && proto !== Object.prototype) {
|
|
286
306
|
const flat = Object.create(null);
|
|
287
|
-
for (const key
|
|
307
|
+
for (const key of Object.keys(set.headers)) flat[key] = set.headers[key];
|
|
288
308
|
set.headers = flat;
|
|
289
309
|
}
|
|
290
310
|
if (set.cookie && require_utils.isNotEmpty(set.cookie)) {
|
|
@@ -292,8 +312,11 @@ function handleSet(set) {
|
|
|
292
312
|
const cookie = require_cookie_serialize.serializeCookie(set.cookie);
|
|
293
313
|
if (cookie) {
|
|
294
314
|
const existing = set.headers[setCookie];
|
|
295
|
-
if (
|
|
296
|
-
|
|
315
|
+
if (existing) {
|
|
316
|
+
const kept = typeof existing === "string" ? [existing] : existing;
|
|
317
|
+
const added = (typeof cookie === "string" ? [cookie] : cookie).filter((value) => !kept.includes(value));
|
|
318
|
+
set.headers[setCookie] = added.length ? kept.concat(added) : existing;
|
|
319
|
+
} else set.headers[setCookie] = cookie;
|
|
297
320
|
}
|
|
298
321
|
}
|
|
299
322
|
if (set.headers[setCookie] && Array.isArray(set.headers[setCookie])) set.headers = parseSetCookies(new Headers(set.headers), set.headers[setCookie]);
|
|
@@ -311,7 +334,7 @@ function applySetHeaders(target, setHeaders, present) {
|
|
|
311
334
|
for (const key of setHeaders.keys()) if (key !== setCookie && !present.has(key)) target.set(key, setHeaders.get(key) ?? "");
|
|
312
335
|
} else {
|
|
313
336
|
let cookies;
|
|
314
|
-
for (const key
|
|
337
|
+
for (const key of Object.keys(setHeaders)) if (key === setCookie) {
|
|
315
338
|
const cookie = setHeaders[key];
|
|
316
339
|
cookies ??= target.getSetCookie();
|
|
317
340
|
if (!cookies.includes(cookie)) {
|
|
@@ -349,7 +372,6 @@ function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = fals
|
|
|
349
372
|
}
|
|
350
373
|
});
|
|
351
374
|
}
|
|
352
|
-
const warnedStreamBorrows = /* @__PURE__ */ new WeakSet();
|
|
353
375
|
function createResponseHandler(handler) {
|
|
354
376
|
const handleStream = createStreamHandler(handler);
|
|
355
377
|
return (response, set, request, owned = false) => {
|
|
@@ -361,25 +383,21 @@ function createResponseHandler(handler) {
|
|
|
361
383
|
const borrowed = !owned || explicitlyBorrowed;
|
|
362
384
|
const mustClone = owned && explicitlyBorrowed;
|
|
363
385
|
if (!borrowed && response.bodyUsed) throw new TypeError("Cannot reuse a consumed Response across requests");
|
|
386
|
+
let status;
|
|
364
387
|
if (set) {
|
|
365
|
-
|
|
388
|
+
status = mergeStatus(response.status, set.status);
|
|
366
389
|
const statusUnchanged = status === void 0 || status === response.status;
|
|
367
390
|
if (!mustClone && statusUnchanged && !set.cookie && !require_utils.isNotEmpty(set.headers)) return response;
|
|
368
391
|
} else if (!mustClone) return response;
|
|
369
392
|
if (!borrowed && response.body?.locked) throw new TypeError("Cannot patch a Response whose body is locked");
|
|
370
393
|
let body = response.body;
|
|
371
394
|
if (borrowed) {
|
|
372
|
-
const bodyBefore = body;
|
|
373
395
|
const cloned = response.clone();
|
|
374
|
-
if (explicitlyBorrowed && bodyBefore && response.body !== bodyBefore && !warnedStreamBorrows.has(response)) {
|
|
375
|
-
warnedStreamBorrows.add(response);
|
|
376
|
-
console.warn("[elysia] borrow() was called on a stream-backed Response");
|
|
377
|
-
}
|
|
378
396
|
body = cloned.body && response.body ? cancelPropagatingBody(cloned.body, response.body, explicitlyBorrowed) : cloned.body;
|
|
379
397
|
}
|
|
380
398
|
const newResponse = new Response(body, set ? {
|
|
381
399
|
headers: mergeHeaders(response.headers, set.headers),
|
|
382
|
-
status
|
|
400
|
+
status,
|
|
383
401
|
statusText: response.statusText
|
|
384
402
|
} : {
|
|
385
403
|
headers: response.headers,
|
|
@@ -404,6 +422,46 @@ const doneResult = {
|
|
|
404
422
|
value: void 0
|
|
405
423
|
};
|
|
406
424
|
/**
|
|
425
|
+
* A returned `ReadableStream` is consumed after the handler returns, so
|
|
426
|
+
* afterResponse, `defer()` and derive dispose must wait for it the way a tee'd
|
|
427
|
+
* generator is waited on
|
|
428
|
+
*
|
|
429
|
+
* A returned `Response` is not observed, reading `.body` would move
|
|
430
|
+
* every Response on these routes off Bun's native send path; a `bytes()`
|
|
431
|
+
* stream keeps its exact-stream contract and releases early as before
|
|
432
|
+
*/
|
|
433
|
+
function observeStream(source) {
|
|
434
|
+
if (source.locked || require_utils.isByteStream(source)) return;
|
|
435
|
+
const reader = source.getReader();
|
|
436
|
+
const [value, observer] = tee({ [Symbol.asyncIterator]: () => ({
|
|
437
|
+
next: () => reader.read(),
|
|
438
|
+
return: (reason) => reader.cancel(reason).then(() => ({
|
|
439
|
+
done: true,
|
|
440
|
+
value: void 0
|
|
441
|
+
}))
|
|
442
|
+
}) });
|
|
443
|
+
const body = new ReadableStream({
|
|
444
|
+
async pull(controller) {
|
|
445
|
+
try {
|
|
446
|
+
const result = await value.next();
|
|
447
|
+
if (result.done) controller.close();
|
|
448
|
+
else controller.enqueue(result.value);
|
|
449
|
+
} catch (error) {
|
|
450
|
+
controller.error(error);
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
cancel(reason) {
|
|
454
|
+
return value.return?.(reason);
|
|
455
|
+
}
|
|
456
|
+
}, { highWaterMark: 0 });
|
|
457
|
+
if (source.sse === true) body.sse = true;
|
|
458
|
+
return [
|
|
459
|
+
body,
|
|
460
|
+
observer,
|
|
461
|
+
value
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
407
465
|
* Split async source into `branches` independent iterators
|
|
408
466
|
*
|
|
409
467
|
* A producer drains the source ahead of consumers
|
|
@@ -524,7 +582,7 @@ function tee(source, branches = 2, cap = 64, capBytes = 1 << 22) {
|
|
|
524
582
|
wakeAll();
|
|
525
583
|
}
|
|
526
584
|
})();
|
|
527
|
-
const makeBranch = (me) => ({
|
|
585
|
+
const makeBranch = (me) => Object.assign(Object.create(null), {
|
|
528
586
|
[Symbol.asyncIterator]() {
|
|
529
587
|
return this;
|
|
530
588
|
},
|
|
@@ -564,6 +622,7 @@ exports.handleFile = handleFile;
|
|
|
564
622
|
exports.handleSet = handleSet;
|
|
565
623
|
exports.materializeSetHeaders = materializeSetHeaders;
|
|
566
624
|
exports.normalizeContentType = normalizeContentType;
|
|
625
|
+
exports.observeStream = observeStream;
|
|
567
626
|
exports.parseSetCookies = parseSetCookies;
|
|
568
627
|
exports.responseToSetHeaders = responseToSetHeaders;
|
|
569
628
|
exports.streamResponse = streamResponse;
|