@sveltejs/kit 2.27.3 → 2.29.0

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 (37) hide show
  1. package/package.json +1 -1
  2. package/src/core/config/index.js +11 -0
  3. package/src/core/config/options.js +30 -11
  4. package/src/core/postbuild/prerender.js +5 -0
  5. package/src/exports/index.js +3 -4
  6. package/src/exports/public.d.ts +40 -11
  7. package/src/exports/vite/build/build_remote.js +4 -4
  8. package/src/exports/vite/index.js +121 -70
  9. package/src/exports/vite/static_analysis/utils.js +101 -0
  10. package/src/exports/vite/utils.js +16 -0
  11. package/src/runtime/app/server/event.js +1 -0
  12. package/src/runtime/app/server/index.js +3 -2
  13. package/src/runtime/app/server/remote/command.js +5 -0
  14. package/src/runtime/app/server/remote/form.js +10 -0
  15. package/src/runtime/client/client.js +2 -2
  16. package/src/runtime/client/fetcher.js +3 -2
  17. package/src/runtime/client/remote-functions/command.svelte.js +91 -0
  18. package/src/runtime/client/remote-functions/form.svelte.js +29 -2
  19. package/src/runtime/client/remote-functions/index.js +1 -1
  20. package/src/runtime/client/remote-functions/shared.svelte.js +11 -14
  21. package/src/runtime/server/cookie.js +2 -1
  22. package/src/runtime/server/data/index.js +3 -4
  23. package/src/runtime/server/page/crypto.js +3 -58
  24. package/src/runtime/server/page/csp.js +2 -2
  25. package/src/runtime/server/page/load_data.js +6 -5
  26. package/src/runtime/server/page/render.js +3 -4
  27. package/src/runtime/server/remote.js +29 -33
  28. package/src/runtime/shared.js +8 -12
  29. package/src/runtime/utils.js +43 -33
  30. package/src/types/internal.d.ts +1 -1
  31. package/src/version.js +1 -1
  32. package/types/index.d.ts +42 -15
  33. package/types/index.d.ts.map +1 -1
  34. package/src/exports/vite/graph_analysis/index.js +0 -87
  35. package/src/exports/vite/graph_analysis/types.d.ts +0 -5
  36. package/src/exports/vite/graph_analysis/utils.js +0 -6
  37. package/src/runtime/client/remote-functions/command.js +0 -71
@@ -62,13 +62,7 @@ export async function handle_remote_call(event, options, manifest, id) {
62
62
  /** @type {RemoteFunctionResponse} */ ({
63
63
  type: 'result',
64
64
  result: stringify(data, transport),
65
- refreshes: stringify(
66
- {
67
- ...get_event_state(event).refreshes,
68
- ...(await apply_client_refreshes(/** @type {string[]} */ (form_client_refreshes)))
69
- },
70
- transport
71
- )
65
+ refreshes: await serialize_refreshes(/** @type {string[]} */ (form_client_refreshes))
72
66
  })
73
67
  );
74
68
  }
@@ -78,13 +72,12 @@ export async function handle_remote_call(event, options, manifest, id) {
78
72
  const { payload, refreshes } = await event.request.json();
79
73
  const arg = parse_remote_arg(payload, transport);
80
74
  const data = await with_event(event, () => fn(arg));
81
- const refreshed = await apply_client_refreshes(refreshes);
82
75
 
83
76
  return json(
84
77
  /** @type {RemoteFunctionResponse} */ ({
85
78
  type: 'result',
86
79
  result: stringify(data, transport),
87
- refreshes: stringify({ ...get_event_state(event).refreshes, ...refreshed }, transport)
80
+ refreshes: await serialize_refreshes(refreshes)
88
81
  })
89
82
  );
90
83
  }
@@ -107,14 +100,10 @@ export async function handle_remote_call(event, options, manifest, id) {
107
100
  );
