@sveltejs/kit 2.58.0 → 2.59.1
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 -1
- package/src/exports/internal/remote-functions.js +1 -1
- package/src/exports/public.d.ts +77 -10
- package/src/exports/vite/dev/index.js +1 -1
- package/src/runtime/app/server/remote/command.js +7 -6
- package/src/runtime/app/server/remote/form.js +2 -1
- package/src/runtime/app/server/remote/query.js +304 -75
- package/src/runtime/app/server/remote/requested.js +109 -20
- package/src/runtime/app/server/remote/shared.js +84 -9
- package/src/runtime/client/client.js +92 -62
- package/src/runtime/client/ndjson.js +42 -0
- package/src/runtime/client/remote-functions/command.svelte.js +6 -1
- package/src/runtime/client/remote-functions/form.svelte.js +23 -6
- package/src/runtime/client/remote-functions/index.js +3 -1
- package/src/runtime/client/remote-functions/query-batch.svelte.js +105 -0
- package/src/runtime/client/remote-functions/query-live.svelte.js +636 -0
- package/src/runtime/client/remote-functions/query.svelte.js +15 -115
- package/src/runtime/client/remote-functions/shared.svelte.js +76 -23
- package/src/runtime/form-utils.js +31 -10
- package/src/runtime/server/page/load_data.js +4 -2
- package/src/runtime/server/page/render.js +4 -1
- package/src/runtime/server/remote.js +117 -9
- package/src/runtime/server/respond.js +1 -0
- package/src/runtime/shared.js +2 -2
- package/src/runtime/utils.js +0 -1
- package/src/types/internal.d.ts +45 -13
- package/src/version.js +1 -1
- package/types/index.d.ts +137 -15
- package/types/index.d.ts.map +7 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @import { RemoteInternals } from 'types' */
|
|
2
2
|
|
|
3
3
|
/** @type {RemoteInternals['type'][]} */
|
|
4
|
-
const types = ['command', 'form', 'prerender', 'query', 'query_batch'];
|
|
4
|
+
const types = ['command', 'form', 'prerender', 'query', 'query_batch', 'query_live'];
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {Record<string, any>} module
|
package/src/exports/public.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface Adapter {
|
|
|
52
52
|
supports?: {
|
|
53
53
|
/**
|
|
54
54
|
* Test support for `read` from `$app/server`.
|
|
55
|
-
* @param details.config The merged route config
|
|
55
|
+
* @param details.config The merged adapter-specific route config exported from the route with `export const config`
|
|
56
56
|
*/
|
|
57
57
|
read?: (details: { config: any; route: { id: string } }) => boolean;
|
|
58
58
|
|
|
@@ -1453,17 +1453,29 @@ export interface Page<
|
|
|
1453
1453
|
export type ParamMatcher = (param: string) => boolean;
|
|
1454
1454
|
|
|
1455
1455
|
/**
|
|
1456
|
-
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
1457
|
-
* `arg` is the validated argument (the input *after*
|
|
1458
|
-
* transformed it, if applicable); `query` is a
|
|
1459
|
-
* original cache key, so `refresh()` / `set()` will
|
|
1456
|
+
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
1457
|
+
* when called with a regular `query`. `arg` is the validated argument (the input *after*
|
|
1458
|
+
* the query's schema validated and transformed it, if applicable); `query` is a
|
|
1459
|
+
* `RemoteQuery` bound to the client's original cache key, so `refresh()` / `set()` will
|
|
1460
|
+
* update the correct client entry.
|
|
1460
1461
|
*/
|
|
1461
1462
|
export type RequestedEntry<Validated, Output> = {
|
|
1462
1463
|
arg: Validated;
|
|
1463
1464
|
query: RemoteQuery<Output>;
|
|
1464
1465
|
};
|
|
1465
1466
|
|
|
1466
|
-
|
|
1467
|
+
/**
|
|
1468
|
+
* A single entry yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested)
|
|
1469
|
+
* when called with a `query.live`. `arg` is the validated argument; `query` is a
|
|
1470
|
+
* `RemoteLiveQuery` bound to the client's original cache key, so `reconnect()` targets
|
|
1471
|
+
* the correct client subscription.
|
|
1472
|
+
*/
|
|
1473
|
+
export type LiveRequestedEntry<Validated, Output> = {
|
|
1474
|
+
arg: Validated;
|
|
1475
|
+
query: RemoteLiveQuery<Output>;
|
|
1476
|
+
};
|
|
1477
|
+
|
|
1478
|
+
export type QueryRequestedResult<Validated, Output> = Iterable<RequestedEntry<Validated, Output>> &
|
|
1467
1479
|
AsyncIterable<RequestedEntry<Validated, Output>> & {
|
|
1468
1480
|
/**
|
|
1469
1481
|
* Call `refresh` on all queries selected by this `requested` invocation.
|
|
@@ -1479,6 +1491,28 @@ export type RequestedResult<Validated, Output> = Iterable<RequestedEntry<Validat
|
|
|
1479
1491
|
refreshAll: () => Promise<void>;
|
|
1480
1492
|
};
|
|
1481
1493
|
|
|
1494
|
+
export type LiveQueryRequestedResult<Validated, Output> = Iterable<
|
|
1495
|
+
LiveRequestedEntry<Validated, Output>
|
|
1496
|
+
> &
|
|
1497
|
+
AsyncIterable<LiveRequestedEntry<Validated, Output>> & {
|
|
1498
|
+
/**
|
|
1499
|
+
* Call `reconnect` on all live queries selected by this `requested` invocation.
|
|
1500
|
+
* This is identical to:
|
|
1501
|
+
* ```ts
|
|
1502
|
+
* import { requested } from '$app/server';
|
|
1503
|
+
*
|
|
1504
|
+
* for await (const { query } of requested(liveQuery, ...)) {
|
|
1505
|
+
* void query.reconnect();
|
|
1506
|
+
* }
|
|
1507
|
+
* ```
|
|
1508
|
+
*/
|
|
1509
|
+
reconnectAll: () => Promise<void>;
|
|
1510
|
+
};
|
|
1511
|
+
|
|
1512
|
+
export type RequestedResult<Validated, Output> =
|
|
1513
|
+
| QueryRequestedResult<Validated, Output>
|
|
1514
|
+
| LiveQueryRequestedResult<Validated, Output>;
|
|
1515
|
+
|
|
1482
1516
|
export interface RequestEvent<
|
|
1483
1517
|
Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
|
|
1484
1518
|
RouteId extends AppRouteId | null = AppRouteId | null
|
|
@@ -1895,6 +1929,7 @@ type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'r
|
|
|
1895
1929
|
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1896
1930
|
get checked(): boolean;
|
|
1897
1931
|
set checked(value: boolean);
|
|
1932
|
+
readonly defaultChecked?: boolean;
|
|
1898
1933
|
}
|
|
1899
1934
|
: T extends 'file'
|
|
1900
1935
|
? {
|
|
@@ -1925,6 +1960,7 @@ type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'r
|
|
|
1925
1960
|
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1926
1961
|
get value(): string | number;
|
|
1927
1962
|
set value(v: string | number);
|
|
1963
|
+
readonly defaultValue?: string | number;
|
|
1928
1964
|
}
|
|
1929
1965
|
: {
|
|
1930
1966
|
name: string;
|
|
@@ -1932,6 +1968,7 @@ type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'r
|
|
|
1932
1968
|
'aria-invalid': boolean | 'false' | 'true' | undefined;
|
|
1933
1969
|
get value(): string | number;
|
|
1934
1970
|
set value(v: string | number);
|
|
1971
|
+
readonly defaultValue?: string | number;
|
|
1935
1972
|
};
|
|
1936
1973
|
|
|
1937
1974
|
type RemoteFormFieldMethods<T> = {
|
|
@@ -1957,7 +1994,9 @@ export type RemoteFormFieldValue = string | string[] | number | boolean | File |
|
|
|
1957
1994
|
type AsArgs<Type extends keyof InputTypeMap, Value> = Type extends 'checkbox'
|
|
1958
1995
|
? Value extends string[]
|
|
1959
1996
|
? [type: Type, value: Value[number] | (string & {})]
|
|
1960
|
-
:
|
|
1997
|
+
: Value extends boolean
|
|
1998
|
+
? [type: Type] | [type: Type, value: boolean]
|
|
1999
|
+
: [type: Type] | [type: Type, value: Value | (string & {})]
|
|
1961
2000
|
: Type extends 'radio' | 'submit' | 'hidden'
|
|
1962
2001
|
? [type: Type, value: Value | (string & {})]
|
|
1963
2002
|
: Type extends 'file' | 'file multiple'
|
|
@@ -2094,7 +2133,7 @@ export interface ValidationError {
|
|
|
2094
2133
|
}
|
|
2095
2134
|
|
|
2096
2135
|
/**
|
|
2097
|
-
* The
|
|
2136
|
+
* The type of a remote `form` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#form) for full documentation.
|
|
2098
2137
|
*/
|
|
2099
2138
|
export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
2100
2139
|
/** Attachment that sets up an event handler that intercepts the form submission on the client to prevent a full page reload */
|
|
@@ -2149,7 +2188,7 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
|
|
|
2149
2188
|
};
|
|
2150
2189
|
|
|
2151
2190
|
/**
|
|
2152
|
-
* The
|
|
2191
|
+
* The type of a remote `command` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#command) for full documentation.
|
|
2153
2192
|
*/
|
|
2154
2193
|
export type RemoteCommand<Input, Output> = {
|
|
2155
2194
|
(arg: undefined extends Input ? Input | void : Input): Promise<Output> & {
|
|
@@ -2161,7 +2200,9 @@ export type RemoteCommand<Input, Output> = {
|
|
|
2161
2200
|
|
|
2162
2201
|
export type RemoteQueryUpdate =
|
|
2163
2202
|
| RemoteQuery<any>
|
|
2203
|
+
| RemoteLiveQuery<any>
|
|
2164
2204
|
| RemoteQueryFunction<any, any>
|
|
2205
|
+
| RemoteLiveQueryFunction<any, any>
|
|
2165
2206
|
| RemoteQueryOverride;
|
|
2166
2207
|
|
|
2167
2208
|
export type RemoteResource<T> = Promise<T> & {
|
|
@@ -2225,10 +2266,25 @@ export type RemoteQuery<T> = RemoteResource<T> & {
|
|
|
2225
2266
|
withOverride(update: (current: T) => T): RemoteQueryOverride;
|
|
2226
2267
|
};
|
|
2227
2268
|
|
|
2269
|
+
export type RemoteLiveQuery<T> = RemoteResource<T> & {
|
|
2270
|
+
/**
|
|
2271
|
+
* Returns an async iterator with live updates.
|
|
2272
|
+
* Unlike awaiting the resource directly, this can only be used _outside_ render
|
|
2273
|
+
* (i.e. in load functions, event handlers and so on)
|
|
2274
|
+
*/
|
|
2275
|
+
run(): AsyncGenerator<T>;
|
|
2276
|
+
/** `true` if the live stream is currently connected. */
|
|
2277
|
+
readonly connected: boolean;
|
|
2278
|
+
/** `true` once the current live stream iterator is done. */
|
|
2279
|
+
readonly done: boolean;
|
|
2280
|
+
/** Reconnects the live stream immediately. */
|
|
2281
|
+
reconnect(): Promise<void>;
|
|
2282
|
+
};
|
|
2283
|
+
|
|
2228
2284
|
export type RemoteQueryOverride = () => void;
|
|
2229
2285
|
|
|
2230
2286
|
/**
|
|
2231
|
-
* The
|
|
2287
|
+
* The type of a remote `prerender` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#prerender) for full documentation.
|
|
2232
2288
|
*/
|
|
2233
2289
|
export type RemotePrerenderFunction<Input, Output> = (
|
|
2234
2290
|
arg: undefined extends Input ? Input | void : Input
|
|
@@ -2250,4 +2306,15 @@ export type RemoteQueryFunction<Input, Output, _Validated = Input> = (
|
|
|
2250
2306
|
arg: undefined extends Input ? Input | void : Input
|
|
2251
2307
|
) => RemoteQuery<Output>;
|
|
2252
2308
|
|
|
2309
|
+
/**
|
|
2310
|
+
* The type of a remote `query.live` function. See [Remote functions](https://svelte.dev/docs/kit/remote-functions#query.live) for full documentation.
|
|
2311
|
+
*
|
|
2312
|
+
* The optional `Validated` generic parameter represents the argument type *after* the
|
|
2313
|
+
* query's schema has validated and (optionally) transformed it, and matches the type
|
|
2314
|
+
* yielded by [`requested`](https://svelte.dev/docs/kit/$app-server#requested).
|
|
2315
|
+
*/
|
|
2316
|
+
export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
|
|
2317
|
+
arg: undefined extends Input ? Input | void : Input
|
|
2318
|
+
) => RemoteLiveQuery<Output>;
|
|
2319
|
+
|
|
2253
2320
|
export * from './index.js';
|
|
@@ -101,7 +101,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
101
101
|
|
|
102
102
|
/** @param {string} id */
|
|
103
103
|
async function resolve(id) {
|
|
104
|
-
const url = id.startsWith('..') ? to_fs(path.
|
|
104
|
+
const url = id.startsWith('..') ? to_fs(path.resolve(id)) : `/${id}`;
|
|
105
105
|
|
|
106
106
|
const module = await loud_ssr_load_module(url);
|
|
107
107
|
|
|
@@ -12,7 +12,7 @@ import { MUTATIVE_METHODS } from '../../../../constants.js';
|
|
|
12
12
|
*
|
|
13
13
|
* @template Output
|
|
14
14
|
* @overload
|
|
15
|
-
* @param {() => Output} fn
|
|
15
|
+
* @param {() => MaybePromise<Output>} fn
|
|
16
16
|
* @returns {RemoteCommand<void, Output>}
|
|
17
17
|
* @since 2.27
|
|
18
18
|
*/
|
|
@@ -25,7 +25,7 @@ import { MUTATIVE_METHODS } from '../../../../constants.js';
|
|
|
25
25
|
* @template Output
|
|
26
26
|
* @overload
|
|
27
27
|
* @param {'unchecked'} validate
|
|
28
|
-
* @param {(arg: Input) => Output} fn
|
|
28
|
+
* @param {(arg: Input) => MaybePromise<Output>} fn
|
|
29
29
|
* @returns {RemoteCommand<Input, Output>}
|
|
30
30
|
* @since 2.27
|
|
31
31
|
*/
|
|
@@ -38,7 +38,7 @@ import { MUTATIVE_METHODS } from '../../../../constants.js';
|
|
|
38
38
|
* @template Output
|
|
39
39
|
* @overload
|
|
40
40
|
* @param {Schema} validate
|
|
41
|
-
* @param {(arg: StandardSchemaV1.InferOutput<Schema>) => Output} fn
|
|
41
|
+
* @param {(arg: StandardSchemaV1.InferOutput<Schema>) => MaybePromise<Output>} fn
|
|
42
42
|
* @returns {RemoteCommand<StandardSchemaV1.InferInput<Schema>, Output>}
|
|
43
43
|
* @since 2.27
|
|
44
44
|
*/
|
|
@@ -46,13 +46,13 @@ import { MUTATIVE_METHODS } from '../../../../constants.js';
|
|
|
46
46
|
* @template Input
|
|
47
47
|
* @template Output
|
|
48
48
|
* @param {any} validate_or_fn
|
|
49
|
-
* @param {(arg?: Input) => Output} [maybe_fn]
|
|
49
|
+
* @param {(arg?: Input) => MaybePromise<Output>} [maybe_fn]
|
|
50
50
|
* @returns {RemoteCommand<Input, Output>}
|
|
51
51
|
* @since 2.27
|
|
52
52
|
*/
|
|
53
53
|
/*@__NO_SIDE_EFFECTS__*/
|
|
54
54
|
export function command(validate_or_fn, maybe_fn) {
|
|
55
|
-
/** @type {(arg?: Input) => Output} */
|
|
55
|
+
/** @type {(arg?: Input) => MaybePromise<Output>} */
|
|
56
56
|
const fn = maybe_fn ?? validate_or_fn;
|
|
57
57
|
|
|
58
58
|
/** @type {(arg?: any) => MaybePromise<Input>} */
|
|
@@ -77,7 +77,8 @@ export function command(validate_or_fn, maybe_fn) {
|
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
state.remote.refreshes ??=
|
|
80
|
+
state.remote.refreshes ??= new Map();
|
|
81
|
+
state.remote.reconnects ??= new Map();
|
|
81
82
|
|
|
82
83
|
const promise = Promise.resolve(
|
|
83
84
|
run_remote_function(event, state, true, () => validate(arg), fn)
|