@tanstack/query-broadcast-client-experimental 4.0.10 → 4.0.11-beta.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 (54) hide show
  1. package/build/{types/query-broadcast-client-experimental/src → lib}/index.d.ts +0 -0
  2. package/build/{cjs/packages/query-broadcast-client-experimental/src → lib}/index.js +1 -1
  3. package/build/lib/index.js.map +1 -0
  4. package/build/lib/index.mjs +97 -0
  5. package/build/lib/index.mjs.map +1 -0
  6. package/build/umd/index.development.js +6 -1017
  7. package/build/umd/index.development.js.map +1 -1
  8. package/build/umd/index.production.js +1 -1
  9. package/build/umd/index.production.js.map +1 -1
  10. package/package.json +17 -7
  11. package/build/cjs/node_modules/broadcast-channel/dist/es/broadcast-channel.js +0 -260
  12. package/build/cjs/node_modules/broadcast-channel/dist/es/broadcast-channel.js.map +0 -1
  13. package/build/cjs/node_modules/broadcast-channel/dist/es/method-chooser.js +0 -83
  14. package/build/cjs/node_modules/broadcast-channel/dist/es/method-chooser.js.map +0 -1
  15. package/build/cjs/node_modules/broadcast-channel/dist/es/methods/indexed-db.js +0 -325
  16. package/build/cjs/node_modules/broadcast-channel/dist/es/methods/indexed-db.js.map +0 -1
  17. package/build/cjs/node_modules/broadcast-channel/dist/es/methods/localstorage.js +0 -193
  18. package/build/cjs/node_modules/broadcast-channel/dist/es/methods/localstorage.js.map +0 -1
  19. package/build/cjs/node_modules/broadcast-channel/dist/es/methods/native.js +0 -88
  20. package/build/cjs/node_modules/broadcast-channel/dist/es/methods/native.js.map +0 -1
  21. package/build/cjs/node_modules/broadcast-channel/dist/es/methods/simulate.js +0 -77
  22. package/build/cjs/node_modules/broadcast-channel/dist/es/methods/simulate.js.map +0 -1
  23. package/build/cjs/node_modules/broadcast-channel/dist/es/options.js +0 -41
  24. package/build/cjs/node_modules/broadcast-channel/dist/es/options.js.map +0 -1
  25. package/build/cjs/node_modules/broadcast-channel/dist/es/util.js +0 -77
  26. package/build/cjs/node_modules/broadcast-channel/dist/es/util.js.map +0 -1
  27. package/build/cjs/node_modules/oblivious-set/dist/es/index.js +0 -83
  28. package/build/cjs/node_modules/oblivious-set/dist/es/index.js.map +0 -1
  29. package/build/cjs/packages/query-broadcast-client-experimental/src/index.js.map +0 -1
  30. package/build/esm/index.js +0 -1106
  31. package/build/esm/index.js.map +0 -1
  32. package/build/stats-html.html +0 -2689
  33. package/build/stats.json +0 -427
  34. package/build/types/query-core/src/focusManager.d.ts +0 -16
  35. package/build/types/query-core/src/hydration.d.ts +0 -34
  36. package/build/types/query-core/src/index.d.ts +0 -20
  37. package/build/types/query-core/src/infiniteQueryBehavior.d.ts +0 -15
  38. package/build/types/query-core/src/infiniteQueryObserver.d.ts +0 -18
  39. package/build/types/query-core/src/logger.d.ts +0 -8
  40. package/build/types/query-core/src/mutation.d.ts +0 -70
  41. package/build/types/query-core/src/mutationCache.d.ts +0 -52
  42. package/build/types/query-core/src/mutationObserver.d.ts +0 -23
  43. package/build/types/query-core/src/notifyManager.d.ts +0 -18
  44. package/build/types/query-core/src/onlineManager.d.ts +0 -16
  45. package/build/types/query-core/src/queriesObserver.d.ts +0 -23
  46. package/build/types/query-core/src/query.d.ts +0 -119
  47. package/build/types/query-core/src/queryCache.d.ts +0 -59
  48. package/build/types/query-core/src/queryClient.d.ts +0 -65
  49. package/build/types/query-core/src/queryObserver.d.ts +0 -61
  50. package/build/types/query-core/src/removable.d.ts +0 -9
  51. package/build/types/query-core/src/retryer.d.ts +0 -33
  52. package/build/types/query-core/src/subscribable.d.ts +0 -10
  53. package/build/types/query-core/src/types.d.ts +0 -417
  54. package/build/types/query-core/src/utils.d.ts +0 -99
