@sveltejs/kit 1.17.1 → 1.19.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 (64) hide show
  1. package/package.json +6 -1
  2. package/src/core/adapt/builder.js +3 -3
  3. package/src/core/config/index.js +2 -2
  4. package/src/core/config/options.js +8 -3
  5. package/src/core/env.js +1 -1
  6. package/src/core/generate_manifest/index.js +2 -2
  7. package/src/core/postbuild/analyse.js +3 -3
  8. package/src/core/postbuild/fallback.js +1 -1
  9. package/src/core/postbuild/prerender.js +1 -1
  10. package/src/core/sync/create_manifest_data/index.js +2 -2
  11. package/src/core/sync/write_ambient.js +1 -1
  12. package/src/core/sync/write_client_manifest.js +1 -1
  13. package/src/core/sync/write_server.js +2 -1
  14. package/src/core/sync/write_types/index.js +24 -24
  15. package/src/exports/hooks/sequence.js +71 -7
  16. package/src/exports/index.js +88 -12
  17. package/src/exports/node/index.js +14 -3
  18. package/src/exports/node/polyfills.js +8 -0
  19. package/src/exports/public.d.ts +1264 -0
  20. package/src/exports/vite/build/build_server.js +2 -2
  21. package/src/exports/vite/build/build_service_worker.js +1 -1
  22. package/src/exports/vite/dev/index.js +3 -3
  23. package/src/exports/vite/index.js +11 -6
  24. package/src/runtime/app/environment.js +3 -4
  25. package/src/runtime/app/forms.js +63 -7
  26. package/src/runtime/app/navigation.js +95 -0
  27. package/src/runtime/app/stores.js +28 -7
  28. package/src/runtime/client/client.js +26 -14
  29. package/src/runtime/client/singletons.js +6 -4
  30. package/src/runtime/client/start.js +1 -1
  31. package/src/runtime/client/types.d.ts +4 -12
  32. package/src/runtime/client/utils.js +29 -10
  33. package/src/runtime/control.js +12 -9
  34. package/src/runtime/server/ambient.d.ts +3 -3
  35. package/src/runtime/server/cookie.js +3 -3
  36. package/src/runtime/server/data/index.js +5 -4
  37. package/src/runtime/server/endpoint.js +11 -4
  38. package/src/runtime/server/fetch.js +4 -6
  39. package/src/runtime/server/index.js +2 -2
  40. package/src/runtime/server/page/actions.js +13 -13
  41. package/src/runtime/server/page/csp.js +7 -2
  42. package/src/runtime/server/page/index.js +6 -5
  43. package/src/runtime/server/page/load_data.js +20 -9
  44. package/src/runtime/server/page/render.js +11 -11
  45. package/src/runtime/server/page/respond_with_error.js +4 -3
  46. package/src/runtime/server/respond.js +6 -6
  47. package/src/runtime/server/utils.js +7 -7
  48. package/src/types/ambient-private.d.ts +11 -0
  49. package/src/types/ambient.d.ts +108 -0
  50. package/{types → src/types}/internal.d.ts +4 -13
  51. package/{types → src/types}/private.d.ts +1 -10
  52. package/src/utils/error.js +3 -3
  53. package/src/utils/exports.js +2 -2
  54. package/src/utils/routing.js +1 -39
  55. package/src/utils/streaming.js +2 -2
  56. package/types/index.d.ts +2081 -1100
  57. package/types/index.d.ts.map +165 -0
  58. package/src/internal.d.ts +0 -16
  59. package/types/ambient.d.ts +0 -486
  60. /package/{types → src/types}/synthetic/$env+dynamic+private.md +0 -0
  61. /package/{types → src/types}/synthetic/$env+dynamic+public.md +0 -0
  62. /package/{types → src/types}/synthetic/$env+static+private.md +0 -0
  63. /package/{types → src/types}/synthetic/$env+static+public.md +0 -0
  64. /package/{types → src/types}/synthetic/$lib.md +0 -0
@@ -65,7 +65,7 @@ export function static_error_page(options, status, message) {
65
65
  }
66
66
 
67
67
  /**
68
- * @param {import('types').RequestEvent} event
68
+ * @param {import('@sveltejs/kit').RequestEvent} event
69
69
  * @param {import('types').SSROptions} options
70
70
  * @param {unknown} error
71
71
  */
