🤖 Merge PR #57922 [busboy] Update to version 1.3 by @martin-badin

* [busboy] Update to version 1.3

* update async-busboy package

* update connect-busboy package

* update express-upload package

* update koa-joi-router package

* update multy package

Co-authored-by: Roland Reed <roland-reed@users.noreply.github.com>
This commit is contained in:
martin-badin
2022-01-06 18:12:27 +01:00
committed by GitHub
parent 889c25a62a
commit a585d5fd2c
14 changed files with 745 additions and 292 deletions

View File

@@ -8,7 +8,7 @@ type Result = asyncBusboy.Result;
type OnFileResult = asyncBusboy.OnFileResult;
type FileReadStream = asyncBusboy.FileReadStream;
const req = null as any as IncomingMessage;
declare const req: IncomingMessage;
const resultPromise = asyncBusboy(req); // $ExpectType Promise<Result>
asyncBusboy(req, {}); // $ExpectType Promise<Result>

View File

@@ -12,6 +12,11 @@
"typeRoots": [
"../"
],
"paths": {
"busboy": [
"busboy/v0"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true

View File

@@ -1,261 +1,222 @@
import Busboy = require('busboy');
import busboy = require('busboy');
// test type exports
type Constructor = Busboy.BusboyConstructor;
type Config = Busboy.BusboyConfig;
type Headers = Busboy.BusboyHeaders;
type BB = Busboy.Busboy;
type Events = Busboy.BusboyEvents;
new Busboy({}); // $ExpectError
const busboy = Busboy({ headers: { 'content-type': 'foo' } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, highWaterMark: 1000 }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, fileHwm: 1000 }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, defCharset: 'utf8' }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, preservePath: true }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { fieldNameSize: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { fieldSize: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { fields: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { fileSize: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { files: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { parts: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { headerPairs: 200 } }); // $ExpectType Busboy
busboy.addListener('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
// $ExpectType Busboy
const bb = busboy({
headers: { 'content-type': 'foo' },
highWaterMark: 1000,
fileHwm: 1000,
defCharset: 'utf8',
preservePath: true,
limits: {
fieldNameSize: 200,
fieldSize: 200,
fields: 200,
fileSize: 200,
files: 200,
parts: 200,
headerPairs: 200,
},
});
busboy.addListener('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.addListener('file', (name, stream, info) => {
name; // $ExpectType string
stream; // $ExpectType Readable
info; // $ExpectType FileInfo
});
busboy.addListener('partsLimit', () => {});
busboy.addListener('partsLimit', foo => {}); // $ExpectError
busboy.addListener('filesLimit', () => {});
busboy.addListener('filesLimit', foo => {}); // $ExpectError
busboy.addListener('fieldsLimit', () => {});
busboy.addListener('fieldsLimit', foo => {}); // $ExpectError
busboy.addListener('error', e => {
bb.addListener('field', (name, value, info) => {
name; // $ExpectType string
value; // $ExpectType string
info; // $ExpectType FieldInfo
});
bb.addListener('partsLimit', () => {});
bb.addListener('partsLimit', foo => {}); // $ExpectError
bb.addListener('filesLimit', () => {});
bb.addListener('filesLimit', foo => {}); // $ExpectError
bb.addListener('fieldsLimit', () => {});
bb.addListener('fieldsLimit', foo => {}); // $ExpectError
bb.addListener('error', e => {
e; // $ExpectType unknown
});
busboy.addListener('finish', () => {});
busboy.addListener('finish', foo => {}); // $ExpectError
bb.addListener('close', () => {});
bb.addListener('close', foo => {}); // $ExpectError
// test fallback
busboy.on('foo', foo => {
bb.on('foo', foo => {
foo; // $ExpectType any
});
busboy.on(Symbol('foo'), foo => {
bb.on(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.on('file', (name, stream, info) => {
name; // $ExpectType string
stream; // $ExpectType Readable
info; // $ExpectType FileInfo
});
busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.on('field', (name, value, info) => {
name; // $ExpectType string
value; // $ExpectType string
info; // $ExpectType FieldInfo
});
busboy.on('partsLimit', () => {});
busboy.on('partsLimit', foo => {}); // $ExpectError
busboy.on('filesLimit', () => {});
busboy.on('filesLimit', foo => {}); // $ExpectError
busboy.on('fieldsLimit', () => {});
busboy.on('fieldsLimit', foo => {}); // $ExpectError
busboy.on('error', e => {
bb.on('partsLimit', () => {});
bb.on('partsLimit', foo => {}); // $ExpectError
bb.on('filesLimit', () => {});
bb.on('filesLimit', foo => {}); // $ExpectError
bb.on('fieldsLimit', () => {});
bb.on('fieldsLimit', foo => {}); // $ExpectError
bb.on('error', e => {
e; // $ExpectType unknown
});
busboy.on('finish', () => {});
busboy.on('finish', foo => {}); // $ExpectError
bb.on('close', () => {});
bb.on('close', foo => {}); // $ExpectError
// test fallback
busboy.on('foo', foo => {
bb.on('foo', foo => {
foo; // $ExpectType any
});
busboy.on(Symbol('foo'), foo => {
bb.on(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.once('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.once('file', (name, stream, info) => {
name; // $ExpectType string
stream; // $ExpectType Readable
info; // $ExpectType FileInfo
});
busboy.once('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.once('field', (name, value, info) => {
name; // $ExpectType string
value; // $ExpectType string
info; // $ExpectType FieldInfo
});
busboy.once('partsLimit', () => {});
busboy.once('partsLimit', foo => {}); // $ExpectError
busboy.once('filesLimit', () => {});
busboy.once('filesLimit', foo => {}); // $ExpectError
busboy.once('fieldsLimit', () => {});
busboy.once('fieldsLimit', foo => {}); // $ExpectError
busboy.once('error', e => {
bb.once('partsLimit', () => {});
bb.once('partsLimit', foo => {}); // $ExpectError
bb.once('filesLimit', () => {});
bb.once('filesLimit', foo => {}); // $ExpectError
bb.once('fieldsLimit', () => {});
bb.once('fieldsLimit', foo => {}); // $ExpectError
bb.once('error', e => {
e; // $ExpectType unknown
});
busboy.once('finish', () => {});
busboy.once('finish', foo => {}); // $ExpectError
bb.once('close', () => {});
bb.once('close', foo => {}); // $ExpectError
// test fallback
busboy.once('foo', foo => {
bb.once('foo', foo => {
foo; // $ExpectType any
});
busboy.once(Symbol('foo'), foo => {
bb.once(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.removeListener('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.removeListener('file', (name, stream, info) => {
name; // $ExpectType string
stream; // $ExpectType Readable
info; // $ExpectType FileInfo
});
busboy.removeListener('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.removeListener('field', (name, value, info) => {
name; // $ExpectType string
value; // $ExpectType string
info; // $ExpectType FieldInfo
});
busboy.removeListener('partsLimit', () => {});
busboy.removeListener('partsLimit', foo => {}); // $ExpectError
busboy.removeListener('filesLimit', () => {});
busboy.removeListener('filesLimit', foo => {}); // $ExpectError
busboy.removeListener('fieldsLimit', () => {});
busboy.removeListener('fieldsLimit', foo => {}); // $ExpectError
busboy.removeListener('error', e => {
bb.removeListener('partsLimit', () => {});
bb.removeListener('partsLimit', foo => {}); // $ExpectError
bb.removeListener('filesLimit', () => {});
bb.removeListener('filesLimit', foo => {}); // $ExpectError
bb.removeListener('fieldsLimit', () => {});
bb.removeListener('fieldsLimit', foo => {}); // $ExpectError
bb.removeListener('error', e => {
e; // $ExpectType unknown
});
busboy.removeListener('finish', () => {});
busboy.removeListener('finish', foo => {}); // $ExpectError
bb.removeListener('close', () => {});
bb.removeListener('close', foo => {}); // $ExpectError
// test fallback
busboy.removeListener('foo', foo => {
bb.removeListener('foo', foo => {
foo; // $ExpectType any
});
busboy.removeListener(Symbol('foo'), foo => {
bb.removeListener(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.off('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.off('file', (name, stream, info) => {
name; // $ExpectType string
stream; // $ExpectType Readable
info; // $ExpectType FileInfo
});
busboy.off('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.off('field', (name, value, info) => {
name; // $ExpectType string
value; // $ExpectType string
info; // $ExpectType FieldInfo
});
busboy.off('partsLimit', () => {});
busboy.off('partsLimit', foo => {}); // $ExpectError
busboy.off('filesLimit', () => {});
busboy.off('filesLimit', foo => {}); // $ExpectError
busboy.off('fieldsLimit', () => {});
busboy.off('fieldsLimit', foo => {}); // $ExpectError
busboy.off('error', e => {
bb.off('partsLimit', () => {});
bb.off('partsLimit', foo => {}); // $ExpectError
bb.off('filesLimit', () => {});
bb.off('filesLimit', foo => {}); // $ExpectError
bb.off('fieldsLimit', () => {});
bb.off('fieldsLimit', foo => {}); // $ExpectError
bb.off('error', e => {
e; // $ExpectType unknown
});
busboy.off('finish', () => {});
busboy.off('finish', foo => {}); // $ExpectError
bb.off('close', () => {});
bb.off('close', foo => {}); // $ExpectError
// test fallback
busboy.off('foo', foo => {
bb.off('foo', foo => {
foo; // $ExpectType any
});
busboy.off(Symbol('foo'), foo => {
bb.off(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.prependListener('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.prependListener('file', (name, stream, info) => {
name; // $ExpectType string
stream; // $ExpectType Readable
info; // $ExpectType FileInfo
});
busboy.prependListener('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.prependListener('field', (name, value, info) => {
name; // $ExpectType string
value; // $ExpectType string
info; // $ExpectType FieldInfo
});
busboy.prependListener('partsLimit', () => {});
busboy.prependListener('partsLimit', foo => {}); // $ExpectError
busboy.prependListener('filesLimit', () => {});
busboy.prependListener('filesLimit', foo => {}); // $ExpectError
busboy.prependListener('fieldsLimit', () => {});
busboy.prependListener('fieldsLimit', foo => {}); // $ExpectError
busboy.prependListener('error', e => {
bb.prependListener('partsLimit', () => {});
bb.prependListener('partsLimit', foo => {}); // $ExpectError
bb.prependListener('filesLimit', () => {});
bb.prependListener('filesLimit', foo => {}); // $ExpectError
bb.prependListener('fieldsLimit', () => {});
bb.prependListener('fieldsLimit', foo => {}); // $ExpectError
bb.prependListener('error', e => {
e; // $ExpectType unknown
});
busboy.prependListener('finish', () => {});
busboy.prependListener('finish', foo => {}); // $ExpectError
bb.prependListener('close', () => {});
bb.prependListener('close', foo => {}); // $ExpectError
// test fallback
busboy.prependListener('foo', foo => {
bb.prependListener('foo', foo => {
foo; // $ExpectType any
});
busboy.prependListener(Symbol('foo'), foo => {
bb.prependListener(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.prependOnceListener('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.prependOnceListener('file', (name, stream, info) => {
name; // $ExpectType string
stream; // $ExpectType Readable
info; // $ExpectType FileInfo
});
busboy.prependOnceListener('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
bb.prependOnceListener('field', (name, value, info) => {
name; // $ExpectType string
value; // $ExpectType string
info; // $ExpectType FieldInfo
});
busboy.prependOnceListener('partsLimit', () => {});
busboy.prependOnceListener('partsLimit', foo => {}); // $ExpectError
busboy.prependOnceListener('filesLimit', () => {});
busboy.prependOnceListener('filesLimit', foo => {}); // $ExpectError
busboy.prependOnceListener('fieldsLimit', () => {});
busboy.prependOnceListener('fieldsLimit', foo => {}); // $ExpectError
busboy.prependOnceListener('error', e => {
bb.prependOnceListener('partsLimit', () => {});
bb.prependOnceListener('partsLimit', foo => {}); // $ExpectError
bb.prependOnceListener('filesLimit', () => {});
bb.prependOnceListener('filesLimit', foo => {}); // $ExpectError
bb.prependOnceListener('fieldsLimit', () => {});
bb.prependOnceListener('fieldsLimit', foo => {}); // $ExpectError
bb.prependOnceListener('error', e => {
e; // $ExpectType unknown
});
busboy.prependOnceListener('finish', () => {});
busboy.prependOnceListener('finish', foo => {}); // $ExpectError
bb.prependOnceListener('close', () => {});
bb.prependOnceListener('close', foo => {}); // $ExpectError
// test fallback
busboy.prependOnceListener('foo', foo => {
bb.prependOnceListener('foo', foo => {
foo; // $ExpectType any
});
busboy.prependOnceListener(Symbol('foo'), foo => {
bb.prependOnceListener(Symbol('foo'), foo => {
foo; // $ExpectType any
});

View File

@@ -1,90 +1,107 @@
// Type definitions for busboy 0.3
// Project: https://www.npmjs.com/package/busboy
// Type definitions for busboy 1.3
// Project: https://github.com/mscdex/busboy
// Definitions by: Jacob Baskin <https://github.com/jacobbaskin>
// BendingBender <https://github.com/BendingBender>
// Martin Badin <https://github.com/martin-badin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import * as http from 'http';
import { IncomingHttpHeaders } from 'http';
import { Readable, Writable } from 'stream';
export = busboy;
declare const busboy: busboy.BusboyConstructor;
declare namespace busboy {
interface Limits {
/**
* Max field name size (in bytes).
*
* @default 100
*/
fieldNameSize?: number | undefined;
/**
* Max field value size (in bytes).
*
* @default 1048576 (1MB)
*/
fieldSize?: number | undefined;
/**
* Max number of non-file fields.
*
* @default Infinity
*/
fields?: number | undefined;
/**
* For multipart forms, the max file size (in bytes).
*
* @default Infinity
*/
fileSize?: number | undefined;
/**
* For multipart forms, the max number of file fields.
*
* @default Infinity
*/
files?: number | undefined;
/**
* For multipart forms, the max number of parts (fields + files).
*
* @default Infinity
*/
parts?: number | undefined;
/**
* For multipart forms, the max number of header key-value pairs to parse.
*
* @default 2000 (same as node's http module)
*/
headerPairs?: number | undefined;
}
interface BusboyConfig {
/**
* These are the HTTP headers of the incoming request, which are used by individual parsers.
*/
headers: BusboyHeaders;
headers?: IncomingHttpHeaders | undefined;
/**
* `highWaterMark` to use for this Busboy instance.
* @default WritableStream default.
* 'highWaterMark' to use for the parser stream
*
* @default stream.Writable
*/
highWaterMark?: number | undefined;
/**
* highWaterMark to use for file streams.
* @default ReadableStream default.
* 'highWaterMark' to use for individual file streams
*
* @default stream.Readable
*/
fileHwm?: number | undefined;
/**
* Default character set to use when one isn't defined.
*
* @default 'utf8'
*/
defCharset?: string | undefined;
/**
* If paths in the multipart 'filename' field shall be preserved.
* If paths in filenames from file parts in a 'multipart/form-data' request shall be preserved.
*
* @default false
*/
preservePath?: boolean | undefined;
/**
* Various limits on incoming data.
*/
limits?:
| {
/**
* Max field name size (in bytes)
* @default 100 bytes
*/
fieldNameSize?: number | undefined;
/**
* Max field value size (in bytes)
* @default 1MB
*/
fieldSize?: number | undefined;
/**
* Max number of non-file fields
* @default Infinity
*/
fields?: number | undefined;
/**
* For multipart forms, the max file size (in bytes)
* @default Infinity
*/
fileSize?: number | undefined;
/**
* For multipart forms, the max number of file fields
* @default Infinity
*/
files?: number | undefined;
/**
* For multipart forms, the max number of parts (fields + files)
* @default Infinity
*/
parts?: number | undefined;
/**
* For multipart forms, the max number of header key=>value pairs to parse
* @default 2000 (same as node's http)
*/
headerPairs?: number | undefined;
}
| undefined;
limits?: Limits | undefined;
}
type BusboyHeaders = { 'content-type': string } & http.IncomingHttpHeaders;
interface Busboy extends Writable {
addListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
@@ -108,6 +125,20 @@ declare namespace busboy {
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
}
interface Info {
encoding: string;
mimeType: string;
}
interface FileInfo extends Info {
filename: string;
}
interface FieldInfo extends Info {
nameTruncated: boolean;
valueTruncated: boolean;
}
interface BusboyEvents {
/**
* Emitted for each new file form field found.
@@ -123,42 +154,45 @@ declare namespace busboy {
* @param listener.transferEncoding Contains the 'Content-Transfer-Encoding' value for the file stream.
* @param listener.mimeType Contains the 'Content-Type' value for the file stream.
*/
file: (
fieldname: string,
stream: Readable,
filename: string,
transferEncoding: string,
mimeType: string,
) => void;
file: (name: string, stream: Readable, info: FileInfo) => void;
/**
* Emitted for each new non-file field found.
*/
field: (
fieldname: string,
value: string,
fieldnameTruncated: boolean,
valueTruncated: boolean,
transferEncoding: string,
mimeType: string,
) => void;
finish: () => void;
field: (name: string, value: string, info: FieldInfo) => void;
/**
* Emitted when specified `parts` limit has been reached. No more 'file' or 'field' events will be emitted.
*/
partsLimit: () => void;
/**
* Emitted when specified `files` limit has been reached. No more 'file' events will be emitted.
* Emitted when specified `files` limit has been reached. No more 'file' events will be emitted.
*/
filesLimit: () => void;
/**
* Emitted when specified `fields` limit has been reached. No more 'field' events will be emitted.
*/
fieldsLimit: () => void;
error: (error: unknown) => void;
}
interface BusboyConstructor {
(options: BusboyConfig): Busboy;
new (options: BusboyConfig): Busboy;
error: (error: unknown) => void;
/**
* @deprecated
* @since 1.0
*/
finish: () => void;
/**
* Use 'close' event instead of 'finish' event when you need to execute
*
* @since 1.0
*/
close: () => void;
}
}
declare function busboy(config: busboy.BusboyConfig): busboy.Busboy;
export = busboy;

View File

@@ -1,3 +1 @@
{
"extends": "@definitelytyped/dtslint/dt.json"
}
{ "extends": "@definitelytyped/dtslint/dt.json" }

View File

@@ -0,0 +1,261 @@
import Busboy = require('busboy');
// test type exports
type Constructor = Busboy.BusboyConstructor;
type Config = Busboy.BusboyConfig;
type Headers = Busboy.BusboyHeaders;
type BB = Busboy.Busboy;
type Events = Busboy.BusboyEvents;
new Busboy({}); // $ExpectError
const busboy = Busboy({ headers: { 'content-type': 'foo' } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, highWaterMark: 1000 }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, fileHwm: 1000 }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, defCharset: 'utf8' }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, preservePath: true }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { fieldNameSize: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { fieldSize: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { fields: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { fileSize: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { files: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { parts: 200 } }); // $ExpectType Busboy
new Busboy({ headers: { 'content-type': 'foo' }, limits: { headerPairs: 200 } }); // $ExpectType Busboy
busboy.addListener('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.addListener('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.addListener('partsLimit', () => {});
busboy.addListener('partsLimit', foo => {}); // $ExpectError
busboy.addListener('filesLimit', () => {});
busboy.addListener('filesLimit', foo => {}); // $ExpectError
busboy.addListener('fieldsLimit', () => {});
busboy.addListener('fieldsLimit', foo => {}); // $ExpectError
busboy.addListener('error', e => {
e; // $ExpectType unknown
});
busboy.addListener('finish', () => {});
busboy.addListener('finish', foo => {}); // $ExpectError
// test fallback
busboy.on('foo', foo => {
foo; // $ExpectType any
});
busboy.on(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.on('partsLimit', () => {});
busboy.on('partsLimit', foo => {}); // $ExpectError
busboy.on('filesLimit', () => {});
busboy.on('filesLimit', foo => {}); // $ExpectError
busboy.on('fieldsLimit', () => {});
busboy.on('fieldsLimit', foo => {}); // $ExpectError
busboy.on('error', e => {
e; // $ExpectType unknown
});
busboy.on('finish', () => {});
busboy.on('finish', foo => {}); // $ExpectError
// test fallback
busboy.on('foo', foo => {
foo; // $ExpectType any
});
busboy.on(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.once('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.once('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.once('partsLimit', () => {});
busboy.once('partsLimit', foo => {}); // $ExpectError
busboy.once('filesLimit', () => {});
busboy.once('filesLimit', foo => {}); // $ExpectError
busboy.once('fieldsLimit', () => {});
busboy.once('fieldsLimit', foo => {}); // $ExpectError
busboy.once('error', e => {
e; // $ExpectType unknown
});
busboy.once('finish', () => {});
busboy.once('finish', foo => {}); // $ExpectError
// test fallback
busboy.once('foo', foo => {
foo; // $ExpectType any
});
busboy.once(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.removeListener('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.removeListener('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.removeListener('partsLimit', () => {});
busboy.removeListener('partsLimit', foo => {}); // $ExpectError
busboy.removeListener('filesLimit', () => {});
busboy.removeListener('filesLimit', foo => {}); // $ExpectError
busboy.removeListener('fieldsLimit', () => {});
busboy.removeListener('fieldsLimit', foo => {}); // $ExpectError
busboy.removeListener('error', e => {
e; // $ExpectType unknown
});
busboy.removeListener('finish', () => {});
busboy.removeListener('finish', foo => {}); // $ExpectError
// test fallback
busboy.removeListener('foo', foo => {
foo; // $ExpectType any
});
busboy.removeListener(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.off('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.off('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.off('partsLimit', () => {});
busboy.off('partsLimit', foo => {}); // $ExpectError
busboy.off('filesLimit', () => {});
busboy.off('filesLimit', foo => {}); // $ExpectError
busboy.off('fieldsLimit', () => {});
busboy.off('fieldsLimit', foo => {}); // $ExpectError
busboy.off('error', e => {
e; // $ExpectType unknown
});
busboy.off('finish', () => {});
busboy.off('finish', foo => {}); // $ExpectError
// test fallback
busboy.off('foo', foo => {
foo; // $ExpectType any
});
busboy.off(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.prependListener('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.prependListener('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.prependListener('partsLimit', () => {});
busboy.prependListener('partsLimit', foo => {}); // $ExpectError
busboy.prependListener('filesLimit', () => {});
busboy.prependListener('filesLimit', foo => {}); // $ExpectError
busboy.prependListener('fieldsLimit', () => {});
busboy.prependListener('fieldsLimit', foo => {}); // $ExpectError
busboy.prependListener('error', e => {
e; // $ExpectType unknown
});
busboy.prependListener('finish', () => {});
busboy.prependListener('finish', foo => {}); // $ExpectError
// test fallback
busboy.prependListener('foo', foo => {
foo; // $ExpectType any
});
busboy.prependListener(Symbol('foo'), foo => {
foo; // $ExpectType any
});
busboy.prependOnceListener('file', (fieldname, file, filename, encoding, mimetype) => {
fieldname; // $ExpectType string
file; // $ExpectType Readable
filename; // $ExpectType string
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.prependOnceListener('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
fieldname; // $ExpectType string
val; // $ExpectType string
fieldnameTruncated; // $ExpectType boolean
valTruncated; // $ExpectType boolean
encoding; // $ExpectType string
mimetype; // $ExpectType string
});
busboy.prependOnceListener('partsLimit', () => {});
busboy.prependOnceListener('partsLimit', foo => {}); // $ExpectError
busboy.prependOnceListener('filesLimit', () => {});
busboy.prependOnceListener('filesLimit', foo => {}); // $ExpectError
busboy.prependOnceListener('fieldsLimit', () => {});
busboy.prependOnceListener('fieldsLimit', foo => {}); // $ExpectError
busboy.prependOnceListener('error', e => {
e; // $ExpectType unknown
});
busboy.prependOnceListener('finish', () => {});
busboy.prependOnceListener('finish', foo => {}); // $ExpectError
// test fallback
busboy.prependOnceListener('foo', foo => {
foo; // $ExpectType any
});
busboy.prependOnceListener(Symbol('foo'), foo => {
foo; // $ExpectType any
});

164
types/busboy/v0/index.d.ts vendored Normal file
View File

@@ -0,0 +1,164 @@
// Type definitions for busboy 0.3
// Project: https://www.npmjs.com/package/busboy
// Definitions by: Jacob Baskin <https://github.com/jacobbaskin>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import * as http from 'http';
import { Readable, Writable } from 'stream';
export = busboy;
declare const busboy: busboy.BusboyConstructor;
declare namespace busboy {
interface BusboyConfig {
/**
* These are the HTTP headers of the incoming request, which are used by individual parsers.
*/
headers: BusboyHeaders;
/**
* `highWaterMark` to use for this Busboy instance.
* @default WritableStream default.
*/
highWaterMark?: number | undefined;
/**
* highWaterMark to use for file streams.
* @default ReadableStream default.
*/
fileHwm?: number | undefined;
/**
* Default character set to use when one isn't defined.
* @default 'utf8'
*/
defCharset?: string | undefined;
/**
* If paths in the multipart 'filename' field shall be preserved.
* @default false
*/
preservePath?: boolean | undefined;
/**
* Various limits on incoming data.
*/
limits?:
| {
/**
* Max field name size (in bytes)
* @default 100 bytes
*/
fieldNameSize?: number | undefined;
/**
* Max field value size (in bytes)
* @default 1MB
*/
fieldSize?: number | undefined;
/**
* Max number of non-file fields
* @default Infinity
*/
fields?: number | undefined;
/**
* For multipart forms, the max file size (in bytes)
* @default Infinity
*/
fileSize?: number | undefined;
/**
* For multipart forms, the max number of file fields
* @default Infinity
*/
files?: number | undefined;
/**
* For multipart forms, the max number of parts (fields + files)
* @default Infinity
*/
parts?: number | undefined;
/**
* For multipart forms, the max number of header key=>value pairs to parse
* @default 2000 (same as node's http)
*/
headerPairs?: number | undefined;
}
| undefined;
}
type BusboyHeaders = { 'content-type': string } & http.IncomingHttpHeaders;
interface Busboy extends Writable {
addListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
on<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
off<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
off(event: string | symbol, listener: (...args: any[]) => void): this;
prependListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener<Event extends keyof BusboyEvents>(event: Event, listener: BusboyEvents[Event]): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
}
interface BusboyEvents {
/**
* Emitted for each new file form field found.
*
* * Note: if you listen for this event, you should always handle the `stream` no matter if you care about the
* file contents or not (e.g. you can simply just do `stream.resume();` if you want to discard the contents),
* otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about **any**
* incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically
* and safely discarded (these discarded files do still count towards `files` and `parts` limits).
* * If a configured file size limit was reached, `stream` will both have a boolean property `truncated`
* (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.
*
* @param listener.transferEncoding Contains the 'Content-Transfer-Encoding' value for the file stream.
* @param listener.mimeType Contains the 'Content-Type' value for the file stream.
*/
file: (
fieldname: string,
stream: Readable,
filename: string,
transferEncoding: string,
mimeType: string,
) => void;
/**
* Emitted for each new non-file field found.
*/
field: (
fieldname: string,
value: string,
fieldnameTruncated: boolean,
valueTruncated: boolean,
transferEncoding: string,
mimeType: string,
) => void;
finish: () => void;
/**
* Emitted when specified `parts` limit has been reached. No more 'file' or 'field' events will be emitted.
*/
partsLimit: () => void;
/**
* Emitted when specified `files` limit has been reached. No more 'file' events will be emitted.
*/
filesLimit: () => void;
/**
* Emitted when specified `fields` limit has been reached. No more 'field' events will be emitted.
*/
fieldsLimit: () => void;
error: (error: unknown) => void;
}
interface BusboyConstructor {
(options: BusboyConfig): Busboy;
new (options: BusboyConfig): Busboy;
}
}

View File

@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"paths": {
"busboy": [
"busboy/v0"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"busboy-tests.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "@definitelytyped/dtslint/dt.json"
}

View File

@@ -1,21 +1,19 @@
// Type definitions for connect-busboy 0.0
// Type definitions for connect-busboy 1.0
// Project: https://github.com/mscdex/connect-busboy
// Definitions by: Pinguet62 <https://github.com/pinguet62>
// Chris Gedrim <https://github.com/chrisgedrim>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
import * as busboy from 'busboy';
import { BusboyConfig, Busboy } from 'busboy';
import { RequestHandler } from 'express';
import * as http from 'http';
declare function connectBusboy(options?: connectBusboy.ConnectBusboyOptions): RequestHandler;
declare namespace connectBusboy {
interface ConnectBusboyOptions extends Omit<busboy.BusboyConfig, 'headers'> {
headers?: http.IncomingHttpHeaders;
interface ConnectBusboyOptions extends BusboyConfig {
immediate?: boolean | undefined;
}
}
@@ -23,7 +21,7 @@ declare namespace connectBusboy {
declare global {
namespace Express {
interface Request {
busboy: busboy.Busboy;
busboy: Busboy;
}
}
}

View File

@@ -12,6 +12,11 @@
"typeRoots": [
"../"
],
"paths": {
"busboy": [
"busboy/v0"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true

View File

@@ -14,7 +14,7 @@ import * as Koa from 'koa';
import * as Joi from 'joi';
import * as KoaRouter from 'koa-router';
import * as CoBody from 'co-body';
import * as busboy from 'busboy';
import { BusboyConfig } from 'busboy';
import * as http from 'http';
declare module 'koa' {
@@ -51,7 +51,7 @@ declare namespace createRouter {
type?: 'form' | 'json' | 'multipart' | undefined;
formOptions?: CoBody.Options | undefined;
jsonOptions?: CoBody.Options | undefined;
multipartOptions?: MultipartOptions | undefined;
multipartOptions?: BusboyConfig | undefined;
output?: { [status: string]: OutputValidation } | undefined;
continueOnError?: boolean | undefined;
validateOptions?: Joi.ValidationOptions | undefined;
@@ -60,10 +60,6 @@ declare namespace createRouter {
meta?: any;
}
interface MultipartOptions extends Omit<busboy.BusboyConfig, 'headers'> {
headers?: http.IncomingHttpHeaders;
}
interface Spec extends Config {
method: string | string[];
path: string | RegExp;

View File

@@ -2,21 +2,16 @@
// Project: https://github.com/eduardorfs/multy
// Definitions by: Jan Dolezel <https://github.com/dolezel>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
import * as Koa from "koa";
import * as busboy from "busboy";
import * as Koa from 'koa';
import { BusboyConfig } from 'busboy';
declare module "koa" {
declare module 'koa' {
interface Request {
body: any;
}
}
declare namespace multy {
type Options = busboy.BusboyConfig;
}
declare function multy(opts?: multy.Options): Koa.Middleware;
declare function multy(opts?: BusboyConfig): Koa.Middleware;
export = multy;

View File

@@ -13,6 +13,11 @@
"typeRoots": [
"../"
],
"paths": {
"busboy": [
"busboy/v0"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true