@sveltejs/kit 1.0.0-next.565 → 1.0.0-next.566
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 +3 -5
- package/src/core/sync/write_ambient.js +5 -1
- package/types/ambient.d.ts +9 -46
- package/types/index.d.ts +394 -38
- package/types/private.d.ts +9 -0
- package/scripts/special-types/$env+dynamic+private.md +0 -10
- package/scripts/special-types/$env+dynamic+public.md +0 -8
- package/scripts/special-types/$env+static+private.md +0 -19
- package/scripts/special-types/$env+static+public.md +0 -7
- package/scripts/special-types/$lib.md +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.566",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -53,8 +53,7 @@
|
|
|
53
53
|
"!src/core/**/test",
|
|
54
54
|
"types",
|
|
55
55
|
"svelte-kit.js",
|
|
56
|
-
"postinstall.js"
|
|
57
|
-
"scripts/special-types"
|
|
56
|
+
"postinstall.js"
|
|
58
57
|
],
|
|
59
58
|
"exports": {
|
|
60
59
|
"./package.json": "./package.json",
|
|
@@ -80,7 +79,7 @@
|
|
|
80
79
|
"node": ">=16.14"
|
|
81
80
|
},
|
|
82
81
|
"scripts": {
|
|
83
|
-
"build": "
|
|
82
|
+
"build": "echo \"TODO remove build script from packages/kit\"",
|
|
84
83
|
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
|
|
85
84
|
"check": "tsc",
|
|
86
85
|
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
|
|
@@ -88,7 +87,6 @@
|
|
|
88
87
|
"test": "pnpm test:unit && pnpm test:integration",
|
|
89
88
|
"test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
90
89
|
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
|
|
91
|
-
"types": "node scripts/extract-types.js",
|
|
92
90
|
"postinstall": "node postinstall.js"
|
|
93
91
|
}
|
|
94
92
|
}
|
|
@@ -6,7 +6,11 @@ import { create_dynamic_types, create_static_types } from '../env.js';
|
|
|
6
6
|
import { write_if_changed } from './utils.js';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// TODO these types should be described in a neutral place, rather than
|
|
10
|
+
// inside either `packages/kit` or `kit.svelte.dev`
|
|
11
|
+
const descriptions_dir = fileURLToPath(
|
|
12
|
+
new URL('../../../../../sites/kit.svelte.dev/scripts/types/special-types', import.meta.url)
|
|
13
|
+
);
|
|
10
14
|
|
|
11
15
|
/** @param {string} filename */
|
|
12
16
|
function read_description(filename) {
|
package/types/ambient.d.ts
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
* /// <reference types="@sveltejs/kit" />
|
|
6
6
|
*
|
|
7
7
|
* declare namespace App {
|
|
8
|
+
* interface Error {}
|
|
8
9
|
* interface Locals {}
|
|
9
|
-
*
|
|
10
10
|
* interface PageData {}
|
|
11
|
-
*
|
|
12
11
|
* interface Platform {}
|
|
13
12
|
* }
|
|
14
13
|
* ```
|
|
@@ -65,11 +64,6 @@ declare namespace App {
|
|
|
65
64
|
export interface Platform {}
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
/**
|
|
69
|
-
* ```ts
|
|
70
|
-
* import { browser, building, dev, version } from '$app/environment';
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
67
|
declare module '$app/environment' {
|
|
74
68
|
/**
|
|
75
69
|
* `true` if the app is running in the browser.
|
|
@@ -92,17 +86,14 @@ declare module '$app/environment' {
|
|
|
92
86
|
export const version: string;
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
/**
|
|
96
|
-
* ```ts
|
|
97
|
-
* import { enhance, applyAction } from '$app/forms';
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
89
|
declare module '$app/forms' {
|
|
101
90
|
import type { ActionResult } from '@sveltejs/kit';
|
|
102
91
|
|
|
103
92
|
type MaybePromise<T> = T | Promise<T>;
|
|
104
93
|
|
|
105
|
-
|
|
94
|
+
// this is duplicated in @sveltejs/kit because create-svelte tests fail
|
|
95
|
+
// if we use the imported version. TODO investigate
|
|
96
|
+
type SubmitFunction<
|
|
106
97
|
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
107
98
|
Invalid extends Record<string, unknown> | undefined = Record<string, any>
|
|
108
99
|
> = (input: {
|
|
@@ -166,9 +157,10 @@ declare module '$app/forms' {
|
|
|
166
157
|
/**
|
|
167
158
|
* Use this function to deserialize the response from a form submission.
|
|
168
159
|
* Usage:
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* const
|
|
160
|
+
*
|
|
161
|
+
* ```js
|
|
162
|
+
* const response = await fetch('/form?/action', { method: 'POST', body: formData });
|
|
163
|
+
* const result = deserialize(await response.text());
|
|
172
164
|
* ```
|
|
173
165
|
*/
|
|
174
166
|
export function deserialize<
|
|
@@ -177,20 +169,6 @@ declare module '$app/forms' {
|
|
|
177
169
|
>(serialized: string): ActionResult<Success, Invalid>;
|
|
178
170
|
}
|
|
179
171
|
|
|
180
|
-
/**
|
|
181
|
-
* ```ts
|
|
182
|
-
* import {
|
|
183
|
-
* afterNavigate,
|
|
184
|
-
* beforeNavigate,
|
|
185
|
-
* disableScrollHandling,
|
|
186
|
-
* goto,
|
|
187
|
-
* invalidate,
|
|
188
|
-
* invalidateAll,
|
|
189
|
-
* preloadCode,
|
|
190
|
-
* preloadData
|
|
191
|
-
* } from '$app/navigation';
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
172
|
declare module '$app/navigation' {
|
|
195
173
|
import { BeforeNavigate, AfterNavigate } from '@sveltejs/kit';
|
|
196
174
|
|
|
@@ -291,11 +269,6 @@ declare module '$app/navigation' {
|
|
|
291
269
|
export function afterNavigate(callback: (navigation: AfterNavigate) => void): void;
|
|
292
270
|
}
|
|
293
271
|
|
|
294
|
-
/**
|
|
295
|
-
* ```ts
|
|
296
|
-
* import { base, assets } from '$app/paths';
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
272
|
declare module '$app/paths' {
|
|
300
273
|
/**
|
|
301
274
|
* A string that matches [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths).
|
|
@@ -312,10 +285,6 @@ declare module '$app/paths' {
|
|
|
312
285
|
}
|
|
313
286
|
|
|
314
287
|
/**
|
|
315
|
-
* ```ts
|
|
316
|
-
* import { getStores, navigating, page, updated } from '$app/stores';
|
|
317
|
-
* ```
|
|
318
|
-
*
|
|
319
288
|
* Stores on the server are _contextual_ — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `page` is unique to each request, rather than shared between multiple requests handled by the same server simultaneously.
|
|
320
289
|
*
|
|
321
290
|
* Because of that, you must subscribe to the stores during component initialization (which happens automatically if you reference the store value, e.g. as `$page`, in a component) before you can use them.
|
|
@@ -353,10 +322,6 @@ declare module '$app/stores' {
|
|
|
353
322
|
}
|
|
354
323
|
|
|
355
324
|
/**
|
|
356
|
-
* ```ts
|
|
357
|
-
* import { build, files, prerendered, version } from '$service-worker';
|
|
358
|
-
* ```
|
|
359
|
-
*
|
|
360
325
|
* This module is only available to [service workers](https://kit.svelte.dev/docs/service-workers).
|
|
361
326
|
*/
|
|
362
327
|
declare module '$service-worker' {
|
|
@@ -387,10 +352,9 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
387
352
|
* A helper function for sequencing multiple `handle` calls in a middleware-like manner.
|
|
388
353
|
*
|
|
389
354
|
* ```js
|
|
390
|
-
* /// file: src/hooks.js
|
|
355
|
+
* /// file: src/hooks.server.js
|
|
391
356
|
* import { sequence } from '@sveltejs/kit/hooks';
|
|
392
357
|
*
|
|
393
|
-
* /** @type {import('@sveltejs/kit').Handle} *\/
|
|
394
358
|
* async function first({ event, resolve }) {
|
|
395
359
|
* console.log('first pre-processing');
|
|
396
360
|
* const result = await resolve(event, {
|
|
@@ -404,7 +368,6 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
404
368
|
* return result;
|
|
405
369
|
* }
|
|
406
370
|
*
|
|
407
|
-
* /** @type {import('@sveltejs/kit').Handle} *\/
|
|
408
371
|
* async function second({ event, resolve }) {
|
|
409
372
|
* console.log('second pre-processing');
|
|
410
373
|
* const result = await resolve(event, {
|
package/types/index.d.ts
CHANGED
|
@@ -14,15 +14,24 @@ import {
|
|
|
14
14
|
PrerenderMissingIdHandlerValue,
|
|
15
15
|
RequestOptions,
|
|
16
16
|
RouteDefinition,
|
|
17
|
-
TrailingSlash,
|
|
18
17
|
UniqueInterface
|
|
19
18
|
} from './private.js';
|
|
20
19
|
import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
|
|
21
20
|
|
|
22
21
|
export { PrerenderOption } from './private.js';
|
|
23
22
|
|
|
23
|
+
/**
|
|
24
|
+
* [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.
|
|
25
|
+
*/
|
|
24
26
|
export interface Adapter {
|
|
27
|
+
/**
|
|
28
|
+
* The name of the adapter, using for logging. Will typically correspond to the package name.
|
|
29
|
+
*/
|
|
25
30
|
name: string;
|
|
31
|
+
/**
|
|
32
|
+
* This function is called after SvelteKit has built your app.
|
|
33
|
+
* @param builder An object provided by SvelteKit that contains methods for adapting the app
|
|
34
|
+
*/
|
|
26
35
|
adapt(builder: Builder): MaybePromise<void>;
|
|
27
36
|
}
|
|
28
37
|
|
|
@@ -58,35 +67,58 @@ type UnpackValidationError<T> = T extends ValidationError<infer X>
|
|
|
58
67
|
? undefined // needs to be undefined, because void will corrupt union type
|
|
59
68
|
: T;
|
|
60
69
|
|
|
70
|
+
/**
|
|
71
|
+
* This object is passed to the `adapt` function of adapters.
|
|
72
|
+
* It contains various methods and properties that are useful for adapting the app.
|
|
73
|
+
*/
|
|
61
74
|
export interface Builder {
|
|
75
|
+
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
|
|
62
76
|
log: Logger;
|
|
77
|
+
/** Remove `dir` and all its contents. */
|
|
63
78
|
rimraf(dir: string): void;
|
|
79
|
+
/** Create `dir` and any required parent directories. */
|
|
64
80
|
mkdirp(dir: string): void;
|
|
65
81
|
|
|
82
|
+
/** The fully resolved `svelte.config.js`. */
|
|
66
83
|
config: ValidatedConfig;
|
|
84
|
+
/** Information about prerendered pages and assets, if any. */
|
|
67
85
|
prerendered: Prerendered;
|
|
68
86
|
|
|
69
87
|
/**
|
|
70
|
-
* Create
|
|
88
|
+
* Create separate functions that map to one or more routes of your app.
|
|
71
89
|
* @param fn A function that groups a set of routes into an entry point
|
|
72
90
|
*/
|
|
73
91
|
createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
|
|
74
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Generate a server-side manifest to initialise the SvelteKit [server](https://kit.svelte.dev/docs/types#public-types-server) with.
|
|
95
|
+
* @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
|
|
96
|
+
*/
|
|
75
97
|
generateManifest(opts: { relativePath: string }): string;
|
|
76
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Resolve a path to the `name` directory inside `outDir`, e.g. `/path/to/.svelte-kit/my-adapter`.
|
|
101
|
+
* @param name path to the file, relative to the build directory
|
|
102
|
+
*/
|
|
77
103
|
getBuildDirectory(name: string): string;
|
|
104
|
+
/** Get the fully resolved path to the directory containing client-side assets, including the contents of your `static` directory. */
|
|
78
105
|
getClientDirectory(): string;
|
|
106
|
+
/** Get the fully resolved path to the directory containing server-side code. */
|
|
79
107
|
getServerDirectory(): string;
|
|
80
|
-
/**
|
|
108
|
+
/** Get the application path including any configured `base` path, e.g. `/my-base-path/_app`. */
|
|
81
109
|
getAppPath(): string;
|
|
82
110
|
|
|
83
111
|
/**
|
|
84
|
-
*
|
|
85
|
-
* @
|
|
112
|
+
* Write client assets to `dest`.
|
|
113
|
+
* @param dest the destination folder
|
|
114
|
+
* @returns an array of files written to `dest`
|
|
86
115
|
*/
|
|
87
116
|
writeClient(dest: string): string[];
|
|
88
117
|
/**
|
|
89
|
-
*
|
|
118
|
+
* Write prerendered files to `dest`.
|
|
119
|
+
* @param dest the destination folder
|
|
120
|
+
* @param opts.fallback the name of a file for fallback responses, like `200.html` or `404.html` depending on where the app is deployed
|
|
121
|
+
* @returns an array of files written to `dest`
|
|
90
122
|
*/
|
|
91
123
|
writePrerendered(
|
|
92
124
|
dest: string,
|
|
@@ -95,16 +127,18 @@ export interface Builder {
|
|
|
95
127
|
}
|
|
96
128
|
): string[];
|
|
97
129
|
/**
|
|
98
|
-
*
|
|
99
|
-
* @
|
|
130
|
+
* Write server-side code to `dest`.
|
|
131
|
+
* @param dest the destination folder
|
|
132
|
+
* @returns an array of files written to `dest`
|
|
100
133
|
*/
|
|
101
134
|
writeServer(dest: string): string[];
|
|
102
135
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @param
|
|
105
|
-
* @param
|
|
136
|
+
* Copy a file or directory.
|
|
137
|
+
* @param from the source file or directory
|
|
138
|
+
* @param to the destination file or directory
|
|
139
|
+
* @param opts.filter a function to determine whether a file or directory should be copied
|
|
106
140
|
* @param opts.replace a map of strings to replace
|
|
107
|
-
* @returns an array of
|
|
141
|
+
* @returns an array of files that were copied
|
|
108
142
|
*/
|
|
109
143
|
copy(
|
|
110
144
|
from: string,
|
|
@@ -116,15 +150,26 @@ export interface Builder {
|
|
|
116
150
|
): string[];
|
|
117
151
|
|
|
118
152
|
/**
|
|
119
|
-
*
|
|
153
|
+
* Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals.
|
|
154
|
+
* @param {string} directory The directory containing the files to be compressed
|
|
120
155
|
*/
|
|
121
156
|
compress(directory: string): Promise<void>;
|
|
122
157
|
}
|
|
123
158
|
|
|
124
159
|
export interface Config {
|
|
160
|
+
/**
|
|
161
|
+
* Options passed to [`svelte.compile`](https://svelte.dev/docs#compile-time-svelte-compile).
|
|
162
|
+
* @default {}
|
|
163
|
+
*/
|
|
125
164
|
compilerOptions?: CompileOptions;
|
|
165
|
+
/**
|
|
166
|
+
* List of file extensions that should be treated as Svelte files.
|
|
167
|
+
* @default [".svelte"]
|
|
168
|
+
*/
|
|
126
169
|
extensions?: string[];
|
|
170
|
+
/** SvelteKit options */
|
|
127
171
|
kit?: KitConfig;
|
|
172
|
+
/** [`@sveltejs/package`](/docs/packaging) options. */
|
|
128
173
|
package?: {
|
|
129
174
|
source?: string;
|
|
130
175
|
dir?: string;
|
|
@@ -132,13 +177,17 @@ export interface Config {
|
|
|
132
177
|
exports?(filepath: string): boolean;
|
|
133
178
|
files?(filepath: string): boolean;
|
|
134
179
|
};
|
|
180
|
+
/** Preprocessor options, if any. Preprocessing can alternatively also be done through Vite's preprocessor capabilities. */
|
|
135
181
|
preprocess?: any;
|
|
182
|
+
/** Any additional options required by tooling that integrates with Svelte. */
|
|
136
183
|
[key: string]: any;
|
|
137
184
|
}
|
|
138
185
|
|
|
139
186
|
export interface Cookies {
|
|
140
187
|
/**
|
|
141
188
|
* Gets a cookie that was previously set with `cookies.set`, or from the request headers.
|
|
189
|
+
* @param name the name of the cookie
|
|
190
|
+
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
|
|
142
191
|
*/
|
|
143
192
|
get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
|
|
144
193
|
|
|
@@ -148,6 +197,9 @@ export interface Cookies {
|
|
|
148
197
|
* 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`.
|
|
149
198
|
*
|
|
150
199
|
* 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.
|
|
200
|
+
* @param name the name of the cookie
|
|
201
|
+
* @param value the cookie value
|
|
202
|
+
* @param opts the options, passed directory to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
|
|
151
203
|
*/
|
|
152
204
|
set(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): void;
|
|
153
205
|
|
|
@@ -155,81 +207,320 @@ export interface Cookies {
|
|
|
155
207
|
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
|
|
156
208
|
*
|
|
157
209
|
* 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.
|
|
210
|
+
* @param name the name of the cookie
|
|
211
|
+
* @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)
|
|
158
212
|
*/
|
|
159
213
|
delete(name: string, opts?: import('cookie').CookieSerializeOptions): void;
|
|
160
214
|
|
|
161
215
|
/**
|
|
162
|
-
* Serialize a cookie name-value pair into a Set-Cookie header string.
|
|
216
|
+
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
|
|
163
217
|
*
|
|
164
218
|
* 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`.
|
|
165
219
|
*
|
|
166
220
|
* 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.
|
|
167
221
|
*
|
|
168
|
-
* @param name the name
|
|
169
|
-
* @param value
|
|
170
|
-
* @param options
|
|
222
|
+
* @param name the name of the cookie
|
|
223
|
+
* @param value the cookie value
|
|
224
|
+
* @param opts the options, passed directory to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
|
|
171
225
|
*/
|
|
172
226
|
serialize(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): string;
|
|
173
227
|
}
|
|
174
228
|
|
|
175
229
|
export interface KitConfig {
|
|
230
|
+
/**
|
|
231
|
+
* Your [adapter](https://kit.svelte.dev/docs/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms.
|
|
232
|
+
* @default undefined
|
|
233
|
+
*/
|
|
176
234
|
adapter?: Adapter;
|
|
235
|
+
/**
|
|
236
|
+
* An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
|
|
237
|
+
*
|
|
238
|
+
* ```js
|
|
239
|
+
* /// file: svelte.config.js
|
|
240
|
+
* /// type: import('@sveltejs/kit').Config
|
|
241
|
+
* const config = {
|
|
242
|
+
* kit: {
|
|
243
|
+
* alias: {
|
|
244
|
+
* // this will match a file
|
|
245
|
+
* 'my-file': 'path/to/my-file.js',
|
|
246
|
+
*
|
|
247
|
+
* // this will match a directory and its contents
|
|
248
|
+
* // (`my-directory/x` resolves to `path/to/my-directory/x`)
|
|
249
|
+
* 'my-directory': 'path/to/my-directory',
|
|
250
|
+
*
|
|
251
|
+
* // an alias ending /* will only match
|
|
252
|
+
* // the contents of a directory, not the directory itself
|
|
253
|
+
* 'my-directory/*': 'path/to/my-directory/*'
|
|
254
|
+
* }
|
|
255
|
+
* }
|
|
256
|
+
* };
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* > The built-in `$lib` alias is controlled by `config.kit.files.lib` as it is used for packaging.
|
|
260
|
+
*
|
|
261
|
+
* > You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
|
|
262
|
+
* @default {}
|
|
263
|
+
*/
|
|
177
264
|
alias?: Record<string, string>;
|
|
265
|
+
/**
|
|
266
|
+
* 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 `/`.
|
|
267
|
+
* @default "_app"
|
|
268
|
+
*/
|
|
178
269
|
appDir?: string;
|
|
270
|
+
/**
|
|
271
|
+
* [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...
|
|
272
|
+
*
|
|
273
|
+
* ```js
|
|
274
|
+
* /// file: svelte.config.js
|
|
275
|
+
* /// type: import('@sveltejs/kit').Config
|
|
276
|
+
* const config = {
|
|
277
|
+
* kit: {
|
|
278
|
+
* csp: {
|
|
279
|
+
* directives: {
|
|
280
|
+
* 'script-src': ['self']
|
|
281
|
+
* },
|
|
282
|
+
* reportOnly: {
|
|
283
|
+
* 'script-src': ['self']
|
|
284
|
+
* }
|
|
285
|
+
* }
|
|
286
|
+
* }
|
|
287
|
+
* };
|
|
288
|
+
*
|
|
289
|
+
* export default config;
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* ...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.
|
|
293
|
+
*
|
|
294
|
+
* 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%">`).
|
|
295
|
+
*
|
|
296
|
+
* 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).
|
|
297
|
+
*
|
|
298
|
+
* > 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.
|
|
299
|
+
*
|
|
300
|
+
* > 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`.
|
|
301
|
+
*/
|
|
179
302
|
csp?: {
|
|
303
|
+
/**
|
|
304
|
+
* 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.
|
|
305
|
+
*/
|
|
180
306
|
mode?: 'hash' | 'nonce' | 'auto';
|
|
307
|
+
/**
|
|
308
|
+
* Directives that will be added to `Content-Security-Policy` headers.
|
|
309
|
+
*/
|
|
181
310
|
directives?: CspDirectives;
|
|
311
|
+
/**
|
|
312
|
+
* Directives that will be added to `Content-Security-Policy-Report-Only` headers.
|
|
313
|
+
*/
|
|
182
314
|
reportOnly?: CspDirectives;
|
|
183
315
|
};
|
|
316
|
+
/**
|
|
317
|
+
* Protection against [cross-site request forgery](https://owasp.org/www-community/attacks/csrf) attacks.
|
|
318
|
+
*/
|
|
184
319
|
csrf?: {
|
|
320
|
+
/**
|
|
321
|
+
* Whether to check the incoming `origin` header for `POST` form submissions and verify that it matches the server's origin.
|
|
322
|
+
*
|
|
323
|
+
* To allow people to make `POST` form submissions to your app from other origins, you will need to disable this option. Be careful!
|
|
324
|
+
* @default true
|
|
325
|
+
*/
|
|
185
326
|
checkOrigin?: boolean;
|
|
186
327
|
};
|
|
328
|
+
/**
|
|
329
|
+
* Environment variable configuration
|
|
330
|
+
*/
|
|
187
331
|
env?: {
|
|
332
|
+
/**
|
|
333
|
+
* The directory to search for `.env` files.
|
|
334
|
+
* @default "."
|
|
335
|
+
*/
|
|
188
336
|
dir?: string;
|
|
337
|
+
/**
|
|
338
|
+
* 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.
|
|
339
|
+
* @default "PUBLIC_"
|
|
340
|
+
*/
|
|
189
341
|
publicPrefix?: string;
|
|
190
342
|
};
|
|
191
|
-
|
|
343
|
+
/**
|
|
344
|
+
* Where to find various files within your project.
|
|
345
|
+
*/
|
|
192
346
|
files?: {
|
|
347
|
+
/**
|
|
348
|
+
* a place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json`
|
|
349
|
+
* @default "static"
|
|
350
|
+
*/
|
|
193
351
|
assets?: string;
|
|
194
352
|
hooks?: {
|
|
353
|
+
/**
|
|
354
|
+
* The location of your client [hooks](https://kit.svelte.dev/docs/hooks).
|
|
355
|
+
* @default "src/hooks.client"
|
|
356
|
+
*/
|
|
195
357
|
client?: string;
|
|
358
|
+
/**
|
|
359
|
+
* The location of your server [hooks](https://kit.svelte.dev/docs/hooks).
|
|
360
|
+
* @default "src/hooks.server"
|
|
361
|
+
*/
|
|
196
362
|
server?: string;
|
|
197
363
|
};
|
|
364
|
+
/**
|
|
365
|
+
* your app's internal library, accessible throughout the codebase as `$lib`
|
|
366
|
+
* @default "src/lib"
|
|
367
|
+
*/
|
|
198
368
|
lib?: string;
|
|
369
|
+
/**
|
|
370
|
+
* a directory containing [parameter matchers](https://kit.svelte.dev/docs/advanced-routing#matching)
|
|
371
|
+
* @default "src/params"
|
|
372
|
+
*/
|
|
199
373
|
params?: string;
|
|
374
|
+
/**
|
|
375
|
+
* the files that define the structure of your app (see [Routing](https://kit.svelte.dev/docs/routing))
|
|
376
|
+
* @default "src/routes"
|
|
377
|
+
*/
|
|
200
378
|
routes?: string;
|
|
379
|
+
/**
|
|
380
|
+
* the location of your service worker's entry point (see [Service workers](https://kit.svelte.dev/docs/service-workers))
|
|
381
|
+
* @default "src/service-worker"
|
|
382
|
+
*/
|
|
201
383
|
serviceWorker?: string;
|
|
384
|
+
/**
|
|
385
|
+
* the location of the template for HTML responses
|
|
386
|
+
* @default "src/app.html"
|
|
387
|
+
*/
|
|
202
388
|
appTemplate?: string;
|
|
389
|
+
/**
|
|
390
|
+
* the location of the template for fallback error responses
|
|
391
|
+
* @default "src/error.html"
|
|
392
|
+
*/
|
|
203
393
|
errorTemplate?: string;
|
|
204
394
|
};
|
|
395
|
+
/**
|
|
396
|
+
* 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.
|
|
397
|
+
*
|
|
398
|
+
* > 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.
|
|
399
|
+
* @default 0
|
|
400
|
+
*/
|
|
205
401
|
inlineStyleThreshold?: number;
|
|
402
|
+
/**
|
|
403
|
+
* 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.
|
|
404
|
+
* @default [".js", ".ts"]
|
|
405
|
+
*/
|
|
406
|
+
moduleExtensions?: string[];
|
|
407
|
+
/**
|
|
408
|
+
* The directory that SvelteKit writes files to during `dev` and `build`. You should exclude this directory from version control.
|
|
409
|
+
* @default ".svelte-kit"
|
|
410
|
+
*/
|
|
206
411
|
outDir?: string;
|
|
207
412
|
paths?: {
|
|
413
|
+
/**
|
|
414
|
+
* 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.
|
|
415
|
+
* @default ""
|
|
416
|
+
*/
|
|
208
417
|
assets?: string;
|
|
418
|
+
/**
|
|
419
|
+
* 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.
|
|
420
|
+
* @default ""
|
|
421
|
+
*/
|
|
209
422
|
base?: string;
|
|
210
423
|
};
|
|
424
|
+
/**
|
|
425
|
+
* See [Prerendering](https://kit.svelte.dev/docs/page-options#prerender).
|
|
426
|
+
*/
|
|
211
427
|
prerender?: {
|
|
428
|
+
/**
|
|
429
|
+
* 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.
|
|
430
|
+
* @default 1
|
|
431
|
+
*/
|
|
212
432
|
concurrency?: number;
|
|
433
|
+
/**
|
|
434
|
+
* Whether SvelteKit should find pages to prerender by following links from `entries`.
|
|
435
|
+
* @default true
|
|
436
|
+
*/
|
|
213
437
|
crawl?: boolean;
|
|
214
|
-
|
|
438
|
+
/**
|
|
439
|
+
* 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).
|
|
440
|
+
* @default ["*"]
|
|
441
|
+
*/
|
|
215
442
|
entries?: Array<'*' | `/${string}`>;
|
|
443
|
+
/**
|
|
444
|
+
* How to respond to HTTP errors encountered while prerendering the app.
|
|
445
|
+
*
|
|
446
|
+
* - `'fail'` — fail the build
|
|
447
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
448
|
+
* - `'warn'` — continue, but print a warning
|
|
449
|
+
* - `(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
|
|
450
|
+
*
|
|
451
|
+
* ```js
|
|
452
|
+
* /// type: import('@sveltejs/kit').Config
|
|
453
|
+
* const config = {
|
|
454
|
+
* kit: {
|
|
455
|
+
* prerender: {
|
|
456
|
+
* handleHttpError: ({ path, referrer, message }) => {
|
|
457
|
+
* // ignore deliberate link to shiny 404 page
|
|
458
|
+
* if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
|
|
459
|
+
* return;
|
|
460
|
+
* }
|
|
461
|
+
*
|
|
462
|
+
* // otherwise fail the build
|
|
463
|
+
* throw new Error(message);
|
|
464
|
+
* }
|
|
465
|
+
* }
|
|
466
|
+
* }
|
|
467
|
+
* }
|
|
468
|
+
* };
|
|
469
|
+
* ```
|
|
470
|
+
*
|
|
471
|
+
* @default "fail"
|
|
472
|
+
*/
|
|
216
473
|
handleHttpError?: PrerenderHttpErrorHandlerValue;
|
|
474
|
+
/**
|
|
475
|
+
* How to respond to hash links from one prerendered page to another that don't correspond to an `id` on the destination page
|
|
476
|
+
*
|
|
477
|
+
* - `'fail'` — fail the build
|
|
478
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
479
|
+
* - `'warn'` — continue, but print a warning
|
|
480
|
+
* - `(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
|
|
481
|
+
*
|
|
482
|
+
* @default "fail"
|
|
483
|
+
*/
|
|
217
484
|
handleMissingId?: PrerenderMissingIdHandlerValue;
|
|
485
|
+
/**
|
|
486
|
+
* The value of `url.origin` during prerendering; useful if it is included in rendered content.
|
|
487
|
+
* @default "http://sveltekit-prerender"
|
|
488
|
+
*/
|
|
218
489
|
origin?: string;
|
|
219
490
|
};
|
|
220
491
|
serviceWorker?: {
|
|
492
|
+
/**
|
|
493
|
+
* Whether to automatically register the service worker, if it exists.
|
|
494
|
+
* @default true
|
|
495
|
+
*/
|
|
221
496
|
register?: boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Determine which files in your `static` directory will be available in `$service-worker.files`.
|
|
499
|
+
* @default (filename) => !/\.DS_Store/.test(filename)
|
|
500
|
+
*/
|
|
222
501
|
files?(filepath: string): boolean;
|
|
223
502
|
};
|
|
224
|
-
|
|
503
|
+
/**
|
|
504
|
+
* 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. SvelteKit solves this problem by falling back to traditional full-page navigation if it detects that a new version has been deployed, using the `name` specified here (which defaults to a timestamp of the build).
|
|
505
|
+
*
|
|
506
|
+
* 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.
|
|
507
|
+
*/
|
|
225
508
|
version?: {
|
|
509
|
+
/**
|
|
510
|
+
* The current app version string.
|
|
511
|
+
* @default Date.now().toString()
|
|
512
|
+
*/
|
|
226
513
|
name?: string;
|
|
514
|
+
/**
|
|
515
|
+
* The interval in milliseconds to poll for version changes. If this is `0`, no polling occurs.
|
|
516
|
+
* @default 0
|
|
517
|
+
*/
|
|
227
518
|
pollInterval?: number;
|
|
228
519
|
};
|
|
229
520
|
}
|
|
230
521
|
|
|
231
522
|
/**
|
|
232
|
-
*
|
|
523
|
+
* 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
|
|
233
524
|
* determines the [response](https://kit.svelte.dev/docs/web-standards#fetch-apis-response).
|
|
234
525
|
* It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
|
|
235
526
|
* This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
|
|
@@ -242,6 +533,8 @@ export interface Handle {
|
|
|
242
533
|
}
|
|
243
534
|
|
|
244
535
|
/**
|
|
536
|
+
* 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.
|
|
537
|
+
*
|
|
245
538
|
* If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
|
|
246
539
|
* Make sure that this function _never_ throws an error.
|
|
247
540
|
*/
|
|
@@ -250,6 +543,8 @@ export interface HandleServerError {
|
|
|
250
543
|
}
|
|
251
544
|
|
|
252
545
|
/**
|
|
546
|
+
* The client-side [`handleError`](https://kit.svelte.dev/docs/hooks#shared-hooks-handleerror) hook runs when an unexpected error is thrown while navigating.
|
|
547
|
+
*
|
|
253
548
|
* If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
|
|
254
549
|
* Make sure that this function _never_ throws an error.
|
|
255
550
|
*/
|
|
@@ -257,6 +552,9 @@ export interface HandleClientError {
|
|
|
257
552
|
(input: { error: unknown; event: NavigationEvent }): MaybePromise<void | App.Error>;
|
|
258
553
|
}
|
|
259
554
|
|
|
555
|
+
/**
|
|
556
|
+
* 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)
|
|
557
|
+
*/
|
|
260
558
|
export interface HandleFetch {
|
|
261
559
|
(input: { event: RequestEvent; request: Request; fetch: typeof fetch }): MaybePromise<Response>;
|
|
262
560
|
}
|
|
@@ -275,6 +573,10 @@ export interface Load<
|
|
|
275
573
|
(event: LoadEvent<Params, InputData, ParentData, RouteId>): MaybePromise<OutputData>;
|
|
276
574
|
}
|
|
277
575
|
|
|
576
|
+
/**
|
|
577
|
+
* The generic form of `PageLoadEvent` and `LayoutLoadEvent`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types))
|
|
578
|
+
* rather than using `LoadEvent` directly.
|
|
579
|
+
*/
|
|
278
580
|
export interface LoadEvent<
|
|
279
581
|
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
280
582
|
Data extends Record<string, unknown> | null = Record<string, any> | null,
|
|
@@ -317,7 +619,7 @@ export interface LoadEvent<
|
|
|
317
619
|
*
|
|
318
620
|
* Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
|
|
319
621
|
*
|
|
320
|
-
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#
|
|
622
|
+
* 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.
|
|
321
623
|
*
|
|
322
624
|
* `setHeaders` has no effect when a `load` function runs in the browser.
|
|
323
625
|
*/
|
|
@@ -374,7 +676,7 @@ export interface NavigationEvent<
|
|
|
374
676
|
RouteId extends string | null = string | null
|
|
375
677
|
> {
|
|
376
678
|
/**
|
|
377
|
-
* The parameters of the current page - e.g. for a route like `/blog/[slug]`,
|
|
679
|
+
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
378
680
|
*/
|
|
379
681
|
params: Params;
|
|
380
682
|
/**
|
|
@@ -392,9 +694,22 @@ export interface NavigationEvent<
|
|
|
392
694
|
url: URL;
|
|
393
695
|
}
|
|
394
696
|
|
|
697
|
+
/**
|
|
698
|
+
* Information about the target of a specific navigation.
|
|
699
|
+
*/
|
|
395
700
|
export interface NavigationTarget {
|
|
701
|
+
/**
|
|
702
|
+
* Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
703
|
+
* Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
|
|
704
|
+
*/
|
|
396
705
|
params: Record<string, string> | null;
|
|
706
|
+
/**
|
|
707
|
+
* Info about the target route
|
|
708
|
+
*/
|
|
397
709
|
route: { id: string | null };
|
|
710
|
+
/**
|
|
711
|
+
* The URL that is navigated to
|
|
712
|
+
*/
|
|
398
713
|
url: URL;
|
|
399
714
|
}
|
|
400
715
|
|
|
@@ -435,7 +750,7 @@ export interface Navigation {
|
|
|
435
750
|
}
|
|
436
751
|
|
|
437
752
|
/**
|
|
438
|
-
* The
|
|
753
|
+
* The argument passed to [`beforeNavigate`](https://kit.svelte.dev/docs/modules#$app-navigation-beforenavigate) callbacks.
|
|
439
754
|
*/
|
|
440
755
|
export interface BeforeNavigate extends Navigation {
|
|
441
756
|
/**
|
|
@@ -445,7 +760,7 @@ export interface BeforeNavigate extends Navigation {
|
|
|
445
760
|
}
|
|
446
761
|
|
|
447
762
|
/**
|
|
448
|
-
* The
|
|
763
|
+
* The argument passed to [`afterNavigate`](https://kit.svelte.dev/docs/modules#$app-navigation-afternavigate) callbacks.
|
|
449
764
|
*/
|
|
450
765
|
export interface AfterNavigate extends Navigation {
|
|
451
766
|
/**
|
|
@@ -456,6 +771,9 @@ export interface AfterNavigate extends Navigation {
|
|
|
456
771
|
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
457
772
|
*/
|
|
458
773
|
type: Omit<NavigationType, 'leave'>;
|
|
774
|
+
/**
|
|
775
|
+
* Since `afterNavigate` is called after a navigation completes, it will never be called with a navigation that unloads the page.
|
|
776
|
+
*/
|
|
459
777
|
willUnload: false;
|
|
460
778
|
}
|
|
461
779
|
|
|
@@ -471,7 +789,7 @@ export interface Page<
|
|
|
471
789
|
*/
|
|
472
790
|
url: URL;
|
|
473
791
|
/**
|
|
474
|
-
* The parameters of the current page - e.g. for a route like `/blog/[slug]`,
|
|
792
|
+
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
475
793
|
*/
|
|
476
794
|
params: Params;
|
|
477
795
|
/**
|
|
@@ -501,6 +819,9 @@ export interface Page<
|
|
|
501
819
|
form: any;
|
|
502
820
|
}
|
|
503
821
|
|
|
822
|
+
/**
|
|
823
|
+
* The shape of a param matcher. See [matching](https://kit.svelte.dev/docs/advanced-routing#matching) for more info.
|
|
824
|
+
*/
|
|
504
825
|
export interface ParamMatcher {
|
|
505
826
|
(param: string): boolean;
|
|
506
827
|
}
|
|
@@ -532,7 +853,7 @@ export interface RequestEvent<
|
|
|
532
853
|
*/
|
|
533
854
|
locals: App.Locals;
|
|
534
855
|
/**
|
|
535
|
-
* The parameters of the current page or endpoint - e.g. for a route like `/blog/[slug]`,
|
|
856
|
+
* The parameters of the current page or endpoint - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
|
|
536
857
|
*/
|
|
537
858
|
params: Params;
|
|
538
859
|
/**
|
|
@@ -572,7 +893,7 @@ export interface RequestEvent<
|
|
|
572
893
|
*
|
|
573
894
|
* Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
|
|
574
895
|
*
|
|
575
|
-
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#
|
|
896
|
+
* You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://kit.svelte.dev/docs/types#public-types-cookies) API instead.
|
|
576
897
|
*/
|
|
577
898
|
setHeaders(headers: Record<string, string>): void;
|
|
578
899
|
/**
|
|
@@ -710,6 +1031,10 @@ export interface ServerLoadEvent<
|
|
|
710
1031
|
depends(...deps: string[]): void;
|
|
711
1032
|
}
|
|
712
1033
|
|
|
1034
|
+
/**
|
|
1035
|
+
* Shape of a form action method that is part of `export const actions = {..}` in `+page.server.js`.
|
|
1036
|
+
* See [form actions](https://kit-svelte-d4b3r0pff-svelte.vercel.app/docs/form-actions) for more information.
|
|
1037
|
+
*/
|
|
713
1038
|
export interface Action<
|
|
714
1039
|
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
715
1040
|
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
@@ -718,6 +1043,10 @@ export interface Action<
|
|
|
718
1043
|
(event: RequestEvent<Params, RouteId>): MaybePromise<OutputData>;
|
|
719
1044
|
}
|
|
720
1045
|
|
|
1046
|
+
/**
|
|
1047
|
+
* Shape of the `export const actions = {..}` object in `+page.server.js`.
|
|
1048
|
+
* See [form actions](https://kit-svelte-d4b3r0pff-svelte.vercel.app/docs/form-actions) for more information.
|
|
1049
|
+
*/
|
|
721
1050
|
export type Actions<
|
|
722
1051
|
Params extends Partial<Record<string, string>> = Partial<Record<string, string>>,
|
|
723
1052
|
OutputData extends Record<string, any> | void = Record<string, any> | void,
|
|
@@ -751,17 +1080,17 @@ export function error(
|
|
|
751
1080
|
): HttpError;
|
|
752
1081
|
|
|
753
1082
|
/**
|
|
754
|
-
* The object returned by the `error` function
|
|
1083
|
+
* The object returned by the [`error`](https://kit.svelte.dev/docs/modules#sveltejs-kit-error) function.
|
|
755
1084
|
*/
|
|
756
1085
|
export interface HttpError {
|
|
757
|
-
/** The HTTP status code */
|
|
1086
|
+
/** The [HTTP status code](https://httpstatusdogs.com), in the range 400-599 */
|
|
758
1087
|
status: number;
|
|
759
|
-
/** The error
|
|
1088
|
+
/** The content of the error. */
|
|
760
1089
|
body: App.Error;
|
|
761
1090
|
}
|
|
762
1091
|
|
|
763
1092
|
/**
|
|
764
|
-
*
|
|
1093
|
+
* Create a `Redirect` object. If thrown during request handling, SvelteKit will
|
|
765
1094
|
* return a redirect response.
|
|
766
1095
|
*/
|
|
767
1096
|
export function redirect(
|
|
@@ -770,22 +1099,24 @@ export function redirect(
|
|
|
770
1099
|
): Redirect;
|
|
771
1100
|
|
|
772
1101
|
/**
|
|
773
|
-
* The object returned by the `redirect` function
|
|
1102
|
+
* The object returned by the [`redirect`](https://kit.svelte.dev/docs/modules#sveltejs-kit-redirect) function
|
|
774
1103
|
*/
|
|
775
1104
|
export interface Redirect {
|
|
776
|
-
/** The HTTP status code */
|
|
1105
|
+
/** The [HTTP status code](https://httpstatusdogs.com), in the range 300-308. */
|
|
777
1106
|
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
778
|
-
/** The location to redirect to */
|
|
1107
|
+
/** The location to redirect to. */
|
|
779
1108
|
location: string;
|
|
780
1109
|
}
|
|
781
1110
|
|
|
782
1111
|
/**
|
|
783
|
-
*
|
|
1112
|
+
* Create a JSON `Response` object from the supplied data.
|
|
1113
|
+
* @param data The value that will be serialized as JSON.
|
|
1114
|
+
* @param init Options such as `status` and `headers` that will be added to the response. A `Content-Type: application/json` header will be added automatically.
|
|
784
1115
|
*/
|
|
785
1116
|
export function json(data: any, init?: ResponseInit): Response;
|
|
786
1117
|
|
|
787
1118
|
/**
|
|
788
|
-
*
|
|
1119
|
+
* Create a `ValidationError` object.
|
|
789
1120
|
*/
|
|
790
1121
|
export function invalid<T extends Record<string, unknown> | undefined>(
|
|
791
1122
|
status: number,
|
|
@@ -793,10 +1124,35 @@ export function invalid<T extends Record<string, unknown> | undefined>(
|
|
|
793
1124
|
): ValidationError<T>;
|
|
794
1125
|
|
|
795
1126
|
/**
|
|
796
|
-
* The object returned by the `invalid` function
|
|
1127
|
+
* The object returned by the [`invalid`](https://kit.svelte.dev/docs/modules#sveltejs-kit-invalid) function
|
|
797
1128
|
*/
|
|
798
1129
|
export interface ValidationError<T extends Record<string, unknown> | undefined = undefined>
|
|
799
1130
|
extends UniqueInterface {
|
|
800
1131
|
status: number;
|
|
801
1132
|
data: T;
|
|
802
1133
|
}
|
|
1134
|
+
|
|
1135
|
+
export interface SubmitFunction<
|
|
1136
|
+
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
1137
|
+
Invalid extends Record<string, unknown> | undefined = Record<string, any>
|
|
1138
|
+
> {
|
|
1139
|
+
(input: {
|
|
1140
|
+
action: URL;
|
|
1141
|
+
data: FormData;
|
|
1142
|
+
form: HTMLFormElement;
|
|
1143
|
+
controller: AbortController;
|
|
1144
|
+
cancel(): void;
|
|
1145
|
+
}): MaybePromise<
|
|
1146
|
+
| void
|
|
1147
|
+
| ((opts: {
|
|
1148
|
+
form: HTMLFormElement;
|
|
1149
|
+
action: URL;
|
|
1150
|
+
result: ActionResult<Success, Invalid>;
|
|
1151
|
+
/**
|
|
1152
|
+
* Call this to get the default behavior of a form submission response.
|
|
1153
|
+
* @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission.
|
|
1154
|
+
*/
|
|
1155
|
+
update(options?: { reset: boolean }): Promise<void>;
|
|
1156
|
+
}) => void)
|
|
1157
|
+
>;
|
|
1158
|
+
}
|
package/types/private.d.ts
CHANGED
|
@@ -152,6 +152,9 @@ export interface Logger {
|
|
|
152
152
|
export type MaybePromise<T> = T | Promise<T>;
|
|
153
153
|
|
|
154
154
|
export interface Prerendered {
|
|
155
|
+
/**
|
|
156
|
+
* 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`.
|
|
157
|
+
*/
|
|
155
158
|
pages: Map<
|
|
156
159
|
string,
|
|
157
160
|
{
|
|
@@ -159,6 +162,9 @@ export interface Prerendered {
|
|
|
159
162
|
file: string;
|
|
160
163
|
}
|
|
161
164
|
>;
|
|
165
|
+
/**
|
|
166
|
+
* A map of `path` to `{ type }` objects.
|
|
167
|
+
*/
|
|
162
168
|
assets: Map<
|
|
163
169
|
string,
|
|
164
170
|
{
|
|
@@ -166,6 +172,9 @@ export interface Prerendered {
|
|
|
166
172
|
type: string;
|
|
167
173
|
}
|
|
168
174
|
>;
|
|
175
|
+
/**
|
|
176
|
+
* A map of redirects encountered during prerendering.
|
|
177
|
+
*/
|
|
169
178
|
redirects: Map<
|
|
170
179
|
string,
|
|
171
180
|
{
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
This module provides access to runtime environment variables, as defined by the platform you're running on. For example if you're using [`adapter-node`](https://github.com/sveltejs/kit/tree/master/packages/adapter-node) (or running [`vite preview`](https://kit.svelte.dev/docs/cli)), this is equivalent to `process.env`. This module only includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env).
|
|
2
|
-
|
|
3
|
-
This module cannot be imported into client-side code.
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
import { env } from '$env/dynamic/private';
|
|
7
|
-
console.log(env.DEPLOYMENT_SPECIFIC_VARIABLE);
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
> In `dev`, `$env/dynamic` always includes environment variables from `.env`. In `prod`, this behavior will depend on your adapter.
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Similar to [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), but only includes variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env) (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code.
|
|
2
|
-
|
|
3
|
-
Note that public dynamic environment variables must all be sent from the server to the client, causing larger network requests — when possible, use `$env/static/public` instead.
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
import { env } from '$env/dynamic/public';
|
|
7
|
-
console.log(env.PUBLIC_DEPLOYMENT_SPECIFIC_VARIABLE);
|
|
8
|
-
```
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Environment variables [loaded by Vite](https://vitejs.dev/guide/env-and-mode.html#env-files) from `.env` files and `process.env`. Like [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), this module cannot be imported into client-side code. This module only includes variables that _do not_ begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env).
|
|
2
|
-
|
|
3
|
-
_Unlike_ [`$env/dynamic/private`](https://kit.svelte.dev/docs/modules#$env-dynamic-private), the values exported from this module are statically injected into your bundle at build time, enabling optimisations like dead code elimination.
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
import { API_KEY } from '$env/static/private';
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
Note that all environment variables referenced in your code should be declared (for example in an `.env` file), even if they don't have a value until the app is deployed:
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
MY_FEATURE_FLAG=""
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
You can override `.env` values from the command line like so:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
MY_FEATURE_FLAG="enabled" npm run dev
|
|
19
|
-
```
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Similar to [`$env/static/private`](https://kit.svelte.dev/docs/modules#$env-static-private), except that it only includes environment variables that begin with [`config.kit.env.publicPrefix`](https://kit.svelte.dev/docs/configuration#env) (which defaults to `PUBLIC_`), and can therefore safely be exposed to client-side code.
|
|
2
|
-
|
|
3
|
-
Values are replaced statically at build time.
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
import { PUBLIC_BASE_URL } from '$env/static/public';
|
|
7
|
-
```
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
This is a simple alias to `src/lib`, or whatever directory is specified as [`config.kit.files.lib`](https://kit.svelte.dev/docs/configuration#files). It allows you to access common components and utility modules without `../../../../` nonsense.
|
|
2
|
-
|
|
3
|
-
#### `$lib/server`
|
|
4
|
-
|
|
5
|
-
A subdirectory of `$lib`. SvelteKit will prevent you from importing any modules in `$lib/server` into client-side code. See [server-only modules](/docs/server-only-modules).
|