@sveltejs/kit 3.0.0-next.1 → 3.0.0-next.11
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 +33 -21
- package/src/constants.js +2 -0
- package/src/core/adapt/builder.js +32 -49
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +137 -71
- package/src/core/config/options.js +236 -244
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +121 -5
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/postbuild/analyse.js +7 -19
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/fallback.js +2 -1
- package/src/core/postbuild/prerender.js +114 -48
- package/src/core/postbuild/queue.js +2 -1
- package/src/core/sync/create_manifest_data/index.js +53 -50
- package/src/core/sync/sync.js +0 -2
- package/src/core/sync/write_client_manifest.js +8 -15
- package/src/core/sync/write_env.js +2 -1
- package/src/core/sync/write_non_ambient.js +12 -9
- package/src/core/sync/write_server.js +14 -15
- package/src/core/sync/write_tsconfig.js +16 -8
- package/src/core/sync/write_tsconfig_test/package.json +7 -0
- package/src/core/sync/write_types/index.js +28 -24
- package/src/core/utils.js +30 -5
- package/src/exports/env/index.js +77 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/sequence.js +3 -2
- package/src/exports/index.js +35 -13
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +8 -5
- package/src/exports/internal/index.js +1 -90
- package/src/exports/internal/{event.js → server/event.js} +1 -2
- package/src/exports/internal/server/index.js +33 -0
- package/src/exports/internal/shared.js +89 -0
- package/src/exports/node/index.js +62 -15
- package/src/exports/params.js +68 -0
- package/src/exports/public.d.ts +363 -189
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +53 -59
- package/src/exports/vite/build/remote.js +18 -11
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +92 -50
- package/src/exports/vite/index.js +903 -681
- package/src/exports/vite/module_ids.js +0 -2
- package/src/exports/vite/preview/index.js +32 -24
- package/src/exports/vite/static_analysis/index.js +2 -4
- package/src/exports/vite/static_analysis/types.d.ts +14 -0
- package/src/exports/vite/utils.js +40 -35
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/forms.js +24 -7
- package/src/runtime/app/paths/client.js +4 -10
- package/src/runtime/app/paths/internal/client.js +4 -2
- package/src/runtime/app/paths/internal/server.js +2 -23
- package/src/runtime/app/paths/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +10 -6
- package/src/runtime/app/server/index.js +1 -1
- package/src/runtime/app/server/remote/command.js +0 -3
- package/src/runtime/app/server/remote/form.js +27 -15
- package/src/runtime/app/server/remote/prerender.js +29 -36
- package/src/runtime/app/server/remote/query.js +101 -99
- package/src/runtime/app/server/remote/requested.js +22 -14
- package/src/runtime/app/server/remote/shared.js +30 -26
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +411 -318
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/ndjson.js +6 -33
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/command.svelte.js +7 -32
- package/src/runtime/client/remote-functions/form.svelte.js +183 -112
- package/src/runtime/client/remote-functions/prerender.svelte.js +29 -8
- package/src/runtime/client/remote-functions/query/index.js +7 -14
- package/src/runtime/client/remote-functions/query/instance.svelte.js +63 -18
- package/src/runtime/client/remote-functions/query/proxy.js +3 -3
- package/src/runtime/client/remote-functions/query-batch.svelte.js +60 -68
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +60 -18
- package/src/runtime/client/remote-functions/query-live/iterator.js +36 -55
- package/src/runtime/client/remote-functions/shared.svelte.js +88 -62
- package/src/runtime/client/sse.js +32 -0
- package/src/runtime/client/state.svelte.js +65 -49
- package/src/runtime/client/stream.js +39 -0
- package/src/runtime/client/types.d.ts +11 -7
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/components/root.svelte +66 -0
- package/src/runtime/env/dynamic/private.js +7 -0
- package/src/runtime/env/dynamic/public.js +7 -0
- package/src/runtime/env/static/private.js +6 -0
- package/src/runtime/env/static/public.js +6 -0
- package/src/runtime/form-utils.js +100 -22
- package/src/runtime/server/cookie.js +69 -52
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +15 -19
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +135 -0
- package/src/runtime/server/fetch.js +1 -1
- package/src/runtime/server/index.js +22 -12
- package/src/runtime/server/internal.js +25 -0
- package/src/runtime/server/page/actions.js +43 -27
- package/src/runtime/server/page/data_serializer.js +10 -10
- package/src/runtime/server/page/index.js +12 -17
- package/src/runtime/server/page/load_data.js +2 -2
- package/src/runtime/server/page/render.js +114 -193
- package/src/runtime/server/page/respond_with_error.js +11 -11
- package/src/runtime/server/page/server_routing.js +27 -18
- package/src/runtime/server/remote-functions.js +596 -0
- package/src/runtime/server/respond.js +100 -68
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/utils.js +2 -134
- package/src/runtime/shared.js +83 -13
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/runtime/types.d.ts +8 -0
- package/src/types/ambient-private.d.ts +2 -0
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +13 -25
- package/src/types/internal.d.ts +95 -80
- package/src/types/private.d.ts +41 -1
- package/src/utils/error.js +24 -4
- package/src/utils/escape.js +9 -25
- package/src/utils/features.js +1 -1
- package/src/utils/fork.js +7 -2
- package/src/utils/import.js +6 -1
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/page_nodes.js +3 -5
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +90 -44
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +20 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +537 -557
- package/types/index.d.ts.map +24 -39
- package/src/core/sync/write_root.js +0 -148
- package/src/exports/internal/server.js +0 -22
- package/src/runtime/server/remote.js +0 -457
- package/src/runtime/shared-server.js +0 -7
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
package/src/exports/public.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
Prerendered,
|
|
12
12
|
PrerenderEntryGeneratorMismatchHandlerValue,
|
|
13
13
|
PrerenderHttpErrorHandlerValue,
|
|
14
|
+
PrerenderInvalidUrlHandlerValue,
|
|
14
15
|
PrerenderMissingIdHandlerValue,
|
|
15
16
|
PrerenderUnseenRoutesHandlerValue,
|
|
16
17
|
PrerenderOption,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
import { BuildData, SSRNodeLoader, SSRRoute, ValidatedConfig } from 'types';
|
|
23
24
|
import { SvelteConfig } from '@sveltejs/vite-plugin-svelte';
|
|
24
25
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
26
|
+
import { Plugin } from 'vite';
|
|
25
27
|
import {
|
|
26
28
|
RouteId as AppRouteId,
|
|
27
29
|
LayoutParams as AppLayoutParams,
|
|
@@ -33,6 +35,8 @@ export { PrerenderOption } from '../types/private.js';
|
|
|
33
35
|
// @ts-ignore this is an optional peer dependency so could be missing. Written like this so dts-buddy preserves the ts-ignore
|
|
34
36
|
type Span = import('@opentelemetry/api').Span;
|
|
35
37
|
|
|
38
|
+
type AppErrorWithOptionalStatus = Omit<App.Error, 'status'> & { status?: App.Error['status'] };
|
|
39
|
+
|
|
36
40
|
/**
|
|
37
41
|
* [Adapters](https://svelte.dev/docs/kit/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing.
|
|
38
42
|
*/
|
|
@@ -54,7 +58,7 @@ export interface Adapter {
|
|
|
54
58
|
* Test support for `read` from `$app/server`.
|
|
55
59
|
* @param details.config The merged adapter-specific route config exported from the route with `export const config`
|
|
56
60
|
*/
|
|
57
|
-
read?: (details: { config: any
|
|
61
|
+
read?: (details: { config: Record<string, any>; route: { id: string } }) => boolean;
|
|
58
62
|
|
|
59
63
|
/**
|
|
60
64
|
* Test support for `instrumentation.server.js`. To pass, the adapter must support running `instrumentation.server.js` prior to the application code.
|
|
@@ -67,6 +71,13 @@ export interface Adapter {
|
|
|
67
71
|
* during dev, build and prerendering.
|
|
68
72
|
*/
|
|
69
73
|
emulate?: () => MaybePromise<Emulator>;
|
|
74
|
+
vite?: {
|
|
75
|
+
/**
|
|
76
|
+
* Plugins provided by the adapter are placed before any of SvelteKit's own plugins.
|
|
77
|
+
* @since 3.0.0
|
|
78
|
+
*/
|
|
79
|
+
plugins?: Plugin[];
|
|
80
|
+
};
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
export type LoadProperties<input extends Record<string, any> | void> = input extends void
|
|
@@ -115,7 +126,7 @@ export interface Builder {
|
|
|
115
126
|
/** Create `dir` and any required parent directories. */
|
|
116
127
|
mkdirp: (dir: string) => void;
|
|
117
128
|
|
|
118
|
-
/** The fully resolved
|
|
129
|
+
/** The fully resolved SvelteKit config. */
|
|
119
130
|
config: ValidatedConfig;
|
|
120
131
|
/** Information about prerendered pages and assets, if any. */
|
|
121
132
|
prerendered: Prerendered;
|
|
@@ -146,7 +157,8 @@ export interface Builder {
|
|
|
146
157
|
|
|
147
158
|
/**
|
|
148
159
|
* Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
|
|
149
|
-
* @param opts
|
|
160
|
+
* @param opts
|
|
161
|
+
* @param opts.relativePath A relative path to the base directory of the server build output
|
|
150
162
|
*/
|
|
151
163
|
generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;
|
|
152
164
|
|
|
@@ -263,13 +275,13 @@ export interface Cookies {
|
|
|
263
275
|
/**
|
|
264
276
|
* Gets a cookie that was previously set with `cookies.set`, or from the request headers.
|
|
265
277
|
* @param name the name of the cookie
|
|
266
|
-
* @param opts the options, passed directly to `cookie.
|
|
278
|
+
* @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
|
|
267
279
|
*/
|
|
268
280
|
get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined;
|
|
269
281
|
|
|
270
282
|
/**
|
|
271
283
|
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
|
|
272
|
-
* @param opts the options, passed directly to `cookie.
|
|
284
|
+
* @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
|
|
273
285
|
*/
|
|
274
286
|
getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
|
|
275
287
|
|
|
@@ -281,7 +293,7 @@ export interface Cookies {
|
|
|
281
293
|
* The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
|
|
282
294
|
* @param name the name of the cookie
|
|
283
295
|
* @param value the cookie value
|
|
284
|
-
* @param opts the options passed to `cookie.
|
|
296
|
+
* @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
|
|
285
297
|
*/
|
|
286
298
|
set: (name: string, value: string, opts: import('cookie').SerializeOptions) => void;
|
|
287
299
|
|
|
@@ -292,10 +304,34 @@ export interface Cookies {
|
|
|
292
304
|
*
|
|
293
305
|
* The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
|
|
294
306
|
* @param name the name of the cookie
|
|
295
|
-
* @param opts the options passed to `cookie.
|
|
307
|
+
* @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
|
|
296
308
|
*/
|
|
297
309
|
delete: (name: string, opts: import('cookie').SerializeOptions) => void;
|
|
298
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Parses a single `Set-Cookie` header. This allows you to apply cookies received from an external source:
|
|
313
|
+
*
|
|
314
|
+
* ```js
|
|
315
|
+
* import { getRequestEvent } from '$app/server';
|
|
316
|
+
*
|
|
317
|
+
* export async function GET() {
|
|
318
|
+
* const { cookies } = getRequestEvent();
|
|
319
|
+
*
|
|
320
|
+
* const response = await fetch('...');
|
|
321
|
+
*
|
|
322
|
+
* for (const str of response.headers.getSetCookie()) {
|
|
323
|
+
* const { name, value, ...options } = cookies.parse(str);
|
|
324
|
+
* cookies.set(name, value, { ...options, path: '/' });
|
|
325
|
+
* }
|
|
326
|
+
*
|
|
327
|
+
* // ...
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* Note the use of `headers.getSetCookie()`, which returns an array of cookie headers, _not_ `headers.get('set-cookie')` which returns a single comma-separated string.
|
|
332
|
+
*/
|
|
333
|
+
parse: typeof import('cookie').parseSetCookie;
|
|
334
|
+
|
|
299
335
|
/**
|
|
300
336
|
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
|
|
301
337
|
*
|
|
@@ -304,7 +340,7 @@ export interface Cookies {
|
|
|
304
340
|
* The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
|
|
305
341
|
* @param name the name of the cookie
|
|
306
342
|
* @param value the cookie value
|
|
307
|
-
* @param opts the options passed to `cookie.
|
|
343
|
+
* @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
|
|
308
344
|
*/
|
|
309
345
|
serialize: (name: string, value: string, opts: import('cookie').SerializeOptions) => string;
|
|
310
346
|
}
|
|
@@ -321,35 +357,37 @@ export interface Emulator {
|
|
|
321
357
|
}
|
|
322
358
|
|
|
323
359
|
export interface KitConfig {
|
|
324
|
-
// TODO: remove this in 4.0
|
|
325
360
|
/**
|
|
326
361
|
* Your [adapter](https://svelte.dev/docs/kit/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms.
|
|
327
362
|
* @default undefined
|
|
328
|
-
* @deprecated removed in 3.0.0. Adapters should now be passed to the `sveltekit` Vite plugin in `vite.config.js`
|
|
329
363
|
*/
|
|
330
364
|
adapter?: Adapter;
|
|
331
365
|
/**
|
|
332
366
|
* An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
|
|
333
367
|
*
|
|
334
368
|
* ```js
|
|
335
|
-
* /// file:
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
369
|
+
* /// file: vite.config.js
|
|
370
|
+
* import { defineConfig } from 'vite';
|
|
371
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
372
|
+
*
|
|
373
|
+
* export default defineConfig({
|
|
374
|
+
* plugins: [
|
|
375
|
+
* sveltekit({
|
|
376
|
+
* alias: {
|
|
377
|
+
* // this will match a file
|
|
378
|
+
* 'my-file': 'path/to/my-file.js',
|
|
379
|
+
*
|
|
380
|
+
* // this will match a directory and its contents
|
|
381
|
+
* // (`my-directory/x` resolves to `path/to/my-directory/x`)
|
|
382
|
+
* 'my-directory': 'path/to/my-directory',
|
|
383
|
+
*
|
|
384
|
+
* // an alias ending /* will only match
|
|
385
|
+
* // the contents of a directory, not the directory itself
|
|
386
|
+
* 'my-directory/*': 'path/to/my-directory/*'
|
|
387
|
+
* }
|
|
388
|
+
* })
|
|
389
|
+
* ]
|
|
390
|
+
* });
|
|
353
391
|
* ```
|
|
354
392
|
*
|
|
355
393
|
* > [!NOTE] You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
|
|
@@ -367,24 +405,26 @@ export interface KitConfig {
|
|
|
367
405
|
* [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...
|
|
368
406
|
*
|
|
369
407
|
* ```js
|
|
370
|
-
* /// file:
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
408
|
+
* /// file: vite.config.js
|
|
409
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
410
|
+
* import { defineConfig } from 'vite';
|
|
411
|
+
*
|
|
412
|
+
* export default defineConfig({
|
|
413
|
+
* plugins: [
|
|
414
|
+
* sveltekit({
|
|
415
|
+
* csp: {
|
|
416
|
+
* directives: {
|
|
417
|
+
* 'script-src': ['self']
|
|
418
|
+
* },
|
|
419
|
+
* // must be specified with either the `report-uri` or `report-to` directives, or both
|
|
420
|
+
* reportOnly: {
|
|
421
|
+
* 'script-src': ['self'],
|
|
422
|
+
* 'report-uri': ['/']
|
|
423
|
+
* }
|
|
424
|
+
* }
|
|
425
|
+
* })
|
|
426
|
+
* ]
|
|
427
|
+
* });
|
|
388
428
|
* ```
|
|
389
429
|
*
|
|
390
430
|
* ...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.
|
|
@@ -395,9 +435,7 @@ export interface KitConfig {
|
|
|
395
435
|
*
|
|
396
436
|
* > [!NOTE] 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.
|
|
397
437
|
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle) to roll your own CSP.
|
|
438
|
+
* If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://svelte.dev/docs/kit/hooks#handle) to roll your own CSP.
|
|
401
439
|
*/
|
|
402
440
|
csp?: {
|
|
403
441
|
/**
|
|
@@ -459,32 +497,6 @@ export interface KitConfig {
|
|
|
459
497
|
};
|
|
460
498
|
/** Experimental features. Here be dragons. These are not subject to semantic versioning, so breaking changes or removal can happen in any release. */
|
|
461
499
|
experimental?: {
|
|
462
|
-
/**
|
|
463
|
-
* Options for enabling server-side [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations including the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle), [`load` functions](https://svelte.dev/docs/kit/load), [form actions](https://svelte.dev/docs/kit/form-actions), and [remote functions](https://svelte.dev/docs/kit/remote-functions).
|
|
464
|
-
* @default { server: false, serverFile: false }
|
|
465
|
-
* @since 2.31.0
|
|
466
|
-
*/
|
|
467
|
-
tracing?: {
|
|
468
|
-
/**
|
|
469
|
-
* Enables server-side [OpenTelemetry](https://opentelemetry.io/) span emission for SvelteKit operations including the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle), [`load` functions](https://svelte.dev/docs/kit/load), [form actions](https://svelte.dev/docs/kit/form-actions), and [remote functions](https://svelte.dev/docs/kit/remote-functions).
|
|
470
|
-
* @default false
|
|
471
|
-
* @since 2.31.0
|
|
472
|
-
*/
|
|
473
|
-
server?: boolean;
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* @since 2.31.0
|
|
478
|
-
*/
|
|
479
|
-
instrumentation?: {
|
|
480
|
-
/**
|
|
481
|
-
* Enables `instrumentation.server.js` for tracing and observability instrumentation.
|
|
482
|
-
* @default false
|
|
483
|
-
* @since 2.31.0
|
|
484
|
-
*/
|
|
485
|
-
server?: boolean;
|
|
486
|
-
};
|
|
487
|
-
|
|
488
500
|
/**
|
|
489
501
|
* Whether to enable the experimental remote functions feature. This feature is not yet stable and may be changed or removed at any time.
|
|
490
502
|
* @default false
|
|
@@ -496,15 +508,6 @@ export interface KitConfig {
|
|
|
496
508
|
* @default false
|
|
497
509
|
*/
|
|
498
510
|
forkPreloads?: boolean;
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Whether to enable the experimental handling of rendering errors.
|
|
502
|
-
* When enabled, `<svelte:boundary>` is used to wrap components at each level
|
|
503
|
-
* where there's an `+error.svelte`, rendering the error page if the component fails.
|
|
504
|
-
* In addition, error boundaries also work on the server and the error object goes through `handleError`.
|
|
505
|
-
* @default false
|
|
506
|
-
*/
|
|
507
|
-
handleRenderingErrors?: boolean;
|
|
508
511
|
};
|
|
509
512
|
/**
|
|
510
513
|
* Where to find various files within your project.
|
|
@@ -545,12 +548,6 @@ export interface KitConfig {
|
|
|
545
548
|
*/
|
|
546
549
|
universal?: string;
|
|
547
550
|
};
|
|
548
|
-
/**
|
|
549
|
-
* Your app's internal library, accessible throughout the codebase as `$lib`.
|
|
550
|
-
* @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
|
|
551
|
-
* @default "src/lib"
|
|
552
|
-
*/
|
|
553
|
-
lib?: string;
|
|
554
551
|
/**
|
|
555
552
|
* A directory containing [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching).
|
|
556
553
|
* @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
|
|
@@ -590,7 +587,7 @@ export interface KitConfig {
|
|
|
590
587
|
*/
|
|
591
588
|
inlineStyleThreshold?: number;
|
|
592
589
|
/**
|
|
593
|
-
* An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.
|
|
590
|
+
* An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.moduleExtensions` will be ignored by the router.
|
|
594
591
|
* @default [".js", ".ts"]
|
|
595
592
|
*/
|
|
596
593
|
moduleExtensions?: string[];
|
|
@@ -672,14 +669,27 @@ export interface KitConfig {
|
|
|
672
669
|
*/
|
|
673
670
|
assets?: '' | `http://${string}` | `https://${string}`;
|
|
674
671
|
/**
|
|
675
|
-
* 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 [`
|
|
672
|
+
* 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 [`resolve(...)` from `$app/paths`](https://svelte.dev/docs/kit/$app-paths#resolve) for that: `<a href="{resolve('/your-page')}">Link</a>`. If you find yourself writing this often, it may make sense to extract this into a reusable component.
|
|
676
673
|
* @default ""
|
|
677
674
|
*/
|
|
678
675
|
base?: '' | `/${string}`;
|
|
676
|
+
/**
|
|
677
|
+
* The origin of your app, used for CSRF protection and prerendering.
|
|
678
|
+
*
|
|
679
|
+
* By default, this is `undefined`, meaning SvelteKit will derive the origin from `request.url` (which is set by the adapter, and ultimately by the platform).
|
|
680
|
+
*
|
|
681
|
+
* If your app is served from an origin that isn't known at request time — for example because it's deployed to a preview deployment whose URL isn't known at build time, or because it's behind a reverse proxy that doesn't pass the `host` header — you can set this to a string like `https://my-site.com`.
|
|
682
|
+
*
|
|
683
|
+
* This is also used as the value of `url.origin` during prerendering (when unset, it defaults to `http://sveltekit-prerender`), and as the trusted origin for CSRF checks on form submissions and remote function calls.
|
|
684
|
+
*
|
|
685
|
+
* @default undefined
|
|
686
|
+
* @since 3.0
|
|
687
|
+
*/
|
|
688
|
+
origin?: string;
|
|
679
689
|
/**
|
|
680
690
|
* Whether to use relative asset paths.
|
|
681
691
|
*
|
|
682
|
-
* If `true`, `
|
|
692
|
+
* If `true`, paths created with `resolve()` and `asset()` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in more portable HTML.
|
|
683
693
|
* If `false`, `%sveltekit.assets%` and references to build artifacts will always be root-relative paths, unless `paths.assets` is an external URL
|
|
684
694
|
*
|
|
685
695
|
* [Single-page app](https://svelte.dev/docs/kit/single-page-apps) fallback pages will always use absolute paths, regardless of this setting.
|
|
@@ -721,23 +731,27 @@ export interface KitConfig {
|
|
|
721
731
|
* - `(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
|
|
722
732
|
*
|
|
723
733
|
* ```js
|
|
724
|
-
* /// file:
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
* kit: {
|
|
728
|
-
* prerender: {
|
|
729
|
-
* handleHttpError: ({ path, referrer, message }) => {
|
|
730
|
-
* // ignore deliberate link to shiny 404 page
|
|
731
|
-
* if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
|
|
732
|
-
* return;
|
|
733
|
-
* }
|
|
734
|
+
* /// file: vite.config.js
|
|
735
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
736
|
+
* import { defineConfig } from 'vite';
|
|
734
737
|
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
738
|
+
* export default defineConfig({
|
|
739
|
+
* plugins: [
|
|
740
|
+
* sveltekit({
|
|
741
|
+
* prerender: {
|
|
742
|
+
* handleHttpError: ({ path, referrer, message }) => {
|
|
743
|
+
* // ignore deliberate link to shiny 404 page
|
|
744
|
+
* if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
|
|
745
|
+
* return;
|
|
746
|
+
* }
|
|
747
|
+
*
|
|
748
|
+
* // otherwise fail the build
|
|
749
|
+
* throw new Error(message);
|
|
750
|
+
* }
|
|
751
|
+
* }
|
|
752
|
+
* })
|
|
753
|
+
* ]
|
|
754
|
+
* });
|
|
741
755
|
* ```
|
|
742
756
|
*
|
|
743
757
|
* @default "fail"
|
|
@@ -784,10 +798,17 @@ export interface KitConfig {
|
|
|
784
798
|
*/
|
|
785
799
|
handleUnseenRoutes?: PrerenderUnseenRoutesHandlerValue;
|
|
786
800
|
/**
|
|
787
|
-
*
|
|
788
|
-
*
|
|
801
|
+
* How to respond when SvelteKit encounters a URL it cannot parse while crawling prerendered HTML (for example, an AT Protocol URL such as `at://did:plc:...`).
|
|
802
|
+
*
|
|
803
|
+
* - `'fail'` — fail the build
|
|
804
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
805
|
+
* - `'warn'` — continue, but print a warning
|
|
806
|
+
* - `(details) => void` — a custom error handler that takes a `details` object with `href`, `referrer` and `message` properties. If you `throw` from this function, the build will fail
|
|
807
|
+
*
|
|
808
|
+
* @default "fail"
|
|
809
|
+
* @since 2.67.0
|
|
789
810
|
*/
|
|
790
|
-
|
|
811
|
+
handleInvalidUrl?: PrerenderInvalidUrlHandlerValue;
|
|
791
812
|
};
|
|
792
813
|
router?: {
|
|
793
814
|
/**
|
|
@@ -812,8 +833,10 @@ export interface KitConfig {
|
|
|
812
833
|
* This has several advantages:
|
|
813
834
|
* - The client does not need to load the routing manifest upfront, which can lead to faster initial page loads
|
|
814
835
|
* - The list of routes is hidden from public view
|
|
815
|
-
* - The server has an opportunity to intercept each navigation (for example through a
|
|
816
|
-
|
|
836
|
+
* - The server has an opportunity to intercept each navigation (for example through middleware in front of SvelteKit, such as a reverse proxy or your platform's edge functions), enabling (for example) A/B testing opaque to SvelteKit
|
|
837
|
+
*
|
|
838
|
+
* Route resolution requests are answered as soon as the route has been looked up, before the `handle` hook is invoked. To intercept them within SvelteKit itself, use the `reroute` hook, which runs for these requests too.
|
|
839
|
+
*
|
|
817
840
|
* The drawback is that for unvisited paths, resolution will take slightly longer (though this is mitigated by [preloading](https://svelte.dev/docs/kit/link-options#data-sveltekit-preload-data)).
|
|
818
841
|
*
|
|
819
842
|
* > [!NOTE] When using server-side route resolution and prerendering, the resolution is prerendered along with the route itself.
|
|
@@ -849,6 +872,17 @@ export interface KitConfig {
|
|
|
849
872
|
register?: false;
|
|
850
873
|
}
|
|
851
874
|
);
|
|
875
|
+
/**
|
|
876
|
+
* Options for enabling [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations.
|
|
877
|
+
* @default { server: false }
|
|
878
|
+
*/
|
|
879
|
+
tracing?: {
|
|
880
|
+
/**
|
|
881
|
+
* Enables server-side [OpenTelemetry](https://opentelemetry.io/) span emission for SvelteKit operations including the [`handle` hook](https://svelte.dev/docs/kit/hooks#handle), [`load` functions](https://svelte.dev/docs/kit/load), [form actions](https://svelte.dev/docs/kit/form-actions), and [remote functions](https://svelte.dev/docs/kit/remote-functions). Tracing — and more significantly, observability instrumentation — can have a nontrivial overhead, so consider whether you really need it, or if it might be more appropriate to turn it on in development and preview environments only.
|
|
882
|
+
* @default false
|
|
883
|
+
*/
|
|
884
|
+
server?: boolean;
|
|
885
|
+
};
|
|
852
886
|
typescript?: {
|
|
853
887
|
/**
|
|
854
888
|
* A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
|
|
@@ -889,16 +923,20 @@ export interface KitConfig {
|
|
|
889
923
|
* For example, to use the current commit hash, you could do use `git rev-parse HEAD`:
|
|
890
924
|
*
|
|
891
925
|
* ```js
|
|
892
|
-
* /// file:
|
|
926
|
+
* /// file: vite.config.js
|
|
893
927
|
* import * as child_process from 'node:child_process';
|
|
928
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
929
|
+
* import { defineConfig } from 'vite';
|
|
894
930
|
*
|
|
895
|
-
* export default {
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
*
|
|
931
|
+
* export default defineConfig({
|
|
932
|
+
* plugins: [
|
|
933
|
+
* sveltekit({
|
|
934
|
+
* version: {
|
|
935
|
+
* name: child_process.execSync('git rev-parse HEAD').toString().trim()
|
|
936
|
+
* }
|
|
937
|
+
* })
|
|
938
|
+
* ]
|
|
939
|
+
* });
|
|
902
940
|
* ```
|
|
903
941
|
*/
|
|
904
942
|
name?: string;
|
|
@@ -911,52 +949,58 @@ export interface KitConfig {
|
|
|
911
949
|
}
|
|
912
950
|
|
|
913
951
|
/**
|
|
914
|
-
* The [`handle`](https://svelte.dev/docs/kit/hooks#
|
|
952
|
+
* The [`handle`](https://svelte.dev/docs/kit/hooks#handle) hook runs every time the SvelteKit server receives a [request](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Request) and
|
|
915
953
|
* determines the [response](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Response).
|
|
916
954
|
* It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
|
|
917
955
|
* This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
|
|
918
956
|
*/
|
|
919
957
|
export type Handle = (input: {
|
|
920
958
|
event: RequestEvent;
|
|
921
|
-
resolve: (event: RequestEvent, opts?: ResolveOptions) =>
|
|
959
|
+
resolve: (event: RequestEvent, opts?: ResolveOptions) => Promise<Response>;
|
|
922
960
|
}) => MaybePromise<Response>;
|
|
923
961
|
|
|
924
962
|
/**
|
|
925
|
-
* The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#
|
|
963
|
+
* The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs when an unexpected error is thrown while responding to a request.
|
|
926
964
|
*
|
|
927
965
|
* If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
|
|
928
966
|
* Make sure that this function _never_ throws an error.
|
|
967
|
+
*
|
|
968
|
+
* The returned object can include a `status` property to override the HTTP status code used in the response.
|
|
969
|
+
* If omitted, the status defaults to 500.
|
|
929
970
|
*/
|
|
930
971
|
export type HandleServerError = (input: {
|
|
931
972
|
error: unknown;
|
|
932
973
|
event: RequestEvent;
|
|
933
974
|
status: number;
|
|
934
975
|
message: string;
|
|
935
|
-
}) => MaybePromise<void |
|
|
976
|
+
}) => MaybePromise<void | AppErrorWithOptionalStatus>;
|
|
936
977
|
|
|
937
978
|
/**
|
|
938
|
-
* The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#
|
|
979
|
+
* The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#handleValidationError) hook runs when the argument to a remote function fails validation.
|
|
939
980
|
*
|
|
940
981
|
* It will be called with the validation issues and the event, and must return an object shape that matches `App.Error`.
|
|
941
982
|
*/
|
|
942
983
|
export type HandleValidationError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
|
|
943
|
-
(input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<
|
|
984
|
+
(input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<AppErrorWithOptionalStatus>;
|
|
944
985
|
|
|
945
986
|
/**
|
|
946
|
-
* The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#
|
|
987
|
+
* The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs when an unexpected error is thrown while navigating.
|
|
947
988
|
*
|
|
948
989
|
* If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
|
|
949
990
|
* Make sure that this function _never_ throws an error.
|
|
991
|
+
*
|
|
992
|
+
* The returned object can include a `status` property to override the HTTP status code used in the response.
|
|
993
|
+
* If omitted, the status defaults to 500.
|
|
950
994
|
*/
|
|
951
995
|
export type HandleClientError = (input: {
|
|
952
996
|
error: unknown;
|
|
953
997
|
event: NavigationEvent;
|
|
954
998
|
status: number;
|
|
955
999
|
message: string;
|
|
956
|
-
}) => MaybePromise<void |
|
|
1000
|
+
}) => MaybePromise<void | AppErrorWithOptionalStatus>;
|
|
957
1001
|
|
|
958
1002
|
/**
|
|
959
|
-
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#
|
|
1003
|
+
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
|
|
960
1004
|
*/
|
|
961
1005
|
export type HandleFetch = (input: {
|
|
962
1006
|
event: RequestEvent;
|
|
@@ -965,25 +1009,25 @@ export type HandleFetch = (input: {
|
|
|
965
1009
|
}) => MaybePromise<Response>;
|
|
966
1010
|
|
|
967
1011
|
/**
|
|
968
|
-
* The [`init`](https://svelte.dev/docs/kit/hooks#
|
|
1012
|
+
* The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked before the server responds to its first request
|
|
969
1013
|
* @since 2.10.0
|
|
970
1014
|
*/
|
|
971
1015
|
export type ServerInit = () => MaybePromise<void>;
|
|
972
1016
|
|
|
973
1017
|
/**
|
|
974
|
-
* The [`init`](https://svelte.dev/docs/kit/hooks#
|
|
1018
|
+
* The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked once the app starts in the browser
|
|
975
1019
|
* @since 2.10.0
|
|
976
1020
|
*/
|
|
977
1021
|
export type ClientInit = () => MaybePromise<void>;
|
|
978
1022
|
|
|
979
1023
|
/**
|
|
980
|
-
* The [`reroute`](https://svelte.dev/docs/kit/hooks#
|
|
1024
|
+
* The [`reroute`](https://svelte.dev/docs/kit/hooks#reroute) hook allows you to modify the URL before it is used to determine which route to render.
|
|
981
1025
|
* @since 2.3.0
|
|
982
1026
|
*/
|
|
983
1027
|
export type Reroute = (event: { url: URL; fetch: typeof fetch }) => MaybePromise<void | string>;
|
|
984
1028
|
|
|
985
1029
|
/**
|
|
986
|
-
* The [`transport`](https://svelte.dev/docs/kit/hooks#
|
|
1030
|
+
* The [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook allows you to transport custom types across the server/client boundary.
|
|
987
1031
|
*
|
|
988
1032
|
* Each transporter has a pair of `encode` and `decode` functions. On the server, `encode` determines whether a value is an instance of the custom type and, if so, returns a non-falsy encoding of the value which can be an object or an array (or `false` otherwise).
|
|
989
1033
|
*
|
|
@@ -1009,11 +1053,11 @@ export type Reroute = (event: { url: URL; fetch: typeof fetch }) => MaybePromise
|
|
|
1009
1053
|
export type Transport = Record<string, Transporter>;
|
|
1010
1054
|
|
|
1011
1055
|
/**
|
|
1012
|
-
* A member of the [`transport`](https://svelte.dev/docs/kit/hooks#
|
|
1056
|
+
* A member of the [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook.
|
|
1013
1057
|
*/
|
|
1014
1058
|
export interface Transporter<
|
|
1015
1059
|
T = any,
|
|
1016
|
-
U =
|
|
1060
|
+
U = any /* minus falsy values, but we can't properly express that */
|
|
1017
1061
|
> {
|
|
1018
1062
|
encode: (value: T) => false | U;
|
|
1019
1063
|
decode: (data: U) => T;
|
|
@@ -1047,7 +1091,7 @@ export interface LoadEvent<
|
|
|
1047
1091
|
* - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
|
|
1048
1092
|
* - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
|
|
1049
1093
|
* - 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.
|
|
1050
|
-
* - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://svelte.dev/docs/kit/hooks#
|
|
1094
|
+
* - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://svelte.dev/docs/kit/hooks#handle)
|
|
1051
1095
|
* - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
|
|
1052
1096
|
*
|
|
1053
1097
|
* You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies)
|
|
@@ -1222,14 +1266,24 @@ export interface NavigationTarget<
|
|
|
1222
1266
|
/**
|
|
1223
1267
|
* - `enter`: The app has hydrated/started
|
|
1224
1268
|
* - `form`: The user submitted a `<form method="GET">`
|
|
1269
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1225
1270
|
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1226
1271
|
* - `link`: Navigation was triggered by a link click
|
|
1227
|
-
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1228
1272
|
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1229
1273
|
*/
|
|
1230
1274
|
export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
1231
1275
|
|
|
1232
1276
|
export interface NavigationBase {
|
|
1277
|
+
/**
|
|
1278
|
+
* The type of navigation:
|
|
1279
|
+
* - `enter`: The app has hydrated/started
|
|
1280
|
+
* - `form`: The user submitted a `<form method="GET">`
|
|
1281
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1282
|
+
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1283
|
+
* - `link`: Navigation was triggered by a link click
|
|
1284
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1285
|
+
*/
|
|
1286
|
+
type: NavigationType;
|
|
1233
1287
|
/**
|
|
1234
1288
|
* Where navigation was triggered from
|
|
1235
1289
|
*/
|
|
@@ -1249,11 +1303,10 @@ export interface NavigationBase {
|
|
|
1249
1303
|
complete: Promise<void>;
|
|
1250
1304
|
}
|
|
1251
1305
|
|
|
1306
|
+
/**
|
|
1307
|
+
* The navigation that occurs when the app starts/hydrates
|
|
1308
|
+
*/
|
|
1252
1309
|
export interface NavigationEnter extends NavigationBase {
|
|
1253
|
-
/**
|
|
1254
|
-
* The type of navigation:
|
|
1255
|
-
* - `enter`: The app has hydrated/started
|
|
1256
|
-
*/
|
|
1257
1310
|
type: 'enter';
|
|
1258
1311
|
|
|
1259
1312
|
/**
|
|
@@ -1269,27 +1322,24 @@ export interface NavigationEnter extends NavigationBase {
|
|
|
1269
1322
|
|
|
1270
1323
|
export type NavigationExternal = NavigationGoto | NavigationLeave;
|
|
1271
1324
|
|
|
1325
|
+
/**
|
|
1326
|
+
* A navigation triggered by a `goto(...)` call or a redirect
|
|
1327
|
+
*/
|
|
1272
1328
|
export interface NavigationGoto extends NavigationBase {
|
|
1273
|
-
/**
|
|
1274
|
-
* The type of navigation:
|
|
1275
|
-
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1276
|
-
*/
|
|
1277
1329
|
type: 'goto';
|
|
1278
1330
|
}
|
|
1279
1331
|
|
|
1332
|
+
/**
|
|
1333
|
+
* A navigation triggered by the tab being closed, or the user navigating to a different document
|
|
1334
|
+
*/
|
|
1280
1335
|
export interface NavigationLeave extends NavigationBase {
|
|
1281
|
-
/**
|
|
1282
|
-
* The type of navigation:
|
|
1283
|
-
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1284
|
-
*/
|
|
1285
1336
|
type: 'leave';
|
|
1286
1337
|
}
|
|
1287
1338
|
|
|
1339
|
+
/**
|
|
1340
|
+
* A navigation triggered by a `<form method="GET">`
|
|
1341
|
+
*/
|
|
1288
1342
|
export interface NavigationFormSubmit extends NavigationBase {
|
|
1289
|
-
/**
|
|
1290
|
-
* The type of navigation:
|
|
1291
|
-
* - `form`: The user submitted a `<form method="GET">`
|
|
1292
|
-
*/
|
|
1293
1343
|
type: 'form';
|
|
1294
1344
|
|
|
1295
1345
|
/**
|
|
@@ -1298,11 +1348,10 @@ export interface NavigationFormSubmit extends NavigationBase {
|
|
|
1298
1348
|
event: SubmitEvent;
|
|
1299
1349
|
}
|
|
1300
1350
|
|
|
1351
|
+
/**
|
|
1352
|
+
* A navigation triggered by back/forward navigation
|
|
1353
|
+
*/
|
|
1301
1354
|
export interface NavigationPopState extends NavigationBase {
|
|
1302
|
-
/**
|
|
1303
|
-
* The type of navigation:
|
|
1304
|
-
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1305
|
-
*/
|
|
1306
1355
|
type: 'popstate';
|
|
1307
1356
|
|
|
1308
1357
|
/**
|
|
@@ -1316,11 +1365,10 @@ export interface NavigationPopState extends NavigationBase {
|
|
|
1316
1365
|
event: PopStateEvent;
|
|
1317
1366
|
}
|
|
1318
1367
|
|
|
1368
|
+
/**
|
|
1369
|
+
* A navigation triggered by a link click
|
|
1370
|
+
*/
|
|
1319
1371
|
export interface NavigationLink extends NavigationBase {
|
|
1320
|
-
/**
|
|
1321
|
-
* The type of navigation:
|
|
1322
|
-
* - `link`: Navigation was triggered by a link click
|
|
1323
|
-
*/
|
|
1324
1372
|
type: 'link';
|
|
1325
1373
|
|
|
1326
1374
|
/**
|
|
@@ -1368,7 +1416,7 @@ export type AfterNavigate = (Navigation | NavigationEnter) & {
|
|
|
1368
1416
|
};
|
|
1369
1417
|
|
|
1370
1418
|
/**
|
|
1371
|
-
* The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object
|
|
1419
|
+
* The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object.
|
|
1372
1420
|
*/
|
|
1373
1421
|
export interface Page<
|
|
1374
1422
|
Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
|
|
@@ -1377,7 +1425,7 @@ export interface Page<
|
|
|
1377
1425
|
/**
|
|
1378
1426
|
* The URL of the current page.
|
|
1379
1427
|
*/
|
|
1380
|
-
url:
|
|
1428
|
+
url: ReadonlyURL & { readonly pathname: ResolvedPathname | (string & {}) };
|
|
1381
1429
|
/**
|
|
1382
1430
|
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
1383
1431
|
*/
|
|
@@ -1416,7 +1464,64 @@ export interface Page<
|
|
|
1416
1464
|
/**
|
|
1417
1465
|
* The shape of a param matcher. See [matching](https://svelte.dev/docs/kit/advanced-routing#Matching) for more info.
|
|
1418
1466
|
*/
|
|
1419
|
-
export type ParamMatcher =
|
|
1467
|
+
export type ParamMatcher<Output = any> = StandardSchemaV1<string, Output>;
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* A value that can be parsed from a URL param and losslessly encoded with `String(...)`.
|
|
1471
|
+
*/
|
|
1472
|
+
export type ParamValue = string | number | boolean | bigint;
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
|
|
1476
|
+
*/
|
|
1477
|
+
export type ParamDefinition =
|
|
1478
|
+
| ((param: string) => ParamValue | undefined)
|
|
1479
|
+
| StandardSchemaV1<string, ParamValue>;
|
|
1480
|
+
|
|
1481
|
+
/**
|
|
1482
|
+
* The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
|
|
1483
|
+
*/
|
|
1484
|
+
export type DefinedParams<T extends Record<string, ParamDefinition>> = {
|
|
1485
|
+
readonly [K in keyof T]: ParamEntry<T[K]>;
|
|
1486
|
+
};
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* Normalizes a property of defineParams (schema or function) to standard schema.
|
|
1490
|
+
*/
|
|
1491
|
+
type ParamEntry<M> =
|
|
1492
|
+
M extends StandardSchemaV1<any, any>
|
|
1493
|
+
? StandardSchemaV1.InferOutput<M> extends ParamValue
|
|
1494
|
+
? StandardSchemaV1<any, M>
|
|
1495
|
+
: StandardSchemaV1<any, never>
|
|
1496
|
+
: M extends (param: string) => infer R
|
|
1497
|
+
? Exclude<R, undefined> extends ParamValue
|
|
1498
|
+
? StandardSchemaV1<any, Exclude<R, undefined>>
|
|
1499
|
+
: StandardSchemaV1<any, never>
|
|
1500
|
+
: never;
|
|
1501
|
+
|
|
1502
|
+
/**
|
|
1503
|
+
* Extracts the param type from a matcher.
|
|
1504
|
+
*/
|
|
1505
|
+
export type MatcherParam<M extends StandardSchemaV1<any, any>> =
|
|
1506
|
+
M extends StandardSchemaV1<any, infer Inner>
|
|
1507
|
+
? Inner extends ParamValue
|
|
1508
|
+
? Inner
|
|
1509
|
+
: Inner extends StandardSchemaV1<any, any>
|
|
1510
|
+
? StandardSchemaV1.InferOutput<Inner> extends ParamValue
|
|
1511
|
+
? StandardSchemaV1.InferOutput<Inner>
|
|
1512
|
+
: never
|
|
1513
|
+
: never
|
|
1514
|
+
: never;
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* Define [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching) for your app.
|
|
1518
|
+
*
|
|
1519
|
+
* @template T
|
|
1520
|
+
* @param definitions
|
|
1521
|
+
*/
|
|
1522
|
+
export function defineParams<T extends Record<string, ParamDefinition>>(
|
|
1523
|
+
definitions: T
|
|
1524
|
+
): DefinedParams<T>;
|
|
1420
1525
|
|
|
1421
1526
|
/**
|
|
1422
1527
|
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
@@ -1493,7 +1598,7 @@ export interface RequestEvent<
|
|
|
1493
1598
|
* - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
|
|
1494
1599
|
* - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
|
|
1495
1600
|
* - 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.
|
|
1496
|
-
* - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://svelte.dev/docs/kit/hooks#
|
|
1601
|
+
* - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://svelte.dev/docs/kit/hooks#handle)
|
|
1497
1602
|
* - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
|
|
1498
1603
|
*
|
|
1499
1604
|
* You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
|
|
@@ -1504,11 +1609,15 @@ export interface RequestEvent<
|
|
|
1504
1609
|
*/
|
|
1505
1610
|
getClientAddress: () => string;
|
|
1506
1611
|
/**
|
|
1507
|
-
* Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#
|
|
1612
|
+
* Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
|
|
1508
1613
|
*/
|
|
1509
1614
|
locals: App.Locals;
|
|
1510
1615
|
/**
|
|
1511
1616
|
* The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
1617
|
+
*
|
|
1618
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1619
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1620
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1512
1621
|
*/
|
|
1513
1622
|
params: Params;
|
|
1514
1623
|
/**
|
|
@@ -1525,6 +1634,10 @@ export interface RequestEvent<
|
|
|
1525
1634
|
route: {
|
|
1526
1635
|
/**
|
|
1527
1636
|
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
|
|
1637
|
+
*
|
|
1638
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1639
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1640
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1528
1641
|
*/
|
|
1529
1642
|
id: RouteId;
|
|
1530
1643
|
};
|
|
@@ -1553,6 +1666,10 @@ export interface RequestEvent<
|
|
|
1553
1666
|
setHeaders: (headers: Record<string, string>) => void;
|
|
1554
1667
|
/**
|
|
1555
1668
|
* The requested URL.
|
|
1669
|
+
*
|
|
1670
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1671
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1672
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1556
1673
|
*/
|
|
1557
1674
|
url: URL;
|
|
1558
1675
|
/**
|
|
@@ -1611,7 +1728,9 @@ export interface ResolveOptions {
|
|
|
1611
1728
|
*/
|
|
1612
1729
|
filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
|
|
1613
1730
|
/**
|
|
1614
|
-
* Determines
|
|
1731
|
+
* Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
|
|
1732
|
+
* `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
|
|
1733
|
+
* [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
|
|
1615
1734
|
* By default, `js` and `css` files will be preloaded.
|
|
1616
1735
|
* @param input the type of the file and its path
|
|
1617
1736
|
*/
|
|
@@ -1646,19 +1765,24 @@ export interface ServerInitOptions {
|
|
|
1646
1765
|
read?: (file: string) => MaybePromise<ReadableStream | null>;
|
|
1647
1766
|
}
|
|
1648
1767
|
|
|
1768
|
+
/**
|
|
1769
|
+
* Information required to instantiate a new `Server` instance.
|
|
1770
|
+
*/
|
|
1649
1771
|
export interface SSRManifest {
|
|
1772
|
+
/** The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes. */
|
|
1650
1773
|
appDir: string;
|
|
1774
|
+
/** The `base` and `appDir` settings combined without a leading slash. */
|
|
1651
1775
|
appPath: string;
|
|
1652
|
-
/** Static files from `
|
|
1776
|
+
/** Static files from `config.files.assets` and the service worker (if any). */
|
|
1653
1777
|
assets: Set<string>;
|
|
1654
1778
|
mimeTypes: Record<string, string>;
|
|
1655
1779
|
|
|
1656
|
-
/** private fields */
|
|
1780
|
+
/** @internal private fields */
|
|
1657
1781
|
_: {
|
|
1658
|
-
client:
|
|
1782
|
+
client: BuildData['client'];
|
|
1659
1783
|
nodes: SSRNodeLoader[];
|
|
1660
1784
|
/** hashed filename -> import to that file */
|
|
1661
|
-
remotes: Record<string, () => Promise<any>>;
|
|
1785
|
+
remotes: Record<string, () => Promise<{ default: Record<string, any> }>>;
|
|
1662
1786
|
routes: SSRRoute[];
|
|
1663
1787
|
prerendered_routes: Set<string>;
|
|
1664
1788
|
matchers: () => Promise<Record<string, ParamMatcher>>;
|
|
@@ -1793,7 +1917,7 @@ export type ActionResult<
|
|
|
1793
1917
|
| { type: 'success'; status: number; data?: Success }
|
|
1794
1918
|
| { type: 'failure'; status: number; data?: Failure }
|
|
1795
1919
|
| { type: 'redirect'; status: number; location: string }
|
|
1796
|
-
| { type: 'error'; status?: number; error:
|
|
1920
|
+
| { type: 'error'; status?: number; error: App.Error };
|
|
1797
1921
|
|
|
1798
1922
|
/**
|
|
1799
1923
|
* The object returned by the [`error`](https://svelte.dev/docs/kit/@sveltejs-kit#error) function.
|
|
@@ -1849,6 +1973,14 @@ export interface Snapshot<T = any> {
|
|
|
1849
1973
|
restore: (snapshot: T) => void;
|
|
1850
1974
|
}
|
|
1851
1975
|
|
|
1976
|
+
export type ReadonlyURLSearchParams = Omit<URLSearchParams, 'set' | 'append' | 'delete' | 'sort'>;
|
|
1977
|
+
|
|
1978
|
+
export type ReadonlyURL = Readonly<
|
|
1979
|
+
Omit<URL, 'searchParams'> & {
|
|
1980
|
+
searchParams: ReadonlyURLSearchParams;
|
|
1981
|
+
}
|
|
1982
|
+
>;
|
|
1983
|
+
|
|
1852
1984
|
// If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
|
|
1853
1985
|
type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
|
|
1854
1986
|
|
|
@@ -1942,6 +2074,10 @@ type RemoteFormFieldMethods<T> = {
|
|
|
1942
2074
|
value(): DeepPartial<T>;
|
|
1943
2075
|
/** Set the values that will be submitted */
|
|
1944
2076
|
set(input: DeepPartial<T>): DeepPartial<T>;
|
|
2077
|
+
/** Whether the field or any nested field has been interacted with since the form was mounted */
|
|
2078
|
+
touched(): boolean;
|
|
2079
|
+
/** Whether the field or any nested field has been edited since the form was mounted */
|
|
2080
|
+
dirty(): boolean;
|
|
1945
2081
|
/** Validation issues, if any */
|
|
1946
2082
|
issues(): RemoteFormIssue[] | undefined;
|
|
1947
2083
|
};
|
|
@@ -2056,7 +2192,7 @@ type RecursiveFormFields = RemoteFormFieldContainer<any> & {
|
|
|
2056
2192
|
type MaybeArray<T> = T | T[];
|
|
2057
2193
|
|
|
2058
2194
|
export interface RemoteFormInput {
|
|
2059
|
-
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput
|
|
2195
|
+
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
|
|
2060
2196
|
}
|
|
2061
2197
|
|
|
2062
2198
|
export interface RemoteFormIssue {
|
|
@@ -2102,6 +2238,24 @@ export interface ValidationError {
|
|
|
2102
2238
|
issues: StandardSchemaV1.Issue[];
|
|
2103
2239
|
}
|
|
2104
2240
|
|
|
2241
|
+
/**
|
|
2242
|
+
* The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2243
|
+
*/
|
|
2244
|
+
export type RemoteFormEnhanceInstance<
|
|
2245
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
2246
|
+
Output = any
|
|
2247
|
+
> = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
|
|
2248
|
+
readonly element: HTMLFormElement;
|
|
2249
|
+
};
|
|
2250
|
+
|
|
2251
|
+
/**
|
|
2252
|
+
* The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2253
|
+
*/
|
|
2254
|
+
export type RemoteFormEnhanceCallback<
|
|
2255
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
2256
|
+
Output = any
|
|
2257
|
+
> = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
|
|
2258
|
+
|
|
2105
2259
|
/**
|
|
2106
2260
|
* The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2107
2261
|
*/
|
|
@@ -2118,13 +2272,7 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2118
2272
|
updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
|
|
2119
2273
|
};
|
|
2120
2274
|
/** Use the `enhance` method to influence what happens when the form is submitted. */
|
|
2121
|
-
enhance(
|
|
2122
|
-
callback: (
|
|
2123
|
-
form: Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
|
|
2124
|
-
readonly element: HTMLFormElement;
|
|
2125
|
-
}
|
|
2126
|
-
) => MaybePromise<void>
|
|
2127
|
-
): {
|
|
2275
|
+
enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
|
|
2128
2276
|
method: 'POST';
|
|
2129
2277
|
action: string;
|
|
2130
2278
|
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
@@ -2148,8 +2296,13 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2148
2296
|
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
|
|
2149
2297
|
/** Validate the form contents programmatically */
|
|
2150
2298
|
validate(options?: {
|
|
2151
|
-
/**
|
|
2152
|
-
|
|
2299
|
+
/**
|
|
2300
|
+
* Set this to `true` to also show validation issues of fields that haven't yet been
|
|
2301
|
+
* edited and blurred. This option is ignored for forms that have previously been
|
|
2302
|
+
* submitted, in which case all fields are always subject to validation
|
|
2303
|
+
* (unless the form is reset, at which point it is treated as pristine)
|
|
2304
|
+
*/
|
|
2305
|
+
all?: boolean;
|
|
2153
2306
|
/** Set this to `true` to only run the `preflight` validation. */
|
|
2154
2307
|
preflightOnly?: boolean;
|
|
2155
2308
|
}): Promise<void>;
|
|
@@ -2157,6 +2310,8 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2157
2310
|
get result(): Output | undefined;
|
|
2158
2311
|
/** The number of pending submissions */
|
|
2159
2312
|
get pending(): number;
|
|
2313
|
+
/** True if the form has been submitted at least once, and hasn't been reset since */
|
|
2314
|
+
get submitted(): boolean;
|
|
2160
2315
|
/** Access form fields using object notation */
|
|
2161
2316
|
fields: RemoteFormFieldsRoot<Input>;
|
|
2162
2317
|
};
|
|
@@ -2180,8 +2335,8 @@ export type RemoteQueryUpdate =
|
|
|
2180
2335
|
| RemoteQueryOverride;
|
|
2181
2336
|
|
|
2182
2337
|
export type RemoteResource<T> = Promise<T> & {
|
|
2183
|
-
/** The error in case the query fails.
|
|
2184
|
-
get error():
|
|
2338
|
+
/** The error in case the query fails. */
|
|
2339
|
+
get error(): App.Error | undefined;
|
|
2185
2340
|
/** `true` before the first result is available and during refreshes */
|
|
2186
2341
|
get loading(): boolean;
|
|
2187
2342
|
} & (
|
|
@@ -2282,7 +2437,7 @@ export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
|
|
|
2282
2437
|
|
|
2283
2438
|
/**
|
|
2284
2439
|
* [Environment variables](https://svelte.dev/docs/kit/environment-variables) can be configured by exporting
|
|
2285
|
-
* a `variables` object from `src/env.ts`, using [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-
|
|
2440
|
+
* a `variables` object from `src/env.ts`, using [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
|
|
2286
2441
|
*/
|
|
2287
2442
|
export interface EnvVarConfig<T> {
|
|
2288
2443
|
/**
|
|
@@ -2301,16 +2456,35 @@ export interface EnvVarConfig<T> {
|
|
|
2301
2456
|
static?: boolean;
|
|
2302
2457
|
/**
|
|
2303
2458
|
* A [Standard Schema](https://standardschema.dev/) validator that is applied to the value when the app starts.
|
|
2459
|
+
* Alternatively, a function that returns the (possibly transformed) value, or throws an error explaining
|
|
2460
|
+
* the problem. Returning `undefined` is valid, so a function can describe an optional variable.
|
|
2304
2461
|
* The validator can output any value — not necessarily a string — but public, non-static values must be
|
|
2305
2462
|
* serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
|
|
2306
2463
|
*
|
|
2307
|
-
* If omitted, the value must be
|
|
2464
|
+
* If omitted, the value must be set, but may be an empty string.
|
|
2308
2465
|
*/
|
|
2309
|
-
schema?: StandardSchemaV1<string | undefined, T
|
|
2466
|
+
schema?: StandardSchemaV1<string | undefined, T> | ((value: string | undefined) => T | undefined);
|
|
2310
2467
|
/**
|
|
2311
2468
|
* A description of the variable that will be used for inline documentation on hover.
|
|
2312
2469
|
*/
|
|
2313
2470
|
description?: string;
|
|
2314
2471
|
}
|
|
2315
2472
|
|
|
2473
|
+
/**
|
|
2474
|
+
* The return type of [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
|
|
2475
|
+
*/
|
|
2476
|
+
export type DefinedEnvVars<T extends Record<string, EnvVarConfig<any>>> = {
|
|
2477
|
+
readonly [K in keyof T]: EnvVarEntry<T[K]>;
|
|
2478
|
+
};
|
|
2479
|
+
|
|
2480
|
+
/**
|
|
2481
|
+
* Normalizes an environment variable config's schema (standard schema or function) to standard schema.
|
|
2482
|
+
*/
|
|
2483
|
+
type EnvVarEntry<C extends EnvVarConfig<any>> =
|
|
2484
|
+
C['schema'] extends StandardSchemaV1<any, any>
|
|
2485
|
+
? C
|
|
2486
|
+
: C['schema'] extends (value: any) => infer R
|
|
2487
|
+
? Omit<C, 'schema'> & { schema: StandardSchemaV1<string | undefined, R> }
|
|
2488
|
+
: C;
|
|
2489
|
+
|
|
2316
2490
|
export * from './index.js';
|