@tanstack/query-core 5.105.1 → 5.105.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.
Files changed (139) hide show
  1. package/build/legacy/{hydration-DdkP3REv.d.cts → hydration-BXjqUj_D.d.cts} +25 -14
  2. package/build/legacy/hydration-BXjqUj_D.d.cts.map +1 -0
  3. package/build/legacy/{hydration-gHEs4kLM.d.ts → hydration-vgIjIhk6.d.ts} +25 -14
  4. package/build/legacy/hydration-vgIjIhk6.d.ts.map +1 -0
  5. package/build/legacy/hydration.d.cts +1 -1
  6. package/build/legacy/hydration.d.ts +1 -1
  7. package/build/legacy/index.d.cts +1 -1
  8. package/build/legacy/index.d.ts +1 -1
  9. package/build/legacy/infiniteQueryBehavior.cjs +2 -1
  10. package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
  11. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  12. package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
  13. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  14. package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
  15. package/build/legacy/infiniteQueryBehavior.js +3 -2
  16. package/build/legacy/infiniteQueryBehavior.js.map +1 -1
  17. package/build/legacy/infiniteQueryObserver.d.cts +1 -1
  18. package/build/legacy/infiniteQueryObserver.d.ts +1 -1
  19. package/build/legacy/mutation.cjs +1 -0
  20. package/build/legacy/mutation.cjs.map +1 -1
  21. package/build/legacy/mutation.d.cts +1 -1
  22. package/build/legacy/mutation.d.ts +1 -1
  23. package/build/legacy/mutation.js +1 -0
  24. package/build/legacy/mutation.js.map +1 -1
  25. package/build/legacy/mutationCache.d.cts +1 -1
  26. package/build/legacy/mutationCache.d.ts +1 -1
  27. package/build/legacy/mutationObserver.d.cts +1 -1
  28. package/build/legacy/mutationObserver.d.ts +1 -1
  29. package/build/legacy/queriesObserver.d.cts +1 -1
  30. package/build/legacy/queriesObserver.d.ts +1 -1
  31. package/build/legacy/query.cjs +54 -36
  32. package/build/legacy/query.cjs.map +1 -1
  33. package/build/legacy/query.d.cts +1 -1
  34. package/build/legacy/query.d.ts +1 -1
  35. package/build/legacy/query.js +55 -37
  36. package/build/legacy/query.js.map +1 -1
  37. package/build/legacy/queryCache.d.cts +1 -1
  38. package/build/legacy/queryCache.d.ts +1 -1
  39. package/build/legacy/queryClient.cjs +11 -6
  40. package/build/legacy/queryClient.cjs.map +1 -1
  41. package/build/legacy/queryClient.d.cts +1 -1
  42. package/build/legacy/queryClient.d.ts +1 -1
  43. package/build/legacy/queryClient.js +11 -6
  44. package/build/legacy/queryClient.js.map +1 -1
  45. package/build/legacy/queryObserver.d.cts +1 -1
  46. package/build/legacy/queryObserver.d.ts +1 -1
  47. package/build/legacy/retryer.d.cts +1 -1
  48. package/build/legacy/retryer.d.ts +1 -1
  49. package/build/legacy/streamedQuery.cjs +10 -4
  50. package/build/legacy/streamedQuery.cjs.map +1 -1
  51. package/build/legacy/streamedQuery.d.cts +3 -1
  52. package/build/legacy/streamedQuery.d.cts.map +1 -1
  53. package/build/legacy/streamedQuery.d.ts +3 -1
  54. package/build/legacy/streamedQuery.d.ts.map +1 -1
  55. package/build/legacy/streamedQuery.js +11 -5
  56. package/build/legacy/streamedQuery.js.map +1 -1
  57. package/build/legacy/types.d.cts +1 -1
  58. package/build/legacy/types.d.ts +1 -1
  59. package/build/legacy/utils.cjs +23 -19
  60. package/build/legacy/utils.cjs.map +1 -1
  61. package/build/legacy/utils.d.cts +2 -2
  62. package/build/legacy/utils.d.ts +2 -2
  63. package/build/legacy/utils.js +23 -20
  64. package/build/legacy/utils.js.map +1 -1
  65. package/build/modern/{hydration-DdkP3REv.d.cts → hydration-BXjqUj_D.d.cts} +25 -14
  66. package/build/modern/hydration-BXjqUj_D.d.cts.map +1 -0
  67. package/build/modern/{hydration-gHEs4kLM.d.ts → hydration-vgIjIhk6.d.ts} +25 -14
  68. package/build/modern/hydration-vgIjIhk6.d.ts.map +1 -0
  69. package/build/modern/hydration.d.cts +1 -1
  70. package/build/modern/hydration.d.ts +1 -1
  71. package/build/modern/index.d.cts +1 -1
  72. package/build/modern/index.d.ts +1 -1
  73. package/build/modern/infiniteQueryBehavior.cjs +2 -1
  74. package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
  75. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  76. package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
  77. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  78. package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
  79. package/build/modern/infiniteQueryBehavior.js +3 -2
  80. package/build/modern/infiniteQueryBehavior.js.map +1 -1
  81. package/build/modern/infiniteQueryObserver.d.cts +1 -1
  82. package/build/modern/infiniteQueryObserver.d.ts +1 -1
  83. package/build/modern/mutation.cjs +1 -0
  84. package/build/modern/mutation.cjs.map +1 -1
  85. package/build/modern/mutation.d.cts +1 -1
  86. package/build/modern/mutation.d.ts +1 -1
  87. package/build/modern/mutation.js +1 -0
  88. package/build/modern/mutation.js.map +1 -1
  89. package/build/modern/mutationCache.d.cts +1 -1
  90. package/build/modern/mutationCache.d.ts +1 -1
  91. package/build/modern/mutationObserver.d.cts +1 -1
  92. package/build/modern/mutationObserver.d.ts +1 -1
  93. package/build/modern/queriesObserver.d.cts +1 -1
  94. package/build/modern/queriesObserver.d.ts +1 -1
  95. package/build/modern/query.cjs +51 -34
  96. package/build/modern/query.cjs.map +1 -1
  97. package/build/modern/query.d.cts +1 -1
  98. package/build/modern/query.d.ts +1 -1
  99. package/build/modern/query.js +52 -35
  100. package/build/modern/query.js.map +1 -1
  101. package/build/modern/queryCache.d.cts +1 -1
  102. package/build/modern/queryCache.d.ts +1 -1
  103. package/build/modern/queryClient.cjs +11 -6
  104. package/build/modern/queryClient.cjs.map +1 -1
  105. package/build/modern/queryClient.d.cts +1 -1
  106. package/build/modern/queryClient.d.ts +1 -1
  107. package/build/modern/queryClient.js +11 -6
  108. package/build/modern/queryClient.js.map +1 -1
  109. package/build/modern/queryObserver.d.cts +1 -1
  110. package/build/modern/queryObserver.d.ts +1 -1
  111. package/build/modern/retryer.d.cts +1 -1
  112. package/build/modern/retryer.d.ts +1 -1
  113. package/build/modern/streamedQuery.cjs +10 -4
  114. package/build/modern/streamedQuery.cjs.map +1 -1
  115. package/build/modern/streamedQuery.d.cts +3 -1
  116. package/build/modern/streamedQuery.d.cts.map +1 -1
  117. package/build/modern/streamedQuery.d.ts +3 -1
  118. package/build/modern/streamedQuery.d.ts.map +1 -1
  119. package/build/modern/streamedQuery.js +11 -5
  120. package/build/modern/streamedQuery.js.map +1 -1
  121. package/build/modern/types.d.cts +1 -1
  122. package/build/modern/types.d.ts +1 -1
  123. package/build/modern/utils.cjs +23 -19
  124. package/build/modern/utils.cjs.map +1 -1
  125. package/build/modern/utils.d.cts +2 -2
  126. package/build/modern/utils.d.ts +2 -2
  127. package/build/modern/utils.js +23 -20
  128. package/build/modern/utils.js.map +1 -1
  129. package/package.json +1 -1
  130. package/src/infiniteQueryBehavior.ts +5 -1
  131. package/src/mutation.ts +4 -0
  132. package/src/query.ts +78 -64
  133. package/src/queryClient.ts +16 -10
  134. package/src/streamedQuery.ts +14 -3
  135. package/src/utils.ts +39 -26
  136. package/build/legacy/hydration-DdkP3REv.d.cts.map +0 -1
  137. package/build/legacy/hydration-gHEs4kLM.d.ts.map +0 -1
  138. package/build/modern/hydration-DdkP3REv.d.cts.map +0 -1
  139. package/build/modern/hydration-gHEs4kLM.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"mutation.cjs","names":["Removable","createRetryer"],"sources":["../../src/mutation.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Removable } from './removable'\nimport { createRetryer } from './retryer'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationMeta,\n MutationOptions,\n MutationStatus,\n} from './types'\nimport type { MutationCache } from './mutationCache'\nimport type { MutationObserver } from './mutationObserver'\nimport type { Retryer } from './retryer'\nimport type { QueryClient } from './queryClient'\n\n// TYPES\n\ninterface MutationConfig<TData, TError, TVariables, TOnMutateResult> {\n client: QueryClient\n mutationId: number\n mutationCache: MutationCache\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>\n}\n\n/**\n * The raw state stored on a `Mutation` instance. This is the underlying state\n * that observer results (e.g. `MutationObserverResult`) are derived from.\n */\nexport interface MutationState<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> {\n /**\n * The value returned by `onMutate`, if defined. Passed to `onSuccess`,\n * `onError` and `onSettled` as the mutation's context.\n */\n context: TOnMutateResult | undefined\n /**\n * The last successfully resolved data for the mutation.\n */\n data: TData | undefined\n /**\n * The error object for the mutation, if the last attempt resulted in an error.\n * - Defaults to `null`.\n */\n error: TError | null\n /**\n * The number of times the mutation function has failed for the current attempt.\n */\n failureCount: number\n /**\n * The reason the current attempt failed, as reported by the retryer.\n */\n failureReason: TError | null\n /**\n * Whether the mutation is currently paused (see network mode), or is\n * waiting for another mutation with the same `scope` to finish.\n */\n isPaused: boolean\n /**\n * The status of the mutation.\n */\n status: MutationStatus\n /**\n * The variables the mutation was last called with.\n */\n variables: TVariables | undefined\n /**\n * The timestamp for when the mutation was submitted.\n */\n submittedAt: number\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError | null\n}\n\ninterface PendingAction<TVariables, TOnMutateResult> {\n type: 'pending'\n isPaused: boolean\n variables?: TVariables\n context?: TOnMutateResult\n}\n\ninterface SuccessAction<TData> {\n type: 'success'\n data: TData\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\n/**\n * The actions a mutation dispatches to update its state, e.g. when it starts, fails, pauses, or\n * succeeds.\n */\nexport type Action<TData, TError, TVariables, TOnMutateResult> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | PendingAction<TVariables, TOnMutateResult>\n | PauseAction\n | SuccessAction<TData>\n\n// CLASS\n\n/**\n * Represents a single mutation attempt. A `Mutation` holds the mutation's\n * options, state (data/error/status), and the `MutationObserver`s currently\n * subscribed to it.\n *\n * Instances are created and managed internally by `MutationCache`; application\n * code typically interacts with mutations indirectly through `QueryClient` or\n * a framework hook like `useMutation`. Direct access to a `Mutation` instance\n * is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * ```\n */\nexport class Mutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> extends Removable {\n state: MutationState<TData, TError, TVariables, TOnMutateResult>\n options!: MutationOptions<TData, TError, TVariables, TOnMutateResult>\n readonly mutationId: number\n\n #client: QueryClient\n #observers: Array<\n MutationObserver<TData, TError, TVariables, TOnMutateResult>\n >\n #mutationCache: MutationCache\n #retryer?: Retryer<TData>\n\n constructor(\n config: MutationConfig<TData, TError, TVariables, TOnMutateResult>,\n ) {\n super()\n\n this.#client = config.client\n this.mutationId = config.mutationId\n this.#mutationCache = config.mutationCache\n this.#observers = []\n this.state = config.state || getDefaultState()\n\n this.setOptions(config.options)\n this.scheduleGc()\n }\n\n /**\n * Replaces the mutation's options and applies their `gcTime`.\n * @internal\n * @param options - The new mutation options.\n */\n setOptions(\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.options = options\n\n this.updateGcTime(this.options.gcTime)\n }\n\n /**\n * The `meta` object passed in the mutation's options, if any.\n * @returns The mutation's `meta`, or `undefined` if none was set.\n */\n get meta(): MutationMeta | undefined {\n return this.options.meta\n }\n\n /**\n * Subscribes an observer to the mutation and stops its garbage collection.\n * @internal\n * @param observer - The observer to add. Adding an observer that is already subscribed does\n * nothing.\n */\n addObserver(observer: MutationObserver<any, any, any, any>): void {\n if (!this.#observers.includes(observer)) {\n this.#observers.push(observer)\n\n // Stop the mutation from being garbage collected\n this.clearGcTimeout()\n\n this.#mutationCache.notify({\n type: 'observerAdded',\n mutation: this,\n observer,\n })\n }\n }\n\n /**\n * Unsubscribes an observer from the mutation.\n * @internal\n * @param observer - The observer to remove. Garbage collection is scheduled afterwards.\n */\n removeObserver(observer: MutationObserver<any, any, any, any>): void {\n this.#observers = this.#observers.filter((x) => x !== observer)\n\n this.scheduleGc()\n\n this.#mutationCache.notify({\n type: 'observerRemoved',\n mutation: this,\n observer,\n })\n }\n\n protected override optionalRemove() {\n if (!this.#observers.length) {\n if (this.state.status === 'pending') {\n this.scheduleGc()\n } else {\n this.#mutationCache.remove(this)\n }\n }\n }\n\n /**\n * Resumes a mutation that is currently paused or was restored from a\n * dehydrated, still-`pending` state.\n *\n * - If this mutation has an active retryer (it paused mid-attempt, e.g. due\n * to the network mode or scope-based queuing), its retryer is resumed.\n * - Otherwise, if the mutation's status is still `pending` (e.g. it was\n * dehydrated while an attempt was in flight and never got a retryer in\n * this instance), `execute` is called again with the last known variables.\n * - Otherwise the mutation has already settled and this resolves immediately\n * without running anything again.\n * @returns A promise that settles with the resumed mutation: it rejects if the mutation fails.\n * It resolves immediately if the mutation has already settled.\n * @see {@link Mutation#execute}\n * @example\n * ```ts\n * // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * await mutation?.continue()\n * ```\n */\n continue(): Promise<unknown> {\n return (\n this.#retryer?.continue() ??\n // continuing a mutation assumes that variables are set, mutation must have been dehydrated before.\n // a settled mutation has no retryer to continue and must not run again\n (this.state.status === 'pending'\n ? this.execute(this.state.variables!)\n : Promise.resolve())\n )\n }\n\n /**\n * Runs the mutation function for the given variables through a retryer, and\n * drives the mutation's state and lifecycle callbacks through to settlement.\n *\n * If this mutation's state is already `pending` when `execute` is called\n * (i.e. it was restored, still in-flight, from a dehydrated state), the\n * `onMutate` step is skipped and a `continue` action is dispatched to\n * unpause it; otherwise a `pending` action is dispatched first, then the\n * mutation cache's `onMutate` and the mutation's own `onMutate` option are\n * awaited in that order, and the resulting context is stored.\n *\n * The mutation function is then run (subject to `retry`/`retryDelay`/\n * `networkMode`, and to the mutation cache's scope-based serialization).\n * On success, the cache's `onSuccess`/`onSettled` callbacks run before the\n * mutation's own `onSuccess`/`onSettled` options, a `success` action is\n * dispatched, and the resolved data is returned. On failure, the same\n * cache-then-option ordering is used for `onError`/`onSettled`, but each of\n * those four callbacks is individually caught so that a throwing callback\n * cannot mask the original error; an `error` action is then dispatched and\n * the original error is re-thrown.\n * @param variables - The variables passed to the `mutationFn`.\n * @returns A promise that resolves with the mutation's data, or rejects with its error.\n * @see {@link Mutation#continue}\n * @example\n * ```ts\n * // Called internally by `MutationObserver.mutate` and `Mutation.continue` —\n * // applications normally trigger mutations through those, not this method.\n * const data = await mutation.execute(variables)\n * ```\n */\n async execute(variables: TVariables): Promise<TData> {\n const onContinue = () => {\n this.#dispatch({ type: 'continue' })\n }\n\n const mutationFnContext = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n const retryer = (this.#retryer = createRetryer({\n fn: () => {\n if (!this.options.mutationFn) {\n return Promise.reject(new Error('No mutationFn found'))\n }\n\n return this.options.mutationFn(variables, mutationFnContext)\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue,\n retry: this.options.retry ?? 0,\n retryDelay: this.options.retryDelay,\n networkMode: this.options.networkMode,\n canRun: () => this.#mutationCache.canRun(this),\n }))\n\n const restored = this.state.status === 'pending'\n const isPaused = !retryer.canStart()\n\n try {\n if (restored) {\n // Dispatch continue action to unpause restored mutation\n onContinue()\n } else {\n this.#dispatch({ type: 'pending', variables, isPaused })\n // Notify cache callback\n if (this.#mutationCache.config.onMutate) {\n await this.#mutationCache.config.onMutate(\n variables,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n }\n const context = await this.options.onMutate?.(\n variables,\n mutationFnContext,\n )\n if (context !== this.state.context) {\n this.#dispatch({\n type: 'pending',\n context,\n variables,\n isPaused,\n })\n }\n }\n const data = await retryer.start()\n\n // Notify cache callback\n await this.#mutationCache.config.onSuccess?.(\n data,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n\n await this.options.onSuccess?.(\n data,\n variables,\n this.state.context!,\n mutationFnContext,\n )\n\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n data,\n null,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n\n await this.options.onSettled?.(\n data,\n null,\n variables,\n this.state.context,\n mutationFnContext,\n )\n\n this.#dispatch({ type: 'success', data })\n return data\n } catch (error) {\n try {\n // Notify cache callback\n await this.#mutationCache.config.onError?.(\n error as any,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n await this.options.onError?.(\n error as TError,\n variables,\n this.state.context,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n undefined,\n error as any,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n await this.options.onSettled?.(\n undefined,\n error as TError,\n variables,\n this.state.context,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n this.#dispatch({ type: 'error', error: error as TError })\n throw error\n } finally {\n // The settled retryer's promise would otherwise pin this mutation's\n // result, variables and context for as long as the cache keeps it\n if (this.#retryer === retryer) {\n this.#retryer = undefined\n }\n this.#mutationCache.runNext(this)\n }\n }\n\n #dispatch(action: Action<TData, TError, TVariables, TOnMutateResult>): void {\n const reducer = (\n state: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): MutationState<TData, TError, TVariables, TOnMutateResult> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n failureCount: action.failureCount,\n failureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n isPaused: true,\n }\n case 'continue':\n return {\n ...state,\n isPaused: false,\n }\n case 'pending':\n return {\n ...state,\n context: action.context,\n data: undefined,\n failureCount: 0,\n failureReason: null,\n error: null,\n isPaused: action.isPaused,\n status: 'pending',\n variables: action.variables,\n submittedAt: Date.now(),\n }\n case 'success':\n return {\n ...state,\n data: action.data,\n failureCount: 0,\n failureReason: null,\n error: null,\n status: 'success',\n isPaused: false,\n }\n case 'error':\n return {\n ...state,\n data: undefined,\n error: action.error,\n failureCount: state.failureCount + 1,\n failureReason: action.error,\n isPaused: false,\n status: 'error',\n }\n }\n }\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n this.#observers.forEach((observer) => {\n observer.onMutationUpdate(action)\n })\n this.#mutationCache.notify({\n mutation: this,\n type: 'updated',\n action,\n })\n })\n }\n}\n\n/**\n * Returns the initial state of a mutation: `'idle'`, with no data, error, or variables.\n * @returns The initial mutation state.\n */\nexport function getDefaultState<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n>(): MutationState<TData, TError, TVariables, TOnMutateResult> {\n return {\n context: undefined,\n data: undefined,\n error: null,\n failureCount: 0,\n failureReason: null,\n isPaused: false,\n status: 'idle',\n variables: undefined,\n submittedAt: 0,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyIA,IAAa,WAAb,cAKUA,kBAAAA,UAAU;CAYlB,YACE,QACA;EACA,MAAM;;;;;;EAEN,8BAAA,uBAAA,SAAA,MAAe,OAAO,MAAA;EACtB,KAAK,aAAa,OAAO;EACzB,8BAAA,uBAAA,gBAAA,MAAsB,OAAO,aAAA;EAC7B,8BAAA,uBAAA,YAAA,MAAkB,CAAC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,KAAK,SACH,OAAO;IACL,GAAG;IACH,UAAU;GACZ;GACF,KAAK,YACH,OAAO;IACL,GAAG;IACH,UAAU;GACZ;GACF,KAAK,WACH,OAAO;IACL,GAAG;IACH,SAAS,OAAO;IAChB,MAAM,KAAA;IACN,cAAc;IACd,eAAe;IACf,OAAO;IACP,UAAU,OAAO;IACjB,QAAQ;IACR,WAAW,OAAO;IAClB,aAAa,KAAK,IAAI;GACxB;GACF,KAAK,WACH,OAAO;IACL,GAAG;IACH,MAAM,OAAO;IACb,cAAc;IACd,eAAe;IACf,OAAO;IACP,QAAQ;IACR,UAAU;GACZ;GACF,KAAK,SACH,OAAO;IACL,GAAG;IACH,MAAM,KAAA;IACN,OAAO,OAAO;IACd,cAAc,MAAM,eAAe;IACnC,eAAe,OAAO;IACtB,UAAU;IACV,QAAQ;GACV;EACJ;CACF;CACA,KAAK,QAAQ,QAAQ,KAAK,KAAK;CAE/B,sBAAA,cAAc,YAAY;EACxB,8BAAA,uBAAA,YAAA,IAAA,CAAA,CAAgB,SAAS,aAAa;GACpC,SAAS,iBAAiB,MAAM;EAClC,CAAC;EACD,8BAAA,uBAAA,gBAAA,IAAA,CAAA,CAAoB,OAAO;GACzB,UAAU;GACV,MAAM;GACN;EACF,CAAC;CACH,CAAC;AACH;;;;;AAOF,SAAgB,kBAK+C;CAC7D,OAAO;EACL,SAAS,KAAA;EACT,MAAM,KAAA;EACN,OAAO;EACP,cAAc;EACd,eAAe;EACf,UAAU;EACV,QAAQ;EACR,WAAW,KAAA;EACX,aAAa;CACf;AACF"}