@@ -12,7 +12,7 @@
12
12
 
13
13
  Object.defineProperty(exports, '__esModule', { value: true });
14
14
 
15
- var broadcastChannel = require('../../../node_modules/broadcast-channel/dist/es/broadcast-channel.js');
15
+ var broadcastChannel = require('broadcast-channel');
16
16
 
17
17
  function broadcastQueryClient({
18
18
  queryClient,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n}: BroadcastQueryClientOptions) {\n let transaction = false\n const tx = (cb: () => void) => {\n transaction = true\n cb()\n transaction = false\n }\n\n const channel = new BroadcastChannel(broadcastChannel, {\n webWorkerSupport: false,\n })\n\n const queryCache = queryClient.getQueryCache()\n\n queryClient.getQueryCache().subscribe((queryEvent) => {\n if (transaction) {\n return\n }\n\n const {\n query: { queryHash, queryKey, state },\n } = queryEvent\n\n if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {\n channel.postMessage({\n type: 'updated',\n queryHash,\n queryKey,\n state,\n })\n }\n\n if (queryEvent.type === 'removed') {\n channel.postMessage({\n type: 'removed',\n queryHash,\n queryKey,\n })\n }\n })\n\n channel.onmessage = (action) => {\n if (!action?.type) {\n return\n }\n\n tx(() => {\n const { type, queryHash, queryKey, state } = action\n\n if (type === 'updated') {\n const query = queryCache.get(queryHash)\n\n if (query) {\n query.setState(state)\n return\n }\n\n queryCache.build(\n queryClient,\n {\n queryKey,\n queryHash,\n },\n state,\n )\n } else if (type === 'removed') {\n const query = queryCache.get(queryHash)\n\n if (query) {\n queryCache.remove(query)\n }\n }\n })\n }\n}\n"],"names":["broadcastQueryClient","queryClient","broadcastChannel","transaction","tx","cb","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove"],"mappings":";;;;;;;;;;;;;;;;AAQO,SAASA,oBAAT,CAA8B;EACnCC,WADmC;AAEnCC,oBAAAA,kBAAgB,GAAG,gBAAA;AAFgB,CAA9B,EAGyB;EAC9B,IAAIC,WAAW,GAAG,KAAlB,CAA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;AACjB,MAAA,OAAA;AACD,KAAA;;AAEDb,IAAAA,EAAE,CAAC,MAAM;MACP,MAAM;QAAEa,IAAF;QAAQH,SAAR;QAAmBC,QAAnB;AAA6BC,QAAAA,KAAAA;AAA7B,OAAA,GAAuCE,MAA7C,CAAA;;MAEA,IAAID,IAAI,KAAK,SAAb,EAAwB;AACtB,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAX,CAAeP,SAAf,CAAd,CAAA;;AAEA,QAAA,IAAID,KAAJ,EAAW;UACTA,KAAK,CAACS,QAAN,CAAeN,KAAf,CAAA,CAAA;AACA,UAAA,OAAA;AACD,SAAA;;AAEDP,QAAAA,UAAU,CAACc,KAAX,CACEtB,WADF,EAEE;UACEc,QADF;AAEED,UAAAA,SAAAA;AAFF,SAFF,EAMEE,KANF,CAAA,CAAA;AAQD,OAhBD,MAgBO,IAAIC,IAAI,KAAK,SAAb,EAAwB;AAC7B,QAAA,MAAMJ,KAAK,GAAGJ,UAAU,CAACY,GAAX,CAAeP,SAAf,CAAd,CAAA;;AAEA,QAAA,IAAID,KAAJ,EAAW;UACTJ,UAAU,CAACe,MAAX,CAAkBX,KAAlB,CAAA,CAAA;AACD,SAAA;AACF,OAAA;AACF,KA1BC,CAAF,CAAA;GALF,CAAA;AAiCD;;;;"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * query-broadcast-client-experimental
