Caricamento del resto di questo confronto.

express-serve-static-core v4 vs v5

Creato Il diff non scade mai
28 rimozioni
744 linee
33 aggiunte
745 linee
// This extracts the core definitions from express to prevent a circular dependency between express and serve-static
// This extracts the core definitions from express to prevent a circular dependency between express and serve-static
/// <reference types="node" />
/// <reference types="node" />


import { SendOptions } from "send";
import { SendOptions } from "send";


declare global {
declare global {
namespace Express {
namespace Express {
// These open interfaces may be extended in an application-specific manner via declaration merging.
// These open interfaces may be extended in an application-specific manner via declaration merging.
// See for example method-override.d.ts (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/method-override/index.d.ts)
// See for example method-override.d.ts (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/method-override/index.d.ts)
interface Request {}
interface Request {}
interface Response {}
interface Response {}
interface Locals {}
interface Locals {}
interface Application {}
interface Application {}
}
}
}
}


import { EventEmitter } from "events";
import { EventEmitter } from "events";
import * as http from "http";
import * as http from "http";
import { ParsedQs } from "qs";
import { ParsedQs } from "qs";
import { Options as RangeParserOptions, Ranges as RangeParserRanges, Result as RangeParserResult } from "range-parser";
import { Options as RangeParserOptions, Ranges as RangeParserRanges, Result as RangeParserResult } from "range-parser";


export {};
export {};


export type Query = ParsedQs;
export type Query = ParsedQs;


export interface NextFunction {
export interface NextFunction {
(err?: any): void;
(err?: any): void;
/**
/**
* "Break-out" of a router by calling {next('router')};
* "Break-out" of a router by calling {next('router')};
* @see {https://expressjs.com/en/guide/using-middleware.html#middleware.router}
* @see {https://expressjs.com/en/guide/using-middleware.html#middleware.router}
*/
*/
(deferToNext: "router"): void;
(deferToNext: "router"): void;
/**
/**
* "Break-out" of a route by calling {next('route')};
* "Break-out" of a route by calling {next('route')};
* @see {https://expressjs.com/en/guide/using-middleware.html#middleware.application}
* @see {https://expressjs.com/en/guide/using-middleware.html#middleware.application}
*/
*/
(deferToNext: "route"): void;
(deferToNext: "route"): void;
}
}


export interface Dictionary<T> {
export interface Dictionary<T> {
[key: string]: T;
[key: string]: T;
}
}


export interface ParamsDictionary {
export interface ParamsDictionary {
[key: string]: string;
[key: string]: string;
}
}
export type ParamsArray = string[];
export type ParamsArray = string[];
export type Params = ParamsDictionary | ParamsArray;
export type Params = ParamsDictionary | ParamsArray;


export interface Locals extends Express.Locals {}
export interface Locals extends Express.Locals {}


export interface RequestHandler<
export interface RequestHandler<
P = ParamsDictionary,
P = ParamsDictionary,
ResBody = any,
ResBody = any,
ReqBody = any,
ReqBody = any,
ReqQuery = ParsedQs,
ReqQuery = ParsedQs,
LocalsObj extends Record<string, any> = Record<string, any>,
LocalsObj extends Record<string, any> = Record<string, any>,
> {
> {
// tslint:disable-next-line callable-types (This is extended from and can't extend from a type alias in ts<2.2)
// tslint:disable-next-line callable-types (This is extended from and can't extend from a type alias in ts<2.2)
(
(
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
res: Response<ResBody, LocalsObj>,
res: Response<ResBody, LocalsObj>,
next: NextFunction,
next: NextFunction,
): void;
): void | Promise<void>;
}
}


export type ErrorRequestHandler<
export type ErrorRequestHandler<
P = ParamsDictionary,
P = ParamsDictionary,
ResBody = any,
ResBody = any,
ReqBody = any,
ReqBody = any,
ReqQuery = ParsedQs,
ReqQuery = ParsedQs,
LocalsObj extends Record<string, any> = Record<string, any>,
LocalsObj extends Record<string, any> = Record<string, any>,
> = (
> = (
err: any,
err: any,
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
res: Response<ResBody, LocalsObj>,
res: Response<ResBody, LocalsObj>,
next: NextFunction,
next: NextFunction,
) => void;
) => void | Promise<void>;


export type PathParams = string | RegExp | Array<string | RegExp>;
export type PathParams = string | RegExp | Array<string | RegExp>;


export type RequestHandlerParams<
export type RequestHandlerParams<
P = ParamsDictionary,
P = ParamsDictionary,
ResBody = any,
ResBody = any,
ReqBody = any,
ReqBody = any,
ReqQuery = ParsedQs,
ReqQuery = ParsedQs,
LocalsObj extends Record<string, any> = Record<string, any>,
LocalsObj extends Record<string, any> = Record<string, any>,
> =
> =
| RequestHandler<P, ResBody, ReqBody, ReqQuery, LocalsObj>
| RequestHandler<P, ResBody, ReqBody, ReqQuery, LocalsObj>
| ErrorRequestHandler<P, ResBody, ReqBody, ReqQuery, LocalsObj>
| ErrorRequestHandler<P, ResBody, ReqBody, ReqQuery, LocalsObj>
| Array<RequestHandler<P> | ErrorRequestHandler<P>>;
| Array<RequestHandler<P> | ErrorRequestHandler<P>>;


type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
type GetRouteParameter<S extends string> = RemoveTail<
type GetRouteParameter<S extends string> = RemoveTail<
RemoveTail<RemoveTail<S, `/${string}`>, `-${string}`>,
RemoveTail<RemoveTail<S, `/${string}`>, `-${string}`>,
`.${string}`
`.${string}`
>;
>;


// prettier-ignore
// prettier-ignore
export type RouteParameters<Route extends string> = string extends Route ? ParamsDictionary
export type RouteParameters<Route extends string> = Route extends `${infer Required}{${infer Optional}}${infer Next}`