@tanstack/query-core 5.0.0-alpha.3 → 5.0.0-alpha.6

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 (103) hide show
  1. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +13 -0
  2. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
  3. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +16 -0
  4. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  5. package/build/lib/focusManager.esm.js +31 -15
  6. package/build/lib/focusManager.esm.js.map +1 -1
  7. package/build/lib/focusManager.js +31 -15
  8. package/build/lib/focusManager.js.map +1 -1
  9. package/build/lib/hydration.esm.js +4 -2
  10. package/build/lib/hydration.esm.js.map +1 -1
  11. package/build/lib/hydration.js +4 -2
  12. package/build/lib/hydration.js.map +1 -1
  13. package/build/lib/infiniteQueryBehavior.d.ts +2 -2
  14. package/build/lib/infiniteQueryBehavior.esm.js +52 -48
  15. package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
  16. package/build/lib/infiniteQueryBehavior.js +52 -48
  17. package/build/lib/infiniteQueryBehavior.js.map +1 -1
  18. package/build/lib/infiniteQueryBehavior.mjs +48 -45
  19. package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
  20. package/build/lib/infiniteQueryObserver.d.ts +6 -6
  21. package/build/lib/infiniteQueryObserver.esm.js +7 -8
  22. package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
  23. package/build/lib/infiniteQueryObserver.js +7 -8
  24. package/build/lib/infiniteQueryObserver.js.map +1 -1
  25. package/build/lib/infiniteQueryObserver.mjs +4 -6
  26. package/build/lib/infiniteQueryObserver.mjs.map +1 -1
  27. package/build/lib/mutation.esm.js +127 -102
  28. package/build/lib/mutation.esm.js.map +1 -1
  29. package/build/lib/mutation.js +127 -102
  30. package/build/lib/mutation.js.map +1 -1
  31. package/build/lib/mutationCache.esm.js +30 -17
  32. package/build/lib/mutationCache.esm.js.map +1 -1
  33. package/build/lib/mutationCache.js +30 -17
  34. package/build/lib/mutationCache.js.map +1 -1
  35. package/build/lib/mutationObserver.esm.js +81 -51
  36. package/build/lib/mutationObserver.esm.js.map +1 -1
  37. package/build/lib/mutationObserver.js +81 -51
  38. package/build/lib/mutationObserver.js.map +1 -1
  39. package/build/lib/onlineManager.esm.js +29 -14
  40. package/build/lib/onlineManager.esm.js.map +1 -1
  41. package/build/lib/onlineManager.js +29 -14
  42. package/build/lib/onlineManager.js.map +1 -1
  43. package/build/lib/queriesObserver.esm.js +94 -65
  44. package/build/lib/queriesObserver.esm.js.map +1 -1
  45. package/build/lib/queriesObserver.js +94 -65
  46. package/build/lib/queriesObserver.js.map +1 -1
  47. package/build/lib/query.d.ts +4 -3
  48. package/build/lib/query.esm.js +210 -161
  49. package/build/lib/query.esm.js.map +1 -1
  50. package/build/lib/query.js +210 -161
  51. package/build/lib/query.js.map +1 -1
  52. package/build/lib/query.mjs.map +1 -1
  53. package/build/lib/queryCache.esm.js +16 -9
  54. package/build/lib/queryCache.esm.js.map +1 -1
  55. package/build/lib/queryCache.js +16 -9
  56. package/build/lib/queryCache.js.map +1 -1
  57. package/build/lib/queryClient.esm.js +103 -63
  58. package/build/lib/queryClient.esm.js.map +1 -1
  59. package/build/lib/queryClient.js +103 -63
  60. package/build/lib/queryClient.js.map +1 -1
  61. package/build/lib/queryObserver.esm.js +308 -207
  62. package/build/lib/queryObserver.esm.js.map +1 -1
  63. package/build/lib/queryObserver.js +307 -206
  64. package/build/lib/queryObserver.js.map +1 -1
  65. package/build/lib/removable.esm.js +13 -6
  66. package/build/lib/removable.esm.js.map +1 -1
  67. package/build/lib/removable.js +13 -6
  68. package/build/lib/removable.js.map +1 -1
  69. package/build/lib/retryer.esm.js +15 -14
  70. package/build/lib/retryer.esm.js.map +1 -1
  71. package/build/lib/retryer.js +15 -14
  72. package/build/lib/retryer.js.map +1 -1
  73. package/build/lib/tests/utils.d.ts +4 -5
  74. package/build/lib/types.d.ts +5 -3
  75. package/build/lib/utils.esm.js +1 -1
  76. package/build/lib/utils.esm.js.map +1 -1
  77. package/build/lib/utils.js +1 -1
  78. package/build/lib/utils.js.map +1 -1
  79. package/build/umd/index.development.js +52 -51
  80. package/build/umd/index.development.js.map +1 -1
  81. package/build/umd/index.production.js +1 -1
  82. package/build/umd/index.production.js.map +1 -1
  83. package/package.json +2 -2
  84. package/src/infiniteQueryBehavior.ts +52 -60
  85. package/src/infiniteQueryObserver.ts +15 -10
  86. package/src/query.ts +6 -4
  87. package/src/tests/focusManager.test.tsx +12 -14
  88. package/src/tests/hydration.test.tsx +15 -14
  89. package/src/tests/infiniteQueryBehavior.test.tsx +16 -9
  90. package/src/tests/infiniteQueryObserver.test.tsx +62 -1
  91. package/src/tests/mutationCache.test.tsx +11 -10
  92. package/src/tests/mutationObserver.test.tsx +3 -2
  93. package/src/tests/mutations.test.tsx +11 -10
  94. package/src/tests/notifyManager.test.tsx +7 -6
  95. package/src/tests/onlineManager.test.tsx +12 -17
  96. package/src/tests/queriesObserver.test.tsx +18 -17
  97. package/src/tests/query.test.tsx +18 -17
  98. package/src/tests/queryCache.test.tsx +14 -13
  99. package/src/tests/queryClient.test.tsx +49 -48
  100. package/src/tests/queryObserver.test.tsx +10 -9
  101. package/src/tests/utils.test.tsx +2 -1
  102. package/src/tests/utils.ts +5 -4
  103. package/src/types.ts +9 -1
