@sveltejs/kit 3.0.0-next.22 → 3.0.0-next.24
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.
- package/package.json +40 -9
- package/src/cli.js +3 -3
- package/src/constants.js +13 -1
- package/src/core/adapt/builder.js +2 -3
- package/src/core/env.js +139 -181
- package/src/core/postbuild/analyse.js +9 -4
- package/src/core/postbuild/prerender.js +22 -23
- package/src/core/sync/create_manifest_data/index.js +29 -33
- package/src/core/sync/sync.js +23 -40
- package/src/core/sync/write_app_manifest.js +83 -0
- package/src/core/sync/write_client_manifest.js +6 -4
- package/src/core/sync/write_server.js +10 -6
- package/src/core/sync/write_types/index.js +2 -2
- package/src/core/utils.js +0 -28
- package/src/exports/hooks/public.d.ts +9 -1
- package/src/exports/index.js +10 -0
- package/src/exports/node/index.js +77 -5
- package/src/exports/public.d.ts +9 -0
- package/src/exports/vite/build/build_server.js +3 -3
- package/src/exports/vite/build/utils.js +48 -4
- package/src/exports/vite/dev/index.js +11 -22
- package/src/exports/vite/index.js +62 -345
- package/src/exports/vite/module_ids.js +1 -11
- package/src/exports/vite/plugins/env-vars.js +117 -0
- package/src/exports/vite/preview/index.js +6 -4
- package/src/exports/vite/utils.js +2 -4
- package/src/runtime/app/env/{types.d.ts → client.js} +9 -4
- package/src/runtime/app/env/index.js +1 -2
- package/src/runtime/app/env/private/index.js +1 -0
- package/src/runtime/app/env/public/client.js +1 -1
- package/src/runtime/app/env/public/server.js +1 -1
- package/src/runtime/app/env/{internal.js → server.js} +4 -4
- package/src/runtime/app/forms/client.js +263 -0
- package/src/runtime/app/forms/index.js +1 -263
- package/src/runtime/app/forms/public.d.ts +1 -1
- package/src/runtime/app/forms/server.js +6 -0
- package/src/runtime/app/forms/shared.js +34 -0
- package/src/runtime/app/manifest/index.js +1 -1
- package/src/runtime/app/navigation/client.js +15 -0
- package/src/runtime/app/navigation/index.js +1 -15
- package/src/runtime/app/navigation/public.d.ts +1 -1
- package/src/runtime/app/navigation/server.js +15 -0
- package/src/runtime/app/paths/server.js +1 -1
- package/src/runtime/app/server/public.d.ts +512 -0
- package/src/runtime/app/server/remote/command.js +1 -1
- package/src/runtime/app/server/remote/form.js +16 -6
- package/src/runtime/app/server/remote/prerender.js +2 -3
- package/src/runtime/app/server/remote/query.js +2 -2
- package/src/runtime/app/server/remote/requested.js +3 -3
- package/src/runtime/app/state/client.svelte.js +207 -0
- package/src/runtime/app/state/index.js +1 -66
- package/src/runtime/app/state/public.d.ts +1 -1
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client.js +206 -274
- package/src/runtime/client/fetcher.js +18 -8
- package/src/runtime/client/remote-functions/command.svelte.js +1 -1
- package/src/runtime/client/remote-functions/form.svelte.js +10 -7
- package/src/runtime/client/remote-functions/prerender.svelte.js +2 -2
- package/src/runtime/client/remote-functions/query/index.js +1 -1
- package/src/runtime/client/remote-functions/query/instance.svelte.js +2 -1
- package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query-live/index.js +1 -1
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +4 -3
- package/src/runtime/client/remote-functions/query-live/iterator.js +1 -1
- package/src/runtime/client/remote-functions/shared.svelte.js +3 -3
- package/src/runtime/client/snapshots.js +1 -3
- package/src/runtime/client/stream.js +27 -20
- package/src/runtime/client/utils.js +7 -3
- package/src/runtime/components/root.svelte +5 -5
- package/src/runtime/env/dynamic/private.js +1 -1
- package/src/runtime/env/static/private.js +1 -1
- package/src/runtime/error-chain.js +54 -0
- package/src/runtime/form-utils.js +53 -77
- package/src/runtime/invalid-import.js +1 -0
- package/src/runtime/props.svelte.js +1 -1
- package/src/runtime/server/data/index.js +1 -1
- package/src/runtime/server/endpoint.js +8 -3
- package/src/runtime/server/env_module.js +1 -1
- package/src/runtime/server/errors.js +2 -2
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/actions.js +77 -122
- package/src/runtime/server/page/index.js +37 -69
- package/src/runtime/server/page/render.js +18 -23
- package/src/runtime/server/remote-functions.js +15 -43
- package/src/runtime/server/respond.js +23 -3
- package/src/telemetry.js +1 -33
- package/src/types/ambient-private.d.ts +9 -17
- package/src/types/internal.d.ts +21 -5
- package/src/types/private.d.ts +1 -1
- package/src/utils/exports.js +1 -0
- package/src/utils/filesystem.js +9 -21
- package/src/utils/functions.js +10 -0
- package/src/utils/promise.js +25 -0
- package/src/utils/routing.js +0 -11
- package/src/utils/url.js +0 -11
- package/src/version.js +1 -1
- package/types/index.d.ts +1134 -1136
- package/types/index.d.ts.map +50 -50
- package/src/exports/remote/index.js +0 -11
- package/src/exports/remote/public.d.ts +0 -519
- package/src/runtime/app/env/private.js +0 -1
- package/src/runtime/app/env/standard-schema.d.ts +0 -0
- package/src/runtime/app/state/client.js +0 -63
- package/src/runtime/client/state.svelte.js +0 -98
- package/src/runtime/server/ambient.d.ts +0 -4
- package/src/utils/path.js +0 -23
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/** @import { Navigation } from '$app/navigation' */
|
|
2
|
+
/** @import { Page } from '$app/state' */
|
|
3
|
+
import { DEV } from 'esm-env';
|
|
4
|
+
import { assets } from '#app/paths';
|
|
5
|
+
import { version } from '$app/env';
|
|
6
|
+
|
|
7
|
+
/** @type {Page} */
|
|
8
|
+
export const internal_page = new (class Page {
|
|
9
|
+
data = $state.raw({});
|
|
10
|
+
form = $state.raw(null);
|
|
11
|
+
error = $state.raw(null);
|
|
12
|
+
params = $state.raw({});
|
|
13
|
+
route = $state.raw({ id: null });
|
|
14
|
+
shallow = $state.raw(null);
|
|
15
|
+
state = $state.raw({});
|
|
16
|
+
status = $state.raw(-1);
|
|
17
|
+
url = $state.raw(new URL('a:'));
|
|
18
|
+
})();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {Partial<Page>} new_page
|
|
22
|
+
*/
|
|
23
|
+
export function update_page(new_page) {
|
|
24
|
+
Object.assign(internal_page, new_page);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A read-only reactive object with information about the current page, serving several use cases:
|
|
29
|
+
* - retrieving the combined `data` of all pages/layouts anywhere in your component tree (also see [loading data](https://svelte.dev/docs/kit/load))
|
|
30
|
+
* - retrieving the current value of the `form` prop anywhere in your component tree (also see [form actions](https://svelte.dev/docs/kit/form-actions))
|
|
31
|
+
* - 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))
|
|
32
|
+
* - 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
|
|
33
|
+
*
|
|
34
|
+
* ```svelte
|
|
35
|
+
* <!--- file: +layout.svelte --->
|
|
36
|
+
* <script>
|
|
37
|
+
* import { page } from '$app/state';
|
|
38
|
+
* </script>
|
|
39
|
+
*
|
|
40
|
+
* <p>Currently at {page.url.pathname}</p>
|
|
41
|
+
*
|
|
42
|
+
* {#if page.error}
|
|
43
|
+
* <span class="red">Problem detected</span>
|
|
44
|
+
* {:else}
|
|
45
|
+
* <span class="small">All systems operational</span>
|
|
46
|
+
* {/if}
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Changes to `page` are available exclusively with runes. (The legacy reactivity syntax will not reflect any changes)
|
|
50
|
+
*
|
|
51
|
+
* ```svelte
|
|
52
|
+
* <!--- file: +page.svelte --->
|
|
53
|
+
* <script>
|
|
54
|
+
* import { page } from '$app/state';
|
|
55
|
+
* const id = $derived(page.params.id); // This will correctly update id for usage on this page
|
|
56
|
+
* $: badId = page.params.id; // Do not use; will never update after initial load
|
|
57
|
+
* </script>
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* 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.
|
|
61
|
+
*
|
|
62
|
+
* @type {Page}
|
|
63
|
+
*/
|
|
64
|
+
export const page = {
|
|
65
|
+
get data() {
|
|
66
|
+
return internal_page.data;
|
|
67
|
+
},
|
|
68
|
+
get error() {
|
|
69
|
+
return internal_page.error;
|
|
70
|
+
},
|
|
71
|
+
get form() {
|
|
72
|
+
return internal_page.form;
|
|
73
|
+
},
|
|
74
|
+
get params() {
|
|
75
|
+
return internal_page.params;
|
|
76
|
+
},
|
|
77
|
+
get route() {
|
|
78
|
+
return internal_page.route;
|
|
79
|
+
},
|
|
80
|
+
get shallow() {
|
|
81
|
+
return internal_page.shallow;
|
|
82
|
+
},
|
|
83
|
+
get state() {
|
|
84
|
+
return internal_page.state;
|
|
85
|
+
},
|
|
86
|
+
get status() {
|
|
87
|
+
return internal_page.status;
|
|
88
|
+
},
|
|
89
|
+
get url() {
|
|
90
|
+
return internal_page.url;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** @type {Navigation | null} */
|
|
95
|
+
let navigation = $state.raw(null);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {Navigation | null} value
|
|
99
|
+
*/
|
|
100
|
+
export function set_navigation(value) {
|
|
101
|
+
navigation = value;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A read-only object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
|
|
106
|
+
* Values are `null` when no navigation is occurring, or during server rendering.
|
|
107
|
+
* @type {Navigation | { from: null, to: null, type: null, willUnload: null, delta: null, complete: null }}
|
|
108
|
+
*/
|
|
109
|
+
export const navigating = {
|
|
110
|
+
get from() {
|
|
111
|
+
return navigation ? navigation.from : null;
|
|
112
|
+
},
|
|
113
|
+
get to() {
|
|
114
|
+
return navigation ? navigation.to : null;
|
|
115
|
+
},
|
|
116
|
+
get type() {
|
|
117
|
+
return navigation ? navigation.type : null;
|
|
118
|
+
},
|
|
119
|
+
get willUnload() {
|
|
120
|
+
return navigation ? navigation.willUnload : null;
|
|
121
|
+
},
|
|
122
|
+
// @ts-expect-error TODO not entirely sure what's going on here
|
|
123
|
+
get delta() {
|
|
124
|
+
return navigation?.type === 'popstate' ? navigation.delta : null;
|
|
125
|
+
},
|
|
126
|
+
get complete() {
|
|
127
|
+
return navigation ? navigation.complete : null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const interval = __SVELTEKIT_APP_VERSION_POLL_INTERVAL__;
|
|
132
|
+
|
|
133
|
+
/** @type {number | undefined} */
|
|
134
|
+
let timeout;
|
|
135
|
+
|
|
136
|
+
/** @type {Promise<boolean> | undefined} */
|
|
137
|
+
let checking;
|
|
138
|
+
|
|
139
|
+
let _updated = $state(false);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 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.
|
|
143
|
+
* @type {{ get current(): boolean; check(): Promise<boolean>; }}
|
|
144
|
+
*/
|
|
145
|
+
export const updated = {
|
|
146
|
+
get current() {
|
|
147
|
+
return _updated;
|
|
148
|
+
},
|
|
149
|
+
async check() {
|
|
150
|
+
if (DEV) return false;
|
|
151
|
+
|
|
152
|
+
window.clearTimeout(timeout);
|
|
153
|
+
|
|
154
|
+
if (_updated) {
|
|
155
|
+
return Promise.resolve(true);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (checking ??= (async () => {
|
|
159
|
+
try {
|
|
160
|
+
const res = await fetch(`${assets}/${__SVELTEKIT_APP_VERSION_FILE__}`, {
|
|
161
|
+
headers: {
|
|
162
|
+
'cache-control': 'no-cache'
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
if (!res.ok) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const data = await res.json();
|
|
171
|
+
return (_updated ||= data.version !== version);
|
|
172
|
+
} catch {
|
|
173
|
+
return false;
|
|
174
|
+
} finally {
|
|
175
|
+
checking = undefined;
|
|
176
|
+
if (interval && !_updated) timeout = window.setTimeout(updated.check, interval);
|
|
177
|
+
}
|
|
178
|
+
})());
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
if (!DEV && interval) {
|
|
183
|
+
timeout = window.setTimeout(updated.check, interval);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Mark `updated.current` as `true` if the given version differs from the one
|
|
188
|
+
* the app was hydrated with. Called from the server response header path.
|
|
189
|
+
* Does NOT reset the poll timer — unlike `check()`, this is a passive observation
|
|
190
|
+
* from a single server instance's response, not an explicit version check. The
|
|
191
|
+
* poll timer continues on its original schedule as a backstop. This is important
|
|
192
|
+
* for platforms that implement skew protection, where `x-sveltekit-version`
|
|
193
|
+
* may be out of date — in this case we still need to poll for `version.json`.
|
|
194
|
+
* @param {string | null} new_version
|
|
195
|
+
*/
|
|
196
|
+
export function notify_version(new_version) {
|
|
197
|
+
if (__SVELTEKIT_APP_VERSION_CHECKS_ENABLED__ && new_version) {
|
|
198
|
+
_updated ||= new_version !== version;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Used for testing
|
|
204
|
+
*/
|
|
205
|
+
export function reset_updated() {
|
|
206
|
+
_updated = false;
|
|
207
|
+
}
|
|
@@ -1,66 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/** @import { Page } from '$app/state' */
|
|
3
|
-
import {
|
|
4
|
-
page as client_page,
|
|
5
|
-
navigating as client_navigating,
|
|
6
|
-
updated as client_updated
|
|
7
|
-
} from './client.js';
|
|
8
|
-
import {
|
|
9
|
-
page as server_page,
|
|
10
|
-
navigating as server_navigating,
|
|
11
|
-
updated as server_updated
|
|
12
|
-
} from './server.js';
|
|
13
|
-
import { BROWSER } from 'esm-env';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A read-only reactive object with information about the current page, serving several use cases:
|
|
17
|
-
* - retrieving the combined `data` of all pages/layouts anywhere in your component tree (also see [loading data](https://svelte.dev/docs/kit/load))
|
|
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))
|
|
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
|
|
21
|
-
*
|
|
22
|
-
* ```svelte
|
|
23
|
-
* <!--- file: +layout.svelte --->
|
|
24
|
-
* <script>
|
|
25
|
-
* import { page } from '$app/state';
|
|
26
|
-
* </script>
|
|
27
|
-
*
|
|
28
|
-
* <p>Currently at {page.url.pathname}</p>
|
|
29
|
-
*
|
|
30
|
-
* {#if page.error}
|
|
31
|
-
* <span class="red">Problem detected</span>
|
|
32
|
-
* {:else}
|
|
33
|
-
* <span class="small">All systems operational</span>
|
|
34
|
-
* {/if}
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* Changes to `page` are available exclusively with runes. (The legacy reactivity syntax will not reflect any changes)
|
|
38
|
-
*
|
|
39
|
-
* ```svelte
|
|
40
|
-
* <!--- file: +page.svelte --->
|
|
41
|
-
* <script>
|
|
42
|
-
* import { page } from '$app/state';
|
|
43
|
-
* const id = $derived(page.params.id); // This will correctly update id for usage on this page
|
|
44
|
-
* $: badId = page.params.id; // Do not use; will never update after initial load
|
|
45
|
-
* </script>
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
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.
|
|
49
|
-
*
|
|
50
|
-
* @type {Page}
|
|
51
|
-
*/
|
|
52
|
-
export const page = BROWSER ? client_page : server_page;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* A read-only object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
|
|
56
|
-
* Values are `null` when no navigation is occurring, or during server rendering.
|
|
57
|
-
* @type {Navigation | { from: null, to: null, type: null, willUnload: null, delta: null, complete: null }}
|
|
58
|
-
*/
|
|
59
|
-
// @ts-expect-error
|
|
60
|
-
export const navigating = BROWSER ? client_navigating : server_navigating;
|
|
61
|
-
|
|
62
|
-
/**
|
|
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.
|
|
64
|
-
* @type {{ get current(): boolean; check(): Promise<boolean>; }}
|
|
65
|
-
*/
|
|
66
|
-
export const updated = BROWSER ? client_updated : server_updated;
|
|
1
|
+
export { page, navigating, updated } from '#app/state';
|