@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.
@@ -1,66 +1,45 @@
1
- import { SingleQuery, Condition, Projection, FieldSort } from '@ahoo-wang/fetcher-wow';
2
- import { UsePromiseStateOptions, UseExecutePromiseReturn } from '../core';
3
- import { AttributesCapable, FetcherError } from '@ahoo-wang/fetcher';
4
- import { AutoExecuteCapable } from './types';
1
+ import { SingleQuery } 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 useSingleQuery hook.
7
- * @template R - The type of the result.
8
- * @template FIELDS - The type of the fields used in conditions and projections.
9
- * @template E - The type of the error.
6
+ * Extends UseQueryOptions with SingleQuery as query key and custom result type.
7
+ *
8
+ * @template R - The result type of the query
9
+ * @template FIELDS - The fields type for the single query
10
+ * @template E - The error type, defaults to FetcherError
10
11
  */
11
- export interface UseSingleQueryOptions<R, FIELDS extends string = string, E = FetcherError> extends UsePromiseStateOptions<R, E>, AttributesCapable, AutoExecuteCapable {
12
- /**
13
- * The initial single query configuration.
14
- */
15
- initialQuery: SingleQuery<FIELDS>;
16
- /**
17
- * The function to execute the single query.
18
- * @param singleQuery - The single query object.
19
- * @param attributes - Optional additional attributes.
20
- * @returns A promise that resolves to the result.
21
- */
22
- query: (singleQuery: SingleQuery<FIELDS>, attributes?: Record<string, any>) => Promise<R>;
12
+ export interface UseSingleQueryOptions<R, FIELDS extends string = string, E = FetcherError> extends UseQueryOptions<SingleQuery<FIELDS>, R, E> {
23
13
  }
24
14
  /**
25
15
  * Return type for the useSingleQuery hook.
26
- * @template R - The type of the result.
27
- * @template FIELDS - The type of the fields used in conditions and projections.
28
- * @template E - The type of the error.
16
+ * Extends UseQueryReturn with SingleQuery as query key and custom result type.
17
+ *
18
+ * @template R - The result type of the query
19
+ * @template FIELDS - The fields type for the single query
20
+ * @template E - The error type, defaults to FetcherError
29
21
  */
30
- export interface UseSingleQueryReturn<R, FIELDS extends string = string, E = FetcherError> extends UseExecutePromiseReturn<R, E> {
31
- /**
32
- * Executes the single query.
33
- * @returns A promise that resolves to the result 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;
22
+ export interface UseSingleQueryReturn<R, FIELDS extends string = string, E = FetcherError> extends UseQueryReturn<SingleQuery<FIELDS>, R, E> {
51
23
  }
52
24
  /**
53
- * A React hook for managing single queries with state management for conditions, projections, and sorting.
54
- * @template R - The type of the result.
55
- * @template FIELDS - The type of the fields used in conditions and projections.
56
- * @template E - The type of the error.
57
- * @param options - The options for the hook.
58
- * @returns An object containing the query state and methods to update it.
25
+ * Hook for querying a single item with conditions, projection, and sorting.
26
+ * Wraps useQuery to provide type-safe single item queries.
27
+ *
28
+ * @template R - The result type of the query
29
+ * @template FIELDS - The fields type for the single query
30
+ * @template E - The error type, defaults to FetcherError
31
+ * @param options - The query options including single query configuration
32
+ * @returns The query result with single item data
33
+ *
59
34
  * @example
60
35
  * ```typescript
61
- * const { data, loading, error, execute, setCondition, setProjection } = useSingleQuery({
62
- * initialQuery: { condition: {}, projection: {}, sort: [] },
63
- * query: async (singleQuery) => fetchSingleData(singleQuery),
36
+ * const { data, isLoading } = useSingleQuery<{ 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) => fetchSingleItem(query),
64
43
  * });
65
44
  * ```
66
45
  */
@@ -1 +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,EAEtB,uBAAuB,EACxB,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,qBAAqB,CACpC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,SAAQ,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,kBAAkB;IAC3E;;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;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB,CACnC,CAAC,EACD,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,CAAC,GAAG,YAAY,CAChB,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,C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,CAAC,CAAC,GAC3C,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAEpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahoo-wang/fetcher-react",
3
- "version": "2.6.15",
3
+ "version": "2.6.18",
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",
@@ -55,7 +55,7 @@
55
55
  "globals": "^16.4.0",
56
56
  "prettier": "^3.6.2",
57
57
  "typescript": "^5.9.3",
58
- "typescript-eslint": "^8.45.0",
58
+ "typescript-eslint": "^8.46.0",
59
59
  "eslint-plugin-react-hooks": "^5.2.0",
60
60
  "unplugin-dts": "1.0.0-beta.6",
61
61
  "vite": "^7.1.9",
@@ -1,66 +0,0 @@
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
@@ -1 +0,0 @@
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,EA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