@sveltejs/kit 3.0.0-next.0 → 3.0.0-next.10
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 +33 -21
- package/src/core/adapt/builder.js +29 -43
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +132 -71
- package/src/core/config/options.js +294 -244
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +121 -5
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/postbuild/analyse.js +7 -19
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/prerender.js +42 -23
- package/src/core/sync/create_manifest_data/index.js +53 -50
- package/src/core/sync/sync.js +0 -2
- package/src/core/sync/write_client_manifest.js +8 -15
- package/src/core/sync/write_env.js +2 -1
- package/src/core/sync/write_non_ambient.js +12 -9
- package/src/core/sync/write_server.js +13 -14
- package/src/core/sync/write_tsconfig.js +16 -8
- package/src/core/sync/write_tsconfig_test/package.json +7 -0
- package/src/core/sync/write_types/index.js +28 -24
- package/src/core/utils.js +2 -2
- package/src/exports/env/index.js +12 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/sequence.js +3 -2
- package/src/exports/index.js +35 -13
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +2 -2
- package/src/exports/internal/index.js +1 -90
- package/src/exports/internal/{event.js → server/event.js} +1 -2
- package/src/exports/internal/server/index.js +33 -0
- package/src/exports/internal/shared.js +89 -0
- package/src/exports/node/index.js +62 -15
- package/src/exports/params.js +63 -0
- package/src/exports/public.d.ts +323 -170
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +53 -59
- package/src/exports/vite/build/remote.js +18 -11
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +42 -44
- package/src/exports/vite/index.js +810 -593
- package/src/exports/vite/preview/index.js +29 -22
- package/src/exports/vite/static_analysis/index.js +2 -4
- package/src/exports/vite/static_analysis/types.d.ts +14 -0
- package/src/exports/vite/utils.js +21 -36
- 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 +6 -0
- package/src/runtime/app/forms.js +24 -7
- package/src/runtime/app/paths/client.js +4 -10
- package/src/runtime/app/paths/internal/client.js +4 -2
- package/src/runtime/app/paths/internal/server.js +2 -23
- package/src/runtime/app/paths/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +9 -5
- package/src/runtime/app/server/remote/command.js +0 -3
- package/src/runtime/app/server/remote/form.js +27 -15
- package/src/runtime/app/server/remote/prerender.js +29 -36
- package/src/runtime/app/server/remote/query.js +101 -99
- package/src/runtime/app/server/remote/requested.js +22 -14
- package/src/runtime/app/server/remote/shared.js +30 -26
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +411 -318
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/ndjson.js +6 -33
- 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 +7 -32
- package/src/runtime/client/remote-functions/form.svelte.js +183 -112
- package/src/runtime/client/remote-functions/prerender.svelte.js +29 -8
- package/src/runtime/client/remote-functions/query/index.js +7 -14
- package/src/runtime/client/remote-functions/query/instance.svelte.js +63 -18
- package/src/runtime/client/remote-functions/query/proxy.js +3 -3
- package/src/runtime/client/remote-functions/query-batch.svelte.js +60 -68
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +60 -18
- package/src/runtime/client/remote-functions/query-live/iterator.js +36 -55
- package/src/runtime/client/remote-functions/shared.svelte.js +88 -62
- package/src/runtime/client/sse.js +32 -0
- package/src/runtime/client/state.svelte.js +65 -49
- package/src/runtime/client/stream.js +38 -0
- package/src/runtime/client/types.d.ts +11 -7
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/components/root.svelte +66 -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 +100 -22
- package/src/runtime/server/cookie.js +69 -52
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +14 -18
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/actions.js +41 -26
- package/src/runtime/server/page/index.js +9 -15
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +112 -187
- package/src/runtime/server/page/respond_with_error.js +7 -8
- package/src/runtime/server/page/server_routing.js +27 -18
- package/src/runtime/server/remote.js +355 -216
- package/src/runtime/server/respond.js +97 -61
- package/src/runtime/server/utils.js +32 -9
- package/src/runtime/shared.js +83 -13
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/runtime/types.d.ts +8 -0
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +15 -22
- package/src/types/internal.d.ts +89 -74
- package/src/types/private.d.ts +33 -1
- package/src/utils/error.js +24 -4
- package/src/utils/import.js +6 -1
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +90 -44
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +20 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +467 -537
- package/types/index.d.ts.map +22 -39
- package/src/core/sync/write_root.js +0 -148
- package/src/exports/internal/server.js +0 -22
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
|
@@ -5,7 +5,7 @@ import { DEV } from 'esm-env';
|
|
|
5
5
|
import { json } from '@sveltejs/kit';
|
|
6
6
|
import { HttpError, Redirect, ActionFailure, SvelteKitError } from '@sveltejs/kit/internal';
|
|
7
7
|
import { with_request_store, merge_tracing } from '@sveltejs/kit/internal/server';
|
|
8
|
-
import {
|
|
8
|
+
import { normalize_error } from '../../../utils/error.js';
|
|
9
9
|
import { is_form_content_type, negotiate } from '../../../utils/http.js';
|
|
10
10
|
import { create_replacer, handle_error_and_jsonify } from '../utils.js';
|
|
11
11
|
import { record_span } from '../../telemetry/record_span.js';
|
|
@@ -36,13 +36,15 @@ export async function handle_action_json_request(event, event_state, options, se
|
|
|
36
36
|
`POST method not allowed. No form actions exist for ${DEV ? `the page at ${event.route.id}` : 'this page'}`
|
|
37
37
|
);
|
|
38
38
|
|
|
39
|
+
const error = await handle_error_and_jsonify(event, event_state, options, no_actions_error);
|
|
40
|
+
|
|
39
41
|
return action_json(
|
|
40
42
|
{
|
|
41
43
|
type: 'error',
|
|
42
|
-
error
|
|
44
|
+
error
|
|
43
45
|
},
|
|
44
46
|
{
|
|
45
|
-
status:
|
|
47
|
+
status: error.status,
|
|
46
48
|
headers: {
|
|
47
49
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
48
50
|
// "The server must generate an Allow header field in a 405 status code response"
|
|
@@ -62,22 +64,27 @@ export async function handle_action_json_request(event, event_state, options, se
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
if (data instanceof ActionFailure) {
|
|
65
|
-
return action_json(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
data
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
67
|
+
return action_json(
|
|
68
|
+
{
|
|
69
|
+
type: 'failure',
|
|
70
|
+
status: data.status,
|
|
71
|
+
// @ts-expect-error we assign a string to what is supposed to be an object. That's ok
|
|
72
|
+
// because we don't use the object outside, and this way we have better code navigation
|
|
73
|
+
// through knowing where the related interface is used.
|
|
74
|
+
data: stringify_action_response(
|
|
75
|
+
data.data,
|
|
76
|
+
/** @type {string} */ (event.route.id),
|
|
77
|
+
options.hooks.transport
|
|
78
|
+
)
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
status: data.status
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
} else if (data) {
|
|
78
85
|
return action_json({
|
|
79
86
|
type: 'success',
|
|
80
|
-
status:
|
|
87
|
+
status: 200,
|
|
81
88
|
// @ts-expect-error see comment above
|
|
82
89
|
data: stringify_action_response(
|
|
83
90
|
data,
|
|
@@ -85,6 +92,9 @@ export async function handle_action_json_request(event, event_state, options, se
|
|
|
85
92
|
options.hooks.transport
|
|
86
93
|
)
|
|
87
94
|
});
|
|
95
|
+
} else {
|
|
96
|
+
// no data returned — use 204 No Content (without a body, per the spec)
|
|
97
|
+
return new Response(null, { status: 204 });
|
|
88
98
|
}
|
|
89
99
|
} catch (e) {
|
|
90
100
|
const err = normalize_error(e);
|
|
@@ -93,18 +103,20 @@ export async function handle_action_json_request(event, event_state, options, se
|
|
|
93
103
|
return action_json_redirect(err);
|
|
94
104
|
}
|
|
95
105
|
|
|
106
|
+
const transformed = await handle_error_and_jsonify(
|
|
107
|
+
event,
|
|
108
|
+
event_state,
|
|
109
|
+
options,
|
|
110
|
+
check_incorrect_fail_use(err)
|
|
111
|
+
);
|
|
112
|
+
|
|
96
113
|
return action_json(
|
|
97
114
|
{
|
|
98
115
|
type: 'error',
|
|
99
|
-
error:
|
|
100
|
-
event,
|
|
101
|
-
event_state,
|
|
102
|
-
options,
|
|
103
|
-
check_incorrect_fail_use(err)
|
|
104
|
-
)
|
|
116
|
+
error: transformed
|
|
105
117
|
},
|
|
106
118
|
{
|
|
107
|
-
status:
|
|
119
|
+
status: transformed.status
|
|
108
120
|
}
|
|
109
121
|
);
|
|
110
122
|
}
|
|
@@ -163,6 +175,7 @@ export async function handle_action_request(event, event_state, server) {
|
|
|
163
175
|
});
|
|
164
176
|
return {
|
|
165
177
|
type: 'error',
|
|
178
|
+
// We're lying a bit with the types here; this will be transformed into a proper App.Error object later
|
|
166
179
|
error: new SvelteKitError(
|
|
167
180
|
405,
|
|
168
181
|
'Method Not Allowed',
|
|
@@ -207,6 +220,7 @@ export async function handle_action_request(event, event_state, server) {
|
|
|
207
220
|
|
|
208
221
|
return {
|
|
209
222
|
type: 'error',
|
|
223
|
+
// @ts-expect-error We're lying a bit with the types here; this will be transformed into a proper App.Error object later
|
|
210
224
|
error: check_incorrect_fail_use(err)
|
|
211
225
|
};
|
|
212
226
|
}
|
|
@@ -243,11 +257,12 @@ async function call_action(event, event_state, actions) {
|
|
|
243
257
|
}
|
|
244
258
|
}
|
|
245
259
|
|
|
246
|
-
|
|
247
|
-
if (!action) {
|
|
260
|
+
if (!Object.hasOwn(actions, name)) {
|
|
248
261
|
throw new SvelteKitError(404, 'Not Found', `No action with name '${name}' found`);
|
|
249
262
|
}
|
|
250
263
|
|
|
264
|
+
const action = actions[name];
|
|
265
|
+
|
|
251
266
|
if (!is_form_content_type(event.request)) {
|
|
252
267
|
throw new SvelteKitError(
|
|
253
268
|
415,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/** @import { Component } from 'svelte' */
|
|
1
2
|
/** @import { ActionResult, RequestEvent, SSRManifest } from '@sveltejs/kit' */
|
|
2
|
-
/** @import { PageNodeIndexes, RequestState, RequiredResolveOptions, ServerDataNode,
|
|
3
|
+
/** @import { PageNodeIndexes, RequestState, RequiredResolveOptions, ServerDataNode, SSRNode, SSROptions, SSRState } from 'types' */
|
|
3
4
|
import { text } from '@sveltejs/kit';
|
|
4
5
|
import { HttpError, Redirect } from '@sveltejs/kit/internal';
|
|
5
6
|
import { compact } from '../../../utils/array.js';
|
|
@@ -269,6 +270,7 @@ export async function render_page(
|
|
|
269
270
|
if (state.prerendering && should_prerender_data) {
|
|
270
271
|
const body = JSON.stringify({
|
|
271
272
|
type: 'redirect',
|
|
273
|
+
status: err.status,
|
|
272
274
|
location: err.location
|
|
273
275
|
});
|
|
274
276
|
|
|
@@ -281,8 +283,8 @@ export async function render_page(
|
|
|
281
283
|
return redirect_response(err.status, err.location);
|
|
282
284
|
}
|
|
283
285
|
|
|
284
|
-
const status = get_status(err);
|
|
285
286
|
const error = await handle_error_and_jsonify(event, event_state, options, err);
|
|
287
|
+
const status = error.status;
|
|
286
288
|
|
|
287
289
|
while (i--) {
|
|
288
290
|
if (page.errors[i]) {
|
|
@@ -315,13 +317,7 @@ export async function render_page(
|
|
|
315
317
|
},
|
|
316
318
|
status,
|
|
317
319
|
error,
|
|
318
|
-
error_components: await load_error_components(
|
|
319
|
-
options,
|
|
320
|
-
ssr,
|
|
321
|
-
error_branch,
|
|
322
|
-
page,
|
|
323
|
-
manifest
|
|
324
|
-
),
|
|
320
|
+
error_components: await load_error_components(ssr, error_branch, page, manifest),
|
|
325
321
|
branch: error_branch,
|
|
326
322
|
fetched,
|
|
327
323
|
data_serializer
|
|
@@ -373,7 +369,7 @@ export async function render_page(
|
|
|
373
369
|
action_result,
|
|
374
370
|
fetched,
|
|
375
371
|
data_serializer: !ssr ? server_data_serializer(event, event_state, options) : data_serializer,
|
|
376
|
-
error_components: await load_error_components(
|
|
372
|
+
error_components: await load_error_components(ssr, branch, page, manifest)
|
|
377
373
|
});
|
|
378
374
|
} catch (e) {
|
|
379
375
|
// a remote function could have thrown a redirect during render
|
|
@@ -397,18 +393,16 @@ export async function render_page(
|
|
|
397
393
|
}
|
|
398
394
|
|
|
399
395
|
/**
|
|
400
|
-
*
|
|
401
|
-
* @param {SSROptions} options
|
|
402
396
|
* @param {boolean} ssr
|
|
403
397
|
* @param {Array<import('./types.js').Loaded | null>} branch
|
|
404
398
|
* @param {PageNodeIndexes} page
|
|
405
399
|
* @param {SSRManifest} manifest
|
|
406
400
|
*/
|
|
407
|
-
async function load_error_components(
|
|
408
|
-
/** @type {Array<
|
|
401
|
+
async function load_error_components(ssr, branch, page, manifest) {
|
|
402
|
+
/** @type {Array<Component | undefined> | undefined} */
|
|
409
403
|
let error_components;
|
|
410
404
|
|
|
411
|
-
if (
|
|
405
|
+
if (ssr) {
|
|
412
406
|
let last_idx = -1;
|
|
413
407
|
error_components = await Promise.all(
|
|
414
408
|
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
@@ -377,7 +377,7 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
|
|
|
377
377
|
}
|
|
378
378
|
|
|
379
379
|
void push_fetched(base64_encode(result), true);
|
|
380
|
-
})();
|
|
380
|
+
})().catch(noop); // prevent unhandled rejection potentially crashing the process
|
|
381
381
|
|
|
382
382
|
return (teed_body = b);
|
|
383
383
|
}
|