From ec673a7754cc802d090976ef80b932c4b72fde4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Mon, 25 Nov 2024 00:25:09 +1300 Subject: [PATCH] refactor(core): move actions to internal exports --- .changeset/kind-shrimps-tan.md | 7 ++ packages/core/package.json | 5 +- packages/core/src/actions/index.ts | 9 +++ packages/core/src/index.ts | 72 ++++++++++++++++--- packages/react/src/hooks/use-accounts.ts | 3 +- packages/react/src/hooks/use-block.ts | 3 +- packages/react/src/hooks/use-client.ts | 3 +- packages/react/src/hooks/use-query.ts | 10 +-- .../react/src/hooks/use-wallet-connector.ts | 2 +- .../src/hooks/use-wallet-disconnector.ts | 2 +- .../src/hooks/use-wallets-initializer.ts | 2 +- packages/react/src/hooks/use-wallets.ts | 4 +- packages/vue/src/composables/use-accounts.ts | 2 +- packages/vue/src/composables/use-block.ts | 2 +- packages/vue/src/composables/use-client.ts | 2 +- packages/vue/src/composables/use-query.ts | 11 ++- .../src/composables/use-wallet-connector.ts | 2 +- .../composables/use-wallet-disconnector.ts | 2 +- .../composables/use-wallets-initializer.ts | 2 +- packages/vue/src/composables/use-wallets.ts | 5 +- 20 files changed, 110 insertions(+), 40 deletions(-) create mode 100644 .changeset/kind-shrimps-tan.md create mode 100644 packages/core/src/actions/index.ts diff --git a/.changeset/kind-shrimps-tan.md b/.changeset/kind-shrimps-tan.md new file mode 100644 index 00000000..aa510408 --- /dev/null +++ b/.changeset/kind-shrimps-tan.md @@ -0,0 +1,7 @@ +--- +"@reactive-dot/react": patch +"@reactive-dot/core": patch +"@reactive-dot/vue": patch +--- + +Moved core actions to internal exports. diff --git a/packages/core/package.json b/packages/core/package.json index 4bf4936b..6ce5a7b4 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -26,8 +26,9 @@ "exports": { ".": "./build/index.js", "./wallets.js": "./build/wallets/index.js", - "./internal/maths.js": "./build/maths/index.js", - "./internal.js": "./build/internal.js" + "./internal.js": "./build/internal.js", + "./internal/actions.js": "./build/actions/index.js", + "./internal/maths.js": "./build/maths/index.js" }, "scripts": { "dev": "tsc --build --watch", diff --git a/packages/core/src/actions/index.ts b/packages/core/src/actions/index.ts new file mode 100644 index 00000000..0560d5c4 --- /dev/null +++ b/packages/core/src/actions/index.ts @@ -0,0 +1,9 @@ +export { aggregateWallets } from "./aggregate-wallets.js"; +export { connectWallet } from "./connect-wallet.js"; +export { disconnectWallet } from "./disconnect-wallet.js"; +export { getAccounts } from "./get-accounts.js"; +export { getBlock, unstable_getBlockExtrinsics } from "./get-block.js"; +export { getClient } from "./get-client.js"; +export { getConnectedWallets } from "./get-connected-wallets.js"; +export { initializeWallets } from "./initialize-wallets.js"; +export { preflight, query } from "./query.js"; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 5247b486..9fdb41c8 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,12 +1,3 @@ -export { aggregateWallets } from "./actions/aggregate-wallets.js"; -export { connectWallet } from "./actions/connect-wallet.js"; -export { disconnectWallet } from "./actions/disconnect-wallet.js"; -export { getAccounts } from "./actions/get-accounts.js"; -export { getBlock, unstable_getBlockExtrinsics } from "./actions/get-block.js"; -export { getClient } from "./actions/get-client.js"; -export { getConnectedWallets } from "./actions/get-connected-wallets.js"; -export { initializeWallets } from "./actions/initialize-wallets.js"; -export { preflight, query } from "./actions/query.js"; export type { AsyncValue } from "./async-state.js"; export type { ChainId } from "./chains.js"; export { defineConfig, type ChainConfig, type Config } from "./config.js"; @@ -15,3 +6,66 @@ export { Query } from "./query-builder.js"; export type { Register } from "./register.js"; export { Storage } from "./storage.js"; export { idle, pending } from "./symbols.js"; + +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + aggregateWallets, +} from "./actions/aggregate-wallets.js"; +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + connectWallet, +} from "./actions/connect-wallet.js"; +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + disconnectWallet, +} from "./actions/disconnect-wallet.js"; +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + getAccounts, +} from "./actions/get-accounts.js"; +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + getBlock, + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + unstable_getBlockExtrinsics, +} from "./actions/get-block.js"; +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + getClient, +} from "./actions/get-client.js"; +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + getConnectedWallets, +} from "./actions/get-connected-wallets.js"; +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + initializeWallets, +} from "./actions/initialize-wallets.js"; +export { + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + preflight, + /** + * @deprecated Use the "/internal/actions.js" subpath export instead. + */ + query, +} from "./actions/query.js"; diff --git a/packages/react/src/hooks/use-accounts.ts b/packages/react/src/hooks/use-accounts.ts index 4d45cb40..3f341df6 100644 --- a/packages/react/src/hooks/use-accounts.ts +++ b/packages/react/src/hooks/use-accounts.ts @@ -4,7 +4,8 @@ import { internal_useChainId } from "./use-chain-id.js"; import { chainSpecDataAtom } from "./use-chain-spec-data.js"; import { useConfig } from "./use-config.js"; import { connectedWalletsAtom } from "./use-wallets.js"; -import { getAccounts, type ChainId, type Config } from "@reactive-dot/core"; +import { type ChainId, type Config } from "@reactive-dot/core"; +import { getAccounts } from "@reactive-dot/core/internal/actions.js"; import { useAtomValue } from "jotai"; import { atomWithObservable } from "jotai/utils"; diff --git a/packages/react/src/hooks/use-block.ts b/packages/react/src/hooks/use-block.ts index 8d9a0324..27111327 100644 --- a/packages/react/src/hooks/use-block.ts +++ b/packages/react/src/hooks/use-block.ts @@ -3,7 +3,8 @@ import type { ChainHookOptions } from "./types.js"; import { internal_useChainId } from "./use-chain-id.js"; import { clientAtom } from "./use-client.js"; import { useConfig } from "./use-config.js"; -import { type ChainId, type Config, getBlock } from "@reactive-dot/core"; +import { type ChainId, type Config } from "@reactive-dot/core"; +import { getBlock } from "@reactive-dot/core/internal/actions.js"; import { useAtomValue } from "jotai"; import { atomWithObservable } from "jotai/utils"; import { from } from "rxjs"; diff --git a/packages/react/src/hooks/use-client.ts b/packages/react/src/hooks/use-client.ts index f34aba92..612a935c 100644 --- a/packages/react/src/hooks/use-client.ts +++ b/packages/react/src/hooks/use-client.ts @@ -3,7 +3,8 @@ import type { ChainHookOptions } from "./types.js"; import { internal_useChainId } from "./use-chain-id.js"; import { useConfig } from "./use-config.js"; import type { ChainId, Config } from "@reactive-dot/core"; -import { getClient, ReactiveDotError } from "@reactive-dot/core"; +import { ReactiveDotError } from "@reactive-dot/core"; +import { getClient } from "@reactive-dot/core/internal/actions.js"; import { useAtomValue } from "jotai"; import { atom } from "jotai"; diff --git a/packages/react/src/hooks/use-query.ts b/packages/react/src/hooks/use-query.ts index c526fe98..f57105a4 100644 --- a/packages/react/src/hooks/use-query.ts +++ b/packages/react/src/hooks/use-query.ts @@ -4,14 +4,7 @@ import { internal_useChainId } from "./use-chain-id.js"; import { useConfig } from "./use-config.js"; import { useQueryRefresher } from "./use-query-refresher.js"; import { typedApiAtom } from "./use-typed-api.js"; -import { - type ChainId, - type Config, - idle, - preflight, - query, - Query, -} from "@reactive-dot/core"; +import { type ChainId, type Config, idle, Query } from "@reactive-dot/core"; import { type ChainDescriptorOf, type Falsy, @@ -23,6 +16,7 @@ import { type QueryInstruction, stringify, } from "@reactive-dot/core/internal.js"; +import { preflight, query } from "@reactive-dot/core/internal/actions.js"; import { type Atom, atom, useAtomValue, type WritableAtom } from "jotai"; import { atomWithObservable, atomWithRefresh } from "jotai/utils"; import { useMemo } from "react"; diff --git a/packages/react/src/hooks/use-wallet-connector.ts b/packages/react/src/hooks/use-wallet-connector.ts index 28088803..c073248d 100644 --- a/packages/react/src/hooks/use-wallet-connector.ts +++ b/packages/react/src/hooks/use-wallet-connector.ts @@ -1,7 +1,7 @@ import { useAsyncAction } from "./use-async-action.js"; import { useConfig } from "./use-config.js"; import { walletsAtom } from "./use-wallets.js"; -import { connectWallet } from "@reactive-dot/core"; +import { connectWallet } from "@reactive-dot/core/internal/actions.js"; import type { Wallet } from "@reactive-dot/core/wallets.js"; import { useAtomCallback } from "jotai/utils"; import { useCallback } from "react"; diff --git a/packages/react/src/hooks/use-wallet-disconnector.ts b/packages/react/src/hooks/use-wallet-disconnector.ts index 50fc8cc4..48f94d7b 100644 --- a/packages/react/src/hooks/use-wallet-disconnector.ts +++ b/packages/react/src/hooks/use-wallet-disconnector.ts @@ -1,7 +1,7 @@ import { useAsyncAction } from "./use-async-action.js"; import { useConfig } from "./use-config.js"; import { walletsAtom } from "./use-wallets.js"; -import { disconnectWallet } from "@reactive-dot/core"; +import { disconnectWallet } from "@reactive-dot/core/internal/actions.js"; import type { Wallet } from "@reactive-dot/core/wallets.js"; import { useAtomCallback } from "jotai/utils"; import { useCallback } from "react"; diff --git a/packages/react/src/hooks/use-wallets-initializer.ts b/packages/react/src/hooks/use-wallets-initializer.ts index 0a63bf74..588c93ce 100644 --- a/packages/react/src/hooks/use-wallets-initializer.ts +++ b/packages/react/src/hooks/use-wallets-initializer.ts @@ -1,11 +1,11 @@ import { useWallets } from "./use-wallets.js"; import { idle, - initializeWallets, pending, type AsyncValue, type ReactiveDotError, } from "@reactive-dot/core"; +import { initializeWallets } from "@reactive-dot/core/internal/actions.js"; import { useCallback, useState } from "react"; /** diff --git a/packages/react/src/hooks/use-wallets.ts b/packages/react/src/hooks/use-wallets.ts index 4d20ccc9..1cd0fa99 100644 --- a/packages/react/src/hooks/use-wallets.ts +++ b/packages/react/src/hooks/use-wallets.ts @@ -1,10 +1,10 @@ import { atomFamilyWithErrorCatcher } from "../utils/jotai.js"; import { useConfig } from "./use-config.js"; +import type { Config } from "@reactive-dot/core"; import { aggregateWallets, - type Config, getConnectedWallets, -} from "@reactive-dot/core"; +} from "@reactive-dot/core/internal/actions.js"; import { atom, useAtomValue } from "jotai"; import { atomWithObservable } from "jotai/utils"; diff --git a/packages/vue/src/composables/use-accounts.ts b/packages/vue/src/composables/use-accounts.ts index c9a0cfdd..9be0fc0c 100644 --- a/packages/vue/src/composables/use-accounts.ts +++ b/packages/vue/src/composables/use-accounts.ts @@ -4,7 +4,7 @@ import { internal_useChainId } from "./use-chain-id.js"; import { useChainSpecDataPromise } from "./use-chain-spec-data.js"; import { useLazyValue } from "./use-lazy-value.js"; import { useConnectedWalletsObservable } from "./use-wallets.js"; -import { getAccounts } from "@reactive-dot/core"; +import { getAccounts } from "@reactive-dot/core/internal/actions.js"; import { computed } from "vue"; /** diff --git a/packages/vue/src/composables/use-block.ts b/packages/vue/src/composables/use-block.ts index e001bf74..eaa0f349 100644 --- a/packages/vue/src/composables/use-block.ts +++ b/packages/vue/src/composables/use-block.ts @@ -3,7 +3,7 @@ import { useAsyncData } from "./use-async-data.js"; import { internal_useChainId } from "./use-chain-id.js"; import { useClientPromise } from "./use-client.js"; import { useLazyValue } from "./use-lazy-value.js"; -import { getBlock } from "@reactive-dot/core"; +import { getBlock } from "@reactive-dot/core/internal/actions.js"; import { from, switchMap } from "rxjs"; import { computed, type MaybeRefOrGetter, toValue } from "vue"; diff --git a/packages/vue/src/composables/use-client.ts b/packages/vue/src/composables/use-client.ts index 6d75353b..b53262cf 100644 --- a/packages/vue/src/composables/use-client.ts +++ b/packages/vue/src/composables/use-client.ts @@ -3,7 +3,7 @@ import { useAsyncData } from "./use-async-data.js"; import { internal_useChainId } from "./use-chain-id.js"; import { useChainConfig } from "./use-config.js"; import { useLazyValue } from "./use-lazy-value.js"; -import { getClient } from "@reactive-dot/core"; +import { getClient } from "@reactive-dot/core/internal/actions.js"; import { computed, toValue } from "vue"; /** diff --git a/packages/vue/src/composables/use-query.ts b/packages/vue/src/composables/use-query.ts index 0469dec2..f2d7f9e3 100644 --- a/packages/vue/src/composables/use-query.ts +++ b/packages/vue/src/composables/use-query.ts @@ -8,12 +8,7 @@ import { useAsyncData } from "./use-async-data.js"; import { internal_useChainId } from "./use-chain-id.js"; import { lazyValue, useLazyValuesCache } from "./use-lazy-value.js"; import { useTypedApiPromise } from "./use-typed-api.js"; -import { - type ChainId, - query as executeQuery, - preflight, - Query, -} from "@reactive-dot/core"; +import { type ChainId, Query } from "@reactive-dot/core"; import { type ChainDescriptorOf, type Falsy, @@ -24,6 +19,10 @@ import { type QueryInstruction, stringify, } from "@reactive-dot/core/internal.js"; +import { + query as executeQuery, + preflight, +} from "@reactive-dot/core/internal/actions.js"; import type { ChainDefinition, TypedApi } from "polkadot-api"; import { combineLatest, from, type Observable, of } from "rxjs"; import { map, switchMap } from "rxjs/operators"; diff --git a/packages/vue/src/composables/use-wallet-connector.ts b/packages/vue/src/composables/use-wallet-connector.ts index e60bae8a..cb000f03 100644 --- a/packages/vue/src/composables/use-wallet-connector.ts +++ b/packages/vue/src/composables/use-wallet-connector.ts @@ -1,6 +1,6 @@ import { useAsyncAction } from "./use-async-action.js"; import { useWalletsPromise } from "./use-wallets.js"; -import { connectWallet } from "@reactive-dot/core"; +import { connectWallet } from "@reactive-dot/core/internal/actions.js"; import type { Wallet } from "@reactive-dot/core/wallets.js"; /** diff --git a/packages/vue/src/composables/use-wallet-disconnector.ts b/packages/vue/src/composables/use-wallet-disconnector.ts index 1a59b816..8293bbd2 100644 --- a/packages/vue/src/composables/use-wallet-disconnector.ts +++ b/packages/vue/src/composables/use-wallet-disconnector.ts @@ -1,6 +1,6 @@ import { useAsyncAction } from "./use-async-action.js"; import { useConnectedWalletsObservable } from "./use-wallets.js"; -import { disconnectWallet } from "@reactive-dot/core"; +import { disconnectWallet } from "@reactive-dot/core/internal/actions.js"; import type { Wallet } from "@reactive-dot/core/wallets.js"; import { firstValueFrom } from "rxjs"; diff --git a/packages/vue/src/composables/use-wallets-initializer.ts b/packages/vue/src/composables/use-wallets-initializer.ts index 184fa2ba..292d9209 100644 --- a/packages/vue/src/composables/use-wallets-initializer.ts +++ b/packages/vue/src/composables/use-wallets-initializer.ts @@ -1,6 +1,6 @@ import { useAsyncAction } from "./use-async-action.js"; import { useWalletsPromise } from "./use-wallets.js"; -import { initializeWallets } from "@reactive-dot/core"; +import { initializeWallets } from "@reactive-dot/core/internal/actions.js"; /** * Composable for initializing wallets. diff --git a/packages/vue/src/composables/use-wallets.ts b/packages/vue/src/composables/use-wallets.ts index d22bfd57..60f8ca0c 100644 --- a/packages/vue/src/composables/use-wallets.ts +++ b/packages/vue/src/composables/use-wallets.ts @@ -1,7 +1,10 @@ import { useAsyncData } from "./use-async-data.js"; import { useConfig } from "./use-config.js"; import { useLazyValue } from "./use-lazy-value.js"; -import { aggregateWallets, getConnectedWallets } from "@reactive-dot/core"; +import { + aggregateWallets, + getConnectedWallets, +} from "@reactive-dot/core/internal/actions.js"; /** * Composable for getting all available wallets.