@ahoo-wang/wow-react 10.0.0-alpha.7 → 10.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,7 +28,8 @@ export interface UseCursorQueryOptions<R, FIELDS extends string = string, Q exte
28
28
  * `execute()` start again from the first page with no rows; `reset()`
29
29
  * empties them; `abort()` and an error keep them.
30
30
  * - `hasMore` — whether a page follows the last one read.
31
- * - `fetchNext()` — reads the next page and appends its rows; it does
31
+ * - `fetchNext()` — reads the next page and appends its rows, from where the
32
+ * pages stand when it is called, whichever render it came from; it does
32
33
  * nothing while a page is loading or when no page follows. A failed
33
34
  * `fetchNext()` keeps the rows, so calling it again retries that page.
34
35
  */
package/dist/index.es.js CHANGED
@@ -140,50 +140,50 @@ function useCountQuery(e) {
140
140
  }
141
141
  // src/hooks/useCursorQuery.ts
142
142
  function useCursorQuery(e) {
143
- let t = c(24), [n, r] = a(noPages), o = i(null), s = e.execute, t0;
144
- t[0] === s ? t0 = t[1] : (t0 = async (e, t) => {
145
- let n = o.current;
146
- o.current = null, n === null && r(noPages());
147
- let i = await s({
148
- ...e,
149
- cursor: n
150
- }, t);
151
- return t.signal.aborted || r((e) => ({
152
- items: n === null ? [...i.list] : [...e.items, ...i.list],
153
- nextCursor: i.nextCursor
154
- })), i;
155
- }, t[0] = s, t[1] = t0);
156
- let l;
157
- t[2] !== e || t[3] !== t0 ? (l = {
143
+ let [n, r] = a(noPages), o = i(null), s = i({
144
+ nextCursor: void 0,
145
+ runs: 0
146
+ }), c = e.execute, { status: l, loading: u, error: d, problem: f, execute: p, abort: m, reset: h, getQuery: g, setQuery: _ } = useQueryRunner({
158
147
  ...e,
159
- execute: t0
160
- }, t[2] = e, t[3] = t0, t[4] = l) : l = t[4];
161
- let { status: u, loading: d, error: f, problem: p, execute: m, abort: h, reset: g, getQuery: _, setQuery: v } = useQueryRunner(l, !1), y = typeof n.nextCursor == "string", t2;
162
- t[5] !== m || t[6] !== d || t[7] !== n.nextCursor ? (t2 = async () => {
163
- if (d || typeof n.nextCursor != "string") return;
164
- o.current = n.nextCursor;
165
- let e = m();
166
- o.current = null, await e;
167
- }, t[5] = m, t[6] = d, t[7] = n.nextCursor, t[8] = t2) : t2 = t[8];
168
- let b = t2, t3;
169
- t[9] === g ? t3 = t[10] : (t3 = () => {
170
- g(), r(noPages());
171
- }, t[9] = g, t[10] = t3);
172
- let x = t3, S;
173
- return t[11] !== h || t[12] !== f || t[13] !== m || t[14] !== b || t[15] !== _ || t[16] !== y || t[17] !== d || t[18] !== n.items || t[19] !== p || t[20] !== x || t[21] !== v || t[22] !== u ? (S = {
148
+ execute: async (e, t) => {
149
+ let n = o.current;
150
+ o.current = null, n === null && (s.current.nextCursor = void 0, r(noPages())), s.current.runs++;
151
+ try {
152
+ let i = await c({
153
+ ...e,
154
+ cursor: n
155
+ }, t);
156
+ return t.signal.aborted || (s.current.nextCursor = i.nextCursor, r((e) => ({
157
+ items: n === null ? [...i.list] : [...e.items, ...i.list],
158
+ nextCursor: i.nextCursor
159
+ }))), i;
160
+ } finally {
161
+ s.current.runs--;
162
+ }
163
+ }
164
+ }, !1), v = typeof n.nextCursor == "string", y = t(async () => {
165
+ let { nextCursor: e, runs: t } = s.current;
166
+ if (t > 0 || typeof e != "string") return;
167
+ o.current = e;
168
+ let n = p();
169
+ o.current = null, await n;
170
+ }, [p]), b = t(() => {
171
+ h(), s.current.nextCursor = void 0, r(noPages());
172
+ }, [h]);
173
+ return {
174
174
  items: n.items,
175
- hasMore: y,
176
- fetchNext: b,
177
- loading: d,
178
- error: f,
179
- problem: p,
180
- status: u,
181
- execute: m,
182
- abort: h,
183
- reset: x,
184
- getQuery: _,
185
- setQuery: v
186
- }, t[11] = h, t[12] = f, t[13] = m, t[14] = b, t[15] = _, t[16] = y, t[17] = d, t[18] = n.items, t[19] = p, t[20] = x, t[21] = v, t[22] = u, t[23] = S) : S = t[23], S;
175
+ hasMore: v,
176
+ fetchNext: y,
177
+ loading: u,
178
+ error: d,
179
+ problem: f,
180
+ status: l,
181
+ execute: p,
182
+ abort: m,
183
+ reset: b,
184
+ getQuery: g,
185
+ setQuery: _
186
+ };
187
187
  }
