@molecule/app-query-angular 1.1.0 → 1.2.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/README.md +91 -14
- package/dist/index.d.ts +15 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -13
- package/dist/index.js.map +1 -1
- package/dist/list-query.d.ts +57 -0
- package/dist/list-query.d.ts.map +1 -0
- package/dist/list-query.js +40 -0
- package/dist/list-query.js.map +1 -0
- package/package.json +5 -5
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-15T13:01:51.146Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-query-angular
|
|
@@ -44,8 +44,8 @@ with a new options object.
|
|
|
44
44
|
|
|
45
45
|
```typescript
|
|
46
46
|
import { Component, OnChanges, computed, input } from '@angular/core'
|
|
47
|
+
import { useTranslation } from '@molecule/app-angular'
|
|
47
48
|
import { getClient, isHttpError } from '@molecule/app-http'
|
|
48
|
-
import { t } from '@molecule/app-i18n'
|
|
49
49
|
import { intentPrefetchProps, useQuery } from '@molecule/app-query-angular'
|
|
50
50
|
|
|
51
51
|
interface PackageDocument {
|
|
@@ -115,8 +115,8 @@ export class PackageLink implements OnChanges {
|
|
|
115
115
|
`,
|
|
116
116
|
})
|
|
117
117
|
export class PackagePage {
|
|
118
|
-
//
|
|
119
|
-
protected readonly t = t
|
|
118
|
+
// The binding's t re-runs the template on a locale switch.
|
|
119
|
+
protected readonly t = useTranslation().t
|
|
120
120
|
readonly name = input('')
|
|
121
121
|
|
|
122
122
|
readonly query = useQuery<PackageDocument | null>(
|
|
@@ -141,8 +141,8 @@ restoring a session never swaps a key that already rendered rows.
|
|
|
141
141
|
|
|
142
142
|
```typescript
|
|
143
143
|
import { Component, computed, input } from '@angular/core'
|
|
144
|
+
import { useTranslation } from '@molecule/app-angular'
|
|
144
145
|
import { getClient, unwrapList } from '@molecule/app-http'
|
|
145
|
-
import { t } from '@molecule/app-i18n'
|
|
146
146
|
import { useQuery } from '@molecule/app-query-angular'
|
|
147
147
|
|
|
148
148
|
interface Invoice {
|
|
@@ -175,8 +175,8 @@ interface Invoice {
|
|
|
175
175
|
`,
|
|
176
176
|
})
|
|
177
177
|
export class InvoiceList {
|
|
178
|
-
//
|
|
179
|
-
protected readonly t = t
|
|
178
|
+
// The binding's t re-runs the template on a locale switch.
|
|
179
|
+
protected readonly t = useTranslation().t
|
|
180
180
|
// The viewer whose invoices these are (also in the key).
|
|
181
181
|
readonly viewer = input('anonymous')
|
|
182
182
|
// The page to show.
|
|
@@ -208,8 +208,8 @@ explicit `fetch()` retries into the mounted page.
|
|
|
208
208
|
|
|
209
209
|
```typescript
|
|
210
210
|
import { Component, input } from '@angular/core'
|
|
211
|
+
import { useTranslation } from '@molecule/app-angular'
|
|
211
212
|
import { getClient } from '@molecule/app-http'
|
|
212
|
-
import { t } from '@molecule/app-i18n'
|
|
213
213
|
import { getQueryClient } from '@molecule/app-query'
|
|
214
214
|
|
|
215
215
|
// The key names what the document actually depends on — here the signed-in
|
|
@@ -243,8 +243,8 @@ async function setFollowing(principal: string, authorId: string, follow: boolean
|
|
|
243
243
|
host: { type: 'button', '(click)': 'retry()' },
|
|
244
244
|
})
|
|
245
245
|
export class FeedRetry {
|
|
246
|
-
//
|
|
247
|
-
protected readonly t = t
|
|
246
|
+
// The binding's t re-runs the template on a locale switch.
|
|
247
|
+
protected readonly t = useTranslation().t
|
|
248
248
|
readonly principal = input.required<string>()
|
|
249
249
|
|
|
250
250
|
retry(): void {
|
|
@@ -270,8 +270,8 @@ the saved record and is the `commit` of `OptimisticToggleButton` (from
|
|
|
270
270
|
|
|
271
271
|
```typescript
|
|
272
272
|
import { Component, computed, input } from '@angular/core'
|
|
273
|
+
import { useTranslation } from '@molecule/app-angular'
|
|
273
274
|
import { getClient, unwrapList, unwrapSingle } from '@molecule/app-http'
|
|
274
|
-
import { t } from '@molecule/app-i18n'
|
|
275
275
|
import { OptimisticToggleButton } from '@molecule/app-ui-angular'
|
|
276
276
|
import { createQueryResource, QueryContent, useQuery } from '@molecule/app-query-angular'
|
|
277
277
|
|
|
@@ -309,7 +309,8 @@ export const invoices = createQueryResource<Invoice>({
|
|
|
309
309
|
export class InvoiceFlagControl {
|
|
310
310
|
readonly invoice = input.required<Invoice>()
|
|
311
311
|
readonly viewer = input.required<string>()
|
|
312
|
-
|
|
312
|
+
// The binding's t re-runs the template on a locale switch.
|
|
313
|
+
protected readonly t = useTranslation().t
|
|
313
314
|
|
|
314
315
|
readonly save = async (flagged: boolean): Promise<boolean> =>
|
|
315
316
|
(await invoices.toggle(this.viewer(), this.invoice().id, 'flag', flagged)).flagged
|
|
@@ -350,8 +351,8 @@ export class InvoiceFlagControl {
|
|
|
350
351
|
imports: [QueryContent, InvoiceFlagControl],
|
|
351
352
|
})
|
|
352
353
|
export class InvoicePage {
|
|
353
|
-
//
|
|
354
|
-
protected readonly t = t
|
|
354
|
+
// The binding's t re-runs the template on a locale switch.
|
|
355
|
+
protected readonly t = useTranslation().t
|
|
355
356
|
readonly id = input('')
|
|
356
357
|
readonly viewer = input('')
|
|
357
358
|
|
|
@@ -523,6 +524,39 @@ interface QueryResource<T, Create = Partial<T>, Update = Partial<T>> {
|
|
|
523
524
|
}
|
|
524
525
|
```
|
|
525
526
|
|
|
527
|
+
#### `ListQueryRoute`
|
|
528
|
+
|
|
529
|
+
The list route a list query reads: `useListRoute` from `@molecule/app-angular` returns these
|
|
530
|
+
signals (and more), so its result is passed as it is.
|
|
531
|
+
|
|
532
|
+
```typescript
|
|
533
|
+
interface ListQueryRoute<Filter extends string = string> {
|
|
534
|
+
/** False while a protected view waits for auth, is signed out, or is unavailable. */
|
|
535
|
+
readonly canLoad: Signal<boolean>
|
|
536
|
+
/** The current URL filter values. */
|
|
537
|
+
readonly filters: Signal<Readonly<Record<Filter, string | undefined>>>
|
|
538
|
+
/** The configured items per page. */
|
|
539
|
+
readonly pageSize: Signal<number>
|
|
540
|
+
/** The zero-indexed item offset for the API request. */
|
|
541
|
+
readonly offset: Signal<number>
|
|
542
|
+
}
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
#### `ListQueryState`
|
|
546
|
+
|
|
547
|
+
The route's current values, as `read` receives them.
|
|
548
|
+
|
|
549
|
+
```typescript
|
|
550
|
+
interface ListQueryState<Filter extends string = string> {
|
|
551
|
+
/** The current URL filter values. */
|
|
552
|
+
readonly filters: Readonly<Record<Filter, string | undefined>>
|
|
553
|
+
/** The configured items per page. */
|
|
554
|
+
readonly pageSize: number
|
|
555
|
+
/** The zero-indexed item offset for the API request. */
|
|
556
|
+
readonly offset: number
|
|
557
|
+
}
|
|
558
|
+
```
|
|
559
|
+
|
|
526
560
|
#### `UseQueryResult`
|
|
527
561
|
|
|
528
562
|
A mounted query's state and its explicit cache and refresh actions. The state
|
|
@@ -616,6 +650,26 @@ interface IntentPrefetchProps {
|
|
|
616
650
|
}
|
|
617
651
|
```
|
|
618
652
|
|
|
653
|
+
### Types
|
|
654
|
+
|
|
655
|
+
#### `ListQuerySource`
|
|
656
|
+
|
|
657
|
+
A plain value or a signal: each input {@link useListQuery} reads reactively.
|
|
658
|
+
|
|
659
|
+
```typescript
|
|
660
|
+
type ListQuerySource<T> = T | Signal<T>
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
#### `ListQueryInputs`
|
|
664
|
+
|
|
665
|
+
Each input of {@link useListQuery} as a {@link ListQuerySource}.
|
|
666
|
+
|
|
667
|
+
```typescript
|
|
668
|
+
type ListQueryInputs<Values> = {
|
|
669
|
+
readonly [Key in keyof Values]: ListQuerySource<Values[Key]>
|
|
670
|
+
}
|
|
671
|
+
```
|
|
672
|
+
|
|
619
673
|
### Classes
|
|
620
674
|
|
|
621
675
|
#### `QueryContent`
|
|
@@ -794,6 +848,29 @@ function createQueryResource<T, Create = Partial<T>, Update = Partial<T>>(
|
|
|
794
848
|
|
|
795
849
|
**Returns:** List and detail query options, and create, update, remove, toggle and refresh.
|
|
796
850
|
|
|
851
|
+
#### `useListQuery(route, inputs, read)`
|
|
852
|
+
|
|
853
|
+
Observe the page a URL list route points at. `read` builds the query from the current value of
|
|
854
|
+
each input (the signed-in `viewer`, request params, a parent record's id) and the route's
|
|
855
|
+
filters, page size and offset. The query is disabled (`null`, no request) while `viewer` is
|
|
856
|
+
null (auth is still being restored) or the route cannot load yet; a changed input or URL moves
|
|
857
|
+
the same observer to the new page.
|
|
858
|
+
Call it in an injection context, as {@link useQuery}.
|
|
859
|
+
|
|
860
|
+
```typescript
|
|
861
|
+
function useListQuery<T, Values extends { viewer: string | null }, Filter extends string = string>(
|
|
862
|
+
route: ListQueryRoute<Filter>,
|
|
863
|
+
inputs: ListQueryInputs<Values>,
|
|
864
|
+
read: (values: Values & { viewer: string }, list: ListQueryState<Filter>) => QueryOptions<T>,
|
|
865
|
+
): UseQueryResult<T>
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
- `route` — The list route, usually `useListRoute(...)` from `@molecule/app-angular`.
|
|
869
|
+
- `inputs` — Plain values or signals; `viewer` is the signed-in user's id, 'anonymous', or null while auth is restoring.
|
|
870
|
+
- `read` — Builds the page's query options, e.g. a generated `articlesPage(...)`.
|
|
871
|
+
|
|
872
|
+
**Returns:** The query state, as {@link useQuery} returns it.
|
|
873
|
+
|
|
797
874
|
#### `usePrefetch()`
|
|
798
875
|
|
|
799
876
|
A stable `prefetch(options)` function for event handlers. Call it in an
|
package/dist/index.d.ts
CHANGED
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
* @example
|
|
31
31
|
* ```typescript
|
|
32
32
|
* import { Component, OnChanges, computed, input } from '@angular/core'
|
|
33
|
+
* import { useTranslation } from '@molecule/app-angular'
|
|
33
34
|
* import { getClient, isHttpError } from '@molecule/app-http'
|
|
34
|
-
* import { t } from '@molecule/app-i18n'
|
|
35
35
|
* import { intentPrefetchProps, useQuery } from '@molecule/app-query-angular'
|
|
36
36
|
*
|
|
37
37
|
* interface PackageDocument {
|
|
@@ -96,8 +96,8 @@
|
|
|
96
96
|
* `,
|
|
97
97
|
* })
|
|
98
98
|
* export class PackagePage {
|
|
99
|
-
* //
|
|
100
|
-
* protected readonly t = t
|
|
99
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
100
|
+
* protected readonly t = useTranslation().t
|
|
101
101
|
* readonly name = input('')
|
|
102
102
|
*
|
|
103
103
|
* readonly query = useQuery<PackageDocument | null>(
|
|
@@ -123,8 +123,8 @@
|
|
|
123
123
|
*
|
|
124
124
|
* ```typescript
|
|
125
125
|
* import { Component, computed, input } from '@angular/core'
|
|
126
|
+
* import { useTranslation } from '@molecule/app-angular'
|
|
126
127
|
* import { getClient, unwrapList } from '@molecule/app-http'
|
|
127
|
-
* import { t } from '@molecule/app-i18n'
|
|
128
128
|
* import { useQuery } from '@molecule/app-query-angular'
|
|
129
129
|
*
|
|
130
130
|
* interface Invoice {
|
|
@@ -153,8 +153,8 @@
|
|
|
153
153
|
* `,
|
|
154
154
|
* })
|
|
155
155
|
* export class InvoiceList {
|
|
156
|
-
* //
|
|
157
|
-
* protected readonly t = t
|
|
156
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
157
|
+
* protected readonly t = useTranslation().t
|
|
158
158
|
* // The viewer whose invoices these are (also in the key).
|
|
159
159
|
* readonly viewer = input('anonymous')
|
|
160
160
|
* // The page to show.
|
|
@@ -187,8 +187,8 @@
|
|
|
187
187
|
*
|
|
188
188
|
* ```typescript
|
|
189
189
|
* import { Component, input } from '@angular/core'
|
|
190
|
+
* import { useTranslation } from '@molecule/app-angular'
|
|
190
191
|
* import { getClient } from '@molecule/app-http'
|
|
191
|
-
* import { t } from '@molecule/app-i18n'
|
|
192
192
|
* import { getQueryClient } from '@molecule/app-query'
|
|
193
193
|
*
|
|
194
194
|
* // The key names what the document actually depends on — here the signed-in
|
|
@@ -222,8 +222,8 @@
|
|
|
222
222
|
* host: { type: 'button', '(click)': 'retry()' },
|
|
223
223
|
* })
|
|
224
224
|
* export class FeedRetry {
|
|
225
|
-
* //
|
|
226
|
-
* protected readonly t = t
|
|
225
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
226
|
+
* protected readonly t = useTranslation().t
|
|
227
227
|
* readonly principal = input.required<string>()
|
|
228
228
|
*
|
|
229
229
|
* retry(): void {
|
|
@@ -250,8 +250,8 @@
|
|
|
250
250
|
*
|
|
251
251
|
* ```typescript
|
|
252
252
|
* import { Component, computed, input } from '@angular/core'
|
|
253
|
+
* import { useTranslation } from '@molecule/app-angular'
|
|
253
254
|
* import { getClient, unwrapList, unwrapSingle } from '@molecule/app-http'
|
|
254
|
-
* import { t } from '@molecule/app-i18n'
|
|
255
255
|
* import { OptimisticToggleButton } from '@molecule/app-ui-angular'
|
|
256
256
|
* import { createQueryResource, QueryContent, useQuery } from '@molecule/app-query-angular'
|
|
257
257
|
*
|
|
@@ -287,7 +287,8 @@
|
|
|
287
287
|
* export class InvoiceFlagControl {
|
|
288
288
|
* readonly invoice = input.required<Invoice>()
|
|
289
289
|
* readonly viewer = input.required<string>()
|
|
290
|
-
*
|
|
290
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
291
|
+
* protected readonly t = useTranslation().t
|
|
291
292
|
*
|
|
292
293
|
* readonly save = async (flagged: boolean): Promise<boolean> =>
|
|
293
294
|
* (await invoices.toggle(this.viewer(), this.invoice().id, 'flag', flagged)).flagged
|
|
@@ -324,8 +325,8 @@
|
|
|
324
325
|
* imports: [QueryContent, InvoiceFlagControl],
|
|
325
326
|
* })
|
|
326
327
|
* export class InvoicePage {
|
|
327
|
-
* //
|
|
328
|
-
* protected readonly t = t
|
|
328
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
329
|
+
* protected readonly t = useTranslation().t
|
|
329
330
|
* readonly id = input('')
|
|
330
331
|
* readonly viewer = input('')
|
|
331
332
|
*
|
|
@@ -456,6 +457,7 @@
|
|
|
456
457
|
*
|
|
457
458
|
* @module
|
|
458
459
|
*/
|
|
460
|
+
export * from './list-query.js';
|
|
459
461
|
export * from './query-content.component.js';
|
|
460
462
|
export * from './resource.js';
|
|
461
463
|
export * from './types.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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0cG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
* @example
|
|
31
31
|
* ```typescript
|
|
32
32
|
* import { Component, OnChanges, computed, input } from '@angular/core'
|
|
33
|
+
* import { useTranslation } from '@molecule/app-angular'
|
|
33
34
|
* import { getClient, isHttpError } from '@molecule/app-http'
|
|
34
|
-
* import { t } from '@molecule/app-i18n'
|
|
35
35
|
* import { intentPrefetchProps, useQuery } from '@molecule/app-query-angular'
|
|
36
36
|
*
|
|
37
37
|
* interface PackageDocument {
|
|
@@ -96,8 +96,8 @@
|
|
|
96
96
|
* `,
|
|
97
97
|
* })
|
|
98
98
|
* export class PackagePage {
|
|
99
|
-
* //
|
|
100
|
-
* protected readonly t = t
|
|
99
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
100
|
+
* protected readonly t = useTranslation().t
|
|
101
101
|
* readonly name = input('')
|
|
102
102
|
*
|
|
103
103
|
* readonly query = useQuery<PackageDocument | null>(
|
|
@@ -123,8 +123,8 @@
|
|
|
123
123
|
*
|
|
124
124
|
* ```typescript
|
|
125
125
|
* import { Component, computed, input } from '@angular/core'
|
|
126
|
+
* import { useTranslation } from '@molecule/app-angular'
|
|
126
127
|
* import { getClient, unwrapList } from '@molecule/app-http'
|
|
127
|
-
* import { t } from '@molecule/app-i18n'
|
|
128
128
|
* import { useQuery } from '@molecule/app-query-angular'
|
|
129
129
|
*
|
|
130
130
|
* interface Invoice {
|
|
@@ -153,8 +153,8 @@
|
|
|
153
153
|
* `,
|
|
154
154
|
* })
|
|
155
155
|
* export class InvoiceList {
|
|
156
|
-
* //
|
|
157
|
-
* protected readonly t = t
|
|
156
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
157
|
+
* protected readonly t = useTranslation().t
|
|
158
158
|
* // The viewer whose invoices these are (also in the key).
|
|
159
159
|
* readonly viewer = input('anonymous')
|
|
160
160
|
* // The page to show.
|
|
@@ -187,8 +187,8 @@
|
|
|
187
187
|
*
|
|
188
188
|
* ```typescript
|
|
189
189
|
* import { Component, input } from '@angular/core'
|
|
190
|
+
* import { useTranslation } from '@molecule/app-angular'
|
|
190
191
|
* import { getClient } from '@molecule/app-http'
|
|
191
|
-
* import { t } from '@molecule/app-i18n'
|
|
192
192
|
* import { getQueryClient } from '@molecule/app-query'
|
|
193
193
|
*
|
|
194
194
|
* // The key names what the document actually depends on — here the signed-in
|
|
@@ -222,8 +222,8 @@
|
|
|
222
222
|
* host: { type: 'button', '(click)': 'retry()' },
|
|
223
223
|
* })
|
|
224
224
|
* export class FeedRetry {
|
|
225
|
-
* //
|
|
226
|
-
* protected readonly t = t
|
|
225
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
226
|
+
* protected readonly t = useTranslation().t
|
|
227
227
|
* readonly principal = input.required<string>()
|
|
228
228
|
*
|
|
229
229
|
* retry(): void {
|
|
@@ -250,8 +250,8 @@
|
|
|
250
250
|
*
|
|
251
251
|
* ```typescript
|
|
252
252
|
* import { Component, computed, input } from '@angular/core'
|
|
253
|
+
* import { useTranslation } from '@molecule/app-angular'
|
|
253
254
|
* import { getClient, unwrapList, unwrapSingle } from '@molecule/app-http'
|
|
254
|
-
* import { t } from '@molecule/app-i18n'
|
|
255
255
|
* import { OptimisticToggleButton } from '@molecule/app-ui-angular'
|
|
256
256
|
* import { createQueryResource, QueryContent, useQuery } from '@molecule/app-query-angular'
|
|
257
257
|
*
|
|
@@ -287,7 +287,8 @@
|
|
|
287
287
|
* export class InvoiceFlagControl {
|
|
288
288
|
* readonly invoice = input.required<Invoice>()
|
|
289
289
|
* readonly viewer = input.required<string>()
|
|
290
|
-
*
|
|
290
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
291
|
+
* protected readonly t = useTranslation().t
|
|
291
292
|
*
|
|
292
293
|
* readonly save = async (flagged: boolean): Promise<boolean> =>
|
|
293
294
|
* (await invoices.toggle(this.viewer(), this.invoice().id, 'flag', flagged)).flagged
|
|
@@ -324,8 +325,8 @@
|
|
|
324
325
|
* imports: [QueryContent, InvoiceFlagControl],
|
|
325
326
|
* })
|
|
326
327
|
* export class InvoicePage {
|
|
327
|
-
* //
|
|
328
|
-
* protected readonly t = t
|
|
328
|
+
* // The binding's t re-runs the template on a locale switch.
|
|
329
|
+
* protected readonly t = useTranslation().t
|
|
329
330
|
* readonly id = input('')
|
|
330
331
|
* readonly viewer = input('')
|
|
331
332
|
*
|
|
@@ -456,6 +457,7 @@
|
|
|
456
457
|
*
|
|
457
458
|
* @module
|
|
458
459
|
*/
|
|
460
|
+
export * from './list-query.js';
|
|
459
461
|
export * from './query-content.component.js';
|
|
460
462
|
export * from './resource.js';
|
|
461
463
|
export * from './types.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0cG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useListQuery`: one cached read driven by a URL list route.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type Signal } from '@angular/core';
|
|
7
|
+
import type { QueryOptions } from '@molecule/app-query';
|
|
8
|
+
import type { UseQueryResult } from './types.js';
|
|
9
|
+
/** A plain value or a signal: each input {@link useListQuery} reads reactively. */
|
|
10
|
+
export type ListQuerySource<T> = T | Signal<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-angular` returns these
|
|
17
|
+
* signals (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: Signal<boolean>;
|
|
22
|
+
/** The current URL filter values. */
|
|
23
|
+
readonly filters: Signal<Readonly<Record<Filter, string | undefined>>>;
|
|
24
|
+
/** The configured items per page. */
|
|
25
|
+
readonly pageSize: Signal<number>;
|
|
26
|
+
/** The zero-indexed item offset for the API request. */
|
|
27
|
+
readonly offset: Signal<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 in an injection context, as {@link useQuery}.
|
|
45
|
+
*
|
|
46
|
+
* @param route - The list route, usually `useListRoute(...)` from `@molecule/app-angular`.
|
|
47
|
+
* @param inputs - Plain values or signals; `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 {@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>): 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,EAAsB,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAGhD,mFAAmF;AACnF,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;AAE9C,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,MAAM,CAAC,OAAO,CAAC,CAAA;IACjC,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;IACtE,qCAAqC;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IACjC,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;CAChC;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;AAUD;;;;;;;;;;;;;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,cAAc,CAAC,CAAC,CAAC,CAcnB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useListQuery`: one cached read driven by a URL list route.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { computed, isSignal } from '@angular/core';
|
|
7
|
+
import { useQuery } from './use-query.js';
|
|
8
|
+
/**
|
|
9
|
+
* Reads a plain value or a signal; inside the query's computed options the read is tracked.
|
|
10
|
+
*
|
|
11
|
+
* @param source - The argument as the caller passed it.
|
|
12
|
+
* @returns Its current value.
|
|
13
|
+
*/
|
|
14
|
+
const current = (source) => (isSignal(source) ? source() : source);
|
|
15
|
+
/**
|
|
16
|
+
* Observe the page a URL list route points at. `read` builds the query from the current value of
|
|
17
|
+
* each input (the signed-in `viewer`, request params, a parent record's id) and the route's
|
|
18
|
+
* filters, page size and offset. The query is disabled (`null`, no request) while `viewer` is
|
|
19
|
+
* null (auth is still being restored) or the route cannot load yet; a changed input or URL moves
|
|
20
|
+
* the same observer to the new page.
|
|
21
|
+
* Call it in an injection context, as {@link useQuery}.
|
|
22
|
+
*
|
|
23
|
+
* @param route - The list route, usually `useListRoute(...)` from `@molecule/app-angular`.
|
|
24
|
+
* @param inputs - Plain values or signals; `viewer` is the signed-in user's id, 'anonymous',
|
|
25
|
+
* or null while auth is restoring.
|
|
26
|
+
* @param read - Builds the page's query options, e.g. a generated `articlesPage(...)`.
|
|
27
|
+
* @returns The query state, as {@link useQuery} returns it.
|
|
28
|
+
*/
|
|
29
|
+
export function useListQuery(route, inputs, read) {
|
|
30
|
+
return useQuery(computed(() => {
|
|
31
|
+
const values = {};
|
|
32
|
+
for (const key of Object.keys(inputs))
|
|
33
|
+
values[key] = current(inputs[key]);
|
|
34
|
+
const { viewer } = values;
|
|
35
|
+
if (viewer === null || !route.canLoad())
|
|
36
|
+
return null;
|
|
37
|
+
return read({ ...values, viewer }, { filters: route.filters(), pageSize: route.pageSize(), offset: route.offset() });
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=list-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-query.js","sourceRoot":"","sources":["../src/list-query.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAA;AAK/D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAmCzC;;;;;GAKG;AACH,MAAM,OAAO,GAAG,CAAI,MAA0B,EAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAE5F;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAK1B,KAA6B,EAC7B,MAA+B,EAC/B,IAA4F;IAE5F,OAAO,QAAQ,CACb,QAAQ,CAAC,GAAG,EAAE;QACZ,MAAM,MAAM,GAAoB,EAAE,CAAA;QAClC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAqB;YACvD,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAuB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;QAC1D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAgB,CAAA;QACnC,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;YAAE,OAAO,IAAI,CAAA;QACpD,OAAO,IAAI,CACT,EAAE,GAAI,MAAiB,EAAE,MAAM,EAAE,EACjC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CACjF,CAAA;IACH,CAAC,CAAC,CACH,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-query-angular",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Angular 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-angular",
|
|
6
6
|
"type": "module",
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
"@angular/compiler-cli": "22.2.3",
|
|
57
57
|
"@angular/core": "22.2.3",
|
|
58
58
|
"@angular/platform-browser": "22.2.3",
|
|
59
|
-
"@molecule/app-angular": "3.
|
|
59
|
+
"@molecule/app-angular": "3.7.1",
|
|
60
60
|
"@molecule/app-framework-conformance": "0.0.0",
|
|
61
|
-
"@molecule/app-i18n": "1.2.
|
|
61
|
+
"@molecule/app-i18n": "1.2.2",
|
|
62
62
|
"@molecule/app-icons": "1.0.4",
|
|
63
63
|
"@molecule/app-query": "1.2.0",
|
|
64
64
|
"@molecule/app-query-memory": "1.0.5",
|
|
65
65
|
"@molecule/app-query-tanstack": "1.0.5",
|
|
66
|
-
"@molecule/app-ui": "1.
|
|
67
|
-
"@molecule/app-ui-angular": "1.
|
|
66
|
+
"@molecule/app-ui": "1.4.0",
|
|
67
|
+
"@molecule/app-ui-angular": "1.2.0",
|
|
68
68
|
"@types/node": "26.6.5",
|
|
69
69
|
"jsdom": "30.1.3",
|
|
70
70
|
"rxjs": "7.8.2",
|