@sveltejs/kit 3.0.0-next.24 → 3.0.0-next.27
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 +16 -10
- package/src/constants.js +6 -0
- package/src/core/adapt/builder.js +128 -33
- package/src/core/adapt/index.js +3 -0
- package/src/core/config/index.js +4 -7
- package/src/core/env.js +39 -14
- package/src/core/generate_manifest/index.js +42 -43
- package/src/core/postbuild/analyse.js +4 -4
- package/src/core/postbuild/fallback.js +1 -1
- package/src/core/postbuild/prerender.js +4 -4
- package/src/core/sync/create_manifest_data/index.js +0 -1
- package/src/core/sync/write_app_manifest.js +3 -2
- package/src/core/sync/write_server.js +3 -17
- package/src/core/utils.js +10 -0
- package/src/exports/adapter.js +22 -0
- package/src/exports/public.d.ts +101 -49
- package/src/exports/vite/build/index.js +1173 -0
- package/src/exports/vite/build/remote.js +4 -4
- package/src/exports/vite/build/service-worker.js +98 -0
- package/src/exports/vite/dev/generate_manifest.js +308 -0
- package/src/exports/vite/dev/index.js +40 -282
- package/src/exports/vite/index.js +156 -1717
- package/src/exports/vite/plugins/env-vars.js +53 -34
- package/src/exports/vite/plugins/guard.js +217 -0
- package/src/exports/vite/plugins/remote.js +237 -0
- package/src/exports/vite/preview/index.js +8 -8
- package/src/exports/vite/static_analysis/index.js +15 -15
- package/src/exports/vite/utils.js +98 -1
- package/src/runner.js +4 -3
- package/src/runtime/app/paths/server.js +2 -2
- package/src/runtime/app/server/index.js +3 -3
- package/src/runtime/app/server/public.d.ts +114 -57
- package/src/runtime/app/server/remote/query.js +2 -2
- package/src/runtime/app/server/remote/requested.js +31 -15
- package/src/runtime/app/state/client.svelte.js +3 -1
- package/src/runtime/client/client.js +43 -198
- package/src/runtime/client/fetcher.js +6 -6
- package/src/runtime/client/focus.js +120 -0
- package/src/runtime/client/remote-functions/command.svelte.js +20 -9
- package/src/runtime/client/remote-functions/form.svelte.js +12 -7
- package/src/runtime/client/remote-functions/query/instance.svelte.js +19 -5
- package/src/runtime/client/remote-functions/shared.svelte.js +22 -1
- package/src/runtime/client/scroll.js +39 -0
- package/src/runtime/client/utils.js +28 -0
- package/src/runtime/form-utils.js +254 -264
- package/src/runtime/server/data/index.js +14 -36
- package/src/runtime/server/errors.js +7 -10
- package/src/runtime/server/fetch.js +21 -25
- package/src/runtime/server/index.js +35 -31
- package/src/runtime/server/internal.js +34 -5
- package/src/runtime/server/page/actions.js +6 -8
- package/src/runtime/server/page/data_serializer.js +6 -10
- package/src/runtime/server/page/index.js +18 -28
- package/src/runtime/server/page/load_data.js +2 -2
- package/src/runtime/server/page/render.js +22 -40
- package/src/runtime/server/page/respond_with_error.js +10 -13
- package/src/runtime/server/page/server_routing.js +21 -27
- package/src/runtime/server/remote-functions.js +136 -136
- package/src/runtime/server/respond.js +66 -64
- package/src/runtime/server/state.js +2 -0
- package/src/runtime/server/utils.js +4 -11
- package/src/runtime/shared.js +9 -0
- package/src/runtime/utils.js +41 -0
- package/src/types/ambient-private.d.ts +1 -2
- package/src/types/global-private.d.ts +8 -0
- package/src/types/internal.d.ts +56 -17
- package/src/utils/filesystem.js +44 -28
- package/src/utils/streaming.js +5 -15
- package/src/version.js +1 -1
- package/types/index.d.ts +235 -93
- package/types/index.d.ts.map +9 -2
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
} from '../pathname.js';
|
|
46
46
|
import { server_data_serializer } from './page/data_serializer.js';
|
|
47
47
|
import { get_remote_id, handle_remote_call } from './remote-functions.js';
|
|
48
|
+
import { hooks, manifest, options } from './internal.js';
|
|
48
49
|
|
|
49
50
|
/** @type {import('types').RequiredResolveOptions['transformPageChunk']} */
|
|
50
51
|
const default_transform = ({ html }) => html;
|
|
@@ -85,12 +86,10 @@ export const respond = propagate_context(internal_respond);
|
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* @param {Request} request
|
|
88
|
-
* @param {import('types').SSROptions} options
|
|
89
|
-
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
90
89
|
* @param {import('types').RequestState} state
|
|
91
90
|
* @returns {Promise<Response>}
|
|
92
91
|
*/
|
|
93
|
-
export async function internal_respond(request,
|
|
92
|
+
export async function internal_respond(request, state) {
|
|
94
93
|
/** URL but stripped from the potential `/__data.json` suffix and its search param */
|
|
95
94
|
const url = new URL(request.url);
|
|
96
95
|
|
|
@@ -100,7 +99,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
100
99
|
|
|
101
100
|
if (!__SVELTEKIT_DEV__) {
|
|
102
101
|
const request_origin = request.headers.get('origin');
|
|
103
|
-
const self_origin = get_self_origin(
|
|
102
|
+
const self_origin = get_self_origin(__SVELTEKIT_PATHS_ORIGIN__, url.origin);
|
|
104
103
|
|
|
105
104
|
if (remote_id) {
|
|
106
105
|
if (
|
|
@@ -113,7 +112,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
113
112
|
const message = 'Cross-site remote requests are forbidden';
|
|
114
113
|
return Response.json({ message }, { status: 403 });
|
|
115
114
|
}
|
|
116
|
-
} else if (
|
|
115
|
+
} else if (__SVELTEKIT_CSRF_CHECK_ORIGIN__) {
|
|
117
116
|
const forbidden = is_csrf_forbidden({
|
|
118
117
|
request,
|
|
119
118
|
request_origin,
|
|
@@ -134,7 +133,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
if (
|
|
136
|
+
if (__SVELTEKIT_HASH_ROUTING__ && url.pathname !== base + '/' && url.pathname !== '/[fallback]') {
|
|
138
137
|
return text('Not found', { status: 404 });
|
|
139
138
|
}
|
|
140
139
|
|
|
@@ -243,8 +242,6 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
243
242
|
// @ts-expect-error this has to be assigned lazily
|
|
244
243
|
event.fetch = create_fetch({
|
|
245
244
|
event,
|
|
246
|
-
options,
|
|
247
|
-
manifest,
|
|
248
245
|
state,
|
|
249
246
|
get_cookie_header,
|
|
250
247
|
set_internal
|
|
@@ -263,7 +260,16 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
263
260
|
|
|
264
261
|
// reroute could alter the given URL, so we pass a copy
|
|
265
262
|
resolved_path =
|
|
266
|
-
(await
|
|
263
|
+
(await hooks.reroute({ url: new URL(url), fetch: event.fetch })) ?? url.pathname;
|
|
264
|
+
|
|
265
|
+
if (!manifest.routes.length && resolved_path !== url.pathname) {
|
|
266
|
+
state.rerouted_url = denormalise_url({
|
|
267
|
+
request_url: request.url,
|
|
268
|
+
resolved_path,
|
|
269
|
+
is_data_request,
|
|
270
|
+
is_route_resolution_request
|
|
271
|
+
}).toString();
|
|
272
|
+
}
|
|
267
273
|
} catch {
|
|
268
274
|
return text('Internal Server Error', {
|
|
269
275
|
status: 500
|
|
@@ -298,14 +304,14 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
298
304
|
// the resolved path has been decoded so it should be compared to the decoded url pathname
|
|
299
305
|
resolved_path !== decode_pathname(url.pathname) &&
|
|
300
306
|
!state.prerendering?.fallback &&
|
|
301
|
-
has_prerendered_path(
|
|
307
|
+
has_prerendered_path(resolved_path)
|
|
302
308
|
) {
|
|
303
|
-
const url =
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
+
const url = denormalise_url({
|
|
310
|
+
request_url: request.url,
|
|
311
|
+
resolved_path,
|
|
312
|
+
is_data_request,
|
|
313
|
+
is_route_resolution_request
|
|
314
|
+
});
|
|
309
315
|
|
|
310
316
|
try {
|
|
311
317
|
// `fetch` automatically decodes the body, so we need to delete the related headers to not break the response
|
|
@@ -323,7 +329,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
323
329
|
statusText: response.statusText
|
|
324
330
|
});
|
|
325
331
|
} catch (error) {
|
|
326
|
-
return await handle_fatal_error(event, state,
|
|
332
|
+
return await handle_fatal_error(event, state, error);
|
|
327
333
|
}
|
|
328
334
|
}
|
|
329
335
|
|
|
@@ -339,10 +345,10 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
339
345
|
|
|
340
346
|
if (is_route_resolution_request) {
|
|
341
347
|
if (is_route_id_resolution_request) {
|
|
342
|
-
return resolve_route_by_id(extract_route_id(resolved_path), new URL(request.url)
|
|
348
|
+
return resolve_route_by_id(extract_route_id(resolved_path), new URL(request.url));
|
|
343
349
|
}
|
|
344
350
|
|
|
345
|
-
return resolve_route(resolved_path, new URL(request.url)
|
|
351
|
+
return resolve_route(resolved_path, new URL(request.url));
|
|
346
352
|
}
|
|
347
353
|
|
|
348
354
|
if (resolved_path === `/${app_dir}/env.js`) {
|
|
@@ -358,8 +364,8 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
358
364
|
|
|
359
365
|
if (!state.prerendering?.fallback && !skip_route_resolution) {
|
|
360
366
|
try {
|
|
361
|
-
const matchers = await manifest.
|
|
362
|
-
const result = find_route(resolved_path, manifest.
|
|
367
|
+
const matchers = await manifest.matchers();
|
|
368
|
+
const result = find_route(resolved_path, manifest.routes, matchers);
|
|
363
369
|
|
|
364
370
|
if (result) {
|
|
365
371
|
route = result.route;
|
|
@@ -369,14 +375,12 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
369
375
|
event.params = result.params;
|
|
370
376
|
}
|
|
371
377
|
} catch (e) {
|
|
372
|
-
return await handle_fatal_error(event, state,
|
|
378
|
+
return await handle_fatal_error(event, state, e);
|
|
373
379
|
}
|
|
374
380
|
}
|
|
375
381
|
|
|
376
382
|
try {
|
|
377
|
-
page_nodes = route?.page
|
|
378
|
-
? new PageNodes(await load_page_nodes(route.page, manifest))
|
|
379
|
-
: undefined;
|
|
383
|
+
page_nodes = route?.page ? new PageNodes(await load_page_nodes(route.page)) : undefined;
|
|
380
384
|
|
|
381
385
|
// determine whether we need to redirect to add/remove a trailing slash
|
|
382
386
|
if (route && !remote_id) {
|
|
@@ -452,10 +456,10 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
452
456
|
add_cookies_to_headers(response.headers, new_cookies.values());
|
|
453
457
|
return response;
|
|
454
458
|
} catch (err) {
|
|
455
|
-
return await handle_fatal_error(event, state,
|
|
459
|
+
return await handle_fatal_error(event, state, err);
|
|
456
460
|
}
|
|
457
461
|
}
|
|
458
|
-
return await handle_fatal_error(event, state,
|
|
462
|
+
return await handle_fatal_error(event, state, e);
|
|
459
463
|
}
|
|
460
464
|
|
|
461
465
|
async function handle() {
|
|
@@ -485,7 +489,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
485
489
|
};
|
|
486
490
|
|
|
487
491
|
return await with_request_store({ event: traced_event, state }, () =>
|
|
488
|
-
|
|
492
|
+
hooks.handle({
|
|
489
493
|
event: traced_event,
|
|
490
494
|
resolve: (event, opts) => {
|
|
491
495
|
return record_span({
|
|
@@ -592,8 +596,6 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
592
596
|
return await respond_with_error({
|
|
593
597
|
event,
|
|
594
598
|
state,
|
|
595
|
-
options,
|
|
596
|
-
manifest,
|
|
597
599
|
error: new SvelteKitError(
|
|
598
600
|
400,
|
|
599
601
|
'Malformed URI',
|
|
@@ -603,31 +605,29 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
603
605
|
});
|
|
604
606
|
}
|
|
605
607
|
|
|
606
|
-
if (
|
|
608
|
+
if (__SVELTEKIT_HASH_ROUTING__ || state.prerendering?.fallback) {
|
|
607
609
|
return await render_response({
|
|
608
610
|
event,
|
|
609
611
|
state,
|
|
610
|
-
options,
|
|
611
|
-
manifest,
|
|
612
612
|
page_config: { ssr: false, csr: true },
|
|
613
613
|
status: 200,
|
|
614
614
|
error: null,
|
|
615
615
|
branch: [
|
|
616
616
|
// include the root layout because it applies to every page
|
|
617
617
|
{
|
|
618
|
-
node: /** @type {SSRNode} */ (await manifest.
|
|
618
|
+
node: /** @type {SSRNode} */ (await manifest.nodes[0]()),
|
|
619
619
|
data: null,
|
|
620
620
|
server_data: null
|
|
621
621
|
}
|
|
622
622
|
],
|
|
623
623
|
fetched: [],
|
|
624
624
|
resolve_opts,
|
|
625
|
-
data_serializer: server_data_serializer(event, state
|
|
625
|
+
data_serializer: server_data_serializer(event, state)
|
|
626
626
|
});
|
|
627
627
|
}
|
|
628
628
|
|
|
629
629
|
if (remote_id) {
|
|
630
|
-
return await handle_remote_call(event, state,
|
|
630
|
+
return await handle_remote_call(event, state, remote_id);
|
|
631
631
|
}
|
|
632
632
|
|
|
633
633
|
if (route) {
|
|
@@ -637,15 +637,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
637
637
|
let response;
|
|
638
638
|
|
|
639
639
|
if (is_data_request) {
|
|
640
|
-
response = await render_data(
|
|
641
|
-
event,
|
|
642
|
-
state,
|
|
643
|
-
route,
|
|
644
|
-
options,
|
|
645
|
-
manifest,
|
|
646
|
-
invalidated_data_nodes,
|
|
647
|
-
trailing_slash
|
|
648
|
-
);
|
|
640
|
+
response = await render_data(event, state, route, invalidated_data_nodes, trailing_slash);
|
|
649
641
|
} else {
|
|
650
642
|
let endpoint;
|
|
651
643
|
if (
|
|
@@ -672,18 +664,10 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
672
664
|
if (!page_nodes) {
|
|
673
665
|
throw new Error('page_nodes not found. This should never happen');
|
|
674
666
|
} else if (page_methods.has(method)) {
|
|
675
|
-
response = await render_page(
|
|
676
|
-
event,
|
|
677
|
-
state,
|
|
678
|
-
route.page,
|
|
679
|
-
options,
|
|
680
|
-
manifest,
|
|
681
|
-
page_nodes,
|
|
682
|
-
resolve_opts
|
|
683
|
-
);
|
|
667
|
+
response = await render_page(event, state, route.page, page_nodes, resolve_opts);
|
|
684
668
|
} else {
|
|
685
669
|
const allowed_methods = new Set(allowed_page_methods);
|
|
686
|
-
const node = await manifest.
|
|
670
|
+
const node = await manifest.nodes[route.page.leaf]();
|
|
687
671
|
if (node?.server?.actions) {
|
|
688
672
|
allowed_methods.add('POST');
|
|
689
673
|
}
|
|
@@ -765,8 +749,6 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
765
749
|
event,
|
|
766
750
|
state,
|
|
767
751
|
{ page: { layouts: [], leaf: 0 } },
|
|
768
|
-
options,
|
|
769
|
-
manifest,
|
|
770
752
|
invalidated_data_nodes,
|
|
771
753
|
// there is no route to take a trailing slash option from, and the
|
|
772
754
|
// SSR'd error page sees the pathname as-is
|
|
@@ -784,8 +766,6 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
784
766
|
return await respond_with_error({
|
|
785
767
|
event,
|
|
786
768
|
state,
|
|
787
|
-
options,
|
|
788
|
-
manifest,
|
|
789
769
|
error: new SvelteKitError(404, 'Not Found', `Not found: ${event.url.pathname}`),
|
|
790
770
|
resolve_opts
|
|
791
771
|
});
|
|
@@ -806,7 +786,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
806
786
|
// and I don't even know how to describe it. need to investigate at some point
|
|
807
787
|
|
|
808
788
|
// HttpError from endpoint can end up here - TODO should it be handled there instead?
|
|
809
|
-
return await handle_fatal_error(event, state,
|
|
789
|
+
return await handle_fatal_error(event, state, e);
|
|
810
790
|
} finally {
|
|
811
791
|
event.cookies.set = () => {
|
|
812
792
|
throw new Error('Cannot use `cookies.set(...)` after the response has been generated');
|
|
@@ -822,13 +802,12 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
822
802
|
|
|
823
803
|
/**
|
|
824
804
|
* @param {import('types').PageNodeIndexes} page
|
|
825
|
-
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
826
805
|
*/
|
|
827
|
-
export function load_page_nodes(page
|
|
806
|
+
export function load_page_nodes(page) {
|
|
828
807
|
return Promise.all([
|
|
829
808
|
// we use == here rather than === because [undefined] serializes as "[null]"
|
|
830
|
-
...page.layouts.map((n) => (n == undefined ? n : manifest.
|
|
831
|
-
manifest.
|
|
809
|
+
...page.layouts.map((n) => (n == undefined ? n : manifest.nodes[n]())),
|
|
810
|
+
manifest.nodes[page.leaf]()
|
|
832
811
|
]);
|
|
833
812
|
}
|
|
834
813
|
|
|
@@ -853,3 +832,26 @@ function propagate_context(fn) {
|
|
|
853
832
|
});
|
|
854
833
|
};
|
|
855
834
|
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* @param {object} opts
|
|
838
|
+
* @param {string} opts.request_url - The original request URL
|
|
839
|
+
* @param {string} opts.resolved_path - The resolved pathname
|
|
840
|
+
* @param {boolean} opts.is_data_request - Whether the request is a data request
|
|
841
|
+
* @param {boolean} opts.is_route_resolution_request -
|
|
842
|
+
* @returns {URL}
|
|
843
|
+
*/
|
|
844
|
+
function denormalise_url({
|
|
845
|
+
request_url,
|
|
846
|
+
resolved_path,
|
|
847
|
+
is_data_request,
|
|
848
|
+
is_route_resolution_request
|
|
849
|
+
}) {
|
|
850
|
+
const url = new URL(request_url);
|
|
851
|
+
url.pathname = is_data_request
|
|
852
|
+
? add_data_suffix(resolved_path)
|
|
853
|
+
: is_route_resolution_request
|
|
854
|
+
? add_resolution_suffix(resolved_path)
|
|
855
|
+
: resolved_path;
|
|
856
|
+
return url;
|
|
857
|
+
}
|
|
@@ -9,6 +9,7 @@ function transient_fields() {
|
|
|
9
9
|
implicit: null,
|
|
10
10
|
forms: null,
|
|
11
11
|
requested: null,
|
|
12
|
+
ignored: null,
|
|
12
13
|
batches: null,
|
|
13
14
|
live_iterators: null
|
|
14
15
|
},
|
|
@@ -36,6 +37,7 @@ export function create_request_state(options) {
|
|
|
36
37
|
prerender_default: undefined,
|
|
37
38
|
error: false,
|
|
38
39
|
depth: 0,
|
|
40
|
+
rerouted_url: null,
|
|
39
41
|
...transient_fields()
|
|
40
42
|
};
|
|
41
43
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { text } from '@sveltejs/kit';
|
|
2
2
|
import { ENDPOINT_METHODS } from '../../constants.js';
|
|
3
|
+
import { manifest } from './internal.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @param {Partial<Record<import('types').HttpMethod, any>>} mod
|
|
@@ -29,13 +30,6 @@ export function allowed_methods(mod) {
|
|
|
29
30
|
return allowed;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
/**
|
|
33
|
-
* @param {import('types').SSROptions} options
|
|
34
|
-
*/
|
|
35
|
-
export function get_global_name(options) {
|
|
36
|
-
return __SVELTEKIT_DEV__ ? '__sveltekit_dev' : `__sveltekit_${options.version_hash}`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
33
|
/**
|
|
40
34
|
* @param {number} status
|
|
41
35
|
* @param {string} location
|
|
@@ -105,13 +99,12 @@ export function serialize_uses(node) {
|
|
|
105
99
|
|
|
106
100
|
/**
|
|
107
101
|
* Returns `true` if the given path was prerendered
|
|
108
|
-
* @param {import('@sveltejs/kit').SSRManifest} manifest
|
|
109
102
|
* @param {string} pathname Should include the base and be decoded
|
|
110
103
|
*/
|
|
111
|
-
export function has_prerendered_path(
|
|
104
|
+
export function has_prerendered_path(pathname) {
|
|
112
105
|
return (
|
|
113
|
-
manifest.
|
|
114
|
-
(pathname.at(-1) === '/' && manifest.
|
|
106
|
+
manifest.prerendered_routes.has(pathname) ||
|
|
107
|
+
(pathname.at(-1) === '/' && manifest.prerendered_routes.has(pathname.slice(0, -1)))
|
|
115
108
|
);
|
|
116
109
|
}
|
|
117
110
|
|
package/src/runtime/shared.js
CHANGED
|
@@ -15,6 +15,15 @@ export function validate_depends(route_id, dep) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Same-origin urls are keyed by path, so prerendered pages can be served from any origin
|
|
20
|
+
* @param {URL} url
|
|
21
|
+
* @param {{ origin: string }} page
|
|
22
|
+
*/
|
|
23
|
+
export function fetch_cache_url(url, page) {
|
|
24
|
+
return url.origin === page.origin ? url.href.slice(page.origin.length) : url.href;
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
export const INVALIDATED_PARAM = 'x-sveltekit-invalidated';
|
|
19
28
|
|
|
20
29
|
export const TRAILING_SLASH_PARAM = 'x-sveltekit-trailing-slash';
|
package/src/runtime/utils.js
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
import { BROWSER } from 'esm-env';
|
|
2
2
|
|
|
3
3
|
export const text_encoder = new TextEncoder();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `ReadableStream.from`, for runtimes that don't support it (as of writing, every Bun release)
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {AsyncIterable<T>} iterable
|
|
9
|
+
* @returns {ReadableStream<T>}
|
|
10
|
+
*/
|
|
11
|
+
export function stream_from_iterable(iterable) {
|
|
12
|
+
// TODO remove the casts once TypeScript's lib includes `ReadableStream.from`
|
|
13
|
+
if (/** @type {any} */ (ReadableStream).from) {
|
|
14
|
+
return /** @type {any} */ (ReadableStream).from(iterable);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
18
|
+
return new ReadableStream({
|
|
19
|
+
async pull(controller) {
|
|
20
|
+
const { value, done } = await iterator.next();
|
|
21
|
+
if (done) controller.close();
|
|
22
|
+
else controller.enqueue(value);
|
|
23
|
+
},
|
|
24
|
+
async cancel(reason) {
|
|
25
|
+
await iterator.return?.(reason);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} head
|
|
32
|
+
* @param {AsyncIterable<string>} chunks
|
|
33
|
+
* @returns {ReadableStream<Uint8Array>} `head` followed by each non-empty chunk, encoded
|
|
34
|
+
*/
|
|
35
|
+
export function stream_text(head, chunks) {
|
|
36
|
+
return stream_from_iterable(
|
|
37
|
+
(async function* () {
|
|
38
|
+
yield text_encoder.encode(head);
|
|
39
|
+
for await (const chunk of chunks) {
|
|
40
|
+
if (chunk) yield text_encoder.encode(chunk);
|
|
41
|
+
}
|
|
42
|
+
})()
|
|
43
|
+
);
|
|
44
|
+
}
|
|
4
45
|
export const text_decoder = new TextDecoder();
|
|
5
46
|
|
|
6
47
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** Internal version of $app/server */
|
|
2
2
|
declare module '<sveltekit:generated>/server.js' {
|
|
3
|
-
import { SSRManifest } from '
|
|
4
|
-
import { SSROptions, ServerHooks } from 'types';
|
|
3
|
+
import { SSROptions, ServerHooks, SSRManifest } from 'types';
|
|
5
4
|
|
|
6
5
|
export const options: SSROptions;
|
|
7
6
|
export const get_hooks: () => Promise<Partial<ServerHooks>>;
|
|
@@ -13,7 +13,15 @@ declare global {
|
|
|
13
13
|
* it is influenced by `NODE_ENV` which can still be true during `vite preview`
|
|
14
14
|
*/
|
|
15
15
|
const __SVELTEKIT_DEV__: boolean;
|
|
16
|
+
const __SVELTEKIT_CSRF_CHECK_ORIGIN__: boolean;
|
|
16
17
|
const __SVELTEKIT_EMBEDDED__: boolean;
|
|
18
|
+
/** True if `config.output.linkHeaderPreload` is `true` */
|
|
19
|
+
const __SVELTEKIT_LINK_HEADER_PRELOAD__: boolean;
|
|
20
|
+
const __SVELTEKIT_PATHS_ORIGIN__: string | undefined;
|
|
21
|
+
/** True if the app has a service worker and `config.serviceWorker.register` is `true` */
|
|
22
|
+
const __SVELTEKIT_SERVICE_WORKER__: boolean;
|
|
23
|
+
/** The `__sveltekit_xxx` name the payload object is attached to, without `globalThis.` */
|
|
24
|
+
const __SVELTEKIT_GLOBAL_NAME__: string;
|
|
17
25
|
const __SVELTEKIT_PATHS_ASSETS__: string;
|
|
18
26
|
const __SVELTEKIT_PATHS_BASE__: string;
|
|
19
27
|
const __SVELTEKIT_PATHS_RELATIVE__: boolean;
|
package/src/types/internal.d.ts
CHANGED
|
@@ -7,12 +7,14 @@ import {
|
|
|
7
7
|
ServerInitOptions,
|
|
8
8
|
Actions,
|
|
9
9
|
RequestEvent,
|
|
10
|
-
SSRManifest,
|
|
11
10
|
Emulator,
|
|
12
|
-
HttpError
|
|
11
|
+
HttpError,
|
|
12
|
+
Adapter,
|
|
13
|
+
AdapterViteConfig
|
|
13
14
|
} from '@sveltejs/kit';
|
|
14
15
|
import { RemoteFormIssue, RemoteQuery, RemoteLiveQuery } from '$app/server';
|
|
15
16
|
import { Config } from '@sveltejs/kit/vite';
|
|
17
|
+
import { ParamMatcher } from '@sveltejs/kit/params';
|
|
16
18
|
import {
|
|
17
19
|
ClientInit,
|
|
18
20
|
Handle,
|
|
@@ -48,12 +50,11 @@ export interface ServerInternalModule {
|
|
|
48
50
|
set_version(version: string): void;
|
|
49
51
|
set_fix_stack_trace(fix_stack_trace: (error: Error) => void): void;
|
|
50
52
|
get_hooks: () => Promise<Record<string, any>>;
|
|
51
|
-
|
|
53
|
+
format_response: (status: number, request: Request) => string;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
export interface Asset {
|
|
55
57
|
file: string;
|
|
56
|
-
size: number;
|
|
57
58
|
type: string | null;
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -194,7 +195,8 @@ export interface InternalRequestOptions extends RequestOptions {
|
|
|
194
195
|
emulator?: Emulator;
|
|
195
196
|
}
|
|
196
197
|
|
|
197
|
-
export class InternalServer
|
|
198
|
+
export class InternalServer implements Server {
|
|
199
|
+
constructor(manifest: SSRManifest);
|
|
198
200
|
init(options: ServerInitOptions): Promise<void>;
|
|
199
201
|
respond(request: Request, options: InternalRequestOptions): Promise<Response>;
|
|
200
202
|
}
|
|
@@ -342,6 +344,8 @@ export type RemoteFunctionData = {
|
|
|
342
344
|
f?: Record<string, RemoteFunctionDataNode>;
|
|
343
345
|
/** Whether there were any refreshes/reconnects during the request */
|
|
344
346
|
r?: true;
|
|
347
|
+
/** Client-requested updates that the server intentionally ignored */
|
|
348
|
+
i?: string[];
|
|
345
349
|
/** The redirect location, if any */
|
|
346
350
|
redirect?: string;
|
|
347
351
|
};
|
|
@@ -457,6 +461,42 @@ export interface ServerNode {
|
|
|
457
461
|
entries?: PrerenderEntryGenerator;
|
|
458
462
|
}
|
|
459
463
|
|
|
464
|
+
/**
|
|
465
|
+
* Information required to instantiate a new `Server` instance.
|
|
466
|
+
*/
|
|
467
|
+
export interface SSRManifest {
|
|
468
|
+
/**
|
|
469
|
+
* The directory where SvelteKit keeps its stuff, including static assets
|
|
470
|
+
* (such as JS and CSS) and internally-used routes.
|
|
471
|
+
*/
|
|
472
|
+
app_dir: string;
|
|
473
|
+
/**
|
|
474
|
+
* The `base` and `appDir` settings combined without a leading slash.
|
|
475
|
+
*/
|
|
476
|
+
app_path: string;
|
|
477
|
+
/**
|
|
478
|
+
* Static files from `config.files.assets` and the service worker (if any).
|
|
479
|
+
*/
|
|
480
|
+
assets: Set<string>;
|
|
481
|
+
/**
|
|
482
|
+
* Map of file extensions to MIME types
|
|
483
|
+
*/
|
|
484
|
+
mime_types: Record<string, string>;
|
|
485
|
+
client: BuildData['client'];
|
|
486
|
+
nodes: SSRNodeLoader[];
|
|
487
|
+
/**
|
|
488
|
+
* hashed filename -> import to that file
|
|
489
|
+
*/
|
|
490
|
+
remotes: Record<string, () => Promise<{ default: Record<string, any> }>>;
|
|
491
|
+
routes: SSRRoute[];
|
|
492
|
+
prerendered_routes: Set<string>;
|
|
493
|
+
matchers: () => Promise<Record<string, ParamMatcher>>;
|
|
494
|
+
/**
|
|
495
|
+
* A `[file]: size` map of all assets imported by server code.
|
|
496
|
+
*/
|
|
497
|
+
server_assets: Record<string, number>;
|
|
498
|
+
}
|
|
499
|
+
|
|
460
500
|
export interface SSRNode {
|
|
461
501
|
/** index into the `nodes` array in the generated `client/app.js`. */
|
|
462
502
|
index: number;
|
|
@@ -493,14 +533,7 @@ export type SSRNodeLoader = () => Promise<SSRNode>;
|
|
|
493
533
|
export interface SSROptions {
|
|
494
534
|
app_template_contains_nonce: boolean;
|
|
495
535
|
csp: ValidatedConfig['csp'];
|
|
496
|
-
csrf_check_origin: boolean;
|
|
497
536
|
csrf_trusted_origins: string[];
|
|
498
|
-
embedded: boolean;
|
|
499
|
-
hash_routing: boolean;
|
|
500
|
-
hooks: ServerHooks;
|
|
501
|
-
link_header_preload: ValidatedConfig['output']['linkHeaderPreload'];
|
|
502
|
-
paths_origin: string | undefined;
|
|
503
|
-
service_worker: boolean;
|
|
504
537
|
service_worker_options: RegistrationOptions;
|
|
505
538
|
templates: {
|
|
506
539
|
app(values: {
|
|
@@ -512,8 +545,6 @@ export interface SSROptions {
|
|
|
512
545
|
}): string;
|
|
513
546
|
error(values: { message: string; status: number }): string;
|
|
514
547
|
};
|
|
515
|
-
version: string;
|
|
516
|
-
version_hash: string;
|
|
517
548
|
}
|
|
518
549
|
|
|
519
550
|
export interface PageNodeIndexes {
|
|
@@ -562,7 +593,8 @@ export interface Uses {
|
|
|
562
593
|
search_params: Set<string>;
|
|
563
594
|
}
|
|
564
595
|
|
|
565
|
-
export type ValidatedConfig = RecursiveRequired<Omit<Config, 'preprocess'>> & {
|
|
596
|
+
export type ValidatedConfig = RecursiveRequired<Omit<Config, 'preprocess' | 'adapter'>> & {
|
|
597
|
+
adapter: Adapter & { vite?: AdapterViteConfig };
|
|
566
598
|
preprocess: Config['preprocess'];
|
|
567
599
|
};
|
|
568
600
|
|
|
@@ -606,7 +638,7 @@ export interface RemoteQueryLiveInternals extends BaseRemoteInternals {
|
|
|
606
638
|
export interface RemoteQueryBatchInternals extends BaseRemoteInternals {
|
|
607
639
|
type: 'query_batch';
|
|
608
640
|
validate: (arg?: any) => MaybePromise<any>;
|
|
609
|
-
run: (args: any[]
|
|
641
|
+
run: (args: any[]) => Promise<any[]>;
|
|
610
642
|
/**
|
|
611
643
|
* Creates a `RemoteQuery` bound directly to a specific client payload (the
|
|
612
644
|
* stringified raw argument) and a pre-validated argument, skipping the query
|
|
@@ -691,6 +723,11 @@ export interface RequestState {
|
|
|
691
723
|
* True if we're currently attempting to render an error page.
|
|
692
724
|
*/
|
|
693
725
|
error: boolean;
|
|
726
|
+
/**
|
|
727
|
+
* The rerouted URL (only if the new pathname differs from the original).
|
|
728
|
+
* Used by platforms that serve a catch-all serverless function.
|
|
729
|
+
*/
|
|
730
|
+
rerouted_url: string | null;
|
|
694
731
|
/**
|
|
695
732
|
* Allows us to prevent `event.fetch` from making infinitely looping internal requests.
|
|
696
733
|
*/
|
|
@@ -720,7 +757,9 @@ export interface RequestState {
|
|
|
720
757
|
/** Instances created via `myForm.for(...)` */
|
|
721
758
|
forms: null | Map<string, any>;
|
|
722
759
|
/** A map of remote function ID to payloads requested for refreshing by the client */
|
|
723
|
-
requested: null | Map<string, string
|
|
760
|
+
requested: null | Map<string, Set<string>>;
|
|
761
|
+
/** Client-requested updates intentionally ignored by `requested(...).ignoreAll()` or `ignore` */
|
|
762
|
+
ignored: null | Set<string>;
|
|
724
763
|
/** A map of query.batch ID to payloads requested for that batch within the same macrotask */
|
|
725
764
|
batches: null | Map<
|
|
726
765
|
string,
|