Comparing version 1.2.3 to 1.2.4
@@ -7,6 +7,6 @@ import type { Context } from '../../context'; | ||
export declare const mergeResponseWithSetHeaders: (response: Response, set: Context["set"]) => void; | ||
export declare const mapResponse: (response: unknown, set: Context["set"], abortSignal?: AbortSignal) => Response; | ||
export declare const mapEarlyResponse: (response: unknown, set: Context["set"], abortSignal?: AbortSignal) => Response | undefined; | ||
export declare const mapCompactResponse: (response: unknown, abortSignal?: AbortSignal) => Response; | ||
export declare const mapResponse: (response: unknown, set: Context["set"], request?: Request) => Response; | ||
export declare const mapEarlyResponse: (response: unknown, set: Context["set"], request?: Request) => Response | undefined; | ||
export declare const mapCompactResponse: (response: unknown, request?: Request) => Response; | ||
export declare const errorToResponse: (error: Error, set?: Context["set"]) => import("undici-types").Response; | ||
export declare const createStaticHandler: (handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"]) => (() => Response) | undefined; |
@@ -92,8 +92,8 @@ "use strict"; | ||
}; | ||
const handleStream = async (generator, set2, abortSignal) => { | ||
const handleStream = async (generator, set2, request) => { | ||
let init = generator.next(); | ||
if (init instanceof Promise) init = await init; | ||
if (init.done) { | ||
if (set2) return mapResponse(init.value, set2, abortSignal); | ||
return mapCompactResponse(init.value, abortSignal); | ||
if (set2) return mapResponse(init.value, set2, request); | ||
return mapCompactResponse(init.value, request); | ||
} | ||
@@ -104,3 +104,3 @@ return new Response( | ||
let end = false; | ||
abortSignal?.addEventListener("abort", () => { | ||
request?.signal?.addEventListener("abort", () => { | ||
end = true; | ||
@@ -217,3 +217,3 @@ try { | ||
}; | ||
const mapResponse = (response, set2, abortSignal) => { | ||
const mapResponse = (response, set2, request) => { | ||
if ((0, import_utils.isNotEmpty)(set2.headers) || set2.status !== 200 || set2.cookie) { | ||
@@ -236,3 +236,3 @@ handleSet(set2); | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
@@ -244,7 +244,7 @@ case "ReadableStream": | ||
set2.headers["content-type"] = "text/event-stream; charset=utf-8"; | ||
abortSignal?.addEventListener( | ||
request?.signal?.addEventListener( | ||
"abort", | ||
{ | ||
handleEvent() { | ||
if (!abortSignal.aborted) | ||
if (request?.signal && !request?.signal?.aborted) | ||
response.cancel(); | ||
@@ -267,3 +267,3 @@ } | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
@@ -275,6 +275,6 @@ return response; | ||
return response.then( | ||
(x) => mapResponse(x, set2) | ||
(x) => mapResponse(x, set2, request) | ||
); | ||
case "Function": | ||
return mapResponse(response(), set2); | ||
return mapResponse(response(), set2, request); | ||
case "Number": | ||
@@ -301,3 +301,3 @@ case "Boolean": | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
@@ -315,7 +315,7 @@ return response; | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
} | ||
if (typeof response?.next === "function") | ||
return handleStream(response, set2, abortSignal); | ||
return handleStream(response, set2, request); | ||
if (typeof response?.then === "function") | ||
@@ -343,6 +343,6 @@ return response.then((x) => mapResponse(x, set2)); | ||
) | ||
return handleStream(response, set2, abortSignal); | ||
return mapCompactResponse(response, abortSignal); | ||
return handleStream(response, set2, request); | ||
return mapCompactResponse(response, request); | ||
}; | ||
const mapEarlyResponse = (response, set2, abortSignal) => { | ||
const mapEarlyResponse = (response, set2, request) => { | ||
if (response === void 0 || response === null) return; | ||
@@ -366,3 +366,3 @@ if ((0, import_utils.isNotEmpty)(set2.headers) || set2.status !== 200 || set2.cookie) { | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
@@ -374,7 +374,7 @@ case "ReadableStream": | ||
set2.headers["content-type"] = "text/event-stream; charset=utf-8"; | ||
abortSignal?.addEventListener( | ||
request?.signal?.addEventListener( | ||
"abort", | ||
{ | ||
handleEvent() { | ||
if (!abortSignal?.aborted) | ||
if (request?.signal && !request?.signal?.aborted) | ||
response.cancel(); | ||
@@ -397,3 +397,3 @@ } | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
@@ -430,3 +430,3 @@ return response; | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
@@ -444,7 +444,7 @@ return response; | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
} | ||
if (typeof response?.next === "function") | ||
return handleStream(response, set2, abortSignal); | ||
return handleStream(response, set2, request); | ||
if (typeof response?.then === "function") | ||
@@ -483,10 +483,10 @@ return response.then((x) => mapEarlyResponse(x, set2)); | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
case "ReadableStream": | ||
abortSignal?.addEventListener( | ||
request?.signal?.addEventListener( | ||
"abort", | ||
{ | ||
handleEvent() { | ||
if (!abortSignal?.aborted) | ||
if (request?.signal && !request?.signal?.aborted) | ||
response.cancel(); | ||
@@ -525,3 +525,3 @@ } | ||
case "Function": | ||
return mapCompactResponse(response(), abortSignal); | ||
return mapCompactResponse(response(), request); | ||
case "Number": | ||
@@ -547,7 +547,7 @@ case "Boolean": | ||
set2, | ||
abortSignal | ||
request | ||
); | ||
} | ||
if (typeof response?.next === "function") | ||
return handleStream(response, set2, abortSignal); | ||
return handleStream(response, set2, request); | ||
if (typeof response?.then === "function") | ||
@@ -571,3 +571,3 @@ return response.then((x) => mapEarlyResponse(x, set2)); | ||
}; | ||
const mapCompactResponse = (response, abortSignal) => { | ||
const mapCompactResponse = (response, request) => { | ||
switch (response?.constructor?.name) { | ||
@@ -592,7 +592,7 @@ case "String": | ||
case "ReadableStream": | ||
abortSignal?.addEventListener( | ||
request?.signal?.addEventListener( | ||
"abort", | ||
{ | ||
handleEvent() { | ||
if (!abortSignal?.aborted) | ||
if (request?.signal && !request?.signal?.aborted) | ||
response.cancel(); | ||
@@ -625,7 +625,7 @@ } | ||
return response.then( | ||
(x) => mapCompactResponse(x, abortSignal) | ||
(x) => mapCompactResponse(x, request) | ||
); | ||
// ? Maybe response or Blob | ||
case "Function": | ||
return mapCompactResponse(response(), abortSignal); | ||
return mapCompactResponse(response(), request); | ||
case "Number": | ||
@@ -640,3 +640,3 @@ case "Boolean": | ||
return response.then( | ||
(x) => mapCompactResponse(x, abortSignal) | ||
(x) => mapCompactResponse(x, request) | ||
); | ||
@@ -654,3 +654,3 @@ if (response instanceof Error) | ||
if (typeof response?.next === "function") | ||
return handleStream(response, void 0, abortSignal); | ||
return handleStream(response, void 0, request); | ||
if (typeof response?.then === "function") | ||
@@ -657,0 +657,0 @@ return response.then((x) => mapResponse(x, set)); |
@@ -36,3 +36,3 @@ "use strict"; | ||
composeHandler: { | ||
mapResponseContext: "c.request.signal", | ||
mapResponseContext: "c.request", | ||
preferWebstandardHeaders: true, | ||
@@ -39,0 +39,0 @@ // @ts-ignore Bun specific |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"author": { | ||
@@ -125,7 +125,2 @@ "name": "saltyAom", | ||
"require": "./dist/cjs/universal/env.js" | ||
}, | ||
"./universal/file": { | ||
"types": "./dist/universal/file.d.ts", | ||
"import": "./dist/universal/file.mjs", | ||
"require": "./dist/cjs/universal/file.js" | ||
} | ||
@@ -132,0 +127,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1786483