@@ -1,28 +1,40 @@
1
1
  'use strict';
2
2
 
3
+ var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
3
4
  var notifyManager = require('./notifyManager.js');
4
5
  var mutation = require('./mutation.js');
5
6
  var utils = require('./utils.js');
6
7
  var subscribable = require('./subscribable.js');
7
8
 
8
9
  // TYPES
9
-
10
+ var _mutations = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutations");
11
+ var _mutationId = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutationId");
12
+ var _resuming = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("resuming");
10
13
  // CLASS
11
14
 
12
15
  class MutationCache extends subscribable.Subscribable {
13
- #mutations;
14
- #mutationId;
15
- #resuming;
16
16
  constructor(config = {}) {
17
17
  super();
18
+ Object.defineProperty(this, _mutations, {
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, _mutationId, {
23
+ writable: true,
24
+ value: void 0
25
+ });
26
+ Object.defineProperty(this, _resuming, {
27
+ writable: true,
28
+ value: void 0
29
+ });
18
30
  this.config = config;
19
- this.#mutations = [];
20
- this.#mutationId = 0;
31
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations] = [];
32
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationId)[_mutationId] = 0;
21
33
  }
22
34
  build(client, options, state) {
23
35
  const mutation$1 = new mutation.Mutation({
24
36
  mutationCache: this,
25
- mutationId: ++this.#mutationId,
37
+ mutationId: ++_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutationId)[_mutationId],
26
38
  options: client.defaultMutationOptions(options),
27
39
  state
28
40
  });
@@ -30,14 +42,14 @@ class MutationCache extends subscribable.Subscribable {
30
42
  return mutation$1;
31
43
  }
32
44
  add(mutation) {
33
- this.#mutations.push(mutation);
45
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].push(mutation);
34
46
  this.notify({
35
47
  type: 'added',
36
48
  mutation
37
49
  });
38
50
  }
39
51
  remove(mutation) {
40
- this.#mutations = this.#mutations.filter(x => x !== mutation);
52
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].filter(x => x !== mutation);
41
53
  this.notify({
42
54
  type: 'removed',
43
55
  mutation
@@ -45,22 +57,22 @@ class MutationCache extends subscribable.Subscribable {
45
57
  }
46
58
  clear() {
47
59
  notifyManager.notifyManager.batch(() => {
48
- this.#mutations.forEach(mutation => {
60
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].forEach(mutation => {
49
61
  this.remove(mutation);
50
62
  });
51
63
  });
52
64
  }
53
65
  getAll() {
54
- return this.#mutations;
66
+ return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations];
55
67
  }
56
68
  find(filters) {
57
69
  if (typeof filters.exact === 'undefined') {
58
70
  filters.exact = true;
59
71
  }
60
- return this.#mutations.find(mutation => utils.matchMutation(filters, mutation));
72
+ return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].find(mutation => utils.matchMutation(filters, mutation));
61
73
  }
62
74
  findAll(filters = {}) {
63
- return this.#mutations.filter(mutation => utils.matchMutation(filters, mutation));
75
+ return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].filter(mutation => utils.matchMutation(filters, mutation));
64
76
  }
65
77
  notify(event) {
66
78
  notifyManager.notifyManager.batch(() => {
@@ -70,13 +82,14 @@ class MutationCache extends subscribable.Subscribable {
70
82
  });
71
83
  }
72
84
  resumePausedMutations() {
73
- this.#resuming = (this.#resuming ?? Promise.resolve()).then(() => {
74
- const pausedMutations = this.#mutations.filter(x => x.state.isPaused);
85
+ var _classPrivateFieldLoo;
86
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _resuming)[_resuming] = ((_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _resuming)[_resuming]) != null ? _classPrivateFieldLoo : Promise.resolve()).then(() => {
87
+ const pausedMutations = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutations)[_mutations].filter(x => x.state.isPaused);
75
88
  return notifyManager.notifyManager.batch(() => pausedMutations.reduce((promise, mutation) => promise.then(() => mutation.continue().catch(utils.noop)), Promise.resolve()));
76
89
  }).then(() => {
77
- this.#resuming = undefined;
90
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _resuming)[_resuming] = undefined;
78
91
  });
79
- return this.#resuming;
92
+ return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _resuming)[_resuming];
80
93
  }
81
94
  }
82
95
 
