elysia 2.0.0-exp.25 → 2.0.0-exp.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.js +0 -16
- package/dist/_virtual/_rolldown/runtime.mjs +2 -0
- package/dist/adapter/bun/index.js +58 -19
- package/dist/adapter/bun/index.mjs +60 -21
- package/dist/adapter/transferable.d.ts +4 -0
- package/dist/adapter/transferable.js +7 -0
- package/dist/adapter/transferable.mjs +5 -0
- package/dist/adapter/utils.d.ts +10 -7
- package/dist/adapter/utils.js +213 -86
- package/dist/adapter/utils.mjs +213 -87
- package/dist/adapter/web-standard/handler.js +26 -17
- package/dist/adapter/web-standard/handler.mjs +26 -17
- package/dist/adapter/web-standard/index.js +27 -5
- package/dist/adapter/web-standard/index.mjs +27 -5
- package/dist/adapter/web-standard/utils.js +1 -0
- package/dist/adapter/web-standard/utils.mjs +1 -0
- package/dist/base.d.ts +90 -286
- package/dist/base.js +267 -122
- package/dist/base.mjs +269 -124
- package/dist/compile/aot.d.ts +14 -1
- package/dist/compile/aot.js +18 -3
- package/dist/compile/aot.mjs +17 -3
- package/dist/compile/handler/frozen-validator.d.ts +41 -0
- package/dist/compile/handler/frozen-validator.js +221 -0
- package/dist/compile/handler/frozen-validator.mjs +218 -0
- package/dist/compile/handler/index.d.ts +13 -4
- package/dist/compile/handler/index.js +112 -30
- package/dist/compile/handler/index.mjs +110 -32
- package/dist/compile/handler/jit.d.ts +0 -1
- package/dist/compile/handler/jit.js +89 -60
- package/dist/compile/handler/jit.mjs +92 -63
- package/dist/compile/handler/params.js +8 -2
- package/dist/compile/handler/params.mjs +9 -3
- package/dist/compile/handler/reconstruct.d.ts +1 -2
- package/dist/compile/handler/reconstruct.js +19 -11
- package/dist/compile/handler/reconstruct.mjs +19 -11
- package/dist/compile/handler/utils.d.ts +6 -8
- package/dist/compile/handler/utils.js +27 -27
- package/dist/compile/handler/utils.mjs +28 -27
- package/dist/compile/index.d.ts +2 -2
- package/dist/compile/index.js +3 -1
- package/dist/compile/index.mjs +2 -2
- package/dist/compile/jit-probe.d.ts +0 -2
- package/dist/compile/jit-probe.js +3 -11
- package/dist/compile/jit-probe.mjs +3 -11
- package/dist/compile/utils.js +2 -2
- package/dist/compile/utils.mjs +2 -2
- package/dist/constants.d.ts +4 -1
- package/dist/constants.js +19 -5
- package/dist/constants.mjs +17 -5
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -1
- package/dist/context.mjs +1 -1
- package/dist/cookie/config.js +5 -5
- package/dist/cookie/config.mjs +5 -5
- package/dist/cookie/cookie.d.ts +2 -4
- package/dist/cookie/cookie.js +37 -23
- package/dist/cookie/cookie.mjs +37 -23
- package/dist/cookie/error.d.ts +17 -0
- package/dist/cookie/error.js +25 -0
- package/dist/cookie/error.mjs +24 -0
- package/dist/cookie/index.d.ts +2 -1
- package/dist/cookie/index.js +2 -0
- package/dist/cookie/index.mjs +2 -1
- package/dist/cookie/lib.js +12 -2
- package/dist/cookie/lib.mjs +12 -2
- package/dist/cookie/serialize.js +5 -1
- package/dist/cookie/serialize.mjs +5 -1
- package/dist/cookie/types.d.ts +1 -3
- package/dist/cookie/utils.d.ts +12 -1
- package/dist/cookie/utils.js +128 -18
- package/dist/cookie/utils.mjs +122 -18
- package/dist/error.d.ts +74 -16
- package/dist/error.js +263 -88
- package/dist/error.mjs +257 -88
- package/dist/handler/error.js +35 -4
- package/dist/handler/error.mjs +36 -5
- package/dist/handler/fetch.js +98 -70
- package/dist/handler/fetch.mjs +99 -71
- package/dist/handler/utils.d.ts +1 -1
- package/dist/handler/utils.js +8 -2
- package/dist/handler/utils.mjs +8 -2
- package/dist/index.d.ts +7 -6
- package/dist/index.js +4 -2
- package/dist/index.mjs +4 -3
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/parse-query.js +37 -22
- package/dist/parse-query.mjs +37 -22
- package/dist/plugin/bun.d.ts +0 -8
- package/dist/plugin/bun.js +10 -60
- package/dist/plugin/bun.mjs +11 -60
- package/dist/plugin/core.d.ts +130 -4
- package/dist/plugin/core.js +352 -19
- package/dist/plugin/core.mjs +347 -20
- package/dist/plugin/esbuild.d.ts +0 -8
- package/dist/plugin/esbuild.js +10 -57
- package/dist/plugin/esbuild.mjs +11 -58
- package/dist/plugin/source.d.ts +7 -9
- package/dist/plugin/source.js +10 -23
- package/dist/plugin/source.mjs +10 -23
- package/dist/plugin/treeshake.js +64 -16
- package/dist/plugin/treeshake.mjs +64 -16
- package/dist/plugin/vite.d.ts +2 -8
- package/dist/plugin/vite.js +37 -12
- package/dist/plugin/vite.mjs +37 -13
- package/dist/sucrose.js +84 -44
- package/dist/sucrose.mjs +84 -44
- package/dist/trace.d.ts +22 -56
- package/dist/trace.js +257 -141
- package/dist/trace.mjs +256 -141
- package/dist/type/bridge-live.d.ts +14 -0
- package/dist/type/bridge-live.js +34 -0
- package/dist/type/bridge-live.mjs +16 -0
- package/dist/type/bridge.d.ts +9 -7
- package/dist/type/bridge.js +8 -0
- package/dist/type/bridge.mjs +3 -1
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/coerce.js +14 -9
- package/dist/type/coerce.mjs +14 -9
- package/dist/type/compat.js +3 -2
- package/dist/type/compat.mjs +4 -3
- package/dist/type/elysia/array-buffer.d.ts +1 -2
- package/dist/type/elysia/array-buffer.js +7 -1
- package/dist/type/elysia/array-buffer.mjs +8 -2
- package/dist/type/elysia/array.js +7 -4
- package/dist/type/elysia/array.mjs +7 -4
- package/dist/type/elysia/boolean.js +6 -3
- package/dist/type/elysia/boolean.mjs +6 -3
- package/dist/type/elysia/date.js +38 -7
- package/dist/type/elysia/date.mjs +39 -8
- package/dist/type/elysia/file-type.d.ts +1 -1
- package/dist/type/elysia/file-type.js +5 -11
- package/dist/type/elysia/file-type.mjs +5 -11
- package/dist/type/elysia/file.js +7 -1
- package/dist/type/elysia/file.mjs +8 -2
- package/dist/type/elysia/files.js +13 -3
- package/dist/type/elysia/files.mjs +15 -5
- package/dist/type/elysia/integer.js +6 -3
- package/dist/type/elysia/integer.mjs +6 -3
- package/dist/type/elysia/intersect.js +6 -3
- package/dist/type/elysia/intersect.mjs +6 -3
- package/dist/type/elysia/maybe-empty.js +4 -2
- package/dist/type/elysia/maybe-empty.mjs +5 -3
- package/dist/type/elysia/nullable.js +4 -1
- package/dist/type/elysia/nullable.mjs +5 -2
- package/dist/type/elysia/number.js +6 -3
- package/dist/type/elysia/number.mjs +6 -3
- package/dist/type/elysia/numeric.js +1 -1
- package/dist/type/elysia/numeric.mjs +1 -1
- package/dist/type/elysia/object.js +8 -5
- package/dist/type/elysia/object.mjs +8 -5
- package/dist/type/elysia/optional.js +11 -13
- package/dist/type/elysia/optional.mjs +12 -13
- package/dist/type/elysia/string.js +6 -3
- package/dist/type/elysia/string.mjs +6 -3
- package/dist/type/elysia/uint8-array.d.ts +1 -2
- package/dist/type/elysia/uint8-array.js +7 -1
- package/dist/type/elysia/uint8-array.mjs +8 -2
- package/dist/type/elysia/union-enum.js +3 -2
- package/dist/type/elysia/union-enum.mjs +4 -3
- package/dist/type/elysia/union.js +6 -3
- package/dist/type/elysia/union.mjs +6 -3
- package/dist/type/elysia/utils.d.ts +2 -1
- package/dist/type/elysia/utils.js +11 -24
- package/dist/type/elysia/utils.mjs +11 -25
- package/dist/type/exports.js +0 -37
- package/dist/type/exports.mjs +1 -33
- package/dist/type/index.js +60 -2
- package/dist/type/index.mjs +59 -2
- package/dist/type/types.d.ts +1 -1
- package/dist/type/utils.js +0 -18
- package/dist/type/utils.mjs +0 -18
- package/dist/type/validator/default-precompute.js +23 -7
- package/dist/type/validator/default-precompute.mjs +23 -7
- package/dist/type/validator/index.d.ts +2 -2
- package/dist/type/validator/index.js +61 -8
- package/dist/type/validator/index.mjs +61 -8
- package/dist/type/validator/string-codec-aot.js +1 -1
- package/dist/type/validator/string-codec-aot.mjs +1 -1
- package/dist/type/validator/validator-cache.d.ts +2 -2
- package/dist/type/validator/validator-cache.js +32 -12
- package/dist/type/validator/validator-cache.mjs +32 -12
- package/dist/types.d.ts +55 -22
- package/dist/universal/file.d.ts +3 -0
- package/dist/universal/file.js +9 -2
- package/dist/universal/file.mjs +9 -2
- package/dist/universal/server.d.ts +1 -0
- package/dist/utils.d.ts +11 -4
- package/dist/utils.js +86 -11
- package/dist/utils.mjs +81 -12
- package/dist/validator/index.d.ts +8 -7
- package/dist/validator/index.js +91 -46
- package/dist/validator/index.mjs +92 -47
- package/dist/validator/route.js +1 -1
- package/dist/validator/route.mjs +1 -1
- package/dist/ws/context.d.ts +1 -0
- package/dist/ws/context.js +12 -25
- package/dist/ws/context.mjs +12 -25
- package/dist/ws/parser.d.ts +1 -4
- package/dist/ws/route.d.ts +5 -2
- package/dist/ws/route.js +159 -60
- package/dist/ws/route.mjs +159 -62
- package/package.json +4 -2
- package/dist/adapter/bun/router.d.ts +0 -10
- package/dist/adapter/bun/router.js +0 -86
- package/dist/adapter/bun/router.mjs +0 -83
- package/dist/compile/handler/constants.d.ts +0 -1
- package/dist/compile/handler/constants.js +0 -1
- package/dist/compile/handler/constants.mjs +0 -1
|
@@ -5,19 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __exportAll = (all, no_symbols) => {
|
|
9
|
-
let target = {};
|
|
10
|
-
for (var name in all) {
|
|
11
|
-
__defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
if (!no_symbols) {
|
|
17
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
-
}
|
|
19
|
-
return target;
|
|
20
|
-
};
|
|
21
8
|
var __copyProps = (to, from, except, desc) => {
|
|
22
9
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
10
|
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
@@ -32,7 +19,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
32
19
|
}
|
|
33
20
|
return to;
|
|
34
21
|
};
|
|
35
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
36
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
37
23
|
value: mod,
|
|
38
24
|
enumerable: true
|
|
@@ -40,6 +26,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
40
26
|
|
|
41
27
|
//#endregion
|
|
42
28
|
|
|
43
|
-
exports.__exportAll = __exportAll;
|
|
44
|
-
exports.__reExport = __reExport;
|
|
45
29
|
exports.__toESM = __toESM;
|
|
@@ -3,29 +3,67 @@ const require_adapter_index = require('../index.js');
|
|
|
3
3
|
const require_constants = require('../../constants.js');
|
|
4
4
|
const require_utils = require('../../utils.js');
|
|
5
5
|
const require_adapter_web_standard_index = require('../web-standard/index.js');
|
|
6
|
+
const require_compile_handler_index = require('../../compile/handler/index.js');
|
|
6
7
|
const require_memory = require('../../memory.js');
|
|
7
8
|
const require_ws_route = require('../../ws/route.js');
|
|
8
9
|
|
|
9
10
|
//#region src/adapter/bun/index.ts
|
|
10
11
|
function collectStaticRoutes(app) {
|
|
12
|
+
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
11
13
|
app.fetch;
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
+
const fetchLevelHook = require_utils.flattenChain(app["~hookChain"]);
|
|
15
|
+
if (fetchLevelHook?.request?.length || fetchLevelHook?.trace?.length || app["~ext"]?.hoc?.length) return;
|
|
16
|
+
const history = app.history;
|
|
17
|
+
if (!history?.length) return;
|
|
14
18
|
const ready = require_utils.nullObject();
|
|
15
19
|
const pending = [];
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
const strictPath = app["~config"]?.strictPath === true;
|
|
21
|
+
const seen = /* @__PURE__ */ new Map();
|
|
22
|
+
for (let i = 0; i < history.length; i++) {
|
|
23
|
+
const route = history[i];
|
|
24
|
+
const method = route[0] === "WS" ? "WS" : require_utils.mapMethodBack(route[0]);
|
|
25
|
+
seen.set(method + " " + route[1], i);
|
|
26
|
+
}
|
|
27
|
+
let explicitPaths;
|
|
28
|
+
if (!strictPath) {
|
|
29
|
+
explicitPaths = /* @__PURE__ */ new Map();
|
|
30
|
+
for (let i = 0; i < history.length; i++) {
|
|
31
|
+
const route = history[i];
|
|
32
|
+
const method = route[0] === "WS" ? "WS" : require_utils.mapMethodBack(route[0]);
|
|
33
|
+
const path = route[1];
|
|
34
|
+
let set = explicitPaths.get(method);
|
|
35
|
+
if (!set) explicitPaths.set(method, set = /* @__PURE__ */ new Set());
|
|
36
|
+
set.add(path);
|
|
37
|
+
if (require_constants.needEncodeRegex.test(path)) {
|
|
38
|
+
const encoded = encodeURI(path);
|
|
39
|
+
if (encoded !== path) set.add(encoded);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const add = (method, path, value) => {
|
|
44
|
+
if (require_constants.needEncodeRegex.test(path)) path = encodeURI(path);
|
|
45
|
+
if (value instanceof Promise) pending.push(value.then((resolved) => {
|
|
46
|
+
if (resolved instanceof Response) (ready[path] ??= require_utils.nullObject())[method] = resolved;
|
|
47
|
+
}, (err) => {
|
|
48
|
+
console.error(`[Elysia] Static route ${method} ${path} failed to resolve:`, err);
|
|
49
|
+
}));
|
|
50
|
+
else (ready[path] ??= require_utils.nullObject())[method] = value;
|
|
51
|
+
};
|
|
52
|
+
for (let i = 0; i < history.length; i++) {
|
|
53
|
+
const route = history[i];
|
|
54
|
+
if (route[0] === "WS") continue;
|
|
55
|
+
const method = require_utils.mapMethodBack(route[0]);
|
|
56
|
+
const path = route[1];
|
|
57
|
+
if (seen.get(method + " " + path) !== i) continue;
|
|
58
|
+
const value = require_compile_handler_index.buildNativeStaticResponse(route, app);
|
|
59
|
+
if (!value) continue;
|
|
60
|
+
add(method, path, value);
|
|
61
|
+
if (!strictPath && !require_constants.isDynamicRegex.test(path)) {
|
|
62
|
+
const loose = require_utils.getLoosePath(path);
|
|
63
|
+
if (loose !== path && !explicitPaths?.get(method)?.has(loose)) add(method, loose, value);
|
|
27
64
|
}
|
|
28
65
|
}
|
|
66
|
+
if (!Object.keys(ready).length && !pending.length) return;
|
|
29
67
|
return [ready, pending];
|
|
30
68
|
}
|
|
31
69
|
const BunAdapter = require_adapter_index.createAdapter({
|
|
@@ -37,7 +75,7 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
37
75
|
listen(app, options, callback) {
|
|
38
76
|
const _config = app["~config"]?.serve;
|
|
39
77
|
const optionsIsObject = typeof options === "object";
|
|
40
|
-
const _options = optionsIsObject ? options : {
|
|
78
|
+
const _options = optionsIsObject ? { ...options } : {
|
|
41
79
|
port: +options,
|
|
42
80
|
fetch: (request, server) => app.fetch(request, server)
|
|
43
81
|
};
|
|
@@ -46,12 +84,13 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
46
84
|
..._config,
|
|
47
85
|
..._options
|
|
48
86
|
} : _options;
|
|
49
|
-
app.server = Bun.serve(serve);
|
|
87
|
+
const server = app.server = Bun.serve(serve);
|
|
50
88
|
const onSetup = app["~ext"]?.setup;
|
|
51
89
|
if (onSetup) for (let i = 0; i < onSetup.length; i++) onSetup[i](app);
|
|
52
90
|
const hasWs = app["~hasWS"];
|
|
53
91
|
if (!hasWs) callback?.(app.server);
|
|
54
92
|
queueMicrotask(() => {
|
|
93
|
+
if (app.server !== server) return;
|
|
55
94
|
if (!app.pending) serve.fetch = app.fetch;
|
|
56
95
|
const buildWebSocket = () => {
|
|
57
96
|
const defaultConfig = app["~config"]?.websocket;
|
|
@@ -62,15 +101,16 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
62
101
|
const staticRoutes = collectStaticRoutes(app);
|
|
63
102
|
if (!staticRoutes) return;
|
|
64
103
|
if (staticRoutes[1].length) return Promise.all(staticRoutes[1]).then(() => {
|
|
104
|
+
if (app.server !== server) return;
|
|
65
105
|
serve.routes = staticRoutes[0];
|
|
66
106
|
app.server.reload(serve);
|
|
67
107
|
});
|
|
68
108
|
if (Object.keys(staticRoutes[0]).length) serve.routes = staticRoutes[0];
|
|
69
109
|
};
|
|
70
110
|
if (app.pending) {
|
|
71
|
-
|
|
72
|
-
else app.server = Bun.serve(serve);
|
|
111
|
+
app.server.reload(serve);
|
|
73
112
|
const reloadAfterModules = () => {
|
|
113
|
+
if (app.server !== server) return;
|
|
74
114
|
serve.fetch = app.fetch;
|
|
75
115
|
if (hasWs || app["~hasWS"]) buildWebSocket();
|
|
76
116
|
collectRoutes();
|
|
@@ -79,8 +119,7 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
79
119
|
app.modules.then(reloadAfterModules, reloadAfterModules);
|
|
80
120
|
} else {
|
|
81
121
|
collectRoutes();
|
|
82
|
-
|
|
83
|
-
else app.server = Bun.serve(serve);
|
|
122
|
+
app.server.reload(serve);
|
|
84
123
|
}
|
|
85
124
|
require_memory.flushMemory();
|
|
86
125
|
if (hasWs) callback?.(app.server);
|
|
@@ -1,30 +1,68 @@
|
|
|
1
1
|
import { createAdapter } from "../index.mjs";
|
|
2
|
-
import { needEncodeRegex } from "../../constants.mjs";
|
|
3
|
-
import { nullObject } from "../../utils.mjs";
|
|
2
|
+
import { isDynamicRegex, needEncodeRegex } from "../../constants.mjs";
|
|
3
|
+
import { flattenChain, getLoosePath, mapMethodBack, nullObject } from "../../utils.mjs";
|
|
4
4
|
import { WebStandardAdapter } from "../web-standard/index.mjs";
|
|
5
|
+
import { buildNativeStaticResponse } from "../../compile/handler/index.mjs";
|
|
5
6
|
import { flushMemory } from "../../memory.mjs";
|
|
6
7
|
import { buildGlobalWSHandler } from "../../ws/route.mjs";
|
|
7
8
|
|
|
8
9
|
//#region src/adapter/bun/index.ts
|
|
9
10
|
function collectStaticRoutes(app) {
|
|
11
|
+
if (app["~config"]?.nativeStaticResponse === false) return;
|
|
10
12
|
app.fetch;
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
+
const fetchLevelHook = flattenChain(app["~hookChain"]);
|
|
14
|
+
if (fetchLevelHook?.request?.length || fetchLevelHook?.trace?.length || app["~ext"]?.hoc?.length) return;
|
|
15
|
+
const history = app.history;
|
|
16
|
+
if (!history?.length) return;
|
|
13
17
|
const ready = nullObject();
|
|
14
18
|
const pending = [];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
const strictPath = app["~config"]?.strictPath === true;
|
|
20
|
+
const seen = /* @__PURE__ */ new Map();
|
|
21
|
+
for (let i = 0; i < history.length; i++) {
|
|
22
|
+
const route = history[i];
|
|
23
|
+
const method = route[0] === "WS" ? "WS" : mapMethodBack(route[0]);
|
|
24
|
+
seen.set(method + " " + route[1], i);
|
|
25
|
+
}
|
|
26
|
+
let explicitPaths;
|
|
27
|
+
if (!strictPath) {
|
|
28
|
+
explicitPaths = /* @__PURE__ */ new Map();
|
|
29
|
+
for (let i = 0; i < history.length; i++) {
|
|
30
|
+
const route = history[i];
|
|
31
|
+
const method = route[0] === "WS" ? "WS" : mapMethodBack(route[0]);
|
|
32
|
+
const path = route[1];
|
|
33
|
+
let set = explicitPaths.get(method);
|
|
34
|
+
if (!set) explicitPaths.set(method, set = /* @__PURE__ */ new Set());
|
|
35
|
+
set.add(path);
|
|
36
|
+
if (needEncodeRegex.test(path)) {
|
|
37
|
+
const encoded = encodeURI(path);
|
|
38
|
+
if (encoded !== path) set.add(encoded);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const add = (method, path, value) => {
|
|
43
|
+
if (needEncodeRegex.test(path)) path = encodeURI(path);
|
|
44
|
+
if (value instanceof Promise) pending.push(value.then((resolved) => {
|
|
45
|
+
if (resolved instanceof Response) (ready[path] ??= nullObject())[method] = resolved;
|
|
46
|
+
}, (err) => {
|
|
47
|
+
console.error(`[Elysia] Static route ${method} ${path} failed to resolve:`, err);
|
|
48
|
+
}));
|
|
49
|
+
else (ready[path] ??= nullObject())[method] = value;
|
|
50
|
+
};
|
|
51
|
+
for (let i = 0; i < history.length; i++) {
|
|
52
|
+
const route = history[i];
|
|
53
|
+
if (route[0] === "WS") continue;
|
|
54
|
+
const method = mapMethodBack(route[0]);
|
|
55
|
+
const path = route[1];
|
|
56
|
+
if (seen.get(method + " " + path) !== i) continue;
|
|
57
|
+
const value = buildNativeStaticResponse(route, app);
|
|
58
|
+
if (!value) continue;
|
|
59
|
+
add(method, path, value);
|
|
60
|
+
if (!strictPath && !isDynamicRegex.test(path)) {
|
|
61
|
+
const loose = getLoosePath(path);
|
|
62
|
+
if (loose !== path && !explicitPaths?.get(method)?.has(loose)) add(method, loose, value);
|
|
26
63
|
}
|
|
27
64
|
}
|
|
65
|
+
if (!Object.keys(ready).length && !pending.length) return;
|
|
28
66
|
return [ready, pending];
|
|
29
67
|
}
|
|
30
68
|
const BunAdapter = createAdapter({
|
|
@@ -36,7 +74,7 @@ const BunAdapter = createAdapter({
|
|
|
36
74
|
listen(app, options, callback) {
|
|
37
75
|
const _config = app["~config"]?.serve;
|
|
38
76
|
const optionsIsObject = typeof options === "object";
|
|
39
|
-
const _options = optionsIsObject ? options : {
|
|
77
|
+
const _options = optionsIsObject ? { ...options } : {
|
|
40
78
|
port: +options,
|
|
41
79
|
fetch: (request, server) => app.fetch(request, server)
|
|
42
80
|
};
|
|
@@ -45,12 +83,13 @@ const BunAdapter = createAdapter({
|
|
|
45
83
|
..._config,
|
|
46
84
|
..._options
|
|
47
85
|
} : _options;
|
|
48
|
-
app.server = Bun.serve(serve);
|
|
86
|
+
const server = app.server = Bun.serve(serve);
|
|
49
87
|
const onSetup = app["~ext"]?.setup;
|
|
50
88
|
if (onSetup) for (let i = 0; i < onSetup.length; i++) onSetup[i](app);
|
|
51
89
|
const hasWs = app["~hasWS"];
|
|
52
90
|
if (!hasWs) callback?.(app.server);
|
|
53
91
|
queueMicrotask(() => {
|
|
92
|
+
if (app.server !== server) return;
|
|
54
93
|
if (!app.pending) serve.fetch = app.fetch;
|
|
55
94
|
const buildWebSocket = () => {
|
|
56
95
|
const defaultConfig = app["~config"]?.websocket;
|
|
@@ -61,15 +100,16 @@ const BunAdapter = createAdapter({
|
|
|
61
100
|
const staticRoutes = collectStaticRoutes(app);
|
|
62
101
|
if (!staticRoutes) return;
|
|
63
102
|
if (staticRoutes[1].length) return Promise.all(staticRoutes[1]).then(() => {
|
|
103
|
+
if (app.server !== server) return;
|
|
64
104
|
serve.routes = staticRoutes[0];
|
|
65
105
|
app.server.reload(serve);
|
|
66
106
|
});
|
|
67
107
|
if (Object.keys(staticRoutes[0]).length) serve.routes = staticRoutes[0];
|
|
68
108
|
};
|
|
69
109
|
if (app.pending) {
|
|
70
|
-
|
|
71
|
-
else app.server = Bun.serve(serve);
|
|
110
|
+
app.server.reload(serve);
|
|
72
111
|
const reloadAfterModules = () => {
|
|
112
|
+
if (app.server !== server) return;
|
|
73
113
|
serve.fetch = app.fetch;
|
|
74
114
|
if (hasWs || app["~hasWS"]) buildWebSocket();
|
|
75
115
|
collectRoutes();
|
|
@@ -78,8 +118,7 @@ const BunAdapter = createAdapter({
|
|
|
78
118
|
app.modules.then(reloadAfterModules, reloadAfterModules);
|
|
79
119
|
} else {
|
|
80
120
|
collectRoutes();
|
|
81
|
-
|
|
82
|
-
else app.server = Bun.serve(serve);
|
|
121
|
+
app.server.reload(serve);
|
|
83
122
|
}
|
|
84
123
|
flushMemory();
|
|
85
124
|
if (hasWs) callback?.(app.server);
|
package/dist/adapter/utils.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { HTTPHeaders } from "../types.js";
|
|
|
4
4
|
import { Context } from "../context.js";
|
|
5
5
|
//#region src/adapter/utils.d.ts
|
|
6
6
|
declare function handleFile(response: File | Blob, set?: Context['set'], request?: Request): Response;
|
|
7
|
+
declare function normalizeHeaders(set: Context['set']): void;
|
|
7
8
|
declare function parseSetCookies(headers: Headers, setCookie: string[]): Headers;
|
|
8
9
|
declare function responseToSetHeaders(response: Response, set?: Context['set']): {
|
|
9
10
|
headers: HTTPHeaders;
|
|
@@ -33,15 +34,17 @@ declare function createResponseHandler(handler: CreateHandlerParameter): (respon
|
|
|
33
34
|
*
|
|
34
35
|
* To prevent long/infinite stream, the unconsumed window is capped:
|
|
35
36
|
* Consumed-by-every-branch entries are trimmed off the front
|
|
36
|
-
* Producer backpressures whenever the window hits `cap`
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* Producer backpressures whenever the window hits `cap` ENTRIES or
|
|
38
|
+
* `capBytes` bytes, whichever comes first
|
|
39
|
+
*
|
|
40
|
+
* Streams below both caps buffer eagerly
|
|
41
|
+
* Only streams exceeding one gate on the slowest consumer
|
|
39
42
|
*
|
|
40
43
|
* Branch 0 is the value consumer (response/client)
|
|
41
|
-
* When
|
|
44
|
+
* When `return()` (client abort / early exit), source is stopped
|
|
42
45
|
* so the observer branches can still reach completion instead of spinning
|
|
43
|
-
* an infinite source
|
|
46
|
+
* an infinite source
|
|
44
47
|
*/
|
|
45
|
-
declare function tee<T>(source: AsyncIterable<T>, branches?: number, cap?: number):
|
|
48
|
+
declare function tee<T>(source: AsyncIterable<T>, branches?: number, cap?: number, capBytes?: number): AsyncIterableIterator<T>[];
|
|
46
49
|
//#endregion
|
|
47
|
-
export { createResponseHandler, createStreamHandler, handleFile, handleSet, mergeHeaders, mergeStatus, parseSetCookies, responseToSetHeaders, streamResponse, tee };
|
|
50
|
+
export { createResponseHandler, createStreamHandler, handleFile, handleSet, mergeHeaders, mergeStatus, normalizeHeaders, parseSetCookies, responseToSetHeaders, streamResponse, tee };
|