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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/package.json +1 -5
  2. package/src/core/postbuild/prerender.js +19 -19
  3. package/src/core/sync/write_types/index.js +1 -3
  4. package/src/exports/hooks/public.d.ts +1 -2
  5. package/src/exports/hooks/sequence.js +1 -1
  6. package/src/exports/index.js +10 -0
  7. package/src/exports/internal/server/event.js +1 -1
  8. package/src/exports/public.d.ts +205 -2
  9. package/src/exports/vite/dev/index.js +1 -2
  10. package/src/exports/vite/index.js +2 -2
  11. package/src/runtime/app/server/public.d.ts +480 -168
  12. package/src/runtime/app/server/remote/command.js +1 -1
  13. package/src/runtime/app/server/remote/form.js +5 -5
  14. package/src/runtime/app/server/remote/prerender.js +1 -1
  15. package/src/runtime/app/server/remote/query.js +2 -2
  16. package/src/runtime/app/server/remote/requested.js +3 -3
  17. package/src/runtime/app/server/remote/shared.js +1 -1
  18. package/src/runtime/client/remote-functions/command.svelte.js +1 -1
  19. package/src/runtime/client/remote-functions/form.svelte.js +1 -1
  20. package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
  21. package/src/runtime/client/remote-functions/query/index.js +1 -1
  22. package/src/runtime/client/remote-functions/query/instance.svelte.js +2 -1
  23. package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
  24. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  25. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +4 -3
  26. package/src/runtime/client/remote-functions/shared.svelte.js +1 -1
  27. package/src/runtime/server/cookie.js +2 -2
  28. package/src/runtime/server/data/index.js +1 -1
  29. package/src/runtime/server/endpoint.js +3 -3
  30. package/src/runtime/server/errors.js +2 -2
  31. package/src/runtime/server/fetch.js +1 -1
  32. package/src/runtime/server/page/actions.js +1 -2
  33. package/src/runtime/server/page/data_serializer.js +2 -2
  34. package/src/runtime/server/page/index.js +1 -2
  35. package/src/runtime/server/page/load_data.js +3 -3
  36. package/src/runtime/server/page/render.js +1 -1
  37. package/src/runtime/server/page/respond_with_error.js +1 -1
  38. package/src/runtime/server/remote-functions.js +2 -3
  39. package/src/runtime/server/respond.js +2 -2
  40. package/src/runtime/server/utils.js +1 -1
  41. package/src/types/internal.d.ts +2 -2
  42. package/src/utils/promise.js +25 -0
  43. package/src/version.js +1 -1
  44. package/types/index.d.ts +750 -762
  45. package/types/index.d.ts.map +46 -50
  46. package/src/exports/remote/index.js +0 -11
  47. package/src/exports/remote/public.d.ts +0 -519
package/types/index.d.ts CHANGED
@@ -3,10 +3,9 @@
3
3
 
