@ahoo-wang/fetcher-react 2.6.6 → 2.6.9
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/dist/core/useExecutePromise.d.ts +24 -3
- package/dist/core/useExecutePromise.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +2071 -100
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +17 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/wow/index.d.ts +5 -0
- package/dist/wow/index.d.ts.map +1 -1
- package/dist/wow/useCountQuery.d.ts +57 -0
- package/dist/wow/useCountQuery.d.ts.map +1 -0
- package/dist/wow/useListQuery.d.ts +75 -0
- package/dist/wow/useListQuery.d.ts.map +1 -0
- package/dist/wow/useListQueryState.d.ts +66 -0
- package/dist/wow/useListQueryState.d.ts.map +1 -0
- package/dist/wow/useListStreamQuery.d.ts +83 -0
- package/dist/wow/useListStreamQuery.d.ts.map +1 -0
- package/dist/wow/usePagedQuery.d.ts +75 -0
- package/dist/wow/usePagedQuery.d.ts.map +1 -0
- package/dist/wow/useSingleQuery.d.ts +70 -0
- package/dist/wow/useSingleQuery.d.ts.map +1 -0
- package/package.json +5 -4
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":""}
|
|
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"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Condition } from '@ahoo-wang/fetcher-wow';
|
|
2
|
+
import { UsePromiseStateOptions, UseExecutePromiseReturn } from '../core';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the useCountQuery hook.
|
|
5
|
+
* @template FIELDS - The type of the fields used in conditions.
|
|
6
|
+
* @template E - The type of the error.
|
|
7
|
+
*/
|
|
8
|
+
export interface UseCountQueryOptions<FIELDS extends string = string, E = unknown> extends UsePromiseStateOptions<number, E> {
|
|
9
|
+
/**
|
|
10
|
+
* The initial condition for the count query.
|
|
11
|
+
*/
|
|
12
|
+
initialCondition: Condition<FIELDS>;
|
|
13
|
+
/**
|
|
14
|
+
* The function to execute the count query.
|
|
15
|
+
* @param condition - The condition to filter resources.
|
|
16
|
+
* @param attributes - Optional additional attributes.
|
|
17
|
+
* @returns A promise that resolves to the count of matching resources.
|
|
18
|
+
*/
|
|
19
|
+
count: (condition: Condition<FIELDS>, attributes?: Record<string, any>) => Promise<number>;
|
|
20
|
+
/**
|
|
21
|
+
* Optional additional attributes to pass to the count function.
|
|
22
|
+
*/
|
|
23
|
+
attributes?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Return type for the useCountQuery hook.
|
|
27
|
+
* @template FIELDS - The type of the fields used in conditions.
|
|
28
|
+
* @template E - The type of the error.
|
|
29
|
+
*/
|
|
30
|
+
export interface UseCountQueryReturn<FIELDS extends string = string, E = unknown> extends UseExecutePromiseReturn<number, E> {
|
|
31
|
+
/**
|
|
32
|
+
* Executes the count query.
|
|
33
|
+
* @returns A promise that resolves to the count or an error.
|
|
34
|
+
*/
|
|
35
|
+
execute: () => Promise<E | number>;
|
|
36
|
+
/**
|
|
37
|
+
* Sets the condition for the query.
|
|
38
|
+
* @param condition - The new condition.
|
|
39
|
+
*/
|
|
40
|
+
setCondition: (condition: Condition<FIELDS>) => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A React hook for managing count queries with state management for conditions.
|
|
44
|
+
* @template FIELDS - The type of the fields used in conditions.
|
|
45
|
+
* @template E - The type of the error.
|
|
46
|
+
* @param options - The options for the hook.
|
|
47
|
+
* @returns An object containing the query state and methods to update it.
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const { data, loading, error, execute, setCondition } = useCountQuery({
|
|
51
|
+
* initialCondition: {},
|
|
52
|
+
* count: async (condition) => fetchCount(condition),
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function useCountQuery<FIELDS extends string = string, E = unknown>(options: UseCountQueryOptions<FIELDS, E>): UseCountQueryReturn<FIELDS>;
|
|
57
|
+
//# sourceMappingURL=useCountQuery.d.ts.map
|
|
@@ -0,0 +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,EAEL,sBAAsB,EAEtB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAGjB;;;;GAIG;AACH,MAAM,WAAW,oBAAoB,CACnC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC;;OAEG;IACH,gBAAgB,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACpC;;;;;OAKG;IACH,KAAK,EAAE,CACL,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,EAC5B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,MAAM,CAAC,CAAC;IACrB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB,CAClC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,uBAAuB,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C;;;OAGG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;IACnC;;;OAGG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;CACtD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,EACvE,OAAO,EAAE,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,GACvC,mBAAmB,CAAC,MAAM,CAAC,CAwB7B"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ListQuery, Condition, Projection, FieldSort } from '@ahoo-wang/fetcher-wow';
|
|
2
|
+
import { UsePromiseStateOptions, UseExecutePromiseReturn } from '../core';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the useListQuery hook.
|
|
5
|
+
* @template R - The type of the result items in the list.
|
|
6
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
7
|
+
* @template E - The type of the error.
|
|
8
|
+
*/
|
|
9
|
+
export interface UseListQueryOptions<R, FIELDS extends string = string, E = unknown> extends UsePromiseStateOptions<R[], E> {
|
|
10
|
+
/**
|
|
11
|
+
* The initial list query configuration.
|
|
12
|
+
*/
|
|
13
|
+
initialQuery: ListQuery<FIELDS>;
|
|
14
|
+
/**
|
|
15
|
+
* The function to execute the list query.
|
|
16
|
+
* @param listQuery - The list query object.
|
|
17
|
+
* @param attributes - Optional additional attributes.
|
|
18
|
+
* @returns A promise that resolves to an array of results.
|
|
19
|
+
*/
|
|
20
|
+
list: (listQuery: ListQuery<FIELDS>, attributes?: Record<string, any>) => Promise<R[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Optional additional attributes to pass to the list function.
|
|
23
|
+
*/
|
|
24
|
+
attributes?: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return type for the useListQuery hook.
|
|
28
|
+
* @template R - The type of the result items in the list.
|
|
29
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
30
|
+
* @template E - The type of the error.
|
|
31
|
+
*/
|
|
32
|
+
export interface UseListQueryReturn<R, FIELDS extends string = string, E = unknown> extends UseExecutePromiseReturn<R[], E> {
|
|
33
|
+
/**
|
|
34
|
+
* Executes the list query.
|
|
35
|
+
* @returns A promise that resolves to the result array or an error.
|
|
36
|
+
*/
|
|
37
|
+
execute: () => Promise<E | R[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the condition for the query.
|
|
40
|
+
* @param condition - The new condition.
|
|
41
|
+
*/
|
|
42
|
+
setCondition: (condition: Condition<FIELDS>) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the projection for the query.
|
|
45
|
+
* @param projection - The new projection.
|
|
46
|
+
*/
|
|
47
|
+
setProjection: (projection: Projection<FIELDS>) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the sort order for the query.
|
|
50
|
+
* @param sort - The new sort array.
|
|
51
|
+
*/
|
|
52
|
+
setSort: (sort: FieldSort<FIELDS>[]) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Sets the limit for the query.
|
|
55
|
+
* @param limit - The new limit.
|
|
56
|
+
*/
|
|
57
|
+
setLimit: (limit: number) => void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A React hook for managing list queries with state management for conditions, projections, sorting, and limits.
|
|
61
|
+
* @template R - The type of the result items in the list.
|
|
62
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
63
|
+
* @template E - The type of the error.
|
|
64
|
+
* @param options - The options for the hook.
|
|
65
|
+
* @returns An object containing the query state and methods to update it.
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const { data, loading, error, execute, setCondition, setLimit } = useListQuery({
|
|
69
|
+
* initialQuery: { condition: {}, projection: {}, sort: [], limit: 10 },
|
|
70
|
+
* list: async (listQuery) => fetchList(listQuery),
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function useListQuery<R, FIELDS extends string = string, E = unknown>(options: UseListQueryOptions<R, FIELDS, E>): UseListQueryReturn<R, FIELDS>;
|
|
75
|
+
//# sourceMappingURL=useListQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useListQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useListQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,SAAS,EACT,SAAS,EACT,KAAK,UAAU,EACf,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,sBAAsB,EAEtB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAIjB;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB,CAClC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,sBAAsB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACtC;;OAEG;IACH,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC;;;;;OAKG;IACH,IAAI,EAAE,CACJ,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,EAC5B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB,CACjC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,uBAAuB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACvC;;;OAGG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChC;;;OAGG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACrD;;;OAGG;IACH,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACxD;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,EACzE,OAAO,EAAE,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GACzC,kBAAkB,CAAC,CAAC,EAAE,MAAM,CAAC,CAkC/B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ListQuery, Condition, Projection, FieldSort } from '@ahoo-wang/fetcher-wow';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the useListQueryState hook.
|
|
4
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseListQueryStateOptions<FIELDS extends string = string> {
|
|
7
|
+
/**
|
|
8
|
+
* The initial list query configuration.
|
|
9
|
+
*/
|
|
10
|
+
initialQuery: ListQuery<FIELDS>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Return type for the useListQueryState hook.
|
|
14
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
15
|
+
*/
|
|
16
|
+
export interface UseListQueryStateReturn<FIELDS extends string = string> {
|
|
17
|
+
/**
|
|
18
|
+
* The current condition.
|
|
19
|
+
*/
|
|
20
|
+
condition: Condition<FIELDS>;
|
|
21
|
+
/**
|
|
22
|
+
* The current projection.
|
|
23
|
+
*/
|
|
24
|
+
projection?: Projection<FIELDS>;
|
|
25
|
+
/**
|
|
26
|
+
* The current sort order.
|
|
27
|
+
*/
|
|
28
|
+
sort?: FieldSort<FIELDS>[];
|
|
29
|
+
/**
|
|
30
|
+
* The current limit.
|
|
31
|
+
*/
|
|
32
|
+
limit?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Sets the condition for the query.
|
|
35
|
+
* @param condition - The new condition.
|
|
36
|
+
*/
|
|
37
|
+
setCondition: (condition: Condition<FIELDS>) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the projection for the query.
|
|
40
|
+
* @param projection - The new projection.
|
|
41
|
+
*/
|
|
42
|
+
setProjection: (projection: Projection<FIELDS>) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the sort order for the query.
|
|
45
|
+
* @param sort - The new sort array.
|
|
46
|
+
*/
|
|
47
|
+
setSort: (sort: FieldSort<FIELDS>[]) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the limit for the query.
|
|
50
|
+
* @param limit - The new limit.
|
|
51
|
+
*/
|
|
52
|
+
setLimit: (limit: number) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Builds the list query object from current state.
|
|
55
|
+
* @returns The list query object.
|
|
56
|
+
*/
|
|
57
|
+
buildQuery: () => ListQuery<FIELDS>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A React hook for managing query state (condition, projection, sort, limit).
|
|
61
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
62
|
+
* @param options - The options for the hook.
|
|
63
|
+
* @returns An object containing the query state and methods to update it.
|
|
64
|
+
*/
|
|
65
|
+
export declare function useListQueryState<FIELDS extends string = string>(options: UseListQueryStateOptions<FIELDS>): UseListQueryStateReturn<FIELDS>;
|
|
66
|
+
//# sourceMappingURL=useListQueryState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useListQueryState.d.ts","sourceRoot":"","sources":["../../src/wow/useListQueryState.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,SAAS,EACT,SAAS,EACT,KAAK,UAAU,EAEf,SAAS,EACV,MAAM,wBAAwB,CAAC;AAGhC;;;GAGG;AACH,MAAM,WAAW,wBAAwB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IACtE;;OAEG;IACH,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IACrE;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC7B;;OAEG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IAC3B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACrD;;;OAGG;IACH,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACxD;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;OAGG;IACH,UAAU,EAAE,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;CACrC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9D,OAAO,EAAE,wBAAwB,CAAC,MAAM,CAAC,GACxC,uBAAuB,CAAC,MAAM,CAAC,CAwCjC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ListQuery, Condition, Projection, FieldSort } from '@ahoo-wang/fetcher-wow';
|
|
2
|
+
import { JsonServerSentEvent } from '@ahoo-wang/fetcher-eventstream';
|
|
3
|
+
import { UsePromiseStateOptions, UseExecutePromiseReturn } from '../core';
|
|
4
|
+
/**
|
|
5
|
+
* Options for the useListStreamQuery hook.
|
|
6
|
+
* @template R - The type of the result items in the stream events.
|
|
7
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
8
|
+
* @template E - The type of the error.
|
|
9
|
+
*/
|
|
10
|
+
export interface UseListStreamQueryOptions<R, FIELDS extends string = string, E = unknown> extends UsePromiseStateOptions<ReadableStream<JsonServerSentEvent<R>>, E> {
|
|
11
|
+
/**
|
|
12
|
+
* The initial list query configuration.
|
|
13
|
+
*/
|
|
14
|
+
initialQuery: ListQuery<FIELDS>;
|
|
15
|
+
/**
|
|
16
|
+
* The function to execute the list stream query.
|
|
17
|
+
* @param listQuery - The list query object.
|
|
18
|
+
* @param attributes - Optional additional attributes.
|
|
19
|
+
* @returns A promise that resolves to a readable stream of JSON server-sent events.
|
|
20
|
+
*/
|
|
21
|
+
listStream: (listQuery: ListQuery<FIELDS>, attributes?: Record<string, any>) => Promise<ReadableStream<JsonServerSentEvent<R>>>;
|
|
22
|
+
/**
|
|
23
|
+
* Optional additional attributes to pass to the listStream function.
|
|
24
|
+
*/
|
|
25
|
+
attributes?: Record<string, any>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Return type for the useListStreamQuery hook.
|
|
29
|
+
* @template R - The type of the result items in the stream events.
|
|
30
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
31
|
+
* @template E - The type of the error.
|
|
32
|
+
*/
|
|
33
|
+
export interface UseListStreamQueryReturn<R, FIELDS extends string = string, E = unknown> extends UseExecutePromiseReturn<ReadableStream<JsonServerSentEvent<R>>, E> {
|
|
34
|
+
/**
|
|
35
|
+
* Executes the list stream query.
|
|
36
|
+
* @returns A promise that resolves to a readable stream of JSON server-sent events or an error.
|
|
37
|
+
*/
|
|
38
|
+
execute: () => Promise<E | ReadableStream<JsonServerSentEvent<R>>>;
|
|
39
|
+
/**
|
|
40
|
+
* Sets the condition for the query.
|
|
41
|
+
* @param condition - The new condition.
|
|
42
|
+
*/
|
|
43
|
+
setCondition: (condition: Condition<FIELDS>) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Sets the projection for the query.
|
|
46
|
+
* @param projection - The new projection.
|
|
47
|
+
*/
|
|
48
|
+
setProjection: (projection: Projection<FIELDS>) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Sets the sort order for the query.
|
|
51
|
+
* @param sort - The new sort array.
|
|
52
|
+
*/
|
|
53
|
+
setSort: (sort: FieldSort<FIELDS>[]) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Sets the limit for the query.
|
|
56
|
+
* @param limit - The new limit.
|
|
57
|
+
*/
|
|
58
|
+
setLimit: (limit: number) => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A React hook for managing list stream queries with state management for conditions, projections, sorting, and limits.
|
|
62
|
+
* Returns a readable stream of JSON server-sent events.
|
|
63
|
+
* @template R - The type of the result items in the stream events.
|
|
64
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
65
|
+
* @template E - The type of the error.
|
|
66
|
+
* @param options - The options for the hook.
|
|
67
|
+
* @returns An object containing the query state and methods to update it.
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const { data, loading, error, execute, setCondition, setLimit } = useListStreamQuery({
|
|
71
|
+
* initialQuery: { condition: {}, projection: {}, sort: [], limit: 10 },
|
|
72
|
+
* listStream: async (listQuery) => fetchListStream(listQuery),
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Use the stream
|
|
76
|
+
* if (data) {
|
|
77
|
+
* const reader = data.getReader();
|
|
78
|
+
* // Process stream events
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function useListStreamQuery<R, FIELDS extends string = string, E = unknown>(options: UseListStreamQueryOptions<R, FIELDS, E>): UseListStreamQueryReturn<R, FIELDS>;
|
|
83
|
+
//# sourceMappingURL=useListStreamQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useListStreamQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useListStreamQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,SAAS,EACT,SAAS,EACT,KAAK,UAAU,EACf,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAEL,sBAAsB,EAEtB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAIjB;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB,CACxC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,sBAAsB,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACzE;;OAEG;IACH,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC;;;;;OAKG;IACH,UAAU,EAAE,CACV,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,EAC5B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB,CACvC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,uBAAuB,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1E;;;OAGG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,cAAc,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE;;;OAGG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACrD;;;OAGG;IACH,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACxD;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,EAEX,OAAO,EAAE,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAC/C,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,CAuCrC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { PagedList, PagedQuery, Condition, Pagination, Projection, FieldSort } from '@ahoo-wang/fetcher-wow';
|
|
2
|
+
import { UsePromiseStateOptions, UseExecutePromiseReturn } from '../core';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the usePagedQuery hook.
|
|
5
|
+
* @template R - The type of the result items in the paged list.
|
|
6
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
7
|
+
* @template E - The type of the error.
|
|
8
|
+
*/
|
|
9
|
+
export interface UsePagedQueryOptions<R, FIELDS extends string = string, E = unknown> extends UsePromiseStateOptions<PagedList<R>, E> {
|
|
10
|
+
/**
|
|
11
|
+
* The initial paged query configuration.
|
|
12
|
+
*/
|
|
13
|
+
initialQuery: PagedQuery<FIELDS>;
|
|
14
|
+
/**
|
|
15
|
+
* The function to execute the paged query.
|
|
16
|
+
* @param pagedQuery - The paged query object.
|
|
17
|
+
* @param attributes - Optional additional attributes.
|
|
18
|
+
* @returns A promise that resolves to a paged list of results.
|
|
19
|
+
*/
|
|
20
|
+
query: (pagedQuery: PagedQuery<FIELDS>, attributes?: Record<string, any>) => Promise<PagedList<R>>;
|
|
21
|
+
/**
|
|
22
|
+
* Optional additional attributes to pass to the query function.
|
|
23
|
+
*/
|
|
24
|
+
attributes?: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return type for the usePagedQuery hook.
|
|
28
|
+
* @template R - The type of the result items in the paged list.
|
|
29
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
30
|
+
* @template E - The type of the error.
|
|
31
|
+
*/
|
|
32
|
+
export interface UsePagedQueryReturn<R, FIELDS extends string = string, E = unknown> extends UseExecutePromiseReturn<PagedList<R>, E> {
|
|
33
|
+
/**
|
|
34
|
+
* Executes the paged query.
|
|
35
|
+
* @returns A promise that resolves to the paged list or an error.
|
|
36
|
+
*/
|
|
37
|
+
execute: () => Promise<E | PagedList<R>>;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the condition for the query.
|
|
40
|
+
* @param condition - The new condition.
|
|
41
|
+
*/
|
|
42
|
+
setCondition: (condition: Condition<FIELDS>) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the projection for the query.
|
|
45
|
+
* @param projection - The new projection.
|
|
46
|
+
*/
|
|
47
|
+
setProjection: (projection: Projection<FIELDS>) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the pagination for the query.
|
|
50
|
+
* @param pagination - The new pagination.
|
|
51
|
+
*/
|
|
52
|
+
setPagination: (pagination: Pagination) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Sets the sort order for the query.
|
|
55
|
+
* @param sort - The new sort array.
|
|
56
|
+
*/
|
|
57
|
+
setSort: (sort: FieldSort<FIELDS>[]) => void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A React hook for managing paged queries with state management for conditions, projections, pagination, and sorting.
|
|
61
|
+
* @template R - The type of the result items in the paged list.
|
|
62
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
63
|
+
* @template E - The type of the error.
|
|
64
|
+
* @param options - The options for the hook.
|
|
65
|
+
* @returns An object containing the query state and methods to update it.
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const { data, loading, error, execute, setCondition, setPagination } = usePagedQuery({
|
|
69
|
+
* initialQuery: { condition: {}, pagination: { index: 1, size: 10 }, projection: {}, sort: [] },
|
|
70
|
+
* query: async (pagedQuery) => fetchPagedData(pagedQuery),
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function usePagedQuery<R, FIELDS extends string = string, E = unknown>(options: UsePagedQueryOptions<R, FIELDS, E>): UsePagedQueryReturn<R, FIELDS>;
|
|
75
|
+
//# sourceMappingURL=usePagedQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePagedQuery.d.ts","sourceRoot":"","sources":["../../src/wow/usePagedQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,KAAK,UAAU,EAEf,UAAU,EACV,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,sBAAsB,EACX,uBAAuB,EACnC,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB,CACnC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/C;;OAEG;IACH,YAAY,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACjC;;;;;OAKG;IACH,KAAK,EAAE,CACL,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,EAC9B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB,CAClC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,uBAAuB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAChD;;;OAGG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC;;;OAGG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACrD;;;OAGG;IACH,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACxD;;;OAGG;IACH,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;IAChD;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC;CAC9C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,EAC1E,OAAO,EAAE,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAC1C,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC,CAsChC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { SingleQuery, Condition, Projection, FieldSort } from '@ahoo-wang/fetcher-wow';
|
|
2
|
+
import { UsePromiseStateOptions, UseExecutePromiseReturn } from '../core';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the useSingleQuery hook.
|
|
5
|
+
* @template R - The type of the result.
|
|
6
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
7
|
+
* @template E - The type of the error.
|
|
8
|
+
*/
|
|
9
|
+
export interface UseSingleQueryOptions<R, FIELDS extends string = string, E = unknown> extends UsePromiseStateOptions<R, E> {
|
|
10
|
+
/**
|
|
11
|
+
* The initial single query configuration.
|
|
12
|
+
*/
|
|
13
|
+
initialQuery: SingleQuery<FIELDS>;
|
|
14
|
+
/**
|
|
15
|
+
* The function to execute the single query.
|
|
16
|
+
* @param singleQuery - The single query object.
|
|
17
|
+
* @param attributes - Optional additional attributes.
|
|
18
|
+
* @returns A promise that resolves to the result.
|
|
19
|
+
*/
|
|
20
|
+
query: (singleQuery: SingleQuery<FIELDS>, attributes?: Record<string, any>) => Promise<R>;
|
|
21
|
+
/**
|
|
22
|
+
* Optional additional attributes to pass to the query function.
|
|
23
|
+
*/
|
|
24
|
+
attributes?: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return type for the useSingleQuery hook.
|
|
28
|
+
* @template R - The type of the result.
|
|
29
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
30
|
+
* @template E - The type of the error.
|
|
31
|
+
*/
|
|
32
|
+
export interface UseSingleQueryReturn<R, FIELDS extends string = string, E = unknown> extends UseExecutePromiseReturn<R, E> {
|
|
33
|
+
/**
|
|
34
|
+
* Executes the single query.
|
|
35
|
+
* @returns A promise that resolves to the result or an error.
|
|
36
|
+
*/
|
|
37
|
+
execute: () => Promise<E | R>;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the condition for the query.
|
|
40
|
+
* @param condition - The new condition.
|
|
41
|
+
*/
|
|
42
|
+
setCondition: (condition: Condition<FIELDS>) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the projection for the query.
|
|
45
|
+
* @param projection - The new projection.
|
|
46
|
+
*/
|
|
47
|
+
setProjection: (projection: Projection<FIELDS>) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Sets the sort order for the query.
|
|
50
|
+
* @param sort - The new sort array.
|
|
51
|
+
*/
|
|
52
|
+
setSort: (sort: FieldSort<FIELDS>[]) => void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A React hook for managing single queries with state management for conditions, projections, and sorting.
|
|
56
|
+
* @template R - The type of the result.
|
|
57
|
+
* @template FIELDS - The type of the fields used in conditions and projections.
|
|
58
|
+
* @template E - The type of the error.
|
|
59
|
+
* @param options - The options for the hook.
|
|
60
|
+
* @returns An object containing the query state and methods to update it.
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const { data, loading, error, execute, setCondition, setProjection } = useSingleQuery({
|
|
64
|
+
* initialQuery: { condition: {}, projection: {}, sort: [] },
|
|
65
|
+
* query: async (singleQuery) => fetchSingleData(singleQuery),
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function useSingleQuery<R, FIELDS extends string = string, E = unknown>(options: UseSingleQueryOptions<R, FIELDS, E>): UseSingleQueryReturn<R, FIELDS>;
|
|
70
|
+
//# sourceMappingURL=useSingleQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSingleQuery.d.ts","sourceRoot":"","sources":["../../src/wow/useSingleQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,WAAW,EACX,SAAS,EACT,KAAK,UAAU,EAEf,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,sBAAsB,EACX,uBAAuB,EACnC,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB,CACpC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC;IACpC;;OAEG;IACH,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC;;;;;OAKG;IACH,KAAK,EAAE,CACL,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC7B,OAAO,CAAC,CAAC,CAAC,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB,CACnC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,OAAO,CACX,SAAQ,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC;IACrC;;;OAGG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9B;;;OAGG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACrD;;;OAGG;IACH,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACxD;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,CAAC;CAC9C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,EAC3E,OAAO,EAAE,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAC3C,oBAAoB,CAAC,CAAC,EAAE,MAAM,CAAC,CA6BjC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher-react",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.9",
|
|
4
4
|
"description": "React integration for Fetcher HTTP client. Provides React Hooks and components for seamless data fetching with automatic re-rendering and loading states.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|
|
@@ -41,23 +41,24 @@
|
|
|
41
41
|
"dependencies": {},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@ahoo-wang/fetcher": "^2.3.4",
|
|
44
|
+
"@ahoo-wang/fetcher-eventstream": "^2.3.4",
|
|
44
45
|
"@ahoo-wang/fetcher-storage": "^2.3.4",
|
|
45
46
|
"@ahoo-wang/fetcher-wow": "^2.3.4",
|
|
46
47
|
"react": ">=16.8.0",
|
|
47
48
|
"react-dom": ">=16.8.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@eslint/js": "^9.
|
|
51
|
+
"@eslint/js": "^9.37.0",
|
|
51
52
|
"@vitest/coverage-v8": "^3.2.4",
|
|
52
53
|
"@vitest/ui": "^3.2.4",
|
|
53
|
-
"eslint": "^9.
|
|
54
|
+
"eslint": "^9.37.0",
|
|
54
55
|
"globals": "^16.4.0",
|
|
55
56
|
"prettier": "^3.6.2",
|
|
56
57
|
"typescript": "^5.9.3",
|
|
57
58
|
"typescript-eslint": "^8.45.0",
|
|
58
59
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
59
60
|
"unplugin-dts": "1.0.0-beta.6",
|
|
60
|
-
"vite": "^7.1.
|
|
61
|
+
"vite": "^7.1.9",
|
|
61
62
|
"vite-bundle-analyzer": "^1.2.3",
|
|
62
63
|
"vitest": "^3.2.4",
|
|
63
64
|
"@testing-library/react": "^16.0.0",
|