elysia 2.0.0-beta.3 → 2.0.0-beta.30
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/README.md +1 -1
- package/dist/_virtual/_rolldown/runtime.mjs +1 -0
- package/dist/adapter/bun/index.d.ts +16 -2
- package/dist/adapter/bun/index.js +458 -119
- package/dist/adapter/bun/index.mjs +459 -121
- package/dist/adapter/constants.mjs +1 -0
- package/dist/adapter/default-headers.mjs +1 -0
- package/dist/adapter/index.mjs +1 -0
- package/dist/adapter/origin.js +0 -57
- package/dist/adapter/origin.mjs +1 -57
- package/dist/adapter/response-ownership.mjs +1 -0
- package/dist/adapter/skip-clone.mjs +1 -0
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/types.mjs +1 -0
- package/dist/adapter/utils.d.ts +11 -3
- package/dist/adapter/utils.js +147 -112
- package/dist/adapter/utils.mjs +149 -114
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +39 -36
- package/dist/adapter/web-standard/handler.mjs +41 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +3 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +6 -18
- package/dist/base.d.ts +272 -145
- package/dist/base.js +740 -675
- package/dist/base.mjs +745 -679
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +40 -90
- package/dist/compile/aot-capture.mjs +44 -89
- package/dist/compile/aot-emit.d.ts +9 -8
- package/dist/compile/aot-emit.js +36 -38
- package/dist/compile/aot-emit.mjs +37 -38
- package/dist/compile/aot-reconstruct.js +7 -30
- package/dist/compile/aot-reconstruct.mjs +8 -30
- package/dist/compile/aot.d.ts +15 -17
- package/dist/compile/aot.js +36 -58
- package/dist/compile/aot.mjs +34 -57
- package/dist/compile/handler/descriptor.d.ts +10 -17
- package/dist/compile/handler/descriptor.js +25 -58
- package/dist/compile/handler/descriptor.mjs +29 -58
- package/dist/compile/handler/frozen-validator.d.ts +7 -12
- package/dist/compile/handler/frozen-validator.js +57 -118
- package/dist/compile/handler/frozen-validator.mjs +56 -118
- package/dist/compile/handler/index.d.ts +8 -4
- package/dist/compile/handler/index.js +322 -206
- package/dist/compile/handler/index.mjs +324 -211
- package/dist/compile/handler/jit.d.ts +28 -21
- package/dist/compile/handler/jit.js +232 -159
- package/dist/compile/handler/jit.mjs +235 -165
- package/dist/compile/handler/params.d.ts +5 -4
- package/dist/compile/handler/params.js +20 -9
- package/dist/compile/handler/params.mjs +24 -12
- package/dist/compile/handler/reconstruct.d.ts +4 -4
- package/dist/compile/handler/reconstruct.js +8 -6
- package/dist/compile/handler/reconstruct.mjs +9 -6
- 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 +8 -0
- package/dist/compile/handler/utils.d.ts +29 -11
- package/dist/compile/handler/utils.js +178 -273
- package/dist/compile/handler/utils.mjs +173 -272
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +3 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +269 -4
- package/dist/compile/utils.d.ts +2 -1
- package/dist/compile/utils.js +14 -6
- package/dist/compile/utils.mjs +14 -6
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -10
- package/dist/compiled.mjs +1 -10
- package/dist/constants.js +19 -4
- package/dist/constants.mjs +20 -4
- package/dist/context.d.ts +15 -5
- package/dist/context.js +17 -36
- package/dist/context.mjs +20 -38
- package/dist/cookie/config.d.ts +6 -2
- package/dist/cookie/config.js +77 -23
- package/dist/cookie/config.mjs +79 -25
- package/dist/cookie/cookie.d.ts +7 -5
- package/dist/cookie/cookie.js +12 -10
- package/dist/cookie/cookie.mjs +13 -10
- package/dist/cookie/crypto.d.ts +1 -1
- package/dist/cookie/crypto.js +19 -14
- package/dist/cookie/crypto.mjs +20 -14
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -3
- package/dist/cookie/error.mjs +7 -3
- package/dist/cookie/lib.js +2 -1
- package/dist/cookie/lib.mjs +3 -1
- package/dist/cookie/serialize.mjs +1 -0
- package/dist/cookie/types.d.ts +1 -1
- package/dist/cookie/types.mjs +1 -0
- package/dist/cookie/utils.d.ts +5 -9
- package/dist/cookie/utils.js +109 -83
- package/dist/cookie/utils.mjs +112 -84
- package/dist/error.d.ts +126 -111
- package/dist/error.js +187 -180
- package/dist/error.mjs +185 -181
- package/dist/generation.d.ts +2 -2
- package/dist/generation.mjs +1 -0
- package/dist/handler/error.d.ts +15 -18
- package/dist/handler/error.js +74 -120
- package/dist/handler/error.mjs +77 -122
- package/dist/handler/fetch.js +165 -153
- package/dist/handler/fetch.mjs +168 -155
- package/dist/handler/utils.d.ts +25 -6
- package/dist/handler/utils.js +81 -26
- package/dist/handler/utils.mjs +76 -25
- package/dist/index.d.ts +11 -11
- package/dist/index.js +3 -1
- package/dist/index.mjs +5 -4
- package/dist/memory.js +2 -2
- package/dist/memory.mjs +3 -2
- package/dist/package.js +1 -1
- package/dist/package.mjs +2 -1
- package/dist/parse-query.js +76 -80
- package/dist/parse-query.mjs +77 -80
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +9 -28
- package/dist/plugin/aot/bun.mjs +11 -29
- package/dist/plugin/aot/core.d.ts +37 -66
- package/dist/plugin/aot/core.js +197 -153
- package/dist/plugin/aot/core.mjs +195 -156
- package/dist/plugin/aot/esbuild.js +8 -24
- package/dist/plugin/aot/esbuild.mjs +10 -25
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +37 -17
- package/dist/plugin/aot/hooks.mjs +38 -19
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -26
- package/dist/plugin/aot/rspack-loader.mjs +2 -26
- package/dist/plugin/aot/rspack.js +2 -19
- package/dist/plugin/aot/rspack.mjs +4 -20
- package/dist/plugin/aot/source.d.ts +7 -43
- package/dist/plugin/aot/source.js +73 -73
- package/dist/plugin/aot/source.mjs +74 -74
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +3 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -32
- package/dist/plugin/aot/unplugin.mjs +5 -32
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/vite.js +0 -14
- package/dist/plugin/aot/vite.mjs +1 -14
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +3 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +2 -10
- package/dist/plugin/trace.d.ts +18 -1
- package/dist/plugin/trace.js +0 -16
- package/dist/plugin/trace.mjs +1 -16
- package/dist/plugin/websocket.d.ts +21 -0
- package/dist/plugin/websocket.js +0 -21
- package/dist/plugin/websocket.mjs +1 -21
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +4 -1
- package/dist/route-table.mjs +5 -1
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +60 -56
- package/dist/schema-snapshot.mjs +61 -56
- package/dist/sucrose.d.ts +7 -56
- package/dist/sucrose.js +103 -735
- package/dist/sucrose.mjs +103 -728
- package/dist/trace.d.ts +16 -10
- package/dist/trace.js +20 -134
- package/dist/trace.mjs +22 -135
- package/dist/type/bridge-live.d.ts +5 -3
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +6 -3
- package/dist/type/bridge.d.ts +7 -5
- package/dist/type/bridge.js +38 -28
- package/dist/type/bridge.mjs +27 -22
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +53 -43
- package/dist/type/coerce-plan.mjs +56 -44
- package/dist/type/coerce.d.ts +2 -6
- package/dist/type/coerce.js +18 -79
- package/dist/type/coerce.mjs +20 -80
- package/dist/type/compat.js +10 -19
- package/dist/type/compat.mjs +12 -20
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/constants.mjs +1 -0
- package/dist/type/elysia/accelerate.mjs +1 -0
- package/dist/type/elysia/array-buffer.d.ts +6 -2
- package/dist/type/elysia/array-buffer.js +16 -15
- package/dist/type/elysia/array-buffer.mjs +17 -16
- package/dist/type/elysia/array-string.js +2 -43
- package/dist/type/elysia/array-string.mjs +3 -43
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +6 -9
- package/dist/type/elysia/boolean-string.mjs +1 -0
- package/dist/type/elysia/boolean.js +3 -13
- package/dist/type/elysia/boolean.mjs +4 -13
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +3 -14
- package/dist/type/elysia/cookie.mjs +4 -14
- package/dist/type/elysia/date.d.ts +2 -1
- package/dist/type/elysia/date.js +7 -14
- package/dist/type/elysia/date.mjs +8 -14
- package/dist/type/elysia/file-type.d.ts +2 -2
- package/dist/type/elysia/file-type.js +4 -3
- package/dist/type/elysia/file-type.mjs +5 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +3 -23
- package/dist/type/elysia/file.mjs +5 -10
- package/dist/type/elysia/files.js +1 -7
- package/dist/type/elysia/files.mjs +3 -8
- package/dist/type/elysia/form.mjs +1 -0
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +3 -28
- package/dist/type/elysia/integer-string.mjs +5 -29
- package/dist/type/elysia/integer.js +3 -13
- package/dist/type/elysia/integer.mjs +4 -13
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +1 -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 +47 -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 +54 -0
- package/dist/type/elysia/maybe-empty.mjs +1 -0
- package/dist/type/elysia/no-validate.mjs +1 -0
- package/dist/type/elysia/nullable.mjs +1 -0
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -12
- package/dist/type/elysia/number.mjs +19 -12
- package/dist/type/elysia/numeric-enum.d.ts +5 -3
- package/dist/type/elysia/numeric-enum.js +1 -5
- package/dist/type/elysia/numeric-enum.mjs +2 -5
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +17 -14
- package/dist/type/elysia/numeric.mjs +17 -14
- package/dist/type/elysia/object-string.js +2 -40
- package/dist/type/elysia/object-string.mjs +3 -40
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +6 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +8 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +19 -0
- package/dist/type/elysia/problem.mjs +19 -0
- package/dist/type/elysia/string.mjs +1 -0
- package/dist/type/elysia/uint8-array.d.ts +2 -1
- package/dist/type/elysia/uint8-array.js +4 -18
- package/dist/type/elysia/uint8-array.mjs +5 -18
- package/dist/type/elysia/union-enum.js +5 -6
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +1 -5
- package/dist/type/elysia/utils.d.ts +4 -6
- package/dist/type/elysia/utils.js +16 -40
- package/dist/type/elysia/utils.mjs +15 -36
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +13 -1
- package/dist/type/exports.mjs +5 -2
- package/dist/type/index.d.ts +1 -1
- package/dist/type/index.js +31 -23
- package/dist/type/index.mjs +33 -24
- package/dist/type/shared.d.ts +12 -10
- package/dist/type/shared.js +75 -109
- package/dist/type/shared.mjs +72 -108
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +7 -0
- package/dist/type/sync-require.mjs +6 -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 +4 -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 +24 -0
- package/dist/type/typebox-type-live.d.ts +6 -4
- package/dist/type/typebox-type-live.js +23 -9
- package/dist/type/typebox-type-live.mjs +11 -6
- package/dist/type/typebox-type.d.ts +14 -4
- package/dist/type/typebox-type.js +85 -22
- package/dist/type/typebox-type.mjs +35 -21
- package/dist/type/typebox-value-live.d.ts +5 -3
- package/dist/type/typebox-value-live.js +7 -3
- package/dist/type/typebox-value-live.mjs +6 -3
- 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 +6 -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 +15 -10
- package/dist/type/typebox-value.js +19 -8
- package/dist/type/typebox-value.mjs +19 -9
- package/dist/type/types.d.ts +1 -1
- package/dist/type/types.mjs +1 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +2 -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 +17 -10
- package/dist/type/validator/custom-error.js +50 -48
- package/dist/type/validator/custom-error.mjs +51 -48
- package/dist/type/validator/default-precompute.d.ts +10 -2
- package/dist/type/validator/default-precompute.js +33 -77
- package/dist/type/validator/default-precompute.mjs +33 -77
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +15 -0
- package/dist/type/validator/exact-mirror-live.mjs +11 -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 +15 -7
- package/dist/type/validator/exact-mirror.mjs +17 -7
- package/dist/type/validator/frozen-check.js +7 -8
- package/dist/type/validator/frozen-check.mjs +9 -9
- package/dist/type/validator/index.d.ts +2 -1
- package/dist/type/validator/index.js +149 -168
- package/dist/type/validator/index.mjs +155 -173
- package/dist/type/validator/string-codec-aot.d.ts +3 -2
- package/dist/type/validator/string-codec-aot.js +11 -7
- package/dist/type/validator/string-codec-aot.mjs +11 -7
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +49 -37
- package/dist/type/validator/validator-cache.mjs +49 -36
- package/dist/types.d.ts +362 -163
- package/dist/types.mjs +1 -0
- package/dist/universal/constants.mjs +1 -0
- 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 +7 -19
- package/dist/universal/file.mjs +9 -19
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/index.mjs +1 -0
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +3 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/universal/server.mjs +1 -0
- package/dist/utils.d.ts +62 -22
- package/dist/utils.js +342 -277
- package/dist/utils.mjs +327 -273
- package/dist/validator/index.d.ts +3 -3
- package/dist/validator/index.js +20 -34
- package/dist/validator/index.mjs +23 -36
- package/dist/validator/route.d.ts +3 -10
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +3 -1
- package/dist/ws/context.d.ts +4 -1
- package/dist/ws/context.js +41 -36
- package/dist/ws/context.mjs +41 -36
- package/dist/ws/index.mjs +1 -0
- package/dist/ws/parser.js +12 -22
- package/dist/ws/parser.mjs +13 -22
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +292 -222
- package/dist/ws/route.mjs +299 -228
- package/dist/ws/types.d.ts +4 -5
- package/dist/ws/types.mjs +1 -0
- package/package.json +22 -55
- 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,7 +1,8 @@
|
|
|
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');
|
|
4
3
|
const require_utils = require('../../utils.js');
|
|
4
|
+
const require_type_bridge = require('../../type/bridge.js');
|
|
5
|
+
const require_universal_is_production = require('../../universal/is-production.js');
|
|
5
6
|
const require_adapter_web_standard_index = require('../web-standard/index.js');
|
|
6
7
|
const require_generation = require('../../generation.js');
|
|
7
8
|
const require_adapter_origin = require('../origin.js');
|
|
@@ -9,15 +10,48 @@ const require_compile_handler_index = require('../../compile/handler/index.js');
|
|
|
9
10
|
const require_route_table = require('../../route-table.js');
|
|
10
11
|
|
|
11
12
|
//#region src/adapter/bun/index.ts
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
function runLifecycle(epoch, callback, ...args) {
|
|
14
|
+
const invoking = epoch.invoking;
|
|
15
|
+
epoch.invoking = true;
|
|
16
|
+
try {
|
|
17
|
+
return callback(...args);
|
|
18
|
+
} finally {
|
|
19
|
+
epoch.invoking = invoking;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const unavailableFetch = () => new Response(null, {
|
|
23
|
+
headers: { connection: "close" },
|
|
24
|
+
status: 503
|
|
25
|
+
});
|
|
26
|
+
function releaseLifecycle(app, ext, createdExt, stop, registerCleanup) {
|
|
27
|
+
if (ext.stop === stop) delete ext.stop;
|
|
28
|
+
if (ext.cleanupEpoch === registerCleanup) delete ext.cleanupEpoch;
|
|
29
|
+
if (createdExt && app["~ext"] === ext && !Object.keys(ext).length) app["~ext"] = void 0;
|
|
30
|
+
}
|
|
31
|
+
async function waitForServerRequests(server, abandoned) {
|
|
32
|
+
while (server.pendingRequests && !abandoned()) await Bun.sleep(1);
|
|
33
|
+
}
|
|
34
|
+
async function settleServerWebSockets(lifecycle, errors) {
|
|
35
|
+
if (!lifecycle) return true;
|
|
36
|
+
lifecycle.closing = true;
|
|
37
|
+
let failed = false;
|
|
38
|
+
do {
|
|
39
|
+
for (const socket of lifecycle.sockets) if (socket.readyState < 3) try {
|
|
40
|
+
socket.terminate();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
errors.push(error);
|
|
43
|
+
failed = true;
|
|
44
|
+
}
|
|
45
|
+
if (failed) return false;
|
|
46
|
+
await Bun.sleep(1);
|
|
47
|
+
const abandon = lifecycle.abandon === true;
|
|
48
|
+
for (const socket of lifecycle.sockets) if (abandon || require_utils.isSocketQuiet(socket)) {
|
|
49
|
+
delete socket.data["~lifecycleRun"];
|
|
50
|
+
lifecycle.sockets.delete(socket);
|
|
51
|
+
}
|
|
52
|
+
} while (lifecycle.sockets.size);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
21
55
|
const withOrigin = (fetch) => (request, server) => {
|
|
22
56
|
require_adapter_origin.origin.request = request;
|
|
23
57
|
try {
|
|
@@ -26,102 +60,177 @@ const withOrigin = (fetch) => (request, server) => {
|
|
|
26
60
|
require_adapter_origin.origin.request = void 0;
|
|
27
61
|
}
|
|
28
62
|
};
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
63
|
+
const isNativeStaticMethod = (method) => method === "GET" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "HEAD" || method === "OPTIONS";
|
|
64
|
+
function expandOptional(path) {
|
|
65
|
+
const at = path.indexOf("?");
|
|
66
|
+
if (at === -1) return [path];
|
|
67
|
+
const start = path.lastIndexOf("/", at);
|
|
68
|
+
const rest = path.slice(at + 1);
|
|
69
|
+
return [...expandOptional(path.slice(0, start) + rest), ...expandOptional(path.slice(0, at) + rest)].map((variant) => variant || "/");
|
|
70
|
+
}
|
|
71
|
+
function isNativePath(path) {
|
|
72
|
+
const names = /* @__PURE__ */ new Set();
|
|
73
|
+
const segments = path.split("/");
|
|
74
|
+
for (let i = 0; i < segments.length; i++) {
|
|
75
|
+
const segment = segments[i];
|
|
76
|
+
if (segment.indexOf("*") !== -1) {
|
|
77
|
+
if (segment !== "*" || i !== segments.length - 1) return false;
|
|
78
|
+
} else if (segment.indexOf(":") !== -1) {
|
|
79
|
+
if (!/^:[A-Za-z_$][\w$]*$/.test(segment)) return false;
|
|
80
|
+
if (names.has(segment)) return false;
|
|
81
|
+
names.add(segment);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
function collectHTMLBundleRoutes(app, handoff, routes) {
|
|
87
|
+
let dynamic;
|
|
88
|
+
let bundles;
|
|
89
|
+
const table = app["~generation"]?.routeTable;
|
|
90
|
+
if (table && !table.handler.some((h, i) => isNativeStaticMethod(table.method[i]) && require_utils.isHTMLBundle(h))) return routes;
|
|
91
|
+
const declared = table ? table.method.map((_, i) => require_route_table.routeRow(table, i)) : app["~routes"];
|
|
92
|
+
for (const route of declared) {
|
|
93
|
+
const [method, path, handler] = route;
|
|
94
|
+
if (!isNativeStaticMethod(method) || !require_utils.isHTMLBundle(handler)) continue;
|
|
95
|
+
if (path.indexOf(":") !== -1 || path.indexOf("*") !== -1) {
|
|
96
|
+
if (!handoff) continue;
|
|
97
|
+
(dynamic ??= /* @__PURE__ */ new Set()).add(method);
|
|
98
|
+
(bundles ??= []).push([
|
|
99
|
+
method,
|
|
100
|
+
path,
|
|
101
|
+
handler
|
|
102
|
+
]);
|
|
103
|
+
} else ((routes ??= require_utils.nullObject())[path] ??= require_utils.nullObject())[method] = handler;
|
|
104
|
+
if (!require_universal_is_production.isProduction() && (route[4] || route[5] || route[6])) console.warn(`[Elysia] ${method} ${path} is an HTML bundle served natively, hooks do not run for it`);
|
|
105
|
+
}
|
|
106
|
+
if (!dynamic) return routes;
|
|
107
|
+
const strictPath = app["~config"]?.strictPath === true;
|
|
108
|
+
const handoffs = [];
|
|
109
|
+
for (const [method, path, handler] of declared) {
|
|
110
|
+
if (require_utils.isHTMLBundle(handler)) continue;
|
|
111
|
+
const targets = method === "*" ? dynamic : dynamic.has(method) ? [method] : void 0;
|
|
112
|
+
if (!targets) continue;
|
|
113
|
+
for (const variant of expandOptional(path)) {
|
|
114
|
+
const loose = strictPath || variant.endsWith("*") ? variant : require_utils.getLoosePath(variant);
|
|
115
|
+
for (const raw of loose === variant ? [variant] : [variant, loose]) {
|
|
116
|
+
if (!isNativePath(raw)) {
|
|
117
|
+
if (!require_universal_is_production.isProduction()) console.warn(`[Elysia] ${method} ${path} cannot be expressed in Bun's router, so :param / * HTML bundles are not served natively (they would shadow it)`);
|
|
118
|
+
return routes;
|
|
119
|
+
}
|
|
120
|
+
const encoded = encodeURI(raw);
|
|
121
|
+
for (const target of targets) {
|
|
122
|
+
if (!/[^ -~]/.test(raw)) handoffs.push([raw, target]);
|
|
123
|
+
if (encoded !== raw) handoffs.push([encoded, target]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const [method, path, bundle] of bundles) ((routes ??= require_utils.nullObject())[path] ??= require_utils.nullObject())[method] = bundle;
|
|
129
|
+
for (const [key, method] of handoffs) (routes[key] ??= require_utils.nullObject())[method] ??= handoff;
|
|
130
|
+
return routes;
|
|
131
|
+
}
|
|
38
132
|
function collectStaticRoutes(app) {
|
|
39
|
-
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
40
133
|
app.fetch;
|
|
41
134
|
const frozenRoot = require_generation.frozenRootOf(app);
|
|
42
135
|
const fetchLevelHook = require_utils.flattenChain(frozenRoot["~hookChain"]);
|
|
43
|
-
|
|
136
|
+
const promoteResponses = app["~config"]?.nativeStaticResponse !== false && !fetchLevelHook?.request?.length && !fetchLevelHook?.trace?.length && !frozenRoot["~ext"]?.hoc?.length;
|
|
44
137
|
const table = app["~generation"]?.routeTable ?? app["~routeTable"];
|
|
45
138
|
const length = table?.length ?? 0;
|
|
46
139
|
if (!table || !length) return;
|
|
47
|
-
const methods = table
|
|
48
|
-
const
|
|
49
|
-
const
|
|
140
|
+
const { method: methods, path: paths, handler: handlers, flags } = table;
|
|
141
|
+
const isStatic = (i) => isNativeStaticMethod(methods[i]) && (flags[i] & require_route_table.RouteFlag.Dynamic) === 0;
|
|
142
|
+
const isPromotable = (h) => promoteResponses && typeof h !== "function" && !(h instanceof Error) && !(h instanceof Promise);
|
|
50
143
|
let hasCandidate = false;
|
|
51
144
|
for (let i = 0; i < length; i++) {
|
|
145
|
+
if (!isStatic(i)) continue;
|
|
52
146
|
const h = handlers[i];
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
147
|
+
if (require_utils.isHTMLBundle(h) || isPromotable(h)) {
|
|
148
|
+
hasCandidate = true;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
57
151
|
}
|
|
58
152
|
if (!hasCandidate) return;
|
|
59
|
-
const ready = require_utils.nullObject();
|
|
60
153
|
const strictPath = frozenRoot["~config"]?.strictPath === true;
|
|
61
|
-
const
|
|
62
|
-
for (let i = 0; i < length; i++)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (require_constants.needEncodeRegex.test(path)) {
|
|
73
|
-
const encoded = encodeURI(path);
|
|
74
|
-
if (encoded !== path) set.add(encoded);
|
|
75
|
-
}
|
|
154
|
+
const routeIndex = /* @__PURE__ */ new Map();
|
|
155
|
+
for (let i = 0; i < length; i++) {
|
|
156
|
+
if (!isStatic(i)) continue;
|
|
157
|
+
const method = methods[i];
|
|
158
|
+
const path = paths[i];
|
|
159
|
+
let pathsByMethod = routeIndex.get(method);
|
|
160
|
+
if (!pathsByMethod) routeIndex.set(method, pathsByMethod = /* @__PURE__ */ new Map());
|
|
161
|
+
pathsByMethod.set(path, i);
|
|
162
|
+
if (!strictPath && (flags[i] & require_route_table.RouteFlag.Encode) !== 0) {
|
|
163
|
+
const encoded = encodeURI(path);
|
|
164
|
+
if (encoded !== path && !pathsByMethod.has(encoded)) pathsByMethod.set(encoded, -1);
|
|
76
165
|
}
|
|
77
166
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
167
|
+
const ready = require_utils.nullObject();
|
|
168
|
+
let hasReady = false;
|
|
169
|
+
const add = (method, path, value, needsEncode) => {
|
|
170
|
+
if (needsEncode) path = encodeURI(path);
|
|
80
171
|
(ready[path] ??= require_utils.nullObject())[method] = value;
|
|
172
|
+
hasReady = true;
|
|
81
173
|
};
|
|
82
174
|
for (let i = 0; i < length; i++) {
|
|
175
|
+
if (!isStatic(i)) continue;
|
|
83
176
|
const method = methods[i];
|
|
84
|
-
|
|
177
|
+
const pathsByMethod = routeIndex.get(method);
|
|
85
178
|
const path = paths[i];
|
|
86
|
-
if (
|
|
87
|
-
if (!nativeStaticMethods.has(method)) continue;
|
|
179
|
+
if (pathsByMethod.get(path) !== i) continue;
|
|
88
180
|
const h = handlers[i];
|
|
89
|
-
|
|
90
|
-
|
|
181
|
+
let value;
|
|
182
|
+
if (require_utils.isHTMLBundle(h)) value = h;
|
|
183
|
+
else if (!isPromotable(h)) continue;
|
|
184
|
+
else value = require_compile_handler_index.buildNativeStaticResponse(require_route_table.routeRow(table, i), app);
|
|
91
185
|
if (!value) continue;
|
|
92
|
-
|
|
93
|
-
|
|
186
|
+
const needsEncode = (flags[i] & require_route_table.RouteFlag.Encode) !== 0;
|
|
187
|
+
add(method, path, value, needsEncode);
|
|
188
|
+
if (!strictPath) {
|
|
94
189
|
const loose = require_utils.getLoosePath(path);
|
|
95
|
-
if (loose !== path && !
|
|
190
|
+
if (loose !== path && !pathsByMethod.has(loose)) add(method, loose, value, needsEncode);
|
|
96
191
|
}
|
|
97
192
|
}
|
|
98
|
-
if (!
|
|
99
|
-
return
|
|
193
|
+
if (!hasReady) return;
|
|
194
|
+
return ready;
|
|
100
195
|
}
|
|
101
196
|
const BunAdapter = require_adapter_index.createAdapter({
|
|
102
|
-
name: "bun",
|
|
103
|
-
runtime: "bun",
|
|
104
|
-
isWebStandard: true,
|
|
105
197
|
parse: require_adapter_web_standard_index.WebStandardAdapter.parse,
|
|
106
198
|
response: require_adapter_web_standard_index.WebStandardAdapter.response,
|
|
107
199
|
listen(app, options, callback) {
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
200
|
+
if (app.server || app["~ext"]?.stop) throw new Error("[Elysia] Cannot call listen() while a server or teardown is active");
|
|
201
|
+
const requestReady = Promise.withResolvers();
|
|
202
|
+
function gatedFetch(request, server) {
|
|
203
|
+
return live && !cancelled ? live(request, server) : requestReady.promise.then(() => {
|
|
204
|
+
if (cancelled || !live) return unavailableFetch();
|
|
205
|
+
return live(request, server);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
const _options = typeof options === "object" ? {
|
|
209
|
+
...options,
|
|
210
|
+
fetch: gatedFetch
|
|
211
|
+
} : {
|
|
116
212
|
port: +options,
|
|
117
213
|
fetch: gatedFetch
|
|
118
214
|
};
|
|
119
|
-
|
|
215
|
+
const _config = app["~config"]?.serve;
|
|
120
216
|
const serve = _config ? {
|
|
121
217
|
..._config,
|
|
122
218
|
..._options
|
|
123
219
|
} : _options;
|
|
124
|
-
|
|
220
|
+
const handoff = (request, server) => serve.fetch(request, server);
|
|
221
|
+
const htmlRoutes = collectHTMLBundleRoutes(app, app.pending ? void 0 : handoff);
|
|
222
|
+
const server = app.server = Bun.serve(serve.routes || serve.error || htmlRoutes ? {
|
|
223
|
+
...serve,
|
|
224
|
+
error: unavailableFetch,
|
|
225
|
+
routes: htmlRoutes ?? {}
|
|
226
|
+
} : serve);
|
|
227
|
+
let live;
|
|
228
|
+
let cancelled = false;
|
|
229
|
+
let shutdownAttempt;
|
|
230
|
+
let wsLifecycle;
|
|
231
|
+
let modulesReady;
|
|
232
|
+
let pendingSetups;
|
|
233
|
+
let setupsSettled;
|
|
125
234
|
const build = () => {
|
|
126
235
|
const fetch = app.fetch;
|
|
127
236
|
let routes;
|
|
@@ -130,11 +239,22 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
130
239
|
} catch (error) {
|
|
131
240
|
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
132
241
|
}
|
|
242
|
+
routes = collectHTMLBundleRoutes(app, handoff, routes);
|
|
133
243
|
let websocket;
|
|
134
244
|
if (app["~hasWS"]) {
|
|
135
245
|
const resolved = require_generation.resolvedWsOf(app);
|
|
136
246
|
if (!resolved) throw new Error("[Elysia] internal: WebSocket routes are present but no capability provider was resolved");
|
|
137
|
-
|
|
247
|
+
const handler = resolved.provider.buildGlobalWSHandler();
|
|
248
|
+
websocket = resolved.config ? Object.assign(handler, resolved.config) : handler;
|
|
249
|
+
const setter = Object.getOwnPropertyDescriptor(handler, "~lifecycle")?.set;
|
|
250
|
+
if (setter) {
|
|
251
|
+
wsLifecycle = {
|
|
252
|
+
closing: false,
|
|
253
|
+
sockets: /* @__PURE__ */ new Set(),
|
|
254
|
+
run: runLifecycle.bind(null, epoch)
|
|
255
|
+
};
|
|
256
|
+
setter.call(handler, wsLifecycle);
|
|
257
|
+
}
|
|
138
258
|
}
|
|
139
259
|
return {
|
|
140
260
|
fetch,
|
|
@@ -142,75 +262,292 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
142
262
|
websocket
|
|
143
263
|
};
|
|
144
264
|
};
|
|
145
|
-
let
|
|
146
|
-
|
|
147
|
-
const
|
|
265
|
+
let startupFailure;
|
|
266
|
+
let forceRequested = false;
|
|
267
|
+
const force = Promise.withResolvers();
|
|
268
|
+
const abandon = Promise.withResolvers();
|
|
269
|
+
let forceDone = false;
|
|
270
|
+
let nativeStopped = false;
|
|
271
|
+
let abandoned = false;
|
|
272
|
+
let published = false;
|
|
273
|
+
let cleanupCompleted = false;
|
|
274
|
+
let idleRequired = false;
|
|
275
|
+
let cleanupFailures;
|
|
276
|
+
let observedOutcome;
|
|
277
|
+
let persistentCleanup;
|
|
278
|
+
let persistentCleanupLength = -1;
|
|
279
|
+
const epochCleanup = [];
|
|
280
|
+
const createdExt = app["~ext"] === void 0;
|
|
281
|
+
const ext = app["~ext"] ??= require_utils.nullObject();
|
|
282
|
+
const epoch = {
|
|
283
|
+
setup: false,
|
|
284
|
+
invoking: false
|
|
285
|
+
};
|
|
286
|
+
const snapshotCleanup = () => {
|
|
287
|
+
if (persistentCleanupLength !== -1) return;
|
|
288
|
+
persistentCleanup = ext.cleanup;
|
|
289
|
+
persistentCleanupLength = persistentCleanup?.length ?? 0;
|
|
290
|
+
};
|
|
291
|
+
const registerCleanup = (handler) => {
|
|
292
|
+
if (ext.cleanupEpoch !== registerCleanup) return false;
|
|
293
|
+
if (!epoch.setup) throw new Error("[Elysia] .onStop() called after its onStart epoch settled");
|
|
294
|
+
if (Array.isArray(handler)) epochCleanup.push(...handler);
|
|
295
|
+
else epochCleanup.push(handler);
|
|
296
|
+
return true;
|
|
297
|
+
};
|
|
298
|
+
const gate = () => {
|
|
299
|
+
if (!published) return;
|
|
300
|
+
live = void 0;
|
|
301
|
+
if (wsLifecycle) wsLifecycle.closing = true;
|
|
148
302
|
try {
|
|
149
|
-
server.reload(
|
|
303
|
+
server.reload({
|
|
304
|
+
...serve,
|
|
305
|
+
fetch: unavailableFetch,
|
|
306
|
+
error: unavailableFetch,
|
|
307
|
+
routes: {}
|
|
308
|
+
});
|
|
150
309
|
} catch (error) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
310
|
+
return { error };
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const nativeStop = async (closeActiveConnections, errors) => {
|
|
314
|
+
try {
|
|
315
|
+
const stopping = server.stop(closeActiveConnections);
|
|
316
|
+
await (closeActiveConnections ? stopping : Promise.race([stopping, force.promise]));
|
|
317
|
+
if (!closeActiveConnections && forceRequested && !forceDone) return false;
|
|
318
|
+
nativeStopped = true;
|
|
319
|
+
if (closeActiveConnections) {
|
|
320
|
+
forceDone = true;
|
|
321
|
+
forceRequested = false;
|
|
322
|
+
}
|
|
323
|
+
return true;
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (closeActiveConnections) forceRequested = true;
|
|
326
|
+
errors.push(error);
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
const isAbandoned = () => abandoned;
|
|
331
|
+
const quiesce = async (force) => {
|
|
332
|
+
const errors = [];
|
|
333
|
+
if (!published) return {
|
|
334
|
+
errors,
|
|
335
|
+
releasable: await nativeStop(true, errors),
|
|
336
|
+
safe: true
|
|
337
|
+
};
|
|
338
|
+
if (force && !idleRequired && !wsLifecycle?.closing) {
|
|
339
|
+
const stopped = await nativeStop(true, errors);
|
|
340
|
+
return {
|
|
341
|
+
errors,
|
|
342
|
+
releasable: stopped,
|
|
343
|
+
safe: stopped
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
const gateFailure = gate();
|
|
347
|
+
if (gateFailure) errors.push(gateFailure.error);
|
|
348
|
+
let socketsSettled = await settleServerWebSockets(wsLifecycle, errors);
|
|
349
|
+
await Promise.resolve();
|
|
350
|
+
let close = forceRequested || gateFailure !== void 0 || !socketsSettled;
|
|
351
|
+
if (!close && nativeStopped) await waitForServerRequests(server, isAbandoned);
|
|
352
|
+
idleRequired = true;
|
|
353
|
+
let stopped = true;
|
|
354
|
+
while (!nativeStopped || forceRequested && !forceDone) {
|
|
355
|
+
if (nativeStopped) close = true;
|
|
356
|
+
stopped = await nativeStop(close, errors);
|
|
357
|
+
if (stopped) {
|
|
358
|
+
if (socketsSettled) socketsSettled = await settleServerWebSockets(wsLifecycle, errors);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (close) break;
|
|
362
|
+
await waitForServerRequests(server, isAbandoned);
|
|
363
|
+
close = true;
|
|
364
|
+
}
|
|
365
|
+
let idleClosed = true;
|
|
366
|
+
if (idleRequired) {
|
|
367
|
+
const closeIdle = server.closeIdleConnections;
|
|
368
|
+
if (closeIdle) try {
|
|
369
|
+
closeIdle.call(server);
|
|
370
|
+
} catch (error) {
|
|
371
|
+
errors.push(error);
|
|
372
|
+
idleClosed = false;
|
|
159
373
|
}
|
|
374
|
+
if (idleClosed && !gateFailure) idleRequired = false;
|
|
160
375
|
}
|
|
376
|
+
const safe = socketsSettled && stopped && idleClosed && (!gateFailure || forceDone);
|
|
377
|
+
return {
|
|
378
|
+
errors,
|
|
379
|
+
releasable: safe,
|
|
380
|
+
safe
|
|
381
|
+
};
|
|
161
382
|
};
|
|
162
383
|
const setup = () => {
|
|
163
|
-
|
|
384
|
+
snapshotCleanup();
|
|
385
|
+
const onSetup = ext.setup;
|
|
164
386
|
if (!onSetup) return;
|
|
165
|
-
|
|
387
|
+
epoch.setup = true;
|
|
388
|
+
ext.cleanupEpoch = registerCleanup;
|
|
166
389
|
for (let i = 0; i < onSetup.length; i++) {
|
|
167
|
-
|
|
168
|
-
|
|
390
|
+
if (cancelled) break;
|
|
391
|
+
try {
|
|
392
|
+
const result = runLifecycle(epoch, onSetup[i], app);
|
|
393
|
+
if (result && typeof result.then === "function") (pendingSetups ??= []).push(Promise.resolve(result));
|
|
394
|
+
} catch (error) {
|
|
395
|
+
if (!pendingSetups) epoch.setup = false;
|
|
396
|
+
stop(true, { error }).catch(() => {});
|
|
397
|
+
throw error;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (pendingSetups) {
|
|
401
|
+
setupsSettled = Promise.allSettled(pendingSetups);
|
|
402
|
+
return Promise.all(pendingSetups).then(() => epoch.setup = false);
|
|
169
403
|
}
|
|
170
|
-
|
|
404
|
+
epoch.setup = false;
|
|
171
405
|
};
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
406
|
+
const stop = (closeActiveConnections, failure) => {
|
|
407
|
+
const reentrant = epoch.invoking;
|
|
408
|
+
if (failure) startupFailure ??= failure;
|
|
409
|
+
if (closeActiveConnections === true) {
|
|
410
|
+
force.resolve();
|
|
411
|
+
if (!failure) abandon.resolve();
|
|
412
|
+
if (!forceDone) forceRequested = true;
|
|
413
|
+
}
|
|
414
|
+
cancelled = true;
|
|
415
|
+
requestReady.resolve();
|
|
416
|
+
if (app.server === server) app.server = void 0;
|
|
417
|
+
let outcome;
|
|
418
|
+
if (shutdownAttempt) {
|
|
419
|
+
if (closeActiveConnections === true && !forceDone) {
|
|
420
|
+
abandoned = true;
|
|
421
|
+
if (wsLifecycle) wsLifecycle.abandon = true;
|
|
422
|
+
}
|
|
423
|
+
outcome = shutdownAttempt;
|
|
424
|
+
} else {
|
|
425
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
426
|
+
outcome = shutdownAttempt = promise;
|
|
427
|
+
const quiescence = quiesce(forceRequested || !published);
|
|
428
|
+
let releasable = false;
|
|
429
|
+
let abandonedSetups;
|
|
430
|
+
(async () => {
|
|
431
|
+
try {
|
|
432
|
+
await Promise.resolve();
|
|
433
|
+
if (modulesReady) try {
|
|
434
|
+
await Promise.race([modulesReady, force.promise]);
|
|
435
|
+
} catch (error) {
|
|
436
|
+
startupFailure ??= { error };
|
|
437
|
+
}
|
|
438
|
+
if (setupsSettled) {
|
|
439
|
+
const setupResults = await Promise.race([setupsSettled, abandon.promise]);
|
|
440
|
+
if (!setupResults) abandonedSetups = setupsSettled;
|
|
441
|
+
else if (!startupFailure) for (let i = 0; i < setupResults.length; i++) {
|
|
442
|
+
const result = setupResults[i];
|
|
443
|
+
if (result.status === "rejected") {
|
|
444
|
+
startupFailure = { error: result.reason };
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
epoch.setup = false;
|
|
450
|
+
const errors = [];
|
|
451
|
+
const quiesced = await quiescence;
|
|
452
|
+
if (startupFailure) errors.push(startupFailure.error);
|
|
453
|
+
errors.push(...quiesced.errors);
|
|
454
|
+
releasable = quiesced.releasable;
|
|
455
|
+
if (!quiesced.safe) {
|
|
456
|
+
if (cleanupFailures) errors.push(...cleanupFailures);
|
|
457
|
+
require_utils.throwLifecycleErrors(errors);
|
|
458
|
+
}
|
|
459
|
+
if (!cleanupCompleted) {
|
|
460
|
+
snapshotCleanup();
|
|
461
|
+
if (ext.stop === stop) {
|
|
462
|
+
const length = persistentCleanupLength + epochCleanup.length;
|
|
463
|
+
for (let n = 0; n < length; n++) {
|
|
464
|
+
if (ext.stop !== stop) break;
|
|
465
|
+
const i = startupFailure ? length - 1 - n : n;
|
|
466
|
+
const handler = i < persistentCleanupLength ? persistentCleanup[i] : epochCleanup[i - persistentCleanupLength];
|
|
467
|
+
try {
|
|
468
|
+
await runLifecycle(epoch, handler, app);
|
|
469
|
+
} catch (error) {
|
|
470
|
+
(cleanupFailures ??= []).push(error);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
cleanupCompleted = true;
|
|
475
|
+
epochCleanup.length = 0;
|
|
476
|
+
}
|
|
477
|
+
if (cleanupFailures) errors.push(...cleanupFailures);
|
|
478
|
+
const release = () => releaseLifecycle(app, ext, createdExt, stop, registerCleanup);
|
|
479
|
+
if (releasable && abandonedSetups) abandonedSetups.then((results) => {
|
|
480
|
+
for (const result of results) if (result.status === "rejected") console.error("[Elysia] onStart abandoned by stop(true) failed:", result.reason);
|
|
481
|
+
release();
|
|
482
|
+
});
|
|
483
|
+
else if (releasable) release();
|
|
484
|
+
require_utils.throwLifecycleErrors(errors);
|
|
485
|
+
} finally {
|
|
486
|
+
epoch.setup = false;
|
|
487
|
+
if (!releasable) shutdownAttempt = void 0;
|
|
488
|
+
}
|
|
489
|
+
})().then(resolve, reject);
|
|
490
|
+
}
|
|
491
|
+
if (!reentrant) return outcome;
|
|
492
|
+
if (observedOutcome !== outcome) {
|
|
493
|
+
observedOutcome = outcome;
|
|
494
|
+
outcome.catch((error) => {
|
|
495
|
+
console.error("[Elysia] stop() failed:", error);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
return Promise.resolve();
|
|
189
499
|
};
|
|
500
|
+
ext.stop = stop;
|
|
190
501
|
const publish = () => {
|
|
191
|
-
if (app.server !== server)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
502
|
+
if (cancelled || app.server !== server) {
|
|
503
|
+
requestReady.resolve();
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
try {
|
|
507
|
+
const built = build();
|
|
508
|
+
live = serve.fetch = withOrigin(built.fetch);
|
|
509
|
+
published = true;
|
|
510
|
+
if (built.websocket) serve.websocket = built.websocket;
|
|
511
|
+
if (built.routes) serve.routes = built.routes;
|
|
512
|
+
try {
|
|
513
|
+
server.reload(serve);
|
|
514
|
+
} catch (error) {
|
|
515
|
+
if (!serve.routes) throw error;
|
|
516
|
+
delete serve.routes;
|
|
517
|
+
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
518
|
+
try {
|
|
519
|
+
server.reload(serve);
|
|
520
|
+
} catch (fallbackError) {
|
|
521
|
+
console.error("[Elysia] Failed to reload Bun server:", fallbackError);
|
|
522
|
+
throw fallbackError;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (callback) callback(server);
|
|
526
|
+
} catch (error) {
|
|
527
|
+
startupFailure ??= { error };
|
|
528
|
+
throw error;
|
|
529
|
+
}
|
|
530
|
+
requestReady.resolve();
|
|
198
531
|
};
|
|
199
532
|
const start = () => {
|
|
200
|
-
|
|
533
|
+
modulesReady = void 0;
|
|
534
|
+
if (cancelled || app.server !== server) {
|
|
535
|
+
requestReady.resolve();
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
201
538
|
const setupReady = setup();
|
|
202
|
-
if (setupReady
|
|
539
|
+
if (setupReady) return setupReady.then(publish);
|
|
203
540
|
publish();
|
|
204
541
|
};
|
|
205
542
|
try {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
543
|
+
const modules = modulesReady = app.modules;
|
|
544
|
+
const preload = require_type_bridge.preloadTypebox();
|
|
545
|
+
(preload ? Promise.all([modules, preload]) : modules).then(start).catch((error) => stop(true, { error })).catch((error) => {
|
|
209
546
|
console.error("[Elysia] listen() failed:", error);
|
|
210
|
-
|
|
547
|
+
if (typeof process !== "undefined") process.exitCode = 1;
|
|
211
548
|
});
|
|
212
549
|
} catch (error) {
|
|
213
|
-
|
|
550
|
+
stop(true, { error }).catch(console.error);
|
|
214
551
|
throw error;
|
|
215
552
|
}
|
|
216
553
|
}
|
|
@@ -218,4 +555,6 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
218
555
|
|
|
219
556
|
//#endregion
|
|
220
557
|
exports.BunAdapter = BunAdapter;
|
|
221
|
-
exports.
|
|
558
|
+
exports.collectHTMLBundleRoutes = collectHTMLBundleRoutes;
|
|
559
|
+
exports.collectStaticRoutes = collectStaticRoutes;
|
|
560
|
+
exports.isHTMLBundle = require_utils.isHTMLBundle;
|