4
4
  declare module '@sveltejs/kit' {
5
5
  import type { Plugin } from 'vite';
6
- import type { RequestEvent } from '$app/server';
7
6
  import type { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
8
- import type { Config } from '@sveltejs/kit/vite';
9
7
  import type { StandardSchemaV1 } from '@standard-schema/spec';
8
+ import type { Config } from '@sveltejs/kit/vite';
10
9
  // @ts-ignore this is an optional peer dependency so could be missing. Written like this so dts-buddy preserves the ts-ignore
11
10
  type Span = import('@opentelemetry/api').Span;
12
11
 
@@ -87,6 +86,14 @@ declare module '@sveltejs/kit' {
87
86
  [uniqueSymbol]: true; // necessary or else UnpackValidationError could wrongly unpack objects with the same shape as ActionFailure
88
87
  }
89
88
 
89
+ /**
90
+ * A validation error thrown by `invalid`.
91
+ */
92
+ export interface ValidationError {
93
+ /** The validation issues */
94
+ issues: StandardSchemaV1.Issue[];
95
+ }
96
+
90
97
  type UnpackValidationError<T> =
91
98
  T extends ActionFailure<infer X>
92
99
  ? X
@@ -242,6 +249,80 @@ declare module '@sveltejs/kit' {
242
249
  compress: (directory: string) => Promise<string[]>;
243
250
  }
244
251
 
252
+ export interface Cookies {
253
+ /**
254
+ * Gets a cookie that was previously set with `cookies.set`, or from the request headers.
255
+ * @param name the name of the cookie
256
+ * @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
257
+ */
258
+ get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined;
259
+
260
+ /**
261
+ * Gets all cookies that were previously set with `cookies.set`, or from the request headers.
262
+ * @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
263
+ */
264
+ getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
265
+
266
+ /**
267
+ * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
268
+ *
269
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
270
+ *
271
+ * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
272
+ * @param name the name of the cookie
273
+ * @param value the cookie value
274
+ * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
275
+ */
276
+ set: (name: string, value: string, opts: import('cookie').SerializeOptions) => void;
277
+
278
+ /**
279
+ * Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
280
+ *
281
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
282
+ *
283
+ * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
284
+ * @param name the name of the cookie
285
+ * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
286
+ */
287
+ delete: (name: string, opts: import('cookie').SerializeOptions) => void;
288
+
289
+ /**
290
+ * Parses a single `Set-Cookie` header. This allows you to apply cookies received from an external source:
291
+ *
292
+ * ```js
293
+ * import { getRequestEvent } from '$app/server';
294
+ *
295
+ * export async function GET() {
296
+ * const { cookies } = getRequestEvent();
297
+ *
298
+ * const response = await fetch('...');
299
+ *
300
+ * for (const str of response.headers.getSetCookie()) {
301
+ * const { name, value, ...options } = cookies.parse(str);
302
+ * cookies.set(name, value, { ...options, path: '/' });
303
+ * }
304
+ *
305
+ * // ...
306
+ * }
307
+ * ```
308
+ *
309
+ * Note the use of `headers.getSetCookie()`, which returns an array of cookie headers, _not_ `headers.get('set-cookie')` which returns a single comma-separated string.
310
+ */
311
+ parse: typeof import('cookie').parseSetCookie;
312
+
313
+ /**
314
+ * Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
315
+ *
316
+ * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
317
+ *
318
+ * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
319
+ * @param name the name of the cookie
320
+ * @param value the cookie value
321
+ * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
322
+ */
323
+ serialize: (name: string, value: string, opts: import('cookie').SerializeOptions) => string;
324
+ }
325
+
245
326
  /**
246
327
  * A collection of functions that influence the environment during dev, build and prerendering
247
328
  */
@@ -311,7 +392,7 @@ declare module '@sveltejs/kit' {
311
392
  *
312
393
  * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
313
394
  *
314
- * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/$app-server#Cookies) API in a server-only `load` function instead.
395
+ * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/@sveltejs-kit#Cookies) API in a server-only `load` function instead.
315
396
  *
316
397
  * `setHeaders` has no effect when a `load` function runs in the browser.
317
398
  */
@@ -413,6 +494,127 @@ declare module '@sveltejs/kit' {
413
494
  url: URL;
414
495
  }
415
496
 
497
+ export interface RequestEvent<
498
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
499
+ RouteId extends AppRouteId | null = AppRouteId | null
500
+ > {
501
+ /**
502
+ * Get or set cookies related to the current request
503
+ */
504
+ readonly cookies: Cookies;
505
+ /**
506
+ * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
507
+ *
508
+ * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
509
+ * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
510
+ * - Internal requests (e.g. for `+server.js` routes) go directly to the handler function when running on the server, without the overhead of an HTTP call.
511
+ * - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://svelte.dev/docs/kit/hooks#handle)
512
+ * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
513
+ *
514
+ * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
515
+ */
516
+ readonly fetch: typeof fetch;
517
+ /**
518
+ * The client's IP address, set by the adapter.
519
+ */
520
+ readonly getClientAddress: () => string;
521
+ /**
522
+ * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
523
+ */
524
+ readonly locals: App.Locals;
525
+ /**
526
+ * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
527
+ *
528
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
529
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
530
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
531
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
532
+ */
533
+ readonly params: Params;
534
+ /**
535
+ * Additional data made available through the adapter.
536
+ */
537
+ readonly platform: Readonly<App.Platform> | undefined;
538
+ /**
539
+ * The original request object.
540
+ */
541
+ readonly request: Request;
542
+ /**
543
+ * Info about the current route.
544
+ */
545
+ readonly route: {
546
+ /**
547
+ * 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.
548
+ *
549
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
550
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
551
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
552
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
553
+ */
554
+ id: RouteId;
555
+ };
556
+ /**
557
+ * If you need to set headers for the response, you can do so using the this method. This is useful if you want the page to be cached, for example:
558
+ *
559
+ * ```js
560
+ * /// file: src/routes/blog/+page.js
561
+ * export async function load({ fetch, setHeaders }) {
562
+ * const url = `https://cms.example.com/articles.json`;
563
+ * const response = await fetch(url);
564
+ *
565
+ * setHeaders({
566
+ * age: response.headers.get('age'),
567
+ * 'cache-control': response.headers.get('cache-control')
568
+ * });
569
+ *
570
+ * return response.json();
571
+ * }
572
+ * ```
573
+ *
574
+ * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
575
+ *
576
+ * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/@sveltejs-kit#Cookies) API instead.
577
+ */
578
+ readonly setHeaders: (headers: Record<string, string>) => void;
579
+ /**
580
+ * The requested URL.
581
+ *
582
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
583
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
584
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
585
+ * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
586
+ */
587
+ readonly url: URL;
588
+ /**
589
+ * `true` if the request comes from the client asking for `+page/layout.server.js` data. The `url` property will be stripped of the internal information
590
+ * related to the data request in this case. Use this property instead if the distinction is important to you.
591
+ */
592
+ readonly isDataRequest: boolean;
593
+ /**
594
+ * `true` for `+server.js` calls coming from SvelteKit without the overhead of actually making an HTTP request. This happens when you make same-origin `fetch` requests on the server.
595
+ */
596
+ readonly isSubRequest: boolean;
597
+
598
+ /**
599
+ * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
600
+ * @since 2.31.0
601
+ */
602
+ readonly tracing: {
603
+ /** Whether tracing is enabled. */
604
+ enabled: boolean;
605
+ /** The root span for the request. This span is named `sveltekit.handle.root`. */
606
+ root: Span;
607
+ /** The span associated with the current `handle` hook, `load` function, or form action. */
608
+ current: Span;
609
+ };
610
+
611
+ /**
612
+ * `true` if the request comes from the client via a remote function. The `url` property will be stripped of the internal information
613
+ * related to the data request in this case. Use this property instead if the distinction is important to you.
614
+ */
615
+ readonly isRemoteRequest: boolean;
616
+ }
617
+
416
618
  /**
417
619
  * A `(event: RequestEvent) => Response` function exported from a `+server.js` file that corresponds to an HTTP verb (`GET`, `PUT`, `PATCH`, etc) and handles requests with that method.
418
620
  *
@@ -834,6 +1036,12 @@ declare module '@sveltejs/kit' {
834
1036
  * @since 2.47.3
835
1037
  */
836
1038
  export function invalid(...issues: (StandardSchemaV1.Issue | string)[]): never;
1039
+ /**
1040
+ * Checks whether this is a validation error thrown by {@link invalid}.
1041
+ * @param e The object to check.
1042
+ * @since 2.47.3
1043
+ */
1044
+ export function isValidationError(e: unknown): e is ValidationError;
837
1045
  /**
838
1046
  * Strips possible SvelteKit-internal suffixes and trailing slashes from the URL pathname.
839
1047
  * Returns the normalized URL as well as a method for adding the potential suffix back
@@ -942,8 +1150,7 @@ declare module '@sveltejs/kit/env' {
942
1150
 
943
1151
  declare module '@sveltejs/kit/hooks' {
944
1152
  import type { StandardSchemaV1 } from '@standard-schema/spec';
945
- import type { NavigationEvent } from '@sveltejs/kit';
946
- import type { RequestEvent } from '$app/server';
1153
+ import type { NavigationEvent, RequestEvent } from '@sveltejs/kit';
947
1154
  /**
948
1155
  * 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
949
1156
  * determines the [response](https://svelte.dev/docs/kit/web-standards#Fetch-APIs-Response).
@@ -1292,550 +1499,13 @@ declare module '@sveltejs/kit/params' {
1292
1499
  export {};
1293
1500
  }
1294
1501
 
1295
- declare module '@sveltejs/kit/remote' {
1296
- import type { StandardSchemaV1 } from '@standard-schema/spec';
1297
- // If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
1298
- type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
1299
-
1300
- // Input type mappings for form fields
1301
- type InputTypeMap = {
1302
- text: string;
1303
- email: string;
1304
- password: string;
1305
- url: string;
1306
- tel: string;
1307
- search: string;
1308
- number: number;
1309
- range: number;
1310
- date: string;
1311
- 'datetime-local': string;
1312
- time: string;
1313
- month: string;
1314
- week: string;
1315
- color: string;
1316
- checkbox: boolean | string[];
1317
- radio: string;
1318
- file: File;
1319
- hidden: string | number | boolean;
1320
- submit: string | number | boolean;
1321
- button: string;
1322
- reset: string;
1323
- image: string;
1324
- select: string;
1325
- 'select multiple': string[];
1326
- 'file multiple': File[];
1327
- };
1328
-
1329
- // Valid input types for a given value type
1330
- export type RemoteFormFieldType<T> = {
1331
- [K in keyof InputTypeMap]: T extends InputTypeMap[K] ? K : never;
1332
- }[keyof InputTypeMap];
1333
-
1334
- // Input element properties based on type
1335
- type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'radio'
1336
- ? {
1337
- name: string;
1338
- type: T;
1339
- value?: string;
1340
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1341
- get checked(): boolean;
1342
- set checked(value: boolean);
1343
- readonly defaultChecked?: boolean;
1344
- }
1345
- : T extends 'file'
1346
- ? {
1347
- name: string;
1348
- type: 'file';
1349
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1350
- get files(): FileList | null;
1351
- set files(v: FileList | null);
1352
- }
1353
- : T extends 'select'
1354
- ? {
1355
- name: string;
1356
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1357
- get value(): string;
1358
- set value(v: string);
1359
- }
1360
- : T extends 'select multiple'
1361
- ? {
1362
- name: string;
1363
- multiple: true;
1364
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1365
- get value(): string[];
1366
- set value(v: string[]);
1367
- }
1368
- : T extends 'text'
1369
- ? {
1370
- name: string;
1371
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1372
- get value(): string | number;
1373
- set value(v: string | number);
1374
- readonly defaultValue?: string | number;
1375
- }
1376
- : {
1377
- name: string;
1378
- type: T;
1379
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
1380
- get value(): string | number;
1381
- set value(v: string | number);
1382
- readonly defaultValue?: string | number;
1383
- };
1384
-
1385
- type RemoteFormFieldMethods<T> = {
1386
- /** The values that will be submitted */
1387
- value(): DeepPartial<T>;
1388
- /** Set the values that will be submitted */
1389
- set(input: DeepPartial<T>): DeepPartial<T>;
1390
- /** Whether the field or any nested field has been interacted with since the form was mounted */
1391
- touched(): boolean;
1392
- /** Whether the field or any nested field has been edited since the form was mounted */
1393
- dirty(): boolean;
1394
- /** Validation issues, if any */
1395
- issues(): RemoteFormIssue[] | undefined;
1396
- };
1397
-
1398
- // These two types use "T extends unknown ? .. : .." to distribute over unions.
1399
- // 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
1400
- type KeysOfUnion<T> = T extends unknown ? keyof T : never;
1401
- type ValueOfUnionKey<T, K extends PropertyKey> = T extends unknown
1402
- ? K extends keyof T
1403
- ? T[K]
1404
- : never
1405
- : never;
1406
-
1407
- export type RemoteFormFieldValue = string | string[] | number | boolean | File | File[];
1408
-
1409
- type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
1410
- ? Value extends string[]
1411
- ? [type: Type, value: Value[number] | (string & {})]
1412
- : Value extends boolean
1413
- ? [type: Type] | [type: Type, value: boolean]
1414
- : [type: Type] | [type: Type, value: Value | (string & {})]
1415
- : Type extends 'submit' | 'hidden'
1416
- ? Value extends string
1417
- ? [type: Type, value: Value | (string & {})]
1418
- : [type: Type, value: Value]
1419
- : Type extends 'radio'
1420
- ? [type: Type, value: Value | (string & {})]
1421
- : Type extends 'file' | 'file multiple'
1422
- ? [type: Type]
1423
- : [type: Type] | [type: Type, value: Value | undefined];
1424
-
1425
- /**
1426
- * Form field accessor type that provides name(), value(), and issues() methods
1427
- */
1428
- export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
1429
- /**
1430
- * Returns an object that can be spread onto an input element with the correct type attribute,
1431
- * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
1432
- * @example
1433
- * ```svelte
1434
- * <input {...myForm.fields.myString.as('text')} />
1435
- * <input {...myForm.fields.myNumber.as('number')} />
1436
- * <input {...myForm.fields.myBoolean.as('checkbox')} />
1437
- * ```
1438
- */
1439
- as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
1440
- };
1441
-
1442
- type RemoteFormFieldContainer<Value> = RemoteFormFieldMethods<Value> & {
1443
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
1444
- allIssues(): RemoteFormIssue[] | undefined;
1445
- };
1446
-
1447
- type UnknownField<Value> = RemoteFormFieldMethods<Value> & {
1448
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
1449
- allIssues(): RemoteFormIssue[] | undefined;
1450
- /**
1451
- * Returns an object that can be spread onto an input element with the correct type attribute,
1452
- * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
1453
- * @example
1454
- * ```svelte
1455
- * <input {...myForm.fields.myString.as('text')} />
1456
- * <input {...myForm.fields.myNumber.as('number')} />
1457
- * <input {...myForm.fields.myBoolean.as('checkbox')} />
1458
- * ```
1459
- */
1460
- as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
1461
- } & {
1462
- [key: string | number]: UnknownField<any>;
1463
- };
1464
-
1465
- type RemoteFormFieldsRoot<Input extends RemoteFormInput | void> =
1466
- IsAny<Input> extends true
1467
- ? RecursiveFormFields
1468
- : Input extends void
1469
- ? {
1470
- /** Validation issues, if any */
1471
- issues(): RemoteFormIssue[] | undefined;
1472
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
1473
- allIssues(): RemoteFormIssue[] | undefined;
1474
- }
1475
- : RemoteFormFields<Input>;
1476
-
1477
- /**
1478
- * Recursive type to build form fields structure with proxy access
1479
- */
1480
- export type RemoteFormFields<T> =
1481
- WillRecurseIndefinitely<T> extends true
1482
- ? RecursiveFormFields
1483
- : NonNullable<T> extends string | number | boolean | File
1484
- ? RemoteFormField<NonNullable<T>>
1485
- : // [NonNullable<T>] is used to prevent distributing over union while still allowing
1486
- // nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
1487
- // to be treated as arrays; only the last condition should distribute over unions
1488
- [NonNullable<T>] extends [string[] | File[]]
1489
- ? RemoteFormField<NonNullable<T>> & {
1490
- [K in number]: RemoteFormField<NonNullable<T>[number]>;
1491
- }
1492
- : [NonNullable<T>] extends [Array<infer U>]
1493
- ? RemoteFormFieldContainer<NonNullable<T>> & {
1494
- [K in number]: RemoteFormFields<U>;
1495
- }
1496
- : RemoteFormFieldContainer<T> & {
1497
- [K in KeysOfUnion<T>]-?: RemoteFormFields<ValueOfUnionKey<T, K>>;
1498
- };
1499
-
1500
- // By breaking this out into its own type, we avoid the TS recursion depth limit
1501
- type RecursiveFormFields = RemoteFormFieldContainer<any> & {
1502
- [key: string | number]: UnknownField<any>;
1503
- };
1504
-
1505
- type MaybeArray<T> = T | T[];
1506
-
1507
- export interface RemoteFormInput {
1508
- [key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
1509
- }
1510
-
1511
- export interface RemoteFormIssue {
1512
- message: string;
1513
- path: Array<string | number>;
1514
- }
1515
-
1516
- // If the schema specifies `id` as a string or number, ensure that `for(...)`
1517
- // only accepts that type. Otherwise, accept `string | number`
1518
- type ExtractId<Input> = Input extends { id: infer Id }
1519
- ? Id extends string | number
1520
- ? Id
1521
- : string | number
1522
- : string | number;
1523
-
1524
- /**
1525
- * A function and proxy object used to imperatively create validation errors in form handlers.
1526
- *
1527
- * Access properties to create field-specific issues: `issue.fieldName('message')`.
1528
- * The type structure mirrors the input data structure for type-safe field access.
1529
- * Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
1530
- */
1531
- export type InvalidField<T> =
1532
- WillRecurseIndefinitely<T> extends true
1533
- ? Record<string | number, any>
1534
- : NonNullable<T> extends string | number | boolean | File
1535
- ? (message: string) => StandardSchemaV1.Issue
1536
- : NonNullable<T> extends Array<infer U>
1537
- ? {
1538
- [K in number]: InvalidField<U>;
1539
- } & ((message: string) => StandardSchemaV1.Issue)
1540
- : NonNullable<T> extends RemoteFormInput
1541
- ? {
1542
- [K in keyof T]-?: InvalidField<T[K]>;
1543
- } & ((message: string) => StandardSchemaV1.Issue)
1544
- : Record<string, never>;
1545
-
1546
- /**
1547
- * A validation error thrown by `invalid`.
1548
- */
1549
- export interface ValidationError {
1550
- /** The validation issues */
1551
- issues: StandardSchemaV1.Issue[];
1552
- }
1553
-
1554
- /**
1555
- * The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
1556
- */
1557
- export type RemoteFormEnhanceInstance<
1558
- Input extends RemoteFormInput | void = RemoteFormInput | void,
1559
- Output = any
1560
- > = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
1561
- readonly element: HTMLFormElement;
1562
- };
1563
-
1564
- /**
1565
- * The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
1566
- */
1567
- export type RemoteFormEnhanceCallback<
1568
- Input extends RemoteFormInput | void = RemoteFormInput | void,
1569
- Output = any
1570
- > = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
1571
-
1572
- /**
1573
- * The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
1574
- */
1575
- export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
1576
- /** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
1577
- [attachment: symbol]: (node: HTMLFormElement) => void;
1578
- method: 'POST';
1579
- /** The URL to send the form to. */
1580
- action: string;
1581
- /** The `<form>` element this instance is currently attached to, if any. */
1582
- get element(): HTMLFormElement | null;
1583
- /** Submit the currently attached form programmatically. */
1584
- submit(): Promise<boolean> & {
1585
- updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
1586
- };
1587
- /** Use the `enhance` method to influence what happens when the form is submitted. */
1588
- enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
1589
- method: 'POST';
1590
- action: string;
1591
- [attachment: symbol]: (node: HTMLFormElement) => void;
1592
- };
1593
- /**
1594
- * Create an instance of the form for the given `id`.
1595
- * The `id` is stringified and used for deduplication to potentially reuse existing instances.
1596
- * Useful when you have multiple forms that use the same remote form action, for example in a loop.
1597
- * ```svelte
1598
- * {#each todos as todo}
1599
- * {const todoForm = updateTodo.for(todo.id)}
1600
- * <form {...todoForm}>
1601
- * {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
1602
- * ...
1603
- * </form>
1604
- * {/each}
1605
- * ```
1606
- */
1607
- for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
1608
- /** Preflight checks */
1609
- preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
1610
- /** Validate the form contents programmatically */
1611
- validate(options?: {
1612
- /**
1613
- * Set this to `true` to also show validation issues of fields that haven't yet been
1614
- * edited and blurred. This option is ignored for forms that have previously been
1615
- * submitted, in which case all fields are always subject to validation
1616
- * (unless the form is reset, at which point it is treated as pristine)
1617
- */
1618
- all?: boolean;
1619
- /** Set this to `true` to only run the `preflight` validation. */
1620
- preflightOnly?: boolean;
1621
- }): Promise<void>;
1622
- /** The result of the form submission */
1623
- get result(): Output | undefined;
1624
- /** The number of pending submissions */
1625
- get pending(): number;
1626
- /** True if the form has been submitted at least once, and hasn't been reset since */
1627
- get submitted(): boolean;
1628
- /** Access form fields using object notation */
1629
- fields: RemoteFormFieldsRoot<Input>;
1630
- };
1631
-
1632
- /**
1633
- * The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
1634
- */
1635
- export type RemoteCommand<Input, Output> = {
1636
- (arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
1637
- updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
1638
- };
1639
- /** The number of pending command executions */
1640
- get pending(): number;
1641
- };
1642
-
1643
- export type RemoteQueryUpdate =
1644
- | RemoteQuery<any>
1645
- | RemoteLiveQuery<any>
1646
- | RemoteQueryFunction<any, any>
1647
- | RemoteLiveQueryFunction<any, any>
1648
- | RemoteQueryOverride;
1649
-
1650
- export type RemoteResource<T> = Promise<T> & {
1651
- /** The error in case the query fails. */
1652
- get error(): App.Error | undefined;
1653
- /** `true` before the first result is available and during refreshes */
1654
- get loading(): boolean;
1655
- } & (
1656
- | {
1657
- /** The current value of the query. Undefined until `ready` is `true` */
1658
- get current(): undefined;
1659
- ready: false;
1660
- }
1661
- | {
1662
- /** The current value of the query. Undefined until `ready` is `true` */
1663
- get current(): T;
1664
- ready: true;
1665
- }
1666
- );
1667
-
1668
- export type RemoteQuery<T> = RemoteResource<T> & {
1669
- /**
1670
- * On the client, this function will update the value of the query without re-fetching it.
1671
- *
1672
- * 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.
1673
- * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
1674
- */
1675
- set(value: T): void;
1676
- /**
1677
- * On the client, this function will re-fetch the query from the server.
1678
- *
1679
- * 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.
1680
- * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
1681
- */
1682
- refresh(): Promise<void>;
1683
- /**
1684
- * 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.
1685
- *
1686
- * ```svelte
1687
- * <script>
1688
- * import { getTodos, addTodo } from './todos.remote.js';
1689
- * const todos = getTodos();
1690
- * </script>
1691
- *
1692
- * <form {...addTodo.enhance(async (form) => {
1693
- * await form.submit().updates(
1694
- * todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
1695
- * );
1696
- * })}>
1697
- * <input type="text" name="text" />
1698
- * <button type="submit">Add Todo</button>
1699
- * </form>
1700
- * ```
1701
- */
1702
- withOverride(update: (current: T) => T): RemoteQueryOverride;
1703
- };
1704
-
1705
- export type RemoteLiveQuery<T> = RemoteResource<T> &
1706
- AsyncIterable<T> & {
1707
- /** `true` if the live stream is currently connected. */
1708
- readonly connected: boolean;
1709
- /** `true` once the current live stream iterator is done. */
1710
- readonly done: boolean;
1711
- /** Reconnects the live stream immediately. */
1712
- reconnect(): Promise<void>;
1713
- };
1714
-
1715
- export type RemoteQueryOverride = () => void;
1716
-
1717
- /**
1718
- * The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
1719
- */
1720
- export type RemotePrerenderFunction<Input, Output> = (
1721
- arg: undefined extends Input ? Input | void : Input
1722
- ) => RemoteResource<Output>;
1723
-
1724
- /**
1725
- * The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
1726
- *
1727
- * The optional `Validated` generic parameter represents the argument type *after* the
1728
- * query's schema has validated and (optionally) transformed it — this is the type the
1729
- * query's implementation function receives on the server, and the type yielded by
1730
- * [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
1731
- * with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
1732
- * schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
1733
- * `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
1734
- * without arguments it defaults to `Input`.
1735
- */
1736
- export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
1737
- arg: undefined extends Input ? Input | void : Input
1738
- ) => RemoteQuery<Output>;
1739
-
1740
- /**
1741
- * The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
1742
- *
1743
- * The optional `Validated` generic parameter represents the argument type *after* the
1744
- * query's schema has validated and (optionally) transformed it, and matches the type
1745
- * yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
1746
- */
1747
- export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
1748
- arg: undefined extends Input ? Input | void : Input
1749
- ) => RemoteLiveQuery<Output>;
1750
-
1751
- /**
1752
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1753
- * when called with a regular `query`. `arg` is the validated argument (the input *after*
1754
- * the query's schema validated and transformed it, if applicable); `query` is a
1755
- * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
1756
- * update the correct client entry.
1757
- */
1758
- export type RequestedEntry<Validated, Output> = {
1759
- arg: Validated;
1760
- query: RemoteQuery<Output>;
1761
- };
1762
-
1763
- /**
1764
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
1765
- * when called with a `query.live`. `arg` is the validated argument; `query` is a
1766
- * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
1767
- * the correct client subscription.
1768
- */
1769
- export type LiveRequestedEntry<Validated, Output> = {
1770
- arg: Validated;
1771
- query: RemoteLiveQuery<Output>;
1772
- };
1773
-
1774
- export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
1775
- AsyncIterable<RequestedEntry<Validated, Output>> & {
1776
- /**
1777
- * Call `refresh` on all queries selected by this `requested` invocation.
1778
- * This is identical to:
1779
- * ```ts
1780
- * import { requested } from '$app/server';
1781
- *
1782
- * for await (const { query } of requested(getPost, ...)) {
1783
- * void query.refresh();
1784
- * }
1785
- * ```
1786
- */
1787
- refreshAll: () => Promise<void>;
1788
- };
1789
-
1790
- export type LiveQueryRequestedResult<Validated, Output> = Iterable<
1791
- LiveRequestedEntry<Validated, Output>
1792
- > &
1793
- AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
1794
- /**
1795
- * Call `reconnect` on all live queries selected by this `requested` invocation.
1796
- * This is identical to:
1797
- * ```ts
1798
- * import { requested } from '$app/server';
1799
- *
1800
- * for await (const { query } of requested(liveQuery, ...)) {
1801
- * void query.reconnect();
1802
- * }
1803
- * ```
1804
- */
1805
- reconnectAll: () => Promise<void>;
1806
- };
1807
-
1808
- export type RequestedResult<Validated, Output> =
1809
- | QueryRequestedResult<Validated, Output>
1810
- | LiveQueryRequestedResult<Validated, Output>;
1811
- /**
1812
- * Checks whether this is a validation error thrown by [`invalid`](https://svelte.dev/docs/kit/@sveltejs-kit#invalid).
1813
- * @param e The object to check.
1814
- * @since 2.47.3
1815
- */
1816
- export function isValidationError(e: unknown): e is import("@sveltejs/kit/remote").ValidationError;
1817
- type MaybePromise<T> = T | Promise<T>;
1818
-
1819
- type DeepPartial<T> = T extends Record<PropertyKey, unknown> | unknown[]
1820
- ? {
1821
- [K in keyof T]?: T[K] extends Record<PropertyKey, unknown> | unknown[]
1822
- ? DeepPartial<T[K]>
1823
- : T[K];
1824
- }
1825
- : T | undefined;
1826
-
1827
- type IsAny<T> = 0 extends 1 & T ? true : false;
1828
-
1829
- export {};
1830
- }
1831
-
1832
- declare module '@sveltejs/kit/vite' {
1833
- import type { Adapter } from '@sveltejs/kit';
1834
- import type { Options } from '@sveltejs/vite-plugin-svelte';
1835
- import type { Plugin } from 'vite';
1836
- // this indirection helps make the docs look pretty
1837
- type VitePluginSvelteOptions = Omit<Options, 'experimental'>;
1838
- type VitePluginSvelteOptionsExperimental = Options['experimental'];
1502
+ declare module '@sveltejs/kit/vite' {
1503
+ import type { Adapter } from '@sveltejs/kit';
1504
+ import type { Options } from '@sveltejs/vite-plugin-svelte';
1505
+ import type { Plugin } from 'vite';
1506
+ // this indirection helps make the docs look pretty
1507
+ type VitePluginSvelteOptions = Omit<Options, 'experimental'>;
1508
+ type VitePluginSvelteOptionsExperimental = Options['experimental'];
1839
1509
 
1840
1510
  /**
1841
1511
  * An extension of [`vite-plugin-svelte`'s options](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#svelte-options).
@@ -3209,218 +2879,537 @@ declare module '$app/paths' {
3209
2879
  ? U
3210
2880
  : T;
3211
2881
 
3212
- type ResolveArgs<T> = T extends `/${string}`
3213
- ? StripSearchOrHash<T> extends infer U extends RouteId
3214
- ? RouteParams<U> extends Record<string, never>
3215
- ? [route: T]
3216
- : [route: T, params: RouteParams<U>]
3217
- : [never]
3218
- : [pathname: T];
2882
+ type ResolveArgs<T> = T extends `/${string}`
2883
+ ? StripSearchOrHash<T> extends infer U extends RouteId
2884
+ ? RouteParams<U> extends Record<string, never>
2885
+ ? [route: T]
2886
+ : [route: T, params: RouteParams<U>]
2887
+ : [never]
2888
+ : [pathname: T];
2889
+
2890
+ export {};
2891
+ }
2892
+
2893
+ declare module '$app/server' {
2894
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2895
+ import type { RequestEvent } from '@sveltejs/kit';
2896
+ // If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
2897
+ type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
2898
+
2899
+ // Input type mappings for form fields
2900
+ type InputTypeMap = {
2901
+ text: string;
2902
+ email: string;
2903
+ password: string;
2904
+ url: string;
2905
+ tel: string;
2906
+ search: string;
2907
+ number: number;
2908
+ range: number;
2909
+ date: string;
2910
+ 'datetime-local': string;
2911
+ time: string;
2912
+ month: string;
2913
+ week: string;
2914
+ color: string;
2915
+ checkbox: boolean | string[];
2916
+ radio: string;
2917
+ file: File;
2918
+ hidden: string | number | boolean;
2919
+ submit: string | number | boolean;
2920
+ button: string;
2921
+ reset: string;
2922
+ image: string;
2923
+ select: string;
2924
+ 'select multiple': string[];
2925
+ 'file multiple': File[];
2926
+ };
2927
+
2928
+ // Valid input types for a given value type
2929
+ export type RemoteFormFieldType<T> = {
2930
+ [K in keyof InputTypeMap]: T extends InputTypeMap[K] ? K : never;
2931
+ }[keyof InputTypeMap];
2932
+
2933
+ // Input element properties based on type
2934
+ type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'radio'
2935
+ ? {
2936
+ name: string;
2937
+ type: T;
2938
+ value?: string;
2939
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2940
+ get checked(): boolean;
2941
+ set checked(value: boolean);
2942
+ readonly defaultChecked?: boolean;
2943
+ }
2944
+ : T extends 'file'
2945
+ ? {
2946
+ name: string;
2947
+ type: 'file';
2948
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2949
+ get files(): FileList | null;
2950
+ set files(v: FileList | null);
2951
+ }
2952
+ : T extends 'select'
2953
+ ? {
2954
+ name: string;
2955
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2956
+ get value(): string;
2957
+ set value(v: string);
2958
+ }
2959
+ : T extends 'select multiple'
2960
+ ? {
2961
+ name: string;
2962
+ multiple: true;
2963
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2964
+ get value(): string[];
2965
+ set value(v: string[]);
2966
+ }
2967
+ : T extends 'text'
2968
+ ? {
2969
+ name: string;
2970
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2971
+ get value(): string | number;
2972
+ set value(v: string | number);
2973
+ readonly defaultValue?: string | number;
2974
+ }
2975
+ : {
2976
+ name: string;
2977
+ type: T;
2978
+ 'aria-invalid': boolean | 'false' | 'true' | undefined;
2979
+ get value(): string | number;
2980
+ set value(v: string | number);
2981
+ readonly defaultValue?: string | number;
2982
+ };
2983
+
2984
+ type RemoteFormFieldMethods<T> = {
2985
+ /** The values that will be submitted */
2986
+ value(): DeepPartial<T>;
2987
+ /** Set the values that will be submitted */
2988
+ set(input: DeepPartial<T>): DeepPartial<T>;
2989
+ /** Whether the field or any nested field has been interacted with since the form was mounted */
2990
+ touched(): boolean;
2991
+ /** Whether the field or any nested field has been edited since the form was mounted */
2992
+ dirty(): boolean;
2993
+ /** Validation issues, if any */
2994
+ issues(): RemoteFormIssue[] | undefined;
2995
+ };
2996
+
2997
+ // These two types use "T extends unknown ? .. : .." to distribute over unions.
2998
+ // Example: if "type T = A | b" then "keyof T" only contains keys that both A and B have, with "KeysOfUnion<T>" we get the keys of both A and B
2999
+ type KeysOfUnion<T> = T extends unknown ? keyof T : never;
3000
+ type ValueOfUnionKey<T, K extends PropertyKey> = T extends unknown
3001
+ ? K extends keyof T
3002
+ ? T[K]
3003
+ : never
3004
+ : never;
3005
+
3006
+ export type RemoteFormFieldValue = string | string[] | number | boolean | File | File[];
3007
+
3008
+ type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
3009
+ ? Value extends string[]
3010
+ ? [type: Type, value: Value[number] | (string & {})]
3011
+ : Value extends boolean
3012
+ ? [type: Type] | [type: Type, value: boolean]
3013
+ : [type: Type] | [type: Type, value: Value | (string & {})]
3014
+ : Type extends 'submit' | 'hidden'
3015
+ ? Value extends string
3016
+ ? [type: Type, value: Value | (string & {})]
3017
+ : [type: Type, value: Value]
3018
+ : Type extends 'radio'
3019
+ ? [type: Type, value: Value | (string & {})]
3020
+ : Type extends 'file' | 'file multiple'
3021
+ ? [type: Type]
3022
+ : [type: Type] | [type: Type, value: Value | undefined];
3023
+
3024
+ /**
3025
+ * Form field accessor type that provides name(), value(), and issues() methods
3026
+ */
3027
+ export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
3028
+ /**
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
+ * ```
3037
+ */
3038
+ as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
3039
+ };
3040
+
3041
+ type RemoteFormFieldContainer<Value> = RemoteFormFieldMethods<Value> & {
3042
+ /** Validation issues belonging to this or any of the fields that belong to it, if any */
3043
+ allIssues(): RemoteFormIssue[] | undefined;
3044
+ };
3045
+
3046
+ type UnknownField<Value> = RemoteFormFieldMethods<Value> & {
3047
+ /** Validation issues belonging to this or any of the fields that belong to it, if any */
3048
+ allIssues(): RemoteFormIssue[] | undefined;
3049
+ /**
3050
+ * Returns an object that can be spread onto an input element with the correct type attribute,
3051
+ * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
3052
+ * @example
3053
+ * ```svelte
3054
+ * <input {...myForm.fields.myString.as('text')} />
3055
+ * <input {...myForm.fields.myNumber.as('number')} />
3056
+ * <input {...myForm.fields.myBoolean.as('checkbox')} />
3057
+ * ```
3058
+ */
3059
+ as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
3060
+ } & {
3061
+ [key: string | number]: UnknownField<any>;
3062
+ };
3063
+
3064
+ type RemoteFormFieldsRoot<Input extends RemoteFormInput | void> =
3065
+ IsAny<Input> extends true
3066
+ ? RecursiveFormFields
3067
+ : Input extends void
3068
+ ? {
3069
+ /** Validation issues, if any */
3070
+ issues(): RemoteFormIssue[] | undefined;
3071
+ /** Validation issues belonging to this or any of the fields that belong to it, if any */
3072
+ allIssues(): RemoteFormIssue[] | undefined;
3073
+ }
3074
+ : RemoteFormFields<Input>;
3075
+
3076
+ /**
3077
+ * Recursive type to build form fields structure with proxy access
3078
+ */
3079
+ export type RemoteFormFields<T> =
3080
+ WillRecurseIndefinitely<T> extends true
3081
+ ? RecursiveFormFields
3082
+ : NonNullable<T> extends string | number | boolean | File
3083
+ ? RemoteFormField<NonNullable<T>>
3084
+ : // [NonNullable<T>] is used to prevent distributing over union while still allowing
3085
+ // nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
3086
+ // to be treated as arrays; only the last condition should distribute over unions
3087
+ [NonNullable<T>] extends [string[] | File[]]
3088
+ ? RemoteFormField<NonNullable<T>> & {
3089
+ [K in number]: RemoteFormField<NonNullable<T>[number]>;
3090
+ }
3091
+ : [NonNullable<T>] extends [Array<infer U>]
3092
+ ? RemoteFormFieldContainer<NonNullable<T>> & {
3093
+ [K in number]: RemoteFormFields<U>;
3094
+ }
3095
+ : RemoteFormFieldContainer<T> & {
3096
+ [K in KeysOfUnion<T>]-?: RemoteFormFields<ValueOfUnionKey<T, K>>;
3097
+ };
3098
+
3099
+ // By breaking this out into its own type, we avoid the TS recursion depth limit
3100
+ type RecursiveFormFields = RemoteFormFieldContainer<any> & {
3101
+ [key: string | number]: UnknownField<any>;
3102
+ };
3219
3103
 
