@ahoo-wang/wow-react 9.9.0 → 10.0.0-alpha.4
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 +75 -71
- package/README.zh-CN.md +75 -73
- package/dist/hooks/useCountQuery.d.ts +17 -14
- package/dist/hooks/useFetcherCountQuery.d.ts +16 -15
- package/dist/hooks/useFetcherListQuery.d.ts +16 -14
- package/dist/hooks/useFetcherListStreamQuery.d.ts +19 -16
- package/dist/hooks/useFetcherPagedQuery.d.ts +15 -13
- package/dist/hooks/useFetcherSingleQuery.d.ts +16 -14
- package/dist/hooks/useListQuery.d.ts +16 -13
- package/dist/hooks/useListStreamQuery.d.ts +21 -17
- package/dist/hooks/usePagedQuery.d.ts +15 -12
- package/dist/hooks/useSingleQuery.d.ts +16 -13
- package/dist/index.es.js +38 -42
- package/dist/index.es.js.map +1 -1
- package/dist/internal/endpoint.d.ts +11 -14
- package/dist/internal/useEndpointRunner.d.ts +2 -2
- package/dist/internal/useListStream.d.ts +3 -3
- package/dist/internal/useQueryRunner.d.ts +1 -1
- package/dist/types.d.ts +22 -17
- package/package.json +9 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Condition } from '@ahoo-wang/wow-client/legacy';
|
|
1
|
+
import { CountQuery, CountResult } from '@ahoo-wang/wow-client';
|
|
3
2
|
import { Endpoint } from '../internal/endpoint.js';
|
|
4
3
|
import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
5
4
|
/**
|
|
@@ -10,7 +9,7 @@ import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
|
10
9
|
* @template E - The error type, `Error` by default
|
|
11
10
|
* @template Q - The filter type: `FilterExpression` by default
|
|
12
11
|
*/
|
|
13
|
-
export interface UseFetcherCountQueryOptions<FIELDS extends string = string, E = Error, Q extends
|
|
12
|
+
export interface UseFetcherCountQueryOptions<FIELDS extends string = string, E = Error, Q extends CountQuery<FIELDS> = CountQuery<FIELDS>> extends Omit<QueryHookOptions<Q, CountResult, E>, 'execute'>, Endpoint {
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* What {@link useFetcherCountQuery} returns: the count as `result`.
|
|
@@ -19,10 +18,10 @@ export interface UseFetcherCountQueryOptions<FIELDS extends string = string, E =
|
|
|
19
18
|
* @template E - The error type, `Error` by default
|
|
20
19
|
* @template Q - The filter type: `FilterExpression` by default
|
|
21
20
|
*/
|
|
22
|
-
export interface UseFetcherCountQueryReturn<FIELDS extends string = string, E = Error, Q extends
|
|
21
|
+
export interface UseFetcherCountQueryReturn<FIELDS extends string = string, E = Error, Q extends CountQuery<FIELDS> = CountQuery<FIELDS>> extends QueryHookReturn<Q, CountResult, E> {
|
|
23
22
|
}
|
|
24
23
|
/**
|
|
25
|
-
* POSTs a
|
|
24
|
+
* POSTs a count to a Wow query route through a Fetcher and keeps the
|
|
26
25
|
* count as state.
|
|
27
26
|
*
|
|
28
27
|
* `url` is resolved against the Fetcher's `baseURL`; `fetcher` is a Fetcher
|
|
@@ -38,28 +37,30 @@ export interface UseFetcherCountQueryReturn<FIELDS extends string = string, E =
|
|
|
38
37
|
*
|
|
39
38
|
* Returns `result` (the count, or `undefined` before the first success),
|
|
40
39
|
* `loading`, `error`, `status`, `execute`, `abort`, `reset`, `getQuery` and
|
|
41
|
-
* `setQuery`. A failed request sets `error` to
|
|
42
|
-
* `
|
|
43
|
-
* `errorCode` from it.
|
|
40
|
+
* `setQuery`. A failed request sets `error` to the
|
|
41
|
+
* `WowProblemError` the route answered with.
|
|
44
42
|
*
|
|
45
43
|
* @template FIELDS - The field names the filter may use
|
|
46
44
|
* @template E - The error type, `Error` by default
|
|
47
45
|
*
|
|
48
46
|
* @example
|
|
49
47
|
* ```tsx
|
|
50
|
-
* import { filter } from '@ahoo-wang/wow-client';
|
|
48
|
+
* import { filter } from '@ahoo-wang/wow-client/dsl';
|
|
51
49
|
* import { useFetcherCountQuery } from '@ahoo-wang/wow-react';
|
|
52
50
|
*
|
|
53
51
|
* function PaidCount() {
|
|
54
52
|
* const { result, error } = useFetcherCountQuery({
|
|
55
|
-
* url: 'order/snapshot/
|
|
56
|
-
* initialQuery: filter.eq('state.status', 'PAID'),
|
|
53
|
+
* url: '/shop/order/snapshot/query',
|
|
54
|
+
* initialQuery: { filter: filter.eq('state.status', 'PAID') },
|
|
57
55
|
* });
|
|
58
56
|
* if (error) return <p role="alert">{error.message}</p>;
|
|
59
|
-
* return <p>{result ?? '…'} paid orders</p>;
|
|
57
|
+
* return <p>{result?.count ?? '…'} paid orders</p>;
|
|
60
58
|
* }
|
|
61
59
|
* ```
|
|
62
60
|
*/
|
|
63
|
-
export declare function useFetcherCountQuery<FIELDS extends string = string, E = Error>(options: UseFetcherCountQueryOptions<FIELDS, E,
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
export declare function useFetcherCountQuery<FIELDS extends string = string, E = Error>(options: UseFetcherCountQueryOptions<FIELDS, E, CountQuery<FIELDS>>): UseFetcherCountQueryReturn<FIELDS, E, CountQuery<FIELDS>>;
|
|
62
|
+
/**
|
|
63
|
+
* {@link useFetcherCountQuery} typed by a query `Q` of your own, a subtype of
|
|
64
|
+
* `CountQuery`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function useFetcherCountQuery<FIELDS extends string = string, E = Error, Q extends CountQuery<FIELDS> = CountQuery<FIELDS>>(options: UseFetcherCountQueryOptions<FIELDS, E, Q>): UseFetcherCountQueryReturn<FIELDS, E, Q>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { FilterListQuery } from '@ahoo-wang/wow-client';
|
|
2
|
-
import { ListQuery, ListQueryRequest } from '@ahoo-wang/wow-client/legacy';
|
|
1
|
+
import { FilterListQuery } from '@ahoo-wang/wow-client/dsl';
|
|
3
2
|
import { Endpoint } from '../internal/endpoint.js';
|
|
4
3
|
import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
5
4
|
/**
|
|
@@ -11,7 +10,7 @@ import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
|
11
10
|
* @template E - The error type, `Error` by default
|
|
12
11
|
* @template Q - The query type: `FilterListQuery` by default
|
|
13
12
|
*/
|
|
14
|
-
export interface UseFetcherListQueryOptions<R, FIELDS extends string = string, E = Error, Q extends
|
|
13
|
+
export interface UseFetcherListQueryOptions<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>> extends Omit<QueryHookOptions<Q, R[], E>, 'execute'>, Endpoint {
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* What {@link useFetcherListQuery} returns: the rows as `result`.
|
|
@@ -21,10 +20,10 @@ export interface UseFetcherListQueryOptions<R, FIELDS extends string = string, E
|
|
|
21
20
|
* @template E - The error type, `Error` by default
|
|
22
21
|
* @template Q - The query type: `FilterListQuery` by default
|
|
23
22
|
*/
|
|
24
|
-
export interface UseFetcherListQueryReturn<R, FIELDS extends string = string, E = Error, Q extends
|
|
23
|
+
export interface UseFetcherListQueryReturn<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>> extends QueryHookReturn<Q, R[], E> {
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
|
-
* POSTs a list query to a Wow
|
|
26
|
+
* POSTs a list query to a Wow query route through a Fetcher and keeps the rows
|
|
28
27
|
* as state.
|
|
29
28
|
*
|
|
30
29
|
* `url` is resolved against the Fetcher's `baseURL`; `fetcher` is a Fetcher
|
|
@@ -40,9 +39,8 @@ export interface UseFetcherListQueryReturn<R, FIELDS extends string = string, E
|
|
|
40
39
|
*
|
|
41
40
|
* Returns `result` (the rows, or `undefined` before the first success),
|
|
42
41
|
* `loading`, `error`, `status`, `execute`, `abort`, `reset`, `getQuery` and
|
|
43
|
-
* `setQuery`. A failed request sets `error` to
|
|
44
|
-
* `
|
|
45
|
-
* `errorCode` from it.
|
|
42
|
+
* `setQuery`. A failed request sets `error` to the
|
|
43
|
+
* `WowProblemError` the route answered with.
|
|
46
44
|
*
|
|
47
45
|
* @template R - One row of the list
|
|
48
46
|
* @template FIELDS - The field names the query may use
|
|
@@ -50,12 +48,13 @@ export interface UseFetcherListQueryReturn<R, FIELDS extends string = string, E
|
|
|
50
48
|
*
|
|
51
49
|
* @example
|
|
52
50
|
* ```tsx
|
|
53
|
-
* import { desc, filter, listQuery } from '@ahoo-wang/wow-client';
|
|
51
|
+
* import { desc, filter, listQuery } from '@ahoo-wang/wow-client/dsl';
|
|
52
|
+
* import type { SnapshotRecord } from '@ahoo-wang/wow-client';
|
|
54
53
|
* import { useFetcherListQuery } from '@ahoo-wang/wow-react';
|
|
55
54
|
*
|
|
56
55
|
* function LatestOrders() {
|
|
57
|
-
* const { result, loading, error, execute } = useFetcherListQuery<OrderState
|
|
58
|
-
* url: 'order/snapshot/
|
|
56
|
+
* const { result, loading, error, execute } = useFetcherListQuery<SnapshotRecord<OrderState>>({
|
|
57
|
+
* url: '/shop/order/snapshot/query',
|
|
59
58
|
* initialQuery: listQuery({
|
|
60
59
|
* filter: filter.eq('state.status', 'PAID'),
|
|
61
60
|
* sort: [desc('createTime')],
|
|
@@ -66,7 +65,7 @@ export interface UseFetcherListQueryReturn<R, FIELDS extends string = string, E
|
|
|
66
65
|
* if (loading || !result) return <p>Loading…</p>;
|
|
67
66
|
* return (
|
|
68
67
|
* <>
|
|
69
|
-
* <ul>{result.map(order => <li key={order.
|
|
68
|
+
* <ul>{result.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>
|
|
70
69
|
* <button onClick={execute}>Refresh</button>
|
|
71
70
|
* </>
|
|
72
71
|
* );
|
|
@@ -74,5 +73,8 @@ export interface UseFetcherListQueryReturn<R, FIELDS extends string = string, E
|
|
|
74
73
|
* ```
|
|
75
74
|
*/
|
|
76
75
|
export declare function useFetcherListQuery<R, FIELDS extends string = string, E = Error>(options: UseFetcherListQueryOptions<R, FIELDS, E, FilterListQuery<FIELDS>>): UseFetcherListQueryReturn<R, FIELDS, E, FilterListQuery<FIELDS>>;
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
/**
|
|
77
|
+
* {@link useFetcherListQuery} typed by a query `Q` of your own, a subtype of
|
|
78
|
+
* `FilterListQuery`, such as one whose literal projection narrows the result.
|
|
79
|
+
*/
|
|
80
|
+
export declare function useFetcherListQuery<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>>(options: UseFetcherListQueryOptions<R, FIELDS, E, Q>): UseFetcherListQueryReturn<R, FIELDS, E, Q>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { FilterListQuery } from '@ahoo-wang/wow-client';
|
|
2
|
-
import { ListQuery, ListQueryRequest } from '@ahoo-wang/wow-client/legacy';
|
|
1
|
+
import { FilterListQuery } from '@ahoo-wang/wow-client/dsl';
|
|
3
2
|
import { Endpoint } from '../internal/endpoint.js';
|
|
4
3
|
import { UseListStreamQueryOptions, UseListStreamQueryReturn } from './useListStreamQuery.js';
|
|
5
4
|
/**
|
|
@@ -9,26 +8,26 @@ import { UseListStreamQueryOptions, UseListStreamQueryReturn } from './useListSt
|
|
|
9
8
|
* @template R - One row of the stream: the `data` of each event
|
|
10
9
|
* @template FIELDS - The field names the query may use
|
|
11
10
|
* @template E - The error type, `Error` by default: a failed request
|
|
12
|
-
* rejects with a `
|
|
13
|
-
*
|
|
11
|
+
* rejects with a `WowProblemError`, and so does an error event in the
|
|
12
|
+
* stream
|
|
14
13
|
* @template Q - The query type: `FilterListQuery` by default
|
|
15
14
|
*/
|
|
16
|
-
export interface UseFetcherListStreamQueryOptions<R, FIELDS extends string = string, E = Error, Q extends
|
|
15
|
+
export interface UseFetcherListStreamQueryOptions<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>> extends Omit<UseListStreamQueryOptions<R, FIELDS, E, Q>, 'execute'>, Endpoint {
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* What {@link useFetcherListStreamQuery} returns; see
|
|
20
19
|
* {@link UseListStreamQueryReturn}.
|
|
21
20
|
*/
|
|
22
|
-
export interface UseFetcherListStreamQueryReturn<R, FIELDS extends string = string, E = Error, Q extends
|
|
21
|
+
export interface UseFetcherListStreamQueryReturn<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>> extends UseListStreamQueryReturn<R, FIELDS, E, Q> {
|
|
23
22
|
}
|
|
24
23
|
/**
|
|
25
|
-
* Streams the rows of a list query from a Wow
|
|
24
|
+
* Streams the rows of a list query from a Wow query route and keeps them as
|
|
26
25
|
* state; see `useListStreamQuery` for the state it returns.
|
|
27
26
|
*
|
|
28
27
|
* It POSTs the query to `url` through `fetcher` (the default Fetcher when
|
|
29
|
-
* omitted) with `Accept: text/event-stream`, the header a Wow
|
|
30
|
-
* answer with an event stream rather than JSON. An error event in the
|
|
31
|
-
* ends it with a `
|
|
28
|
+
* omitted) with `Accept: text/event-stream`, the header a Wow service needs
|
|
29
|
+
* to answer with an event stream rather than JSON. An error event in the
|
|
30
|
+
* stream ends it with a `WowProblemError` in `error`.
|
|
32
31
|
*
|
|
33
32
|
* A change of `url`, or of `fetcher`, runs the query again. A Fetcher is
|
|
34
33
|
* compared by its name, or by its `baseURL` when it has none, so one created
|
|
@@ -40,18 +39,19 @@ export interface UseFetcherListStreamQueryReturn<R, FIELDS extends string = stri
|
|
|
40
39
|
*
|
|
41
40
|
* @example
|
|
42
41
|
* ```tsx
|
|
43
|
-
* import { filter, listQuery } from '@ahoo-wang/wow-client';
|
|
42
|
+
* import { filter, listQuery } from '@ahoo-wang/wow-client/dsl';
|
|
43
|
+
* import type { SnapshotRecord } from '@ahoo-wang/wow-client';
|
|
44
44
|
* import { useFetcherListStreamQuery } from '@ahoo-wang/wow-react';
|
|
45
45
|
*
|
|
46
46
|
* function PaidOrders() {
|
|
47
|
-
* const { items, done, loading, error } = useFetcherListStreamQuery<OrderState
|
|
48
|
-
* url: 'order/snapshot/
|
|
47
|
+
* const { items, done, loading, error } = useFetcherListStreamQuery<SnapshotRecord<OrderState>>({
|
|
48
|
+
* url: '/shop/order/snapshot/query',
|
|
49
49
|
* initialQuery: listQuery({ filter: filter.eq('state.status', 'PAID') }),
|
|
50
50
|
* });
|
|
51
51
|
* if (error) return <p role="alert">{error.message}</p>;
|
|
52
52
|
* return (
|
|
53
53
|
* <>
|
|
54
|
-
* <ul>{items.map(order => <li key={order.
|
|
54
|
+
* <ul>{items.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>
|
|
55
55
|
* {loading ? <p>Loading…</p> : done && <p>{items.length} orders</p>}
|
|
56
56
|
* </>
|
|
57
57
|
* );
|
|
@@ -59,5 +59,8 @@ export interface UseFetcherListStreamQueryReturn<R, FIELDS extends string = stri
|
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
61
|
export declare function useFetcherListStreamQuery<R, FIELDS extends string = string, E = Error>(options: UseFetcherListStreamQueryOptions<R, FIELDS, E, FilterListQuery<FIELDS>>): UseFetcherListStreamQueryReturn<R, FIELDS, E, FilterListQuery<FIELDS>>;
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
/**
|
|
63
|
+
* {@link useFetcherListStreamQuery} typed by a query `Q` of your own, a subtype of
|
|
64
|
+
* `FilterListQuery`, such as one whose literal projection narrows the result.
|
|
65
|
+
*/
|
|
66
|
+
export declare function useFetcherListStreamQuery<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>>(options: UseFetcherListStreamQueryOptions<R, FIELDS, E, Q>): UseFetcherListStreamQueryReturn<R, FIELDS, E, Q>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PagedQuery, PagedQueryRequest } from '@ahoo-wang/wow-client/legacy';
|
|
1
|
+
import { PagedQuery, PagedResult } from '@ahoo-wang/wow-client';
|
|
3
2
|
import { Endpoint } from '../internal/endpoint.js';
|
|
4
3
|
import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
5
4
|
/**
|
|
@@ -11,7 +10,7 @@ import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
|
11
10
|
* @template E - The error type, `Error` by default
|
|
12
11
|
* @template Q - The query type: `FilterPagedQuery` by default
|
|
13
12
|
*/
|
|
14
|
-
export interface UseFetcherPagedQueryOptions<R, FIELDS extends string = string, E = Error, Q extends
|
|
13
|
+
export interface UseFetcherPagedQueryOptions<R, FIELDS extends string = string, E = Error, Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>> extends Omit<QueryHookOptions<Q, PagedResult<R>, E>, 'execute'>, Endpoint {
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* What {@link useFetcherPagedQuery} returns: the page (`total` and `list`)
|
|
@@ -22,10 +21,10 @@ export interface UseFetcherPagedQueryOptions<R, FIELDS extends string = string,
|
|
|
22
21
|
* @template E - The error type, `Error` by default
|
|
23
22
|
* @template Q - The query type: `FilterPagedQuery` by default
|
|
24
23
|
*/
|
|
25
|
-
export interface UseFetcherPagedQueryReturn<R, FIELDS extends string = string, E = Error, Q extends
|
|
24
|
+
export interface UseFetcherPagedQueryReturn<R, FIELDS extends string = string, E = Error, Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>> extends QueryHookReturn<Q, PagedResult<R>, E> {
|
|
26
25
|
}
|
|
27
26
|
/**
|
|
28
|
-
* POSTs a paged query to a Wow
|
|
27
|
+
* POSTs a paged query to a Wow query route through a Fetcher and keeps the page
|
|
29
28
|
* as state.
|
|
30
29
|
*
|
|
31
30
|
* `url` is resolved against the Fetcher's `baseURL`; `fetcher` is a Fetcher
|
|
@@ -41,9 +40,8 @@ export interface UseFetcherPagedQueryReturn<R, FIELDS extends string = string, E
|
|
|
41
40
|
*
|
|
42
41
|
* Returns `result` (`{ total, list }`, or `undefined` before the first
|
|
43
42
|
* success), `loading`, `error`, `status`, `execute`, `abort`, `reset`,
|
|
44
|
-
* `getQuery` and `setQuery`. A failed request sets `error` to
|
|
45
|
-
* `
|
|
46
|
-
* server's `errorCode` from it.
|
|
43
|
+
* `getQuery` and `setQuery`. A failed request sets `error` to the
|
|
44
|
+
* `WowProblemError` the route answered with.
|
|
47
45
|
*
|
|
48
46
|
* @template R - One row of the page
|
|
49
47
|
* @template FIELDS - The field names the query may use
|
|
@@ -51,12 +49,13 @@ export interface UseFetcherPagedQueryReturn<R, FIELDS extends string = string, E
|
|
|
51
49
|
*
|
|
52
50
|
* @example
|
|
53
51
|
* ```tsx
|
|
54
|
-
* import { filter, pagedQuery } from '@ahoo-wang/wow-client';
|
|
52
|
+
* import { filter, pagedQuery } from '@ahoo-wang/wow-client/dsl';
|
|
53
|
+
* import type { SnapshotRecord } from '@ahoo-wang/wow-client';
|
|
55
54
|
* import { useFetcherPagedQuery } from '@ahoo-wang/wow-react';
|
|
56
55
|
*
|
|
57
56
|
* function PaidOrders({ page }: { page: number }) {
|
|
58
|
-
* const { result, loading, error } = useFetcherPagedQuery<OrderState
|
|
59
|
-
* url: 'order/snapshot/
|
|
57
|
+
* const { result, loading, error } = useFetcherPagedQuery<SnapshotRecord<OrderState>>({
|
|
58
|
+
* url: '/shop/order/snapshot/query',
|
|
60
59
|
* query: pagedQuery({
|
|
61
60
|
* filter: filter.eq('state.status', 'PAID'),
|
|
62
61
|
* pagination: { index: page, size: 20 },
|
|
@@ -68,6 +67,9 @@ export interface UseFetcherPagedQueryReturn<R, FIELDS extends string = string, E
|
|
|
68
67
|
* }
|
|
69
68
|
* ```
|
|
70
69
|
*/
|
|
71
|
-
export declare function useFetcherPagedQuery<R, FIELDS extends string = string, E = Error>(options: UseFetcherPagedQueryOptions<R, FIELDS, E, FilterPagedQuery<FIELDS>>): UseFetcherPagedQueryReturn<R, FIELDS, E, FilterPagedQuery<FIELDS>>;
|
|
72
70
|
export declare function useFetcherPagedQuery<R, FIELDS extends string = string, E = Error>(options: UseFetcherPagedQueryOptions<R, FIELDS, E, PagedQuery<FIELDS>>): UseFetcherPagedQueryReturn<R, FIELDS, E, PagedQuery<FIELDS>>;
|
|
73
|
-
|
|
71
|
+
/**
|
|
72
|
+
* {@link useFetcherPagedQuery} typed by a query `Q` of your own, a subtype of
|
|
73
|
+
* `PagedQuery`, such as one whose literal projection narrows the result.
|
|
74
|
+
*/
|
|
75
|
+
export declare function useFetcherPagedQuery<R, FIELDS extends string = string, E = Error, Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>>(options: UseFetcherPagedQueryOptions<R, FIELDS, E, Q>): UseFetcherPagedQueryReturn<R, FIELDS, E, Q>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { FilterSingleQuery } from '@ahoo-wang/wow-client';
|
|
2
|
-
import { SingleQuery, SingleQueryRequest } from '@ahoo-wang/wow-client/legacy';
|
|
1
|
+
import { FilterSingleQuery } from '@ahoo-wang/wow-client/dsl';
|
|
3
2
|
import { Endpoint } from '../internal/endpoint.js';
|
|
4
3
|
import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
5
4
|
/**
|
|
@@ -11,7 +10,7 @@ import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
|
11
10
|
* @template E - The error type, `Error` by default
|
|
12
11
|
* @template Q - The query type: `FilterSingleQuery` by default
|
|
13
12
|
*/
|
|
14
|
-
export interface UseFetcherSingleQueryOptions<R, FIELDS extends string = string, E = Error, Q extends
|
|
13
|
+
export interface UseFetcherSingleQueryOptions<R, FIELDS extends string = string, E = Error, Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>> extends Omit<QueryHookOptions<Q, R, E>, 'execute'>, Endpoint {
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* What {@link useFetcherSingleQuery} returns: the item as `result`.
|
|
@@ -21,10 +20,10 @@ export interface UseFetcherSingleQueryOptions<R, FIELDS extends string = string,
|
|
|
21
20
|
* @template E - The error type, `Error` by default
|
|
22
21
|
* @template Q - The query type: `FilterSingleQuery` by default
|
|
23
22
|
*/
|
|
24
|
-
export interface UseFetcherSingleQueryReturn<R, FIELDS extends string = string, E = Error, Q extends
|
|
23
|
+
export interface UseFetcherSingleQueryReturn<R, FIELDS extends string = string, E = Error, Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>> extends QueryHookReturn<Q, R, E> {
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
|
-
* POSTs a single query to a Wow
|
|
26
|
+
* POSTs a single query to a Wow query route through a Fetcher and keeps the
|
|
28
27
|
* result as state.
|
|
29
28
|
*
|
|
30
29
|
* `url` is resolved against the Fetcher's `baseURL`; `fetcher` is a Fetcher
|
|
@@ -40,9 +39,8 @@ export interface UseFetcherSingleQueryReturn<R, FIELDS extends string = string,
|
|
|
40
39
|
*
|
|
41
40
|
* Returns `result` (the item, or `undefined` before the first success),
|
|
42
41
|
* `loading`, `error`, `status`, `execute`, `abort`, `reset`, `getQuery` and
|
|
43
|
-
* `setQuery`. A failed request sets `error` to
|
|
44
|
-
* `
|
|
45
|
-
* `errorCode` from it.
|
|
42
|
+
* `setQuery`. A failed request sets `error` to the
|
|
43
|
+
* `WowProblemError` the route answered with.
|
|
46
44
|
*
|
|
47
45
|
* @template R - The item the query returns
|
|
48
46
|
* @template FIELDS - The field names the query may use
|
|
@@ -50,20 +48,24 @@ export interface UseFetcherSingleQueryReturn<R, FIELDS extends string = string,
|
|
|
50
48
|
*
|
|
51
49
|
* @example
|
|
52
50
|
* ```tsx
|
|
53
|
-
* import { filter, singleQuery } from '@ahoo-wang/wow-client';
|
|
51
|
+
* import { filter, singleQuery } from '@ahoo-wang/wow-client/dsl';
|
|
52
|
+
* import type { SnapshotRecord } from '@ahoo-wang/wow-client';
|
|
54
53
|
* import { useFetcherSingleQuery } from '@ahoo-wang/wow-react';
|
|
55
54
|
*
|
|
56
55
|
* function OrderStatus({ id }: { id: string }) {
|
|
57
|
-
* const { result, loading, error } = useFetcherSingleQuery<OrderState
|
|
58
|
-
* url: 'order/snapshot/
|
|
56
|
+
* const { result, loading, error } = useFetcherSingleQuery<SnapshotRecord<OrderState>>({
|
|
57
|
+
* url: '/shop/order/snapshot/query',
|
|
59
58
|
* query: singleQuery({ filter: filter.id(id) }),
|
|
60
59
|
* });
|
|
61
60
|
* if (error) return <p role="alert">{error.message}</p>;
|
|
62
61
|
* if (loading || !result) return <p>Loading…</p>;
|
|
63
|
-
* return <p>{result.status}</p>;
|
|
62
|
+
* return <p>{result.state.status}</p>;
|
|
64
63
|
* }
|
|
65
64
|
* ```
|
|
66
65
|
*/
|
|
67
66
|
export declare function useFetcherSingleQuery<R, FIELDS extends string = string, E = Error>(options: UseFetcherSingleQueryOptions<R, FIELDS, E, FilterSingleQuery<FIELDS>>): UseFetcherSingleQueryReturn<R, FIELDS, E, FilterSingleQuery<FIELDS>>;
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
/**
|
|
68
|
+
* {@link useFetcherSingleQuery} typed by a query `Q` of your own, a subtype of
|
|
69
|
+
* `FilterSingleQuery`, such as one whose literal projection narrows the result.
|
|
70
|
+
*/
|
|
71
|
+
export declare function useFetcherSingleQuery<R, FIELDS extends string = string, E = Error, Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>>(options: UseFetcherSingleQueryOptions<R, FIELDS, E, Q>): UseFetcherSingleQueryReturn<R, FIELDS, E, Q>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { FilterListQuery } from '@ahoo-wang/wow-client';
|
|
2
|
-
import { ListQuery, ListQueryRequest } from '@ahoo-wang/wow-client/legacy';
|
|
1
|
+
import { FilterListQuery } from '@ahoo-wang/wow-client/dsl';
|
|
3
2
|
import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
4
3
|
/**
|
|
5
4
|
* Options of {@link useListQuery}: a list query and an `execute` that resolves
|
|
@@ -10,7 +9,7 @@ import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
|
10
9
|
* @template E - The error type, `Error` by default
|
|
11
10
|
* @template Q - The query type: `FilterListQuery` by default
|
|
12
11
|
*/
|
|
13
|
-
export interface UseListQueryOptions<R, FIELDS extends string = string, E = Error, Q extends
|
|
12
|
+
export interface UseListQueryOptions<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>> extends QueryHookOptions<Q, R[], E> {
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* What {@link useListQuery} returns: the rows as `result`.
|
|
@@ -20,14 +19,14 @@ export interface UseListQueryOptions<R, FIELDS extends string = string, E = Erro
|
|
|
20
19
|
* @template E - The error type, `Error` by default
|
|
21
20
|
* @template Q - The query type: `FilterListQuery` by default
|
|
22
21
|
*/
|
|
23
|
-
export interface UseListQueryReturn<R, FIELDS extends string = string, E = Error, Q extends
|
|
22
|
+
export interface UseListQueryReturn<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>> extends QueryHookReturn<Q, R[], E> {
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
26
25
|
* Runs a list query through your own `execute` function and keeps the rows
|
|
27
26
|
* as state: typically a query client's `list` or `listState`.
|
|
28
27
|
*
|
|
29
|
-
* `execute` receives the query
|
|
30
|
-
* `
|
|
28
|
+
* `execute` receives the query and the request options of the run, its
|
|
29
|
+
* `signal` included; hand them on so that a newer query, `abort()`
|
|
31
30
|
* or an unmount cancels the request. The query runs on mount and whenever
|
|
32
31
|
* `query` or `setQuery()` changes it; set `autoExecute: false` to run it only
|
|
33
32
|
* through `execute()`.
|
|
@@ -44,25 +43,29 @@ export interface UseListQueryReturn<R, FIELDS extends string = string, E = Error
|
|
|
44
43
|
*
|
|
45
44
|
* @example
|
|
46
45
|
* ```tsx
|
|
47
|
-
* import {
|
|
46
|
+
* import type { SnapshotQueryClient, SnapshotRecord } from '@ahoo-wang/wow-client';
|
|
47
|
+
* import { desc, filter, listQuery } from '@ahoo-wang/wow-client/dsl';
|
|
48
48
|
* import { useListQuery } from '@ahoo-wang/wow-react';
|
|
49
49
|
*
|
|
50
50
|
* function LatestOrders({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {
|
|
51
|
-
* const { result, loading, error } = useListQuery<OrderState
|
|
51
|
+
* const { result, loading, error } = useListQuery<SnapshotRecord<OrderState>, OrderFields>({
|
|
52
52
|
* initialQuery: listQuery({
|
|
53
53
|
* filter: filter.eq('state.status', 'PAID'),
|
|
54
54
|
* sort: [desc('createTime')],
|
|
55
55
|
* limit: 20,
|
|
56
56
|
* }),
|
|
57
|
-
* execute: (query,
|
|
58
|
-
* client.
|
|
57
|
+
* execute: (query, options) =>
|
|
58
|
+
* client.list(query, options),
|
|
59
59
|
* });
|
|
60
60
|
* if (error) return <p role="alert">{error.message}</p>;
|
|
61
61
|
* if (loading || !result) return <p>Loading…</p>;
|
|
62
|
-
* return <ul>{result.map(order => <li key={order.
|
|
62
|
+
* return <ul>{result.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>;
|
|
63
63
|
* }
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
66
|
export declare function useListQuery<R, FIELDS extends string = string, E = Error>(options: UseListQueryOptions<R, FIELDS, E, FilterListQuery<FIELDS>>): UseListQueryReturn<R, FIELDS, E, FilterListQuery<FIELDS>>;
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
/**
|
|
68
|
+
* {@link useListQuery} typed by a query `Q` of your own, a subtype of
|
|
69
|
+
* `FilterListQuery`, such as one whose literal projection narrows the result.
|
|
70
|
+
*/
|
|
71
|
+
export declare function useListQuery<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>>(options: UseListQueryOptions<R, FIELDS, E, Q>): UseListQueryReturn<R, FIELDS, E, Q>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { FilterListQuery } from '@ahoo-wang/wow-client';
|
|
2
|
-
import { ListQuery, ListQueryRequest } from '@ahoo-wang/wow-client/legacy';
|
|
1
|
+
import { FilterListQuery } from '@ahoo-wang/wow-client/dsl';
|
|
3
2
|
import { ListStreamExecutor, QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
4
3
|
/**
|
|
5
4
|
* Options of {@link useListStreamQuery}: those of every query hook, with an
|
|
@@ -10,11 +9,11 @@ import { ListStreamExecutor, QueryHookOptions, QueryHookReturn } from '../types.
|
|
|
10
9
|
* @template R - One row of the stream: the `data` of each event
|
|
11
10
|
* @template FIELDS - The field names the query may use
|
|
12
11
|
* @template E - The error type, `Error` by default: a failed request
|
|
13
|
-
* rejects with a `
|
|
14
|
-
*
|
|
12
|
+
* rejects with a `WowProblemError`, and so does an error event in the
|
|
13
|
+
* stream
|
|
15
14
|
* @template Q - The query type: `FilterListQuery` by default
|
|
16
15
|
*/
|
|
17
|
-
export interface UseListStreamQueryOptions<R, FIELDS extends string = string, E = Error, Q extends
|
|
16
|
+
export interface UseListStreamQueryOptions<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>> extends Omit<QueryHookOptions<Q, R[], E>, 'execute'> {
|
|
18
17
|
/** Opens the stream for a query. */
|
|
19
18
|
execute: ListStreamExecutor<R, Q>;
|
|
20
19
|
}
|
|
@@ -28,13 +27,13 @@ export interface UseListStreamQueryOptions<R, FIELDS extends string = string, E
|
|
|
28
27
|
* error keep the rows received before them.
|
|
29
28
|
* - `done` — the stream ended normally and `items` holds every row.
|
|
30
29
|
* - `loading` — from the request until the stream ends, fails or is aborted.
|
|
31
|
-
* - `error` — the request failed
|
|
32
|
-
*
|
|
30
|
+
* - `error` — the request failed, or the server sent an error event in the
|
|
31
|
+
* stream: a `WowProblemError`, with the problem's `code`.
|
|
33
32
|
* - `status` — `idle`, `loading`, `success` (the same as `done`) or `error`.
|
|
34
33
|
* - `execute()` runs the current query again and aborts the stream in flight;
|
|
35
34
|
* `abort()` stops the stream; `reset()` stops it and empties `items`.
|
|
36
35
|
*/
|
|
37
|
-
export interface UseListStreamQueryReturn<R, FIELDS extends string = string, E = Error, Q extends
|
|
36
|
+
export interface UseListStreamQueryReturn<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>> extends Omit<QueryHookReturn<Q, R[], E>, 'result'> {
|
|
38
37
|
/**
|
|
39
38
|
* The rows of the current query received so far, a new array at every
|
|
40
39
|
* update.
|
|
@@ -52,8 +51,9 @@ export interface UseListStreamQueryReturn<R, FIELDS extends string = string, E =
|
|
|
52
51
|
* unmount. Components render `items` and never hold a reader, so the hook is
|
|
53
52
|
* safe under StrictMode. `autoExecute` defaults to `true`.
|
|
54
53
|
*
|
|
55
|
-
* Pass a query client
|
|
56
|
-
* `Accept: text/event-stream` and turns error events into a
|
|
54
|
+
* Pass a query client's `listStream` as `execute` — it sends
|
|
55
|
+
* `Accept: text/event-stream` and turns error events into a
|
|
56
|
+
* `WowProblemError` — or
|
|
57
57
|
* use `useFetcherListStreamQuery` with a URL.
|
|
58
58
|
*
|
|
59
59
|
* @template R - One row of the stream: the `data` of each event
|
|
@@ -64,19 +64,20 @@ export interface UseListStreamQueryReturn<R, FIELDS extends string = string, E =
|
|
|
64
64
|
*
|
|
65
65
|
* @example
|
|
66
66
|
* ```tsx
|
|
67
|
-
* import {
|
|
67
|
+
* import type { SnapshotQueryClient, SnapshotRecord } from '@ahoo-wang/wow-client';
|
|
68
|
+
* import { filter, listQuery } from '@ahoo-wang/wow-client/dsl';
|
|
68
69
|
* import { useListStreamQuery } from '@ahoo-wang/wow-react';
|
|
69
70
|
*
|
|
70
71
|
* function PaidOrders({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {
|
|
71
|
-
* const { items, done, loading, error, abort } = useListStreamQuery<OrderState
|
|
72
|
+
* const { items, done, loading, error, abort } = useListStreamQuery<SnapshotRecord<OrderState>, OrderFields>({
|
|
72
73
|
* initialQuery: listQuery({ filter: filter.eq('state.status', 'PAID') }),
|
|
73
|
-
* execute: (query,
|
|
74
|
-
* client.
|
|
74
|
+
* execute: (query, options) =>
|
|
75
|
+
* client.listStream(query, options),
|
|
75
76
|
* });
|
|
76
77
|
* if (error) return <p role="alert">{error.message}</p>;
|
|
77
78
|
* return (
|
|
78
79
|
* <>
|
|
79
|
-
* <ul>{items.map(order => <li key={order.
|
|
80
|
+
* <ul>{items.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>
|
|
80
81
|
* {loading && <button onClick={abort}>Stop</button>}
|
|
81
82
|
* {done && <p>{items.length} orders</p>}
|
|
82
83
|
* </>
|
|
@@ -85,5 +86,8 @@ export interface UseListStreamQueryReturn<R, FIELDS extends string = string, E =
|
|
|
85
86
|
* ```
|
|
86
87
|
*/
|
|
87
88
|
export declare function useListStreamQuery<R, FIELDS extends string = string, E = Error>(options: UseListStreamQueryOptions<R, FIELDS, E, FilterListQuery<FIELDS>>): UseListStreamQueryReturn<R, FIELDS, E, FilterListQuery<FIELDS>>;
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
/**
|
|
90
|
+
* {@link useListStreamQuery} typed by a query `Q` of your own, a subtype of
|
|
91
|
+
* `FilterListQuery`, such as one whose literal projection narrows the result.
|
|
92
|
+
*/
|
|
93
|
+
export declare function useListStreamQuery<R, FIELDS extends string = string, E = Error, Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>>(options: UseListStreamQueryOptions<R, FIELDS, E, Q>): UseListStreamQueryReturn<R, FIELDS, E, Q>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PagedQuery, PagedQueryRequest } from '@ahoo-wang/wow-client/legacy';
|
|
1
|
+
import { PagedQuery, PagedResult } from '@ahoo-wang/wow-client';
|
|
3
2
|
import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
4
3
|
/**
|
|
5
4
|
* Options of {@link usePagedQuery}: a paged query and an `execute` that
|
|
@@ -10,7 +9,7 @@ import { QueryHookOptions, QueryHookReturn } from '../types.js';
|
|
|
10
9
|
* @template E - The error type, `Error` by default
|
|
11
10
|
* @template Q - The query type: `FilterPagedQuery` by default
|
|
12
11
|
*/
|
|
13
|
-
export interface UsePagedQueryOptions<R, FIELDS extends string = string, E = Error, Q extends
|
|
12
|
+
export interface UsePagedQueryOptions<R, FIELDS extends string = string, E = Error, Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>> extends QueryHookOptions<Q, PagedResult<R>, E> {
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* What {@link usePagedQuery} returns: the page (`total` and `list`) as
|
|
@@ -21,14 +20,14 @@ export interface UsePagedQueryOptions<R, FIELDS extends string = string, E = Err
|
|
|
21
20
|
* @template E - The error type, `Error` by default
|
|
22
21
|
* @template Q - The query type: `FilterPagedQuery` by default
|
|
23
22
|
*/
|
|
24
|
-
export interface UsePagedQueryReturn<R, FIELDS extends string = string, E = Error, Q extends
|
|
23
|
+
export interface UsePagedQueryReturn<R, FIELDS extends string = string, E = Error, Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>> extends QueryHookReturn<Q, PagedResult<R>, E> {
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
26
|
* Runs a paged query through your own `execute` function and keeps the page
|
|
28
27
|
* as state: typically a query client's `paged` or `pagedState`.
|
|
29
28
|
*
|
|
30
|
-
* `execute` receives the query
|
|
31
|
-
* `
|
|
29
|
+
* `execute` receives the query and the request options of the run, its
|
|
30
|
+
* `signal` included; hand them on so that a newer query, `abort()`
|
|
32
31
|
* or an unmount cancels the request. The query runs on mount and whenever
|
|
33
32
|
* `query` or `setQuery()` changes it — turn pages with `setQuery()`; set
|
|
34
33
|
* `autoExecute: false` to run it only through `execute()`.
|
|
@@ -45,17 +44,18 @@ export interface UsePagedQueryReturn<R, FIELDS extends string = string, E = Erro
|
|
|
45
44
|
*
|
|
46
45
|
* @example
|
|
47
46
|
* ```tsx
|
|
48
|
-
* import {
|
|
47
|
+
* import type { SnapshotQueryClient, SnapshotRecord } from '@ahoo-wang/wow-client';
|
|
48
|
+
* import { filter, pagedQuery } from '@ahoo-wang/wow-client/dsl';
|
|
49
49
|
* import { usePagedQuery } from '@ahoo-wang/wow-react';
|
|
50
50
|
*
|
|
51
51
|
* function PaidOrders({ client, page }: { client: SnapshotQueryClient<OrderState, OrderFields>; page: number }) {
|
|
52
|
-
* const { result, loading, error } = usePagedQuery<OrderState
|
|
52
|
+
* const { result, loading, error } = usePagedQuery<SnapshotRecord<OrderState>, OrderFields>({
|
|
53
53
|
* query: pagedQuery({
|
|
54
54
|
* filter: filter.eq('state.status', 'PAID'),
|
|
55
55
|
* pagination: { index: page, size: 20 },
|
|
56
56
|
* }),
|
|
57
|
-
* execute: (query,
|
|
58
|
-
* client.
|
|
57
|
+
* execute: (query, options) =>
|
|
58
|
+
* client.paged(query, options),
|
|
59
59
|
* });
|
|
60
60
|
* if (error) return <p role="alert">{error.message}</p>;
|
|
61
61
|
* if (loading || !result) return <p>Loading…</p>;
|
|
@@ -63,6 +63,9 @@ export interface UsePagedQueryReturn<R, FIELDS extends string = string, E = Erro
|
|
|
63
63
|
* }
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
export declare function usePagedQuery<R, FIELDS extends string = string, E = Error>(options: UsePagedQueryOptions<R, FIELDS, E, FilterPagedQuery<FIELDS>>): UsePagedQueryReturn<R, FIELDS, E, FilterPagedQuery<FIELDS>>;
|
|
67
66
|
export declare function usePagedQuery<R, FIELDS extends string = string, E = Error>(options: UsePagedQueryOptions<R, FIELDS, E, PagedQuery<FIELDS>>): UsePagedQueryReturn<R, FIELDS, E, PagedQuery<FIELDS>>;
|
|
68
|
-
|
|
67
|
+
/**
|
|
68
|
+
* {@link usePagedQuery} typed by a query `Q` of your own, a subtype of
|
|
69
|
+
* `PagedQuery`, such as one whose literal projection narrows the result.
|
|
70
|
+
*/
|
|
71
|
+
export declare function usePagedQuery<R, FIELDS extends string = string, E = Error, Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>>(options: UsePagedQueryOptions<R, FIELDS, E, Q>): UsePagedQueryReturn<R, FIELDS, E, Q>;
|