Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elysia

Package Overview
Dependencies
Maintainers
0
Versions
451
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia - npm Package Compare versions

Comparing version 1.2.0-exp.37 to 1.2.0-exp.38

1

dist/adapter/web-standard/handler.d.ts

@@ -5,2 +5,3 @@ import type { Context } from '../../context';

export declare function streamResponse(response: Response): AsyncGenerator<string, void, unknown>;
export declare const handleSet: (set: Context["set"]) => void;
export declare const mapResponse: (response: unknown, set: Context["set"], abortSignal?: AbortSignal) => Response;

@@ -7,0 +8,0 @@ export declare const mapEarlyResponse: (response: unknown, set: Context["set"], abortSignal?: AbortSignal) => Response | undefined;

312

dist/cjs/adapter/web-standard/handler.js

@@ -23,2 +23,3 @@ "use strict";

errorToResponse: () => errorToResponse,
handleSet: () => handleSet,
mapCompactResponse: () => mapCompactResponse,

@@ -170,20 +171,40 @@ mapEarlyResponse: () => mapEarlyResponse,

}
const handleSet = (set2) => {
if (typeof set2.status === "string") set2.status = import_utils.StatusMap[set2.status];
if (set2.redirect) {
set2.headers.Location = set2.redirect;
if (!set2.status || set2.status < 300 || set2.status >= 400)
set2.status = 302;
}
if (set2.cookie && (0, import_utils.isNotEmpty)(set2.cookie)) {
const cookie = (0, import_cookies.serializeCookie)(set2.cookie);
if (cookie) set2.headers["set-cookie"] = cookie;
}
if (set2.headers["set-cookie"] && Array.isArray(set2.headers["set-cookie"])) {
set2.headers = parseSetCookies(
new Headers(set2.headers),
set2.headers["set-cookie"]
);
}
};
const mergeResponseWithSetHeaders = (response, set2) => {
let isCookieSet = false;
if (set2.headers instanceof Headers)
for (const key of set2.headers.keys()) {
if (key === "set-cookie") {
if (isCookieSet) continue;
isCookieSet = true;
for (const cookie of set2.headers.getSetCookie())
response.headers.append("set-cookie", cookie);
} else response.headers.append(key, set2.headers?.get(key) ?? "");
}
else
for (const key in set2.headers)
response.headers.append(key, set2.headers[key]);
if (response.status !== set2.status)
set2.status = response.status;
};
const mapResponse = (response, set2, abortSignal) => {
if ((0, import_utils.isNotEmpty)(set2.headers) || set2.status !== 200 || set2.redirect || set2.cookie) {
if (typeof set2.status === "string") set2.status = import_utils.StatusMap[set2.status];
if (set2.redirect) {
set2.headers.Location = set2.redirect;
if (!set2.status || set2.status < 300 || set2.status >= 400)
set2.status = 302;
}
if (set2.cookie && (0, import_utils.isNotEmpty)(set2.cookie)) {
const cookie = (0, import_cookies.serializeCookie)(set2.cookie);
if (cookie) set2.headers["set-cookie"] = cookie;
}
if (set2.headers["set-cookie"] && Array.isArray(set2.headers["set-cookie"])) {
set2.headers = parseSetCookies(
new Headers(set2.headers),
set2.headers["set-cookie"]
);
}
handleSet(set2);
switch (response?.constructor?.name) {

@@ -228,29 +249,3 @@ case "String":

case "Response":
let isCookieSet = false;
if (set2.headers instanceof Headers)
for (const key of set2.headers.keys()) {
if (key === "set-cookie") {
if (isCookieSet) continue;
isCookieSet = true;
for (const cookie of set2.headers.getSetCookie()) {
;
response.headers.append(
"set-cookie",
cookie
);
}
} else
response.headers.append(
key,
set2.headers?.get(key) ?? ""
);
}
else
for (const key in set2.headers)
response.headers.append(
key,
set2.headers[key]
);
if (response.status !== set2.status)
set2.status = response.status;
mergeResponseWithSetHeaders(response, set2);
if (response.headers.get("transfer-encoding") === "chunked")

@@ -285,32 +280,11 @@ return handleStream(

if (response instanceof Response) {
let isCookieSet2 = false;
if (set2.headers instanceof Headers)
for (const key of set2.headers.keys()) {
if (key === "set-cookie") {
if (isCookieSet2) continue;
isCookieSet2 = true;
for (const cookie of set2.headers.getSetCookie()) {
;
response.headers.append(
"set-cookie",
cookie
);
}
} else
response.headers.append(
key,
set2.headers?.get(key) ?? ""
);
}
else
for (const key in set2.headers)
response.headers.append(
key,
set2.headers[key]
);
if (import_utils.hasHeaderShorthand)
set2.headers = response.headers.toJSON();
else
for (const [key, value] of response.headers.entries())
if (key in set2.headers) set2.headers[key] = value;
mergeResponseWithSetHeaders(response, set2);
if (response.headers.get(
"transfer-encoding"
) === "chunked")
return handleStream(
streamResponse(response),
set2,
abortSignal
);
return response;

@@ -349,106 +323,9 @@ }

}
} else
switch (response?.constructor?.name) {
case "String":
return new Response(response);
case "Array":
case "Object":
return Response.json(response, set2);
case "ElysiaFile":
return handleFile(response.value);
case "Blob":
return handleFile(response, set2);
case "ElysiaCustomStatusResponse":
set2.status = response.code;
return mapResponse(
response.response,
set2,
abortSignal
);
case "ReadableStream":
abortSignal?.addEventListener(
"abort",
{
handleEvent() {
if (!abortSignal?.aborted)
response.cancel();
}
},
{
once: true
}
);
return new Response(response, {
headers: {
"Content-Type": "text/event-stream; charset=utf-8"
}
});
case void 0:
if (!response) return new Response("");
return new Response(JSON.stringify(response), {
headers: {
"content-type": "application/json"
}
});
case "Response":
if (response.headers.get("transfer-encoding") === "chunked")
return handleStream(
streamResponse(response),
set2,
abortSignal
);
return response;
case "Error":
return errorToResponse(response, set2);
case "Promise":
return response.then((x) => {
const r = mapCompactResponse(x, abortSignal);
if (r !== void 0) return r;
return new Response("");
});
// ? Maybe response or Blob
case "Function":
return mapCompactResponse(response(), abortSignal);
case "Number":
case "Boolean":
return new Response(response.toString());
case "Cookie":
if (response instanceof import_cookies.Cookie)
return new Response(response.value, set2);
return new Response(response?.toString(), set2);
case "FormData":
return new Response(response, set2);
default:
if (response instanceof Response) return response;
if (response instanceof Promise)
return response.then((x) => mapResponse(x, set2));
if (response instanceof Error)
return errorToResponse(response, set2);
if (response instanceof import_error.ElysiaCustomStatusResponse) {
set2.status = response.code;
return mapResponse(
response.response,
set2,
abortSignal
);
}
if (typeof response?.next === "function")
return handleStream(response, set2, abortSignal);
if (typeof response?.then === "function")
return response.then((x) => mapResponse(x, set2));
if (typeof response?.toResponse === "function")
return mapResponse(response.toResponse(), set2);
if ("charCodeAt" in response) {
const code = response.charCodeAt(0);
if (code === 123 || code === 91) {
if (!set2.headers["Content-Type"])
set2.headers["Content-Type"] = "application/json";
return new Response(
JSON.stringify(response),
set2
);
}
}
return new Response(response);
}
}
if (
// @ts-expect-error
typeof response?.next === "function" || response instanceof ReadableStream || response instanceof Response && response.headers.get("transfer-encoding") === "chunked"
)
return handleStream(response, set2, abortSignal);
return mapCompactResponse(response, abortSignal);
};

