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

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 (88) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +8 -8
  3. package/src/constants.js +3 -1
  4. package/src/core/adapt/builder.js +3 -6
  5. package/src/core/config/index.js +6 -1
  6. package/src/core/config/options.js +54 -104
  7. package/src/core/env.js +25 -11
  8. package/src/core/postbuild/fallback.js +2 -1
  9. package/src/core/postbuild/prerender.js +75 -28
  10. package/src/core/postbuild/queue.js +2 -1
  11. package/src/core/sync/sync.js +11 -14
  12. package/src/core/sync/utils.js +21 -1
  13. package/src/core/sync/{write_non_ambient.js → write_app_types.js} +23 -21
  14. package/src/core/sync/write_client_manifest.js +4 -12
  15. package/src/core/sync/write_env.js +6 -4
  16. package/src/core/sync/write_server.js +12 -17
  17. package/src/core/sync/write_tsconfig/index.js +245 -0
  18. package/src/core/sync/write_tsconfig/utils.js +162 -0
  19. package/src/core/sync/write_types/index.js +80 -88
  20. package/src/core/utils.js +28 -3
  21. package/src/exports/env/index.js +68 -3
  22. package/src/exports/internal/env.js +6 -3
  23. package/src/exports/internal/server/index.js +3 -1
  24. package/src/exports/params.js +9 -4
  25. package/src/exports/public.d.ts +69 -71
  26. package/src/exports/vite/dev/index.js +112 -56
  27. package/src/exports/vite/index.js +483 -258
  28. package/src/exports/vite/module_ids.js +2 -2
  29. package/src/exports/vite/preview/index.js +3 -2
  30. package/src/exports/vite/utils.js +21 -10
  31. package/src/runner.js +13 -0
  32. package/src/runtime/app/forms.js +4 -0
  33. package/src/runtime/app/manifest/index.js +1 -0
  34. package/src/runtime/app/paths/client.js +30 -30
  35. package/src/runtime/app/paths/internal/client.js +26 -0
  36. package/src/runtime/app/paths/server.js +23 -10
  37. package/src/runtime/app/paths/types.d.ts +11 -19
  38. package/src/runtime/app/server/index.js +1 -1
  39. package/src/runtime/app/server/remote/command.js +12 -7
  40. package/src/runtime/app/server/remote/form.js +29 -26
  41. package/src/runtime/app/server/remote/prerender.js +9 -2
  42. package/src/runtime/app/server/remote/query.js +6 -5
  43. package/src/runtime/app/server/remote/shared.js +48 -30
  44. package/src/runtime/app/service-worker/index.js +24 -0
  45. package/src/runtime/app/state/index.js +1 -1
  46. package/src/runtime/client/client.js +46 -9
  47. package/src/runtime/client/ndjson.js +1 -1
  48. package/src/runtime/client/remote-functions/form.svelte.js +43 -51
  49. package/src/runtime/client/remote-functions/query/index.js +2 -2
  50. package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -3
  51. package/src/runtime/client/remote-functions/query-live/iterator.js +5 -2
  52. package/src/runtime/client/remote-functions/shared.svelte.js +4 -1
  53. package/src/runtime/client/state.svelte.js +54 -21
  54. package/src/runtime/client/stream.js +3 -2
  55. package/src/runtime/form-utils.js +89 -54
  56. package/src/runtime/server/cookie.js +1 -1
  57. package/src/runtime/server/data/index.js +32 -29
  58. package/src/runtime/server/errors.js +135 -0
  59. package/src/runtime/server/fetch.js +1 -1
  60. package/src/runtime/server/index.js +20 -10
  61. package/src/runtime/server/internal.js +25 -0
  62. package/src/runtime/server/page/actions.js +4 -3
  63. package/src/runtime/server/page/data_serializer.js +10 -10
  64. package/src/runtime/server/page/index.js +3 -2
  65. package/src/runtime/server/page/load_data.js +1 -1
  66. package/src/runtime/server/page/render.js +22 -35
  67. package/src/runtime/server/page/respond_with_error.js +6 -5
  68. package/src/runtime/server/{remote.js → remote-functions.js} +67 -36
  69. package/src/runtime/server/respond.js +58 -20
  70. package/src/runtime/server/sourcemaps.js +183 -0
  71. package/src/runtime/server/utils.js +12 -157
  72. package/src/types/ambient-private.d.ts +10 -0
  73. package/src/types/ambient.d.ts +22 -27
  74. package/src/types/global-private.d.ts +12 -5
  75. package/src/types/internal.d.ts +19 -9
  76. package/src/types/private.d.ts +8 -0
  77. package/src/utils/escape.js +9 -25
  78. package/src/utils/features.js +1 -1
  79. package/src/utils/fork.js +7 -2
  80. package/src/utils/page_nodes.js +3 -5
  81. package/src/utils/url.js +12 -0
  82. package/src/version.js +1 -1
  83. package/types/index.d.ts +152 -120
  84. package/types/index.d.ts.map +6 -1
  85. package/src/core/sync/write_ambient.js +0 -18
  86. package/src/core/sync/write_tsconfig.js +0 -258
  87. package/src/runtime/shared-server.js +0 -7
  88. /package/src/core/sync/{write_tsconfig_test → write_tsconfig/test-app}/package.json +0 -0
