@sveltejs/kit 3.0.0-next.1 → 3.0.0-next.11
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/constants.js +2 -0
- package/src/core/adapt/builder.js +32 -49
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +137 -71
- package/src/core/config/options.js +236 -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/fallback.js +2 -1
- package/src/core/postbuild/prerender.js +114 -48
- package/src/core/postbuild/queue.js +2 -1
- 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 +14 -15
- 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 +30 -5
- package/src/exports/env/index.js +77 -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 +8 -5
- 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 +68 -0
- package/src/exports/public.d.ts +363 -189
- 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 +92 -50
- package/src/exports/vite/index.js +903 -681
- package/src/exports/vite/module_ids.js +0 -2
- package/src/exports/vite/preview/index.js +32 -24
- 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 +40 -35
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/forms.js +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 +10 -6
- package/src/runtime/app/server/index.js +1 -1
- 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 +39 -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 +15 -19
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +135 -0
- package/src/runtime/server/fetch.js +1 -1
- package/src/runtime/server/index.js +22 -12
- package/src/runtime/server/internal.js +25 -0
- package/src/runtime/server/page/actions.js +43 -27
- package/src/runtime/server/page/data_serializer.js +10 -10
- package/src/runtime/server/page/index.js +12 -17
- package/src/runtime/server/page/load_data.js +2 -2
- package/src/runtime/server/page/render.js +114 -193
- package/src/runtime/server/page/respond_with_error.js +11 -11
- package/src/runtime/server/page/server_routing.js +27 -18
- package/src/runtime/server/remote-functions.js +596 -0
- package/src/runtime/server/respond.js +100 -68
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/utils.js +2 -134
- 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-private.d.ts +2 -0
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +13 -25
- package/src/types/internal.d.ts +95 -80
- package/src/types/private.d.ts +41 -1
- package/src/utils/error.js +24 -4
- package/src/utils/escape.js +9 -25
- package/src/utils/features.js +1 -1
- package/src/utils/fork.js +7 -2
- package/src/utils/import.js +6 -1
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/page_nodes.js +3 -5
- 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 +537 -557
- package/types/index.d.ts.map +24 -39
- package/src/core/sync/write_root.js +0 -148
- package/src/exports/internal/server.js +0 -22
- package/src/runtime/server/remote.js +0 -457
- package/src/runtime/shared-server.js +0 -7
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
|
@@ -1,457 +0,0 @@
|
|
|
1
|
-
/** @import { ActionResult, RemoteForm, RequestEvent, SSRManifest } from '@sveltejs/kit' */
|
|
2
|
-
/** @import { RemoteFormInternals, RemoteFunctionResponse, RemoteInternals, RequestState, SSROptions } from 'types' */
|
|
3
|
-
|
|
4
|
-
import { json, error } from '@sveltejs/kit';
|
|
5
|
-
import { HttpError, Redirect, SvelteKitError } from '@sveltejs/kit/internal';
|
|
6
|
-
import { with_request_store, merge_tracing } from '@sveltejs/kit/internal/server';
|
|
7
|
-
import { app_dir, base } from '$app/paths/internal/server';
|
|
8
|
-
import { is_form_content_type } from '../../utils/http.js';
|
|
9
|
-
import { parse_remote_arg, split_remote_key, stringify } from '../shared.js';
|
|
10
|
-
import { handle_error_and_jsonify } from './utils.js';
|
|
11
|
-
import { normalize_error } from '../../utils/error.js';
|
|
12
|
-
import { check_incorrect_fail_use } from './page/actions.js';
|
|
13
|
-
import { DEV } from 'esm-env';
|
|
14
|
-
import { record_span } from '../telemetry/record_span.js';
|
|
15
|
-
import { deserialize_binary_form } from '../form-utils.js';
|
|
16
|
-
|
|
17
|
-
/** @type {typeof handle_remote_call_internal} */
|
|
18
|
-
export async function handle_remote_call(event, state, options, manifest, id) {
|
|
19
|
-
return record_span({
|
|
20
|
-
name: 'sveltekit.remote.call',
|
|
21
|
-
attributes: {
|
|
22
|
-
'sveltekit.remote.call.id': id
|
|
23
|
-
},
|
|
24
|
-
fn: (current) => {
|
|
25
|
-
const traced_event = merge_tracing(event, current);
|
|
26
|
-
return with_request_store({ event: traced_event, state }, () =>
|
|
27
|
-
handle_remote_call_internal(traced_event, state, options, manifest, id)
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {RequestEvent} event
|
|
35
|
-
* @param {RequestState} state
|
|
36
|
-
* @param {SSROptions} options
|
|
37
|
-
* @param {SSRManifest} manifest
|
|
38
|
-
* @param {string} id
|
|
39
|
-
*/
|
|
40
|
-
async function handle_remote_call_internal(event, state, options, manifest, id) {
|
|
41
|
-
const [hash, name, additional_args] = id.split('/');
|
|
42
|
-
const remotes = manifest._.remotes;
|
|
43
|
-
|
|
44
|
-
if (!remotes[hash]) error(404);
|
|
45
|
-
|
|
46
|
-
const module = await remotes[hash]();
|
|
47
|
-
const fn = module.default[name];
|
|
48
|
-
|
|
49
|
-
if (!fn) error(404);
|
|
50
|
-
|
|
51
|
-
/** @type {RemoteInternals} */
|
|
52
|
-
const internals = fn.__;
|
|
53
|
-
const transport = options.hooks.transport;
|
|
54
|
-
|
|
55
|
-
event.tracing.current.setAttributes({
|
|
56
|
-
'sveltekit.remote.call.type': internals.type,
|
|
57
|
-
'sveltekit.remote.call.name': internals.name
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
if (internals.type === 'query_batch') {
|
|
62
|
-
if (event.request.method !== 'POST') {
|
|
63
|
-
throw new SvelteKitError(
|
|
64
|
-
405,
|
|
65
|
-
'Method Not Allowed',
|
|
66
|
-
`\`query.batch\` functions must be invoked via POST request, not ${event.request.method}`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** @type {{ payloads: string[] }} */
|
|
71
|
-
const { payloads } = await event.request.json();
|
|
72
|
-
|
|
73
|
-
const args = await Promise.all(
|
|
74
|
-
payloads.map((payload) => parse_remote_arg(payload, transport))
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const results = await with_request_store({ event, state }, () =>
|
|
78
|
-
internals.run(args, options)
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
return json(
|
|
82
|
-
/** @type {RemoteFunctionResponse} */ ({
|
|
83
|
-
type: 'result',
|
|
84
|
-
result: stringify(results, transport)
|
|
85
|
-
})
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (internals.type === 'form') {
|
|
90
|
-
if (event.request.method !== 'POST') {
|
|
91
|
-
throw new SvelteKitError(
|
|
92
|
-
405,
|
|
93
|
-
'Method Not Allowed',
|
|
94
|
-
`\`form\` functions must be invoked via POST request, not ${event.request.method}`
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!is_form_content_type(event.request)) {
|
|
99
|
-
throw new SvelteKitError(
|
|
100
|
-
415,
|
|
101
|
-
'Unsupported Media Type',
|
|
102
|
-
`\`form\` functions expect form-encoded data — received ${event.request.headers.get(
|
|
103
|
-
'content-type'
|
|
104
|
-
)}`
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const { data, meta, form_data } = await deserialize_binary_form(event.request);
|
|
109
|
-
state.remote.requested = create_requested_map(meta.remote_refreshes);
|
|
110
|
-
|
|
111
|
-
// If this is a keyed form instance (created via form.for(key)), add the key to the form data (unless already set)
|
|
112
|
-
// Note that additional_args will only be set if the form is not enhanced, as enhanced forms transfer the key inside `data`.
|
|
113
|
-
if (additional_args && !('id' in data)) {
|
|
114
|
-
data.id = JSON.parse(decodeURIComponent(additional_args));
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const fn = internals.fn;
|
|
118
|
-
const result = await with_request_store({ event, state }, () => fn(data, meta, form_data));
|
|
119
|
-
|
|
120
|
-
return json(
|
|
121
|
-
/** @type {RemoteFunctionResponse} */ ({
|
|
122
|
-
type: 'result',
|
|
123
|
-
result: stringify(result, transport),
|
|
124
|
-
refreshes: result.issues
|
|
125
|
-
? undefined
|
|
126
|
-
: await serialize_singleflight(state.remote.refreshes),
|
|
127
|
-
reconnects: result.issues
|
|
128
|
-
? undefined
|
|
129
|
-
: await serialize_singleflight(state.remote.reconnects)
|
|
130
|
-
})
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (internals.type === 'command') {
|
|
135
|
-
/** @type {{ payload: string, refreshes?: string[] }} */
|
|
136
|
-
const { payload, refreshes } = await event.request.json();
|
|
137
|
-
state.remote.requested = create_requested_map(refreshes);
|
|
138
|
-
const arg = parse_remote_arg(payload, transport);
|
|
139
|
-
const data = await with_request_store({ event, state }, () => fn(arg));
|
|
140
|
-
|
|
141
|
-
return json(
|
|
142
|
-
/** @type {RemoteFunctionResponse} */ ({
|
|
143
|
-
type: 'result',
|
|
144
|
-
result: stringify(data, transport),
|
|
145
|
-
refreshes: await serialize_singleflight(state.remote.refreshes),
|
|
146
|
-
reconnects: await serialize_singleflight(state.remote.reconnects)
|
|
147
|
-
})
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (internals.type === 'query_live') {
|
|
152
|
-
if (event.request.method !== 'GET') {
|
|
153
|
-
throw new SvelteKitError(
|
|
154
|
-
405,
|
|
155
|
-
'Method Not Allowed',
|
|
156
|
-
`\`query.live\` functions must be invoked via GET request, not ${event.request.method}`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const payload = /** @type {string} */ (
|
|
161
|
-
new URL(event.request.url).searchParams.get('payload')
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
const generator = internals.run(event, state, parse_remote_arg(payload, transport));
|
|
165
|
-
|
|
166
|
-
const encoder = new TextEncoder();
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @param {ReadableStreamDefaultController} controller
|
|
170
|
-
* @param {any} payload
|
|
171
|
-
*/
|
|
172
|
-
function send(controller, payload) {
|
|
173
|
-
controller.enqueue(encoder.encode(JSON.stringify(payload) + '\n'));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let closed = false;
|
|
177
|
-
|
|
178
|
-
/** @type {string | undefined} */
|
|
179
|
-
let result = undefined;
|
|
180
|
-
|
|
181
|
-
async function cancel() {
|
|
182
|
-
if (closed) return;
|
|
183
|
-
closed = true;
|
|
184
|
-
await generator.return(undefined);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
event.request.signal.addEventListener('abort', cancel, { once: true });
|
|
188
|
-
|
|
189
|
-
return new Response(
|
|
190
|
-
new ReadableStream({
|
|
191
|
-
async pull(controller) {
|
|
192
|
-
if (event.request.signal.aborted) {
|
|
193
|
-
await cancel();
|
|
194
|
-
controller.close();
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
try {
|
|
199
|
-
while (true) {
|
|
200
|
-
const { value, done } = await generator.next();
|
|
201
|
-
|
|
202
|
-
if (done) {
|
|
203
|
-
await cancel();
|
|
204
|
-
controller.close();
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// only send changed data
|
|
209
|
-
if (result !== (result = stringify(value, transport))) {
|
|
210
|
-
send(controller, {
|
|
211
|
-
type: 'result',
|
|
212
|
-
result
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
} catch (error) {
|
|
219
|
-
if (!event.request.signal.aborted) {
|
|
220
|
-
if (error instanceof Redirect) {
|
|
221
|
-
send(controller, {
|
|
222
|
-
type: 'redirect',
|
|
223
|
-
location: error.location
|
|
224
|
-
});
|
|
225
|
-
} else {
|
|
226
|
-
const status =
|
|
227
|
-
error instanceof HttpError || error instanceof SvelteKitError
|
|
228
|
-
? error.status
|
|
229
|
-
: 500;
|
|
230
|
-
|
|
231
|
-
send(controller, {
|
|
232
|
-
type: 'error',
|
|
233
|
-
error: await handle_error_and_jsonify(event, state, options, error),
|
|
234
|
-
status
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
await cancel();
|
|
240
|
-
controller.close();
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
cancel
|
|
244
|
-
}),
|
|
245
|
-
{
|
|
246
|
-
headers: {
|
|
247
|
-
'cache-control': 'private, no-store',
|
|
248
|
-
'content-type': 'application/x-ndjson'
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const payload =
|
|
255
|
-
internals.type === 'prerender'
|
|
256
|
-
? additional_args
|
|
257
|
-
: /** @type {string} */ (
|
|
258
|
-
// new URL(...) necessary because we're hiding the URL from the user in the event object
|
|
259
|
-
new URL(event.request.url).searchParams.get('payload')
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
const data = await with_request_store({ event, state }, () =>
|
|
263
|
-
fn(parse_remote_arg(payload, transport))
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
return json(
|
|
267
|
-
/** @type {RemoteFunctionResponse} */ ({
|
|
268
|
-
type: 'result',
|
|
269
|
-
result: stringify(data, transport)
|
|
270
|
-
})
|
|
271
|
-
);
|
|
272
|
-
} catch (error) {
|
|
273
|
-
if (error instanceof Redirect) {
|
|
274
|
-
return json(
|
|
275
|
-
/** @type {RemoteFunctionResponse} */ ({
|
|
276
|
-
type: 'redirect',
|
|
277
|
-
location: error.location,
|
|
278
|
-
refreshes: await serialize_singleflight(state.remote.refreshes),
|
|
279
|
-
reconnects: await serialize_singleflight(state.remote.reconnects)
|
|
280
|
-
})
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const status =
|
|
285
|
-
error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
|
286
|
-
|
|
287
|
-
return json(
|
|
288
|
-
/** @type {RemoteFunctionResponse} */ ({
|
|
289
|
-
type: 'error',
|
|
290
|
-
error: await handle_error_and_jsonify(event, state, options, error),
|
|
291
|
-
status
|
|
292
|
-
}),
|
|
293
|
-
{
|
|
294
|
-
// By setting a non-200 during prerendering we fail the prerender process (unless handleHttpError handles it).
|
|
295
|
-
// Errors at runtime will be passed to the client and are handled there
|
|
296
|
-
status: state.prerendering ? status : undefined,
|
|
297
|
-
headers: {
|
|
298
|
-
'cache-control': 'private, no-store'
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/** @param {Map<string, Promise<any>> | null} map */
|
|
305
|
-
async function serialize_singleflight(map) {
|
|
306
|
-
if (!map || map.size === 0) {
|
|
307
|
-
return undefined;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
const results = await Promise.all(
|
|
311
|
-
Array.from(map, async ([key, promise]) => {
|
|
312
|
-
try {
|
|
313
|
-
return [key, { type: 'result', data: await promise }];
|
|
314
|
-
} catch (error) {
|
|
315
|
-
const status =
|
|
316
|
-
error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
|
317
|
-
|
|
318
|
-
return [
|
|
319
|
-
key,
|
|
320
|
-
{
|
|
321
|
-
type: 'error',
|
|
322
|
-
status,
|
|
323
|
-
error: await handle_error_and_jsonify(event, state, options, error)
|
|
324
|
-
}
|
|
325
|
-
];
|
|
326
|
-
}
|
|
327
|
-
})
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
return stringify(Object.fromEntries(results), transport);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* @param {string[] | undefined} refreshes
|
|
336
|
-
*/
|
|
337
|
-
function create_requested_map(refreshes) {
|
|
338
|
-
/** @type {Map<string, string[]>} */
|
|
339
|
-
const requested = new Map();
|
|
340
|
-
|
|
341
|
-
for (const key of refreshes ?? []) {
|
|
342
|
-
const parts = split_remote_key(key);
|
|
343
|
-
|
|
344
|
-
const existing = requested.get(parts.id);
|
|
345
|
-
|
|
346
|
-
if (existing) {
|
|
347
|
-
existing.push(parts.payload);
|
|
348
|
-
} else {
|
|
349
|
-
requested.set(parts.id, [parts.payload]);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
return requested;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/** @type {typeof handle_remote_form_post_internal} */
|
|
357
|
-
export async function handle_remote_form_post(event, state, manifest, id) {
|
|
358
|
-
return record_span({
|
|
359
|
-
name: 'sveltekit.remote.form.post',
|
|
360
|
-
attributes: {
|
|
361
|
-
'sveltekit.remote.form.post.id': id
|
|
362
|
-
},
|
|
363
|
-
fn: (current) => {
|
|
364
|
-
const traced_event = merge_tracing(event, current);
|
|
365
|
-
return with_request_store({ event: traced_event, state }, () =>
|
|
366
|
-
handle_remote_form_post_internal(traced_event, state, manifest, id)
|
|
367
|
-
);
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* @param {RequestEvent} event
|
|
374
|
-
* @param {RequestState} state
|
|
375
|
-
* @param {SSRManifest} manifest
|
|
376
|
-
* @param {string} id
|
|
377
|
-
* @returns {Promise<ActionResult>}
|
|
378
|
-
*/
|
|
379
|
-
async function handle_remote_form_post_internal(event, state, manifest, id) {
|
|
380
|
-
const [hash, name, action_id] = id.split('/');
|
|
381
|
-
const remotes = manifest._.remotes;
|
|
382
|
-
const module = await remotes[hash]?.();
|
|
383
|
-
|
|
384
|
-
let form = /** @type {RemoteForm<any, any>} */ (module?.default[name]);
|
|
385
|
-
|
|
386
|
-
if (!form) {
|
|
387
|
-
event.setHeaders({
|
|
388
|
-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
389
|
-
// "The server must generate an Allow header field in a 405 status code response"
|
|
390
|
-
allow: 'GET'
|
|
391
|
-
});
|
|
392
|
-
return {
|
|
393
|
-
type: 'error',
|
|
394
|
-
error: new SvelteKitError(
|
|
395
|
-
405,
|
|
396
|
-
'Method Not Allowed',
|
|
397
|
-
`POST method not allowed. No form actions exist for ${DEV ? `the page at ${event.route.id}` : 'this page'}`
|
|
398
|
-
)
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (action_id) {
|
|
403
|
-
// @ts-expect-error
|
|
404
|
-
form = with_request_store({ event, state }, () => form.for(JSON.parse(action_id)));
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
try {
|
|
408
|
-
const fn = /** @type {RemoteFormInternals} */ (/** @type {any} */ (form).__).fn;
|
|
409
|
-
|
|
410
|
-
const { data, meta, form_data } = await deserialize_binary_form(event.request);
|
|
411
|
-
|
|
412
|
-
if (action_id && !('id' in data)) {
|
|
413
|
-
data.id = JSON.parse(decodeURIComponent(action_id));
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
await with_request_store({ event, state }, () => fn(data, meta, form_data));
|
|
417
|
-
|
|
418
|
-
// We don't want the data to appear on `let { form } = $props()`, which is why we're not returning it.
|
|
419
|
-
// It is instead available on `myForm.result`, setting of which happens within the remote `form` function.
|
|
420
|
-
return {
|
|
421
|
-
type: 'success',
|
|
422
|
-
status: 200
|
|
423
|
-
};
|
|
424
|
-
} catch (e) {
|
|
425
|
-
const err = normalize_error(e);
|
|
426
|
-
|
|
427
|
-
if (err instanceof Redirect) {
|
|
428
|
-
return {
|
|
429
|
-
type: 'redirect',
|
|
430
|
-
status: err.status,
|
|
431
|
-
location: err.location
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return {
|
|
436
|
-
type: 'error',
|
|
437
|
-
error: check_incorrect_fail_use(err)
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* @param {URL} url
|
|
444
|
-
*/
|
|
445
|
-
export function get_remote_id(url) {
|
|
446
|
-
return (
|
|
447
|
-
url.pathname.startsWith(`${base}/${app_dir}/remote/`) &&
|
|
448
|
-
url.pathname.replace(`${base}/${app_dir}/remote/`, '')
|
|
449
|
-
);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* @param {URL} url
|
|
454
|
-
*/
|
|
455
|
-
export function get_remote_action(url) {
|
|
456
|
-
return url.searchParams.get('/remote');
|
|
457
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
This is a simple alias to `src/lib`, or whatever directory is specified as [`config.kit.files.lib`](https://svelte.dev/docs/kit/configuration#files). It allows you to access common components and utility modules without `../../../../` nonsense.
|
|
2
|
-
|
|
3
|
-
### `$lib/server`
|
|
4
|
-
|
|
5
|
-
A subdirectory of `$lib`. SvelteKit will prevent you from importing any modules in `$lib/server` into client-side code. See [server-only modules](https://svelte.dev/docs/kit/server-only-modules).
|
|
File without changes
|