@sveltejs/kit 3.0.0-next.4 → 3.0.0-next.6
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 +17 -17
- package/src/core/adapt/builder.js +18 -4
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +64 -5
- package/src/core/config/options.js +73 -21
- package/src/core/env.js +35 -4
- 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 +23 -5
- package/src/core/sync/write_client_manifest.js +7 -0
- package/src/core/sync/write_server.js +13 -10
- package/src/core/sync/write_tsconfig.js +2 -4
- package/src/exports/index.js +32 -10
- package/src/exports/internal/env.js +1 -1
- package/src/exports/internal/index.js +6 -5
- package/src/exports/node/index.js +57 -6
- package/src/exports/public.d.ts +218 -114
- package/src/exports/vite/build/build_server.js +6 -1
- package/src/exports/vite/dev/index.js +10 -20
- package/src/exports/vite/index.js +306 -222
- package/src/exports/vite/preview/index.js +15 -7
- package/src/exports/vite/utils.js +8 -10
- 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 +1 -3
- package/src/runtime/app/paths/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +7 -3
- package/src/runtime/app/server/remote/form.js +10 -3
- package/src/runtime/app/server/remote/query.js +3 -6
- package/src/runtime/app/server/remote/requested.js +8 -4
- package/src/runtime/app/server/remote/shared.js +5 -7
- package/src/runtime/client/client.js +184 -93
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/remote-functions/form.svelte.js +134 -24
- package/src/runtime/client/remote-functions/prerender.svelte.js +8 -2
- package/src/runtime/client/remote-functions/query/index.js +3 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +9 -2
- package/src/runtime/client/remote-functions/query-batch.svelte.js +4 -3
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +26 -9
- package/src/runtime/client/remote-functions/shared.svelte.js +17 -7
- package/src/runtime/client/types.d.ts +9 -1
- package/src/runtime/client/utils.js +1 -1
- package/src/runtime/form-utils.js +84 -16
- 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 +1 -1
- package/src/runtime/server/page/actions.js +41 -26
- package/src/runtime/server/page/index.js +2 -1
- package/src/runtime/server/page/render.js +21 -23
- package/src/runtime/server/page/respond_with_error.js +7 -8
- package/src/runtime/server/remote.js +64 -27
- package/src/runtime/server/respond.js +81 -50
- package/src/runtime/server/utils.js +7 -7
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/types/ambient.d.ts +5 -4
- package/src/types/global-private.d.ts +4 -4
- package/src/types/internal.d.ts +8 -10
- package/src/types/private.d.ts +33 -1
- package/src/types/synthetic/$lib.md +1 -1
- package/src/utils/error.js +11 -3
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/url.js +99 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +340 -186
- package/types/index.d.ts.map +10 -9
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,
|
|
@@ -33,6 +34,8 @@ export { PrerenderOption } from '../types/private.js';
|
|
|
33
34
|
// @ts-ignore this is an optional peer dependency so could be missing. Written like this so dts-buddy preserves the ts-ignore
|
|
34
35
|
type Span = import('@opentelemetry/api').Span;
|
|
35
36
|
|
|
37
|
+
type AppErrorWithOptionalStatus = Omit<App.Error, 'status'> & { status?: App.Error['status'] };
|
|
38
|
+
|
|
36
39
|
/**
|
|
37
40
|
* [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
41
|
*/
|
|
@@ -115,7 +118,7 @@ export interface Builder {
|
|
|
115
118
|
/** Create `dir` and any required parent directories. */
|
|
116
119
|
mkdirp: (dir: string) => void;
|
|
117
120
|
|
|
118
|
-
/** The fully resolved
|
|
121
|
+
/** The fully resolved SvelteKit config. */
|
|
119
122
|
config: ValidatedConfig;
|
|
120
123
|
/** Information about prerendered pages and assets, if any. */
|
|
121
124
|
prerendered: Prerendered;
|
|
@@ -263,13 +266,13 @@ export interface Cookies {
|
|
|
263
266
|
/**
|
|
264
267
|
* Gets a cookie that was previously set with `cookies.set`, or from the request headers.
|
|
265
268
|
* @param name the name of the cookie
|
|
266
|
-
* @param opts the options, passed directly to `cookie.
|
|
269
|
+
* @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
|
|
267
270
|
*/
|
|
268
271
|
get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined;
|
|
269
272
|
|
|
270
273
|
/**
|
|
271
274
|
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
|
|
272
|
-
* @param opts the options, passed directly to `cookie.
|
|
275
|
+
* @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
|
|
273
276
|
*/
|
|
274
277
|
getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
|
|
275
278
|
|
|
@@ -281,7 +284,7 @@ export interface Cookies {
|
|
|
281
284
|
* 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
285
|
* @param name the name of the cookie
|
|
283
286
|
* @param value the cookie value
|
|
284
|
-
* @param opts the options passed to `cookie.
|
|
287
|
+
* @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
288
|
*/
|
|
286
289
|
set: (name: string, value: string, opts: import('cookie').SerializeOptions) => void;
|
|
287
290
|
|
|
@@ -292,10 +295,34 @@ export interface Cookies {
|
|
|
292
295
|
*
|
|
293
296
|
* 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
297
|
* @param name the name of the cookie
|
|
295
|
-
* @param opts the options passed to `cookie.
|
|
298
|
+
* @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
299
|
*/
|
|
297
300
|
delete: (name: string, opts: import('cookie').SerializeOptions) => void;
|
|
298
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Parses a single `Set-Cookie` header. This allows you to apply cookies received from an external source:
|
|
304
|
+
*
|
|
305
|
+
* ```js
|
|
306
|
+
* import { getRequestEvent } from '$app/server';
|
|
307
|
+
*
|
|
308
|
+
* export async function GET() {
|
|
309
|
+
* const { cookies } = getRequestEvent();
|
|
310
|
+
*
|
|
311
|
+
* const response = await fetch('...');
|
|
312
|
+
*
|
|
313
|
+
* for (const str of response.headers.getSetCookie()) {
|
|
314
|
+
* const { name, value, ...options } = cookies.parse(str);
|
|
315
|
+
* cookies.set(name, value, { ...options, path: '/' });
|
|
316
|
+
* }
|
|
317
|
+
*
|
|
318
|
+
* // ...
|
|
319
|
+
* }
|
|
320
|
+
* ```
|
|
321
|
+
*
|
|
322
|
+
* 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.
|
|
323
|
+
*/
|
|
324
|
+
parse: typeof import('cookie').parseSetCookie;
|
|
325
|
+
|
|
299
326
|
/**
|
|
300
327
|
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
|
|
301
328
|
*
|
|
@@ -304,7 +331,7 @@ export interface Cookies {
|
|
|
304
331
|
* 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
332
|
* @param name the name of the cookie
|
|
306
333
|
* @param value the cookie value
|
|
307
|
-
* @param opts the options passed to `cookie.
|
|
334
|
+
* @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
335
|
*/
|
|
309
336
|
serialize: (name: string, value: string, opts: import('cookie').SerializeOptions) => string;
|
|
310
337
|
}
|
|
@@ -321,35 +348,37 @@ export interface Emulator {
|
|
|
321
348
|
}
|
|
322
349
|
|
|
323
350
|
export interface KitConfig {
|
|
324
|
-
// TODO: remove this in 4.0
|
|
325
351
|
/**
|
|
326
352
|
* 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
353
|
* @default undefined
|
|
328
|
-
* @deprecated removed in 3.0.0. Adapters should now be passed to the `sveltekit` Vite plugin in `vite.config.js`
|
|
329
354
|
*/
|
|
330
355
|
adapter?: Adapter;
|
|
331
356
|
/**
|
|
332
357
|
* An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
|
|
333
358
|
*
|
|
334
359
|
* ```js
|
|
335
|
-
* /// file:
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
360
|
+
* /// file: vite.config.js
|
|
361
|
+
* import { defineConfig } from 'vite';
|
|
362
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
363
|
+
*
|
|
364
|
+
* export default defineConfig({
|
|
365
|
+
* plugins: [
|
|
366
|
+
* sveltekit({
|
|
367
|
+
* alias: {
|
|
368
|
+
* // this will match a file
|
|
369
|
+
* 'my-file': 'path/to/my-file.js',
|
|
370
|
+
*
|
|
371
|
+
* // this will match a directory and its contents
|
|
372
|
+
* // (`my-directory/x` resolves to `path/to/my-directory/x`)
|
|
373
|
+
* 'my-directory': 'path/to/my-directory',
|
|
374
|
+
*
|
|
375
|
+
* // an alias ending /* will only match
|
|
376
|
+
* // the contents of a directory, not the directory itself
|
|
377
|
+
* 'my-directory/*': 'path/to/my-directory/*'
|
|
378
|
+
* }
|
|
379
|
+
* })
|
|
380
|
+
* ]
|
|
381
|
+
* });
|
|
353
382
|
* ```
|
|
354
383
|
*
|
|
355
384
|
* > [!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 +396,26 @@ export interface KitConfig {
|
|
|
367
396
|
* [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
397
|
*
|
|
369
398
|
* ```js
|
|
370
|
-
* /// file:
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
399
|
+
* /// file: vite.config.js
|
|
400
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
401
|
+
* import { defineConfig } from 'vite';
|
|
402
|
+
*
|
|
403
|
+
* export default defineConfig({
|
|
404
|
+
* plugins: [
|
|
405
|
+
* sveltekit({
|
|
406
|
+
* csp: {
|
|
407
|
+
* directives: {
|
|
408
|
+
* 'script-src': ['self']
|
|
409
|
+
* },
|
|
410
|
+
* // must be specified with either the `report-uri` or `report-to` directives, or both
|
|
411
|
+
* reportOnly: {
|
|
412
|
+
* 'script-src': ['self'],
|
|
413
|
+
* 'report-uri': ['/']
|
|
414
|
+
* }
|
|
415
|
+
* }
|
|
416
|
+
* })
|
|
417
|
+
* ]
|
|
418
|
+
* });
|
|
388
419
|
* ```
|
|
389
420
|
*
|
|
390
421
|
* ...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.
|
|
@@ -590,7 +621,7 @@ export interface KitConfig {
|
|
|
590
621
|
*/
|
|
591
622
|
inlineStyleThreshold?: number;
|
|
592
623
|
/**
|
|
593
|
-
* An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.
|
|
624
|
+
* 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
625
|
* @default [".js", ".ts"]
|
|
595
626
|
*/
|
|
596
627
|
moduleExtensions?: string[];
|
|
@@ -672,14 +703,27 @@ export interface KitConfig {
|
|
|
672
703
|
*/
|
|
673
704
|
assets?: '' | `http://${string}` | `https://${string}`;
|
|
674
705
|
/**
|
|
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 [`
|
|
706
|
+
* 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
707
|
* @default ""
|
|
677
708
|
*/
|
|
678
709
|
base?: '' | `/${string}`;
|
|
710
|
+
/**
|
|
711
|
+
* The origin of your app, used for CSRF protection and prerendering.
|
|
712
|
+
*
|
|
713
|
+
* 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).
|
|
714
|
+
*
|
|
715
|
+
* 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`.
|
|
716
|
+
*
|
|
717
|
+
* 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.
|
|
718
|
+
*
|
|
719
|
+
* @default undefined
|
|
720
|
+
* @since 3.0
|
|
721
|
+
*/
|
|
722
|
+
origin?: `http://${string}` | `https://${string}`;
|
|
679
723
|
/**
|
|
680
724
|
* Whether to use relative asset paths.
|
|
681
725
|
*
|
|
682
|
-
* If `true`, `
|
|
726
|
+
* 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
727
|
* If `false`, `%sveltekit.assets%` and references to build artifacts will always be root-relative paths, unless `paths.assets` is an external URL
|
|
684
728
|
*
|
|
685
729
|
* [Single-page app](https://svelte.dev/docs/kit/single-page-apps) fallback pages will always use absolute paths, regardless of this setting.
|
|
@@ -721,23 +765,27 @@ export interface KitConfig {
|
|
|
721
765
|
* - `(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
766
|
*
|
|
723
767
|
* ```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
|
-
* }
|
|
768
|
+
* /// file: vite.config.js
|
|
769
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
770
|
+
* import { defineConfig } from 'vite';
|
|
734
771
|
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
772
|
+
* export default defineConfig({
|
|
773
|
+
* plugins: [
|
|
774
|
+
* sveltekit({
|
|
775
|
+
* prerender: {
|
|
776
|
+
* handleHttpError: ({ path, referrer, message }) => {
|
|
777
|
+
* // ignore deliberate link to shiny 404 page
|
|
778
|
+
* if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
|
|
779
|
+
* return;
|
|
780
|
+
* }
|
|
781
|
+
*
|
|
782
|
+
* // otherwise fail the build
|
|
783
|
+
* throw new Error(message);
|
|
784
|
+
* }
|
|
785
|
+
* }
|
|
786
|
+
* })
|
|
787
|
+
* ]
|
|
788
|
+
* });
|
|
741
789
|
* ```
|
|
742
790
|
*
|
|
743
791
|
* @default "fail"
|
|
@@ -784,10 +832,17 @@ export interface KitConfig {
|
|
|
784
832
|
*/
|
|
785
833
|
handleUnseenRoutes?: PrerenderUnseenRoutesHandlerValue;
|
|
786
834
|
/**
|
|
787
|
-
*
|
|
788
|
-
*
|
|
835
|
+
* 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:...`).
|
|
836
|
+
*
|
|
837
|
+
* - `'fail'` — fail the build
|
|
838
|
+
* - `'ignore'` - silently ignore the failure and continue
|
|
839
|
+
* - `'warn'` — continue, but print a warning
|
|
840
|
+
* - `(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
|
|
841
|
+
*
|
|
842
|
+
* @default "fail"
|
|
843
|
+
* @since 2.67.0
|
|
789
844
|
*/
|
|
790
|
-
|
|
845
|
+
handleInvalidUrl?: PrerenderInvalidUrlHandlerValue;
|
|
791
846
|
};
|
|
792
847
|
router?: {
|
|
793
848
|
/**
|
|
@@ -889,16 +944,20 @@ export interface KitConfig {
|
|
|
889
944
|
* For example, to use the current commit hash, you could do use `git rev-parse HEAD`:
|
|
890
945
|
*
|
|
891
946
|
* ```js
|
|
892
|
-
* /// file:
|
|
947
|
+
* /// file: vite.config.js
|
|
893
948
|
* import * as child_process from 'node:child_process';
|
|
949
|
+
* import { sveltekit } from '@sveltejs/kit/vite';
|
|
950
|
+
* import { defineConfig } from 'vite';
|
|
894
951
|
*
|
|
895
|
-
* export default {
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
*
|
|
952
|
+
* export default defineConfig({
|
|
953
|
+
* plugins: [
|
|
954
|
+
* sveltekit({
|
|
955
|
+
* version: {
|
|
956
|
+
* name: child_process.execSync('git rev-parse HEAD').toString().trim()
|
|
957
|
+
* }
|
|
958
|
+
* })
|
|
959
|
+
* ]
|
|
960
|
+
* });
|
|
902
961
|
* ```
|
|
903
962
|
*/
|
|
904
963
|
name?: string;
|
|
@@ -926,13 +985,16 @@ export type Handle = (input: {
|
|
|
926
985
|
*
|
|
927
986
|
* If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
|
|
928
987
|
* Make sure that this function _never_ throws an error.
|
|
988
|
+
*
|
|
989
|
+
* The returned object can include a `status` property to override the HTTP status code used in the response.
|
|
990
|
+
* If omitted, the status defaults to 500.
|
|
929
991
|
*/
|
|
930
992
|
export type HandleServerError = (input: {
|
|
931
993
|
error: unknown;
|
|
932
994
|
event: RequestEvent;
|
|
933
995
|
status: number;
|
|
934
996
|
message: string;
|
|
935
|
-
}) => MaybePromise<void |
|
|
997
|
+
}) => MaybePromise<void | AppErrorWithOptionalStatus>;
|
|
936
998
|
|
|
937
999
|
/**
|
|
938
1000
|
* The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleValidationError) hook runs when the argument to a remote function fails validation.
|
|
@@ -940,20 +1002,23 @@ export type HandleServerError = (input: {
|
|
|
940
1002
|
* It will be called with the validation issues and the event, and must return an object shape that matches `App.Error`.
|
|
941
1003
|
*/
|
|
942
1004
|
export type HandleValidationError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
|
|
943
|
-
(input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<
|
|
1005
|
+
(input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<AppErrorWithOptionalStatus>;
|
|
944
1006
|
|
|
945
1007
|
/**
|
|
946
1008
|
* The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError) hook runs when an unexpected error is thrown while navigating.
|
|
947
1009
|
*
|
|
948
1010
|
* If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
|
|
949
1011
|
* Make sure that this function _never_ throws an error.
|
|
1012
|
+
*
|
|
1013
|
+
* The returned object can include a `status` property to override the HTTP status code used in the response.
|
|
1014
|
+
* If omitted, the status defaults to 500.
|
|
950
1015
|
*/
|
|
951
1016
|
export type HandleClientError = (input: {
|
|
952
1017
|
error: unknown;
|
|
953
1018
|
event: NavigationEvent;
|
|
954
1019
|
status: number;
|
|
955
1020
|
message: string;
|
|
956
|
-
}) => MaybePromise<void |
|
|
1021
|
+
}) => MaybePromise<void | AppErrorWithOptionalStatus>;
|
|
957
1022
|
|
|
958
1023
|
/**
|
|
959
1024
|
* 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`.
|
|
@@ -1222,14 +1287,24 @@ export interface NavigationTarget<
|
|
|
1222
1287
|
/**
|
|
1223
1288
|
* - `enter`: The app has hydrated/started
|
|
1224
1289
|
* - `form`: The user submitted a `<form method="GET">`
|
|
1290
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1225
1291
|
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1226
1292
|
* - `link`: Navigation was triggered by a link click
|
|
1227
|
-
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1228
1293
|
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1229
1294
|
*/
|
|
1230
1295
|
export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
1231
1296
|
|
|
1232
1297
|
export interface NavigationBase {
|
|
1298
|
+
/**
|
|
1299
|
+
* The type of navigation:
|
|
1300
|
+
* - `enter`: The app has hydrated/started
|
|
1301
|
+
* - `form`: The user submitted a `<form method="GET">`
|
|
1302
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1303
|
+
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1304
|
+
* - `link`: Navigation was triggered by a link click
|
|
1305
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1306
|
+
*/
|
|
1307
|
+
type: NavigationType;
|
|
1233
1308
|
/**
|
|
1234
1309
|
* Where navigation was triggered from
|
|
1235
1310
|
*/
|
|
@@ -1249,11 +1324,10 @@ export interface NavigationBase {
|
|
|
1249
1324
|
complete: Promise<void>;
|
|
1250
1325
|
}
|
|
1251
1326
|
|
|
1327
|
+
/**
|
|
1328
|
+
* The navigation that occurs when the app starts/hydrates
|
|
1329
|
+
*/
|
|
1252
1330
|
export interface NavigationEnter extends NavigationBase {
|
|
1253
|
-
/**
|
|
1254
|
-
* The type of navigation:
|
|
1255
|
-
* - `enter`: The app has hydrated/started
|
|
1256
|
-
*/
|
|
1257
1331
|
type: 'enter';
|
|
1258
1332
|
|
|
1259
1333
|
/**
|
|
@@ -1269,27 +1343,24 @@ export interface NavigationEnter extends NavigationBase {
|
|
|
1269
1343
|
|
|
1270
1344
|
export type NavigationExternal = NavigationGoto | NavigationLeave;
|
|
1271
1345
|
|
|
1346
|
+
/**
|
|
1347
|
+
* A navigation triggered by a `goto(...)` call or a redirect
|
|
1348
|
+
*/
|
|
1272
1349
|
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
1350
|
type: 'goto';
|
|
1278
1351
|
}
|
|
1279
1352
|
|
|
1353
|
+
/**
|
|
1354
|
+
* A navigation triggered by the tab being closed, or the user navigating to a different document
|
|
1355
|
+
*/
|
|
1280
1356
|
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
1357
|
type: 'leave';
|
|
1286
1358
|
}
|
|
1287
1359
|
|
|
1360
|
+
/**
|
|
1361
|
+
* A navigation triggered by a `<form method="GET">`
|
|
1362
|
+
*/
|
|
1288
1363
|
export interface NavigationFormSubmit extends NavigationBase {
|
|
1289
|
-
/**
|
|
1290
|
-
* The type of navigation:
|
|
1291
|
-
* - `form`: The user submitted a `<form method="GET">`
|
|
1292
|
-
*/
|
|
1293
1364
|
type: 'form';
|
|
1294
1365
|
|
|
1295
1366
|
/**
|
|
@@ -1298,11 +1369,10 @@ export interface NavigationFormSubmit extends NavigationBase {
|
|
|
1298
1369
|
event: SubmitEvent;
|
|
1299
1370
|
}
|
|
1300
1371
|
|
|
1372
|
+
/**
|
|
1373
|
+
* A navigation triggered by back/forward navigation
|
|
1374
|
+
*/
|
|
1301
1375
|
export interface NavigationPopState extends NavigationBase {
|
|
1302
|
-
/**
|
|
1303
|
-
* The type of navigation:
|
|
1304
|
-
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
1305
|
-
*/
|
|
1306
1376
|
type: 'popstate';
|
|
1307
1377
|
|
|
1308
1378
|
/**
|
|
@@ -1316,11 +1386,10 @@ export interface NavigationPopState extends NavigationBase {
|
|
|
1316
1386
|
event: PopStateEvent;
|
|
1317
1387
|
}
|
|
1318
1388
|
|
|
1389
|
+
/**
|
|
1390
|
+
* A navigation triggered by a link click
|
|
1391
|
+
*/
|
|
1319
1392
|
export interface NavigationLink extends NavigationBase {
|
|
1320
|
-
/**
|
|
1321
|
-
* The type of navigation:
|
|
1322
|
-
* - `link`: Navigation was triggered by a link click
|
|
1323
|
-
*/
|
|
1324
1393
|
type: 'link';
|
|
1325
1394
|
|
|
1326
1395
|
/**
|
|
@@ -1509,6 +1578,10 @@ export interface RequestEvent<
|
|
|
1509
1578
|
locals: App.Locals;
|
|
1510
1579
|
/**
|
|
1511
1580
|
* The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
1581
|
+
*
|
|
1582
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1583
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1584
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1512
1585
|
*/
|
|
1513
1586
|
params: Params;
|
|
1514
1587
|
/**
|
|
@@ -1525,6 +1598,10 @@ export interface RequestEvent<
|
|
|
1525
1598
|
route: {
|
|
1526
1599
|
/**
|
|
1527
1600
|
* 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.
|
|
1601
|
+
*
|
|
1602
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1603
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1604
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1528
1605
|
*/
|
|
1529
1606
|
id: RouteId;
|
|
1530
1607
|
};
|
|
@@ -1553,6 +1630,10 @@ export interface RequestEvent<
|
|
|
1553
1630
|
setHeaders: (headers: Record<string, string>) => void;
|
|
1554
1631
|
/**
|
|
1555
1632
|
* The requested URL.
|
|
1633
|
+
*
|
|
1634
|
+
* In the context of a remote function request initiated by the client, this relates to the page the remote function
|
|
1635
|
+
* was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
|
|
1636
|
+
* whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
|
|
1556
1637
|
*/
|
|
1557
1638
|
url: URL;
|
|
1558
1639
|
/**
|
|
@@ -1649,7 +1730,7 @@ export interface ServerInitOptions {
|
|
|
1649
1730
|
export interface SSRManifest {
|
|
1650
1731
|
appDir: string;
|
|
1651
1732
|
appPath: string;
|
|
1652
|
-
/** Static files from `
|
|
1733
|
+
/** Static files from `config.files.assets` and the service worker (if any). */
|
|
1653
1734
|
assets: Set<string>;
|
|
1654
1735
|
mimeTypes: Record<string, string>;
|
|
1655
1736
|
|
|
@@ -1793,7 +1874,7 @@ export type ActionResult<
|
|
|
1793
1874
|
| { type: 'success'; status: number; data?: Success }
|
|
1794
1875
|
| { type: 'failure'; status: number; data?: Failure }
|
|
1795
1876
|
| { type: 'redirect'; status: number; location: string }
|
|
1796
|
-
| { type: 'error'; status?: number; error:
|
|
1877
|
+
| { type: 'error'; status?: number; error: App.Error };
|
|
1797
1878
|
|
|
1798
1879
|
/**
|
|
1799
1880
|
* The object returned by the [`error`](https://svelte.dev/docs/kit/@sveltejs-kit#error) function.
|
|
@@ -1942,6 +2023,10 @@ type RemoteFormFieldMethods<T> = {
|
|
|
1942
2023
|
value(): DeepPartial<T>;
|
|
1943
2024
|
/** Set the values that will be submitted */
|
|
1944
2025
|
set(input: DeepPartial<T>): DeepPartial<T>;
|
|
2026
|
+
/** Whether the field or any nested field has been interacted with since the form was mounted */
|
|
2027
|
+
touched(): boolean;
|
|
2028
|
+
/** Whether the field or any nested field has been edited since the form was mounted */
|
|
2029
|
+
dirty(): boolean;
|
|
1945
2030
|
/** Validation issues, if any */
|
|
1946
2031
|
issues(): RemoteFormIssue[] | undefined;
|
|
1947
2032
|
};
|
|
@@ -2056,7 +2141,7 @@ type RecursiveFormFields = RemoteFormFieldContainer<any> & {
|
|
|
2056
2141
|
type MaybeArray<T> = T | T[];
|
|
2057
2142
|
|
|
2058
2143
|
export interface RemoteFormInput {
|
|
2059
|
-
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput
|
|
2144
|
+
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
|
|
2060
2145
|
}
|
|
2061
2146
|
|
|
2062
2147
|
export interface RemoteFormIssue {
|
|
@@ -2102,6 +2187,24 @@ export interface ValidationError {
|
|
|
2102
2187
|
issues: StandardSchemaV1.Issue[];
|
|
2103
2188
|
}
|
|
2104
2189
|
|
|
2190
|
+
/**
|
|
2191
|
+
* The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2192
|
+
*/
|
|
2193
|
+
export type RemoteFormEnhanceInstance<
|
|
2194
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
2195
|
+
Output = any
|
|
2196
|
+
> = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
|
|
2197
|
+
readonly element: HTMLFormElement;
|
|
2198
|
+
};
|
|
2199
|
+
|
|
2200
|
+
/**
|
|
2201
|
+
* The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2202
|
+
*/
|
|
2203
|
+
export type RemoteFormEnhanceCallback<
|
|
2204
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
2205
|
+
Output = any
|
|
2206
|
+
> = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
|
|
2207
|
+
|
|
2105
2208
|
/**
|
|
2106
2209
|
* The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2107
2210
|
*/
|
|
@@ -2118,13 +2221,7 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2118
2221
|
updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
|
|
2119
2222
|
};
|
|
2120
2223
|
/** 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
|
-
): {
|
|
2224
|
+
enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
|
|
2128
2225
|
method: 'POST';
|
|
2129
2226
|
action: string;
|
|
2130
2227
|
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
@@ -2148,8 +2245,13 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2148
2245
|
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
|
|
2149
2246
|
/** Validate the form contents programmatically */
|
|
2150
2247
|
validate(options?: {
|
|
2151
|
-
/**
|
|
2152
|
-
|
|
2248
|
+
/**
|
|
2249
|
+
* Set this to `true` to also show validation issues of fields that haven't yet been
|
|
2250
|
+
* edited and blurred. This option is ignored for forms that have previously been
|
|
2251
|
+
* submitted, in which case all fields are always subject to validation
|
|
2252
|
+
* (unless the form is reset, at which point it is treated as pristine)
|
|
2253
|
+
*/
|
|
2254
|
+
all?: boolean;
|
|
2153
2255
|
/** Set this to `true` to only run the `preflight` validation. */
|
|
2154
2256
|
preflightOnly?: boolean;
|
|
2155
2257
|
}): Promise<void>;
|
|
@@ -2157,6 +2259,8 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2157
2259
|
get result(): Output | undefined;
|
|
2158
2260
|
/** The number of pending submissions */
|
|
2159
2261
|
get pending(): number;
|
|
2262
|
+
/** True if the form has been submitted at least once, and hasn't been reset since */
|
|
2263
|
+
get submitted(): boolean;
|
|
2160
2264
|
/** Access form fields using object notation */
|
|
2161
2265
|
fields: RemoteFormFieldsRoot<Input>;
|
|
2162
2266
|
};
|
|
@@ -149,7 +149,12 @@ export function build_server_nodes(
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
if (node.universal) {
|
|
152
|
-
if (
|
|
152
|
+
if (
|
|
153
|
+
(kit.router.type === 'hash' &&
|
|
154
|
+
node.page_options !== null &&
|
|
155
|
+
node.page_options?.ssr === undefined) ||
|
|
156
|
+
(node.page_options && node.page_options.ssr === false)
|
|
157
|
+
) {
|
|
153
158
|
exports.push(`export const universal = ${s(node.page_options, null, 2)};`);
|
|
154
159
|
} else {
|
|
155
160
|
imports.push(
|