elysia 2.0.0-beta.8 → 2.0.0-beta.9
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.
|
@@ -211,6 +211,10 @@ function composeRootHook(root, inheritedChain) {
|
|
|
211
211
|
if (!locals) return inherited;
|
|
212
212
|
return require_utils.mergeHook(inherited, locals);
|
|
213
213
|
}
|
|
214
|
+
function staticPrimitiveType(response, value) {
|
|
215
|
+
if ((typeof value === "string" || typeof value === "number" || typeof value === "boolean") && !response.headers.has("content-type")) response.headers.set("content-type", "text/plain;charset=utf-8");
|
|
216
|
+
return response;
|
|
217
|
+
}
|
|
214
218
|
function buildNativeStaticResponse(route, root) {
|
|
215
219
|
const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
216
220
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
@@ -221,10 +225,7 @@ function buildNativeStaticResponse(route, root) {
|
|
|
221
225
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
222
226
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
223
227
|
const mapped = adapter.response.map(handler, { headers: rootHeaders ? Object.assign(require_utils.nullObject(), rootHeaders) : require_utils.nullObject() });
|
|
224
|
-
if (mapped instanceof Response)
|
|
225
|
-
if (!mapped.headers.has("content-type") && (typeof handler === "string" || typeof handler === "number" || typeof handler === "boolean")) mapped.headers.set("content-type", "text/plain;charset=utf-8");
|
|
226
|
-
return mapped;
|
|
227
|
-
}
|
|
228
|
+
if (mapped instanceof Response) return staticPrimitiveType(mapped, handler);
|
|
228
229
|
}
|
|
229
230
|
function toArray(name, hook) {
|
|
230
231
|
if (typeof hook[name] === "function") hook[name] = [hook[name]];
|
|
@@ -320,7 +321,7 @@ function compileHandler(route, root, precomputedStatic, liveOnly = false) {
|
|
|
320
321
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
321
322
|
const set = { headers: rootHeaders ? Object.assign(require_utils.nullObject(), rootHeaders) : require_utils.nullObject() };
|
|
322
323
|
const mapped = adapter.response.map(handler, set);
|
|
323
|
-
if (mapped instanceof Response) handler = mapped;
|
|
324
|
+
if (mapped instanceof Response) handler = staticPrimitiveType(mapped, handler);
|
|
324
325
|
}
|
|
325
326
|
const isStaticResponse = !isHandleFunction && handler instanceof Response;
|
|
326
327
|
const isPromiseHandler = !isHandleFunction && handler instanceof Promise;
|
|
@@ -210,6 +210,10 @@ function composeRootHook(root, inheritedChain) {
|
|
|
210
210
|
if (!locals) return inherited;
|
|
211
211
|
return mergeHook(inherited, locals);
|
|
212
212
|
}
|
|
213
|
+
function staticPrimitiveType(response, value) {
|
|
214
|
+
if ((typeof value === "string" || typeof value === "number" || typeof value === "boolean") && !response.headers.has("content-type")) response.headers.set("content-type", "text/plain;charset=utf-8");
|
|
215
|
+
return response;
|
|
216
|
+
}
|
|
213
217
|
function buildNativeStaticResponse(route, root) {
|
|
214
218
|
const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
215
219
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
@@ -220,10 +224,7 @@ function buildNativeStaticResponse(route, root) {
|
|
|
220
224
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
221
225
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
222
226
|
const mapped = adapter.response.map(handler, { headers: rootHeaders ? Object.assign(nullObject(), rootHeaders) : nullObject() });
|
|
223
|
-
if (mapped instanceof Response)
|
|
224
|
-
if (!mapped.headers.has("content-type") && (typeof handler === "string" || typeof handler === "number" || typeof handler === "boolean")) mapped.headers.set("content-type", "text/plain;charset=utf-8");
|
|
225
|
-
return mapped;
|
|
226
|
-
}
|
|
227
|
+
if (mapped instanceof Response) return staticPrimitiveType(mapped, handler);
|
|
227
228
|
}
|
|
228
229
|
function toArray(name, hook) {
|
|
229
230
|
if (typeof hook[name] === "function") hook[name] = [hook[name]];
|
|
@@ -319,7 +320,7 @@ function compileHandler(route, root, precomputedStatic, liveOnly = false) {
|
|
|
319
320
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
320
321
|
const set = { headers: rootHeaders ? Object.assign(nullObject(), rootHeaders) : nullObject() };
|
|
321
322
|
const mapped = adapter.response.map(handler, set);
|
|
322
|
-
if (mapped instanceof Response) handler = mapped;
|
|
323
|
+
if (mapped instanceof Response) handler = staticPrimitiveType(mapped, handler);
|
|
323
324
|
}
|
|
324
325
|
const isStaticResponse = !isHandleFunction && handler instanceof Response;
|
|
325
326
|
const isPromiseHandler = !isHandleFunction && handler instanceof Promise;
|
package/dist/package.js
CHANGED
package/dist/package.mjs
CHANGED