vafast 0.1.5 → 0.1.6
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/index.js +63 -38
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51852,29 +51852,64 @@ var import_qs = __toESM(require_lib2(), 1);
|
|
|
51852
51852
|
var import_cookie = __toESM(require_dist(), 1);
|
|
51853
51853
|
async function parseBody(req) {
|
|
51854
51854
|
const contentType = req.headers.get("content-type") || "";
|
|
51855
|
-
|
|
51855
|
+
try {
|
|
51856
|
+
if (contentType.includes("application/json")) {
|
|
51857
|
+
try {
|
|
51858
|
+
const body = await req.json();
|
|
51859
|
+
if (body === "" || body === null) {
|
|
51860
|
+
return;
|
|
51861
|
+
}
|
|
51862
|
+
return body;
|
|
51863
|
+
} catch (error) {
|
|
51864
|
+
console.warn("JSON \u89E3\u6790\u5931\u8D25:", error);
|
|
51865
|
+
return;
|
|
51866
|
+
}
|
|
51867
|
+
}
|
|
51868
|
+
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
51869
|
+
try {
|
|
51870
|
+
const text2 = await req.text();
|
|
51871
|
+
if (!text2)
|
|
51872
|
+
return;
|
|
51873
|
+
return Object.fromEntries(new URLSearchParams(text2));
|
|
51874
|
+
} catch (error) {
|
|
51875
|
+
console.warn("\u8868\u5355\u6570\u636E\u89E3\u6790\u5931\u8D25:", error);
|
|
51876
|
+
return;
|
|
51877
|
+
}
|
|
51878
|
+
}
|
|
51879
|
+
if (contentType.includes("multipart/form-data")) {
|
|
51880
|
+
try {
|
|
51881
|
+
return await parseMultipartFormData(req);
|
|
51882
|
+
} catch (error) {
|
|
51883
|
+
console.warn("\u6587\u4EF6\u4E0A\u4F20\u89E3\u6790\u5931\u8D25:", error);
|
|
51884
|
+
return;
|
|
51885
|
+
}
|
|
51886
|
+
}
|
|
51887
|
+
if (contentType.includes("text/plain")) {
|
|
51888
|
+
try {
|
|
51889
|
+
const text2 = await req.text();
|
|
51890
|
+
return text2 || undefined;
|
|
51891
|
+
} catch (error) {
|
|
51892
|
+
console.warn("\u6587\u672C\u89E3\u6790\u5931\u8D25:", error);
|
|
51893
|
+
return;
|
|
51894
|
+
}
|
|
51895
|
+
}
|
|
51896
|
+
if (contentType.includes("application/octet-stream")) {
|
|
51897
|
+
try {
|
|
51898
|
+
return await req.arrayBuffer();
|
|
51899
|
+
} catch (error) {
|
|
51900
|
+
console.warn("\u4E8C\u8FDB\u5236\u6570\u636E\u89E3\u6790\u5931\u8D25:", error);
|
|
51901
|
+
return;
|
|
51902
|
+
}
|
|
51903
|
+
}
|
|
51856
51904
|
try {
|
|
51857
|
-
|
|
51858
|
-
|
|
51905
|
+
const text2 = await req.text();
|
|
51906
|
+
return text2 || undefined;
|
|
51907
|
+
} catch (error) {
|
|
51908
|
+
console.warn("\u9ED8\u8BA4\u6587\u672C\u89E3\u6790\u5931\u8D25:", error);
|
|
51859
51909
|
return;
|
|
51860
51910
|
}
|
|
51861
|
-
}
|
|
51862
|
-
|
|
51863
|
-
const text2 = await req.text();
|
|
51864
|
-
return Object.fromEntries(new URLSearchParams(text2));
|
|
51865
|
-
}
|
|
51866
|
-
if (contentType.includes("multipart/form-data")) {
|
|
51867
|
-
return await parseMultipartFormData(req);
|
|
51868
|
-
}
|
|
51869
|
-
if (contentType.includes("text/plain")) {
|
|
51870
|
-
return await req.text();
|
|
51871
|
-
}
|
|
51872
|
-
if (contentType.includes("application/octet-stream")) {
|
|
51873
|
-
return await req.arrayBuffer();
|
|
51874
|
-
}
|
|
51875
|
-
try {
|
|
51876
|
-
return await req.text();
|
|
51877
|
-
} catch {
|
|
51911
|
+
} catch (error) {
|
|
51912
|
+
console.error("parseBody \u53D1\u751F\u672A\u9884\u671F\u9519\u8BEF:", error);
|
|
51878
51913
|
return;
|
|
51879
51914
|
}
|
|
51880
51915
|
}
|
|
@@ -55570,7 +55605,7 @@ function autoResponseUltra(result) {
|
|
|
55570
55605
|
return EMPTY_RESPONSE_204;
|
|
55571
55606
|
}
|
|
55572
55607
|
}
|
|
55573
|
-
function createRouteHandler(
|
|
55608
|
+
function createRouteHandler(handler, config = {}) {
|
|
55574
55609
|
const hasBodySchema = config.body !== undefined;
|
|
55575
55610
|
const hasQuerySchema = config.query !== undefined;
|
|
55576
55611
|
const hasParamsSchema = config.params !== undefined;
|
|
@@ -55587,22 +55622,12 @@ function createRouteHandler(config, handler) {
|
|
|
55587
55622
|
let cookies = {};
|
|
55588
55623
|
let body = undefined;
|
|
55589
55624
|
let params = {};
|
|
55590
|
-
|
|
55591
|
-
|
|
55592
|
-
|
|
55593
|
-
|
|
55594
|
-
|
|
55595
|
-
}
|
|
55596
|
-
if (hasCookiesSchema) {
|
|
55597
|
-
cookies = parseCookies(req);
|
|
55598
|
-
}
|
|
55599
|
-
if (hasBodySchema) {
|
|
55600
|
-
const [, parsedBody] = await goAwait(parseBody(req));
|
|
55601
|
-
body = parsedBody;
|
|
55602
|
-
}
|
|
55603
|
-
if (hasParamsSchema) {
|
|
55604
|
-
params = req.pathParams || req.params || {};
|
|
55605
|
-
}
|
|
55625
|
+
queryObj = parseQuery(req);
|
|
55626
|
+
headers = parseHeaders(req);
|
|
55627
|
+
cookies = parseCookies(req);
|
|
55628
|
+
const [, parsedBody] = await goAwait(parseBody(req));
|
|
55629
|
+
body = parsedBody;
|
|
55630
|
+
params = req.pathParams || req.params || {};
|
|
55606
55631
|
if (hasBodySchema || hasQuerySchema || hasParamsSchema || hasHeadersSchema || hasCookiesSchema) {
|
|
55607
55632
|
const data = { body, query: queryObj, params, headers, cookies };
|
|
55608
55633
|
validateAllSchemasUltra(config, data);
|
|
@@ -55645,7 +55670,7 @@ function extractSchemaFromError(error) {
|
|
|
55645
55670
|
}
|
|
55646
55671
|
function withExtra() {
|
|
55647
55672
|
return function withExtraHandler(config, handler) {
|
|
55648
|
-
return createRouteHandler(
|
|
55673
|
+
return createRouteHandler(handler, config);
|
|
55649
55674
|
};
|
|
55650
55675
|
}
|
|
55651
55676
|
export {
|