@vue-solana/vue 2.0.0 → 2.2.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 (186) hide show
  1. package/README.md +210 -21
  2. package/dist/index.cjs +60 -20
  3. package/dist/index.d.cts +26 -5
  4. package/dist/index.d.mts +26 -5
  5. package/dist/index.d.ts +26 -5
  6. package/dist/index.mjs +38 -19
  7. package/dist/shared/vue.5euWd6-V.mjs +59 -0
  8. package/dist/shared/vue.9TPxZPMf.cjs +59 -0
  9. package/dist/shared/vue.B4-LEdSE.cjs +102 -0
  10. package/dist/shared/{vue.CP1DPDX9.cjs → vue.B6ainw2G.cjs} +1 -1
  11. package/dist/shared/vue.B8LptjZP.mjs +32 -0
  12. package/dist/shared/vue.B8VvC8d2.mjs +101 -0
  13. package/dist/shared/{vue.DP7qY8Rk.mjs → vue.BD6Gm1nl.mjs} +2 -2
  14. package/dist/shared/vue.BDNOyiGZ.mjs +109 -0
  15. package/dist/shared/{vue.BAlo-tIh.cjs → vue.BGxz4dru.cjs} +5 -1
  16. package/dist/shared/{vue.stUBDBI9.mjs → vue.BINkrA8h.mjs} +2 -2
  17. package/dist/shared/{vue.k9Q6aN-0.cjs → vue.BIxphCAq.cjs} +1 -1
  18. package/dist/shared/{vue.yQcL1yMv.mjs → vue.BOpgWr43.mjs} +2 -2
  19. package/dist/shared/{vue.dPRo2X5y.mjs → vue.BQRpjwKl.mjs} +2 -2
  20. package/dist/shared/vue.BSfiHqwj.mjs +34 -0
  21. package/dist/shared/{vue.CZwftA0L.cjs → vue.BVaMoz9y.cjs} +1 -1
  22. package/dist/shared/vue.BY0qpgYr.cjs +35 -0
  23. package/dist/shared/vue.Bk5xjlUx.cjs +61 -0
  24. package/dist/shared/{vue.3VLZmw05.mjs → vue.BsGwt78R.mjs} +1 -1
  25. package/dist/shared/{vue.B_LRH8SM.cjs → vue.Bwd1sGAM.cjs} +2 -2
  26. package/dist/shared/vue.ByxbBC3y.mjs +57 -0
  27. package/dist/shared/{vue.BbMPRDeO.mjs → vue.C13umiQi.mjs} +2 -2
  28. package/dist/shared/vue.C5FVoEZT.mjs +99 -0
  29. package/dist/shared/vue.CATOh_9G.mjs +42 -0
  30. package/dist/shared/{vue.XQFqlMId.cjs → vue.CIs8QhCw.cjs} +2 -2
  31. package/dist/shared/vue.CMohL_Cz.mjs +58 -0
  32. package/dist/shared/{vue.CnUlZSe8.mjs → vue.CQh3AUE8.mjs} +2 -5
  33. package/dist/shared/vue.CTqPbvz3.cjs +36 -0
  34. package/dist/shared/{vue.CSJSK0Nq.cjs → vue.CWZSMVnB.cjs} +3 -3
  35. package/dist/shared/{vue.DL-yMCNc.mjs → vue.CXB4NEMA.mjs} +2 -2
  36. package/dist/shared/{vue.D7xFeC2m.mjs → vue.C_4qJDiF.mjs} +1 -1
  37. package/dist/shared/vue.CbJFnho-.mjs +171 -0
  38. package/dist/shared/vue.CoaIWGPT.cjs +38 -0
  39. package/dist/shared/{vue.ChujsB0B.mjs → vue.CpkwC8Th.mjs} +1 -1
  40. package/dist/shared/vue.CrkK_T15.cjs +86 -0
  41. package/dist/shared/{vue.BMencBpI.cjs → vue.D-qi8PSL.cjs} +2 -2
  42. package/dist/shared/{vue.PJjEncbP.mjs → vue.D218Ow7t.mjs} +6 -2
  43. package/dist/shared/{vue.B2sFJ1xI.mjs → vue.D3Y0PWbF.mjs} +1 -1
  44. package/dist/shared/vue.D5U1yLG3.mjs +83 -0
  45. package/dist/shared/{vue.CXHYdyKZ.cjs → vue.DAg5wC1G.cjs} +2 -2
  46. package/dist/shared/vue.DDbVk0Zh.cjs +180 -0
  47. package/dist/shared/{vue.BaR1VPhl.cjs → vue.DE3emjSF.cjs} +2 -6
  48. package/dist/shared/vue.DEHxNvUX.cjs +7 -0
  49. package/dist/shared/vue.DFaMJLAQ.cjs +60 -0
  50. package/dist/shared/{vue.DgCmU1RR.cjs → vue.DKyQ7J67.cjs} +1 -1
  51. package/dist/shared/vue.DXQVIRZA.mjs +174 -0
  52. package/dist/shared/vue.DYk0Xfr3.mjs +36 -0
  53. package/dist/shared/vue.D_P5SqqD.mjs +5 -0
  54. package/dist/shared/{vue.C7yR7Cs0.cjs → vue.Di7yjJ-R.cjs} +2 -2
  55. package/dist/shared/vue.DxM45azl.cjs +173 -0
  56. package/dist/shared/{vue.WugzPOca.mjs → vue.Dyi1OCI1.mjs} +3 -3
  57. package/dist/shared/{vue.CEn2purG.cjs → vue.E_npPFoV.cjs} +2 -2
  58. package/dist/shared/{vue.__r7YYZE.cjs → vue.FiMmnMHr.cjs} +1 -1
  59. package/dist/shared/{vue.CZO8TwJP.mjs → vue.JUWqu6kD.mjs} +1 -1
  60. package/dist/shared/{vue.BaFrF2PF.mjs → vue.Mxc8w6Qk.mjs} +1 -1
  61. package/dist/shared/{vue.C32ozdA1.cjs → vue.Sbbm9JSu.cjs} +1 -1
  62. package/dist/shared/vue.ZuUCEEab.cjs +103 -0
  63. package/dist/shared/vue.g8fnm_ca.cjs +45 -0
  64. package/dist/shared/vue.l3UCdN7z.cjs +111 -0
  65. package/dist/swr.cjs +136 -0
  66. package/dist/swr.d.cts +41 -0
  67. package/dist/swr.d.mts +41 -0
  68. package/dist/swr.d.ts +41 -0
  69. package/dist/swr.mjs +131 -0
  70. package/dist/useAccountInfo.cjs +5 -4
  71. package/dist/useAccountInfo.mjs +5 -4
  72. package/dist/useAction.cjs +9 -0
  73. package/dist/useAction.d.cts +45 -0
  74. package/dist/useAction.d.mts +45 -0
  75. package/dist/useAction.d.ts +45 -0
  76. package/dist/useAction.mjs +3 -0
  77. package/dist/useAirdrop.cjs +14 -0
  78. package/dist/useAirdrop.d.cts +25 -0
  79. package/dist/useAirdrop.d.mts +25 -0
  80. package/dist/useAirdrop.d.ts +25 -0
  81. package/dist/useAirdrop.mjs +8 -0
  82. package/dist/useBalance.cjs +5 -4
  83. package/dist/useBalance.mjs +5 -4
  84. package/dist/useClientCapability.cjs +12 -0
  85. package/dist/useClientCapability.d.cts +39 -0
  86. package/dist/useClientCapability.d.mts +39 -0
  87. package/dist/useClientCapability.d.ts +39 -0
  88. package/dist/useClientCapability.mjs +5 -0
  89. package/dist/useConnection.cjs +4 -3
  90. package/dist/useConnection.d.cts +3 -2
  91. package/dist/useConnection.d.mts +3 -2
  92. package/dist/useConnection.d.ts +3 -2
  93. package/dist/useConnection.mjs +4 -3
  94. package/dist/useIdentity.cjs +12 -0
  95. package/dist/useIdentity.d.cts +3 -0
  96. package/dist/useIdentity.d.mts +3 -0
  97. package/dist/useIdentity.d.ts +3 -0
  98. package/dist/useIdentity.mjs +6 -0
  99. package/dist/usePayer.cjs +13 -0
  100. package/dist/usePayer.d.cts +18 -0
  101. package/dist/usePayer.d.mts +18 -0
  102. package/dist/usePayer.d.ts +18 -0
  103. package/dist/usePayer.mjs +6 -0
  104. package/dist/usePlanTransaction.cjs +14 -0
  105. package/dist/usePlanTransaction.d.cts +37 -0
  106. package/dist/usePlanTransaction.d.mts +37 -0
  107. package/dist/usePlanTransaction.d.ts +37 -0
  108. package/dist/usePlanTransaction.mjs +7 -0
  109. package/dist/usePlanTransactions.cjs +13 -0
  110. package/dist/usePlanTransactions.d.cts +4 -0
  111. package/dist/usePlanTransactions.d.mts +4 -0
  112. package/dist/usePlanTransactions.d.ts +4 -0
  113. package/dist/usePlanTransactions.mjs +7 -0
  114. package/dist/useProgramAccounts.cjs +5 -4
  115. package/dist/useProgramAccounts.mjs +5 -4
  116. package/dist/useRequest.cjs +11 -0
  117. package/dist/useRequest.d.cts +73 -0
  118. package/dist/useRequest.d.mts +73 -0
  119. package/dist/useRequest.d.ts +73 -0
  120. package/dist/useRequest.mjs +5 -0
  121. package/dist/useRpc.cjs +3 -2
  122. package/dist/useRpc.d.cts +3 -2
  123. package/dist/useRpc.d.mts +3 -2
  124. package/dist/useRpc.d.ts +3 -2
  125. package/dist/useRpc.mjs +3 -2
  126. package/dist/useSelectedWalletAccount.cjs +13 -0
  127. package/dist/useSelectedWalletAccount.d.cts +117 -0
  128. package/dist/useSelectedWalletAccount.d.mts +117 -0
  129. package/dist/useSelectedWalletAccount.d.ts +117 -0
  130. package/dist/useSelectedWalletAccount.mjs +3 -0
  131. package/dist/useSignAndSendTransaction.cjs +7 -6
  132. package/dist/useSignAndSendTransaction.mjs +7 -6
  133. package/dist/useSignAndSendTransactions.cjs +15 -0
  134. package/dist/useSignAndSendTransactions.d.cts +35 -0
  135. package/dist/useSignAndSendTransactions.d.mts +35 -0
  136. package/dist/useSignAndSendTransactions.d.ts +35 -0
  137. package/dist/useSignAndSendTransactions.mjs +8 -0
  138. package/dist/useSignIn.cjs +13 -0
  139. package/dist/useSignIn.d.cts +23 -0
  140. package/dist/useSignIn.d.mts +23 -0
  141. package/dist/useSignIn.d.ts +23 -0
  142. package/dist/useSignIn.mjs +7 -0
  143. package/dist/useSignMessage.cjs +4 -3
  144. package/dist/useSignMessage.mjs +4 -3
  145. package/dist/useSignTransactions.cjs +13 -0
  146. package/dist/useSignTransactions.d.cts +24 -0
  147. package/dist/useSignTransactions.d.mts +24 -0
  148. package/dist/useSignTransactions.d.ts +24 -0
  149. package/dist/useSignTransactions.mjs +7 -0
  150. package/dist/useSignatureStatus.cjs +5 -4
  151. package/dist/useSignatureStatus.mjs +5 -4
  152. package/dist/useSolana.cjs +2 -1
  153. package/dist/useSolana.mjs +2 -1
  154. package/dist/useSolanaClient.cjs +3 -2
  155. package/dist/useSolanaClient.d.cts +3 -2
  156. package/dist/useSolanaClient.d.mts +3 -2
  157. package/dist/useSolanaClient.d.ts +3 -2
  158. package/dist/useSolanaClient.mjs +3 -2
  159. package/dist/useSubscription.cjs +9 -0
  160. package/dist/useSubscription.d.cts +70 -0
  161. package/dist/useSubscription.d.mts +70 -0
  162. package/dist/useSubscription.d.ts +70 -0
  163. package/dist/useSubscription.mjs +3 -0
  164. package/dist/useTokenAccounts.cjs +5 -4
  165. package/dist/useTokenAccounts.mjs +5 -4
  166. package/dist/useTokenBalance.cjs +5 -4
  167. package/dist/useTokenBalance.mjs +5 -4
  168. package/dist/useTrackedData.cjs +10 -0
  169. package/dist/useTrackedData.d.cts +98 -0
  170. package/dist/useTrackedData.d.mts +98 -0
  171. package/dist/useTrackedData.d.ts +98 -0
  172. package/dist/useTrackedData.mjs +4 -0
  173. package/dist/useTransaction.cjs +2 -1
  174. package/dist/useTransaction.d.cts +12 -1
  175. package/dist/useTransaction.d.mts +12 -1
  176. package/dist/useTransaction.d.ts +12 -1
  177. package/dist/useTransaction.mjs +2 -1
  178. package/dist/useTransactionConfirmation.cjs +5 -4
  179. package/dist/useTransactionConfirmation.mjs +5 -4
  180. package/dist/useWallet.cjs +3 -2
  181. package/dist/useWallet.mjs +3 -2
  182. package/dist/useWallets.cjs +3 -2
  183. package/dist/useWallets.mjs +3 -2
  184. package/package.json +78 -3
  185. package/dist/shared/vue.C4d2JA8U.mjs +0 -44
  186. package/dist/shared/vue.CE5i8KZZ.cjs +0 -46
