diff --git a/lib/index.ts b/lib/index.ts index 4c3033a..0baabe3 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,4 @@ -import { FastifyPluginAsync, FastifyRequest } from 'fastify' +import { type FastifyPluginAsync, type FastifyRequest } from 'fastify' import FastifyPlugin from 'fastify-plugin' import type { Fields, File, Files, Options } from 'formidable' // Since, formidable is CommonJS module @@ -7,7 +7,7 @@ import type { Fields, File, Files, Options } from 'formidable' import FormidableNamespace from 'formidable' import type Formidable from 'formidable/Formidable' import * as fs from 'fs' -import { IncomingMessage } from 'http' +import { type IncomingMessage } from 'http' export const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]') export const kIsMultipartParsed = Symbol.for('[FastifyMultipart.isMultipartParsed]') export const kFileSavedPaths = Symbol.for('[FastifyMultipart.fileSavedPaths]') @@ -30,7 +30,7 @@ export interface FastifyFormidableOptions { formidable?: Formidable | Options } -function promisify (func: Function): (request: IncomingMessage) => Promise<{ fields: Fields, files: Files }> { +function promisify (func: (request: IncomingMessage, callback: (err: any, fields: Fields, files: Files) => void) => void): (request: IncomingMessage) => Promise<{ fields: Fields, files: Files }> { return async function (request: IncomingMessage): Promise<{ fields: Fields, files: Files }> { return await new Promise(function (resolve, reject) { func(request, function (err: any, fields: Fields, files: Files) { diff --git a/test/addContentTypeParser.test.ts b/test/addContentTypeParser.test.ts index 5e199ae..fa92dac 100644 --- a/test/addContentTypeParser.test.ts +++ b/test/addContentTypeParser.test.ts @@ -1,5 +1,5 @@ import * as fs from 'fs' -import { AddressInfo } from 'net' +import { type AddressInfo } from 'net' import * as path from 'path' import t from 'tap' import { createFastify } from './createFastify' diff --git a/test/addHooks.test.ts b/test/addHooks.test.ts index b381a10..b00761c 100644 --- a/test/addHooks.test.ts +++ b/test/addHooks.test.ts @@ -1,5 +1,5 @@ import * as fs from 'fs' -import { AddressInfo } from 'net' +import { type AddressInfo } from 'net' import * as path from 'path' import t from 'tap' import { createFastify } from './createFastify' diff --git a/test/createFastify.ts b/test/createFastify.ts index 77c4838..a6cc825 100644 --- a/test/createFastify.ts +++ b/test/createFastify.ts @@ -1,7 +1,7 @@ import fastifySwagger from '@fastify/swagger' -import Fastify, { FastifyInstance } from 'fastify' -import { Options } from 'formidable' -import FastifyFormidable, { ajvBinaryFormat, FastifyFormidableOptions } from '../lib' +import Fastify, { type FastifyInstance } from 'fastify' +import { type Options } from 'formidable' +import FastifyFormidable, { ajvBinaryFormat, type FastifyFormidableOptions } from '../lib' // reduce keep alive to prevent `undici` keep the socket open export const fastifyOptions = { keepAliveTimeout: 100 } @@ -11,7 +11,7 @@ export async function createFastify (t: Tap.Test, options: FastifyFormidableOpti await fastify.register(FastifyFormidable, options) - fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) { + fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) { if (inline === true) await request.parseMultipart() if (typeof inline === 'object') await request.parseMultipart(inline) return await reply.code(200).send({ @@ -38,7 +38,7 @@ export async function createIntegrationFastify (t: Tap.Test, options: FastifyFor await fastify.register(FastifyFormidable, options) await fastify.register(fastifySwagger) - fastify.post<{ Body: { foo: String, file: string } }>('/', { + fastify.post<{ Body: { foo: string, file: string } }>('/', { schema }, async function (request, reply) { if (inline) await request.parseMultipart() diff --git a/test/error.test.ts b/test/error.test.ts index a47d0b0..f69f6e7 100644 --- a/test/error.test.ts +++ b/test/error.test.ts @@ -1,7 +1,7 @@ import Fastify from 'fastify' import { IncomingForm } from 'formidable' import * as fs from 'fs' -import { AddressInfo } from 'net' +import { type AddressInfo } from 'net' import * as path from 'path' import t from 'tap' import FastifyFormidable from '../lib' @@ -36,8 +36,7 @@ t.test('error', function (t) { t.teardown(fastify.close) const formidable = new IncomingForm() - // @ts-expect-error - formidable.parse = function (_, callback: Function) { + formidable.parse = function (_, callback: (err: any) => void) { callback(new Error('parse error')) } @@ -45,7 +44,7 @@ t.test('error', function (t) { formidable }) - fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) { + fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) { const body = await request.parseMultipart() return await reply.code(200).send({ body, diff --git a/test/integration.test.ts b/test/integration.test.ts index c44b410..116c21b 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -1,5 +1,5 @@ import * as fs from 'fs' -import { AddressInfo } from 'net' +import { type AddressInfo } from 'net' import * as path from 'path' import t from 'tap' import { createIntegrationFastify } from './createFastify' diff --git a/test/parseMultipart.test.ts b/test/parseMultipart.test.ts index 63f64f4..f377b42 100644 --- a/test/parseMultipart.test.ts +++ b/test/parseMultipart.test.ts @@ -1,5 +1,5 @@ import * as fs from 'fs' -import { AddressInfo } from 'net' +import { type AddressInfo } from 'net' import * as path from 'path' import t from 'tap' import { createFastify } from './createFastify' diff --git a/test/removeFilesFromBody.test.ts b/test/removeFilesFromBody.test.ts index 3678314..e801151 100644 --- a/test/removeFilesFromBody.test.ts +++ b/test/removeFilesFromBody.test.ts @@ -1,6 +1,6 @@ import Fastify from 'fastify' import * as fs from 'fs' -import { AddressInfo } from 'net' +import { type AddressInfo } from 'net' import * as path from 'path' import t from 'tap' import FastifyFormidable from '../lib' @@ -26,7 +26,7 @@ t.test('removeFilesFromBody', function (t) { removeFilesFromBody: true }) - fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) { + fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) { return await reply.code(200).send({ body: request.body, files: request.files @@ -63,7 +63,7 @@ t.test('removeFilesFromBody', function (t) { removeFilesFromBody: true }) - fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) { + fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) { return await reply.code(200).send({ body: request.body, files: request.files @@ -99,7 +99,7 @@ t.test('removeFilesFromBody', function (t) { removeFilesFromBody: true }) - fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) { + fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) { const body = await request.parseMultipart() return await reply.code(200).send({ body, @@ -137,7 +137,7 @@ t.test('removeFilesFromBody', function (t) { removeFilesFromBody: true }) - fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) { + fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) { return await reply.code(200).send({ body: request.body, files: request.files diff --git a/test/warning.test.ts b/test/warning.test.ts index 0d34ea8..b353899 100644 --- a/test/warning.test.ts +++ b/test/warning.test.ts @@ -1,6 +1,6 @@ import Fastify from 'fastify' import * as fs from 'fs' -import { AddressInfo } from 'net' +import { type AddressInfo } from 'net' import * as path from 'path' import t from 'tap' import FastifyFormidable from '../lib' @@ -26,7 +26,7 @@ t.test('warning', function (t) { removeFilesFromBody: true }) - fastify.post<{ Body: { foo: String, file: string } }>('/', { + fastify.post<{ Body: { foo: string, file: string } }>('/', { onRequest (request, _, done) { request.log = { warn (msg: string) {