@tanstack/query-core 5.91.2 → 5.94.4
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/package.json +1 -1
- package/build/legacy/_tsup-dts-rollup.d.cts +0 -2229
- package/build/legacy/_tsup-dts-rollup.d.ts +0 -2229
- package/build/legacy/chunk-PXG64RU4.js +0 -25
- package/build/legacy/chunk-PXG64RU4.js.map +0 -1
- package/build/legacy/environmentManager.cjs +0 -48
- package/build/legacy/environmentManager.cjs.map +0 -1
- package/build/legacy/environmentManager.d.cts +0 -2
- package/build/legacy/environmentManager.d.ts +0 -2
- package/build/legacy/environmentManager.js +0 -25
- package/build/legacy/environmentManager.js.map +0 -1
- package/build/legacy/focusManager.cjs +0 -107
- package/build/legacy/focusManager.cjs.map +0 -1
- package/build/legacy/focusManager.d.cts +0 -2
- package/build/legacy/focusManager.d.ts +0 -2
- package/build/legacy/focusManager.js +0 -80
- package/build/legacy/focusManager.js.map +0 -1
- package/build/legacy/hydration.cjs +0 -178
- package/build/legacy/hydration.cjs.map +0 -1
- package/build/legacy/hydration.d.cts +0 -7
- package/build/legacy/hydration.d.ts +0 -7
- package/build/legacy/hydration.js +0 -152
- package/build/legacy/hydration.js.map +0 -1
- package/build/legacy/index.cjs +0 -113
- package/build/legacy/index.cjs.map +0 -1
- package/build/legacy/index.d.cts +0 -142
- package/build/legacy/index.d.ts +0 -142
- package/build/legacy/index.js +0 -75
- package/build/legacy/index.js.map +0 -1
- package/build/legacy/infiniteQueryBehavior.cjs +0 -146
- package/build/legacy/infiniteQueryBehavior.cjs.map +0 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +0 -3
- package/build/legacy/infiniteQueryBehavior.d.ts +0 -3
- package/build/legacy/infiniteQueryBehavior.js +0 -126
- package/build/legacy/infiniteQueryBehavior.js.map +0 -1
- package/build/legacy/infiniteQueryObserver.cjs +0 -93
- package/build/legacy/infiniteQueryObserver.cjs.map +0 -1
- package/build/legacy/infiniteQueryObserver.d.cts +0 -1
- package/build/legacy/infiniteQueryObserver.d.ts +0 -1
- package/build/legacy/infiniteQueryObserver.js +0 -74
- package/build/legacy/infiniteQueryObserver.js.map +0 -1
- package/build/legacy/mutation.cjs +0 -333
- package/build/legacy/mutation.cjs.map +0 -1
- package/build/legacy/mutation.d.cts +0 -4
- package/build/legacy/mutation.d.ts +0 -4
- package/build/legacy/mutation.js +0 -306
- package/build/legacy/mutation.js.map +0 -1
- package/build/legacy/mutationCache.cjs +0 -170
- package/build/legacy/mutationCache.cjs.map +0 -1
- package/build/legacy/mutationCache.d.cts +0 -2
- package/build/legacy/mutationCache.d.ts +0 -2
- package/build/legacy/mutationCache.js +0 -137
- package/build/legacy/mutationCache.js.map +0 -1
- package/build/legacy/mutationObserver.cjs +0 -190
- package/build/legacy/mutationObserver.cjs.map +0 -1
- package/build/legacy/mutationObserver.d.cts +0 -1
- package/build/legacy/mutationObserver.d.ts +0 -1
- package/build/legacy/mutationObserver.js +0 -164
- package/build/legacy/mutationObserver.js.map +0 -1
- package/build/legacy/notifyManager.cjs +0 -113
- package/build/legacy/notifyManager.cjs.map +0 -1
- package/build/legacy/notifyManager.d.cts +0 -3
- package/build/legacy/notifyManager.d.ts +0 -3
- package/build/legacy/notifyManager.js +0 -88
- package/build/legacy/notifyManager.js.map +0 -1
- package/build/legacy/onlineManager.cjs +0 -96
- package/build/legacy/onlineManager.cjs.map +0 -1
- package/build/legacy/onlineManager.d.cts +0 -2
- package/build/legacy/onlineManager.d.ts +0 -2
- package/build/legacy/onlineManager.js +0 -69
- package/build/legacy/onlineManager.js.map +0 -1
- package/build/legacy/queriesObserver.cjs +0 -260
- package/build/legacy/queriesObserver.cjs.map +0 -1
- package/build/legacy/queriesObserver.d.cts +0 -2
- package/build/legacy/queriesObserver.d.ts +0 -2
- package/build/legacy/queriesObserver.js +0 -234
- package/build/legacy/queriesObserver.js.map +0 -1
- package/build/legacy/query.cjs +0 -487
- package/build/legacy/query.cjs.map +0 -1
- package/build/legacy/query.d.cts +0 -10
- package/build/legacy/query.d.ts +0 -10
- package/build/legacy/query.js +0 -468
- package/build/legacy/query.js.map +0 -1
- package/build/legacy/queryCache.cjs +0 -131
- package/build/legacy/queryCache.cjs.map +0 -1
- package/build/legacy/queryCache.d.cts +0 -3
- package/build/legacy/queryCache.d.ts +0 -3
- package/build/legacy/queryCache.js +0 -105
- package/build/legacy/queryCache.js.map +0 -1
- package/build/legacy/queryClient.cjs +0 -349
- package/build/legacy/queryClient.cjs.map +0 -1
- package/build/legacy/queryClient.d.cts +0 -1
- package/build/legacy/queryClient.d.ts +0 -1
- package/build/legacy/queryClient.js +0 -324
- package/build/legacy/queryClient.js.map +0 -1
- package/build/legacy/queryObserver.cjs +0 -516
- package/build/legacy/queryObserver.cjs.map +0 -1
- package/build/legacy/queryObserver.d.cts +0 -1
- package/build/legacy/queryObserver.d.ts +0 -1
- package/build/legacy/queryObserver.js +0 -498
- package/build/legacy/queryObserver.js.map +0 -1
- package/build/legacy/removable.cjs +0 -70
- package/build/legacy/removable.cjs.map +0 -1
- package/build/legacy/removable.d.cts +0 -1
- package/build/legacy/removable.d.ts +0 -1
- package/build/legacy/removable.js +0 -44
- package/build/legacy/removable.js.map +0 -1
- package/build/legacy/retryer.cjs +0 -166
- package/build/legacy/retryer.cjs.map +0 -1
- package/build/legacy/retryer.d.cts +0 -7
- package/build/legacy/retryer.d.ts +0 -7
- package/build/legacy/retryer.js +0 -140
- package/build/legacy/retryer.js.map +0 -1
- package/build/legacy/streamedQuery.cjs +0 -80
- package/build/legacy/streamedQuery.cjs.map +0 -1
- package/build/legacy/streamedQuery.d.cts +0 -1
- package/build/legacy/streamedQuery.d.ts +0 -1
- package/build/legacy/streamedQuery.js +0 -57
- package/build/legacy/streamedQuery.js.map +0 -1
- package/build/legacy/subscribable.cjs +0 -51
- package/build/legacy/subscribable.cjs.map +0 -1
- package/build/legacy/subscribable.d.cts +0 -1
- package/build/legacy/subscribable.d.ts +0 -1
- package/build/legacy/subscribable.js +0 -28
- package/build/legacy/subscribable.js.map +0 -1
- package/build/legacy/thenable.cjs +0 -76
- package/build/legacy/thenable.cjs.map +0 -1
- package/build/legacy/thenable.d.cts +0 -6
- package/build/legacy/thenable.d.ts +0 -6
- package/build/legacy/thenable.js +0 -52
- package/build/legacy/thenable.js.map +0 -1
- package/build/legacy/timeoutManager.cjs +0 -110
- package/build/legacy/timeoutManager.cjs.map +0 -1
- package/build/legacy/timeoutManager.d.cts +0 -7
- package/build/legacy/timeoutManager.d.ts +0 -7
- package/build/legacy/timeoutManager.js +0 -81
- package/build/legacy/timeoutManager.js.map +0 -1
- package/build/legacy/types.cjs +0 -37
- package/build/legacy/types.cjs.map +0 -1
- package/build/legacy/types.d.cts +0 -95
- package/build/legacy/types.d.ts +0 -95
- package/build/legacy/types.js +0 -12
- package/build/legacy/types.js.map +0 -1
- package/build/legacy/utils.cjs +0 -330
- package/build/legacy/utils.cjs.map +0 -1
- package/build/legacy/utils.d.cts +0 -30
- package/build/legacy/utils.d.ts +0 -30
- package/build/legacy/utils.js +0 -283
- package/build/legacy/utils.js.map +0 -1
- package/build/modern/_tsup-dts-rollup.d.cts +0 -2229
- package/build/modern/_tsup-dts-rollup.d.ts +0 -2229
- package/build/modern/environmentManager.cjs +0 -48
- package/build/modern/environmentManager.cjs.map +0 -1
- package/build/modern/environmentManager.d.cts +0 -2
- package/build/modern/environmentManager.d.ts +0 -2
- package/build/modern/environmentManager.js +0 -23
- package/build/modern/environmentManager.js.map +0 -1
- package/build/modern/focusManager.cjs +0 -93
- package/build/modern/focusManager.cjs.map +0 -1
- package/build/modern/focusManager.d.cts +0 -2
- package/build/modern/focusManager.d.ts +0 -2
- package/build/modern/focusManager.js +0 -67
- package/build/modern/focusManager.js.map +0 -1
- package/build/modern/hydration.cjs +0 -173
- package/build/modern/hydration.cjs.map +0 -1
- package/build/modern/hydration.d.cts +0 -7
- package/build/modern/hydration.d.ts +0 -7
- package/build/modern/hydration.js +0 -145
- package/build/modern/hydration.js.map +0 -1
- package/build/modern/index.cjs +0 -113
- package/build/modern/index.cjs.map +0 -1
- package/build/modern/index.d.cts +0 -142
- package/build/modern/index.d.ts +0 -142
- package/build/modern/index.js +0 -73
- package/build/modern/index.js.map +0 -1
- package/build/modern/infiniteQueryBehavior.cjs +0 -142
- package/build/modern/infiniteQueryBehavior.cjs.map +0 -1
- package/build/modern/infiniteQueryBehavior.d.cts +0 -3
- package/build/modern/infiniteQueryBehavior.d.ts +0 -3
- package/build/modern/infiniteQueryBehavior.js +0 -120
- package/build/modern/infiniteQueryBehavior.js.map +0 -1
- package/build/modern/infiniteQueryObserver.cjs +0 -92
- package/build/modern/infiniteQueryObserver.cjs.map +0 -1
- package/build/modern/infiniteQueryObserver.d.cts +0 -1
- package/build/modern/infiniteQueryObserver.d.ts +0 -1
- package/build/modern/infiniteQueryObserver.js +0 -71
- package/build/modern/infiniteQueryObserver.js.map +0 -1
- package/build/modern/mutation.cjs +0 -307
- package/build/modern/mutation.cjs.map +0 -1
- package/build/modern/mutation.d.cts +0 -4
- package/build/modern/mutation.d.ts +0 -4
- package/build/modern/mutation.js +0 -281
- package/build/modern/mutation.js.map +0 -1
- package/build/modern/mutationCache.cjs +0 -149
- package/build/modern/mutationCache.cjs.map +0 -1
- package/build/modern/mutationCache.d.cts +0 -2
- package/build/modern/mutationCache.d.ts +0 -2
- package/build/modern/mutationCache.js +0 -124
- package/build/modern/mutationCache.js.map +0 -1
- package/build/modern/mutationObserver.cjs +0 -165
- package/build/modern/mutationObserver.cjs.map +0 -1
- package/build/modern/mutationObserver.d.cts +0 -1
- package/build/modern/mutationObserver.d.ts +0 -1
- package/build/modern/mutationObserver.js +0 -140
- package/build/modern/mutationObserver.js.map +0 -1
- package/build/modern/notifyManager.cjs +0 -113
- package/build/modern/notifyManager.cjs.map +0 -1
- package/build/modern/notifyManager.d.cts +0 -3
- package/build/modern/notifyManager.d.ts +0 -3
- package/build/modern/notifyManager.js +0 -86
- package/build/modern/notifyManager.js.map +0 -1
- package/build/modern/onlineManager.cjs +0 -83
- package/build/modern/onlineManager.cjs.map +0 -1
- package/build/modern/onlineManager.d.cts +0 -2
- package/build/modern/onlineManager.d.ts +0 -2
- package/build/modern/onlineManager.js +0 -57
- package/build/modern/onlineManager.js.map +0 -1
- package/build/modern/queriesObserver.cjs +0 -237
- package/build/modern/queriesObserver.cjs.map +0 -1
- package/build/modern/queriesObserver.d.cts +0 -2
- package/build/modern/queriesObserver.d.ts +0 -2
- package/build/modern/queriesObserver.js +0 -212
- package/build/modern/queriesObserver.js.map +0 -1
- package/build/modern/query.cjs +0 -461
- package/build/modern/query.cjs.map +0 -1
- package/build/modern/query.d.cts +0 -10
- package/build/modern/query.d.ts +0 -10
- package/build/modern/query.js +0 -443
- package/build/modern/query.js.map +0 -1
- package/build/modern/queryCache.cjs +0 -122
- package/build/modern/queryCache.cjs.map +0 -1
- package/build/modern/queryCache.d.cts +0 -3
- package/build/modern/queryCache.d.ts +0 -3
- package/build/modern/queryCache.js +0 -97
- package/build/modern/queryCache.js.map +0 -1
- package/build/modern/queryClient.cjs +0 -322
- package/build/modern/queryClient.cjs.map +0 -1
- package/build/modern/queryClient.d.cts +0 -1
- package/build/modern/queryClient.d.ts +0 -1
- package/build/modern/queryClient.js +0 -305
- package/build/modern/queryClient.js.map +0 -1
- package/build/modern/queryObserver.cjs +0 -489
- package/build/modern/queryObserver.cjs.map +0 -1
- package/build/modern/queryObserver.d.cts +0 -1
- package/build/modern/queryObserver.d.ts +0 -1
- package/build/modern/queryObserver.js +0 -472
- package/build/modern/queryObserver.js.map +0 -1
- package/build/modern/removable.cjs +0 -59
- package/build/modern/removable.cjs.map +0 -1
- package/build/modern/removable.d.cts +0 -1
- package/build/modern/removable.d.ts +0 -1
- package/build/modern/removable.js +0 -34
- package/build/modern/removable.js.map +0 -1
- package/build/modern/retryer.cjs +0 -162
- package/build/modern/retryer.cjs.map +0 -1
- package/build/modern/retryer.d.cts +0 -7
- package/build/modern/retryer.d.ts +0 -7
- package/build/modern/retryer.js +0 -134
- package/build/modern/retryer.js.map +0 -1
- package/build/modern/streamedQuery.cjs +0 -80
- package/build/modern/streamedQuery.cjs.map +0 -1
- package/build/modern/streamedQuery.d.cts +0 -1
- package/build/modern/streamedQuery.d.ts +0 -1
- package/build/modern/streamedQuery.js +0 -55
- package/build/modern/streamedQuery.js.map +0 -1
- package/build/modern/subscribable.cjs +0 -51
- package/build/modern/subscribable.cjs.map +0 -1
- package/build/modern/subscribable.d.cts +0 -1
- package/build/modern/subscribable.d.ts +0 -1
- package/build/modern/subscribable.js +0 -26
- package/build/modern/subscribable.js.map +0 -1
- package/build/modern/thenable.cjs +0 -75
- package/build/modern/thenable.cjs.map +0 -1
- package/build/modern/thenable.d.cts +0 -6
- package/build/modern/thenable.d.ts +0 -6
- package/build/modern/thenable.js +0 -49
- package/build/modern/thenable.js.map +0 -1
- package/build/modern/timeoutManager.cjs +0 -98
- package/build/modern/timeoutManager.cjs.map +0 -1
- package/build/modern/timeoutManager.d.cts +0 -7
- package/build/modern/timeoutManager.d.ts +0 -7
- package/build/modern/timeoutManager.js +0 -70
- package/build/modern/timeoutManager.js.map +0 -1
- package/build/modern/types.cjs +0 -37
- package/build/modern/types.cjs.map +0 -1
- package/build/modern/types.d.cts +0 -95
- package/build/modern/types.d.ts +0 -95
- package/build/modern/types.js +0 -10
- package/build/modern/types.js.map +0 -1
- package/build/modern/utils.cjs +0 -330
- package/build/modern/utils.cjs.map +0 -1
- package/build/modern/utils.d.cts +0 -30
- package/build/modern/utils.d.ts +0 -30
- package/build/modern/utils.js +0 -281
- package/build/modern/utils.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"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\nexport interface MutationState<\n TData = unknown,\n TError = DefaultError,\n TVariables = unknown,\n TOnMutateResult = unknown,\n> {\n context: TOnMutateResult | undefined\n data: TData | undefined\n error: TError | null\n failureCount: number\n failureReason: TError | null\n isPaused: boolean\n status: MutationStatus\n variables: TVariables | undefined\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\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\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 setOptions(\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.options = options\n\n this.updateGcTime(this.options.gcTime)\n }\n\n get meta(): MutationMeta | undefined {\n return this.options.meta\n }\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 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 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 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 this.execute(this.state.variables!)\n )\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 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 = !this.#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 this.#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 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\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":";;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAF9B;AAmFO,IAAM,WAAN,cAKG,UAAU;AAAA,EAYlB,YACE,QACA;AACA,UAAM;AApBH;AAUL;AACA;AAGA;AACA;AAOE,uBAAK,SAAU,OAAO;AACtB,SAAK,aAAa,OAAO;AACzB,uBAAK,gBAAiB,OAAO;AAC7B,uBAAK,YA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Q,QAAQ,KAAK,KAAK;AAE/B,gBAAc,MAAM,MAAM;AACxB,uBAAK,YAAW,QAAQ,CAAC,aAAa;AACpC,eAAS,iBAAiB,MAAM;AAAA,IAClC,CAAC;AACD,uBAAK,gBAAe,OAAO;AAAA,MACzB,UAAU;AAAA,MACV,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;AAGK,SAAS,kBAK+C;AAC7D,SAAO;AAAA,IACL,SAAS;AAAA,IACT,MAAM;AAAA,IACN,OAAO;AAAA,IACP,cAAc;AAAA,IACd,eAAe;AAAA,IACf,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,aAAa;AAAA,EACf;AACF;","names":[]}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __typeError = (msg) => {
|
|
7
|
-
throw TypeError(msg);
|
|
8
|
-
};
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
-
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
27
|
-
set _(value) {
|
|
28
|
-
__privateSet(obj, member, value, setter);
|
|
29
|
-
},
|
|
30
|
-
get _() {
|
|
31
|
-
return __privateGet(obj, member, getter);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// src/mutationCache.ts
|
|
36
|
-
var mutationCache_exports = {};
|
|
37
|
-
__export(mutationCache_exports, {
|
|
38
|
-
MutationCache: () => MutationCache
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(mutationCache_exports);
|
|
41
|
-
var import_notifyManager = require("./notifyManager.cjs");
|
|
42
|
-
var import_mutation = require("./mutation.cjs");
|
|
43
|
-
var import_utils = require("./utils.cjs");
|
|
44
|
-
var import_subscribable = require("./subscribable.cjs");
|
|
45
|
-
var _mutations, _scopes, _mutationId;
|
|
46
|
-
var MutationCache = class extends import_subscribable.Subscribable {
|
|
47
|
-
constructor(config = {}) {
|
|
48
|
-
super();
|
|
49
|
-
this.config = config;
|
|
50
|
-
__privateAdd(this, _mutations);
|
|
51
|
-
__privateAdd(this, _scopes);
|
|
52
|
-
__privateAdd(this, _mutationId);
|
|
53
|
-
__privateSet(this, _mutations, /* @__PURE__ */ new Set());
|
|
54
|
-
__privateSet(this, _scopes, /* @__PURE__ */ new Map());
|
|
55
|
-
__privateSet(this, _mutationId, 0);
|
|
56
|
-
}
|
|
57
|
-
build(client, options, state) {
|
|
58
|
-
const mutation = new import_mutation.Mutation({
|
|
59
|
-
client,
|
|
60
|
-
mutationCache: this,
|
|
61
|
-
mutationId: ++__privateWrapper(this, _mutationId)._,
|
|
62
|
-
options: client.defaultMutationOptions(options),
|
|
63
|
-
state
|
|
64
|
-
});
|
|
65
|
-
this.add(mutation);
|
|
66
|
-
return mutation;
|
|
67
|
-
}
|
|
68
|
-
add(mutation) {
|
|
69
|
-
__privateGet(this, _mutations).add(mutation);
|
|
70
|
-
const scope = scopeFor(mutation);
|
|
71
|
-
if (typeof scope === "string") {
|
|
72
|
-
const scopedMutations = __privateGet(this, _scopes).get(scope);
|
|
73
|
-
if (scopedMutations) {
|
|
74
|
-
scopedMutations.push(mutation);
|
|
75
|
-
} else {
|
|
76
|
-
__privateGet(this, _scopes).set(scope, [mutation]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
this.notify({ type: "added", mutation });
|
|
80
|
-
}
|
|
81
|
-
remove(mutation) {
|
|
82
|
-
if (__privateGet(this, _mutations).delete(mutation)) {
|
|
83
|
-
const scope = scopeFor(mutation);
|
|
84
|
-
if (typeof scope === "string") {
|
|
85
|
-
const scopedMutations = __privateGet(this, _scopes).get(scope);
|
|
86
|
-
if (scopedMutations) {
|
|
87
|
-
if (scopedMutations.length > 1) {
|
|
88
|
-
const index = scopedMutations.indexOf(mutation);
|
|
89
|
-
if (index !== -1) {
|
|
90
|
-
scopedMutations.splice(index, 1);
|
|
91
|
-
}
|
|
92
|
-
} else if (scopedMutations[0] === mutation) {
|
|
93
|
-
__privateGet(this, _scopes).delete(scope);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
this.notify({ type: "removed", mutation });
|
|
99
|
-
}
|
|
100
|
-
canRun(mutation) {
|
|
101
|
-
const scope = scopeFor(mutation);
|
|
102
|
-
if (typeof scope === "string") {
|
|
103
|
-
const mutationsWithSameScope = __privateGet(this, _scopes).get(scope);
|
|
104
|
-
const firstPendingMutation = mutationsWithSameScope == null ? void 0 : mutationsWithSameScope.find(
|
|
105
|
-
(m) => m.state.status === "pending"
|
|
106
|
-
);
|
|
107
|
-
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
108
|
-
} else {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
runNext(mutation) {
|
|
113
|
-
var _a;
|
|
114
|
-
const scope = scopeFor(mutation);
|
|
115
|
-
if (typeof scope === "string") {
|
|
116
|
-
const foundMutation = (_a = __privateGet(this, _scopes).get(scope)) == null ? void 0 : _a.find((m) => m !== mutation && m.state.isPaused);
|
|
117
|
-
return (foundMutation == null ? void 0 : foundMutation.continue()) ?? Promise.resolve();
|
|
118
|
-
} else {
|
|
119
|
-
return Promise.resolve();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
clear() {
|
|
123
|
-
import_notifyManager.notifyManager.batch(() => {
|
|
124
|
-
__privateGet(this, _mutations).forEach((mutation) => {
|
|
125
|
-
this.notify({ type: "removed", mutation });
|
|
126
|
-
});
|
|
127
|
-
__privateGet(this, _mutations).clear();
|
|
128
|
-
__privateGet(this, _scopes).clear();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
getAll() {
|
|
132
|
-
return Array.from(__privateGet(this, _mutations));
|
|
133
|
-
}
|
|
134
|
-
find(filters) {
|
|
135
|
-
const defaultedFilters = { exact: true, ...filters };
|
|
136
|
-
return this.getAll().find(
|
|
137
|
-
(mutation) => (0, import_utils.matchMutation)(defaultedFilters, mutation)
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
findAll(filters = {}) {
|
|
141
|
-
return this.getAll().filter((mutation) => (0, import_utils.matchMutation)(filters, mutation));
|
|
142
|
-
}
|
|
143
|
-
notify(event) {
|
|
144
|
-
import_notifyManager.notifyManager.batch(() => {
|
|
145
|
-
this.listeners.forEach((listener) => {
|
|
146
|
-
listener(event);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
resumePausedMutations() {
|
|
151
|
-
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
152
|
-
return import_notifyManager.notifyManager.batch(
|
|
153
|
-
() => Promise.all(
|
|
154
|
-
pausedMutations.map((mutation) => mutation.continue().catch(import_utils.noop))
|
|
155
|
-
)
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
_mutations = new WeakMap();
|
|
160
|
-
_scopes = new WeakMap();
|
|
161
|
-
_mutationId = new WeakMap();
|
|
162
|
-
function scopeFor(mutation) {
|
|
163
|
-
var _a;
|
|
164
|
-
return (_a = mutation.options.scope) == null ? void 0 : _a.id;
|
|
165
|
-
}
|
|
166
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
167
|
-
0 && (module.exports = {
|
|
168
|
-
MutationCache
|
|
169
|
-
});
|
|
170
|
-
//# sourceMappingURL=mutationCache.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\ninterface MutationCacheConfig {\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAC9B,sBAAyB;AACzB,mBAAoC;AACpC,0BAA6B;AAH7B;AA4FO,IAAM,gBAAN,cAA4B,iCAAoC;AAAA,EAKrE,YAAmB,SAA8B,CAAC,GAAG;AACnD,UAAM;AADW;AAJnB;AACA;AACA;AAIE,uBAAK,YAAa,oBAAI,IAAI;AAC1B,uBAAK,SAAU,oBAAI,IAAI;AACvB,uBAAK,aAAc;AAAA,EACrB;AAAA,EAEA,MACE,QACA,SACA,OACsD;AACtD,UAAM,WAAW,IAAI,yBAAS;AAAA,MAC5B;AAAA,MACA,eAAe;AAAA,MACf,YAAmB,EAAL,uBAAK,aAAL;AAAA,MACd,SAAS,OAAO,uBAAuB,OAAO;AAAA,MAC9C;AAAA,IACF,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QAAQ;AAAA,QACN,gBAAgB,IAAI,CAAC,aAAa,SAAS,SAAS,EAAE,MAAM,iBAAI,CAAC;AAAA,MACnE;AAAA,IACF;AAAA,EACF;AACF;AAlJE;AACA;AACA;AAkJF,SAAS,SAAS,UAAwC;AAjP1D;AAkPE,UAAO,cAAS,QAAQ,UAAjB,mBAAwB;AACjC;","names":[]}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__privateAdd,
|
|
3
|
-
__privateGet,
|
|
4
|
-
__privateSet,
|
|
5
|
-
__privateWrapper
|
|
6
|
-
} from "./chunk-PXG64RU4.js";
|
|
7
|
-
|
|
8
|
-
// src/mutationCache.ts
|
|
9
|
-
import { notifyManager } from "./notifyManager.js";
|
|
10
|
-
import { Mutation } from "./mutation.js";
|
|
11
|
-
import { matchMutation, noop } from "./utils.js";
|
|
12
|
-
import { Subscribable } from "./subscribable.js";
|
|
13
|
-
var _mutations, _scopes, _mutationId;
|
|
14
|
-
var MutationCache = class extends Subscribable {
|
|
15
|
-
constructor(config = {}) {
|
|
16
|
-
super();
|
|
17
|
-
this.config = config;
|
|
18
|
-
__privateAdd(this, _mutations);
|
|
19
|
-
__privateAdd(this, _scopes);
|
|
20
|
-
__privateAdd(this, _mutationId);
|
|
21
|
-
__privateSet(this, _mutations, /* @__PURE__ */ new Set());
|
|
22
|
-
__privateSet(this, _scopes, /* @__PURE__ */ new Map());
|
|
23
|
-
__privateSet(this, _mutationId, 0);
|
|
24
|
-
}
|
|
25
|
-
build(client, options, state) {
|
|
26
|
-
const mutation = new Mutation({
|
|
27
|
-
client,
|
|
28
|
-
mutationCache: this,
|
|
29
|
-
mutationId: ++__privateWrapper(this, _mutationId)._,
|
|
30
|
-
options: client.defaultMutationOptions(options),
|
|
31
|
-
state
|
|
32
|
-
});
|
|
33
|
-
this.add(mutation);
|
|
34
|
-
return mutation;
|
|
35
|
-
}
|
|
36
|
-
add(mutation) {
|
|
37
|
-
__privateGet(this, _mutations).add(mutation);
|
|
38
|
-
const scope = scopeFor(mutation);
|
|
39
|
-
if (typeof scope === "string") {
|
|
40
|
-
const scopedMutations = __privateGet(this, _scopes).get(scope);
|
|
41
|
-
if (scopedMutations) {
|
|
42
|
-
scopedMutations.push(mutation);
|
|
43
|
-
} else {
|
|
44
|
-
__privateGet(this, _scopes).set(scope, [mutation]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
this.notify({ type: "added", mutation });
|
|
48
|
-
}
|
|
49
|
-
remove(mutation) {
|
|
50
|
-
if (__privateGet(this, _mutations).delete(mutation)) {
|
|
51
|
-
const scope = scopeFor(mutation);
|
|
52
|
-
if (typeof scope === "string") {
|
|
53
|
-
const scopedMutations = __privateGet(this, _scopes).get(scope);
|
|
54
|
-
if (scopedMutations) {
|
|
55
|
-
if (scopedMutations.length > 1) {
|
|
56
|
-
const index = scopedMutations.indexOf(mutation);
|
|
57
|
-
if (index !== -1) {
|
|
58
|
-
scopedMutations.splice(index, 1);
|
|
59
|
-
}
|
|
60
|
-
} else if (scopedMutations[0] === mutation) {
|
|
61
|
-
__privateGet(this, _scopes).delete(scope);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.notify({ type: "removed", mutation });
|
|
67
|
-
}
|
|
68
|
-
canRun(mutation) {
|
|
69
|
-
const scope = scopeFor(mutation);
|
|
70
|
-
if (typeof scope === "string") {
|
|
71
|
-
const mutationsWithSameScope = __privateGet(this, _scopes).get(scope);
|
|
72
|
-
const firstPendingMutation = mutationsWithSameScope == null ? void 0 : mutationsWithSameScope.find(
|
|
73
|
-
(m) => m.state.status === "pending"
|
|
74
|
-
);
|
|
75
|
-
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
76
|
-
} else {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
runNext(mutation) {
|
|
81
|
-
var _a;
|
|
82
|
-
const scope = scopeFor(mutation);
|
|
83
|
-
if (typeof scope === "string") {
|
|
84
|
-
const foundMutation = (_a = __privateGet(this, _scopes).get(scope)) == null ? void 0 : _a.find((m) => m !== mutation && m.state.isPaused);
|
|
85
|
-
return (foundMutation == null ? void 0 : foundMutation.continue()) ?? Promise.resolve();
|
|
86
|
-
} else {
|
|
87
|
-
return Promise.resolve();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
clear() {
|
|
91
|
-
notifyManager.batch(() => {
|
|
92
|
-
__privateGet(this, _mutations).forEach((mutation) => {
|
|
93
|
-
this.notify({ type: "removed", mutation });
|
|
94
|
-
});
|
|
95
|
-
__privateGet(this, _mutations).clear();
|
|
96
|
-
__privateGet(this, _scopes).clear();
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
getAll() {
|
|
100
|
-
return Array.from(__privateGet(this, _mutations));
|
|
101
|
-
}
|
|
102
|
-
find(filters) {
|
|
103
|
-
const defaultedFilters = { exact: true, ...filters };
|
|
104
|
-
return this.getAll().find(
|
|
105
|
-
(mutation) => matchMutation(defaultedFilters, mutation)
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
findAll(filters = {}) {
|
|
109
|
-
return this.getAll().filter((mutation) => matchMutation(filters, mutation));
|
|
110
|
-
}
|
|
111
|
-
notify(event) {
|
|
112
|
-
notifyManager.batch(() => {
|
|
113
|
-
this.listeners.forEach((listener) => {
|
|
114
|
-
listener(event);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
resumePausedMutations() {
|
|
119
|
-
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
120
|
-
return notifyManager.batch(
|
|
121
|
-
() => Promise.all(
|
|
122
|
-
pausedMutations.map((mutation) => mutation.continue().catch(noop))
|
|
123
|
-
)
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
_mutations = new WeakMap();
|
|
128
|
-
_scopes = new WeakMap();
|
|
129
|
-
_mutationId = new WeakMap();
|
|
130
|
-
function scopeFor(mutation) {
|
|
131
|
-
var _a;
|
|
132
|
-
return (_a = mutation.options.scope) == null ? void 0 : _a.id;
|
|
133
|
-
}
|
|
134
|
-
export {
|
|
135
|
-
MutationCache
|
|
136
|
-
};
|
|
137
|
-
//# sourceMappingURL=mutationCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mutationCache.ts"],"sourcesContent":["import { notifyManager } from './notifyManager'\nimport { Mutation } from './mutation'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\nimport type { MutationObserver } from './mutationObserver'\nimport type {\n DefaultError,\n MutationFunctionContext,\n MutationOptions,\n NotifyEvent,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { Action, MutationState } from './mutation'\nimport type { MutationFilters } from './utils'\n\n// TYPES\n\ninterface MutationCacheConfig {\n onError?: (\n error: DefaultError,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSuccess?: (\n data: unknown,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n onMutateResult: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n context: MutationFunctionContext,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded extends NotifyEvent {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved extends NotifyEvent {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated extends NotifyEvent {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\nexport type MutationCacheNotifyEvent =\n | NotifyEventMutationAdded\n | NotifyEventMutationRemoved\n | NotifyEventMutationObserverAdded\n | NotifyEventMutationObserverRemoved\n | NotifyEventMutationObserverOptionsUpdated\n | NotifyEventMutationUpdated\n\ntype MutationCacheListener = (event: MutationCacheNotifyEvent) => void\n\n// CLASS\n\nexport class MutationCache extends Subscribable<MutationCacheListener> {\n #mutations: Set<Mutation<any, any, any, any>>\n #scopes: Map<string, Array<Mutation<any, any, any, any>>>\n #mutationId: number\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\n this.#mutations = new Set()\n this.#scopes = new Map()\n this.#mutationId = 0\n }\n\n build<TData, TError, TVariables, TOnMutateResult>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TOnMutateResult>,\n state?: MutationState<TData, TError, TVariables, TOnMutateResult>,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> {\n const mutation = new Mutation({\n client,\n mutationCache: this,\n mutationId: ++this.#mutationId,\n options: client.defaultMutationOptions(options),\n state,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n add(mutation: Mutation<any, any, any, any>): void {\n this.#mutations.add(mutation)\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n scopedMutations.push(mutation)\n } else {\n this.#scopes.set(scope, [mutation])\n }\n }\n this.notify({ type: 'added', mutation })\n }\n\n remove(mutation: Mutation<any, any, any, any>): void {\n if (this.#mutations.delete(mutation)) {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const scopedMutations = this.#scopes.get(scope)\n if (scopedMutations) {\n if (scopedMutations.length > 1) {\n const index = scopedMutations.indexOf(mutation)\n if (index !== -1) {\n scopedMutations.splice(index, 1)\n }\n } else if (scopedMutations[0] === mutation) {\n this.#scopes.delete(scope)\n }\n }\n }\n }\n\n // Currently we notify the removal even if the mutation was already removed.\n // Consider making this an error or not notifying of the removal depending on the desired semantics.\n this.notify({ type: 'removed', mutation })\n }\n\n canRun(mutation: Mutation<any, any, any, any>): boolean {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const mutationsWithSameScope = this.#scopes.get(scope)\n const firstPendingMutation = mutationsWithSameScope?.find(\n (m) => m.state.status === 'pending',\n )\n // we can run if there is no current pending mutation (start use-case)\n // or if WE are the first pending mutation (continue use-case)\n return !firstPendingMutation || firstPendingMutation === mutation\n } else {\n // For unscoped mutations there are never any pending mutations in front of the\n // current mutation\n return true\n }\n }\n\n runNext(mutation: Mutation<any, any, any, any>): Promise<unknown> {\n const scope = scopeFor(mutation)\n if (typeof scope === 'string') {\n const foundMutation = this.#scopes\n .get(scope)\n ?.find((m) => m !== mutation && m.state.isPaused)\n\n return foundMutation?.continue() ?? Promise.resolve()\n } else {\n return Promise.resolve()\n }\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.#mutations.forEach((mutation) => {\n this.notify({ type: 'removed', mutation })\n })\n this.#mutations.clear()\n this.#scopes.clear()\n })\n }\n\n getAll(): Array<Mutation> {\n return Array.from(this.#mutations)\n }\n\n find<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TOnMutateResult = unknown,\n >(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TOnMutateResult> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((mutation) =>\n matchMutation(defaultedFilters, mutation),\n ) as Mutation<TData, TError, TVariables, TOnMutateResult> | undefined\n }\n\n findAll(filters: MutationFilters = {}): Array<Mutation> {\n return this.getAll().filter((mutation) => matchMutation(filters, mutation))\n }\n\n notify(event: MutationCacheNotifyEvent) {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n resumePausedMutations(): Promise<unknown> {\n const pausedMutations = this.getAll().filter((x) => x.state.isPaused)\n\n return notifyManager.batch(() =>\n Promise.all(\n pausedMutations.map((mutation) => mutation.continue().catch(noop)),\n ),\n )\n }\n}\n\nfunction scopeFor(mutation: Mutation<any, any, any, any>) {\n return mutation.options.scope?.id\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,eAAe,YAAY;AACpC,SAAS,oBAAoB;AAH7B;AA4FO,IAAM,gBAAN,cAA4B,aAAoC;AAAA,EAKrE,YAAmB,SAA8B,CAAC,GAAG;AACnD,UAAM;AADW;AAJnB;AACA;AACA;AAIE,uBAAK,YAAa,oBAAI,IAAI;AAC1B,uBAAK,SAAU,oBAAI,IAAI;AACvB,uBAAK,aAAc;AAAA,EACrB;AAAA,EAEA,MACE,QACA,SACA,OACsD;AACtD,UAAM,WAAW,IAAI,SAAS;AAAA,MAC5B;AAAA,MACA,eAAe;AAAA,MACf,YAAmB,EAAL,uBAAK,aAAL;AAAA,MACd,SAAS,OAAO,uBAAuB,OAAO;AAAA,MAC9C;AAAA,IACF,CAAC;AAED,SAAK,IAAI,QAAQ;AAEjB,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,UAA8C;AAChD,uBAAK,YAAW,IAAI,QAAQ;AAC5B,UAAM,QAAQ,SAAS,QAAQ;AAC/B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,kBAAkB,mBAAK,SAAQ,IAAI,KAAK;AAC9C,UAAI,iBAAiB;AACnB,wBAAgB,KAAK,QAAQ;AAAA,MAC/B,OAAO;AACL,2BAAK,SAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;AAAA,MACpC;AAAA,IACF;AACA,SAAK,OAA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M;AACxB,yBAAK,YAAW,QAAQ,CAAC,aAAa;AACpC,aAAK,OAAO,EAAE,MAAM,WAAW,SAAS,CAAC;AAAA,MAC3C,CAAC;AACD,yBAAK,YAAW,MAAM;AACtB,yBAAK,SAAQ,MAAM;AAAA,IACrB,CAAC;AAAA,EACH;AAAA,EAEA,SAA0B;AACxB,WAAO,MAAM,KAAK,mBAAK,WAAU;AAAA,EACnC;AAAA,EAEA,KAME,SACkE;AAClE,UAAM,mBAAmB,EAAE,OAAO,MAAM,GAAG,QAAQ;AAEnD,WAAO,KAAK,OAAO,EAAE;AAAA,MAAK,CAAC,aACzB,cAAc,kBAAkB,QAAQ;AAAA,IAC1C;AAAA,EACF;AAAA,EAEA,QAAQ,UAA2B,CAAC,GAAoB;AACtD,WAAO,KAAK,OAAO,EAAE,OAAO,CAAC,aAAa,cAAc,SAAS,QAAQ,CAAC;AAAA,EAC5E;AAAA,EAEA,OAAO,OAAiC;AACtC,kBAAc,MAAM,MAAM;AACxB,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,iBAAS,KAAK;AAAA,MAChB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAEA,wBAA0C;AACxC,UAAM,kBAAkB,KAAK,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,QAAQ;AAEpE,WAAO,cAAc;AAAA,MAAM,MACzB,QAAQ;AAAA,QACN,gBAAgB,IAAI,CAAC,aAAa,SAAS,SAAS,EAAE,MAAM,IAAI,CAAC;AAAA,MACnE;AAAA,IACF;AAAA,EACF;AACF;AAlJE;AACA;AACA;AAkJF,SAAS,SAAS,UAAwC;AAjP1D;AAkPE,UAAO,cAAS,QAAQ,UAAjB,mBAAwB;AACjC;","names":[]}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __typeError = (msg) => {
|
|
7
|
-
throw TypeError(msg);
|
|
8
|
-
};
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
|
-
|
|
28
|
-
// src/mutationObserver.ts
|
|
29
|
-
var mutationObserver_exports = {};
|
|
30
|
-
__export(mutationObserver_exports, {
|
|
31
|
-
MutationObserver: () => MutationObserver
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(mutationObserver_exports);
|
|
34
|
-
var import_mutation = require("./mutation.cjs");
|
|
35
|
-
var import_notifyManager = require("./notifyManager.cjs");
|
|
36
|
-
var import_subscribable = require("./subscribable.cjs");
|
|
37
|
-
var import_utils = require("./utils.cjs");
|
|
38
|
-
var _client, _currentResult, _currentMutation, _mutateOptions, _MutationObserver_instances, updateResult_fn, notify_fn;
|
|
39
|
-
var MutationObserver = class extends import_subscribable.Subscribable {
|
|
40
|
-
constructor(client, options) {
|
|
41
|
-
super();
|
|
42
|
-
__privateAdd(this, _MutationObserver_instances);
|
|
43
|
-
__privateAdd(this, _client);
|
|
44
|
-
__privateAdd(this, _currentResult);
|
|
45
|
-
__privateAdd(this, _currentMutation);
|
|
46
|
-
__privateAdd(this, _mutateOptions);
|
|
47
|
-
__privateSet(this, _client, client);
|
|
48
|
-
this.setOptions(options);
|
|
49
|
-
this.bindMethods();
|
|
50
|
-
__privateMethod(this, _MutationObserver_instances, updateResult_fn).call(this);
|
|
51
|
-
}
|
|
52
|
-
bindMethods() {
|
|
53
|
-
this.mutate = this.mutate.bind(this);
|
|
54
|
-
this.reset = this.reset.bind(this);
|
|
55
|
-
}
|
|
56
|
-
setOptions(options) {
|
|
57
|
-
var _a;
|
|
58
|
-
const prevOptions = this.options;
|
|
59
|
-
this.options = __privateGet(this, _client).defaultMutationOptions(options);
|
|
60
|
-
if (!(0, import_utils.shallowEqualObjects)(this.options, prevOptions)) {
|
|
61
|
-
__privateGet(this, _client).getMutationCache().notify({
|
|
62
|
-
type: "observerOptionsUpdated",
|
|
63
|
-
mutation: __privateGet(this, _currentMutation),
|
|
64
|
-
observer: this
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if ((prevOptions == null ? void 0 : prevOptions.mutationKey) && this.options.mutationKey && (0, import_utils.hashKey)(prevOptions.mutationKey) !== (0, import_utils.hashKey)(this.options.mutationKey)) {
|
|
68
|
-
this.reset();
|
|
69
|
-
} else if (((_a = __privateGet(this, _currentMutation)) == null ? void 0 : _a.state.status) === "pending") {
|
|
70
|
-
__privateGet(this, _currentMutation).setOptions(this.options);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
onUnsubscribe() {
|
|
74
|
-
var _a;
|
|
75
|
-
if (!this.hasListeners()) {
|
|
76
|
-
(_a = __privateGet(this, _currentMutation)) == null ? void 0 : _a.removeObserver(this);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
onMutationUpdate(action) {
|
|
80
|
-
__privateMethod(this, _MutationObserver_instances, updateResult_fn).call(this);
|
|
81
|
-
__privateMethod(this, _MutationObserver_instances, notify_fn).call(this, action);
|
|
82
|
-
}
|
|
83
|
-
getCurrentResult() {
|
|
84
|
-
return __privateGet(this, _currentResult);
|
|
85
|
-
}
|
|
86
|
-
reset() {
|
|
87
|
-
var _a;
|
|
88
|
-
(_a = __privateGet(this, _currentMutation)) == null ? void 0 : _a.removeObserver(this);
|
|
89
|
-
__privateSet(this, _currentMutation, void 0);
|
|
90
|
-
__privateMethod(this, _MutationObserver_instances, updateResult_fn).call(this);
|
|
91
|
-
__privateMethod(this, _MutationObserver_instances, notify_fn).call(this);
|
|
92
|
-
}
|
|
93
|
-
mutate(variables, options) {
|
|
94
|
-
var _a;
|
|
95
|
-
__privateSet(this, _mutateOptions, options);
|
|
96
|
-
(_a = __privateGet(this, _currentMutation)) == null ? void 0 : _a.removeObserver(this);
|
|
97
|
-
__privateSet(this, _currentMutation, __privateGet(this, _client).getMutationCache().build(__privateGet(this, _client), this.options));
|
|
98
|
-
__privateGet(this, _currentMutation).addObserver(this);
|
|
99
|
-
return __privateGet(this, _currentMutation).execute(variables);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
_client = new WeakMap();
|
|
103
|
-
_currentResult = new WeakMap();
|
|
104
|
-
_currentMutation = new WeakMap();
|
|
105
|
-
_mutateOptions = new WeakMap();
|
|
106
|
-
_MutationObserver_instances = new WeakSet();
|
|
107
|
-
updateResult_fn = function() {
|
|
108
|
-
var _a;
|
|
109
|
-
const state = ((_a = __privateGet(this, _currentMutation)) == null ? void 0 : _a.state) ?? (0, import_mutation.getDefaultState)();
|
|
110
|
-
__privateSet(this, _currentResult, {
|
|
111
|
-
...state,
|
|
112
|
-
isPending: state.status === "pending",
|
|
113
|
-
isSuccess: state.status === "success",
|
|
114
|
-
isError: state.status === "error",
|
|
115
|
-
isIdle: state.status === "idle",
|
|
116
|
-
mutate: this.mutate,
|
|
117
|
-
reset: this.reset
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
notify_fn = function(action) {
|
|
121
|
-
import_notifyManager.notifyManager.batch(() => {
|
|
122
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
123
|
-
if (__privateGet(this, _mutateOptions) && this.hasListeners()) {
|
|
124
|
-
const variables = __privateGet(this, _currentResult).variables;
|
|
125
|
-
const onMutateResult = __privateGet(this, _currentResult).context;
|
|
126
|
-
const context = {
|
|
127
|
-
client: __privateGet(this, _client),
|
|
128
|
-
meta: this.options.meta,
|
|
129
|
-
mutationKey: this.options.mutationKey
|
|
130
|
-
};
|
|
131
|
-
if ((action == null ? void 0 : action.type) === "success") {
|
|
132
|
-
try {
|
|
133
|
-
(_b = (_a = __privateGet(this, _mutateOptions)).onSuccess) == null ? void 0 : _b.call(
|
|
134
|
-
_a,
|
|
135
|
-
action.data,
|
|
136
|
-
variables,
|
|
137
|
-
onMutateResult,
|
|
138
|
-
context
|
|
139
|
-
);
|
|
140
|
-
} catch (e) {
|
|
141
|
-
void Promise.reject(e);
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
(_d = (_c = __privateGet(this, _mutateOptions)).onSettled) == null ? void 0 : _d.call(
|
|
145
|
-
_c,
|
|
146
|
-
action.data,
|
|
147
|
-
null,
|
|
148
|
-
variables,
|
|
149
|
-
onMutateResult,
|
|
150
|
-
context
|
|
151
|
-
);
|
|
152
|
-
} catch (e) {
|
|
153
|
-
void Promise.reject(e);
|
|
154
|
-
}
|
|
155
|
-
} else if ((action == null ? void 0 : action.type) === "error") {
|
|
156
|
-
try {
|
|
157
|
-
(_f = (_e = __privateGet(this, _mutateOptions)).onError) == null ? void 0 : _f.call(
|
|
158
|
-
_e,
|
|
159
|
-
action.error,
|
|
160
|
-
variables,
|
|
161
|
-
onMutateResult,
|
|
162
|
-
context
|
|
163
|
-
);
|
|
164
|
-
} catch (e) {
|
|
165
|
-
void Promise.reject(e);
|
|
166
|
-
}
|
|
167
|
-
try {
|
|
168
|
-
(_h = (_g = __privateGet(this, _mutateOptions)).onSettled) == null ? void 0 : _h.call(
|
|
169
|
-
_g,
|
|
170
|
-
void 0,
|
|
171
|
-
action.error,
|
|
172
|
-
variables,
|
|
173
|
-
onMutateResult,
|
|
174
|
-
context
|
|
175
|
-
);
|
|
176
|
-
} catch (e) {
|
|
177
|
-
void Promise.reject(e);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
this.listeners.forEach((listener) => {
|
|
182
|
-
listener(__privateGet(this, _currentResult));
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
187
|
-
0 && (module.exports = {
|
|
188
|
-
MutationObserver
|
|
189
|
-
});
|
|
190
|
-
//# sourceMappingURL=mutationObserver.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mutationObserver.ts"],"sourcesContent":["import { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport { hashKey, shallowEqualObjects } from './utils'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n MutateOptions,\n MutationFunctionContext,\n MutationObserverOptions,\n MutationObserverResult,\n} from './types'\nimport type { Action, Mutation } from './mutation'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (\n result: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n) => void\n\n// CLASS\n\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TOnMutateResult>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TOnMutateResult>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TOnMutateResult>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n super()\n\n this.#client = client\n this.setOptions(options)\n this.bindMethods()\n this.#updateResult()\n }\n\n protected bindMethods(): void {\n this.mutate = this.mutate.bind(this)\n this.reset = this.reset.bind(this)\n }\n\n setOptions(\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n const prevOptions = this.options as\n | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n | undefined\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(this.options, prevOptions)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n\n if (\n prevOptions?.mutationKey &&\n this.options.mutationKey &&\n hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)\n ) {\n this.reset()\n } else if (this.#currentMutation?.state.status === 'pending') {\n this.#currentMutation.setOptions(this.options)\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n onMutationUpdate(\n action: Action<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > {\n return this.#currentResult\n }\n\n reset(): void {\n // reset needs to remove the observer from the mutation because there is no way to \"get it back\"\n // another mutate call will yield a new mutation!\n this.#currentMutation?.removeObserver(this)\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,\n ): Promise<TData> {\n this.#mutateOptions = options\n\n this.#currentMutation?.removeObserver(this)\n\n this.#currentMutation = this.#client\n .getMutationCache()\n .build(this.#client, this.options)\n\n this.#currentMutation.addObserver(this)\n\n return this.#currentMutation.execute(variables)\n }\n\n #updateResult(): void {\n const state =\n this.#currentMutation?.state ??\n getDefaultState<TData, TError, TVariables, TOnMutateResult>()\n\n this.#currentResult = {\n ...state,\n isPending: state.status === 'pending',\n isSuccess: state.status === 'success',\n isError: state.status === 'error',\n isIdle: state.status === 'idle',\n mutate: this.mutate,\n reset: this.reset,\n } as MutationObserverResult<TData, TError, TVariables, TOnMutateResult>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n if (this.#mutateOptions && this.hasListeners()) {\n const variables = this.#currentResult.variables!\n const onMutateResult = this.#currentResult.context\n\n const context = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n if (action?.type === 'success') {\n try {\n this.#mutateOptions.onSuccess?.(\n action.data,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n action.data,\n null,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n } else if (action?.type === 'error') {\n try {\n this.#mutateOptions.onError?.(\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n undefined,\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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;AAAA,YACP;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA;AAAA,QAEJ,SAAS,GAAG;AACV,eAAK,QAAQ,OAAO,CAAC;AAAA,QACvB;AAAA,MACF,YAAW,iCAAQ,UAAS,SAAS;AACnC,YAAI;AACF,yCAAK,iBAAe,YAApB;AAAA;AAAA,YACE,OAAO;AAAA,YACP;AAAA,YACA;AAAA,YACA;AAAA;AAAA,QAEJ,SAAS,GAAG;AACV,eAAK,QAAQ,OAAO,CAAC;AAAA,QACvB;AACA,YAAI;AACF,yCAAK,iBAAe,cAApB;AAAA;AAAA,YACE;AAAA,YACA,OAAO;AAAA,YACP;AAAA,YACA;AAAA,YACA;AAAA;AAAA,QAEJ,SAAS,GAAG;AACV,eAAK,QAAQ,OAAO,CAAC;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAGA,SAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,eAAS,mBAAK,eAAc;AAAA,IAC9B,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MutationObserver_alias_1 as MutationObserver } from './_tsup-dts-rollup.cjs';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { MutationObserver_alias_1 as MutationObserver } from './_tsup-dts-rollup.js';
|