@@ -1 +1 @@
1
- {"version":3,"file":"mutationCache.js","sources":["../../src/mutationCache.ts"],"sourcesContent":["import type { MutationObserver } from './mutationObserver'\nimport type { NotifyEvent, MutationOptions, DefaultError } 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: DefaultError,\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>,\n ) => Promise<unknown> | unknown\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n context: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\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\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 #mutations: Mutation<any, any, any, any>[]\n #mutationId: number\n #resuming: Promise<unknown> | undefined\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\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 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.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<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TContext = unknown,\n >(\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) =>\n matchMutation(filters, mutation),\n )\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 this.#resuming = (this.#resuming ?? Promise.resolve())\n .then(() => {\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() as Promise<unknown>,\n ),\n )\n })\n .then(() => {\n this.#resuming = undefined\n })\n\n return this.#resuming\n }\n}\n"],"names":["MutationCache","Subscribable","constructor","config","build","client","options","state","mutation","Mutation","mutationCache","mutationId","defaultMutationOptions","add","push","notify","type","remove","filter","x","clear","notifyManager","batch","forEach","getAll","find","filters","exact","matchMutation","findAll","event","listeners","listener","resumePausedMutations","Promise","resolve","then","pausedMutations","isPaused","reduce","promise","continue","catch","noop","undefined"],"mappings":";;;;;;;AAUA;;AAuEA;;AAEO,MAAMA,aAAa,SAASC,yBAAY,CAAwB;AACrE,EAAA,UAAU,CAAA;AACV,EAAA,WAAW,CAAA;AACX,EAAA,SAAS,CAAA;AAETC,EAAAA,WAAW,CAAQC,MAA2B,GAAG,EAAE,EAAE;AACnD,IAAA,KAAK,EAAE,CAAA;IAAA,IADUA,CAAAA,MAA2B,GAA3BA,MAA2B,CAAA;AAE5C,IAAA,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;AACpB,IAAA,IAAI,CAAC,WAAW,GAAG,CAAC,CAAA;AACtB,GAAA;AAEAC,EAAAA,KAAK,CACHC,MAAmB,EACnBC,OAA6D,EAC7DC,KAA0D,EACX;AAC/C,IAAA,MAAMC,UAAQ,GAAG,IAAIC,iBAAQ,CAAC;AAC5BC,MAAAA,aAAa,EAAE,IAAI;AACnBC,MAAAA,UAAU,EAAE,EAAE,IAAI,CAAC,W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"mutationCache.js","sources":["../../src/mutationCache.ts"],"sourcesContent":["import type { MutationObserver } from './mutationObserver'\nimport type { NotifyEvent, MutationOptions, DefaultError } 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: DefaultError,\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>,\n ) => Promise<unknown> | unknown\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n variables: unknown,\n context: unknown,\n mutation: Mutation<unknown, unknown, unknown>,\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\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 #mutations: Mutation<any, any, any, any>[]\n #mutationId: number\n #resuming: Promise<unknown> | undefined\n\n constructor(public config: MutationCacheConfig = {}) {\n super()\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 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.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<\n TData = unknown,\n TError = DefaultError,\n TVariables = any,\n TContext = unknown,\n >(\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) =>\n matchMutation(filters, mutation),\n )\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 this.#resuming = (this.#resuming ?? Promise.resolve())\n .then(() => {\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() as Promise<unknown>,\n ),\n )\n })\n .then(() => {\n this.#resuming = undefined\n })\n\n return this.#resuming\n }\n}\n"],"names":["_classPrivateFieldLooseKey","MutationCache","Subscribable","constructor","config","_classPrivateFieldLooseBase","build","client","options","state","mutation","Mutation","mutationCache","mutationId","defaultMutationOptions","add","push","notify","type","remove","filter","x","clear","notifyManager","batch","forEach","getAll","find","filters","exact","matchMutation","findAll","event","listeners","listener","resumePausedMutations","Promise","resolve","then","pausedMutations","isPaused","reduce","promise","continue","catch","noop","undefined"],"mappings":";;;;;;;;AAUA;AAAA,IAAA,UAAA,gBAAAA,mDAAA,CAAA,WAAA,CAAA,CAAA;AAAA,IAAA,WAAA,gBAAAA,mDAAA,CAAA,YAAA,CAAA,CAAA;AAAA,IAAA,SAAA,gBAAAA,mDAAA,CAAA,UAAA,CAAA,CAAA;AAuEA;;AAEO,MAAMC,aAAa,SAASC,yBAAY,CAAwB;AAKrEC,EAAAA,WAAW,CAAQC,MAA2B,GAAG,EAAE,EAAE;AACnD,IAAA,KAAK,EAAE,CAAA;AAAA,IAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,UAAA,EAAA;AAAA,MAAA,QAAA,EAAA,IAAA;AAAA,MAAA,KAAA,EAAA,KAAA,CAAA;AAAA,KAAA,CAAA,CAAA;AAAA,IAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,WAAA,EAAA;AAAA,MAAA,QAAA,EAAA,IAAA;AAAA,MAAA,KAAA,EAAA,KAAA,CAAA;AAAA,KAAA,CAAA,CAAA;AAAA,IAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,SAAA,EAAA;AAAA,MAAA,QAAA,EAAA,IAAA;AAAA,MA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,CAAA;AACJ,GAAA;AAEAG,EAAAA,qBAAqB,GAAqB;AAAA,IAAA,IAAA,qBAAA,CAAA;IACxC9B,oDAAI,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA,SAAA,CAAA,GAAa,CAAC,CAAA,qBAAA,GAAAA,oDAAA,CAAA,IAAI,EAAc+B,SAAAA,CAAAA,CAAAA,SAAAA,CAAAA,KAAAA,IAAAA,GAAAA,qBAAAA,GAAAA,OAAO,CAACC,OAAO,EAAE,EAClDC,IAAI,CAAC,MAAM;AACV,MAAA,MAAMC,eAAe,GAAGlC,oDAAI,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA,UAAA,CAAA,CAAYe,MAAM,CAAEC,CAAC,IAAKA,CAAC,CAACZ,KAAK,CAAC+B,QAAQ,CAAC,CAAA;AACvE,MAAA,OAAOjB,2BAAa,CAACC,KAAK,CAAC,MACzBe,eAAe,CAACE,MAAM,CACpB,CAACC,OAAO,EAAEhC,QAAQ,KAChBgC,OAAO,CAACJ,IAAI,CAAC,MAAM5B,QAAQ,CAACiC,QAAQ,EAAE,CAACC,KAAK,CAACC,UAAI,CAAC,CAAC,EACrDT,OAAO,CAACC,OAAO,EAAE,CAClB,CACF,CAAA;AACH,KAAC,CAAC,CACDC,IAAI,CAAC,MAAM;AACV,MAAAjC,oDAAA,CAAA,IAAI,0BAAayC,SAAS,CAAA;AAC5B,KAAC,CAAC,CAAA;AAEJ,IAAA,OAAAzC,oDAAA,CAAO,IAAI,EAAA,SAAA,CAAA,CAAA,SAAA,CAAA,CAAA;AACb,GAAA;AACF;;;;"}
@@ -1,95 +1,125 @@
1
+ import { classPrivateFieldLooseBase as _classPrivateFieldLooseBase, classPrivateFieldLooseKey as _classPrivateFieldLooseKey } from './_virtual/_rollupPluginBabelHelpers.esm.js';
1
2
  import { getDefaultState } from './mutation.esm.js';
