@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.
Files changed (127) hide show
  1. package/package.json +33 -21
  2. package/src/core/adapt/builder.js +29 -43
  3. package/src/core/adapt/index.js +1 -4
  4. package/src/core/config/index.js +132 -71
  5. package/src/core/config/options.js +294 -244
  6. package/src/core/config/types.d.ts +1 -1
  7. package/src/core/env.js +121 -5
  8. package/src/core/generate_manifest/index.js +12 -15
  9. package/src/core/postbuild/analyse.js +7 -19
  10. package/src/core/postbuild/crawl.js +22 -6
  11. package/src/core/postbuild/prerender.js +42 -23
  12. package/src/core/sync/create_manifest_data/index.js +53 -50
  13. package/src/core/sync/sync.js +0 -2
  14. package/src/core/sync/write_client_manifest.js +8 -15
  15. package/src/core/sync/write_env.js +2 -1
  16. package/src/core/sync/write_non_ambient.js +12 -9
  17. package/src/core/sync/write_server.js +13 -14
  18. package/src/core/sync/write_tsconfig.js +16 -8
  19. package/src/core/sync/write_tsconfig_test/package.json +7 -0
  20. package/src/core/sync/write_types/index.js +28 -24
  21. package/src/core/utils.js +2 -2
  22. package/src/exports/env/index.js +12 -0
  23. package/src/exports/hooks/index.js +3 -9
  24. package/src/exports/hooks/sequence.js +3 -2
  25. package/src/exports/index.js +35 -13
  26. package/src/exports/internal/client.js +5 -0
  27. package/src/exports/internal/env.js +2 -2
  28. package/src/exports/internal/index.js +1 -90
  29. package/src/exports/internal/{event.js → server/event.js} +1 -2
  30. package/src/exports/internal/server/index.js +33 -0
  31. package/src/exports/internal/shared.js +89 -0
  32. package/src/exports/node/index.js +62 -15
  33. package/src/exports/params.js +63 -0
  34. package/src/exports/public.d.ts +323 -170
  35. package/src/exports/url.js +86 -0
  36. package/src/exports/vite/build/build_server.js +53 -59
  37. package/src/exports/vite/build/remote.js +18 -11
  38. package/src/exports/vite/build/utils.js +0 -8
  39. package/src/exports/vite/dev/index.js +42 -44
  40. package/src/exports/vite/index.js +810 -593
  41. package/src/exports/vite/preview/index.js +29 -22
  42. package/src/exports/vite/static_analysis/index.js +2 -4
  43. package/src/exports/vite/static_analysis/types.d.ts +14 -0
  44. package/src/exports/vite/utils.js +21 -36
  45. package/src/runtime/app/env/internal.js +4 -4
  46. package/src/runtime/app/env/types.d.ts +1 -1
  47. package/src/runtime/app/environment/index.js +6 -0
  48. package/src/runtime/app/forms.js +24 -7
  49. package/src/runtime/app/paths/client.js +4 -10
  50. package/src/runtime/app/paths/internal/client.js +4 -2
  51. package/src/runtime/app/paths/internal/server.js +2 -23
  52. package/src/runtime/app/paths/public.d.ts +0 -28
  53. package/src/runtime/app/paths/server.js +9 -5
  54. package/src/runtime/app/server/remote/command.js +0 -3
  55. package/src/runtime/app/server/remote/form.js +27 -15
  56. package/src/runtime/app/server/remote/prerender.js +29 -36
  57. package/src/runtime/app/server/remote/query.js +101 -99
  58. package/src/runtime/app/server/remote/requested.js +22 -14
  59. package/src/runtime/app/server/remote/shared.js +30 -26
  60. package/src/runtime/app/state/client.js +1 -2
  61. package/src/runtime/app/stores.js +13 -76
  62. package/src/runtime/client/bundle.js +1 -1
  63. package/src/runtime/client/client-entry.js +3 -0
  64. package/src/runtime/client/client.js +411 -318
  65. package/src/runtime/client/entry.js +24 -3
  66. package/src/runtime/client/fetcher.js +3 -2
  67. package/src/runtime/client/ndjson.js +6 -33
  68. package/src/runtime/client/payload.js +17 -0
  69. package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
  70. package/src/runtime/client/remote-functions/command.svelte.js +7 -32
  71. package/src/runtime/client/remote-functions/form.svelte.js +183 -112
  72. package/src/runtime/client/remote-functions/prerender.svelte.js +29 -8
  73. package/src/runtime/client/remote-functions/query/index.js +7 -14
  74. package/src/runtime/client/remote-functions/query/instance.svelte.js +63 -18
  75. package/src/runtime/client/remote-functions/query/proxy.js +3 -3
  76. package/src/runtime/client/remote-functions/query-batch.svelte.js +60 -68
  77. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +60 -18
  78. package/src/runtime/client/remote-functions/query-live/iterator.js +36 -55
  79. package/src/runtime/client/remote-functions/shared.svelte.js +88 -62
  80. package/src/runtime/client/sse.js +32 -0
  81. package/src/runtime/client/state.svelte.js +65 -49
  82. package/src/runtime/client/stream.js +38 -0
  83. package/src/runtime/client/types.d.ts +11 -7
  84. package/src/runtime/client/utils.js +0 -96
  85. package/src/runtime/components/root.svelte +66 -0
  86. package/src/runtime/env/dynamic/private.js +7 -0
  87. package/src/runtime/env/dynamic/public.js +7 -0
  88. package/src/runtime/env/static/private.js +6 -0
  89. package/src/runtime/env/static/public.js +6 -0
  90. package/src/runtime/form-utils.js +100 -22
  91. package/src/runtime/server/cookie.js +69 -52
  92. package/src/runtime/server/csrf.js +65 -0
  93. package/src/runtime/server/data/index.js +14 -18
  94. package/src/runtime/server/env_module.js +0 -5
  95. package/src/runtime/server/index.js +2 -2
  96. package/src/runtime/server/page/actions.js +41 -26
  97. package/src/runtime/server/page/index.js +9 -15
  98. package/src/runtime/server/page/load_data.js +1 -1
  99. package/src/runtime/server/page/render.js +112 -187
  100. package/src/runtime/server/page/respond_with_error.js +7 -8
  101. package/src/runtime/server/page/server_routing.js +27 -18
  102. package/src/runtime/server/remote.js +355 -216
  103. package/src/runtime/server/respond.js +97 -61
  104. package/src/runtime/server/utils.js +32 -9
  105. package/src/runtime/shared.js +83 -13
  106. package/src/runtime/telemetry/otel.js +1 -1
  107. package/src/runtime/types.d.ts +8 -0
  108. package/src/types/ambient.d.ts +10 -5
  109. package/src/types/global-private.d.ts +15 -22
  110. package/src/types/internal.d.ts +89 -74
  111. package/src/types/private.d.ts +33 -1
  112. package/src/utils/error.js +24 -4
  113. package/src/utils/import.js +6 -1
  114. package/src/utils/imports.js +83 -0
  115. package/src/utils/mime.js +9 -0
  116. package/src/utils/params.js +66 -0
  117. package/src/utils/routing.js +90 -44
  118. package/src/utils/shared-iterator.js +5 -0
  119. package/src/utils/streaming.js +14 -4
  120. package/src/utils/url.js +20 -2
  121. package/src/version.js +1 -1
  122. package/types/index.d.ts +467 -537
  123. package/types/index.d.ts.map +22 -39
  124. package/src/core/sync/write_root.js +0 -148
  125. package/src/exports/internal/server.js +0 -22
  126. package/src/types/synthetic/$lib.md +0 -5
  127. /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 { get_status, normalize_error } from '../../../utils/error.js';
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: await handle_error_and_jsonify(event, event_state, options, no_actions_error)
44
+ error
43
45
  },
44
46
  {
45
- status: no_actions_error.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
- type: 'failure',
67
- status: data.status,
68
- // @ts-expect-error we assign a string to what is supposed to be an object. That's ok
69
- // because we don't use the object outside, and this way we have better code navigation
70
- // through knowing where the related interface is used.
71
- data: stringify_action_response(
72
- data.data,
73
- /** @type {string} */ (event.route.id),
74
- options.hooks.transport
75
- )
76
- });
77
- } else {
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: data ? 200 : 204,
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: await handle_error_and_jsonify(
100
- event,
101
- event_state,
102
- options,
103
- check_incorrect_fail_use(err)
104
- )
116
+ error: transformed
105
117
  },
106
118
  {
107
- status: get_status(err)
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
- const action = actions[name];
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, SSRComponent, SSRNode, SSROptions, SSRState } from 'types' */
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(options, ssr, branch, page, manifest)
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(options, ssr, branch, page, manifest) {
408
- /** @type {Array<SSRComponent | undefined> | undefined} */
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 (options.server_error_boundaries && ssr) {
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
  }