elysia 2.0.0-beta.26 → 2.0.0-beta.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/adapter/bun/index.js +0 -19
- package/dist/adapter/bun/index.mjs +0 -19
- package/dist/adapter/origin.js +0 -57
- package/dist/adapter/origin.mjs +0 -57
- package/dist/adapter/utils.d.ts +1 -1
- package/dist/adapter/utils.js +5 -35
- package/dist/adapter/utils.mjs +5 -35
- package/dist/adapter/web-standard/handler.js +9 -14
- package/dist/adapter/web-standard/handler.mjs +9 -14
- package/dist/base.d.ts +11 -11
- package/dist/base.js +26 -144
- package/dist/base.mjs +27 -145
- package/dist/compile/aot-capture.js +12 -19
- package/dist/compile/aot-capture.mjs +12 -19
- package/dist/compile/aot-emit.d.ts +1 -2
- package/dist/compile/aot-emit.js +5 -29
- package/dist/compile/aot-emit.mjs +6 -29
- package/dist/compile/aot-reconstruct.js +7 -30
- package/dist/compile/aot-reconstruct.mjs +7 -30
- package/dist/compile/aot.js +0 -7
- package/dist/compile/aot.mjs +0 -7
- package/dist/compile/handler/descriptor.d.ts +1 -2
- package/dist/compile/handler/descriptor.js +2 -5
- package/dist/compile/handler/descriptor.mjs +2 -4
- package/dist/compile/handler/frozen-validator.js +0 -11
- package/dist/compile/handler/frozen-validator.mjs +0 -11
- package/dist/compile/handler/index.js +10 -26
- package/dist/compile/handler/index.mjs +11 -27
- package/dist/compile/handler/jit.d.ts +5 -1
- package/dist/compile/handler/jit.js +7 -28
- package/dist/compile/handler/jit.mjs +9 -30
- package/dist/compile/handler/params.js +0 -3
- package/dist/compile/handler/params.mjs +0 -3
- package/dist/compile/handler/utils.d.ts +2 -1
- package/dist/compile/handler/utils.js +7 -16
- package/dist/compile/handler/utils.mjs +6 -16
- package/dist/compiled.js +0 -9
- package/dist/compiled.mjs +0 -9
- package/dist/constants.js +19 -4
- package/dist/constants.mjs +19 -4
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -7
- package/dist/context.mjs +1 -7
- package/dist/cookie/cookie.d.ts +7 -4
- package/dist/cookie/cookie.js +10 -5
- package/dist/cookie/cookie.mjs +10 -5
- package/dist/cookie/crypto.d.ts +1 -1
- package/dist/cookie/crypto.js +8 -7
- package/dist/cookie/crypto.mjs +8 -7
- package/dist/cookie/types.d.ts +1 -1
- package/dist/cookie/utils.js +5 -18
- package/dist/cookie/utils.mjs +5 -18
- package/dist/error.d.ts +5 -4
- package/dist/error.js +0 -73
- package/dist/error.mjs +0 -73
- package/dist/generation.d.ts +1 -1
- package/dist/handler/error.js +1 -28
- package/dist/handler/error.mjs +1 -28
- package/dist/handler/fetch.js +18 -30
- package/dist/handler/fetch.mjs +18 -30
- package/dist/handler/utils.js +5 -5
- package/dist/handler/utils.mjs +5 -5
- package/dist/index.d.ts +5 -5
- 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/parse-query.js +0 -4
- package/dist/parse-query.mjs +0 -4
- package/dist/plugin/aot/bun.js +0 -26
- package/dist/plugin/aot/bun.mjs +0 -26
- package/dist/plugin/aot/core.js +2 -34
- package/dist/plugin/aot/core.mjs +2 -34
- package/dist/plugin/aot/esbuild.js +0 -19
- package/dist/plugin/aot/esbuild.mjs +0 -19
- package/dist/plugin/aot/hooks.js +2 -4
- package/dist/plugin/aot/hooks.mjs +3 -5
- package/dist/plugin/aot/rspack-loader.js +0 -16
- package/dist/plugin/aot/rspack-loader.mjs +0 -16
- package/dist/plugin/aot/rspack.js +0 -14
- package/dist/plugin/aot/rspack.mjs +0 -14
- package/dist/plugin/aot/source.js +6 -8
- package/dist/plugin/aot/source.mjs +6 -8
- package/dist/plugin/aot/unplugin.js +0 -19
- package/dist/plugin/aot/unplugin.mjs +0 -19
- package/dist/plugin/aot/vite.js +0 -14
- package/dist/plugin/aot/vite.mjs +0 -14
- package/dist/plugin/trace.d.ts +16 -0
- package/dist/plugin/trace.js +0 -16
- package/dist/plugin/trace.mjs +0 -16
- package/dist/plugin/websocket.d.ts +21 -0
- package/dist/plugin/websocket.js +0 -21
- package/dist/plugin/websocket.mjs +0 -21
- package/dist/schema-snapshot.js +0 -4
- package/dist/schema-snapshot.mjs +0 -4
- package/dist/sucrose.d.ts +1 -1
- package/dist/sucrose.js +0 -4
- package/dist/sucrose.mjs +0 -4
- package/dist/trace.d.ts +1 -1
- package/dist/trace.js +0 -1
- package/dist/trace.mjs +0 -1
- package/dist/type/bridge.js +22 -20
- package/dist/type/bridge.mjs +22 -20
- package/dist/type/coerce-plan.d.ts +1 -1
- package/dist/type/coerce-plan.js +19 -12
- package/dist/type/coerce-plan.mjs +19 -12
- package/dist/type/coerce.js +0 -4
- package/dist/type/coerce.mjs +0 -4
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/date.d.ts +2 -1
- package/dist/type/elysia/file-type.js +3 -2
- package/dist/type/elysia/file-type.mjs +3 -2
- package/dist/type/elysia/numeric-enum.js +0 -4
- package/dist/type/elysia/numeric-enum.mjs +0 -4
- package/dist/type/elysia/problem.js +0 -6
- package/dist/type/elysia/problem.mjs +0 -6
- package/dist/type/elysia/union-enum.js +0 -1
- package/dist/type/elysia/union-enum.mjs +0 -1
- package/dist/type/elysia/utils.d.ts +2 -2
- package/dist/type/elysia/utils.js +5 -19
- package/dist/type/elysia/utils.mjs +5 -19
- package/dist/type/index.js +0 -11
- package/dist/type/index.mjs +0 -11
- package/dist/type/shared.d.ts +10 -2
- package/dist/type/shared.js +36 -17
- package/dist/type/shared.mjs +34 -17
- package/dist/type/sync-require.js +0 -7
- package/dist/type/sync-require.mjs +0 -7
- package/dist/type/typebox-type.js +1 -7
- package/dist/type/typebox-type.mjs +1 -7
- package/dist/type/typebox-value.js +0 -3
- package/dist/type/typebox-value.mjs +0 -3
- package/dist/type/types.d.ts +1 -1
- package/dist/type/validator/custom-error.js +1 -4
- package/dist/type/validator/custom-error.mjs +1 -4
- package/dist/type/validator/default-precompute.js +0 -7
- package/dist/type/validator/default-precompute.mjs +0 -7
- package/dist/type/validator/exact-mirror-live.js +0 -7
- package/dist/type/validator/exact-mirror-live.mjs +1 -7
- package/dist/type/validator/exact-mirror.js +15 -7
- package/dist/type/validator/exact-mirror.mjs +15 -7
- package/dist/type/validator/index.js +7 -19
- package/dist/type/validator/index.mjs +8 -20
- package/dist/type/validator/string-codec-aot.js +3 -5
- package/dist/type/validator/string-codec-aot.mjs +3 -5
- package/dist/types.d.ts +13 -21
- package/dist/universal/file.js +0 -7
- package/dist/universal/file.mjs +0 -7
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +11 -91
- package/dist/utils.mjs +11 -91
- package/dist/validator/route.d.ts +1 -8
- package/dist/ws/context.js +14 -15
- package/dist/ws/context.mjs +14 -15
- package/dist/ws/parser.js +2 -2
- package/dist/ws/parser.mjs +2 -2
- package/dist/ws/route.js +114 -58
- package/dist/ws/route.mjs +115 -59
- package/package.json +3 -8
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
<br>
|
|
17
17
|
|
|
18
|
-

