@tanstack/query-core 5.103.1 → 5.103.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/{classPrivateFieldSet2-CV7wyte-.js → classPrivateFieldSet2-CukOTU3U.js} +5 -5
- package/build/legacy/{classPrivateFieldSet2-Bo0ZyOIv.cjs → classPrivateFieldSet2-CvCEk6bM.cjs} +5 -5
- package/build/legacy/{classPrivateMethodInitSpec-CBwa_Y7C.js → classPrivateMethodInitSpec-CgB-WYk3.js} +2 -2
- package/build/legacy/{classPrivateMethodInitSpec-DVhcLejn.cjs → classPrivateMethodInitSpec-Nr6mgZRs.cjs} +2 -2
- package/build/legacy/focusManager.cjs +1 -1
- package/build/legacy/focusManager.d.cts +1 -1
- package/build/legacy/focusManager.d.ts +1 -1
- package/build/legacy/focusManager.js +1 -1
- package/build/legacy/{hydration-DwR10Hi-.d.cts → hydration-B9t5w6NC.d.ts} +167 -25
- package/build/legacy/hydration-B9t5w6NC.d.ts.map +1 -0
- package/build/legacy/{hydration-Cq7QYAzB.d.ts → hydration-Br9VIGXa.d.cts} +167 -25
- package/build/legacy/hydration-Br9VIGXa.d.cts.map +1 -0
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +2 -2
- package/build/legacy/infiniteQueryObserver.d.ts +2 -2
- package/build/legacy/mutation.cjs +2 -2
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutation.js +2 -2
- package/build/legacy/mutationCache.cjs +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationCache.js +1 -1
- package/build/legacy/mutationObserver.cjs +2 -2
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/mutationObserver.js +2 -2
- package/build/legacy/onlineManager.cjs +1 -1
- package/build/legacy/onlineManager.d.cts +1 -1
- package/build/legacy/onlineManager.d.ts +1 -1
- package/build/legacy/onlineManager.js +1 -1
- package/build/legacy/queriesObserver.cjs +2 -2
- package/build/legacy/queriesObserver.d.cts +2 -2
- package/build/legacy/queriesObserver.d.cts.map +1 -1
- package/build/legacy/queriesObserver.d.ts +2 -2
- package/build/legacy/queriesObserver.d.ts.map +1 -1
- package/build/legacy/queriesObserver.js +2 -2
- package/build/legacy/query.cjs +2 -2
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/query.js +2 -2
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +3 -4
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryCache.js +3 -4
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +8 -1
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +8 -1
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +2 -2
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +2 -2
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/removable-0GzhW1PK.d.cts +22 -0
- package/build/legacy/removable-0GzhW1PK.d.cts.map +1 -0
- package/build/legacy/removable-0GzhW1PK.d.ts +22 -0
- package/build/legacy/removable-0GzhW1PK.d.ts.map +1 -0
- package/build/legacy/removable.cjs +10 -1
- package/build/legacy/removable.cjs.map +1 -1
- package/build/legacy/removable.d.cts +1 -1
- package/build/legacy/removable.d.ts +1 -1
- package/build/legacy/removable.js +10 -1
- package/build/legacy/removable.js.map +1 -1
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +0 -7
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +1 -8
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +1 -8
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +0 -7
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/subscribable-CysQ0tne.d.cts +34 -0
- package/build/legacy/subscribable-CysQ0tne.d.cts.map +1 -0
- package/build/legacy/subscribable-CysQ0tne.d.ts +34 -0
- package/build/legacy/subscribable-CysQ0tne.d.ts.map +1 -0
- package/build/legacy/subscribable.cjs +22 -0
- package/build/legacy/subscribable.cjs.map +1 -1
- package/build/legacy/subscribable.d.cts +1 -1
- package/build/legacy/subscribable.d.ts +1 -1
- package/build/legacy/subscribable.js +22 -0
- package/build/legacy/subscribable.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +1 -1
- package/build/legacy/timeoutManager.js +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +1 -1
- package/build/modern/focusManager.d.ts +1 -1
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/{hydration-DwR10Hi-.d.cts → hydration-B9t5w6NC.d.ts} +167 -25
- package/build/modern/hydration-B9t5w6NC.d.ts.map +1 -0
- package/build/modern/{hydration-Cq7QYAzB.d.ts → hydration-Br9VIGXa.d.cts} +167 -25
- package/build/modern/hydration-Br9VIGXa.d.cts.map +1 -0
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +2 -2
- package/build/modern/infiniteQueryObserver.d.ts +2 -2
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +1 -1
- package/build/modern/onlineManager.d.ts +1 -1
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +2 -2
- package/build/modern/queriesObserver.d.cts.map +1 -1
- package/build/modern/queriesObserver.d.ts +2 -2
- package/build/modern/queriesObserver.d.ts.map +1 -1
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +2 -3
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryCache.js +2 -3
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +7 -0
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +7 -0
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/removable-0GzhW1PK.d.cts +22 -0
- package/build/modern/removable-0GzhW1PK.d.cts.map +1 -0
- package/build/modern/removable-0GzhW1PK.d.ts +22 -0
- package/build/modern/removable-0GzhW1PK.d.ts.map +1 -0
- package/build/modern/removable.cjs +9 -0
- package/build/modern/removable.cjs.map +1 -1
- package/build/modern/removable.d.cts +1 -1
- package/build/modern/removable.d.ts +1 -1
- package/build/modern/removable.js +9 -0
- package/build/modern/removable.js.map +1 -1
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +0 -7
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +1 -8
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +1 -8
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +0 -7
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/subscribable-CysQ0tne.d.cts +34 -0
- package/build/modern/subscribable-CysQ0tne.d.cts.map +1 -0
- package/build/modern/subscribable-CysQ0tne.d.ts +34 -0
- package/build/modern/subscribable-CysQ0tne.d.ts.map +1 -0
- package/build/modern/subscribable.cjs +22 -0
- package/build/modern/subscribable.cjs.map +1 -1
- package/build/modern/subscribable.d.cts +1 -1
- package/build/modern/subscribable.d.ts +1 -1
- package/build/modern/subscribable.js +22 -0
- package/build/modern/subscribable.js.map +1 -1
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/hydration.ts +1 -0
- package/src/query.ts +1 -2
- package/src/queryCache.ts +3 -8
- package/src/queryClient.ts +7 -0
- package/src/queryObserver.ts +4 -8
- package/src/removable.ts +9 -0
- package/src/retryer.ts +4 -0
- package/src/streamedQuery.ts +0 -7
- package/src/subscribable.ts +22 -0
- package/src/types.ts +159 -35
- package/src/utils.ts +1 -1
- package/build/legacy/hydration-Cq7QYAzB.d.ts.map +0 -1
- package/build/legacy/hydration-DwR10Hi-.d.cts.map +0 -1
- package/build/legacy/removable-DeMjhW5M.d.cts +0 -13
- package/build/legacy/removable-DeMjhW5M.d.cts.map +0 -1
- package/build/legacy/removable-DeMjhW5M.d.ts +0 -13
- package/build/legacy/removable-DeMjhW5M.d.ts.map +0 -1
- package/build/legacy/subscribable-CbifVTKz.d.cts +0 -12
- package/build/legacy/subscribable-CbifVTKz.d.cts.map +0 -1
- package/build/legacy/subscribable-CbifVTKz.d.ts +0 -12
- package/build/legacy/subscribable-CbifVTKz.d.ts.map +0 -1
- package/build/modern/hydration-Cq7QYAzB.d.ts.map +0 -1
- package/build/modern/hydration-DwR10Hi-.d.cts.map +0 -1
- package/build/modern/removable-DeMjhW5M.d.cts +0 -13
- package/build/modern/removable-DeMjhW5M.d.cts.map +0 -1
- package/build/modern/removable-DeMjhW5M.d.ts +0 -13
- package/build/modern/removable-DeMjhW5M.d.ts.map +0 -1
- package/build/modern/subscribable-CbifVTKz.d.cts +0 -12
- package/build/modern/subscribable-CbifVTKz.d.cts.map +0 -1
- package/build/modern/subscribable-CbifVTKz.d.ts +0 -12
- package/build/modern/subscribable-CbifVTKz.d.ts.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as CancelledError, an as isCancelledError, en as RetryDelayValue, in as createRetryer, nn as Retryer, rn as canFetch, tn as RetryValue } from "./hydration-
|
|
1
|
+
import { $t as CancelledError, an as isCancelledError, en as RetryDelayValue, in as createRetryer, nn as Retryer, rn as canFetch, tn as RetryValue } from "./hydration-Br9VIGXa.cjs";
|
|
2
2
|
export { CancelledError, RetryDelayValue, RetryValue, Retryer, canFetch, createRetryer, isCancelledError };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as CancelledError, an as isCancelledError, en as RetryDelayValue, in as createRetryer, nn as Retryer, rn as canFetch, tn as RetryValue } from "./hydration-
|
|
1
|
+
import { $t as CancelledError, an as isCancelledError, en as RetryDelayValue, in as createRetryer, nn as Retryer, rn as canFetch, tn as RetryValue } from "./hydration-B9t5w6NC.js";
|
|
2
2
|
export { CancelledError, RetryDelayValue, RetryValue, Retryer, canFetch, createRetryer, isCancelledError };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryer.js","names":["isServerEnvironment"],"sources":["../../src/retryer.ts"],"sourcesContent":["import { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { isServer as isServerEnvironment } from './environmentManager'\nimport { noop, sleep } from './utils'\nimport type { CancelOptions, DefaultError, NetworkMode } from './types'\n\n// TYPES\n\ninterface RetryerConfig<TData = unknown, TError = DefaultError> {\n fn: () => TData | Promise<TData>\n initialPromise?: Promise<TData>\n onCancel?: (error: TError) => void\n onFail?: (failureCount: number, error: TError) => void\n onPause?: () => void\n onContinue?: () => void\n retry?: RetryValue<TError>\n retryDelay?: RetryDelayValue<TError>\n networkMode: NetworkMode | undefined\n canRun: () => boolean\n}\n\nexport interface Retryer<TData = unknown> {\n promise: Promise<TData>\n cancel: (cancelOptions?: CancelOptions) => void\n continue: () => Promise<unknown>\n cancelRetry: () => void\n continueRetry: () => void\n canStart: () => boolean\n start: () => Promise<TData>\n status: () => 'pending' | 'resolved' | 'rejected'\n}\n\ntype RetryerStatus = 'pending' | 'resolved' | 'rejected'\n\nexport type RetryValue<TError> = boolean | number | ShouldRetryFunction<TError>\n\ntype ShouldRetryFunction<TError = DefaultError> = (\n failureCount: number,\n error: TError,\n) => boolean\n\nexport type RetryDelayValue<TError> = number | RetryDelayFunction<TError>\n\ntype RetryDelayFunction<TError = DefaultError> = (\n failureCount: number,\n error: TError,\n) => number\n\nfunction defaultRetryDelay(failureCount: number) {\n return Math.min(1000 * 2 ** failureCount, 30000)\n}\n\nexport function canFetch(networkMode: NetworkMode | undefined): boolean {\n return (networkMode ?? 'online') === 'online'\n ? onlineManager.isOnline()\n : true\n}\n\n/**\n * The error thrown by a `Retryer` (and surfaced to `query.promise`/`mutation`) when a fetch is cancelled, e.g. via\n * `query.cancel()`. `revert`, if `true`, tells the caller to restore the state the query was in before the fetch\n * started instead of surfacing the error. `silent`, if `true`, tells the caller to suppress this error and instead\n * resolve with the promise of the fetch that triggered the cancellation.\n * @example\n * ```ts\n * query.cancel()\n *\n * try {\n * await query.promise\n * } catch (error) {\n * if (error instanceof CancelledError) {\n * // the fetch was cancelled, e.g. via `query.cancel()`\n * }\n * }\n * ```\n */\nexport class CancelledError extends Error {\n revert?: boolean\n silent?: boolean\n constructor(options?: CancelOptions) {\n super('CancelledError')\n this.revert = options?.revert\n this.silent = options?.silent\n }\n}\n\n/**\n * @deprecated Use instanceof `CancelledError` instead.\n */\nexport function isCancelledError(value: any): value is CancelledError {\n return value instanceof CancelledError\n}\n\nexport function createRetryer<TData = unknown, TError = DefaultError>(\n config: RetryerConfig<TData, TError>,\n): Retryer<TData> {\n let isRetryCancelled = false\n let failureCount = 0\n let continueFn: ((value?: unknown) => void) | undefined\n let status: RetryerStatus = 'pending'\n let promiseResolve: (data: TData) => void\n let promiseReject: (error: TError) => void\n\n const promise = new Promise<TData>((resolve, reject) => {\n promiseResolve = resolve\n promiseReject = reject\n })\n promise.catch(noop)\n\n const isResolved = () => status !== 'pending'\n\n const cancel = (cancelOptions?: CancelOptions): void => {\n if (!isResolved()) {\n const error = new CancelledError(cancelOptions) as TError\n reject(error)\n\n config.onCancel?.(error)\n }\n }\n const cancelRetry = () => {\n isRetryCancelled = true\n }\n\n const continueRetry = () => {\n isRetryCancelled = false\n }\n\n const canContinue = () =>\n focusManager.isFocused() &&\n (config.networkMode === 'always' || onlineManager.isOnline()) &&\n config.canRun()\n\n const canStart = () => canFetch(config.networkMode) && config.canRun()\n\n const resolve = (value: any) => {\n if (!isResolved()) {\n continueFn?.()\n status = 'resolved'\n promiseResolve(value)\n }\n }\n\n const reject = (value: any) => {\n if (!isResolved()) {\n continueFn?.()\n status = 'rejected'\n promiseReject(value)\n }\n }\n\n const pause = () => {\n return new Promise((continueResolve) => {\n continueFn = (value) => {\n if (isResolved() || canContinue()) {\n continueResolve(value)\n }\n }\n config.onPause?.()\n }).then(() => {\n continueFn = undefined\n if (!isResolved()) {\n config.onContinue?.()\n }\n })\n }\n\n // Create loop function\n const run = () => {\n // Do nothing if already resolved\n if (isResolved()) {\n return\n }\n\n let promiseOrValue: any\n\n // we can re-use config.initialPromise on the first call of run()\n const initialPromise =\n failureCount === 0 ? config.initialPromise : undefined\n\n // Execute query\n try {\n promiseOrValue = initialPromise ?? config.fn()\n } catch (error) {\n promiseOrValue = Promise.reject(error)\n }\n\n Promise.resolve(promiseOrValue)\n .then(resolve)\n .catch((error) => {\n // Stop if the fetch is already resolved\n if (isResolved()) {\n return\n }\n\n // Do we need to retry the request?\n const retry = config.retry ?? (isServerEnvironment() ? 0 : 3)\n const retryDelay = config.retryDelay ?? defaultRetryDelay\n const delay =\n typeof retryDelay === 'function'\n ? retryDelay(failureCount, error)\n : retryDelay\n const shouldRetry =\n retry === true ||\n (typeof retry === 'number' && failureCount < retry) ||\n (typeof retry === 'function' && retry(failureCount, error))\n\n if (isRetryCancelled || !shouldRetry) {\n // We are done if the query does not need to be retried\n reject(error)\n return\n }\n\n failureCount++\n\n // Notify on fail\n config.onFail?.(failureCount, error)\n\n // Delay\n sleep(delay)\n // Pause if the document is not visible or when the device is offline\n .then(() => {\n return canContinue() ? undefined : pause()\n })\n .then(() => {\n if (isRetryCancelled) {\n reject(error)\n } else {\n run()\n }\n })\n })\n }\n\n return {\n promise,\n status: () => status,\n cancel,\n continue: () => {\n continueFn?.()\n return promise\n },\n cancelRetry,\n continueRetry,\n canStart,\n start: () => {\n // Start loop\n if (canStart()) {\n run()\n } else {\n pause().then(run)\n }\n return promise\n },\n }\n}\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"retryer.js","names":["isServerEnvironment"],"sources":["../../src/retryer.ts"],"sourcesContent":["import { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { isServer as isServerEnvironment } from './environmentManager'\nimport { noop, sleep } from './utils'\nimport type { CancelOptions, DefaultError, NetworkMode } from './types'\n\n// TYPES\n\ninterface RetryerConfig<TData = unknown, TError = DefaultError> {\n fn: () => TData | Promise<TData>\n initialPromise?: Promise<TData>\n onCancel?: (error: TError) => void\n onFail?: (failureCount: number, error: TError) => void\n onPause?: () => void\n onContinue?: () => void\n retry?: RetryValue<TError>\n retryDelay?: RetryDelayValue<TError>\n networkMode: NetworkMode | undefined\n canRun: () => boolean\n}\n\nexport interface Retryer<TData = unknown> {\n promise: Promise<TData>\n cancel: (cancelOptions?: CancelOptions) => void\n continue: () => Promise<unknown>\n cancelRetry: () => void\n continueRetry: () => void\n canStart: () => boolean\n start: () => Promise<TData>\n status: () => 'pending' | 'resolved' | 'rejected'\n}\n\ntype RetryerStatus = 'pending' | 'resolved' | 'rejected'\n\n/** @inline */\nexport type RetryValue<TError> = boolean | number | ShouldRetryFunction<TError>\n\n/** @inline */\ntype ShouldRetryFunction<TError = DefaultError> = (\n failureCount: number,\n error: TError,\n) => boolean\n\n/** @inline */\nexport type RetryDelayValue<TError> = number | RetryDelayFunction<TError>\n\n/** @inline */\ntype RetryDelayFunction<TError = DefaultError> = (\n failureCount: number,\n error: TError,\n) => number\n\nfunction defaultRetryDelay(failureCount: number) {\n return Math.min(1000 * 2 ** failureCount, 30000)\n}\n\nexport function canFetch(networkMode: NetworkMode | undefined): boolean {\n return (networkMode ?? 'online') === 'online'\n ? onlineManager.isOnline()\n : true\n}\n\n/**\n * The error thrown by a `Retryer` (and surfaced to `query.promise`/`mutation`) when a fetch is cancelled, e.g. via\n * `query.cancel()`. `revert`, if `true`, tells the caller to restore the state the query was in before the fetch\n * started instead of surfacing the error. `silent`, if `true`, tells the caller to suppress this error and instead\n * resolve with the promise of the fetch that triggered the cancellation.\n * @example\n * ```ts\n * query.cancel()\n *\n * try {\n * await query.promise\n * } catch (error) {\n * if (error instanceof CancelledError) {\n * // the fetch was cancelled, e.g. via `query.cancel()`\n * }\n * }\n * ```\n */\nexport class CancelledError extends Error {\n revert?: boolean\n silent?: boolean\n constructor(options?: CancelOptions) {\n super('CancelledError')\n this.revert = options?.revert\n this.silent = options?.silent\n }\n}\n\n/**\n * @deprecated Use instanceof `CancelledError` instead.\n */\nexport function isCancelledError(value: any): value is CancelledError {\n return value instanceof CancelledError\n}\n\nexport function createRetryer<TData = unknown, TError = DefaultError>(\n config: RetryerConfig<TData, TError>,\n): Retryer<TData> {\n let isRetryCancelled = false\n let failureCount = 0\n let continueFn: ((value?: unknown) => void) | undefined\n let status: RetryerStatus = 'pending'\n let promiseResolve: (data: TData) => void\n let promiseReject: (error: TError) => void\n\n const promise = new Promise<TData>((resolve, reject) => {\n promiseResolve = resolve\n promiseReject = reject\n })\n promise.catch(noop)\n\n const isResolved = () => status !== 'pending'\n\n const cancel = (cancelOptions?: CancelOptions): void => {\n if (!isResolved()) {\n const error = new CancelledError(cancelOptions) as TError\n reject(error)\n\n config.onCancel?.(error)\n }\n }\n const cancelRetry = () => {\n isRetryCancelled = true\n }\n\n const continueRetry = () => {\n isRetryCancelled = false\n }\n\n const canContinue = () =>\n focusManager.isFocused() &&\n (config.networkMode === 'always' || onlineManager.isOnline()) &&\n config.canRun()\n\n const canStart = () => canFetch(config.networkMode) && config.canRun()\n\n const resolve = (value: any) => {\n if (!isResolved()) {\n continueFn?.()\n status = 'resolved'\n promiseResolve(value)\n }\n }\n\n const reject = (value: any) => {\n if (!isResolved()) {\n continueFn?.()\n status = 'rejected'\n promiseReject(value)\n }\n }\n\n const pause = () => {\n return new Promise((continueResolve) => {\n continueFn = (value) => {\n if (isResolved() || canContinue()) {\n continueResolve(value)\n }\n }\n config.onPause?.()\n }).then(() => {\n continueFn = undefined\n if (!isResolved()) {\n config.onContinue?.()\n }\n })\n }\n\n // Create loop function\n const run = () => {\n // Do nothing if already resolved\n if (isResolved()) {\n return\n }\n\n let promiseOrValue: any\n\n // we can re-use config.initialPromise on the first call of run()\n const initialPromise =\n failureCount === 0 ? config.initialPromise : undefined\n\n // Execute query\n try {\n promiseOrValue = initialPromise ?? config.fn()\n } catch (error) {\n promiseOrValue = Promise.reject(error)\n }\n\n Promise.resolve(promiseOrValue)\n .then(resolve)\n .catch((error) => {\n // Stop if the fetch is already resolved\n if (isResolved()) {\n return\n }\n\n // Do we need to retry the request?\n const retry = config.retry ?? (isServerEnvironment() ? 0 : 3)\n const retryDelay = config.retryDelay ?? defaultRetryDelay\n const delay =\n typeof retryDelay === 'function'\n ? retryDelay(failureCount, error)\n : retryDelay\n const shouldRetry =\n retry === true ||\n (typeof retry === 'number' && failureCount < retry) ||\n (typeof retry === 'function' && retry(failureCount, error))\n\n if (isRetryCancelled || !shouldRetry) {\n // We are done if the query does not need to be retried\n reject(error)\n return\n }\n\n failureCount++\n\n // Notify on fail\n config.onFail?.(failureCount, error)\n\n // Delay\n sleep(delay)\n // Pause if the document is not visible or when the device is offline\n .then(() => {\n return canContinue() ? undefined : pause()\n })\n .then(() => {\n if (isRetryCancelled) {\n reject(error)\n } else {\n run()\n }\n })\n })\n }\n\n return {\n promise,\n status: () => status,\n cancel,\n continue: () => {\n continueFn?.()\n return promise\n },\n cancelRetry,\n continueRetry,\n canStart,\n start: () => {\n // Start loop\n if (canStart()) {\n run()\n } else {\n pause().then(run)\n }\n return promise\n },\n }\n}\n"],"mappings":";;;;;AAoDA,SAAS,kBAAkB,cAAsB;CAC/C,OAAO,KAAK,IAAI,MAAO,KAAK,cAAc,GAAK;AACjD;AAEA,SAAgB,SAAS,aAA+C;CACtE,QAAQ,eAAe,cAAc,WACjC,cAAc,SAAS,IACvB;AACN;;;;;;;;;;;;;;;;;;;AAoBA,IAAa,iBAAb,cAAoC,MAAM;CAGxC,YAAY,SAAyB;EACnC,MAAM,gBAAgB;EACtB,KAAK,SAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAS,QAAS;EACvB,KAAK,SAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAS,QAAS;CACzB;AACF;;;;AAKA,SAAgB,iBAAiB,OAAqC;CACpE,OAAO,iBAAiB;AAC1B;AAEA,SAAgB,cACd,QACgB;CAChB,IAAI,mBAAmB;CACvB,IAAI,eAAe;CACnB,IAAI;CACJ,IAAI,SAAwB;CAC5B,IAAI;CACJ,IAAI;CAEJ,MAAM,UAAU,IAAI,SAAgB,SAAS,WAAW;EACtD,iBAAiB;EACjB,gBAAgB;CAClB,CAAC;CACD,QAAQ,MAAM,IAAI;CAElB,MAAM,mBAAmB,WAAW;CAEpC,MAAM,UAAU,kBAAwC;EACtD,IAAI,CAAC,WAAW,GAAG;;GACjB,MAAM,QAAQ,IAAI,eAAe,aAAa;GAC9C,OAAO,KAAK;GAEZ,CAAA,mBAAA,OAAO,cAAA,QAAA,qBAAA,KAAA,KAAA,iBAAA,KAAA,QAAW,KAAK;EACzB;CACF;CACA,MAAM,oBAAoB;EACxB,mBAAmB;CACrB;CAEA,MAAM,sBAAsB;EAC1B,mBAAmB;CACrB;CAEA,MAAM,oBACJ,aAAa,UAAU,MACtB,OAAO,gBAAgB,YAAY,cAAc,SAAS,MAC3D,OAAO,OAAO;CAEhB,MAAM,iBAAiB,SAAS,OAAO,WAAW,KAAK,OAAO,OAAO;CAErE,MAAM,WAAW,UAAe;EAC9B,IAAI,CAAC,WAAW,GAAG;GACjB,eAAA,QAAA,eAAA,KAAA,KAAA,WAAa;GACb,SAAS;GACT,eAAe,KAAK;EACtB;CACF;CAEA,MAAM,UAAU,UAAe;EAC7B,IAAI,CAAC,WAAW,GAAG;GACjB,eAAA,QAAA,eAAA,KAAA,KAAA,WAAa;GACb,SAAS;GACT,cAAc,KAAK;EACrB;CACF;CAEA,MAAM,cAAc;EAClB,OAAO,IAAI,SAAS,oBAAoB;;GACtC,cAAc,UAAU;IACtB,IAAI,WAAW,KAAK,YAAY,GAC9B,gBAAgB,KAAK;GAEzB;GACA,CAAA,kBAAA,OAAO,aAAA,QAAA,oBAAA,KAAA,KAAA,gBAAA,KAAA,MAAU;EACnB,CAAC,CAAC,CAAC,WAAW;GACZ,aAAa,KAAA;GACb,IAAI,CAAC,WAAW,GAAG;;IACjB,CAAA,qBAAA,OAAO,gBAAA,QAAA,uBAAA,KAAA,KAAA,mBAAA,KAAA,MAAa;GACtB;EACF,CAAC;CACH;CAGA,MAAM,YAAY;EAEhB,IAAI,WAAW,GACb;EAGF,IAAI;EAGJ,MAAM,iBACJ,iBAAiB,IAAI,OAAO,iBAAiB,KAAA;EAG/C,IAAI;GACF,iBAAiB,kBAAkB,OAAO,GAAG;EAC/C,SAAS,OAAO;GACd,iBAAiB,QAAQ,OAAO,KAAK;EACvC;EAEA,QAAQ,QAAQ,cAAc,CAAC,CAC5B,KAAK,OAAO,CAAC,CACb,OAAO,UAAU;;GAEhB,IAAI,WAAW,GACb;GAIF,MAAM,QAAQ,OAAO,UAAUA,SAAoB,IAAI,IAAI;GAC3D,MAAM,aAAa,OAAO,cAAc;GACxC,MAAM,QACJ,OAAO,eAAe,aAClB,WAAW,cAAc,KAAK,IAC9B;GACN,MAAM,cACJ,UAAU,QACT,OAAO,UAAU,YAAY,eAAe,SAC5C,OAAO,UAAU,cAAc,MAAM,cAAc,KAAK;GAE3D,IAAI,oBAAoB,CAAC,aAAa;IAEpC,OAAO,KAAK;IACZ;GACF;GAEA;GAGA,CAAA,iBAAA,OAAO,YAAA,QAAA,mBAAA,KAAA,KAAA,eAAA,KAAA,QAAS,cAAc,KAAK;GAGnC,MAAM,KAAK,CAAC,CAET,WAAW;IACV,OAAO,YAAY,IAAI,KAAA,IAAY,MAAM;GAC3C,CAAC,CAAC,CACD,WAAW;IACV,IAAI,kBACF,OAAO,KAAK;SAEZ,IAAI;GAER,CAAC;EACL,CAAC;CACL;CAEA,OAAO;EACL;EACA,cAAc;EACd;EACA,gBAAgB;GACd,eAAA,QAAA,eAAA,KAAA,KAAA,WAAa;GACb,OAAO;EACT;EACA;EACA;EACA;EACA,aAAa;GAEX,IAAI,SAAS,GACX,IAAI;QAEJ,MAAM,CAAC,CAAC,KAAK,GAAG;GAElB,OAAO;EACT;CACF;AACF"}
|
|
@@ -7,13 +7,6 @@ const require_utils = require("./utils.cjs");
|
|
|
7
7
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
8
8
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
9
9
|
* @param streamFn - The function that returns an AsyncIterable to stream data from.
|
|
10
|
-
* @param refetchMode - Defines how re-fetches are handled.
|
|
11
|
-
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
12
|
-
* Set to `'append'` to append new data to the existing data.
|
|
13
|
-
* Set to `'replace'` to write all data to the cache once the stream ends.
|
|
14
|
-
* @param reducer - A function to reduce the streamed chunks into the final data.
|
|
15
|
-
* Defaults to a function that appends chunks to the end of the array.
|
|
16
|
-
* @param initialValue - Initial value to be used while the first chunk is being fetched, and returned if the stream yields no values.
|
|
17
10
|
* @example
|
|
18
11
|
* ```ts
|
|
19
12
|
* await queryClient.query({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamedQuery.cjs","names":["addToEnd","addConsumeAwareSignal"],"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n /** The function that returns an `AsyncIterable` to stream data from. */\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n /**\n * Defines how refetches are handled.\n * - `'reset'` (default): erases all data and puts the query back into `pending` state.\n * - `'append'`: appends new data to the existing data.\n * - `'replace'`: writes all data to the cache once the stream ends.\n */\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n /**\n * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an\n * array, since there is no default way to accumulate non-array chunks.\n */\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n /**\n * The value used while the first chunk is being fetched, and returned if the stream yields no\n * values. Required together with a custom `reducer`.\n */\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param streamFn - The function that returns an AsyncIterable to stream data from.\n * @
|
|
1
|
+
{"version":3,"file":"streamedQuery.cjs","names":["addToEnd","addConsumeAwareSignal"],"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n /** The function that returns an `AsyncIterable` to stream data from. */\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n /**\n * Defines how refetches are handled.\n * - `'reset'` (default): erases all data and puts the query back into `pending` state.\n * - `'append'`: appends new data to the existing data.\n * - `'replace'`: writes all data to the cache once the stream ends.\n */\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n /**\n * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an\n * array, since there is no default way to accumulate non-array chunks.\n */\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n /**\n * The value used while the first chunk is being fetched, and returned if the stream yields no\n * values. Required together with a custom `reducer`.\n */\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param streamFn - The function that returns an AsyncIterable to stream data from.\n * @example\n * ```ts\n * await queryClient.query({\n * queryKey: ['data'],\n * queryFn: streamedQuery({\n * streamFn: fetchDataInChunks,\n * }),\n * })\n * ```\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TData = Array<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n>({\n streamFn,\n refetchMode = 'reset',\n reducer = (items, chunk) =>\n addToEnd(items as Array<TQueryFnData>, chunk) as TData,\n initialValue = [] as TData,\n}: StreamedQueryParams<TQueryFnData, TData, TQueryKey>): QueryFunction<\n TData,\n TQueryKey\n> {\n return async (context) => {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n const isRefetch = !!query && query.isFetched()\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n ...query.resetState,\n fetchStatus: 'fetching',\n })\n }\n\n let result = initialValue\n\n let cancelled: boolean = false as boolean\n const streamFnContext = addConsumeAwareSignal<\n OmitKeyof<typeof context, 'signal'>\n >(\n {\n client: context.client,\n meta: context.meta,\n queryKey: context.queryKey,\n pageParam: context.pageParam,\n direction: context.direction,\n },\n () => context.signal,\n () => (cancelled = true),\n )\n\n const stream = await streamFn(streamFnContext)\n\n const isReplaceRefetch = isRefetch && refetchMode === 'replace'\n\n for await (const chunk of stream) {\n if (cancelled) {\n break\n }\n\n if (isReplaceRefetch) {\n // don't append to the cache directly when replace-refetching\n result = reducer(result, chunk)\n } else {\n context.client.setQueryData<TData>(context.queryKey, (prev) =>\n reducer(prev === undefined ? initialValue : prev, chunk),\n )\n }\n }\n\n // finalize result: replace-refetching needs to write to the cache\n if (isReplaceRefetch && !cancelled) {\n context.client.setQueryData<TData>(context.queryKey, result)\n }\n\n const data = context.client.getQueryData<TData>(context.queryKey)\n return data === undefined ? initialValue : data\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmEA,SAAgB,cAId,EACA,UACA,cAAc,SACd,WAAW,OAAO,UAChBA,cAAAA,SAAS,OAA8B,KAAK,GAC9C,eAAe,CAAC,KAIhB;CACA,OAAO,OAAO,YAAY;EACxB,MAAM,QAAQ,QAAQ,OACnB,cAAc,CAAC,CACf,KAAK;GAAE,UAAU,QAAQ;GAAU,OAAO;EAAK,CAAC;EACnD,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,UAAU;EAC7C,IAAI,aAAa,gBAAgB,SAC/B,MAAM,SAAS;GACb,GAAG,MAAM;GACT,aAAa;EACf,CAAC;EAGH,IAAI,SAAS;EAEb,IAAI,YAAqB;EAezB,MAAM,SAAS,MAAM,SAdGC,cAAAA,sBAGtB;GACE,QAAQ,QAAQ;GAChB,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB,WAAW,QAAQ;GACnB,WAAW,QAAQ;EACrB,SACM,QAAQ,cACP,YAAY,IAGuB,CAAC;EAE7C,MAAM,mBAAmB,aAAa,gBAAgB;EAEtD,WAAW,MAAM,SAAS,QAAQ;GAChC,IAAI,WACF;GAGF,IAAI,kBAEF,SAAS,QAAQ,QAAQ,KAAK;QAE9B,QAAQ,OAAO,aAAoB,QAAQ,WAAW,SACpD,QAAQ,SAAS,KAAA,IAAY,eAAe,MAAM,KAAK,CACzD;EAEJ;EAGA,IAAI,oBAAoB,CAAC,WACvB,QAAQ,OAAO,aAAoB,QAAQ,UAAU,MAAM;EAG7D,MAAM,OAAO,QAAQ,OAAO,aAAoB,QAAQ,QAAQ;EAChE,OAAO,SAAS,KAAA,IAAY,eAAe;CAC7C;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ct as QueryKey, St as QueryFunctionContext, xt as QueryFunction } from "./hydration-
|
|
1
|
+
import { Ct as QueryKey, St as QueryFunctionContext, xt as QueryFunction } from "./hydration-Br9VIGXa.cjs";
|
|
2
2
|
//#region src/streamedQuery.d.ts
|
|
3
3
|
type BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {
|
|
4
4
|
/** The function that returns an `AsyncIterable` to stream data from. */
|
|
@@ -34,13 +34,6 @@ type StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> = Simp
|
|
|
34
34
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
35
35
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
36
36
|
* @param streamFn - The function that returns an AsyncIterable to stream data from.
|
|
37
|
-
* @param refetchMode - Defines how re-fetches are handled.
|
|
38
|
-
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
39
|
-
* Set to `'append'` to append new data to the existing data.
|
|
40
|
-
* Set to `'replace'` to write all data to the cache once the stream ends.
|
|
41
|
-
* @param reducer - A function to reduce the streamed chunks into the final data.
|
|
42
|
-
* Defaults to a function that appends chunks to the end of the array.
|
|
43
|
-
* @param initialValue - Initial value to be used while the first chunk is being fetched, and returned if the stream yields no values.
|
|
44
37
|
* @example
|
|
45
38
|
* ```ts
|
|
46
39
|
* await queryClient.query({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamedQuery.d.cts","names":[],"sources":["../../src/streamedQuery.ts"],"mappings":";;KAQK,wBAAwB,cAAc,kBAAkB;;EAE3D,WACE,SAAS,qBAAqB,eAC3B,cAAc,gBAAgB,QAAQ,cAAc;;;;;;;EAOzD;;KAGG,0BACH,cACA,kBAAkB,YAChB,wBAAwB,cAAc;EACxC;EACA;;KAGG,6BACH,cACA,OACA,kBAAkB,YAChB,wBAAwB,cAAc;;;;;EAKxC,UAAU,KAAK,OAAO,OAAO,iBAAiB;;;;;EAK9C,cAAc;;KAGX,oBAAoB,cAAc,OAAO,kBAAkB,YAC5D,0BAA0B,cAAc,aACxC,6BAA6B,cAAc,OAAO
|
|
1
|
+
{"version":3,"file":"streamedQuery.d.cts","names":[],"sources":["../../src/streamedQuery.ts"],"mappings":";;KAQK,wBAAwB,cAAc,kBAAkB;;EAE3D,WACE,SAAS,qBAAqB,eAC3B,cAAc,gBAAgB,QAAQ,cAAc;;;;;;;EAOzD;;KAGG,0BACH,cACA,kBAAkB,YAChB,wBAAwB,cAAc;EACxC;EACA;;KAGG,6BACH,cACA,OACA,kBAAkB,YAChB,wBAAwB,cAAc;;;;;EAKxC,UAAU,KAAK,OAAO,OAAO,iBAAiB;;;;;EAK9C,cAAc;;KAGX,oBAAoB,cAAc,OAAO,kBAAkB,YAC5D,0BAA0B,cAAc,aACxC,6BAA6B,cAAc,OAAO;;;;;;;;;;;;;;;;;iBAkBtC,cACd,wBACA,QAAQ,MAAM,eACd,kBAAkB,WAAW,YAE7B,UACA,aACA,SAEA,gBACC,oBAAoB,cAAc,OAAO,aAAa,cACvD,OACA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ct as QueryKey, St as QueryFunctionContext, xt as QueryFunction } from "./hydration-
|
|
1
|
+
import { Ct as QueryKey, St as QueryFunctionContext, xt as QueryFunction } from "./hydration-B9t5w6NC.js";
|
|
2
2
|
//#region src/streamedQuery.d.ts
|
|
3
3
|
type BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {
|
|
4
4
|
/** The function that returns an `AsyncIterable` to stream data from. */
|
|
@@ -34,13 +34,6 @@ type StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> = Simp
|
|
|
34
34
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
35
35
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
36
36
|
* @param streamFn - The function that returns an AsyncIterable to stream data from.
|
|
37
|
-
* @param refetchMode - Defines how re-fetches are handled.
|
|
38
|
-
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
39
|
-
* Set to `'append'` to append new data to the existing data.
|
|
40
|
-
* Set to `'replace'` to write all data to the cache once the stream ends.
|
|
41
|
-
* @param reducer - A function to reduce the streamed chunks into the final data.
|
|
42
|
-
* Defaults to a function that appends chunks to the end of the array.
|
|
43
|
-
* @param initialValue - Initial value to be used while the first chunk is being fetched, and returned if the stream yields no values.
|
|
44
37
|
* @example
|
|
45
38
|
* ```ts
|
|
46
39
|
* await queryClient.query({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamedQuery.d.ts","names":[],"sources":["../../src/streamedQuery.ts"],"mappings":";;KAQK,wBAAwB,cAAc,kBAAkB;;EAE3D,WACE,SAAS,qBAAqB,eAC3B,cAAc,gBAAgB,QAAQ,cAAc;;;;;;;EAOzD;;KAGG,0BACH,cACA,kBAAkB,YAChB,wBAAwB,cAAc;EACxC;EACA;;KAGG,6BACH,cACA,OACA,kBAAkB,YAChB,wBAAwB,cAAc;;;;;EAKxC,UAAU,KAAK,OAAO,OAAO,iBAAiB;;;;;EAK9C,cAAc;;KAGX,oBAAoB,cAAc,OAAO,kBAAkB,YAC5D,0BAA0B,cAAc,aACxC,6BAA6B,cAAc,OAAO
|
|
1
|
+
{"version":3,"file":"streamedQuery.d.ts","names":[],"sources":["../../src/streamedQuery.ts"],"mappings":";;KAQK,wBAAwB,cAAc,kBAAkB;;EAE3D,WACE,SAAS,qBAAqB,eAC3B,cAAc,gBAAgB,QAAQ,cAAc;;;;;;;EAOzD;;KAGG,0BACH,cACA,kBAAkB,YAChB,wBAAwB,cAAc;EACxC;EACA;;KAGG,6BACH,cACA,OACA,kBAAkB,YAChB,wBAAwB,cAAc;;;;;EAKxC,UAAU,KAAK,OAAO,OAAO,iBAAiB;;;;;EAK9C,cAAc;;KAGX,oBAAoB,cAAc,OAAO,kBAAkB,YAC5D,0BAA0B,cAAc,aACxC,6BAA6B,cAAc,OAAO;;;;;;;;;;;;;;;;;iBAkBtC,cACd,wBACA,QAAQ,MAAM,eACd,kBAAkB,WAAW,YAE7B,UACA,aACA,SAEA,gBACC,oBAAoB,cAAc,OAAO,aAAa,cACvD,OACA"}
|
|
@@ -6,13 +6,6 @@ import { addConsumeAwareSignal, addToEnd } from "./utils.js";
|
|
|
6
6
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
7
7
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
8
8
|
* @param streamFn - The function that returns an AsyncIterable to stream data from.
|
|
9
|
-
* @param refetchMode - Defines how re-fetches are handled.
|
|
10
|
-
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
11
|
-
* Set to `'append'` to append new data to the existing data.
|
|
12
|
-
* Set to `'replace'` to write all data to the cache once the stream ends.
|
|
13
|
-
* @param reducer - A function to reduce the streamed chunks into the final data.
|
|
14
|
-
* Defaults to a function that appends chunks to the end of the array.
|
|
15
|
-
* @param initialValue - Initial value to be used while the first chunk is being fetched, and returned if the stream yields no values.
|
|
16
9
|
* @example
|
|
17
10
|
* ```ts
|
|
18
11
|
* await queryClient.query({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamedQuery.js","names":[],"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n /** The function that returns an `AsyncIterable` to stream data from. */\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n /**\n * Defines how refetches are handled.\n * - `'reset'` (default): erases all data and puts the query back into `pending` state.\n * - `'append'`: appends new data to the existing data.\n * - `'replace'`: writes all data to the cache once the stream ends.\n */\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n /**\n * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an\n * array, since there is no default way to accumulate non-array chunks.\n */\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n /**\n * The value used while the first chunk is being fetched, and returned if the stream yields no\n * values. Required together with a custom `reducer`.\n */\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param streamFn - The function that returns an AsyncIterable to stream data from.\n * @
|
|
1
|
+
{"version":3,"file":"streamedQuery.js","names":[],"sources":["../../src/streamedQuery.ts"],"sourcesContent":["import { addConsumeAwareSignal, addToEnd } from './utils'\nimport type {\n OmitKeyof,\n QueryFunction,\n QueryFunctionContext,\n QueryKey,\n} from './types'\n\ntype BaseStreamedQueryParams<TQueryFnData, TQueryKey extends QueryKey> = {\n /** The function that returns an `AsyncIterable` to stream data from. */\n streamFn: (\n context: QueryFunctionContext<TQueryKey>,\n ) => AsyncIterable<TQueryFnData> | Promise<AsyncIterable<TQueryFnData>>\n /**\n * Defines how refetches are handled.\n * - `'reset'` (default): erases all data and puts the query back into `pending` state.\n * - `'append'`: appends new data to the existing data.\n * - `'replace'`: writes all data to the cache once the stream ends.\n */\n refetchMode?: 'append' | 'reset' | 'replace'\n}\n\ntype SimpleStreamedQueryParams<\n TQueryFnData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n reducer?: never\n initialValue?: never\n}\n\ntype ReducibleStreamedQueryParams<\n TQueryFnData,\n TData,\n TQueryKey extends QueryKey,\n> = BaseStreamedQueryParams<TQueryFnData, TQueryKey> & {\n /**\n * Reduces streamed chunks into the final data shape. Required whenever `TData` is not an\n * array, since there is no default way to accumulate non-array chunks.\n */\n reducer: (acc: TData, chunk: TQueryFnData) => TData\n /**\n * The value used while the first chunk is being fetched, and returned if the stream yields no\n * values. Required together with a custom `reducer`.\n */\n initialValue: TData\n}\n\ntype StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =\n | SimpleStreamedQueryParams<TQueryFnData, TQueryKey>\n | ReducibleStreamedQueryParams<TQueryFnData, TData, TQueryKey>\n\n/**\n * This is a helper function to create a query function that streams data from an AsyncIterable.\n * Data will be an Array of all the chunks received.\n * The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.\n * The query will stay in fetchStatus 'fetching' until the stream ends.\n * @param streamFn - The function that returns an AsyncIterable to stream data from.\n * @example\n * ```ts\n * await queryClient.query({\n * queryKey: ['data'],\n * queryFn: streamedQuery({\n * streamFn: fetchDataInChunks,\n * }),\n * })\n * ```\n */\nexport function streamedQuery<\n TQueryFnData = unknown,\n TData = Array<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n>({\n streamFn,\n refetchMode = 'reset',\n reducer = (items, chunk) =>\n addToEnd(items as Array<TQueryFnData>, chunk) as TData,\n initialValue = [] as TData,\n}: StreamedQueryParams<TQueryFnData, TData, TQueryKey>): QueryFunction<\n TData,\n TQueryKey\n> {\n return async (context) => {\n const query = context.client\n .getQueryCache()\n .find({ queryKey: context.queryKey, exact: true })\n const isRefetch = !!query && query.isFetched()\n if (isRefetch && refetchMode === 'reset') {\n query.setState({\n ...query.resetState,\n fetchStatus: 'fetching',\n })\n }\n\n let result = initialValue\n\n let cancelled: boolean = false as boolean\n const streamFnContext = addConsumeAwareSignal<\n OmitKeyof<typeof context, 'signal'>\n >(\n {\n client: context.client,\n meta: context.meta,\n queryKey: context.queryKey,\n pageParam: context.pageParam,\n direction: context.direction,\n },\n () => context.signal,\n () => (cancelled = true),\n )\n\n const stream = await streamFn(streamFnContext)\n\n const isReplaceRefetch = isRefetch && refetchMode === 'replace'\n\n for await (const chunk of stream) {\n if (cancelled) {\n break\n }\n\n if (isReplaceRefetch) {\n // don't append to the cache directly when replace-refetching\n result = reducer(result, chunk)\n } else {\n context.client.setQueryData<TData>(context.queryKey, (prev) =>\n reducer(prev === undefined ? initialValue : prev, chunk),\n )\n }\n }\n\n // finalize result: replace-refetching needs to write to the cache\n if (isReplaceRefetch && !cancelled) {\n context.client.setQueryData<TData>(context.queryKey, result)\n }\n\n const data = context.client.getQueryData<TData>(context.queryKey)\n return data === undefined ? initialValue : data\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmEA,SAAgB,cAId,EACA,UACA,cAAc,SACd,WAAW,OAAO,UAChB,SAAS,OAA8B,KAAK,GAC9C,eAAe,CAAC,KAIhB;CACA,OAAO,OAAO,YAAY;EACxB,MAAM,QAAQ,QAAQ,OACnB,cAAc,CAAC,CACf,KAAK;GAAE,UAAU,QAAQ;GAAU,OAAO;EAAK,CAAC;EACnD,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,UAAU;EAC7C,IAAI,aAAa,gBAAgB,SAC/B,MAAM,SAAS;GACb,GAAG,MAAM;GACT,aAAa;EACf,CAAC;EAGH,IAAI,SAAS;EAEb,IAAI,YAAqB;EAezB,MAAM,SAAS,MAAM,SAdG,sBAGtB;GACE,QAAQ,QAAQ;GAChB,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB,WAAW,QAAQ;GACnB,WAAW,QAAQ;EACrB,SACM,QAAQ,cACP,YAAY,IAGuB,CAAC;EAE7C,MAAM,mBAAmB,aAAa,gBAAgB;EAEtD,WAAW,MAAM,SAAS,QAAQ;GAChC,IAAI,WACF;GAGF,IAAI,kBAEF,SAAS,QAAQ,QAAQ,KAAK;QAE9B,QAAQ,OAAO,aAAoB,QAAQ,WAAW,SACpD,QAAQ,SAAS,KAAA,IAAY,eAAe,MAAM,KAAK,CACzD;EAEJ;EAGA,IAAI,oBAAoB,CAAC,WACvB,QAAQ,OAAO,aAAoB,QAAQ,UAAU,MAAM;EAG7D,MAAM,OAAO,QAAQ,OAAO,aAAoB,QAAQ,QAAQ;EAChE,OAAO,SAAS,KAAA,IAAY,eAAe;CAC7C;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/subscribable.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,
|
|
4
|
+
* the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.
|
|
5
|
+
* Subclasses decide what a listener receives and when it is called.
|
|
6
|
+
*/
|
|
7
|
+
declare class Subscribable<TListener extends Function> {
|
|
8
|
+
protected listeners: Set<TListener>;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Registers a listener to be called on every update this object notifies about. Returns a function
|
|
12
|
+
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
13
|
+
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
14
|
+
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const unsubscribe = subscribable.subscribe(() => {
|
|
18
|
+
* // react to the update
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* unsubscribe()
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
subscribe(listener: TListener): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
27
|
+
*/
|
|
28
|
+
hasListeners(): boolean;
|
|
29
|
+
protected onSubscribe(): void;
|
|
30
|
+
protected onUnsubscribe(): void;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Subscribable as t };
|
|
34
|
+
//# sourceMappingURL=subscribable-CysQ0tne.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribable-CysQ0tne.d.cts","names":[],"sources":["../../src/subscribable.ts"],"mappings":";;;;;;cAKa,aAAa,kBAAkB;YAChC,WAAS,IAAA;;;;;;;;;;;;;;;;EAoBnB,UAAU,UAAU;;;;EAcpB;YAIU;YAIA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/subscribable.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,
|
|
4
|
+
* the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.
|
|
5
|
+
* Subclasses decide what a listener receives and when it is called.
|
|
6
|
+
*/
|
|
7
|
+
declare class Subscribable<TListener extends Function> {
|
|
8
|
+
protected listeners: Set<TListener>;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Registers a listener to be called on every update this object notifies about. Returns a function
|
|
12
|
+
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
13
|
+
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
14
|
+
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const unsubscribe = subscribable.subscribe(() => {
|
|
18
|
+
* // react to the update
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* unsubscribe()
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
subscribe(listener: TListener): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
27
|
+
*/
|
|
28
|
+
hasListeners(): boolean;
|
|
29
|
+
protected onSubscribe(): void;
|
|
30
|
+
protected onUnsubscribe(): void;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Subscribable as t };
|
|
34
|
+
//# sourceMappingURL=subscribable-CysQ0tne.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribable-CysQ0tne.d.ts","names":[],"sources":["../../src/subscribable.ts"],"mappings":";;;;;;cAKa,aAAa,kBAAkB;YAChC,WAAS,IAAA;;;;;;;;;;;;;;;;EAoBnB,UAAU,UAAU;;;;EAcpB;YAIU;YAIA"}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/subscribable.ts
|
|
3
|
+
/**
|
|
4
|
+
* The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,
|
|
5
|
+
* the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.
|
|
6
|
+
* Subclasses decide what a listener receives and when it is called.
|
|
7
|
+
*/
|
|
3
8
|
var Subscribable = class {
|
|
4
9
|
constructor() {
|
|
5
10
|
this.listeners = /* @__PURE__ */ new Set();
|
|
6
11
|
this.subscribe = this.subscribe.bind(this);
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Registers a listener to be called on every update this object notifies about. Returns a function
|
|
15
|
+
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
16
|
+
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
17
|
+
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const unsubscribe = subscribable.subscribe(() => {
|
|
21
|
+
* // react to the update
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* unsubscribe()
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
8
27
|
subscribe(listener) {
|
|
9
28
|
this.listeners.add(listener);
|
|
10
29
|
this.onSubscribe();
|
|
@@ -13,6 +32,9 @@ var Subscribable = class {
|
|
|
13
32
|
this.onUnsubscribe();
|
|
14
33
|
};
|
|
15
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
37
|
+
*/
|
|
16
38
|
hasListeners() {
|
|
17
39
|
return this.listeners.size > 0;
|
|
18
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribable.cjs","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"subscribable.cjs","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["/**\n * The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,\n * the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.\n * Subclasses decide what a listener receives and when it is called.\n */\nexport class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n /**\n * Registers a listener to be called on every update this object notifies about. Returns a function\n * that removes the listener again — call it to stop listening. The base class never drops a listener\n * on its own, though some subclasses clear all of theirs in `destroy()`.\n * @param listener - Called on each update, with whatever the subclass passes to its subscribers.\n * @example\n * ```ts\n * const unsubscribe = subscribable.subscribe(() => {\n * // react to the update\n * })\n *\n * unsubscribe()\n * ```\n */\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n /**\n * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.\n */\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";;;;;;;AAKA,IAAa,eAAb,MAAsD;CAGpD,cAAc;EAFd,KAAU,4BAAY,IAAI,IAAe;EAGvC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C;;;;;;;;;;;;;;;CAgBA,UAAU,UAAiC;EACzC,KAAK,UAAU,IAAI,QAAQ;EAE3B,KAAK,YAAY;EAEjB,aAAa;GACX,KAAK,UAAU,OAAO,QAAQ;GAC9B,KAAK,cAAc;EACrB;CACF;;;;CAKA,eAAwB;EACtB,OAAO,KAAK,UAAU,OAAO;CAC/B;CAEA,cAA8B,CAE9B;CAEA,gBAAgC,CAEhC;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as Subscribable } from "./subscribable-
|
|
1
|
+
import { t as Subscribable } from "./subscribable-CysQ0tne.cjs";
|
|
2
2
|
export { Subscribable };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as Subscribable } from "./subscribable-
|
|
1
|
+
import { t as Subscribable } from "./subscribable-CysQ0tne.js";
|
|
2
2
|
export { Subscribable };
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
//#region src/subscribable.ts
|
|
2
|
+
/**
|
|
3
|
+
* The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,
|
|
4
|
+
* the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.
|
|
5
|
+
* Subclasses decide what a listener receives and when it is called.
|
|
6
|
+
*/
|
|
2
7
|
var Subscribable = class {
|
|
3
8
|
constructor() {
|
|
4
9
|
this.listeners = /* @__PURE__ */ new Set();
|
|
5
10
|
this.subscribe = this.subscribe.bind(this);
|
|
6
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Registers a listener to be called on every update this object notifies about. Returns a function
|
|
14
|
+
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
15
|
+
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
16
|
+
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const unsubscribe = subscribable.subscribe(() => {
|
|
20
|
+
* // react to the update
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* unsubscribe()
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
7
26
|
subscribe(listener) {
|
|
8
27
|
this.listeners.add(listener);
|
|
9
28
|
this.onSubscribe();
|
|
@@ -12,6 +31,9 @@ var Subscribable = class {
|
|
|
12
31
|
this.onUnsubscribe();
|
|
13
32
|
};
|
|
14
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
36
|
+
*/
|
|
15
37
|
hasListeners() {
|
|
16
38
|
return this.listeners.size > 0;
|
|
17
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribable.js","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"subscribable.js","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["/**\n * The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,\n * the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.\n * Subclasses decide what a listener receives and when it is called.\n */\nexport class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n /**\n * Registers a listener to be called on every update this object notifies about. Returns a function\n * that removes the listener again — call it to stop listening. The base class never drops a listener\n * on its own, though some subclasses clear all of theirs in `destroy()`.\n * @param listener - Called on each update, with whatever the subclass passes to its subscribers.\n * @example\n * ```ts\n * const unsubscribe = subscribable.subscribe(() => {\n * // react to the update\n * })\n *\n * unsubscribe()\n * ```\n */\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n /**\n * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.\n */\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";;;;;;AAKA,IAAa,eAAb,MAAsD;CAGpD,cAAc;EAFd,KAAU,4BAAY,IAAI,IAAe;EAGvC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C;;;;;;;;;;;;;;;CAgBA,UAAU,UAAiC;EACzC,KAAK,UAAU,IAAI,QAAQ;EAE3B,KAAK,YAAY;EAEjB,aAAa;GACX,KAAK,UAAU,OAAO,QAAQ;GAC9B,KAAK,cAAc;EACrB;CACF;;;;CAKA,eAAwB;EACtB,OAAO,KAAK,UAAU,OAAO;CAC/B;CAEA,cAA8B,CAE9B;CAEA,gBAAgC,CAEhC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_classPrivateFieldSet2 = require("./classPrivateFieldSet2-
|
|
2
|
+
const require_classPrivateFieldSet2 = require("./classPrivateFieldSet2-CvCEk6bM.cjs");
|
|
3
3
|
//#region src/timeoutManager.ts
|
|
4
4
|
const defaultTimeoutProvider = {
|
|
5
5
|
setTimeout: (callback, delay) => setTimeout(callback, delay),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, t as _classPrivateFieldSet2 } from "./classPrivateFieldSet2-
|
|
1
|
+
import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, t as _classPrivateFieldSet2 } from "./classPrivateFieldSet2-CukOTU3U.js";
|
|
2
2
|
//#region src/timeoutManager.ts
|
|
3
3
|
const defaultTimeoutProvider = {
|
|
4
4
|
setTimeout: (callback, delay) => setTimeout(callback, delay),
|