1
+ {"version":3,"file":"mutation.cjs","names":["Removable","createRetryer"],"sources":["../../src/mutation.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Removable } from './removable'\nimport { createRetryer } from './retryer'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationMeta,\n MutationOptions,\n MutationStatus,\n} from './types'\nimport type { MutationCache } from './mutationCache'\nimport type { MutationObserver } from './mutationObserver'\nimport type { Retryer } from './retryer'\nimport type { QueryClient } from './queryClient'\n\n// TYPES\n\ninterface MutationConfig<TData, TError, TVariables, TOnMutateResult> {\n client: QueryClient\n mutationId: number\n mutationCache: MutationCache\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>\n}\n\n/**\n * The raw state stored on a `Mutation` instance. This is the underlying state\n * that observer results (e.g. `MutationObserverResult`) are derived from.\n */\nexport interface MutationState<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> {\n /**\n * The value returned by `onMutate`, if defined. Passed to `onSuccess`,\n * `onError` and `onSettled` as the mutation's context.\n */\n context: TOnMutateResult | undefined\n /**\n * The last successfully resolved data for the mutation.\n */\n data: TData | undefined\n /**\n * The error object for the mutation, if the last attempt resulted in an error.\n * - Defaults to `null`.\n */\n error: TError | null\n /**\n * The number of times the mutation function has failed for the current attempt.\n */\n failureCount: number\n /**\n * The reason the current attempt failed, as reported by the retryer.\n */\n failureReason: TError | null\n /**\n * Whether the mutation is currently paused (see network mode), or is\n * waiting for another mutation with the same `scope` to finish.\n */\n isPaused: boolean\n /**\n * The status of the mutation.\n */\n status: MutationStatus\n /**\n * The variables the mutation was last called with.\n */\n variables: TVariables | undefined\n /**\n * The timestamp for when the mutation was submitted.\n */\n submittedAt: number\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError | null\n}\n\ninterface PendingAction<TVariables, TOnMutateResult> {\n type: 'pending'\n isPaused: boolean\n variables?: TVariables\n context?: TOnMutateResult\n}\n\ninterface SuccessAction<TData> {\n type: 'success'\n data: TData\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\n/**\n * The actions a mutation dispatches to update its state, e.g. when it starts, fails, pauses, or\n * succeeds.\n */\nexport type Action<TData, TError, TVariables, TOnMutateResult> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | PendingAction<TVariables, TOnMutateResult>\n | PauseAction\n | SuccessAction<TData>\n\n// CLASS\n\n/**\n * Represents a single mutation attempt. A `Mutation` holds the mutation's\n * options, state (data/error/status), and the `MutationObserver`s currently\n * subscribed to it.\n *\n * Instances are created and managed internally by `MutationCache`; application\n * code typically interacts with mutations indirectly through `QueryClient` or\n * a framework hook like `useMutation`. Direct access to a `Mutation` instance\n * is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * ```\n */\nexport class Mutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> extends Removable {\n state: MutationState<TData, TError, TVariables, TOnMutateResult>\n options!: MutationOptions<TData, TError, TVariables, TOnMutateResult>\n readonly mutationId: number\n\n #client: QueryClient\n #observers: Array<\n MutationObserver<TData, TError, TVariables, TOnMutateResult>\n >\n #mutationCache: MutationCache\n #retryer?: Retryer<TData>\n\n constructor(\n config: MutationConfig<TData, TError, TVariables, TOnMutateResult>,\n ) {\n super()\n\n this.#client = config.client\n this.mutationId = config.mutationId\n this.#mutationCache = config.mutationCache\n this.#observers = []\n this.state = config.state || getDefaultState()\n\n this.setOptions(config.options)\n this.scheduleGc()\n }\n\n /**\n * Replaces the mutation's options and applies their `gcTime`.\n * @internal\n * @param options - The new mutation options.\n */\n setOptions(\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.options = options\n\n this.updateGcTime(this.options.gcTime)\n }\n\n /**\n * The `meta` object passed in the mutation's options, if any.\n * @returns The mutation's `meta`, or `undefined` if none was set.\n */\n get meta(): MutationMeta | undefined {\n return this.options.meta\n }\n\n /**\n * Subscribes an observer to the mutation and stops its garbage collection.\n * @internal\n * @param observer - The observer to add. Adding an observer that is already subscribed does\n * nothing.\n */\n addObserver(observer: MutationObserver<any, any, any, any>): void {\n if (!this.#observers.includes(observer)) {\n this.#observers.push(observer)\n\n // Stop the mutation from being garbage collected\n this.clearGcTimeout()\n\n this.#mutationCache.notify({\n type: 'observerAdded',\n mutation: this,\n observer,\n })\n }\n }\n\n /**\n * Unsubscribes an observer from the mutation.\n * @internal\n * @param observer - The observer to remove. Garbage collection is scheduled afterwards.\n */\n removeObserver(observer: MutationObserver<any, any, any, any>): void {\n this.#observers = this.#observers.filter((x) => x !== observer)\n\n this.scheduleGc()\n\n this.#mutationCache.notify({\n type: 'observerRemoved',\n mutation: this,\n observer,\n })\n }\n\n protected override optionalRemove() {\n if (!this.#observers.length) {\n if (this.state.status === 'pending') {\n this.scheduleGc()\n } else {\n this.#mutationCache.remove(this)\n }\n }\n }\n\n /**\n * Resumes a mutation that is currently paused or was restored from a\n * dehydrated, still-`pending` state.\n *\n * - If this mutation has an active retryer (it paused mid-attempt, e.g. due\n * to the network mode or scope-based queuing), its retryer is resumed.\n * - Otherwise, if the mutation's status is still `pending` (e.g. it was\n * dehydrated while an attempt was in flight and never got a retryer in\n * this instance), `execute` is called again with the last known variables.\n * - Otherwise the mutation has already settled and this resolves immediately\n * without running anything again.\n * @returns A promise that settles with the resumed mutation: it rejects if the mutation fails.\n * It resolves immediately if the mutation has already settled.\n * @see {@link Mutation#execute}\n * @example\n * ```ts\n * // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * await mutation?.continue()\n * ```\n */\n continue(): Promise<unknown> {\n return (\n this.#retryer?.continue() ??\n // continuing a mutation assumes that variables are set, mutation must have been dehydrated before.\n // a settled mutation has no retryer to continue and must not run again\n (this.state.status === 'pending'\n ? this.execute(this.state.variables!)\n : Promise.resolve())\n )\n }\n\n /**\n * Runs the mutation function for the given variables through a retryer, and\n * drives the mutation's state and lifecycle callbacks through to settlement.\n *\n * If this mutation's state is already `pending` when `execute` is called\n * (i.e. it was restored, still in-flight, from a dehydrated state), the\n * `onMutate` step is skipped and a `continue` action is dispatched to\n * unpause it; otherwise a `pending` action is dispatched first, then the\n * mutation cache's `onMutate` and the mutation's own `onMutate` option are\n * awaited in that order, and the resulting context is stored.\n *\n * The mutation function is then run (subject to `retry`/`retryDelay`/\n * `networkMode`, and to the mutation cache's scope-based serialization).\n * On success, the cache's `onSuccess`/`onSettled` callbacks run before the\n * mutation's own `onSuccess`/`onSettled` options, a `success` action is\n * dispatched, and the resolved data is returned. On failure, the same\n * cache-then-option ordering is used for `onError`/`onSettled`, but each of\n * those four callbacks is individually caught so that a throwing callback\n * cannot mask the original error; an `error` action is then dispatched and\n * the original error is re-thrown.\n * @param variables - The variables passed to the `mutationFn`.\n * @returns A promise that resolves with the mutation's data, or rejects with its error.\n * @see {@link Mutation#continue}\n * @example\n * ```ts\n * // Called internally by `MutationObserver.mutate` and `Mutation.continue` —\n * // applications normally trigger mutations through those, not this method.\n * const data = await mutation.execute(variables)\n * ```\n */\n async execute(variables: TVariables): Promise<TData> {\n const onContinue = () => {\n this.#dispatch({ type: 'continue' })\n }\n\n const mutationFnContext = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n const retryer = (this.#retryer = createRetryer({\n fn: () => {\n if (!this.options.mutationFn) {\n return Promise.reject(new Error('No mutationFn found'))\n }\n\n return this.options.mutationFn(variables, mutationFnContext)\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue,\n retry: this.options.retry ?? 0,\n retryDelay: this.options.retryDelay,\n networkMode: this.options.networkMode,\n canRun: () => this.#mutationCache.canRun(this),\n }))\n\n const restored = this.state.status === 'pending'\n const isPaused = !retryer.canStart()\n\n try {\n if (restored) {\n // Dispatch continue action to unpause restored mutation\n onContinue()\n } else {\n this.#dispatch({ type: 'pending', variables, isPaused })\n // Notify cache callback\n if (this.#mutationCache.config.onMutate) {\n await this.#mutationCache.config.onMutate(\n variables,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n }\n const context = await this.options.onMutate?.(\n variables,\n mutationFnContext,\n )\n if (context !== this.state.context) {\n this.#dispatch({\n type: 'pending',\n context,\n variables,\n isPaused,\n })\n }\n }\n // Unpause a mutation that became able to start while onMutate was running\n if (this.state.isPaused && retryer.canStart()) {\n onContinue()\n }\n const data = await retryer.start()\n\n // Notify cache callback\n await this.#mutationCache.config.onSuccess?.(\n data,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n\n await this.options.onSuccess?.(\n data,\n variables,\n this.state.context!,\n mutationFnContext,\n )\n\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n data,\n null,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n\n await this.options.onSettled?.(\n data,\n null,\n variables,\n this.state.context,\n mutationFnContext,\n )\n\n this.#dispatch({ type: 'success', data })\n return data\n } catch (error) {\n try {\n // Notify cache callback\n await this.#mutationCache.config.onError?.(\n error as any,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n await this.options.onError?.(\n error as TError,\n variables,\n this.state.context,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n undefined,\n error as any,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n await this.options.onSettled?.(\n undefined,\n error as TError,\n variables,\n this.state.context,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n this.#dispatch({ type: 'error', error: error as TError })\n throw error\n } finally {\n // The settled retryer's promise would otherwise pin this mutation's\n // result, variables and context for as long as the cache keeps it\n if (this.#retryer === retryer) {\n this.#retryer = undefined\n }\n this.#mutationCache.runNext(this)\n }\n }\n\n #dispatch(action: Action<TData, TError, TVariables, TOnMutateResult>): void {\n const reducer = (\n state: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): MutationState<TData, TError, TVariables, TOnMutateResult> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n failureCount: action.failureCount,\n failureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n isPaused: true,\n }\n case 'continue':\n return {\n ...state,\n isPaused: false,\n }\n case 'pending':\n return {\n ...state,\n context: action.context,\n data: undefined,\n failureCount: 0,\n failureReason: null,\n error: null,\n isPaused: action.isPaused,\n status: 'pending',\n variables: action.variables,\n submittedAt: Date.now(),\n }\n case 'success':\n return {\n ...state,\n data: action.data,\n failureCount: 0,\n failureReason: null,\n error: null,\n status: 'success',\n isPaused: false,\n }\n case 'error':\n return {\n ...state,\n data: undefined,\n error: action.error,\n failureCount: state.failureCount + 1,\n failureReason: action.error,\n isPaused: false,\n status: 'error',\n }\n }\n }\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n this.#observers.forEach((observer) => {\n observer.onMutationUpdate(action)\n })\n this.#mutationCache.notify({\n mutation: this,\n type: 'updated',\n action,\n })\n })\n }\n}\n\n/**\n * Returns the initial state of a mutation: `'idle'`, with no data, error, or variables.\n * @returns The initial mutation state.\n */\nexport function getDefaultState<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n>(): MutationState<TData, TError, TVariables, TOnMutateResult> {\n return {\n context: undefined,\n data: undefined,\n error: null,\n failureCount: 0,\n failureReason: null,\n isPaused: false,\n status: 'idle',\n variables: undefined,\n submittedAt: 0,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyIA,IAAa,WAAb,cAKUA,kBAAAA,UAAU;CAYlB,YACE,QACA;EACA,MAAM;;;;;;EAEN,8BAAA,uBAAA,SAAA,MAAe,OAAO,MAAA;EACtB,KAAK,aAAa,OAAO;EACzB,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,QAAkE;CAC1E,MAAM,WACJ,UAC8D;EAC9D,QAAQ,OAAO,MAAf;GACE,KAAK,UACH,OAAO;IACL,GAAG;IACH,cAAc,OAAO;IACrB,eAAe,OAAO;GACxB;GACF,KAAK,SACH,OAAO;IACL,GAAG;IACH,UAAU;GACZ;GACF,KAAK,YACH,OAAO;IACL,GAAG;IACH,UAAU;GACZ;GACF,KAAK,WACH,OAAO;IACL,GAAG;IACH,SAAS,OAAO;IAChB,MAAM,KAAA;IACN,cAAc;IACd,eAAe;IACf,OAAO;IACP,UAAU,OAAO;IACjB,QAAQ;IACR,WAAW,OAAO;IAClB,aAAa,KAAK,IAAI;GACxB;GACF,KAAK,WACH,OAAO;IACL,GAAG;IACH,MAAM,OAAO;IACb,cAAc;IACd,eAAe;IACf,OAAO;IACP,QAAQ;IACR,UAAU;GACZ;GACF,KAAK,SACH,OAAO;IACL,GAAG;IACH,MAAM,KAAA;IACN,OAAO,OAAO;IACd,cAAc,MAAM,eAAe;IACnC,eAAe,OAAO;IACtB,UAAU;IACV,QAAQ;GACV;EACJ;CACF;CACA,KAAK,QAAQ,QAAQ,KAAK,KAAK;CAE/B,sBAAA,cAAc,YAAY;EACxB,8BAAA,uBAAA,YAAA,IAAA,CAAA,CAAgB,SAAS,aAAa;GACpC,SAAS,iBAAiB,MAAM;EAClC,CAAC;EACD,8BAAA,uBAAA,gBAAA,IAAA,CAAA,CAAoB,OAAO;GACzB,UAAU;GACV,MAAM;GACN;EACF,CAAC;CACH,CAAC;AACH;;;;;AAOF,SAAgB,kBAK+C;CAC7D,OAAO;EACL,SAAS,KAAA;EACT,MAAM,KAAA;EACN,OAAO;EACP,cAAc;EACd,eAAe;EACf,UAAU;EACV,QAAQ;EACR,WAAW,KAAA;EACX,aAAa;CACf;AACF"}
@@ -1,2 +1,2 @@
1
- import { Bn as Action, Hn as MutationState, Un as getDefaultState, Vn as Mutation } from "./hydration-DdkP3REv.cjs";
1
+ import { Gn as getDefaultState, Hn as Action, Un as Mutation, Wn as MutationState } from "./hydration-BXjqUj_D.cjs";
2
2
  export { Action, Mutation, MutationState, getDefaultState };
@@ -1,2 +1,2 @@
1
- import { Bn as Action, Hn as MutationState, Un as getDefaultState, Vn as Mutation } from "./hydration-gHEs4kLM.js";
1
+ import { Gn as getDefaultState, Hn as Action, Un as Mutation, Wn as MutationState } from "./hydration-vgIjIhk6.js";
2
2
  export { Action, Mutation, MutationState, getDefaultState };
@@ -200,6 +200,7 @@ var Mutation = class extends Removable {
200
200
  isPaused
201
201
  });