|
|
19
19
|
|
|
20
20
|
<!---
|
|
21
21
|
```bash
|
|
@@ -52,15 +52,6 @@ async function settleServerWebSockets(lifecycle, errors) {
|
|
|
52
52
|
} while (lifecycle.sockets.size);
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* ! This may looks like it would cause race condition, but it is not
|
|
57
|
-
* Bun is single-threaded and synchronous, so the `finally` block will
|
|
58
|
-
* always run before the next request comes in
|
|
59
|
-
* @see ../origin.ts
|
|
60
|
-
*
|
|
61
|
-
* `finally` runs on the synchronous return of `fetch` (the returned promise is
|
|
62
|
-
* not awaited), so the slot is live only for the handler's synchronous prologue
|
|
63
|
-
*/
|
|
64
55
|
const withOrigin = (fetch) => (request, server) => {
|
|
65
56
|
require_adapter_origin.origin.request = request;
|
|
66
57
|
try {
|
|
@@ -92,16 +83,6 @@ function isNativePath(path) {
|
|
|
92
83
|
}
|
|
93
84
|
return true;
|
|
94
85
|
}
|
|
95
|
-
/**
|
|
96
|
-
* HTML bundles served by Bun's native router.
|
|
97
|
-
*
|
|
98
|
-
* A `:param` / `*` bundle matches before `fetch`, so with a `handoff` every
|
|
99
|
-
* other route of that method is registered natively too, pointing at `fetch`;
|
|
100
|
-
* Bun's specificity (exact > param > wildcard) then picks the Elysia route over
|
|
101
|
-
* the bundle (Elysia's own router skips these bundles, see `#buildRouterUnsafe`).
|
|
102
|
-
* If any route can't be expressed in Bun's router, dynamic bundles are skipped
|
|
103
|
-
* entirely, since the bundle would shadow that route.
|
|
104
|
-
*/
|
|
105
86
|
function collectHTMLBundleRoutes(app, handoff, routes) {
|
|
106
87
|
let dynamic;
|
|
107
88
|
let bundles;
|
|
@@ -52,15 +52,6 @@ async function settleServerWebSockets(lifecycle, errors) {
|
|
|
52
52
|
} while (lifecycle.sockets.size);
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* ! This may looks like it would cause race condition, but it is not
|
|
57
|
-
* Bun is single-threaded and synchronous, so the `finally` block will
|
|
58
|
-
* always run before the next request comes in
|
|
59
|
-
* @see ../origin.ts
|
|
60
|
-
*
|
|
61
|
-
* `finally` runs on the synchronous return of `fetch` (the returned promise is
|
|
62
|
-
* not awaited), so the slot is live only for the handler's synchronous prologue
|
|
63
|
-
*/
|
|
64
55
|
const withOrigin = (fetch) => (request, server) => {
|
|
65
56
|
origin.request = request;
|
|
66
57
|
try {
|
|
@@ -92,16 +83,6 @@ function isNativePath(path) {
|
|
|
92
83
|
}
|
|
93
84
|
return true;
|
|
94
85
|
}
|
|
95
|
-
/**
|
|
96
|
-
* HTML bundles served by Bun's native router.
|
|
97
|
-
*
|
|
98
|
-
* A `:param` / `*` bundle matches before `fetch`, so with a `handoff` every
|
|
99
|
-
* other route of that method is registered natively too, pointing at `fetch`;
|
|
100
|
-
* Bun's specificity (exact > param > wildcard) then picks the Elysia route over
|
|
101
|
-
* the bundle (Elysia's own router skips these bundles, see `#buildRouterUnsafe`).
|
|
102
|
-
* If any route can't be expressed in Bun's router, dynamic bundles are skipped
|
|
103
|
-
* entirely, since the bundle would shadow that route.
|
|
104
|
-
*/
|
|
105
86
|
function collectHTMLBundleRoutes(app, handoff, routes) {
|
|
106
87
|
let dynamic;
|
|
107
88
|
let bundles;
|
package/dist/adapter/origin.js
CHANGED
|
@@ -1,63 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
//#region src/adapter/origin.ts
|
|
4
|
-
/**
|
|
5
|
-
* Provenance channel for deferred abort-signal arming.
|
|
6
|
-
*
|
|
7
|
-
* Bun materializes `Request.signal` lazily (~214ns on the first read), so
|
|
8
|
-
* Elysia only pays for it once the pipeline can actually observe an abort,
|
|
9
|
-
* that is, after it suspends. Deferring that read is only sound for the exact
|
|
10
|
-
* `Request` instance `Bun.serve` handed to `fetch`: any other request
|
|
11
|
-
* (`app.handle`, a non-Bun adapter, or a `.wrap()` HOC that substitutes the
|
|
12
|
-
* request) may carry a user-controlled signal that is already aborted at entry
|
|
13
|
-
* and therefore must be observed synchronously.
|
|
14
|
-
*
|
|
15
|
-
* The Bun adapter publishes the untouched original here for the *synchronous*
|
|
16
|
-
* prologue of `app.fetch` and, on the lane where `fetch` has no request hook
|
|
17
|
-
* to run, for the compiled route's own entry probe, which is still inside that
|
|
18
|
-
* same synchronous frame, then clears it in `finally`, so the window closes
|
|
19
|
-
* before the first suspension and cannot leak across concurrent requests.
|
|
20
|
-
* A `.wrap()` HOC that replaces the request or defers calling `next()` past a
|
|
21
|
-
* microtask simply misses the window, fetch handler falls back to eager check
|
|
22
|
-
*
|
|
23
|
-
* ## "A single shared slot that every request writes to, so a race condition?"
|
|
24
|
-
*
|
|
25
|
-
* It looks like one, but it can't be. Explained like you're five:
|
|
26
|
-
*
|
|
27
|
-
* JavaScript only ever does ONE thing at a time. When a request comes in, the
|
|
28
|
-
* adapter writes its name on the whiteboard (`origin.request = request`),
|
|
29
|
-
* walks it down the hall (`fetch(request)` the synchronous part, where the
|
|
30
|
-
* one and only identity check happens, in `fetch`'s prologue, or at the
|
|
31
|
-
* compiled route's entry when `fetch` had no hook to run first), and erases
|
|
32
|
-
* the whiteboard `finally`
|
|
33
|
-
* all in one uninterruptible turn. The next request's turn CANNOT start
|
|
34
|
-
* until this turn is completely finished, because that is how the event loop
|
|
35
|
-
* works: run-to-completion, no preemption. So request B can never see request
|
|
36
|
-
* A's name on the board, by the time B's turn starts, the board was already
|
|
37
|
-
* erased at the end of A's turn.
|
|
38
|
-
*
|
|
39
|
-
* "But the handler is async!" the `await`s inside it run LATER, in separate
|
|
40
|
-
* turns. That is fine, because the check already happened: the verdict was
|
|
41
|
-
* copied onto that request's own context (`'~sig'`) during the synchronous
|
|
42
|
-
* part, and the code that runs after an `await` only ever reads the context,
|
|
43
|
-
* never this slot.
|
|
44
|
-
*
|
|
45
|
-
* And if any assumption here ever breaks, a runtime that re-enters, a wrap
|
|
46
|
-
* that delays, a future edit that sneaks an `await` in before the check the
|
|
47
|
-
* comparison simply MISSES and the request falls back to eager arming, which
|
|
48
|
-
* is the exact pre-optimization behavior. Every failure mode makes a request
|
|
49
|
-
* slightly slower, never incorrect
|
|
50
|
-
*
|
|
51
|
-
* Adversarial proof, not just argument: `test/core/abort-race.test.ts` storms
|
|
52
|
-
* concurrent servers, in-process `handle()` calls, request-substituting and
|
|
53
|
-
* `next()`-delaying wraps at this slot and asserts zero misclassification.
|
|
54
|
-
*
|
|
55
|
-
* Never infer the Bun runtime from `fetch`'s second argument: Cloudflare
|
|
56
|
-
* Workers pass `env` there.
|
|
57
|
-
*
|
|
58
|
-
* It's insanely stupid, but it works. As Bun is single-threaded and synchronous
|
|
59
|
-
* so the `finally` block will always run before the next request comes in.
|
|
60
|
-
*/
|
|
61
4
|
const origin = { request: void 0 };
|
|
62
5
|
|
|
63
6
|
//#endregion
|
package/dist/adapter/origin.mjs
CHANGED
|
@@ -1,62 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
//#region src/adapter/origin.ts
|
|
3
|
-
/**
|
|
4
|
-
* Provenance channel for deferred abort-signal arming.
|
|
5
|
-
*
|
|
6
|
-
* Bun materializes `Request.signal` lazily (~214ns on the first read), so
|
|
7
|
-
* Elysia only pays for it once the pipeline can actually observe an abort,
|
|
8
|
-
* that is, after it suspends. Deferring that read is only sound for the exact
|
|
9
|
-
* `Request` instance `Bun.serve` handed to `fetch`: any other request
|
|
10
|
-
* (`app.handle`, a non-Bun adapter, or a `.wrap()` HOC that substitutes the
|
|
11
|
-
* request) may carry a user-controlled signal that is already aborted at entry
|
|
12
|
-
* and therefore must be observed synchronously.
|
|
13
|
-
*
|
|
14
|
-
* The Bun adapter publishes the untouched original here for the *synchronous*
|
|
15
|
-
* prologue of `app.fetch` and, on the lane where `fetch` has no request hook
|
|
16
|
-
* to run, for the compiled route's own entry probe, which is still inside that
|
|
17
|
-
* same synchronous frame, then clears it in `finally`, so the window closes
|
|
18
|
-
* before the first suspension and cannot leak across concurrent requests.
|
|
19
|
-
* A `.wrap()` HOC that replaces the request or defers calling `next()` past a
|
|
20
|
-
* microtask simply misses the window, fetch handler falls back to eager check
|
|
21
|
-
*
|
|
22
|
-
* ## "A single shared slot that every request writes to, so a race condition?"
|
|
23
|
-
*
|
|
24
|
-
* It looks like one, but it can't be. Explained like you're five:
|
|
25
|
-
*
|
|
26
|
-
* JavaScript only ever does ONE thing at a time. When a request comes in, the
|
|
27
|
-
* adapter writes its name on the whiteboard (`origin.request = request`),
|
|
28
|
-
* walks it down the hall (`fetch(request)` the synchronous part, where the
|
|
29
|
-
* one and only identity check happens, in `fetch`'s prologue, or at the
|
|
30
|
-
* compiled route's entry when `fetch` had no hook to run first), and erases
|
|
31
|
-
* the whiteboard `finally`
|
|
32
|
-
* all in one uninterruptible turn. The next request's turn CANNOT start
|
|
33
|
-
* until this turn is completely finished, because that is how the event loop
|
|
34
|
-
* works: run-to-completion, no preemption. So request B can never see request
|
|
35
|
-
* A's name on the board, by the time B's turn starts, the board was already
|
|
36
|
-
* erased at the end of A's turn.
|
|
37
|
-
*
|
|
38
|
-
* "But the handler is async!" the `await`s inside it run LATER, in separate
|
|
39
|
-
* turns. That is fine, because the check already happened: the verdict was
|
|
40
|
-
* copied onto that request's own context (`'~sig'`) during the synchronous
|
|
41
|
-
* part, and the code that runs after an `await` only ever reads the context,
|
|
42
|
-
* never this slot.
|
|
43
|
-
*
|
|
44
|
-
* And if any assumption here ever breaks, a runtime that re-enters, a wrap
|
|
45
|
-
* that delays, a future edit that sneaks an `await` in before the check the
|
|
46
|
-
* comparison simply MISSES and the request falls back to eager arming, which
|
|
47
|
-
* is the exact pre-optimization behavior. Every failure mode makes a request
|
|
48
|
-
* slightly slower, never incorrect
|
|
49
|
-
*
|
|
50
|
-
* Adversarial proof, not just argument: `test/core/abort-race.test.ts` storms
|
|
51
|
-
* concurrent servers, in-process `handle()` calls, request-substituting and
|
|
52
|
-
* `next()`-delaying wraps at this slot and asserts zero misclassification.
|
|
53
|
-
*
|
|
54
|
-
* Never infer the Bun runtime from `fetch`'s second argument: Cloudflare
|
|
55
|
-
* Workers pass `env` there.
|
|
56
|
-
*
|
|
57
|
-
* It's insanely stupid, but it works. As Bun is single-threaded and synchronous
|
|
58
|
-
* so the `finally` block will always run before the next request comes in.
|
|
59
|
-
*/
|
|
60
3
|
const origin = { request: void 0 };
|
|
61
4
|
|
|
62
5
|
//#endregion
|
package/dist/adapter/utils.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ declare function responseToSetHeaders(response: Response, set?: Context['set']):
|
|
|
15
15
|
redirect?: never;
|
|
16
16
|
} | {
|
|
17
17
|
headers: any;
|
|
18
|
-
status: number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "
|
|
18
|
+
status: number | "Not Found" | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required";
|
|
19
19
|
};
|
|
20
20
|
interface CreateHandlerParameter {
|
|
21
21
|
mapResponse(response: unknown, set: Context['set'], request?: Request, owned?: boolean): Response;
|
package/dist/adapter/utils.js
CHANGED
|
@@ -55,10 +55,8 @@ function handleFile(response, set, request, size = response.size) {
|
|
|
55
55
|
}
|
|
56
56
|
const body = "value" in response ? response.value : response;
|
|
57
57
|
const immutable = set && (set.status === 206 || set.status === 304 || set.status === 412 || set.status === 416);
|
|
58
|
-
const defaultHeader = immutable ? require_utils.nullObject() : {
|
|
59
|
-
|
|
60
|
-
"content-range": size ? `bytes 0-${size - 1}/${size}` : void 0
|
|
61
|
-
};
|
|
58
|
+
const defaultHeader = immutable ? require_utils.nullObject() : { "accept-ranges": "bytes" };
|
|
59
|
+
if (!immutable && size) defaultHeader["content-range"] = `bytes 0-${size - 1}/${size}`;
|
|
62
60
|
if (!set && !size) return new Response(body);
|
|
63
61
|
if (!set) return new Response(body, { headers: defaultHeader });
|
|
64
62
|
if (set.headers instanceof Headers) {
|
|
@@ -132,7 +130,7 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
132
130
|
const typedSSE = !skipFormat && "sse" in generator && generator.sse === true;
|
|
133
131
|
const sourceIterator = typeof generator.next === "function" ? generator : void 0;
|
|
134
132
|
let init = typedSSE ? void 0 : generator.next?.();
|
|
135
|
-
if (init instanceof Promise) init = await init;
|
|
133
|
+
if (init instanceof Promise || typeof init?.then === "function") init = await init;
|
|
136
134
|
const sign = set?.["~sign"];
|
|
137
135
|
if (sign) try {
|
|
138
136
|
await sign(set);
|
|
@@ -358,11 +356,6 @@ function mergeHeaders(responseHeaders, setHeaders) {
|
|
|
358
356
|
applySetHeaders(headers, setHeaders, responseHeaders);
|
|
359
357
|
return headers;
|
|
360
358
|
}
|
|
361
|
-
function mergeStatus(responseStatus, setStatus) {
|
|
362
|
-
if (typeof setStatus === "string") setStatus = require_constants.StatusMap[setStatus];
|
|
363
|
-
if (responseStatus === 200) return setStatus;
|
|
364
|
-
return responseStatus;
|
|
365
|
-
}
|
|
366
359
|
function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = false) {
|
|
367
360
|
const reader = clonedBody.getReader();
|
|
368
361
|
return new ReadableStream({
|
|
@@ -394,7 +387,8 @@ function createResponseHandler(handler) {
|
|
|
394
387
|
if (!borrowed && response.bodyUsed) throw new TypeError("Cannot reuse a consumed Response across requests");
|
|
395
388
|
let status;
|
|
396
389
|
if (set) {
|
|
397
|
-
status =
|
|
390
|
+
status = response.status === 200 ? set.status : response.status;
|
|
391
|
+
if (typeof status === "string") status = require_constants.StatusMap[status];
|
|
398
392
|
const statusUnchanged = status === void 0 || status === response.status;
|
|
399
393
|
if (!mustClone && statusUnchanged && !set.cookie && !require_utils.isNotEmpty(set.headers)) return response;
|
|
400
394
|
} else if (!mustClone) return response;
|
|
@@ -430,12 +424,6 @@ const doneResult = {
|
|
|
430
424
|
done: true,
|
|
431
425
|
value: void 0
|
|
432
426
|
};
|
|
433
|
-
/**
|
|
434
|
-
* Tee a returned `ReadableStream` so afterResponse, `defer()` and derive
|
|
435
|
-
* dispose wait for it, as for a tee'd generator. A `bytes()` stream is left
|
|
436
|
-
* alone (exact-stream contract), and so is a `Response`: reading its `.body`
|
|
437
|
-
* would move it off Bun's native send path
|
|
438
|
-
*/
|
|
439
427
|
function observeStream(source) {
|
|
440
428
|
if (source.locked || require_utils.isByteStream(source)) return;
|
|
441
429
|
const reader = source.getReader();
|
|
@@ -467,24 +455,6 @@ function observeStream(source) {
|
|
|
467
455
|
value
|
|
468
456
|
];
|
|
469
457
|
}
|
|
470
|
-
/**
|
|
471
|
-
* Split async source into `branches` independent iterators
|
|
472
|
-
*
|
|
473
|
-
* A producer drains the source ahead of consumers
|
|
474
|
-
*
|
|
475
|
-
* To prevent long/infinite stream, the unconsumed window is capped:
|
|
476
|
-
* Consumed-by-every-branch entries are trimmed off the front
|
|
477
|
-
* Producer backpressures whenever the window hits `cap` ENTRIES or
|
|
478
|
-
* `capBytes` bytes, whichever comes first
|
|
479
|
-
*
|
|
480
|
-
* Streams below both caps buffer eagerly
|
|
481
|
-
* Only streams exceeding one gate on the slowest consumer
|
|
482
|
-
*
|
|
483
|
-
* Branch 0 is the value consumer (response/client)
|
|
484
|
-
* When `return()` (client abort / early exit), source is stopped
|
|
485
|
-
* so the observer branches can still reach completion instead of spinning
|
|
486
|
-
* an infinite source
|
|
487
|
-
*/
|
|
488
458
|
function tee(source, branches = 2, cap = 64, capBytes = 1 << 22) {
|
|
489
459
|
const iterator = source[Symbol.asyncIterator]?.() ?? source[Symbol.iterator]();
|
|
490
460
|
const buffer = [];
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -55,10 +55,8 @@ function handleFile(response, set, request, size = response.size) {
|
|
|
55
55
|
}
|
|
56
56
|
const body = "value" in response ? response.value : response;
|
|
57
57
|
const immutable = set && (set.status === 206 || set.status === 304 || set.status === 412 || set.status === 416);
|
|
58
|
-
const defaultHeader = immutable ? nullObject() : {
|
|
59
|
-
|
|
60
|
-
"content-range": size ? `bytes 0-${size - 1}/${size}` : void 0
|
|
61
|
-
};
|
|
58
|
+
const defaultHeader = immutable ? nullObject() : { "accept-ranges": "bytes" };
|
|
59
|
+
if (!immutable && size) defaultHeader["content-range"] = `bytes 0-${size - 1}/${size}`;
|
|
62
60
|
if (!set && !size) return new Response(body);
|
|
63
61
|
if (!set) return new Response(body, { headers: defaultHeader });
|
|
64
62
|
if (set.headers instanceof Headers) {
|
|
@@ -132,7 +130,7 @@ function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
|
132
130
|
const typedSSE = !skipFormat && "sse" in generator && generator.sse === true;
|
|
133
131
|
const sourceIterator = typeof generator.next === "function" ? generator : void 0;
|
|
134
132
|
let init = typedSSE ? void 0 : generator.next?.();
|
|
135
|
-
if (init instanceof Promise) init = await init;
|
|
133
|
+
if (init instanceof Promise || typeof init?.then === "function") init = await init;
|
|
136
134
|
const sign = set?.["~sign"];
|
|
137
135
|
if (sign) try {
|
|
138
136
|
await sign(set);
|
|
@@ -358,11 +356,6 @@ function mergeHeaders(responseHeaders, setHeaders) {
|
|
|
358
356
|
applySetHeaders(headers, setHeaders, responseHeaders);
|
|
359
357
|
return headers;
|
|
360
358
|
}
|
|
361
|
-
function mergeStatus(responseStatus, setStatus) {
|
|
362
|
-
if (typeof setStatus === "string") setStatus = StatusMap[setStatus];
|
|
363
|
-
if (responseStatus === 200) return setStatus;
|
|
364
|
-
return responseStatus;
|
|
365
|
-
}
|
|
366
359
|
function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = false) {
|
|
367
360
|
const reader = clonedBody.getReader();
|
|
368
361
|
return new ReadableStream({
|
|
@@ -394,7 +387,8 @@ function createResponseHandler(handler) {
|
|
|
394
387
|
if (!borrowed && response.bodyUsed) throw new TypeError("Cannot reuse a consumed Response across requests");
|
|
395
388
|
let status;
|
|
396
389
|
if (set) {
|
|
397
|
-
status =
|
|
390
|
+
status = response.status === 200 ? set.status : response.status;
|
|
391
|
+
if (typeof status === "string") status = StatusMap[status];
|
|
398
392
|
const statusUnchanged = status === void 0 || status === response.status;
|
|
399
393
|
if (!mustClone && statusUnchanged && !set.cookie && !isNotEmpty(set.headers)) return response;
|
|
400
394
|
} else if (!mustClone) return response;
|
|
@@ -430,12 +424,6 @@ const doneResult = {
|
|
|
430
424
|
done: true,
|
|
431
425
|
value: void 0
|
|
432
426
|
};
|
|
433
|
-
/**
|
|
434
|
-
* Tee a returned `ReadableStream` so afterResponse, `defer()` and derive
|
|
435
|
-
* dispose wait for it, as for a tee'd generator. A `bytes()` stream is left
|
|
436
|
-
* alone (exact-stream contract), and so is a `Response`: reading its `.body`
|
|
437
|
-
* would move it off Bun's native send path
|
|
438
|
-
*/
|
|
439
427
|
function observeStream(source) {
|
|
440
428
|
if (source.locked || isByteStream(source)) return;
|
|
441
429
|
const reader = source.getReader();
|
|
@@ -467,24 +455,6 @@ function observeStream(source) {
|
|
|
467
455
|
value
|
|
468
456
|
];
|
|
469
457
|
}
|
|
470
|
-
/**
|
|
471
|
-
* Split async source into `branches` independent iterators
|
|
472
|
-
*
|
|
473
|
-
* A producer drains the source ahead of consumers
|
|
474
|
-
*
|
|
475
|
-
* To prevent long/infinite stream, the unconsumed window is capped:
|
|
476
|
-
* Consumed-by-every-branch entries are trimmed off the front
|
|
477
|
-
* Producer backpressures whenever the window hits `cap` ENTRIES or
|
|
478
|
-
* `capBytes` bytes, whichever comes first
|
|
479
|
-
*
|
|
480
|
-
* Streams below both caps buffer eagerly
|
|
481
|
-
* Only streams exceeding one gate on the slowest consumer
|
|
482
|
-
*
|
|
483
|
-
* Branch 0 is the value consumer (response/client)
|
|
484
|
-
* When `return()` (client abort / early exit), source is stopped
|
|
485
|
-
* so the observer branches can still reach completion instead of spinning
|
|
486
|
-
* an infinite source
|
|
487
|
-
*/
|
|
488
458
|
function tee(source, branches = 2, cap = 64, capBytes = 1 << 22) {
|
|
489
459
|
const iterator = source[Symbol.asyncIterator]?.() ?? source[Symbol.iterator]();
|
|
490
460
|
const buffer = [];
|
|
@@ -13,7 +13,8 @@ const textPlainInit = { headers: { "content-type": "text/plain" } };
|
|
|
13
13
|
function handleElysiaFile(file, set = { headers: require_utils.nullObject() }, request) {
|
|
14
14
|
const contentType = file.type;
|
|
15
15
|
const headers = require_adapter_utils.materializeSetHeaders(set);
|
|
16
|
-
if (contentType !== "application/octet-stream") headers
|
|
16
|
+
if (contentType !== "application/octet-stream") if (headers instanceof Headers) headers.set("content-type", contentType);
|
|
17
|
+
else headers["content-type"] = contentType;
|
|
17
18
|
const stats = file.stats;
|
|
18
19
|
if (stats) return stats.then((stat) => {
|
|
19
20
|
const size = stat.size;
|
|
@@ -63,7 +64,9 @@ function withStatus(response, set, request, owned) {
|
|
|
63
64
|
status: response.status,
|
|
64
65
|
headers: require_utils.nullObject()
|
|
65
66
|
};
|
|
66
|
-
if (response.headers) Object.
|
|
67
|
+
if (response.headers) if (set.headers instanceof Headers) for (const [key, value] of Object.entries(response.headers)) if (key.toLowerCase() === "set-cookie") for (const cookie of Array.isArray(value) ? value : [value]) set.headers.append(key, cookie);
|
|
68
|
+
else set.headers.set(key, value);
|
|
69
|
+
else Object.assign(require_adapter_utils.materializeSetHeaders(set), response.headers);
|
|
67
70
|
return mapResponseWithSet(response.response, set, request, owned);
|
|
68
71
|
}
|
|
69
72
|
const checkRemovedSetRedirect = !require_universal_is_production.isProduction();
|
|
@@ -86,7 +89,9 @@ function mapCompactResponse(response, request, owned) {
|
|
|
86
89
|
case "String": return new Response(response, textHeaders);
|
|
87
90
|
case "Array": return Response.json(response);
|
|
88
91
|
case "ElysiaForm": return new Response(require_utils.formToFormData(response));
|
|
89
|
-
case "Object":
|
|
92
|
+
case "Object":
|
|
93
|
+
if (typeof response?.next === "function") return handleStream(response, void 0, request, void 0, owned);
|
|
94
|
+
return Response.json(response);
|
|
90
95
|
case "Number":
|
|
91
96
|
case "Boolean": return new Response(String(response));
|
|
92
97
|
case "ElysiaFile": return handleElysiaFile(response, void 0, request);
|
|
@@ -125,17 +130,7 @@ function errorToResponse(error, set, request, owned = false) {
|
|
|
125
130
|
function mapFallback(response, set, request, owned = false) {
|
|
126
131
|
if (response instanceof Response) return handleResponse(response, set, request, owned);
|
|
127
132
|
if (response instanceof Error) return errorToResponse(response, set, request, owned);
|
|
128
|
-
if (response instanceof require_error.ElysiaStatus)
|
|
129
|
-
if (set && response.headers) {
|
|
130
|
-
set.status = response.status;
|
|
131
|
-
set.headers = {
|
|
132
|
-
...set.headers,
|
|
133
|
-
...response.headers
|
|
134
|
-
};
|
|
135
|
-
return mapResponse(response.response, set, request, owned);
|
|
136
|
-
}
|
|
137
|
-
return withStatus(response, set, request, owned);
|
|
138
|
-
}
|
|
133
|
+
if (response instanceof require_error.ElysiaStatus) return withStatus(response, set, request, owned);
|
|
139
134
|
if (response instanceof require_universal_file.ElysiaFile) return handleElysiaFile(response, set, request);
|
|
140
135
|
if (require_utils.isElysiaForm(response)) return new Response(require_utils.formToFormData(response), set);
|
|
141
136
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
|
@@ -13,7 +13,8 @@ const textPlainInit = { headers: { "content-type": "text/plain" } };
|
|
|
13
13
|
function handleElysiaFile(file, set = { headers: nullObject() }, request) {
|
|
14
14
|
const contentType = file.type;
|
|
15
15
|
const headers = materializeSetHeaders(set);
|
|
16
|
-
if (contentType !== "application/octet-stream") headers
|
|
16
|
+
if (contentType !== "application/octet-stream") if (headers instanceof Headers) headers.set("content-type", contentType);
|
|
17
|
+
else headers["content-type"] = contentType;
|
|
17
18
|
const stats = file.stats;
|
|
18
19
|
if (stats) return stats.then((stat) => {
|
|
19
20
|
const size = stat.size;
|
|
@@ -63,7 +64,9 @@ function withStatus(response, set, request, owned) {
|
|
|
63
64
|
status: response.status,
|
|
64
65
|
headers: nullObject()
|
|
65
66
|
};
|
|
66
|
-
if (response.headers) Object.
|
|
67
|
+
if (response.headers) if (set.headers instanceof Headers) for (const [key, value] of Object.entries(response.headers)) if (key.toLowerCase() === "set-cookie") for (const cookie of Array.isArray(value) ? value : [value]) set.headers.append(key, cookie);
|
|
68
|
+
else set.headers.set(key, value);
|
|
69
|
+
else Object.assign(materializeSetHeaders(set), response.headers);
|
|
67
70
|
return mapResponseWithSet(response.response, set, request, owned);
|
|
68
71
|
}
|
|
69
72
|
const checkRemovedSetRedirect = !isProduction();
|
|
@@ -86,7 +89,9 @@ function mapCompactResponse(response, request, owned) {
|
|
|
86
89
|
case "String": return new Response(response, textHeaders);
|
|
87
90
|
case "Array": return Response.json(response);
|
|
88
91
|
case "ElysiaForm": return new Response(formToFormData(response));
|
|
89
|
-
case "Object":
|
|
92
|
+
case "Object":
|
|
93
|
+
if (typeof response?.next === "function") return handleStream(response, void 0, request, void 0, owned);
|
|
94
|
+
return Response.json(response);
|
|
90
95
|
case "Number":
|
|
91
96
|
case "Boolean": return new Response(String(response));
|
|
92
97
|
case "ElysiaFile": return handleElysiaFile(response, void 0, request);
|
|
@@ -125,17 +130,7 @@ function errorToResponse(error, set, request, owned = false) {
|
|
|
125
130
|
function mapFallback(response, set, request, owned = false) {
|
|
126
131
|
if (response instanceof Response) return handleResponse(response, set, request, owned);
|
|
127
132
|
if (response instanceof Error) return errorToResponse(response, set, request, owned);
|
|
128
|
-
if (response instanceof ElysiaStatus)
|
|
129
|
-
if (set && response.headers) {
|
|
130
|
-
set.status = response.status;
|
|
131
|
-
set.headers = {
|
|
132
|
-
...set.headers,
|
|
133
|
-
...response.headers
|
|
134
|
-
};
|
|
135
|
-
return mapResponse(response.response, set, request, owned);
|
|
136
|
-
}
|
|
137
|
-
return withStatus(response, set, request, owned);
|
|
138
|
-
}
|
|
133
|
+
if (response instanceof ElysiaStatus) return withStatus(response, set, request, owned);
|
|
139
134
|
if (response instanceof ElysiaFile) return handleElysiaFile(response, set, request);
|
|
140
135
|
if (isElysiaForm(response)) return new Response(formToFormData(response), set);
|
|
141
136
|
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
package/dist/base.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ElysiaStatus } from "./error.js";
|
|
2
|
+
import { AnySchema } from "./type/types.js";
|
|
3
|
+
import { AotFingerprint, CompilerSession, ProgramId } from "./compile/aot.js";
|
|
2
4
|
import { ChainNode } from "./utils.js";
|
|
3
5
|
import { ListenCallback, Serve, Server } from "./universal/server.js";
|
|
4
6
|
import { Context, ErrorContext, LifecycleContext } from "./context.js";
|
|
5
7
|
import { TraceCapability, TraceHandler } from "./trace.js";
|
|
6
|
-
import { AnySchema } from "./type/types.js";
|
|
7
|
-
import { AotFingerprint, CompilerSession, ProgramId } from "./compile/aot.js";
|
|
8
8
|
import { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, BodyHandler, CompiledHandler, CreateEden, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, ElysiaConfig, ElysiaHandlerToResponseSchemaAmbiguous, EphemeralType, ErrorDefinitionEntry, ErrorHandler, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, GlobalHookReturn, GracefulHandler, GuardHookSingleton, GuardLocalHook, HTTPMethod, HistoryEntry, HookContextSchema, HookContextSingleton, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, LocalHookReturn, Macro, MacroOptionContext, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, ObjectMacroDefs, OptionalHandler, ParentResponse, PluginHookReturn, PreHandler, Prettify, PublicRoute, ResolveUsedRouteErrors, RouteBase, ScopedHookReturn, ScopedMapDeriveReturn, SingletonBase, StaticMapAliases, TransformHandler, UnionResponseStatus, UnwrapRoute, WrapFn } from "./types.js";
|
|
9
9
|
import { RouteErrorHooks } from "./handler/utils.js";
|
|
10
10
|
import { WSCapability, WSHandlerResponse, WSLocalHook, WSMessageHandler, WSOptions, WSOptionsEntry } from "./ws/types.js";
|
|
@@ -99,7 +99,6 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
99
99
|
'~aotFingerprint'?: AotFingerprint;
|
|
100
100
|
'~compilerSession'?: CompilerSession;
|
|
101
101
|
'~generation'?: Generation;
|
|
102
|
-
'~introspect'?: boolean;
|
|
103
102
|
'~scopeChild'?: boolean;
|
|
104
103
|
'~scopeChildren'?: AnyElysia[];
|
|
105
104
|
constructor(config?: ElysiaConfig<BasePath, Scope>);
|
|
@@ -228,7 +227,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
228
227
|
* ```typescript
|
|
229
228
|
* new Elysia()
|
|
230
229
|
* .setup(({ server }) => {
|
|
231
|
-
* console.log(
|
|
230
|
+
* console.log(`Running at ${server?.url}`)
|
|
232
231
|
* })
|
|
233
232
|
* .listen(3000)
|
|
234
233
|
* ```
|
|
@@ -403,7 +402,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
403
402
|
* .post('/', ({ body }) => body)
|
|
404
403
|
* ```
|
|
405
404
|
*/
|
|
406
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
405
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
407
406
|
schema: 'merge';
|
|
408
407
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
409
408
|
derive: {};
|
|
@@ -423,7 +422,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
423
422
|
response: UnionResponseStatus<Volatile['response'], ElysiaHandlerToResponseSchemaAmbiguous<BeforeHandle> & ElysiaHandlerToResponseSchemaAmbiguous<AfterHandle> & ElysiaHandlerToResponseSchemaAmbiguous<ErrorHandle> & MacroContext['return']>;
|
|
424
423
|
error: Volatile['error'];
|
|
425
424
|
}>;
|
|
426
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const NewElysia extends AnyElysia>(hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
425
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const NewElysia extends AnyElysia>(hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
427
426
|
schema: 'merge';
|
|
428
427
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
429
428
|
derive: {};
|
|
@@ -465,7 +464,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
465
464
|
response: Volatile['response'];
|
|
466
465
|
error: Volatile['error'];
|
|
467
466
|
}>) => NewElysia): Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & NewElysia['~Routes'], Ephemeral, Volatile>;
|
|
468
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'local', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
467
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'local', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
469
468
|
schema: 'merge';
|
|
470
469
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
471
470
|
derive: {};
|
|
@@ -485,7 +484,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
485
484
|
response: UnionResponseStatus<Volatile['response'], ElysiaHandlerToResponseSchemaAmbiguous<BeforeHandle> & ElysiaHandlerToResponseSchemaAmbiguous<AfterHandle> & ElysiaHandlerToResponseSchemaAmbiguous<ErrorHandle> & MacroContext['return']>;
|
|
486
485
|
error: Volatile['error'];
|
|
487
486
|
}>;
|
|
488
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'plugin', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
487
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'plugin', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
489
488
|
schema: 'merge';
|
|
490
489
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
491
490
|
derive: {};
|
|
@@ -505,7 +504,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
505
504
|
response: UnionResponseStatus<Ephemeral['response'], ElysiaHandlerToResponseSchemaAmbiguous<BeforeHandle> & ElysiaHandlerToResponseSchemaAmbiguous<AfterHandle> & ElysiaHandlerToResponseSchemaAmbiguous<ErrorHandle> & MacroContext['return']>;
|
|
506
505
|
error: Ephemeral['error'];
|
|
507
506
|
}, Volatile>;
|
|
508
|
-
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'global', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
507
|
+
guard<const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], BasePath>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>>(scope: 'global', hook: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
509
508
|
schema: 'merge';
|
|
510
509
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
511
510
|
derive: {};
|
|
@@ -543,7 +542,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
543
542
|
parser: Metadata['parser'];
|
|
544
543
|
response: Metadata['response'];
|
|
545
544
|
}, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & NewElysia['~Routes'], Ephemeral, Volatile>;
|
|
546
|
-
group<const Prefix extends string, const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], JoinPath<BasePath, Prefix>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const NewElysia extends AnyElysia>(prefix: Prefix, schema: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle> & {
|
|
545
|
+
group<const Prefix extends string, const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], JoinPath<BasePath, Prefix>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>), const BeforeHandle extends MaybeArray<OptionalHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const AfterHandle extends MaybeArray<AfterHandler<Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const ErrorHandle extends MaybeArray<ErrorHandler<Definitions['error'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>>>, const NewElysia extends AnyElysia>(prefix: Prefix, schema: GuardLocalHook<Input, Schema & MacroContext, GuardHookSingleton<Singleton, Ephemeral, Volatile, MacroContext>, keyof Metadata['parser'], BeforeHandle, AfterHandle, ErrorHandle, 'merge'> & {
|
|
547
546
|
schema: 'merge';
|
|
548
547
|
} & MacroOptionContext<Metadata['macroFn'], Schema, GuardHookSingleton<Singleton, Ephemeral, Volatile, {
|
|
549
548
|
derive: {};
|
|
@@ -922,7 +921,8 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
922
921
|
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): this;
|
|
923
922
|
/**
|
|
924
923
|
* ### ws
|
|
925
|
-
* Register a WebSocket route
|
|
924
|
+
* Register a WebSocket route as `(path, options)`, `(path, handler)`, or `(path, options, handler)`.
|
|
925
|
+
* Requires `.use(websocket())` from `elysia/websocket`.
|
|
926
926
|
*/
|
|
927
927
|
ws<const Path extends string, const Input extends Metadata['macro'] & InputSchema<keyof Definitions['typebox'] & string>, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<Input, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', undefined extends Input['params'] ? true : false>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Input, Definitions['typebox']>)>(path: Path, options: WSLocalHook<Input, Schema & MacroContext, Singleton & {
|
|
928
928
|
derive: Ephemeral['derive'] & Volatile['derive'] & MacroContext['derive'];
|