3220
- export {};
3221
- }
3104
+ type MaybeArray<T> = T | T[];
3222
3105
 
3223
- declare module '$app/server' {
3224
- import type { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
3225
- import type { StandardSchemaV1 } from '@standard-schema/spec';
3226
- import type { RemoteCommand, RemoteForm, RemoteFormInput, InvalidField, RemotePrerenderFunction, RemoteQueryFunction, RemoteLiveQueryFunction, QueryRequestedResult, LiveQueryRequestedResult } from '@sveltejs/kit/remote';
3227
- // @ts-ignore this is an optional peer dependency so could be missing. Written like this so dts-buddy preserves the ts-ignore
3228
- type Span = import('@opentelemetry/api').Span;
3106
+ export interface RemoteFormInput {
3107
+ [key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
3108
+ }
3229
3109
 
3230
- export interface Cookies {
3231
- /**
3232
- * Gets a cookie that was previously set with `cookies.set`, or from the request headers.
3233
- * @param name the name of the cookie
3234
- * @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
3235
- */
3236
- get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined;
3110
+ export interface RemoteFormIssue {
3111
+ message: string;
3112
+ path: Array<string | number>;
3113
+ }
3237
3114
 
3238
- /**
3239
- * Gets all cookies that were previously set with `cookies.set`, or from the request headers.
3240
- * @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
3241
- */
3242
- getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
3115
+ // If the schema specifies `id` as a string or number, ensure that `for(...)`
3116
+ // only accepts that type. Otherwise, accept `string | number`
3117
+ type ExtractId<Input> = Input extends { id: infer Id }
3118
+ ? Id extends string | number
3119
+ ? Id
3120
+ : string | number
3121
+ : string | number;
3243
3122
 
3244
- /**
3245
- * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
3246
- *
3247
- * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
3248
- *
3249
- * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
3250
- * @param name the name of the cookie
3251
- * @param value the cookie value
3252
- * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
3253
- */
3254
- set: (name: string, value: string, opts: import('cookie').SerializeOptions) => void;
3123
+ /**
3124
+ * A function and proxy object used to imperatively create validation errors in form handlers.
3125
+ *
3126
+ * Access properties to create field-specific issues: `issue.fieldName('message')`.
3127
+ * The type structure mirrors the input data structure for type-safe field access.
3128
+ * Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
3129
+ */
3130
+ export type RemoteFormInvalidField<T> =
3131
+ WillRecurseIndefinitely<T> extends true
3132
+ ? Record<string | number, any>
3133
+ : NonNullable<T> extends string | number | boolean | File
3134
+ ? (message: string) => StandardSchemaV1.Issue
3135
+ : NonNullable<T> extends Array<infer U>
3136
+ ? {
3137
+ [K in number]: RemoteFormInvalidField<U>;
3138
+ } & ((message: string) => StandardSchemaV1.Issue)
3139
+ : NonNullable<T> extends RemoteFormInput
3140
+ ? {
3141
+ [K in keyof T]-?: RemoteFormInvalidField<T[K]>;
3142
+ } & ((message: string) => StandardSchemaV1.Issue)
3143
+ : Record<string, never>;
3255
3144
 
3256
- /**
3257
- * Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
3258
- *
3259
- * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
3260
- *
3261
- * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
3262
- * @param name the name of the cookie
3263
- * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
3264
- */
3265
- delete: (name: string, opts: import('cookie').SerializeOptions) => void;
3145
+ /**
3146
+ * The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
3147
+ */
3148
+ export type RemoteFormEnhanceInstance<
3149
+ Input extends RemoteFormInput | void = RemoteFormInput | void,
3150
+ Output = any
3151
+ > = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
3152
+ readonly element: HTMLFormElement;
3153
+ };
3154
+
3155
+ /**
3156
+ * The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
3157
+ */
3158
+ export type RemoteFormEnhanceCallback<
3159
+ Input extends RemoteFormInput | void = RemoteFormInput | void,
3160
+ Output = any
3161
+ > = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
3266
3162
 
3163
+ /**
3164
+ * The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
3165
+ */
3166
+ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
3167
+ /** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
3168
+ [attachment: symbol]: (node: HTMLFormElement) => void;
3169
+ method: 'POST';
3170
+ /** The URL to send the form to. */
3171
+ action: string;
3172
+ /** The `<form>` element this instance is currently attached to, if any. */
3173
+ get element(): HTMLFormElement | null;
3174
+ /** Submit the currently attached form programmatically. */
3175
+ submit(): Promise<boolean> & {
3176
+ updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
3177
+ };
3178
+ /** Use the `enhance` method to influence what happens when the form is submitted. */
3179
+ enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
3180
+ method: 'POST';
3181
+ action: string;
3182
+ [attachment: symbol]: (node: HTMLFormElement) => void;
3183
+ };
3267
3184
  /**
3268
- * Parses a single `Set-Cookie` header. This allows you to apply cookies received from an external source:
3269
- *
3270
- * ```js
3271
- * import { getRequestEvent } from '$app/server';
3272
- *
3273
- * export async function GET() {
3274
- * const { cookies } = getRequestEvent();
3275
- *
3276
- * const response = await fetch('...');
3277
- *
3278
- * for (const str of response.headers.getSetCookie()) {
3279
- * const { name, value, ...options } = cookies.parse(str);
3280
- * cookies.set(name, value, { ...options, path: '/' });
3281
- * }
3282
- *
3283
- * // ...
3284
- * }
3185
+ * Create an instance of the form for the given `id`.
3186
+ * The `id` is stringified and used for deduplication to potentially reuse existing instances.
3187
+ * Useful when you have multiple forms that use the same remote form action, for example in a loop.
3188
+ * ```svelte
3189
+ * {#each todos as todo}
3190
+ * {const todoForm = updateTodo.for(todo.id)}
3191
+ * <form {...todoForm}>
3192
+ * {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
3193
+ * ...
3194
+ * </form>
3195
+ * {/each}
3285
3196
  * ```
3286
- *
3287
- * Note the use of `headers.getSetCookie()`, which returns an array of cookie headers, _not_ `headers.get('set-cookie')` which returns a single comma-separated string.
3288
3197
  */
3289
- parse: typeof import('cookie').parseSetCookie;
3198
+ for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
3199
+ /** Preflight checks */
3200
+ preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
3201
+ /** Validate the form contents programmatically */
3202
+ validate(options?: {
3203
+ /**
3204
+ * Set this to `true` to also show validation issues of fields that haven't yet been
3205
+ * edited and blurred. This option is ignored for forms that have previously been
3206
+ * submitted, in which case all fields are always subject to validation
3207
+ * (unless the form is reset, at which point it is treated as pristine)
3208
+ */
3209
+ all?: boolean;
3210
+ /** Set this to `true` to only run the `preflight` validation. */
3211
+ preflightOnly?: boolean;
3212
+ }): Promise<void>;
3213
+ /** The result of the form submission */
3214
+ get result(): Output | undefined;
3215
+ /** The number of pending submissions */
3216
+ get pending(): number;
3217
+ /** True if the form has been submitted at least once, and hasn't been reset since */
3218
+ get submitted(): boolean;
3219
+ /** Access form fields using object notation */
3220
+ fields: RemoteFormFieldsRoot<Input>;
3221
+ };
3290
3222
 
3291
- /**
3292
- * Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
3293
- *
3294
- * The `httpOnly` is `true` by default, as is `secure`, except during development, when it defaults to `false`. These must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
3295
- *
3296
- * The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
3297
- * @param name the name of the cookie
3298
- * @param value the cookie value
3299
- * @param opts the options passed to `cookie.stringifySetCookie` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
3300
- */
3301
- serialize: (name: string, value: string, opts: import('cookie').SerializeOptions) => string;
3302
- }
3223
+ /**
3224
+ * The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
3225
+ */
3226
+ export type RemoteCommand<Input, Output> = {
3227
+ (arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
3228
+ updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
3229
+ };
3230
+ /** The number of pending command executions */
3231
+ get pending(): number;
3232
+ };
3303
3233
 
