@sveltejs/kit 3.0.0-next.18 → 3.0.0-next.19
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 +12 -5
- package/src/cli.js +1 -1
- package/src/constants.js +3 -0
- package/src/core/config/index.js +1 -1
- package/src/core/env.js +1 -1
- package/src/core/postbuild/analyse.js +1 -1
- package/src/core/postbuild/prerender.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +9 -0
- package/src/core/sync/sync.js +22 -9
- package/src/core/sync/ts.js +1 -1
- package/src/core/sync/write_app_types.js +1 -1
- package/src/core/sync/write_client_manifest.js +1 -1
- package/src/core/sync/write_server.js +1 -3
- package/src/core/sync/write_tsconfig/index.js +1 -1
- package/src/core/sync/write_types/index.js +6 -3
- package/src/exports/index.js +9 -9
- package/src/exports/internal/server/event.js +1 -1
- package/src/exports/internal/server/telemetry.js +1 -1
- package/src/exports/internal/shared.js +9 -0
- package/src/exports/{params.js → params/index.js} +6 -4
- package/src/exports/params/public.d.ts +63 -0
- package/src/exports/public.d.ts +77 -447
- package/src/exports/vite/build/build_server.js +2 -2
- package/src/exports/vite/dev/index.js +2 -3
- package/src/exports/vite/index.js +14 -3
- package/src/pathname.js +55 -0
- package/src/runtime/app/{forms.js → forms/index.js} +9 -8
- package/src/runtime/app/forms/public.d.ts +2 -0
- package/src/runtime/app/forms/types.d.ts +56 -0
- package/src/runtime/app/{navigation.js → navigation/index.js} +2 -2
- package/src/runtime/app/navigation/public.d.ts +237 -0
- package/src/runtime/app/paths/client.js +14 -8
- package/src/runtime/app/paths/index.js +1 -1
- package/src/runtime/app/paths/internal/client.js +4 -0
- package/src/runtime/app/paths/internal/server.js +4 -0
- package/src/runtime/app/paths/internal.d.ts +3 -0
- package/src/runtime/app/paths/public.d.ts +1 -1
- package/src/runtime/app/paths/server.js +6 -4
- package/src/runtime/app/server/index.js +1 -1
- package/src/runtime/app/server/remote/form.js +3 -4
- package/src/runtime/app/server/remote/prerender.js +3 -3
- package/src/runtime/app/server/remote/shared.js +3 -10
- package/src/runtime/app/state/index.js +4 -2
- package/src/runtime/app/state/public.d.ts +72 -0
- package/src/runtime/app/stores.js +2 -2
- package/src/runtime/client/client.js +65 -54
- package/src/runtime/client/entry.js +2 -2
- package/src/runtime/client/remote-functions/command.svelte.js +36 -34
- package/src/runtime/client/remote-functions/form.svelte.js +76 -78
- package/src/runtime/client/remote-functions/prerender.svelte.js +3 -3
- package/src/runtime/client/remote-functions/query/index.js +1 -1
- package/src/runtime/client/remote-functions/query/instance.svelte.js +4 -3
- package/src/runtime/client/remote-functions/query-batch.svelte.js +3 -3
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -5
- package/src/runtime/client/remote-functions/query-live/iterator.js +5 -7
- package/src/runtime/client/remote-functions/shared.svelte.js +9 -14
- package/src/runtime/client/state.svelte.js +5 -3
- package/src/runtime/client/types.d.ts +2 -1
- package/src/runtime/pathname.js +6 -61
- package/src/runtime/props.svelte.js +1 -1
- package/src/runtime/server/constants.js +0 -3
- package/src/runtime/server/errors.js +53 -28
- package/src/runtime/server/fetch.js +1 -1
- package/src/runtime/server/index.js +9 -14
- package/src/runtime/server/page/actions.js +2 -1
- package/src/runtime/server/page/index.js +7 -3
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +17 -11
- package/src/runtime/server/page/server_routing.js +3 -2
- package/src/runtime/server/remote-functions.js +3 -2
- package/src/runtime/server/respond.js +4 -8
- package/src/runtime/server/state.js +3 -6
- package/src/types/ambient.d.ts +1 -1
- package/src/types/internal.d.ts +8 -10
- package/src/types/private.d.ts +12 -3
- package/src/utils/error.js +30 -14
- package/src/utils/page_nodes.js +3 -2
- package/src/utils/params.js +3 -2
- package/src/utils/routing.js +5 -4
- package/src/version.js +1 -1
- package/types/index.d.ts +992 -932
- package/types/index.d.ts.map +43 -31
- /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseSetCookie } from 'cookie';
|
|
2
2
|
import { noop } from '../../utils/functions.js';
|
|
3
3
|
import { respond } from './respond.js';
|
|
4
|
-
import * as paths from '
|
|
4
|
+
import * as paths from '#app/paths';
|
|
5
5
|
import { read_implementation } from './internal.js';
|
|
6
6
|
import { has_prerendered_path } from './utils.js';
|
|
7
7
|
import { fork_state_for_subrequest } from './state.js';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { noop } from '../../utils/functions.js';
|
|
2
|
-
import { IN_WEBCONTAINER } from '
|
|
2
|
+
import { IN_WEBCONTAINER } from '../../constants.js';
|
|
3
3
|
import { respond } from './respond.js';
|
|
4
4
|
import { create_request_state } from './state.js';
|
|
5
5
|
import { options, get_hooks } from '__SERVER__/internal.js';
|
|
6
6
|
import { set_read_implementation, set_manifest, fix_stack_trace } from './internal.js';
|
|
7
7
|
import { set_env } from '__sveltekit/env';
|
|
8
|
-
import { SvelteKitError } from '@sveltejs/kit/internal';
|
|
9
8
|
import { init_tracing } from '@sveltejs/kit/internal/server';
|
|
10
9
|
import { DEV } from 'esm-env';
|
|
11
10
|
import { init_transport } from '#app/internal/transport';
|
|
@@ -130,8 +129,13 @@ export class Server {
|
|
|
130
129
|
handle: module.handle || (({ event, resolve }) => resolve(event)),
|
|
131
130
|
handleError:
|
|
132
131
|
module.handleError ||
|
|
133
|
-
(({ error }) => {
|
|
134
|
-
if (
|
|
132
|
+
(({ kind, error, issues }) => {
|
|
133
|
+
if (kind === 'validation') {
|
|
134
|
+
console.error('Remote function schema validation failed:', issues);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (kind !== 'unknown') {
|
|
135
139
|
// don't log stack traces for 404s etc, it's all internal gubbins
|
|
136
140
|
return;
|
|
137
141
|
}
|
|
@@ -149,12 +153,6 @@ export class Server {
|
|
|
149
153
|
}
|
|
150
154
|
}),
|
|
151
155
|
handleFetch: module.handleFetch || (({ request, fetch }) => fetch(request)),
|
|
152
|
-
handleValidationError:
|
|
153
|
-
module.handleValidationError ||
|
|
154
|
-
(({ issues }) => {
|
|
155
|
-
console.error('Remote function schema validation failed:', issues);
|
|
156
|
-
return { message: 'Bad Request', status: 400 };
|
|
157
|
-
}),
|
|
158
156
|
reroute: module.reroute || noop
|
|
159
157
|
};
|
|
160
158
|
|
|
@@ -171,9 +169,6 @@ export class Server {
|
|
|
171
169
|
},
|
|
172
170
|
handleError: ({ error }) => console.error(error),
|
|
173
171
|
handleFetch: ({ request, fetch }) => fetch(request),
|
|
174
|
-
handleValidationError: () => {
|
|
175
|
-
return { message: 'Bad Request' };
|
|
176
|
-
},
|
|
177
172
|
reroute: noop
|
|
178
173
|
};
|
|
179
174
|
} else {
|
|
@@ -192,7 +187,7 @@ export class Server {
|
|
|
192
187
|
request,
|
|
193
188
|
this.#options,
|
|
194
189
|
this.#manifest,
|
|
195
|
-
create_request_state(options
|
|
190
|
+
create_request_state(options)
|
|
196
191
|
);
|
|
197
192
|
|
|
198
193
|
if (DEV) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
/** @import { RequestEvent,
|
|
1
|
+
/** @import { RequestEvent, Actions } from '@sveltejs/kit' */
|
|
2
|
+
/** @import { ActionResult } from '$app/forms' */
|
|
2
3
|
/** @import { SSROptions, SSRNode, ServerNode } from 'types' */
|
|
3
4
|
import { DEV } from 'esm-env';
|
|
4
5
|
import { json } from '@sveltejs/kit';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @import { Component } from 'svelte' */
|
|
2
|
-
/** @import {
|
|
2
|
+
/** @import { RequestEvent, SSRManifest } from '@sveltejs/kit' */
|
|
3
|
+
/** @import { ActionResult } from '$app/forms' */
|
|
3
4
|
/** @import { PageNodeIndexes, RequestState, RequiredResolveOptions, ServerDataNode, SSRNode, SSROptions } from 'types' */
|
|
4
5
|
import { text } from '@sveltejs/kit';
|
|
5
6
|
import { Redirect } from '@sveltejs/kit/internal';
|
|
@@ -112,7 +113,10 @@ export async function render_page(event, state, page, options, manifest, nodes,
|
|
|
112
113
|
// renders an empty 'shell' page if SSR is turned off and if there is
|
|
113
114
|
// no server data to prerender. As a result, the load functions and rendering
|
|
114
115
|
// only occur client-side.
|
|
115
|
-
if (
|
|
116
|
+
if (
|
|
117
|
+
ssr === false &&
|
|
118
|
+
!((state.prerendering || state.prerender_default === true) && should_prerender_data)
|
|
119
|
+
) {
|
|
116
120
|
// if the user makes a request through a non-enhanced form, the returned value is lost
|
|
117
121
|
// because there is no SSR or client-side handling of the response
|
|
118
122
|
if (DEV && action_result && !event.request.headers.has('x-sveltekit-action')) {
|
|
@@ -162,7 +166,7 @@ export async function render_page(event, state, page, options, manifest, nodes,
|
|
|
162
166
|
|
|
163
167
|
const data_serializer = server_data_serializer(event, state, options);
|
|
164
168
|
const data_serializer_json =
|
|
165
|
-
state.prerendering && should_prerender_data
|
|
169
|
+
(state.prerendering || state.prerender_default === true) && should_prerender_data
|
|
166
170
|
? server_data_serializer_json(event, state, options)
|
|
167
171
|
: null;
|
|
168
172
|
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import * as devalue from 'devalue';
|
|
3
3
|
import { DEV } from 'esm-env';
|
|
4
4
|
import { isRedirect, text } from '@sveltejs/kit';
|
|
5
|
-
import * as paths from '
|
|
5
|
+
import * as paths from '#app/paths';
|
|
6
|
+
import { relative } from '$app/paths/internal/server';
|
|
6
7
|
import { hash } from '../../../utils/hash.js';
|
|
7
8
|
import { serialize_data } from './serialize_data.js';
|
|
8
9
|
import { s } from '../../../utils/misc.js';
|
|
@@ -42,7 +43,7 @@ import { has_custom_transporters, uneval } from '#app/internal/transport';
|
|
|
42
43
|
* event: import('@sveltejs/kit').RequestEvent;
|
|
43
44
|
* state: import('types').RequestState;
|
|
44
45
|
* resolve_opts: import('types').RequiredResolveOptions;
|
|
45
|
-
* action_result?: import('
|
|
46
|
+
* action_result?: import('$app/forms').ActionResult;
|
|
46
47
|
* data_serializer: import('./types.js').ServerDataSerializer;
|
|
47
48
|
* error_components?: Array<import('svelte').Component | undefined>
|
|
48
49
|
* }} opts
|
|
@@ -62,7 +63,7 @@ export async function render_response({
|
|
|
62
63
|
data_serializer,
|
|
63
64
|
error_components
|
|
64
65
|
}) {
|
|
65
|
-
if (state.prerendering) {
|
|
66
|
+
if (state.prerendering || state.prerender_default === true) {
|
|
66
67
|
if (options.csp.mode === 'nonce') {
|
|
67
68
|
throw new Error('Cannot use prerendering if config.csp.mode === "nonce"');
|
|
68
69
|
}
|
|
@@ -110,11 +111,11 @@ export async function render_response({
|
|
|
110
111
|
let base_expression = s(paths.base);
|
|
111
112
|
|
|
112
113
|
const csp = new Csp(options.csp, {
|
|
113
|
-
prerender: !!state.prerendering
|
|
114
|
+
prerender: !!(state.prerendering || state.prerender_default === true)
|
|
114
115
|
});
|
|
115
116
|
|
|
116
117
|
// if appropriate, use relative paths for greater portability
|
|
117
|
-
if (
|
|
118
|
+
if (relative) {
|
|
118
119
|
if (!state.prerendering?.fallback) {
|
|
119
120
|
// the relative path depth must reflect the URL the browser is actually at, which
|
|
120
121
|
// for a data request includes the `__data.json` suffix that was stripped during routing
|
|
@@ -316,7 +317,7 @@ export async function render_response({
|
|
|
316
317
|
* @param {string[]} attributes
|
|
317
318
|
*/
|
|
318
319
|
const add_preload = (path, attributes) => {
|
|
319
|
-
if (options.link_header_preload && !state.prerendering) {
|
|
320
|
+
if (options.link_header_preload && !(state.prerendering || state.prerender_default === true)) {
|
|
320
321
|
link_headers.add(`<${encodeURI(path)}>; ${attributes.join('; ')}; nopush`);
|
|
321
322
|
} else {
|
|
322
323
|
head.add_link_tag(path, attributes);
|
|
@@ -357,7 +358,11 @@ export async function render_response({
|
|
|
357
358
|
if (page_config.ssr && page_config.csr) {
|
|
358
359
|
body += `\n\t\t\t${fetched
|
|
359
360
|
.map((item) =>
|
|
360
|
-
serialize_data(
|
|
361
|
+
serialize_data(
|
|
362
|
+
item,
|
|
363
|
+
resolve_opts.filterSerializedResponseHeaders,
|
|
364
|
+
!!(state.prerendering || state.prerender_default === true)
|
|
365
|
+
)
|
|
361
366
|
)
|
|
362
367
|
.join('\n\t\t\t')}`;
|
|
363
368
|
}
|
|
@@ -369,7 +374,8 @@ export async function render_response({
|
|
|
369
374
|
// import the env.js module so that it evaluates before any user code can evaluate.
|
|
370
375
|
// TODO revert to using top-level await once https://bugs.webkit.org/show_bug.cgi?id=242740 is fixed
|
|
371
376
|
// https://github.com/sveltejs/kit/pull/11601
|
|
372
|
-
const load_env_eagerly =
|
|
377
|
+
const load_env_eagerly =
|
|
378
|
+
client.uses_env_dynamic_public && (state.prerendering || state.prerender_default === true);
|
|
373
379
|
|
|
374
380
|
if (load_env_eagerly) {
|
|
375
381
|
modulepreloads.add(`${paths.app_dir}/env.js`);
|
|
@@ -400,7 +406,7 @@ export async function render_response({
|
|
|
400
406
|
if (route && !state.prerendering.resolved_route_ids.has(route.id)) {
|
|
401
407
|
state.prerendering.resolved_route_ids.add(route.id);
|
|
402
408
|
|
|
403
|
-
const id_pathname = paths.base + route_id_resolution_pathname(
|
|
409
|
+
const id_pathname = paths.base + route_id_resolution_pathname(route.id);
|
|
404
410
|
|
|
405
411
|
state.prerendering.dependencies.set(
|
|
406
412
|
id_pathname,
|
|
@@ -587,14 +593,14 @@ export async function render_response({
|
|
|
587
593
|
'content-type': 'text/html'
|
|
588
594
|
});
|
|
589
595
|
|
|
590
|
-
if (state.prerendering) {
|
|
596
|
+
if (state.prerendering || state.prerender_default === true) {
|
|
591
597
|
// TODO read headers set with setHeaders and convert into http-equiv where possible
|
|
592
598
|
const csp_headers = csp.csp_provider.get_meta();
|
|
593
599
|
if (csp_headers) {
|
|
594
600
|
head.add_http_equiv(csp_headers);
|
|
595
601
|
}
|
|
596
602
|
|
|
597
|
-
if (state.prerendering
|
|
603
|
+
if (state.prerendering?.cache) {
|
|
598
604
|
head.add_http_equiv(
|
|
599
605
|
`<meta http-equiv="cache-control" content="${state.prerendering.cache}">`
|
|
600
606
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @import { SSRManifest } from '@sveltejs/kit' */
|
|
2
|
-
import { base, assets
|
|
2
|
+
import { base, assets } from '#app/paths';
|
|
3
|
+
import { relative } from '$app/paths/internal/server';
|
|
3
4
|
import { text } from '@sveltejs/kit';
|
|
4
5
|
import { s } from '../../../utils/misc.js';
|
|
5
6
|
import { find_route } from '../../../utils/routing.js';
|
|
@@ -20,7 +21,7 @@ export function generate_route_object(route, url, client) {
|
|
|
20
21
|
.join(',\n\t\t');
|
|
21
22
|
|
|
22
23
|
// stringified version of
|
|
23
|
-
|
|
24
|
+
/* @type {import('types').CSRRouteServer} */
|
|
24
25
|
return [
|
|
25
26
|
`{\n\tid: ${s(route.id)}`,
|
|
26
27
|
`errors: ${s(route.errors)}`,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
/** @import {
|
|
1
|
+
/** @import { RemoteForm, RequestEvent, SSRManifest } from '@sveltejs/kit' */
|
|
2
|
+
/** @import { ActionResult } from '$app/forms' */
|
|
2
3
|
/** @import { RemoteFormInternals, RemoteFunctionData, RemoteFunctionResponse, RemoteInternals, RequestState, SSROptions } from 'types' */
|
|
3
4
|
|
|
4
5
|
import { json, error } from '@sveltejs/kit';
|
|
5
6
|
import { Redirect, SvelteKitError } from '@sveltejs/kit/internal';
|
|
6
7
|
import { with_request_store, merge_tracing, record_span } from '@sveltejs/kit/internal/server';
|
|
7
|
-
import { app_dir, base } from '
|
|
8
|
+
import { app_dir, base } from '#app/paths';
|
|
8
9
|
import { is_form_content_type } from '../../utils/http.js';
|
|
9
10
|
import { create_remote_key, parse_remote_arg, split_remote_key } from '../shared.js';
|
|
10
11
|
import { stringify } from '#app/internal/transport';
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
record_span,
|
|
9
9
|
with_request_store
|
|
10
10
|
} from '@sveltejs/kit/internal/server';
|
|
11
|
-
import { base, app_dir } from '
|
|
11
|
+
import { base, app_dir } from '#app/paths';
|
|
12
12
|
import { is_endpoint_request, render_endpoint } from './endpoint.js';
|
|
13
13
|
import { render_page } from './page/index.js';
|
|
14
14
|
import { render_response } from './page/render.js';
|
|
@@ -152,7 +152,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
152
152
|
* for path resolution, then return the route object as a JS file.
|
|
153
153
|
*/
|
|
154
154
|
url.pathname = strip_resolution_suffix(url.pathname);
|
|
155
|
-
is_route_id_resolution_request = is_route_id_resolution_path(url.pathname
|
|
155
|
+
is_route_id_resolution_request = is_route_id_resolution_path(url.pathname);
|
|
156
156
|
} else if (is_data_request) {
|
|
157
157
|
url.pathname =
|
|
158
158
|
strip_data_suffix(url.pathname) +
|
|
@@ -339,11 +339,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
339
339
|
|
|
340
340
|
if (is_route_resolution_request) {
|
|
341
341
|
if (is_route_id_resolution_request) {
|
|
342
|
-
return resolve_route_by_id(
|
|
343
|
-
extract_route_id(resolved_path, app_dir),
|
|
344
|
-
new URL(request.url),
|
|
345
|
-
manifest
|
|
346
|
-
);
|
|
342
|
+
return resolve_route_by_id(extract_route_id(resolved_path), new URL(request.url), manifest);
|
|
347
343
|
}
|
|
348
344
|
|
|
349
345
|
return resolve_route(resolved_path, new URL(request.url), manifest);
|
|
@@ -429,7 +425,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
429
425
|
prerender = node.prerender ?? prerender;
|
|
430
426
|
} else if (page_nodes) {
|
|
431
427
|
config = page_nodes.get_config() ?? config;
|
|
432
|
-
prerender = page_nodes.prerender();
|
|
428
|
+
prerender = state.prerender_default = page_nodes.prerender();
|
|
433
429
|
}
|
|
434
430
|
|
|
435
431
|
if (state.emulator?.platform) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @import { InternalRequestOptions, RequestState
|
|
1
|
+
/** @import { InternalRequestOptions, RequestState } from 'types' */
|
|
2
2
|
|
|
3
3
|
/** Per-request caches and context flags — never carried into a fork. */
|
|
4
4
|
function transient_fields() {
|
|
@@ -16,17 +16,15 @@ function transient_fields() {
|
|
|
16
16
|
is_in_remote_form_or_command: false,
|
|
17
17
|
is_in_remote_query: false,
|
|
18
18
|
is_in_remote_prerender: false,
|
|
19
|
-
is_in_render: false
|
|
20
|
-
original_event: undefined
|
|
19
|
+
is_in_render: false
|
|
21
20
|
};
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* @param {InternalRequestOptions} options
|
|
26
|
-
* @param {ServerHooks} hooks
|
|
27
25
|
* @returns {RequestState}
|
|
28
26
|
*/
|
|
29
|
-
export function create_request_state(options
|
|
27
|
+
export function create_request_state(options) {
|
|
30
28
|
// every field is initialized up front so the object shape stays stable
|
|
31
29
|
return {
|
|
32
30
|
getClientAddress: options.getClientAddress,
|
|
@@ -38,7 +36,6 @@ export function create_request_state(options, hooks) {
|
|
|
38
36
|
prerender_default: undefined,
|
|
39
37
|
error: false,
|
|
40
38
|
depth: 0,
|
|
41
|
-
handleValidationError: hooks.handleValidationError,
|
|
42
39
|
...transient_fields()
|
|
43
40
|
};
|
|
44
41
|
}
|
package/src/types/ambient.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
declare namespace App {
|
|
24
24
|
/**
|
|
25
|
-
* Defines the common shape of expected and unexpected errors. Expected errors are thrown using the `error` function.
|
|
25
|
+
* Defines the common shape of expected and unexpected errors. Expected errors are thrown using the `error` function. Every error passes through the `handleError` hooks, which must return this shape (with `status` and `message` optional, since they default to those of the caught error).
|
|
26
26
|
*/
|
|
27
27
|
export interface Error {
|
|
28
28
|
status: number;
|
package/src/types/internal.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
ServerInit,
|
|
21
21
|
ClientInit,
|
|
22
22
|
Transport,
|
|
23
|
-
HandleValidationError,
|
|
24
23
|
RemoteFormIssue,
|
|
25
24
|
RemoteQuery,
|
|
26
25
|
RemoteLiveQuery
|
|
@@ -156,7 +155,6 @@ export interface ServerHooks {
|
|
|
156
155
|
handleFetch: HandleFetch;
|
|
157
156
|
handle: Handle;
|
|
158
157
|
handleError: HandleServerError;
|
|
159
|
-
handleValidationError: HandleValidationError;
|
|
160
158
|
reroute: Reroute;
|
|
161
159
|
transport?: Transport;
|
|
162
160
|
init?: ServerInit;
|
|
@@ -232,6 +230,7 @@ export interface PrerenderDependency {
|
|
|
232
230
|
body: null | string | Uint8Array;
|
|
233
231
|
}
|
|
234
232
|
|
|
233
|
+
/** Internal context for the prerendering process */
|
|
235
234
|
export interface PrerenderOptions {
|
|
236
235
|
cache?: string; // including this here is a bit of a hack, but it makes it easy to add <meta http-equiv>
|
|
237
236
|
fallback?: boolean;
|
|
@@ -627,10 +626,15 @@ export interface RemotePrerenderInternals extends BaseRemoteInternals {
|
|
|
627
626
|
}
|
|
628
627
|
|
|
629
628
|
export type RemoteAnyQueryInternals =
|
|
630
|
-
|
|
629
|
+
| RemoteQueryInternals
|
|
630
|
+
| RemoteQueryBatchInternals
|
|
631
|
+
| RemoteQueryLiveInternals;
|
|
631
632
|
|
|
632
633
|
export type RemoteInternals =
|
|
633
|
-
|
|
634
|
+
| RemoteAnyQueryInternals
|
|
635
|
+
| RemoteCommandInternals
|
|
636
|
+
| RemoteFormInternals
|
|
637
|
+
| RemotePrerenderInternals;
|
|
634
638
|
|
|
635
639
|
export interface InternalRemoteFormIssue extends RemoteFormIssue {
|
|
636
640
|
name: string;
|
|
@@ -678,7 +682,6 @@ export interface RequestState {
|
|
|
678
682
|
* Allows us to prevent `event.fetch` from making infinitely looping internal requests.
|
|
679
683
|
*/
|
|
680
684
|
readonly depth: number;
|
|
681
|
-
readonly handleValidationError: ServerHooks['handleValidationError'];
|
|
682
685
|
readonly remote: {
|
|
683
686
|
/** Resolved query/prerender data, populated by `await myQuery()` or `myQuery.set(...)` */
|
|
684
687
|
data: null | Map<RemoteInternals, Record<string, MaybePromise<any>>>;
|
|
@@ -729,11 +732,6 @@ export interface RequestState {
|
|
|
729
732
|
readonly is_in_remote_query: boolean;
|
|
730
733
|
readonly is_in_remote_prerender: boolean;
|
|
731
734
|
readonly is_in_render: boolean;
|
|
732
|
-
/**
|
|
733
|
-
* The event before `derive_remote_function_event` hid or stubbed properties.
|
|
734
|
-
* Hooks like `handleValidationError` receive this so `url` etc. stay accessible
|
|
735
|
-
*/
|
|
736
|
-
readonly original_event?: RequestEvent;
|
|
737
735
|
}
|
|
738
736
|
|
|
739
737
|
export interface RequestStore {
|
package/src/types/private.d.ts
CHANGED
|
@@ -239,11 +239,20 @@ export interface PrerenderInvalidUrlHandler {
|
|
|
239
239
|
export type PrerenderHttpErrorHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderHttpErrorHandler;
|
|
240
240
|
export type PrerenderMissingIdHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderMissingIdHandler;
|
|
241
241
|
export type PrerenderUnseenRoutesHandlerValue =
|
|
242
|
-
|
|
242
|
+
| 'fail'
|
|
243
|
+
| 'warn'
|
|
244
|
+
| 'ignore'
|
|
245
|
+
| PrerenderUnseenRoutesHandler;
|
|
243
246
|
export type PrerenderEntryGeneratorMismatchHandlerValue =
|
|
244
|
-
|
|
247
|
+
| 'fail'
|
|
248
|
+
| 'warn'
|
|
249
|
+
| 'ignore'
|
|
250
|
+
| PrerenderEntryGeneratorMismatchHandler;
|
|
245
251
|
export type PrerenderInvalidUrlHandlerValue =
|
|
246
|
-
|
|
252
|
+
| 'fail'
|
|
253
|
+
| 'warn'
|
|
254
|
+
| 'ignore'
|
|
255
|
+
| PrerenderInvalidUrlHandler;
|
|
247
256
|
|
|
248
257
|
export type PrerenderOption = boolean | 'auto';
|
|
249
258
|
|
package/src/utils/error.js
CHANGED
|
@@ -36,23 +36,39 @@ export function normalize_error(error) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @param {
|
|
40
|
-
* @param {any} [error]
|
|
39
|
+
* @param {unknown} error
|
|
41
40
|
*/
|
|
42
|
-
export function get_status(
|
|
43
|
-
|
|
44
|
-
const status = err instanceof HttpError || err instanceof SvelteKitError ? err.status : 500;
|
|
45
|
-
|
|
46
|
-
if (error == null || typeof transformed?.status !== 'number') {
|
|
47
|
-
return status;
|
|
48
|
-
} else {
|
|
49
|
-
return transformed.status;
|
|
50
|
-
}
|
|
41
|
+
export function get_status(error) {
|
|
42
|
+
return error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
|
51
43
|
}
|
|
52
44
|
|
|
53
45
|
/**
|
|
54
|
-
*
|
|
46
|
+
* Adds development-only compatibility accessors for the former top-level `status` and `message`
|
|
47
|
+
* properties of the `handleError` hook input.
|
|
48
|
+
* @template {object} T
|
|
49
|
+
* @param {T} input
|
|
50
|
+
* @param {{ status: number; message: string }} fallback
|
|
51
|
+
* @returns {T}
|
|
55
52
|
*/
|
|
56
|
-
export function
|
|
57
|
-
|
|
53
|
+
export function add_deprecated_handle_error_properties(input, fallback) {
|
|
54
|
+
Object.defineProperties(input, {
|
|
55
|
+
status: {
|
|
56
|
+
get() {
|
|
57
|
+
console.warn(
|
|
58
|
+
'The `status` property of `handleError` is deprecated. Use `error.status` for expected and framework errors, or `500` for unexpected errors.'
|
|
59
|
+
);
|
|
60
|
+
return fallback.status;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
message: {
|
|
64
|
+
get() {
|
|
65
|
+
console.warn(
|
|
66
|
+
"The `message` property of `handleError` is deprecated. Use `error.message` for expected and framework errors, or 'Internal Error' for unexpected errors."
|
|
67
|
+
);
|
|
68
|
+
return fallback.message;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return input;
|
|
58
74
|
}
|
package/src/utils/page_nodes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @import { UniversalNode, ServerNode } from 'types' */
|
|
1
2
|
import {
|
|
2
3
|
validate_layout_exports,
|
|
3
4
|
validate_layout_server_exports,
|
|
@@ -42,10 +43,10 @@ export class PageNodes {
|
|
|
42
43
|
/**
|
|
43
44
|
* @template {'prerender' | 'ssr' | 'csr' | 'trailingSlash'} Option
|
|
44
45
|
* @param {Option} option
|
|
45
|
-
* @returns {
|
|
46
|
+
* @returns {(UniversalNode | ServerNode)[Option] | undefined}
|
|
46
47
|
*/
|
|
47
48
|
#get_option(option) {
|
|
48
|
-
/** @typedef {(
|
|
49
|
+
/** @typedef {(UniversalNode | ServerNode)[Option]} Value */
|
|
49
50
|
|
|
50
51
|
return this.data.reduce((value, node) => {
|
|
51
52
|
return node?.universal?.[option] ?? node?.server?.[option] ?? value;
|
package/src/utils/params.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @import { ParamMatcher } from '@sveltejs/kit/params' */
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { pathToFileURL } from 'node:url';
|
|
3
4
|
|
|
@@ -38,7 +39,7 @@ export function validate_param_matchers(params, names, file) {
|
|
|
38
39
|
* root: string;
|
|
39
40
|
* load?: (file: string) => Promise<Record<string, unknown>>;
|
|
40
41
|
* }} opts
|
|
41
|
-
* @returns {Promise<Record<string,
|
|
42
|
+
* @returns {Promise<Record<string, ParamMatcher> | null>}
|
|
42
43
|
*/
|
|
43
44
|
export async function load_and_validate_params({ routes, params_path, root, load }) {
|
|
44
45
|
const names = collect_matcher_names(routes);
|
|
@@ -62,5 +63,5 @@ export async function load_and_validate_params({ routes, params_path, root, load
|
|
|
62
63
|
params_path
|
|
63
64
|
);
|
|
64
65
|
|
|
65
|
-
return /** @type {Record<string,
|
|
66
|
+
return /** @type {Record<string, ParamMatcher>} */ (module.params);
|
|
66
67
|
}
|
package/src/utils/routing.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @import { ParamMatcher, ParamValue } from '@sveltejs/kit/params' */
|
|
1
2
|
import { BROWSER } from 'esm-env';
|
|
2
3
|
import { escape_for_regexp } from './regex.js';
|
|
3
4
|
|
|
@@ -146,7 +147,7 @@ export function get_route_segments(route) {
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
/**
|
|
149
|
-
* @param {
|
|
150
|
+
* @param {ParamMatcher} matcher
|
|
150
151
|
* @param {string} value
|
|
151
152
|
* @returns {{ success: true, value: any } | { success: false }}
|
|
152
153
|
*/
|
|
@@ -178,7 +179,7 @@ function run_matcher(matcher, value) {
|
|
|
178
179
|
/**
|
|
179
180
|
* @param {RegExpMatchArray} match
|
|
180
181
|
* @param {import('types').RouteParam[]} params
|
|
181
|
-
* @param {Record<string,
|
|
182
|
+
* @param {Record<string, ParamMatcher>} matchers
|
|
182
183
|
*/
|
|
183
184
|
export function exec(match, params, matchers) {
|
|
184
185
|
/** @type {Record<string, any>} */
|
|
@@ -298,7 +299,7 @@ export const segment_pattern = new RegExp(
|
|
|
298
299
|
* ); // `/blog/hello-world/something/else`
|
|
299
300
|
* ```
|
|
300
301
|
* @param {string} id
|
|
301
|
-
* @param {Record<string,
|
|
302
|
+
* @param {Record<string, ParamValue | undefined>} params
|
|
302
303
|
* @returns {string}
|
|
303
304
|
*/
|
|
304
305
|
export function resolve_route(id, params) {
|
|
@@ -360,7 +361,7 @@ export function has_server_load(node) {
|
|
|
360
361
|
* @template {{pattern: RegExp, params: import('types').RouteParam[]}} Route
|
|
361
362
|
* @param {string} path - The decoded pathname to match
|
|
362
363
|
* @param {Route[]} routes
|
|
363
|
-
* @param {Record<string,
|
|
364
|
+
* @param {Record<string, ParamMatcher>} matchers
|
|
364
365
|
* @returns {{ route: Route, params: Record<string, any> } | null}
|
|
365
366
|
*/
|
|
366
367
|
export function find_route(path, routes, matchers) {
|
package/src/version.js
CHANGED