@bepalo/router 2.13.37 → 2.14.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bepalo/router",
3
- "version": "2.13.37",
3
+ "version": "2.14.40",
4
4
  "description": "A fast and feature-rich router for JavaScript runtimes.",
5
5
  "author": "Natnael Eshetu",
6
6
  "license": "MIT",
@@ -55,12 +55,16 @@ export const parseCookie = <XContext = {}>(): FreeHandler<
55
55
 
56
56
  /**
57
57
  * Parsed body object types.
58
- * @typedef {Object} ParsedBody
58
+ * @typedef {Object|Array<unknown>|string|null|undefined} ParsedBody
59
59
  */
60
60
  export type ParsedBody =
61
- | { value: string | number | boolean | null }
62
- | { values: unknown[] }
63
- | Record<string, unknown>;
61
+ | Record<string, unknown>
62
+ | Array<unknown>
63
+ | string
64
+ | number
65
+ | boolean
66
+ | null
67
+ | undefined;
64
68
 
65
69
  /**
66
70
  * Context object containing parsed request body.
@@ -125,7 +129,7 @@ export const parseBody = <XContext = {}>(options?: {
125
129
  ? parseInt(contentLengthHeader)
126
130
  : undefined;
127
131
  if (contentLength === 0) {
128
- ctx.body = {};
132
+ ctx.body = undefined;
129
133
  return;
130
134
  }
131
135
  if (contentLength !== undefined && contentLength > maxSize) {
@@ -138,31 +142,17 @@ export const parseBody = <XContext = {}>(options?: {
138
142
  ctx.body = Object.fromEntries(body.entries());
139
143
  break;
140
144
  }
141
- case "application/json": {
142
- const body = await req.json();
143
- if (Array.isArray(body)) {
144
- ctx.body = { values: body };
145
- } else if (body === undefined) {
146
- ctx.body = {};
147
- } else if (body === null) {
148
- ctx.body = { value: null };
149
- } else if (typeof body === "object") {
150
- ctx.body = body;
151
- } else {
152
- ctx.body = { value: body };
153
- }
145
+ case "application/json":
146
+ ctx.body = await req.json();
154
147
  break;
155
- }
156
- case "text/plain": {
157
- const text = await req.text();
158
- ctx.body = { text };
148
+ case "text/plain":
149
+ ctx.body = await req.text();
159
150
  break;
160
- }
161
151
  default:
162
- ctx.body = {};
152
+ ctx.body = undefined;
163
153
  break;
164
154
  }
165
- } catch (error) {
155
+ } catch {
166
156
  await _req.body?.cancel().catch(() => {});
167
157
  return status(400, "Malformed Payload");
168
158
  }