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

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 (61) hide show
  1. package/package.json +7 -3
  2. package/src/cli.js +2 -2
  3. package/src/core/adapt/builder.js +14 -14
  4. package/src/core/adapt/index.js +16 -2
  5. package/src/core/config/index.js +33 -44
  6. package/src/core/config/options.js +66 -44
  7. package/src/core/env.js +3 -3
  8. package/src/core/postbuild/analyse.js +1 -1
  9. package/src/core/postbuild/prerender.js +48 -20
  10. package/src/core/sync/create_manifest_data/index.js +11 -11
  11. package/src/core/sync/sync.js +8 -8
  12. package/src/core/sync/write_app_types.js +2 -2
  13. package/src/core/sync/write_client_manifest.js +1 -1
  14. package/src/core/sync/write_server.js +14 -14
  15. package/src/core/sync/write_tsconfig/index.js +4 -4
  16. package/src/core/sync/write_types/index.js +10 -9
  17. package/src/exports/hooks/public.d.ts +2 -1
  18. package/src/exports/hooks/sequence.js +1 -1
  19. package/src/exports/index.js +0 -10
  20. package/src/exports/internal/server/event.js +1 -1
  21. package/src/exports/public.d.ts +2 -786
  22. package/src/exports/remote/index.js +11 -0
  23. package/src/exports/remote/public.d.ts +519 -0
  24. package/src/exports/vite/build/build_server.js +2 -2
  25. package/src/exports/vite/dev/index.js +30 -32
  26. package/src/exports/vite/index.js +98 -47
  27. package/src/exports/vite/preview/index.js +10 -10
  28. package/src/exports/vite/public.d.ts +588 -0
  29. package/src/exports/vite/utils.js +1 -1
  30. package/src/runtime/app/server/public.d.ts +168 -486
  31. package/src/runtime/app/server/remote/command.js +1 -1
  32. package/src/runtime/app/server/remote/form.js +1 -1
  33. package/src/runtime/app/server/remote/prerender.js +1 -1
  34. package/src/runtime/app/server/remote/query.js +2 -2
  35. package/src/runtime/app/server/remote/requested.js +1 -1
  36. package/src/runtime/app/server/remote/shared.js +1 -1
  37. package/src/runtime/client/remote-functions/command.svelte.js +1 -1
  38. package/src/runtime/client/remote-functions/form.svelte.js +1 -1
  39. package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
  40. package/src/runtime/client/remote-functions/query/index.js +1 -1
  41. package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
  42. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  43. package/src/runtime/client/remote-functions/shared.svelte.js +1 -1
  44. package/src/runtime/server/cookie.js +2 -2
  45. package/src/runtime/server/data/index.js +1 -1
  46. package/src/runtime/server/endpoint.js +3 -3
  47. package/src/runtime/server/errors.js +2 -2
  48. package/src/runtime/server/fetch.js +1 -1
  49. package/src/runtime/server/page/actions.js +2 -1
  50. package/src/runtime/server/page/data_serializer.js +2 -2
  51. package/src/runtime/server/page/index.js +2 -1
  52. package/src/runtime/server/page/load_data.js +3 -3
  53. package/src/runtime/server/page/render.js +1 -1
  54. package/src/runtime/server/page/respond_with_error.js +1 -1
  55. package/src/runtime/server/remote-functions.js +3 -2
  56. package/src/runtime/server/respond.js +2 -2
  57. package/src/runtime/server/utils.js +1 -1
  58. package/src/types/internal.d.ts +7 -11
  59. package/src/version.js +1 -1
  60. package/types/index.d.ts +2368 -2341
  61. package/types/index.d.ts.map +67 -61
