@tanstack/query-broadcast-client-experimental 5.94.4 → 5.95.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.
@@ -0,0 +1,40 @@
1
+ import type { BroadcastChannelOptions } from 'broadcast-channel';
2
+ import { Options } from 'tsup';
3
+ import type { QueryClient } from '@tanstack/query-core';
4
+ import { UserConfig } from 'vite';
5
+
6
+ export declare function broadcastQueryClient({ queryClient, broadcastChannel, options, }: BroadcastQueryClientOptions): () => void;
7
+
8
+ declare interface BroadcastQueryClientOptions {
9
+ queryClient: QueryClient;
10
+ broadcastChannel?: string;
11
+ options?: BroadcastChannelOptions;
12
+ }
13
+
14
+ export declare const default_alias: any[];
15
+
16
+ export declare const default_alias_1: any[];
17
+
18
+ export declare const default_alias_2: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
19
+
20
+ export declare const default_alias_3: UserConfig;
21
+
22
+ /**
23
+ * @param {Object} opts - Options for building configurations.
24
+ * @param {string[]} opts.entry - The entry array.
25
+ * @returns {import('tsup').Options}
26
+ */
27
+ export declare function legacyConfig(opts: {
28
+ entry: string[];
29
+ }): Options;
30
+
31
+ /**
32
+ * @param {Object} opts - Options for building configurations.
33
+ * @param {string[]} opts.entry - The entry array.
34
+ * @returns {import('tsup').Options}
35
+ */
36
+ export declare function modernConfig(opts: {
37
+ entry: string[];
38
+ }): Options;
39
+
40
+ export { }
@@ -0,0 +1,40 @@
1
+ import type { BroadcastChannelOptions } from 'broadcast-channel';
2
+ import { Options } from 'tsup';
3
+ import type { QueryClient } from '@tanstack/query-core';
4
+ import { UserConfig } from 'vite';
5
+
6
+ export declare function broadcastQueryClient({ queryClient, broadcastChannel, options, }: BroadcastQueryClientOptions): () => void;
7
+
8
+ declare interface BroadcastQueryClientOptions {
9
+ queryClient: QueryClient;
10
+ broadcastChannel?: string;
11
+ options?: BroadcastChannelOptions;
12
+ }
13
+
14
+ export declare const default_alias: any[];
15
+
16
+ export declare const default_alias_1: any[];
17
+
18
+ export declare const default_alias_2: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
19
+
20
+ export declare const default_alias_3: UserConfig;
21
+
22
+ /**
23
+ * @param {Object} opts - Options for building configurations.
24
+ * @param {string[]} opts.entry - The entry array.
25
+ * @returns {import('tsup').Options}
26
+ */
27
+ export declare function legacyConfig(opts: {
28
+ entry: string[];
29
+ }): Options;
30
+
31
+ /**
32
+ * @param {Object} opts - Options for building configurations.
33
+ * @param {string[]} opts.entry - The entry array.
34
+ * @returns {import('tsup').Options}
35
+ */
36
+ export declare function modernConfig(opts: {
37
+ entry: string[];
38
+ }): Options;
39
+
40
+ export { }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ broadcastQueryClient: () => broadcastQueryClient
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_broadcast_channel = require("broadcast-channel");
27
+ function broadcastQueryClient({
28
+ queryClient,
29
+ broadcastChannel = "tanstack-query",
30
+ options
31
+ }) {
32
+ let transaction = false;
33
+ const tx = (cb) => {
34
+ transaction = true;
35
+ cb();
36
+ transaction = false;
37
+ };
38
+ const channel = new import_broadcast_channel.BroadcastChannel(broadcastChannel, {
39
+ webWorkerSupport: false,
40
+ ...options
41
+ });
42
+ const queryCache = queryClient.getQueryCache();
43
+ const unsubscribe = queryClient.getQueryCache().subscribe((queryEvent) => {
44
+ if (transaction) {
45
+ return;
46
+ }
47
+ const {
48
+ query: { queryHash, queryKey, state, observers }
49
+ } = queryEvent;
50
+ if (queryEvent.type === "updated" && queryEvent.action.type === "success") {
51
+ channel.postMessage({
52
+ type: "updated",
53
+ queryHash,
54
+ queryKey,
55
+ state
56
+ });
57
+ }
58
+ if (queryEvent.type === "removed" && observers.length > 0) {
59
+ channel.postMessage({
60
+ type: "removed",
61
+ queryHash,
62
+ queryKey
63
+ });
64
+ }
65
+ if (queryEvent.type === "added") {
66
+ channel.postMessage({
67
+ type: "added",
68
+ queryHash,
69
+ queryKey
70
+ });
71
+ }
72
+ });
73
+ channel.onmessage = (action) => {
74
+ if (!(action == null ? void 0 : action.type)) {
75
+ return;
76
+ }
77
+ tx(() => {
78
+ const { type, queryHash, queryKey, state } = action;
79
+ const query = queryCache.get(queryHash);
80
+ if (type === "updated") {
81
+ if (query) {
82
+ query.setState(state);
83
+ return;
84
+ }
85
+ queryCache.build(
86
+ queryClient,
87
+ {
88
+ queryKey,
89
+ queryHash
90
+ },
91
+ state
92
+ );
93
+ } else if (type === "removed") {
94
+ if (query) {
95
+ queryCache.remove(query);
96
+ }
97
+ } else if (type === "added") {
98
+ if (query) {
99
+ query.setState(state);
100
+ return;
101
+ }
102
+ queryCache.build(
103
+ queryClient,
104
+ {
105
+ queryKey,
106
+ queryHash
107
+ },
108
+ state
109
+ );
110
+ }
111
+ });
112
+ };
113
+ return () => {
114
+ unsubscribe();
115
+ channel.close();
116
+ };
117
+ }
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ broadcastQueryClient
121
+ });
122
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\n}: BroadcastQueryClientOptions): () => void {\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 ...options,\n })\n\n const queryCache = queryClient.getQueryCache()\n\n const unsubscribe = queryClient.getQueryCache().subscribe((queryEvent) => {\n if (transaction) {\n return\n }\n\n const {\n query: { queryHash, queryKey, state, observers },\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' && observers.length > 0) {\n channel.postMessage({\n type: 'removed',\n queryHash,\n queryKey,\n })\n }\n\n if (queryEvent.type === 'added') {\n channel.postMessage({\n type: 'added',\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 const query = queryCache.get(queryHash)\n\n if (type === 'updated') {\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 if (query) {\n queryCache.remove(query)\n }\n } else if (type === 'added') {\n if (query) {\n query.setState(state)\n return\n }\n queryCache.build(\n queryClient,\n {\n queryKey,\n queryHash,\n },\n state,\n )\n }\n })\n }\n return () => {\n unsubscribe()\n channel.close()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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UACF;AAAA,UACA;AAAA,QACF;AAAA,MACF,WAAW,SAAS,WAAW;AAC7B,YAAI,OAAO;AACT,qBAAW,OAAO,KAAK;AAAA,QACzB;AAAA,MACF,WAAW,SAAS,SAAS;AAC3B,YAAI,OAAO;AACT,gBAAM,SAAS,KAAK;AACpB;AAAA,QACF;AACA,mBAAW;AAAA,UACT;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UACF;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,MAAM;AACX,gBAAY;AACZ,YAAQ,MAAM;AAAA,EAChB;AACF;","names":[]}
@@ -0,0 +1 @@
1
+ export { broadcastQueryClient } from './_tsup-dts-rollup.cjs';
@@ -0,0 +1 @@
1
+ export { broadcastQueryClient } from './_tsup-dts-rollup.js';
@@ -0,0 +1,97 @@
1
+ // src/index.ts
2
+ import { BroadcastChannel } from "broadcast-channel";
3
+ function broadcastQueryClient({
4
+ queryClient,
5
+ broadcastChannel = "tanstack-query",
6
+ options
7
+ }) {
8
+ let transaction = false;
9
+ const tx = (cb) => {
10
+ transaction = true;
11
+ cb();
12
+ transaction = false;
13
+ };
14
+ const channel = new BroadcastChannel(broadcastChannel, {
15
+ webWorkerSupport: false,
16
+ ...options
17
+ });
18
+ const queryCache = queryClient.getQueryCache();
19
+ const unsubscribe = queryClient.getQueryCache().subscribe((queryEvent) => {
20
+ if (transaction) {
21
+ return;
22
+ }
23
+ const {
24
+ query: { queryHash, queryKey, state, observers }
25
+ } = queryEvent;
26
+ if (queryEvent.type === "updated" && queryEvent.action.type === "success") {
27
+ channel.postMessage({
28
+ type: "updated",
29
+ queryHash,
30
+ queryKey,
31
+ state
32
+ });
33
+ }
34
+ if (queryEvent.type === "removed" && observers.length > 0) {
35
+ channel.postMessage({
36
+ type: "removed",
37
+ queryHash,
38
+ queryKey
39
+ });
40
+ }
41
+ if (queryEvent.type === "added") {
42
+ channel.postMessage({
43
+ type: "added",
44
+ queryHash,
45
+ queryKey
46
+ });
47
+ }
48
+ });
49
+ channel.onmessage = (action) => {
50
+ if (!(action == null ? void 0 : action.type)) {
51
+ return;
52
+ }
53
+ tx(() => {
54
+ const { type, queryHash, queryKey, state } = action;
55
+ const query = queryCache.get(queryHash);
56
+ if (type === "updated") {
57
+ if (query) {
58
+ query.setState(state);
59
+ return;
60
+ }
61
+ queryCache.build(
62
+ queryClient,
63
+ {
64
+ queryKey,
65
+ queryHash
66
+ },
67
+ state
68
+ );
69
+ } else if (type === "removed") {
70
+ if (query) {
71
+ queryCache.remove(query);
72
+ }
73
+ } else if (type === "added") {
74
+ if (query) {
75
+ query.setState(state);
76
+ return;
77
+ }
78
+ queryCache.build(
79
+ queryClient,
80
+ {
81
+ queryKey,
82
+ queryHash
83
+ },
84
+ state
85
+ );
86
+ }
87
+ });
88
+ };
89
+ return () => {
90
+ unsubscribe();
91
+ channel.close();
92
+ };
93
+ }
94
+ export {
95
+ broadcastQueryClient
96
+ };
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\n}: BroadcastQueryClientOptions): () => void {\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 ...options,\n })\n\n const queryCache = queryClient.getQueryCache()\n\n const unsubscribe = queryClient.getQueryCache().subscribe((queryEvent) => {\n if (transaction) {\n return\n }\n\n const {\n query: { queryHash, queryKey, state, observers },\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' && observers.length > 0) {\n channel.postMessage({\n type: 'removed',\n queryHash,\n queryKey,\n })\n }\n\n if (queryEvent.type === 'added') {\n channel.postMessage({\n type: 'added',\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 const query = queryCache.get(queryHash)\n\n if (type === 'updated') {\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 if (query) {\n queryCache.remove(query)\n }\n } else if (type === 'added') {\n if (query) {\n query.setState(state)\n return\n }\n queryCache.build(\n queryClient,\n {\n queryKey,\n queryHash,\n },\n state,\n )\n }\n })\n }\n return () => {\n unsubscribe()\n channel.close()\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAU1B,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA,mBAAmB;AAAA,EACnB;AACF,GAA4C;AAC1C,MAAI,cAAc;AAClB,QAAM,KAAK,CAAC,OAAmB;AAC7B,kBAAc;AACd,OAAG;AACH,kBAAc;AAAA,EAChB;AAEA,QAAM,UAAU,IAAI,iBAAiB,kBAAkB;AAAA,IACrD,kBAAkB;AAAA,IAClB,GAAG;AAAA,EACL,CAAC;AAED,QAAM,aAAa,YAAY,cAAc;AAE7C,QAAM,cAAc,YAAY,cAAc,EAAE,UAAU,CAAC,eAAe;AACxE,QAAI,aAAa;AACf;AAAA,IACF;AAEA,UAAM;AAAA,MACJ,OAAO,EAAE,WAAW,UAAU,OAAO,UAAU;AAAA,IACjD,IAAI;AAEJ,QAAI,WAAW,SAAS,aAAa,WAAW,OAAO,SAAS,WAAW;AACzE,cAAQ,YAAY;AAAA,QAClB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,WAAW,SAAS,aAAa,UAAU,SAAS,GAAG;AACzD,cAAQ,YAAY;AAAA,QAClB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,WAAW,SAAS,SAAS;AAC/B,cAAQ,YAAY;AAAA,QAClB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,UAAQ,YAAY,CAAC,WAAW;AAC9B,QAAI,EAAC,iCAAQ,OAAM;AACjB;AAAA,IACF;AAEA,OAAG,MAAM;AACP,YAAM,EAAE,MAAM,WAAW,UAAU,MAAM,IAAI;AAE7C,YAAM,QAAQ,WAAW,IAAI,SAAS;AAEtC,UAAI,SAAS,WAAW;AACtB,YAAI,OAAO;AACT,gBAAM,SAAS,KAAK;AACpB;AAAA,QACF;AAEA,mBAAW;AAAA,UACT;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UACF;AAAA,UACA;AAAA,QACF;AAAA,MACF,WAAW,SAAS,WAAW;AAC7B,YAAI,OAAO;AACT,qBAAW,OAAO,KAAK;AAAA,QACzB;AAAA,MACF,WAAW,SAAS,SAAS;AAC3B,YAAI,OAAO;AACT,gBAAM,SAAS,KAAK;AACpB;AAAA,QACF;AACA,mBAAW;AAAA,UACT;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UACF;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,MAAM;AACX,gBAAY;AACZ,YAAQ,MAAM;AAAA,EAChB;AACF;","names":[]}
@@ -0,0 +1,40 @@
1
+ import type { BroadcastChannelOptions } from 'broadcast-channel';
2
+ import { Options } from 'tsup';
3
+ import type { QueryClient } from '@tanstack/query-core';
4
+ import { UserConfig } from 'vite';
5
+
6
+ export declare function broadcastQueryClient({ queryClient, broadcastChannel, options, }: BroadcastQueryClientOptions): () => void;
7
+
8
+ declare interface BroadcastQueryClientOptions {
9
+ queryClient: QueryClient;
10
+ broadcastChannel?: string;
11
+ options?: BroadcastChannelOptions;
12
+ }
13
+
14
+ export declare const default_alias: any[];
15
+
16
+ export declare const default_alias_1: any[];
17
+
18
+ export declare const default_alias_2: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
19
+
20
+ export declare const default_alias_3: UserConfig;
21
+
22
+ /**
23
+ * @param {Object} opts - Options for building configurations.
24
+ * @param {string[]} opts.entry - The entry array.
25
+ * @returns {import('tsup').Options}
26
+ */
27
+ export declare function legacyConfig(opts: {
28
+ entry: string[];
29
+ }): Options;
30
+
31
+ /**
32
+ * @param {Object} opts - Options for building configurations.
33
+ * @param {string[]} opts.entry - The entry array.
34
+ * @returns {import('tsup').Options}
35
+ */
36
+ export declare function modernConfig(opts: {
37
+ entry: string[];
38
+ }): Options;
39
+
40
+ export { }
@@ -0,0 +1,40 @@
1
+ import type { BroadcastChannelOptions } from 'broadcast-channel';
2
+ import { Options } from 'tsup';
3
+ import type { QueryClient } from '@tanstack/query-core';
4
+ import { UserConfig } from 'vite';
5
+
6
+ export declare function broadcastQueryClient({ queryClient, broadcastChannel, options, }: BroadcastQueryClientOptions): () => void;
7
+
8
+ declare interface BroadcastQueryClientOptions {
9
+ queryClient: QueryClient;
10
+ broadcastChannel?: string;
11
+ options?: BroadcastChannelOptions;
12
+ }
13
+
14
+ export declare const default_alias: any[];
15
+
16
+ export declare const default_alias_1: any[];
17
+
18
+ export declare const default_alias_2: Options | Options[] | ((overrideOptions: Options) => Options | Options[] | Promise<Options | Options[]>);
19
+
20
+ export declare const default_alias_3: UserConfig;
21
+
22
+ /**
23
+ * @param {Object} opts - Options for building configurations.
24
+ * @param {string[]} opts.entry - The entry array.
25
+ * @returns {import('tsup').Options}
26
+ */
27
+ export declare function legacyConfig(opts: {
28
+ entry: string[];
29
+ }): Options;
30
+
31
+ /**
32
+ * @param {Object} opts - Options for building configurations.
33
+ * @param {string[]} opts.entry - The entry array.
34
+ * @returns {import('tsup').Options}
35
+ */
36
+ export declare function modernConfig(opts: {
37
+ entry: string[];
38
+ }): Options;
39
+
40
+ export { }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ broadcastQueryClient: () => broadcastQueryClient
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_broadcast_channel = require("broadcast-channel");
27
+ function broadcastQueryClient({
28
+ queryClient,
29
+ broadcastChannel = "tanstack-query",
30
+ options
31
+ }) {
32
+ let transaction = false;
33
+ const tx = (cb) => {
34
+ transaction = true;
35
+ cb();
36
+ transaction = false;
37
+ };
38
+ const channel = new import_broadcast_channel.BroadcastChannel(broadcastChannel, {
39
+ webWorkerSupport: false,
40
+ ...options
41
+ });
42
+ const queryCache = queryClient.getQueryCache();
43
+ const unsubscribe = queryClient.getQueryCache().subscribe((queryEvent) => {
44
+ if (transaction) {
45
+ return;
46
+ }
47
+ const {
48
+ query: { queryHash, queryKey, state, observers }
49
+ } = queryEvent;
50
+ if (queryEvent.type === "updated" && queryEvent.action.type === "success") {
51
+ channel.postMessage({
52
+ type: "updated",
53
+ queryHash,
54
+ queryKey,
55
+ state
56
+ });
57
+ }
58
+ if (queryEvent.type === "removed" && observers.length > 0) {
59
+ channel.postMessage({
60
+ type: "removed",
61
+ queryHash,
62
+ queryKey
63
+ });
64
+ }
65
+ if (queryEvent.type === "added") {
66
+ channel.postMessage({
67
+ type: "added",
68
+ queryHash,
69
+ queryKey
70
+ });
71
+ }
72
+ });
73
+ channel.onmessage = (action) => {
74
+ if (!action?.type) {
75
+ return;
76
+ }
77
+ tx(() => {
78
+ const { type, queryHash, queryKey, state } = action;
79
+ const query = queryCache.get(queryHash);
80
+ if (type === "updated") {
81
+ if (query) {
82
+ query.setState(state);
83
+ return;
84
+ }
85
+ queryCache.build(
86
+ queryClient,
87
+ {
88
+ queryKey,
89
+ queryHash
90
+ },
91
+ state
92
+ );
93
+ } else if (type === "removed") {
94
+ if (query) {
95
+ queryCache.remove(query);
96
+ }
97
+ } else if (type === "added") {
98
+ if (query) {
99
+ query.setState(state);
100
+ return;
101
+ }
102
+ queryCache.build(
103
+ queryClient,
104
+ {
105
+ queryKey,
106
+ queryHash
107
+ },
108
+ state
109
+ );
110
+ }
111
+ });
112
+ };
113
+ return () => {
114
+ unsubscribe();
115
+ channel.close();
116
+ };
117
+ }
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ broadcastQueryClient
121
+ });
122
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\n}: BroadcastQueryClientOptions): () => void {\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 ...options,\n })\n\n const queryCache = queryClient.getQueryCache()\n\n const unsubscribe = queryClient.getQueryCache().subscribe((queryEvent) => {\n if (transaction) {\n return\n }\n\n const {\n query: { queryHash, queryKey, state, observers },\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' && observers.length > 0) {\n channel.postMessage({\n type: 'removed',\n queryHash,\n queryKey,\n })\n }\n\n if (queryEvent.type === 'added') {\n channel.postMessage({\n type: 'added',\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 const query = queryCache.get(queryHash)\n\n if (type === 'updated') {\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 if (query) {\n queryCache.remove(query)\n }\n } else if (type === 'added') {\n if (query) {\n query.setState(state)\n return\n }\n queryCache.build(\n queryClient,\n {\n queryKey,\n queryHash,\n },\n state,\n )\n }\n })\n }\n return () => {\n unsubscribe()\n channel.close()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAiC;AAU1B,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA,mBAAmB;AAAA,EACnB;AACF,GAA4C;AAC1C,MAAI,cAAc;AAClB,QAAM,KAAK,CAAC,OAAmB;AAC7B,kBAAc;AACd,OAAG;AACH,kBAAc;AAAA,EAChB;AAEA,QAAM,UAAU,IAAI,0CAAiB,kBAAkB;AAAA,IACrD,kBAAkB;AAAA,IAClB,GAAG;AAAA,EACL,CAAC;AAED,QAAM,aAAa,YAAY,cAAc;AAE7C,QAAM,cAAc,YAAY,cAAc,EAAE,UAAU,CAAC,eAAe;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MAAM;AAAA,EAChB;AACF;","names":[]}
@@ -0,0 +1 @@
1
+ export { broadcastQueryClient } from './_tsup-dts-rollup.cjs';
@@ -0,0 +1 @@
1
+ export { broadcastQueryClient } from './_tsup-dts-rollup.js';
@@ -0,0 +1,97 @@
1
+ // src/index.ts
2
+ import { BroadcastChannel } from "broadcast-channel";
3
+ function broadcastQueryClient({
4
+ queryClient,
5
+ broadcastChannel = "tanstack-query",
6
+ options
7
+ }) {
8
+ let transaction = false;
9
+ const tx = (cb) => {
10
+ transaction = true;
11
+ cb();
12
+ transaction = false;
13
+ };
14
+ const channel = new BroadcastChannel(broadcastChannel, {
15
+ webWorkerSupport: false,
16
+ ...options
17
+ });
18
+ const queryCache = queryClient.getQueryCache();
19
+ const unsubscribe = queryClient.getQueryCache().subscribe((queryEvent) => {
20
+ if (transaction) {
21
+ return;
22
+ }
23
+ const {
24
+ query: { queryHash, queryKey, state, observers }
25
+ } = queryEvent;
26
+ if (queryEvent.type === "updated" && queryEvent.action.type === "success") {
27
+ channel.postMessage({
28
+ type: "updated",
29
+ queryHash,
30
+ queryKey,
31
+ state
32
+ });
33
+ }
34
+ if (queryEvent.type === "removed" && observers.length > 0) {
35
+ channel.postMessage({
36
+ type: "removed",
37
+ queryHash,
38
+ queryKey
39
+ });
40
+ }
41
+ if (queryEvent.type === "added") {
42
+ channel.postMessage({
43
+ type: "added",
44
+ queryHash,
45
+ queryKey
46
+ });
47
+ }
48
+ });
49
+ channel.onmessage = (action) => {
50
+ if (!action?.type) {
51
+ return;
52
+ }
53
+ tx(() => {
54
+ const { type, queryHash, queryKey, state } = action;
55
+ const query = queryCache.get(queryHash);
56
+ if (type === "updated") {
57
+ if (query) {
58
+ query.setState(state);
59
+ return;
60
+ }
61
+ queryCache.build(
62
+ queryClient,
63
+ {
64
+ queryKey,
65
+ queryHash
66
+ },
67
+ state
68
+ );
69
+ } else if (type === "removed") {
70
+ if (query) {
71
+ queryCache.remove(query);
72
+ }
73
+ } else if (type === "added") {
74
+ if (query) {
75
+ query.setState(state);
76
+ return;
77
+ }
78
+ queryCache.build(
79
+ queryClient,
80
+ {
81
+ queryKey,
82
+ queryHash
83
+ },
84
+ state
85
+ );
86
+ }
87
+ });
88
+ };
89
+ return () => {
90
+ unsubscribe();
91
+ channel.close();
92
+ };
93
+ }
94
+ export {
95
+ broadcastQueryClient
96
+ };
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { BroadcastChannel } from 'broadcast-channel'\nimport type { BroadcastChannelOptions } from 'broadcast-channel'\nimport type { QueryClient } from '@tanstack/query-core'\n\ninterface BroadcastQueryClientOptions {\n queryClient: QueryClient\n broadcastChannel?: string\n options?: BroadcastChannelOptions\n}\n\nexport function broadcastQueryClient({\n queryClient,\n broadcastChannel = 'tanstack-query',\n options,\n}: BroadcastQueryClientOptions): () => void {\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 ...options,\n })\n\n const queryCache = queryClient.getQueryCache()\n\n const unsubscribe = queryClient.getQueryCache().subscribe((queryEvent) => {\n if (transaction) {\n return\n }\n\n const {\n query: { queryHash, queryKey, state, observers },\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' && observers.length > 0) {\n channel.postMessage({\n type: 'removed',\n queryHash,\n queryKey,\n })\n }\n\n if (queryEvent.type === 'added') {\n channel.postMessage({\n type: 'added',\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 const query = queryCache.get(queryHash)\n\n if (type === 'updated') {\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 if (query) {\n queryCache.remove(query)\n }\n } else if (type === 'added') {\n if (query) {\n query.setState(state)\n return\n }\n queryCache.build(\n queryClient,\n {\n queryKey,\n queryHash,\n },\n state,\n )\n }\n })\n }\n return () => {\n unsubscribe()\n channel.close()\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAU1B,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA,mBAAmB;AAAA,EACnB;AACF,GAA4C;AAC1C,MAAI,cAAc;AAClB,QAAM,KAAK,CAAC,OAAmB;AAC7B,kBAAc;AACd,OAAG;AACH,kBAAc;AAAA,EAChB;AAEA,QAAM,UAAU,IAAI,iBAAiB,kBAAkB;AAAA,IACrD,kBAAkB;AAAA,IAClB,GAAG;AAAA,EACL,CAAC;AAED,QAAM,aAAa,YAAY,cAAc;AAE7C,QAAM,cAAc,YAAY,cAAc,EAAE,UAAU,CAAC,eAAe;AACxE,QAAI,aAAa;AACf;AAAA,IACF;AAEA,UAAM;AAAA,MACJ,OAAO,EAAE,WAAW,UAAU,OAAO,UAAU;AAAA,IACjD,IAAI;AAEJ,QAAI,WAAW,SAAS,aAAa,WAAW,OAAO,SAAS,WAAW;AACzE,cAAQ,YAAY;AAAA,QAClB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,WAAW,SAAS,aAAa,UAAU,SAAS,GAAG;AACzD,cAAQ,YAAY;AAAA,QAClB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,WAAW,SAAS,SAAS;AAC/B,cAAQ,YAAY;AAAA,QAClB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,UAAQ,YAAY,CAAC,WAAW;AAC9B,QAAI,CAAC,QAAQ,MAAM;AACjB;AAAA,IACF;AAEA,OAAG,MAAM;AACP,YAAM,EAAE,MAAM,WAAW,UAAU,MAAM,IAAI;AAE7C,YAAM,QAAQ,WAAW,IAAI,SAAS;AAEtC,UAAI,SAAS,WAAW;AACtB,YAAI,OAAO;AACT,gBAAM,SAAS,KAAK;AACpB;AAAA,QACF;AAEA,mBAAW;AAAA,UACT;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UACF;AAAA,UACA;AAAA,QACF;AAAA,MACF,WAAW,SAAS,WAAW;AAC7B,YAAI,OAAO;AACT,qBAAW,OAAO,KAAK;AAAA,QACzB;AAAA,MACF,WAAW,SAAS,SAAS;AAC3B,YAAI,OAAO;AACT,gBAAM,SAAS,KAAK;AACpB;AAAA,QACF;AACA,mBAAW;AAAA,UACT;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UACF;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,MAAM;AACX,gBAAY;AACZ,YAAQ,MAAM;AAAA,EAChB;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-broadcast-client-experimental",
3
- "version": "5.94.4",
3
+ "version": "5.95.0",
4
4
  "description": "An experimental plugin to for broadcasting the state of your queryClient between browser tabs/windows",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "broadcast-channel": "^7.0.0",
43
- "@tanstack/query-core": "5.94.4"
43
+ "@tanstack/query-core": "5.95.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@testing-library/react": "^16.1.0",