Socket
Socket
Sign inDemoInstall

@fastify/multipart

Package Overview
Dependencies
Maintainers
20
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/multipart - npm Package Compare versions

Comparing version 7.2.0 to 7.3.0

test/named-import.test-d.ts

239

index.d.ts
import { Busboy, BusboyConfig, BusboyFileStream } from "@fastify/busboy";
import { FastifyPluginCallback } from "fastify";
import { Readable } from 'stream';
import { Readable } from "stream";
import { FastifyErrorConstructor } from "@fastify/error";
type MultipartHandler = (
field: string,
file: BusboyFileStream,
filename: string,
encoding: string,
mimetype: string,
) => void;
declare module "fastify" {
interface FastifyRequest {
isMultipart: () => boolean;
interface BodyEntry {
data: Buffer,
filename: string,
encoding: string,
mimetype: string,
limit: false
}
// promise api
parts: (
options?: Omit<BusboyConfig, "headers">
) => AsyncIterableIterator<fastifyMultipart.Multipart>;
export interface MultipartFields {
[fieldname: string]: Multipart | Multipart[] | undefined;
// legacy
multipart: (
handler: MultipartHandler,
next: (err: Error) => void,
options?: Omit<BusboyConfig, "headers">
) => Busboy;
// Stream mode
file: (
options?: Omit<BusboyConfig, "headers">
) => Promise<fastifyMultipart.MultipartFile | undefined>;
files: (
options?: Omit<BusboyConfig, "headers">
) => AsyncIterableIterator<fastifyMultipart.MultipartFile>;
// Disk mode
saveRequestFiles: (
options?: Omit<BusboyConfig, "headers"> & { tmpdir?: string }
) => Promise<Array<fastifyMultipart.SavedMultipartFile>>;
cleanRequestFiles: () => Promise<void>;
tmpUploads: Array<string> | null;
}
interface FastifyInstance {
multipartErrors: MultipartErrors;
}
}
export type Multipart = MultipartFile | MultipartValue;
type FastifyMultipartPlugin = FastifyPluginCallback<
| fastifyMultipart.FastifyMultipartBaseOptions
| fastifyMultipart.FastifyMultipartOptions
| fastifyMultipart.FastifyMultipartAttachFieldsToBodyOptions
>;
export interface MultipartFile {
toBuffer: () => Promise<Buffer>,
type MultipartHandler = (
field: string,
file: BusboyFileStream,
fieldname: string,
filename: string,
encoding: string,
mimetype: string,
fields: MultipartFields
}
mimetype: string
) => void;
export interface SavedMultipartFile extends MultipartFile {
/**
* Path to the temporary file
*/
filepath: string,
}
export interface MultipartValue<T = unknown> {
value: T;
fieldname: string;
interface BodyEntry {
data: Buffer;
filename: string;
encoding: string;
mimetype: string;
encoding: string;
fieldnameTruncated: boolean;
valueTruncated: boolean;
fields: MultipartFields;
limit: false;
}
interface MultipartErrors {
PartsLimitError: FastifyErrorConstructor,
FilesLimitError: FastifyErrorConstructor,
FieldsLimitError: FastifyErrorConstructor,
PrototypeViolationError: FastifyErrorConstructor,
InvalidMultipartContentTypeError: FastifyErrorConstructor,
RequestFileTooLargeError: FastifyErrorConstructor
PartsLimitError: FastifyErrorConstructor;
FilesLimitError: FastifyErrorConstructor;
FieldsLimitError: FastifyErrorConstructor;
PrototypeViolationError: FastifyErrorConstructor;
InvalidMultipartContentTypeError: FastifyErrorConstructor;
RequestFileTooLargeError: FastifyErrorConstructor;
}
declare module "fastify" {
interface FastifyRequest {
isMultipart: () => boolean;
declare namespace fastifyMultipart {
export interface SavedMultipartFile extends MultipartFile {
/**
* Path to the temporary file
*/
filepath: string;
}
// promise api
parts: (options?: Omit<BusboyConfig, 'headers'>) => AsyncIterableIterator<Multipart>
export type Multipart = MultipartFile | MultipartValue;
// legacy
multipart: (handler: MultipartHandler, next: (err: Error) => void, options?: Omit<BusboyConfig, 'headers'>) => Busboy;
export interface MultipartFile {
toBuffer: () => Promise<Buffer>;
file: BusboyFileStream;
fieldname: string;
filename: string;
encoding: string;
mimetype: string;
fields: MultipartFields;
}
// Stream mode
file: (options?: Omit<BusboyConfig, 'headers'>) => Promise<MultipartFile | undefined>
files: (options?: Omit<BusboyConfig, 'headers'>) => AsyncIterableIterator<MultipartFile>
export interface MultipartValue<T = unknown> {
value: T;
fieldname: string;
mimetype: string;
encoding: string;
fieldnameTruncated: boolean;
valueTruncated: boolean;
fields: MultipartFields;
}
// Disk mode
saveRequestFiles: (options?: Omit<BusboyConfig, 'headers'> & { tmpdir?: string }) => Promise<Array<SavedMultipartFile>>
cleanRequestFiles: () => Promise<void>
tmpUploads: Array<string> | null
}
export interface MultipartFields {
[fieldname: string]: Multipart | Multipart[] | undefined;
}
interface FastifyInstance {
multipartErrors: MultipartErrors
}
}
export interface FastifyMultipartBaseOptions {
export interface FastifyMultipartBaseOptions {
/**

@@ -103,3 +122,3 @@ * Append the multipart parameters to the body object

*/
throwFileSizeLimit?: boolean
throwFileSizeLimit?: boolean;

@@ -115,42 +134,46 @@ /**

*/
isPartAFile?: (fieldName: string | undefined, contentType: string | undefined, fileName: string | undefined) => boolean;
isPartAFile?: (
fieldName: string | undefined,
contentType: string | undefined,
fileName: string | undefined
) => boolean;
limits?: {
/**
* Max field name size in bytes
*/
fieldNameSize?: number;
/**
* Max field name size in bytes
*/
fieldNameSize?: number;
/**
* Max field value size in bytes
*/
fieldSize?: number;
/**
* Max field value size in bytes
*/
fieldSize?: number;
/**
* Max number of non-file fields
*/
fields?: number;
/**
* Max number of non-file fields
*/
fields?: number;
/**
* For multipart forms, the max file size
*/
fileSize?: number;
/**
* For multipart forms, the max file size
*/
fileSize?: number;
/**
* Max number of file fields
*/
files?: number;
/**
* Max number of file fields
*/
files?: number;
/**
* Max number of header key=>value pairs
*/
headerPairs?: number;
}
}
/**
* Max number of header key=>value pairs
*/
headerPairs?: number;
};
}
export interface FastifyMultipartOptions extends FastifyMultipartBaseOptions {
export interface FastifyMultipartOptions extends FastifyMultipartBaseOptions {
/**
* Only valid in the promise api. Append the multipart parameters to the body object.
*/
attachFieldsToBody?: false
attachFieldsToBody?: false;

@@ -160,10 +183,18 @@ /**

*/
onFile?: (fieldName: string, stream: Readable, filename: string, encoding: string, mimetype: string, body: Record<string, BodyEntry>) => void | Promise<void>;
}
onFile?: (
fieldName: string,
stream: Readable,
filename: string,
encoding: string,
mimetype: string,
body: Record<string, BodyEntry>
) => void | Promise<void>;
}
export interface FastifyMultipartAttactFieldsToBodyOptions extends FastifyMultipartBaseOptions {
export interface FastifyMultipartAttachFieldsToBodyOptions
extends FastifyMultipartBaseOptions {
/**
* Only valid in the promise api. Append the multipart parameters to the body object.
*/
attachFieldsToBody: true | 'keyValues';
attachFieldsToBody: true | "keyValues";

@@ -174,5 +205,11 @@ /**

onFile?: (part: MultipartFile) => void | Promise<void>;
}
export const fastifyMultipart: FastifyMultipartPlugin;
export { fastifyMultipart as default };
}
declare function fastifyMultipart(
...params: Parameters<FastifyMultipartPlugin>
): ReturnType<FastifyMultipartPlugin>;
declare const fastifyMultipart: FastifyPluginCallback<FastifyMultipartOptions | FastifyMultipartAttactFieldsToBodyOptions>;
export default fastifyMultipart;
export = fastifyMultipart;

@@ -578,5 +578,13 @@ 'use strict'

module.exports = fp(fastifyMultipart, {
const _fastifyMultipart = fp(fastifyMultipart, {
fastify: '4.x',
name: '@fastify/multipart'
})
/**
* These export configurations enable JS and TS developers
* to consumer fastify in whatever way best suits their needs.
*/
module.exports = _fastifyMultipart
module.exports.fastifyMultipart = _fastifyMultipart
module.exports.default = _fastifyMultipart
{
"name": "@fastify/multipart",
"version": "7.2.0",
"version": "7.3.0",
"description": "Multipart plugin for Fastify",

@@ -25,3 +25,3 @@ "main": "index.js",

"eslint": "^8.20.0",
"eslint-config-standard-with-typescript": "^22.0.0",
"eslint-config-standard-with-typescript": "^23.0.0",
"eslint-plugin-import": "^2.26.0",

@@ -39,14 +39,4 @@ "eslint-plugin-n": "^15.2.4",

"tap": "^16.0.0",
"tsd": "^0.23.0"
"tsd": "^0.24.1"
},
"scripts": {
"coverage": "tap \"test/**/*.test.js\" --coverage-report=html",
"climem": "climem 8999 localhost",
"lint": "standard | snazzy",
"lint:fix": "standard --fix",
"start": "CLIMEM=8999 node -r climem ./examples/example",
"test": "npm run lint && npm run unit && npm run typescript",
"typescript": "tsd",
"unit": "tap \"test/**/*.test.js\" -t 90"
},
"repository": {

@@ -68,3 +58,13 @@ "type": "git",

"access": "public"
},
"scripts": {
"coverage": "tap \"test/**/*.test.js\" --coverage-report=html",
"climem": "climem 8999 localhost",
"lint": "standard | snazzy",
"lint:fix": "standard --fix",
"start": "CLIMEM=8999 node -r climem ./examples/example",
"test": "npm run lint && npm run unit && npm run typescript",
"typescript": "tsd",
"unit": "tap \"test/**/*.test.js\" -t 90"
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc