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

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 (195) hide show
  1. package/package.json +62 -36
  2. package/src/cli.js +15 -12
  3. package/src/constants.js +6 -1
  4. package/src/core/adapt/builder.js +66 -72
  5. package/src/core/adapt/index.js +17 -6
  6. package/src/core/config/index.js +134 -80
  7. package/src/core/config/options.js +295 -273
  8. package/src/core/config/types.d.ts +1 -1
  9. package/src/core/env.js +146 -16
  10. package/src/core/generate_manifest/index.js +18 -15
  11. package/src/core/postbuild/analyse.js +8 -20
  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 +222 -70
  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 +82 -62
  19. package/src/core/sync/sync.js +40 -31
  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} +107 -58
  23. package/src/core/sync/write_client_manifest.js +14 -29
  24. package/src/core/sync/write_env.js +7 -5
  25. package/src/core/sync/write_server.js +37 -45
  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 +127 -123
  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 +195 -0
  36. package/src/exports/hooks/sequence.js +9 -6
  37. package/src/exports/index.js +52 -29
  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} +2 -3
  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 +50 -1733
  49. package/src/exports/remote/index.js +11 -0
  50. package/src/exports/remote/public.d.ts +519 -0
  51. package/src/exports/url.js +86 -0
  52. package/src/exports/vite/build/build_server.js +54 -65
  53. package/src/exports/vite/build/remote.js +24 -19
  54. package/src/exports/vite/build/utils.js +0 -8
  55. package/src/exports/vite/dev/index.js +218 -146
  56. package/src/exports/vite/index.js +1590 -858
  57. package/src/exports/vite/module_ids.js +2 -2
  58. package/src/exports/vite/preview/index.js +40 -32
  59. package/src/exports/vite/public.d.ts +588 -0
  60. package/src/exports/vite/utils.js +84 -46
  61. package/src/pathname.js +55 -0
  62. package/src/runner.js +15 -0
  63. package/src/runtime/app/env/internal.js +4 -4
  64. package/src/runtime/app/env/types.d.ts +1 -1
  65. package/src/runtime/app/environment/index.js +3 -3
  66. package/src/runtime/app/{forms.js → forms/index.js} +73 -42
  67. package/src/runtime/app/forms/public.d.ts +2 -0
  68. package/src/runtime/app/forms/types.d.ts +56 -0
  69. package/src/runtime/app/internal/transport.js +53 -0
  70. package/src/runtime/app/manifest/index.js +1 -0
  71. package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
  72. package/src/runtime/app/navigation/public.d.ts +237 -0
  73. package/src/runtime/app/paths/client.js +37 -37
  74. package/src/runtime/app/paths/index.js +1 -1
  75. package/src/runtime/app/paths/internal/client.js +34 -2
  76. package/src/runtime/app/paths/internal/server.js +6 -23
  77. package/src/runtime/app/paths/internal.d.ts +3 -0
  78. package/src/runtime/app/paths/public.d.ts +1 -29
  79. package/src/runtime/app/paths/server.js +36 -17
  80. package/src/runtime/app/paths/types.d.ts +11 -19
  81. package/src/runtime/app/server/index.js +2 -2
  82. package/src/runtime/app/server/public.d.ts +201 -0
  83. package/src/runtime/app/server/remote/command.js +13 -11
  84. package/src/runtime/app/server/remote/form.js +61 -39
  85. package/src/runtime/app/server/remote/prerender.js +45 -45
  86. package/src/runtime/app/server/remote/query.js +106 -108
  87. package/src/runtime/app/server/remote/requested.js +27 -19
  88. package/src/runtime/app/server/remote/shared.js +76 -76
  89. package/src/runtime/app/service-worker/index.js +24 -0
  90. package/src/runtime/app/state/client.js +4 -2
  91. package/src/runtime/app/state/index.js +7 -5
  92. package/src/runtime/app/state/public.d.ts +72 -0
  93. package/src/runtime/app/state/server.js +3 -0
  94. package/src/runtime/app/stores.js +15 -78
  95. package/src/runtime/client/bundle.js +1 -1
  96. package/src/runtime/client/client-entry.js +3 -0
  97. package/src/runtime/client/client.js +1336 -648
  98. package/src/runtime/client/constants.js +3 -6
  99. package/src/runtime/client/entry.js +24 -3
  100. package/src/runtime/client/fetcher.js +25 -25
  101. package/src/runtime/client/ndjson.js +1 -1
  102. package/src/runtime/client/parse.js +1 -1
  103. package/src/runtime/client/payload.js +17 -0
  104. package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
  105. package/src/runtime/client/remote-functions/command.svelte.js +37 -61
  106. package/src/runtime/client/remote-functions/form.svelte.js +267 -178
  107. package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
  108. package/src/runtime/client/remote-functions/query/index.js +10 -17
  109. package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
  110. package/src/runtime/client/remote-functions/query/proxy.js +5 -5
  111. package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
  112. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  113. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
  114. package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
  115. package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
  116. package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
  117. package/src/runtime/client/snapshots.js +147 -0
  118. package/src/runtime/client/state.svelte.js +94 -55
  119. package/src/runtime/client/stream.js +3 -2
  120. package/src/runtime/client/types.d.ts +13 -9
  121. package/src/runtime/client/utils.js +22 -110
  122. package/src/runtime/components/root.svelte +56 -0
  123. package/src/runtime/env/dynamic/private.js +7 -0
  124. package/src/runtime/env/dynamic/public.js +7 -0
  125. package/src/runtime/env/static/private.js +6 -0
  126. package/src/runtime/env/static/public.js +6 -0
  127. package/src/runtime/form-utils.js +172 -61
  128. package/src/runtime/pathname.js +20 -32
  129. package/src/runtime/props.svelte.js +72 -0
  130. package/src/runtime/server/constants.js +0 -3
  131. package/src/runtime/server/cookie.js +72 -55
  132. package/src/runtime/server/csrf.js +65 -0
  133. package/src/runtime/server/data/index.js +49 -53
  134. package/src/runtime/server/dev.js +22 -0
  135. package/src/runtime/server/endpoint.js +6 -7
  136. package/src/runtime/server/env_module.js +0 -5
  137. package/src/runtime/server/errors.js +160 -0
  138. package/src/runtime/server/fetch.js +32 -39
  139. package/src/runtime/server/index.js +90 -64
  140. package/src/runtime/server/internal.js +71 -0
  141. package/src/runtime/server/page/actions.js +85 -64
  142. package/src/runtime/server/page/crypto.js +2 -2
  143. package/src/runtime/server/page/csp.js +88 -104
  144. package/src/runtime/server/page/data_serializer.js +24 -25
  145. package/src/runtime/server/page/index.js +36 -53
  146. package/src/runtime/server/page/load_data.js +50 -57
  147. package/src/runtime/server/page/render.js +173 -239
  148. package/src/runtime/server/page/respond_with_error.js +17 -31
  149. package/src/runtime/server/page/serialize_data.js +2 -13
  150. package/src/runtime/server/page/server_routing.js +85 -26
  151. package/src/runtime/server/remote-functions.js +640 -0
  152. package/src/runtime/server/respond.js +190 -131
  153. package/src/runtime/server/sourcemaps.js +183 -0
  154. package/src/runtime/server/state.js +53 -0
  155. package/src/runtime/server/utils.js +13 -155
  156. package/src/runtime/shared.js +20 -40
  157. package/src/runtime/utils.js +3 -0
  158. package/src/types/ambient-private.d.ts +11 -1
  159. package/src/types/ambient.d.ts +87 -36
  160. package/src/types/global-private.d.ts +25 -25
  161. package/src/types/internal.d.ts +163 -157
  162. package/src/types/private.d.ts +41 -1
  163. package/src/utils/error.js +28 -4
  164. package/src/utils/escape.js +9 -25
  165. package/src/utils/features.js +1 -1
  166. package/src/utils/filesystem.js +1 -23
  167. package/src/utils/fork.js +7 -2
  168. package/src/utils/hash.js +21 -0
  169. package/src/utils/http.js +8 -7
  170. package/src/utils/import.js +9 -2
  171. package/src/utils/imports.js +83 -0
  172. package/src/utils/mime.js +9 -0
  173. package/src/utils/page_nodes.js +6 -7
  174. package/src/utils/params.js +67 -0
  175. package/src/utils/regex.js +9 -0
  176. package/src/utils/routing.js +145 -73
  177. package/src/utils/shared-iterator.js +5 -0
  178. package/src/utils/streaming.js +14 -4
  179. package/src/utils/url.js +33 -2
  180. package/src/version.js +1 -1
  181. package/types/index.d.ts +2616 -2433
  182. package/types/index.d.ts.map +120 -106
  183. package/src/core/sync/write_ambient.js +0 -18
  184. package/src/core/sync/write_root.js +0 -148
  185. package/src/core/sync/write_tsconfig.js +0 -250
  186. package/src/exports/internal/server.js +0 -22
  187. package/src/exports/node/polyfills.js +0 -30
  188. package/src/runtime/server/app.js +0 -9
  189. package/src/runtime/server/remote.js +0 -457
  190. package/src/runtime/shared-server.js +0 -7
  191. package/src/runtime/telemetry/otel.js +0 -21
  192. package/src/runtime/telemetry/record_span.js +0 -65
  193. package/src/types/synthetic/$lib.md +0 -5
  194. /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
  195. /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