@@ -0,0 +1,111 @@
1
+ 'use strict';
2
+
3
+ const errors = require('@vue-solana/core/errors');
4
+ const vue = require('vue');
5
+
6
+ function useSubscription(source, options = {}) {
7
+ const data = vue.shallowRef(void 0);
8
+ const error = vue.shallowRef(null);
9
+ const status = vue.shallowRef("loading");
10
+ const disposables = [];
11
+ let connectionCount = 0;
12
+ let disposed = false;
13
+ let activeSource;
14
+ let activeStore;
15
+ function applyState(state) {
16
+ if (state.status === "loaded") {
17
+ data.value = state.data;
18
+ error.value = null;
19
+ status.value = "loaded";
20
+ } else if (state.status === "error") {
21
+ error.value = errors.normalizeSolanaError(state.error, "RPC_FAILURE");
22
+ status.value = "error";
23
+ options.onError?.(state.error);
24
+ } else if (state.status === "loading") {
25
+ status.value = data.value === void 0 ? "loading" : status.value;
26
+ } else if (state.status === "idle") {
27
+ data.value = void 0;
28
+ error.value = null;
29
+ status.value = "loading";
30
+ }
31
+ }
32
+ function openConnection(store, override) {
33
+ activeStore = store;
34
+ connectionCount += 1;
35
+ const connection = connectionCount;
36
+ const callerSignal = override ? override.abortSignal : options.getAbortSignal?.(connection);
37
+ applyState(store.getState());
38
+ disposables.push(
39
+ store.subscribe(() => {
40
+ applyState(store.getState());
41
+ })
42
+ );
43
+ if (callerSignal?.aborted) {
44
+ applyState({ data: store.getState().data, error: callerSignal.reason, status: "error" });
45
+ return;
46
+ }
47
+ if (callerSignal) {
48
+ store.withSignal(callerSignal).connect();
49
+ } else {
50
+ store.connect();
51
+ }
52
+ }
53
+ function disconnect() {
54
+ disposables.forEach((dispose) => {
55
+ dispose();
56
+ });
57
+ disposables.length = 0;
58
+ if (activeStore) {
59
+ activeStore.reset();
60
+ activeStore = void 0;
61
+ }
62
+ activeSource = void 0;
63
+ }
64
+ function connectCurrent(override) {
65
+ if (disposed) {
66
+ return;
67
+ }
68
+ const resolved = vue.isRef(source) ? source.value : source;
69
+ if (resolved === null || resolved === void 0) {
70
+ disconnect();
71
+ data.value = void 0;
72
+ error.value = null;
73
+ status.value = "disabled";
74
+ return;
75
+ }
76
+ if (activeSource === resolved && activeStore) {
77
+ openConnection(activeStore, override);
78
+ return;
79
+ }
80
+ disconnect();
81
+ activeSource = resolved;
82
+ openConnection(resolved.reactiveStore(), override);
83
+ }
84
+ vue.watch(
85
+ () => vue.isRef(source) ? source.value : source,
86
+ () => {
87
+ connectCurrent();
88
+ },
89
+ { flush: "sync" }
90
+ );
91
+ vue.onMounted(() => {
92
+ connectCurrent();
93
+ });
94
+ if (!vue.getCurrentInstance()) {
95
+ connectCurrent();
96
+ }
97
+ vue.onScopeDispose(() => {
98
+ disposed = true;
99
+ disconnect();
100
+ });
101
+ return {
102
+ data: vue.computed(() => data.value),
103
+ error: vue.computed(() => error.value),
104
+ reconnect: (options2) => {
105
+ connectCurrent(options2);
106
+ },
107
+ status: vue.computed(() => status.value)
108
+ };
109
+ }
110
+
111
+ exports.useSubscription = useSubscription;
package/dist/swr.cjs ADDED
@@ -0,0 +1,136 @@
1
+ 'use strict';
2
+
3
+ const vue = require('vue');
4
+ const useRequest = require('./shared/vue.ZuUCEEab.cjs');
5
+ const useSubscription = require('./shared/vue.l3UCdN7z.cjs');
6
+ const useTrackedData = require('./shared/vue.DxM45azl.cjs');
7
+ require('@vue-solana/core/action');
8
+ require('@vue-solana/core/kit');
9
+ require('@vue-solana/core/errors');
10
+
11
+ const PREFIX_REQUEST = "request:";
12
+ const PREFIX_SUBSCRIPTION = "subscription:";
13
+ const PREFIX_TRACKED = "tracked:";
14
+ const swrCache = /* @__PURE__ */ new Map();
15
+ function clearSwrCache() {
16
+ swrCache.clear();
17
+ }
18
+ function readSwrCache(key) {
19
+ return swrCache.get(key);
20
+ }
21
+ function writeSwrCache(key, entry) {
22
+ swrCache.set(key, entry);
23
+ }
24
+ function deleteSwrCache(key) {
25
+ swrCache.delete(key);
26
+ }
27
+ function isPendingStatus(status) {
28
+ return status === "fetching" || status === "loading";
29
+ }
30
+ function writeSwrResult(key, data, error, status) {
31
+ if (status === "disabled") {
32
+ deleteSwrCache(key);
33
+ return;
34
+ }
35
+ const previous = readSwrCache(key);
36
+ writeSwrCache(key, {
37
+ data: data !== void 0 ? data : previous?.data,
38
+ error,
39
+ status
40
+ });
41
+ }
42
+ function swrError(error, status, seed) {
43
+ if (status === "disabled") {
44
+ return null;
45
+ }
46
+ return error ?? (isPendingStatus(status) ? seed?.error ?? null : null);
47
+ }
48
+ function useRequestSwr(key, source, options = {}) {
49
+ const cacheKey = `${PREFIX_REQUEST}${key}`;
50
+ const seed = readSwrCache(cacheKey);
51
+ const result = useRequest.useRequest(source, options);
52
+ if (result.status.value === "disabled") {
53
+ deleteSwrCache(cacheKey);
54
+ }
55
+ vue.watch(
56
+ [result.data, result.error, result.status],
57
+ ([data2, error2, status]) => writeSwrResult(cacheKey, data2, error2, status),
58
+ { flush: "sync" }
59
+ );
60
+ const data = vue.computed(() => {
61
+ if (result.status.value === "disabled") {
62
+ return void 0;
63
+ }
64
+ return result.data.value !== void 0 ? result.data.value : seed?.data;
65
+ });
66
+ const error = vue.computed(
67
+ () => swrError(result.error.value, result.status.value, seed)
68
+ );
69
+ return {
70
+ data,
71
+ error,
72
+ refresh: result.refresh,
73
+ status: result.status
74
+ };
75
+ }
76
+ function useSubscriptionSwr(key, source, options = {}) {
77
+ const cacheKey = `${PREFIX_SUBSCRIPTION}${key}`;
78
+ const seed = readSwrCache(cacheKey);
79
+ const result = useSubscription.useSubscription(source, options);
80
+ if (result.status.value === "disabled") {
81
+ deleteSwrCache(cacheKey);
82
+ }
83
+ vue.watch(
84
+ [result.data, result.error, result.status],
85
+ ([data2, error2, status]) => writeSwrResult(cacheKey, data2, error2, status),
86
+ { flush: "sync" }
87
+ );
88
+ const data = vue.computed(() => {
89
+ if (result.status.value === "disabled") {
90
+ return void 0;
91
+ }
92
+ return result.data.value !== void 0 ? result.data.value : seed?.data;
93
+ });
94
+ const error = vue.computed(
95
+ () => swrError(result.error.value, result.status.value, seed)
96
+ );
97
+ return {
98
+ data,
99
+ error,
100
+ reconnect: result.reconnect,
101
+ status: result.status
102
+ };
103
+ }
104
+ function useTrackedDataSwr(key, source, options = {}) {
105
+ const cacheKey = `${PREFIX_TRACKED}${key}`;
106
+ const seed = readSwrCache(cacheKey);
107
+ const result = useTrackedData.useTrackedData(source, options);
108
+ if (result.status.value === "disabled") {
109
+ deleteSwrCache(cacheKey);
110
+ }
111
+ vue.watch(
112
+ [result.data, result.error, result.status],
113
+ ([data2, error2, status]) => writeSwrResult(cacheKey, data2, error2, status),
114
+ { flush: "sync" }
115
+ );
116
+ const data = vue.computed(() => {
117
+ if (result.status.value === "disabled") {
118
+ return void 0;
119
+ }
120
+ return result.data.value ?? seed?.data;
121
+ });
122
+ const error = vue.computed(
123
+ () => swrError(result.error.value, result.status.value, seed)
124
+ );
125
+ return {
126
+ data,
127
+ error,
128
+ refresh: result.refresh,
129
+ status: result.status
130
+ };
131
+ }
132
+
133
+ exports.clearSwrCache = clearSwrCache;
134
+ exports.useRequestSwr = useRequestSwr;
135
+ exports.useSubscriptionSwr = useSubscriptionSwr;
136
+ exports.useTrackedDataSwr = useTrackedDataSwr;
package/dist/swr.d.cts ADDED
@@ -0,0 +1,41 @@
1
+ import { useRequest, UseRequestOptions, UseRequestReturn } from './useRequest.cjs';
2
+ import { UseSubscriptionSource, UseSubscriptionOptions, UseSubscriptionReturn } from './useSubscription.cjs';
3
+ import { UseTrackedDataSource, UseTrackedDataOptions, UseTrackedDataReturn } from './useTrackedData.cjs';
4
+ import '@vue-solana/core/errors';
5
+ import 'vue';
6
+ import '@vue-solana/core/kit';
7
+
8
+ /**
9
+ * Remove every cached SWR entry (all adapters). Useful between test cases
10
+ * and to reset server-side caches per request.
11
+ */
12
+ declare function clearSwrCache(): void;
13
+ /**
14
+ * `useRequest` with cache keying. A component mounting with a key that
15
+ * already holds data shows it immediately (stale) while its own request
16
+ * revalidates; results are written back for the next mount.
17
+ *
18
+ * A `null`/`undefined` source disables the request and **clears** the
19
+ * cached entry for the key — including when the component mounts with the
20
+ * source already disabled.
21
+ */
22
+ declare function useRequestSwr<TResult>(key: string, source: Parameters<typeof useRequest<TResult>>[0], options?: UseRequestOptions): UseRequestReturn<TResult>;
23
+ /**
24
+ * `useSubscription` with cache keying — a freshly mounted component seeds
25
+ * from the last-known stream value while its own subscription connects.
26
+ *
27
+ * A `null`/`undefined` source disables the subscription and **clears** the
28
+ * cached entry for the key.
29
+ */
30
+ declare function useSubscriptionSwr<TResult>(key: string, source: UseSubscriptionSource<TResult>, options?: UseSubscriptionOptions): UseSubscriptionReturn<TResult>;
31
+ /**
32
+ * `useTrackedData` with cache keying — seeds from the last-known
33
+ * {@link SolanaRpcResponse} envelope (data **and** slot context) while the
34
+ * fetch + subscription pair revalidates.
35
+ *
36
+ * A `null`/`undefined` source disables the composable and **clears** the
37
+ * cached entry for the key.
38
+ */
39
+ declare function useTrackedDataSwr<TInitialValue, TStreamValue, TItem>(key: string, source: UseTrackedDataSource<TInitialValue, TStreamValue, TItem>, options?: UseTrackedDataOptions): UseTrackedDataReturn<TItem>;
40
+
41
+ export { clearSwrCache, useRequestSwr, useSubscriptionSwr, useTrackedDataSwr };
package/dist/swr.d.mts ADDED
@@ -0,0 +1,41 @@
1
+ import { useRequest, UseRequestOptions, UseRequestReturn } from './useRequest.mjs';
2
+ import { UseSubscriptionSource, UseSubscriptionOptions, UseSubscriptionReturn } from './useSubscription.mjs';
3
+ import { UseTrackedDataSource, UseTrackedDataOptions, UseTrackedDataReturn } from './useTrackedData.mjs';
4
+ import '@vue-solana/core/errors';
5
+ import 'vue';
6
+ import '@vue-solana/core/kit';
7
+
8
+ /**
9
+ * Remove every cached SWR entry (all adapters). Useful between test cases
10
+ * and to reset server-side caches per request.
11
+ */
12
+ declare function clearSwrCache(): void;
13
+ /**
14
+ * `useRequest` with cache keying. A component mounting with a key that
15
+ * already holds data shows it immediately (stale) while its own request
16
+ * revalidates; results are written back for the next mount.
17
+ *
18
+ * A `null`/`undefined` source disables the request and **clears** the
19
+ * cached entry for the key — including when the component mounts with the
20
+ * source already disabled.
21
+ */
22
+ declare function useRequestSwr<TResult>(key: string, source: Parameters<typeof useRequest<TResult>>[0], options?: UseRequestOptions): UseRequestReturn<TResult>;
23
+ /**
24
+ * `useSubscription` with cache keying — a freshly mounted component seeds
25
+ * from the last-known stream value while its own subscription connects.
26
+ *
27
+ * A `null`/`undefined` source disables the subscription and **clears** the
28
+ * cached entry for the key.
29
+ */
30
+ declare function useSubscriptionSwr<TResult>(key: string, source: UseSubscriptionSource<TResult>, options?: UseSubscriptionOptions): UseSubscriptionReturn<TResult>;
31
+ /**
32
+ * `useTrackedData` with cache keying — seeds from the last-known
33
+ * {@link SolanaRpcResponse} envelope (data **and** slot context) while the
34
+ * fetch + subscription pair revalidates.
35
+ *
36
+ * A `null`/`undefined` source disables the composable and **clears** the
37
+ * cached entry for the key.
38
+ */
39
+ declare function useTrackedDataSwr<TInitialValue, TStreamValue, TItem>(key: string, source: UseTrackedDataSource<TInitialValue, TStreamValue, TItem>, options?: UseTrackedDataOptions): UseTrackedDataReturn<TItem>;
40
+
41
+ export { clearSwrCache, useRequestSwr, useSubscriptionSwr, useTrackedDataSwr };
package/dist/swr.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { useRequest, UseRequestOptions, UseRequestReturn } from './useRequest.js';
2
+ import { UseSubscriptionSource, UseSubscriptionOptions, UseSubscriptionReturn } from './useSubscription.js';
3
+ import { UseTrackedDataSource, UseTrackedDataOptions, UseTrackedDataReturn } from './useTrackedData.js';
4
+ import '@vue-solana/core/errors';
5
+ import 'vue';
6
+ import '@vue-solana/core/kit';
7
+
8
+ /**
9
+ * Remove every cached SWR entry (all adapters). Useful between test cases
10
+ * and to reset server-side caches per request.
11
+ */
12
+ declare function clearSwrCache(): void;
13
+ /**
14
+ * `useRequest` with cache keying. A component mounting with a key that
15
+ * already holds data shows it immediately (stale) while its own request
16
+ * revalidates; results are written back for the next mount.
17
+ *
18
+ * A `null`/`undefined` source disables the request and **clears** the
19
+ * cached entry for the key — including when the component mounts with the
20
+ * source already disabled.
21
+ */
22
+ declare function useRequestSwr<TResult>(key: string, source: Parameters<typeof useRequest<TResult>>[0], options?: UseRequestOptions): UseRequestReturn<TResult>;
23
+ /**
24
+ * `useSubscription` with cache keying — a freshly mounted component seeds
25
+ * from the last-known stream value while its own subscription connects.
26
+ *
27
+ * A `null`/`undefined` source disables the subscription and **clears** the
28
+ * cached entry for the key.
29
+ */
30
+ declare function useSubscriptionSwr<TResult>(key: string, source: UseSubscriptionSource<TResult>, options?: UseSubscriptionOptions): UseSubscriptionReturn<TResult>;
31
+ /**
32
+ * `useTrackedData` with cache keying — seeds from the last-known
33
+ * {@link SolanaRpcResponse} envelope (data **and** slot context) while the
34
+ * fetch + subscription pair revalidates.
35
+ *
36
+ * A `null`/`undefined` source disables the composable and **clears** the
37
+ * cached entry for the key.
38
+ */
39
+ declare function useTrackedDataSwr<TInitialValue, TStreamValue, TItem>(key: string, source: UseTrackedDataSource<TInitialValue, TStreamValue, TItem>, options?: UseTrackedDataOptions): UseTrackedDataReturn<TItem>;
40
+
41
+ export { clearSwrCache, useRequestSwr, useSubscriptionSwr, useTrackedDataSwr };
package/dist/swr.mjs ADDED
@@ -0,0 +1,131 @@
1
+ import { watch, computed } from 'vue';
2
+ import { u as useRequest } from './shared/vue.B8VvC8d2.mjs';
3
+ import { u as useSubscription } from './shared/vue.BDNOyiGZ.mjs';
4
+ import { u as useTrackedData } from './shared/vue.CbJFnho-.mjs';
5
+ import '@vue-solana/core/action';
6
+ import '@vue-solana/core/kit';
7
+ import '@vue-solana/core/errors';
8
+
9
+ const PREFIX_REQUEST = "request:";
10
+ const PREFIX_SUBSCRIPTION = "subscription:";
11
+ const PREFIX_TRACKED = "tracked:";
12
+ const swrCache = /* @__PURE__ */ new Map();
13
+ function clearSwrCache() {
14
+ swrCache.clear();
15
+ }
16
+ function readSwrCache(key) {
17
+ return swrCache.get(key);
18
+ }
19
+ function writeSwrCache(key, entry) {
20
+ swrCache.set(key, entry);
21
+ }
22
+ function deleteSwrCache(key) {
23
+ swrCache.delete(key);
24
+ }
25
+ function isPendingStatus(status) {
26
+ return status === "fetching" || status === "loading";
27
+ }
28
+ function writeSwrResult(key, data, error, status) {
29
+ if (status === "disabled") {
30
+ deleteSwrCache(key);
31
+ return;
32
+ }
33
+ const previous = readSwrCache(key);
34
+ writeSwrCache(key, {
35
+ data: data !== void 0 ? data : previous?.data,
36
+ error,
37
+ status
38
+ });
39
+ }
40
+ function swrError(error, status, seed) {
41
+ if (status === "disabled") {
42
+ return null;
43
+ }
44
+ return error ?? (isPendingStatus(status) ? seed?.error ?? null : null);
45
+ }
46
+ function useRequestSwr(key, source, options = {}) {
47
+ const cacheKey = `${PREFIX_REQUEST}${key}`;
48
+ const seed = readSwrCache(cacheKey);
49
+ const result = useRequest(source, options);
50
+ if (result.status.value === "disabled") {
51
+ deleteSwrCache(cacheKey);
52
+ }
53
+ watch(
54
+ [result.data, result.error, result.status],
55
+ ([data2, error2, status]) => writeSwrResult(cacheKey, data2, error2, status),
56
+ { flush: "sync" }
57
+ );
58
+ const data = computed(() => {
59
+ if (result.status.value === "disabled") {
60
+ return void 0;
61
+ }
62
+ return result.data.value !== void 0 ? result.data.value : seed?.data;
63
+ });
64
+ const error = computed(
65
+ () => swrError(result.error.value, result.status.value, seed)
66
+ );
67
+ return {
68
+ data,
69
+ error,
70
+ refresh: result.refresh,
71
+ status: result.status
72
+ };
73
+ }
74
+ function useSubscriptionSwr(key, source, options = {}) {
75
+ const cacheKey = `${PREFIX_SUBSCRIPTION}${key}`;
76
+ const seed = readSwrCache(cacheKey);
77
+ const result = useSubscription(source, options);
78
+ if (result.status.value === "disabled") {
79
+ deleteSwrCache(cacheKey);
80
+ }
81
+ watch(
82
+ [result.data, result.error, result.status],
83
+ ([data2, error2, status]) => writeSwrResult(cacheKey, data2, error2, status),
84
+ { flush: "sync" }
85
+ );
86
+ const data = computed(() => {
87
+ if (result.status.value === "disabled") {
88
+ return void 0;
89
+ }
90
+ return result.data.value !== void 0 ? result.data.value : seed?.data;
91
+ });
92
+ const error = computed(
93
+ () => swrError(result.error.value, result.status.value, seed)
94
+ );
95
+ return {
96
+ data,
97
+ error,
98
+ reconnect: result.reconnect,
99
+ status: result.status
100
+ };
101
+ }
102
+ function useTrackedDataSwr(key, source, options = {}) {
103
+ const cacheKey = `${PREFIX_TRACKED}${key}`;
104
+ const seed = readSwrCache(cacheKey);
105
+ const result = useTrackedData(source, options);
106
+ if (result.status.value === "disabled") {
107
+ deleteSwrCache(cacheKey);
108
+ }
109
+ watch(
110
+ [result.data, result.error, result.status],
111
+ ([data2, error2, status]) => writeSwrResult(cacheKey, data2, error2, status),
112
+ { flush: "sync" }
113
+ );
114
+ const data = computed(() => {
115
+ if (result.status.value === "disabled") {
116
+ return void 0;
117
+ }
118
+ return result.data.value ?? seed?.data;
119
+ });
120
+ const error = computed(
121
+ () => swrError(result.error.value, result.status.value, seed)
122
+ );
123
+ return {
124
+ data,
125
+ error,
126
+ refresh: result.refresh,
127
+ status: result.status
128
+ };
129
+ }
130
+
131
+ export { clearSwrCache, useRequestSwr, useSubscriptionSwr, useTrackedDataSwr };
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const useAccountInfo = require('./shared/vue.BMencBpI.cjs');
3
+ const useAccountInfo = require('./shared/vue.D-qi8PSL.cjs');
4
4
  require('@vue-solana/core/errors');