3304
- export interface RequestEvent<
3305
- Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
3306
- RouteId extends AppRouteId | null = AppRouteId | null
3307
- > {
3308
- /**
3309
- * Get or set cookies related to the current request
3310
- */
3311
- readonly cookies: Cookies;
3312
- /**
3313
- * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
3314
- *
3315
- * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
3316
- * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
3317
- * - Internal requests (e.g. for `+server.js` routes) go directly to the handler function when running on the server, without the overhead of an HTTP call.
3318
- * - During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the `text` and `json` methods of the `Response` object. Note that headers will _not_ be serialized, unless explicitly included via [`filterSerializedResponseHeaders`](https://svelte.dev/docs/kit/hooks#handle)
3319
- * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
3320
- *
3321
- * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
3322
- */
3323
- readonly fetch: typeof fetch;
3324
- /**
3325
- * The client's IP address, set by the adapter.
3326
- */
3327
- readonly getClientAddress: () => string;
3328
- /**
3329
- * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
3330
- */
3331
- readonly locals: App.Locals;
3234
+ export type RemoteQueryUpdate =
3235
+ | RemoteQuery<any>
3236
+ | RemoteLiveQuery<any>
3237
+ | RemoteQueryFunction<any, any>
3238
+ | RemoteLiveQueryFunction<any, any>
3239
+ | RemoteQueryOverride;
3240
+
3241
+ export type RemoteResource<T> = Promise<T> & {
3242
+ /** The error in case the query fails. */
3243
+ get error(): App.Error | undefined;
3244
+ /** `true` before the first result is available and during refreshes */
3245
+ get loading(): boolean;
3246
+ } & (
3247
+ | {
3248
+ /** The current value of the query. Undefined until `ready` is `true` */
3249
+ get current(): undefined;
3250
+ ready: false;
3251
+ }
3252
+ | {
3253
+ /** The current value of the query. Undefined until `ready` is `true` */
3254
+ get current(): T;
3255
+ ready: true;
3256
+ }
3257
+ );
3258
+
3259
+ export type RemoteQuery<T> = RemoteResource<T> & {
3332
3260
  /**
3333
- * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
3261
+ * On the client, this function will update the value of the query without re-fetching it.
3334
3262
  *
3335
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
3336
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
3337
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
3338
- * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
3339
- */
3340
- readonly params: Params;
3341
- /**
3342
- * Additional data made available through the adapter.
3263
+ * On the server, this can be called in the context of a `command` or `form` and the specified data will accompany the action response back to the client.
3264
+ * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
3343
3265
  */
3344
- readonly platform: Readonly<App.Platform> | undefined;
3266
+ set(value: T): void;
3345
3267
  /**
3346
- * The original request object.
3268
+ * On the client, this function will re-fetch the query from the server.
3269
+ *
3270
+ * On the server, this can be called in the context of a `command` or `form` and the refreshed data will accompany the action response back to the client.
3271
+ * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
3347
3272
  */
3348
- readonly request: Request;
3273
+ refresh(): Promise<void>;
3349
3274
  /**
3350
- * Info about the current route.
3275
+ * Temporarily override a query's value during a [single-flight mutation](https://svelte.dev/docs/kit/remote-functions#Single-flight-mutations) to provide optimistic updates.
3276
+ *
3277
+ * ```svelte
3278
+ * <script>
3279
+ * import { getTodos, addTodo } from './todos.remote.js';
3280
+ * const todos = getTodos();
3281
+ * </script>
3282
+ *
3283
+ * <form {...addTodo.enhance(async (form) => {
3284
+ * await form.submit().updates(
3285
+ * todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
3286
+ * );
3287
+ * })}>
3288
+ * <input type="text" name="text" />
3289
+ * <button type="submit">Add Todo</button>
3290
+ * </form>
3291
+ * ```
3351
3292
  */
3352
- readonly route: {
3293
+ withOverride(update: (current: T) => T): RemoteQueryOverride;
3294
+ };
3295
+
3296
+ export type RemoteLiveQuery<T> = RemoteResource<T> &
3297
+ AsyncIterable<T> & {
3298
+ /** `true` if the live stream is currently connected. */
3299
+ readonly connected: boolean;
3300
+ /** `true` once the current live stream iterator is done. */
3301
+ readonly done: boolean;
3302
+ /** Reconnects the live stream immediately. */
3303
+ reconnect(): Promise<void>;
3304
+ };
3305
+
3306
+ export type RemoteQueryOverride = () => void;
3307
+
3308
+ /**
3309
+ * The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
3310
+ */
3311
+ export type RemotePrerenderFunction<Input, Output> = (
3312
+ arg: undefined extends Input ? Input | void : Input
3313
+ ) => RemoteResource<Output>;
3314
+
3315
+ /**
3316
+ * The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
3317
+ *
3318
+ * The optional `Validated` generic parameter represents the argument type *after* the
3319
+ * query's schema has validated and (optionally) transformed it — this is the type the
3320
+ * query's implementation function receives on the server, and the type yielded by
3321
+ * [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
3322
+ * with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
3323
+ * schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
3324
+ * `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
3325
+ * without arguments it defaults to `Input`.
3326
+ */
3327
+ export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
3328
+ arg: undefined extends Input ? Input | void : Input
3329
+ ) => RemoteQuery<Output>;
3330
+
3331
+ /**
3332
+ * The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
3333
+ *
3334
+ * The optional `Validated` generic parameter represents the argument type *after* the
3335
+ * query's schema has validated and (optionally) transformed it, and matches the type
3336
+ * yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
3337
+ */
3338
+ export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
3339
+ arg: undefined extends Input ? Input | void : Input
3340
+ ) => RemoteLiveQuery<Output>;
3341
+
3342
+ /**
3343
+ * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
3344
+ * when called with a regular `query`. `arg` is the validated argument (the input *after*
3345
+ * the query's schema validated and transformed it, if applicable); `query` is a
3346
+ * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
3347
+ * update the correct client entry.
3348
+ */
3349
+ export type RequestedEntry<Validated, Output> = {
3350
+ arg: Validated;
3351
+ query: RemoteQuery<Output>;
3352
+ };
3353
+
3354
+ /**
3355
+ * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
3356
+ * when called with a `query.live`. `arg` is the validated argument; `query` is a
3357
+ * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
3358
+ * the correct client subscription.
3359
+ */
3360
+ export type RemoteLiveQueryRequestedEntry<Validated, Output> = {
3361
+ arg: Validated;
3362
+ query: RemoteLiveQuery<Output>;
3363
+ };
3364
+
3365
+ export type RemoteQueryRequestedResult<Validated, Output> = Iterable<
3366
+ RequestedEntry<Validated, Output>
3367
+ > &
3368
+ AsyncIterable<RequestedEntry<Validated, Output>> & {
3353
3369
  /**
3354
- * 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.
3370
+ * Call `refresh` on all queries selected by this `requested` invocation.
3371
+ * This is identical to:
3372
+ * ```ts
3373
+ * import { requested } from '$app/server';
3355
3374
  *
3356
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
3357
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
3358
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
3359
- * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
3375
+ * for await (const { query } of requested(getPost, ...)) {
3376
+ * void query.refresh();
3377
+ * }
3378
+ * ```
3360
3379
  */
3361
- id: RouteId;
3380
+ refreshAll: () => Promise<void>;
3362
3381
  };
