@sveltejs/kit 3.0.0-next.18 → 3.0.0-next.19

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 (83) hide show
  1. package/package.json +12 -5
  2. package/src/cli.js +1 -1
  3. package/src/constants.js +3 -0
  4. package/src/core/config/index.js +1 -1
  5. package/src/core/env.js +1 -1
  6. package/src/core/postbuild/analyse.js +1 -1
  7. package/src/core/postbuild/prerender.js +1 -1
  8. package/src/core/sync/create_manifest_data/index.js +9 -0
  9. package/src/core/sync/sync.js +22 -9
  10. package/src/core/sync/ts.js +1 -1
  11. package/src/core/sync/write_app_types.js +1 -1
  12. package/src/core/sync/write_client_manifest.js +1 -1
  13. package/src/core/sync/write_server.js +1 -3
  14. package/src/core/sync/write_tsconfig/index.js +1 -1
  15. package/src/core/sync/write_types/index.js +6 -3
  16. package/src/exports/index.js +9 -9
  17. package/src/exports/internal/server/event.js +1 -1
  18. package/src/exports/internal/server/telemetry.js +1 -1
  19. package/src/exports/internal/shared.js +9 -0
  20. package/src/exports/{params.js → params/index.js} +6 -4
  21. package/src/exports/params/public.d.ts +63 -0
  22. package/src/exports/public.d.ts +77 -447
  23. package/src/exports/vite/build/build_server.js +2 -2
  24. package/src/exports/vite/dev/index.js +2 -3
  25. package/src/exports/vite/index.js +14 -3
  26. package/src/pathname.js +55 -0
  27. package/src/runtime/app/{forms.js → forms/index.js} +9 -8
  28. package/src/runtime/app/forms/public.d.ts +2 -0
  29. package/src/runtime/app/forms/types.d.ts +56 -0
  30. package/src/runtime/app/{navigation.js → navigation/index.js} +2 -2
  31. package/src/runtime/app/navigation/public.d.ts +237 -0
  32. package/src/runtime/app/paths/client.js +14 -8
  33. package/src/runtime/app/paths/index.js +1 -1
  34. package/src/runtime/app/paths/internal/client.js +4 -0
  35. package/src/runtime/app/paths/internal/server.js +4 -0
  36. package/src/runtime/app/paths/internal.d.ts +3 -0
  37. package/src/runtime/app/paths/public.d.ts +1 -1
  38. package/src/runtime/app/paths/server.js +6 -4
  39. package/src/runtime/app/server/index.js +1 -1
  40. package/src/runtime/app/server/remote/form.js +3 -4
  41. package/src/runtime/app/server/remote/prerender.js +3 -3
  42. package/src/runtime/app/server/remote/shared.js +3 -10
  43. package/src/runtime/app/state/index.js +4 -2
  44. package/src/runtime/app/state/public.d.ts +72 -0
  45. package/src/runtime/app/stores.js +2 -2
  46. package/src/runtime/client/client.js +65 -54
  47. package/src/runtime/client/entry.js +2 -2
  48. package/src/runtime/client/remote-functions/command.svelte.js +36 -34
  49. package/src/runtime/client/remote-functions/form.svelte.js +76 -78
  50. package/src/runtime/client/remote-functions/prerender.svelte.js +3 -3
  51. package/src/runtime/client/remote-functions/query/index.js +1 -1
  52. package/src/runtime/client/remote-functions/query/instance.svelte.js +4 -3
  53. package/src/runtime/client/remote-functions/query-batch.svelte.js +3 -3
  54. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -5
  55. package/src/runtime/client/remote-functions/query-live/iterator.js +5 -7
  56. package/src/runtime/client/remote-functions/shared.svelte.js +9 -14
  57. package/src/runtime/client/state.svelte.js +5 -3
  58. package/src/runtime/client/types.d.ts +2 -1
  59. package/src/runtime/pathname.js +6 -61
  60. package/src/runtime/props.svelte.js +1 -1
  61. package/src/runtime/server/constants.js +0 -3
  62. package/src/runtime/server/errors.js +53 -28
  63. package/src/runtime/server/fetch.js +1 -1
  64. package/src/runtime/server/index.js +9 -14
  65. package/src/runtime/server/page/actions.js +2 -1
  66. package/src/runtime/server/page/index.js +7 -3
  67. package/src/runtime/server/page/load_data.js +1 -1
  68. package/src/runtime/server/page/render.js +17 -11
  69. package/src/runtime/server/page/server_routing.js +3 -2
  70. package/src/runtime/server/remote-functions.js +3 -2
  71. package/src/runtime/server/respond.js +4 -8
  72. package/src/runtime/server/state.js +3 -6
  73. package/src/types/ambient.d.ts +1 -1
  74. package/src/types/internal.d.ts +8 -10
  75. package/src/types/private.d.ts +12 -3
  76. package/src/utils/error.js +30 -14
  77. package/src/utils/page_nodes.js +3 -2
  78. package/src/utils/params.js +3 -2
  79. package/src/utils/routing.js +5 -4
  80. package/src/version.js +1 -1
  81. package/types/index.d.ts +992 -932
  82. package/types/index.d.ts.map +43 -31
  83. /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