@@ -58,7 +58,7 @@ export interface Adapter {
58
58
  * Test support for `read` from `$app/server`.
59
59
  * @param details.config The merged adapter-specific route config exported from the route with `export const config`
60
60
  */
61
- read?: (details: { config: any; route: { id: string } }) => boolean;
61
+ read?: (details: { config: Record<string, any>; route: { id: string } }) => boolean;
62
62
 
63
63
  /**
64
64
  * Test support for `instrumentation.server.js`. To pass, the adapter must support running `instrumentation.server.js` prior to the application code.
@@ -288,7 +288,7 @@ export interface Cookies {
288
288
  /**
289
289
  * 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.
290
290
  *
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.
291
+ * 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
292
  *
293
293
  * 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
294
  * @param name the name of the cookie
@@ -300,7 +300,7 @@ export interface Cookies {
300
300
  /**
301
301
  * Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
302
302
  *
303
- * 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.
303
+ * 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.
304
304
  *
305
305
  * 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.
306
306
  * @param name the name of the cookie
@@ -335,7 +335,7 @@ export interface Cookies {
335
335
  /**
336
336
  * Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
337
337
  *
338
- * 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.
338
+ * 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.
339
339
  *
340
340
  * 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.
341
341
  * @param name the name of the cookie
@@ -365,32 +365,10 @@ export interface KitConfig {
365
365
  /**
366
366
  * An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
367
367
  *
368
- * ```js
369
- * /// file: vite.config.js
370
- * import { defineConfig } from 'vite';
371
- * import { sveltekit } from '@sveltejs/kit/vite';
372
- *
373
- * export default defineConfig({
374
- * plugins: [
375
- * sveltekit({
376
- * alias: {
377
- * // this will match a file
378
- * 'my-file': 'path/to/my-file.js',
379
- *
380
- * // this will match a directory and its contents
381
- * // (`my-directory/x` resolves to `path/to/my-directory/x`)
382
- * 'my-directory': 'path/to/my-directory',
383
- *
384
- * // an alias ending /* will only match
385
- * // the contents of a directory, not the directory itself
386
- * 'my-directory/*': 'path/to/my-directory/*'
387
- * }
388
- * })
389
- * ]
390
- * });
391
- * ```
368
+ * This option is deprecated. Use [subpath imports](https://svelte.dev/docs/kit/$lib) instead.
392
369
  *
393
370
  * > [!NOTE] You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
371
+ * @deprecated
394
372
  * @default {}
395
373
  */
396
374
  alias?: Record<string, string>;
@@ -435,7 +413,7 @@ export interface KitConfig {
435
413
  *
436
414
  * > [!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.
437
415
  *
438
- * 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.
416
+ * 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.
439
417
  */
440
418
  csp?: {
441
419
  /**
@@ -833,8 +811,10 @@ export interface KitConfig {
833
811
  * This has several advantages:
834
812
  * - The client does not need to load the routing manifest upfront, which can lead to faster initial page loads
835
813
  * - The list of routes is hidden from public view
836
- * - The server has an opportunity to intercept each navigation (for example through a middleware), enabling (for example) A/B testing opaque to SvelteKit
837
-
814
+ * - 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
815
+ *
816
+ * 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.
817
+ *
838
818
  * 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)).
839
819
  *
840
820
  * > [!NOTE] When using server-side route resolution and prerendering, the resolution is prerendered along with the route itself.
@@ -844,13 +824,7 @@ export interface KitConfig {
844
824
  */
845
825
  resolution?: 'client' | 'server';
846
826
  };
847
- serviceWorker?: {
848
- /**
849
- * Determine which files in your `static` directory will be available in `$service-worker.files`.
850
- * @default (filename) => !/\.DS_Store/.test(filename)
851
- */
852
- files?: (file: string) => boolean;
853
- } & (
827
+ serviceWorker?:
854
828
  | {
855
829
  /**
856
830
  * Whether to automatically register the service worker, if it exists.
@@ -868,19 +842,21 @@ export interface KitConfig {
868
842
  * @default true
869
843
  */
870
844
  register?: false;
871
- }
872
- );
845
+ };
873
846
  /**
874
847
  * Options for enabling [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations.
875
848
  * @default { server: false }
876
849
  */
877
850
  tracing?: {
878
851
  /**
879
- * 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). 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.
852
+ * 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.
880
853
  * @default false
881
854
  */
882
855
  server?: boolean;
883
856
  };
857
+ /**
858
+ * @deprecated Add configuration to `tsconfig.json` directly
859
+ */
884
860
  typescript?: {
885
861
  /**
886
862
  * A function that allows you to edit the generated `tsconfig.json`. You can mutate the config (recommended) or return a new one.
@@ -895,9 +871,9 @@ export interface KitConfig {
895
871
  };
896
872
  /**
897
873
  * 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.
898
- * SvelteKit helps you solve this problem through version management.
874
+ * 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.
899
875
  * 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.
900
- * 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`:
876
+ * 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`:
901
877
  * ```html
902
878
  * /// file: +layout.svelte
903
879
  * <script>
@@ -912,7 +888,7 @@ export interface KitConfig {
912
888
  * </script>
913
889
  * ```
914
890
  *
915
- * 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.
891
+ * 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).
916
892
  */
917
893
  version?: {
918
894
  /**
@@ -939,15 +915,15 @@ export interface KitConfig {
939
915
  */
940
916
  name?: string;
941
917
  /**
942
- * The interval in milliseconds to poll for version changes. If this is `0`, no polling occurs.
943
- * @default 0
918
+ * 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.
919
+ * @default 3600000
944
920
  */
945
921
  pollInterval?: number;
946
922
  };
947
923
  }
948
924
 
949
925
  /**
950
- * 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
926
+ * The [`handle`](https://svelte.dev/docs/kit/hooks#handle) hook runs every time the SvelteKit server receives a [request](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Request) and
951
927
  * determines the [response](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Response).
952
928
  * It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
953
929
  * This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
@@ -958,7 +934,7 @@ export type Handle = (input: {
958
934
  }) => MaybePromise<Response>;
959
935
 
960
936
  /**
961
- * 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.
937
+ * The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs when an unexpected error is thrown while responding to a request.
962
938
  *
963
939
  * If an unexpected error is thrown during loading or rendering, this function will be called with the error and the event.
964
940
  * Make sure that this function _never_ throws an error.
@@ -974,7 +950,7 @@ export type HandleServerError = (input: {
974
950
  }) => MaybePromise<void | AppErrorWithOptionalStatus>;
975
951
 
976
952
  /**
977
- * The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#Server-hooks-handleValidationError) hook runs when the argument to a remote function fails validation.
953
+ * The [`handleValidationError`](https://svelte.dev/docs/kit/hooks#handleValidationError) hook runs when the argument to a remote function fails validation.
978
954
  *
979
955
  * It will be called with the validation issues and the event, and must return an object shape that matches `App.Error`.
980
956
  */
@@ -982,7 +958,7 @@ export type HandleValidationError<Issue extends StandardSchemaV1.Issue = Standar
982
958
  (input: { issues: Issue[]; event: RequestEvent }) => MaybePromise<AppErrorWithOptionalStatus>;
983
959
 
984
960
  /**
985
- * The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#Shared-hooks-handleError) hook runs when an unexpected error is thrown while navigating.
961
+ * The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs when an unexpected error is thrown while navigating.
986
962
  *
987
963
  * If an unexpected error is thrown during loading or the following render, this function will be called with the error and the event.
988
964
  * Make sure that this function _never_ throws an error.
@@ -998,7 +974,7 @@ export type HandleClientError = (input: {
998
974
  }) => MaybePromise<void | AppErrorWithOptionalStatus>;
999
975
 
1000
976
  /**
1001
- * 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`.
977
+ * The [`handleFetch`](https://svelte.dev/docs/kit/hooks#handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
1002
978
  */
1003
979
  export type HandleFetch = (input: {
1004
980
  event: RequestEvent;
@@ -1007,25 +983,25 @@ export type HandleFetch = (input: {
1007
983
  }) => MaybePromise<Response>;
1008
984
 
1009
985
  /**
1010
- * The [`init`](https://svelte.dev/docs/kit/hooks#Shared-hooks-init) will be invoked before the server responds to its first request
986
+ * The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked before the server responds to its first request
1011
987
  * @since 2.10.0
1012
988
  */
1013
989
  export type ServerInit = () => MaybePromise<void>;
1014
990
 
1015
991
  /**
1016
- * The [`init`](https://svelte.dev/docs/kit/hooks#Shared-hooks-init) will be invoked once the app starts in the browser
992
+ * The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked once the app starts in the browser
1017
993
  * @since 2.10.0
1018
994
  */
1019
995
  export type ClientInit = () => MaybePromise<void>;
1020
996
 
1021
997
  /**
1022
- * 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.
998
+ * The [`reroute`](https://svelte.dev/docs/kit/hooks#reroute) hook allows you to modify the URL before it is used to determine which route to render.
1023
999
  * @since 2.3.0
1024
1000
  */
1025
1001
  export type Reroute = (event: { url: URL; fetch: typeof fetch }) => MaybePromise<void | string>;
1026
1002
 
1027
1003
  /**
1028
- * The [`transport`](https://svelte.dev/docs/kit/hooks#Universal-hooks-transport) hook allows you to transport custom types across the server/client boundary.
1004
+ * The [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook allows you to transport custom types across the server/client boundary.
1029
1005
  *
1030
1006
  * 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).
1031
1007
  *
@@ -1051,7 +1027,7 @@ export type Reroute = (event: { url: URL; fetch: typeof fetch }) => MaybePromise
1051
1027
  export type Transport = Record<string, Transporter>;
1052
1028
 
1053
1029
  /**
1054
- * A member of the [`transport`](https://svelte.dev/docs/kit/hooks#Universal-hooks-transport) hook.
1030
+ * A member of the [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook.
1055
1031
  */
1056
1032
  export interface Transporter<
1057
1033
  T = any,
@@ -1089,7 +1065,7 @@ export interface LoadEvent<
1089
1065
  * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
1090
1066
  * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
1091
1067
  * - 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.
1092
- * - 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)
1068
+ * - 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)
1093
1069
  * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
1094
1070
  *
1095
1071
  * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies)
@@ -1596,7 +1572,7 @@ export interface RequestEvent<
1596
1572
  * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
1597
1573
  * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
1598
1574
  * - 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.
1599
- * - 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)
1575
+ * - 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)
1600
1576
  * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