3363
- /**
3364
- * If you need to set headers for the response, you can do so using the this method. This is useful if you want the page to be cached, for example:
3365
- *
3366
- * ```js
3367
- * /// file: src/routes/blog/+page.js
3368
- * export async function load({ fetch, setHeaders }) {
3369
- * const url = `https://cms.example.com/articles.json`;
3370
- * const response = await fetch(url);
3371
- *
3372
- * setHeaders({
3373
- * age: response.headers.get('age'),
3374
- * 'cache-control': response.headers.get('cache-control')
3375
- * });
3376
- *
3377
- * return response.json();
3378
- * }
3379
- * ```
3380
- *
3381
- * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
3382
- *
3383
- * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/$app-server#Cookies) API instead.
3384
- */
3385
- readonly setHeaders: (headers: Record<string, string>) => void;
3386
- /**
3387
- * The requested URL.
3388
- *
3389
- * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
3390
- * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
3391
- * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
3392
- * to determine whether or not a user is authorized to access certain data, as these values are part of the request which could be manipulated.
3393
- */
3394
- readonly url: URL;
3395
- /**
3396
- * `true` if the request comes from the client asking for `+page/layout.server.js` data. The `url` property will be stripped of the internal information
3397
- * related to the data request in this case. Use this property instead if the distinction is important to you.
3398
- */
3399
- readonly isDataRequest: boolean;
3400
- /**
3401
- * `true` for `+server.js` calls coming from SvelteKit without the overhead of actually making an HTTP request. This happens when you make same-origin `fetch` requests on the server.
3402
- */
3403
- readonly isSubRequest: boolean;
3404
3382
 
