Skip to content

Commit 7bd56c5

Browse files
committed
[chore] export App types
1 parent 5e36256 commit 7bd56c5

File tree

10 files changed

+58
-51
lines changed

10 files changed

+58
-51
lines changed

.changeset/nice-ways-search.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[chore] export App types

packages/kit/src/core/adapt/prerender.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
105105

106106
const server_root = resolve_path(dir);
107107

108-
/** @type {import('types/internal').App} */
108+
/** @type {import('types/app').App} */
109109
const app = await import(pathToFileURL(`${server_root}/server/app.js`).href);
110110

111111
app.init({

packages/kit/src/core/preview/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function preview({
3434

3535
const app_file = resolve(cwd, `${SVELTE_KIT}/output/server/app.js`);
3636

37-
/** @type {import('types/internal').App} */
37+
/** @type {import('types/app').App} */
3838
const app = await import(pathToFileURL(app_file).href);
3939

4040
/** @type {import('sirv').RequestHandler} */

packages/kit/src/runtime/server/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { coalesce_to_error } from '../utils.js';
88
import { hash } from '../hash.js';
99

1010
/**
11-
* @param {import('types/internal').Incoming} incoming
11+
* @param {import('types/app').IncomingRequest} incoming
1212
* @param {import('types/internal').SSRRenderOptions} options
1313
* @param {import('types/internal').SSRRenderState} [state]
1414
*/

packages/kit/types/app.d.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Headers, RawBody } from './helper';
2+
import { ServerResponse } from './hooks';
3+
4+
export interface IncomingRequest {
5+
method: string;
6+
host: string;
7+
path: string;
8+
query: URLSearchParams;
9+
headers: Headers;
10+
rawBody: RawBody;
11+
}
12+
13+
export interface App {
14+
init({
15+
paths,
16+
prerendering,
17+
read
18+
}: {
19+
paths: {
20+
base: string;
21+
assets: string;
22+
};
23+
prerendering: boolean;
24+
read(file: string): Buffer;
25+
}): void;
26+
render(
27+
incoming: IncomingRequest,
28+
options?: {
29+
prerender: {
30+
fallback?: string;
31+
all: boolean;
32+
dependencies?: Map<string, ServerResponse>;
33+
};
34+
}
35+
): Promise<ServerResponse>;
36+
}

packages/kit/types/helper.d.ts

-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ export type ParameterizedBody<Body = unknown> = Body extends FormData
1919
// but this can't happen until TypeScript 4.3
2020
export type Headers = Record<string, string>;
2121

22-
export type Location<Params extends Record<string, string> = Record<string, string>> = {
23-
host: string;
24-
path: string;
25-
params: Params;
26-
query: URLSearchParams;
27-
};
28-
2922
export type InferValue<T, Key extends keyof T, Default> = T extends Record<Key, infer Val>
3023
? Val
3124
: Default;

packages/kit/types/hooks.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Headers, Location, MaybePromise, ParameterizedBody, RawBody } from './helper';
1+
import { IncomingRequest } from './app';
2+
import { Headers, MaybePromise, ParameterizedBody } from './helper';
23

34
export type StrictBody = string | Uint8Array;
45

5-
export interface ServerRequest<Locals = Record<string, any>, Body = unknown> extends Location {
6-
method: string;
7-
headers: Headers;
8-
rawBody: RawBody;
6+
export interface ServerRequest<Locals = Record<string, any>, Body = unknown>
7+
extends IncomingRequest {
8+
params: Record<string, string>;
99
body: ParameterizedBody<Body>;
1010
locals: Locals;
1111
}

packages/kit/types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import './ambient-modules';
55

6+
export { App, IncomingRequest } from './app';
67
export { Adapter, AdapterUtils, Config, PrerenderErrorHandler, ValidatedConfig } from './config';
78
export { EndpointOutput, RequestHandler } from './endpoint';
89
export { ErrorLoad, ErrorLoadInput, Load, LoadInput, LoadOutput, Page } from './page';

packages/kit/types/internal.d.ts

-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { RequestHandler } from './endpoint';
2-
import { Headers, Location, ParameterizedBody, RawBody } from './helper';
32
import {
43
ExternalFetch,
54
GetSession,
@@ -12,13 +11,6 @@ import { Load } from './page';
1211

1312
type PageId = string;
1413

15-
export interface Incoming extends Omit<Location, 'params'> {
16-
method: string;
17-
headers: Headers;
18-
rawBody: RawBody;
19-
body?: ParameterizedBody;
20-
}
21-
2214
export interface Logger {
2315
(msg: string): void;
2416
success(msg: string): void;
@@ -28,31 +20,6 @@ export interface Logger {
2820
info(msg: string): void;
2921
}
3022

31-
export interface App {
32-
init({
33-
paths,
34-
prerendering,
35-
read
36-
}: {
37-
paths: {
38-
base: string;
39-
assets: string;
40-
};
41-
prerendering: boolean;
42-
read(file: string): Buffer;
43-
}): void;
44-
render(
45-
incoming: Incoming,
46-
options?: {
47-
prerender: {
48-
fallback?: string;
49-
all: boolean;
50-
dependencies?: Map<string, ServerResponse>;
51-
};
52-
}
53-
): Promise<ServerResponse>;
54-
}
55-
5623
export interface SSRComponent {
5724
ssr?: boolean;
5825
router?: boolean;

packages/kit/types/page.d.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { InferValue, Location as Page, MaybePromise, Rec } from './helper';
1+
import { InferValue, MaybePromise, Rec } from './helper';
2+
3+
export interface Page<Params extends Record<string, string> = Record<string, string>> {
4+
host: string;
5+
path: string;
6+
params: Params;
7+
query: URLSearchParams;
8+
}
29

310
export interface LoadInput<
411
PageParams extends Rec<string> = Rec<string>,
@@ -68,5 +75,3 @@ export interface ErrorLoad<
6875
>
6976
): MaybePromise<LoadOutput<InferValue<Output, 'props', Rec>, InferValue<Output, 'context', Rec>>>;
7077
}
71-
72-
export { Page };

0 commit comments

Comments
 (0)