@sveltejs/kit 1.0.0-next.55 → 1.0.0-next.550

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +5 -2
  2. package/package.json +93 -67
  3. package/postinstall.js +47 -0
  4. package/scripts/special-types/$env+dynamic+private.md +10 -0
  5. package/scripts/special-types/$env+dynamic+public.md +8 -0
  6. package/scripts/special-types/$env+static+private.md +19 -0
  7. package/scripts/special-types/$env+static+public.md +7 -0
  8. package/scripts/special-types/$lib.md +5 -0
  9. package/src/cli.js +108 -0
  10. package/src/constants.js +5 -0
  11. package/src/core/adapt/builder.js +212 -0
  12. package/src/core/adapt/index.js +31 -0
  13. package/src/core/config/default-error.html +56 -0
  14. package/src/core/config/index.js +110 -0
  15. package/src/core/config/options.js +516 -0
  16. package/src/core/config/types.d.ts +1 -0
  17. package/src/core/env.js +121 -0
  18. package/src/core/generate_manifest/index.js +125 -0
  19. package/src/core/prerender/crawl.js +207 -0
  20. package/src/core/prerender/entities.js +2252 -0
  21. package/src/core/prerender/prerender.js +460 -0
  22. package/src/core/prerender/queue.js +80 -0
  23. package/src/core/sync/create_manifest_data/conflict.js +0 -0
  24. package/src/core/sync/create_manifest_data/index.js +513 -0
  25. package/src/core/sync/create_manifest_data/sort.js +161 -0
  26. package/src/core/sync/create_manifest_data/types.d.ts +37 -0
  27. package/src/core/sync/sync.js +78 -0
  28. package/src/core/sync/utils.js +33 -0
  29. package/src/core/sync/write_ambient.js +53 -0
  30. package/src/core/sync/write_client_manifest.js +106 -0
  31. package/src/core/sync/write_matchers.js +25 -0
  32. package/src/core/sync/write_root.js +91 -0
  33. package/src/core/sync/write_tsconfig.js +195 -0
  34. package/src/core/sync/write_types/index.js +809 -0
  35. package/src/core/utils.js +67 -0
  36. package/src/exports/hooks/index.js +1 -0
  37. package/src/exports/hooks/sequence.js +44 -0
  38. package/src/exports/index.js +45 -0
  39. package/src/exports/node/index.js +172 -0
  40. package/src/exports/node/polyfills.js +28 -0
  41. package/src/exports/vite/build/build_server.js +384 -0
  42. package/src/exports/vite/build/build_service_worker.js +92 -0
  43. package/src/exports/vite/build/utils.js +195 -0
  44. package/src/exports/vite/dev/index.js +588 -0
  45. package/src/exports/vite/graph_analysis/index.js +107 -0
  46. package/src/exports/vite/graph_analysis/types.d.ts +5 -0
  47. package/src/exports/vite/graph_analysis/utils.js +6 -0
  48. package/src/exports/vite/index.js +651 -0
  49. package/src/exports/vite/preview/index.js +193 -0
  50. package/src/exports/vite/types.d.ts +3 -0
  51. package/src/exports/vite/utils.js +171 -0
  52. package/src/runtime/app/env.js +1 -0
  53. package/src/runtime/app/environment.js +11 -0
  54. package/src/runtime/app/forms.js +141 -0
  55. package/src/runtime/app/navigation.js +23 -0
  56. package/src/runtime/app/paths.js +1 -0
  57. package/src/runtime/app/stores.js +102 -0
  58. package/src/runtime/client/ambient.d.ts +30 -0
  59. package/src/runtime/client/client.js +1726 -0
  60. package/src/runtime/client/fetcher.js +121 -0
  61. package/src/runtime/client/parse.js +60 -0
  62. package/src/runtime/client/singletons.js +21 -0
  63. package/src/runtime/client/start.js +43 -0
  64. package/src/runtime/client/types.d.ts +84 -0
  65. package/src/runtime/client/utils.js +166 -0
  66. package/src/runtime/components/error.svelte +16 -0
  67. package/{assets → src/runtime}/components/layout.svelte +0 -0
  68. package/src/runtime/control.js +98 -0
  69. package/src/runtime/env/dynamic/private.js +1 -0
  70. package/src/runtime/env/dynamic/public.js +1 -0
  71. package/src/runtime/env-private.js +6 -0
  72. package/src/runtime/env-public.js +6 -0
  73. package/src/runtime/env.js +6 -0
  74. package/src/runtime/hash.js +20 -0
  75. package/src/runtime/paths.js +11 -0
  76. package/src/runtime/server/cookie.js +231 -0
  77. package/src/runtime/server/data/index.js +144 -0
  78. package/src/runtime/server/endpoint.js +89 -0
  79. package/src/runtime/server/fetch.js +164 -0
  80. package/src/runtime/server/index.js +375 -0
  81. package/src/runtime/server/page/actions.js +258 -0
  82. package/src/runtime/server/page/crypto.js +239 -0
  83. package/src/runtime/server/page/csp.js +250 -0
  84. package/src/runtime/server/page/index.js +303 -0
  85. package/src/runtime/server/page/load_data.js +258 -0
  86. package/src/runtime/server/page/render.js +391 -0
  87. package/src/runtime/server/page/respond_with_error.js +102 -0
  88. package/src/runtime/server/page/serialize_data.js +87 -0
  89. package/src/runtime/server/page/types.d.ts +35 -0
  90. package/src/runtime/server/utils.js +205 -0
  91. package/src/utils/array.js +9 -0
  92. package/src/utils/error.js +22 -0
  93. package/src/utils/escape.js +46 -0
  94. package/src/utils/filesystem.js +166 -0
  95. package/src/utils/functions.js +16 -0
  96. package/src/utils/http.js +72 -0
  97. package/src/utils/misc.js +1 -0
  98. package/src/utils/promises.js +17 -0
  99. package/src/utils/routing.js +168 -0
  100. package/src/utils/unit_test.js +11 -0
  101. package/src/utils/url.js +159 -0
  102. package/svelte-kit.js +1 -1
  103. package/types/ambient.d.ts +469 -0
  104. package/types/index.d.ts +775 -0
  105. package/types/internal.d.ts +381 -0
  106. package/types/private.d.ts +229 -0
  107. package/CHANGELOG.md +0 -519
  108. package/assets/components/error.svelte +0 -13
  109. package/assets/runtime/app/env.js +0 -5
  110. package/assets/runtime/app/navigation.js +0 -48
  111. package/assets/runtime/app/paths.js +0 -1
  112. package/assets/runtime/app/stores.js +0 -93
  113. package/assets/runtime/chunks/utils.js +0 -22
  114. package/assets/runtime/internal/singletons.js +0 -23
  115. package/assets/runtime/internal/start.js +0 -823
  116. package/assets/runtime/paths.js +0 -12
  117. package/dist/chunks/index.js +0 -3544
  118. package/dist/chunks/index2.js +0 -572
  119. package/dist/chunks/index3.js +0 -246
  120. package/dist/chunks/index4.js +0 -569
  121. package/dist/chunks/index5.js +0 -751
  122. package/dist/chunks/index6.js +0 -323
  123. package/dist/chunks/standard.js +0 -99
  124. package/dist/chunks/utils.js +0 -83
  125. package/dist/cli.js +0 -558
  126. package/dist/ssr.js +0 -2620
  127. package/types.d.ts +0 -74
  128. package/types.internal.d.ts +0 -237