@@ -1,519 +1,201 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { DeepPartial, IsAny, MaybePromise } from 'types';
1
+ import { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
3
2
 
4
3
  export * from './index.js';
5
4
 
6
- // If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
7
- type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
5
+ // @ts-ignore this is an optional peer dependency so could be missing. Written like this so dts-buddy preserves the ts-ignore
6
+ type Span = import('@opentelemetry/api').Span;
8
7
 
9
- // Input type mappings for form fields
10
- type InputTypeMap = {
11
- text: string;
12
- email: string;
13
- password: string;
14
- url: string;
15
- tel: string;
16
- search: string;
17
- number: number;
18
- range: number;
19
- date: string;
20
- 'datetime-local': string;
21
- time: string;
22
- month: string;
23
- week: string;
24
- color: string;
25
- checkbox: boolean | string[];
26
- radio: string;
27
- file: File;
28
- hidden: string | number | boolean;
29
- submit: string | number | boolean;
30
- button: string;
31
- reset: string;
32
- image: string;
33
- select: string;
34
- 'select multiple': string[];
35
- 'file multiple': File[];
36
- };
37
-
38
- // Valid input types for a given value type
39
- export type RemoteFormFieldType<T> = {
40
- [K in keyof InputTypeMap]: T extends InputTypeMap[K] ? K : never;
41
- }[keyof InputTypeMap];
42
-
43
- // Input element properties based on type
44
- type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'radio'
45
- ? {
46
- name: string;
47
- type: T;
48
- value?: string;
49
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
50
- get checked(): boolean;
51
- set checked(value: boolean);
52
- readonly defaultChecked?: boolean;
53
- }
54
- : T extends 'file'
55
- ? {
56
- name: string;
57
- type: 'file';
58
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
59
- get files(): FileList | null;
60
- set files(v: FileList | null);
61
- }
62
- : T extends 'select'
63
- ? {
64
- name: string;
65
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
66
- get value(): string;
67
- set value(v: string);
68
- }
69
- : T extends 'select multiple'
70
- ? {
71
- name: string;
72
- multiple: true;
73
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
74
- get value(): string[];
75
- set value(v: string[]);
76
- }
77
- : T extends 'text'
78
- ? {
79
- name: string;
80
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
81
- get value(): string | number;
82
- set value(v: string | number);
83
- readonly defaultValue?: string | number;
84
- }
85
- : {
86
- name: string;
87
- type: T;
88
- 'aria-invalid': boolean | 'false' | 'true' | undefined;
89
- get value(): string | number;
90
- set value(v: string | number);
91
- readonly defaultValue?: string | number;
92
- };
93
-
94
- type RemoteFormFieldMethods<T> = {
95
- /** The values that will be submitted */
96
- value(): DeepPartial<T>;
97
- /** Set the values that will be submitted */
98
- set(input: DeepPartial<T>): DeepPartial<T>;
99
- /** Whether the field or any nested field has been interacted with since the form was mounted */
100
- touched(): boolean;
101
- /** Whether the field or any nested field has been edited since the form was mounted */
102
- dirty(): boolean;
103
- /** Validation issues, if any */
104
- issues(): RemoteFormIssue[] | undefined;
105
- };
106
-
107
- // These two types use "T extends unknown ? .. : .." to distribute over unions.
108
- // 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
109
- type KeysOfUnion<T> = T extends unknown ? keyof T : never;
110
- type ValueOfUnionKey<T, K extends PropertyKey> = T extends unknown
111
- ? K extends keyof T
112
- ? T[K]
113
- : never
114
- : never;
115
-
116
- export type RemoteFormFieldValue = string | string[] | number | boolean | File | File[];
8
+ export interface Cookies {
9
+ /**
10
+ * Gets a cookie that was previously set with `cookies.set`, or from the request headers.
11
+ * @param name the name of the cookie
12
+ * @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
13
+ */
14
+ get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined;
117
15
 
118
- type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
119
- ? Value extends string[]
120
- ? [type: Type, value: Value[number] | (string & {})]
121
- : Value extends boolean
122
- ? [type: Type] | [type: Type, value: boolean]
123
- : [type: Type] | [type: Type, value: Value | (string & {})]
124
- : Type extends 'submit' | 'hidden'
125
- ? Value extends string
126
- ? [type: Type, value: Value | (string & {})]
127
- : [type: Type, value: Value]
128
- : Type extends 'radio'
129
- ? [type: Type, value: Value | (string & {})]
130
- : Type extends 'file' | 'file multiple'
131
- ? [type: Type]
132
- : [type: Type] | [type: Type, value: Value | undefined];
16
+ /**
17
+ * Gets all cookies that were previously set with `cookies.set`, or from the request headers.
18
+ * @param opts the options, passed directly to `cookie.parseCookie`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
19
+ */
20
+ getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
133
21
 
134
- /**
135
- * Form field accessor type that provides name(), value(), and issues() methods
136
- */
137
- export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
138
22
  /**
139
- * Returns an object that can be spread onto an input element with the correct type attribute,
140
- * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
141
- * @example
142
- * ```svelte
143
- * <input {...myForm.fields.myString.as('text')} />
144
- * <input {...myForm.fields.myNumber.as('number')} />
145
- * <input {...myForm.fields.myBoolean.as('checkbox')} />
146
- * ```
23
+ * 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.
24
+ *
25
+ * 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.
26
+ *
27
+ * 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.
28
+ * @param name the name of the cookie
29
+ * @param value the cookie value
30
+ * @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)
147
31
  */
148
- as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
149
- };
32
+ set: (name: string, value: string, opts: import('cookie').SerializeOptions) => void;
150
33
 
151
- type RemoteFormFieldContainer<Value> = RemoteFormFieldMethods<Value> & {
152
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
153
- allIssues(): RemoteFormIssue[] | undefined;
154
- };
34
+ /**
35
+ * Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
36
+ *
37
+ * 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.
38
+ *
39
+ * 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.
40
+ * @param name the name of the cookie
41
+ * @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)
42
+ */
43
+ delete: (name: string, opts: import('cookie').SerializeOptions) => void;
155
44
 
156
- type UnknownField<Value> = RemoteFormFieldMethods<Value> & {
157
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
158
- allIssues(): RemoteFormIssue[] | undefined;
159
45
  /**
160
- * Returns an object that can be spread onto an input element with the correct type attribute,
161
- * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters.
162
- * @example
163
- * ```svelte
164
- * <input {...myForm.fields.myString.as('text')} />
165
- * <input {...myForm.fields.myNumber.as('number')} />
166
- * <input {...myForm.fields.myBoolean.as('checkbox')} />
46
+ * Parses a single `Set-Cookie` header. This allows you to apply cookies received from an external source:
47
+ *
48
+ * ```js
49
+ * import { getRequestEvent } from '$app/server';
50
+ *
51
+ * export async function GET() {
52
+ * const { cookies } = getRequestEvent();
53
+ *
54
+ * const response = await fetch('...');
55
+ *
56
+ * for (const str of response.headers.getSetCookie()) {
57
+ * const { name, value, ...options } = cookies.parse(str);
58
+ * cookies.set(name, value, { ...options, path: '/' });
59
+ * }
60
+ *
61
+ * // ...
62
+ * }
167
63
  * ```
64
+ *
65
+ * 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.
168
66
  */
169
- as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
170
- } & {
171
- [key: string | number]: UnknownField<any>;
172
- };
173
-
174
- type RemoteFormFieldsRoot<Input extends RemoteFormInput | void> =
175
- IsAny<Input> extends true
176
- ? RecursiveFormFields
177
- : Input extends void
178
- ? {
179
- /** Validation issues, if any */
180
- issues(): RemoteFormIssue[] | undefined;
181
- /** Validation issues belonging to this or any of the fields that belong to it, if any */
182
- allIssues(): RemoteFormIssue[] | undefined;
183
- }
184
- : RemoteFormFields<Input>;
67
+ parse: typeof import('cookie').parseSetCookie;
185
68
 
186
- /**
187
- * Recursive type to build form fields structure with proxy access
188
- */
189
- export type RemoteFormFields<T> =
190
- WillRecurseIndefinitely<T> extends true
191
- ? RecursiveFormFields
192
- : NonNullable<T> extends string | number | boolean | File
193
- ? RemoteFormField<NonNullable<T>>
194
- : // [NonNullable<T>] is used to prevent distributing over union while still allowing
195
- // nullable wrappers (e.g. `string[] | undefined` from a schema with `.default([])`)
196
- // to be treated as arrays; only the last condition should distribute over unions
197
- [NonNullable<T>] extends [string[] | File[]]
198
- ? RemoteFormField<NonNullable<T>> & {
199
- [K in number]: RemoteFormField<NonNullable<T>[number]>;
200
- }
201
- : [NonNullable<T>] extends [Array<infer U>]
202
- ? RemoteFormFieldContainer<NonNullable<T>> & {
203
- [K in number]: RemoteFormFields<U>;
204
- }
205
- : RemoteFormFieldContainer<T> & {
206
- [K in KeysOfUnion<T>]-?: RemoteFormFields<ValueOfUnionKey<T, K>>;
207
- };
208
-
209
- // By breaking this out into its own type, we avoid the TS recursion depth limit
210
- type RecursiveFormFields = RemoteFormFieldContainer<any> & {
211
- [key: string | number]: UnknownField<any>;
212
- };
213
-
214
- type MaybeArray<T> = T | T[];
215
-
216
- export interface RemoteFormInput {
217
- [key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput> | undefined;
218
- }
219
-
220
- export interface RemoteFormIssue {
221
- message: string;
222
- path: Array<string | number>;
223
- }
224
-
225
- // If the schema specifies `id` as a string or number, ensure that `for(...)`
226
- // only accepts that type. Otherwise, accept `string | number`
227
- type ExtractId<Input> = Input extends { id: infer Id }
228
- ? Id extends string | number
229
- ? Id
230
- : string | number
231
- : string | number;
232
-
233
- /**
234
- * A function and proxy object used to imperatively create validation errors in form handlers.
235
- *
236
- * Access properties to create field-specific issues: `issue.fieldName('message')`.
237
- * The type structure mirrors the input data structure for type-safe field access.
238
- * Call `invalid(issue.foo(...), issue.nested.bar(...))` to throw a validation error.
239
- */
240
- export type InvalidField<T> =
241
- WillRecurseIndefinitely<T> extends true
242
- ? Record<string | number, any>
243
- : NonNullable<T> extends string | number | boolean | File
244
- ? (message: string) => StandardSchemaV1.Issue
245
- : NonNullable<T> extends Array<infer U>
246
- ? {
247
- [K in number]: InvalidField<U>;
248
- } & ((message: string) => StandardSchemaV1.Issue)
249
- : NonNullable<T> extends RemoteFormInput
250
- ? {
251
- [K in keyof T]-?: InvalidField<T[K]>;
252
- } & ((message: string) => StandardSchemaV1.Issue)
253
- : Record<string, never>;
254
-
255
- /**
256
- * A validation error thrown by `invalid`.
257
- */
258
- export interface ValidationError {
259
- /** The validation issues */
260
- issues: StandardSchemaV1.Issue[];
69
+ /**
70
+ * Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
71
+ *
72
+ * 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.
73
+ *
74
+ * 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.
75
+ * @param name the name of the cookie
76
+ * @param value the cookie value
77
+ * @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)
78
+ */
79
+ serialize: (name: string, value: string, opts: import('cookie').SerializeOptions) => string;
261
80
  }
262
81
 
263
- /**
264
- * The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
265
- */
266
- export type RemoteFormEnhanceInstance<
267
- Input extends RemoteFormInput | void = RemoteFormInput | void,
268
- Output = any
269
- > = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
270
- readonly element: HTMLFormElement;
271
- };
272
-
273
- /**
274
- * The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
275
- */
276
- export type RemoteFormEnhanceCallback<
277
- Input extends RemoteFormInput | void = RemoteFormInput | void,
278
- Output = any
279
- > = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
280
-
281
- /**
282
- * The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
283
- */
284
- export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
285
- /** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
286
- [attachment: symbol]: (node: HTMLFormElement) => void;
287
- method: 'POST';
288
- /** The URL to send the form to. */
289
- action: string;
290
- /** The `<form>` element this instance is currently attached to, if any. */
291
- get element(): HTMLFormElement | null;
292
- /** Submit the currently attached form programmatically. */
293
- submit(): Promise<boolean> & {
294
- updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
295
- };
296
- /** Use the `enhance` method to influence what happens when the form is submitted. */
297
- enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
298
- method: 'POST';
299
- action: string;
300
- [attachment: symbol]: (node: HTMLFormElement) => void;
301
- };
82
+ export interface RequestEvent<
83
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
84
+ RouteId extends AppRouteId | null = AppRouteId | null
85
+ > {
302
86
  /**
303
- * Create an instance of the form for the given `id`.
304
- * The `id` is stringified and used for deduplication to potentially reuse existing instances.
305
- * Useful when you have multiple forms that use the same remote form action, for example in a loop.
306
- * ```svelte
307
- * {#each todos as todo}
308
- * {@const todoForm = updateTodo.for(todo.id)}
309
- * <form {...todoForm}>
310
- * {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
311
- * ...
312
- * </form>
313
- * {/each}
314
- * ```
87
+ * Get or set cookies related to the current request
315
88
  */
316
- for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
317
- /** Preflight checks */
318
- preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
319
- /** Validate the form contents programmatically */
320
- validate(options?: {
321
- /**
322
- * Set this to `true` to also show validation issues of fields that haven't yet been
323
- * edited and blurred. This option is ignored for forms that have previously been
324
- * submitted, in which case all fields are always subject to validation
325
- * (unless the form is reset, at which point it is treated as pristine)
326
- */
327
- all?: boolean;
328
- /** Set this to `true` to only run the `preflight` validation. */
329
- preflightOnly?: boolean;
330
- }): Promise<void>;
331
- /** The result of the form submission */
332
- get result(): Output | undefined;
333
- /** The number of pending submissions */
334
- get pending(): number;
335
- /** True if the form has been submitted at least once, and hasn't been reset since */
336
- get submitted(): boolean;
337
- /** Access form fields using object notation */
338
- fields: RemoteFormFieldsRoot<Input>;
339
- };
340
-
341
- /**
342
- * The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
343
- */
344
- export type RemoteCommand<Input, Output> = {
345
- (arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
346
- updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
347
- };
348
- /** The number of pending command executions */
349
- get pending(): number;
350
- };
351
-
352
- export type RemoteQueryUpdate =
353
- | RemoteQuery<any>
354
- | RemoteLiveQuery<any>
355
- | RemoteQueryFunction<any, any>
356
- | RemoteLiveQueryFunction<any, any>
357
- | RemoteQueryOverride;
358
-
359
- export type RemoteResource<T> = Promise<T> & {
360
- /** The error in case the query fails. */
361
- get error(): App.Error | undefined;
362
- /** `true` before the first result is available and during refreshes */
363
- get loading(): boolean;
364
- } & (
365
- | {
366
- /** The current value of the query. Undefined until `ready` is `true` */
367
- get current(): undefined;
368
- ready: false;
369
- }
370
- | {
371
- /** The current value of the query. Undefined until `ready` is `true` */
372
- get current(): T;
373
- ready: true;
374
- }
375
- );
376
-
377
- export type RemoteQuery<T> = RemoteResource<T> & {
89
+ readonly cookies: Cookies;
378
90
  /**
379
- * On the client, this function will update the value of the query without re-fetching it.
91
+ * `fetch` is equivalent to the [native `fetch` web API](https://developer.mozilla.org/en-US/docs/Web/API/fetch), with a few additional features:
92
+ *
93
+ * - It can be used to make credentialed requests on the server, as it inherits the `cookie` and `authorization` headers for the page request.
94
+ * - It can make relative requests on the server (ordinarily, `fetch` requires a URL with an origin when used in a server context).
95
+ * - 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.
96
+ * - 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)
97
+ * - During hydration, the response will be read from the HTML, guaranteeing consistency and preventing an additional network request.
380
98
  *
381
- * 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.
382
- * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
99
+ * You can learn more about making credentialed requests with cookies [here](https://svelte.dev/docs/kit/load#Cookies).
383
100
  */
384
- set(value: T): void;
101
+ readonly fetch: typeof fetch;
385
102
  /**
386
- * On the client, this function will re-fetch the query from the server.
387
- *
388
- * 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.
389
- * This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
103
+ * The client's IP address, set by the adapter.
390
104
  */
391
- refresh(): Promise<void>;
105
+ readonly getClientAddress: () => string;
392
106
  /**
393
- * 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.
394
- *
395
- * ```svelte
396
- * <script>
397
- * import { getTodos, addTodo } from './todos.remote.js';
398
- * const todos = getTodos();
399
- * </script>
107
+ * Contains custom data that was added to the request within the [`server handle hook`](https://svelte.dev/docs/kit/hooks#handle).
108
+ */
109
+ readonly locals: App.Locals;
110
+ /**
111
+ * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
400
112
  *
401
- * <form {...addTodo.enhance(async (form) => {
402
- * await form.submit().updates(
403
- * todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
404
- * );
405
- * })}>
406
- * <input type="text" name="text" />
407
- * <button type="submit">Add Todo</button>
408
- * </form>
409
- * ```
113
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
114
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
115
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
116
+ * 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.
410
117
  */
411
- withOverride(update: (current: T) => T): RemoteQueryOverride;
412
- };
413
-
414
- export type RemoteLiveQuery<T> = RemoteResource<T> &
415
- AsyncIterable<T> & {
416
- /** `true` if the live stream is currently connected. */
417
- readonly connected: boolean;
418
- /** `true` once the current live stream iterator is done. */
419
- readonly done: boolean;
420
- /** Reconnects the live stream immediately. */
421
- reconnect(): Promise<void>;
422
- };
423
-
424
- export type RemoteQueryOverride = () => void;
425
-
426
- /**
427
- * The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
428
- */
429
- export type RemotePrerenderFunction<Input, Output> = (
430
- arg: undefined extends Input ? Input | void : Input
431
- ) => RemoteResource<Output>;
432
-
433
- /**
434
- * The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
435
- *
436
- * The optional `Validated` generic parameter represents the argument type *after* the
437
- * query's schema has validated and (optionally) transformed it — this is the type the
438
- * query's implementation function receives on the server, and the type yielded by
439
- * [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
440
- * with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
441
- * schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
442
- * `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
443
- * without arguments it defaults to `Input`.
444
- */
445
- export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
446
- arg: undefined extends Input ? Input | void : Input
447
- ) => RemoteQuery<Output>;
448
-
449
- /**
450
- * The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
451
- *
452
- * The optional `Validated` generic parameter represents the argument type *after* the
453
- * query's schema has validated and (optionally) transformed it, and matches the type
454
- * yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
455
- */
456
- export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
457
- arg: undefined extends Input ? Input | void : Input
458
- ) => RemoteLiveQuery<Output>;
459
-
460
- /**
461
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
462
- * when called with a regular `query`. `arg` is the validated argument (the input *after*
463
- * the query's schema validated and transformed it, if applicable); `query` is a
464
- * `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
465
- * update the correct client entry.
466
- */
467
- export type RequestedEntry<Validated, Output> = {
468
- arg: Validated;
469
- query: RemoteQuery<Output>;
470
- };
471
-
472
- /**
473
- * A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
474
- * when called with a `query.live`. `arg` is the validated argument; `query` is a
475
- * `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
476
- * the correct client subscription.
477
- */
478
- export type LiveRequestedEntry<Validated, Output> = {
479
- arg: Validated;
480
- query: RemoteLiveQuery<Output>;
481
- };
482
-
483
- export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
484
- AsyncIterable<RequestedEntry<Validated, Output>> & {
118
+ readonly params: Params;
119
+ /**
120
+ * Additional data made available through the adapter.
121
+ */
122
+ readonly platform: Readonly<App.Platform> | undefined;
123
+ /**
124
+ * The original request object.
125
+ */
126
+ readonly request: Request;
127
+ /**
128
+ * Info about the current route.
129
+ */
130
+ readonly route: {
485
131
  /**
486
- * Call `refresh` on all queries selected by this `requested` invocation.
487
- * This is identical to:
488
- * ```ts
489
- * import { requested } from '$app/server';
132
+ * 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.
490
133
  *
491
- * for await (const { query } of requested(getPost, ...)) {
492
- * void query.refresh();
493
- * }
494
- * ```
134
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
135
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
136
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
137
+ * 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.
495
138
  */
496
- refreshAll: () => Promise<void>;
139
+ id: RouteId;
497
140
  };
141
+ /**
142
+ * 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:
143
+ *
144
+ * ```js
145
+ * /// file: src/routes/blog/+page.js
146
+ * export async function load({ fetch, setHeaders }) {
147
+ * const url = `https://cms.example.com/articles.json`;
148
+ * const response = await fetch(url);
149
+ *
150
+ * setHeaders({
151
+ * age: response.headers.get('age'),
152
+ * 'cache-control': response.headers.get('cache-control')
153
+ * });
154
+ *
155
+ * return response.json();
156
+ * }
157
+ * ```
158
+ *
159
+ * Setting the same header multiple times (even in separate `load` functions) is an error — you can only set a given header once.
160
+ *
161
+ * You cannot add a `set-cookie` header with `setHeaders` — use the [`cookies`](https://svelte.dev/docs/kit/$app-server#Cookies) API instead.
162
+ */
163
+ readonly setHeaders: (headers: Record<string, string>) => void;
164
+ /**
165
+ * The requested URL.
166
+ *
167
+ * Inside `query` functions (including `query.batch` and `query.live`), accessing this property throws an error.
168
+ * Pass values from the page as arguments to the query instead. Inside `form` and `command` functions it relates to the page
169
+ * the remote function was called from, _not_ the URL of the endpoint SvelteKit creates for the remote function. Never use it
170
+ * 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.
171
+ */
172
+ readonly url: URL;
173
+ /**
174
+ * `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
175
+ * related to the data request in this case. Use this property instead if the distinction is important to you.
176
+ */
177
+ readonly isDataRequest: boolean;
178
+ /**
179
+ * `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.
180
+ */
181
+ readonly isSubRequest: boolean;
498
182
 
499
- export type LiveQueryRequestedResult<Validated, Output> = Iterable<
500
- LiveRequestedEntry<Validated, Output>
501
- > &
502
- AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
503
- /**
504
- * Call `reconnect` on all live queries selected by this `requested` invocation.
505
- * This is identical to:
506
- * ```ts
507
- * import { requested } from '$app/server';
508
- *
509
- * for await (const { query } of requested(liveQuery, ...)) {
510
- * void query.reconnect();
511
- * }
512
- * ```
513
- */
514
- reconnectAll: () => Promise<void>;
183
+ /**
184
+ * Access to spans for tracing. If tracing is not enabled, these spans will do nothing.
185
+ * @since 2.31.0
186
+ */
187
+ readonly tracing: {
188
+ /** Whether tracing is enabled. */
189
+ enabled: boolean;
190
+ /** The root span for the request. This span is named `sveltekit.handle.root`. */
191
+ root: Span;
192
+ /** The span associated with the current `handle` hook, `load` function, or form action. */
193
+ current: Span;
515
194
  };
516
195
 
517
- export type RequestedResult<Validated, Output> =
518
- | QueryRequestedResult<Validated, Output>
519
- | LiveQueryRequestedResult<Validated, Output>;
196
+ /**
197
+ * `true` if the request comes from the client via a remote function. The `url` property will be stripped of the internal information
198
+ * related to the data request in this case. Use this property instead if the distinction is important to you.
199
+ */
200
+ readonly isRemoteRequest: boolean;
201
+ }