@tanstack/query-core 4.35.7 → 4.39.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.
Files changed (143) hide show
  1. package/build/lib/queryCache.d.ts +14 -4
  2. package/build/lib/queryClient.d.ts +83 -20
  3. package/build/lib/tests/queryClient.types.test.d.ts +2 -0
  4. package/build/lib/tests/utils.d.ts +1 -0
  5. package/build/lib/types.d.ts +8 -0
  6. package/package.json +2 -9
  7. package/src/mutationObserver.ts +3 -1
  8. package/src/queryCache.ts +37 -6
  9. package/src/queryClient.ts +202 -37
  10. package/src/tests/mutations.test.tsx +8 -0
  11. package/src/tests/queryClient.types.test.tsx +13 -0
  12. package/src/tests/utils.ts +2 -0
  13. package/src/types.ts +20 -0
  14. package/build/lib/focusManager.esm.js +0 -91
  15. package/build/lib/focusManager.esm.js.map +0 -1
  16. package/build/lib/focusManager.js +0 -96
  17. package/build/lib/focusManager.js.map +0 -1
  18. package/build/lib/focusManager.mjs +0 -91
  19. package/build/lib/focusManager.mjs.map +0 -1
  20. package/build/lib/hydration.esm.js +0 -109
  21. package/build/lib/hydration.esm.js.map +0 -1
  22. package/build/lib/hydration.js +0 -116
  23. package/build/lib/hydration.js.map +0 -1
  24. package/build/lib/hydration.mjs +0 -109
  25. package/build/lib/hydration.mjs.map +0 -1
  26. package/build/lib/index.esm.js +0 -15
  27. package/build/lib/index.esm.js.map +0 -1
  28. package/build/lib/index.js +0 -48
  29. package/build/lib/index.js.map +0 -1
  30. package/build/lib/index.mjs +0 -15
  31. package/build/lib/index.mjs.map +0 -1
  32. package/build/lib/infiniteQueryBehavior.esm.js +0 -146
  33. package/build/lib/infiniteQueryBehavior.esm.js.map +0 -1
  34. package/build/lib/infiniteQueryBehavior.js +0 -154
  35. package/build/lib/infiniteQueryBehavior.js.map +0 -1
  36. package/build/lib/infiniteQueryBehavior.mjs +0 -146
  37. package/build/lib/infiniteQueryBehavior.mjs.map +0 -1
  38. package/build/lib/infiniteQueryObserver.esm.js +0 -85
  39. package/build/lib/infiniteQueryObserver.esm.js.map +0 -1
  40. package/build/lib/infiniteQueryObserver.js +0 -89
  41. package/build/lib/infiniteQueryObserver.js.map +0 -1
  42. package/build/lib/infiniteQueryObserver.mjs +0 -85
  43. package/build/lib/infiniteQueryObserver.mjs.map +0 -1
  44. package/build/lib/logger.esm.js +0 -4
  45. package/build/lib/logger.esm.js.map +0 -1
  46. package/build/lib/logger.js +0 -8
  47. package/build/lib/logger.js.map +0 -1
  48. package/build/lib/logger.mjs +0 -4
  49. package/build/lib/logger.mjs.map +0 -1
  50. package/build/lib/logger.native.esm.js +0 -12
  51. package/build/lib/logger.native.esm.js.map +0 -1
  52. package/build/lib/logger.native.js +0 -16
  53. package/build/lib/logger.native.js.map +0 -1
  54. package/build/lib/logger.native.mjs +0 -12
  55. package/build/lib/logger.native.mjs.map +0 -1
  56. package/build/lib/mutation.esm.js +0 -261
  57. package/build/lib/mutation.esm.js.map +0 -1
  58. package/build/lib/mutation.js +0 -266
  59. package/build/lib/mutation.js.map +0 -1
  60. package/build/lib/mutation.mjs +0 -261
  61. package/build/lib/mutation.mjs.map +0 -1
  62. package/build/lib/mutationCache.esm.js +0 -93
  63. package/build/lib/mutationCache.esm.js.map +0 -1
  64. package/build/lib/mutationCache.js +0 -97
  65. package/build/lib/mutationCache.js.map +0 -1
  66. package/build/lib/mutationCache.mjs +0 -93
  67. package/build/lib/mutationCache.mjs.map +0 -1
  68. package/build/lib/mutationObserver.esm.js +0 -132
  69. package/build/lib/mutationObserver.esm.js.map +0 -1
  70. package/build/lib/mutationObserver.js +0 -136
  71. package/build/lib/mutationObserver.js.map +0 -1
  72. package/build/lib/mutationObserver.mjs +0 -132
  73. package/build/lib/mutationObserver.mjs.map +0 -1
  74. package/build/lib/notifyManager.esm.js +0 -99
  75. package/build/lib/notifyManager.esm.js.map +0 -1
  76. package/build/lib/notifyManager.js +0 -104
  77. package/build/lib/notifyManager.js.map +0 -1
  78. package/build/lib/notifyManager.mjs +0 -99
  79. package/build/lib/notifyManager.mjs.map +0 -1
  80. package/build/lib/onlineManager.esm.js +0 -93
  81. package/build/lib/onlineManager.esm.js.map +0 -1
  82. package/build/lib/onlineManager.js +0 -98
  83. package/build/lib/onlineManager.js.map +0 -1
  84. package/build/lib/onlineManager.mjs +0 -93
  85. package/build/lib/onlineManager.mjs.map +0 -1
  86. package/build/lib/queriesObserver.esm.js +0 -168
  87. package/build/lib/queriesObserver.esm.js.map +0 -1
  88. package/build/lib/queriesObserver.js +0 -172
  89. package/build/lib/queriesObserver.js.map +0 -1
  90. package/build/lib/queriesObserver.mjs +0 -168
  91. package/build/lib/queriesObserver.mjs.map +0 -1
  92. package/build/lib/query.esm.js +0 -475
  93. package/build/lib/query.esm.js.map +0 -1
  94. package/build/lib/query.js +0 -479
  95. package/build/lib/query.js.map +0 -1
  96. package/build/lib/query.mjs +0 -475
  97. package/build/lib/query.mjs.map +0 -1
  98. package/build/lib/queryCache.esm.js +0 -127
  99. package/build/lib/queryCache.esm.js.map +0 -1
  100. package/build/lib/queryCache.js +0 -131
  101. package/build/lib/queryCache.js.map +0 -1
  102. package/build/lib/queryCache.mjs +0 -127
  103. package/build/lib/queryCache.mjs.map +0 -1
  104. package/build/lib/queryClient.esm.js +0 -356
  105. package/build/lib/queryClient.esm.js.map +0 -1
  106. package/build/lib/queryClient.js +0 -360
  107. package/build/lib/queryClient.js.map +0 -1
  108. package/build/lib/queryClient.mjs +0 -356
  109. package/build/lib/queryClient.mjs.map +0 -1
  110. package/build/lib/queryObserver.esm.js +0 -580
  111. package/build/lib/queryObserver.esm.js.map +0 -1
  112. package/build/lib/queryObserver.js +0 -584
  113. package/build/lib/queryObserver.js.map +0 -1
  114. package/build/lib/queryObserver.mjs +0 -580
  115. package/build/lib/queryObserver.mjs.map +0 -1
  116. package/build/lib/removable.esm.js +0 -33
  117. package/build/lib/removable.esm.js.map +0 -1
  118. package/build/lib/removable.js +0 -37
  119. package/build/lib/removable.js.map +0 -1
  120. package/build/lib/removable.mjs +0 -33
  121. package/build/lib/removable.mjs.map +0 -1
  122. package/build/lib/retryer.esm.js +0 -167
  123. package/build/lib/retryer.esm.js.map +0 -1
  124. package/build/lib/retryer.js +0 -174
  125. package/build/lib/retryer.js.map +0 -1
  126. package/build/lib/retryer.mjs +0 -167
  127. package/build/lib/retryer.mjs.map +0 -1
  128. package/build/lib/subscribable.esm.js +0 -32
  129. package/build/lib/subscribable.esm.js.map +0 -1
  130. package/build/lib/subscribable.js +0 -36
  131. package/build/lib/subscribable.js.map +0 -1
  132. package/build/lib/subscribable.mjs +0 -32
  133. package/build/lib/subscribable.mjs.map +0 -1
  134. package/build/lib/utils.esm.js +0 -320
  135. package/build/lib/utils.esm.js.map +0 -1
  136. package/build/lib/utils.js +0 -350
  137. package/build/lib/utils.js.map +0 -1
  138. package/build/lib/utils.mjs +0 -320
  139. package/build/lib/utils.mjs.map +0 -1
  140. package/build/umd/index.development.js +0 -3307
  141. package/build/umd/index.development.js.map +0 -1
  142. package/build/umd/index.production.js +0 -2
  143. package/build/umd/index.production.js.map +0 -1