3405
- /**
3406
- * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
3407
- * @since 2.31.0
3408
- */
3409
- readonly tracing: {
3410
- /** Whether tracing is enabled. */
3411
- enabled: boolean;
3412
- /** The root span for the request. This span is named `sveltekit.handle.root`. */
3413
- root: Span;
3414
- /** The span associated with the current `handle` hook, `load` function, or form action. */
3415
- current: Span;
3383
+ export type RemoteLiveQueryRequestedResult<Validated, Output> = Iterable<
3384
+ RemoteLiveQueryRequestedEntry<Validated, Output>
3385
+ > &
3386
+ AsyncIterable<RemoteLiveQueryRequestedEntry<Validated, Output>> & {
3387
+ /**
3388
+ * Call `reconnect` on all live queries selected by this `requested` invocation.
3389
+ * This is identical to:
3390
+ * ```ts
3391
+ * import { requested } from '$app/server';
3392
+ *
3393
+ * for await (const { query } of requested(liveQuery, ...)) {
3394
+ * void query.reconnect();
3395
+ * }
3396
+ * ```
3397
+ */
3398
+ reconnectAll: () => Promise<void>;
3416
3399
  };
3417
3400
 
3418
- /**
3419
- * `true` if the request comes from the client via a remote function. The `url` property will be stripped of the internal information
3420
- * related to the data request in this case. Use this property instead if the distinction is important to you.
3421
- */
3422
- readonly isRemoteRequest: boolean;
3423
- }
3401
+ export type RequestedResult<Validated, Output> =
3402
+ | RemoteQueryRequestedResult<Validated, Output>
3403
+ | RemoteLiveQueryRequestedResult<Validated, Output>;
3404
+ type RemoteLiveQueryUserFunctionReturnType<Output> = MaybePromise<
3405
+ | AsyncGenerator<Output>
3406
+ | AsyncIterator<Output>
3407
+ | AsyncIterable<Output>
3408
+ | Generator<Output>
3409
+ | Iterator<Output>
3410
+ | Iterable<Output>
3411
+ >;
3412
+ type RemotePrerenderInputsGenerator<Input = any> = () => MaybePromise<Input[]>;
3424
3413
  /**
3425
3414
  * Read the contents of an imported asset from the filesystem
3426
3415
  * @example
@@ -3434,6 +3423,28 @@ declare module '$app/server' {
3434
3423
  * @since 2.4.0
3435
3424
  */
