@use-stellar/vue 0.0.0-stage → 0.2.3

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,84 @@
1
+ import { InjectionKey, Ref, App } from 'vue';
2
+ import { QueryStore, WalletState, QueryConfig } from 'use-stellar/core';
3
+
4
+ type StellarNetwork = "testnet" | "mainnet" | "futurenet";
5
+ interface NetworkConfig {
6
+ network: StellarNetwork;
7
+ horizonUrl: string;
8
+ sorobanUrl: string;
9
+ networkPassphrase: string;
10
+ }
11
+ type Asset = "XLM" | {
12
+ code: string;
13
+ issuer: string;
14
+ };
15
+ type Balance = {
16
+ asset: "XLM";
17
+ balance: string;
18
+ } | {
19
+ asset: {
20
+ code: string;
21
+ issuer: string;
22
+ };
23
+ balance: string;
24
+ limit?: string;
25
+ } | {
26
+ asset: "liquidity_pool_shares";
27
+ balance: string;
28
+ liquidityPoolId: string;
29
+ };
30
+ declare const NETWORK_CONFIGS: Record<StellarNetwork, NetworkConfig>;
31
+
32
+ interface StellarPluginOptions {
33
+ /** Defaults to `"testnet"`. */
34
+ network?: StellarNetwork;
35
+ /** Override the built-in Horizon/Soroban endpoints for `network`. Any field left out keeps the default. */
36
+ networkConfig?: Partial<Pick<NetworkConfig, "horizonUrl" | "sorobanUrl" | "networkPassphrase">>;
37
+ /** Cache configuration shared by every composable. */
38
+ queryConfig?: QueryConfig;
39
+ /** Initial connected wallet address, primarily for restored client sessions. */
40
+ walletAddress?: string | null;
41
+ }
42
+ interface StellarRuntime {
43
+ network: StellarNetwork;
44
+ networkConfig: NetworkConfig;
45
+ /** One query cache per app, shared by every composable. */
46
+ queryStore: QueryStore;
47
+ /** The wallet connection the write composables sign with. */
48
+ wallet: WalletState;
49
+ /** Replaces the wallet state, and keeps `walletAddress` in step with it. */
50
+ setWallet: (wallet: WalletState) => void;
51
+ /** The address read composables default to when given none. */
52
+ walletAddress: Ref<string | null>;
53
+ setWalletAddress: (address: string | null) => void;
54
+ }
55
+ declare const STELLAR_RUNTIME_KEY: InjectionKey<StellarRuntime>;
56
+ /**
57
+ * Builds a Stellar runtime without installing it as a plugin. Used by
58
+ * {@link createStellarPlugin} itself, and by the test harness in
59
+ * `use-stellar/vue/test-utils` to provide a runtime without a real app.
60
+ */
61
+ declare function createStellarRuntime(options?: StellarPluginOptions): StellarRuntime;
62
+ /**
63
+ * Vue plugin that installs the Stellar runtime — resolved network config plus
64
+ * one shared query cache — so every composable in this package reads and
65
+ * writes through the same instance.
66
+ *
67
+ * @example
68
+ * import { createApp } from "vue"
69
+ * import { createStellarPlugin } from "@use-stellar/vue"
70
+ *
71
+ * createApp(App).use(createStellarPlugin({ network: "testnet" })).mount("#app")
72
+ */
73
+ declare function createStellarPlugin(options?: StellarPluginOptions): {
74
+ install(app: App): void;
75
+ };
76
+ /**
77
+ * Reads the installed Stellar runtime.
78
+ *
79
+ * @throws {Error} when called outside a component tree the plugin was
80
+ * installed on (or outside `app.runWithContext()` in tests).
81
+ */
82
+ declare function useStellarRuntime(): StellarRuntime;
83
+
84
+ export { type Asset as A, type Balance as B, NETWORK_CONFIGS as N, STELLAR_RUNTIME_KEY as S, type NetworkConfig as a, type StellarNetwork as b, type StellarPluginOptions as c, type StellarRuntime as d, createStellarPlugin as e, createStellarRuntime as f, useStellarRuntime as u };
@@ -0,0 +1,27 @@
1
+ import { App } from 'vue';
2
+ import { d as StellarRuntime, c as StellarPluginOptions } from './plugin-bXIRDH8_.mjs';
3
+ import 'use-stellar/core';
4
+
5
+ interface StellarTestHarness {
6
+ app: App;
7
+ /** The exact runtime instance provided to the app — same `QueryStore` every composable in `run()` reads through. */
8
+ runtime: StellarRuntime;
9
+ /** Runs `fn` with the runtime available to `inject()` / composables, inside a disposable effect scope. */
10
+ run: <T>(fn: () => T) => T;
11
+ /** Stops the effect scope, tearing down every watcher/computed created via `run()`. Call in `afterEach`. */
12
+ dispose: () => void;
13
+ }
14
+ /**
15
+ * Mounts a throwaway Vue app with the Stellar plugin installed, for testing
16
+ * composables that call `useStellarRuntime()` — directly, or through
17
+ * `useBalance` and friends — with no real component tree.
18
+ *
19
+ * @example
20
+ * const harness = createStellarTestHarness({ network: "testnet" })
21
+ * const { balance } = harness.run(() => useBalance({ address: "GABC..." }))
22
+ * // ...assert...
23
+ * harness.dispose()
24
+ */
25
+ declare function createStellarTestHarness(options?: StellarPluginOptions): StellarTestHarness;
26
+
27
+ export { type StellarTestHarness, createStellarTestHarness };
@@ -0,0 +1,27 @@
1
+ import { App } from 'vue';
2
+ import { d as StellarRuntime, c as StellarPluginOptions } from './plugin-bXIRDH8_.js';
3
+ import 'use-stellar/core';
4
+
5
+ interface StellarTestHarness {
6
+ app: App;
7
+ /** The exact runtime instance provided to the app — same `QueryStore` every composable in `run()` reads through. */
8
+ runtime: StellarRuntime;
9
+ /** Runs `fn` with the runtime available to `inject()` / composables, inside a disposable effect scope. */
10
+ run: <T>(fn: () => T) => T;
11
+ /** Stops the effect scope, tearing down every watcher/computed created via `run()`. Call in `afterEach`. */
12
+ dispose: () => void;
13
+ }
14
+ /**
15
+ * Mounts a throwaway Vue app with the Stellar plugin installed, for testing
16
+ * composables that call `useStellarRuntime()` — directly, or through
17
+ * `useBalance` and friends — with no real component tree.
18
+ *
19
+ * @example
20
+ * const harness = createStellarTestHarness({ network: "testnet" })
21
+ * const { balance } = harness.run(() => useBalance({ address: "GABC..." }))
22
+ * // ...assert...
23
+ * harness.dispose()
24
+ */
25
+ declare function createStellarTestHarness(options?: StellarPluginOptions): StellarTestHarness;
26
+
27
+ export { type StellarTestHarness, createStellarTestHarness };
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+ var core = require('use-stellar/core');
5
+
6
+ // src/test-utils.ts
7
+
8
+ // src/types.ts
9
+ var NETWORK_PASSPHRASES = {
10
+ testnet: "Test SDF Network ; September 2015",
11
+ mainnet: "Public Global Stellar Network ; September 2015",
12
+ futurenet: "Test SDF Future Network ; October 2022"
13
+ };
14
+ var NETWORK_CONFIGS = {
15
+ testnet: {
16
+ network: "testnet",
17
+ horizonUrl: "https://horizon-testnet.stellar.org",
18
+ sorobanUrl: "https://soroban-testnet.stellar.org",
19
+ networkPassphrase: NETWORK_PASSPHRASES.testnet
20
+ },
21
+ mainnet: {
22
+ network: "mainnet",
23
+ horizonUrl: "https://horizon.stellar.org",
24
+ sorobanUrl: "https://soroban.stellar.org",
25
+ networkPassphrase: NETWORK_PASSPHRASES.mainnet
26
+ },
27
+ futurenet: {
28
+ network: "futurenet",
29
+ horizonUrl: "https://horizon-futurenet.stellar.org",
30
+ sorobanUrl: "https://rpc-futurenet.stellar.org",
31
+ networkPassphrase: NETWORK_PASSPHRASES.futurenet
32
+ }
33
+ };
34
+
35
+ // src/plugin.ts
36
+ var STELLAR_RUNTIME_KEY = /* @__PURE__ */ Symbol("use-stellar/vue:runtime");
37
+ var DISCONNECTED_WALLET = {
38
+ connected: false,
39
+ connecting: false,
40
+ address: null,
41
+ network: null,
42
+ wallet: null,
43
+ walletName: null,
44
+ error: null,
45
+ walletNetwork: null,
46
+ walletNetworkPassphrase: null
47
+ };
48
+ function resolveNetworkConfig(network, override) {
49
+ const builtIn = NETWORK_CONFIGS[network];
50
+ if (!override) return builtIn;
51
+ return {
52
+ network,
53
+ horizonUrl: override.horizonUrl ?? builtIn.horizonUrl,
54
+ sorobanUrl: override.sorobanUrl ?? builtIn.sorobanUrl,
55
+ networkPassphrase: override.networkPassphrase ?? builtIn.networkPassphrase
56
+ };
57
+ }
58
+ function createStellarRuntime(options = {}) {
59
+ const network = options.network ?? "testnet";
60
+ const walletAddress = vue.shallowRef(options.walletAddress ?? null);
61
+ const runtime = {
62
+ network,
63
+ networkConfig: resolveNetworkConfig(network, options.networkConfig),
64
+ queryStore: new core.QueryStore(options.queryConfig),
65
+ wallet: { ...DISCONNECTED_WALLET, address: options.walletAddress ?? null },
66
+ setWallet(wallet) {
67
+ runtime.wallet = wallet;
68
+ walletAddress.value = wallet.address;
69
+ },
70
+ walletAddress,
71
+ setWalletAddress(address) {
72
+ walletAddress.value = address;
73
+ }
74
+ };
75
+ return runtime;
76
+ }
77
+
78
+ // src/test-utils.ts
79
+ function createStellarTestHarness(options = {}) {
80
+ const runtime = createStellarRuntime(options);
81
+ const app = vue.createApp({});
82
+ app.provide(STELLAR_RUNTIME_KEY, runtime);
83
+ const scope = vue.effectScope();
84
+ function run(fn) {
85
+ return scope.run(() => app.runWithContext(fn));
86
+ }
87
+ return {
88
+ app,
89
+ runtime,
90
+ run,
91
+ dispose: () => scope.stop()
92
+ };
93
+ }
94
+
95
+ exports.createStellarTestHarness = createStellarTestHarness;
96
+ //# sourceMappingURL=test-utils.js.map
97
+ //# sourceMappingURL=test-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../src/plugin.ts","../src/test-utils.ts"],"names":["shallowRef","QueryStore","createApp","effectScope"],"mappings":";;;;;;;;AA0BA,IAAM,mBAAA,GAAsD;AAAA,EAC1D,OAAA,EAAS,mCAAA;AAAA,EACT,OAAA,EAAS,gDAAA;AAAA,EACT,SAAA,EAAW;AACb,CAAA;AAEO,IAAM,eAAA,GAAyD;AAAA,EACpE,OAAA,EAAS;AAAA,IACP,OAAA,EAAS,SAAA;AAAA,IACT,UAAA,EAAY,qCAAA;AAAA,IACZ,UAAA,EAAY,qCAAA;AAAA,IACZ,mBAAmB,mBAAA,CAAoB;AAAA,GACzC;AAAA,EACA,OAAA,EAAS;AAAA,IACP,OAAA,EAAS,SAAA;AAAA,IACT,UAAA,EAAY,6BAAA;AAAA,IACZ,UAAA,EAAY,6BAAA;AAAA,IACZ,mBAAmB,mBAAA,CAAoB;AAAA,GACzC;AAAA,EACA,SAAA,EAAW;AAAA,IACT,OAAA,EAAS,WAAA;AAAA,IACT,UAAA,EAAY,uCAAA;AAAA,IACZ,UAAA,EAAY,mCAAA;AAAA,IACZ,mBAAmB,mBAAA,CAAoB;AAAA;AAE3C,CAAA;;;ACdO,IAAM,mBAAA,0BAA2D,yBAAyB,CAAA;AAEjG,IAAM,mBAAA,GAAmC;AAAA,EACvC,SAAA,EAAW,KAAA;AAAA,EACX,UAAA,EAAY,KAAA;AAAA,EACZ,OAAA,EAAS,IAAA;AAAA,EACT,OAAA,EAAS,IAAA;AAAA,EACT,MAAA,EAAQ,IAAA;AAAA,EACR,UAAA,EAAY,IAAA;AAAA,EACZ,KAAA,EAAO,IAAA;AAAA,EACP,aAAA,EAAe,IAAA;AAAA,EACf,uBAAA,EAAyB;AAC3B,CAAA;AAEA,SAAS,oBAAA,CACP,SACA,QAAA,EACe;AACf,EAAA,MAAM,OAAA,GAAU,gBAAgB,OAAO,CAAA;AACvC,EAAA,IAAI,CAAC,UAAU,OAAO,OAAA;AAEtB,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,UAAA,EAAY,QAAA,CAAS,UAAA,IAAc,OAAA,CAAQ,UAAA;AAAA,IAC3C,UAAA,EAAY,QAAA,CAAS,UAAA,IAAc,OAAA,CAAQ,UAAA;AAAA,IAC3C,iBAAA,EAAmB,QAAA,CAAS,iBAAA,IAAqB,OAAA,CAAQ;AAAA,GAC3D;AACF;AAOO,SAAS,oBAAA,CAAqB,OAAA,GAAgC,EAAC,EAAmB;AACvF,EAAA,MAAM,OAAA,GAAU,QAAQ,OAAA,IAAW,SAAA;AACnC,EAAA,MAAM,aAAA,GAAgBA,cAAA,CAAW,OAAA,CAAQ,aAAA,IAAiB,IAAI,CAAA;AAE9D,EAAA,MAAM,OAAA,GAA0B;AAAA,IAC9B,OAAA;AAAA,IACA,aAAA,EAAe,oBAAA,CAAqB,OAAA,EAAS,OAAA,CAAQ,aAAa,CAAA;AAAA,IAClE,UAAA,EAAY,IAAIC,eAAA,CAAW,OAAA,CAAQ,WAAW,CAAA;AAAA,IAC9C,QAAQ,EAAE,GAAG,qBAAqB,OAAA,EAAS,OAAA,CAAQ,iBAAiB,IAAA,EAAK;AAAA,IACzE,UAAU,MAAA,EAAc;AACtB,MAAA,OAAA,CAAQ,MAAA,GAAS,MAAA;AACjB,MAAA,aAAA,CAAc,QAAQ,MAAA,CAAO,OAAA;AAAA,IAC/B,CAAA;AAAA,IACA,aAAA;AAAA,IACA,iBAAiB,OAAA,EAA8B;AAC7C,MAAA,aAAA,CAAc,KAAA,GAAQ,OAAA;AAAA,IACxB;AAAA,GACF;AACA,EAAA,OAAO,OAAA;AACT;;;ACjDO,SAAS,wBAAA,CAAyB,OAAA,GAAgC,EAAC,EAAuB;AAC/F,EAAA,MAAM,OAAA,GAAU,qBAAqB,OAAO,CAAA;AAC5C,EAAA,MAAM,GAAA,GAAMC,aAAA,CAAU,EAAE,CAAA;AACxB,EAAA,GAAA,CAAI,OAAA,CAAQ,qBAAqB,OAAO,CAAA;AAExC,EAAA,MAAM,QAAqBC,eAAA,EAAY;AAEvC,EAAA,SAAS,IAAO,EAAA,EAAgB;AAC9B,IAAA,OAAO,MAAM,GAAA,CAAI,MAAM,GAAA,CAAI,cAAA,CAAe,EAAE,CAAC,CAAA;AAAA,EAC/C;AAEA,EAAA,OAAO;AAAA,IACL,GAAA;AAAA,IACA,OAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA,EAAS,MAAM,KAAA,CAAM,IAAA;AAAK,GAC5B;AACF","file":"test-utils.js","sourcesContent":["// packages/vue/src/types.ts\n//\n// A small, self-contained type set for the Vue adapter. Deliberately not\n// imported from the `use-stellar` (React) package: that package declares\n// `react` as a required peer dependency, and pulling any part of it in here\n// would put a React peer-dependency warning in front of every Vue user who\n// installs this package — the exact installation friction `rn-03` fixed for\n// React Native. Custom networks aren't supported yet; only the three SDF\n// defaults are.\n\nexport type StellarNetwork = \"testnet\" | \"mainnet\" | \"futurenet\"\n\nexport interface NetworkConfig {\n network: StellarNetwork\n horizonUrl: string\n sorobanUrl: string\n networkPassphrase: string\n}\n\nexport type Asset = \"XLM\" | { code: string; issuer: string }\n\nexport type Balance =\n | { asset: \"XLM\"; balance: string }\n | { asset: { code: string; issuer: string }; balance: string; limit?: string }\n | { asset: \"liquidity_pool_shares\"; balance: string; liquidityPoolId: string }\n\nconst NETWORK_PASSPHRASES: Record<StellarNetwork, string> = {\n testnet: \"Test SDF Network ; September 2015\",\n mainnet: \"Public Global Stellar Network ; September 2015\",\n futurenet: \"Test SDF Future Network ; October 2022\",\n}\n\nexport const NETWORK_CONFIGS: Record<StellarNetwork, NetworkConfig> = {\n testnet: {\n network: \"testnet\",\n horizonUrl: \"https://horizon-testnet.stellar.org\",\n sorobanUrl: \"https://soroban-testnet.stellar.org\",\n networkPassphrase: NETWORK_PASSPHRASES.testnet,\n },\n mainnet: {\n network: \"mainnet\",\n horizonUrl: \"https://horizon.stellar.org\",\n sorobanUrl: \"https://soroban.stellar.org\",\n networkPassphrase: NETWORK_PASSPHRASES.mainnet,\n },\n futurenet: {\n network: \"futurenet\",\n horizonUrl: \"https://horizon-futurenet.stellar.org\",\n sorobanUrl: \"https://rpc-futurenet.stellar.org\",\n networkPassphrase: NETWORK_PASSPHRASES.futurenet,\n },\n}\n","// packages/vue/src/plugin.ts\n\nimport { inject, shallowRef, type App, type InjectionKey, type Ref } from \"vue\"\nimport {\n QueryStore,\n getWalletAdapter,\n readWalletSession,\n type QueryConfig,\n type WalletState,\n} from \"use-stellar/core\"\nimport { NETWORK_CONFIGS, type NetworkConfig, type StellarNetwork } from \"./types\"\n\nexport interface StellarPluginOptions {\n /** Defaults to `\"testnet\"`. */\n network?: StellarNetwork\n /** Override the built-in Horizon/Soroban endpoints for `network`. Any field left out keeps the default. */\n networkConfig?: Partial<Pick<NetworkConfig, \"horizonUrl\" | \"sorobanUrl\" | \"networkPassphrase\">>\n /** Cache configuration shared by every composable. */\n queryConfig?: QueryConfig\n /** Initial connected wallet address, primarily for restored client sessions. */\n walletAddress?: string | null\n}\n\nexport interface StellarRuntime {\n network: StellarNetwork\n networkConfig: NetworkConfig\n /** One query cache per app, shared by every composable. */\n queryStore: QueryStore\n /** The wallet connection the write composables sign with. */\n wallet: WalletState\n /** Replaces the wallet state, and keeps `walletAddress` in step with it. */\n setWallet: (wallet: WalletState) => void\n /** The address read composables default to when given none. */\n walletAddress: Ref<string | null>\n setWalletAddress: (address: string | null) => void\n}\n\nexport const STELLAR_RUNTIME_KEY: InjectionKey<StellarRuntime> = Symbol(\"use-stellar/vue:runtime\")\n\nconst DISCONNECTED_WALLET: WalletState = {\n connected: false,\n connecting: false,\n address: null,\n network: null,\n wallet: null,\n walletName: null,\n error: null,\n walletNetwork: null,\n walletNetworkPassphrase: null,\n}\n\nfunction resolveNetworkConfig(\n network: StellarNetwork,\n override: StellarPluginOptions[\"networkConfig\"]\n): NetworkConfig {\n const builtIn = NETWORK_CONFIGS[network]\n if (!override) return builtIn\n\n return {\n network,\n horizonUrl: override.horizonUrl ?? builtIn.horizonUrl,\n sorobanUrl: override.sorobanUrl ?? builtIn.sorobanUrl,\n networkPassphrase: override.networkPassphrase ?? builtIn.networkPassphrase,\n }\n}\n\n/**\n * Builds a Stellar runtime without installing it as a plugin. Used by\n * {@link createStellarPlugin} itself, and by the test harness in\n * `use-stellar/vue/test-utils` to provide a runtime without a real app.\n */\nexport function createStellarRuntime(options: StellarPluginOptions = {}): StellarRuntime {\n const network = options.network ?? \"testnet\"\n const walletAddress = shallowRef(options.walletAddress ?? null)\n\n const runtime: StellarRuntime = {\n network,\n networkConfig: resolveNetworkConfig(network, options.networkConfig),\n queryStore: new QueryStore(options.queryConfig),\n wallet: { ...DISCONNECTED_WALLET, address: options.walletAddress ?? null },\n setWallet(wallet): void {\n runtime.wallet = wallet\n walletAddress.value = wallet.address\n },\n walletAddress,\n setWalletAddress(address: string | null): void {\n walletAddress.value = address\n },\n }\n return runtime\n}\n\n/** Restores a persisted wallet without ever prompting during server rendering. */\nexport async function restoreWalletSession(\n runtime: StellarRuntime,\n storage: \"local\" | \"session\" = \"local\"\n): Promise<void> {\n const session = await readWalletSession(storage)\n if (!session) return\n\n try {\n const adapter = getWalletAdapter(session.wallet)\n const available = await adapter.isAvailable()\n if (!available) return\n\n const canReconnect = adapter.canAutoConnect\n ? await adapter.canAutoConnect(runtime.network)\n : false\n if (!canReconnect) {\n runtime.setWallet({\n ...runtime.wallet,\n wallet: session.wallet,\n walletName: adapter.metadata.name,\n address: session.address ?? null,\n })\n return\n }\n\n const connection = await adapter.connect(runtime.network)\n const network = await adapter.getNetworkDetails(runtime.network)\n runtime.setWallet({\n connected: true,\n connecting: false,\n address: connection.address,\n network: runtime.network,\n wallet: connection.wallet,\n walletName: adapter.metadata.name,\n error: null,\n walletNetwork: network.network,\n walletNetworkPassphrase: network.networkPassphrase,\n })\n } catch {\n // Session restoration is best-effort; a normal disconnected app remains usable.\n }\n}\n\n/**\n * Vue plugin that installs the Stellar runtime — resolved network config plus\n * one shared query cache — so every composable in this package reads and\n * writes through the same instance.\n *\n * @example\n * import { createApp } from \"vue\"\n * import { createStellarPlugin } from \"@use-stellar/vue\"\n *\n * createApp(App).use(createStellarPlugin({ network: \"testnet\" })).mount(\"#app\")\n */\nexport function createStellarPlugin(options: StellarPluginOptions = {}) {\n return {\n install(app: App): void {\n app.provide(STELLAR_RUNTIME_KEY, createStellarRuntime(options))\n },\n }\n}\n\n/**\n * Reads the installed Stellar runtime.\n *\n * @throws {Error} when called outside a component tree the plugin was\n * installed on (or outside `app.runWithContext()` in tests).\n */\nexport function useStellarRuntime(): StellarRuntime {\n const runtime = inject(STELLAR_RUNTIME_KEY)\n if (!runtime) {\n throw new Error(\n \"@use-stellar/vue: no plugin installed. Call \" +\n \"app.use(createStellarPlugin()) before using any composable.\"\n )\n }\n return runtime\n}\n","// packages/vue/src/test-utils.ts\n//\n// A reusable harness for testing this package's composables without a real\n// component tree: no DOM, no @vue/test-utils, no mounted app.\n//\n// Two Vue primitives make this possible together:\n// - `app.runWithContext(fn)` (Vue 3.3+) lets `inject()` resolve against the\n// app's provided values from outside a component's `setup()`.\n// - `effectScope()` gives every `watchEffect`/`computed` a lifecycle to\n// belong to, so `dispose()` actually tears them down — `runWithContext`\n// alone does not do this, since it only sets the injection context.\n//\n// Exported from a separate `@use-stellar/vue/test-utils` entry point so\n// `effectScope`/`createApp` test scaffolding never ends up in a consumer's\n// production bundle just because they imported the main package.\n\nimport { createApp, effectScope, type App, type EffectScope } from \"vue\"\nimport { STELLAR_RUNTIME_KEY, createStellarRuntime } from \"./plugin\"\nimport type { StellarPluginOptions, StellarRuntime } from \"./plugin\"\n\nexport interface StellarTestHarness {\n app: App\n /** The exact runtime instance provided to the app — same `QueryStore` every composable in `run()` reads through. */\n runtime: StellarRuntime\n /** Runs `fn` with the runtime available to `inject()` / composables, inside a disposable effect scope. */\n run: <T>(fn: () => T) => T\n /** Stops the effect scope, tearing down every watcher/computed created via `run()`. Call in `afterEach`. */\n dispose: () => void\n}\n\n/**\n * Mounts a throwaway Vue app with the Stellar plugin installed, for testing\n * composables that call `useStellarRuntime()` — directly, or through\n * `useBalance` and friends — with no real component tree.\n *\n * @example\n * const harness = createStellarTestHarness({ network: \"testnet\" })\n * const { balance } = harness.run(() => useBalance({ address: \"GABC...\" }))\n * // ...assert...\n * harness.dispose()\n */\nexport function createStellarTestHarness(options: StellarPluginOptions = {}): StellarTestHarness {\n const runtime = createStellarRuntime(options)\n const app = createApp({})\n app.provide(STELLAR_RUNTIME_KEY, runtime)\n\n const scope: EffectScope = effectScope()\n\n function run<T>(fn: () => T): T {\n return scope.run(() => app.runWithContext(fn)) as T\n }\n\n return {\n app,\n runtime,\n run,\n dispose: () => scope.stop(),\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { createStellarRuntime, STELLAR_RUNTIME_KEY } from './chunk-7ROX7ZPL.mjs';
2
+ import { createApp, effectScope } from 'vue';
3
+
4
+ function createStellarTestHarness(options = {}) {
5
+ const runtime = createStellarRuntime(options);
6
+ const app = createApp({});
7
+ app.provide(STELLAR_RUNTIME_KEY, runtime);
8
+ const scope = effectScope();
9
+ function run(fn) {
10
+ return scope.run(() => app.runWithContext(fn));
11
+ }
12
+ return {
13
+ app,
14
+ runtime,
15
+ run,
16
+ dispose: () => scope.stop()
17
+ };
18
+ }
19
+
20
+ export { createStellarTestHarness };
21
+ //# sourceMappingURL=test-utils.mjs.map
22
+ //# sourceMappingURL=test-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/test-utils.ts"],"names":[],"mappings":";;;AAyCO,SAAS,wBAAA,CAAyB,OAAA,GAAgC,EAAC,EAAuB;AAC/F,EAAA,MAAM,OAAA,GAAU,qBAAqB,OAAO,CAAA;AAC5C,EAAA,MAAM,GAAA,GAAM,SAAA,CAAU,EAAE,CAAA;AACxB,EAAA,GAAA,CAAI,OAAA,CAAQ,qBAAqB,OAAO,CAAA;AAExC,EAAA,MAAM,QAAqB,WAAA,EAAY;AAEvC,EAAA,SAAS,IAAO,EAAA,EAAgB;AAC9B,IAAA,OAAO,MAAM,GAAA,CAAI,MAAM,GAAA,CAAI,cAAA,CAAe,EAAE,CAAC,CAAA;AAAA,EAC/C;AAEA,EAAA,OAAO;AAAA,IACL,GAAA;AAAA,IACA,OAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA,EAAS,MAAM,KAAA,CAAM,IAAA;AAAK,GAC5B;AACF","file":"test-utils.mjs","sourcesContent":["// packages/vue/src/test-utils.ts\n//\n// A reusable harness for testing this package's composables without a real\n// component tree: no DOM, no @vue/test-utils, no mounted app.\n//\n// Two Vue primitives make this possible together:\n// - `app.runWithContext(fn)` (Vue 3.3+) lets `inject()` resolve against the\n// app's provided values from outside a component's `setup()`.\n// - `effectScope()` gives every `watchEffect`/`computed` a lifecycle to\n// belong to, so `dispose()` actually tears them down — `runWithContext`\n// alone does not do this, since it only sets the injection context.\n//\n// Exported from a separate `@use-stellar/vue/test-utils` entry point so\n// `effectScope`/`createApp` test scaffolding never ends up in a consumer's\n// production bundle just because they imported the main package.\n\nimport { createApp, effectScope, type App, type EffectScope } from \"vue\"\nimport { STELLAR_RUNTIME_KEY, createStellarRuntime } from \"./plugin\"\nimport type { StellarPluginOptions, StellarRuntime } from \"./plugin\"\n\nexport interface StellarTestHarness {\n app: App\n /** The exact runtime instance provided to the app — same `QueryStore` every composable in `run()` reads through. */\n runtime: StellarRuntime\n /** Runs `fn` with the runtime available to `inject()` / composables, inside a disposable effect scope. */\n run: <T>(fn: () => T) => T\n /** Stops the effect scope, tearing down every watcher/computed created via `run()`. Call in `afterEach`. */\n dispose: () => void\n}\n\n/**\n * Mounts a throwaway Vue app with the Stellar plugin installed, for testing\n * composables that call `useStellarRuntime()` — directly, or through\n * `useBalance` and friends — with no real component tree.\n *\n * @example\n * const harness = createStellarTestHarness({ network: \"testnet\" })\n * const { balance } = harness.run(() => useBalance({ address: \"GABC...\" }))\n * // ...assert...\n * harness.dispose()\n */\nexport function createStellarTestHarness(options: StellarPluginOptions = {}): StellarTestHarness {\n const runtime = createStellarRuntime(options)\n const app = createApp({})\n app.provide(STELLAR_RUNTIME_KEY, runtime)\n\n const scope: EffectScope = effectScope()\n\n function run<T>(fn: () => T): T {\n return scope.run(() => app.runWithContext(fn)) as T\n }\n\n return {\n app,\n runtime,\n run,\n dispose: () => scope.stop(),\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,135 @@
1
1
  {
2
2
  "name": "@use-stellar/vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.3",
4
+ "description": "Vue 3 composables for the Stellar network, built on use-stellar",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/RaceeyXo/use-stellar.git",
8
+ "directory": "packages/vue"
9
+ },
10
+ "homepage": "https://github.com/RaceeyXo/use-stellar/tree/main/packages/vue#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/RaceeyXo/use-stellar/issues"
13
+ },
14
+ "license": "Apache-2.0",
15
+ "main": "dist/index.js",
16
+ "module": "dist/index.mjs",
17
+ "types": "dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./dist/index.d.mts",
22
+ "default": "./dist/index.mjs"
23
+ },
24
+ "require": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "./test-utils": {
30
+ "import": {
31
+ "types": "./dist/test-utils.d.mts",
32
+ "default": "./dist/test-utils.mjs"
33
+ },
34
+ "require": {
35
+ "types": "./dist/test-utils.d.ts",
36
+ "default": "./dist/test-utils.js"
37
+ }
38
+ },
39
+ "./nuxt": {
40
+ "import": {
41
+ "types": "./dist/nuxt/module.d.mts",
42
+ "default": "./dist/nuxt/module.mjs"
43
+ },
44
+ "require": {
45
+ "types": "./dist/nuxt/module.d.ts",
46
+ "default": "./dist/nuxt/module.js"
47
+ }
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
51
+ "files": [
52
+ "dist"
53
+ ],
54
+ "engines": {
55
+ "node": ">=20"
56
+ },
57
+ "sideEffects": false,
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
+ "dependencies": {
62
+ "@stellar/stellar-sdk": "^12.0.0"
63
+ },
64
+ "peerDependencies": {
65
+ "@nuxt/kit": "^3.0.0 || ^4.0.0",
66
+ "vue": "^3.3.0",
67
+ "use-stellar": "^0.2.3"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "@nuxt/kit": {
71
+ "optional": true
72
+ }
73
+ },
74
+ "devDependencies": {
75
+ "@nuxt/kit": "^4.6.2",
76
+ "@size-limit/esbuild": "12.1.0",
77
+ "@size-limit/esbuild-why": "12.1.0",
78
+ "@size-limit/preset-small-lib": "^12.1.0",
79
+ "@types/jest": "^29.5.0",
80
+ "@types/node": "^20.0.0",
81
+ "@vue/server-renderer": "^3.5.0",
82
+ "jest": "^29.0.0",
83
+ "jest-environment-jsdom": "^29.0.0",
84
+ "size-limit": "^12.1.0",
85
+ "ts-jest": "^29.0.0",
86
+ "tsup": "^8.0.0",
87
+ "typescript": "^5.9.3",
88
+ "vue": "^3.5.0",
89
+ "use-stellar": "0.2.3"
90
+ },
91
+ "size-limit": [
92
+ {
93
+ "name": "Vue CommonJS bundle",
94
+ "path": "dist/index.js",
95
+ "limit": "15 kB",
96
+ "ignore": [
97
+ "@stellar/stellar-sdk",
98
+ "vue",
99
+ "use-stellar"
100
+ ]
101
+ },
102
+ {
103
+ "name": "Vue ES module bundle",
104
+ "path": "dist/index.mjs",
105
+ "limit": "11 kB",
106
+ "ignore": [
107
+ "@stellar/stellar-sdk",
108
+ "vue",
109
+ "use-stellar"
110
+ ]
111
+ }
112
+ ],
113
+ "keywords": [
114
+ "stellar",
115
+ "soroban",
116
+ "vue",
117
+ "vue3",
118
+ "nuxt",
119
+ "composables",
120
+ "blockchain",
121
+ "web3",
122
+ "xlm",
123
+ "usdc"
124
+ ],
125
+ "scripts": {
126
+ "build": "tsup",
127
+ "dev": "tsup --watch",
128
+ "test": "jest",
129
+ "test:watch": "jest --watch",
130
+ "test:package": "node scripts/smoke-test.js",
131
+ "typecheck": "tsc --noEmit",
132
+ "size": "size-limit",
133
+ "size:why": "size-limit --why"
134
+ }
6
135
  }