@@ -1,91 +0,0 @@
1
- import { Subscribable } from './subscribable.esm.js';
2
- import { isServer } from './utils.esm.js';
3
-
4
- class FocusManager extends Subscribable {
5
- constructor() {
6
- super();
7
-
8
- this.setup = onFocus => {
9
- // addEventListener does not exist in React Native, but window does
10
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
11
- if (!isServer && window.addEventListener) {
12
- const listener = () => onFocus(); // Listen to visibillitychange and focus
13
-
14
-
15
- window.addEventListener('visibilitychange', listener, false);
16
- window.addEventListener('focus', listener, false);
17
- return () => {
18
- // Be sure to unsubscribe if a new handler is set
19
- window.removeEventListener('visibilitychange', listener);
20
- window.removeEventListener('focus', listener);
21
- };
22
- }
23
-
24
- return;
25
- };
26
- }
27
-
28
- onSubscribe() {
29
- if (!this.cleanup) {
30
- this.setEventListener(this.setup);
31
- }
32
- }
33
-
34
- onUnsubscribe() {
35
- if (!this.hasListeners()) {
36
- var _this$cleanup;
37
-
38
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
39
- this.cleanup = undefined;
40
- }
41
- }
42
-
43
- setEventListener(setup) {
44
- var _this$cleanup2;
45
-
46
- this.setup = setup;
47
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
48
- this.cleanup = setup(focused => {
49
- if (typeof focused === 'boolean') {
50
- this.setFocused(focused);
51
- } else {
52
- this.onFocus();
53
- }
54
- });
55
- }
56
-
57
- setFocused(focused) {
58
- const changed = this.focused !== focused;
59
-
60
- if (changed) {
61
- this.focused = focused;
62
- this.onFocus();
63
- }
64
- }
65
-
66
- onFocus() {
67
- this.listeners.forEach(({
68
- listener
69
- }) => {
70
- listener();
71
- });
72
- }
73
-
74
- isFocused() {
75
- if (typeof this.focused === 'boolean') {
76
- return this.focused;
77
- } // document global can be unavailable in react native
78
-
79
-
80
- if (typeof document === 'undefined') {
81
- return true;
82
- }
83
-
84
- return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
85
- }
86
-
87
- }
88
- const focusManager = new FocusManager();
89
-
90
- export { FocusManager, focusManager };
91
- //# sourceMappingURL=focusManager.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"focusManager.esm.js","sources":["../../src/focusManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\nimport { isServer } from './utils'\n\ntype SetupFn = (\n setFocused: (focused?: boolean) => void,\n) => (() => void) | undefined\n\nexport class FocusManager extends Subscribable {\n private focused?: boolean\n private cleanup?: () => void\n\n private setup: SetupFn\n\n constructor() {\n super()\n this.setup = (onFocus) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isServer && window.addEventListener) {\n const listener = () => onFocus()\n // Listen to visibillitychange and focus\n window.addEventListener('visibilitychange', listener, false)\n window.addEventListener('focus', listener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('visibilitychange', listener)\n window.removeEventListener('focus', listener)\n }\n }\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.cleanup) {\n this.setEventListener(this.setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.cleanup?.()\n this.cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.setup = setup\n this.cleanup?.()\n this.cleanup = setup((focused) => {\n if (typeof focused === 'boolean') {\n this.setFocused(focused)\n } else {\n this.onFocus()\n }\n })\n }\n\n setFocused(focused?: boolean): void {\n const changed = this.focused !== focused\n if (changed) {\n this.focused = focused\n this.onFocus()\n }\n }\n\n onFocus(): void {\n this.listeners.forEach(({ listener }) => {\n listener()\n })\n }\n\n isFocused(): boolean {\n if (typeof this.focused === 'boolean') {\n return this.focused\n }\n\n // document global can be unavailable in react native\n if (typeof document === 'undefined') {\n return true\n }\n\n return [undefined, 'visible', 'prerender'].includes(\n document.visibilityState,\n )\n }\n}\n\nexport const focusManager = new FocusManager()\n"],"names":["FocusManager","Subscribable","constructor","setup","onFocus","isServer","window","addEventListener","listener","removeEventListener","onSubscribe","cleanup","setEventListener","onUnsubscribe","hasListeners","undefined","focused","setFocused","changed","listeners","forEach","isFocused","document","includes","visibilityState","focusManager"],"mappings":";;;AAOO,MAAMA,YAAN,SAA2BC,YAA3B,CAAwC;AAM7CC,EAAAA,WAAW,GAAG;AACZ,IAAA,KAAA,EAAA,CAAA;;IACA,IAAKC,CAAAA,KAAL,GAAcC,OAAD,IAAa;AACxB;AACA;AACA,MAAA,IAAI,CAACC,QAAD,IAAaC,MAAM,CAACC,gBAAxB,EAA0C;AACxC,QAAA,MAAMC,QAAQ,GAAG,MAAMJ,OAAO,EAA9B,CADwC;;;AAGxCE,QAAAA,MAAM,CAACC,gBAAP,CAAwB,kBAAxB,EAA4CC,QAA5C,EAAsD,KAAtD,CAAA,CAAA;AACAF,QAAAA,MAAM,CAACC,gBAAP,CAAwB,OAAxB,EAAiCC,QAAjC,EAA2C,K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CAAA;AAOD,GAAA;;EAEDa,UAAU,CAACD,OAAD,EAA0B;AAClC,IAAA,MAAME,OAAO,GAAG,IAAKF,CAAAA,OAAL,KAAiBA,OAAjC,CAAA;;AACA,IAAA,IAAIE,OAAJ,EAAa;MACX,IAAKF,CAAAA,OAAL,GAAeA,OAAf,CAAA;AACA,MAAA,IAAA,CAAKZ,OAAL,EAAA,CAAA;AACD,KAAA;AACF,GAAA;;AAEDA,EAAAA,OAAO,GAAS;AACd,IAAA,IAAA,CAAKe,SAAL,CAAeC,OAAf,CAAuB,CAAC;AAAEZ,MAAAA,QAAAA;AAAF,KAAD,KAAkB;MACvCA,QAAQ,EAAA,CAAA;KADV,CAAA,CAAA;AAGD,GAAA;;AAEDa,EAAAA,SAAS,GAAY;AACnB,IAAA,IAAI,OAAO,IAAA,CAAKL,OAAZ,KAAwB,SAA5B,EAAuC;AACrC,MAAA,OAAO,KAAKA,OAAZ,CAAA;AACD,KAHkB;;;AAMnB,IAAA,IAAI,OAAOM,QAAP,KAAoB,WAAxB,EAAqC;AACnC,MAAA,OAAO,IAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAO,CAACP,SAAD,EAAY,SAAZ,EAAuB,WAAvB,CAAoCQ,CAAAA,QAApC,CACLD,QAAQ,CAACE,eADJ,CAAP,CAAA;AAGD,GAAA;;AA/E4C,CAAA;AAkFlCC,MAAAA,YAAY,GAAG,IAAIzB,YAAJ;;;;"}
@@ -1,96 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var subscribable = require('./subscribable.js');
6
- var utils = require('./utils.js');
7
-
8
- class FocusManager extends subscribable.Subscribable {
9
- constructor() {
10
- super();
11
-
12
- this.setup = onFocus => {
13
- // addEventListener does not exist in React Native, but window does
14
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
15
- if (!utils.isServer && window.addEventListener) {
16
- const listener = () => onFocus(); // Listen to visibillitychange and focus
17
-
18
-
19
- window.addEventListener('visibilitychange', listener, false);
20
- window.addEventListener('focus', listener, false);
21
- return () => {
22
- // Be sure to unsubscribe if a new handler is set
23
- window.removeEventListener('visibilitychange', listener);
24
- window.removeEventListener('focus', listener);
25
- };
26
- }
27
-
28
- return;
29
- };
30
- }
31
-
32
- onSubscribe() {
33
- if (!this.cleanup) {
34
- this.setEventListener(this.setup);
35
- }
36
- }
37
-
38
- onUnsubscribe() {
39
- if (!this.hasListeners()) {
40
- var _this$cleanup;
41
-
42
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
43
- this.cleanup = undefined;
44
- }
45
- }
46
-
47
- setEventListener(setup) {
48
- var _this$cleanup2;
49
-
50
- this.setup = setup;
51
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
52
- this.cleanup = setup(focused => {
53
- if (typeof focused === 'boolean') {
54
- this.setFocused(focused);
55
- } else {
56
- this.onFocus();
57
- }
58
- });
59
- }
60
-
61
- setFocused(focused) {
62
- const changed = this.focused !== focused;
63
-
64
- if (changed) {
65
- this.focused = focused;
66
- this.onFocus();
67
- }
68
- }
69
-
70
- onFocus() {
71
- this.listeners.forEach(({
72
- listener
73
- }) => {
74
- listener();
75
- });
76
- }
77
-
78
- isFocused() {
79
- if (typeof this.focused === 'boolean') {
80
- return this.focused;
81
- } // document global can be unavailable in react native
82
-
83
-
84
- if (typeof document === 'undefined') {
85
- return true;
86
- }
87
-
88
- return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
89
- }
90
-
91
- }
92
- const focusManager = new FocusManager();
93
-
94
- exports.FocusManager = FocusManager;
95
- exports.focusManager = focusManager;
96
- //# sourceMappingURL=focusManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"focusManager.js","sources":["../../src/focusManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\nimport { isServer } from './utils'\n\ntype SetupFn = (\n setFocused: (focused?: boolean) => void,\n) => (() => void) | undefined\n\nexport class FocusManager extends Subscribable {\n private focused?: boolean\n private cleanup?: () => void\n\n private setup: SetupFn\n\n constructor() {\n super()\n this.setup = (onFocus) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isServer && window.addEventListener) {\n const listener = () => onFocus()\n // Listen to visibillitychange and focus\n window.addEventListener('visibilitychange', listener, false)\n window.addEventListener('focus', listener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('visibilitychange', listener)\n window.removeEventListener('focus', listener)\n }\n }\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.cleanup) {\n this.setEventListener(this.setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.cleanup?.()\n this.cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.setup = setup\n this.cleanup?.()\n this.cleanup = setup((focused) => {\n if (typeof focused === 'boolean') {\n this.setFocused(focused)\n } else {\n this.onFocus()\n }\n })\n }\n\n setFocused(focused?: boolean): void {\n const changed = this.focused !== focused\n if (changed) {\n this.focused = focused\n this.onFocus()\n }\n }\n\n onFocus(): void {\n this.listeners.forEach(({ listener }) => {\n listener()\n })\n }\n\n isFocused(): boolean {\n if (typeof this.focused === 'boolean') {\n return this.focused\n }\n\n // document global can be unavailable in react native\n if (typeof document === 'undefined') {\n return true\n }\n\n return [undefined, 'visible', 'prerender'].includes(\n document.visibilityState,\n )\n }\n}\n\nexport const focusManager = new FocusManager()\n"],"names":["FocusManager","Subscribable","constructor","setup","onFocus","isServer","window","addEventListener","listener","removeEventListener","onSubscribe","cleanup","setEventListener","onUnsubscribe","hasListeners","undefined","focused","setFocused","changed","listeners","forEach","isFocused","document","includes","visibilityState","focusManager"],"mappings":";;;;;;;AAOO,MAAMA,YAAN,SAA2BC,yBAA3B,CAAwC;AAM7CC,EAAAA,WAAW,GAAG;AACZ,IAAA,KAAA,EAAA,CAAA;;IACA,IAAKC,CAAAA,KAAL,GAAcC,OAAD,IAAa;AACxB;AACA;AACA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from './utils.mjs';
3
-
4
- class FocusManager extends Subscribable {
5
- constructor() {
6
- super();
7
-
8
- this.setup = onFocus => {
9
- // addEventListener does not exist in React Native, but window does
10
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
11
- if (!isServer && window.addEventListener) {
12
- const listener = () => onFocus(); // Listen to visibillitychange and focus
13
-
14
-
15
- window.addEventListener('visibilitychange', listener, false);
16
- window.addEventListener('focus', listener, false);
17
- return () => {
18
- // Be sure to unsubscribe if a new handler is set
19
- window.removeEventListener('visibilitychange', listener);
20
- window.removeEventListener('focus', listener);
21
- };
22
- }
23
-
24
- return;
25
- };
26
- }
27
-
28
- onSubscribe() {
29
- if (!this.cleanup) {
30
- this.setEventListener(this.setup);
31
- }
32
- }
33
-
34
- onUnsubscribe() {
35
- if (!this.hasListeners()) {
36
- var _this$cleanup;
37
-
38
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
39
- this.cleanup = undefined;
40
- }
41
- }
42
-
43
- setEventListener(setup) {
44
- var _this$cleanup2;
45
-
46
- this.setup = setup;
47
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
48
- this.cleanup = setup(focused => {
49
- if (typeof focused === 'boolean') {
50
- this.setFocused(focused);
51
- } else {
52
- this.onFocus();
53
- }
54
- });
55
- }
56
-
57
- setFocused(focused) {
58
- const changed = this.focused !== focused;
59
-
60
- if (changed) {
61
- this.focused = focused;
62
- this.onFocus();
63
- }
64
- }
65
-
66
- onFocus() {
67
- this.listeners.forEach(({
68
- listener
69
- }) => {
70
- listener();
71
- });
72
- }
73
-
74
- isFocused() {
75
- if (typeof this.focused === 'boolean') {
76
- return this.focused;
77
- } // document global can be unavailable in react native
78
-
79
-
80
- if (typeof document === 'undefined') {
81
- return true;
82
- }
83
-
84
- return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
85
- }
86
-
87
- }
88
- const focusManager = new FocusManager();
89
-
90
- export { FocusManager, focusManager };
91
- //# sourceMappingURL=focusManager.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"focusManager.mjs","sources":["../../src/focusManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\nimport { isServer } from './utils'\n\ntype SetupFn = (\n setFocused: (focused?: boolean) => void,\n) => (() => void) | undefined\n\nexport class FocusManager extends Subscribable {\n private focused?: boolean\n private cleanup?: () => void\n\n private setup: SetupFn\n\n constructor() {\n super()\n this.setup = (onFocus) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isServer && window.addEventListener) {\n const listener = () => onFocus()\n // Listen to visibillitychange and focus\n window.addEventListener('visibilitychange', listener, false)\n window.addEventListener('focus', listener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('visibilitychange', listener)\n window.removeEventListener('focus', listener)\n }\n }\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.cleanup) {\n this.setEventListener(this.setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.cleanup?.()\n this.cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.setup = setup\n this.cleanup?.()\n this.cleanup = setup((focused) => {\n if (typeof focused === 'boolean') {\n this.setFocused(focused)\n } else {\n this.onFocus()\n }\n })\n }\n\n setFocused(focused?: boolean): void {\n const changed = this.focused !== focused\n if (changed) {\n this.focused = focused\n this.onFocus()\n }\n }\n\n onFocus(): void {\n this.listeners.forEach(({ listener }) => {\n listener()\n })\n }\n\n isFocused(): boolean {\n if (typeof this.focused === 'boolean') {\n return this.focused\n }\n\n // document global can be unavailable in react native\n if (typeof document === 'undefined') {\n return true\n }\n\n return [undefined, 'visible', 'prerender'].includes(\n document.visibilityState,\n )\n }\n}\n\nexport const focusManager = new FocusManager()\n"],"names":["FocusManager","Subscribable","constructor","setup","onFocus","isServer","window","addEventListener","listener","removeEventListener","onSubscribe","cleanup","setEventListener","onUnsubscribe","hasListeners","undefined","focused","setFocused","changed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,WAAvB,CAAoCQ,CAAAA,QAApC,CACLD,QAAQ,CAACE,eADJ,CAAP,CAAA;AAGD,GAAA;;AA/E4C,CAAA;AAkFlCC,MAAAA,YAAY,GAAG,IAAIzB,YAAJ;;;;"}
@@ -1,109 +0,0 @@
1
- // TYPES
2
- // FUNCTIONS
3
- function dehydrateMutation(mutation) {
4
- return {
5
- mutationKey: mutation.options.mutationKey,
6
- state: mutation.state
7
- };
8
- } // Most config is not dehydrated but instead meant to configure again when
9
- // consuming the de/rehydrated data, typically with useQuery on the client.
10
- // Sometimes it might make sense to prefetch data on the server and include
11
- // in the html-payload, but not consume it on the initial render.
12
-
13
-
14
- function dehydrateQuery(query) {
15
- return {
16
- state: query.state,
17
- queryKey: query.queryKey,
18
- queryHash: query.queryHash
19
- };
20
- }
21
-
22
- function defaultShouldDehydrateMutation(mutation) {
23
- return mutation.state.isPaused;
24
- }
25
- function defaultShouldDehydrateQuery(query) {
26
- return query.state.status === 'success';
27
- }
28
- function dehydrate(client, options = {}) {
29
- const mutations = [];
30
- const queries = [];
31
-
32
- if (options.dehydrateMutations !== false) {
33
- const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
34
- client.getMutationCache().getAll().forEach(mutation => {
35
- if (shouldDehydrateMutation(mutation)) {
36
- mutations.push(dehydrateMutation(mutation));
37
- }
38
- });
39
- }
40
-
41
- if (options.dehydrateQueries !== false) {
42
- const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
43
- client.getQueryCache().getAll().forEach(query => {
44
- if (shouldDehydrateQuery(query)) {
45
- queries.push(dehydrateQuery(query));
46
- }
47
- });
48
- }
49
-
50
- return {
51
- mutations,
52
- queries
53
- };
54
- }
55
- function hydrate(client, dehydratedState, options) {
56
- if (typeof dehydratedState !== 'object' || dehydratedState === null) {
57
- return;
58
- }
59
-
60
- const mutationCache = client.getMutationCache();
61
- const queryCache = client.getQueryCache(); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
62
-
63
- const mutations = dehydratedState.mutations || []; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
64
-
65
- const queries = dehydratedState.queries || [];
66
- mutations.forEach(dehydratedMutation => {
67
- var _options$defaultOptio;
68
-
69
- mutationCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio = options.defaultOptions) == null ? void 0 : _options$defaultOptio.mutations),
70
- mutationKey: dehydratedMutation.mutationKey
71
- }, dehydratedMutation.state);
72
- });
73
- queries.forEach(({
74
- queryKey,
75
- state,
76
- queryHash
77
- }) => {
78
- var _options$defaultOptio2;
79
-
80
- const query = queryCache.get(queryHash); // Do not hydrate if an existing query exists with newer data
81
-
82
- if (query) {
83
- if (query.state.dataUpdatedAt < state.dataUpdatedAt) {
84
- // omit fetchStatus from dehydrated state
85
- // so that query stays in its current fetchStatus
86
- const {
87
- fetchStatus: _ignored,
88
- ...dehydratedQueryState
89
- } = state;
90
- query.setState(dehydratedQueryState);
91
- }
92
-
93
- return;
94
- } // Restore query
95
-
96
-
97
- queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
98
- queryKey,
99
- queryHash
100
- }, // Reset fetch status to idle to avoid
101
- // query being stuck in fetching state upon hydration
102
- { ...state,
103
- fetchStatus: 'idle'
104
- });
105
- });
106
- }
107
-
108
- export { defaultShouldDehydrateMutation, defaultShouldDehydrateQuery, dehydrate, hydrate };
109
- //# sourceMappingURL=hydration.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hydration.esm.js","sources":["../../src/hydration.ts"],"sourcesContent":["import type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type {\n MutationKey,\n MutationOptions,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\n\nexport interface DehydrateOptions {\n dehydrateMutations?: boolean\n dehydrateQueries?: boolean\n shouldDehydrateMutation?: ShouldDehydrateMutationFunction\n shouldDehydrateQuery?: ShouldDehydrateQueryFunction\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n queries?: QueryOptions\n mutations?: MutationOptions\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport interface DehydratedState {\n mutations: DehydratedMutation[]\n queries: DehydratedQuery[]\n}\n\nexport type ShouldDehydrateQueryFunction = (query: Query) => boolean\n\nexport type ShouldDehydrateMutationFunction = (mutation: Mutation) => boolean\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query: Query): DehydratedQuery {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const mutations: DehydratedMutation[] = []\n const queries: DehydratedQuery[] = []\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation =\n options.shouldDehydrateMutation || defaultShouldDehydrateMutation\n\n client\n .getMutationCache()\n .getAll()\n .forEach((mutation) => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation))\n }\n })\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery =\n options.shouldDehydrateQuery || defaultShouldDehydrateQuery\n\n client\n .getQueryCache()\n .getAll()\n .forEach((query) => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query))\n }\n })\n }\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach((dehydratedMutation) => {\n mutationCache.build(\n client,\n {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey,\n },\n dehydratedMutation.state,\n )\n })\n\n queries.forEach(({ queryKey, state, queryHash }) => {\n const query = queryCache.get(queryHash)\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < state.dataUpdatedAt) {\n // omit fetchStatus from dehydrated state\n // so that query stays in its current fetchStatus\n const { fetchStatus: _ignored, ...dehydratedQueryState } = state\n query.setState(dehydratedQueryState)\n }\n return\n }\n\n // Restore query\n queryCache.build(\n client,\n {\n ...options?.defaultOptions?.queries,\n queryKey,\n queryHash,\n },\n // Reset fetch status to idle to avoid\n // query being stuck in fetching state upon hydration\n {\n ...state,\n fetchStatus: 'idle',\n },\n )\n })\n}\n"],"names":["dehydrateMutation","mutation","mutationKey","options","state","dehydrateQuery","query","queryKey","queryHash","defaultShouldDehydrateMutation","isPaused","defaultShouldDehydrateQuery","status","dehydrate","client","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","dehydrateQueries","shouldDehydrateQuery","getQueryCache","hydrate","dehydratedState","mutationCache","queryCache","dehydratedMutation","build","defaultOptions","get","dataUpdatedAt","fetchStatus","_ignored","dehydratedQueryState","setState"],"mappings":"AAUA;AAoCA;AAEA,SAASA,iBAAT,CAA2BC,QAA3B,EAAmE;EACjE,OAAO;AACLC,IAAAA,WAAW,EA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AAA;AAAnB,GAAD,KAAoC;AAAA,IAAA,IAAA,sBAAA,CAAA;;IAClD,MAAMF,KAAK,GAAGuB,UAAU,CAACI,GAAX,CAAezB,SAAf,CAAd,CADkD;;AAIlD,IAAA,IAAIF,KAAJ,EAAW;MACT,IAAIA,KAAK,CAACF,KAAN,CAAY8B,aAAZ,GAA4B9B,KAAK,CAAC8B,aAAtC,EAAqD;AACnD;AACA;QACA,MAAM;AAAEC,UAAAA,WAAW,EAAEC,QAAf;UAAyB,GAAGC,oBAAAA;AAA5B,SAAA,GAAqDjC,KAA3D,CAAA;QACAE,KAAK,CAACgC,QAAN,CAAeD,oBAAf,CAAA,CAAA;AACD,OAAA;;AACD,MAAA,OAAA;AACD,KAZiD;;;AAelDR,IAAAA,UAAU,CAACE,KAAX,CACEjB,MADF,EAEE,EACE,IAAGX,OAAH,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,CAAA,sBAAA,GAAGA,OAAO,CAAE6B,cAAZ,KAAG,IAAA,GAAA,KAAA,CAAA,GAAA,sBAAA,CAAyBhB,OAA5B,CADF;MAEET,QAFF;AAGEC,MAAAA,SAAAA;AAHF,KAFF;AAQE;AACA,IAAA,EACE,GAAGJ,KADL;AAEE+B,MAAAA,WAAW,EAAE,MAAA;KAXjB,CAAA,CAAA;GAfF,CAAA,CAAA;AA8BD;;;;"}
@@ -1,116 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- // TYPES
6
- // FUNCTIONS
7
- function dehydrateMutation(mutation) {
8
- return {
9
- mutationKey: mutation.options.mutationKey,
10
- state: mutation.state
11
- };
12
- } // Most config is not dehydrated but instead meant to configure again when
13
- // consuming the de/rehydrated data, typically with useQuery on the client.
14
- // Sometimes it might make sense to prefetch data on the server and include
15
- // in the html-payload, but not consume it on the initial render.
16
-
17
-
18
- function dehydrateQuery(query) {
19
- return {
20
- state: query.state,
21
- queryKey: query.queryKey,
22
- queryHash: query.queryHash
23
- };
24
- }
25
-
26
- function defaultShouldDehydrateMutation(mutation) {
27
- return mutation.state.isPaused;
28
- }
29
- function defaultShouldDehydrateQuery(query) {
30
- return query.state.status === 'success';
31
- }
32
- function dehydrate(client, options = {}) {
33
- const mutations = [];
34
- const queries = [];
35
-
36
- if (options.dehydrateMutations !== false) {
37
- const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
38
- client.getMutationCache().getAll().forEach(mutation => {
39
- if (shouldDehydrateMutation(mutation)) {
40
- mutations.push(dehydrateMutation(mutation));
41
- }
42
- });
43
- }
44
-
45
- if (options.dehydrateQueries !== false) {
46
- const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
47
- client.getQueryCache().getAll().forEach(query => {
48
- if (shouldDehydrateQuery(query)) {
49
- queries.push(dehydrateQuery(query));
50
- }
51
- });
52
- }
53
-
54
- return {
55
- mutations,
56
- queries
57
- };
58
- }
59
- function hydrate(client, dehydratedState, options) {
60
- if (typeof dehydratedState !== 'object' || dehydratedState === null) {
61
- return;
62
- }
63
-
64
- const mutationCache = client.getMutationCache();
65
- const queryCache = client.getQueryCache(); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
66
-
67
- const mutations = dehydratedState.mutations || []; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
68
-
69
- const queries = dehydratedState.queries || [];
70
- mutations.forEach(dehydratedMutation => {
71
- var _options$defaultOptio;
72
-
73
- mutationCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio = options.defaultOptions) == null ? void 0 : _options$defaultOptio.mutations),
74
- mutationKey: dehydratedMutation.mutationKey
75
- }, dehydratedMutation.state);
76
- });
77
- queries.forEach(({
78
- queryKey,
79
- state,
80
- queryHash
81
- }) => {
82
- var _options$defaultOptio2;
83
-
84
- const query = queryCache.get(queryHash); // Do not hydrate if an existing query exists with newer data
85
-
86
- if (query) {
87
- if (query.state.dataUpdatedAt < state.dataUpdatedAt) {
88
- // omit fetchStatus from dehydrated state
89
- // so that query stays in its current fetchStatus
90
- const {
91
- fetchStatus: _ignored,
92
- ...dehydratedQueryState
93
- } = state;
94
- query.setState(dehydratedQueryState);
95
- }
96
-
97
- return;
98
- } // Restore query
99
-
100
-
101
- queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
102
- queryKey,
103
- queryHash
104
- }, // Reset fetch status to idle to avoid
105
- // query being stuck in fetching state upon hydration
106
- { ...state,
107
- fetchStatus: 'idle'
108
- });
109
- });
110
- }
111
-
112
- exports.defaultShouldDehydrateMutation = defaultShouldDehydrateMutation;
113
- exports.defaultShouldDehydrateQuery = defaultShouldDehydrateQuery;
114
- exports.dehydrate = dehydrate;
115
- exports.hydrate = hydrate;
116
- //# sourceMappingURL=hydration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hydration.js","sources":["../../src/hydration.ts"],"sourcesContent":["import type { QueryClient } from './queryClient'\nimport type { Query, QueryState } from './query'\nimport type {\n MutationKey,\n MutationOptions,\n QueryKey,\n QueryOptions,\n} from './types'\nimport type { Mutation, MutationState } from './mutation'\n\n// TYPES\n\nexport interface DehydrateOptions {\n dehydrateMutations?: boolean\n dehydrateQueries?: boolean\n shouldDehydrateMutation?: ShouldDehydrateMutationFunction\n shouldDehydrateQuery?: ShouldDehydrateQueryFunction\n}\n\nexport interface HydrateOptions {\n defaultOptions?: {\n queries?: QueryOptions\n mutations?: MutationOptions\n }\n}\n\ninterface DehydratedMutation {\n mutationKey?: MutationKey\n state: MutationState\n}\n\ninterface DehydratedQuery {\n queryHash: string\n queryKey: QueryKey\n state: QueryState\n}\n\nexport interface DehydratedState {\n mutations: DehydratedMutation[]\n queries: DehydratedQuery[]\n}\n\nexport type ShouldDehydrateQueryFunction = (query: Query) => boolean\n\nexport type ShouldDehydrateMutationFunction = (mutation: Mutation) => boolean\n\n// FUNCTIONS\n\nfunction dehydrateMutation(mutation: Mutation): DehydratedMutation {\n return {\n mutationKey: mutation.options.mutationKey,\n state: mutation.state,\n }\n}\n\n// Most config is not dehydrated but instead meant to configure again when\n// consuming the de/rehydrated data, typically with useQuery on the client.\n// Sometimes it might make sense to prefetch data on the server and include\n// in the html-payload, but not consume it on the initial render.\nfunction dehydrateQuery(query: Query): DehydratedQuery {\n return {\n state: query.state,\n queryKey: query.queryKey,\n queryHash: query.queryHash,\n }\n}\n\nexport function defaultShouldDehydrateMutation(mutation: Mutation) {\n return mutation.state.isPaused\n}\n\nexport function defaultShouldDehydrateQuery(query: Query) {\n return query.state.status === 'success'\n}\n\nexport function dehydrate(\n client: QueryClient,\n options: DehydrateOptions = {},\n): DehydratedState {\n const mutations: DehydratedMutation[] = []\n const queries: DehydratedQuery[] = []\n\n if (options.dehydrateMutations !== false) {\n const shouldDehydrateMutation =\n options.shouldDehydrateMutation || defaultShouldDehydrateMutation\n\n client\n .getMutationCache()\n .getAll()\n .forEach((mutation) => {\n if (shouldDehydrateMutation(mutation)) {\n mutations.push(dehydrateMutation(mutation))\n }\n })\n }\n\n if (options.dehydrateQueries !== false) {\n const shouldDehydrateQuery =\n options.shouldDehydrateQuery || defaultShouldDehydrateQuery\n\n client\n .getQueryCache()\n .getAll()\n .forEach((query) => {\n if (shouldDehydrateQuery(query)) {\n queries.push(dehydrateQuery(query))\n }\n })\n }\n\n return { mutations, queries }\n}\n\nexport function hydrate(\n client: QueryClient,\n dehydratedState: unknown,\n options?: HydrateOptions,\n): void {\n if (typeof dehydratedState !== 'object' || dehydratedState === null) {\n return\n }\n\n const mutationCache = client.getMutationCache()\n const queryCache = client.getQueryCache()\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const mutations = (dehydratedState as DehydratedState).mutations || []\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const queries = (dehydratedState as DehydratedState).queries || []\n\n mutations.forEach((dehydratedMutation) => {\n mutationCache.build(\n client,\n {\n ...options?.defaultOptions?.mutations,\n mutationKey: dehydratedMutation.mutationKey,\n },\n dehydratedMutation.state,\n )\n })\n\n queries.forEach(({ queryKey, state, queryHash }) => {\n const query = queryCache.get(queryHash)\n\n // Do not hydrate if an existing query exists with newer data\n if (query) {\n if (query.state.dataUpdatedAt < state.dataUpdatedAt) {\n // omit fetchStatus from dehydrated state\n // so that query stays in its current fetchStatus\n const { fetchStatus: _ignored, ...dehydratedQueryState } = state\n query.setState(dehydratedQueryState)\n }\n return\n }\n\n // Restore query\n queryCache.build(\n client,\n {\n ...options?.defaultOptions?.queries,\n queryKey,\n queryHash,\n },\n // Reset fetch status to idle to avoid\n // query being stuck in fetching state upon hydration\n {\n ...state,\n fetchStatus: 'idle',\n },\n )\n })\n}\n"],"names":["dehydrateMutation","mutation","mutationKey","options","state","dehydrateQuery","query","queryKey","queryHash","defaultShouldDehydrateMutation","isPaused","defaultShouldDehydrateQuery","status","dehydrate","client","mutations","queries","dehydrateMutations","shouldDehydrateMutation","getMutationCache","getAll","forEach","push","dehydrateQueries","shouldDehydrateQuery","getQueryCache","hydrate","dehydratedState","mutationCache","queryCache","dehydratedMutation","build","defaultOptions","get","dataUpdatedAt","fetchStatus","_ignored","dehydratedQueryState","setState"],"mappings":";;;;AAUA;AAoCA;AAEA,SAASA,iBAAT,CAA2BC,QAA3B,EAAmE;EACjE,OAAO;AACLC,IAAAA,WAAW,EAAED,QAAQ,CAACE,OAAT,CAAiBD,WADzB;IAELE,KAAK,EAAEH,QAAQ,CAACG,KAAAA;GAFlB,CAAA;AAID;AAGD;AACA;AACA;;;AACA,SAASC,cAAT,CAAwBC,KAAxB,EAAuD;EACrD,OAAO;IACLF,KAAK,EAAEE,KAAK,CAACF,KADR;IAELG,QAAQ,EAAED,KAAK,CAACC,QAFX;IAGLC,SAAS,EAAEF,KAAK,CAACE,SAAAA;GAHnB,CAAA;AAKD,CAAA;;AAEM,SAASC,8BAAT,CAAwCR,QAAxC,EAA4D;AACjE,EAAA,OAAOA,QAAQ,CAACG,KAAT,CAAeM,QAAtB,CAAA;AACD,CAAA;AA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