vafast 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +33 -33
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -51852,31 +51852,30 @@ 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
- try {
51861
- if (contentType.includes("application/json")) {
51855
+ if (contentType.includes("application/json")) {
51856
+ try {
51862
51857
  return await req.json();
51858
+ } catch {
51859
+ return;
51863
51860
  }
51864
- if (contentType.includes("application/x-www-form-urlencoded")) {
51865
- const text2 = await req.text();
51866
- return Object.fromEntries(new URLSearchParams(text2));
51867
- }
51868
- if (contentType.includes("multipart/form-data")) {
51869
- return await parseMultipartFormData(req);
51870
- }
51871
- if (contentType.includes("text/plain")) {
51872
- return await req.text();
51873
- }
51874
- if (contentType.includes("application/octet-stream")) {
51875
- return await req.arrayBuffer();
51876
- }
51861
+ }
51862
+ if (contentType.includes("application/x-www-form-urlencoded")) {
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")) {
51877
51870
  return await req.text();
51878
- } catch (error) {
51879
- throw new Error(`\u89E3\u6790\u8BF7\u6C42\u4F53\u5931\u8D25: ${error instanceof Error ? error.message : "\u672A\u77E5\u9519\u8BEF"}`);
51871
+ }
51872
+ if (contentType.includes("application/octet-stream")) {
51873
+ return await req.arrayBuffer();
51874
+ }
51875
+ try {
51876
+ return await req.text();
51877
+ } catch {
51878
+ return;
51880
51879
  }
51881
51880
  }
51882
51881
  async function parseMultipartFormData(req) {
@@ -55530,23 +55529,21 @@ var defaultValidationErrorHandler = (error, field, value, schema) => {
55530
55529
  timestamp: new Date().toISOString()
55531
55530
  }, 400);
55532
55531
  };
55533
- function autoResponse(result) {
55532
+ var TEXT_HEADERS = { "Content-Type": "text/plain; charset=utf-8" };
55533
+ var EMPTY_RESPONSE_204 = new Response(null, { status: 204 });
55534
+ function autoResponseUltra(result) {
55534
55535
  if (result instanceof Response) {
55535
55536
  return result;
55536
55537
  }
55537
55538
  if (result === null || result === undefined) {
55538
- return new Response("", { status: 204 });
55539
+ return EMPTY_RESPONSE_204;
55539
55540
  }
55540
55541
  switch (typeof result) {
55541
55542
  case "string":
55542
- return new Response(result, {
55543
- headers: { "Content-Type": "text/plain; charset=utf-8" }
55544
- });
55543
+ return new Response(result, { headers: TEXT_HEADERS });
55545
55544
  case "number":
55546
55545
  case "boolean":
55547
- return new Response(String(result), {
55548
- headers: { "Content-Type": "text/plain; charset=utf-8" }
55549
- });
55546
+ return new Response(result.toString(), { headers: TEXT_HEADERS });
55550
55547
  case "object":
55551
55548
  if ("data" in result) {
55552
55549
  const { data, status = 200, headers = {} } = result;
@@ -55561,13 +55558,16 @@ function autoResponse(result) {
55561
55558
  "Content-Type": "text/plain; charset=utf-8",
55562
55559
  ...headers
55563
55560
  };
55564
- return new Response(String(data), { status, headers: finalHeaders });
55561
+ return new Response(data.toString(), {
55562
+ status,
55563
+ headers: finalHeaders
55564
+ });
55565
55565
  }
55566
55566
  return json(data, status, headers);
55567
55567
  }
55568
55568
  return json(result);
55569
55569
  default:
55570
- return new Response("", { status: 204 });
55570
+ return EMPTY_RESPONSE_204;
55571
55571
  }
55572
55572
  }
55573
55573
  function createRouteHandler(config, handler) {
@@ -55617,7 +55617,7 @@ function createRouteHandler(config, handler) {
55617
55617
  cookies,
55618
55618
  ...extras
55619
55619
  });
55620
- return autoResponse(result);
55620
+ return autoResponseUltra(result);
55621
55621
  } catch (error) {
55622
55622
  if (error instanceof Error && error.message.includes("\u9A8C\u8BC1\u5931\u8D25")) {
55623
55623
  const field = extractFieldFromError(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vafast",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "专为Bun构建的极简结构化Web框架。Go风格,函数优先。",
5
5
  "type": "module",
6
6
  "repository": {