@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
|
@@ -0,0 +1,1264 @@
|
|
|
1
|
+
import 'svelte'; // pick up `declare module "*.svelte"`
|
|
2
|
+
import 'vite/client'; // pick up `declare module "*.jpg"`, etc.
|
|
3
|
+
import '../types/ambient.js';
|
|
4
|
+
|
|
5
|
+
import { CompileOptions } from 'svelte/types/compiler/interfaces';
|
|
6
|
+
import {
|
|
7
|
+
AdapterEntry,
|
|
8
|
+
CspDirectives,
|
|
9
|
+
HttpMethod,
|
|
10
|
+
Logger,
|
|
11
|
+
MaybePromise,
|
|
12
|
+
Prerendered,
|
|
13
|
+
PrerenderEntryGeneratorMismatchHandlerValue,
|
|
14
|
+
PrerenderHttpErrorHandlerValue,
|
|
15
|
+
PrerenderMissingIdHandlerValue,
|
|
16
|
+
PrerenderOption,
|
|
17
|
+
RequestOptions,
|
|
18
|
+
RouteSegment
|
|
19
|
+
} from '../types/private.js';
|
|
20
|
+
import { ActionFailure } from '../runtime/control.js';
|
|
21
|
+
import { BuildData, SSRNodeLoader, SSRRoute, ValidatedConfig } from 'types';
|
|
22
|
+
import type { PluginOptions } from '@sveltejs/vite-plugin-svelte';
|
|
23
|
+
|
|
24
|
+
export { PrerenderOption } from '../types/private.js';
|
|
25
|
+
export { ActionFailure };
|
|
26
|
+
|
|
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
|
+
/**
|
|
36
|
+
* This function is called after SvelteKit has built your app.
|
|
37
|
+
* @param builder An object provided by SvelteKit that contains methods for adapting the app
|
|
38
|
+
*/
|
|
39
|
+
adapt(builder: Builder): MaybePromise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type AwaitedPropertiesUnion<input extends Record<string, any> | void> = input extends void
|
|
43
|
+
? undefined // needs to be undefined, because void will break intellisense
|
|
44
|
+
: input extends Record<string, any>
|
|
45
|
+
? {
|
|
46
|
+
[key in keyof input]: Awaited<input[key]>;
|
|
47
|
+
}
|
|
48
|
+
: {} extends input // handles the any case
|
|
49
|
+
? input
|
|
50
|
+
: unknown;
|
|
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;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* This object is passed to the `adapt` function of adapters.
|
|
78
|
+
* It contains various methods and properties that are useful for adapting the app.
|
|
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>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Generate a fallback page for a static webserver to use when no route is matched. Useful for single-page apps.
|
|
104
|
+
*/
|
|
105
|
+
generateFallback(dest: string): Promise<void>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Generate a server-side manifest to initialise the SvelteKit [server](https://kit.svelte.dev/docs/types#public-types-server) with.
|
|
109
|
+
* @param opts a relative path to the base directory of the app and optionally in which format (esm or cjs) the manifest should be generated
|
|
110
|
+
*/
|
|
111
|
+
generateManifest(opts: { relativePath: string; routes?: RouteDefinition[] }): string;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Resolve a path to the `name` directory inside `outDir`, e.g. `/path/to/.svelte-kit/my-adapter`.
|
|
115
|
+
* @param name path to the file, relative to the build directory
|
|
116
|
+
*/
|
|
117
|
+
getBuildDirectory(name: string): string;
|
|
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
|
+
}
|
|
166
|
+
|
|
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
|
+
/**
|
|
174
|
+
* List of file extensions that should be treated as Svelte files.
|
|
175
|
+
* @default [".svelte"]
|
|
176
|
+
*/
|
|
177
|
+
extensions?: string[];
|
|
178
|
+
/** SvelteKit options */
|
|
179
|
+
kit?: KitConfig;
|
|
180
|
+
/** [`@sveltejs/package`](/docs/packaging) options. */
|
|
181
|
+
package?: {
|
|
182
|
+
source?: string;
|
|
183
|
+
dir?: string;
|
|
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
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface Cookies {
|
|
197
|
+
/**
|
|
198
|
+
* Gets a cookie that was previously set with `cookies.set`, or from the request headers.
|
|
199
|
+
* @param name the name of the cookie
|
|
200
|
+
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
|
|
201
|
+
*/
|
|
202
|
+
get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
|
|
206
|
+
* @param opts the options, passed directily to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
|
|
207
|
+
*/
|
|
208
|
+
getAll(opts?: import('cookie').CookieParseOptions): Array<{ name: string; value: string }>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 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.
|
|
212
|
+
*
|
|
213
|
+
* 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`.
|
|
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)
|
|
219
|
+
*/
|
|
220
|
+
set(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): void;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
|
|
224
|
+
*
|
|
225
|
+
* 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.
|
|
226
|
+
* @param name the name of the cookie
|
|
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)
|
|
228
|
+
*/
|
|
229
|
+
delete(name: string, opts?: import('cookie').CookieSerializeOptions): void;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
|
|
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)
|
|
241
|
+
*/
|
|
242
|
+
serialize(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): string;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface KitConfig {
|
|
246
|
+
/**
|
|
247
|
+
* Your [adapter](https://kit.svelte.dev/docs/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms.
|
|
248
|
+
* @default undefined
|
|
249
|
+
*/
|
|
250
|
+
adapter?: Adapter;
|
|
251
|
+
/**
|
|
252
|
+
* An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
|
|
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 {}
|
|
279
|
+
*/
|
|
280
|
+
alias?: Record<string, string>;
|
|
281
|
+
/**
|
|
282
|
+
* 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 `/`.
|
|
283
|
+
* @default "_app"
|
|
284
|
+
*/
|
|
285
|
+
appDir?: string;
|
|
286
|
+
/**
|
|
287
|
+
* [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...
|
|
288
|
+
*
|
|
289
|
+
* ```js
|
|
290
|
+
* /// file: svelte.config.js
|
|
291
|
+
* /// type: import('@sveltejs/kit').Config
|
|
292
|
+
* const config = {
|
|
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.
|
|
319
|
+
*/
|
|
320
|
+
csp?: {
|
|
321
|
+
/**
|
|
322
|
+
* 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.
|
|
323
|
+
*/
|
|
324
|
+
mode?: 'hash' | 'nonce' | 'auto';
|
|
325
|
+
/**
|
|
326
|
+
* Directives that will be added to `Content-Security-Policy` headers.
|
|
327
|
+
*/
|
|
328
|
+
directives?: CspDirectives;
|
|
329
|
+
/**
|
|
330
|
+
* Directives that will be added to `Content-Security-Policy-Report-Only` headers.
|
|
331
|
+
*/
|
|
332
|
+
reportOnly?: CspDirectives;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Protection against [cross-site request forgery (CSRF)](https://owasp.org/www-community/attacks/csrf) attacks.
|
|
336
|
+
*/
|
|
337
|
+
csrf?: {
|
|
338
|
+
/**
|
|
339
|
+
* Whether to check the incoming `origin` header for `POST`, `PUT`, `PATCH`, or `DELETE` form submissions and verify that it matches the server's origin.
|
|
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
|
|
343
|
+
*/
|
|
344
|
+
checkOrigin?: boolean;
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Here be dragons. Enable at your peril.
|
|
348
|
+
*/
|
|
349
|
+
dangerZone?: {
|
|
350
|
+
/**
|
|
351
|
+
* Automatically add server-side `fetch`ed URLs to the `dependencies` map of `load` functions. This will expose secrets
|
|
352
|
+
* to the client if your URL contains them.
|
|
353
|
+
*/
|
|
354
|
+
trackServerFetches?: boolean;
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* 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`.
|
|
358
|
+
* @default false
|
|
359
|
+
*/
|
|
360
|
+
embedded?: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* Environment variable configuration
|
|
363
|
+
*/
|
|
364
|
+
env?: {
|
|
365
|
+
/**
|
|
366
|
+
* The directory to search for `.env` files.
|
|
367
|
+
* @default "."
|
|
368
|
+
*/
|
|
369
|
+
dir?: string;
|
|
370
|
+
/**
|
|
371
|
+
* 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.
|
|
372
|
+
* @default "PUBLIC_"
|
|
373
|
+
*/
|
|
374
|
+
publicPrefix?: string;
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* Where to find various files within your project.
|
|
378
|
+
*/
|
|
379
|
+
files?: {
|
|
380
|
+
/**
|
|
381
|
+
* a place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json`
|
|
382
|
+
* @default "static"
|
|
383
|
+
*/
|
|
384
|
+
assets?: string;
|
|
385
|
+
hooks?: {
|
|
386
|
+
/**
|
|
387
|
+
* The location of your client [hooks](https://kit.svelte.dev/docs/hooks).
|
|
388
|
+
* @default "src/hooks.client"
|
|
389
|
+
*/
|
|
390
|
+
client?: string;
|
|
391
|
+
/**
|
|
392
|
+
* The location of your server [hooks](https://kit.svelte.dev/docs/hooks).
|
|
393
|
+
* @default "src/hooks.server"
|
|
394
|
+
*/
|
|
395
|
+
server?: string;
|
|
396
|
+
};
|
|
397
|
+
/**
|
|
398
|
+
* your app's internal library, accessible throughout the codebase as `$lib`
|
|
399
|
+
* @default "src/lib"
|
|
400
|
+
*/
|
|
401
|
+
lib?: string;
|
|
402
|
+
/**
|
|
403
|
+
* a directory containing [parameter matchers](https://kit.svelte.dev/docs/advanced-routing#matching)
|
|
404
|
+
* @default "src/params"
|
|
405
|
+
*/
|
|
406
|
+
params?: string;
|
|
407
|
+
/**
|
|
408
|
+
* the files that define the structure of your app (see [Routing](https://kit.svelte.dev/docs/routing))
|
|
409
|
+
* @default "src/routes"
|
|
410
|
+
*/
|
|
411
|
+
routes?: string;
|
|
412
|
+
/**
|
|
413
|
+
* the location of your service worker's entry point (see [Service workers](https://kit.svelte.dev/docs/service-workers))
|
|
414
|
+
* @default "src/service-worker"
|
|
415
|
+
*/
|
|
416
|
+
serviceWorker?: string;
|
|
417
|
+
/**
|
|
418
|
+
* the location of the template for HTML responses
|
|
419
|
+
* @default "src/app.html"
|
|
420
|
+
*/
|
|
421
|
+
appTemplate?: string;
|
|
422
|
+
/**
|
|
423
|
+
* the location of the template for fallback error responses
|
|
424
|
+
* @default "src/error.html"
|
|
425
|
+
*/
|
|
426
|
+
errorTemplate?: string;
|
|
427
|
+
};
|
|
428
|
+
/**
|
|
429
|
+
* 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.
|
|
430
|
+
*
|
|
431
|
+
* > 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.
|
|
432
|
+
* @default 0
|
|
433
|
+
*/
|
|
434
|
+
inlineStyleThreshold?: number;
|
|
435
|
+
/**
|
|
436
|
+
* 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.
|
|
437
|
+
* @default [".js", ".ts"]
|
|
438
|
+
*/
|
|
439
|
+
moduleExtensions?: string[];
|
|
440
|
+
/**
|
|
441
|
+
* The directory that SvelteKit writes files to during `dev` and `build`. You should exclude this directory from version control.
|
|
442
|
+
* @default ".svelte-kit"
|
|
443
|
+
*/
|
|
444
|
+
outDir?: string;
|
|
445
|
+
/**
|
|
446
|
+
* Options related to the build output format
|
|
447
|
+
*/
|
|
448
|
+
output?: {
|
|
449
|
+
/**
|
|
450
|
+
* SvelteKit will preload the JavaScript modules needed for the initial page to avoid import 'waterfalls', resulting in faster application startup. There
|
|
451
|
+
* are three strategies with different trade-offs:
|
|
452
|
+
* - `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).
|
|
453
|
+
* - `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.
|
|
454
|
+
* - `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.
|
|
455
|
+
* @default "modulepreload"
|
|
456
|
+
*/
|
|
457
|
+
preloadStrategy?: 'modulepreload' | 'preload-js' | 'preload-mjs';
|
|
458
|
+
};
|
|
459
|
+
paths?: {
|
|
460
|
+
/**
|
|
461
|
+
* 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.
|
|
462
|
+
* @default ""
|
|
463
|
+
*/
|
|
464
|
+
assets?: '' | `http://${string}` | `https://${string}`;
|
|
465
|
+
/**
|
|
466
|
+
* 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.
|
|
467
|
+
* @default ""
|
|
468
|
+
*/
|
|
469
|
+
base?: '' | `/${string}`;
|
|
470
|
+
/**
|
|
471
|
+
* 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.
|
|
472
|
+
*
|
|
473
|
+
* If `true`, `base` and `assets` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in portable HTML.
|
|
474
|
+
* If `false`, `%sveltekit.assets%` and references to build artifacts will always be root-relative paths, unless `paths.assets` is an external URL
|
|
475
|
+
*
|
|
476
|
+
* 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.
|
|
477
|
+
* @default undefined
|
|
478
|
+
*/
|
|
479
|
+
relative?: boolean | undefined;
|
|
480
|
+
};
|
|
481
|
+
/**
|
|
482
|
+
* See [Prerendering](https://kit.svelte.dev/docs/page-options#prerender).
|
|
483
|
+
*/
|
|
484
|
+
prerender?: {
|
|
485
|
+
/**
|
|
486
|
+
* 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.
|
|
487
|
+
* @default 1
|
|
488
|
+
*/
|
|
489
|
+
concurrency?: number;
|
|
490
|
+
/**
|
|
491
|
+
* Whether SvelteKit should find pages to prerender by following links from `entries`.
|
|
492
|
+
* @default true
|
|
493
|
+
*/
|
|
494
|
+
crawl?: boolean;
|
|
495
|
+
/**
|
|
496
|
+
* 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).
|
|
497
|
+
* @default ["*"]
|
|
498
|
+
*/
|
|
499
|
+
entries?: Array<'*' | `/${string}`>;
|
|
500
|
+
/**
|
|
501
|
+
* How to respond to HTTP errors encountered while prerendering the app.
|
|
502
|
+
*
|
|
503
|
+
* - `'fail'` — fail the build
|
|
504
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
505
|
+
* - `'warn'` — continue, but print a warning
|
|
506
|
+
* - `(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
|
|
507
|
+
*
|
|
508
|
+
* ```js
|
|
509
|
+
* /// file: svelte.config.js
|
|
510
|
+
* /// type: import('@sveltejs/kit').Config
|
|
511
|
+
* const config = {
|
|
512
|
+
* kit: {
|
|
513
|
+
* prerender: {
|
|
514
|
+
* handleHttpError: ({ path, referrer, message }) => {
|
|
515
|
+
* // ignore deliberate link to shiny 404 page
|
|
516
|
+
* if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
|
|
517
|
+
* return;
|
|
518
|
+
* }
|
|
519
|
+
*
|
|
520
|
+
* // otherwise fail the build
|
|
521
|
+
* throw new Error(message);
|
|
522
|
+
* }
|
|
523
|
+
* }
|
|
524
|
+
* }
|
|
525
|
+
* };
|
|
526
|
+
* ```
|
|
527
|
+
*
|
|
528
|
+
* @default "fail"
|
|
529
|
+
*/
|
|
530
|
+
handleHttpError?: PrerenderHttpErrorHandlerValue;
|
|
531
|
+
/**
|
|
532
|
+
* How to respond when hash links from one prerendered page to another don't correspond to an `id` on the destination page.
|
|
533
|
+
*
|
|
534
|
+
* - `'fail'` — fail the build
|
|
535
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
536
|
+
* - `'warn'` — continue, but print a warning
|
|
537
|
+
* - `(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
|
|
538
|
+
*
|
|
539
|
+
* @default "fail"
|
|
540
|
+
*/
|
|
541
|
+
handleMissingId?: PrerenderMissingIdHandlerValue;
|
|
542
|
+
/**
|
|
543
|
+
* How to respond when an entry generated by the `entries` export doesn't match the route it was generated from.
|
|
544
|
+
*
|
|
545
|
+
* - `'fail'` — fail the build
|
|
546
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
547
|
+
* - `'warn'` — continue, but print a warning
|
|
548
|
+
* - `(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
|
|
549
|
+
*
|
|
550
|
+
* @default "fail"
|
|
551
|
+
*/
|
|
552
|
+
handleEntryGeneratorMismatch?: PrerenderEntryGeneratorMismatchHandlerValue;
|
|
553
|
+
/**
|
|
554
|
+
* The value of `url.origin` during prerendering; useful if it is included in rendered content.
|
|
555
|
+
* @default "http://sveltekit-prerender"
|
|
556
|
+
*/
|
|
557
|
+
origin?: string;
|
|
558
|
+
};
|
|
559
|
+
serviceWorker?: {
|
|
560
|
+
/**
|
|
561
|
+
* Whether to automatically register the service worker, if it exists.
|
|
562
|
+
* @default true
|
|
563
|
+
*/
|
|
564
|
+
register?: boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Determine which files in your `static` directory will be available in `$service-worker.files`.
|
|
567
|
+
* @default (filename) => !/\.DS_Store/.test(filename)
|
|
568
|
+
*/
|
|
569
|
+
files?(filepath: string): boolean;
|
|
570
|
+
};
|
|
571
|
+
typescript?: {
|
|
572
|
+
/**
|
|
573
|
+
* A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
|
|
574
|
+
* This is useful for extending a shared `tsconfig.json` in a monorepo root, for example.
|
|
575
|
+
* @default (config) => config
|
|
576
|
+
*/
|
|
577
|
+
config?: (config: Record<string, any>) => Record<string, any> | void;
|
|
578
|
+
};
|
|
579
|
+
/**
|
|
580
|
+
* 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.
|
|
581
|
+
* SvelteKit helps you solve this problem through version management.
|
|
582
|
+
* 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.
|
|
583
|
+
* 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`:
|
|
584
|
+
* ```html
|
|
585
|
+
* /// file: +layout.svelte
|
|
586
|
+
* <script>
|
|
587
|
+
* import { beforeNavigate } from '$app/navigation';
|
|
588
|
+
* import { updated } from '$app/stores';
|
|
589
|
+
*
|
|
590
|
+
* beforeNavigate(({ willUnload, to }) => {
|
|
591
|
+
* if ($updated && !willUnload && to?.url) {
|
|
592
|
+
* location.href = to.url.href;
|
|
593
|
+
* }
|
|
594
|
+
* });
|
|
595
|
+
* </script>
|
|
596
|
+
* ```
|
|
597
|
+
*
|
|
598
|
+
* 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.
|
|
599
|
+
*/
|
|
600
|
+
version?: {
|
|
601
|
+
/**
|
|
602
|
+
* 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.
|
|
603
|
+
*
|
|
604
|
+
* For example, to use the current commit hash, you could do use `git rev-parse HEAD`:
|
|
605
|
+
*
|
|
606
|
+
* ```js
|
|
607
|
+
* /// file: svelte.config.js
|
|
608
|
+
* import * as child_process from 'node:child_process';
|
|
609
|
+
*
|
|
610
|
+
* export default {
|
|
611
|
+
* kit: {
|
|
612
|
+
* version: {
|
|
613
|
+
* name: child_process.execSync('git rev-parse HEAD').toString().trim()
|
|
614
|
+
* }
|
|
615
|
+
* }
|
|
616
|
+
* };
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
619
|
+
name?: string;
|
|
620
|
+
/**
|
|
621
|
+
* The interval in milliseconds to poll for version changes. If this is `0`, no polling occurs.
|
|
622
|
+
* @default 0
|
|
623
|
+
*/
|
|
624
|
+
pollInterval?: number;
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* 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
|
|
630
|
+
* determines the [response](https://kit.svelte.dev/docs/web-standards#fetch-apis-response).
|
|
631
|
+
* It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
|
|
632
|
+
* This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
|
|
633
|
+
*/
|
|
634
|
+
export type Handle = (input: {
|
|
635
|
+
event: RequestEvent;
|
|
636
|
+
resolve(event: RequestEvent, opts?: ResolveOptions): MaybePromise<Response>;
|
|
637
|
+
}) => MaybePromise<Response>;
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* 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.
|
|
641
|
+
*
|
|
642
|
+
* If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
|
|
643
|
+
* Make sure that this function _never_ throws an error.
|
|
644
|
+
*/
|
|
645
|
+
export type HandleServerError = (input: {
|
|
646
|
+
error: unknown;
|
|
647
|
+
event: RequestEvent;
|
|
648
|
+
}) => MaybePromise<void | App.Error>;
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* The client-side [`handleError`](https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror) hook runs when an unexpected error is thrown while navigating.
|
|
652
|
+
*
|
|
653
|
+
* If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
|
|
654
|
+
* Make sure that this function _never_ throws an error.
|
|
655
|
+
*/
|
|
656
|
+
export type HandleClientError = (input: {
|
|
657
|
+
error: unknown;
|
|
658
|
+
event: NavigationEvent;
|
|
659
|
+
}) => MaybePromise<void | App.Error>;
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* 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)
|
|
663
|
+
*/
|
|
664
|
+
export type HandleFetch = (input: {
|
|
665
|
+
event: RequestEvent;
|
|
666
|
+
request: Request;
|
|
667
|
+
fetch: typeof fetch;
|
|
668
|
+
}) => MaybePromise<Response>;
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
672
|
+
* rather than using `Load` directly.
|
|
673
|
+
*/
|
|
674
|
+
export type Load<
|
|
675
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
676
|
+
InputData extends Record<string, unknown> | null = Record<string, any> | null,
|
|
677
|
+
ParentData extends Record<string, unknown> = Record<string, any>,
|
|
678
|
+
OutputData extends Record<string, unknown> | void = Record<string, any> | void,
|
|
679
|
+
RouteId extends string | null = string | null
|
|
680
|
+
> = (event: LoadEvent<Params, InputData, ParentData, RouteId>) => MaybePromise<OutputData>;
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* The generic form of `PageLoadEvent` and `LayoutLoadEvent`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
684
|
+
* rather than using `LoadEvent` directly.
|
|
685
|
+
*/
|
|
686
|
+
export interface LoadEvent<
|
|
687
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
688
|
+
Data extends Record<string, unknown> | null = Record<string, any> | null,
|
|
689
|
+
ParentData extends Record<string, unknown> = Record<string, any>,
|
|
690
|
+
RouteId extends string | null = string | null
|
|
691
|
+
> extends NavigationEvent<Params, RouteId> {
|
|
692
|
+
/**
|
|
693
|
+
* `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
|
|
694
|
+
*
|
|
695
|
+
* - it can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request
|
|
696
|
+
* - it can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context)
|
|
697
|
+
* - 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
|
|
698
|
+
* - 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)
|
|
699
|
+
* - during hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request
|
|
700
|
+
*
|
|
701
|
+
* > Cookies will only be passed through if the target host is the same as the SvelteKit application or a more specific subdomain of it.
|
|
702
|
+
*/
|
|
703
|
+
fetch: typeof fetch;
|
|
704
|
+
/**
|
|
705
|
+
* Contains the data returned by the route's server `load` function (in `+layout.server.js` or `+page.server.js`), if any.
|
|
706
|
+
*/
|
|
707
|
+
data: Data;
|
|
708
|
+
/**
|
|
709
|
+
* 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:
|
|
710
|
+
*
|
|
711
|
+
* ```js
|
|
712
|
+
* /// file: src/routes/blog/+page.js
|
|
713
|
+
* export async function load({ fetch, setHeaders }) {
|
|
714
|
+
* const url = `https://cms.example.com/articles.json`;
|
|
715
|
+
* const response = await fetch(url);
|
|
716
|
+
*
|
|
717
|
+
* setHeaders({
|
|
718
|
+
* age: response.headers.get('age'),
|
|
719
|
+
* 'cache-control': response.headers.get('cache-control')
|
|
720
|
+
* });
|
|
721
|
+
*
|
|
722
|
+
* return response.json();
|
|
723
|
+
* }
|
|
724
|
+
* ```
|
|
725
|
+
*
|
|
726
|
+
* Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
|
|
727
|
+
*
|
|
728
|
+
* 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.
|
|
729
|
+
*
|
|
730
|
+
* `setHeaders` has no effect when a `load` function runs in the browser.
|
|
731
|
+
*/
|
|
732
|
+
setHeaders(headers: Record<string, string>): void;
|
|
733
|
+
/**
|
|
734
|
+
* `await parent()` returns data from parent `+layout.js` `load` functions.
|
|
735
|
+
* 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.
|
|
736
|
+
*
|
|
737
|
+
* 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.
|
|
738
|
+
*/
|
|
739
|
+
parent(): Promise<ParentData>;
|
|
740
|
+
/**
|
|
741
|
+
* 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.
|
|
742
|
+
*
|
|
743
|
+
* 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`.
|
|
744
|
+
*
|
|
745
|
+
* 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).
|
|
746
|
+
*
|
|
747
|
+
* 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).
|
|
748
|
+
*
|
|
749
|
+
* 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.
|
|
750
|
+
*
|
|
751
|
+
* ```js
|
|
752
|
+
* /// file: src/routes/+page.js
|
|
753
|
+
* let count = 0;
|
|
754
|
+
* export async function load({ depends }) {
|
|
755
|
+
* depends('increase:count');
|
|
756
|
+
*
|
|
757
|
+
* return { count: count++ };
|
|
758
|
+
* }
|
|
759
|
+
* ```
|
|
760
|
+
*
|
|
761
|
+
* ```html
|
|
762
|
+
* /// file: src/routes/+page.svelte
|
|
763
|
+
* <script>
|
|
764
|
+
* import { invalidate } from '$app/navigation';
|
|
765
|
+
*
|
|
766
|
+
* export let data;
|
|
767
|
+
*
|
|
768
|
+
* const increase = async () => {
|
|
769
|
+
* await invalidate('increase:count');
|
|
770
|
+
* }
|
|
771
|
+
* </script>
|
|
772
|
+
*
|
|
773
|
+
* <p>{data.count}<p>
|
|
774
|
+
* <button on:click={increase}>Increase Count</button>
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
777
|
+
depends(...deps: string[]): void;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
export interface NavigationEvent<
|
|
781
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
782
|
+
RouteId extends string | null = string | null
|
|
783
|
+
> {
|
|
784
|
+
/**
|
|
785
|
+
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
786
|
+
*/
|
|
787
|
+
params: Params;
|
|
788
|
+
/**
|
|
789
|
+
* Info about the current route
|
|
790
|
+
*/
|
|
791
|
+
route: {
|
|
792
|
+
/**
|
|
793
|
+
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
794
|
+
*/
|
|
795
|
+
id: RouteId;
|
|
796
|
+
};
|
|
797
|
+
/**
|
|
798
|
+
* The URL of the current page
|
|
799
|
+
*/
|
|
800
|
+
url: URL;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Information about the target of a specific navigation.
|
|
805
|
+
*/
|
|
806
|
+
export interface NavigationTarget {
|
|
807
|
+
/**
|
|
808
|
+
* Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
809
|
+
* Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
|
|
810
|
+
*/
|
|
811
|
+
params: Record<string, string> | null;
|
|
812
|
+
/**
|
|
813
|
+
* Info about the target route
|
|
814
|
+
*/
|
|
815
|
+
route: { id: string | null };
|
|
816
|
+
/**
|
|
817
|
+
* The URL that is navigated to
|
|
818
|
+
*/
|
|
819
|
+
url: URL;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* - `enter`: The app has hydrated
|
|
824
|
+
* - `form`: The user submitted a `<form>`
|
|
825
|
+
* - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
|
|
826
|
+
* - `link`: Navigation was triggered by a link click
|
|
827
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
828
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
829
|
+
*/
|
|
830
|
+
export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
831
|
+
|
|
832
|
+
export interface Navigation {
|
|
833
|
+
/**
|
|
834
|
+
* Where navigation was triggered from
|
|
835
|
+
*/
|
|
836
|
+
from: NavigationTarget | null;
|
|
837
|
+
/**
|
|
838
|
+
* Where navigation is going to/has gone to
|
|
839
|
+
*/
|
|
840
|
+
to: NavigationTarget | null;
|
|
841
|
+
/**
|
|
842
|
+
* The type of navigation:
|
|
843
|
+
* - `form`: The user submitted a `<form>`
|
|
844
|
+
* - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
|
|
845
|
+
* - `link`: Navigation was triggered by a link click
|
|
846
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
847
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
848
|
+
*/
|
|
849
|
+
type: Omit<NavigationType, 'enter'>;
|
|
850
|
+
/**
|
|
851
|
+
* Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation)
|
|
852
|
+
*/
|
|
853
|
+
willUnload: boolean;
|
|
854
|
+
/**
|
|
855
|
+
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
856
|
+
*/
|
|
857
|
+
delta?: number;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* The argument passed to [`beforeNavigate`](https://kit.svelte.dev/docs/modules#$app-navigation-beforenavigate) callbacks.
|
|
862
|
+
*/
|
|
863
|
+
export interface BeforeNavigate extends Navigation {
|
|
864
|
+
/**
|
|
865
|
+
* Call this to prevent the navigation from starting.
|
|
866
|
+
*/
|
|
867
|
+
cancel(): void;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* The argument passed to [`afterNavigate`](https://kit.svelte.dev/docs/modules#$app-navigation-afternavigate) callbacks.
|
|
872
|
+
*/
|
|
873
|
+
export interface AfterNavigate extends Navigation {
|
|
874
|
+
/**
|
|
875
|
+
* The type of navigation:
|
|
876
|
+
* - `enter`: The app has hydrated
|
|
877
|
+
* - `form`: The user submitted a `<form>`
|
|
878
|
+
* - `link`: Navigation was triggered by a link click
|
|
879
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
880
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
881
|
+
*/
|
|
882
|
+
type: Omit<NavigationType, 'leave'>;
|
|
883
|
+
/**
|
|
884
|
+
* Since `afterNavigate` is called after a navigation completes, it will never be called with a navigation that unloads the page.
|
|
885
|
+
*/
|
|
886
|
+
willUnload: false;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* The shape of the `$page` store
|
|
891
|
+
*/
|
|
892
|
+
export interface Page<
|
|
893
|
+
Params extends Record<string, string> = Record<string, string>,
|
|
894
|
+
RouteId extends string | null = string | null
|
|
895
|
+
> {
|
|
896
|
+
/**
|
|
897
|
+
* The URL of the current page
|
|
898
|
+
*/
|
|
899
|
+
url: URL;
|
|
900
|
+
/**
|
|
901
|
+
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
902
|
+
*/
|
|
903
|
+
params: Params;
|
|
904
|
+
/**
|
|
905
|
+
* Info about the current route
|
|
906
|
+
*/
|
|
907
|
+
route: {
|
|
908
|
+
/**
|
|
909
|
+
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
910
|
+
*/
|
|
911
|
+
id: RouteId;
|
|
912
|
+
};
|
|
913
|
+
/**
|
|
914
|
+
* Http status code of the current page
|
|
915
|
+
*/
|
|
916
|
+
status: number;
|
|
917
|
+
/**
|
|
918
|
+
* The error object of the current page, if any. Filled from the `handleError` hooks.
|
|
919
|
+
*/
|
|
920
|
+
error: App.Error | null;
|
|
921
|
+
/**
|
|
922
|
+
* The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
|
|
923
|
+
*/
|
|
924
|
+
data: App.PageData & Record<string, any>;
|
|
925
|
+
/**
|
|
926
|
+
* Filled only after a form submission. See [form actions](https://kit.svelte.dev/docs/form-actions) for more info.
|
|
927
|
+
*/
|
|
928
|
+
form: any;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* The shape of a param matcher. See [matching](https://kit.svelte.dev/docs/advanced-routing#matching) for more info.
|
|
933
|
+
*/
|
|
934
|
+
export type ParamMatcher = (param: string) => boolean;
|
|
935
|
+
|
|
936
|
+
export interface RequestEvent<
|
|
937
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
938
|
+
RouteId extends string | null = string | null
|
|
939
|
+
> {
|
|
940
|
+
/**
|
|
941
|
+
* Get or set cookies related to the current request
|
|
942
|
+
*/
|
|
943
|
+
cookies: Cookies;
|
|
944
|
+
/**
|
|
945
|
+
* `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
|
|
946
|
+
*
|
|
947
|
+
* - it can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request
|
|
948
|
+
* - it can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context)
|
|
949
|
+
* - 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
|
|
950
|
+
*
|
|
951
|
+
* > Cookies will only be passed through if the target host is the same as the SvelteKit application or a more specific subdomain of it.
|
|
952
|
+
*/
|
|
953
|
+
fetch: typeof fetch;
|
|
954
|
+
/**
|
|
955
|
+
* The client's IP address, set by the adapter.
|
|
956
|
+
*/
|
|
957
|
+
getClientAddress(): string;
|
|
958
|
+
/**
|
|
959
|
+
* Contains custom data that was added to the request within the [`handle hook`](https://kit.svelte.dev/docs/hooks#server-hooks-handle).
|
|
960
|
+
*/
|
|
961
|
+
locals: App.Locals;
|
|
962
|
+
/**
|
|
963
|
+
* The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
964
|
+
*/
|
|
965
|
+
params: Params;
|
|
966
|
+
/**
|
|
967
|
+
* Additional data made available through the adapter.
|
|
968
|
+
*/
|
|
969
|
+
platform: Readonly<App.Platform> | undefined;
|
|
970
|
+
/**
|
|
971
|
+
* The original request object
|
|
972
|
+
*/
|
|
973
|
+
request: Request;
|
|
974
|
+
/**
|
|
975
|
+
* Info about the current route
|
|
976
|
+
*/
|
|
977
|
+
route: {
|
|
978
|
+
/**
|
|
979
|
+
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`
|
|
980
|
+
*/
|
|
981
|
+
id: RouteId;
|
|
982
|
+
};
|
|
983
|
+
/**
|
|
984
|
+
* 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:
|
|
985
|
+
*
|
|
986
|
+
* ```js
|
|
987
|
+
* /// file: src/routes/blog/+page.js
|
|
988
|
+
* export async function load({ fetch, setHeaders }) {
|
|
989
|
+
* const url = `https://cms.example.com/articles.json`;
|
|
990
|
+
* const response = await fetch(url);
|
|
991
|
+
*
|
|
992
|
+
* setHeaders({
|
|
993
|
+
* age: response.headers.get('age'),
|
|
994
|
+
* 'cache-control': response.headers.get('cache-control')
|
|
995
|
+
* });
|
|
996
|
+
*
|
|
997
|
+
* return response.json();
|
|
998
|
+
* }
|
|
999
|
+
* ```
|
|
1000
|
+
*
|
|
1001
|
+
* Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
|
|
1002
|
+
*
|
|
1003
|
+
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#public-types-cookies) API instead.
|
|
1004
|
+
*/
|
|
1005
|
+
setHeaders(headers: Record<string, string>): void;
|
|
1006
|
+
/**
|
|
1007
|
+
* The requested URL.
|
|
1008
|
+
*/
|
|
1009
|
+
url: URL;
|
|
1010
|
+
/**
|
|
1011
|
+
* `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
|
|
1012
|
+
* related to the data request in this case. Use this property instead if the distinction is important to you.
|
|
1013
|
+
*/
|
|
1014
|
+
isDataRequest: boolean;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* 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.
|
|
1019
|
+
*
|
|
1020
|
+
* 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.
|
|
1021
|
+
*/
|
|
1022
|
+
export type RequestHandler<
|
|
1023
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1024
|
+
RouteId extends string | null = string | null
|
|
1025
|
+
> = (event: RequestEvent<Params, RouteId>) => MaybePromise<Response>;
|
|
1026
|
+
|
|
1027
|
+
export interface ResolveOptions {
|
|
1028
|
+
/**
|
|
1029
|
+
* Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
|
|
1030
|
+
* (they could include an element's opening tag but not its closing tag, for example)
|
|
1031
|
+
* but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
|
|
1032
|
+
* @param input the html chunk and the info if this is the last chunk
|
|
1033
|
+
*/
|
|
1034
|
+
transformPageChunk?(input: { html: string; done: boolean }): MaybePromise<string | undefined>;
|
|
1035
|
+
/**
|
|
1036
|
+
* Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
|
|
1037
|
+
* By default, none will be included.
|
|
1038
|
+
* @param name header name
|
|
1039
|
+
* @param value header value
|
|
1040
|
+
*/
|
|
1041
|
+
filterSerializedResponseHeaders?(name: string, value: string): boolean;
|
|
1042
|
+
/**
|
|
1043
|
+
* Determines what should be added to the `<head>` tag to preload it.
|
|
1044
|
+
* By default, `js` and `css` files will be preloaded.
|
|
1045
|
+
* @param input the type of the file and its path
|
|
1046
|
+
*/
|
|
1047
|
+
preload?(input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }): boolean;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
export interface RouteDefinition<Config = any> {
|
|
1051
|
+
id: string;
|
|
1052
|
+
api: {
|
|
1053
|
+
methods: HttpMethod[];
|
|
1054
|
+
};
|
|
1055
|
+
page: {
|
|
1056
|
+
methods: Extract<HttpMethod, 'GET' | 'POST'>[];
|
|
1057
|
+
};
|
|
1058
|
+
pattern: RegExp;
|
|
1059
|
+
prerender: PrerenderOption;
|
|
1060
|
+
segments: RouteSegment[];
|
|
1061
|
+
methods: HttpMethod[];
|
|
1062
|
+
config: Config;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
export class Server {
|
|
1066
|
+
constructor(manifest: SSRManifest);
|
|
1067
|
+
init(options: ServerInitOptions): Promise<void>;
|
|
1068
|
+
respond(request: Request, options: RequestOptions): Promise<Response>;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
export interface ServerInitOptions {
|
|
1072
|
+
env: Record<string, string>;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
export interface SSRManifest {
|
|
1076
|
+
appDir: string;
|
|
1077
|
+
appPath: string;
|
|
1078
|
+
assets: Set<string>;
|
|
1079
|
+
mimeTypes: Record<string, string>;
|
|
1080
|
+
|
|
1081
|
+
/** private fields */
|
|
1082
|
+
_: {
|
|
1083
|
+
client: NonNullable<BuildData['client']>;
|
|
1084
|
+
nodes: SSRNodeLoader[];
|
|
1085
|
+
routes: SSRRoute[];
|
|
1086
|
+
matchers(): Promise<Record<string, ParamMatcher>>;
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
1092
|
+
* rather than using `ServerLoad` directly.
|
|
1093
|
+
*/
|
|
1094
|
+
export type ServerLoad<
|
|
1095
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1096
|
+
ParentData extends Record<string, any> = Record<string, any>,
|
|
1097
|
+
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1098
|
+
RouteId extends string | null = string | null
|
|
1099
|
+
> = (event: ServerLoadEvent<Params, ParentData, RouteId>) => MaybePromise<OutputData>;
|
|
1100
|
+
|
|
1101
|
+
export interface ServerLoadEvent<
|
|
1102
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1103
|
+
ParentData extends Record<string, any> = Record<string, any>,
|
|
1104
|
+
RouteId extends string | null = string | null
|
|
1105
|
+
> extends RequestEvent<Params, RouteId> {
|
|
1106
|
+
/**
|
|
1107
|
+
* `await parent()` returns data from parent `+layout.server.js` `load` functions.
|
|
1108
|
+
*
|
|
1109
|
+
* 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.
|
|
1110
|
+
*/
|
|
1111
|
+
parent(): Promise<ParentData>;
|
|
1112
|
+
/**
|
|
1113
|
+
* 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.
|
|
1114
|
+
*
|
|
1115
|
+
* 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`.
|
|
1116
|
+
*
|
|
1117
|
+
* 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).
|
|
1118
|
+
*
|
|
1119
|
+
* 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).
|
|
1120
|
+
*
|
|
1121
|
+
* 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.
|
|
1122
|
+
*
|
|
1123
|
+
* ```js
|
|
1124
|
+
* /// file: src/routes/+page.js
|
|
1125
|
+
* let count = 0;
|
|
1126
|
+
* export async function load({ depends }) {
|
|
1127
|
+
* depends('increase:count');
|
|
1128
|
+
*
|
|
1129
|
+
* return { count: count++ };
|
|
1130
|
+
* }
|
|
1131
|
+
* ```
|
|
1132
|
+
*
|
|
1133
|
+
* ```html
|
|
1134
|
+
* /// file: src/routes/+page.svelte
|
|
1135
|
+
* <script>
|
|
1136
|
+
* import { invalidate } from '$app/navigation';
|
|
1137
|
+
*
|
|
1138
|
+
* export let data;
|
|
1139
|
+
*
|
|
1140
|
+
* const increase = async () => {
|
|
1141
|
+
* await invalidate('increase:count');
|
|
1142
|
+
* }
|
|
1143
|
+
* </script>
|
|
1144
|
+
*
|
|
1145
|
+
* <p>{data.count}<p>
|
|
1146
|
+
* <button on:click={increase}>Increase Count</button>
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
depends(...deps: string[]): void;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Shape of a form action method that is part of `export const actions = {..}` in `+page.server.js`.
|
|
1154
|
+
* See [form actions](https://kit.svelte.dev/docs/form-actions) for more information.
|
|
1155
|
+
*/
|
|
1156
|
+
export type Action<
|
|
1157
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1158
|
+
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1159
|
+
RouteId extends string | null = string | null
|
|
1160
|
+
> = (event: RequestEvent<Params, RouteId>) => MaybePromise<OutputData>;
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Shape of the `export const actions = {..}` object in `+page.server.js`.
|
|
1164
|
+
* See [form actions](https://kit.svelte.dev/docs/form-actions) for more information.
|
|
1165
|
+
*/
|
|
1166
|
+
export type Actions<
|
|
1167
|
+
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
1168
|
+
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
1169
|
+
RouteId extends string | null = string | null
|
|
1170
|
+
> = Record<string, Action<Params, OutputData, RouteId>>;
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* When calling a form action via fetch, the response will be one of these shapes.
|
|
1174
|
+
* ```svelte
|
|
1175
|
+
* <form method="post" use:enhance={() => {
|
|
1176
|
+
* return ({ result }) => {
|
|
1177
|
+
* // result is of type ActionResult
|
|
1178
|
+
* };
|
|
1179
|
+
* }}
|
|
1180
|
+
* ```
|
|
1181
|
+
*/
|
|
1182
|
+
export type ActionResult<
|
|
1183
|
+
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1184
|
+
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
1185
|
+
> =
|
|
1186
|
+
| { type: 'success'; status: number; data?: Success }
|
|
1187
|
+
| { type: 'failure'; status: number; data?: Failure }
|
|
1188
|
+
| { type: 'redirect'; status: number; location: string }
|
|
1189
|
+
| { type: 'error'; status?: number; error: any };
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
* The object returned by the [`error`](https://kit.svelte.dev/docs/modules#sveltejs-kit-error) function.
|
|
1193
|
+
*/
|
|
1194
|
+
export interface HttpError {
|
|
1195
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
|
|
1196
|
+
status: number;
|
|
1197
|
+
/** The content of the error. */
|
|
1198
|
+
body: App.Error;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* The object returned by the [`redirect`](https://kit.svelte.dev/docs/modules#sveltejs-kit-redirect) function
|
|
1203
|
+
*/
|
|
1204
|
+
export interface Redirect {
|
|
1205
|
+
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
|
|
1206
|
+
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
1207
|
+
/** The location to redirect to. */
|
|
1208
|
+
location: string;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
export type SubmitFunction<
|
|
1212
|
+
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1213
|
+
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
1214
|
+
> = (input: {
|
|
1215
|
+
action: URL;
|
|
1216
|
+
/**
|
|
1217
|
+
* use `formData` instead of `data`
|
|
1218
|
+
* @deprecated
|
|
1219
|
+
*/
|
|
1220
|
+
data: FormData;
|
|
1221
|
+
formData: FormData;
|
|
1222
|
+
/**
|
|
1223
|
+
* use `formElement` instead of `form`
|
|
1224
|
+
* @deprecated
|
|
1225
|
+
*/
|
|
1226
|
+
form: HTMLFormElement;
|
|
1227
|
+
formElement: HTMLFormElement;
|
|
1228
|
+
controller: AbortController;
|
|
1229
|
+
submitter: HTMLElement | null;
|
|
1230
|
+
cancel(): void;
|
|
1231
|
+
}) => MaybePromise<
|
|
1232
|
+
| void
|
|
1233
|
+
| ((opts: {
|
|
1234
|
+
/**
|
|
1235
|
+
* use `formData` instead of `data`
|
|
1236
|
+
* @deprecated
|
|
1237
|
+
*/
|
|
1238
|
+
data: FormData;
|
|
1239
|
+
formData: FormData;
|
|
1240
|
+
/**
|
|
1241
|
+
* use `formElement` instead of `form`
|
|
1242
|
+
* @deprecated
|
|
1243
|
+
*/
|
|
1244
|
+
form: HTMLFormElement;
|
|
1245
|
+
formElement: HTMLFormElement;
|
|
1246
|
+
action: URL;
|
|
1247
|
+
result: ActionResult<Success, Failure>;
|
|
1248
|
+
/**
|
|
1249
|
+
* Call this to get the default behavior of a form submission response.
|
|
1250
|
+
* @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission.
|
|
1251
|
+
*/
|
|
1252
|
+
update(options?: { reset: boolean }): Promise<void>;
|
|
1253
|
+
}) => void)
|
|
1254
|
+
>;
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* The type of `export const snapshot` exported from a page or layout component.
|
|
1258
|
+
*/
|
|
1259
|
+
export interface Snapshot<T = any> {
|
|
1260
|
+
capture: () => T;
|
|
1261
|
+
restore: (snapshot: T) => void;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export * from './index.js';
|