3436
3425
  export function read(asset: string): Response;
3426
+ type MaybePromise<T> = T | Promise<T>;
3427
+
3428
+ type DeepPartial<T> = T extends Record<PropertyKey, unknown> | unknown[]
3429
+ ? {
3430
+ [K in keyof T]?: T[K] extends Record<PropertyKey, unknown> | unknown[]
3431
+ ? DeepPartial<T[K]>
3432
+ : T[K];
3433
+ }
3434
+ : T | undefined;
3435
+
3436
+ type IsAny<T> = 0 extends 1 & T ? true : false;
3437
+
3438
+ type HasNonOptionalBoolean<T> =
3439
+ IsAny<T> extends true
3440
+ ? never
3441
+ : [T] extends [boolean]
3442
+ ? true
3443
+ : T extends Array<infer U>
3444
+ ? HasNonOptionalBoolean<U>
3445
+ : T extends Record<string, any>
3446
+ ? { [K in keyof T]: HasNonOptionalBoolean<T[K]> }[keyof T]
3447
+ : never;
3437
3448
  /**
3438
3449
  * Returns the current `RequestEvent`. Can be used inside server hooks, server `load` functions, actions, and endpoints (and functions called by them).
3439
3450
  *
@@ -3481,7 +3492,7 @@ declare module '$app/server' {
3481
3492
  *
3482
3493
  * @since 2.27
3483
3494
  */
