@sveltejs/kit 3.0.0-next.19 → 3.0.0-next.20

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 (44) hide show
  1. package/package.json +12 -12
  2. package/src/core/adapt/builder.js +2 -1
  3. package/src/core/adapt/index.js +1 -1
  4. package/src/core/env.js +1 -1
  5. package/src/core/postbuild/prerender.js +61 -8
  6. package/src/core/sync/write_env.js +1 -1
  7. package/src/core/sync/write_server.js +2 -2
  8. package/src/core/sync/write_tsconfig/index.js +1 -3
  9. package/src/core/sync/write_tsconfig/utils.js +0 -24
  10. package/src/exports/env/index.js +1 -1
  11. package/src/exports/env/public.d.ts +55 -0
  12. package/src/exports/hooks/public.d.ts +194 -0
  13. package/src/exports/hooks/sequence.js +4 -3
  14. package/src/exports/index.js +1 -1
  15. package/src/exports/internal/env.js +1 -1
  16. package/src/exports/params/public.d.ts +2 -2
  17. package/src/exports/public.d.ts +1 -757
  18. package/src/exports/vite/dev/index.js +2 -2
  19. package/src/exports/vite/index.js +541 -384
  20. package/src/exports/vite/utils.js +0 -16
  21. package/src/runtime/app/internal/transport.js +1 -1
  22. package/src/runtime/app/server/public.d.ts +519 -0
  23. package/src/runtime/app/server/remote/command.js +1 -1
  24. package/src/runtime/app/server/remote/form.js +1 -1
  25. package/src/runtime/app/server/remote/prerender.js +1 -1
  26. package/src/runtime/app/server/remote/query.js +2 -1
  27. package/src/runtime/app/server/remote/requested.js +1 -1
  28. package/src/runtime/client/client.js +1 -1
  29. package/src/runtime/client/remote-functions/command.svelte.js +1 -1
  30. package/src/runtime/client/remote-functions/form.svelte.js +1 -1
  31. package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
  32. package/src/runtime/client/remote-functions/query/index.js +1 -1
  33. package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
  34. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  35. package/src/runtime/client/remote-functions/shared.svelte.js +1 -1
  36. package/src/runtime/server/errors.js +2 -2
  37. package/src/runtime/server/internal.js +39 -0
  38. package/src/runtime/server/page/load_data.js +1 -1
  39. package/src/runtime/server/remote-functions.js +17 -5
  40. package/src/runtime/server/respond.js +1 -1
  41. package/src/types/internal.d.ts +14 -13
  42. package/src/version.js +1 -1
  43. package/types/index.d.ts +1403 -1403
  44. package/types/index.d.ts.map +68 -62
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "3.0.0-next.19",
3
+ "version": "3.0.0-next.20",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -19,30 +19,30 @@
19
19
  "type": "module",
20
20
  "dependencies": {
21
21
  "@standard-schema/spec": "^1.1.0",
22
- "@sveltejs/acorn-typescript": "^1.0.10",
23
- "acorn": "^8.17.0",
24
- "cookie": "^2.0.0",
25
- "devalue": "^5.8.1",
22
+ "@sveltejs/acorn-typescript": "^1.0.12",
23
+ "acorn": "^8.18.0",
24
+ "cookie": "^2.0.1",
25
+ "devalue": "^5.9.0",
26
26
  "esm-env": "^1.2.2",
27
- "magic-string": "^0.30.21",
28
- "mrmime": "^2.0.0",
27
+ "magic-string": "^1.1.0",
28
+ "mrmime": "^2.0.1",
29
29
  "sirv": "^3.0.2"
30
30
  },
