@sveltejs/kit 3.0.0-next.17 → 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 (84) 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 +93 -453
  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 +17 -5
  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/csrf.js +1 -1
  63. package/src/runtime/server/errors.js +53 -28
  64. package/src/runtime/server/fetch.js +1 -1
  65. package/src/runtime/server/index.js +9 -14
  66. package/src/runtime/server/page/actions.js +2 -1
  67. package/src/runtime/server/page/index.js +7 -3
  68. package/src/runtime/server/page/load_data.js +1 -1
  69. package/src/runtime/server/page/render.js +17 -11
  70. package/src/runtime/server/page/server_routing.js +3 -2
  71. package/src/runtime/server/remote-functions.js +3 -2
  72. package/src/runtime/server/respond.js +4 -8
  73. package/src/runtime/server/state.js +3 -6
  74. package/src/types/ambient.d.ts +1 -1
  75. package/src/types/internal.d.ts +8 -10
  76. package/src/types/private.d.ts +12 -3
  77. package/src/utils/error.js +30 -14
  78. package/src/utils/page_nodes.js +3 -2
  79. package/src/utils/params.js +3 -2
  80. package/src/utils/routing.js +5 -4
  81. package/src/version.js +1 -1
  82. package/types/index.d.ts +1005 -935
  83. package/types/index.d.ts.map +43 -31
  84. /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.
@@ -46,11 +59,18 @@ declare module '@sveltejs/kit' {
46
59
  */
47
60
  emulate?: () => MaybePromise<Emulator>;
48
61
  vite?: {
49
- /**
50
- * Plugins provided by the adapter are placed before any of SvelteKit's own plugins.
51
- * @since 3.0.0
52
- */
53
- plugins?: Plugin[];
62
+ plugins?: {
63
+ /**
64
+ * Vite plugins placed before any of SvelteKit's own plugins.
65
+ * @since 3.0.0
66
+ */
67
+ pre?: Plugin[];
68
+ /**
69
+ * Vite plugins placed after any of SvelteKit's own plugins.
70
+ * @since 3.0.0
71
+ */
72
+ post?: Plugin[];
73
+ };
54
74
  };
55
75
  }
56
76
 
@@ -432,7 +452,10 @@ declare module '@sveltejs/kit' {
432
452
  *
433
453
  * CSRF checks only apply in production, not in local development.
434
454
  * @default []
435
- * @example ['https://checkout.stripe.com', 'https://accounts.google.com']
455
+ * @example
456
+ * ```js
457
+ * ['https://checkout.stripe.com', 'https://accounts.google.com']
458
+ * ```
436
459
  */
437
460
  trustedOrigins?: string[];
438
461
  };
@@ -912,45 +935,76 @@ declare module '@sveltejs/kit' {
912
935
  resolve: (event: RequestEvent, opts?: ResolveOptions) => Promise<Response>;
913
936
  }) => MaybePromise<Response>;
914
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
+
915
950
  /**
916
- * The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs when an unexpected error is thrown while responding to a request.
917
- *
918
- * If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
919
- * Make sure that this function _never_ throws an error.
920
- *
921
- * The returned object can include a `status` property to override the HTTP status code used in the response.
922
- * 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).
923
956
  */
924
- export type HandleServerError = (input: {
925
- error: unknown;
926
- event: RequestEvent;
927
- status: number;
928
- message: string;
929
- }) => 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' }>;
930
972
 
931
973
  /**
932
- * 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).
933
979
  *
934
- * 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.
935
986
  */
