-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: separate ESM vs CJS type definitions (#200)
* fix ESM types * update package.json files per code review * old style exports * oops. forgot one * chore: revert `url` types * fix: update pkg `files` lists * chore: consolidate `parse` types; - named exports only * fix(cluster): use namespace for CommonJS types * fix(send): use namespace for CommonJS types * fix(polka): named type `Trouter` import * fix(polka): use namespace for CommonJS types --------- Co-authored-by: Luke Edwards <[email protected]>
- Loading branch information
Showing
15 changed files
with
215 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { RequestListener } from 'http'; | ||
|
||
export interface ClusterController { | ||
listen(port: number): void; | ||
} | ||
|
||
export default function (app: RequestListener | { listen: Function }): ClusterController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
import type { RequestListener } from 'http'; | ||
|
||
export interface ClusterController { | ||
listen(port: number): void; | ||
declare namespace cluster { | ||
export interface ClusterController { | ||
listen(port: number): void; | ||
} | ||
} | ||
|
||
export default function (app: RequestListener | { listen: Function }): ClusterController; | ||
declare function cluster( | ||
app: RequestListener | { | ||
listen: Function | ||
} | ||
): cluster.ClusterController; | ||
|
||
export = cluster; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import type { IncomingMessage, ServerResponse } from 'http'; | ||
import type { ListenOptions, Server } from 'net'; | ||
import type { ParsedURL } from '@polka/url'; | ||
import type { Trouter } from 'trouter'; | ||
|
||
type Promisable<T> = Promise<T> | T; | ||
type ListenCallback = () => Promisable<void>; | ||
|
||
export interface IError extends Error { | ||
code?: number; | ||
status?: number; | ||
details?: any; | ||
} | ||
|
||
export type NextHandler = (err?: string | IError) => Promisable<void>; | ||
export type ErrorHandler<T extends Request = Request> = (err: string | IError, req: T, res: Response, next: NextHandler) => Promisable<void>; | ||
export type Middleware<T extends IncomingMessage = Request> = (req: T & Request, res: Response, next: NextHandler) => Promisable<void>; | ||
|
||
export interface IOptions<T extends Request = Request> { | ||
server?: Server; | ||
onNoMatch?: Middleware<T>; | ||
onError?: ErrorHandler<T>; | ||
} | ||
|
||
export type Response = ServerResponse; | ||
|
||
export interface Request extends IncomingMessage { | ||
url: string; | ||
method: string; | ||
originalUrl: string; | ||
params: Record<string, string>; | ||
path: string; | ||
search: string; | ||
query: Record<string,string>; | ||
body?: any; | ||
_decoded?: true; | ||
_parsedUrl: ParsedURL; | ||
} | ||
|
||
export interface Polka<T extends Request = Request> extends Trouter<Middleware<T>> { | ||
readonly server: Server; | ||
readonly wares: Middleware<T>[]; | ||
|
||
readonly onError: ErrorHandler<T>; | ||
readonly onNoMatch: Middleware<T>; | ||
|
||
readonly handler: Middleware<T>; | ||
parse: (req: IncomingMessage) => ParsedURL; | ||
|
||
use(pattern: RegExp|string, ...handlers: (Polka<T> | Middleware<T>)[]): this; | ||
use(...handlers: (Polka<T> | Middleware<T>)[]): this; | ||
|
||
listen(port?: number, hostname?: string, backlog?: number, callback?: ListenCallback): this; | ||
listen(port?: number, hostname?: string, callback?: ListenCallback): this; | ||
listen(port?: number, backlog?: number, callback?: ListenCallback): this; | ||
listen(port?: number, callback?: ListenCallback): this; | ||
listen(path: string, backlog?: number, callback?: ListenCallback): this; | ||
listen(path: string, callback?: ListenCallback): this; | ||
listen(options: ListenOptions, callback?: ListenCallback): this; | ||
listen(handle: any, backlog?: number, callback?: ListenCallback): this; | ||
listen(handle: any, callback?: ListenCallback): this; | ||
} | ||
|
||
export default function<T extends Request = Request>( | ||
options?: IOptions<T> | ||
): Polka<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import type { ServerResponse } from 'http'; | ||
export default function (res: ServerResponse, code?: number, location?: string): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
import type { ServerResponse } from 'http'; | ||
export default function (res: ServerResponse, code?: number, location?: string): void; | ||
|
||
declare function redirect(res: ServerResponse, code?: number, location?: string): void; | ||
|
||
export = redirect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { ServerResponse } from 'http'; | ||
export type OutgoingHeaders = Record<string, string|string[]>; | ||
export default function (res: ServerResponse, status?: number, data?: any, headers?: OutgoingHeaders): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
import type { ServerResponse } from 'http'; | ||
export type OutgoingHeaders = Record<string, string|string[]>; | ||
export default function (res: ServerResponse, status?: number, data?: any, headers?: OutgoingHeaders): void; | ||
|
||
declare namespace send { | ||
export type OutgoingHeaders = Record<string, string|string[]>; | ||
} | ||
|
||
declare function send( | ||
res: ServerResponse, | ||
status?: number, | ||
data?: any, | ||
headers?: send.OutgoingHeaders | ||
): void; | ||
|
||
export = send; |
Oops, something went wrong.