@@ -1,11 +1,8 @@
1
- /** @import { RequestEvent } from '@sveltejs/kit' */
2
- /** @import { ServerHooks, MaybePromise, RequestState, RemoteInternals, RequestStore, RemoteLiveQueryUserFunctionReturnType } from 'types' */
3
- import { parse } from 'devalue';
1
+ /** @import { RequestEvent } from '$app/server' */
2
+ /** @import { MaybePromise, RequestState, RemoteInternals, RequestStore, RemoteLiveQueryUserFunctionReturnType } from 'types' */
4
3
  import { error } from '@sveltejs/kit';
5
- import { hydratable } from 'svelte';
6
- import { with_request_store, get_request_store } from '@sveltejs/kit/internal/server';
7
- import { create_remote_key, stringify } from '../../../shared.js';
8
- import { noop } from '../../../../utils/functions.js';
4
+ import { ValidationError } from '@sveltejs/kit/internal';
5
+ import { with_request_store } from '@sveltejs/kit/internal/server';
9
6
 
10
7
  /**
11
8
  * @param {any} validate_or_fn
@@ -30,21 +27,12 @@ export function create_validator(validate_or_fn, maybe_fn) {
30
27
  // use https://standardschema.dev validator if provided
31
28
  if ('~standard' in validate_or_fn) {
32
29
  return async (arg) => {
33
- // Get event before async validation to ensure it's available in server environments without AsyncLocalStorage, too
34
- const { event, state } = get_request_store();
35
-
36
30
  // access property and call method in one go to preserve potential this context
37
31
  const result = await validate_or_fn['~standard'].validate(arg);
38
32
 
39
33
  // if the `issues` field exists, the validation failed
40
34
  if (result.issues) {
41
- error(
42
- 400,
43
- await state.handleValidationError({
44
- issues: result.issues,
45
- event
46
- })
47
- );
35
+ throw new ValidationError(result.issues);
48
36
  }
49
37
 
50
38
  return result.value;
@@ -76,38 +64,13 @@ export async function get_response(internals, payload, state, get_result) {
76
64
  await 0;
77
65
 
78
66
  const cache = get_cache(internals, state);
79
- const entry = (cache[payload] ??= {
80
- serialize: false,
81
- data: get_result()
82
- });
83
-
84
- entry.serialize ||= !!state.is_in_universal_load;
85
-
86
- if (state.is_in_render && internals.id) {
87
- const remote_key = create_remote_key(internals.id, payload);
88
-
89
- void Promise.resolve(entry.data)
90
- .then((value) => {
91
- void hydratable(remote_key, () => stringify(value, state.transport));
92
- })
93
- .catch(noop);
94
- }
95
67
 
96
- return entry.data;
97
- }
98
-
99
- /**
100
- * @param {any} data
101
- * @param {ServerHooks['transport']} transport
102
- */
103
- export function parse_remote_response(data, transport) {
104
- /** @type {Record<string, any>} */
105
- const revivers = {};
106
- for (const key in transport) {
107
- revivers[key] = transport[key].decode;
68
+ if (!state.is_in_remote_query) {
69
+ // if this is a top-level (not nested) `await myQuery()`, include it in the serialized response
70
+ get_implicit_lookup(internals, state)[payload] = get_result;
108
71
  }
109
72
 
110
- return parse(data, revivers);
73
+ return (cache[payload] ??= get_result());
111
74
  }
112
75
 
113
76
  /**
@@ -117,38 +80,55 @@ export function parse_remote_response(data, transport) {
117
80
  * @returns {RequestStore}
118
81
  */
119
82
  function derive_remote_function_event(event, state, allow_cookies) {
120
- return {
121
- event: {
122
- ...event,
123
- setHeaders: () => {
124
- throw new Error('setHeaders is not allowed in remote functions');
83
+ /** @type {RequestEvent} */
84
+ const derived = {
85
+ ...event,
86
+ setHeaders: () => {
87
+ throw new Error('setHeaders is not allowed in remote functions');
88
+ },
89
+ cookies: {
90
+ ...event.cookies,
91
+ set: (name, value, opts) => {
92
+ if (!allow_cookies) {
93
+ throw new Error('Cannot set cookies in `query` or `prerender` functions');
94
+ }
95
+
96
+ if (opts.path && !opts.path.startsWith('/')) {
97
+ throw new Error('Cookies set in remote functions must have an absolute path');
98
+ }
99
+
100
+ return event.cookies.set(name, value, opts);
125
101
  },
126
- cookies: {
127
- ...event.cookies,
128
- set: (name, value, opts) => {
129
- if (!allow_cookies) {
130
- throw new Error('Cannot set cookies in `query` or `prerender` functions');
131
- }
132
-
133
- if (opts.path && !opts.path.startsWith('/')) {
134
- throw new Error('Cookies set in remote functions must have an absolute path');
135
- }
136
-
137
- return event.cookies.set(name, value, opts);
138
- },
139
- delete: (name, opts) => {
140
- if (!allow_cookies) {
141
- throw new Error('Cannot delete cookies in `query` or `prerender` functions');
142
- }
143
-
144
- if (opts.path && !opts.path.startsWith('/')) {
145
- throw new Error('Cookies deleted in remote functions must have an absolute path');
146
- }
147
-
148
- return event.cookies.delete(name, opts);
102
+ delete: (name, opts) => {
103
+ if (!allow_cookies) {
104
+ throw new Error('Cannot delete cookies in `query` or `prerender` functions');
149
105
  }
106
+
107
+ if (opts.path && !opts.path.startsWith('/')) {
108
+ throw new Error('Cookies deleted in remote functions must have an absolute path');
109
+ }
110
+
111
+ return event.cookies.delete(name, opts);
150
112
  }
151
- },
113
+ }
114
+ };
115
+
116
+ if (state.is_in_remote_query) {
117
+ for (const property of ['url', 'params', 'route']) {
118
+ // non-enumerable so spreading for a nested derivation doesn't invoke the getter
119
+ Object.defineProperty(derived, property, {
120
+ enumerable: false,
121
+ get() {
122
+ throw new Error(
123
+ `Cannot access event.${property} in a query. Pass the value as an argument to the query instead`
124
+ );
125
+ }
126
+ });
127
+ }
128
+ }
129
+
130
+ return {
131
+ event: derived,
152
132
  state: {
153
133
  ...state,
154
134
  is_in_remote_function: true
@@ -239,10 +219,15 @@ function to_iterator(source, name) {
239
219
  }
240
220
 
241
221
  /**
222
+ * Note that `state` is deliberately not optional: resources that capture the request
223
+ * state at creation must pass it explicitly, because reading it from the request store
224
+ * at call time is only equivalent on runtimes with `AsyncLocalStorage` support.
225
+ * Callers without a captured state (such as the module-level `form` instance getters)
226
+ * should pass `get_request_store().state` themselves.
242
227
  * @param {RemoteInternals} internals
243
228
  * @param {RequestState} state
244
229
  */
245
- export function get_cache(internals, state = get_request_store().state) {
230
+ export function get_cache(internals, state) {
246
231
  let cache = state.remote.data?.get(internals);
247
232
 
248
233
  if (cache === undefined) {
@@ -252,3 +237,18 @@ export function get_cache(internals, state = get_request_store().state) {
252
237
 
253
238
  return cache;
254
239
  }
240
+
241
+ /**
242
+ * @param {RemoteInternals} internals
243
+ * @param {RequestState} state
244
+ */
245
+ export function get_implicit_lookup(internals, state) {
246
+ let cache = state.remote.implicit?.get(internals);
247
+
248
+ if (cache === undefined) {
249
+ cache = {};
250
+ (state.remote.implicit ??= new Map()).set(internals, cache);
251
+ }
252
+
253
+ return cache;
254
+ }
@@ -0,0 +1,24 @@
1
+ /// <reference no-default-lib="true"/>
2
+ /// <reference lib="esnext" />
3
+ /// <reference lib="webworker" />
4
+
5
+ import { DEV } from 'esm-env';
6
+
7
+ /**
8
+ * The execution context of a service worker. This export exists to make it easier to
9
+ * use service workers with the correct types, provided the importing module is governed
10
+ * by a `tsconfig.json` that extends [`$app/tsconfig/service-worker`](https://svelte.dev/docs/kit/$app-tsconfig-service-worker).
11
+ *
12
+ */
13
+ export const self = /** @type {ServiceWorkerGlobalScope} */ (
14
+ /** @type {unknown} */ (globalThis.self)
15
+ );
16
+
17
+ if (DEV) {
18
+ if (
19
+ typeof ServiceWorkerGlobalScope === 'undefined' ||
20
+ !(self instanceof ServiceWorkerGlobalScope)
21
+ ) {
22
+ throw new Error('The `$app/service-worker` module can only be imported into a service worker');
23
+ }
24
+ }
@@ -3,7 +3,6 @@ import {
3
3
  navigating as _navigating,
4
4
  updated as _updated
5
5
  } from '../../client/state.svelte.js';
6
- import { stores } from '../../client/client.js';
7
6
 
8
7
  export const page = {
9
8
  get data() {
@@ -21,6 +20,9 @@ export const page = {
21
20
  get route() {
22
21
  return _page.route;
23
22
  },
23
+ get shallow() {
24
+ return _page.shallow;
25
+ },
24
26
  get state() {
25
27
  return _page.state;
26
28
  },
@@ -57,5 +59,5 @@ export const updated = {
57
59
  get current() {
58
60
  return _updated.current;
59
61
  },
60
- check: stores.updated.check
62
+ check: _updated.check
61
63
  };
@@ -1,3 +1,5 @@
1
+ /** @import { Navigation } from '$app/navigation' */
2
+ /** @import { Page } from '$app/state' */
1
3
  import {
2
4
  page as client_page,
3
5
  navigating as client_navigating,
@@ -14,8 +16,8 @@ import { BROWSER } from 'esm-env';
14
16
  * A read-only reactive object with information about the current page, serving several use cases:
15
17
  * - retrieving the combined `data` of all pages/layouts anywhere in your component tree (also see [loading data](https://svelte.dev/docs/kit/load))
16
18
  * - retrieving the current value of the `form` prop anywhere in your component tree (also see [form actions](https://svelte.dev/docs/kit/form-actions))
17
- * - retrieving the page state that was set through `goto`, `pushState` or `replaceState` (also see [goto](https://svelte.dev/docs/kit/$app-navigation#goto) and [shallow routing](https://svelte.dev/docs/kit/shallow-routing))
18
- * - retrieving metadata such as the URL you're on, the current route and its parameters, and whether or not there was an error
19
+ * - retrieving the page state that was set through `goto` (also see [goto](https://svelte.dev/docs/kit/$app-navigation#goto) and [shallow routing](https://svelte.dev/docs/kit/shallow-routing))
20
+ * - retrieving metadata such as the URL you're on, the current route and its parameters, the target of a shallow navigation, and whether or not there was an error
19
21
  *
20
22
  * ```svelte
21
23
  * <!--- file: +layout.svelte --->
@@ -45,20 +47,20 @@ import { BROWSER } from 'esm-env';
45
47
  *
46
48
  * On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time.
47
49
  *
48
- * @type {import('@sveltejs/kit').Page}
50
+ * @type {Page}
49
51
  */
50
52
  export const page = BROWSER ? client_page : server_page;
51
53
 
52
54
  /**
53
55
  * A read-only object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
54
56
  * Values are `null` when no navigation is occurring, or during server rendering.
55
- * @type {import('@sveltejs/kit').Navigation | { from: null, to: null, type: null, willUnload: null, delta: null, complete: null }}
57
+ * @type {Navigation | { from: null, to: null, type: null, willUnload: null, delta: null, complete: null }}
56
58
  */
57
59
  // @ts-expect-error
58
60
  export const navigating = BROWSER ? client_navigating : server_navigating;
59
61
 
60
62
  /**
61
- * A read-only reactive value that's initially `false`. If [`version.pollInterval`](https://svelte.dev/docs/kit/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update `current` to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
63
+ * A read-only reactive value that's initially `false`. SvelteKit checks for new versions on data, remote, and form action responses (via the `x-sveltekit-version` header), when the tab regains focus or becomes visible, and on a poll interval (see [`version.pollInterval`](https://svelte.dev/docs/kit/configuration#version)). `updated.current` is set to `true` when a new version is detected. `updated.check()` will force an immediate check, regardless of polling.
62
64
  * @type {{ get current(): boolean; check(): Promise<boolean>; }}
63
65
  */
64
66
  export const updated = BROWSER ? client_updated : server_updated;
@@ -0,0 +1,72 @@
1
+ import type {
2
+ LayoutParams as AppLayoutParams,
3
+ ResolvedPathname,
4
+ RouteId as AppRouteId
5
+ } from '$app/types';
6
+
7
+ export * from './index.js';
8
+
9
+ export type ReadonlyURLSearchParams = Omit<URLSearchParams, 'set' | 'append' | 'delete' | 'sort'>;
10
+
11
+ export type ReadonlyURL = Readonly<
12
+ Omit<URL, 'searchParams'> & {
13
+ searchParams: ReadonlyURLSearchParams;
14
+ }
15
+ >;
16
+
17
+ /**
18
+ * The shape of the [`page`](https://svelte.dev/docs/kit/$app-state#page) reactive object.
19
+ */
20
+ export interface Page<
21
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
22
+ RouteId extends AppRouteId | null = AppRouteId | null
23
+ > {
24
+ /**
25
+ * The URL of the current page.
26
+ */
27
+ url: ReadonlyURL & { readonly pathname: ResolvedPathname | (string & {}) };
28
+ /**
29
+ * The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
30
+ */
31
+ params: Params;
32
+ /**
33
+ * Info about the current route.
34
+ */
35
+ route: {
36
+ /**
37
+ * 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.
38
+ */
39
+ id: RouteId;
40
+ };
41
+ /**
42
+ * HTTP status code of the current page.
43
+ */
44
+ status: number;
45
+ /**
46
+ * The error object of the current page, if any. Filled from the `handleError` hooks.
47
+ */
48
+ error: App.Error | null;
49
+ /**
50
+ * The merged result of all data from all `load` functions on the current page. You can type a common denominator through `App.PageData`.
51
+ */
52
+ data: App.PageData & Record<string, any>;
53
+ /**
54
+ * The page state, which can be manipulated using [`goto`](https://svelte.dev/docs/kit/$app-navigation#goto) from `$app/navigation`.
55
+ */
56
+ state: App.PageState;
57
+ /**
58
+ * Information about the target of the current shallow navigation, or `null` if no shallow navigation has occurred.
59
+ */
60
+ shallow: {
61
+ /** Parameters of the target route, or `null` if the URL does not resolve to a route. */
62
+ params: AppLayoutParams<'/'> | null;
63
+ /** Info about the target route, or `null` if the URL does not resolve to a route. */
64
+ route: { id: AppRouteId } | null;
65
+ /** The normalized URL passed to `goto(..., { shallow: true })`. */
66
+ url: ReadonlyURL;
67
+ } | null;
68
+ /**
69
+ * Filled only after a form submission. See [form actions](https://svelte.dev/docs/kit/form-actions) for more info.
70
+ */
71
+ form: any;
72
+ }
@@ -33,6 +33,9 @@ export const page = {
33
33
  get route() {
34
34
  return (DEV ? context_dev('page.route') : context()).page.route;
35
35
  },
36
+ get shallow() {
37
+ return (DEV ? context_dev('page.shallow') : context()).page.shallow;
38
+ },
36
39
  get state() {
37
40
  return (DEV ? context_dev('page.state') : context()).page.state;
38
41
  },
@@ -1,101 +1,38 @@
1
- import { getContext } from 'svelte';
2
- import { BROWSER, DEV } from 'esm-env';
3
- import { stores as browser_stores } from '../client/client.js';
1
+ // TODO: remove this file when enough people have migrated to Kit 3
2
+
3
+ /** @returns {never} */
4
+ function removed() {
5
+ throw new Error(
6
+ '`$app/stores` has been removed in favour of `$app/state`. See https://svelte.dev/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated'
7
+ );
8
+ }
4
9
 
5
10
  /**
6
- * A function that returns all of the contextual stores. On the server, this must be called during component initialization.
7
- * Only use this if you need to defer store subscription until after the component has mounted, for some reason.
8
- *
9
11
  * @deprecated Use `$app/state` instead (requires Svelte 5, [see docs for more info](https://svelte.dev/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated))
10
12
  */
11
- export const getStores = () => {
12
- const stores = BROWSER ? browser_stores : getContext('__svelte__');
13
-
14
- return {
15
- /** @type {typeof page} */
16
- page: {
17
- subscribe: stores.page.subscribe
18
- },
19
- /** @type {typeof navigating} */
20
- navigating: {
21
- subscribe: stores.navigating.subscribe
22
- },
23
- /** @type {typeof updated} */
24
- updated: stores.updated
25
- };
26
- };
13
+ export const getStores = removed;
27
14
 
28
15
  /**
29
- * A readable store whose value contains page data.
30
- *
31
- * On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
32
- *
33
16
  * @deprecated Use `page` from `$app/state` instead (requires Svelte 5, [see docs for more info](https://svelte.dev/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated))
34
- * @type {import('svelte/store').Readable<import('@sveltejs/kit').Page>}
17
+ * @type {import('svelte/store').Readable<import('$app/state').Page>}
35
18
  */
36
19
  export const page = {
37
- subscribe(fn) {
38
- const store = DEV ? get_store('page') : getStores().page;
39
- return store.subscribe(fn);
40
- }
20
+ subscribe: removed
41
21
  };
42
22
 
43
23
  /**
44
- * A readable store.
45
- * When navigating starts, its value is a `Navigation` object with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
46
- * When navigating finishes, its value reverts to `null`.
47
- *
48
- * On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
49
- *
50
24
  * @deprecated Use `navigating` from `$app/state` instead (requires Svelte 5, [see docs for more info](https://svelte.dev/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated))
51
- * @type {import('svelte/store').Readable<import('@sveltejs/kit').Navigation | null>}
25
+ * @type {import('svelte/store').Readable<import('$app/navigation').Navigation | null>}
52
26
  */
53
27
  export const navigating = {
54
- subscribe(fn) {
55
- const store = DEV ? get_store('navigating') : getStores().navigating;
56
- return store.subscribe(fn);
57
- }
28
+ subscribe: removed
58
29
  };
59
30
 
60
31
  /**
61
- * A readable store whose initial value is `false`. If [`version.pollInterval`](https://svelte.dev/docs/kit/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update the store value to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
62
- *
63
- * On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
64
- *
65
32
  * @deprecated Use `updated` from `$app/state` instead (requires Svelte 5, [see docs for more info](https://svelte.dev/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated))
66
33
  * @type {import('svelte/store').Readable<boolean> & { check(): Promise<boolean> }}
67
34
  */
68
35
  export const updated = {
69
- subscribe(fn) {
70
- const store = DEV ? get_store('updated') : getStores().updated;
71
-
72
- if (BROWSER) {
73
- updated.check = store.check;
74
- }
75
-
76
- return store.subscribe(fn);
77
- },
78
- check: () => {
79
- throw new Error(
80
- BROWSER
81
- ? 'Cannot check updated store before subscribing'
82
- : 'Can only check updated store in browser'
83
- );
84
- }
36
+ subscribe: removed,
37
+ check: removed
85
38
  };
86
-
87
- /**
88
- * @template {keyof ReturnType<typeof getStores>} Name
89
- * @param {Name} name
90
- * @returns {ReturnType<typeof getStores>[Name]}
91
- */
92
- function get_store(name) {
93
- try {
94
- return getStores()[name];
95
- } catch {
96
- throw new Error(
97
- `Cannot subscribe to '${name}' store on the server outside of a Svelte component, as it is bound to the current request via component context. This prevents state from leaking between users.` +
98
- 'For more information, see https://svelte.dev/docs/kit/state-management#avoid-shared-state-on-the-server'
99
- );
100
- }
101
- }
@@ -1,6 +1,6 @@
1
1
  /* if `bundleStrategy` is 'single' or 'inline', this file is used as the entry point */
2
2
 
3
- import * as kit from './entry.js';
3
+ import * as kit from './client-entry.js';
4
4
 
5
5
  // @ts-expect-error
6
6
  import * as app from '__sveltekit/manifest';
@@ -0,0 +1,3 @@
1
+ // we expose this as a separate entry point (rather than treating client.js as the entry point)
2
+ // so that everything other than `start`/`load_css` can be treeshaken
3
+ export { start, load_css } from './client.js';