elysia 2.0.0-exp.21 → 2.0.0-exp.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/utils.d.ts +1 -1
- package/dist/base.d.ts +1 -1
- package/dist/base.js +8 -15
- package/dist/base.mjs +8 -15
- package/dist/compile/handler/index.d.ts +1 -1
- package/dist/compile/handler/index.js +23 -19
- package/dist/compile/handler/index.mjs +23 -19
- package/dist/error.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/coerce.js +1 -5
- package/dist/type/coerce.mjs +1 -5
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/file-type.d.ts +1 -1
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/index.js +7 -2
- package/dist/type/validator/index.mjs +7 -2
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +1 -1
- package/dist/validator/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/adapter/utils.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare function responseToSetHeaders(response: Response, set?: Context['set']):
|
|
|
11
11
|
cookie?: Record<string, BaseCookie>;
|
|
12
12
|
} | {
|
|
13
13
|
headers: any;
|
|
14
|
-
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" | "
|
|
14
|
+
status: number | "Bad Request" | "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" | "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";
|
|
15
15
|
};
|
|
16
16
|
interface CreateHandlerParameter {
|
|
17
17
|
mapResponse(response: unknown, set: Context['set'], request?: Request): Response;
|
package/dist/base.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ElysiaStatus } from "./error.js";
|
|
2
2
|
import { TraceHandler } from "./trace.js";
|
|
3
|
+
import { AnySchema } from "./type/types.js";
|
|
3
4
|
import { ListenCallback, Serve, Server } from "./universal/server.js";
|
|
4
5
|
import { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, BodyHandler, CompiledHandler, CreateEden, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaHandlerToResponseSchemaAmbiguous, EphemeralType, ErrorDefinitionEntry, ErrorHandler, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, GracefulHandler, GuardLocalHook, HTTPMethod, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, Macro, MacroSchemaChannel, 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
|
-
import { AnySchema } from "./type/types.js";
|
|
6
6
|
import { ChainNode } from "./utils.js";
|
|
7
7
|
import { Context, ErrorContext, LifecycleContext } from "./context.js";
|
|
8
8
|
import { WSHandlerResponse, WSLocalHook, WSMessageHandler } from "./ws/types.js";
|
package/dist/base.js
CHANGED
|
@@ -38,7 +38,6 @@ var Elysia = class Elysia {
|
|
|
38
38
|
}
|
|
39
39
|
#compiled;
|
|
40
40
|
#cachedRoutes;
|
|
41
|
-
#hasMapResponse;
|
|
42
41
|
constructor(config) {
|
|
43
42
|
this["~config"] = config;
|
|
44
43
|
this["~Prefix"] = config?.prefix;
|
|
@@ -213,7 +212,6 @@ var Elysia = class Elysia {
|
|
|
213
212
|
return this.#onBranch("afterHandle", scopeOrFn, fn);
|
|
214
213
|
}
|
|
215
214
|
mapResponse(scopeOrFn, fn) {
|
|
216
|
-
this.#hasMapResponse = true;
|
|
217
215
|
return this.#onBranch("mapResponse", scopeOrFn, fn);
|
|
218
216
|
}
|
|
219
217
|
afterResponse(scopeOrFn, fn) {
|
|
@@ -534,7 +532,6 @@ var Elysia = class Elysia {
|
|
|
534
532
|
}
|
|
535
533
|
}
|
|
536
534
|
const hookChain = app["~hookChain"];
|
|
537
|
-
if (!this.#hasMapResponse && app.#hasMapResponse) this.#hasMapResponse = true;
|
|
538
535
|
if (app["~ext"]) {
|
|
539
536
|
const { decorator, store, headers, models, parser, macro, error, hoc, setup, cleanup } = app["~ext"];
|
|
540
537
|
const ext = this["~ext"] ??= require_utils.nullObject();
|
|
@@ -902,9 +899,9 @@ var Elysia = class Elysia {
|
|
|
902
899
|
for (let i = 0; i < length; i++) if (require_utils.mapMethodBack(this.#history[i][0]) === "HEAD") (explicitHead ??= /* @__PURE__ */ new Set()).add(this.#history[i][1]);
|
|
903
900
|
}
|
|
904
901
|
const wrapHeadHandler = Elysia.#wrapHeadHandler;
|
|
905
|
-
const
|
|
902
|
+
const isLoose = this["~config"]?.strictPath !== true;
|
|
906
903
|
let explicitPaths;
|
|
907
|
-
if (
|
|
904
|
+
if (isLoose && this["~config"]?.distinctPath) {
|
|
908
905
|
explicitPaths = /* @__PURE__ */ new Map();
|
|
909
906
|
for (let i = 0; i < length; i++) {
|
|
910
907
|
const route = this.#history[i];
|
|
@@ -927,12 +924,12 @@ var Elysia = class Elysia {
|
|
|
927
924
|
const ws = require_ws_route.buildWSRoute(route, this);
|
|
928
925
|
const handler = ws[0];
|
|
929
926
|
const options = ws[1];
|
|
930
|
-
if (require_constants.isDynamicRegex.test(path)) (this["~router"] ??= new memoirist.default({ loosePath:
|
|
927
|
+
if (require_constants.isDynamicRegex.test(path)) (this["~router"] ??= new memoirist.default({ loosePath: isLoose })).add("WS", path, handler, false);
|
|
931
928
|
else {
|
|
932
929
|
this.#initMap();
|
|
933
930
|
const wsMap = this["~map"]["WS"] ??= require_utils.nullObject();
|
|
934
931
|
wsMap[path] = handler;
|
|
935
|
-
if (
|
|
932
|
+
if (isLoose) {
|
|
936
933
|
const loose = require_utils.getLoosePath(path);
|
|
937
934
|
if (loose !== path && !explicitPaths?.get("WS")?.has(loose)) wsMap[loose] = handler;
|
|
938
935
|
}
|
|
@@ -954,7 +951,7 @@ var Elysia = class Elysia {
|
|
|
954
951
|
let staticResponse;
|
|
955
952
|
const maybeStatic = buildStatic && typeof route[2] !== "function";
|
|
956
953
|
if (maybeStatic) {
|
|
957
|
-
staticResponse = require_compile_handler_index.buildNativeStaticResponse(route, this
|
|
954
|
+
staticResponse = require_compile_handler_index.buildNativeStaticResponse(route, this);
|
|
958
955
|
if (staticResponse) {
|
|
959
956
|
const target = this["~staticResponse"] ??= {
|
|
960
957
|
GET: void 0,
|
|
@@ -975,7 +972,7 @@ var Elysia = class Elysia {
|
|
|
975
972
|
const sharedStatic = maybeStatic && staticResponse instanceof Response ? staticResponse : void 0;
|
|
976
973
|
const autoHead = enableAutoHead && method === "GET" && !explicitHead?.has(path);
|
|
977
974
|
const isDynamic = require_constants.isDynamicRegex.test(path);
|
|
978
|
-
const registerLoose = !isDynamic &&
|
|
975
|
+
const registerLoose = !isDynamic && isLoose && (path.length === 0 || path.charCodeAt(path.length - 1) === 47);
|
|
979
976
|
const explicitMain = registerLoose ? explicitPaths?.get(method) : void 0;
|
|
980
977
|
if (!isDynamic && !require_constants.needEncodeRegex.test(path) && !registerLoose) {
|
|
981
978
|
const map = methods[method] ??= require_utils.nullObject();
|
|
@@ -1002,7 +999,7 @@ var Elysia = class Elysia {
|
|
|
1002
999
|
}
|
|
1003
1000
|
}
|
|
1004
1001
|
if (isDynamic) {
|
|
1005
|
-
const router = this["~router"] ??= new memoirist.default({ loosePath:
|
|
1002
|
+
const router = this["~router"] ??= new memoirist.default({ loosePath: isLoose });
|
|
1006
1003
|
const handler = this.handler(i, precompile, void 0, sharedStatic);
|
|
1007
1004
|
const headHandler = autoHead ? wrapHeadHandler(handler) : void 0;
|
|
1008
1005
|
for (let p = 0; p < paths.length; p++) {
|
|
@@ -1032,11 +1029,7 @@ var Elysia = class Elysia {
|
|
|
1032
1029
|
return this.#handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.startsWith("/") ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
|
|
1033
1030
|
}
|
|
1034
1031
|
listen(options, callback) {
|
|
1035
|
-
|
|
1036
|
-
this["~config"] ??= require_utils.nullObject();
|
|
1037
|
-
this["~config"].adapter = require_adapter_bun_index.BunAdapter;
|
|
1038
|
-
}
|
|
1039
|
-
const listen = this["~config"]?.adapter?.listen;
|
|
1032
|
+
const listen = (this["~config"]?.adapter ?? require_universal_constants.isBun ? require_adapter_bun_index.BunAdapter : void 0)?.listen;
|
|
1040
1033
|
if (!listen) throw new Error("No adapter provided for listen()");
|
|
1041
1034
|
if (!require_universal_env.env.ELYSIA_AOT_BUILD) listen(this, options, callback);
|
|
1042
1035
|
return this;
|
package/dist/base.mjs
CHANGED
|
@@ -35,7 +35,6 @@ var Elysia = class Elysia {
|
|
|
35
35
|
}
|
|
36
36
|
#compiled;
|
|
37
37
|
#cachedRoutes;
|
|
38
|
-
#hasMapResponse;
|
|
39
38
|
constructor(config) {
|
|
40
39
|
this["~config"] = config;
|
|
41
40
|
this["~Prefix"] = config?.prefix;
|
|
@@ -210,7 +209,6 @@ var Elysia = class Elysia {
|
|
|
210
209
|
return this.#onBranch("afterHandle", scopeOrFn, fn);
|
|
211
210
|
}
|
|
212
211
|
mapResponse(scopeOrFn, fn) {
|
|
213
|
-
this.#hasMapResponse = true;
|
|
214
212
|
return this.#onBranch("mapResponse", scopeOrFn, fn);
|
|
215
213
|
}
|
|
216
214
|
afterResponse(scopeOrFn, fn) {
|
|
@@ -531,7 +529,6 @@ var Elysia = class Elysia {
|
|
|
531
529
|
}
|
|
532
530
|
}
|
|
533
531
|
const hookChain = app["~hookChain"];
|
|
534
|
-
if (!this.#hasMapResponse && app.#hasMapResponse) this.#hasMapResponse = true;
|
|
535
532
|
if (app["~ext"]) {
|
|
536
533
|
const { decorator, store, headers, models, parser, macro, error, hoc, setup, cleanup } = app["~ext"];
|
|
537
534
|
const ext = this["~ext"] ??= nullObject();
|
|
@@ -899,9 +896,9 @@ var Elysia = class Elysia {
|
|
|
899
896
|
for (let i = 0; i < length; i++) if (mapMethodBack(this.#history[i][0]) === "HEAD") (explicitHead ??= /* @__PURE__ */ new Set()).add(this.#history[i][1]);
|
|
900
897
|
}
|
|
901
898
|
const wrapHeadHandler = Elysia.#wrapHeadHandler;
|
|
902
|
-
const
|
|
899
|
+
const isLoose = this["~config"]?.strictPath !== true;
|
|
903
900
|
let explicitPaths;
|
|
904
|
-
if (
|
|
901
|
+
if (isLoose && this["~config"]?.distinctPath) {
|
|
905
902
|
explicitPaths = /* @__PURE__ */ new Map();
|
|
906
903
|
for (let i = 0; i < length; i++) {
|
|
907
904
|
const route = this.#history[i];
|
|
@@ -924,12 +921,12 @@ var Elysia = class Elysia {
|
|
|
924
921
|
const ws = buildWSRoute(route, this);
|
|
925
922
|
const handler = ws[0];
|
|
926
923
|
const options = ws[1];
|
|
927
|
-
if (isDynamicRegex.test(path)) (this["~router"] ??= new Memoirist({ loosePath:
|
|
924
|
+
if (isDynamicRegex.test(path)) (this["~router"] ??= new Memoirist({ loosePath: isLoose })).add("WS", path, handler, false);
|
|
928
925
|
else {
|
|
929
926
|
this.#initMap();
|
|
930
927
|
const wsMap = this["~map"]["WS"] ??= nullObject();
|
|
931
928
|
wsMap[path] = handler;
|
|
932
|
-
if (
|
|
929
|
+
if (isLoose) {
|
|
933
930
|
const loose = getLoosePath(path);
|
|
934
931
|
if (loose !== path && !explicitPaths?.get("WS")?.has(loose)) wsMap[loose] = handler;
|
|
935
932
|
}
|
|
@@ -951,7 +948,7 @@ var Elysia = class Elysia {
|
|
|
951
948
|
let staticResponse;
|
|
952
949
|
const maybeStatic = buildStatic && typeof route[2] !== "function";
|
|
953
950
|
if (maybeStatic) {
|
|
954
|
-
staticResponse = buildNativeStaticResponse(route, this
|
|
951
|
+
staticResponse = buildNativeStaticResponse(route, this);
|
|
955
952
|
if (staticResponse) {
|
|
956
953
|
const target = this["~staticResponse"] ??= {
|
|
957
954
|
GET: void 0,
|
|
@@ -972,7 +969,7 @@ var Elysia = class Elysia {
|
|
|
972
969
|
const sharedStatic = maybeStatic && staticResponse instanceof Response ? staticResponse : void 0;
|
|
973
970
|
const autoHead = enableAutoHead && method === "GET" && !explicitHead?.has(path);
|
|
974
971
|
const isDynamic = isDynamicRegex.test(path);
|
|
975
|
-
const registerLoose = !isDynamic &&
|
|
972
|
+
const registerLoose = !isDynamic && isLoose && (path.length === 0 || path.charCodeAt(path.length - 1) === 47);
|
|
976
973
|
const explicitMain = registerLoose ? explicitPaths?.get(method) : void 0;
|
|
977
974
|
if (!isDynamic && !needEncodeRegex.test(path) && !registerLoose) {
|
|
978
975
|
const map = methods[method] ??= nullObject();
|
|
@@ -999,7 +996,7 @@ var Elysia = class Elysia {
|
|
|
999
996
|
}
|
|
1000
997
|
}
|
|
1001
998
|
if (isDynamic) {
|
|
1002
|
-
const router = this["~router"] ??= new Memoirist({ loosePath:
|
|
999
|
+
const router = this["~router"] ??= new Memoirist({ loosePath: isLoose });
|
|
1003
1000
|
const handler = this.handler(i, precompile, void 0, sharedStatic);
|
|
1004
1001
|
const headHandler = autoHead ? wrapHeadHandler(handler) : void 0;
|
|
1005
1002
|
for (let p = 0; p < paths.length; p++) {
|
|
@@ -1029,11 +1026,7 @@ var Elysia = class Elysia {
|
|
|
1029
1026
|
return this.#handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.startsWith("/") ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
|
|
1030
1027
|
}
|
|
1031
1028
|
listen(options, callback) {
|
|
1032
|
-
|
|
1033
|
-
this["~config"] ??= nullObject();
|
|
1034
|
-
this["~config"].adapter = BunAdapter;
|
|
1035
|
-
}
|
|
1036
|
-
const listen = this["~config"]?.adapter?.listen;
|
|
1029
|
+
const listen = (this["~config"]?.adapter ?? isBun ? BunAdapter : void 0)?.listen;
|
|
1037
1030
|
if (!listen) throw new Error("No adapter provided for listen()");
|
|
1038
1031
|
if (!env.ELYSIA_AOT_BUILD) listen(this, options, callback);
|
|
1039
1032
|
return this;
|
|
@@ -4,7 +4,7 @@ import { AnyElysia } from "../../base.js";
|
|
|
4
4
|
import { setCaptureHeaderShorthand } from "./jit.js";
|
|
5
5
|
|
|
6
6
|
//#region src/compile/handler/index.d.ts
|
|
7
|
-
declare function buildNativeStaticResponse([,, handler, instance, localHook, appHook, inheritedChain]: InternalRoute, root: AnyElysia
|
|
7
|
+
declare function buildNativeStaticResponse([,, handler, instance, localHook, appHook, inheritedChain]: InternalRoute, root: AnyElysia): Response | Promise<Response> | undefined;
|
|
8
8
|
declare function composeRouteHook(instance: AnyElysia, localHook: Partial<AnyLocalHook> | undefined, appHook: ChainNode | undefined, inheritedChain: ChainNode | undefined, root: AnyElysia): AnyLocalHook | undefined;
|
|
9
9
|
declare function compileHandler([_method, path, handler, instance, localHook, appHook, inheritedChain]: InternalRoute, root: AnyElysia, precomputedStatic?: Response): CompiledHandler;
|
|
10
10
|
//#endregion
|
|
@@ -112,34 +112,38 @@ function composeRootHook(root, inheritedChain) {
|
|
|
112
112
|
if (!locals) return inherited;
|
|
113
113
|
return require_utils.mergeHook(inherited, locals);
|
|
114
114
|
}
|
|
115
|
-
function buildNativeStaticResponse([, , handler, instance, localHook, appHook, inheritedChain], root
|
|
115
|
+
function buildNativeStaticResponse([, , handler, instance, localHook, appHook, inheritedChain], root) {
|
|
116
116
|
if (typeof handler === "function" || handler instanceof Error) return;
|
|
117
117
|
const adapter = root["~config"]?.adapter ?? require_adapter_constants.defaultAdapter;
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (hook?.
|
|
124
|
-
|
|
125
|
-
context.responseValue = handler;
|
|
126
|
-
for (let i = 0; i < hook.mapResponse.length; i++) {
|
|
127
|
-
const fn = hook.mapResponse[i];
|
|
128
|
-
if (typeof fn !== "function") continue;
|
|
129
|
-
const mapped = fn(context);
|
|
130
|
-
if (mapped instanceof Response || mapped instanceof Promise) return mapped;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
118
|
+
if (localHook) root["~applyMacro"](localHook);
|
|
119
|
+
resolveChainMacros(root, appHook);
|
|
120
|
+
if (inheritedChain) resolveChainMacros(root, inheritedChain);
|
|
121
|
+
const hook = applyHook(localHook, require_utils.flattenChainMemo(root, appHook), instance !== root ? composeRootHook(root, inheritedChain) : void 0, true);
|
|
122
|
+
if (hook) {
|
|
123
|
+
if (hook?.transform || hook?.beforeHandle || hook?.afterHandle) return;
|
|
124
|
+
if (hook?.body || hook?.query || hook?.params || hook?.headers || hook?.cookie || (hook?.schemas)?.length) return;
|
|
133
125
|
}
|
|
134
126
|
const rootHeaders = root["~ext"]?.headers;
|
|
135
|
-
const
|
|
127
|
+
const mapResponse = hook?.mapResponse ? (value) => {
|
|
128
|
+
const context = new (require_context.createContext(root))(new Request("http://e.ly"));
|
|
129
|
+
context.responseValue = value;
|
|
130
|
+
if (!Array.isArray(hook.mapResponse)) hook.mapResponse = [hook.mapResponse];
|
|
131
|
+
for (let i = 0; i < hook.mapResponse.length; i++) {
|
|
132
|
+
const fn = hook.mapResponse[i];
|
|
133
|
+
if (typeof fn !== "function") continue;
|
|
134
|
+
const mapped = fn(context);
|
|
135
|
+
if (mapped instanceof Response || mapped instanceof Promise) return mapped;
|
|
136
|
+
}
|
|
137
|
+
} : (value) => {
|
|
138
|
+
return adapter.response.map(value, { headers: rootHeaders ? Object.assign(require_utils.nullObject(), rootHeaders) : require_utils.nullObject() });
|
|
139
|
+
};
|
|
136
140
|
if (handler instanceof Promise) return handler.then((resolved) => {
|
|
137
141
|
if (resolved instanceof Response && !rootHeaders) return resolved;
|
|
138
|
-
const mapped =
|
|
142
|
+
const mapped = mapResponse(resolved);
|
|
139
143
|
return mapped instanceof Response ? mapped : void 0;
|
|
140
144
|
});
|
|
141
145
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
142
|
-
const mapped =
|
|
146
|
+
const mapped = mapResponse(handler);
|
|
143
147
|
if (mapped instanceof Response || mapped instanceof Promise) return mapped;
|
|
144
148
|
}
|
|
145
149
|
function toArray(name, hook) {
|
|
@@ -111,34 +111,38 @@ function composeRootHook(root, inheritedChain) {
|
|
|
111
111
|
if (!locals) return inherited;
|
|
112
112
|
return mergeHook(inherited, locals);
|
|
113
113
|
}
|
|
114
|
-
function buildNativeStaticResponse([, , handler, instance, localHook, appHook, inheritedChain], root
|
|
114
|
+
function buildNativeStaticResponse([, , handler, instance, localHook, appHook, inheritedChain], root) {
|
|
115
115
|
if (typeof handler === "function" || handler instanceof Error) return;
|
|
116
116
|
const adapter = root["~config"]?.adapter ?? defaultAdapter;
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (hook?.
|
|
123
|
-
|
|
124
|
-
context.responseValue = handler;
|
|
125
|
-
for (let i = 0; i < hook.mapResponse.length; i++) {
|
|
126
|
-
const fn = hook.mapResponse[i];
|
|
127
|
-
if (typeof fn !== "function") continue;
|
|
128
|
-
const mapped = fn(context);
|
|
129
|
-
if (mapped instanceof Response || mapped instanceof Promise) return mapped;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
117
|
+
if (localHook) root["~applyMacro"](localHook);
|
|
118
|
+
resolveChainMacros(root, appHook);
|
|
119
|
+
if (inheritedChain) resolveChainMacros(root, inheritedChain);
|
|
120
|
+
const hook = applyHook(localHook, flattenChainMemo(root, appHook), instance !== root ? composeRootHook(root, inheritedChain) : void 0, true);
|
|
121
|
+
if (hook) {
|
|
122
|
+
if (hook?.transform || hook?.beforeHandle || hook?.afterHandle) return;
|
|
123
|
+
if (hook?.body || hook?.query || hook?.params || hook?.headers || hook?.cookie || (hook?.schemas)?.length) return;
|
|
132
124
|
}
|
|
133
125
|
const rootHeaders = root["~ext"]?.headers;
|
|
134
|
-
const
|
|
126
|
+
const mapResponse = hook?.mapResponse ? (value) => {
|
|
127
|
+
const context = new (createContext(root))(new Request("http://e.ly"));
|
|
128
|
+
context.responseValue = value;
|
|
129
|
+
if (!Array.isArray(hook.mapResponse)) hook.mapResponse = [hook.mapResponse];
|
|
130
|
+
for (let i = 0; i < hook.mapResponse.length; i++) {
|
|
131
|
+
const fn = hook.mapResponse[i];
|
|
132
|
+
if (typeof fn !== "function") continue;
|
|
133
|
+
const mapped = fn(context);
|
|
134
|
+
if (mapped instanceof Response || mapped instanceof Promise) return mapped;
|
|
135
|
+
}
|
|
136
|
+
} : (value) => {
|
|
137
|
+
return adapter.response.map(value, { headers: rootHeaders ? Object.assign(nullObject(), rootHeaders) : nullObject() });
|
|
138
|
+
};
|
|
135
139
|
if (handler instanceof Promise) return handler.then((resolved) => {
|
|
136
140
|
if (resolved instanceof Response && !rootHeaders) return resolved;
|
|
137
|
-
const mapped =
|
|
141
|
+
const mapped = mapResponse(resolved);
|
|
138
142
|
return mapped instanceof Response ? mapped : void 0;
|
|
139
143
|
});
|
|
140
144
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
141
|
-
const mapped =
|
|
145
|
+
const mapped = mapResponse(handler);
|
|
142
146
|
if (mapped instanceof Response || mapped instanceof Promise) return mapped;
|
|
143
147
|
}
|
|
144
148
|
function toArray(name, hook) {
|
package/dist/error.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ declare class ElysiaStatus<const in out Code extends number | keyof StatusMap, T
|
|
|
85
85
|
constructor(code: Code, res: T);
|
|
86
86
|
get status(): number;
|
|
87
87
|
}
|
|
88
|
-
declare const status: <const Code extends number | keyof StatusMap, const T = (Code extends keyof StatusMapBack ? StatusMapBack[Code] : Code)>(code: Code, response?: T) => ElysiaStatus<Code, T, Code extends "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" | "
|
|
88
|
+
declare const status: <const Code extends number | keyof StatusMap, const T = (Code extends keyof StatusMapBack ? StatusMapBack[Code] : Code)>(code: Code, response?: T) => ElysiaStatus<Code, T, Code extends "Bad Request" | "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" | "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" ? {
|
|
89
89
|
readonly Continue: 100;
|
|
90
90
|
readonly 'Switching Protocols': 101;
|
|
91
91
|
readonly Processing: 102;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { StatusMap, StatusMapBack } from "./constants.js";
|
|
2
2
|
import { ElysiaError, ElysiaStatus, InternalServerError, InvalidCookieSignature, NotFound, ParseError, SelectiveStatus, ValidationError, status, validationDetail } from "./error.js";
|
|
3
|
+
import { ElysiaFile, file } from "./universal/file.js";
|
|
3
4
|
import { BaseCookie, CookieOptions } from "./cookie/types.js";
|
|
4
5
|
import { Cookie } from "./cookie/cookie.js";
|
|
5
|
-
import { ElysiaFile, file } from "./universal/file.js";
|
|
6
|
-
import { env } from "./universal/env.js";
|
|
7
|
-
import { Server } from "./universal/server.js";
|
|
8
|
-
import { HTTPHeaders, InputSchema, Macro, MacroToContext, MacroToProperty, RouteSchema, SSEPayload, UnwrapRoute, UnwrapSchema } from "./types.js";
|
|
9
6
|
import { AnySchema, BaseSchema, StandardJSONSchemaV1Like, StandardSchemaV1Like } from "./type/types.js";
|
|
10
7
|
import { TCookieField, TCookieObject } from "./type/elysia/cookie.js";
|
|
11
8
|
import { FileTypeDetector, fileType, setFileTypeDetector } from "./type/elysia/file-type.js";
|
|
@@ -15,6 +12,9 @@ import { Capture, Compiled } from "./compile/aot.js";
|
|
|
15
12
|
import { MultiValidator, StandardValidator, Validator } from "./validator/index.js";
|
|
16
13
|
import { TypeBoxValidator } from "./type/validator/index.js";
|
|
17
14
|
import { TypeSystem, t } from "./type/index.js";
|
|
15
|
+
import { env } from "./universal/env.js";
|
|
16
|
+
import { Server } from "./universal/server.js";
|
|
17
|
+
import { HTTPHeaders, InputSchema, Macro, MacroToContext, MacroToProperty, RouteSchema, SSEPayload, UnwrapRoute, UnwrapSchema } from "./types.js";
|
|
18
18
|
import { form, prefix, redirect, sse } from "./utils.js";
|
|
19
19
|
import { Context, ErrorContext, createBaseContext, createContext } from "./context.js";
|
|
20
20
|
import { Elysia } from "./base.js";
|
package/dist/type/coerce.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ declare const coerceQuery: () => CoerceOption[];
|
|
|
36
36
|
declare const coerceBody: () => CoerceOption[];
|
|
37
37
|
declare const coerceFormData: () => CoerceOption[];
|
|
38
38
|
declare const coerceStringToStructure: () => CoerceOption[];
|
|
39
|
-
declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined):
|
|
39
|
+
declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined): TSchema | BaseSchema;
|
|
40
40
|
interface CoerceLeaf {
|
|
41
41
|
e: number;
|
|
42
42
|
c?: Record<string, unknown>;
|
package/dist/type/coerce.js
CHANGED
|
@@ -249,16 +249,12 @@ function captureCoercePlan(original, coerced) {
|
|
|
249
249
|
const walk = (o, c) => {
|
|
250
250
|
if (o === c || !c || typeof c !== "object") return null;
|
|
251
251
|
const ely = c["~elyTyp"];
|
|
252
|
-
if (ely === require_type_constants.ELYSIA_TYPES.ObjectString && (!o || o["~elyTyp"] !== ely)) {
|
|
252
|
+
if ((ely === require_type_constants.ELYSIA_TYPES.ObjectString || ely === require_type_constants.ELYSIA_TYPES.ArrayString) && (!o || o["~elyTyp"] !== ely)) {
|
|
253
253
|
any = true;
|
|
254
254
|
const site = { os: ely };
|
|
255
255
|
if (o && "~optional" in o) site.o = o["~optional"];
|
|
256
256
|
return site;
|
|
257
257
|
}
|
|
258
|
-
if (ely === require_type_constants.ELYSIA_TYPES.ArrayString) {
|
|
259
|
-
bakeable = false;
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
258
|
if (ely && COERCE_LEAF_CTOR[ely] && (!o || o["~elyTyp"] !== ely)) {
|
|
263
259
|
any = true;
|
|
264
260
|
const leaf = { e: ely };
|
package/dist/type/coerce.mjs
CHANGED
|
@@ -248,16 +248,12 @@ function captureCoercePlan(original, coerced) {
|
|
|
248
248
|
const walk = (o, c) => {
|
|
249
249
|
if (o === c || !c || typeof c !== "object") return null;
|
|
250
250
|
const ely = c["~elyTyp"];
|
|
251
|
-
if (ely === ELYSIA_TYPES.ObjectString && (!o || o["~elyTyp"] !== ely)) {
|
|
251
|
+
if ((ely === ELYSIA_TYPES.ObjectString || ely === ELYSIA_TYPES.ArrayString) && (!o || o["~elyTyp"] !== ely)) {
|
|
252
252
|
any = true;
|
|
253
253
|
const site = { os: ely };
|
|
254
254
|
if (o && "~optional" in o) site.o = o["~optional"];
|
|
255
255
|
return site;
|
|
256
256
|
}
|
|
257
|
-
if (ely === ELYSIA_TYPES.ArrayString) {
|
|
258
|
-
bakeable = false;
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
257
|
if (ely && COERCE_LEAF_CTOR[ely] && (!o || o["~elyTyp"] !== ely)) {
|
|
262
258
|
any = true;
|
|
263
259
|
const leaf = { e: ely };
|
package/dist/type/constants.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare const ELYSIA_TYPES: {
|
|
|
17
17
|
readonly NoValidate: 15;
|
|
18
18
|
};
|
|
19
19
|
type ELYSIA_TYPES = typeof ELYSIA_TYPES;
|
|
20
|
-
declare const primitiveElysiaTypes: Set<
|
|
20
|
+
declare const primitiveElysiaTypes: Set<2 | 1 | 3 | 6 | 10 | 11 | 13 | 14>;
|
|
21
21
|
declare const noEnumerable: {
|
|
22
22
|
readonly enumerable: false;
|
|
23
23
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MaybeArray, MaybePromise } from "../../types.js";
|
|
2
1
|
import { FileType, FileUnit } from "../types.js";
|
|
2
|
+
import { MaybeArray, MaybePromise } from "../../types.js";
|
|
3
3
|
|
|
4
4
|
//#region src/type/elysia/file-type.d.ts
|
|
5
5
|
type FileTypeDetector = (file: File) => MaybePromise<string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MaybePromise } from "../../types.js";
|
|
2
1
|
import { Validator as Validator$1, ValidatorOptions } from "../../validator/index.js";
|
|
3
2
|
import { TypeBoxValidatorCache } from "./validator-cache.js";
|
|
3
|
+
import { MaybePromise } from "../../types.js";
|
|
4
4
|
import { Static, StaticDecode, StaticEncode, TAny, TSchema } from "typebox/type";
|
|
5
5
|
import { TLocalizedValidationError } from "typebox/error";
|
|
6
6
|
import { Validator } from "typebox/schema";
|
|
@@ -148,8 +148,13 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
148
148
|
const originalElyTyp = schema?.["~elyTyp"];
|
|
149
149
|
const frozen = options?.aot && options.slot ? require_compile_aot.Compiled.getValidator(options.aot.method, options.aot.path, options.slot) : void 0;
|
|
150
150
|
let schemaHasRef = false;
|
|
151
|
-
if (name && options?.models)
|
|
152
|
-
|
|
151
|
+
if (name && options?.models) {
|
|
152
|
+
schema = moduleCache.getOrInsertComputed(options.models, () => (0, typebox_type.Module)(options.models))[name];
|
|
153
|
+
if (isIntersectable) {
|
|
154
|
+
const members = [schema, ...options.schemas];
|
|
155
|
+
schema = shallowMergeObjects(members) ?? (0, typebox_type.Evaluate)((0, typebox_type.Intersect)(members));
|
|
156
|
+
}
|
|
157
|
+
} else if (options?.models && typeof name !== "string") {
|
|
153
158
|
schemaHasRef = frozen ? frozen.r === 1 : schemaContainsRef(schema);
|
|
154
159
|
if (schemaHasRef) {
|
|
155
160
|
const id = `inline@${++inlineRefId}`;
|
|
@@ -145,8 +145,13 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
145
145
|
const originalElyTyp = schema?.["~elyTyp"];
|
|
146
146
|
const frozen = options?.aot && options.slot ? Compiled.getValidator(options.aot.method, options.aot.path, options.slot) : void 0;
|
|
147
147
|
let schemaHasRef = false;
|
|
148
|
-
if (name && options?.models)
|
|
149
|
-
|
|
148
|
+
if (name && options?.models) {
|
|
149
|
+
schema = moduleCache.getOrInsertComputed(options.models, () => Module(options.models))[name];
|
|
150
|
+
if (isIntersectable) {
|
|
151
|
+
const members = [schema, ...options.schemas];
|
|
152
|
+
schema = shallowMergeObjects(members) ?? Evaluate(Intersect(members));
|
|
153
|
+
}
|
|
154
|
+
} else if (options?.models && typeof name !== "string") {
|
|
150
155
|
schemaHasRef = frozen ? frozen.r === 1 : schemaContainsRef(schema);
|
|
151
156
|
if (schemaHasRef) {
|
|
152
157
|
const id = `inline@${++inlineRefId}`;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MethodMap, StatusMapBack } from "./constants.js";
|
|
2
2
|
import { ElysiaError, ElysiaStatus } from "./error.js";
|
|
3
|
-
import { CookieOptions } from "./cookie/types.js";
|
|
4
3
|
import { ElysiaFile } from "./universal/file.js";
|
|
5
4
|
import { TraceEvent, TraceListener } from "./trace.js";
|
|
6
|
-
import {
|
|
5
|
+
import { CookieOptions } from "./cookie/types.js";
|
|
7
6
|
import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
|
|
7
|
+
import { Serve } from "./universal/server.js";
|
|
8
8
|
import { ChainNode } from "./utils.js";
|
|
9
9
|
import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.js";
|
|
10
10
|
import { WebSocketHandler } from "./ws/types.js";
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MethodMap } from "./constants.js";
|
|
2
|
-
import { AnyLocalHook, AppHook, ElysiaFormData, EventFn, EventScope, GuardSchemaType, InputSchema, Macro, MaybeArray, Prettify, SSEPayload } from "./types.js";
|
|
3
2
|
import { AnySchema, StandardSchemaV1Like } from "./type/types.js";
|
|
3
|
+
import { AnyLocalHook, AppHook, ElysiaFormData, EventFn, EventScope, GuardSchemaType, InputSchema, Macro, MaybeArray, Prettify, SSEPayload } from "./types.js";
|
|
4
4
|
import { Context } from "./context.js";
|
|
5
5
|
|
|
6
6
|
//#region src/utils.d.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ElysiaConfig, MaybePromise } from "../types.js";
|
|
2
1
|
import { AnySchema, StandardSchemaV1Like } from "../type/types.js";
|
|
3
2
|
import { CoerceOption } from "../type/coerce.js";
|
|
4
3
|
import { ValidatorSlot } from "../compile/aot.js";
|
|
5
4
|
import { TypeBoxValidator } from "../type/bridge.js";
|
|
5
|
+
import { ElysiaConfig, MaybePromise } from "../types.js";
|
|
6
6
|
import { TSchema } from "typebox/type";
|
|
7
7
|
import { TLocalizedValidationError } from "typebox/error";
|
|
8
8
|
|