elysia 2.0.0-exp.0 → 2.0.0-exp.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.js +0 -2
- package/dist/adapter/bun/index.d.ts +1 -1
- package/dist/adapter/bun/index.js +6 -1
- package/dist/adapter/bun/index.mjs +6 -1
- package/dist/adapter/bun/router.js +1 -1
- package/dist/adapter/bun/router.mjs +1 -1
- package/dist/adapter/constants.d.ts +1 -1
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/utils.d.ts +1 -1
- package/dist/adapter/utils.js +5 -3
- package/dist/adapter/utils.mjs +5 -3
- package/dist/adapter/web-standard/index.d.ts +1 -1
- package/dist/base.d.ts +10 -26
- package/dist/base.js +56 -18
- package/dist/base.mjs +58 -20
- package/dist/compile/aot.d.ts +44 -28
- package/dist/compile/aot.js +23 -37
- package/dist/compile/aot.mjs +22 -38
- package/dist/compile/handler/index.d.ts +4 -2
- package/dist/compile/handler/index.js +50 -29
- package/dist/compile/handler/index.mjs +51 -31
- package/dist/compile/handler/utils.js +3 -3
- package/dist/compile/handler/utils.mjs +3 -3
- package/dist/compile/index.d.ts +2 -2
- package/dist/compile/index.js +2 -1
- package/dist/compile/index.mjs +2 -2
- package/dist/compile/utils.d.ts +2 -1
- package/dist/compile/utils.js +9 -1
- package/dist/compile/utils.mjs +8 -1
- package/dist/cookie/config.js +7 -6
- package/dist/cookie/config.mjs +7 -6
- package/dist/cookie/cookie.js +1 -3
- package/dist/cookie/cookie.mjs +1 -3
- package/dist/cookie/utils.js +6 -4
- package/dist/cookie/utils.mjs +6 -4
- package/dist/error.d.ts +6 -9
- package/dist/error.js +26 -19
- package/dist/error.mjs +26 -19
- package/dist/handler/error.js +2 -2
- package/dist/handler/error.mjs +3 -3
- package/dist/handler/fetch.js +40 -11
- package/dist/handler/fetch.mjs +41 -12
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -7
- package/dist/index.mjs +2 -2
- package/dist/plugin/bun.js +29 -3
- package/dist/plugin/bun.mjs +28 -3
- package/dist/plugin/core.d.ts +8 -1
- package/dist/plugin/esbuild.js +28 -3
- package/dist/plugin/esbuild.mjs +28 -3
- package/dist/plugin/source.js +28 -0
- package/dist/plugin/source.mjs +29 -1
- package/dist/plugin/treeshake.d.ts +10 -0
- package/dist/plugin/treeshake.js +63 -0
- package/dist/plugin/treeshake.mjs +61 -0
- package/dist/plugin/vite.js +7 -1
- package/dist/plugin/vite.mjs +7 -1
- package/dist/trace.js +1 -1
- package/dist/trace.mjs +1 -1
- package/dist/type/bridge.d.ts +7 -11
- package/dist/type/bridge.js +0 -10
- package/dist/type/bridge.mjs +1 -9
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/coerce.js +38 -4
- package/dist/type/coerce.mjs +38 -4
- package/dist/type/compat.js +4 -4
- package/dist/type/compat.mjs +7 -7
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/array-buffer.js +4 -4
- package/dist/type/elysia/array-buffer.mjs +4 -4
- package/dist/type/elysia/array-string.d.ts +2 -2
- package/dist/type/elysia/array-string.js +5 -5
- package/dist/type/elysia/array-string.mjs +6 -6
- package/dist/type/elysia/array.js +11 -8
- package/dist/type/elysia/array.mjs +11 -8
- package/dist/type/elysia/boolean-string.d.ts +1 -1
- package/dist/type/elysia/boolean-string.js +4 -5
- package/dist/type/elysia/boolean-string.mjs +4 -5
- package/dist/type/elysia/boolean.js +2 -2
- package/dist/type/elysia/boolean.mjs +2 -2
- package/dist/type/elysia/cookie.js +1 -4
- package/dist/type/elysia/cookie.mjs +1 -4
- package/dist/type/elysia/date.js +17 -10
- package/dist/type/elysia/date.mjs +17 -10
- package/dist/type/elysia/file.js +4 -4
- package/dist/type/elysia/file.mjs +4 -4
- package/dist/type/elysia/files.js +4 -4
- package/dist/type/elysia/files.mjs +4 -4
- package/dist/type/elysia/form.js +3 -3
- package/dist/type/elysia/form.mjs +4 -4
- package/dist/type/elysia/integer-string.js +7 -6
- package/dist/type/elysia/integer-string.mjs +8 -7
- package/dist/type/elysia/integer.js +2 -2
- package/dist/type/elysia/integer.mjs +2 -2
- package/dist/type/elysia/maybe-empty.d.ts +3 -2
- package/dist/type/elysia/maybe-empty.js +4 -4
- package/dist/type/elysia/maybe-empty.mjs +4 -4
- package/dist/type/elysia/nullable.d.ts +3 -2
- package/dist/type/elysia/nullable.js +3 -3
- package/dist/type/elysia/nullable.mjs +3 -3
- package/dist/type/elysia/number.js +2 -2
- package/dist/type/elysia/number.mjs +2 -2
- package/dist/type/elysia/numeric-enum.js +4 -3
- package/dist/type/elysia/numeric-enum.mjs +4 -3
- package/dist/type/elysia/numeric.js +7 -6
- package/dist/type/elysia/numeric.mjs +7 -6
- package/dist/type/elysia/object-string.d.ts +2 -2
- package/dist/type/elysia/object-string.js +5 -5
- package/dist/type/elysia/object-string.mjs +6 -6
- package/dist/type/elysia/object.js +12 -9
- package/dist/type/elysia/object.mjs +12 -9
- package/dist/type/elysia/optional.js +12 -5
- package/dist/type/elysia/optional.mjs +12 -5
- package/dist/type/elysia/string.js +2 -2
- package/dist/type/elysia/string.mjs +2 -2
- package/dist/type/elysia/uint8-array.js +2 -2
- package/dist/type/elysia/uint8-array.mjs +2 -2
- package/dist/type/elysia/union-enum.d.ts +3 -2
- package/dist/type/elysia/union-enum.js +2 -2
- package/dist/type/elysia/union-enum.mjs +2 -2
- package/dist/type/elysia/utils.js +4 -8
- package/dist/type/elysia/utils.mjs +4 -8
- package/dist/type/exports.js +2071 -39
- package/dist/type/exports.mjs +307 -17
- package/dist/type/index.d.ts +3 -3
- package/dist/type/index.js +4 -31
- package/dist/type/index.mjs +4 -26
- package/dist/type/types.d.ts +1 -1
- package/dist/type/validator.d.ts +3 -3
- package/dist/type/validator.js +547 -117
- package/dist/type/validator.mjs +549 -119
- package/dist/types.d.ts +16 -4
- package/dist/utils.js +12 -8
- package/dist/utils.mjs +12 -8
- package/dist/validator/index.js +7 -6
- package/dist/validator/index.mjs +7 -6
- package/dist/validator/route.js +9 -9
- package/dist/validator/route.mjs +9 -9
- package/dist/ws/context.js +4 -7
- package/dist/ws/context.mjs +4 -7
- package/dist/ws/parser.js +6 -1
- package/dist/ws/parser.mjs +6 -1
- package/dist/ws/route.js +6 -4
- package/dist/ws/route.mjs +6 -4
- package/package.json +12 -4
|
@@ -32,7 +32,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
32
32
|
}
|
|
33
33
|
return to;
|
|
34
34
|
};
|
|
35
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
36
35
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
37
36
|
value: mod,
|
|
38
37
|
enumerable: true
|
|
@@ -41,5 +40,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
41
40
|
//#endregion
|
|
42
41
|
|
|
43
42
|
exports.__exportAll = __exportAll;
|
|
44
|
-
exports.__reExport = __reExport;
|
|
45
43
|
exports.__toESM = __toESM;
|
|
@@ -6,7 +6,7 @@ import { AnyElysia } from "../../base.js";
|
|
|
6
6
|
declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, Promise<void>[]] | undefined;
|
|
7
7
|
declare const BunAdapter: {
|
|
8
8
|
parse: {
|
|
9
|
-
default: (context: Context, contentType: string) => string |
|
|
9
|
+
default: (context: Context, contentType: string) => string | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
10
10
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
11
11
|
text: (context: Context) => MaybePromise<string>;
|
|
12
12
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
|
@@ -35,7 +35,12 @@ const BunAdapter = require_adapter_index.createAdapter({
|
|
|
35
35
|
name: "bun",
|
|
36
36
|
runtime: "bun",
|
|
37
37
|
listen(app, options, callback) {
|
|
38
|
-
const
|
|
38
|
+
const _config = app["~config"]?.serve;
|
|
39
|
+
const _options = typeof options === "object" ? options : { port: +options };
|
|
40
|
+
const serve = _config ? {
|
|
41
|
+
..._config,
|
|
42
|
+
..._options
|
|
43
|
+
} : _options;
|
|
39
44
|
const hasWs = app["~hasWS"];
|
|
40
45
|
serve.fetch = (request, server) => app.fetch(request, server);
|
|
41
46
|
app.server = Bun.serve(serve);
|
|
@@ -34,7 +34,12 @@ const BunAdapter = createAdapter({
|
|
|
34
34
|
name: "bun",
|
|
35
35
|
runtime: "bun",
|
|
36
36
|
listen(app, options, callback) {
|
|
37
|
-
const
|
|
37
|
+
const _config = app["~config"]?.serve;
|
|
38
|
+
const _options = typeof options === "object" ? options : { port: +options };
|
|
39
|
+
const serve = _config ? {
|
|
40
|
+
..._config,
|
|
41
|
+
..._options
|
|
42
|
+
} : _options;
|
|
38
43
|
const hasWs = app["~hasWS"];
|
|
39
44
|
serve.fetch = (request, server) => app.fetch(request, server);
|
|
40
45
|
app.server = Bun.serve(serve);
|
|
@@ -62,13 +62,13 @@ function createPlainHandler(handler, handleError, Context) {
|
|
|
62
62
|
}
|
|
63
63
|
function createRouteMap(app) {
|
|
64
64
|
const Context = createBunContext(app);
|
|
65
|
+
const handleError = require_handler_error.createErrorHandler(require_utils.flattenChain(app["~hookChain"])?.error, require_adapter_web_standard_index.WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
|
|
65
66
|
function fetch(request) {
|
|
66
67
|
return handleError(new Context(request), new require_error.NotFound());
|
|
67
68
|
}
|
|
68
69
|
const history = app.history;
|
|
69
70
|
const length = history?.length ?? 0;
|
|
70
71
|
if (length === 0) return [{ "/elysia": new Response("hi") }, fetch];
|
|
71
|
-
const handleError = require_handler_error.createErrorHandler(require_utils.flattenChain(app["~hookChain"])?.error, require_adapter_web_standard_index.WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
|
|
72
72
|
const routes = require_utils.nullObject();
|
|
73
73
|
for (let i = 0; i < length; i++) {
|
|
74
74
|
const route = history[i];
|
|
@@ -61,13 +61,13 @@ function createPlainHandler(handler, handleError, Context) {
|
|
|
61
61
|
}
|
|
62
62
|
function createRouteMap(app) {
|
|
63
63
|
const Context = createBunContext(app);
|
|
64
|
+
const handleError = createErrorHandler(flattenChain(app["~hookChain"])?.error, WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
|
|
64
65
|
function fetch(request) {
|
|
65
66
|
return handleError(new Context(request), new NotFound());
|
|
66
67
|
}
|
|
67
68
|
const history = app.history;
|
|
68
69
|
const length = history?.length ?? 0;
|
|
69
70
|
if (length === 0) return [{ "/elysia": new Response("hi") }, fetch];
|
|
70
|
-
const handleError = createErrorHandler(flattenChain(app["~hookChain"])?.error, WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
|
|
71
71
|
const routes = nullObject();
|
|
72
72
|
for (let i = 0; i < length; i++) {
|
|
73
73
|
const route = history[i];
|
|
@@ -5,7 +5,7 @@ import { AnyElysia } from "../base.js";
|
|
|
5
5
|
//#region src/adapter/constants.d.ts
|
|
6
6
|
declare const defaultAdapter: {
|
|
7
7
|
parse: {
|
|
8
|
-
default: (context: Context, contentType: string) => string |
|
|
8
|
+
default: (context: Context, contentType: string) => string | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
9
9
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
10
10
|
text: (context: Context) => MaybePromise<string>;
|
|
11
11
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/adapter/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { AnyElysia } from "../base.js";
|
|
|
7
7
|
//#region src/adapter/index.d.ts
|
|
8
8
|
declare function createAdapter(adapter: ElysiaAdapterOptions): {
|
|
9
9
|
parse: {
|
|
10
|
-
default: (context: Context, contentType: string) => string |
|
|
10
|
+
default: (context: Context, contentType: string) => string | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
11
11
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
12
12
|
text: (context: Context) => MaybePromise<string>;
|
|
13
13
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/adapter/utils.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare function responseToSetHeaders(response: Response, set?: Context['set']):
|
|
|
12
12
|
cookie?: Record<string, BaseCookie>;
|
|
13
13
|
} | {
|
|
14
14
|
headers: any;
|
|
15
|
-
status: number | "
|
|
15
|
+
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" | "Not Found" | "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";
|
|
16
16
|
};
|
|
17
17
|
interface CreateHandlerParameter {
|
|
18
18
|
mapResponse(response: unknown, set: Context['set'], request?: Request): Response;
|
package/dist/adapter/utils.js
CHANGED
|
@@ -51,7 +51,7 @@ function handleFile(response, set, request) {
|
|
|
51
51
|
if (!set && !size) return new Response(response);
|
|
52
52
|
if (!set) return new Response(response, { headers: defaultHeader });
|
|
53
53
|
if (set.headers instanceof Headers) {
|
|
54
|
-
for (const key of Object.keys(defaultHeader)) if (
|
|
54
|
+
for (const key of Object.keys(defaultHeader)) if (!set.headers.has(key)) set.headers.append(key, defaultHeader[key]);
|
|
55
55
|
if (immutable) {
|
|
56
56
|
set.headers.delete("content-length");
|
|
57
57
|
set.headers.delete("accept-ranges");
|
|
@@ -96,7 +96,9 @@ function responseToSetHeaders(response, set) {
|
|
|
96
96
|
};
|
|
97
97
|
for (const [key, value] of response.headers.entries()) set.headers[key] = value;
|
|
98
98
|
}
|
|
99
|
-
if (set.headers
|
|
99
|
+
if (set.headers instanceof Headers) {
|
|
100
|
+
if (set.headers.has("content-encoding")) set.headers.delete("content-encoding");
|
|
101
|
+
} else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
100
102
|
return set;
|
|
101
103
|
}
|
|
102
104
|
const enqueueBinaryChunk = (controller, chunk) => {
|
|
@@ -209,7 +211,7 @@ async function* streamResponse(response) {
|
|
|
209
211
|
function handleSet(set) {
|
|
210
212
|
if (typeof set.status === "string") set.status = require_constants.StatusMap[set.status];
|
|
211
213
|
const proto = Object.getPrototypeOf(set.headers);
|
|
212
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
214
|
+
if (proto !== null && proto !== Object.prototype && !(set.headers instanceof Headers)) {
|
|
213
215
|
const flat = Object.create(null);
|
|
214
216
|
for (const key in set.headers) flat[key] = set.headers[key];
|
|
215
217
|
set.headers = flat;
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -50,7 +50,7 @@ function handleFile(response, set, request) {
|
|
|
50
50
|
if (!set && !size) return new Response(response);
|
|
51
51
|
if (!set) return new Response(response, { headers: defaultHeader });
|
|
52
52
|
if (set.headers instanceof Headers) {
|
|
53
|
-
for (const key of Object.keys(defaultHeader)) if (
|
|
53
|
+
for (const key of Object.keys(defaultHeader)) if (!set.headers.has(key)) set.headers.append(key, defaultHeader[key]);
|
|
54
54
|
if (immutable) {
|
|
55
55
|
set.headers.delete("content-length");
|
|
56
56
|
set.headers.delete("accept-ranges");
|
|
@@ -95,7 +95,9 @@ function responseToSetHeaders(response, set) {
|
|
|
95
95
|
};
|
|
96
96
|
for (const [key, value] of response.headers.entries()) set.headers[key] = value;
|
|
97
97
|
}
|
|
98
|
-
if (set.headers
|
|
98
|
+
if (set.headers instanceof Headers) {
|
|
99
|
+
if (set.headers.has("content-encoding")) set.headers.delete("content-encoding");
|
|
100
|
+
} else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
99
101
|
return set;
|
|
100
102
|
}
|
|
101
103
|
const enqueueBinaryChunk = (controller, chunk) => {
|
|
@@ -208,7 +210,7 @@ async function* streamResponse(response) {
|
|
|
208
210
|
function handleSet(set) {
|
|
209
211
|
if (typeof set.status === "string") set.status = StatusMap[set.status];
|
|
210
212
|
const proto = Object.getPrototypeOf(set.headers);
|
|
211
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
213
|
+
if (proto !== null && proto !== Object.prototype && !(set.headers instanceof Headers)) {
|
|
212
214
|
const flat = Object.create(null);
|
|
213
215
|
for (const key in set.headers) flat[key] = set.headers[key];
|
|
214
216
|
set.headers = flat;
|
|
@@ -5,7 +5,7 @@ import { AnyElysia } from "../../base.js";
|
|
|
5
5
|
//#region src/adapter/web-standard/index.d.ts
|
|
6
6
|
declare const WebStandardAdapter: {
|
|
7
7
|
parse: {
|
|
8
|
-
default: (context: Context, contentType: string) => string |
|
|
8
|
+
default: (context: Context, contentType: string) => string | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
|
|
9
9
|
json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
|
|
10
10
|
text: (context: Context) => MaybePromise<string>;
|
|
11
11
|
urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
|
package/dist/base.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ElysiaStatus } from "./error.js";
|
|
2
2
|
import { TraceHandler } from "./trace.js";
|
|
3
3
|
import { ListenCallback, Serve, Server } from "./universal/server.js";
|
|
4
|
-
import { AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, AppEvent, BodyHandler, CompiledHandler,
|
|
4
|
+
import { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, AppEvent, BodyHandler, CompiledHandler, CreateEden, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaHandlerToResponseSchemaAmbiguous, EphemeralType, ErrorDefinitionEntry, ErrorHandler, EventFn, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, GuardLocalHook, HTTPMethod, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, Macro, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PreHandler, Prettify, PublicRoute, ResolveRouteErrors, RouteBase, SingletonBase, TransformHandler, UnionResponseStatus, UnwrapRoute, WrapFn } from "./types.js";
|
|
5
5
|
import { AnySchema } from "./type/types.js";
|
|
6
6
|
import { ChainNode } from "./utils.js";
|
|
7
7
|
import { Context, ErrorContext, LifecycleContext } from "./context.js";
|
|
@@ -11,22 +11,6 @@ import { TRef, TSchema } from "typebox";
|
|
|
11
11
|
|
|
12
12
|
//#region src/base.d.ts
|
|
13
13
|
type AnyElysia = Elysia<any, any, any, any, any, any, any, any>;
|
|
14
|
-
/**
|
|
15
|
-
* Shared return type for the HTTP verb methods' overloads — folds a single
|
|
16
|
-
* route into the instance's Eden tree. Factored out so each verb's two
|
|
17
|
-
* overloads (with-hook / no-hook) don't each re-spell the ~50-line type.
|
|
18
|
-
* `Method` is a literal (`'get'`) for the verbs, or the generic method for
|
|
19
|
-
* `.method()`. `MacroContext` is `{}` on the no-hook overload.
|
|
20
|
-
*/
|
|
21
|
-
type AddRoute<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, Method extends string, Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Handle> = Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & CreateEden<JoinPath<BasePath, Path>, { [method in Method]: CreateEdenResponse<Path, Schema, MacroContext, ComposeElysiaResponse<Schema & MacroContext & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], Handle, UnionResponseStatus<Metadata['response'], UnionResponseStatus<Ephemeral['response'], UnionResponseStatus<Volatile['response'], MacroContext['return'] & {}>>>, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>, UnhandledReturnedErrorOf<Handle, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>> }>, Ephemeral, Volatile>;
|
|
22
|
-
/**
|
|
23
|
-
* `AddRoute`'s WebSocket sibling — folds a `.ws()` route into the Eden tree
|
|
24
|
-
* under the `subscribe` key. `Response` is `void` for the options-only form,
|
|
25
|
-
* or `WSHandlerResponse<Handler>` when a positional message handler is given.
|
|
26
|
-
*/
|
|
27
|
-
type AddWSRoute<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Response> = Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & CreateEden<JoinPath<BasePath, Path>, {
|
|
28
|
-
subscribe: CreateWSEdenResponse<Path, Schema, MacroContext, ComposeElysiaResponse<Schema & MacroContext & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], Response, UnionResponseStatus<Metadata['response'], UnionResponseStatus<Ephemeral['response'], UnionResponseStatus<Volatile['response'], MacroContext['return'] & {}>>>, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>>;
|
|
29
|
-
}>, Ephemeral, Volatile>;
|
|
30
14
|
declare class Elysia<const in out BasePath extends string = '', const in out Scope extends EventScope = 'local', const in out Singleton extends SingletonBase = DefaultSingleton, const in out Definitions extends DefinitionBase = {
|
|
31
15
|
typebox: {};
|
|
32
16
|
error: [];
|
|
@@ -889,7 +873,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
889
873
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'get', Path, Schema, MacroContext, Handle>;
|
|
890
874
|
get<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
891
875
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
892
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
876
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'get', Path, Schema, {}, Handle>;
|
|
893
877
|
/**
|
|
894
878
|
* ### post
|
|
895
879
|
* Register handler for path with method [POST]
|
|
@@ -909,7 +893,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
909
893
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'post', Path, Schema, MacroContext, Handle>;
|
|
910
894
|
post<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
911
895
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
912
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
896
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'post', Path, Schema, {}, Handle>;
|
|
913
897
|
/**
|
|
914
898
|
* ### put
|
|
915
899
|
* Register handler for path with method [PUT]
|
|
@@ -929,7 +913,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
929
913
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'put', Path, Schema, MacroContext, Handle>;
|
|
930
914
|
put<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
931
915
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
932
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
916
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'put', Path, Schema, {}, Handle>;
|
|
933
917
|
/**
|
|
934
918
|
* ### patch
|
|
935
919
|
* Register handler for path with method [PATCH]
|
|
@@ -949,7 +933,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
949
933
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'patch', Path, Schema, MacroContext, Handle>;
|
|
950
934
|
patch<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
951
935
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
952
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
936
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'patch', Path, Schema, {}, Handle>;
|
|
953
937
|
/**
|
|
954
938
|
* ### delete
|
|
955
939
|
* Register handler for path with method [DELETE]
|
|
@@ -969,7 +953,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
969
953
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'delete', Path, Schema, MacroContext, Handle>;
|
|
970
954
|
delete<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
971
955
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
972
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
956
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'delete', Path, Schema, {}, Handle>;
|
|
973
957
|
/**
|
|
974
958
|
* ### options
|
|
975
959
|
* Register handler for path with method [OPTIONS]
|
|
@@ -989,7 +973,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
989
973
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'options', Path, Schema, MacroContext, Handle>;
|
|
990
974
|
options<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
991
975
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
992
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
976
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'options', Path, Schema, {}, Handle>;
|
|
993
977
|
/**
|
|
994
978
|
* ### head
|
|
995
979
|
* Register handler for path with method [HEAD]
|
|
@@ -1009,13 +993,13 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
1009
993
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'head', Path, Schema, MacroContext, Handle>;
|
|
1010
994
|
head<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
1011
995
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1012
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
996
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, 'head', Path, Schema, {}, Handle>;
|
|
1013
997
|
all<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 Decorator extends Singleton & {
|
|
1014
998
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1015
999
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): this;
|
|
1016
1000
|
all<const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
1017
1001
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1018
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
1002
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(path: Path, fn: Handle & Metadata['macro']): this;
|
|
1019
1003
|
/**
|
|
1020
1004
|
* ### method
|
|
1021
1005
|
* Register a handler for `path` with an arbitrary HTTP `method`
|
|
@@ -1034,7 +1018,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
1034
1018
|
}, const MacroContext extends ({} extends Metadata['macroFn'] ? {} : MacroToContext<Metadata['macroFn'], Omit<Input, NonResolvableMacroKey>, Definitions['typebox']>), const Handle extends ({} extends MacroContext ? InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>> : InlineHandler<NoInfer<Schema>, NoInfer<Decorator>, MacroContext>)>(method: Method, path: Path, hook: LocalHook<Input, Schema & MacroContext, Decorator, Definitions['error'], keyof Metadata['parser']>, fn: Handle): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, Method, Path, Schema, MacroContext, Handle>;
|
|
1035
1019
|
method<const Method extends HTTPMethod, const Path extends string, const Schema extends IntersectIfObjectSchema<MergeSchema<UnwrapRoute<{}, Definitions['typebox'], JoinPath<BasePath, Path>>, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, '', true>, MergeScopedSchemas<Metadata['schemas'], Ephemeral['schemas'], Volatile['schemas']>>, const Decorator extends Singleton & {
|
|
1036
1020
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1037
|
-
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator
|
|
1021
|
+
}, const Handle extends InlineHandlerNonMacro<NoInfer<Schema>, NoInfer<Decorator>>>(method: Method, path: Path, fn: Handle & Metadata['macro']): AddRoute<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, Volatile, Method, Path, Schema, {}, Handle>;
|
|
1038
1022
|
/**
|
|
1039
1023
|
* ### ws
|
|
1040
1024
|
* Register a WebSocket route. Mirrors `.get`/`.post` ergonomics:
|
package/dist/base.js
CHANGED
|
@@ -14,6 +14,22 @@ memoirist = require_runtime.__toESM(memoirist);
|
|
|
14
14
|
|
|
15
15
|
//#region src/base.ts
|
|
16
16
|
const useNodesBuffer = [];
|
|
17
|
+
const isPlainObject = (v) => {
|
|
18
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
19
|
+
const proto = Object.getPrototypeOf(v);
|
|
20
|
+
return proto === Object.prototype || proto === null;
|
|
21
|
+
};
|
|
22
|
+
function clonePlainDecorators(source, seen = /* @__PURE__ */ new WeakMap()) {
|
|
23
|
+
const existing = seen.get(source);
|
|
24
|
+
if (existing) return existing;
|
|
25
|
+
const out = require_utils.nullObject();
|
|
26
|
+
seen.set(source, out);
|
|
27
|
+
for (const key in source) {
|
|
28
|
+
const value = source[key];
|
|
29
|
+
out[key] = isPlainObject(value) ? clonePlainDecorators(value, seen) : value;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
17
33
|
var Elysia = class Elysia {
|
|
18
34
|
#hasPlugin = false;
|
|
19
35
|
#hasGlobal = false;
|
|
@@ -31,7 +47,7 @@ var Elysia = class Elysia {
|
|
|
31
47
|
}
|
|
32
48
|
}
|
|
33
49
|
get history() {
|
|
34
|
-
if (!this.#history) return
|
|
50
|
+
if (!this.#history) return;
|
|
35
51
|
this.#resolveMacros();
|
|
36
52
|
return this.#history;
|
|
37
53
|
}
|
|
@@ -47,9 +63,8 @@ var Elysia = class Elysia {
|
|
|
47
63
|
if (!this.#history) return [];
|
|
48
64
|
if (this.#cachedRoutes) return this.#cachedRoutes;
|
|
49
65
|
this.#resolveMacros();
|
|
50
|
-
const routes = this.#history.map(([method, path, handler, , hook, appHook]) => {
|
|
51
|
-
const
|
|
52
|
-
const merged = flatAppHook ? hook ? require_utils.mergeHook(require_utils.cloneHook(hook), flatAppHook) : flatAppHook : hook;
|
|
66
|
+
const routes = this.#history.map(([method, path, handler, instance, hook, appHook, inheritedChain]) => {
|
|
67
|
+
const merged = require_compile_handler_index.composeRouteHook(instance, hook, appHook, inheritedChain, this);
|
|
53
68
|
if (merged?.schemas?.length) for (const entry of merged.schemas) {
|
|
54
69
|
if (!entry?.response) continue;
|
|
55
70
|
merged.response = require_utils.mergeResponse(merged.response, entry.response);
|
|
@@ -138,7 +153,7 @@ var Elysia = class Elysia {
|
|
|
138
153
|
headers(headers) {
|
|
139
154
|
const ext = this.#ext;
|
|
140
155
|
if (ext.headers) Object.assign(ext.headers, headers);
|
|
141
|
-
else ext.headers = headers;
|
|
156
|
+
else ext.headers = Object.assign(require_utils.nullObject(), headers);
|
|
142
157
|
return this;
|
|
143
158
|
}
|
|
144
159
|
#on(type, fn, scope = this["~config"]?.as) {
|
|
@@ -293,7 +308,8 @@ var Elysia = class Elysia {
|
|
|
293
308
|
require_utils.hookToGuard(hook);
|
|
294
309
|
if (hook.derive) {
|
|
295
310
|
this["~derive"] ??= /* @__PURE__ */ new WeakSet();
|
|
296
|
-
this["~derive"].add(
|
|
311
|
+
if (Array.isArray(hook.derive)) for (const fn of hook.derive) this["~derive"].add(fn);
|
|
312
|
+
else this["~derive"].add(hook.derive);
|
|
297
313
|
}
|
|
298
314
|
const trackFn = (fn) => {
|
|
299
315
|
if (typeof fn !== "function") return;
|
|
@@ -355,7 +371,8 @@ var Elysia = class Elysia {
|
|
|
355
371
|
if (hook.derive) {
|
|
356
372
|
const promoted = require_utils.nullObject();
|
|
357
373
|
for (const key of Object.keys(hook)) {
|
|
358
|
-
if (
|
|
374
|
+
if (key === "derive" || key === "resolve") continue;
|
|
375
|
+
if (!require_utils.eventProperties.has(key) && !require_utils.schemaProperties.has(key) && key !== "schema" && key !== "schemas") continue;
|
|
359
376
|
promoted[key] = hook[key];
|
|
360
377
|
}
|
|
361
378
|
const extras = [];
|
|
@@ -542,8 +559,11 @@ var Elysia = class Elysia {
|
|
|
542
559
|
if (app["~ext"]) {
|
|
543
560
|
const { decorator, store, headers, models, parser, macro, error, hoc } = app["~ext"];
|
|
544
561
|
const ext = this["~ext"] ??= require_utils.nullObject();
|
|
545
|
-
if (decorator)
|
|
546
|
-
|
|
562
|
+
if (decorator) {
|
|
563
|
+
const cloned = clonePlainDecorators(decorator);
|
|
564
|
+
if (ext.decorator) require_utils.mergeDeep(ext.decorator, cloned);
|
|
565
|
+
else ext.decorator = Object.assign(require_utils.nullObject(), cloned);
|
|
566
|
+
}
|
|
547
567
|
if (store) if (ext.store) require_utils.mergeDeep(ext.store, store);
|
|
548
568
|
else ext.store = Object.assign(require_utils.nullObject(), store);
|
|
549
569
|
if (headers) if (ext.headers) Object.assign(ext.headers, headers);
|
|
@@ -585,7 +605,7 @@ var Elysia = class Elysia {
|
|
|
585
605
|
const isGlobal = nodeScope === "global";
|
|
586
606
|
const added = node.added;
|
|
587
607
|
for (const key in added) {
|
|
588
|
-
if (key === "
|
|
608
|
+
if (key === "schemas") {
|
|
589
609
|
const schemas = added.schemas;
|
|
590
610
|
if (!schemas) continue;
|
|
591
611
|
const target = isGlobal ? globalEvents ??= require_utils.nullObject() : pluginEvents ??= require_utils.nullObject();
|
|
@@ -595,6 +615,7 @@ var Elysia = class Elysia {
|
|
|
595
615
|
}
|
|
596
616
|
continue;
|
|
597
617
|
}
|
|
618
|
+
if (key === "schema") continue;
|
|
598
619
|
if (require_utils.eventProperties.has(key)) {
|
|
599
620
|
const raw = added[key];
|
|
600
621
|
const fns = Array.isArray(raw) ? raw : [raw];
|
|
@@ -773,7 +794,7 @@ var Elysia = class Elysia {
|
|
|
773
794
|
if (!adapter?.websocket && !require_universal_constants.isBun) throw new Error(`[Elysia] WebSocket is not supported on '${adapter?.name ?? "web-standard"}' adapter.`);
|
|
774
795
|
let opts;
|
|
775
796
|
if (handler !== void 0) {
|
|
776
|
-
opts =
|
|
797
|
+
opts = Object.assign(require_utils.nullObject(), optionsOrHandler);
|
|
777
798
|
if (opts.message != null && opts.message !== handler) throw new Error("[Elysia] .ws(): cannot specify 'message' as both positional handler and options.message");
|
|
778
799
|
opts.message = handler;
|
|
779
800
|
} else if (typeof optionsOrHandler === "function") {
|
|
@@ -891,6 +912,22 @@ var Elysia = class Elysia {
|
|
|
891
912
|
}
|
|
892
913
|
const wrapHeadHandler = Elysia.#wrapHeadHandler;
|
|
893
914
|
const strict = !!this["~config"]?.strictPath;
|
|
915
|
+
let explicitPaths;
|
|
916
|
+
if (!strict) {
|
|
917
|
+
explicitPaths = /* @__PURE__ */ new Map();
|
|
918
|
+
for (let i = 0; i < length; i++) {
|
|
919
|
+
const route = this.#history[i];
|
|
920
|
+
const m = route[0] === "WS" ? "WS" : require_utils.mapMethodBack(route[0]);
|
|
921
|
+
const p = route[1];
|
|
922
|
+
let set = explicitPaths.get(m);
|
|
923
|
+
if (!set) explicitPaths.set(m, set = /* @__PURE__ */ new Set());
|
|
924
|
+
set.add(p);
|
|
925
|
+
if (require_constants.needEncodeRegex.test(p)) {
|
|
926
|
+
const encoded = encodeURI(p);
|
|
927
|
+
if (encoded !== p) set.add(encoded);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
}
|
|
894
931
|
for (let i = 0; i < length; i++) {
|
|
895
932
|
const route = this.#history[i];
|
|
896
933
|
const method = require_utils.mapMethodBack(route[0]);
|
|
@@ -906,7 +943,7 @@ var Elysia = class Elysia {
|
|
|
906
943
|
wsMap[path] = handler;
|
|
907
944
|
if (!this["~config"]?.strictPath) {
|
|
908
945
|
const loose = require_utils.getLoosePath(path);
|
|
909
|
-
if (loose !== path) wsMap[loose] = handler;
|
|
946
|
+
if (loose !== path && !explicitPaths?.get("WS")?.has(loose)) wsMap[loose] = handler;
|
|
910
947
|
}
|
|
911
948
|
}
|
|
912
949
|
if (options && require_utils.isNotEmpty(options)) {
|
|
@@ -932,19 +969,20 @@ var Elysia = class Elysia {
|
|
|
932
969
|
(target[path] ??= require_utils.nullObject())[method] = staticResponse;
|
|
933
970
|
if (!this["~config"]?.strictPath) {
|
|
934
971
|
const loose = require_utils.getLoosePath(path);
|
|
935
|
-
(target[loose] ??= require_utils.nullObject())[method] = staticResponse;
|
|
972
|
+
if (!explicitPaths?.get(method)?.has(loose)) (target[loose] ??= require_utils.nullObject())[method] = staticResponse;
|
|
936
973
|
}
|
|
937
974
|
}
|
|
938
975
|
}
|
|
939
976
|
const sharedStatic = maybeStatic && staticResponse instanceof Response ? staticResponse : void 0;
|
|
940
977
|
const autoHead = enableAutoHead && method === "GET" && !explicitHead?.has(path);
|
|
941
|
-
const registerPattern = (registerMain, registerHead, handler, headHandler) => {
|
|
978
|
+
const registerPattern = (registerMain, registerHead, handler, headHandler, registerLoose) => {
|
|
979
|
+
const explicitMain = explicitPaths?.get(method);
|
|
942
980
|
const add = (p) => {
|
|
943
981
|
registerMain(p, handler);
|
|
944
982
|
if (headHandler) registerHead(p, headHandler);
|
|
945
|
-
if (
|
|
983
|
+
if (registerLoose) {
|
|
946
984
|
const loose = require_utils.getLoosePath(p);
|
|
947
|
-
if (loose !== p) {
|
|
985
|
+
if (loose !== p && !explicitMain?.has(loose)) {
|
|
948
986
|
registerMain(loose, handler);
|
|
949
987
|
if (headHandler) registerHead(loose, headHandler);
|
|
950
988
|
}
|
|
@@ -959,7 +997,7 @@ var Elysia = class Elysia {
|
|
|
959
997
|
if (require_constants.isDynamicRegex.test(path)) {
|
|
960
998
|
const router = this["~router"] ??= new memoirist.default();
|
|
961
999
|
const handler = this.handler(i, precompile, void 0, sharedStatic);
|
|
962
|
-
registerPattern((p, h) => router.add(method, p, h, false), (p, h) => router.add("HEAD", p, h, false), handler, autoHead ? wrapHeadHandler(handler) : void 0);
|
|
1000
|
+
registerPattern((p, h) => router.add(method, p, h, false), (p, h) => router.add("HEAD", p, h, false), handler, autoHead ? wrapHeadHandler(handler) : void 0, false);
|
|
963
1001
|
} else {
|
|
964
1002
|
const map = methods[method] ??= require_utils.nullObject();
|
|
965
1003
|
const handler = this.handler(i, precompile, route, sharedStatic);
|
|
@@ -969,7 +1007,7 @@ var Elysia = class Elysia {
|
|
|
969
1007
|
map[p] = h;
|
|
970
1008
|
}, (p, h) => {
|
|
971
1009
|
head[p] = h;
|
|
972
|
-
}, handler, headHandler);
|
|
1010
|
+
}, handler, headHandler, !strict);
|
|
973
1011
|
}
|
|
974
1012
|
}
|
|
975
1013
|
}
|