@sveltejs/kit 3.0.0-next.4 → 3.0.0-next.7
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 +23 -18
- package/src/core/adapt/builder.js +29 -43
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +135 -71
- package/src/core/config/options.js +291 -244
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +120 -5
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/postbuild/analyse.js +8 -12
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/prerender.js +40 -23
- package/src/core/sync/create_manifest_data/index.js +29 -49
- package/src/core/sync/write_client_manifest.js +14 -14
- package/src/core/sync/write_non_ambient.js +10 -7
- package/src/core/sync/write_root.js +9 -30
- package/src/core/sync/write_server.js +13 -11
- package/src/core/sync/write_tsconfig.js +2 -4
- package/src/core/sync/write_types/index.js +11 -10
- package/src/exports/index.js +34 -12
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +1 -1
- 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 +58 -7
- package/src/exports/params.js +63 -0
- package/src/exports/public.d.ts +299 -145
- package/src/exports/url.js +84 -0
- package/src/exports/vite/build/build_server.js +6 -1
- package/src/exports/vite/dev/index.js +38 -37
- package/src/exports/vite/index.js +498 -353
- package/src/exports/vite/preview/index.js +16 -8
- package/src/exports/vite/utils.js +7 -11
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/forms.js +22 -5
- package/src/runtime/app/paths/client.js +4 -10
- package/src/runtime/app/paths/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +8 -4
- package/src/runtime/app/server/remote/form.js +10 -3
- package/src/runtime/app/server/remote/query.js +9 -18
- package/src/runtime/app/server/remote/requested.js +8 -4
- package/src/runtime/app/server/remote/shared.js +5 -7
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/client.js +205 -167
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/form.svelte.js +122 -31
- package/src/runtime/client/remote-functions/prerender.svelte.js +17 -4
- package/src/runtime/client/remote-functions/query/index.js +3 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +27 -11
- package/src/runtime/client/remote-functions/query-batch.svelte.js +4 -3
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +42 -15
- package/src/runtime/client/remote-functions/shared.svelte.js +18 -9
- package/src/runtime/client/state.svelte.js +66 -49
- package/src/runtime/client/types.d.ts +10 -2
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/form-utils.js +99 -18
- package/src/runtime/server/cookie.js +22 -33
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +7 -7
- 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 +2 -1
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +36 -47
- package/src/runtime/server/page/respond_with_error.js +7 -8
- package/src/runtime/server/page/server_routing.js +13 -9
- package/src/runtime/server/remote.js +85 -39
- package/src/runtime/server/respond.js +92 -58
- package/src/runtime/server/utils.js +7 -7
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +4 -4
- package/src/types/internal.d.ts +17 -20
- package/src/types/private.d.ts +33 -1
- package/src/types/synthetic/$lib.md +1 -1
- package/src/utils/error.js +12 -4
- package/src/utils/mime.js +9 -0
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +84 -38
- 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 +434 -269
- package/types/index.d.ts.map +19 -15
- package/src/exports/internal/server.js +0 -22
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { GENERATED_COMMENT } from '../../constants.js';
|
|
3
|
+
import { resolve_entry } from '../../utils/filesystem.js';
|
|
3
4
|
import { posixify } from '../../utils/os.js';
|
|
4
5
|
import { write_if_changed } from './utils.js';
|
|
5
6
|
import { s } from '../../utils/misc.js';
|
|
@@ -85,10 +86,6 @@ export {};
|
|
|
85
86
|
* @param {import('types').ValidatedKitConfig} config
|
|
86
87
|
*/
|
|
87
88
|
function generate_app_types(manifest_data, config) {
|
|
88
|
-
/** @param {string} matcher */
|
|
89
|
-
const path_to_matcher = (matcher) =>
|
|
90
|
-
posixify(path.relative(config.outDir, path.join(config.files.params, matcher + '.js')));
|
|
91
|
-
|
|
92
89
|
/** @type {Map<string, string>} */
|
|
93
90
|
const matcher_types = new Map();
|
|
94
91
|
|
|
@@ -98,7 +95,15 @@ function generate_app_types(manifest_data, config) {
|
|
|
98
95
|
|
|
99
96
|
let type = matcher_types.get(matcher);
|
|
100
97
|
if (!type) {
|
|
101
|
-
|
|
98
|
+
const path_to_params = () => {
|
|
99
|
+
const params_file =
|
|
100
|
+
resolve_entry(config.files.params) ??
|
|
101
|
+
config.files.params.replace(/\.(js|ts)$/, '') + '.js';
|
|
102
|
+
|
|
103
|
+
return posixify(path.relative(config.outDir, params_file));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
type = `import('@sveltejs/kit').MatcherParam<(typeof import('${path_to_params()}').params)[${JSON.stringify(matcher)}]>`;
|
|
102
107
|
matcher_types.set(matcher, type);
|
|
103
108
|
}
|
|
104
109
|
|
|
@@ -239,8 +244,6 @@ function generate_app_types(manifest_data, config) {
|
|
|
239
244
|
|
|
240
245
|
return [
|
|
241
246
|
'declare module "$app/types" {',
|
|
242
|
-
'\ttype MatcherParam<M> = M extends (param : string) => param is (infer U extends string) ? U : string;',
|
|
243
|
-
'',
|
|
244
247
|
'\texport interface AppTypes {',
|
|
245
248
|
`\t\tRouteId(): ${manifest_data.routes.map((r) => s(r.id)).join(' | ')};`,
|
|
246
249
|
`\t\tRouteParams(): {\n\t\t\t${dynamic_routes.join(';\n\t\t\t')}\n\t\t};`,
|
|
@@ -81,45 +81,24 @@ export function write_root(manifest_data, config, output) {
|
|
|
81
81
|
<!-- This file is generated by @sveltejs/kit — do not edit it! -->
|
|
82
82
|
<svelte:options runes={true} />
|
|
83
83
|
<script>
|
|
84
|
-
import {
|
|
85
|
-
import { browser } from '$app/env';
|
|
84
|
+
import { afterNavigate } from '$app/navigation';
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
let { stores, page, constructors, components = [], form, ${use_boundaries ? 'errors = [], error, ' : ''}${levels
|
|
86
|
+
let { page, constructors, components = [], form, ${use_boundaries ? 'errors = [], error, ' : ''}${levels
|
|
89
87
|
.map((l) => `data_${l} = null`)
|
|
90
88
|
.join(', ')} } = $props();
|
|
91
89
|
${use_boundaries ? `let data = $derived({${levels.map((l) => `'${l}': data_${l}`).join(', ')}})` : ''}
|
|
92
90
|
|
|
93
|
-
if (browser) {
|
|
94
|
-
$effect.pre(() => stores.page.set(page));
|
|
95
|
-
} else {
|
|
96
|
-
// svelte-ignore state_referenced_locally
|
|
97
|
-
setContext('__svelte__', stores);
|
|
98
|
-
// svelte-ignore state_referenced_locally
|
|
99
|
-
stores.page.set(page);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
$effect(() => {
|
|
103
|
-
stores;page;constructors;components;form;${use_boundaries ? 'errors;error;' : ''}${levels.map((l) => `data_${l}`).join(';')};
|
|
104
|
-
stores.page.notify();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
91
|
let mounted = $state(false);
|
|
108
92
|
let navigated = $state(false);
|
|
109
93
|
let title = $state(null);
|
|
110
94
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
mounted = true;
|
|
122
|
-
return unsubscribe;
|
|
95
|
+
afterNavigate(() => {
|
|
96
|
+
if (mounted) {
|
|
97
|
+
navigated = true;
|
|
98
|
+
title = document.title || 'untitled page';
|
|
99
|
+
} else {
|
|
100
|
+
mounted = true;
|
|
101
|
+
}
|
|
123
102
|
});
|
|
124
103
|
|
|
125
104
|
const Pyramid_${max_depth} = $derived(constructors[${max_depth}]);
|
|
@@ -15,7 +15,6 @@ import { escape_html } from '../../utils/escape.js';
|
|
|
15
15
|
* config: import('types').ValidatedConfig;
|
|
16
16
|
* has_service_worker: boolean;
|
|
17
17
|
* template: string;
|
|
18
|
-
* error_page: string;
|
|
19
18
|
* }} opts
|
|
20
19
|
*/
|
|
21
20
|
const server_template = ({
|
|
@@ -23,18 +22,16 @@ const server_template = ({
|
|
|
23
22
|
server_hooks,
|
|
24
23
|
universal_hooks,
|
|
25
24
|
has_service_worker,
|
|
26
|
-
template
|
|
27
|
-
error_page
|
|
25
|
+
template
|
|
28
26
|
}) => `
|
|
29
27
|
import root from '../root.js';
|
|
30
28
|
import { set_building, set_prerendering } from '$app/env/internal';
|
|
31
29
|
import { set_assets } from '$app/paths/internal/server';
|
|
32
30
|
import { set_manifest, set_read_implementation } from '__sveltekit/server';
|
|
33
|
-
import
|
|
31
|
+
import error from '../shared/error-template.js';
|
|
34
32
|
|
|
35
33
|
export const options = {
|
|
36
34
|
app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
|
|
37
|
-
async: ${s(!!config.compilerOptions?.experimental?.async)},
|
|
38
35
|
csp: ${s(config.kit.csp)},
|
|
39
36
|
csrf_check_origin: ${s(!config.kit.csrf.trustedOrigins.includes('*'))},
|
|
40
37
|
csrf_trusted_origins: ${s(config.kit.csrf.trustedOrigins)},
|
|
@@ -42,6 +39,7 @@ export const options = {
|
|
|
42
39
|
hash_routing: ${s(config.kit.router.type === 'hash')},
|
|
43
40
|
hooks: null, // added lazily, via \`get_hooks\`
|
|
44
41
|
link_header_preload: ${s(config.kit.output.linkHeaderPreload)},
|
|
42
|
+
paths_origin: ${s(config.kit.paths.origin)},
|
|
45
43
|
root,
|
|
46
44
|
service_worker: ${has_service_worker},
|
|
47
45
|
service_worker_options: ${config.kit.serviceWorker.register ? s(config.kit.serviceWorker.options) : 'null'},
|
|
@@ -57,9 +55,7 @@ export const options = {
|
|
|
57
55
|
/%sveltekit\.env\.([^%]+)%/g,
|
|
58
56
|
(_match, capture) => `" + (env[${s(capture)}] ?? "") + "`
|
|
59
57
|
)},
|
|
60
|
-
error
|
|
61
|
-
.replace(/%sveltekit\.status%/g, '" + status + "')
|
|
62
|
-
.replace(/%sveltekit\.error\.message%/g, '" + message + "')}
|
|
58
|
+
error
|
|
63
59
|
},
|
|
64
60
|
version_hash: ${s(hash(config.kit.version.name))}
|
|
65
61
|
};
|
|
@@ -87,7 +83,7 @@ export async function get_hooks() {
|
|
|
87
83
|
};
|
|
88
84
|
}
|
|
89
85
|
|
|
90
|
-
export { set_assets, set_building,
|
|
86
|
+
export { set_assets, set_building, set_manifest, set_prerendering, set_read_implementation };
|
|
91
87
|
`;
|
|
92
88
|
|
|
93
89
|
// TODO need to re-run this whenever src/app.html or src/error.html are
|
|
@@ -120,6 +116,13 @@ export function write_server(config, output, root) {
|
|
|
120
116
|
return posixify(path.relative(`${output}/server`, file));
|
|
121
117
|
}
|
|
122
118
|
|
|
119
|
+
write_if_changed(
|
|
120
|
+
`${output}/shared/error-template.js`,
|
|
121
|
+
`export default ({ status, message }) => ${s(load_error_page(config))
|
|
122
|
+
.replace(/%sveltekit\.status%/g, '" + status + "')
|
|
123
|
+
.replace(/%sveltekit\.error\.message%/g, '" + message + "')};`
|
|
124
|
+
);
|
|
125
|
+
|
|
123
126
|
// Contains the stringified version of
|
|
124
127
|
/** @type {import('types').SSROptions} */
|
|
125
128
|
write_if_changed(
|
|
@@ -130,8 +133,7 @@ export function write_server(config, output, root) {
|
|
|
130
133
|
universal_hooks: universal_hooks_file ? relative(universal_hooks_file) : null,
|
|
131
134
|
has_service_worker:
|
|
132
135
|
config.kit.serviceWorker.register && !!resolve_entry(config.kit.files.serviceWorker),
|
|
133
|
-
template: load_template(root, config)
|
|
134
|
-
error_page: load_error_page(config)
|
|
136
|
+
template: load_template(root, config)
|
|
135
137
|
})
|
|
136
138
|
);
|
|
137
139
|
}
|
|
@@ -62,7 +62,6 @@ export function get_tsconfig(kit, cwd) {
|
|
|
62
62
|
'env.d.ts',
|
|
63
63
|
'non-ambient.d.ts',
|
|
64
64
|
'./types/**/$types.d.ts',
|
|
65
|
-
config_relative('svelte.config.js'),
|
|
66
65
|
config_relative('vite.config.js'),
|
|
67
66
|
config_relative('vite.config.ts')
|
|
68
67
|
]);
|
|
@@ -125,8 +124,7 @@ export function get_tsconfig(kit, cwd) {
|
|
|
125
124
|
moduleResolution: 'bundler',
|
|
126
125
|
module: 'esnext',
|
|
127
126
|
noEmit: true, // prevent tsconfig error "overwriting input files" - Vite handles the build and ignores this
|
|
128
|
-
target: 'esnext'
|
|
129
|
-
types: ['node']
|
|
127
|
+
target: 'esnext'
|
|
130
128
|
},
|
|
131
129
|
include: [...include],
|
|
132
130
|
exclude
|
|
@@ -176,7 +174,7 @@ function validate_user_config(cwd, out, config) {
|
|
|
176
174
|
styleText(
|
|
177
175
|
['bold', 'yellow'],
|
|
178
176
|
`You have specified a baseUrl and/or paths in your ${config.kind} which interferes with SvelteKit's auto-generated tsconfig.json. ` +
|
|
179
|
-
'Remove it to avoid problems with intellisense. For path aliases, use `
|
|
177
|
+
'Remove it to avoid problems with intellisense. For path aliases, use `config.alias` instead: https://svelte.dev/docs/kit/configuration#alias'
|
|
180
178
|
)
|
|
181
179
|
);
|
|
182
180
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import MagicString from 'magic-string';
|
|
4
|
-
import { rimraf, walk } from '../../../utils/filesystem.js';
|
|
4
|
+
import { rimraf, walk, resolve_entry } from '../../../utils/filesystem.js';
|
|
5
5
|
import { compact } from '../../../utils/array.js';
|
|
6
6
|
import { posixify } from '../../../utils/os.js';
|
|
7
7
|
import { ts } from '../ts.js';
|
|
@@ -198,11 +198,6 @@ function update_types(config, routes, route, root, to_delete = new Set()) {
|
|
|
198
198
|
// Makes sure a type is "repackaged" and therefore more readable
|
|
199
199
|
declarations.push('type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;');
|
|
200
200
|
|
|
201
|
-
// returns the predicate of a matcher's type guard - or string if there is no type guard
|
|
202
|
-
declarations.push(
|
|
203
|
-
'type MatcherParam<M> = M extends (param : string) => param is (infer U extends string) ? U : string;'
|
|
204
|
-
);
|
|
205
|
-
|
|
206
201
|
declarations.push(
|
|
207
202
|
'type RouteParams = ' + generate_params_type(route.params, outdir, config) + ';'
|
|
208
203
|
);
|
|
@@ -604,16 +599,22 @@ function replace_ext_with_js(file_path) {
|
|
|
604
599
|
* @param {import('types').ValidatedConfig} config
|
|
605
600
|
*/
|
|
606
601
|
function generate_params_type(params, outdir, config) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
602
|
+
const path_to_params = () => {
|
|
603
|
+
const params_file =
|
|
604
|
+
resolve_entry(config.kit.files.params) ??
|
|
605
|
+
config.kit.files.params.replace(/\.(js|ts)$/, '') + '.js';
|
|
606
|
+
|
|
607
|
+
return posixify(path.relative(outdir, params_file));
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
const params_import = path_to_params();
|
|
610
611
|
|
|
611
612
|
return `{ ${params
|
|
612
613
|
.map(
|
|
613
614
|
(param) =>
|
|
614
615
|
`${param.name}${param.optional ? '?' : ''}: ${
|
|
615
616
|
param.matcher
|
|
616
|
-
? `MatcherParam<typeof import('${
|
|
617
|
+
? `import('@sveltejs/kit').MatcherParam<(typeof import('${params_import}').params)[${JSON.stringify(param.matcher)}]>`
|
|
617
618
|
: 'string'
|
|
618
619
|
}${param.optional ? ' | undefined' : ''}`
|
|
619
620
|
)
|
package/src/exports/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
2
|
-
|
|
3
|
-
import { HttpError, Redirect, ActionFailure, ValidationError } from './internal/index.js';
|
|
2
|
+
import { HttpError, Redirect, ActionFailure, ValidationError } from './internal/shared.js';
|
|
4
3
|
import { BROWSER, DEV } from 'esm-env';
|
|
5
4
|
import {
|
|
6
5
|
add_data_suffix,
|
|
@@ -11,8 +10,10 @@ import {
|
|
|
11
10
|
strip_resolution_suffix
|
|
12
11
|
} from '../runtime/pathname.js';
|
|
13
12
|
import { text_encoder } from '../runtime/utils.js';
|
|
13
|
+
import { validate_redirect_location } from './url.js';
|
|
14
14
|
|
|
15
15
|
export { VERSION } from '../version.js';
|
|
16
|
+
export { defineParams } from './params.js';
|
|
16
17
|
|
|
17
18
|
// Keep the status codes as `number` because restricting to certain numbers makes it unnecessarily hard to use compared to the benefits
|
|
18
19
|
// (we have runtime errors already to check for invalid codes). Also see https://github.com/sveltejs/kit/issues/11780
|
|
@@ -26,10 +27,10 @@ export { VERSION } from '../version.js';
|
|
|
26
27
|
* return an error response without invoking `handleError`.
|
|
27
28
|
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
28
29
|
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
29
|
-
* @param {App.Error} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
30
|
+
* @param {Omit<App.Error, 'status'> & { status?: App.Error['status'] }} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
30
31
|
* @overload
|
|
31
32
|
* @param {number} status
|
|
32
|
-
* @param {App.Error} body
|
|
33
|
+
* @param {Omit<App.Error, 'status'> & { status?: App.Error['status'] }} body
|
|
33
34
|
* @return {never}
|
|
34
35
|
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
35
36
|
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
@@ -40,10 +41,10 @@ export { VERSION } from '../version.js';
|
|
|
40
41
|
* return an error response without invoking `handleError`.
|
|
41
42
|
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
42
43
|
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
43
|
-
* @param {{ message: string } extends App.Error ?
|
|
44
|
+
* @param {{ status: number; message: string } extends App.Error ? string | void | undefined : never} body The error message.
|
|
44
45
|
* @overload
|
|
45
46
|
* @param {number} status
|
|
46
|
-
* @param {{ message: string } extends App.Error ?
|
|
47
|
+
* @param {{ status: number; message: string } extends App.Error ? string | void | undefined : never} body
|
|
47
48
|
* @return {never}
|
|
48
49
|
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
49
50
|
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
@@ -54,17 +55,34 @@ export { VERSION } from '../version.js';
|
|
|
54
55
|
* return an error response without invoking `handleError`.
|
|
55
56
|
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
56
57
|
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
57
|
-
* @param {
|
|
58
|
+
* @param {string} body The error message.
|
|
59
|
+
* @param {{ status: number; message: string } extends App.Error ? never : Omit<App.Error, 'status' | 'message'>} properties Additional properties of the App.Error type.
|
|
60
|
+
* @overload
|
|
61
|
+
* @param {number} status
|
|
62
|
+
* @param {string} body
|
|
63
|
+
* @param {{ status: number; message: string } extends App.Error ? never : Omit<App.Error, 'status' | 'message'>} properties
|
|
58
64
|
* @return {never}
|
|
59
65
|
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
60
66
|
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
61
67
|
*/
|
|
62
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Throws an error with a HTTP status code and an optional message.
|
|
70
|
+
* When called during request handling, this will cause SvelteKit to
|
|
71
|
+
* return an error response without invoking `handleError`.
|
|
72
|
+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
73
|
+
* @param {any} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
74
|
+
* @param {any} [body] An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
75
|
+
* @param {any} [properties] Additional properties of the App.Error type when passing a string message.
|
|
76
|
+
* @return {never}
|
|
77
|
+
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
78
|
+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
79
|
+
*/
|
|
80
|
+
export function error(status, body, properties) {
|
|
63
81
|
if ((!BROWSER || DEV) && (isNaN(status) || status < 400 || status > 599)) {
|
|
64
82
|
throw new Error(`HTTP error status codes must be between 400 and 599 — ${status} is invalid`);
|
|
65
83
|
}
|
|
66
84
|
|
|
67
|
-
throw new HttpError(status, body);
|
|
85
|
+
throw new HttpError(status, body, properties);
|
|
68
86
|
}
|
|
69
87
|
|
|
70
88
|
/**
|
|
@@ -92,19 +110,23 @@ export function isHttpError(e, status) {
|
|
|
92
110
|
*
|
|
93
111
|
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | ({} & number)} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
|
|
94
112
|
* @param {string | URL} location The location to redirect to.
|
|
113
|
+
* @param {{ external?: boolean | string[] }} [options] To redirect to an external URL, you must pass `{ external: true }` to allow any external URL except `javascript:` URLs, or `{ external: [...] }` with an allowlist of permitted origins.
|
|
95
114
|
* @throws {import('./public.js').Redirect} This error instructs SvelteKit to redirect to the specified location.
|
|
96
|
-
* @throws {Error} If the provided status is invalid
|
|
115
|
+
* @throws {Error} If the provided status is invalid, the location cannot be used as a header value, or the location is an external URL without permission.
|
|
97
116
|
* @return {never}
|
|
98
117
|
*/
|
|
99
|
-
export function redirect(status, location) {
|
|
118
|
+
export function redirect(status, location, options) {
|
|
100
119
|
if ((!BROWSER || DEV) && (isNaN(status) || status < 300 || status > 308)) {
|
|
101
120
|
throw new Error('Invalid status code');
|
|
102
121
|
}
|
|
103
122
|
|
|
123
|
+
const href = location.toString();
|
|
124
|
+
validate_redirect_location(href, options);
|
|
125
|
+
|
|
104
126
|
throw new Redirect(
|
|
105
127
|
// @ts-ignore
|
|
106
128
|
status,
|
|
107
|
-
|
|
129
|
+
href
|
|
108
130
|
);
|
|
109
131
|
}
|
|
110
132
|
|
|
@@ -16,7 +16,7 @@ const ASYNC_VALIDATOR = {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @param {Record<string, EnvVarConfig<any
|
|
19
|
+
* @param {Record<string, EnvVarConfig<any> | undefined>} variables
|
|
20
20
|
* @param {string | undefined} value
|
|
21
21
|
* @param {string} name
|
|
22
22
|
* @param {Record<string, StandardSchemaV1.Issue[]>} issues
|
|
@@ -1,90 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export class HttpError {
|
|
4
|
-
/**
|
|
5
|
-
* @param {number} status
|
|
6
|
-
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
|
|
7
|
-
*/
|
|
8
|
-
constructor(status, body) {
|
|
9
|
-
this.status = status;
|
|
10
|
-
if (typeof body === 'string') {
|
|
11
|
-
this.body = { message: body };
|
|
12
|
-
} else if (body) {
|
|
13
|
-
this.body = body;
|
|
14
|
-
} else {
|
|
15
|
-
this.body = { message: `Error: ${status}` };
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
toString() {
|
|
20
|
-
return JSON.stringify(this.body);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class Redirect {
|
|
25
|
-
/**
|
|
26
|
-
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
|
|
27
|
-
* @param {string} location
|
|
28
|
-
*/
|
|
29
|
-
constructor(status, location) {
|
|
30
|
-
try {
|
|
31
|
-
new Headers({ location });
|
|
32
|
-
} catch {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Invalid redirect location ${JSON.stringify(location)}: ` +
|
|
35
|
-
'this string contains characters that cannot be used in HTTP headers'
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.status = status;
|
|
40
|
-
this.location = location;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* An error that was thrown from within the SvelteKit runtime that is not fatal and doesn't result in a 500, such as a 404.
|
|
46
|
-
* `SvelteKitError` goes through `handleError`.
|
|
47
|
-
* @extends Error
|
|
48
|
-
*/
|
|
49
|
-
export class SvelteKitError extends Error {
|
|
50
|
-
/**
|
|
51
|
-
* @param {number} status
|
|
52
|
-
* @param {string} text
|
|
53
|
-
* @param {string} message
|
|
54
|
-
*/
|
|
55
|
-
constructor(status, text, message) {
|
|
56
|
-
super(message);
|
|
57
|
-
this.status = status;
|
|
58
|
-
this.text = text;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @template [T=undefined]
|
|
64
|
-
*/
|
|
65
|
-
export class ActionFailure {
|
|
66
|
-
/**
|
|
67
|
-
* @param {number} status
|
|
68
|
-
* @param {T} data
|
|
69
|
-
*/
|
|
70
|
-
constructor(status, data) {
|
|
71
|
-
this.status = status;
|
|
72
|
-
this.data = data;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Error thrown when form validation fails imperatively
|
|
78
|
-
*/
|
|
79
|
-
export class ValidationError extends Error {
|
|
80
|
-
/**
|
|
81
|
-
* @param {StandardSchemaV1.Issue[]} issues
|
|
82
|
-
*/
|
|
83
|
-
constructor(issues) {
|
|
84
|
-
super('Validation failed');
|
|
85
|
-
this.name = 'ValidationError';
|
|
86
|
-
this.issues = issues;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export { init_remote_functions } from './remote-functions.js';
|
|
1
|
+
export * from '#internal';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/** @import { RequestEvent } from '@sveltejs/kit' */
|
|
2
2
|
/** @import { RequestStore } from 'types' */
|
|
3
3
|
/** @import { AsyncLocalStorage } from 'node:async_hooks' */
|
|
4
|
-
|
|
5
|
-
import { IN_WEBCONTAINER } from '../../runtime/server/constants.js';
|
|
4
|
+
import { IN_WEBCONTAINER } from '../../../runtime/server/constants.js';
|
|
6
5
|
|
|
7
6
|
/** @type {RequestStore | null} */
|
|
8
7
|
let sync_store = null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @import { Span } from '@opentelemetry/api' */
|
|
2
|
+
import { try_get_request_store } from './event.js';
|
|
3
|
+
|
|
4
|
+
export function get_origin() {
|
|
5
|
+
return try_get_request_store()?.event.url.origin;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @template {{ tracing: { enabled: boolean, root: Span, current: Span } }} T
|
|
10
|
+
* @param {T} event_like
|
|
11
|
+
* @param {Span} current
|
|
12
|
+
* @returns {T}
|
|
13
|
+
*/
|
|
14
|
+
export function merge_tracing(event_like, current) {
|
|
15
|
+
return {
|
|
16
|
+
...event_like,
|
|
17
|
+
tracing: {
|
|
18
|
+
...event_like.tracing,
|
|
19
|
+
current
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
with_request_store,
|
|
26
|
+
getRequestEvent,
|
|
27
|
+
get_request_store,
|
|
28
|
+
try_get_request_store
|
|
29
|
+
} from './event.js';
|
|
30
|
+
|
|
31
|
+
export { init_remote_functions } from './remote-functions.js';
|
|
32
|
+
|
|
33
|
+
export * from '../shared.js';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
2
|
+
|
|
3
|
+
export class HttpError {
|
|
4
|
+
/**
|
|
5
|
+
* @param {number} status
|
|
6
|
+
* @param {Omit<App.Error, 'status'> | string | undefined} body
|
|
7
|
+
* @param {Omit<App.Error, 'status' | 'message'>} [properties]
|
|
8
|
+
*/
|
|
9
|
+
constructor(status, body, properties) {
|
|
10
|
+
this.status = status;
|
|
11
|
+
if (typeof body === 'string') {
|
|
12
|
+
this.body = { ...properties, message: body, status };
|
|
13
|
+
} else if (body) {
|
|
14
|
+
this.body = { ...body, status };
|
|
15
|
+
} else {
|
|
16
|
+
this.body = { message: `Error: ${status}`, status };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toString() {
|
|
21
|
+
return JSON.stringify(this.body);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class Redirect {
|
|
26
|
+
/**
|
|
27
|
+
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
|
|
28
|
+
* @param {string} location
|
|
29
|
+
*/
|
|
30
|
+
constructor(status, location) {
|
|
31
|
+
try {
|
|
32
|
+
new Headers({ location });
|
|
33
|
+
} catch {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Invalid redirect location ${JSON.stringify(location)}: ` +
|
|
36
|
+
'this string contains characters that cannot be used in HTTP headers'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.status = status;
|
|
41
|
+
this.location = location;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* An error that was thrown from within the SvelteKit runtime that is not fatal and doesn't result in a 500, such as a 404.
|
|
47
|
+
* `SvelteKitError` goes through `handleError`.
|
|
48
|
+
* @extends Error
|
|
49
|
+
*/
|
|
50
|
+
export class SvelteKitError extends Error {
|
|
51
|
+
/**
|
|
52
|
+
* @param {number} status
|
|
53
|
+
* @param {string} text
|
|
54
|
+
* @param {string} message
|
|
55
|
+
*/
|
|
56
|
+
constructor(status, text, message) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.status = status;
|
|
59
|
+
this.text = text;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @template [T=undefined]
|
|
65
|
+
*/
|
|
66
|
+
export class ActionFailure {
|
|
67
|
+
/**
|
|
68
|
+
* @param {number} status
|
|
69
|
+
* @param {T} data
|
|
70
|
+
*/
|
|
71
|
+
constructor(status, data) {
|
|
72
|
+
this.status = status;
|
|
73
|
+
this.data = data;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Error thrown when form validation fails imperatively
|
|
79
|
+
*/
|
|
80
|
+
export class ValidationError extends Error {
|
|
81
|
+
/**
|
|
82
|
+
* @param {StandardSchemaV1.Issue[]} issues
|
|
83
|
+
*/
|
|
84
|
+
constructor(issues) {
|
|
85
|
+
super('Validation failed');
|
|
86
|
+
this.name = 'ValidationError';
|
|
87
|
+
this.issues = issues;
|
|
88
|
+
}
|
|
89
|
+
}
|