1601
1577
  *
1602
1578
  * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
@@ -1607,15 +1583,16 @@ export interface RequestEvent<
1607
1583
  */
1608
1584
  getClientAddress: () => string;
1609
1585
  /**
1610
- * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#Server-hooks-handle).
1586
+ * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
1611
1587
  */
1612
1588
  locals: App.Locals;
1613
1589
  /**
1614
1590
  * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1615
1591
  *
1616
- * In the context of a remote function request initiated by the client, this relates to the page the remote function
1617
- * was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
1618
- * whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1592
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1593
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1594
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1595
+ * 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.
1619
1596
  */
1620
1597
  params: Params;
1621
1598
  /**
@@ -1633,9 +1610,10 @@ export interface RequestEvent<
1633
1610
  /**
1634
1611
  * 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.
1635
1612
  *
1636
- * In the context of a remote function request initiated by the client, this relates to the page the remote function
1637
- * was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
1638
- * whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1613
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1614
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1615
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1616
+ * 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.
1639
1617
  */
1640
1618
  id: RouteId;
1641
1619
  };
@@ -1665,9 +1643,10 @@ export interface RequestEvent<
1665
1643
  /**
1666
1644
  * The requested URL.
1667
1645
  *
1668
- * In the context of a remote function request initiated by the client, this relates to the page the remote function
1669
- * was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use this to determine
1670
- * whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
1646
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
1647
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
1648
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
1649
+ * 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.
1671
1650
  */