188
188
  function noPages() {
189
189
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","names":["QueryStatus","QueryState","status","result","R","error","Error","QueryEvent","type","initialQueryState","runsOnMount","undefined","queryTransition","state","event","dequal","useCallback","useEffect","useLayoutEffect","useRef","useState","RequestOptions","toWowProblemError","WowProblemError","QueryHookOptions","QueryHookReturn","initialQueryState","queryTransition","QueryEvent","QueryState","useContentStable","value","kept","setKept","notify","name","callback","T","Promise","thrown","console","warn","isAbortError","error","Error","failureOf","problem","String","cause","useQueryRunner","options","Q","R","O","retainResult","autoExecute","query","requestOptions","state","setState","initialQuery","undefined","latest","current","request","id","controller","AbortController","mounted","settle","event","cancel","abort","execute","type","result","signal","AbortSignal","aborted","onSuccess","onError","reset","getQuery","setQuery","previousQuery","cleared","status","loading","AggregationQuery","useQueryRunner","QueryHookOptions","QueryHookReturn","UseAggregateQueryOptions","FIELDS","Q","ROW","UseAggregateQueryReturn","useAggregateQuery","options","CountQuery","CountResult","useQueryRunner","QueryHookOptions","QueryHookReturn","UseCountQueryOptions","FIELDS","Q","UseCountQueryReturn","useCountQuery","options","CursorPage","CursorQuery","useCallback","useRef","useState","useQueryRunner","QueryExecutor","QueryHookOptions","QueryHookReturn","UseCursorQueryOptions","Omit","FIELDS","Q","R","execute","cursor","UseCursorQueryReturn","items","hasMore","fetchNext","Promise","Pages","nextCursor","useCursorQuery","options","$","_c","pages","setPages","noPages","next","readPage","t0","query","options_0","current","page","signal","aborted","pages_0","list","t1","status","loading","error","problem","abort","reset","getQuery","setQuery","t2","run","t3","resetPages","t4","undefined","_c","FilterListQuery","useQueryRunner","QueryHookOptions","QueryHookReturn","UseListQueryOptions","FIELDS","Q","R","UseListQueryReturn","useListQuery","options","PagedQuery","PagedList","useQueryRunner","QueryHookOptions","QueryHookReturn","UsePagedQueryOptions","FIELDS","Q","R","UsePagedQueryReturn","usePagedQuery","options","FilterSingleQuery","useQueryRunner","QueryHookOptions","QueryHookReturn","UseSingleQueryOptions","FIELDS","Q","R","UseSingleQueryReturn","useSingleQuery","options","Positioned","PUBLISH_INTERVAL_MS","readStreamRows","stream","ReadableStream","R","signal","AbortSignal","publish","rows","position","Promise","reader","getReader","published","publishedAt","Infinity","timer","ReturnType","setTimeout","flush","undefined","clearTimeout","aborted","length","Date","now","slice","schedule","wait","Math","max","cancel","reason","catch","addEventListener","once","done","value","read","push","row","error","removeEventListener","releaseLock","StreamOptions","FilterListQuery","useCallback","useState","readStreamRows","useQueryRunner","QueryHookOptions","QueryHookReturn","StreamExecutor","UseStreamQueryOptions","FIELDS","Omit","Q","R","execute","UseStreamQueryReturn","items","position","done","Rows","useStreamQuery","options","$","_c","rows","setRows","noRows","openStream","t0","query","options_0","stream","signal","t1","status","loading","error","problem","abort","reset","getQuery","setQuery","t2","resetRows","t3","t4","undefined","_c","runsOnMount","event","state","kept","setKept","useState","value","dequal","callback","thrown","name","error","toWowProblemError","autoExecute","options","query","requestOptions","setState","latest","useRef","current","request","mounted","settle","useCallback","id","state_0","cancel","controller","execute_0","query_0","controller_0","id_0","state_1","requestOptions_0","result","execute","retainResult","abort","state_2","reset","state_3","getQuery","setQuery","query_1","previousQuery","useEffect","cleared","WowProblemError","$","pages","setPages","next","readPage","cursor","page","options_0","pages_0","t1","hasMore","loading","run","fetchNext","resetPages","t4","problem","status","reader","stream","rows","position","published","publishedAt","timer","publish","wait","signal","done","setRows","openStream","resetRows","t3"],"sources":["../src/internal/queryTransitions.ts","../src/internal/useQueryRunner.ts","../src/hooks/useAggregateQuery.ts","../src/hooks/useCountQuery.ts","../src/hooks/useCursorQuery.ts","../src/hooks/useListQuery.ts","../src/hooks/usePagedQuery.ts","../src/hooks/useSingleQuery.ts","../src/internal/readStreamRows.ts","../src/hooks/useStreamQuery.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\n/*\n * What a query hook shows, and how each event changes it: section 3 of\n * docs/design/architecture.md as pure functions, with no React. The\n * request itself (aborting it, ignoring a late answer) is useQueryRunner's.\n */\n\nimport type { QueryStatus } from '../types.js';\n\n/** What a query hook shows at one moment. */\nexport interface QueryState<R> {\n status: QueryStatus;\n result: R | undefined;\n error: Error | undefined;\n}\n\n/** Something that happens to a query hook. */\nexport type QueryEvent<R> =\n | { type: 'start' }\n | { type: 'succeed'; result: R | undefined }\n | { type: 'fail'; error: Error }\n | { type: 'abort' }\n | { type: 'reset' };\n\n/**\n * The first state. A hook that will run its query as soon as it mounts\n * starts `loading`, so the server and the first client frame already show\n * what the next frames show; any other starts `idle`.\n */\nexport function initialQueryState<R>(runsOnMount: boolean): QueryState<R> {\n return {\n status: runsOnMount ? 'loading' : 'idle',\n result: undefined,\n error: undefined,\n };\n}\n\n/**\n * The state after one event:\n *\n * - `start`: `loading`; the last result stays until the new one arrives, the\n * error goes.\n * - `succeed`: `success` with the new result (`undefined` for a hook that\n * keeps its own, as the list-stream hooks keep `items`).\n * - `fail`: `error`; the last result stays, so a failed refresh does not\n * blank what was shown.\n * - `abort`: `idle`; the last result stays, the error goes.\n * - `reset`: `idle`, with neither result nor error.\n */\nexport function queryTransition<R>(\n state: QueryState<R>,\n event: QueryEvent<R>,\n): QueryState<R> {\n switch (event.type) {\n case 'start':\n return { status: 'loading', result: state.result, error: undefined };\n case 'succeed':\n return { status: 'success', result: event.result, error: undefined };\n case 'fail':\n return { status: 'error', result: state.result, error: event.error };\n case 'abort':\n return { status: 'idle', result: state.result, error: undefined };\n case 'reset':\n return { status: 'idle', result: undefined, error: undefined };\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 { dequal } from 'dequal';\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport {\n type RequestOptions,\n toWowProblemError,\n WowProblemError,\n} from '@ahoo-wang/wow-client';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\nimport {\n initialQueryState,\n queryTransition,\n type QueryEvent,\n type QueryState,\n} from './queryTransitions.js';\n\n/**\n * `value`, or the one of an earlier render when that one has the same\n * content, so that an object rebuilt on every render keeps one identity.\n */\nfunction useContentStable<T>(value: T): T {\n const [kept, setKept] = useState(value);\n if (kept === value || dequal(kept, value)) return kept;\n setKept(value);\n return value;\n}\n\n/** Hands a callback its argument; one that throws never breaks the state. */\nasync function notify<T>(\n name: string,\n callback: ((value: T) => void | Promise<void>) | undefined,\n value: T,\n): Promise<void> {\n try {\n await callback?.(value);\n } catch (thrown) {\n // The state already shows the outcome; the host learns of its broken\n // callback without the hook swallowing it.\n // eslint-disable-next-line no-console\n console.warn(`wow-react: ${name} threw`, thrown);\n }\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof Error && error.name === 'AbortError';\n}\n\n/**\n * What a run failed with, as the hook reports it: the problem a Wow service\n * answered with when the failure carries one (a fetcher's `ExchangeError` of\n * a response that is not 2xx is read as its problem), else the error itself,\n * a value thrown that is not an `Error` wrapped in one.\n */\nasync function failureOf(thrown: unknown): Promise<Error> {\n const problem = await toWowProblemError(thrown);\n if (problem) return problem;\n return thrown instanceof Error\n ? thrown\n : new Error(String(thrown), { cause: thrown });\n}\n\n/**\n * The one request state machine every hook runs on.\n *\n * - Latest wins: every run takes a new number and aborts the one before; an\n * answer that is no longer the latest, arrives after `abort()` or\n * `reset()`, or arrives after unmount, changes nothing.\n * - A run starts on mount, whenever the query or `requestOptions` changes\n * by content, through `setQuery()`, and when `autoExecute` turns on;\n * `execute()` starts one by hand.\n * - `abort()`, `reset()` and unmount abort the request in flight.\n * - StrictMode's second mount aborts the first run and starts one more, so\n * exactly one answer lands.\n * - A failure is reported as an `Error`, and as `problem` too when a Wow\n * service answered it.\n *\n * With `retainResult` off the runner hands a run's result to `onSuccess`\n * but does not keep it as `result`: the list-stream and cursor hooks keep\n * their rows as `items` already. `execute` and the callbacks are read when a\n * run starts or settles, so a change to them never starts one.\n */\nexport function useQueryRunner<Q, R, O extends RequestOptions = RequestOptions>(\n options: QueryHookOptions<Q, R, O>,\n retainResult = true,\n): QueryHookReturn<Q, R> {\n const autoExecute = options.autoExecute ?? true;\n const query = useContentStable(options.query);\n const requestOptions = useContentStable(options.requestOptions);\n const [state, setState] = useState<QueryState<R>>(() =>\n initialQueryState(\n autoExecute && (options.query ?? options.initialQuery) !== undefined,\n ),\n );\n const latest = useRef(options);\n const current = useRef<Q | undefined>(options.query ?? options.initialQuery);\n const request = useRef<{ id: number; controller?: AbortController }>({\n id: 0,\n });\n const mounted = useRef(false);\n\n useLayoutEffect(() => {\n latest.current = options;\n });\n\n /** Applies an event unless run `id` is no longer the one that counts. */\n const settle = useCallback((id: number, event: QueryEvent<R>) => {\n if (!mounted.current || request.current.id !== id) return false;\n setState(state => queryTransition(state, event));\n return true;\n }, []);\n\n /** Stops the run in flight: no answer of it changes anything any more. */\n const cancel = useCallback(() => {\n const { controller } = request.current;\n request.current = { id: request.current.id + 1 };\n controller?.abort();\n }, []);\n\n const execute = useCallback(async () => {\n const query = current.current;\n if (!mounted.current || query === undefined) return;\n request.current.controller?.abort();\n const controller = new AbortController();\n const id = request.current.id + 1;\n request.current = { id, controller };\n setState(state => queryTransition(state, { type: 'start' }));\n const { execute, requestOptions } = latest.current;\n try {\n const result = await execute(query, {\n ...requestOptions,\n signal: controller.signal,\n } as O & { readonly signal: AbortSignal });\n if (controller.signal.aborted) {\n settle(id, { type: 'abort' });\n } else if (\n settle(id, {\n type: 'succeed',\n result: retainResult ? result : undefined,\n })\n ) {\n await notify('onSuccess', latest.current.onSuccess, result);\n }\n } catch (thrown) {\n if (controller.signal.aborted || isAbortError(thrown)) {\n settle(id, { type: 'abort' });\n return;\n }\n const error = await failureOf(thrown);\n if (settle(id, { type: 'fail', error })) {\n await notify('onError', latest.current.onError, error);\n }\n } finally {\n if (request.current.controller === controller)\n request.current = { id: request.current.id };\n }\n }, [settle, retainResult]);\n\n const abort = useCallback(() => {\n cancel();\n setState(state => queryTransition(state, { type: 'abort' }));\n }, [cancel]);\n\n const reset = useCallback(() => {\n cancel();\n setState(state => queryTransition(state, { type: 'reset' }));\n }, [cancel]);\n\n const getQuery = useCallback(() => current.current, []);\n\n const setQuery = useCallback(\n (query: Q) => {\n current.current = query;\n if (latest.current.autoExecute ?? true) void execute();\n },\n [execute],\n );\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n cancel();\n };\n }, [cancel]);\n\n const previousQuery = useRef(query);\n useEffect(() => {\n const cleared = query === undefined && previousQuery.current !== undefined;\n previousQuery.current = query;\n if (cleared) {\n // A controlled query set to `undefined` (`id ? singleQuery(…) :\n // undefined`) means nothing to run: stop, keep what was shown.\n current.current = undefined;\n abort();\n return;\n }\n if (query !== undefined) current.current = query;\n if (autoExecute) void execute();\n }, [query, requestOptions, autoExecute, execute, abort]);\n\n return {\n status: state.status,\n loading: state.status === 'loading',\n result: state.result,\n error: state.error,\n problem: state.error instanceof WowProblemError ? state.error : undefined,\n execute,\n abort,\n reset,\n getQuery,\n 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 type { AggregationQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link useAggregateQuery}: an aggregation and an `execute` that\n * resolves to its rows, as a query client's `aggregate` does.\n *\n * @template ROW - One row of the result: the groups and metrics by alias\n * @template FIELDS - The field names the aggregation may use\n * @template Q - The aggregation type: `AggregationQuery` by default\n */\nexport interface UseAggregateQueryOptions<\n ROW,\n FIELDS extends string = string,\n Q extends AggregationQuery<FIELDS, string> = AggregationQuery<FIELDS, string>,\n> extends QueryHookOptions<Q, ROW[]> {}\n\n/**\n * What {@link useAggregateQuery} returns: the rows as `result`.\n *\n * @template ROW - One row of the result\n * @template FIELDS - The field names the aggregation may use\n * @template Q - The aggregation type: `AggregationQuery` by default\n */\nexport interface UseAggregateQueryReturn<\n ROW,\n FIELDS extends string = string,\n Q extends AggregationQuery<FIELDS, string> = AggregationQuery<FIELDS, string>,\n> extends QueryHookReturn<Q, ROW[]> {}\n\n/**\n * Runs an aggregation through your own `execute` function and keeps its rows\n * as state: typically a query client's `aggregate`, one row per group.\n *\n * `execute` receives the aggregation and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The aggregation runs on mount and\n * whenever `query` or `setQuery()` changes it; set `autoExecute: false` to\n * run it only through `execute()`.\n *\n * Returns `result` (the rows, or `undefined` before the first success),\n * `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`,\n * `getQuery` and `setQuery`.\n *\n * @template ROW - One row of the result: the groups and metrics by alias\n * @template FIELDS - The field names the aggregation may use. With a client\n * whose fields are narrower than `string`, as a generated client's are,\n * pass them here: TypeScript does not infer them from `execute` once\n * `ROW` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient } from '@ahoo-wang/wow-client';\n * import { aggregation } from '@ahoo-wang/wow-client/dsl';\n * import { useAggregateQuery } from '@ahoo-wang/wow-react';\n *\n * type StatusCount = { status: string; orders: number };\n *\n * function OrdersByStatus({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { result, error } = useAggregateQuery<StatusCount, OrderFields>({\n * query: {\n * groupBy: [aggregation.terms('state.status', 'status')],\n * metrics: [aggregation.count('orders')],\n * },\n * execute: (query, options) =>\n * client.aggregate<StatusCount>(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * return <ul>{result?.map(row => <li key={row.status}>{row.status}: {row.orders}</li>)}</ul>;\n * }\n * ```\n */\nexport function useAggregateQuery<ROW, FIELDS extends string = string>(\n options: UseAggregateQueryOptions<\n ROW,\n FIELDS,\n AggregationQuery<FIELDS, string>\n >,\n): UseAggregateQueryReturn<ROW, FIELDS, AggregationQuery<FIELDS, string>>;\n/**\n * {@link useAggregateQuery} typed by an aggregation `Q` of your own, a\n * subtype of `AggregationQuery`.\n */\nexport function useAggregateQuery<\n ROW,\n FIELDS extends string = string,\n Q extends AggregationQuery<FIELDS, string> = AggregationQuery<FIELDS, string>,\n>(\n options: UseAggregateQueryOptions<ROW, FIELDS, Q>,\n): UseAggregateQueryReturn<ROW, FIELDS, Q>;\nexport function useAggregateQuery<\n ROW,\n FIELDS extends string,\n Q extends AggregationQuery<FIELDS, string>,\n>(\n options: UseAggregateQueryOptions<ROW, FIELDS, Q>,\n): UseAggregateQueryReturn<ROW, FIELDS, Q> {\n return useQueryRunner<Q, ROW[]>(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 type { CountQuery, CountResult } from '@ahoo-wang/wow-client';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link useCountQuery}: a filter and an `execute` that resolves to\n * how many rows it matches.\n *\n * @template FIELDS - The field names the filter may use\n * @template Q - The filter type: `FilterExpression` by default\n */\nexport interface UseCountQueryOptions<\n FIELDS extends string = string,\n Q extends CountQuery<FIELDS> = CountQuery<FIELDS>,\n> extends QueryHookOptions<Q, CountResult> {}\n\n/**\n * What {@link useCountQuery} returns: the count as `result`.\n *\n * @template FIELDS - The field names the filter may use\n * @template Q - The filter type: `FilterExpression` by default\n */\nexport interface UseCountQueryReturn<\n FIELDS extends string = string,\n Q extends CountQuery<FIELDS> = CountQuery<FIELDS>,\n> extends QueryHookReturn<Q, CountResult> {}\n\n/**\n * Counts what a filter matches through your own `execute` function and keeps\n * the count as state: typically a query client's `count`.\n *\n * `execute` receives the filter and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The count runs on mount and whenever\n * `query` or `setQuery()` changes the filter; set `autoExecute: false` to run\n * it only through `execute()`.\n *\n * Returns `result` (the count, or `undefined` before the first success),\n * `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`, `getQuery` and\n * `setQuery`.\n *\n * @template FIELDS - The field names the filter may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here; inferred from the first filter, they would admit only its\n * fields in `setQuery()`\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient } from '@ahoo-wang/wow-client';\n * import { filter } from '@ahoo-wang/wow-client/dsl';\n * import { useCountQuery } from '@ahoo-wang/wow-react';\n *\n * function PaidCount({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { result, error } = useCountQuery<OrderFields>({\n * initialQuery: { filter: filter.eq('state.status', 'PAID') },\n * execute: (query, options) =>\n * client.count(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * return <p>{result?.count ?? '…'} paid orders</p>;\n * }\n * ```\n */\nexport function useCountQuery<FIELDS extends string = string>(\n options: UseCountQueryOptions<FIELDS, CountQuery<FIELDS>>,\n): UseCountQueryReturn<FIELDS, CountQuery<FIELDS>>;\n/**\n * {@link useCountQuery} typed by a query `Q` of your own, a subtype of\n * `CountQuery`.\n */\nexport function useCountQuery<\n FIELDS extends string = string,\n Q extends CountQuery<FIELDS> = CountQuery<FIELDS>,\n>(options: UseCountQueryOptions<FIELDS, Q>): UseCountQueryReturn<FIELDS, Q>;\nexport function useCountQuery<\n FIELDS extends string,\n Q extends CountQuery<FIELDS>,\n>(options: UseCountQueryOptions<FIELDS, Q>): UseCountQueryReturn<FIELDS, Q> {\n return useQueryRunner<Q, CountResult>(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 type { CursorPage, CursorQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useCallback, useRef, useState } from 'react';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type {\n QueryExecutor,\n QueryHookOptions,\n QueryHookReturn,\n} from '../types.js';\n\n/**\n * Options of {@link useCursorQuery}: a cursor query without its `cursor`,\n * which the hook owns, and an `execute` that reads one page, as a query\n * client's `cursor` does.\n *\n * `onSuccess` receives each page as it arrives.\n *\n * @template R - One row of a page\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `CursorQuery` without `cursor` by default\n */\nexport interface UseCursorQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends Omit<CursorQuery<FIELDS>, 'cursor'> = Omit<\n CursorQuery<FIELDS>,\n 'cursor'\n >,\n> extends Omit<QueryHookOptions<Q, CursorPage<R>>, 'execute'> {\n /**\n * Reads one page: the query with the `cursor` of the page, `null` for\n * the first.\n */\n execute: QueryExecutor<Q & { cursor: string | null }, CursorPage<R>>;\n}\n\n/**\n * What {@link useCursorQuery} returns: the rows of every page read so far,\n * and how to read the next one.\n *\n * - `items` — the rows of the pages read so far, in order. A new query and\n * `execute()` start again from the first page with no rows; `reset()`\n * empties them; `abort()` and an error keep them.\n * - `hasMore` — whether a page follows the last one read.\n * - `fetchNext()` — reads the next page and appends its rows; it does\n * nothing while a page is loading or when no page follows. A failed\n * `fetchNext()` keeps the rows, so calling it again retries that page.\n */\nexport interface UseCursorQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends Omit<CursorQuery<FIELDS>, 'cursor'> = Omit<\n CursorQuery<FIELDS>,\n 'cursor'\n >,\n> extends Omit<QueryHookReturn<Q, CursorPage<R>>, 'result'> {\n /** The rows of every page read so far, a new array at every page. */\n items: R[];\n /** Whether a page follows the last one read. */\n hasMore: boolean;\n /** Reads the next page and appends its rows. */\n fetchNext: () => Promise<void>;\n}\n\n/** The rows read so far, and the cursor of the page after them. */\ninterface Pages<R> {\n items: R[];\n /** `undefined` before the first page, `null` after the last. */\n nextCursor: string | null | undefined;\n}\n\n/**\n * Reads a forward-only cursor query page by page and keeps the rows as\n * state: typically a query client's `cursor`, for a list that grows as the\n * reader scrolls.\n *\n * The hook owns the cursor: every run of the query starts at the first page,\n * and `fetchNext()` hands `execute` the `nextCursor` of the page before.\n * `execute` receives the request options of the run, its `signal` included;\n * hand them on so that a newer query, `abort()` or an unmount cancels the\n * request. The first page is read on mount and whenever `query` or\n * `setQuery()` changes the query; set `autoExecute: false` to read it only\n * through `execute()`.\n *\n * @template R - One row of a page\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is\n * given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { filter } from '@ahoo-wang/wow-client/dsl';\n * import { useCursorQuery } from '@ahoo-wang/wow-react';\n *\n * function PaidOrders({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { items, hasMore, loading, error, fetchNext } = useCursorQuery<Snapshot<OrderState>, OrderFields>({\n * query: { filter: filter.eq('state.status', 'PAID'), size: 50 },\n * execute: (query, options) =>\n * client.cursor(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * return (\n * <>\n * <ul>{items.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>\n * {hasMore && <button disabled={loading} onClick={() => void fetchNext()}>More</button>}\n * </>\n * );\n * }\n * ```\n */\nexport function useCursorQuery<R, FIELDS extends string = string>(\n options: UseCursorQueryOptions<\n R,\n FIELDS,\n Omit<CursorQuery<FIELDS>, 'cursor'>\n >,\n): UseCursorQueryReturn<R, FIELDS, Omit<CursorQuery<FIELDS>, 'cursor'>>;\n/**\n * {@link useCursorQuery} typed by a query `Q` of your own, a subtype of\n * `CursorQuery` without `cursor`, such as one whose literal projection\n * narrows the rows.\n */\nexport function useCursorQuery<\n R,\n FIELDS extends string = string,\n Q extends Omit<CursorQuery<FIELDS>, 'cursor'> = Omit<\n CursorQuery<FIELDS>,\n 'cursor'\n >,\n>(\n options: UseCursorQueryOptions<R, FIELDS, Q>,\n): UseCursorQueryReturn<R, FIELDS, Q>;\nexport function useCursorQuery<\n R,\n FIELDS extends string,\n Q extends Omit<CursorQuery<FIELDS>, 'cursor'>,\n>(\n options: UseCursorQueryOptions<R, FIELDS, Q>,\n): UseCursorQueryReturn<R, FIELDS, Q> {\n const [pages, setPages] = useState<Pages<R>>(noPages);\n // The cursor the next run reads from, set by fetchNext() just before it\n // starts the run; any other run (a new query, execute(), setQuery()) finds\n // none and reads the first page.\n const next = useRef<string | null>(null);\n const readPage = options.execute;\n const {\n status,\n loading,\n error,\n problem,\n execute,\n abort,\n reset,\n getQuery,\n setQuery,\n } = useQueryRunner<Q, CursorPage<R>>(\n {\n ...options,\n execute: async (query, options) => {\n const cursor = next.current;\n next.current = null;\n if (cursor === null) setPages(noPages());\n const page = await readPage({ ...query, cursor }, options);\n // A run that no longer counts was aborted by the runner: its page\n // belongs to a query the rows have moved on from.\n if (!options.signal.aborted) {\n setPages(pages => ({\n items:\n cursor === null ? [...page.list] : [...pages.items, ...page.list],\n nextCursor: page.nextCursor,\n }));\n }\n return page;\n },\n },\n false,\n );\n const hasMore = typeof pages.nextCursor === 'string';\n const fetchNext = useCallback(async () => {\n if (loading || typeof pages.nextCursor !== 'string') return;\n next.current = pages.nextCursor;\n // The runner hands the cursor to the executor before it first awaits;\n // clear it in case the run did not start (no query, unmounted).\n const run = execute();\n next.current = null;\n await run;\n }, [loading, pages.nextCursor, execute]);\n const resetPages = useCallback(() => {\n reset();\n setPages(noPages());\n }, [reset]);\n return {\n items: pages.items,\n hasMore,\n fetchNext,\n loading,\n error,\n problem,\n status,\n execute,\n abort,\n reset: resetPages,\n getQuery,\n setQuery,\n };\n}\n\nfunction noPages<R>(): Pages<R> {\n return { items: [], nextCursor: undefined };\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 type { FilterListQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link useListQuery}: a list query and an `execute` that resolves\n * to its rows.\n *\n * @template R - One row of the list\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterListQuery` by default\n */\nexport interface UseListQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n> extends QueryHookOptions<Q, R[]> {}\n\n/**\n * What {@link useListQuery} returns: the rows as `result`.\n *\n * @template R - One row of the list\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterListQuery` by default\n */\nexport interface UseListQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n> extends QueryHookReturn<Q, R[]> {}\n\n/**\n * Runs a list query through your own `execute` function and keeps the rows\n * as state: typically a query client's `list` or `listState`.\n *\n * `execute` receives the query and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The query runs on mount and whenever\n * `query` or `setQuery()` changes it; set `autoExecute: false` to run it only\n * through `execute()`.\n *\n * Returns `result` (the rows, or `undefined` before the first success),\n * `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`, `getQuery` and\n * `setQuery`.\n *\n * @template R - One row of the list\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { desc, filter, listQuery } from '@ahoo-wang/wow-client/dsl';\n * import { useListQuery } from '@ahoo-wang/wow-react';\n *\n * function LatestOrders({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { result, loading, error } = useListQuery<Snapshot<OrderState>, OrderFields>({\n * initialQuery: listQuery({\n * filter: filter.eq('state.status', 'PAID'),\n * sort: [desc('createTime')],\n * limit: 20,\n * }),\n * execute: (query, options) =>\n * client.list(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * if (loading || !result) return <p>Loading…</p>;\n * return <ul>{result.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>;\n * }\n * ```\n */\nexport function useListQuery<R, FIELDS extends string = string>(\n options: UseListQueryOptions<R, FIELDS, FilterListQuery<FIELDS>>,\n): UseListQueryReturn<R, FIELDS, FilterListQuery<FIELDS>>;\n/**\n * {@link useListQuery} typed by a query `Q` of your own, a subtype of\n * `FilterListQuery`, such as one whose literal projection narrows the result.\n */\nexport function useListQuery<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n>(options: UseListQueryOptions<R, FIELDS, Q>): UseListQueryReturn<R, FIELDS, Q>;\nexport function useListQuery<\n R,\n FIELDS extends string,\n Q extends FilterListQuery<FIELDS>,\n>(\n options: UseListQueryOptions<R, FIELDS, Q>,\n): UseListQueryReturn<R, FIELDS, Q> {\n return useQueryRunner<Q, R[]>(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 type { PagedQuery, PagedList } from '@ahoo-wang/wow-client/dsl';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link usePagedQuery}: a paged query and an `execute` that\n * resolves to one page.\n *\n * @template R - One row of the page\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterPagedQuery` by default\n */\nexport interface UsePagedQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>,\n> extends QueryHookOptions<Q, PagedList<R>> {}\n\n/**\n * What {@link usePagedQuery} returns: the page (`total` and `list`) as\n * `result`.\n *\n * @template R - One row of the page\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterPagedQuery` by default\n */\nexport interface UsePagedQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>,\n> extends QueryHookReturn<Q, PagedList<R>> {}\n\n/**\n * Runs a paged query through your own `execute` function and keeps the page\n * as state: typically a query client's `paged` or `pagedState`.\n *\n * `execute` receives the query and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The query runs on mount and whenever\n * `query` or `setQuery()` changes it — turn pages with `setQuery()`; set\n * `autoExecute: false` to run it only through `execute()`.\n *\n * Returns `result` (`{ total, list }`, or `undefined` before the first\n * success), `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`,\n * `getQuery` and `setQuery`.\n *\n * @template R - One row of the page\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { filter, pagedQuery } from '@ahoo-wang/wow-client/dsl';\n * import { usePagedQuery } from '@ahoo-wang/wow-react';\n *\n * function PaidOrders({ client, page }: { client: SnapshotQueryClient<OrderState, OrderFields>; page: number }) {\n * const { result, loading, error } = usePagedQuery<Snapshot<OrderState>, OrderFields>({\n * query: pagedQuery({\n * filter: filter.eq('state.status', 'PAID'),\n * pagination: { index: page, size: 20 },\n * }),\n * execute: (query, options) =>\n * client.paged(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * if (loading || !result) return <p>Loading…</p>;\n * return <p>{result.list.length} of {result.total}</p>;\n * }\n * ```\n */\nexport function usePagedQuery<R, FIELDS extends string = string>(\n options: UsePagedQueryOptions<R, FIELDS, PagedQuery<FIELDS>>,\n): UsePagedQueryReturn<R, FIELDS, PagedQuery<FIELDS>>;\n/**\n * {@link usePagedQuery} typed by a query `Q` of your own, a subtype of\n * `PagedQuery`, such as one whose literal projection narrows the result.\n */\nexport function usePagedQuery<\n R,\n FIELDS extends string = string,\n Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>,\n>(\n options: UsePagedQueryOptions<R, FIELDS, Q>,\n): UsePagedQueryReturn<R, FIELDS, Q>;\nexport function usePagedQuery<\n R,\n FIELDS extends string,\n Q extends PagedQuery<FIELDS>,\n>(\n options: UsePagedQueryOptions<R, FIELDS, Q>,\n): UsePagedQueryReturn<R, FIELDS, Q> {\n return useQueryRunner<Q, PagedList<R>>(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 type { FilterSingleQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link useSingleQuery}: a single query and an `execute` that\n * resolves to one item, or `undefined` when nothing matches, as a query\n * client's `single` does.\n *\n * @template R - The item the query returns\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterSingleQuery` by default\n */\nexport interface UseSingleQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>,\n> extends QueryHookOptions<Q, R | undefined> {}\n\n/**\n * What {@link useSingleQuery} returns: the item as `result`, `undefined`\n * before the first run and when nothing matched (tell them apart by\n * `status`).\n *\n * @template R - The item the query returns\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterSingleQuery` by default\n */\nexport interface UseSingleQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>,\n> extends QueryHookReturn<Q, R | undefined> {}\n\n/**\n * Runs a single query through your own `execute` function and keeps the\n * result as state: typically a query client's `single` or `singleState`.\n *\n * `execute` receives the query and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The query runs on mount and whenever\n * `query` or `setQuery()` changes it; set `autoExecute: false` to run it only\n * through `execute()`.\n *\n * Returns `result` (the item, or `undefined` before the first success),\n * `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`, `getQuery` and\n * `setQuery`.\n *\n * @template R - The item the query returns\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { filter, singleQuery } from '@ahoo-wang/wow-client/dsl';\n * import { useSingleQuery } from '@ahoo-wang/wow-react';\n *\n * function OrderStatus({ client, id }: { client: SnapshotQueryClient<OrderState, OrderFields>; id: string }) {\n * const { result, loading, error } = useSingleQuery<Snapshot<OrderState>, OrderFields>({\n * query: singleQuery({ filter: filter.id(id) }),\n * execute: (query, options) =>\n * client.single(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * if (loading) return <p>Loading…</p>;\n * if (!result) return <p>No such order.</p>;\n * return <p>{result.state.status}</p>;\n * }\n * ```\n */\nexport function useSingleQuery<R, FIELDS extends string = string>(\n options: UseSingleQueryOptions<R, FIELDS, FilterSingleQuery<FIELDS>>,\n): UseSingleQueryReturn<R, FIELDS, FilterSingleQuery<FIELDS>>;\n/**\n * {@link useSingleQuery} typed by a query `Q` of your own, a subtype of\n * `FilterSingleQuery`, such as one whose literal projection narrows the result.\n */\nexport function useSingleQuery<\n R,\n FIELDS extends string = string,\n Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>,\n>(\n options: UseSingleQueryOptions<R, FIELDS, Q>,\n): UseSingleQueryReturn<R, FIELDS, Q>;\nexport function useSingleQuery<\n R,\n FIELDS extends string,\n Q extends FilterSingleQuery<FIELDS>,\n>(\n options: UseSingleQueryOptions<R, FIELDS, Q>,\n): UseSingleQueryReturn<R, FIELDS, Q> {\n return useQueryRunner<Q, R | undefined>(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 type { Positioned } from '@ahoo-wang/wow-client';\n\n/**\n * The least time between two publishes while a stream is read: about one\n * frame, so the rows keep up with the screen while a long stream costs a\n * bounded number of renders.\n */\nexport const PUBLISH_INTERVAL_MS = 16;\n\n/**\n * Reads a stream of rows to its end and resolves to every record, in order.\n *\n * While it reads, it hands the records received so far, and the position of\n * the last row that had one, to `publish`: the first\n * rows on the next macrotask, then at most once every\n * {@link PUBLISH_INTERVAL_MS}. Publishing by time, not by network chunk,\n * bounds how often a long stream renders and copies its rows: one render per\n * interval however many chunks arrive in it, and each `publish` still gets a\n * new array. It publishes the last rows before it\n * resolves or rejects, so the rows before a failure stay visible.\n *\n * `signal` aborting cancels the stream — a fake or already-buffered body\n * does not end with the request — and stops every later `publish`: a newer\n * query or an unmount has taken over, and its rows must not be overwritten.\n * The reader is always released, so the stream never stays locked.\n *\n * Internal: not exported from the package.\n */\nexport async function readStreamRows<R>(\n stream: ReadableStream<Positioned<R>>,\n signal: AbortSignal,\n publish: (rows: R[], position: string | undefined) => void,\n): Promise<R[]> {\n const reader = stream.getReader();\n const rows: R[] = [];\n let position: string | undefined;\n let published = 0;\n let publishedAt = -Infinity;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const flush = () => {\n if (timer !== undefined) clearTimeout(timer);\n timer = undefined;\n if (signal.aborted || published === rows.length) return;\n published = rows.length;\n publishedAt = Date.now();\n publish(rows.slice(), position);\n };\n const schedule = () => {\n if (timer !== undefined) return;\n const wait = Math.max(0, publishedAt + PUBLISH_INTERVAL_MS - Date.now());\n timer = setTimeout(flush, wait);\n };\n const cancel = () => {\n reader.cancel(signal.reason).catch(() => {\n // The stream had already failed; that failure is the one reported.\n });\n };\n if (signal.aborted) cancel();\n else signal.addEventListener('abort', cancel, { once: true });\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n rows.push(value.row);\n if (value.position !== undefined) position = value.position;\n schedule();\n }\n flush();\n return rows;\n } catch (error) {\n flush();\n throw error;\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n signal.removeEventListener('abort', cancel);\n reader.releaseLock();\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 type { StreamOptions } from '@ahoo-wang/wow-client';\nimport type { FilterListQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useCallback, useState } from 'react';\nimport { readStreamRows } from '../internal/readStreamRows.js';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type {\n QueryHookOptions,\n QueryHookReturn,\n StreamExecutor,\n} from '../types.js';\n\n/**\n * Options of {@link useStreamQuery}: those of every query hook, with an\n * `execute` that opens the stream and `requestOptions` that take the\n * stream's `resume`.\n *\n * `onSuccess` receives every record once the stream has ended.\n *\n * @template R - One record of the stream\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterListQuery` by default\n */\nexport interface UseStreamQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n> extends Omit<QueryHookOptions<Q, R[], StreamOptions>, 'execute'> {\n /**\n * Opens the stream for a query: a query client's `streamRows`, which\n * answers each record with its position.\n */\n execute: StreamExecutor<R, Q>;\n}\n\n/**\n * What {@link useStreamQuery} returns: the records as they arrive, whether\n * the stream has ended, and where it stopped.\n *\n * - `items` — the records of the current query received so far, in order,\n * updated at most about once a frame (every 16 ms) while they arrive. A new\n * query starts from an empty list; `reset()` empties it; `abort()` and an\n * error keep the records received before them.\n * - `position` — the position of the last record in `items` that had one.\n * - `done` — the stream ended normally and `items` holds every record.\n * - `loading` — from the request until the stream ends, fails or is aborted.\n * - `error` — the request failed, or the server sent an error event in the\n * stream; `problem` is then the `WowProblemError`, with the problem's\n * `code`.\n * - `status` — `idle`, `loading`, `success` (the same as `done`) or `error`.\n * - `execute()` runs the current query again and aborts the stream in flight;\n * `abort()` stops the stream; `reset()` stops it and empties `items`.\n */\nexport interface UseStreamQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n> extends Omit<QueryHookReturn<Q, R[]>, 'result'> {\n /**\n * The records of the current query received so far, a new array at every\n * update.\n */\n items: R[];\n /**\n * The position of the last record received that had one, or `undefined`\n * before the first such record: hand it back as\n * `requestOptions.resume.lastEventId` to go on after it, on a later mount.\n * A new query and `reset()` clear it with `items`.\n */\n position: string | undefined;\n /** Whether the stream ended normally, so `items` holds every record. */\n done: boolean;\n}\n\n/** The records read so far, and where they stopped. */\ninterface Rows<R> {\n items: R[];\n position: string | undefined;\n}\n\n/**\n * Streams the records of a list query as server-sent events and keeps them\n * as state.\n *\n * The hook owns the stream: it reads it, collects the records into `items`,\n * and cancels it when a newer query starts, on `abort()` or `reset()`, and on\n * unmount. Components render `items` and never hold a reader, so the hook is\n * safe under StrictMode. `autoExecute` defaults to `true`.\n *\n * Pass a query client's `streamRows` as `execute`: it sends\n * `Accept: text/event-stream`, resumes a stream the server ends to be\n * resumed or that is cut off, turns error events into a `WowProblemError`,\n * and answers each record with its position, which the hook keeps as\n * `position`.\n *\n * To go on where a stream stopped after the component remounts (a page\n * change, a reload), keep `position` somewhere that outlives it and hand it\n * back as `requestOptions: { resume: { lastEventId: saved } }`; the first\n * request then asks for the records after it.\n *\n * @template R - One record of the stream\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { filter, listQuery } from '@ahoo-wang/wow-client/dsl';\n * import { useStreamQuery } from '@ahoo-wang/wow-react';\n *\n * function PaidOrders({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { items, done, loading, error, abort } = useStreamQuery<Snapshot<OrderState>, OrderFields>({\n * initialQuery: listQuery({ filter: filter.eq('state.status', 'PAID') }),\n * execute: (query, options) =>\n * client.streamRows(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * return (\n * <>\n * <ul>{items.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>\n * {loading && <button onClick={abort}>Stop</button>}\n * {done && <p>{items.length} orders</p>}\n * </>\n * );\n * }\n * ```\n */\nexport function useStreamQuery<R, FIELDS extends string = string>(\n options: UseStreamQueryOptions<R, FIELDS, FilterListQuery<FIELDS>>,\n): UseStreamQueryReturn<R, FIELDS, FilterListQuery<FIELDS>>;\n/**\n * {@link useStreamQuery} typed by a query `Q` of your own, a subtype of\n * `FilterListQuery`, such as one whose literal projection narrows the result.\n */\nexport function useStreamQuery<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n>(\n options: UseStreamQueryOptions<R, FIELDS, Q>,\n): UseStreamQueryReturn<R, FIELDS, Q>;\nexport function useStreamQuery<\n R,\n FIELDS extends string,\n Q extends FilterListQuery<FIELDS>,\n>(\n options: UseStreamQueryOptions<R, FIELDS, Q>,\n): UseStreamQueryReturn<R, FIELDS, Q> {\n // Each run starts from no records; `abort()` and an error keep the records\n // received; `reset()` empties them. The runner aborts the run's signal\n // whenever the run stops counting, and readStreamRows stops publishing\n // then, so records of a stale stream never reach `items`.\n const [rows, setRows] = useState<Rows<R>>(noRows);\n const openStream = options.execute;\n const {\n status,\n loading,\n error,\n problem,\n execute,\n abort,\n reset,\n getQuery,\n setQuery,\n } = useQueryRunner<Q, R[], StreamOptions>(\n {\n ...options,\n execute: async (query, options) => {\n setRows(noRows());\n const stream = await openStream(query, options);\n return readStreamRows(stream, options.signal, (items, position) =>\n setRows({ items, position }),\n );\n },\n },\n false,\n );\n const resetRows = useCallback(() => {\n reset();\n setRows(noRows());\n }, [reset]);\n return {\n items: rows.items,\n position: rows.position,\n done: status === 'success',\n loading,\n error,\n problem,\n status,\n execute,\n abort,\n reset: resetRows,\n getQuery,\n setQuery,\n };\n}\n\nfunction noRows<R>(): Rows<R> {\n return { items: [], position: undefined };\n}\n"],"mappings":";;;;;AAyCA,SAAgBS,kBAAqBC,GAAqC;CACxE,OAAO;EACL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.js","names":["QueryStatus","QueryState","status","result","R","error","Error","QueryEvent","type","initialQueryState","runsOnMount","undefined","queryTransition","state","event","dequal","useCallback","useEffect","useLayoutEffect","useRef","useState","RequestOptions","toWowProblemError","WowProblemError","QueryHookOptions","QueryHookReturn","initialQueryState","queryTransition","QueryEvent","QueryState","useContentStable","value","kept","setKept","notify","name","callback","T","Promise","thrown","console","warn","isAbortError","error","Error","failureOf","problem","String","cause","useQueryRunner","options","Q","R","O","retainResult","autoExecute","query","requestOptions","state","setState","initialQuery","undefined","latest","current","request","id","controller","AbortController","mounted","settle","event","cancel","abort","execute","type","result","signal","AbortSignal","aborted","onSuccess","onError","reset","getQuery","setQuery","previousQuery","cleared","status","loading","AggregationQuery","useQueryRunner","QueryHookOptions","QueryHookReturn","UseAggregateQueryOptions","FIELDS","Q","ROW","UseAggregateQueryReturn","useAggregateQuery","options","CountQuery","CountResult","useQueryRunner","QueryHookOptions","QueryHookReturn","UseCountQueryOptions","FIELDS","Q","UseCountQueryReturn","useCountQuery","options","CursorPage","CursorQuery","useCallback","useRef","useState","useQueryRunner","QueryExecutor","QueryHookOptions","QueryHookReturn","UseCursorQueryOptions","Omit","FIELDS","Q","R","execute","cursor","UseCursorQueryReturn","items","hasMore","fetchNext","Promise","Pages","nextCursor","useCursorQuery","options","pages","setPages","noPages","next","progress","runs","undefined","readPage","status","loading","error","problem","abort","reset","getQuery","setQuery","query","current","page","signal","aborted","list","run","resetPages","FilterListQuery","useQueryRunner","QueryHookOptions","QueryHookReturn","UseListQueryOptions","FIELDS","Q","R","UseListQueryReturn","useListQuery","options","PagedQuery","PagedList","useQueryRunner","QueryHookOptions","QueryHookReturn","UsePagedQueryOptions","FIELDS","Q","R","UsePagedQueryReturn","usePagedQuery","options","FilterSingleQuery","useQueryRunner","QueryHookOptions","QueryHookReturn","UseSingleQueryOptions","FIELDS","Q","R","UseSingleQueryReturn","useSingleQuery","options","Positioned","PUBLISH_INTERVAL_MS","readStreamRows","stream","ReadableStream","R","signal","AbortSignal","publish","rows","position","Promise","reader","getReader","published","publishedAt","Infinity","timer","ReturnType","setTimeout","flush","undefined","clearTimeout","aborted","length","Date","now","slice","schedule","wait","Math","max","cancel","reason","catch","addEventListener","once","done","value","read","push","row","error","removeEventListener","releaseLock","StreamOptions","FilterListQuery","useCallback","useState","readStreamRows","useQueryRunner","QueryHookOptions","QueryHookReturn","StreamExecutor","UseStreamQueryOptions","FIELDS","Omit","Q","R","execute","UseStreamQueryReturn","items","position","done","Rows","useStreamQuery","options","$","_c","rows","setRows","noRows","openStream","t0","query","options_0","stream","signal","t1","status","loading","error","problem","abort","reset","getQuery","setQuery","t2","resetRows","t3","t4","undefined","_c","runsOnMount","event","state","kept","setKept","useState","value","dequal","callback","thrown","name","error","toWowProblemError","autoExecute","options","query","requestOptions","setState","latest","useRef","current","request","mounted","settle","useCallback","id","state_0","cancel","controller","execute_0","query_0","controller_0","id_0","state_1","requestOptions_0","result","execute","retainResult","abort","state_2","reset","state_3","getQuery","setQuery","query_1","previousQuery","useEffect","cleared","WowProblemError","pages","setPages","next","progress","readPage","cursor","page","options_0","hasMore","fetchNext","runs","nextCursor","run","resetPages","reader","stream","rows","position","published","publishedAt","timer","publish","wait","signal","done","$","setRows","openStream","t1","resetRows","t3","status","t4","loading","problem"],"sources":["../src/internal/queryTransitions.ts","../src/internal/useQueryRunner.ts","../src/hooks/useAggregateQuery.ts","../src/hooks/useCountQuery.ts","../src/hooks/useCursorQuery.ts","../src/hooks/useListQuery.ts","../src/hooks/usePagedQuery.ts","../src/hooks/useSingleQuery.ts","../src/internal/readStreamRows.ts","../src/hooks/useStreamQuery.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\n/*\n * What a query hook shows, and how each event changes it: section 3 of\n * docs/design/architecture.md as pure functions, with no React. The\n * request itself (aborting it, ignoring a late answer) is useQueryRunner's.\n */\n\nimport type { QueryStatus } from '../types.js';\n\n/** What a query hook shows at one moment. */\nexport interface QueryState<R> {\n status: QueryStatus;\n result: R | undefined;\n error: Error | undefined;\n}\n\n/** Something that happens to a query hook. */\nexport type QueryEvent<R> =\n | { type: 'start' }\n | { type: 'succeed'; result: R | undefined }\n | { type: 'fail'; error: Error }\n | { type: 'abort' }\n | { type: 'reset' };\n\n/**\n * The first state. A hook that will run its query as soon as it mounts\n * starts `loading`, so the server and the first client frame already show\n * what the next frames show; any other starts `idle`.\n */\nexport function initialQueryState<R>(runsOnMount: boolean): QueryState<R> {\n return {\n status: runsOnMount ? 'loading' : 'idle',\n result: undefined,\n error: undefined,\n };\n}\n\n/**\n * The state after one event:\n *\n * - `start`: `loading`; the last result stays until the new one arrives, the\n * error goes.\n * - `succeed`: `success` with the new result (`undefined` for a hook that\n * keeps its own, as the list-stream hooks keep `items`).\n * - `fail`: `error`; the last result stays, so a failed refresh does not\n * blank what was shown.\n * - `abort`: `idle`; the last result stays, the error goes.\n * - `reset`: `idle`, with neither result nor error.\n */\nexport function queryTransition<R>(\n state: QueryState<R>,\n event: QueryEvent<R>,\n): QueryState<R> {\n switch (event.type) {\n case 'start':\n return { status: 'loading', result: state.result, error: undefined };\n case 'succeed':\n return { status: 'success', result: event.result, error: undefined };\n case 'fail':\n return { status: 'error', result: state.result, error: event.error };\n case 'abort':\n return { status: 'idle', result: state.result, error: undefined };\n case 'reset':\n return { status: 'idle', result: undefined, error: undefined };\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 { dequal } from 'dequal';\nimport {\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\nimport {\n type RequestOptions,\n toWowProblemError,\n WowProblemError,\n} from '@ahoo-wang/wow-client';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\nimport {\n initialQueryState,\n queryTransition,\n type QueryEvent,\n type QueryState,\n} from './queryTransitions.js';\n\n/**\n * `value`, or the one of an earlier render when that one has the same\n * content, so that an object rebuilt on every render keeps one identity.\n */\nfunction useContentStable<T>(value: T): T {\n const [kept, setKept] = useState(value);\n if (kept === value || dequal(kept, value)) return kept;\n setKept(value);\n return value;\n}\n\n/** Hands a callback its argument; one that throws never breaks the state. */\nasync function notify<T>(\n name: string,\n callback: ((value: T) => void | Promise<void>) | undefined,\n value: T,\n): Promise<void> {\n try {\n await callback?.(value);\n } catch (thrown) {\n // The state already shows the outcome; the host learns of its broken\n // callback without the hook swallowing it.\n // eslint-disable-next-line no-console\n console.warn(`wow-react: ${name} threw`, thrown);\n }\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof Error && error.name === 'AbortError';\n}\n\n/**\n * What a run failed with, as the hook reports it: the problem a Wow service\n * answered with when the failure carries one (a fetcher's `ExchangeError` of\n * a response that is not 2xx is read as its problem), else the error itself,\n * a value thrown that is not an `Error` wrapped in one.\n */\nasync function failureOf(thrown: unknown): Promise<Error> {\n const problem = await toWowProblemError(thrown);\n if (problem) return problem;\n return thrown instanceof Error\n ? thrown\n : new Error(String(thrown), { cause: thrown });\n}\n\n/**\n * The one request state machine every hook runs on.\n *\n * - Latest wins: every run takes a new number and aborts the one before; an\n * answer that is no longer the latest, arrives after `abort()` or\n * `reset()`, or arrives after unmount, changes nothing.\n * - A run starts on mount, whenever the query or `requestOptions` changes\n * by content, through `setQuery()`, and when `autoExecute` turns on;\n * `execute()` starts one by hand.\n * - `abort()`, `reset()` and unmount abort the request in flight.\n * - StrictMode's second mount aborts the first run and starts one more, so\n * exactly one answer lands.\n * - A failure is reported as an `Error`, and as `problem` too when a Wow\n * service answered it.\n *\n * With `retainResult` off the runner hands a run's result to `onSuccess`\n * but does not keep it as `result`: the list-stream and cursor hooks keep\n * their rows as `items` already. `execute` and the callbacks are read when a\n * run starts or settles, so a change to them never starts one.\n */\nexport function useQueryRunner<Q, R, O extends RequestOptions = RequestOptions>(\n options: QueryHookOptions<Q, R, O>,\n retainResult = true,\n): QueryHookReturn<Q, R> {\n const autoExecute = options.autoExecute ?? true;\n const query = useContentStable(options.query);\n const requestOptions = useContentStable(options.requestOptions);\n const [state, setState] = useState<QueryState<R>>(() =>\n initialQueryState(\n autoExecute && (options.query ?? options.initialQuery) !== undefined,\n ),\n );\n const latest = useRef(options);\n const current = useRef<Q | undefined>(options.query ?? options.initialQuery);\n const request = useRef<{ id: number; controller?: AbortController }>({\n id: 0,\n });\n const mounted = useRef(false);\n\n useLayoutEffect(() => {\n latest.current = options;\n });\n\n /** Applies an event unless run `id` is no longer the one that counts. */\n const settle = useCallback((id: number, event: QueryEvent<R>) => {\n if (!mounted.current || request.current.id !== id) return false;\n setState(state => queryTransition(state, event));\n return true;\n }, []);\n\n /** Stops the run in flight: no answer of it changes anything any more. */\n const cancel = useCallback(() => {\n const { controller } = request.current;\n request.current = { id: request.current.id + 1 };\n controller?.abort();\n }, []);\n\n const execute = useCallback(async () => {\n const query = current.current;\n if (!mounted.current || query === undefined) return;\n request.current.controller?.abort();\n const controller = new AbortController();\n const id = request.current.id + 1;\n request.current = { id, controller };\n setState(state => queryTransition(state, { type: 'start' }));\n const { execute, requestOptions } = latest.current;\n try {\n const result = await execute(query, {\n ...requestOptions,\n signal: controller.signal,\n } as O & { readonly signal: AbortSignal });\n if (controller.signal.aborted) {\n settle(id, { type: 'abort' });\n } else if (\n settle(id, {\n type: 'succeed',\n result: retainResult ? result : undefined,\n })\n ) {\n await notify('onSuccess', latest.current.onSuccess, result);\n }\n } catch (thrown) {\n if (controller.signal.aborted || isAbortError(thrown)) {\n settle(id, { type: 'abort' });\n return;\n }\n const error = await failureOf(thrown);\n if (settle(id, { type: 'fail', error })) {\n await notify('onError', latest.current.onError, error);\n }\n } finally {\n if (request.current.controller === controller)\n request.current = { id: request.current.id };\n }\n }, [settle, retainResult]);\n\n const abort = useCallback(() => {\n cancel();\n setState(state => queryTransition(state, { type: 'abort' }));\n }, [cancel]);\n\n const reset = useCallback(() => {\n cancel();\n setState(state => queryTransition(state, { type: 'reset' }));\n }, [cancel]);\n\n const getQuery = useCallback(() => current.current, []);\n\n const setQuery = useCallback(\n (query: Q) => {\n current.current = query;\n if (latest.current.autoExecute ?? true) void execute();\n },\n [execute],\n );\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n cancel();\n };\n }, [cancel]);\n\n const previousQuery = useRef(query);\n useEffect(() => {\n const cleared = query === undefined && previousQuery.current !== undefined;\n previousQuery.current = query;\n if (cleared) {\n // A controlled query set to `undefined` (`id ? singleQuery(…) :\n // undefined`) means nothing to run: stop, keep what was shown.\n current.current = undefined;\n abort();\n return;\n }\n if (query !== undefined) current.current = query;\n if (autoExecute) void execute();\n }, [query, requestOptions, autoExecute, execute, abort]);\n\n return {\n status: state.status,\n loading: state.status === 'loading',\n result: state.result,\n error: state.error,\n problem: state.error instanceof WowProblemError ? state.error : undefined,\n execute,\n abort,\n reset,\n getQuery,\n 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 type { AggregationQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link useAggregateQuery}: an aggregation and an `execute` that\n * resolves to its rows, as a query client's `aggregate` does.\n *\n * @template ROW - One row of the result: the groups and metrics by alias\n * @template FIELDS - The field names the aggregation may use\n * @template Q - The aggregation type: `AggregationQuery` by default\n */\nexport interface UseAggregateQueryOptions<\n ROW,\n FIELDS extends string = string,\n Q extends AggregationQuery<FIELDS, string> = AggregationQuery<FIELDS, string>,\n> extends QueryHookOptions<Q, ROW[]> {}\n\n/**\n * What {@link useAggregateQuery} returns: the rows as `result`.\n *\n * @template ROW - One row of the result\n * @template FIELDS - The field names the aggregation may use\n * @template Q - The aggregation type: `AggregationQuery` by default\n */\nexport interface UseAggregateQueryReturn<\n ROW,\n FIELDS extends string = string,\n Q extends AggregationQuery<FIELDS, string> = AggregationQuery<FIELDS, string>,\n> extends QueryHookReturn<Q, ROW[]> {}\n\n/**\n * Runs an aggregation through your own `execute` function and keeps its rows\n * as state: typically a query client's `aggregate`, one row per group.\n *\n * `execute` receives the aggregation and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The aggregation runs on mount and\n * whenever `query` or `setQuery()` changes it; set `autoExecute: false` to\n * run it only through `execute()`.\n *\n * Returns `result` (the rows, or `undefined` before the first success),\n * `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`,\n * `getQuery` and `setQuery`.\n *\n * @template ROW - One row of the result: the groups and metrics by alias\n * @template FIELDS - The field names the aggregation may use. With a client\n * whose fields are narrower than `string`, as a generated client's are,\n * pass them here: TypeScript does not infer them from `execute` once\n * `ROW` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient } from '@ahoo-wang/wow-client';\n * import { aggregation } from '@ahoo-wang/wow-client/dsl';\n * import { useAggregateQuery } from '@ahoo-wang/wow-react';\n *\n * type StatusCount = { status: string; orders: number };\n *\n * function OrdersByStatus({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { result, error } = useAggregateQuery<StatusCount, OrderFields>({\n * query: {\n * groupBy: [aggregation.terms('state.status', 'status')],\n * metrics: [aggregation.count('orders')],\n * },\n * execute: (query, options) =>\n * client.aggregate<StatusCount>(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * return <ul>{result?.map(row => <li key={row.status}>{row.status}: {row.orders}</li>)}</ul>;\n * }\n * ```\n */\nexport function useAggregateQuery<ROW, FIELDS extends string = string>(\n options: UseAggregateQueryOptions<\n ROW,\n FIELDS,\n AggregationQuery<FIELDS, string>\n >,\n): UseAggregateQueryReturn<ROW, FIELDS, AggregationQuery<FIELDS, string>>;\n/**\n * {@link useAggregateQuery} typed by an aggregation `Q` of your own, a\n * subtype of `AggregationQuery`.\n */\nexport function useAggregateQuery<\n ROW,\n FIELDS extends string = string,\n Q extends AggregationQuery<FIELDS, string> = AggregationQuery<FIELDS, string>,\n>(\n options: UseAggregateQueryOptions<ROW, FIELDS, Q>,\n): UseAggregateQueryReturn<ROW, FIELDS, Q>;\nexport function useAggregateQuery<\n ROW,\n FIELDS extends string,\n Q extends AggregationQuery<FIELDS, string>,\n>(\n options: UseAggregateQueryOptions<ROW, FIELDS, Q>,\n): UseAggregateQueryReturn<ROW, FIELDS, Q> {\n return useQueryRunner<Q, ROW[]>(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 type { CountQuery, CountResult } from '@ahoo-wang/wow-client';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link useCountQuery}: a filter and an `execute` that resolves to\n * how many rows it matches.\n *\n * @template FIELDS - The field names the filter may use\n * @template Q - The filter type: `FilterExpression` by default\n */\nexport interface UseCountQueryOptions<\n FIELDS extends string = string,\n Q extends CountQuery<FIELDS> = CountQuery<FIELDS>,\n> extends QueryHookOptions<Q, CountResult> {}\n\n/**\n * What {@link useCountQuery} returns: the count as `result`.\n *\n * @template FIELDS - The field names the filter may use\n * @template Q - The filter type: `FilterExpression` by default\n */\nexport interface UseCountQueryReturn<\n FIELDS extends string = string,\n Q extends CountQuery<FIELDS> = CountQuery<FIELDS>,\n> extends QueryHookReturn<Q, CountResult> {}\n\n/**\n * Counts what a filter matches through your own `execute` function and keeps\n * the count as state: typically a query client's `count`.\n *\n * `execute` receives the filter and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The count runs on mount and whenever\n * `query` or `setQuery()` changes the filter; set `autoExecute: false` to run\n * it only through `execute()`.\n *\n * Returns `result` (the count, or `undefined` before the first success),\n * `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`, `getQuery` and\n * `setQuery`.\n *\n * @template FIELDS - The field names the filter may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here; inferred from the first filter, they would admit only its\n * fields in `setQuery()`\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient } from '@ahoo-wang/wow-client';\n * import { filter } from '@ahoo-wang/wow-client/dsl';\n * import { useCountQuery } from '@ahoo-wang/wow-react';\n *\n * function PaidCount({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { result, error } = useCountQuery<OrderFields>({\n * initialQuery: { filter: filter.eq('state.status', 'PAID') },\n * execute: (query, options) =>\n * client.count(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * return <p>{result?.count ?? '…'} paid orders</p>;\n * }\n * ```\n */\nexport function useCountQuery<FIELDS extends string = string>(\n options: UseCountQueryOptions<FIELDS, CountQuery<FIELDS>>,\n): UseCountQueryReturn<FIELDS, CountQuery<FIELDS>>;\n/**\n * {@link useCountQuery} typed by a query `Q` of your own, a subtype of\n * `CountQuery`.\n */\nexport function useCountQuery<\n FIELDS extends string = string,\n Q extends CountQuery<FIELDS> = CountQuery<FIELDS>,\n>(options: UseCountQueryOptions<FIELDS, Q>): UseCountQueryReturn<FIELDS, Q>;\nexport function useCountQuery<\n FIELDS extends string,\n Q extends CountQuery<FIELDS>,\n>(options: UseCountQueryOptions<FIELDS, Q>): UseCountQueryReturn<FIELDS, Q> {\n return useQueryRunner<Q, CountResult>(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 type { CursorPage, CursorQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useCallback, useRef, useState } from 'react';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type {\n QueryExecutor,\n QueryHookOptions,\n QueryHookReturn,\n} from '../types.js';\n\n/**\n * Options of {@link useCursorQuery}: a cursor query without its `cursor`,\n * which the hook owns, and an `execute` that reads one page, as a query\n * client's `cursor` does.\n *\n * `onSuccess` receives each page as it arrives.\n *\n * @template R - One row of a page\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `CursorQuery` without `cursor` by default\n */\nexport interface UseCursorQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends Omit<CursorQuery<FIELDS>, 'cursor'> = Omit<\n CursorQuery<FIELDS>,\n 'cursor'\n >,\n> extends Omit<QueryHookOptions<Q, CursorPage<R>>, 'execute'> {\n /**\n * Reads one page: the query with the `cursor` of the page, `null` for\n * the first.\n */\n execute: QueryExecutor<Q & { cursor: string | null }, CursorPage<R>>;\n}\n\n/**\n * What {@link useCursorQuery} returns: the rows of every page read so far,\n * and how to read the next one.\n *\n * - `items` — the rows of the pages read so far, in order. A new query and\n * `execute()` start again from the first page with no rows; `reset()`\n * empties them; `abort()` and an error keep them.\n * - `hasMore` — whether a page follows the last one read.\n * - `fetchNext()` — reads the next page and appends its rows, from where the\n * pages stand when it is called, whichever render it came from; it does\n * nothing while a page is loading or when no page follows. A failed\n * `fetchNext()` keeps the rows, so calling it again retries that page.\n */\nexport interface UseCursorQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends Omit<CursorQuery<FIELDS>, 'cursor'> = Omit<\n CursorQuery<FIELDS>,\n 'cursor'\n >,\n> extends Omit<QueryHookReturn<Q, CursorPage<R>>, 'result'> {\n /** The rows of every page read so far, a new array at every page. */\n items: R[];\n /** Whether a page follows the last one read. */\n hasMore: boolean;\n /** Reads the next page and appends its rows. */\n fetchNext: () => Promise<void>;\n}\n\n/** The rows read so far, and the cursor of the page after them. */\ninterface Pages<R> {\n items: R[];\n /** `undefined` before the first page, `null` after the last. */\n nextCursor: string | null | undefined;\n}\n\n/**\n * Reads a forward-only cursor query page by page and keeps the rows as\n * state: typically a query client's `cursor`, for a list that grows as the\n * reader scrolls.\n *\n * The hook owns the cursor: every run of the query starts at the first page,\n * and `fetchNext()` hands `execute` the `nextCursor` of the page before.\n * `execute` receives the request options of the run, its `signal` included;\n * hand them on so that a newer query, `abort()` or an unmount cancels the\n * request. The first page is read on mount and whenever `query` or\n * `setQuery()` changes the query; set `autoExecute: false` to read it only\n * through `execute()`.\n *\n * @template R - One row of a page\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is\n * given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { filter } from '@ahoo-wang/wow-client/dsl';\n * import { useCursorQuery } from '@ahoo-wang/wow-react';\n *\n * function PaidOrders({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { items, hasMore, loading, error, fetchNext } = useCursorQuery<Snapshot<OrderState>, OrderFields>({\n * query: { filter: filter.eq('state.status', 'PAID'), size: 50 },\n * execute: (query, options) =>\n * client.cursor(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * return (\n * <>\n * <ul>{items.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>\n * {hasMore && <button disabled={loading} onClick={() => void fetchNext()}>More</button>}\n * </>\n * );\n * }\n * ```\n */\nexport function useCursorQuery<R, FIELDS extends string = string>(\n options: UseCursorQueryOptions<\n R,\n FIELDS,\n Omit<CursorQuery<FIELDS>, 'cursor'>\n >,\n): UseCursorQueryReturn<R, FIELDS, Omit<CursorQuery<FIELDS>, 'cursor'>>;\n/**\n * {@link useCursorQuery} typed by a query `Q` of your own, a subtype of\n * `CursorQuery` without `cursor`, such as one whose literal projection\n * narrows the rows.\n */\nexport function useCursorQuery<\n R,\n FIELDS extends string = string,\n Q extends Omit<CursorQuery<FIELDS>, 'cursor'> = Omit<\n CursorQuery<FIELDS>,\n 'cursor'\n >,\n>(\n options: UseCursorQueryOptions<R, FIELDS, Q>,\n): UseCursorQueryReturn<R, FIELDS, Q>;\nexport function useCursorQuery<\n R,\n FIELDS extends string,\n Q extends Omit<CursorQuery<FIELDS>, 'cursor'>,\n>(\n options: UseCursorQueryOptions<R, FIELDS, Q>,\n): UseCursorQueryReturn<R, FIELDS, Q> {\n const [pages, setPages] = useState<Pages<R>>(noPages);\n // The cursor the next run reads from, set by fetchNext() just before it\n // starts the run; any other run (a new query, execute(), setQuery()) finds\n // none and reads the first page.\n const next = useRef<string | null>(null);\n // Where the pages stand as of now, not as of a render: fetchNext() reads\n // them when it is called, so a handler that awaits one fetchNext() and\n // calls the same one again reads on from the page the first one read.\n const progress = useRef<{\n nextCursor: string | null | undefined;\n runs: number;\n }>({ nextCursor: undefined, runs: 0 });\n const readPage = options.execute;\n const {\n status,\n loading,\n error,\n problem,\n execute,\n abort,\n reset,\n getQuery,\n setQuery,\n } = useQueryRunner<Q, CursorPage<R>>(\n {\n ...options,\n execute: async (query, options) => {\n const cursor = next.current;\n next.current = null;\n if (cursor === null) {\n progress.current.nextCursor = undefined;\n setPages(noPages());\n }\n progress.current.runs++;\n try {\n const page = await readPage({ ...query, cursor }, options);\n // A run that no longer counts was aborted by the runner: its page\n // belongs to a query the rows have moved on from.\n if (!options.signal.aborted) {\n progress.current.nextCursor = page.nextCursor;\n setPages(pages => ({\n items:\n cursor === null\n ? [...page.list]\n : [...pages.items, ...page.list],\n nextCursor: page.nextCursor,\n }));\n }\n return page;\n } finally {\n progress.current.runs--;\n }\n },\n },\n false,\n );\n const hasMore = typeof pages.nextCursor === 'string';\n const fetchNext = useCallback(async () => {\n const { nextCursor, runs } = progress.current;\n if (runs > 0 || typeof nextCursor !== 'string') return;\n next.current = nextCursor;\n // The runner hands the cursor to the executor before it first awaits;\n // clear it in case the run did not start (no query, unmounted).\n const run = execute();\n next.current = null;\n await run;\n }, [execute]);\n const resetPages = useCallback(() => {\n reset();\n progress.current.nextCursor = undefined;\n setPages(noPages());\n }, [reset]);\n return {\n items: pages.items,\n hasMore,\n fetchNext,\n loading,\n error,\n problem,\n status,\n execute,\n abort,\n reset: resetPages,\n getQuery,\n setQuery,\n };\n}\n\nfunction noPages<R>(): Pages<R> {\n return { items: [], nextCursor: undefined };\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 type { FilterListQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link useListQuery}: a list query and an `execute` that resolves\n * to its rows.\n *\n * @template R - One row of the list\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterListQuery` by default\n */\nexport interface UseListQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n> extends QueryHookOptions<Q, R[]> {}\n\n/**\n * What {@link useListQuery} returns: the rows as `result`.\n *\n * @template R - One row of the list\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterListQuery` by default\n */\nexport interface UseListQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n> extends QueryHookReturn<Q, R[]> {}\n\n/**\n * Runs a list query through your own `execute` function and keeps the rows\n * as state: typically a query client's `list` or `listState`.\n *\n * `execute` receives the query and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The query runs on mount and whenever\n * `query` or `setQuery()` changes it; set `autoExecute: false` to run it only\n * through `execute()`.\n *\n * Returns `result` (the rows, or `undefined` before the first success),\n * `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`, `getQuery` and\n * `setQuery`.\n *\n * @template R - One row of the list\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { desc, filter, listQuery } from '@ahoo-wang/wow-client/dsl';\n * import { useListQuery } from '@ahoo-wang/wow-react';\n *\n * function LatestOrders({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { result, loading, error } = useListQuery<Snapshot<OrderState>, OrderFields>({\n * initialQuery: listQuery({\n * filter: filter.eq('state.status', 'PAID'),\n * sort: [desc('createTime')],\n * limit: 20,\n * }),\n * execute: (query, options) =>\n * client.list(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * if (loading || !result) return <p>Loading…</p>;\n * return <ul>{result.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>;\n * }\n * ```\n */\nexport function useListQuery<R, FIELDS extends string = string>(\n options: UseListQueryOptions<R, FIELDS, FilterListQuery<FIELDS>>,\n): UseListQueryReturn<R, FIELDS, FilterListQuery<FIELDS>>;\n/**\n * {@link useListQuery} typed by a query `Q` of your own, a subtype of\n * `FilterListQuery`, such as one whose literal projection narrows the result.\n */\nexport function useListQuery<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n>(options: UseListQueryOptions<R, FIELDS, Q>): UseListQueryReturn<R, FIELDS, Q>;\nexport function useListQuery<\n R,\n FIELDS extends string,\n Q extends FilterListQuery<FIELDS>,\n>(\n options: UseListQueryOptions<R, FIELDS, Q>,\n): UseListQueryReturn<R, FIELDS, Q> {\n return useQueryRunner<Q, R[]>(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 type { PagedQuery, PagedList } from '@ahoo-wang/wow-client/dsl';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link usePagedQuery}: a paged query and an `execute` that\n * resolves to one page.\n *\n * @template R - One row of the page\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterPagedQuery` by default\n */\nexport interface UsePagedQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>,\n> extends QueryHookOptions<Q, PagedList<R>> {}\n\n/**\n * What {@link usePagedQuery} returns: the page (`total` and `list`) as\n * `result`.\n *\n * @template R - One row of the page\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterPagedQuery` by default\n */\nexport interface UsePagedQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>,\n> extends QueryHookReturn<Q, PagedList<R>> {}\n\n/**\n * Runs a paged query through your own `execute` function and keeps the page\n * as state: typically a query client's `paged` or `pagedState`.\n *\n * `execute` receives the query and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The query runs on mount and whenever\n * `query` or `setQuery()` changes it — turn pages with `setQuery()`; set\n * `autoExecute: false` to run it only through `execute()`.\n *\n * Returns `result` (`{ total, list }`, or `undefined` before the first\n * success), `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`,\n * `getQuery` and `setQuery`.\n *\n * @template R - One row of the page\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { filter, pagedQuery } from '@ahoo-wang/wow-client/dsl';\n * import { usePagedQuery } from '@ahoo-wang/wow-react';\n *\n * function PaidOrders({ client, page }: { client: SnapshotQueryClient<OrderState, OrderFields>; page: number }) {\n * const { result, loading, error } = usePagedQuery<Snapshot<OrderState>, OrderFields>({\n * query: pagedQuery({\n * filter: filter.eq('state.status', 'PAID'),\n * pagination: { index: page, size: 20 },\n * }),\n * execute: (query, options) =>\n * client.paged(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * if (loading || !result) return <p>Loading…</p>;\n * return <p>{result.list.length} of {result.total}</p>;\n * }\n * ```\n */\nexport function usePagedQuery<R, FIELDS extends string = string>(\n options: UsePagedQueryOptions<R, FIELDS, PagedQuery<FIELDS>>,\n): UsePagedQueryReturn<R, FIELDS, PagedQuery<FIELDS>>;\n/**\n * {@link usePagedQuery} typed by a query `Q` of your own, a subtype of\n * `PagedQuery`, such as one whose literal projection narrows the result.\n */\nexport function usePagedQuery<\n R,\n FIELDS extends string = string,\n Q extends PagedQuery<FIELDS> = PagedQuery<FIELDS>,\n>(\n options: UsePagedQueryOptions<R, FIELDS, Q>,\n): UsePagedQueryReturn<R, FIELDS, Q>;\nexport function usePagedQuery<\n R,\n FIELDS extends string,\n Q extends PagedQuery<FIELDS>,\n>(\n options: UsePagedQueryOptions<R, FIELDS, Q>,\n): UsePagedQueryReturn<R, FIELDS, Q> {\n return useQueryRunner<Q, PagedList<R>>(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 type { FilterSingleQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type { QueryHookOptions, QueryHookReturn } from '../types.js';\n\n/**\n * Options of {@link useSingleQuery}: a single query and an `execute` that\n * resolves to one item, or `undefined` when nothing matches, as a query\n * client's `single` does.\n *\n * @template R - The item the query returns\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterSingleQuery` by default\n */\nexport interface UseSingleQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>,\n> extends QueryHookOptions<Q, R | undefined> {}\n\n/**\n * What {@link useSingleQuery} returns: the item as `result`, `undefined`\n * before the first run and when nothing matched (tell them apart by\n * `status`).\n *\n * @template R - The item the query returns\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterSingleQuery` by default\n */\nexport interface UseSingleQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>,\n> extends QueryHookReturn<Q, R | undefined> {}\n\n/**\n * Runs a single query through your own `execute` function and keeps the\n * result as state: typically a query client's `single` or `singleState`.\n *\n * `execute` receives the query and the request options of the run, its\n * `signal` included; hand them on so that a newer query, `abort()`\n * or an unmount cancels the request. The query runs on mount and whenever\n * `query` or `setQuery()` changes it; set `autoExecute: false` to run it only\n * through `execute()`.\n *\n * Returns `result` (the item, or `undefined` before the first success),\n * `loading`, `error`, `problem`, `status`, `execute`, `abort`, `reset`, `getQuery` and\n * `setQuery`.\n *\n * @template R - The item the query returns\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { filter, singleQuery } from '@ahoo-wang/wow-client/dsl';\n * import { useSingleQuery } from '@ahoo-wang/wow-react';\n *\n * function OrderStatus({ client, id }: { client: SnapshotQueryClient<OrderState, OrderFields>; id: string }) {\n * const { result, loading, error } = useSingleQuery<Snapshot<OrderState>, OrderFields>({\n * query: singleQuery({ filter: filter.id(id) }),\n * execute: (query, options) =>\n * client.single(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * if (loading) return <p>Loading…</p>;\n * if (!result) return <p>No such order.</p>;\n * return <p>{result.state.status}</p>;\n * }\n * ```\n */\nexport function useSingleQuery<R, FIELDS extends string = string>(\n options: UseSingleQueryOptions<R, FIELDS, FilterSingleQuery<FIELDS>>,\n): UseSingleQueryReturn<R, FIELDS, FilterSingleQuery<FIELDS>>;\n/**\n * {@link useSingleQuery} typed by a query `Q` of your own, a subtype of\n * `FilterSingleQuery`, such as one whose literal projection narrows the result.\n */\nexport function useSingleQuery<\n R,\n FIELDS extends string = string,\n Q extends FilterSingleQuery<FIELDS> = FilterSingleQuery<FIELDS>,\n>(\n options: UseSingleQueryOptions<R, FIELDS, Q>,\n): UseSingleQueryReturn<R, FIELDS, Q>;\nexport function useSingleQuery<\n R,\n FIELDS extends string,\n Q extends FilterSingleQuery<FIELDS>,\n>(\n options: UseSingleQueryOptions<R, FIELDS, Q>,\n): UseSingleQueryReturn<R, FIELDS, Q> {\n return useQueryRunner<Q, R | undefined>(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 type { Positioned } from '@ahoo-wang/wow-client';\n\n/**\n * The least time between two publishes while a stream is read: about one\n * frame, so the rows keep up with the screen while a long stream costs a\n * bounded number of renders.\n */\nexport const PUBLISH_INTERVAL_MS = 16;\n\n/**\n * Reads a stream of rows to its end and resolves to every record, in order.\n *\n * While it reads, it hands the records received so far, and the position of\n * the last row that had one, to `publish`: the first\n * rows on the next macrotask, then at most once every\n * {@link PUBLISH_INTERVAL_MS}. Publishing by time, not by network chunk,\n * bounds how often a long stream renders and copies its rows: one render per\n * interval however many chunks arrive in it, and each `publish` still gets a\n * new array. It publishes the last rows before it\n * resolves or rejects, so the rows before a failure stay visible.\n *\n * `signal` aborting cancels the stream — a fake or already-buffered body\n * does not end with the request — and stops every later `publish`: a newer\n * query or an unmount has taken over, and its rows must not be overwritten.\n * The reader is always released, so the stream never stays locked.\n *\n * Internal: not exported from the package.\n */\nexport async function readStreamRows<R>(\n stream: ReadableStream<Positioned<R>>,\n signal: AbortSignal,\n publish: (rows: R[], position: string | undefined) => void,\n): Promise<R[]> {\n const reader = stream.getReader();\n const rows: R[] = [];\n let position: string | undefined;\n let published = 0;\n let publishedAt = -Infinity;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const flush = () => {\n if (timer !== undefined) clearTimeout(timer);\n timer = undefined;\n if (signal.aborted || published === rows.length) return;\n published = rows.length;\n publishedAt = Date.now();\n publish(rows.slice(), position);\n };\n const schedule = () => {\n if (timer !== undefined) return;\n const wait = Math.max(0, publishedAt + PUBLISH_INTERVAL_MS - Date.now());\n timer = setTimeout(flush, wait);\n };\n const cancel = () => {\n reader.cancel(signal.reason).catch(() => {\n // The stream had already failed; that failure is the one reported.\n });\n };\n if (signal.aborted) cancel();\n else signal.addEventListener('abort', cancel, { once: true });\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n rows.push(value.row);\n if (value.position !== undefined) position = value.position;\n schedule();\n }\n flush();\n return rows;\n } catch (error) {\n flush();\n throw error;\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n signal.removeEventListener('abort', cancel);\n reader.releaseLock();\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 type { StreamOptions } from '@ahoo-wang/wow-client';\nimport type { FilterListQuery } from '@ahoo-wang/wow-client/dsl';\nimport { useCallback, useState } from 'react';\nimport { readStreamRows } from '../internal/readStreamRows.js';\nimport { useQueryRunner } from '../internal/useQueryRunner.js';\nimport type {\n QueryHookOptions,\n QueryHookReturn,\n StreamExecutor,\n} from '../types.js';\n\n/**\n * Options of {@link useStreamQuery}: those of every query hook, with an\n * `execute` that opens the stream and `requestOptions` that take the\n * stream's `resume`.\n *\n * `onSuccess` receives every record once the stream has ended.\n *\n * @template R - One record of the stream\n * @template FIELDS - The field names the query may use\n * @template Q - The query type: `FilterListQuery` by default\n */\nexport interface UseStreamQueryOptions<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n> extends Omit<QueryHookOptions<Q, R[], StreamOptions>, 'execute'> {\n /**\n * Opens the stream for a query: a query client's `streamRows`, which\n * answers each record with its position.\n */\n execute: StreamExecutor<R, Q>;\n}\n\n/**\n * What {@link useStreamQuery} returns: the records as they arrive, whether\n * the stream has ended, and where it stopped.\n *\n * - `items` — the records of the current query received so far, in order,\n * updated at most about once a frame (every 16 ms) while they arrive. A new\n * query starts from an empty list; `reset()` empties it; `abort()` and an\n * error keep the records received before them.\n * - `position` — the position of the last record in `items` that had one.\n * - `done` — the stream ended normally and `items` holds every record.\n * - `loading` — from the request until the stream ends, fails or is aborted.\n * - `error` — the request failed, or the server sent an error event in the\n * stream; `problem` is then the `WowProblemError`, with the problem's\n * `code`.\n * - `status` — `idle`, `loading`, `success` (the same as `done`) or `error`.\n * - `execute()` runs the current query again and aborts the stream in flight;\n * `abort()` stops the stream; `reset()` stops it and empties `items`.\n */\nexport interface UseStreamQueryReturn<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n> extends Omit<QueryHookReturn<Q, R[]>, 'result'> {\n /**\n * The records of the current query received so far, a new array at every\n * update.\n */\n items: R[];\n /**\n * The position of the last record received that had one, or `undefined`\n * before the first such record: hand it back as\n * `requestOptions.resume.lastEventId` to go on after it, on a later mount.\n * A new query and `reset()` clear it with `items`.\n */\n position: string | undefined;\n /** Whether the stream ended normally, so `items` holds every record. */\n done: boolean;\n}\n\n/** The records read so far, and where they stopped. */\ninterface Rows<R> {\n items: R[];\n position: string | undefined;\n}\n\n/**\n * Streams the records of a list query as server-sent events and keeps them\n * as state.\n *\n * The hook owns the stream: it reads it, collects the records into `items`,\n * and cancels it when a newer query starts, on `abort()` or `reset()`, and on\n * unmount. Components render `items` and never hold a reader, so the hook is\n * safe under StrictMode. `autoExecute` defaults to `true`.\n *\n * Pass a query client's `streamRows` as `execute`: it sends\n * `Accept: text/event-stream`, resumes a stream the server ends to be\n * resumed or that is cut off, turns error events into a `WowProblemError`,\n * and answers each record with its position, which the hook keeps as\n * `position`.\n *\n * To go on where a stream stopped after the component remounts (a page\n * change, a reload), keep `position` somewhere that outlives it and hand it\n * back as `requestOptions: { resume: { lastEventId: saved } }`; the first\n * request then asks for the records after it.\n *\n * @template R - One record of the stream\n * @template FIELDS - The field names the query may use. With a client whose\n * fields are narrower than `string`, as a generated client's are, pass\n * them here: TypeScript does not infer them from `execute` once `R` is given\n *\n * @example\n * ```tsx\n * import type { SnapshotQueryClient, Snapshot } from '@ahoo-wang/wow-client';\n * import { filter, listQuery } from '@ahoo-wang/wow-client/dsl';\n * import { useStreamQuery } from '@ahoo-wang/wow-react';\n *\n * function PaidOrders({ client }: { client: SnapshotQueryClient<OrderState, OrderFields> }) {\n * const { items, done, loading, error, abort } = useStreamQuery<Snapshot<OrderState>, OrderFields>({\n * initialQuery: listQuery({ filter: filter.eq('state.status', 'PAID') }),\n * execute: (query, options) =>\n * client.streamRows(query, options),\n * });\n * if (error) return <p role=\"alert\">{error.message}</p>;\n * return (\n * <>\n * <ul>{items.map(order => <li key={order.aggregateId}>{order.state.status}</li>)}</ul>\n * {loading && <button onClick={abort}>Stop</button>}\n * {done && <p>{items.length} orders</p>}\n * </>\n * );\n * }\n * ```\n */\nexport function useStreamQuery<R, FIELDS extends string = string>(\n options: UseStreamQueryOptions<R, FIELDS, FilterListQuery<FIELDS>>,\n): UseStreamQueryReturn<R, FIELDS, FilterListQuery<FIELDS>>;\n/**\n * {@link useStreamQuery} typed by a query `Q` of your own, a subtype of\n * `FilterListQuery`, such as one whose literal projection narrows the result.\n */\nexport function useStreamQuery<\n R,\n FIELDS extends string = string,\n Q extends FilterListQuery<FIELDS> = FilterListQuery<FIELDS>,\n>(\n options: UseStreamQueryOptions<R, FIELDS, Q>,\n): UseStreamQueryReturn<R, FIELDS, Q>;\nexport function useStreamQuery<\n R,\n FIELDS extends string,\n Q extends FilterListQuery<FIELDS>,\n>(\n options: UseStreamQueryOptions<R, FIELDS, Q>,\n): UseStreamQueryReturn<R, FIELDS, Q> {\n // Each run starts from no records; `abort()` and an error keep the records\n // received; `reset()` empties them. The runner aborts the run's signal\n // whenever the run stops counting, and readStreamRows stops publishing\n // then, so records of a stale stream never reach `items`.\n const [rows, setRows] = useState<Rows<R>>(noRows);\n const openStream = options.execute;\n const {\n status,\n loading,\n error,\n problem,\n execute,\n abort,\n reset,\n getQuery,\n setQuery,\n } = useQueryRunner<Q, R[], StreamOptions>(\n {\n ...options,\n execute: async (query, options) => {\n setRows(noRows());\n const stream = await openStream(query, options);\n return readStreamRows(stream, options.signal, (items, position) =>\n setRows({ items, position }),\n );\n },\n },\n false,\n );\n const resetRows = useCallback(() => {\n reset();\n setRows(noRows());\n }, [reset]);\n return {\n items: rows.items,\n position: rows.position,\n done: status === 'success',\n loading,\n error,\n problem,\n status,\n execute,\n abort,\n reset: resetRows,\n getQuery,\n setQuery,\n };\n}\n\nfun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AR,GAAAQ,EAAA,MAAAkB,GAAAlB,EAAA,MAAAa,GAAAb,EAAA,MAAAe,GAAAf,EAAA,MAAAqB,GAAArB,EAAA,MAAAE,EAAAR,OAAAM,EAAA,MAAAE,EAAAP,UAAAK,EAAA,MAAAmB,GAAAnB,EAAA,MAAAY,GAAAZ,EAAA,MAAAsB,GAAAtB,EAAA,MAAAuB,KAAAA,IAAAvB,EAAA,KAbMuB;AAaN;AAGH,SAASnB,SAAqB;CAC5B,OAAO;EAAEV,OAAO,CAAA;EAAIC,UAAU6B,KAAAA;CAAU;AAC1C"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ahoo-wang/wow-react",
3
- "version": "10.0.0-alpha.7",
4
- "description": "React hooks for Wow (https://github.com/Ahoo-Wang/Wow) queries: single, list, paged, count and list-stream. Requires React 19.3 or later.",
3
+ "version": "10.0.0-beta.2",
4
+ "description": "React hooks for Wow (https://github.com/Ahoo-Wang/Wow) queries: single, list, paged, count and list-stream. Requires React 19 or later.",
5
5
  "keywords": [
6
6
  "wow",
7
7
  "wow-react",
@@ -48,31 +48,31 @@
48
48
  },
49
49
  "peerDependencies": {
50
50
  "react": "^19.0.0",
51
- "@ahoo-wang/wow-client": "~10.0.0-alpha.7"
51
+ "@ahoo-wang/wow-client": "~10.0.0-beta.2"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@ahoo-wang/fetcher": "^6.0.1",
55
55
  "@eslint/js": "^10.0.1",
56
- "@microsoft/api-extractor": "^7.59.4",
57
- "@rolldown/plugin-babel": "^0.2.4",
56
+ "@microsoft/api-extractor": "^7.60.1",
57
+ "@rolldown/plugin-babel": "^0.3.0",
58
58
  "@testing-library/react": "^16.3.3",
59
59
  "@types/react": "^19.3.0",
60
60
  "@types/react-dom": "^19.3.0",
61
61
  "@vitejs/plugin-react": "6.1.2",
62
62
  "@vitest/coverage-v8": "4.1.12",
63
63
  "babel-plugin-react-compiler": "1.0.0",
64
- "eslint": "^10.13.0",
64
+ "eslint": "^10.14.0",
65
65
  "eslint-plugin-react-hooks": "^7.1.1",
66
66
  "globals": "^17.13.0",
67
67
  "jsdom": "^30.1.3",
68
68
  "react": "^19.3.1",
69
69
  "react-dom": "^19.3.1",
70
70
  "typescript": "~6.0.3",
71
- "typescript-eslint": "^8.72.0",
71
+ "typescript-eslint": "^8.72.1",
72
72
  "unplugin-dts": "1.1.2",
73
73
  "vite": "8.3.5",
74
74
  "vitest": "^4.1.12",
75
- "@ahoo-wang/wow-client": "~10.0.0-alpha.7"
75
+ "@ahoo-wang/wow-client": "~10.0.0-beta.2"
76
76
  },
77
77
  "scripts": {
78
78
  "build": "vite build && pnpm test:package",