-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
internal.d.ts
306 lines (266 loc) · 6.39 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
import { OutputAsset, OutputChunk } from 'rollup';
import { SvelteComponent } from 'svelte/internal';
import {
Action,
Config,
ExternalFetch,
ServerLoad,
Handle,
HandleError,
KitConfig,
Load,
RequestEvent,
RequestHandler,
ResolveOptions,
Server,
ServerInitOptions,
SSRManifest
} from './index.js';
import { HttpMethod, MaybePromise, 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<string, HttpMethod[]>;
vite_manifest: import('vite').Manifest;
};
}
export interface CSRPageNode {
component: typeof SvelteComponent;
shared: {
load: Load;
hydrate: boolean;
router: boolean;
};
server: boolean;
}
export type CSRPageNodeLoader = () => Promise<CSRPageNode>;
export type CSRRoute = {
id: string;
exec: (path: string) => undefined | Record<string, string>;
errors: CSRPageNodeLoader[];
layouts: CSRPageNodeLoader[];
leaf: CSRPageNodeLoader;
uses_server_data: boolean;
};
export interface EndpointData {
type: 'endpoint';
id: string;
pattern: RegExp;
file: string;
}
export type GetParams = (match: RegExpExecArray) => Record<string, string>;
export interface Hooks {
externalFetch: ExternalFetch;
handle: Handle;
handleError: HandleError;
}
export interface ImportNode {
name: string;
dynamic: boolean;
}
export class InternalServer extends Server {
init(options: ServerInitOptions): 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 MethodOverride {
parameter: string;
allowed: string[];
}
export interface PageNode {
component?: string; // TODO supply default component if it's missing (bit of an edge case)
shared?: string;
server?: string;
}
export interface PageData {
type: 'page';
id: string;
pattern: RegExp;
errors: Array<PageNode | undefined>;
layouts: Array<PageNode | undefined>;
leaf: PageNode;
}
export type PayloadScriptAttributes =
| { type: 'data'; url: string; body?: string }
| { type: 'server_data' }
| { type: 'validation_errors' };
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>;
}
export type RouteData = PageData | EndpointData;
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 SSREndpoint {
type: 'endpoint';
id: string;
pattern: RegExp;
names: string[];
types: string[];
load(): Promise<Partial<Record<HttpMethod, RequestHandler>>>;
}
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;
hydrate?: boolean;
prerender?: boolean;
router?: boolean;
ssr?: boolean;
};
server: {
load?: ServerLoad;
HEAD?: ServerLoad;
POST?: Action;
PATCH?: Action;
PUT?: Action;
DELETE?: Action;
};
}
export type SSRNodeLoader = () => Promise<SSRNode>;
export interface SSROptions {
csp: ValidatedConfig['kit']['csp'];
dev: boolean;
get_stack: (error: Error) => string | undefined;
handle_error(error: Error & { frame?: string }, event: RequestEvent): void;
hooks: Hooks;
hydrate: boolean;
manifest: SSRManifest;
method_override: MethodOverride;
paths: {
base: string;
assets: string;
};
prerender: {
default: boolean;
enabled: boolean;
};
public_env: Record<string, string>;
read(file: string): Buffer;
root: SSRComponent['default'];
router: boolean;
service_worker?: string;
template({
head,
body,
assets,
nonce
}: {
head: string;
body: string;
assets: string;
nonce: string;
}): string;
template_contains_nonce: boolean;
trailing_slash: TrailingSlash;
}
export interface SSRPage {
type: 'page';
id: string;
pattern: RegExp;
names: string[];
types: string[];
errors: Array<number | undefined>;
layouts: Array<number | undefined>;
leaf: number;
}
export interface SSRErrorPage {
id: '__error';
}
export type SSRRoute = SSREndpoint | SSRPage;
export interface SSRState {
fallback?: string;
getClientAddress: () => string;
initiator?: SSRPage | SSRErrorPage;
platform?: any;
prerendering?: PrerenderOptions;
}
export type StrictBody = string | Uint8Array;
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;
}