936
- export type HandleValidationError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
937
- (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>;
938
990
 
939
991
  /**
940
- * 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.
941
994
  *
942
- * If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
943
- * 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).
944
1002
  *
945
- * The returned object can include a `status` property to override the HTTP status code used in the response.
946
- * If omitted, the status defaults to 500.
1003
+ * Make sure that this function _never_ throws an error.
947
1004
  */
948
- export type HandleClientError = (input: {
949
- error: unknown;
950
- event: NavigationEvent;
951
- status: number;
952
- message: string;
953
- }) => MaybePromise<void | AppErrorWithOptionalStatus>;
1005
+ export type HandleClientError = (
1006
+ input: ClientCaughtError & { event: NavigationEvent }
1007
+ ) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
954
1008
 
955
1009
  /**
956
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`.
@@ -1177,810 +1231,401 @@ declare module '@sveltejs/kit' {
1177
1231
  }
1178
1232
 
1179
1233
  /**
1180
- * 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.
1181
1239
  */
1182
- export interface NavigationTarget<
1183
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1184
- RouteId extends AppRouteId | null = AppRouteId | null
1185
- > {
1186
- /**
1187
- * Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1188
- * Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
1189
- */
1190
- params: Params | null;
1191
- /**
1192
- * Info about the target route
1193
- */
1194
- 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>> & {
1195
1258
  /**
1196
- * 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
+ * ```
1197
1268
  */
1198
- 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>;
1199
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
+ > {
1200
1298
  /**
1201
- * The URL that is navigated to
1299
+ * Get or set cookies related to the current request
1202
1300
  */
1203
- url: URL;
1301
+ readonly cookies: Cookies;
1204
1302
  /**
1205
- * 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:
1206
1304
  *
1207
- * 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.
1208
1310
  *
1209
- * For the `to` target, this represents the scroll position that will be or was restored:
1210
- * - In `beforeNavigate` and `onNavigate`, this is only available for `popstate` navigations (back/forward button)
1211
- * and will be `null` for other navigation types, since the final scroll position isn't known
1212
- * ahead of time.
1213
- * - In `afterNavigate`, this is always the scroll position that was applied after the navigation
1214
- * completed.
1311
+ * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
1215
1312
  */
1216
- scroll: { x: number; y: number } | null;
1217
- }
1218
-
1219
- export interface GotoOptions {
1313
+ readonly fetch: typeof fetch;
1220
1314
  /**
1221
- * If `true`, replaces the current history entry rather than creating a new one.
1222
- * @default false
1315
+ * The client's IP address, set by the adapter.
1223
1316
  */
1224
- replace?: boolean;
1225
- /** @deprecated Use `replace` instead. */
1226
- replaceState?: boolean;
1317
+ readonly getClientAddress: () => string;
1227
1318
  /**
1228
- * If `true`, updates the URL and `page.state` without navigating.
1229
- * @default false
1319
+ * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
1230
1320
  */
1231
- shallow?: boolean;
1321
+ readonly locals: App.Locals;
1232
1322
  /**
1233
- * If `true`, resets the scroll position (to the top of the page, or to the element
1234
- * matching the URL's `#hash` if there is one) and resets focus (to the `<body>`, or the
1235
- * `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.
1236
1324
  *
1237
- * If `false`, the current scroll position and focused element are left alone.
1238
- * @default true, or false when `shallow` is true
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.
1239
1329
  */
1240
- reset?: boolean;
1330
+ readonly params: Params;
1241
1331
  /**
1242
- * If `true`, reruns all `load` functions and queries of the page.
1243
- * @default false
1332
+ * Additional data made available through the adapter.
1244
1333
  */
1245
- refreshAll?: boolean;
1246
- /** Causes any `load` functions to rerun if they depend on one of the URLs. */
1247
- invalidate?: Array<string | URL | ((url: URL) => boolean)>;
1248
- /** @deprecated Use `refreshAll` instead. */
1249
- invalidateAll?: boolean;
1250
- /** An optional object that will be available as `page.state`. */
1251
- state?: App.PageState;
1334
+ readonly platform: Readonly<App.Platform> | undefined;
1252
1335
  /**
1253
- * If `true`, `page.state` will be restored after a full page reload.
1254
- * @default false
1336
+ * The original request object.
1255
1337
  */
1256
- persistState?: boolean;
1257
- }
1258
-
1259
- /**
1260
- * - `enter`: The app has hydrated/started
1261
- * - `form`: The user submitted a `<form method="GET">`
1262
- * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1263
- * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1264
- * - `link`: Navigation was triggered by a link click
1265
- * - `popstate`: Navigation was triggered by back/forward navigation
1266
- */
1267
- export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
1268
-
1269
- export interface NavigationBase {
1338
+ readonly request: Request;
1270
1339
  /**
1271
- * The type of navigation:
1272
- * - `enter`: The app has hydrated/started
1273
- * - `form`: The user submitted a `<form method="GET">`
1274
- * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1275
- * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1276
- * - `link`: Navigation was triggered by a link click
1277
- * - `popstate`: Navigation was triggered by back/forward navigation
1340
+ * Info about the current route.
1278
1341
  */
1279
- type: NavigationType;
1280
- /** Whether this is a shallow navigation. */
1281
- shallow: boolean;
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
+ };
1282
1353
  /**
1283
- * Where navigation was triggered from
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.
1284
1374
  */
1285
- from: NavigationTarget | null;
1375
+ readonly setHeaders: (headers: Record<string, string>) => void;
1286
1376
  /**
1287
- * Where navigation is going to/has gone to
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.
1288
1383
  */
1289
- to: NavigationTarget | null;
1384
+ readonly url: URL;
1290
1385
  /**
1291
- * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
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.
1292
1388
  */
1293
- willUnload: boolean;
1389
+ readonly isDataRequest: boolean;
1294
1390
  /**
1295
- * A promise that resolves once the navigation is complete, and rejects if the navigation
1296
- * fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
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.
1297
1392
  */
1298
- complete: Promise<void>;
1299
- }
1300
-
1301
- /**
1302
- * The navigation that occurs when the app starts/hydrates
1303
- */
1304
- export interface NavigationEnter extends NavigationBase {
1305
- type: 'enter';
1393
+ readonly isSubRequest: boolean;
1306
1394
 
1307
1395
  /**
1308
- * In case of a history back/forward navigation, the number of steps to go back/forward
1396
+ * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
1397
+ * @since 2.31.0
1309
1398
  */
1310
- delta?: undefined;
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
+ };
1311
1407
 
1312
1408
  /**
1313
- * Dispatched `Event` object when navigation occurred by `popstate` or `link`.
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.
1314
1411
  */
1315
- event?: undefined;
1412
+ readonly isRemoteRequest: boolean;
1316
1413
  }
1317
1414
 
1318
- export type NavigationExternal = NavigationGoto | NavigationLeave;
1319
-
1320
1415
  /**
1321
- * 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.
1322
1419
  */
1323
- export interface NavigationGoto extends NavigationBase {
1324
- 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;
1325
1448
  }
1326
1449
 
1327
- /**
1328
- * A navigation triggered by the tab being closed, or the user navigating to a different document
1329
- */
1330
- export interface NavigationLeave extends NavigationBase {
1331
- 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>;
1332
1476
  }
1333
1477
 
1334
1478
  /**
1335
- * A navigation triggered by a `<form method="GET">`
1479
+ * Information required to instantiate a new `Server` instance.
1336
1480
  */
1337
- export interface NavigationFormSubmit extends NavigationBase {
1338
- type: 'form';
1339
-
1340
- /**
1341
- * The `SubmitEvent` that caused the navigation
1342
- */
1343
- 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>;
1344
1489
  }
1345
1490
 
1346
1491
  /**
1347
- * 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.
1348
1494
  */
1349
- export interface NavigationPopState extends NavigationBase {
1350
- 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>;
1351
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> {
1352
1507
  /**
1353
- * 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.
1354
1511
  */
1355
- delta: number;
1356
-
1512
+ parent: () => Promise<ParentData>;
1357
1513
  /**
1358
- * 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
+ * ```
1359
1549
  */
1360
- event: PopStateEvent;
1361
- }
1362
-
1363
- /**
1364
- * A navigation triggered by a link click
1365
- */
1366
- export interface NavigationLink extends NavigationBase {
1367
- 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;
1368
1565
 
1369
1566
  /**
1370
- * 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
1371
1569
  */
1372
- 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
+ };
1373
1578
  }
1374
1579
 
1375
- export type Navigation =
1376
- 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>;
1377
1589
 
1378
1590
  /**
1379
- * 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.
1380
1593
  */
1381
- export type BeforeNavigate = Navigation & {
1382
- /**
1383
- * Call this to prevent the navigation from starting.
1384
- */
1385
- cancel: () => void;
1386
- };
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>>;
1387
1599
 
1388
1600
  /**
1389
- * 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.
1390
1602
  */
1391
- export type OnNavigate = Navigation & {
1392
- type: Exclude<NavigationType, 'enter' | 'leave'>;
1393
- /**
1394
- * Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
1395
- */
1396
- willUnload: false;
1397
- };
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
+ }
1398
1609
 
