@sveltejs/kit 3.0.0-next.19 → 3.0.0-next.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -12
- package/src/core/adapt/builder.js +2 -1
- package/src/core/adapt/index.js +1 -1
- package/src/core/env.js +1 -1
- package/src/core/postbuild/prerender.js +61 -8
- package/src/core/sync/write_env.js +1 -1
- package/src/core/sync/write_server.js +2 -2
- package/src/core/sync/write_tsconfig/index.js +1 -3
- package/src/core/sync/write_tsconfig/utils.js +0 -24
- package/src/exports/env/index.js +1 -1
- package/src/exports/env/public.d.ts +55 -0
- package/src/exports/hooks/public.d.ts +194 -0
- package/src/exports/hooks/sequence.js +4 -3
- package/src/exports/index.js +1 -1
- package/src/exports/internal/env.js +1 -1
- package/src/exports/params/public.d.ts +2 -2
- package/src/exports/public.d.ts +1 -757
- package/src/exports/vite/dev/index.js +2 -2
- package/src/exports/vite/index.js +541 -384
- package/src/exports/vite/utils.js +0 -16
- package/src/runtime/app/internal/transport.js +1 -1
- package/src/runtime/app/server/public.d.ts +519 -0
- package/src/runtime/app/server/remote/command.js +1 -1
- package/src/runtime/app/server/remote/form.js +1 -1
- package/src/runtime/app/server/remote/prerender.js +1 -1
- package/src/runtime/app/server/remote/query.js +2 -1
- package/src/runtime/app/server/remote/requested.js +1 -1
- package/src/runtime/client/client.js +1 -1
- package/src/runtime/client/remote-functions/command.svelte.js +1 -1
- package/src/runtime/client/remote-functions/form.svelte.js +1 -1
- package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query/index.js +1 -1
- package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query-live/index.js +1 -1
- package/src/runtime/client/remote-functions/shared.svelte.js +1 -1
- package/src/runtime/server/errors.js +2 -2
- package/src/runtime/server/internal.js +39 -0
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/remote-functions.js +17 -5
- package/src/runtime/server/respond.js +1 -1
- package/src/types/internal.d.ts +14 -13
- package/src/version.js +1 -1
- package/types/index.d.ts +1403 -1403
- package/types/index.d.ts.map +68 -62
package/types/index.d.ts
CHANGED
|
@@ -3,27 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
declare module '@sveltejs/kit' {
|
|
5
5
|
import type { SvelteConfig } from '@sveltejs/vite-plugin-svelte';
|
|
6
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
7
6
|
import type { Plugin } from 'vite';
|
|
8
7
|
import type { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
|
|
8
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
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
|
|
|
12
|
-
type AppErrorWithOptionalDefaults = Omit<App.Error, 'status' | 'message'> & {
|
|
13
|
-
status?: App.Error['status'];
|
|
14
|
-
message?: App.Error['message'];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* `void` is only a valid `handleError` return when `App.Error` adds no required properties
|
|
19
|
-
* beyond `status` and `message` — both of which are optional in the return, since they default
|
|
20
|
-
* to those of the caught error. If `App.Error` is augmented with required properties, the hook
|
|
21
|
-
* must return them, so returning nothing becomes a type error.
|
|
22
|
-
*/
|
|
23
|
-
type VoidIfNoRequiredAppErrorProperties = { status: number; message: string } extends App.Error
|
|
24
|
-
? void
|
|
25
|
-
: never;
|
|
26
|
-
|
|
27
12
|
/**
|
|
28
13
|
* [Adapters](https://svelte.dev/docs/kit/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing.
|
|
29
14
|
*/
|
|
@@ -924,152 +909,6 @@ declare module '@sveltejs/kit' {
|
|
|
924
909
|
};
|
|
925
910
|
}
|
|
926
911
|
|
|
927
|
-
/**
|
|
928
|
-
* The [`handle`](https://svelte.dev/docs/kit/hooks#handle) hook runs every time the SvelteKit server receives a [request](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Request) and
|
|
929
|
-
* determines the [response](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Response).
|
|
930
|
-
* It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
|
|
931
|
-
* This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
|
|
932
|
-
*/
|
|
933
|
-
export type Handle = (input: {
|
|
934
|
-
event: RequestEvent;
|
|
935
|
-
resolve: (event: RequestEvent, opts?: ResolveOptions) => Promise<Response>;
|
|
936
|
-
}) => MaybePromise<Response>;
|
|
937
|
-
|
|
938
|
-
type CaughtErrorMap = {
|
|
939
|
-
app: App.Error;
|
|
940
|
-
framework: { status: number; message: string };
|
|
941
|
-
unknown: unknown;
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
type ValidationCaughtError<Issue extends StandardSchemaV1.Issue> = {
|
|
945
|
-
kind: 'validation';
|
|
946
|
-
error: { status: number; message: string };
|
|
947
|
-
issues: Issue[];
|
|
948
|
-
};
|
|
949
|
-
|
|
950
|
-
/**
|
|
951
|
-
* The error passed to the [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hooks.
|
|
952
|
-
* Use the `kind` discriminant to distinguish errors from your app (thrown with the
|
|
953
|
-
* [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper), errors generated by
|
|
954
|
-
* SvelteKit itself (such as 404s), validation errors, and unknown errors (thrown by your code,
|
|
955
|
-
* or code it calls).
|
|
956
|
-
*/
|
|
957
|
-
export type CaughtError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
|
|
958
|
-
| {
|
|
959
|
-
[Kind in keyof CaughtErrorMap]: {
|
|
960
|
-
/** Identifies the category and origin of the error */
|
|
961
|
-
kind: Kind;
|
|
962
|
-
/** The caught error. Its type depends on `kind` */
|
|
963
|
-
error: CaughtErrorMap[Kind];
|
|
964
|
-
/** Only present for validation errors */
|
|
965
|
-
issues?: undefined;
|
|
966
|
-
};
|
|
967
|
-
}[keyof CaughtErrorMap]
|
|
968
|
-
| ValidationCaughtError<Issue>;
|
|
969
|
-
|
|
970
|
-
/** The error passed to the client-side `handleError` hook. */
|
|
971
|
-
export type ClientCaughtError = Exclude<CaughtError, { kind: 'validation' }>;
|
|
972
|
-
|
|
973
|
-
/**
|
|
974
|
-
* The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs for every error thrown while responding to a request, except redirects.
|
|
975
|
-
*
|
|
976
|
-
* The `kind` property discriminates between _app_ errors (thrown with the [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper),
|
|
977
|
-
* _framework_ errors (generated by SvelteKit itself, such as 404s), _validation_ errors (caused by invalid remote function arguments)
|
|
978
|
-
* and _unknown_ errors (thrown by your code, or code it calls).
|
|
979
|
-
*
|
|
980
|
-
* The hook returns an object matching `App.Error`, in which `status` and `message` are optional — return them only to
|
|
981
|
-
* override the defaults. Omitted properties are inherited from the caught error: the body passed to `error(...)` for app errors,
|
|
982
|
-
* the status and safe message for framework and validation errors, and `500`/`'Internal Error'` for unknown errors. Return nothing to
|
|
983
|
-
* keep the defaults entirely (if you augment `App.Error` with required properties, you must return those).
|
|
984
|
-
*
|
|
985
|
-
* Make sure that this function _never_ throws an error.
|
|
986
|
-
*/
|
|
987
|
-
export type HandleServerError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> = (
|
|
988
|
-
input: CaughtError<Issue> & { event: RequestEvent }
|
|
989
|
-
) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
|
|
990
|
-
|
|
991
|
-
/**
|
|
992
|
-
* The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs for every error thrown while navigating, except redirects.
|
|
993
|
-
* Errors that were already transformed by the server-side hook are not passed to it a second time.
|
|
994
|
-
*
|
|
995
|
-
* The `kind` property discriminates between _app_ errors (thrown with the [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper),
|
|
996
|
-
* _framework_ errors (generated by SvelteKit itself, such as 404s) and _unknown_ errors (thrown by your code, or code it calls).
|
|
997
|
-
*
|
|
998
|
-
* The hook returns an object matching `App.Error`, in which `status` and `message` are optional — return them only to
|
|
999
|
-
* override the defaults. Omitted properties are inherited from the caught error: the body passed to `error(...)` for app errors,
|
|
1000
|
-
* the status and safe message for framework errors, and `500`/`'Internal Error'` for unknown errors. Return nothing to
|
|
1001
|
-
* keep the defaults entirely (if you augment `App.Error` with required properties, you must return those).
|
|
1002
|
-
*
|
|
1003
|
-
* Make sure that this function _never_ throws an error.
|
|
1004
|
-
*/
|
|
1005
|
-
export type HandleClientError = (
|
|
1006
|
-
input: ClientCaughtError & { event: NavigationEvent }
|
|
1007
|
-
) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
|
|
1008
|
-
|
|
1009
|
-
/**
|
|
1010
|
-
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
|
|
1011
|
-
*/
|
|
1012
|
-
export type HandleFetch = (input: {
|
|
1013
|
-
event: RequestEvent;
|
|
1014
|
-
request: Request;
|
|
1015
|
-
fetch: typeof fetch;
|
|
1016
|
-
}) => MaybePromise<Response>;
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked before the server responds to its first request
|
|
1020
|
-
* @since 2.10.0
|
|
1021
|
-
*/
|
|
1022
|
-
export type ServerInit = () => MaybePromise<void>;
|
|
1023
|
-
|
|
1024
|
-
/**
|
|
1025
|
-
* The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked once the app starts in the browser
|
|
1026
|
-
* @since 2.10.0
|
|
1027
|
-
*/
|
|
1028
|
-
export type ClientInit = () => MaybePromise<void>;
|
|
1029
|
-
|
|
1030
|
-
/**
|
|
1031
|
-
* The [`reroute`](https://svelte.dev/docs/kit/hooks#reroute) hook allows you to modify the URL before it is used to determine which route to render.
|
|
1032
|
-
* @since 2.3.0
|
|
1033
|
-
*/
|
|
1034
|
-
export type Reroute = (event: { url: URL; fetch: typeof fetch }) => MaybePromise<void | string>;
|
|
1035
|
-
|
|
1036
|
-
/**
|
|
1037
|
-
* The [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook allows you to transport custom types across the server/client boundary.
|
|
1038
|
-
*
|
|
1039
|
-
* Each transporter has a pair of `encode` and `decode` functions. On the server, `encode` determines whether a value is an instance of the custom type and, if so, returns a non-falsy encoding of the value which can be an object or an array (or `false` otherwise).
|
|
1040
|
-
*
|
|
1041
|
-
* In the browser, `decode` turns the encoding back into an instance of the custom type.
|
|
1042
|
-
*
|
|
1043
|
-
* ```ts
|
|
1044
|
-
* import type { Transport } from '@sveltejs/kit';
|
|
1045
|
-
*
|
|
1046
|
-
* declare class MyCustomType {
|
|
1047
|
-
* data: any
|
|
1048
|
-
* }
|
|
1049
|
-
*
|
|
1050
|
-
* // hooks.js
|
|
1051
|
-
* export const transport: Transport = {
|
|
1052
|
-
* MyCustomType: {
|
|
1053
|
-
* encode: (value) => value instanceof MyCustomType && [value.data],
|
|
1054
|
-
* decode: ([data]) => new MyCustomType(data)
|
|
1055
|
-
* }
|
|
1056
|
-
* };
|
|
1057
|
-
* ```
|
|
1058
|
-
* @since 2.11.0
|
|
1059
|
-
*/
|
|
1060
|
-
export type Transport = Record<string, Transporter>;
|
|
1061
|
-
|
|
1062
|
-
/**
|
|
1063
|
-
* A member of the [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook.
|
|
1064
|
-
*/
|
|
1065
|
-
export interface Transporter<
|
|
1066
|
-
T = any,
|
|
1067
|
-
U = any /* minus falsy values, but we can't properly express that */
|
|
1068
|
-
> {
|
|
1069
|
-
encode: (value: T) => false | U;
|
|
1070
|
-
decode: (data: U) => T;
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
912
|
/**
|
|
1074
913
|
* The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://svelte.dev/docs/kit/types#Generated-types))
|
|
1075
914
|
* rather than using `Load` directly.
|
|
@@ -1230,67 +1069,6 @@ declare module '@sveltejs/kit' {
|
|
|
1230
1069
|
url: URL;
|
|
1231
1070
|
}
|
|
1232
1071
|
|
|
1233
|
-
/**
|
|
1234
|
-
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
1235
|
-
* when called with a regular `query`. `arg` is the validated argument (the input *after*
|
|
1236
|
-
* the query's schema validated and transformed it, if applicable); `query` is a
|
|
1237
|
-
* `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
|
|
1238
|
-
* update the correct client entry.
|
|
1239
|
-
*/
|
|
1240
|
-
export type RequestedEntry<Validated, Output> = {
|
|
1241
|
-
arg: Validated;
|
|
1242
|
-
query: RemoteQuery<Output>;
|
|
1243
|
-
};
|
|
1244
|
-
|
|
1245
|
-
/**
|
|
1246
|
-
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
1247
|
-
* when called with a `query.live`. `arg` is the validated argument; `query` is a
|
|
1248
|
-
* `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
|
|
1249
|
-
* the correct client subscription.
|
|
1250
|
-
*/
|
|
1251
|
-
export type LiveRequestedEntry<Validated, Output> = {
|
|
1252
|
-
arg: Validated;
|
|
1253
|
-
query: RemoteLiveQuery<Output>;
|
|
1254
|
-
};
|
|
1255
|
-
|
|
1256
|
-
export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
|
|
1257
|
-
AsyncIterable<RequestedEntry<Validated, Output>> & {
|
|
1258
|
-
/**
|
|
1259
|
-
* Call `refresh` on all queries selected by this `requested` invocation.
|
|
1260
|
-
* This is identical to:
|
|
1261
|
-
* ```ts
|
|
1262
|
-
* import { requested } from '$app/server';
|
|
1263
|
-
*
|
|
1264
|
-
* for await (const { query } of requested(getPost, ...)) {
|
|
1265
|
-
* void query.refresh();
|
|
1266
|
-
* }
|
|
1267
|
-
* ```
|
|
1268
|
-
*/
|
|
1269
|
-
refreshAll: () => Promise<void>;
|
|
1270
|
-
};
|
|
1271
|
-
|
|
1272
|
-
export type LiveQueryRequestedResult<Validated, Output> = Iterable<
|
|
1273
|
-
LiveRequestedEntry<Validated, Output>
|
|
1274
|
-
> &
|
|
1275
|
-
AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
|
|
1276
|
-
/**
|
|
1277
|
-
* Call `reconnect` on all live queries selected by this `requested` invocation.
|
|
1278
|
-
* This is identical to:
|
|
1279
|
-
* ```ts
|
|
1280
|
-
* import { requested } from '$app/server';
|
|
1281
|
-
*
|
|
1282
|
-
* for await (const { query } of requested(liveQuery, ...)) {
|
|
1283
|
-
* void query.reconnect();
|
|
1284
|
-
* }
|
|
1285
|
-
* ```
|
|
1286
|
-
*/
|
|
1287
|
-
reconnectAll: () => Promise<void>;
|
|
1288
|
-
};
|
|
1289
|
-
|
|
1290
|
-
export type RequestedResult<Validated, Output> =
|
|
1291
|
-
| QueryRequestedResult<Validated, Output>
|
|
1292
|
-
| LiveQueryRequestedResult<Validated, Output>;
|
|
1293
|
-
|
|
1294
1072
|
export interface RequestEvent<
|
|
1295
1073
|
Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
|
|
1296
1074
|
RouteId extends AppRouteId | null = AppRouteId | null
|
|
@@ -1422,31 +1200,6 @@ declare module '@sveltejs/kit' {
|
|
|
1422
1200
|
RouteId extends AppRouteId | null = AppRouteId | null
|
|
1423
1201
|
> = (event: RequestEvent<Params, RouteId>) => MaybePromise<Response>;
|
|
1424
1202
|
|
|
1425
|
-
export interface ResolveOptions {
|
|
1426
|
-
/**
|
|
1427
|
-
* Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
|
|
1428
|
-
* (they could include an element's opening tag but not its closing tag, for example)
|
|
1429
|
-
* but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
|
|
1430
|
-
* @param input the html chunk and the info if this is the last chunk
|
|
1431
|
-
*/
|
|
1432
|
-
transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
|
|
1433
|
-
/**
|
|
1434
|
-
* Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
|
|
1435
|
-
* By default, none will be included.
|
|
1436
|
-
* @param name header name
|
|
1437
|
-
* @param value header value
|
|
1438
|
-
*/
|
|
1439
|
-
filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
|
|
1440
|
-
/**
|
|
1441
|
-
* Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
|
|
1442
|
-
* `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
|
|
1443
|
-
* [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
|
|
1444
|
-
* By default, `js` and `css` files will be preloaded.
|
|
1445
|
-
* @param input the type of the file and its path
|
|
1446
|
-
*/
|
|
1447
|
-
preload?: (input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }) => boolean;
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
1203
|
export interface RouteDefinition<Config = any> {
|
|
1451
1204
|
id: string;
|
|
1452
1205
|
api: {
|
|
@@ -1625,519 +1378,13 @@ declare module '@sveltejs/kit' {
|
|
|
1625
1378
|
capture: () => T;
|
|
1626
1379
|
restore: (snapshot: T) => void;
|
|
1627
1380
|
}
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
email: string;
|
|
1636
|
-
password: string;
|
|
1637
|
-
url: string;
|
|
1638
|
-
tel: string;
|
|
1639
|
-
search: string;
|
|
1640
|
-
number: number;
|
|
1641
|
-
range: number;
|
|
1642
|
-
date: string;
|
|
1643
|
-
'datetime-local': string;
|
|
1644
|
-
time: string;
|
|
1645
|
-
month: string;
|
|
1646
|
-
week: string;
|
|
1647
|
-
color: string;
|
|
1648
|
-
checkbox: boolean | string[];
|
|
1649
|
-
radio: string;
|
|
1650
|
-
file: File;
|
|
1651
|
-
hidden: string | number | boolean;
|
|
1652
|
-
submit: string | number | boolean;
|
|
1653
|
-
button: string;
|
|
1654
|
-
reset: string;
|
|
1655
|
-
image: string;
|
|
1656
|
-
select: string;
|
|
1657
|
-
'select multiple': string[];
|
|
1658
|
-
'file multiple': File[];
|
|
1659
|
-
};
|
|
1660
|
-
|
|
1661
|
-
// Valid input types for a given value type
|
|
1662
|
-
export type RemoteFormFieldType<T> = {
|
|
1663
|
-
[K in keyof InputTypeMap]: T extends InputTypeMap[K] ? K : never;
|
|
1664
|
-
}[keyof InputTypeMap];
|
|
1665
|
-
|
|
1666
|
-
// Input element properties based on type
|
|
1667
|
-
type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'radio'
|
|
1668
|
-
? {
|
|
1669
|
-
name: string;
|
|
1670
|
-
type: T;
|
|
1671
|
-
value?: string;
|
|
1672
|
-
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1673
|
-
get checked(): boolean;
|
|
1674
|
-
set checked(value: boolean);
|
|
1675
|
-
readonly defaultChecked?: boolean;
|
|
1676
|
-
}
|
|
1677
|
-
: T extends 'file'
|
|
1678
|
-
? {
|
|
1679
|
-
name: string;
|
|
1680
|
-
type: 'file';
|
|
1681
|
-
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1682
|
-
get files(): FileList | null;
|
|
1683
|
-
set files(v: FileList | null);
|
|
1684
|
-
}
|
|
1685
|
-
: T extends 'select'
|
|
1686
|
-
? {
|
|
1687
|
-
name: string;
|
|
1688
|
-
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1689
|
-
get value(): string;
|
|
1690
|
-
set value(v: string);
|
|
1691
|
-
}
|
|
1692
|
-
: T extends 'select multiple'
|
|
1693
|
-
? {
|
|
1694
|
-
name: string;
|
|
1695
|
-
multiple: true;
|
|
1696
|
-
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1697
|
-
get value(): string[];
|
|
1698
|
-
set value(v: string[]);
|
|
1699
|
-
}
|
|
1700
|
-
: T extends 'text'
|
|
1701
|
-
? {
|
|
1702
|
-
name: string;
|
|
1703
|
-
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1704
|
-
get value(): string | number;
|
|
1705
|
-
set value(v: string | number);
|
|
1706
|
-
readonly defaultValue?: string | number;
|
|
1707
|
-
}
|
|
1708
|
-
: {
|
|
1709
|
-
name: string;
|
|
1710
|
-
type: T;
|
|
1711
|
-
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1712
|
-
get value(): string | number;
|
|
1713
|
-
set value(v: string | number);
|
|
1714
|
-
readonly defaultValue?: string | number;
|
|
1715
|
-
};
|
|
1716
|
-
|
|
1717
|
-
type RemoteFormFieldMethods<T> = {
|
|
1718
|
-
/** The values that will be submitted */
|
|
1719
|
-
value(): DeepPartial<T>;
|
|
1720
|
-
/** Set the values that will be submitted */
|
|
1721
|
-
set(input: DeepPartial<T>): DeepPartial<T>;
|
|
1722
|
-
/** Whether the field or any nested field has been interacted with since the form was mounted */
|
|
1723
|
-
touched(): boolean;
|
|
1724
|
-
/** Whether the field or any nested field has been edited since the form was mounted */
|
|
1725
|
-
dirty(): boolean;
|
|
1726
|
-
/** Validation issues, if any */
|
|
1727
|
-
issues(): RemoteFormIssue[] | undefined;
|
|
1728
|
-
};
|
|
1729
|
-
|
|
1730
|
-
// These two types use "T extends unknown ? .. : .." to distribute over unions.
|
|
1731
|
-
// 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
|
|
1732
|
-
type KeysOfUnion<T> = T extends unknown ? keyof T : never;
|
|
1733
|
-
type ValueOfUnionKey<T, K extends PropertyKey> = T extends unknown
|
|
1734
|
-
? K extends keyof T
|
|
1735
|
-
? T[K]
|
|
1736
|
-
: never
|
|
1737
|
-
: never;
|
|
1738
|
-
|
|
1739
|
-
export type RemoteFormFieldValue = string | string[] | number | boolean | File | File[];
|
|
1740
|
-
|
|
1741
|
-
type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
|
|
1742
|
-
? Value extends string[]
|
|
1743
|
-
? [type: Type, value: Value[number] | (string & {})]
|
|
1744
|
-
: Value extends boolean
|
|
1745
|
-
? [type: Type] | [type: Type, value: boolean]
|
|
1746
|
-
: [type: Type] | [type: Type, value: Value | (string & {})]
|
|
1747
|
-
: Type extends 'submit' | 'hidden'
|
|
1748
|
-
? Value extends string
|
|
1749
|
-
? [type: Type, value: Value | (string & {})]
|
|
1750
|
-
: [type: Type, value: Value]
|
|
1751
|
-
: Type extends 'radio'
|
|
1752
|
-
? [type: Type, value: Value | (string & {})]
|
|
1753
|
-
: Type extends 'file' | 'file multiple'
|
|
1754
|
-
? [type: Type]
|
|
1755
|
-
: [type: Type] | [type: Type, value: Value | undefined];
|
|
1756
|
-
|
|
1757
|
-
/**
|
|
1758
|
-
* Form field accessor type that provides name(), value(), and issues() methods
|
|
1759
|
-
*/
|
|
1760
|
-
export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
|
|
1761
|
-
/**
|
|
1762
|
-
* Returns an object that can be spread onto an input element with the correct type attribute,
|
|
1763
|
-
* aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
|
|
1764
|
-
* @example
|
|
1765
|
-
* ```svelte
|
|
1766
|
-
* <input {...myForm.fields.myString.as('text')} />
|
|
1767
|
-
* <input {...myForm.fields.myNumber.as('number')} />
|
|
1768
|
-
* <input {...myForm.fields.myBoolean.as('checkbox')} />
|
|
1769
|
-
* ```
|
|
1770
|
-
*/
|
|
1771
|
-
as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
|
|
1772
|
-
};
|
|
1773
|
-
|
|
1774
|
-
type RemoteFormFieldContainer<Value> = RemoteFormFieldMethods<Value> & {
|
|
1775
|
-
/** Validation issues belonging to this or any of the fields that belong to it, if any */
|
|
1776
|
-
allIssues(): RemoteFormIssue[] | undefined;
|
|
1777
|
-
};
|
|
1778
|
-
|
|
1779
|
-
type UnknownField<Value> = RemoteFormFieldMethods<Value> & {
|
|
1780
|
-
/** Validation issues belonging to this or any of the fields that belong to it, if any */
|
|
1781
|
-
allIssues(): RemoteFormIssue[] | undefined;
|
|
1782
|
-
/**
|
|
1783
|
-
* Returns an object that can be spread onto an input element with the correct type attribute,
|
|
1784
|
-
* aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
|
|
1785
|
-
* @example
|
|
1786
|
-
* ```svelte
|
|
1787
|
-
* <input {...myForm.fields.myString.as('text')} />
|
|
1788
|
-
* <input {...myForm.fields.myNumber.as('number')} />
|
|
1789
|
-
* <input {...myForm.fields.myBoolean.as('checkbox')} />
|
|
1790
|
-
* ```
|
|
1791
|
-
*/
|
|
1792
|
-
as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
|
|
1793
|
-
} & {
|
|
1794
|
-
[key: string | number]: UnknownField<any>;
|
|
1795
|
-
};
|
|
1796
|
-
|
|
1797
|
-
type RemoteFormFieldsRoot<Input extends RemoteFormInput | void> =
|
|
1798
|
-
IsAny<Input> extends true
|
|
1799
|
-
? RecursiveFormFields
|
|
1800
|
-
: Input extends void
|
|
1801
|
-
? {
|
|
1802
|
-
/** Validation issues, if any */
|
|
1803
|
-
issues(): RemoteFormIssue[] | undefined;
|
|
1804
|
-
/** Validation issues belonging to this or any of the fields that belong to it, if any */
|
|
1805
|
-
allIssues(): RemoteFormIssue[] | undefined;
|
|
1806
|
-
}
|
|
1807
|
-
: RemoteFormFields<Input>;
|
|
1808
|
-
|
|
1809
|
-
/**
|
|
1810
|
-
* Recursive type to build form fields structure with proxy access
|
|
1811
|
-
*/
|
|
1812
|
-
export type RemoteFormFields<T> =
|
|
1813
|
-
WillRecurseIndefinitely<T> extends true
|
|
1814
|
-
? RecursiveFormFields
|
|
1815
|
-
: NonNullable<T> extends string | number | boolean | File
|
|
1816
|
-
? RemoteFormField<NonNullable<T>>
|
|
1817
|
-
: // [NonNullable<T>] is used to prevent distributing over union while still allowing
|
|
1818
|
-
// nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
|
|
1819
|
-
// to be treated as arrays; only the last condition should distribute over unions
|
|
1820
|
-
[NonNullable<T>] extends [string[] | File[]]
|
|
1821
|
-
? RemoteFormField<NonNullable<T>> & {
|
|
1822
|
-
[K in number]: RemoteFormField<NonNullable<T>[number]>;
|
|
1823
|
-
}
|
|
1824
|
-
: [NonNullable<T>] extends [Array<infer U>]
|
|
1825
|
-
? RemoteFormFieldContainer<NonNullable<T>> & {
|
|
1826
|
-
[K in number]: RemoteFormFields<U>;
|
|
1827
|
-
}
|
|
1828
|
-
: RemoteFormFieldContainer<T> & {
|
|
1829
|
-
[K in KeysOfUnion<T>]-?: RemoteFormFields<ValueOfUnionKey<T, K>>;
|
|
1830
|
-
};
|
|
1831
|
-
|
|
1832
|
-
// By breaking this out into its own type, we avoid the TS recursion depth limit
|
|
1833
|
-
type RecursiveFormFields = RemoteFormFieldContainer<any> & {
|
|
1834
|
-
[key: string | number]: UnknownField<any>;
|
|
1835
|
-
};
|
|
1836
|
-
|
|
1837
|
-
type MaybeArray<T> = T | T[];
|
|
1838
|
-
|
|
1839
|
-
export interface RemoteFormInput {
|
|
1840
|
-
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
export interface RemoteFormIssue {
|
|
1844
|
-
message: string;
|
|
1845
|
-
path: Array<string | number>;
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
// If the schema specifies `id` as a string or number, ensure that `for(...)`
|
|
1849
|
-
// only accepts that type. Otherwise, accept `string | number`
|
|
1850
|
-
type ExtractId<Input> = Input extends { id: infer Id }
|
|
1851
|
-
? Id extends string | number
|
|
1852
|
-
? Id
|
|
1853
|
-
: string | number
|
|
1854
|
-
: string | number;
|
|
1855
|
-
|
|
1856
|
-
/**
|
|
1857
|
-
* A function and proxy object used to imperatively create validation errors in form handlers.
|
|
1858
|
-
*
|
|
1859
|
-
* Access properties to create field-specific issues: `issue.fieldName('message')`.
|
|
1860
|
-
* The type structure mirrors the input data structure for type-safe field access.
|
|
1861
|
-
* Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
|
|
1862
|
-
*/
|
|
1863
|
-
export type InvalidField<T> =
|
|
1864
|
-
WillRecurseIndefinitely<T> extends true
|
|
1865
|
-
? Record<string | number, any>
|
|
1866
|
-
: NonNullable<T> extends string | number | boolean | File
|
|
1867
|
-
? (message: string) => StandardSchemaV1.Issue
|
|
1868
|
-
: NonNullable<T> extends Array<infer U>
|
|
1869
|
-
? {
|
|
1870
|
-
[K in number]: InvalidField<U>;
|
|
1871
|
-
} & ((message: string) => StandardSchemaV1.Issue)
|
|
1872
|
-
: NonNullable<T> extends RemoteFormInput
|
|
1873
|
-
? {
|
|
1874
|
-
[K in keyof T]-?: InvalidField<T[K]>;
|
|
1875
|
-
} & ((message: string) => StandardSchemaV1.Issue)
|
|
1876
|
-
: Record<string, never>;
|
|
1877
|
-
|
|
1878
|
-
/**
|
|
1879
|
-
* A validation error thrown by `invalid`.
|
|
1880
|
-
*/
|
|
1881
|
-
export interface ValidationError {
|
|
1882
|
-
/** The validation issues */
|
|
1883
|
-
issues: StandardSchemaV1.Issue[];
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
/**
|
|
1887
|
-
* The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
1888
|
-
*/
|
|
1889
|
-
export type RemoteFormEnhanceInstance<
|
|
1890
|
-
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
1891
|
-
Output = any
|
|
1892
|
-
> = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
|
|
1893
|
-
readonly element: HTMLFormElement;
|
|
1894
|
-
};
|
|
1895
|
-
|
|
1896
|
-
/**
|
|
1897
|
-
* The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
1898
|
-
*/
|
|
1899
|
-
export type RemoteFormEnhanceCallback<
|
|
1900
|
-
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
1901
|
-
Output = any
|
|
1902
|
-
> = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
|
|
1903
|
-
|
|
1904
|
-
/**
|
|
1905
|
-
* The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
1906
|
-
*/
|
|
1907
|
-
export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
1908
|
-
/** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
|
|
1909
|
-
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
1910
|
-
method: 'POST';
|
|
1911
|
-
/** The URL to send the form to. */
|
|
1912
|
-
action: string;
|
|
1913
|
-
/** The `<form>` element this instance is currently attached to, if any. */
|
|
1914
|
-
get element(): HTMLFormElement | null;
|
|
1915
|
-
/** Submit the currently attached form programmatically. */
|
|
1916
|
-
submit(): Promise<boolean> & {
|
|
1917
|
-
updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
|
|
1918
|
-
};
|
|
1919
|
-
/** Use the `enhance` method to influence what happens when the form is submitted. */
|
|
1920
|
-
enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
|
|
1921
|
-
method: 'POST';
|
|
1922
|
-
action: string;
|
|
1923
|
-
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
1924
|
-
};
|
|
1925
|
-
/**
|
|
1926
|
-
* Create an instance of the form for the given `id`.
|
|
1927
|
-
* The `id` is stringified and used for deduplication to potentially reuse existing instances.
|
|
1928
|
-
* Useful when you have multiple forms that use the same remote form action, for example in a loop.
|
|
1929
|
-
* ```svelte
|
|
1930
|
-
* {#each todos as todo}
|
|
1931
|
-
* {@const todoForm = updateTodo.for(todo.id)}
|
|
1932
|
-
* <form {...todoForm}>
|
|
1933
|
-
* {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
|
|
1934
|
-
* ...
|
|
1935
|
-
* </form>
|
|
1936
|
-
* {/each}
|
|
1937
|
-
* ```
|
|
1938
|
-
*/
|
|
1939
|
-
for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
|
|
1940
|
-
/** Preflight checks */
|
|
1941
|
-
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
|
|
1942
|
-
/** Validate the form contents programmatically */
|
|
1943
|
-
validate(options?: {
|
|
1944
|
-
/**
|
|
1945
|
-
* Set this to `true` to also show validation issues of fields that haven't yet been
|
|
1946
|
-
* edited and blurred. This option is ignored for forms that have previously been
|
|
1947
|
-
* submitted, in which case all fields are always subject to validation
|
|
1948
|
-
* (unless the form is reset, at which point it is treated as pristine)
|
|
1949
|
-
*/
|
|
1950
|
-
all?: boolean;
|
|
1951
|
-
/** Set this to `true` to only run the `preflight` validation. */
|
|
1952
|
-
preflightOnly?: boolean;
|
|
1953
|
-
}): Promise<void>;
|
|
1954
|
-
/** The result of the form submission */
|
|
1955
|
-
get result(): Output | undefined;
|
|
1956
|
-
/** The number of pending submissions */
|
|
1957
|
-
get pending(): number;
|
|
1958
|
-
/** True if the form has been submitted at least once, and hasn't been reset since */
|
|
1959
|
-
get submitted(): boolean;
|
|
1960
|
-
/** Access form fields using object notation */
|
|
1961
|
-
fields: RemoteFormFieldsRoot<Input>;
|
|
1962
|
-
};
|
|
1963
|
-
|
|
1964
|
-
/**
|
|
1965
|
-
* The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
|
|
1966
|
-
*/
|
|
1967
|
-
export type RemoteCommand<Input, Output> = {
|
|
1968
|
-
(arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
|
|
1969
|
-
updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
|
|
1970
|
-
};
|
|
1971
|
-
/** The number of pending command executions */
|
|
1972
|
-
get pending(): number;
|
|
1973
|
-
};
|
|
1974
|
-
|
|
1975
|
-
export type RemoteQueryUpdate =
|
|
1976
|
-
| RemoteQuery<any>
|
|
1977
|
-
| RemoteLiveQuery<any>
|
|
1978
|
-
| RemoteQueryFunction<any, any>
|
|
1979
|
-
| RemoteLiveQueryFunction<any, any>
|
|
1980
|
-
| RemoteQueryOverride;
|
|
1981
|
-
|
|
1982
|
-
export type RemoteResource<T> = Promise<T> & {
|
|
1983
|
-
/** The error in case the query fails. */
|
|
1984
|
-
get error(): App.Error | undefined;
|
|
1985
|
-
/** `true` before the first result is available and during refreshes */
|
|
1986
|
-
get loading(): boolean;
|
|
1987
|
-
} & (
|
|
1988
|
-
| {
|
|
1989
|
-
/** The current value of the query. Undefined until `ready` is `true` */
|
|
1990
|
-
get current(): undefined;
|
|
1991
|
-
ready: false;
|
|
1992
|
-
}
|
|
1993
|
-
| {
|
|
1994
|
-
/** The current value of the query. Undefined until `ready` is `true` */
|
|
1995
|
-
get current(): T;
|
|
1996
|
-
ready: true;
|
|
1997
|
-
}
|
|
1998
|
-
);
|
|
1999
|
-
|
|
2000
|
-
export type RemoteQuery<T> = RemoteResource<T> & {
|
|
2001
|
-
/**
|
|
2002
|
-
* On the client, this function will update the value of the query without re-fetching it.
|
|
2003
|
-
*
|
|
2004
|
-
* 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.
|
|
2005
|
-
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
|
|
2006
|
-
*/
|
|
2007
|
-
set(value: T): void;
|
|
2008
|
-
/**
|
|
2009
|
-
* On the client, this function will re-fetch the query from the server.
|
|
2010
|
-
*
|
|
2011
|
-
* 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.
|
|
2012
|
-
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
|
|
2013
|
-
*/
|
|
2014
|
-
refresh(): Promise<void>;
|
|
2015
|
-
/**
|
|
2016
|
-
* 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.
|
|
2017
|
-
*
|
|
2018
|
-
* ```svelte
|
|
2019
|
-
* <script>
|
|
2020
|
-
* import { getTodos, addTodo } from './todos.remote.js';
|
|
2021
|
-
* const todos = getTodos();
|
|
2022
|
-
* </script>
|
|
2023
|
-
*
|
|
2024
|
-
* <form {...addTodo.enhance(async (form) => {
|
|
2025
|
-
* await form.submit().updates(
|
|
2026
|
-
* todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
|
|
2027
|
-
* );
|
|
2028
|
-
* })}>
|
|
2029
|
-
* <input type="text" name="text" />
|
|
2030
|
-
* <button type="submit">Add Todo</button>
|
|
2031
|
-
* </form>
|
|
2032
|
-
* ```
|
|
2033
|
-
*/
|
|
2034
|
-
withOverride(update: (current: T) => T): RemoteQueryOverride;
|
|
2035
|
-
};
|
|
2036
|
-
|
|
2037
|
-
export type RemoteLiveQuery<T> = RemoteResource<T> &
|
|
2038
|
-
AsyncIterable<T> & {
|
|
2039
|
-
/** `true` if the live stream is currently connected. */
|
|
2040
|
-
readonly connected: boolean;
|
|
2041
|
-
/** `true` once the current live stream iterator is done. */
|
|
2042
|
-
readonly done: boolean;
|
|
2043
|
-
/** Reconnects the live stream immediately. */
|
|
2044
|
-
reconnect(): Promise<void>;
|
|
2045
|
-
};
|
|
2046
|
-
|
|
2047
|
-
export type RemoteQueryOverride = () => void;
|
|
2048
|
-
|
|
2049
|
-
/**
|
|
2050
|
-
* The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
|
|
2051
|
-
*/
|
|
2052
|
-
export type RemotePrerenderFunction<Input, Output> = (
|
|
2053
|
-
arg: undefined extends Input ? Input | void : Input
|
|
2054
|
-
) => RemoteResource<Output>;
|
|
2055
|
-
|
|
2056
|
-
/**
|
|
2057
|
-
* The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
|
|
2058
|
-
*
|
|
2059
|
-
* The optional `Validated` generic parameter represents the argument type *after* the
|
|
2060
|
-
* query's schema has validated and (optionally) transformed it — this is the type the
|
|
2061
|
-
* query's implementation function receives on the server, and the type yielded by
|
|
2062
|
-
* [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
|
|
2063
|
-
* with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
|
|
2064
|
-
* schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
|
|
2065
|
-
* `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
|
|
2066
|
-
* without arguments it defaults to `Input`.
|
|
2067
|
-
*/
|
|
2068
|
-
export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
|
|
2069
|
-
arg: undefined extends Input ? Input | void : Input
|
|
2070
|
-
) => RemoteQuery<Output>;
|
|
2071
|
-
|
|
2072
|
-
/**
|
|
2073
|
-
* The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
|
|
2074
|
-
*
|
|
2075
|
-
* The optional `Validated` generic parameter represents the argument type *after* the
|
|
2076
|
-
* query's schema has validated and (optionally) transformed it, and matches the type
|
|
2077
|
-
* yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
|
|
2078
|
-
*/
|
|
2079
|
-
export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
|
|
2080
|
-
arg: undefined extends Input ? Input | void : Input
|
|
2081
|
-
) => RemoteLiveQuery<Output>;
|
|
2082
|
-
|
|
2083
|
-
/**
|
|
2084
|
-
* [Environment variables](https://svelte.dev/docs/kit/environment-variables) can be configured by exporting
|
|
2085
|
-
* a `variables` object from `src/env.ts`, using [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
|
|
2086
|
-
*/
|
|
2087
|
-
export interface EnvVarConfig<T> {
|
|
2088
|
-
/**
|
|
2089
|
-
* Whether the environment variable can be accessed by client-side code.
|
|
2090
|
-
* - if `true`, it can be imported from `$app/env/public`
|
|
2091
|
-
* - if `false`, it can be imported from `$app/env/private`, which is a [server-only module](https://svelte.dev/docs/kit/server-only-modules)
|
|
2092
|
-
* @default false
|
|
2093
|
-
*/
|
|
2094
|
-
public?: boolean;
|
|
2095
|
-
/**
|
|
2096
|
-
* Whether the value is determined at build time or when the app runs.
|
|
2097
|
-
* - if `true`, the build time value is inlined into the bundle. This enables optimisations like dead-code elimination
|
|
2098
|
-
* - if `false`, the value is read from the environment when the app starts
|
|
2099
|
-
* @default false
|
|
2100
|
-
*/
|
|
2101
|
-
static?: boolean;
|
|
2102
|
-
/**
|
|
2103
|
-
* A [Standard Schema](https://standardschema.dev/) validator that is applied to the value when the app starts.
|
|
2104
|
-
* Alternatively, a function that returns the (possibly transformed) value, or throws an error explaining
|
|
2105
|
-
* the problem. Returning `undefined` is valid, so a function can describe an optional variable.
|
|
2106
|
-
* The validator can output any value — not necessarily a string — but public, non-static values must be
|
|
2107
|
-
* serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
|
|
2108
|
-
*
|
|
2109
|
-
* If omitted, the value must be set, but may be an empty string.
|
|
2110
|
-
*/
|
|
2111
|
-
schema?: StandardSchemaV1<string | undefined, T> | ((value: string | undefined) => T | undefined);
|
|
2112
|
-
/**
|
|
2113
|
-
* A description of the variable that will be used for inline documentation on hover.
|
|
2114
|
-
*/
|
|
2115
|
-
description?: string;
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
/**
|
|
2119
|
-
* The return type of [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
|
|
2120
|
-
*/
|
|
2121
|
-
export type DefinedEnvVars<T extends Record<string, EnvVarConfig<any>>> = {
|
|
2122
|
-
readonly [K in keyof T]: EnvVarEntry<T[K]>;
|
|
2123
|
-
};
|
|
2124
|
-
|
|
2125
|
-
/**
|
|
2126
|
-
* Normalizes an environment variable config's schema (standard schema or function) to standard schema.
|
|
2127
|
-
*/
|
|
2128
|
-
type EnvVarEntry<C extends EnvVarConfig<any>> =
|
|
2129
|
-
C['schema'] extends StandardSchemaV1<any, any>
|
|
2130
|
-
? C
|
|
2131
|
-
: C['schema'] extends (value: any) => infer R
|
|
2132
|
-
? Omit<C, 'schema'> & { schema: StandardSchemaV1<string | undefined, R> }
|
|
2133
|
-
: C;
|
|
2134
|
-
interface AdapterEntry {
|
|
2135
|
-
/**
|
|
2136
|
-
* A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
|
|
2137
|
-
* For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
|
|
2138
|
-
* be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
|
|
2139
|
-
*/
|
|
2140
|
-
id: string;
|
|
1381
|
+
interface AdapterEntry {
|
|
1382
|
+
/**
|
|
1383
|
+
* A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
|
|
1384
|
+
* For example, `/foo/a-[b]` and `/foo/[c]` are different routes, but would both
|
|
1385
|
+
* be represented in a Netlify _redirects file as `/foo/:param`, so they share an ID
|
|
1386
|
+
*/
|
|
1387
|
+
id: string;
|
|
2141
1388
|
|
|
2142
1389
|
/**
|
|
2143
1390
|
* A function that compares the candidate route with the current route to determine
|
|
@@ -2393,16 +1640,6 @@ declare module '@sveltejs/kit' {
|
|
|
2393
1640
|
dynamic: boolean;
|
|
2394
1641
|
rest: boolean;
|
|
2395
1642
|
}
|
|
2396
|
-
|
|
2397
|
-
type DeepPartial<T> = T extends Record<PropertyKey, unknown> | unknown[]
|
|
2398
|
-
? {
|
|
2399
|
-
[K in keyof T]?: T[K] extends Record<PropertyKey, unknown> | unknown[]
|
|
2400
|
-
? DeepPartial<T[K]>
|
|
2401
|
-
: T[K];
|
|
2402
|
-
}
|
|
2403
|
-
: T | undefined;
|
|
2404
|
-
|
|
2405
|
-
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
2406
1643
|
type RecursiveRequired<T> = {
|
|
2407
1644
|
// Recursive implementation of TypeScript's Required utility type.
|
|
2408
1645
|
// Will recursively continue until it reaches a primitive or Function
|
|
@@ -2551,7 +1788,7 @@ declare module '@sveltejs/kit' {
|
|
|
2551
1788
|
* @param e The object to check.
|
|
2552
1789
|
* @since 2.47.3
|
|
2553
1790
|
*/
|
|
2554
|
-
export function isValidationError(e: unknown): e is
|
|
1791
|
+
export function isValidationError(e: unknown): e is import("$app/server").ValidationError;
|
|
2555
1792
|
/**
|
|
2556
1793
|
* Strips possible SvelteKit-internal suffixes and trailing slashes from the URL pathname.
|
|
2557
1794
|
* Returns the normalized URL as well as a method for adding the potential suffix back
|
|
@@ -2576,7 +1813,58 @@ declare module '@sveltejs/kit' {
|
|
|
2576
1813
|
}
|
|
2577
1814
|
|
|
2578
1815
|
declare module '@sveltejs/kit/env' {
|
|
2579
|
-
import type {
|
|
1816
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
1817
|
+
/**
|
|
1818
|
+
* [Environment variables](https://svelte.dev/docs/kit/environment-variables) can be configured by exporting
|
|
1819
|
+
* a `variables` object from `src/env.ts`, using [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
|
|
1820
|
+
*/
|
|
1821
|
+
export interface EnvVarConfig<T> {
|
|
1822
|
+
/**
|
|
1823
|
+
* Whether the environment variable can be accessed by client-side code.
|
|
1824
|
+
* - if `true`, it can be imported from `$app/env/public`
|
|
1825
|
+
* - if `false`, it can be imported from `$app/env/private`, which is a [server-only module](https://svelte.dev/docs/kit/server-only-modules)
|
|
1826
|
+
* @default false
|
|
1827
|
+
*/
|
|
1828
|
+
public?: boolean;
|
|
1829
|
+
/**
|
|
1830
|
+
* Whether the value is determined at build time or when the app runs.
|
|
1831
|
+
* - if `true`, the build time value is inlined into the bundle. This enables optimisations like dead-code elimination
|
|
1832
|
+
* - if `false`, the value is read from the environment when the app starts
|
|
1833
|
+
* @default false
|
|
1834
|
+
*/
|
|
1835
|
+
static?: boolean;
|
|
1836
|
+
/**
|
|
1837
|
+
* A [Standard Schema](https://standardschema.dev/) validator that is applied to the value when the app starts.
|
|
1838
|
+
* Alternatively, a function that returns the (possibly transformed) value, or throws an error explaining
|
|
1839
|
+
* the problem. Returning `undefined` is valid, so a function can describe an optional variable.
|
|
1840
|
+
* The validator can output any value — not necessarily a string — but public, non-static values must be
|
|
1841
|
+
* serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
|
|
1842
|
+
*
|
|
1843
|
+
* If omitted, the value must be set, but may be an empty string.
|
|
1844
|
+
*/
|
|
1845
|
+
schema?: StandardSchemaV1<string | undefined, T> | ((value: string | undefined) => T | undefined);
|
|
1846
|
+
/**
|
|
1847
|
+
* A description of the variable that will be used for inline documentation on hover.
|
|
1848
|
+
*/
|
|
1849
|
+
description?: string;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
/**
|
|
1853
|
+
* The return type of [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-env#defineEnvVars).
|
|
1854
|
+
*/
|
|
1855
|
+
export type DefinedEnvVars<T extends Record<string, EnvVarConfig<any>>> = {
|
|
1856
|
+
readonly [K in keyof T]: EnvVarEntry<T[K]>;
|
|
1857
|
+
};
|
|
1858
|
+
|
|
1859
|
+
/**
|
|
1860
|
+
* Normalizes an environment variable config's schema (standard schema or function) to standard schema.
|
|
1861
|
+
*/
|
|
1862
|
+
type EnvVarEntry<C extends EnvVarConfig<any>> =
|
|
1863
|
+
C['schema'] extends StandardSchemaV1<any, any>
|
|
1864
|
+
? C
|
|
1865
|
+
: C['schema'] extends (value: any) => infer R
|
|
1866
|
+
? Omit<C, 'schema'> & { schema: StandardSchemaV1<string | undefined, R> }
|
|
1867
|
+
: C;
|
|
2580
1868
|
/**
|
|
2581
1869
|
* Utility for defining [environment variables](https://svelte.dev/docs/kit/environment-variables),
|
|
2582
1870
|
* which are made available via `$app/env/public` and `$app/env/private`.
|
|
@@ -2604,11 +1892,201 @@ declare module '@sveltejs/kit/env' {
|
|
|
2604
1892
|
* */
|
|
2605
1893
|
export function defineEnvVars<T extends Record<string, EnvVarConfig<any>>>(variables: T): DefinedEnvVars<T>;
|
|
2606
1894
|
|
|
2607
|
-
export {};
|
|
2608
|
-
}
|
|
1895
|
+
export {};
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
declare module '@sveltejs/kit/hooks' {
|
|
1899
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
1900
|
+
import type { NavigationEvent, RequestEvent } from '@sveltejs/kit';
|
|
1901
|
+
/**
|
|
1902
|
+
* The [`handle`](https://svelte.dev/docs/kit/hooks#handle) hook runs every time the SvelteKit server receives a [request](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Request) and
|
|
1903
|
+
* determines the [response](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Response).
|
|
1904
|
+
* It receives an `event` object representing the request and a function called `resolve`, which renders the route and generates a `Response`.
|
|
1905
|
+
* This allows you to modify response headers or bodies, or bypass SvelteKit entirely (for implementing routes programmatically, for example).
|
|
1906
|
+
*/
|
|
1907
|
+
export type Handle = (input: {
|
|
1908
|
+
event: RequestEvent;
|
|
1909
|
+
resolve: (event: RequestEvent, opts?: ResolveOptions) => Promise<Response>;
|
|
1910
|
+
}) => MaybePromise<Response>;
|
|
1911
|
+
|
|
1912
|
+
type CaughtErrorMap = {
|
|
1913
|
+
app: App.Error;
|
|
1914
|
+
framework: { status: number; message: string };
|
|
1915
|
+
unknown: unknown;
|
|
1916
|
+
};
|
|
1917
|
+
|
|
1918
|
+
type ValidationCaughtError<Issue extends StandardSchemaV1.Issue> = {
|
|
1919
|
+
kind: 'validation';
|
|
1920
|
+
error: { status: number; message: string };
|
|
1921
|
+
issues: Issue[];
|
|
1922
|
+
};
|
|
1923
|
+
|
|
1924
|
+
/**
|
|
1925
|
+
* The error passed to the [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hooks.
|
|
1926
|
+
* Use the `kind` discriminant to distinguish errors from your app (thrown with the
|
|
1927
|
+
* [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper), errors generated by
|
|
1928
|
+
* SvelteKit itself (such as 404s), validation errors, and unknown errors (thrown by your code,
|
|
1929
|
+
* or code it calls).
|
|
1930
|
+
*/
|
|
1931
|
+
export type CaughtError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> =
|
|
1932
|
+
| {
|
|
1933
|
+
[Kind in keyof CaughtErrorMap]: {
|
|
1934
|
+
/** Identifies the category and origin of the error */
|
|
1935
|
+
kind: Kind;
|
|
1936
|
+
/** The caught error. Its type depends on `kind` */
|
|
1937
|
+
error: CaughtErrorMap[Kind];
|
|
1938
|
+
/** Only present for validation errors */
|
|
1939
|
+
issues?: undefined;
|
|
1940
|
+
};
|
|
1941
|
+
}[keyof CaughtErrorMap]
|
|
1942
|
+
| ValidationCaughtError<Issue>;
|
|
1943
|
+
|
|
1944
|
+
/** The error passed to the client-side `handleError` hook. */
|
|
1945
|
+
export type ClientCaughtError = Exclude<CaughtError, { kind: 'validation' }>;
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* The server-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs for every error thrown while responding to a request, except redirects.
|
|
1949
|
+
*
|
|
1950
|
+
* The `kind` property discriminates between _app_ errors (thrown with the [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper),
|
|
1951
|
+
* _framework_ errors (generated by SvelteKit itself, such as 404s), _validation_ errors (caused by invalid remote function arguments)
|
|
1952
|
+
* and _unknown_ errors (thrown by your code, or code it calls).
|
|
1953
|
+
*
|
|
1954
|
+
* The hook returns an object matching `App.Error`, in which `status` and `message` are optional — return them only to
|
|
1955
|
+
* override the defaults. Omitted properties are inherited from the caught error: the body passed to `error(...)` for app errors,
|
|
1956
|
+
* the status and safe message for framework and validation errors, and `500`/`'Internal Error'` for unknown errors. Return nothing to
|
|
1957
|
+
* keep the defaults entirely (if you augment `App.Error` with required properties, you must return those).
|
|
1958
|
+
*
|
|
1959
|
+
* Make sure that this function _never_ throws an error.
|
|
1960
|
+
*/
|
|
1961
|
+
export type HandleServerError<Issue extends StandardSchemaV1.Issue = StandardSchemaV1.Issue> = (
|
|
1962
|
+
input: CaughtError<Issue> & { event: RequestEvent }
|
|
1963
|
+
) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
|
|
1964
|
+
|
|
1965
|
+
/**
|
|
1966
|
+
* The client-side [`handleError`](https://svelte.dev/docs/kit/hooks#handleError) hook runs for every error thrown while navigating, except redirects.
|
|
1967
|
+
* Errors that were already transformed by the server-side hook are not passed to it a second time.
|
|
1968
|
+
*
|
|
1969
|
+
* The `kind` property discriminates between _app_ errors (thrown with the [`error`](https://svelte.dev/docs/kit/errors#App-errors) helper),
|
|
1970
|
+
* _framework_ errors (generated by SvelteKit itself, such as 404s) and _unknown_ errors (thrown by your code, or code it calls).
|
|
1971
|
+
*
|
|
1972
|
+
* The hook returns an object matching `App.Error`, in which `status` and `message` are optional — return them only to
|
|
1973
|
+
* override the defaults. Omitted properties are inherited from the caught error: the body passed to `error(...)` for app errors,
|
|
1974
|
+
* the status and safe message for framework errors, and `500`/`'Internal Error'` for unknown errors. Return nothing to
|
|
1975
|
+
* keep the defaults entirely (if you augment `App.Error` with required properties, you must return those).
|
|
1976
|
+
*
|
|
1977
|
+
* Make sure that this function _never_ throws an error.
|
|
1978
|
+
*/
|
|
1979
|
+
export type HandleClientError = (
|
|
1980
|
+
input: ClientCaughtError & { event: NavigationEvent }
|
|
1981
|
+
) => MaybePromise<AppErrorWithOptionalDefaults | VoidIfNoRequiredAppErrorProperties>;
|
|
1982
|
+
|
|
1983
|
+
/**
|
|
1984
|
+
* The [`handleFetch`](https://svelte.dev/docs/kit/hooks#handleFetch) hook allows you to modify (or replace) the result of an [`event.fetch`](https://svelte.dev/docs/kit/load#Making-fetch-requests) call that runs on the server (or during prerendering) inside an endpoint, `load`, `action`, `handle`, `handleError` or `reroute`.
|
|
1985
|
+
*/
|
|
1986
|
+
export type HandleFetch = (input: {
|
|
1987
|
+
event: RequestEvent;
|
|
1988
|
+
request: Request;
|
|
1989
|
+
fetch: typeof fetch;
|
|
1990
|
+
}) => MaybePromise<Response>;
|
|
1991
|
+
|
|
1992
|
+
/**
|
|
1993
|
+
* The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked before the server responds to its first request
|
|
1994
|
+
* @since 2.10.0
|
|
1995
|
+
*/
|
|
1996
|
+
export type ServerInit = () => MaybePromise<void>;
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* The [`init`](https://svelte.dev/docs/kit/hooks#init) will be invoked once the app starts in the browser
|
|
2000
|
+
* @since 2.10.0
|
|
2001
|
+
*/
|
|
2002
|
+
export type ClientInit = () => MaybePromise<void>;
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* The [`reroute`](https://svelte.dev/docs/kit/hooks#reroute) hook allows you to modify the URL before it is used to determine which route to render.
|
|
2006
|
+
* @since 2.3.0
|
|
2007
|
+
*/
|
|
2008
|
+
export type Reroute = (event: { url: URL; fetch: typeof fetch }) => MaybePromise<void | string>;
|
|
2009
|
+
|
|
2010
|
+
/**
|
|
2011
|
+
* The [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook allows you to transport custom types across the server/client boundary.
|
|
2012
|
+
*
|
|
2013
|
+
* Each transporter has a pair of `encode` and `decode` functions. On the server, `encode` determines whether a value is an instance of the custom type and, if so, returns a non-falsy encoding of the value which can be an object or an array (or `false` otherwise).
|
|
2014
|
+
*
|
|
2015
|
+
* In the browser, `decode` turns the encoding back into an instance of the custom type.
|
|
2016
|
+
*
|
|
2017
|
+
* ```ts
|
|
2018
|
+
* import type { Transport } from '@sveltejs/kit/hooks';
|
|
2019
|
+
*
|
|
2020
|
+
* declare class MyCustomType {
|
|
2021
|
+
* data: any
|
|
2022
|
+
* }
|
|
2023
|
+
*
|
|
2024
|
+
* // hooks.js
|
|
2025
|
+
* export const transport: Transport = {
|
|
2026
|
+
* MyCustomType: {
|
|
2027
|
+
* encode: (value) => value instanceof MyCustomType && [value.data],
|
|
2028
|
+
* decode: ([data]) => new MyCustomType(data)
|
|
2029
|
+
* }
|
|
2030
|
+
* };
|
|
2031
|
+
* ```
|
|
2032
|
+
* @since 2.11.0
|
|
2033
|
+
*/
|
|
2034
|
+
export type Transport = Record<string, Transporter>;
|
|
2035
|
+
|
|
2036
|
+
/**
|
|
2037
|
+
* A member of the [`transport`](https://svelte.dev/docs/kit/hooks#transport) hook.
|
|
2038
|
+
*/
|
|
2039
|
+
export interface Transporter<
|
|
2040
|
+
T = any,
|
|
2041
|
+
U = any /* minus falsy values, but we can't properly express that */
|
|
2042
|
+
> {
|
|
2043
|
+
encode: (value: T) => false | U;
|
|
2044
|
+
decode: (data: U) => T;
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
export interface ResolveOptions {
|
|
2048
|
+
/**
|
|
2049
|
+
* Applies custom transforms to HTML. If `done` is true, it's the final chunk. Chunks are not guaranteed to be well-formed HTML
|
|
2050
|
+
* (they could include an element's opening tag but not its closing tag, for example)
|
|
2051
|
+
* but they will always be split at sensible boundaries such as `%sveltekit.head%` or layout/page components.
|
|
2052
|
+
* @param input the html chunk and the info if this is the last chunk
|
|
2053
|
+
*/
|
|
2054
|
+
transformPageChunk?: (input: { html: string; done: boolean }) => MaybePromise<string | undefined>;
|
|
2055
|
+
/**
|
|
2056
|
+
* Determines which headers should be included in serialized responses when a `load` function loads a resource with `fetch`.
|
|
2057
|
+
* By default, none will be included.
|
|
2058
|
+
* @param name header name
|
|
2059
|
+
* @param value header value
|
|
2060
|
+
*/
|
|
2061
|
+
filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
|
|
2062
|
+
/**
|
|
2063
|
+
* Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
|
|
2064
|
+
* `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
|
|
2065
|
+
* [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
|
|
2066
|
+
* By default, `js` and `css` files will be preloaded.
|
|
2067
|
+
* @param input the type of the file and its path
|
|
2068
|
+
*/
|
|
2069
|
+
preload?: (input: { type: 'font' | 'css' | 'js' | 'asset'; path: string }) => boolean;
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
type AppErrorWithOptionalDefaults = Omit<App.Error, 'status' | 'message'> & {
|
|
2073
|
+
status?: App.Error['status'];
|
|
2074
|
+
message?: App.Error['message'];
|
|
2075
|
+
};
|
|
2609
2076
|
|
|
2610
|
-
|
|
2611
|
-
|
|
2077
|
+
/**
|
|
2078
|
+
* `void` is only a valid `handleError` return when `App.Error` adds no required properties
|
|
2079
|
+
* beyond `status` and `message` — both of which are optional in the return, since they default
|
|
2080
|
+
* to those of the caught error. If `App.Error` is augmented with required properties, the hook
|
|
2081
|
+
* must return them, so returning nothing becomes a type error.
|
|
2082
|
+
*/
|
|
2083
|
+
type VoidIfNoRequiredAppErrorProperties = {
|
|
2084
|
+
status: number;
|
|
2085
|
+
message: string;
|
|
2086
|
+
} extends App.Error
|
|
2087
|
+
? void
|
|
2088
|
+
: never;
|
|
2089
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
2612
2090
|
/**
|
|
2613
2091
|
* A helper function for sequencing multiple `handle` calls in a middleware-like manner.
|
|
2614
2092
|
* The behavior for the `handle` options is as follows:
|
|
@@ -2620,7 +2098,7 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
2620
2098
|
* /// file: src/hooks.server.js
|
|
2621
2099
|
* import { sequence } from '@sveltejs/kit/hooks';
|
|
2622
2100
|
*
|
|
2623
|
-
* /// type: import('@sveltejs/kit').Handle
|
|
2101
|
+
* /// type: import('@sveltejs/kit/hooks').Handle
|
|
2624
2102
|
* async function first({ event, resolve }) {
|
|
2625
2103
|
* console.log('first pre-processing');
|
|
2626
2104
|
* const result = await resolve(event, {
|
|
@@ -2639,7 +2117,7 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
2639
2117
|
* return result;
|
|
2640
2118
|
* }
|
|
2641
2119
|
*
|
|
2642
|
-
* /// type: import('@sveltejs/kit').Handle
|
|
2120
|
+
* /// type: import('@sveltejs/kit/hooks').Handle
|
|
2643
2121
|
* async function second({ event, resolve }) {
|
|
2644
2122
|
* console.log('second pre-processing');
|
|
2645
2123
|
* const result = await resolve(event, {
|
|
@@ -2681,719 +2159,1242 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
2681
2159
|
*
|
|
2682
2160
|
* @param handlers The chain of `handle` functions
|
|
2683
2161
|
* */
|
|
2684
|
-
export function sequence(...handlers: Handle[]): Handle;
|
|
2162
|
+
export function sequence(...handlers: Handle[]): Handle;
|
|
2163
|
+
|
|
2164
|
+
export {};
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
declare module '@sveltejs/kit/node' {
|
|
2168
|
+
export function getRequest({ request, base, bodySizeLimit }: {
|
|
2169
|
+
request: import("http").IncomingMessage;
|
|
2170
|
+
base: string;
|
|
2171
|
+
bodySizeLimit?: number;
|
|
2172
|
+
}): Request;
|
|
2173
|
+
|
|
2174
|
+
export function setResponse(res: import("http").ServerResponse, response: Response): void;
|
|
2175
|
+
/**
|
|
2176
|
+
* Converts a file on disk to a readable stream
|
|
2177
|
+
* @since 2.4.0
|
|
2178
|
+
*/
|
|
2179
|
+
export function createReadableStream(file: string): ReadableStream;
|
|
2180
|
+
|
|
2181
|
+
export {};
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
declare module '@sveltejs/kit/params' {
|
|
2185
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2186
|
+
/**
|
|
2187
|
+
* The shape of a param matcher. See [matching](https://svelte.dev/docs/kit/advanced-routing#Matching) for more info.
|
|
2188
|
+
*/
|
|
2189
|
+
export type ParamMatcher<Output = any> = StandardSchemaV1<string, Output>;
|
|
2190
|
+
|
|
2191
|
+
/**
|
|
2192
|
+
* A value that can be parsed from a URL param and losslessly encoded with `String(...)`.
|
|
2193
|
+
*/
|
|
2194
|
+
export type ParamValue = string | number | boolean | bigint;
|
|
2195
|
+
|
|
2196
|
+
/**
|
|
2197
|
+
* A param matcher definition passed to [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit-params#defineParams).
|
|
2198
|
+
*/
|
|
2199
|
+
export type ParamDefinition =
|
|
2200
|
+
| ((param: string) => ParamValue | undefined)
|
|
2201
|
+
| StandardSchemaV1<string, ParamValue>;
|
|
2202
|
+
|
|
2203
|
+
/**
|
|
2204
|
+
* The return type of [`defineParams`](https://svelte.dev/docs/kit/@sveltejs-kit-params#defineParams).
|
|
2205
|
+
*/
|
|
2206
|
+
export type DefinedParams<T extends Record<string, ParamDefinition>> = {
|
|
2207
|
+
readonly [K in keyof T]: ParamEntry<T[K]>;
|
|
2208
|
+
};
|
|
2209
|
+
|
|
2210
|
+
/**
|
|
2211
|
+
* Normalizes a property of defineParams (schema or function) to standard schema.
|
|
2212
|
+
*/
|
|
2213
|
+
type ParamEntry<M> =
|
|
2214
|
+
M extends StandardSchemaV1<any, any>
|
|
2215
|
+
? StandardSchemaV1.InferOutput<M> extends ParamValue
|
|
2216
|
+
? StandardSchemaV1<any, M>
|
|
2217
|
+
: StandardSchemaV1<any, never>
|
|
2218
|
+
: M extends (param: string) => infer R
|
|
2219
|
+
? Exclude<R, undefined> extends ParamValue
|
|
2220
|
+
? StandardSchemaV1<any, Exclude<R, undefined>>
|
|
2221
|
+
: StandardSchemaV1<any, never>
|
|
2222
|
+
: never;
|
|
2223
|
+
|
|
2224
|
+
/**
|
|
2225
|
+
* Extracts the param type from a matcher.
|
|
2226
|
+
*/
|
|
2227
|
+
export type MatcherParam<M extends StandardSchemaV1<any, any>> =
|
|
2228
|
+
M extends StandardSchemaV1<any, infer Inner>
|
|
2229
|
+
? Inner extends ParamValue
|
|
2230
|
+
? Inner
|
|
2231
|
+
: Inner extends StandardSchemaV1<any, any>
|
|
2232
|
+
? StandardSchemaV1.InferOutput<Inner> extends ParamValue
|
|
2233
|
+
? StandardSchemaV1.InferOutput<Inner>
|
|
2234
|
+
: never
|
|
2235
|
+
: never
|
|
2236
|
+
: never;
|
|
2237
|
+
|
|
2238
|
+
/**
|
|
2239
|
+
* Define [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching) for your app.
|
|
2240
|
+
*
|
|
2241
|
+
* */
|
|
2242
|
+
export function defineParams<T extends Record<string, ParamDefinition>>(
|
|
2243
|
+
definitions: T
|
|
2244
|
+
): DefinedParams<T>;
|
|
2245
|
+
|
|
2246
|
+
export {};
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
declare module '@sveltejs/kit/vite' {
|
|
2250
|
+
import type { KitConfig } from '@sveltejs/kit';
|
|
2251
|
+
import type { Options, SvelteConfig } from '@sveltejs/vite-plugin-svelte';
|
|
2252
|
+
import type { Plugin } from 'vite';
|
|
2253
|
+
/**
|
|
2254
|
+
* Returns the SvelteKit Vite plugins.
|
|
2255
|
+
* Any options that don't belong to SvelteKit are passed through to `vite-plugin-svelte`.
|
|
2256
|
+
*
|
|
2257
|
+
* Since version 3.0.0 you must pass [configuration](configuration) directly.
|
|
2258
|
+
*
|
|
2259
|
+
* Since version 2.62.0 you can pass configuration directly, in which case `svelte.config.js` is ignored.
|
|
2260
|
+
*
|
|
2261
|
+
* */
|
|
2262
|
+
export function sveltekit(config?: KitConfig & Omit<Options, "onwarn"> & Pick<SvelteConfig, "vitePlugin">): Promise<Plugin[]>;
|
|
2263
|
+
|
|
2264
|
+
export {};
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
declare module '$app/env' {
|
|
2268
|
+
/**
|
|
2269
|
+
* `true` if the app is running in the browser.
|
|
2270
|
+
*/
|
|
2271
|
+
export const browser: boolean;
|
|
2272
|
+
|
|
2273
|
+
/**
|
|
2274
|
+
* Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
|
|
2275
|
+
*/
|
|
2276
|
+
export const dev: boolean;
|
|
2277
|
+
|
|
2278
|
+
/**
|
|
2279
|
+
* SvelteKit analyses your app during the `build` step by running it. During this process, `building` is `true`. This also applies during prerendering.
|
|
2280
|
+
*/
|
|
2281
|
+
export const building: boolean;
|
|
2282
|
+
|
|
2283
|
+
/**
|
|
2284
|
+
* The value of `config.version.name`.
|
|
2285
|
+
*/
|
|
2286
|
+
export const version: string;
|
|
2287
|
+
|
|
2288
|
+
export {};
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
declare module '$app/forms' {
|
|
2292
|
+
/**
|
|
2293
|
+
* Use this function to deserialize the response from a form submission.
|
|
2294
|
+
* Usage:
|
|
2295
|
+
*
|
|
2296
|
+
* ```js
|
|
2297
|
+
* import { deserialize } from '$app/forms';
|
|
2298
|
+
*
|
|
2299
|
+
* async function handleSubmit(event) {
|
|
2300
|
+
* const response = await fetch('/form?/action', {
|
|
2301
|
+
* method: 'POST',
|
|
2302
|
+
* body: new FormData(event.target)
|
|
2303
|
+
* });
|
|
2304
|
+
*
|
|
2305
|
+
* const result = deserialize(await response.text());
|
|
2306
|
+
* // ...
|
|
2307
|
+
* }
|
|
2308
|
+
* ```
|
|
2309
|
+
* */
|
|
2310
|
+
export function deserialize<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: string): ActionResult<Success, Failure>;
|
|
2311
|
+
/**
|
|
2312
|
+
* This action enhances a `<form>` element that otherwise would work without JavaScript.
|
|
2313
|
+
*
|
|
2314
|
+
* The `submit` function is called upon submission with the given FormData and the `action` that should be triggered.
|
|
2315
|
+
* If `cancel` is called, the form will not be submitted.
|
|
2316
|
+
* You can use the abort `controller` to cancel the submission in case another one starts.
|
|
2317
|
+
* If a function is returned, that function is called with the response from the server.
|
|
2318
|
+
* If nothing is returned, the fallback will be used.
|
|
2319
|
+
*
|
|
2320
|
+
* If this function or its return value isn't set, it emulates the browser-native behaviour, just without the full-page reload. It
|
|
2321
|
+
* - resets the `<form>` element and refreshes all data in case of a successful submission with no redirect response
|
|
2322
|
+
* - updates the `form` prop, `page.form` and `page.status` if the action is on the same page as the form
|
|
2323
|
+
* - navigates to the page the submission lands on — populating that page's `form` prop and `page.status` — on success and failure if that isn't the current page, just as a native form submission would, but with the `?/actionName` param stripped from the destination URL
|
|
2324
|
+
* - redirects in case of a redirect response
|
|
2325
|
+
* - renders the nearest error page in case of an unexpected error — the one nearest the action's route, if the action is on a different page
|
|
2326
|
+
*
|
|
2327
|
+
* If you provide a custom function with a callback and want to use the default behavior, invoke `update` in your callback.
|
|
2328
|
+
* It accepts an options object
|
|
2329
|
+
* - `reset: false` if you don't want the `<form>` values to be reset after a successful submission
|
|
2330
|
+
* - `refreshAll` to control whether all data is refreshed after submission; it defaults to `true` for successes and `false` for failures
|
|
2331
|
+
* - `navigate: false` to apply non-redirect results to the current page rather than navigating to `result.location`; redirects are always followed
|
|
2332
|
+
* @param form_element The form element
|
|
2333
|
+
* @param submit Submit callback
|
|
2334
|
+
*/
|
|
2335
|
+
export function enhance<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(form_element: HTMLFormElement, submit?: SubmitFunction<Success, Failure>): {
|
|
2336
|
+
destroy(): void;
|
|
2337
|
+
};
|
|
2338
|
+
/**
|
|
2339
|
+
* When calling a form action via fetch, the response will be one of these shapes.
|
|
2340
|
+
* ```svelte
|
|
2341
|
+
* <form method="post" use:enhance={() => {
|
|
2342
|
+
* return ({ result }) => {
|
|
2343
|
+
* // result is of type ActionResult
|
|
2344
|
+
* };
|
|
2345
|
+
* }}
|
|
2346
|
+
* ```
|
|
2347
|
+
*
|
|
2348
|
+
* Success and failure results carry the root-relative `pathname + search` of the action URL, with
|
|
2349
|
+
* the `?/actionName` parameter removed. Redirect results carry the redirect target. Server-generated
|
|
2350
|
+
* error results also carry the action location, while client-generated errors such as network
|
|
2351
|
+
* failures do not. `update` uses this location to emulate native form navigation.
|
|
2352
|
+
*/
|
|
2353
|
+
export type ActionResult<
|
|
2354
|
+
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
2355
|
+
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
2356
|
+
> =
|
|
2357
|
+
| { type: 'success'; status: number; data?: Success; location: string }
|
|
2358
|
+
| { type: 'failure'; status: number; data?: Failure; location: string }
|
|
2359
|
+
| { type: 'redirect'; status: number; location: string }
|
|
2360
|
+
| { type: 'error'; status?: number; error: App.Error; location?: string };
|
|
2361
|
+
|
|
2362
|
+
export type SubmitFunction<
|
|
2363
|
+
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
2364
|
+
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
2365
|
+
> = (input: {
|
|
2366
|
+
action: URL;
|
|
2367
|
+
formData: FormData;
|
|
2368
|
+
formElement: HTMLFormElement;
|
|
2369
|
+
controller: AbortController;
|
|
2370
|
+
submitter: HTMLElement | null;
|
|
2371
|
+
cancel: () => void;
|
|
2372
|
+
}) => MaybePromise<
|
|
2373
|
+
| void
|
|
2374
|
+
| ((opts: {
|
|
2375
|
+
formData: FormData;
|
|
2376
|
+
formElement: HTMLFormElement;
|
|
2377
|
+
action: URL;
|
|
2378
|
+
result: ActionResult<Success, Failure>;
|
|
2379
|
+
/**
|
|
2380
|
+
* Call this to get the default behavior of a form submission response.
|
|
2381
|
+
* @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission. `refreshAll` defaults to `true` for successful results and `false` for failures. When the submission navigates, setting it to `false` still runs the destination's `load` functions but may reuse shared layout data. Set `navigate: false` to apply non-redirect results to the current page instead of navigating to `result.location`. Redirects are always followed.
|
|
2382
|
+
*/
|
|
2383
|
+
update: (options?: {
|
|
2384
|
+
reset?: boolean;
|
|
2385
|
+
refreshAll?: boolean;
|
|
2386
|
+
navigate?: boolean;
|
|
2387
|
+
/** @deprecated Use `refreshAll` instead. */
|
|
2388
|
+
invalidateAll?: boolean;
|
|
2389
|
+
}) => Promise<void>;
|
|
2390
|
+
}) => MaybePromise<void>)
|
|
2391
|
+
>;
|
|
2392
|
+
/**
|
|
2393
|
+
* Updates the `form` property of the current page with the given data and updates `page.status`.
|
|
2394
|
+
* In case of an error, it renders the nearest error page. In case of a redirect, it navigates to
|
|
2395
|
+
* the redirect location.
|
|
2396
|
+
* */
|
|
2397
|
+
export function applyAction<Success extends Record<string, unknown> | undefined, Failure extends Record<string, unknown> | undefined>(result: ActionResult<Success, Failure>): Promise<void>;
|
|
2398
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
2685
2399
|
|
|
2686
2400
|
export {};
|
|
2687
2401
|
}
|
|
2688
2402
|
|
|
2689
|
-
declare module '
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2403
|
+
declare module '$app/navigation' {
|
|
2404
|
+
import type { LayoutParams as AppLayoutParams, RouteId as AppRouteId } from '$app/types';
|
|
2405
|
+
/**
|
|
2406
|
+
* Information about the target of a specific navigation.
|
|
2407
|
+
*/
|
|
2408
|
+
export interface NavigationTarget<
|
|
2409
|
+
Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
|
|
2410
|
+
RouteId extends AppRouteId | null = AppRouteId | null
|
|
2411
|
+
> {
|
|
2412
|
+
/**
|
|
2413
|
+
* Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
2414
|
+
* Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
|
|
2415
|
+
*/
|
|
2416
|
+
params: Params | null;
|
|
2417
|
+
/**
|
|
2418
|
+
* Info about the target route
|
|
2419
|
+
*/
|
|
2420
|
+
route: {
|
|
2421
|
+
/**
|
|
2422
|
+
* The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
|
|
2423
|
+
*/
|
|
2424
|
+
id: RouteId | null;
|
|
2425
|
+
};
|
|
2426
|
+
/**
|
|
2427
|
+
* The URL that is navigated to
|
|
2428
|
+
*/
|
|
2429
|
+
url: URL;
|
|
2430
|
+
/**
|
|
2431
|
+
* The scroll position associated with this navigation.
|
|
2432
|
+
*
|
|
2433
|
+
* For the `from` target, this is the scroll position at the moment of navigation.
|
|
2434
|
+
*
|
|
2435
|
+
* For the `to` target, this represents the scroll position that will be or was restored:
|
|
2436
|
+
* - In `beforeNavigate` and `onNavigate`, this is only available for `popstate` navigations (back/forward button)
|
|
2437
|
+
* and will be `null` for other navigation types, since the final scroll position isn't known
|
|
2438
|
+
* ahead of time.
|
|
2439
|
+
* - In `afterNavigate`, this is always the scroll position that was applied after the navigation
|
|
2440
|
+
* completed.
|
|
2441
|
+
*/
|
|
2442
|
+
scroll: { x: number; y: number } | null;
|
|
2443
|
+
}
|
|
2444
|
+
|
|
2445
|
+
export interface GotoOptions {
|
|
2446
|
+
/**
|
|
2447
|
+
* If `true`, replaces the current history entry rather than creating a new one.
|
|
2448
|
+
* @default false
|
|
2449
|
+
*/
|
|
2450
|
+
replace?: boolean;
|
|
2451
|
+
/** @deprecated Use `replace` instead. */
|
|
2452
|
+
replaceState?: boolean;
|
|
2453
|
+
/**
|
|
2454
|
+
* If `true`, updates the URL and `page.state` without navigating.
|
|
2455
|
+
* @default false
|
|
2456
|
+
*/
|
|
2457
|
+
shallow?: boolean;
|
|
2458
|
+
/**
|
|
2459
|
+
* If `true`, resets the scroll position (to the top of the page, or to the element
|
|
2460
|
+
* matching the URL's `#hash` if there is one) and resets focus (to the `<body>`, or the
|
|
2461
|
+
* `autofocus` element if there is one) once the navigation completes.
|
|
2462
|
+
*
|
|
2463
|
+
* If `false`, the current scroll position and focused element are left alone.
|
|
2464
|
+
* @default true, or false when `shallow` is true
|
|
2465
|
+
*/
|
|
2466
|
+
reset?: boolean;
|
|
2467
|
+
/**
|
|
2468
|
+
* If `true`, reruns all `load` functions and queries of the page.
|
|
2469
|
+
* @default false
|
|
2470
|
+
*/
|
|
2471
|
+
refreshAll?: boolean;
|
|
2472
|
+
/** Causes any `load` functions to rerun if they depend on one of the URLs. */
|
|
2473
|
+
invalidate?: Array<string | URL | ((url: URL) => boolean)>;
|
|
2474
|
+
/** @deprecated Use `refreshAll` instead. */
|
|
2475
|
+
invalidateAll?: boolean;
|
|
2476
|
+
/** An optional object that will be available as `page.state`. */
|
|
2477
|
+
state?: App.PageState;
|
|
2478
|
+
/**
|
|
2479
|
+
* If `true`, `page.state` will be restored after a full page reload.
|
|
2480
|
+
* @default false
|
|
2481
|
+
*/
|
|
2482
|
+
persistState?: boolean;
|
|
2483
|
+
}
|
|
2695
2484
|
|
|
2696
|
-
export function setResponse(res: import("http").ServerResponse, response: Response): void;
|
|
2697
2485
|
/**
|
|
2698
|
-
*
|
|
2699
|
-
*
|
|
2486
|
+
* - `enter`: The app has hydrated/started
|
|
2487
|
+
* - `form`: The user submitted a `<form method="GET">`
|
|
2488
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
2489
|
+
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
2490
|
+
* - `link`: Navigation was triggered by a link click
|
|
2491
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
2700
2492
|
*/
|
|
2701
|
-
export
|
|
2493
|
+
export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
|
|
2702
2494
|
|
|
2703
|
-
export {
|
|
2704
|
-
|
|
2495
|
+
export interface NavigationBase {
|
|
2496
|
+
/**
|
|
2497
|
+
* The type of navigation:
|
|
2498
|
+
* - `enter`: The app has hydrated/started
|
|
2499
|
+
* - `form`: The user submitted a `<form method="GET">`
|
|
2500
|
+
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
2501
|
+
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
2502
|
+
* - `link`: Navigation was triggered by a link click
|
|
2503
|
+
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
2504
|
+
*/
|
|
2505
|
+
type: NavigationType;
|
|
2506
|
+
/** Whether this is a shallow navigation. */
|
|
2507
|
+
shallow: boolean;
|
|
2508
|
+
/**
|
|
2509
|
+
* Where navigation was triggered from
|
|
2510
|
+
*/
|
|
2511
|
+
from: NavigationTarget | null;
|
|
2512
|
+
/**
|
|
2513
|
+
* Where navigation is going to/has gone to
|
|
2514
|
+
*/
|
|
2515
|
+
to: NavigationTarget | null;
|
|
2516
|
+
/**
|
|
2517
|
+
* Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
|
|
2518
|
+
*/
|
|
2519
|
+
willUnload: boolean;
|
|
2520
|
+
/**
|
|
2521
|
+
* A promise that resolves once the navigation is complete, and rejects if the navigation
|
|
2522
|
+
* fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
|
|
2523
|
+
*/
|
|
2524
|
+
complete: Promise<void>;
|
|
2525
|
+
}
|
|
2705
2526
|
|
|
2706
|
-
declare module '@sveltejs/kit/params' {
|
|
2707
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2708
2527
|
/**
|
|
2709
|
-
* The
|
|
2528
|
+
* The navigation that occurs when the app starts/hydrates
|
|
2710
2529
|
*/
|
|
2711
|
-
export
|
|
2530
|
+
export interface NavigationEnter extends NavigationBase {
|
|
2531
|
+
type: 'enter';
|
|
2532
|
+
|
|
2533
|
+
/**
|
|
2534
|
+
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
2535
|
+
*/
|
|
2536
|
+
delta?: undefined;
|
|
2537
|
+
|
|
2538
|
+
/**
|
|
2539
|
+
* Dispatched `Event` object when navigation occurred by `popstate` or `link`.
|
|
2540
|
+
*/
|
|
2541
|
+
event?: undefined;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
export type NavigationExternal = NavigationGoto | NavigationLeave;
|
|
2712
2545
|
|
|
2713
2546
|
/**
|
|
2714
|
-
* A
|
|
2547
|
+
* A navigation triggered by a `goto(...)` call or a redirect
|
|
2715
2548
|
*/
|
|
2716
|
-
export
|
|
2549
|
+
export interface NavigationGoto extends NavigationBase {
|
|
2550
|
+
type: 'goto';
|
|
2551
|
+
}
|
|
2717
2552
|
|
|
2718
2553
|
/**
|
|
2719
|
-
* A
|
|
2554
|
+
* A navigation triggered by the tab being closed, or the user navigating to a different document
|
|
2720
2555
|
*/
|
|
2721
|
-
export
|
|
2722
|
-
|
|
2723
|
-
|
|
2556
|
+
export interface NavigationLeave extends NavigationBase {
|
|
2557
|
+
type: 'leave';
|
|
2558
|
+
}
|
|
2724
2559
|
|
|
2725
2560
|
/**
|
|
2726
|
-
*
|
|
2561
|
+
* A navigation triggered by a `<form method="GET">`
|
|
2727
2562
|
*/
|
|
2728
|
-
export
|
|
2729
|
-
|
|
2730
|
-
|
|
2563
|
+
export interface NavigationFormSubmit extends NavigationBase {
|
|
2564
|
+
type: 'form';
|
|
2565
|
+
|
|
2566
|
+
/**
|
|
2567
|
+
* The `SubmitEvent` that caused the navigation
|
|
2568
|
+
*/
|
|
2569
|
+
event: SubmitEvent;
|
|
2570
|
+
}
|
|
2731
2571
|
|
|
2732
2572
|
/**
|
|
2733
|
-
*
|
|
2573
|
+
* A navigation triggered by back/forward navigation
|
|
2734
2574
|
*/
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2575
|
+
export interface NavigationPopState extends NavigationBase {
|
|
2576
|
+
type: 'popstate';
|
|
2577
|
+
|
|
2578
|
+
/**
|
|
2579
|
+
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
2580
|
+
*/
|
|
2581
|
+
delta: number;
|
|
2582
|
+
|
|
2583
|
+
/**
|
|
2584
|
+
* The `PopStateEvent` that caused the navigation
|
|
2585
|
+
*/
|
|
2586
|
+
event: PopStateEvent;
|
|
2587
|
+
}
|
|
2745
2588
|
|
|
2746
2589
|
/**
|
|
2747
|
-
*
|
|
2590
|
+
* A navigation triggered by a link click
|
|
2748
2591
|
*/
|
|
2749
|
-
export
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2592
|
+
export interface NavigationLink extends NavigationBase {
|
|
2593
|
+
type: 'link';
|
|
2594
|
+
|
|
2595
|
+
/**
|
|
2596
|
+
* The `PointerEvent` that caused the navigation
|
|
2597
|
+
*/
|
|
2598
|
+
event: PointerEvent;
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
export type Navigation =
|
|
2602
|
+
| NavigationExternal
|
|
2603
|
+
| NavigationFormSubmit
|
|
2604
|
+
| NavigationPopState
|
|
2605
|
+
| NavigationLink;
|
|
2606
|
+
|
|
2607
|
+
/**
|
|
2608
|
+
* The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
|
|
2609
|
+
*/
|
|
2610
|
+
export type BeforeNavigate = Navigation & {
|
|
2611
|
+
/**
|
|
2612
|
+
* Call this to prevent the navigation from starting.
|
|
2613
|
+
*/
|
|
2614
|
+
cancel: () => void;
|
|
2615
|
+
};
|
|
2616
|
+
|
|
2617
|
+
/**
|
|
2618
|
+
* The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
|
|
2619
|
+
*/
|
|
2620
|
+
export type OnNavigate = Navigation & {
|
|
2621
|
+
type: Exclude<NavigationType, 'enter' | 'leave'>;
|
|
2622
|
+
/**
|
|
2623
|
+
* Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
|
|
2624
|
+
*/
|
|
2625
|
+
willUnload: false;
|
|
2626
|
+
};
|
|
2759
2627
|
|
|
2760
2628
|
/**
|
|
2761
|
-
*
|
|
2629
|
+
* The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
|
|
2630
|
+
*/
|
|
2631
|
+
export type AfterNavigate = (Navigation | NavigationEnter) & {
|
|
2632
|
+
type: Exclude<NavigationType, 'leave'>;
|
|
2633
|
+
/**
|
|
2634
|
+
* Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
|
|
2635
|
+
*/
|
|
2636
|
+
willUnload: false;
|
|
2637
|
+
};
|
|
2638
|
+
/**
|
|
2639
|
+
* A lifecycle function that captures state before navigating and restores it when traversing history.
|
|
2640
|
+
*
|
|
2641
|
+
* 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.
|
|
2642
|
+
*
|
|
2643
|
+
* 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.
|
|
2762
2644
|
*
|
|
2645
|
+
* `snapshot` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
2763
2646
|
* */
|
|
2764
|
-
export function
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
}
|
|
2770
|
-
|
|
2771
|
-
declare module '@sveltejs/kit/vite' {
|
|
2772
|
-
import type { KitConfig } from '@sveltejs/kit';
|
|
2773
|
-
import type { Options, SvelteConfig } from '@sveltejs/vite-plugin-svelte';
|
|
2774
|
-
import type { Plugin } from 'vite';
|
|
2647
|
+
export function snapshot<T>(options: {
|
|
2648
|
+
id?: string;
|
|
2649
|
+
capture: () => T;
|
|
2650
|
+
restore: (value: T) => void;
|
|
2651
|
+
reset?: () => void;
|
|
2652
|
+
}): void;
|
|
2775
2653
|
/**
|
|
2776
|
-
*
|
|
2777
|
-
* Any options that don't belong to SvelteKit are passed through to `vite-plugin-svelte`.
|
|
2654
|
+
* A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a URL.
|
|
2778
2655
|
*
|
|
2779
|
-
*
|
|
2656
|
+
* `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
2657
|
+
* */
|
|
2658
|
+
export function afterNavigate(callback: (navigation: AfterNavigate) => void): void;
|
|
2659
|
+
/**
|
|
2660
|
+
* 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.
|
|
2780
2661
|
*
|
|
2781
|
-
*
|
|
2662
|
+
* 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.
|
|
2663
|
+
*
|
|
2664
|
+
* 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`.
|
|
2665
|
+
*
|
|
2666
|
+
* 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`.
|
|
2782
2667
|
*
|
|
2668
|
+
* `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
2783
2669
|
* */
|
|
2784
|
-
export function
|
|
2785
|
-
|
|
2786
|
-
export {};
|
|
2787
|
-
}
|
|
2788
|
-
|
|
2789
|
-
declare module '$app/env' {
|
|
2790
|
-
/**
|
|
2791
|
-
* `true` if the app is running in the browser.
|
|
2792
|
-
*/
|
|
2793
|
-
export const browser: boolean;
|
|
2794
|
-
|
|
2670
|
+
export function beforeNavigate(callback: (navigation: BeforeNavigate) => void): void;
|
|
2795
2671
|
/**
|
|
2796
|
-
*
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2672
|
+
* A lifecycle function that runs the supplied `callback` immediately before we navigate to a new URL except during full-page navigations.
|
|
2673
|
+
*
|
|
2674
|
+
* 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.
|
|
2675
|
+
*
|
|
2676
|
+
* 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.
|
|
2677
|
+
*
|
|
2678
|
+
* `onNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
2679
|
+
* */
|
|
2680
|
+
export function onNavigate(callback: (navigation: OnNavigate) => MaybePromise<(() => void) | void>): void;
|
|
2800
2681
|
/**
|
|
2801
|
-
*
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2682
|
+
* 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.
|
|
2683
|
+
* This is generally discouraged, since it breaks user expectations.
|
|
2684
|
+
* */
|
|
2685
|
+
export function disableScrollHandling(): void;
|
|
2805
2686
|
/**
|
|
2806
|
-
*
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2687
|
+
* Allows you to navigate programmatically to a given route, with control over details such as whether scroll and focus are reset
|
|
2688
|
+
* (as they would be with a regular navigation) or preserved.
|
|
2689
|
+
*
|
|
2690
|
+
* 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.
|
|
2691
|
+
*
|
|
2692
|
+
* `goto` is intended for navigations to routes that belong to the app, and will reject if a route cannot be resolved.
|
|
2693
|
+
* For external URLs, use `window.location = url` to perform a full-page navigation instead of calling `goto(url)`.
|
|
2694
|
+
*
|
|
2695
|
+
* @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.
|
|
2696
|
+
* @param opts Options related to the navigation
|
|
2697
|
+
* */
|
|
2698
|
+
export function goto(url: string | URL, opts?: GotoOptions): Promise<void>;
|
|
2814
2699
|
/**
|
|
2815
|
-
*
|
|
2816
|
-
* Usage:
|
|
2700
|
+
* 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.
|
|
2817
2701
|
*
|
|
2818
|
-
*
|
|
2819
|
-
*
|
|
2702
|
+
* 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).
|
|
2703
|
+
* To create a custom identifier, use a string beginning with `[a-z]+:` (e.g. `custom:state`) — this is a valid URL.
|
|
2820
2704
|
*
|
|
2821
|
-
*
|
|
2822
|
-
*
|
|
2823
|
-
* method: 'POST',
|
|
2824
|
-
* body: new FormData(event.target)
|
|
2825
|
-
* });
|
|
2705
|
+
* The `function` argument can be used define a custom predicate. It receives the full `URL` and causes `load` to rerun if `true` is returned.
|
|
2706
|
+
* This can be useful if you want to invalidate based on a pattern instead of a exact match.
|
|
2826
2707
|
*
|
|
2827
|
-
*
|
|
2828
|
-
*
|
|
2829
|
-
* }
|
|
2708
|
+
* ```ts
|
|
2709
|
+
* // Example: Match '/path' regardless of the query parameters
|
|
2710
|
+
* import { invalidate } from '$app/navigation';
|
|
2711
|
+
*
|
|
2712
|
+
* invalidate((url) => url.pathname === '/path');
|
|
2830
2713
|
* ```
|
|
2714
|
+
* @param resource The invalidated URL
|
|
2715
|
+
* @param keepState If `true`, the current `page.state` will be preserved. Otherwise, it will be reset to an empty object. `false` by default.
|
|
2831
2716
|
* */
|
|
2832
|
-
export function
|
|
2717
|
+
export function invalidate(resource: string | URL | ((url: URL) => boolean), keepState?: boolean): Promise<void>;
|
|
2833
2718
|
/**
|
|
2834
|
-
*
|
|
2719
|
+
* 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.
|
|
2835
2720
|
*
|
|
2836
|
-
*
|
|
2837
|
-
* If `cancel` is called, the form will not be submitted.
|
|
2838
|
-
* You can use the abort `controller` to cancel the submission in case another one starts.
|
|
2839
|
-
* If a function is returned, that function is called with the response from the server.
|
|
2840
|
-
* If nothing is returned, the fallback will be used.
|
|
2721
|
+
* 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.
|
|
2841
2722
|
*
|
|
2842
|
-
*
|
|
2843
|
-
*
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
*
|
|
2847
|
-
*
|
|
2723
|
+
* @deprecated Use [`refreshAll`](https://svelte.dev/docs/kit/$app-navigation#refreshAll) instead. Unlike `invalidateAll`, `refreshAll` does not reset `page.state`.
|
|
2724
|
+
* */
|
|
2725
|
+
export function invalidateAll(): Promise<void>;
|
|
2726
|
+
/**
|
|
2727
|
+
* Causes all currently active remote functions to refresh, and all `load` functions belonging to the currently active page to re-run.
|
|
2728
|
+
* Returns a `Promise` that resolves when the page is subsequently updated.
|
|
2729
|
+
* */
|
|
2730
|
+
export function refreshAll(): Promise<void>;
|
|
2731
|
+
/**
|
|
2732
|
+
* Programmatically preloads the given page, which means
|
|
2733
|
+
* 1. ensuring that the code for the page is loaded, and
|
|
2734
|
+
* 2. calling the page's load function with the appropriate options.
|
|
2848
2735
|
*
|
|
2849
|
-
*
|
|
2850
|
-
*
|
|
2851
|
-
*
|
|
2852
|
-
*
|
|
2853
|
-
*
|
|
2854
|
-
*
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2736
|
+
* This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.
|
|
2737
|
+
* If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
|
|
2738
|
+
* Returns a Promise that resolves with the result of running the new route's `load` functions once the preload is complete.
|
|
2739
|
+
*
|
|
2740
|
+
* @param href Page to preload
|
|
2741
|
+
* */
|
|
2742
|
+
export function preloadData(href: string): Promise<({
|
|
2743
|
+
type: "loaded";
|
|
2744
|
+
data: Record<string, any>;
|
|
2745
|
+
} | {
|
|
2746
|
+
type: "redirect";
|
|
2747
|
+
location: string;
|
|
2748
|
+
} | {
|
|
2749
|
+
type: "error";
|
|
2750
|
+
error: App.Error;
|
|
2751
|
+
}) & {
|
|
2752
|
+
status: number;
|
|
2753
|
+
}>;
|
|
2860
2754
|
/**
|
|
2861
|
-
*
|
|
2862
|
-
*
|
|
2863
|
-
*
|
|
2864
|
-
*
|
|
2865
|
-
*
|
|
2866
|
-
*
|
|
2867
|
-
*
|
|
2755
|
+
* Programmatically imports the code for routes that haven't yet been fetched.
|
|
2756
|
+
* Typically, you might call this to speed up subsequent navigation.
|
|
2757
|
+
*
|
|
2758
|
+
* Takes a route ID such as `/about` or `/blog/[slug]`. Unlike pathnames, route IDs
|
|
2759
|
+
* are never prefixed with the app's [base path](https://svelte.dev/docs/kit/configuration#paths).
|
|
2760
|
+
* If you have a pathname rather than a route ID, you can convert it with
|
|
2761
|
+
* [`match`](https://svelte.dev/docs/kit/$app-paths#match) from `$app/paths`:
|
|
2762
|
+
*
|
|
2763
|
+
* ```js
|
|
2764
|
+
* import { match } from '$app/paths';
|
|
2765
|
+
* import { preloadCode } from '$app/navigation';
|
|
2766
|
+
*
|
|
2767
|
+
* const matched = await match('/blog/hello-world');
|
|
2768
|
+
* if (matched) await preloadCode(matched.id);
|
|
2868
2769
|
* ```
|
|
2869
2770
|
*
|
|
2870
|
-
*
|
|
2871
|
-
*
|
|
2872
|
-
*
|
|
2873
|
-
*
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
| { type: 'redirect'; status: number; location: string }
|
|
2882
|
-
| { type: 'error'; status?: number; error: App.Error; location?: string };
|
|
2883
|
-
|
|
2884
|
-
export type SubmitFunction<
|
|
2885
|
-
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
2886
|
-
Failure extends Record<string, unknown> | undefined = Record<string, any>
|
|
2887
|
-
> = (input: {
|
|
2888
|
-
action: URL;
|
|
2889
|
-
formData: FormData;
|
|
2890
|
-
formElement: HTMLFormElement;
|
|
2891
|
-
controller: AbortController;
|
|
2892
|
-
submitter: HTMLElement | null;
|
|
2893
|
-
cancel: () => void;
|
|
2894
|
-
}) => MaybePromise<
|
|
2895
|
-
| void
|
|
2896
|
-
| ((opts: {
|
|
2897
|
-
formData: FormData;
|
|
2898
|
-
formElement: HTMLFormElement;
|
|
2899
|
-
action: URL;
|
|
2900
|
-
result: ActionResult<Success, Failure>;
|
|
2901
|
-
/**
|
|
2902
|
-
* Call this to get the default behavior of a form submission response.
|
|
2903
|
-
* @param options Set `reset: false` if you don't want the `<form>` values to be reset after a successful submission. `refreshAll` defaults to `true` for successful results and `false` for failures. When the submission navigates, setting it to `false` still runs the destination's `load` functions but may reuse shared layout data. Set `navigate: false` to apply non-redirect results to the current page instead of navigating to `result.location`. Redirects are always followed.
|
|
2904
|
-
*/
|
|
2905
|
-
update: (options?: {
|
|
2906
|
-
reset?: boolean;
|
|
2907
|
-
refreshAll?: boolean;
|
|
2908
|
-
navigate?: boolean;
|
|
2909
|
-
/** @deprecated Use `refreshAll` instead. */
|
|
2910
|
-
invalidateAll?: boolean;
|
|
2911
|
-
}) => Promise<void>;
|
|
2912
|
-
}) => MaybePromise<void>)
|
|
2913
|
-
>;
|
|
2771
|
+
* Unlike `preloadData`, this won't call `load` functions.
|
|
2772
|
+
* Returns a Promise that resolves when the modules have been imported.
|
|
2773
|
+
*
|
|
2774
|
+
* */
|
|
2775
|
+
export function preloadCode(id: import("$app/types").RouteId): Promise<void>;
|
|
2776
|
+
/**
|
|
2777
|
+
* Programmatically create a new history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
|
|
2778
|
+
*
|
|
2779
|
+
* @deprecated Use `goto(url, { state, shallow: true })` instead.
|
|
2780
|
+
* */
|
|
2781
|
+
export function pushState(url: string | URL, state: App.PageState): Promise<void>;
|
|
2914
2782
|
/**
|
|
2915
|
-
*
|
|
2916
|
-
*
|
|
2917
|
-
*
|
|
2783
|
+
* Programmatically replace the current history entry with the given `page.state`. Used for [shallow routing](https://svelte.dev/docs/kit/shallow-routing).
|
|
2784
|
+
*
|
|
2785
|
+
* @deprecated Use `goto(url, { state, shallow: true, replace: true })` instead.
|
|
2918
2786
|
* */
|
|
2919
|
-
export function
|
|
2787
|
+
export function replaceState(url: string | URL, state: App.PageState): Promise<void>;
|
|
2920
2788
|
type MaybePromise<T> = T | Promise<T>;
|
|
2921
2789
|
|
|
2922
2790
|
export {};
|
|
2923
2791
|
}
|
|
2924
2792
|
|
|
2925
|
-
declare module '$app/
|
|
2926
|
-
import type {
|
|
2793
|
+
declare module '$app/paths' {
|
|
2794
|
+
import type { AssetPath, RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname, RouteId, RouteParams } from '$app/types';
|
|
2927
2795
|
/**
|
|
2928
|
-
*
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2796
|
+
* 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.
|
|
2797
|
+
*
|
|
2798
|
+
* During server rendering, the base path is relative and depends on the page currently being rendered.
|
|
2799
|
+
*
|
|
2800
|
+
* @example
|
|
2801
|
+
* ```svelte
|
|
2802
|
+
* <script>
|
|
2803
|
+
* import { asset } from '$app/paths';
|
|
2804
|
+
* </script>
|
|
2805
|
+
*
|
|
2806
|
+
* <img alt="a potato" src={asset('potato.jpg')} />
|
|
2807
|
+
* ```
|
|
2808
|
+
* @since 2.26
|
|
2809
|
+
*
|
|
2810
|
+
* */
|
|
2811
|
+
export function asset(file: AssetPath): string;
|
|
2812
|
+
/**
|
|
2813
|
+
* Resolve a pathname by prefixing it with the base path, if any, or resolve a route ID by populating dynamic segments with parameters.
|
|
2814
|
+
*
|
|
2815
|
+
* During server rendering, the base path is relative and depends on the page currently being rendered.
|
|
2816
|
+
*
|
|
2817
|
+
* @example
|
|
2818
|
+
* ```js
|
|
2819
|
+
* import { resolve } from '$app/paths';
|
|
2820
|
+
*
|
|
2821
|
+
* // using a pathname
|
|
2822
|
+
* const resolved = resolve(`blog/hello-world`);
|
|
2823
|
+
*
|
|
2824
|
+
* // using a route ID plus parameters
|
|
2825
|
+
* const resolved = resolve('/blog/[slug]', {
|
|
2826
|
+
* slug: 'hello-world'
|
|
2827
|
+
* });
|
|
2828
|
+
* ```
|
|
2829
|
+
* @since 2.26
|
|
2830
|
+
*
|
|
2831
|
+
* */
|
|
2832
|
+
export function resolve<T extends RouteIdWithSearchOrHash | PathnameWithSearchOrHash>(...args: ResolveArgs<T>): ResolvedPathname;
|
|
2833
|
+
/**
|
|
2834
|
+
* Match a path or URL to a route ID and extracts any parameters.
|
|
2835
|
+
*
|
|
2836
|
+
* @example
|
|
2837
|
+
* ```js
|
|
2838
|
+
* import { match } from '$app/paths';
|
|
2839
|
+
*
|
|
2840
|
+
* const route = await match('blog/hello-world');
|
|
2841
|
+
*
|
|
2842
|
+
* if (route?.id === '/blog/[slug]') {
|
|
2843
|
+
* const slug = route.params.slug;
|
|
2844
|
+
* const response = await fetch(`/api/posts/${slug}`);
|
|
2845
|
+
* const post = await response.json();
|
|
2846
|
+
* }
|
|
2847
|
+
* ```
|
|
2848
|
+
* @since 2.52.0
|
|
2849
|
+
*
|
|
2850
|
+
* */
|
|
2851
|
+
export function match(url: URL | string): Promise<{ [K in RouteId]: {
|
|
2852
|
+
id: K;
|
|
2853
|
+
params: RouteParams<K>;
|
|
2854
|
+
}; }[RouteId] | null>;
|
|
2855
|
+
type StripSearchOrHash<T extends string> = T extends `${infer U}?${string}`
|
|
2856
|
+
? U
|
|
2857
|
+
: T extends `${infer U}#${string}`
|
|
2858
|
+
? U
|
|
2859
|
+
: T;
|
|
2966
2860
|
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
2861
|
+
type ResolveArgs<T> = T extends `/${string}`
|
|
2862
|
+
? StripSearchOrHash<T> extends infer U extends RouteId
|
|
2863
|
+
? RouteParams<U> extends Record<string, never>
|
|
2864
|
+
? [route: T]
|
|
2865
|
+
: [route: T, params: RouteParams<U>]
|
|
2866
|
+
: [never]
|
|
2867
|
+
: [pathname: T];
|
|
2868
|
+
|
|
2869
|
+
export {};
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2872
|
+
declare module '$app/server' {
|
|
2873
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2874
|
+
import type { RequestEvent } from '@sveltejs/kit';
|
|
2875
|
+
// If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
|
|
2876
|
+
type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
|
|
2877
|
+
|
|
2878
|
+
// Input type mappings for form fields
|
|
2879
|
+
type InputTypeMap = {
|
|
2880
|
+
text: string;
|
|
2881
|
+
email: string;
|
|
2882
|
+
password: string;
|
|
2883
|
+
url: string;
|
|
2884
|
+
tel: string;
|
|
2885
|
+
search: string;
|
|
2886
|
+
number: number;
|
|
2887
|
+
range: number;
|
|
2888
|
+
date: string;
|
|
2889
|
+
'datetime-local': string;
|
|
2890
|
+
time: string;
|
|
2891
|
+
month: string;
|
|
2892
|
+
week: string;
|
|
2893
|
+
color: string;
|
|
2894
|
+
checkbox: boolean | string[];
|
|
2895
|
+
radio: string;
|
|
2896
|
+
file: File;
|
|
2897
|
+
hidden: string | number | boolean;
|
|
2898
|
+
submit: string | number | boolean;
|
|
2899
|
+
button: string;
|
|
2900
|
+
reset: string;
|
|
2901
|
+
image: string;
|
|
2902
|
+
select: string;
|
|
2903
|
+
'select multiple': string[];
|
|
2904
|
+
'file multiple': File[];
|
|
2905
|
+
};
|
|
2906
|
+
|
|
2907
|
+
// Valid input types for a given value type
|
|
2908
|
+
export type RemoteFormFieldType<T> = {
|
|
2909
|
+
[K in keyof InputTypeMap]: T extends InputTypeMap[K] ? K : never;
|
|
2910
|
+
}[keyof InputTypeMap];
|
|
2911
|
+
|
|
2912
|
+
// Input element properties based on type
|
|
2913
|
+
type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'radio'
|
|
2914
|
+
? {
|
|
2915
|
+
name: string;
|
|
2916
|
+
type: T;
|
|
2917
|
+
value?: string;
|
|
2918
|
+
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
2919
|
+
get checked(): boolean;
|
|
2920
|
+
set checked(value: boolean);
|
|
2921
|
+
readonly defaultChecked?: boolean;
|
|
2922
|
+
}
|
|
2923
|
+
: T extends 'file'
|
|
2924
|
+
? {
|
|
2925
|
+
name: string;
|
|
2926
|
+
type: 'file';
|
|
2927
|
+
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
2928
|
+
get files(): FileList | null;
|
|
2929
|
+
set files(v: FileList | null);
|
|
2930
|
+
}
|
|
2931
|
+
: T extends 'select'
|
|
2932
|
+
? {
|
|
2933
|
+
name: string;
|
|
2934
|
+
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
2935
|
+
get value(): string;
|
|
2936
|
+
set value(v: string);
|
|
2937
|
+
}
|
|
2938
|
+
: T extends 'select multiple'
|
|
2939
|
+
? {
|
|
2940
|
+
name: string;
|
|
2941
|
+
multiple: true;
|
|
2942
|
+
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
2943
|
+
get value(): string[];
|
|
2944
|
+
set value(v: string[]);
|
|
2945
|
+
}
|
|
2946
|
+
: T extends 'text'
|
|
2947
|
+
? {
|
|
2948
|
+
name: string;
|
|
2949
|
+
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
2950
|
+
get value(): string | number;
|
|
2951
|
+
set value(v: string | number);
|
|
2952
|
+
readonly defaultValue?: string | number;
|
|
2953
|
+
}
|
|
2954
|
+
: {
|
|
2955
|
+
name: string;
|
|
2956
|
+
type: T;
|
|
2957
|
+
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
2958
|
+
get value(): string | number;
|
|
2959
|
+
set value(v: string | number);
|
|
2960
|
+
readonly defaultValue?: string | number;
|
|
2961
|
+
};
|
|
2962
|
+
|
|
2963
|
+
type RemoteFormFieldMethods<T> = {
|
|
2964
|
+
/** The values that will be submitted */
|
|
2965
|
+
value(): DeepPartial<T>;
|
|
2966
|
+
/** Set the values that will be submitted */
|
|
2967
|
+
set(input: DeepPartial<T>): DeepPartial<T>;
|
|
2968
|
+
/** Whether the field or any nested field has been interacted with since the form was mounted */
|
|
2969
|
+
touched(): boolean;
|
|
2970
|
+
/** Whether the field or any nested field has been edited since the form was mounted */
|
|
2971
|
+
dirty(): boolean;
|
|
2972
|
+
/** Validation issues, if any */
|
|
2973
|
+
issues(): RemoteFormIssue[] | undefined;
|
|
2974
|
+
};
|
|
2975
|
+
|
|
2976
|
+
// These two types use "T extends unknown ? .. : .." to distribute over unions.
|
|
2977
|
+
// 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
|
|
2978
|
+
type KeysOfUnion<T> = T extends unknown ? keyof T : never;
|
|
2979
|
+
type ValueOfUnionKey<T, K extends PropertyKey> = T extends unknown
|
|
2980
|
+
? K extends keyof T
|
|
2981
|
+
? T[K]
|
|
2982
|
+
: never
|
|
2983
|
+
: never;
|
|
2984
|
+
|
|
2985
|
+
export type RemoteFormFieldValue = string | string[] | number | boolean | File | File[];
|
|
2986
|
+
|
|
2987
|
+
type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
|
|
2988
|
+
? Value extends string[]
|
|
2989
|
+
? [type: Type, value: Value[number] | (string & {})]
|
|
2990
|
+
: Value extends boolean
|
|
2991
|
+
? [type: Type] | [type: Type, value: boolean]
|
|
2992
|
+
: [type: Type] | [type: Type, value: Value | (string & {})]
|
|
2993
|
+
: Type extends 'submit' | 'hidden'
|
|
2994
|
+
? Value extends string
|
|
2995
|
+
? [type: Type, value: Value | (string & {})]
|
|
2996
|
+
: [type: Type, value: Value]
|
|
2997
|
+
: Type extends 'radio'
|
|
2998
|
+
? [type: Type, value: Value | (string & {})]
|
|
2999
|
+
: Type extends 'file' | 'file multiple'
|
|
3000
|
+
? [type: Type]
|
|
3001
|
+
: [type: Type] | [type: Type, value: Value | undefined];
|
|
3006
3002
|
|
|
3007
3003
|
/**
|
|
3008
|
-
*
|
|
3009
|
-
* - `form`: The user submitted a `<form method="GET">`
|
|
3010
|
-
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
3011
|
-
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
3012
|
-
* - `link`: Navigation was triggered by a link click
|
|
3013
|
-
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
3004
|
+
* Form field accessor type that provides name(), value(), and issues() methods
|
|
3014
3005
|
*/
|
|
3015
|
-
export type
|
|
3016
|
-
|
|
3017
|
-
export interface NavigationBase {
|
|
3018
|
-
/**
|
|
3019
|
-
* The type of navigation:
|
|
3020
|
-
* - `enter`: The app has hydrated/started
|
|
3021
|
-
* - `form`: The user submitted a `<form method="GET">`
|
|
3022
|
-
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
3023
|
-
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
3024
|
-
* - `link`: Navigation was triggered by a link click
|
|
3025
|
-
* - `popstate`: Navigation was triggered by back/forward navigation
|
|
3026
|
-
*/
|
|
3027
|
-
type: NavigationType;
|
|
3028
|
-
/** Whether this is a shallow navigation. */
|
|
3029
|
-
shallow: boolean;
|
|
3030
|
-
/**
|
|
3031
|
-
* Where navigation was triggered from
|
|
3032
|
-
*/
|
|
3033
|
-
from: NavigationTarget | null;
|
|
3034
|
-
/**
|
|
3035
|
-
* Where navigation is going to/has gone to
|
|
3036
|
-
*/
|
|
3037
|
-
to: NavigationTarget | null;
|
|
3006
|
+
export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
|
|
3038
3007
|
/**
|
|
3039
|
-
*
|
|
3008
|
+
* Returns an object that can be spread onto an input element with the correct type attribute,
|
|
3009
|
+
* aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
|
|
3010
|
+
* @example
|
|
3011
|
+
* ```svelte
|
|
3012
|
+
* <input {...myForm.fields.myString.as('text')} />
|
|
3013
|
+
* <input {...myForm.fields.myNumber.as('number')} />
|
|
3014
|
+
* <input {...myForm.fields.myBoolean.as('checkbox')} />
|
|
3015
|
+
* ```
|
|
3040
3016
|
*/
|
|
3041
|
-
|
|
3017
|
+
as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
|
|
3018
|
+
};
|
|
3019
|
+
|
|
3020
|
+
type RemoteFormFieldContainer<Value> = RemoteFormFieldMethods<Value> & {
|
|
3021
|
+
/** Validation issues belonging to this or any of the fields that belong to it, if any */
|
|
3022
|
+
allIssues(): RemoteFormIssue[] | undefined;
|
|
3023
|
+
};
|
|
3024
|
+
|
|
3025
|
+
type UnknownField<Value> = RemoteFormFieldMethods<Value> & {
|
|
3026
|
+
/** Validation issues belonging to this or any of the fields that belong to it, if any */
|
|
3027
|
+
allIssues(): RemoteFormIssue[] | undefined;
|
|
3042
3028
|
/**
|
|
3043
|
-
*
|
|
3044
|
-
*
|
|
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
|
+
* ```
|
|
3045
3037
|
*/
|
|
3046
|
-
|
|
3047
|
-
}
|
|
3038
|
+
as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
|
|
3039
|
+
} & {
|
|
3040
|
+
[key: string | number]: UnknownField<any>;
|
|
3041
|
+
};
|
|
3042
|
+
|
|
3043
|
+
type RemoteFormFieldsRoot<Input extends RemoteFormInput | void> =
|
|
3044
|
+
IsAny<Input> extends true
|
|
3045
|
+
? RecursiveFormFields
|
|
3046
|
+
: Input extends void
|
|
3047
|
+
? {
|
|
3048
|
+
/** Validation issues, if any */
|
|
3049
|
+
issues(): RemoteFormIssue[] | undefined;
|
|
3050
|
+
/** Validation issues belonging to this or any of the fields that belong to it, if any */
|
|
3051
|
+
allIssues(): RemoteFormIssue[] | undefined;
|
|
3052
|
+
}
|
|
3053
|
+
: RemoteFormFields<Input>;
|
|
3048
3054
|
|
|
3049
3055
|
/**
|
|
3050
|
-
*
|
|
3056
|
+
* Recursive type to build form fields structure with proxy access
|
|
3051
3057
|
*/
|
|
3052
|
-
export
|
|
3053
|
-
|
|
3058
|
+
export type RemoteFormFields<T> =
|
|
3059
|
+
WillRecurseIndefinitely<T> extends true
|
|
3060
|
+
? RecursiveFormFields
|
|
3061
|
+
: NonNullable<T> extends string | number | boolean | File
|
|
3062
|
+
? RemoteFormField<NonNullable<T>>
|
|
3063
|
+
: // [NonNullable<T>] is used to prevent distributing over union while still allowing
|
|
3064
|
+
// nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
|
|
3065
|
+
// to be treated as arrays; only the last condition should distribute over unions
|
|
3066
|
+
[NonNullable<T>] extends [string[] | File[]]
|
|
3067
|
+
? RemoteFormField<NonNullable<T>> & {
|
|
3068
|
+
[K in number]: RemoteFormField<NonNullable<T>[number]>;
|
|
3069
|
+
}
|
|
3070
|
+
: [NonNullable<T>] extends [Array<infer U>]
|
|
3071
|
+
? RemoteFormFieldContainer<NonNullable<T>> & {
|
|
3072
|
+
[K in number]: RemoteFormFields<U>;
|
|
3073
|
+
}
|
|
3074
|
+
: RemoteFormFieldContainer<T> & {
|
|
3075
|
+
[K in KeysOfUnion<T>]-?: RemoteFormFields<ValueOfUnionKey<T, K>>;
|
|
3076
|
+
};
|
|
3054
3077
|
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3078
|
+
// By breaking this out into its own type, we avoid the TS recursion depth limit
|
|
3079
|
+
type RecursiveFormFields = RemoteFormFieldContainer<any> & {
|
|
3080
|
+
[key: string | number]: UnknownField<any>;
|
|
3081
|
+
};
|
|
3059
3082
|
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3083
|
+
type MaybeArray<T> = T | T[];
|
|
3084
|
+
|
|
3085
|
+
export interface RemoteFormInput {
|
|
3086
|
+
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
|
|
3064
3087
|
}
|
|
3065
3088
|
|
|
3066
|
-
export
|
|
3089
|
+
export interface RemoteFormIssue {
|
|
3090
|
+
message: string;
|
|
3091
|
+
path: Array<string | number>;
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
// If the schema specifies `id` as a string or number, ensure that `for(...)`
|
|
3095
|
+
// only accepts that type. Otherwise, accept `string | number`
|
|
3096
|
+
type ExtractId<Input> = Input extends { id: infer Id }
|
|
3097
|
+
? Id extends string | number
|
|
3098
|
+
? Id
|
|
3099
|
+
: string | number
|
|
3100
|
+
: string | number;
|
|
3067
3101
|
|
|
3068
3102
|
/**
|
|
3069
|
-
* A
|
|
3103
|
+
* A function and proxy object used to imperatively create validation errors in form handlers.
|
|
3104
|
+
*
|
|
3105
|
+
* Access properties to create field-specific issues: `issue.fieldName('message')`.
|
|
3106
|
+
* The type structure mirrors the input data structure for type-safe field access.
|
|
3107
|
+
* Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
|
|
3070
3108
|
*/
|
|
3071
|
-
export
|
|
3072
|
-
|
|
3073
|
-
|
|
3109
|
+
export type InvalidField<T> =
|
|
3110
|
+
WillRecurseIndefinitely<T> extends true
|
|
3111
|
+
? Record<string | number, any>
|
|
3112
|
+
: NonNullable<T> extends string | number | boolean | File
|
|
3113
|
+
? (message: string) => StandardSchemaV1.Issue
|
|
3114
|
+
: NonNullable<T> extends Array<infer U>
|
|
3115
|
+
? {
|
|
3116
|
+
[K in number]: InvalidField<U>;
|
|
3117
|
+
} & ((message: string) => StandardSchemaV1.Issue)
|
|
3118
|
+
: NonNullable<T> extends RemoteFormInput
|
|
3119
|
+
? {
|
|
3120
|
+
[K in keyof T]-?: InvalidField<T[K]>;
|
|
3121
|
+
} & ((message: string) => StandardSchemaV1.Issue)
|
|
3122
|
+
: Record<string, never>;
|
|
3074
3123
|
|
|
3075
3124
|
/**
|
|
3076
|
-
* A
|
|
3125
|
+
* A validation error thrown by `invalid`.
|
|
3077
3126
|
*/
|
|
3078
|
-
export interface
|
|
3079
|
-
|
|
3127
|
+
export interface ValidationError {
|
|
3128
|
+
/** The validation issues */
|
|
3129
|
+
issues: StandardSchemaV1.Issue[];
|
|
3080
3130
|
}
|
|
3081
3131
|
|
|
3082
3132
|
/**
|
|
3083
|
-
*
|
|
3133
|
+
* The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
3084
3134
|
*/
|
|
3085
|
-
export
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
event: SubmitEvent;
|
|
3092
|
-
}
|
|
3135
|
+
export type RemoteFormEnhanceInstance<
|
|
3136
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
3137
|
+
Output = any
|
|
3138
|
+
> = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
|
|
3139
|
+
readonly element: HTMLFormElement;
|
|
3140
|
+
};
|
|
3093
3141
|
|
|
3094
3142
|
/**
|
|
3095
|
-
*
|
|
3143
|
+
* The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
3096
3144
|
*/
|
|
3097
|
-
export
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
3102
|
-
*/
|
|
3103
|
-
delta: number;
|
|
3145
|
+
export type RemoteFormEnhanceCallback<
|
|
3146
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
3147
|
+
Output = any
|
|
3148
|
+
> = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
|
|
3104
3149
|
|
|
3150
|
+
/**
|
|
3151
|
+
* The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
3152
|
+
*/
|
|
3153
|
+
export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
3154
|
+
/** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
|
|
3155
|
+
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
3156
|
+
method: 'POST';
|
|
3157
|
+
/** The URL to send the form to. */
|
|
3158
|
+
action: string;
|
|
3159
|
+
/** The `<form>` element this instance is currently attached to, if any. */
|
|
3160
|
+
get element(): HTMLFormElement | null;
|
|
3161
|
+
/** Submit the currently attached form programmatically. */
|
|
3162
|
+
submit(): Promise<boolean> & {
|
|
3163
|
+
updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
|
|
3164
|
+
};
|
|
3165
|
+
/** Use the `enhance` method to influence what happens when the form is submitted. */
|
|
3166
|
+
enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
|
|
3167
|
+
method: 'POST';
|
|
3168
|
+
action: string;
|
|
3169
|
+
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
3170
|
+
};
|
|
3105
3171
|
/**
|
|
3106
|
-
*
|
|
3172
|
+
* Create an instance of the form for the given `id`.
|
|
3173
|
+
* The `id` is stringified and used for deduplication to potentially reuse existing instances.
|
|
3174
|
+
* Useful when you have multiple forms that use the same remote form action, for example in a loop.
|
|
3175
|
+
* ```svelte
|
|
3176
|
+
* {#each todos as todo}
|
|
3177
|
+
* {@const todoForm = updateTodo.for(todo.id)}
|
|
3178
|
+
* <form {...todoForm}>
|
|
3179
|
+
* {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
|
|
3180
|
+
* ...
|
|
3181
|
+
* </form>
|
|
3182
|
+
* {/each}
|
|
3183
|
+
* ```
|
|
3107
3184
|
*/
|
|
3108
|
-
|
|
3109
|
-
|
|
3185
|
+
for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
|
|
3186
|
+
/** Preflight checks */
|
|
3187
|
+
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
|
|
3188
|
+
/** Validate the form contents programmatically */
|
|
3189
|
+
validate(options?: {
|
|
3190
|
+
/**
|
|
3191
|
+
* Set this to `true` to also show validation issues of fields that haven't yet been
|
|
3192
|
+
* edited and blurred. This option is ignored for forms that have previously been
|
|
3193
|
+
* submitted, in which case all fields are always subject to validation
|
|
3194
|
+
* (unless the form is reset, at which point it is treated as pristine)
|
|
3195
|
+
*/
|
|
3196
|
+
all?: boolean;
|
|
3197
|
+
/** Set this to `true` to only run the `preflight` validation. */
|
|
3198
|
+
preflightOnly?: boolean;
|
|
3199
|
+
}): Promise<void>;
|
|
3200
|
+
/** The result of the form submission */
|
|
3201
|
+
get result(): Output | undefined;
|
|
3202
|
+
/** The number of pending submissions */
|
|
3203
|
+
get pending(): number;
|
|
3204
|
+
/** True if the form has been submitted at least once, and hasn't been reset since */
|
|
3205
|
+
get submitted(): boolean;
|
|
3206
|
+
/** Access form fields using object notation */
|
|
3207
|
+
fields: RemoteFormFieldsRoot<Input>;
|
|
3208
|
+
};
|
|
3110
3209
|
|
|
3111
3210
|
/**
|
|
3112
|
-
*
|
|
3211
|
+
* The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
|
|
3113
3212
|
*/
|
|
3114
|
-
export
|
|
3115
|
-
|
|
3213
|
+
export type RemoteCommand<Input, Output> = {
|
|
3214
|
+
(arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
|
|
3215
|
+
updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
|
|
3216
|
+
};
|
|
3217
|
+
/** The number of pending command executions */
|
|
3218
|
+
get pending(): number;
|
|
3219
|
+
};
|
|
3116
3220
|
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3221
|
+
export type RemoteQueryUpdate =
|
|
3222
|
+
| RemoteQuery<any>
|
|
3223
|
+
| RemoteLiveQuery<any>
|
|
3224
|
+
| RemoteQueryFunction<any, any>
|
|
3225
|
+
| RemoteLiveQueryFunction<any, any>
|
|
3226
|
+
| RemoteQueryOverride;
|
|
3122
3227
|
|
|
3123
|
-
export type
|
|
3124
|
-
|
|
3125
|
-
|
|
|
3126
|
-
|
|
3127
|
-
|
|
3228
|
+
export type RemoteResource<T> = Promise<T> & {
|
|
3229
|
+
/** The error in case the query fails. */
|
|
3230
|
+
get error(): App.Error | undefined;
|
|
3231
|
+
/** `true` before the first result is available and during refreshes */
|
|
3232
|
+
get loading(): boolean;
|
|
3233
|
+
} & (
|
|
3234
|
+
| {
|
|
3235
|
+
/** The current value of the query. Undefined until `ready` is `true` */
|
|
3236
|
+
get current(): undefined;
|
|
3237
|
+
ready: false;
|
|
3238
|
+
}
|
|
3239
|
+
| {
|
|
3240
|
+
/** The current value of the query. Undefined until `ready` is `true` */
|
|
3241
|
+
get current(): T;
|
|
3242
|
+
ready: true;
|
|
3243
|
+
}
|
|
3244
|
+
);
|
|
3128
3245
|
|
|
3129
|
-
|
|
3130
|
-
* The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
|
|
3131
|
-
*/
|
|
3132
|
-
export type BeforeNavigate = Navigation & {
|
|
3246
|
+
export type RemoteQuery<T> = RemoteResource<T> & {
|
|
3133
3247
|
/**
|
|
3134
|
-
*
|
|
3248
|
+
* On the client, this function will update the value of the query without re-fetching it.
|
|
3249
|
+
*
|
|
3250
|
+
* 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.
|
|
3251
|
+
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
|
|
3135
3252
|
*/
|
|
3136
|
-
|
|
3137
|
-
};
|
|
3138
|
-
|
|
3139
|
-
/**
|
|
3140
|
-
* The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
|
|
3141
|
-
*/
|
|
3142
|
-
export type OnNavigate = Navigation & {
|
|
3143
|
-
type: Exclude<NavigationType, 'enter' | 'leave'>;
|
|
3253
|
+
set(value: T): void;
|
|
3144
3254
|
/**
|
|
3145
|
-
*
|
|
3255
|
+
* On the client, this function will re-fetch the query from the server.
|
|
3256
|
+
*
|
|
3257
|
+
* 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.
|
|
3258
|
+
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
|
|
3146
3259
|
*/
|
|
3147
|
-
|
|
3148
|
-
};
|
|
3149
|
-
|
|
3150
|
-
/**
|
|
3151
|
-
* The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
|
|
3152
|
-
*/
|
|
3153
|
-
export type AfterNavigate = (Navigation | NavigationEnter) & {
|
|
3154
|
-
type: Exclude<NavigationType, 'leave'>;
|
|
3260
|
+
refresh(): Promise<void>;
|
|
3155
3261
|
/**
|
|
3156
|
-
*
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
*
|
|
3190
|
-
* `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
3191
|
-
* */
|
|
3192
|
-
export function beforeNavigate(callback: (navigation: BeforeNavigate) => void): void;
|
|
3193
|
-
/**
|
|
3194
|
-
* A lifecycle function that runs the supplied `callback` immediately before we navigate to a new URL except during full-page navigations.
|
|
3195
|
-
*
|
|
3196
|
-
* 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.
|
|
3197
|
-
*
|
|
3198
|
-
* 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.
|
|
3199
|
-
*
|
|
3200
|
-
* `onNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
3201
|
-
* */
|
|
3202
|
-
export function onNavigate(callback: (navigation: OnNavigate) => MaybePromise<(() => void) | void>): void;
|
|
3203
|
-
/**
|
|
3204
|
-
* 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.
|
|
3205
|
-
* This is generally discouraged, since it breaks user expectations.
|
|
3206
|
-
* */
|
|
3207
|
-
export function disableScrollHandling(): void;
|
|
3208
|
-
/**
|
|
3209
|
-
* Allows you to navigate programmatically to a given route, with control over details such as whether scroll and focus are reset
|
|
3210
|
-
* (as they would be with a regular navigation) or preserved.
|
|
3211
|
-
*
|
|
3212
|
-
* 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.
|
|
3213
|
-
*
|
|
3214
|
-
* `goto` is intended for navigations to routes that belong to the app, and will reject if a route cannot be resolved.
|
|
3215
|
-
* For external URLs, use `window.location = url` to perform a full-page navigation instead of calling `goto(url)`.
|
|
3216
|
-
*
|
|
3217
|
-
* @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.
|
|
3218
|
-
* @param opts Options related to the navigation
|
|
3219
|
-
* */
|
|
3220
|
-
export function goto(url: string | URL, opts?: GotoOptions): Promise<void>;
|
|
3221
|
-
/**
|
|
3222
|
-
* 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.
|
|
3223
|
-
*
|
|
3224
|
-
* 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).
|
|
3225
|
-
* To create a custom identifier, use a string beginning with `[a-z]+:` (e.g. `custom:state`) — this is a valid URL.
|
|
3226
|
-
*
|
|
3227
|
-
* The `function` argument can be used define a custom predicate. It receives the full `URL` and causes `load` to rerun if `true` is returned.
|
|
3228
|
-
* This can be useful if you want to invalidate based on a pattern instead of a exact match.
|
|
3229
|
-
*
|
|
3230
|
-
* ```ts
|
|
3231
|
-
* // Example: Match '/path' regardless of the query parameters
|
|
3232
|
-
* import { invalidate } from '$app/navigation';
|
|
3233
|
-
*
|
|
3234
|
-
* invalidate((url) => url.pathname === '/path');
|
|
3235
|
-
* ```
|
|
3236
|
-
* @param resource The invalidated URL
|
|
3237
|
-
* @param keepState If `true`, the current `page.state` will be preserved. Otherwise, it will be reset to an empty object. `false` by default.
|
|
3238
|
-
* */
|
|
3239
|
-
export function invalidate(resource: string | URL | ((url: URL) => boolean), keepState?: boolean): Promise<void>;
|
|
3240
|
-
/**
|
|
3241
|
-
* 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.
|
|
3242
|
-
*
|
|
3243
|
-
* 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.
|
|
3244
|
-
*
|
|
3245
|
-
* @deprecated Use [`refreshAll`](https://svelte.dev/docs/kit/$app-navigation#refreshAll) instead. Unlike `invalidateAll`, `refreshAll` does not reset `page.state`.
|
|
3246
|
-
* */
|
|
3247
|
-
export function invalidateAll(): Promise<void>;
|
|
3248
|
-
/**
|
|
3249
|
-
* Causes all currently active remote functions to refresh, and all `load` functions belonging to the currently active page to re-run.
|
|
3250
|
-
* Returns a `Promise` that resolves when the page is subsequently updated.
|
|
3251
|
-
* */
|
|
3252
|
-
export function refreshAll(): Promise<void>;
|
|
3253
|
-
/**
|
|
3254
|
-
* Programmatically preloads the given page, which means
|
|
3255
|
-
* 1. ensuring that the code for the page is loaded, and
|
|
3256
|
-
* 2. calling the page's load function with the appropriate options.
|
|
3257
|
-
*
|
|
3258
|
-
* This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.
|
|
3259
|
-
* If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
|
|
3260
|
-
* Returns a Promise that resolves with the result of running the new route's `load` functions once the preload is complete.
|
|
3261
|
-
*
|
|
3262
|
-
* @param href Page to preload
|
|
3263
|
-
* */
|
|
3264
|
-
export function preloadData(href: string): Promise<({
|
|
3265
|
-
type: "loaded";
|
|
3266
|
-
data: Record<string, any>;
|
|
3267
|
-
} | {
|
|
3268
|
-
type: "redirect";
|
|
3269
|
-
location: string;
|
|
3270
|
-
} | {
|
|
3271
|
-
type: "error";
|
|
3272
|
-
error: App.Error;
|
|
3273
|
-
}) & {
|
|
3274
|
-
status: number;
|
|
3275
|
-
}>;
|
|
3276
|
-
/**
|
|
3277
|
-
* Programmatically imports the code for routes that haven't yet been fetched.
|
|
3278
|
-
* Typically, you might call this to speed up subsequent navigation.
|
|
3279
|
-
*
|
|
3280
|
-
* Takes a route ID such as `/about` or `/blog/[slug]`. Unlike pathnames, route IDs
|
|
3281
|
-
* are never prefixed with the app's [base path](https://svelte.dev/docs/kit/configuration#paths).
|
|
3282
|
-
* If you have a pathname rather than a route ID, you can convert it with
|
|
3283
|
-
* [`match`](https://svelte.dev/docs/kit/$app-paths#match) from `$app/paths`:
|
|
3284
|
-
*
|
|
3285
|
-
* ```js
|
|
3286
|
-
* import { match } from '$app/paths';
|
|
3287
|
-
* import { preloadCode } from '$app/navigation';
|
|
3288
|
-
*
|
|
3289
|
-
* const matched = await match('/blog/hello-world');
|
|
3290
|
-
* if (matched) await preloadCode(matched.id);
|
|
3291
|
-
* ```
|
|
3292
|
-
*
|
|
3293
|
-
* Unlike `preloadData`, this won't call `load` functions.
|
|
3294
|
-
* Returns a Promise that resolves when the modules have been imported.
|
|
3295
|
-
*
|
|
3296
|
-
* */
|
|
3297
|
-
export function preloadCode(id: import("$app/types").RouteId): Promise<void>;
|
|
3262
|
+
* 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.
|
|
3263
|
+
*
|
|
3264
|
+
* ```svelte
|
|
3265
|
+
* <script>
|
|
3266
|
+
* import { getTodos, addTodo } from './todos.remote.js';
|
|
3267
|
+
* const todos = getTodos();
|
|
3268
|
+
* </script>
|
|
3269
|
+
*
|
|
3270
|
+
* <form {...addTodo.enhance(async (form) => {
|
|
3271
|
+
* await form.submit().updates(
|
|
3272
|
+
* todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
|
|
3273
|
+
* );
|
|
3274
|
+
* })}>
|
|
3275
|
+
* <input type="text" name="text" />
|
|
3276
|
+
* <button type="submit">Add Todo</button>
|
|
3277
|
+
* </form>
|
|
3278
|
+
* ```
|
|
3279
|
+
*/
|
|
3280
|
+
withOverride(update: (current: T) => T): RemoteQueryOverride;
|
|
3281
|
+
};
|
|
3282
|
+
|
|
3283
|
+
export type RemoteLiveQuery<T> = RemoteResource<T> &
|
|
3284
|
+
AsyncIterable<T> & {
|
|
3285
|
+
/** `true` if the live stream is currently connected. */
|
|
3286
|
+
readonly connected: boolean;
|
|
3287
|
+
/** `true` once the current live stream iterator is done. */
|
|
3288
|
+
readonly done: boolean;
|
|
3289
|
+
/** Reconnects the live stream immediately. */
|
|
3290
|
+
reconnect(): Promise<void>;
|
|
3291
|
+
};
|
|
3292
|
+
|
|
3293
|
+
export type RemoteQueryOverride = () => void;
|
|
3294
|
+
|
|
3298
3295
|
/**
|
|
3299
|
-
*
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3296
|
+
* The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
|
|
3297
|
+
*/
|
|
3298
|
+
export type RemotePrerenderFunction<Input, Output> = (
|
|
3299
|
+
arg: undefined extends Input ? Input | void : Input
|
|
3300
|
+
) => RemoteResource<Output>;
|
|
3301
|
+
|
|
3304
3302
|
/**
|
|
3305
|
-
*
|
|
3303
|
+
* The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
|
|
3306
3304
|
*
|
|
3307
|
-
*
|
|
3308
|
-
*
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3305
|
+
* The optional `Validated` generic parameter represents the argument type *after* the
|
|
3306
|
+
* query's schema has validated and (optionally) transformed it — this is the type the
|
|
3307
|
+
* query's implementation function receives on the server, and the type yielded by
|
|
3308
|
+
* [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
|
|
3309
|
+
* with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
|
|
3310
|
+
* schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
|
|
3311
|
+
* `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
|
|
3312
|
+
* without arguments it defaults to `Input`.
|
|
3313
|
+
*/
|
|
3314
|
+
export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
|
|
3315
|
+
arg: undefined extends Input ? Input | void : Input
|
|
3316
|
+
) => RemoteQuery<Output>;
|
|
3314
3317
|
|
|
3315
|
-
declare module '$app/paths' {
|
|
3316
|
-
import type { AssetPath, RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname, RouteId, RouteParams } from '$app/types';
|
|
3317
3318
|
/**
|
|
3318
|
-
*
|
|
3319
|
-
*
|
|
3320
|
-
* During server rendering, the base path is relative and depends on the page currently being rendered.
|
|
3321
|
-
*
|
|
3322
|
-
* @example
|
|
3323
|
-
* ```svelte
|
|
3324
|
-
* <script>
|
|
3325
|
-
* import { asset } from '$app/paths';
|
|
3326
|
-
* </script>
|
|
3327
|
-
*
|
|
3328
|
-
* <img alt="a potato" src={asset('potato.jpg')} />
|
|
3329
|
-
* ```
|
|
3330
|
-
* @since 2.26
|
|
3319
|
+
* The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
|
|
3331
3320
|
*
|
|
3332
|
-
*
|
|
3333
|
-
|
|
3321
|
+
* The optional `Validated` generic parameter represents the argument type *after* the
|
|
3322
|
+
* query's schema has validated and (optionally) transformed it, and matches the type
|
|
3323
|
+
* yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
|
|
3324
|
+
*/
|
|
3325
|
+
export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
|
|
3326
|
+
arg: undefined extends Input ? Input | void : Input
|
|
3327
|
+
) => RemoteLiveQuery<Output>;
|
|
3328
|
+
|
|
3334
3329
|
/**
|
|
3335
|
-
*
|
|
3336
|
-
*
|
|
3337
|
-
*
|
|
3338
|
-
*
|
|
3339
|
-
*
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
* // using a route ID plus parameters
|
|
3347
|
-
* const resolved = resolve('/blog/[slug]', {
|
|
3348
|
-
* slug: 'hello-world'
|
|
3349
|
-
* });
|
|
3350
|
-
* ```
|
|
3351
|
-
* @since 2.26
|
|
3352
|
-
*
|
|
3353
|
-
* */
|
|
3354
|
-
export function resolve<T extends RouteIdWithSearchOrHash | PathnameWithSearchOrHash>(...args: ResolveArgs<T>): ResolvedPathname;
|
|
3330
|
+
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
3331
|
+
* when called with a regular `query`. `arg` is the validated argument (the input *after*
|
|
3332
|
+
* the query's schema validated and transformed it, if applicable); `query` is a
|
|
3333
|
+
* `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
|
|
3334
|
+
* update the correct client entry.
|
|
3335
|
+
*/
|
|
3336
|
+
export type RequestedEntry<Validated, Output> = {
|
|
3337
|
+
arg: Validated;
|
|
3338
|
+
query: RemoteQuery<Output>;
|
|
3339
|
+
};
|
|
3340
|
+
|
|
3355
3341
|
/**
|
|
3356
|
-
*
|
|
3357
|
-
*
|
|
3358
|
-
*
|
|
3359
|
-
*
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
* const slug = route.params.slug;
|
|
3366
|
-
* const response = await fetch(`/api/posts/${slug}`);
|
|
3367
|
-
* const post = await response.json();
|
|
3368
|
-
* }
|
|
3369
|
-
* ```
|
|
3370
|
-
* @since 2.52.0
|
|
3371
|
-
*
|
|
3372
|
-
* */
|
|
3373
|
-
export function match(url: URL | string): Promise<{ [K in RouteId]: {
|
|
3374
|
-
id: K;
|
|
3375
|
-
params: RouteParams<K>;
|
|
3376
|
-
}; }[RouteId] | null>;
|
|
3377
|
-
type StripSearchOrHash<T extends string> = T extends `${infer U}?${string}`
|
|
3378
|
-
? U
|
|
3379
|
-
: T extends `${infer U}#${string}`
|
|
3380
|
-
? U
|
|
3381
|
-
: T;
|
|
3342
|
+
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
3343
|
+
* when called with a `query.live`. `arg` is the validated argument; `query` is a
|
|
3344
|
+
* `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
|
|
3345
|
+
* the correct client subscription.
|
|
3346
|
+
*/
|
|
3347
|
+
export type LiveRequestedEntry<Validated, Output> = {
|
|
3348
|
+
arg: Validated;
|
|
3349
|
+
query: RemoteLiveQuery<Output>;
|
|
3350
|
+
};
|
|
3382
3351
|
|
|
3383
|
-
type
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3352
|
+
export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
|
|
3353
|
+
AsyncIterable<RequestedEntry<Validated, Output>> & {
|
|
3354
|
+
/**
|
|
3355
|
+
* Call `refresh` on all queries selected by this `requested` invocation.
|
|
3356
|
+
* This is identical to:
|
|
3357
|
+
* ```ts
|
|
3358
|
+
* import { requested } from '$app/server';
|
|
3359
|
+
*
|
|
3360
|
+
* for await (const { query } of requested(getPost, ...)) {
|
|
3361
|
+
* void query.refresh();
|
|
3362
|
+
* }
|
|
3363
|
+
* ```
|
|
3364
|
+
*/
|
|
3365
|
+
refreshAll: () => Promise<void>;
|
|
3366
|
+
};
|
|
3390
3367
|
|
|
3391
|
-
export
|
|
3392
|
-
|
|
3368
|
+
export type LiveQueryRequestedResult<Validated, Output> = Iterable<
|
|
3369
|
+
LiveRequestedEntry<Validated, Output>
|
|
3370
|
+
> &
|
|
3371
|
+
AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
|
|
3372
|
+
/**
|
|
3373
|
+
* Call `reconnect` on all live queries selected by this `requested` invocation.
|
|
3374
|
+
* This is identical to:
|
|
3375
|
+
* ```ts
|
|
3376
|
+
* import { requested } from '$app/server';
|
|
3377
|
+
*
|
|
3378
|
+
* for await (const { query } of requested(liveQuery, ...)) {
|
|
3379
|
+
* void query.reconnect();
|
|
3380
|
+
* }
|
|
3381
|
+
* ```
|
|
3382
|
+
*/
|
|
3383
|
+
reconnectAll: () => Promise<void>;
|
|
3384
|
+
};
|
|
3393
3385
|
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3386
|
+
export type RequestedResult<Validated, Output> =
|
|
3387
|
+
| QueryRequestedResult<Validated, Output>
|
|
3388
|
+
| LiveQueryRequestedResult<Validated, Output>;
|
|
3389
|
+
type RemoteLiveQueryUserFunctionReturnType<Output> = MaybePromise<
|
|
3390
|
+
| AsyncGenerator<Output>
|
|
3391
|
+
| AsyncIterator<Output>
|
|
3392
|
+
| AsyncIterable<Output>
|
|
3393
|
+
| Generator<Output>
|
|
3394
|
+
| Iterator<Output>
|
|
3395
|
+
| Iterable<Output>
|
|
3396
|
+
>;
|
|
3397
|
+
type RemotePrerenderInputsGenerator<Input = any> = () => MaybePromise<Input[]>;
|
|
3397
3398
|
/**
|
|
3398
3399
|
* Read the contents of an imported asset from the filesystem
|
|
3399
3400
|
* @example
|
|
@@ -3407,6 +3408,28 @@ declare module '$app/server' {
|
|
|
3407
3408
|
* @since 2.4.0
|
|
3408
3409
|
*/
|
|
3409
3410
|
export function read(asset: string): Response;
|
|
3411
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
3412
|
+
|
|
3413
|
+
type DeepPartial<T> = T extends Record<PropertyKey, unknown> | unknown[]
|
|
3414
|
+
? {
|
|
3415
|
+
[K in keyof T]?: T[K] extends Record<PropertyKey, unknown> | unknown[]
|
|
3416
|
+
? DeepPartial<T[K]>
|
|
3417
|
+
: T[K];
|
|
3418
|
+
}
|
|
3419
|
+
: T | undefined;
|
|
3420
|
+
|
|
3421
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
3422
|
+
|
|
3423
|
+
type HasNonOptionalBoolean<T> =
|
|
3424
|
+
IsAny<T> extends true
|
|
3425
|
+
? never
|
|
3426
|
+
: [T] extends [boolean]
|
|
3427
|
+
? true
|
|
3428
|
+
: T extends Array<infer U>
|
|
3429
|
+
? HasNonOptionalBoolean<U>
|
|
3430
|
+
: T extends Record<string, any>
|
|
3431
|
+
? { [K in keyof T]: HasNonOptionalBoolean<T[K]> }[keyof T]
|
|
3432
|
+
: never;
|
|
3410
3433
|
/**
|
|
3411
3434
|
* Returns the current `RequestEvent`. Can be used inside server hooks, server `load` functions, actions, and endpoints (and functions called by them).
|
|
3412
3435
|
*
|
|
@@ -3623,29 +3646,6 @@ declare module '$app/server' {
|
|
|
3623
3646
|
*
|
|
3624
3647
|
* */
|
|
3625
3648
|
export function requested<Input, Output, Validated = Input>(query: RemoteLiveQueryFunction<Input, Output, Validated>, limit: number): LiveQueryRequestedResult<Validated, Output>;
|
|
3626
|
-
type RemoteLiveQueryUserFunctionReturnType<Output> = MaybePromise<
|
|
3627
|
-
| AsyncGenerator<Output>
|
|
3628
|
-
| AsyncIterator<Output>
|
|
3629
|
-
| AsyncIterable<Output>
|
|
3630
|
-
| Generator<Output>
|
|
3631
|
-
| Iterator<Output>
|
|
3632
|
-
| Iterable<Output>
|
|
3633
|
-
>;
|
|
3634
|
-
type RemotePrerenderInputsGenerator<Input = any> = () => MaybePromise<Input[]>;
|
|
3635
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
3636
|
-
|
|
3637
|
-
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
3638
|
-
|
|
3639
|
-
type HasNonOptionalBoolean<T> =
|
|
3640
|
-
IsAny<T> extends true
|
|
3641
|
-
? never
|
|
3642
|
-
: [T] extends [boolean]
|
|
3643
|
-
? true
|
|
3644
|
-
: T extends Array<infer U>
|
|
3645
|
-
? HasNonOptionalBoolean<U>
|
|
3646
|
-
: T extends Record<string, any>
|
|
3647
|
-
? { [K in keyof T]: HasNonOptionalBoolean<T[K]> }[keyof T]
|
|
3648
|
-
: never;
|
|
3649
3649
|
|
|
3650
3650
|
export {};
|
|
3651
3651
|
}
|