@ahoo-wang/fetcher-react 3.6.1 → 3.6.2
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/useQuery.d.ts +3 -5
- package/dist/core/useQuery.d.ts.map +1 -1
- package/dist/core/useQueryState.d.ts +30 -8
- package/dist/core/useQueryState.d.ts.map +1 -1
- package/dist/fetcher/useFetcherQuery.d.ts +3 -5
- package/dist/fetcher/useFetcherQuery.d.ts.map +1 -1
- package/dist/index.es.js +422 -422
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/core/useQuery.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { UseExecutePromiseReturn, UseExecutePromiseOptions } from './index';
|
|
1
|
+
import { UseExecutePromiseReturn, UseExecutePromiseOptions, QueryOptions } from './index';
|
|
2
2
|
import { AttributesCapable, FetcherError } from '@ahoo-wang/fetcher';
|
|
3
3
|
import { UseQueryStateReturn } from './useQueryState';
|
|
4
|
-
import { AutoExecuteCapable
|
|
4
|
+
import { AutoExecuteCapable } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Configuration options for the useQuery hook
|
|
7
7
|
* @template Q - The type of the query parameters
|
|
8
8
|
* @template R - The type of the result value
|
|
9
9
|
* @template E - The type of the error value
|
|
10
10
|
*/
|
|
11
|
-
export interface UseQueryOptions<Q, R, E = FetcherError> extends UseExecutePromiseOptions<R, E>, AttributesCapable, AutoExecuteCapable
|
|
12
|
-
/** The initial query parameters */
|
|
13
|
-
initialQuery: Q;
|
|
11
|
+
export interface UseQueryOptions<Q, R, E = FetcherError> extends UseExecutePromiseOptions<R, E>, QueryOptions<Q>, AttributesCapable, AutoExecuteCapable {
|
|
14
12
|
/** Function to execute the query with given parameters and optional attributes */
|
|
15
13
|
execute: (query: Q, attributes?: Record<string, any>, abortController?: AbortController) => Promise<R>;
|
|
16
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../src/core/useQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,uBAAuB,EACvB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../src/core/useQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,uBAAuB,EACvB,wBAAwB,EACP,YAAY,EAC9B,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAiB,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,CACrD,SAAQ,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,EACpC,YAAY,CAAC,CAAC,CAAC,EACf,iBAAiB,EACjB,kBAAkB;IAEpB,kFAAkF;IAClF,OAAO,EAAE,CACP,KAAK,EAAE,CAAC,EACR,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,eAAe,CAAC,EAAE,eAAe,KAC9B,OAAO,CAAC,CAAC,CAAC,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc,CAC7B,CAAC,EACD,CAAC,EACD,CAAC,GAAG,YAAY,CAChB,SAAQ,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAC7D,4DAA4D;IAC5D,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;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,CA+DzB"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { AutoExecuteCapable
|
|
1
|
+
import { AutoExecuteCapable } from '../types';
|
|
2
|
+
export interface QueryOptions<Q> {
|
|
3
|
+
/** The initial query parameters to be stored and managed */
|
|
4
|
+
initialQuery?: Q;
|
|
5
|
+
/** The current query parameters. If provided, overrides initialQuery and updates the state. */
|
|
6
|
+
query?: Q;
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* Configuration options for the useQueryState hook
|
|
4
10
|
* @template Q - The type of the query parameters
|
|
5
11
|
*/
|
|
6
|
-
export interface UseQueryStateOptions<Q> extends AutoExecuteCapable
|
|
7
|
-
/** The initial query parameters to be stored and managed */
|
|
8
|
-
initialQuery: Q;
|
|
12
|
+
export interface UseQueryStateOptions<Q> extends QueryOptions<Q>, AutoExecuteCapable {
|
|
9
13
|
/** Function to execute with the current query parameters. Called when autoExecute is true */
|
|
10
14
|
execute: (query: Q) => Promise<void>;
|
|
11
15
|
}
|
|
@@ -26,9 +30,15 @@ export interface UseQueryStateReturn<Q> {
|
|
|
26
30
|
* getting and setting the current query, and optionally automatically executing
|
|
27
31
|
* queries when the query changes or on component mount.
|
|
28
32
|
*
|
|
29
|
-
* @template Q - The type of the query parameters
|
|
33
|
+
* @template Q - The type of the query parameters, which can be any object type representing query data
|
|
30
34
|
* @param options - Configuration options for the hook
|
|
31
|
-
* @
|
|
35
|
+
* @param options.initialQuery - Optional initial query parameters to be stored and managed. Used if no query is provided.
|
|
36
|
+
* @param options.query - Optional current query parameters. If provided, overrides initialQuery and updates the state.
|
|
37
|
+
* @param options.autoExecute - Boolean flag indicating whether to automatically execute the query on mount or when query changes. Defaults to true.
|
|
38
|
+
* @param options.execute - Function to execute with the current query parameters. Called when autoExecute is true and query changes.
|
|
39
|
+
* @returns An object containing functions to manage the query state
|
|
40
|
+
* @returns getQuery - Function that returns the current query parameters of type Q
|
|
41
|
+
* @returns setQuery - Function that updates the query parameters and triggers execution if autoExecute is enabled
|
|
32
42
|
*
|
|
33
43
|
* @example
|
|
34
44
|
* ```typescript
|
|
@@ -65,8 +75,20 @@ export interface UseQueryStateReturn<Q> {
|
|
|
65
75
|
* }
|
|
66
76
|
* ```
|
|
67
77
|
*
|
|
68
|
-
* @
|
|
69
|
-
*
|
|
78
|
+
* @example
|
|
79
|
+
* // Example with autoExecute disabled
|
|
80
|
+
* const { getQuery, setQuery } = useQueryState<UserQuery>({
|
|
81
|
+
* initialQuery: { id: '1' },
|
|
82
|
+
* autoExecute: false,
|
|
83
|
+
* execute: executeQuery,
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* // Manually trigger execution
|
|
87
|
+
* setQuery({ id: '2' });
|
|
88
|
+
* executeQuery(getQuery());
|
|
89
|
+
*
|
|
90
|
+
* @throws {Error} Throws an error if neither initialQuery nor query is provided in the options.
|
|
91
|
+
* @throws Exceptions may also be thrown by the execute function if it encounters errors during query execution.
|
|
70
92
|
*/
|
|
71
93
|
export declare function useQueryState<Q>(options: UseQueryStateOptions<Q>): UseQueryStateReturn<Q>;
|
|
72
94
|
//# sourceMappingURL=useQueryState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueryState.d.ts","sourceRoot":"","sources":["../../src/core/useQueryState.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"useQueryState.d.ts","sourceRoot":"","sources":["../../src/core/useQueryState.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB,+FAA+F;IAC/F,KAAK,CAAC,EAAE,CAAC,CAAC;CACX;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,CACrC,SAAQ,YAAY,CAAC,CAAC,CAAC,EAAE,kBAAkB;IAC3C,6FAA6F;IAC7F,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,yFAAyF;IACzF,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC/B,mBAAmB,CAAC,CAAC,CAAC,CAiCxB"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { UseFetcherOptions, UseFetcherReturn } from './index';
|
|
2
2
|
import { FetcherError } from '@ahoo-wang/fetcher';
|
|
3
|
-
import { UseQueryStateReturn } from '../core';
|
|
4
|
-
import { AutoExecuteCapable
|
|
3
|
+
import { QueryOptions, UseQueryStateReturn } from '../core';
|
|
4
|
+
import { AutoExecuteCapable } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Configuration options for the useFetcherQuery hook
|
|
7
7
|
* @template Q - The type of the query parameters
|
|
8
8
|
* @template R - The type of the result value
|
|
9
9
|
* @template E - The type of the error value
|
|
10
10
|
*/
|
|
11
|
-
export interface UseFetcherQueryOptions<Q, R, E = FetcherError> extends UseFetcherOptions<R, E>, AutoExecuteCapable
|
|
11
|
+
export interface UseFetcherQueryOptions<Q, R, E = FetcherError> extends UseFetcherOptions<R, E>, QueryOptions<Q>, AutoExecuteCapable {
|
|
12
12
|
/** The URL endpoint to send the POST request to */
|
|
13
13
|
url: string;
|
|
14
|
-
/** The initial query parameters to be sent as the request body */
|
|
15
|
-
initialQuery: Q;
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
16
|
* Return type of the useFetcherQuery hook
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetcherQuery.d.ts","sourceRoot":"","sources":["../../src/fetcher/useFetcherQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAc,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAqC,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAA4B,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"useFetcherQuery.d.ts","sourceRoot":"","sources":["../../src/fetcher/useFetcherQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAc,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAqC,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAE,YAAY,EAA4B,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,CAC5D,SAAQ,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,kBAAkB;IACpE,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,CAC3D,SAAQ,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC;IACtD,4DAA4D;IAC5D,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,YAAY,EACpD,OAAO,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACvC,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CA8DhC"}
|