elysia 1.4.29 → 2.0.0-exp.0
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 +45 -0
- package/dist/_virtual/_rolldown/runtime.mjs +36 -0
- package/dist/adapter/bun/index.d.ts +30 -6
- package/dist/adapter/bun/index.js +81 -381
- package/dist/adapter/bun/index.mjs +79 -383
- package/dist/adapter/bun/router.d.ts +10 -0
- package/dist/adapter/bun/router.js +86 -0
- package/dist/adapter/bun/router.mjs +83 -0
- package/dist/adapter/constants.d.ts +29 -0
- package/dist/adapter/constants.js +10 -0
- package/dist/adapter/constants.mjs +9 -0
- package/dist/adapter/index.d.ts +32 -1
- package/dist/adapter/index.js +25 -14
- package/dist/adapter/index.mjs +23 -0
- package/dist/adapter/types.d.ts +72 -122
- package/dist/adapter/types.js +1 -14
- package/dist/adapter/types.mjs +1 -0
- package/dist/adapter/utils.d.ts +45 -19
- package/dist/adapter/utils.js +364 -309
- package/dist/adapter/utils.mjs +354 -281
- package/dist/adapter/web-standard/handler.d.ts +11 -9
- package/dist/adapter/web-standard/handler.js +141 -415
- package/dist/adapter/web-standard/handler.mjs +138 -399
- package/dist/adapter/web-standard/index.d.ts +29 -2
- package/dist/adapter/web-standard/index.js +25 -164
- package/dist/adapter/web-standard/index.mjs +25 -149
- package/dist/adapter/web-standard/utils.d.ts +4 -0
- package/dist/adapter/web-standard/utils.js +146 -0
- package/dist/adapter/web-standard/utils.mjs +145 -0
- package/dist/base.d.ts +1075 -0
- package/dist/base.js +1019 -0
- package/dist/base.mjs +1016 -0
- package/dist/compile/aot.d.ts +169 -0
- package/dist/compile/aot.js +287 -0
- package/dist/compile/aot.mjs +275 -0
- package/dist/compile/handler/constants.d.ts +1 -0
- package/dist/compile/handler/constants.js +1 -0
- package/dist/compile/handler/constants.mjs +1 -0
- package/dist/compile/handler/index.d.ts +9 -0
- package/dist/compile/handler/index.js +605 -0
- package/dist/compile/handler/index.mjs +602 -0
- package/dist/compile/handler/params.d.ts +24 -0
- package/dist/compile/handler/params.js +57 -0
- package/dist/compile/handler/params.mjs +55 -0
- package/dist/compile/handler/utils.d.ts +29 -0
- package/dist/compile/handler/utils.js +442 -0
- package/dist/compile/handler/utils.mjs +431 -0
- package/dist/compile/index.d.ts +3 -0
- package/dist/compile/index.js +7 -0
- package/dist/compile/index.mjs +4 -0
- package/dist/compile/types.d.ts +4 -0
- package/dist/compile/types.js +1 -0
- package/dist/compile/types.mjs +1 -0
- package/dist/compile/utils.d.ts +7 -0
- package/dist/compile/utils.js +11 -0
- package/dist/compile/utils.mjs +8 -0
- package/dist/compiled.d.ts +17 -0
- package/dist/compiled.js +20 -0
- package/dist/compiled.mjs +16 -0
- package/dist/constants.d.ts +158 -0
- package/dist/constants.js +96 -0
- package/dist/constants.mjs +88 -0
- package/dist/context.d.ts +113 -126
- package/dist/context.js +77 -14
- package/dist/context.mjs +74 -0
- package/dist/cookie/config.d.ts +27 -0
- package/dist/cookie/config.js +100 -0
- package/dist/cookie/config.mjs +98 -0
- package/dist/cookie/cookie.d.ts +28 -0
- package/dist/cookie/cookie.js +88 -0
- package/dist/cookie/cookie.mjs +86 -0
- package/dist/cookie/index.d.ts +4 -0
- package/dist/cookie/index.js +10 -0
- package/dist/cookie/index.mjs +4 -0
- package/dist/cookie/lib.d.ts +7 -0
- package/dist/cookie/lib.js +74 -0
- package/dist/cookie/lib.mjs +72 -0
- package/dist/cookie/types.d.ts +115 -0
- package/dist/cookie/types.js +1 -0
- package/dist/cookie/types.mjs +1 -0
- package/dist/cookie/utils.d.ts +19 -0
- package/dist/cookie/utils.js +188 -0
- package/dist/cookie/utils.mjs +178 -0
- package/dist/error.d.ts +150 -190
- package/dist/error.js +283 -363
- package/dist/error.mjs +273 -332
- package/dist/handler/error.d.ts +7 -0
- package/dist/handler/error.js +74 -0
- package/dist/handler/error.mjs +73 -0
- package/dist/handler/fetch.d.ts +8 -0
- package/dist/handler/fetch.js +256 -0
- package/dist/handler/fetch.mjs +253 -0
- package/dist/handler/index.d.ts +4 -0
- package/dist/handler/index.js +9 -0
- package/dist/handler/index.mjs +5 -0
- package/dist/handler/utils.d.ts +6 -0
- package/dist/handler/utils.js +26 -0
- package/dist/handler/utils.mjs +23 -0
- package/dist/index.d.ts +16 -2198
- package/dist/index.js +54 -1947
- package/dist/index.mjs +17 -1986
- package/dist/memory.d.ts +4 -0
- package/dist/memory.js +17 -0
- package/dist/memory.mjs +16 -0
- package/dist/parse-query.d.ts +7 -9
- package/dist/parse-query.js +138 -165
- package/dist/parse-query.mjs +135 -134
- package/dist/plugin/bun.d.ts +24 -0
- package/dist/plugin/bun.js +49 -0
- package/dist/plugin/bun.mjs +48 -0
- package/dist/plugin/core.d.ts +35 -0
- package/dist/plugin/core.js +41 -0
- package/dist/plugin/core.mjs +36 -0
- package/dist/plugin/esbuild.d.ts +26 -0
- package/dist/plugin/esbuild.js +51 -0
- package/dist/plugin/esbuild.mjs +49 -0
- package/dist/plugin/source.d.ts +38 -0
- package/dist/plugin/source.js +235 -0
- package/dist/plugin/source.mjs +233 -0
- package/dist/plugin/vite.d.ts +29 -0
- package/dist/plugin/vite.js +43 -0
- package/dist/plugin/vite.mjs +42 -0
- package/dist/sucrose.d.ts +52 -59
- package/dist/sucrose.js +470 -307
- package/dist/sucrose.mjs +458 -275
- package/dist/trace.d.ts +172 -127
- package/dist/trace.js +274 -135
- package/dist/trace.mjs +272 -113
- package/dist/type/bridge.d.ts +50 -0
- package/dist/type/bridge.js +157 -0
- package/dist/type/bridge.mjs +63 -0
- package/dist/type/coerce.d.ts +43 -0
- package/dist/type/coerce.js +330 -0
- package/dist/type/coerce.mjs +321 -0
- package/dist/type/compat.d.ts +4 -0
- package/dist/type/compat.js +39 -0
- package/dist/type/compat.mjs +37 -0
- package/dist/type/constants.d.ts +25 -0
- package/dist/type/constants.js +36 -0
- package/dist/type/constants.mjs +32 -0
- package/dist/type/elysia/accelerate.d.ts +6 -0
- package/dist/type/elysia/accelerate.js +11 -0
- package/dist/type/elysia/accelerate.mjs +9 -0
- package/dist/type/elysia/array-buffer.d.ts +7 -0
- package/dist/type/elysia/array-buffer.js +21 -0
- package/dist/type/elysia/array-buffer.mjs +19 -0
- package/dist/type/elysia/array-string.d.ts +7 -0
- package/dist/type/elysia/array-string.js +28 -0
- package/dist/type/elysia/array-string.mjs +26 -0
- package/dist/type/elysia/array.d.ts +6 -0
- package/dist/type/elysia/array.js +26 -0
- package/dist/type/elysia/array.mjs +25 -0
- package/dist/type/elysia/boolean-string.d.ts +6 -0
- package/dist/type/elysia/boolean-string.js +24 -0
- package/dist/type/elysia/boolean-string.mjs +22 -0
- package/dist/type/elysia/boolean.d.ts +6 -0
- package/dist/type/elysia/boolean.js +17 -0
- package/dist/type/elysia/boolean.mjs +15 -0
- package/dist/type/elysia/cookie.d.ts +18 -0
- package/dist/type/elysia/cookie.js +54 -0
- package/dist/type/elysia/cookie.mjs +53 -0
- package/dist/type/elysia/date.d.ts +7 -0
- package/dist/type/elysia/date.js +60 -0
- package/dist/type/elysia/date.mjs +58 -0
- package/dist/type/elysia/file-type.d.ts +24 -0
- package/dist/type/elysia/file-type.js +83 -0
- package/dist/type/elysia/file-type.mjs +73 -0
- package/dist/type/elysia/file.d.ts +9 -0
- package/dist/type/elysia/file.js +58 -0
- package/dist/type/elysia/file.mjs +42 -0
- package/dist/type/elysia/files.d.ts +8 -0
- package/dist/type/elysia/files.js +35 -0
- package/dist/type/elysia/files.mjs +33 -0
- package/dist/type/elysia/form.d.ts +8 -0
- package/dist/type/elysia/form.js +17 -0
- package/dist/type/elysia/form.mjs +15 -0
- package/dist/type/elysia/integer-string.d.ts +7 -0
- package/dist/type/elysia/integer-string.js +37 -0
- package/dist/type/elysia/integer-string.mjs +35 -0
- package/dist/type/elysia/integer.d.ts +6 -0
- package/dist/type/elysia/integer.js +17 -0
- package/dist/type/elysia/integer.mjs +15 -0
- package/dist/type/elysia/intersect.d.ts +6 -0
- package/dist/type/elysia/intersect.js +17 -0
- package/dist/type/elysia/intersect.mjs +16 -0
- package/dist/type/elysia/maybe-empty.d.ts +6 -0
- package/dist/type/elysia/maybe-empty.js +19 -0
- package/dist/type/elysia/maybe-empty.mjs +17 -0
- package/dist/type/elysia/no-validate.d.ts +6 -0
- package/dist/type/elysia/no-validate.js +9 -0
- package/dist/type/elysia/no-validate.mjs +8 -0
- package/dist/type/elysia/nullable.d.ts +6 -0
- package/dist/type/elysia/nullable.js +12 -0
- package/dist/type/elysia/nullable.mjs +10 -0
- package/dist/type/elysia/number.d.ts +6 -0
- package/dist/type/elysia/number.js +17 -0
- package/dist/type/elysia/number.mjs +15 -0
- package/dist/type/elysia/numeric-enum.d.ts +11 -0
- package/dist/type/elysia/numeric-enum.js +25 -0
- package/dist/type/elysia/numeric-enum.mjs +23 -0
- package/dist/type/elysia/numeric.d.ts +7 -0
- package/dist/type/elysia/numeric.js +35 -0
- package/dist/type/elysia/numeric.mjs +33 -0
- package/dist/type/elysia/object-string.d.ts +7 -0
- package/dist/type/elysia/object-string.js +28 -0
- package/dist/type/elysia/object-string.mjs +26 -0
- package/dist/type/elysia/object.d.ts +6 -0
- package/dist/type/elysia/object.js +41 -0
- package/dist/type/elysia/object.mjs +40 -0
- package/dist/type/elysia/optional.d.ts +6 -0
- package/dist/type/elysia/optional.js +17 -0
- package/dist/type/elysia/optional.mjs +15 -0
- package/dist/type/elysia/string.d.ts +6 -0
- package/dist/type/elysia/string.js +27 -0
- package/dist/type/elysia/string.mjs +25 -0
- package/dist/type/elysia/uint8-array.d.ts +7 -0
- package/dist/type/elysia/uint8-array.js +21 -0
- package/dist/type/elysia/uint8-array.mjs +19 -0
- package/dist/type/elysia/union-enum.d.ts +7 -0
- package/dist/type/elysia/union-enum.js +30 -0
- package/dist/type/elysia/union-enum.mjs +28 -0
- package/dist/type/elysia/union.d.ts +6 -0
- package/dist/type/elysia/union.js +17 -0
- package/dist/type/elysia/union.mjs +16 -0
- package/dist/type/elysia/utils.d.ts +52 -0
- package/dist/type/elysia/utils.js +104 -0
- package/dist/type/elysia/utils.mjs +95 -0
- package/dist/type/exports.d.ts +36 -0
- package/dist/type/exports.js +103 -0
- package/dist/type/exports.mjs +66 -0
- package/dist/type/index.d.ts +9 -0
- package/dist/type/index.js +46 -0
- package/dist/type/index.mjs +31 -0
- package/dist/type/types.d.ts +194 -0
- package/dist/type/types.js +1 -0
- package/dist/type/types.mjs +1 -0
- package/dist/type/utils.d.ts +7 -0
- package/dist/type/utils.js +77 -0
- package/dist/type/utils.mjs +75 -0
- package/dist/type/validator.d.ts +44 -0
- package/dist/type/validator.js +603 -0
- package/dist/type/validator.mjs +599 -0
- package/dist/types.d.ts +835 -1238
- package/dist/types.js +1 -14
- package/dist/types.mjs +1 -0
- package/dist/universal/constants.d.ts +8 -0
- package/dist/universal/constants.js +23 -0
- package/dist/universal/constants.mjs +17 -0
- package/dist/universal/env.d.ts +4 -1
- package/dist/universal/env.js +8 -26
- package/dist/universal/env.mjs +7 -5
- package/dist/universal/file.d.ts +48 -86
- package/dist/universal/file.js +87 -158
- package/dist/universal/file.mjs +82 -133
- package/dist/universal/index.d.ts +4 -3
- package/dist/universal/index.js +6 -27
- package/dist/universal/index.mjs +3 -5
- package/dist/universal/server.d.ts +317 -313
- package/dist/universal/server.js +1 -14
- package/dist/universal/server.mjs +1 -0
- package/dist/universal/types.d.ts +117 -114
- package/dist/universal/types.js +19 -40
- package/dist/universal/types.mjs +16 -18
- package/dist/utils.d.ts +118 -193
- package/dist/utils.js +442 -692
- package/dist/utils.mjs +408 -629
- package/dist/validator/index.d.ts +62 -0
- package/dist/validator/index.js +203 -0
- package/dist/validator/index.mjs +200 -0
- package/dist/validator/route.d.ts +33 -0
- package/dist/validator/route.js +49 -0
- package/dist/validator/route.mjs +48 -0
- package/dist/ws/context.d.ts +48 -0
- package/dist/ws/context.js +189 -0
- package/dist/ws/context.mjs +187 -0
- package/dist/ws/index.d.ts +5 -77
- package/dist/ws/index.js +11 -180
- package/dist/ws/index.mjs +5 -157
- package/dist/ws/parser.d.ts +8 -0
- package/dist/ws/parser.js +64 -0
- package/dist/ws/parser.mjs +61 -0
- package/dist/ws/route.d.ts +11 -0
- package/dist/ws/route.js +335 -0
- package/dist/ws/route.mjs +333 -0
- package/dist/ws/types.d.ts +112 -57
- package/dist/ws/types.js +1 -14
- package/dist/ws/types.mjs +1 -0
- package/package.json +108 -111
- package/bunfig.toml +0 -2
- package/dist/adapter/bun/compose.d.ts +0 -3
- package/dist/adapter/bun/compose.js +0 -90
- package/dist/adapter/bun/compose.mjs +0 -74
- package/dist/adapter/bun/handler-native.d.ts +0 -3
- package/dist/adapter/bun/handler-native.js +0 -42
- package/dist/adapter/bun/handler-native.mjs +0 -22
- package/dist/adapter/bun/handler.d.ts +0 -7
- package/dist/adapter/bun/handler.js +0 -363
- package/dist/adapter/bun/handler.mjs +0 -346
- package/dist/adapter/cloudflare-worker/index.d.ts +0 -20
- package/dist/adapter/cloudflare-worker/index.js +0 -59
- package/dist/adapter/cloudflare-worker/index.mjs +0 -39
- package/dist/compose.d.ts +0 -30
- package/dist/compose.js +0 -1324
- package/dist/compose.mjs +0 -1336
- package/dist/cookies.d.ts +0 -158
- package/dist/cookies.js +0 -250
- package/dist/cookies.mjs +0 -221
- package/dist/dynamic-handle.d.ts +0 -15
- package/dist/dynamic-handle.js +0 -533
- package/dist/dynamic-handle.mjs +0 -521
- package/dist/formats.d.ts +0 -79
- package/dist/formats.js +0 -153
- package/dist/formats.mjs +0 -132
- package/dist/manifest.d.ts +0 -0
- package/dist/manifest.js +0 -1
- package/dist/manifest.mjs +0 -0
- package/dist/replace-schema.d.ts +0 -60
- package/dist/replace-schema.js +0 -140
- package/dist/replace-schema.mjs +0 -115
- package/dist/schema.d.ts +0 -107
- package/dist/schema.js +0 -833
- package/dist/schema.mjs +0 -814
- package/dist/type-system/format.d.ts +0 -55
- package/dist/type-system/format.js +0 -197
- package/dist/type-system/format.mjs +0 -175
- package/dist/type-system/index.d.ts +0 -45
- package/dist/type-system/index.js +0 -406
- package/dist/type-system/index.mjs +0 -394
- package/dist/type-system/types.d.ts +0 -155
- package/dist/type-system/types.js +0 -14
- package/dist/type-system/types.mjs +0 -0
- package/dist/type-system/utils.d.ts +0 -62
- package/dist/type-system/utils.js +0 -141
- package/dist/type-system/utils.mjs +0 -111
- package/dist/universal/request.d.ts +0 -29
- package/dist/universal/request.js +0 -126
- package/dist/universal/request.mjs +0 -105
- package/dist/universal/utils.d.ts +0 -3
- package/dist/universal/utils.js +0 -41
- package/dist/universal/utils.mjs +0 -18
- package/dist/ws/bun.d.ts +0 -419
- package/dist/ws/bun.js +0 -14
- package/dist/ws/bun.mjs +0 -0
- package/knip.json +0 -22
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
24
|
+
key = keys[i];
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
37
|
+
value: mod,
|
|
38
|
+
enumerable: true
|
|
39
|
+
}) : target, mod));
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
|
|
43
|
+
exports.__exportAll = __exportAll;
|
|
44
|
+
exports.__reExport = __reExport;
|
|
45
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __exportAll = (all, no_symbols) => {
|
|
7
|
+
let target = {};
|
|
8
|
+
for (var name in all) {
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (!no_symbols) {
|
|
15
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
|
+
}
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
22
|
+
key = keys[i];
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: ((k) => from[k]).bind(null, key),
|
|
26
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { __exportAll, __reExport };
|
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ListenCallback, Serve } from "../../universal/server.js";
|
|
2
|
+
import { AnyLocalHook, MaybePromise } from "../../types.js";
|
|
3
|
+
import { Context } from "../../context.js";
|
|
4
|
+
import { AnyElysia } from "../../base.js";
|
|
5
|
+
//#region src/adapter/bun/index.d.ts
|
|
6
|
+
declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, Promise<void>[]] | undefined;
|
|
7
|
+
declare const BunAdapter: {
|
|
8
|
+
parse: {
|
|
9
|
+
default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
|
|
10
|
+
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
11
|
+
text: (context: Context) => MaybePromise<string>;
|
|
12
|
+
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
13
|
+
arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
|
|
14
|
+
formData: (context: Context) => MaybePromise<Record<string, unknown>>;
|
|
15
|
+
};
|
|
16
|
+
name: string;
|
|
17
|
+
runtime: "node" | "deno" | "bun" | "cloudflare-worker" | "browser" | "vercel" | "netlify" | "lambda" | "fastly" | "edge" | "unknown" | (string & {});
|
|
18
|
+
isWebStandard: boolean;
|
|
19
|
+
listen?(app: AnyElysia, options: string | number | Partial<Serve>, callback?: ListenCallback): void;
|
|
20
|
+
stop?(app: AnyElysia, closeActiveConnections?: boolean): Promise<void>;
|
|
21
|
+
response: {
|
|
22
|
+
map(response: unknown, set: Context["set"], ...params: unknown[]): unknown;
|
|
23
|
+
compact?(response: unknown, ...params: unknown[]): unknown;
|
|
24
|
+
static?(handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"], ...params: unknown[]): (() => unknown) | undefined;
|
|
25
|
+
nativeStatic?(handle: unknown, hooks: AnyLocalHook, set?: Context["set"]): (() => MaybePromise<Response>) | undefined;
|
|
26
|
+
};
|
|
27
|
+
fetch?(app: AnyElysia): (request: Request) => MaybePromise<Response>;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { BunAdapter, collectStaticRoutes };
|
|
@@ -1,382 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (r1[key] && r2[key]) {
|
|
81
|
-
if (typeof r1[key] == "function" || r1[key] instanceof Response) {
|
|
82
|
-
r1[key] = r2[key];
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
r1[key] = {
|
|
86
|
-
...r1[key],
|
|
87
|
-
...r2[key]
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return r1;
|
|
92
|
-
}, removeTrailingPath = (routes) => {
|
|
93
|
-
for (const key of Object.keys(routes))
|
|
94
|
-
key.length > 1 && key.charCodeAt(key.length - 1) === 47 && (routes[key.slice(0, -1)] = routes[key], delete routes[key]);
|
|
95
|
-
return routes;
|
|
96
|
-
}, BunAdapter = {
|
|
97
|
-
...import_web_standard.WebStandardAdapter,
|
|
98
|
-
name: "bun",
|
|
99
|
-
handler: {
|
|
100
|
-
mapResponse: import_handler.mapResponse,
|
|
101
|
-
mapEarlyResponse: import_handler.mapEarlyResponse,
|
|
102
|
-
mapCompactResponse: import_handler.mapCompactResponse,
|
|
103
|
-
createStaticHandler: import_handler.createStaticHandler,
|
|
104
|
-
createNativeStaticHandler: import_handler_native.createNativeStaticHandler
|
|
105
|
-
},
|
|
106
|
-
composeHandler: {
|
|
107
|
-
...import_web_standard.WebStandardAdapter.composeHandler,
|
|
108
|
-
headers: import_utils2.hasHeaderShorthand ? `c.headers=c.request.headers.toJSON()
|
|
109
|
-
` : `c.headers={}
|
|
110
|
-
for(const [k,v] of c.request.headers.entries())c.headers[k]=v
|
|
111
|
-
`
|
|
112
|
-
},
|
|
113
|
-
listen(app) {
|
|
114
|
-
return (options, callback) => {
|
|
115
|
-
if (typeof Bun > "u")
|
|
116
|
-
throw new Error(
|
|
117
|
-
".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch"
|
|
118
|
-
);
|
|
119
|
-
if (app.compile(), typeof options == "string") {
|
|
120
|
-
if (!(0, import_utils2.isNumericString)(options))
|
|
121
|
-
throw new Error("Port must be a numeric value");
|
|
122
|
-
options = parseInt(options);
|
|
123
|
-
}
|
|
124
|
-
const createStaticRoute = (iterator, { withAsync = !1 } = {}) => {
|
|
125
|
-
const staticRoutes = {}, ops = [];
|
|
126
|
-
for (let [path, route] of Object.entries(iterator))
|
|
127
|
-
if (path = encodeURI(path), import_utils2.supportPerMethodInlineHandler) {
|
|
128
|
-
if (!route) continue;
|
|
129
|
-
for (const [method, value] of Object.entries(route))
|
|
130
|
-
if (!(!value || !(method in supportedMethods))) {
|
|
131
|
-
if (value instanceof Promise) {
|
|
132
|
-
withAsync && (staticRoutes[path] || (staticRoutes[path] = {}), ops.push(
|
|
133
|
-
value.then((awaited) => {
|
|
134
|
-
awaited instanceof Response && (staticRoutes[path][method] = awaited), isHTMLBundle(awaited) && (staticRoutes[path][method] = awaited);
|
|
135
|
-
})
|
|
136
|
-
));
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
!(value instanceof Response) && !isHTMLBundle(value) || (staticRoutes[path] || (staticRoutes[path] = {}), staticRoutes[path][method] = value);
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
if (!route) continue;
|
|
143
|
-
if (route instanceof Promise) {
|
|
144
|
-
withAsync && (staticRoutes[path] || (staticRoutes[path] = {}), ops.push(
|
|
145
|
-
route.then((awaited) => {
|
|
146
|
-
awaited instanceof Response && (staticRoutes[path] = awaited);
|
|
147
|
-
})
|
|
148
|
-
));
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (!(route instanceof Response)) continue;
|
|
152
|
-
staticRoutes[path] = route;
|
|
153
|
-
}
|
|
154
|
-
return withAsync ? Promise.all(ops).then(() => staticRoutes) : staticRoutes;
|
|
155
|
-
}, routes = removeTrailingPath(
|
|
156
|
-
mergeRoutes(
|
|
157
|
-
mergeRoutes(
|
|
158
|
-
createStaticRoute(app.router.response),
|
|
159
|
-
mapRoutes(app)
|
|
160
|
-
),
|
|
161
|
-
// @ts-ignore
|
|
162
|
-
app.config.serve?.routes
|
|
163
|
-
)
|
|
164
|
-
), serve = typeof options == "object" ? {
|
|
165
|
-
development: !import_error.isProduction,
|
|
166
|
-
reusePort: !0,
|
|
167
|
-
idleTimeout: 30,
|
|
168
|
-
...app.config.serve || {},
|
|
169
|
-
...options || {},
|
|
170
|
-
routes,
|
|
171
|
-
websocket: {
|
|
172
|
-
...app.config.websocket || {},
|
|
173
|
-
...import_ws.websocket || {},
|
|
174
|
-
...options.websocket || {}
|
|
175
|
-
},
|
|
176
|
-
fetch: app.fetch
|
|
177
|
-
} : {
|
|
178
|
-
development: !import_error.isProduction,
|
|
179
|
-
reusePort: !0,
|
|
180
|
-
idleTimeout: 30,
|
|
181
|
-
...app.config.serve || {},
|
|
182
|
-
routes,
|
|
183
|
-
websocket: {
|
|
184
|
-
...app.config.websocket || {},
|
|
185
|
-
...import_ws.websocket || {}
|
|
186
|
-
},
|
|
187
|
-
port: options,
|
|
188
|
-
fetch: app.fetch
|
|
189
|
-
};
|
|
190
|
-
if (app.server = Bun.serve(serve), app.event.start)
|
|
191
|
-
for (let i = 0; i < app.event.start.length; i++)
|
|
192
|
-
app.event.start[i].fn(app);
|
|
193
|
-
callback && callback(app.server), process.on("beforeExit", async () => {
|
|
194
|
-
if (app.server && (await app.server.stop?.(), app.server = null, app.event.stop))
|
|
195
|
-
for (let i = 0; i < app.event.stop.length; i++)
|
|
196
|
-
app.event.stop[i].fn(app);
|
|
197
|
-
}), app.promisedModules.then(async () => {
|
|
198
|
-
app.config.aot, app.compile();
|
|
199
|
-
const routes2 = removeTrailingPath(
|
|
200
|
-
mergeRoutes(
|
|
201
|
-
mergeRoutes(
|
|
202
|
-
await createStaticRoute(app.router.response, {
|
|
203
|
-
withAsync: !0
|
|
204
|
-
}),
|
|
205
|
-
mapRoutes(app)
|
|
206
|
-
),
|
|
207
|
-
// @ts-ignore
|
|
208
|
-
app.config.serve?.routes
|
|
209
|
-
)
|
|
210
|
-
);
|
|
211
|
-
app.server?.reload({
|
|
212
|
-
...serve,
|
|
213
|
-
fetch: app.fetch,
|
|
214
|
-
// @ts-ignore
|
|
215
|
-
routes: routes2
|
|
216
|
-
}), Bun?.gc(!1);
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
},
|
|
220
|
-
async stop(app, closeActiveConnections) {
|
|
221
|
-
if (app.server) {
|
|
222
|
-
if (await app.server.stop(closeActiveConnections), app.server = null, app.event.stop?.length)
|
|
223
|
-
for (let i = 0; i < app.event.stop.length; i++)
|
|
224
|
-
app.event.stop[i].fn(app);
|
|
225
|
-
} else
|
|
226
|
-
console.log(
|
|
227
|
-
"Elysia isn't running. Call `app.listen` to start the server.",
|
|
228
|
-
new Error().stack
|
|
229
|
-
);
|
|
230
|
-
},
|
|
231
|
-
ws(app, path, options) {
|
|
232
|
-
const { parse, body, response, ...rest } = options, messageValidator = (0, import_schema.getSchemaValidator)(body, {
|
|
233
|
-
// @ts-expect-error private property
|
|
234
|
-
modules: app.definitions.typebox,
|
|
235
|
-
// @ts-expect-error private property
|
|
236
|
-
models: app.definitions.type,
|
|
237
|
-
normalize: app.config.normalize
|
|
238
|
-
}), validateMessage = messageValidator ? messageValidator.provider === "standard" ? (data) => messageValidator.schema["~standard"].validate(data).issues : (data) => messageValidator.Check(data) === !1 : void 0, responseValidator = (0, import_schema.getSchemaValidator)(response, {
|
|
239
|
-
// @ts-expect-error private property
|
|
240
|
-
modules: app.definitions.typebox,
|
|
241
|
-
// @ts-expect-error private property
|
|
242
|
-
models: app.definitions.type,
|
|
243
|
-
normalize: app.config.normalize
|
|
244
|
-
});
|
|
245
|
-
app.route(
|
|
246
|
-
"WS",
|
|
247
|
-
path,
|
|
248
|
-
async (context) => {
|
|
249
|
-
const server = context.server ?? app.server, { set, path: path2, qi, headers, query, params } = context;
|
|
250
|
-
if (context.validator = responseValidator, options.upgrade)
|
|
251
|
-
if (typeof options.upgrade == "function") {
|
|
252
|
-
const temp = options.upgrade(context);
|
|
253
|
-
temp instanceof Promise && await temp;
|
|
254
|
-
} else options.upgrade && Object.assign(
|
|
255
|
-
set.headers,
|
|
256
|
-
options.upgrade
|
|
257
|
-
);
|
|
258
|
-
if (set.cookie && (0, import_utils2.isNotEmpty)(set.cookie)) {
|
|
259
|
-
const cookie = (0, import_cookies.serializeCookie)(set.cookie);
|
|
260
|
-
cookie && (set.headers["set-cookie"] = cookie);
|
|
261
|
-
}
|
|
262
|
-
set.headers["set-cookie"] && Array.isArray(set.headers["set-cookie"]) && (set.headers = (0, import_utils.parseSetCookies)(
|
|
263
|
-
new Headers(set.headers),
|
|
264
|
-
set.headers["set-cookie"]
|
|
265
|
-
));
|
|
266
|
-
const handleResponse = (0, import_ws.createHandleWSResponse)(responseValidator), parseMessage = (0, import_ws.createWSMessageParser)(parse);
|
|
267
|
-
let _id;
|
|
268
|
-
if (typeof options.beforeHandle == "function") {
|
|
269
|
-
const result = options.beforeHandle(context);
|
|
270
|
-
result instanceof Promise && await result;
|
|
271
|
-
}
|
|
272
|
-
const errorHandlers = [
|
|
273
|
-
...options.error ? Array.isArray(options.error) ? options.error : [options.error] : [],
|
|
274
|
-
...(app.event.error ?? []).map(
|
|
275
|
-
(x) => typeof x == "function" ? x : x.fn
|
|
276
|
-
)
|
|
277
|
-
].filter((x) => x), hasCustomErrorHandlers = errorHandlers.length > 0, handleErrors = hasCustomErrorHandlers ? async (ws, error) => {
|
|
278
|
-
for (const handleError of errorHandlers) {
|
|
279
|
-
let response2 = handleError(
|
|
280
|
-
Object.assign(context, { error })
|
|
281
|
-
);
|
|
282
|
-
if (response2 instanceof Promise && (response2 = await response2), await handleResponse(ws, response2), response2) break;
|
|
283
|
-
}
|
|
284
|
-
} : () => {
|
|
285
|
-
};
|
|
286
|
-
if (!server?.upgrade(context.request, {
|
|
287
|
-
headers: (0, import_utils2.isNotEmpty)(set.headers) ? set.headers : void 0,
|
|
288
|
-
data: {
|
|
289
|
-
...context,
|
|
290
|
-
get id() {
|
|
291
|
-
return _id || (_id = (0, import_utils2.randomId)());
|
|
292
|
-
},
|
|
293
|
-
validator: responseValidator,
|
|
294
|
-
ping(ws, data) {
|
|
295
|
-
options.ping?.(ws, data);
|
|
296
|
-
},
|
|
297
|
-
pong(ws, data) {
|
|
298
|
-
options.pong?.(ws, data);
|
|
299
|
-
},
|
|
300
|
-
open: async (ws) => {
|
|
301
|
-
try {
|
|
302
|
-
await handleResponse(
|
|
303
|
-
ws,
|
|
304
|
-
options.open?.(
|
|
305
|
-
new import_ws.ElysiaWS(ws, context)
|
|
306
|
-
)
|
|
307
|
-
);
|
|
308
|
-
} catch (error) {
|
|
309
|
-
handleErrors(ws, error);
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
message: async (ws, _message) => {
|
|
313
|
-
const message = await parseMessage(ws, _message);
|
|
314
|
-
if (validateMessage && validateMessage(message)) {
|
|
315
|
-
const validationError = new import_error.ValidationError(
|
|
316
|
-
"message",
|
|
317
|
-
messageValidator,
|
|
318
|
-
message
|
|
319
|
-
);
|
|
320
|
-
return hasCustomErrorHandlers ? handleErrors(ws, validationError) : void ws.send(
|
|
321
|
-
validationError.message
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
try {
|
|
325
|
-
await handleResponse(
|
|
326
|
-
ws,
|
|
327
|
-
options.message?.(
|
|
328
|
-
new import_ws.ElysiaWS(
|
|
329
|
-
ws,
|
|
330
|
-
context,
|
|
331
|
-
message
|
|
332
|
-
),
|
|
333
|
-
message
|
|
334
|
-
)
|
|
335
|
-
);
|
|
336
|
-
} catch (error) {
|
|
337
|
-
handleErrors(ws, error);
|
|
338
|
-
}
|
|
339
|
-
},
|
|
340
|
-
drain: async (ws) => {
|
|
341
|
-
try {
|
|
342
|
-
await handleResponse(
|
|
343
|
-
ws,
|
|
344
|
-
options.drain?.(
|
|
345
|
-
new import_ws.ElysiaWS(ws, context)
|
|
346
|
-
)
|
|
347
|
-
);
|
|
348
|
-
} catch (error) {
|
|
349
|
-
handleErrors(ws, error);
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
close: async (ws, code, reason) => {
|
|
353
|
-
try {
|
|
354
|
-
await handleResponse(
|
|
355
|
-
ws,
|
|
356
|
-
options.close?.(
|
|
357
|
-
new import_ws.ElysiaWS(ws, context),
|
|
358
|
-
code,
|
|
359
|
-
reason
|
|
360
|
-
)
|
|
361
|
-
);
|
|
362
|
-
} catch (error) {
|
|
363
|
-
handleErrors(ws, error);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}))
|
|
368
|
-
return (0, import_error.status)(400, "Expected a websocket connection");
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
...rest,
|
|
372
|
-
websocket: options
|
|
373
|
-
}
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
378
|
-
0 && (module.exports = {
|
|
379
|
-
BunAdapter,
|
|
380
|
-
isHTMLBundle,
|
|
381
|
-
removeTrailingPath
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_adapter_index = require('../index.js');
|
|
3
|
+
const require_utils = require('../../utils.js');
|
|
4
|
+
const require_adapter_web_standard_index = require('../web-standard/index.js');
|
|
5
|
+
const require_memory = require('../../memory.js');
|
|
6
|
+
const require_ws_route = require('../../ws/route.js');
|
|
7
|
+
|
|
8
|
+
//#region src/adapter/bun/index.ts
|
|
9
|
+
function collectStaticRoutes(app) {
|
|
10
|
+
if (app["~ext"]?.hoc?.length) return;
|
|
11
|
+
const hook = require_utils.flattenChain(app["~hookChain"]);
|
|
12
|
+
if (hook && (hook?.request?.length || hook?.mapResponse?.length || hook?.afterResponse?.length || hook?.trace?.length)) return;
|
|
13
|
+
app.fetch;
|
|
14
|
+
const source = app["~staticResponse"];
|
|
15
|
+
if (!source) return;
|
|
16
|
+
const ready = require_utils.nullObject();
|
|
17
|
+
const pending = [];
|
|
18
|
+
for (const rawPath in source) {
|
|
19
|
+
const path = encodeURI(rawPath);
|
|
20
|
+
const methods = source[rawPath];
|
|
21
|
+
for (const method in methods) {
|
|
22
|
+
const value = methods[method];
|
|
23
|
+
if (value instanceof Promise) pending.push(value.then((resolved) => {
|
|
24
|
+
if (resolved instanceof Response) (ready[path] ??= require_utils.nullObject())[method] = resolved;
|
|
25
|
+
}, (err) => {
|
|
26
|
+
console.error(`[Elysia] Static route ${method} ${path} failed to resolve:`, err);
|
|
27
|
+
}));
|
|
28
|
+
else (ready[path] ??= require_utils.nullObject())[method] = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return [ready, pending];
|
|
32
|
+
}
|
|
33
|
+
const BunAdapter = require_adapter_index.createAdapter({
|
|
34
|
+
...require_adapter_web_standard_index.WebStandardAdapter,
|
|
35
|
+
name: "bun",
|
|
36
|
+
runtime: "bun",
|
|
37
|
+
listen(app, options, callback) {
|
|
38
|
+
const serve = typeof options === "object" ? options : { port: +options };
|
|
39
|
+
const hasWs = app["~hasWS"];
|
|
40
|
+
serve.fetch = (request, server) => app.fetch(request, server);
|
|
41
|
+
app.server = Bun.serve(serve);
|
|
42
|
+
if (!hasWs) callback?.(app.server);
|
|
43
|
+
queueMicrotask(() => {
|
|
44
|
+
if (!app.pending) serve.fetch = app.fetch;
|
|
45
|
+
const buildWebSocket = () => {
|
|
46
|
+
const defaultConfig = app["~config"]?.websocket;
|
|
47
|
+
serve.websocket = defaultConfig ? Object.assign(require_ws_route.buildGlobalWSHandler(), defaultConfig) : require_ws_route.buildGlobalWSHandler();
|
|
48
|
+
};
|
|
49
|
+
if (hasWs) buildWebSocket();
|
|
50
|
+
const collectRoutes = () => {
|
|
51
|
+
const staticRoutes = collectStaticRoutes(app);
|
|
52
|
+
if (!staticRoutes) return;
|
|
53
|
+
if (staticRoutes[1].length) return Promise.all(staticRoutes[1]).then(() => {
|
|
54
|
+
serve.routes = staticRoutes[0];
|
|
55
|
+
app.server.reload(serve);
|
|
56
|
+
});
|
|
57
|
+
if (Object.keys(staticRoutes[0]).length) serve.routes = staticRoutes[0];
|
|
58
|
+
};
|
|
59
|
+
if (app.pending) {
|
|
60
|
+
if (app.server) app.server.reload(serve);
|
|
61
|
+
else app.server = Bun.serve(serve);
|
|
62
|
+
const reloadAfterModules = () => {
|
|
63
|
+
serve.fetch = app.fetch;
|
|
64
|
+
if (hasWs || app["~hasWS"]) buildWebSocket();
|
|
65
|
+
collectRoutes();
|
|
66
|
+
app.server.reload(serve);
|
|
67
|
+
};
|
|
68
|
+
app.modules.then(reloadAfterModules, reloadAfterModules);
|
|
69
|
+
} else {
|
|
70
|
+
collectRoutes();
|
|
71
|
+
if (app.server) app.server.reload(serve);
|
|
72
|
+
else app.server = Bun.serve(serve);
|
|
73
|
+
}
|
|
74
|
+
require_memory.flushMemory();
|
|
75
|
+
if (hasWs) callback?.(app.server);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
382
78
|
});
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
exports.BunAdapter = BunAdapter;
|
|
82
|
+
exports.collectStaticRoutes = collectStaticRoutes;
|