@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.
- package/package.json +62 -36
- package/src/cli.js +15 -12
- package/src/constants.js +6 -1
- package/src/core/adapt/builder.js +66 -72
- package/src/core/adapt/index.js +17 -6
- package/src/core/config/index.js +134 -80
- package/src/core/config/options.js +295 -273
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +146 -16
- package/src/core/generate_manifest/index.js +18 -15
- package/src/core/postbuild/analyse.js +8 -20
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/entities.js +8 -2
- package/src/core/postbuild/fallback.js +4 -2
- package/src/core/postbuild/prerender.js +222 -70
- package/src/core/postbuild/queue.js +2 -1
- package/src/core/sync/create_manifest_data/conflict.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +82 -62
- package/src/core/sync/sync.js +40 -31
- package/src/core/sync/ts.js +1 -1
- package/src/core/sync/utils.js +22 -2
- package/src/core/sync/{write_non_ambient.js → write_app_types.js} +107 -58
- package/src/core/sync/write_client_manifest.js +14 -29
- package/src/core/sync/write_env.js +7 -5
- package/src/core/sync/write_server.js +37 -45
- package/src/core/sync/write_tsconfig/index.js +274 -0
- package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
- package/src/core/sync/write_tsconfig/utils.js +77 -0
- package/src/core/sync/write_tsconfig/validate.js +128 -0
- package/src/core/sync/write_types/index.js +127 -123
- package/src/core/utils.js +30 -5
- package/src/exports/env/index.js +77 -0
- package/src/exports/env/public.d.ts +55 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/public.d.ts +195 -0
- package/src/exports/hooks/sequence.js +9 -6
- package/src/exports/index.js +52 -29
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +8 -5
- package/src/exports/internal/index.js +1 -90
- package/src/exports/internal/{event.js → server/event.js} +2 -3
- package/src/exports/internal/server/index.js +37 -0
- package/src/exports/internal/server/telemetry.js +95 -0
- package/src/exports/internal/shared.js +90 -0
- package/src/exports/node/index.js +64 -22
- package/src/exports/params/index.js +70 -0
- package/src/exports/params/public.d.ts +63 -0
- package/src/exports/public.d.ts +50 -1733
- package/src/exports/remote/index.js +11 -0
- package/src/exports/remote/public.d.ts +519 -0
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +54 -65
- package/src/exports/vite/build/remote.js +24 -19
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +218 -146
- package/src/exports/vite/index.js +1590 -858
- package/src/exports/vite/module_ids.js +2 -2
- package/src/exports/vite/preview/index.js +40 -32
- package/src/exports/vite/public.d.ts +588 -0
- package/src/exports/vite/utils.js +84 -46
- package/src/pathname.js +55 -0
- package/src/runner.js +15 -0
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/{forms.js → forms/index.js} +73 -42
- package/src/runtime/app/forms/public.d.ts +2 -0
- package/src/runtime/app/forms/types.d.ts +56 -0
- package/src/runtime/app/internal/transport.js +53 -0
- package/src/runtime/app/manifest/index.js +1 -0
- package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
- package/src/runtime/app/navigation/public.d.ts +237 -0
- package/src/runtime/app/paths/client.js +37 -37
- package/src/runtime/app/paths/index.js +1 -1
- package/src/runtime/app/paths/internal/client.js +34 -2
- package/src/runtime/app/paths/internal/server.js +6 -23
- package/src/runtime/app/paths/internal.d.ts +3 -0
- package/src/runtime/app/paths/public.d.ts +1 -29
- package/src/runtime/app/paths/server.js +36 -17
- package/src/runtime/app/paths/types.d.ts +11 -19
- package/src/runtime/app/server/index.js +2 -2
- package/src/runtime/app/server/public.d.ts +201 -0
- package/src/runtime/app/server/remote/command.js +13 -11
- package/src/runtime/app/server/remote/form.js +61 -39
- package/src/runtime/app/server/remote/prerender.js +45 -45
- package/src/runtime/app/server/remote/query.js +106 -108
- package/src/runtime/app/server/remote/requested.js +27 -19
- package/src/runtime/app/server/remote/shared.js +76 -76
- package/src/runtime/app/service-worker/index.js +24 -0
- package/src/runtime/app/state/client.js +4 -2
- package/src/runtime/app/state/index.js +7 -5
- package/src/runtime/app/state/public.d.ts +72 -0
- package/src/runtime/app/state/server.js +3 -0
- package/src/runtime/app/stores.js +15 -78
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +1336 -648
- package/src/runtime/client/constants.js +3 -6
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +25 -25
- package/src/runtime/client/ndjson.js +1 -1
- package/src/runtime/client/parse.js +1 -1
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/command.svelte.js +37 -61
- package/src/runtime/client/remote-functions/form.svelte.js +267 -178
- package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
- package/src/runtime/client/remote-functions/query/index.js +10 -17
- package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
- package/src/runtime/client/remote-functions/query/proxy.js +5 -5
- package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
- package/src/runtime/client/remote-functions/query-live/index.js +1 -1
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
- package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
- package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
- package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
- package/src/runtime/client/snapshots.js +147 -0
- package/src/runtime/client/state.svelte.js +94 -55
- package/src/runtime/client/stream.js +3 -2
- package/src/runtime/client/types.d.ts +13 -9
- package/src/runtime/client/utils.js +22 -110
- package/src/runtime/components/root.svelte +56 -0
- package/src/runtime/env/dynamic/private.js +7 -0
- package/src/runtime/env/dynamic/public.js +7 -0
- package/src/runtime/env/static/private.js +6 -0
- package/src/runtime/env/static/public.js +6 -0
- package/src/runtime/form-utils.js +172 -61
- package/src/runtime/pathname.js +20 -32
- package/src/runtime/props.svelte.js +72 -0
- package/src/runtime/server/constants.js +0 -3
- package/src/runtime/server/cookie.js +72 -55
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +49 -53
- package/src/runtime/server/dev.js +22 -0
- package/src/runtime/server/endpoint.js +6 -7
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +160 -0
- package/src/runtime/server/fetch.js +32 -39
- package/src/runtime/server/index.js +90 -64
- package/src/runtime/server/internal.js +71 -0
- package/src/runtime/server/page/actions.js +85 -64
- package/src/runtime/server/page/crypto.js +2 -2
- package/src/runtime/server/page/csp.js +88 -104
- package/src/runtime/server/page/data_serializer.js +24 -25
- package/src/runtime/server/page/index.js +36 -53
- package/src/runtime/server/page/load_data.js +50 -57
- package/src/runtime/server/page/render.js +173 -239
- package/src/runtime/server/page/respond_with_error.js +17 -31
- package/src/runtime/server/page/serialize_data.js +2 -13
- package/src/runtime/server/page/server_routing.js +85 -26
- package/src/runtime/server/remote-functions.js +640 -0
- package/src/runtime/server/respond.js +190 -131
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/state.js +53 -0
- package/src/runtime/server/utils.js +13 -155
- package/src/runtime/shared.js +20 -40
- package/src/runtime/utils.js +3 -0
- package/src/types/ambient-private.d.ts +11 -1
- package/src/types/ambient.d.ts +87 -36
- package/src/types/global-private.d.ts +25 -25
- package/src/types/internal.d.ts +163 -157
- package/src/types/private.d.ts +41 -1
- package/src/utils/error.js +28 -4
- package/src/utils/escape.js +9 -25
- package/src/utils/features.js +1 -1
- package/src/utils/filesystem.js +1 -23
- package/src/utils/fork.js +7 -2
- package/src/utils/hash.js +21 -0
- package/src/utils/http.js +8 -7
- package/src/utils/import.js +9 -2
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/page_nodes.js +6 -7
- package/src/utils/params.js +67 -0
- package/src/utils/regex.js +9 -0
- package/src/utils/routing.js +145 -73
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +33 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +2616 -2433
- package/types/index.d.ts.map +120 -106
- package/src/core/sync/write_ambient.js +0 -18
- package/src/core/sync/write_root.js +0 -148
- package/src/core/sync/write_tsconfig.js +0 -250
- package/src/exports/internal/server.js +0 -22
- package/src/exports/node/polyfills.js +0 -30
- package/src/runtime/server/app.js +0 -9
- package/src/runtime/server/remote.js +0 -457
- package/src/runtime/shared-server.js +0 -7
- package/src/runtime/telemetry/otel.js +0 -21
- package/src/runtime/telemetry/record_span.js +0 -65
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
- /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/** @import { RequestEvent } from '
|
|
2
|
-
/** @import {
|
|
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 {
|
|
6
|
-
import { with_request_store
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
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:
|
|
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
|
|
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 {
|
|
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 {
|
|
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`.
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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('
|
|
17
|
+
* @type {import('svelte/store').Readable<import('$app/state').Page>}
|
|
35
18
|
*/
|
|
36
19
|
export const page = {
|
|
37
|
-
subscribe
|
|
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('
|
|
25
|
+
* @type {import('svelte/store').Readable<import('$app/navigation').Navigation | null>}
|
|
52
26
|
*/
|
|
53
27
|
export const navigating = {
|
|
54
|
-
subscribe
|
|
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
|
|
70
|
-
|
|
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
|
-
}
|