@darksheep/request-body 1.1.0 → 1.1.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.3](https://github.com/DarkSheepSoftware/node-packages/compare/request-body-v1.1.2...request-body-v1.1.3) (2026-09-20)
4
+
5
+
6
+ ### 📦 Dependencies
7
+
8
+ * **pkg:** update dependency @fastify/busboy to v3.2.1 ([#940](https://github.com/DarkSheepSoftware/node-packages/issues/940)) ([87c873b](https://github.com/DarkSheepSoftware/node-packages/commit/87c873bcad908ce64764788bf76f83ef32d6329d))
9
+ * **pkg:** update dependency @fastify/busboy to v3.2.2 ([#955](https://github.com/DarkSheepSoftware/node-packages/issues/955)) ([5ef0809](https://github.com/DarkSheepSoftware/node-packages/commit/5ef08093a15652913417ac101ed5f98c3fe14d87))
10
+
11
+ ## [1.1.2](https://github.com/DarkSheepSoftware/node-packages/compare/request-body-v1.1.1...request-body-v1.1.2) (2026-04-17)
12
+
13
+
14
+ ### Dependencies
15
+
16
+ * The following workspace dependencies were updated
17
+ * devDependencies
18
+ * @darksheep/fake-fetch bumped to 0.0.3
19
+
20
+ ## [1.1.1](https://github.com/DarkSheepSoftware/node-packages/compare/request-body-v1.1.0...request-body-v1.1.1) (2026-04-17)
21
+
22
+
23
+ ### Dependencies
24
+
25
+ * The following workspace dependencies were updated
26
+ * dependencies
27
+ * @darksheep/errors bumped from 1.2.0 to 1.2.1
28
+ * @darksheep/json-schema bumped to 0.1.2
29
+ * @darksheep/types bumped to 1.3.1
30
+
3
31
  ## [1.1.0](https://github.com/DarkSheepSoftware/node-packages/compare/request-body-v1.0.7...request-body-v1.1.0) (2025-10-09)
4
32
 
5
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darksheep/request-body",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
4
  "description": "http.IncomingMessage to something a little more useful",
5
5
  "license": "UNLICENCED",
6
6
  "type": "module",
@@ -45,15 +45,18 @@
45
45
  "test:watch": "node --watch --test src/**/*.test.js"
46
46
  },
47
47
  "dependencies": {
48
- "@darksheep/errors": "1.2.0",
48
+ "@darksheep/errors": "1.2.1",
49
49
  "@darksheep/json-schema": "",
50
50
  "@darksheep/types": "",
51
- "@fastify/busboy": "3.2.0"
51
+ "@fastify/busboy": "3.2.2"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@darksheep/fake-fetch": ""
55
55
  },
56
56
  "engines": {
57
57
  "node": "^20.13.1 || >=22.2.0"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
58
61
  }
59
62
  }
package/src/form.js CHANGED
@@ -47,7 +47,7 @@ export async function toForm(request, options) {
47
47
 
48
48
  /** @type {Promise<unknown>[]} */
49
49
  const pQueue = [];
50
- return new Promise((resolve, reject) => {
50
+ return await new Promise((resolve, reject) => {
51
51
  busboy
52
52
  .on('file', (fieldname, stream, filename, _encoding, mimetype) => {
53
53
  pQueue.push((async () => {
package/src/json.js CHANGED
@@ -50,5 +50,5 @@ export async function toJson(request, options) {
50
50
  return /** @type {Data} */ (data);
51
51
  }
52
52
 
53
- return validate(options.schema, data, RequestSchemaError);
53
+ return await validate(options.schema, data, RequestSchemaError);
54
54
  }
@@ -15,20 +15,24 @@ const lengths = new WeakMap();
15
15
  * @returns {Transform}
16
16
  */
17
17
  export function limitMaxLength({ maxBytes = 1_000_000 } = {}) {
18
- return new Transform({
18
+ const stream = new Transform({
19
19
  transform(chunk, _encoding, callback) {
20
20
  if (Buffer.isBuffer(chunk) === false) {
21
- return callback(new Error('Cannot chunk, not buffer'));
21
+ callback(new Error('Cannot chunk, not buffer'));
22
+ return;
22
23
  }
23
- const current = lengths.get(this) ?? 0;
24
+ const current = lengths.get(stream) ?? 0;
24
25
  const next = current + chunk.length;
25
- lengths.set(this, next);
26
+ lengths.set(stream, next);
26
27
 
27
28
  if (next > maxBytes) {
28
- return callback(new Error('Maximum stream length exceeded'));
29
+ callback(new Error('Maximum stream length exceeded'));
30
+ return;
29
31
  }
30
32
 
31
33
  callback(null, chunk);
32
34
  },
33
35
  });
36
+
37
+ return stream;
34
38
  }
package/types/buffer.d.ts CHANGED
@@ -1,9 +1,14 @@
1
+ /**
2
+ * @import { Duplex, Readable } from 'node:stream'
3
+ * @import { IncomingMessage } from 'node:http'
4
+ * @import { MaxLengthOptions } from './utilities/max-length.js'
5
+ */
6
+ import type { IncomingMessage } from 'node:http';
7
+ import type { MaxLengthOptions } from './utilities/max-length.js';
8
+ export type ToBufferOptions = (MaxLengthOptions);
1
9
  /**
2
10
  * @param {IncomingMessage} request - The http request object.
3
11
  * @param {MaxLengthOptions} [options] - The request to buffer options.
4
12
  * @returns {Promise<Buffer>}
5
13
  */
6
- export function toBuffer(request: IncomingMessage, options?: MaxLengthOptions): Promise<Buffer>;
7
- export type ToBufferOptions = (MaxLengthOptions);
8
- import type { IncomingMessage } from 'node:http';
9
- import type { MaxLengthOptions } from './utilities/max-length.js';
14
+ export declare function toBuffer(request: IncomingMessage, options?: MaxLengthOptions): Promise<Buffer>;
package/types/form.d.ts CHANGED
@@ -1,9 +1,13 @@
1
+ /**
2
+ * @import { IncomingMessage } from 'node:http'
3
+ * @import { ToBufferOptions } from './buffer.js'
4
+ */
5
+ import type { IncomingMessage } from 'node:http';
6
+ import type { ToBufferOptions } from './buffer.js';
7
+ export type ToFormOptions = (ToBufferOptions);
1
8
  /**
2
9
  * @param {IncomingMessage} request - The http request object.
3
10
  * @param {ToFormOptions} [options] - The request to FormData options.
4
11
  * @returns {Promise<FormData>}
5
12
  */
6
- export function toForm(request: IncomingMessage, options?: ToFormOptions): Promise<FormData>;
7
- export type ToFormOptions = (ToBufferOptions);
8
- import type { IncomingMessage } from 'node:http';
9
- import type { ToBufferOptions } from './buffer.js';
13
+ export declare function toForm(request: IncomingMessage, options?: ToFormOptions): Promise<FormData>;
package/types/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { toBuffer } from "./buffer.js";
2
- export { toJson } from "./json.js";
3
- export { toStream } from "./stream.js";
4
- export { toText } from "./text.js";
5
- export { toForm, toForm as toFormData } from "./form.js";
6
- export { toQuerystring, toQuerystring as toUrlEncoded } from "./querystring.js";
1
+ export { toBuffer } from './buffer.js';
2
+ export { toJson } from './json.js';
3
+ export { toStream } from './stream.js';
4
+ export { toText } from './text.js';
5
+ export { toForm, toForm as toFormData, } from './form.js';
6
+ export { toQuerystring, toQuerystring as toUrlEncoded, } from './querystring.js';
package/types/json.d.ts CHANGED
@@ -1,3 +1,14 @@
1
+ /**
2
+ * @import { IncomingMessage } from 'node:http';
3
+ * @import { FromSchema, JSONSchema } from '@darksheep/json-schema';
4
+ * @import { ToTextOptions } from './text.js';
5
+ */
6
+ import type { IncomingMessage } from 'node:http';
7
+ import type { FromSchema, JSONSchema } from '@darksheep/json-schema';
8
+ import type { ToTextOptions } from './text.js';
9
+ export type ToJsonOptions = (ToTextOptions & {
10
+ schema: JSONSchema;
11
+ });
1
12
  /**
2
13
  * @template {JSONSchema} const Schema - The raw JSON schema.
3
14
  * @template [Data=FromSchema<Schema>] - The typescript type that matches the JSON Schema.
@@ -5,13 +16,6 @@
5
16
  * @param {ToJsonOptions & { schema: Schema }} [options] - The json options to match.
6
17
  * @returns {Promise<Data>}
7
18
  */
8
- export function toJson<const Schema extends JSONSchema, Data = FromSchema<Schema>>(request: IncomingMessage, options?: ToJsonOptions & {
19
+ export declare function toJson<const Schema extends JSONSchema, Data = FromSchema<Schema>>(request: IncomingMessage, options?: ToJsonOptions & {
9
20
  schema: Schema;
10
21
  }): Promise<Data>;
11
- export type ToJsonOptions = (ToTextOptions & {
12
- schema: JSONSchema;
13
- });
14
- import type { JSONSchema } from '@darksheep/json-schema';
15
- import type { FromSchema } from '@darksheep/json-schema';
16
- import type { IncomingMessage } from 'node:http';
17
- import type { ToTextOptions } from './text.js';
@@ -1,3 +1,11 @@
1
+ /**
2
+ * @import { IncomingMessage } from 'node:http'
3
+ * @import { ToTextOptions } from './text.js'
4
+ */
5
+ import type { IncomingMessage } from 'node:http';
6
+ import type { ToTextOptions } from './text.js';
7
+ import { URLSearchParams } from 'node:url';
8
+ export type ToQueryStringOptions = (ToTextOptions);
1
9
  /**
2
10
  * @typedef {(
3
11
  * & ToTextOptions
@@ -8,8 +16,4 @@
8
16
  * @param {ToQueryStringOptions} [options] - The request to QueryString options.
9
17
  * @returns {Promise<URLSearchParams>}
10
18
  */
11
- export function toQuerystring(request: IncomingMessage, options?: ToQueryStringOptions): Promise<URLSearchParams>;
12
- export type ToQueryStringOptions = (ToTextOptions);
13
- import type { IncomingMessage } from 'node:http';
14
- import { URLSearchParams } from 'node:url';
15
- import type { ToTextOptions } from './text.js';
19
+ export declare function toQuerystring(request: IncomingMessage, options?: ToQueryStringOptions): Promise<URLSearchParams>;
package/types/stream.d.ts CHANGED
@@ -1,3 +1,13 @@
1
+ /**
2
+ * @import { IncomingMessage } from 'node:http'
3
+ * @import { ReadableOptions } from 'node:stream'
4
+ * @import { ToBufferOptions } from './buffer.js'
5
+ */
6
+ import type { IncomingMessage } from 'node:http';
7
+ import type { ReadableOptions } from 'node:stream';
8
+ import type { ToBufferOptions } from './buffer.js';
9
+ import { Readable } from 'node:stream';
10
+ export type ToStreamOptions = (ToBufferOptions & ReadableOptions);
1
11
  /**
2
12
  * @typedef {(
3
13
  * & ToBufferOptions
@@ -9,9 +19,4 @@
9
19
  * @param {ToStreamOptions} [options] - The options for the readable stream.
10
20
  * @returns {Promise<Readable>}
11
21
  */
12
- export function toStream(request: IncomingMessage, options?: ToStreamOptions): Promise<Readable>;
13
- export type ToStreamOptions = (ToBufferOptions & ReadableOptions);
14
- import type { IncomingMessage } from 'node:http';
15
- import { Readable } from 'node:stream';
16
- import type { ToBufferOptions } from './buffer.js';
17
- import type { ReadableOptions } from 'node:stream';
22
+ export declare function toStream(request: IncomingMessage, options?: ToStreamOptions): Promise<Readable>;
package/types/text.d.ts CHANGED
@@ -1,3 +1,12 @@
1
+ /**
2
+ * @import { IncomingMessage } from 'node:http'
3
+ * @import { ToBufferOptions } from './buffer.js'
4
+ */
5
+ import type { IncomingMessage } from 'node:http';
6
+ import type { ToBufferOptions } from './buffer.js';
7
+ export type ToTextOptions = (ToBufferOptions & {
8
+ encoding?: BufferEncoding;
9
+ });
1
10
  /**
2
11
  * @typedef {(
3
12
  * & ToBufferOptions
@@ -9,9 +18,4 @@
9
18
  * @param {ToTextOptions} [options] - The options for converting to text.
10
19
  * @returns {Promise<string>}
11
20
  */
12
- export function toText(request: IncomingMessage, options?: ToTextOptions): Promise<string>;
13
- export type ToTextOptions = (ToBufferOptions & {
14
- encoding?: BufferEncoding;
15
- });
16
- import type { IncomingMessage } from 'node:http';
17
- import type { ToBufferOptions } from './buffer.js';
21
+ export declare function toText(request: IncomingMessage, options?: ToTextOptions): Promise<string>;
@@ -1,3 +1,10 @@
1
+ import { Transform } from 'node:stream';
2
+ export type MaxLengthOptions = {
3
+ /**
4
+ * - The maximum number of bytes.
5
+ */
6
+ maxBytes?: number;
7
+ };
1
8
  /**
2
9
  * @typedef MaxLengthOptions
3
10
  * @property {number} [maxBytes] - The maximum number of bytes.
@@ -6,11 +13,4 @@
6
13
  * @param {MaxLengthOptions} [options] - The maximum length of the stream allowed.
7
14
  * @returns {Transform}
8
15
  */
9
- export function limitMaxLength({ maxBytes }?: MaxLengthOptions): Transform;
10
- export type MaxLengthOptions = {
11
- /**
12
- * - The maximum number of bytes.
13
- */
14
- maxBytes?: number;
15
- };
16
- import { Transform } from 'node:stream';
16
+ export declare function limitMaxLength({ maxBytes }?: MaxLengthOptions): Transform;