@molecule/app-query-svelte 1.1.0 → 1.3.0
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/README.md +96 -1
- package/dist/QueryContent.svelte +3 -0
- package/dist/QueryContent.svelte.d.ts.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/list-query.d.ts +57 -0
- package/dist/list-query.d.ts.map +1 -0
- package/dist/list-query.js +50 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-16T21:21:19.334Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-query-svelte
|
|
@@ -333,6 +333,8 @@ interface QueryResource<T, Create = Partial<T>, Update = Partial<T>> {
|
|
|
333
333
|
/**
|
|
334
334
|
* `useQuery` options for the collection. `viewer` is who the answer is for (the signed-in id,
|
|
335
335
|
* or `'anonymous'`); a page or filter change keeps the rows on screen until the next answer.
|
|
336
|
+
* One record per URL identity, retaining the first occurrence. Equal values without an
|
|
337
|
+
* addressable id remain separate. Writes already refresh the collection.
|
|
336
338
|
*/
|
|
337
339
|
list(viewer: string, params?: Record<string, unknown>): QueryOptions<T[]>
|
|
338
340
|
/**
|
|
@@ -374,6 +376,39 @@ interface QueryResource<T, Create = Partial<T>, Update = Partial<T>> {
|
|
|
374
376
|
}
|
|
375
377
|
```
|
|
376
378
|
|
|
379
|
+
#### `ListQueryRoute`
|
|
380
|
+
|
|
381
|
+
The list route a list query reads: `useListRoute` from `@molecule/app-svelte` returns these
|
|
382
|
+
stores (and more), so its result is passed as it is.
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
interface ListQueryRoute<Filter extends string = string> {
|
|
386
|
+
/** False while a protected view waits for auth, is signed out, or is unavailable. */
|
|
387
|
+
readonly canLoad: Readable<boolean>
|
|
388
|
+
/** The current URL filter values. */
|
|
389
|
+
readonly filters: Readable<Readonly<Record<Filter, string | undefined>>>
|
|
390
|
+
/** The configured items per page. */
|
|
391
|
+
readonly pageSize: Readable<number>
|
|
392
|
+
/** The zero-indexed item offset for the API request. */
|
|
393
|
+
readonly offset: Readable<number>
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
#### `ListQueryState`
|
|
398
|
+
|
|
399
|
+
The route's current values, as `read` receives them.
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
interface ListQueryState<Filter extends string = string> {
|
|
403
|
+
/** The current URL filter values. */
|
|
404
|
+
readonly filters: Readonly<Record<Filter, string | undefined>>
|
|
405
|
+
/** The configured items per page. */
|
|
406
|
+
readonly pageSize: number
|
|
407
|
+
/** The zero-indexed item offset for the API request. */
|
|
408
|
+
readonly offset: number
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
377
412
|
#### `UseQueryResult`
|
|
378
413
|
|
|
379
414
|
A mounted query's state and its explicit cache and refresh actions. The
|
|
@@ -409,6 +444,16 @@ A loaded document owns its controls; absent documents expose only status content
|
|
|
409
444
|
|
|
410
445
|
```typescript
|
|
411
446
|
interface QueryContentProps<T> {
|
|
447
|
+
/**
|
|
448
|
+
* One optional empty branch, exclusive with children. The pure predicate reads the
|
|
449
|
+
* loaded document (an array or an application-owned envelope); render selects the
|
|
450
|
+
* current view's message and recovery action. Omit it to keep empty arrays as data.
|
|
451
|
+
*/
|
|
452
|
+
empty?: {
|
|
453
|
+
when: (data: NonNullable<T>) => boolean
|
|
454
|
+
render: NonNullable<QueryContentProps<T>['children']>
|
|
455
|
+
}
|
|
456
|
+
|
|
412
457
|
/**
|
|
413
458
|
* State from `useQuery` — as the readable store the hook returns, or as a
|
|
414
459
|
* compatible observer's plain state object. Both follow the query.
|
|
@@ -443,6 +488,26 @@ interface IntentPrefetchProps {
|
|
|
443
488
|
}
|
|
444
489
|
```
|
|
445
490
|
|
|
491
|
+
### Types
|
|
492
|
+
|
|
493
|
+
#### `ListQuerySource`
|
|
494
|
+
|
|
495
|
+
A plain value or a readable store: each input {@link useListQuery} reads reactively.
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
type ListQuerySource<T> = T | Readable<T>
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
#### `ListQueryInputs`
|
|
502
|
+
|
|
503
|
+
Each input of {@link useListQuery} as a {@link ListQuerySource}.
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
type ListQueryInputs<Values> = {
|
|
507
|
+
readonly [Key in keyof Values]: ListQuerySource<Values[Key]>
|
|
508
|
+
}
|
|
509
|
+
```
|
|
510
|
+
|
|
446
511
|
### Functions
|
|
447
512
|
|
|
448
513
|
#### `prefetchQuery(options)`
|
|
@@ -492,6 +557,29 @@ function createQueryResource<T, Create = Partial<T>, Update = Partial<T>>(
|
|
|
492
557
|
|
|
493
558
|
**Returns:** List and detail query options, and create, update, remove, toggle and refresh.
|
|
494
559
|
|
|
560
|
+
#### `useListQuery(route, inputs, read)`
|
|
561
|
+
|
|
562
|
+
Observe the page a URL list route points at. `read` builds the query from the current value of
|
|
563
|
+
each input (the signed-in `viewer`, request params, a parent record's id) and the route's
|
|
564
|
+
filters, page size and offset. The query is disabled (`null`, no request) while `viewer` is
|
|
565
|
+
null (auth is still being restored) or the route cannot load yet; a changed input or URL moves
|
|
566
|
+
the same observer to the new page.
|
|
567
|
+
Call it during component initialisation, as {@link useQuery}.
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
function useListQuery<T, Values extends { viewer: string | null }, Filter extends string = string>(
|
|
571
|
+
route: ListQueryRoute<Filter>,
|
|
572
|
+
inputs: ListQueryInputs<Values>,
|
|
573
|
+
read: (values: Values & { viewer: string }, list: ListQueryState<Filter>) => QueryOptions<T>,
|
|
574
|
+
): Readable<UseQueryResult<T>>
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
- `route` — The list route, usually `useListRoute(...)` from `@molecule/app-svelte`.
|
|
578
|
+
- `inputs` — Plain values or stores; `viewer` is the signed-in user's id, 'anonymous', or null while auth is restoring.
|
|
579
|
+
- `read` — Builds the page's query options, e.g. a generated `articlesPage(...)`.
|
|
580
|
+
|
|
581
|
+
**Returns:** The query state as a store, as {@link useQuery} returns it.
|
|
582
|
+
|
|
495
583
|
#### `usePrefetch()`
|
|
496
584
|
|
|
497
585
|
A stable `prefetch(options)` function for event handlers. One identity for
|
|
@@ -635,3 +723,10 @@ Peer dependencies:
|
|
|
635
723
|
- Keep every resource identity in the query key. A boundary cannot correct a
|
|
636
724
|
query that supplies another record's cached data. QueryContent is headless
|
|
637
725
|
and owns no translations or styling.
|
|
726
|
+
|
|
727
|
+
For a collection, `QueryContent` also accepts one `empty` branch:
|
|
728
|
+
`{ when: page => page.rows.length === 0, render: page => selectedEmptyState }`.
|
|
729
|
+
It is exclusive with loaded children, so a selected view chooses its message and
|
|
730
|
+
recovery action once rather than rendering a general empty message beside it.
|
|
731
|
+
`when` receives a loaded document; empty arrays remain data when this prop is omitted.
|
|
732
|
+
The render value uses this framework's existing children function, snippet or template.
|
package/dist/QueryContent.svelte
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
pending = null,
|
|
26
26
|
missing = null,
|
|
27
27
|
error = null,
|
|
28
|
+
empty,
|
|
28
29
|
}: QueryContentProps<T> = $props()
|
|
29
30
|
|
|
30
31
|
/**
|
|
@@ -48,6 +49,8 @@
|
|
|
48
49
|
{/if}
|
|
49
50
|
{:else if $view.data === null}
|
|
50
51
|
{#if missing}{@render missing()}{/if}
|
|
52
|
+
{:else if empty?.when($view.data)}
|
|
53
|
+
{@render empty.render($view.data)}
|
|
51
54
|
{:else}
|
|
52
55
|
{@render children($view.data)}
|
|
53
56
|
{/if}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryContent.svelte.d.ts","sourceRoot":"","sources":["../src/QueryContent.svelte"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,iBAAS,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"QueryContent.svelte.d.ts","sourceRoot":"","sources":["../src/QueryContent.svelte"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,iBAAS,QAAQ,CAAC,CAAC;WAiDU,iBAAiB,CAAC,CAAC,CAAC;;;;;EAA4E;AAC7H,cAAM,iBAAiB,CAAC,CAAC;IACrB,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,MAAM,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClD,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,QAAQ;IACR,OAAO;CACV;AAED,UAAU,qBAAqB;IAC3B,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;KAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC5X,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3H,YAAY,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACjE;AACD,QAAA,MAAM,YAAY,EAAE,qBAAmC,CAAC;AACtC,KAAK,YAAY,CAAC,CAAC,IAAI,YAAY,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9D,eAAe,YAAY,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -290,9 +290,17 @@
|
|
|
290
290
|
* query that supplies another record's cached data. QueryContent is headless
|
|
291
291
|
* and owns no translations or styling.
|
|
292
292
|
*
|
|
293
|
+
* For a collection, `QueryContent` also accepts one `empty` branch:
|
|
294
|
+
* `{ when: page => page.rows.length === 0, render: page => selectedEmptyState }`.
|
|
295
|
+
* It is exclusive with loaded children, so a selected view chooses its message and
|
|
296
|
+
* recovery action once rather than rendering a general empty message beside it.
|
|
297
|
+
* `when` receives a loaded document; empty arrays remain data when this prop is omitted.
|
|
298
|
+
* The render value uses this framework's existing children function, snippet or template.
|
|
299
|
+
*
|
|
293
300
|
* @module
|
|
294
301
|
*/
|
|
295
302
|
export * from './components.js';
|
|
303
|
+
export * from './list-query.js';
|
|
296
304
|
export * from './resource.js';
|
|
297
305
|
export * from './types.js';
|
|
298
306
|
export * from './usePrefetch.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4SG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -290,9 +290,17 @@
|
|
|
290
290
|
* query that supplies another record's cached data. QueryContent is headless
|
|
291
291
|
* and owns no translations or styling.
|
|
292
292
|
*
|
|
293
|
+
* For a collection, `QueryContent` also accepts one `empty` branch:
|
|
294
|
+
* `{ when: page => page.rows.length === 0, render: page => selectedEmptyState }`.
|
|
295
|
+
* It is exclusive with loaded children, so a selected view chooses its message and
|
|
296
|
+
* recovery action once rather than rendering a general empty message beside it.
|
|
297
|
+
* `when` receives a loaded document; empty arrays remain data when this prop is omitted.
|
|
298
|
+
* The render value uses this framework's existing children function, snippet or template.
|
|
299
|
+
*
|
|
293
300
|
* @module
|
|
294
301
|
*/
|
|
295
302
|
export * from './components.js';
|
|
303
|
+
export * from './list-query.js';
|
|
296
304
|
export * from './resource.js';
|
|
297
305
|
export * from './types.js';
|
|
298
306
|
export * from './usePrefetch.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useListQuery`: one cached read driven by a URL list route.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type Readable } from 'svelte/store';
|
|
7
|
+
import type { QueryOptions } from '@molecule/app-query';
|
|
8
|
+
import type { UseQueryResult } from './types.js';
|
|
9
|
+
/** A plain value or a readable store: each input {@link useListQuery} reads reactively. */
|
|
10
|
+
export type ListQuerySource<T> = T | Readable<T>;
|
|
11
|
+
/** Each input of {@link useListQuery} as a {@link ListQuerySource}. */
|
|
12
|
+
export type ListQueryInputs<Values> = {
|
|
13
|
+
readonly [Key in keyof Values]: ListQuerySource<Values[Key]>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The list route a list query reads: `useListRoute` from `@molecule/app-svelte` returns these
|
|
17
|
+
* stores (and more), so its result is passed as it is.
|
|
18
|
+
*/
|
|
19
|
+
export interface ListQueryRoute<Filter extends string = string> {
|
|
20
|
+
/** False while a protected view waits for auth, is signed out, or is unavailable. */
|
|
21
|
+
readonly canLoad: Readable<boolean>;
|
|
22
|
+
/** The current URL filter values. */
|
|
23
|
+
readonly filters: Readable<Readonly<Record<Filter, string | undefined>>>;
|
|
24
|
+
/** The configured items per page. */
|
|
25
|
+
readonly pageSize: Readable<number>;
|
|
26
|
+
/** The zero-indexed item offset for the API request. */
|
|
27
|
+
readonly offset: Readable<number>;
|
|
28
|
+
}
|
|
29
|
+
/** The route's current values, as `read` receives them. */
|
|
30
|
+
export interface ListQueryState<Filter extends string = string> {
|
|
31
|
+
/** The current URL filter values. */
|
|
32
|
+
readonly filters: Readonly<Record<Filter, string | undefined>>;
|
|
33
|
+
/** The configured items per page. */
|
|
34
|
+
readonly pageSize: number;
|
|
35
|
+
/** The zero-indexed item offset for the API request. */
|
|
36
|
+
readonly offset: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Observe the page a URL list route points at. `read` builds the query from the current value of
|
|
40
|
+
* each input (the signed-in `viewer`, request params, a parent record's id) and the route's
|
|
41
|
+
* filters, page size and offset. The query is disabled (`null`, no request) while `viewer` is
|
|
42
|
+
* null (auth is still being restored) or the route cannot load yet; a changed input or URL moves
|
|
43
|
+
* the same observer to the new page.
|
|
44
|
+
* Call it during component initialisation, as {@link useQuery}.
|
|
45
|
+
*
|
|
46
|
+
* @param route - The list route, usually `useListRoute(...)` from `@molecule/app-svelte`.
|
|
47
|
+
* @param inputs - Plain values or stores; `viewer` is the signed-in user's id, 'anonymous',
|
|
48
|
+
* or null while auth is restoring.
|
|
49
|
+
* @param read - Builds the page's query options, e.g. a generated `articlesPage(...)`.
|
|
50
|
+
* @returns The query state as a store, as {@link useQuery} returns it.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useListQuery<T, Values extends {
|
|
53
|
+
viewer: string | null;
|
|
54
|
+
}, Filter extends string = string>(route: ListQueryRoute<Filter>, inputs: ListQueryInputs<Values>, read: (values: Values & {
|
|
55
|
+
viewer: string;
|
|
56
|
+
}, list: ListQueryState<Filter>) => QueryOptions<T>): Readable<UseQueryResult<T>>;
|
|
57
|
+
//# sourceMappingURL=list-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-query.d.ts","sourceRoot":"","sources":["../src/list-query.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAW,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAGhD,2FAA2F;AAC3F,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;AAEhD,uEAAuE;AACvE,MAAM,MAAM,eAAe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IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,GAC3F,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAqB7B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useListQuery`: one cached read driven by a URL list route.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { derived, readable } from 'svelte/store';
|
|
7
|
+
import { useQuery } from './useQuery.js';
|
|
8
|
+
/**
|
|
9
|
+
* Whether an argument is a readable store (an object with `subscribe`) rather than a value.
|
|
10
|
+
*
|
|
11
|
+
* @param source - The argument as the caller passed it.
|
|
12
|
+
* @returns True for a store.
|
|
13
|
+
*/
|
|
14
|
+
const isStore = (source) => typeof source === 'object' &&
|
|
15
|
+
source !== null &&
|
|
16
|
+
typeof source.subscribe === 'function';
|
|
17
|
+
/**
|
|
18
|
+
* The store view of an argument: the store itself, or a constant store of the value.
|
|
19
|
+
*
|
|
20
|
+
* @param source - The argument as the caller passed it.
|
|
21
|
+
* @returns A readable store of it.
|
|
22
|
+
*/
|
|
23
|
+
const toStore = (source) => isStore(source) ? source : readable(source);
|
|
24
|
+
/**
|
|
25
|
+
* Observe the page a URL list route points at. `read` builds the query from the current value of
|
|
26
|
+
* each input (the signed-in `viewer`, request params, a parent record's id) and the route's
|
|
27
|
+
* filters, page size and offset. The query is disabled (`null`, no request) while `viewer` is
|
|
28
|
+
* null (auth is still being restored) or the route cannot load yet; a changed input or URL moves
|
|
29
|
+
* the same observer to the new page.
|
|
30
|
+
* Call it during component initialisation, as {@link useQuery}.
|
|
31
|
+
*
|
|
32
|
+
* @param route - The list route, usually `useListRoute(...)` from `@molecule/app-svelte`.
|
|
33
|
+
* @param inputs - Plain values or stores; `viewer` is the signed-in user's id, 'anonymous',
|
|
34
|
+
* or null while auth is restoring.
|
|
35
|
+
* @param read - Builds the page's query options, e.g. a generated `articlesPage(...)`.
|
|
36
|
+
* @returns The query state as a store, as {@link useQuery} returns it.
|
|
37
|
+
*/
|
|
38
|
+
export function useListQuery(route, inputs, read) {
|
|
39
|
+
const keys = Object.keys(inputs);
|
|
40
|
+
const values = derived(keys.map((key) => toStore(inputs[key])), (current) => {
|
|
41
|
+
const next = {};
|
|
42
|
+
keys.forEach((key, index) => {
|
|
43
|
+
next[key] = current[index];
|
|
44
|
+
});
|
|
45
|
+
return next;
|
|
46
|
+
});
|
|
47
|
+
return useQuery(derived([values, route.canLoad, route.filters, route.pageSize, route.offset], ([current, canLoad, filters, pageSize, offset]) => current.viewer !== null && canLoad
|
|
48
|
+
? read({ ...current, viewer: current.viewer }, { filters, pageSize, offset })
|
|
49
|
+
: null));
|
|
50
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -34,6 +34,15 @@ export interface UseQueryResult<T> extends QueryState<T> {
|
|
|
34
34
|
}
|
|
35
35
|
/** A loaded document owns its controls; absent documents expose only status content. */
|
|
36
36
|
export interface QueryContentProps<T> {
|
|
37
|
+
/**
|
|
38
|
+
* One optional empty branch, exclusive with children. The pure predicate reads the
|
|
39
|
+
* loaded document (an array or an application-owned envelope); render selects the
|
|
40
|
+
* current view's message and recovery action. Omit it to keep empty arrays as data.
|
|
41
|
+
*/
|
|
42
|
+
empty?: {
|
|
43
|
+
when: (data: NonNullable<T>) => boolean;
|
|
44
|
+
render: NonNullable<QueryContentProps<T>['children']>;
|
|
45
|
+
};
|
|
37
46
|
/**
|
|
38
47
|
* State from `useQuery` — as the readable store the hook returns, or as a
|
|
39
48
|
* compatible observer's plain state object. Both follow the query.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA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CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACxB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAA;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,4CAA4C;IAC5C,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,8CAA8C;IAC9C,YAAY,EAAE,MAAM,IAAI,CAAA;CACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-query-svelte",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Svelte hooks for @molecule/app-query — read a cached document synchronously, observe it, and prefetch on intent",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/app-query-svelte",
|
|
6
6
|
"type": "module",
|
|
@@ -56,14 +56,14 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@molecule/app-framework-conformance": "0.0.0",
|
|
59
|
-
"@molecule/app-i18n": "1.2.
|
|
59
|
+
"@molecule/app-i18n": "1.2.2",
|
|
60
60
|
"@molecule/app-icons": "1.0.4",
|
|
61
|
-
"@molecule/app-query": "1.
|
|
62
|
-
"@molecule/app-query-memory": "1.0
|
|
63
|
-
"@molecule/app-query-tanstack": "1.0
|
|
64
|
-
"@molecule/app-svelte": "3.
|
|
65
|
-
"@molecule/app-ui": "1.
|
|
66
|
-
"@molecule/app-ui-svelte": "1.1.
|
|
61
|
+
"@molecule/app-query": "1.3.1",
|
|
62
|
+
"@molecule/app-query-memory": "1.1.0",
|
|
63
|
+
"@molecule/app-query-tanstack": "1.1.0",
|
|
64
|
+
"@molecule/app-svelte": "3.7.1",
|
|
65
|
+
"@molecule/app-ui": "1.4.0",
|
|
66
|
+
"@molecule/app-ui-svelte": "1.1.6",
|
|
67
67
|
"@sveltejs/package": "3.0.2",
|
|
68
68
|
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
69
69
|
"@types/node": "26.6.5",
|