@sveltejs/kit 3.0.0-next.22 → 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.
- package/package.json +1 -5
- package/src/core/postbuild/prerender.js +19 -19
- package/src/exports/index.js +10 -0
- package/src/exports/public.d.ts +9 -0
- package/src/runtime/app/server/public.d.ts +512 -0
- package/src/runtime/app/server/remote/command.js +1 -1
- package/src/runtime/app/server/remote/form.js +5 -5
- package/src/runtime/app/server/remote/prerender.js +1 -1
- package/src/runtime/app/server/remote/query.js +1 -1
- package/src/runtime/app/server/remote/requested.js +3 -3
- package/src/runtime/client/remote-functions/command.svelte.js +1 -1
- package/src/runtime/client/remote-functions/form.svelte.js +1 -1
- package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query/index.js +1 -1
- package/src/runtime/client/remote-functions/query/instance.svelte.js +2 -1
- package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query-live/index.js +1 -1
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +4 -3
- package/src/runtime/client/remote-functions/shared.svelte.js +1 -1
- package/src/runtime/server/remote-functions.js +1 -1
- package/src/types/internal.d.ts +1 -1
- package/src/utils/promise.js +25 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +1100 -1108
- package/types/index.d.ts.map +45 -47
- package/src/exports/remote/index.js +0 -11
- package/src/exports/remote/public.d.ts +0 -519
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.23",
|
|
4
4
|
"description": "SvelteKit is the fastest way to build Svelte apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -129,10 +129,6 @@
|
|
|
129
129
|
"types": "./types/index.d.ts",
|
|
130
130
|
"import": "./src/exports/params/index.js"
|
|
131
131
|
},
|
|
132
|
-
"./remote": {
|
|
133
|
-
"types": "./types/index.d.ts",
|
|
134
|
-
"import": "./src/exports/remote/index.js"
|
|
135
|
-
},
|
|
136
132
|
"./vite": {
|
|
137
133
|
"types": "./types/index.d.ts",
|
|
138
134
|
"import": "./src/exports/vite/index.js"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
|
-
import { clearLine, moveCursor } from 'node:readline';
|
|
5
4
|
import { pathToFileURL } from 'node:url';
|
|
6
5
|
import { walk } from '../../utils/filesystem.js';
|
|
7
6
|
import { posixify } from '../../utils/os.js';
|
|
@@ -283,26 +282,31 @@ async function prerender({
|
|
|
283
282
|
// currently requesting, then clearing the line once the response comes in.
|
|
284
283
|
// This avoids the wall of text that happens when you prerender
|
|
285
284
|
// many pages and log each response
|
|
285
|
+
const { stdout, stderr } = process;
|
|
286
|
+
|
|
286
287
|
let current = false;
|
|
287
|
-
let
|
|
288
|
-
|
|
289
|
-
const
|
|
288
|
+
let needs_newline = true;
|
|
289
|
+
|
|
290
|
+
const write = stdout.write;
|
|
291
|
+
|
|
292
|
+
/** @param {string} value */
|
|
293
|
+
const print = (value) => write.call(stdout, value);
|
|
290
294
|
|
|
291
|
-
/** @type {ProxyHandler<typeof
|
|
292
|
-
const
|
|
295
|
+
/** @type {ProxyHandler<typeof stdout.write>} */
|
|
296
|
+
const intercept = {
|
|
293
297
|
apply(target, this_arg, args) {
|
|
294
298
|
const chunk = args[0];
|
|
295
299
|
if (chunk.length > 0) {
|
|
296
300
|
current = false;
|
|
297
|
-
|
|
301
|
+
needs_newline =
|
|
298
302
|
typeof chunk === 'string' ? !chunk.endsWith('\n') : chunk[chunk.length - 1] !== 10;
|
|
299
303
|
}
|
|
300
304
|
return Reflect.apply(target, this_arg, args);
|
|
301
305
|
}
|
|
302
306
|
};
|
|
303
307
|
|
|
304
|
-
|
|
305
|
-
|
|
308
|
+
stdout.write = new Proxy(stdout.write, intercept);
|
|
309
|
+
stderr.write = new Proxy(stderr.write, intercept);
|
|
306
310
|
|
|
307
311
|
progress = {
|
|
308
312
|
clear: () => {
|
|
@@ -310,25 +314,21 @@ async function prerender({
|
|
|
310
314
|
// the previous progress log, because that will corrupt things
|
|
311
315
|
if (!current) return;
|
|
312
316
|
|
|
313
|
-
|
|
314
|
-
|
|
317
|
+
print('\x1B[1A'); // move cursor to start of progress update
|
|
318
|
+
print('\x1B[2K'); // clear current line
|
|
315
319
|
},
|
|
316
320
|
|
|
317
321
|
update: (path) => {
|
|
318
|
-
if
|
|
319
|
-
|
|
320
|
-
stdout_write.call(process.stdout, '\n');
|
|
321
|
-
}
|
|
322
|
+
// if we're in the middle of a line, start a new one
|
|
323
|
+
if (needs_newline) print('\n');
|
|
322
324
|
|
|
323
|
-
|
|
325
|
+
print(`crawling ${path}\n`);
|
|
324
326
|
current = true;
|
|
325
|
-
|
|
327
|
+
needs_newline = false;
|
|
326
328
|
},
|
|
327
329
|
|
|
328
330
|
updated: 0
|
|
329
331
|
};
|
|
330
|
-
|
|
331
|
-
console.log('');
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
/** @type {Set<string>} */
|
package/src/exports/index.js
CHANGED
|
@@ -270,6 +270,16 @@ export function invalid(...issues) {
|
|
|
270
270
|
);
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Checks whether this is a validation error thrown by {@link invalid}.
|
|
275
|
+
* @param {unknown} e The object to check.
|
|
276
|
+
* @return {e is import('./public.js').ValidationError}
|
|
277
|
+
* @since 2.47.3
|
|
278
|
+
*/
|
|
279
|
+
export function isValidationError(e) {
|
|
280
|
+
return e instanceof ValidationError;
|
|
281
|
+
}
|
|
282
|
+
|
|
273
283
|
/**
|
|
274
284
|
* Strips possible SvelteKit-internal suffixes and trailing slashes from the URL pathname.
|
|
275
285
|
* Returns the normalized URL as well as a method for adding the potential suffix back
|
package/src/exports/public.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { BuildData, SSRNodeLoader, SSRRoute, ValidatedConfig } from 'types';
|
|
|
16
16
|
import { Plugin } from 'vite';
|
|
17
17
|
import { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
|
|
18
18
|
import { ParamMatcher } from '@sveltejs/kit/params';
|
|
19
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
19
20
|
|
|
20
21
|
export { PrerenderOption } from '../types/private.js';
|
|
21
22
|
|
|
@@ -99,6 +100,14 @@ export interface ActionFailure<T = undefined> {
|
|
|
99
100
|
[uniqueSymbol]: true; // necessary or else UnpackValidationError could wrongly unpack objects with the same shape as ActionFailure
|
|
100
101
|
}
|
|
101
102
|
|
|
103
|
+
/**
|
|
104
|
+
* A validation error thrown by `invalid`.
|
|
105
|
+
*/
|
|
106
|
+
export interface ValidationError {
|
|
107
|
+
/** The validation issues */
|
|
108
|
+
issues: StandardSchemaV1.Issue[];
|
|
109
|
+
}
|
|
110
|
+
|
|
102
111
|
type UnpackValidationError<T> =
|
|
103
112
|
T extends ActionFailure<infer X>
|
|
104
113
|
? X
|
|
@@ -1 +1,513 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { DeepPartial, IsAny, MaybePromise } from 'types';
|
|
3
|
+
|
|
1
4
|
export * from './index.js';
|
|
5
|
+
|
|
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;
|
|
8
|
+
|
|
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[];
|
|
117
|
+
|
|
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];
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Form field accessor type that provides name(), value(), and issues() methods
|
|
136
|
+
*/
|
|
137
|
+
export type RemoteFormField<Value extends RemoteFormFieldValue> = RemoteFormFieldMethods<Value> & {
|
|
138
|
+
/**
|
|
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
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
as<T extends RemoteFormFieldType<Value>>(...args: AsArgs<T, Value>): InputElementProps<T>;
|
|
149
|
+
};
|
|
150
|
+
|
|
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
|
+
};
|
|
155
|
+
|
|
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
|
+
/**
|
|
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')} />
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
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>;
|
|
185
|
+
|
|
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 RemoteFormInvalidField<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]: RemoteFormInvalidField<U>;
|
|
248
|
+
} & ((message: string) => StandardSchemaV1.Issue)
|
|
249
|
+
: NonNullable<T> extends RemoteFormInput
|
|
250
|
+
? {
|
|
251
|
+
[K in keyof T]-?: RemoteFormInvalidField<T[K]>;
|
|
252
|
+
} & ((message: string) => StandardSchemaV1.Issue)
|
|
253
|
+
: Record<string, never>;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* The form instance as received inside an `enhance` callback. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
257
|
+
*/
|
|
258
|
+
export type RemoteFormEnhanceInstance<
|
|
259
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
260
|
+
Output = any
|
|
261
|
+
> = Omit<RemoteForm<Input, Output>, 'enhance' | 'element'> & {
|
|
262
|
+
readonly element: HTMLFormElement;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* The callback passed to a remote form's `enhance` method. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
267
|
+
*/
|
|
268
|
+
export type RemoteFormEnhanceCallback<
|
|
269
|
+
Input extends RemoteFormInput | void = RemoteFormInput | void,
|
|
270
|
+
Output = any
|
|
271
|
+
> = (form: RemoteFormEnhanceInstance<Input, Output>) => MaybePromise<void>;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
275
|
+
*/
|
|
276
|
+
export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
277
|
+
/** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
|
|
278
|
+
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
279
|
+
method: 'POST';
|
|
280
|
+
/** The URL to send the form to. */
|
|
281
|
+
action: string;
|
|
282
|
+
/** The `<form>` element this instance is currently attached to, if any. */
|
|
283
|
+
get element(): HTMLFormElement | null;
|
|
284
|
+
/** Submit the currently attached form programmatically. */
|
|
285
|
+
submit(): Promise<boolean> & {
|
|
286
|
+
updates: (...updates: RemoteQueryUpdate[]) => Promise<boolean>;
|
|
287
|
+
};
|
|
288
|
+
/** Use the `enhance` method to influence what happens when the form is submitted. */
|
|
289
|
+
enhance(callback: RemoteFormEnhanceCallback<Input, Output>): {
|
|
290
|
+
method: 'POST';
|
|
291
|
+
action: string;
|
|
292
|
+
[attachment: symbol]: (node: HTMLFormElement) => void;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Create an instance of the form for the given `id`.
|
|
296
|
+
* The `id` is stringified and used for deduplication to potentially reuse existing instances.
|
|
297
|
+
* Useful when you have multiple forms that use the same remote form action, for example in a loop.
|
|
298
|
+
* ```svelte
|
|
299
|
+
* {#each todos as todo}
|
|
300
|
+
* {const todoForm = updateTodo.for(todo.id)}
|
|
301
|
+
* <form {...todoForm}>
|
|
302
|
+
* {#if todoForm.result?.invalid}<p>Invalid data</p>{/if}
|
|
303
|
+
* ...
|
|
304
|
+
* </form>
|
|
305
|
+
* {/each}
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
for(id: ExtractId<Input>): Omit<RemoteForm<Input, Output>, 'for'>;
|
|
309
|
+
/** Preflight checks */
|
|
310
|
+
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
|
|
311
|
+
/** Validate the form contents programmatically */
|
|
312
|
+
validate(options?: {
|
|
313
|
+
/**
|
|
314
|
+
* Set this to `true` to also show validation issues of fields that haven't yet been
|
|
315
|
+
* edited and blurred. This option is ignored for forms that have previously been
|
|
316
|
+
* submitted, in which case all fields are always subject to validation
|
|
317
|
+
* (unless the form is reset, at which point it is treated as pristine)
|
|
318
|
+
*/
|
|
319
|
+
all?: boolean;
|
|
320
|
+
/** Set this to `true` to only run the `preflight` validation. */
|
|
321
|
+
preflightOnly?: boolean;
|
|
322
|
+
}): Promise<void>;
|
|
323
|
+
/** The result of the form submission */
|
|
324
|
+
get result(): Output | undefined;
|
|
325
|
+
/** The number of pending submissions */
|
|
326
|
+
get pending(): number;
|
|
327
|
+
/** True if the form has been submitted at least once, and hasn't been reset since */
|
|
328
|
+
get submitted(): boolean;
|
|
329
|
+
/** Access form fields using object notation */
|
|
330
|
+
fields: RemoteFormFieldsRoot<Input>;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
|
|
335
|
+
*/
|
|
336
|
+
export type RemoteCommand<Input, Output> = {
|
|
337
|
+
(arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
|
|
338
|
+
updates(...updates: RemoteQueryUpdate[]): Promise<Output>;
|
|
339
|
+
};
|
|
340
|
+
/** The number of pending command executions */
|
|
341
|
+
get pending(): number;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export type RemoteQueryUpdate =
|
|
345
|
+
| RemoteQuery<any>
|
|
346
|
+
| RemoteLiveQuery<any>
|
|
347
|
+
| RemoteQueryFunction<any, any>
|
|
348
|
+
| RemoteLiveQueryFunction<any, any>
|
|
349
|
+
| RemoteQueryOverride;
|
|
350
|
+
|
|
351
|
+
export type RemoteResource<T> = Promise<T> & {
|
|
352
|
+
/** The error in case the query fails. */
|
|
353
|
+
get error(): App.Error | undefined;
|
|
354
|
+
/** `true` before the first result is available and during refreshes */
|
|
355
|
+
get loading(): boolean;
|
|
356
|
+
} & (
|
|
357
|
+
| {
|
|
358
|
+
/** The current value of the query. Undefined until `ready` is `true` */
|
|
359
|
+
get current(): undefined;
|
|
360
|
+
ready: false;
|
|
361
|
+
}
|
|
362
|
+
| {
|
|
363
|
+
/** The current value of the query. Undefined until `ready` is `true` */
|
|
364
|
+
get current(): T;
|
|
365
|
+
ready: true;
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
export type RemoteQuery<T> = RemoteResource<T> & {
|
|
370
|
+
/**
|
|
371
|
+
* On the client, this function will update the value of the query without re-fetching it.
|
|
372
|
+
*
|
|
373
|
+
* 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.
|
|
374
|
+
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
|
|
375
|
+
*/
|
|
376
|
+
set(value: T): void;
|
|
377
|
+
/**
|
|
378
|
+
* On the client, this function will re-fetch the query from the server.
|
|
379
|
+
*
|
|
380
|
+
* 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.
|
|
381
|
+
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
|
|
382
|
+
*/
|
|
383
|
+
refresh(): Promise<void>;
|
|
384
|
+
/**
|
|
385
|
+
* 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.
|
|
386
|
+
*
|
|
387
|
+
* ```svelte
|
|
388
|
+
* <script>
|
|
389
|
+
* import { getTodos, addTodo } from './todos.remote.js';
|
|
390
|
+
* const todos = getTodos();
|
|
391
|
+
* </script>
|
|
392
|
+
*
|
|
393
|
+
* <form {...addTodo.enhance(async (form) => {
|
|
394
|
+
* await form.submit().updates(
|
|
395
|
+
* todos.withOverride((todos) => [...todos, { text: form.fields.text.value() }])
|
|
396
|
+
* );
|
|
397
|
+
* })}>
|
|
398
|
+
* <input type="text" name="text" />
|
|
399
|
+
* <button type="submit">Add Todo</button>
|
|
400
|
+
* </form>
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
withOverride(update: (current: T) => T): RemoteQueryOverride;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
export type RemoteLiveQuery<T> = RemoteResource<T> &
|
|
407
|
+
AsyncIterable<T> & {
|
|
408
|
+
/** `true` if the live stream is currently connected. */
|
|
409
|
+
readonly connected: boolean;
|
|
410
|
+
/** `true` once the current live stream iterator is done. */
|
|
411
|
+
readonly done: boolean;
|
|
412
|
+
/** Reconnects the live stream immediately. */
|
|
413
|
+
reconnect(): Promise<void>;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
export type RemoteQueryOverride = () => void;
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
|
|
420
|
+
*/
|
|
421
|
+
export type RemotePrerenderFunction<Input, Output> = (
|
|
422
|
+
arg: undefined extends Input ? Input | void : Input
|
|
423
|
+
) => RemoteResource<Output>;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* The return value of a remote `query` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query) for full documentation.
|
|
427
|
+
*
|
|
428
|
+
* The optional `Validated` generic parameter represents the argument type *after* the
|
|
429
|
+
* query's schema has validated and (optionally) transformed it — this is the type the
|
|
430
|
+
* query's implementation function receives on the server, and the type yielded by
|
|
431
|
+
* [`requested`](https://svelte.dev/docs/kit/$app-server#requested). For queries declared
|
|
432
|
+
* with [Standard Schema](https://standardschema.dev/) it differs from `Input` when the
|
|
433
|
+
* schema contains a transform (e.g. `v.pipe(v.number(), v.transform(String))` has
|
|
434
|
+
* `Input = number` but `Validated = string`). For `'unchecked'` validators and queries
|
|
435
|
+
* without arguments it defaults to `Input`.
|
|
436
|
+
*/
|
|
437
|
+
export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
|
|
438
|
+
arg: undefined extends Input ? Input | void : Input
|
|
439
|
+
) => RemoteQuery<Output>;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
|
|
443
|
+
*
|
|
444
|
+
* The optional `Validated` generic parameter represents the argument type *after* the
|
|
445
|
+
* query's schema has validated and (optionally) transformed it, and matches the type
|
|
446
|
+
* yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
|
|
447
|
+
*/
|
|
448
|
+
export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
|
|
449
|
+
arg: undefined extends Input ? Input | void : Input
|
|
450
|
+
) => RemoteLiveQuery<Output>;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
454
|
+
* when called with a regular `query`. `arg` is the validated argument (the input *after*
|
|
455
|
+
* the query's schema validated and transformed it, if applicable); `query` is a
|
|
456
|
+
* `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
|
|
457
|
+
* update the correct client entry.
|
|
458
|
+
*/
|
|
459
|
+
export type RequestedEntry<Validated, Output> = {
|
|
460
|
+
arg: Validated;
|
|
461
|
+
query: RemoteQuery<Output>;
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
466
|
+
* when called with a `query.live`. `arg` is the validated argument; `query` is a
|
|
467
|
+
* `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
|
|
468
|
+
* the correct client subscription.
|
|
469
|
+
*/
|
|
470
|
+
export type RemoteLiveQueryRequestedEntry<Validated, Output> = {
|
|
471
|
+
arg: Validated;
|
|
472
|
+
query: RemoteLiveQuery<Output>;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
export type RemoteQueryRequestedResult<Validated, Output> = Iterable<
|
|
476
|
+
RequestedEntry<Validated, Output>
|
|
477
|
+
> &
|
|
478
|
+
AsyncIterable<RequestedEntry<Validated, Output>> & {
|
|
479
|
+
/**
|
|
480
|
+
* Call `refresh` on all queries selected by this `requested` invocation.
|
|
481
|
+
* This is identical to:
|
|
482
|
+
* ```ts
|
|
483
|
+
* import { requested } from '$app/server';
|
|
484
|
+
*
|
|
485
|
+
* for await (const { query } of requested(getPost, ...)) {
|
|
486
|
+
* void query.refresh();
|
|
487
|
+
* }
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
refreshAll: () => Promise<void>;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
export type RemoteLiveQueryRequestedResult<Validated, Output> = Iterable<
|
|
494
|
+
RemoteLiveQueryRequestedEntry<Validated, Output>
|
|
495
|
+
> &
|
|
496
|
+
AsyncIterable<RemoteLiveQueryRequestedEntry<Validated, Output>> & {
|
|
497
|
+
/**
|
|
498
|
+
* Call `reconnect` on all live queries selected by this `requested` invocation.
|
|
499
|
+
* This is identical to:
|
|
500
|
+
* ```ts
|
|
501
|
+
* import { requested } from '$app/server';
|
|
502
|
+
*
|
|
503
|
+
* for await (const { query } of requested(liveQuery, ...)) {
|
|
504
|
+
* void query.reconnect();
|
|
505
|
+
* }
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
reconnectAll: () => Promise<void>;
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
export type RequestedResult<Validated, Output> =
|
|
512
|
+
| RemoteQueryRequestedResult<Validated, Output>
|
|
513
|
+
| RemoteLiveQueryRequestedResult<Validated, Output>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @import { RemoteCommand } from '
|
|
1
|
+
/** @import { RemoteCommand } from '$app/server' */
|
|
2
2
|
/** @import { MaybePromise, RemoteCommandInternals } from 'types' */
|
|
3
3
|
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
4
4
|
import { get_request_store } from '@sveltejs/kit/internal/server';
|