elysia 2.0.0-beta.14 → 2.0.0-beta.16
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 +5 -2
- package/dist/adapter/bun/index.js +47 -40
- package/dist/adapter/bun/index.mjs +46 -41
- package/dist/adapter/utils.js +16 -21
- package/dist/adapter/utils.mjs +16 -21
- package/dist/base.d.ts +8 -0
- package/dist/base.js +106 -59
- package/dist/base.mjs +107 -60
- package/dist/compile/aot-capture.js +1 -1
- package/dist/compile/aot-capture.mjs +1 -1
- package/dist/compile/aot.js +14 -21
- package/dist/compile/aot.mjs +14 -21
- package/dist/compile/handler/frozen-validator.js +51 -42
- package/dist/compile/handler/frozen-validator.mjs +51 -42
- package/dist/compile/handler/index.js +57 -50
- package/dist/compile/handler/index.mjs +57 -50
- package/dist/compile/handler/jit.js +36 -26
- package/dist/compile/handler/jit.mjs +37 -27
- package/dist/compile/handler/params.js +2 -0
- package/dist/compile/handler/params.mjs +3 -1
- package/dist/compile/handler/utils.d.ts +2 -2
- package/dist/compile/handler/utils.js +115 -111
- package/dist/compile/handler/utils.mjs +115 -113
- package/dist/context.d.ts +3 -1
- package/dist/context.js +2 -0
- package/dist/context.mjs +3 -1
- package/dist/cookie/config.js +6 -7
- package/dist/cookie/config.mjs +6 -7
- package/dist/error.d.ts +6 -3
- package/dist/error.js +26 -28
- package/dist/error.mjs +26 -28
- package/dist/handler/fetch.js +2 -1
- package/dist/handler/fetch.mjs +3 -2
- package/dist/handler/utils.d.ts +3 -1
- package/dist/handler/utils.js +19 -1
- package/dist/handler/utils.mjs +17 -1
- package/dist/index.d.ts +3 -3
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +1 -1
- package/dist/plugin/aot/core.js +4 -0
- package/dist/plugin/aot/core.mjs +4 -0
- package/dist/sucrose.js +60 -59
- package/dist/sucrose.mjs +60 -59
- package/dist/trace.js +6 -9
- package/dist/trace.mjs +6 -9
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.js +1 -1
- package/dist/type/bridge-live.mjs +1 -1
- package/dist/type/bridge.d.ts +3 -3
- package/dist/type/coerce-plan.js +41 -36
- package/dist/type/coerce-plan.mjs +41 -36
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/cookie.js +8 -17
- package/dist/type/elysia/cookie.mjs +8 -17
- package/dist/type/elysia/date.js +6 -7
- package/dist/type/elysia/date.mjs +6 -7
- package/dist/type/elysia/numeric.js +8 -9
- package/dist/type/elysia/numeric.mjs +8 -9
- 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/exports.d.ts +3 -2
- package/dist/type/exports.js +2 -0
- package/dist/type/exports.mjs +2 -1
- package/dist/type/index.js +2 -0
- package/dist/type/index.mjs +2 -0
- package/dist/type/typebox-value-live.d.ts +2 -2
- package/dist/type/typebox-value-live.js +2 -2
- package/dist/type/typebox-value-live.mjs +2 -2
- package/dist/type/typebox-value.d.ts +6 -6
- package/dist/type/validator/clean-safe.d.ts +1 -2
- package/dist/type/validator/clean-safe.js +0 -2
- package/dist/type/validator/clean-safe.mjs +1 -2
- package/dist/type/validator/custom-error.js +37 -26
- package/dist/type/validator/custom-error.mjs +37 -26
- package/dist/type/validator/default-precompute.js +24 -26
- package/dist/type/validator/default-precompute.mjs +24 -26
- package/dist/type/validator/exact-mirror.js +6 -8
- package/dist/type/validator/exact-mirror.mjs +6 -8
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/index.js +64 -66
- package/dist/type/validator/index.mjs +65 -67
- package/dist/type/validator/validator-cache.d.ts +3 -3
- package/dist/type/validator/validator-cache.js +7 -10
- package/dist/type/validator/validator-cache.mjs +6 -9
- package/dist/types.d.ts +2 -1
- package/dist/universal/file.js +2 -6
- package/dist/universal/file.mjs +2 -6
- package/dist/utils.d.ts +10 -2
- package/dist/utils.js +85 -47
- package/dist/utils.mjs +82 -48
- package/dist/validator/index.js +14 -18
- package/dist/validator/index.mjs +14 -18
- package/dist/ws/context.js +9 -11
- package/dist/ws/context.mjs +9 -11
- package/dist/ws/parser.js +23 -20
- package/dist/ws/parser.mjs +23 -20
- package/dist/ws/route.js +76 -87
- package/dist/ws/route.mjs +76 -87
- package/package.json +5 -2
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { BunHTMLBundlelike } from "../../types.js";
|
|
1
2
|
import { AnyElysia } from "../../base.js";
|
|
2
3
|
import { ElysiaAdapterOptions } from "../types.js";
|
|
3
4
|
//#region src/adapter/bun/index.d.ts
|
|
4
|
-
declare
|
|
5
|
+
declare const isHTMLBundle: (value: unknown) => value is BunHTMLBundlelike;
|
|
6
|
+
declare function collectHTMLBundleRoutes(app: AnyElysia): Record<string, Record<string, BunHTMLBundlelike>> | undefined;
|
|
7
|
+
declare function collectStaticRoutes(app: AnyElysia): Record<string, Record<string, Response | BunHTMLBundlelike>> | undefined;
|
|
5
8
|
declare const BunAdapter: ElysiaAdapterOptions<void>;
|
|
6
9
|
//#endregion
|
|
7
|
-
export { BunAdapter, collectStaticRoutes };
|
|
10
|
+
export { BunAdapter, collectHTMLBundleRoutes, collectStaticRoutes, isHTMLBundle };
|
|
@@ -21,29 +21,11 @@ const unavailableFetch = () => new Response(null, {
|
|
|
21
21
|
headers: { connection: "close" },
|
|
22
22
|
status: 503
|
|
23
23
|
});
|
|
24
|
-
function reloadServer(server, serve) {
|
|
25
|
-
try {
|
|
26
|
-
server.reload(serve);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
if (!serve.routes) throw error;
|
|
29
|
-
delete serve.routes;
|
|
30
|
-
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
31
|
-
try {
|
|
32
|
-
server.reload(serve);
|
|
33
|
-
} catch (fallbackError) {
|
|
34
|
-
console.error("[Elysia] Failed to reload Bun server:", fallbackError);
|
|
35
|
-
throw fallbackError;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
24
|
function releaseLifecycle(app, ext, createdExt, stop, registerCleanup) {
|
|
40
25
|
if (ext.stop === stop) delete ext.stop;
|
|
41
26
|
if (ext.cleanupEpoch === registerCleanup) delete ext.cleanupEpoch;
|
|
42
27
|
if (createdExt && app["~ext"] === ext && !Object.keys(ext).length) app["~ext"] = void 0;
|
|
43
28
|
}
|
|
44
|
-
function clearAppServer(app, server) {
|
|
45
|
-
if (app.server === server) app.server = void 0;
|
|
46
|
-
}
|
|
47
29
|
async function waitForServerRequests(server, abandoned) {
|
|
48
30
|
while (server.pendingRequests && !abandoned()) await Bun.sleep(1);
|
|
49
31
|
}
|
|
@@ -68,17 +50,6 @@ async function settleServerWebSockets(lifecycle, errors) {
|
|
|
68
50
|
} while (lifecycle.sockets.size);
|
|
69
51
|
return true;
|
|
70
52
|
}
|
|
71
|
-
const closeServerIdle = (server, errors) => {
|
|
72
|
-
const close = server.closeIdleConnections;
|
|
73
|
-
if (!close) return true;
|
|
74
|
-
try {
|
|
75
|
-
close.call(server);
|
|
76
|
-
return true;
|
|
77
|
-
} catch (error) {
|
|
78
|
-
errors.push(error);
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
53
|
/**
|
|
83
54
|
* ! This may looks like it would cause race condition, but it is not
|
|
84
55
|
* Bun is single-threaded and synchronous, so the `finally` block will
|
|
@@ -97,12 +68,20 @@ const withOrigin = (fetch) => (request, server) => {
|
|
|
97
68
|
}
|
|
98
69
|
};
|
|
99
70
|
const isNativeStaticMethod = (method) => method === "GET" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "HEAD" || method === "OPTIONS";
|
|
71
|
+
const isHTMLBundle = (value) => typeof value === "object" && value !== null && typeof value.index === "string";
|
|
72
|
+
function collectHTMLBundleRoutes(app) {
|
|
73
|
+
let routes;
|
|
74
|
+
for (const [method, path, handler] of app["~routes"]) {
|
|
75
|
+
if (!isNativeStaticMethod(method) || !isHTMLBundle(handler) || path.indexOf(":") !== -1 || path.indexOf("*") !== -1) continue;
|
|
76
|
+
((routes ??= require_utils.nullObject())[path] ??= require_utils.nullObject())[method] = handler;
|
|
77
|
+
}
|
|
78
|
+
return routes;
|
|
79
|
+
}
|
|
100
80
|
function collectStaticRoutes(app) {
|
|
101
|
-
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
102
81
|
app.fetch;
|
|
103
82
|
const frozenRoot = require_generation.frozenRootOf(app);
|
|
104
83
|
const fetchLevelHook = require_utils.flattenChain(frozenRoot["~hookChain"]);
|
|
105
|
-
|
|
84
|
+
const promoteResponses = app["~config"]?.nativeStaticResponse !== false && !fetchLevelHook?.request?.length && !fetchLevelHook?.trace?.length && !frozenRoot["~ext"]?.hoc?.length;
|
|
106
85
|
const table = app["~generation"]?.routeTable ?? app["~routeTable"];
|
|
107
86
|
const length = table?.length ?? 0;
|
|
108
87
|
if (!table || !length) return;
|
|
@@ -111,7 +90,7 @@ function collectStaticRoutes(app) {
|
|
|
111
90
|
for (let i = 0; i < length; i++) {
|
|
112
91
|
if (!isNativeStaticMethod(methods[i]) || (flags[i] & require_route_table.RouteFlag.Dynamic) !== 0) continue;
|
|
113
92
|
const h = handlers[i];
|
|
114
|
-
if (typeof h !== "function" && !(h instanceof Error) && !(h instanceof Promise)) {
|
|
93
|
+
if (isHTMLBundle(h) || promoteResponses && typeof h !== "function" && !(h instanceof Error) && !(h instanceof Promise)) {
|
|
115
94
|
hasCandidate = true;
|
|
116
95
|
break;
|
|
117
96
|
}
|
|
@@ -146,8 +125,10 @@ function collectStaticRoutes(app) {
|
|
|
146
125
|
const path = paths[i];
|
|
147
126
|
if (pathsByMethod.get(path) !== i) continue;
|
|
148
127
|
const h = handlers[i];
|
|
149
|
-
|
|
150
|
-
|
|
128
|
+
let value;
|
|
129
|
+
if (isHTMLBundle(h)) value = h;
|
|
130
|
+
else if (!promoteResponses || typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
|
|
131
|
+
else value = require_compile_handler_index.buildNativeStaticResponse(require_route_table.routeRow(table, i), app);
|
|
151
132
|
if (!value) continue;
|
|
152
133
|
const needsEncode = (routeFlags & require_route_table.RouteFlag.Encode) !== 0;
|
|
153
134
|
add(method, path, value, needsEncode);
|
|
@@ -185,10 +166,11 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
185
166
|
..._config,
|
|
186
167
|
..._options
|
|
187
168
|
} : _options;
|
|
188
|
-
const
|
|
169
|
+
const htmlRoutes = collectHTMLBundleRoutes(app);
|
|
170
|
+
const server = app.server = Bun.serve(serve.routes || serve.error || htmlRoutes ? {
|
|
189
171
|
...serve,
|
|
190
172
|
error: unavailableFetch,
|
|
191
|
-
routes: {}
|
|
173
|
+
routes: htmlRoutes ?? {}
|
|
192
174
|
} : serve);
|
|
193
175
|
let live;
|
|
194
176
|
let cancelled = false;
|
|
@@ -329,7 +311,13 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
329
311
|
}
|
|
330
312
|
let idleClosed = true;
|
|
331
313
|
if (idleRequired) {
|
|
332
|
-
|
|
314
|
+
const closeIdle = server.closeIdleConnections;
|
|
315
|
+
if (closeIdle) try {
|
|
316
|
+
closeIdle.call(server);
|
|
317
|
+
} catch (error) {
|
|
318
|
+
errors.push(error);
|
|
319
|
+
idleClosed = false;
|
|
320
|
+
}
|
|
333
321
|
if (idleClosed && !gateFailure) idleRequired = false;
|
|
334
322
|
}
|
|
335
323
|
const safe = socketsSettled && stopped && idleClosed && (!gateFailure || forceDone);
|
|
@@ -368,7 +356,7 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
368
356
|
}
|
|
369
357
|
cancelled = true;
|
|
370
358
|
requestReady.resolve();
|
|
371
|
-
|
|
359
|
+
if (app.server === server) app.server = void 0;
|
|
372
360
|
let outcome;
|
|
373
361
|
if (shutdownAttempt) {
|
|
374
362
|
if (closeActiveConnections === true && !forceDone) {
|
|
@@ -423,6 +411,11 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
423
411
|
(cleanupFailures ??= []).push(error);
|
|
424
412
|
}
|
|
425
413
|
}
|
|
414
|
+
try {
|
|
415
|
+
await require_utils.disposeDecorators(app);
|
|
416
|
+
} catch (error) {
|
|
417
|
+
(cleanupFailures ??= []).push(error);
|
|
418
|
+
}
|
|
426
419
|
}
|
|
427
420
|
cleanupCompleted = true;
|
|
428
421
|
epochCleanup.length = 0;
|
|
@@ -457,7 +450,19 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
457
450
|
published = true;
|
|
458
451
|
if (built.websocket) serve.websocket = built.websocket;
|
|
459
452
|
if (built.routes) serve.routes = built.routes;
|
|
460
|
-
|
|
453
|
+
try {
|
|
454
|
+
server.reload(serve);
|
|
455
|
+
} catch (error) {
|
|
456
|
+
if (!serve.routes) throw error;
|
|
457
|
+
delete serve.routes;
|
|
458
|
+
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
459
|
+
try {
|
|
460
|
+
server.reload(serve);
|
|
461
|
+
} catch (fallbackError) {
|
|
462
|
+
console.error("[Elysia] Failed to reload Bun server:", fallbackError);
|
|
463
|
+
throw fallbackError;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
461
466
|
if (callback) callback(server);
|
|
462
467
|
} catch (error) {
|
|
463
468
|
startupFailure ??= { error };
|
|
@@ -490,4 +495,6 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
490
495
|
|
|
491
496
|
//#endregion
|
|
492
497
|
exports.BunAdapter = BunAdapter;
|
|
493
|
-
exports.
|
|
498
|
+
exports.collectHTMLBundleRoutes = collectHTMLBundleRoutes;
|
|
499
|
+
exports.collectStaticRoutes = collectStaticRoutes;
|
|
500
|
+
exports.isHTMLBundle = isHTMLBundle;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createAdapter } from "../index.mjs";
|
|
2
|
-
import { flattenChain, getLoosePath, isSocketQuiet, nullObject, throwLifecycleErrors } from "../../utils.mjs";
|
|
2
|
+
import { disposeDecorators, flattenChain, getLoosePath, isSocketQuiet, nullObject, throwLifecycleErrors } from "../../utils.mjs";
|
|
3
3
|
import { WebStandardAdapter } from "../web-standard/index.mjs";
|
|
4
4
|
import { frozenRootOf, resolvedWsOf } from "../../generation.mjs";
|
|
5
5
|
import { origin } from "../origin.mjs";
|
|
@@ -20,29 +20,11 @@ const unavailableFetch = () => new Response(null, {
|
|
|
20
20
|
headers: { connection: "close" },
|
|
21
21
|
status: 503
|
|
22
22
|
});
|
|
23
|
-
function reloadServer(server, serve) {
|
|
24
|
-
try {
|
|
25
|
-
server.reload(serve);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
if (!serve.routes) throw error;
|
|
28
|
-
delete serve.routes;
|
|
29
|
-
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
30
|
-
try {
|
|
31
|
-
server.reload(serve);
|
|
32
|
-
} catch (fallbackError) {
|
|
33
|
-
console.error("[Elysia] Failed to reload Bun server:", fallbackError);
|
|
34
|
-
throw fallbackError;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
23
|
function releaseLifecycle(app, ext, createdExt, stop, registerCleanup) {
|
|
39
24
|
if (ext.stop === stop) delete ext.stop;
|
|
40
25
|
if (ext.cleanupEpoch === registerCleanup) delete ext.cleanupEpoch;
|
|
41
26
|
if (createdExt && app["~ext"] === ext && !Object.keys(ext).length) app["~ext"] = void 0;
|
|
42
27
|
}
|
|
43
|
-
function clearAppServer(app, server) {
|
|
44
|
-
if (app.server === server) app.server = void 0;
|
|
45
|
-
}
|
|
46
28
|
async function waitForServerRequests(server, abandoned) {
|
|
47
29
|
while (server.pendingRequests && !abandoned()) await Bun.sleep(1);
|
|
48
30
|
}
|
|
@@ -67,17 +49,6 @@ async function settleServerWebSockets(lifecycle, errors) {
|
|
|
67
49
|
} while (lifecycle.sockets.size);
|
|
68
50
|
return true;
|
|
69
51
|
}
|
|
70
|
-
const closeServerIdle = (server, errors) => {
|
|
71
|
-
const close = server.closeIdleConnections;
|
|
72
|
-
if (!close) return true;
|
|
73
|
-
try {
|
|
74
|
-
close.call(server);
|
|
75
|
-
return true;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
errors.push(error);
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
52
|
/**
|
|
82
53
|
* ! This may looks like it would cause race condition, but it is not
|
|
83
54
|
* Bun is single-threaded and synchronous, so the `finally` block will
|
|
@@ -96,12 +67,20 @@ const withOrigin = (fetch) => (request, server) => {
|
|
|
96
67
|
}
|
|
97
68
|
};
|
|
98
69
|
const isNativeStaticMethod = (method) => method === "GET" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "HEAD" || method === "OPTIONS";
|
|
70
|
+
const isHTMLBundle = (value) => typeof value === "object" && value !== null && typeof value.index === "string";
|
|
71
|
+
function collectHTMLBundleRoutes(app) {
|
|
72
|
+
let routes;
|
|
73
|
+
for (const [method, path, handler] of app["~routes"]) {
|
|
74
|
+
if (!isNativeStaticMethod(method) || !isHTMLBundle(handler) || path.indexOf(":") !== -1 || path.indexOf("*") !== -1) continue;
|
|
75
|
+
((routes ??= nullObject())[path] ??= nullObject())[method] = handler;
|
|
76
|
+
}
|
|
77
|
+
return routes;
|
|
78
|
+
}
|
|
99
79
|
function collectStaticRoutes(app) {
|
|
100
|
-
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
101
80
|
app.fetch;
|
|
102
81
|
const frozenRoot = frozenRootOf(app);
|
|
103
82
|
const fetchLevelHook = flattenChain(frozenRoot["~hookChain"]);
|
|
104
|
-
|
|
83
|
+
const promoteResponses = app["~config"]?.nativeStaticResponse !== false && !fetchLevelHook?.request?.length && !fetchLevelHook?.trace?.length && !frozenRoot["~ext"]?.hoc?.length;
|
|
105
84
|
const table = app["~generation"]?.routeTable ?? app["~routeTable"];
|
|
106
85
|
const length = table?.length ?? 0;
|
|
107
86
|
if (!table || !length) return;
|
|
@@ -110,7 +89,7 @@ function collectStaticRoutes(app) {
|
|
|
110
89
|
for (let i = 0; i < length; i++) {
|
|
111
90
|
if (!isNativeStaticMethod(methods[i]) || (flags[i] & RouteFlag.Dynamic) !== 0) continue;
|
|
112
91
|
const h = handlers[i];
|
|
113
|
-
if (typeof h !== "function" && !(h instanceof Error) && !(h instanceof Promise)) {
|
|
92
|
+
if (isHTMLBundle(h) || promoteResponses && typeof h !== "function" && !(h instanceof Error) && !(h instanceof Promise)) {
|
|
114
93
|
hasCandidate = true;
|
|
115
94
|
break;
|
|
116
95
|
}
|
|
@@ -145,8 +124,10 @@ function collectStaticRoutes(app) {
|
|
|
145
124
|
const path = paths[i];
|
|
146
125
|
if (pathsByMethod.get(path) !== i) continue;
|
|
147
126
|
const h = handlers[i];
|
|
148
|
-
|
|
149
|
-
|
|
127
|
+
let value;
|
|
128
|
+
if (isHTMLBundle(h)) value = h;
|
|
129
|
+
else if (!promoteResponses || typeof h === "function" || h instanceof Error || h instanceof Promise) continue;
|
|
130
|
+
else value = buildNativeStaticResponse(routeRow(table, i), app);
|
|
150
131
|
if (!value) continue;
|
|
151
132
|
const needsEncode = (routeFlags & RouteFlag.Encode) !== 0;
|
|
152
133
|
add(method, path, value, needsEncode);
|
|
@@ -184,10 +165,11 @@ const BunAdapter = createAdapter({
|
|
|
184
165
|
..._config,
|
|
185
166
|
..._options
|
|
186
167
|
} : _options;
|
|
187
|
-
const
|
|
168
|
+
const htmlRoutes = collectHTMLBundleRoutes(app);
|
|
169
|
+
const server = app.server = Bun.serve(serve.routes || serve.error || htmlRoutes ? {
|
|
188
170
|
...serve,
|
|
189
171
|
error: unavailableFetch,
|
|
190
|
-
routes: {}
|
|
172
|
+
routes: htmlRoutes ?? {}
|
|
191
173
|
} : serve);
|
|
192
174
|
let live;
|
|
193
175
|
let cancelled = false;
|
|
@@ -328,7 +310,13 @@ const BunAdapter = createAdapter({
|
|
|
328
310
|
}
|
|
329
311
|
let idleClosed = true;
|
|
330
312
|
if (idleRequired) {
|
|
331
|
-
|
|
313
|
+
const closeIdle = server.closeIdleConnections;
|
|
314
|
+
if (closeIdle) try {
|
|
315
|
+
closeIdle.call(server);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
errors.push(error);
|
|
318
|
+
idleClosed = false;
|
|
319
|
+
}
|
|
332
320
|
if (idleClosed && !gateFailure) idleRequired = false;
|
|
333
321
|
}
|
|
334
322
|
const safe = socketsSettled && stopped && idleClosed && (!gateFailure || forceDone);
|
|
@@ -367,7 +355,7 @@ const BunAdapter = createAdapter({
|
|
|
367
355
|
}
|
|
368
356
|
cancelled = true;
|
|
369
357
|
requestReady.resolve();
|
|
370
|
-
|
|
358
|
+
if (app.server === server) app.server = void 0;
|
|
371
359
|
let outcome;
|
|
372
360
|
if (shutdownAttempt) {
|
|
373
361
|
if (closeActiveConnections === true && !forceDone) {
|
|
@@ -422,6 +410,11 @@ const BunAdapter = createAdapter({
|
|
|
422
410
|
(cleanupFailures ??= []).push(error);
|
|
423
411
|
}
|
|
424
412
|
}
|
|
413
|
+
try {
|
|
414
|
+
await disposeDecorators(app);
|
|
415
|
+
} catch (error) {
|
|
416
|
+
(cleanupFailures ??= []).push(error);
|
|
417
|
+
}
|
|
425
418
|
}
|
|
426
419
|
cleanupCompleted = true;
|
|
427
420
|
epochCleanup.length = 0;
|
|
@@ -456,7 +449,19 @@ const BunAdapter = createAdapter({
|
|
|
456
449
|
published = true;
|
|
457
450
|
if (built.websocket) serve.websocket = built.websocket;
|
|
458
451
|
if (built.routes) serve.routes = built.routes;
|
|
459
|
-
|
|
452
|
+
try {
|
|
453
|
+
server.reload(serve);
|
|
454
|
+
} catch (error) {
|
|
455
|
+
if (!serve.routes) throw error;
|
|
456
|
+
delete serve.routes;
|
|
457
|
+
console.warn("[Elysia] Native static promotion was skipped:", error);
|
|
458
|
+
try {
|
|
459
|
+
server.reload(serve);
|
|
460
|
+
} catch (fallbackError) {
|
|
461
|
+
console.error("[Elysia] Failed to reload Bun server:", fallbackError);
|
|
462
|
+
throw fallbackError;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
460
465
|
if (callback) callback(server);
|
|
461
466
|
} catch (error) {
|
|
462
467
|
startupFailure ??= { error };
|
|
@@ -488,4 +493,4 @@ const BunAdapter = createAdapter({
|
|
|
488
493
|
});
|
|
489
494
|
|
|
490
495
|
//#endregion
|
|
491
|
-
export { BunAdapter, collectStaticRoutes };
|
|
496
|
+
export { BunAdapter, collectHTMLBundleRoutes, collectStaticRoutes, isHTMLBundle };
|
package/dist/adapter/utils.js
CHANGED
|
@@ -124,25 +124,6 @@ function responseToSetHeaders(response, set) {
|
|
|
124
124
|
if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
125
125
|
return set;
|
|
126
126
|
}
|
|
127
|
-
function enqueueBinaryChunk(controller, chunk) {
|
|
128
|
-
if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
|
|
129
|
-
controller.enqueue(new Uint8Array(buffer));
|
|
130
|
-
return true;
|
|
131
|
-
});
|
|
132
|
-
if (chunk instanceof Uint8Array) {
|
|
133
|
-
controller.enqueue(chunk);
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
if (chunk instanceof ArrayBuffer) {
|
|
137
|
-
controller.enqueue(new Uint8Array(chunk));
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
if (ArrayBuffer.isView(chunk)) {
|
|
141
|
-
controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
127
|
function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
147
128
|
return async (generator, set, request, skipFormat, owned = false) => {
|
|
148
129
|
if (request === null) return void 0;
|
|
@@ -253,7 +234,21 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
253
234
|
controller.enqueue(encodeChunk(value.toSSE()));
|
|
254
235
|
return;
|
|
255
236
|
}
|
|
256
|
-
|
|
237
|
+
let p;
|
|
238
|
+
if (value instanceof Blob) p = value.arrayBuffer().then((buffer) => {
|
|
239
|
+
controller.enqueue(new Uint8Array(buffer));
|
|
240
|
+
return true;
|
|
241
|
+
});
|
|
242
|
+
else if (value instanceof Uint8Array) {
|
|
243
|
+
controller.enqueue(value);
|
|
244
|
+
p = true;
|
|
245
|
+
} else if (value instanceof ArrayBuffer) {
|
|
246
|
+
controller.enqueue(new Uint8Array(value));
|
|
247
|
+
p = true;
|
|
248
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
249
|
+
controller.enqueue(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
250
|
+
p = true;
|
|
251
|
+
} else p = false;
|
|
257
252
|
if (p !== false) return void await p;
|
|
258
253
|
if (typeof value === "object") try {
|
|
259
254
|
controller.enqueue(encodeChunk(format(JSON.stringify(value))));
|
|
@@ -540,7 +535,7 @@ function tee(source, branches = 2, cap = 64, capBytes = 1 << 22) {
|
|
|
540
535
|
wakeAll();
|
|
541
536
|
}
|
|
542
537
|
})();
|
|
543
|
-
const makeBranch = (me) => ({
|
|
538
|
+
const makeBranch = (me) => Object.assign(Object.create(null), {
|
|
544
539
|
[Symbol.asyncIterator]() {
|
|
545
540
|
return this;
|
|
546
541
|
},
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -123,25 +123,6 @@ function responseToSetHeaders(response, set) {
|
|
|
123
123
|
if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
124
124
|
return set;
|
|
125
125
|
}
|
|
126
|
-
function enqueueBinaryChunk(controller, chunk) {
|
|
127
|
-
if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
|
|
128
|
-
controller.enqueue(new Uint8Array(buffer));
|
|
129
|
-
return true;
|
|
130
|
-
});
|
|
131
|
-
if (chunk instanceof Uint8Array) {
|
|
132
|
-
controller.enqueue(chunk);
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
if (chunk instanceof ArrayBuffer) {
|
|
136
|
-
controller.enqueue(new Uint8Array(chunk));
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
if (ArrayBuffer.isView(chunk)) {
|
|
140
|
-
controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
126
|
function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
146
127
|
return async (generator, set, request, skipFormat, owned = false) => {
|
|
147
128
|
if (request === null) return void 0;
|
|
@@ -252,7 +233,21 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
252
233
|
controller.enqueue(encodeChunk(value.toSSE()));
|
|
253
234
|
return;
|
|
254
235
|
}
|
|
255
|
-
|
|
236
|
+
let p;
|
|
237
|
+
if (value instanceof Blob) p = value.arrayBuffer().then((buffer) => {
|
|
238
|
+
controller.enqueue(new Uint8Array(buffer));
|
|
239
|
+
return true;
|
|
240
|
+
});
|
|
241
|
+
else if (value instanceof Uint8Array) {
|
|
242
|
+
controller.enqueue(value);
|
|
243
|
+
p = true;
|
|
244
|
+
} else if (value instanceof ArrayBuffer) {
|
|
245
|
+
controller.enqueue(new Uint8Array(value));
|
|
246
|
+
p = true;
|
|
247
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
248
|
+
controller.enqueue(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
249
|
+
p = true;
|
|
250
|
+
} else p = false;
|
|
256
251
|
if (p !== false) return void await p;
|
|
257
252
|
if (typeof value === "object") try {
|
|
258
253
|
controller.enqueue(encodeChunk(format(JSON.stringify(value))));
|
|
@@ -539,7 +534,7 @@ function tee(source, branches = 2, cap = 64, capBytes = 1 << 22) {
|
|
|
539
534
|
wakeAll();
|
|
540
535
|
}
|
|
541
536
|
})();
|
|
542
|
-
const makeBranch = (me) => ({
|
|
537
|
+
const makeBranch = (me) => Object.assign(Object.create(null), {
|
|
543
538
|
[Symbol.asyncIterator]() {
|
|
544
539
|
return this;
|
|
545
540
|
},
|
package/dist/base.d.ts
CHANGED
|
@@ -50,6 +50,14 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
50
50
|
hoc?: WrapFn<any>[];
|
|
51
51
|
setup?: GracefulHandler<any>[];
|
|
52
52
|
cleanup?: GracefulHandler<any>[];
|
|
53
|
+
/**
|
|
54
|
+
* Accepted `.decorate()` values implementing an explicit disposer, in
|
|
55
|
+
* registration order.
|
|
56
|
+
*
|
|
57
|
+
* Recorded at registration so the original reference survives a
|
|
58
|
+
* `.use()` clone, a same-name merge and a later override
|
|
59
|
+
*/
|
|
60
|
+
disposable?: unknown[];
|
|
53
61
|
cleanupEpoch?: (handler: GracefulHandler<any> | GracefulHandler<any>[]) => boolean;
|
|
54
62
|
stop?: (closeActiveConnections?: boolean, failure?: {
|
|
55
63
|
error: unknown;
|