$app/server
import {
function command<Output>(fn: () => Output): RemoteCommand<void, Output> (+2 overloads)Creates a remote command. When called from the browser, the function will be invoked on the server via a fetch call.
See Remote functions for full documentation.
command,
function form<Output>(fn: () => MaybePromise<Output>): RemoteForm<void, Output> (+2 overloads)Creates a form object that can be spread onto a <form> element.
See Remote functions for full documentation.
form,
function getRequestEvent(): RequestEventReturns the current RequestEvent. Can be used inside server hooks, server load functions, actions, and endpoints (and functions called by them).
In environments without AsyncLocalStorage, this must be called synchronously (i.e. not after an await).
getRequestEvent,
function prerender<Output>(fn: () => MaybePromise<Output>, options?: {
inputs?: RemotePrerenderInputsGenerator<void>;
dynamic?: boolean;
} | undefined): RemotePrerenderFunction<void, Output> (+2 overloads)
Creates a remote prerender function. When called from the browser, the function will be invoked on the server via a fetch call.
See Remote functions for full documentation.
prerender,
function query<Output>(fn: () => MaybePromise<Output>): RemoteQueryFunction<void, Output> (+2 overloads)Creates a remote query. When called from the browser, the function will be invoked on the server via a fetch call.
See Remote functions for full documentation.
query,
function read(asset: string): ResponseRead the contents of an imported asset from the filesystem
read,
function requested<Input, Output>(query: RemoteQueryFunction<Input, Output>, limit?: number): RequestedResult<Input>In the context of a remote command or form request, returns an iterable
of the client-requested refreshes' validated arguments up to the supplied limit.
Arguments that fail validation or exceed the limit are recorded as failures in
the response to the client.
requested
} from '$app/server';command
Disponible depuis la version 2.27
Crée une commande distante. Lorsqu'exécutée sur le navigateur, la fonction sera invoquée sur le
serveur via un appel fetch.
Voir la section sur les fonctions distantes pour lire la documentation complète.
function command<Output>(
fn: () => MaybePromise<Output>
): RemoteCommand<void, Output>;function command<Input, Output>(
validate: 'unchecked',
fn: (arg: Input) => MaybePromise<Output>
): RemoteCommand<Input, Output>;function command<Schema extends StandardSchemaV1, Output>(
validate: Schema,
fn: (
arg: StandardSchemaV1.InferOutput<Schema>
) => MaybePromise<Output>
): RemoteCommand<
StandardSchemaV1.InferInput<Schema>,
Output
>;form
Disponible depuis la version 2.27
Crée un objet de formulaire pouvant être "étalé" sur un élément <form>
Voir la section sur les fonctions distantes pour lire la documentation complète.
function form<Output>(
fn: () => MaybePromise<Output>
): RemoteForm<void, Output>;function form<Input extends RemoteFormInput, Output>(
validate: 'unchecked',
fn: (
data: Input,
issue: InvalidField<Input>
) => MaybePromise<Output>
): RemoteForm<Input, Output>;function form<
Schema extends StandardSchemaV1<
RemoteFormInput,
Record<string, any>
>,
Output
>(
validate: Schema,
fn: (
data: StandardSchemaV1.InferOutput<Schema>,
issue: InvalidField<StandardSchemaV1.InferInput<Schema>>
) => MaybePromise<Output>
): RemoteForm<StandardSchemaV1.InferInput<Schema>, Output>;getRequestEvent
Disponible depuis la version 2.20.0
Renvoie l'objet RequestEvent courant. Peut être utilisé dans les hooks de serveur, les fonctions
load de serveur, les actions, et les endpoints (et dans les fonctions exécutées par ceux-ci).
Dans les environnements ne possédant pas de
AsyncLocalStorage, cette
méthode doit être appelée de manière synchrone (c'est-à-dire pas après un await).
function getRequestEvent(): RequestEvent;prerender
Disponible depuis la version 2.27
Crée une fonction de pré-rendu distante. Lorsqu'exécutée sur le navigateur, la fonction sera
invoquée sur le serveur via un appel fetch.
Voir la section sur les fonctions distantes pour lire la documentation complète.
function prerender<Output>(
fn: () => MaybePromise<Output>,
options?:
| {
inputs?: RemotePrerenderInputsGenerator<void>;
dynamic?: boolean;
}
| undefined
): RemotePrerenderFunction<void, Output>;function prerender<Input, Output>(
validate: 'unchecked',
fn: (arg: Input) => MaybePromise<Output>,
options?:
| {
inputs?: RemotePrerenderInputsGenerator<Input>;
dynamic?: boolean;
}
| undefined
): RemotePrerenderFunction<Input, Output>;function prerender<Schema extends StandardSchemaV1, Output>(
schema: Schema,
fn: (
arg: StandardSchemaV1.InferOutput<Schema>
) => MaybePromise<Output>,
options?:
| {
inputs?: RemotePrerenderInputsGenerator<
StandardSchemaV1.InferInput<Schema>
>;
dynamic?: boolean;
}
| undefined
): RemotePrerenderFunction<
StandardSchemaV1.InferInput<Schema>,
Output
>;query
Disponible depuis la version 2.27
Crée une query distante. Lorsqu'exécutée sur le navigateur, la fonction sera invoquée sur le serveur
via un appel fetch.
Voir la section sur les fonctions distantes pour lire la documentation complète.
function query<Output>(
fn: () => MaybePromise<Output>
): RemoteQueryFunction<void, Output>;function query<Input, Output>(
validate: 'unchecked',
fn: (arg: Input) => MaybePromise<Output>
): RemoteQueryFunction<Input, Output>;function query<Schema extends StandardSchemaV1, Output>(
schema: Schema,
fn: (
arg: StandardSchemaV1.InferOutput<Schema>
) => MaybePromise<Output>
): RemoteQueryFunction<
StandardSchemaV1.InferInput<Schema>,
Output,
StandardSchemaV1.InferOutput<Schema>
>;read
Disponible depuis la version 2.4.0
Lit le contenu d'un asset importé depuis le système de fichiers.
import { function read(asset: string): ResponseRead the contents of an imported asset from the filesystem
read } from '$app/server';
import const somefile: stringsomefile from './somefile.txt';
const const asset: Responseasset = function read(asset: string): ResponseRead the contents of an imported asset from the filesystem
read(const somefile: stringsomefile);
const const text: stringtext = await const asset: Responseasset.Body.text(): Promise<string>text();function read(asset: string): Response;requested
Dans le contexte d'une requête distante via command ou form, renvoie un itérable d'entrées { arg, query } pour les mises-à-jour demandées par le client, jusqu'à la limite fournie. Chaque
query est une RemoteQuery liée à la clé de cache originale côté client, afin que les appels
refresh() / set() se propagent correctement même lorsque le schéma de la query transforme les
entrées. arg est l'argument validé, c-à-d la valeur après que le schéma ait tourné (donc
InferOutput<Schema> pour les queries déclarées avec un Standard Schema).
Les arguments échouant la validation ou dépassent la limite sont enregistrés comme des échecs dans la réponse au client.
import { function requested<Input, Output, Validated = Input>(query: RemoteQueryFunction<Input, Output, Validated>, limit: number): RequestedResult<Validated, Output>In the context of a remote command or form request, returns an iterable
of { arg, query } entries for the refreshes requested by the client, up to
the supplied limit. Each query is a RemoteQuery bound to the original
client-side cache key, so refresh() / set() propagate correctly even when
the query's schema transforms the input. arg is the validated argument,
i.e. the value after the schema has run (so InferOutput<Schema> for queries
declared with a Standard Schema).
Arguments that fail validation or exceed limit are recorded as failures in
the response to the client.
requested } from '$app/server';
for (const const arg: RequestedEntry<unknown, unknown>arg of requested<unknown, unknown, unknown>(query: RemoteQueryFunction<unknown, unknown, unknown>, limit: number): RequestedResult<unknown, unknown>In the context of a remote command or form request, returns an iterable
of { arg, query } entries for the refreshes requested by the client, up to
the supplied limit. Each query is a RemoteQuery bound to the original
client-side cache key, so refresh() / set() propagate correctly even when
the query's schema transforms the input. arg is the validated argument,
i.e. the value after the schema has run (so InferOutput<Schema> for queries
declared with a Standard Schema).
Arguments that fail validation or exceed limit are recorded as failures in
the response to the client.
requested(getPost, 5)) {
// `arg` est l'argument validé ; `query` est liée à la clé de cache du client.
// Vous pouvez ignorer cette promesse — SvelteKit l'attendra et relaiera toute erreur au client.
void getPost(const arg: RequestedEntry<unknown, unknown>arg).refresh();
}Vous pouvez également appeler refreshAll sur le résultat, en tant que forme raccourcie de
l'exemple précédent :
import { function requested<Input, Output>(query: RemoteQueryFunction<Input, Output>, limit?: number): RequestedResult<Input>In the context of a remote command or form request, returns an iterable
of the client-requested refreshes' validated arguments up to the supplied limit.
Arguments that fail validation or exceed the limit are recorded as failures in
the response to the client.
requested } from '$app/server';
await requested<unknown, unknown>(query: RemoteQueryFunction<unknown, unknown>, limit?: number): RequestedResult<unknown>In the context of a remote command or form request, returns an iterable
of the client-requested refreshes' validated arguments up to the supplied limit.
Arguments that fail validation or exceed the limit are recorded as failures in
the response to the client.
requested(getPost, 5).refreshAll: () => Promise<void>Call refresh on all queries selected by this requested invocation.
This is identical to:
import { requested } from '$app/server';
for await (const arg of requested(query, ...) {
void query(arg).refresh();
}
refreshAll();Fonctionne également avec query.batch — les mises-à-jour pour les entrées individuelles sont
rassemblées dans un seul appel groupé.
Vaut aussi pour les queries de temps réel (live queries), mais avec reconnect et reconnectAll.
function requested<Input, Output, Validated = Input>(
query: RemoteQueryFunction<Input, Output, Validated>,
limit: number
): QueryRequestedResult<Validated, Output>;function requested<Input, Output, Validated = Input>(
query: RemoteLiveQueryFunction<Input, Output, Validated>,
limit: number
): LiveQueryRequestedResult<Validated, Output>;query
namespace query {
/**
* Crée une fonction de requête groupée qui collecte plusieurs appels et les exécute dans une
* seule requête.
*
* Voir [Fonctions distantes](https://svelte.dev/docs/kit/remote-functions#query.batch) pour plus
* d'infos.
*
* @since 2.35
*/
function batch<Input, Output>(
validate: 'unchecked',
fn: (
args: Input[]
) => MaybePromise<(arg: Input, idx: number) => Output>
): RemoteQueryFunction<Input, Output>;
/**
* Crée une fonction de requête groupée qui collecte plusieurs appels et les exécute dans une
* seule requête.
*
* Voir [Fonctions distantes](https://svelte.dev/docs/kit/remote-functions#query.batch) pour plus
* d'infos.
*
* @since 2.35
*/
function batch<Schema extends StandardSchemaV1, Output>(
schema: Schema,
fn: (
args: StandardSchemaV1.InferOutput<Schema>[]
) => MaybePromise<
(
arg: StandardSchemaV1.InferOutput<Schema>,
idx: number
) => Output
>
): RemoteQueryFunction<
StandardSchemaV1.InferInput<Schema>,
Output,
StandardSchemaV1.InferOutput<Schema>
>;
/**
* Crée une live query distante. Lorsqu'appelée depuis le navigateur, la fonction sera exécutée
* sur le serveur via un appel `fetch` de streaming.
*
* Voir [Fonctions distantes](https://svelte.dev/docs/kit/remote-functions#query.live) pour plus
* d'infos.
*
* */
function live<Output>(
fn: (
arg: void
) => RemoteLiveQueryUserFunctionReturnType<Output>
): RemoteLiveQueryFunction<void, Output>;
function live<Input, Output>(
validate: 'unchecked',
fn: (
arg: Input
) => RemoteLiveQueryUserFunctionReturnType<Output>
): RemoteLiveQueryFunction<Input, Output>;
function live<Schema extends StandardSchemaV1, Output>(
schema: Schema,
fn: (
arg: StandardSchemaV1.InferOutput<Schema>
) => RemoteLiveQueryUserFunctionReturnType<Output>
): RemoteLiveQueryFunction<
StandardSchemaV1.InferInput<Schema>,
Output,
StandardSchemaV1.InferOutput<Schema>
>;
}Modifier cette page sur Github llms.txt