@opendatalabs/vana-sdk 0.1.0-alpha.fd33fc9 → 2.0.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.
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +33 -1
- package/dist/browser.js.map +1 -1
- package/dist/chains/index.cjs.map +1 -1
- package/dist/chains/index.d.ts +30 -1
- package/dist/chains/index.js.map +1 -1
- package/dist/client/__tests__/enhancedResponse.test.d.ts +1 -0
- package/dist/client/enhancedResponse.cjs +164 -0
- package/dist/client/enhancedResponse.cjs.map +1 -0
- package/dist/client/enhancedResponse.d.ts +120 -0
- package/dist/client/enhancedResponse.js +138 -0
- package/dist/client/enhancedResponse.js.map +1 -0
- package/dist/config/chains.cjs.map +1 -1
- package/dist/config/chains.d.ts +99 -0
- package/dist/config/chains.js.map +1 -1
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +66 -10
- package/dist/contracts/contractController.js.map +1 -1
- package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
- package/dist/controllers/__tests__/operations.processQueue.test.d.ts +1 -0
- package/dist/controllers/base.cjs +33 -0
- package/dist/controllers/base.cjs.map +1 -1
- package/dist/controllers/base.d.ts +10 -0
- package/dist/controllers/base.js +33 -0
- package/dist/controllers/base.js.map +1 -1
- package/dist/controllers/data.cjs +417 -276
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +246 -193
- package/dist/controllers/data.js +430 -279
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/operations.cjs +430 -0
- package/dist/controllers/operations.cjs.map +1 -0
- package/dist/controllers/operations.d.ts +229 -0
- package/dist/controllers/operations.js +406 -0
- package/dist/controllers/operations.js.map +1 -0
- package/dist/controllers/permissions.cjs +690 -209
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +196 -68
- package/dist/controllers/permissions.js +690 -209
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +27 -28
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +104 -25
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +88 -40
- package/dist/controllers/schemas.js +104 -25
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server.cjs +269 -58
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +157 -52
- package/dist/controllers/server.js +269 -58
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/__tests__/health.test.d.ts +1 -0
- package/dist/core/__tests__/inMemoryNonceManager.test.d.ts +1 -0
- package/dist/core/__tests__/nonceManager.test.d.ts +1 -0
- package/dist/core/__tests__/pollingManager.test.d.ts +4 -0
- package/dist/core/apiClient.cjs +53 -3
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +132 -7
- package/dist/core/apiClient.js +53 -3
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/generics.cjs +30 -3
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +95 -6
- package/dist/core/generics.js +30 -3
- package/dist/core/generics.js.map +1 -1
- package/dist/core/health.cjs +289 -0
- package/dist/core/health.cjs.map +1 -0
- package/dist/core/health.d.ts +143 -0
- package/dist/core/health.js +265 -0
- package/dist/core/health.js.map +1 -0
- package/dist/core/inMemoryNonceManager.cjs +138 -0
- package/dist/core/inMemoryNonceManager.cjs.map +1 -0
- package/dist/core/inMemoryNonceManager.d.ts +69 -0
- package/dist/core/inMemoryNonceManager.js +114 -0
- package/dist/core/inMemoryNonceManager.js.map +1 -0
- package/dist/core/nonceManager.cjs +304 -0
- package/dist/core/nonceManager.cjs.map +1 -0
- package/dist/core/nonceManager.d.ts +116 -0
- package/dist/core/nonceManager.js +280 -0
- package/dist/core/nonceManager.js.map +1 -0
- package/dist/core/pollingManager.cjs +292 -0
- package/dist/core/pollingManager.cjs.map +1 -0
- package/dist/core/pollingManager.d.ts +120 -0
- package/dist/core/pollingManager.js +268 -0
- package/dist/core/pollingManager.js.map +1 -0
- package/dist/core.cjs +55 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +54 -3
- package/dist/core.js +55 -1
- package/dist/core.js.map +1 -1
- package/dist/crypto/ecies/base.cjs +16 -3
- package/dist/crypto/ecies/base.cjs.map +1 -1
- package/dist/crypto/ecies/base.js +16 -3
- package/dist/crypto/ecies/base.js.map +1 -1
- package/dist/errors.cjs +29 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +28 -0
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DLPPerformanceImplementation.cjs +42 -0
- package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +32 -0
- package/dist/generated/abi/DLPPerformanceImplementation.js +42 -0
- package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRegistryImplementation.cjs +5 -5
- package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +4 -4
- package/dist/generated/abi/DLPRegistryImplementation.js +5 -5
- package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +166 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +129 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.js +166 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +167 -19
- package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +127 -14
- package/dist/generated/abi/DataPortabilityGranteesImplementation.js +167 -19
- package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +0 -19
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +0 -14
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +0 -19
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs +0 -19
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +0 -14
- package/dist/generated/abi/DataPortabilityServersImplementation.js +0 -19
- package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.cjs +0 -13
- package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.d.ts +0 -10
- package/dist/generated/abi/DataRegistryImplementation.js +0 -13
- package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/SwapHelperImplementation.cjs +0 -43
- package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -1
- package/dist/generated/abi/SwapHelperImplementation.d.ts +0 -35
- package/dist/generated/abi/SwapHelperImplementation.js +0 -43
- package/dist/generated/abi/SwapHelperImplementation.js.map +1 -1
- package/dist/generated/abi/VanaEpochImplementation.cjs +195 -0
- package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaEpochImplementation.d.ts +151 -0
- package/dist/generated/abi/VanaEpochImplementation.js +195 -0
- package/dist/generated/abi/VanaEpochImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolEntityImplementation.cjs +22 -65
- package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +17 -51
- package/dist/generated/abi/VanaPoolEntityImplementation.js +22 -65
- package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.cjs +113 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +85 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.js +113 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
- package/dist/generated/abi/index.d.ts +546 -146
- package/dist/generated/event-types.cjs.map +1 -1
- package/dist/generated/event-types.d.ts +14 -8
- package/dist/generated/eventRegistry.cjs +42 -18
- package/dist/generated/eventRegistry.cjs.map +1 -1
- package/dist/generated/eventRegistry.js +42 -18
- package/dist/generated/eventRegistry.js.map +1 -1
- package/dist/generated/server/server-exports.cjs +22 -0
- package/dist/generated/server/server-exports.cjs.map +1 -1
- package/dist/generated/server/server-exports.d.ts +27 -10
- package/dist/generated/server/server-exports.js +17 -0
- package/dist/generated/server/server-exports.js.map +1 -1
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +771 -402
- package/dist/generated/subgraph.cjs +797 -32
- package/dist/generated/subgraph.cjs.map +1 -1
- package/dist/generated/subgraph.d.ts +135 -0
- package/dist/generated/subgraph.js +792 -32
- package/dist/generated/subgraph.js.map +1 -1
- package/dist/index.browser.d.ts +2 -0
- package/dist/index.browser.js +10 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +26 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +49 -5
- package/dist/index.node.js +25 -1
- package/dist/index.node.js.map +1 -1
- package/dist/lib/__tests__/redisAtomicStore.test.d.ts +1 -0
- package/dist/lib/redisAtomicStore.cjs +201 -0
- package/dist/lib/redisAtomicStore.cjs.map +1 -0
- package/dist/lib/redisAtomicStore.d.ts +120 -0
- package/dist/lib/redisAtomicStore.js +177 -0
- package/dist/lib/redisAtomicStore.js.map +1 -0
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +39 -1
- package/dist/node.js.map +1 -1
- package/dist/platform/browser.cjs +160 -2
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +232 -12
- package/dist/platform/browser.js +160 -2
- package/dist/platform/browser.js.map +1 -1
- package/dist/platform/interface.cjs.map +1 -1
- package/dist/platform/interface.d.ts +283 -90
- package/dist/platform/node.cjs +163 -2
- package/dist/platform/node.cjs.map +1 -1
- package/dist/platform/node.d.ts +69 -6
- package/dist/platform/node.js +163 -2
- package/dist/platform/node.js.map +1 -1
- package/dist/server/relayerHandler.cjs +315 -81
- package/dist/server/relayerHandler.cjs.map +1 -1
- package/dist/server/relayerHandler.d.ts +35 -2
- package/dist/server/relayerHandler.js +315 -81
- package/dist/server/relayerHandler.js.map +1 -1
- package/dist/storage/index.cjs +3 -0
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/manager.cjs +108 -25
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +119 -25
- package/dist/storage/manager.js +108 -25
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +86 -15
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +109 -20
- package/dist/storage/providers/callback-storage.js +86 -15
- package/dist/storage/providers/callback-storage.js.map +1 -1
- package/dist/storage/providers/dropbox.cjs +237 -0
- package/dist/storage/providers/dropbox.cjs.map +1 -0
- package/dist/storage/providers/dropbox.d.ts +39 -0
- package/dist/storage/providers/dropbox.js +215 -0
- package/dist/storage/providers/dropbox.js.map +1 -0
- package/dist/storage/providers/dropbox.test.d.ts +1 -0
- package/dist/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.d.ts +12 -14
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/tests/data-upload-owner-validation.test.d.ts +1 -0
- package/dist/tests/permissions-transaction-options.test.d.ts +1 -0
- package/dist/types/atomicStore.cjs +31 -0
- package/dist/types/atomicStore.cjs.map +1 -0
- package/dist/types/atomicStore.d.ts +236 -0
- package/dist/types/atomicStore.js +7 -0
- package/dist/types/atomicStore.js.map +1 -0
- package/dist/types/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +39 -11
- package/dist/types/chains.cjs.map +1 -1
- package/dist/types/chains.d.ts +74 -7
- package/dist/types/chains.js.map +1 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +38 -4
- package/dist/types/config.js.map +1 -1
- package/dist/types/contracts.cjs.map +1 -1
- package/dist/types/contracts.d.ts +71 -7
- package/dist/types/controller-context.cjs.map +1 -1
- package/dist/types/controller-context.d.ts +4 -1
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +11 -10
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +81 -10
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +31 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/operationStore.cjs +17 -0
- package/dist/types/operationStore.cjs.map +1 -0
- package/dist/types/operationStore.d.ts +171 -0
- package/dist/types/operationStore.js +1 -0
- package/dist/types/operationStore.js.map +1 -0
- package/dist/types/operations.cjs +3 -15
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +131 -39
- package/dist/types/operations.js +2 -13
- package/dist/types/operations.js.map +1 -1
- package/dist/types/options.cjs +17 -0
- package/dist/types/options.cjs.map +1 -0
- package/dist/types/options.d.ts +308 -0
- package/dist/types/options.js +1 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/permissions.cjs.map +1 -1
- package/dist/types/permissions.d.ts +19 -20
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +150 -14
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +145 -24
- package/dist/types/storage.cjs.map +1 -1
- package/dist/types/storage.d.ts +9 -21
- package/dist/types/storage.js.map +1 -1
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +0 -45
- package/dist/utils/__tests__/chainQuery.test.d.ts +1 -0
- package/dist/utils/__tests__/subgraphConsistency.test.d.ts +4 -0
- package/dist/utils/__tests__/subgraphPagination.test.d.ts +4 -0
- package/dist/utils/chainQuery.cjs +107 -0
- package/dist/utils/chainQuery.cjs.map +1 -0
- package/dist/utils/chainQuery.d.ts +31 -0
- package/dist/utils/chainQuery.js +82 -0
- package/dist/utils/chainQuery.js.map +1 -0
- package/dist/utils/grantFiles.cjs +4 -1
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.d.ts +10 -20
- package/dist/utils/grantFiles.js +4 -1
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +95 -16
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +93 -12
- package/dist/utils/grants.js.map +1 -1
- package/dist/utils/ipfs.cjs +2 -4
- package/dist/utils/ipfs.cjs.map +1 -1
- package/dist/utils/ipfs.d.ts +1 -1
- package/dist/utils/ipfs.js +2 -4
- package/dist/utils/ipfs.js.map +1 -1
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +32 -7
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/signatureCache.cjs +8 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +49 -8
- package/dist/utils/signatureCache.js +8 -2
- package/dist/utils/signatureCache.js.map +1 -1
- package/dist/utils/subgraphConsistency.cjs +184 -0
- package/dist/utils/subgraphConsistency.cjs.map +1 -0
- package/dist/utils/subgraphConsistency.d.ts +65 -0
- package/dist/utils/subgraphConsistency.js +155 -0
- package/dist/utils/subgraphConsistency.js.map +1 -0
- package/dist/utils/subgraphMetaCache.cjs +101 -0
- package/dist/utils/subgraphMetaCache.cjs.map +1 -0
- package/dist/utils/subgraphMetaCache.d.ts +56 -0
- package/dist/utils/subgraphMetaCache.js +76 -0
- package/dist/utils/subgraphMetaCache.js.map +1 -0
- package/dist/utils/subgraphPagination.cjs +104 -0
- package/dist/utils/subgraphPagination.cjs.map +1 -0
- package/dist/utils/subgraphPagination.d.ts +78 -0
- package/dist/utils/subgraphPagination.js +78 -0
- package/dist/utils/subgraphPagination.js.map +1 -0
- package/dist/utils/transactionHelpers.cjs.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +12 -12
- package/dist/utils/transactionHelpers.js.map +1 -1
- package/dist/utils/typedDataConverter.cjs.map +1 -1
- package/dist/utils/typedDataConverter.d.ts +39 -3
- package/dist/utils/typedDataConverter.js.map +1 -1
- package/dist/utils/urlResolver.cjs +7 -0
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +22 -4
- package/dist/utils/urlResolver.js +7 -0
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs.map +1 -1
- package/dist/utils/wallet.d.ts +78 -16
- package/dist/utils/wallet.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Utilities for handling paginated subgraph queries
|
|
3
|
+
* @module vana-sdk/utils/subgraphPagination
|
|
4
|
+
*/
|
|
5
|
+
import { type DocumentNode } from "graphql";
|
|
6
|
+
import type { PaginationOptions } from "../types/options";
|
|
7
|
+
/**
|
|
8
|
+
* Generic subgraph response structure
|
|
9
|
+
*/
|
|
10
|
+
export interface SubgraphResponse<T> {
|
|
11
|
+
data?: T;
|
|
12
|
+
errors?: Array<{
|
|
13
|
+
message: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for paginated subgraph queries
|
|
18
|
+
*/
|
|
19
|
+
export interface PaginatedQueryConfig<TData, TItem, TRawItem = any> {
|
|
20
|
+
/** The GraphQL endpoint URL */
|
|
21
|
+
endpoint: string;
|
|
22
|
+
/** The GraphQL document to execute */
|
|
23
|
+
document: DocumentNode;
|
|
24
|
+
/** Base variables for the query (e.g., userId) */
|
|
25
|
+
baseVariables: Record<string, any>;
|
|
26
|
+
/** Pagination options from the user */
|
|
27
|
+
options?: PaginationOptions;
|
|
28
|
+
/** Function to extract items from the response */
|
|
29
|
+
extractItems: (data: TData) => TRawItem[] | undefined;
|
|
30
|
+
/** Function to transform items if needed */
|
|
31
|
+
transformItem?: (item: TRawItem) => TItem;
|
|
32
|
+
/** Maximum items per GraphQL query (default: 1000) */
|
|
33
|
+
maxPerQuery?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Generic paginated query executor for subgraph queries
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Handles pagination, fetchAll, and proper GraphQL query construction.
|
|
40
|
+
* Abstracts the common pattern of paginated subgraph queries.
|
|
41
|
+
*
|
|
42
|
+
* @param config - Configuration for the paginated query
|
|
43
|
+
* @returns Array of items from all pages
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const files = await executePaginatedQuery({
|
|
48
|
+
* endpoint: subgraphUrl,
|
|
49
|
+
* document: GetUserFilesPaginatedDocument,
|
|
50
|
+
* baseVariables: { userId: owner.toLowerCase() },
|
|
51
|
+
* options: { limit: 50, orderBy: 'addedAtBlock' },
|
|
52
|
+
* extractItems: (data) => data?.user?.files,
|
|
53
|
+
* transformItem: (file) => ({
|
|
54
|
+
* id: parseInt(file.id),
|
|
55
|
+
* url: file.url,
|
|
56
|
+
* // ... transform to UserFile
|
|
57
|
+
* })
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function executePaginatedQuery<TData, TItem, TRawItem = any>(config: PaginatedQueryConfig<TData, TItem, TRawItem>): Promise<TItem[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Helper to map string orderBy values to GraphQL enums
|
|
64
|
+
*
|
|
65
|
+
* @param orderBy - String orderBy value from options
|
|
66
|
+
* @param enumMap - Map of string values to GraphQL enum values
|
|
67
|
+
* @returns The mapped enum value or undefined
|
|
68
|
+
*/
|
|
69
|
+
export declare function mapOrderByToEnum<T>(orderBy: string | undefined, enumMap: Record<string, T>, defaultValue?: T): T | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Helper to map string orderDirection to GraphQL enum
|
|
72
|
+
*
|
|
73
|
+
* @param direction - Direction string ('asc' or 'desc')
|
|
74
|
+
* @param ascValue - The GraphQL enum value for ascending
|
|
75
|
+
* @param descValue - The GraphQL enum value for descending
|
|
76
|
+
* @returns The mapped enum value
|
|
77
|
+
*/
|
|
78
|
+
export declare function mapOrderDirection<T>(direction: "asc" | "desc" | undefined, ascValue: T, descValue: T, defaultValue?: T): T;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { print } from "graphql";
|
|
2
|
+
async function executePaginatedQuery(config) {
|
|
3
|
+
const {
|
|
4
|
+
endpoint,
|
|
5
|
+
document,
|
|
6
|
+
baseVariables,
|
|
7
|
+
options,
|
|
8
|
+
extractItems,
|
|
9
|
+
transformItem,
|
|
10
|
+
maxPerQuery = 1e3
|
|
11
|
+
} = config;
|
|
12
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
13
|
+
const offset = options?.offset ?? 0;
|
|
14
|
+
const orderBy = options?.orderBy;
|
|
15
|
+
const orderDirection = options?.orderDirection;
|
|
16
|
+
const allItems = [];
|
|
17
|
+
let currentOffset = offset;
|
|
18
|
+
const pageSize = Math.min(limit, maxPerQuery);
|
|
19
|
+
while (true) {
|
|
20
|
+
const currentLimit = options?.fetchAll ? pageSize : Math.min(pageSize, limit - allItems.length);
|
|
21
|
+
const variables = {
|
|
22
|
+
...baseVariables,
|
|
23
|
+
first: currentLimit,
|
|
24
|
+
skip: currentOffset,
|
|
25
|
+
...orderBy && { orderBy },
|
|
26
|
+
...orderDirection && { orderDirection }
|
|
27
|
+
};
|
|
28
|
+
const response = await fetch(endpoint, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: {
|
|
31
|
+
"Content-Type": "application/json"
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
query: print(document),
|
|
35
|
+
variables
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const result = await response.json();
|
|
44
|
+
if (result.errors) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const items = extractItems(result.data);
|
|
50
|
+
if (!items || items.length === 0) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
const transformedItems = transformItem ? items.map(transformItem) : items;
|
|
54
|
+
allItems.push(...transformedItems);
|
|
55
|
+
if (!options?.fetchAll && allItems.length >= limit) {
|
|
56
|
+
return allItems.slice(0, limit);
|
|
57
|
+
}
|
|
58
|
+
if (items.length < currentLimit) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
currentOffset += items.length;
|
|
62
|
+
}
|
|
63
|
+
return allItems;
|
|
64
|
+
}
|
|
65
|
+
function mapOrderByToEnum(orderBy, enumMap, defaultValue) {
|
|
66
|
+
if (!orderBy) return defaultValue;
|
|
67
|
+
return enumMap[orderBy] ?? defaultValue;
|
|
68
|
+
}
|
|
69
|
+
function mapOrderDirection(direction, ascValue, descValue, defaultValue) {
|
|
70
|
+
if (!direction) return defaultValue ?? descValue;
|
|
71
|
+
return direction === "asc" ? ascValue : descValue;
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
executePaginatedQuery,
|
|
75
|
+
mapOrderByToEnum,
|
|
76
|
+
mapOrderDirection
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=subgraphPagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/subgraphPagination.ts"],"sourcesContent":["/**\n * @file Utilities for handling paginated subgraph queries\n * @module vana-sdk/utils/subgraphPagination\n */\n\nimport { print, type DocumentNode } from \"graphql\";\nimport type { PaginationOptions } from \"../types/options\";\n\n/**\n * Generic subgraph response structure\n */\nexport interface SubgraphResponse<T> {\n data?: T;\n errors?: Array<{ message: string }>;\n}\n\n/**\n * Configuration for paginated subgraph queries\n */\nexport interface PaginatedQueryConfig<TData, TItem, TRawItem = any> {\n /** The GraphQL endpoint URL */\n endpoint: string;\n\n /** The GraphQL document to execute */\n document: DocumentNode;\n\n /** Base variables for the query (e.g., userId) */\n baseVariables: Record<string, any>;\n\n /** Pagination options from the user */\n options?: PaginationOptions;\n\n /** Function to extract items from the response */\n extractItems: (data: TData) => TRawItem[] | undefined;\n\n /** Function to transform items if needed */\n transformItem?: (item: TRawItem) => TItem;\n\n /** Maximum items per GraphQL query (default: 1000) */\n maxPerQuery?: number;\n}\n\n/**\n * Generic paginated query executor for subgraph queries\n *\n * @remarks\n * Handles pagination, fetchAll, and proper GraphQL query construction.\n * Abstracts the common pattern of paginated subgraph queries.\n *\n * @param config - Configuration for the paginated query\n * @returns Array of items from all pages\n *\n * @example\n * ```typescript\n * const files = await executePaginatedQuery({\n * endpoint: subgraphUrl,\n * document: GetUserFilesPaginatedDocument,\n * baseVariables: { userId: owner.toLowerCase() },\n * options: { limit: 50, orderBy: 'addedAtBlock' },\n * extractItems: (data) => data?.user?.files,\n * transformItem: (file) => ({\n * id: parseInt(file.id),\n * url: file.url,\n * // ... transform to UserFile\n * })\n * });\n * ```\n */\nexport async function executePaginatedQuery<TData, TItem, TRawItem = any>(\n config: PaginatedQueryConfig<TData, TItem, TRawItem>,\n): Promise<TItem[]> {\n const {\n endpoint,\n document,\n baseVariables,\n options,\n extractItems,\n transformItem,\n maxPerQuery = 1000,\n } = config;\n\n // Set pagination defaults\n const limit = options?.fetchAll\n ? Number.MAX_SAFE_INTEGER\n : (options?.limit ?? 100);\n const offset = options?.offset ?? 0;\n const orderBy = options?.orderBy;\n const orderDirection = options?.orderDirection;\n\n const allItems: TItem[] = [];\n let currentOffset = offset;\n const pageSize = Math.min(limit, maxPerQuery);\n\n // Handle fetchAll by making multiple queries if needed\n while (true) {\n const currentLimit = options?.fetchAll\n ? pageSize\n : Math.min(pageSize, limit - allItems.length);\n\n // Build query variables\n const variables = {\n ...baseVariables,\n first: currentLimit,\n skip: currentOffset,\n ...(orderBy && { orderBy }),\n ...(orderDirection && { orderDirection }),\n };\n\n // Execute query\n const response = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n query: print(document),\n variables,\n }),\n });\n\n if (!response.ok) {\n throw new Error(\n `Subgraph request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const result = (await response.json()) as SubgraphResponse<TData>;\n\n if (result.errors) {\n throw new Error(\n `Subgraph errors: ${result.errors.map((e) => e.message).join(\", \")}`,\n );\n }\n\n // Extract items from response\n const items = extractItems(result.data as TData);\n\n if (!items || items.length === 0) {\n // No more items\n break;\n }\n\n // Transform items if transformer provided\n const transformedItems: TItem[] = transformItem\n ? items.map(transformItem)\n : (items as unknown as TItem[]);\n\n allItems.push(...transformedItems);\n\n // Check if we have enough items or should continue\n if (!options?.fetchAll && allItems.length >= limit) {\n // We have enough items\n return allItems.slice(0, limit); // Trim to exact limit\n }\n\n if (items.length < currentLimit) {\n // No more items available\n break;\n }\n\n // Continue to next page\n currentOffset += items.length;\n }\n\n return allItems;\n}\n\n/**\n * Helper to map string orderBy values to GraphQL enums\n *\n * @param orderBy - String orderBy value from options\n * @param enumMap - Map of string values to GraphQL enum values\n * @returns The mapped enum value or undefined\n */\nexport function mapOrderByToEnum<T>(\n orderBy: string | undefined,\n enumMap: Record<string, T>,\n defaultValue?: T,\n): T | undefined {\n if (!orderBy) return defaultValue;\n return enumMap[orderBy] ?? defaultValue;\n}\n\n/**\n * Helper to map string orderDirection to GraphQL enum\n *\n * @param direction - Direction string ('asc' or 'desc')\n * @param ascValue - The GraphQL enum value for ascending\n * @param descValue - The GraphQL enum value for descending\n * @returns The mapped enum value\n */\nexport function mapOrderDirection<T>(\n direction: \"asc\" | \"desc\" | undefined,\n ascValue: T,\n descValue: T,\n defaultValue?: T,\n): T {\n if (!direction) return defaultValue ?? descValue;\n return direction === \"asc\" ? ascValue : descValue;\n}\n"],"mappings":"AAKA,SAAS,aAAgC;AA+DzC,eAAsB,sBACpB,QACkB;AAClB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,EAChB,IAAI;AAGJ,QAAM,QAAQ,SAAS,WACnB,OAAO,mBACN,SAAS,SAAS;AACvB,QAAM,SAAS,SAAS,UAAU;AAClC,QAAM,UAAU,SAAS;AACzB,QAAM,iBAAiB,SAAS;AAEhC,QAAM,WAAoB,CAAC;AAC3B,MAAI,gBAAgB;AACpB,QAAM,WAAW,KAAK,IAAI,OAAO,WAAW;AAG5C,SAAO,MAAM;AACX,UAAM,eAAe,SAAS,WAC1B,WACA,KAAK,IAAI,UAAU,QAAQ,SAAS,MAAM;AAG9C,UAAM,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,OAAO;AAAA,MACP,MAAM;AAAA,MACN,GAAI,WAAW,EAAE,QAAQ;AAAA,MACzB,GAAI,kBAAkB,EAAE,eAAe;AAAA,IACzC;AAGA,UAAM,WAAW,MAAM,MAAM,UAAU;AAAA,MACrC,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACnB,OAAO,MAAM,QAAQ;AAAA,QACrB;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI;AAAA,QACR,4BAA4B,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,MACpE;AAAA,IACF;AAEA,UAAM,SAAU,MAAM,SAAS,KAAK;AAEpC,QAAI,OAAO,QAAQ;AACjB,YAAM,IAAI;AAAA,QACR,oBAAoB,OAAO,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAAA,MACpE;AAAA,IACF;AAGA,UAAM,QAAQ,aAAa,OAAO,IAAa;AAE/C,QAAI,CAAC,SAAS,MAAM,WAAW,GAAG;AAEhC;AAAA,IACF;AAGA,UAAM,mBAA4B,gBAC9B,MAAM,IAAI,aAAa,IACtB;AAEL,aAAS,KAAK,GAAG,gBAAgB;AAGjC,QAAI,CAAC,SAAS,YAAY,SAAS,UAAU,OAAO;AAElD,aAAO,SAAS,MAAM,GAAG,KAAK;AAAA,IAChC;AAEA,QAAI,MAAM,SAAS,cAAc;AAE/B;AAAA,IACF;AAGA,qBAAiB,MAAM;AAAA,EACzB;AAEA,SAAO;AACT;AASO,SAAS,iBACd,SACA,SACA,cACe;AACf,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,OAAO,KAAK;AAC7B;AAUO,SAAS,kBACd,WACA,UACA,WACA,cACG;AACH,MAAI,CAAC,UAAW,QAAO,gBAAgB;AACvC,SAAO,cAAc,QAAQ,WAAW;AAC1C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/transactionHelpers.ts"],"sourcesContent":["/**\n * Helper functions for creating typed transaction POJOs\n */\n\nimport type { Hash, Address } from \"viem\";\nimport type { TransactionResult } from \"../types/operations\";\nimport type { Contract, Fn } from \"../generated/event-types\";\n\n/**\n * Creates
|
|
1
|
+
{"version":3,"sources":["../../src/utils/transactionHelpers.ts"],"sourcesContent":["/**\n * Helper functions for creating typed transaction POJOs\n */\n\nimport type { Hash, Address } from \"viem\";\nimport type { TransactionResult } from \"../types/operations\";\nimport type { Contract, Fn } from \"../generated/event-types\";\n\n/**\n * Creates typed TransactionResult with validation.\n *\n * @remarks\n * Ensures type safety for transaction results.\n * Reduces boilerplate in transaction handling.\n *\n * @param input - Transaction details\n * @param input.hash - Transaction hash from the blockchain\n * @param input.from - Transaction sender address\n * @param input.contract - Contract name being called\n * @param input.fn - Function name being executed\n * @param input.chainId - Optional chain ID for network identification\n * @param input.value - Optional transaction value in wei\n * @param input.nonce - Optional transaction nonce for ordering\n * @param input.to - Optional recipient address for the transaction\n * @returns Typed TransactionResult POJO\n *\n * @example\n * ```typescript\n * return tx({\n * hash,\n * from: account.address,\n * contract: \"DataPortabilityPermissions\",\n * fn: \"revokePermission\"\n * });\n * ```\n */\nexport function tx<C extends Contract, F extends Fn<C>>(input: {\n hash: Hash;\n from: Address;\n contract: C;\n fn: F;\n chainId?: number;\n value?: bigint;\n nonce?: number;\n to?: Address;\n}): TransactionResult<C, F> {\n // Create a new plain object to ensure independence and true POJO behavior\n return {\n hash: input.hash,\n from: input.from,\n contract: input.contract,\n fn: input.fn,\n ...(input.chainId !== undefined && { chainId: input.chainId }),\n ...(input.value !== undefined && { value: input.value }),\n ...(input.nonce !== undefined && { nonce: input.nonce }),\n ...(input.to !== undefined && { to: input.to }),\n };\n}\n\n/**\n * Creates a transaction result with literal type inference.\n * Use this when you need TypeScript to preserve exact string literals.\n *\n * @param input - Transaction details\n * @param input.hash - Transaction hash\n * @param input.from - Transaction sender address\n * @param input.contract - Contract name\n * @param input.fn - Function name\n * @param input.chainId - Optional chain ID\n * @param input.value - Optional transaction value\n * @param input.nonce - Optional nonce\n * @param input.to - Optional recipient address\n * @returns Typed TransactionResult\n *\n * @example\n * ```typescript\n * const transaction = txLiteral({\n * hash: '0x...',\n * from: '0x...',\n * contract: \"DataPortabilityPermissions\",\n * fn: \"revokePermission\",\n * });\n * // TypeScript knows exactly: DataPortabilityPermissions + revokePermission\n * ```\n */\nexport function txLiteral<\n const C extends Contract,\n const F extends Fn<C>,\n>(input: {\n hash: Hash;\n from: Address;\n contract: C;\n fn: F;\n chainId?: number;\n value?: bigint;\n nonce?: number;\n to?: Address;\n}): TransactionResult<C, F> {\n // Create a new plain object to ensure independence and true POJO behavior\n return {\n hash: input.hash,\n from: input.from,\n contract: input.contract,\n fn: input.fn,\n ...(input.chainId !== undefined && { chainId: input.chainId }),\n ...(input.value !== undefined && { value: input.value }),\n ...(input.nonce !== undefined && { nonce: input.nonce }),\n ...(input.to !== undefined && { to: input.to }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCO,SAAS,GAAwC,OAS5B;AAE1B,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,IAAI,MAAM;AAAA,IACV,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,QAAQ;AAAA,IAC5D,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,OAAO,UAAa,EAAE,IAAI,MAAM,GAAG;AAAA,EAC/C;AACF;AA4BO,SAAS,UAGd,OAS0B;AAE1B,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,IAAI,MAAM;AAAA,IACV,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,QAAQ;AAAA,IAC5D,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,OAAO,UAAa,EAAE,IAAI,MAAM,GAAG;AAAA,EAC/C;AACF;","names":[]}
|
|
@@ -5,22 +5,22 @@ import type { Hash, Address } from "viem";
|
|
|
5
5
|
import type { TransactionResult } from "../types/operations";
|
|
6
6
|
import type { Contract, Fn } from "../generated/event-types";
|
|
7
7
|
/**
|
|
8
|
-
* Creates
|
|
8
|
+
* Creates typed TransactionResult with validation.
|
|
9
9
|
*
|
|
10
10
|
* @remarks
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Ensures type safety for transaction results.
|
|
12
|
+
* Reduces boilerplate in transaction handling.
|
|
13
13
|
*
|
|
14
14
|
* @param input - Transaction details
|
|
15
|
-
* @param input.hash - Transaction hash
|
|
15
|
+
* @param input.hash - Transaction hash from the blockchain
|
|
16
16
|
* @param input.from - Transaction sender address
|
|
17
|
-
* @param input.contract - Contract name
|
|
18
|
-
* @param input.fn - Function name
|
|
19
|
-
* @param input.chainId - Optional chain ID
|
|
20
|
-
* @param input.value - Optional transaction value
|
|
21
|
-
* @param input.nonce - Optional nonce
|
|
22
|
-
* @param input.to - Optional recipient address
|
|
23
|
-
* @returns Typed TransactionResult
|
|
17
|
+
* @param input.contract - Contract name being called
|
|
18
|
+
* @param input.fn - Function name being executed
|
|
19
|
+
* @param input.chainId - Optional chain ID for network identification
|
|
20
|
+
* @param input.value - Optional transaction value in wei
|
|
21
|
+
* @param input.nonce - Optional transaction nonce for ordering
|
|
22
|
+
* @param input.to - Optional recipient address for the transaction
|
|
23
|
+
* @returns Typed TransactionResult POJO
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
@@ -28,7 +28,7 @@ import type { Contract, Fn } from "../generated/event-types";
|
|
|
28
28
|
* hash,
|
|
29
29
|
* from: account.address,
|
|
30
30
|
* contract: "DataPortabilityPermissions",
|
|
31
|
-
* fn: "revokePermission"
|
|
31
|
+
* fn: "revokePermission"
|
|
32
32
|
* });
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/transactionHelpers.ts"],"sourcesContent":["/**\n * Helper functions for creating typed transaction POJOs\n */\n\nimport type { Hash, Address } from \"viem\";\nimport type { TransactionResult } from \"../types/operations\";\nimport type { Contract, Fn } from \"../generated/event-types\";\n\n/**\n * Creates
|
|
1
|
+
{"version":3,"sources":["../../src/utils/transactionHelpers.ts"],"sourcesContent":["/**\n * Helper functions for creating typed transaction POJOs\n */\n\nimport type { Hash, Address } from \"viem\";\nimport type { TransactionResult } from \"../types/operations\";\nimport type { Contract, Fn } from \"../generated/event-types\";\n\n/**\n * Creates typed TransactionResult with validation.\n *\n * @remarks\n * Ensures type safety for transaction results.\n * Reduces boilerplate in transaction handling.\n *\n * @param input - Transaction details\n * @param input.hash - Transaction hash from the blockchain\n * @param input.from - Transaction sender address\n * @param input.contract - Contract name being called\n * @param input.fn - Function name being executed\n * @param input.chainId - Optional chain ID for network identification\n * @param input.value - Optional transaction value in wei\n * @param input.nonce - Optional transaction nonce for ordering\n * @param input.to - Optional recipient address for the transaction\n * @returns Typed TransactionResult POJO\n *\n * @example\n * ```typescript\n * return tx({\n * hash,\n * from: account.address,\n * contract: \"DataPortabilityPermissions\",\n * fn: \"revokePermission\"\n * });\n * ```\n */\nexport function tx<C extends Contract, F extends Fn<C>>(input: {\n hash: Hash;\n from: Address;\n contract: C;\n fn: F;\n chainId?: number;\n value?: bigint;\n nonce?: number;\n to?: Address;\n}): TransactionResult<C, F> {\n // Create a new plain object to ensure independence and true POJO behavior\n return {\n hash: input.hash,\n from: input.from,\n contract: input.contract,\n fn: input.fn,\n ...(input.chainId !== undefined && { chainId: input.chainId }),\n ...(input.value !== undefined && { value: input.value }),\n ...(input.nonce !== undefined && { nonce: input.nonce }),\n ...(input.to !== undefined && { to: input.to }),\n };\n}\n\n/**\n * Creates a transaction result with literal type inference.\n * Use this when you need TypeScript to preserve exact string literals.\n *\n * @param input - Transaction details\n * @param input.hash - Transaction hash\n * @param input.from - Transaction sender address\n * @param input.contract - Contract name\n * @param input.fn - Function name\n * @param input.chainId - Optional chain ID\n * @param input.value - Optional transaction value\n * @param input.nonce - Optional nonce\n * @param input.to - Optional recipient address\n * @returns Typed TransactionResult\n *\n * @example\n * ```typescript\n * const transaction = txLiteral({\n * hash: '0x...',\n * from: '0x...',\n * contract: \"DataPortabilityPermissions\",\n * fn: \"revokePermission\",\n * });\n * // TypeScript knows exactly: DataPortabilityPermissions + revokePermission\n * ```\n */\nexport function txLiteral<\n const C extends Contract,\n const F extends Fn<C>,\n>(input: {\n hash: Hash;\n from: Address;\n contract: C;\n fn: F;\n chainId?: number;\n value?: bigint;\n nonce?: number;\n to?: Address;\n}): TransactionResult<C, F> {\n // Create a new plain object to ensure independence and true POJO behavior\n return {\n hash: input.hash,\n from: input.from,\n contract: input.contract,\n fn: input.fn,\n ...(input.chainId !== undefined && { chainId: input.chainId }),\n ...(input.value !== undefined && { value: input.value }),\n ...(input.nonce !== undefined && { nonce: input.nonce }),\n ...(input.to !== undefined && { to: input.to }),\n };\n}\n"],"mappings":"AAoCO,SAAS,GAAwC,OAS5B;AAE1B,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,IAAI,MAAM;AAAA,IACV,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,QAAQ;AAAA,IAC5D,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,OAAO,UAAa,EAAE,IAAI,MAAM,GAAG;AAAA,EAC/C;AACF;AA4BO,SAAS,UAGd,OAS0B;AAE1B,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,IAAI,MAAM;AAAA,IACV,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,QAAQ;AAAA,IAC5D,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,OAAO,UAAa,EAAE,IAAI,MAAM,GAAG;AAAA,EAC/C;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/typedDataConverter.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/typedDataConverter.ts"],"sourcesContent":["/**\n * Provides type-safe conversion between Vana and viem typed data formats.\n *\n * @remarks\n * This module bridges the gap between Vana's generic typed data structure\n * and viem's strict TypedDataDefinition format, ensuring compatibility\n * for EIP-712 signature operations.\n *\n * @category Utilities\n * @module typedDataConverter\n */\n\nimport type { TypedDataDefinition } from \"viem\";\nimport type { GenericTypedData } from \"../types/permissions\";\n\n/**\n * Converts a GenericTypedData object to a viem-compatible TypedDataDefinition.\n *\n * @remarks\n * Transforms Vana's flexible typed data format into viem's strict format\n * with readonly arrays. This ensures type safety when passing typed data\n * to viem's `signTypedData` method for EIP-712 signatures.\n *\n * @param typedData - The typed data object to convert.\n * Obtain from permission operations or server responses.\n * @returns A properly typed TypedDataDefinition for use with viem\n *\n * @example\n * ```typescript\n * const vanTypedData: GenericTypedData = {\n * domain: { name: 'Vana', version: '1', chainId: 14800 },\n * types: {\n * Permission: [\n * { name: 'grantee', type: 'address' },\n * { name: 'operation', type: 'string' }\n * ]\n * },\n * primaryType: 'Permission',\n * message: { grantee: '0x...', operation: 'read' }\n * };\n *\n * const viemTypedData = toViemTypedDataDefinition(vanaTypedData);\n * const signature = await walletClient.signTypedData(viemTypedData);\n * ```\n *\n * @category Utilities\n */\nexport function toViemTypedDataDefinition(\n typedData: GenericTypedData,\n): TypedDataDefinition {\n // Transform the types to match viem's expected format with readonly arrays\n const viemTypes: Record<string, readonly { name: string; type: string }[]> =\n {};\n\n for (const [typeName, typeArray] of Object.entries(typedData.types)) {\n // Create a new readonly array for each type\n viemTypes[typeName] = typeArray.map((field) => ({\n name: field.name,\n type: field.type,\n })) as readonly { name: string; type: string }[];\n }\n\n return {\n domain: typedData.domain,\n types: viemTypes as TypedDataDefinition[\"types\"],\n primaryType: typedData.primaryType,\n message: typedData.message,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+CO,SAAS,0BACd,WACqB;AAErB,QAAM,YACJ,CAAC;AAEH,aAAW,CAAC,UAAU,SAAS,KAAK,OAAO,QAAQ,UAAU,KAAK,GAAG;AAEnE,cAAU,QAAQ,IAAI,UAAU,IAAI,CAAC,WAAW;AAAA,MAC9C,MAAM,MAAM;AAAA,MACZ,MAAM,MAAM;AAAA,IACd,EAAE;AAAA,EACJ;AAEA,SAAO;AAAA,IACL,QAAQ,UAAU;AAAA,IAClB,OAAO;AAAA,IACP,aAAa,UAAU;AAAA,IACvB,SAAS,UAAU;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -1,10 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides type-safe conversion between Vana and viem typed data formats.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This module bridges the gap between Vana's generic typed data structure
|
|
6
|
+
* and viem's strict TypedDataDefinition format, ensuring compatibility
|
|
7
|
+
* for EIP-712 signature operations.
|
|
8
|
+
*
|
|
9
|
+
* @category Utilities
|
|
10
|
+
* @module typedDataConverter
|
|
11
|
+
*/
|
|
1
12
|
import type { TypedDataDefinition } from "viem";
|
|
2
13
|
import type { GenericTypedData } from "../types/permissions";
|
|
3
14
|
/**
|
|
4
|
-
* Converts a GenericTypedData object to a
|
|
5
|
-
* This function ensures type safety when passing typed data to viem's signTypedData method.
|
|
15
|
+
* Converts a GenericTypedData object to a viem-compatible TypedDataDefinition.
|
|
6
16
|
*
|
|
7
|
-
* @
|
|
17
|
+
* @remarks
|
|
18
|
+
* Transforms Vana's flexible typed data format into viem's strict format
|
|
19
|
+
* with readonly arrays. This ensures type safety when passing typed data
|
|
20
|
+
* to viem's `signTypedData` method for EIP-712 signatures.
|
|
21
|
+
*
|
|
22
|
+
* @param typedData - The typed data object to convert.
|
|
23
|
+
* Obtain from permission operations or server responses.
|
|
8
24
|
* @returns A properly typed TypedDataDefinition for use with viem
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const vanTypedData: GenericTypedData = {
|
|
29
|
+
* domain: { name: 'Vana', version: '1', chainId: 14800 },
|
|
30
|
+
* types: {
|
|
31
|
+
* Permission: [
|
|
32
|
+
* { name: 'grantee', type: 'address' },
|
|
33
|
+
* { name: 'operation', type: 'string' }
|
|
34
|
+
* ]
|
|
35
|
+
* },
|
|
36
|
+
* primaryType: 'Permission',
|
|
37
|
+
* message: { grantee: '0x...', operation: 'read' }
|
|
38
|
+
* };
|
|
39
|
+
*
|
|
40
|
+
* const viemTypedData = toViemTypedDataDefinition(vanaTypedData);
|
|
41
|
+
* const signature = await walletClient.signTypedData(viemTypedData);
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @category Utilities
|
|
9
45
|
*/
|
|
10
46
|
export declare function toViemTypedDataDefinition(typedData: GenericTypedData): TypedDataDefinition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/typedDataConverter.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/typedDataConverter.ts"],"sourcesContent":["/**\n * Provides type-safe conversion between Vana and viem typed data formats.\n *\n * @remarks\n * This module bridges the gap between Vana's generic typed data structure\n * and viem's strict TypedDataDefinition format, ensuring compatibility\n * for EIP-712 signature operations.\n *\n * @category Utilities\n * @module typedDataConverter\n */\n\nimport type { TypedDataDefinition } from \"viem\";\nimport type { GenericTypedData } from \"../types/permissions\";\n\n/**\n * Converts a GenericTypedData object to a viem-compatible TypedDataDefinition.\n *\n * @remarks\n * Transforms Vana's flexible typed data format into viem's strict format\n * with readonly arrays. This ensures type safety when passing typed data\n * to viem's `signTypedData` method for EIP-712 signatures.\n *\n * @param typedData - The typed data object to convert.\n * Obtain from permission operations or server responses.\n * @returns A properly typed TypedDataDefinition for use with viem\n *\n * @example\n * ```typescript\n * const vanTypedData: GenericTypedData = {\n * domain: { name: 'Vana', version: '1', chainId: 14800 },\n * types: {\n * Permission: [\n * { name: 'grantee', type: 'address' },\n * { name: 'operation', type: 'string' }\n * ]\n * },\n * primaryType: 'Permission',\n * message: { grantee: '0x...', operation: 'read' }\n * };\n *\n * const viemTypedData = toViemTypedDataDefinition(vanaTypedData);\n * const signature = await walletClient.signTypedData(viemTypedData);\n * ```\n *\n * @category Utilities\n */\nexport function toViemTypedDataDefinition(\n typedData: GenericTypedData,\n): TypedDataDefinition {\n // Transform the types to match viem's expected format with readonly arrays\n const viemTypes: Record<string, readonly { name: string; type: string }[]> =\n {};\n\n for (const [typeName, typeArray] of Object.entries(typedData.types)) {\n // Create a new readonly array for each type\n viemTypes[typeName] = typeArray.map((field) => ({\n name: field.name,\n type: field.type,\n })) as readonly { name: string; type: string }[];\n }\n\n return {\n domain: typedData.domain,\n types: viemTypes as TypedDataDefinition[\"types\"],\n primaryType: typedData.primaryType,\n message: typedData.message,\n };\n}\n"],"mappings":"AA+CO,SAAS,0BACd,WACqB;AAErB,QAAM,YACJ,CAAC;AAEH,aAAW,CAAC,UAAU,SAAS,KAAK,OAAO,QAAQ,UAAU,KAAK,GAAG;AAEnE,cAAU,QAAQ,IAAI,UAAU,IAAI,CAAC,WAAW;AAAA,MAC9C,MAAM,MAAM;AAAA,MACZ,MAAM,MAAM;AAAA,IACd,EAAE;AAAA,EACJ;AAEA,SAAO;AAAA,IACL,QAAQ,UAAU;AAAA,IAClB,OAAO;AAAA,IACP,aAAa,UAAU;AAAA,IACvB,SAAS,UAAU;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -24,6 +24,13 @@ __export(urlResolver_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(urlResolver_exports);
|
|
25
25
|
var import_download = require("./download");
|
|
26
26
|
class UrlResolutionError extends Error {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new URL resolution error.
|
|
29
|
+
*
|
|
30
|
+
* @param message - Description of what went wrong
|
|
31
|
+
* @param url - The URL that failed to resolve
|
|
32
|
+
* @param cause - The underlying error that caused the failure
|
|
33
|
+
*/
|
|
27
34
|
constructor(message, url, cause) {
|
|
28
35
|
super(message);
|
|
29
36
|
this.url = url;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/urlResolver.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"sources":["../../src/utils/urlResolver.ts"],"sourcesContent":["/**\n * Provides universal URL resolution across multiple protocols.\n *\n * @remarks\n * This module enables fetching data from various protocols including IPFS,\n * HTTP/HTTPS, and Arweave through a unified interface. It handles protocol\n * conversion, gateway selection, and fallback strategies automatically.\n *\n * @category Utilities\n * @module utils/urlResolver\n */\n\nimport { universalFetch } from \"./download\";\n\n/**\n * Indicates that URL resolution or data fetching failed.\n *\n * @remarks\n * This error provides context about which URL failed and why,\n * making it easier to debug issues with external resources.\n *\n * @category Errors\n */\nexport class UrlResolutionError extends Error {\n /**\n * Creates a new URL resolution error.\n *\n * @param message - Description of what went wrong\n * @param url - The URL that failed to resolve\n * @param cause - The underlying error that caused the failure\n */\n constructor(\n message: string,\n public readonly url: string,\n public override readonly cause?: Error,\n ) {\n super(message);\n this.name = \"UrlResolutionError\";\n }\n}\n\n/**\n * Fetches and parses JSON data from any supported URL protocol\n *\n * @param url - The URL to fetch from (supports ipfs://, https://, http://, ar://)\n * @param downloadRelayer - Optional download relayer for CORS bypass\n * @param downloadRelayer.proxyDownload - Function to proxy downloads through application server\n * @returns Promise resolving to the parsed JSON data\n * @throws {UrlResolutionError} When the URL cannot be resolved or parsed\n *\n * @example\n * ```typescript\n * // Fetch from IPFS\n * const data = await fetchFromUrl(\"ipfs://QmXxx...\");\n *\n * // Fetch from HTTPS\n * const data = await fetchFromUrl(\"https://example.com/data.json\");\n *\n * // Handles protocol conversion internally\n * const schema = await fetchFromUrl(schemaDefinitionUrl);\n * ```\n */\nexport async function fetchFromUrl(\n url: string,\n downloadRelayer?: { proxyDownload: (url: string) => Promise<Blob> },\n): Promise<unknown> {\n try {\n // Use unified download utility with automatic fallbacks\n const response = await universalFetch(url, downloadRelayer);\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n // Parse JSON response\n const data = await response.json();\n return data;\n } catch (error) {\n throw new UrlResolutionError(\n `Failed to fetch from ${url}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n url,\n error instanceof Error ? error : undefined,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAA+B;AAWxB,MAAM,2BAA2B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5C,YACE,SACgB,KACS,OACzB;AACA,UAAM,OAAO;AAHG;AACS;AAGzB,SAAK,OAAO;AAAA,EACd;AACF;AAuBA,eAAsB,aACpB,KACA,iBACkB;AAClB,MAAI;AAEF,UAAM,WAAW,UAAM,gCAAe,KAAK,eAAe;AAE1D,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,QAAQ,SAAS,MAAM,KAAK,SAAS,UAAU,EAAE;AAAA,IACnE;AAGA,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,wBAAwB,GAAG,KAAK,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACxF;AAAA,MACA,iBAAiB,QAAQ,QAAQ;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,15 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides universal URL resolution across multiple protocols.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This module enables fetching data from various protocols including IPFS,
|
|
6
|
+
* HTTP/HTTPS, and Arweave through a unified interface. It handles protocol
|
|
7
|
+
* conversion, gateway selection, and fallback strategies automatically.
|
|
8
|
+
*
|
|
9
|
+
* @category Utilities
|
|
10
|
+
* @module utils/urlResolver
|
|
6
11
|
*/
|
|
7
12
|
/**
|
|
8
|
-
*
|
|
13
|
+
* Indicates that URL resolution or data fetching failed.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This error provides context about which URL failed and why,
|
|
17
|
+
* making it easier to debug issues with external resources.
|
|
18
|
+
*
|
|
19
|
+
* @category Errors
|
|
9
20
|
*/
|
|
10
21
|
export declare class UrlResolutionError extends Error {
|
|
11
22
|
readonly url: string;
|
|
12
23
|
readonly cause?: Error | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new URL resolution error.
|
|
26
|
+
*
|
|
27
|
+
* @param message - Description of what went wrong
|
|
28
|
+
* @param url - The URL that failed to resolve
|
|
29
|
+
* @param cause - The underlying error that caused the failure
|
|
30
|
+
*/
|
|
13
31
|
constructor(message: string, url: string, cause?: Error | undefined);
|
|
14
32
|
}
|
|
15
33
|
/**
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { universalFetch } from "./download";
|
|
2
2
|
class UrlResolutionError extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new URL resolution error.
|
|
5
|
+
*
|
|
6
|
+
* @param message - Description of what went wrong
|
|
7
|
+
* @param url - The URL that failed to resolve
|
|
8
|
+
* @param cause - The underlying error that caused the failure
|
|
9
|
+
*/
|
|
3
10
|
constructor(message, url, cause) {
|
|
4
11
|
super(message);
|
|
5
12
|
this.url = url;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/urlResolver.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"sources":["../../src/utils/urlResolver.ts"],"sourcesContent":["/**\n * Provides universal URL resolution across multiple protocols.\n *\n * @remarks\n * This module enables fetching data from various protocols including IPFS,\n * HTTP/HTTPS, and Arweave through a unified interface. It handles protocol\n * conversion, gateway selection, and fallback strategies automatically.\n *\n * @category Utilities\n * @module utils/urlResolver\n */\n\nimport { universalFetch } from \"./download\";\n\n/**\n * Indicates that URL resolution or data fetching failed.\n *\n * @remarks\n * This error provides context about which URL failed and why,\n * making it easier to debug issues with external resources.\n *\n * @category Errors\n */\nexport class UrlResolutionError extends Error {\n /**\n * Creates a new URL resolution error.\n *\n * @param message - Description of what went wrong\n * @param url - The URL that failed to resolve\n * @param cause - The underlying error that caused the failure\n */\n constructor(\n message: string,\n public readonly url: string,\n public override readonly cause?: Error,\n ) {\n super(message);\n this.name = \"UrlResolutionError\";\n }\n}\n\n/**\n * Fetches and parses JSON data from any supported URL protocol\n *\n * @param url - The URL to fetch from (supports ipfs://, https://, http://, ar://)\n * @param downloadRelayer - Optional download relayer for CORS bypass\n * @param downloadRelayer.proxyDownload - Function to proxy downloads through application server\n * @returns Promise resolving to the parsed JSON data\n * @throws {UrlResolutionError} When the URL cannot be resolved or parsed\n *\n * @example\n * ```typescript\n * // Fetch from IPFS\n * const data = await fetchFromUrl(\"ipfs://QmXxx...\");\n *\n * // Fetch from HTTPS\n * const data = await fetchFromUrl(\"https://example.com/data.json\");\n *\n * // Handles protocol conversion internally\n * const schema = await fetchFromUrl(schemaDefinitionUrl);\n * ```\n */\nexport async function fetchFromUrl(\n url: string,\n downloadRelayer?: { proxyDownload: (url: string) => Promise<Blob> },\n): Promise<unknown> {\n try {\n // Use unified download utility with automatic fallbacks\n const response = await universalFetch(url, downloadRelayer);\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n // Parse JSON response\n const data = await response.json();\n return data;\n } catch (error) {\n throw new UrlResolutionError(\n `Failed to fetch from ${url}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n url,\n error instanceof Error ? error : undefined,\n );\n }\n}\n"],"mappings":"AAYA,SAAS,sBAAsB;AAWxB,MAAM,2BAA2B,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ5C,YACE,SACgB,KACS,OACzB;AACA,UAAM,OAAO;AAHG;AACS;AAGzB,SAAK,OAAO;AAAA,EACd;AACF;AAuBA,eAAsB,aACpB,KACA,iBACkB;AAClB,MAAI;AAEF,UAAM,WAAW,MAAM,eAAe,KAAK,eAAe;AAE1D,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,QAAQ,SAAS,MAAM,KAAK,SAAS,UAAU,EAAE;AAAA,IACnE;AAGA,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,wBAAwB,GAAG,KAAK,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACxF;AAAA,MACA,iBAAiB,QAAQ,QAAQ;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/wallet.ts"],"sourcesContent":["import type { Account, Address } from \"viem\";\n\n/**\n * Extracts an Ethereum address from various account formats.\n *\n *
|
|
1
|
+
{"version":3,"sources":["../../src/utils/wallet.ts"],"sourcesContent":["import type { Account, Address } from \"viem\";\n\n/**\n * Extracts an Ethereum address from various account formats.\n *\n * @remarks\n * Handles viem's polymorphic Account type which can be a string address,\n * an object with an address property, or a LocalAccount. This utility\n * provides consistent address extraction across the SDK, eliminating\n * duplicate logic and potential inconsistencies.\n *\n * @param account - The account to extract address from.\n * Can be a hex string address, Account object, or LocalAccount.\n * @returns The extracted Ethereum address as a `0x`-prefixed string\n *\n * @throws {Error} When account is undefined or null.\n * Provide a valid account from wallet connection.\n * @throws {Error} When address cannot be determined from account structure.\n * Ensure account has a valid address property.\n *\n * @example\n * ```typescript\n * // String address\n * const addr1 = extractAddress('0x742d35Cc6634C0532925a3b844Bc9e7595f0b0Bb');\n *\n * // Account object\n * const addr2 = extractAddress({ address: '0x742d...' });\n *\n * // LocalAccount from viem\n * const account = privateKeyToAccount('0x...');\n * const addr3 = extractAddress(account);\n * ```\n *\n * @category Utilities\n */\nexport function extractAddress(\n account: Account | Address | undefined | null,\n): Address {\n if (!account) {\n throw new Error(\"No account provided\");\n }\n\n // Handle string address directly\n if (typeof account === \"string\") {\n return account as Address;\n }\n\n // Handle object with address property\n if (typeof account === \"object\" && \"address\" in account && account.address) {\n return account.address;\n }\n\n throw new Error(\"Unable to determine wallet address from account\");\n}\n\n/**\n * Safely extracts an address without throwing errors.\n *\n * @remarks\n * Non-throwing version of `extractAddress` for optional address resolution.\n * Use when address extraction failure is acceptable and should be handled\n * gracefully without exception handling.\n *\n * @param account - The account to extract address from.\n * Can be a hex string address, Account object, LocalAccount, or nullish.\n * @returns The extracted Ethereum address or `undefined` if extraction fails\n *\n * @example\n * ```typescript\n * const address = extractAddressSafe(potentialAccount);\n *\n * if (address) {\n * console.log(`Using address: ${address}`);\n * } else {\n * console.log('No valid address available');\n * }\n *\n * // Useful in optional chaining\n * const userAddress = extractAddressSafe(user?.wallet) ?? DEFAULT_ADDRESS;\n * ```\n *\n * @category Utilities\n */\nexport function extractAddressSafe(\n account: Account | Address | undefined | null,\n): Address | undefined {\n try {\n return extractAddress(account);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Validates whether a value contains a valid Ethereum address.\n *\n * @remarks\n * Type guard that performs runtime validation of Ethereum address format.\n * Checks for proper `0x` prefix and 40 hexadecimal characters. Works with\n * string addresses, Account objects, and LocalAccount instances.\n *\n * @param account - The value to validate for address presence\n * @returns `true` if account contains a valid Ethereum address, `false` otherwise\n *\n * @example\n * ```typescript\n * const maybeAccount: unknown = getUserInput();\n *\n * if (hasAddress(maybeAccount)) {\n * // TypeScript knows maybeAccount is Account | Address\n * const address = extractAddress(maybeAccount);\n * await vana.data.getUserFiles({ owner: address });\n * } else {\n * console.error('Invalid address format');\n * }\n *\n * // Filter valid addresses from mixed array\n * const addresses = mixedArray.filter(hasAddress).map(extractAddress);\n * ```\n *\n * @category Utilities\n */\nexport function hasAddress(account: unknown): account is Account | Address {\n if (!account) return false;\n\n if (typeof account === \"string\") {\n // Basic check for Ethereum address format\n return /^0x[a-fA-F0-9]{40}$/.test(account);\n }\n\n if (typeof account === \"object\" && \"address\" in account) {\n const accountWithAddress = account as { address: unknown };\n const addr = accountWithAddress.address;\n return typeof addr === \"string\" && /^0x[a-fA-F0-9]{40}$/.test(addr);\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCO,SAAS,eACd,SACS;AACT,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAGA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,YAAY,YAAY,aAAa,WAAW,QAAQ,SAAS;AAC1E,WAAO,QAAQ;AAAA,EACjB;AAEA,QAAM,IAAI,MAAM,iDAAiD;AACnE;AA8BO,SAAS,mBACd,SACqB;AACrB,MAAI;AACF,WAAO,eAAe,OAAO;AAAA,EAC/B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AA+BO,SAAS,WAAW,SAAgD;AACzE,MAAI,CAAC,QAAS,QAAO;AAErB,MAAI,OAAO,YAAY,UAAU;AAE/B,WAAO,sBAAsB,KAAK,OAAO;AAAA,EAC3C;AAEA,MAAI,OAAO,YAAY,YAAY,aAAa,SAAS;AACvD,UAAM,qBAAqB;AAC3B,UAAM,OAAO,mBAAmB;AAChC,WAAO,OAAO,SAAS,YAAY,sBAAsB,KAAK,IAAI;AAAA,EACpE;AAEA,SAAO;AACT;","names":[]}
|
package/dist/utils/wallet.d.ts
CHANGED
|
@@ -2,31 +2,93 @@ import type { Account, Address } from "viem";
|
|
|
2
2
|
/**
|
|
3
3
|
* Extracts an Ethereum address from various account formats.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Handles viem's polymorphic Account type which can be a string address,
|
|
7
|
+
* an object with an address property, or a LocalAccount. This utility
|
|
8
|
+
* provides consistent address extraction across the SDK, eliminating
|
|
9
|
+
* duplicate logic and potential inconsistencies.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* @param account - The account to extract address from.
|
|
12
|
+
* Can be a hex string address, Account object, or LocalAccount.
|
|
13
|
+
* @returns The extracted Ethereum address as a `0x`-prefixed string
|
|
12
14
|
*
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
* @throws Error
|
|
15
|
+
* @throws {Error} When account is undefined or null.
|
|
16
|
+
* Provide a valid account from wallet connection.
|
|
17
|
+
* @throws {Error} When address cannot be determined from account structure.
|
|
18
|
+
* Ensure account has a valid address property.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // String address
|
|
23
|
+
* const addr1 = extractAddress('0x742d35Cc6634C0532925a3b844Bc9e7595f0b0Bb');
|
|
24
|
+
*
|
|
25
|
+
* // Account object
|
|
26
|
+
* const addr2 = extractAddress({ address: '0x742d...' });
|
|
27
|
+
*
|
|
28
|
+
* // LocalAccount from viem
|
|
29
|
+
* const account = privateKeyToAccount('0x...');
|
|
30
|
+
* const addr3 = extractAddress(account);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @category Utilities
|
|
16
34
|
*/
|
|
17
35
|
export declare function extractAddress(account: Account | Address | undefined | null): Address;
|
|
18
36
|
/**
|
|
19
|
-
* Safely extracts an address
|
|
20
|
-
*
|
|
37
|
+
* Safely extracts an address without throwing errors.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Non-throwing version of `extractAddress` for optional address resolution.
|
|
41
|
+
* Use when address extraction failure is acceptable and should be handled
|
|
42
|
+
* gracefully without exception handling.
|
|
43
|
+
*
|
|
44
|
+
* @param account - The account to extract address from.
|
|
45
|
+
* Can be a hex string address, Account object, LocalAccount, or nullish.
|
|
46
|
+
* @returns The extracted Ethereum address or `undefined` if extraction fails
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const address = extractAddressSafe(potentialAccount);
|
|
21
51
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
52
|
+
* if (address) {
|
|
53
|
+
* console.log(`Using address: ${address}`);
|
|
54
|
+
* } else {
|
|
55
|
+
* console.log('No valid address available');
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* // Useful in optional chaining
|
|
59
|
+
* const userAddress = extractAddressSafe(user?.wallet) ?? DEFAULT_ADDRESS;
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @category Utilities
|
|
24
63
|
*/
|
|
25
64
|
export declare function extractAddressSafe(account: Account | Address | undefined | null): Address | undefined;
|
|
26
65
|
/**
|
|
27
|
-
*
|
|
66
|
+
* Validates whether a value contains a valid Ethereum address.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Type guard that performs runtime validation of Ethereum address format.
|
|
70
|
+
* Checks for proper `0x` prefix and 40 hexadecimal characters. Works with
|
|
71
|
+
* string addresses, Account objects, and LocalAccount instances.
|
|
72
|
+
*
|
|
73
|
+
* @param account - The value to validate for address presence
|
|
74
|
+
* @returns `true` if account contains a valid Ethereum address, `false` otherwise
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const maybeAccount: unknown = getUserInput();
|
|
79
|
+
*
|
|
80
|
+
* if (hasAddress(maybeAccount)) {
|
|
81
|
+
* // TypeScript knows maybeAccount is Account | Address
|
|
82
|
+
* const address = extractAddress(maybeAccount);
|
|
83
|
+
* await vana.data.getUserFiles({ owner: address });
|
|
84
|
+
* } else {
|
|
85
|
+
* console.error('Invalid address format');
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* // Filter valid addresses from mixed array
|
|
89
|
+
* const addresses = mixedArray.filter(hasAddress).map(extractAddress);
|
|
90
|
+
* ```
|
|
28
91
|
*
|
|
29
|
-
* @
|
|
30
|
-
* @returns True if account has a valid address
|
|
92
|
+
* @category Utilities
|
|
31
93
|
*/
|
|
32
94
|
export declare function hasAddress(account: unknown): account is Account | Address;
|
package/dist/utils/wallet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/wallet.ts"],"sourcesContent":["import type { Account, Address } from \"viem\";\n\n/**\n * Extracts an Ethereum address from various account formats.\n *\n *
|
|
1
|
+
{"version":3,"sources":["../../src/utils/wallet.ts"],"sourcesContent":["import type { Account, Address } from \"viem\";\n\n/**\n * Extracts an Ethereum address from various account formats.\n *\n * @remarks\n * Handles viem's polymorphic Account type which can be a string address,\n * an object with an address property, or a LocalAccount. This utility\n * provides consistent address extraction across the SDK, eliminating\n * duplicate logic and potential inconsistencies.\n *\n * @param account - The account to extract address from.\n * Can be a hex string address, Account object, or LocalAccount.\n * @returns The extracted Ethereum address as a `0x`-prefixed string\n *\n * @throws {Error} When account is undefined or null.\n * Provide a valid account from wallet connection.\n * @throws {Error} When address cannot be determined from account structure.\n * Ensure account has a valid address property.\n *\n * @example\n * ```typescript\n * // String address\n * const addr1 = extractAddress('0x742d35Cc6634C0532925a3b844Bc9e7595f0b0Bb');\n *\n * // Account object\n * const addr2 = extractAddress({ address: '0x742d...' });\n *\n * // LocalAccount from viem\n * const account = privateKeyToAccount('0x...');\n * const addr3 = extractAddress(account);\n * ```\n *\n * @category Utilities\n */\nexport function extractAddress(\n account: Account | Address | undefined | null,\n): Address {\n if (!account) {\n throw new Error(\"No account provided\");\n }\n\n // Handle string address directly\n if (typeof account === \"string\") {\n return account as Address;\n }\n\n // Handle object with address property\n if (typeof account === \"object\" && \"address\" in account && account.address) {\n return account.address;\n }\n\n throw new Error(\"Unable to determine wallet address from account\");\n}\n\n/**\n * Safely extracts an address without throwing errors.\n *\n * @remarks\n * Non-throwing version of `extractAddress` for optional address resolution.\n * Use when address extraction failure is acceptable and should be handled\n * gracefully without exception handling.\n *\n * @param account - The account to extract address from.\n * Can be a hex string address, Account object, LocalAccount, or nullish.\n * @returns The extracted Ethereum address or `undefined` if extraction fails\n *\n * @example\n * ```typescript\n * const address = extractAddressSafe(potentialAccount);\n *\n * if (address) {\n * console.log(`Using address: ${address}`);\n * } else {\n * console.log('No valid address available');\n * }\n *\n * // Useful in optional chaining\n * const userAddress = extractAddressSafe(user?.wallet) ?? DEFAULT_ADDRESS;\n * ```\n *\n * @category Utilities\n */\nexport function extractAddressSafe(\n account: Account | Address | undefined | null,\n): Address | undefined {\n try {\n return extractAddress(account);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Validates whether a value contains a valid Ethereum address.\n *\n * @remarks\n * Type guard that performs runtime validation of Ethereum address format.\n * Checks for proper `0x` prefix and 40 hexadecimal characters. Works with\n * string addresses, Account objects, and LocalAccount instances.\n *\n * @param account - The value to validate for address presence\n * @returns `true` if account contains a valid Ethereum address, `false` otherwise\n *\n * @example\n * ```typescript\n * const maybeAccount: unknown = getUserInput();\n *\n * if (hasAddress(maybeAccount)) {\n * // TypeScript knows maybeAccount is Account | Address\n * const address = extractAddress(maybeAccount);\n * await vana.data.getUserFiles({ owner: address });\n * } else {\n * console.error('Invalid address format');\n * }\n *\n * // Filter valid addresses from mixed array\n * const addresses = mixedArray.filter(hasAddress).map(extractAddress);\n * ```\n *\n * @category Utilities\n */\nexport function hasAddress(account: unknown): account is Account | Address {\n if (!account) return false;\n\n if (typeof account === \"string\") {\n // Basic check for Ethereum address format\n return /^0x[a-fA-F0-9]{40}$/.test(account);\n }\n\n if (typeof account === \"object\" && \"address\" in account) {\n const accountWithAddress = account as { address: unknown };\n const addr = accountWithAddress.address;\n return typeof addr === \"string\" && /^0x[a-fA-F0-9]{40}$/.test(addr);\n }\n\n return false;\n}\n"],"mappings":"AAmCO,SAAS,eACd,SACS;AACT,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAGA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,YAAY,YAAY,aAAa,WAAW,QAAQ,SAAS;AAC1E,WAAO,QAAQ;AAAA,EACjB;AAEA,QAAM,IAAI,MAAM,iDAAiD;AACnE;AA8BO,SAAS,mBACd,SACqB;AACrB,MAAI;AACF,WAAO,eAAe,OAAO;AAAA,EAC/B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AA+BO,SAAS,WAAW,SAAgD;AACzE,MAAI,CAAC,QAAS,QAAO;AAErB,MAAI,OAAO,YAAY,UAAU;AAE/B,WAAO,sBAAsB,KAAK,OAAO;AAAA,EAC3C;AAEA,MAAI,OAAO,YAAY,YAAY,aAAa,SAAS;AACvD,UAAM,qBAAqB;AAC3B,UAAM,OAAO,mBAAmB;AAChC,WAAO,OAAO,SAAS,YAAY,sBAAsB,KAAK,IAAI;AAAA,EACpE;AAEA,SAAO;AACT;","names":[]}
|