@sveltejs/kit 3.0.0-next.22 → 3.0.0-next.23

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.
package/types/index.d.ts CHANGED
@@ -4,8 +4,8 @@
4
4
  declare module '@sveltejs/kit' {
5
5
  import type { Plugin } from 'vite';
6
6
  import type { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
7
- import type { Config } from '@sveltejs/kit/vite';
8
7
  import type { StandardSchemaV1 } from '@standard-schema/spec';
8
+ import type { Config } from '@sveltejs/kit/vite';
9
9
  // @ts-ignore this is an optional peer dependency so could be missing. Written like this so dts-buddy preserves the ts-ignore
10
10
  type Span = import('@opentelemetry/api').Span;
11
11
 
@@ -86,6 +86,14 @@ declare module '@sveltejs/kit' {
86
86
  [uniqueSymbol]: true; // necessary or else UnpackValidationError could wrongly unpack objects with the same shape as ActionFailure
87
87
  }
88
88
 
89
+ /**
90
+ * A validation error thrown by `invalid`.
91
+ */
92
+ export interface ValidationError {
93
+ /** The validation issues */
94
+ issues: StandardSchemaV1.Issue[];
95
+ }
96
+
89
97
  type UnpackValidationError<T> =
90
98
  T extends ActionFailure<infer X>
91
99
  ? X
@@ -1028,6 +1036,12 @@ declare module '@sveltejs/kit' {
1028
1036
  * @since 2.47.3
1029
1037
  */
1030
1038
  export function invalid(...issues: (StandardSchemaV1.Issue | string)[]): never;
1039
+ /**
1040
+ * Checks whether this is a validation error thrown by {@link invalid}.
1041
+ * @param e The object to check.
1042
+ * @since 2.47.3
1043
+ */
1044
+ export function isValidationError(e: unknown): e is ValidationError;
1031
1045
  /**
1032
1046
  * Strips possible SvelteKit-internal suffixes and trailing slashes from the URL pathname.
1033
1047
  * Returns the normalized URL as well as a method for adding the potential suffix back
@@ -1485,775 +1499,238 @@ declare module '@sveltejs/kit/params' {
1485
1499
  export {};
1486
1500
  }
1487
1501
 
1488
- declare module '@sveltejs/kit/remote' {
1489
- import type { StandardSchemaV1 } from '@standard-schema/spec';
1490
- // If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
1491
- type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
1492
-
1493
- // Input type mappings for form fields
1494
- type InputTypeMap = {
1495
- text: string;
1496
- email: string;
1497
- password: string;
1498
- url: string;
1499
- tel: string;
1500
- search: string;
1501
- number: number;
1502
- range: number;
1503
- date: string;
1504
- 'datetime-local': string;
1505
- time: string;
1506
- month: string;
1507
- week: string;
1508
- color: string;
1509
- checkbox: boolean | string[];
1510
- radio: string;
1511
- file: File;
1512
- hidden: string | number | boolean;
1513
- submit: string | number | boolean;
1514
- button: string;
1515
- reset: string;
1516
- image: string;
1517
- select: string;
1518
- 'select multiple': string[];
1519
- 'file multiple': File[];
1520
- };
1521
-
1522
- // Valid input types for a given value type
1523
- export type RemoteFormFieldType<T> = {
1524
- [K in keyof InputTypeMap]: T extends InputTypeMap[K] ? K : never;
1525
- }[keyof InputTypeMap];
1526
-
1527
- // Input element properties based on type
1528
- type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'radio'
1529
- ? {
1530
- name: string;
1531
- type: T;
1532
- value?: string;
1533
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1534
- get checked(): boolean;
1535
- set checked(value: boolean);
1536
- readonly defaultChecked?: boolean;
1537
- }
1538
- : T extends 'file'
1539
- ? {
1540
- name: string;
1541
- type: 'file';
1542
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1543
- get files(): FileList | null;
1544
- set files(v: FileList | null);
1545
- }
1546
- : T extends 'select'
1547
- ? {
1548
- name: string;
1549
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1550
- get value(): string;
1551
- set value(v: string);
1552
- }
1553
- : T extends 'select multiple'
1554
- ? {
1555
- name: string;
1556
- multiple: true;
1557
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1558
- get value(): string[];
1559
- set value(v: string[]);
1560
- }
1561
- : T extends 'text'
1562
- ? {
1563
- name: string;
1564
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1565
- get value(): string | number;
1566
- set value(v: string | number);
1567
- readonly defaultValue?: string | number;
1568
- }
1569
- : {
1570
- name: string;
1571
- type: T;
1572
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1573
- get value(): string | number;
1574
- set value(v: string | number);
1575
- readonly defaultValue?: string | number;
1576
- };
1577
-
1578
- type RemoteFormFieldMethods<T> = {
1579
- /** The values that will be submitted */
1580
- value(): DeepPartial<T>;
1581
- /** Set the values that will be submitted */
1582
- set(input: DeepPartial<T>): DeepPartial<T>;
1583
- /** Whether the field or any nested field has been interacted with since the form was mounted */
1584
- touched(): boolean;
1585
- /** Whether the field or any nested field has been edited since the form was mounted */
1586
- dirty(): boolean;
1587
- /** Validation issues, if any */
1588
- issues(): RemoteFormIssue[] | undefined;
1589
- };
1590
-
1591
- // These two types use "T extends unknown ? .. : .." to distribute over unions.
1592
- // Example: if "type T = A | b" then "keyof T" only contains keys that both A and B have, with "KeysOfUnion<T>" we get the keys of both A and B
1593
- type KeysOfUnion<T> = T extends unknown ? keyof T : never;
1594
- type ValueOfUnionKey<T, K extends PropertyKey> = T extends unknown
1595
- ? K extends keyof T
1596
- ? T[K]
1597
- : never
1598
- : never;
1599
-
1600
- export type RemoteFormFieldValue = string | string[] | number | boolean | File | File[];
1601
-
1602
- type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
1603
- ? Value extends string[]
1604
- ? [type: Type, value: Value[number] | (string & {})]
1605
- : Value extends boolean
1606
- ? [type: Type] | [type: Type, value: boolean]
1607
- : [type: Type] | [type: Type, value: Value | (string & {})]
1608
- : Type extends 'submit' | 'hidden'
1609
- ? Value extends string
1610
- ? [type: Type, value: Value | (string & {})]
1611
- : [type: Type, value: Value]
1612
- : Type extends 'radio'
1613
- ? [type: Type, value: Value | (string & {})]
1614
- : Type extends 'file' | 'file multiple'
1615
- ? [type: Type]
1616
- : [type: Type] | [type: Type, value: Value | undefined];
1502
+ declare module '@sveltejs/kit/vite' {
1503
+ import type { Adapter } from '@sveltejs/kit';
1504
+ import type { Options } from '@sveltejs/vite-plugin-svelte';
1505
+ import type { Plugin } from 'vite';
1506
+ // this indirection helps make the docs look pretty
1507
+ type VitePluginSvelteOptions = Omit<Options, 'experimental'>;
1508
+ type VitePluginSvelteOptionsExperimental = Options['experimental'];
1617
1509
 
1618
1510
  /**
1619
- * Form field accessor type that provides name(), value(), and issues() methods
1511
+ * An extension of [`vite-plugin-svelte`'s options](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#svelte-options).
1620
1512
  */
1621
- export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
1513
+ export interface Config extends VitePluginSvelteOptions {
1622
1514
  /**
1623
- * Returns an object that can be spread onto an input element with the correct type attribute,
1624
- * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
1625
- * @example
1626
- * ```svelte
1627
- * <input {...myForm.fields.myString.as('text')} />
1628
- * <input {...myForm.fields.myNumber.as('number')} />
1629
- * <input {...myForm.fields.myBoolean.as('checkbox')} />
1630
- * ```
1515
+ * Your [adapter](https://svelte.dev/docs/kit/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms.
1516
+ * @default undefined
1631
1517
  */
1632
- as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
1633
- };
1634
-
1635
- type RemoteFormFieldContainer<Value> = RemoteFormFieldMethods<Value> & {
1636
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
1637
- allIssues(): RemoteFormIssue[] | undefined;
1638
- };
1639
-
1640
- type UnknownField<Value> = RemoteFormFieldMethods<Value> & {
1641
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
1642
- allIssues(): RemoteFormIssue[] | undefined;
1518
+ adapter?: Adapter;
1643
1519
  /**
1644
- * Returns an object that can be spread onto an input element with the correct type attribute,
1645
- * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
1646
- * @example
1647
- * ```svelte
1648
- * <input {...myForm.fields.myString.as('text')} />
1649
- * <input {...myForm.fields.myNumber.as('number')} />
1650
- * <input {...myForm.fields.myBoolean.as('checkbox')} />
1520
+ * An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
1521
+ *
1522
+ * This option is deprecated. Use [subpath imports](https://svelte.dev/docs/kit/$lib) instead.
1523
+ *
1524
+ * > [!NOTE] You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
1525
+ * @deprecated
1526
+ * @default {}
1527
+ */
1528
+ alias?: Record<string, string>;
1529
+ /**
1530
+ * The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes.
1531
+ *
1532
+ * If `paths.assets` is specified, there will be two app directories — `${paths.assets}/${appDir}` and `${paths.base}/${appDir}`.
1533
+ * @default "_app"
1534
+ */
1535
+ appDir?: string;
1536
+ /**
1537
+ * [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) configuration. CSP helps to protect your users against cross-site scripting (XSS) attacks, by limiting the places resources can be loaded from. For example, a configuration like this...
1538
+ *
1539
+ * ```js
1540
+ * /// file: vite.config.js
1541
+ * import { sveltekit } from '@sveltejs/kit/vite';
1542
+ * import { defineConfig } from 'vite';
1543
+ *
1544
+ * export default defineConfig({
1545
+ * plugins: [
1546
+ * sveltekit({
1547
+ * csp: {
1548
+ * directives: {
1549
+ * 'script-src': ['self']
1550
+ * },
1551
+ * // must be specified with either the `report-uri` or `report-to` directives, or both
1552
+ * reportOnly: {
1553
+ * 'script-src': ['self'],
1554
+ * 'report-uri': ['/']
1555
+ * }
1556
+ * }
1557
+ * })
1558
+ * ]
1559
+ * });
1651
1560
  * ```
1561
+ *
1562
+ * ...would prevent scripts loading from external sites. SvelteKit will augment the specified directives with nonces or hashes (depending on `mode`) for any inline styles and scripts it generates.
1563
+ *
1564
+ * To add a nonce for scripts and links manually included in `src/app.html`, you may use the placeholder `%sveltekit.nonce%` (for example `<script nonce="%sveltekit.nonce%">`).
1565
+ *
1566
+ * When pages are prerendered, the CSP header is added via a `<meta http-equiv>` tag (note that in this case, `frame-ancestors`, `report-uri` and `sandbox` directives will be ignored).
1567
+ *
1568
+ * > [!NOTE] When `mode` is `'auto'`, SvelteKit will use nonces for dynamically rendered pages and hashes for prerendered pages. Using nonces with prerendered pages is insecure and therefore forbidden.
1569
+ *
1570
+ * If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://svelte.dev/docs/kit/hooks#handle) to roll your own CSP.
1652
1571
  */
1653
- as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
1654
- } & {
1655
- [key: string | number]: UnknownField<any>;
1656
- };
1657
-
1658
- type RemoteFormFieldsRoot<Input extends RemoteFormInput | void> =
1659
- IsAny<Input> extends true
1660
- ? RecursiveFormFields
1661
- : Input extends void
1662
- ? {
1663
- /** Validation issues, if any */
1664
- issues(): RemoteFormIssue[] | undefined;
1665
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
1666
- allIssues(): RemoteFormIssue[] | undefined;
1667
- }
1668
- : RemoteFormFields<Input>;
1669
-
1670
- /**
1671
- * Recursive type to build form fields structure with proxy access
1672
- */
1673
- export type RemoteFormFields<T> =
1674
- WillRecurseIndefinitely<T> extends true
1675
- ? RecursiveFormFields
1676
- : NonNullable<T> extends string | number | boolean | File
1677
- ? RemoteFormField<NonNullable<T>>
1678
- : // [NonNullable<T>] is used to prevent distributing over union while still allowing
1679
- // nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
1680
- // to be treated as arrays; only the last condition should distribute over unions
1681
- [NonNullable<T>] extends [string[] | File[]]
1682
- ? RemoteFormField<NonNullable<T>> & {
1683
- [K in number]: RemoteFormField<NonNullable<T>[number]>;
1684
- }
1685
- : [NonNullable<T>] extends [Array<infer U>]
1686
- ? RemoteFormFieldContainer<NonNullable<T>> & {
1687
- [K in number]: RemoteFormFields<U>;
1688
- }
1689
- : RemoteFormFieldContainer<T> & {
1690
- [K in KeysOfUnion<T>]-?: RemoteFormFields<ValueOfUnionKey<T, K>>;
1691
- };
1692
-
1693
- // By breaking this out into its own type, we avoid the TS recursion depth limit
1694
- type RecursiveFormFields = RemoteFormFieldContainer<any> & {
1695
- [key: string | number]: UnknownField<any>;
1696
- };
1697
-
1698
- type MaybeArray<T> = T | T[];
1699
-
1700
- export interface RemoteFormInput {
1701
- [key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
1702
- }
1703
-
1704
- export interface RemoteFormIssue {
1705
- message: string;
1706
- path: Array<string | number>;
1707
- }
1708
-
1709
- // If the schema specifies `id` as a string or number, ensure that `for(...)`
1710
- // only accepts that type. Otherwise, accept `string | number`
1711
- type ExtractId<Input> = Input extends { id: infer Id }
1712
- ? Id extends string | number
1713
- ? Id
1714
- : string | number
1715
- : string | number;
1716
-
1717
- /**
1718
- * A function and proxy object used to imperatively create validation errors in form handlers.
1719
- *
1720
- * Access properties to create field-specific issues: `issue.fieldName('message')`.
1721
- * The type structure mirrors the input data structure for type-safe field access.
1722
- * Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
1723
- */
1724
- export type InvalidField<T> =
1725
- WillRecurseIndefinitely<T> extends true
1726
- ? Record<string | number, any>
1727
- : NonNullable<T> extends string | number | boolean | File
1728
- ? (message: string) => StandardSchemaV1.Issue
1729
- : NonNullable<T> extends Array<infer U>
1730
- ? {
1731
- [K in number]: InvalidField<U>;
1732
- } & ((message: string) => StandardSchemaV1.Issue)
1733
- : NonNullable<T> extends RemoteFormInput
1734
- ? {
1735
- [K in keyof T]-?: InvalidField<T[K]>;
1736
- } & ((message: string) => StandardSchemaV1.Issue)
1737
- : Record<string, never>;
1738
-
1739
- /**
1740
- * A validation error thrown by `invalid`.
1741
- */
1742
- export interface ValidationError {
1743
- /** The validation issues */
1744
- issues: StandardSchemaV1.Issue[];
1745
- }
1746
-
1747
- /**
1748
- * The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
1749
- */
1750
- export type RemoteFormEnhanceInstance<
1751
- Input extends RemoteFormInput | void = RemoteFormInput | void,
1752
- Output = any
1753
- > = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
1754
- readonly element: HTMLFormElement;
1755
- };
1756
-
1757
- /**
1758
- * The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
1759
- */
1760
- export type RemoteFormEnhanceCallback<
1761
- Input extends RemoteFormInput | void = RemoteFormInput | void,
1762
- Output = any
1763
- > = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
1764
-
1765
- /**
1766
- * The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
1767
- */
1768
- export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
1769
- /** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
1770
- [attachment: symbol]: (node: HTMLFormElement) => void;
1771
- method: 'POST';
1772
- /** The URL to send the form to. */
1773
- action: string;
1774
- /** The `<form>` element this instance is currently attached to, if any. */
1775
- get element(): HTMLFormElement | null;
1776
- /** Submit the currently attached form programmatically. */
1777
- submit(): Promise<boolean> & {
1778
- updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
1779
- };
1780
- /** Use the `enhance` method to influence what happens when the form is submitted. */
1781
- enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
1782
- method: 'POST';
1783
- action: string;
1784
- [attachment: symbol]: (node: HTMLFormElement) => void;
1572
+ csp?: {
1573
+ /**
1574
+ * Whether to use hashes or nonces to restrict `<script>` and `<style>` elements. `'auto'` will use hashes for prerendered pages, and nonces for dynamically rendered pages.
1575
+ */
1576
+ mode?: 'hash' | 'nonce' | 'auto';
1577
+ /**
1578
+ * Directives that will be added to `Content-Security-Policy` headers.
1579
+ */
1580
+ directives?: CspDirectives;
1581
+ /**
1582
+ * Directives that will be added to `Content-Security-Policy-Report-Only` headers.
1583
+ */
1584
+ reportOnly?: CspDirectives;
1785
1585
  };
1786
1586
  /**
1787
- * Create an instance of the form for the given `id`.
1788
- * The `id` is stringified and used for deduplication to potentially reuse existing instances.
1789
- * Useful when you have multiple forms that use the same remote form action, for example in a loop.
1790
- * ```svelte
1791
- * {#each todos as todo}
1792
- * {const todoForm = updateTodo.for(todo.id)}
1793
- * <form {...todoForm}>
1794
- * {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
1795
- * ...
1796
- * </form>
1797
- * {/each}
1798
- * ```
1587
+ * Protection against [cross-site request forgery (CSRF)](https://owasp.org/www-community/attacks/csrf) attacks.
1799
1588
  */
1800
- for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
1801
- /** Preflight checks */
1802
- preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
1803
- /** Validate the form contents programmatically */
1804
- validate(options?: {
1589
+ csrf?: {
1805
1590
  /**
1806
- * Set this to `true` to also show validation issues of fields that haven't yet been
1807
- * edited and blurred. This option is ignored for forms that have previously been
1808
- * submitted, in which case all fields are always subject to validation
1809
- * (unless the form is reset, at which point it is treated as pristine)
1591
+ * Whether to check the incoming `origin` header for `POST`, `PUT`, `PATCH`, or `DELETE` form submissions and verify that it matches the server's origin.
1592
+ *
1593
+ * To allow people to make `POST`, `PUT`, `PATCH`, or `DELETE` requests with a `Content-Type` of `application/x-www-form-urlencoded`, `multipart/form-data`, or `text/plain` to your app from other origins, you will need to disable this option. Be careful!
1594
+ * @default true
1595
+ * @deprecated removed in 3.0. Use `trustedOrigins: ['*']` instead
1810
1596
  */
1811
- all?: boolean;
1812
- /** Set this to `true` to only run the `preflight` validation. */
1813
- preflightOnly?: boolean;
1814
- }): Promise<void>;
1815
- /** The result of the form submission */
1816
- get result(): Output | undefined;
1817
- /** The number of pending submissions */
1818
- get pending(): number;
1819
- /** True if the form has been submitted at least once, and hasn't been reset since */
1820
- get submitted(): boolean;
1821
- /** Access form fields using object notation */
1822
- fields: RemoteFormFieldsRoot<Input>;
1823
- };
1824
-
1825
- /**
1826
- * The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
1827
- */
1828
- export type RemoteCommand<Input, Output> = {
1829
- (arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
1830
- updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
1597
+ checkOrigin?: boolean;
1598
+ /**
1599
+ * An array of origins that are allowed to make cross-origin form submissions to your app.
1600
+ *
1601
+ * Each origin should be a complete origin including protocol (e.g., `https://payment-gateway.com`).
1602
+ * This is useful for allowing trusted third-party services like payment gateways or authentication providers to submit forms to your app.
1603
+ *
1604
+ * If the array contains `'*'`, all origins will be trusted. This is generally not recommended!
1605
+ *
1606
+ * > [!NOTE] Only add origins you completely trust, as this bypasses CSRF protection for those origins.
1607
+ *
1608
+ * CSRF checks only apply in production, not in local development.
1609
+ * @default []
1610
+ * @example
1611
+ * ```js
1612
+ * ['https://checkout.stripe.com', 'https://accounts.google.com']
1613
+ * ```
1614
+ */
1615
+ trustedOrigins?: string[];
1831
1616
  };
1832
- /** The number of pending command executions */
1833
- get pending(): number;
1834
- };
1835
-
1836
- export type RemoteQueryUpdate =
1837
- | RemoteQuery<any>
1838
- | RemoteLiveQuery<any>
1839
- | RemoteQueryFunction<any, any>
1840
- | RemoteLiveQueryFunction<any, any>
1841
- | RemoteQueryOverride;
1842
-
1843
- export type RemoteResource<T> = Promise<T> & {
1844
- /** The error in case the query fails. */
1845
- get error(): App.Error | undefined;
1846
- /** `true` before the first result is available and during refreshes */
1847
- get loading(): boolean;
1848
- } & (
1849
- | {
1850
- /** The current value of the query. Undefined until `ready` is `true` */
1851
- get current(): undefined;
1852
- ready: false;
1853
- }
1854
- | {
1855
- /** The current value of the query. Undefined until `ready` is `true` */
1856
- get current(): T;
1857
- ready: true;
1858
- }
1859
- );
1860
-
1861
- export type RemoteQuery<T> = RemoteResource<T> & {
1862
1617
  /**
1863
- * On the client, this function will update the value of the query without re-fetching it.
1864
- *
1865
- * On the server, this can be called in the context of a `command` or `form` and the specified data will accompany the action response back to the client.
1866
- * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
1618
+ * Whether or not the app is embedded inside a larger app. If `true`, SvelteKit will add its event listeners related to navigation etc on the parent of `%sveltekit.body%` instead of `window`, and will pass `params` from the server rather than inferring them from `location.pathname`.
1619
+ * Note that it is generally not supported to embed multiple SvelteKit apps on the same page and use client-side SvelteKit features within them (things such as pushing to the history state assume a single instance).
1620
+ * @default false
1867
1621
  */
1868
- set(value: T): void;
1622
+ embedded?: boolean;
1869
1623
  /**
1870
- * On the client, this function will re-fetch the query from the server.
1871
- *
1872
- * On the server, this can be called in the context of a `command` or `form` and the refreshed data will accompany the action response back to the client.
1873
- * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
1624
+ * Environment variable configuration
1874
1625
  */
1875
- refresh(): Promise<void>;
1626
+ env?: {
1627
+ /**
1628
+ * The directory to search for `.env` files.
1629
+ * @default "."
1630
+ */
1631
+ dir?: string;
1632
+ };
1633
+ /** Experimental features. Here be dragons. These are not subject to semantic versioning, so breaking changes or removal can happen in any release. */
1634
+ experimental?: VitePluginSvelteOptionsExperimental & {
1635
+ /**
1636
+ * Whether to enable the experimental remote functions feature. This feature is not yet stable and may be changed or removed at any time.
1637
+ * @default false
1638
+ */
1639
+ remoteFunctions?: boolean;
1640
+
1641
+ /**
1642
+ * Whether to enable the experimental forked preloading feature using Svelte's fork API.
1643
+ * @default false
1644
+ */
1645
+ forkPreloads?: boolean;
1646
+ };
1876
1647
  /**
1877
- * Temporarily override a query's value during a [single-flight mutation](https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations) to provide optimistic updates.
1878
- *
1879
- * ```svelte
1880
- * <script>
1881
- * import { getTodos, addTodo } from './todos.remote.js';
1882
- * const todos = getTodos();
1883
- * </script>
1884
- *
1885
- * <form {...addTodo.enhance(async (form) => {
1886
- * await form.submit().updates(
1887
- * todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
1888
- * );
1889
- * })}>
1890
- * <input type="text" name="text" />
1891
- * <button type="submit">Add Todo</button>
1892
- * </form>
1893
- * ```
1648
+ * Where to find various files within your project.
1649
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1894
1650
  */
1895
- withOverride(update: (current: T) => T): RemoteQueryOverride;
1896
- };
1897
-
1898
- export type RemoteLiveQuery<T> = RemoteResource<T> &
1899
- AsyncIterable<T> & {
1900
- /** `true` if the live stream is currently connected. */
1901
- readonly connected: boolean;
1902
- /** `true` once the current live stream iterator is done. */
1903
- readonly done: boolean;
1904
- /** Reconnects the live stream immediately. */
1905
- reconnect(): Promise<void>;
1906
- };
1907
-
1908
- export type RemoteQueryOverride = () => void;
1909
-
1910
- /**
1911
- * The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
1912
- */
1913
- export type RemotePrerenderFunction<Input, Output> = (
1914
- arg: undefined extends Input ? Input | void : Input
1915
- ) => RemoteResource<Output>;
1916
-
1917
- /**
1918
- * The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
1919
- *
1920
- * The optional `Validated` generic parameter represents the argument type *after* the
1921
- * query's schema has validated and (optionally) transformed it — this is the type the
1922
- * query's implementation function receives on the server, and the type yielded by
1923
- * [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
1924
- * with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
1925
- * schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
1926
- * `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
1927
- * without arguments it defaults to `Input`.
1928
- */
1929
- export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
1930
- arg: undefined extends Input ? Input | void : Input
1931
- ) => RemoteQuery<Output>;
1932
-
1933
- /**
1934
- * The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
1935
- *
1936
- * The optional `Validated` generic parameter represents the argument type *after* the
1937
- * query's schema has validated and (optionally) transformed it, and matches the type
1938
- * yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
1939
- */
1940
- export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
1941
- arg: undefined extends Input ? Input | void : Input
1942
- ) => RemoteLiveQuery<Output>;
1943
-
1944
- /**
1945
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1946
- * when called with a regular `query`. `arg` is the validated argument (the input *after*
1947
- * the query's schema validated and transformed it, if applicable); `query` is a
1948
- * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
1949
- * update the correct client entry.
1950
- */
1951
- export type RequestedEntry<Validated, Output> = {
1952
- arg: Validated;
1953
- query: RemoteQuery<Output>;
1954
- };
1955
-
1956
- /**
1957
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1958
- * when called with a `query.live`. `arg` is the validated argument; `query` is a
1959
- * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
1960
- * the correct client subscription.
1961
- */
1962
- export type LiveRequestedEntry<Validated, Output> = {
1963
- arg: Validated;
1964
- query: RemoteLiveQuery<Output>;
1965
- };
1966
-
1967
- export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
1968
- AsyncIterable<RequestedEntry<Validated, Output>> & {
1651
+ files?: {
1969
1652
  /**
1970
- * Call `refresh` on all queries selected by this `requested` invocation.
1971
- * This is identical to:
1972
- * ```ts
1973
- * import { requested } from '$app/server';
1974
- *
1975
- * for await (const { query } of requested(getPost, ...)) {
1976
- * void query.refresh();
1977
- * }
1978
- * ```
1653
+ * The location of your source code.
1654
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1655
+ * @default "src"
1656
+ * @since 2.28
1979
1657
  */
1980
- refreshAll: () => Promise<void>;
1981
- };
1982
-
1983
- export type LiveQueryRequestedResult<Validated, Output> = Iterable<
1984
- LiveRequestedEntry<Validated, Output>
1985
- > &
1986
- AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
1658
+ src?: string;
1987
1659
  /**
1988
- * Call `reconnect` on all live queries selected by this `requested` invocation.
1989
- * This is identical to:
1990
- * ```ts
1991
- * import { requested } from '$app/server';
1992
- *
1993
- * for await (const { query } of requested(liveQuery, ...)) {
1994
- * void query.reconnect();
1995
- * }
1996
- * ```
1660
+ * A place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json`.
1661
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1662
+ * @default "static"
1997
1663
  */
1998
- reconnectAll: () => Promise<void>;
1664
+ assets?: string;
1665
+ hooks?: {
1666
+ /**
1667
+ * The location of your client [hooks](https://svelte.dev/docs/kit/hooks).
1668
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1669
+ * @default "src/hooks.client"
1670
+ */
1671
+ client?: string;
1672
+ /**
1673
+ * The location of your server [hooks](https://svelte.dev/docs/kit/hooks).
1674
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1675
+ * @default "src/hooks.server"
1676
+ */
1677
+ server?: string;
1678
+ /**
1679
+ * The location of your universal [hooks](https://svelte.dev/docs/kit/hooks).
1680
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1681
+ * @default "src/hooks"
1682
+ * @since 2.3.0
1683
+ */
1684
+ universal?: string;
1685
+ };
1686
+ /**
1687
+ * A directory containing [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching).
1688
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1689
+ * @default "src/params"
1690
+ */
1691
+ params?: string;
1692
+ /**
1693
+ * The files that define the structure of your app (see [Routing](https://svelte.dev/docs/kit/routing)).
1694
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1695
+ * @default "src/routes"
1696
+ */
1697
+ routes?: string;
1698
+ /**
1699
+ * The location of your service worker's entry point (see [Service workers](https://svelte.dev/docs/kit/service-workers)).
1700
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1701
+ * @default "src/service-worker"
1702
+ */
1703
+ serviceWorker?: string;
1704
+ /**
1705
+ * The location of the template for HTML responses.
1706
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1707
+ * @default "src/app.html"
1708
+ */
1709
+ appTemplate?: string;
1710
+ /**
1711
+ * The location of the template for fallback error responses.
1712
+ * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
1713
+ * @default "src/error.html"
1714
+ */
1715
+ errorTemplate?: string;
1999
1716
  };
2000
-
2001
- export type RequestedResult<Validated, Output> =
2002
- | QueryRequestedResult<Validated, Output>
2003
- | LiveQueryRequestedResult<Validated, Output>;
2004
- /**
2005
- * Checks whether this is a validation error thrown by [`invalid`](https://svelte.dev/docs/kit/@sveltejs-kit#invalid).
2006
- * @param e The object to check.
2007
- * @since 2.47.3
2008
- */
2009
- export function isValidationError(e: unknown): e is import("@sveltejs/kit/remote").ValidationError;
2010
- type MaybePromise<T> = T | Promise<T>;
2011
-
2012
- type DeepPartial<T> = T extends Record<PropertyKey, unknown> | unknown[]
2013
- ? {
2014
- [K in keyof T]?: T[K] extends Record<PropertyKey, unknown> | unknown[]
2015
- ? DeepPartial<T[K]>
2016
- : T[K];
2017
- }
2018
- : T | undefined;
2019
-
2020
- type IsAny<T> = 0 extends 1 & T ? true : false;
2021
-
2022
- export {};
2023
- }
2024
-
2025
- declare module '@sveltejs/kit/vite' {
2026
- import type { Adapter } from '@sveltejs/kit';
2027
- import type { Options } from '@sveltejs/vite-plugin-svelte';
2028
- import type { Plugin } from 'vite';
2029
- // this indirection helps make the docs look pretty
2030
- type VitePluginSvelteOptions = Omit<Options, 'experimental'>;
2031
- type VitePluginSvelteOptionsExperimental = Options['experimental'];
2032
-
2033
- /**
2034
- * An extension of [`vite-plugin-svelte`'s options](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#svelte-options).
2035
- */
2036
- export interface Config extends VitePluginSvelteOptions {
2037
1717
  /**
2038
- * Your [adapter](https://svelte.dev/docs/kit/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms.
2039
- * @default undefined
1718
+ * Inline CSS inside a `<style>` block at the head of the HTML. This option is a number that specifies the maximum length of a CSS file in UTF-16 code units, as specified by the [String.length](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length) property, to be inlined. All CSS files needed for the page that are smaller than this value are merged and inlined in a `<style>` block.
1719
+ *
1720
+ * > [!NOTE] This results in fewer initial requests and can improve your [First Contentful Paint](https://web.dev/first-contentful-paint) score. However, it generates larger HTML output and reduces the effectiveness of browser caches. Use it advisedly.
1721
+ * @default 0
2040
1722
  */
2041
- adapter?: Adapter;
1723
+ inlineStyleThreshold?: number;
2042
1724
  /**
2043
- * An object containing zero or more aliases used to replace values in `import` statements. These aliases are automatically passed to Vite and TypeScript.
2044
- *
2045
- * This option is deprecated. Use [subpath imports](https://svelte.dev/docs/kit/$lib) instead.
2046
- *
2047
- * > [!NOTE] You will need to run `npm run dev` to have SvelteKit automatically generate the required alias configuration in `jsconfig.json` or `tsconfig.json`.
2048
- * @deprecated
2049
- * @default {}
1725
+ * An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.moduleExtensions` will be ignored by the router.
1726
+ * @default [".js", ".ts"]
2050
1727
  */
2051
- alias?: Record<string, string>;
1728
+ moduleExtensions?: string[];
2052
1729
  /**
2053
- * The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes.
2054
- *
2055
- * If `paths.assets` is specified, there will be two app directories — `${paths.assets}/${appDir}` and `${paths.base}/${appDir}`.
2056
- * @default "_app"
1730
+ * The directory that SvelteKit writes files to during `dev` and `build`. You should exclude this directory from version control.
1731
+ * @default ".svelte-kit"
2057
1732
  */
2058
- appDir?: string;
2059
- /**
2060
- * [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) configuration. CSP helps to protect your users against cross-site scripting (XSS) attacks, by limiting the places resources can be loaded from. For example, a configuration like this...
2061
- *
2062
- * ```js
2063
- * /// file: vite.config.js
2064
- * import { sveltekit } from '@sveltejs/kit/vite';
2065
- * import { defineConfig } from 'vite';
2066
- *
2067
- * export default defineConfig({
2068
- * plugins: [
2069
- * sveltekit({
2070
- * csp: {
2071
- * directives: {
2072
- * 'script-src': ['self']
2073
- * },
2074
- * // must be specified with either the `report-uri` or `report-to` directives, or both
2075
- * reportOnly: {
2076
- * 'script-src': ['self'],
2077
- * 'report-uri': ['/']
2078
- * }
2079
- * }
2080
- * })
2081
- * ]
2082
- * });
2083
- * ```
2084
- *
2085
- * ...would prevent scripts loading from external sites. SvelteKit will augment the specified directives with nonces or hashes (depending on `mode`) for any inline styles and scripts it generates.
2086
- *
2087
- * To add a nonce for scripts and links manually included in `src/app.html`, you may use the placeholder `%sveltekit.nonce%` (for example `<script nonce="%sveltekit.nonce%">`).
2088
- *
2089
- * When pages are prerendered, the CSP header is added via a `<meta http-equiv>` tag (note that in this case, `frame-ancestors`, `report-uri` and `sandbox` directives will be ignored).
2090
- *
2091
- * > [!NOTE] When `mode` is `'auto'`, SvelteKit will use nonces for dynamically rendered pages and hashes for prerendered pages. Using nonces with prerendered pages is insecure and therefore forbidden.
2092
- *
2093
- * If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://svelte.dev/docs/kit/hooks#handle) to roll your own CSP.
2094
- */
2095
- csp?: {
2096
- /**
2097
- * Whether to use hashes or nonces to restrict `<script>` and `<style>` elements. `'auto'` will use hashes for prerendered pages, and nonces for dynamically rendered pages.
2098
- */
2099
- mode?: 'hash' | 'nonce' | 'auto';
2100
- /**
2101
- * Directives that will be added to `Content-Security-Policy` headers.
2102
- */
2103
- directives?: CspDirectives;
2104
- /**
2105
- * Directives that will be added to `Content-Security-Policy-Report-Only` headers.
2106
- */
2107
- reportOnly?: CspDirectives;
2108
- };
2109
- /**
2110
- * Protection against [cross-site request forgery (CSRF)](https://owasp.org/www-community/attacks/csrf) attacks.
2111
- */
2112
- csrf?: {
2113
- /**
2114
- * Whether to check the incoming `origin` header for `POST`, `PUT`, `PATCH`, or `DELETE` form submissions and verify that it matches the server's origin.
2115
- *
2116
- * To allow people to make `POST`, `PUT`, `PATCH`, or `DELETE` requests with a `Content-Type` of `application/x-www-form-urlencoded`, `multipart/form-data`, or `text/plain` to your app from other origins, you will need to disable this option. Be careful!
2117
- * @default true
2118
- * @deprecated removed in 3.0. Use `trustedOrigins: ['*']` instead
2119
- */
2120
- checkOrigin?: boolean;
2121
- /**
2122
- * An array of origins that are allowed to make cross-origin form submissions to your app.
2123
- *
2124
- * Each origin should be a complete origin including protocol (e.g., `https://payment-gateway.com`).
2125
- * This is useful for allowing trusted third-party services like payment gateways or authentication providers to submit forms to your app.
2126
- *
2127
- * If the array contains `'*'`, all origins will be trusted. This is generally not recommended!
2128
- *
2129
- * > [!NOTE] Only add origins you completely trust, as this bypasses CSRF protection for those origins.
2130
- *
2131
- * CSRF checks only apply in production, not in local development.
2132
- * @default []
2133
- * @example
2134
- * ```js
2135
- * ['https://checkout.stripe.com', 'https://accounts.google.com']
2136
- * ```
2137
- */
2138
- trustedOrigins?: string[];
2139
- };
2140
- /**
2141
- * Whether or not the app is embedded inside a larger app. If `true`, SvelteKit will add its event listeners related to navigation etc on the parent of `%sveltekit.body%` instead of `window`, and will pass `params` from the server rather than inferring them from `location.pathname`.
2142
- * Note that it is generally not supported to embed multiple SvelteKit apps on the same page and use client-side SvelteKit features within them (things such as pushing to the history state assume a single instance).
2143
- * @default false
2144
- */
2145
- embedded?: boolean;
2146
- /**
2147
- * Environment variable configuration
2148
- */
2149
- env?: {
2150
- /**
2151
- * The directory to search for `.env` files.
2152
- * @default "."
2153
- */
2154
- dir?: string;
2155
- };
2156
- /** Experimental features. Here be dragons. These are not subject to semantic versioning, so breaking changes or removal can happen in any release. */
2157
- experimental?: VitePluginSvelteOptionsExperimental & {
2158
- /**
2159
- * Whether to enable the experimental remote functions feature. This feature is not yet stable and may be changed or removed at any time.
2160
- * @default false
2161
- */
2162
- remoteFunctions?: boolean;
2163
-
2164
- /**
2165
- * Whether to enable the experimental forked preloading feature using Svelte's fork API.
2166
- * @default false
2167
- */
2168
- forkPreloads?: boolean;
2169
- };
2170
- /**
2171
- * Where to find various files within your project.
2172
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2173
- */
2174
- files?: {
2175
- /**
2176
- * The location of your source code.
2177
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2178
- * @default "src"
2179
- * @since 2.28
2180
- */
2181
- src?: string;
2182
- /**
2183
- * A place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json`.
2184
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2185
- * @default "static"
2186
- */
2187
- assets?: string;
2188
- hooks?: {
2189
- /**
2190
- * The location of your client [hooks](https://svelte.dev/docs/kit/hooks).
2191
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2192
- * @default "src/hooks.client"
2193
- */
2194
- client?: string;
2195
- /**
2196
- * The location of your server [hooks](https://svelte.dev/docs/kit/hooks).
2197
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2198
- * @default "src/hooks.server"
2199
- */
2200
- server?: string;
2201
- /**
2202
- * The location of your universal [hooks](https://svelte.dev/docs/kit/hooks).
2203
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2204
- * @default "src/hooks"
2205
- * @since 2.3.0
2206
- */
2207
- universal?: string;
2208
- };
2209
- /**
2210
- * A directory containing [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching).
2211
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2212
- * @default "src/params"
2213
- */
2214
- params?: string;
2215
- /**
2216
- * The files that define the structure of your app (see [Routing](https://svelte.dev/docs/kit/routing)).
2217
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2218
- * @default "src/routes"
2219
- */
2220
- routes?: string;
2221
- /**
2222
- * The location of your service worker's entry point (see [Service workers](https://svelte.dev/docs/kit/service-workers)).
2223
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2224
- * @default "src/service-worker"
2225
- */
2226
- serviceWorker?: string;
2227
- /**
2228
- * The location of the template for HTML responses.
2229
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2230
- * @default "src/app.html"
2231
- */
2232
- appTemplate?: string;
2233
- /**
2234
- * The location of the template for fallback error responses.
2235
- * @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
2236
- * @default "src/error.html"
2237
- */
2238
- errorTemplate?: string;
2239
- };
2240
- /**
2241
- * Inline CSS inside a `<style>` block at the head of the HTML. This option is a number that specifies the maximum length of a CSS file in UTF-16 code units, as specified by the [String.length](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length) property, to be inlined. All CSS files needed for the page that are smaller than this value are merged and inlined in a `<style>` block.
2242
- *
2243
- * > [!NOTE] This results in fewer initial requests and can improve your [First Contentful Paint](https://web.dev/first-contentful-paint) score. However, it generates larger HTML output and reduces the effectiveness of browser caches. Use it advisedly.
2244
- * @default 0
2245
- */
2246
- inlineStyleThreshold?: number;
2247
- /**
2248
- * An array of file extensions that SvelteKit will treat as modules. Files with extensions that match neither `config.extensions` nor `config.moduleExtensions` will be ignored by the router.
2249
- * @default [".js", ".ts"]
2250
- */
2251
- moduleExtensions?: string[];
2252
- /**
2253
- * The directory that SvelteKit writes files to during `dev` and `build`. You should exclude this directory from version control.
2254
- * @default ".svelte-kit"
2255
- */
2256
- outDir?: string;
1733
+ outDir?: string;
2257
1734
  /**
2258
1735
  * Options related to the build output format
2259
1736
  */
@@ -3026,397 +2503,913 @@ declare module '$app/navigation' {
3026
2503
  persistState?: boolean;
3027
2504
  }
3028
2505
 
3029
- /**
3030
- * - `enter`: The app has hydrated/started
3031
- * - `form`: The user submitted a `<form method="GET">`
3032
- * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
3033
- * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
3034
- * - `link`: Navigation was triggered by a link click
3035
- * - `popstate`: Navigation was triggered by back/forward navigation
3036
- */
3037
- export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
2506
+ /**
2507
+ * - `enter`: The app has hydrated/started
2508
+ * - `form`: The user submitted a `<form method="GET">`
2509
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
2510
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
2511
+ * - `link`: Navigation was triggered by a link click
2512
+ * - `popstate`: Navigation was triggered by back/forward navigation
2513
+ */
2514
+ export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
2515
+
2516
+ export interface NavigationBase {
2517
+ /**
2518
+ * The type of navigation:
2519
+ * - `enter`: The app has hydrated/started
2520
+ * - `form`: The user submitted a `<form method="GET">`
2521
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
2522
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
2523
+ * - `link`: Navigation was triggered by a link click
2524
+ * - `popstate`: Navigation was triggered by back/forward navigation
2525
+ */
2526
+ type: NavigationType;
2527
+ /** Whether this is a shallow navigation. */
2528
+ shallow: boolean;
2529
+ /**
2530
+ * Where navigation was triggered from
2531
+ */
2532
+ from: NavigationTarget | null;
2533
+ /**
2534
+ * Where navigation is going to/has gone to
2535
+ */
2536
+ to: NavigationTarget | null;
2537
+ /**
2538
+ * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
2539
+ */
2540
+ willUnload: boolean;
2541
+ /**
2542
+ * A promise that resolves once the navigation is complete, and rejects if the navigation
2543
+ * fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
2544
+ */
2545
+ complete: Promise<void>;
2546
+ }
2547
+
2548
+ /**
2549
+ * The navigation that occurs when the app starts/hydrates
2550
+ */
2551
+ export interface NavigationEnter extends NavigationBase {
2552
+ type: 'enter';
2553
+
2554
+ /**
2555
+ * In case of a history back/forward navigation, the number of steps to go back/forward
2556
+ */
2557
+ delta?: undefined;
2558
+
2559
+ /**
2560
+ * Dispatched `Event` object when navigation occurred by `popstate` or `link`.
2561
+ */
2562
+ event?: undefined;
2563
+ }
2564
+
2565
+ export type NavigationExternal = NavigationGoto | NavigationLeave;
2566
+
2567
+ /**
2568
+ * A navigation triggered by a `goto(...)` call or a redirect
2569
+ */
2570
+ export interface NavigationGoto extends NavigationBase {
2571
+ type: 'goto';
2572
+ }
2573
+
2574
+ /**
2575
+ * A navigation triggered by the tab being closed, or the user navigating to a different document
2576
+ */
2577
+ export interface NavigationLeave extends NavigationBase {
2578
+ type: 'leave';
2579
+ }
2580
+
2581
+ /**
2582
+ * A navigation triggered by a `<form method="GET">`
2583
+ */
2584
+ export interface NavigationFormSubmit extends NavigationBase {
2585
+ type: 'form';
2586
+
2587
+ /**
2588
+ * The `SubmitEvent` that caused the navigation
2589
+ */
2590
+ event: SubmitEvent;
2591
+ }
2592
+
2593
+ /**
2594
+ * A navigation triggered by back/forward navigation
2595
+ */
2596
+ export interface NavigationPopState extends NavigationBase {
2597
+ type: 'popstate';
2598
+
2599
+ /**
2600
+ * In case of a history back/forward navigation, the number of steps to go back/forward
2601
+ */
2602
+ delta: number;
2603
+
2604
+ /**
2605
+ * The `PopStateEvent` that caused the navigation
2606
+ */
2607
+ event: PopStateEvent;
2608
+ }
2609
+
2610
+ /**
2611
+ * A navigation triggered by a link click
2612
+ */
2613
+ export interface NavigationLink extends NavigationBase {
2614
+ type: 'link';
2615
+
2616
+ /**
2617
+ * The `PointerEvent` that caused the navigation
2618
+ */
2619
+ event: PointerEvent;
2620
+ }
2621
+
2622
+ export type Navigation =
2623
+ | NavigationExternal
2624
+ | NavigationFormSubmit
2625
+ | NavigationPopState
2626
+ | NavigationLink;
2627
+
2628
+ /**
2629
+ * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
2630
+ */
2631
+ export type BeforeNavigate = Navigation & {
2632
+ /**
2633
+ * Call this to prevent the navigation from starting.
2634
+ */
2635
+ cancel: () => void;
2636
+ };
2637
+
2638
+ /**
2639
+ * The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
2640
+ */
2641
+ export type OnNavigate = Navigation & {
2642
+ type: Exclude<NavigationType, 'enter' | 'leave'>;
2643
+ /**
2644
+ * Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
2645
+ */
2646
+ willUnload: false;
2647
+ };
2648
+
2649
+ /**
2650
+ * The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
2651
+ */
2652
+ export type AfterNavigate = (Navigation | NavigationEnter) & {
2653
+ type: Exclude<NavigationType, 'leave'>;
2654
+ /**
2655
+ * Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
2656
+ */
2657
+ willUnload: false;
2658
+ };
2659
+ /**
2660
+ * A lifecycle function that captures state before navigating and restores it when traversing history.
2661
+ *
2662
+ * By default, the snapshot `id` is generated from the call site. Pass an explicit `id` to keep snapshots stable across deployments or distinguish multiple uses of a shared helper.
2663
+ *
2664
+ * The optional `reset` callback runs on navigations where there is no captured value to restore, such as when a new history entry is created. Captured values are serialized with the app's transport hook.
2665
+ *
2666
+ * `snapshot` must be called during a component initialization. It remains active as long as the component is mounted.
2667
+ * */
2668
+ export function snapshot<T>(options: {
2669
+ id?: string;
2670
+ capture: () => T;
2671
+ restore: (value: T) => void;
2672
+ reset?: () => void;
2673
+ }): void;
2674
+ /**
2675
+ * A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a URL.
2676
+ *
2677
+ * `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
2678
+ * */
2679
+ export function afterNavigate(callback: (navigation: AfterNavigate) => void): void;
2680
+ /**
2681
+ * A navigation interceptor that triggers before we navigate to a URL, whether by clicking a link, calling `goto(...)`, or using the browser back/forward controls.
2682
+ *
2683
+ * Calling `cancel()` will prevent the navigation from completing. If `navigation.type === 'leave'` — meaning the user is navigating away from the app (or closing the tab) — calling `cancel` will trigger the native browser unload confirmation dialog. In this case, the navigation may or may not be cancelled depending on the user's response.
2684
+ *
2685
+ * When a navigation isn't to a SvelteKit-owned route (and therefore controlled by SvelteKit's client-side router), `navigation.to.route.id` will be `null`.
2686
+ *
2687
+ * If the navigation will (if not cancelled) cause the document to unload — in other words `'leave'` navigations and `'link'` navigations where `navigation.to.route === null` — `navigation.willUnload` is `true`.
2688
+ *
2689
+ * `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
2690
+ * */
2691
+ export function beforeNavigate(callback: (navigation: BeforeNavigate) => void): void;
2692
+ /**
2693
+ * A lifecycle function that runs the supplied `callback` immediately before we navigate to a new URL except during full-page navigations.
2694
+ *
2695
+ * If you return a `Promise`, SvelteKit will wait for it to resolve before completing the navigation. This allows you to — for example — use `document.startViewTransition`. Avoid promises that are slow to resolve, since navigation will appear stalled to the user.
2696
+ *
2697
+ * If a function (or a `Promise` that resolves to a function) is returned from the callback, it will be called once the DOM has updated.
2698
+ *
2699
+ * `onNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
2700
+ * */
2701
+ export function onNavigate(callback: (navigation: OnNavigate) => MaybePromise<(() => void) | void>): void;
2702
+ /**
2703
+ * If called when the page is being updated following a navigation (in `onMount` or `afterNavigate` or an action, for example), this disables SvelteKit's built-in scroll handling.
2704
+ * This is generally discouraged, since it breaks user expectations.
2705
+ * */
2706
+ export function disableScrollHandling(): void;
2707
+ /**
2708
+ * Allows you to navigate programmatically to a given route, with control over details such as whether scroll and focus are reset
2709
+ * (as they would be with a regular navigation) or preserved.
2710
+ *
2711
+ * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) or the state change has been applied.
2712
+ *
2713
+ * `goto` is intended for navigations to routes that belong to the app, and will reject if a route cannot be resolved.
2714
+ * For external URLs, use `window.location = url` to perform a full-page navigation instead of calling `goto(url)`.
2715
+ *
2716
+ * @param url Where to navigate to. Note that if you've set [`config.paths.base`](https://svelte.dev/docs/kit/configuration#paths) and the URL is root-relative, you need to prepend the base path if you want to navigate within the app.
2717
+ * @param opts Options related to the navigation
2718
+ * */
2719
+ export function goto(url: string | URL, opts?: GotoOptions): Promise<void>;
2720
+ /**
2721
+ * Causes any `load` functions belonging to the currently active page to re-run if they depend on the `url` in question, via `fetch` or `depends`. Returns a `Promise` that resolves when the page is subsequently updated.
2722
+ *
2723
+ * If the argument is given as a `string` or `URL`, it must resolve to the same URL that was passed to `fetch` or `depends` (including query parameters).
2724
+ * To create a custom identifier, use a string beginning with `[a-z]+:` (e.g. `custom:state`) — this is a valid URL.
2725
+ *
2726
+ * The `function` argument can be used define a custom predicate. It receives the full `URL` and causes `load` to rerun if `true` is returned.
2727
+ * This can be useful if you want to invalidate based on a pattern instead of a exact match.
2728
+ *
2729
+ * ```ts
2730
+ * // Example: Match '/path' regardless of the query parameters
2731
+ * import { invalidate } from '$app/navigation';
2732
+ *
2733
+ * invalidate((url) => url.pathname === '/path');
2734
+ * ```
2735
+ * @param resource The invalidated URL
2736
+ * @param keepState If `true`, the current `page.state` will be preserved. Otherwise, it will be reset to an empty object. `false` by default.
2737
+ * */
2738
+ export function invalidate(resource: string | URL | ((url: URL) => boolean), keepState?: boolean): Promise<void>;
2739
+ /**
2740
+ * Causes all `load` and `query` functions belonging to the currently active page to re-run. Returns a `Promise` that resolves when the page is subsequently updated.
2741
+ *
2742
+ * Note that this resets `page.state` to an empty object. If you want to preserve `page.state` (for example when using [shallow routing](https://svelte.dev/docs/kit/shallow-routing)), use `refreshAll` instead.
2743
+ *
2744
+ * @deprecated Use [`refreshAll`](https://svelte.dev/docs/kit/$app-navigation#refreshAll) instead. Unlike `invalidateAll`, `refreshAll` does not reset `page.state`.
2745
+ * */
2746
+ export function invalidateAll(): Promise<void>;
2747
+ /**
2748
+ * Causes all currently active remote functions to refresh, and all `load` functions belonging to the currently active page to re-run.
2749
+ * Returns a `Promise` that resolves when the page is subsequently updated.
2750
+ * */
2751
+ export function refreshAll(): Promise<void>;
2752
+ /**
2753
+ * Programmatically preloads the given page, which means
2754
+ * 1. ensuring that the code for the page is loaded, and
2755
+ * 2. calling the page's load function with the appropriate options.
2756
+ *
2757
+ * This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.
2758
+ * If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
2759
+ * Returns a Promise that resolves with the result of running the new route's `load` functions once the preload is complete.
2760
+ *
2761
+ * @param href Page to preload
2762
+ * */
2763
+ export function preloadData(href: string): Promise<({
2764
+ type: "loaded";
2765
+ data: Record<string, any>;
2766
+ } | {
2767
+ type: "redirect";
2768
+ location: string;
2769
+ } | {
2770
+ type: "error";
2771
+ error: App.Error;
2772
+ }) & {
2773
+ status: number;
2774
+ }>;
2775
+ /**
2776
+ * Programmatically imports the code for routes that haven't yet been fetched.
2777
+ * Typically, you might call this to speed up subsequent navigation.
2778
+ *
2779
+ * Takes a route ID such as `/about` or `/blog/[slug]`. Unlike pathnames, route IDs
2780
+ * are never prefixed with the app's [base path](https://svelte.dev/docs/kit/configuration#paths).
2781
+ * If you have a pathname rather than a route ID, you can convert it with
2782
+ * [`match`](https://svelte.dev/docs/kit/$app-paths#match) from `$app/paths`:
2783
+ *
2784
+ * ```js
2785
+ * import { match } from '$app/paths';
2786
+ * import { preloadCode } from '$app/navigation';
2787
+ *
2788
+ * const matched = await match('/blog/hello-world');
2789
+ * if (matched) await preloadCode(matched.id);
2790
+ * ```
2791
+ *
2792
+ * Unlike `preloadData`, this won't call `load` functions.
2793
+ * Returns a Promise that resolves when the modules have been imported.
2794
+ *
2795
+ * */
2796
+ export function preloadCode(id: import("$app/types").RouteId): Promise<void>;
2797
+ /**
2798
+ * Programmatically create a new history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
2799
+ *
2800
+ * @deprecated Use `goto(url, { state, shallow: true })` instead.
2801
+ * */
2802
+ export function pushState(url: string | URL, state: App.PageState): Promise<void>;
2803
+ /**
2804
+ * Programmatically replace the current history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
2805
+ *
2806
+ * @deprecated Use `goto(url, { state, shallow: true, replace: true })` instead.
2807
+ * */
2808
+ export function replaceState(url: string | URL, state: App.PageState): Promise<void>;
2809
+ type MaybePromise<T> = T | Promise<T>;
2810
+
2811
+ export {};
2812
+ }
2813
+
2814
+ declare module '$app/paths' {
2815
+ import type { AssetPath, RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname, RouteId, RouteParams } from '$app/types';
2816
+ /**
2817
+ * Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
2818
+ *
2819
+ * During server rendering, the base path is relative and depends on the page currently being rendered.
2820
+ *
2821
+ * @example
2822
+ * ```svelte
2823
+ * <script>
2824
+ * import { asset } from '$app/paths';
2825
+ * </script>
2826
+ *
2827
+ * <img alt="a potato" src={asset('potato.jpg')} />
2828
+ * ```
2829
+ * @since 2.26
2830
+ *
2831
+ * */
2832
+ export function asset(file: AssetPath): string;
2833
+ /**
2834
+ * Resolve a pathname by prefixing it with the base path, if any, or resolve a route ID by populating dynamic segments with parameters.
2835
+ *
2836
+ * During server rendering, the base path is relative and depends on the page currently being rendered.
2837
+ *
2838
+ * @example
2839
+ * ```js
2840
+ * import { resolve } from '$app/paths';
2841
+ *
2842
+ * // using a pathname
2843
+ * const resolved = resolve(`blog/hello-world`);
2844
+ *
2845
+ * // using a route ID plus parameters
2846
+ * const resolved = resolve('/blog/[slug]', {
2847
+ * slug: 'hello-world'
2848
+ * });
2849
+ * ```
2850
+ * @since 2.26
2851
+ *
2852
+ * */
2853
+ export function resolve<T extends RouteIdWithSearchOrHash | PathnameWithSearchOrHash>(...args: ResolveArgs<T>): ResolvedPathname;
2854
+ /**
2855
+ * Match a path or URL to a route ID and extracts any parameters.
2856
+ *
2857
+ * @example
2858
+ * ```js
2859
+ * import { match } from '$app/paths';
2860
+ *
2861
+ * const route = await match('blog/hello-world');
2862
+ *
2863
+ * if (route?.id === '/blog/[slug]') {
2864
+ * const slug = route.params.slug;
2865
+ * const response = await fetch(`/api/posts/${slug}`);
2866
+ * const post = await response.json();
2867
+ * }
2868
+ * ```
2869
+ * @since 2.52.0
2870
+ *
2871
+ * */
2872
+ export function match(url: URL | string): Promise<{ [K in RouteId]: {
2873
+ id: K;
2874
+ params: RouteParams<K>;
2875
+ }; }[RouteId] | null>;
2876
+ type StripSearchOrHash<T extends string> = T extends `${infer U}?${string}`
2877
+ ? U
2878
+ : T extends `${infer U}#${string}`
2879
+ ? U
2880
+ : T;
2881
+
2882
+ type ResolveArgs<T> = T extends `/${string}`
2883
+ ? StripSearchOrHash<T> extends infer U extends RouteId
2884
+ ? RouteParams<U> extends Record<string, never>
2885
+ ? [route: T]
2886
+ : [route: T, params: RouteParams<U>]
2887
+ : [never]
2888
+ : [pathname: T];
2889
+
2890
+ export {};
2891
+ }
2892
+
2893
+ declare module '$app/server' {
2894
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2895
+ import type { RequestEvent } from '@sveltejs/kit';
2896
+ // If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
2897
+ type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
2898
+
2899
+ // Input type mappings for form fields
2900
+ type InputTypeMap = {
2901
+ text: string;
2902
+ email: string;
2903
+ password: string;
2904
+ url: string;
2905
+ tel: string;
2906
+ search: string;
2907
+ number: number;
2908
+ range: number;
2909
+ date: string;
2910
+ 'datetime-local': string;
2911
+ time: string;
2912
+ month: string;
2913
+ week: string;
2914
+ color: string;
2915
+ checkbox: boolean | string[];
2916
+ radio: string;
2917
+ file: File;
2918
+ hidden: string | number | boolean;
2919
+ submit: string | number | boolean;
2920
+ button: string;
2921
+ reset: string;
2922
+ image: string;
2923
+ select: string;
2924
+ 'select multiple': string[];
2925
+ 'file multiple': File[];
2926
+ };
2927
+
2928
+ // Valid input types for a given value type
2929
+ export type RemoteFormFieldType<T> = {
2930
+ [K in keyof InputTypeMap]: T extends InputTypeMap[K] ? K : never;
2931
+ }[keyof InputTypeMap];
2932
+
2933
+ // Input element properties based on type
2934
+ type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'radio'
2935
+ ? {
2936
+ name: string;
2937
+ type: T;
2938
+ value?: string;
2939
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2940
+ get checked(): boolean;
2941
+ set checked(value: boolean);
2942
+ readonly defaultChecked?: boolean;
2943
+ }
2944
+ : T extends 'file'
2945
+ ? {
2946
+ name: string;
2947
+ type: 'file';
2948
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2949
+ get files(): FileList | null;
2950
+ set files(v: FileList | null);
2951
+ }
2952
+ : T extends 'select'
2953
+ ? {
2954
+ name: string;
2955
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2956
+ get value(): string;
2957
+ set value(v: string);
2958
+ }
2959
+ : T extends 'select multiple'
2960
+ ? {
2961
+ name: string;
2962
+ multiple: true;
2963
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2964
+ get value(): string[];
2965
+ set value(v: string[]);
2966
+ }
2967
+ : T extends 'text'
2968
+ ? {
2969
+ name: string;
2970
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2971
+ get value(): string | number;
2972
+ set value(v: string | number);
2973
+ readonly defaultValue?: string | number;
2974
+ }
2975
+ : {
2976
+ name: string;
2977
+ type: T;
2978
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2979
+ get value(): string | number;
2980
+ set value(v: string | number);
2981
+ readonly defaultValue?: string | number;
2982
+ };
2983
+
2984
+ type RemoteFormFieldMethods<T> = {
2985
+ /** The values that will be submitted */
2986
+ value(): DeepPartial<T>;
2987
+ /** Set the values that will be submitted */
2988
+ set(input: DeepPartial<T>): DeepPartial<T>;
2989
+ /** Whether the field or any nested field has been interacted with since the form was mounted */
2990
+ touched(): boolean;
2991
+ /** Whether the field or any nested field has been edited since the form was mounted */
2992
+ dirty(): boolean;
2993
+ /** Validation issues, if any */
2994
+ issues(): RemoteFormIssue[] | undefined;
2995
+ };
3038
2996
 
3039
- export interface NavigationBase {
3040
- /**
3041
- * The type of navigation:
3042
- * - `enter`: The app has hydrated/started
3043
- * - `form`: The user submitted a `<form method="GET">`
3044
- * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
3045
- * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
3046
- * - `link`: Navigation was triggered by a link click
3047
- * - `popstate`: Navigation was triggered by back/forward navigation
3048
- */
3049
- type: NavigationType;
3050
- /** Whether this is a shallow navigation. */
3051
- shallow: boolean;
3052
- /**
3053
- * Where navigation was triggered from
3054
- */
3055
- from: NavigationTarget | null;
3056
- /**
3057
- * Where navigation is going to/has gone to
3058
- */
3059
- to: NavigationTarget | null;
3060
- /**
3061
- * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
3062
- */
3063
- willUnload: boolean;
3064
- /**
3065
- * A promise that resolves once the navigation is complete, and rejects if the navigation
3066
- * fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
3067
- */
3068
- complete: Promise<void>;
3069
- }
2997
+ // These two types use "T extends unknown ? .. : .." to distribute over unions.
2998
+ // Example: if "type T = A | b" then "keyof T" only contains keys that both A and B have, with "KeysOfUnion<T>" we get the keys of both A and B
2999
+ type KeysOfUnion<T> = T extends unknown ? keyof T : never;
3000
+ type ValueOfUnionKey<T, K extends PropertyKey> = T extends unknown
3001
+ ? K extends keyof T
3002
+ ? T[K]
3003
+ : never
3004
+ : never;
3005
+
3006
+ export type RemoteFormFieldValue = string | string[] | number | boolean | File | File[];
3007
+
3008
+ type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
3009
+ ? Value extends string[]
3010
+ ? [type: Type, value: Value[number] | (string & {})]
3011
+ : Value extends boolean
3012
+ ? [type: Type] | [type: Type, value: boolean]
3013
+ : [type: Type] | [type: Type, value: Value | (string & {})]
3014
+ : Type extends 'submit' | 'hidden'
3015
+ ? Value extends string
3016
+ ? [type: Type, value: Value | (string & {})]
3017
+ : [type: Type, value: Value]
3018
+ : Type extends 'radio'
3019
+ ? [type: Type, value: Value | (string & {})]
3020
+ : Type extends 'file' | 'file multiple'
3021
+ ? [type: Type]
3022
+ : [type: Type] | [type: Type, value: Value | undefined];
3070
3023
 
3071
3024
  /**
3072
- * The navigation that occurs when the app starts/hydrates
3025
+ * Form field accessor type that provides name(), value(), and issues() methods
3073
3026
  */
3074
- export interface NavigationEnter extends NavigationBase {
3075
- type: 'enter';
3076
-
3027
+ export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
3077
3028
  /**
3078
- * In case of a history back/forward navigation, the number of steps to go back/forward
3029
+ * Returns an object that can be spread onto an input element with the correct type attribute,
3030
+ * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
3031
+ * @example
3032
+ * ```svelte
3033
+ * <input {...myForm.fields.myString.as('text')} />
3034
+ * <input {...myForm.fields.myNumber.as('number')} />
3035
+ * <input {...myForm.fields.myBoolean.as('checkbox')} />
3036
+ * ```
3079
3037
  */
3080
- delta?: undefined;
3038
+ as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
3039
+ };
3040
+
3041
+ type RemoteFormFieldContainer<Value> = RemoteFormFieldMethods<Value> & {
3042
+ /** Validation issues belonging to this or any of the fields that belong to it, if any */
3043
+ allIssues(): RemoteFormIssue[] | undefined;
3044
+ };
3081
3045
 
3046
+ type UnknownField<Value> = RemoteFormFieldMethods<Value> & {
3047
+ /** Validation issues belonging to this or any of the fields that belong to it, if any */
3048
+ allIssues(): RemoteFormIssue[] | undefined;
3082
3049
  /**
3083
- * Dispatched `Event` object when navigation occurred by `popstate` or `link`.
3050
+ * Returns an object that can be spread onto an input element with the correct type attribute,
3051
+ * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
3052
+ * @example
3053
+ * ```svelte
3054
+ * <input {...myForm.fields.myString.as('text')} />
3055
+ * <input {...myForm.fields.myNumber.as('number')} />
3056
+ * <input {...myForm.fields.myBoolean.as('checkbox')} />
3057
+ * ```
3084
3058
  */
3085
- event?: undefined;
3086
- }
3059
+ as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
3060
+ } & {
3061
+ [key: string | number]: UnknownField<any>;
3062
+ };
3087
3063
 
3088
- export type NavigationExternal = NavigationGoto | NavigationLeave;
3064
+ type RemoteFormFieldsRoot<Input extends RemoteFormInput | void> =
3065
+ IsAny<Input> extends true
3066
+ ? RecursiveFormFields
3067
+ : Input extends void
3068
+ ? {
3069
+ /** Validation issues, if any */
3070
+ issues(): RemoteFormIssue[] | undefined;
3071
+ /** Validation issues belonging to this or any of the fields that belong to it, if any */
3072
+ allIssues(): RemoteFormIssue[] | undefined;
3073
+ }
3074
+ : RemoteFormFields<Input>;
3089
3075
 
3090
3076
  /**
3091
- * A navigation triggered by a `goto(...)` call or a redirect
3077
+ * Recursive type to build form fields structure with proxy access
3092
3078
  */
3093
- export interface NavigationGoto extends NavigationBase {
3094
- type: 'goto';
3079
+ export type RemoteFormFields<T> =
3080
+ WillRecurseIndefinitely<T> extends true
3081
+ ? RecursiveFormFields
3082
+ : NonNullable<T> extends string | number | boolean | File
3083
+ ? RemoteFormField<NonNullable<T>>
3084
+ : // [NonNullable<T>] is used to prevent distributing over union while still allowing
3085
+ // nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
3086
+ // to be treated as arrays; only the last condition should distribute over unions
3087
+ [NonNullable<T>] extends [string[] | File[]]
3088
+ ? RemoteFormField<NonNullable<T>> & {
3089
+ [K in number]: RemoteFormField<NonNullable<T>[number]>;
3090
+ }
3091
+ : [NonNullable<T>] extends [Array<infer U>]
3092
+ ? RemoteFormFieldContainer<NonNullable<T>> & {
3093
+ [K in number]: RemoteFormFields<U>;
3094
+ }
3095
+ : RemoteFormFieldContainer<T> & {
3096
+ [K in KeysOfUnion<T>]-?: RemoteFormFields<ValueOfUnionKey<T, K>>;
3097
+ };
3098
+
3099
+ // By breaking this out into its own type, we avoid the TS recursion depth limit
3100
+ type RecursiveFormFields = RemoteFormFieldContainer<any> & {
3101
+ [key: string | number]: UnknownField<any>;
3102
+ };
3103
+
3104
+ type MaybeArray<T> = T | T[];
3105
+
3106
+ export interface RemoteFormInput {
3107
+ [key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
3095
3108
  }
3096
3109
 
3097
- /**
3098
- * A navigation triggered by the tab being closed, or the user navigating to a different document
3099
- */
3100
- export interface NavigationLeave extends NavigationBase {
3101
- type: 'leave';
3110
+ export interface RemoteFormIssue {
3111
+ message: string;
3112
+ path: Array<string | number>;
3102
3113
  }
3103
3114
 
3115
+ // If the schema specifies `id` as a string or number, ensure that `for(...)`
3116
+ // only accepts that type. Otherwise, accept `string | number`
3117
+ type ExtractId<Input> = Input extends { id: infer Id }
3118
+ ? Id extends string | number
3119
+ ? Id
3120
+ : string | number
3121
+ : string | number;
3122
+
3104
3123
  /**
3105
- * A navigation triggered by a `<form method="GET">`
3124
+ * A function and proxy object used to imperatively create validation errors in form handlers.
3125
+ *
3126
+ * Access properties to create field-specific issues: `issue.fieldName('message')`.
3127
+ * The type structure mirrors the input data structure for type-safe field access.
3128
+ * Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
3106
3129
  */
3107
- export interface NavigationFormSubmit extends NavigationBase {
3108
- type: 'form';
3109
-
3110
- /**
3111
- * The `SubmitEvent` that caused the navigation
3112
- */
3113
- event: SubmitEvent;
3114
- }
3130
+ export type RemoteFormInvalidField<T> =
3131
+ WillRecurseIndefinitely<T> extends true
3132
+ ? Record<string | number, any>
3133
+ : NonNullable<T> extends string | number | boolean | File
3134
+ ? (message: string) => StandardSchemaV1.Issue
3135
+ : NonNullable<T> extends Array<infer U>
3136
+ ? {
3137
+ [K in number]: RemoteFormInvalidField<U>;
3138
+ } & ((message: string) => StandardSchemaV1.Issue)
3139
+ : NonNullable<T> extends RemoteFormInput
3140
+ ? {
3141
+ [K in keyof T]-?: RemoteFormInvalidField<T[K]>;
3142
+ } & ((message: string) => StandardSchemaV1.Issue)
3143
+ : Record<string, never>;
3115
3144
 
3116
3145
  /**
3117
- * A navigation triggered by back/forward navigation
3146
+ * The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
3118
3147
  */
3119
- export interface NavigationPopState extends NavigationBase {
3120
- type: 'popstate';
3121
-
3122
- /**
3123
- * In case of a history back/forward navigation, the number of steps to go back/forward
3124
- */
3125
- delta: number;
3126
-
3127
- /**
3128
- * The `PopStateEvent` that caused the navigation
3129
- */
3130
- event: PopStateEvent;
3131
- }
3148
+ export type RemoteFormEnhanceInstance<
3149
+ Input extends RemoteFormInput | void = RemoteFormInput | void,
3150
+ Output = any
3151
+ > = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
3152
+ readonly element: HTMLFormElement;
3153
+ };
3132
3154
 
3133
3155
  /**
3134
- * A navigation triggered by a link click
3156
+ * The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
3135
3157
  */
3136
- export interface NavigationLink extends NavigationBase {
3137
- type: 'link';
3138
-
3139
- /**
3140
- * The `PointerEvent` that caused the navigation
3141
- */
3142
- event: PointerEvent;
3143
- }
3144
-
3145
- export type Navigation =
3146
- | NavigationExternal
3147
- | NavigationFormSubmit
3148
- | NavigationPopState
3149
- | NavigationLink;
3158
+ export type RemoteFormEnhanceCallback<
3159
+ Input extends RemoteFormInput | void = RemoteFormInput | void,
3160
+ Output = any
3161
+ > = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
3150
3162
 
3151
3163
  /**
3152
- * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
3164
+ * The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
3153
3165
  */
3154
- export type BeforeNavigate = Navigation & {
3166
+ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
3167
+ /** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
3168
+ [attachment: symbol]: (node: HTMLFormElement) => void;
3169
+ method: 'POST';
3170
+ /** The URL to send the form to. */
3171
+ action: string;
3172
+ /** The `<form>` element this instance is currently attached to, if any. */
3173
+ get element(): HTMLFormElement | null;
3174
+ /** Submit the currently attached form programmatically. */
3175
+ submit(): Promise<boolean> & {
3176
+ updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
3177
+ };
3178
+ /** Use the `enhance` method to influence what happens when the form is submitted. */
3179
+ enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
3180
+ method: 'POST';
3181
+ action: string;
3182
+ [attachment: symbol]: (node: HTMLFormElement) => void;
3183
+ };
3155
3184
  /**
3156
- * Call this to prevent the navigation from starting.
3185
+ * Create an instance of the form for the given `id`.
3186
+ * The `id` is stringified and used for deduplication to potentially reuse existing instances.
3187
+ * Useful when you have multiple forms that use the same remote form action, for example in a loop.
3188
+ * ```svelte
3189
+ * {#each todos as todo}
3190
+ * {const todoForm = updateTodo.for(todo.id)}
3191
+ * <form {...todoForm}>
3192
+ * {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
3193
+ * ...
3194
+ * </form>
3195
+ * {/each}
3196
+ * ```
3157
3197
  */
3158
- cancel: () => void;
3198
+ for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
3199
+ /** Preflight checks */
3200
+ preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
3201
+ /** Validate the form contents programmatically */
3202
+ validate(options?: {
3203
+ /**
3204
+ * Set this to `true` to also show validation issues of fields that haven't yet been
3205
+ * edited and blurred. This option is ignored for forms that have previously been
3206
+ * submitted, in which case all fields are always subject to validation
3207
+ * (unless the form is reset, at which point it is treated as pristine)
3208
+ */
3209
+ all?: boolean;
3210
+ /** Set this to `true` to only run the `preflight` validation. */
3211
+ preflightOnly?: boolean;
3212
+ }): Promise<void>;
3213
+ /** The result of the form submission */
3214
+ get result(): Output | undefined;
3215
+ /** The number of pending submissions */
3216
+ get pending(): number;
3217
+ /** True if the form has been submitted at least once, and hasn't been reset since */
3218
+ get submitted(): boolean;
3219
+ /** Access form fields using object notation */
3220
+ fields: RemoteFormFieldsRoot<Input>;
3159
3221
  };
3160
3222
 
3161
3223
  /**
3162
- * The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
3224
+ * The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
3163
3225
  */
3164
- export type OnNavigate = Navigation & {
3165
- type: Exclude<NavigationType, 'enter' | 'leave'>;
3166
- /**
3167
- * Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
3168
- */
3169
- willUnload: false;
3226
+ export type RemoteCommand<Input, Output> = {
3227
+ (arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
3228
+ updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
3229
+ };
3230
+ /** The number of pending command executions */
3231
+ get pending(): number;
3170
3232
  };
3171
3233
 
3172
- /**
3173
- * The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
3174
- */
3175
- export type AfterNavigate = (Navigation | NavigationEnter) & {
3176
- type: Exclude<NavigationType, 'leave'>;
3234
+ export type RemoteQueryUpdate =
3235
+ | RemoteQuery<any>
3236
+ | RemoteLiveQuery<any>
3237
+ | RemoteQueryFunction<any, any>
3238
+ | RemoteLiveQueryFunction<any, any>
3239
+ | RemoteQueryOverride;
3240
+
3241
+ export type RemoteResource<T> = Promise<T> & {
3242
+ /** The error in case the query fails. */
3243
+ get error(): App.Error | undefined;
3244
+ /** `true` before the first result is available and during refreshes */
3245
+ get loading(): boolean;
3246
+ } & (
3247
+ | {
3248
+ /** The current value of the query. Undefined until `ready` is `true` */
3249
+ get current(): undefined;
3250
+ ready: false;
3251
+ }
3252
+ | {
3253
+ /** The current value of the query. Undefined until `ready` is `true` */
3254
+ get current(): T;
3255
+ ready: true;
3256
+ }
3257
+ );
3258
+
3259
+ export type RemoteQuery<T> = RemoteResource<T> & {
3177
3260
  /**
3178
- * Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
3261
+ * On the client, this function will update the value of the query without re-fetching it.
3262
+ *
3263
+ * On the server, this can be called in the context of a `command` or `form` and the specified data will accompany the action response back to the client.
3264
+ * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
3179
3265
  */
3180
- willUnload: false;
3181
- };
3182
- /**
3183
- * A lifecycle function that captures state before navigating and restores it when traversing history.
3184
- *
3185
- * By default, the snapshot `id` is generated from the call site. Pass an explicit `id` to keep snapshots stable across deployments or distinguish multiple uses of a shared helper.
3186
- *
3187
- * The optional `reset` callback runs on navigations where there is no captured value to restore, such as when a new history entry is created. Captured values are serialized with the app's transport hook.
3188
- *
3189
- * `snapshot` must be called during a component initialization. It remains active as long as the component is mounted.
3190
- * */
3191
- export function snapshot<T>(options: {
3192
- id?: string;
3193
- capture: () => T;
3194
- restore: (value: T) => void;
3195
- reset?: () => void;
3196
- }): void;
3197
- /**
3198
- * A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a URL.
3199
- *
3200
- * `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3201
- * */
3202
- export function afterNavigate(callback: (navigation: AfterNavigate) => void): void;
3203
- /**
3204
- * A navigation interceptor that triggers before we navigate to a URL, whether by clicking a link, calling `goto(...)`, or using the browser back/forward controls.
3205
- *
3206
- * Calling `cancel()` will prevent the navigation from completing. If `navigation.type === 'leave'` — meaning the user is navigating away from the app (or closing the tab) — calling `cancel` will trigger the native browser unload confirmation dialog. In this case, the navigation may or may not be cancelled depending on the user's response.
3207
- *
3208
- * When a navigation isn't to a SvelteKit-owned route (and therefore controlled by SvelteKit's client-side router), `navigation.to.route.id` will be `null`.
3209
- *
3210
- * If the navigation will (if not cancelled) cause the document to unload — in other words `'leave'` navigations and `'link'` navigations where `navigation.to.route === null` — `navigation.willUnload` is `true`.
3211
- *
3212
- * `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3213
- * */
3214
- export function beforeNavigate(callback: (navigation: BeforeNavigate) => void): void;
3215
- /**
3216
- * A lifecycle function that runs the supplied `callback` immediately before we navigate to a new URL except during full-page navigations.
3217
- *
3218
- * If you return a `Promise`, SvelteKit will wait for it to resolve before completing the navigation. This allows you to — for example — use `document.startViewTransition`. Avoid promises that are slow to resolve, since navigation will appear stalled to the user.
3219
- *
3220
- * If a function (or a `Promise` that resolves to a function) is returned from the callback, it will be called once the DOM has updated.
3221
- *
3222
- * `onNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
3223
- * */
3224
- export function onNavigate(callback: (navigation: OnNavigate) => MaybePromise<(() => void) | void>): void;
3225
- /**
3226
- * If called when the page is being updated following a navigation (in `onMount` or `afterNavigate` or an action, for example), this disables SvelteKit's built-in scroll handling.
3227
- * This is generally discouraged, since it breaks user expectations.
3228
- * */
3229
- export function disableScrollHandling(): void;
3230
- /**
3231
- * Allows you to navigate programmatically to a given route, with control over details such as whether scroll and focus are reset
3232
- * (as they would be with a regular navigation) or preserved.
3233
- *
3234
- * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) or the state change has been applied.
3235
- *
3236
- * `goto` is intended for navigations to routes that belong to the app, and will reject if a route cannot be resolved.
3237
- * For external URLs, use `window.location = url` to perform a full-page navigation instead of calling `goto(url)`.
3238
- *
3239
- * @param url Where to navigate to. Note that if you've set [`config.paths.base`](https://svelte.dev/docs/kit/configuration#paths) and the URL is root-relative, you need to prepend the base path if you want to navigate within the app.
3240
- * @param opts Options related to the navigation
3241
- * */
3242
- export function goto(url: string | URL, opts?: GotoOptions): Promise<void>;
3243
- /**
3244
- * Causes any `load` functions belonging to the currently active page to re-run if they depend on the `url` in question, via `fetch` or `depends`. Returns a `Promise` that resolves when the page is subsequently updated.
3245
- *
3246
- * If the argument is given as a `string` or `URL`, it must resolve to the same URL that was passed to `fetch` or `depends` (including query parameters).
3247
- * To create a custom identifier, use a string beginning with `[a-z]+:` (e.g. `custom:state`) — this is a valid URL.
3248
- *
3249
- * The `function` argument can be used define a custom predicate. It receives the full `URL` and causes `load` to rerun if `true` is returned.
3250
- * This can be useful if you want to invalidate based on a pattern instead of a exact match.
3251
- *
3252
- * ```ts
3253
- * // Example: Match '/path' regardless of the query parameters
3254
- * import { invalidate } from '$app/navigation';
3255
- *
3256
- * invalidate((url) => url.pathname === '/path');
3257
- * ```
3258
- * @param resource The invalidated URL
3259
- * @param keepState If `true`, the current `page.state` will be preserved. Otherwise, it will be reset to an empty object. `false` by default.
3260
- * */
3261
- export function invalidate(resource: string | URL | ((url: URL) => boolean), keepState?: boolean): Promise<void>;
3262
- /**
3263
- * Causes all `load` and `query` functions belonging to the currently active page to re-run. Returns a `Promise` that resolves when the page is subsequently updated.
3264
- *
3265
- * Note that this resets `page.state` to an empty object. If you want to preserve `page.state` (for example when using [shallow routing](https://svelte.dev/docs/kit/shallow-routing)), use `refreshAll` instead.
3266
- *
3267
- * @deprecated Use [`refreshAll`](https://svelte.dev/docs/kit/$app-navigation#refreshAll) instead. Unlike `invalidateAll`, `refreshAll` does not reset `page.state`.
3268
- * */
3269
- export function invalidateAll(): Promise<void>;
3270
- /**
3271
- * Causes all currently active remote functions to refresh, and all `load` functions belonging to the currently active page to re-run.
3272
- * Returns a `Promise` that resolves when the page is subsequently updated.
3273
- * */
3274
- export function refreshAll(): Promise<void>;
3275
- /**
3276
- * Programmatically preloads the given page, which means
3277
- * 1. ensuring that the code for the page is loaded, and
3278
- * 2. calling the page's load function with the appropriate options.
3279
- *
3280
- * This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.
3281
- * If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
3282
- * Returns a Promise that resolves with the result of running the new route's `load` functions once the preload is complete.
3283
- *
3284
- * @param href Page to preload
3285
- * */
3286
- export function preloadData(href: string): Promise<({
3287
- type: "loaded";
3288
- data: Record<string, any>;
3289
- } | {
3290
- type: "redirect";
3291
- location: string;
3292
- } | {
3293
- type: "error";
3294
- error: App.Error;
3295
- }) & {
3296
- status: number;
3297
- }>;
3298
- /**
3299
- * Programmatically imports the code for routes that haven't yet been fetched.
3300
- * Typically, you might call this to speed up subsequent navigation.
3301
- *
3302
- * Takes a route ID such as `/about` or `/blog/[slug]`. Unlike pathnames, route IDs
3303
- * are never prefixed with the app's [base path](https://svelte.dev/docs/kit/configuration#paths).
3304
- * If you have a pathname rather than a route ID, you can convert it with
3305
- * [`match`](https://svelte.dev/docs/kit/$app-paths#match) from `$app/paths`:
3306
- *
3307
- * ```js
3308
- * import { match } from '$app/paths';
3309
- * import { preloadCode } from '$app/navigation';
3310
- *
3311
- * const matched = await match('/blog/hello-world');
3312
- * if (matched) await preloadCode(matched.id);
3313
- * ```
3314
- *
3315
- * Unlike `preloadData`, this won't call `load` functions.
3316
- * Returns a Promise that resolves when the modules have been imported.
3317
- *
3318
- * */
3319
- export function preloadCode(id: import("$app/types").RouteId): Promise<void>;
3266
+ set(value: T): void;
3267
+ /**
3268
+ * On the client, this function will re-fetch the query from the server.
3269
+ *
3270
+ * On the server, this can be called in the context of a `command` or `form` and the refreshed data will accompany the action response back to the client.
3271
+ * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
3272
+ */
3273
+ refresh(): Promise<void>;
3274
+ /**
3275
+ * Temporarily override a query's value during a [single-flight mutation](https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations) to provide optimistic updates.
3276
+ *
3277
+ * ```svelte
3278
+ * <script>
3279
+ * import { getTodos, addTodo } from './todos.remote.js';
3280
+ * const todos = getTodos();
3281
+ * </script>
3282
+ *
3283
+ * <form {...addTodo.enhance(async (form) => {
3284
+ * await form.submit().updates(
3285
+ * todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
3286
+ * );
3287
+ * })}>
3288
+ * <input type="text" name="text" />
3289
+ * <button type="submit">Add Todo</button>
3290
+ * </form>
3291
+ * ```
3292
+ */
3293
+ withOverride(update: (current: T) => T): RemoteQueryOverride;
3294
+ };
3295
+
3296
+ export type RemoteLiveQuery<T> = RemoteResource<T> &
3297
+ AsyncIterable<T> & {
3298
+ /** `true` if the live stream is currently connected. */
3299
+ readonly connected: boolean;
3300
+ /** `true` once the current live stream iterator is done. */
3301
+ readonly done: boolean;
3302
+ /** Reconnects the live stream immediately. */
3303
+ reconnect(): Promise<void>;
3304
+ };
3305
+
3306
+ export type RemoteQueryOverride = () => void;
3307
+
3320
3308
  /**
3321
- * Programmatically create a new history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
3322
- *
3323
- * @deprecated Use `goto(url, { state, shallow: true })` instead.
3324
- * */
3325
- export function pushState(url: string | URL, state: App.PageState): Promise<void>;
3309
+ * The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
3310
+ */
3311
+ export type RemotePrerenderFunction<Input, Output> = (
3312
+ arg: undefined extends Input ? Input | void : Input
3313
+ ) => RemoteResource<Output>;
3314
+
3326
3315
  /**
3327
- * Programmatically replace the current history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
3316
+ * The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
3328
3317
  *
3329
- * @deprecated Use `goto(url, { state, shallow: true, replace: true })` instead.
3330
- * */
3331
- export function replaceState(url: string | URL, state: App.PageState): Promise<void>;
3332
- type MaybePromise<T> = T | Promise<T>;
3333
-
3334
- export {};
3335
- }
3318
+ * The optional `Validated` generic parameter represents the argument type *after* the
3319
+ * query's schema has validated and (optionally) transformed it — this is the type the
3320
+ * query's implementation function receives on the server, and the type yielded by
3321
+ * [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
3322
+ * with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
3323
+ * schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
3324
+ * `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
3325
+ * without arguments it defaults to `Input`.
3326
+ */
3327
+ export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
3328
+ arg: undefined extends Input ? Input | void : Input
3329
+ ) => RemoteQuery<Output>;
3336
3330
 
3337
- declare module '$app/paths' {
3338
- import type { AssetPath, RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname, RouteId, RouteParams } from '$app/types';
3339
3331
  /**
3340
- * Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
3341
- *
3342
- * During server rendering, the base path is relative and depends on the page currently being rendered.
3343
- *
3344
- * @example
3345
- * ```svelte
3346
- * <script>
3347
- * import { asset } from '$app/paths';
3348
- * </script>
3349
- *
3350
- * <img alt="a potato" src={asset('potato.jpg')} />
3351
- * ```
3352
- * @since 2.26
3332
+ * The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
3353
3333
  *
3354
- * */
3355
- export function asset(file: AssetPath): string;
3334
+ * The optional `Validated` generic parameter represents the argument type *after* the
3335
+ * query's schema has validated and (optionally) transformed it, and matches the type
3336
+ * yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
3337
+ */
3338
+ export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
3339
+ arg: undefined extends Input ? Input | void : Input
3340
+ ) => RemoteLiveQuery<Output>;
3341
+
3356
3342
  /**
3357
- * Resolve a pathname by prefixing it with the base path, if any, or resolve a route ID by populating dynamic segments with parameters.
3358
- *
3359
- * During server rendering, the base path is relative and depends on the page currently being rendered.
3360
- *
3361
- * @example
3362
- * ```js
3363
- * import { resolve } from '$app/paths';
3364
- *
3365
- * // using a pathname
3366
- * const resolved = resolve(`blog/hello-world`);
3367
- *
3368
- * // using a route ID plus parameters
3369
- * const resolved = resolve('/blog/[slug]', {
3370
- * slug: 'hello-world'
3371
- * });
3372
- * ```
3373
- * @since 2.26
3374
- *
3375
- * */
3376
- export function resolve<T extends RouteIdWithSearchOrHash | PathnameWithSearchOrHash>(...args: ResolveArgs<T>): ResolvedPathname;
3343
+ * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
3344
+ * when called with a regular `query`. `arg` is the validated argument (the input *after*
3345
+ * the query's schema validated and transformed it, if applicable); `query` is a
3346
+ * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
3347
+ * update the correct client entry.
3348
+ */
3349
+ export type RequestedEntry<Validated, Output> = {
3350
+ arg: Validated;
3351
+ query: RemoteQuery<Output>;
3352
+ };
3353
+
3377
3354
  /**
3378
- * Match a path or URL to a route ID and extracts any parameters.
3379
- *
3380
- * @example
3381
- * ```js
3382
- * import { match } from '$app/paths';
3383
- *
3384
- * const route = await match('blog/hello-world');
3385
- *
3386
- * if (route?.id === '/blog/[slug]') {
3387
- * const slug = route.params.slug;
3388
- * const response = await fetch(`/api/posts/${slug}`);
3389
- * const post = await response.json();
3390
- * }
3391
- * ```
3392
- * @since 2.52.0
3393
- *
3394
- * */
3395
- export function match(url: URL | string): Promise<{ [K in RouteId]: {
3396
- id: K;
3397
- params: RouteParams<K>;
3398
- }; }[RouteId] | null>;
3399
- type StripSearchOrHash<T extends string> = T extends `${infer U}?${string}`
3400
- ? U
3401
- : T extends `${infer U}#${string}`
3402
- ? U
3403
- : T;
3355
+ * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
3356
+ * when called with a `query.live`. `arg` is the validated argument; `query` is a
3357
+ * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
3358
+ * the correct client subscription.
3359
+ */
3360
+ export type RemoteLiveQueryRequestedEntry<Validated, Output> = {
3361
+ arg: Validated;
3362
+ query: RemoteLiveQuery<Output>;
3363
+ };
3404
3364
 
3405
- type ResolveArgs<T> = T extends `/${string}`
3406
- ? StripSearchOrHash<T> extends infer U extends RouteId
3407
- ? RouteParams<U> extends Record<string, never>
3408
- ? [route: T]
3409
- : [route: T, params: RouteParams<U>]
3410
- : [never]
3411
- : [pathname: T];
3365
+ export type RemoteQueryRequestedResult<Validated, Output> = Iterable<
3366
+ RequestedEntry<Validated, Output>
3367
+ > &
3368
+ AsyncIterable<RequestedEntry<Validated, Output>> & {
3369
+ /**
3370
+ * Call `refresh` on all queries selected by this `requested` invocation.
3371
+ * This is identical to:
3372
+ * ```ts
3373
+ * import { requested } from '$app/server';
3374
+ *
3375
+ * for await (const { query } of requested(getPost, ...)) {
3376
+ * void query.refresh();
3377
+ * }
3378
+ * ```
3379
+ */
3380
+ refreshAll: () => Promise<void>;
3381
+ };
3412
3382
 
3413
- export {};
3414
- }
3383
+ export type RemoteLiveQueryRequestedResult<Validated, Output> = Iterable<
3384
+ RemoteLiveQueryRequestedEntry<Validated, Output>
3385
+ > &
3386
+ AsyncIterable<RemoteLiveQueryRequestedEntry<Validated, Output>> & {
3387
+ /**
3388
+ * Call `reconnect` on all live queries selected by this `requested` invocation.
3389
+ * This is identical to:
3390
+ * ```ts
3391
+ * import { requested } from '$app/server';
3392
+ *
3393
+ * for await (const { query } of requested(liveQuery, ...)) {
3394
+ * void query.reconnect();
3395
+ * }
3396
+ * ```
3397
+ */
3398
+ reconnectAll: () => Promise<void>;
3399
+ };
3415
3400
 
3416
- declare module '$app/server' {
3417
- import type { StandardSchemaV1 } from '@standard-schema/spec';
3418
- import type { RequestEvent } from '@sveltejs/kit';
3419
- import type { RemoteCommand, RemoteForm, RemoteFormInput, InvalidField, RemotePrerenderFunction, RemoteQueryFunction, RemoteLiveQueryFunction, QueryRequestedResult, LiveQueryRequestedResult } from '@sveltejs/kit/remote';
3401
+ export type RequestedResult<Validated, Output> =
3402
+ | RemoteQueryRequestedResult<Validated, Output>
3403
+ | RemoteLiveQueryRequestedResult<Validated, Output>;
3404
+ type RemoteLiveQueryUserFunctionReturnType<Output> = MaybePromise<
3405
+ | AsyncGenerator<Output>
3406
+ | AsyncIterator<Output>
3407
+ | AsyncIterable<Output>
3408
+ | Generator<Output>
3409
+ | Iterator<Output>
3410
+ | Iterable<Output>
3411
+ >;
3412
+ type RemotePrerenderInputsGenerator<Input = any> = () => MaybePromise<Input[]>;
3420
3413
  /**
3421
3414
  * Read the contents of an imported asset from the filesystem
3422
3415
  * @example
@@ -3430,6 +3423,28 @@ declare module '$app/server' {
3430
3423
  * @since 2.4.0
3431
3424
  */
3432
3425
  export function read(asset: string): Response;
3426
+ type MaybePromise<T> = T | Promise<T>;
3427
+
3428
+ type DeepPartial<T> = T extends Record<PropertyKey, unknown> | unknown[]
3429
+ ? {
3430
+ [K in keyof T]?: T[K] extends Record<PropertyKey, unknown> | unknown[]
3431
+ ? DeepPartial<T[K]>
3432
+ : T[K];
3433
+ }
3434
+ : T | undefined;
3435
+
3436
+ type IsAny<T> = 0 extends 1 & T ? true : false;
3437
+
3438
+ type HasNonOptionalBoolean<T> =
3439
+ IsAny<T> extends true
3440
+ ? never
3441
+ : [T] extends [boolean]
3442
+ ? true
3443
+ : T extends Array<infer U>
3444
+ ? HasNonOptionalBoolean<U>
3445
+ : T extends Record<string, any>
3446
+ ? { [K in keyof T]: HasNonOptionalBoolean<T[K]> }[keyof T]
3447
+ : never;
3433
3448
  /**
3434
3449
  * Returns the current `RequestEvent`. Can be used inside server hooks, server `load` functions, actions, and endpoints (and functions called by them).
3435
3450
  *
@@ -3477,7 +3492,7 @@ declare module '$app/server' {
3477
3492
  *
3478
3493
  * @since 2.27
3479
3494
  */
3480
- export function form<Input extends RemoteFormInput, Output>(validate: "unchecked", fn: (data: Input, issue: InvalidField<Input>) => MaybePromise<Output>): RemoteForm<Input, Output>;
3495
+ export function form<Input extends RemoteFormInput, Output>(validate: "unchecked", fn: (data: Input, issue: RemoteFormInvalidField<Input>) => MaybePromise<Output>): RemoteForm<Input, Output>;
3481
3496
  /**
3482
3497
  * Creates a form object that can be spread onto a `<form>` element.
3483
3498
  *
@@ -3485,7 +3500,7 @@ declare module '$app/server' {
3485
3500
  *
3486
3501
  * @since 2.27
3487
3502
  */
3488
- export function form<Schema extends StandardSchemaV1<RemoteFormInput, Record<string, any>>, Output>(validate: true extends HasNonOptionalBoolean<StandardSchemaV1.InferInput<Schema>> ? "Error: All booleans in form schemas must be optional (e.g. `v.optional(v.boolean(), false)`) because checkbox inputs do not send a false value when unchecked." : Schema, fn: (data: StandardSchemaV1.InferOutput<Schema>, issue: InvalidField<StandardSchemaV1.InferInput<Schema>>) => MaybePromise<Output>): RemoteForm<StandardSchemaV1.InferInput<Schema>, Output>;
3503
+ export function form<Schema extends StandardSchemaV1<RemoteFormInput, Record<string, any>>, Output>(validate: true extends HasNonOptionalBoolean<StandardSchemaV1.InferInput<Schema>> ? "Error: All booleans in form schemas must be optional (e.g. `v.optional(v.boolean(), false)`) because checkbox inputs do not send a false value when unchecked." : Schema, fn: (data: StandardSchemaV1.InferOutput<Schema>, issue: RemoteFormInvalidField<StandardSchemaV1.InferInput<Schema>>) => MaybePromise<Output>): RemoteForm<StandardSchemaV1.InferInput<Schema>, Output>;
3489
3504
  /**
3490
3505
  * Creates a remote prerender function. When called from the browser, the function will be invoked on the server via a `fetch` call.
3491
3506
  *
@@ -3613,7 +3628,7 @@ declare module '$app/server' {
3613
3628
  * For live queries, the same applies, but with `reconnect` and `reconnectAll`.
3614
3629
  *
3615
3630
  * */
3616
- export function requested<Input, Output, Validated = Input>(query: RemoteQueryFunction<Input, Output, Validated>, limit: number): QueryRequestedResult<Validated, Output>;
3631
+ export function requested<Input, Output, Validated = Input>(query: RemoteQueryFunction<Input, Output, Validated>, limit: number): RemoteQueryRequestedResult<Validated, Output>;
3617
3632
  /**
3618
3633
  * Inside a remote `command` or `form` callback, returns an iterable
3619
3634
  * of `{ arg, query }` entries for the live query instances the client asked to reconnect, up to
@@ -3645,30 +3660,7 @@ declare module '$app/server' {
3645
3660
  * ```
3646
3661
  *
3647
3662
  * */
3648
- export function requested<Input, Output, Validated = Input>(query: RemoteLiveQueryFunction<Input, Output, Validated>, limit: number): LiveQueryRequestedResult<Validated, Output>;
3649
- type RemoteLiveQueryUserFunctionReturnType<Output> = MaybePromise<
3650
- | AsyncGenerator<Output>
3651
- | AsyncIterator<Output>
3652
- | AsyncIterable<Output>
3653
- | Generator<Output>
3654
- | Iterator<Output>
3655
- | Iterable<Output>
3656
- >;
3657
- type RemotePrerenderInputsGenerator<Input = any> = () => MaybePromise<Input[]>;
3658
- type MaybePromise<T> = T | Promise<T>;
3659
-
3660
- type IsAny<T> = 0 extends 1 & T ? true : false;
3661
-
3662
- type HasNonOptionalBoolean<T> =
3663
- IsAny<T> extends true
3664
- ? never
3665
- : [T] extends [boolean]
3666
- ? true
3667
- : T extends Array<infer U>
3668
- ? HasNonOptionalBoolean<U>
3669
- : T extends Record<string, any>
3670
- ? { [K in keyof T]: HasNonOptionalBoolean<T[K]> }[keyof T]
3671
- : never;
3663
+ export function requested<Input, Output, Validated = Input>(query: RemoteLiveQueryFunction<Input, Output, Validated>, limit: number): RemoteLiveQueryRequestedResult<Validated, Output>;
3672
3664
 
3673
3665
  export {};
3674
3666
  }