@ahoo-wang/fetcher-react 2.6.16 → 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 CHANGED
@@ -340,7 +340,7 @@ import { useListQuery } from '@ahoo-wang/fetcher-react';
340
340
  const MyComponent = () => {
341
341
  const { result, loading, error, execute, setCondition, setLimit } = useListQuery({
342
342
  initialQuery: { condition: {}, projection: {}, sort: [], limit: 10 },
343
- list: async (listQuery) => {
343
+ execute: async (listQuery) => {
344
344
  // Your list fetching logic here
345
345
  return fetchListData(listQuery);
346
346
  },
@@ -375,7 +375,7 @@ import { useListQuery } from '@ahoo-wang/fetcher-react';
375
375
  const MyComponent = () => {
376
376
  const { result, loading, error, execute, setCondition } = useListQuery({
377
377
  initialQuery: { condition: {}, projection: {}, sort: [], limit: 10 },
378
- list: async (listQuery) => fetchListData(listQuery),
378
+ execute: async (listQuery) => fetchListData(listQuery),
379
379
  autoExecute: true, // Automatically execute on component mount
380
380
  });
381
381
 
@@ -413,7 +413,7 @@ const MyComponent = () => {
413
413
  projection: {},
414
414
  sort: []
415
415
  },
416
- query: async (pagedQuery) => {
416
+ execute: async (pagedQuery) => {
417
417
  // Your paged fetching logic here
418
418
  return fetchPagedData(pagedQuery);
419
419
  },
@@ -430,7 +430,7 @@ const MyComponent = () => {
430
430
  return (
431
431
  <div>
432
432
  <ul>
433
- {result?.data?.map((item, index) => (
433
+ {result?.list?.map((item, index) => (
434
434
  <li key={index}>{item.name}</li>
435
435
  ))}
436
436
  </ul>
@@ -458,7 +458,7 @@ const MyComponent = () => {
458
458
  projection: {},
459
459
  sort: []
460
460
  },
461
- query: async (pagedQuery) => fetchPagedData(pagedQuery),
461
+ execute: async (pagedQuery) => fetchPagedData(pagedQuery),
462
462
  autoExecute: true, // Automatically execute on component mount
463
463
  });
464
464
 
@@ -470,7 +470,7 @@ const MyComponent = () => {
470
470
  return (
471
471
  <div>
472
472
  <ul>
473
- {result?.data?.map((item, index) => (
473
+ {result?.list?.map((item, index) => (
474
474
  <li key={index}>{item.name}</li>
475
475
  ))}
476
476
  </ul>
@@ -495,7 +495,7 @@ import { useSingleQuery } from '@ahoo-wang/fetcher-react';
495
495
  const MyComponent = () => {
496
496
  const { result, loading, error, execute, setCondition } = useSingleQuery({
497
497
  initialQuery: { condition: {}, projection: {}, sort: [] },
498
- query: async (singleQuery) => {
498
+ execute: async (singleQuery) => {
499
499
  // Your single item fetching logic here
500
500
  return fetchSingleData(singleQuery);
501
501
  },
@@ -526,7 +526,7 @@ import { useSingleQuery } from '@ahoo-wang/fetcher-react';
526
526
  const MyComponent = () => {
527
527
  const { result, loading, error, execute, setCondition } = useSingleQuery({
528
528
  initialQuery: { condition: {}, projection: {}, sort: [] },
529
- query: async (singleQuery) => fetchSingleData(singleQuery),
529
+ execute: async (singleQuery) => fetchSingleData(singleQuery),
530
530
  autoExecute: true, // Automatically execute on component mount
531
531
  });
532
532
 
@@ -552,8 +552,8 @@ import { useCountQuery } from '@ahoo-wang/fetcher-react';
552
552
 
553
553
  const MyComponent = () => {
554
554
  const { result, loading, error, execute, setCondition } = useCountQuery({
555
- initialCondition: {},
556
- count: async (condition) => {
555
+ initialQuery: {},
556
+ execute: async (condition) => {
557
557
  // Your count fetching logic here
558
558
  return fetchCount(condition);
559
559
  },
@@ -583,8 +583,8 @@ import { useCountQuery } from '@ahoo-wang/fetcher-react';
583
583
 
584
584
  const MyComponent = () => {
585
585
  const { result, loading, error, execute, setCondition } = useCountQuery({
586
- initialCondition: {},
587
- count: async (condition) => fetchCount(condition),
586
+ initialQuery: {},
587
+ execute: async (condition) => fetchCount(condition),
588
588
  autoExecute: true, // Automatically execute on component mount
589
589
  });
590
590
 
@@ -611,7 +611,7 @@ import { useListStreamQuery } from '@ahoo-wang/fetcher-react';
611
611
  const MyComponent = () => {
612
612
  const { result, loading, error, execute, setCondition } = useListStreamQuery({
613
613
  initialQuery: { condition: {}, projection: {}, sort: [], limit: 100 },
614
- listStream: async (listQuery) => {
614
+ execute: async (listQuery) => {
615
615
  // Your stream fetching logic here
616
616
  return fetchListStream(listQuery);
617
617
  },
@@ -655,7 +655,7 @@ import { useListStreamQuery } from '@ahoo-wang/fetcher-react';
655
655
  const MyComponent = () => {
656
656
  const { result, loading, error, execute, setCondition } = useListStreamQuery({
657
657
  initialQuery: { condition: {}, projection: {}, sort: [], limit: 100 },
658
- listStream: async (listQuery) => fetchListStream(listQuery),
658
+ execute: async (listQuery) => fetchListStream(listQuery),
659
659
  autoExecute: true, // Automatically execute on component mount
660
660
  });
661
661
 
@@ -947,7 +947,7 @@ A React hook for managing count queries with state management for conditions.
947
947
 
948
948
  **Parameters:**
949
949
 
950
- - `options`: Configuration options including initialCondition and count function
950
+ - `options`: Configuration options including initialQuery and execute function
951
951
  - `autoExecute`: Whether to automatically execute the query on component mount (defaults to false)
952
952
 
953
953
  **Returns:**
package/README.zh-CN.md CHANGED
@@ -94,7 +94,7 @@ import { useListQuery } from '@ahoo-wang/fetcher-react';
94
94
  const MyComponent = () => {
95
95
  const { result, loading, error, execute, setCondition } = useListQuery({
96
96
  initialQuery: { condition: {}, projection: {}, sort: [], limit: 10 },
97
- list: async (listQuery) => fetchListData(listQuery),
97
+ execute: async (listQuery) => fetchListData(listQuery),
98
98
  autoExecute: true, // 在组件挂载时自动执行
99
99
  });
100
100
 
@@ -330,8 +330,8 @@ import { useListQuery } from '@ahoo-wang/fetcher-react';
330
330
  const MyComponent = () => {
331
331
  const { result, loading, error, execute, setCondition, setLimit } = useListQuery({
332
332
  initialQuery: { condition: {}, projection: {}, sort: [], limit: 10 },
333
- list: async (listQuery) => {
334
- // 您的列表获取逻辑
333
+ execute: async (listQuery) => {
334
+ // Your list fetching logic here
335
335
  return fetchListData(listQuery);
336
336
  },
337
337
  });
@@ -372,8 +372,8 @@ const MyComponent = () => {
372
372
  projection: {},
373
373
  sort: []
374
374
  },
375
- query: async (pagedQuery) => {
376
- // 您的分页获取逻辑
375
+ execute: async (pagedQuery) => {
376
+ // Your paged fetching logic here
377
377
  return fetchPagedData(pagedQuery);
378
378
  },
379
379
  });
@@ -389,7 +389,7 @@ const MyComponent = () => {
389
389
  return (
390
390
  <div>
391
391
  <ul>
392
- {result?.data?.map((item, index) => (
392
+ {result?.list?.map((item, index) => (
393
393
  <li key={index}>{item.name}</li>
394
394
  ))}
395
395
  </ul>
@@ -414,7 +414,7 @@ import { useSingleQuery } from '@ahoo-wang/fetcher-react';
414
414
  const MyComponent = () => {
415
415
  const { result, loading, error, execute, setCondition } = useSingleQuery({
416
416
  initialQuery: { condition: {}, projection: {}, sort: [] },
417
- query: async (singleQuery) => {
417
+ execute: async (singleQuery) => {
418
418
  // 您的单个获取逻辑
419
419
  return fetchSingleData(singleQuery);
420
420
  },
@@ -446,8 +446,8 @@ import { useCountQuery } from '@ahoo-wang/fetcher-react';
446
446
 
447
447
  const MyComponent = () => {
448
448
  const { result, loading, error, execute, setCondition } = useCountQuery({
449
- initialCondition: {},
450
- count: async (condition) => {
449
+ initialQuery: {},
450
+ execute: async (condition) => {
451
451
  // 您的计数获取逻辑
452
452
  return fetchCount(condition);
453
453
  },
@@ -480,7 +480,7 @@ import { useListStreamQuery } from '@ahoo-wang/fetcher-react';
480
480
  const MyComponent = () => {
481
481
  const { result, loading, error, execute, setCondition } = useListStreamQuery({
482
482
  initialQuery: { condition: {}, projection: {}, sort: [], limit: 100 },
483
- listStream: async (listQuery) => {
483
+ execute: async (listQuery) => {
484
484
  // 您的流获取逻辑
485
485
  return fetchListStream(listQuery);
486
486
  },
@@ -768,7 +768,7 @@ function useCountQuery<FIELDS extends string = string, E = FetcherError>(
768
768
 
769
769
  **参数:**
770
770
 
771
- - `options`: 包含 initialConditioncount 函数的配置选项
771
+ - `options`: 包含 initialQueryexecute 函数的配置选项
772
772
  - `autoExecute`: 是否在组件挂载时自动执行查询(默认为 false)
773
773
 
774
774
  **返回值:**
@@ -1,3 +1,4 @@
1
+ import { MutableRefObject } from 'react';
1
2
  /**
2
3
  * A React hook that returns a ref containing the latest value, useful for accessing the current value in async callbacks.
3
4
  *
@@ -28,5 +29,5 @@
28
29
  * };
29
30
  * ```
30
31
  */
31
- export declare function useLatest<T>(value: T): import('react').MutableRefObject<T>;
32
+ export declare function useLatest<T>(value: T): MutableRefObject<T>;
32
33
  //# sourceMappingURL=useLatest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLatest.d.ts","sourceRoot":"","sources":["../../src/core/useLatest.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,uCAIpC"}
1
+ {"version":3,"file":"useLatest.d.ts","sourceRoot":"","sources":["../../src/core/useLatest.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAU,MAAM,OAAO,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAI1D"}
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
- import { useRef as S, useCallback as o, useEffect as m, useState as L, useMemo as b, useSyncExternalStore as p } from "react";
1
+ import { useRef as S, useCallback as u, useEffect as m, useState as L, useMemo as b, useSyncExternalStore as p } from "react";
2
2
  import { fetcherRegistrar as F, getFetcher as M } from "@ahoo-wang/fetcher";
3
3
  function R() {
4
- const t = S(!1), s = o(() => t.current, []);
4
+ const t = S(!1), s = u(() => t.current, []);
5
5
  return m(() => (t.current = !0, () => {
6
6
  t.current = !1;
7
7
  }), []), s;
@@ -15,175 +15,176 @@ function C(t) {
15
15
  const [s, e] = L(
16
16
  t?.initialStatus ?? "idle"
17
17
  /* IDLE */
18
- ), [u, a] = L(void 0), [r, n] = L(void 0), c = R(), i = w(t), l = o(() => {
19
- c() && (e(
18
+ ), [c, a] = L(void 0), [r, n] = L(void 0), o = R(), f = w(t), i = u(() => {
19
+ o() && (e(
20
20
  "loading"
21
21
  /* LOADING */
22
22
  ), n(void 0));
23
- }, [c]), d = o(
24
- async (f) => {
25
- if (c()) {
26
- a(f), e(
23
+ }, [o]), d = u(
24
+ async (l) => {
25
+ if (o()) {
26
+ a(l), e(
27
27
  "success"
28
28
  /* SUCCESS */
29
29
  ), n(void 0);
30
30
  try {
31
- await i.current?.onSuccess?.(f);
31
+ await f.current?.onSuccess?.(l);
32
32
  } catch (y) {
33
33
  console.warn("PromiseState onSuccess callback error:", y);
34
34
  }
35
35
  }
36
36
  },
37
- [c, i]
38
- ), E = o(
39
- async (f) => {
40
- if (c()) {
41
- n(f), e(
37
+ [o, f]
38
+ ), E = u(
39
+ async (l) => {
40
+ if (o()) {
41
+ n(l), e(
42
42
  "error"
43
43
  /* ERROR */
44
44
  ), a(void 0);
45
45
  try {
46
- await i.current?.onError?.(f);
46
+ await f.current?.onError?.(l);
47
47
  } catch (y) {
48
48
  console.warn("PromiseState onError callback error:", y);
49
49
  }
50
50
  }
51
51
  },
52
- [c, i]
53
- ), g = o(() => {
54
- c() && (e(
52
+ [o, f]
53
+ ), g = u(() => {
54
+ o() && (e(
55
55
  "idle"
56
56
  /* IDLE */
57
57
  ), n(void 0), a(void 0));
58
- }, [c]);
58
+ }, [o]);
59
59
  return b(
60
60
  () => ({
61
61
  status: s,
62
62
  loading: s === "loading",
63
- result: u,
63
+ result: c,
64
64
  error: r,
65
- setLoading: l,
65
+ setLoading: i,
66
66
  setSuccess: d,
67
67
  setError: E,
68
68
  setIdle: g
69
69
  }),
70
- [s, u, r, l, d, E, g]
70
+ [s, c, r, i, d, E, g]
71
71
  );
72
72
  }
73
73
  function Q() {
74
- const t = S(0), s = o(() => ++t.current, []), e = o(() => t.current, []), u = o((n) => n === t.current, []), a = o(() => {
74
+ const t = S(0), s = u(() => ++t.current, []), e = u(() => t.current, []), c = u((n) => n === t.current, []), a = u(() => {
75
75
  t.current++;
76
- }, []), r = o(() => {
76
+ }, []), r = u(() => {
77
77
  t.current = 0;
78
78
  }, []);
79
79
  return b(() => ({
80
80
  generate: s,
81
81
  current: e,
82
- isLatest: u,
82
+ isLatest: c,
83
83
  invalidate: a,
84
84
  reset: r
85
- }), [s, e, u, a, r]);
85
+ }), [s, e, c, a, r]);
86
86
  }
87
87
  function q(t) {
88
- const { loading: s, result: e, error: u, status: a, setLoading: r, setSuccess: n, setError: c, setIdle: i } = C(t), l = R(), d = Q(), E = t?.propagateError, g = o(
88
+ const { loading: s, result: e, error: c, status: a, setLoading: r, setSuccess: n, setError: o, setIdle: f } = C(t), i = R(), d = Q(), E = t?.propagateError, g = u(
89
89
  async (y) => {
90
- if (!l())
90
+ if (!i())
91
91
  throw new Error("Component is unmounted");
92
92
  const v = d.generate();
93
93
  r();
94
94
  try {
95
95
  const I = await (typeof y == "function" ? y() : y);
96
- return l() && d.isLatest(v) && await n(I), I;
96
+ return i() && d.isLatest(v) && await n(I), I;
97
97
  } catch (x) {
98
- if (l() && d.isLatest(v) && await c(x), E)
98
+ if (i() && d.isLatest(v) && await o(x), E)
99
99
  throw x;
100
100
  return x;
101
101
  }
102
102
  },
103
- [r, n, c, l, d, E]
104
- ), f = o(() => {
105
- l() && i();
106
- }, [i, l]);
103
+ [r, n, o, i, d, E]
104
+ ), l = u(() => {
105
+ i() && f();
106
+ }, [f, i]);
107
107
  return b(
108
108
  () => ({
109
109
  loading: s,
110
110
  result: e,
111
- error: u,
111
+ error: c,
112
112
  execute: g,
113
- reset: f,
113
+ reset: l,
114
114
  status: a
115
115
  }),
116
- [s, e, u, g, f, a]
116
+ [s, e, c, g, l, a]
117
117
  );
118
118
  }
119
119
  function P(t) {
120
- const s = o(
120
+ const s = u(
121
121
  (r) => t.addListener(r),
122
122
  [t]
123
- ), e = o(() => t.get(), [t]), u = p(s, e, e), a = o(
123
+ ), e = u(() => t.get(), [t]), c = p(s, e, e), a = u(
124
124
  (r) => t.set(r),
125
125
  [t]
126
126
  );
127
- return [u, a];
127
+ return [c, a];
128
128
  }
129
129
  function G(t) {
130
- const { fetcher: s = F.default } = t || {}, e = C(t), [u, a] = L(
130
+ const { fetcher: s = F.default } = t || {}, e = C(t), [c, a] = L(
131
131
  void 0
132
- ), r = R(), n = S(), c = Q(), i = w(t), l = M(s), d = o(
132
+ ), r = R(), n = S(), o = Q(), f = w(t), i = M(s), d = u(
133
133
  async (E) => {
134
134
  n.current && n.current.abort(), n.current = E.abortController ?? new AbortController(), E.abortController = n.current;
135
- const g = c.generate();
135
+ const g = o.generate();
136
136
  e.setLoading();
137
137
  try {
138
- const f = await l.exchange(
138
+ const l = await i.exchange(
139
139
  E,
140
- i.current
140
+ f.current
141
141
  );
142
- r() && c.isLatest(g) && a(f);
143
- const y = await f.extractResult();
144
- r() && c.isLatest(g) && await e.setSuccess(y);
145
- } catch (f) {
146
- if (f instanceof Error && f.name === "AbortError") {
142
+ r() && o.isLatest(g) && a(l);
143
+ const y = await l.extractResult();
144
+ r() && o.isLatest(g) && await e.setSuccess(y);
145
+ } catch (l) {
146
+ if (l instanceof Error && l.name === "AbortError") {
147
147
  r() && e.setIdle();
148
148
  return;
149
149
  }
150
- r() && c.isLatest(g) && await e.setError(f);
150
+ r() && o.isLatest(g) && await e.setError(l);
151
151
  } finally {
152
152
  n.current === E.abortController && (n.current = void 0);
153
153
  }
154
154
  },
155
- [l, r, i, e, c]
155
+ [i, r, f, e, o]
156
156
  );
157
157
  return m(() => () => {
158
158
  n.current?.abort(), n.current = void 0;
159
159
  }, []), b(
160
160
  () => ({
161
161
  ...e,
162
- exchange: u,
162
+ exchange: c,
163
163
  execute: d
164
164
  }),
165
- [e, u, d]
165
+ [e, c, d]
166
166
  );
167
167
  }
168
168
  function h(t) {
169
- const { initialQuery: s } = t, e = q(t), u = w(s), a = w(t), r = o(async () => a.current.execute(
170
- u.current,
169
+ const { initialQuery: s } = t, e = q(t), c = w(s), a = w(t), r = u(async () => a.current.execute(
170
+ c.current,
171
171
  a.current.attributes
172
- ), [u, a]), n = o(
173
- (d) => {
174
- u.current = d;
172
+ ), [c, a]), n = u(() => c.current, [c]), o = u(
173
+ (E) => {
174
+ c.current = E;
175
175
  },
176
- [u]
177
- ), { execute: c } = e, i = o(() => c(r), [c, r]), { autoExecute: l } = t;
176
+ [c]
177
+ ), { execute: f } = e, i = u(() => f(r), [f, r]), { autoExecute: d } = t;
178
178
  return m(() => {
179
- l && i();
180
- }, [l, i]), b(
179
+ d && i();
180
+ }, [d, i]), b(
181
181
  () => ({
182
182
  ...e,
183
183
  execute: i,
184
- setQuery: n
184
+ getQuery: n,
185
+ setQuery: o
185
186
  }),
186
- [e, i, n]
187
+ [e, i, n, o]
187
188
  );
188
189
  }
189
190
  function K(t) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/core/useMounted.ts","../src/core/useLatest.ts","../src/core/usePromiseState.ts","../src/core/useRequestId.ts","../src/core/useExecutePromise.ts","../src/storage/useKeyStorage.ts","../src/fetcher/useFetcher.ts","../src/wow/useQuery.ts","../src/wow/usePagedQuery.ts","../src/wow/useSingleQuery.ts","../src/wow/useCountQuery.ts","../src/wow/useListQuery.ts","../src/wow/useListStreamQuery.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef, useEffect, useCallback } from 'react';\n\n/**\n * A React hook that returns a function to check if the component is mounted.\n *\n * @returns A function that returns true if the component is mounted, false otherwise\n *\n * @example\n * ```typescript\n * import { useMounted } from '@ahoo-wang/fetcher-react';\n *\n * const MyComponent = () => {\n * const isMounted = useMounted();\n *\n * useEffect(() => {\n * someAsyncOperation().then(() => {\n * if (isMounted()) {\n * setState(result);\n * }\n * });\n * }, []);\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport function useMounted() {\n const isMountedRef = useRef(false);\n const isMountedFn = useCallback(() => isMountedRef.current, []);\n useEffect(() => {\n isMountedRef.current = true;\n return () => {\n isMountedRef.current = false;\n };\n }, []);\n\n return isMountedFn;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef } from 'react';\n\n/**\n * A React hook that returns a ref containing the latest value, useful for accessing the current value in async callbacks.\n *\n * @template T - The type of the value\n * @param value - The value to track\n * @returns A ref object containing the latest value\n *\n * @example\n * ```typescript\n * import { useLatest } from '@ahoo-wang/fetcher-react';\n *\n * const MyComponent = () => {\n * const [count, setCount] = useState(0);\n * const latestCount = useLatest(count);\n *\n * const handleAsync = async () => {\n * await someAsyncOperation();\n * console.log('Latest count:', latestCount.current); // Always the latest\n * };\n *\n * return (\n * <div>\n * <p>Count: {count}</p>\n * <button onClick={() => setCount(c => c + 1)}>Increment</button>\n * <button onClick={handleAsync}>Async Log</button>\n * </div>\n * );\n * };\n * ```\n */\nexport function useLatest<T>(value: T) {\n const ref = useRef(value);\n ref.current = value;\n return ref;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useMemo, useState } from 'react';\nimport { useMounted } from './useMounted';\nimport { useLatest } from './useLatest';\nimport { FetcherError } from '@ahoo-wang/fetcher';\n\n/**\n * Enumeration of possible promise execution states\n */\nexport enum PromiseStatus {\n IDLE = 'idle',\n LOADING = 'loading',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nexport interface PromiseState<R, E = unknown> {\n /** Current status of the promise */\n status: PromiseStatus;\n /** Indicates if currently loading */\n loading: boolean;\n /** The result value */\n result: R | undefined;\n /** The error value */\n error: E | undefined;\n}\n\nexport interface PromiseStateCallbacks<R, E = unknown> {\n /** Callback invoked on success (can be async) */\n onSuccess?: (result: R) => void | Promise<void>;\n /** Callback invoked on error (can be async) */\n onError?: (error: E) => void | Promise<void>;\n}\n\n/**\n * Options for configuring usePromiseState behavior\n * @template R - The type of result\n *\n * @example\n * ```typescript\n * const options: UsePromiseStateOptions<string> = {\n * initialStatus: PromiseStatus.IDLE,\n * onSuccess: (result) => console.log('Success:', result),\n * onError: async (error) => {\n * await logErrorToServer(error);\n * console.error('Error:', error);\n * },\n * };\n * ```\n */\nexport interface UsePromiseStateOptions<R, E = FetcherError>\n extends PromiseStateCallbacks<R, E> {\n /** Initial status, defaults to IDLE */\n initialStatus?: PromiseStatus;\n}\n\n/**\n * Return type for usePromiseState hook\n * @template R - The type of result\n */\nexport interface UsePromiseStateReturn<R, E = FetcherError>\n extends PromiseState<R, E> {\n /** Set status to LOADING */\n setLoading: () => void;\n /** Set status to SUCCESS with result */\n setSuccess: (result: R) => Promise<void>;\n /** Set status to ERROR with error */\n setError: (error: E) => Promise<void>;\n /** Set status to IDLE */\n setIdle: () => void;\n}\n\n/**\n * A React hook for managing promise state without execution logic\n * @template R - The type of result\n * @param options - Configuration options\n * @returns State management object\n *\n * @example\n * ```typescript\n * import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();\n *\n * const handleSuccess = () => setSuccess('Data loaded');\n * const handleError = () => setError(new Error('Failed to load'));\n *\n * return (\n * <div>\n * <button onClick={handleSuccess}>Set Success</button>\n * <button onClick={handleError}>Set Error</button>\n * <button onClick={setIdle}>Reset</button>\n * <p>Status: {status}</p>\n * {loading && <p>Loading...</p>}\n * {result && <p>Result: {result}</p>}\n * {error && <p>Error: {error.message}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function usePromiseState<R = unknown, E = FetcherError>(\n options?: UsePromiseStateOptions<R, E>,\n): UsePromiseStateReturn<R, E> {\n const [status, setStatus] = useState<PromiseStatus>(\n options?.initialStatus ?? PromiseStatus.IDLE,\n );\n const [result, setResult] = useState<R | undefined>(undefined);\n const [error, setErrorState] = useState<E | undefined>(undefined);\n const isMounted = useMounted();\n const latestOptions = useLatest(options);\n const setLoadingFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.LOADING);\n setErrorState(undefined);\n }\n }, [isMounted]);\n\n const setSuccessFn = useCallback(\n async (result: R) => {\n if (isMounted()) {\n setResult(result);\n setStatus(PromiseStatus.SUCCESS);\n setErrorState(undefined);\n try {\n await latestOptions.current?.onSuccess?.(result);\n } catch (callbackError) {\n // Log callback errors but don't affect state\n console.warn('PromiseState onSuccess callback error:', callbackError);\n }\n }\n },\n [isMounted, latestOptions],\n );\n\n const setErrorFn = useCallback(\n async (error: E) => {\n if (isMounted()) {\n setErrorState(error);\n setStatus(PromiseStatus.ERROR);\n setResult(undefined);\n try {\n await latestOptions.current?.onError?.(error);\n } catch (callbackError) {\n // Log callback errors but don't affect state\n console.warn('PromiseState onError callback error:', callbackError);\n }\n }\n },\n [isMounted, latestOptions],\n );\n\n const setIdleFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.IDLE);\n setErrorState(undefined);\n setResult(undefined);\n }\n }, [isMounted]);\n return useMemo(\n () => ({\n status,\n loading: status === PromiseStatus.LOADING,\n result,\n error,\n setLoading: setLoadingFn,\n setSuccess: setSuccessFn,\n setError: setErrorFn,\n setIdle: setIdleFn,\n }),\n [status, result, error, setLoadingFn, setSuccessFn, setErrorFn, setIdleFn],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef, useCallback, useMemo } from 'react';\n\n/**\n * Return type for useRequestId hook\n */\nexport interface UseRequestIdReturn {\n /** Generate a new request ID and get the current one */\n generate: () => number;\n /** Get the current request ID without generating a new one */\n current: () => number;\n /** Check if a given request ID is the latest */\n isLatest: (requestId: number) => boolean;\n /** Invalidate current request ID (mark as stale) */\n invalidate: () => void;\n /** Reset request ID counter */\n reset: () => void;\n}\n\n/**\n * A React hook for managing request IDs and race condition protection\n *\n * @example\n * ```typescript\n * // Basic usage\n * const requestId = useRequestId();\n *\n * const execute = async () => {\n * const id = requestId.generate();\n *\n * try {\n * const result = await someAsyncOperation();\n *\n * // Check if this is still the latest request\n * if (requestId.isLatest(id)) {\n * setState(result);\n * }\n * } catch (error) {\n * if (requestId.isLatest(id)) {\n * setError(error);\n * }\n * }\n * };\n *\n * // Manual cancellation\n * const handleCancel = () => {\n * requestId.invalidate(); // All ongoing requests will be ignored\n * };\n * ```\n *\n * @example\n * ```typescript\n * // With async operation wrapper\n * const { execute, cancel } = useAsyncOperation(async (data) => {\n * return await apiCall(data);\n * }, [requestId]);\n * ```\n */\nexport function useRequestId(): UseRequestIdReturn {\n const requestIdRef = useRef<number>(0);\n\n const generate = useCallback((): number => {\n return ++requestIdRef.current;\n }, []);\n\n const current = useCallback((): number => {\n return requestIdRef.current;\n }, []);\n\n const isLatest = useCallback((requestId: number): boolean => {\n return requestId === requestIdRef.current;\n }, []);\n\n const invalidate = useCallback((): void => {\n requestIdRef.current++;\n }, []);\n\n const reset = useCallback((): void => {\n requestIdRef.current = 0;\n }, []);\n return useMemo(() => {\n return {\n generate,\n current,\n isLatest,\n invalidate,\n reset,\n };\n }, [generate, current, isLatest, invalidate, reset]);\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { useMounted } from './useMounted';\nimport {\n usePromiseState,\n PromiseState,\n UsePromiseStateOptions,\n} from './usePromiseState';\nimport { useRequestId } from './useRequestId';\nimport { FetcherError } from '@ahoo-wang/fetcher';\n\nexport interface UseExecutePromiseOptions<R, E = unknown>\n extends UsePromiseStateOptions<R, E> {\n /**\n * Whether to propagate errors thrown by the promise.\n * If true, the execute function will throw errors.\n * If false (default), the execute function will return the error as the result instead of throwing.\n */\n propagateError?: boolean;\n}\n\n/**\n * Type definition for a function that returns a Promise\n * @template R - The type of value the promise will resolve to\n */\nexport type PromiseSupplier<R> = () => Promise<R>;\n\n/**\n * Interface defining the return type of useExecutePromise hook\n * @template R - The type of the result value\n */\nexport interface UseExecutePromiseReturn<R, E = FetcherError>\n extends PromiseState<R, E> {\n /**\n * Function to execute a promise supplier or promise.\n * Returns a promise that resolves to the result on success, or the error if propagateError is false.\n */\n execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R | E>;\n /** Function to reset the state to initial values */\n reset: () => void;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @template R - The type of the result value\n * @template E - The type of the error value\n * @param options - Configuration options for the hook\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useExecutePromise } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n *\n * const fetchData = async () => {\n * const response = await fetch('/api/data');\n * return response.text();\n * };\n *\n * const handleFetch = () => {\n * execute(fetchData);\n * };\n *\n * const handleReset = () => {\n * reset();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * <button onClick={handleReset}>Reset</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n *\n * // Example with propagateError set to true\n * const { execute } = useExecutePromise<string>({ propagateError: true });\n * try {\n * await execute(fetchData);\n * } catch (err) {\n * console.error('Error occurred:', err);\n * }\n * ```\n */\nexport function useExecutePromise<R = unknown, E = FetcherError>(\n options?: UseExecutePromiseOptions<R, E>,\n): UseExecutePromiseReturn<R, E> {\n const { loading, result, error, status, setLoading, setSuccess, setError, setIdle } = usePromiseState<R, E>(options);\n const isMounted = useMounted();\n const requestId = useRequestId();\n const propagateError = options?.propagateError;\n /**\n * Execute a promise supplier or promise and manage its state\n * @param input - A function that returns a Promise or a Promise to be executed\n * @returns A Promise that resolves with the result on success, or the error if propagateError is false\n */\n const execute = useCallback(\n async (input: PromiseSupplier<R> | Promise<R>): Promise<R | E> => {\n if (!isMounted()) {\n throw new Error('Component is unmounted');\n }\n const currentRequestId = requestId.generate();\n setLoading();\n try {\n const promise = typeof input === 'function' ? input() : input;\n const data = await promise;\n\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await setSuccess(data);\n }\n return data;\n } catch (err) {\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await setError(err as E);\n }\n if (propagateError) {\n throw err;\n }\n return err as E;\n }\n },\n [setLoading, setSuccess, setError, isMounted, requestId, propagateError],\n );\n\n /**\n * Reset the state to initial values\n */\n const reset = useCallback(() => {\n if (isMounted()) {\n setIdle();\n }\n }, [setIdle, isMounted]);\n\n return useMemo(\n () => ({\n loading: loading,\n result: result,\n error: error,\n execute,\n reset,\n status: status,\n }),\n [loading, result, error, execute, reset, status],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { KeyStorage } from '@ahoo-wang/fetcher-storage';\n\n/**\n * A React hook that provides state management for a KeyStorage instance.\n * Subscribes to storage changes and returns the current value along with a setter function.\n *\n * @template T - The type of value stored in the key storage\n * @param keyStorage - The KeyStorage instance to subscribe to and manage\n * @returns A tuple containing the current stored value and a function to update it\n */\nexport function useKeyStorage<T>(\n keyStorage: KeyStorage<T>,\n): [T | null, (value: T) => void] {\n const subscribe = useCallback(\n (callback: () => void) => keyStorage.addListener(callback),\n [keyStorage],\n );\n const getSnapshot = useCallback(() => keyStorage.get(), [keyStorage]);\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setValue = useCallback(\n (value: T) => keyStorage.set(value),\n [keyStorage],\n );\n return [value, setValue];\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n fetcherRegistrar,\n FetcherCapable,\n FetchExchange,\n FetchRequest,\n getFetcher,\n RequestOptions, FetcherError,\n} from '@ahoo-wang/fetcher';\nimport { useMounted } from '../core';\nimport { useRef, useCallback, useEffect, useState, useMemo } from 'react';\nimport {\n PromiseState,\n useLatest,\n usePromiseState,\n UsePromiseStateOptions,\n useRequestId,\n} from '../core';\n\n/**\n * Configuration options for the useFetcher hook.\n * Extends RequestOptions and FetcherCapable interfaces.\n */\nexport interface UseFetcherOptions<R, E = FetcherError>\n extends RequestOptions,\n FetcherCapable,\n UsePromiseStateOptions<R, E> {\n}\n\nexport interface UseFetcherReturn<R, E = FetcherError> extends PromiseState<R, E> {\n /** The FetchExchange object representing the ongoing fetch operation */\n exchange?: FetchExchange;\n execute: (request: FetchRequest) => Promise<void>;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @param options - Configuration options for the fetcher\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useFetcher } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute } = useFetcher<string>();\n *\n * const handleFetch = () => {\n * execute({ url: '/api/data', method: 'GET' });\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useFetcher<R, E = FetcherError>(\n options?: UseFetcherOptions<R, E>,\n): UseFetcherReturn<R, E> {\n const { fetcher = fetcherRegistrar.default } = options || {};\n const state = usePromiseState<R, E>(options);\n const [exchange, setExchange] = useState<FetchExchange | undefined>(\n undefined,\n );\n const isMounted = useMounted();\n const abortControllerRef = useRef<AbortController | undefined>();\n const requestId = useRequestId();\n const latestOptions = useLatest(options);\n const currentFetcher = getFetcher(fetcher);\n /**\n * Execute the fetch operation.\n * Cancels any ongoing fetch before starting a new one.\n */\n const execute = useCallback(\n async (request: FetchRequest) => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n abortControllerRef.current =\n request.abortController ?? new AbortController();\n request.abortController = abortControllerRef.current;\n const currentRequestId = requestId.generate();\n state.setLoading();\n try {\n const exchange = await currentFetcher.exchange(\n request,\n latestOptions.current,\n );\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n setExchange(exchange);\n }\n const result = await exchange.extractResult<R>();\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await state.setSuccess(result);\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n if (isMounted()) {\n state.setIdle();\n }\n return;\n }\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await state.setError(error as E);\n }\n } finally {\n if (abortControllerRef.current === request.abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [currentFetcher, isMounted, latestOptions, state, requestId],\n );\n\n useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = undefined;\n };\n }, []);\n return useMemo(\n () => ({\n ...state,\n exchange,\n execute,\n }),\n [state, exchange, execute],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n useExecutePromise,\n useLatest,\n UseExecutePromiseReturn,\n UseExecutePromiseOptions,\n} from '../core';\nimport { useCallback, useMemo, useEffect } from 'react';\nimport { AttributesCapable, FetcherError } from '@ahoo-wang/fetcher';\nimport { AutoExecuteCapable } from './types';\n\n/**\n * Configuration options for the useQuery hook\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n */\nexport interface UseQueryOptions<Q, R, E = FetcherError>\n extends UseExecutePromiseOptions<R, E>,\n AttributesCapable,\n AutoExecuteCapable {\n /** The initial query parameters */\n initialQuery: Q;\n\n /** Function to execute the query with given parameters and optional attributes */\n execute: (query: Q, attributes?: Record<string, any>) => Promise<R>;\n}\n\n/**\n * Return type of the useQuery hook\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n */\nexport interface UseQueryReturn<Q, R, E = FetcherError>\n extends UseExecutePromiseReturn<R, E> {\n /** Function to execute the query with current parameters */\n execute: () => Promise<R | E>;\n /** Function to update the query parameters */\n setQuery: (query: Q) => void;\n}\n\n/**\n * A React hook for managing query-based asynchronous operations\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n * @param options - Configuration options for the query\n * @returns An object containing the query state and control functions\n *\n * @example\n * ```typescript\n * import { useQuery } from '@ahoo-wang/fetcher-react';\n *\n * interface UserQuery {\n * id: string;\n * }\n *\n * interface User {\n * id: string;\n * name: string;\n * }\n *\n * function UserComponent() {\n * const { loading, result, error, execute, setQuery } = useQuery<UserQuery, User>({\n * initialQuery: { id: '1' },\n * execute: async (query) => {\n * const response = await fetch(`/api/users/${query.id}`);\n * return response.json();\n * },\n * autoExecute: true,\n * });\n *\n * const handleUserChange = (userId: string) => {\n * setQuery({ id: userId });\n * execute();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={() => handleUserChange('2')}>Load User 2</button>\n * {result && <p>User: {result.name}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useQuery<Q, R, E = FetcherError>(\n options: UseQueryOptions<Q, R, E>,\n): UseQueryReturn<Q, R, E> {\n const { initialQuery } = options;\n const promiseState = useExecutePromise<R, E>(options);\n const latestQuery = useLatest(initialQuery);\n const latestOptions = useLatest(options);\n const queryExecutor = useCallback(async (): Promise<R> => {\n return latestOptions.current.execute(\n latestQuery.current,\n latestOptions.current.attributes,\n );\n }, [latestQuery, latestOptions]);\n const setQuery = useCallback(\n (query: Q) => {\n latestQuery.current = query;\n },\n [latestQuery],\n );\n const { execute: promiseExecutor } = promiseState;\n const execute = useCallback(() => {\n return promiseExecutor(queryExecutor);\n }, [promiseExecutor, queryExecutor]);\n\n const { autoExecute } = options;\n\n useEffect(() => {\n if (autoExecute) {\n execute();\n }\n }, [autoExecute, execute]);\n\n return useMemo(\n () => ({\n ...promiseState,\n execute,\n setQuery,\n }),\n [promiseState, execute, setQuery],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PagedList, PagedQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the usePagedQuery hook.\n * Extends UseQueryOptions with PagedQuery as query key and PagedList as data type.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UsePagedQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<PagedQuery<FIELDS>, PagedList<R>, E> {\n}\n\n/**\n * Return type for the usePagedQuery hook.\n * Extends UseQueryReturn with PagedQuery as query key and PagedList as data type.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UsePagedQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<PagedQuery<FIELDS>, PagedList<R>, E> {\n}\n\n/**\n * Hook for querying paged data with conditions, projection, pagination, and sorting.\n * Wraps useQuery to provide type-safe paged queries.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including paged query configuration\n * @returns The query result with paged list data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = usePagedQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * pagination: { index: 1, size: 10 },\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchPagedData(query),\n * });\n * ```\n */\nexport function usePagedQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UsePagedQueryOptions<R, FIELDS, E>,\n): UsePagedQueryReturn<R, FIELDS, E> {\n return useQuery<PagedQuery<FIELDS>, PagedList<R>, E>(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SingleQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useSingleQuery hook.\n * Extends UseQueryOptions with SingleQuery as query key and custom result type.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseSingleQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<SingleQuery<FIELDS>, R, E> {\n}\n\n/**\n * Return type for the useSingleQuery hook.\n * Extends UseQueryReturn with SingleQuery as query key and custom result type.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseSingleQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<SingleQuery<FIELDS>, R, E> {\n}\n\n/**\n * Hook for querying a single item with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe single item queries.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including single query configuration\n * @returns The query result with single item data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useSingleQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchSingleItem(query),\n * });\n * ```\n */\nexport function useSingleQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseSingleQueryOptions<R, FIELDS, E>,\n): UseSingleQueryReturn<R, FIELDS, E> {\n return useQuery<SingleQuery<FIELDS>, R, E>(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Condition } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useCountQuery hook.\n * Extends UseQueryOptions with Condition as query key and number as data type.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseCountQueryOptions<\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<Condition<FIELDS>, number, E> {\n}\n\n/**\n * Return type for the useCountQuery hook.\n * Extends UseQueryReturn with Condition as query key and number as data type.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseCountQueryReturn<\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<Condition<FIELDS>, number, E> {\n}\n\n/**\n * Hook for querying count data with conditions.\n * Wraps useQuery to provide type-safe count queries.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including condition and other settings\n * @returns The query result with count data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useCountQuery({\n * queryKey: [{ field: 'status', operator: 'eq', value: 'active' }],\n * queryFn: async (condition) => fetchCount(condition),\n * });\n * ```\n */\nexport function useCountQuery<FIELDS extends string = string, E = FetcherError>(\n options: UseCountQueryOptions<FIELDS, E>,\n): UseCountQueryReturn<FIELDS, E> {\n return useQuery(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ListQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useListQuery hook.\n * Extends UseQueryOptions with ListQuery as query key and array of results as data type.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<ListQuery<FIELDS>, R[], E> {\n}\n\n/**\n * Return type for the useListQuery hook.\n * Extends UseQueryReturn with ListQuery as query key and array of results as data type.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<ListQuery<FIELDS>, R[], E> {\n}\n\n/**\n * Hook for querying list data with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe list queries.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including list query configuration\n * @returns The query result with list data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useListQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchListData(query),\n * });\n * ```\n */\nexport function useListQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseListQueryOptions<R, FIELDS, E>,\n): UseListQueryReturn<R, FIELDS, E> {\n return useQuery<ListQuery<FIELDS>, R[], E>(options);\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ListQuery } from '@ahoo-wang/fetcher-wow';\nimport type { JsonServerSentEvent } from '@ahoo-wang/fetcher-eventstream';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useListStreamQuery hook.\n * Extends UseQueryOptions with ListQuery as query key and stream of events as data type.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListStreamQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<\n ListQuery<FIELDS>,\n ReadableStream<JsonServerSentEvent<R>>,\n E\n> {\n}\n\n/**\n * Return type for the useListStreamQuery hook.\n * Extends UseQueryReturn with ListQuery as query key and stream of events as data type.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListStreamQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<\n ListQuery<FIELDS>,\n ReadableStream<JsonServerSentEvent<R>>,\n E\n> {\n}\n\n/**\n * Hook for querying streaming list data with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe streaming list queries.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including list stream query configuration\n * @returns The query result with streaming data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useListStreamQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchStreamData(query),\n * });\n * ```\n */\nexport function useListStreamQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseListStreamQueryOptions<R, FIELDS, E>,\n): UseListStreamQueryReturn<R, FIELDS, E> {\n return useQuery<ListQuery<FIELDS>, ReadableStream<JsonServerSentEvent<R>>, E>(\n options,\n );\n}\n"],"names":["useMounted","isMountedRef","useRef","isMountedFn","useCallback","useEffect","useLatest","value","ref","PromiseStatus","usePromiseState","options","status","setStatus","useState","result","setResult","error","setErrorState","isMounted","latestOptions","setLoadingFn","setSuccessFn","callbackError","setErrorFn","setIdleFn","useMemo","useRequestId","requestIdRef","generate","current","isLatest","requestId","invalidate","reset","useExecutePromise","loading","setLoading","setSuccess","setError","setIdle","propagateError","execute","input","currentRequestId","data","err","useKeyStorage","keyStorage","subscribe","callback","getSnapshot","useSyncExternalStore","setValue","useFetcher","fetcher","fetcherRegistrar","state","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request","useQuery","initialQuery","promiseState","latestQuery","queryExecutor","setQuery","query","promiseExecutor","autoExecute","usePagedQuery","useSingleQuery","useCountQuery","useListQuery","useListStreamQuery"],"mappings":";;AAuCO,SAASA,IAAa;AAC3B,QAAMC,IAAeC,EAAO,EAAK,GAC3BC,IAAcC,EAAY,MAAMH,EAAa,SAAS,CAAA,CAAE;AAC9D,SAAAI,EAAU,OACRJ,EAAa,UAAU,IAChB,MAAM;AACX,IAAAA,EAAa,UAAU;AAAA,EACzB,IACC,CAAA,CAAE,GAEEE;AACT;ACLO,SAASG,EAAaC,GAAU;AACrC,QAAMC,IAAMN,EAAOK,CAAK;AACxB,SAAAC,EAAI,UAAUD,GACPC;AACT;AC5BO,IAAKC,sBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,UAAU,WACVA,EAAA,UAAU,WACVA,EAAA,QAAQ,SAJEA,IAAAA,KAAA,CA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,"file":"index.es.js","sources":["../src/core/useMounted.ts","../src/core/useLatest.ts","../src/core/usePromiseState.ts","../src/core/useRequestId.ts","../src/core/useExecutePromise.ts","../src/storage/useKeyStorage.ts","../src/fetcher/useFetcher.ts","../src/wow/useQuery.ts","../src/wow/usePagedQuery.ts","../src/wow/useSingleQuery.ts","../src/wow/useCountQuery.ts","../src/wow/useListQuery.ts","../src/wow/useListStreamQuery.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef, useEffect, useCallback } from 'react';\n\n/**\n * A React hook that returns a function to check if the component is mounted.\n *\n * @returns A function that returns true if the component is mounted, false otherwise\n *\n * @example\n * ```typescript\n * import { useMounted } from '@ahoo-wang/fetcher-react';\n *\n * const MyComponent = () => {\n * const isMounted = useMounted();\n *\n * useEffect(() => {\n * someAsyncOperation().then(() => {\n * if (isMounted()) {\n * setState(result);\n * }\n * });\n * }, []);\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport function useMounted() {\n const isMountedRef = useRef(false);\n const isMountedFn = useCallback(() => isMountedRef.current, []);\n useEffect(() => {\n isMountedRef.current = true;\n return () => {\n isMountedRef.current = false;\n };\n }, []);\n\n return isMountedFn;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { MutableRefObject, useRef } from 'react';\n\n/**\n * A React hook that returns a ref containing the latest value, useful for accessing the current value in async callbacks.\n *\n * @template T - The type of the value\n * @param value - The value to track\n * @returns A ref object containing the latest value\n *\n * @example\n * ```typescript\n * import { useLatest } from '@ahoo-wang/fetcher-react';\n *\n * const MyComponent = () => {\n * const [count, setCount] = useState(0);\n * const latestCount = useLatest(count);\n *\n * const handleAsync = async () => {\n * await someAsyncOperation();\n * console.log('Latest count:', latestCount.current); // Always the latest\n * };\n *\n * return (\n * <div>\n * <p>Count: {count}</p>\n * <button onClick={() => setCount(c => c + 1)}>Increment</button>\n * <button onClick={handleAsync}>Async Log</button>\n * </div>\n * );\n * };\n * ```\n */\nexport function useLatest<T>(value: T): MutableRefObject<T> {\n const ref = useRef(value);\n ref.current = value;\n return ref;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useMemo, useState } from 'react';\nimport { useMounted } from './useMounted';\nimport { useLatest } from './useLatest';\nimport { FetcherError } from '@ahoo-wang/fetcher';\n\n/**\n * Enumeration of possible promise execution states\n */\nexport enum PromiseStatus {\n IDLE = 'idle',\n LOADING = 'loading',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nexport interface PromiseState<R, E = unknown> {\n /** Current status of the promise */\n status: PromiseStatus;\n /** Indicates if currently loading */\n loading: boolean;\n /** The result value */\n result: R | undefined;\n /** The error value */\n error: E | undefined;\n}\n\nexport interface PromiseStateCallbacks<R, E = unknown> {\n /** Callback invoked on success (can be async) */\n onSuccess?: (result: R) => void | Promise<void>;\n /** Callback invoked on error (can be async) */\n onError?: (error: E) => void | Promise<void>;\n}\n\n/**\n * Options for configuring usePromiseState behavior\n * @template R - The type of result\n *\n * @example\n * ```typescript\n * const options: UsePromiseStateOptions<string> = {\n * initialStatus: PromiseStatus.IDLE,\n * onSuccess: (result) => console.log('Success:', result),\n * onError: async (error) => {\n * await logErrorToServer(error);\n * console.error('Error:', error);\n * },\n * };\n * ```\n */\nexport interface UsePromiseStateOptions<R, E = FetcherError>\n extends PromiseStateCallbacks<R, E> {\n /** Initial status, defaults to IDLE */\n initialStatus?: PromiseStatus;\n}\n\n/**\n * Return type for usePromiseState hook\n * @template R - The type of result\n */\nexport interface UsePromiseStateReturn<R, E = FetcherError>\n extends PromiseState<R, E> {\n /** Set status to LOADING */\n setLoading: () => void;\n /** Set status to SUCCESS with result */\n setSuccess: (result: R) => Promise<void>;\n /** Set status to ERROR with error */\n setError: (error: E) => Promise<void>;\n /** Set status to IDLE */\n setIdle: () => void;\n}\n\n/**\n * A React hook for managing promise state without execution logic\n * @template R - The type of result\n * @param options - Configuration options\n * @returns State management object\n *\n * @example\n * ```typescript\n * import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();\n *\n * const handleSuccess = () => setSuccess('Data loaded');\n * const handleError = () => setError(new Error('Failed to load'));\n *\n * return (\n * <div>\n * <button onClick={handleSuccess}>Set Success</button>\n * <button onClick={handleError}>Set Error</button>\n * <button onClick={setIdle}>Reset</button>\n * <p>Status: {status}</p>\n * {loading && <p>Loading...</p>}\n * {result && <p>Result: {result}</p>}\n * {error && <p>Error: {error.message}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function usePromiseState<R = unknown, E = FetcherError>(\n options?: UsePromiseStateOptions<R, E>,\n): UsePromiseStateReturn<R, E> {\n const [status, setStatus] = useState<PromiseStatus>(\n options?.initialStatus ?? PromiseStatus.IDLE,\n );\n const [result, setResult] = useState<R | undefined>(undefined);\n const [error, setErrorState] = useState<E | undefined>(undefined);\n const isMounted = useMounted();\n const latestOptions = useLatest(options);\n const setLoadingFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.LOADING);\n setErrorState(undefined);\n }\n }, [isMounted]);\n\n const setSuccessFn = useCallback(\n async (result: R) => {\n if (isMounted()) {\n setResult(result);\n setStatus(PromiseStatus.SUCCESS);\n setErrorState(undefined);\n try {\n await latestOptions.current?.onSuccess?.(result);\n } catch (callbackError) {\n // Log callback errors but don't affect state\n console.warn('PromiseState onSuccess callback error:', callbackError);\n }\n }\n },\n [isMounted, latestOptions],\n );\n\n const setErrorFn = useCallback(\n async (error: E) => {\n if (isMounted()) {\n setErrorState(error);\n setStatus(PromiseStatus.ERROR);\n setResult(undefined);\n try {\n await latestOptions.current?.onError?.(error);\n } catch (callbackError) {\n // Log callback errors but don't affect state\n console.warn('PromiseState onError callback error:', callbackError);\n }\n }\n },\n [isMounted, latestOptions],\n );\n\n const setIdleFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.IDLE);\n setErrorState(undefined);\n setResult(undefined);\n }\n }, [isMounted]);\n return useMemo(\n () => ({\n status,\n loading: status === PromiseStatus.LOADING,\n result,\n error,\n setLoading: setLoadingFn,\n setSuccess: setSuccessFn,\n setError: setErrorFn,\n setIdle: setIdleFn,\n }),\n [status, result, error, setLoadingFn, setSuccessFn, setErrorFn, setIdleFn],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef, useCallback, useMemo } from 'react';\n\n/**\n * Return type for useRequestId hook\n */\nexport interface UseRequestIdReturn {\n /** Generate a new request ID and get the current one */\n generate: () => number;\n /** Get the current request ID without generating a new one */\n current: () => number;\n /** Check if a given request ID is the latest */\n isLatest: (requestId: number) => boolean;\n /** Invalidate current request ID (mark as stale) */\n invalidate: () => void;\n /** Reset request ID counter */\n reset: () => void;\n}\n\n/**\n * A React hook for managing request IDs and race condition protection\n *\n * @example\n * ```typescript\n * // Basic usage\n * const requestId = useRequestId();\n *\n * const execute = async () => {\n * const id = requestId.generate();\n *\n * try {\n * const result = await someAsyncOperation();\n *\n * // Check if this is still the latest request\n * if (requestId.isLatest(id)) {\n * setState(result);\n * }\n * } catch (error) {\n * if (requestId.isLatest(id)) {\n * setError(error);\n * }\n * }\n * };\n *\n * // Manual cancellation\n * const handleCancel = () => {\n * requestId.invalidate(); // All ongoing requests will be ignored\n * };\n * ```\n *\n * @example\n * ```typescript\n * // With async operation wrapper\n * const { execute, cancel } = useAsyncOperation(async (data) => {\n * return await apiCall(data);\n * }, [requestId]);\n * ```\n */\nexport function useRequestId(): UseRequestIdReturn {\n const requestIdRef = useRef<number>(0);\n\n const generate = useCallback((): number => {\n return ++requestIdRef.current;\n }, []);\n\n const current = useCallback((): number => {\n return requestIdRef.current;\n }, []);\n\n const isLatest = useCallback((requestId: number): boolean => {\n return requestId === requestIdRef.current;\n }, []);\n\n const invalidate = useCallback((): void => {\n requestIdRef.current++;\n }, []);\n\n const reset = useCallback((): void => {\n requestIdRef.current = 0;\n }, []);\n return useMemo(() => {\n return {\n generate,\n current,\n isLatest,\n invalidate,\n reset,\n };\n }, [generate, current, isLatest, invalidate, reset]);\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { useMounted } from './useMounted';\nimport {\n usePromiseState,\n PromiseState,\n UsePromiseStateOptions,\n} from './usePromiseState';\nimport { useRequestId } from './useRequestId';\nimport { FetcherError } from '@ahoo-wang/fetcher';\n\nexport interface UseExecutePromiseOptions<R, E = unknown>\n extends UsePromiseStateOptions<R, E> {\n /**\n * Whether to propagate errors thrown by the promise.\n * If true, the execute function will throw errors.\n * If false (default), the execute function will return the error as the result instead of throwing.\n */\n propagateError?: boolean;\n}\n\n/**\n * Type definition for a function that returns a Promise\n * @template R - The type of value the promise will resolve to\n */\nexport type PromiseSupplier<R> = () => Promise<R>;\n\n/**\n * Interface defining the return type of useExecutePromise hook\n * @template R - The type of the result value\n */\nexport interface UseExecutePromiseReturn<R, E = FetcherError>\n extends PromiseState<R, E> {\n /**\n * Function to execute a promise supplier or promise.\n * Returns a promise that resolves to the result on success, or the error if propagateError is false.\n */\n execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R | E>;\n /** Function to reset the state to initial values */\n reset: () => void;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @template R - The type of the result value\n * @template E - The type of the error value\n * @param options - Configuration options for the hook\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useExecutePromise } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n *\n * const fetchData = async () => {\n * const response = await fetch('/api/data');\n * return response.text();\n * };\n *\n * const handleFetch = () => {\n * execute(fetchData);\n * };\n *\n * const handleReset = () => {\n * reset();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * <button onClick={handleReset}>Reset</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n *\n * // Example with propagateError set to true\n * const { execute } = useExecutePromise<string>({ propagateError: true });\n * try {\n * await execute(fetchData);\n * } catch (err) {\n * console.error('Error occurred:', err);\n * }\n * ```\n */\nexport function useExecutePromise<R = unknown, E = FetcherError>(\n options?: UseExecutePromiseOptions<R, E>,\n): UseExecutePromiseReturn<R, E> {\n const { loading, result, error, status, setLoading, setSuccess, setError, setIdle } = usePromiseState<R, E>(options);\n const isMounted = useMounted();\n const requestId = useRequestId();\n const propagateError = options?.propagateError;\n /**\n * Execute a promise supplier or promise and manage its state\n * @param input - A function that returns a Promise or a Promise to be executed\n * @returns A Promise that resolves with the result on success, or the error if propagateError is false\n */\n const execute = useCallback(\n async (input: PromiseSupplier<R> | Promise<R>): Promise<R | E> => {\n if (!isMounted()) {\n throw new Error('Component is unmounted');\n }\n const currentRequestId = requestId.generate();\n setLoading();\n try {\n const promise = typeof input === 'function' ? input() : input;\n const data = await promise;\n\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await setSuccess(data);\n }\n return data;\n } catch (err) {\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await setError(err as E);\n }\n if (propagateError) {\n throw err;\n }\n return err as E;\n }\n },\n [setLoading, setSuccess, setError, isMounted, requestId, propagateError],\n );\n\n /**\n * Reset the state to initial values\n */\n const reset = useCallback(() => {\n if (isMounted()) {\n setIdle();\n }\n }, [setIdle, isMounted]);\n\n return useMemo(\n () => ({\n loading: loading,\n result: result,\n error: error,\n execute,\n reset,\n status: status,\n }),\n [loading, result, error, execute, reset, status],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { KeyStorage } from '@ahoo-wang/fetcher-storage';\n\n/**\n * A React hook that provides state management for a KeyStorage instance.\n * Subscribes to storage changes and returns the current value along with a setter function.\n *\n * @template T - The type of value stored in the key storage\n * @param keyStorage - The KeyStorage instance to subscribe to and manage\n * @returns A tuple containing the current stored value and a function to update it\n */\nexport function useKeyStorage<T>(\n keyStorage: KeyStorage<T>,\n): [T | null, (value: T) => void] {\n const subscribe = useCallback(\n (callback: () => void) => keyStorage.addListener(callback),\n [keyStorage],\n );\n const getSnapshot = useCallback(() => keyStorage.get(), [keyStorage]);\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setValue = useCallback(\n (value: T) => keyStorage.set(value),\n [keyStorage],\n );\n return [value, setValue];\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n fetcherRegistrar,\n FetcherCapable,\n FetchExchange,\n FetchRequest,\n getFetcher,\n RequestOptions, FetcherError,\n} from '@ahoo-wang/fetcher';\nimport { useMounted } from '../core';\nimport { useRef, useCallback, useEffect, useState, useMemo } from 'react';\nimport {\n PromiseState,\n useLatest,\n usePromiseState,\n UsePromiseStateOptions,\n useRequestId,\n} from '../core';\n\n/**\n * Configuration options for the useFetcher hook.\n * Extends RequestOptions and FetcherCapable interfaces.\n */\nexport interface UseFetcherOptions<R, E = FetcherError>\n extends RequestOptions,\n FetcherCapable,\n UsePromiseStateOptions<R, E> {\n}\n\nexport interface UseFetcherReturn<R, E = FetcherError> extends PromiseState<R, E> {\n /** The FetchExchange object representing the ongoing fetch operation */\n exchange?: FetchExchange;\n execute: (request: FetchRequest) => Promise<void>;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @param options - Configuration options for the fetcher\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useFetcher } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute } = useFetcher<string>();\n *\n * const handleFetch = () => {\n * execute({ url: '/api/data', method: 'GET' });\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useFetcher<R, E = FetcherError>(\n options?: UseFetcherOptions<R, E>,\n): UseFetcherReturn<R, E> {\n const { fetcher = fetcherRegistrar.default } = options || {};\n const state = usePromiseState<R, E>(options);\n const [exchange, setExchange] = useState<FetchExchange | undefined>(\n undefined,\n );\n const isMounted = useMounted();\n const abortControllerRef = useRef<AbortController | undefined>();\n const requestId = useRequestId();\n const latestOptions = useLatest(options);\n const currentFetcher = getFetcher(fetcher);\n /**\n * Execute the fetch operation.\n * Cancels any ongoing fetch before starting a new one.\n */\n const execute = useCallback(\n async (request: FetchRequest) => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n abortControllerRef.current =\n request.abortController ?? new AbortController();\n request.abortController = abortControllerRef.current;\n const currentRequestId = requestId.generate();\n state.setLoading();\n try {\n const exchange = await currentFetcher.exchange(\n request,\n latestOptions.current,\n );\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n setExchange(exchange);\n }\n const result = await exchange.extractResult<R>();\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await state.setSuccess(result);\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n if (isMounted()) {\n state.setIdle();\n }\n return;\n }\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await state.setError(error as E);\n }\n } finally {\n if (abortControllerRef.current === request.abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [currentFetcher, isMounted, latestOptions, state, requestId],\n );\n\n useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = undefined;\n };\n }, []);\n return useMemo(\n () => ({\n ...state,\n exchange,\n execute,\n }),\n [state, exchange, execute],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n useExecutePromise,\n useLatest,\n UseExecutePromiseReturn,\n UseExecutePromiseOptions,\n} from '../core';\nimport { useCallback, useMemo, useEffect } from 'react';\nimport { AttributesCapable, FetcherError } from '@ahoo-wang/fetcher';\nimport { AutoExecuteCapable } from './types';\n\n/**\n * Configuration options for the useQuery hook\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n */\nexport interface UseQueryOptions<Q, R, E = FetcherError>\n extends UseExecutePromiseOptions<R, E>,\n AttributesCapable,\n AutoExecuteCapable {\n /** The initial query parameters */\n initialQuery: Q;\n\n /** Function to execute the query with given parameters and optional attributes */\n execute: (query: Q, attributes?: Record<string, any>) => Promise<R>;\n}\n\n/**\n * Return type of the useQuery hook\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n */\nexport interface UseQueryReturn<Q, R, E = FetcherError>\n extends UseExecutePromiseReturn<R, E> {\n /**\n * Get the current query parameters\n */\n getQuery: () => Q;\n /** Function to update the query parameters */\n setQuery: (query: Q) => void;\n /** Function to execute the query with current parameters */\n execute: () => Promise<R | E>;\n}\n\n/**\n * A React hook for managing query-based asynchronous operations\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n * @param options - Configuration options for the query\n * @returns An object containing the query state and control functions\n *\n * @example\n * ```typescript\n * import { useQuery } from '@ahoo-wang/fetcher-react';\n *\n * interface UserQuery {\n * id: string;\n * }\n *\n * interface User {\n * id: string;\n * name: string;\n * }\n *\n * function UserComponent() {\n * const { loading, result, error, execute, setQuery } = useQuery<UserQuery, User>({\n * initialQuery: { id: '1' },\n * execute: async (query) => {\n * const response = await fetch(`/api/users/${query.id}`);\n * return response.json();\n * },\n * autoExecute: true,\n * });\n *\n * const handleUserChange = (userId: string) => {\n * setQuery({ id: userId });\n * execute();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={() => handleUserChange('2')}>Load User 2</button>\n * {result && <p>User: {result.name}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useQuery<Q, R, E = FetcherError>(\n options: UseQueryOptions<Q, R, E>,\n): UseQueryReturn<Q, R, E> {\n const { initialQuery } = options;\n const promiseState = useExecutePromise<R, E>(options);\n const latestQuery = useLatest(initialQuery);\n const latestOptions = useLatest(options);\n const queryExecutor = useCallback(async (): Promise<R> => {\n return latestOptions.current.execute(\n latestQuery.current,\n latestOptions.current.attributes,\n );\n }, [latestQuery, latestOptions]);\n const getQuery = useCallback(() => {\n return latestQuery.current;\n }, [latestQuery]);\n const setQuery = useCallback(\n (query: Q) => {\n latestQuery.current = query;\n },\n [latestQuery],\n );\n const { execute: promiseExecutor } = promiseState;\n const execute = useCallback(() => {\n return promiseExecutor(queryExecutor);\n }, [promiseExecutor, queryExecutor]);\n\n const { autoExecute } = options;\n\n useEffect(() => {\n if (autoExecute) {\n execute();\n }\n }, [autoExecute, execute]);\n\n return useMemo(\n () => ({\n ...promiseState,\n execute,\n getQuery,\n setQuery,\n }),\n [promiseState, execute, getQuery, setQuery],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PagedList, PagedQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the usePagedQuery hook.\n * Extends UseQueryOptions with PagedQuery as query key and PagedList as data type.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UsePagedQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<PagedQuery<FIELDS>, PagedList<R>, E> {\n}\n\n/**\n * Return type for the usePagedQuery hook.\n * Extends UseQueryReturn with PagedQuery as query key and PagedList as data type.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UsePagedQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<PagedQuery<FIELDS>, PagedList<R>, E> {\n}\n\n/**\n * Hook for querying paged data with conditions, projection, pagination, and sorting.\n * Wraps useQuery to provide type-safe paged queries.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including paged query configuration\n * @returns The query result with paged list data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = usePagedQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * pagination: { index: 1, size: 10 },\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchPagedData(query),\n * });\n * ```\n */\nexport function usePagedQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UsePagedQueryOptions<R, FIELDS, E>,\n): UsePagedQueryReturn<R, FIELDS, E> {\n return useQuery<PagedQuery<FIELDS>, PagedList<R>, E>(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SingleQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useSingleQuery hook.\n * Extends UseQueryOptions with SingleQuery as query key and custom result type.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseSingleQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<SingleQuery<FIELDS>, R, E> {\n}\n\n/**\n * Return type for the useSingleQuery hook.\n * Extends UseQueryReturn with SingleQuery as query key and custom result type.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseSingleQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<SingleQuery<FIELDS>, R, E> {\n}\n\n/**\n * Hook for querying a single item with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe single item queries.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including single query configuration\n * @returns The query result with single item data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useSingleQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchSingleItem(query),\n * });\n * ```\n */\nexport function useSingleQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseSingleQueryOptions<R, FIELDS, E>,\n): UseSingleQueryReturn<R, FIELDS, E> {\n return useQuery<SingleQuery<FIELDS>, R, E>(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Condition } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useCountQuery hook.\n * Extends UseQueryOptions with Condition as query key and number as data type.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseCountQueryOptions<\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<Condition<FIELDS>, number, E> {\n}\n\n/**\n * Return type for the useCountQuery hook.\n * Extends UseQueryReturn with Condition as query key and number as data type.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseCountQueryReturn<\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<Condition<FIELDS>, number, E> {\n}\n\n/**\n * Hook for querying count data with conditions.\n * Wraps useQuery to provide type-safe count queries.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including condition and other settings\n * @returns The query result with count data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useCountQuery({\n * queryKey: [{ field: 'status', operator: 'eq', value: 'active' }],\n * queryFn: async (condition) => fetchCount(condition),\n * });\n * ```\n */\nexport function useCountQuery<FIELDS extends string = string, E = FetcherError>(\n options: UseCountQueryOptions<FIELDS, E>,\n): UseCountQueryReturn<FIELDS, E> {\n return useQuery(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ListQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useListQuery hook.\n * Extends UseQueryOptions with ListQuery as query key and array of results as data type.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<ListQuery<FIELDS>, R[], E> {\n}\n\n/**\n * Return type for the useListQuery hook.\n * Extends UseQueryReturn with ListQuery as query key and array of results as data type.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<ListQuery<FIELDS>, R[], E> {\n}\n\n/**\n * Hook for querying list data with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe list queries.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including list query configuration\n * @returns The query result with list data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useListQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchListData(query),\n * });\n * ```\n */\nexport function useListQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseListQueryOptions<R, FIELDS, E>,\n): UseListQueryReturn<R, FIELDS, E> {\n return useQuery<ListQuery<FIELDS>, R[], E>(options);\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ListQuery } from '@ahoo-wang/fetcher-wow';\nimport type { JsonServerSentEvent } from '@ahoo-wang/fetcher-eventstream';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useListStreamQuery hook.\n * Extends UseQueryOptions with ListQuery as query key and stream of events as data type.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListStreamQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<\n ListQuery<FIELDS>,\n ReadableStream<JsonServerSentEvent<R>>,\n E\n> {\n}\n\n/**\n * Return type for the useListStreamQuery hook.\n * Extends UseQueryReturn with ListQuery as query key and stream of events as data type.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListStreamQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<\n ListQuery<FIELDS>,\n ReadableStream<JsonServerSentEvent<R>>,\n E\n> {\n}\n\n/**\n * Hook for querying streaming list data with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe streaming list queries.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including list stream query configuration\n * @returns The query result with streaming data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useListStreamQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchStreamData(query),\n * });\n * ```\n */\nexport function useListStreamQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseListStreamQueryOptions<R, FIELDS, E>,\n): UseListStreamQueryReturn<R, FIELDS, E> {\n return useQuery<ListQuery<FIELDS>, ReadableStream<JsonServerSentEvent<R>>, E>(\n options,\n );\n}\n"],"names":["useMounted","isMountedRef","useRef","isMountedFn","useCallback","useEffect","useLatest","value","ref","PromiseStatus","usePromiseState","options","status","setStatus","useState","result","setResult","error","setErrorState","isMounted","latestOptions","setLoadingFn","setSuccessFn","callbackError","setErrorFn","setIdleFn","useMemo","useRequestId","requestIdRef","generate","current","isLatest","requestId","invalidate","reset","useExecutePromise","loading","setLoading","setSuccess","setError","setIdle","propagateError","execute","input","currentRequestId","data","err","useKeyStorage","keyStorage","subscribe","callback","getSnapshot","useSyncExternalStore","setValue","useFetcher","fetcher","fetcherRegistrar","state","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request","useQuery","initialQuery","promiseState","latestQuery","queryExecutor","getQuery","setQuery","query","promiseExecutor","autoExecute","usePagedQuery","useSingleQuery","useCountQuery","useListQuery","useListStreamQuery"],"mappings":";;AAuCO,SAASA,IAAa;AAC3B,QAAMC,IAAeC,EAAO,EAAK,GAC3BC,IAAcC,EAAY,MAAMH,EAAa,SAAS,CAAA,CAAE;AAC9D,SAAAI,EAAU,OACRJ,EAAa,UAAU,IAChB,MAAM;AACX,IAAAA,EAAa,UAAU;AAAA,EACzB,IACC,CAAA,CAAE,GAEEE;AACT;ACLO,SAASG,EAAaC,GAA+B;AAC1D,QAAMC,IAAMN,EAAOK,CAAK;AACxB,SAAAC,EAAI,UAAUD,GACPC;AACT;AC5BO,IAAKC,sBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,UAAU,WACVA,EAAA,UAAU,WACVA,EAAA,QAAQ,SAJEA,IAAAA,KAAA,CAAA,CAAA;AA6FL,SAASC,EACdC,GAC6B;AAC7B,QAAM,CAACC,GAAQC,CAAS,IAAIC;AAAA,IAC1BH,GAAS,iBAAiB;AAAA;AAAA,EAAA,GAEtB,CAACI,GAAQC,CAAS,IAAIF,EAAwB,MAAS,GACvD,CAACG,GAAOC,CAAa,IAAIJ,EAAwB,MAAS,GAC1DK,IAAYnB,EAAA,GACZoB,IAAgBd,EAAUK,CAAO,GACjCU,IAAejB,EAAY,MAAM;AACrC,IAAIe,QACFN;AAAA,MAAU;AAAA;AAAA,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AA,GAEvB,CAAC+C,GAAa/C,CAAa,CAAC,GACzBiD,IAAWjE,EAAY,MACpB+D,EAAY,SAClB,CAACA,CAAW,CAAC,GACVG,IAAWlE;AAAA,IACf,CAACmE,MAAa;AACZ,MAAAJ,EAAY,UAAUI;AAAA,IACxB;AAAA,IACA,CAACJ,CAAW;AAAA,EAAA,GAER,EAAE,SAASK,EAAA,IAAoBN,GAC/BxB,IAAUtC,EAAY,MACnBoE,EAAgBJ,CAAa,GACnC,CAACI,GAAiBJ,CAAa,CAAC,GAE7B,EAAE,aAAAK,MAAgB9D;AAExB,SAAAN,EAAU,MAAM;AACd,IAAIoE,KACF/B,EAAA;AAAA,EAEJ,GAAG,CAAC+B,GAAa/B,CAAO,CAAC,GAElBhB;AAAA,IACL,OAAO;AAAA,MACL,GAAGwC;AAAA,MACH,SAAAxB;AAAA,MACA,UAAA2B;AAAA,MACA,UAAAC;AAAA,IAAA;AAAA,IAEF,CAACJ,GAAcxB,GAAS2B,GAAUC,CAAQ;AAAA,EAAA;AAE9C;AC/EO,SAASI,EAKd/D,GACmC;AACnC,SAAOqD,EAA8CrD,CAAO;AAC9D;ACTO,SAASgE,EAKdhE,GACoC;AACpC,SAAOqD,EAAoCrD,CAAO;AACpD;ACjBO,SAASiE,EACdjE,GACgC;AAChC,SAAOqD,EAASrD,CAAO;AACzB;ACKO,SAASkE,EAKdlE,GACkC;AAClC,SAAOqD,EAAoCrD,CAAO;AACpD;ACCO,SAASmE,EAKdnE,GACwC;AACxC,SAAOqD;AAAA,IACLrD;AAAA,EAAA;AAEJ;"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(n,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react"),require("@ahoo-wang/fetcher")):typeof define=="function"&&define.amd?define(["exports","react","@ahoo-wang/fetcher"],t):(n=typeof globalThis<"u"?globalThis:n||self,t(n.FetcherReact={},n.React,n.Fetcher))})(this,(function(n,t,k){"use strict";function S(){const e=t.useRef(!1),c=t.useCallback(()=>e.current,[]);return t.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),c}function g(e){const c=t.useRef(e);return c.current=e,c}var w=(e=>(e.IDLE="idle",e.LOADING="loading",e.SUCCESS="success",e.ERROR="error",e))(w||{});function L(e){const[c,s]=t.useState(e?.initialStatus??"idle"),[a,i]=t.useState(void 0),[r,u]=t.useState(void 0),o=S(),l=g(e),f=t.useCallback(()=>{o()&&(s("loading"),u(void 0))},[o]),b=t.useCallback(async d=>{if(o()){i(d),s("success"),u(void 0);try{await l.current?.onSuccess?.(d)}catch(E){console.warn("PromiseState onSuccess callback error:",E)}}},[o,l]),y=t.useCallback(async d=>{if(o()){u(d),s("error"),i(void 0);try{await l.current?.onError?.(d)}catch(E){console.warn("PromiseState onError callback error:",E)}}},[o,l]),C=t.useCallback(()=>{o()&&(s("idle"),u(void 0),i(void 0))},[o]);return t.useMemo(()=>({status:c,loading:c==="loading",result:a,error:r,setLoading:f,setSuccess:b,setError:y,setIdle:C}),[c,a,r,f,b,y,C])}function R(){const e=t.useRef(0),c=t.useCallback(()=>++e.current,[]),s=t.useCallback(()=>e.current,[]),a=t.useCallback(u=>u===e.current,[]),i=t.useCallback(()=>{e.current++},[]),r=t.useCallback(()=>{e.current=0},[]);return t.useMemo(()=>({generate:c,current:s,isLatest:a,invalidate:i,reset:r}),[c,s,a,i,r])}function Q(e){const{loading:c,result:s,error:a,status:i,setLoading:r,setSuccess:u,setError:o,setIdle:l}=L(e),f=S(),b=R(),y=e?.propagateError,C=t.useCallback(async E=>{if(!f())throw new Error("Component is unmounted");const v=b.generate();r();try{const I=await(typeof E=="function"?E():E);return f()&&b.isLatest(v)&&await u(I),I}catch(m){if(f()&&b.isLatest(v)&&await o(m),y)throw m;return m}},[r,u,o,f,b,y]),d=t.useCallback(()=>{f()&&l()},[l,f]);return t.useMemo(()=>({loading:c,result:s,error:a,execute:C,reset:d,status:i}),[c,s,a,C,d,i])}function M(e){const c=t.useCallback(r=>e.addListener(r),[e]),s=t.useCallback(()=>e.get(),[e]),a=t.useSyncExternalStore(c,s,s),i=t.useCallback(r=>e.set(r),[e]);return[a,i]}function F(e){const{fetcher:c=k.fetcherRegistrar.default}=e||{},s=L(e),[a,i]=t.useState(void 0),r=S(),u=t.useRef(),o=R(),l=g(e),f=k.getFetcher(c),b=t.useCallback(async y=>{u.current&&u.current.abort(),u.current=y.abortController??new AbortController,y.abortController=u.current;const C=o.generate();s.setLoading();try{const d=await f.exchange(y,l.current);r()&&o.isLatest(C)&&i(d);const E=await d.extractResult();r()&&o.isLatest(C)&&await s.setSuccess(E)}catch(d){if(d instanceof Error&&d.name==="AbortError"){r()&&s.setIdle();return}r()&&o.isLatest(C)&&await s.setError(d)}finally{u.current===y.abortController&&(u.current=void 0)}},[f,r,l,s,o]);return t.useEffect(()=>()=>{u.current?.abort(),u.current=void 0},[]),t.useMemo(()=>({...s,exchange:a,execute:b}),[s,a,b])}function h(e){const{initialQuery:c}=e,s=Q(e),a=g(c),i=g(e),r=t.useCallback(async()=>i.current.execute(a.current,i.current.attributes),[a,i]),u=t.useCallback(b=>{a.current=b},[a]),{execute:o}=s,l=t.useCallback(()=>o(r),[o,r]),{autoExecute:f}=e;return t.useEffect(()=>{f&&l()},[f,l]),t.useMemo(()=>({...s,execute:l,setQuery:u}),[s,l,u])}function q(e){return h(e)}function P(e){return h(e)}function O(e){return h(e)}function x(e){return h(e)}function A(e){return h(e)}n.PromiseStatus=w,n.useCountQuery=O,n.useExecutePromise=Q,n.useFetcher=F,n.useKeyStorage=M,n.useLatest=g,n.useListQuery=x,n.useListStreamQuery=A,n.useMounted=S,n.usePagedQuery=q,n.usePromiseState=L,n.useQuery=h,n.useRequestId=R,n.useSingleQuery=P,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(s,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react"),require("@ahoo-wang/fetcher")):typeof define=="function"&&define.amd?define(["exports","react","@ahoo-wang/fetcher"],t):(s=typeof globalThis<"u"?globalThis:s||self,t(s.FetcherReact={},s.React,s.Fetcher))})(this,(function(s,t,R){"use strict";function S(){const e=t.useRef(!1),c=t.useCallback(()=>e.current,[]);return t.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),c}function h(e){const c=t.useRef(e);return c.current=e,c}var w=(e=>(e.IDLE="idle",e.LOADING="loading",e.SUCCESS="success",e.ERROR="error",e))(w||{});function k(e){const[c,r]=t.useState(e?.initialStatus??"idle"),[o,i]=t.useState(void 0),[n,u]=t.useState(void 0),a=S(),d=h(e),l=t.useCallback(()=>{a()&&(r("loading"),u(void 0))},[a]),b=t.useCallback(async f=>{if(a()){i(f),r("success"),u(void 0);try{await d.current?.onSuccess?.(f)}catch(E){console.warn("PromiseState onSuccess callback error:",E)}}},[a,d]),y=t.useCallback(async f=>{if(a()){u(f),r("error"),i(void 0);try{await d.current?.onError?.(f)}catch(E){console.warn("PromiseState onError callback error:",E)}}},[a,d]),C=t.useCallback(()=>{a()&&(r("idle"),u(void 0),i(void 0))},[a]);return t.useMemo(()=>({status:c,loading:c==="loading",result:o,error:n,setLoading:l,setSuccess:b,setError:y,setIdle:C}),[c,o,n,l,b,y,C])}function L(){const e=t.useRef(0),c=t.useCallback(()=>++e.current,[]),r=t.useCallback(()=>e.current,[]),o=t.useCallback(u=>u===e.current,[]),i=t.useCallback(()=>{e.current++},[]),n=t.useCallback(()=>{e.current=0},[]);return t.useMemo(()=>({generate:c,current:r,isLatest:o,invalidate:i,reset:n}),[c,r,o,i,n])}function Q(e){const{loading:c,result:r,error:o,status:i,setLoading:n,setSuccess:u,setError:a,setIdle:d}=k(e),l=S(),b=L(),y=e?.propagateError,C=t.useCallback(async E=>{if(!l())throw new Error("Component is unmounted");const v=b.generate();n();try{const I=await(typeof E=="function"?E():E);return l()&&b.isLatest(v)&&await u(I),I}catch(m){if(l()&&b.isLatest(v)&&await a(m),y)throw m;return m}},[n,u,a,l,b,y]),f=t.useCallback(()=>{l()&&d()},[d,l]);return t.useMemo(()=>({loading:c,result:r,error:o,execute:C,reset:f,status:i}),[c,r,o,C,f,i])}function M(e){const c=t.useCallback(n=>e.addListener(n),[e]),r=t.useCallback(()=>e.get(),[e]),o=t.useSyncExternalStore(c,r,r),i=t.useCallback(n=>e.set(n),[e]);return[o,i]}function F(e){const{fetcher:c=R.fetcherRegistrar.default}=e||{},r=k(e),[o,i]=t.useState(void 0),n=S(),u=t.useRef(),a=L(),d=h(e),l=R.getFetcher(c),b=t.useCallback(async y=>{u.current&&u.current.abort(),u.current=y.abortController??new AbortController,y.abortController=u.current;const C=a.generate();r.setLoading();try{const f=await l.exchange(y,d.current);n()&&a.isLatest(C)&&i(f);const E=await f.extractResult();n()&&a.isLatest(C)&&await r.setSuccess(E)}catch(f){if(f instanceof Error&&f.name==="AbortError"){n()&&r.setIdle();return}n()&&a.isLatest(C)&&await r.setError(f)}finally{u.current===y.abortController&&(u.current=void 0)}},[l,n,d,r,a]);return t.useEffect(()=>()=>{u.current?.abort(),u.current=void 0},[]),t.useMemo(()=>({...r,exchange:o,execute:b}),[r,o,b])}function g(e){const{initialQuery:c}=e,r=Q(e),o=h(c),i=h(e),n=t.useCallback(async()=>i.current.execute(o.current,i.current.attributes),[o,i]),u=t.useCallback(()=>o.current,[o]),a=t.useCallback(y=>{o.current=y},[o]),{execute:d}=r,l=t.useCallback(()=>d(n),[d,n]),{autoExecute:b}=e;return t.useEffect(()=>{b&&l()},[b,l]),t.useMemo(()=>({...r,execute:l,getQuery:u,setQuery:a}),[r,l,u,a])}function q(e){return g(e)}function P(e){return g(e)}function O(e){return g(e)}function x(e){return g(e)}function A(e){return g(e)}s.PromiseStatus=w,s.useCountQuery=O,s.useExecutePromise=Q,s.useFetcher=F,s.useKeyStorage=M,s.useLatest=h,s.useListQuery=x,s.useListStreamQuery=A,s.useMounted=S,s.usePagedQuery=q,s.usePromiseState=k,s.useQuery=g,s.useRequestId=L,s.useSingleQuery=P,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/core/useMounted.ts","../src/core/useLatest.ts","../src/core/usePromiseState.ts","../src/core/useRequestId.ts","../src/core/useExecutePromise.ts","../src/storage/useKeyStorage.ts","../src/fetcher/useFetcher.ts","../src/wow/useQuery.ts","../src/wow/usePagedQuery.ts","../src/wow/useSingleQuery.ts","../src/wow/useCountQuery.ts","../src/wow/useListQuery.ts","../src/wow/useListStreamQuery.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef, useEffect, useCallback } from 'react';\n\n/**\n * A React hook that returns a function to check if the component is mounted.\n *\n * @returns A function that returns true if the component is mounted, false otherwise\n *\n * @example\n * ```typescript\n * import { useMounted } from '@ahoo-wang/fetcher-react';\n *\n * const MyComponent = () => {\n * const isMounted = useMounted();\n *\n * useEffect(() => {\n * someAsyncOperation().then(() => {\n * if (isMounted()) {\n * setState(result);\n * }\n * });\n * }, []);\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport function useMounted() {\n const isMountedRef = useRef(false);\n const isMountedFn = useCallback(() => isMountedRef.current, []);\n useEffect(() => {\n isMountedRef.current = true;\n return () => {\n isMountedRef.current = false;\n };\n }, []);\n\n return isMountedFn;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef } from 'react';\n\n/**\n * A React hook that returns a ref containing the latest value, useful for accessing the current value in async callbacks.\n *\n * @template T - The type of the value\n * @param value - The value to track\n * @returns A ref object containing the latest value\n *\n * @example\n * ```typescript\n * import { useLatest } from '@ahoo-wang/fetcher-react';\n *\n * const MyComponent = () => {\n * const [count, setCount] = useState(0);\n * const latestCount = useLatest(count);\n *\n * const handleAsync = async () => {\n * await someAsyncOperation();\n * console.log('Latest count:', latestCount.current); // Always the latest\n * };\n *\n * return (\n * <div>\n * <p>Count: {count}</p>\n * <button onClick={() => setCount(c => c + 1)}>Increment</button>\n * <button onClick={handleAsync}>Async Log</button>\n * </div>\n * );\n * };\n * ```\n */\nexport function useLatest<T>(value: T) {\n const ref = useRef(value);\n ref.current = value;\n return ref;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useMemo, useState } from 'react';\nimport { useMounted } from './useMounted';\nimport { useLatest } from './useLatest';\nimport { FetcherError } from '@ahoo-wang/fetcher';\n\n/**\n * Enumeration of possible promise execution states\n */\nexport enum PromiseStatus {\n IDLE = 'idle',\n LOADING = 'loading',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nexport interface PromiseState<R, E = unknown> {\n /** Current status of the promise */\n status: PromiseStatus;\n /** Indicates if currently loading */\n loading: boolean;\n /** The result value */\n result: R | undefined;\n /** The error value */\n error: E | undefined;\n}\n\nexport interface PromiseStateCallbacks<R, E = unknown> {\n /** Callback invoked on success (can be async) */\n onSuccess?: (result: R) => void | Promise<void>;\n /** Callback invoked on error (can be async) */\n onError?: (error: E) => void | Promise<void>;\n}\n\n/**\n * Options for configuring usePromiseState behavior\n * @template R - The type of result\n *\n * @example\n * ```typescript\n * const options: UsePromiseStateOptions<string> = {\n * initialStatus: PromiseStatus.IDLE,\n * onSuccess: (result) => console.log('Success:', result),\n * onError: async (error) => {\n * await logErrorToServer(error);\n * console.error('Error:', error);\n * },\n * };\n * ```\n */\nexport interface UsePromiseStateOptions<R, E = FetcherError>\n extends PromiseStateCallbacks<R, E> {\n /** Initial status, defaults to IDLE */\n initialStatus?: PromiseStatus;\n}\n\n/**\n * Return type for usePromiseState hook\n * @template R - The type of result\n */\nexport interface UsePromiseStateReturn<R, E = FetcherError>\n extends PromiseState<R, E> {\n /** Set status to LOADING */\n setLoading: () => void;\n /** Set status to SUCCESS with result */\n setSuccess: (result: R) => Promise<void>;\n /** Set status to ERROR with error */\n setError: (error: E) => Promise<void>;\n /** Set status to IDLE */\n setIdle: () => void;\n}\n\n/**\n * A React hook for managing promise state without execution logic\n * @template R - The type of result\n * @param options - Configuration options\n * @returns State management object\n *\n * @example\n * ```typescript\n * import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();\n *\n * const handleSuccess = () => setSuccess('Data loaded');\n * const handleError = () => setError(new Error('Failed to load'));\n *\n * return (\n * <div>\n * <button onClick={handleSuccess}>Set Success</button>\n * <button onClick={handleError}>Set Error</button>\n * <button onClick={setIdle}>Reset</button>\n * <p>Status: {status}</p>\n * {loading && <p>Loading...</p>}\n * {result && <p>Result: {result}</p>}\n * {error && <p>Error: {error.message}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function usePromiseState<R = unknown, E = FetcherError>(\n options?: UsePromiseStateOptions<R, E>,\n): UsePromiseStateReturn<R, E> {\n const [status, setStatus] = useState<PromiseStatus>(\n options?.initialStatus ?? PromiseStatus.IDLE,\n );\n const [result, setResult] = useState<R | undefined>(undefined);\n const [error, setErrorState] = useState<E | undefined>(undefined);\n const isMounted = useMounted();\n const latestOptions = useLatest(options);\n const setLoadingFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.LOADING);\n setErrorState(undefined);\n }\n }, [isMounted]);\n\n const setSuccessFn = useCallback(\n async (result: R) => {\n if (isMounted()) {\n setResult(result);\n setStatus(PromiseStatus.SUCCESS);\n setErrorState(undefined);\n try {\n await latestOptions.current?.onSuccess?.(result);\n } catch (callbackError) {\n // Log callback errors but don't affect state\n console.warn('PromiseState onSuccess callback error:', callbackError);\n }\n }\n },\n [isMounted, latestOptions],\n );\n\n const setErrorFn = useCallback(\n async (error: E) => {\n if (isMounted()) {\n setErrorState(error);\n setStatus(PromiseStatus.ERROR);\n setResult(undefined);\n try {\n await latestOptions.current?.onError?.(error);\n } catch (callbackError) {\n // Log callback errors but don't affect state\n console.warn('PromiseState onError callback error:', callbackError);\n }\n }\n },\n [isMounted, latestOptions],\n );\n\n const setIdleFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.IDLE);\n setErrorState(undefined);\n setResult(undefined);\n }\n }, [isMounted]);\n return useMemo(\n () => ({\n status,\n loading: status === PromiseStatus.LOADING,\n result,\n error,\n setLoading: setLoadingFn,\n setSuccess: setSuccessFn,\n setError: setErrorFn,\n setIdle: setIdleFn,\n }),\n [status, result, error, setLoadingFn, setSuccessFn, setErrorFn, setIdleFn],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef, useCallback, useMemo } from 'react';\n\n/**\n * Return type for useRequestId hook\n */\nexport interface UseRequestIdReturn {\n /** Generate a new request ID and get the current one */\n generate: () => number;\n /** Get the current request ID without generating a new one */\n current: () => number;\n /** Check if a given request ID is the latest */\n isLatest: (requestId: number) => boolean;\n /** Invalidate current request ID (mark as stale) */\n invalidate: () => void;\n /** Reset request ID counter */\n reset: () => void;\n}\n\n/**\n * A React hook for managing request IDs and race condition protection\n *\n * @example\n * ```typescript\n * // Basic usage\n * const requestId = useRequestId();\n *\n * const execute = async () => {\n * const id = requestId.generate();\n *\n * try {\n * const result = await someAsyncOperation();\n *\n * // Check if this is still the latest request\n * if (requestId.isLatest(id)) {\n * setState(result);\n * }\n * } catch (error) {\n * if (requestId.isLatest(id)) {\n * setError(error);\n * }\n * }\n * };\n *\n * // Manual cancellation\n * const handleCancel = () => {\n * requestId.invalidate(); // All ongoing requests will be ignored\n * };\n * ```\n *\n * @example\n * ```typescript\n * // With async operation wrapper\n * const { execute, cancel } = useAsyncOperation(async (data) => {\n * return await apiCall(data);\n * }, [requestId]);\n * ```\n */\nexport function useRequestId(): UseRequestIdReturn {\n const requestIdRef = useRef<number>(0);\n\n const generate = useCallback((): number => {\n return ++requestIdRef.current;\n }, []);\n\n const current = useCallback((): number => {\n return requestIdRef.current;\n }, []);\n\n const isLatest = useCallback((requestId: number): boolean => {\n return requestId === requestIdRef.current;\n }, []);\n\n const invalidate = useCallback((): void => {\n requestIdRef.current++;\n }, []);\n\n const reset = useCallback((): void => {\n requestIdRef.current = 0;\n }, []);\n return useMemo(() => {\n return {\n generate,\n current,\n isLatest,\n invalidate,\n reset,\n };\n }, [generate, current, isLatest, invalidate, reset]);\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { useMounted } from './useMounted';\nimport {\n usePromiseState,\n PromiseState,\n UsePromiseStateOptions,\n} from './usePromiseState';\nimport { useRequestId } from './useRequestId';\nimport { FetcherError } from '@ahoo-wang/fetcher';\n\nexport interface UseExecutePromiseOptions<R, E = unknown>\n extends UsePromiseStateOptions<R, E> {\n /**\n * Whether to propagate errors thrown by the promise.\n * If true, the execute function will throw errors.\n * If false (default), the execute function will return the error as the result instead of throwing.\n */\n propagateError?: boolean;\n}\n\n/**\n * Type definition for a function that returns a Promise\n * @template R - The type of value the promise will resolve to\n */\nexport type PromiseSupplier<R> = () => Promise<R>;\n\n/**\n * Interface defining the return type of useExecutePromise hook\n * @template R - The type of the result value\n */\nexport interface UseExecutePromiseReturn<R, E = FetcherError>\n extends PromiseState<R, E> {\n /**\n * Function to execute a promise supplier or promise.\n * Returns a promise that resolves to the result on success, or the error if propagateError is false.\n */\n execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R | E>;\n /** Function to reset the state to initial values */\n reset: () => void;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @template R - The type of the result value\n * @template E - The type of the error value\n * @param options - Configuration options for the hook\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useExecutePromise } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n *\n * const fetchData = async () => {\n * const response = await fetch('/api/data');\n * return response.text();\n * };\n *\n * const handleFetch = () => {\n * execute(fetchData);\n * };\n *\n * const handleReset = () => {\n * reset();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * <button onClick={handleReset}>Reset</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n *\n * // Example with propagateError set to true\n * const { execute } = useExecutePromise<string>({ propagateError: true });\n * try {\n * await execute(fetchData);\n * } catch (err) {\n * console.error('Error occurred:', err);\n * }\n * ```\n */\nexport function useExecutePromise<R = unknown, E = FetcherError>(\n options?: UseExecutePromiseOptions<R, E>,\n): UseExecutePromiseReturn<R, E> {\n const { loading, result, error, status, setLoading, setSuccess, setError, setIdle } = usePromiseState<R, E>(options);\n const isMounted = useMounted();\n const requestId = useRequestId();\n const propagateError = options?.propagateError;\n /**\n * Execute a promise supplier or promise and manage its state\n * @param input - A function that returns a Promise or a Promise to be executed\n * @returns A Promise that resolves with the result on success, or the error if propagateError is false\n */\n const execute = useCallback(\n async (input: PromiseSupplier<R> | Promise<R>): Promise<R | E> => {\n if (!isMounted()) {\n throw new Error('Component is unmounted');\n }\n const currentRequestId = requestId.generate();\n setLoading();\n try {\n const promise = typeof input === 'function' ? input() : input;\n const data = await promise;\n\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await setSuccess(data);\n }\n return data;\n } catch (err) {\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await setError(err as E);\n }\n if (propagateError) {\n throw err;\n }\n return err as E;\n }\n },\n [setLoading, setSuccess, setError, isMounted, requestId, propagateError],\n );\n\n /**\n * Reset the state to initial values\n */\n const reset = useCallback(() => {\n if (isMounted()) {\n setIdle();\n }\n }, [setIdle, isMounted]);\n\n return useMemo(\n () => ({\n loading: loading,\n result: result,\n error: error,\n execute,\n reset,\n status: status,\n }),\n [loading, result, error, execute, reset, status],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { KeyStorage } from '@ahoo-wang/fetcher-storage';\n\n/**\n * A React hook that provides state management for a KeyStorage instance.\n * Subscribes to storage changes and returns the current value along with a setter function.\n *\n * @template T - The type of value stored in the key storage\n * @param keyStorage - The KeyStorage instance to subscribe to and manage\n * @returns A tuple containing the current stored value and a function to update it\n */\nexport function useKeyStorage<T>(\n keyStorage: KeyStorage<T>,\n): [T | null, (value: T) => void] {\n const subscribe = useCallback(\n (callback: () => void) => keyStorage.addListener(callback),\n [keyStorage],\n );\n const getSnapshot = useCallback(() => keyStorage.get(), [keyStorage]);\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setValue = useCallback(\n (value: T) => keyStorage.set(value),\n [keyStorage],\n );\n return [value, setValue];\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n fetcherRegistrar,\n FetcherCapable,\n FetchExchange,\n FetchRequest,\n getFetcher,\n RequestOptions, FetcherError,\n} from '@ahoo-wang/fetcher';\nimport { useMounted } from '../core';\nimport { useRef, useCallback, useEffect, useState, useMemo } from 'react';\nimport {\n PromiseState,\n useLatest,\n usePromiseState,\n UsePromiseStateOptions,\n useRequestId,\n} from '../core';\n\n/**\n * Configuration options for the useFetcher hook.\n * Extends RequestOptions and FetcherCapable interfaces.\n */\nexport interface UseFetcherOptions<R, E = FetcherError>\n extends RequestOptions,\n FetcherCapable,\n UsePromiseStateOptions<R, E> {\n}\n\nexport interface UseFetcherReturn<R, E = FetcherError> extends PromiseState<R, E> {\n /** The FetchExchange object representing the ongoing fetch operation */\n exchange?: FetchExchange;\n execute: (request: FetchRequest) => Promise<void>;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @param options - Configuration options for the fetcher\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useFetcher } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute } = useFetcher<string>();\n *\n * const handleFetch = () => {\n * execute({ url: '/api/data', method: 'GET' });\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useFetcher<R, E = FetcherError>(\n options?: UseFetcherOptions<R, E>,\n): UseFetcherReturn<R, E> {\n const { fetcher = fetcherRegistrar.default } = options || {};\n const state = usePromiseState<R, E>(options);\n const [exchange, setExchange] = useState<FetchExchange | undefined>(\n undefined,\n );\n const isMounted = useMounted();\n const abortControllerRef = useRef<AbortController | undefined>();\n const requestId = useRequestId();\n const latestOptions = useLatest(options);\n const currentFetcher = getFetcher(fetcher);\n /**\n * Execute the fetch operation.\n * Cancels any ongoing fetch before starting a new one.\n */\n const execute = useCallback(\n async (request: FetchRequest) => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n abortControllerRef.current =\n request.abortController ?? new AbortController();\n request.abortController = abortControllerRef.current;\n const currentRequestId = requestId.generate();\n state.setLoading();\n try {\n const exchange = await currentFetcher.exchange(\n request,\n latestOptions.current,\n );\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n setExchange(exchange);\n }\n const result = await exchange.extractResult<R>();\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await state.setSuccess(result);\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n if (isMounted()) {\n state.setIdle();\n }\n return;\n }\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await state.setError(error as E);\n }\n } finally {\n if (abortControllerRef.current === request.abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [currentFetcher, isMounted, latestOptions, state, requestId],\n );\n\n useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = undefined;\n };\n }, []);\n return useMemo(\n () => ({\n ...state,\n exchange,\n execute,\n }),\n [state, exchange, execute],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n useExecutePromise,\n useLatest,\n UseExecutePromiseReturn,\n UseExecutePromiseOptions,\n} from '../core';\nimport { useCallback, useMemo, useEffect } from 'react';\nimport { AttributesCapable, FetcherError } from '@ahoo-wang/fetcher';\nimport { AutoExecuteCapable } from './types';\n\n/**\n * Configuration options for the useQuery hook\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n */\nexport interface UseQueryOptions<Q, R, E = FetcherError>\n extends UseExecutePromiseOptions<R, E>,\n AttributesCapable,\n AutoExecuteCapable {\n /** The initial query parameters */\n initialQuery: Q;\n\n /** Function to execute the query with given parameters and optional attributes */\n execute: (query: Q, attributes?: Record<string, any>) => Promise<R>;\n}\n\n/**\n * Return type of the useQuery hook\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n */\nexport interface UseQueryReturn<Q, R, E = FetcherError>\n extends UseExecutePromiseReturn<R, E> {\n /** Function to execute the query with current parameters */\n execute: () => Promise<R | E>;\n /** Function to update the query parameters */\n setQuery: (query: Q) => void;\n}\n\n/**\n * A React hook for managing query-based asynchronous operations\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n * @param options - Configuration options for the query\n * @returns An object containing the query state and control functions\n *\n * @example\n * ```typescript\n * import { useQuery } from '@ahoo-wang/fetcher-react';\n *\n * interface UserQuery {\n * id: string;\n * }\n *\n * interface User {\n * id: string;\n * name: string;\n * }\n *\n * function UserComponent() {\n * const { loading, result, error, execute, setQuery } = useQuery<UserQuery, User>({\n * initialQuery: { id: '1' },\n * execute: async (query) => {\n * const response = await fetch(`/api/users/${query.id}`);\n * return response.json();\n * },\n * autoExecute: true,\n * });\n *\n * const handleUserChange = (userId: string) => {\n * setQuery({ id: userId });\n * execute();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={() => handleUserChange('2')}>Load User 2</button>\n * {result && <p>User: {result.name}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useQuery<Q, R, E = FetcherError>(\n options: UseQueryOptions<Q, R, E>,\n): UseQueryReturn<Q, R, E> {\n const { initialQuery } = options;\n const promiseState = useExecutePromise<R, E>(options);\n const latestQuery = useLatest(initialQuery);\n const latestOptions = useLatest(options);\n const queryExecutor = useCallback(async (): Promise<R> => {\n return latestOptions.current.execute(\n latestQuery.current,\n latestOptions.current.attributes,\n );\n }, [latestQuery, latestOptions]);\n const setQuery = useCallback(\n (query: Q) => {\n latestQuery.current = query;\n },\n [latestQuery],\n );\n const { execute: promiseExecutor } = promiseState;\n const execute = useCallback(() => {\n return promiseExecutor(queryExecutor);\n }, [promiseExecutor, queryExecutor]);\n\n const { autoExecute } = options;\n\n useEffect(() => {\n if (autoExecute) {\n execute();\n }\n }, [autoExecute, execute]);\n\n return useMemo(\n () => ({\n ...promiseState,\n execute,\n setQuery,\n }),\n [promiseState, execute, setQuery],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PagedList, PagedQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the usePagedQuery hook.\n * Extends UseQueryOptions with PagedQuery as query key and PagedList as data type.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UsePagedQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<PagedQuery<FIELDS>, PagedList<R>, E> {\n}\n\n/**\n * Return type for the usePagedQuery hook.\n * Extends UseQueryReturn with PagedQuery as query key and PagedList as data type.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UsePagedQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<PagedQuery<FIELDS>, PagedList<R>, E> {\n}\n\n/**\n * Hook for querying paged data with conditions, projection, pagination, and sorting.\n * Wraps useQuery to provide type-safe paged queries.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including paged query configuration\n * @returns The query result with paged list data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = usePagedQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * pagination: { index: 1, size: 10 },\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchPagedData(query),\n * });\n * ```\n */\nexport function usePagedQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UsePagedQueryOptions<R, FIELDS, E>,\n): UsePagedQueryReturn<R, FIELDS, E> {\n return useQuery<PagedQuery<FIELDS>, PagedList<R>, E>(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SingleQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useSingleQuery hook.\n * Extends UseQueryOptions with SingleQuery as query key and custom result type.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseSingleQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<SingleQuery<FIELDS>, R, E> {\n}\n\n/**\n * Return type for the useSingleQuery hook.\n * Extends UseQueryReturn with SingleQuery as query key and custom result type.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseSingleQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<SingleQuery<FIELDS>, R, E> {\n}\n\n/**\n * Hook for querying a single item with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe single item queries.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including single query configuration\n * @returns The query result with single item data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useSingleQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchSingleItem(query),\n * });\n * ```\n */\nexport function useSingleQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseSingleQueryOptions<R, FIELDS, E>,\n): UseSingleQueryReturn<R, FIELDS, E> {\n return useQuery<SingleQuery<FIELDS>, R, E>(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Condition } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useCountQuery hook.\n * Extends UseQueryOptions with Condition as query key and number as data type.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseCountQueryOptions<\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<Condition<FIELDS>, number, E> {\n}\n\n/**\n * Return type for the useCountQuery hook.\n * Extends UseQueryReturn with Condition as query key and number as data type.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseCountQueryReturn<\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<Condition<FIELDS>, number, E> {\n}\n\n/**\n * Hook for querying count data with conditions.\n * Wraps useQuery to provide type-safe count queries.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including condition and other settings\n * @returns The query result with count data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useCountQuery({\n * queryKey: [{ field: 'status', operator: 'eq', value: 'active' }],\n * queryFn: async (condition) => fetchCount(condition),\n * });\n * ```\n */\nexport function useCountQuery<FIELDS extends string = string, E = FetcherError>(\n options: UseCountQueryOptions<FIELDS, E>,\n): UseCountQueryReturn<FIELDS, E> {\n return useQuery(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ListQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useListQuery hook.\n * Extends UseQueryOptions with ListQuery as query key and array of results as data type.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<ListQuery<FIELDS>, R[], E> {\n}\n\n/**\n * Return type for the useListQuery hook.\n * Extends UseQueryReturn with ListQuery as query key and array of results as data type.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<ListQuery<FIELDS>, R[], E> {\n}\n\n/**\n * Hook for querying list data with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe list queries.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including list query configuration\n * @returns The query result with list data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useListQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchListData(query),\n * });\n * ```\n */\nexport function useListQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseListQueryOptions<R, FIELDS, E>,\n): UseListQueryReturn<R, FIELDS, E> {\n return useQuery<ListQuery<FIELDS>, R[], E>(options);\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ListQuery } from '@ahoo-wang/fetcher-wow';\nimport type { JsonServerSentEvent } from '@ahoo-wang/fetcher-eventstream';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useListStreamQuery hook.\n * Extends UseQueryOptions with ListQuery as query key and stream of events as data type.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListStreamQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<\n ListQuery<FIELDS>,\n ReadableStream<JsonServerSentEvent<R>>,\n E\n> {\n}\n\n/**\n * Return type for the useListStreamQuery hook.\n * Extends UseQueryReturn with ListQuery as query key and stream of events as data type.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListStreamQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<\n ListQuery<FIELDS>,\n ReadableStream<JsonServerSentEvent<R>>,\n E\n> {\n}\n\n/**\n * Hook for querying streaming list data with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe streaming list queries.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including list stream query configuration\n * @returns The query result with streaming data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useListStreamQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchStreamData(query),\n * });\n * ```\n */\nexport function useListStreamQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseListStreamQueryOptions<R, FIELDS, E>,\n): UseListStreamQueryReturn<R, FIELDS, E> {\n return useQuery<ListQuery<FIELDS>, ReadableStream<JsonServerSentEvent<R>>, E>(\n options,\n );\n}\n"],"names":["useMounted","isMountedRef","useRef","isMountedFn","useCallback","useEffect","useLatest","value","ref","PromiseStatus","usePromiseState","options","status","setStatus","useState","result","setResult","error","setErrorState","isMounted","latestOptions","setLoadingFn","setSuccessFn","callbackError","setErrorFn","setIdleFn","useMemo","useRequestId","requestIdRef","generate","current","isLatest","requestId","invalidate","reset","useExecutePromise","loading","setLoading","setSuccess","setError","setIdle","propagateError","execute","input","currentRequestId","data","err","useKeyStorage","keyStorage","subscribe","callback","getSnapshot","useSyncExternalStore","setValue","useFetcher","fetcher","fetcherRegistrar","state","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request","useQuery","initialQuery","promiseState","latestQuery","queryExecutor","setQuery","query","promiseExecutor","autoExecute","usePagedQuery","useSingleQuery","useCountQuery","useListQuery","useListStreamQuery"],"mappings":"uUAuCO,SAASA,GAAa,CAC3B,MAAMC,EAAeC,EAAAA,OAAO,EAAK,EAC3BC,EAAcC,EAAAA,YAAY,IAAMH,EAAa,QAAS,CAAA,CAAE,EAC9DI,OAAAA,EAAAA,UAAU,KACRJ,EAAa,QAAU,GAChB,IAAM,CACXA,EAAa,QAAU,EACzB,GACC,CAAA,CAAE,EAEEE,CACT,CCLO,SAASG,EAAaC,EAAU,CACrC,MAAMC,EAAMN,EAAAA,OAAOK,CAAK,EACxB,OAAAC,EAAI,QAAUD,EACPC,CACT,CC5BO,IAAKC,GAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,QAAU,UACVA,EAAA,QAAU,UACVA,EAAA,MAAQ,QAJEA,IAAAA,GAAA,CAAA,CAAA,EA6FL,SAASC,EACdC,EAC6B,CAC7B,KAAM,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAC1BH,GAAS,eAAiB,MAAA,EAEtB,CAACI,EAAQC,CAAS,EAAIF,EAAAA,SAAwB,MAAS,EACvD,CAACG,EAAOC,CAAa,EAAIJ,EAAAA,SAAwB,MAAS,EAC1DK,EAAYnB,EAAA,EACZoB,EAAgBd,EAAUK,CAAO,EACjCU,EAAejB,EAAAA,YAAY,IAAM,CACjCe,MACFN,EAAU,SAAA,EACVK,EAAc,MAAS,EAE3B,EAAG,CAACC,CAAS,CAAC,EAERG,EAAelB,EAAAA,Y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+D,EAKd/D,EACoC,CACpC,OAAOqD,EAAoCrD,CAAO,CACpD,CCjBO,SAASgE,EACdhE,EACgC,CAChC,OAAOqD,EAASrD,CAAO,CACzB,CCKO,SAASiE,EAKdjE,EACkC,CAClC,OAAOqD,EAAoCrD,CAAO,CACpD,CCCO,SAASkE,EAKdlE,EACwC,CACxC,OAAOqD,EACLrD,CAAA,CAEJ"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/core/useMounted.ts","../src/core/useLatest.ts","../src/core/usePromiseState.ts","../src/core/useRequestId.ts","../src/core/useExecutePromise.ts","../src/storage/useKeyStorage.ts","../src/fetcher/useFetcher.ts","../src/wow/useQuery.ts","../src/wow/usePagedQuery.ts","../src/wow/useSingleQuery.ts","../src/wow/useCountQuery.ts","../src/wow/useListQuery.ts","../src/wow/useListStreamQuery.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef, useEffect, useCallback } from 'react';\n\n/**\n * A React hook that returns a function to check if the component is mounted.\n *\n * @returns A function that returns true if the component is mounted, false otherwise\n *\n * @example\n * ```typescript\n * import { useMounted } from '@ahoo-wang/fetcher-react';\n *\n * const MyComponent = () => {\n * const isMounted = useMounted();\n *\n * useEffect(() => {\n * someAsyncOperation().then(() => {\n * if (isMounted()) {\n * setState(result);\n * }\n * });\n * }, []);\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport function useMounted() {\n const isMountedRef = useRef(false);\n const isMountedFn = useCallback(() => isMountedRef.current, []);\n useEffect(() => {\n isMountedRef.current = true;\n return () => {\n isMountedRef.current = false;\n };\n }, []);\n\n return isMountedFn;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { MutableRefObject, useRef } from 'react';\n\n/**\n * A React hook that returns a ref containing the latest value, useful for accessing the current value in async callbacks.\n *\n * @template T - The type of the value\n * @param value - The value to track\n * @returns A ref object containing the latest value\n *\n * @example\n * ```typescript\n * import { useLatest } from '@ahoo-wang/fetcher-react';\n *\n * const MyComponent = () => {\n * const [count, setCount] = useState(0);\n * const latestCount = useLatest(count);\n *\n * const handleAsync = async () => {\n * await someAsyncOperation();\n * console.log('Latest count:', latestCount.current); // Always the latest\n * };\n *\n * return (\n * <div>\n * <p>Count: {count}</p>\n * <button onClick={() => setCount(c => c + 1)}>Increment</button>\n * <button onClick={handleAsync}>Async Log</button>\n * </div>\n * );\n * };\n * ```\n */\nexport function useLatest<T>(value: T): MutableRefObject<T> {\n const ref = useRef(value);\n ref.current = value;\n return ref;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useMemo, useState } from 'react';\nimport { useMounted } from './useMounted';\nimport { useLatest } from './useLatest';\nimport { FetcherError } from '@ahoo-wang/fetcher';\n\n/**\n * Enumeration of possible promise execution states\n */\nexport enum PromiseStatus {\n IDLE = 'idle',\n LOADING = 'loading',\n SUCCESS = 'success',\n ERROR = 'error',\n}\n\nexport interface PromiseState<R, E = unknown> {\n /** Current status of the promise */\n status: PromiseStatus;\n /** Indicates if currently loading */\n loading: boolean;\n /** The result value */\n result: R | undefined;\n /** The error value */\n error: E | undefined;\n}\n\nexport interface PromiseStateCallbacks<R, E = unknown> {\n /** Callback invoked on success (can be async) */\n onSuccess?: (result: R) => void | Promise<void>;\n /** Callback invoked on error (can be async) */\n onError?: (error: E) => void | Promise<void>;\n}\n\n/**\n * Options for configuring usePromiseState behavior\n * @template R - The type of result\n *\n * @example\n * ```typescript\n * const options: UsePromiseStateOptions<string> = {\n * initialStatus: PromiseStatus.IDLE,\n * onSuccess: (result) => console.log('Success:', result),\n * onError: async (error) => {\n * await logErrorToServer(error);\n * console.error('Error:', error);\n * },\n * };\n * ```\n */\nexport interface UsePromiseStateOptions<R, E = FetcherError>\n extends PromiseStateCallbacks<R, E> {\n /** Initial status, defaults to IDLE */\n initialStatus?: PromiseStatus;\n}\n\n/**\n * Return type for usePromiseState hook\n * @template R - The type of result\n */\nexport interface UsePromiseStateReturn<R, E = FetcherError>\n extends PromiseState<R, E> {\n /** Set status to LOADING */\n setLoading: () => void;\n /** Set status to SUCCESS with result */\n setSuccess: (result: R) => Promise<void>;\n /** Set status to ERROR with error */\n setError: (error: E) => Promise<void>;\n /** Set status to IDLE */\n setIdle: () => void;\n}\n\n/**\n * A React hook for managing promise state without execution logic\n * @template R - The type of result\n * @param options - Configuration options\n * @returns State management object\n *\n * @example\n * ```typescript\n * import { usePromiseState, PromiseStatus } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { status, loading, result, error, setSuccess, setError, setIdle } = usePromiseState<string>();\n *\n * const handleSuccess = () => setSuccess('Data loaded');\n * const handleError = () => setError(new Error('Failed to load'));\n *\n * return (\n * <div>\n * <button onClick={handleSuccess}>Set Success</button>\n * <button onClick={handleError}>Set Error</button>\n * <button onClick={setIdle}>Reset</button>\n * <p>Status: {status}</p>\n * {loading && <p>Loading...</p>}\n * {result && <p>Result: {result}</p>}\n * {error && <p>Error: {error.message}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function usePromiseState<R = unknown, E = FetcherError>(\n options?: UsePromiseStateOptions<R, E>,\n): UsePromiseStateReturn<R, E> {\n const [status, setStatus] = useState<PromiseStatus>(\n options?.initialStatus ?? PromiseStatus.IDLE,\n );\n const [result, setResult] = useState<R | undefined>(undefined);\n const [error, setErrorState] = useState<E | undefined>(undefined);\n const isMounted = useMounted();\n const latestOptions = useLatest(options);\n const setLoadingFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.LOADING);\n setErrorState(undefined);\n }\n }, [isMounted]);\n\n const setSuccessFn = useCallback(\n async (result: R) => {\n if (isMounted()) {\n setResult(result);\n setStatus(PromiseStatus.SUCCESS);\n setErrorState(undefined);\n try {\n await latestOptions.current?.onSuccess?.(result);\n } catch (callbackError) {\n // Log callback errors but don't affect state\n console.warn('PromiseState onSuccess callback error:', callbackError);\n }\n }\n },\n [isMounted, latestOptions],\n );\n\n const setErrorFn = useCallback(\n async (error: E) => {\n if (isMounted()) {\n setErrorState(error);\n setStatus(PromiseStatus.ERROR);\n setResult(undefined);\n try {\n await latestOptions.current?.onError?.(error);\n } catch (callbackError) {\n // Log callback errors but don't affect state\n console.warn('PromiseState onError callback error:', callbackError);\n }\n }\n },\n [isMounted, latestOptions],\n );\n\n const setIdleFn = useCallback(() => {\n if (isMounted()) {\n setStatus(PromiseStatus.IDLE);\n setErrorState(undefined);\n setResult(undefined);\n }\n }, [isMounted]);\n return useMemo(\n () => ({\n status,\n loading: status === PromiseStatus.LOADING,\n result,\n error,\n setLoading: setLoadingFn,\n setSuccess: setSuccessFn,\n setError: setErrorFn,\n setIdle: setIdleFn,\n }),\n [status, result, error, setLoadingFn, setSuccessFn, setErrorFn, setIdleFn],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useRef, useCallback, useMemo } from 'react';\n\n/**\n * Return type for useRequestId hook\n */\nexport interface UseRequestIdReturn {\n /** Generate a new request ID and get the current one */\n generate: () => number;\n /** Get the current request ID without generating a new one */\n current: () => number;\n /** Check if a given request ID is the latest */\n isLatest: (requestId: number) => boolean;\n /** Invalidate current request ID (mark as stale) */\n invalidate: () => void;\n /** Reset request ID counter */\n reset: () => void;\n}\n\n/**\n * A React hook for managing request IDs and race condition protection\n *\n * @example\n * ```typescript\n * // Basic usage\n * const requestId = useRequestId();\n *\n * const execute = async () => {\n * const id = requestId.generate();\n *\n * try {\n * const result = await someAsyncOperation();\n *\n * // Check if this is still the latest request\n * if (requestId.isLatest(id)) {\n * setState(result);\n * }\n * } catch (error) {\n * if (requestId.isLatest(id)) {\n * setError(error);\n * }\n * }\n * };\n *\n * // Manual cancellation\n * const handleCancel = () => {\n * requestId.invalidate(); // All ongoing requests will be ignored\n * };\n * ```\n *\n * @example\n * ```typescript\n * // With async operation wrapper\n * const { execute, cancel } = useAsyncOperation(async (data) => {\n * return await apiCall(data);\n * }, [requestId]);\n * ```\n */\nexport function useRequestId(): UseRequestIdReturn {\n const requestIdRef = useRef<number>(0);\n\n const generate = useCallback((): number => {\n return ++requestIdRef.current;\n }, []);\n\n const current = useCallback((): number => {\n return requestIdRef.current;\n }, []);\n\n const isLatest = useCallback((requestId: number): boolean => {\n return requestId === requestIdRef.current;\n }, []);\n\n const invalidate = useCallback((): void => {\n requestIdRef.current++;\n }, []);\n\n const reset = useCallback((): void => {\n requestIdRef.current = 0;\n }, []);\n return useMemo(() => {\n return {\n generate,\n current,\n isLatest,\n invalidate,\n reset,\n };\n }, [generate, current, isLatest, invalidate, reset]);\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { useMounted } from './useMounted';\nimport {\n usePromiseState,\n PromiseState,\n UsePromiseStateOptions,\n} from './usePromiseState';\nimport { useRequestId } from './useRequestId';\nimport { FetcherError } from '@ahoo-wang/fetcher';\n\nexport interface UseExecutePromiseOptions<R, E = unknown>\n extends UsePromiseStateOptions<R, E> {\n /**\n * Whether to propagate errors thrown by the promise.\n * If true, the execute function will throw errors.\n * If false (default), the execute function will return the error as the result instead of throwing.\n */\n propagateError?: boolean;\n}\n\n/**\n * Type definition for a function that returns a Promise\n * @template R - The type of value the promise will resolve to\n */\nexport type PromiseSupplier<R> = () => Promise<R>;\n\n/**\n * Interface defining the return type of useExecutePromise hook\n * @template R - The type of the result value\n */\nexport interface UseExecutePromiseReturn<R, E = FetcherError>\n extends PromiseState<R, E> {\n /**\n * Function to execute a promise supplier or promise.\n * Returns a promise that resolves to the result on success, or the error if propagateError is false.\n */\n execute: (input: PromiseSupplier<R> | Promise<R>) => Promise<R | E>;\n /** Function to reset the state to initial values */\n reset: () => void;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @template R - The type of the result value\n * @template E - The type of the error value\n * @param options - Configuration options for the hook\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useExecutePromise } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute, reset } = useExecutePromise<string>();\n *\n * const fetchData = async () => {\n * const response = await fetch('/api/data');\n * return response.text();\n * };\n *\n * const handleFetch = () => {\n * execute(fetchData);\n * };\n *\n * const handleReset = () => {\n * reset();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * <button onClick={handleReset}>Reset</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n *\n * // Example with propagateError set to true\n * const { execute } = useExecutePromise<string>({ propagateError: true });\n * try {\n * await execute(fetchData);\n * } catch (err) {\n * console.error('Error occurred:', err);\n * }\n * ```\n */\nexport function useExecutePromise<R = unknown, E = FetcherError>(\n options?: UseExecutePromiseOptions<R, E>,\n): UseExecutePromiseReturn<R, E> {\n const { loading, result, error, status, setLoading, setSuccess, setError, setIdle } = usePromiseState<R, E>(options);\n const isMounted = useMounted();\n const requestId = useRequestId();\n const propagateError = options?.propagateError;\n /**\n * Execute a promise supplier or promise and manage its state\n * @param input - A function that returns a Promise or a Promise to be executed\n * @returns A Promise that resolves with the result on success, or the error if propagateError is false\n */\n const execute = useCallback(\n async (input: PromiseSupplier<R> | Promise<R>): Promise<R | E> => {\n if (!isMounted()) {\n throw new Error('Component is unmounted');\n }\n const currentRequestId = requestId.generate();\n setLoading();\n try {\n const promise = typeof input === 'function' ? input() : input;\n const data = await promise;\n\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await setSuccess(data);\n }\n return data;\n } catch (err) {\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await setError(err as E);\n }\n if (propagateError) {\n throw err;\n }\n return err as E;\n }\n },\n [setLoading, setSuccess, setError, isMounted, requestId, propagateError],\n );\n\n /**\n * Reset the state to initial values\n */\n const reset = useCallback(() => {\n if (isMounted()) {\n setIdle();\n }\n }, [setIdle, isMounted]);\n\n return useMemo(\n () => ({\n loading: loading,\n result: result,\n error: error,\n execute,\n reset,\n status: status,\n }),\n [loading, result, error, execute, reset, status],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { KeyStorage } from '@ahoo-wang/fetcher-storage';\n\n/**\n * A React hook that provides state management for a KeyStorage instance.\n * Subscribes to storage changes and returns the current value along with a setter function.\n *\n * @template T - The type of value stored in the key storage\n * @param keyStorage - The KeyStorage instance to subscribe to and manage\n * @returns A tuple containing the current stored value and a function to update it\n */\nexport function useKeyStorage<T>(\n keyStorage: KeyStorage<T>,\n): [T | null, (value: T) => void] {\n const subscribe = useCallback(\n (callback: () => void) => keyStorage.addListener(callback),\n [keyStorage],\n );\n const getSnapshot = useCallback(() => keyStorage.get(), [keyStorage]);\n const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const setValue = useCallback(\n (value: T) => keyStorage.set(value),\n [keyStorage],\n );\n return [value, setValue];\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n fetcherRegistrar,\n FetcherCapable,\n FetchExchange,\n FetchRequest,\n getFetcher,\n RequestOptions, FetcherError,\n} from '@ahoo-wang/fetcher';\nimport { useMounted } from '../core';\nimport { useRef, useCallback, useEffect, useState, useMemo } from 'react';\nimport {\n PromiseState,\n useLatest,\n usePromiseState,\n UsePromiseStateOptions,\n useRequestId,\n} from '../core';\n\n/**\n * Configuration options for the useFetcher hook.\n * Extends RequestOptions and FetcherCapable interfaces.\n */\nexport interface UseFetcherOptions<R, E = FetcherError>\n extends RequestOptions,\n FetcherCapable,\n UsePromiseStateOptions<R, E> {\n}\n\nexport interface UseFetcherReturn<R, E = FetcherError> extends PromiseState<R, E> {\n /** The FetchExchange object representing the ongoing fetch operation */\n exchange?: FetchExchange;\n execute: (request: FetchRequest) => Promise<void>;\n}\n\n/**\n * A React hook for managing asynchronous operations with proper state handling\n * @param options - Configuration options for the fetcher\n * @returns An object containing the current state and control functions\n *\n * @example\n * ```typescript\n * import { useFetcher } from '@ahoo-wang/fetcher-react';\n *\n * function MyComponent() {\n * const { loading, result, error, execute } = useFetcher<string>();\n *\n * const handleFetch = () => {\n * execute({ url: '/api/data', method: 'GET' });\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={handleFetch}>Fetch Data</button>\n * {result && <p>{result}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useFetcher<R, E = FetcherError>(\n options?: UseFetcherOptions<R, E>,\n): UseFetcherReturn<R, E> {\n const { fetcher = fetcherRegistrar.default } = options || {};\n const state = usePromiseState<R, E>(options);\n const [exchange, setExchange] = useState<FetchExchange | undefined>(\n undefined,\n );\n const isMounted = useMounted();\n const abortControllerRef = useRef<AbortController | undefined>();\n const requestId = useRequestId();\n const latestOptions = useLatest(options);\n const currentFetcher = getFetcher(fetcher);\n /**\n * Execute the fetch operation.\n * Cancels any ongoing fetch before starting a new one.\n */\n const execute = useCallback(\n async (request: FetchRequest) => {\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n abortControllerRef.current =\n request.abortController ?? new AbortController();\n request.abortController = abortControllerRef.current;\n const currentRequestId = requestId.generate();\n state.setLoading();\n try {\n const exchange = await currentFetcher.exchange(\n request,\n latestOptions.current,\n );\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n setExchange(exchange);\n }\n const result = await exchange.extractResult<R>();\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await state.setSuccess(result);\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'AbortError') {\n if (isMounted()) {\n state.setIdle();\n }\n return;\n }\n if (isMounted() && requestId.isLatest(currentRequestId)) {\n await state.setError(error as E);\n }\n } finally {\n if (abortControllerRef.current === request.abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [currentFetcher, isMounted, latestOptions, state, requestId],\n );\n\n useEffect(() => {\n return () => {\n abortControllerRef.current?.abort();\n abortControllerRef.current = undefined;\n };\n }, []);\n return useMemo(\n () => ({\n ...state,\n exchange,\n execute,\n }),\n [state, exchange, execute],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n useExecutePromise,\n useLatest,\n UseExecutePromiseReturn,\n UseExecutePromiseOptions,\n} from '../core';\nimport { useCallback, useMemo, useEffect } from 'react';\nimport { AttributesCapable, FetcherError } from '@ahoo-wang/fetcher';\nimport { AutoExecuteCapable } from './types';\n\n/**\n * Configuration options for the useQuery hook\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n */\nexport interface UseQueryOptions<Q, R, E = FetcherError>\n extends UseExecutePromiseOptions<R, E>,\n AttributesCapable,\n AutoExecuteCapable {\n /** The initial query parameters */\n initialQuery: Q;\n\n /** Function to execute the query with given parameters and optional attributes */\n execute: (query: Q, attributes?: Record<string, any>) => Promise<R>;\n}\n\n/**\n * Return type of the useQuery hook\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n */\nexport interface UseQueryReturn<Q, R, E = FetcherError>\n extends UseExecutePromiseReturn<R, E> {\n /**\n * Get the current query parameters\n */\n getQuery: () => Q;\n /** Function to update the query parameters */\n setQuery: (query: Q) => void;\n /** Function to execute the query with current parameters */\n execute: () => Promise<R | E>;\n}\n\n/**\n * A React hook for managing query-based asynchronous operations\n * @template Q - The type of the query parameters\n * @template R - The type of the result value\n * @template E - The type of the error value\n * @param options - Configuration options for the query\n * @returns An object containing the query state and control functions\n *\n * @example\n * ```typescript\n * import { useQuery } from '@ahoo-wang/fetcher-react';\n *\n * interface UserQuery {\n * id: string;\n * }\n *\n * interface User {\n * id: string;\n * name: string;\n * }\n *\n * function UserComponent() {\n * const { loading, result, error, execute, setQuery } = useQuery<UserQuery, User>({\n * initialQuery: { id: '1' },\n * execute: async (query) => {\n * const response = await fetch(`/api/users/${query.id}`);\n * return response.json();\n * },\n * autoExecute: true,\n * });\n *\n * const handleUserChange = (userId: string) => {\n * setQuery({ id: userId });\n * execute();\n * };\n *\n * if (loading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * return (\n * <div>\n * <button onClick={() => handleUserChange('2')}>Load User 2</button>\n * {result && <p>User: {result.name}</p>}\n * </div>\n * );\n * }\n * ```\n */\nexport function useQuery<Q, R, E = FetcherError>(\n options: UseQueryOptions<Q, R, E>,\n): UseQueryReturn<Q, R, E> {\n const { initialQuery } = options;\n const promiseState = useExecutePromise<R, E>(options);\n const latestQuery = useLatest(initialQuery);\n const latestOptions = useLatest(options);\n const queryExecutor = useCallback(async (): Promise<R> => {\n return latestOptions.current.execute(\n latestQuery.current,\n latestOptions.current.attributes,\n );\n }, [latestQuery, latestOptions]);\n const getQuery = useCallback(() => {\n return latestQuery.current;\n }, [latestQuery]);\n const setQuery = useCallback(\n (query: Q) => {\n latestQuery.current = query;\n },\n [latestQuery],\n );\n const { execute: promiseExecutor } = promiseState;\n const execute = useCallback(() => {\n return promiseExecutor(queryExecutor);\n }, [promiseExecutor, queryExecutor]);\n\n const { autoExecute } = options;\n\n useEffect(() => {\n if (autoExecute) {\n execute();\n }\n }, [autoExecute, execute]);\n\n return useMemo(\n () => ({\n ...promiseState,\n execute,\n getQuery,\n setQuery,\n }),\n [promiseState, execute, getQuery, setQuery],\n );\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PagedList, PagedQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the usePagedQuery hook.\n * Extends UseQueryOptions with PagedQuery as query key and PagedList as data type.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UsePagedQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<PagedQuery<FIELDS>, PagedList<R>, E> {\n}\n\n/**\n * Return type for the usePagedQuery hook.\n * Extends UseQueryReturn with PagedQuery as query key and PagedList as data type.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UsePagedQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<PagedQuery<FIELDS>, PagedList<R>, E> {\n}\n\n/**\n * Hook for querying paged data with conditions, projection, pagination, and sorting.\n * Wraps useQuery to provide type-safe paged queries.\n *\n * @template R - The type of the result items in the paged list\n * @template FIELDS - The fields type for the paged query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including paged query configuration\n * @returns The query result with paged list data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = usePagedQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * pagination: { index: 1, size: 10 },\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchPagedData(query),\n * });\n * ```\n */\nexport function usePagedQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UsePagedQueryOptions<R, FIELDS, E>,\n): UsePagedQueryReturn<R, FIELDS, E> {\n return useQuery<PagedQuery<FIELDS>, PagedList<R>, E>(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SingleQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useSingleQuery hook.\n * Extends UseQueryOptions with SingleQuery as query key and custom result type.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseSingleQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<SingleQuery<FIELDS>, R, E> {\n}\n\n/**\n * Return type for the useSingleQuery hook.\n * Extends UseQueryReturn with SingleQuery as query key and custom result type.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseSingleQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<SingleQuery<FIELDS>, R, E> {\n}\n\n/**\n * Hook for querying a single item with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe single item queries.\n *\n * @template R - The result type of the query\n * @template FIELDS - The fields type for the single query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including single query configuration\n * @returns The query result with single item data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useSingleQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchSingleItem(query),\n * });\n * ```\n */\nexport function useSingleQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseSingleQueryOptions<R, FIELDS, E>,\n): UseSingleQueryReturn<R, FIELDS, E> {\n return useQuery<SingleQuery<FIELDS>, R, E>(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Condition } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useCountQuery hook.\n * Extends UseQueryOptions with Condition as query key and number as data type.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseCountQueryOptions<\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<Condition<FIELDS>, number, E> {\n}\n\n/**\n * Return type for the useCountQuery hook.\n * Extends UseQueryReturn with Condition as query key and number as data type.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseCountQueryReturn<\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<Condition<FIELDS>, number, E> {\n}\n\n/**\n * Hook for querying count data with conditions.\n * Wraps useQuery to provide type-safe count queries.\n *\n * @template FIELDS - The fields type for the condition\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including condition and other settings\n * @returns The query result with count data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useCountQuery({\n * queryKey: [{ field: 'status', operator: 'eq', value: 'active' }],\n * queryFn: async (condition) => fetchCount(condition),\n * });\n * ```\n */\nexport function useCountQuery<FIELDS extends string = string, E = FetcherError>(\n options: UseCountQueryOptions<FIELDS, E>,\n): UseCountQueryReturn<FIELDS, E> {\n return useQuery(options);\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ListQuery } from '@ahoo-wang/fetcher-wow';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useListQuery hook.\n * Extends UseQueryOptions with ListQuery as query key and array of results as data type.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<ListQuery<FIELDS>, R[], E> {\n}\n\n/**\n * Return type for the useListQuery hook.\n * Extends UseQueryReturn with ListQuery as query key and array of results as data type.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<ListQuery<FIELDS>, R[], E> {\n}\n\n/**\n * Hook for querying list data with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe list queries.\n *\n * @template R - The type of the result items in the list\n * @template FIELDS - The fields type for the list query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including list query configuration\n * @returns The query result with list data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useListQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchListData(query),\n * });\n * ```\n */\nexport function useListQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseListQueryOptions<R, FIELDS, E>,\n): UseListQueryReturn<R, FIELDS, E> {\n return useQuery<ListQuery<FIELDS>, R[], E>(options);\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ListQuery } from '@ahoo-wang/fetcher-wow';\nimport type { JsonServerSentEvent } from '@ahoo-wang/fetcher-eventstream';\nimport { FetcherError } from '@ahoo-wang/fetcher';\nimport { useQuery, UseQueryOptions, UseQueryReturn } from './useQuery';\n\n/**\n * Options for the useListStreamQuery hook.\n * Extends UseQueryOptions with ListQuery as query key and stream of events as data type.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListStreamQueryOptions<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryOptions<\n ListQuery<FIELDS>,\n ReadableStream<JsonServerSentEvent<R>>,\n E\n> {\n}\n\n/**\n * Return type for the useListStreamQuery hook.\n * Extends UseQueryReturn with ListQuery as query key and stream of events as data type.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n */\nexport interface UseListStreamQueryReturn<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n> extends UseQueryReturn<\n ListQuery<FIELDS>,\n ReadableStream<JsonServerSentEvent<R>>,\n E\n> {\n}\n\n/**\n * Hook for querying streaming list data with conditions, projection, and sorting.\n * Wraps useQuery to provide type-safe streaming list queries.\n *\n * @template R - The type of the result items in the stream events\n * @template FIELDS - The fields type for the list stream query\n * @template E - The error type, defaults to FetcherError\n * @param options - The query options including list stream query configuration\n * @returns The query result with streaming data\n *\n * @example\n * ```typescript\n * const { data, isLoading } = useListStreamQuery<{ id: number; name: string }, 'id' | 'name'>({\n * initialQuery: {\n * condition: all(),\n * projection: { include: ['id', 'name'] },\n * sort: [{ field: 'id', direction: SortDirection.ASC }],\n * },\n * execute: async (query) => fetchStreamData(query),\n * });\n * ```\n */\nexport function useListStreamQuery<\n R,\n FIELDS extends string = string,\n E = FetcherError,\n>(\n options: UseListStreamQueryOptions<R, FIELDS, E>,\n): UseListStreamQueryReturn<R, FIELDS, E> {\n return useQuery<ListQuery<FIELDS>, ReadableStream<JsonServerSentEvent<R>>, E>(\n options,\n );\n}\n"],"names":["useMounted","isMountedRef","useRef","isMountedFn","useCallback","useEffect","useLatest","value","ref","PromiseStatus","usePromiseState","options","status","setStatus","useState","result","setResult","error","setErrorState","isMounted","latestOptions","setLoadingFn","setSuccessFn","callbackError","setErrorFn","setIdleFn","useMemo","useRequestId","requestIdRef","generate","current","isLatest","requestId","invalidate","reset","useExecutePromise","loading","setLoading","setSuccess","setError","setIdle","propagateError","execute","input","currentRequestId","data","err","useKeyStorage","keyStorage","subscribe","callback","getSnapshot","useSyncExternalStore","setValue","useFetcher","fetcher","fetcherRegistrar","state","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request","useQuery","initialQuery","promiseState","latestQuery","queryExecutor","getQuery","setQuery","query","promiseExecutor","autoExecute","usePagedQuery","useSingleQuery","useCountQuery","useListQuery","useListStreamQuery"],"mappings":"uUAuCO,SAASA,GAAa,CAC3B,MAAMC,EAAeC,EAAAA,OAAO,EAAK,EAC3BC,EAAcC,EAAAA,YAAY,IAAMH,EAAa,QAAS,CAAA,CAAE,EAC9DI,OAAAA,EAAAA,UAAU,KACRJ,EAAa,QAAU,GAChB,IAAM,CACXA,EAAa,QAAU,EACzB,GACC,CAAA,CAAE,EAEEE,CACT,CCLO,SAASG,EAAaC,EAA+B,CAC1D,MAAMC,EAAMN,EAAAA,OAAOK,CAAK,EACxB,OAAAC,EAAI,QAAUD,EACPC,CACT,CC5BO,IAAKC,GAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,QAAU,UACVA,EAAA,QAAU,UACVA,EAAA,MAAQ,QAJEA,IAAAA,GAAA,CAAA,CAAA,EA6FL,SAASC,EACdC,EAC6B,CAC7B,KAAM,CAACC,EAAQC,CA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xB,EAAUtC,EAAAA,YAAY,IACnBoE,EAAgBJ,CAAa,EACnC,CAACI,EAAiBJ,CAAa,CAAC,EAE7B,CAAE,YAAAK,GAAgB9D,EAExBN,OAAAA,EAAAA,UAAU,IAAM,CACVoE,GACF/B,EAAA,CAEJ,EAAG,CAAC+B,EAAa/B,CAAO,CAAC,EAElBhB,EAAAA,QACL,KAAO,CACL,GAAGwC,EACH,QAAAxB,EACA,SAAA2B,EACA,SAAAC,CAAA,GAEF,CAACJ,EAAcxB,EAAS2B,EAAUC,CAAQ,CAAA,CAE9C,CC/EO,SAASI,EAKd/D,EACmC,CACnC,OAAOqD,EAA8CrD,CAAO,CAC9D,CCTO,SAASgE,EAKdhE,EACoC,CACpC,OAAOqD,EAAoCrD,CAAO,CACpD,CCjBO,SAASiE,EACdjE,EACgC,CAChC,OAAOqD,EAASrD,CAAO,CACzB,CCKO,SAASkE,EAKdlE,EACkC,CAClC,OAAOqD,EAAoCrD,CAAO,CACpD,CCCO,SAASmE,EAKdnE,EACwC,CACxC,OAAOqD,EACLrD,CAAA,CAEJ"}
@@ -20,10 +20,14 @@ export interface UseQueryOptions<Q, R, E = FetcherError> extends UseExecutePromi
20
20
  * @template E - The type of the error value
21
21
  */
22
22
  export interface UseQueryReturn<Q, R, E = FetcherError> extends UseExecutePromiseReturn<R, E> {
23
- /** Function to execute the query with current parameters */
24
- execute: () => Promise<R | E>;
23
+ /**
24
+ * Get the current query parameters
25
+ */
26
+ getQuery: () => Q;
25
27
  /** Function to update the query parameters */
26
28
  setQuery: (query: Q) => void;
29
+ /** Function to execute the query with current parameters */
30
+ execute: () => Promise<R | E>;
27
31
  }
28
32
  /**
29
33
  * A React hook for managing query-based asynchronous operations
@@ -1 +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,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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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahoo-wang/fetcher-react",
3
- "version": "2.6.16",
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",