@tanstack/query-core 4.10.3 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/build/lib/mutation.esm.js +3 -3
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js +3 -3
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs +3 -3
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/mutationCache.d.ts +3 -3
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/umd/index.development.js +3 -3
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +5 -3
- package/src/mutation.ts +3 -3
- package/src/mutationCache.ts +3 -3
- package/src/tests/mutationCache.test.tsx +76 -0
- package/src/tests/utils.ts +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutationCache.mjs","sources":["../../src/mutationCache.ts"],"sourcesContent":["import type { MutationObserver } from './mutationObserver'\nimport type { MutationOptions } from './types'\nimport type { QueryClient } from './queryClient'\nimport { notifyManager } from './notifyManager'\nimport type { Action, MutationState } from './mutation'\nimport { Mutation } from './mutation'\nimport type { MutationFilters } from './utils'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\n\n// TYPES\n\ninterface MutationCacheConfig {\n onError?: (\n error: unknown,\n variables: unknown,\n context: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n ) =>
|
|
1
|
+
{"version":3,"file":"mutationCache.mjs","sources":["../../src/mutationCache.ts"],"sourcesContent":["import type { MutationObserver } from './mutationObserver'\nimport type { MutationOptions } from './types'\nimport type { QueryClient } from './queryClient'\nimport { notifyManager } from './notifyManager'\nimport type { Action, MutationState } from './mutation'\nimport { Mutation } from './mutation'\nimport type { MutationFilters } from './utils'\nimport { matchMutation, noop } from './utils'\nimport { Subscribable } from './subscribable'\n\n// TYPES\n\ninterface MutationCacheConfig {\n onError?: (\n error: unknown,\n variables: unknown,\n context: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n ) => Promise<unknown> | unknown\n onSuccess?: (\n data: unknown,\n variables: unknown,\n context: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\n ) => Promise<unknown> | unknown\n onMutate?: (\n variables: unknown,\n mutation: Mutation<unknown, unknown, unknown, unknown>,\n ) => Promise<unknown> | unknown\n}\n\ninterface NotifyEventMutationAdded {\n type: 'added'\n mutation: Mutation<any, any, any, any>\n}\ninterface NotifyEventMutationRemoved {\n type: 'removed'\n mutation: Mutation<any, any, any, any>\n}\n\ninterface NotifyEventMutationObserverAdded {\n type: 'observerAdded'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverRemoved {\n type: 'observerRemoved'\n mutation: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any>\n}\n\ninterface NotifyEventMutationObserverOptionsUpdated {\n type: 'observerOptionsUpdated'\n mutation?: Mutation<any, any, any, any>\n observer: MutationObserver<any, any, any, any>\n}\n\ninterface NotifyEventMutationUpdated {\n type: 'updated'\n mutation: Mutation<any, any, any, any>\n action: Action<any, any, any, any>\n}\n\ntype 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 config: MutationCacheConfig\n\n private mutations: Mutation<any, any, any, any>[]\n private mutationId: number\n\n constructor(config?: MutationCacheConfig) {\n super()\n this.config = config || {}\n this.mutations = []\n this.mutationId = 0\n }\n\n build<TData, TError, TVariables, TContext>(\n client: QueryClient,\n options: MutationOptions<TData, TError, TVariables, TContext>,\n state?: MutationState<TData, TError, TVariables, TContext>,\n ): Mutation<TData, TError, TVariables, TContext> {\n const mutation = new Mutation({\n mutationCache: this,\n logger: client.getLogger(),\n mutationId: ++this.mutationId,\n options: client.defaultMutationOptions(options),\n state,\n defaultOptions: options.mutationKey\n ? client.getMutationDefaults(options.mutationKey)\n : undefined,\n meta: options.meta,\n })\n\n this.add(mutation)\n\n return mutation\n }\n\n add(mutation: Mutation<any, any, any, any>): void {\n this.mutations.push(mutation)\n this.notify({ type: 'added', mutation })\n }\n\n remove(mutation: Mutation<any, any, any, any>): void {\n this.mutations = this.mutations.filter((x) => x !== mutation)\n this.notify({ type: 'removed', mutation })\n }\n\n clear(): void {\n notifyManager.batch(() => {\n this.mutations.forEach((mutation) => {\n this.remove(mutation)\n })\n })\n }\n\n getAll(): Mutation[] {\n return this.mutations\n }\n\n find<TData = unknown, TError = unknown, TVariables = any, TContext = unknown>(\n filters: MutationFilters,\n ): Mutation<TData, TError, TVariables, TContext> | undefined {\n if (typeof filters.exact === 'undefined') {\n filters.exact = true\n }\n\n return this.mutations.find((mutation) => matchMutation(filters, mutation))\n }\n\n findAll(filters: MutationFilters): Mutation[] {\n return this.mutations.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<void> {\n const pausedMutations = this.mutations.filter((x) => x.state.isPaused)\n return notifyManager.batch(() =>\n pausedMutations.reduce(\n (promise, mutation) =>\n promise.then(() => mutation.continue().catch(noop)),\n Promise.resolve(),\n ),\n )\n }\n}\n"],"names":["MutationCache","Subscribable","constructor","config","mutations","mutationId","build","client","options","state","mutation","Mutation","mutationCache","logger","getLogger","defaultMutationOptions","defaultOptions","mutationKey","getMutationDefaults","undefined","meta","add","push","notify","type","remove","filter","x","clear","notifyManager","batch","forEach","getAll","find","filters","exact","matchMutation","findAll","event","listeners","listener","resumePausedMutations","pausedMutations","isPaused","reduce","promise","then","continue","catch","noop","Promise","resolve"],"mappings":";;;;;AA0EA;AAEO,MAAMA,aAAN,SAA4BC,YAA5B,CAAgE;EAMrEC,WAAW,CAACC,MAAD,EAA+B;AACxC,IAAA,KAAA,EAAA,CAAA;AACA,IAAA,IAAA,CAAKA,MAAL,GAAcA,MAAM,IAAI,EAAxB,CAAA;IACA,IAAKC,CAAAA,SAAL,GAAiB,EAAjB,CAAA;IACA,IAAKC,CAAAA,UAAL,GAAkB,CAAlB,CAAA;AACD,GAAA;;AAEDC,EAAAA,KAAK,CACHC,MADG,EAEHC,OAFG,EAGHC,KAHG,EAI4C;AAC/C,IAAA,MAAMC,QAAQ,GAAG,IAAIC,QAAJ,CAAa;AAC5BC,MAAAA,aAAa,EAAE,IADa;AAE5BC,MAAAA,MAAM,EAAEN,MAAM,CAACO,SAAP,EAFoB;MAG5BT,UAAU,EAAE,EAAE,IAAA,CAAKA,UAHS;AAI5BG,MAAAA,OAAO,EAAED,MAAM,CAACQ,sBAAP,CAA8BP,OAA9B,CAJmB;MAK5BC,KAL4B;AAM5BO,MAAAA,cAAc,EAAER,OAAO,CAACS,WAAR,GACZV,MAAM,CAACW,mBAAP,CAA2BV,OAAO,CAACS,WAAnC,CADY,GAEZE,SARwB;MAS5BC,IAAI,EAAEZ,OAAO,CAACY,IAAAA;AATc,KAAb,CAAjB,CAAA;IAYA,IAAKC,CAAAA,GAAL,CAASX,QAAT,CAAA,CAAA;AAEA,IAAA,OAAOA,QAAP,CAAA;AACD,GAAA;;EAEDW,GAAG,CAACX,QAAD,EAA+C;AAChD,IAAA,IAAA,CAAKN,SAAL,CAAekB,IAAf,CAAoBZ,QAApB,CAAA,CAAA;AACA,IAAA,IAAA,CAAKa,MAAL,CAAY;AAAEC,MAAAA,IAAI,EAAE,OAAR;AAAiBd,MAAAA,QAAAA;KAA7B,CAAA,CAAA;AACD,GAAA;;EAEDe,MAAM,CAACf,QAAD,EAA+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,CAAA,CAAA;AAKD,GAAA;;AAEDG,EAAAA,qBAAqB,GAAkB;AACrC,IAAA,MAAMC,eAAe,GAAG,IAAKtC,CAAAA,SAAL,CAAesB,MAAf,CAAuBC,CAAD,IAAOA,CAAC,CAAClB,KAAF,CAAQkC,QAArC,CAAxB,CAAA;AACA,IAAA,OAAOd,aAAa,CAACC,KAAd,CAAoB,MACzBY,eAAe,CAACE,MAAhB,CACE,CAACC,OAAD,EAAUnC,QAAV,KACEmC,OAAO,CAACC,IAAR,CAAa,MAAMpC,QAAQ,CAACqC,QAAT,EAAA,CAAoBC,KAApB,CAA0BC,IAA1B,CAAnB,CAFJ,EAGEC,OAAO,CAACC,OAAR,EAHF,CADK,CAAP,CAAA;AAOD,GAAA;;AAxFoE;;;;"}
|
|
@@ -1476,7 +1476,7 @@
|
|
|
1476
1476
|
variables: this.options.variables
|
|
1477
1477
|
}); // Notify cache callback
|
|
1478
1478
|
|
|
1479
|
-
(_this$mutationCache$c = (_this$mutationCache$c2 = this.mutationCache.config).onMutate) == null ? void 0 : _this$mutationCache$c.call(_this$mutationCache$c2, this.state.variables, this);
|
|
1479
|
+
await ((_this$mutationCache$c = (_this$mutationCache$c2 = this.mutationCache.config).onMutate) == null ? void 0 : _this$mutationCache$c.call(_this$mutationCache$c2, this.state.variables, this));
|
|
1480
1480
|
const context = await ((_this$options$onMutat = (_this$options = this.options).onMutate) == null ? void 0 : _this$options$onMutat.call(_this$options, this.state.variables));
|
|
1481
1481
|
|
|
1482
1482
|
if (context !== this.state.context) {
|
|
@@ -1490,7 +1490,7 @@
|
|
|
1490
1490
|
|
|
1491
1491
|
const data = await executeMutation(); // Notify cache callback
|
|
1492
1492
|
|
|
1493
|
-
(_this$mutationCache$c3 = (_this$mutationCache$c4 = this.mutationCache.config).onSuccess) == null ? void 0 : _this$mutationCache$c3.call(_this$mutationCache$c4, data, this.state.variables, this.state.context, this);
|
|
1493
|
+
await ((_this$mutationCache$c3 = (_this$mutationCache$c4 = this.mutationCache.config).onSuccess) == null ? void 0 : _this$mutationCache$c3.call(_this$mutationCache$c4, data, this.state.variables, this.state.context, this));
|
|
1494
1494
|
await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options2, data, this.state.variables, this.state.context));
|
|
1495
1495
|
await ((_this$options$onSettl = (_this$options3 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options3, data, null, this.state.variables, this.state.context));
|
|
1496
1496
|
this.dispatch({
|
|
@@ -1503,7 +1503,7 @@
|
|
|
1503
1503
|
var _this$mutationCache$c5, _this$mutationCache$c6, _this$options$onError, _this$options4, _this$options$onSettl2, _this$options5;
|
|
1504
1504
|
|
|
1505
1505
|
// Notify cache callback
|
|
1506
|
-
(_this$mutationCache$c5 = (_this$mutationCache$c6 = this.mutationCache.config).onError) == null ? void 0 : _this$mutationCache$c5.call(_this$mutationCache$c6, error, this.state.variables, this.state.context, this);
|
|
1506
|
+
await ((_this$mutationCache$c5 = (_this$mutationCache$c6 = this.mutationCache.config).onError) == null ? void 0 : _this$mutationCache$c5.call(_this$mutationCache$c6, error, this.state.variables, this.state.context, this));
|
|
1507
1507
|
|
|
1508
1508
|
if ("development" !== 'production') {
|
|
1509
1509
|
this.logger.error(error);
|