@ahoo-wang/fetcher-react 2.8.6 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,20 +1,21 @@
1
1
  var F = Object.defineProperty;
2
2
  var f = (t, e) => F(t, "name", { value: e, configurable: !0 });
3
- import { useRef as b, useCallback as u, useEffect as m, useState as S, useMemo as h, useSyncExternalStore as M } from "react";
4
- import { fetcherRegistrar as q, getFetcher as O } from "@ahoo-wang/fetcher";
3
+ import { useRef as h, useCallback as u, useEffect as w, useState as S, useMemo as x, useSyncExternalStore as M } from "react";
4
+ import { nameGenerator as q } from "@ahoo-wang/fetcher-eventbus";
5
+ import { fetcherRegistrar as O, getFetcher as A } from "@ahoo-wang/fetcher";
5
6
  function R() {
6
- const t = b(!1), e = u(() => t.current, []);
7
- return m(() => (t.current = !0, () => {
7
+ const t = h(!1), e = u(() => t.current, []);
8
+ return w(() => (t.current = !0, () => {
8
9
  t.current = !1;
9
10
  }), []), e;
10
11
  }
11
12
  f(R, "useMounted");
12
13
  function v(t) {
13
- const e = b(t);
14
+ const e = h(t);
14
15
  return e.current = t, e;
15
16
  }
16
17
  f(v, "useLatest");
17
- var A = /* @__PURE__ */ ((t) => (t.IDLE = "idle", t.LOADING = "loading", t.SUCCESS = "success", t.ERROR = "error", t))(A || {});
18
+ var D = /* @__PURE__ */ ((t) => (t.IDLE = "idle", t.LOADING = "loading", t.SUCCESS = "success", t.ERROR = "error", t))(D || {});
18
19
  function C(t) {
19
20
  const [e, r] = S(
20
21
  t?.initialStatus ?? "idle"
@@ -33,8 +34,8 @@ function C(t) {
33
34
  ), n(void 0);
34
35
  try {
35
36
  await d.current?.onSuccess?.(i);
36
- } catch (x) {
37
- console.warn("PromiseState onSuccess callback error:", x);
37
+ } catch (m) {
38
+ console.warn("PromiseState onSuccess callback error:", m);
38
39
  }
39
40
  }
40
41
  },
@@ -48,8 +49,8 @@ function C(t) {
48
49
  ), a(void 0);
49
50
  try {
50
51
  await d.current?.onError?.(i);
51
- } catch (x) {
52
- console.warn("PromiseState onError callback error:", x);
52
+ } catch (m) {
53
+ console.warn("PromiseState onError callback error:", m);
53
54
  }
54
55
  }
55
56
  },
@@ -60,7 +61,7 @@ function C(t) {
60
61
  /* IDLE */
61
62
  ), n(void 0), a(void 0));
62
63
  }, [o]);
