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