Skip to content

chore: fix types #1884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
857 changes: 382 additions & 475 deletions package-lock.json

Large diffs are not rendered by default.

53 changes: 19 additions & 34 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="node" />
/// <reference types="node" />
export = wdm;
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
/** @typedef {import("webpack").Compiler} Compiler */
Expand Down Expand Up @@ -154,8 +152,7 @@ export = wdm;
* @returns {API<RequestInternal, ResponseInternal>}
*/
declare function wdm<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
>(
compiler: Compiler | MultiCompiler,
Expand Down Expand Up @@ -204,14 +201,6 @@ declare namespace wdm {
HapiOptions,
};
}
type Compiler = import("webpack").Compiler;
type MultiCompiler = import("webpack").MultiCompiler;
type API<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
> = Middleware<RequestInternal, ResponseInternal> &
AdditionalMethods<RequestInternal, ResponseInternal>;
/**
* @template S
* @template O
Expand Down Expand Up @@ -243,28 +232,25 @@ declare function hapiWrapper<
* @returns {(ctx: any, next: Function) => Promise<void> | void}
*/
declare function koaWrapper<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
>(
compiler: Compiler | MultiCompiler,
options?: Options<RequestInternal, ResponseInternal> | undefined,
): (ctx: any, next: Function) => Promise<void> | void;
type Schema = import("schema-utils/declarations/validate").Schema;
type Compiler = import("webpack").Compiler;
type MultiCompiler = import("webpack").MultiCompiler;
type Configuration = import("webpack").Configuration;
type Stats = import("webpack").Stats;
type MultiStats = import("webpack").MultiStats;
type ReadStream = import("fs").ReadStream;
type ExtendedServerResponse = {
locals?:
| {
webpack?:
| {
devMiddleware?:
| Context<import("http").IncomingMessage, ServerResponse>
| undefined;
}
| undefined;
webpack?: {
devMiddleware?: Context<IncomingMessage, ServerResponse>;
};
}
| undefined;
};
Expand All @@ -289,8 +275,7 @@ type ResponseData = {
byteLength: number;
};
type ModifyResponseData<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
> = (
req: RequestInternal,
Expand All @@ -299,8 +284,7 @@ type ModifyResponseData<
byteLength: number,
) => ResponseData;
type Context<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
> = {
state: boolean;
Expand All @@ -313,8 +297,7 @@ type Context<
outputFileSystem: OutputFileSystem;
};
type FilledContext<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
> = WithoutUndefined<Context<RequestInternal, ResponseInternal>, "watching">;
type NormalizedHeaders =
Expand All @@ -324,8 +307,7 @@ type NormalizedHeaders =
value: number | string;
}>;
type Headers<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
> =
| NormalizedHeaders
Expand All @@ -336,8 +318,7 @@ type Headers<
) => void | undefined | NormalizedHeaders)
| undefined;
type Options<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
> = {
mimeTypes?:
Expand All @@ -361,8 +342,7 @@ type Options<
lastModified?: boolean | undefined;
};
type Middleware<
RequestInternal extends
import("http").IncomingMessage = import("http").IncomingMessage,
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
> = (
req: RequestInternal,
Expand All @@ -378,7 +358,7 @@ type WaitUntilValid = (callback: Callback) => any;
type Invalidate = (callback: Callback) => any;
type Close = (callback: (err: Error | null | undefined) => void) => any;
type AdditionalMethods<
RequestInternal extends import("http").IncomingMessage,
RequestInternal extends IncomingMessage,
ResponseInternal extends ServerResponse,
> = {
getFilenameFromUrl: GetFilenameFromUrl;
Expand All @@ -387,6 +367,11 @@ type AdditionalMethods<
close: Close;
context: Context<RequestInternal, ResponseInternal>;
};
type API<
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
ResponseInternal extends ServerResponse = ServerResponse,
> = Middleware<RequestInternal, ResponseInternal> &
AdditionalMethods<RequestInternal, ResponseInternal>;
type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
type WithoutUndefined<T, K extends keyof T> = T & {
[P in K]: NonNullable<T[P]>;
Expand Down
9 changes: 4 additions & 5 deletions types/middleware.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export = wrapper;
/**
* @template {IncomingMessage} Request
Expand All @@ -14,8 +13,8 @@ export = wrapper;
* @return {import("./index.js").Middleware<Request, Response>}
*/
declare function wrapper<
Request extends import("http").IncomingMessage,
Response extends import("./index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
>(
context: import("./index.js").FilledContext<Request, Response>,
): import("./index.js").Middleware<Request, Response>;
Expand All @@ -33,8 +32,8 @@ declare namespace wrapper {
* send error options
*/
type SendErrorOptions<
Request extends import("http").IncomingMessage,
Response extends import("./index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
> = {
/**
* headers
Expand Down
13 changes: 4 additions & 9 deletions types/utils/compatibleAPI.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export type IncomingMessage = import("../index.js").IncomingMessage;
export type ServerResponse = import("../index.js").ServerResponse;
export type ExpectedResponse = {
Expand All @@ -20,11 +19,7 @@ export type ExpectedResponse = {
* @param {number} code
*/
export function setStatusCode<
Response extends import("http").ServerResponse<
import("http").IncomingMessage
> &
import("../index.js").ExtendedServerResponse &
ExpectedResponse,
Response extends ServerResponse & ExpectedResponse,
>(res: Response, code: number): void;
/**
* @template {IncomingMessage} Request
Expand All @@ -33,15 +28,15 @@ export function setStatusCode<
* @param {string | Buffer} bufferOrStream
*/
export function send<
Request extends import("http").IncomingMessage,
Response extends import("../index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
>(res: Response & ExpectedResponse, bufferOrStream: string | Buffer): void;
/**
* @template {ServerResponse} Response
* @param {Response & ExpectedResponse} res
* @param {import("fs").ReadStream} bufferOrStream
*/
export function pipe<Response extends import("../index.js").ServerResponse>(
export function pipe<Response extends ServerResponse>(
res: Response & ExpectedResponse,
bufferOrStream: import("fs").ReadStream,
): void;
Expand Down
2 changes: 1 addition & 1 deletion types/utils/etag.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ declare function etag(entity: Buffer | ReadStream | Stats): Promise<{
declare namespace etag {
export { Stats, ReadStream };
}
type ReadStream = import("fs").ReadStream;
type Stats = import("fs").Stats;
type ReadStream = import("fs").ReadStream;
5 changes: 2 additions & 3 deletions types/utils/getFilenameFromUrl.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export = getFilenameFromUrl;
/**
* @template {IncomingMessage} Request
Expand All @@ -9,8 +8,8 @@ export = getFilenameFromUrl;
* @returns {string | undefined}
*/
declare function getFilenameFromUrl<
Request extends import("http").IncomingMessage,
Response extends import("../index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
>(
context: import("../index.js").FilledContext<Request, Response>,
url: string,
Expand Down
5 changes: 2 additions & 3 deletions types/utils/getPaths.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export = getPaths;
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").Stats} Stats */
Expand All @@ -11,8 +10,8 @@ export = getPaths;
* @param {import("../index.js").FilledContext<Request, Response>} context
*/
declare function getPaths<
Request extends import("http").IncomingMessage,
Response extends import("../index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
>(
context: import("../index.js").FilledContext<Request, Response>,
): {
Expand Down
14 changes: 6 additions & 8 deletions types/utils/memorize.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ declare function memorize<T>(
cache,
}?:
| {
cache?:
| Map<
string,
{
data: T;
}
>
| undefined;
cache?: Map<
string,
{
data: T;
}
>;
}
| undefined,
callback?: ((value: T) => T) | undefined,
Expand Down
5 changes: 2 additions & 3 deletions types/utils/ready.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export = ready;
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
/** @typedef {import("../index.js").ServerResponse} ServerResponse */
Expand All @@ -11,8 +10,8 @@ export = ready;
* @returns {void}
*/
declare function ready<
Request extends import("http").IncomingMessage,
Response extends import("../index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
>(
context: import("../index.js").FilledContext<Request, Response>,
callback: (...args: any[]) => any,
Expand Down
5 changes: 2 additions & 3 deletions types/utils/setupHooks.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export = setupHooks;
/** @typedef {import("webpack").Configuration} Configuration */
/** @typedef {import("webpack").Compiler} Compiler */
Expand All @@ -16,8 +15,8 @@ export = setupHooks;
* @param {import("../index.js").WithOptional<import("../index.js").Context<Request, Response>, "watching" | "outputFileSystem">} context
*/
declare function setupHooks<
Request extends import("http").IncomingMessage,
Response extends import("../index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
>(
context: import("../index.js").WithOptional<
import("../index.js").Context<Request, Response>,
Expand Down
5 changes: 2 additions & 3 deletions types/utils/setupOutputFileSystem.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export = setupOutputFileSystem;
/** @typedef {import("webpack").MultiCompiler} MultiCompiler */
/** @typedef {import("../index.js").IncomingMessage} IncomingMessage */
Expand All @@ -9,8 +8,8 @@ export = setupOutputFileSystem;
* @param {import("../index.js").WithOptional<import("../index.js").Context<Request, Response>, "watching" | "outputFileSystem">} context
*/
declare function setupOutputFileSystem<
Request extends import("http").IncomingMessage,
Response extends import("../index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
>(
context: import("../index.js").WithOptional<
import("../index.js").Context<Request, Response>,
Expand Down
5 changes: 2 additions & 3 deletions types/utils/setupWriteToDisk.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
export = setupWriteToDisk;
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").MultiCompiler} MultiCompiler */
Expand All @@ -11,8 +10,8 @@ export = setupWriteToDisk;
* @param {import("../index.js").WithOptional<import("../index.js").Context<Request, Response>, "watching" | "outputFileSystem">} context
*/
declare function setupWriteToDisk<
Request extends import("http").IncomingMessage,
Response extends import("../index.js").ServerResponse,
Request extends IncomingMessage,
Response extends ServerResponse,
>(
context: import("../index.js").WithOptional<
import("../index.js").Context<Request, Response>,
Expand Down
Loading