@@ -74,7 +74,7 @@ export async function handle_fatal_error(event, options, error) {
74
74
  const status = error instanceof HttpError ? error.status : 500;
75
75
  const body = await handle_error_and_jsonify(event, options, error);
76
76
 
77
- // ideally we'd use sec-fetch-dest instead, but Safari — quelle surprise — doesn't support it
77
+ // ideally we'd use sec-fetch-dest instead, but Safari — quelle surprise — doesn't support it
78
78
  const type = negotiate(event.request.headers.get('accept') || 'text/html', [
79
79
  'application/json',
80
80
  'text/html'
@@ -90,7 +90,7 @@ export async function handle_fatal_error(event, options, error) {
90
90
  }
91
91
 
92
92
  /**
93
- * @param {import('types').RequestEvent} event
93
+ * @param {import('@sveltejs/kit').RequestEvent} event
94
94
  * @param {import('types').SSROptions} options
95
95
  * @param {any} error
96
96
  * @returns {Promise<App.Error>}
@@ -132,7 +132,7 @@ export function redirect_response(status, location) {
132
132
  }
133
133
 
134
134
  /**
135
- * @param {import('types').RequestEvent} event
135
+ * @param {import('@sveltejs/kit').RequestEvent} event
136
136
  * @param {Error & { path: string }} error
137
137
  */
138
138
  export function clarify_devalue_error(event, error) {
@@ -162,9 +162,9 @@ export function stringify_uses(node) {
162
162
  uses.push(`"params":${JSON.stringify(Array.from(node.uses.params))}`);
163
163
  }
164
164
 
165
- if (node.uses?.parent) uses.push(`"parent":1`);
166
- if (node.uses?.route) uses.push(`"route":1`);
167
- if (node.uses?.url) uses.push(`"url":1`);
165
+ if (node.uses?.parent) uses.push('"parent":1');
166
+ if (node.uses?.route) uses.push('"route":1');
167
+ if (node.uses?.url) uses.push('"url":1');
168
168
 
169
169
  return `"uses":{${uses.join(',')}}`;
170
170
  }
@@ -0,0 +1,11 @@
1
+ declare global {
2
+ const __SVELTEKIT_ADAPTER_NAME__: string;
3
+ const __SVELTEKIT_APP_VERSION_FILE__: string;
4
+ const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
5
+ const __SVELTEKIT_DEV__: boolean;
6
+ const __SVELTEKIT_EMBEDDED__: boolean;
7
+ var Bun: object;
8
+ var Deno: object;
9
+ }
10
+
11
+ export {};
@@ -0,0 +1,108 @@
1
+ /**
2
+ * It's possible to tell SvelteKit how to type objects inside your app by declaring the `App` namespace. By default, a new project will have a file called `src/app.d.ts` containing the following:
3
+ *
4
+ * ```ts
5
+ * declare global {
6
+ * namespace App {
7
+ * // interface Error {}
8
+ * // interface Locals {}
9
+ * // interface PageData {}
10
+ * // interface Platform {}
11
+ * }
12
+ * }
13
+ *
14
+ * export {};
15
+ * ```
16
+ *
17
+ * The `export {}` line exists because without it, the file would be treated as an _ambient module_ which prevents you from adding `import` declarations.
18
+ * If you need to add ambient `declare module` declarations, do so in a separate file like `src/ambient.d.ts`.
19
+ *
20
+ * By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, and `data` from `load` functions.
21
+ */
22
+ declare namespace App {
23
+ /**
24
+ * Defines the common shape of expected and unexpected errors. Expected errors are thrown using the `error` function. Unexpected errors are handled by the `handleError` hooks which should return this shape.
25
+ */
26
+ export interface Error {
27
+ message: string;
28
+ }
29
+
30
+ /**
31
+ * The interface that defines `event.locals`, which can be accessed in [hooks](https://kit.svelte.dev/docs/hooks) (`handle`, and `handleError`), server-only `load` functions, and `+server.js` files.
32
+ */
33
+ export interface Locals {}
34
+
35
+ /**
36
+ * Defines the common shape of the [$page.data store](https://kit.svelte.dev/docs/modules#$app-stores-page) - that is, the data that is shared between all pages.
37
+ * The `Load` and `ServerLoad` functions in `./$types` will be narrowed accordingly.
38
+ * Use optional properties for data that is only present on specific pages. Do not add an index signature (`[key: string]: any`).
39
+ */
40
+ export interface PageData {}
41
+
42
+ /**
43
+ * If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#platform-specific-context) via `event.platform`, you can specify it here.
44
+ */
45
+ export interface Platform {}
46
+ }
47
+
48
+ /**
49
+ * This module is only available to [service workers](https://kit.svelte.dev/docs/service-workers).
50
+ */
51
+ declare module '$service-worker' {
52
+ /**
53
+ * The `base` path of the deployment. Typically this is equivalent to `config.kit.paths.base`, but it is calculated from `location.pathname` meaning that it will continue to work correctly if the site is deployed to a subdirectory.
54
+ * Note that there is a `base` but no `assets`, since service workers cannot be used if `config.kit.paths.assets` is specified.
55
+ */
56
+ export const base: string;
57
+ /**
58
+ * An array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`.
59
+ * During development, this is an empty array.
60
+ */
61
+ export const build: string[];
62
+ /**
63
+ * An array of URL strings representing the files in your static directory, or whatever directory is specified by `config.kit.files.assets`. You can customize which files are included from `static` directory using [`config.kit.serviceWorker.files`](https://kit.svelte.dev/docs/configuration)
64
+ */
65
+ export const files: string[];
66
+ /**
67
+ * An array of pathnames corresponding to prerendered pages and endpoints.
68
+ * During development, this is an empty array.
69
+ */
70
+ export const prerendered: string[];
71
+ /**
72
+ * See [`config.kit.version`](https://kit.svelte.dev/docs/configuration#version). It's useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches.
73
+ */
74
+ export const version: string;
75
+ }
76
+
77
+ /** Internal version of $app/environment */
78
+ declare module '__sveltekit/environment' {
79
+ /**
80
+ * SvelteKit analyses your app during the `build` step by running it. During this process, `building` is `true`. This also applies during prerendering.
81
+ */
82
+ export const building: boolean;
83
+ /**
84
+ * The value of `config.kit.version.name`.
85
+ */
86
+ export const version: string;
87
+ export function set_building(): void;
88
+ }
89
+
90
+ /** Internal version of $app/paths */
91
+ declare module '__sveltekit/paths' {
92
+ /**
93
+ * A string that matches [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths).
94
+ *
95
+ * Example usage: `<a href="{base}/your-page">Link</a>`
96
+ */
97
+ export let base: '' | `/${string}`;
98
+ /**
99
+ * An absolute path that matches [`config.kit.paths.assets`](https://kit.svelte.dev/docs/configuration#paths).
100
+ *
101
+ * > If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
102
+ */
103
+ export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets';
104
+ export let relative: boolean | undefined; // TODO in 2.0, make this a `boolean` that defaults to `true`
105
+ export function reset(): void;
106
+ export function override(paths: { base: string; assets: string }): void;
107
+ export function set_assets(path: string): void;
108
+ }
@@ -13,7 +13,7 @@ import {
13
13
  HandleFetch,
14
14
  Actions,
15
15
  HandleClientError
16
- } from './index.js';
16
+ } from '@sveltejs/kit';
17
17
  import {
18
18
  HttpMethod,
19
19
  MaybePromise,
@@ -333,6 +333,7 @@ export interface SSROptions {
333
333
  app_template_contains_nonce: boolean;
334
334
  csp: ValidatedConfig['kit']['csp'];
335
335
  csrf_check_origin: boolean;
336
+ track_server_fetches: boolean;
336
337
  embedded: boolean;
337
338
  env_public_prefix: string;
338
339
  hooks: ServerHooks;
@@ -411,15 +412,5 @@ export type ValidatedConfig = RecursiveRequired<Config>;
411
412
 
412
413
  export type ValidatedKitConfig = RecursiveRequired<KitConfig>;
413
414
 
414
- export * from './index';
415
- export * from './private';
416
-
417
- declare global {
418
- const __SVELTEKIT_ADAPTER_NAME__: string;
419
- const __SVELTEKIT_APP_VERSION_FILE__: string;
420
- const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
421
- const __SVELTEKIT_DEV__: boolean;
422
- const __SVELTEKIT_EMBEDDED__: boolean;
423
- var Bun: object;
424
- var Deno: object;
425
- }
415
+ export * from '../exports/index';
416
+ export * from './private.js';
@@ -2,7 +2,7 @@
2
2
  // but which cannot be imported from `@sveltejs/kit`. Care should
3
3
  // be taken to avoid breaking changes when editing this file
4
4
 
5
- import { RouteDefinition } from './index.js';
5
+ import { RouteDefinition } from '@sveltejs/kit';
6
6
 
7
7
  export interface AdapterEntry {
8
8
  /**
@@ -233,12 +233,3 @@ export interface RouteSegment {
233
233
  }
234
234
 
235
235
  export type TrailingSlash = 'never' | 'always' | 'ignore';
236
-
237
- /**
238
- * This doesn't actually exist, it's a way to better distinguish the type
239
- */
240
- declare const uniqueSymbol: unique symbol;
241
-
242
- export interface UniqueInterface {
243
- readonly [uniqueSymbol]: unknown;
244
- }
@@ -1,5 +1,3 @@
1
- import { HttpError, Redirect } from '../runtime/control.js';
2
-
3
1
  /**
4
2
  * @param {unknown} err
5
3
  * @return {Error}
@@ -18,5 +16,7 @@ export function coalesce_to_error(err) {
18
16
  * @param {unknown} error
19
17
  */
20
18
  export function normalize_error(error) {
21
- return /** @type {Redirect | HttpError | Error} */ (error);
19
+ return /** @type {import('../runtime/control.js').Redirect | import('../runtime/control.js').HttpError | Error} */ (
20
+ error
21
+ );
22
22
  }
@@ -31,7 +31,7 @@ function validator(expected) {
31
31
  * @returns {string | void}
32
32
  */
33
33
  function hint_for_supported_files(key, ext = '.js') {
34
- let supported_files = [];
34
+ const supported_files = [];
35
35
 
36
36
  if (valid_layout_exports.has(key)) {
37
37
  supported_files.push(`+layout${ext}`);
@@ -54,7 +54,7 @@ function hint_for_supported_files(key, ext = '.js') {
54
54
  }
55
55
 
56
56
  if (supported_files.length > 0) {
57
- return `'${key}' is a valid export in ${supported_files.slice(0, -1).join(`, `)}${
57
+ return `'${key}' is a valid export in ${supported_files.slice(0, -1).join(', ')}${
58
58
  supported_files.length > 1 ? ' or ' : ''
59
59
  }${supported_files.at(-1)}`;
60
60
  }
@@ -96,44 +96,6 @@ export function parse_route_id(id) {
96
96
  return { pattern, params };
97
97
  }
98
98
 
99
- const basic_param_pattern = /\[(\[)?(?:\.\.\.)?(\w+?)(?:=(\w+))?\]\]?/g;
100
-
101
- /**
102
- * Parses a route ID, then resolves it to a path by replacing parameters with actual values from `entry`.
103
- * @param {string} id The route id
104
- * @param {Record<string, string | undefined>} entry The entry meant to populate the route. For example, if the route is `/blog/[slug]`, the entry would be `{ slug: 'hello-world' }`
105
- * @example
106
- * ```js
107
- * resolve_entry(`/blog/[slug]/[...somethingElse]`, { slug: 'hello-world', somethingElse: 'something/else' }); // `/blog/hello-world/something/else`
108
- * ```
109
- */
110
- export function resolve_entry(id, entry) {
111
- const segments = get_route_segments(id);
112
- return (
113
- '/' +
114
- segments
115
- .map((segment) =>
116
- segment.replace(basic_param_pattern, (_, optional, name) => {
117
- const param_value = entry[name];
118
-
119
- // This is nested so TS correctly narrows the type
120
- if (!param_value) {
121
- if (optional) return '';
122
- throw new Error(`Missing parameter '${name}' in route ${id}`);
123
- }
124
-
125
- if (param_value.startsWith('/') || param_value.endsWith('/'))
126
- throw new Error(
127
- `Parameter '${name}' in route ${id} cannot start or end with a slash -- this would cause an invalid route like foo//bar`
128
- );
129
- return param_value;
130
- })
131
- )
132
- .filter(Boolean)
133
- .join('/')
134
- );
135
- }
136
-
137
99
  const optional_param_regex = /\/\[\[\w+?(?:=\w+)?\]\]/;
138
100
 
139
101
  /**
@@ -167,7 +129,7 @@ export function get_route_segments(route) {
167
129
  /**
168
130
  * @param {RegExpMatchArray} match
169
131
  * @param {import('types').RouteParam[]} params
170
- * @param {Record<string, import('types').ParamMatcher>} matchers
132
+ * @param {Record<string, import('@sveltejs/kit').ParamMatcher>} matchers
171
133
  */
172
134
  export function exec(match, params, matchers) {
173
135
  /** @type {Record<string, string>} */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @returns {import("types").Deferred & { promise: Promise<any> }}}
2
+ * @returns {import('types').Deferred & { promise: Promise<any> }}}
3
3
  */
4
4
  function defer() {
5
5
  let fulfil;
@@ -23,7 +23,7 @@ function defer() {
23
23
  * }}
24
24
  */
25
25
  export function create_async_iterator() {
26
- let deferred = [defer()];
26
+ const deferred = [defer()];
27
27
 
28
28
  return {
29
29
  iterator: {