@ahoo-wang/fetcher-react 2.6.15 → 2.6.18
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 +15 -15
- package/README.zh-CN.md +11 -11
- package/dist/core/useLatest.d.ts +2 -1
- package/dist/core/useLatest.d.ts.map +1 -1
- package/dist/index.es.js +157 -2112
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -17
- package/dist/index.umd.js.map +1 -1
- package/dist/wow/index.d.ts +1 -0
- package/dist/wow/index.d.ts.map +1 -1
- package/dist/wow/useCountQuery.d.ts +23 -38
- package/dist/wow/useCountQuery.d.ts.map +1 -1
- package/dist/wow/useListQuery.d.ts +31 -57
- package/dist/wow/useListQuery.d.ts.map +1 -1
- package/dist/wow/useListStreamQuery.d.ts +31 -64
- package/dist/wow/useListStreamQuery.d.ts.map +1 -1
- package/dist/wow/usePagedQuery.d.ts +32 -57
- package/dist/wow/usePagedQuery.d.ts.map +1 -1
- package/dist/wow/useQuery.d.ts +80 -0
- package/dist/wow/useQuery.d.ts.map +1 -0
- package/dist/wow/useSingleQuery.d.ts +31 -52
- package/dist/wow/useSingleQuery.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/wow/useListQueryState.d.ts +0 -66
- package/dist/wow/useListQueryState.d.ts.map +0 -1
package/dist/wow/index.d.ts
CHANGED
package/dist/wow/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wow/index.ts"],"names":[],"mappings":"AAaA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wow/index.ts"],"names":[],"mappings":"AAaA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
@@ -1,53 +1,38 @@
|
|
|
1
1
|
import { Condition } from '@ahoo-wang/fetcher-wow';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { AutoExecuteCapable } from './types';
|
|
2
|
+
import { FetcherError } from '@ahoo-wang/fetcher';
|
|
3
|
+
import { UseQueryOptions, UseQueryReturn } from './useQuery';
|
|
5
4
|
/**
|
|
6
5
|
* Options for the useCountQuery hook.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Extends UseQueryOptions with Condition as query key and number as data type.
|
|
7
|
+
*
|
|
8
|
+
* @template FIELDS - The fields type for the condition
|
|
9
|
+
* @template E - The error type, defaults to FetcherError
|
|
9
10
|
*/
|
|
10
|
-
export interface UseCountQueryOptions<FIELDS extends string = string, E = FetcherError> extends
|
|
11
|
-
/**
|
|
12
|
-
* The initial condition for the count query.
|
|
13
|
-
*/
|
|
14
|
-
initialCondition: Condition<FIELDS>;
|
|
15
|
-
/**
|
|
16
|
-
* The function to execute the count query.
|
|
17
|
-
* @param condition - The condition to filter resources.
|
|
18
|
-
* @param attributes - Optional additional attributes.
|
|
19
|
-
* @returns A promise that resolves to the count of matching resources.
|
|
20
|
-
*/
|
|
21
|
-
count: (condition: Condition<FIELDS>, attributes?: Record<string, any>) => Promise<number>;
|
|
11
|
+
export interface UseCountQueryOptions<FIELDS extends string = string, E = FetcherError> extends UseQueryOptions<Condition<FIELDS>, number, E> {
|
|
22
12
|
}
|
|
23
13
|
/**
|
|
24
14
|
* Return type for the useCountQuery hook.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
15
|
+
* Extends UseQueryReturn with Condition as query key and number as data type.
|
|
16
|
+
*
|
|
17
|
+
* @template FIELDS - The fields type for the condition
|
|
18
|
+
* @template E - The error type, defaults to FetcherError
|
|
27
19
|
*/
|
|
28
|
-
export interface UseCountQueryReturn<FIELDS extends string = string, E = FetcherError> extends
|
|
29
|
-
/**
|
|
30
|
-
* Executes the count query.
|
|
31
|
-
* @returns A promise that resolves to the count or an error.
|
|
32
|
-
*/
|
|
33
|
-
execute: () => Promise<E | number>;
|
|
34
|
-
/**
|
|
35
|
-
* Sets the condition for the query.
|
|
36
|
-
* @param condition - The new condition.
|
|
37
|
-
*/
|
|
38
|
-
setCondition: (condition: Condition<FIELDS>) => void;
|
|
20
|
+
export interface UseCountQueryReturn<FIELDS extends string = string, E = FetcherError> extends UseQueryReturn<Condition<FIELDS>, number, E> {
|
|
39
21
|
}
|
|
40
22
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @
|
|
45
|
-
* @
|
|
23
|
+
* Hook for querying count data with conditions.
|
|
24
|
+
* Wraps useQuery to provide type-safe count queries.
|
|
25
|
+
*
|
|
26
|
+
* @template FIELDS - The fields type for the condition
|
|
27
|
+
* @template E - The error type, defaults to FetcherError
|
|
28
|
+
* @param options - The query options including condition and other settings
|
|
29
|
+
* @returns The query result with count data
|
|
30
|
+
*
|
|
46
31
|
* @example
|
|
47
32
|
* ```typescript
|
|
48
|
-
* const { data,
|
|
49
|
-
*
|
|
50
|
-
*
|
|
33
|
+
* const { data, isLoading } = useCountQuery({
|
|
34
|
+
* queryKey: [{ field: 'status', operator: 'eq', value: 'active' }],
|
|
35
|
+
* queryFn: async (condition) => fetchCount(condition),
|
|
51
36
|
* });
|
|
52
37
|
* ```
|
|
53
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCountQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useCountQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"useCountQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useCountQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAY,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB,CACnC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;CACtD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB,CAClC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;CACrD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,YAAY,EAC5E,OAAO,EAAE,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,GACvC,mBAAmB,CAAC,MAAM,EAAE,CAAC,CAAC,CAEhC"}
|
|
@@ -1,71 +1,45 @@
|
|
|
1
|
-
import { ListQuery
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { AutoExecuteCapable } from './types';
|
|
1
|
+
import { ListQuery } from '@ahoo-wang/fetcher-wow';
|
|
2
|
+
import { FetcherError } from '@ahoo-wang/fetcher';
|
|
3
|
+
import { UseQueryOptions, UseQueryReturn } from './useQuery';
|
|
5
4
|
/**
|
|
6
5
|
* Options for the useListQuery hook.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @template
|
|
6
|
+
* Extends UseQueryOptions with ListQuery as query key and array of results as data type.
|
|
7
|
+
*
|
|
8
|
+
* @template R - The type of the result items in the list
|
|
9
|
+
* @template FIELDS - The fields type for the list query
|
|
10
|
+
* @template E - The error type, defaults to FetcherError
|
|
10
11
|
*/
|
|
11
|
-
export interface UseListQueryOptions<R, FIELDS extends string = string, E = FetcherError> extends
|
|
12
|
-
/**
|
|
13
|
-
* The initial list query configuration.
|
|
14
|
-
*/
|
|
15
|
-
initialQuery: ListQuery<FIELDS>;
|
|
16
|
-
/**
|
|
17
|
-
* The function to execute the list query.
|
|
18
|
-
* @param listQuery - The list query object.
|
|
19
|
-
* @param attributes - Optional additional attributes.
|
|
20
|
-
* @returns A promise that resolves to an array of results.
|
|
21
|
-
*/
|
|
22
|
-
list: (listQuery: ListQuery<FIELDS>, attributes?: Record<string, any>) => Promise<R[]>;
|
|
12
|
+
export interface UseListQueryOptions<R, FIELDS extends string = string, E = FetcherError> extends UseQueryOptions<ListQuery<FIELDS>, R[], E> {
|
|
23
13
|
}
|
|
24
14
|
/**
|
|
25
15
|
* Return type for the useListQuery hook.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @template
|
|
16
|
+
* Extends UseQueryReturn with ListQuery as query key and array of results as data type.
|
|
17
|
+
*
|
|
18
|
+
* @template R - The type of the result items in the list
|
|
19
|
+
* @template FIELDS - The fields type for the list query
|
|
20
|
+
* @template E - The error type, defaults to FetcherError
|
|
29
21
|
*/
|
|
30
|
-
export interface UseListQueryReturn<R, FIELDS extends string = string, E = FetcherError> extends
|
|
31
|
-
/**
|
|
32
|
-
* Executes the list query.
|
|
33
|
-
* @returns A promise that resolves to the result array or an error.
|
|
34
|
-
*/
|
|
35
|
-
execute: () => Promise<E | R[]>;
|
|
36
|
-
/**
|
|
37
|
-
* Sets the condition for the query.
|
|
38
|
-
* @param condition - The new condition.
|
|
39
|
-
*/
|
|
40
|
-
setCondition: (condition: Condition<FIELDS>) => void;
|
|
41
|
-
/**
|
|
42
|
-
* Sets the projection for the query.
|
|
43
|
-
* @param projection - The new projection.
|
|
44
|
-
*/
|
|
45
|
-
setProjection: (projection: Projection<FIELDS>) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Sets the sort order for the query.
|
|
48
|
-
* @param sort - The new sort array.
|
|
49
|
-
*/
|
|
50
|
-
setSort: (sort: FieldSort<FIELDS>[]) => void;
|
|
51
|
-
/**
|
|
52
|
-
* Sets the limit for the query.
|
|
53
|
-
* @param limit - The new limit.
|
|
54
|
-
*/
|
|
55
|
-
setLimit: (limit: number) => void;
|
|
22
|
+
export interface UseListQueryReturn<R, FIELDS extends string = string, E = FetcherError> extends UseQueryReturn<ListQuery<FIELDS>, R[], E> {
|
|
56
23
|
}
|
|
57
24
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @template
|
|
62
|
-
* @
|
|
63
|
-
* @
|
|
25
|
+
* Hook for querying list data with conditions, projection, and sorting.
|
|
26
|
+
* Wraps useQuery to provide type-safe list queries.
|
|
27
|
+
*
|
|
28
|
+
* @template R - The type of the result items in the list
|
|
29
|
+
* @template FIELDS - The fields type for the list query
|
|
30
|
+
* @template E - The error type, defaults to FetcherError
|
|
31
|
+
* @param options - The query options including list query configuration
|
|
32
|
+
* @returns The query result with list data
|
|
33
|
+
*
|
|
64
34
|
* @example
|
|
65
35
|
* ```typescript
|
|
66
|
-
* const { data,
|
|
67
|
-
* initialQuery: {
|
|
68
|
-
*
|
|
36
|
+
* const { data, isLoading } = useListQuery<{ id: number; name: string }, 'id' | 'name'>({
|
|
37
|
+
* initialQuery: {
|
|
38
|
+
* condition: all(),
|
|
39
|
+
* projection: { include: ['id', 'name'] },
|
|
40
|
+
* sort: [{ field: 'id', direction: SortDirection.ASC }],
|
|
41
|
+
* },
|
|
42
|
+
* execute: async (query) => fetchListData(query),
|
|
69
43
|
* });
|
|
70
44
|
* ```
|
|
71
45
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useListQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useListQuery.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"useListQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useListQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAY,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB,CAClC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;CACnD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB,CACjC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAC1B,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,EAEhB,OAAO,EAAE,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GACzC,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAElC"}
|
|
@@ -1,80 +1,47 @@
|
|
|
1
|
-
import { ListQuery
|
|
1
|
+
import { ListQuery } from '@ahoo-wang/fetcher-wow';
|
|
2
2
|
import { JsonServerSentEvent } from '@ahoo-wang/fetcher-eventstream';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { AutoExecuteCapable } from './types';
|
|
3
|
+
import { FetcherError } from '@ahoo-wang/fetcher';
|
|
4
|
+
import { UseQueryOptions, UseQueryReturn } from './useQuery';
|
|
6
5
|
/**
|
|
7
6
|
* Options for the useListStreamQuery hook.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @template
|
|
7
|
+
* Extends UseQueryOptions with ListQuery as query key and stream of events as data type.
|
|
8
|
+
*
|
|
9
|
+
* @template R - The type of the result items in the stream events
|
|
10
|
+
* @template FIELDS - The fields type for the list stream query
|
|
11
|
+
* @template E - The error type, defaults to FetcherError
|
|
11
12
|
*/
|
|
12
|
-
export interface UseListStreamQueryOptions<R, FIELDS extends string = string, E = FetcherError> extends
|
|
13
|
-
/**
|
|
14
|
-
* The initial list query configuration.
|
|
15
|
-
*/
|
|
16
|
-
initialQuery: ListQuery<FIELDS>;
|
|
17
|
-
/**
|
|
18
|
-
* The function to execute the list stream query.
|
|
19
|
-
* @param listQuery - The list query object.
|
|
20
|
-
* @param attributes - Optional additional attributes.
|
|
21
|
-
* @returns A promise that resolves to a readable stream of JSON server-sent events.
|
|
22
|
-
*/
|
|
23
|
-
listStream: (listQuery: ListQuery<FIELDS>, attributes?: Record<string, any>) => Promise<ReadableStream<JsonServerSentEvent<R>>>;
|
|
13
|
+
export interface UseListStreamQueryOptions<R, FIELDS extends string = string, E = FetcherError> extends UseQueryOptions<ListQuery<FIELDS>, ReadableStream<JsonServerSentEvent<R>>, E> {
|
|
24
14
|
}
|
|
25
15
|
/**
|
|
26
16
|
* Return type for the useListStreamQuery hook.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @template
|
|
17
|
+
* Extends UseQueryReturn with ListQuery as query key and stream of events as data type.
|
|
18
|
+
*
|
|
19
|
+
* @template R - The type of the result items in the stream events
|
|
20
|
+
* @template FIELDS - The fields type for the list stream query
|
|
21
|
+
* @template E - The error type, defaults to FetcherError
|
|
30
22
|
*/
|
|
31
|
-
export interface UseListStreamQueryReturn<R, FIELDS extends string = string, E = FetcherError> extends
|
|
32
|
-
/**
|
|
33
|
-
* Executes the list stream query.
|
|
34
|
-
* @returns A promise that resolves to a readable stream of JSON server-sent events or an error.
|
|
35
|
-
*/
|
|
36
|
-
execute: () => Promise<E | ReadableStream<JsonServerSentEvent<R>>>;
|
|
37
|
-
/**
|
|
38
|
-
* Sets the condition for the query.
|
|
39
|
-
* @param condition - The new condition.
|
|
40
|
-
*/
|
|
41
|
-
setCondition: (condition: Condition<FIELDS>) => void;
|
|
42
|
-
/**
|
|
43
|
-
* Sets the projection for the query.
|
|
44
|
-
* @param projection - The new projection.
|
|
45
|
-
*/
|
|
46
|
-
setProjection: (projection: Projection<FIELDS>) => void;
|
|
47
|
-
/**
|
|
48
|
-
* Sets the sort order for the query.
|
|
49
|
-
* @param sort - The new sort array.
|
|
50
|
-
*/
|
|
51
|
-
setSort: (sort: FieldSort<FIELDS>[]) => void;
|
|
52
|
-
/**
|
|
53
|
-
* Sets the limit for the query.
|
|
54
|
-
* @param limit - The new limit.
|
|
55
|
-
*/
|
|
56
|
-
setLimit: (limit: number) => void;
|
|
23
|
+
export interface UseListStreamQueryReturn<R, FIELDS extends string = string, E = FetcherError> extends UseQueryReturn<ListQuery<FIELDS>, ReadableStream<JsonServerSentEvent<R>>, E> {
|
|
57
24
|
}
|
|
58
25
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @template
|
|
63
|
-
* @template
|
|
64
|
-
* @
|
|
65
|
-
* @
|
|
26
|
+
* Hook for querying streaming list data with conditions, projection, and sorting.
|
|
27
|
+
* Wraps useQuery to provide type-safe streaming list queries.
|
|
28
|
+
*
|
|
29
|
+
* @template R - The type of the result items in the stream events
|
|
30
|
+
* @template FIELDS - The fields type for the list stream query
|
|
31
|
+
* @template E - The error type, defaults to FetcherError
|
|
32
|
+
* @param options - The query options including list stream query configuration
|
|
33
|
+
* @returns The query result with streaming data
|
|
34
|
+
*
|
|
66
35
|
* @example
|
|
67
36
|
* ```typescript
|
|
68
|
-
* const { data,
|
|
69
|
-
* initialQuery: {
|
|
70
|
-
*
|
|
37
|
+
* const { data, isLoading } = useListStreamQuery<{ id: number; name: string }, 'id' | 'name'>({
|
|
38
|
+
* initialQuery: {
|
|
39
|
+
* condition: all(),
|
|
40
|
+
* projection: { include: ['id', 'name'] },
|
|
41
|
+
* sort: [{ field: 'id', direction: SortDirection.ASC }],
|
|
42
|
+
* },
|
|
43
|
+
* execute: async (query) => fetchStreamData(query),
|
|
71
44
|
* });
|
|
72
|
-
*
|
|
73
|
-
* // Use the stream
|
|
74
|
-
* if (data) {
|
|
75
|
-
* const reader = data.getReader();
|
|
76
|
-
* // Process stream events
|
|
77
|
-
* }
|
|
78
45
|
* ```
|
|
79
46
|
*/
|
|
80
47
|
export declare function useListStreamQuery<R, FIELDS extends string = string, E = FetcherError>(options: UseListStreamQueryOptions<R, FIELDS, E>): UseListStreamQueryReturn<R, FIELDS, E>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useListStreamQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useListStreamQuery.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"useListStreamQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useListStreamQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAY,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,WAAW,yBAAyB,CACxC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,eAAe,CACvB,SAAS,CAAC,MAAM,CAAC,EACjB,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,EACtC,CAAC,CACF;CACA;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB,CACvC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,cAAc,CACtB,SAAS,CAAC,MAAM,CAAC,EACf,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,EACtC,CAAC,CACJ;CACA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,EAEhB,OAAO,EAAE,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAC/C,wBAAwB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAIxC"}
|
|
@@ -1,71 +1,46 @@
|
|
|
1
|
-
import { PagedList, PagedQuery
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { AutoExecuteCapable } from './types';
|
|
1
|
+
import { PagedList, PagedQuery } from '@ahoo-wang/fetcher-wow';
|
|
2
|
+
import { FetcherError } from '@ahoo-wang/fetcher';
|
|
3
|
+
import { UseQueryOptions, UseQueryReturn } from './useQuery';
|
|
5
4
|
/**
|
|
6
5
|
* Options for the usePagedQuery hook.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @template
|
|
6
|
+
* Extends UseQueryOptions with PagedQuery as query key and PagedList as data type.
|
|
7
|
+
*
|
|
8
|
+
* @template R - The type of the result items in the paged list
|
|
9
|
+
* @template FIELDS - The fields type for the paged query
|
|
10
|
+
* @template E - The error type, defaults to FetcherError
|
|
10
11
|
*/
|
|
11
|
-
export interface UsePagedQueryOptions<R, FIELDS extends string = string, E = FetcherError> extends
|
|
12
|
-
/**
|
|
13
|
-
* The initial paged query configuration.
|
|
14
|
-
*/
|
|
15
|
-
initialQuery: PagedQuery<FIELDS>;
|
|
16
|
-
/**
|
|
17
|
-
* The function to execute the paged query.
|
|
18
|
-
* @param pagedQuery - The paged query object.
|
|
19
|
-
* @param attributes - Optional additional attributes.
|
|
20
|
-
* @returns A promise that resolves to a paged list of results.
|
|
21
|
-
*/
|
|
22
|
-
query: (pagedQuery: PagedQuery<FIELDS>, attributes?: Record<string, any>) => Promise<PagedList<R>>;
|
|
12
|
+
export interface UsePagedQueryOptions<R, FIELDS extends string = string, E = FetcherError> extends UseQueryOptions<PagedQuery<FIELDS>, PagedList<R>, E> {
|
|
23
13
|
}
|
|
24
14
|
/**
|
|
25
15
|
* Return type for the usePagedQuery hook.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @template
|
|
16
|
+
* Extends UseQueryReturn with PagedQuery as query key and PagedList as data type.
|
|
17
|
+
*
|
|
18
|
+
* @template R - The type of the result items in the paged list
|
|
19
|
+
* @template FIELDS - The fields type for the paged query
|
|
20
|
+
* @template E - The error type, defaults to FetcherError
|
|
29
21
|
*/
|
|
30
|
-
export interface UsePagedQueryReturn<R, FIELDS extends string = string, E = FetcherError> extends
|
|
31
|
-
/**
|
|
32
|
-
* Executes the paged query.
|
|
33
|
-
* @returns A promise that resolves to the paged list or an error.
|
|
34
|
-
*/
|
|
35
|
-
execute: () => Promise<E | PagedList<R>>;
|
|
36
|
-
/**
|
|
37
|
-
* Sets the condition for the query.
|
|
38
|
-
* @param condition - The new condition.
|
|
39
|
-
*/
|
|
40
|
-
setCondition: (condition: Condition<FIELDS>) => void;
|
|
41
|
-
/**
|
|
42
|
-
* Sets the projection for the query.
|
|
43
|
-
* @param projection - The new projection.
|
|
44
|
-
*/
|
|
45
|
-
setProjection: (projection: Projection<FIELDS>) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Sets the pagination for the query.
|
|
48
|
-
* @param pagination - The new pagination.
|
|
49
|
-
*/
|
|
50
|
-
setPagination: (pagination: Pagination) => void;
|
|
51
|
-
/**
|
|
52
|
-
* Sets the sort order for the query.
|
|
53
|
-
* @param sort - The new sort array.
|
|
54
|
-
*/
|
|
55
|
-
setSort: (sort: FieldSort<FIELDS>[]) => void;
|
|
22
|
+
export interface UsePagedQueryReturn<R, FIELDS extends string = string, E = FetcherError> extends UseQueryReturn<PagedQuery<FIELDS>, PagedList<R>, E> {
|
|
56
23
|
}
|
|
57
24
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @template
|
|
62
|
-
* @
|
|
63
|
-
* @
|
|
25
|
+
* Hook for querying paged data with conditions, projection, pagination, and sorting.
|
|
26
|
+
* Wraps useQuery to provide type-safe paged queries.
|
|
27
|
+
*
|
|
28
|
+
* @template R - The type of the result items in the paged list
|
|
29
|
+
* @template FIELDS - The fields type for the paged query
|
|
30
|
+
* @template E - The error type, defaults to FetcherError
|
|
31
|
+
* @param options - The query options including paged query configuration
|
|
32
|
+
* @returns The query result with paged list data
|
|
33
|
+
*
|
|
64
34
|
* @example
|
|
65
35
|
* ```typescript
|
|
66
|
-
* const { data,
|
|
67
|
-
* initialQuery: {
|
|
68
|
-
*
|
|
36
|
+
* const { data, isLoading } = usePagedQuery<{ id: number; name: string }, 'id' | 'name'>({
|
|
37
|
+
* initialQuery: {
|
|
38
|
+
* condition: all(),
|
|
39
|
+
* pagination: { index: 1, size: 10 },
|
|
40
|
+
* projection: { include: ['id', 'name'] },
|
|
41
|
+
* sort: [{ field: 'id', direction: SortDirection.ASC }],
|
|
42
|
+
* },
|
|
43
|
+
* execute: async (query) => fetchPagedData(query),
|
|
69
44
|
* });
|
|
70
45
|
* ```
|
|
71
46
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePagedQuery.d.ts","sourceRoot":"","sources":["../../src/wow/usePagedQuery.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"usePagedQuery.d.ts","sourceRoot":"","sources":["../../src/wow/usePagedQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAY,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB,CACnC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CAC7D;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB,CAClC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CAC5D;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAC3B,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,EAEhB,OAAO,EAAE,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAC1C,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAEnC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { UseExecutePromiseReturn, UseExecutePromiseOptions } from '../core';
|
|
2
|
+
import { AttributesCapable, FetcherError } from '@ahoo-wang/fetcher';
|
|
3
|
+
import { AutoExecuteCapable } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the useQuery hook
|
|
6
|
+
* @template Q - The type of the query parameters
|
|
7
|
+
* @template R - The type of the result value
|
|
8
|
+
* @template E - The type of the error value
|
|
9
|
+
*/
|
|
10
|
+
export interface UseQueryOptions<Q, R, E = FetcherError> extends UseExecutePromiseOptions<R, E>, AttributesCapable, AutoExecuteCapable {
|
|
11
|
+
/** The initial query parameters */
|
|
12
|
+
initialQuery: Q;
|
|
13
|
+
/** Function to execute the query with given parameters and optional attributes */
|
|
14
|
+
execute: (query: Q, attributes?: Record<string, any>) => Promise<R>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Return type of the useQuery hook
|
|
18
|
+
* @template Q - The type of the query parameters
|
|
19
|
+
* @template R - The type of the result value
|
|
20
|
+
* @template E - The type of the error value
|
|
21
|
+
*/
|
|
22
|
+
export interface UseQueryReturn<Q, R, E = FetcherError> extends UseExecutePromiseReturn<R, E> {
|
|
23
|
+
/**
|
|
24
|
+
* Get the current query parameters
|
|
25
|
+
*/
|
|
26
|
+
getQuery: () => Q;
|
|
27
|
+
/** Function to update the query parameters */
|
|
28
|
+
setQuery: (query: Q) => void;
|
|
29
|
+
/** Function to execute the query with current parameters */
|
|
30
|
+
execute: () => Promise<R | E>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A React hook for managing query-based asynchronous operations
|
|
34
|
+
* @template Q - The type of the query parameters
|
|
35
|
+
* @template R - The type of the result value
|
|
36
|
+
* @template E - The type of the error value
|
|
37
|
+
* @param options - Configuration options for the query
|
|
38
|
+
* @returns An object containing the query state and control functions
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { useQuery } from '@ahoo-wang/fetcher-react';
|
|
43
|
+
*
|
|
44
|
+
* interface UserQuery {
|
|
45
|
+
* id: string;
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* interface User {
|
|
49
|
+
* id: string;
|
|
50
|
+
* name: string;
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* function UserComponent() {
|
|
54
|
+
* const { loading, result, error, execute, setQuery } = useQuery<UserQuery, User>({
|
|
55
|
+
* initialQuery: { id: '1' },
|
|
56
|
+
* execute: async (query) => {
|
|
57
|
+
* const response = await fetch(`/api/users/${query.id}`);
|
|
58
|
+
* return response.json();
|
|
59
|
+
* },
|
|
60
|
+
* autoExecute: true,
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* const handleUserChange = (userId: string) => {
|
|
64
|
+
* setQuery({ id: userId });
|
|
65
|
+
* execute();
|
|
66
|
+
* };
|
|
67
|
+
*
|
|
68
|
+
* if (loading) return <div>Loading...</div>;
|
|
69
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
70
|
+
* return (
|
|
71
|
+
* <div>
|
|
72
|
+
* <button onClick={() => handleUserChange('2')}>Load User 2</button>
|
|
73
|
+
* {result && <p>User: {result.name}</p>}
|
|
74
|
+
* </div>
|
|
75
|
+
* );
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function useQuery<Q, R, E = FetcherError>(options: UseQueryOptions<Q, R, E>): UseQueryReturn<Q, R, E>;
|
|
80
|
+
//# sourceMappingURL=useQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,CACrD,SAAQ,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,EACpC,iBAAiB,EACjB,kBAAkB;IACpB,mCAAmC;IACnC,YAAY,EAAE,CAAC,CAAC;IAEhB,kFAAkF;IAClF,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CACrE;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,CACpD,SAAQ,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC;IACrC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,8CAA8C;IAC9C,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,4DAA4D;IAC5D,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,EAC7C,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAChC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CA0CzB"}
|