31
31
  "devDependencies": {
32
- "@opentelemetry/api": "^1.9.0",
32
+ "@opentelemetry/api": "^1.9.1",
33
33
  "@playwright/test": "^1.62.0",
34
- "@sveltejs/vite-plugin-svelte": "^7.0.0",
34
+ "@sveltejs/vite-plugin-svelte": "^7.3.0",
35
35
  "@types/connect": "^3.4.38",
36
36
  "@typescript/native": "npm:typescript@^7.0.2",
37
37
  "@types/node": "^22.19.19",
38
38
  "dts-buddy": "^0.8.3",
39
39
  "jsdom": "^30.0.0",
40
- "rolldown": "^1.2.0",
41
- "svelte": "^5.56.3",
40
+ "rolldown": "^1.2.3",
41
+ "svelte": "^5.56.8",
42
42
  "svelte-preprocess": "^6.0.5",
43
43
  "typescript": "~6.0.3",
44
44
  "valibot": "^1.4.2",
45
- "vite": "^8.1.5",
45
+ "vite": "^8.2.1",
46
46
  "vitest": "^4.1.10"
47
47
  },
48
48
  "peerDependencies": {
@@ -1,7 +1,8 @@
1
1
  /** @import { StandardSchemaV1 } from '@standard-schema/spec' */
2
2
  /** @import { Builder } from '@sveltejs/kit' */
3
3
  /** @import { ResolvedConfig } from 'vite' */
4
- /** @import { RouteDefinition, EnvVarConfig } from '@sveltejs/kit' */
4
+ /** @import { RouteDefinition } from '@sveltejs/kit' */
5
+ /** @import { EnvVarConfig } from '@sveltejs/kit/env' */
5
6
  /** @import { RouteData, ValidatedConfig, BuildData, ServerMetadata, ServerMetadataRoute, Prerendered, PrerenderMap, Logger, RemoteChunk } from 'types' */
6
7
  import { loadEnv } from 'vite';
7
8
  import * as devalue from 'devalue';
@@ -10,7 +10,7 @@ import { create_builder } from './builder.js';
10
10
  * @param {import('types').Logger} log
11
11
  * @param {import('types').RemoteChunk[]} remotes
12
12
  * @param {import('vite').ResolvedConfig} vite_config
13
- * @param {Record<string, import('@sveltejs/kit').EnvVarConfig<any>> | null} explicit_env_config
13
+ * @param {Record<string, import('@sveltejs/kit/env').EnvVarConfig<any>> | null} explicit_env_config
14
14
  */
15
15
  export async function adapt(
16
16
  config,
package/src/core/env.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** @import { StandardSchemaV1 } from '@standard-schema/spec' */
2
- /** @import { EnvVarConfig } from '@sveltejs/kit' */
2
+ /** @import { EnvVarConfig } from '@sveltejs/kit/env' */
3
3
  /** @import { ValidatedKitConfig } from 'types' */
4
4
  import path from 'node:path';
5
5
  import * as devalue from 'devalue';
@@ -1,5 +1,7 @@
1
+ import process from 'node:process';
1
2
  import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
2
3
  import { dirname, join } from 'node:path';
4
+ import { clearLine, moveCursor } from 'node:readline';
3
5
  import { pathToFileURL } from 'node:url';
4
6
  import { walk } from '../../utils/filesystem.js';
5
7
  import { posixify } from '../../utils/os.js';
@@ -16,7 +18,6 @@ import * as devalue from 'devalue';
16
18
  import { createReadableStream } from '@sveltejs/kit/node';
17
19
  import generate_fallback from './fallback.js';
18
20
  import { stringify_remote_arg } from '../../runtime/shared.js';
19
- import { log_response } from '../../exports/vite/utils.js';
20
21
  import { matches_content_type } from '../../utils/http.js';
21
22
 
22
23
  export default forked(import.meta.url, prerender);
@@ -36,19 +37,30 @@ const SPECIAL_HASHLINKS = new Set(['', 'top']);
36
37
  * verbose: boolean;
37
38
  * env: Record<string, string>;
38
39
  * vite_config_file: string | undefined;
40
+ * is_tty: boolean | undefined;
39
41
  * }} opts
40
42
  */
