@sveltejs/kit 3.0.0-next.12 → 3.0.0-next.14

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.
Files changed (77) hide show
  1. package/package.json +11 -11
  2. package/src/cli.js +2 -2
  3. package/src/core/adapt/builder.js +8 -5
  4. package/src/core/generate_manifest/index.js +6 -0
  5. package/src/core/postbuild/entities.js +8 -2
  6. package/src/core/postbuild/fallback.js +2 -1
  7. package/src/core/postbuild/prerender.js +15 -6
  8. package/src/core/sync/create_manifest_data/conflict.js +1 -1
  9. package/src/core/sync/create_manifest_data/index.js +33 -2
  10. package/src/core/sync/write_app_types.js +73 -29
  11. package/src/core/sync/write_tsconfig/index.js +15 -2
  12. package/src/core/sync/write_types/index.js +5 -2
  13. package/src/exports/index.js +23 -12
  14. package/src/exports/internal/shared.js +4 -12
  15. package/src/exports/node/index.js +2 -7
  16. package/src/exports/public.d.ts +61 -12
  17. package/src/exports/vite/build/remote.js +10 -12
  18. package/src/exports/vite/dev/index.js +32 -19
  19. package/src/exports/vite/index.js +162 -133
  20. package/src/exports/vite/utils.js +1 -7
  21. package/src/runtime/app/server/remote/form.js +9 -1
  22. package/src/runtime/app/server/remote/prerender.js +13 -9
  23. package/src/runtime/app/server/remote/query.js +0 -6
  24. package/src/runtime/app/server/remote/requested.js +4 -4
  25. package/src/runtime/app/state/client.js +3 -0
  26. package/src/runtime/app/state/index.js +2 -2
  27. package/src/runtime/app/state/server.js +3 -0
  28. package/src/runtime/client/client.js +731 -342
  29. package/src/runtime/client/constants.js +2 -6
  30. package/src/runtime/client/fetcher.js +24 -25
  31. package/src/runtime/client/remote-functions/form.svelte.js +42 -14
  32. package/src/runtime/client/remote-functions/prerender.svelte.js +2 -2
  33. package/src/runtime/client/remote-functions/query/index.js +1 -1
  34. package/src/runtime/client/remote-functions/query/instance.svelte.js +2 -2
  35. package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
  36. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +2 -2
  37. package/src/runtime/client/remote-functions/query-live/iterator.js +10 -8
  38. package/src/runtime/client/remote-functions/query-live/proxy.js +0 -10
  39. package/src/runtime/client/remote-functions/shared.svelte.js +12 -11
  40. package/src/runtime/client/state.svelte.js +10 -22
  41. package/src/runtime/client/types.d.ts +1 -2
  42. package/src/runtime/client/utils.js +22 -14
  43. package/src/runtime/components/root.svelte +4 -14
  44. package/src/runtime/form-utils.js +4 -6
  45. package/src/runtime/pathname.js +37 -0
  46. package/src/runtime/props.svelte.js +71 -0
  47. package/src/runtime/server/fetch.js +9 -14
  48. package/src/runtime/server/index.js +10 -24
  49. package/src/runtime/server/page/crypto.js +2 -2
  50. package/src/runtime/server/page/csp.js +88 -104
  51. package/src/runtime/server/page/index.js +1 -2
  52. package/src/runtime/server/page/load_data.js +16 -33
  53. package/src/runtime/server/page/render.js +46 -25
  54. package/src/runtime/server/page/respond_with_error.js +1 -3
  55. package/src/runtime/server/page/serialize_data.js +2 -13
  56. package/src/runtime/server/page/server_routing.js +58 -9
  57. package/src/runtime/server/respond.js +20 -29
  58. package/src/runtime/server/state.js +43 -0
  59. package/src/runtime/shared.js +4 -2
  60. package/src/runtime/utils.js +3 -0
  61. package/src/types/ambient-private.d.ts +2 -2
  62. package/src/types/ambient.d.ts +59 -8
  63. package/src/types/global-private.d.ts +1 -1
  64. package/src/types/internal.d.ts +4 -8
  65. package/src/types/private.d.ts +3 -12
  66. package/src/utils/hash.js +21 -0
  67. package/src/utils/http.js +8 -7
  68. package/src/utils/import.js +2 -1
  69. package/src/utils/params.js +1 -1
  70. package/src/utils/regex.js +9 -0
  71. package/src/utils/routing.js +52 -27
  72. package/src/utils/url.js +1 -0
  73. package/src/version.js +1 -1
  74. package/types/index.d.ts +165 -66
  75. package/types/index.d.ts.map +2 -1
  76. package/src/exports/node/polyfills.js +0 -30
  77. package/src/runtime/types.d.ts +0 -8