1399
1610
  /**
1400
- * 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.
1401
1612
  */
1402
- export type AfterNavigate = (Navigation | NavigationEnter) & {
1403
- type: Exclude<NavigationType, 'leave'>;
1404
- /**
1405
- * Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
1406
- */
1407
- willUnload: false;
1408
- };
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
+ }
1409
1619
 
1410
1620
  /**
1411
- * The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object.
1412
- */
1413
- export interface Page<
1414
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1415
- RouteId extends AppRouteId | null = AppRouteId | null
1416
- > {
1417
- /**
1418
- * The URL of the current page.
1419
- */
1420
- url: ReadonlyURL & { readonly pathname: ResolvedPathname | (string & {}) };
1421
- /**
1422
- * The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1423
- */
1424
- params: Params;
1425
- /**
1426
- * Info about the current route.
1427
- */
1428
- route: {
1429
- /**
1430
- * 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.
1431
- */
1432
- id: RouteId;
1433
- };
1434
- /**
1435
- * HTTP status code of the current page.
1436
- */
1437
- status: number;
1438
- /**
1439
- * The error object of the current page, if any. Filled from the `handleError` hooks.
1440
- */
1441
- error: App.Error | null;
1442
- /**
1443
- * The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
1444
- */
1445
- data: App.PageData & Record<string, any>;
1446
- /**
1447
- * The page state, which can be manipulated using [`goto`](https://svelte.dev/docs/kit/$app-navigation#goto) from `$app/navigation`.
1448
- */
1449
- state: App.PageState;
1450
- /**
1451
- * Information about the target of the current shallow navigation, or `null` if no shallow navigation has occurred.
1452
- */
1453
- shallow: {
1454
- /** Parameters of the target route, or `null` if the URL does not resolve to a route. */
1455
- params: AppLayoutParams<'/'> | null;
1456
- /** Info about the target route, or `null` if the URL does not resolve to a route. */
1457
- route: { id: AppRouteId } | null;
1458
- /** The normalized URL passed to `goto(..., { shallow: true })`. */
1459
- url: ReadonlyURL;
1460
- } | null;
1461
- /**
1462
- * Filled only after a form submission. See [form actions](https://svelte.dev/docs/kit/form-actions) for more info.
1463
- */
1464
- form: any;
1465
- }
1466
-
1467
- /**
1468
- * The shape of a param matcher. See [matching](https://svelte.dev/docs/kit/advanced-routing#Matching) for more info.
1469
- */
1470
- export type ParamMatcher<Output = any> = StandardSchemaV1<string, Output>;
1471
-
1472
- /**
1473
- * A value that can be parsed from a URL param and losslessly encoded with `String(...)`.
1474
- */
1475
- export type ParamValue = string | number | boolean | bigint;
1476
-
1477
- /**
1478
- * A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
1479
- */
1480
- export type ParamDefinition =
1481
- ((param: string) => ParamValue | undefined) | StandardSchemaV1<string, ParamValue>;
1482
-
1483
- /**
1484
- * The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
1485
- */
1486
- export type DefinedParams<T extends Record<string, ParamDefinition>> = {
1487
- readonly [K in keyof T]: ParamEntry<T[K]>;
1488
- };
1489
-
1490
- /**
1491
- * Normalizes a property of defineParams (schema or function) to standard schema.
1492
- */
1493
- type ParamEntry<M> =
1494
- M extends StandardSchemaV1<any, any>
1495
- ? StandardSchemaV1.InferOutput<M> extends ParamValue
1496
- ? StandardSchemaV1<any, M>
1497
- : StandardSchemaV1<any, never>
1498
- : M extends (param: string) => infer R
1499
- ? Exclude<R, undefined> extends ParamValue
1500
- ? StandardSchemaV1<any, Exclude<R, undefined>>
1501
- : StandardSchemaV1<any, never>
1502
- : never;
1503
-
1504
- /**
1505
- * Extracts the param type from a matcher.
1506
- */
1507
- export type MatcherParam<M extends StandardSchemaV1<any, any>> =
1508
- M extends StandardSchemaV1<any, infer Inner>
1509
- ? Inner extends ParamValue
1510
- ? Inner
1511
- : Inner extends StandardSchemaV1<any, any>
1512
- ? StandardSchemaV1.InferOutput<Inner> extends ParamValue
1513
- ? StandardSchemaV1.InferOutput<Inner>
1514
- : never
1515
- : never
1516
- : never;
1517
-
1518
- /**
1519
- * Define [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching) for your app.
1520
- *
1521
- * */
1522
- export function defineParams<T extends Record<string, ParamDefinition>>(
1523
- definitions: T
1524
- ): DefinedParams<T>;
1525
-
1526
- /**
1527
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1528
- * when called with a regular `query`. `arg` is the validated argument (the input *after*
1529
- * the query's schema validated and transformed it, if applicable); `query` is a
1530
- * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
1531
- * update the correct client entry.
1532
- */
1533
- export type RequestedEntry<Validated, Output> = {
1534
- arg: Validated;
1535
- query: RemoteQuery<Output>;
1536
- };
1537
-
1538
- /**
1539
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1540
- * when called with a `query.live`. `arg` is the validated argument; `query` is a
1541
- * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
1542
- * the correct client subscription.
1543
- */
1544
- export type LiveRequestedEntry<Validated, Output> = {
1545
- arg: Validated;
1546
- query: RemoteLiveQuery<Output>;
1547
- };
1548
-
1549
- export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
1550
- AsyncIterable<RequestedEntry<Validated, Output>> & {
1551
- /**
1552
- * Call `refresh` on all queries selected by this `requested` invocation.
1553
- * This is identical to:
1554
- * ```ts
1555
- * import { requested } from '$app/server';
1556
- *
1557
- * for await (const { query } of requested(getPost, ...)) {
1558
- * void query.refresh();
1559
- * }
1560
- * ```
1561
- */
1562
- refreshAll: () => Promise<void>;
1563
- };
1564
-
1565
- export type LiveQueryRequestedResult<Validated, Output> = Iterable<
1566
- LiveRequestedEntry<Validated, Output>
1567
- > &
1568
- AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
1569
- /**
1570
- * Call `reconnect` on all live queries selected by this `requested` invocation.
1571
- * This is identical to:
1572
- * ```ts
1573
- * import { requested } from '$app/server';
1574
- *
1575
- * for await (const { query } of requested(liveQuery, ...)) {
1576
- * void query.reconnect();
1577
- * }
1578
- * ```
1579
- */
1580
- reconnectAll: () => Promise<void>;
1581
- };
1582
-
1583
- export type RequestedResult<Validated, Output> =
1584
- QueryRequestedResult<Validated, Output> | LiveQueryRequestedResult<Validated, Output>;
1585
-
1586
- export interface RequestEvent<
1587
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1588
- RouteId extends AppRouteId | null = AppRouteId | null
1589
- > {
1590
- /**
1591
- * Get or set cookies related to the current request
1592
- */
1593
- readonly cookies: Cookies;
1594
- /**
1595
- * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
1596
- *
1597
- * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
1598
- * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
1599
- * - 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.
1600
- * - 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)
1601
- * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
1602
- *
1603
- * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
1604
- */
1605
- readonly fetch: typeof fetch;
1606
- /**
1607
- * The client's IP address, set by the adapter.
1608
- */
1609
- readonly getClientAddress: () => string;
1610
- /**
1611
- * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
1612
- */
1613
- readonly locals: App.Locals;
1614
- /**
1615
- * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1616
- *
1617
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1618
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1619
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1620
- * 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.
1621
- */
1622
- readonly params: Params;
1623
- /**
1624
- * Additional data made available through the adapter.
1625
- */
1626
- readonly platform: Readonly<App.Platform> | undefined;
1627
- /**
1628
- * The original request object.
1629
- */
1630
- readonly request: Request;
1631
- /**
1632
- * Info about the current route.
1633
- */
1634
- readonly route: {
1635
- /**
1636
- * 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.
1637
- *
1638
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1639
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1640
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1641
- * 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.
1642
- */
1643
- id: RouteId;
1644
- };
1645
- /**
1646
- * 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:
1647
- *
1648
- * ```js
1649
- * /// file: src/routes/blog/+page.js
1650
- * export async function load({ fetch, setHeaders }) {
1651
- * const url = `https://cms.example.com/articles.json`;
1652
- * const response = await fetch(url);
1653
- *
1654
- * setHeaders({
1655
- * age: response.headers.get('age'),
1656
- * 'cache-control': response.headers.get('cache-control')
1657
- * });
1658
- *
1659
- * return response.json();
1660
- * }
1661
- * ```
1662
- *
1663
- * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
1664
- *
1665
- * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/@sveltejs-kit#Cookies) API instead.
1666
- */
1667
- readonly setHeaders: (headers: Record<string, string>) => void;
1668
- /**
1669
- * The requested URL.
1670
- *
1671
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1672
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1673
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1674
- * 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.
1675
- */
1676
- readonly url: URL;
1677
- /**
1678
- * `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
1679
- * related to the data request in this case. Use this property instead if the distinction is important to you.
1680
- */
1681
- readonly isDataRequest: boolean;
1682
- /**
1683
- * `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.
1684
- */
1685
- readonly isSubRequest: boolean;
1686
-
1687
- /**
1688
- * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
1689
- * @since 2.31.0
1690
- */
1691
- readonly tracing: {
1692
- /** Whether tracing is enabled. */
1693
- enabled: boolean;
1694
- /** The root span for the request. This span is named `sveltekit.handle.root`. */
1695
- root: Span;
1696
- /** The span associated with the current `handle` hook, `load` function, or form action. */
1697
- current: Span;
1698
- };
1699
-
1700
- /**
1701
- * `true` if the request comes from the client via a remote function. The `url` property will be stripped of the internal information
1702
- * related to the data request in this case. Use this property instead if the distinction is important to you.
1703
- */
1704
- readonly isRemoteRequest: boolean;
1705
- }
1706
-
1707
- /**
1708
- * 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.
1709
- *
1710
- * 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.
1711
- */
1712
- export type RequestHandler<
1713
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1714
- RouteId extends AppRouteId | null = AppRouteId | null
1715
- > = (event: RequestEvent<Params, RouteId>) => MaybePromise<Response>;
1716
-
1717
- export interface ResolveOptions {
1718
- /**
1719
- * Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
1720
- * (they could include an element's opening tag but not its closing tag, for example)
1721
- * but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
1722
- * @param input the html chunk and the info if this is the last chunk
1723
- */
1724
- transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
1725
- /**
1726
- * Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
1727
- * By default, none will be included.
1728
- * @param name header name
1729
- * @param value header value
1730
- */
1731
- filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
1732
- /**
1733
- * Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
1734
- * `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
1735
- * [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
1736
- * By default, `js` and `css` files will be preloaded.
1737
- * @param input the type of the file and its path
1738
- */
1739
- preload?: (input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }) => boolean;
1740
- }
1741
-
1742
- export interface RouteDefinition<Config = any> {
1743
- id: string;
1744
- api: {
1745
- methods: Array<HttpMethod | '*'>;
1746
- };
1747
- page: {
1748
- methods: Array<Extract<HttpMethod, 'GET' | 'POST'>>;
1749
- };
1750
- pattern: RegExp;
1751
- prerender: PrerenderOption;
1752
- segments: RouteSegment[];
1753
- methods: Array<HttpMethod | '*'>;
1754
- config: Config;
1755
- }
1756
-
1757
- export class Server {
1758
- constructor(manifest: SSRManifest);
1759
- init(options: ServerInitOptions): Promise<void>;
1760
- respond(request: Request, options: RequestOptions): Promise<Response>;
1761
- }
1762
-
1763
- export interface ServerInitOptions {
1764
- /** A map of environment variables. */
1765
- env: Record<string, string | undefined>;
1766
- /** A function that turns an asset filename into a `ReadableStream`. Required for the `read` export from `$app/server` to work. */
1767
- read?: (file: string) => MaybePromise<ReadableStream | null>;
1768
- }
1769
-
1770
- /**
1771
- * Information required to instantiate a new `Server` instance.
1772
- */
1773
- export interface SSRManifest {
1774
- /** The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes. */
1775
- appDir: string;
1776
- /** The `base` and `appDir` settings combined without a leading slash. */
1777
- appPath: string;
1778
- /** Static files from `config.files.assets` and the service worker (if any). */
1779
- assets: Set<string>;
1780
- mimeTypes: Record<string, string>;
1781
- }
1782
-
1783
- /**
1784
- * The generic form of `PageServerLoad` and `LayoutServerLoad`. You should import those from `./$types` (see [generated types](https://svelte.dev/docs/kit/types#Generated-types))
1785
- * rather than using `ServerLoad` directly.
1786
- */
1787
- export type ServerLoad<
1788
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1789
- ParentData extends Record<string, any> = Record<string, any>,
1790
- OutputData extends Record<string, any> | void = Record<string, any> | void,
1791
- RouteId extends AppRouteId | null = AppRouteId | null
1792
- > = (event: ServerLoadEvent<Params, ParentData, RouteId>) => MaybePromise<OutputData>;
1793
-
1794
- export interface ServerLoadEvent<
1795
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1796
- ParentData extends Record<string, any> = Record<string, any>,
1797
- RouteId extends AppRouteId | null = AppRouteId | null
1798
- > extends RequestEvent<Params, RouteId> {
1799
- /**
1800
- * `await parent()` returns data from parent `+layout.server.js` `load` functions.
1801
- *
1802
- * 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.
1803
- */
1804
- parent: () => Promise<ParentData>;
1805
- /**
1806
- * 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.
1807
- *
1808
- * 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`.
1809
- *
1810
- * 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).
1811
- *
1812
- * 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).
1813
- *
1814
- * 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.
1815
- *
1816
- * ```js
1817
- * /// file: src/routes/+page.js
1818
- * let count = 0;
1819
- * export async function load({ depends }) {
1820
- * depends('increase:count');
1821
- *
1822
- * return { count: count++ };
1823
- * }
1824
- * ```
1825
- *
1826
- * ```html
1827
- * /// file: src/routes/+page.svelte
1828
- * <script>
1829
- * import { invalidate } from '$app/navigation';
1830
- *
1831
- * let { data } = $props();
1832
- *
1833
- * const increase = async () => {
1834
- * await invalidate('increase:count');
1835
- * }
1836
- * </script>
1837
- *
1838
- * <p>{data.count}<p>
1839
- * <button on:click={increase}>Increase Count</button>
1840
- * ```
1841
- */
1842
- depends: (...deps: string[]) => void;
1843
- /**
1844
- * Use this function to opt out of dependency tracking for everything that is synchronously called within the callback. Example:
1845
- *
1846
- * ```js
1847
- * /// file: src/routes/+page.js
1848
- * export async function load({ untrack, url }) {
1849
- * // Untrack url.pathname so that path changes don't trigger a rerun
1850
- * if (untrack(() => url.pathname === '/')) {
1851
- * return { message: 'Welcome!' };
1852
- * }
1853
- * }
1854
- * ```
1855
- */
1856
- untrack: <T>(fn: () => T) => T;
1857
-
1858
- /**
1859
- * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
1860
- * @since 2.31.0
1861
- */
1862
- tracing: {
1863
- /** Whether tracing is enabled. */
1864
- enabled: boolean;
1865
- /** The root span for the request. This span is named `sveltekit.handle.root`. */
1866
- root: Span;
1867
- /** The span associated with the current server `load` function. */
1868
- current: Span;
1869
- };
1870
- }
1871
-
1872
- /**
1873
- * Shape of a form action method that is part of `export const actions = {...}` in `+page.server.js`.
1874
- * See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
1875
- */
1876
- export type Action<
1877
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1878
- OutputData extends Record<string, any> | void = Record<string, any> | void,
1879
- RouteId extends AppRouteId | null = AppRouteId | null
1880
- > = (event: RequestEvent<Params, RouteId>) => MaybePromise<OutputData>;
1881
-
1882
- /**
1883
- * Shape of the `export const actions = {...}` object in `+page.server.js`.
1884
- * See [form actions](https://svelte.dev/docs/kit/form-actions) for more information.
1885
- */
1886
- export type Actions<
1887
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1888
- OutputData extends Record<string, any> | void = Record<string, any> | void,
1889
- RouteId extends AppRouteId | null = AppRouteId | null
1890
- > = Record<string, Action<Params, OutputData, RouteId>>;
1891
-
1892
- /**
1893
- * When calling a form action via fetch, the response will be one of these shapes.
1894
- * ```svelte
1895
- * <form method="post" use:enhance={() => {
1896
- * return ({ result }) => {
1897
- * // result is of type ActionResult
1898
- * };
1899
- * }}
1900
- * ```
1901
- *
1902
- * Success and failure results carry the root-relative `pathname + search` of the action URL, with
1903
- * the `?/actionName` parameter removed. Redirect results carry the redirect target. Server-generated
1904
- * error results also carry the action location, while client-generated errors such as network
1905
- * failures do not. `update` uses this location to emulate native form navigation.
1906
- */
1907
- export type ActionResult<
1908
- Success extends Record<string, unknown> | undefined = Record<string, any>,
1909
- Failure extends Record<string, unknown> | undefined = Record<string, any>
1910
- > =
1911
- | { type: 'success'; status: number; data?: Success; location: string }
1912
- | { type: 'failure'; status: number; data?: Failure; location: string }
1913
- | { type: 'redirect'; status: number; location: string }
1914
- | { type: 'error'; status?: number; error: App.Error; location?: string };
1915
-
1916
- /**
1917
- * The object returned by the [`error`](https://svelte.dev/docs/kit/@sveltejs-kit#error) function.
1918
- */
1919
- export interface HttpError {
1920
- /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
1921
- status: number;
1922
- /** The content of the error. */
1923
- body: App.Error;
1924
- }
1925
-
1926
- /**
1927
- * The object returned by the [`redirect`](https://svelte.dev/docs/kit/@sveltejs-kit#redirect) function.
1928
- */
1929
- export interface Redirect {
1930
- /** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
1931
- status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
1932
- /** The location to redirect to. */
1933
- location: string;
1934
- }
1935
-
1936
- export type SubmitFunction<
1937
- Success extends Record<string, unknown> | undefined = Record<string, any>,
1938
- Failure extends Record<string, unknown> | undefined = Record<string, any>
1939
- > = (input: {
1940
- action: URL;
1941
- formData: FormData;
1942
- formElement: HTMLFormElement;
1943
- controller: AbortController;
1944
- submitter: HTMLElement | null;
1945
- cancel: () => void;
1946
- }) => MaybePromise<
1947
- | void
1948
- | ((opts: {
1949
- formData: FormData;
1950
- formElement: HTMLFormElement;
1951
- action: URL;
1952
- result: ActionResult<Success, Failure>;
1953
- /**
1954
- * Call this to get the default behavior of a form submission response.
1955
- * @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.
1956
- */
1957
- update: (options?: {
1958
- reset?: boolean;
1959
- refreshAll?: boolean;
1960
- navigate?: boolean;
1961
- /** @deprecated Use `refreshAll` instead. */
1962
- invalidateAll?: boolean;
1963
- }) => Promise<void>;
1964
- }) => MaybePromise<void>)
1965
- >;
1966
-
1967
- /**
1968
- * The type of `export const snapshot` exported from a page or layout component.
1969
- * @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.
1970
1623
  */
