@maroonedsoftware/multipart 1.0.0 → 1.0.1

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": "@maroonedsoftware/multipart",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A robust multipart form-data and multipart/related parser for Node.js HTTP servers.",
5
5
  "author": {
6
6
  "name": "Marooned Software",
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@fastify/busboy": "^3.2.0",
37
- "@maroonedsoftware/errors": "1.0.0"
37
+ "@maroonedsoftware/errors": "1.1.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@repo/config-typescript": "0.0.0",
@@ -1,120 +0,0 @@
1
- import { IncomingMessage } from 'node:http';
2
- import { FileHandler, MultipartData } from './types.js';
3
- import { Readable, Writable } from 'node:stream';
4
- /**
5
- * Extended Readable stream interface for multipart/related file parts.
6
- *
7
- * Provides additional metadata about the stream state including whether
8
- * the stream was truncated due to size limits and the total bytes read.
9
- */
10
- export interface MultipartRelatedFileStream extends Readable {
11
- /** Whether the file stream was truncated due to size limits */
12
- truncated: boolean;
13
- /** The number of bytes that have been read from the stream so far */
14
- bytesRead: number;
15
- }
16
- /**
17
- * Parser for multipart/related content type requests.
18
- *
19
- * The multipart/related content type is used when multiple related parts
20
- * need to be processed together, such as email messages with inline attachments
21
- * or SOAP messages with MIME attachments.
22
- *
23
- * This parser extends Writable to act as a stream destination for the incoming
24
- * request body, parsing parts as they arrive and invoking handlers for files.
25
- *
26
- * @extends Writable
27
- *
28
- * @example
29
- * ```typescript
30
- * import { IncomingMessage } from 'node:http';
31
- * import { MultipartRelatedParser } from './multipart.related.parser.js';
32
- *
33
- * async function handleRelatedContent(req: IncomingMessage) {
34
- * const parser = new MultipartRelatedParser(req);
35
- *
36
- * const parts = await parser.parse(async (fieldname, stream, filename) => {
37
- * // Process each related part
38
- * const content = await streamToBuffer(stream);
39
- * console.log(`Received ${filename}: ${content.length} bytes`);
40
- * });
41
- * }
42
- * ```
43
- */
44
- export declare class MultipartRelatedParser extends Writable {
45
- private readonly req;
46
- /** Map storing parsed fields and files keyed by field name */
47
- private readonly fields;
48
- /** Optional handler for processing file uploads */
49
- private fileHandler?;
50
- /** A null stream used to drain file streams when errors occur */
51
- private readonly nullStream;
52
- /**
53
- * Creates a new MultipartRelatedParser instance.
54
- *
55
- * @param req - The incoming HTTP request containing multipart/related data
56
- */
57
- constructor(req: IncomingMessage);
58
- /**
59
- * Parses the multipart/related request body.
60
- *
61
- * @param fileHandler - A callback function to handle file parts as they are received.
62
- * Each file part triggers the handler with the field name, stream,
63
- * filename, encoding, and MIME type.
64
- * @returns A promise that resolves to a Map of field names to their parsed data.
65
- * If multiple values exist for a field name, they are stored as an array.
66
- *
67
- * @throws {HttpError} 413 error if parts, files, or fields limits are exceeded
68
- *
69
- * @example
70
- * ```typescript
71
- * const parts = await parser.parse(async (fieldname, stream, filename) => {
72
- * const chunks: Buffer[] = [];
73
- * for await (const chunk of stream) {
74
- * chunks.push(chunk);
75
- * }
76
- * // Process the complete content
77
- * processContent(Buffer.concat(chunks));
78
- * });
79
- * ```
80
- */
81
- parse(fileHandler: FileHandler): Promise<Map<string, MultipartData | MultipartData[]>>;
82
- /**
83
- * Stores parsed data in the fields map, handling multiple values for the same field.
84
- *
85
- * @param name - The field name
86
- * @param data - The parsed field or file data
87
- */
88
- private setData;
89
- /**
90
- * Handler for parsed form fields.
91
- */
92
- private onField;
93
- /**
94
- * Handler for parsed file uploads.
95
- */
96
- private onFile;
97
- private resolve;
98
- private reject;
99
- /**
100
- * Handler called when parsing completes or an error occurs.
101
- */
102
- private onEnd;
103
- /**
104
- * Handler for when the parts limit is exceeded.
105
- */
106
- private onPartsLimit;
107
- /**
108
- * Handler for when the files limit is exceeded.
109
- */
110
- private onFilesLimit;
111
- /**
112
- * Handler for when the fields limit is exceeded.
113
- */
114
- private onFieldsLimit;
115
- /**
116
- * Cleans up event listeners to prevent memory leaks.
117
- */
118
- private cleanup;
119
- }
120
- //# sourceMappingURL=multipart.related.parser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multipart.related.parser.d.ts","sourceRoot":"","sources":["../src/multipart.related.parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;GAKG;AACH,MAAM,WAAW,0BAA2B,SAAQ,QAAQ;IAC1D,+DAA+D;IAC/D,SAAS,EAAE,OAAO,CAAC;IACnB,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,sBAAuB,SAAQ,QAAQ;IAmBtC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAlBhC,8DAA8D;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsD;IAE7E,mDAAmD;IACnD,OAAO,CAAC,WAAW,CAAC,CAAc;IAElC,iEAAiE;IACjE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAIxB;IAEH;;;;OAIG;gBAC0B,GAAG,EAAE,eAAe;IAIjD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,WAAW,EAAE,WAAW;IAS9B;;;;;OAKG;IACH,OAAO,CAAC,OAAO;IAWf;;OAEG;IACH,OAAO,CAAC,OAAO;IAUf;;OAEG;IACH,OAAO,CAAC,MAAM;IAcd,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,MAAM;IAEd;;OAEG;IACH,OAAO,CAAC,KAAK;IASb;;OAEG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAOrB;;OAEG;IACH,OAAO,CAAC,OAAO;CAUhB"}