@sveltejs/kit 1.17.1 → 1.19.0
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.
- package/package.json +6 -1
- package/src/core/adapt/builder.js +3 -3
- package/src/core/config/index.js +2 -2
- package/src/core/config/options.js +8 -3
- package/src/core/env.js +1 -1
- package/src/core/generate_manifest/index.js +2 -2
- package/src/core/postbuild/analyse.js +3 -3
- package/src/core/postbuild/fallback.js +1 -1
- package/src/core/postbuild/prerender.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +2 -2
- package/src/core/sync/write_ambient.js +1 -1
- package/src/core/sync/write_client_manifest.js +1 -1
- package/src/core/sync/write_server.js +2 -1
- package/src/core/sync/write_types/index.js +24 -24
- package/src/exports/hooks/sequence.js +71 -7
- package/src/exports/index.js +88 -12
- package/src/exports/node/index.js +14 -3
- package/src/exports/node/polyfills.js +8 -0
- package/src/exports/public.d.ts +1264 -0
- package/src/exports/vite/build/build_server.js +2 -2
- package/src/exports/vite/build/build_service_worker.js +1 -1
- package/src/exports/vite/dev/index.js +3 -3
- package/src/exports/vite/index.js +11 -6
- package/src/runtime/app/environment.js +3 -4
- package/src/runtime/app/forms.js +63 -7
- package/src/runtime/app/navigation.js +95 -0
- package/src/runtime/app/stores.js +28 -7
- package/src/runtime/client/client.js +26 -14
- package/src/runtime/client/singletons.js +6 -4
- package/src/runtime/client/start.js +1 -1
- package/src/runtime/client/types.d.ts +4 -12
- package/src/runtime/client/utils.js +29 -10
- package/src/runtime/control.js +12 -9
- package/src/runtime/server/ambient.d.ts +3 -3
- package/src/runtime/server/cookie.js +3 -3
- package/src/runtime/server/data/index.js +5 -4
- package/src/runtime/server/endpoint.js +11 -4
- package/src/runtime/server/fetch.js +4 -6
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/actions.js +13 -13
- package/src/runtime/server/page/csp.js +7 -2
- package/src/runtime/server/page/index.js +6 -5
- package/src/runtime/server/page/load_data.js +20 -9
- package/src/runtime/server/page/render.js +11 -11
- package/src/runtime/server/page/respond_with_error.js +4 -3
- package/src/runtime/server/respond.js +6 -6
- package/src/runtime/server/utils.js +7 -7
- package/src/types/ambient-private.d.ts +11 -0
- package/src/types/ambient.d.ts +108 -0
- package/{types → src/types}/internal.d.ts +4 -13
- package/{types → src/types}/private.d.ts +1 -10
- package/src/utils/error.js +3 -3
- package/src/utils/exports.js +2 -2
- package/src/utils/routing.js +1 -39
- package/src/utils/streaming.js +2 -2
- package/types/index.d.ts +2081 -1100
- package/types/index.d.ts.map +165 -0
- package/src/internal.d.ts +0 -16
- package/types/ambient.d.ts +0 -486
- /package/{types → src/types}/synthetic/$env+dynamic+private.md +0 -0
- /package/{types → src/types}/synthetic/$env+dynamic+public.md +0 -0
- /package/{types → src/types}/synthetic/$env+static+private.md +0 -0
- /package/{types → src/types}/synthetic/$env+static+public.md +0 -0
- /package/{types → src/types}/synthetic/$lib.md +0 -0
package/types/index.d.ts
CHANGED
|
@@ -1,1302 +1,2283 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
AdapterEntry,
|
|
9
|
-
CspDirectives,
|
|
10
|
-
HttpMethod,
|
|
11
|
-
Logger,
|
|
12
|
-
MaybePromise,
|
|
13
|
-
Prerendered,
|
|
14
|
-
PrerenderEntryGeneratorMismatchHandlerValue,
|
|
15
|
-
PrerenderHttpErrorHandlerValue,
|
|
16
|
-
PrerenderMissingIdHandlerValue,
|
|
17
|
-
PrerenderOption,
|
|
18
|
-
RequestOptions,
|
|
19
|
-
RouteSegment,
|
|
20
|
-
UniqueInterface
|
|
21
|
-
} from './private.js';
|
|
22
|
-
import { BuildData, SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
|
|
23
|
-
import type { PluginOptions } from '@sveltejs/vite-plugin-svelte';
|
|
24
|
-
|
|
25
|
-
export { PrerenderOption } from './private.js';
|
|
1
|
+
declare module '@sveltejs/kit' {
|
|
2
|
+
import 'svelte'; // pick up `declare module "*.svelte"`
|
|
3
|
+
import 'vite/client';
|
|
4
|
+
|
|
5
|
+
import { CompileOptions } from 'svelte/types/compiler/interfaces';
|
|
6
|
+
import type { PluginOptions } from '@sveltejs/vite-plugin-svelte';
|
|
7
|
+
export { ActionFailure };
|
|
26
8
|
|
|
27
|
-
/**
|
|
28
|
-
* [Adapters](https://kit.svelte.dev/docs/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing.
|
|
29
|
-
*/
|
|
30
|
-
export interface Adapter {
|
|
31
|
-
/**
|
|
32
|
-
* The name of the adapter, using for logging. Will typically correspond to the package name.
|
|
33
|
-
*/
|
|
34
|
-
name: string;
|
|
35
9
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @param builder An object provided by SvelteKit that contains methods for adapting the app
|
|
10
|
+
* [Adapters](https://kit.svelte.dev/docs/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing.
|
|
38
11
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
12
|
+
export interface Adapter {
|
|
13
|
+
/**
|
|
14
|
+
* The name of the adapter, using for logging. Will typically correspond to the package name.
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* This function is called after SvelteKit has built your app.
|
|
19
|
+
* */
|
|
20
|
+
adapt(builder: Builder): MaybePromise<void>;
|
|
21
|
+
}
|
|
41
22
|
|
|
42
|
-
type AwaitedPropertiesUnion<input extends Record<string, any> | void> = input extends void
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export type AwaitedProperties<input extends Record<string, any> | void> =
|
|
53
|
-
AwaitedPropertiesUnion<input> extends Record<string, any>
|
|
54
|
-
? OptionalUnion<AwaitedPropertiesUnion<input>>
|
|
55
|
-
: AwaitedPropertiesUnion<input>;
|
|
56
|
-
|
|
57
|
-
export type AwaitedActions<T extends Record<string, (...args: any) => any>> = OptionalUnion<
|
|
58
|
-
{
|
|
59
|
-
[Key in keyof T]: UnpackValidationError<Awaited<ReturnType<T[Key]>>>;
|
|
60
|
-
}[keyof T]
|
|
61
|
-
>;
|
|
62
|
-
|
|
63
|
-
// Takes a union type and returns a union type where each type also has all properties
|
|
64
|
-
// of all possible types (typed as undefined), making accessing them more ergonomic
|
|
65
|
-
type OptionalUnion<
|
|
66
|
-
U extends Record<string, any>, // not unknown, else interfaces don't satisfy this constraint
|
|
67
|
-
A extends keyof U = U extends U ? keyof U : never
|
|
68
|
-
> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;
|
|
69
|
-
|
|
70
|
-
type UnpackValidationError<T> = T extends ActionFailure<infer X>
|
|
71
|
-
? X
|
|
72
|
-
: T extends void
|
|
73
|
-
? undefined // needs to be undefined, because void will corrupt union type
|
|
74
|
-
: T;
|
|
23
|
+
type AwaitedPropertiesUnion<input extends Record<string, any> | void> = input extends void
|
|
24
|
+
? undefined // needs to be undefined, because void will break intellisense
|
|
25
|
+
: input extends Record<string, any>
|
|
26
|
+
? {
|
|
27
|
+
[key in keyof input]: Awaited<input[key]>;
|
|
28
|
+
}
|
|
29
|
+
: {} extends input // handles the any case
|
|
30
|
+
? input
|
|
31
|
+
: unknown;
|
|
75
32
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export interface Builder {
|
|
81
|
-
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
|
|
82
|
-
log: Logger;
|
|
83
|
-
/** Remove `dir` and all its contents. */
|
|
84
|
-
rimraf(dir: string): void;
|
|
85
|
-
/** Create `dir` and any required parent directories. */
|
|
86
|
-
mkdirp(dir: string): void;
|
|
87
|
-
|
|
88
|
-
/** The fully resolved `svelte.config.js`. */
|
|
89
|
-
config: ValidatedConfig;
|
|
90
|
-
/** Information about prerendered pages and assets, if any. */
|
|
91
|
-
prerendered: Prerendered;
|
|
92
|
-
/** An array of all routes (including prerendered) */
|
|
93
|
-
routes: RouteDefinition[];
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Create separate functions that map to one or more routes of your app.
|
|
97
|
-
* @param fn A function that groups a set of routes into an entry point
|
|
98
|
-
* @deprecated Use `builder.routes` instead
|
|
99
|
-
*/
|
|
100
|
-
createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
|
|
33
|
+
export type AwaitedProperties<input extends Record<string, any> | void> =
|
|
34
|
+
AwaitedPropertiesUnion<input> extends Record<string, any>
|
|
35
|
+
? OptionalUnion<AwaitedPropertiesUnion<input>>
|
|
36
|
+
: AwaitedPropertiesUnion<input>;
|
|
101
37
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
38
|
+
export type AwaitedActions<T extends Record<string, (...args: any) => any>> = OptionalUnion<
|
|
39
|
+
{
|
|
40
|
+
[Key in keyof T]: UnpackValidationError<Awaited<ReturnType<T[Key]>>>;
|
|
41
|
+
}[keyof T]
|
|
42
|
+
>;
|
|
106
43
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
44
|
+
// Takes a union type and returns a union type where each type also has all properties
|
|
45
|
+
// of all possible types (typed as undefined), making accessing them more ergonomic
|
|
46
|
+
type OptionalUnion<
|
|
47
|
+
U extends Record<string, any>, // not unknown, else interfaces don't satisfy this constraint
|
|
48
|
+
A extends keyof U = U extends U ? keyof U : never
|
|
49
|
+
> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;
|
|
112
50
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
/** Get the fully resolved path to the directory containing client-side assets, including the contents of your `static` directory. */
|
|
119
|
-
getClientDirectory(): string;
|
|
120
|
-
/** Get the fully resolved path to the directory containing server-side code. */
|
|
121
|
-
getServerDirectory(): string;
|
|
122
|
-
/** Get the application path including any configured `base` path, e.g. `/my-base-path/_app`. */
|
|
123
|
-
getAppPath(): string;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Write client assets to `dest`.
|
|
127
|
-
* @param dest the destination folder
|
|
128
|
-
* @returns an array of files written to `dest`
|
|
129
|
-
*/
|
|
130
|
-
writeClient(dest: string): string[];
|
|
131
|
-
/**
|
|
132
|
-
* Write prerendered files to `dest`.
|
|
133
|
-
* @param dest the destination folder
|
|
134
|
-
* @returns an array of files written to `dest`
|
|
135
|
-
*/
|
|
136
|
-
writePrerendered(dest: string): string[];
|
|
137
|
-
/**
|
|
138
|
-
* Write server-side code to `dest`.
|
|
139
|
-
* @param dest the destination folder
|
|
140
|
-
* @returns an array of files written to `dest`
|
|
141
|
-
*/
|
|
142
|
-
writeServer(dest: string): string[];
|
|
143
|
-
/**
|
|
144
|
-
* Copy a file or directory.
|
|
145
|
-
* @param from the source file or directory
|
|
146
|
-
* @param to the destination file or directory
|
|
147
|
-
* @param opts.filter a function to determine whether a file or directory should be copied
|
|
148
|
-
* @param opts.replace a map of strings to replace
|
|
149
|
-
* @returns an array of files that were copied
|
|
150
|
-
*/
|
|
151
|
-
copy(
|
|
152
|
-
from: string,
|
|
153
|
-
to: string,
|
|
154
|
-
opts?: {
|
|
155
|
-
filter?(basename: string): boolean;
|
|
156
|
-
replace?: Record<string, string>;
|
|
157
|
-
}
|
|
158
|
-
): string[];
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals.
|
|
162
|
-
* @param {string} directory The directory containing the files to be compressed
|
|
163
|
-
*/
|
|
164
|
-
compress(directory: string): Promise<void>;
|
|
165
|
-
}
|
|
51
|
+
type UnpackValidationError<T> = T extends ActionFailure<infer X>
|
|
52
|
+
? X
|
|
53
|
+
: T extends void
|
|
54
|
+
? undefined // needs to be undefined, because void will corrupt union type
|
|
55
|
+
: T;
|
|
166
56
|
|
|
167
|
-
export interface Config {
|
|
168
|
-
/**
|
|
169
|
-
* Options passed to [`svelte.compile`](https://svelte.dev/docs#compile-time-svelte-compile).
|
|
170
|
-
* @default {}
|
|
171
|
-
*/
|
|
172
|
-
compilerOptions?: CompileOptions;
|
|
173
57
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
58
|
+
* This object is passed to the `adapt` function of adapters.
|
|
59
|
+
* It contains various methods and properties that are useful for adapting the app.
|
|
176
60
|
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
dir
|
|
184
|
-
emitTypes?: boolean;
|
|
185
|
-
exports?(filepath: string): boolean;
|
|
186
|
-
files?(filepath: string): boolean;
|
|
187
|
-
};
|
|
188
|
-
/** Preprocessor options, if any. Preprocessing can alternatively also be done through Vite's preprocessor capabilities. */
|
|
189
|
-
preprocess?: any;
|
|
190
|
-
/** `vite-plugin-svelte` plugin options. */
|
|
191
|
-
vitePlugin?: PluginOptions;
|
|
192
|
-
/** Any additional options required by tooling that integrates with Svelte. */
|
|
193
|
-
[key: string]: any;
|
|
194
|
-
}
|
|
61
|
+
export interface Builder {
|
|
62
|
+
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
|
|
63
|
+
log: Logger;
|
|
64
|
+
/** Remove `dir` and all its contents. */
|
|
65
|
+
rimraf(dir: string): void;
|
|
66
|
+
/** Create `dir` and any required parent directories. */
|
|
67
|
+
mkdirp(dir: string): void;
|
|
195
68
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
69
|
+
/** The fully resolved `svelte.config.js`. */
|
|
70
|
+
config: ValidatedConfig;
|
|
71
|
+
/** Information about prerendered pages and assets, if any. */
|
|
72
|
+
prerendered: Prerendered;
|
|
73
|
+
/** An array of all routes (including prerendered) */
|
|
74
|
+
routes: RouteDefinition[];
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Create separate functions that map to one or more routes of your app.
|
|
78
|
+
* */
|
|
79
|
+
createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Generate a fallback page for a static webserver to use when no route is matched. Useful for single-page apps.
|
|
83
|
+
*/
|
|
84
|
+
generateFallback(dest: string): Promise<void>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Generate a server-side manifest to initialise the SvelteKit [server](https://kit.svelte.dev/docs/types#public-types-server) with.
|
|
88
|
+
* */
|
|
89
|
+
generateManifest(opts: { relativePath: string; routes?: RouteDefinition[] }): string;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Resolve a path to the `name` directory inside `outDir`, e.g. `/path/to/.svelte-kit/my-adapter`.
|
|
93
|
+
* */
|
|
94
|
+
getBuildDirectory(name: string): string;
|
|
95
|
+
/** Get the fully resolved path to the directory containing client-side assets, including the contents of your `static` directory. */
|
|
96
|
+
getClientDirectory(): string;
|
|
97
|
+
/** Get the fully resolved path to the directory containing server-side code. */
|
|
98
|
+
getServerDirectory(): string;
|
|
99
|
+
/** Get the application path including any configured `base` path, e.g. `/my-base-path/_app`. */
|
|
100
|
+
getAppPath(): string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Write client assets to `dest`.
|
|
104
|
+
* */
|
|
105
|
+
writeClient(dest: string): string[];
|
|
106
|
+
/**
|
|
107
|
+
* Write prerendered files to `dest`.
|
|
108
|
+
* */
|
|
109
|
+
writePrerendered(dest: string): string[];
|
|
110
|
+
/**
|
|
111
|
+
* Write server-side code to `dest`.
|
|
112
|
+
* */
|
|
113
|
+
writeServer(dest: string): string[];
|
|
114
|
+
/**
|
|
115
|
+
* Copy a file or directory.
|
|
116
|
+
* */
|
|
117
|
+
copy(
|
|
118
|
+
from: string,
|
|
119
|
+
to: string,
|
|
120
|
+
opts?: {
|
|
121
|
+
filter?(basename: string): boolean;
|
|
122
|
+
replace?: Record<string, string>;
|
|
123
|
+
}
|
|
124
|
+
): string[];
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals.
|
|
128
|
+
* */
|
|
129
|
+
compress(directory: string): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface Config {
|
|
133
|
+
/**
|
|
134
|
+
* Options passed to [`svelte.compile`](https://svelte.dev/docs#compile-time-svelte-compile).
|
|
135
|
+
* @default {}
|
|
136
|
+
*/
|
|
137
|
+
compilerOptions?: CompileOptions;
|
|
138
|
+
/**
|
|
139
|
+
* List of file extensions that should be treated as Svelte files.
|
|
140
|
+
* @default [".svelte"]
|
|
141
|
+
*/
|
|
142
|
+
extensions?: string[];
|
|
143
|
+
/** SvelteKit options */
|
|
144
|
+
kit?: KitConfig;
|
|
145
|
+
/** [`@sveltejs/package`](/docs/packaging) options. */
|
|
146
|
+
package?: {
|
|
147
|
+
source?: string;
|
|
148
|
+
dir?: string;
|
|
149
|
+
emitTypes?: boolean;
|
|
150
|
+
exports?(filepath: string): boolean;
|
|
151
|
+
files?(filepath: string): boolean;
|
|
152
|
+
};
|
|
153
|
+
/** Preprocessor options, if any. Preprocessing can alternatively also be done through Vite's preprocessor capabilities. */
|
|
154
|
+
preprocess?: any;
|
|
155
|
+
/** `vite-plugin-svelte` plugin options. */
|
|
156
|
+
vitePlugin?: PluginOptions;
|
|
157
|
+
/** Any additional options required by tooling that integrates with Svelte. */
|
|
158
|
+
[key: string]: any;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface Cookies {
|
|
162
|
+
/**
|
|
163
|
+
* Gets a cookie that was previously set with `cookies.set`, or from the request headers.
|
|
164
|
+
* */
|
|
165
|
+
get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
|
|
169
|
+
* */
|
|
170
|
+
getAll(opts?: import('cookie').CookieParseOptions): Array<{ name: string; value: string }>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
|
|
174
|
+
*
|
|
175
|
+
* 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`.
|
|
176
|
+
*
|
|
177
|
+
* 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.
|
|
178
|
+
* */
|
|
179
|
+
set(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): void;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
|
|
183
|
+
*
|
|
184
|
+
* 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.
|
|
185
|
+
* */
|
|
186
|
+
delete(name: string, opts?: import('cookie').CookieSerializeOptions): void;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
|
|
190
|
+
*
|
|
191
|
+
* 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`.
|
|
192
|
+
*
|
|
193
|
+
* 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.
|
|
194
|
+
*
|
|
195
|
+
* */
|
|
196
|
+
serialize(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface KitConfig {
|
|
200
|
+
/**
|
|
201
|
+
* Your [adapter](https://kit.svelte.dev/docs/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms.
|
|
202
|
+
* @default undefined
|
|
203
|
+
*/
|
|
204
|
+
adapter?: Adapter;
|
|
205
|
+
/**
|
|
206
|
+
* An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
|
|
207
|
+
*
|
|
208
|
+
* ```js
|
|
209
|
+
* /// file: svelte.config.js
|
|
210
|
+
* /// type: import('@sveltejs/kit').Config
|
|
211
|
+
* const config = {
|
|
212
|
+
* kit: {
|
|
213
|
+
* alias: {
|
|
214
|
+
* // this will match a file
|
|
215
|
+
* 'my-file': 'path/to/my-file.js',
|
|
216
|
+
*
|
|
217
|
+
* // this will match a directory and its contents
|
|
218
|
+
* // (`my-directory/x` resolves to `path/to/my-directory/x`)
|
|
219
|
+
* 'my-directory': 'path/to/my-directory',
|
|
220
|
+
*
|
|
221
|
+
* // an alias ending /* will only match
|
|
222
|
+
* // the contents of a directory, not the directory itself
|
|
223
|
+
* 'my-directory/*': 'path/to/my-directory/*'
|
|
224
|
+
* }
|
|
225
|
+
* }
|
|
226
|
+
* };
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* > The built-in `$lib` alias is controlled by `config.kit.files.lib` as it is used for packaging.
|
|
230
|
+
*
|
|
231
|
+
* > You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
|
|
232
|
+
* @default {}
|
|
233
|
+
*/
|
|
234
|
+
alias?: Record<string, string>;
|
|
235
|
+
/**
|
|
236
|
+
* The directory relative to `paths.assets` where the built JS and CSS (and imported assets) are served from. (The filenames therein contain content-based hashes, meaning they can be cached indefinitely). Must not start or end with `/`.
|
|
237
|
+
* @default "_app"
|
|
238
|
+
*/
|
|
239
|
+
appDir?: string;
|
|
240
|
+
/**
|
|
241
|
+
* [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) configuration. CSP helps to protect your users against cross-site scripting (XSS) attacks, by limiting the places resources can be loaded from. For example, a configuration like this...
|
|
242
|
+
*
|
|
243
|
+
* ```js
|
|
244
|
+
* /// file: svelte.config.js
|
|
245
|
+
* /// type: import('@sveltejs/kit').Config
|
|
246
|
+
* const config = {
|
|
247
|
+
* kit: {
|
|
248
|
+
* csp: {
|
|
249
|
+
* directives: {
|
|
250
|
+
* 'script-src': ['self']
|
|
251
|
+
* },
|
|
252
|
+
* reportOnly: {
|
|
253
|
+
* 'script-src': ['self']
|
|
254
|
+
* }
|
|
255
|
+
* }
|
|
256
|
+
* }
|
|
257
|
+
* };
|
|
258
|
+
*
|
|
259
|
+
* export default config;
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* ...would prevent scripts loading from external sites. SvelteKit will augment the specified directives with nonces or hashes (depending on `mode`) for any inline styles and scripts it generates.
|
|
263
|
+
*
|
|
264
|
+
* To add a nonce for scripts and links manually included in `src/app.html`, you may use the placeholder `%sveltekit.nonce%` (for example `<script nonce="%sveltekit.nonce%">`).
|
|
265
|
+
*
|
|
266
|
+
* When pages are prerendered, the CSP header is added via a `<meta http-equiv>` tag (note that in this case, `frame-ancestors`, `report-uri` and `sandbox` directives will be ignored).
|
|
267
|
+
*
|
|
268
|
+
* > When `mode` is `'auto'`, SvelteKit will use nonces for dynamically rendered pages and hashes for prerendered pages. Using nonces with prerendered pages is insecure and therefore forbidden.
|
|
269
|
+
*
|
|
270
|
+
* > Note that most [Svelte transitions](https://svelte.dev/tutorial/transition) work by creating an inline `<style>` element. If you use these in your app, you must either leave the `style-src` directive unspecified or add `unsafe-inline`.
|
|
271
|
+
*
|
|
272
|
+
* If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://kit.svelte.dev/docs/hooks#server-hooks-handle) to roll your own CSP.
|
|
273
|
+
*/
|
|
274
|
+
csp?: {
|
|
275
|
+
/**
|
|
276
|
+
* Whether to use hashes or nonces to restrict `<script>` and `<style>` elements. `'auto'` will use hashes for prerendered pages, and nonces for dynamically rendered pages.
|
|
277
|
+
*/
|
|
278
|
+
mode?: 'hash' | 'nonce' | 'auto';
|
|
279
|
+
/**
|
|
280
|
+
* Directives that will be added to `Content-Security-Policy` headers.
|
|
281
|
+
*/
|
|
282
|
+
directives?: CspDirectives;
|
|
283
|
+
/**
|
|
284
|
+
* Directives that will be added to `Content-Security-Policy-Report-Only` headers.
|
|
285
|
+
*/
|
|
286
|
+
reportOnly?: CspDirectives;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* Protection against [cross-site request forgery (CSRF)](https://owasp.org/www-community/attacks/csrf) attacks.
|
|
290
|
+
*/
|
|
291
|
+
csrf?: {
|
|
292
|
+
/**
|
|
293
|
+
* Whether to check the incoming `origin` header for `POST`, `PUT`, `PATCH`, or `DELETE` form submissions and verify that it matches the server's origin.
|
|
294
|
+
*
|
|
295
|
+
* To allow people to make `POST`, `PUT`, `PATCH`, or `DELETE` requests with a `Content-Type` of `application/x-www-form-urlencoded`, `multipart/form-data`, or `text/plain` to your app from other origins, you will need to disable this option. Be careful!
|
|
296
|
+
* @default true
|
|
297
|
+
*/
|
|
298
|
+
checkOrigin?: boolean;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Here be dragons. Enable at your peril.
|
|
302
|
+
*/
|
|
303
|
+
dangerZone?: {
|
|
304
|
+
/**
|
|
305
|
+
* Automatically add server-side `fetch`ed URLs to the `dependencies` map of `load` functions. This will expose secrets
|
|
306
|
+
* to the client if your URL contains them.
|
|
307
|
+
*/
|
|
308
|
+
trackServerFetches?: boolean;
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Whether or not the app is embedded inside a larger app. If `true`, SvelteKit will add its event listeners related to navigation etc on the parent of `%sveltekit.body%` instead of `window`, and will pass `params` from the server rather than inferring them from `location.pathname`.
|
|
312
|
+
* @default false
|
|
313
|
+
*/
|
|
314
|
+
embedded?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Environment variable configuration
|
|
317
|
+
*/
|
|
318
|
+
env?: {
|
|
319
|
+
/**
|
|
320
|
+
* The directory to search for `.env` files.
|
|
321
|
+
* @default "."
|
|
322
|
+
*/
|
|
323
|
+
dir?: string;
|
|
324
|
+
/**
|
|
325
|
+
* A prefix that signals that an environment variable is safe to expose to client-side code. See [`$env/static/public`](/docs/modules#$env-static-public) and [`$env/dynamic/public`](/docs/modules#$env-dynamic-public). Note that Vite's [`envPrefix`](https://vitejs.dev/config/shared-options.html#envprefix) must be set separately if you are using Vite's environment variable handling - though use of that feature should generally be unnecessary.
|
|
326
|
+
* @default "PUBLIC_"
|
|
327
|
+
*/
|
|
328
|
+
publicPrefix?: string;
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Where to find various files within your project.
|
|
332
|
+
*/
|
|
333
|
+
files?: {
|
|
334
|
+
/**
|
|
335
|
+
* a place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json`
|
|
336
|
+
* @default "static"
|
|
337
|
+
*/
|
|
338
|
+
assets?: string;
|
|
339
|
+
hooks?: {
|
|
340
|
+
/**
|
|
341
|
+
* The location of your client [hooks](https://kit.svelte.dev/docs/hooks).
|
|
342
|
+
* @default "src/hooks.client"
|
|
343
|
+
*/
|
|
344
|
+
client?: string;
|
|
345
|
+
/**
|
|
346
|
+
* The location of your server [hooks](https://kit.svelte.dev/docs/hooks).
|
|
347
|
+
* @default "src/hooks.server"
|
|
348
|
+
*/
|
|
349
|
+
server?: string;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* your app's internal library, accessible throughout the codebase as `$lib`
|
|
353
|
+
* @default "src/lib"
|
|
354
|
+
*/
|
|
355
|
+
lib?: string;
|
|
356
|
+
/**
|
|
357
|
+
* a directory containing [parameter matchers](https://kit.svelte.dev/docs/advanced-routing#matching)
|
|
358
|
+
* @default "src/params"
|
|
359
|
+
*/
|
|
360
|
+
params?: string;
|
|
361
|
+
/**
|
|
362
|
+
* the files that define the structure of your app (see [Routing](https://kit.svelte.dev/docs/routing))
|
|
363
|
+
* @default "src/routes"
|
|
364
|
+
*/
|
|
365
|
+
routes?: string;
|
|
366
|
+
/**
|
|
367
|
+
* the location of your service worker's entry point (see [Service workers](https://kit.svelte.dev/docs/service-workers))
|
|
368
|
+
* @default "src/service-worker"
|
|
369
|
+
*/
|
|
370
|
+
serviceWorker?: string;
|
|
371
|
+
/**
|
|
372
|
+
* the location of the template for HTML responses
|
|
373
|
+
* @default "src/app.html"
|
|
374
|
+
*/
|
|
375
|
+
appTemplate?: string;
|
|
376
|
+
/**
|
|
377
|
+
* the location of the template for fallback error responses
|
|
378
|
+
* @default "src/error.html"
|
|
379
|
+
*/
|
|
380
|
+
errorTemplate?: string;
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Inline CSS inside a `<style>` block at the head of the HTML. This option is a number that specifies the maximum length of a CSS file to be inlined. All CSS files needed for the page and smaller than this value are merged and inlined in a `<style>` block.
|
|
384
|
+
*
|
|
385
|
+
* > This results in fewer initial requests and can improve your [First Contentful Paint](https://web.dev/first-contentful-paint) score. However, it generates larger HTML output and reduces the effectiveness of browser caches. Use it advisedly.
|
|
386
|
+
* @default 0
|
|
387
|
+
*/
|
|
388
|
+
inlineStyleThreshold?: number;
|
|
389
|
+
/**
|
|
390
|
+
* An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.kit.moduleExtensions` will be ignored by the router.
|
|
391
|
+
* @default [".js", ".ts"]
|
|
392
|
+
*/
|
|
393
|
+
moduleExtensions?: string[];
|
|
394
|
+
/**
|
|
395
|
+
* The directory that SvelteKit writes files to during `dev` and `build`. You should exclude this directory from version control.
|
|
396
|
+
* @default ".svelte-kit"
|
|
397
|
+
*/
|
|
398
|
+
outDir?: string;
|
|
399
|
+
/**
|
|
400
|
+
* Options related to the build output format
|
|
401
|
+
*/
|
|
402
|
+
output?: {
|
|
403
|
+
/**
|
|
404
|
+
* SvelteKit will preload the JavaScript modules needed for the initial page to avoid import 'waterfalls', resulting in faster application startup. There
|
|
405
|
+
* are three strategies with different trade-offs:
|
|
406
|
+
* - `modulepreload` - uses `<link rel="modulepreload">`. This delivers the best results in Chromium-based browsers, but is currently ignored by Firefox and Safari (though support is coming to Safari soon).
|
|
407
|
+
* - `preload-js` - uses `<link rel="preload">`. Prevents waterfalls in Chromium and Safari, but Chromium will parse each module twice (once as a script, once as a module). Causes modules to be requested twice in Firefox. This is a good setting if you want to maximise performance for users on iOS devices at the cost of a very slight degradation for Chromium users.
|
|
408
|
+
* - `preload-mjs` - uses `<link rel="preload">` but with the `.mjs` extension which prevents double-parsing in Chromium. Some static webservers will fail to serve .mjs files with a `Content-Type: application/javascript` header, which will cause your application to break. If that doesn't apply to you, this is the option that will deliver the best performance for the largest number of users, until `modulepreload` is more widely supported.
|
|
409
|
+
* @default "modulepreload"
|
|
410
|
+
*/
|
|
411
|
+
preloadStrategy?: 'modulepreload' | 'preload-js' | 'preload-mjs';
|
|
412
|
+
};
|
|
413
|
+
paths?: {
|
|
414
|
+
/**
|
|
415
|
+
* An absolute path that your app's files are served from. This is useful if your files are served from a storage bucket of some kind.
|
|
416
|
+
* @default ""
|
|
417
|
+
*/
|
|
418
|
+
assets?: '' | `http://${string}` | `https://${string}`;
|
|
419
|
+
/**
|
|
420
|
+
* A root-relative path that must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string. This specifies where your app is served from and allows the app to live on a non-root path. Note that you need to prepend all your root-relative links with the base value or they will point to the root of your domain, not your `base` (this is how the browser works). You can use [`base` from `$app/paths`](/docs/modules#$app-paths-base) for that: `<a href="{base}/your-page">Link</a>`. If you find yourself writing this often, it may make sense to extract this into a reusable component.
|
|
421
|
+
* @default ""
|
|
422
|
+
*/
|
|
423
|
+
base?: '' | `/${string}`;
|
|
424
|
+
/**
|
|
425
|
+
* Whether to use relative asset paths. By default, if `paths.assets` is not external, SvelteKit will replace `%sveltekit.assets%` with a relative path and use relative paths to reference build artifacts, but `base` and `assets` imported from `$app/paths` will be as specified in your config.
|
|
426
|
+
*
|
|
427
|
+
* If `true`, `base` and `assets` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in portable HTML.
|
|
428
|
+
* If `false`, `%sveltekit.assets%` and references to build artifacts will always be root-relative paths, unless `paths.assets` is an external URL
|
|
429
|
+
*
|
|
430
|
+
* If your app uses a `<base>` element, you should set this to `false`, otherwise asset URLs will incorrectly be resolved against the `<base>` URL rather than the current page.
|
|
431
|
+
* @default undefined
|
|
432
|
+
*/
|
|
433
|
+
relative?: boolean | undefined;
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* See [Prerendering](https://kit.svelte.dev/docs/page-options#prerender).
|
|
437
|
+
*/
|
|
438
|
+
prerender?: {
|
|
439
|
+
/**
|
|
440
|
+
* How many pages can be prerendered simultaneously. JS is single-threaded, but in cases where prerendering performance is network-bound (for example loading content from a remote CMS) this can speed things up by processing other tasks while waiting on the network response.
|
|
441
|
+
* @default 1
|
|
442
|
+
*/
|
|
443
|
+
concurrency?: number;
|
|
444
|
+
/**
|
|
445
|
+
* Whether SvelteKit should find pages to prerender by following links from `entries`.
|
|
446
|
+
* @default true
|
|
447
|
+
*/
|
|
448
|
+
crawl?: boolean;
|
|
449
|
+
/**
|
|
450
|
+
* An array of pages to prerender, or start crawling from (if `crawl: true`). The `*` string includes all non-dynamic routes (i.e. pages with no `[parameters]`, because SvelteKit doesn't know what value the parameters should have).
|
|
451
|
+
* @default ["*"]
|
|
452
|
+
*/
|
|
453
|
+
entries?: Array<'*' | `/${string}`>;
|
|
454
|
+
/**
|
|
455
|
+
* How to respond to HTTP errors encountered while prerendering the app.
|
|
456
|
+
*
|
|
457
|
+
* - `'fail'` — fail the build
|
|
458
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
459
|
+
* - `'warn'` — continue, but print a warning
|
|
460
|
+
* - `(details) => void` — a custom error handler that takes a `details` object with `status`, `path`, `referrer`, `referenceType` and `message` properties. If you `throw` from this function, the build will fail
|
|
461
|
+
*
|
|
462
|
+
* ```js
|
|
463
|
+
* /// file: svelte.config.js
|
|
464
|
+
* /// type: import('@sveltejs/kit').Config
|
|
465
|
+
* const config = {
|
|
466
|
+
* kit: {
|
|
467
|
+
* prerender: {
|
|
468
|
+
* handleHttpError: ({ path, referrer, message }) => {
|
|
469
|
+
* // ignore deliberate link to shiny 404 page
|
|
470
|
+
* if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
|
|
471
|
+
* return;
|
|
472
|
+
* }
|
|
473
|
+
*
|
|
474
|
+
* // otherwise fail the build
|
|
475
|
+
* throw new Error(message);
|
|
476
|
+
* }
|
|
477
|
+
* }
|
|
478
|
+
* }
|
|
479
|
+
* };
|
|
480
|
+
* ```
|
|
481
|
+
*
|
|
482
|
+
* @default "fail"
|
|
483
|
+
*/
|
|
484
|
+
handleHttpError?: PrerenderHttpErrorHandlerValue;
|
|
485
|
+
/**
|
|
486
|
+
* How to respond when hash links from one prerendered page to another don't correspond to an `id` on the destination page.
|
|
487
|
+
*
|
|
488
|
+
* - `'fail'` — fail the build
|
|
489
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
490
|
+
* - `'warn'` — continue, but print a warning
|
|
491
|
+
* - `(details) => void` — a custom error handler that takes a `details` object with `path`, `id`, `referrers` and `message` properties. If you `throw` from this function, the build will fail
|
|
492
|
+
*
|
|
493
|
+
* @default "fail"
|
|
494
|
+
*/
|
|
495
|
+
handleMissingId?: PrerenderMissingIdHandlerValue;
|
|
496
|
+
/**
|
|
497
|
+
* How to respond when an entry generated by the `entries` export doesn't match the route it was generated from.
|
|
498
|
+
*
|
|
499
|
+
* - `'fail'` — fail the build
|
|
500
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
501
|
+
* - `'warn'` — continue, but print a warning
|
|
502
|
+
* - `(details) => void` — a custom error handler that takes a `details` object with `generatedFromId`, `entry`, `matchedId` and `message` properties. If you `throw` from this function, the build will fail
|
|
503
|
+
*
|
|
504
|
+
* @default "fail"
|
|
505
|
+
*/
|
|
506
|
+
handleEntryGeneratorMismatch?: PrerenderEntryGeneratorMismatchHandlerValue;
|
|
507
|
+
/**
|
|
508
|
+
* The value of `url.origin` during prerendering; useful if it is included in rendered content.
|
|
509
|
+
* @default "http://sveltekit-prerender"
|
|
510
|
+
*/
|
|
511
|
+
origin?: string;
|
|
512
|
+
};
|
|
513
|
+
serviceWorker?: {
|
|
514
|
+
/**
|
|
515
|
+
* Whether to automatically register the service worker, if it exists.
|
|
516
|
+
* @default true
|
|
517
|
+
*/
|
|
518
|
+
register?: boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Determine which files in your `static` directory will be available in `$service-worker.files`.
|
|
521
|
+
* @default (filename) => !/\.DS_Store/.test(filename)
|
|
522
|
+
*/
|
|
523
|
+
files?(filepath: string): boolean;
|
|
524
|
+
};
|
|
525
|
+
typescript?: {
|
|
526
|
+
/**
|
|
527
|
+
* A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
|
|
528
|
+
* This is useful for extending a shared `tsconfig.json` in a monorepo root, for example.
|
|
529
|
+
* @default (config) => config
|
|
530
|
+
*/
|
|
531
|
+
config?: (config: Record<string, any>) => Record<string, any> | void;
|
|
532
|
+
};
|
|
533
|
+
/**
|
|
534
|
+
* Client-side navigation can be buggy if you deploy a new version of your app while people are using it. If the code for the new page is already loaded, it may have stale content; if it isn't, the app's route manifest may point to a JavaScript file that no longer exists.
|
|
535
|
+
* SvelteKit helps you solve this problem through version management.
|
|
536
|
+
* If SvelteKit encounters an error while loading the page and detects that a new version has been deployed (using the `name` specified here, which defaults to a timestamp of the build) it will fall back to traditional full-page navigation.
|
|
537
|
+
* Not all navigations will result in an error though, for example if the JavaScript for the next page is already loaded. If you still want to force a full-page navigation in these cases, use techniques such as setting the `pollInterval` and then using `beforeNavigate`:
|
|
538
|
+
* ```html
|
|
539
|
+
* /// file: +layout.svelte
|
|
540
|
+
* <script>
|
|
541
|
+
* import { beforeNavigate } from '$app/navigation';
|
|
542
|
+
* import { updated } from '$app/stores';
|
|
543
|
+
*
|
|
544
|
+
* beforeNavigate(({ willUnload, to }) => {
|
|
545
|
+
* if ($updated && !willUnload && to?.url) {
|
|
546
|
+
* location.href = to.url.href;
|
|
547
|
+
* }
|
|
548
|
+
* });
|
|
549
|
+
* </script>
|
|
550
|
+
* ```
|
|
551
|
+
*
|
|
552
|
+
* If you set `pollInterval` to a non-zero value, SvelteKit will poll for new versions in the background and set the value of the [`updated`](/docs/modules#$app-stores-updated) store to `true` when it detects one.
|
|
553
|
+
*/
|
|
554
|
+
version?: {
|
|
555
|
+
/**
|
|
556
|
+
* The current app version string. If specified, this must be deterministic (e.g. a commit ref rather than `Math.random()` or `Date.now().toString()`), otherwise defaults to a timestamp of the build.
|
|
557
|
+
*
|
|
558
|
+
* For example, to use the current commit hash, you could do use `git rev-parse HEAD`:
|
|
559
|
+
*
|
|
560
|
+
* ```js
|
|
561
|
+
* /// file: svelte.config.js
|
|
562
|
+
* import * as child_process from 'node:child_process';
|
|
563
|
+
*
|
|
564
|
+
* export default {
|
|
565
|
+
* kit: {
|
|
566
|
+
* version: {
|
|
567
|
+
* name: child_process.execSync('git rev-parse HEAD').toString().trim()
|
|
568
|
+
* }
|
|
569
|
+
* }
|
|
570
|
+
* };
|
|
571
|
+
* ```
|
|
572
|
+
*/
|
|
573
|
+
name?: string;
|
|
574
|
+
/**
|
|
575
|
+
* The interval in milliseconds to poll for version changes. If this is `0`, no polling occurs.
|
|
576
|
+
* @default 0
|
|
577
|
+
*/
|
|
578
|
+
pollInterval?: number;
|
|
579
|
+
};
|
|
580
|
+
}
|
|
203
581
|
|
|
204
582
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
583
|
+
* The [`handle`](https://kit.svelte.dev/docs/hooks#server-hooks-handle) hook runs every time the SvelteKit server receives a [request](https://kit.svelte.dev/docs/web-standards#fetch-apis-request) and
|
|
584
|
+
* determines the [response](https://kit.svelte.dev/docs/web-standards#fetch-apis-response).
|
|
585
|
+
* It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
|
|
586
|
+
* This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
|
|
207
587
|
*/
|
|
208
|
-
|
|
588
|
+
export type Handle = (input: {
|
|
589
|
+
event: RequestEvent;
|
|
590
|
+
resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
|
|
591
|
+
}) => MaybePromise<Response>;
|
|
209
592
|
|
|
210
593
|
/**
|
|
211
|
-
*
|
|
594
|
+
* The server-side [`handleError`](https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror) hook runs when an unexpected error is thrown while responding to a request.
|
|
212
595
|
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* 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.
|
|
216
|
-
* @param name the name of the cookie
|
|
217
|
-
* @param value the cookie value
|
|
218
|
-
* @param opts the options, passed directory to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
|
|
596
|
+
* If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
|
|
597
|
+
* Make sure that this function _never_ throws an error.
|
|
219
598
|
*/
|
|
220
|
-
|
|
599
|
+
export type HandleServerError = (input: {
|
|
600
|
+
error: unknown;
|
|
601
|
+
event: RequestEvent;
|
|
602
|
+
}) => MaybePromise<void | App.Error>;
|
|
221
603
|
|
|
222
604
|
/**
|
|
223
|
-
*
|
|
605
|
+
* The client-side [`handleError`](https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror) hook runs when an unexpected error is thrown while navigating.
|
|
224
606
|
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* @param opts the options, passed directory to `cookie.serialize`. The `path` must match the path of the cookie you want to delete. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
|
|
607
|
+
* If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
|
|
608
|
+
* Make sure that this function _never_ throws an error.
|
|
228
609
|
*/
|
|
229
|
-
|
|
610
|
+
export type HandleClientError = (input: {
|
|
611
|
+
error: unknown;
|
|
612
|
+
event: NavigationEvent;
|
|
613
|
+
}) => MaybePromise<void | App.Error>;
|
|
230
614
|
|
|
231
615
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* 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`.
|
|
235
|
-
*
|
|
236
|
-
* 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.
|
|
237
|
-
*
|
|
238
|
-
* @param name the name of the cookie
|
|
239
|
-
* @param value the cookie value
|
|
240
|
-
* @param opts the options, passed directory to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
|
|
616
|
+
* The [`handleFetch`](https://kit.svelte.dev/docs/hooks#server-hooks-handlefetch) hook allows you to modify (or replace) a `fetch` request that happens inside a `load` function that runs on the server (or during pre-rendering)
|
|
241
617
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
618
|
+
export type HandleFetch = (input: {
|
|
619
|
+
event: RequestEvent;
|
|
620
|
+
request: Request;
|
|
621
|
+
fetch: typeof fetch;
|
|
622
|
+
}) => MaybePromise<Response>;
|
|
244
623
|
|
|
245
|
-
export interface KitConfig {
|
|
246
624
|
/**
|
|
247
|
-
*
|
|
248
|
-
*
|
|
625
|
+
* The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
626
|
+
* rather than using `Load` directly.
|
|
249
627
|
*/
|
|
250
|
-
|
|
628
|
+
export type Load<
|
|
629
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
630
|
+
InputData extends Record<string, unknown> | null = Record<string, any> | null,
|
|
631
|
+
ParentData extends Record<string, unknown> = Record<string, any>,
|
|
632
|
+
OutputData extends Record<string, unknown> | void = Record<string, any> | void,
|
|
633
|
+
RouteId extends string | null = string | null
|
|
634
|
+
> = (event: LoadEvent<Params, InputData, ParentData, RouteId>) => MaybePromise<OutputData>;
|
|
635
|
+
|
|
251
636
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* ```js
|
|
255
|
-
* /// file: svelte.config.js
|
|
256
|
-
* /// type: import('@sveltejs/kit').Config
|
|
257
|
-
* const config = {
|
|
258
|
-
* kit: {
|
|
259
|
-
* alias: {
|
|
260
|
-
* // this will match a file
|
|
261
|
-
* 'my-file': 'path/to/my-file.js',
|
|
262
|
-
*
|
|
263
|
-
* // this will match a directory and its contents
|
|
264
|
-
* // (`my-directory/x` resolves to `path/to/my-directory/x`)
|
|
265
|
-
* 'my-directory': 'path/to/my-directory',
|
|
266
|
-
*
|
|
267
|
-
* // an alias ending /* will only match
|
|
268
|
-
* // the contents of a directory, not the directory itself
|
|
269
|
-
* 'my-directory/*': 'path/to/my-directory/*'
|
|
270
|
-
* }
|
|
271
|
-
* }
|
|
272
|
-
* };
|
|
273
|
-
* ```
|
|
274
|
-
*
|
|
275
|
-
* > The built-in `$lib` alias is controlled by `config.kit.files.lib` as it is used for packaging.
|
|
276
|
-
*
|
|
277
|
-
* > You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
|
|
278
|
-
* @default {}
|
|
637
|
+
* The generic form of `PageLoadEvent` and `LayoutLoadEvent`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
638
|
+
* rather than using `LoadEvent` directly.
|
|
279
639
|
*/
|
|
280
|
-
|
|
640
|
+
export interface LoadEvent<
|
|
641
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
642
|
+
Data extends Record<string, unknown> | null = Record<string, any> | null,
|
|
643
|
+
ParentData extends Record<string, unknown> = Record<string, any>,
|
|
644
|
+
RouteId extends string | null = string | null
|
|
645
|
+
> extends NavigationEvent<Params, RouteId> {
|
|
646
|
+
/**
|
|
647
|
+
* `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
|
|
648
|
+
*
|
|
649
|
+
* - it can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request
|
|
650
|
+
* - it can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context)
|
|
651
|
+
* - 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
|
|
652
|
+
* - 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)
|
|
653
|
+
* - during hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request
|
|
654
|
+
*
|
|
655
|
+
* > Cookies will only be passed through if the target host is the same as the SvelteKit application or a more specific subdomain of it.
|
|
656
|
+
*/
|
|
657
|
+
fetch: typeof fetch;
|
|
658
|
+
/**
|
|
659
|
+
* Contains the data returned by the route's server `load` function (in `+layout.server.js` or `+page.server.js`), if any.
|
|
660
|
+
*/
|
|
661
|
+
data: Data;
|
|
662
|
+
/**
|
|
663
|
+
* 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:
|
|
664
|
+
*
|
|
665
|
+
* ```js
|
|
666
|
+
* /// file: src/routes/blog/+page.js
|
|
667
|
+
* export async function load({ fetch, setHeaders }) {
|
|
668
|
+
* const url = `https://cms.example.com/articles.json`;
|
|
669
|
+
* const response = await fetch(url);
|
|
670
|
+
*
|
|
671
|
+
* setHeaders({
|
|
672
|
+
* age: response.headers.get('age'),
|
|
673
|
+
* 'cache-control': response.headers.get('cache-control')
|
|
674
|
+
* });
|
|
675
|
+
*
|
|
676
|
+
* return response.json();
|
|
677
|
+
* }
|
|
678
|
+
* ```
|
|
679
|
+
*
|
|
680
|
+
* Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
|
|
681
|
+
*
|
|
682
|
+
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#public-types-cookies) API in a server-only `load` function instead.
|
|
683
|
+
*
|
|
684
|
+
* `setHeaders` has no effect when a `load` function runs in the browser.
|
|
685
|
+
*/
|
|
686
|
+
setHeaders(headers: Record<string, string>): void;
|
|
687
|
+
/**
|
|
688
|
+
* `await parent()` returns data from parent `+layout.js` `load` functions.
|
|
689
|
+
* 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.
|
|
690
|
+
*
|
|
691
|
+
* 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.
|
|
692
|
+
*/
|
|
693
|
+
parent(): Promise<ParentData>;
|
|
694
|
+
/**
|
|
695
|
+
* 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.
|
|
696
|
+
*
|
|
697
|
+
* 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`.
|
|
698
|
+
*
|
|
699
|
+
* 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).
|
|
700
|
+
*
|
|
701
|
+
* 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).
|
|
702
|
+
*
|
|
703
|
+
* 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.
|
|
704
|
+
*
|
|
705
|
+
* ```js
|
|
706
|
+
* /// file: src/routes/+page.js
|
|
707
|
+
* let count = 0;
|
|
708
|
+
* export async function load({ depends }) {
|
|
709
|
+
* depends('increase:count');
|
|
710
|
+
*
|
|
711
|
+
* return { count: count++ };
|
|
712
|
+
* }
|
|
713
|
+
* ```
|
|
714
|
+
*
|
|
715
|
+
* ```html
|
|
716
|
+
* /// file: src/routes/+page.svelte
|
|
717
|
+
* <script>
|
|
718
|
+
* import { invalidate } from '$app/navigation';
|
|
719
|
+
*
|
|
720
|
+
* export let data;
|
|
721
|
+
*
|
|
722
|
+
* const increase = async () => {
|
|
723
|
+
* await invalidate('increase:count');
|
|
724
|
+
* }
|
|
725
|
+
* </script>
|
|
726
|
+
*
|
|
727
|
+
* <p>{data.count}<p>
|
|
728
|
+
* <button on:click={increase}>Increase Count</button>
|
|
729
|
+
* ```
|
|
730
|
+
*/
|
|
731
|
+
depends(...deps: string[]): void;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
export interface NavigationEvent<
|
|
735
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
736
|
+
RouteId extends string | null = string | null
|
|
737
|
+
> {
|
|
738
|
+
/**
|
|
739
|
+
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
740
|
+
*/
|
|
741
|
+
params: Params;
|
|
742
|
+
/**
|
|
743
|
+
* Info about the current route
|
|
744
|
+
*/
|
|
745
|
+
route: {
|
|
746
|
+
/**
|
|
747
|
+
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
748
|
+
*/
|
|
749
|
+
id: RouteId;
|
|
750
|
+
};
|
|
751
|
+
/**
|
|
752
|
+
* The URL of the current page
|
|
753
|
+
*/
|
|
754
|
+
url: URL;
|
|
755
|
+
}
|
|
756
|
+
|
|
281
757
|
/**
|
|
282
|
-
*
|
|
283
|
-
* @default "_app"
|
|
758
|
+
* Information about the target of a specific navigation.
|
|
284
759
|
*/
|
|
285
|
-
|
|
760
|
+
export interface NavigationTarget {
|
|
761
|
+
/**
|
|
762
|
+
* Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
763
|
+
* Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
|
|
764
|
+
*/
|
|
765
|
+
params: Record<string, string> | null;
|
|
766
|
+
/**
|
|
767
|
+
* Info about the target route
|
|
768
|
+
*/
|
|
769
|
+
route: { id: string | null };
|
|
770
|
+
/**
|
|
771
|
+
* The URL that is navigated to
|
|
772
|
+
*/
|
|
773
|
+
url: URL;
|
|
774
|
+
}
|
|
775
|
+
|
|
286
776
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
* kit: {
|
|
294
|
-
* csp: {
|
|
295
|
-
* directives: {
|
|
296
|
-
* 'script-src': ['self']
|
|
297
|
-
* },
|
|
298
|
-
* reportOnly: {
|
|
299
|
-
* 'script-src': ['self']
|
|
300
|
-
* }
|
|
301
|
-
* }
|
|
302
|
-
* }
|
|
303
|
-
* };
|
|
304
|
-
*
|
|
305
|
-
* export default config;
|
|
306
|
-
* ```
|
|
307
|
-
*
|
|
308
|
-
* ...would prevent scripts loading from external sites. SvelteKit will augment the specified directives with nonces or hashes (depending on `mode`) for any inline styles and scripts it generates.
|
|
309
|
-
*
|
|
310
|
-
* To add a nonce for scripts and links manually included in `src/app.html`, you may use the placeholder `%sveltekit.nonce%` (for example `<script nonce="%sveltekit.nonce%">`).
|
|
311
|
-
*
|
|
312
|
-
* When pages are prerendered, the CSP header is added via a `<meta http-equiv>` tag (note that in this case, `frame-ancestors`, `report-uri` and `sandbox` directives will be ignored).
|
|
313
|
-
*
|
|
314
|
-
* > When `mode` is `'auto'`, SvelteKit will use nonces for dynamically rendered pages and hashes for prerendered pages. Using nonces with prerendered pages is insecure and therefore forbidden.
|
|
315
|
-
*
|
|
316
|
-
* > Note that most [Svelte transitions](https://svelte.dev/tutorial/transition) work by creating an inline `<style>` element. If you use these in your app, you must either leave the `style-src` directive unspecified or add `unsafe-inline`.
|
|
317
|
-
*
|
|
318
|
-
* If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://kit.svelte.dev/docs/hooks#server-hooks-handle) to roll your own CSP.
|
|
777
|
+
* - `enter`: The app has hydrated
|
|
778
|
+
* - `form`: The user submitted a `<form>`
|
|
779
|
+
* - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
|
|
780
|
+
* - `link`: Navigation was triggered by a link click
|
|
781
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
782
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
319
783
|
*/
|
|
320
|
-
|
|
784
|
+
export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
785
|
+
|
|
786
|
+
export interface Navigation {
|
|
321
787
|
/**
|
|
322
|
-
*
|
|
788
|
+
* Where navigation was triggered from
|
|
323
789
|
*/
|
|
324
|
-
|
|
790
|
+
from: NavigationTarget | null;
|
|
325
791
|
/**
|
|
326
|
-
*
|
|
792
|
+
* Where navigation is going to/has gone to
|
|
327
793
|
*/
|
|
328
|
-
|
|
794
|
+
to: NavigationTarget | null;
|
|
329
795
|
/**
|
|
330
|
-
*
|
|
796
|
+
* The type of navigation:
|
|
797
|
+
* - `form`: The user submitted a `<form>`
|
|
798
|
+
* - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
|
|
799
|
+
* - `link`: Navigation was triggered by a link click
|
|
800
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
801
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
331
802
|
*/
|
|
332
|
-
|
|
333
|
-
};
|
|
334
|
-
/**
|
|
335
|
-
* Protection against [cross-site request forgery (CSRF)](https://owasp.org/www-community/attacks/csrf) attacks.
|
|
336
|
-
*/
|
|
337
|
-
csrf?: {
|
|
803
|
+
type: Omit<NavigationType, 'enter'>;
|
|
338
804
|
/**
|
|
339
|
-
* Whether
|
|
340
|
-
*
|
|
341
|
-
* To allow people to make `POST`, `PUT`, `PATCH`, or `DELETE` requests with a `Content-Type` of `application/x-www-form-urlencoded`, `multipart/form-data`, or `text/plain` to your app from other origins, you will need to disable this option. Be careful!
|
|
342
|
-
* @default true
|
|
805
|
+
* Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation)
|
|
343
806
|
*/
|
|
344
|
-
|
|
345
|
-
|
|
807
|
+
willUnload: boolean;
|
|
808
|
+
/**
|
|
809
|
+
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
810
|
+
*/
|
|
811
|
+
delta?: number;
|
|
812
|
+
}
|
|
813
|
+
|
|
346
814
|
/**
|
|
347
|
-
*
|
|
348
|
-
* @default false
|
|
815
|
+
* The argument passed to [`beforeNavigate`](https://kit.svelte.dev/docs/modules#$app-navigation-beforenavigate) callbacks.
|
|
349
816
|
*/
|
|
350
|
-
|
|
817
|
+
export interface BeforeNavigate extends Navigation {
|
|
818
|
+
/**
|
|
819
|
+
* Call this to prevent the navigation from starting.
|
|
820
|
+
*/
|
|
821
|
+
cancel(): void;
|
|
822
|
+
}
|
|
823
|
+
|
|
351
824
|
/**
|
|
352
|
-
*
|
|
825
|
+
* The argument passed to [`afterNavigate`](https://kit.svelte.dev/docs/modules#$app-navigation-afternavigate) callbacks.
|
|
353
826
|
*/
|
|
354
|
-
|
|
827
|
+
export interface AfterNavigate extends Navigation {
|
|
355
828
|
/**
|
|
356
|
-
* The
|
|
357
|
-
*
|
|
829
|
+
* The type of navigation:
|
|
830
|
+
* - `enter`: The app has hydrated
|
|
831
|
+
* - `form`: The user submitted a `<form>`
|
|
832
|
+
* - `link`: Navigation was triggered by a link click
|
|
833
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
834
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
358
835
|
*/
|
|
359
|
-
|
|
836
|
+
type: Omit<NavigationType, 'leave'>;
|
|
360
837
|
/**
|
|
361
|
-
*
|
|
362
|
-
* @default "PUBLIC_"
|
|
838
|
+
* Since `afterNavigate` is called after a navigation completes, it will never be called with a navigation that unloads the page.
|
|
363
839
|
*/
|
|
364
|
-
|
|
365
|
-
}
|
|
840
|
+
willUnload: false;
|
|
841
|
+
}
|
|
842
|
+
|
|
366
843
|
/**
|
|
367
|
-
*
|
|
844
|
+
* The shape of the `$page` store
|
|
368
845
|
*/
|
|
369
|
-
|
|
846
|
+
export interface Page<
|
|
847
|
+
Params extends Record<string, string> = Record<string, string>,
|
|
848
|
+
RouteId extends string | null = string | null
|
|
849
|
+
> {
|
|
370
850
|
/**
|
|
371
|
-
*
|
|
372
|
-
* @default "static"
|
|
851
|
+
* The URL of the current page
|
|
373
852
|
*/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
853
|
+
url: URL;
|
|
854
|
+
/**
|
|
855
|
+
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
856
|
+
*/
|
|
857
|
+
params: Params;
|
|
858
|
+
/**
|
|
859
|
+
* Info about the current route
|
|
860
|
+
*/
|
|
861
|
+
route: {
|
|
381
862
|
/**
|
|
382
|
-
* The
|
|
383
|
-
* @default "src/hooks.server"
|
|
863
|
+
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
384
864
|
*/
|
|
385
|
-
|
|
865
|
+
id: RouteId;
|
|
386
866
|
};
|
|
387
867
|
/**
|
|
388
|
-
*
|
|
389
|
-
* @default "src/lib"
|
|
868
|
+
* Http status code of the current page
|
|
390
869
|
*/
|
|
391
|
-
|
|
870
|
+
status: number;
|
|
392
871
|
/**
|
|
393
|
-
*
|
|
394
|
-
* @default "src/params"
|
|
872
|
+
* The error object of the current page, if any. Filled from the `handleError` hooks.
|
|
395
873
|
*/
|
|
396
|
-
|
|
874
|
+
error: App.Error | null;
|
|
397
875
|
/**
|
|
398
|
-
*
|
|
399
|
-
* @default "src/routes"
|
|
876
|
+
* The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
|
|
400
877
|
*/
|
|
401
|
-
|
|
878
|
+
data: App.PageData & Record<string, any>;
|
|
402
879
|
/**
|
|
403
|
-
*
|
|
404
|
-
* @default "src/service-worker"
|
|
880
|
+
* Filled only after a form submission. See [form actions](https://kit.svelte.dev/docs/form-actions) for more info.
|
|
405
881
|
*/
|
|
406
|
-
|
|
882
|
+
form: any;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* The shape of a param matcher. See [matching](https://kit.svelte.dev/docs/advanced-routing#matching) for more info.
|
|
887
|
+
*/
|
|
888
|
+
export type ParamMatcher = (param: string) => boolean;
|
|
889
|
+
|
|
890
|
+
export interface RequestEvent<
|
|
891
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
892
|
+
RouteId extends string | null = string | null
|
|
893
|
+
> {
|
|
407
894
|
/**
|
|
408
|
-
*
|
|
409
|
-
* @default "src/app.html"
|
|
895
|
+
* Get or set cookies related to the current request
|
|
410
896
|
*/
|
|
411
|
-
|
|
897
|
+
cookies: Cookies;
|
|
412
898
|
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
899
|
+
* `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
|
|
900
|
+
*
|
|
901
|
+
* - it can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request
|
|
902
|
+
* - it can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context)
|
|
903
|
+
* - 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
|
|
904
|
+
*
|
|
905
|
+
* > Cookies will only be passed through if the target host is the same as the SvelteKit application or a more specific subdomain of it.
|
|
415
906
|
*/
|
|
416
|
-
|
|
417
|
-
};
|
|
418
|
-
/**
|
|
419
|
-
* Inline CSS inside a `<style>` block at the head of the HTML. This option is a number that specifies the maximum length of a CSS file to be inlined. All CSS files needed for the page and smaller than this value are merged and inlined in a `<style>` block.
|
|
420
|
-
*
|
|
421
|
-
* > This results in fewer initial requests and can improve your [First Contentful Paint](https://web.dev/first-contentful-paint) score. However, it generates larger HTML output and reduces the effectiveness of browser caches. Use it advisedly.
|
|
422
|
-
* @default 0
|
|
423
|
-
*/
|
|
424
|
-
inlineStyleThreshold?: number;
|
|
425
|
-
/**
|
|
426
|
-
* An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.kit.moduleExtensions` will be ignored by the router.
|
|
427
|
-
* @default [".js", ".ts"]
|
|
428
|
-
*/
|
|
429
|
-
moduleExtensions?: string[];
|
|
430
|
-
/**
|
|
431
|
-
* The directory that SvelteKit writes files to during `dev` and `build`. You should exclude this directory from version control.
|
|
432
|
-
* @default ".svelte-kit"
|
|
433
|
-
*/
|
|
434
|
-
outDir?: string;
|
|
435
|
-
/**
|
|
436
|
-
* Options related to the build output format
|
|
437
|
-
*/
|
|
438
|
-
output?: {
|
|
907
|
+
fetch: typeof fetch;
|
|
439
908
|
/**
|
|
440
|
-
*
|
|
441
|
-
* are three strategies with different trade-offs:
|
|
442
|
-
* - `modulepreload` - uses `<link rel="modulepreload">`. This delivers the best results in Chromium-based browsers, but is currently ignored by Firefox and Safari (though support is coming to Safari soon).
|
|
443
|
-
* - `preload-js` - uses `<link rel="preload">`. Prevents waterfalls in Chromium and Safari, but Chromium will parse each module twice (once as a script, once as a module). Causes modules to be requested twice in Firefox. This is a good setting if you want to maximise performance for users on iOS devices at the cost of a very slight degradation for Chromium users.
|
|
444
|
-
* - `preload-mjs` - uses `<link rel="preload">` but with the `.mjs` extension which prevents double-parsing in Chromium. Some static webservers will fail to serve .mjs files with a `Content-Type: application/javascript` header, which will cause your application to break. If that doesn't apply to you, this is the option that will deliver the best performance for the largest number of users, until `modulepreload` is more widely supported.
|
|
445
|
-
* @default "modulepreload"
|
|
909
|
+
* The client's IP address, set by the adapter.
|
|
446
910
|
*/
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
911
|
+
getClientAddress(): string;
|
|
912
|
+
/**
|
|
913
|
+
* Contains custom data that was added to the request within the [`handle hook`](https://kit.svelte.dev/docs/hooks#server-hooks-handle).
|
|
914
|
+
*/
|
|
915
|
+
locals: App.Locals;
|
|
916
|
+
/**
|
|
917
|
+
* The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
918
|
+
*/
|
|
919
|
+
params: Params;
|
|
920
|
+
/**
|
|
921
|
+
* Additional data made available through the adapter.
|
|
922
|
+
*/
|
|
923
|
+
platform: Readonly<App.Platform> | undefined;
|
|
450
924
|
/**
|
|
451
|
-
*
|
|
452
|
-
* @default ""
|
|
925
|
+
* The original request object
|
|
453
926
|
*/
|
|
454
|
-
|
|
927
|
+
request: Request;
|
|
455
928
|
/**
|
|
456
|
-
*
|
|
457
|
-
* @default ""
|
|
929
|
+
* Info about the current route
|
|
458
930
|
*/
|
|
459
|
-
|
|
931
|
+
route: {
|
|
932
|
+
/**
|
|
933
|
+
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
934
|
+
*/
|
|
935
|
+
id: RouteId;
|
|
936
|
+
};
|
|
460
937
|
/**
|
|
461
|
-
*
|
|
938
|
+
* 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:
|
|
462
939
|
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
940
|
+
* ```js
|
|
941
|
+
* /// file: src/routes/blog/+page.js
|
|
942
|
+
* export async function load({ fetch, setHeaders }) {
|
|
943
|
+
* const url = `https://cms.example.com/articles.json`;
|
|
944
|
+
* const response = await fetch(url);
|
|
465
945
|
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
946
|
+
* setHeaders({
|
|
947
|
+
* age: response.headers.get('age'),
|
|
948
|
+
* 'cache-control': response.headers.get('cache-control')
|
|
949
|
+
* });
|
|
950
|
+
*
|
|
951
|
+
* return response.json();
|
|
952
|
+
* }
|
|
953
|
+
* ```
|
|
954
|
+
*
|
|
955
|
+
* Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
|
|
956
|
+
*
|
|
957
|
+
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#public-types-cookies) API instead.
|
|
468
958
|
*/
|
|
469
|
-
|
|
470
|
-
};
|
|
471
|
-
/**
|
|
472
|
-
* See [Prerendering](https://kit.svelte.dev/docs/page-options#prerender).
|
|
473
|
-
*/
|
|
474
|
-
prerender?: {
|
|
959
|
+
setHeaders(headers: Record<string, string>): void;
|
|
475
960
|
/**
|
|
476
|
-
*
|
|
477
|
-
* @default 1
|
|
961
|
+
* The requested URL.
|
|
478
962
|
*/
|
|
479
|
-
|
|
963
|
+
url: URL;
|
|
480
964
|
/**
|
|
481
|
-
*
|
|
482
|
-
*
|
|
965
|
+
* `true` if the request comes from the client asking for `+page/layout.server.js` data. The `url` property will be stripped of the internal information
|
|
966
|
+
* related to the data request in this case. Use this property instead if the distinction is important to you.
|
|
483
967
|
*/
|
|
484
|
-
|
|
968
|
+
isDataRequest: boolean;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* 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.
|
|
973
|
+
*
|
|
974
|
+
* 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.
|
|
975
|
+
*/
|
|
976
|
+
export type RequestHandler<
|
|
977
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
978
|
+
RouteId extends string | null = string | null
|
|
979
|
+
> = (event: RequestEvent<Params, RouteId>) => MaybePromise<Response>;
|
|
980
|
+
|
|
981
|
+
export interface ResolveOptions {
|
|
982
|
+
/**
|
|
983
|
+
* Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
|
|
984
|
+
* (they could include an element's opening tag but not its closing tag, for example)
|
|
985
|
+
* but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
|
|
986
|
+
* */
|
|
987
|
+
transformPageChunk?(input: { html: string; done: boolean }): MaybePromise<string | undefined>;
|
|
988
|
+
/**
|
|
989
|
+
* Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
|
|
990
|
+
* By default, none will be included.
|
|
991
|
+
* */
|
|
992
|
+
filterSerializedResponseHeaders?(name: string, value: string): boolean;
|
|
485
993
|
/**
|
|
486
|
-
*
|
|
487
|
-
*
|
|
994
|
+
* Determines what should be added to the `<head>` tag to preload it.
|
|
995
|
+
* By default, `js` and `css` files will be preloaded.
|
|
996
|
+
* */
|
|
997
|
+
preload?(input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }): boolean;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
export interface RouteDefinition<Config = any> {
|
|
1001
|
+
id: string;
|
|
1002
|
+
api: {
|
|
1003
|
+
methods: HttpMethod[];
|
|
1004
|
+
};
|
|
1005
|
+
page: {
|
|
1006
|
+
methods: Extract<HttpMethod, 'GET' | 'POST'>[];
|
|
1007
|
+
};
|
|
1008
|
+
pattern: RegExp;
|
|
1009
|
+
prerender: PrerenderOption;
|
|
1010
|
+
segments: RouteSegment[];
|
|
1011
|
+
methods: HttpMethod[];
|
|
1012
|
+
config: Config;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
export class Server {
|
|
1016
|
+
constructor(manifest: SSRManifest);
|
|
1017
|
+
init(options: ServerInitOptions): Promise<void>;
|
|
1018
|
+
respond(request: Request, options: RequestOptions): Promise<Response>;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
export interface ServerInitOptions {
|
|
1022
|
+
env: Record<string, string>;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
export interface SSRManifest {
|
|
1026
|
+
appDir: string;
|
|
1027
|
+
appPath: string;
|
|
1028
|
+
assets: Set<string>;
|
|
1029
|
+
mimeTypes: Record<string, string>;
|
|
1030
|
+
|
|
1031
|
+
/** private fields */
|
|
1032
|
+
_: {
|
|
1033
|
+
client: NonNullable<BuildData['client']>;
|
|
1034
|
+
nodes: SSRNodeLoader[];
|
|
1035
|
+
routes: SSRRoute[];
|
|
1036
|
+
matchers(): Promise<Record<string, ParamMatcher>>;
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
/**
|
|
1041
|
+
* The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
1042
|
+
* rather than using `ServerLoad` directly.
|
|
1043
|
+
*/
|
|
1044
|
+
export type ServerLoad<
|
|
1045
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1046
|
+
ParentData extends Record<string, any> = Record<string, any>,
|
|
1047
|
+
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1048
|
+
RouteId extends string | null = string | null
|
|
1049
|
+
> = (event: ServerLoadEvent<Params, ParentData, RouteId>) => MaybePromise<OutputData>;
|
|
1050
|
+
|
|
1051
|
+
export interface ServerLoadEvent<
|
|
1052
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1053
|
+
ParentData extends Record<string, any> = Record<string, any>,
|
|
1054
|
+
RouteId extends string | null = string | null
|
|
1055
|
+
> extends RequestEvent<Params, RouteId> {
|
|
1056
|
+
/**
|
|
1057
|
+
* `await parent()` returns data from parent `+layout.server.js` `load` functions.
|
|
1058
|
+
*
|
|
1059
|
+
* 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.
|
|
488
1060
|
*/
|
|
489
|
-
|
|
1061
|
+
parent(): Promise<ParentData>;
|
|
490
1062
|
/**
|
|
491
|
-
*
|
|
1063
|
+
* 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.
|
|
1064
|
+
*
|
|
1065
|
+
* 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`.
|
|
492
1066
|
*
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
1067
|
+
* 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).
|
|
1068
|
+
*
|
|
1069
|
+
* 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).
|
|
1070
|
+
*
|
|
1071
|
+
* 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.
|
|
497
1072
|
*
|
|
498
1073
|
* ```js
|
|
499
|
-
* /// file:
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
* prerender: {
|
|
504
|
-
* handleHttpError: ({ path, referrer, message }) => {
|
|
505
|
-
* // ignore deliberate link to shiny 404 page
|
|
506
|
-
* if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
|
|
507
|
-
* return;
|
|
508
|
-
* }
|
|
1074
|
+
* /// file: src/routes/+page.js
|
|
1075
|
+
* let count = 0;
|
|
1076
|
+
* export async function load({ depends }) {
|
|
1077
|
+
* depends('increase:count');
|
|
509
1078
|
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* }
|
|
513
|
-
* }
|
|
514
|
-
* }
|
|
515
|
-
* };
|
|
1079
|
+
* return { count: count++ };
|
|
1080
|
+
* }
|
|
516
1081
|
* ```
|
|
517
1082
|
*
|
|
518
|
-
*
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
* How to respond when hash links from one prerendered page to another don't correspond to an `id` on the destination page.
|
|
1083
|
+
* ```html
|
|
1084
|
+
* /// file: src/routes/+page.svelte
|
|
1085
|
+
* <script>
|
|
1086
|
+
* import { invalidate } from '$app/navigation';
|
|
523
1087
|
*
|
|
524
|
-
*
|
|
525
|
-
* - `'ignore'` - silently ignore the failure and continue
|
|
526
|
-
* - `'warn'` — continue, but print a warning
|
|
527
|
-
* - `(details) => void` — a custom error handler that takes a `details` object with `path`, `id`, `referrers` and `message` properties. If you `throw` from this function, the build will fail
|
|
1088
|
+
* export let data;
|
|
528
1089
|
*
|
|
529
|
-
*
|
|
1090
|
+
* const increase = async () => {
|
|
1091
|
+
* await invalidate('increase:count');
|
|
1092
|
+
* }
|
|
1093
|
+
* </script>
|
|
1094
|
+
*
|
|
1095
|
+
* <p>{data.count}<p>
|
|
1096
|
+
* <button on:click={increase}>Increase Count</button>
|
|
1097
|
+
* ```
|
|
530
1098
|
*/
|
|
531
|
-
|
|
1099
|
+
depends(...deps: string[]): void;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Shape of a form action method that is part of `export const actions = {..}` in `+page.server.js`.
|
|
1104
|
+
* See [form actions](https://kit.svelte.dev/docs/form-actions) for more information.
|
|
1105
|
+
*/
|
|
1106
|
+
export type Action<
|
|
1107
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1108
|
+
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1109
|
+
RouteId extends string | null = string | null
|
|
1110
|
+
> = (event: RequestEvent<Params, RouteId>) => MaybePromise<OutputData>;
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Shape of the `export const actions = {..}` object in `+page.server.js`.
|
|
1114
|
+
* See [form actions](https://kit.svelte.dev/docs/form-actions) for more information.
|
|
1115
|
+
*/
|
|
1116
|
+
export type Actions<
|
|
1117
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1118
|
+
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1119
|
+
RouteId extends string | null = string | null
|
|
1120
|
+
> = Record<string, Action<Params, OutputData, RouteId>>;
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* When calling a form action via fetch, the response will be one of these shapes.
|
|
1124
|
+
* ```svelte
|
|
1125
|
+
* <form method="post" use:enhance={() => {
|
|
1126
|
+
* return ({ result }) => {
|
|
1127
|
+
* // result is of type ActionResult
|
|
1128
|
+
* };
|
|
1129
|
+
* }}
|
|
1130
|
+
* ```
|
|
1131
|
+
*/
|
|
1132
|
+
export type ActionResult<
|
|
1133
|
+
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1134
|
+
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
1135
|
+
> =
|
|
1136
|
+
| { type: 'success'; status: number; data?: Success }
|
|
1137
|
+
| { type: 'failure'; status: number; data?: Failure }
|
|
1138
|
+
| { type: 'redirect'; status: number; location: string }
|
|
1139
|
+
| { type: 'error'; status?: number; error: any };
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* The object returned by the [`error`](https://kit.svelte.dev/docs/modules#sveltejs-kit-error) function.
|
|
1143
|
+
*/
|
|
1144
|
+
export interface HttpError {
|
|
1145
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
|
|
1146
|
+
status: number;
|
|
1147
|
+
/** The content of the error. */
|
|
1148
|
+
body: App.Error;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* The object returned by the [`redirect`](https://kit.svelte.dev/docs/modules#sveltejs-kit-redirect) function
|
|
1153
|
+
*/
|
|
1154
|
+
export interface Redirect {
|
|
1155
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
|
|
1156
|
+
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
1157
|
+
/** The location to redirect to. */
|
|
1158
|
+
location: string;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
export type SubmitFunction<
|
|
1162
|
+
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1163
|
+
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
1164
|
+
> = (input: {
|
|
1165
|
+
action: URL;
|
|
532
1166
|
/**
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
*
|
|
1167
|
+
* use `formData` instead of `data`
|
|
1168
|
+
* */
|
|
1169
|
+
data: FormData;
|
|
1170
|
+
formData: FormData;
|
|
1171
|
+
/**
|
|
1172
|
+
* use `formElement` instead of `form`
|
|
1173
|
+
* */
|
|
1174
|
+
form: HTMLFormElement;
|
|
1175
|
+
formElement: HTMLFormElement;
|
|
1176
|
+
controller: AbortController;
|
|
1177
|
+
submitter: HTMLElement | null;
|
|
1178
|
+
cancel(): void;
|
|
1179
|
+
}) => MaybePromise<
|
|
1180
|
+
| void
|
|
1181
|
+
| ((opts: {
|
|
1182
|
+
/**
|
|
1183
|
+
* use `formData` instead of `data`
|
|
1184
|
+
* */
|
|
1185
|
+
data: FormData;
|
|
1186
|
+
formData: FormData;
|
|
1187
|
+
/**
|
|
1188
|
+
* use `formElement` instead of `form`
|
|
1189
|
+
* */
|
|
1190
|
+
form: HTMLFormElement;
|
|
1191
|
+
formElement: HTMLFormElement;
|
|
1192
|
+
action: URL;
|
|
1193
|
+
result: ActionResult<Success, Failure>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Call this to get the default behavior of a form submission response.
|
|
1196
|
+
* */
|
|
1197
|
+
update(options?: { reset: boolean }): Promise<void>;
|
|
1198
|
+
}) => void)
|
|
1199
|
+
>;
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* The type of `export const snapshot` exported from a page or layout component.
|
|
1203
|
+
*/
|
|
1204
|
+
export interface Snapshot<T = any> {
|
|
1205
|
+
capture: () => T;
|
|
1206
|
+
restore: (snapshot: T) => void;
|
|
1207
|
+
}
|
|
1208
|
+
export interface AdapterEntry {
|
|
1209
|
+
/**
|
|
1210
|
+
* A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
|
|
1211
|
+
* For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
|
|
1212
|
+
* be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
|
|
1213
|
+
*/
|
|
1214
|
+
id: string;
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* A function that compares the candidate route with the current route to determine
|
|
1218
|
+
* if it should be grouped with the current route.
|
|
539
1219
|
*
|
|
540
|
-
*
|
|
1220
|
+
* Use cases:
|
|
1221
|
+
* - Fallback pages: `/foo/[c]` is a fallback for `/foo/a-[b]`, and `/[...catchall]` is a fallback for all routes
|
|
1222
|
+
* - Grouping routes that share a common `config`: `/foo` should be deployed to the edge, `/bar` and `/baz` should be deployed to a serverless function
|
|
541
1223
|
*/
|
|
542
|
-
|
|
1224
|
+
filter(route: RouteDefinition): boolean;
|
|
1225
|
+
|
|
543
1226
|
/**
|
|
544
|
-
*
|
|
545
|
-
*
|
|
1227
|
+
* A function that is invoked once the entry has been created. This is where you
|
|
1228
|
+
* should write the function to the filesystem and generate redirect manifests.
|
|
546
1229
|
*/
|
|
547
|
-
|
|
548
|
-
}
|
|
549
|
-
|
|
1230
|
+
complete(entry: { generateManifest(opts: { relativePath: string }): string }): MaybePromise<void>;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
// Based on https://github.com/josh-hemphill/csp-typed-directives/blob/latest/src/csp.types.ts
|
|
1234
|
+
//
|
|
1235
|
+
// MIT License
|
|
1236
|
+
//
|
|
1237
|
+
// Copyright (c) 2021-present, Joshua Hemphill
|
|
1238
|
+
// Copyright (c) 2021, Tecnico Corporation
|
|
1239
|
+
//
|
|
1240
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1241
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
1242
|
+
// in the Software without restriction, including without limitation the rights
|
|
1243
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
1244
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
1245
|
+
// furnished to do so, subject to the following conditions:
|
|
1246
|
+
//
|
|
1247
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
1248
|
+
// copies or substantial portions of the Software.
|
|
1249
|
+
//
|
|
1250
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1251
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1252
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1253
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1254
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1255
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1256
|
+
// SOFTWARE.
|
|
1257
|
+
|
|
1258
|
+
export namespace Csp {
|
|
1259
|
+
type ActionSource = 'strict-dynamic' | 'report-sample';
|
|
1260
|
+
type BaseSource =
|
|
1261
|
+
| 'self'
|
|
1262
|
+
| 'unsafe-eval'
|
|
1263
|
+
| 'unsafe-hashes'
|
|
1264
|
+
| 'unsafe-inline'
|
|
1265
|
+
| 'wasm-unsafe-eval'
|
|
1266
|
+
| 'none';
|
|
1267
|
+
type CryptoSource = `${'nonce' | 'sha256' | 'sha384' | 'sha512'}-${string}`;
|
|
1268
|
+
type FrameSource = HostSource | SchemeSource | 'self' | 'none';
|
|
1269
|
+
type HostNameScheme = `${string}.${string}` | 'localhost';
|
|
1270
|
+
type HostSource = `${HostProtocolSchemes}${HostNameScheme}${PortScheme}`;
|
|
1271
|
+
type HostProtocolSchemes = `${string}://` | '';
|
|
1272
|
+
type HttpDelineator = '/' | '?' | '#' | '\\';
|
|
1273
|
+
type PortScheme = `:${number}` | '' | ':*';
|
|
1274
|
+
type SchemeSource = 'http:' | 'https:' | 'data:' | 'mediastream:' | 'blob:' | 'filesystem:';
|
|
1275
|
+
type Source = HostSource | SchemeSource | CryptoSource | BaseSource;
|
|
1276
|
+
type Sources = Source[];
|
|
1277
|
+
type UriPath = `${HttpDelineator}${string}`;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
export interface CspDirectives {
|
|
1281
|
+
'child-src'?: Csp.Sources;
|
|
1282
|
+
'default-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
1283
|
+
'frame-src'?: Csp.Sources;
|
|
1284
|
+
'worker-src'?: Csp.Sources;
|
|
1285
|
+
'connect-src'?: Csp.Sources;
|
|
1286
|
+
'font-src'?: Csp.Sources;
|
|
1287
|
+
'img-src'?: Csp.Sources;
|
|
1288
|
+
'manifest-src'?: Csp.Sources;
|
|
1289
|
+
'media-src'?: Csp.Sources;
|
|
1290
|
+
'object-src'?: Csp.Sources;
|
|
1291
|
+
'prefetch-src'?: Csp.Sources;
|
|
1292
|
+
'script-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
1293
|
+
'script-src-elem'?: Csp.Sources;
|
|
1294
|
+
'script-src-attr'?: Csp.Sources;
|
|
1295
|
+
'style-src'?: Array<Csp.Source | Csp.ActionSource>;
|
|
1296
|
+
'style-src-elem'?: Csp.Sources;
|
|
1297
|
+
'style-src-attr'?: Csp.Sources;
|
|
1298
|
+
'base-uri'?: Array<Csp.Source | Csp.ActionSource>;
|
|
1299
|
+
sandbox?: Array<
|
|
1300
|
+
| 'allow-downloads-without-user-activation'
|
|
1301
|
+
| 'allow-forms'
|
|
1302
|
+
| 'allow-modals'
|
|
1303
|
+
| 'allow-orientation-lock'
|
|
1304
|
+
| 'allow-pointer-lock'
|
|
1305
|
+
| 'allow-popups'
|
|
1306
|
+
| 'allow-popups-to-escape-sandbox'
|
|
1307
|
+
| 'allow-presentation'
|
|
1308
|
+
| 'allow-same-origin'
|
|
1309
|
+
| 'allow-scripts'
|
|
1310
|
+
| 'allow-storage-access-by-user-activation'
|
|
1311
|
+
| 'allow-top-navigation'
|
|
1312
|
+
| 'allow-top-navigation-by-user-activation'
|
|
1313
|
+
>;
|
|
1314
|
+
'form-action'?: Array<Csp.Source | Csp.ActionSource>;
|
|
1315
|
+
'frame-ancestors'?: Array<Csp.HostSource | Csp.SchemeSource | Csp.FrameSource>;
|
|
1316
|
+
'navigate-to'?: Array<Csp.Source | Csp.ActionSource>;
|
|
1317
|
+
'report-uri'?: Csp.UriPath[];
|
|
1318
|
+
'report-to'?: string[];
|
|
1319
|
+
|
|
1320
|
+
'require-trusted-types-for'?: Array<'script'>;
|
|
1321
|
+
'trusted-types'?: Array<'none' | 'allow-duplicates' | '*' | string>;
|
|
1322
|
+
'upgrade-insecure-requests'?: boolean;
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
'require-sri-for'?: Array<'script' | 'style' | 'script style'>;
|
|
1326
|
+
|
|
1327
|
+
|
|
1328
|
+
'block-all-mixed-content'?: boolean;
|
|
1329
|
+
|
|
1330
|
+
|
|
1331
|
+
'plugin-types'?: Array<`${string}/${string}` | 'none'>;
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
|
+
referrer?: Array<
|
|
1335
|
+
| 'no-referrer'
|
|
1336
|
+
| 'no-referrer-when-downgrade'
|
|
1337
|
+
| 'origin'
|
|
1338
|
+
| 'origin-when-cross-origin'
|
|
1339
|
+
| 'same-origin'
|
|
1340
|
+
| 'strict-origin'
|
|
1341
|
+
| 'strict-origin-when-cross-origin'
|
|
1342
|
+
| 'unsafe-url'
|
|
1343
|
+
| 'none'
|
|
1344
|
+
>;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS';
|
|
1348
|
+
|
|
1349
|
+
export interface Logger {
|
|
1350
|
+
(msg: string): void;
|
|
1351
|
+
success(msg: string): void;
|
|
1352
|
+
error(msg: string): void;
|
|
1353
|
+
warn(msg: string): void;
|
|
1354
|
+
minor(msg: string): void;
|
|
1355
|
+
info(msg: string): void;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
1359
|
+
|
|
1360
|
+
export interface Prerendered {
|
|
550
1361
|
/**
|
|
551
|
-
*
|
|
552
|
-
* @default true
|
|
1362
|
+
* A map of `path` to `{ file }` objects, where a path like `/foo` corresponds to `foo.html` and a path like `/bar/` corresponds to `bar/index.html`.
|
|
553
1363
|
*/
|
|
554
|
-
|
|
1364
|
+
pages: Map<
|
|
1365
|
+
string,
|
|
1366
|
+
{
|
|
1367
|
+
/** The location of the .html file relative to the output directory */
|
|
1368
|
+
file: string;
|
|
1369
|
+
}
|
|
1370
|
+
>;
|
|
555
1371
|
/**
|
|
556
|
-
*
|
|
557
|
-
* @default (filename) => !/\.DS_Store/.test(filename)
|
|
1372
|
+
* A map of `path` to `{ type }` objects.
|
|
558
1373
|
*/
|
|
559
|
-
|
|
1374
|
+
assets: Map<
|
|
1375
|
+
string,
|
|
1376
|
+
{
|
|
1377
|
+
/** The MIME type of the asset */
|
|
1378
|
+
type: string;
|
|
1379
|
+
}
|
|
1380
|
+
>;
|
|
1381
|
+
/**
|
|
1382
|
+
* A map of redirects encountered during prerendering.
|
|
1383
|
+
*/
|
|
1384
|
+
redirects: Map<
|
|
1385
|
+
string,
|
|
1386
|
+
{
|
|
1387
|
+
status: number;
|
|
1388
|
+
location: string;
|
|
1389
|
+
}
|
|
1390
|
+
>;
|
|
1391
|
+
/** An array of prerendered paths (without trailing slashes, regardless of the trailingSlash config) */
|
|
1392
|
+
paths: string[];
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
export interface PrerenderHttpErrorHandler {
|
|
1396
|
+
(details: {
|
|
1397
|
+
status: number;
|
|
1398
|
+
path: string;
|
|
1399
|
+
referrer: string | null;
|
|
1400
|
+
referenceType: 'linked' | 'fetched';
|
|
1401
|
+
message: string;
|
|
1402
|
+
}): void;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
export interface PrerenderMissingIdHandler {
|
|
1406
|
+
(details: { path: string; id: string; referrers: string[]; message: string }): void;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
export interface PrerenderEntryGeneratorMismatchHandler {
|
|
1410
|
+
(details: { generatedFromId: string; entry: string; matchedId: string; message: string }): void;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
export type PrerenderHttpErrorHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderHttpErrorHandler;
|
|
1414
|
+
export type PrerenderMissingIdHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderMissingIdHandler;
|
|
1415
|
+
export type PrerenderEntryGeneratorMismatchHandlerValue =
|
|
1416
|
+
| 'fail'
|
|
1417
|
+
| 'warn'
|
|
1418
|
+
| 'ignore'
|
|
1419
|
+
| PrerenderEntryGeneratorMismatchHandler;
|
|
1420
|
+
|
|
1421
|
+
export type PrerenderOption = boolean | 'auto';
|
|
1422
|
+
|
|
1423
|
+
export type PrerenderMap = Map<string, PrerenderOption>;
|
|
1424
|
+
|
|
1425
|
+
export interface RequestOptions {
|
|
1426
|
+
getClientAddress(): string;
|
|
1427
|
+
platform?: App.Platform;
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
export interface RouteSegment {
|
|
1431
|
+
content: string;
|
|
1432
|
+
dynamic: boolean;
|
|
1433
|
+
rest: boolean;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
export type TrailingSlash = 'never' | 'always' | 'ignore';
|
|
1437
|
+
/**
|
|
1438
|
+
* This is a grotesque hack that, in dev, allows us to replace the implementations
|
|
1439
|
+
* of these classes that you'd get by importing them from `@sveltejs/kit` with the
|
|
1440
|
+
* ones that are imported via Vite and loaded internally, so that instanceof
|
|
1441
|
+
* checks work even though SvelteKit imports this module via Vite and consumers
|
|
1442
|
+
* import it via Node
|
|
1443
|
+
* */
|
|
1444
|
+
function replace_implementations(implementations: {
|
|
1445
|
+
ActionFailure: typeof ActionFailure;
|
|
1446
|
+
HttpError: typeof HttpError;
|
|
1447
|
+
Redirect: typeof Redirect;
|
|
1448
|
+
}): void;
|
|
1449
|
+
export class HttpError {
|
|
1450
|
+
|
|
1451
|
+
constructor(status: number, body: {
|
|
1452
|
+
message: string;
|
|
1453
|
+
} extends App.Error ? (App.Error | string | undefined) : App.Error);
|
|
1454
|
+
status: number;
|
|
1455
|
+
body: App.Error;
|
|
1456
|
+
toString(): string;
|
|
1457
|
+
}
|
|
1458
|
+
export class Redirect {
|
|
1459
|
+
|
|
1460
|
+
constructor(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, location: string);
|
|
1461
|
+
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
1462
|
+
location: string;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
class ActionFailure<T extends Record<string, unknown> | undefined = undefined> {
|
|
1466
|
+
|
|
1467
|
+
constructor(status: number, data?: T | undefined);
|
|
1468
|
+
status: number;
|
|
1469
|
+
data: T | undefined;
|
|
1470
|
+
}
|
|
1471
|
+
import { SvelteComponent } from 'svelte/internal';
|
|
1472
|
+
|
|
1473
|
+
interface ServerModule {
|
|
1474
|
+
Server: typeof InternalServer;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
interface ServerInternalModule {
|
|
1478
|
+
set_building(building: boolean): void;
|
|
1479
|
+
set_assets(path: string): void;
|
|
1480
|
+
set_private_env(environment: Record<string, string>): void;
|
|
1481
|
+
set_public_env(environment: Record<string, string>): void;
|
|
1482
|
+
set_version(version: string): void;
|
|
1483
|
+
set_fix_stack_trace(fix_stack_trace: (stack: string) => string): void;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
interface Asset {
|
|
1487
|
+
file: string;
|
|
1488
|
+
size: number;
|
|
1489
|
+
type: string | null;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
interface AssetDependencies {
|
|
1493
|
+
file: string;
|
|
1494
|
+
imports: string[];
|
|
1495
|
+
stylesheets: string[];
|
|
1496
|
+
fonts: string[];
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
interface BuildData {
|
|
1500
|
+
app_dir: string;
|
|
1501
|
+
app_path: string;
|
|
1502
|
+
manifest_data: ManifestData;
|
|
1503
|
+
service_worker: string | null;
|
|
1504
|
+
client: {
|
|
1505
|
+
start: string;
|
|
1506
|
+
app: string;
|
|
1507
|
+
imports: string[];
|
|
1508
|
+
stylesheets: string[];
|
|
1509
|
+
fonts: string[];
|
|
1510
|
+
} | null;
|
|
1511
|
+
server_manifest: import('vite').Manifest;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
interface CSRPageNode {
|
|
1515
|
+
component: typeof SvelteComponent;
|
|
1516
|
+
universal: {
|
|
1517
|
+
load?: Load;
|
|
1518
|
+
trailingSlash?: TrailingSlash;
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
type CSRPageNodeLoader = () => Promise<CSRPageNode>;
|
|
1523
|
+
|
|
1524
|
+
/**
|
|
1525
|
+
* Definition of a client side route.
|
|
1526
|
+
* The boolean in the tuples indicates whether the route has a server load.
|
|
1527
|
+
*/
|
|
1528
|
+
type CSRRoute = {
|
|
1529
|
+
id: string;
|
|
1530
|
+
exec(path: string): undefined | Record<string, string>;
|
|
1531
|
+
errors: Array<CSRPageNodeLoader | undefined>;
|
|
1532
|
+
layouts: Array<[has_server_load: boolean, node_loader: CSRPageNodeLoader] | undefined>;
|
|
1533
|
+
leaf: [has_server_load: boolean, node_loader: CSRPageNodeLoader];
|
|
560
1534
|
};
|
|
561
|
-
|
|
1535
|
+
|
|
1536
|
+
interface Deferred {
|
|
1537
|
+
fulfil: (value: any) => void;
|
|
1538
|
+
reject: (error: Error) => void;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
type GetParams = (match: RegExpExecArray) => Record<string, string>;
|
|
1542
|
+
|
|
1543
|
+
interface ServerHooks {
|
|
1544
|
+
handleFetch: HandleFetch;
|
|
1545
|
+
handle: Handle;
|
|
1546
|
+
handleError: HandleServerError;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
interface ClientHooks {
|
|
1550
|
+
handleError: HandleClientError;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
interface Env {
|
|
1554
|
+
private: Record<string, string>;
|
|
1555
|
+
public: Record<string, string>;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
class InternalServer extends Server {
|
|
1559
|
+
init(options: ServerInitOptions): Promise<void>;
|
|
1560
|
+
respond(
|
|
1561
|
+
request: Request,
|
|
1562
|
+
options: RequestOptions & {
|
|
1563
|
+
prerendering?: PrerenderOptions;
|
|
1564
|
+
read: (file: string) => Buffer;
|
|
1565
|
+
}
|
|
1566
|
+
): Promise<Response>;
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
interface ManifestData {
|
|
1570
|
+
assets: Asset[];
|
|
1571
|
+
nodes: PageNode[];
|
|
1572
|
+
routes: RouteData[];
|
|
1573
|
+
matchers: Record<string, string>;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
interface PageNode {
|
|
1577
|
+
depth: number;
|
|
1578
|
+
component?: string; // TODO supply default component if it's missing (bit of an edge case)
|
|
1579
|
+
universal?: string;
|
|
1580
|
+
server?: string;
|
|
1581
|
+
parent_id?: string;
|
|
1582
|
+
parent?: PageNode;
|
|
562
1583
|
/**
|
|
563
|
-
*
|
|
564
|
-
* This is useful for extending a shared `tsconfig.json` in a monorepo root, for example.
|
|
565
|
-
* @default (config) => config
|
|
1584
|
+
* Filled with the pages that reference this layout (if this is a layout)
|
|
566
1585
|
*/
|
|
567
|
-
|
|
1586
|
+
child_pages?: PageNode[];
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
interface PrerenderDependency {
|
|
1590
|
+
response: Response;
|
|
1591
|
+
body: null | string | Uint8Array;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
interface PrerenderOptions {
|
|
1595
|
+
cache?: string; // including this here is a bit of a hack, but it makes it easy to add <meta http-equiv>
|
|
1596
|
+
fallback?: boolean;
|
|
1597
|
+
dependencies: Map<string, PrerenderDependency>;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
type RecursiveRequired<T> = {
|
|
1601
|
+
// Recursive implementation of TypeScript's Required utility type.
|
|
1602
|
+
// Will recursively continue until it reaches a primitive or Function
|
|
1603
|
+
[K in keyof T]-?: Extract<T[K], Function> extends never // If it does not have a Function type
|
|
1604
|
+
? RecursiveRequired<T[K]> // recursively continue through.
|
|
1605
|
+
: T[K]; // Use the exact type for everything else
|
|
568
1606
|
};
|
|
1607
|
+
|
|
1608
|
+
type RequiredResolveOptions = Required<ResolveOptions>;
|
|
1609
|
+
|
|
1610
|
+
interface RouteParam {
|
|
1611
|
+
name: string;
|
|
1612
|
+
matcher: string;
|
|
1613
|
+
optional: boolean;
|
|
1614
|
+
rest: boolean;
|
|
1615
|
+
chained: boolean;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
569
1618
|
/**
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
* Not all navigations will result in an error though, for example if the JavaScript for the next page is already loaded. If you still want to force a full-page navigation in these cases, use techniques such as setting the `pollInterval` and then using `beforeNavigate`:
|
|
574
|
-
* ```html
|
|
575
|
-
* /// file: +layout.svelte
|
|
576
|
-
* <script>
|
|
577
|
-
* import { beforeNavigate } from '$app/navigation';
|
|
578
|
-
* import { updated } from '$app/stores';
|
|
579
|
-
*
|
|
580
|
-
* beforeNavigate(({ willUnload, to }) => {
|
|
581
|
-
* if ($updated && !willUnload && to?.url) {
|
|
582
|
-
* location.href = to.url.href;
|
|
583
|
-
* }
|
|
584
|
-
* });
|
|
585
|
-
* </script>
|
|
586
|
-
* ```
|
|
587
|
-
*
|
|
588
|
-
* If you set `pollInterval` to a non-zero value, SvelteKit will poll for new versions in the background and set the value of the [`updated`](/docs/modules#$app-stores-updated) store to `true` when it detects one.
|
|
1619
|
+
* Represents a route segment in the app. It can either be an intermediate node
|
|
1620
|
+
* with only layout/error pages, or a leaf, at which point either `page` and `leaf`
|
|
1621
|
+
* or `endpoint` is set.
|
|
589
1622
|
*/
|
|
590
|
-
|
|
1623
|
+
interface RouteData {
|
|
1624
|
+
id: string;
|
|
1625
|
+
parent: RouteData | null;
|
|
1626
|
+
|
|
1627
|
+
segment: string;
|
|
1628
|
+
pattern: RegExp;
|
|
1629
|
+
params: RouteParam[];
|
|
1630
|
+
|
|
1631
|
+
layout: PageNode | null;
|
|
1632
|
+
error: PageNode | null;
|
|
1633
|
+
leaf: PageNode | null;
|
|
1634
|
+
|
|
1635
|
+
page: {
|
|
1636
|
+
layouts: Array<number | undefined>;
|
|
1637
|
+
errors: Array<number | undefined>;
|
|
1638
|
+
leaf: number;
|
|
1639
|
+
} | null;
|
|
1640
|
+
|
|
1641
|
+
endpoint: {
|
|
1642
|
+
file: string;
|
|
1643
|
+
} | null;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
type ServerRedirectNode = {
|
|
1647
|
+
type: 'redirect';
|
|
1648
|
+
location: string;
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1651
|
+
type ServerNodesResponse = {
|
|
1652
|
+
type: 'data';
|
|
591
1653
|
/**
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
* For example, to use the current commit hash, you could do use `git rev-parse HEAD`:
|
|
595
|
-
*
|
|
596
|
-
* ```js
|
|
597
|
-
* /// file: svelte.config.js
|
|
598
|
-
* import * as child_process from 'node:child_process';
|
|
599
|
-
*
|
|
600
|
-
* export default {
|
|
601
|
-
* kit: {
|
|
602
|
-
* version: {
|
|
603
|
-
* name: child_process.execSync('git rev-parse HEAD').toString().trim()
|
|
604
|
-
* }
|
|
605
|
-
* }
|
|
606
|
-
* };
|
|
607
|
-
* ```
|
|
1654
|
+
* If `null`, then there was no load function <- TODO is this outdated now with the recent changes?
|
|
608
1655
|
*/
|
|
609
|
-
|
|
1656
|
+
nodes: Array<ServerDataNode | ServerDataSkippedNode | ServerErrorNode | null>;
|
|
1657
|
+
};
|
|
1658
|
+
|
|
1659
|
+
type ServerDataResponse = ServerRedirectNode | ServerNodesResponse;
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
* Signals a successful response of the server `load` function.
|
|
1663
|
+
* The `uses` property tells the client when it's possible to reuse this data
|
|
1664
|
+
* in a subsequent request.
|
|
1665
|
+
*/
|
|
1666
|
+
interface ServerDataNode {
|
|
1667
|
+
type: 'data';
|
|
610
1668
|
/**
|
|
611
|
-
* The
|
|
612
|
-
*
|
|
1669
|
+
* The serialized version of this contains a serialized representation of any deferred promises,
|
|
1670
|
+
* which will be resolved later through chunk nodes.
|
|
1671
|
+
*/
|
|
1672
|
+
data: Record<string, any> | null;
|
|
1673
|
+
uses: Uses;
|
|
1674
|
+
slash?: TrailingSlash;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* Resolved data/error of a deferred promise.
|
|
1679
|
+
*/
|
|
1680
|
+
interface ServerDataChunkNode {
|
|
1681
|
+
type: 'chunk';
|
|
1682
|
+
id: number;
|
|
1683
|
+
data?: Record<string, any>;
|
|
1684
|
+
error?: any;
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
/**
|
|
1688
|
+
* Signals that the server `load` function was not run, and the
|
|
1689
|
+
* client should use what it has in memory
|
|
1690
|
+
*/
|
|
1691
|
+
interface ServerDataSkippedNode {
|
|
1692
|
+
type: 'skip';
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
/**
|
|
1696
|
+
* Signals that the server `load` function failed
|
|
1697
|
+
*/
|
|
1698
|
+
interface ServerErrorNode {
|
|
1699
|
+
type: 'error';
|
|
1700
|
+
error: App.Error;
|
|
1701
|
+
/**
|
|
1702
|
+
* Only set for HttpErrors
|
|
613
1703
|
*/
|
|
614
|
-
|
|
1704
|
+
status?: number;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
interface ServerMetadataRoute {
|
|
1708
|
+
config: any;
|
|
1709
|
+
api: {
|
|
1710
|
+
methods: HttpMethod[];
|
|
1711
|
+
};
|
|
1712
|
+
page: {
|
|
1713
|
+
methods: Array<'GET' | 'POST'>;
|
|
1714
|
+
};
|
|
1715
|
+
methods: HttpMethod[];
|
|
1716
|
+
prerender: PrerenderOption | undefined;
|
|
1717
|
+
entries: Array<string> | undefined;
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
interface ServerMetadata {
|
|
1721
|
+
nodes: Array<{ has_server_load: boolean }>;
|
|
1722
|
+
routes: Map<string, ServerMetadataRoute>;
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
interface SSRComponent {
|
|
1726
|
+
default: {
|
|
1727
|
+
render(props: Record<string, any>): {
|
|
1728
|
+
html: string;
|
|
1729
|
+
head: string;
|
|
1730
|
+
css: {
|
|
1731
|
+
code: string;
|
|
1732
|
+
map: any; // TODO
|
|
1733
|
+
};
|
|
1734
|
+
};
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
type SSRComponentLoader = () => Promise<SSRComponent>;
|
|
1739
|
+
|
|
1740
|
+
interface SSRNode {
|
|
1741
|
+
component: SSRComponentLoader;
|
|
1742
|
+
/** index into the `components` array in client/manifest.js */
|
|
1743
|
+
index: number;
|
|
1744
|
+
/** external JS files */
|
|
1745
|
+
imports: string[];
|
|
1746
|
+
/** external CSS files */
|
|
1747
|
+
stylesheets: string[];
|
|
1748
|
+
/** external font files */
|
|
1749
|
+
fonts: string[];
|
|
1750
|
+
/** inlined styles */
|
|
1751
|
+
inline_styles?(): MaybePromise<Record<string, string>>;
|
|
1752
|
+
|
|
1753
|
+
universal: {
|
|
1754
|
+
load?: Load;
|
|
1755
|
+
prerender?: PrerenderOption;
|
|
1756
|
+
ssr?: boolean;
|
|
1757
|
+
csr?: boolean;
|
|
1758
|
+
trailingSlash?: TrailingSlash;
|
|
1759
|
+
config?: any;
|
|
1760
|
+
entries?: PrerenderEntryGenerator;
|
|
1761
|
+
};
|
|
1762
|
+
|
|
1763
|
+
server: {
|
|
1764
|
+
load?: ServerLoad;
|
|
1765
|
+
prerender?: PrerenderOption;
|
|
1766
|
+
ssr?: boolean;
|
|
1767
|
+
csr?: boolean;
|
|
1768
|
+
trailingSlash?: TrailingSlash;
|
|
1769
|
+
actions?: Actions;
|
|
1770
|
+
config?: any;
|
|
1771
|
+
entries?: PrerenderEntryGenerator;
|
|
1772
|
+
};
|
|
1773
|
+
|
|
1774
|
+
universal_id: string;
|
|
1775
|
+
server_id: string;
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
type SSRNodeLoader = () => Promise<SSRNode>;
|
|
1779
|
+
|
|
1780
|
+
interface SSROptions {
|
|
1781
|
+
app_template_contains_nonce: boolean;
|
|
1782
|
+
csp: ValidatedConfig['kit']['csp'];
|
|
1783
|
+
csrf_check_origin: boolean;
|
|
1784
|
+
track_server_fetches: boolean;
|
|
1785
|
+
embedded: boolean;
|
|
1786
|
+
env_public_prefix: string;
|
|
1787
|
+
hooks: ServerHooks;
|
|
1788
|
+
preload_strategy: ValidatedConfig['kit']['output']['preloadStrategy'];
|
|
1789
|
+
root: SSRComponent['default'];
|
|
1790
|
+
service_worker: boolean;
|
|
1791
|
+
templates: {
|
|
1792
|
+
app(values: {
|
|
1793
|
+
head: string;
|
|
1794
|
+
body: string;
|
|
1795
|
+
assets: string;
|
|
1796
|
+
nonce: string;
|
|
1797
|
+
env: Record<string, string>;
|
|
1798
|
+
}): string;
|
|
1799
|
+
error(values: { message: string; status: number }): string;
|
|
1800
|
+
};
|
|
1801
|
+
version_hash: string;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
interface PageNodeIndexes {
|
|
1805
|
+
errors: Array<number | undefined>;
|
|
1806
|
+
layouts: Array<number | undefined>;
|
|
1807
|
+
leaf: number;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
type PrerenderEntryGenerator = () => MaybePromise<Array<Record<string, string>>>;
|
|
1811
|
+
|
|
1812
|
+
type SSREndpoint = Partial<Record<HttpMethod, RequestHandler>> & {
|
|
1813
|
+
prerender?: PrerenderOption;
|
|
1814
|
+
trailingSlash?: TrailingSlash;
|
|
1815
|
+
config?: any;
|
|
1816
|
+
entries?: PrerenderEntryGenerator;
|
|
615
1817
|
};
|
|
616
|
-
}
|
|
617
1818
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
1819
|
+
interface SSRRoute {
|
|
1820
|
+
id: string;
|
|
1821
|
+
pattern: RegExp;
|
|
1822
|
+
params: RouteParam[];
|
|
1823
|
+
page: PageNodeIndexes | null;
|
|
1824
|
+
endpoint: (() => Promise<SSREndpoint>) | null;
|
|
1825
|
+
endpoint_id?: string;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
interface SSRState {
|
|
1829
|
+
fallback?: string;
|
|
1830
|
+
getClientAddress(): string;
|
|
1831
|
+
/**
|
|
1832
|
+
* True if we're currently attempting to render an error page
|
|
1833
|
+
*/
|
|
1834
|
+
error: boolean;
|
|
1835
|
+
/**
|
|
1836
|
+
* Allows us to prevent `event.fetch` from making infinitely looping internal requests
|
|
1837
|
+
*/
|
|
1838
|
+
depth: number;
|
|
1839
|
+
platform?: any;
|
|
1840
|
+
prerendering?: PrerenderOptions;
|
|
1841
|
+
/**
|
|
1842
|
+
* When fetching data from a +server.js endpoint in `load`, the page's
|
|
1843
|
+
* prerender option is inherited by the endpoint, unless overridden
|
|
1844
|
+
*/
|
|
1845
|
+
prerender_default?: PrerenderOption;
|
|
1846
|
+
read?: (file: string) => Buffer;
|
|
1847
|
+
}
|
|
630
1848
|
|
|
631
|
-
|
|
632
|
-
* The server-side [`handleError`](https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror) hook runs when an unexpected error is thrown while responding to a request.
|
|
633
|
-
*
|
|
634
|
-
* If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
|
|
635
|
-
* Make sure that this function _never_ throws an error.
|
|
636
|
-
*/
|
|
637
|
-
export interface HandleServerError {
|
|
638
|
-
(input: { error: unknown; event: RequestEvent }): MaybePromise<void | App.Error>;
|
|
639
|
-
}
|
|
1849
|
+
type StrictBody = string | ArrayBufferView;
|
|
640
1850
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
(input: { error: unknown; event: NavigationEvent }): MaybePromise<void | App.Error>;
|
|
649
|
-
}
|
|
1851
|
+
interface Uses {
|
|
1852
|
+
dependencies: Set<string>;
|
|
1853
|
+
params: Set<string>;
|
|
1854
|
+
parent: boolean;
|
|
1855
|
+
route: boolean;
|
|
1856
|
+
url: boolean;
|
|
1857
|
+
}
|
|
650
1858
|
|
|
651
|
-
|
|
652
|
-
* The [`handleFetch`](https://kit.svelte.dev/docs/hooks#server-hooks-handlefetch) hook allows you to modify (or replace) a `fetch` request that happens inside a `load` function that runs on the server (or during pre-rendering)
|
|
653
|
-
*/
|
|
654
|
-
export interface HandleFetch {
|
|
655
|
-
(input: { event: RequestEvent; request: Request; fetch: typeof fetch }): MaybePromise<Response>;
|
|
656
|
-
}
|
|
1859
|
+
type ValidatedConfig = RecursiveRequired<Config>;
|
|
657
1860
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
1861
|
+
type ValidatedKitConfig = RecursiveRequired<KitConfig>;
|
|
1862
|
+
export function error(status: number, body: App.Error): HttpError;
|
|
1863
|
+
export function error(status: number, body?: {
|
|
1864
|
+
message: string;
|
|
1865
|
+
} extends App.Error ? App.Error | string | undefined : never): HttpError;
|
|
1866
|
+
/**
|
|
1867
|
+
* Create a `Redirect` object. If thrown during request handling, SvelteKit will return a redirect response.
|
|
1868
|
+
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
|
|
1869
|
+
* */
|
|
1870
|
+
export function redirect(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, location: string): Redirect;
|
|
1871
|
+
/**
|
|
1872
|
+
* Create a JSON `Response` object from the supplied data.
|
|
1873
|
+
* */
|
|
1874
|
+
export function json(data: any, init?: ResponseInit | undefined): Response;
|
|
1875
|
+
/**
|
|
1876
|
+
* Create a `Response` object from the supplied body.
|
|
1877
|
+
* */
|
|
1878
|
+
export function text(body: string, init?: ResponseInit | undefined): Response;
|
|
1879
|
+
/**
|
|
1880
|
+
* Create an `ActionFailure` object.
|
|
1881
|
+
* */
|
|
1882
|
+
export function fail<T extends Record<string, unknown> | undefined = undefined>(status: number, data?: T | undefined): ActionFailure<T>;
|
|
1883
|
+
/**
|
|
1884
|
+
* Populate a route ID with params to resolve a pathname.
|
|
1885
|
+
* @example
|
|
1886
|
+
* ```js
|
|
1887
|
+
* resolvePath(
|
|
1888
|
+
* `/blog/[slug]/[...somethingElse]`,
|
|
1889
|
+
* {
|
|
1890
|
+
* slug: 'hello-world',
|
|
1891
|
+
* somethingElse: 'something/else'
|
|
1892
|
+
* }
|
|
1893
|
+
* ); // `/blog/hello-world/something/else`
|
|
1894
|
+
* ```
|
|
1895
|
+
* */
|
|
1896
|
+
export function resolvePath(id: string, params: Record<string, string | undefined>): string;
|
|
670
1897
|
}
|
|
671
1898
|
|
|
672
|
-
|
|
673
|
-
* The generic form of `PageLoadEvent` and `LayoutLoadEvent`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
674
|
-
* rather than using `LoadEvent` directly.
|
|
675
|
-
*/
|
|
676
|
-
export interface LoadEvent<
|
|
677
|
-
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
678
|
-
Data extends Record<string, unknown> | null = Record<string, any> | null,
|
|
679
|
-
ParentData extends Record<string, unknown> = Record<string, any>,
|
|
680
|
-
RouteId extends string | null = string | null
|
|
681
|
-
> extends NavigationEvent<Params, RouteId> {
|
|
682
|
-
/**
|
|
683
|
-
* `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
|
|
684
|
-
*
|
|
685
|
-
* - it can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request
|
|
686
|
-
* - it can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context)
|
|
687
|
-
* - 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
|
|
688
|
-
* - 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)
|
|
689
|
-
* - during hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request
|
|
690
|
-
*
|
|
691
|
-
* > Cookies will only be passed through if the target host is the same as the SvelteKit application or a more specific subdomain of it.
|
|
692
|
-
*/
|
|
693
|
-
fetch: typeof fetch;
|
|
694
|
-
/**
|
|
695
|
-
* Contains the data returned by the route's server `load` function (in `+layout.server.js` or `+page.server.js`), if any.
|
|
696
|
-
*/
|
|
697
|
-
data: Data;
|
|
698
|
-
/**
|
|
699
|
-
* 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:
|
|
700
|
-
*
|
|
701
|
-
* ```js
|
|
702
|
-
* /// file: src/routes/blog/+page.js
|
|
703
|
-
* export async function load({ fetch, setHeaders }) {
|
|
704
|
-
* const url = `https://cms.example.com/articles.json`;
|
|
705
|
-
* const response = await fetch(url);
|
|
706
|
-
*
|
|
707
|
-
* setHeaders({
|
|
708
|
-
* age: response.headers.get('age'),
|
|
709
|
-
* 'cache-control': response.headers.get('cache-control')
|
|
710
|
-
* });
|
|
711
|
-
*
|
|
712
|
-
* return response.json();
|
|
713
|
-
* }
|
|
714
|
-
* ```
|
|
715
|
-
*
|
|
716
|
-
* Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
|
|
717
|
-
*
|
|
718
|
-
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#public-types-cookies) API in a server-only `load` function instead.
|
|
719
|
-
*
|
|
720
|
-
* `setHeaders` has no effect when a `load` function runs in the browser.
|
|
721
|
-
*/
|
|
722
|
-
setHeaders(headers: Record<string, string>): void;
|
|
723
|
-
/**
|
|
724
|
-
* `await parent()` returns data from parent `+layout.js` `load` functions.
|
|
725
|
-
* 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.
|
|
726
|
-
*
|
|
727
|
-
* 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.
|
|
728
|
-
*/
|
|
729
|
-
parent(): Promise<ParentData>;
|
|
1899
|
+
declare module '@sveltejs/kit/hooks' {
|
|
730
1900
|
/**
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
* 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).
|
|
738
|
-
*
|
|
739
|
-
* 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.
|
|
1901
|
+
* A helper function for sequencing multiple `handle` calls in a middleware-like manner.
|
|
1902
|
+
* The behavior for the `handle` options is as follows:
|
|
1903
|
+
* - `transformPageChunk` is applied in reverse order and merged
|
|
1904
|
+
* - `preload` is applied in forward order, the first option "wins" and no `preload` options after it are called
|
|
1905
|
+
* - `filterSerializedResponseHeaders` behaves the same as `preload`
|
|
740
1906
|
*
|
|
741
1907
|
* ```js
|
|
742
|
-
* /// file: src/
|
|
743
|
-
*
|
|
744
|
-
* export async function load({ depends }) {
|
|
745
|
-
* depends('increase:count');
|
|
1908
|
+
* /// file: src/hooks.server.js
|
|
1909
|
+
* import { sequence } from '@sveltejs/kit/hooks';
|
|
746
1910
|
*
|
|
747
|
-
*
|
|
1911
|
+
* /// type: import('@sveltejs/kit').Handle
|
|
1912
|
+
* async function first({ event, resolve }) {
|
|
1913
|
+
* console.log('first pre-processing');
|
|
1914
|
+
* const result = await resolve(event, {
|
|
1915
|
+
* transformPageChunk: ({ html }) => {
|
|
1916
|
+
* // transforms are applied in reverse order
|
|
1917
|
+
* console.log('first transform');
|
|
1918
|
+
* return html;
|
|
1919
|
+
* },
|
|
1920
|
+
* preload: () => {
|
|
1921
|
+
* // this one wins as it's the first defined in the chain
|
|
1922
|
+
* console.log('first preload');
|
|
1923
|
+
* }
|
|
1924
|
+
* });
|
|
1925
|
+
* console.log('first post-processing');
|
|
1926
|
+
* return result;
|
|
748
1927
|
* }
|
|
749
|
-
* ```
|
|
750
1928
|
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
1929
|
+
* /// type: import('@sveltejs/kit').Handle
|
|
1930
|
+
* async function second({ event, resolve }) {
|
|
1931
|
+
* console.log('second pre-processing');
|
|
1932
|
+
* const result = await resolve(event, {
|
|
1933
|
+
* transformPageChunk: ({ html }) => {
|
|
1934
|
+
* console.log('second transform');
|
|
1935
|
+
* return html;
|
|
1936
|
+
* },
|
|
1937
|
+
* preload: () => {
|
|
1938
|
+
* console.log('second preload');
|
|
1939
|
+
* },
|
|
1940
|
+
* filterSerializedResponseHeaders: () => {
|
|
1941
|
+
* // this one wins as it's the first defined in the chain
|
|
1942
|
+
* console.log('second filterSerializedResponseHeaders');
|
|
1943
|
+
* }
|
|
1944
|
+
* });
|
|
1945
|
+
* console.log('second post-processing');
|
|
1946
|
+
* return result;
|
|
1947
|
+
* }
|
|
755
1948
|
*
|
|
756
|
-
*
|
|
1949
|
+
* export const handle = sequence(first, second);
|
|
1950
|
+
* ```
|
|
757
1951
|
*
|
|
758
|
-
*
|
|
759
|
-
* await invalidate('increase:count');
|
|
760
|
-
* }
|
|
761
|
-
* </script>
|
|
1952
|
+
* The example above would print:
|
|
762
1953
|
*
|
|
763
|
-
* <p>{data.count}<p>
|
|
764
|
-
* <button on:click={increase}>Increase Count</button>
|
|
765
1954
|
* ```
|
|
766
|
-
|
|
767
|
-
|
|
1955
|
+
* first pre-processing
|
|
1956
|
+
* first preload
|
|
1957
|
+
* second pre-processing
|
|
1958
|
+
* second filterSerializedResponseHeaders
|
|
1959
|
+
* second transform
|
|
1960
|
+
* first transform
|
|
1961
|
+
* second post-processing
|
|
1962
|
+
* first post-processing
|
|
1963
|
+
* ```
|
|
1964
|
+
*
|
|
1965
|
+
* */
|
|
1966
|
+
export function sequence(...handlers: import('@sveltejs/kit').Handle[]): import('@sveltejs/kit').Handle;
|
|
768
1967
|
}
|
|
769
1968
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
/**
|
|
779
|
-
* Info about the current route
|
|
780
|
-
*/
|
|
781
|
-
route: {
|
|
782
|
-
/**
|
|
783
|
-
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
784
|
-
*/
|
|
785
|
-
id: RouteId;
|
|
786
|
-
};
|
|
787
|
-
/**
|
|
788
|
-
* The URL of the current page
|
|
789
|
-
*/
|
|
790
|
-
url: URL;
|
|
1969
|
+
declare module '@sveltejs/kit/node' {
|
|
1970
|
+
export function getRequest({ request, base, bodySizeLimit }: {
|
|
1971
|
+
request: import('http').IncomingMessage;
|
|
1972
|
+
base: string;
|
|
1973
|
+
bodySizeLimit?: number;
|
|
1974
|
+
}): Promise<Request>;
|
|
1975
|
+
|
|
1976
|
+
export function setResponse(res: import('http').ServerResponse, response: Response): Promise<void>;
|
|
791
1977
|
}
|
|
792
1978
|
|
|
793
|
-
|
|
794
|
-
* Information about the target of a specific navigation.
|
|
795
|
-
*/
|
|
796
|
-
export interface NavigationTarget {
|
|
797
|
-
/**
|
|
798
|
-
* Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
799
|
-
* Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
|
|
800
|
-
*/
|
|
801
|
-
params: Record<string, string> | null;
|
|
802
|
-
/**
|
|
803
|
-
* Info about the target route
|
|
804
|
-
*/
|
|
805
|
-
route: { id: string | null };
|
|
1979
|
+
declare module '@sveltejs/kit/node/polyfills' {
|
|
806
1980
|
/**
|
|
807
|
-
*
|
|
1981
|
+
* Make various web APIs available as globals:
|
|
1982
|
+
* - `crypto`
|
|
1983
|
+
* - `fetch`
|
|
1984
|
+
* - `Headers`
|
|
1985
|
+
* - `Request`
|
|
1986
|
+
* - `Response`
|
|
808
1987
|
*/
|
|
809
|
-
|
|
1988
|
+
export function installPolyfills(): void;
|
|
810
1989
|
}
|
|
811
1990
|
|
|
812
|
-
|
|
813
|
-
* - `enter`: The app has hydrated
|
|
814
|
-
* - `form`: The user submitted a `<form>`
|
|
815
|
-
* - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
|
|
816
|
-
* - `link`: Navigation was triggered by a link click
|
|
817
|
-
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
818
|
-
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
819
|
-
*/
|
|
820
|
-
export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
821
|
-
|
|
822
|
-
export interface Navigation {
|
|
823
|
-
/**
|
|
824
|
-
* Where navigation was triggered from
|
|
825
|
-
*/
|
|
826
|
-
from: NavigationTarget | null;
|
|
827
|
-
/**
|
|
828
|
-
* Where navigation is going to/has gone to
|
|
829
|
-
*/
|
|
830
|
-
to: NavigationTarget | null;
|
|
1991
|
+
declare module '@sveltejs/kit/vite' {
|
|
831
1992
|
/**
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
type: Omit<NavigationType, 'enter'>;
|
|
1993
|
+
* Returns the SvelteKit Vite plugins.
|
|
1994
|
+
* */
|
|
1995
|
+
export function sveltekit(): Promise<import('vite').Plugin[]>;
|
|
1996
|
+
export { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
declare module '$app/environment' {
|
|
840
2000
|
/**
|
|
841
|
-
*
|
|
2001
|
+
* `true` if the app is running in the browser.
|
|
842
2002
|
*/
|
|
843
|
-
|
|
2003
|
+
export const browser: boolean;
|
|
844
2004
|
/**
|
|
845
|
-
*
|
|
2005
|
+
* Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
|
|
846
2006
|
*/
|
|
847
|
-
|
|
2007
|
+
export const dev: boolean;
|
|
2008
|
+
export { building, version } from "__sveltekit/environment";
|
|
848
2009
|
}
|
|
849
2010
|
|
|
850
|
-
|
|
851
|
-
* The argument passed to [`beforeNavigate`](https://kit.svelte.dev/docs/modules#$app-navigation-beforenavigate) callbacks.
|
|
852
|
-
*/
|
|
853
|
-
export interface BeforeNavigate extends Navigation {
|
|
2011
|
+
declare module '$app/forms' {
|
|
854
2012
|
/**
|
|
855
|
-
*
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* The argument passed to [`afterNavigate`](https://kit.svelte.dev/docs/modules#$app-navigation-afternavigate) callbacks.
|
|
862
|
-
*/
|
|
863
|
-
export interface AfterNavigate extends Navigation {
|
|
2013
|
+
* This action updates the `form` property of the current page with the given data and updates `$page.status`.
|
|
2014
|
+
* In case of an error, it redirects to the nearest error page.
|
|
2015
|
+
* */
|
|
2016
|
+
export function applyAction<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: import("@sveltejs/kit").ActionResult<Success, Failure>): Promise<void>;
|
|
864
2017
|
/**
|
|
865
|
-
*
|
|
866
|
-
*
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
*
|
|
871
|
-
|
|
872
|
-
|
|
2018
|
+
* Use this function to deserialize the response from a form submission.
|
|
2019
|
+
* Usage:
|
|
2020
|
+
*
|
|
2021
|
+
* ```js
|
|
2022
|
+
* import { deserialize } from '$app/forms';
|
|
2023
|
+
*
|
|
2024
|
+
* async function handleSubmit(event) {
|
|
2025
|
+
* const response = await fetch('/form?/action', {
|
|
2026
|
+
* method: 'POST',
|
|
2027
|
+
* body: new FormData(event.target)
|
|
2028
|
+
* });
|
|
2029
|
+
*
|
|
2030
|
+
* const result = deserialize(await response.text());
|
|
2031
|
+
* // ...
|
|
2032
|
+
* }
|
|
2033
|
+
* ```
|
|
2034
|
+
* */
|
|
2035
|
+
export function deserialize<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: string): import("@sveltejs/kit").ActionResult<Success, Failure>;
|
|
873
2036
|
/**
|
|
874
|
-
*
|
|
875
|
-
|
|
876
|
-
|
|
2037
|
+
* This action enhances a `<form>` element that otherwise would work without JavaScript.
|
|
2038
|
+
*
|
|
2039
|
+
* The `submit` function is called upon submission with the given FormData and the `action` that should be triggered.
|
|
2040
|
+
* If `cancel` is called, the form will not be submitted.
|
|
2041
|
+
* You can use the abort `controller` to cancel the submission in case another one starts.
|
|
2042
|
+
* If a function is returned, that function is called with the response from the server.
|
|
2043
|
+
* If nothing is returned, the fallback will be used.
|
|
2044
|
+
*
|
|
2045
|
+
* If this function or its return value isn't set, it
|
|
2046
|
+
* - falls back to updating the `form` prop with the returned data if the action is one same page as the form
|
|
2047
|
+
* - updates `$page.status`
|
|
2048
|
+
* - resets the `<form>` element and invalidates all data in case of successful submission with no redirect response
|
|
2049
|
+
* - redirects in case of a redirect response
|
|
2050
|
+
* - redirects to the nearest error page in case of an unexpected error
|
|
2051
|
+
*
|
|
2052
|
+
* If you provide a custom function with a callback and want to use the default behavior, invoke `update` in your callback.
|
|
2053
|
+
* */
|
|
2054
|
+
export function enhance<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(form_element: HTMLFormElement, submit?: import("@sveltejs/kit").SubmitFunction<Success, Failure>): {
|
|
2055
|
+
destroy(): void;
|
|
2056
|
+
};
|
|
877
2057
|
}
|
|
878
2058
|
|
|
879
|
-
|
|
880
|
-
* The shape of the `$page` store
|
|
881
|
-
*/
|
|
882
|
-
export interface Page<
|
|
883
|
-
Params extends Record<string, string> = Record<string, string>,
|
|
884
|
-
RouteId extends string | null = string | null
|
|
885
|
-
> {
|
|
2059
|
+
declare module '$app/navigation' {
|
|
886
2060
|
/**
|
|
887
|
-
*
|
|
888
|
-
|
|
889
|
-
|
|
2061
|
+
* If called when the page is being updated following a navigation (in `onMount` or `afterNavigate` or an action, for example), this disables SvelteKit's built-in scroll handling.
|
|
2062
|
+
* This is generally discouraged, since it breaks user expectations.
|
|
2063
|
+
* */
|
|
2064
|
+
export const disableScrollHandling: () => void;
|
|
890
2065
|
/**
|
|
891
|
-
*
|
|
892
|
-
|
|
893
|
-
|
|
2066
|
+
* Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
|
|
2067
|
+
* For external URLs, use `window.location = url` instead of calling `goto(url)`.
|
|
2068
|
+
*
|
|
2069
|
+
* */
|
|
2070
|
+
export const goto: (url: string | URL, opts?: {
|
|
2071
|
+
replaceState?: boolean;
|
|
2072
|
+
noScroll?: boolean;
|
|
2073
|
+
keepFocus?: boolean;
|
|
2074
|
+
invalidateAll?: boolean;
|
|
2075
|
+
state?: any;
|
|
2076
|
+
}) => Promise<void>;
|
|
2077
|
+
/**
|
|
2078
|
+
* Causes any `load` functions belonging to the currently active page to re-run if they depend on the `url` in question, via `fetch` or `depends`. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
2079
|
+
*
|
|
2080
|
+
* If the argument is given as a `string` or `URL`, it must resolve to the same URL that was passed to `fetch` or `depends` (including query parameters).
|
|
2081
|
+
* To create a custom identifier, use a string beginning with `[a-z]+:` (e.g. `custom:state`) — this is a valid URL.
|
|
2082
|
+
*
|
|
2083
|
+
* The `function` argument can be used define a custom predicate. It receives the full `URL` and causes `load` to rerun if `true` is returned.
|
|
2084
|
+
* This can be useful if you want to invalidate based on a pattern instead of a exact match.
|
|
2085
|
+
*
|
|
2086
|
+
* ```ts
|
|
2087
|
+
* // Example: Match '/path' regardless of the query parameters
|
|
2088
|
+
* import { invalidate } from '$app/navigation';
|
|
2089
|
+
*
|
|
2090
|
+
* invalidate((url) => url.pathname === '/path');
|
|
2091
|
+
* ```
|
|
2092
|
+
* */
|
|
2093
|
+
export const invalidate: (url: string | URL | ((url: URL) => boolean)) => Promise<void>;
|
|
894
2094
|
/**
|
|
895
|
-
*
|
|
896
|
-
*/
|
|
897
|
-
|
|
898
|
-
/**
|
|
899
|
-
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
900
|
-
*/
|
|
901
|
-
id: RouteId;
|
|
902
|
-
};
|
|
2095
|
+
* Causes all `load` functions belonging to the currently active page to re-run. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
2096
|
+
* */
|
|
2097
|
+
export const invalidateAll: () => Promise<void>;
|
|
903
2098
|
/**
|
|
904
|
-
*
|
|
905
|
-
|
|
906
|
-
|
|
2099
|
+
* Programmatically preloads the given page, which means
|
|
2100
|
+
* 1. ensuring that the code for the page is loaded, and
|
|
2101
|
+
* 2. calling the page's load function with the appropriate options.
|
|
2102
|
+
*
|
|
2103
|
+
* This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.
|
|
2104
|
+
* If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
|
|
2105
|
+
* Returns a Promise that resolves when the preload is complete.
|
|
2106
|
+
*
|
|
2107
|
+
* */
|
|
2108
|
+
export const preloadData: (href: string) => Promise<void>;
|
|
907
2109
|
/**
|
|
908
|
-
*
|
|
909
|
-
|
|
910
|
-
|
|
2110
|
+
* Programmatically imports the code for routes that haven't yet been fetched.
|
|
2111
|
+
* Typically, you might call this to speed up subsequent navigation.
|
|
2112
|
+
*
|
|
2113
|
+
* You can specify routes by any matching pathname such as `/about` (to match `src/routes/about/+page.svelte`) or `/blog/*` (to match `src/routes/blog/[slug]/+page.svelte`).
|
|
2114
|
+
*
|
|
2115
|
+
* Unlike `preloadData`, this won't call `load` functions.
|
|
2116
|
+
* Returns a Promise that resolves when the modules have been imported.
|
|
2117
|
+
*
|
|
2118
|
+
* */
|
|
2119
|
+
export const preloadCode: (...urls: string[]) => Promise<void>;
|
|
911
2120
|
/**
|
|
912
|
-
*
|
|
913
|
-
|
|
914
|
-
|
|
2121
|
+
* A navigation interceptor that triggers before we navigate to a new URL, whether by clicking a link, calling `goto(...)`, or using the browser back/forward controls.
|
|
2122
|
+
* Calling `cancel()` will prevent the navigation from completing. If the navigation would have directly unloaded the current page, calling `cancel` will trigger the native
|
|
2123
|
+
* browser unload confirmation dialog. In these cases, `navigation.willUnload` is `true`.
|
|
2124
|
+
*
|
|
2125
|
+
* When a navigation isn't client side, `navigation.to.route.id` will be `null`.
|
|
2126
|
+
*
|
|
2127
|
+
* `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
2128
|
+
* */
|
|
2129
|
+
export const beforeNavigate: (callback: (navigation: import('@sveltejs/kit').BeforeNavigate) => void) => void;
|
|
915
2130
|
/**
|
|
916
|
-
*
|
|
917
|
-
|
|
918
|
-
|
|
2131
|
+
* A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a new URL.
|
|
2132
|
+
*
|
|
2133
|
+
* `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
2134
|
+
* */
|
|
2135
|
+
export const afterNavigate: (callback: (navigation: import('@sveltejs/kit').AfterNavigate) => void) => void;
|
|
919
2136
|
}
|
|
920
2137
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
*/
|
|
924
|
-
export interface ParamMatcher {
|
|
925
|
-
(param: string): boolean;
|
|
2138
|
+
declare module '$app/paths' {
|
|
2139
|
+
export { base, assets } from "__sveltekit/paths";
|
|
926
2140
|
}
|
|
927
2141
|
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
2142
|
+
declare module '$app/stores' {
|
|
2143
|
+
export function getStores(): {
|
|
2144
|
+
|
|
2145
|
+
page: typeof page;
|
|
2146
|
+
|
|
2147
|
+
navigating: typeof navigating;
|
|
2148
|
+
|
|
2149
|
+
updated: typeof updated;
|
|
2150
|
+
};
|
|
932
2151
|
/**
|
|
933
|
-
*
|
|
934
|
-
|
|
935
|
-
|
|
2152
|
+
* A readable store whose value contains page data.
|
|
2153
|
+
*
|
|
2154
|
+
* On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
|
|
2155
|
+
*
|
|
2156
|
+
* */
|
|
2157
|
+
export const page: import('svelte/store').Readable<import('@sveltejs/kit').Page>;
|
|
936
2158
|
/**
|
|
937
|
-
*
|
|
2159
|
+
* A readable store.
|
|
2160
|
+
* When navigating starts, its value is a `Navigation` object with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
|
|
2161
|
+
* When navigating finishes, its value reverts to `null`.
|
|
938
2162
|
*
|
|
939
|
-
*
|
|
940
|
-
*
|
|
941
|
-
|
|
2163
|
+
* On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
|
|
2164
|
+
* */
|
|
2165
|
+
export const navigating: import('svelte/store').Readable<import('@sveltejs/kit').Navigation | null>;
|
|
2166
|
+
/**
|
|
2167
|
+
* A readable store whose initial value is `false`. If [`version.pollInterval`](https://kit.svelte.dev/docs/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update the store value to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
|
|
942
2168
|
*
|
|
943
|
-
*
|
|
944
|
-
*/
|
|
945
|
-
|
|
2169
|
+
* On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
|
|
2170
|
+
* */
|
|
2171
|
+
export const updated: import('svelte/store').Readable<boolean> & {
|
|
2172
|
+
check(): Promise<boolean>;
|
|
2173
|
+
};
|
|
2174
|
+
}/**
|
|
2175
|
+
* It's possible to tell SvelteKit how to type objects inside your app by declaring the `App` namespace. By default, a new project will have a file called `src/app.d.ts` containing the following:
|
|
2176
|
+
*
|
|
2177
|
+
* ```ts
|
|
2178
|
+
* declare global {
|
|
2179
|
+
* namespace App {
|
|
2180
|
+
* // interface Error {}
|
|
2181
|
+
* // interface Locals {}
|
|
2182
|
+
* // interface PageData {}
|
|
2183
|
+
* // interface Platform {}
|
|
2184
|
+
* }
|
|
2185
|
+
* }
|
|
2186
|
+
*
|
|
2187
|
+
* export {};
|
|
2188
|
+
* ```
|
|
2189
|
+
*
|
|
2190
|
+
* The `export {}` line exists because without it, the file would be treated as an _ambient module_ which prevents you from adding `import` declarations.
|
|
2191
|
+
* If you need to add ambient `declare module` declarations, do so in a separate file like `src/ambient.d.ts`.
|
|
2192
|
+
*
|
|
2193
|
+
* By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, and `data` from `load` functions.
|
|
2194
|
+
*/
|
|
2195
|
+
declare namespace App {
|
|
946
2196
|
/**
|
|
947
|
-
*
|
|
2197
|
+
* Defines the common shape of expected and unexpected errors. Expected errors are thrown using the `error` function. Unexpected errors are handled by the `handleError` hooks which should return this shape.
|
|
948
2198
|
*/
|
|
949
|
-
|
|
2199
|
+
export interface Error {
|
|
2200
|
+
message: string;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
950
2203
|
/**
|
|
951
|
-
*
|
|
2204
|
+
* The interface that defines `event.locals`, which can be accessed in [hooks](https://kit.svelte.dev/docs/hooks) (`handle`, and `handleError`), server-only `load` functions, and `+server.js` files.
|
|
952
2205
|
*/
|
|
953
|
-
|
|
2206
|
+
export interface Locals {}
|
|
2207
|
+
|
|
954
2208
|
/**
|
|
955
|
-
*
|
|
2209
|
+
* Defines the common shape of the [$page.data store](https://kit.svelte.dev/docs/modules#$app-stores-page) - that is, the data that is shared between all pages.
|
|
2210
|
+
* The `Load` and `ServerLoad` functions in `./$types` will be narrowed accordingly.
|
|
2211
|
+
* Use optional properties for data that is only present on specific pages. Do not add an index signature (`[key: string]: any`).
|
|
956
2212
|
*/
|
|
957
|
-
|
|
2213
|
+
export interface PageData {}
|
|
2214
|
+
|
|
958
2215
|
/**
|
|
959
|
-
*
|
|
2216
|
+
* If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#platform-specific-context) via `event.platform`, you can specify it here.
|
|
960
2217
|
*/
|
|
961
|
-
|
|
2218
|
+
export interface Platform {}
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
/**
|
|
2222
|
+
* This module is only available to [service workers](https://kit.svelte.dev/docs/service-workers).
|
|
2223
|
+
*/
|
|
2224
|
+
declare module '$service-worker' {
|
|
962
2225
|
/**
|
|
963
|
-
* The
|
|
2226
|
+
* The `base` path of the deployment. Typically this is equivalent to `config.kit.paths.base`, but it is calculated from `location.pathname` meaning that it will continue to work correctly if the site is deployed to a subdirectory.
|
|
2227
|
+
* Note that there is a `base` but no `assets`, since service workers cannot be used if `config.kit.paths.assets` is specified.
|
|
964
2228
|
*/
|
|
965
|
-
|
|
2229
|
+
export const base: string;
|
|
966
2230
|
/**
|
|
967
|
-
*
|
|
2231
|
+
* An array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`.
|
|
2232
|
+
* During development, this is an empty array.
|
|
968
2233
|
*/
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
972
|
-
*/
|
|
973
|
-
id: RouteId;
|
|
974
|
-
};
|
|
2234
|
+
export const build: string[];
|
|
975
2235
|
/**
|
|
976
|
-
*
|
|
977
|
-
*
|
|
978
|
-
* ```js
|
|
979
|
-
* /// file: src/routes/blog/+page.js
|
|
980
|
-
* export async function load({ fetch, setHeaders }) {
|
|
981
|
-
* const url = `https://cms.example.com/articles.json`;
|
|
982
|
-
* const response = await fetch(url);
|
|
983
|
-
*
|
|
984
|
-
* setHeaders({
|
|
985
|
-
* age: response.headers.get('age'),
|
|
986
|
-
* 'cache-control': response.headers.get('cache-control')
|
|
987
|
-
* });
|
|
988
|
-
*
|
|
989
|
-
* return response.json();
|
|
990
|
-
* }
|
|
991
|
-
* ```
|
|
992
|
-
*
|
|
993
|
-
* Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
|
|
994
|
-
*
|
|
995
|
-
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#public-types-cookies) API instead.
|
|
2236
|
+
* An array of URL strings representing the files in your static directory, or whatever directory is specified by `config.kit.files.assets`. You can customize which files are included from `static` directory using [`config.kit.serviceWorker.files`](https://kit.svelte.dev/docs/configuration)
|
|
996
2237
|
*/
|
|
997
|
-
|
|
2238
|
+
export const files: string[];
|
|
998
2239
|
/**
|
|
999
|
-
*
|
|
2240
|
+
* An array of pathnames corresponding to prerendered pages and endpoints.
|
|
2241
|
+
* During development, this is an empty array.
|
|
1000
2242
|
*/
|
|
1001
|
-
|
|
2243
|
+
export const prerendered: string[];
|
|
1002
2244
|
/**
|
|
1003
|
-
* `
|
|
1004
|
-
* related to the data request in this case. Use this property instead if the distinction is important to you.
|
|
2245
|
+
* See [`config.kit.version`](https://kit.svelte.dev/docs/configuration#version). It's useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches.
|
|
1005
2246
|
*/
|
|
1006
|
-
|
|
2247
|
+
export const version: string;
|
|
1007
2248
|
}
|
|
1008
2249
|
|
|
1009
|
-
/**
|
|
1010
|
-
|
|
1011
|
-
*
|
|
1012
|
-
* 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.
|
|
1013
|
-
*/
|
|
1014
|
-
export interface RequestHandler<
|
|
1015
|
-
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1016
|
-
RouteId extends string | null = string | null
|
|
1017
|
-
> {
|
|
1018
|
-
(event: RequestEvent<Params, RouteId>): MaybePromise<Response>;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
export interface ResolveOptions {
|
|
1022
|
-
/**
|
|
1023
|
-
* Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
|
|
1024
|
-
* (they could include an element's opening tag but not its closing tag, for example)
|
|
1025
|
-
* but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
|
|
1026
|
-
* @param input the html chunk and the info if this is the last chunk
|
|
1027
|
-
*/
|
|
1028
|
-
transformPageChunk?(input: { html: string; done: boolean }): MaybePromise<string | undefined>;
|
|
2250
|
+
/** Internal version of $app/environment */
|
|
2251
|
+
declare module '__sveltekit/environment' {
|
|
1029
2252
|
/**
|
|
1030
|
-
*
|
|
1031
|
-
* By default, none will be included.
|
|
1032
|
-
* @param name header name
|
|
1033
|
-
* @param value header value
|
|
2253
|
+
* SvelteKit analyses your app during the `build` step by running it. During this process, `building` is `true`. This also applies during prerendering.
|
|
1034
2254
|
*/
|
|
1035
|
-
|
|
2255
|
+
export const building: boolean;
|
|
1036
2256
|
/**
|
|
1037
|
-
*
|
|
1038
|
-
* By default, `js`, `css` and `font` files will be preloaded.
|
|
1039
|
-
* @param input the type of the file and its path
|
|
2257
|
+
* The value of `config.kit.version.name`.
|
|
1040
2258
|
*/
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
export interface RouteDefinition<Config = any> {
|
|
1045
|
-
id: string;
|
|
1046
|
-
api: {
|
|
1047
|
-
methods: HttpMethod[];
|
|
1048
|
-
};
|
|
1049
|
-
page: {
|
|
1050
|
-
methods: Extract<HttpMethod, 'GET' | 'POST'>[];
|
|
1051
|
-
};
|
|
1052
|
-
pattern: RegExp;
|
|
1053
|
-
prerender: PrerenderOption;
|
|
1054
|
-
segments: RouteSegment[];
|
|
1055
|
-
methods: HttpMethod[];
|
|
1056
|
-
config: Config;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
export class Server {
|
|
1060
|
-
constructor(manifest: SSRManifest);
|
|
1061
|
-
init(options: ServerInitOptions): Promise<void>;
|
|
1062
|
-
respond(request: Request, options: RequestOptions): Promise<Response>;
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
export interface ServerInitOptions {
|
|
1066
|
-
env: Record<string, string>;
|
|
2259
|
+
export const version: string;
|
|
2260
|
+
export function set_building(): void;
|
|
1067
2261
|
}
|
|
1068
2262
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
appPath: string;
|
|
1072
|
-
assets: Set<string>;
|
|
1073
|
-
mimeTypes: Record<string, string>;
|
|
1074
|
-
|
|
1075
|
-
/** private fields */
|
|
1076
|
-
_: {
|
|
1077
|
-
client: NonNullable<BuildData['client']>;
|
|
1078
|
-
nodes: SSRNodeLoader[];
|
|
1079
|
-
routes: SSRRoute[];
|
|
1080
|
-
matchers(): Promise<Record<string, ParamMatcher>>;
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
/**
|
|
1085
|
-
* The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
1086
|
-
* rather than using `ServerLoad` directly.
|
|
1087
|
-
*/
|
|
1088
|
-
export interface ServerLoad<
|
|
1089
|
-
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1090
|
-
ParentData extends Record<string, any> = Record<string, any>,
|
|
1091
|
-
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1092
|
-
RouteId extends string | null = string | null
|
|
1093
|
-
> {
|
|
1094
|
-
(event: ServerLoadEvent<Params, ParentData, RouteId>): MaybePromise<OutputData>;
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
export interface ServerLoadEvent<
|
|
1098
|
-
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1099
|
-
ParentData extends Record<string, any> = Record<string, any>,
|
|
1100
|
-
RouteId extends string | null = string | null
|
|
1101
|
-
> extends RequestEvent<Params, RouteId> {
|
|
2263
|
+
/** Internal version of $app/paths */
|
|
2264
|
+
declare module '__sveltekit/paths' {
|
|
1102
2265
|
/**
|
|
1103
|
-
*
|
|
2266
|
+
* A string that matches [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths).
|
|
1104
2267
|
*
|
|
1105
|
-
*
|
|
2268
|
+
* Example usage: `<a href="{base}/your-page">Link</a>`
|
|
1106
2269
|
*/
|
|
1107
|
-
|
|
2270
|
+
export let base: '' | `/${string}`;
|
|
1108
2271
|
/**
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1111
|
-
* 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`.
|
|
1112
|
-
*
|
|
1113
|
-
* 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).
|
|
1114
|
-
*
|
|
1115
|
-
* 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).
|
|
1116
|
-
*
|
|
1117
|
-
* 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.
|
|
1118
|
-
*
|
|
1119
|
-
* ```js
|
|
1120
|
-
* /// file: src/routes/+page.js
|
|
1121
|
-
* let count = 0;
|
|
1122
|
-
* export async function load({ depends }) {
|
|
1123
|
-
* depends('increase:count');
|
|
1124
|
-
*
|
|
1125
|
-
* return { count: count++ };
|
|
1126
|
-
* }
|
|
1127
|
-
* ```
|
|
2272
|
+
* An absolute path that matches [`config.kit.paths.assets`](https://kit.svelte.dev/docs/configuration#paths).
|
|
1128
2273
|
*
|
|
1129
|
-
*
|
|
1130
|
-
* /// file: src/routes/+page.svelte
|
|
1131
|
-
* <script>
|
|
1132
|
-
* import { invalidate } from '$app/navigation';
|
|
1133
|
-
*
|
|
1134
|
-
* export let data;
|
|
1135
|
-
*
|
|
1136
|
-
* const increase = async () => {
|
|
1137
|
-
* await invalidate('increase:count');
|
|
1138
|
-
* }
|
|
1139
|
-
* </script>
|
|
1140
|
-
*
|
|
1141
|
-
* <p>{data.count}<p>
|
|
1142
|
-
* <button on:click={increase}>Increase Count</button>
|
|
1143
|
-
* ```
|
|
2274
|
+
* > If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
|
|
1144
2275
|
*/
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
* See [form actions](https://kit.svelte.dev/docs/form-actions) for more information.
|
|
1151
|
-
*/
|
|
1152
|
-
export interface Action<
|
|
1153
|
-
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1154
|
-
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1155
|
-
RouteId extends string | null = string | null
|
|
1156
|
-
> {
|
|
1157
|
-
(event: RequestEvent<Params, RouteId>): MaybePromise<OutputData>;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
/**
|
|
1161
|
-
* Shape of the `export const actions = {..}` object in `+page.server.js`.
|
|
1162
|
-
* See [form actions](https://kit.svelte.dev/docs/form-actions) for more information.
|
|
1163
|
-
*/
|
|
1164
|
-
export type Actions<
|
|
1165
|
-
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1166
|
-
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1167
|
-
RouteId extends string | null = string | null
|
|
1168
|
-
> = Record<string, Action<Params, OutputData, RouteId>>;
|
|
1169
|
-
|
|
1170
|
-
/**
|
|
1171
|
-
* When calling a form action via fetch, the response will be one of these shapes.
|
|
1172
|
-
* ```svelte
|
|
1173
|
-
* <form method="post" use:enhance={() => {
|
|
1174
|
-
* return ({ result }) => {
|
|
1175
|
-
* // result is of type ActionResult
|
|
1176
|
-
* };
|
|
1177
|
-
* }}
|
|
1178
|
-
* ```
|
|
1179
|
-
*/
|
|
1180
|
-
export type ActionResult<
|
|
1181
|
-
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1182
|
-
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
1183
|
-
> =
|
|
1184
|
-
| { type: 'success'; status: number; data?: Success }
|
|
1185
|
-
| { type: 'failure'; status: number; data?: Failure }
|
|
1186
|
-
| { type: 'redirect'; status: number; location: string }
|
|
1187
|
-
| { type: 'error'; status?: number; error: any };
|
|
1188
|
-
|
|
1189
|
-
/**
|
|
1190
|
-
* Creates an `HttpError` object with an HTTP status code and an optional message.
|
|
1191
|
-
* This object, if thrown during request handling, will cause SvelteKit to
|
|
1192
|
-
* return an error response without invoking `handleError`.
|
|
1193
|
-
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
1194
|
-
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1195
|
-
* @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
1196
|
-
*/
|
|
1197
|
-
export function error(status: number, body: App.Error): HttpError;
|
|
1198
|
-
export function error(
|
|
1199
|
-
status: number,
|
|
1200
|
-
// this overload ensures you can omit the argument or pass in a string if App.Error is of type { message: string }
|
|
1201
|
-
body?: { message: string } extends App.Error ? App.Error | string | undefined : never
|
|
1202
|
-
): HttpError;
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* The object returned by the [`error`](https://kit.svelte.dev/docs/modules#sveltejs-kit-error) function.
|
|
1206
|
-
*/
|
|
1207
|
-
export interface HttpError {
|
|
1208
|
-
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
|
|
1209
|
-
status: number;
|
|
1210
|
-
/** The content of the error. */
|
|
1211
|
-
body: App.Error;
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* Create a `Redirect` object. If thrown during request handling, SvelteKit will return a redirect response.
|
|
1216
|
-
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
|
|
1217
|
-
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
|
|
1218
|
-
* @param location The location to redirect to.
|
|
1219
|
-
*/
|
|
1220
|
-
export function redirect(
|
|
1221
|
-
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308,
|
|
1222
|
-
location: string
|
|
1223
|
-
): Redirect;
|
|
1224
|
-
|
|
1225
|
-
/**
|
|
1226
|
-
* The object returned by the [`redirect`](https://kit.svelte.dev/docs/modules#sveltejs-kit-redirect) function
|
|
1227
|
-
*/
|
|
1228
|
-
export interface Redirect {
|
|
1229
|
-
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
|
|
1230
|
-
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
1231
|
-
/** The location to redirect to. */
|
|
1232
|
-
location: string;
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
/**
|
|
1236
|
-
* Create a JSON `Response` object from the supplied data.
|
|
1237
|
-
* @param data The value that will be serialized as JSON.
|
|
1238
|
-
* @param init Options such as `status` and `headers` that will be added to the response. `Content-Type: application/json` and `Content-Length` headers will be added automatically.
|
|
1239
|
-
*/
|
|
1240
|
-
export function json(data: any, init?: ResponseInit): Response;
|
|
1241
|
-
|
|
1242
|
-
/**
|
|
1243
|
-
* Create a `Response` object from the supplied body.
|
|
1244
|
-
* @param body The value that will be used as-is.
|
|
1245
|
-
* @param init Options such as `status` and `headers` that will be added to the response. A `Content-Length` header will be added automatically.
|
|
1246
|
-
*/
|
|
1247
|
-
export function text(body: string, init?: ResponseInit): Response;
|
|
1248
|
-
|
|
1249
|
-
/**
|
|
1250
|
-
* Create an `ActionFailure` object.
|
|
1251
|
-
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1252
|
-
* @param data Data associated with the failure (e.g. validation errors)
|
|
1253
|
-
*/
|
|
1254
|
-
export function fail<T extends Record<string, unknown> | undefined = undefined>(
|
|
1255
|
-
status: number,
|
|
1256
|
-
data?: T
|
|
1257
|
-
): ActionFailure<T>;
|
|
1258
|
-
|
|
1259
|
-
/**
|
|
1260
|
-
* The object returned by the [`fail`](https://kit.svelte.dev/docs/modules#sveltejs-kit-fail) function
|
|
1261
|
-
*/
|
|
1262
|
-
export interface ActionFailure<T extends Record<string, unknown> | undefined = undefined>
|
|
1263
|
-
extends UniqueInterface {
|
|
1264
|
-
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
|
|
1265
|
-
status: number;
|
|
1266
|
-
/** Data associated with the failure (e.g. validation errors) */
|
|
1267
|
-
data: T;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
export interface SubmitFunction<
|
|
1271
|
-
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1272
|
-
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
1273
|
-
> {
|
|
1274
|
-
(input: {
|
|
1275
|
-
action: URL;
|
|
1276
|
-
data: FormData;
|
|
1277
|
-
form: HTMLFormElement;
|
|
1278
|
-
controller: AbortController;
|
|
1279
|
-
submitter: HTMLElement | null;
|
|
1280
|
-
cancel(): void;
|
|
1281
|
-
}): MaybePromise<
|
|
1282
|
-
| void
|
|
1283
|
-
| ((opts: {
|
|
1284
|
-
form: HTMLFormElement;
|
|
1285
|
-
action: URL;
|
|
1286
|
-
result: ActionResult<Success, Failure>;
|
|
1287
|
-
/**
|
|
1288
|
-
* Call this to get the default behavior of a form submission response.
|
|
1289
|
-
* @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission.
|
|
1290
|
-
*/
|
|
1291
|
-
update(options?: { reset: boolean }): Promise<void>;
|
|
1292
|
-
}) => void)
|
|
1293
|
-
>;
|
|
2276
|
+
export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets';
|
|
2277
|
+
export let relative: boolean | undefined; // TODO in 2.0, make this a `boolean` that defaults to `true`
|
|
2278
|
+
export function reset(): void;
|
|
2279
|
+
export function override(paths: { base: string; assets: string }): void;
|
|
2280
|
+
export function set_assets(path: string): void;
|
|
1294
2281
|
}
|
|
1295
2282
|
|
|
1296
|
-
|
|
1297
|
-
* The type of `export const snapshot` exported from a page or layout component.
|
|
1298
|
-
*/
|
|
1299
|
-
export interface Snapshot<T = any> {
|
|
1300
|
-
capture: () => T;
|
|
1301
|
-
restore: (snapshot: T) => void;
|
|
1302
|
-
}
|
|
2283
|
+
//# sourceMappingURL=index.d.ts.map
|