1971
1624
  export interface Snapshot<T = any> {
1972
1625
  capture: () => T;
1973
1626
  restore: (snapshot: T) => void;
1974
1627
  }
1975
1628
 
1976
- export type ReadonlyURLSearchParams = Omit<URLSearchParams, 'set' | 'append' | 'delete' | 'sort'>;
1977
-
1978
- export type ReadonlyURL = Readonly<
1979
- Omit<URL, 'searchParams'> & {
1980
- searchParams: ReadonlyURLSearchParams;
1981
- }
1982
- >;
1983
-
1984
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
1985
1630
  type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
1986
1631
 
@@ -2721,11 +2366,20 @@ declare module '@sveltejs/kit' {
2721
2366
  type PrerenderHttpErrorHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderHttpErrorHandler;
2722
2367
  type PrerenderMissingIdHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderMissingIdHandler;
2723
2368
  type PrerenderUnseenRoutesHandlerValue =
2724
- 'fail' | 'warn' | 'ignore' | PrerenderUnseenRoutesHandler;
2369
+ | 'fail'
2370
+ | 'warn'
2371
+ | 'ignore'
2372
+ | PrerenderUnseenRoutesHandler;
2725
2373
  type PrerenderEntryGeneratorMismatchHandlerValue =
2726
- 'fail' | 'warn' | 'ignore' | PrerenderEntryGeneratorMismatchHandler;
2374
+ | 'fail'
2375
+ | 'warn'
2376
+ | 'ignore'
2377
+ | PrerenderEntryGeneratorMismatchHandler;
2727
2378
  type PrerenderInvalidUrlHandlerValue =
2728
- 'fail' | 'warn' | 'ignore' | PrerenderInvalidUrlHandler;
2379
+ | 'fail'
2380
+ | 'warn'
2381
+ | 'ignore'
2382
+ | PrerenderInvalidUrlHandler;
2729
2383
 
2730
2384
  export type PrerenderOption = boolean | 'auto';
2731
2385
 
@@ -2767,7 +2421,7 @@ declare module '@sveltejs/kit' {
2767
2421
  /**
2768
2422
  * Throws an error with a HTTP status code and an optional message.
2769
2423
  * When called during request handling, this will cause SvelteKit to
2770
- * return an error response without invoking `handleError`.
2424
+ * return an error response; the error will be passed to `handleError` as an _expected_ error.
2771
2425
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2772
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.
2773
2427
  * @param message The error message.
@@ -2781,7 +2435,7 @@ declare module '@sveltejs/kit' {
2781
2435
  /**
2782
2436
  * Throws an error with a HTTP status code and an optional message.
2783
2437
  * When called during request handling, this will cause SvelteKit to
2784
- * return an error response without invoking `handleError`.
2438
+ * return an error response; the error will be passed to `handleError` as an _expected_ error.
2785
2439
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2786
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.
2787
2441
  * @param message The error message.
@@ -2789,14 +2443,11 @@ declare module '@sveltejs/kit' {
2789
2443
  * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
2790
2444
  * @throws {Error} If the provided status is invalid (not between 400 and 599).
2791
2445
  */
2792
- export function error(status: number, message: string, properties: {
2793
- status: number;
2794
- message: string;
2795
- } 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;
2796
2447
  /**
2797
2448
  * Throws an error with a HTTP status code and an optional message.
2798
2449
  * When called during request handling, this will cause SvelteKit to
2799
- * return an error response without invoking `handleError`.
2450
+ * return an error response; the error will be passed to `handleError` as an _expected_ error.
2800
2451
  * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
2801
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
2802
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.
@@ -2956,203 +2607,556 @@ declare module '@sveltejs/kit/env' {
2956
2607
  export {};
2957
2608
  }
2958
2609
 
2959
- declare module '@sveltejs/kit/hooks' {
2960
- 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' {
2961
2814
  /**
2962
- * A helper function for sequencing multiple `handle` calls in a middleware-like manner.
2963
- * The behavior for the `handle` options is as follows:
2964
- * - `transformPageChunk` is applied in reverse order and merged
2965
- * - `preload` is applied in forward order, the first option "wins" and no `preload` options after it are called
2966
- * - `filterSerializedResponseHeaders` behaves the same as `preload`
2815
+ * Use this function to deserialize the response from a form submission.
2816
+ * Usage:
2967
2817
  *
2968
2818
  * ```js
2969
- * /// file: src/hooks.server.js
2970
- * import { sequence } from '@sveltejs/kit/hooks';
2819
+ * import { deserialize } from '$app/forms';
2971
2820
  *
2972
- * /// type: import('@sveltejs/kit').Handle
2973
- * async function first({ event, resolve }) {
2974
- * console.log('first pre-processing');
2975
- * const result = await resolve(event, {
2976
- * transformPageChunk: ({ html }) => {
2977
- * // transforms are applied in reverse order
2978
- * console.log('first transform');
2979
- * return html;
2980
- * },
2981
- * preload: () => {
2982
- * // this one wins as it's the first defined in the chain
2983
- * console.log('first preload');
2984
- * return true;
2985
- * }
2986
- * });
2987
- * console.log('first post-processing');
2988
- * return result;
2989
- * }
2821
+ * async function handleSubmit(event) {
2822
+ * const response = await fetch('/form?/action', {
2823
+ * method: 'POST',
2824
+ * body: new FormData(event.target)
2825
+ * });
2990
2826
  *
2991
- * /// type: import('@sveltejs/kit').Handle
2992
- * async function second({ event, resolve }) {
2993
- * console.log('second pre-processing');
2994
- * const result = await resolve(event, {
2995
- * transformPageChunk: ({ html }) => {
2996
- * console.log('second transform');
2997
- * return html;
2998
- * },
2999
- * preload: () => {
3000
- * console.log('second preload');
3001
- * return true;
3002
- * },
3003
- * filterSerializedResponseHeaders: () => {
3004
- * // this one wins as it's the first defined in the chain
3005
- * console.log('second filterSerializedResponseHeaders');
3006
- * return true;
3007
- * }
3008
- * });
3009
- * console.log('second post-processing');
3010
- * return result;
2827
+ * const result = deserialize(await response.text());
2828
+ * // ...
3011
2829
  * }
3012
- *
3013
- * export const handle = sequence(first, second);
3014
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.
3015
2835
  *
3016
- * 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.
3017
2841
  *
3018
- * ```
3019
- * first pre-processing
3020
- * first preload
3021
- * second pre-processing
3022
- * second filterSerializedResponseHeaders
3023
- * second transform
3024
- * first transform
3025
- * second post-processing
3026
- * first post-processing
3027
- * ```
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
3028
2848
  *
3029
- * 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
+ * ```
3030
2869
  *
3031
- * @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.
3032
2918
  * */
3033
- 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>;
3034
2921
 
3035
2922
  export {};
3036
2923
  }
3037
2924
 
3038
- declare module '@sveltejs/kit/node' {
3039
- export function getRequest({ request, base, bodySizeLimit }: {
3040
- request: import("http").IncomingMessage;
3041
- base: string;
3042
- bodySizeLimit?: number;
3043
- }): 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
+ }
3044
3048
 
3045
- export function setResponse(res: import("http").ServerResponse, response: Response): void;
3046
3049
  /**
3047
- * Converts a file on disk to a readable stream
3048
- * @since 2.4.0
3050
+ * The navigation that occurs when the app starts/hydrates
3049
3051
  */
3050
- export function createReadableStream(file: string): ReadableStream;
3052
+ export interface NavigationEnter extends NavigationBase {
3053
+ type: 'enter';
3051
3054
 
3052
- export {};
3053
- }
3055
+ /**
3056
+ * In case of a history back/forward navigation, the number of steps to go back/forward
3057
+ */
3058
+ delta?: undefined;
3054
3059
 
3055
- declare module '@sveltejs/kit/vite' {
3056
- import type { KitConfig } from '@sveltejs/kit';
3057
- import type { Options, SvelteConfig } from '@sveltejs/vite-plugin-svelte';
3058
- import type { Plugin } from 'vite';
3059
- /**
3060
- * Returns the SvelteKit Vite plugins.
3061
- * Any options that don't belong to SvelteKit are passed through to `vite-plugin-svelte`.
3062
- *
3063
- * Since version 3.0.0 you must pass [configuration](configuration) directly.
3064
- *
3065
- * Since version 2.62.0 you can pass configuration directly, in which case `svelte.config.js` is ignored.
3066
- *
3067
- * */
3068
- 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
+ }
3069
3065
 
3070
- export {};
3071
- }
3066
+ export type NavigationExternal = NavigationGoto | NavigationLeave;
3072
3067
 
3073
- declare module '$app/env' {
3074
3068
  /**
3075
- * `true` if the app is running in the browser.
3069
+ * A navigation triggered by a `goto(...)` call or a redirect
3076
3070
  */
3077
- export const browser: boolean;
3071
+ export interface NavigationGoto extends NavigationBase {
3072
+ type: 'goto';
3073
+ }
3078
3074
 
3079
3075
  /**
3080
- * 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
3081
3077
  */
3082
- export const dev: boolean;
3078
+ export interface NavigationLeave extends NavigationBase {
3079
+ type: 'leave';
3080
+ }
3083
3081
 
3084
3082
  /**
3085
- * 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">`
3086
3084
  */
3087
- 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
+ }
3088
3093
 
3089
3094
  /**
3090
- * The value of `config.version.name`.
3095
+ * A navigation triggered by back/forward navigation
3091
3096
  */
3092
- export const version: string;
3097
+ export interface NavigationPopState extends NavigationBase {
3098
+ type: 'popstate';
3093
3099
 
3094
- export {};
3095
- }
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
+ }
3096
3110
 
