@sveltejs/kit 3.0.0-next.0 → 3.0.0-next.10
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/core/adapt/builder.js +29 -43
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +132 -71
- package/src/core/config/options.js +294 -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/prerender.js +42 -23
- 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 +13 -14
- 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 +2 -2
- package/src/exports/env/index.js +12 -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 +2 -2
- 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 +63 -0
- package/src/exports/public.d.ts +323 -170
- 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 +42 -44
- package/src/exports/vite/index.js +810 -593
- package/src/exports/vite/preview/index.js +29 -22
- 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 +21 -36
- 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 +6 -0
- 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 +9 -5
- 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 +38 -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 +14 -18
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/actions.js +41 -26
- package/src/runtime/server/page/index.js +9 -15
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +112 -187
- package/src/runtime/server/page/respond_with_error.js +7 -8
- package/src/runtime/server/page/server_routing.js +27 -18
- package/src/runtime/server/remote.js +355 -216
- package/src/runtime/server/respond.js +97 -61
- package/src/runtime/server/utils.js +32 -9
- 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.d.ts +10 -5
- package/src/types/global-private.d.ts +15 -22
- package/src/types/internal.d.ts +89 -74
- package/src/types/private.d.ts +33 -1
- package/src/utils/error.js +24 -4
- package/src/utils/import.js +6 -1
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- 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 +467 -537
- package/types/index.d.ts.map +22 -39
- package/src/core/sync/write_root.js +0 -148
- package/src/exports/internal/server.js +0 -22
- 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
|
*/
|
|
@@ -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,8 +435,6 @@ 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
|
-
* > [!NOTE] Note that most [Svelte transitions](https://svelte.dev/tutorial/svelte/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`.
|
|
399
|
-
*
|
|
400
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#Server-hooks-handle) to roll your own CSP.
|
|
401
439
|
*/
|
|
402
440
|
csp?: {
|
|
@@ -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
|
/**
|
|
@@ -849,6 +870,17 @@ export interface KitConfig {
|
|
|
849
870
|
register?: false;
|
|
850
871
|
}
|
|
851
872
|
);
|
|
873
|
+
/**
|
|
874
|
+
* Options for enabling [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations.
|
|
875
|
+
* @default { server: false }
|
|
876
|
+
*/
|
|
877
|
+
tracing?: {
|
|
878
|
+
/**
|
|
879
|
+
* 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). 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.
|
|
880
|
+
* @default false
|
|
881
|
+
*/
|
|
882
|
+
server?: boolean;
|
|
883
|
+
};
|
|
852
884
|
typescript?: {
|
|
853
885
|
/**
|
|
854
886
|
* A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
|
|
@@ -889,16 +921,20 @@ export interface KitConfig {
|
|
|
889
921
|
* For example, to use the current commit hash, you could do use `git rev-parse HEAD`:
|
|
890
922
|
*
|
|
891
923
|
* ```js
|
|
892
|
-
* /// file:
|
|
924
|
+
* /// file: vite.config.js
|
|
893
925
|
* import * as child_process from 'node:child_process';
|
|
926
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
927
|
+
* import { defineConfig } from 'vite';
|
|
894
928
|
*
|
|
895
|
-
* export default {
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
*
|
|
929
|
+
* export default defineConfig({
|
|
930
|
+
* plugins: [
|
|
931
|
+
* sveltekit({
|
|
932
|
+
* version: {
|
|
933
|
+
* name: child_process.execSync('git rev-parse HEAD').toString().trim()
|
|
934
|
+
* }
|
|
935
|
+
* })
|
|
936
|
+
* ]
|
|
937
|
+
* });
|
|
902
938
|
* ```
|
|
903
939
|
*/
|
|
904
940
|
name?: string;
|
|
@@ -918,7 +954,7 @@ export interface KitConfig {
|
|
|
918
954
|
*/
|
|
919
955
|
export type Handle = (input: {
|
|
920
956
|
event: RequestEvent;
|
|
921
|
-
resolve: (event: RequestEvent, opts?: ResolveOptions) =>
|
|
957
|
+
resolve: (event: RequestEvent, opts?: ResolveOptions) => Promise<Response>;
|
|
922
958
|
}) => MaybePromise<Response>;
|
|
923
959
|
|
|
924
960
|
/**
|
|
@@ -926,13 +962,16 @@ export type Handle = (input: {
|
|
|
926
962
|
*
|
|
927
963
|
* If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
|
|
928
964
|
* Make sure that this function _never_ throws an error.
|
|
965
|
+
*
|
|
966
|
+
* The returned object can include a `status` property to override the HTTP status code used in the response.
|
|
967
|
+
* If omitted, the status defaults to 500.
|
|
929
968
|
*/
|
|
930
969
|
export type HandleServerError = (input: {
|
|
931
970
|
error: unknown;
|
|
932
971
|
event: RequestEvent;
|
|
933
972
|
status: number;
|
|
934
973
|
message: string;
|
|
935
|
-
}) => MaybePromise<void |
|
|
974
|
+
}) => MaybePromise<void | AppErrorWithOptionalStatus>;
|
|
936
975
|
|
|
937
976
|
/**
|
|
938
977
|
* The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleValidationError) hook runs when the argument to a remote function fails validation.
|
|
@@ -940,20 +979,23 @@ export type HandleServerError = (input: {
|
|
|
940
979
|
* It will be called with the validation issues and the event, and must return an object shape that matches `App.Error`.
|
|
941
980
|
*/
|
|
942
981
|
export type HandleValidationError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
|
|
943
|
-
(input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<
|
|
982
|
+
(input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<AppErrorWithOptionalStatus>;
|
|
944
983
|
|
|
945
984
|
/**
|
|
946
985
|
* The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError) hook runs when an unexpected error is thrown while navigating.
|
|
947
986
|
*
|
|
948
987
|
* If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
|
|
949
988
|
* Make sure that this function _never_ throws an error.
|
|
989
|
+
*
|
|
990
|
+
* The returned object can include a `status` property to override the HTTP status code used in the response.
|
|
991
|
+
* If omitted, the status defaults to 500.
|
|
950
992
|
*/
|
|
951
993
|
export type HandleClientError = (input: {
|
|
952
994
|
error: unknown;
|
|
953
995
|
event: NavigationEvent;
|
|
954
996
|
status: number;
|
|
955
997
|
message: string;
|
|
956
|
-
}) => MaybePromise<void |
|
|
998
|
+
}) => MaybePromise<void | AppErrorWithOptionalStatus>;
|
|
957
999
|
|
|
958
1000
|
/**
|
|
959
1001
|
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-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`.
|
|
@@ -1013,7 +1055,7 @@ export type Transport = Record<string, Transporter>;
|
|
|
1013
1055
|
*/
|
|
1014
1056
|
export interface Transporter<
|
|
1015
1057
|
T = any,
|
|
1016
|
-
U =
|
|
1058
|
+
U = any /* minus falsy values, but we can't properly express that */
|
|
1017
1059
|
> {
|
|
1018
1060
|
encode: (value: T) => false | U;
|
|
1019
1061
|
decode: (data: U) => T;
|
|
@@ -1222,14 +1264,24 @@ export interface NavigationTarget<
|
|
|
1222
1264
|
/**
|
|
1223
1265
|
* - `enter`: The app has hydrated/started
|
|
1224
1266
|
* - `form`: The user submitted a `<form method="GET">`
|
|
1267
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1225
1268
|
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1226
1269
|
* - `link`: Navigation was triggered by a link click
|
|
1227
|
-
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1228
1270
|
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1229
1271
|
*/
|
|
1230
1272
|
export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
1231
1273
|
|
|
1232
1274
|
export interface NavigationBase {
|
|
1275
|
+
/**
|
|
1276
|
+
* The type of navigation:
|
|
1277
|
+
* - `enter`: The app has hydrated/started
|
|
1278
|
+
* - `form`: The user submitted a `<form method="GET">`
|
|
1279
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1280
|
+
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1281
|
+
* - `link`: Navigation was triggered by a link click
|
|
1282
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1283
|
+
*/
|
|
1284
|
+
type: NavigationType;
|
|
1233
1285
|
/**
|
|
1234
1286
|
* Where navigation was triggered from
|
|
1235
1287
|
*/
|
|
@@ -1249,11 +1301,10 @@ export interface NavigationBase {
|
|
|
1249
1301
|
complete: Promise<void>;
|
|
1250
1302
|
}
|
|
1251
1303
|
|
|
1304
|
+
/**
|
|
1305
|
+
* The navigation that occurs when the app starts/hydrates
|
|
1306
|
+
*/
|
|
1252
1307
|
export interface NavigationEnter extends NavigationBase {
|
|
1253
|
-
/**
|
|
1254
|
-
* The type of navigation:
|
|
1255
|
-
* - `enter`: The app has hydrated/started
|
|
1256
|
-
*/
|
|
1257
1308
|
type: 'enter';
|
|
1258
1309
|
|
|
1259
1310
|
/**
|
|
@@ -1269,27 +1320,24 @@ export interface NavigationEnter extends NavigationBase {
|
|
|
1269
1320
|
|
|
1270
1321
|
export type NavigationExternal = NavigationGoto | NavigationLeave;
|
|
1271
1322
|
|
|
1323
|
+
/**
|
|
1324
|
+
* A navigation triggered by a `goto(...)` call or a redirect
|
|
1325
|
+
*/
|
|
1272
1326
|
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
1327
|
type: 'goto';
|
|
1278
1328
|
}
|
|
1279
1329
|
|
|
1330
|
+
/**
|
|
1331
|
+
* A navigation triggered by the tab being closed, or the user navigating to a different document
|
|
1332
|
+
*/
|
|
1280
1333
|
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
1334
|
type: 'leave';
|
|
1286
1335
|
}
|
|
1287
1336
|
|
|
1337
|
+
/**
|
|
1338
|
+
* A navigation triggered by a `<form method="GET">`
|
|
1339
|
+
*/
|
|
1288
1340
|
export interface NavigationFormSubmit extends NavigationBase {
|
|
1289
|
-
/**
|
|
1290
|
-
* The type of navigation:
|
|
1291
|
-
* - `form`: The user submitted a `<form method="GET">`
|
|
1292
|
-
*/
|
|
1293
1341
|
type: 'form';
|
|
1294
1342
|
|
|
1295
1343
|
/**
|
|
@@ -1298,11 +1346,10 @@ export interface NavigationFormSubmit extends NavigationBase {
|
|
|
1298
1346
|
event: SubmitEvent;
|
|
1299
1347
|
}
|
|
1300
1348
|
|
|
1349
|
+
/**
|
|
1350
|
+
* A navigation triggered by back/forward navigation
|
|
1351
|
+
*/
|
|
1301
1352
|
export interface NavigationPopState extends NavigationBase {
|
|
1302
|
-
/**
|
|
1303
|
-
* The type of navigation:
|
|
1304
|
-
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1305
|
-
*/
|
|
1306
1353
|
type: 'popstate';
|
|
1307
1354
|
|
|
1308
1355
|
/**
|
|
@@ -1316,11 +1363,10 @@ export interface NavigationPopState extends NavigationBase {
|
|
|
1316
1363
|
event: PopStateEvent;
|
|
1317
1364
|
}
|
|
1318
1365
|
|
|
1366
|
+
/**
|
|
1367
|
+
* A navigation triggered by a link click
|
|
1368
|
+
*/
|
|
1319
1369
|
export interface NavigationLink extends NavigationBase {
|
|
1320
|
-
/**
|
|
1321
|
-
* The type of navigation:
|
|
1322
|
-
* - `link`: Navigation was triggered by a link click
|
|
1323
|
-
*/
|
|
1324
1370
|
type: 'link';
|
|
1325
1371
|
|
|
1326
1372
|
/**
|
|
@@ -1368,7 +1414,7 @@ export type AfterNavigate = (Navigation | NavigationEnter) & {
|
|
|
1368
1414
|
};
|
|
1369
1415
|
|
|
1370
1416
|
/**
|
|
1371
|
-
* The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object
|
|
1417
|
+
* The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object.
|
|
1372
1418
|
*/
|
|
1373
1419
|
export interface Page<
|
|
1374
1420
|
Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
|
|
@@ -1377,7 +1423,7 @@ export interface Page<
|
|
|
1377
1423
|
/**
|
|
1378
1424
|
* The URL of the current page.
|
|
1379
1425
|
*/
|
|
1380
|
-
url:
|
|
1426
|
+
url: ReadonlyURL & { readonly pathname: ResolvedPathname | (string & {}) };
|
|
1381
1427
|
/**
|
|
1382
1428
|
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
1383
1429
|
*/
|
|
@@ -1416,7 +1462,64 @@ export interface Page<
|
|
|
1416
1462
|
/**
|
|
1417
1463
|
* The shape of a param matcher. See [matching](https://svelte.dev/docs/kit/advanced-routing#Matching) for more info.
|
|
1418
1464
|
*/
|
|
1419
|
-
export type ParamMatcher =
|
|
1465
|
+
export type ParamMatcher<Output = any> = StandardSchemaV1<string, Output>;
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* A value that can be parsed from a URL param and losslessly encoded with `String(...)`.
|
|
1469
|
+
*/
|
|
1470
|
+
export type ParamValue = string | number | boolean | bigint;
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
|
|
1474
|
+
*/
|
|
1475
|
+
export type ParamDefinition =
|
|
1476
|
+
| ((param: string) => ParamValue | undefined)
|
|
1477
|
+
| StandardSchemaV1<string, ParamValue>;
|
|
1478
|
+
|
|
1479
|
+
/**
|
|
1480
|
+
* The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
|
|
1481
|
+
*/
|
|
1482
|
+
export type DefinedParams<T extends Record<string, ParamDefinition>> = {
|
|
1483
|
+
readonly [K in keyof T]: ParamEntry<T[K]>;
|
|
1484
|
+
};
|
|
1485
|
+
|
|
1486
|
+
/**
|
|
1487
|
+
* Normalizes a property of defineParams (schema or function) to standard schema.
|
|
1488
|
+
*/
|
|
1489
|
+
type ParamEntry<M> =
|
|
1490
|
+
M extends StandardSchemaV1<any, any>
|
|
1491
|
+
? StandardSchemaV1.InferOutput<M> extends ParamValue
|
|
1492
|
+
? StandardSchemaV1<any, M>
|
|
1493
|
+
: StandardSchemaV1<any, never>
|
|
1494
|
+
: M extends (param: string) => infer R
|
|
1495
|
+
? Exclude<R, undefined> extends ParamValue
|
|
1496
|
+
? StandardSchemaV1<any, Exclude<R, undefined>>
|
|
1497
|
+
: StandardSchemaV1<any, never>
|
|
1498
|
+
: never;
|
|
1499
|
+
|
|
1500
|
+
/**
|
|
1501
|
+
* Extracts the param type from a matcher.
|
|
1502
|
+
*/
|
|
1503
|
+
export type MatcherParam<M extends StandardSchemaV1<any, any>> =
|
|
1504
|
+
M extends StandardSchemaV1<any, infer Inner>
|
|
1505
|
+
? Inner extends ParamValue
|
|
1506
|
+
? Inner
|
|
1507
|
+
: Inner extends StandardSchemaV1<any, any>
|
|
1508
|
+
? StandardSchemaV1.InferOutput<Inner> extends ParamValue
|
|
1509
|
+
? StandardSchemaV1.InferOutput<Inner>
|
|
1510
|
+
: never
|
|
1511
|
+
: never
|
|
1512
|
+
: never;
|
|
1513
|
+
|
|
1514
|
+
/**
|
|
1515
|
+
* Define [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching) for your app.
|
|
1516
|
+
*
|
|
1517
|
+
* @template T
|
|
1518
|
+
* @param definitions
|
|
1519
|
+
*/
|
|
1520
|
+
export function defineParams<T extends Record<string, ParamDefinition>>(
|
|
1521
|
+
definitions: T
|
|
1522
|
+
): DefinedParams<T>;
|
|
1420
1523
|
|
|
1421
1524
|
/**
|
|
1422
1525
|
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
@@ -1509,6 +1612,10 @@ export interface RequestEvent<
|
|
|
1509
1612
|
locals: App.Locals;
|
|
1510
1613
|
/**
|
|
1511
1614
|
* The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
1615
|
+
*
|
|
1616
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1617
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1618
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1512
1619
|
*/
|
|
1513
1620
|
params: Params;
|
|
1514
1621
|
/**
|
|
@@ -1525,6 +1632,10 @@ export interface RequestEvent<
|
|
|
1525
1632
|
route: {
|
|
1526
1633
|
/**
|
|
1527
1634
|
* 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.
|
|
1635
|
+
*
|
|
1636
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1637
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1638
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1528
1639
|
*/
|
|
1529
1640
|
id: RouteId;
|
|
1530
1641
|
};
|
|
@@ -1553,6 +1664,10 @@ export interface RequestEvent<
|
|
|
1553
1664
|
setHeaders: (headers: Record<string, string>) => void;
|
|
1554
1665
|
/**
|
|
1555
1666
|
* The requested URL.
|
|
1667
|
+
*
|
|
1668
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1669
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1670
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1556
1671
|
*/
|
|
1557
1672
|
url: URL;
|
|
1558
1673
|
/**
|
|
@@ -1611,7 +1726,9 @@ export interface ResolveOptions {
|
|
|
1611
1726
|
*/
|
|
1612
1727
|
filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
|
|
1613
1728
|
/**
|
|
1614
|
-
* Determines
|
|
1729
|
+
* Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
|
|
1730
|
+
* `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
|
|
1731
|
+
* [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
|
|
1615
1732
|
* By default, `js` and `css` files will be preloaded.
|
|
1616
1733
|
* @param input the type of the file and its path
|
|
1617
1734
|
*/
|
|
@@ -1646,19 +1763,24 @@ export interface ServerInitOptions {
|
|
|
1646
1763
|
read?: (file: string) => MaybePromise<ReadableStream | null>;
|
|
1647
1764
|
}
|
|
1648
1765
|
|
|
1766
|
+
/**
|
|
1767
|
+
* Information required to instantiate a new `Server` instance.
|
|
1768
|
+
*/
|
|
1649
1769
|
export interface SSRManifest {
|
|
1770
|
+
/** The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes. */
|
|
1650
1771
|
appDir: string;
|
|
1772
|
+
/** The `base` and `appDir` settings combined without a leading slash. */
|
|
1651
1773
|
appPath: string;
|
|
1652
|
-
/** Static files from `
|
|
1774
|
+
/** Static files from `config.files.assets` and the service worker (if any). */
|
|
1653
1775
|
assets: Set<string>;
|
|
1654
1776
|
mimeTypes: Record<string, string>;
|
|
1655
1777
|
|
|
1656
|
-
/** private fields */
|
|
1778
|
+
/** @internal private fields */
|
|
1657
1779
|
_: {
|
|
1658
|
-
client:
|
|
1780
|
+
client: BuildData['client'];
|
|
1659
1781
|
nodes: SSRNodeLoader[];
|
|
1660
1782
|
/** hashed filename -> import to that file */
|
|
1661
|
-
remotes: Record<string, () => Promise<any>>;
|
|
1783
|
+
remotes: Record<string, () => Promise<{ default: Record<string, any> }>>;
|
|
1662
1784
|
routes: SSRRoute[];
|
|
1663
1785
|
prerendered_routes: Set<string>;
|
|
1664
1786
|
matchers: () => Promise<Record<string, ParamMatcher>>;
|
|
@@ -1793,7 +1915,7 @@ export type ActionResult<
|
|
|
1793
1915
|
| { type: 'success'; status: number; data?: Success }
|
|
1794
1916
|
| { type: 'failure'; status: number; data?: Failure }
|
|
1795
1917
|
| { type: 'redirect'; status: number; location: string }
|
|
1796
|
-
| { type: 'error'; status?: number; error:
|
|
1918
|
+
| { type: 'error'; status?: number; error: App.Error };
|
|
1797
1919
|
|
|
1798
1920
|
/**
|
|
1799
1921
|
* The object returned by the [`error`](https://svelte.dev/docs/kit/@sveltejs-kit#error) function.
|
|
@@ -1849,6 +1971,14 @@ export interface Snapshot<T = any> {
|
|
|
1849
1971
|
restore: (snapshot: T) => void;
|
|
1850
1972
|
}
|
|
1851
1973
|
|
|
1974
|
+
export type ReadonlyURLSearchParams = Omit<URLSearchParams, 'set' | 'append' | 'delete' | 'sort'>;
|
|
1975
|
+
|
|
1976
|
+
export type ReadonlyURL = Readonly<
|
|
1977
|
+
Omit<URL, 'searchParams'> & {
|
|
1978
|
+
searchParams: ReadonlyURLSearchParams;
|
|
1979
|
+
}
|
|
1980
|
+
>;
|
|
1981
|
+
|
|
1852
1982
|
// 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
1983
|
type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
|
|
1854
1984
|
|
|
@@ -1942,6 +2072,10 @@ type RemoteFormFieldMethods<T> = {
|
|
|
1942
2072
|
value(): DeepPartial<T>;
|
|
1943
2073
|
/** Set the values that will be submitted */
|
|
1944
2074
|
set(input: DeepPartial<T>): DeepPartial<T>;
|
|
2075
|
+
/** Whether the field or any nested field has been interacted with since the form was mounted */
|
|
2076
|
+
touched(): boolean;
|
|
2077
|
+
/** Whether the field or any nested field has been edited since the form was mounted */
|
|
2078
|
+
dirty(): boolean;
|
|
1945
2079
|
/** Validation issues, if any */
|
|
1946
2080
|
issues(): RemoteFormIssue[] | undefined;
|
|
1947
2081
|
};
|
|
@@ -2056,7 +2190,7 @@ type RecursiveFormFields = RemoteFormFieldContainer<any> & {
|
|
|
2056
2190
|
type MaybeArray<T> = T | T[];
|
|
2057
2191
|
|
|
2058
2192
|
export interface RemoteFormInput {
|
|
2059
|
-
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput
|
|
2193
|
+
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
|
|
2060
2194
|
}
|
|
2061
2195
|
|
|
2062
2196
|
export interface RemoteFormIssue {
|
|
@@ -2102,6 +2236,24 @@ export interface ValidationError {
|
|
|
2102
2236
|
issues: StandardSchemaV1.Issue[];
|
|
2103
2237
|
}
|
|
2104
2238
|
|
|
2239
|
+
/**
|
|
2240
|
+
* The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2241
|
+
*/
|
|
2242
|
+
export type RemoteFormEnhanceInstance<
|
|
2243
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
2244
|
+
Output = any
|
|
2245
|
+
> = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
|
|
2246
|
+
readonly element: HTMLFormElement;
|
|
2247
|
+
};
|
|
2248
|
+
|
|
2249
|
+
/**
|
|
2250
|
+
* The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2251
|
+
*/
|
|
2252
|
+
export type RemoteFormEnhanceCallback<
|
|
2253
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
2254
|
+
Output = any
|
|
2255
|
+
> = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
|
|
2256
|
+
|
|
2105
2257
|
/**
|
|
2106
2258
|
* The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2107
2259
|
*/
|
|
@@ -2118,13 +2270,7 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2118
2270
|
updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
|
|
2119
2271
|
};
|
|
2120
2272
|
/** 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
|
-
): {
|
|
2273
|
+
enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
|
|
2128
2274
|
method: 'POST';
|
|
2129
2275
|
action: string;
|
|
2130
2276
|
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
@@ -2148,8 +2294,13 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2148
2294
|
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
|
|
2149
2295
|
/** Validate the form contents programmatically */
|
|
2150
2296
|
validate(options?: {
|
|
2151
|
-
/**
|
|
2152
|
-
|
|
2297
|
+
/**
|
|
2298
|
+
* Set this to `true` to also show validation issues of fields that haven't yet been
|
|
2299
|
+
* edited and blurred. This option is ignored for forms that have previously been
|
|
2300
|
+
* submitted, in which case all fields are always subject to validation
|
|
2301
|
+
* (unless the form is reset, at which point it is treated as pristine)
|
|
2302
|
+
*/
|
|
2303
|
+
all?: boolean;
|
|
2153
2304
|
/** Set this to `true` to only run the `preflight` validation. */
|
|
2154
2305
|
preflightOnly?: boolean;
|
|
2155
2306
|
}): Promise<void>;
|
|
@@ -2157,6 +2308,8 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2157
2308
|
get result(): Output | undefined;
|
|
2158
2309
|
/** The number of pending submissions */
|
|
2159
2310
|
get pending(): number;
|
|
2311
|
+
/** True if the form has been submitted at least once, and hasn't been reset since */
|
|
2312
|
+
get submitted(): boolean;
|
|
2160
2313
|
/** Access form fields using object notation */
|
|
2161
2314
|
fields: RemoteFormFieldsRoot<Input>;
|
|
2162
2315
|
};
|
|
@@ -2180,8 +2333,8 @@ export type RemoteQueryUpdate =
|
|
|
2180
2333
|
| RemoteQueryOverride;
|
|
2181
2334
|
|
|
2182
2335
|
export type RemoteResource<T> = Promise<T> & {
|
|
2183
|
-
/** The error in case the query fails.
|
|
2184
|
-
get error():
|
|
2336
|
+
/** The error in case the query fails. */
|
|
2337
|
+
get error(): App.Error | undefined;
|
|
2185
2338
|
/** `true` before the first result is available and during refreshes */
|
|
2186
2339
|
get loading(): boolean;
|
|
2187
2340
|
} & (
|
|
@@ -2282,7 +2435,7 @@ export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
|
|
|
2282
2435
|
|
|
2283
2436
|
/**
|
|
2284
2437
|
* [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-
|
|
2438
|
+
* a `variables` object from `src/env.ts`, using [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
|
|
2286
2439
|
*/
|
|
2287
2440
|
export interface EnvVarConfig<T> {
|
|
2288
2441
|
/**
|