@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
@@ -1,3 +1,24 @@
1
- // we expose this as a separate entry point (rather than treating client.js as the entry point)
2
- // so that everything other than `start`/`load_css` can be treeshaken
3
- export { start, load_css } from './client.js';
1
+ /* in development or if `bundleStrategy` is 'split', this file is used as the entry point */
2
+
3
+ import { set_payload } from './payload.js';
4
+
5
+ /** @type {Promise<typeof import('./client-entry.js')>} */
6
+ let client;
7
+
8
+ /** @param {import('types').SvelteKitPayload} payload */
9
+ export function init(payload) {
10
+ set_payload(payload);
11
+ // Importing the client after setting the payload ensures that modules such as
12
+ // `$app/paths` can read it during initialization.
13
+ client ??= import('./client-entry.js');
14
+ }
15
+
16
+ /** @param {Parameters<import('./client-entry.js').start>} args */
17
+ export async function start(...args) {
18
+ return (await client).start(...args);
19
+ }
20
+
21
+ /** @param {Parameters<import('./client-entry.js').load_css>} args */
22
+ export async function load_css(...args) {
23
+ return (await client).load_css(...args);
24
+ }
@@ -94,8 +94,6 @@ export function initial_fetch(resource, opts) {
94
94
  script.remove(); // In case multiple script tags match the same selector
95
95
  let { body, ...init } = JSON.parse(script.textContent);
96
96
 
97
- const ttl = script.getAttribute('data-ttl');
98
- if (ttl) cache.set(selector, { body, init, ttl: 1000 * Number(ttl) });
99
97
  const b64 = script.getAttribute('data-b64');
100
98
  if (b64 !== null) {
101
99
  // Can't use native_fetch('data:...;base64,${body}')
@@ -103,6 +101,9 @@ export function initial_fetch(resource, opts) {
103
101
  body = base64_decode(body);
104
102
  }
105
103
 
104
+ const ttl = script.getAttribute('data-ttl');
105
+ if (ttl) cache.set(selector, { body, init, ttl: 1000 * Number(ttl) });
106
+
106
107
  return Promise.resolve(new Response(body, init));
107
108
  }
108
109
 
@@ -1,42 +1,15 @@
1
+ import { read_stream } from './stream.js';
2
+
1
3
  /**
2
4
  * Yields parsed JSON objects from a ReadableStream of newline-delimited JSON.
3
5
  * Each yielded value is the raw `JSON.parse`'d object — callers handle deserialization.
4
6
  * @param {ReadableStreamDefaultReader<Uint8Array>} reader
5
7
  */
6
8
  export async function* read_ndjson(reader) {
7
- let done = false;
8
- let buffer = '';
9
- const decoder = new TextDecoder();
10
-
11
- while (true) {
12
- let split = buffer.indexOf('\n');
13
- while (split !== -1) {
14
- const line = buffer.slice(0, split).trim();
15
- buffer = buffer.slice(split + 1);
16
-
17
- if (line) {
18
- yield JSON.parse(line);
19
- }
20
-
21
- split = buffer.indexOf('\n');
22
- }
23
-
24
- if (done) {
25
- const line = buffer.trim();
26
- if (line) {
27
- yield JSON.parse(line);
28
- }
29
- return;
30
- }
31
-
32
- const chunk = await reader.read();
33
- done = chunk.done;
34
- if (chunk.value) {
35
- buffer += decoder.decode(chunk.value, { stream: true });
36
- }
37
-
38
- if (done) {
39
- buffer += decoder.decode();
9
+ for await (const block of read_stream(reader, '\n')) {
10
+ const line = block.trim();
11
+ if (line) {
12
+ yield JSON.parse(line);
40
13
  }
41
14
  }
42
15
  }
@@ -0,0 +1,17 @@
1
+ /** @import {SvelteKitPayload} from 'types'; */
2
+
3
+ /**
4
+ * Code inside the SvelteKit client runtime should only use this, not the global,
5
+ * so that the file hashes stay stable between rebuilds as long as the SvelteKit runtime doesn't change
6
+ */
7
+ export let payload = __SVELTEKIT_PAYLOAD__ ?? /** @type {SvelteKitPayload} */ ({});
8
+
9
+ /** @param {SvelteKitPayload} value */
10
+ export function set_payload(value) {
11
+ payload = value;
12
+ }
13
+
14
+ // this makes Vite inject its dev client code as this module's first dependency
15
+ // so that global constant replacements are done before any other module evaluates.
16
+ // For build, it's inert.
17
+ import.meta.hot;
@@ -1,8 +1,10 @@
1
+ /** @import { Query } from './query/instance.svelte.js' */
2
+ /** @import { LiveQuery } from './query-live/instance.svelte.js' */
1
3
  import { tick } from 'svelte';
2
4
  import { once } from '../../../utils/functions.js';
3
5
 
4
6
  /**
5
- * @template R
7
+ * @template [R=Query<any> | LiveQuery<any>]
6
8
  * @typedef {object} CacheEntry
7
9
  * @property {number} proxy_count The number of live proxy instances referencing this
8
10
  * entry. The entry is eligible for eviction when this hits zero.
@@ -1,16 +1,8 @@
1
1
  /** @import { RemoteCommand, RemoteQueryUpdate } from '@sveltejs/kit' */
2
- /** @import { RemoteFunctionResponse } from 'types' */
3
2
  import { app_dir, base } from '$app/paths/internal/client';
4
- import * as devalue from 'devalue';
5
- import { HttpError } from '@sveltejs/kit/internal';
6
3
  import { app } from '../client.js';
7
- import { stringify_remote_arg } from '../../shared.js';
8
- import {
9
- get_remote_request_headers,
10
- apply_refreshes,
11
- categorize_updates,
12
- apply_reconnections
13
- } from './shared.svelte.js';
4
+ import { stringify_command_arg } from '../../shared.js';
5
+ import { get_remote_request_headers, categorize_updates, remote_request } from './shared.svelte.js';
14
6
 
15
7
  /**
16
8
  * Client-version of the `command` function from `$app/server`.
@@ -53,39 +45,22 @@ export function command(id) {
53
45
  throw updates_error;
54
46
  }
55
47
 
56
- const response = await fetch(`${base}/${app_dir}/remote/${id}`, {
48
+ const response = await remote_request(`${base}/${app_dir}/remote/${id}`, {
57
49
  method: 'POST',
58
50
  body: JSON.stringify({
59
- payload: stringify_remote_arg(arg, app.hooks.transport, false),
51
+ payload: await stringify_command_arg(arg, app.hooks.transport),
60
52
  refreshes: Array.from(refreshes ?? [])
61
53
  }),
62
54
  headers
63
55
  });
64
56
 
65
- if (!response.ok) {
66
- // We only end up here in case of a network error or if the server has an internal error
67
- // (which shouldn't happen because we handle errors on the server and always send a 200 response)
68
- throw new Error('Failed to execute remote function');
69
- }
70
-
71
- const result = /** @type {RemoteFunctionResponse} */ (await response.json());
72
- if (result.type === 'redirect') {
57
+ if (response.redirect) {
73
58
  throw new Error(
74
59
  'Redirects are not allowed in commands. Return a result instead and use goto on the client'
75
60
  );
76
- } else if (result.type === 'error') {
77
- throw new HttpError(result.status ?? 500, result.error);
78
- } else {
79
- if (result.refreshes) {
80
- apply_refreshes(result.refreshes);
81
- }
82
-
83
- if (result.reconnects) {
84
- apply_reconnections(result.reconnects);
85
- }
86
-
87
- return devalue.parse(result.result, app.decoders);
88
61
  }
62
+
63
+ return response._;
89
64
  } finally {
90
65
  overrides?.forEach((fn) => fn());
91
66