3097
- declare module '$app/forms' {
3098
3111
  /**
3099
- * Use this function to deserialize the response from a form submission.
3100
- * Usage:
3101
- *
3102
- * ```js
3103
- * import { deserialize } from '$app/forms';
3104
- *
3105
- * async function handleSubmit(event) {
3106
- * const response = await fetch('/form?/action', {
3107
- * method: 'POST',
3108
- * body: new FormData(event.target)
3109
- * });
3110
- *
3111
- * const result = deserialize(await response.text());
3112
- * // ...
3113
- * }
3114
- * ```
3115
- * */
3116
- 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
+
3117
3129
  /**
3118
- * This action enhances a `<form>` element that otherwise would work without JavaScript.
3119
- *
3120
- * The `submit` function is called upon submission with the given FormData and the `action` that should be triggered.
3121
- * If `cancel` is called, the form will not be submitted.
3122
- * You can use the abort `controller` to cancel the submission in case another one starts.
3123
- * If a function is returned, that function is called with the response from the server.
3124
- * If nothing is returned, the fallback will be used.
3125
- *
3126
- * If this function or its return value isn't set, it emulates the browser-native behaviour, just without the full-page reload. It
3127
- * - resets the `<form>` element and refreshes all data in case of a successful submission with no redirect response
3128
- * - updates the `form` prop, `page.form` and `page.status` if the action is on the same page as the form
3129
- * - 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
3130
- * - redirects in case of a redirect response
3131
- * - 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
3132
- *
3133
- * If you provide a custom function with a callback and want to use the default behavior, invoke `update` in your callback.
3134
- * It accepts an options object
3135
- * - `reset: false` if you don't want the `<form>` values to be reset after a successful submission
3136
- * - `refreshAll` to control whether all data is refreshed after submission; it defaults to `true` for successes and `false` for failures
3137
- * - `navigate: false` to apply non-redirect results to the current page rather than navigating to `result.location`; redirects are always followed
3138
- * @param form_element The form element
3139
- * @param submit Submit callback
3130
+ * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
3140
3131
  */
3141
- 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>): {
3142
- destroy(): void;
3132
+ export type BeforeNavigate = Navigation & {
3133
+ /**
3134
+ * Call this to prevent the navigation from starting.
3135
+ */
3136
+ cancel: () => void;
3143
3137
  };
3144
- /**
3145
- * Updates the `form` property of the current page with the given data and updates `page.status`.
3146
- * In case of an error, it renders the nearest error page. In case of a redirect, it navigates to
3147
- * the redirect location.
3148
- * */
3149
- export function applyAction<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: import("@sveltejs/kit").ActionResult<Success, Failure>): Promise<void>;
3150
3138
 
