import { OutputAsset, OutputChunk } from 'rollup'; import { SvelteComponent } from 'svelte/internal'; import { Config, ServerLoad, Handle, HandleServerError, KitConfig, Load, RequestEvent, RequestHandler, ResolveOptions, Server, ServerInitOptions, SSRManifest, HandleFetch, Actions, HandleClientError } from './index.js'; import { HttpMethod, MaybePromise, PrerenderOption, RequestOptions, TrailingSlash } from './private.js'; export interface ServerModule { Server: typeof InternalServer; override(options: { paths: { base: string; assets: string; }; prerendering: boolean; protocol?: 'http' | 'https'; read(file: string): Buffer; }): void; } export interface Asset { file: string; size: number; type: string | null; } export interface BuildData { app_dir: string; manifest_data: ManifestData; service_worker: string | null; client: { assets: OutputAsset[]; chunks: OutputChunk[]; entry: { file: string; imports: string[]; stylesheets: string[]; }; vite_manifest: import('vite').Manifest; }; server: { chunks: OutputChunk[]; methods: Record; vite_manifest: import('vite').Manifest; }; } export interface CSRPageNode { component: typeof SvelteComponent; shared: { load?: Load; }; server: boolean; } export type CSRPageNodeLoader = () => Promise; /** * Definition of a client side route. * The boolean in the tuples indicates whether the route has a server load. */ export type CSRRoute = { id: string; exec: (path: string) => undefined | Record; errors: Array; layouts: Array<[boolean, CSRPageNodeLoader] | undefined>; leaf: [boolean, CSRPageNodeLoader]; }; export type GetParams = (match: RegExpExecArray) => Record; export interface ServerHooks { handleFetch: HandleFetch; handle: Handle; handleError: HandleServerError; } export interface ClientHooks { handleError: HandleClientError; } export class InternalServer extends Server { init(options: ServerInitOptions): Promise; respond( request: Request, options: RequestOptions & { prerendering?: PrerenderOptions; } ): Promise; } export interface ManifestData { assets: Asset[]; nodes: PageNode[]; routes: RouteData[]; matchers: Record; } export interface PageNode { depth: number; component?: string; // TODO supply default component if it's missing (bit of an edge case) shared?: string; server?: string; parent_id?: string; parent?: PageNode; /** * Filled with the pages that reference this layout (if this is a layout) */ child_pages?: PageNode[]; } export interface PrerenderDependency { response: Response; body: null | string | Uint8Array; } export interface PrerenderOptions { cache?: string; // including this here is a bit of a hack, but it makes it easy to add fallback?: boolean; dependencies: Map; } export type RecursiveRequired = { // Recursive implementation of TypeScript's Required utility type. // Will recursively continue until it reaches a primitive or Function [K in keyof T]-?: Extract extends never // If it does not have a Function type ? RecursiveRequired // recursively continue through. : T[K]; // Use the exact type for everything else }; export type RequiredResolveOptions = Required; export interface Respond { (request: Request, options: SSROptions, state: SSRState): Promise; } /** * Represents a route segment in the app. It can either be an intermediate node * with only layout/error pages, or a leaf, at which point either `page` and `leaf` * or `endpoint` is set. */ export interface RouteData { id: string; parent: RouteData | null; segment: string; pattern: RegExp; names: string[]; types: string[]; layout: PageNode | null; error: PageNode | null; leaf: PageNode | null; page: { layouts: Array; errors: Array; leaf: number; } | null; endpoint: { file: string; } | null; } export type ServerData = | { type: 'redirect'; location: string; } | { type: 'data'; /** * If `null`, then there was no load function */ nodes: Array; }; /** * Signals a successful response of the server `load` function. * The `uses` property tells the client when it's possible to reuse this data * in a subsequent request. */ export interface ServerDataNode { type: 'data'; data: Record | null; uses: { dependencies?: string[]; params?: string[]; parent?: number | void; // 1 or undefined url?: number | void; // 1 or undefined }; } /** * Signals that the server `load` function was not run, and the * client should use what it has in memory */ export interface ServerDataSkippedNode { type: 'skip'; } /** * Signals that the server `load` function failed */ export interface ServerErrorNode { type: 'error'; error: App.PageError; /** * Only set for HttpErrors */ status?: number; } export interface SSRComponent { default: { render(props: Record): { html: string; head: string; css: { code: string; map: any; // TODO }; }; }; } export type SSRComponentLoader = () => Promise; export interface SSRNode { component: SSRComponentLoader; /** index into the `components` array in client-manifest.js */ index: number; /** client-side module URL for this component */ file: string; /** external JS files */ imports: string[]; /** external CSS files */ stylesheets: string[]; /** inlined styles */ inline_styles?: () => MaybePromise>; shared: { load?: Load; prerender?: PrerenderOption; ssr?: boolean; csr?: boolean; }; server: { load?: ServerLoad; prerender?: PrerenderOption; ssr?: boolean; csr?: boolean; actions?: Actions; }; // store this in dev so we can print serialization errors server_id?: string; } export type SSRNodeLoader = () => Promise; export interface SSROptions { csp: ValidatedConfig['kit']['csp']; csrf: { check_origin: boolean; }; dev: boolean; handle_error(error: Error & { frame?: string }, event: RequestEvent): App.PageError; hooks: ServerHooks; manifest: SSRManifest; paths: { base: string; assets: string; }; public_env: Record; read(file: string): Buffer; root: SSRComponent['default']; service_worker?: string; app_template({ head, body, assets, nonce }: { head: string; body: string; assets: string; nonce: string; }): string; app_template_contains_nonce: boolean; error_template({ message, status }: { message: string; status: number }): string; trailing_slash: TrailingSlash; } export interface SSRErrorPage { id: '__error'; } export interface PageNodeIndexes { errors: Array; layouts: Array; leaf: number; } export type SSREndpoint = Partial> & { prerender?: PrerenderOption; }; export interface SSRRoute { id: string; pattern: RegExp; names: string[]; types: string[]; page: PageNodeIndexes | null; endpoint: (() => Promise) | null; } export interface SSRState { fallback?: string; getClientAddress: () => string; initiator?: SSRRoute | SSRErrorPage; platform?: any; prerendering?: PrerenderOptions; /** * When fetching data from a +server.js endpoint in `load`, the page's * prerender option is inherited by the endpoint, unless overridden */ prerender_default?: PrerenderOption; } export type StrictBody = string | Uint8Array; export interface Uses { dependencies: Set; params: Set; parent: boolean; url: boolean; } export type ValidatedConfig = RecursiveRequired; export type ValidatedKitConfig = RecursiveRequired; export * from './index'; export * from './private'; declare global { const __SVELTEKIT_ADAPTER_NAME__: string; const __SVELTEKIT_APP_VERSION__: string; const __SVELTEKIT_APP_VERSION_FILE__: string; const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number; const __SVELTEKIT_DEV__: boolean; }