108
101
  } catch (error) {
109
102
  if (error instanceof Redirect) {
110
- const refreshes = {
111
- ...(get_event_state(event).refreshes ?? {}), // could be set by form actions
112
- ...(await apply_client_refreshes(form_client_refreshes ?? []))
113
- };
114
103
  return json({
115
104
  type: 'redirect',
116
105
  location: error.location,
117
- refreshes: Object.keys(refreshes).length > 0 ? stringify(refreshes, transport) : undefined
106
+ refreshes: await serialize_refreshes(form_client_refreshes ?? [])
118
107
  });
119
108
  }
120
109
 
@@ -132,26 +121,33 @@ export async function handle_remote_call(event, options, manifest, id) {
132
121
  );
133
122
  }
134
123
 
135
- /** @param {string[]} refreshes */
136
- async function apply_client_refreshes(refreshes) {
137
- return Object.fromEntries(
138
- await Promise.all(
139
- refreshes.map(async (key) => {
140
- const [hash, name, payload] = key.split('/');
141
- const loader = manifest._.remotes[hash];
142
-
143
- // TODO what do we do in this case? erroring after the mutation has happened is not great
144
- if (!loader) error(400, 'Bad Request');
145
-
146
- const module = await loader();
147
- const fn = module[name];
148
-
149
- if (!fn) error(400, 'Bad Request');
150
-
151
- return [key, await with_event(event, () => fn(parse_remote_arg(payload, transport)))];
152
- })
124
+ /**
125
+ * @param {string[]} client_refreshes
126
+ */
127
+ async function serialize_refreshes(client_refreshes) {
128
+ const refreshes = {
129
+ ...get_event_state(event).refreshes,
130
+ ...Object.fromEntries(
131
+ await Promise.all(
132
+ client_refreshes.map(async (key) => {
133
+ const [hash, name, payload] = key.split('/');
134
+ const loader = manifest._.remotes[hash];
135
+
136
+ // TODO what do we do in this case? erroring after the mutation has happened is not great
137
+ if (!loader) error(400, 'Bad Request');
138
+
139
+ const module = await loader();
140
+ const fn = module[name];
141
+
142
+ if (!fn) error(400, 'Bad Request');
143
+
144
+ return [key, await with_event(event, () => fn(parse_remote_arg(payload, transport)))];
145
+ })
146
+ )
153
147
  )
154
- );
148
+ };
149
+
150
+ return Object.keys(refreshes).length > 0 ? stringify(refreshes, transport) : undefined;
155
151
  }
156
152
  }
157
153
 
@@ -1,5 +1,6 @@
1
1
  /** @import { Transport } from '@sveltejs/kit' */
2
2
  import * as devalue from 'devalue';
3
+ import { base64_decode, base64_encode, text_decoder } from './utils.js';
3
4
 
4
5
  /**
5
6
  * @param {string} route_id
@@ -41,12 +42,8 @@ export function stringify_remote_arg(value, transport) {
41
42
  // If people hit file/url size limits, we can look into using something like compress_and_encode_text from svelte.dev beyond a certain size
42
43
  const json_string = stringify(value, transport);
43
44
 
44
- // Convert to UTF-8 bytes, then base64 - handles all Unicode properly (btoa would fail on exotic characters)
45
- const utf8_bytes = new TextEncoder().encode(json_string);
46
- return btoa(String.fromCharCode(...utf8_bytes))
47
- .replace(/=/g, '')
48
- .replace(/\+/g, '-')
49
- .replace(/\//g, '_');
45
+ const bytes = new TextEncoder().encode(json_string);
46
+ return base64_encode(bytes).replaceAll('=', '').replaceAll('+', '-').replaceAll('/', '_');
50
47
  }
51
48
 
52
49
  /**
@@ -57,13 +54,12 @@ export function stringify_remote_arg(value, transport) {
57
54
  export function parse_remote_arg(string, transport) {
58
55
  if (!string) return undefined;
59
56
 
60
- const decoders = Object.fromEntries(Object.entries(transport).map(([k, v]) => [k, v.decode]));
57
+ const json_string = text_decoder.decode(
58
+ // no need to add back `=` characters, atob can handle it
59
+ base64_decode(string.replaceAll('-', '+').replaceAll('_', '/'))
60
+ );
61
61
 
62
- // We don't need to add back the `=`-padding because atob can handle it
63
- const base64_restored = string.replace(/-/g, '+').replace(/_/g, '/');
64
- const binary_string = atob(base64_restored);
65
- const utf8_bytes = new Uint8Array([...binary_string].map((char) => char.charCodeAt(0)));
66
- const json_string = new TextDecoder().decode(utf8_bytes);
62
+ const decoders = Object.fromEntries(Object.entries(transport).map(([k, v]) => [k, v.decode]));
67
63
 
68
64
  return devalue.parse(json_string, decoders);
69
65
  }
@@ -1,37 +1,7 @@
1
- /**
2
- * @param {string} text
3
- * @returns {ArrayBufferLike}
4
- */
5
- export function b64_decode(text) {
6
- const d = atob(text);
1
+ import { BROWSER } from 'esm-env';
7
2
 
8
- const u8 = new Uint8Array(d.length);
9
-
10
- for (let i = 0; i < d.length; i++) {
11
- u8[i] = d.charCodeAt(i);
12
- }
13
-
14
- return u8.buffer;
15
- }
16
-
17
- /**
18
- * @param {ArrayBuffer} buffer
19
- * @returns {string}
20
- */
21
- export function b64_encode(buffer) {
22
- if (globalThis.Buffer) {
23
- return Buffer.from(buffer).toString('base64');
24
- }
25
-
26
- const little_endian = new Uint8Array(new Uint16Array([1]).buffer)[0] > 0;
27
-
28
- // The Uint16Array(Uint8Array(...)) ensures the code points are padded with 0's
29
- return btoa(
30
- new TextDecoder(little_endian ? 'utf-16le' : 'utf-16be').decode(
31
- new Uint16Array(new Uint8Array(buffer))
32
- )
33
- );
34
- }
3
+ export const text_encoder = new TextEncoder();
4
+ export const text_decoder = new TextDecoder();
35
5
 
36
6
  /**
37
7
  * Like node's path.relative, but without using node
@@ -53,3 +23,43 @@ export function get_relative_path(from, to) {
53
23
 
54
24
  return from_parts.concat(to_parts).join('/');
55
25
  }
26
+
27
+ /**
28
+ * @param {Uint8Array} bytes
29
+ * @returns {string}
30
+ */
31
+ export function base64_encode(bytes) {
32
+ // Using `Buffer` is faster than iterating
33
+ if (!BROWSER && globalThis.Buffer) {
34
+ return globalThis.Buffer.from(bytes).toString('base64');
35
+ }
36
+
37
+ let binary = '';
38
+
39
+ for (let i = 0; i < bytes.length; i++) {
40
+ binary += String.fromCharCode(bytes[i]);
41
+ }
42
+
43
+ return btoa(binary);
44
+ }
45
+
46
+ /**
47
+ * @param {string} encoded
48
+ * @returns {Uint8Array}
49
+ */
50
+ export function base64_decode(encoded) {
51
+ // Using `Buffer` is faster than iterating
52
+ if (!BROWSER && globalThis.Buffer) {
53
+ const buffer = globalThis.Buffer.from(encoded, 'base64');
54
+ return new Uint8Array(buffer);
55
+ }
56
+
57
+ const binary = atob(encoded);
58
+ const bytes = new Uint8Array(binary.length);
59
+
60
+ for (let i = 0; i < binary.length; i++) {
61
+ bytes[i] = binary.charCodeAt(i);
62
+ }
63
+
64
+ return bytes;
65
+ }
@@ -302,7 +302,7 @@ export type RemoteFunctionResponse =
302
302
  type: 'result';
303
303
  result: string;
304
304
  /** devalue'd Record<string, any> */
305
- refreshes: string;
305
+ refreshes: string | undefined;
306
306
  };