202
202
  }
203
+ if (this.state.isPaused && retryer.canStart()) onContinue();
203
204
  const data = await retryer.start();
204
205
  await ((_classPrivateFieldGet3 = (_classPrivateFieldGet4 = _classPrivateFieldGet2(_mutationCache, this).config).onSuccess) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.call(_classPrivateFieldGet4, data, variables, this.state.context, this, mutationFnContext));
205
206
  await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) === null || _this$options$onSucce === void 0 ? void 0 : _this$options$onSucce.call(_this$options2, data, variables, this.state.context, mutationFnContext));
@@ -1 +1 @@
1
- {"version":3,"file":"mutation.js","names":[],"sources":["../../src/mutation.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Removable } from './removable'\nimport { createRetryer } from './retryer'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationMeta,\n MutationOptions,\n MutationStatus,\n} from './types'\nimport type { MutationCache } from './mutationCache'\nimport type { MutationObserver } from './mutationObserver'\nimport type { Retryer } from './retryer'\nimport type { QueryClient } from './queryClient'\n\n// TYPES\n\ninterface MutationConfig<TData, TError, TVariables, TOnMutateResult> {\n client: QueryClient\n mutationId: number\n mutationCache: MutationCache\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>\n}\n\n/**\n * The raw state stored on a `Mutation` instance. This is the underlying state\n * that observer results (e.g. `MutationObserverResult`) are derived from.\n */\nexport interface MutationState<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> {\n /**\n * The value returned by `onMutate`, if defined. Passed to `onSuccess`,\n * `onError` and `onSettled` as the mutation's context.\n */\n context: TOnMutateResult | undefined\n /**\n * The last successfully resolved data for the mutation.\n */\n data: TData | undefined\n /**\n * The error object for the mutation, if the last attempt resulted in an error.\n * - Defaults to `null`.\n */\n error: TError | null\n /**\n * The number of times the mutation function has failed for the current attempt.\n */\n failureCount: number\n /**\n * The reason the current attempt failed, as reported by the retryer.\n */\n failureReason: TError | null\n /**\n * Whether the mutation is currently paused (see network mode), or is\n * waiting for another mutation with the same `scope` to finish.\n */\n isPaused: boolean\n /**\n * The status of the mutation.\n */\n status: MutationStatus\n /**\n * The variables the mutation was last called with.\n */\n variables: TVariables | undefined\n /**\n * The timestamp for when the mutation was submitted.\n */\n submittedAt: number\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError | null\n}\n\ninterface PendingAction<TVariables, TOnMutateResult> {\n type: 'pending'\n isPaused: boolean\n variables?: TVariables\n context?: TOnMutateResult\n}\n\ninterface SuccessAction<TData> {\n type: 'success'\n data: TData\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\n/**\n * The actions a mutation dispatches to update its state, e.g. when it starts, fails, pauses, or\n * succeeds.\n */\nexport type Action<TData, TError, TVariables, TOnMutateResult> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | PendingAction<TVariables, TOnMutateResult>\n | PauseAction\n | SuccessAction<TData>\n\n// CLASS\n\n/**\n * Represents a single mutation attempt. A `Mutation` holds the mutation's\n * options, state (data/error/status), and the `MutationObserver`s currently\n * subscribed to it.\n *\n * Instances are created and managed internally by `MutationCache`; application\n * code typically interacts with mutations indirectly through `QueryClient` or\n * a framework hook like `useMutation`. Direct access to a `Mutation` instance\n * is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * ```\n */\nexport class Mutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> extends Removable {\n state: MutationState<TData, TError, TVariables, TOnMutateResult>\n options!: MutationOptions<TData, TError, TVariables, TOnMutateResult>\n readonly mutationId: number\n\n #client: QueryClient\n #observers: Array<\n MutationObserver<TData, TError, TVariables, TOnMutateResult>\n >\n #mutationCache: MutationCache\n #retryer?: Retryer<TData>\n\n constructor(\n config: MutationConfig<TData, TError, TVariables, TOnMutateResult>,\n ) {\n super()\n\n this.#client = config.client\n this.mutationId = config.mutationId\n this.#mutationCache = config.mutationCache\n this.#observers = []\n this.state = config.state || getDefaultState()\n\n this.setOptions(config.options)\n this.scheduleGc()\n }\n\n /**\n * Replaces the mutation's options and applies their `gcTime`.\n * @internal\n * @param options - The new mutation options.\n */\n setOptions(\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.options = options\n\n this.updateGcTime(this.options.gcTime)\n }\n\n /**\n * The `meta` object passed in the mutation's options, if any.\n * @returns The mutation's `meta`, or `undefined` if none was set.\n */\n get meta(): MutationMeta | undefined {\n return this.options.meta\n }\n\n /**\n * Subscribes an observer to the mutation and stops its garbage collection.\n * @internal\n * @param observer - The observer to add. Adding an observer that is already subscribed does\n * nothing.\n */\n addObserver(observer: MutationObserver<any, any, any, any>): void {\n if (!this.#observers.includes(observer)) {\n this.#observers.push(observer)\n\n // Stop the mutation from being garbage collected\n this.clearGcTimeout()\n\n this.#mutationCache.notify({\n type: 'observerAdded',\n mutation: this,\n observer,\n })\n }\n }\n\n /**\n * Unsubscribes an observer from the mutation.\n * @internal\n * @param observer - The observer to remove. Garbage collection is scheduled afterwards.\n */\n removeObserver(observer: MutationObserver<any, any, any, any>): void {\n this.#observers = this.#observers.filter((x) => x !== observer)\n\n this.scheduleGc()\n\n this.#mutationCache.notify({\n type: 'observerRemoved',\n mutation: this,\n observer,\n })\n }\n\n protected override optionalRemove() {\n if (!this.#observers.length) {\n if (this.state.status === 'pending') {\n this.scheduleGc()\n } else {\n this.#mutationCache.remove(this)\n }\n }\n }\n\n /**\n * Resumes a mutation that is currently paused or was restored from a\n * dehydrated, still-`pending` state.\n *\n * - If this mutation has an active retryer (it paused mid-attempt, e.g. due\n * to the network mode or scope-based queuing), its retryer is resumed.\n * - Otherwise, if the mutation's status is still `pending` (e.g. it was\n * dehydrated while an attempt was in flight and never got a retryer in\n * this instance), `execute` is called again with the last known variables.\n * - Otherwise the mutation has already settled and this resolves immediately\n * without running anything again.\n * @returns A promise that settles with the resumed mutation: it rejects if the mutation fails.\n * It resolves immediately if the mutation has already settled.\n * @see {@link Mutation#execute}\n * @example\n * ```ts\n * // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * await mutation?.continue()\n * ```\n */\n continue(): Promise<unknown> {\n return (\n this.#retryer?.continue() ??\n // continuing a mutation assumes that variables are set, mutation must have been dehydrated before.\n // a settled mutation has no retryer to continue and must not run again\n (this.state.status === 'pending'\n ? this.execute(this.state.variables!)\n : Promise.resolve())\n )\n }\n\n /**\n * Runs the mutation function for the given variables through a retryer, and\n * drives the mutation's state and lifecycle callbacks through to settlement.\n *\n * If this mutation's state is already `pending` when `execute` is called\n * (i.e. it was restored, still in-flight, from a dehydrated state), the\n * `onMutate` step is skipped and a `continue` action is dispatched to\n * unpause it; otherwise a `pending` action is dispatched first, then the\n * mutation cache's `onMutate` and the mutation's own `onMutate` option are\n * awaited in that order, and the resulting context is stored.\n *\n * The mutation function is then run (subject to `retry`/`retryDelay`/\n * `networkMode`, and to the mutation cache's scope-based serialization).\n * On success, the cache's `onSuccess`/`onSettled` callbacks run before the\n * mutation's own `onSuccess`/`onSettled` options, a `success` action is\n * dispatched, and the resolved data is returned. On failure, the same\n * cache-then-option ordering is used for `onError`/`onSettled`, but each of\n * those four callbacks is individually caught so that a throwing callback\n * cannot mask the original error; an `error` action is then dispatched and\n * the original error is re-thrown.\n * @param variables - The variables passed to the `mutationFn`.\n * @returns A promise that resolves with the mutation's data, or rejects with its error.\n * @see {@link Mutation#continue}\n * @example\n * ```ts\n * // Called internally by `MutationObserver.mutate` and `Mutation.continue` —\n * // applications normally trigger mutations through those, not this method.\n * const data = await mutation.execute(variables)\n * ```\n */\n async execute(variables: TVariables): Promise<TData> {\n const onContinue = () => {\n this.#dispatch({ type: 'continue' })\n }\n\n const mutationFnContext = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n const retryer = (this.#retryer = createRetryer({\n fn: () => {\n if (!this.options.mutationFn) {\n return Promise.reject(new Error('No mutationFn found'))\n }\n\n return this.options.mutationFn(variables, mutationFnContext)\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue,\n retry: this.options.retry ?? 0,\n retryDelay: this.options.retryDelay,\n networkMode: this.options.networkMode,\n canRun: () => this.#mutationCache.canRun(this),\n }))\n\n const restored = this.state.status === 'pending'\n const isPaused = !retryer.canStart()\n\n try {\n if (restored) {\n // Dispatch continue action to unpause restored mutation\n onContinue()\n } else {\n this.#dispatch({ type: 'pending', variables, isPaused })\n // Notify cache callback\n if (this.#mutationCache.config.onMutate) {\n await this.#mutationCache.config.onMutate(\n variables,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n }\n const context = await this.options.onMutate?.(\n variables,\n mutationFnContext,\n )\n if (context !== this.state.context) {\n this.#dispatch({\n type: 'pending',\n context,\n variables,\n isPaused,\n })\n }\n }\n const data = await retryer.start()\n\n // Notify cache callback\n await this.#mutationCache.config.onSuccess?.(\n data,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n\n await this.options.onSuccess?.(\n data,\n variables,\n this.state.context!,\n mutationFnContext,\n )\n\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n data,\n null,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n\n await this.options.onSettled?.(\n data,\n null,\n variables,\n this.state.context,\n mutationFnContext,\n )\n\n this.#dispatch({ type: 'success', data })\n return data\n } catch (error) {\n try {\n // Notify cache callback\n await this.#mutationCache.config.onError?.(\n error as any,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n await this.options.onError?.(\n error as TError,\n variables,\n this.state.context,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n undefined,\n error as any,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n await this.options.onSettled?.(\n undefined,\n error as TError,\n variables,\n this.state.context,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n this.#dispatch({ type: 'error', error: error as TError })\n throw error\n } finally {\n // The settled retryer's promise would otherwise pin this mutation's\n // result, variables and context for as long as the cache keeps it\n if (this.#retryer === retryer) {\n this.#retryer = undefined\n }\n this.#mutationCache.runNext(this)\n }\n }\n\n #dispatch(action: Action<TData, TError, TVariables, TOnMutateResult>): void {\n const reducer = (\n state: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): MutationState<TData, TError, TVariables, TOnMutateResult> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n failureCount: action.failureCount,\n failureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n isPaused: true,\n }\n case 'continue':\n return {\n ...state,\n isPaused: false,\n }\n case 'pending':\n return {\n ...state,\n context: action.context,\n data: undefined,\n failureCount: 0,\n failureReason: null,\n error: null,\n isPaused: action.isPaused,\n status: 'pending',\n variables: action.variables,\n submittedAt: Date.now(),\n }\n case 'success':\n return {\n ...state,\n data: action.data,\n failureCount: 0,\n failureReason: null,\n error: null,\n status: 'success',\n isPaused: false,\n }\n case 'error':\n return {\n ...state,\n data: undefined,\n error: action.error,\n failureCount: state.failureCount + 1,\n failureReason: action.error,\n isPaused: false,\n status: 'error',\n }\n }\n }\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n this.#observers.forEach((observer) => {\n observer.onMutationUpdate(action)\n })\n this.#mutationCache.notify({\n mutation: this,\n type: 'updated',\n action,\n })\n })\n }\n}\n\n/**\n * Returns the initial state of a mutation: `'idle'`, with no data, error, or variables.\n * @returns The initial mutation state.\n */\nexport function getDefaultState<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n>(): MutationState<TData, TError, TVariables, TOnMutateResult> {\n return {\n context: undefined,\n data: undefined,\n error: null,\n failureCount: 0,\n failureReason: null,\n isPaused: false,\n status: 'idle',\n variables: undefined,\n submittedAt: 0,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyIA,IAAa,WAAb,cAKU,UAAU;CAYlB,YACE,QACA;EACA,MAAM;;;;;;EAEN,uBAAA,SAAA,MAAe,OAAO,MAAA;EACtB,KAAK,aAAa,OAAO;EACzB,uBAAA,gBAAA,MAAsB,OAAO,aAAA;EAC7B,uBAAA,YAAA,MAAkB,CAAC,CAAA;EACnB,KAAK,QAAQ,OAAO,SAAS,gBAAgB;EAE7C,KAAK,WAAW,OAAO,OAAO;EAC9B,KAAK,WAAW;CAClB;;;;;;CAOA,WACE,SACM;EACN,KAAK,UAAU;EAEf,KAAK,aAAa,KAAK,QAAQ,MAAM;CACvC;;;;;CAMA,IAAI,OAAiC;EACnC,OAAO,KAAK,QAAQ;CACtB;;;;;;;CAQA,YAAY,UAAsD;EAChE,IAAI,CAAA,uBAAA,YAAC,IAAA,C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;EACJ;CACF;CACA,KAAK,QAAQ,QAAQ,KAAK,KAAK;CAE/B,cAAc,YAAY;EACxB,uBAAA,YAAA,IAAA,CAAA,CAAgB,SAAS,aAAa;GACpC,SAAS,iBAAiB,MAAM;EAClC,CAAC;EACD,uBAAA,gBAAA,IAAA,CAAA,CAAoB,OAAO;GACzB,UAAU;GACV,MAAM;GACN;EACF,CAAC;CACH,CAAC;AACH;;;;;AAOF,SAAgB,kBAK+C;CAC7D,OAAO;EACL,SAAS,KAAA;EACT,MAAM,KAAA;EACN,OAAO;EACP,cAAc;EACd,eAAe;EACf,UAAU;EACV,QAAQ;EACR,WAAW,KAAA;EACX,aAAa;CACf;AACF"}
1
+ {"version":3,"file":"mutation.js","names":[],"sources":["../../src/mutation.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Removable } from './removable'\nimport { createRetryer } from './retryer'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationMeta,\n MutationOptions,\n MutationStatus,\n} from './types'\nimport type { MutationCache } from './mutationCache'\nimport type { MutationObserver } from './mutationObserver'\nimport type { Retryer } from './retryer'\nimport type { QueryClient } from './queryClient'\n\n// TYPES\n\ninterface MutationConfig<TData, TError, TVariables, TOnMutateResult> {\n client: QueryClient\n mutationId: number\n mutationCache: MutationCache\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>\n}\n\n/**\n * The raw state stored on a `Mutation` instance. This is the underlying state\n * that observer results (e.g. `MutationObserverResult`) are derived from.\n */\nexport interface MutationState<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> {\n /**\n * The value returned by `onMutate`, if defined. Passed to `onSuccess`,\n * `onError` and `onSettled` as the mutation's context.\n */\n context: TOnMutateResult | undefined\n /**\n * The last successfully resolved data for the mutation.\n */\n data: TData | undefined\n /**\n * The error object for the mutation, if the last attempt resulted in an error.\n * - Defaults to `null`.\n */\n error: TError | null\n /**\n * The number of times the mutation function has failed for the current attempt.\n */\n failureCount: number\n /**\n * The reason the current attempt failed, as reported by the retryer.\n */\n failureReason: TError | null\n /**\n * Whether the mutation is currently paused (see network mode), or is\n * waiting for another mutation with the same `scope` to finish.\n */\n isPaused: boolean\n /**\n * The status of the mutation.\n */\n status: MutationStatus\n /**\n * The variables the mutation was last called with.\n */\n variables: TVariables | undefined\n /**\n * The timestamp for when the mutation was submitted.\n */\n submittedAt: number\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError | null\n}\n\ninterface PendingAction<TVariables, TOnMutateResult> {\n type: 'pending'\n isPaused: boolean\n variables?: TVariables\n context?: TOnMutateResult\n}\n\ninterface SuccessAction<TData> {\n type: 'success'\n data: TData\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\n/**\n * The actions a mutation dispatches to update its state, e.g. when it starts, fails, pauses, or\n * succeeds.\n */\nexport type Action<TData, TError, TVariables, TOnMutateResult> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | PendingAction<TVariables, TOnMutateResult>\n | PauseAction\n | SuccessAction<TData>\n\n// CLASS\n\n/**\n * Represents a single mutation attempt. A `Mutation` holds the mutation's\n * options, state (data/error/status), and the `MutationObserver`s currently\n * subscribed to it.\n *\n * Instances are created and managed internally by `MutationCache`; application\n * code typically interacts with mutations indirectly through `QueryClient` or\n * a framework hook like `useMutation`. Direct access to a `Mutation` instance\n * is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.\n * @example\n * ```ts\n * const mutationCache = queryClient.getMutationCache()\n *\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * ```\n */\nexport class Mutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> extends Removable {\n state: MutationState<TData, TError, TVariables, TOnMutateResult>\n options!: MutationOptions<TData, TError, TVariables, TOnMutateResult>\n readonly mutationId: number\n\n #client: QueryClient\n #observers: Array<\n MutationObserver<TData, TError, TVariables, TOnMutateResult>\n >\n #mutationCache: MutationCache\n #retryer?: Retryer<TData>\n\n constructor(\n config: MutationConfig<TData, TError, TVariables, TOnMutateResult>,\n ) {\n super()\n\n this.#client = config.client\n this.mutationId = config.mutationId\n this.#mutationCache = config.mutationCache\n this.#observers = []\n this.state = config.state || getDefaultState()\n\n this.setOptions(config.options)\n this.scheduleGc()\n }\n\n /**\n * Replaces the mutation's options and applies their `gcTime`.\n * @internal\n * @param options - The new mutation options.\n */\n setOptions(\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.options = options\n\n this.updateGcTime(this.options.gcTime)\n }\n\n /**\n * The `meta` object passed in the mutation's options, if any.\n * @returns The mutation's `meta`, or `undefined` if none was set.\n */\n get meta(): MutationMeta | undefined {\n return this.options.meta\n }\n\n /**\n * Subscribes an observer to the mutation and stops its garbage collection.\n * @internal\n * @param observer - The observer to add. Adding an observer that is already subscribed does\n * nothing.\n */\n addObserver(observer: MutationObserver<any, any, any, any>): void {\n if (!this.#observers.includes(observer)) {\n this.#observers.push(observer)\n\n // Stop the mutation from being garbage collected\n this.clearGcTimeout()\n\n this.#mutationCache.notify({\n type: 'observerAdded',\n mutation: this,\n observer,\n })\n }\n }\n\n /**\n * Unsubscribes an observer from the mutation.\n * @internal\n * @param observer - The observer to remove. Garbage collection is scheduled afterwards.\n */\n removeObserver(observer: MutationObserver<any, any, any, any>): void {\n this.#observers = this.#observers.filter((x) => x !== observer)\n\n this.scheduleGc()\n\n this.#mutationCache.notify({\n type: 'observerRemoved',\n mutation: this,\n observer,\n })\n }\n\n protected override optionalRemove() {\n if (!this.#observers.length) {\n if (this.state.status === 'pending') {\n this.scheduleGc()\n } else {\n this.#mutationCache.remove(this)\n }\n }\n }\n\n /**\n * Resumes a mutation that is currently paused or was restored from a\n * dehydrated, still-`pending` state.\n *\n * - If this mutation has an active retryer (it paused mid-attempt, e.g. due\n * to the network mode or scope-based queuing), its retryer is resumed.\n * - Otherwise, if the mutation's status is still `pending` (e.g. it was\n * dehydrated while an attempt was in flight and never got a retryer in\n * this instance), `execute` is called again with the last known variables.\n * - Otherwise the mutation has already settled and this resolves immediately\n * without running anything again.\n * @returns A promise that settles with the resumed mutation: it rejects if the mutation fails.\n * It resolves immediately if the mutation has already settled.\n * @see {@link Mutation#execute}\n * @example\n * ```ts\n * // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()\n * const mutation = mutationCache.find({ mutationKey: ['addPost'] })\n * await mutation?.continue()\n * ```\n */\n continue(): Promise<unknown> {\n return (\n this.#retryer?.continue() ??\n // continuing a mutation assumes that variables are set, mutation must have been dehydrated before.\n // a settled mutation has no retryer to continue and must not run again\n (this.state.status === 'pending'\n ? this.execute(this.state.variables!)\n : Promise.resolve())\n )\n }\n\n /**\n * Runs the mutation function for the given variables through a retryer, and\n * drives the mutation's state and lifecycle callbacks through to settlement.\n *\n * If this mutation's state is already `pending` when `execute` is called\n * (i.e. it was restored, still in-flight, from a dehydrated state), the\n * `onMutate` step is skipped and a `continue` action is dispatched to\n * unpause it; otherwise a `pending` action is dispatched first, then the\n * mutation cache's `onMutate` and the mutation's own `onMutate` option are\n * awaited in that order, and the resulting context is stored.\n *\n * The mutation function is then run (subject to `retry`/`retryDelay`/\n * `networkMode`, and to the mutation cache's scope-based serialization).\n * On success, the cache's `onSuccess`/`onSettled` callbacks run before the\n * mutation's own `onSuccess`/`onSettled` options, a `success` action is\n * dispatched, and the resolved data is returned. On failure, the same\n * cache-then-option ordering is used for `onError`/`onSettled`, but each of\n * those four callbacks is individually caught so that a throwing callback\n * cannot mask the original error; an `error` action is then dispatched and\n * the original error is re-thrown.\n * @param variables - The variables passed to the `mutationFn`.\n * @returns A promise that resolves with the mutation's data, or rejects with its error.\n * @see {@link Mutation#continue}\n * @example\n * ```ts\n * // Called internally by `MutationObserver.mutate` and `Mutation.continue` —\n * // applications normally trigger mutations through those, not this method.\n * const data = await mutation.execute(variables)\n * ```\n */\n async execute(variables: TVariables): Promise<TData> {\n const onContinue = () => {\n this.#dispatch({ type: 'continue' })\n }\n\n const mutationFnContext = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n const retryer = (this.#retryer = createRetryer({\n fn: () => {\n if (!this.options.mutationFn) {\n return Promise.reject(new Error('No mutationFn found'))\n }\n\n return this.options.mutationFn(variables, mutationFnContext)\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue,\n retry: this.options.retry ?? 0,\n retryDelay: this.options.retryDelay,\n networkMode: this.options.networkMode,\n canRun: () => this.#mutationCache.canRun(this),\n }))\n\n const restored = this.state.status === 'pending'\n const isPaused = !retryer.canStart()\n\n try {\n if (restored) {\n // Dispatch continue action to unpause restored mutation\n onContinue()\n } else {\n this.#dispatch({ type: 'pending', variables, isPaused })\n // Notify cache callback\n if (this.#mutationCache.config.onMutate) {\n await this.#mutationCache.config.onMutate(\n variables,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n }\n const context = await this.options.onMutate?.(\n variables,\n mutationFnContext,\n )\n if (context !== this.state.context) {\n this.#dispatch({\n type: 'pending',\n context,\n variables,\n isPaused,\n })\n }\n }\n // Unpause a mutation that became able to start while onMutate was running\n if (this.state.isPaused && retryer.canStart()) {\n onContinue()\n }\n const data = await retryer.start()\n\n // Notify cache callback\n await this.#mutationCache.config.onSuccess?.(\n data,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n\n await this.options.onSuccess?.(\n data,\n variables,\n this.state.context!,\n mutationFnContext,\n )\n\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n data,\n null,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n\n await this.options.onSettled?.(\n data,\n null,\n variables,\n this.state.context,\n mutationFnContext,\n )\n\n this.#dispatch({ type: 'success', data })\n return data\n } catch (error) {\n try {\n // Notify cache callback\n await this.#mutationCache.config.onError?.(\n error as any,\n variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n await this.options.onError?.(\n error as TError,\n variables,\n this.state.context,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n // Notify cache callback\n await this.#mutationCache.config.onSettled?.(\n undefined,\n error as any,\n this.state.variables,\n this.state.context,\n this as Mutation<unknown, unknown, unknown, unknown>,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n try {\n await this.options.onSettled?.(\n undefined,\n error as TError,\n variables,\n this.state.context,\n mutationFnContext,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n\n this.#dispatch({ type: 'error', error: error as TError })\n throw error\n } finally {\n // The settled retryer's promise would otherwise pin this mutation's\n // result, variables and context for as long as the cache keeps it\n if (this.#retryer === retryer) {\n this.#retryer = undefined\n }\n this.#mutationCache.runNext(this)\n }\n }\n\n #dispatch(action: Action<TData, TError, TVariables, TOnMutateResult>): void {\n const reducer = (\n state: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): MutationState<TData, TError, TVariables, TOnMutateResult> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n failureCount: action.failureCount,\n failureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n isPaused: true,\n }\n case 'continue':\n return {\n ...state,\n isPaused: false,\n }\n case 'pending':\n return {\n ...state,\n context: action.context,\n data: undefined,\n failureCount: 0,\n failureReason: null,\n error: null,\n isPaused: action.isPaused,\n status: 'pending',\n variables: action.variables,\n submittedAt: Date.now(),\n }\n case 'success':\n return {\n ...state,\n data: action.data,\n failureCount: 0,\n failureReason: null,\n error: null,\n status: 'success',\n isPaused: false,\n }\n case 'error':\n return {\n ...state,\n data: undefined,\n error: action.error,\n failureCount: state.failureCount + 1,\n failureReason: action.error,\n isPaused: false,\n status: 'error',\n }\n }\n }\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n this.#observers.forEach((observer) => {\n observer.onMutationUpdate(action)\n })\n this.#mutationCache.notify({\n mutation: this,\n type: 'updated',\n action,\n })\n })\n }\n}\n\n/**\n * Returns the initial state of a mutation: `'idle'`, with no data, error, or variables.\n * @returns The initial mutation state.\n */\nexport function getDefaultState<\n TData,\n TError,\n TVariables,\n TOnMutateResult,\n>(): MutationState<TData, TError, TVariables, TOnMutateResult> {\n return {\n context: undefined,\n data: undefined,\n error: null,\n failureCount: 0,\n failureReason: null,\n isPaused: false,\n status: 'idle',\n variables: undefined,\n submittedAt: 0,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyIA,IAAa,WAAb,cAKU,UAAU;CAYlB,YACE,QACA;EACA,MAAM;;;;;;EAEN,uBAAA,SAAA,MAAe,OAAO,MAAA;EACtB,KAAK,aAAa,OAAO;EACzB,uBAAA,gBAAA,MAAsB,OAAO,aAAA;EAC7B,uBAAA,YAAA,MAAkB,CAAC,CAAA;EACnB,KAAK,QAAQ,OAAO,SAAS,gBAAgB;EAE7C,KAAK,WAAW,OAAO,OAAO;EAC9B,KAAK,WAAW;CAClB;;;;;;CAOA,WACE,SACM;EACN,KAAK,UAAU;EAEf,KAAK,aAAa,KAAK,QAAQ,MAAM;CACvC;;;;;CAMA,IAAI,OAAiC;EACnC,OAAO,KAAK,QAAQ;CACtB;;;;;;;CAQA,YAAY,UAAsD;EAChE,IAAI,CAAA,uBAAA,YAAC,IAAA,CAAA,CAAgB,SAAS,QAAQ,GAAG;GACvC,uBAAA,YAAA,IAAA,CAAA,CAAgB,KAAK,QAAQ;GAG7B,KAAK,eAAe;GAEpB,uBAAA,gBAAA,IAAA,CAAA,CAAoB,OAAO;IACzB,MAAM;IACN,UAAU;IACV;GACF,CAAC;EACH;CACF;;;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AM;EAClC,CAAC;EACD,uBAAA,gBAAA,IAAA,CAAA,CAAoB,OAAO;GACzB,UAAU;GACV,MAAM;GACN;EACF,CAAC;CACH,CAAC;AACH;;;;;AAOF,SAAgB,kBAK+C;CAC7D,OAAO;EACL,SAAS,KAAA;EACT,MAAM,KAAA;EACN,OAAO;EACP,cAAc;EACd,eAAe;EACf,UAAU;EACV,QAAQ;EACR,WAAW,KAAA;EACX,aAAa;CACf;AACF"}
@@ -1,2 +1,2 @@
1
- import { Gn as MutationCacheConfig, Kn as MutationCacheNotifyEvent, Wn as MutationCache } from "./hydration-DdkP3REv.cjs";
1
+ import { Jn as MutationCacheNotifyEvent, Kn as MutationCache, qn as MutationCacheConfig } from "./hydration-BXjqUj_D.cjs";
2
2
  export { MutationCache, MutationCacheConfig, MutationCacheNotifyEvent };
@@ -1,2 +1,2 @@
1
- import { Gn as MutationCacheConfig, Kn as MutationCacheNotifyEvent, Wn as MutationCache } from "./hydration-gHEs4kLM.js";
1
+ import { Jn as MutationCacheNotifyEvent, Kn as MutationCache, qn as MutationCacheConfig } from "./hydration-vgIjIhk6.js";
2
2
  export { MutationCache, MutationCacheConfig, MutationCacheNotifyEvent };
@@ -1,2 +1,2 @@
1
- import { qn as MutationObserver } from "./hydration-DdkP3REv.cjs";
1
+ import { Yn as MutationObserver } from "./hydration-BXjqUj_D.cjs";
2
2
  export { MutationObserver };
@@ -1,2 +1,2 @@
1
- import { qn as MutationObserver } from "./hydration-gHEs4kLM.js";
1
+ import { Yn as MutationObserver } from "./hydration-vgIjIhk6.js";
2
2
  export { MutationObserver };
@@ -1,5 +1,5 @@
1
1
  import { t as Subscribable } from "./subscribable-D2lAzdDi.cjs";
2
- import { $n as Query, At as QueryObserverOptions, Pt as QueryObserverResult, on as QueryClient, rr as QueryObserver } from "./hydration-DdkP3REv.cjs";
2
+ import { At as QueryObserverOptions, Pt as QueryObserverResult, ar as QueryObserver, on as QueryClient, tr as Query } from "./hydration-BXjqUj_D.cjs";
3
3
  type QueriesObserverListener = (result: Array<QueryObserverResult>) => void;
4
4
  type CombineFn<TCombinedResult> = (result: Array<QueryObserverResult>) => TCombinedResult;
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { t as Subscribable } from "./subscribable-D2lAzdDi.js";
2
- import { $n as Query, At as QueryObserverOptions, Pt as QueryObserverResult, on as QueryClient, rr as QueryObserver } from "./hydration-gHEs4kLM.js";
2
+ import { At as QueryObserverOptions, Pt as QueryObserverResult, ar as QueryObserver, on as QueryClient, tr as Query } from "./hydration-vgIjIhk6.js";
3
3
  type QueriesObserverListener = (result: Array<QueryObserverResult>) => void;
4
4
  type CombineFn<TCombinedResult> = (result: Array<QueryObserverResult>) => TCombinedResult;
5
5
  /**
@@ -13,6 +13,7 @@ var _revertState = /* @__PURE__ */ new WeakMap();
13
13
  var _cache = /* @__PURE__ */ new WeakMap();
14
14
  var _client = /* @__PURE__ */ new WeakMap();
15
15
  var _retryer = /* @__PURE__ */ new WeakMap();
16
+ var _fetchPromise = /* @__PURE__ */ new WeakMap();
16
17
  var _defaultOptions = /* @__PURE__ */ new WeakMap();
17
18
  var _abortSignalConsumed = /* @__PURE__ */ new WeakMap();
18
19
  var _Query_brand = /* @__PURE__ */ new WeakSet();
@@ -44,6 +45,7 @@ var Query = class extends require_removable.Removable {
44
45
  require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _cache, void 0);
45
46
  require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _client, void 0);
46
47
  require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _retryer, void 0);
