@molecule/app-query-svelte 0.0.1-stage → 1.2.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 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-14T15:30:33.015Z
6
+ Generated: 2026-11-14T22:00:54.075Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-query-svelte
@@ -374,6 +374,39 @@ interface QueryResource<T, Create = Partial<T>, Update = Partial<T>> {
374
374
  }
375
375
  ```
376
376
 
377
+ #### `ListQueryRoute`
378
+
379
+ The list route a list query reads: `useListRoute` from `@molecule/app-svelte` returns these
380
+ stores (and more), so its result is passed as it is.
381
+
382
+ ```typescript
383
+ interface ListQueryRoute<Filter extends string = string> {
384
+ /** False while a protected view waits for auth, is signed out, or is unavailable. */
385
+ readonly canLoad: Readable<boolean>
386
+ /** The current URL filter values. */
387
+ readonly filters: Readable<Readonly<Record<Filter, string | undefined>>>
388
+ /** The configured items per page. */
389
+ readonly pageSize: Readable<number>
390
+ /** The zero-indexed item offset for the API request. */
391
+ readonly offset: Readable<number>
392
+ }
393
+ ```
394
+
395
+ #### `ListQueryState`
396
+
397
+ The route's current values, as `read` receives them.
398
+
399
+ ```typescript
400
+ interface ListQueryState<Filter extends string = string> {
401
+ /** The current URL filter values. */
402
+ readonly filters: Readonly<Record<Filter, string | undefined>>
403
+ /** The configured items per page. */
404
+ readonly pageSize: number
405
+ /** The zero-indexed item offset for the API request. */
406
+ readonly offset: number
407
+ }
408
+ ```
409
+
377
410
  #### `UseQueryResult`
378
411
 
379
412
  A mounted query's state and its explicit cache and refresh actions. The
@@ -443,6 +476,26 @@ interface IntentPrefetchProps {
443
476
  }
444
477
  ```
445
478
 
479
+ ### Types
480
+
481
+ #### `ListQuerySource`
482
+
483
+ A plain value or a readable store: each input {@link useListQuery} reads reactively.
484
+
485
+ ```typescript
486
+ type ListQuerySource<T> = T | Readable<T>
487
+ ```
488
+
489
+ #### `ListQueryInputs`
490
+
491
+ Each input of {@link useListQuery} as a {@link ListQuerySource}.
492
+
493
+ ```typescript
494
+ type ListQueryInputs<Values> = {
495
+ readonly [Key in keyof Values]: ListQuerySource<Values[Key]>
496
+ }
497
+ ```
498
+
446
499
  ### Functions
447
500
 
448
501
  #### `prefetchQuery(options)`
@@ -492,6 +545,29 @@ function createQueryResource<T, Create = Partial<T>, Update = Partial<T>>(
492
545
 
493
546
  **Returns:** List and detail query options, and create, update, remove, toggle and refresh.
494
547
 
548
+ #### `useListQuery(route, inputs, read)`
549
+
550
+ Observe the page a URL list route points at. `read` builds the query from the current value of
551
+ each input (the signed-in `viewer`, request params, a parent record's id) and the route's
552
+ filters, page size and offset. The query is disabled (`null`, no request) while `viewer` is
553
+ null (auth is still being restored) or the route cannot load yet; a changed input or URL moves
554
+ the same observer to the new page.
555
+ Call it during component initialisation, as {@link useQuery}.
556
+
557
+ ```typescript
558
+ function useListQuery<T, Values extends { viewer: string | null }, Filter extends string = string>(
559
+ route: ListQueryRoute<Filter>,
560
+ inputs: ListQueryInputs<Values>,
561
+ read: (values: Values & { viewer: string }, list: ListQueryState<Filter>) => QueryOptions<T>,
562
+ ): Readable<UseQueryResult<T>>
563
+ ```
564
+
565
+ - `route` — The list route, usually `useListRoute(...)` from `@molecule/app-svelte`.
566
+ - `inputs` — Plain values or stores; `viewer` is the signed-in user's id, 'anonymous', or null while auth is restoring.
567
+ - `read` — Builds the page's query options, e.g. a generated `articlesPage(...)`.
568
+
569
+ **Returns:** The query state as a store, as {@link useQuery} returns it.
570
+
495
571
  #### `usePrefetch()`
496
572
 
497
573
  A stable `prefetch(options)` function for event handlers. One identity for
package/dist/index.d.ts CHANGED
@@ -293,6 +293,7 @@
293
293
  * @module
294
294
  */
295
295
  export * from './components.js';
296
+ export * from './list-query.js';
296
297
  export * from './resource.js';
297
298
  export * from './types.js';
298
299
  export * from './usePrefetch.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqSG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqSG;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
@@ -293,6 +293,7 @@
293
293
  * @module
294
294
  */
295
295
  export * from './components.js';
296
+ export * from './list-query.js';
296
297
  export * from './resource.js';
297
298
  export * from './types.js';
298
299
  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,CAAC,MAAM,IAAI;IACpC,QAAQ,EAAE,GAAG,IAAI,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;CAC7D,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IAC5D,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACnC,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;IACxE,qCAAqC;IACrC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACnC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;CAClC;AAED,2DAA2D;AAC3D,MAAM,WAAW,cAAc,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IAC5D,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;IAC9D,qCAAqC;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAsBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC1B,CAAC,EACD,MAAM,SAAS;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EACxC,MAAM,SAAS,MAAM,GAAG,MAAM,EAE9B,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,EAC7B,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,EAC/B,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-query-svelte",
3
- "version": "0.0.1-stage",
3
+ "version": "1.2.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",
@@ -61,9 +61,9 @@
61
61
  "@molecule/app-query": "1.2.0",
62
62
  "@molecule/app-query-memory": "1.0.5",
63
63
  "@molecule/app-query-tanstack": "1.0.5",
64
- "@molecule/app-svelte": "3.5.1",
64
+ "@molecule/app-svelte": "3.6.0",
65
65
  "@molecule/app-ui": "1.3.11",
66
- "@molecule/app-ui-svelte": "1.1.2",
66
+ "@molecule/app-ui-svelte": "1.1.3",
67
67
  "@sveltejs/package": "3.0.2",
68
68
  "@sveltejs/vite-plugin-svelte": "7.1.2",
69
69
  "@types/node": "26.6.5",