```dts
function form<
Schema extends StandardSchemaV1<
RemoteFormInput,
Record
>,
Output
>(
validate: true extends HasNonOptionalBoolean<
StandardSchemaV1.InferInput
>
? '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,
issue: InvalidField>
) => MaybePromise
): RemoteForm, Output>;
```
## getRequestEvent
` for queries
declared with a Standard Schema).
Arguments that fail validation or exceed `limit` are recorded as failures in
the response to the client.
See [Client-requested refreshes](/docs/kit/remote-functions#Single-flight-mutations-Client-requested-refreshes)
for usage in a remote `command` or `form`.
```ts
import { requested } from '$app/server';
for (const { arg, query } of requested(getPost, 5)) {
// `arg` is the validated argument; `query` is bound to the client's
// cache key. It's safe to throw away this promise -- SvelteKit will
// await it and forward any errors to the client.
void query.refresh();
}
```
As a shorthand for the above, you can also call `refreshAll` on the result:
```ts
import { requested } from '$app/server';
await requested(getPost, 5).refreshAll();
```
Works with `query.batch` as well — refreshes for individual entries are
collected into a single batched call.
For live queries, the same applies, but with `reconnect` and `reconnectAll`.
```dts
function requested (
query: RemoteQueryFunction ,
limit: number
): QueryRequestedResult;
```
```dts
function requested (
query: RemoteLiveQueryFunction ,
limit: number
): LiveQueryRequestedResult;
```
## InvalidField
A function and proxy object used to imperatively create validation errors in form handlers.
Access properties to create field-specific issues: `issue.fieldName('message')`.
The type structure mirrors the input data structure for type-safe field access.
Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
```dts
type InvalidField =
WillRecurseIndefinitely extends true
? Record
: NonNullable extends
| string
| number
| boolean
| File
? (message: string) => StandardSchemaV1.Issue
: NonNullable extends Array
? {
[K in number]: InvalidField;
} & ((message: string) => StandardSchemaV1.Issue)
: NonNullable extends RemoteFormInput
? {
[K in keyof T]-?: InvalidField;
} & ((
message: string
) => StandardSchemaV1.Issue)
: Record;
```
## LiveQueryRequestedResult
```dts
type LiveQueryRequestedResult = Iterable<
LiveRequestedEntry
> &
AsyncIterable> & {
/**
* Call `reconnect` on all live queries selected by this `requested` invocation.
* This is identical to:
* ```ts
* import { requested } from '$app/server';
*
* for await (const { query } of requested(liveQuery, ...)) {
* void query.reconnect();
* }
* ```
*/
reconnectAll: () => Promise;
};
```
## LiveRequestedEntry
A single entry yielded by [`requested`](/docs/kit/$app-server#requested)
when called with a `query.live`. `arg` is the validated argument; `query` is a
`RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
the correct client subscription.
```dts
type LiveRequestedEntry = {
arg: Validated;
query: RemoteLiveQuery;
};
```
## QueryRequestedResult
```dts
type QueryRequestedResult = Iterable<
RequestedEntry
> &
AsyncIterable> & {
/**
* Call `refresh` on all queries selected by this `requested` invocation.
* This is identical to:
* ```ts
* import { requested } from '$app/server';
*
* for await (const { query } of requested(getPost, ...)) {
* void query.refresh();
* }
* ```
*/
refreshAll: () => Promise;
};
```
## RemoteCommand
The type of a remote `command` function. See [Remote functions](/docs/kit/remote-functions#command) for full documentation.
```dts
type RemoteCommand = {
(
arg: undefined extends Input ? Input | void : Input
): Promise & {
updates(
...updates: RemoteQueryUpdate[]
): Promise;
};
/** The number of pending command executions */
get pending(): number;
};
```
## RemoteForm
The type of a remote `form` function. See [Remote functions](/docs/kit/remote-functions#form) for full documentation.
```dts
type RemoteForm<
Input extends RemoteFormInput | void,
Output
> = {
/** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
[attachment: symbol]: (node: HTMLFormElement) => void;
method: 'POST';
/** The URL to send the form to. */
action: string;
/** The `
## RemoteFormEnhanceCallback
The callback passed to a remote form's `enhance` method. See [Remote functions](/docs/kit/remote-functions#form) for full documentation.
```dts
type RemoteFormEnhanceCallback<
Input extends RemoteFormInput | void =
RemoteFormInput | void,
Output = any
> = (
form: RemoteFormEnhanceInstance
) => MaybePromise;
```
## RemoteFormEnhanceInstance
The form instance as received inside an `enhance` callback. See [Remote functions](/docs/kit/remote-functions#form) for full documentation.
```dts
type RemoteFormEnhanceInstance<
Input extends RemoteFormInput | void =
RemoteFormInput | void,
Output = any
> = Omit<
RemoteForm ,
'enhance' | 'element'
> & {
readonly element: HTMLFormElement;
};
```
## RemoteFormField
Form field accessor type that provides name(), value(), and issues() methods
```dts
type RemoteFormField =
RemoteFormFieldMethods & {
/**
* Returns an object that can be spread onto an input element with the correct type attribute,
* aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
* @example
* ```svelte
*
*
*
* ```
*/
as>(
...args: AsArgs
): InputElementProps;
};
```
## RemoteFormFieldType
```dts
type RemoteFormFieldType = {
[K in keyof InputTypeMap]: T extends InputTypeMap[K]
? K
: never;
}[keyof InputTypeMap];
```
## RemoteFormFieldValue
```dts
type RemoteFormFieldValue =
| string
| string[]
| number
| boolean
| File
| File[];
```
## RemoteFormFields
Recursive type to build form fields structure with proxy access
```dts
type RemoteFormFields =
WillRecurseIndefinitely extends true
? RecursiveFormFields
: NonNullable extends
| string
| number
| boolean
| File
? RemoteFormField>
: // [NonNullable] is used to prevent distributing over union while still allowing
// nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
// to be treated as arrays; only the last condition should distribute over unions
[NonNullable] extends [string[] | File[]]
? RemoteFormField> & {
[K in number]: RemoteFormField<
NonNullable[number]
>;
}
: [NonNullable] extends [Array]
? RemoteFormFieldContainer> & {
[K in number]: RemoteFormFields;
}
: RemoteFormFieldContainer & {
[K in KeysOfUnion]-?: RemoteFormFields<
ValueOfUnionKey
>;
};
```
## RemoteFormInput
```dts
interface RemoteFormInput {/*…*/}
```
```dts
[key: string]: MaybeArray
| undefined;
```
## RemoteFormIssue
```dts
interface RemoteFormIssue {/*…*/}
```
```dts
message: string;
```
## RemoteLiveQuery
```dts
type RemoteLiveQuery = RemoteResource &
AsyncIterable & {
/** `true` if the live stream is currently connected. */
readonly connected: boolean;
/** `true` once the current live stream iterator is done. */
readonly done: boolean;
/** Reconnects the live stream immediately. */
reconnect(): Promise;
};
```
## RemoteLiveQueryFunction
The type of a remote `query.live` function. See [Remote functions](/docs/kit/remote-functions#query.live) for full documentation.
The optional `Validated` generic parameter represents the argument type *after* the
query's schema has validated and (optionally) transformed it, and matches the type
yielded by [`requested`](/docs/kit/$app-server#requested).
```dts
type RemoteLiveQueryFunction<
Input,
Output,
_Validated = Input
> = (
arg: undefined extends Input ? Input | void : Input
) => RemoteLiveQuery;
```
## RemotePrerenderFunction
The type of a remote `prerender` function. See [Remote functions](/docs/kit/remote-functions#prerender) for full documentation.
```dts
type RemotePrerenderFunction = (
arg: undefined extends Input ? Input | void : Input
) => RemoteResource;
```
## RemoteQuery
```dts
type RemoteQuery = RemoteResource & {
/**
* On the client, this function will update the value of the query without re-fetching it.
*
* 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.
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
*/
set(value: T): void;
/**
* On the client, this function will re-fetch the query from the server.
*
* 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.
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
*/
refresh(): Promise;
/**
* 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.
*
* ```svelte
*
*
* {
* await form.submit().updates(
* todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
* );
* })}>
*
* Add Todo
*
* ```
*/
withOverride(
update: (current: T) => T
): RemoteQueryOverride;
};
```
## RemoteQueryFunction
The return value of a remote `query` function. See [Remote functions](/docs/kit/remote-functions#query) for full documentation.
The optional `Validated` generic parameter represents the argument type *after* the
query's schema has validated and (optionally) transformed it — this is the type the
query's implementation function receives on the server, and the type yielded by
[`requested`](/docs/kit/$app-server#requested). For queries declared
with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
`Input = number` but `Validated = string`). For `'unchecked'` validators and queries
without arguments it defaults to `Input`.
```dts
type RemoteQueryFunction<
Input,
Output,
_Validated = Input
> = (
arg: undefined extends Input ? Input | void : Input
) => RemoteQuery;
```
## RemoteQueryOverride
```dts
type RemoteQueryOverride = () => void;
```
## RemoteQueryUpdate
```dts
type RemoteQueryUpdate =
| RemoteQuery
| RemoteLiveQuery
| RemoteQueryFunction
| RemoteLiveQueryFunction
| RemoteQueryOverride;
```
## RemoteResource
```dts
type RemoteResource = Promise & {
/** The error in case the query fails. */
get error(): App.Error | undefined;
/** `true` before the first result is available and during refreshes */
get loading(): boolean;
} & (
| {
/** The current value of the query. Undefined until `ready` is `true` */
get current(): undefined;
ready: false;
}
| {
/** The current value of the query. Undefined until `ready` is `true` */
get current(): T;
ready: true;
}
);
```
## RequestedEntry
A single entry yielded by [`requested`](/docs/kit/$app-server#requested)
when called with a regular `query`. `arg` is the validated argument (the input *after*
the query's schema validated and transformed it, if applicable); `query` is a
`RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
update the correct client entry.
```dts
type RequestedEntry = {
arg: Validated;
query: RemoteQuery;
};
```
## RequestedResult
```dts
type RequestedResult =
| QueryRequestedResult
| LiveQueryRequestedResult;
```
## ValidationError
A validation error thrown by `invalid`.
```dts
interface ValidationError {/*…*/}
```
```dts
issues: StandardSchemaV1.Issue[];
```
The validation issues
## query
```dts
namespace query {
/**
* Creates a batch query function that collects multiple calls and executes them in a single request
*
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.batch) for full documentation.
*
* @since 2.35
*/
function batch (
validate: 'unchecked',
fn: (
args: Input[]
) => MaybePromise<(arg: Input, idx: number) => Output>
): RemoteQueryFunction ;
/**
* Creates a batch query function that collects multiple calls and executes them in a single request
*
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.batch) for full documentation.
*
* @since 2.35
*/
function batch(
schema: Schema,
fn: (
args: StandardSchemaV1.InferOutput[]
) => MaybePromise<
(
arg: StandardSchemaV1.InferOutput,
idx: number
) => Output
>
): RemoteQueryFunction<
StandardSchemaV1.InferInput,
Output,
StandardSchemaV1.InferOutput
>;
/**
* Creates a live remote query. When called from the browser, the function will be invoked on the server via a streaming `fetch` call.
*
* See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
*
* */
function live(
fn: (
arg: void
) => RemoteLiveQueryUserFunctionReturnType
): RemoteLiveQueryFunction;
function live (
validate: 'unchecked',
fn: (
arg: Input
) => RemoteLiveQueryUserFunctionReturnType
): RemoteLiveQueryFunction ;
function live(
schema: Schema,
fn: (
arg: StandardSchemaV1.InferOutput
) => RemoteLiveQueryUserFunctionReturnType
): RemoteLiveQueryFunction<
StandardSchemaV1.InferInput,
Output,
StandardSchemaV1.InferOutput
>;
}
```