@fastify/multipart
Advanced tools
Comparing version 8.3.0 to 9.0.0-pre.fv5.1
17
index.js
@@ -10,8 +10,7 @@ 'use strict' | ||
const { generateId } = require('./lib/generateId') | ||
const util = require('node:util') | ||
const createError = require('@fastify/error') | ||
const sendToWormhole = require('stream-wormhole') | ||
const streamToNull = require('./lib/stream-consumer') | ||
const deepmergeAll = require('@fastify/deepmerge')({ all: true }) | ||
const { PassThrough, pipeline, Readable } = require('node:stream') | ||
const pump = util.promisify(pipeline) | ||
const { PassThrough, Readable } = require('node:stream') | ||
const { pipeline: pump } = require('node:stream/promises') | ||
const secureJSON = require('secure-json-parse') | ||
@@ -100,3 +99,2 @@ | ||
/* Don't modify the body if a field doesn't have a value or an attached buffer */ | ||
/* istanbul ignore else */ | ||
if (field.value !== undefined) { | ||
@@ -148,2 +146,3 @@ body[key] = field.value | ||
async function append (key, entry) { | ||
/* c8 ignore next: Buffer.isBuffer is not covered and causing `npm test` to fail */ | ||
if (entry.type === 'file' || (attachFieldsToBody === 'keyValues' && Buffer.isBuffer(entry))) { | ||
@@ -169,2 +168,3 @@ // TODO use File constructor with fs.openAsBlob() | ||
fastify.decorateRequest('formData', async function () { | ||
/* c8 ignore next: Next line is not covered and causing `npm test` to fail */ | ||
throw new NoFormData() | ||
@@ -356,3 +356,3 @@ }) | ||
// ensure that stream is consumed, any error is suppressed | ||
sendToWormhole(file) | ||
streamToNull(file).catch(() => {}) | ||
onError(new PrototypeViolationError()) | ||
@@ -509,6 +509,6 @@ return | ||
await unlink(filepath) | ||
} catch (error) { | ||
/* istanbul ignore next */ | ||
} /* c8 ignore start */ catch (error) { | ||
this.log.error(error, 'Could not delete file') | ||
} | ||
/* c8 ignore stop */ | ||
} | ||
@@ -522,3 +522,2 @@ } | ||
/* Only return a part if the file property exists */ | ||
/* istanbul ignore else */ | ||
if (part.file) { | ||
@@ -525,0 +524,0 @@ return part |
{ | ||
"name": "@fastify/multipart", | ||
"version": "8.3.0", | ||
"version": "9.0.0-pre.fv5.1", | ||
"description": "Multipart plugin for Fastify", | ||
@@ -9,14 +9,13 @@ "main": "index.js", | ||
"dependencies": { | ||
"@fastify/busboy": "^2.1.0", | ||
"@fastify/deepmerge": "^1.0.0", | ||
"@fastify/error": "^3.0.0", | ||
"fastify-plugin": "^4.0.0", | ||
"secure-json-parse": "^2.4.0", | ||
"stream-wormhole": "^1.1.0" | ||
"@fastify/busboy": "^3.0.0", | ||
"@fastify/deepmerge": "^2.0.0", | ||
"@fastify/error": "^4.0.0", | ||
"fastify-plugin": "^5.0.0-pre.fv5.1", | ||
"secure-json-parse": "^2.7.0" | ||
}, | ||
"devDependencies": { | ||
"@fastify/pre-commit": "^2.0.2", | ||
"@fastify/swagger": "^8.10.1", | ||
"@fastify/swagger-ui": "^3.0.0", | ||
"@types/node": "^20.1.0", | ||
"@fastify/pre-commit": "^2.1.0", | ||
"@fastify/swagger": "^9.0.0-pre.fv5.1", | ||
"@fastify/swagger-ui": "^5.0.0-pre.fv5.1", | ||
"@types/node": "^20.11.6", | ||
"@typescript-eslint/eslint-plugin": "^7.1.0", | ||
@@ -27,4 +26,7 @@ "@typescript-eslint/parser": "^7.1.0", | ||
"concat-stream": "^2.0.0", | ||
"eslint": "^8.20.0", | ||
"fastify": "^4.0.0", | ||
"eslint": "^8.56.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-n": "^16.6.2", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"fastify": "^5.0.0-alpha.3", | ||
"form-data": "^4.0.0", | ||
@@ -34,6 +36,6 @@ "h2url": "^0.2.0", | ||
"pump": "^3.0.0", | ||
"readable-stream": "^4.5.1", | ||
"readable-stream": "^4.5.2", | ||
"snazzy": "^9.0.0", | ||
"standard": "^17.0.0", | ||
"tap": "^16.0.0", | ||
"standard": "^17.1.0", | ||
"tap": "^18.6.1", | ||
"tsd": "^0.31.0" | ||
@@ -51,3 +53,3 @@ }, | ||
"test:typescript": "tsd", | ||
"test:unit": "tap -t 90" | ||
"test:unit": "tap -t 120" | ||
}, | ||
@@ -54,0 +56,0 @@ "repository": { |
@@ -12,3 +12,3 @@ 'use strict' | ||
const crypto = require('node:crypto') | ||
const sendToWormhole = require('stream-wormhole') | ||
const streamToNull = require('../lib/stream-consumer') | ||
@@ -42,3 +42,3 @@ // skipping on Github Actions because it takes too long | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
} | ||
@@ -83,6 +83,7 @@ } | ||
const addresses = fastify.addresses() | ||
const opts = { | ||
protocol: 'http:', | ||
hostname: 'localhost', | ||
port: fastify.server.address().port, | ||
hostname: addresses[0].address, | ||
port: addresses[0].port, | ||
path: '/', | ||
@@ -89,0 +90,0 @@ headers: form.getHeaders(), |
@@ -10,3 +10,3 @@ 'use strict' | ||
const { Readable } = require('readable-stream') | ||
const sendToWormhole = require('stream-wormhole') | ||
const streamToNull = require('../lib/stream-consumer') | ||
const EventEmitter = require('node:events') | ||
@@ -27,3 +27,3 @@ const { once } = EventEmitter | ||
const part = await req.file({ limits: { fileSize: 16500 } }) | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
if (part.file.truncated) { | ||
@@ -30,0 +30,0 @@ reply.code(500).send() |
@@ -10,3 +10,3 @@ 'use strict' | ||
const fs = require('node:fs') | ||
const sendToWormhole = require('stream-wormhole') | ||
const streamToNull = require('../lib/stream-consumer') | ||
@@ -25,3 +25,3 @@ const filePath = path.join(__dirname, '../README.md') | ||
t.ok(part.file) | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
} | ||
@@ -28,0 +28,0 @@ reply.code(200).send() |
@@ -11,3 +11,3 @@ 'use strict' | ||
const EventEmitter = require('node:events') | ||
const sendToWormhole = require('stream-wormhole') | ||
const streamToNull = require('../lib/stream-consumer') | ||
const { once } = EventEmitter | ||
@@ -30,3 +30,3 @@ | ||
const part = await req.file({ limits: { fileSize: 2 } }) | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
@@ -76,3 +76,3 @@ reply.code(200).send() | ||
const part = await req.file({ limits: { fileSize: 2 }, throwFileSizeLimit: false }) | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
@@ -79,0 +79,0 @@ reply.code(200).send() |
@@ -15,3 +15,3 @@ 'use strict' | ||
const pump = util.promisify(stream.pipeline) | ||
const sendToWormhole = require('stream-wormhole') | ||
const streamToNull = require('../lib/stream-consumer') | ||
@@ -93,3 +93,3 @@ const filePath = path.join(__dirname, '../README.md') | ||
t.equal(part.type, 'file') | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
} | ||
@@ -146,3 +146,3 @@ reply.code(200).send() | ||
if (part.file) { | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
} | ||
@@ -276,3 +276,3 @@ } | ||
t.ok(part.file, 'part received') | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
} | ||
@@ -337,3 +337,3 @@ reply.code(200).send() | ||
t.equal(part.type, 'file') | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
} | ||
@@ -493,3 +493,3 @@ reply.code(200).send() | ||
t.equal(part.type, 'file') | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
} | ||
@@ -541,3 +541,3 @@ reply.code(200).send() | ||
t.equal(part.type, 'file') | ||
await sendToWormhole(part.file) | ||
await streamToNull(part.file) | ||
} | ||
@@ -645,3 +645,3 @@ reply.code(200).send() | ||
test('should not freeze when error is thrown during processing', { skip: process.versions.node.startsWith('14') }, async function (t) { | ||
test('should not freeze when error is thrown during processing', async function (t) { | ||
t.plan(2) | ||
@@ -700,48 +700,1 @@ const app = Fastify() | ||
}) | ||
const hasGlobalFormData = typeof globalThis.FormData === 'function' | ||
test('no formData', { skip: !hasGlobalFormData }, function (t) { | ||
t.plan(6) | ||
const fastify = Fastify() | ||
t.teardown(fastify.close.bind(fastify)) | ||
fastify.register(multipart) | ||
fastify.post('/', async function (req, reply) { | ||
await t.rejects(req.formData()) | ||
for await (const part of req.parts()) { | ||
t.equal(part.type, 'field') | ||
t.equal(part.fieldname, 'hello') | ||
t.equal(part.value, 'world') | ||
} | ||
reply.code(200).send() | ||
}) | ||
fastify.listen({ port: 0 }, async function () { | ||
// request | ||
const form = new FormData() | ||
const opts = { | ||
protocol: 'http:', | ||
hostname: 'localhost', | ||
port: fastify.server.address().port, | ||
path: '/', | ||
headers: form.getHeaders(), | ||
method: 'POST' | ||
} | ||
const req = http.request(opts, (res) => { | ||
t.equal(res.statusCode, 200) | ||
// consume all data without processing | ||
res.resume() | ||
res.on('end', () => { | ||
t.pass('res ended successfully') | ||
}) | ||
}) | ||
form.append('hello', 'world') | ||
form.pipe(req) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
157146
5
44
4508
0
23
2
+ Added@fastify/busboy@3.0.0(transitive)
+ Added@fastify/deepmerge@2.0.0(transitive)
+ Added@fastify/error@4.0.0(transitive)
+ Addedfastify-plugin@5.0.1(transitive)
- Removedstream-wormhole@^1.1.0
- Removed@fastify/busboy@2.1.1(transitive)
- Removed@fastify/deepmerge@1.3.0(transitive)
- Removed@fastify/error@3.4.1(transitive)
- Removedfastify-plugin@4.5.1(transitive)
- Removedstream-wormhole@1.1.0(transitive)
Updated@fastify/busboy@^3.0.0
Updated@fastify/deepmerge@^2.0.0
Updated@fastify/error@^4.0.0
Updatedsecure-json-parse@^2.7.0