3484
- export function form<Input extends RemoteFormInput, Output>(validate: "unchecked", fn: (data: Input, issue: InvalidField<Input>) => MaybePromise<Output>): RemoteForm<Input, Output>;
3495
+ export function form<Input extends RemoteFormInput, Output>(validate: "unchecked", fn: (data: Input, issue: RemoteFormInvalidField<Input>) => MaybePromise<Output>): RemoteForm<Input, Output>;
3485
3496
  /**
3486
3497
  * Creates a form object that can be spread onto a `<form>` element.
3487
3498
  *
@@ -3489,7 +3500,7 @@ declare module '$app/server' {
3489
3500
  *
3490
3501
  * @since 2.27
3491
3502
  */
3492
- export function form<Schema extends StandardSchemaV1<RemoteFormInput, Record<string, any>>, Output>(validate: true extends HasNonOptionalBoolean<StandardSchemaV1.InferInput<Schema>> ? "Error: All booleans in form schemas must be optional (e.g. `v.optional(v.boolean(), false)`) because checkbox inputs do not send a false value when unchecked." : Schema, fn: (data: StandardSchemaV1.InferOutput<Schema>, issue: InvalidField<StandardSchemaV1.InferInput<Schema>>) => MaybePromise<Output>): RemoteForm<StandardSchemaV1.InferInput<Schema>, Output>;
3503
+ export function form<Schema extends StandardSchemaV1<RemoteFormInput, Record<string, any>>, Output>(validate: true extends HasNonOptionalBoolean<StandardSchemaV1.InferInput<Schema>> ? "Error: All booleans in form schemas must be optional (e.g. `v.optional(v.boolean(), false)`) because checkbox inputs do not send a false value when unchecked." : Schema, fn: (data: StandardSchemaV1.InferOutput<Schema>, issue: RemoteFormInvalidField<StandardSchemaV1.InferInput<Schema>>) => MaybePromise<Output>): RemoteForm<StandardSchemaV1.InferInput<Schema>, Output>;
3493
3504
  /**
3494
3505
  * Creates a remote prerender function. When called from the browser, the function will be invoked on the server via a `fetch` call.
3495
3506
  *
@@ -3617,7 +3628,7 @@ declare module '$app/server' {
3617
3628
  * For live queries, the same applies, but with `reconnect` and `reconnectAll`.
3618
3629
  *
3619
3630
  * */
3620
- export function requested<Input, Output, Validated = Input>(query: RemoteQueryFunction<Input, Output, Validated>, limit: number): QueryRequestedResult<Validated, Output>;
3631
+ export function requested<Input, Output, Validated = Input>(query: RemoteQueryFunction<Input, Output, Validated>, limit: number): RemoteQueryRequestedResult<Validated, Output>;
3621
3632
  /**
3622
3633
  * Inside a remote `command` or `form` callback, returns an iterable
3623
3634
  * of `{ arg, query }` entries for the live query instances the client asked to reconnect, up to
@@ -3649,30 +3660,7 @@ declare module '$app/server' {
3649
3660
  * ```
3650
3661
  *
3651
3662
  * */
3652
- export function requested<Input, Output, Validated = Input>(query: RemoteLiveQueryFunction<Input, Output, Validated>, limit: number): LiveQueryRequestedResult<Validated, Output>;
3653
- type RemoteLiveQueryUserFunctionReturnType<Output> = MaybePromise<
3654
- | AsyncGenerator<Output>
3655
- | AsyncIterator<Output>
3656
- | AsyncIterable<Output>
3657
- | Generator<Output>
3658
- | Iterator<Output>
3659
- | Iterable<Output>
3660
- >;
3661
- type RemotePrerenderInputsGenerator<Input = any> = () => MaybePromise<Input[]>;
3662
- type MaybePromise<T> = T | Promise<T>;
3663
-
3664
- type IsAny<T> = 0 extends 1 & T ? true : false;
3665
-
3666
- type HasNonOptionalBoolean<T> =
3667
- IsAny<T> extends true
3668
- ? never
3669
- : [T] extends [boolean]
3670
- ? true
3671
- : T extends Array<infer U>
3672
- ? HasNonOptionalBoolean<U>
3673
- : T extends Record<string, any>
3674
- ? { [K in keyof T]: HasNonOptionalBoolean<T[K]> }[keyof T]
3675
- : never;
3663
+ export function requested<Input, Output, Validated = Input>(query: RemoteLiveQueryFunction<Input, Output, Validated>, limit: number): RemoteLiveQueryRequestedResult<Validated, Output>;
3676
3664
 
3677
3665
  export {};
3678
3666
  }