package/src/utils/hash.js CHANGED
@@ -20,3 +20,24 @@ export function hash(...values) {
20
20
 
21
21
  return (hash >>> 0).toString(36);
22
22
  }
23
+
24
+ /**
25
+ * Hash of the headers and body a `fetch` was called with. The server-side serializer and the
26
+ * client-side cache lookup must produce identical values for cached responses to be found.
27
+ * @param {HeadersInit | undefined} headers
28
+ * @param {import('types').StrictBody | null | undefined} body
29
+ */
30
+ export function hash_request(headers, body) {
31
+ /** @type {import('types').StrictBody[]} */
32
+ const values = [];
33
+
34
+ if (headers) {
35
+ values.push([...new Headers(headers)].join(','));
36
+ }
37
+
38
+ if (body) {
39
+ values.push(body);
40
+ }
41
+
42
+ return hash(...values);
43
+ }
package/src/utils/http.js CHANGED
@@ -11,7 +11,7 @@ export function negotiate(accept, types) {
11
11
  const parts = [];
12
12
 
13
13
  accept.split(',').forEach((str, i) => {
14
- const match = /([^/ \t]+)\/([^; \t]+)[ \t]*(?:;[ \t]*q=([0-9.]+))?/.exec(str);
14
+ const match = /^[ \t]*([^/ \t]+)\/([^; \t]+)[ \t]*(?:;[ \t]*q=([0-9.]+))?/.exec(str);
15
15
 
16
16
  // no match equals invalid header — ignore
17
17
  if (match) {
@@ -57,12 +57,13 @@ export function negotiate(accept, types) {
57
57
  }
58
58
 
59
59
  /**
60
- * Returns `true` if the request contains a `content-type` header with the given type
61
- * @param {Request} request
60
+ * Returns `true` if a `content-type` header value is one of the given types, ignoring
61
+ * parameters such as `charset` and comparing case-insensitively
62
+ * @param {string | null | undefined} header
62
63
  * @param {...string} types
63
64
  */
64
- function is_content_type(request, ...types) {
65
- const type = request.headers.get('content-type')?.split(';', 1)[0].trim() ?? '';
65
+ export function matches_content_type(header, ...types) {
66
+ const type = header?.split(';', 1)[0].trim() ?? '';
66
67
  return types.includes(type.toLowerCase());
67
68
  }
68
69
 
@@ -72,8 +73,8 @@ function is_content_type(request, ...types) {
72
73
  export function is_form_content_type(request) {
73
74
  // These content types must be protected against CSRF
74
75
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/enctype
75
- return is_content_type(
76
- request,
76
+ return matches_content_type(
77
+ request.headers.get('content-type'),
77
78
  'application/x-www-form-urlencoded',
78
79
  'multipart/form-data',
79
80
  'text/plain',
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
3
4
 
4
5
  /**
5
6
  * Resolves a peer dependency relative to the current working directory.
@@ -51,7 +52,7 @@ function resolve_peer(dependency, root) {
51
52
  */
52
53
  export async function import_peer(dependency, root) {
53
54
  try {
54
- return await import(/* @vite-ignore */ resolve_peer(dependency, root));
55
+ return await import(/* @vite-ignore */ pathToFileURL(resolve_peer(dependency, root)).href);
55
56
  } catch {
56
57
  return await import(/* @vite-ignore */ dependency);
57
58
  }
@@ -25,7 +25,7 @@ export function collect_matcher_names(routes) {
25
25
  */
26
26
  export function validate_param_matchers(params, names, file) {
27
27
  for (const name of names) {
28
- if (!(name in params)) {
28
+ if (!Object.hasOwn(params, name)) {
29
29
  throw new Error(`No matcher found for parameter '${name}'${file ? ` in ${file}` : ''}`);
30
30
  }
31
31
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Escapes characters that have special meaning in a regular expression.
3
+ * @param {string} str
4
+ * @returns {string} escaped string
5
+ */
6
+ export function escape_for_regexp(str) {
7
+ // TODO replace with `RegExp.escape(str)` when we require Node >= 24
8
+ return str.replace(/[.*+?^${}()|[\]\\]/g, (match) => '\\' + match);
9
+ }
@@ -1,9 +1,32 @@
1
1
  import { BROWSER } from 'esm-env';
2
+ import { escape_for_regexp } from './regex.js';
2
3
 
3
4
  const param_pattern = /^(\[)?(\.\.\.)?([\w-]+)(?:=([\w-]+))?(\])?$/;
4
5
 
5
6
  const root_group_pattern = /^\/\((?:[^)]+)\)$/;
6
7
 
8
+ const escape_sequence_pattern = /\[([ux])\+([^\]]+)\]/;
9
+
10
+ /**
11
+ * Decodes the codepoints of an `[x+nn]` or `[u+nnnn]` escape sequence
12
+ * @param {string} code the sequence without its `[x+`/`[u+` prefix or `]` suffix
13
+ */
14
+ export function decode_escape_sequence(code) {
15
+ return String.fromCodePoint(...code.split('-').map((codepoint) => parseInt(codepoint, 16)));
16
+ }
17
+
18
+ /**
19
+ * Encodes the characters that `decode_pathname` leaves untouched, so that a decoded
20
+ * escape sequence still matches the pattern `parse_route_id` builds for it
21
+ * @param {string} str
22
+ */
23
+ export function encode_pathname_chars(str) {
24
+ return str.replace(
25
+ /[%/?#]/g,
26
+ (char) => '%' + char.charCodeAt(0).toString(16).toUpperCase().padStart(2, '0')
27
+ );
28
+ }
29
+
7
30
  /**
8
31
  * Creates the regex pattern, extracts parameter names, and generates types for a route
9
32
  * @param {string} id
@@ -51,19 +74,8 @@ export function parse_route_id(id) {
51
74
  const result = parts
52
75
  .map((content, i) => {
53
76
  if (i % 2) {
54
- if (content.startsWith('x+')) {
55
- return escape(String.fromCharCode(parseInt(content.slice(2), 16)));
56
- }
57
-
58
- if (content.startsWith('u+')) {
59
- return escape(
60
- String.fromCharCode(
61
- ...content
62
- .slice(2)
63
- .split('-')
64
- .map((code) => parseInt(code, 16))
65
- )
66
- );
77
+ if (content.startsWith('x+') || content.startsWith('u+')) {
78
+ return escape(decode_escape_sequence(content.slice(2)));
67
79
  }
68
80
 
69
81
  // We know the match cannot be null in the browser because manifest generation
@@ -243,25 +255,36 @@ export function exec(match, params, matchers) {
243
255
  return result;
244
256
  }
245
257
 
258
+ /**
259
+ * `decode_pathname` leaves these characters untouched, so routes have to match their encoded forms
260
+ * @type {Record<string, string>}
261
+ */
262
+ const encoded = {
263
+ '%': '%25',
264
+ '/': '%2[Ff]',
265
+ '?': '%3[Ff]',
266
+ '#': '%23'
267
+ };
268
+
246
269
  /** @param {string} str */
247
270
  function escape(str) {
248
- return (
249
- str
250
- .normalize()
251
- // escape [ and ] before escaping other characters, since they are used in the replacements
252
- .replace(/[[\]]/g, '\\$&')
253
- // replace %, /, ? and # with their encoded versions because decode_pathname leaves them untouched
254
- .replace(/%/g, '%25')
255
- .replace(/\//g, '%2[Ff]')
256
- .replace(/\?/g, '%3[Ff]')
257
- .replace(/#/g, '%23')
258
- // escape characters that have special meaning in regex
259
- .replace(/[.*+?^${}()|\\]/g, '\\$&')
260
- );
271
+ // the replacements in `encoded` are regex source themselves, so they must not be escaped again
272
+ return str
273
+ .normalize()
274
+ .split(/([%/?#])/)
275
+ .map((part, i) => (i % 2 ? encoded[part] : escape_for_regexp(part)))
276
+ .join('');
261
277
  }
262
278
 
263
279
  const basic_param_pattern = /\[(\[)?(\.\.\.)?([\w-]+?)(?:=([\w-]+))?\]\]?/g;
264
280
 
281
+ // escape sequences are expanded in the same pass as the params, so that a param
282
+ // value containing `[x+2f]` is not itself expanded
283
+ export const segment_pattern = new RegExp(
284
+ `${escape_sequence_pattern.source}|${basic_param_pattern.source}`,
285
+ 'g'
286
+ );
287
+
265
288
  /**
266
289
  * Populate a route ID with params to resolve a pathname.
267
290
  * @example
@@ -286,7 +309,9 @@ export function resolve_route(id, params) {
286
309
  '/' +
287
310
  segments
288
311
  .map((segment) =>
289
- segment.replace(basic_param_pattern, (_, optional, rest, name) => {
312
+ segment.replace(segment_pattern, (_, escape_type, escape_code, optional, rest, name) => {
313
+ if (escape_type) return encode_pathname_chars(decode_escape_sequence(escape_code));
314
+
290
315
  const value = params[name];
291
316
 
292
317
  if (value === undefined || value === '') {
package/src/utils/url.js CHANGED
@@ -46,6 +46,7 @@ export function relative_pathname(from, to) {
46
46
  export function matches_external_allowlist_entry(location, allowed) {
47
47
  if (location === allowed) return true;
48
48
 
49
+ // TODO replace the try/catch with `URL.parse` when browser support allows (Chrome 126, Firefox 126, Safari 18)
49
50
  try {
50
51
  const allow = new URL(allowed);
51
52
  const loc = new URL(location, allow);
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '3.0.0-next.12';
4
+ export const VERSION = '3.0.0-next.14';
package/types/index.d.ts CHANGED
@@ -225,8 +225,9 @@ declare module '@sveltejs/kit' {
225
225
  /**
226
226
  * Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals.
227
227
  * @param directory The directory containing the files to be compressed
228
+ * @returns an array of the files in `directory` that were compressed
228
229
  */
229
- compress: (directory: string) => Promise<void>;
230
+ compress: (directory: string) => Promise<string[]>;
230
231
  }
231
232
 
232
233
  /**
@@ -834,7 +835,7 @@ declare module '@sveltejs/kit' {
834
835
  * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
835
836
  * This is useful for extending a shared `tsconfig.json` in a monorepo root, for example.
836
837
  *
837
- * Note that any paths configured here should be relative to the generated config file, which is written to `.svelte-kit/tsconfig.json`.
838
+ * Note that any paths configured here should be relative to the generated config file, which is written to `node_modules/$app/tsconfig.json`.
838
839
  *
839
840
  * @default (config) => config
840
841
  * @since 1.3.0
@@ -1209,6 +1210,46 @@ declare module '@sveltejs/kit' {
1209
1210
  scroll: { x: number; y: number } | null;
1210
1211
  }
1211
1212
 
1213
+ export interface GotoOptions {
1214
+ /**
1215
+ * If `true`, replaces the current history entry rather than creating a new one.
1216
+ * @default false
1217
+ */
1218
+ replace?: boolean;
1219
+ /** @deprecated Use `replace` instead. */
1220
+ replaceState?: boolean;
1221
+ /**
1222
+ * If `true`, updates the URL and `page.state` without navigating.
1223
+ * @default false
1224
+ */
1225
+ shallow?: boolean;
1226
+ /**
1227
+ * If `true`, resets the scroll position (to the top of the page, or to the element
1228
+ * matching the URL's `#hash` if there is one) and resets focus (to the `<body>`, or the
1229
+ * `autofocus` element if there is one) once the navigation completes.
1230
+ *
1231
+ * If `false`, the current scroll position and focused element are left alone.
1232
+ * @default true, or false when `shallow` is true
1233
+ */
1234
+ reset?: boolean;
1235
+ /**
1236
+ * If `true`, reruns all `load` functions and queries of the page.
1237
+ * @default false
1238
+ */
1239
+ refreshAll?: boolean;
1240
+ /** Causes any `load` functions to rerun if they depend on one of the URLs. */
1241
+ invalidate?: Array<string | URL | ((url: URL) => boolean)>;
1242
+ /** @deprecated Use `refreshAll` instead. */
1243
+ invalidateAll?: boolean;
1244
+ /** An optional object that will be available as `page.state`. */
1245
+ state?: App.PageState;
1246
+ /**
1247
+ * If `true`, `page.state` will be restored after a full page reload.
1248
+ * @default false
1249
+ */
1250
+ persistState?: boolean;
1251
+ }
1252
+
1212
1253
  /**
1213
1254
  * - `enter`: The app has hydrated/started
1214
1255
  * - `form`: The user submitted a `<form method="GET">`
@@ -1230,6 +1271,8 @@ declare module '@sveltejs/kit' {
1230
1271
  * - `popstate`: Navigation was triggered by back/forward navigation
1231
1272
  */
1232
1273
  type: NavigationType;
1274
+ /** Whether this is a shallow navigation. */
1275
+ shallow: boolean;
1233
1276
  /**
1234
1277
  * Where navigation was triggered from
1235
1278
  */
@@ -1324,10 +1367,7 @@ declare module '@sveltejs/kit' {
1324
1367
  }
1325
1368
 
1326
1369
  export type Navigation =
1327
- | NavigationExternal
1328
- | NavigationFormSubmit
1329
- | NavigationPopState
1330
- | NavigationLink;
1370
+ NavigationExternal | NavigationFormSubmit | NavigationPopState | NavigationLink;
1331
1371
 
1332
1372
  /**
1333
1373
  * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
@@ -1398,9 +1438,20 @@ declare module '@sveltejs/kit' {
1398
1438
  */
1399
1439
  data: App.PageData & Record<string, any>;
1400
1440
  /**
1401
- * The page state, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`.
1441
+ * The page state, which can be manipulated using [`goto`](https://svelte.dev/docs/kit/$app-navigation#goto) from `$app/navigation`.
1402
1442
  */
1403
1443
  state: App.PageState;
1444
+ /**
1445
+ * Information about the target of the current shallow navigation, or `null` if no shallow navigation has occurred.
1446
+ */
1447
+ shallow: {
1448
+ /** Parameters of the target route, or `null` if the URL does not resolve to a route. */
1449
+ params: AppLayoutParams<'/'> | null;
1450
+ /** Info about the target route, or `null` if the URL does not resolve to a route. */
1451
+ route: { id: AppRouteId } | null;
1452
+ /** The normalized URL passed to `goto(..., { shallow: true })`. */
1453
+ url: ReadonlyURL;
1454
+ } | null;
1404
1455
  /**
1405
1456
  * Filled only after a form submission. See [form actions](https://svelte.dev/docs/kit/form-actions) for more info.
1406
1457
  */
@@ -1421,8 +1472,7 @@ declare module '@sveltejs/kit' {
1421
1472
  * A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
1422
1473
  */
1423
1474
  export type ParamDefinition =
1424
- | ((param: string) => ParamValue | undefined)
1425
- | StandardSchemaV1<string, ParamValue>;
1475
+ ((param: string) => ParamValue | undefined) | StandardSchemaV1<string, ParamValue>;
1426
1476
 
1427
1477
  /**
1428
1478
  * The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
@@ -1525,8 +1575,7 @@ declare module '@sveltejs/kit' {
1525
1575
  };
1526
1576
 
1527
1577
  export type RequestedResult<Validated, Output> =
1528
- | QueryRequestedResult<Validated, Output>
1529
- | LiveQueryRequestedResult<Validated, Output>;
1578
+ QueryRequestedResult<Validated, Output> | LiveQueryRequestedResult<Validated, Output>;
1530
1579
 
1531
1580
  export interface RequestEvent<
1532
1581
  Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
@@ -1707,7 +1756,7 @@ declare module '@sveltejs/kit' {
1707
1756
 
1708
1757
  export interface ServerInitOptions {
1709
1758
  /** A map of environment variables. */
1710
- env: Record<string, string>;
1759
+ env: Record<string, string | undefined>;
1711
1760
  /** A function that turns an asset filename into a `ReadableStream`. Required for the `read` export from `$app/server` to work. */
1712
1761
  read?: (file: string) => MaybePromise<ReadableStream | null>;
1713
1762
  }
@@ -2655,20 +2704,11 @@ declare module '@sveltejs/kit' {
2655
2704
  type PrerenderHttpErrorHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderHttpErrorHandler;
2656
2705
  type PrerenderMissingIdHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderMissingIdHandler;
2657
2706
  type PrerenderUnseenRoutesHandlerValue =
2658
- | 'fail'
2659
- | 'warn'
2660
- | 'ignore'
2661
- | PrerenderUnseenRoutesHandler;
2707
+ 'fail' | 'warn' | 'ignore' | PrerenderUnseenRoutesHandler;
2662
2708
  type PrerenderEntryGeneratorMismatchHandlerValue =
2663
- | 'fail'
2664
- | 'warn'
2665
- | 'ignore'
2666
- | PrerenderEntryGeneratorMismatchHandler;
2709
+ 'fail' | 'warn' | 'ignore' | PrerenderEntryGeneratorMismatchHandler;
2667
2710
  type PrerenderInvalidUrlHandlerValue =
2668
- | 'fail'
2669
- | 'warn'
2670
- | 'ignore'
2671
- | PrerenderInvalidUrlHandler;
2711
+ 'fail' | 'warn' | 'ignore' | PrerenderInvalidUrlHandler;
2672
2712
 
2673
2713
  export type PrerenderOption = boolean | 'auto';
2674
2714
 
@@ -2713,42 +2753,43 @@ declare module '@sveltejs/kit' {
2713
2753
  * return an error response without invoking `handleError`.
2714
2754
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2715
2755
  * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
2716
- * @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
2756
+ * @param message The error message.
2717
2757
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
2718
2758
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
2719
2759
  */
2720
- export function error(status: number, body: Omit<App.Error, "status"> & {
2721
- status?: App.Error["status"];
2722
- }): never;
2760
+ export function error(status: {
2761
+ status: number;
2762
+ message: string;
2763
+ } extends App.Error ? number : never, message?: string | undefined): never;
2723
2764
  /**
2724
2765
  * Throws an error with a HTTP status code and an optional message.
2725
2766
  * When called during request handling, this will cause SvelteKit to
2726
2767
  * return an error response without invoking `handleError`.
2727
2768
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2728
2769
  * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
2729
- * @param body The error message.
2770
+ * @param message The error message.
2771
+ * @param properties Additional properties of the App.Error type.
2730
2772
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
2731
2773
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
2732
2774
  */
2733
- export function error(status: number, body: {
2775
+ export function error(status: number, message: string, properties: {
2734
2776
  status: number;
2735
2777
  message: string;
2736
- } extends App.Error ? string | void | undefined : never): never;
2778
+ } extends App.Error ? never : Omit<App.Error, "status" | "message">): never;
2737
2779
  /**
2738
2780
  * Throws an error with a HTTP status code and an optional message.
2739
2781
  * When called during request handling, this will cause SvelteKit to
2740
2782
  * return an error response without invoking `handleError`.
2741
2783
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2784
+ * @deprecated Passing an `App.Error` body as the second argument is deprecated — pass the `message` as the second argument, and any additional properties as the third
2742
2785
  * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
2743
- * @param body The error message.
2744
- * @param properties Additional properties of the App.Error type.
2786
+ * @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
2745
2787
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
2746
2788
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
2747
2789
  */
2748
- export function error(status: number, body: string, properties: {
2749
- status: number;
2750
- message: string;
2751
- } extends App.Error ? never : Omit<App.Error, "status" | "message">): never;
2790
+ export function error(status: number, properties: Omit<App.Error, "status"> & {
2791
+ status?: App.Error["status"];
2792
+ }): never;
2752
2793
  /**
2753
2794
  * Checks whether this is an error thrown by {@link error}.
2754
2795
  * @param status The status to filter for.
@@ -3092,6 +3133,7 @@ declare module '$app/forms' {
3092
3133
  }
3093
3134
 
3094
3135
  declare module '$app/navigation' {
3136
+ import type { RouteId } from '$app/types';
3095
3137
  /**
3096
3138
  * A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a URL.
3097
3139
  *
@@ -3126,25 +3168,18 @@ declare module '$app/navigation' {
3126
3168
  * */
3127
3169
  export function disableScrollHandling(): void;
3128
3170
  /**
3129
- * Allows you to navigate programmatically to a given route, with options such as keeping the current element focused.
3130
- * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
3171
+ * Allows you to navigate programmatically to a given route, with control over details such as whether scroll and focus are reset
3172
+ * (as they would be with a regular navigation) or preserved.
3173
+ *
3174
+ * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) or the state change has been applied.
3131
3175
  *
3132
- * `goto` is intended for navigations to routes that belong to the app.
3133
- * If the URL does not resolve to a route within the app, the returned promise will reject.
3176
+ * `goto` is intended for navigations to routes that belong to the app, and will reject if a route cannot be resolved.
3134
3177
  * For external URLs, use `window.location = url` to perform a full-page navigation instead of calling `goto(url)`.
3135
3178
  *
3136
3179
  * @param url Where to navigate to. Note that if you've set [`config.paths.base`](https://svelte.dev/docs/kit/configuration#paths) and the URL is root-relative, you need to prepend the base path if you want to navigate within the app.
3137
- * @param {Object} opts Options related to the navigation
3180
+ * @param opts Options related to the navigation
3138
3181
  * */
3139
- export function goto(url: string | URL, opts?: {
3140
- replaceState?: boolean | undefined;
3141
- noScroll?: boolean | undefined;
3142
- keepFocus?: boolean | undefined;
3143
- refreshAll?: boolean | undefined;
3144
- invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
3145
- invalidateAll?: boolean | undefined;
3146
- state?: App.PageState | undefined;
3147
- }): Promise<void>;
3182
+ export function goto(url: string | URL, opts?: import("@sveltejs/kit").GotoOptions): Promise<void>;
3148
3183
  /**
3149
3184
  * Causes any `load` functions belonging to the currently active page to re-run if they depend on the `url` in question, via `fetch` or `depends`. Returns a `Promise` that resolves when the page is subsequently updated.
3150
3185
  *
@@ -3204,23 +3239,36 @@ declare module '$app/navigation' {
3204
3239
  * Programmatically imports the code for routes that haven't yet been fetched.
3205
3240
  * Typically, you might call this to speed up subsequent navigation.
3206
3241
  *
3207
- * You can specify routes by any matching pathname such as `/about` (to match `src/routes/about/+page.svelte`) or `/blog/*` (to match `src/routes/blog/[slug]/+page.svelte`).
3242
+ * Takes a route ID such as `/about` or `/blog/[slug]`. Unlike pathnames, route IDs
3243
+ * are never prefixed with the app's [base path](https://svelte.dev/docs/kit/configuration#paths).
3244
+ * If you have a pathname rather than a route ID, you can convert it with
3245
+ * [`match`](https://svelte.dev/docs/kit/$app-paths#match) from `$app/paths`:
3246
+ *
3247
+ * ```js
3248
+ * import { match } from '$app/paths';
3249
+ * import { preloadCode } from '$app/navigation';
3250
+ *
3251
+ * const matched = await match('/blog/hello-world');
3252
+ * if (matched) await preloadCode(matched.id);
3253
+ * ```
3208
3254
  *
3209
3255
  * Unlike `preloadData`, this won't call `load` functions.
3210
3256
  * Returns a Promise that resolves when the modules have been imported.
3211
3257
  *
3212
3258
  * */
3213
- export function preloadCode(pathname: string): Promise<void>;
3259
+ export function preloadCode(id: RouteId): Promise<void>;
3214
3260
  /**
3215
- * Programmatically create a new history entry with the given `page.state`. To use the current URL, you can pass `''` as the first argument. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
3261
+ * Programmatically create a new history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
3216
3262
  *
3263
+ * @deprecated Use `goto(url, { state, shallow: true })` instead.
3217
3264
  * */
3218
- export function pushState(url: string | URL, state: App.PageState): void;
3265
+ export function pushState(url: string | URL, state: App.PageState): Promise<void>;
3219
3266
  /**
3220
- * Programmatically replace the current history entry with the given `page.state`. To use the current URL, you can pass `''` as the first argument. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
3267
+ * Programmatically replace the current history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
3221
3268
  *
3269
+ * @deprecated Use `goto(url, { state, shallow: true, replace: true })` instead.
3222
3270
  * */
3223
- export function replaceState(url: string | URL, state: App.PageState): void;
3271
+ export function replaceState(url: string | URL, state: App.PageState): Promise<void>;
3224
3272
  type MaybePromise<T> = T | Promise<T>;
3225
3273
 
3226
3274
  export {};
@@ -3582,8 +3630,8 @@ declare module '$app/state' {
3582
3630
  * A read-only reactive object with information about the current page, serving several use cases:
3583
3631
  * - retrieving the combined `data` of all pages/layouts anywhere in your component tree (also see [loading data](https://svelte.dev/docs/kit/load))
3584
3632
  * - retrieving the current value of the `form` prop anywhere in your component tree (also see [form actions](https://svelte.dev/docs/kit/form-actions))
3585
- * - retrieving the page state that was set through `goto`, `pushState` or `replaceState` (also see [goto](https://svelte.dev/docs/kit/$app-navigation#goto) and [shallow routing](https://svelte.dev/docs/kit/shallow-routing))
3586
- * - retrieving metadata such as the URL you're on, the current route and its parameters, and whether or not there was an error
3633
+ * - retrieving the page state that was set through `goto` (also see [goto](https://svelte.dev/docs/kit/$app-navigation#goto) and [shallow routing](https://svelte.dev/docs/kit/shallow-routing))
3634
+ * - retrieving metadata such as the URL you're on, the current route and its parameters, the target of a shallow navigation, and whether or not there was an error
3587
3635
  *
3588
3636
  * ```svelte
3589
3637
  * <!--- file: +layout.svelte --->
@@ -3684,7 +3732,7 @@ declare namespace App {
3684
3732
  export interface PageData {}
3685
3733
 
3686
3734
  /**
3687
- * The shape of the `page.state` object, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`.
3735
+ * The shape of the `page.state` object, which can be manipulated using [`goto`](https://svelte.dev/docs/kit/$app-navigation#goto).
3688
3736
  */
3689
3737
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
3690
3738
  export interface PageState {}
@@ -3718,9 +3766,41 @@ declare module '$app/manifest' {
3718
3766
  */
3719
3767
  export const prerendered: Array<{ path: import('$app/types').Path }>;
3720
3768
  /**
3721
- * An array of objects with an `id` property representing the routes in your app.
3769
+ * A route in your app, along with its capabilities. `page` indicates the presence of a `+page`,
3770
+ * while `endpoint` indicates the presence of a `+server`. Both are `true` when both files exist.
3771
+ */
3772
+ export type ManifestRoute =
3773
+ | {
3774
+ id: Exclude<import('$app/types').PageRouteId, import('$app/types').EndpointRouteId>;
3775
+ page: true;
3776
+ endpoint: false;
3777
+ }
3778
+ | {
3779
+ id: Exclude<import('$app/types').EndpointRouteId, import('$app/types').PageRouteId>;
3780
+ page: false;
3781
+ endpoint: true;
3782
+ }
3783
+ | {
3784
+ id: Extract<import('$app/types').PageRouteId, import('$app/types').EndpointRouteId>;
3785
+ page: true;
3786
+ endpoint: true;
3787
+ };
3788
+ /**
3789
+ * An array of objects representing the routes in your app. Only routes that the router can match
3790
+ * are included — directories that merely hold a `+layout` are not routes of their own.
3791
+ *
3792
+ * Each object has an `id`, plus `page` and `endpoint` booleans describing whether the route has a
3793
+ * `+page` and/or a `+server`. Both are `true` for a route that has both, so the capabilities can
3794
+ * be filtered independently:
3795
+ *
3796
+ * ```js
3797
+ * import { routes } from '$app/manifest';
3798
+ *
3799
+ * const pages = routes.filter((route) => route.page);
3800
+ * const endpoints = routes.filter((route) => route.endpoint);
3801
+ * ```
3722
3802
  */
3723
- export const routes: Array<{ id: import('$app/types').RouteId }>;
3803
+ export const routes: ManifestRoute[];
3724
3804
  }
3725
3805
 
3726
3806
  /**
@@ -3734,6 +3814,8 @@ declare module '$app/types' {
3734
3814
  // These are all functions so that we can leverage function overloads to get the correct type.
3735
3815
  // Using the return types directly would error with a "not the same type" error.
3736
3816
  // https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-interfaces
3817
+ PageRouteId(): string;
3818
+ EndpointRouteId(): string;
3737
3819
  RouteId(): string;
3738
3820
  RouteParams(): Record<string, Record<string, string>>;
3739
3821
  LayoutParams(): Record<string, Record<string, string>>;
@@ -3743,7 +3825,21 @@ declare module '$app/types' {
3743
3825
  }
3744
3826
 
3745
3827
  /**
3746
- * A union of all the route IDs in your app. Used for `page.route.id` and `event.route.id`.
3828
+ * A union of the route IDs in your app that have a `+page`.
3829
+ *
3830
+ * A route ID can be in both `PageRouteId` and `EndpointRouteId`, if its directory contains both a `+page` and a `+server`.
3831
+ */
3832
+ export type PageRouteId = ReturnType<AppTypes['PageRouteId']>;
3833
+
3834
+ /**
3835
+ * A union of the route IDs in your app that have a `+server`.
3836
+ *
3837
+ * A route ID can be in both `PageRouteId` and `EndpointRouteId`, if its directory contains both a `+page` and a `+server`.
3838
+ */
3839
+ export type EndpointRouteId = ReturnType<AppTypes['EndpointRouteId']>;
3840
+
3841
+ /**
3842
+ * A union of all the route IDs in your app — the union of `PageRouteId` and `EndpointRouteId`. Used for `page.route.id` and `event.route.id`.
3747
3843
  */
3748
3844
  export type RouteId = ReturnType<AppTypes['RouteId']>;
3749
3845
 
@@ -3759,12 +3855,15 @@ declare module '$app/types' {
3759
3855
  ? ReturnType<AppTypes['RouteParams']>[T]
3760
3856
  : Record<string, never>;
3761
3857
 
3858
+ /**
3859
+ * The route IDs accepted by `LayoutParams`. Like `RouteId`, these preserve route groups and `[param]` syntax, but they identify directories containing layouts rather than matchable routes.
3860
+ */
3861
+ type LayoutParamsId = keyof ReturnType<AppTypes['LayoutParams']>;
3862
+
3762
3863
  /**
3763
3864
  * A utility for getting the parameters associated with a given layout, which is similar to `RouteParams` but also includes optional parameters for any child route.
3764
3865
  */
3765
- export type LayoutParams<T extends RouteId> = T extends keyof ReturnType<AppTypes['LayoutParams']>
3766
- ? ReturnType<AppTypes['LayoutParams']>[T]
3767
- : Record<string, never>;
3866
+ export type LayoutParams<T extends LayoutParamsId> = ReturnType<AppTypes['LayoutParams']>[T];
3768
3867
 
3769
3868
  /**
3770
3869
  * A union of all valid paths in your app, relative to the `base` path.