5
5
  require('vue');
6
6
  require('@vue-solana/core/address');
7
- require('./shared/vue.CZwftA0L.cjs');
8
- require('./shared/vue.k9Q6aN-0.cjs');
9
- require('./shared/vue.BaR1VPhl.cjs');
7
+ require('./shared/vue.BVaMoz9y.cjs');
8
+ require('./shared/vue.BIxphCAq.cjs');
9
+ require('./shared/vue.DE3emjSF.cjs');
10
+ require('./shared/vue.DEHxNvUX.cjs');
10
11
  require('./shared/vue.DNxOpDXz.cjs');
11
12
 
12
13
 
@@ -1,8 +1,9 @@
1
- export { u as useAccountInfo } from './shared/vue.dPRo2X5y.mjs';
1
+ export { u as useAccountInfo } from './shared/vue.BQRpjwKl.mjs';
2
2
  import '@vue-solana/core/errors';
3
3
  import 'vue';
4
4
  import '@vue-solana/core/address';
5
- import './shared/vue.ChujsB0B.mjs';
6
- import './shared/vue.BaFrF2PF.mjs';
7
- import './shared/vue.CnUlZSe8.mjs';
5
+ import './shared/vue.CpkwC8Th.mjs';
6
+ import './shared/vue.Mxc8w6Qk.mjs';
7
+ import './shared/vue.CQh3AUE8.mjs';
8
+ import './shared/vue.D_P5SqqD.mjs';
8
9
  import './shared/vue.Bfu1dCKe.mjs';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const useAction = require('./shared/vue.CoaIWGPT.cjs');
