forked from sveltejs/kit
/
internal.d.ts
379 lines (331 loc) · 8.07 KB
/
internal.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
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;
app_path: 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<string, HttpMethod[]>;
vite_manifest: import('vite').Manifest;
};
}
export interface CSRPageNode {
component: typeof SvelteComponent;
shared: {
load?: Load;
};
server: boolean;
}
export type CSRPageNodeLoader = () => Promise<CSRPageNode>;
/**
* 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<string, string>;
errors: Array<CSRPageNodeLoader | undefined>;
layouts: Array<[boolean, CSRPageNodeLoader] | undefined>;
leaf: [boolean, CSRPageNodeLoader];
};
export type GetParams = (match: RegExpExecArray) => Record<string, string>;
export interface ServerHooks {
handleFetch: HandleFetch;
handle: Handle;
handleError: HandleServerError;
}
export interface ClientHooks {
handleError: HandleClientError;
}
export class InternalServer extends Server {
init(options: ServerInitOptions): Promise<void>;
respond(
request: Request,
options: RequestOptions & {
prerendering?: PrerenderOptions;
}
): Promise<Response>;
}
export interface ManifestData {
assets: Asset[];
nodes: PageNode[];
routes: RouteData[];
matchers: Record<string, string>;
}
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 <meta http-equiv>
fallback?: boolean;
dependencies: Map<string, PrerenderDependency>;
}
export type RecursiveRequired<T> = {
// Recursive implementation of TypeScript's Required utility type.
// Will recursively continue until it reaches a primitive or Function
[K in keyof T]-?: Extract<T[K], Function> extends never // If it does not have a Function type
? RecursiveRequired<T[K]> // recursively continue through.
: T[K]; // Use the exact type for everything else
};
export type RequiredResolveOptions = Required<ResolveOptions>;
export interface Respond {
(request: Request, options: SSROptions, state: SSRState): Promise<Response>;
}
/**
* 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<number | undefined>;
errors: Array<number | undefined>;
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<ServerDataNode | ServerDataSkippedNode | ServerErrorNode | null>;
};
/**
* 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<string, any> | 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.Error;
/**
* Only set for HttpErrors
*/
status?: number;
}
export interface SSRComponent {
default: {
render(props: Record<string, any>): {
html: string;
head: string;
css: {
code: string;
map: any; // TODO
};
};
};
}
export type SSRComponentLoader = () => Promise<SSRComponent>;
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<Record<string, string>>;
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<SSRNode>;
export interface SSROptions {
csp: ValidatedConfig['kit']['csp'];
csrf: {
check_origin: boolean;
};
dev: boolean;
handle_error(error: Error & { frame?: string }, event: RequestEvent): App.Error;
hooks: ServerHooks;
manifest: SSRManifest;
paths: {
base: string;
assets: string;
};
public_env: Record<string, string>;
read(file: string): Buffer;
root: SSRComponent['default'];
service_worker: boolean;
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<number | undefined>;
layouts: Array<number | undefined>;
leaf: number;
}
export type SSREndpoint = Partial<Record<HttpMethod, RequestHandler>> & {
prerender?: PrerenderOption;
};
export interface SSRRoute {
id: string;
pattern: RegExp;
names: string[];
types: string[];
page: PageNodeIndexes | null;
endpoint: (() => Promise<SSREndpoint>) | 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<string>;
params: Set<string>;
parent: boolean;
url: boolean;
}
export type ValidatedConfig = RecursiveRequired<Config>;
export type ValidatedKitConfig = RecursiveRequired<KitConfig>;
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;
}