48
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _fetchPromise, void 0);
47
49
  require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _defaultOptions, void 0);
48
50
  require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _abortSignalConsumed, void 0);
49
51
  require_classPrivateFieldSet2._classPrivateFieldSet2(_abortSignalConsumed, this, false);
@@ -371,9 +373,9 @@ var Query = class extends require_removable.Removable {
371
373
  var _classPrivateFieldGet7, _context$fetchOptions;
372
374
  if (this.state.fetchStatus !== "idle" && ((_classPrivateFieldGet7 = require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet7 === void 0 ? void 0 : _classPrivateFieldGet7.status()) !== "rejected") {
373
375
  if (this.state.data !== void 0 && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.cancelRefetch)) this.cancel({ silent: true });
374
- else if (require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this)) {
376
+ else if (require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this) && require_classPrivateFieldSet2._classPrivateFieldGet2(_fetchPromise, this)) {
375
377
  require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this).continueRetry();
376
- return require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this).promise;
378
+ return require_classPrivateFieldSet2._classPrivateFieldGet2(_fetchPromise, this);
377
379
  }
378
380
  }
379
381
  if (options) this.setOptions(options);
@@ -386,11 +388,17 @@ var Query = class extends require_removable.Removable {
386
388
  }
387
389
  const abortController = new AbortController();
