@sveltejs/kit 3.0.0-next.2 → 3.0.0-next.20

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 (192) hide show
  1. package/package.json +58 -36
  2. package/src/cli.js +14 -11
  3. package/src/constants.js +6 -1
  4. package/src/core/adapt/builder.js +54 -60
  5. package/src/core/adapt/index.js +2 -5
  6. package/src/core/config/index.js +141 -76
  7. package/src/core/config/options.js +260 -260
  8. package/src/core/config/types.d.ts +1 -1
  9. package/src/core/env.js +143 -13
  10. package/src/core/generate_manifest/index.js +18 -15
  11. package/src/core/postbuild/analyse.js +7 -19
  12. package/src/core/postbuild/crawl.js +22 -6
  13. package/src/core/postbuild/entities.js +8 -2
  14. package/src/core/postbuild/fallback.js +4 -2
  15. package/src/core/postbuild/prerender.js +193 -69
  16. package/src/core/postbuild/queue.js +2 -1
  17. package/src/core/sync/create_manifest_data/conflict.js +1 -1
  18. package/src/core/sync/create_manifest_data/index.js +72 -52
  19. package/src/core/sync/sync.js +35 -26
  20. package/src/core/sync/ts.js +1 -1
  21. package/src/core/sync/utils.js +22 -2
  22. package/src/core/sync/{write_non_ambient.js → write_app_types.js} +105 -56
  23. package/src/core/sync/write_client_manifest.js +13 -28
  24. package/src/core/sync/write_env.js +7 -5
  25. package/src/core/sync/write_server.js +25 -33
  26. package/src/core/sync/write_tsconfig/index.js +274 -0
  27. package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
  28. package/src/core/sync/write_tsconfig/utils.js +77 -0
  29. package/src/core/sync/write_tsconfig/validate.js +128 -0
  30. package/src/core/sync/write_types/index.js +119 -116
  31. package/src/core/utils.js +30 -5
  32. package/src/exports/env/index.js +77 -0
  33. package/src/exports/env/public.d.ts +55 -0
  34. package/src/exports/hooks/index.js +3 -9
  35. package/src/exports/hooks/public.d.ts +194 -0
  36. package/src/exports/hooks/sequence.js +9 -6
  37. package/src/exports/index.js +53 -20
  38. package/src/exports/internal/client.js +5 -0
  39. package/src/exports/internal/env.js +8 -5
  40. package/src/exports/internal/index.js +1 -90
  41. package/src/exports/internal/{event.js → server/event.js} +1 -2
  42. package/src/exports/internal/server/index.js +37 -0
  43. package/src/exports/internal/server/telemetry.js +95 -0
  44. package/src/exports/internal/shared.js +90 -0
  45. package/src/exports/node/index.js +64 -22
  46. package/src/exports/params/index.js +70 -0
  47. package/src/exports/params/public.d.ts +63 -0
  48. package/src/exports/public.d.ts +219 -1118
  49. package/src/exports/url.js +86 -0
  50. package/src/exports/vite/build/build_server.js +53 -64
  51. package/src/exports/vite/build/remote.js +24 -19
  52. package/src/exports/vite/build/utils.js +0 -8
  53. package/src/exports/vite/dev/index.js +199 -125
  54. package/src/exports/vite/index.js +1514 -833
  55. package/src/exports/vite/module_ids.js +2 -2
  56. package/src/exports/vite/preview/index.js +32 -24
  57. package/src/exports/vite/utils.js +83 -45
  58. package/src/pathname.js +55 -0
  59. package/src/runner.js +15 -0
  60. package/src/runtime/app/env/internal.js +4 -4
  61. package/src/runtime/app/env/types.d.ts +1 -1
  62. package/src/runtime/app/environment/index.js +3 -3
  63. package/src/runtime/app/{forms.js → forms/index.js} +73 -42
  64. package/src/runtime/app/forms/public.d.ts +2 -0
  65. package/src/runtime/app/forms/types.d.ts +56 -0
  66. package/src/runtime/app/internal/transport.js +53 -0
  67. package/src/runtime/app/manifest/index.js +1 -0
  68. package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
  69. package/src/runtime/app/navigation/public.d.ts +237 -0
  70. package/src/runtime/app/paths/client.js +37 -37
  71. package/src/runtime/app/paths/index.js +1 -1
  72. package/src/runtime/app/paths/internal/client.js +34 -2
  73. package/src/runtime/app/paths/internal/server.js +6 -23
  74. package/src/runtime/app/paths/internal.d.ts +3 -0
  75. package/src/runtime/app/paths/public.d.ts +1 -29
  76. package/src/runtime/app/paths/server.js +36 -17
  77. package/src/runtime/app/paths/types.d.ts +11 -19
  78. package/src/runtime/app/server/index.js +2 -2
  79. package/src/runtime/app/server/public.d.ts +519 -0
  80. package/src/runtime/app/server/remote/command.js +13 -11
  81. package/src/runtime/app/server/remote/form.js +61 -39
  82. package/src/runtime/app/server/remote/prerender.js +45 -45
  83. package/src/runtime/app/server/remote/query.js +106 -108
  84. package/src/runtime/app/server/remote/requested.js +27 -19
  85. package/src/runtime/app/server/remote/shared.js +75 -75
  86. package/src/runtime/app/service-worker/index.js +24 -0
  87. package/src/runtime/app/state/client.js +4 -2
  88. package/src/runtime/app/state/index.js +7 -5
  89. package/src/runtime/app/state/public.d.ts +72 -0
  90. package/src/runtime/app/state/server.js +3 -0
  91. package/src/runtime/app/stores.js +15 -78
  92. package/src/runtime/client/bundle.js +1 -1
  93. package/src/runtime/client/client-entry.js +3 -0
  94. package/src/runtime/client/client.js +1336 -648
  95. package/src/runtime/client/constants.js +3 -6
  96. package/src/runtime/client/entry.js +24 -3
  97. package/src/runtime/client/fetcher.js +25 -25
  98. package/src/runtime/client/ndjson.js +1 -1
  99. package/src/runtime/client/parse.js +1 -1
  100. package/src/runtime/client/payload.js +17 -0
  101. package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
  102. package/src/runtime/client/remote-functions/command.svelte.js +37 -61
  103. package/src/runtime/client/remote-functions/form.svelte.js +267 -178
  104. package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
  105. package/src/runtime/client/remote-functions/query/index.js +10 -17
  106. package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
  107. package/src/runtime/client/remote-functions/query/proxy.js +5 -5
  108. package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
  109. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  110. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
  111. package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
  112. package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
  113. package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
  114. package/src/runtime/client/snapshots.js +147 -0
  115. package/src/runtime/client/state.svelte.js +94 -55
  116. package/src/runtime/client/stream.js +3 -2
  117. package/src/runtime/client/types.d.ts +13 -9
  118. package/src/runtime/client/utils.js +22 -110
  119. package/src/runtime/components/root.svelte +56 -0
  120. package/src/runtime/env/dynamic/private.js +7 -0
  121. package/src/runtime/env/dynamic/public.js +7 -0
  122. package/src/runtime/env/static/private.js +6 -0
  123. package/src/runtime/env/static/public.js +6 -0
  124. package/src/runtime/form-utils.js +172 -61
  125. package/src/runtime/pathname.js +20 -32
  126. package/src/runtime/props.svelte.js +72 -0
  127. package/src/runtime/server/constants.js +0 -3
  128. package/src/runtime/server/cookie.js +70 -53
  129. package/src/runtime/server/csrf.js +65 -0
  130. package/src/runtime/server/data/index.js +48 -52
  131. package/src/runtime/server/dev.js +22 -0
  132. package/src/runtime/server/endpoint.js +3 -4
  133. package/src/runtime/server/env_module.js +0 -5
  134. package/src/runtime/server/errors.js +160 -0
  135. package/src/runtime/server/fetch.js +31 -38
  136. package/src/runtime/server/index.js +90 -64
  137. package/src/runtime/server/internal.js +71 -0
  138. package/src/runtime/server/page/actions.js +84 -64
  139. package/src/runtime/server/page/crypto.js +2 -2
  140. package/src/runtime/server/page/csp.js +88 -104
  141. package/src/runtime/server/page/data_serializer.js +22 -23
  142. package/src/runtime/server/page/index.js +35 -53
  143. package/src/runtime/server/page/load_data.js +47 -54
  144. package/src/runtime/server/page/render.js +172 -238
  145. package/src/runtime/server/page/respond_with_error.js +16 -30
  146. package/src/runtime/server/page/serialize_data.js +2 -13
  147. package/src/runtime/server/page/server_routing.js +85 -26
  148. package/src/runtime/server/remote-functions.js +639 -0
  149. package/src/runtime/server/respond.js +188 -129
  150. package/src/runtime/server/sourcemaps.js +183 -0
  151. package/src/runtime/server/state.js +53 -0
  152. package/src/runtime/server/utils.js +12 -154
  153. package/src/runtime/shared.js +20 -40
  154. package/src/runtime/utils.js +3 -0
  155. package/src/types/ambient-private.d.ts +11 -1
  156. package/src/types/ambient.d.ts +87 -36
  157. package/src/types/global-private.d.ts +25 -25
  158. package/src/types/internal.d.ts +160 -150
  159. package/src/types/private.d.ts +41 -1
  160. package/src/utils/error.js +28 -4
  161. package/src/utils/escape.js +9 -25
  162. package/src/utils/features.js +1 -1
  163. package/src/utils/filesystem.js +1 -23
  164. package/src/utils/fork.js +7 -2
  165. package/src/utils/hash.js +21 -0
  166. package/src/utils/http.js +8 -7
  167. package/src/utils/import.js +9 -2
  168. package/src/utils/imports.js +83 -0
  169. package/src/utils/mime.js +9 -0
  170. package/src/utils/page_nodes.js +6 -7
  171. package/src/utils/params.js +67 -0
  172. package/src/utils/regex.js +9 -0
  173. package/src/utils/routing.js +145 -73
  174. package/src/utils/shared-iterator.js +5 -0
  175. package/src/utils/streaming.js +14 -4
  176. package/src/utils/url.js +33 -2
  177. package/src/version.js +1 -1
  178. package/types/index.d.ts +2291 -2135
  179. package/types/index.d.ts.map +116 -108
  180. package/src/core/sync/write_ambient.js +0 -18
  181. package/src/core/sync/write_root.js +0 -148
  182. package/src/core/sync/write_tsconfig.js +0 -250
  183. package/src/exports/internal/server.js +0 -22
  184. package/src/exports/node/polyfills.js +0 -30
  185. package/src/runtime/server/app.js +0 -9
  186. package/src/runtime/server/remote.js +0 -457
  187. package/src/runtime/shared-server.js +0 -7
  188. package/src/runtime/telemetry/otel.js +0 -21
  189. package/src/runtime/telemetry/record_span.js +0 -65
  190. package/src/types/synthetic/$lib.md +0 -5
  191. /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
  192. /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