2
3
  import { notifyManager } from './notifyManager.esm.js';
3
4
  import { Subscribable } from './subscribable.esm.js';
4
5
  import { shallowEqualObjects } from './utils.esm.js';
5
6
 
6
7
  // TYPES
7
-
8
+ var _client = /*#__PURE__*/_classPrivateFieldLooseKey("client");
9
+ var _currentResult = /*#__PURE__*/_classPrivateFieldLooseKey("currentResult");
10
+ var _currentMutation = /*#__PURE__*/_classPrivateFieldLooseKey("currentMutation");
11
+ var _mutateOptions = /*#__PURE__*/_classPrivateFieldLooseKey("mutateOptions");
12
+ var _updateResult = /*#__PURE__*/_classPrivateFieldLooseKey("updateResult");
13
+ var _notify = /*#__PURE__*/_classPrivateFieldLooseKey("notify");
8
14
  // CLASS
9
15
 
10
16
  class MutationObserver extends Subscribable {
11
- #client;
12
- #currentResult = undefined;
13
- #currentMutation;
14
- #mutateOptions;
15
17
  constructor(client, options) {
16
18
  super();
17
- this.#client = client;
19
+ Object.defineProperty(this, _notify, {
20
+ value: _notify2
21
+ });
22
+ Object.defineProperty(this, _updateResult, {
23
+ value: _updateResult2
24
+ });
25
+ Object.defineProperty(this, _client, {
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, _currentResult, {
30
+ writable: true,
31
+ value: undefined
32
+ });
33
+ Object.defineProperty(this, _currentMutation, {
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ Object.defineProperty(this, _mutateOptions, {
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ _classPrivateFieldLooseBase(this, _client)[_client] = client;
18
42
  this.setOptions(options);
19
43
  this.bindMethods();
20
- this.#updateResult();
44
+ _classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
21
45
  }
22
46
  bindMethods() {
23
47
  this.mutate = this.mutate.bind(this);
24
48
  this.reset = this.reset.bind(this);
25
49
  }
26
50
  setOptions(options) {
51
+ var _classPrivateFieldLoo;
27
52
  const prevOptions = this.options;
28
- this.options = this.#client.defaultMutationOptions(options);
53
+ this.options = _classPrivateFieldLooseBase(this, _client)[_client].defaultMutationOptions(options);
29
54
  if (!shallowEqualObjects(prevOptions, this.options)) {
30
- this.#client.getMutationCache().notify({
55
+ _classPrivateFieldLooseBase(this, _client)[_client].getMutationCache().notify({
31
56
  type: 'observerOptionsUpdated',
32
- mutation: this.#currentMutation,
57
+ mutation: _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation],
33
58
  observer: this
34
59
  });
35
60
  }
36
- this.#currentMutation?.setOptions(this.options);
61
+ (_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo.setOptions(this.options);
37
62
  }
38
63
  onUnsubscribe() {
39
64
  if (!this.listeners.length) {
40
- this.#currentMutation?.removeObserver(this);
65
+ var _classPrivateFieldLoo2;
66
+ (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo2.removeObserver(this);
41
67
  }
42
68
  }
43
69
  onMutationUpdate(action) {
44
- this.#updateResult();
45
- this.#notify(action);
70
+ _classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
71
+ _classPrivateFieldLooseBase(this, _notify)[_notify](action);
46
72
  }
47
73
  getCurrentResult() {
48
- return this.#currentResult;
74
+ return _classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
49
75
  }
50
76
  reset() {
51
- this.#currentMutation = undefined;
52
- this.#updateResult();
53
- this.#notify();
77
+ _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation] = undefined;
78
+ _classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
79
+ _classPrivateFieldLooseBase(this, _notify)[_notify]();
54
80
  }
55
81
  mutate(variables, options) {
56
- this.#mutateOptions = options;
57
- this.#currentMutation?.removeObserver(this);
58
- this.#currentMutation = this.#client.getMutationCache().build(this.#client, this.options);
59
- this.#currentMutation.addObserver(this);
60
- return this.#currentMutation.execute(variables);
82
+ var _classPrivateFieldLoo3;
83
+ _classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions] = options;
84
+ (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo3.removeObserver(this);
85
+ _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation] = _classPrivateFieldLooseBase(this, _client)[_client].getMutationCache().build(_classPrivateFieldLooseBase(this, _client)[_client], this.options);
86
+ _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation].addObserver(this);
87
+ return _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation].execute(variables);
61
88
  }
62
- #updateResult() {
63
- const state = this.#currentMutation?.state ?? getDefaultState();
64
- this.#currentResult = {
65
- ...state,
66
- isPending: state.status === 'pending',
67
- isSuccess: state.status === 'success',
68
- isError: state.status === 'error',
69
- isIdle: state.status === 'idle',
70
- mutate: this.mutate,
71
- reset: this.reset
72
- };
73
- }
74
- #notify(action) {
75
- notifyManager.batch(() => {
76
- // First trigger the mutate callbacks
77
- if (this.#mutateOptions && this.hasListeners()) {
78
- if (action?.type === 'success') {
79
- this.#mutateOptions.onSuccess?.(action.data, this.#currentResult.variables, this.#currentResult.context);
80
- this.#mutateOptions.onSettled?.(action.data, null, this.#currentResult.variables, this.#currentResult.context);
81
- } else if (action?.type === 'error') {
82
- this.#mutateOptions.onError?.(action.error, this.#currentResult.variables, this.#currentResult.context);
83
- this.#mutateOptions.onSettled?.(undefined, action.error, this.#currentResult.variables, this.#currentResult.context);
84
- }
89
+ }
90
+ function _updateResult2() {
91
+ var _classPrivateFieldLoo4, _classPrivateFieldLoo5;
92
+ const state = (_classPrivateFieldLoo4 = (_classPrivateFieldLoo5 = _classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo5.state) != null ? _classPrivateFieldLoo4 : getDefaultState();
93
+ _classPrivateFieldLooseBase(this, _currentResult)[_currentResult] = {
94
+ ...state,
95
+ isPending: state.status === 'pending',
96
+ isSuccess: state.status === 'success',
97
+ isError: state.status === 'error',
98
+ isIdle: state.status === 'idle',
99
+ mutate: this.mutate,
100
+ reset: this.reset
101
+ };
102
+ }
103
+ function _notify2(action) {
104
+ notifyManager.batch(() => {
105
+ // First trigger the mutate callbacks
106
+ if (_classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions] && this.hasListeners()) {
107
+ if ((action == null ? void 0 : action.type) === 'success') {
108
+ var _classPrivateFieldLoo6, _classPrivateFieldLoo7, _classPrivateFieldLoo8, _classPrivateFieldLoo9;
109
+ (_classPrivateFieldLoo6 = (_classPrivateFieldLoo7 = _classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSuccess) == null ? void 0 : _classPrivateFieldLoo6.call(_classPrivateFieldLoo7, action.data, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
110
+ (_classPrivateFieldLoo8 = (_classPrivateFieldLoo9 = _classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSettled) == null ? void 0 : _classPrivateFieldLoo8.call(_classPrivateFieldLoo9, action.data, null, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
111
+ } else if ((action == null ? void 0 : action.type) === 'error') {
112
+ var _classPrivateFieldLoo10, _classPrivateFieldLoo11, _classPrivateFieldLoo12, _classPrivateFieldLoo13;
113
+ (_classPrivateFieldLoo10 = (_classPrivateFieldLoo11 = _classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onError) == null ? void 0 : _classPrivateFieldLoo10.call(_classPrivateFieldLoo11, action.error, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
114
+ (_classPrivateFieldLoo12 = (_classPrivateFieldLoo13 = _classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSettled) == null ? void 0 : _classPrivateFieldLoo12.call(_classPrivateFieldLoo13, undefined, action.error, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
85
115
  }
116
+ }
86
117
 
87
- // Then trigger the listeners
88
- this.listeners.forEach(listener => {
89
- listener(this.#currentResult);
90
- });
118
+ // Then trigger the listeners
119
+ this.listeners.forEach(listener => {
120
+ listener(_classPrivateFieldLooseBase(this, _currentResult)[_currentResult]);
91
121
  });
92
- }
122
+ });
93
123
  }
94
124
 
95
125
  export { MutationObserver };
@@ -1 +1 @@
1
- {"version":3,"file":"mutationObserver.esm.js","sources":["../../src/mutationObserver.ts"],"sourcesContent":["import type { Action, Mutation } from './mutation'\nimport { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport type { QueryClient } from './queryClient'\nimport { Subscribable } from './subscribable'\nimport type {\n MutateOptions,\n MutationObserverResult,\n MutationObserverOptions,\n DefaultError,\n} from './types'\nimport { shallowEqualObjects } from './utils'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TContext> = (\n result: MutationObserverResult<TData, TError, TVariables, TContext>,\n) => void\n\n// CLASS\n\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TContext>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TContext>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<TData, TError, TVariables, TContext> =\n undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TContext>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<TData, TError, TVariables, TContext>,\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<TData, TError, TVariables, TContext>,\n ) {\n const prevOptions = this.options\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(prevOptions, this.options)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n this.#currentMutation?.setOptions(this.options)\n }\n\n protected onUnsubscribe(): void {\n if (!this.listeners.length) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n onMutationUpdate(action: Action<TData, TError, TVariables, TContext>): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TContext\n > {\n return this.#currentResult\n }\n\n reset(): void {\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TContext>,\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, TContext>()\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, TContext>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TContext>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n if (this.#mutateOptions && this.hasListeners()) {\n if (action?.type === 'success') {\n this.#mutateOptions.onSuccess?.(\n action.data,\n this.#currentResult.variables!,\n this.#currentResult.context!,\n )\n this.#mutateOptions.onSettled?.(\n action.data,\n null,\n this.#currentResult.variables!,\n this.#currentResult.context,\n )\n } else if (action?.type === 'error') {\n this.#mutateOptions.onError?.(\n action.error,\n this.#currentResult.variables!,\n this.#currentResult.context,\n )\n this.#mutateOptions.onSettled?.(\n undefined,\n action.error,\n this.#currentResult.variables!,\n this.#currentResult.context,\n )\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n })\n }\n}\n"],"names":["MutationObserver","Subscribable","undefined","constructor","client","options","setOptions","bindMethods","mutate","bind","reset","prevOptions","defaultMutationOptions","shallowEqualObjects","getMutationCache","notify","type","mutation","observer","onUnsubscribe","listeners","length","removeObserver","onMutationUpdate","action","getCurrentResult","variables","build","addObserver","execute","state","getDefaultState","isPending","status","isSuccess","isError","isIdle","notifyManager","batch","hasListeners","onSuccess","data","context","onSettled","onError","error","forEach","listener"],"mappings":";;;;;AAaA;;AAMA;;AAEO,MAAMA,gBAAgB,SAKnBC,YAAY,CAEpB;AAGA,EAAA,OAAO,CAAA;EACP,cAAc,GACZC,SAAS,CAAA;AACX,EAAA,gBAAgB,CAAA;AAChB,EAAA,cAAc,CAAA;AAEdC,EAAAA,WAAW,CACTC,MAAmB,EACnBC,OAAqE,EACrE;AACA,IAAA,KAAK,EAAE,CAAA;AAEP,IAAA,IAAI,CAAC,OAAO,GAAGD,MAAM,CAAA;AACrB,IAAA,IAAI,CAACE,UAAU,CAACD,OAAO,CAAC,CAAA;IACxB,IAAI,CAACE,WAAW,EAAE,CAAA;IAClB,IAAI,CAAC,aAAa,EAAE,CAAA;AACtB,GAAA;AAEUA,EAAAA,WAAW,GAAS;IAC5B,IAAI,CAACC,MAAM,GAAG,IAAI,CAACA,MAAM,CAACC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpC,IAAI,CAACC,KAAK,GAAG,IAAI,CAACA,KAAK,CAACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACpC,GAAA;EAEAH,UAAU,CACRD,OAAsE,EACtE;AACA,IAAA,MAAMM,WAAW,GAAG,IAAI,CAACN,OAAO,CAAA;IAChC,IAAI,CAACA,OAAO,GAAG,IAAI,CAAC,OAAO,CAACO,sBAAsB,CAACP,OAAO,CAAC,CAAA;IAC3D,IAAI,CAACQ,mBAAmB,CAACF,WAAW,EAAE,IAAI,CAACN,OAAO,CAAC,EAAE;MACnD,IAAI,CAAC,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KAAK,EACZ,IAAI,CAAC,cAAc,CAACnB,SAAS,EAC7B,IAAI,CAAC,cAAc,CAACgB,OAAO,CAC5B,CAAA;UACD,IAAI,CAAC,cAAc,CAACC,SAAS,GAC3BzC,SAAS,EACTsB,MAAM,CAACqB,KAAK,EACZ,IAAI,CAAC,cAAc,CAACnB,SAAS,EAC7B,IAAI,CAAC,cAAc,CAACgB,OAAO,CAC5B,CAAA;AACH,SAAA;AACF,OAAA;;AAEA;AACA,MAAA,IAAI,CAACtB,SAAS,CAAC0B,OAAO,CAAEC,QAAQ,IAAK;AACnCA,QAAAA,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;AAC/B,OAAC,CAAC,CAAA;AACJ,KAAC,CAAC,CAAA;AACJ,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"mutationObserver.esm.js","sources":["../../src/mutationObserver.ts"],"sourcesContent":["import type { Action, Mutation } from './mutation'\nimport { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport type { QueryClient } from './queryClient'\nimport { Subscribable } from './subscribable'\nimport type {\n MutateOptions,\n MutationObserverResult,\n MutationObserverOptions,\n DefaultError,\n} from './types'\nimport { shallowEqualObjects } from './utils'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TContext> = (\n result: MutationObserverResult<TData, TError, TVariables, TContext>,\n) => void\n\n// CLASS\n\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TContext>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TContext>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<TData, TError, TVariables, TContext> =\n undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TContext>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<TData, TError, TVariables, TContext>,\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<TData, TError, TVariables, TContext>,\n ) {\n const prevOptions = this.options\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(prevOptions, this.options)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n this.#currentMutation?.setOptions(this.options)\n }\n\n protected onUnsubscribe(): void {\n if (!this.listeners.length) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n onMutationUpdate(action: Action<TData, TError, TVariables, TContext>): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TContext\n > {\n return this.#currentResult\n }\n\n reset(): void {\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TContext>,\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, TContext>()\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, TContext>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TContext>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n if (this.#mutateOptions && this.hasListeners()) {\n if (action?.type === 'success') {\n this.#mutateOptions.onSuccess?.(\n action.data,\n this.#currentResult.variables!,\n this.#currentResult.context!,\n )\n this.#mutateOptions.onSettled?.(\n action.data,\n null,\n this.#currentResult.variables!,\n this.#currentResult.context,\n )\n } else if (action?.type === 'error') {\n this.#mutateOptions.onError?.(\n action.error,\n this.#currentResult.variables!,\n this.#currentResult.context,\n )\n this.#mutateOptions.onSettled?.(\n undefined,\n action.error,\n this.#currentResult.variables!,\n this.#currentResult.context,\n )\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n })\n }\n}\n"],"names":["MutationObserver","Subscribable","constructor","client","options","undefined","setOptions","bindMethods","mutate","bind","reset","prevOptions","defaultMutationOptions","shallowEqualObjects","getMutationCache","notify","type","mutation","observer","onUnsubscribe","listeners","length","removeObserver","onMutationUpdate","action","getCurrentResult","variables","build","addObserver","execute","state","getDefaultState","isPending","status","isSuccess","isError","isIdle","notifyManager","batch","hasListeners","onSuccess","data","context","onSettled","onError","error","forEach","listener"],"mappings":";;;;;;AAaA;AAAA,IAAA,OAAA,gBAAA,0BAAA,CAAA,QAAA,CAAA,CAAA;AAAA,IAAA,cAAA,gBAAA,0BAAA,CAAA,eAAA,CAAA,CAAA;AAAA,IAAA,gBAAA,gBAAA,0BAAA,CAAA,iBAAA,CAAA,CAAA;AAAA,IAAA,cAAA,gBAAA,0BAAA,CAAA,eAAA,CAAA,CAAA;AAAA,IAAA,aAAA,gBAAA,0BAAA,CAAA,cAAA,CAAA,CAAA;AAAA,IAAA,OAAA,gBAAA,0BAAA,CAAA,QAAA,CAAA,CAAA;AAMA;;AAEO,MAAMA,gBAAgB,SAKnBC,YAAY,CAEpB;AASAC,EAAAA,WAAW,CACTC,MAAmB,EACnBC,OAAqE,EACrE;AACA,IAAA,KAAK,EAAE,CAAA;AAAA,IAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,OAAA,EAAA;AAAA,MAAA,KAAA,EAAA,QAAA;AAAA,KAAA,CAAA,CAAA;AAAA,IAAA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,aAAA,EAAA;AAAA,M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AAEA;AACA,IAAA,IAAI,CAACtB,SAAS,CAAC0B,OAAO,CAAEC,QAAQ,IAAK;MACnCA,QAAQ,CAAA,2BAAA,CAAC,IAAI,EAAgB,cAAA,CAAA,CAAA,cAAA,CAAA,CAAA,CAAA;AAC/B,KAAC,CAAC,CAAA;AACJ,GAAC,CAAC,CAAA;AACJ;;;;"}
@@ -1,97 +1,127 @@
1
1
  'use strict';
2
2
 
3
+ var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
3
4
  var mutation = require('./mutation.js');
4
5
  var notifyManager = require('./notifyManager.js');
5
6
  var subscribable = require('./subscribable.js');
6
7
  var utils = require('./utils.js');
7
8
 
8
9
  // TYPES
9
-
10
+ var _client = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("client");
11
+ var _currentResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentResult");
12
+ var _currentMutation = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentMutation");
13
+ var _mutateOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("mutateOptions");
14
+ var _updateResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateResult");
15
+ var _notify = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("notify");
10
16
  // CLASS
11
17
 
12
18
  class MutationObserver extends subscribable.Subscribable {
13
- #client;
14
- #currentResult = undefined;
15
- #currentMutation;
16
- #mutateOptions;
17
19
  constructor(client, options) {
18
20
  super();
19
- this.#client = client;
21
+ Object.defineProperty(this, _notify, {
22
+ value: _notify2
23
+ });
24
+ Object.defineProperty(this, _updateResult, {
25
+ value: _updateResult2
26
+ });
27
+ Object.defineProperty(this, _client, {
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ Object.defineProperty(this, _currentResult, {
32
+ writable: true,
33
+ value: undefined
34
+ });
35
+ Object.defineProperty(this, _currentMutation, {
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, _mutateOptions, {
40
+ writable: true,
41
+ value: void 0
42
+ });
43
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = client;
20
44
  this.setOptions(options);
21
45
  this.bindMethods();
22
- this.#updateResult();
46
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
23
47
  }
24
48
  bindMethods() {
25
49
  this.mutate = this.mutate.bind(this);
26
50
  this.reset = this.reset.bind(this);
27
51
  }
28
52
  setOptions(options) {
53
+ var _classPrivateFieldLoo;
29
54
  const prevOptions = this.options;
30
- this.options = this.#client.defaultMutationOptions(options);
55
+ this.options = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].defaultMutationOptions(options);
31
56
  if (!utils.shallowEqualObjects(prevOptions, this.options)) {
32
- this.#client.getMutationCache().notify({
57
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getMutationCache().notify({
33
58
  type: 'observerOptionsUpdated',
34
- mutation: this.#currentMutation,
59
+ mutation: _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation],
35
60
  observer: this
36
61
  });
37
62
  }
38
- this.#currentMutation?.setOptions(this.options);
63
+ (_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo.setOptions(this.options);
39
64
  }
40
65
  onUnsubscribe() {
41
66
  if (!this.listeners.length) {
42
- this.#currentMutation?.removeObserver(this);
67
+ var _classPrivateFieldLoo2;
68
+ (_classPrivateFieldLoo2 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo2.removeObserver(this);
43
69
  }
44
70
  }
45
71
  onMutationUpdate(action) {
46
- this.#updateResult();
47
- this.#notify(action);
72
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
73
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify](action);
48
74
  }
49
75
  getCurrentResult() {
50
- return this.#currentResult;
76
+ return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
51
77
  }
52
78
  reset() {
53
- this.#currentMutation = undefined;
54
- this.#updateResult();
55
- this.#notify();
79
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation] = undefined;
80
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
81
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify]();
56
82
  }
57
83
  mutate(variables, options) {
58
- this.#mutateOptions = options;
59
- this.#currentMutation?.removeObserver(this);
60
- this.#currentMutation = this.#client.getMutationCache().build(this.#client, this.options);
61
- this.#currentMutation.addObserver(this);
62
- return this.#currentMutation.execute(variables);
84
+ var _classPrivateFieldLoo3;
85
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions] = options;
86
+ (_classPrivateFieldLoo3 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo3.removeObserver(this);
87
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getMutationCache().build(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client], this.options);
88
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation].addObserver(this);
89
+ return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation].execute(variables);
63
90
  }
64
- #updateResult() {
65
- const state = this.#currentMutation?.state ?? mutation.getDefaultState();
66
- this.#currentResult = {
67
- ...state,
68
- isPending: state.status === 'pending',
69
- isSuccess: state.status === 'success',
70
- isError: state.status === 'error',
71
- isIdle: state.status === 'idle',
72
- mutate: this.mutate,
73
- reset: this.reset
74
- };
75
- }
76
- #notify(action) {
77
- notifyManager.notifyManager.batch(() => {
78
- // First trigger the mutate callbacks
79
- if (this.#mutateOptions && this.hasListeners()) {
80
- if (action?.type === 'success') {
81
- this.#mutateOptions.onSuccess?.(action.data, this.#currentResult.variables, this.#currentResult.context);
82
- this.#mutateOptions.onSettled?.(action.data, null, this.#currentResult.variables, this.#currentResult.context);
83
- } else if (action?.type === 'error') {
84
- this.#mutateOptions.onError?.(action.error, this.#currentResult.variables, this.#currentResult.context);
85
- this.#mutateOptions.onSettled?.(undefined, action.error, this.#currentResult.variables, this.#currentResult.context);
86
- }
91
+ }
92
+ function _updateResult2() {
93
+ var _classPrivateFieldLoo4, _classPrivateFieldLoo5;
94
+ const state = (_classPrivateFieldLoo4 = (_classPrivateFieldLoo5 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentMutation)[_currentMutation]) == null ? void 0 : _classPrivateFieldLoo5.state) != null ? _classPrivateFieldLoo4 : mutation.getDefaultState();
95
+ _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult] = {
96
+ ...state,
97
+ isPending: state.status === 'pending',
98
+ isSuccess: state.status === 'success',
99
+ isError: state.status === 'error',
100
+ isIdle: state.status === 'idle',
101
+ mutate: this.mutate,
102
+ reset: this.reset
103
+ };
104
+ }
105
+ function _notify2(action) {
106
+ notifyManager.notifyManager.batch(() => {
107
+ // First trigger the mutate callbacks
108
+ if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions] && this.hasListeners()) {
109
+ if ((action == null ? void 0 : action.type) === 'success') {
110
+ var _classPrivateFieldLoo6, _classPrivateFieldLoo7, _classPrivateFieldLoo8, _classPrivateFieldLoo9;
111
+ (_classPrivateFieldLoo6 = (_classPrivateFieldLoo7 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSuccess) == null ? void 0 : _classPrivateFieldLoo6.call(_classPrivateFieldLoo7, action.data, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
112
+ (_classPrivateFieldLoo8 = (_classPrivateFieldLoo9 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSettled) == null ? void 0 : _classPrivateFieldLoo8.call(_classPrivateFieldLoo9, action.data, null, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
113
+ } else if ((action == null ? void 0 : action.type) === 'error') {
114
+ var _classPrivateFieldLoo10, _classPrivateFieldLoo11, _classPrivateFieldLoo12, _classPrivateFieldLoo13;
115
+ (_classPrivateFieldLoo10 = (_classPrivateFieldLoo11 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onError) == null ? void 0 : _classPrivateFieldLoo10.call(_classPrivateFieldLoo11, action.error, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
116
+ (_classPrivateFieldLoo12 = (_classPrivateFieldLoo13 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _mutateOptions)[_mutateOptions]).onSettled) == null ? void 0 : _classPrivateFieldLoo12.call(_classPrivateFieldLoo13, undefined, action.error, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].variables, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].context);
87
117
  }
118
+ }
88
119
 
89
- // Then trigger the listeners
90
- this.listeners.forEach(listener => {
91
- listener(this.#currentResult);
92
- });
120
+ // Then trigger the listeners
121
+ this.listeners.forEach(listener => {
122
+ listener(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult]);
93
123
  });
94
- }
124
+ });
95
125
  }
96
126
 
97
127
  exports.MutationObserver = MutationObserver;