388
390
  const addSignalProperty = (object) => {
389
- Object.defineProperty(object, "signal", {
390
- enumerable: true,
391
- get: () => {
392
- require_classPrivateFieldSet2._classPrivateFieldSet2(_abortSignalConsumed, this, true);
393
- return abortController.signal;
391
+ Object.defineProperties(object, {
392
+ [require_utils.fetchSignal]: {
393
+ value: abortController.signal,
394
+ enumerable: true
395
+ },
396
+ signal: {
397
+ enumerable: true,
398
+ get: () => {
399
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_abortSignalConsumed, this, true);
400
+ return abortController.signal;
401
+ }
394
402
  }
395
403
  });
396
404
  };
@@ -461,37 +469,47 @@ var Query = class extends require_removable.Removable {
461
469
  networkMode: context.options.networkMode,
462
470
  canRun: () => true
463
471
  }));
464
- try {
465
- var _classPrivateFieldGet8, _classPrivateFieldGet9, _classPrivateFieldGet10, _classPrivateFieldGet11;
466
- const data = await retryer.start();
467
- if (data === void 0) {
468
- if (process.env.NODE_ENV !== "production") console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`);
469
- throw new Error(`${this.queryHash} data is undefined`);
470
- }
471
- this.setData(data);
472
- (_classPrivateFieldGet8 = (_classPrivateFieldGet9 = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).config).onSuccess) === null || _classPrivateFieldGet8 === void 0 || _classPrivateFieldGet8.call(_classPrivateFieldGet9, data, this);
473
- (_classPrivateFieldGet10 = (_classPrivateFieldGet11 = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).config).onSettled) === null || _classPrivateFieldGet10 === void 0 || _classPrivateFieldGet10.call(_classPrivateFieldGet11, data, this.state.error, this);
474
- return data;
475
- } catch (error) {
476
- var _classPrivateFieldGet12, _classPrivateFieldGet13, _classPrivateFieldGet14, _classPrivateFieldGet15;
477
- if (error instanceof require_retryer.CancelledError) {
478
- if (error.silent) return require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this).promise;
479
- else if (error.revert) {
480
- if (this.state.data === void 0) throw error;
481
- return this.state.data;
472
+ const fetchPromise = (async () => {
473
+ try {
474
+ var _classPrivateFieldGet8, _classPrivateFieldGet9, _classPrivateFieldGet10, _classPrivateFieldGet11;
475
+ const data = await retryer.promise;
476
+ if (data === void 0) {
477
+ if (process.env.NODE_ENV !== "production") console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`);
478
+ throw new Error(`${this.queryHash} data is undefined`);
479
+ }
480
+ this.setData(data);
481
+ (_classPrivateFieldGet8 = (_classPrivateFieldGet9 = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).config).onSuccess) === null || _classPrivateFieldGet8 === void 0 || _classPrivateFieldGet8.call(_classPrivateFieldGet9, data, this);
482
+ (_classPrivateFieldGet10 = (_classPrivateFieldGet11 = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).config).onSettled) === null || _classPrivateFieldGet10 === void 0 || _classPrivateFieldGet10.call(_classPrivateFieldGet11, data, this.state.error, this);
483
+ return data;
484
+ } catch (error) {
485
+ var _classPrivateFieldGet12, _classPrivateFieldGet13, _classPrivateFieldGet14, _classPrivateFieldGet15;
486
+ if (error instanceof require_retryer.CancelledError) {
487
+ if (error.silent) {
488
+ if (require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this) !== retryer && require_classPrivateFieldSet2._classPrivateFieldGet2(_fetchPromise, this)) return require_classPrivateFieldSet2._classPrivateFieldGet2(_fetchPromise, this);
489
+ throw error;
490
+ } else if (error.revert) {
491
+ if (this.state.data === void 0) throw error;
492
+ return this.state.data;
493
+ }
494
+ }
495
+ require_classPrivateFieldSet2._assertClassBrand(_Query_brand, this, _dispatch).call(this, {
496
+ type: "error",
497
+ error
498
+ });
499
+ (_classPrivateFieldGet12 = (_classPrivateFieldGet13 = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).config).onError) === null || _classPrivateFieldGet12 === void 0 || _classPrivateFieldGet12.call(_classPrivateFieldGet13, error, this);
500
+ (_classPrivateFieldGet14 = (_classPrivateFieldGet15 = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).config).onSettled) === null || _classPrivateFieldGet14 === void 0 || _classPrivateFieldGet14.call(_classPrivateFieldGet15, this.state.data, error, this);
501
+ throw error;
502
+ } finally {
503
+ if (require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this) === retryer) {
504
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_retryer, this, void 0);
505
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_fetchPromise, this, void 0);
482
506
  }
507
+ this.scheduleGc();
483
508
  }
484
- require_classPrivateFieldSet2._assertClassBrand(_Query_brand, this, _dispatch).call(this, {
485
- type: "error",
486
- error
487
- });
488
- (_classPrivateFieldGet12 = (_classPrivateFieldGet13 = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).config).onError) === null || _classPrivateFieldGet12 === void 0 || _classPrivateFieldGet12.call(_classPrivateFieldGet13, error, this);
489
- (_classPrivateFieldGet14 = (_classPrivateFieldGet15 = require_classPrivateFieldSet2._classPrivateFieldGet2(_cache, this).config).onSettled) === null || _classPrivateFieldGet14 === void 0 || _classPrivateFieldGet14.call(_classPrivateFieldGet15, this.state.data, error, this);
490
- throw error;
491
- } finally {
492
- if (require_classPrivateFieldSet2._classPrivateFieldGet2(_retryer, this) === retryer) require_classPrivateFieldSet2._classPrivateFieldSet2(_retryer, this, void 0);
493
- this.scheduleGc();
494
- }
509
+ })();
510
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_fetchPromise, this, fetchPromise);
511
+ retryer.start();
512
+ return fetchPromise;
495
513
  }
496
514
  };
497
515
  function _dispatch(action) {