41
- async function prerender({ hash, out, manifest_path, metadata, verbose, env, vite_config_file }) {
43
+ async function prerender({
44
+ hash,
45
+ out,
46
+ manifest_path,
47
+ metadata,
48
+ verbose,
49
+ env,
50
+ vite_config_file,
51
+ is_tty
52
+ }) {
42
53
  /** @type {import('@sveltejs/kit').SSRManifest} */
43
54
  const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
44
55
 
45
56
  /** @type {import('types').ServerInternalModule} */
46
- const internal = await import(pathToFileURL(`${out}/server/internal.js`).href);
57
+ const { set_building, set_prerendering, set_manifest, set_read_implementation, log_response } =
58
+ await import(pathToFileURL(`${out}/server/internal.js`).href);
47
59
 
48
60
  // configure `import { building } from `$app/env` —
49
61
  // essential we do this before analysing the code
50
- internal.set_building();
51
- internal.set_prerendering();
62
+ set_building();
63
+ set_prerendering();
52
64
 
53
65
  // `set_env` and `Server` live in modules that import the user's `src/env` config. We import them
54
66
  // *after* `set_building()` so that `building`-dependent expressions resolve correctly
@@ -263,6 +275,45 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
263
275
  /** @type {Map<string, Promise<any>>} */
264
276
  const remote_responses = new Map();
265
277
 
278
+ /** @type {(path: string) => void} */
279
+ let progress_line = noop;
280
+
281
+ if (is_tty) {
282
+ // Where possible, provide progress feedback by showing the path we're
283
+ // currently requesting, then clearing the line once the response comes in.
284
+ // This avoids the wall of text that happens when you prerender
285
+ // many pages and log each response
286
+ let current = false;
287
+ const stdout_write = process.stdout.write;
288
+ const stderr_write = process.stderr.write;
289
+
290
+ process.stdout.write = new Proxy(stdout_write, {
291
+ apply(target, this_arg, args) {
292
+ current = false;
293
+ return Reflect.apply(target, this_arg, args);
294
+ }
295
+ });
296
+
297
+ process.stderr.write = new Proxy(stderr_write, {
298
+ apply(target, this_arg, args) {
299
+ current = false;
300
+ return Reflect.apply(target, this_arg, args);
301
+ }
302
+ });
303
+
304
+ progress_line = (path) => {
305
+ // If app code writes to stdout or stderr, don't move the cursor to clear
306
+ // the previous progress log, because that will corrupt things
307
+ if (current) {
308
+ moveCursor(process.stdout, 0, -1);
309
+ clearLine(process.stdout, 0);
310
+ }
311
+
312
+ stdout_write.call(process.stdout, `rendering ${path}...\n`);
313
+ current = true;
314
+ };
315
+ }
316
+
266
317
  /** @type {Set<string>} */
267
318
  const resolved_route_ids = new Set();
268
319
 
@@ -303,6 +354,8 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
303
354
  /** @type {Map<string, import('types').PrerenderDependency>} */
304
355
  const dependencies = new Map();
305
356
 
357
+ progress_line(decoded);
358
+
306
359
  const request = new Request(prerender_origin + encoded);
307
360
 
308
361
  const response = await server.respond(request, {
@@ -344,7 +397,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
344
397
  });
345
398
  }
346
399
 
347
- if (response.status !== 204) {
400
+ if (response.status >= 400) {
348
401
  log_response(response.status, request);
349
402
  }
350
403
 
@@ -574,8 +627,8 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
574
627
 
575
628
  // the user's remote function modules may reference `read` or the `manifest` at the top-level
576
629
  // so we need to set them before evaluating those modules to avoid potential runtime errors
577
- internal.set_manifest(manifest);
578
- internal.set_read_implementation((file) => createReadableStream(`${out}/server/${file}`));
630
+ set_manifest(manifest);
631
+ set_read_implementation((file) => createReadableStream(`${out}/server/${file}`));
579
632
 
580
633
  /** @type {Array<import('types').RemotePrerenderInternals>} */
581
634
  const prerender_functions = [];
@@ -1,4 +1,4 @@
1
- /** @import { EnvVarConfig } from '@sveltejs/kit' */
1
+ /** @import { EnvVarConfig } from '@sveltejs/kit/env' */
2
2
  import path from 'node:path';
3
3
  import { create_explicit_env_types } from '../env.js';
4
4
  import { write_if_changed } from './utils.js';
@@ -25,7 +25,7 @@ const server_template = ({
25
25
  }) => `
26
26
  import { set_building, set_prerendering } from '$app/env/internal';
27
27
  import { set_assets } from '$app/paths/internal/server';
28
- import { set_fix_stack_trace, set_manifest, set_read_implementation } from '__sveltekit/server';
28
+ import { set_fix_stack_trace, set_manifest, set_read_implementation, log_response } from '__sveltekit/server';
29
29
  import error from '../shared/error-template.js';
30
30
 
31
31
  export const options = {
@@ -78,7 +78,7 @@ export async function get_hooks() {
78
78
  };
79
79
  }
80
80
 
81
- export { set_assets, set_building, set_fix_stack_trace, set_manifest, set_prerendering, set_read_implementation };
81
+ export { set_assets, set_building, set_fix_stack_trace, set_manifest, set_prerendering, set_read_implementation, log_response };
82
82
  `;
83
83
 
84
84
  /**
@@ -6,7 +6,6 @@ import { styleText } from 'node:util';
6
6
  import { write_if_changed } from '../utils.js';
7
7
  import {
8
8
  ESSENTIAL_OPTIONS,
9
- get_subpath_imports,
10
9
  normalize_config,
11
10
  RECOMMENDED_OPTIONS,
12
11
  remove_trailing_slashstar
@@ -243,8 +242,7 @@ const alias_value = /^(.+?)((\/\*)|(\.\w+))?$/;
243
242
  */
244
243
  function get_paths(config, root) {
245
244
  const alias = {
246
- ...config.alias,
247
- ...get_subpath_imports(root)
245
+ ...config.alias
248
246
  };
249
247
 
250
248
  /** @type {Record<string, string[]>} */
@@ -1,5 +1,4 @@
1
1
  import path from 'node:path';
2
- import { normalize_import_value, read_package_imports } from '../../../utils/imports.js';
3
2
  import { posixify } from '../../../utils/os.js';
4
3
 
5
4
  /**
@@ -76,26 +75,3 @@ export function remove_trailing_slashstar(file) {
76
75
  return file;
77
76
  }
78
77
  }
79
-
80
- /**
81
- * @param {string} root
82
- */
83
- export function get_subpath_imports(root) {
84
- // Add all `#`-prefixed imports from package.json as path aliases
85
- const imports = read_package_imports(root);
86
-
87
- /** @type {Record<string, string>} */
88
- const alias = {};
89
-
90
- if (imports) {
91
- for (const [key, raw_value] of Object.entries(imports)) {
92
- if (!key.startsWith('#')) continue;
93
- const value = normalize_import_value(raw_value);
94
- if (value) {
95
- alias[key] = value;
96
- }
97
- }
98
- }
99
-
100
- return alias;
101
- }
@@ -1,5 +1,5 @@
1
1
  /** @import { StandardSchemaV1 } from '@standard-schema/spec' */
2
- /** @import { DefinedEnvVars, EnvVarConfig } from '@sveltejs/kit' */
2
+ /** @import { DefinedEnvVars, EnvVarConfig } from '@sveltejs/kit/env' */
3
3
 
4
4
  /**
5
5
  * Utility for defining [environment variables](https://svelte.dev/docs/kit/environment-variables),
@@ -0,0 +1,55 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+
3
+ export * from './index.js';
4
+
5
+ /**
6
+ * [Environment variables](https://svelte.dev/docs/kit/environment-variables) can be configured by exporting
7
+ * a `variables` object from `src/env.ts`, using [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
8
+ */
9
+ export interface EnvVarConfig<T> {
10
+ /**
11
+ * Whether the environment variable can be accessed by client-side code.
12
+ * - if `true`, it can be imported from `$app/env/public`
13
+ * - if `false`, it can be imported from `$app/env/private`, which is a [server-only module](https://svelte.dev/docs/kit/server-only-modules)
14
+ * @default false
15
+ */
16
+ public?: boolean;
17
+ /**
18
+ * Whether the value is determined at build time or when the app runs.
19
+ * - if `true`, the build time value is inlined into the bundle. This enables optimisations like dead-code elimination
20
+ * - if `false`, the value is read from the environment when the app starts
21
+ * @default false
22
+ */
23
+ static?: boolean;
24
+ /**
25
+ * A [Standard Schema](https://standardschema.dev/) validator that is applied to the value when the app starts.
26
+ * Alternatively, a function that returns the (possibly transformed) value, or throws an error explaining
27
+ * the problem. Returning `undefined` is valid, so a function can describe an optional variable.
28
+ * The validator can output any value — not necessarily a string — but public, non-static values must be
29
+ * serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
30
+ *
31
+ * If omitted, the value must be set, but may be an empty string.
32
+ */
33
+ schema?: StandardSchemaV1<string | undefined, T> | ((value: string | undefined) => T | undefined);
34
+ /**
35
+ * A description of the variable that will be used for inline documentation on hover.
36
+ */
37
+ description?: string;
38
+ }
39
+
40
+ /**
41
+ * The return type of [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
42
+ */
43
+ export type DefinedEnvVars<T extends Record<string, EnvVarConfig<any>>> = {
44
+ readonly [K in keyof T]: EnvVarEntry<T[K]>;
45
+ };
46
+
47
+ /**
48
+ * Normalizes an environment variable config's schema (standard schema or function) to standard schema.
49
+ */
50
+ type EnvVarEntry<C extends EnvVarConfig<any>> =
51
+ C['schema'] extends StandardSchemaV1<any, any>
52
+ ? C
53
+ : C['schema'] extends (value: any) => infer R
54
+ ? Omit<C, 'schema'> & { schema: StandardSchemaV1<string | undefined, R> }
55
+ : C;
@@ -0,0 +1,194 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import { NavigationEvent, RequestEvent } from '@sveltejs/kit';
3
+ import { MaybePromise } from 'types';
4
+
5
+ export * from './index.js';
6
+
7
+ /**
8
+ * The [`handle`](https://svelte.dev/docs/kit/hooks#handle) hook runs every time the SvelteKit server receives a [request](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Request) and
9
+ * determines the [response](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Response).
10
+ * It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
11
+ * This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
12
+ */
13
+ export type Handle = (input: {
14
+ event: RequestEvent;
15
+ resolve: (event: RequestEvent, opts?: ResolveOptions) => Promise<Response>;
16
+ }) => MaybePromise<Response>;
17
+
18
+ type CaughtErrorMap = {
19
+ app: App.Error;
20
+ framework: { status: number; message: string };
21
+ unknown: unknown;
22
+ };
23
+
24
+ type ValidationCaughtError<Issue extends StandardSchemaV1.Issue> = {
25
+ kind: 'validation';
26
+ error: { status: number; message: string };
27
+ issues: Issue[];
28
+ };
29
+
30
+ /**
31
+ * The error passed to the [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hooks.
32
+ * Use the `kind` discriminant to distinguish errors from your app (thrown with the
33
+ * [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper), errors generated by
34
+ * SvelteKit itself (such as 404s), validation errors, and unknown errors (thrown by your code,
35
+ * or code it calls).
36
+ */
37
+ export type CaughtError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
38
+ | {
39
+ [Kind in keyof CaughtErrorMap]: {
40
+ /** Identifies the category and origin of the error */
41
+ kind: Kind;
42
+ /** The caught error. Its type depends on `kind` */
43
+ error: CaughtErrorMap[Kind];
44
+ /** Only present for validation errors */
45
+ issues?: undefined;
46
+ };
47
+ }[keyof CaughtErrorMap]
48
+ | ValidationCaughtError<Issue>;
49
+
50
+ /** The error passed to the client-side `handleError` hook. */
51
+ export type ClientCaughtError = Exclude<CaughtError, { kind: 'validation' }>;
52
+
53
+ /**
54
+ * The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs for every error thrown while responding to a request, except redirects.
55
+ *
56
+ * The `kind` property discriminates between _app_ errors (thrown with the [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper),
57
+ * _framework_ errors (generated by SvelteKit itself, such as 404s), _validation_ errors (caused by invalid remote function arguments)
58
+ * and _unknown_ errors (thrown by your code, or code it calls).
59
+ *
60
+ * The hook returns an object matching `App.Error`, in which `status` and `message` are optional — return them only to
61
+ * override the defaults. Omitted properties are inherited from the caught error: the body passed to `error(...)` for app errors,
62
+ * the status and safe message for framework and validation errors, and `500`/`'Internal Error'` for unknown errors. Return nothing to
63
+ * keep the defaults entirely (if you augment `App.Error` with required properties, you must return those).
64
+ *
65
+ * Make sure that this function _never_ throws an error.
66
+ */
67
+ export type HandleServerError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> = (
68
+ input: CaughtError<Issue> & { event: RequestEvent }
69
+ ) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
70
+
71
+ /**
72
+ * The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs for every error thrown while navigating, except redirects.
73
+ * Errors that were already transformed by the server-side hook are not passed to it a second time.
74
+ *
75
+ * The `kind` property discriminates between _app_ errors (thrown with the [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper),
76
+ * _framework_ errors (generated by SvelteKit itself, such as 404s) and _unknown_ errors (thrown by your code, or code it calls).
77
+ *
78
+ * The hook returns an object matching `App.Error`, in which `status` and `message` are optional — return them only to
79
+ * override the defaults. Omitted properties are inherited from the caught error: the body passed to `error(...)` for app errors,
80
+ * the status and safe message for framework errors, and `500`/`'Internal Error'` for unknown errors. Return nothing to
81
+ * keep the defaults entirely (if you augment `App.Error` with required properties, you must return those).
82
+ *
83
+ * Make sure that this function _never_ throws an error.
84
+ */
85
+ export type HandleClientError = (
86
+ input: ClientCaughtError & { event: NavigationEvent }
87
+ ) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
88
+
89
+ /**
90
+ * The [`handleFetch`](https://svelte.dev/docs/kit/hooks#handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
91
+ */
92
+ export type HandleFetch = (input: {
93
+ event: RequestEvent;
94
+ request: Request;
95
+ fetch: typeof fetch;
96
+ }) => MaybePromise<Response>;
97
+
98
+ /**
99
+ * The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked before the server responds to its first request
100
+ * @since 2.10.0
101
+ */
102
+ export type ServerInit = () => MaybePromise<void>;
103
+
104
+ /**
105
+ * The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked once the app starts in the browser
106
+ * @since 2.10.0
107
+ */
108
+ export type ClientInit = () => MaybePromise<void>;
109
+
110
+ /**
111
+ * The [`reroute`](https://svelte.dev/docs/kit/hooks#reroute) hook allows you to modify the URL before it is used to determine which route to render.
112
+ * @since 2.3.0
113
+ */
114
+ export type Reroute = (event: { url: URL; fetch: typeof fetch }) => MaybePromise<void | string>;
115
+
116
+ /**
117
+ * The [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook allows you to transport custom types across the server/client boundary.
118
+ *
119
+ * Each transporter has a pair of `encode` and `decode` functions. On the server, `encode` determines whether a value is an instance of the custom type and, if so, returns a non-falsy encoding of the value which can be an object or an array (or `false` otherwise).
120
+ *
121
+ * In the browser, `decode` turns the encoding back into an instance of the custom type.
122
+ *
123
+ * ```ts
124
+ * import type { Transport } from '@sveltejs/kit/hooks';
125
+ *
126
+ * declare class MyCustomType {
127
+ * data: any
128
+ * }
129
+ *
130
+ * // hooks.js
131
+ * export const transport: Transport = {
132
+ * MyCustomType: {
133
+ * encode: (value) => value instanceof MyCustomType && [value.data],
134
+ * decode: ([data]) => new MyCustomType(data)
135
+ * }
136
+ * };
137
+ * ```
138
+ * @since 2.11.0
139
+ */
140
+ export type Transport = Record<string, Transporter>;
141
+
142
+ /**
143
+ * A member of the [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook.
144
+ */
145
+ export interface Transporter<
146
+ T = any,
147
+ U = any /* minus falsy values, but we can't properly express that */
148
+ > {
149
+ encode: (value: T) => false | U;
150
+ decode: (data: U) => T;
151
+ }
152
+
153
+ export interface ResolveOptions {
154
+ /**
155
+ * Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
156
+ * (they could include an element's opening tag but not its closing tag, for example)
157
+ * but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
158
+ * @param input the html chunk and the info if this is the last chunk
159
+ */
160
+ transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
161
+ /**
162
+ * Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
163
+ * By default, none will be included.
164
+ * @param name header name
165
+ * @param value header value
166
+ */
167
+ filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
168
+ /**
169
+ * Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
170
+ * `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
171
+ * [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
172
+ * By default, `js` and `css` files will be preloaded.
173
+ * @param input the type of the file and its path
174
+ */
175
+ preload?: (input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }) => boolean;
176
+ }
177
+
178
+ type AppErrorWithOptionalDefaults = Omit<App.Error, 'status' | 'message'> & {
179
+ status?: App.Error['status'];
180
+ message?: App.Error['message'];
181
+ };
182
+
183
+ /**
184
+ * `void` is only a valid `handleError` return when `App.Error` adds no required properties
185
+ * beyond `status` and `message` — both of which are optional in the return, since they default
186
+ * to those of the caught error. If `App.Error` is augmented with required properties, the hook
187
+ * must return them, so returning nothing becomes a type error.
188
+ */
189
+ type VoidIfNoRequiredAppErrorProperties = {
190
+ status: number;
191
+ message: string;
192
+ } extends App.Error
193
+ ? void
194
+ : never;
@@ -1,4 +1,5 @@
1
- /** @import { Handle, RequestEvent, ResolveOptions } from '@sveltejs/kit' */
1
+ /** @import { RequestEvent } from '@sveltejs/kit' */
2
+ /** @import { Handle, ResolveOptions } from '@sveltejs/kit/hooks' */
2
3
  import {
3
4
  merge_tracing,
4
5
  get_request_store,
@@ -17,7 +18,7 @@ import {
17
18
  * /// file: src/hooks.server.js
18
19
  * import { sequence } from '@sveltejs/kit/hooks';
19
20
  *
20
- * /// type: import('@sveltejs/kit').Handle
21
+ * /// type: import('@sveltejs/kit/hooks').Handle
21
22
  * async function first({ event, resolve }) {
22
23
  * console.log('first pre-processing');
23
24
  * const result = await resolve(event, {
@@ -36,7 +37,7 @@ import {
36
37
  * return result;
37
38
  * }
38
39
  *
39
- * /// type: import('@sveltejs/kit').Handle
40
+ * /// type: import('@sveltejs/kit/hooks').Handle
40
41
  * async function second({ event, resolve }) {
41
42
  * console.log('second pre-processing');
42
43
  * const result = await resolve(event, {
@@ -273,7 +273,7 @@ export function invalid(...issues) {
273
273
  /**
274
274
  * Checks whether this is an validation error thrown by {@link invalid}.
275
275
  * @param {unknown} e The object to check.
276
- * @return {e is import('./public.js').ActionFailure}
276
+ * @return {e is import('$app/server').ValidationError}
277
277
  * @since 2.47.3
278
278
  */
279
279
  export function isValidationError(e) {
@@ -1,5 +1,5 @@
1
1
  /** @import { StandardSchemaV1 } from '@standard-schema/spec' */
2
- /** @import { EnvVarConfig } from '@sveltejs/kit' */
2
+ /** @import { EnvVarConfig } from '@sveltejs/kit/env' */
3
3
 
4
4
  import { stackless } from '../../utils/error.js';
5
5
 
@@ -11,14 +11,14 @@ export type ParamMatcher<Output = any> = StandardSchemaV1<string, Output>;
11
11
  export type ParamValue = string | number | boolean | bigint;
12
12
 
13
13
  /**
14
- * A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
14
+ * A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit-params#defineParams).
15
15
  */
16
16
  export type ParamDefinition =
17
17
  | ((param: string) => ParamValue | undefined)
18
18
  | StandardSchemaV1<string, ParamValue>;
19
19
 
20
20
  /**
21
- * The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit#defineParams).
21
+ * The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit-params#defineParams).
22
22
  */
23
23
  export type DefinedParams<T extends Record<string, ParamDefinition>> = {
24
24
  readonly [K in keyof T]: ParamEntry<T[K]>;