vafast 0.1.4 → 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 +55 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51852,31 +51852,65 @@ 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
|
-
const contentLength = req.headers.get("content-length");
|
|
51856
|
-
const maxSize = 10 * 1024 * 1024;
|
|
51857
|
-
if (contentLength && parseInt(contentLength) > maxSize) {
|
|
51858
|
-
throw new Error(`\u8BF7\u6C42\u4F53\u8FC7\u5927: ${contentLength} bytes (\u6700\u5927\u5141\u8BB8: ${maxSize} bytes)`);
|
|
51859
|
-
}
|
|
51860
51855
|
try {
|
|
51861
51856
|
if (contentType.includes("application/json")) {
|
|
51862
|
-
|
|
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
|
+
}
|
|
51863
51867
|
}
|
|
51864
51868
|
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
51865
|
-
|
|
51866
|
-
|
|
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
|
+
}
|
|
51867
51878
|
}
|
|
51868
51879
|
if (contentType.includes("multipart/form-data")) {
|
|
51869
|
-
|
|
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
|
+
}
|
|
51870
51886
|
}
|
|
51871
51887
|
if (contentType.includes("text/plain")) {
|
|
51872
|
-
|
|
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
|
+
}
|
|
51873
51895
|
}
|
|
51874
51896
|
if (contentType.includes("application/octet-stream")) {
|
|
51875
|
-
|
|
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
|
+
}
|
|
51904
|
+
try {
|
|
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);
|
|
51909
|
+
return;
|
|
51876
51910
|
}
|
|
51877
|
-
return await req.text();
|
|
51878
51911
|
} catch (error) {
|
|
51879
|
-
|
|
51912
|
+
console.error("parseBody \u53D1\u751F\u672A\u9884\u671F\u9519\u8BEF:", error);
|
|
51913
|
+
return;
|
|
51880
51914
|
}
|
|
51881
51915
|
}
|
|
51882
51916
|
async function parseMultipartFormData(req) {
|
|
@@ -55571,7 +55605,7 @@ function autoResponseUltra(result) {
|
|
|
55571
55605
|
return EMPTY_RESPONSE_204;
|
|
55572
55606
|
}
|
|
55573
55607
|
}
|
|
55574
|
-
function createRouteHandler(
|
|
55608
|
+
function createRouteHandler(handler, config = {}) {
|
|
55575
55609
|
const hasBodySchema = config.body !== undefined;
|
|
55576
55610
|
const hasQuerySchema = config.query !== undefined;
|
|
55577
55611
|
const hasParamsSchema = config.params !== undefined;
|
|
@@ -55588,22 +55622,12 @@ function createRouteHandler(config, handler) {
|
|
|
55588
55622
|
let cookies = {};
|
|
55589
55623
|
let body = undefined;
|
|
55590
55624
|
let params = {};
|
|
55591
|
-
|
|
55592
|
-
|
|
55593
|
-
|
|
55594
|
-
|
|
55595
|
-
|
|
55596
|
-
}
|
|
55597
|
-
if (hasCookiesSchema) {
|
|
55598
|
-
cookies = parseCookies(req);
|
|
55599
|
-
}
|
|
55600
|
-
if (hasBodySchema) {
|
|
55601
|
-
const [, parsedBody] = await goAwait(parseBody(req));
|
|
55602
|
-
body = parsedBody;
|
|
55603
|
-
}
|
|
55604
|
-
if (hasParamsSchema) {
|
|
55605
|
-
params = req.pathParams || req.params || {};
|
|
55606
|
-
}
|
|
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 || {};
|
|
55607
55631
|
if (hasBodySchema || hasQuerySchema || hasParamsSchema || hasHeadersSchema || hasCookiesSchema) {
|
|
55608
55632
|
const data = { body, query: queryObj, params, headers, cookies };
|
|
55609
55633
|
validateAllSchemasUltra(config, data);
|
|
@@ -55646,7 +55670,7 @@ function extractSchemaFromError(error) {
|
|
|
55646
55670
|
}
|
|
55647
55671
|
function withExtra() {
|
|
55648
55672
|
return function withExtraHandler(config, handler) {
|
|
55649
|
-
return createRouteHandler(
|
|
55673
|
+
return createRouteHandler(handler, config);
|
|
55650
55674
|
};
|
|
55651
55675
|
}
|
|
55652
55676
|
export {
|