3
+ *
4
+ * Copyright (c) TanStack
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import { BroadcastChannel } from 'broadcast-channel';
12
+
13
+ function broadcastQueryClient({
14
+ queryClient,
15
+ broadcastChannel = 'tanstack-query'
16
+ }) {
17
+ let transaction = false;
18
+
19
+ const tx = cb => {
20
+ transaction = true;
21
+ cb();
22
+ transaction = false;
23
+ };
24
+
25
+ const channel = new BroadcastChannel(broadcastChannel, {
26
+ webWorkerSupport: false
27
+ });
28
+ const queryCache = queryClient.getQueryCache();
29
+ queryClient.getQueryCache().subscribe(queryEvent => {
30
+ if (transaction) {
31
+ return;
32
+ }
33
+
34
+ const {
35
+ query: {
36
+ queryHash,
37
+ queryKey,
38
+ state
39
+ }
40
+ } = queryEvent;
41
+
42
+ if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {
43
+ channel.postMessage({
44
+ type: 'updated',
45
+ queryHash,
46
+ queryKey,
47
+ state
48
+ });
49
+ }
50
+
51
+ if (queryEvent.type === 'removed') {
52
+ channel.postMessage({
53
+ type: 'removed',
54
+ queryHash,
55
+ queryKey
56
+ });
57
+ }
58
+ });
59
+
60
+ channel.onmessage = action => {
61
+ if (!(action != null && action.type)) {
62
+ return;
63
+ }
64
+
65
+ tx(() => {
66
+ const {
67
+ type,
68
+ queryHash,
69
+ queryKey,
70
+ state
71
+ } = action;
72
+
73
+ if (type === 'updated') {
74
+ const query = queryCache.get(queryHash);
75
+
76
+ if (query) {
77
+ query.setState(state);
78
+ return;
79
+ }
80
+
81
+ queryCache.build(queryClient, {
82
+ queryKey,
83
+ queryHash
84
+ }, state);
85
+ } else if (type === 'removed') {
86
+ const query = queryCache.get(queryHash);
87
+
88
+ if (query) {
89
+ queryCache.remove(query);
90
+ }
91
+ }
92
+ });
93
+ };
94
+ }
95
+
96
+ export { broadcastQueryClient };
97
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n}: BroadcastQueryClientOptions) {\n let transaction = false\n const tx = (cb: () => void) => {\n transaction = true\n cb()\n transaction = false\n }\n\n const channel = new BroadcastChannel(broadcastChannel, {\n webWorkerSupport: false,\n })\n\n const queryCache = queryClient.getQueryCache()\n\n queryClient.getQueryCache().subscribe((queryEvent) => {\n if (transaction) {\n return\n }\n\n const {\n query: { queryHash, queryKey, state },\n } = queryEvent\n\n if (queryEvent.type === 'updated' && queryEvent.action.type === 'success') {\n channel.postMessage({\n type: 'updated',\n queryHash,\n queryKey,\n state,\n })\n }\n\n if (queryEvent.type === 'removed') {\n channel.postMessage({\n type: 'removed',\n queryHash,\n queryKey,\n })\n }\n })\n\n channel.onmessage = (action) => {\n if (!action?.type) {\n return\n }\n\n tx(() => {\n const { type, queryHash, queryKey, state } = action\n\n if (type === 'updated') {\n const query = queryCache.get(queryHash)\n\n if (query) {\n query.setState(state)\n return\n }\n\n queryCache.build(\n queryClient,\n {\n queryKey,\n queryHash,\n },\n state,\n )\n } else if (type === 'removed') {\n const query = queryCache.get(queryHash)\n\n if (query) {\n queryCache.remove(query)\n }\n }\n })\n }\n}\n"],"names":["broadcastQueryClient","queryClient","broadcastChannel","transaction","tx","cb","channel","BroadcastChannel","webWorkerSupport","queryCache","getQueryCache","subscribe","queryEvent","query","queryHash","queryKey","state","type","action","postMessage","onmessage","get","setState","build","remove"],"mappings":";;;;;;;;;;;;AAQO,SAASA,oBAAT,CAA8B;EACnCC,WADmC;AAEnCC,EAAAA,gBAAgB,GAAG,gBAAA;AAFgB,CAA9B,EAGyB;EAC9B,IAAIC,WAAW,GAAG,KAAlB,CAAA;;EACA,MAAMC,EAAE,GAAIC,EAAD,IAAoB;AAC7BF,IAAAA,WAAW,GAAG,IAAd,CAAA;IACAE,EAAE,EAAA,CAAA;AACFF,IAAAA,WAAW,GAAG,KAAd,CAAA;GAHF,CAAA;;AAMA,EAAA,MAAMG,OAAO,GAAG,IAAIC,gBAAJ,CAAqBL,gBAArB,EAAuC;AACrDM,IAAAA,gBAAgB,EAAE,KAAA;AADmC,GAAvC,CAAhB,CAAA;AAIA,EAAA,MAAMC,UAAU,GAAGR,WAAW,CAACS,aAAZ,EAAnB,CAAA;AAEAT,EAAAA,WAAW,CAACS,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