package/types/index.d.ts CHANGED
@@ -5,11 +5,24 @@ declare module '@sveltejs/kit' {
5
5
  import type { SvelteConfig } from '@sveltejs/vite-plugin-svelte';
6
6
  import type { StandardSchemaV1 } from '@standard-schema/spec';
7
7
  import type { Plugin } from 'vite';
8
- import type { RouteId as AppRouteId, LayoutParams as AppLayoutParams, ResolvedPathname } from '$app/types';
8
+ import type { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
9
9
  // @ts-ignore this is an optional peer dependency so could be missing. Written like this so dts-buddy preserves the ts-ignore
10
10
  type Span = import('@opentelemetry/api').Span;
11
11
 
12
- type AppErrorWithOptionalStatus = Omit<App.Error, 'status'> & { status?: App.Error['status'] };
12
+ type AppErrorWithOptionalDefaults = Omit<App.Error, 'status' | 'message'> & {
13
+ status?: App.Error['status'];
14
+ message?: App.Error['message'];
15
+ };
16
+
17
+ /**
18
+ * `void` is only a valid `handleError` return when `App.Error` adds no required properties
19
+ * beyond `status` and `message` — both of which are optional in the return, since they default
20
+ * to those of the caught error. If `App.Error` is augmented with required properties, the hook
21
+ * must return them, so returning nothing becomes a type error.
22
+ */
23
+ type VoidIfNoRequiredAppErrorProperties = { status: number; message: string } extends App.Error
24
+ ? void
25
+ : never;
13
26
 
14
27
  /**
15
28
  * [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.
@@ -922,45 +935,76 @@ declare module '@sveltejs/kit' {
922
935
  resolve: (event: RequestEvent, opts?: ResolveOptions) => Promise<Response>;
923
936
  }) => MaybePromise<Response>;
924
937
 
938
+ type CaughtErrorMap = {
939
+ app: App.Error;
940
+ framework: { status: number; message: string };
941
+ unknown: unknown;
942
+ };
943
+
944
+ type ValidationCaughtError<Issue extends StandardSchemaV1.Issue> = {
945
+ kind: 'validation';
946
+ error: { status: number; message: string };
947
+ issues: Issue[];
948
+ };
949
+
925
950
  /**
926
- * The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs when an unexpected error is thrown while responding to a request.
927
- *
928
- * If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
929
- * Make sure that this function _never_ throws an error.
930
- *
931
- * The returned object can include a `status` property to override the HTTP status code used in the response.
932
- * If omitted, the status defaults to 500.
951
+ * The error passed to the [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hooks.
952
+ * Use the `kind` discriminant to distinguish errors from your app (thrown with the
953
+ * [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper), errors generated by
954
+ * SvelteKit itself (such as 404s), validation errors, and unknown errors (thrown by your code,
955
+ * or code it calls).
933
956
  */
934
- export type HandleServerError = (input: {
935
- error: unknown;
936
- event: RequestEvent;
937
- status: number;
938
- message: string;
939
- }) => MaybePromise<void | AppErrorWithOptionalStatus>;
957
+ export type CaughtError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
958
+ | {
959
+ [Kind in keyof CaughtErrorMap]: {
960
+ /** Identifies the category and origin of the error */
961
+ kind: Kind;
962
+ /** The caught error. Its type depends on `kind` */
963
+ error: CaughtErrorMap[Kind];
964
+ /** Only present for validation errors */
965
+ issues?: undefined;
966
+ };
967
+ }[keyof CaughtErrorMap]
968
+ | ValidationCaughtError<Issue>;
969
+
970
+ /** The error passed to the client-side `handleError` hook. */
971
+ export type ClientCaughtError = Exclude<CaughtError, { kind: 'validation' }>;
940
972
 
941
973
  /**
942
- * The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#handleValidationError) hook runs when the argument to a remote function fails validation.
974
+ * The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs for every error thrown while responding to a request, except redirects.
975
+ *
976
+ * The `kind` property discriminates between _app_ errors (thrown with the [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper),
977
+ * _framework_ errors (generated by SvelteKit itself, such as 404s), _validation_ errors (caused by invalid remote function arguments)
978
+ * and _unknown_ errors (thrown by your code, or code it calls).
943
979
  *
944
- * It will be called with the validation issues and the event, and must return an object shape that matches `App.Error`.
980
+ * The hook returns an object matching `App.Error`, in which `status` and `message` are optional return them only to
981
+ * override the defaults. Omitted properties are inherited from the caught error: the body passed to `error(...)` for app errors,
982
+ * the status and safe message for framework and validation errors, and `500`/`'Internal Error'` for unknown errors. Return nothing to
983
+ * keep the defaults entirely (if you augment `App.Error` with required properties, you must return those).
984
+ *
985
+ * Make sure that this function _never_ throws an error.
945
986
  */
946
- export type HandleValidationError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
947
- (input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<AppErrorWithOptionalStatus>;
987
+ export type HandleServerError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> = (
988
+ input: CaughtError<Issue> & { event: RequestEvent }
989
+ ) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
948
990
 
949
991
  /**
950
- * The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs when an unexpected error is thrown while navigating.
992
+ * The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs for every error thrown while navigating, except redirects.
993
+ * Errors that were already transformed by the server-side hook are not passed to it a second time.
951
994
  *
952
- * If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
953
- * Make sure that this function _never_ throws an error.
995
+ * The `kind` property discriminates between _app_ errors (thrown with the [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper),
996
+ * _framework_ errors (generated by SvelteKit itself, such as 404s) and _unknown_ errors (thrown by your code, or code it calls).
997
+ *
998
+ * The hook returns an object matching `App.Error`, in which `status` and `message` are optional — return them only to
999
+ * override the defaults. Omitted properties are inherited from the caught error: the body passed to `error(...)` for app errors,
1000
+ * the status and safe message for framework errors, and `500`/`'Internal Error'` for unknown errors. Return nothing to
1001
+ * keep the defaults entirely (if you augment `App.Error` with required properties, you must return those).
954
1002
  *
955
- * The returned object can include a `status` property to override the HTTP status code used in the response.
956
- * If omitted, the status defaults to 500.
1003
+ * Make sure that this function _never_ throws an error.
957
1004
  */
958
- export type HandleClientError = (input: {
959
- error: unknown;
960
- event: NavigationEvent;
961
- status: number;
962
- message: string;
963
- }) => MaybePromise<void | AppErrorWithOptionalStatus>;
1005
+ export type HandleClientError = (
1006
+ input: ClientCaughtError & { event: NavigationEvent }
1007
+ ) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
964
1008
 
965
1009
  /**
966
1010
  * The [`handleFetch`](https://svelte.dev/docs/kit/hooks#handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
@@ -1187,810 +1231,401 @@ declare module '@sveltejs/kit' {
1187
1231
  }
1188
1232
 
1189
1233
  /**
1190
- * Information about the target of a specific navigation.
1234
+ * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1235
+ * when called with a regular `query`. `arg` is the validated argument (the input *after*
1236
+ * the query's schema validated and transformed it, if applicable); `query` is a
1237
+ * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
1238
+ * update the correct client entry.
1191
1239
  */
1192
- export interface NavigationTarget<
1193
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1194
- RouteId extends AppRouteId | null = AppRouteId | null
1195
- > {
1196
- /**
1197
- * Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1198
- * Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
1199
- */
1200
- params: Params | null;
1201
- /**
1202
- * Info about the target route
1203
- */
1204
- route: {
1240
+ export type RequestedEntry<Validated, Output> = {
1241
+ arg: Validated;
1242
+ query: RemoteQuery<Output>;
1243
+ };
1244
+
1245
+ /**
1246
+ * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1247
+ * when called with a `query.live`. `arg` is the validated argument; `query` is a
1248
+ * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
1249
+ * the correct client subscription.
1250
+ */
1251
+ export type LiveRequestedEntry<Validated, Output> = {
1252
+ arg: Validated;
1253
+ query: RemoteLiveQuery<Output>;
1254
+ };
1255
+
1256
+ export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
1257
+ AsyncIterable<RequestedEntry<Validated, Output>> & {
1205
1258
  /**
1206
- * 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.
1259
+ * Call `refresh` on all queries selected by this `requested` invocation.
1260
+ * This is identical to:
1261
+ * ```ts
1262
+ * import { requested } from '$app/server';
1263
+ *
1264
+ * for await (const { query } of requested(getPost, ...)) {
1265
+ * void query.refresh();
1266
+ * }
1267
+ * ```
1207
1268
  */
1208
- id: RouteId | null;
1269
+ refreshAll: () => Promise<void>;
1270
+ };
1271
+
1272
+ export type LiveQueryRequestedResult<Validated, Output> = Iterable<
1273
+ LiveRequestedEntry<Validated, Output>
1274
+ > &
1275
+ AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
1276
+ /**
1277
+ * Call `reconnect` on all live queries selected by this `requested` invocation.
1278
+ * This is identical to:
1279
+ * ```ts
1280
+ * import { requested } from '$app/server';
1281
+ *
1282
+ * for await (const { query } of requested(liveQuery, ...)) {
1283
+ * void query.reconnect();
1284
+ * }
1285
+ * ```
1286
+ */
1287
+ reconnectAll: () => Promise<void>;
1209
1288
  };
1289
+
1290
+ export type RequestedResult<Validated, Output> =
1291
+ | QueryRequestedResult<Validated, Output>
1292
+ | LiveQueryRequestedResult<Validated, Output>;
1293
+
1294
+ export interface RequestEvent<
1295
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1296
+ RouteId extends AppRouteId | null = AppRouteId | null
1297
+ > {
1210
1298
  /**
1211
- * The URL that is navigated to
1299
+ * Get or set cookies related to the current request
1212
1300
  */
1213
- url: URL;
1301
+ readonly cookies: Cookies;
1214
1302
  /**
1215
- * The scroll position associated with this navigation.
1303
+ * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
1216
1304
  *
1217
- * For the `from` target, this is the scroll position at the moment of navigation.
1305
+ * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
1306
+ * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
1307
+ * - Internal requests (e.g. for `+server.js` routes) go directly to the handler function when running on the server, without the overhead of an HTTP call.
1308
+ * - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://svelte.dev/docs/kit/hooks#handle)
1309
+ * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
1218
1310
  *
1219
- * For the `to` target, this represents the scroll position that will be or was restored:
1220
- * - In `beforeNavigate` and `onNavigate`, this is only available for `popstate` navigations (back/forward button)
1221
- * and will be `null` for other navigation types, since the final scroll position isn't known
1222
- * ahead of time.
1223
- * - In `afterNavigate`, this is always the scroll position that was applied after the navigation
1224
- * completed.
1311
+ * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
1225
1312
  */
1226
- scroll: { x: number; y: number } | null;
1227
- }
1228
-
1229
- export interface GotoOptions {
1313
+ readonly fetch: typeof fetch;
1230
1314
  /**
1231
- * If `true`, replaces the current history entry rather than creating a new one.
1232
- * @default false
1315
+ * The client's IP address, set by the adapter.
1233
1316
  */
1234
- replace?: boolean;
1235
- /** @deprecated Use `replace` instead. */
1236
- replaceState?: boolean;
1317
+ readonly getClientAddress: () => string;
1237
1318
  /**
1238
- * If `true`, updates the URL and `page.state` without navigating.
1239
- * @default false
1319
+ * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
1240
1320
  */
1241
- shallow?: boolean;
1321
+ readonly locals: App.Locals;
1242
1322
  /**
1243
- * If `true`, resets the scroll position (to the top of the page, or to the element
1244
- * matching the URL's `#hash` if there is one) and resets focus (to the `<body>`, or the
1245
- * `autofocus` element if there is one) once the navigation completes.
1323
+ * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1246
1324
  *
1247
- * If `false`, the current scroll position and focused element are left alone.
1248
- * @default true, or false when `shallow` is true
1249
- */
1250
- reset?: boolean;
1251
- /**
1252
- * If `true`, reruns all `load` functions and queries of the page.
1253
- * @default false
1325
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1326
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1327
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1328
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1254
1329
  */
1255
- refreshAll?: boolean;
1256
- /** Causes any `load` functions to rerun if they depend on one of the URLs. */
1257
- invalidate?: Array<string | URL | ((url: URL) => boolean)>;
1258
- /** @deprecated Use `refreshAll` instead. */
1259
- invalidateAll?: boolean;
1260
- /** An optional object that will be available as `page.state`. */
1261
- state?: App.PageState;
1330
+ readonly params: Params;
1262
1331
  /**
1263
- * If `true`, `page.state` will be restored after a full page reload.
1264
- * @default false
1332
+ * Additional data made available through the adapter.
1265
1333
  */
1266
- persistState?: boolean;
1267
- }
1268
-
1269
- /**
1270
- * - `enter`: The app has hydrated/started
1271
- * - `form`: The user submitted a `<form method="GET">`
1272
- * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1273
- * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1274
- * - `link`: Navigation was triggered by a link click
1275
- * - `popstate`: Navigation was triggered by back/forward navigation
1276
- */
1277
- export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
1278
-
1279
- export interface NavigationBase {
1334
+ readonly platform: Readonly<App.Platform> | undefined;
1280
1335
  /**
1281
- * The type of navigation:
1282
- * - `enter`: The app has hydrated/started
1283
- * - `form`: The user submitted a `<form method="GET">`
1284
- * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1285
- * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1286
- * - `link`: Navigation was triggered by a link click
1287
- * - `popstate`: Navigation was triggered by back/forward navigation
1336
+ * The original request object.
1288
1337
  */
1289
- type: NavigationType;
1290
- /** Whether this is a shallow navigation. */
1291
- shallow: boolean;
1338
+ readonly request: Request;
1292
1339
  /**
1293
- * Where navigation was triggered from
1340
+ * Info about the current route.
1294
1341
  */
1295
- from: NavigationTarget | null;
1342
+ readonly route: {
1343
+ /**
1344
+ * 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.
1345
+ *
1346
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1347
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1348
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1349
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1350
+ */
1351
+ id: RouteId;
1352
+ };
1296
1353
  /**
1297
- * Where navigation is going to/has gone to
1354
+ * If you need to set headers for the response, you can do so using the this method. This is useful if you want the page to be cached, for example:
1355
+ *
1356
+ * ```js
1357
+ * /// file: src/routes/blog/+page.js
1358
+ * export async function load({ fetch, setHeaders }) {
1359
+ * const url = `https://cms.example.com/articles.json`;
1360
+ * const response = await fetch(url);
1361
+ *
1362
+ * setHeaders({
1363
+ * age: response.headers.get('age'),
1364
+ * 'cache-control': response.headers.get('cache-control')
1365
+ * });
1366
+ *
1367
+ * return response.json();
1368
+ * }
1369
+ * ```
1370
+ *
1371
+ * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
1372
+ *
1373
+ * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/@sveltejs-kit#Cookies) API instead.
1298
1374
  */
1299
- to: NavigationTarget | null;
1375
+ readonly setHeaders: (headers: Record<string, string>) => void;
1300
1376
  /**
1301
- * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
1377
+ * The requested URL.
1378
+ *
1379
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1380
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1381
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1382
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1302
1383
  */
1303
- willUnload: boolean;
1384
+ readonly url: URL;
1304
1385
  /**
1305
- * A promise that resolves once the navigation is complete, and rejects if the navigation
1306
- * fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
1386
+ * `true` if the request comes from the client asking for `+page/layout.server.js` data. The `url` property will be stripped of the internal information
1387
+ * related to the data request in this case. Use this property instead if the distinction is important to you.
1307
1388
  */
1308
- complete: Promise<void>;
1309
- }
1310
-
1311
- /**
1312
- * The navigation that occurs when the app starts/hydrates
1313
- */
1314
- export interface NavigationEnter extends NavigationBase {
1315
- type: 'enter';
1316
-
1389
+ readonly isDataRequest: boolean;
1317
1390
  /**
1318
- * In case of a history back/forward navigation, the number of steps to go back/forward
1391
+ * `true` for `+server.js` calls coming from SvelteKit without the overhead of actually making an HTTP request. This happens when you make same-origin `fetch` requests on the server.
1319
1392
  */
1320
- delta?: undefined;
1393
+ readonly isSubRequest: boolean;
1321
1394
 
1322
1395
  /**
1323
- * Dispatched `Event` object when navigation occurred by `popstate` or `link`.
1396
+ * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
1397
+ * @since 2.31.0
1324
1398
  */
1325
- event?: undefined;
1326
- }
1399
+ readonly tracing: {
1400
+ /** Whether tracing is enabled. */
1401
+ enabled: boolean;
1402
+ /** The root span for the request. This span is named `sveltekit.handle.root`. */
1403
+ root: Span;
1404
+ /** The span associated with the current `handle` hook, `load` function, or form action. */
1405
+ current: Span;
1406
+ };
1327
1407
 
1328
- export type NavigationExternal = NavigationGoto | NavigationLeave;
1408
+ /**
1409
+ * `true` if the request comes from the client via a remote function. The `url` property will be stripped of the internal information
1410
+ * related to the data request in this case. Use this property instead if the distinction is important to you.
1411
+ */
1412
+ readonly isRemoteRequest: boolean;
1413
+ }
1329
1414
 
1330
1415
  /**
1331
- * A navigation triggered by a `goto(...)` call or a redirect
1416
+ * A `(event: RequestEvent) => Response` function exported from a `+server.js` file that corresponds to an HTTP verb (`GET`, `PUT`, `PATCH`, etc) and handles requests with that method.
1417
+ *
1418
+ * It receives `Params` as the first generic argument, which you can skip by using [generated types](https://svelte.dev/docs/kit/types#Generated-types) instead.
1332
1419
  */
1333
- export interface NavigationGoto extends NavigationBase {
1334
- type: 'goto';
1420
+ export type RequestHandler<
1421
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1422
+ RouteId extends AppRouteId | null = AppRouteId | null
1423
+ > = (event: RequestEvent<Params, RouteId>) => MaybePromise<Response>;
1424
+
1425
+ export interface ResolveOptions {
1426
+ /**
1427
+ * Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
1428
+ * (they could include an element's opening tag but not its closing tag, for example)
1429
+ * but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
1430
+ * @param input the html chunk and the info if this is the last chunk
1431
+ */
1432
+ transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
1433
+ /**
1434
+ * Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
1435
+ * By default, none will be included.
1436
+ * @param name header name
1437
+ * @param value header value
1438
+ */
1439
+ filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
1440
+ /**
1441
+ * Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
1442
+ * `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
1443
+ * [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
1444
+ * By default, `js` and `css` files will be preloaded.
1445
+ * @param input the type of the file and its path
1446
+ */
1447
+ preload?: (input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }) => boolean;
1335
1448
  }
1336
1449
 
1337
- /**
1338
- * A navigation triggered by the tab being closed, or the user navigating to a different document
1339
- */
1340
- export interface NavigationLeave extends NavigationBase {
1341
- type: 'leave';
1450
+ export interface RouteDefinition<Config = any> {
1451
+ id: string;
1452
+ api: {
1453
+ methods: Array<HttpMethod | '*'>;
1454
+ };
1455
+ page: {
1456
+ methods: Array<Extract<HttpMethod, 'GET' | 'POST'>>;
1457
+ };
1458
+ pattern: RegExp;
1459
+ prerender: PrerenderOption;
1460
+ segments: RouteSegment[];
1461
+ methods: Array<HttpMethod | '*'>;
1462
+ config: Config;
1463
+ }
1464
+
1465
+ export class Server {
1466
+ constructor(manifest: SSRManifest);
1467
+ init(options: ServerInitOptions): Promise<void>;
1468
+ respond(request: Request, options: RequestOptions): Promise<Response>;
1469
+ }
1470
+
1471
+ export interface ServerInitOptions {
1472
+ /** A map of environment variables. */
1473
+ env: Record<string, string | undefined>;
1474
+ /** A function that turns an asset filename into a `ReadableStream`. Required for the `read` export from `$app/server` to work. */
1475
+ read?: (file: string) => MaybePromise<ReadableStream | null>;
1342
1476
  }
1343
1477
 
1344
1478
  /**
1345
- * A navigation triggered by a `<form method="GET">`
1479
+ * Information required to instantiate a new `Server` instance.
1346
1480
  */
1347
- export interface NavigationFormSubmit extends NavigationBase {
1348
- type: 'form';
1349
-
1350
- /**
1351
- * The `SubmitEvent` that caused the navigation
1352
- */
1353
- event: SubmitEvent;
1481
+ export interface SSRManifest {
1482
+ /** The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes. */
1483
+ appDir: string;
1484
+ /** The `base` and `appDir` settings combined without a leading slash. */
1485
+ appPath: string;
1486
+ /** Static files from `config.files.assets` and the service worker (if any). */
1487
+ assets: Set<string>;
1488
+ mimeTypes: Record<string, string>;
1354
1489
  }
1355
1490
 
1356
1491
  /**
1357
- * A navigation triggered by back/forward navigation
1492
+ * The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://svelte.dev/docs/kit/types#Generated-types))
1493
+ * rather than using `ServerLoad` directly.
1358
1494
  */
1359
- export interface NavigationPopState extends NavigationBase {
1360
- type: 'popstate';
1495
+ export type ServerLoad<
1496
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1497
+ ParentData extends Record<string, any> = Record<string, any>,
1498
+ OutputData extends Record<string, any> | void = Record<string, any> | void,
1499
+ RouteId extends AppRouteId | null = AppRouteId | null
1500
+ > = (event: ServerLoadEvent<Params, ParentData, RouteId>) => MaybePromise<OutputData>;
1361
1501
 
1502
+ export interface ServerLoadEvent<
1503
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1504
+ ParentData extends Record<string, any> = Record<string, any>,
1505
+ RouteId extends AppRouteId | null = AppRouteId | null
1506
+ > extends RequestEvent<Params, RouteId> {
1362
1507
  /**
1363
- * In case of a history back/forward navigation, the number of steps to go back/forward
1508
+ * `await parent()` returns data from parent `+layout.server.js` `load` functions.
1509
+ *
1510
+ * Be careful not to introduce accidental waterfalls when using `await parent()`. If for example you only want to merge parent data into the returned output, call it _after_ fetching your other data.
1364
1511
  */
1365
- delta: number;
1366
-
1512
+ parent: () => Promise<ParentData>;
1367
1513
  /**
1368
- * The `PopStateEvent` that caused the navigation
1514
+ * This function declares that the `load` function has a _dependency_ on one or more URLs or custom identifiers, which can subsequently be used with [`invalidate()`](https://svelte.dev/docs/kit/$app-navigation#invalidate) to cause `load` to rerun.
1515
+ *
1516
+ * Most of the time you won't need this, as `fetch` calls `depends` on your behalf — it's only necessary if you're using a custom API client that bypasses `fetch`.
1517
+ *
1518
+ * URLs can be absolute or relative to the page being loaded, and must be [encoded](https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding).
1519
+ *
1520
+ * Custom identifiers have to be prefixed with one or more lowercase letters followed by a colon to conform to the [URI specification](https://www.rfc-editor.org/rfc/rfc3986.html).
1521
+ *
1522
+ * The following example shows how to use `depends` to register a dependency on a custom identifier, which is `invalidate`d after a button click, making the `load` function rerun.
1523
+ *
1524
+ * ```js
1525
+ * /// file: src/routes/+page.js
1526
+ * let count = 0;
1527
+ * export async function load({ depends }) {
1528
+ * depends('increase:count');
1529
+ *
1530
+ * return { count: count++ };
1531
+ * }
1532
+ * ```
1533
+ *
1534
+ * ```html
1535
+ * /// file: src/routes/+page.svelte
1536
+ * <script>
1537
+ * import { invalidate } from '$app/navigation';
1538
+ *
1539
+ * let { data } = $props();
1540
+ *
1541
+ * const increase = async () => {
1542
+ * await invalidate('increase:count');
1543
+ * }
1544
+ * </script>
1545
+ *
1546
+ * <p>{data.count}<p>
1547
+ * <button on:click={increase}>Increase Count</button>
1548
+ * ```
1369
1549
  */
1370
- event: PopStateEvent;
1371
- }
1372
-
1373
- /**
1374
- * A navigation triggered by a link click
1375
- */
1376
- export interface NavigationLink extends NavigationBase {
1377
- type: 'link';
1550
+ depends: (...deps: string[]) => void;
1551
+ /**
1552
+ * Use this function to opt out of dependency tracking for everything that is synchronously called within the callback. Example:
1553
+ *
1554
+ * ```js
1555
+ * /// file: src/routes/+page.js
1556
+ * export async function load({ untrack, url }) {
1557
+ * // Untrack url.pathname so that path changes don't trigger a rerun
1558
+ * if (untrack(() => url.pathname === '/')) {
1559
+ * return { message: 'Welcome!' };
1560
+ * }
1561
+ * }
1562
+ * ```
1563
+ */
1564
+ untrack: <T>(fn: () => T) => T;
1378
1565
 
1379
1566
  /**
1380
- * The `PointerEvent` that caused the navigation
1567
+ * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
1568
+ * @since 2.31.0
1381
1569
  */
1382
- event: PointerEvent;
1570
+ tracing: {
1571
+ /** Whether tracing is enabled. */
1572
+ enabled: boolean;
1573
+ /** The root span for the request. This span is named `sveltekit.handle.root`. */
1574
+ root: Span;
1575
+ /** The span associated with the current server `load` function. */
1576
+ current: Span;
1577
+ };
1383
1578
  }
1384
1579
 
1385
- export type Navigation =
1386
- NavigationExternal | NavigationFormSubmit | NavigationPopState | NavigationLink;
1580
+ /**
1581
+ * Shape of a form action method that is part of `export const actions = {...}` in `+page.server.js`.
1582
+ * See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
1583
+ */
1584
+ export type Action<
1585
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1586
+ OutputData extends Record<string, any> | void = Record<string, any> | void,
1587
+ RouteId extends AppRouteId | null = AppRouteId | null
1588
+ > = (event: RequestEvent<Params, RouteId>) => MaybePromise<OutputData>;
1387
1589
 
1388
1590
  /**
1389
- * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
1591
+ * Shape of the `export const actions = {...}` object in `+page.server.js`.
1592
+ * See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
1390
1593
  */
1391
- export type BeforeNavigate = Navigation & {
1392
- /**
1393
- * Call this to prevent the navigation from starting.
1394
- */
1395
- cancel: () => void;
1396
- };
1594
+ export type Actions<
1595
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1596
+ OutputData extends Record<string, any> | void = Record<string, any> | void,
1597
+ RouteId extends AppRouteId | null = AppRouteId | null
1598
+ > = Record<string, Action<Params, OutputData, RouteId>>;
1397
1599
 
1398
1600
  /**
1399
- * The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
1601
+ * The object returned by the [`error`](https://svelte.dev/docs/kit/@sveltejs-kit#error) function.
1400
1602
  */
1401
- export type OnNavigate = Navigation & {
1402
- type: Exclude<NavigationType, 'enter' | 'leave'>;
1403
- /**
1404
- * Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
1405
- */
1406
- willUnload: false;
1407
- };
1603
+ export interface HttpError {
1604
+ /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
1605
+ status: number;
1606
+ /** The content of the error. */
1607
+ body: App.Error;
1608
+ }
1408
1609
 
1409
1610
  /**
1410
- * The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
1611
+ * The object returned by the [`redirect`](https://svelte.dev/docs/kit/@sveltejs-kit#redirect) function.
1411
1612
  */
1412
- export type AfterNavigate = (Navigation | NavigationEnter) & {
1413
- type: Exclude<NavigationType, 'leave'>;
1414
- /**
1415
- * Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
1416
- */
1417
- willUnload: false;
1418
- };
1613
+ export interface Redirect {
1614
+ /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
1615
+ status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
1616
+ /** The location to redirect to. */
1617
+ location: string;
1618
+ }
1419
1619
 
1420
1620
  /**
1421
- * The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object.
1422
- */
1423
- export interface Page<
1424
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1425
- RouteId extends AppRouteId | null = AppRouteId | null
1426
- > {
1427
- /**
1428
- * The URL of the current page.
1429
- */
1430
- url: ReadonlyURL & { readonly pathname: ResolvedPathname | (string & {}) };
1431
- /**
1432
- * The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1433
- */
1434
- params: Params;
1435
- /**
1436
- * Info about the current route.
1437
- */
1438
- route: {
1439
- /**
1440
- * 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.
1441
- */
1442
- id: RouteId;
1443
- };
1444
- /**
1445
- * HTTP status code of the current page.
1446
- */
1447
- status: number;
1448
- /**
1449
- * The error object of the current page, if any. Filled from the `handleError` hooks.
1450
- */
1451
- error: App.Error | null;
1452
- /**
1453
- * The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
1454
- */
1455
- data: App.PageData & Record<string, any>;
1456
- /**
1457
- * The page state, which can be manipulated using [`goto`](https://svelte.dev/docs/kit/$app-navigation#goto) from `$app/navigation`.
1458
- */
1459
- state: App.PageState;
1460
- /**
1461
- * Information about the target of the current shallow navigation, or `null` if no shallow navigation has occurred.
1462
- */
1463
- shallow: {
1464
- /** Parameters of the target route, or `null` if the URL does not resolve to a route. */
1465
- params: AppLayoutParams<'/'> | null;
1466
- /** Info about the target route, or `null` if the URL does not resolve to a route. */
1467
- route: { id: AppRouteId } | null;
1468
- /** The normalized URL passed to `goto(..., { shallow: true })`. */
1469
- url: ReadonlyURL;
1470
- } | null;
1471
- /**
1472
- * Filled only after a form submission. See [form actions](https://svelte.dev/docs/kit/form-actions) for more info.
1473
- */
1474
- form: any;
1475
- }
1476
-
1477
- /**
1478
- * The shape of a param matcher. See [matching](https://svelte.dev/docs/kit/advanced-routing#Matching) for more info.
1479
- */
1480
- export type ParamMatcher<Output = any> = StandardSchemaV1<string, Output>;
1481
-
1482
- /**
1483
- * A value that can be parsed from a URL param and losslessly encoded with `String(...)`.
1484
- */
1485
- export type ParamValue = string | number | boolean | bigint;
1486
-
1487
- /**
1488
- * A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
1489
- */
1490
- export type ParamDefinition =
1491
- ((param: string) => ParamValue | undefined) | StandardSchemaV1<string, ParamValue>;
1492
-
1493
- /**
1494
- * The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
1495
- */
1496
- export type DefinedParams<T extends Record<string, ParamDefinition>> = {
1497
- readonly [K in keyof T]: ParamEntry<T[K]>;
1498
- };
1499
-
1500
- /**
1501
- * Normalizes a property of defineParams (schema or function) to standard schema.
1502
- */
1503
- type ParamEntry<M> =
1504
- M extends StandardSchemaV1<any, any>
1505
- ? StandardSchemaV1.InferOutput<M> extends ParamValue
1506
- ? StandardSchemaV1<any, M>
1507
- : StandardSchemaV1<any, never>
1508
- : M extends (param: string) => infer R
1509
- ? Exclude<R, undefined> extends ParamValue
1510
- ? StandardSchemaV1<any, Exclude<R, undefined>>
1511
- : StandardSchemaV1<any, never>
1512
- : never;
1513
-
1514
- /**
1515
- * Extracts the param type from a matcher.
1516
- */
1517
- export type MatcherParam<M extends StandardSchemaV1<any, any>> =
1518
- M extends StandardSchemaV1<any, infer Inner>
1519
- ? Inner extends ParamValue
1520
- ? Inner
1521
- : Inner extends StandardSchemaV1<any, any>
1522
- ? StandardSchemaV1.InferOutput<Inner> extends ParamValue
1523
- ? StandardSchemaV1.InferOutput<Inner>
1524
- : never
1525
- : never
1526
- : never;
1527
-
1528
- /**
1529
- * Define [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching) for your app.
1530
- *
1531
- * */
1532
- export function defineParams<T extends Record<string, ParamDefinition>>(
1533
- definitions: T
1534
- ): DefinedParams<T>;
1535
-
1536
- /**
1537
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1538
- * when called with a regular `query`. `arg` is the validated argument (the input *after*
1539
- * the query's schema validated and transformed it, if applicable); `query` is a
1540
- * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
1541
- * update the correct client entry.
1542
- */
1543
- export type RequestedEntry<Validated, Output> = {
1544
- arg: Validated;
1545
- query: RemoteQuery<Output>;
1546
- };
1547
-
1548
- /**
1549
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1550
- * when called with a `query.live`. `arg` is the validated argument; `query` is a
1551
- * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
1552
- * the correct client subscription.
1553
- */
1554
- export type LiveRequestedEntry<Validated, Output> = {
1555
- arg: Validated;
1556
- query: RemoteLiveQuery<Output>;
1557
- };
1558
-
1559
- export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
1560
- AsyncIterable<RequestedEntry<Validated, Output>> & {
1561
- /**
1562
- * Call `refresh` on all queries selected by this `requested` invocation.
1563
- * This is identical to:
1564
- * ```ts
1565
- * import { requested } from '$app/server';
1566
- *
1567
- * for await (const { query } of requested(getPost, ...)) {
1568
- * void query.refresh();
1569
- * }
1570
- * ```
1571
- */
1572
- refreshAll: () => Promise<void>;
1573
- };
1574
-
1575
- export type LiveQueryRequestedResult<Validated, Output> = Iterable<
1576
- LiveRequestedEntry<Validated, Output>
1577
- > &
1578
- AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
1579
- /**
1580
- * Call `reconnect` on all live queries selected by this `requested` invocation.
1581
- * This is identical to:
1582
- * ```ts
1583
- * import { requested } from '$app/server';
1584
- *
1585
- * for await (const { query } of requested(liveQuery, ...)) {
1586
- * void query.reconnect();
1587
- * }
1588
- * ```
1589
- */
1590
- reconnectAll: () => Promise<void>;
1591
- };
1592
-
1593
- export type RequestedResult<Validated, Output> =
1594
- QueryRequestedResult<Validated, Output> | LiveQueryRequestedResult<Validated, Output>;
1595
-
1596
- export interface RequestEvent<
1597
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1598
- RouteId extends AppRouteId | null = AppRouteId | null
1599
- > {
1600
- /**
1601
- * Get or set cookies related to the current request
1602
- */
1603
- readonly cookies: Cookies;
1604
- /**
1605
- * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
1606
- *
1607
- * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
1608
- * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
1609
- * - Internal requests (e.g. for `+server.js` routes) go directly to the handler function when running on the server, without the overhead of an HTTP call.
1610
- * - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://svelte.dev/docs/kit/hooks#handle)
1611
- * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
1612
- *
1613
- * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
1614
- */
1615
- readonly fetch: typeof fetch;
1616
- /**
1617
- * The client's IP address, set by the adapter.
1618
- */
1619
- readonly getClientAddress: () => string;
1620
- /**
1621
- * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
1622
- */
1623
- readonly locals: App.Locals;
1624
- /**
1625
- * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1626
- *
1627
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1628
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1629
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1630
- * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1631
- */
1632
- readonly params: Params;
1633
- /**
1634
- * Additional data made available through the adapter.
1635
- */
1636
- readonly platform: Readonly<App.Platform> | undefined;
1637
- /**
1638
- * The original request object.
1639
- */
1640
- readonly request: Request;
1641
- /**
1642
- * Info about the current route.
1643
- */
1644
- readonly route: {
1645
- /**
1646
- * 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.
1647
- *
1648
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1649
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1650
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1651
- * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1652
- */
1653
- id: RouteId;
1654
- };
1655
- /**
1656
- * If you need to set headers for the response, you can do so using the this method. This is useful if you want the page to be cached, for example:
1657
- *
1658
- * ```js
1659
- * /// file: src/routes/blog/+page.js
1660
- * export async function load({ fetch, setHeaders }) {
1661
- * const url = `https://cms.example.com/articles.json`;
1662
- * const response = await fetch(url);
1663
- *
1664
- * setHeaders({
1665
- * age: response.headers.get('age'),
1666
- * 'cache-control': response.headers.get('cache-control')
1667
- * });
1668
- *
1669
- * return response.json();
1670
- * }
1671
- * ```
1672
- *
1673
- * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
1674
- *
1675
- * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/@sveltejs-kit#Cookies) API instead.
1676
- */
1677
- readonly setHeaders: (headers: Record<string, string>) => void;
1678
- /**
1679
- * The requested URL.
1680
- *
1681
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1682
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1683
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1684
- * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1685
- */
1686
- readonly url: URL;
1687
- /**
1688
- * `true` if the request comes from the client asking for `+page/layout.server.js` data. The `url` property will be stripped of the internal information
1689
- * related to the data request in this case. Use this property instead if the distinction is important to you.
1690
- */
1691
- readonly isDataRequest: boolean;
1692
- /**
1693
- * `true` for `+server.js` calls coming from SvelteKit without the overhead of actually making an HTTP request. This happens when you make same-origin `fetch` requests on the server.
1694
- */
1695
- readonly isSubRequest: boolean;
1696
-
1697
- /**
1698
- * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
1699
- * @since 2.31.0
1700
- */
1701
- readonly tracing: {
1702
- /** Whether tracing is enabled. */
1703
- enabled: boolean;
1704
- /** The root span for the request. This span is named `sveltekit.handle.root`. */
1705
- root: Span;
1706
- /** The span associated with the current `handle` hook, `load` function, or form action. */
1707
- current: Span;
1708
- };
1709
-
1710
- /**
1711
- * `true` if the request comes from the client via a remote function. The `url` property will be stripped of the internal information
1712
- * related to the data request in this case. Use this property instead if the distinction is important to you.
1713
- */
1714
- readonly isRemoteRequest: boolean;
1715
- }
1716
-
1717
- /**
1718
- * A `(event: RequestEvent) => Response` function exported from a `+server.js` file that corresponds to an HTTP verb (`GET`, `PUT`, `PATCH`, etc) and handles requests with that method.
1719
- *
1720
- * It receives `Params` as the first generic argument, which you can skip by using [generated types](https://svelte.dev/docs/kit/types#Generated-types) instead.
1721
- */
1722
- export type RequestHandler<
1723
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1724
- RouteId extends AppRouteId | null = AppRouteId | null
1725
- > = (event: RequestEvent<Params, RouteId>) => MaybePromise<Response>;
1726
-
1727
- export interface ResolveOptions {
1728
- /**
1729
- * Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
1730
- * (they could include an element's opening tag but not its closing tag, for example)
1731
- * but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
1732
- * @param input the html chunk and the info if this is the last chunk
1733
- */
1734
- transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
1735
- /**
1736
- * Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
1737
- * By default, none will be included.
1738
- * @param name header name
1739
- * @param value header value
1740
- */
1741
- filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
1742
- /**
1743
- * Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
1744
- * `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
1745
- * [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
1746
- * By default, `js` and `css` files will be preloaded.
1747
- * @param input the type of the file and its path
1748
- */
1749
- preload?: (input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }) => boolean;
1750
- }
1751
-
1752
- export interface RouteDefinition<Config = any> {
1753
- id: string;
1754
- api: {
1755
- methods: Array<HttpMethod | '*'>;
1756
- };
1757
- page: {
1758
- methods: Array<Extract<HttpMethod, 'GET' | 'POST'>>;
1759
- };
1760
- pattern: RegExp;
1761
- prerender: PrerenderOption;
1762
- segments: RouteSegment[];
1763
- methods: Array<HttpMethod | '*'>;
1764
- config: Config;
1765
- }
1766
-
1767
- export class Server {
1768
- constructor(manifest: SSRManifest);
1769
- init(options: ServerInitOptions): Promise<void>;
1770
- respond(request: Request, options: RequestOptions): Promise<Response>;
1771
- }
1772
-
1773
- export interface ServerInitOptions {
1774
- /** A map of environment variables. */
1775
- env: Record<string, string | undefined>;
1776
- /** A function that turns an asset filename into a `ReadableStream`. Required for the `read` export from `$app/server` to work. */
1777
- read?: (file: string) => MaybePromise<ReadableStream | null>;
1778
- }
1779
-
1780
- /**
1781
- * Information required to instantiate a new `Server` instance.
1782
- */
1783
- export interface SSRManifest {
1784
- /** The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes. */
1785
- appDir: string;
1786
- /** The `base` and `appDir` settings combined without a leading slash. */
1787
- appPath: string;
1788
- /** Static files from `config.files.assets` and the service worker (if any). */
1789
- assets: Set<string>;
1790
- mimeTypes: Record<string, string>;
1791
- }
1792
-
1793
- /**
1794
- * The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://svelte.dev/docs/kit/types#Generated-types))
1795
- * rather than using `ServerLoad` directly.
1796
- */
1797
- export type ServerLoad<
1798
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1799
- ParentData extends Record<string, any> = Record<string, any>,
1800
- OutputData extends Record<string, any> | void = Record<string, any> | void,
1801
- RouteId extends AppRouteId | null = AppRouteId | null
1802
- > = (event: ServerLoadEvent<Params, ParentData, RouteId>) => MaybePromise<OutputData>;
1803
-
1804
- export interface ServerLoadEvent<
1805
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1806
- ParentData extends Record<string, any> = Record<string, any>,
1807
- RouteId extends AppRouteId | null = AppRouteId | null
1808
- > extends RequestEvent<Params, RouteId> {
1809
- /**
1810
- * `await parent()` returns data from parent `+layout.server.js` `load` functions.
1811
- *
1812
- * Be careful not to introduce accidental waterfalls when using `await parent()`. If for example you only want to merge parent data into the returned output, call it _after_ fetching your other data.
1813
- */
1814
- parent: () => Promise<ParentData>;
1815
- /**
1816
- * This function declares that the `load` function has a _dependency_ on one or more URLs or custom identifiers, which can subsequently be used with [`invalidate()`](https://svelte.dev/docs/kit/$app-navigation#invalidate) to cause `load` to rerun.
1817
- *
1818
- * Most of the time you won't need this, as `fetch` calls `depends` on your behalf — it's only necessary if you're using a custom API client that bypasses `fetch`.
1819
- *
1820
- * URLs can be absolute or relative to the page being loaded, and must be [encoded](https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding).
1821
- *
1822
- * Custom identifiers have to be prefixed with one or more lowercase letters followed by a colon to conform to the [URI specification](https://www.rfc-editor.org/rfc/rfc3986.html).
1823
- *
1824
- * The following example shows how to use `depends` to register a dependency on a custom identifier, which is `invalidate`d after a button click, making the `load` function rerun.
1825
- *
1826
- * ```js
1827
- * /// file: src/routes/+page.js
1828
- * let count = 0;
1829
- * export async function load({ depends }) {
1830
- * depends('increase:count');
1831
- *
1832
- * return { count: count++ };
1833
- * }
1834
- * ```
1835
- *
1836
- * ```html
1837
- * /// file: src/routes/+page.svelte
1838
- * <script>
1839
- * import { invalidate } from '$app/navigation';
1840
- *
1841
- * let { data } = $props();
1842
- *
1843
- * const increase = async () => {
1844
- * await invalidate('increase:count');
1845
- * }
1846
- * </script>
1847
- *
1848
- * <p>{data.count}<p>
1849
- * <button on:click={increase}>Increase Count</button>
1850
- * ```
1851
- */
1852
- depends: (...deps: string[]) => void;
1853
- /**
1854
- * Use this function to opt out of dependency tracking for everything that is synchronously called within the callback. Example:
1855
- *
1856
- * ```js
1857
- * /// file: src/routes/+page.js
1858
- * export async function load({ untrack, url }) {
1859
- * // Untrack url.pathname so that path changes don't trigger a rerun
1860
- * if (untrack(() => url.pathname === '/')) {
1861
- * return { message: 'Welcome!' };
1862
- * }
1863
- * }
1864
- * ```
1865
- */
1866
- untrack: <T>(fn: () => T) => T;
1867
-
1868
- /**
1869
- * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
1870
- * @since 2.31.0
1871
- */
1872
- tracing: {
1873
- /** Whether tracing is enabled. */
1874
- enabled: boolean;
1875
- /** The root span for the request. This span is named `sveltekit.handle.root`. */
1876
- root: Span;
1877
- /** The span associated with the current server `load` function. */
1878
- current: Span;
1879
- };
1880
- }
1881
-
1882
- /**
1883
- * Shape of a form action method that is part of `export const actions = {...}` in `+page.server.js`.
1884
- * See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
1885
- */
1886
- export type Action<
1887
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1888
- OutputData extends Record<string, any> | void = Record<string, any> | void,
1889
- RouteId extends AppRouteId | null = AppRouteId | null
1890
- > = (event: RequestEvent<Params, RouteId>) => MaybePromise<OutputData>;
1891
-
1892
- /**
1893
- * Shape of the `export const actions = {...}` object in `+page.server.js`.
1894
- * See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
1895
- */
1896
- export type Actions<
1897
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1898
- OutputData extends Record<string, any> | void = Record<string, any> | void,
1899
- RouteId extends AppRouteId | null = AppRouteId | null
1900
- > = Record<string, Action<Params, OutputData, RouteId>>;
1901
-
1902
- /**
1903
- * When calling a form action via fetch, the response will be one of these shapes.
1904
- * ```svelte
1905
- * <form method="post" use:enhance={() => {
1906
- * return ({ result }) => {
1907
- * // result is of type ActionResult
1908
- * };
1909
- * }}
1910
- * ```
1911
- *
1912
- * Success and failure results carry the root-relative `pathname + search` of the action URL, with
1913
- * the `?/actionName` parameter removed. Redirect results carry the redirect target. Server-generated
1914
- * error results also carry the action location, while client-generated errors such as network
1915
- * failures do not. `update` uses this location to emulate native form navigation.
1916
- */
1917
- export type ActionResult<
1918
- Success extends Record<string, unknown> | undefined = Record<string, any>,
1919
- Failure extends Record<string, unknown> | undefined = Record<string, any>
1920
- > =
1921
- | { type: 'success'; status: number; data?: Success; location: string }
1922
- | { type: 'failure'; status: number; data?: Failure; location: string }
1923
- | { type: 'redirect'; status: number; location: string }
1924
- | { type: 'error'; status?: number; error: App.Error; location?: string };
1925
-
1926
- /**
1927
- * The object returned by the [`error`](https://svelte.dev/docs/kit/@sveltejs-kit#error) function.
1928
- */
1929
- export interface HttpError {
1930
- /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
1931
- status: number;
1932
- /** The content of the error. */
1933
- body: App.Error;
1934
- }
1935
-
1936
- /**
1937
- * The object returned by the [`redirect`](https://svelte.dev/docs/kit/@sveltejs-kit#redirect) function.
1938
- */
1939
- export interface Redirect {
1940
- /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
1941
- status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
1942
- /** The location to redirect to. */
1943
- location: string;
1944
- }
1945
-
1946
- export type SubmitFunction<
1947
- Success extends Record<string, unknown> | undefined = Record<string, any>,
1948
- Failure extends Record<string, unknown> | undefined = Record<string, any>
1949
- > = (input: {
1950
- action: URL;
1951
- formData: FormData;
1952
- formElement: HTMLFormElement;
1953
- controller: AbortController;
1954
- submitter: HTMLElement | null;
1955
- cancel: () => void;
1956
- }) => MaybePromise<
1957
- | void
1958
- | ((opts: {
1959
- formData: FormData;
1960
- formElement: HTMLFormElement;
1961
- action: URL;
1962
- result: ActionResult<Success, Failure>;
1963
- /**
1964
- * Call this to get the default behavior of a form submission response.
1965
- * @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission. `refreshAll` defaults to `true` for successful results and `false` for failures. When the submission navigates, setting it to `false` still runs the destination's `load` functions but may reuse shared layout data. Set `navigate: false` to apply non-redirect results to the current page instead of navigating to `result.location`. Redirects are always followed.
1966
- */
1967
- update: (options?: {
1968
- reset?: boolean;
1969
- refreshAll?: boolean;
1970
- navigate?: boolean;
1971
- /** @deprecated Use `refreshAll` instead. */
1972
- invalidateAll?: boolean;
1973
- }) => Promise<void>;
1974
- }) => MaybePromise<void>)
1975
- >;
1976
-
1977
- /**
1978
- * The type of `export const snapshot` exported from a page or layout component.
1979
- * @deprecated Use the [`snapshot`](https://svelte.dev/docs/kit/$app-navigation#snapshot) helper from `$app/navigation` instead.
1621
+ * The type of `export const snapshot` exported from a page or layout component.
1622
+ * @deprecated Use the [`snapshot`](https://svelte.dev/docs/kit/$app-navigation#snapshot) helper from `$app/navigation` instead.
1980
1623
  */
1981
1624
  export interface Snapshot<T = any> {
1982
1625
  capture: () => T;
1983
1626
  restore: (snapshot: T) => void;
1984
1627
  }
1985
1628
 
1986
- export type ReadonlyURLSearchParams = Omit<URLSearchParams, 'set' | 'append' | 'delete' | 'sort'>;
1987
-
1988
- export type ReadonlyURL = Readonly<
1989
- Omit<URL, 'searchParams'> & {
1990
- searchParams: ReadonlyURLSearchParams;
1991
- }
1992
- >;
1993
-
1994
1629
  // If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
1995
1630
  type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
1996
1631
 
@@ -2731,11 +2366,20 @@ declare module '@sveltejs/kit' {
2731
2366
  type PrerenderHttpErrorHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderHttpErrorHandler;
2732
2367
  type PrerenderMissingIdHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderMissingIdHandler;
2733
2368
  type PrerenderUnseenRoutesHandlerValue =
2734
- 'fail' | 'warn' | 'ignore' | PrerenderUnseenRoutesHandler;
2369
+ | 'fail'
2370
+ | 'warn'
2371
+ | 'ignore'
2372
+ | PrerenderUnseenRoutesHandler;
2735
2373
  type PrerenderEntryGeneratorMismatchHandlerValue =
2736
- 'fail' | 'warn' | 'ignore' | PrerenderEntryGeneratorMismatchHandler;
2374
+ | 'fail'
2375
+ | 'warn'
2376
+ | 'ignore'
2377
+ | PrerenderEntryGeneratorMismatchHandler;
2737
2378
  type PrerenderInvalidUrlHandlerValue =
2738
- 'fail' | 'warn' | 'ignore' | PrerenderInvalidUrlHandler;
2379
+ | 'fail'
2380
+ | 'warn'
2381
+ | 'ignore'
2382
+ | PrerenderInvalidUrlHandler;
2739
2383
 
2740
2384
  export type PrerenderOption = boolean | 'auto';
2741
2385
 
@@ -2777,7 +2421,7 @@ declare module '@sveltejs/kit' {
2777
2421
  /**
2778
2422
  * Throws an error with a HTTP status code and an optional message.
2779
2423
  * When called during request handling, this will cause SvelteKit to
2780
- * return an error response without invoking `handleError`.
2424
+ * return an error response; the error will be passed to `handleError` as an _expected_ error.
2781
2425
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2782
2426
  * @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.
2783
2427
  * @param message The error message.
@@ -2791,7 +2435,7 @@ declare module '@sveltejs/kit' {
2791
2435
  /**
2792
2436
  * Throws an error with a HTTP status code and an optional message.
2793
2437
  * When called during request handling, this will cause SvelteKit to
2794
- * return an error response without invoking `handleError`.
2438
+ * return an error response; the error will be passed to `handleError` as an _expected_ error.
2795
2439
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2796
2440
  * @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.
2797
2441
  * @param message The error message.
@@ -2799,14 +2443,11 @@ declare module '@sveltejs/kit' {
2799
2443
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
2800
2444
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
2801
2445
  */
2802
- export function error(status: number, message: string, properties: {
2803
- status: number;
2804
- message: string;
2805
- } extends App.Error ? never : Omit<App.Error, "status" | "message">): never;
2446
+ export function error(status: number, message: string, properties: keyof Omit<App.Error, "status" | "message"> extends never ? never : Omit<App.Error, "status" | "message">): never;
2806
2447
  /**
2807
2448
  * Throws an error with a HTTP status code and an optional message.
2808
2449
  * When called during request handling, this will cause SvelteKit to
2809
- * return an error response without invoking `handleError`.
2450
+ * return an error response; the error will be passed to `handleError` as an _expected_ error.
2810
2451
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2811
2452
  * @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
2812
2453
  * @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.
@@ -2966,203 +2607,556 @@ declare module '@sveltejs/kit/env' {
2966
2607
  export {};
2967
2608
  }
2968
2609
 
2969
- declare module '@sveltejs/kit/hooks' {
2970
- import type { Handle } from '@sveltejs/kit';
2610
+ declare module '@sveltejs/kit/hooks' {
2611
+ import type { Handle } from '@sveltejs/kit';
2612
+ /**
2613
+ * A helper function for sequencing multiple `handle` calls in a middleware-like manner.
2614
+ * The behavior for the `handle` options is as follows:
2615
+ * - `transformPageChunk` is applied in reverse order and merged
2616
+ * - `preload` is applied in forward order, the first option "wins" and no `preload` options after it are called
2617
+ * - `filterSerializedResponseHeaders` behaves the same as `preload`
2618
+ *
2619
+ * ```js
2620
+ * /// file: src/hooks.server.js
2621
+ * import { sequence } from '@sveltejs/kit/hooks';
2622
+ *
2623
+ * /// type: import('@sveltejs/kit').Handle
2624
+ * async function first({ event, resolve }) {
2625
+ * console.log('first pre-processing');
2626
+ * const result = await resolve(event, {
2627
+ * transformPageChunk: ({ html }) => {
2628
+ * // transforms are applied in reverse order
2629
+ * console.log('first transform');
2630
+ * return html;
2631
+ * },
2632
+ * preload: () => {
2633
+ * // this one wins as it's the first defined in the chain
2634
+ * console.log('first preload');
2635
+ * return true;
2636
+ * }
2637
+ * });
2638
+ * console.log('first post-processing');
2639
+ * return result;
2640
+ * }
2641
+ *
2642
+ * /// type: import('@sveltejs/kit').Handle
2643
+ * async function second({ event, resolve }) {
2644
+ * console.log('second pre-processing');
2645
+ * const result = await resolve(event, {
2646
+ * transformPageChunk: ({ html }) => {
2647
+ * console.log('second transform');
2648
+ * return html;
2649
+ * },
2650
+ * preload: () => {
2651
+ * console.log('second preload');
2652
+ * return true;
2653
+ * },
2654
+ * filterSerializedResponseHeaders: () => {
2655
+ * // this one wins as it's the first defined in the chain
2656
+ * console.log('second filterSerializedResponseHeaders');
2657
+ * return true;
2658
+ * }
2659
+ * });
2660
+ * console.log('second post-processing');
2661
+ * return result;
2662
+ * }
2663
+ *
2664
+ * export const handle = sequence(first, second);
2665
+ * ```
2666
+ *
2667
+ * The example above would print:
2668
+ *
2669
+ * ```
2670
+ * first pre-processing
2671
+ * first preload
2672
+ * second pre-processing
2673
+ * second filterSerializedResponseHeaders
2674
+ * second transform
2675
+ * first transform
2676
+ * second post-processing
2677
+ * first post-processing
2678
+ * ```
2679
+ *
2680
+ * Calling `resolve` invokes the next handler in the sequence (or SvelteKit itself, if it is the last one). To pass data between handlers, use `event.locals`.
2681
+ *
2682
+ * @param handlers The chain of `handle` functions
2683
+ * */
2684
+ export function sequence(...handlers: Handle[]): Handle;
2685
+
2686
+ export {};
2687
+ }
2688
+
2689
+ declare module '@sveltejs/kit/node' {
2690
+ export function getRequest({ request, base, bodySizeLimit }: {
2691
+ request: import("http").IncomingMessage;
2692
+ base: string;
2693
+ bodySizeLimit?: number;
2694
+ }): Request;
2695
+
2696
+ export function setResponse(res: import("http").ServerResponse, response: Response): void;
2697
+ /**
2698
+ * Converts a file on disk to a readable stream
2699
+ * @since 2.4.0
2700
+ */
2701
+ export function createReadableStream(file: string): ReadableStream;
2702
+
2703
+ export {};
2704
+ }
2705
+
2706
+ declare module '@sveltejs/kit/params' {
2707
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2708
+ /**
2709
+ * The shape of a param matcher. See [matching](https://svelte.dev/docs/kit/advanced-routing#Matching) for more info.
2710
+ */
2711
+ export type ParamMatcher<Output = any> = StandardSchemaV1<string, Output>;
2712
+
2713
+ /**
2714
+ * A value that can be parsed from a URL param and losslessly encoded with `String(...)`.
2715
+ */
2716
+ export type ParamValue = string | number | boolean | bigint;
2717
+
2718
+ /**
2719
+ * A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
2720
+ */
2721
+ export type ParamDefinition =
2722
+ | ((param: string) => ParamValue | undefined)
2723
+ | StandardSchemaV1<string, ParamValue>;
2724
+
2725
+ /**
2726
+ * The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
2727
+ */
2728
+ export type DefinedParams<T extends Record<string, ParamDefinition>> = {
2729
+ readonly [K in keyof T]: ParamEntry<T[K]>;
2730
+ };
2731
+
2732
+ /**
2733
+ * Normalizes a property of defineParams (schema or function) to standard schema.
2734
+ */
2735
+ type ParamEntry<M> =
2736
+ M extends StandardSchemaV1<any, any>
2737
+ ? StandardSchemaV1.InferOutput<M> extends ParamValue
2738
+ ? StandardSchemaV1<any, M>
2739
+ : StandardSchemaV1<any, never>
2740
+ : M extends (param: string) => infer R
2741
+ ? Exclude<R, undefined> extends ParamValue
2742
+ ? StandardSchemaV1<any, Exclude<R, undefined>>
2743
+ : StandardSchemaV1<any, never>
2744
+ : never;
2745
+
2746
+ /**
2747
+ * Extracts the param type from a matcher.
2748
+ */
2749
+ export type MatcherParam<M extends StandardSchemaV1<any, any>> =
2750
+ M extends StandardSchemaV1<any, infer Inner>
2751
+ ? Inner extends ParamValue
2752
+ ? Inner
2753
+ : Inner extends StandardSchemaV1<any, any>
2754
+ ? StandardSchemaV1.InferOutput<Inner> extends ParamValue
2755
+ ? StandardSchemaV1.InferOutput<Inner>
2756
+ : never
2757
+ : never
2758
+ : never;
2759
+
2760
+ /**
2761
+ * Define [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching) for your app.
2762
+ *
2763
+ * */
2764
+ export function defineParams<T extends Record<string, ParamDefinition>>(
2765
+ definitions: T
2766
+ ): DefinedParams<T>;
2767
+
2768
+ export {};
2769
+ }
2770
+
2771
+ declare module '@sveltejs/kit/vite' {
2772
+ import type { KitConfig } from '@sveltejs/kit';
2773
+ import type { Options, SvelteConfig } from '@sveltejs/vite-plugin-svelte';
2774
+ import type { Plugin } from 'vite';
2775
+ /**
2776
+ * Returns the SvelteKit Vite plugins.
2777
+ * Any options that don't belong to SvelteKit are passed through to `vite-plugin-svelte`.
2778
+ *
2779
+ * Since version 3.0.0 you must pass [configuration](configuration) directly.
2780
+ *
2781
+ * Since version 2.62.0 you can pass configuration directly, in which case `svelte.config.js` is ignored.
2782
+ *
2783
+ * */
2784
+ export function sveltekit(config?: KitConfig & Omit<Options, "onwarn"> & Pick<SvelteConfig, "vitePlugin">): Promise<Plugin[]>;
2785
+
2786
+ export {};
2787
+ }
2788
+
2789
+ declare module '$app/env' {
2790
+ /**
2791
+ * `true` if the app is running in the browser.
2792
+ */
2793
+ export const browser: boolean;
2794
+
2795
+ /**
2796
+ * Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
2797
+ */
2798
+ export const dev: boolean;
2799
+
2800
+ /**
2801
+ * SvelteKit analyses your app during the `build` step by running it. During this process, `building` is `true`. This also applies during prerendering.
2802
+ */
2803
+ export const building: boolean;
2804
+
2805
+ /**
2806
+ * The value of `config.version.name`.
2807
+ */
2808
+ export const version: string;
2809
+
2810
+ export {};
2811
+ }
2812
+
2813
+ declare module '$app/forms' {
2971
2814
  /**
2972
- * A helper function for sequencing multiple `handle` calls in a middleware-like manner.
2973
- * The behavior for the `handle` options is as follows:
2974
- * - `transformPageChunk` is applied in reverse order and merged
2975
- * - `preload` is applied in forward order, the first option "wins" and no `preload` options after it are called
2976
- * - `filterSerializedResponseHeaders` behaves the same as `preload`
2815
+ * Use this function to deserialize the response from a form submission.
2816
+ * Usage:
2977
2817
  *
2978
2818
  * ```js
2979
- * /// file: src/hooks.server.js
2980
- * import { sequence } from '@sveltejs/kit/hooks';
2819
+ * import { deserialize } from '$app/forms';
2981
2820
  *
2982
- * /// type: import('@sveltejs/kit').Handle
2983
- * async function first({ event, resolve }) {
2984
- * console.log('first pre-processing');
2985
- * const result = await resolve(event, {
2986
- * transformPageChunk: ({ html }) => {
2987
- * // transforms are applied in reverse order
2988
- * console.log('first transform');
2989
- * return html;
2990
- * },
2991
- * preload: () => {
2992
- * // this one wins as it's the first defined in the chain
2993
- * console.log('first preload');
2994
- * return true;
2995
- * }
2996
- * });
2997
- * console.log('first post-processing');
2998
- * return result;
2999
- * }
2821
+ * async function handleSubmit(event) {
2822
+ * const response = await fetch('/form?/action', {
2823
+ * method: 'POST',
2824
+ * body: new FormData(event.target)
2825
+ * });
3000
2826
  *
3001
- * /// type: import('@sveltejs/kit').Handle
3002
- * async function second({ event, resolve }) {
3003
- * console.log('second pre-processing');
3004
- * const result = await resolve(event, {
3005
- * transformPageChunk: ({ html }) => {
3006
- * console.log('second transform');
3007
- * return html;
3008
- * },
3009
- * preload: () => {
3010
- * console.log('second preload');
3011
- * return true;
3012
- * },
3013
- * filterSerializedResponseHeaders: () => {
3014
- * // this one wins as it's the first defined in the chain
3015
- * console.log('second filterSerializedResponseHeaders');
3016
- * return true;
3017
- * }
3018
- * });
3019
- * console.log('second post-processing');
3020
- * return result;
2827
+ * const result = deserialize(await response.text());
2828
+ * // ...
3021
2829
  * }
3022
- *
3023
- * export const handle = sequence(first, second);
3024
2830
  * ```
2831
+ * */
2832
+ export function deserialize<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: string): ActionResult<Success, Failure>;
2833
+ /**
2834
+ * This action enhances a `<form>` element that otherwise would work without JavaScript.
3025
2835
  *
3026
- * The example above would print:
2836
+ * The `submit` function is called upon submission with the given FormData and the `action` that should be triggered.
2837
+ * If `cancel` is called, the form will not be submitted.
2838
+ * You can use the abort `controller` to cancel the submission in case another one starts.
2839
+ * If a function is returned, that function is called with the response from the server.
2840
+ * If nothing is returned, the fallback will be used.
3027
2841
  *
3028
- * ```
3029
- * first pre-processing
3030
- * first preload
3031
- * second pre-processing
3032
- * second filterSerializedResponseHeaders
3033
- * second transform
3034
- * first transform
3035
- * second post-processing
3036
- * first post-processing
3037
- * ```
2842
+ * If this function or its return value isn't set, it emulates the browser-native behaviour, just without the full-page reload. It
2843
+ * - resets the `<form>` element and refreshes all data in case of a successful submission with no redirect response
2844
+ * - updates the `form` prop, `page.form` and `page.status` if the action is on the same page as the form
2845
+ * - navigates to the page the submission lands on — populating that page's `form` prop and `page.status` — on success and failure if that isn't the current page, just as a native form submission would, but with the `?/actionName` param stripped from the destination URL
2846
+ * - redirects in case of a redirect response
2847
+ * - renders the nearest error page in case of an unexpected error — the one nearest the action's route, if the action is on a different page
3038
2848
  *
3039
- * Calling `resolve` invokes the next handler in the sequence (or SvelteKit itself, if it is the last one). To pass data between handlers, use `event.locals`.
2849
+ * If you provide a custom function with a callback and want to use the default behavior, invoke `update` in your callback.
2850
+ * It accepts an options object
2851
+ * - `reset: false` if you don't want the `<form>` values to be reset after a successful submission
2852
+ * - `refreshAll` to control whether all data is refreshed after submission; it defaults to `true` for successes and `false` for failures
2853
+ * - `navigate: false` to apply non-redirect results to the current page rather than navigating to `result.location`; redirects are always followed
2854
+ * @param form_element The form element
2855
+ * @param submit Submit callback
2856
+ */
2857
+ export function enhance<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(form_element: HTMLFormElement, submit?: SubmitFunction<Success, Failure>): {
2858
+ destroy(): void;
2859
+ };
2860
+ /**
2861
+ * When calling a form action via fetch, the response will be one of these shapes.
2862
+ * ```svelte
2863
+ * <form method="post" use:enhance={() => {
2864
+ * return ({ result }) => {
2865
+ * // result is of type ActionResult
2866
+ * };
2867
+ * }}
2868
+ * ```
3040
2869
  *
3041
- * @param handlers The chain of `handle` functions
2870
+ * Success and failure results carry the root-relative `pathname + search` of the action URL, with
2871
+ * the `?/actionName` parameter removed. Redirect results carry the redirect target. Server-generated
2872
+ * error results also carry the action location, while client-generated errors such as network
2873
+ * failures do not. `update` uses this location to emulate native form navigation.
2874
+ */
2875
+ export type ActionResult<
2876
+ Success extends Record<string, unknown> | undefined = Record<string, any>,
2877
+ Failure extends Record<string, unknown> | undefined = Record<string, any>
2878
+ > =
2879
+ | { type: 'success'; status: number; data?: Success; location: string }
2880
+ | { type: 'failure'; status: number; data?: Failure; location: string }
2881
+ | { type: 'redirect'; status: number; location: string }
2882
+ | { type: 'error'; status?: number; error: App.Error; location?: string };
2883
+
2884
+ export type SubmitFunction<
2885
+ Success extends Record<string, unknown> | undefined = Record<string, any>,
2886
+ Failure extends Record<string, unknown> | undefined = Record<string, any>
2887
+ > = (input: {
2888
+ action: URL;
2889
+ formData: FormData;
2890
+ formElement: HTMLFormElement;
2891
+ controller: AbortController;
2892
+ submitter: HTMLElement | null;
2893
+ cancel: () => void;
2894
+ }) => MaybePromise<
2895
+ | void
2896
+ | ((opts: {
2897
+ formData: FormData;
2898
+ formElement: HTMLFormElement;
2899
+ action: URL;
2900
+ result: ActionResult<Success, Failure>;
2901
+ /**
2902
+ * Call this to get the default behavior of a form submission response.
2903
+ * @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission. `refreshAll` defaults to `true` for successful results and `false` for failures. When the submission navigates, setting it to `false` still runs the destination's `load` functions but may reuse shared layout data. Set `navigate: false` to apply non-redirect results to the current page instead of navigating to `result.location`. Redirects are always followed.
2904
+ */
2905
+ update: (options?: {
2906
+ reset?: boolean;
2907
+ refreshAll?: boolean;
2908
+ navigate?: boolean;
2909
+ /** @deprecated Use `refreshAll` instead. */
2910
+ invalidateAll?: boolean;
2911
+ }) => Promise<void>;
2912
+ }) => MaybePromise<void>)
2913
+ >;
2914
+ /**
2915
+ * Updates the `form` property of the current page with the given data and updates `page.status`.
2916
+ * In case of an error, it renders the nearest error page. In case of a redirect, it navigates to
2917
+ * the redirect location.
3042
2918
  * */
3043
- export function sequence(...handlers: Handle[]): Handle;
2919
+ export function applyAction<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: ActionResult<Success, Failure>): Promise<void>;
2920
+ type MaybePromise<T> = T | Promise<T>;
3044
2921
 
3045
2922
  export {};
3046
2923
  }
3047
2924
 
3048
- declare module '@sveltejs/kit/node' {
3049
- export function getRequest({ request, base, bodySizeLimit }: {
3050
- request: import("http").IncomingMessage;
3051
- base: string;
3052
- bodySizeLimit?: number;
3053
- }): Request;
2925
+ declare module '$app/navigation' {
2926
+ import type { LayoutParams as AppLayoutParams, RouteId as AppRouteId } from '$app/types';
2927
+ /**
2928
+ * Information about the target of a specific navigation.
2929
+ */
2930
+ export interface NavigationTarget<
2931
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
2932
+ RouteId extends AppRouteId | null = AppRouteId | null
2933
+ > {
2934
+ /**
2935
+ * Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
2936
+ * Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
2937
+ */
2938
+ params: Params | null;
2939
+ /**
2940
+ * Info about the target route
2941
+ */
2942
+ route: {
2943
+ /**
2944
+ * 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.
2945
+ */
2946
+ id: RouteId | null;
2947
+ };
2948
+ /**
2949
+ * The URL that is navigated to
2950
+ */
2951
+ url: URL;
2952
+ /**
2953
+ * The scroll position associated with this navigation.
2954
+ *
2955
+ * For the `from` target, this is the scroll position at the moment of navigation.
2956
+ *
2957
+ * For the `to` target, this represents the scroll position that will be or was restored:
2958
+ * - In `beforeNavigate` and `onNavigate`, this is only available for `popstate` navigations (back/forward button)
2959
+ * and will be `null` for other navigation types, since the final scroll position isn't known
2960
+ * ahead of time.
2961
+ * - In `afterNavigate`, this is always the scroll position that was applied after the navigation
2962
+ * completed.
2963
+ */
2964
+ scroll: { x: number; y: number } | null;
2965
+ }
2966
+
2967
+ export interface GotoOptions {
2968
+ /**
2969
+ * If `true`, replaces the current history entry rather than creating a new one.
2970
+ * @default false
2971
+ */
2972
+ replace?: boolean;
2973
+ /** @deprecated Use `replace` instead. */
2974
+ replaceState?: boolean;
2975
+ /**
2976
+ * If `true`, updates the URL and `page.state` without navigating.
2977
+ * @default false
2978
+ */
2979
+ shallow?: boolean;
2980
+ /**
2981
+ * If `true`, resets the scroll position (to the top of the page, or to the element
2982
+ * matching the URL's `#hash` if there is one) and resets focus (to the `<body>`, or the
2983
+ * `autofocus` element if there is one) once the navigation completes.
2984
+ *
2985
+ * If `false`, the current scroll position and focused element are left alone.
2986
+ * @default true, or false when `shallow` is true
2987
+ */
2988
+ reset?: boolean;
2989
+ /**
2990
+ * If `true`, reruns all `load` functions and queries of the page.
2991
+ * @default false
2992
+ */
2993
+ refreshAll?: boolean;
2994
+ /** Causes any `load` functions to rerun if they depend on one of the URLs. */
2995
+ invalidate?: Array<string | URL | ((url: URL) => boolean)>;
2996
+ /** @deprecated Use `refreshAll` instead. */
2997
+ invalidateAll?: boolean;
2998
+ /** An optional object that will be available as `page.state`. */
2999
+ state?: App.PageState;
3000
+ /**
3001
+ * If `true`, `page.state` will be restored after a full page reload.
3002
+ * @default false
3003
+ */
3004
+ persistState?: boolean;
3005
+ }
3006
+
3007
+ /**
3008
+ * - `enter`: The app has hydrated/started
3009
+ * - `form`: The user submitted a `<form method="GET">`
3010
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
3011
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
3012
+ * - `link`: Navigation was triggered by a link click
3013
+ * - `popstate`: Navigation was triggered by back/forward navigation
3014
+ */
3015
+ export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
3016
+
3017
+ export interface NavigationBase {
3018
+ /**
3019
+ * The type of navigation:
3020
+ * - `enter`: The app has hydrated/started
3021
+ * - `form`: The user submitted a `<form method="GET">`
3022
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
3023
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
3024
+ * - `link`: Navigation was triggered by a link click
3025
+ * - `popstate`: Navigation was triggered by back/forward navigation
3026
+ */
3027
+ type: NavigationType;
3028
+ /** Whether this is a shallow navigation. */
3029
+ shallow: boolean;
3030
+ /**
3031
+ * Where navigation was triggered from
3032
+ */
3033
+ from: NavigationTarget | null;
3034
+ /**
3035
+ * Where navigation is going to/has gone to
3036
+ */
3037
+ to: NavigationTarget | null;
3038
+ /**
3039
+ * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
3040
+ */
3041
+ willUnload: boolean;
3042
+ /**
3043
+ * A promise that resolves once the navigation is complete, and rejects if the navigation
3044
+ * fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
3045
+ */
3046
+ complete: Promise<void>;
3047
+ }
3054
3048
 
3055
- export function setResponse(res: import("http").ServerResponse, response: Response): void;
3056
3049
  /**
3057
- * Converts a file on disk to a readable stream
3058
- * @since 2.4.0
3050
+ * The navigation that occurs when the app starts/hydrates
3059
3051
  */
3060
- export function createReadableStream(file: string): ReadableStream;
3052
+ export interface NavigationEnter extends NavigationBase {
3053
+ type: 'enter';
3061
3054
 
3062
- export {};
3063
- }
3055
+ /**
3056
+ * In case of a history back/forward navigation, the number of steps to go back/forward
3057
+ */
3058
+ delta?: undefined;
3064
3059
 
3065
- declare module '@sveltejs/kit/vite' {
3066
- import type { KitConfig } from '@sveltejs/kit';
3067
- import type { Options, SvelteConfig } from '@sveltejs/vite-plugin-svelte';
3068
- import type { Plugin } from 'vite';
3069
- /**
3070
- * Returns the SvelteKit Vite plugins.
3071
- * Any options that don't belong to SvelteKit are passed through to `vite-plugin-svelte`.
3072
- *
3073
- * Since version 3.0.0 you must pass [configuration](configuration) directly.
3074
- *
3075
- * Since version 2.62.0 you can pass configuration directly, in which case `svelte.config.js` is ignored.
3076
- *
3077
- * */
3078
- export function sveltekit(config?: KitConfig & Omit<Options, "onwarn"> & Pick<SvelteConfig, "vitePlugin">): Promise<Plugin[]>;
3060
+ /**
3061
+ * Dispatched `Event` object when navigation occurred by `popstate` or `link`.
3062
+ */
3063
+ event?: undefined;
3064
+ }
3079
3065
 
3080
- export {};
3081
- }
3066
+ export type NavigationExternal = NavigationGoto | NavigationLeave;
3082
3067
 
3083
- declare module '$app/env' {
3084
3068
  /**
3085
- * `true` if the app is running in the browser.
3069
+ * A navigation triggered by a `goto(...)` call or a redirect
3086
3070
  */
3087
- export const browser: boolean;
3071
+ export interface NavigationGoto extends NavigationBase {
3072
+ type: 'goto';
3073
+ }
3088
3074
 
3089
3075
  /**
3090
- * Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
3076
+ * A navigation triggered by the tab being closed, or the user navigating to a different document
3091
3077
  */
3092
- export const dev: boolean;
3078
+ export interface NavigationLeave extends NavigationBase {
3079
+ type: 'leave';
3080
+ }
3093
3081
 
3094
3082
  /**
3095
- * SvelteKit analyses your app during the `build` step by running it. During this process, `building` is `true`. This also applies during prerendering.
3083
+ * A navigation triggered by a `<form method="GET">`
3096
3084
  */
3097
- export const building: boolean;
3085
+ export interface NavigationFormSubmit extends NavigationBase {
3086
+ type: 'form';
3087
+
3088
+ /**
3089
+ * The `SubmitEvent` that caused the navigation
3090
+ */
3091
+ event: SubmitEvent;
3092
+ }
3098
3093
 
3099
3094
  /**
3100
- * The value of `config.version.name`.
3095
+ * A navigation triggered by back/forward navigation
3101
3096
  */
3102
- export const version: string;
3097
+ export interface NavigationPopState extends NavigationBase {
3098
+ type: 'popstate';
3103
3099
 
3104
- export {};
3105
- }
3100
+ /**
3101
+ * In case of a history back/forward navigation, the number of steps to go back/forward
3102
+ */
3103
+ delta: number;
3104
+
3105
+ /**
3106
+ * The `PopStateEvent` that caused the navigation
3107
+ */
3108
+ event: PopStateEvent;
3109
+ }
3106
3110
 
3107
- declare module '$app/forms' {
3108
3111
  /**
3109
- * Use this function to deserialize the response from a form submission.
3110
- * Usage:
3111
- *
3112
- * ```js
3113
- * import { deserialize } from '$app/forms';
3114
- *
3115
- * async function handleSubmit(event) {
3116
- * const response = await fetch('/form?/action', {
3117
- * method: 'POST',
3118
- * body: new FormData(event.target)
3119
- * });
3120
- *
3121
- * const result = deserialize(await response.text());
3122
- * // ...
3123
- * }
3124
- * ```
3125
- * */
3126
- export function deserialize<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: string): import("@sveltejs/kit").ActionResult<Success, Failure>;
3112
+ * A navigation triggered by a link click
3113
+ */
3114
+ export interface NavigationLink extends NavigationBase {
3115
+ type: 'link';
3116
+
3117
+ /**
3118
+ * The `PointerEvent` that caused the navigation
3119
+ */
3120
+ event: PointerEvent;
3121
+ }
3122
+
3123
+ export type Navigation =
3124
+ | NavigationExternal
3125
+ | NavigationFormSubmit
3126
+ | NavigationPopState
3127
+ | NavigationLink;
3128
+
3127
3129
  /**
3128
- * This action enhances a `<form>` element that otherwise would work without JavaScript.
3129
- *
3130
- * The `submit` function is called upon submission with the given FormData and the `action` that should be triggered.
3131
- * If `cancel` is called, the form will not be submitted.
3132
- * You can use the abort `controller` to cancel the submission in case another one starts.
3133
- * If a function is returned, that function is called with the response from the server.
3134
- * If nothing is returned, the fallback will be used.
3135
- *
3136
- * If this function or its return value isn't set, it emulates the browser-native behaviour, just without the full-page reload. It
3137
- * - resets the `<form>` element and refreshes all data in case of a successful submission with no redirect response
3138
- * - updates the `form` prop, `page.form` and `page.status` if the action is on the same page as the form
3139
- * - navigates to the page the submission lands on — populating that page's `form` prop and `page.status` — on success and failure if that isn't the current page, just as a native form submission would, but with the `?/actionName` param stripped from the destination URL
3140
- * - redirects in case of a redirect response
3141
- * - renders the nearest error page in case of an unexpected error — the one nearest the action's route, if the action is on a different page
3142
- *
3143
- * If you provide a custom function with a callback and want to use the default behavior, invoke `update` in your callback.
3144
- * It accepts an options object
3145
- * - `reset: false` if you don't want the `<form>` values to be reset after a successful submission
3146
- * - `refreshAll` to control whether all data is refreshed after submission; it defaults to `true` for successes and `false` for failures
3147
- * - `navigate: false` to apply non-redirect results to the current page rather than navigating to `result.location`; redirects are always followed
3148
- * @param form_element The form element
3149
- * @param submit Submit callback
3130
+ * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
3150
3131
  */
3151
- export function enhance<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(form_element: HTMLFormElement, submit?: import("@sveltejs/kit").SubmitFunction<Success, Failure>): {
3152
- destroy(): void;
3132
+ export type BeforeNavigate = Navigation & {
3133
+ /**
3134
+ * Call this to prevent the navigation from starting.
3135
+ */
3136
+ cancel: () => void;
3153
3137
  };
3154
- /**
3155
- * Updates the `form` property of the current page with the given data and updates `page.status`.
3156
- * In case of an error, it renders the nearest error page. In case of a redirect, it navigates to
3157
- * the redirect location.
3158
- * */
3159
- export function applyAction<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: import("@sveltejs/kit").ActionResult<Success, Failure>): Promise<void>;
3160
3138
 
3161
- export {};
3162
- }
3139
+ /**
3140
+ * The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
3141
+ */
3142
+ export type OnNavigate = Navigation & {
3143
+ type: Exclude<NavigationType, 'enter' | 'leave'>;
3144
+ /**
3145
+ * Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
3146
+ */
3147
+ willUnload: false;
3148
+ };
3163
3149
 
3164
- declare module '$app/navigation' {
3165
- import type { RouteId } from '$app/types';
3150
+ /**
3151
+ * The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
3152
+ */
3153
+ export type AfterNavigate = (Navigation | NavigationEnter) & {
3154
+ type: Exclude<NavigationType, 'leave'>;
3155
+ /**
3156
+ * Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
3157
+ */
3158
+ willUnload: false;
3159
+ };
3166
3160
  /**
3167
3161
  * A lifecycle function that captures state before navigating and restores it when traversing history.
3168
3162
  *
@@ -3183,7 +3177,7 @@ declare module '$app/navigation' {
3183
3177
  *
3184
3178
  * `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3185
3179
  * */
3186
- export function afterNavigate(callback: (navigation: import("@sveltejs/kit").AfterNavigate) => void): void;
3180
+ export function afterNavigate(callback: (navigation: AfterNavigate) => void): void;
3187
3181
  /**
3188
3182
  * A navigation interceptor that triggers before we navigate to a URL, whether by clicking a link, calling `goto(...)`, or using the browser back/forward controls.
3189
3183
  *
@@ -3195,7 +3189,7 @@ declare module '$app/navigation' {
3195
3189
  *
3196
3190
  * `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3197
3191
  * */
3198
- export function beforeNavigate(callback: (navigation: import("@sveltejs/kit").BeforeNavigate) => void): void;
3192
+ export function beforeNavigate(callback: (navigation: BeforeNavigate) => void): void;
3199
3193
  /**
3200
3194
  * A lifecycle function that runs the supplied `callback` immediately before we navigate to a new URL except during full-page navigations.
3201
3195
  *
@@ -3205,7 +3199,7 @@ declare module '$app/navigation' {
3205
3199
  *
3206
3200
  * `onNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3207
3201
  * */
3208
- export function onNavigate(callback: (navigation: import("@sveltejs/kit").OnNavigate) => MaybePromise<(() => void) | void>): void;
3202
+ export function onNavigate(callback: (navigation: OnNavigate) => MaybePromise<(() => void) | void>): void;
3209
3203
  /**
3210
3204
  * If called when the page is being updated following a navigation (in `onMount` or `afterNavigate` or an action, for example), this disables SvelteKit's built-in scroll handling.
3211
3205
  * This is generally discouraged, since it breaks user expectations.
@@ -3223,7 +3217,7 @@ declare module '$app/navigation' {
3223
3217
  * @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.
3224
3218
  * @param opts Options related to the navigation
3225
3219
  * */
3226
- export function goto(url: string | URL, opts?: import("@sveltejs/kit").GotoOptions): Promise<void>;
3220
+ export function goto(url: string | URL, opts?: GotoOptions): Promise<void>;
3227
3221
  /**
3228
3222
  * 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.
3229
3223
  *
@@ -3300,7 +3294,7 @@ declare module '$app/navigation' {
3300
3294
  * Returns a Promise that resolves when the modules have been imported.
3301
3295
  *
3302
3296
  * */
3303
- export function preloadCode(id: RouteId): Promise<void>;
3297
+ export function preloadCode(id: import("$app/types").RouteId): Promise<void>;
3304
3298
  /**
3305
3299
  * Programmatically create a new history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
3306
3300
  *
@@ -3670,6 +3664,72 @@ declare module '$app/service-worker' {
3670
3664
  }
3671
3665
 
3672
3666
  declare module '$app/state' {
3667
+ import type { LayoutParams as AppLayoutParams, ResolvedPathname, RouteId as AppRouteId } from '$app/types';
3668
+ import type { Navigation } from '$app/navigation';
3669
+ export type ReadonlyURLSearchParams = Omit<URLSearchParams, 'set' | 'append' | 'delete' | 'sort'>;
3670
+
3671
+ export type ReadonlyURL = Readonly<
3672
+ Omit<URL, 'searchParams'> & {
3673
+ searchParams: ReadonlyURLSearchParams;
3674
+ }
3675
+ >;
3676
+
3677
+ /**
3678
+ * The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object.
3679
+ */
3680
+ export interface Page<
3681
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
3682
+ RouteId extends AppRouteId | null = AppRouteId | null
3683
+ > {
3684
+ /**
3685
+ * The URL of the current page.
3686
+ */
3687
+ url: ReadonlyURL & { readonly pathname: ResolvedPathname | (string & {}) };
3688
+ /**
3689
+ * The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
3690
+ */
3691
+ params: Params;
3692
+ /**
3693
+ * Info about the current route.
3694
+ */
3695
+ route: {
3696
+ /**
3697
+ * 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.
3698
+ */
3699
+ id: RouteId;
3700
+ };
3701
+ /**
3702
+ * HTTP status code of the current page.
3703
+ */
3704
+ status: number;
3705
+ /**
3706
+ * The error object of the current page, if any. Filled from the `handleError` hooks.
3707
+ */
3708
+ error: App.Error | null;
3709
+ /**
3710
+ * The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
3711
+ */
3712
+ data: App.PageData & Record<string, any>;
3713
+ /**
3714
+ * The page state, which can be manipulated using [`goto`](https://svelte.dev/docs/kit/$app-navigation#goto) from `$app/navigation`.
3715
+ */
3716
+ state: App.PageState;
3717
+ /**
3718
+ * Information about the target of the current shallow navigation, or `null` if no shallow navigation has occurred.
3719
+ */
3720
+ shallow: {
3721
+ /** Parameters of the target route, or `null` if the URL does not resolve to a route. */
3722
+ params: AppLayoutParams<'/'> | null;
3723
+ /** Info about the target route, or `null` if the URL does not resolve to a route. */
3724
+ route: { id: AppRouteId } | null;
3725
+ /** The normalized URL passed to `goto(..., { shallow: true })`. */
3726
+ url: ReadonlyURL;
3727
+ } | null;
3728
+ /**
3729
+ * Filled only after a form submission. See [form actions](https://svelte.dev/docs/kit/form-actions) for more info.
3730
+ */
3731
+ form: any;
3732
+ }
3673
3733
  /**
3674
3734
  * A read-only reactive object with information about the current page, serving several use cases:
3675
3735
  * - retrieving the combined `data` of all pages/layouts anywhere in your component tree (also see [loading data](https://svelte.dev/docs/kit/load))
@@ -3706,12 +3766,12 @@ declare module '$app/state' {
3706
3766
  * On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time.
3707
3767
  *
3708
3768
  * */
3709
- export const page: import("@sveltejs/kit").Page;
3769
+ export const page: Page;
3710
3770
  /**
3711
3771
  * A read-only object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
3712
3772
  * Values are `null` when no navigation is occurring, or during server rendering.
3713
3773
  * */
3714
- export const navigating: import("@sveltejs/kit").Navigation | {
3774
+ export const navigating: Navigation | {
3715
3775
  from: null;
3716
3776
  to: null;
3717
3777
  type: null;
@@ -3754,7 +3814,7 @@ declare module '$app/state' {
3754
3814
  */
3755
3815
  declare namespace App {
3756
3816
  /**
3757
- * Defines the common shape of expected and unexpected errors. Expected errors are thrown using the `error` function. Unexpected errors are handled by the `handleError` hooks which should return this shape.
3817
+ * Defines the common shape of expected and unexpected errors. Expected errors are thrown using the `error` function. Every error passes through the `handleError` hooks, which must return this shape (with `status` and `message` optional, since they default to those of the caught error).
3758
3818
  */
3759
3819
  export interface Error {
3760
3820
  status: number;