4
+ require('@vue-solana/core/action');
5
+ require('vue');
6
+
7
+
8
+
9
+ exports.useAction = useAction.useAction;
@@ -0,0 +1,45 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
3
+ type UseActionStatus = "idle" | "running" | "success" | "error";
4
+ interface UseActionOptions {
5
+ /**
6
+ * Called after a dispatch settles successfully.
7
+ */
8
+ onSuccess?: (data: unknown) => void;
9
+ /**
10
+ * Called after a dispatch fails for a reason other than supersession.
11
+ */
12
+ onError?: (error: unknown) => void;
13
+ }
14
+ interface UseActionReturn<TArgs extends readonly unknown[], TResult> {
15
+ data: ComputedRef<TResult | undefined>;
16
+ dispatch: (...args: TArgs) => Promise<TResult>;
17
+ error: ComputedRef<unknown>;
18
+ isRunning: ComputedRef<boolean>;
19
+ reset: () => void;
20
+ status: ComputedRef<UseActionStatus>;
21
+ }
22
+ /**
23
+ * Generic async action state machine.
24
+ *
25
+ * Accepts any async function that receives a fresh `AbortSignal` per call and
26
+ * tracks `{ data, dispatch, error, isRunning, reset, status }` through Vue
27
+ * reactive state.
28
+ *
29
+ * - There is no dependencies array: pass the handler directly or as a ref;
30
+ * `dispatch` always invokes the latest closure, so handlers reading
31
+ * reactive state never see stale values. `dispatch` keeps a stable identity
32
+ * across the component lifetime.
33
+ * - Calling `dispatch` again while a call is in flight aborts the previous
34
+ * call. Superseded calls reject with an abort reason so callers can detect
35
+ * them; they never corrupt state.
36
+ * - Failures surface on `error` while the previous `data` is preserved for
37
+ * stale-while-revalidate rendering.
38
+ *
39
+ * The underlying state machine is `createSolanaActionStore` from
40
+ * `@vue-solana/core/action`, shared with non-Vue consumers.
41
+ */
42
+ declare function useAction<TArgs extends readonly unknown[], TResult>(action: ((signal: AbortSignal, ...args: TArgs) => Promise<TResult>) | Ref<(signal: AbortSignal, ...args: TArgs) => Promise<TResult>>, options?: UseActionOptions): UseActionReturn<TArgs, TResult>;
43
+
44
+ export { useAction };
45
+ export type { UseActionOptions, UseActionReturn, UseActionStatus };
@@ -0,0 +1,45 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
3
+ type UseActionStatus = "idle" | "running" | "success" | "error";
4
+ interface UseActionOptions {
5
+ /**
6
+ * Called after a dispatch settles successfully.
7
+ */
8
+ onSuccess?: (data: unknown) => void;
9
+ /**
10
+ * Called after a dispatch fails for a reason other than supersession.
11
+ */
12
+ onError?: (error: unknown) => void;
13
+ }
14
+ interface UseActionReturn<TArgs extends readonly unknown[], TResult> {
15
+ data: ComputedRef<TResult | undefined>;
16
+ dispatch: (...args: TArgs) => Promise<TResult>;
17
+ error: ComputedRef<unknown>;
18
+ isRunning: ComputedRef<boolean>;
19
+ reset: () => void;
20
+ status: ComputedRef<UseActionStatus>;
21
+ }
22
+ /**
23
+ * Generic async action state machine.
24
+ *
25
+ * Accepts any async function that receives a fresh `AbortSignal` per call and
26
+ * tracks `{ data, dispatch, error, isRunning, reset, status }` through Vue
27
+ * reactive state.
28
+ *
29
+ * - There is no dependencies array: pass the handler directly or as a ref;
30
+ * `dispatch` always invokes the latest closure, so handlers reading
31
+ * reactive state never see stale values. `dispatch` keeps a stable identity
32
+ * across the component lifetime.
33
+ * - Calling `dispatch` again while a call is in flight aborts the previous
34
+ * call. Superseded calls reject with an abort reason so callers can detect
35
+ * them; they never corrupt state.
36
+ * - Failures surface on `error` while the previous `data` is preserved for
37
+ * stale-while-revalidate rendering.
38
+ *
39
+ * The underlying state machine is `createSolanaActionStore` from
40
+ * `@vue-solana/core/action`, shared with non-Vue consumers.
41
+ */
42
+ declare function useAction<TArgs extends readonly unknown[], TResult>(action: ((signal: AbortSignal, ...args: TArgs) => Promise<TResult>) | Ref<(signal: AbortSignal, ...args: TArgs) => Promise<TResult>>, options?: UseActionOptions): UseActionReturn<TArgs, TResult>;
43
+
44
+ export { useAction };
45
+ export type { UseActionOptions, UseActionReturn, UseActionStatus };
@@ -0,0 +1,45 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
3
+ type UseActionStatus = "idle" | "running" | "success" | "error";
4
+ interface UseActionOptions {
5
+ /**
6
+ * Called after a dispatch settles successfully.
7
+ */
8
+ onSuccess?: (data: unknown) => void;
9
+ /**
10
+ * Called after a dispatch fails for a reason other than supersession.
11
+ */
12
+ onError?: (error: unknown) => void;
13
+ }
14
+ interface UseActionReturn<TArgs extends readonly unknown[], TResult> {
15
+ data: ComputedRef<TResult | undefined>;
16
+ dispatch: (...args: TArgs) => Promise<TResult>;
17
+ error: ComputedRef<unknown>;
18
+ isRunning: ComputedRef<boolean>;
19
+ reset: () => void;
20
+ status: ComputedRef<UseActionStatus>;
21
+ }
22
+ /**
23
+ * Generic async action state machine.
24
+ *
25
+ * Accepts any async function that receives a fresh `AbortSignal` per call and
26
+ * tracks `{ data, dispatch, error, isRunning, reset, status }` through Vue
27
+ * reactive state.
28
+ *
29
+ * - There is no dependencies array: pass the handler directly or as a ref;
30
+ * `dispatch` always invokes the latest closure, so handlers reading
31
+ * reactive state never see stale values. `dispatch` keeps a stable identity
32
+ * across the component lifetime.
33
+ * - Calling `dispatch` again while a call is in flight aborts the previous
34
+ * call. Superseded calls reject with an abort reason so callers can detect
35
+ * them; they never corrupt state.
36
+ * - Failures surface on `error` while the previous `data` is preserved for
37
+ * stale-while-revalidate rendering.
38
+ *
39
+ * The underlying state machine is `createSolanaActionStore` from
40
+ * `@vue-solana/core/action`, shared with non-Vue consumers.
41
+ */
42
+ declare function useAction<TArgs extends readonly unknown[], TResult>(action: ((signal: AbortSignal, ...args: TArgs) => Promise<TResult>) | Ref<(signal: AbortSignal, ...args: TArgs) => Promise<TResult>>, options?: UseActionOptions): UseActionReturn<TArgs, TResult>;
43
+
44
+ export { useAction };
45
+ export type { UseActionOptions, UseActionReturn, UseActionStatus };