307
307
 
308
308
  /**
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '2.27.3';
4
+ export const VERSION = '2.29.0';
package/types/index.d.ts CHANGED
@@ -397,26 +397,38 @@ declare module '@sveltejs/kit' {
397
397
  };
398
398
  /**
399
399
  * Where to find various files within your project.
400
+ * @deprecated
400
401
  */
401
402
  files?: {
403
+ /**
404
+ * the location of your source code
405
+ * @deprecated
406
+ * @default "src"
407
+ * @since 2.28
408
+ */
409
+ src?: string;
402
410
  /**
403
411
  * a place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json`
412
+ * @deprecated
404
413
  * @default "static"
405
414
  */
406
415
  assets?: string;
407
416
  hooks?: {
408
417
  /**
409
418
  * The location of your client [hooks](https://svelte.dev/docs/kit/hooks).
419
+ * @deprecated
410
420
  * @default "src/hooks.client"
411
421
  */
412
422
  client?: string;
413
423
  /**
414
424
  * The location of your server [hooks](https://svelte.dev/docs/kit/hooks).
425
+ * @deprecated
415
426
  * @default "src/hooks.server"
416
427
  */
417
428
  server?: string;
418
429
  /**
419
430
  * The location of your universal [hooks](https://svelte.dev/docs/kit/hooks).
431
+ * @deprecated
420
432
  * @default "src/hooks"
421
433
  * @since 2.3.0
422
434
  */
@@ -424,31 +436,37 @@ declare module '@sveltejs/kit' {
424
436
  };
425
437
  /**
426
438
  * your app's internal library, accessible throughout the codebase as `$lib`
439
+ * @deprecated
427
440
  * @default "src/lib"
428
441
  */
429
442
  lib?: string;
430
443
  /**
431
444
  * a directory containing [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching)
445
+ * @deprecated
432
446
  * @default "src/params"
433
447
  */
434
448
  params?: string;
435
449
  /**
436
450
  * the files that define the structure of your app (see [Routing](https://svelte.dev/docs/kit/routing))
451
+ * @deprecated
437
452
  * @default "src/routes"
438
453
  */
439
454
  routes?: string;
440
455
  /**
441
456
  * the location of your service worker's entry point (see [Service workers](https://svelte.dev/docs/kit/service-workers))
457
+ * @deprecated
442
458
  * @default "src/service-worker"
443
459
  */
444
460
  serviceWorker?: string;
445
461
  /**
446
462
  * the location of the template for HTML responses
463
+ * @deprecated
447
464
  * @default "src/app.html"
448
465
  */
449
466
  appTemplate?: string;
450
467
  /**
451
468
  * the location of the template for fallback error responses
469
+ * @deprecated
452
470
  * @default "src/error.html"
453
471
  */
454
472
  errorTemplate?: string;
@@ -997,12 +1015,15 @@ declare module '@sveltejs/kit' {
997
1015
  /**
998
1016
  * Information about the target of a specific navigation.
999
1017
  */
1000
- export interface NavigationTarget {
1018
+ export interface NavigationTarget<
1019
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
1020
+ RouteId extends AppRouteId | null = AppRouteId | null
1021
+ > {
1001
1022
  /**
1002
1023
  * Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
1003
1024
  * Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
1004
1025
  */
1005
- params: Record<string, string> | null;
1026
+ params: Params | null;
1006
1027
  /**
1007
1028
  * Info about the target route
1008
1029
  */
@@ -1010,7 +1031,7 @@ declare module '@sveltejs/kit' {
1010
1031
  /**
1011
1032
  * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
1012
1033
  */
1013
- id: string | null;
1034
+ id: RouteId | null;
1014
1035
  };
1015
1036
  /**
1016
1037
  * The URL that is navigated to
@@ -1020,8 +1041,8 @@ declare module '@sveltejs/kit' {
1020
1041
 
1021
1042
  /**
1022
1043
  * - `enter`: The app has hydrated/started
1023
- * - `form`: The user submitted a `<form>` with a GET method
1024
- * - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
1044
+ * - `form`: The user submitted a `<form method="GET">`
1045
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1025
1046
  * - `link`: Navigation was triggered by a link click
1026
1047
  * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1027
1048
  * - `popstate`: Navigation was triggered by back/forward navigation
@@ -1039,7 +1060,7 @@ declare module '@sveltejs/kit' {
1039
1060
  to: NavigationTarget | null;
1040
1061
  /**
1041
1062
  * The type of navigation:
1042
- * - `form`: The user submitted a `<form>`
1063
+ * - `form`: The user submitted a `<form method="GET">`
1043
1064
  * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1044
1065
  * - `link`: Navigation was triggered by a link click
1045
1066
  * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
@@ -1077,7 +1098,7 @@ declare module '@sveltejs/kit' {
1077
1098
  export interface OnNavigate extends Navigation {
1078
1099
  /**
1079
1100
  * The type of navigation:
1080
- * - `form`: The user submitted a `<form>`
1101
+ * - `form`: The user submitted a `<form method="GET">`
1081
1102
  * - `link`: Navigation was triggered by a link click
1082
1103
  * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1083
1104
  * - `popstate`: Navigation was triggered by back/forward navigation
@@ -1096,7 +1117,7 @@ declare module '@sveltejs/kit' {
1096
1117
  /**
1097
1118
  * The type of navigation:
1098
1119
  * - `enter`: The app has hydrated/started
1099
- * - `form`: The user submitted a `<form>`
1120
+ * - `form`: The user submitted a `<form method="GET">`
1100
1121
  * - `link`: Navigation was triggered by a link click
1101
1122
  * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1102
1123
  * - `popstate`: Navigation was triggered by back/forward navigation
@@ -1542,6 +1563,8 @@ declare module '@sveltejs/kit' {
1542
1563
  for(key: string | number | boolean): Omit<RemoteForm<Result>, 'for'>;
1543
1564
  /** The result of the form submission */
1544
1565
  get result(): Result | undefined;
1566
+ /** The number of pending submissions */
1567
+ get pending(): number;
1545
1568
  /** Spread this onto a `<button>` or `<input type="submit">` */
1546
1569
  buttonProps: {
1547
1570
  type: 'submit';
@@ -1563,14 +1586,20 @@ declare module '@sveltejs/kit' {
1563
1586
  formaction: string;
1564
1587
  onclick: (event: Event) => void;
1565
1588
  };
1589
+ /** The number of pending submissions */
1590
+ get pending(): number;
1566
1591
  };
1567
1592
  };
1568
1593
 
1569
1594
  /**
1570
1595
  * The return value of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
1571
1596
  */
1572
- export type RemoteCommand<Input, Output> = (arg: Input) => Promise<Awaited<Output>> & {
1573
- updates(...queries: Array<RemoteQuery<any> | RemoteQueryOverride>): Promise<Awaited<Output>>;
1597
+ export type RemoteCommand<Input, Output> = {
1598
+ (arg: Input): Promise<Awaited<Output>> & {
1599
+ updates(...queries: Array<RemoteQuery<any> | RemoteQueryOverride>): Promise<Awaited<Output>>;
1600
+ };
1601
+ /** The number of pending command executions */
1602
+ get pending(): number;
1574
1603
  };
1575
1604
 
1576
1605
  export type RemoteResource<T> = Promise<Awaited<T>> & {
@@ -1600,7 +1629,7 @@ declare module '@sveltejs/kit' {
1600
1629
  */
1601
1630
  refresh(): Promise<void>;
1602
1631
  /**
1603
- * Temporarily override the value of a query. This is used with the `updates` method of a [command](https://svelte.dev/docs/kit/remote-functions#command-Single-flight-mutations) or [enhanced form submission](https://svelte.dev/docs/kit/remote-functions#form-enhance) to provide optimistic updates.
1632
+ * Temporarily override the value of a query. This is used with the `updates` method of a [command](https://svelte.dev/docs/kit/remote-functions#command-Updating-queries) or [enhanced form submission](https://svelte.dev/docs/kit/remote-functions#form-enhance) to provide optimistic updates.
1604
1633
  *
1605
1634
  * ```svelte
1606
1635
  * <script>
@@ -2605,8 +2634,6 @@ declare module '$app/paths' {
2605
2634
  }
2606
2635
 
2607
2636
  declare module '$app/server' {
2608
- // @ts-ignore
2609
- import { LayoutParams as AppLayoutParams, RouteId as AppRouteId } from '$app/types'
2610
2637
  import type { RequestEvent, RemoteCommand, RemoteForm, RemotePrerenderFunction, RemoteQueryFunction } from '@sveltejs/kit';
2611
2638
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2612
2639
  /**
@@ -2627,8 +2654,8 @@ declare module '$app/server' {
2627
2654
  *
2628
2655
  * In environments without [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage), this must be called synchronously (i.e. not after an `await`).
2629
2656
  * @since 2.20.0
2630
- */
2631
- export function getRequestEvent(): RequestEvent<AppLayoutParams<"/">, any>;
2657
+ * */
2658
+ export function getRequestEvent(): RequestEvent;
2632
2659
  /**
2633
2660
  * Creates a remote command. When called from the browser, the function will be invoked on the server via a `fetch` call.
2634
2661
  *
@@ -185,6 +185,6 @@
185
185
  null,
186
186
  null
187
187
  ],
188
- "mappings": ";;;;;;;;;;kBAiCiBA,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;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AAOA",
189
189
  "ignoreList": []
190
190
  }
@@ -1,87 +0,0 @@
1
- import path from 'node:path';
2
- import { posixify } from '../../../utils/filesystem.js';
3
- import { normalize_id, strip_virtual_prefix } from '../utils.js';
4
- import { app_server, env_dynamic_private, env_static_private } from '../module_ids.js';
5
-
6
- const ILLEGAL_IMPORTS = new Set([env_dynamic_private, env_static_private, app_server]);
7
- const ILLEGAL_MODULE_NAME_PATTERN = /.*\.server\..+/;
8
-
9
- /**
10
- * Checks if given id imports a module that is not allowed to be imported into client-side code.
11
- * @param {string} id
12
- * @param {{
13
- * cwd: string;
14
- * node_modules: string;
15
- * server: string;
16
- * }} dirs
17
- */
18
- export function is_illegal(id, dirs) {
19
- if (ILLEGAL_IMPORTS.has(id)) return true;
20
- if (!id.startsWith(dirs.cwd) || id.startsWith(dirs.node_modules)) return false;
21
- return ILLEGAL_MODULE_NAME_PATTERN.test(path.basename(id)) || id.startsWith(dirs.server);
22
- }
23
-
24
- /**
25
- * Creates a guard that checks that no id imports a module that is not allowed to be imported into client-side code.
26
- * @param {import('vite').Rollup.PluginContext} context
27
- * @param {{ cwd: string; lib: string }} paths
28
- */
29
- export function module_guard(context, { cwd, lib }) {
30
- /** @type {Set<string>} */
31
- const seen = new Set();
32
-
33
- const dirs = {
34
- // ids will be posixified, so we need to posixify these, too
35
- cwd: posixify(cwd),
36
- node_modules: posixify(path.join(cwd, 'node_modules')),
37
- server: posixify(path.join(lib, 'server'))
38
- };
39
-
40
- /**
41
- * @param {string} id
42
- * @param {Array<{ id: string; dynamic: boolean }>} chain
43
- */
44
- function follow(id, chain) {
45
- if (seen.has(id)) return;
46
- seen.add(id);
47
-
48
- if (is_illegal(id, dirs)) {
49
- chain.shift(); // discard the entry point
50
- id = normalize_id(id, lib, cwd);
51
-
52
- const pyramid =
53
- chain.map(({ id, dynamic }, i) => {
54
- id = normalize_id(id, lib, cwd);
55
-
56
- return `${' '.repeat(i * 2)}- ${strip_virtual_prefix(id)} ${
57
- dynamic ? 'dynamically imports' : 'imports'
58
- }\n`;
59
- }) + `${' '.repeat(chain.length)}- ${strip_virtual_prefix(id)}`;
60
-
61
- const message = `Cannot import ${strip_virtual_prefix(
62
- id
63
- )} into client-side code:\n${pyramid}`;
64
-
65
- throw new Error(message);
66
- }
67
-
68
- const module = context.getModuleInfo(id);
69
-
70
- if (module) {
71
- for (const child of module.importedIds) {
72
- follow(child, [...chain, { id, dynamic: false }]);
73
- }
74
-
75
- for (const child of module.dynamicallyImportedIds) {
76
- follow(child, [...chain, { id, dynamic: true }]);
77
- }
78
- }
79
- }
80
-
81
- return {
82
- /** @param {string} id should be posixified */
83
- check: (id) => {
84
- follow(id, []);
85
- }
86
- };
87
- }
@@ -1,5 +0,0 @@
1
- export interface ImportGraph {
2
- readonly id: string;
3
- readonly dynamic: boolean;
4
- readonly children: Generator<ImportGraph>;
5
- }
@@ -1,6 +0,0 @@
1
- const query_pattern = /\?.*$/s;
2
-
3
- /** @param {string} path */
4
- export function remove_query_from_id(path) {
5
- return path.replace(query_pattern, '');
6
- }
@@ -1,71 +0,0 @@
1
- /** @import { RemoteCommand, RemoteQueryOverride } from '@sveltejs/kit' */
2
- /** @import { RemoteFunctionResponse } from 'types' */
3
- /** @import { Query } from './query.svelte.js' */
4
- import { app_dir, base } from '__sveltekit/paths';
5
- import * as devalue from 'devalue';
6
- import { HttpError } from '@sveltejs/kit/internal';
7
- import { app } from '../client.js';
8
- import { stringify_remote_arg } from '../../shared.js';
9
- import { refresh_queries, release_overrides } from './shared.svelte.js';
10
-
11
- /**
12
- * Client-version of the `command` function from `$app/server`.
13
- * @param {string} id
14
- * @returns {RemoteCommand<any, any>}
15
- */
16
- export function command(id) {
17
- // Careful: This function MUST be synchronous (can't use the async keyword) because the return type has to be a promise with an updates() method.
18
- // If we make it async, the return type will be a promise that resolves to a promise with an updates() method, which is not what we want.
19
- return (arg) => {
20
- /** @type {Array<Query<any> | RemoteQueryOverride>} */
21
- let updates = [];
22
-
23
- /** @type {Promise<any> & { updates: (...args: any[]) => any }} */
24
- const promise = (async () => {
25
- // Wait a tick to give room for the `updates` method to be called
26
- await Promise.resolve();
27
-
28
- const response = await fetch(`${base}/${app_dir}/remote/${id}`, {
29
- method: 'POST',
30
- body: JSON.stringify({
31
- payload: stringify_remote_arg(arg, app.hooks.transport),
32
- refreshes: updates.map((u) => u._key)
33
- }),
34
- headers: {
35
- 'Content-Type': 'application/json'
36
- }
37
- });
38
-
39
- if (!response.ok) {
40
- release_overrides(updates);
41
- // We only end up here in case of a network error or if the server has an internal error
42
- // (which shouldn't happen because we handle errors on the server and always send a 200 response)
43
- throw new Error('Failed to execute remote function');
44
- }
45
-
46
- const result = /** @type {RemoteFunctionResponse} */ (await response.json());
47
- if (result.type === 'redirect') {
48
- release_overrides(updates);
49
- throw new Error(
50
- 'Redirects are not allowed in commands. Return a result instead and use goto on the client'
51
- );
52
- } else if (result.type === 'error') {
53
- release_overrides(updates);
54
- throw new HttpError(result.status ?? 500, result.error);
55
- } else {
56
- refresh_queries(result.refreshes, updates);
57
-
58
- return devalue.parse(result.result, app.decoders);
59
- }
60
- })();
61
-
62
- promise.updates = (/** @type {any} */ ...args) => {
63
- updates = args;
64
- // @ts-expect-error Don't allow updates to be called multiple times
65
- delete promise.updates;
66
- return promise;
67
- };
68
-
69
- return promise;
70
- };
71
- }