3151
- export {};
3152
- }
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
+ };
3153
3149
 
3154
- declare module '$app/navigation' {
3155
- 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
+ };
3156
3160
  /**
3157
3161
  * A lifecycle function that captures state before navigating and restores it when traversing history.
3158
3162
  *
@@ -3173,7 +3177,7 @@ declare module '$app/navigation' {
3173
3177
  *
3174
3178
  * `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3175
3179
  * */
3176
- export function afterNavigate(callback: (navigation: import("@sveltejs/kit").AfterNavigate) => void): void;
3180
+ export function afterNavigate(callback: (navigation: AfterNavigate) => void): void;
3177
3181
  /**
3178
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.
3179
3183
  *
@@ -3185,7 +3189,7 @@ declare module '$app/navigation' {
3185
3189
  *
3186
3190
  * `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3187
3191
  * */
3188
- export function beforeNavigate(callback: (navigation: import("@sveltejs/kit").BeforeNavigate) => void): void;
3192
+ export function beforeNavigate(callback: (navigation: BeforeNavigate) => void): void;
3189
3193
  /**
3190
3194
  * A lifecycle function that runs the supplied `callback` immediately before we navigate to a new URL except during full-page navigations.
3191
3195
  *
@@ -3195,7 +3199,7 @@ declare module '$app/navigation' {
3195
3199
  *
3196
3200
  * `onNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3197
3201
  * */