@@ -11,22 +11,18 @@ import {
11
11
  Prerendered,
12
12
  PrerenderEntryGeneratorMismatchHandlerValue,
13
13
  PrerenderHttpErrorHandlerValue,
14
+ PrerenderInvalidUrlHandlerValue,
14
15
  PrerenderMissingIdHandlerValue,
15
16
  PrerenderUnseenRoutesHandlerValue,
16
17
  PrerenderOption,
17
18
  RequestOptions,
18
- RouteSegment,
19
- DeepPartial,
20
- IsAny
19
+ RouteSegment
21
20
  } from '../types/private.js';
22
21
  import { BuildData, SSRNodeLoader, SSRRoute, ValidatedConfig } from 'types';
23
22
  import { SvelteConfig } from '@sveltejs/vite-plugin-svelte';
24
- import { StandardSchemaV1 } from '@standard-schema/spec';
25
- import {
26
- RouteId as AppRouteId,
27
- LayoutParams as AppLayoutParams,
28
- ResolvedPathname
29
- } from '$app/types';
23
+ import { Plugin } from 'vite';
24
+ import { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
25
+ import { ParamMatcher } from '@sveltejs/kit/params';
30
26
 
31
27
  export { PrerenderOption } from '../types/private.js';
32
28
 
@@ -54,7 +50,7 @@ export interface Adapter {
54
50
  * Test support for `read` from `$app/server`.
55
51
  * @param details.config The merged adapter-specific route config exported from the route with `export const config`
56
52
  */
57
- read?: (details: { config: any; route: { id: string } }) => boolean;
53
+ read?: (details: { config: Record<string, any>; route: { id: string } }) => boolean;
58
54
 
59
55
  /**
60
56
  * Test support for `instrumentation.server.js`. To pass, the adapter must support running `instrumentation.server.js` prior to the application code.
@@ -67,6 +63,20 @@ export interface Adapter {
67
63
  * during dev, build and prerendering.
68
64
  */
69
65
  emulate?: () => MaybePromise<Emulator>;
66
+ vite?: {
67
+ plugins?: {
68
+ /**
69
+ * Vite plugins placed before any of SvelteKit's own plugins.
70
+ * @since 3.0.0
71
+ */
72
+ pre?: Plugin[];
73
+ /**
74
+ * Vite plugins placed after any of SvelteKit's own plugins.
75
+ * @since 3.0.0
76
+ */
77
+ post?: Plugin[];
78
+ };
79
+ };
70
80
  }
71
81
 
72
82
  export type LoadProperties<input extends Record<string, any> | void> = input extends void
@@ -110,12 +120,18 @@ type UnpackValidationError<T> =
110
120
  export interface Builder {
111
121
  /** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
112
122
  log: Logger;
113
- /** Remove `dir` and all its contents. */
123
+ /**
124
+ * Remove `dir` and all its contents.
125
+ * @deprecated Use `fs.rmSync(dir, { force: true, recursive: true })` instead
126
+ */
114
127
  rimraf: (dir: string) => void;
115
- /** Create `dir` and any required parent directories. */
128
+ /**
129
+ * Create `dir` and any required parent directories.
130
+ * @deprecated Use `fs.mkdirSync(dir, { recursive: true })` instead
131
+ */
116
132
  mkdirp: (dir: string) => void;
117
133
 
118
- /** The fully resolved Svelte config. */
134
+ /** The fully resolved SvelteKit config. */
119
135
  config: ValidatedConfig;
120
136
  /** Information about prerendered pages and assets, if any. */
121
137
  prerendered: Prerendered;
@@ -146,7 +162,8 @@ export interface Builder {
146
162
 
147
163
  /**
148
164
  * Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
149
- * @param opts a relative path to the base directory of the app and optionally in which format (esm or cjs) the manifest should be generated
165
+ * @param opts
166
+ * @param opts.relativePath A relative path to the base directory of the server build output
150
167
  */
151
168
  generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;
152
169
 
@@ -241,8 +258,9 @@ export interface Builder {
241
258
  /**
242
259
  * Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals.
243
260
  * @param {string} directory The directory containing the files to be compressed
261
+ * @returns an array of the files in `directory` that were compressed
244
262
  */
245
- compress: (directory: string) => Promise<void>;
263
+ compress: (directory: string) => Promise<string[]>;
246
264
  }
247
265
 
248
266
  /**
@@ -263,48 +281,72 @@ export interface Cookies {
263
281
  /**
264
282
  * Gets a cookie that was previously set with `cookies.set`, or from the request headers.
265
283
  * @param name the name of the cookie
266
- * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
284
+ * @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
267
285
  */
268
286
  get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined;
269
287
 
270
288
  /**
271
289
  * Gets all cookies that were previously set with `cookies.set`, or from the request headers.
272
- * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
290
+ * @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
273
291
  */
274
292
  getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
275
293
 
276
294
  /**
277
295
  * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
278
296
  *
279
- * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
297
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
280
298
  *
281
299
  * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
282
300
  * @param name the name of the cookie
283
301
  * @param value the cookie value
284
- * @param opts the options passed to `cookie.serialize` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
302
+ * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
285
303
  */
286
304
  set: (name: string, value: string, opts: import('cookie').SerializeOptions) => void;
287
305
 
288
306
  /**
289
307
  * Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
290
308
  *
291
- * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
309
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
292
310
  *
293
311
  * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
294
312
  * @param name the name of the cookie
295
- * @param opts the options passed to `cookie.serialize` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
313
+ * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
296
314
  */
297
315
  delete: (name: string, opts: import('cookie').SerializeOptions) => void;
298
316
 
317
+ /**
318
+ * Parses a single `Set-Cookie` header. This allows you to apply cookies received from an external source:
319
+ *
320
+ * ```js
321
+ * import { getRequestEvent } from '$app/server';
322
+ *
323
+ * export async function GET() {
324
+ * const { cookies } = getRequestEvent();
325
+ *
326
+ * const response = await fetch('...');
327
+ *
328
+ * for (const str of response.headers.getSetCookie()) {
329
+ * const { name, value, ...options } = cookies.parse(str);
330
+ * cookies.set(name, value, { ...options, path: '/' });
331
+ * }
332
+ *
333
+ * // ...
334
+ * }
335
+ * ```
336
+ *
337
+ * Note the use of `headers.getSetCookie()`, which returns an array of cookie headers, _not_ `headers.get('set-cookie')` which returns a single comma-separated string.
338
+ */
339
+ parse: typeof import('cookie').parseSetCookie;
340
+
299
341
  /**
300
342
  * Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
301
343
  *
302
- * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
344
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
303
345
  *
304
346
  * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
305
347
  * @param name the name of the cookie
306
348
  * @param value the cookie value
307
- * @param opts the options passed to `cookie.serialize` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
349
+ * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
308
350
  */
309
351
  serialize: (name: string, value: string, opts: import('cookie').SerializeOptions) => string;
310
352
  }
@@ -321,38 +363,18 @@ export interface Emulator {
321
363
  }
322
364
 
323
365
  export interface KitConfig {
324
- // TODO: remove this in 4.0
325
366
  /**
326
367
  * Your [adapter](https://svelte.dev/docs/kit/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms.
327
368
  * @default undefined
328
- * @deprecated removed in 3.0.0. Adapters should now be passed to the `sveltekit` Vite plugin in `vite.config.js`
329
369
  */
330
370
  adapter?: Adapter;
331
371
  /**
332
372
  * An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
333
373
  *
334
- * ```js
335
- * /// file: svelte.config.js
336
- * /// type: import('@sveltejs/kit').Config
337
- * const config = {
338
- * kit: {
339
- * alias: {
340
- * // this will match a file
341
- * 'my-file': 'path/to/my-file.js',
342
- *
343
- * // this will match a directory and its contents
344
- * // (`my-directory/x` resolves to `path/to/my-directory/x`)
345
- * 'my-directory': 'path/to/my-directory',
346
- *
347
- * // an alias ending /* will only match
348
- * // the contents of a directory, not the directory itself
349
- * 'my-directory/*': 'path/to/my-directory/*'
350
- * }
351
- * }
352
- * };
353
- * ```
374
+ * This option is deprecated. Use [subpath imports](https://svelte.dev/docs/kit/$lib) instead.
354
375
  *
355
376
  * > [!NOTE] You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
377
+ * @deprecated
356
378
  * @default {}
357
379
  */
358
380
  alias?: Record<string, string>;
@@ -367,24 +389,26 @@ export interface KitConfig {
367
389
  * [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) configuration. CSP helps to protect your users against cross-site scripting (XSS) attacks, by limiting the places resources can be loaded from. For example, a configuration like this...
368
390
  *
369
391
  * ```js
370
- * /// file: svelte.config.js
371
- * /// type: import('@sveltejs/kit').Config
372
- * const config = {
373
- * kit: {
374
- * csp: {
375
- * directives: {
376
- * 'script-src': ['self']
377
- * },
378
- * // must be specified with either the `report-uri` or `report-to` directives, or both
379
- * reportOnly: {
380
- * 'script-src': ['self'],
381
- * 'report-uri': ['/']
382
- * }
383
- * }
384
- * }
385
- * };
386
- *
387
- * export default config;
392
+ * /// file: vite.config.js
393
+ * import { sveltekit } from '@sveltejs/kit/vite';
394
+ * import { defineConfig } from 'vite';
395
+ *
396
+ * export default defineConfig({
397
+ * plugins: [
398
+ * sveltekit({
399
+ * csp: {
400
+ * directives: {
401
+ * 'script-src': ['self']
402
+ * },
403
+ * // must be specified with either the `report-uri` or `report-to` directives, or both
404
+ * reportOnly: {
405
+ * 'script-src': ['self'],
406
+ * 'report-uri': ['/']
407
+ * }
408
+ * }
409
+ * })
410
+ * ]
411
+ * });
388
412
  * ```
389
413
  *
390
414
  * ...would prevent scripts loading from external sites. SvelteKit will augment the specified directives with nonces or hashes (depending on `mode`) for any inline styles and scripts it generates.
@@ -395,9 +419,7 @@ export interface KitConfig {
395
419
  *
396
420
  * > [!NOTE] When `mode` is `'auto'`, SvelteKit will use nonces for dynamically rendered pages and hashes for prerendered pages. Using nonces with prerendered pages is insecure and therefore forbidden.
397
421
  *
398
- * > [!NOTE] Note that most [Svelte transitions](https://svelte.dev/tutorial/svelte/transition) work by creating an inline `<style>` element. If you use these in your app, you must either leave the `style-src` directive unspecified or add `unsafe-inline`.
399
- *
400
- * If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle) to roll your own CSP.
422
+ * If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://svelte.dev/docs/kit/hooks#handle) to roll your own CSP.
401
423
  */
402
424
  csp?: {
403
425
  /**
@@ -437,7 +459,10 @@ export interface KitConfig {
437
459
  *
438
460
  * CSRF checks only apply in production, not in local development.
439
461
  * @default []
440
- * @example ['https://checkout.stripe.com', 'https://accounts.google.com']
462
+ * @example
463
+ * ```js
464
+ * ['https://checkout.stripe.com', 'https://accounts.google.com']
465
+ * ```
441
466
  */
442
467
  trustedOrigins?: string[];
443
468
  };
@@ -459,32 +484,6 @@ export interface KitConfig {
459
484
  };
460
485
  /** Experimental features. Here be dragons. These are not subject to semantic versioning, so breaking changes or removal can happen in any release. */
461
486
  experimental?: {
462
- /**
463
- * Options for enabling server-side [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations including the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle), [`load` functions](https://svelte.dev/docs/kit/load), [form actions](https://svelte.dev/docs/kit/form-actions), and [remote functions](https://svelte.dev/docs/kit/remote-functions).
464
- * @default { server: false, serverFile: false }
465
- * @since 2.31.0
466
- */
467
- tracing?: {
468
- /**
469
- * Enables server-side [OpenTelemetry](https://opentelemetry.io/) span emission for SvelteKit operations including the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle), [`load` functions](https://svelte.dev/docs/kit/load), [form actions](https://svelte.dev/docs/kit/form-actions), and [remote functions](https://svelte.dev/docs/kit/remote-functions).
470
- * @default false
471
- * @since 2.31.0
472
- */
473
- server?: boolean;
474
- };
475
-
476
- /**
477
- * @since 2.31.0
478
- */
479
- instrumentation?: {
480
- /**
481
- * Enables `instrumentation.server.js` for tracing and observability instrumentation.
482
- * @default false
483
- * @since 2.31.0
484
- */
485
- server?: boolean;
486
- };
487
-
488
487
  /**
489
488
  * Whether to enable the experimental remote functions feature. This feature is not yet stable and may be changed or removed at any time.
490
489
  * @default false
@@ -496,15 +495,6 @@ export interface KitConfig {
496
495
  * @default false
497
496
  */
498
497
  forkPreloads?: boolean;
499
-
500
- /**
501
- * Whether to enable the experimental handling of rendering errors.
502
- * When enabled, `<svelte:boundary>` is used to wrap components at each level
503
- * where there's an `+error.svelte`, rendering the error page if the component fails.
504
- * In addition, error boundaries also work on the server and the error object goes through `handleError`.
505
- * @default false
506
- */
507
- handleRenderingErrors?: boolean;
508
498
  };
509
499
  /**
510
500
  * Where to find various files within your project.
@@ -545,12 +535,6 @@ export interface KitConfig {
545
535
  */
546
536
  universal?: string;
547
537
  };
548
- /**
549
- * Your app's internal library, accessible throughout the codebase as `$lib`.
550
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
551
- * @default "src/lib"
552
- */
553
- lib?: string;
554
538
  /**
555
539
  * A directory containing [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching).
556
540
  * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
@@ -590,7 +574,7 @@ export interface KitConfig {
590
574
  */
591
575
  inlineStyleThreshold?: number;
592
576
  /**
593
- * An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.kit.moduleExtensions` will be ignored by the router.
577
+ * An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.moduleExtensions` will be ignored by the router.
594
578
  * @default [".js", ".ts"]
595
579
  */
596
580
  moduleExtensions?: string[];
@@ -672,14 +656,27 @@ export interface KitConfig {
672
656
  */
673
657
  assets?: '' | `http://${string}` | `https://${string}`;
674
658
  /**
675
- * A root-relative path that must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string. This specifies where your app is served from and allows the app to live on a non-root path. Note that you need to prepend all your root-relative links with the base value or they will point to the root of your domain, not your `base` (this is how the browser works). You can use [`base` from `$app/paths`](https://svelte.dev/docs/kit/$app-paths#base) for that: `<a href="{base}/your-page">Link</a>`. If you find yourself writing this often, it may make sense to extract this into a reusable component.
659
+ * A root-relative path that must start, but not end with `/` (e.g. `/base-path`), unless it is the empty string. This specifies where your app is served from and allows the app to live on a non-root path. Note that you need to prepend all your root-relative links with the base value or they will point to the root of your domain, not your `base` (this is how the browser works). You can use [`resolve(...)` from `$app/paths`](https://svelte.dev/docs/kit/$app-paths#resolve) for that: `<a href="{resolve('/your-page')}">Link</a>`. If you find yourself writing this often, it may make sense to extract this into a reusable component.
676
660
  * @default ""
677
661
  */
678
662
  base?: '' | `/${string}`;
663
+ /**
664
+ * The origin of your app, used for CSRF protection and prerendering.
665
+ *
666
+ * By default, this is `undefined`, meaning SvelteKit will derive the origin from `request.url` (which is set by the adapter, and ultimately by the platform).
667
+ *
668
+ * If your app is served from an origin that isn't known at request time — for example because it's deployed to a preview deployment whose URL isn't known at build time, or because it's behind a reverse proxy that doesn't pass the `host` header — you can set this to a string like `https://my-site.com`.
669
+ *
670
+ * This is also used as the value of `url.origin` during prerendering (when unset, it defaults to `http://sveltekit-prerender`), and as the trusted origin for CSRF checks on form submissions and remote function calls.
671
+ *
672
+ * @default undefined
673
+ * @since 3.0
674
+ */
675
+ origin?: string;
679
676
  /**
680
677
  * Whether to use relative asset paths.
681
678
  *
682
- * If `true`, `base` and `assets` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in more portable HTML.
679
+ * If `true`, paths created with `resolve()` and `asset()` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in more portable HTML.
683
680
  * If `false`, `%sveltekit.assets%` and references to build artifacts will always be root-relative paths, unless `paths.assets` is an external URL
684
681
  *
685
682
  * [Single-page app](https://svelte.dev/docs/kit/single-page-apps) fallback pages will always use absolute paths, regardless of this setting.
@@ -721,23 +718,27 @@ export interface KitConfig {
721
718
  * - `(details) => void` — a custom error handler that takes a `details` object with `status`, `path`, `referrer`, `referenceType` and `message` properties. If you `throw` from this function, the build will fail
722
719
  *
723
720
  * ```js
724
- * /// file: svelte.config.js
725
- * /// type: import('@sveltejs/kit').Config
726
- * const config = {
727
- * kit: {
728
- * prerender: {
729
- * handleHttpError: ({ path, referrer, message }) => {
730
- * // ignore deliberate link to shiny 404 page
731
- * if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
732
- * return;
733
- * }
721
+ * /// file: vite.config.js
722
+ * import { sveltekit } from '@sveltejs/kit/vite';
723
+ * import { defineConfig } from 'vite';
734
724
  *
735
- * // otherwise fail the build
736
- * throw new Error(message);
737
- * }
738
- * }
739
- * }
740
- * };
725
+ * export default defineConfig({
726
+ * plugins: [
727
+ * sveltekit({
728
+ * prerender: {
729
+ * handleHttpError: ({ path, referrer, message }) => {
730
+ * // ignore deliberate link to shiny 404 page
731
+ * if (path === '/not-found' && referrer === '/blog/how-we-built-our-404-page') {
732
+ * return;
733
+ * }
734
+ *
735
+ * // otherwise fail the build
736
+ * throw new Error(message);
737
+ * }
738
+ * }
739
+ * })
740
+ * ]
741
+ * });
741
742
  * ```
742
743
  *
743
744
  * @default "fail"
@@ -784,10 +785,17 @@ export interface KitConfig {
784
785
  */
785
786
  handleUnseenRoutes?: PrerenderUnseenRoutesHandlerValue;
786
787
  /**
787
- * The value of `url.origin` during prerendering; useful if it is included in rendered content.
788
- * @default "http://sveltekit-prerender"
788
+ * How to respond when SvelteKit encounters a URL it cannot parse while crawling prerendered HTML (for example, an AT Protocol URL such as `at://did:plc:...`).
789
+ *
790
+ * - `'fail'` — fail the build
791
+ * - `'ignore'` - silently ignore the failure and continue
792
+ * - `'warn'` — continue, but print a warning
793
+ * - `(details) => void` — a custom error handler that takes a `details` object with `href`, `referrer` and `message` properties. If you `throw` from this function, the build will fail
794
+ *
795
+ * @default "fail"
796
+ * @since 2.67.0
789
797
  */
790
- origin?: string;
798
+ handleInvalidUrl?: PrerenderInvalidUrlHandlerValue;
791
799
  };
792
800
  router?: {
793
801
  /**
@@ -812,8 +820,10 @@ export interface KitConfig {
812
820
  * This has several advantages:
813
821
  * - The client does not need to load the routing manifest upfront, which can lead to faster initial page loads
814
822
  * - The list of routes is hidden from public view
815
- * - The server has an opportunity to intercept each navigation (for example through a middleware), enabling (for example) A/B testing opaque to SvelteKit
816
-
823
+ * - The server has an opportunity to intercept each navigation (for example through middleware in front of SvelteKit, such as a reverse proxy or your platform's edge functions), enabling (for example) A/B testing opaque to SvelteKit
824
+ *
825
+ * Route resolution requests are answered as soon as the route has been looked up, before the `handle` hook is invoked. To intercept them within SvelteKit itself, use the `reroute` hook, which runs for these requests too.
826
+ *
817
827
  * The drawback is that for unvisited paths, resolution will take slightly longer (though this is mitigated by [preloading](https://svelte.dev/docs/kit/link-options#data-sveltekit-preload-data)).
818
828
  *
819
829
  * > [!NOTE] When using server-side route resolution and prerendering, the resolution is prerendered along with the route itself.
@@ -823,13 +833,7 @@ export interface KitConfig {
823
833
  */
824
834
  resolution?: 'client' | 'server';
825
835
  };
826
- serviceWorker?: {
827
- /**
828
- * Determine which files in your `static` directory will be available in `$service-worker.files`.
829
- * @default (filename) => !/\.DS_Store/.test(filename)
830
- */
831
- files?: (file: string) => boolean;
832
- } & (
836
+ serviceWorker?:
833
837
  | {
834
838
  /**
835
839
  * Whether to automatically register the service worker, if it exists.
@@ -847,14 +851,27 @@ export interface KitConfig {
847
851
  * @default true
848
852
  */
849
853
  register?: false;
850
- }
851
- );
854
+ };
855
+ /**
856
+ * Options for enabling [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations.
857
+ * @default { server: false }
858
+ */
859
+ tracing?: {
860
+ /**
861
+ * Enables server-side [OpenTelemetry](https://opentelemetry.io/) span emission for SvelteKit operations including the [`handle` hook](https://svelte.dev/docs/kit/hooks#handle), [`load` functions](https://svelte.dev/docs/kit/load), [form actions](https://svelte.dev/docs/kit/form-actions), and [remote functions](https://svelte.dev/docs/kit/remote-functions). Tracing — and more significantly, observability instrumentation — can have a nontrivial overhead, so consider whether you really need it, or if it might be more appropriate to turn it on in development and preview environments only.
862
+ * @default false
863
+ */
864
+ server?: boolean;
865
+ };
866
+ /**
867
+ * @deprecated Add configuration to `tsconfig.json` directly
868
+ */
852
869
  typescript?: {
853
870
  /**
854
871
  * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
855
872
  * This is useful for extending a shared `tsconfig.json` in a monorepo root, for example.
856
873
  *
857
- * Note that any paths configured here should be relative to the generated config file, which is written to `.svelte-kit/tsconfig.json`.
874
+ * Note that any paths configured here should be relative to the generated config file, which is written to `node_modules/$app/tsconfig.json`.
858
875
  *
859
876
  * @default (config) => config
860
877
  * @since 1.3.0
@@ -863,9 +880,9 @@ export interface KitConfig {
863
880
  };
864
881
  /**
865
882
  * Client-side navigation can be buggy if you deploy a new version of your app while people are using it. If the code for the new page is already loaded, it may have stale content; if it isn't, the app's route manifest may point to a JavaScript file that no longer exists.
866
- * SvelteKit helps you solve this problem through version management.
883
+ * SvelteKit helps you solve this problem through version management. The current version is included in data, remote, and form action responses via the `x-sveltekit-version` header, so SvelteKit can detect new deployments without polling — for example when a navigation triggers a server `load` function, or when a remote function is called. SvelteKit also checks for new versions when the tab regains focus or becomes visible.
867
884
  * If SvelteKit encounters an error while loading the page and detects that a new version has been deployed (using the `name` specified here, which defaults to a timestamp of the build) it will fall back to traditional full-page navigation.
868
- * Not all navigations will result in an error though, for example if the JavaScript for the next page is already loaded. If you still want to force a full-page navigation in these cases, use techniques such as setting the `pollInterval` and then using `beforeNavigate`:
885
+ * Not all navigations will result in an error though, for example if the JavaScript for the next page is already loaded. If you still want to force a full-page navigation in these cases, use `beforeNavigate`:
869
886
  * ```html
870
887
  * /// file: +layout.svelte
871
888
  * <script>
@@ -880,7 +897,7 @@ export interface KitConfig {
880
897
  * </script>
881
898
  * ```
882
899
  *
883
- * If you set `pollInterval` to a non-zero value, SvelteKit will poll for new versions in the background and set the value of [`updated.current`](https://svelte.dev/docs/kit/$app-state#updated) `true` when it detects one.
900
+ * In addition to these checks, SvelteKit polls for new versions on an interval and sets [`updated.current`](https://svelte.dev/docs/kit/$app-state#updated) to `true` when it detects one. Set `pollInterval` to `0` to disable polling (the header- and event-based checks will still run).
884
901
  */
885
902
  version?: {
886
903
  /**
@@ -889,136 +906,31 @@ export interface KitConfig {
889
906
  * For example, to use the current commit hash, you could do use `git rev-parse HEAD`:
890
907
  *
891
908
  * ```js
892
- * /// file: svelte.config.js
909
+ * /// file: vite.config.js
893
910
  * import * as child_process from 'node:child_process';
911
+ * import { sveltekit } from '@sveltejs/kit/vite';
912
+ * import { defineConfig } from 'vite';
894
913
  *
895
- * export default {
896
- * kit: {
897
- * version: {
898
- * name: child_process.execSync('git rev-parse HEAD').toString().trim()
899
- * }
900
- * }
901
- * };
914
+ * export default defineConfig({
915
+ * plugins: [
916
+ * sveltekit({
917
+ * version: {
918
+ * name: child_process.execSync('git rev-parse HEAD').toString().trim()
919
+ * }
920
+ * })
921
+ * ]
922
+ * });
902
923
  * ```
903
924
  */
904
925
  name?: string;
905
926
  /**
906
- * The interval in milliseconds to poll for version changes. If this is `0`, no polling occurs.
907
- * @default 0
927
+ * The interval in milliseconds to poll for version changes. If this is `0`, no polling occurs. SvelteKit also checks for new versions on server responses (via the `x-sveltekit-version` header) and when the tab regains focus or becomes visible, so polling is only needed for long-lived sessions on a single page.
928
+ * @default 3600000
908
929
  */
909
930
  pollInterval?: number;
910
931
  };
911
932
  }
912
933
 
913
- /**
914
- * The [`handle`](https://svelte.dev/docs/kit/hooks#Server-hooks-handle) hook runs every time the SvelteKit server receives a [request](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Request) and
915
- * determines the [response](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Response).
916
- * It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
917
- * This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
918
- */
919
- export type Handle = (input: {
920
- event: RequestEvent;
921
- resolve: (event: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>;
922
- }) => MaybePromise<Response>;
923
-
924
- /**
925
- * The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError) hook runs when an unexpected error is thrown while responding to a request.
926
- *
927
- * If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
928
- * Make sure that this function _never_ throws an error.
929
- */
930
- export type HandleServerError = (input: {
931
- error: unknown;
932
- event: RequestEvent;
933
- status: number;
934
- message: string;
935
- }) => MaybePromise<void | App.Error>;
936
-
937
- /**
938
- * The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleValidationError) hook runs when the argument to a remote function fails validation.
939
- *
940
- * It will be called with the validation issues and the event, and must return an object shape that matches `App.Error`.
941
- */
942
- export type HandleValidationError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
943
- (input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<App.Error>;
944
-
945
- /**
946
- * The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError) hook runs when an unexpected error is thrown while navigating.
947
- *
948
- * If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
949
- * Make sure that this function _never_ throws an error.
950
- */
951
- export type HandleClientError = (input: {
952
- error: unknown;
953
- event: NavigationEvent;
954
- status: number;
955
- message: string;
956
- }) => MaybePromise<void | App.Error>;
957
-
958
- /**
959
- * The [`handleFetch`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
960
- */
961
- export type HandleFetch = (input: {
962
- event: RequestEvent;
963
- request: Request;
964
- fetch: typeof fetch;
965
- }) => MaybePromise<Response>;
966
-
967
- /**
968
- * The [`init`](https://svelte.dev/docs/kit/hooks#Shared-hooks-init) will be invoked before the server responds to its first request
969
- * @since 2.10.0
970
- */
971
- export type ServerInit = () => MaybePromise<void>;
972
-
973
- /**
974
- * The [`init`](https://svelte.dev/docs/kit/hooks#Shared-hooks-init) will be invoked once the app starts in the browser
975
- * @since 2.10.0
976
- */
977
- export type ClientInit = () => MaybePromise<void>;
978
-
979
- /**
980
- * The [`reroute`](https://svelte.dev/docs/kit/hooks#Universal-hooks-reroute) hook allows you to modify the URL before it is used to determine which route to render.
981
- * @since 2.3.0
982
- */
983
- export type Reroute = (event: { url: URL; fetch: typeof fetch }) => MaybePromise<void | string>;
984
-
985
- /**
986
- * The [`transport`](https://svelte.dev/docs/kit/hooks#Universal-hooks-transport) hook allows you to transport custom types across the server/client boundary.
987
- *
988
- * Each transporter has a pair of `encode` and `decode` functions. On the server, `encode` determines whether a value is an instance of the custom type and, if so, returns a non-falsy encoding of the value which can be an object or an array (or `false` otherwise).
989
- *
990
- * In the browser, `decode` turns the encoding back into an instance of the custom type.
991
- *
992
- * ```ts
993
- * import type { Transport } from '@sveltejs/kit';
994
- *
995
- * declare class MyCustomType {
996
- * data: any
997
- * }
998
- *
999
- * // hooks.js
1000
- * export const transport: Transport = {
1001
- * MyCustomType: {
1002
- * encode: (value) => value instanceof MyCustomType && [value.data],
1003
- * decode: ([data]) => new MyCustomType(data)
1004
- * }
1005
- * };
1006
- * ```
1007
- * @since 2.11.0
1008
- */
1009
- export type Transport = Record<string, Transporter>;
1010
-
1011
- /**
1012
- * A member of the [`transport`](https://svelte.dev/docs/kit/hooks#Universal-hooks-transport) hook.
1013
- */
1014
- export interface Transporter<
1015
- T = any,
1016
- U = Exclude<any, false | 0 | '' | null | undefined | typeof NaN>
1017
- > {
1018
- encode: (value: T) => false | U;
1019
- decode: (data: U) => T;
1020
- }
1021
-
1022
934
  /**
1023
935
  * The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://svelte.dev/docs/kit/types#Generated-types))
1024
936
  * rather than using `Load` directly.
@@ -1047,7 +959,7 @@ export interface LoadEvent<
1047
959
  * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
1048
960
  * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
1049
961
  * - 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.
1050
- * - 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#Server-hooks-handle)
962
+ * - 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)
1051
963
  * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
1052
964
  *
1053
965
  * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies)
@@ -1179,306 +1091,6 @@ export interface NavigationEvent<
1179
1091
  url: URL;
1180
1092
  }
1181
1093
 
1182
- /**
1183
- * Information about the target of a specific navigation.
1184
- */
1185
- export interface NavigationTarget<
1186
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1187
- RouteId extends AppRouteId | null = AppRouteId | null
1188
- > {
1189
- /**
1190
- * Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1191
- * Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
1192
- */
1193
- params: Params | null;
1194
- /**
1195
- * Info about the target route
1196
- */
1197
- route: {
1198
- /**
1199
- * 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.
1200
- */
1201
- id: RouteId | null;
1202
- };
1203
- /**
1204
- * The URL that is navigated to
1205
- */
1206
- url: URL;
1207
- /**
1208
- * The scroll position associated with this navigation.
1209
- *
1210
- * For the `from` target, this is the scroll position at the moment of navigation.
1211
- *
1212
- * For the `to` target, this represents the scroll position that will be or was restored:
1213
- * - In `beforeNavigate` and `onNavigate`, this is only available for `popstate` navigations (back/forward button)
1214
- * and will be `null` for other navigation types, since the final scroll position isn't known
1215
- * ahead of time.
1216
- * - In `afterNavigate`, this is always the scroll position that was applied after the navigation
1217
- * completed.
1218
- */
1219
- scroll: { x: number; y: number } | null;
1220
- }
1221
-
1222
- /**
1223
- * - `enter`: The app has hydrated/started
1224
- * - `form`: The user submitted a `<form method="GET">`
1225
- * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1226
- * - `link`: Navigation was triggered by a link click
1227
- * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1228
- * - `popstate`: Navigation was triggered by back/forward navigation
1229
- */
1230
- export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
1231
-
1232
- export interface NavigationBase {
1233
- /**
1234
- * Where navigation was triggered from
1235
- */
1236
- from: NavigationTarget | null;
1237
- /**
1238
- * Where navigation is going to/has gone to
1239
- */
1240
- to: NavigationTarget | null;
1241
- /**
1242
- * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
1243
- */
1244
- willUnload: boolean;
1245
- /**
1246
- * A promise that resolves once the navigation is complete, and rejects if the navigation
1247
- * fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
1248
- */
1249
- complete: Promise<void>;
1250
- }
1251
-
1252
- export interface NavigationEnter extends NavigationBase {
1253
- /**
1254
- * The type of navigation:
1255
- * - `enter`: The app has hydrated/started
1256
- */
1257
- type: 'enter';
1258
-
1259
- /**
1260
- * In case of a history back/forward navigation, the number of steps to go back/forward
1261
- */
1262
- delta?: undefined;
1263
-
1264
- /**
1265
- * Dispatched `Event` object when navigation occurred by `popstate` or `link`.
1266
- */
1267
- event?: undefined;
1268
- }
1269
-
1270
- export type NavigationExternal = NavigationGoto | NavigationLeave;
1271
-
1272
- export interface NavigationGoto extends NavigationBase {
1273
- /**
1274
- * The type of navigation:
1275
- * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1276
- */
1277
- type: 'goto';
1278
- }
1279
-
1280
- export interface NavigationLeave extends NavigationBase {
1281
- /**
1282
- * The type of navigation:
1283
- * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1284
- */
1285
- type: 'leave';
1286
- }
1287
-
1288
- export interface NavigationFormSubmit extends NavigationBase {
1289
- /**
1290
- * The type of navigation:
1291
- * - `form`: The user submitted a `<form method="GET">`
1292
- */
1293
- type: 'form';
1294
-
1295
- /**
1296
- * The `SubmitEvent` that caused the navigation
1297
- */
1298
- event: SubmitEvent;
1299
- }
1300
-
1301
- export interface NavigationPopState extends NavigationBase {
1302
- /**
1303
- * The type of navigation:
1304
- * - `popstate`: Navigation was triggered by back/forward navigation
1305
- */
1306
- type: 'popstate';
1307
-
1308
- /**
1309
- * In case of a history back/forward navigation, the number of steps to go back/forward
1310
- */
1311
- delta: number;
1312
-
1313
- /**
1314
- * The `PopStateEvent` that caused the navigation
1315
- */
1316
- event: PopStateEvent;
1317
- }
1318
-
1319
- export interface NavigationLink extends NavigationBase {
1320
- /**
1321
- * The type of navigation:
1322
- * - `link`: Navigation was triggered by a link click
1323
- */
1324
- type: 'link';
1325
-
1326
- /**
1327
- * The `PointerEvent` that caused the navigation
1328
- */
1329
- event: PointerEvent;
1330
- }
1331
-
1332
- export type Navigation =
1333
- | NavigationExternal
1334
- | NavigationFormSubmit
1335
- | NavigationPopState
1336
- | NavigationLink;
1337
-
1338
- /**
1339
- * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
1340
- */
1341
- export type BeforeNavigate = Navigation & {
1342
- /**
1343
- * Call this to prevent the navigation from starting.
1344
- */
1345
- cancel: () => void;
1346
- };
1347
-
1348
- /**
1349
- * The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
1350
- */
1351
- export type OnNavigate = Navigation & {
1352
- type: Exclude<NavigationType, 'enter' | 'leave'>;
1353
- /**
1354
- * Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
1355
- */
1356
- willUnload: false;
1357
- };
1358
-
1359
- /**
1360
- * The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
1361
- */
1362
- export type AfterNavigate = (Navigation | NavigationEnter) & {
1363
- type: Exclude<NavigationType, 'leave'>;
1364
- /**
1365
- * Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
1366
- */
1367
- willUnload: false;
1368
- };
1369
-
1370
- /**
1371
- * The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object and the [`$page`](https://svelte.dev/docs/kit/$app-stores) store.
1372
- */
1373
- export interface Page<
1374
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1375
- RouteId extends AppRouteId | null = AppRouteId | null
1376
- > {
1377
- /**
1378
- * The URL of the current page.
1379
- */
1380
- url: URL & { pathname: ResolvedPathname };
1381
- /**
1382
- * The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1383
- */
1384
- params: Params;
1385
- /**
1386
- * Info about the current route.
1387
- */
1388
- route: {
1389
- /**
1390
- * 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.
1391
- */
1392
- id: RouteId;
1393
- };
1394
- /**
1395
- * HTTP status code of the current page.
1396
- */
1397
- status: number;
1398
- /**
1399
- * The error object of the current page, if any. Filled from the `handleError` hooks.
1400
- */
1401
- error: App.Error | null;
1402
- /**
1403
- * The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
1404
- */
1405
- data: App.PageData & Record<string, any>;
1406
- /**
1407
- * The page state, which can be manipulated using the [`pushState`](https://svelte.dev/docs/kit/$app-navigation#pushState) and [`replaceState`](https://svelte.dev/docs/kit/$app-navigation#replaceState) functions from `$app/navigation`.
1408
- */
1409
- state: App.PageState;
1410
- /**
1411
- * Filled only after a form submission. See [form actions](https://svelte.dev/docs/kit/form-actions) for more info.
1412
- */
1413
- form: any;
1414
- }
1415
-
1416
- /**
1417
- * The shape of a param matcher. See [matching](https://svelte.dev/docs/kit/advanced-routing#Matching) for more info.
1418
- */
1419
- export type ParamMatcher = (param: string) => boolean;
1420
-
1421
- /**
1422
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1423
- * when called with a regular `query`. `arg` is the validated argument (the input *after*
1424
- * the query's schema validated and transformed it, if applicable); `query` is a
1425
- * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
1426
- * update the correct client entry.
1427
- */
1428
- export type RequestedEntry<Validated, Output> = {
1429
- arg: Validated;
1430
- query: RemoteQuery<Output>;
1431
- };
1432
-
1433
- /**
1434
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1435
- * when called with a `query.live`. `arg` is the validated argument; `query` is a
1436
- * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
1437
- * the correct client subscription.
1438
- */
1439
- export type LiveRequestedEntry<Validated, Output> = {
1440
- arg: Validated;
1441
- query: RemoteLiveQuery<Output>;
1442
- };
1443
-
1444
- export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
1445
- AsyncIterable<RequestedEntry<Validated, Output>> & {
1446
- /**
1447
- * Call `refresh` on all queries selected by this `requested` invocation.
1448
- * This is identical to:
1449
- * ```ts
1450
- * import { requested } from '$app/server';
1451
- *
1452
- * for await (const { query } of requested(getPost, ...)) {
1453
- * void query.refresh();
1454
- * }
1455
- * ```
1456
- */
1457
- refreshAll: () => Promise<void>;
1458
- };
1459
-
1460
- export type LiveQueryRequestedResult<Validated, Output> = Iterable<
1461
- LiveRequestedEntry<Validated, Output>
1462
- > &
1463
- AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
1464
- /**
1465
- * Call `reconnect` on all live queries selected by this `requested` invocation.
1466
- * This is identical to:
1467
- * ```ts
1468
- * import { requested } from '$app/server';
1469
- *
1470
- * for await (const { query } of requested(liveQuery, ...)) {
1471
- * void query.reconnect();
1472
- * }
1473
- * ```
1474
- */
1475
- reconnectAll: () => Promise<void>;
1476
- };
1477
-
1478
- export type RequestedResult<Validated, Output> =
1479
- | QueryRequestedResult<Validated, Output>
1480
- | LiveQueryRequestedResult<Validated, Output>;
1481
-
1482
1094
  export interface RequestEvent<
1483
1095
  Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1484
1096
  RouteId extends AppRouteId | null = AppRouteId | null
@@ -1486,45 +1098,55 @@ export interface RequestEvent<
1486
1098
  /**
1487
1099
  * Get or set cookies related to the current request
1488
1100
  */
1489
- cookies: Cookies;
1101
+ readonly cookies: Cookies;
1490
1102
  /**
1491
1103
  * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
1492
1104
  *
1493
1105
  * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
1494
1106
  * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
1495
1107
  * - 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.
1496
- * - 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#Server-hooks-handle)
1108
+ * - 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)
1497
1109
  * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
1498
1110
  *
1499
1111
  * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
1500
1112
  */
1501
- fetch: typeof fetch;
1113
+ readonly fetch: typeof fetch;
1502
1114
  /**
1503
1115
  * The client's IP address, set by the adapter.
1504
1116
  */
1505
- getClientAddress: () => string;
1117
+ readonly getClientAddress: () => string;
1506
1118
  /**
1507
- * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#Server-hooks-handle).
1119
+ * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
1508
1120
  */
1509
- locals: App.Locals;
1121
+ readonly locals: App.Locals;
1510
1122
  /**
1511
1123
  * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1124
+ *
1125
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1126
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1127
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1128
+ * 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.
1512
1129
  */
1513
- params: Params;
1130
+ readonly params: Params;
1514
1131
  /**
1515
1132
  * Additional data made available through the adapter.
1516
1133
  */
1517
- platform: Readonly<App.Platform> | undefined;
1134
+ readonly platform: Readonly<App.Platform> | undefined;
1518
1135
  /**
1519
1136
  * The original request object.
1520
1137
  */
1521
- request: Request;
1138
+ readonly request: Request;
1522
1139
  /**
1523
1140
  * Info about the current route.
1524
1141
  */
1525
- route: {
1142
+ readonly route: {
1526
1143
  /**
1527
1144
  * 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.
1145
+ *
1146
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1147
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1148
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1149
+ * 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.
1528
1150
  */
1529
1151
  id: RouteId;
1530
1152
  };
@@ -1550,26 +1172,31 @@ export interface RequestEvent<
1550
1172
  *
1551
1173
  * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/@sveltejs-kit#Cookies) API instead.
1552
1174
  */
1553
- setHeaders: (headers: Record<string, string>) => void;
1175
+ readonly setHeaders: (headers: Record<string, string>) => void;
1554
1176
  /**
1555
1177
  * The requested URL.
1178
+ *
1179
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1180
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1181
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1182
+ * 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.
1556
1183
  */
1557
- url: URL;
1184
+ readonly url: URL;
1558
1185
  /**
1559
1186
  * `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
1560
1187
  * related to the data request in this case. Use this property instead if the distinction is important to you.
1561
1188
  */
1562
- isDataRequest: boolean;
1189
+ readonly isDataRequest: boolean;
1563
1190
  /**
1564
1191
  * `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.
1565
1192
  */
1566
- isSubRequest: boolean;
1193
+ readonly isSubRequest: boolean;
1567
1194
 
1568
1195
  /**
1569
1196
  * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
1570
1197
  * @since 2.31.0
1571
1198
  */
1572
- tracing: {
1199
+ readonly tracing: {
1573
1200
  /** Whether tracing is enabled. */
1574
1201
  enabled: boolean;
1575
1202
  /** The root span for the request. This span is named `sveltekit.handle.root`. */
@@ -1582,7 +1209,7 @@ export interface RequestEvent<
1582
1209
  * `true` if the request comes from the client via a remote function. The `url` property will be stripped of the internal information
1583
1210
  * related to the data request in this case. Use this property instead if the distinction is important to you.
1584
1211
  */
1585
- isRemoteRequest: boolean;
1212
+ readonly isRemoteRequest: boolean;
1586
1213
  }
1587
1214
 
1588
1215
  /**
@@ -1595,29 +1222,6 @@ export type RequestHandler<
1595
1222
  RouteId extends AppRouteId | null = AppRouteId | null
1596
1223
  > = (event: RequestEvent<Params, RouteId>) => MaybePromise<Response>;
1597
1224
 
1598
- export interface ResolveOptions {
1599
- /**
1600
- * Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
1601
- * (they could include an element's opening tag but not its closing tag, for example)
1602
- * but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
1603
- * @param input the html chunk and the info if this is the last chunk
1604
- */
1605
- transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
1606
- /**
1607
- * Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
1608
- * By default, none will be included.
1609
- * @param name header name
1610
- * @param value header value
1611
- */
1612
- filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
1613
- /**
1614
- * Determines what should be added to the `<head>` tag to preload it.
1615
- * By default, `js` and `css` files will be preloaded.
1616
- * @param input the type of the file and its path
1617
- */
1618
- preload?: (input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }) => boolean;
1619
- }
1620
-
1621
1225
  export interface RouteDefinition<Config = any> {
1622
1226
  id: string;
1623
1227
  api: {
@@ -1641,24 +1245,29 @@ export class Server {
1641
1245
 
1642
1246
  export interface ServerInitOptions {
1643
1247
  /** A map of environment variables. */
1644
- env: Record<string, string>;
1248
+ env: Record<string, string | undefined>;
1645
1249
  /** A function that turns an asset filename into a `ReadableStream`. Required for the `read` export from `$app/server` to work. */
1646
1250
  read?: (file: string) => MaybePromise<ReadableStream | null>;
1647
1251
  }
1648
1252
 
1253
+ /**
1254
+ * Information required to instantiate a new `Server` instance.
1255
+ */
1649
1256
  export interface SSRManifest {
1257
+ /** The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes. */
1650
1258
  appDir: string;
1259
+ /** The `base` and `appDir` settings combined without a leading slash. */
1651
1260
  appPath: string;
1652
- /** Static files from `kit.config.files.assets` and the service worker (if any). */
1261
+ /** Static files from `config.files.assets` and the service worker (if any). */
1653
1262
  assets: Set<string>;
1654
1263
  mimeTypes: Record<string, string>;
1655
1264
 
1656
- /** private fields */
1265
+ /** @internal private fields */
1657
1266
  _: {
1658
- client: NonNullable<BuildData['client']>;
1267
+ client: BuildData['client'];
1659
1268
  nodes: SSRNodeLoader[];
1660
1269
  /** hashed filename -> import to that file */
1661
- remotes: Record<string, () => Promise<any>>;
1270
+ remotes: Record<string, () => Promise<{ default: Record<string, any> }>>;
1662
1271
  routes: SSRRoute[];
1663
1272
  prerendered_routes: Set<string>;
1664
1273
  matchers: () => Promise<Record<string, ParamMatcher>>;
@@ -1776,25 +1385,6 @@ export type Actions<
1776
1385
  RouteId extends AppRouteId | null = AppRouteId | null
1777
1386
  > = Record<string, Action<Params, OutputData, RouteId>>;
1778
1387
 
1779
- /**
1780
- * When calling a form action via fetch, the response will be one of these shapes.
1781
- * ```svelte
1782
- * <form method="post" use:enhance={() => {
1783
- * return ({ result }) => {
1784
- * // result is of type ActionResult
1785
- * };
1786
- * }}
1787
- * ```
1788
- */
1789
- export type ActionResult<
1790
- Success extends Record<string, unknown> | undefined = Record<string, any>,
1791
- Failure extends Record<string, unknown> | undefined = Record<string, any>
1792
- > =
1793
- | { type: 'success'; status: number; data?: Success }
1794
- | { type: 'failure'; status: number; data?: Failure }
1795
- | { type: 'redirect'; status: number; location: string }
1796
- | { type: 'error'; status?: number; error: any };
1797
-
1798
1388
  /**
1799
1389
  * The object returned by the [`error`](https://svelte.dev/docs/kit/@sveltejs-kit#error) function.
1800
1390
  */
@@ -1815,502 +1405,13 @@ export interface Redirect {
1815
1405
  location: string;
1816
1406
  }
1817
1407
 
1818
- export type SubmitFunction<
1819
- Success extends Record<string, unknown> | undefined = Record<string, any>,
1820
- Failure extends Record<string, unknown> | undefined = Record<string, any>
1821
- > = (input: {
1822
- action: URL;
1823
- formData: FormData;
1824
- formElement: HTMLFormElement;
1825
- controller: AbortController;
1826
- submitter: HTMLElement | null;
1827
- cancel: () => void;
1828
- }) => MaybePromise<
1829
- | void
1830
- | ((opts: {
1831
- formData: FormData;
1832
- formElement: HTMLFormElement;
1833
- action: URL;
1834
- result: ActionResult<Success, Failure>;
1835
- /**
1836
- * Call this to get the default behavior of a form submission response.
1837
- * @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission.
1838
- * @param invalidateAll Set `invalidateAll: false` if you don't want the action to call `invalidateAll` after submission.
1839
- */
1840
- update: (options?: { reset?: boolean; invalidateAll?: boolean }) => Promise<void>;
1841
- }) => MaybePromise<void>)
1842
- >;
1843
-
1844
1408
  /**
1845
1409
  * The type of `export const snapshot` exported from a page or layout component.
1410
+ * @deprecated Use the [`snapshot`](https://svelte.dev/docs/kit/$app-navigation#snapshot) helper from `$app/navigation` instead.
1846
1411
  */
1847
1412
  export interface Snapshot<T = any> {
1848
1413
  capture: () => T;
1849
1414
  restore: (snapshot: T) => void;
1850
1415
  }
1851
1416
 
1852
- // If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
1853
- type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
1854
-
1855
- // Input type mappings for form fields
1856
- type InputTypeMap = {
1857
- text: string;
1858
- email: string;
1859
- password: string;
1860
- url: string;
1861
- tel: string;
1862
- search: string;
1863
- number: number;
1864
- range: number;
1865
- date: string;
1866
- 'datetime-local': string;
1867
- time: string;
1868
- month: string;
1869
- week: string;
1870
- color: string;
1871
- checkbox: boolean | string[];
1872
- radio: string;
1873
- file: File;
1874
- hidden: string | number | boolean;
1875
- submit: string | number | boolean;
1876
- button: string;
1877
- reset: string;
1878
- image: string;
1879
- select: string;
1880
- 'select multiple': string[];
1881
- 'file multiple': File[];
1882
- };
1883
-
1884
- // Valid input types for a given value type
1885
- export type RemoteFormFieldType<T> = {
1886
- [K in keyof InputTypeMap]: T extends InputTypeMap[K] ? K : never;
1887
- }[keyof InputTypeMap];
1888
-
1889
- // Input element properties based on type
1890
- type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'radio'
1891
- ? {
1892
- name: string;
1893
- type: T;
1894
- value?: string;
1895
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1896
- get checked(): boolean;
1897
- set checked(value: boolean);
1898
- readonly defaultChecked?: boolean;
1899
- }
1900
- : T extends 'file'
1901
- ? {
1902
- name: string;
1903
- type: 'file';
1904
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1905
- get files(): FileList | null;
1906
- set files(v: FileList | null);
1907
- }
1908
- : T extends 'select'
1909
- ? {
1910
- name: string;
1911
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1912
- get value(): string;
1913
- set value(v: string);
1914
- }
1915
- : T extends 'select multiple'
1916
- ? {
1917
- name: string;
1918
- multiple: true;
1919
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1920
- get value(): string[];
1921
- set value(v: string[]);
1922
- }
1923
- : T extends 'text'
1924
- ? {
1925
- name: string;
1926
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1927
- get value(): string | number;
1928
- set value(v: string | number);
1929
- readonly defaultValue?: string | number;
1930
- }
1931
- : {
1932
- name: string;
1933
- type: T;
1934
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1935
- get value(): string | number;
1936
- set value(v: string | number);
1937
- readonly defaultValue?: string | number;
1938
- };
1939
-
1940
- type RemoteFormFieldMethods<T> = {
1941
- /** The values that will be submitted */
1942
- value(): DeepPartial<T>;
1943
- /** Set the values that will be submitted */
1944
- set(input: DeepPartial<T>): DeepPartial<T>;
1945
- /** Validation issues, if any */
1946
- issues(): RemoteFormIssue[] | undefined;
1947
- };
1948
-
1949
- // These two types use "T extends unknown ? .. : .." to distribute over unions.
1950
- // Example: if "type T = A | b" then "keyof T" only contains keys that both A and B have, with "KeysOfUnion<T>" we get the keys of both A and B
1951
- type KeysOfUnion<T> = T extends unknown ? keyof T : never;
1952
- type ValueOfUnionKey<T, K extends PropertyKey> = T extends unknown
1953
- ? K extends keyof T
1954
- ? T[K]
1955
- : never
1956
- : never;
1957
-
1958
- export type RemoteFormFieldValue = string | string[] | number | boolean | File | File[];
1959
-
1960
- type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
1961
- ? Value extends string[]
1962
- ? [type: Type, value: Value[number] | (string & {})]
1963
- : Value extends boolean
1964
- ? [type: Type] | [type: Type, value: boolean]
1965
- : [type: Type] | [type: Type, value: Value | (string & {})]
1966
- : Type extends 'submit' | 'hidden'
1967
- ? Value extends string
1968
- ? [type: Type, value: Value | (string & {})]
1969
- : [type: Type, value: Value]
1970
- : Type extends 'radio'
1971
- ? [type: Type, value: Value | (string & {})]
1972
- : Type extends 'file' | 'file multiple'
1973
- ? [type: Type]
1974
- : [type: Type] | [type: Type, value: Value | (string & {})];
1975
-
1976
- /**
1977
- * Form field accessor type that provides name(), value(), and issues() methods
1978
- */
1979
- export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
1980
- /**
1981
- * Returns an object that can be spread onto an input element with the correct type attribute,
1982
- * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
1983
- * @example
1984
- * ```svelte
1985
- * <input {...myForm.fields.myString.as('text')} />
1986
- * <input {...myForm.fields.myNumber.as('number')} />
1987
- * <input {...myForm.fields.myBoolean.as('checkbox')} />
1988
- * ```
1989
- */
1990
- as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
1991
- };
1992
-
1993
- type RemoteFormFieldContainer<Value> = RemoteFormFieldMethods<Value> & {
1994
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
1995
- allIssues(): RemoteFormIssue[] | undefined;
1996
- };
1997
-
1998
- type UnknownField<Value> = RemoteFormFieldMethods<Value> & {
1999
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
2000
- allIssues(): RemoteFormIssue[] | undefined;
2001
- /**
2002
- * Returns an object that can be spread onto an input element with the correct type attribute,
2003
- * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
2004
- * @example
2005
- * ```svelte
2006
- * <input {...myForm.fields.myString.as('text')} />
2007
- * <input {...myForm.fields.myNumber.as('number')} />
2008
- * <input {...myForm.fields.myBoolean.as('checkbox')} />
2009
- * ```
2010
- */
2011
- as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
2012
- } & {
2013
- [key: string | number]: UnknownField<any>;
2014
- };
2015
-
2016
- type RemoteFormFieldsRoot<Input extends RemoteFormInput | void> =
2017
- IsAny<Input> extends true
2018
- ? RecursiveFormFields
2019
- : Input extends void
2020
- ? {
2021
- /** Validation issues, if any */
2022
- issues(): RemoteFormIssue[] | undefined;
2023
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
2024
- allIssues(): RemoteFormIssue[] | undefined;
2025
- }
2026
- : RemoteFormFields<Input>;
2027
-
2028
- /**
2029
- * Recursive type to build form fields structure with proxy access
2030
- */
2031
- export type RemoteFormFields<T> =
2032
- WillRecurseIndefinitely<T> extends true
2033
- ? RecursiveFormFields
2034
- : NonNullable<T> extends string | number | boolean | File
2035
- ? RemoteFormField<NonNullable<T>>
2036
- : // [NonNullable<T>] is used to prevent distributing over union while still allowing
2037
- // nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
2038
- // to be treated as arrays; only the last condition should distribute over unions
2039
- [NonNullable<T>] extends [string[] | File[]]
2040
- ? RemoteFormField<NonNullable<T>> & {
2041
- [K in number]: RemoteFormField<NonNullable<T>[number]>;
2042
- }
2043
- : [NonNullable<T>] extends [Array<infer U>]
2044
- ? RemoteFormFieldContainer<NonNullable<T>> & {
2045
- [K in number]: RemoteFormFields<U>;
2046
- }
2047
- : RemoteFormFieldContainer<T> & {
2048
- [K in KeysOfUnion<T>]-?: RemoteFormFields<ValueOfUnionKey<T, K>>;
2049
- };
2050
-
2051
- // By breaking this out into its own type, we avoid the TS recursion depth limit
2052
- type RecursiveFormFields = RemoteFormFieldContainer<any> & {
2053
- [key: string | number]: UnknownField<any>;
2054
- };
2055
-
2056
- type MaybeArray<T> = T | T[];
2057
-
2058
- export interface RemoteFormInput {
2059
- [key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput>;
2060
- }
2061
-
2062
- export interface RemoteFormIssue {
2063
- message: string;
2064
- path: Array<string | number>;
2065
- }
2066
-
2067
- // If the schema specifies `id` as a string or number, ensure that `for(...)`
2068
- // only accepts that type. Otherwise, accept `string | number`
2069
- type ExtractId<Input> = Input extends { id: infer Id }
2070
- ? Id extends string | number
2071
- ? Id
2072
- : string | number
2073
- : string | number;
2074
-
2075
- /**
2076
- * A function and proxy object used to imperatively create validation errors in form handlers.
2077
- *
2078
- * Access properties to create field-specific issues: `issue.fieldName('message')`.
2079
- * The type structure mirrors the input data structure for type-safe field access.
2080
- * Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
2081
- */
2082
- export type InvalidField<T> =
2083
- WillRecurseIndefinitely<T> extends true
2084
- ? Record<string | number, any>
2085
- : NonNullable<T> extends string | number | boolean | File
2086
- ? (message: string) => StandardSchemaV1.Issue
2087
- : NonNullable<T> extends Array<infer U>
2088
- ? {
2089
- [K in number]: InvalidField<U>;
2090
- } & ((message: string) => StandardSchemaV1.Issue)
2091
- : NonNullable<T> extends RemoteFormInput
2092
- ? {
2093
- [K in keyof T]-?: InvalidField<T[K]>;
2094
- } & ((message: string) => StandardSchemaV1.Issue)
2095
- : Record<string, never>;
2096
-
2097
- /**
2098
- * A validation error thrown by `invalid`.
2099
- */
2100
- export interface ValidationError {
2101
- /** The validation issues */
2102
- issues: StandardSchemaV1.Issue[];
2103
- }
2104
-
2105
- /**
2106
- * The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
2107
- */
2108
- export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
2109
- /** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
2110
- [attachment: symbol]: (node: HTMLFormElement) => void;
2111
- method: 'POST';
2112
- /** The URL to send the form to. */
2113
- action: string;
2114
- /** The `<form>` element this instance is currently attached to, if any. */
2115
- get element(): HTMLFormElement | null;
2116
- /** Submit the currently attached form programmatically. */
2117
- submit(): Promise<boolean> & {
2118
- updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
2119
- };
2120
- /** Use the `enhance` method to influence what happens when the form is submitted. */
2121
- enhance(
2122
- callback: (
2123
- form: Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
2124
- readonly element: HTMLFormElement;
2125
- }
2126
- ) => MaybePromise<void>
2127
- ): {
2128
- method: 'POST';
2129
- action: string;
2130
- [attachment: symbol]: (node: HTMLFormElement) => void;
2131
- };
2132
- /**
2133
- * Create an instance of the form for the given `id`.
2134
- * The `id` is stringified and used for deduplication to potentially reuse existing instances.
2135
- * Useful when you have multiple forms that use the same remote form action, for example in a loop.
2136
- * ```svelte
2137
- * {#each todos as todo}
2138
- * {@const todoForm = updateTodo.for(todo.id)}
2139
- * <form {...todoForm}>
2140
- * {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
2141
- * ...
2142
- * </form>
2143
- * {/each}
2144
- * ```
2145
- */
2146
- for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
2147
- /** Preflight checks */
2148
- preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
2149
- /** Validate the form contents programmatically */
2150
- validate(options?: {
2151
- /** Set this to `true` to also show validation issues of fields that haven't been touched yet. */
2152
- includeUntouched?: boolean;
2153
- /** Set this to `true` to only run the `preflight` validation. */
2154
- preflightOnly?: boolean;
2155
- }): Promise<void>;
2156
- /** The result of the form submission */
2157
- get result(): Output | undefined;
2158
- /** The number of pending submissions */
2159
- get pending(): number;
2160
- /** Access form fields using object notation */
2161
- fields: RemoteFormFieldsRoot<Input>;
2162
- };
2163
-
2164
- /**
2165
- * The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
2166
- */
2167
- export type RemoteCommand<Input, Output> = {
2168
- (arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
2169
- updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
2170
- };
2171
- /** The number of pending command executions */
2172
- get pending(): number;
2173
- };
2174
-
2175
- export type RemoteQueryUpdate =
2176
- | RemoteQuery<any>
2177
- | RemoteLiveQuery<any>
2178
- | RemoteQueryFunction<any, any>
2179
- | RemoteLiveQueryFunction<any, any>
2180
- | RemoteQueryOverride;
2181
-
2182
- export type RemoteResource<T> = Promise<T> & {
2183
- /** The error in case the query fails. Most often this is a [`HttpError`](https://svelte.dev/docs/kit/@sveltejs-kit#HttpError) but it isn't guaranteed to be. */
2184
- get error(): any;
2185
- /** `true` before the first result is available and during refreshes */
2186
- get loading(): boolean;
2187
- } & (
2188
- | {
2189
- /** The current value of the query. Undefined until `ready` is `true` */
2190
- get current(): undefined;
2191
- ready: false;
2192
- }
2193
- | {
2194
- /** The current value of the query. Undefined until `ready` is `true` */
2195
- get current(): T;
2196
- ready: true;
2197
- }
2198
- );
2199
-
2200
- export type RemoteQuery<T> = RemoteResource<T> & {
2201
- /**
2202
- * On the client, this function will update the value of the query without re-fetching it.
2203
- *
2204
- * On the server, this can be called in the context of a `command` or `form` and the specified data will accompany the action response back to the client.
2205
- * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
2206
- */
2207
- set(value: T): void;
2208
- /**
2209
- * On the client, this function will re-fetch the query from the server.
2210
- *
2211
- * On the server, this can be called in the context of a `command` or `form` and the refreshed data will accompany the action response back to the client.
2212
- * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
2213
- */
2214
- refresh(): Promise<void>;
2215
- /**
2216
- * Temporarily override a query's value during a [single-flight mutation](https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations) to provide optimistic updates.
2217
- *
2218
- * ```svelte
2219
- * <script>
2220
- * import { getTodos, addTodo } from './todos.remote.js';
2221
- * const todos = getTodos();
2222
- * </script>
2223
- *
2224
- * <form {...addTodo.enhance(async (form) => {
2225
- * await form.submit().updates(
2226
- * todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
2227
- * );
2228
- * })}>
2229
- * <input type="text" name="text" />
2230
- * <button type="submit">Add Todo</button>
2231
- * </form>
2232
- * ```
2233
- */
2234
- withOverride(update: (current: T) => T): RemoteQueryOverride;
2235
- };
2236
-
2237
- export type RemoteLiveQuery<T> = RemoteResource<T> &
2238
- AsyncIterable<T> & {
2239
- /** `true` if the live stream is currently connected. */
2240
- readonly connected: boolean;
2241
- /** `true` once the current live stream iterator is done. */
2242
- readonly done: boolean;
2243
- /** Reconnects the live stream immediately. */
2244
- reconnect(): Promise<void>;
2245
- };
2246
-
2247
- export type RemoteQueryOverride = () => void;
2248
-
2249
- /**
2250
- * The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
2251
- */
2252
- export type RemotePrerenderFunction<Input, Output> = (
2253
- arg: undefined extends Input ? Input | void : Input
2254
- ) => RemoteResource<Output>;
2255
-
2256
- /**
2257
- * The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
2258
- *
2259
- * The optional `Validated` generic parameter represents the argument type *after* the
2260
- * query's schema has validated and (optionally) transformed it — this is the type the
2261
- * query's implementation function receives on the server, and the type yielded by
2262
- * [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
2263
- * with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
2264
- * schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
2265
- * `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
2266
- * without arguments it defaults to `Input`.
2267
- */
2268
- export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
2269
- arg: undefined extends Input ? Input | void : Input
2270
- ) => RemoteQuery<Output>;
2271
-
2272
- /**
2273
- * The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
2274
- *
2275
- * The optional `Validated` generic parameter represents the argument type *after* the
2276
- * query's schema has validated and (optionally) transformed it, and matches the type
2277
- * yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
2278
- */
2279
- export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
2280
- arg: undefined extends Input ? Input | void : Input
2281
- ) => RemoteLiveQuery<Output>;
2282
-
2283
- /**
2284
- * [Environment variables](https://svelte.dev/docs/kit/environment-variables) can be configured by exporting
2285
- * a `variables` object from `src/env.ts`, using [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-hooks#defineEnvVars).
2286
- */
2287
- export interface EnvVarConfig<T> {
2288
- /**
2289
- * Whether the environment variable can be accessed by client-side code.
2290
- * - if `true`, it can be imported from `$app/env/public`
2291
- * - if `false`, it can be imported from `$app/env/private`, which is a [server-only module](https://svelte.dev/docs/kit/server-only-modules)
2292
- * @default false
2293
- */
2294
- public?: boolean;
2295
- /**
2296
- * Whether the value is determined at build time or when the app runs.
2297
- * - if `true`, the build time value is inlined into the bundle. This enables optimisations like dead-code elimination
2298
- * - if `false`, the value is read from the environment when the app starts
2299
- * @default false
2300
- */
2301
- static?: boolean;
2302
- /**
2303
- * A [Standard Schema](https://standardschema.dev/) validator that is applied to the value when the app starts.
2304
- * The validator can output any value — not necessarily a string — but public, non-static values must be
2305
- * serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
2306
- *
2307
- * If omitted, the value must be a non-empty string.
2308
- */
2309
- schema?: StandardSchemaV1<string | undefined, T>;
2310
- /**
2311
- * A description of the variable that will be used for inline documentation on hover.
2312
- */
2313
- description?: string;
2314
- }
2315
-
2316
1417
  export * from './index.js';