@@ -458,17 +335,3 @@ const mapEarlyResponse = (response, set2, abortSignal) => {

if ((0, import_utils.isNotEmpty)(set2.headers) || set2.status !== 200 || set2.redirect || set2.cookie) {
if (typeof set2.status === "string") set2.status = import_utils.StatusMap[set2.status];
if (set2.redirect) {
set2.headers.Location = set2.redirect;
if (!set2.status || set2.status < 300 || set2.status >= 400)
set2.status = 302;
}
if (set2.cookie && (0, import_utils.isNotEmpty)(set2.cookie)) {
const cookie = (0, import_cookies.serializeCookie)(set2.cookie);
if (cookie) set2.headers["set-cookie"] = cookie;
}
if (set2.headers["set-cookie"] && Array.isArray(set2.headers["set-cookie"]))
set2.headers = parseSetCookies(
new Headers(set2.headers),
set2.headers["set-cookie"]
);
handleSet(set2);
switch (response?.constructor?.name) {

@@ -513,29 +376,3 @@ case "String":

case "Response":
let isCookieSet = false;
if (set2.headers instanceof Headers)
for (const key of set2.headers.keys()) {
if (key === "set-cookie") {
if (isCookieSet) continue;
isCookieSet = true;
for (const cookie of set2.headers.getSetCookie()) {
;
response.headers.append(
"set-cookie",
cookie
);
}
} else
response.headers.append(
key,
set2.headers?.get(key) ?? ""
);
}
else
for (const key in set2.headers)
response.headers.append(
key,
set2.headers[key]
);
if (response.status !== set2.status)
set2.status = response.status;
mergeResponseWithSetHeaders(response, set2);
if (response.headers.get("transfer-encoding") === "chunked")

@@ -571,29 +408,11 @@ return handleStream(

if (response instanceof Response) {
let isCookieSet2 = false;
if (set2.headers instanceof Headers)
for (const key of set2.headers.keys()) {
if (key === "set-cookie") {
if (isCookieSet2) continue;
isCookieSet2 = true;
for (const cookie of set2.headers.getSetCookie()) {
;
response.headers.append(
"set-cookie",
cookie
);
}
} else
response.headers.append(
key,
set2.headers?.get(key) ?? ""
);
}
else
for (const key in set2.headers)
response.headers.append(
key,
set2.headers[key]
);
if (response.status !== set2.status)
set2.status = response.status;
mergeResponseWithSetHeaders(response, set2);
if (response.headers.get(
"transfer-encoding"
) === "chunked")
return handleStream(
streamResponse(response),
set2,
abortSignal
);
return response;

@@ -853,2 +672,3 @@ }

errorToResponse,
handleSet,
mapCompactResponse,

@@ -855,0 +675,0 @@ mapEarlyResponse,

{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "1.2.0-exp.37",
"version": "1.2.0-exp.38",
"author": {

@@ -6,0 +6,0 @@ "name": "saltyAom",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc