elysia 2.0.0-exp.5 → 2.0.0-exp.51
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/_virtual/_rolldown/runtime.js +0 -14
- package/dist/_virtual/_rolldown/runtime.mjs +2 -0
- package/dist/adapter/bun/index.d.ts +3 -26
- package/dist/adapter/bun/index.js +197 -58
- package/dist/adapter/bun/index.mjs +198 -59
- package/dist/adapter/constants.d.ts +3 -26
- package/dist/adapter/default-headers.d.ts +4 -0
- package/dist/adapter/default-headers.js +7 -0
- package/dist/adapter/default-headers.mjs +5 -0
- package/dist/adapter/index.d.ts +1 -26
- package/dist/adapter/index.js +1 -19
- package/dist/adapter/index.mjs +1 -19
- package/dist/adapter/origin.d.ts +59 -0
- package/dist/adapter/origin.js +60 -0
- package/dist/adapter/origin.mjs +58 -0
- package/dist/adapter/response-ownership.d.ts +5 -0
- package/dist/adapter/response-ownership.js +13 -0
- package/dist/adapter/response-ownership.mjs +10 -0
- package/dist/adapter/skip-clone.d.ts +4 -0
- package/dist/adapter/skip-clone.js +7 -0
- package/dist/adapter/skip-clone.mjs +5 -0
- package/dist/adapter/types.d.ts +8 -34
- package/dist/adapter/utils.d.ts +22 -17
- package/dist/adapter/utils.js +352 -160
- package/dist/adapter/utils.mjs +352 -160
- package/dist/adapter/web-standard/handler.d.ts +3 -3
- package/dist/adapter/web-standard/handler.js +85 -84
- package/dist/adapter/web-standard/handler.mjs +86 -85
- package/dist/adapter/web-standard/index.d.ts +2 -26
- package/dist/adapter/web-standard/index.js +47 -2
- package/dist/adapter/web-standard/index.mjs +47 -2
- package/dist/adapter/web-standard/utils.js +9 -2
- package/dist/adapter/web-standard/utils.mjs +9 -2
- package/dist/base.d.ts +187 -338
- package/dist/base.js +913 -424
- package/dist/base.mjs +915 -426
- package/dist/compile/analysis-cache.d.ts +6 -0
- package/dist/compile/analysis-cache.js +12 -0
- package/dist/compile/analysis-cache.mjs +11 -0
- package/dist/compile/aot-capture.d.ts +24 -0
- package/dist/compile/aot-capture.js +373 -0
- package/dist/compile/aot-capture.mjs +361 -0
- package/dist/compile/aot-emit.d.ts +29 -0
- package/dist/compile/aot-emit.js +107 -0
- package/dist/compile/aot-emit.mjs +101 -0
- package/dist/compile/aot-reconstruct.d.ts +30 -0
- package/dist/compile/aot-reconstruct.js +156 -0
- package/dist/compile/aot-reconstruct.mjs +147 -0
- package/dist/compile/aot.d.ts +141 -60
- package/dist/compile/aot.js +170 -244
- package/dist/compile/aot.mjs +154 -234
- package/dist/compile/handler/descriptor.d.ts +77 -0
- package/dist/compile/handler/descriptor.js +198 -0
- package/dist/compile/handler/descriptor.mjs +193 -0
- package/dist/compile/handler/frozen-validator.d.ts +39 -0
- package/dist/compile/handler/frozen-validator.js +322 -0
- package/dist/compile/handler/frozen-validator.mjs +316 -0
- package/dist/compile/handler/index.d.ts +12 -4
- package/dist/compile/handler/index.js +202 -65
- package/dist/compile/handler/index.mjs +202 -69
- package/dist/compile/handler/jit.d.ts +15 -7
- package/dist/compile/handler/jit.js +239 -151
- package/dist/compile/handler/jit.mjs +242 -156
- package/dist/compile/handler/params.d.ts +5 -1
- package/dist/compile/handler/params.js +20 -3
- package/dist/compile/handler/params.mjs +22 -5
- package/dist/compile/handler/reconstruct.d.ts +3 -4
- package/dist/compile/handler/reconstruct.js +36 -15
- package/dist/compile/handler/reconstruct.mjs +36 -15
- package/dist/compile/handler/utils.d.ts +19 -12
- package/dist/compile/handler/utils.js +178 -128
- package/dist/compile/handler/utils.mjs +160 -113
- package/dist/compile/jit-probe.d.ts +0 -4
- package/dist/compile/jit-probe.js +1 -11
- package/dist/compile/jit-probe.mjs +1 -11
- package/dist/compile/lexer.d.ts +7 -0
- package/dist/compile/lexer.js +53 -0
- package/dist/compile/lexer.mjs +48 -0
- package/dist/compile/utils.js +8 -4
- package/dist/compile/utils.mjs +8 -4
- package/dist/constants.d.ts +4 -25
- package/dist/constants.js +17 -17
- package/dist/constants.mjs +15 -15
- package/dist/context.d.ts +14 -48
- package/dist/context.js +43 -20
- package/dist/context.mjs +44 -21
- package/dist/cookie/config.d.ts +5 -1
- package/dist/cookie/config.js +19 -22
- package/dist/cookie/config.mjs +18 -22
- package/dist/cookie/cookie.d.ts +3 -5
- package/dist/cookie/cookie.js +42 -23
- package/dist/cookie/cookie.mjs +43 -23
- package/dist/cookie/crypto.d.ts +20 -0
- package/dist/cookie/crypto.js +169 -0
- package/dist/cookie/crypto.mjs +152 -0
- package/dist/cookie/error.d.ts +17 -0
- package/dist/cookie/error.js +25 -0
- package/dist/cookie/error.mjs +24 -0
- package/dist/cookie/index.d.ts +5 -3
- package/dist/cookie/index.js +5 -3
- package/dist/cookie/index.mjs +4 -2
- package/dist/cookie/lib.d.ts +1 -1
- package/dist/cookie/lib.js +15 -13
- package/dist/cookie/lib.mjs +15 -13
- package/dist/cookie/serialize.js +5 -1
- package/dist/cookie/serialize.mjs +5 -1
- package/dist/cookie/types.d.ts +1 -3
- package/dist/cookie/utils.d.ts +14 -7
- package/dist/cookie/utils.js +107 -95
- package/dist/cookie/utils.mjs +102 -91
- package/dist/error.d.ts +100 -19
- package/dist/error.js +355 -120
- package/dist/error.mjs +347 -119
- package/dist/generation.d.ts +30 -0
- package/dist/generation.js +23 -0
- package/dist/generation.mjs +17 -0
- package/dist/handler/error.js +37 -6
- package/dist/handler/error.mjs +38 -7
- package/dist/handler/fetch.js +198 -130
- package/dist/handler/fetch.mjs +198 -130
- package/dist/handler/index.d.ts +1 -3
- package/dist/handler/index.js +1 -5
- package/dist/handler/index.mjs +1 -3
- package/dist/handler/utils.d.ts +11 -2
- package/dist/handler/utils.js +27 -5
- package/dist/handler/utils.mjs +24 -5
- package/dist/index.d.ts +17 -10
- package/dist/index.js +19 -7
- package/dist/index.mjs +11 -8
- package/dist/memory.js +2 -2
- package/dist/memory.mjs +2 -2
- package/dist/package.js +11 -0
- package/dist/package.mjs +5 -0
- package/dist/parse-query.js +38 -22
- package/dist/parse-query.mjs +38 -22
- package/dist/plugin/{bun.d.ts → aot/bun.d.ts} +4 -2
- package/dist/plugin/aot/bun.js +35 -0
- package/dist/plugin/aot/bun.mjs +34 -0
- package/dist/plugin/aot/core.d.ts +291 -0
- package/dist/plugin/aot/core.js +505 -0
- package/dist/plugin/aot/core.mjs +481 -0
- package/dist/plugin/{esbuild.d.ts → aot/esbuild.d.ts} +5 -3
- package/dist/plugin/aot/esbuild.js +48 -0
- package/dist/plugin/aot/esbuild.mjs +46 -0
- package/dist/plugin/aot/hooks.d.ts +28 -0
- package/dist/plugin/aot/hooks.js +114 -0
- package/dist/plugin/aot/hooks.mjs +112 -0
- package/dist/plugin/aot/rspack-loader.d.ts +23 -0
- package/dist/plugin/aot/rspack-loader.js +44 -0
- package/dist/plugin/aot/rspack-loader.mjs +40 -0
- package/dist/plugin/aot/rspack.d.ts +23 -0
- package/dist/plugin/aot/rspack.js +85 -0
- package/dist/plugin/aot/rspack.mjs +82 -0
- package/dist/plugin/aot/source.d.ts +60 -0
- package/dist/plugin/aot/source.js +422 -0
- package/dist/plugin/aot/source.mjs +418 -0
- package/dist/plugin/aot/treeshake.d.ts +4 -0
- package/dist/plugin/aot/treeshake.js +95 -0
- package/dist/plugin/aot/treeshake.mjs +94 -0
- package/dist/plugin/aot/unplugin.d.ts +54 -0
- package/dist/plugin/aot/unplugin.js +68 -0
- package/dist/plugin/aot/unplugin.mjs +66 -0
- package/dist/plugin/{vite.d.ts → aot/vite.d.ts} +4 -3
- package/dist/plugin/aot/vite.js +34 -0
- package/dist/plugin/aot/vite.mjs +33 -0
- package/dist/plugin/aot/worker.js +28 -0
- package/dist/plugin/aot/worker.mjs +27 -0
- package/dist/plugin/auto-head.d.ts +6 -0
- package/dist/plugin/auto-head.js +38 -0
- package/dist/plugin/auto-head.mjs +36 -0
- package/dist/plugin/trace.d.ts +10 -0
- package/dist/plugin/trace.js +39 -0
- package/dist/plugin/trace.mjs +36 -0
- package/dist/plugin/websocket.d.ts +6 -0
- package/dist/plugin/websocket.js +61 -0
- package/dist/plugin/websocket.mjs +60 -0
- package/dist/route-table.d.ts +25 -0
- package/dist/route-table.js +59 -0
- package/dist/route-table.mjs +56 -0
- package/dist/schema-snapshot.d.ts +9 -0
- package/dist/schema-snapshot.js +271 -0
- package/dist/schema-snapshot.mjs +269 -0
- package/dist/sucrose.d.ts +1 -23
- package/dist/sucrose.js +556 -219
- package/dist/sucrose.mjs +557 -217
- package/dist/trace.d.ts +27 -57
- package/dist/trace.js +256 -141
- package/dist/trace.mjs +256 -141
- package/dist/type/bridge-live.d.ts +15 -0
- package/dist/type/bridge-live.js +39 -0
- package/dist/type/bridge-live.mjs +17 -0
- package/dist/type/bridge.d.ts +20 -11
- package/dist/type/bridge.js +34 -0
- package/dist/type/bridge.mjs +10 -1
- package/dist/type/coerce-plan.d.ts +38 -0
- package/dist/type/coerce-plan.js +110 -0
- package/dist/type/coerce-plan.mjs +101 -0
- package/dist/type/coerce.d.ts +6 -24
- package/dist/type/coerce.js +49 -172
- package/dist/type/coerce.mjs +35 -158
- package/dist/type/compat.js +7 -3
- package/dist/type/compat.mjs +9 -5
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/accelerate.js +2 -1
- package/dist/type/elysia/accelerate.mjs +2 -1
- package/dist/type/elysia/array-buffer.d.ts +1 -2
- package/dist/type/elysia/array-buffer.js +9 -3
- package/dist/type/elysia/array-buffer.mjs +10 -4
- package/dist/type/elysia/array-string.js +3 -3
- package/dist/type/elysia/array-string.mjs +1 -1
- package/dist/type/elysia/array.js +7 -4
- package/dist/type/elysia/array.mjs +7 -4
- package/dist/type/elysia/boolean-string.js +2 -1
- package/dist/type/elysia/boolean-string.mjs +2 -1
- package/dist/type/elysia/boolean.js +6 -3
- package/dist/type/elysia/boolean.mjs +6 -3
- package/dist/type/elysia/cookie.d.ts +2 -5
- package/dist/type/elysia/date.js +38 -7
- package/dist/type/elysia/date.mjs +39 -8
- package/dist/type/elysia/file-type.d.ts +2 -1
- package/dist/type/elysia/file-type.js +11 -13
- package/dist/type/elysia/file-type.mjs +12 -14
- package/dist/type/elysia/file.js +10 -4
- package/dist/type/elysia/file.mjs +10 -4
- package/dist/type/elysia/files.js +16 -6
- package/dist/type/elysia/files.mjs +18 -8
- package/dist/type/elysia/integer-string.js +6 -4
- package/dist/type/elysia/integer-string.mjs +6 -4
- package/dist/type/elysia/integer.js +6 -3
- package/dist/type/elysia/integer.mjs +6 -3
- package/dist/type/elysia/intersect.js +8 -5
- package/dist/type/elysia/intersect.mjs +7 -4
- package/dist/type/elysia/maybe-empty.js +4 -2
- package/dist/type/elysia/maybe-empty.mjs +5 -3
- package/dist/type/elysia/nullable.js +4 -1
- package/dist/type/elysia/nullable.mjs +5 -2
- package/dist/type/elysia/number.js +6 -3
- package/dist/type/elysia/number.mjs +6 -3
- package/dist/type/elysia/numeric.js +29 -3
- package/dist/type/elysia/numeric.mjs +29 -3
- package/dist/type/elysia/object-string.js +3 -3
- package/dist/type/elysia/object-string.mjs +1 -1
- package/dist/type/elysia/object.js +8 -5
- package/dist/type/elysia/object.mjs +8 -5
- package/dist/type/elysia/optional.js +11 -13
- package/dist/type/elysia/optional.mjs +12 -13
- package/dist/type/elysia/string.js +22 -6
- package/dist/type/elysia/string.mjs +22 -6
- package/dist/type/elysia/uint8-array.d.ts +1 -2
- package/dist/type/elysia/uint8-array.js +10 -4
- package/dist/type/elysia/uint8-array.mjs +11 -5
- package/dist/type/elysia/union-enum.js +3 -2
- package/dist/type/elysia/union-enum.mjs +4 -3
- package/dist/type/elysia/union.js +6 -3
- package/dist/type/elysia/union.mjs +6 -3
- package/dist/type/elysia/utils.d.ts +3 -2
- package/dist/type/elysia/utils.js +34 -34
- package/dist/type/elysia/utils.mjs +33 -34
- package/dist/type/exports.js +6 -2073
- package/dist/type/exports.mjs +3 -323
- package/dist/type/index.d.ts +6 -2
- package/dist/type/index.js +64 -2
- package/dist/type/index.mjs +62 -3
- package/dist/type/shared.d.ts +27 -0
- package/dist/type/shared.js +171 -0
- package/dist/type/shared.mjs +161 -0
- package/dist/type/types.d.ts +20 -8
- package/dist/type/utils.js +29 -63
- package/dist/type/utils.mjs +29 -63
- package/dist/type/validator/clean-safe.d.ts +8 -0
- package/dist/type/validator/clean-safe.js +82 -0
- package/dist/type/validator/clean-safe.mjs +77 -0
- package/dist/type/validator/custom-error.js +124 -46
- package/dist/type/validator/custom-error.mjs +125 -47
- package/dist/type/validator/default-precompute.d.ts +7 -3
- package/dist/type/validator/default-precompute.js +61 -105
- package/dist/type/validator/default-precompute.mjs +60 -104
- package/dist/type/validator/frozen-check.js +4 -3
- package/dist/type/validator/frozen-check.mjs +2 -1
- package/dist/type/validator/index.d.ts +4 -3
- package/dist/type/validator/index.js +324 -235
- package/dist/type/validator/index.mjs +328 -241
- package/dist/type/validator/string-codec-aot.d.ts +2 -3
- package/dist/type/validator/string-codec-aot.js +8 -47
- package/dist/type/validator/string-codec-aot.mjs +7 -45
- package/dist/type/validator/validator-cache.d.ts +14 -9
- package/dist/type/validator/validator-cache.js +165 -80
- package/dist/type/validator/validator-cache.mjs +162 -80
- package/dist/types.d.ts +191 -102
- package/dist/universal/constants.d.ts +1 -3
- package/dist/universal/constants.js +1 -5
- package/dist/universal/constants.mjs +1 -3
- package/dist/universal/env.d.ts +3 -2
- package/dist/universal/env.js +6 -2
- package/dist/universal/env.mjs +5 -2
- package/dist/universal/file.d.ts +12 -5
- package/dist/universal/file.js +76 -47
- package/dist/universal/file.mjs +76 -47
- package/dist/universal/index.d.ts +2 -1
- package/dist/universal/index.js +3 -1
- package/dist/universal/index.mjs +2 -1
- package/dist/universal/is-production.d.ts +5 -0
- package/dist/universal/is-production.js +10 -0
- package/dist/universal/is-production.mjs +8 -0
- package/dist/universal/server.d.ts +1 -0
- package/dist/utils.d.ts +51 -21
- package/dist/utils.js +293 -54
- package/dist/utils.mjs +278 -53
- package/dist/validator/index.d.ts +13 -12
- package/dist/validator/index.js +157 -68
- package/dist/validator/index.mjs +158 -69
- package/dist/validator/route.d.ts +0 -1
- package/dist/validator/route.js +5 -3
- package/dist/validator/route.mjs +6 -4
- package/dist/ws/context.d.ts +13 -12
- package/dist/ws/context.js +33 -67
- package/dist/ws/context.mjs +33 -67
- package/dist/ws/parser.d.ts +1 -4
- package/dist/ws/route.d.ts +8 -3
- package/dist/ws/route.js +343 -133
- package/dist/ws/route.mjs +341 -135
- package/dist/ws/types.d.ts +47 -5
- package/package.json +78 -32
- package/dist/adapter/bun/router.d.ts +0 -10
- package/dist/adapter/bun/router.js +0 -86
- package/dist/adapter/bun/router.mjs +0 -83
- package/dist/compile/handler/constants.js +0 -1
- package/dist/compile/handler/constants.mjs +0 -1
- package/dist/compile/index.d.ts +0 -3
- package/dist/compile/index.js +0 -8
- package/dist/compile/index.mjs +0 -4
- package/dist/compile/types.d.ts +0 -4
- package/dist/compile/types.js +0 -1
- package/dist/compile/types.mjs +0 -1
- package/dist/plugin/bun.js +0 -82
- package/dist/plugin/bun.mjs +0 -80
- package/dist/plugin/core.d.ts +0 -87
- package/dist/plugin/core.js +0 -109
- package/dist/plugin/core.mjs +0 -102
- package/dist/plugin/esbuild.js +0 -83
- package/dist/plugin/esbuild.mjs +0 -81
- package/dist/plugin/source.d.ts +0 -75
- package/dist/plugin/source.js +0 -354
- package/dist/plugin/source.mjs +0 -349
- package/dist/plugin/treeshake.d.ts +0 -10
- package/dist/plugin/treeshake.js +0 -63
- package/dist/plugin/treeshake.mjs +0 -61
- package/dist/plugin/vite.js +0 -61
- package/dist/plugin/vite.mjs +0 -60
- package/dist/universal/types.d.ts +0 -127
- package/dist/universal/types.js +0 -20
- package/dist/universal/types.mjs +0 -17
- /package/dist/{compile/handler/constants.d.ts → plugin/aot/worker.d.ts} +0 -0
|
@@ -5,19 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __exportAll = (all, no_symbols) => {
|
|
9
|
-
let target = {};
|
|
10
|
-
for (var name in all) {
|
|
11
|
-
__defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
if (!no_symbols) {
|
|
17
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
-
}
|
|
19
|
-
return target;
|
|
20
|
-
};
|
|
21
8
|
var __copyProps = (to, from, except, desc) => {
|
|
22
9
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
10
|
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
@@ -39,5 +26,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
26
|
|
|
40
27
|
//#endregion
|
|
41
28
|
|
|
42
|
-
exports.__exportAll = __exportAll;
|
|
43
29
|
exports.__toESM = __toESM;
|
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
import { ListenCallback, Serve } from "../../universal/server.js";
|
|
2
|
-
import { AnyLocalHook, MaybePromise } from "../../types.js";
|
|
3
|
-
import { Context } from "../../context.js";
|
|
4
1
|
import { AnyElysia } from "../../base.js";
|
|
2
|
+
import { ElysiaAdapterOptions } from "../types.js";
|
|
5
3
|
//#region src/adapter/bun/index.d.ts
|
|
6
|
-
declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>,
|
|
7
|
-
declare const BunAdapter:
|
|
8
|
-
parse: {
|
|
9
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
|
|
10
|
-
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
11
|
-
text: (context: Context) => MaybePromise<string>;
|
|
12
|
-
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
13
|
-
arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
|
|
14
|
-
formData: (context: Context) => MaybePromise<Record<string, unknown>>;
|
|
15
|
-
};
|
|
16
|
-
name: string;
|
|
17
|
-
runtime: "node" | "deno" | "bun" | "cloudflare-worker" | "browser" | "vercel" | "netlify" | "lambda" | "fastly" | "edge" | "unknown" | (string & {});
|
|
18
|
-
isWebStandard: boolean;
|
|
19
|
-
listen?(app: AnyElysia, options: string | number | Partial<Serve>, callback?: ListenCallback): void;
|
|
20
|
-
stop?(app: AnyElysia, closeActiveConnections?: boolean): Promise<void>;
|
|
21
|
-
response: {
|
|
22
|
-
map(response: unknown, set: Context["set"], ...params: unknown[]): unknown;
|
|
23
|
-
compact?(response: unknown, ...params: unknown[]): unknown;
|
|
24
|
-
static?(handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"], ...params: unknown[]): (() => unknown) | undefined;
|
|
25
|
-
nativeStatic?(handle: unknown, hooks: AnyLocalHook, set?: Context["set"]): (() => MaybePromise<Response>) | undefined;
|
|
26
|
-
};
|
|
27
|
-
fetch?(app: AnyElysia): (request: Request) => MaybePromise<Response>;
|
|
28
|
-
};
|
|
4
|
+
declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, readonly []] | undefined;
|
|
5
|
+
declare const BunAdapter: ElysiaAdapterOptions;
|
|
29
6
|
//#endregion
|
|
30
7
|
export { BunAdapter, collectStaticRoutes };
|
|
@@ -1,84 +1,223 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_adapter_index = require('../index.js');
|
|
3
|
+
const require_constants = require('../../constants.js');
|
|
3
4
|
const require_utils = require('../../utils.js');
|
|
4
5
|
const require_adapter_web_standard_index = require('../web-standard/index.js');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
6
|
+
const require_generation = require('../../generation.js');
|
|
7
|
+
const require_compile_handler_index = require('../../compile/handler/index.js');
|
|
8
|
+
const require_route_table = require('../../route-table.js');
|
|
9
|
+
const require_adapter_origin = require('../origin.js');
|
|
7
10
|
|
|
8
11
|
//#region src/adapter/bun/index.ts
|
|
12
|
+
/**
|
|
13
|
+
* ! This may looks like it would cause race condition, but it is not
|
|
14
|
+
* Bun is single-threaded and synchronous, so the `finally` block will
|
|
15
|
+
* always run before the next request comes in
|
|
16
|
+
* @see ../origin.ts
|
|
17
|
+
*
|
|
18
|
+
* Publish the request `Bun.serve` handed us so `createFetchHandler` can prove,
|
|
19
|
+
* before its first suspension, that it holds the untouched original and may
|
|
20
|
+
* defer materializing `request.signal`
|
|
21
|
+
*
|
|
22
|
+
* `finally` runs on the synchronous return of `fetch` (the returned promise is
|
|
23
|
+
* not awaited), so the slot is live only for the handler's synchronous prologue.
|
|
24
|
+
*/
|
|
25
|
+
const withOrigin = (fetch) => (request, server) => {
|
|
26
|
+
require_adapter_origin.origin.request = request;
|
|
27
|
+
try {
|
|
28
|
+
return fetch(request, server);
|
|
29
|
+
} finally {
|
|
30
|
+
require_adapter_origin.origin.request = void 0;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const nativeStaticMethods = new Set([
|
|
34
|
+
"GET",
|
|
35
|
+
"POST",
|
|
36
|
+
"PUT",
|
|
37
|
+
"DELETE",
|
|
38
|
+
"PATCH",
|
|
39
|
+
"HEAD",
|
|
40
|
+
"OPTIONS"
|
|
41
|
+
]);
|
|
9
42
|
function collectStaticRoutes(app) {
|
|
10
|
-
if (app["~
|
|
11
|
-
const hook = require_utils.flattenChain(app["~hookChain"]);
|
|
12
|
-
if (hook && (hook?.request?.length || hook?.mapResponse?.length || hook?.afterResponse?.length || hook?.trace?.length)) return;
|
|
43
|
+
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
13
44
|
app.fetch;
|
|
14
|
-
const
|
|
15
|
-
|
|
45
|
+
const frozenRoot = require_generation.frozenRootOf(app);
|
|
46
|
+
const fetchLevelHook = require_utils.flattenChain(frozenRoot["~hookChain"]);
|
|
47
|
+
if (fetchLevelHook?.request?.length || fetchLevelHook?.trace?.length || frozenRoot["~ext"]?.hoc?.length) return;
|
|
48
|
+
const table = app["~generation"]?.routeTable ?? app["~routeTable"];
|
|
49
|
+
const length = table?.length ?? 0;
|
|
50
|
+
if (!table || !length) return;
|
|
51
|
+
const methods = table.method;
|
|
52
|
+
const paths = table.path;
|
|
53
|
+
const handlers = table.handler;
|
|
54
|
+
let hasCandidate = false;
|
|
55
|
+
for (let i = 0; i < length; i++) {
|
|
56
|
+
const h = handlers[i];
|
|
57
|
+
if (typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
|
|
58
|
+
if (!nativeStaticMethods.has(methods[i])) continue;
|
|
59
|
+
hasCandidate = true;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
if (!hasCandidate) return;
|
|
16
63
|
const ready = require_utils.nullObject();
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
64
|
+
const strictPath = frozenRoot["~config"]?.strictPath === true;
|
|
65
|
+
const seen = /* @__PURE__ */ new Map();
|
|
66
|
+
for (let i = 0; i < length; i++) seen.set(methods[i] + " " + paths[i], i);
|
|
67
|
+
let explicitPaths;
|
|
68
|
+
if (!strictPath) {
|
|
69
|
+
explicitPaths = /* @__PURE__ */ new Map();
|
|
70
|
+
for (let i = 0; i < length; i++) {
|
|
71
|
+
const method = methods[i];
|
|
72
|
+
const path = paths[i];
|
|
73
|
+
let set = explicitPaths.get(method);
|
|
74
|
+
if (!set) explicitPaths.set(method, set = /* @__PURE__ */ new Set());
|
|
75
|
+
set.add(path);
|
|
76
|
+
if (require_constants.needEncodeRegex.test(path)) {
|
|
77
|
+
const encoded = encodeURI(path);
|
|
78
|
+
if (encoded !== path) set.add(encoded);
|
|
79
|
+
}
|
|
29
80
|
}
|
|
30
81
|
}
|
|
31
|
-
|
|
82
|
+
const add = (method, path, value) => {
|
|
83
|
+
if (require_constants.needEncodeRegex.test(path)) path = encodeURI(path);
|
|
84
|
+
(ready[path] ??= require_utils.nullObject())[method] = value;
|
|
85
|
+
};
|
|
86
|
+
for (let i = 0; i < length; i++) {
|
|
87
|
+
const method = methods[i];
|
|
88
|
+
if (method === "WS") continue;
|
|
89
|
+
const path = paths[i];
|
|
90
|
+
if (seen.get(method + " " + path) !== i) continue;
|
|
91
|
+
if (!nativeStaticMethods.has(method)) continue;
|
|
92
|
+
const h = handlers[i];
|
|
93
|
+
if (typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
|
|
94
|
+
const value = require_compile_handler_index.buildNativeStaticResponse(require_route_table.routeRow(table, i), app);
|
|
95
|
+
if (!value) continue;
|
|
96
|
+
add(method, path, value);
|
|
97
|
+
if (!strictPath && !require_constants.isDynamicRegex.test(path)) {
|
|
98
|
+
const loose = require_utils.getLoosePath(path);
|
|
99
|
+
if (loose !== path && !explicitPaths?.get(method)?.has(loose)) add(method, loose, value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!Object.keys(ready).length) return;
|
|
103
|
+
return [ready, []];
|
|
32
104
|
}
|
|
33
105
|
const BunAdapter = require_adapter_index.createAdapter({
|
|
34
|
-
...require_adapter_web_standard_index.WebStandardAdapter,
|
|
35
106
|
name: "bun",
|
|
36
107
|
runtime: "bun",
|
|
108
|
+
isWebStandard: true,
|
|
109
|
+
parse: require_adapter_web_standard_index.WebStandardAdapter.parse,
|
|
110
|
+
response: require_adapter_web_standard_index.WebStandardAdapter.response,
|
|
37
111
|
listen(app, options, callback) {
|
|
38
112
|
const _config = app["~config"]?.serve;
|
|
39
|
-
const
|
|
113
|
+
const optionsIsObject = typeof options === "object";
|
|
114
|
+
const _options = optionsIsObject ? { ...options } : {
|
|
115
|
+
port: +options,
|
|
116
|
+
fetch: (request, server) => app.fetch(request, server)
|
|
117
|
+
};
|
|
118
|
+
if (optionsIsObject) _options.fetch = (request, server) => app.fetch(request, server);
|
|
40
119
|
const serve = _config ? {
|
|
41
120
|
..._config,
|
|
42
121
|
..._options
|
|
43
122
|
} : _options;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
123
|
+
const onSetup = app["~ext"]?.setup;
|
|
124
|
+
const needsGate = app.pending || !!onSetup?.length;
|
|
125
|
+
let ready;
|
|
126
|
+
const build = () => {
|
|
127
|
+
const fetch = app.fetch;
|
|
128
|
+
let routes;
|
|
129
|
+
try {
|
|
130
|
+
routes = collectStaticRoutes(app);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
133
|
+
}
|
|
134
|
+
let websocket;
|
|
135
|
+
if (app["~hasWS"]) {
|
|
136
|
+
const resolved = require_generation.resolvedWsOf(app);
|
|
137
|
+
if (!resolved) throw new Error("[Elysia] internal: WebSocket routes are present but no capability provider was resolved.");
|
|
138
|
+
websocket = resolved.config ? Object.assign(resolved.provider.buildGlobalWSHandler(), resolved.config) : resolved.provider.buildGlobalWSHandler();
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
fetch,
|
|
142
|
+
routes,
|
|
143
|
+
websocket
|
|
63
144
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
145
|
+
};
|
|
146
|
+
let built;
|
|
147
|
+
if (!needsGate) built = build();
|
|
148
|
+
if (needsGate) serve.fetch = (request, server) => ready.then(() => app.fetch(request, server));
|
|
149
|
+
else serve.fetch = withOrigin(built.fetch);
|
|
150
|
+
const server = app.server = Bun.serve(serve);
|
|
151
|
+
const reload = () => {
|
|
152
|
+
try {
|
|
153
|
+
server.reload(serve);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!serve.routes) throw error;
|
|
156
|
+
delete serve.routes;
|
|
157
|
+
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
158
|
+
try {
|
|
159
|
+
server.reload(serve);
|
|
160
|
+
} catch (fallbackError) {
|
|
161
|
+
console.error("[Elysia] Failed to reload Bun server:", fallbackError);
|
|
162
|
+
throw fallbackError;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const setup = () => {
|
|
167
|
+
const onSetup = app["~ext"]?.setup;
|
|
168
|
+
if (!onSetup) return;
|
|
169
|
+
let pendingSetups;
|
|
170
|
+
for (let i = 0; i < onSetup.length; i++) {
|
|
171
|
+
const result = onSetup[i](app);
|
|
172
|
+
if (result && typeof result.then === "function") (pendingSetups ??= []).push(result);
|
|
173
|
+
}
|
|
174
|
+
if (pendingSetups) return Promise.all(pendingSetups);
|
|
175
|
+
};
|
|
176
|
+
const rollback = (error) => {
|
|
177
|
+
if (app.server !== server) return;
|
|
178
|
+
try {
|
|
179
|
+
server.stop(true);
|
|
180
|
+
} catch (stopError) {
|
|
181
|
+
console.error(stopError);
|
|
182
|
+
} finally {
|
|
183
|
+
app.server = void 0;
|
|
78
184
|
}
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
185
|
+
const cleanup = app["~ext"]?.cleanup;
|
|
186
|
+
if (cleanup) for (let i = cleanup.length - 1; i >= 0; i--) try {
|
|
187
|
+
const result = cleanup[i](app);
|
|
188
|
+
if (result && typeof result.then === "function") Promise.resolve(result).catch(console.error);
|
|
189
|
+
} catch (cleanupError) {
|
|
190
|
+
console.error(cleanupError);
|
|
191
|
+
}
|
|
192
|
+
return error;
|
|
193
|
+
};
|
|
194
|
+
const publish = () => {
|
|
195
|
+
if (app.server !== server) return;
|
|
196
|
+
built ??= build();
|
|
197
|
+
serve.fetch = withOrigin(built.fetch);
|
|
198
|
+
if (built.websocket) serve.websocket = built.websocket;
|
|
199
|
+
if (built.routes) serve.routes = built.routes[0];
|
|
200
|
+
if (needsGate || built.websocket || built.routes) reload();
|
|
201
|
+
if (callback) callback(server);
|
|
202
|
+
};
|
|
203
|
+
const start = () => {
|
|
204
|
+
if (app.server !== server) return;
|
|
205
|
+
const setupReady = setup();
|
|
206
|
+
if (setupReady && typeof setupReady.then === "function") return Promise.resolve(setupReady).then(publish);
|
|
207
|
+
publish();
|
|
208
|
+
};
|
|
209
|
+
try {
|
|
210
|
+
if (app.pending) ready = app.modules.then(start);
|
|
211
|
+
else {
|
|
212
|
+
const result = start();
|
|
213
|
+
if (result && typeof result.then === "function") ready = result;
|
|
214
|
+
else if (needsGate) ready = Promise.resolve();
|
|
215
|
+
}
|
|
216
|
+
ready?.catch(rollback);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
rollback(error);
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
82
221
|
}
|
|
83
222
|
});
|
|
84
223
|
|
|
@@ -1,83 +1,222 @@
|
|
|
1
1
|
import { createAdapter } from "../index.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { isDynamicRegex, needEncodeRegex } from "../../constants.mjs";
|
|
3
|
+
import { flattenChain, getLoosePath, nullObject } from "../../utils.mjs";
|
|
3
4
|
import { WebStandardAdapter } from "../web-standard/index.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { frozenRootOf, resolvedWsOf } from "../../generation.mjs";
|
|
6
|
+
import { buildNativeStaticResponse } from "../../compile/handler/index.mjs";
|
|
7
|
+
import { routeRow } from "../../route-table.mjs";
|
|
8
|
+
import { origin } from "../origin.mjs";
|
|
6
9
|
|
|
7
10
|
//#region src/adapter/bun/index.ts
|
|
11
|
+
/**
|
|
12
|
+
* ! This may looks like it would cause race condition, but it is not
|
|
13
|
+
* Bun is single-threaded and synchronous, so the `finally` block will
|
|
14
|
+
* always run before the next request comes in
|
|
15
|
+
* @see ../origin.ts
|
|
16
|
+
*
|
|
17
|
+
* Publish the request `Bun.serve` handed us so `createFetchHandler` can prove,
|
|
18
|
+
* before its first suspension, that it holds the untouched original and may
|
|
19
|
+
* defer materializing `request.signal`
|
|
20
|
+
*
|
|
21
|
+
* `finally` runs on the synchronous return of `fetch` (the returned promise is
|
|
22
|
+
* not awaited), so the slot is live only for the handler's synchronous prologue.
|
|
23
|
+
*/
|
|
24
|
+
const withOrigin = (fetch) => (request, server) => {
|
|
25
|
+
origin.request = request;
|
|
26
|
+
try {
|
|
27
|
+
return fetch(request, server);
|
|
28
|
+
} finally {
|
|
29
|
+
origin.request = void 0;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const nativeStaticMethods = new Set([
|
|
33
|
+
"GET",
|
|
34
|
+
"POST",
|
|
35
|
+
"PUT",
|
|
36
|
+
"DELETE",
|
|
37
|
+
"PATCH",
|
|
38
|
+
"HEAD",
|
|
39
|
+
"OPTIONS"
|
|
40
|
+
]);
|
|
8
41
|
function collectStaticRoutes(app) {
|
|
9
|
-
if (app["~
|
|
10
|
-
const hook = flattenChain(app["~hookChain"]);
|
|
11
|
-
if (hook && (hook?.request?.length || hook?.mapResponse?.length || hook?.afterResponse?.length || hook?.trace?.length)) return;
|
|
42
|
+
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
12
43
|
app.fetch;
|
|
13
|
-
const
|
|
14
|
-
|
|
44
|
+
const frozenRoot = frozenRootOf(app);
|
|
45
|
+
const fetchLevelHook = flattenChain(frozenRoot["~hookChain"]);
|
|
46
|
+
if (fetchLevelHook?.request?.length || fetchLevelHook?.trace?.length || frozenRoot["~ext"]?.hoc?.length) return;
|
|
47
|
+
const table = app["~generation"]?.routeTable ?? app["~routeTable"];
|
|
48
|
+
const length = table?.length ?? 0;
|
|
49
|
+
if (!table || !length) return;
|
|
50
|
+
const methods = table.method;
|
|
51
|
+
const paths = table.path;
|
|
52
|
+
const handlers = table.handler;
|
|
53
|
+
let hasCandidate = false;
|
|
54
|
+
for (let i = 0; i < length; i++) {
|
|
55
|
+
const h = handlers[i];
|
|
56
|
+
if (typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
|
|
57
|
+
if (!nativeStaticMethods.has(methods[i])) continue;
|
|
58
|
+
hasCandidate = true;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (!hasCandidate) return;
|
|
15
62
|
const ready = nullObject();
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
63
|
+
const strictPath = frozenRoot["~config"]?.strictPath === true;
|
|
64
|
+
const seen = /* @__PURE__ */ new Map();
|
|
65
|
+
for (let i = 0; i < length; i++) seen.set(methods[i] + " " + paths[i], i);
|
|
66
|
+
let explicitPaths;
|
|
67
|
+
if (!strictPath) {
|
|
68
|
+
explicitPaths = /* @__PURE__ */ new Map();
|
|
69
|
+
for (let i = 0; i < length; i++) {
|
|
70
|
+
const method = methods[i];
|
|
71
|
+
const path = paths[i];
|
|
72
|
+
let set = explicitPaths.get(method);
|
|
73
|
+
if (!set) explicitPaths.set(method, set = /* @__PURE__ */ new Set());
|
|
74
|
+
set.add(path);
|
|
75
|
+
if (needEncodeRegex.test(path)) {
|
|
76
|
+
const encoded = encodeURI(path);
|
|
77
|
+
if (encoded !== path) set.add(encoded);
|
|
78
|
+
}
|
|
28
79
|
}
|
|
29
80
|
}
|
|
30
|
-
|
|
81
|
+
const add = (method, path, value) => {
|
|
82
|
+
if (needEncodeRegex.test(path)) path = encodeURI(path);
|
|
83
|
+
(ready[path] ??= nullObject())[method] = value;
|
|
84
|
+
};
|
|
85
|
+
for (let i = 0; i < length; i++) {
|
|
86
|
+
const method = methods[i];
|
|
87
|
+
if (method === "WS") continue;
|
|
88
|
+
const path = paths[i];
|
|
89
|
+
if (seen.get(method + " " + path) !== i) continue;
|
|
90
|
+
if (!nativeStaticMethods.has(method)) continue;
|
|
91
|
+
const h = handlers[i];
|
|
92
|
+
if (typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
|
|
93
|
+
const value = buildNativeStaticResponse(routeRow(table, i), app);
|
|
94
|
+
if (!value) continue;
|
|
95
|
+
add(method, path, value);
|
|
96
|
+
if (!strictPath && !isDynamicRegex.test(path)) {
|
|
97
|
+
const loose = getLoosePath(path);
|
|
98
|
+
if (loose !== path && !explicitPaths?.get(method)?.has(loose)) add(method, loose, value);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!Object.keys(ready).length) return;
|
|
102
|
+
return [ready, []];
|
|
31
103
|
}
|
|
32
104
|
const BunAdapter = createAdapter({
|
|
33
|
-
...WebStandardAdapter,
|
|
34
105
|
name: "bun",
|
|
35
106
|
runtime: "bun",
|
|
107
|
+
isWebStandard: true,
|
|
108
|
+
parse: WebStandardAdapter.parse,
|
|
109
|
+
response: WebStandardAdapter.response,
|
|
36
110
|
listen(app, options, callback) {
|
|
37
111
|
const _config = app["~config"]?.serve;
|
|
38
|
-
const
|
|
112
|
+
const optionsIsObject = typeof options === "object";
|
|
113
|
+
const _options = optionsIsObject ? { ...options } : {
|
|
114
|
+
port: +options,
|
|
115
|
+
fetch: (request, server) => app.fetch(request, server)
|
|
116
|
+
};
|
|
117
|
+
if (optionsIsObject) _options.fetch = (request, server) => app.fetch(request, server);
|
|
39
118
|
const serve = _config ? {
|
|
40
119
|
..._config,
|
|
41
120
|
..._options
|
|
42
121
|
} : _options;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
122
|
+
const onSetup = app["~ext"]?.setup;
|
|
123
|
+
const needsGate = app.pending || !!onSetup?.length;
|
|
124
|
+
let ready;
|
|
125
|
+
const build = () => {
|
|
126
|
+
const fetch = app.fetch;
|
|
127
|
+
let routes;
|
|
128
|
+
try {
|
|
129
|
+
routes = collectStaticRoutes(app);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
132
|
+
}
|
|
133
|
+
let websocket;
|
|
134
|
+
if (app["~hasWS"]) {
|
|
135
|
+
const resolved = resolvedWsOf(app);
|
|
136
|
+
if (!resolved) throw new Error("[Elysia] internal: WebSocket routes are present but no capability provider was resolved.");
|
|
137
|
+
websocket = resolved.config ? Object.assign(resolved.provider.buildGlobalWSHandler(), resolved.config) : resolved.provider.buildGlobalWSHandler();
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
fetch,
|
|
141
|
+
routes,
|
|
142
|
+
websocket
|
|
62
143
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
144
|
+
};
|
|
145
|
+
let built;
|
|
146
|
+
if (!needsGate) built = build();
|
|
147
|
+
if (needsGate) serve.fetch = (request, server) => ready.then(() => app.fetch(request, server));
|
|
148
|
+
else serve.fetch = withOrigin(built.fetch);
|
|
149
|
+
const server = app.server = Bun.serve(serve);
|
|
150
|
+
const reload = () => {
|
|
151
|
+
try {
|
|
152
|
+
server.reload(serve);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (!serve.routes) throw error;
|
|
155
|
+
delete serve.routes;
|
|
156
|
+
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
157
|
+
try {
|
|
158
|
+
server.reload(serve);
|
|
159
|
+
} catch (fallbackError) {
|
|
160
|
+
console.error("[Elysia] Failed to reload Bun server:", fallbackError);
|
|
161
|
+
throw fallbackError;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const setup = () => {
|
|
166
|
+
const onSetup = app["~ext"]?.setup;
|
|
167
|
+
if (!onSetup) return;
|
|
168
|
+
let pendingSetups;
|
|
169
|
+
for (let i = 0; i < onSetup.length; i++) {
|
|
170
|
+
const result = onSetup[i](app);
|
|
171
|
+
if (result && typeof result.then === "function") (pendingSetups ??= []).push(result);
|
|
172
|
+
}
|
|
173
|
+
if (pendingSetups) return Promise.all(pendingSetups);
|
|
174
|
+
};
|
|
175
|
+
const rollback = (error) => {
|
|
176
|
+
if (app.server !== server) return;
|
|
177
|
+
try {
|
|
178
|
+
server.stop(true);
|
|
179
|
+
} catch (stopError) {
|
|
180
|
+
console.error(stopError);
|
|
181
|
+
} finally {
|
|
182
|
+
app.server = void 0;
|
|
77
183
|
}
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
|
|
184
|
+
const cleanup = app["~ext"]?.cleanup;
|
|
185
|
+
if (cleanup) for (let i = cleanup.length - 1; i >= 0; i--) try {
|
|
186
|
+
const result = cleanup[i](app);
|
|
187
|
+
if (result && typeof result.then === "function") Promise.resolve(result).catch(console.error);
|
|
188
|
+
} catch (cleanupError) {
|
|
189
|
+
console.error(cleanupError);
|
|
190
|
+
}
|
|
191
|
+
return error;
|
|
192
|
+
};
|
|
193
|
+
const publish = () => {
|
|
194
|
+
if (app.server !== server) return;
|
|
195
|
+
built ??= build();
|
|
196
|
+
serve.fetch = withOrigin(built.fetch);
|
|
197
|
+
if (built.websocket) serve.websocket = built.websocket;
|
|
198
|
+
if (built.routes) serve.routes = built.routes[0];
|
|
199
|
+
if (needsGate || built.websocket || built.routes) reload();
|
|
200
|
+
if (callback) callback(server);
|
|
201
|
+
};
|
|
202
|
+
const start = () => {
|
|
203
|
+
if (app.server !== server) return;
|
|
204
|
+
const setupReady = setup();
|
|
205
|
+
if (setupReady && typeof setupReady.then === "function") return Promise.resolve(setupReady).then(publish);
|
|
206
|
+
publish();
|
|
207
|
+
};
|
|
208
|
+
try {
|
|
209
|
+
if (app.pending) ready = app.modules.then(start);
|
|
210
|
+
else {
|
|
211
|
+
const result = start();
|
|
212
|
+
if (result && typeof result.then === "function") ready = result;
|
|
213
|
+
else if (needsGate) ready = Promise.resolve();
|
|
214
|
+
}
|
|
215
|
+
ready?.catch(rollback);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
rollback(error);
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
81
220
|
}
|
|
82
221
|
});
|
|
83
222
|
|
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { Context } from "../context.js";
|
|
4
|
-
import { AnyElysia } from "../base.js";
|
|
1
|
+
import { ElysiaAdapterOptions } from "./types.js";
|
|
2
|
+
|
|
5
3
|
//#region src/adapter/constants.d.ts
|
|
6
|
-
declare const defaultAdapter:
|
|
7
|
-
parse: {
|
|
8
|
-
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
|
|
9
|
-
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
10
|
-
text: (context: Context) => MaybePromise<string>;
|
|
11
|
-
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
12
|
-
arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
|
|
13
|
-
formData: (context: Context) => MaybePromise<Record<string, unknown>>;
|
|
14
|
-
};
|
|
15
|
-
name: string;
|
|
16
|
-
runtime: "node" | "deno" | "bun" | "cloudflare-worker" | "browser" | "vercel" | "netlify" | "lambda" | "fastly" | "edge" | "unknown" | (string & {});
|
|
17
|
-
isWebStandard: boolean;
|
|
18
|
-
listen?(app: AnyElysia, options: string | number | Partial<Serve>, callback?: ListenCallback): void;
|
|
19
|
-
stop?(app: AnyElysia, closeActiveConnections?: boolean): Promise<void>;
|
|
20
|
-
response: {
|
|
21
|
-
map(response: unknown, set: Context["set"], ...params: unknown[]): unknown;
|
|
22
|
-
compact?(response: unknown, ...params: unknown[]): unknown;
|
|
23
|
-
static?(handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"], ...params: unknown[]): (() => unknown) | undefined;
|
|
24
|
-
nativeStatic?(handle: unknown, hooks: AnyLocalHook, set?: Context["set"]): (() => MaybePromise<Response>) | undefined;
|
|
25
|
-
};
|
|
26
|
-
fetch?(app: AnyElysia): (request: Request) => MaybePromise<Response>;
|
|
27
|
-
};
|
|
4
|
+
declare const defaultAdapter: ElysiaAdapterOptions;
|
|
28
5
|
//#endregion
|
|
29
6
|
export { defaultAdapter };
|