@@ -0,0 +1,775 @@
1
+ /// <reference types="svelte" />
2
+ /// <reference types="vite/client" />
3
+
4
+ import './ambient.js';
5
+
6
+ import { CompileOptions } from 'svelte/types/compiler/interfaces';
7
+ import {
8
+ AdapterEntry,
9
+ CspDirectives,
10
+ Logger,
11
+ MaybePromise,
12
+ Prerendered,
13
+ PrerenderHttpErrorHandlerValue,
14
+ PrerenderMissingIdHandlerValue,
15
+ RequestOptions,
16
+ RouteDefinition,
17
+ TrailingSlash,
18
+ UniqueInterface
19
+ } from './private.js';
20
+ import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
21
+ import { HttpError, Redirect } from '../src/runtime/control.js';
22
+
23
+ export { PrerenderOption } from './private.js';
24
+
25
+ export interface Adapter {
26
+ name: string;
27
+ adapt(builder: Builder): MaybePromise<void>;
28
+ }
29
+
30
+ type AwaitedPropertiesUnion<input extends Record<string, any> | void> = input extends void
31
+ ? undefined // needs to be undefined, because void will break intellisense
32
+ : input extends Record<string, any>
33
+ ? {
34
+ [key in keyof input]: Awaited<input[key]>;
35
+ }
36
+ : {} extends input // handles the any case
37
+ ? input
38
+ : unknown;
39
+
40
+ export type AwaitedProperties<input extends Record<string, any> | void> =
41
+ AwaitedPropertiesUnion<input> extends Record<string, any>
42
+ ? OptionalUnion<AwaitedPropertiesUnion<input>>
43
+ : AwaitedPropertiesUnion<input>;
44
+
45
+ export type AwaitedActions<T extends Record<string, (...args: any) => any>> = {
46
+ [Key in keyof T]: OptionalUnion<UnpackValidationError<Awaited<ReturnType<T[Key]>>>>;
47
+ }[keyof T];
48
+
49
+ // Takes a union type and returns a union type where each type also has all properties
50
+ // of all possible types (typed as undefined), making accessing them more ergonomic
51
+ type OptionalUnion<
52
+ U extends Record<string, any>, // not unknown, else interfaces don't satisfy this constraint
53
+ A extends keyof U = U extends U ? keyof U : never
54
+ > = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;
55
+
56
+ // Needs to be here, else ActionData will be resolved to unknown - probably because of "d.ts file imports .js file" in combination with allowJs
57
+ export interface ValidationError<T extends Record<string, unknown> | undefined = undefined>
58
+ extends UniqueInterface {
59
+ status: number;
60
+ data: T;
61
+ }
62
+
63
+ type UnpackValidationError<T> = T extends ValidationError<infer X>
64
+ ? X
65
+ : T extends void
66
+ ? undefined // needs to be undefined, because void will corrupt union type
67
+ : T;
68
+
69
+ export interface Builder {
70
+ log: Logger;
71
+ rimraf(dir: string): void;
72
+ mkdirp(dir: string): void;
73
+
74
+ config: ValidatedConfig;
75
+ prerendered: Prerendered;
76
+
77
+ /**
78
+ * Create entry points that map to individual functions
79
+ * @param fn A function that groups a set of routes into an entry point
80
+ */
81
+ createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
82
+
83
+ generateManifest(opts: { relativePath: string; format?: 'esm' | 'cjs' }): string;
84
+
85
+ getBuildDirectory(name: string): string;
86
+ getClientDirectory(): string;
87
+ getServerDirectory(): string;
88
+ getStaticDirectory(): string;
89
+ /** The application path including any configured base path */
90
+ getAppPath(): string;
91
+
92
+ /**
93
+ * @param dest the destination folder to which files should be copied
94
+ * @returns an array of paths corresponding to the files that have been created by the copy
95
+ */
96
+ writeClient(dest: string): string[];
97
+ /**
98
+ * @param dest
99
+ */
100
+ writePrerendered(
101
+ dest: string,
102
+ opts?: {
103
+ fallback?: string;
104
+ }
105
+ ): string[];
106
+ /**
107
+ * @param dest the destination folder to which files should be copied
108
+ * @returns an array of paths corresponding to the files that have been created by the copy
109
+ */
110
+ writeServer(dest: string): string[];
111
+ /**
112
+ * @param from the source file or folder
113
+ * @param to the destination file or folder
114
+ * @param opts.filter a function to determine whether a file or folder should be copied
115
+ * @param opts.replace a map of strings to replace
116
+ * @returns an array of paths corresponding to the files that have been created by the copy
117
+ */
118
+ copy(
119
+ from: string,
120
+ to: string,
121
+ opts?: {
122
+ filter?(basename: string): boolean;
123
+ replace?: Record<string, string>;
124
+ }
125
+ ): string[];
126
+
127
+ /**
128
+ * @param {string} directory Path to the directory containing the files to be compressed
129
+ */
130
+ compress(directory: string): Promise<void>;
131
+ }
132
+
133
+ export interface Config {
134
+ compilerOptions?: CompileOptions;
135
+ extensions?: string[];
136
+ kit?: KitConfig;
137
+ package?: {
138
+ source?: string;
139
+ dir?: string;
140
+ emitTypes?: boolean;
141
+ exports?(filepath: string): boolean;
142
+ files?(filepath: string): boolean;
143
+ };
144
+ preprocess?: any;
145
+ [key: string]: any;
146
+ }
147
+
148
+ export interface Cookies {
149
+ /**
150
+ * Gets a cookie that was previously set with `cookies.set`, or from the request headers.
151
+ */
152
+ get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
153
+
154
+ /**
155
+ * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` during the current request.
156
+ *
157
+ * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP. The `sameSite` option defaults to `lax`.
158
+ *
159
+ * By default, the `path` of a cookie is the 'directory' of the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app.
160
+ */
161
+ set(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): void;
162
+
163
+ /**
164
+ * Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
165
+ *
166
+ * By default, the `path` of a cookie is the 'directory' of the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app.
167
+ */
168
+ delete(name: string, opts?: import('cookie').CookieSerializeOptions): void;
169
+
170
+ /**
171
+ * Serialize a cookie name-value pair into a Set-Cookie header string.
172
+ *
173
+ * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP. The `sameSite` option defaults to `lax`.
174
+ *
175
+ * By default, the `path` of a cookie is the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app.
176
+ *
177
+ * @param name the name for the cookie
178
+ * @param value value to set the cookie to
179
+ * @param options object containing serialization options
180
+ */
181
+ serialize(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): string;
182
+ }
183
+
184
+ export interface KitConfig {
185
+ adapter?: Adapter;
186
+ alias?: Record<string, string>;
187
+ appDir?: string;
188
+ csp?: {
189
+ mode?: 'hash' | 'nonce' | 'auto';
190
+ directives?: CspDirectives;
191
+ reportOnly?: CspDirectives;
192
+ };
193
+ csrf?: {
194
+ checkOrigin?: boolean;
195
+ };
196
+ env?: {
197
+ dir?: string;
198
+ publicPrefix?: string;
199
+ };
200
+ moduleExtensions?: string[];
201
+ files?: {
202
+ assets?: string;
203
+ hooks?: {
204
+ client?: string;
205
+ server?: string;
206
+ };
207
+ lib?: string;
208
+ params?: string;
209
+ routes?: string;
210
+ serviceWorker?: string;
211
+ appTemplate?: string;
212
+ errorTemplate?: string;
213
+ };
214
+ inlineStyleThreshold?: number;
215
+ outDir?: string;
216
+ paths?: {
217
+ assets?: string;
218
+ base?: string;
219
+ };
220
+ prerender?: {
221
+ concurrency?: number;
222
+ crawl?: boolean;
223
+ default?: boolean;
224
+ enabled?: boolean;
225
+ entries?: Array<'*' | `/${string}`>;
226
+ handleHttpError?: PrerenderHttpErrorHandlerValue;
227
+ handleMissingId?: PrerenderMissingIdHandlerValue;
228
+ origin?: string;
229
+ };
230
+ serviceWorker?: {
231
+ register?: boolean;
232
+ files?(filepath: string): boolean;
233
+ };
234
+ trailingSlash?: TrailingSlash;
235
+ version?: {
236
+ name?: string;
237
+ pollInterval?: number;
238
+ };
239
+ }
240
+
241
+ /**
242
+ * This function runs every time the SvelteKit server receives a [request](https://kit.svelte.dev/docs/web-standards#fetch-apis-request) and
243
+ * determines the [response](https://kit.svelte.dev/docs/web-standards#fetch-apis-response).
244
+ * It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
245
+ * This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
246
+ */
247
+ export interface Handle {
248
+ (input: {
249
+ event: RequestEvent;
250
+ resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
251
+ }): MaybePromise<Response>;
252
+ }
253
+
254
+ export interface HandleServerError {
255
+ (input: { error: unknown; event: RequestEvent }): void | App.Error;
256
+ }
257
+
258
+ export interface HandleClientError {
259
+ (input: { error: unknown; event: NavigationEvent }): void | App.Error;
260
+ }
261
+
262
+ export interface HandleFetch {
263
+ (input: { event: RequestEvent; request: Request; fetch: typeof fetch }): MaybePromise<Response>;
264
+ }
265
+
266
+ /**
267
+ * The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
268
+ * rather than using `Load` directly.
269
+ */
270
+ export interface Load<
271
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
272
+ InputData extends Record<string, unknown> | null = Record<string, any> | null,
273
+ ParentData extends Record<string, unknown> = Record<string, any>,
274
+ OutputData extends Record<string, unknown> | void = Record<string, any> | void,
275
+ RouteId extends string | null = string | null
276
+ > {
277
+ (event: LoadEvent<Params, InputData, ParentData, RouteId>): MaybePromise<OutputData>;
278
+ }
279
+
280
+ export interface LoadEvent<
281
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
282
+ Data extends Record<string, unknown> | null = Record<string, any> | null,
283
+ ParentData extends Record<string, unknown> = Record<string, any>,
284
+ RouteId extends string | null = string | null
285
+ > extends NavigationEvent<Params, RouteId> {
286
+ /**
287
+ * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
288
+ *
289
+ * - it can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request
290
+ * - it can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context)
291
+ * - internal requests (e.g. for `+server.js` routes) go directly to the handler function when running on the server, without the overhead of an HTTP call
292
+ * - during server-side rendering, the response will be captured and inlined into the rendered HTML. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://kit.svelte.dev/docs/hooks#server-hooks-handle)
293
+ * - during hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request
294
+ *
295
+ * > Cookies will only be passed through if the target host is the same as the SvelteKit application or a more specific subdomain of it.
296
+ */
297
+ fetch: typeof fetch;
298
+ /**
299
+ * Contains the data returned by the route's server `load` function (in `+layout.server.js` or `+page.server.js`), if any.
300
+ */
301
+ data: Data;
302
+ /**
303
+ * If you need to set headers for the response, you can do so using the this method. This is useful if you want the page to be cached, for example:
304
+ *
305
+ * ```js
306
+ * /// file: src/routes/blog/+page.js
307
+ * export async function load({ fetch, setHeaders }) {
308
+ * const url = `https://cms.example.com/articles.json`;
309
+ * const response = await fetch(url);
310
+ *
311
+ * setHeaders({
312
+ * age: response.headers.get('age'),
313
+ * 'cache-control': response.headers.get('cache-control')
314
+ * });
315
+ *
316
+ * return response.json();
317
+ * }
318
+ * ```
319
+ *
320
+ * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
321
+ *
322
+ * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#sveltejs-kit-cookies) API in a server-only `load` function instead.
323
+ *
324
+ * `setHeaders` has no effect when a `load` function runs in the browser.
325
+ */
326
+ setHeaders(headers: Record<string, string>): void;
327
+ /**
328
+ * `await parent()` returns data from parent `+layout.js` `load` functions.
329
+ * Implicitly, a missing `+layout.js` is treated as a `({ data }) => data` function, meaning that it will return and forward data from parent `+layout.server.js` files.
330
+ *
331
+ * Be careful not to introduce accidental waterfalls when using `await parent()`. If for example you only want to merge parent data into the returned output, call it _after_ fetching your other data.
332
+ */
333
+ parent(): Promise<ParentData>;
334
+ /**
335
+ * This function declares that the `load` function has a _dependency_ on one or more URLs or custom identifiers, which can subsequently be used with [`invalidate()`](/docs/modules#$app-navigation-invalidate) to cause `load` to rerun.
336
+ *
337
+ * Most of the time you won't need this, as `fetch` calls `depends` on your behalf — it's only necessary if you're using a custom API client that bypasses `fetch`.
338
+ *
339
+ * URLs can be absolute or relative to the page being loaded, and must be [encoded](https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding).
340
+ *
341
+ * Custom identifiers have to be prefixed with one or more lowercase letters followed by a colon to conform to the [URI specification](https://www.rfc-editor.org/rfc/rfc3986.html).
342
+ *
343
+ * The following example shows how to use `depends` to register a dependency on a custom identifier, which is `invalidate`d after a button click, making the `load` function rerun.
344
+ *
345
+ * ```js
346
+ * /// file: src/routes/+page.js
347
+ * let count = 0;
348
+ * export async function load({ depends }) {
349
+ * depends('increase:count');
350
+ *
351
+ * return { count: count++ };
352
+ * }
353
+ * ```
354
+ *
355
+ * ```html
356
+ * /// file: src/routes/+page.svelte
357
+ * <script>
358
+ * import { invalidate } from '$app/navigation';
359
+ *
360
+ * export let data;
361
+ *
362
+ * const increase = async () => {
363
+ * await invalidate('increase:count');
364
+ * }
365
+ * </script>
366
+ *
367
+ * <p>{data.count}<p>
368
+ * <button on:click={increase}>Increase Count</button>
369
+ * ```
370
+ */
371
+ depends(...deps: string[]): void;
372
+ }
373
+
374
+ export interface NavigationEvent<
375
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
376
+ RouteId extends string | null = string | null
377
+ > {
378
+ /**
379
+ * The parameters of the current page - e.g. for a route like `/blog/[slug]`, the `slug` parameter
380
+ */
381
+ params: Params;
382
+ /**
383
+ * Info about the current route
384
+ */
385
+ route: {
386
+ /**
387
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
388
+ */
389
+ id: RouteId;
390
+ };
391
+ /**
392
+ * The URL of the current page
393
+ */
394
+ url: URL;
395
+ }
396
+
397
+ export interface NavigationTarget {
398
+ params: Record<string, string> | null;
399
+ route: { id: string | null };
400
+ url: URL;
401
+ }
402
+
403
+ /**
404
+ * - `enter`: The app has hydrated
405
+ * - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
406
+ * - `link`: Navigation was triggered by a link click
407
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
408
+ * - `popstate`: Navigation was triggered by back/forward navigation
409
+ */
410
+ export type NavigationType = 'enter' | 'leave' | 'link' | 'goto' | 'popstate';
411
+
412
+ export interface Navigation {
413
+ /**
414
+ * Where navigation was triggered from
415
+ */
416
+ from: NavigationTarget | null;
417
+ /**
418
+ * Where navigation is going to/has gone to
419
+ */
420
+ to: NavigationTarget | null;
421
+ /**
422
+ * The type of navigation:
423
+ * - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
424
+ * - `link`: Navigation was triggered by a link click
425
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
426
+ * - `popstate`: Navigation was triggered by back/forward navigation
427
+ */
428
+ type: Omit<NavigationType, 'enter'>;
429
+ /**
430
+ * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation)
431
+ */
432
+ willUnload: boolean;
433
+ /**
434
+ * In case of a history back/forward navigation, the number of steps to go back/forward
435
+ */
436
+ delta?: number;
437
+ }
438
+
439
+ /**
440
+ * The interface that corresponds to the `beforeNavigate`'s input parameter.
441
+ */
442
+ export interface BeforeNavigate extends Navigation {
443
+ /**
444
+ * Call this to prevent the navigation from starting.
445
+ */
446
+ cancel(): void;
447
+ }
448
+
449
+ /**
450
+ * The interface that corresponds to the `afterNavigate`'s input parameter.
451
+ */
452
+ export interface AfterNavigate extends Navigation {
453
+ /**
454
+ * The type of navigation:
455
+ * - `enter`: The app has hydrated
456
+ * - `link`: Navigation was triggered by a link click
457
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
458
+ * - `popstate`: Navigation was triggered by back/forward navigation
459
+ */
460
+ type: Omit<NavigationType, 'leave'>;
461
+ willUnload: false;
462
+ }
463
+
464
+ /**
465
+ * The shape of the `$page` store
466
+ */
467
+ export interface Page<
468
+ Params extends Record<string, string> = Record<string, string>,
469
+ RouteId extends string | null = string | null
470
+ > {
471
+ /**
472
+ * The URL of the current page
473
+ */
474
+ url: URL;
475
+ /**
476
+ * The parameters of the current page - e.g. for a route like `/blog/[slug]`, the `slug` parameter
477
+ */
478
+ params: Params;
479
+ /**
480
+ * Info about the current route
481
+ */
482
+ route: {
483
+ /**
484
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
485
+ */
486
+ id: RouteId;
487
+ };
488
+ /**
489
+ * Http status code of the current page
490
+ */
491
+ status: number;
492
+ /**
493
+ * The error object of the current page, if any. Filled from the `handleError` hooks.
494
+ */
495
+ error: App.Error | null;
496
+ /**
497
+ * The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
498
+ */
499
+ data: App.PageData & Record<string, any>;
500
+ /**
501
+ * Filled only after a form submission. See [form actions](https://kit.svelte.dev/docs/form-actions) for more info.
502
+ */
503
+ form: any;
504
+ }
505
+
506
+ export interface ParamMatcher {
507
+ (param: string): boolean;
508
+ }
509
+
510
+ export interface RequestEvent<
511
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
512
+ RouteId extends string | null = string | null
513
+ > {
514
+ /**
515
+ * Get or set cookies related to the current request
516
+ */
517
+ cookies: Cookies;
518
+ /**
519
+ * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
520
+ *
521
+ * - it can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request
522
+ * - it can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context)
523
+ * - internal requests (e.g. for `+server.js` routes) go directly to the handler function when running on the server, without the overhead of an HTTP call
524
+ *
525
+ * > Cookies will only be passed through if the target host is the same as the SvelteKit application or a more specific subdomain of it.
526
+ */
527
+ fetch: typeof fetch;
528
+ /**
529
+ * The client's IP address, set by the adapter.
530
+ */
531
+ getClientAddress(): string;
532
+ /**
533
+ * Contains custom data that was added to the request within the [`handle hook`](https://kit.svelte.dev/docs/hooks#server-hooks-handle).
534
+ */
535
+ locals: App.Locals;
536
+ /**
537
+ * The parameters of the current page or endpoint - e.g. for a route like `/blog/[slug]`, the `slug` parameter
538
+ */
539
+ params: Params;
540
+ /**
541
+ * Additional data made available through the adapter.
542
+ */
543
+ platform: Readonly<App.Platform>;
544
+ /**
545
+ * The original request object
546
+ */
547
+ request: Request;
548
+ /**
549
+ * Info about the current route
550
+ */
551
+ route: {
552
+ /**
553
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
554
+ */
555
+ id: RouteId;
556
+ };
557
+ /**
558
+ * If you need to set headers for the response, you can do so using the this method. This is useful if you want the page to be cached, for example:
559
+ *
560
+ * ```js
561
+ * /// file: src/routes/blog/+page.js
562
+ * export async function load({ fetch, setHeaders }) {
563
+ * const url = `https://cms.example.com/articles.json`;
564
+ * const response = await fetch(url);
565
+ *
566
+ * setHeaders({
567
+ * age: response.headers.get('age'),
568
+ * 'cache-control': response.headers.get('cache-control')
569
+ * });
570
+ *
571
+ * return response.json();
572
+ * }
573
+ * ```
574
+ *
575
+ * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
576
+ *
577
+ * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#sveltejs-kit-cookies) API instead.
578
+ */
579
+ setHeaders(headers: Record<string, string>): void;
580
+ /**
581
+ * The URL of the current page or endpoint
582
+ */
583
+ url: URL;
584
+ }
585
+
586
+ /**
587
+ * A `(event: RequestEvent) => Response` function exported from a `+server.js` file that corresponds to an HTTP verb (`GET`, `PUT`, `PATCH`, etc) and handles requests with that method.
588
+ *
589
+ * It receives `Params` as the first generic argument, which you can skip by using [generated types](https://kit.svelte.dev/docs/types#generated-types) instead.
590
+ */
591
+ export interface RequestHandler<
592
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
593
+ RouteId extends string | null = string | null
594
+ > {
595
+ (event: RequestEvent<Params, RouteId>): MaybePromise<Response>;
596
+ }
597
+
598
+ export interface ResolveOptions {
599
+ /**
600
+ * Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
601
+ * (they could include an element's opening tag but not its closing tag, for example)
602
+ * but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
603
+ * @param input the html chunk and the info if this is the last chunk
604
+ */
605
+ transformPageChunk?(input: { html: string; done: boolean }): MaybePromise<string | undefined>;
606
+ /**
607
+ * Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
608
+ * By default, none will be included.
609
+ * @param name header name
610
+ * @param value header value
611
+ */
612
+ filterSerializedResponseHeaders?(name: string, value: string): boolean;
613
+ /**
614
+ * Determines what should be added to the `<head>` tag to preload it.
615
+ * By default, `js`, `css` and `font` files will be preloaded.
616
+ * @param input the type of the file and its path
617
+ */
618
+ preload?(input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }): boolean;
619
+ }
620
+
621
+ export class Server {
622
+ constructor(manifest: SSRManifest);
623
+ init(options: ServerInitOptions): Promise<void>;
624
+ respond(request: Request, options: RequestOptions): Promise<Response>;
625
+ }
626
+
627
+ export interface ServerInitOptions {
628
+ env: Record<string, string>;
629
+ }
630
+
631
+ export interface SSRManifest {
632
+ appDir: string;
633
+ appPath: string;
634
+ assets: Set<string>;
635
+ mimeTypes: Record<string, string>;
636
+
637
+ /** private fields */
638
+ _: {
639
+ entry: {
640
+ file: string;
641
+ imports: string[];
642
+ stylesheets: string[];
643
+ fonts: string[];
644
+ };
645
+ nodes: SSRNodeLoader[];
646
+ routes: SSRRoute[];
647
+ matchers(): Promise<Record<string, ParamMatcher>>;
648
+ };
649
+ }
650
+
651
+ /**
652
+ * The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
653
+ * rather than using `ServerLoad` directly.
654
+ */
655
+ export interface ServerLoad<
656
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
657
+ ParentData extends Record<string, any> = Record<string, any>,
658
+ OutputData extends Record<string, any> | void = Record<string, any> | void,
659
+ RouteId extends string | null = string | null
660
+ > {
661
+ (event: ServerLoadEvent<Params, ParentData, RouteId>): MaybePromise<OutputData>;
662
+ }
663
+
664
+ export interface ServerLoadEvent<
665
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
666
+ ParentData extends Record<string, any> = Record<string, any>,
667
+ RouteId extends string | null = string | null
668
+ > extends RequestEvent<Params, RouteId> {
669
+ /**
670
+ * `await parent()` returns data from parent `+layout.server.js` `load` functions.
671
+ *
672
+ * Be careful not to introduce accidental waterfalls when using `await parent()`. If for example you only want to merge parent data into the returned output, call it _after_ fetching your other data.
673
+ */
674
+ parent(): Promise<ParentData>;
675
+ /**
676
+ * This function declares that the `load` function has a _dependency_ on one or more URLs or custom identifiers, which can subsequently be used with [`invalidate()`](/docs/modules#$app-navigation-invalidate) to cause `load` to rerun.
677
+ *
678
+ * Most of the time you won't need this, as `fetch` calls `depends` on your behalf — it's only necessary if you're using a custom API client that bypasses `fetch`.
679
+ *
680
+ * URLs can be absolute or relative to the page being loaded, and must be [encoded](https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding).
681
+ *
682
+ * Custom identifiers have to be prefixed with one or more lowercase letters followed by a colon to conform to the [URI specification](https://www.rfc-editor.org/rfc/rfc3986.html).
683
+ *
684
+ * The following example shows how to use `depends` to register a dependency on a custom identifier, which is `invalidate`d after a button click, making the `load` function rerun.
685
+ *
686
+ * ```js
687
+ * /// file: src/routes/+page.js
688
+ * let count = 0;
689
+ * export async function load({ depends }) {
690
+ * depends('increase:count');
691
+ *
692
+ * return { count: count++ };
693
+ * }
694
+ * ```
695
+ *
696
+ * ```html
697
+ * /// file: src/routes/+page.svelte
698
+ * <script>
699
+ * import { invalidate } from '$app/navigation';
700
+ *
701
+ * export let data;
702
+ *
703
+ * const increase = async () => {
704
+ * await invalidate('increase:count');
705
+ * }
706
+ * </script>
707
+ *
708
+ * <p>{data.count}<p>
709
+ * <button on:click={increase}>Increase Count</button>
710
+ * ```
711
+ */
712
+ depends(...deps: string[]): void;
713
+ }
714
+
715
+ export interface Action<
716
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
717
+ OutputData extends Record<string, any> | void = Record<string, any> | void,
718
+ RouteId extends string | null = string | null
719
+ > {
720
+ (event: RequestEvent<Params, RouteId>): MaybePromise<OutputData>;
721
+ }
722
+
723
+ export type Actions<
724
+ Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
725
+ OutputData extends Record<string, any> | void = Record<string, any> | void,
726
+ RouteId extends string | null = string | null
727
+ > = Record<string, Action<Params, OutputData, RouteId>>;
728
+
729
+ /**
730
+ * When calling a form action via fetch, the response will be one of these shapes.
731
+ */
732
+ export type ActionResult<
733
+ Success extends Record<string, unknown> | undefined = Record<string, any>,
734
+ Invalid extends Record<string, unknown> | undefined = Record<string, any>
735
+ > =
736
+ | { type: 'success'; status: number; data?: Success }
737
+ | { type: 'invalid'; status: number; data?: Invalid }
738
+ | { type: 'redirect'; status: number; location: string }
739
+ | { type: 'error'; error: any };
740
+
741
+ /**
742
+ * Creates an `HttpError` object with an HTTP status code and an optional message.
743
+ * This object, if thrown during request handling, will cause SvelteKit to
744
+ * return an error response without invoking `handleError`
745
+ * @param status The HTTP status code
746
+ * @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
747
+ */
748
+ export function error(status: number, body: App.Error): HttpError;
749
+ export function error(
750
+ status: number,
751
+ // this overload ensures you can omit the argument or pass in a string if App.Error is of type { message: string }
752
+ body?: { message: string } extends App.Error ? App.Error | string | undefined : never
753
+ ): HttpError;
754
+
755
+ /**
756
+ * Creates a `Redirect` object. If thrown during request handling, SvelteKit will
757
+ * return a redirect response.
758
+ */
759
+ export function redirect(
760
+ status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308,
761
+ location: string
762
+ ): Redirect;
763
+
764
+ /**
765
+ * Generates a JSON `Response` object from the supplied data.
766
+ */
767
+ export function json(data: any, init?: ResponseInit): Response;
768
+
769
+ /**
770
+ * Generates a `ValidationError` object.
771
+ */
772
+ export function invalid<T extends Record<string, unknown> | undefined>(
773
+ status: number,
774
+ data?: T
775
+ ): ValidationError<T>;