1672
1651
  url: URL;
1673
1652
  /**
@@ -2105,7 +2084,7 @@ type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
2105
2084
  ? [type: Type, value: Value | (string & {})]
2106
2085
  : Type extends 'file' | 'file multiple'
2107
2086
  ? [type: Type]
2108
- : [type: Type] | [type: Type, value: Value | (string & {})];
2087
+ : [type: Type] | [type: Type, value: Value | undefined];
2109
2088
 
2110
2089
  /**
2111
2090
  * Form field accessor type that provides name(), value(), and issues() methods
@@ -2454,16 +2433,35 @@ export interface EnvVarConfig<T> {
2454
2433
  static?: boolean;
2455
2434
  /**
2456
2435
  * A [Standard Schema](https://standardschema.dev/) validator that is applied to the value when the app starts.
2436
+ * Alternatively, a function that returns the (possibly transformed) value, or throws an error explaining
2437
+ * the problem. Returning `undefined` is valid, so a function can describe an optional variable.
2457
2438
  * The validator can output any value — not necessarily a string — but public, non-static values must be
2458
2439
  * serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
2459
2440
  *
2460
- * If omitted, the value must be a non-empty string.
2441
+ * If omitted, the value must be set, but may be an empty string.
2461
2442
  */
2462
- schema?: StandardSchemaV1<string | undefined, T>;
2443
+ schema?: StandardSchemaV1<string | undefined, T> | ((value: string | undefined) => T | undefined);
2463
2444
  /**
2464
2445
  * A description of the variable that will be used for inline documentation on hover.
2465
2446
  */
2466
2447
  description?: string;
2467
2448
  }
2468
2449
 
2450
+ /**
2451
+ * The return type of [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
2452
+ */
2453
+ export type DefinedEnvVars<T extends Record<string, EnvVarConfig<any>>> = {
2454
+ readonly [K in keyof T]: EnvVarEntry<T[K]>;
2455
+ };
2456
+
2457
+ /**
2458
+ * Normalizes an environment variable config's schema (standard schema or function) to standard schema.
2459
+ */
2460
+ type EnvVarEntry<C extends EnvVarConfig<any>> =
2461
+ C['schema'] extends StandardSchemaV1<any, any>
2462
+ ? C
2463
+ : C['schema'] extends (value: any) => infer R
2464
+ ? Omit<C, 'schema'> & { schema: StandardSchemaV1<string | undefined, R> }
2465
+ : C;
2466
+
2469
2467
  export * from './index.js';