3198
- export function onNavigate(callback: (navigation: import("@sveltejs/kit").OnNavigate) => MaybePromise<(() => void) | void>): void;
3202
+ export function onNavigate(callback: (navigation: OnNavigate) => MaybePromise<(() => void) | void>): void;
3199
3203
  /**
3200
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.
3201
3205
  * This is generally discouraged, since it breaks user expectations.
@@ -3213,7 +3217,7 @@ declare module '$app/navigation' {
3213
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.
3214
3218
  * @param opts Options related to the navigation
3215
3219
  * */
3216
- export function goto(url: string | URL, opts?: import("@sveltejs/kit").GotoOptions): Promise<void>;
3220
+ export function goto(url: string | URL, opts?: GotoOptions): Promise<void>;
3217
3221
  /**
3218
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.
3219
3223
  *
@@ -3290,7 +3294,7 @@ declare module '$app/navigation' {
3290
3294
  * Returns a Promise that resolves when the modules have been imported.
3291
3295
  *
3292
3296
  * */
3293
- export function preloadCode(id: RouteId): Promise<void>;
3297
+ export function preloadCode(id: import("$app/types").RouteId): Promise<void>;
3294
3298
  /**
3295
3299
  * Programmatically create a new history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
3296
3300
  *
@@ -3660,6 +3664,72 @@ declare module '$app/service-worker' {
3660
3664
  }
3661
3665
 
3662
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
+ }
3663
3733
  /**
3664
3734
  * A read-only reactive object with information about the current page, serving several use cases:
3665
3735
  * - retrieving the combined `data` of all pages/layouts anywhere in your component tree (also see [loading data](https://svelte.dev/docs/kit/load))
@@ -3696,12 +3766,12 @@ declare module '$app/state' {
3696
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.
3697
3767
  *
3698
3768
  * */
3699
- export const page: import("@sveltejs/kit").Page;
3769
+ export const page: Page;
3700
3770
  /**
3701
3771
  * A read-only object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
3702
3772
  * Values are `null` when no navigation is occurring, or during server rendering.
3703
3773
  * */
3704
- export const navigating: import("@sveltejs/kit").Navigation | {
3774
+ export const navigating: Navigation | {
3705
3775
  from: null;
3706
3776
  to: null;
3707
3777
  type: null;
@@ -3744,7 +3814,7 @@ declare module '$app/state' {
3744
3814
  */
3745
3815
  declare namespace App {
3746
3816
  /**
3747
- * 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).
3748
3818
  */
3749
3819
  export interface Error {
3750
3820
  status: number;