63
- return h(
64
+ return x(
64
65
  () => ({
65
66
  status: e,
66
67
  loading: e === "loading",
@@ -76,12 +77,12 @@ function C(t) {
76
77
  }
77
78
  f(C, "usePromiseState");
78
79
  function Q() {
79
- const t = b(0), e = u(() => ++t.current, []), r = u(() => t.current, []), c = u((n) => n === t.current, []), a = u(() => {
80
+ const t = h(0), e = u(() => ++t.current, []), r = u(() => t.current, []), c = u((n) => n === t.current, []), a = u(() => {
80
81
  t.current++;
81
82
  }, []), s = u(() => {
82
83
  t.current = 0;
83
84
  }, []);
84
- return h(() => ({
85
+ return x(() => ({
85
86
  generate: e,
86
87
  current: r,
87
88
  isLatest: c,
@@ -90,27 +91,27 @@ function Q() {
90
91
  }), [e, r, c, a, s]);
91
92
  }
92
93
  f(Q, "useRequestId");
93
- function D(t) {
94
+ function G(t) {
94
95
  const { loading: e, result: r, error: c, status: a, setLoading: s, setSuccess: n, setError: o, setIdle: d } = C(t), l = R(), E = Q(), g = t?.propagateError, y = u(
95
- async (x) => {
96
+ async (m) => {
96
97
  if (!l())
97
98
  throw new Error("Component is unmounted");
98
99
  const I = E.generate();
99
100
  s();
100
101
  try {
101
- const p = await (typeof x == "function" ? x() : x);
102
+ const p = await (typeof m == "function" ? m() : m);
102
103
  return l() && E.isLatest(I) && await n(p), p;
103
- } catch (w) {
104
- if (l() && E.isLatest(I) && await o(w), g)
105
- throw w;
106
- return w;
104
+ } catch (L) {
105
+ if (l() && E.isLatest(I) && await o(L), g)
106
+ throw L;
107
+ return L;
107
108
  }
108
109
  },
109
110
  [s, n, o, l, E, g]
110
111
  ), i = u(() => {
111
112
  l() && d();
112
113
  }, [d, l]);
113
- return h(
114
+ return x(
114
115
  () => ({
115
116
  loading: e,
116
117
  result: r,
@@ -122,10 +123,13 @@ function D(t) {
122
123
  [e, r, c, y, i, a]
123
124
  );
124
125
  }
125
- f(D, "useExecutePromise");
126
- function N(t) {
126
+ f(G, "useExecutePromise");
127
+ function V(t) {
127
128
  const e = u(
128
- (s) => t.addListener(s),
129
+ (s) => t.addListener({
130
+ name: q.generate("useKeyStorage"),
131
+ handle: s
132
+ }),
129
133
  [t]
130
134
  ), r = u(() => t.get(), [t]), c = M(e, r, r), a = u(
131
135
  (s) => t.set(s),
@@ -133,11 +137,11 @@ function N(t) {
133
137
  );
134
138
  return [c, a];
135
139
  }
136
- f(N, "useKeyStorage");
137
- function U(t) {
138
- const { fetcher: e = q.default } = t || {}, r = C(t), [c, a] = S(
140
+ f(V, "useKeyStorage");
141
+ function j(t) {
142
+ const { fetcher: e = O.default } = t || {}, r = C(t), [c, a] = S(
139
143
  void 0
140
- ), s = R(), n = b(), o = Q(), d = v(t), l = O(e), E = u(
144
+ ), s = R(), n = h(), o = Q(), d = v(t), l = A(e), E = u(
141
145
  async (g) => {
142
146
  n.current && n.current.abort(), n.current = g.abortController ?? new AbortController(), g.abortController = n.current;
143
147
  const y = o.generate();
@@ -148,8 +152,8 @@ function U(t) {
148
152
  d.current
149
153
  );
150
154
  s() && o.isLatest(y) && a(i);
151
- const x = await i.extractResult();
152
- s() && o.isLatest(y) && await r.setSuccess(x);
155
+ const m = await i.extractResult();
156
+ s() && o.isLatest(y) && await r.setSuccess(m);
153
157
  } catch (i) {
154
158
  if (i instanceof Error && i.name === "AbortError") {
155
159
  s() && r.setIdle();
@@ -162,9 +166,9 @@ function U(t) {
162
166
  },
163
167
  [l, s, d, r, o]
164
168
  );
165
- return m(() => () => {
169
+ return w(() => () => {
166
170
  n.current?.abort(), n.current = void 0;
167
- }, []), h(
171
+ }, []), x(
168
172
  () => ({
169
173
  ...r,
170
174
  exchange: c,
@@ -173,9 +177,9 @@ function U(t) {
173
177
  [r, c, E]
174
178
  );
175
179
  }
176
- f(U, "useFetcher");
177
- function L(t) {
178
- const e = v(t), r = D(e.current), c = b(t.initialQuery), a = u(async () => e.current.execute(
180
+ f(j, "useFetcher");
181
+ function b(t) {
182
+ const e = v(t), r = G(e.current), c = h(t.initialQuery), a = u(async () => e.current.execute(
179
183
  c.current,
180
184
  e.current.attributes
181
185
  ), [c, e]), { execute: s } = r, n = u(() => s(a), [s, a]), o = u(() => c.current, [c]), d = u(
@@ -184,9 +188,9 @@ function L(t) {
184
188
  },
185
189
  [c, e, n]
186
190
  );
187
- return m(() => {
191
+ return w(() => {
188
192
  e.current.autoExecute && n();
189
- }, [e, n]), h(
193
+ }, [e, n]), x(
190
194
  () => ({
191
195
  ...r,
192
196
  execute: n,
@@ -196,43 +200,43 @@ function L(t) {
196
200
  [r, n, o, d]
197
201
  );
198
202
  }
199
- f(L, "useQuery");
200
- function V(t) {
201
- return L(t);
202
- }
203
- f(V, "usePagedQuery");
204
- function j(t) {
205
- return L(t);
206
- }
207
- f(j, "useSingleQuery");
203
+ f(b, "useQuery");
208
204
  function k(t) {
209
- return L(t);
205
+ return b(t);
210
206
  }
211
- f(k, "useCountQuery");
207
+ f(k, "usePagedQuery");
212
208
  function z(t) {
213
- return L(t);
209
+ return b(t);
214
210
  }
215
- f(z, "useListQuery");
211
+ f(z, "useSingleQuery");
216
212
  function B(t) {
217
- return L(
213
+ return b(t);
214
+ }
215
+ f(B, "useCountQuery");
216
+ function H(t) {
217
+ return b(t);
218
+ }
219
+ f(H, "useListQuery");
220
+ function J(t) {
221
+ return b(
218
222
  t
219
223
  );
220
224
  }
221
- f(B, "useListStreamQuery");
225
+ f(J, "useListStreamQuery");
222
226
  export {
223
- A as PromiseStatus,
224
- k as useCountQuery,
225
- D as useExecutePromise,
226
- U as useFetcher,
227
- N as useKeyStorage,
227
+ D as PromiseStatus,
228
+ B as useCountQuery,
229
+ G as useExecutePromise,
230
+ j as useFetcher,
231
+ V as useKeyStorage,
228
232
  v as useLatest,
229
- z as useListQuery,
230
- B as useListStreamQuery,
233
+ H as useListQuery,
234
+ J as useListStreamQuery,
231
235
  R as useMounted,
232
- V as usePagedQuery,
236
+ k as usePagedQuery,
233
237
  C as usePromiseState,
234
- L as useQuery,
238
+ b as useQuery,
235
239
  Q as useRequestId,
236
- j as useSingleQuery
240
+ z as useSingleQuery
237
241
  };
238
242
  //# sourceMappingURL=index.es.js.map
@@ -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 { 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) => {\n return keyStorage.addListener(callback);\n },\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, useRef } 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 }); // Automatically executes if autoExecute is true\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 latestOptions = useLatest(options);\n const promiseState = useExecutePromise<R, E>(latestOptions.current);\n const queryRef = useRef(options.initialQuery);\n\n const queryExecutor = useCallback(async (): Promise<R> => {\n return latestOptions.current.execute(\n queryRef.current,\n latestOptions.current.attributes,\n );\n }, [queryRef, latestOptions]);\n const { execute: promiseExecutor } = promiseState;\n const execute = useCallback(() => {\n return promiseExecutor(queryExecutor);\n }, [promiseExecutor, queryExecutor]);\n const getQuery = useCallback(() => {\n return queryRef.current;\n }, [queryRef]);\n const setQuery = useCallback(\n (query: Q) => {\n queryRef.current = query;\n if (latestOptions.current.autoExecute) {\n execute();\n }\n },\n [queryRef, latestOptions, execute],\n );\n\n useEffect(() => {\n if (latestOptions.current.autoExecute) {\n execute();\n }\n }, [latestOptions, 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 * @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","__name","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","promiseState","queryRef","queryExecutor","promiseExecutor","getQuery","setQuery","query","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;AAXgBG,EAAAN,GAAA;ACMT,SAASO,EAAaC,GAA+B;AAC1D,QAAMC,IAAMP,EAAOM,CAAK;AACxB,SAAAC,EAAI,UAAUD,GACPC;AACT;AAJgBH,EAAAC,GAAA;ACxBT,IAAKG,sBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,UAAU,WACVA,EAA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qD,EAA8CrD,CAAO;AAC9D;AARgBN,EAAAmE,GAAA;ACDT,SAASC,EAKd9D,GACoC;AACpC,SAAOqD,EAAoCrD,CAAO;AACpD;AARgBN,EAAAoE,GAAA;ACVT,SAASC,EACd/D,GACgC;AAChC,SAAOqD,EAASrD,CAAO;AACzB;AAJgBN,EAAAqE,GAAA;ACUT,SAASC,EAKdhE,GACkC;AAClC,SAAOqD,EAAoCrD,CAAO;AACpD;AARgBN,EAAAsE,GAAA;ACST,SAASC,EAKdjE,GACwC;AACxC,SAAOqD;AAAA,IACLrD;AAAA,EAAA;AAEJ;AAVgBN,EAAAuE,GAAA;"}
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 { 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';\nimport { nameGenerator } from '@ahoo-wang/fetcher-eventbus';\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) => {\n return keyStorage.addListener({\n name: nameGenerator.generate('useKeyStorage'),\n handle: callback,\n });\n },\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, useRef } 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 }); // Automatically executes if autoExecute is true\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 latestOptions = useLatest(options);\n const promiseState = useExecutePromise<R, E>(latestOptions.current);\n const queryRef = useRef(options.initialQuery);\n\n const queryExecutor = useCallback(async (): Promise<R> => {\n return latestOptions.current.execute(\n queryRef.current,\n latestOptions.current.attributes,\n );\n }, [queryRef, latestOptions]);\n const { execute: promiseExecutor } = promiseState;\n const execute = useCallback(() => {\n return promiseExecutor(queryExecutor);\n }, [promiseExecutor, queryExecutor]);\n const getQuery = useCallback(() => {\n return queryRef.current;\n }, [queryRef]);\n const setQuery = useCallback(\n (query: Q) => {\n queryRef.current = query;\n if (latestOptions.current.autoExecute) {\n execute();\n }\n },\n [queryRef, latestOptions, execute],\n );\n\n useEffect(() => {\n if (latestOptions.current.autoExecute) {\n execute();\n }\n }, [latestOptions, 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 * @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","__name","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","nameGenerator","getSnapshot","useSyncExternalStore","setValue","useFetcher","fetcher","fetcherRegistrar","state","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request","useQuery","promiseState","queryRef","queryExecutor","promiseExecutor","getQuery","setQuery","query","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;AAXgBG,EAAAN,GAAA;ACMT,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O,CAAC,GAEpBhB;AAAA,IACL,OAAO;AAAA,MACL,GAAGwC;AAAA,MACH,SAAAxB;AAAA,MACA,UAAA4B;AAAA,MACA,UAAAC;AAAA,IAAA;AAAA,IAEF,CAACL,GAAcxB,GAAS4B,GAAUC,CAAQ;AAAA,EAAA;AAE9C;AA7CgBlE,EAAA4D,GAAA;AClCT,SAASQ,EAKd9D,GACmC;AACnC,SAAOsD,EAA8CtD,CAAO;AAC9D;AARgBN,EAAAoE,GAAA;ACDT,SAASC,EAKd/D,GACoC;AACpC,SAAOsD,EAAoCtD,CAAO;AACpD;AARgBN,EAAAqE,GAAA;ACVT,SAASC,EACdhE,GACgC;AAChC,SAAOsD,EAAStD,CAAO;AACzB;AAJgBN,EAAAsE,GAAA;ACUT,SAASC,EAKdjE,GACkC;AAClC,SAAOsD,EAAoCtD,CAAO;AACpD;AARgBN,EAAAuE,GAAA;ACST,SAASC,EAKdlE,GACwC;AACxC,SAAOsD;AAAA,IACLtD;AAAA,EAAA;AAEJ;AAVgBN,EAAAwE,GAAA;"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(u,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):(u=typeof globalThis<"u"?globalThis:u||self,t(u.FetcherReact={},u.React,u.Fetcher))})(this,(function(u,t,w){"use strict";var j=Object.defineProperty;var d=(u,t)=>j(u,"name",{value:t,configurable:!0});function S(){const e=t.useRef(!1),r=t.useCallback(()=>e.current,[]);return t.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),r}d(S,"useMounted");function m(e){const r=t.useRef(e);return r.current=e,r}d(m,"useLatest");var Q=(e=>(e.IDLE="idle",e.LOADING="loading",e.SUCCESS="success",e.ERROR="error",e))(Q||{});function k(e){const[r,n]=t.useState(e?.initialStatus??"idle"),[o,i]=t.useState(void 0),[c,s]=t.useState(void 0),a=S(),b=m(e),f=t.useCallback(()=>{a()&&(n("loading"),s(void 0))},[a]),y=t.useCallback(async l=>{if(a()){i(l),n("success"),s(void 0);try{await b.current?.onSuccess?.(l)}catch(g){console.warn("PromiseState onSuccess callback error:",g)}}},[a,b]),C=t.useCallback(async l=>{if(a()){s(l),n("error"),i(void 0);try{await b.current?.onError?.(l)}catch(g){console.warn("PromiseState onError callback error:",g)}}},[a,b]),E=t.useCallback(()=>{a()&&(n("idle"),s(void 0),i(void 0))},[a]);return t.useMemo(()=>({status:r,loading:r==="loading",result:o,error:c,setLoading:f,setSuccess:y,setError:C,setIdle:E}),[r,o,c,f,y,C,E])}d(k,"usePromiseState");function L(){const e=t.useRef(0),r=t.useCallback(()=>++e.current,[]),n=t.useCallback(()=>e.current,[]),o=t.useCallback(s=>s===e.current,[]),i=t.useCallback(()=>{e.current++},[]),c=t.useCallback(()=>{e.current=0},[]);return t.useMemo(()=>({generate:r,current:n,isLatest:o,invalidate:i,reset:c}),[r,n,o,i,c])}d(L,"useRequestId");function v(e){const{loading:r,result:n,error:o,status:i,setLoading:c,setSuccess:s,setError:a,setIdle:b}=k(e),f=S(),y=L(),C=e?.propagateError,E=t.useCallback(async g=>{if(!f())throw new Error("Component is unmounted");const I=y.generate();c();try{const M=await(typeof g=="function"?g():g);return f()&&y.isLatest(I)&&await s(M),M}catch(R){if(f()&&y.isLatest(I)&&await a(R),C)throw R;return R}},[c,s,a,f,y,C]),l=t.useCallback(()=>{f()&&b()},[b,f]);return t.useMemo(()=>({loading:r,result:n,error:o,execute:E,reset:l,status:i}),[r,n,o,E,l,i])}d(v,"useExecutePromise");function F(e){const r=t.useCallback(c=>e.addListener(c),[e]),n=t.useCallback(()=>e.get(),[e]),o=t.useSyncExternalStore(r,n,n),i=t.useCallback(c=>e.set(c),[e]);return[o,i]}d(F,"useKeyStorage");function q(e){const{fetcher:r=w.fetcherRegistrar.default}=e||{},n=k(e),[o,i]=t.useState(void 0),c=S(),s=t.useRef(),a=L(),b=m(e),f=w.getFetcher(r),y=t.useCallback(async C=>{s.current&&s.current.abort(),s.current=C.abortController??new AbortController,C.abortController=s.current;const E=a.generate();n.setLoading();try{const l=await f.exchange(C,b.current);c()&&a.isLatest(E)&&i(l);const g=await l.extractResult();c()&&a.isLatest(E)&&await n.setSuccess(g)}catch(l){if(l instanceof Error&&l.name==="AbortError"){c()&&n.setIdle();return}c()&&a.isLatest(E)&&await n.setError(l)}finally{s.current===C.abortController&&(s.current=void 0)}},[f,c,b,n,a]);return t.useEffect(()=>()=>{s.current?.abort(),s.current=void 0},[]),t.useMemo(()=>({...n,exchange:o,execute:y}),[n,o,y])}d(q,"useFetcher");function h(e){const r=m(e),n=v(r.current),o=t.useRef(e.initialQuery),i=t.useCallback(async()=>r.current.execute(o.current,r.current.attributes),[o,r]),{execute:c}=n,s=t.useCallback(()=>c(i),[c,i]),a=t.useCallback(()=>o.current,[o]),b=t.useCallback(f=>{o.current=f,r.current.autoExecute&&s()},[o,r,s]);return t.useEffect(()=>{r.current.autoExecute&&s()},[r,s]),t.useMemo(()=>({...n,execute:s,getQuery:a,setQuery:b}),[n,s,a,b])}d(h,"useQuery");function P(e){return h(e)}d(P,"usePagedQuery");function x(e){return h(e)}d(x,"useSingleQuery");function O(e){return h(e)}d(O,"useCountQuery");function A(e){return h(e)}d(A,"useListQuery");function T(e){return h(e)}d(T,"useListStreamQuery"),u.PromiseStatus=Q,u.useCountQuery=O,u.useExecutePromise=v,u.useFetcher=q,u.useKeyStorage=F,u.useLatest=m,u.useListQuery=A,u.useListStreamQuery=T,u.useMounted=S,u.usePagedQuery=P,u.usePromiseState=k,u.useQuery=h,u.useRequestId=L,u.useSingleQuery=x,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react"),require("@ahoo-wang/fetcher-eventbus"),require("@ahoo-wang/fetcher")):typeof define=="function"&&define.amd?define(["exports","react","@ahoo-wang/fetcher-eventbus","@ahoo-wang/fetcher"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.FetcherReact={},u.React,u.FetcherEventBus,u.Fetcher))})(this,(function(u,t,F,L){"use strict";var j=Object.defineProperty;var d=(u,t)=>j(u,"name",{value:t,configurable:!0});function S(){const e=t.useRef(!1),r=t.useCallback(()=>e.current,[]);return t.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),r}d(S,"useMounted");function m(e){const r=t.useRef(e);return r.current=e,r}d(m,"useLatest");var v=(e=>(e.IDLE="idle",e.LOADING="loading",e.SUCCESS="success",e.ERROR="error",e))(v||{});function k(e){const[r,n]=t.useState(e?.initialStatus??"idle"),[c,i]=t.useState(void 0),[o,s]=t.useState(void 0),a=S(),b=m(e),f=t.useCallback(()=>{a()&&(n("loading"),s(void 0))},[a]),h=t.useCallback(async l=>{if(a()){i(l),n("success"),s(void 0);try{await b.current?.onSuccess?.(l)}catch(g){console.warn("PromiseState onSuccess callback error:",g)}}},[a,b]),y=t.useCallback(async l=>{if(a()){s(l),n("error"),i(void 0);try{await b.current?.onError?.(l)}catch(g){console.warn("PromiseState onError callback error:",g)}}},[a,b]),C=t.useCallback(()=>{a()&&(n("idle"),s(void 0),i(void 0))},[a]);return t.useMemo(()=>({status:r,loading:r==="loading",result:c,error:o,setLoading:f,setSuccess:h,setError:y,setIdle:C}),[r,c,o,f,h,y,C])}d(k,"usePromiseState");function w(){const e=t.useRef(0),r=t.useCallback(()=>++e.current,[]),n=t.useCallback(()=>e.current,[]),c=t.useCallback(s=>s===e.current,[]),i=t.useCallback(()=>{e.current++},[]),o=t.useCallback(()=>{e.current=0},[]);return t.useMemo(()=>({generate:r,current:n,isLatest:c,invalidate:i,reset:o}),[r,n,c,i,o])}d(w,"useRequestId");function Q(e){const{loading:r,result:n,error:c,status:i,setLoading:o,setSuccess:s,setError:a,setIdle:b}=k(e),f=S(),h=w(),y=e?.propagateError,C=t.useCallback(async g=>{if(!f())throw new Error("Component is unmounted");const I=h.generate();o();try{const M=await(typeof g=="function"?g():g);return f()&&h.isLatest(I)&&await s(M),M}catch(R){if(f()&&h.isLatest(I)&&await a(R),y)throw R;return R}},[o,s,a,f,h,y]),l=t.useCallback(()=>{f()&&b()},[b,f]);return t.useMemo(()=>({loading:r,result:n,error:c,execute:C,reset:l,status:i}),[r,n,c,C,l,i])}d(Q,"useExecutePromise");function q(e){const r=t.useCallback(o=>e.addListener({name:F.nameGenerator.generate("useKeyStorage"),handle:o}),[e]),n=t.useCallback(()=>e.get(),[e]),c=t.useSyncExternalStore(r,n,n),i=t.useCallback(o=>e.set(o),[e]);return[c,i]}d(q,"useKeyStorage");function P(e){const{fetcher:r=L.fetcherRegistrar.default}=e||{},n=k(e),[c,i]=t.useState(void 0),o=S(),s=t.useRef(),a=w(),b=m(e),f=L.getFetcher(r),h=t.useCallback(async y=>{s.current&&s.current.abort(),s.current=y.abortController??new AbortController,y.abortController=s.current;const C=a.generate();n.setLoading();try{const l=await f.exchange(y,b.current);o()&&a.isLatest(C)&&i(l);const g=await l.extractResult();o()&&a.isLatest(C)&&await n.setSuccess(g)}catch(l){if(l instanceof Error&&l.name==="AbortError"){o()&&n.setIdle();return}o()&&a.isLatest(C)&&await n.setError(l)}finally{s.current===y.abortController&&(s.current=void 0)}},[f,o,b,n,a]);return t.useEffect(()=>()=>{s.current?.abort(),s.current=void 0},[]),t.useMemo(()=>({...n,exchange:c,execute:h}),[n,c,h])}d(P,"useFetcher");function E(e){const r=m(e),n=Q(r.current),c=t.useRef(e.initialQuery),i=t.useCallback(async()=>r.current.execute(c.current,r.current.attributes),[c,r]),{execute:o}=n,s=t.useCallback(()=>o(i),[o,i]),a=t.useCallback(()=>c.current,[c]),b=t.useCallback(f=>{c.current=f,r.current.autoExecute&&s()},[c,r,s]);return t.useEffect(()=>{r.current.autoExecute&&s()},[r,s]),t.useMemo(()=>({...n,execute:s,getQuery:a,setQuery:b}),[n,s,a,b])}d(E,"useQuery");function x(e){return E(e)}d(x,"usePagedQuery");function O(e){return E(e)}d(O,"useSingleQuery");function A(e){return E(e)}d(A,"useCountQuery");function K(e){return E(e)}d(K,"useListQuery");function T(e){return E(e)}d(T,"useListStreamQuery"),u.PromiseStatus=v,u.useCountQuery=A,u.useExecutePromise=Q,u.useFetcher=P,u.useKeyStorage=q,u.useLatest=m,u.useListQuery=K,u.useListStreamQuery=T,u.useMounted=S,u.usePagedQuery=x,u.usePromiseState=k,u.useQuery=E,u.useRequestId=w,u.useSingleQuery=O,Object.defineProperty(u,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 { 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) => {\n return keyStorage.addListener(callback);\n },\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, useRef } 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 }); // Automatically executes if autoExecute is true\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 latestOptions = useLatest(options);\n const promiseState = useExecutePromise<R, E>(latestOptions.current);\n const queryRef = useRef(options.initialQuery);\n\n const queryExecutor = useCallback(async (): Promise<R> => {\n return latestOptions.current.execute(\n queryRef.current,\n latestOptions.current.attributes,\n );\n }, [queryRef, latestOptions]);\n const { execute: promiseExecutor } = promiseState;\n const execute = useCallback(() => {\n return promiseExecutor(queryExecutor);\n }, [promiseExecutor, queryExecutor]);\n const getQuery = useCallback(() => {\n return queryRef.current;\n }, [queryRef]);\n const setQuery = useCallback(\n (query: Q) => {\n queryRef.current = query;\n if (latestOptions.current.autoExecute) {\n execute();\n }\n },\n [queryRef, latestOptions, execute],\n );\n\n useEffect(() => {\n if (latestOptions.current.autoExecute) {\n execute();\n }\n }, [latestOptions, 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 * @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","__name","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","promiseState","queryRef","queryExecutor","promiseExecutor","getQuery","setQuery","query","usePagedQuery","useSingleQuery","useCountQuery","useListQuery","useListStreamQuery"],"mappings":"sZAuCO,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,CAXgBG,EAAAN,EAAA,cCMT,SAASO,EAAaC,EAA+B,CAC1D,MAAMC,EAAMP,EAAAA,OAAOM,CAAK,EACxB,OAAAC,EAAI,QAAUD,EACPC,CACT,CAJgBH,EAAAC,EAAA,a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YAAY,SACzBiB,EAAc,QAAQ,QAC3B8C,EAAS,QACT9C,EAAc,QAAQ,UAAA,EAEvB,CAAC8C,EAAU9C,CAAa,CAAC,EACtB,CAAE,QAASgD,CAAA,EAAoBH,EAC/BvB,EAAUvC,EAAAA,YAAY,IACnBiE,EAAgBD,CAAa,EACnC,CAACC,EAAiBD,CAAa,CAAC,EAC7BE,EAAWlE,EAAAA,YAAY,IACpB+D,EAAS,QACf,CAACA,CAAQ,CAAC,EACPI,EAAWnE,EAAAA,YACdoE,GAAa,CACZL,EAAS,QAAUK,EACfnD,EAAc,QAAQ,aACxBsB,EAAA,CAEJ,EACA,CAACwB,EAAU9C,EAAesB,CAAO,CAAA,EAGnCtC,OAAAA,EAAAA,UAAU,IAAM,CACVgB,EAAc,QAAQ,aACxBsB,EAAA,CAEJ,EAAG,CAACtB,EAAesB,CAAO,CAAC,EAEpBhB,EAAAA,QACL,KAAO,CACL,GAAGuC,EACH,QAAAvB,EACA,SAAA2B,EACA,SAAAC,CAAA,GAEF,CAACL,EAAcvB,EAAS2B,EAAUC,CAAQ,CAAA,CAE9C,CA7CgBjE,EAAA2D,EAAA,YClCT,SAASQ,EAKd7D,EACmC,CACnC,OAAOqD,EAA8CrD,CAAO,CAC9D,CARgBN,EAAAmE,EAAA,iBCDT,SAASC,EAKd9D,EACoC,CACpC,OAAOqD,EAAoCrD,CAAO,CACpD,CARgBN,EAAAoE,EAAA,kBCVT,SAASC,EACd/D,EACgC,CAChC,OAAOqD,EAASrD,CAAO,CACzB,CAJgBN,EAAAqE,EAAA,iBCUT,SAASC,EAKdhE,EACkC,CAClC,OAAOqD,EAAoCrD,CAAO,CACpD,CARgBN,EAAAsE,EAAA,gBCST,SAASC,EAKdjE,EACwC,CACxC,OAAOqD,EACLrD,CAAA,CAEJ,CAVgBN,EAAAuE,EAAA"}
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';\nimport { nameGenerator } from '@ahoo-wang/fetcher-eventbus';\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) => {\n return keyStorage.addListener({\n name: nameGenerator.generate('useKeyStorage'),\n handle: callback,\n });\n },\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, useRef } 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 }); // Automatically executes if autoExecute is true\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 latestOptions = useLatest(options);\n const promiseState = useExecutePromise<R, E>(latestOptions.current);\n const queryRef = useRef(options.initialQuery);\n\n const queryExecutor = useCallback(async (): Promise<R> => {\n return latestOptions.current.execute(\n queryRef.current,\n latestOptions.current.attributes,\n );\n }, [queryRef, latestOptions]);\n const { execute: promiseExecutor } = promiseState;\n const execute = useCallback(() => {\n return promiseExecutor(queryExecutor);\n }, [promiseExecutor, queryExecutor]);\n const getQuery = useCallback(() => {\n return queryRef.current;\n }, [queryRef]);\n const setQuery = useCallback(\n (query: Q) => {\n queryRef.current = query;\n if (latestOptions.current.autoExecute) {\n execute();\n }\n },\n [queryRef, latestOptions, execute],\n );\n\n useEffect(() => {\n if (latestOptions.current.autoExecute) {\n execute();\n }\n }, [latestOptions, 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 * @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","__name","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","nameGenerator","getSnapshot","useSyncExternalStore","setValue","useFetcher","fetcher","fetcherRegistrar","state","exchange","setExchange","abortControllerRef","currentFetcher","getFetcher","request","useQuery","promiseState","queryRef","queryExecutor","promiseExecutor","getQuery","setQuery","query","usePagedQuery","useSingleQuery","useCountQuery","useListQuery","useListStreamQuery"],"mappings":"+eAuCO,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,CAXgBG,EAAAN,EAAA,cCMT,SAASO,EAAaC,EAA+B,CAC1D,MAAMC,EAAMP,EAAAA,OAAOM,CAAK,EACxB,OAAAC,EAAI,QAAUD,EACPC,CACT,CAJgBH,EAAAC,EAAA,aCxBT,IAAKG,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,EAAYpB,EAAA,EACZ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EAAWpE,EAAAA,YACdqE,GAAa,CACZL,EAAS,QAAUK,EACfpD,EAAc,QAAQ,aACxBsB,EAAA,CAEJ,EACA,CAACyB,EAAU/C,EAAesB,CAAO,CAAA,EAGnCtC,OAAAA,EAAAA,UAAU,IAAM,CACVgB,EAAc,QAAQ,aACxBsB,EAAA,CAEJ,EAAG,CAACtB,EAAesB,CAAO,CAAC,EAEpBhB,EAAAA,QACL,KAAO,CACL,GAAGwC,EACH,QAAAxB,EACA,SAAA4B,EACA,SAAAC,CAAA,GAEF,CAACL,EAAcxB,EAAS4B,EAAUC,CAAQ,CAAA,CAE9C,CA7CgBlE,EAAA4D,EAAA,YClCT,SAASQ,EAKd9D,EACmC,CACnC,OAAOsD,EAA8CtD,CAAO,CAC9D,CARgBN,EAAAoE,EAAA,iBCDT,SAASC,EAKd/D,EACoC,CACpC,OAAOsD,EAAoCtD,CAAO,CACpD,CARgBN,EAAAqE,EAAA,kBCVT,SAASC,EACdhE,EACgC,CAChC,OAAOsD,EAAStD,CAAO,CACzB,CAJgBN,EAAAsE,EAAA,iBCUT,SAASC,EAKdjE,EACkC,CAClC,OAAOsD,EAAoCtD,CAAO,CACpD,CARgBN,EAAAuE,EAAA,gBCST,SAASC,EAKdlE,EACwC,CACxC,OAAOsD,EACLtD,CAAA,CAEJ,CAVgBN,EAAAwE,EAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyStorage.d.ts","sourceRoot":"","sources":["../../src/storage/useKeyStorage.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GACxB,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAchC"}
1
+ {"version":3,"file":"useKeyStorage.d.ts","sourceRoot":"","sources":["../../src/storage/useKeyStorage.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGxD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GACxB,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,CAiBhC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahoo-wang/fetcher-react",
3
- "version": "2.8.6",
3
+ "version": "2.9.0",
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",
@@ -42,6 +42,7 @@
42
42
  "peerDependencies": {
43
43
  "@ahoo-wang/fetcher": "^2.3.4",
44
44
  "@ahoo-wang/fetcher-eventstream": "^2.3.4",
45
+ "@ahoo-wang/fetcher-eventbus": "^2.8.8",
45
46
  "@ahoo-wang/fetcher-storage": "^2.3.4",
46
47
  "@ahoo-wang/fetcher-wow": "^2.3.4",
47
48
  "react": ">=18.0.0",