graphql-upload 14.0.0 → 15.0.0

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 ADDED
@@ -0,0 +1,606 @@
1
+ # graphql-upload changelog
2
+
3
+ ## 15.0.0
4
+
5
+ ### Major
6
+
7
+ - Updated the [`busboy`](https://npm.im/busboy) dependency to v1, fixing [#311](https://github.com/jaydenseric/graphql-upload/issues/311).
8
+ - This important update addresses the vulnerability [CVE-2022-24434](https://nvd.nist.gov/vuln/detail/CVE-2022-24434) ([GHSA-wm7h-9275-46v2](https://github.com/advisories/GHSA-wm7h-9275-46v2)).
9
+ - Some error messages have changed.
10
+ - Temporarily until [mscdex/busboy#297](https://github.com/mscdex/busboy/issues/297) is fixed upstream, for the function `processRequest` and the middleware `graphqlUploadExpress` and `graphqlUploadKoa` the option `maxFileSize` is actually 1 byte less than the amount specified.
11
+
12
+ ### Patch
13
+
14
+ - Updated the [`typescript`](https://npm.im/typescript) dev dependency.
15
+ - In the function `processRequest` use the `on` method instead of `once` to listen for `error` events on the [`busboy`](https://npm.im/busboy) parser, as in edge cases the same parser could have multiple `error` events and all must be handled to prevent the Node.js process exiting with an error.
16
+ - Simplified error handling within the function `processRequest`.
17
+ - Added a test for the function `processRequest` with a maliciously malformed multipart request.
18
+
19
+ ## 14.0.0
20
+
21
+ ### Major
22
+
23
+ - Updated Node.js support to `^14.17.0 || ^16.0.0 || >= 18.0.0`.
24
+ - Updated the [`graphql`](https://npm.im/graphql) peer dependency to `^16.3.0`.
25
+ - Updated the [`http-errors`](https://npm.im/http-errors) dependency to v2.
26
+ - Public modules are now individually listed in the package `files` and `exports` fields.
27
+ - Removed the package main index module; deep imports must be used.
28
+ - Shortened public module deep import paths, removing the `/public/`.
29
+ - Implemented TypeScript types via JSDoc comments, closing [#282](https://github.com/jaydenseric/graphql-upload/issues/282).
30
+ - The `GraphQLUpload` scalar no longer uses deprecated `GraphQLError` constructor parameters.
31
+
32
+ ### Patch
33
+
34
+ - Updated dev dependencies.
35
+ - Simplified dev dependencies and config for ESLint.
36
+ - Check TypeScript types via a new package `types` script.
37
+ - Removed the [`jsdoc-md`](https://npm.im/jsdoc-md) dev dependency and the related package scripts, replacing the readme “API” section with a manually written “Exports” section.
38
+ - Removed the [`hard-rejection`](https://npm.im/hard-rejection) dev dependency. Instead, tests are run with the Node.js CLI flag `--unhandled-rejections=throw` to make Node.js v14 behave like newer versions.
39
+ - Removed the [`formdata-node`](https://npm.im/formdata-node) dev dependency. Instead, `File` and `FormData` are imported from [`node-fetch`](https://npm.im/node-fetch).
40
+ - Updated GitHub Actions CI config:
41
+ - Run tests with Node.js v14, v16, v18.
42
+ - Updated `actions/checkout` to v3.
43
+ - Updated `actions/setup-node` to v3.
44
+ - Reorganized the test file structure.
45
+ - Use the `.js` file extension in `require` paths.
46
+ - Use the Node.js `Readable` property `readableEncoding` instead of `_readableState.encoding` in tests.
47
+ - Use `substring` instead of the deprecated string method `substr` in tests.
48
+ - Fixed a typo in a code comment.
49
+ - Updated documentation.
50
+ - Added a `license.md` MIT License file, closing [#86](https://github.com/jaydenseric/graphql-upload/issues/86).
51
+
52
+ ## 13.0.0
53
+
54
+ ### Major
55
+
56
+ - Updated Node.js support to `^12.22.0 || ^14.17.0 || >= 16.0.0`.
57
+ - Updated dev dependencies, some of which require newer Node.js versions than previously supported.
58
+ - Removed `./package` from the package `exports` field; the full `package.json` filename must be used in a `require` path.
59
+
60
+ ### Patch
61
+
62
+ - Updated the [`graphql`](https://npm.im/graphql) peer dependency to `0.13.1 - 16`.
63
+ - Updated dependencies.
64
+ - Also run GitHub Actions CI with Node.js v17.
65
+ - Simplified package scripts.
66
+ - Renamed imports in the test index module.
67
+ - Test the `processRequest` function with a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec) that has no files.
68
+ - Test the `processRequest` function with an unparsable multipart request.
69
+ - Replaced the [`form-data`](https://npm.im/form-data) dev dependency with [`formdata-node`](https://npm.im/formdata-node), [`formdata-node`](https://npm.im/form-data-encoder), and [`node-abort-controller`](https://npm.im/node-abort-controller) and refactored tests to align with web standards.
70
+ - Refactored the `processRequest` function to remove the [`isobject`](https://npm.im/isobject) dependency.
71
+ - Improved the `processRequest` function, via [#273](https://github.com/jaydenseric/graphql-upload/pull/273):
72
+ - Fixed ending requests from being handled incorrectly as aborting in edge cases, closing [#272](https://github.com/jaydenseric/graphql-upload/pull/272).
73
+ - Fixed read streams created via the resolved `Upload` scalar value `createReadStream` method:
74
+ - Not emitting the `error` event when the multipart request is aborted certain ways while the file is uploading.
75
+ - Emitting incorrect `error` event details for multipart request file field parse errors.
76
+ - Configured Prettier option `singleQuote` to the default, `false`.
77
+ - Documentation tweaks.
78
+
79
+ ## 12.0.0
80
+
81
+ ### Major
82
+
83
+ - Updated Node.js support to `^12.20 || >= 14.13`.
84
+ - Updated dev dependencies, some of which require newer Node.js versions than previously supported.
85
+ - The tests are now ESM in `.mjs` files instead of CJS in `.js` files.
86
+ - Replaced the the `package.json` `exports` field public [subpath folder mapping](https://nodejs.org/api/packages.html#packages_subpath_folder_mappings) (deprecated by Node.js) with a [subpath pattern](https://nodejs.org/api/packages.html#packages_subpath_patterns). Deep `require` paths must now include the `.js` file extension.
87
+
88
+ ### Minor
89
+
90
+ - Added a package `sideEffects` field.
91
+
92
+ ### Patch
93
+
94
+ - Updated dependencies.
95
+ - Lint fixes for the updated Prettier version.
96
+ - Updated GitHub Actions CI config:
97
+ - Updated the tested Node.js versions to v12, v14, v16.
98
+ - Updated `actions/checkout` to v2.
99
+ - Updated `actions/setup-node` to v2.
100
+ - Simplify config with the [`npm install-test`](https://docs.npmjs.com/cli/v7/commands/npm-install-test) command.
101
+ - Don’t specify the `CI` environment variable as it’s set by default.
102
+ - Removed `npm-debug.log` from the `.gitignore` file as npm [v4.2.0](https://github.com/npm/npm/releases/tag/v4.2.0)+ doesn’t create it in the current working directory.
103
+ - Updated the EditorConfig URL.
104
+ - Updated the package `keywords` field.
105
+ - More specific package `main` field path.
106
+ - Simplified JSDoc related package scripts now that [`jsdoc-md`](https://npm.im/jsdoc-md) v10 automatically generates a Prettier formatted readme.
107
+ - Added a package `test:jsdoc` script that checks the readme API docs are up to date with the source JSDoc.
108
+ - Refactored private constants from exports of a single module to individual modules.
109
+ - Fixed test name and comment typos.
110
+ - Updated external URLs in docs.
111
+ - Prettier format for a JSDoc code example.
112
+ - Updated a `GraphQLUpload` code example to use [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema) instead of [`graphql-tools`](https://npm.im/graphql-tools).
113
+ - Removed from the readme the notice that the package was previously published as [`apollo-upload-server`](https://npm.im/apollo-upload-server).
114
+ - Simplified the readme “Setup” and “Support” sections.
115
+
116
+ ## 11.0.0
117
+
118
+ ### Major
119
+
120
+ - Updated Node.js support to `^10.13.0 || ^12.0.0 || >= 13.7.0`.
121
+ - Added a [package `exports` field](https://nodejs.org/api/esm.html#esm_package_entry_points) with [conditional exports](https://nodejs.org/api/esm.html#esm_conditional_exports) to support native ESM in Node.js and keep internal code private, [whilst avoiding the dual package hazard](https://nodejs.org/api/esm.html#esm_approach_1_use_an_es_module_wrapper). Published files have been reorganized, so previously undocumented deep imports will need to be rewritten according to the newly documented paths.
122
+ - Updated dev dependencies, some of which require newer Node.js versions than previously supported.
123
+
124
+ ### Patch
125
+
126
+ - Updated the [`graphql`](https://npm.im/graphql) peer dependency to `0.13.1 - 15`, fixing [#200](https://github.com/jaydenseric/graphql-upload/issues/200) via [#201](https://github.com/jaydenseric/graphql-upload/pull/201).
127
+ - Updated Prettier related package scripts.
128
+ - Configured Prettier option `semi` to the default, `true`.
129
+ - Ensure GitHub Actions run on pull request.
130
+ - Also run GitHub Actions with Node.js v14.
131
+ - Fixed the `ignoreStream` function tests for Node.js v14 with a new `CountReadableStream` test helper, fixing [#209](https://github.com/jaydenseric/graphql-upload/issues/209).
132
+ - Minor JSDoc wording tweak for consistency.
133
+ - Mention [`Promise.allSettled`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) in the readme “Tips” section.
134
+ - Updated MDN Web Docs links.
135
+
136
+ ## 10.0.0
137
+
138
+ ### Major
139
+
140
+ - Updated Node.js support from v8.10+ to v10+, as earlier versions have reached end-of-life.
141
+ - Updated the [`fs-capacitor`](https://npm.im/fs-capacitor) dependency to v6, which now requires Node.js v10+, via [#179](https://github.com/jaydenseric/graphql-upload/pull/179).
142
+ - Updated dev dependencies, some of which now require Node.js v10+.
143
+ - Replaced the [`tap`](https://npm.im/tap) dev dependency with [`test-director`](https://npm.im/test-director), [`coverage-node`](https://npm.im/coverage-node), and [`hard-rejection`](https://npm.im/hard-rejection) to improve the dev experience and reduce the dev install size by ~75.7 MB. These new dev dependencies require Node.js v10+.
144
+ - Reorganized files. This is only a breaking change for projects using undocumented deep imports.
145
+ - Removed now redundant Node.js version compatibility logic in the `processRequest` function.
146
+ - The `processRequest` function now places references to instances of the now exported and documented `Upload` class in the GraphQL operation for the `GraphQLUpload` scalar to derive its value, and the `GraphQLUpload` scalar now throws a `GraphQLError` when it parses an invalid value, fixing [#175](https://github.com/jaydenseric/graphql-upload/issues/175) via [#181](https://github.com/jaydenseric/graphql-upload/pull/181).
147
+ - The `GraphQLUpload` scalar `parseLiteral` and `serialize` methods now throw `GraphQLError` (instead of `Error`) instances, with tweaked messages.
148
+
149
+ ### Minor
150
+
151
+ - The `createReadStream` function in resolved file uploads now accepts options to configure the encoding and high water mark, fixing [#177](https://github.com/jaydenseric/graphql-upload/issues/177) via [#179](https://github.com/jaydenseric/graphql-upload/pull/179).
152
+
153
+ ### Patch
154
+
155
+ - Removed the now redundant [`eslint-plugin-import-order-alphabetical`](https://npm.im/eslint-plugin-import-order-alphabetical) and [`express-async-handler`](https://npm.im/express-async-handler) dev dependencies.
156
+ - Stop using [`husky`](https://npm.im/husky) and [`lint-staged`](https://npm.im/lint-staged).
157
+ - Use [`isobject`](https://npm.im/isobject) for checking if values are enumerable, non-array objects.
158
+ - Tests have been massively reorganized, refactored, and improved.
159
+ - Test the `GraphQLUpload` scalar.
160
+ - Test the `ignoreStream` function.
161
+ - Moved the `Upload` class to its own file.
162
+ - Added JSDoc for the `Upload` class instance property `file`.
163
+ - Test the `Upload` class.
164
+ - Improved JSDoc `FileUpload` typedef description.
165
+ - Removed now redundant `eslint-disable-next-line` comments.
166
+ - Use strict mode for scripts.
167
+
168
+ ## 9.0.0
169
+
170
+ ### Major
171
+
172
+ - Updated Node.js support from v8.5+ to v8.10+, to match what the [`eslint`](https://npm.im/eslint) dev dependency now supports. This is unlikely to be a breaking change for the published package.
173
+ - Removed the `Upload` scalar promise resolved `stream` property that has been deprecated since v7, along with associated tests.
174
+ - ESM is no longer published, due to CJS/ESM compatibility issues across recent Node.js versions, via [#169](https://github.com/jaydenseric/graphql-upload/pull/169).
175
+ - The file structure and non-index file exports have changed. This should only affect projects using undocumented deep imports.
176
+
177
+ ### Minor
178
+
179
+ - Updated the [`fs-capacitor`](https://npm.im/fs-capacitor) dependency to v4 to support Node.js v13, making required changes to the source and tests, via [#166](https://github.com/jaydenseric/graphql-upload/pull/166).
180
+ - JSDoc comments are now included in the published code.
181
+ - Several anonymous functions have been named, for better error stack traces.
182
+ - Setup [GitHub Sponsors funding](https://github.com/sponsors/jaydenseric):
183
+ - Added `.github/funding.yml` to display a sponsor button in GitHub.
184
+ - Added a `package.json` `funding` field to enable npm CLI funding features.
185
+
186
+ ### Patch
187
+
188
+ - Updated dev dependencies.
189
+ - Removed the `.nycrc.json` file:
190
+ - [`tap`](https://npm.im/tap) now ignores test files by default.
191
+ - The `lib/test-helpers` directory is now ignored using [`tap`](https://npm.im/tap) CLI arguments due to [tapjs/node-tap#612](https://github.com/tapjs/node-tap/issues/612).
192
+ - Removed the `esm` and `mjs` package tags; they will be added back once native ESM is properly supported.
193
+ - Updated JSDoc code examples to use CJS instead of ESM, as native ESM is not yet properly supported.
194
+ - No longer test [`fs-capacitor`](https://npm.im/fs-capacitor) implementation details such as temp file creation and cleanup.
195
+ - Commented the reasons for several `istanbul ignore next` comments.
196
+
197
+ ## 8.1.0
198
+
199
+ ### Minor
200
+
201
+ - `processRequest` now throws an appropriate error when a multipart field value exceeds the configured size limit, fixing [#159](https://github.com/jaydenseric/graphql-upload/issues/159).
202
+ - When the file size limit is exceeded, mention how many bytes the limit is in the stream error message.
203
+ - Added a new `processRequest` option to the `graphqlUploadExpress` and `graphqlUploadKoa` middleware, for improved testing without mocks or spies which are difficult to achieve with ESM.
204
+
205
+ ### Patch
206
+
207
+ - Updated dependencies.
208
+ - Due to updated dependencies: Lint fixes, removed redundant `eslint-disable-next-line` comments, and regenerated the readme.
209
+ - Documented [`koa-graphql`](https://npm.im/koa-graphql) as known to be compatible, via [#156](https://github.com/jaydenseric/graphql-upload/pull/156).
210
+ - Fixed a readme typo, via [#161](https://github.com/jaydenseric/graphql-upload/pull/161).
211
+ - Use GitHub Actions instead of Travis for CI.
212
+ - Removed `package-lock.json` from `.gitignore` and `.prettierignore`, as it’s disabled in `.npmrc` anyway.
213
+ - New file structure.
214
+ - Explicitly defined main exports (instead of using `export * from`) to prevent accidental public exposure of internal APIs.
215
+ - Moved JSDoc typedefs into the index main entry file, alphabetically sorted.
216
+ - Nicer Browserslist query syntax.
217
+ - Replaced the `isObject` helper with a smarter and tested `isEnumerableObject`.
218
+ - Removed the `isString` helper.
219
+ - Enforced 100% code coverage for tests, and improved `processRequest` internals and tests (including a new test using vanilla Node.js HTTP), fixing [#130](https://github.com/jaydenseric/graphql-upload/issues/130) via [#162](https://github.com/jaydenseric/graphql-upload/pull/162).
220
+ - Removed a workaround from the `startServer` test helper.
221
+ - Added a new `ProcessRequestFunction` JSDoc type, and applied it to `processRequest`.
222
+ - Renamed the `UploadOptions` JSDoc type to `ProcessRequestOptions`.
223
+ - Misc. documentation improvements.
224
+
225
+ ## 8.0.7
226
+
227
+ ### Patch
228
+
229
+ - Updated dependencies.
230
+ - Handle invalid object paths in `map` multipart field entries, fixing [#154](https://github.com/jaydenseric/graphql-upload/issues/154).
231
+ - Import `WriteStream` from [`fs-capacitor`](https://npm.im/fs-capacitor) as a named rather than default import.
232
+
233
+ ## 8.0.6
234
+
235
+ ### Patch
236
+
237
+ - Updated dependencies.
238
+ - Allow batched operations again, fixing [#142](https://github.com/jaydenseric/graphql-upload/issues/142).
239
+ - Simplify tests by writing JSON as strings instead of using `JSON.stringify`.
240
+ - Use async middleware with [`express-async-handler`](https://npm.im/express-async-handler) for Express tests.
241
+ - Removed unintended `maxFiles` config in certain tests.
242
+ - Added the Open Graph image design to the logo Sketch file.
243
+
244
+ ## 8.0.5
245
+
246
+ ### Patch
247
+
248
+ - Updated dependencies.
249
+ - Handle invalid types in multipart fields and respond with meaningful HTTP 400 errors, via [#139](https://github.com/jaydenseric/graphql-upload/pull/139):
250
+ - Invalid `operations` type.
251
+ - Invalid `map` type.
252
+ - Invalid `map` entry type.
253
+ - Invalid `map` entry array item type.
254
+ - Additionally test current Node.js v8 and v10 versions with Travis.
255
+ - Reduced the size of the published `package.json` by moving dev tool config to files. This also prevents editor extensions such as Prettier and ESLint from detecting config and attempting to operate when opening package files installed in `node_modules`.
256
+ - Removed the [`watch`](https://npm.im/watch) dev dependency and `watch` script.
257
+ - Simplified the `prepublishOnly` script.
258
+ - Change to the `classic` TAP reporter for tests.
259
+ - Add [`apollo-server-koa`](https://npm.im/apollo-server-koa) and [`apollo-server-express`](https://npm.im/apollo-server-express) back to the compatible environments list in the readme, now that they use the current version of this package.
260
+
261
+ ## 8.0.4
262
+
263
+ ### Patch
264
+
265
+ - Updated the [`fs-capacitor`](https://npm.im/fs-capacitor) dependency to v2, fixing [#131](https://github.com/jaydenseric/graphql-upload/issues/131) via [#132](https://github.com/jaydenseric/graphql-upload/pull/132).
266
+
267
+ ## 8.0.3
268
+
269
+ ### Patch
270
+
271
+ - Updated dependencies. The `busboy` update contains [a bug fix for `.pipe()` on file streams](https://github.com/mscdex/busboy/issues/188).
272
+ - Use [jsDelivr](https://jsdelivr.com) for the readme logo instead of [RawGit](https://rawgit.com) as they are shutting down.
273
+
274
+ ## 8.0.2
275
+
276
+ ### Patch
277
+
278
+ - Updated dev dependencies.
279
+ - Fixed hanging when a request with a large payload has an “immediate” error, such as a malformed request, fixing [#123](https://github.com/jaydenseric/graphql-upload/issues/123) via [#124](https://github.com/jaydenseric/graphql-upload/pull/124).
280
+ - Moved JSDoc type definitions to the end of files to make it easier to open to the code.
281
+
282
+ ## 8.0.1
283
+
284
+ ### Patch
285
+
286
+ - Updated dev dependencies.
287
+ - Removed the package `module` field. Webpack by default resolves extensionless paths the same way Node.js in `--experimental-modules` mode does; `.mjs` files are preferred. Tools misconfigured or unable to resolve `.mjs` can get confused when `module` points to an `.mjs` ESM file and they attempt to resolve named imports from `.js` CJS files.
288
+ - Updated package scripts and config for the new [`husky`](https://npm.im/husky) version.
289
+ - Added a package `browserslist` field with the target Node.js version for [`@babel/preset-env`](https://npm.im/@babel/preset-env) and removed related config from `babel.config.js`.
290
+ - Tests now log if the environment is CJS or ESM (`--experimental-modules`) and the `NODE_ENV`.
291
+ - Fixed broken readme API documentation links.
292
+
293
+ ## 8.0.0
294
+
295
+ ### Major
296
+
297
+ - New naming that drops “apollo” to reflect the independent and universal nature of the project, fixing [#68](https://github.com/jaydenseric/apollo-upload-server/issues/68):
298
+
299
+ - Changed the package name from [`apollo-upload-server`](https://npm.im/apollo-upload-server) to [`graphql-upload`](https://npm.im/graphql-upload).
300
+ - Renamed `apolloUploadKoa` to `graphqlUploadKoa`.
301
+ - Renamed `apolloUploadExpress` to `graphqlUploadExpress`.
302
+
303
+ To migrate you project from `apollo-upload-server@7.1.0` to `graphql-upload@8.0.0`:
304
+
305
+ 1. Run `npm uninstall apollo-upload-server`.
306
+ 2. Run `npm install graphql-upload`.
307
+ 3. Find and replace:
308
+ - `apolloUploadKoa` → `graphqlUploadKoa`.
309
+ - `apolloUploadExpress` → `graphqlUploadExpress`.
310
+
311
+ ### Patch
312
+
313
+ - Updated dependencies.
314
+ - New project logo.
315
+
316
+ ## 7.1.0
317
+
318
+ ### Minor
319
+
320
+ - Support [`graphql`](https://npm.im/graphql) v14.
321
+
322
+ ### Patch
323
+
324
+ - Updated dev dependencies.
325
+
326
+ ## 7.0.0
327
+
328
+ ### Major
329
+
330
+ - The `processRequest` function now requires a [`http.ServerResponse`](https://nodejs.org/api/http.html#http_class_http_serverresponse) instance as its second argument.
331
+ - Replaced the previously exported error classes with [`http-errors`](https://npm.im/http-errors) and snapshot tested error details, via [#105](https://github.com/jaydenseric/apollo-upload-server/pull/105).
332
+ - No longer exporting the `SPEC_URL` constant.
333
+
334
+ ### Minor
335
+
336
+ - `Upload` scalar promises now resolve with a `createReadStream` method instead of a `stream` property, via [#92](https://github.com/jaydenseric/apollo-upload-server/pull/92).
337
+ - Accessing an `Upload` scalar promise resolved `stream` property results in a deprecation warning that recommends using `createReadStream` instead. It will be removed in a future release. Via [#107](https://github.com/jaydenseric/apollo-upload-server/pull/107).
338
+ - An `Upload` scalar variable can now be used by multiple resolvers, via [#92](https://github.com/jaydenseric/apollo-upload-server/pull/92).
339
+ - Multiple `Upload` scalar variables can now use the same multipart data, via [#92](https://github.com/jaydenseric/apollo-upload-server/pull/92).
340
+ - Malformed requests containing invalid JSON for `operations` or `map` multipart fields cause an appropriate error with a `400` status instead of crashing the process, relating to [#81](https://github.com/jaydenseric/apollo-upload-server/pull/81) and [#95](https://github.com/jaydenseric/apollo-upload-server/issues/95).
341
+ - Malformed requests missing `operations`, `map` and files, or just `map` and files, cause an appropriate error with a `400` status instead of hanging, fixing [#96](https://github.com/jaydenseric/apollo-upload-server/issues/96).
342
+ - Tweaked `GraphQLUpload` scalar description to remove details about how it resolves on the server as they are irrelevant to API users.
343
+ - Tweaked `GraphQLUpload` scalar error messages.
344
+
345
+ ### Patch
346
+
347
+ - Updated dev dependencies.
348
+ - Removed the [`npm-run-all`](https://npm.im/npm-run-all) dev dependency and made scripts and tests sync for easier debugging, at the cost of slightly longer build times.
349
+ - Explicitly set `processRequest` default options instead of relying on [`busboy`](https://npm.im/busboy) defaults.
350
+ - Better organized project file structure.
351
+ - Configured Prettier to lint `.yml` files.
352
+ - Ensure the readme Travis build status badge only tracks `master` branch.
353
+
354
+ ## 6.0.0-alpha.1
355
+
356
+ Big thanks to new collaborator [@mike-marcacci](https://github.com/mike-marcacci) for his help solving tricky bugs and edge-cases!
357
+
358
+ ### Major
359
+
360
+ - Updated Node.js support from v6.10+ to v8.5+ for [native ESM](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V8.md#8.5.0), [object rest/spread properties](https://node.green#ES2018-features-object-rest-spread-properties), and [async functions](https://node.green#ES2017-features-async-functions).
361
+ - Removed the [`@babel/runtime`](https://npm.im/@babel/runtime) dependency and config.
362
+ - Fixed [#45](https://github.com/jaydenseric/apollo-upload-server/issues/45), [#77](https://github.com/jaydenseric/apollo-upload-server/issues/77) and [#83](https://github.com/jaydenseric/apollo-upload-server/issues/83) via [#81](https://github.com/jaydenseric/apollo-upload-server/pull/81):
363
+ - Add `error` event listeners to file streams to prevent server crashes on aborted requests or parser errors.
364
+ - Use [`fs-capacitor`](https://npm.im/fs-capacitor) to ensure the server doesn’t hang if an upload `await` is out of order, or is never consumed.
365
+
366
+ ### Minor
367
+
368
+ - Refactored package scripts to use `prepare` to support installation via Git (e.g. `npm install jaydenseric/apollo-upload-server`).
369
+
370
+ ### Patch
371
+
372
+ - Updated dependencies.
373
+ - Use single instead of double typographic quotes in error messages.
374
+ - Use `babel.config.js` instead of `.babelrc.js`.
375
+ - Enabled `shippedProposals` in [`@babel/preset-env`](https://npm.im/@babel/preset-env) config.
376
+ - Improved testing:
377
+ - Use [`tap`](https://npm.im/tap) instead of [`ava`](https://npm.im/ava). Tests no longer transpile on the fly, are faster and AVA no longer dictates the Babel version.
378
+ - Tests run against the actual dist `.mjs` and `.js` files in native ESM (`--experimental-modules`) and CJS environments.
379
+ - Removed `get-port` dev dependency.
380
+ - Added Express tests.
381
+ - Test middleware error response status codes.
382
+ - Test behavior of aborted HTTP requests.
383
+ - Test that the app can respond if an upload is not handled.
384
+ - Test files to upload are created in context, rather than using arbitrary project files, via [#89](https://github.com/jaydenseric/apollo-upload-server/pull/89).
385
+ - Improved `package.json` scripts:
386
+ - Leveraged `npm-run-all` more for parallelism and reduced noise.
387
+ - Removed the clean script `rimraf` dev dependency in favour of native `rm -rf`. Leaner and faster; we only support \*nix now for contributing anyway.
388
+ - No longer use `cross-env`; contributors with Windows may setup and use a Bash shell.
389
+ - Renamed the `ESM` environment variable to `BABEL_ESM` to be more specific.
390
+ - Removed linting fix scripts.
391
+ - Linting included in the test script; Travis CI will fail PR's with lint errors.
392
+ - Custom watch script.
393
+ - Improved ESLint config:
394
+ - Simplified ESLint config with [`eslint-config-env`](https://npm.im/eslint-config-env).
395
+ - Removed redundant [`eslint-plugin-ava`](https://npm.im/eslint-plugin-ava) dev dependency and config.
396
+ - Undo overriding ESLint ignoring dotfiles by default as there are none now.
397
+ - Use `.prettierignore` to leave `package.json` formatting to npm.
398
+ - Tweaked package `description` and `keywords`.
399
+ - Compact package `repository` field.
400
+ - Improved documentation.
401
+ - Readme badge changes to deal with [shields.io](https://shields.io) unreliability:
402
+ - Use the official Travis build status badge.
403
+ - Use [Badgen](https://badgen.net) for the npm version badge.
404
+ - Removed the licence badge. The licence can be found in `package.json` and rarely changes.
405
+ - Removed the Github issues and stars badges. The readme is most viewed on Github anyway.
406
+ - Changelog version entries now have “Major”, “Minor” and “Patch” subheadings.
407
+
408
+ ## 5.0.0
409
+
410
+ ### Major
411
+
412
+ - [`graphql`](https://npm.im/graphql) peer dependency range updated to `^0.13.1` for native ESM support via `.mjs`. It’s a breaking change despite being a semver patch.
413
+
414
+ ### Patch
415
+
416
+ - Updated dependencies.
417
+ - More robust npm scripts, with the ability to watch builds and tests together.
418
+ - Fixed missing dev dependency for fetching in tests.
419
+ - Use [`eslint-plugin-ava`](https://github.com/avajs/eslint-plugin-ava).
420
+ - HTTPS `package.json` author URL.
421
+ - New readme logo URL that doesn’t need to be updated every version.
422
+
423
+ ## 4.0.2
424
+
425
+ ### Patch
426
+
427
+ - Temporary solution for importing CommonJS in `.mjs`, fixing reopened [#40](https://github.com/jaydenseric/apollo-upload-server/issues/40).
428
+
429
+ ## 4.0.1
430
+
431
+ ### Patch
432
+
433
+ - Correct imports for vanilla Node.js `--experimental-modules` and `.mjs` support, fixing [#40](https://github.com/jaydenseric/apollo-upload-server/issues/40).
434
+
435
+ ## 4.0.0
436
+
437
+ ### Patch
438
+
439
+ - Updated dependencies.
440
+ - Simplified npm scripts.
441
+ - Readme updates:
442
+ - Documented [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) types, via [#39](https://github.com/jaydenseric/apollo-upload-server/pull/39).
443
+ - Explained how to use `processRequest` for custom middleware.
444
+ - Improved usage instructions.
445
+ - Display oldest supported Node.js version.
446
+ - Misc. tweaks including a simpler heading structure.
447
+
448
+ ## 4.0.0-alpha.3
449
+
450
+ ### Minor
451
+
452
+ - Updated peer dependencies to support `graphql@0.12`, via [#36](https://github.com/jaydenseric/apollo-upload-server/pull/36).
453
+
454
+ ### Patch
455
+
456
+ - Updated dependencies.
457
+
458
+ ## 4.0.0-alpha.2
459
+
460
+ ### Minor
461
+
462
+ - Transpile and polyfill for Node.js v6.10+ (down from v7.6+) to [support AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html), fixing [#33](https://github.com/jaydenseric/apollo-upload-server/issues/33).
463
+ - Modular project structure that works better for native ESM.
464
+ - Added tests.
465
+ - Set up Travis to test using the latest stable Node.js version and the oldest supported in `package.json` `engines` (v6.10).
466
+ - Added a Travis readme badge.
467
+ - Improved error handling, fixing [#26](https://github.com/jaydenseric/apollo-upload-server/issues/26):
468
+ - Custom errors are thrown or emitted with meaningful messages that are exported so consumers can use `instanceof` with them.
469
+ - Where it makes sense, errors cause relevant HTTP status codes to be set in middleware.
470
+ - [Misordered multipart fields](https://github.com/jaydenseric/graphql-multipart-request-spec) cause `processRequest` to throw `MapBeforeOperationsUploadError` and `FilesBeforeMapUploadError` errors in middleware.
471
+ - The `map` field provided by the client is used to naively check the `maxFiles` option is not exceeded for a speedy `MaxFilesUploadError` error in middleware. The real number of files parsed is checked too, incase the request is malformed.
472
+ - If files are missing from the request the `scalar Upload` promises reject with a `FileMissingUploadError` error.
473
+ - Already if a file exceeds the `maxFileSize` option the file is truncated, the stream emits a `limit` event and `stream.truncated === true`. Now an `error` event is also emitted with a `MaxFileSizeUploadError`.
474
+ - Aborting requests from the client causes `scalar Upload` promises to reject with a `UploadPromiseDisconnectUploadError` error for file upload streams that have not yet been parsed. For streams being parsed an `error` event is emitted with an `FileStreamDisconnectUploadError` error and `stream.truncated === true`. It is up to consumers to cleanup aborted streams in their resolvers.
475
+
476
+ ### Patch
477
+
478
+ - Updated dependencies.
479
+ - Smarter Babel config with `.babelrc.js`.
480
+ - Refactor to use fewer Busboy event listeners.
481
+
482
+ ## 4.0.0-alpha.1
483
+
484
+ ### Major
485
+
486
+ - New API to support the [GraphQL multipart request spec v2.0.0-alpha.2](https://github.com/jaydenseric/graphql-multipart-request-spec/releases/tag/v2.0.0-alpha.2). Files no longer upload to the filesystem; [readable streams](https://nodejs.org/api/stream.html#stream_readable_streams) are used in resolvers instead. Fixes [#13](https://github.com/jaydenseric/apollo-upload-server/issues/13) via [#22](https://github.com/jaydenseric/apollo-upload-server/pull/22).
487
+ - Export a new `Upload` scalar type to use in place of the old `Upload` input type. It represents a file upload promise that resolves an object containing `stream`, `filename`, `mimetype` and `encoding`.
488
+ - Deprecated the `uploadDir` middleware option.
489
+ - `graphql` is now a peer dependency.
490
+
491
+ ### Minor
492
+
493
+ - Added new `maxFieldSize`, `maxFileSize` and `maxFiles` middleware options.
494
+
495
+ ### Patch
496
+
497
+ - Middleware are now arrow functions.
498
+
499
+ ## 3.0.0
500
+
501
+ ### Major
502
+
503
+ - Updated Node.js support from v6.4+ to v7.6+.
504
+ - Express middleware now passes on errors instead of blocking, via [#20](https://github.com/jaydenseric/apollo-upload-server/pull/20).
505
+
506
+ ### Patch
507
+
508
+ - Using Babel directly, dropping Rollup.
509
+ - New directory structure for compiled files.
510
+ - Module files now have `.mjs` extension.
511
+ - No longer publish the `src` directory.
512
+ - No more sourcemaps.
513
+ - Use an arrow function for the Koa middleware, to match the Express middleware.
514
+ - Compiled code is now prettier.
515
+ - Prettier markdown files.
516
+ - Updated package keywords.
517
+ - Updated an Apollo documentation link in the changelog.
518
+ - Readme improvements:
519
+ - Added links to badges.
520
+ - Removed the inspiration links; they are less relevant to the evolved codebase.
521
+ - Fixed an Apollo link.
522
+ - Replaced example resolver code with a link to the [Apollo upload examples](https://github.com/jaydenseric/apollo-upload-examples).
523
+
524
+ ## 2.0.4
525
+
526
+ ### Patch
527
+
528
+ - Updated dependencies.
529
+ - Readme tweaks including a new license badge.
530
+
531
+ ## 2.0.3
532
+
533
+ ### Patch
534
+
535
+ - Updated dependencies.
536
+ - Removed `package-lock.json`. Lockfiles are [not recommended](https://github.com/sindresorhus/ama/issues/479#issuecomment-310661514) for packages.
537
+ - Moved Babel config out of `package.json` to prevent issues when consumers run Babel over `node_modules`.
538
+ - Readme tweaks and fixes:
539
+ - Renamed the `File` input type `Upload` for clarity.
540
+ - Wording and formatting improvements.
541
+ - Covered React Native.
542
+ - Documented custom middleware.
543
+
544
+ ## 2.0.2
545
+
546
+ ### Patch
547
+
548
+ - Updated dependencies.
549
+ - Added a changelog.
550
+ - Dropped Yarn in favor of npm@5. Removed `yarn.lock` and updated install instructions.
551
+ - Set targeted Node version as a string for `babel-preset-env`.
552
+ - New ESLint config. Dropped [Standard Style](https://standardjs.com) and began using [Prettier](https://github.com/prettier/eslint-plugin-prettier).
553
+ - Using [lint-staged](https://github.com/okonet/lint-staged) to ensure contributors don't commit lint errors.
554
+ - Removed `build:watch` script. Use `npm run build -- --watch` directly.
555
+
556
+ ## 2.0.1
557
+
558
+ ### Patch
559
+
560
+ - Updated dependencies.
561
+ - Support regular requests from clients other than apollo-upload-client again, fixing [#4](https://github.com/jaydenseric/apollo-upload-server/issues/4).
562
+ - Removed incorrect commas from example GraphQL input type.
563
+
564
+ ## 2.0.0
565
+
566
+ ### Major
567
+
568
+ - Support `apollo-upload-client` v3 and [query batching](https://apollographql.com/docs/apollo-server/requests#batching).
569
+
570
+ ### Patch
571
+
572
+ - Clearer package description.
573
+ - Use [Standard Style](https://standardjs.com) instead of ESLint directly.
574
+
575
+ ## 1.1.0
576
+
577
+ ### Minor
578
+
579
+ - Exporting a new helper function for processing requests. It can be used to create custom middleware, or middleware for unsupported routers.
580
+ - Exporting new Koa middleware.
581
+ - Upload directory is ensured on every request now. While slightly less efficient, it prevents major errors when if it is deleted while the server is running.
582
+
583
+ ### Patch
584
+
585
+ - Updated dependencies.
586
+ - Documented npm install as well as Yarn.
587
+ - Typo fix in the readme.
588
+
589
+ ## 1.0.2
590
+
591
+ ### Patch
592
+
593
+ - Fixed broken Github deep links in the readme.
594
+ - Readme rewording.
595
+ - Simplified `package.json` description.
596
+
597
+ ## 1.0.1
598
+
599
+ ### Patch
600
+
601
+ - Added missing metadata to `package.json`.
602
+ - Added a link to apollographql/graphql-server in the readme.
603
+
604
+ ## 1.0.0
605
+
606
+ Initial release.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-upload",
3
- "version": "14.0.0",
3
+ "version": "15.0.0",
4
4
  "description": "Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -61,10 +61,10 @@
61
61
  }
62
62
  },
63
63
  "dependencies": {
64
- "@types/busboy": "^0.3.2",
64
+ "@types/busboy": "^1.5.0",
65
65
  "@types/node": "*",
66
66
  "@types/object-path": "^0.11.1",
67
- "busboy": "^0.3.1",
67
+ "busboy": "^1.6.0",
68
68
  "fs-capacitor": "^6.2.0",
69
69
  "http-errors": "^2.0.0",
70
70
  "object-path": "^0.11.8"
@@ -83,7 +83,7 @@
83
83
  "node-fetch": "^3.2.3",
84
84
  "prettier": "^2.6.2",
85
85
  "test-director": "^8.0.2",
86
- "typescript": "^4.7.1-rc"
86
+ "typescript": "^4.7.2"
87
87
  },
88
88
  "scripts": {
89
89
  "eslint": "eslint .",
package/processRequest.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  "use strict";
4
4
 
5
- const Busboy = require("busboy");
5
+ const busboy = require("busboy");
6
6
  const { WriteStream } = require("fs-capacitor");
7
7
  const createError = require("http-errors");
8
8
  const objectPath = require("object-path");
@@ -42,9 +42,6 @@ function processRequest(
42
42
  /** @type {Error} */
43
43
  let exitError;
44
44
 
45
- /** @type {import("stream").Readable} */
46
- let lastFileStream;
47
-
48
45
  /**
49
46
  * @type {{ [key: string]: unknown } | Array<
50
47
  * { [key: string]: unknown }
@@ -62,7 +59,7 @@ function processRequest(
62
59
  /** @type {Map<string, Upload>} */
63
60
  let map;
64
61
 
65
- const parser = new Busboy({
62
+ const parser = busboy({
66
63
  // @ts-ignore This is about to change with `busboy` v1 types.
67
64
  headers: request.headers,
68
65
  limits: {
@@ -76,31 +73,20 @@ function processRequest(
76
73
  /**
77
74
  * Exits request processing with an error. Successive calls have no effect.
78
75
  * @param {Error} error Error instance.
76
+ * @param {boolean} [isParserError] Is the error from the parser.
79
77
  */
80
- const exit = (error) => {
81
- // None of the tested scenarios cause multiple calls of this function, but
82
- // it’s still good to guard against it happening in case it’s possible now
83
- // or in the future.
84
- // coverage ignore next line
78
+ function exit(error, isParserError = false) {
85
79
  if (exitError) return;
86
80
 
87
81
  exitError = error;
88
82
 
89
- reject(exitError);
90
-
91
- parser.destroy();
92
-
93
- if (
94
- lastFileStream &&
95
- !lastFileStream.readableEnded &&
96
- !lastFileStream.destroyed
97
- )
98
- lastFileStream.destroy(exitError);
99
-
100
83
  if (map)
101
84
  for (const upload of map.values())
102
85
  if (!upload.file) upload.reject(exitError);
103
86
 
87
+ // If the error came from the parser, don’t cause it to be emitted again.
88
+ isParserError ? parser.destroy() : parser.destroy(exitError);
89
+
104
90
  request.unpipe(parser);
105
91
 
106
92
  // With a sufficiently large request body, subsequent events in the same
@@ -110,197 +96,197 @@ function processRequest(
110
96
  setImmediate(() => {
111
97
  request.resume();
112
98
  });
113
- };
114
99
 
115
- parser.on(
116
- "field",
117
- (fieldName, value, fieldNameTruncated, valueTruncated) => {
118
- if (valueTruncated)
119
- return exit(
120
- createError(
121
- 413,
122
- `The ‘${fieldName}’ multipart field value exceeds the ${maxFieldSize} byte size limit.`
123
- )
124
- );
125
-
126
- switch (fieldName) {
127
- case "operations":
128
- try {
129
- operations = JSON.parse(value);
130
- } catch (error) {
131
- return exit(
132
- createError(
133
- 400,
134
- `Invalid JSON in the ‘operations’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
135
- )
136
- );
137
- }
138
-
139
- // `operations` should be an object or an array. Note that arrays
140
- // and `null` have an `object` type.
141
- if (typeof operations !== "object" || !operations)
142
- return exit(
143
- createError(
144
- 400,
145
- `Invalid type for the ‘operations’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
146
- )
147
- );
100
+ reject(exitError);
101
+ }
148
102
 
149
- operationsPath = objectPath(operations);
103
+ parser.on("field", (fieldName, value, { valueTruncated }) => {
104
+ if (valueTruncated)
105
+ return exit(
106
+ createError(
107
+ 413,
108
+ `The ‘${fieldName}’ multipart field value exceeds the ${maxFieldSize} byte size limit.`
109
+ )
110
+ );
150
111
 
151
- break;
152
- case "map": {
153
- if (!operations)
154
- return exit(
155
- createError(
156
- 400,
157
- `Misordered multipart fields; ‘map’ should follow ‘operations’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
158
- )
159
- );
112
+ switch (fieldName) {
113
+ case "operations":
114
+ try {
115
+ operations = JSON.parse(value);
116
+ } catch (error) {
117
+ return exit(
118
+ createError(
119
+ 400,
120
+ `Invalid JSON in the ‘operations’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
121
+ )
122
+ );
123
+ }
160
124
 
161
- let parsedMap;
162
- try {
163
- parsedMap = JSON.parse(value);
164
- } catch (error) {
165
- return exit(
166
- createError(
167
- 400,
168
- `Invalid JSON in the ‘map’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
169
- )
170
- );
171
- }
125
+ // `operations` should be an object or an array. Note that arrays
126
+ // and `null` have an `object` type.
127
+ if (typeof operations !== "object" || !operations)
128
+ return exit(
129
+ createError(
130
+ 400,
131
+ `Invalid type for the ‘operations’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
132
+ )
133
+ );
134
+
135
+ operationsPath = objectPath(operations);
136
+
137
+ break;
138
+ case "map": {
139
+ if (!operations)
140
+ return exit(
141
+ createError(
142
+ 400,
143
+ `Misordered multipart fields; ‘map’ should follow ‘operations’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
144
+ )
145
+ );
146
+
147
+ let parsedMap;
148
+ try {
149
+ parsedMap = JSON.parse(value);
150
+ } catch (error) {
151
+ return exit(
152
+ createError(
153
+ 400,
154
+ `Invalid JSON in the ‘map’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
155
+ )
156
+ );
157
+ }
172
158
 
173
- // `map` should be an object.
174
- if (
175
- typeof parsedMap !== "object" ||
176
- !parsedMap ||
177
- Array.isArray(parsedMap)
178
- )
159
+ // `map` should be an object.
160
+ if (
161
+ typeof parsedMap !== "object" ||
162
+ !parsedMap ||
163
+ Array.isArray(parsedMap)
164
+ )
165
+ return exit(
166
+ createError(
167
+ 400,
168
+ `Invalid type for the ‘map’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
169
+ )
170
+ );
171
+
172
+ const mapEntries = Object.entries(parsedMap);
173
+
174
+ // Check max files is not exceeded, even though the number of files
175
+ // to parse might not match the map provided by the client.
176
+ if (mapEntries.length > maxFiles)
177
+ return exit(
178
+ createError(413, `${maxFiles} max file uploads exceeded.`)
179
+ );
180
+
181
+ map = new Map();
182
+ for (const [fieldName, paths] of mapEntries) {
183
+ if (!Array.isArray(paths))
179
184
  return exit(
180
185
  createError(
181
186
  400,
182
- `Invalid type for the ‘map’ multipart field (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
187
+ `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
183
188
  )
184
189
  );
185
190
 
186
- const mapEntries = Object.entries(parsedMap);
187
-
188
- // Check max files is not exceeded, even though the number of files
189
- // to parse might not match the map provided by the client.
190
- if (mapEntries.length > maxFiles)
191
- return exit(
192
- createError(413, `${maxFiles} max file uploads exceeded.`)
193
- );
191
+ map.set(fieldName, new Upload());
194
192
 
195
- map = new Map();
196
- for (const [fieldName, paths] of mapEntries) {
197
- if (!Array.isArray(paths))
193
+ for (const [index, path] of paths.entries()) {
194
+ if (typeof path !== "string")
198
195
  return exit(
199
196
  createError(
200
197
  400,
201
- `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
198
+ `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
202
199
  )
203
200
  );
204
201
 
205
- map.set(fieldName, new Upload());
206
-
207
- for (const [index, path] of paths.entries()) {
208
- if (typeof path !== "string")
209
- return exit(
210
- createError(
211
- 400,
212
- `Invalid type for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
213
- )
214
- );
215
-
216
- try {
217
- operationsPath.set(path, map.get(fieldName));
218
- } catch (error) {
219
- return exit(
220
- createError(
221
- 400,
222
- `Invalid object path for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value ‘${path}’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
223
- )
224
- );
225
- }
202
+ try {
203
+ operationsPath.set(path, map.get(fieldName));
204
+ } catch (error) {
205
+ return exit(
206
+ createError(
207
+ 400,
208
+ `Invalid object path for the ‘map’ multipart field entry key ‘${fieldName}’ array index ‘${index}’ value ‘${path}’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
209
+ )
210
+ );
226
211
  }
227
212
  }
228
-
229
- resolve(operations);
230
213
  }
231
- }
232
- }
233
- );
234
-
235
- parser.on("file", (fieldName, stream, filename, encoding, mimetype) => {
236
- lastFileStream = stream;
237
-
238
- if (!map) {
239
- ignoreStream(stream);
240
- return exit(
241
- createError(
242
- 400,
243
- `Misordered multipart fields; files should follow ‘map’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
244
- )
245
- );
246
- }
247
-
248
- const upload = map.get(fieldName);
249
214
 
250
- if (!upload) {
251
- // The file is extraneous. As the rest can still be processed, just
252
- // ignore it and don’t exit with an error.
253
- ignoreStream(stream);
254
- return;
215
+ resolve(operations);
216
+ }
255
217
  }
218
+ });
256
219
 
257
- /** @type {Error} */
258
- let fileError;
220
+ parser.on(
221
+ "file",
222
+ (fieldName, stream, { filename, encoding, mimeType: mimetype }) => {
223
+ if (!map) {
224
+ ignoreStream(stream);
225
+ return exit(
226
+ createError(
227
+ 400,
228
+ `Misordered multipart fields; files should follow ‘map’ (${GRAPHQL_MULTIPART_REQUEST_SPEC_URL}).`
229
+ )
230
+ );
231
+ }
259
232
 
260
- const capacitor = new WriteStream();
233
+ const upload = map.get(fieldName);
261
234
 
262
- capacitor.on("error", () => {
263
- stream.unpipe();
264
- stream.resume();
265
- });
235
+ if (!upload) {
236
+ // The file is extraneous. As the rest can still be processed, just
237
+ // ignore it and don’t exit with an error.
238
+ ignoreStream(stream);
239
+ return;
240
+ }
266
241
 
267
- stream.on("limit", () => {
268
- fileError = createError(
269
- 413,
270
- `File truncated as it exceeds the ${maxFileSize} byte size limit.`
271
- );
272
- stream.unpipe();
273
- capacitor.destroy(fileError);
274
- });
242
+ /** @type {Error} */
243
+ let fileError;
275
244
 
276
- stream.on("error", (error) => {
277
- fileError = error;
278
- stream.unpipe();
279
- capacitor.destroy(fileError);
280
- });
245
+ const capacitor = new WriteStream();
281
246
 
282
- /** @type {FileUpload} */
283
- const file = {
284
- filename,
285
- mimetype,
286
- encoding,
287
- createReadStream(options) {
288
- const error = fileError || (released ? exitError : null);
289
- if (error) throw error;
290
- return capacitor.createReadStream(options);
291
- },
292
- capacitor,
293
- };
294
-
295
- Object.defineProperty(file, "capacitor", {
296
- enumerable: false,
297
- configurable: false,
298
- writable: false,
299
- });
247
+ capacitor.on("error", () => {
248
+ stream.unpipe();
249
+ stream.resume();
250
+ });
300
251
 
301
- stream.pipe(capacitor);
302
- upload.resolve(file);
303
- });
252
+ stream.on("limit", () => {
253
+ fileError = createError(
254
+ 413,
255
+ `File truncated as it exceeds the ${maxFileSize} byte size limit.`
256
+ );
257
+ stream.unpipe();
258
+ capacitor.destroy(fileError);
259
+ });
260
+
261
+ stream.on("error", (error) => {
262
+ fileError = error;
263
+ stream.unpipe();
264
+ capacitor.destroy(fileError);
265
+ });
266
+
267
+ /** @type {FileUpload} */
268
+ const file = {
269
+ filename,
270
+ mimetype,
271
+ encoding,
272
+ createReadStream(options) {
273
+ const error = fileError || (released ? exitError : null);
274
+ if (error) throw error;
275
+ return capacitor.createReadStream(options);
276
+ },
277
+ capacitor,
278
+ };
279
+
280
+ Object.defineProperty(file, "capacitor", {
281
+ enumerable: false,
282
+ configurable: false,
283
+ writable: false,
284
+ });
285
+
286
+ stream.pipe(capacitor);
287
+ upload.resolve(file);
288
+ }
289
+ );
304
290
 
305
291
  parser.once("filesLimit", () =>
306
292
  exit(createError(413, `${maxFiles} max file uploads exceeded.`))
@@ -331,7 +317,13 @@ function processRequest(
331
317
  upload.reject(createError(400, "File missing in the request."));
332
318
  });
333
319
 
334
- parser.once("error", exit);
320
+ // Use the `on` method instead of `once` as in edge cases the same parser
321
+ // could have multiple `error` events and all must be handled to prevent the
322
+ // Node.js process exiting with an error. One edge case is if there is a
323
+ // malformed part header as well as an unexpected end of the form.
324
+ parser.on("error", (/** @type {Error} */ error) => {
325
+ exit(error, true);
326
+ });
335
327
 
336
328
  response.once("close", () => {
337
329
  released = true;