From f56a12fc8883962d490acba3a80b8a7927d5a26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Vieira?= Date: Thu, 23 Aug 2018 16:59:54 +0100 Subject: [PATCH] Add server properties. --- types/next/index.d.ts | 93 +++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 30 deletions(-) diff --git a/types/next/index.d.ts b/types/next/index.d.ts index 2d87121d61..268078544a 100644 --- a/types/next/index.d.ts +++ b/types/next/index.d.ts @@ -16,13 +16,16 @@ import * as url from "url"; import { Response as NodeResponse } from "node-fetch"; +import Router from './router'; + declare namespace next { /** Map object used in query strings. */ type QueryStringMapObject = Record; /** * Context object used in methods like `getInitialProps()` - * <> + * https://github.com/zeit/next.js/blob/6.1.1/server/render.js#L77 + * https://github.com/zeit/next.js/blob/6.1.1/readme.md#fetching-data-and-component-lifecycle */ interface NextContext { /** path section of URL */ @@ -39,8 +42,6 @@ declare namespace next { jsonPageRes?: NodeResponse; /** Error object if any error is encountered during the rendering */ err?: Error; - /** Whether we're running on the server environment or not. */ - isServer?: boolean; } type NextSFC = NextStatelessComponent; @@ -51,8 +52,11 @@ declare namespace next { type UrlLike = url.UrlObject | url.Url; - interface ServerConfig { - // known keys + /** + * Next.js config schema. + * https://github.com/zeit/next.js/blob/6.1.1/server/config.js#L10 + */ + interface NextConfig { webpack?: any; webpackDevMiddleware?: any; poweredByHeader?: boolean; @@ -60,21 +64,58 @@ declare namespace next { assetPrefix?: string; configOrigin?: string; useFileSystemPublicRoutes?: boolean; + generateBuildId?: () => string; + generateEtags?: boolean; + pageExtensions?: string[]; + publicRuntimeConfig?: object; + serverRuntimeConfig?: object; - // and since this is a config, it can take anything else, too. + // Plugin can define their own keys. [key: string]: any; } + /** + * Options passed to the Server constructor in Node.js. + * https://github.com/zeit/next.js/blob/6.1.1/server/index.js#L30 + */ interface ServerOptions { dir?: string; dev?: boolean; staticMarkup?: boolean; quiet?: boolean; - conf?: ServerConfig; + conf?: NextConfig; } + /** + * Next.js server instance API. + */ interface Server { - setAssetPrefix: (cdnUrl: string) => void; + // From constructor + // https://github.com/zeit/next.js/blob/6.1.1/server/index.js#L30 + dir: string; + dev: boolean; + quiet: boolean; + router: Router; + http: null | http.Server; + nextConfig: NextConfig; + distDir: string; + buildId: string; + hotReloader: any; + renderOpts: { + dev: string; + staticMarkup: boolean; + distDir: string; + hotReloader: any; + buildId: string; + availableChunks: object; + generateETags: boolean; + runtimeConfig?: object; + }; + + getHotReloader( + dir: string, + options: { quiet: boolean; config: NextConfig; buildId: string } + ): any; handleRequest( req: http.IncomingMessage, res: http.ServerResponse, @@ -85,6 +126,8 @@ declare namespace next { res: http.ServerResponse, parsedUrl?: UrlLike ) => Promise; + setAssetPrefix(prefix: string): void; + prepare(): Promise; close(): Promise; defineRoutes(): Promise; @@ -102,6 +145,12 @@ declare namespace next { query?: QueryStringMapObject, parsedUrl?: UrlLike ): Promise; + renderToHTML( + req: http.IncomingMessage, + res: http.ServerResponse, + pathname: string, + query?: QueryStringMapObject + ): Promise; renderError( err: any, req: http.IncomingMessage, @@ -109,17 +158,6 @@ declare namespace next { pathname: string, query?: QueryStringMapObject ): Promise; - render404( - req: http.IncomingMessage, - res: http.ServerResponse, - parsedUrl: UrlLike - ): Promise; - renderToHTML( - req: http.IncomingMessage, - res: http.ServerResponse, - pathname: string, - query?: QueryStringMapObject - ): Promise; renderErrorToHTML( err: any, req: http.IncomingMessage, @@ -127,6 +165,11 @@ declare namespace next { pathname: string, query?: QueryStringMapObject ): Promise; + render404( + req: http.IncomingMessage, + res: http.ServerResponse, + parsedUrl?: UrlLike + ): Promise; serveStatic( req: http.IncomingMessage, @@ -134,19 +177,9 @@ declare namespace next { path: string ): Promise; isServeableUrl(path: string): boolean; - isInternalUrl(req: http.IncomingMessage): boolean; readBuildId(): string; handleBuildId(buildId: string, res: http.ServerResponse): boolean; - getCompilationError( - page: string, - req: http.IncomingMessage, - res: http.ServerResponse - ): Promise; - handleBuildHash( - filename: string, - hash: string, - res: http.ServerResponse - ): void; + getCompilationError(): Promise; send404(res: http.ServerResponse): void; } }