@sveltejs/kit 3.0.0-next.4 → 3.0.0-next.7
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 +23 -18
- package/src/core/adapt/builder.js +29 -43
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +135 -71
- package/src/core/config/options.js +291 -244
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +120 -5
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/postbuild/analyse.js +8 -12
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/prerender.js +40 -23
- package/src/core/sync/create_manifest_data/index.js +29 -49
- package/src/core/sync/write_client_manifest.js +14 -14
- package/src/core/sync/write_non_ambient.js +10 -7
- package/src/core/sync/write_root.js +9 -30
- package/src/core/sync/write_server.js +13 -11
- package/src/core/sync/write_tsconfig.js +2 -4
- package/src/core/sync/write_types/index.js +11 -10
- package/src/exports/index.js +34 -12
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +1 -1
- 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 +58 -7
- package/src/exports/params.js +63 -0
- package/src/exports/public.d.ts +299 -145
- package/src/exports/url.js +84 -0
- package/src/exports/vite/build/build_server.js +6 -1
- package/src/exports/vite/dev/index.js +38 -37
- package/src/exports/vite/index.js +498 -353
- package/src/exports/vite/preview/index.js +16 -8
- package/src/exports/vite/utils.js +7 -11
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/forms.js +22 -5
- package/src/runtime/app/paths/client.js +4 -10
- package/src/runtime/app/paths/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +8 -4
- package/src/runtime/app/server/remote/form.js +10 -3
- package/src/runtime/app/server/remote/query.js +9 -18
- package/src/runtime/app/server/remote/requested.js +8 -4
- package/src/runtime/app/server/remote/shared.js +5 -7
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/client.js +205 -167
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/form.svelte.js +122 -31
- package/src/runtime/client/remote-functions/prerender.svelte.js +17 -4
- package/src/runtime/client/remote-functions/query/index.js +3 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +27 -11
- package/src/runtime/client/remote-functions/query-batch.svelte.js +4 -3
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +42 -15
- package/src/runtime/client/remote-functions/shared.svelte.js +18 -9
- package/src/runtime/client/state.svelte.js +66 -49
- package/src/runtime/client/types.d.ts +10 -2
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/form-utils.js +99 -18
- package/src/runtime/server/cookie.js +22 -33
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +7 -7
- 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 +2 -1
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +36 -47
- package/src/runtime/server/page/respond_with_error.js +7 -8
- package/src/runtime/server/page/server_routing.js +13 -9
- package/src/runtime/server/remote.js +85 -39
- package/src/runtime/server/respond.js +92 -58
- package/src/runtime/server/utils.js +7 -7
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +4 -4
- package/src/types/internal.d.ts +17 -20
- package/src/types/private.d.ts +33 -1
- package/src/types/synthetic/$lib.md +1 -1
- package/src/utils/error.js +12 -4
- package/src/utils/mime.js +9 -0
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +84 -38
- 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 +434 -269
- package/types/index.d.ts.map +19 -15
- package/src/exports/internal/server.js +0 -22
- /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;
|
|
@@ -263,13 +274,13 @@ export interface Cookies {
|
|
|
263
274
|
/**
|
|
264
275
|
* Gets a cookie that was previously set with `cookies.set`, or from the request headers.
|
|
265
276
|
* @param name the name of the cookie
|
|
266
|
-
* @param opts the options, passed directly to `cookie.
|
|
277
|
+
* @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
|
|
267
278
|
*/
|
|
268
279
|
get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined;
|
|
269
280
|
|
|
270
281
|
/**
|
|
271
282
|
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
|
|
272
|
-
* @param opts the options, passed directly to `cookie.
|
|
283
|
+
* @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
|
|
273
284
|
*/
|
|
274
285
|
getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
|
|
275
286
|
|
|
@@ -281,7 +292,7 @@ export interface Cookies {
|
|
|
281
292
|
* 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
293
|
* @param name the name of the cookie
|
|
283
294
|
* @param value the cookie value
|
|
284
|
-
* @param opts the options passed to `cookie.
|
|
295
|
+
* @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
296
|
*/
|
|
286
297
|
set: (name: string, value: string, opts: import('cookie').SerializeOptions) => void;
|
|
287
298
|
|
|
@@ -292,10 +303,34 @@ export interface Cookies {
|
|
|
292
303
|
*
|
|
293
304
|
* 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
305
|
* @param name the name of the cookie
|
|
295
|
-
* @param opts the options passed to `cookie.
|
|
306
|
+
* @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
307
|
*/
|
|
297
308
|
delete: (name: string, opts: import('cookie').SerializeOptions) => void;
|
|
298
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Parses a single `Set-Cookie` header. This allows you to apply cookies received from an external source:
|
|
312
|
+
*
|
|
313
|
+
* ```js
|
|
314
|
+
* import { getRequestEvent } from '$app/server';
|
|
315
|
+
*
|
|
316
|
+
* export async function GET() {
|
|
317
|
+
* const { cookies } = getRequestEvent();
|
|
318
|
+
*
|
|
319
|
+
* const response = await fetch('...');
|
|
320
|
+
*
|
|
321
|
+
* for (const str of response.headers.getSetCookie()) {
|
|
322
|
+
* const { name, value, ...options } = cookies.parse(str);
|
|
323
|
+
* cookies.set(name, value, { ...options, path: '/' });
|
|
324
|
+
* }
|
|
325
|
+
*
|
|
326
|
+
* // ...
|
|
327
|
+
* }
|
|
328
|
+
* ```
|
|
329
|
+
*
|
|
330
|
+
* 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.
|
|
331
|
+
*/
|
|
332
|
+
parse: typeof import('cookie').parseSetCookie;
|
|
333
|
+
|
|
299
334
|
/**
|
|
300
335
|
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
|
|
301
336
|
*
|
|
@@ -304,7 +339,7 @@ export interface Cookies {
|
|
|
304
339
|
* 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
340
|
* @param name the name of the cookie
|
|
306
341
|
* @param value the cookie value
|
|
307
|
-
* @param opts the options passed to `cookie.
|
|
342
|
+
* @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
343
|
*/
|
|
309
344
|
serialize: (name: string, value: string, opts: import('cookie').SerializeOptions) => string;
|
|
310
345
|
}
|
|
@@ -321,35 +356,37 @@ export interface Emulator {
|
|
|
321
356
|
}
|
|
322
357
|
|
|
323
358
|
export interface KitConfig {
|
|
324
|
-
// TODO: remove this in 4.0
|
|
325
359
|
/**
|
|
326
360
|
* 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
361
|
* @default undefined
|
|
328
|
-
* @deprecated removed in 3.0.0. Adapters should now be passed to the `sveltekit` Vite plugin in `vite.config.js`
|
|
329
362
|
*/
|
|
330
363
|
adapter?: Adapter;
|
|
331
364
|
/**
|
|
332
365
|
* An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
|
|
333
366
|
*
|
|
334
367
|
* ```js
|
|
335
|
-
* /// file:
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
368
|
+
* /// file: vite.config.js
|
|
369
|
+
* import { defineConfig } from 'vite';
|
|
370
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
371
|
+
*
|
|
372
|
+
* export default defineConfig({
|
|
373
|
+
* plugins: [
|
|
374
|
+
* sveltekit({
|
|
375
|
+
* alias: {
|
|
376
|
+
* // this will match a file
|
|
377
|
+
* 'my-file': 'path/to/my-file.js',
|
|
378
|
+
*
|
|
379
|
+
* // this will match a directory and its contents
|
|
380
|
+
* // (`my-directory/x` resolves to `path/to/my-directory/x`)
|
|
381
|
+
* 'my-directory': 'path/to/my-directory',
|
|
382
|
+
*
|
|
383
|
+
* // an alias ending /* will only match
|
|
384
|
+
* // the contents of a directory, not the directory itself
|
|
385
|
+
* 'my-directory/*': 'path/to/my-directory/*'
|
|
386
|
+
* }
|
|
387
|
+
* })
|
|
388
|
+
* ]
|
|
389
|
+
* });
|
|
353
390
|
* ```
|
|
354
391
|
*
|
|
355
392
|
* > [!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 +404,26 @@ export interface KitConfig {
|
|
|
367
404
|
* [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
405
|
*
|
|
369
406
|
* ```js
|
|
370
|
-
* /// file:
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
407
|
+
* /// file: vite.config.js
|
|
408
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
409
|
+
* import { defineConfig } from 'vite';
|
|
410
|
+
*
|
|
411
|
+
* export default defineConfig({
|
|
412
|
+
* plugins: [
|
|
413
|
+
* sveltekit({
|
|
414
|
+
* csp: {
|
|
415
|
+
* directives: {
|
|
416
|
+
* 'script-src': ['self']
|
|
417
|
+
* },
|
|
418
|
+
* // must be specified with either the `report-uri` or `report-to` directives, or both
|
|
419
|
+
* reportOnly: {
|
|
420
|
+
* 'script-src': ['self'],
|
|
421
|
+
* 'report-uri': ['/']
|
|
422
|
+
* }
|
|
423
|
+
* }
|
|
424
|
+
* })
|
|
425
|
+
* ]
|
|
426
|
+
* });
|
|
388
427
|
* ```
|
|
389
428
|
*
|
|
390
429
|
* ...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.
|
|
@@ -459,32 +498,6 @@ export interface KitConfig {
|
|
|
459
498
|
};
|
|
460
499
|
/** Experimental features. Here be dragons. These are not subject to semantic versioning, so breaking changes or removal can happen in any release. */
|
|
461
500
|
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
501
|
/**
|
|
489
502
|
* Whether to enable the experimental remote functions feature. This feature is not yet stable and may be changed or removed at any time.
|
|
490
503
|
* @default false
|
|
@@ -590,7 +603,7 @@ export interface KitConfig {
|
|
|
590
603
|
*/
|
|
591
604
|
inlineStyleThreshold?: number;
|
|
592
605
|
/**
|
|
593
|
-
* An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.
|
|
606
|
+
* 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
607
|
* @default [".js", ".ts"]
|
|
595
608
|
*/
|
|
596
609
|
moduleExtensions?: string[];
|
|
@@ -672,14 +685,27 @@ export interface KitConfig {
|
|
|
672
685
|
*/
|
|
673
686
|
assets?: '' | `http://${string}` | `https://${string}`;
|
|
674
687
|
/**
|
|
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 [`
|
|
688
|
+
* 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
689
|
* @default ""
|
|
677
690
|
*/
|
|
678
691
|
base?: '' | `/${string}`;
|
|
692
|
+
/**
|
|
693
|
+
* The origin of your app, used for CSRF protection and prerendering.
|
|
694
|
+
*
|
|
695
|
+
* 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).
|
|
696
|
+
*
|
|
697
|
+
* 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`.
|
|
698
|
+
*
|
|
699
|
+
* 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.
|
|
700
|
+
*
|
|
701
|
+
* @default undefined
|
|
702
|
+
* @since 3.0
|
|
703
|
+
*/
|
|
704
|
+
origin?: string;
|
|
679
705
|
/**
|
|
680
706
|
* Whether to use relative asset paths.
|
|
681
707
|
*
|
|
682
|
-
* If `true`, `
|
|
708
|
+
* 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
709
|
* If `false`, `%sveltekit.assets%` and references to build artifacts will always be root-relative paths, unless `paths.assets` is an external URL
|
|
684
710
|
*
|
|
685
711
|
* [Single-page app](https://svelte.dev/docs/kit/single-page-apps) fallback pages will always use absolute paths, regardless of this setting.
|
|
@@ -721,23 +747,27 @@ export interface KitConfig {
|
|
|
721
747
|
* - `(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
748
|
*
|
|
723
749
|
* ```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
|
-
* }
|
|
750
|
+
* /// file: vite.config.js
|
|
751
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
752
|
+
* import { defineConfig } from 'vite';
|
|
734
753
|
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
754
|
+
* export default defineConfig({
|
|
755
|
+
* plugins: [
|
|
756
|
+
* sveltekit({
|
|
757
|
+
* prerender: {
|
|
758
|
+
* handleHttpError: ({ path, referrer, message }) => {
|
|
759
|
+
* // ignore deliberate link to shiny 404 page
|
|
760
|
+
* if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
|
|
761
|
+
* return;
|
|
762
|
+
* }
|
|
763
|
+
*
|
|
764
|
+
* // otherwise fail the build
|
|
765
|
+
* throw new Error(message);
|
|
766
|
+
* }
|
|
767
|
+
* }
|
|
768
|
+
* })
|
|
769
|
+
* ]
|
|
770
|
+
* });
|
|
741
771
|
* ```
|
|
742
772
|
*
|
|
743
773
|
* @default "fail"
|
|
@@ -784,10 +814,17 @@ export interface KitConfig {
|
|
|
784
814
|
*/
|
|
785
815
|
handleUnseenRoutes?: PrerenderUnseenRoutesHandlerValue;
|
|
786
816
|
/**
|
|
787
|
-
*
|
|
788
|
-
*
|
|
817
|
+
* 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:...`).
|
|
818
|
+
*
|
|
819
|
+
* - `'fail'` — fail the build
|
|
820
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
821
|
+
* - `'warn'` — continue, but print a warning
|
|
822
|
+
* - `(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
|
|
823
|
+
*
|
|
824
|
+
* @default "fail"
|
|
825
|
+
* @since 2.67.0
|
|
789
826
|
*/
|
|
790
|
-
|
|
827
|
+
handleInvalidUrl?: PrerenderInvalidUrlHandlerValue;
|
|
791
828
|
};
|
|
792
829
|
router?: {
|
|
793
830
|
/**
|
|
@@ -849,6 +886,17 @@ export interface KitConfig {
|
|
|
849
886
|
register?: false;
|
|
850
887
|
}
|
|
851
888
|
);
|
|
889
|
+
/**
|
|
890
|
+
* Options for enabling [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations.
|
|
891
|
+
* @default { server: false }
|
|
892
|
+
*/
|
|
893
|
+
tracing?: {
|
|
894
|
+
/**
|
|
895
|
+
* 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.
|
|
896
|
+
* @default false
|
|
897
|
+
*/
|
|
898
|
+
server?: boolean;
|
|
899
|
+
};
|
|
852
900
|
typescript?: {
|
|
853
901
|
/**
|
|
854
902
|
* A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
|
|
@@ -889,16 +937,20 @@ export interface KitConfig {
|
|
|
889
937
|
* For example, to use the current commit hash, you could do use `git rev-parse HEAD`:
|
|
890
938
|
*
|
|
891
939
|
* ```js
|
|
892
|
-
* /// file:
|
|
940
|
+
* /// file: vite.config.js
|
|
893
941
|
* import * as child_process from 'node:child_process';
|
|
942
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
943
|
+
* import { defineConfig } from 'vite';
|
|
894
944
|
*
|
|
895
|
-
* export default {
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
*
|
|
945
|
+
* export default defineConfig({
|
|
946
|
+
* plugins: [
|
|
947
|
+
* sveltekit({
|
|
948
|
+
* version: {
|
|
949
|
+
* name: child_process.execSync('git rev-parse HEAD').toString().trim()
|
|
950
|
+
* }
|
|
951
|
+
* })
|
|
952
|
+
* ]
|
|
953
|
+
* });
|
|
902
954
|
* ```
|
|
903
955
|
*/
|
|
904
956
|
name?: string;
|
|
@@ -926,13 +978,16 @@ export type Handle = (input: {
|
|
|
926
978
|
*
|
|
927
979
|
* If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
|
|
928
980
|
* Make sure that this function _never_ throws an error.
|
|
981
|
+
*
|
|
982
|
+
* The returned object can include a `status` property to override the HTTP status code used in the response.
|
|
983
|
+
* If omitted, the status defaults to 500.
|
|
929
984
|
*/
|
|
930
985
|
export type HandleServerError = (input: {
|
|
931
986
|
error: unknown;
|
|
932
987
|
event: RequestEvent;
|
|
933
988
|
status: number;
|
|
934
989
|
message: string;
|
|
935
|
-
}) => MaybePromise<void |
|
|
990
|
+
}) => MaybePromise<void | AppErrorWithOptionalStatus>;
|
|
936
991
|
|
|
937
992
|
/**
|
|
938
993
|
* The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleValidationError) hook runs when the argument to a remote function fails validation.
|
|
@@ -940,20 +995,23 @@ export type HandleServerError = (input: {
|
|
|
940
995
|
* It will be called with the validation issues and the event, and must return an object shape that matches `App.Error`.
|
|
941
996
|
*/
|
|
942
997
|
export type HandleValidationError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
|
|
943
|
-
(input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<
|
|
998
|
+
(input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<AppErrorWithOptionalStatus>;
|
|
944
999
|
|
|
945
1000
|
/**
|
|
946
1001
|
* The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError) hook runs when an unexpected error is thrown while navigating.
|
|
947
1002
|
*
|
|
948
1003
|
* If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
|
|
949
1004
|
* Make sure that this function _never_ throws an error.
|
|
1005
|
+
*
|
|
1006
|
+
* The returned object can include a `status` property to override the HTTP status code used in the response.
|
|
1007
|
+
* If omitted, the status defaults to 500.
|
|
950
1008
|
*/
|
|
951
1009
|
export type HandleClientError = (input: {
|
|
952
1010
|
error: unknown;
|
|
953
1011
|
event: NavigationEvent;
|
|
954
1012
|
status: number;
|
|
955
1013
|
message: string;
|
|
956
|
-
}) => MaybePromise<void |
|
|
1014
|
+
}) => MaybePromise<void | AppErrorWithOptionalStatus>;
|
|
957
1015
|
|
|
958
1016
|
/**
|
|
959
1017
|
* 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 +1071,7 @@ export type Transport = Record<string, Transporter>;
|
|
|
1013
1071
|
*/
|
|
1014
1072
|
export interface Transporter<
|
|
1015
1073
|
T = any,
|
|
1016
|
-
U =
|
|
1074
|
+
U = any /* minus falsy values, but we can't properly express that */
|
|
1017
1075
|
> {
|
|
1018
1076
|
encode: (value: T) => false | U;
|
|
1019
1077
|
decode: (data: U) => T;
|
|
@@ -1222,14 +1280,24 @@ export interface NavigationTarget<
|
|
|
1222
1280
|
/**
|
|
1223
1281
|
* - `enter`: The app has hydrated/started
|
|
1224
1282
|
* - `form`: The user submitted a `<form method="GET">`
|
|
1283
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1225
1284
|
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1226
1285
|
* - `link`: Navigation was triggered by a link click
|
|
1227
|
-
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1228
1286
|
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1229
1287
|
*/
|
|
1230
1288
|
export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
1231
1289
|
|
|
1232
1290
|
export interface NavigationBase {
|
|
1291
|
+
/**
|
|
1292
|
+
* The type of navigation:
|
|
1293
|
+
* - `enter`: The app has hydrated/started
|
|
1294
|
+
* - `form`: The user submitted a `<form method="GET">`
|
|
1295
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1296
|
+
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1297
|
+
* - `link`: Navigation was triggered by a link click
|
|
1298
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1299
|
+
*/
|
|
1300
|
+
type: NavigationType;
|
|
1233
1301
|
/**
|
|
1234
1302
|
* Where navigation was triggered from
|
|
1235
1303
|
*/
|
|
@@ -1249,11 +1317,10 @@ export interface NavigationBase {
|
|
|
1249
1317
|
complete: Promise<void>;
|
|
1250
1318
|
}
|
|
1251
1319
|
|
|
1320
|
+
/**
|
|
1321
|
+
* The navigation that occurs when the app starts/hydrates
|
|
1322
|
+
*/
|
|
1252
1323
|
export interface NavigationEnter extends NavigationBase {
|
|
1253
|
-
/**
|
|
1254
|
-
* The type of navigation:
|
|
1255
|
-
* - `enter`: The app has hydrated/started
|
|
1256
|
-
*/
|
|
1257
1324
|
type: 'enter';
|
|
1258
1325
|
|
|
1259
1326
|
/**
|
|
@@ -1269,27 +1336,24 @@ export interface NavigationEnter extends NavigationBase {
|
|
|
1269
1336
|
|
|
1270
1337
|
export type NavigationExternal = NavigationGoto | NavigationLeave;
|
|
1271
1338
|
|
|
1339
|
+
/**
|
|
1340
|
+
* A navigation triggered by a `goto(...)` call or a redirect
|
|
1341
|
+
*/
|
|
1272
1342
|
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
1343
|
type: 'goto';
|
|
1278
1344
|
}
|
|
1279
1345
|
|
|
1346
|
+
/**
|
|
1347
|
+
* A navigation triggered by the tab being closed, or the user navigating to a different document
|
|
1348
|
+
*/
|
|
1280
1349
|
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
1350
|
type: 'leave';
|
|
1286
1351
|
}
|
|
1287
1352
|
|
|
1353
|
+
/**
|
|
1354
|
+
* A navigation triggered by a `<form method="GET">`
|
|
1355
|
+
*/
|
|
1288
1356
|
export interface NavigationFormSubmit extends NavigationBase {
|
|
1289
|
-
/**
|
|
1290
|
-
* The type of navigation:
|
|
1291
|
-
* - `form`: The user submitted a `<form method="GET">`
|
|
1292
|
-
*/
|
|
1293
1357
|
type: 'form';
|
|
1294
1358
|
|
|
1295
1359
|
/**
|
|
@@ -1298,11 +1362,10 @@ export interface NavigationFormSubmit extends NavigationBase {
|
|
|
1298
1362
|
event: SubmitEvent;
|
|
1299
1363
|
}
|
|
1300
1364
|
|
|
1365
|
+
/**
|
|
1366
|
+
* A navigation triggered by back/forward navigation
|
|
1367
|
+
*/
|
|
1301
1368
|
export interface NavigationPopState extends NavigationBase {
|
|
1302
|
-
/**
|
|
1303
|
-
* The type of navigation:
|
|
1304
|
-
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1305
|
-
*/
|
|
1306
1369
|
type: 'popstate';
|
|
1307
1370
|
|
|
1308
1371
|
/**
|
|
@@ -1316,11 +1379,10 @@ export interface NavigationPopState extends NavigationBase {
|
|
|
1316
1379
|
event: PopStateEvent;
|
|
1317
1380
|
}
|
|
1318
1381
|
|
|
1382
|
+
/**
|
|
1383
|
+
* A navigation triggered by a link click
|
|
1384
|
+
*/
|
|
1319
1385
|
export interface NavigationLink extends NavigationBase {
|
|
1320
|
-
/**
|
|
1321
|
-
* The type of navigation:
|
|
1322
|
-
* - `link`: Navigation was triggered by a link click
|
|
1323
|
-
*/
|
|
1324
1386
|
type: 'link';
|
|
1325
1387
|
|
|
1326
1388
|
/**
|
|
@@ -1368,7 +1430,7 @@ export type AfterNavigate = (Navigation | NavigationEnter) & {
|
|
|
1368
1430
|
};
|
|
1369
1431
|
|
|
1370
1432
|
/**
|
|
1371
|
-
* The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object
|
|
1433
|
+
* The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object.
|
|
1372
1434
|
*/
|
|
1373
1435
|
export interface Page<
|
|
1374
1436
|
Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
|
|
@@ -1416,7 +1478,64 @@ export interface Page<
|
|
|
1416
1478
|
/**
|
|
1417
1479
|
* The shape of a param matcher. See [matching](https://svelte.dev/docs/kit/advanced-routing#Matching) for more info.
|
|
1418
1480
|
*/
|
|
1419
|
-
export type ParamMatcher =
|
|
1481
|
+
export type ParamMatcher<Output = any> = StandardSchemaV1<string, Output>;
|
|
1482
|
+
|
|
1483
|
+
/**
|
|
1484
|
+
* A value that can be parsed from a URL param and losslessly encoded with `String(...)`.
|
|
1485
|
+
*/
|
|
1486
|
+
export type ParamValue = string | number | boolean | bigint;
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
|
|
1490
|
+
*/
|
|
1491
|
+
export type ParamDefinition =
|
|
1492
|
+
| ((param: string) => ParamValue | undefined)
|
|
1493
|
+
| StandardSchemaV1<string, ParamValue>;
|
|
1494
|
+
|
|
1495
|
+
/**
|
|
1496
|
+
* The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
|
|
1497
|
+
*/
|
|
1498
|
+
export type DefinedParams<T extends Record<string, ParamDefinition>> = {
|
|
1499
|
+
readonly [K in keyof T]: ParamEntry<T[K]>;
|
|
1500
|
+
};
|
|
1501
|
+
|
|
1502
|
+
/**
|
|
1503
|
+
* Normalizes a property of defineParams (schema or function) to standard schema.
|
|
1504
|
+
*/
|
|
1505
|
+
type ParamEntry<M> =
|
|
1506
|
+
M extends StandardSchemaV1<any, any>
|
|
1507
|
+
? StandardSchemaV1.InferOutput<M> extends ParamValue
|
|
1508
|
+
? StandardSchemaV1<any, M>
|
|
1509
|
+
: StandardSchemaV1<any, never>
|
|
1510
|
+
: M extends (param: string) => infer R
|
|
1511
|
+
? Exclude<R, undefined> extends ParamValue
|
|
1512
|
+
? StandardSchemaV1<any, Exclude<R, undefined>>
|
|
1513
|
+
: StandardSchemaV1<any, never>
|
|
1514
|
+
: never;
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* Extracts the param type from a matcher.
|
|
1518
|
+
*/
|
|
1519
|
+
export type MatcherParam<M extends StandardSchemaV1<any, any>> =
|
|
1520
|
+
M extends StandardSchemaV1<any, infer Inner>
|
|
1521
|
+
? Inner extends ParamValue
|
|
1522
|
+
? Inner
|
|
1523
|
+
: Inner extends StandardSchemaV1<any, any>
|
|
1524
|
+
? StandardSchemaV1.InferOutput<Inner> extends ParamValue
|
|
1525
|
+
? StandardSchemaV1.InferOutput<Inner>
|
|
1526
|
+
: never
|
|
1527
|
+
: never
|
|
1528
|
+
: never;
|
|
1529
|
+
|
|
1530
|
+
/**
|
|
1531
|
+
* Define [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching) for your app.
|
|
1532
|
+
*
|
|
1533
|
+
* @template T
|
|
1534
|
+
* @param definitions
|
|
1535
|
+
*/
|
|
1536
|
+
export function defineParams<T extends Record<string, ParamDefinition>>(
|
|
1537
|
+
definitions: T
|
|
1538
|
+
): DefinedParams<T>;
|
|
1420
1539
|
|
|
1421
1540
|
/**
|
|
1422
1541
|
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
@@ -1509,6 +1628,10 @@ export interface RequestEvent<
|
|
|
1509
1628
|
locals: App.Locals;
|
|
1510
1629
|
/**
|
|
1511
1630
|
* The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
1631
|
+
*
|
|
1632
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1633
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1634
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1512
1635
|
*/
|
|
1513
1636
|
params: Params;
|
|
1514
1637
|
/**
|
|
@@ -1525,6 +1648,10 @@ export interface RequestEvent<
|
|
|
1525
1648
|
route: {
|
|
1526
1649
|
/**
|
|
1527
1650
|
* 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.
|
|
1651
|
+
*
|
|
1652
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1653
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1654
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1528
1655
|
*/
|
|
1529
1656
|
id: RouteId;
|
|
1530
1657
|
};
|
|
@@ -1553,6 +1680,10 @@ export interface RequestEvent<
|
|
|
1553
1680
|
setHeaders: (headers: Record<string, string>) => void;
|
|
1554
1681
|
/**
|
|
1555
1682
|
* The requested URL.
|
|
1683
|
+
*
|
|
1684
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1685
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1686
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1556
1687
|
*/
|
|
1557
1688
|
url: URL;
|
|
1558
1689
|
/**
|
|
@@ -1649,7 +1780,7 @@ export interface ServerInitOptions {
|
|
|
1649
1780
|
export interface SSRManifest {
|
|
1650
1781
|
appDir: string;
|
|
1651
1782
|
appPath: string;
|
|
1652
|
-
/** Static files from `
|
|
1783
|
+
/** Static files from `config.files.assets` and the service worker (if any). */
|
|
1653
1784
|
assets: Set<string>;
|
|
1654
1785
|
mimeTypes: Record<string, string>;
|
|
1655
1786
|
|
|
@@ -1793,7 +1924,7 @@ export type ActionResult<
|
|
|
1793
1924
|
| { type: 'success'; status: number; data?: Success }
|
|
1794
1925
|
| { type: 'failure'; status: number; data?: Failure }
|
|
1795
1926
|
| { type: 'redirect'; status: number; location: string }
|
|
1796
|
-
| { type: 'error'; status?: number; error:
|
|
1927
|
+
| { type: 'error'; status?: number; error: App.Error };
|
|
1797
1928
|
|
|
1798
1929
|
/**
|
|
1799
1930
|
* The object returned by the [`error`](https://svelte.dev/docs/kit/@sveltejs-kit#error) function.
|
|
@@ -1942,6 +2073,10 @@ type RemoteFormFieldMethods<T> = {
|
|
|
1942
2073
|
value(): DeepPartial<T>;
|
|
1943
2074
|
/** Set the values that will be submitted */
|
|
1944
2075
|
set(input: DeepPartial<T>): DeepPartial<T>;
|
|
2076
|
+
/** Whether the field or any nested field has been interacted with since the form was mounted */
|
|
2077
|
+
touched(): boolean;
|
|
2078
|
+
/** Whether the field or any nested field has been edited since the form was mounted */
|
|
2079
|
+
dirty(): boolean;
|
|
1945
2080
|
/** Validation issues, if any */
|
|
1946
2081
|
issues(): RemoteFormIssue[] | undefined;
|
|
1947
2082
|
};
|
|
@@ -2056,7 +2191,7 @@ type RecursiveFormFields = RemoteFormFieldContainer<any> & {
|
|
|
2056
2191
|
type MaybeArray<T> = T | T[];
|
|
2057
2192
|
|
|
2058
2193
|
export interface RemoteFormInput {
|
|
2059
|
-
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput
|
|
2194
|
+
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
|
|
2060
2195
|
}
|
|
2061
2196
|
|
|
2062
2197
|
export interface RemoteFormIssue {
|
|
@@ -2102,6 +2237,24 @@ export interface ValidationError {
|
|
|
2102
2237
|
issues: StandardSchemaV1.Issue[];
|
|
2103
2238
|
}
|
|
2104
2239
|
|
|
2240
|
+
/**
|
|
2241
|
+
* The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2242
|
+
*/
|
|
2243
|
+
export type RemoteFormEnhanceInstance<
|
|
2244
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
2245
|
+
Output = any
|
|
2246
|
+
> = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
|
|
2247
|
+
readonly element: HTMLFormElement;
|
|
2248
|
+
};
|
|
2249
|
+
|
|
2250
|
+
/**
|
|
2251
|
+
* The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2252
|
+
*/
|
|
2253
|
+
export type RemoteFormEnhanceCallback<
|
|
2254
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
2255
|
+
Output = any
|
|
2256
|
+
> = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
|
|
2257
|
+
|
|
2105
2258
|
/**
|
|
2106
2259
|
* The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2107
2260
|
*/
|
|
@@ -2118,13 +2271,7 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2118
2271
|
updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
|
|
2119
2272
|
};
|
|
2120
2273
|
/** 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
|
-
): {
|
|
2274
|
+
enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
|
|
2128
2275
|
method: 'POST';
|
|
2129
2276
|
action: string;
|
|
2130
2277
|
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
@@ -2148,8 +2295,13 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2148
2295
|
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
|
|
2149
2296
|
/** Validate the form contents programmatically */
|
|
2150
2297
|
validate(options?: {
|
|
2151
|
-
/**
|
|
2152
|
-
|
|
2298
|
+
/**
|
|
2299
|
+
* Set this to `true` to also show validation issues of fields that haven't yet been
|
|
2300
|
+
* edited and blurred. This option is ignored for forms that have previously been
|
|
2301
|
+
* submitted, in which case all fields are always subject to validation
|
|
2302
|
+
* (unless the form is reset, at which point it is treated as pristine)
|
|
2303
|
+
*/
|
|
2304
|
+
all?: boolean;
|
|
2153
2305
|
/** Set this to `true` to only run the `preflight` validation. */
|
|
2154
2306
|
preflightOnly?: boolean;
|
|
2155
2307
|
}): Promise<void>;
|
|
@@ -2157,6 +2309,8 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2157
2309
|
get result(): Output | undefined;
|
|
2158
2310
|
/** The number of pending submissions */
|
|
2159
2311
|
get pending(): number;
|
|
2312
|
+
/** True if the form has been submitted at least once, and hasn't been reset since */
|
|
2313
|
+
get submitted(): boolean;
|
|
2160
2314
|
/** Access form fields using object notation */
|
|
2161
2315
|
fields: RemoteFormFieldsRoot<Input>;
|
|
2162
2316
|
};
|
|
@@ -2180,8 +2334,8 @@ export type RemoteQueryUpdate =
|
|
|
2180
2334
|
| RemoteQueryOverride;
|
|
2181
2335
|
|
|
2182
2336
|
export type RemoteResource<T> = Promise<T> & {
|
|
2183
|
-
/** The error in case the query fails.
|
|
2184
|
-
get error():
|
|
2337
|
+
/** The error in case the query fails. */
|
|
2338
|
+
get error(): App.Error | undefined;
|
|
2185
2339
|
/** `true` before the first result is available and during refreshes */
|
|
2186
2340
|
get loading(): boolean;
|
|
2187
2341
|
} & (
|