@gala-chain/launchpad-sdk 5.0.3 → 5.0.4-beta.1
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/EXAMPLES.md +141 -7
- package/README.md +68 -36
- package/dist/ai-docs.json +7357 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +70 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/src/LaunchpadSDK.d.ts +3288 -214
- package/dist/src/LaunchpadSDK.d.ts.map +1 -1
- package/dist/src/api/LaunchpadAPI.d.ts +21 -41
- package/dist/src/api/LaunchpadAPI.d.ts.map +1 -1
- package/dist/src/api/dto/BurnTokensDto.d.ts.map +1 -1
- package/dist/src/api/dto/LockTokenDto.d.ts.map +1 -1
- package/dist/src/api/dto/TransferTokenDto.d.ts.map +1 -1
- package/dist/src/api/dto/UnlockTokenDto.d.ts.map +1 -1
- package/dist/src/auth/JwtAuth.d.ts +145 -0
- package/dist/src/auth/JwtAuth.d.ts.map +1 -0
- package/dist/src/auth/SessionAuthService.d.ts +146 -0
- package/dist/src/auth/SessionAuthService.d.ts.map +1 -0
- package/dist/src/auth/SignatureAuth.d.ts.map +1 -1
- package/dist/src/bridge/BridgeService.d.ts.map +1 -1
- package/dist/src/bridge/GalaConnectClient.d.ts.map +1 -1
- package/dist/src/bridge/constants/tokens.d.ts +4 -3
- package/dist/src/bridge/constants/tokens.d.ts.map +1 -1
- package/dist/src/bridge/index.d.ts +1 -0
- package/dist/src/bridge/index.d.ts.map +1 -1
- package/dist/src/bridge/strategies/BridgeStrategy.d.ts.map +1 -1
- package/dist/src/bridge/strategies/EthereumBridgeStrategy.d.ts +1 -38
- package/dist/src/bridge/strategies/EthereumBridgeStrategy.d.ts.map +1 -1
- package/dist/src/bridge/strategies/SolanaBridgeStrategy.d.ts +1 -21
- package/dist/src/bridge/strategies/SolanaBridgeStrategy.d.ts.map +1 -1
- package/dist/src/bridge/types/bridge.dto.d.ts +15 -2
- package/dist/src/bridge/types/bridge.dto.d.ts.map +1 -1
- package/dist/src/bridge/utils/RateLimiter.d.ts +1 -1
- package/dist/src/bridge/utils/RateLimiter.d.ts.map +1 -1
- package/dist/src/bridge/utils/address-formatter.d.ts +25 -0
- package/dist/src/bridge/utils/address-formatter.d.ts.map +1 -0
- package/dist/src/bridge/utils/addressValidation.d.ts +200 -0
- package/dist/src/bridge/utils/addressValidation.d.ts.map +1 -0
- package/dist/src/bridge/utils/balanceHelpers.d.ts +215 -0
- package/dist/src/bridge/utils/balanceHelpers.d.ts.map +1 -0
- package/dist/src/bridge/utils/bridgeErrors.d.ts +98 -0
- package/dist/src/bridge/utils/bridgeErrors.d.ts.map +1 -0
- package/dist/src/bridge/utils/bridgeOutHelpers.d.ts +68 -0
- package/dist/src/bridge/utils/bridgeOutHelpers.d.ts.map +1 -0
- package/dist/src/bridge/utils/bridgePayload.d.ts +107 -0
- package/dist/src/bridge/utils/bridgePayload.d.ts.map +1 -0
- package/dist/src/bridge/utils/bridgeStatusParser.d.ts +75 -0
- package/dist/src/bridge/utils/bridgeStatusParser.d.ts.map +1 -0
- package/dist/src/bridge/utils/eip712Helpers.d.ts +66 -0
- package/dist/src/bridge/utils/eip712Helpers.d.ts.map +1 -0
- package/dist/src/bridge/utils/index.d.ts +9 -0
- package/dist/src/bridge/utils/index.d.ts.map +1 -1
- package/dist/src/bridge/utils/retry.d.ts +16 -0
- package/dist/src/bridge/utils/retry.d.ts.map +1 -1
- package/dist/src/bridge/utils/strategyDelegation.d.ts +69 -0
- package/dist/src/bridge/utils/strategyDelegation.d.ts.map +1 -0
- package/dist/src/bridge/utils/tokenIdUtils.d.ts +7 -0
- package/dist/src/bridge/utils/tokenIdUtils.d.ts.map +1 -1
- package/dist/src/bridge/utils/tokenMath.d.ts.map +1 -1
- package/dist/src/bridge/utils/tokenMetadataResolver.d.ts +97 -0
- package/dist/src/bridge/utils/tokenMetadataResolver.d.ts.map +1 -0
- package/dist/src/constants/endpoints.d.ts +453 -0
- package/dist/src/constants/endpoints.d.ts.map +1 -1
- package/dist/src/constants/error-messages.d.ts +1 -1
- package/dist/src/constants/error-messages.d.ts.map +1 -1
- package/dist/src/constants/jwt.d.ts +41 -0
- package/dist/src/constants/jwt.d.ts.map +1 -0
- package/dist/src/constants/sdk-defaults.d.ts +37 -0
- package/dist/src/constants/sdk-defaults.d.ts.map +1 -0
- package/dist/src/constants/version.generated.d.ts +1 -1
- package/dist/src/constants/version.generated.d.ts.map +1 -1
- package/dist/src/helpers/sdk.d.ts.map +1 -1
- package/dist/src/helpers/wallet.d.ts +4 -3
- package/dist/src/helpers/wallet.d.ts.map +1 -1
- package/dist/src/index.d.ts +70 -11
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/schemas/files.d.ts +2 -2
- package/dist/src/schemas/launchpad.d.ts +40 -8
- package/dist/src/schemas/launchpad.d.ts.map +1 -1
- package/dist/src/schemas/pagination.d.ts +7 -7
- package/dist/src/schemas/primitives.d.ts.map +1 -1
- package/dist/src/schemas/trade.d.ts +6 -6
- package/dist/src/schemas/user.d.ts +4 -4
- package/dist/src/schemas/validators.d.ts +15 -7
- package/dist/src/schemas/validators.d.ts.map +1 -1
- package/dist/src/services/AbstractCacheService.d.ts +227 -0
- package/dist/src/services/AbstractCacheService.d.ts.map +1 -0
- package/dist/src/services/AbstractTokenFetchService.d.ts +150 -0
- package/dist/src/services/AbstractTokenFetchService.d.ts.map +1 -0
- package/dist/src/services/ApiKeyService.d.ts +205 -0
- package/dist/src/services/ApiKeyService.d.ts.map +1 -0
- package/dist/src/services/BanService.d.ts +195 -0
- package/dist/src/services/BanService.d.ts.map +1 -0
- package/dist/src/services/BaseService.d.ts +50 -3
- package/dist/src/services/BaseService.d.ts.map +1 -1
- package/dist/src/services/BatchedCacheService.d.ts +132 -0
- package/dist/src/services/BatchedCacheService.d.ts.map +1 -0
- package/dist/src/services/BridgeableTokenCache.d.ts +32 -98
- package/dist/src/services/BridgeableTokenCache.d.ts.map +1 -1
- package/dist/src/services/BridgeableTokenService.d.ts +18 -13
- package/dist/src/services/BridgeableTokenService.d.ts.map +1 -1
- package/dist/src/services/BundleService.d.ts.map +1 -1
- package/dist/src/services/BundlerClientFactory.d.ts +32 -0
- package/dist/src/services/BundlerClientFactory.d.ts.map +1 -0
- package/dist/src/services/ChatMessagesService.d.ts +152 -0
- package/dist/src/services/ChatMessagesService.d.ts.map +1 -0
- package/dist/src/services/CommentService.d.ts +119 -0
- package/dist/src/services/CommentService.d.ts.map +1 -0
- package/dist/src/services/CommentsService.d.ts +155 -0
- package/dist/src/services/CommentsService.d.ts.map +1 -0
- package/dist/src/services/ContentFlagService.d.ts +212 -0
- package/dist/src/services/ContentFlagService.d.ts.map +1 -0
- package/dist/src/services/ContentReactionService.d.ts +175 -0
- package/dist/src/services/ContentReactionService.d.ts.map +1 -0
- package/dist/src/services/DexBackendClient.d.ts.map +1 -1
- package/dist/src/services/DexPoolService.d.ts +3 -3
- package/dist/src/services/DexPoolService.d.ts.map +1 -1
- package/dist/src/services/DexQuoteService.d.ts.map +1 -1
- package/dist/src/services/DexService.d.ts +2 -5
- package/dist/src/services/DexService.d.ts.map +1 -1
- package/dist/src/services/GSwapAssetService.d.ts +80 -0
- package/dist/src/services/GSwapAssetService.d.ts.map +1 -0
- package/dist/src/services/GSwapLiquidityMutationService.d.ts +140 -0
- package/dist/src/services/GSwapLiquidityMutationService.d.ts.map +1 -0
- package/dist/src/services/GSwapLiquidityQueryService.d.ts +87 -0
- package/dist/src/services/GSwapLiquidityQueryService.d.ts.map +1 -0
- package/dist/src/services/GSwapPoolCalculationService.d.ts +200 -0
- package/dist/src/services/GSwapPoolCalculationService.d.ts.map +1 -0
- package/dist/src/services/GSwapPoolQueryService.d.ts +116 -0
- package/dist/src/services/GSwapPoolQueryService.d.ts.map +1 -0
- package/dist/src/services/GSwapService.d.ts +14 -0
- package/dist/src/services/GSwapService.d.ts.map +1 -1
- package/dist/src/services/GSwapSwapService.d.ts +68 -0
- package/dist/src/services/GSwapSwapService.d.ts.map +1 -0
- package/dist/src/services/GalaChainBalanceService.d.ts +155 -0
- package/dist/src/services/GalaChainBalanceService.d.ts.map +1 -0
- package/dist/src/services/GalaChainGatewayClient.d.ts +32 -1
- package/dist/src/services/GalaChainGatewayClient.d.ts.map +1 -1
- package/dist/src/services/GalaChainLockService.d.ts +144 -0
- package/dist/src/services/GalaChainLockService.d.ts.map +1 -0
- package/dist/src/services/GalaChainService.d.ts +23 -106
- package/dist/src/services/GalaChainService.d.ts.map +1 -1
- package/dist/src/services/GalaChainTokenService.d.ts +108 -0
- package/dist/src/services/GalaChainTokenService.d.ts.map +1 -0
- package/dist/src/services/GalaChainTransferService.d.ts +205 -0
- package/dist/src/services/GalaChainTransferService.d.ts.map +1 -0
- package/dist/src/services/ImageService.d.ts +24 -8
- package/dist/src/services/ImageService.d.ts.map +1 -1
- package/dist/src/services/LaunchpadService.d.ts +77 -5
- package/dist/src/services/LaunchpadService.d.ts.map +1 -1
- package/dist/src/services/ModeratorService.d.ts +269 -0
- package/dist/src/services/ModeratorService.d.ts.map +1 -0
- package/dist/src/services/MultiPoolStateManager.d.ts +4 -6
- package/dist/src/services/MultiPoolStateManager.d.ts.map +1 -1
- package/dist/src/services/NetworkKeyedCacheService.d.ts +185 -0
- package/dist/src/services/NetworkKeyedCacheService.d.ts.map +1 -0
- package/dist/src/services/OverseerService.d.ts +322 -0
- package/dist/src/services/OverseerService.d.ts.map +1 -0
- package/dist/src/services/PoolCacheManager.d.ts +2 -2
- package/dist/src/services/PoolCacheManager.d.ts.map +1 -1
- package/dist/src/services/PoolService.d.ts +61 -7
- package/dist/src/services/PoolService.d.ts.map +1 -1
- package/dist/src/services/PoolStateManager.d.ts +2 -2
- package/dist/src/services/PoolStateManager.d.ts.map +1 -1
- package/dist/src/services/PriceHistoryService.d.ts.map +1 -1
- package/dist/src/services/SignatureService.d.ts.map +1 -1
- package/dist/src/services/StreamChatService.d.ts +378 -0
- package/dist/src/services/StreamChatService.d.ts.map +1 -0
- package/dist/src/services/StreamTokenServiceBase.d.ts +371 -0
- package/dist/src/services/StreamTokenServiceBase.d.ts.map +1 -0
- package/dist/src/services/StreamWebSocketService.d.ts +268 -0
- package/dist/src/services/StreamWebSocketService.d.ts.map +1 -0
- package/dist/src/services/StreamingEventService.d.ts +431 -0
- package/dist/src/services/StreamingEventService.d.ts.map +1 -0
- package/dist/src/services/StreamingService.d.ts +547 -0
- package/dist/src/services/StreamingService.d.ts.map +1 -0
- package/dist/src/services/SwapEventQueue.d.ts +2 -2
- package/dist/src/services/SwapEventQueue.d.ts.map +1 -1
- package/dist/src/services/TokenBanService.d.ts +214 -0
- package/dist/src/services/TokenBanService.d.ts.map +1 -0
- package/dist/src/services/TokenClassKeyService.d.ts.map +1 -1
- package/dist/src/services/TokenMetadataCache.d.ts +36 -27
- package/dist/src/services/TokenMetadataCache.d.ts.map +1 -1
- package/dist/src/services/TokenMetadataService.d.ts +24 -4
- package/dist/src/services/TokenMetadataService.d.ts.map +1 -1
- package/dist/src/services/TokenResolverService.d.ts.map +1 -1
- package/dist/src/services/TradeService.d.ts +73 -0
- package/dist/src/services/TradeService.d.ts.map +1 -1
- package/dist/src/services/UserService.d.ts +56 -3
- package/dist/src/services/UserService.d.ts.map +1 -1
- package/dist/src/services/WebSocketService.d.ts +3 -3
- package/dist/src/services/WebSocketService.d.ts.map +1 -1
- package/dist/src/services/WrapService.d.ts +18 -5
- package/dist/src/services/WrapService.d.ts.map +1 -1
- package/dist/src/services/WrappableTokenCache.d.ts +8 -36
- package/dist/src/services/WrappableTokenCache.d.ts.map +1 -1
- package/dist/src/services/WrappableTokenService.d.ts +18 -12
- package/dist/src/services/WrappableTokenService.d.ts.map +1 -1
- package/dist/src/services/shared/cache-helpers.d.ts +188 -0
- package/dist/src/services/shared/cache-helpers.d.ts.map +1 -0
- package/dist/src/services/shared/http-helpers.d.ts +146 -0
- package/dist/src/services/shared/http-helpers.d.ts.map +1 -0
- package/dist/src/services/shared/pagination-helpers.d.ts +157 -0
- package/dist/src/services/shared/pagination-helpers.d.ts.map +1 -0
- package/dist/src/services/shared/service-validators.d.ts +137 -0
- package/dist/src/services/shared/service-validators.d.ts.map +1 -0
- package/dist/src/services/shared/websocket-helpers.d.ts +158 -0
- package/dist/src/services/shared/websocket-helpers.d.ts.map +1 -0
- package/dist/src/test-constants.d.ts +29 -0
- package/dist/src/test-constants.d.ts.map +1 -0
- package/dist/src/types/api-key.dto.d.ts +300 -0
- package/dist/src/types/api-key.dto.d.ts.map +1 -0
- package/dist/src/types/backend-responses.d.ts +12 -0
- package/dist/src/types/backend-responses.d.ts.map +1 -1
- package/dist/src/types/ban.dto.d.ts +413 -0
- package/dist/src/types/ban.dto.d.ts.map +1 -0
- package/dist/src/types/burn.dto.d.ts +21 -0
- package/dist/src/types/burn.dto.d.ts.map +1 -1
- package/dist/src/types/chat-messages.dto.d.ts +193 -0
- package/dist/src/types/chat-messages.dto.d.ts.map +1 -0
- package/dist/src/types/comment.dto.d.ts +180 -0
- package/dist/src/types/comment.dto.d.ts.map +1 -0
- package/dist/src/types/comments.dto.d.ts +210 -0
- package/dist/src/types/comments.dto.d.ts.map +1 -0
- package/dist/src/types/common.d.ts +369 -0
- package/dist/src/types/common.d.ts.map +1 -1
- package/dist/src/types/constraints.d.ts +374 -0
- package/dist/src/types/constraints.d.ts.map +1 -0
- package/dist/src/types/content-flag.dto.d.ts +310 -0
- package/dist/src/types/content-flag.dto.d.ts.map +1 -0
- package/dist/src/types/content-reactions.dto.d.ts +132 -0
- package/dist/src/types/content-reactions.dto.d.ts.map +1 -0
- package/dist/src/types/dex-pool.dto.d.ts +13 -37
- package/dist/src/types/dex-pool.dto.d.ts.map +1 -1
- package/dist/src/types/dto.d.ts +8 -0
- package/dist/src/types/dto.d.ts.map +1 -1
- package/dist/src/types/galachain-api.types.d.ts +30 -0
- package/dist/src/types/galachain-api.types.d.ts.map +1 -1
- package/dist/src/types/gswap-responses.types.d.ts.map +1 -1
- package/dist/src/types/launchpad.dto.d.ts +234 -131
- package/dist/src/types/launchpad.dto.d.ts.map +1 -1
- package/dist/src/types/launchpad.validation.d.ts.map +1 -1
- package/dist/src/types/lock.dto.d.ts +20 -35
- package/dist/src/types/lock.dto.d.ts.map +1 -1
- package/dist/src/types/moderator.dto.d.ts +581 -0
- package/dist/src/types/moderator.dto.d.ts.map +1 -0
- package/dist/src/types/options.dto.d.ts +25 -115
- package/dist/src/types/options.dto.d.ts.map +1 -1
- package/dist/src/types/overseer.dto.d.ts +420 -0
- package/dist/src/types/overseer.dto.d.ts.map +1 -0
- package/dist/src/types/pool.dto.d.ts +106 -0
- package/dist/src/types/pool.dto.d.ts.map +1 -0
- package/dist/src/types/result.types.d.ts +3 -2
- package/dist/src/types/result.types.d.ts.map +1 -1
- package/dist/src/types/session-auth.dto.d.ts +91 -0
- package/dist/src/types/session-auth.dto.d.ts.map +1 -0
- package/dist/src/types/stream-chat.dto.d.ts +815 -0
- package/dist/src/types/stream-chat.dto.d.ts.map +1 -0
- package/dist/src/types/streaming-events.dto.d.ts +586 -0
- package/dist/src/types/streaming-events.dto.d.ts.map +1 -0
- package/dist/src/types/streaming.dto.d.ts +1141 -0
- package/dist/src/types/streaming.dto.d.ts.map +1 -0
- package/dist/src/types/token-ban.dto.d.ts +195 -0
- package/dist/src/types/token-ban.dto.d.ts.map +1 -0
- package/dist/src/types/trade.dto.d.ts +21 -61
- package/dist/src/types/trade.dto.d.ts.map +1 -1
- package/dist/src/types/trades-query.dto.d.ts +127 -0
- package/dist/src/types/trades-query.dto.d.ts.map +1 -0
- package/dist/src/types/transfer.dto.d.ts +20 -15
- package/dist/src/types/transfer.dto.d.ts.map +1 -1
- package/dist/src/types/user.dto.d.ts +185 -73
- package/dist/src/types/user.dto.d.ts.map +1 -1
- package/dist/src/types/wrappable-token.dto.d.ts +6 -2
- package/dist/src/types/wrappable-token.dto.d.ts.map +1 -1
- package/dist/src/utils/LiquidityEventExtractor.d.ts.map +1 -1
- package/dist/src/utils/Logger.d.ts.map +1 -1
- package/dist/src/utils/MonitoringMetrics.d.ts.map +1 -1
- package/dist/src/utils/PoolKeyNormalizer.d.ts.map +1 -1
- package/dist/src/utils/ReconnectionManager.d.ts +142 -0
- package/dist/src/utils/ReconnectionManager.d.ts.map +1 -0
- package/dist/src/utils/SignatureHelper.d.ts +9 -0
- package/dist/src/utils/SignatureHelper.d.ts.map +1 -1
- package/dist/src/utils/SwapEventExtractor.d.ts.map +1 -1
- package/dist/src/utils/adapters.d.ts.map +1 -1
- package/dist/src/utils/address-formatter.d.ts +317 -0
- package/dist/src/utils/address-formatter.d.ts.map +1 -0
- package/dist/src/utils/agent-config.d.ts.map +1 -1
- package/dist/src/utils/amount-validator.d.ts +268 -0
- package/dist/src/utils/amount-validator.d.ts.map +1 -0
- package/dist/src/utils/api-patterns.d.ts +347 -0
- package/dist/src/utils/api-patterns.d.ts.map +1 -0
- package/dist/src/utils/array-helpers.d.ts +115 -0
- package/dist/src/utils/array-helpers.d.ts.map +1 -0
- package/dist/src/utils/async-patterns.d.ts +272 -0
- package/dist/src/utils/async-patterns.d.ts.map +1 -0
- package/dist/src/utils/auto-pagination.d.ts +195 -2
- package/dist/src/utils/auto-pagination.d.ts.map +1 -1
- package/dist/src/utils/bignumber-helpers.d.ts +119 -13
- package/dist/src/utils/bignumber-helpers.d.ts.map +1 -1
- package/dist/src/utils/bignumber-pool-cache.d.ts.map +1 -1
- package/dist/src/utils/bondingCurveCalculations.d.ts.map +1 -1
- package/dist/src/utils/cacheWarmingHelpers.d.ts +2 -2
- package/dist/src/utils/cacheWarmingHelpers.d.ts.map +1 -1
- package/dist/src/utils/data-transform-patterns.d.ts +393 -0
- package/dist/src/utils/data-transform-patterns.d.ts.map +1 -0
- package/dist/src/utils/date-utils.d.ts +166 -0
- package/dist/src/utils/date-utils.d.ts.map +1 -1
- package/dist/src/utils/delimiter-parser.d.ts +139 -0
- package/dist/src/utils/delimiter-parser.d.ts.map +1 -0
- package/dist/src/utils/error-factories.d.ts +346 -1
- package/dist/src/utils/error-factories.d.ts.map +1 -1
- package/dist/src/utils/error-handling-patterns.d.ts +390 -0
- package/dist/src/utils/error-handling-patterns.d.ts.map +1 -0
- package/dist/src/utils/error-patterns.d.ts +360 -0
- package/dist/src/utils/error-patterns.d.ts.map +1 -0
- package/dist/src/utils/error-utils.d.ts +250 -0
- package/dist/src/utils/error-utils.d.ts.map +1 -1
- package/dist/src/utils/error-wrapper.d.ts +208 -0
- package/dist/src/utils/error-wrapper.d.ts.map +1 -0
- package/dist/src/utils/errors.d.ts +70 -0
- package/dist/src/utils/errors.d.ts.map +1 -1
- package/dist/src/utils/http-factory.d.ts +36 -0
- package/dist/src/utils/http-factory.d.ts.map +1 -0
- package/dist/src/utils/http.d.ts.map +1 -1
- package/dist/src/utils/load-env.d.ts.map +1 -1
- package/dist/src/utils/multipart.d.ts.map +1 -1
- package/dist/src/utils/numeric-patterns.d.ts +289 -0
- package/dist/src/utils/numeric-patterns.d.ts.map +1 -0
- package/dist/src/utils/numeric-wrappers.d.ts +146 -0
- package/dist/src/utils/numeric-wrappers.d.ts.map +1 -0
- package/dist/src/utils/object-extractors.d.ts +115 -0
- package/dist/src/utils/object-extractors.d.ts.map +1 -0
- package/dist/src/utils/object-patterns.d.ts +81 -0
- package/dist/src/utils/object-patterns.d.ts.map +1 -0
- package/dist/src/utils/pagination-helpers.d.ts +230 -0
- package/dist/src/utils/pagination-helpers.d.ts.map +1 -0
- package/dist/src/utils/pool-pair-parser.d.ts +3 -1
- package/dist/src/utils/pool-pair-parser.d.ts.map +1 -1
- package/dist/src/utils/pool-state-validator.d.ts.map +1 -1
- package/dist/src/utils/position-filters.d.ts +1 -2
- package/dist/src/utils/position-filters.d.ts.map +1 -1
- package/dist/src/utils/query-params.d.ts +0 -16
- package/dist/src/utils/query-params.d.ts.map +1 -1
- package/dist/src/utils/response-handlers.d.ts +149 -20
- package/dist/src/utils/response-handlers.d.ts.map +1 -1
- package/dist/src/utils/response-helpers.d.ts +28 -0
- package/dist/src/utils/response-helpers.d.ts.map +1 -0
- package/dist/src/utils/response-normalizers.d.ts +27 -49
- package/dist/src/utils/response-normalizers.d.ts.map +1 -1
- package/dist/src/utils/safe-parsers.d.ts +487 -0
- package/dist/src/utils/safe-parsers.d.ts.map +1 -0
- package/dist/src/utils/service-validators.d.ts +268 -0
- package/dist/src/utils/service-validators.d.ts.map +1 -0
- package/dist/src/utils/slippage-utils.d.ts.map +1 -1
- package/dist/src/utils/string-patterns.d.ts +404 -0
- package/dist/src/utils/string-patterns.d.ts.map +1 -0
- package/dist/src/utils/string-transforms.d.ts +89 -0
- package/dist/src/utils/string-transforms.d.ts.map +1 -0
- package/dist/src/utils/string-utils.d.ts +108 -0
- package/dist/src/utils/string-utils.d.ts.map +1 -0
- package/dist/src/utils/swap-delta-calculator.d.ts.map +1 -1
- package/dist/src/utils/tick-crossing-handler.d.ts.map +1 -1
- package/dist/src/utils/token-format-converter.d.ts +22 -8
- package/dist/src/utils/token-format-converter.d.ts.map +1 -1
- package/dist/src/utils/token-parser.d.ts +2 -2
- package/dist/src/utils/token-parser.d.ts.map +1 -1
- package/dist/src/utils/token-stringification.d.ts +168 -0
- package/dist/src/utils/token-stringification.d.ts.map +1 -0
- package/dist/src/utils/tokenNameNormalizer.d.ts +96 -0
- package/dist/src/utils/tokenNameNormalizer.d.ts.map +1 -0
- package/dist/src/utils/tokenNormalizer.d.ts +8 -45
- package/dist/src/utils/tokenNormalizer.d.ts.map +1 -1
- package/dist/src/utils/transfer-validation.d.ts +1 -1
- package/dist/src/utils/transfer-validation.d.ts.map +1 -1
- package/dist/src/utils/type-guard-factory.d.ts +260 -0
- package/dist/src/utils/type-guard-factory.d.ts.map +1 -0
- package/dist/src/utils/unique-key-generator.d.ts +148 -0
- package/dist/src/utils/unique-key-generator.d.ts.map +1 -0
- package/dist/src/utils/validation-helpers.d.ts +906 -183
- package/dist/src/utils/validation-helpers.d.ts.map +1 -1
- package/dist/src/utils/validation-patterns.d.ts +745 -0
- package/dist/src/utils/validation-patterns.d.ts.map +1 -0
- package/dist/src/utils/validation.d.ts +2 -30
- package/dist/src/utils/validation.d.ts.map +1 -1
- package/dist/src/utils/wallet.d.ts +12 -1
- package/dist/src/utils/wallet.d.ts.map +1 -1
- package/dist/src/utils/websocket-patterns.d.ts +681 -0
- package/dist/src/utils/websocket-patterns.d.ts.map +1 -0
- package/dist/src/utils/websocket-validators.d.ts.map +1 -1
- package/package.json +86 -19
- package/dist/src/bridge/strategies/index.d.ts +0 -9
- package/dist/src/bridge/strategies/index.d.ts.map +0 -1
- package/dist/src/constants/counts.d.ts +0 -66
- package/dist/src/constants/counts.d.ts.map +0 -1
- package/dist/src/services/WebSocketManager.d.ts +0 -99
- package/dist/src/services/WebSocketManager.d.ts.map +0 -1
- package/dist/src/types/eip712-types.d.ts +0 -140
- package/dist/src/types/eip712-types.d.ts.map +0 -1
- package/dist/src/types/pool-state-manager-config.dto.d.ts +0 -103
- package/dist/src/types/pool-state-manager-config.dto.d.ts.map +0 -1
- package/dist/src/utils/number-utils.d.ts +0 -94
- package/dist/src/utils/number-utils.d.ts.map +0 -1
- package/dist/src/utils/precision-math.d.ts +0 -37
- package/dist/src/utils/precision-math.d.ts.map +0 -1
|
@@ -7,6 +7,18 @@
|
|
|
7
7
|
* @category Utilities
|
|
8
8
|
* @since 3.6.2
|
|
9
9
|
*/
|
|
10
|
+
import { type TokenNameConstraint } from '../types/constraints';
|
|
11
|
+
/**
|
|
12
|
+
* Pagination bounds structure (required fields)
|
|
13
|
+
*
|
|
14
|
+
* This interface defines the required pagination bounds.
|
|
15
|
+
*/
|
|
16
|
+
export interface PaginationBounds {
|
|
17
|
+
MIN_PAGE: number;
|
|
18
|
+
MAX_PAGE: number;
|
|
19
|
+
MIN_LIMIT: number;
|
|
20
|
+
MAX_LIMIT: number;
|
|
21
|
+
}
|
|
10
22
|
/**
|
|
11
23
|
* Pagination constraints structure
|
|
12
24
|
*
|
|
@@ -14,56 +26,11 @@
|
|
|
14
26
|
* used across the SDK (e.g., USER_CONSTRAINTS, TRADE_CONSTRAINTS).
|
|
15
27
|
*/
|
|
16
28
|
export interface PaginationConstraints {
|
|
17
|
-
PAGINATION:
|
|
18
|
-
MIN_PAGE: number;
|
|
19
|
-
MAX_PAGE: number;
|
|
20
|
-
MIN_LIMIT: number;
|
|
21
|
-
MAX_LIMIT: number;
|
|
22
|
-
};
|
|
29
|
+
PAGINATION: PaginationBounds;
|
|
23
30
|
}
|
|
24
31
|
/**
|
|
25
32
|
* Validates pagination parameters against constraint bounds
|
|
26
33
|
*
|
|
27
|
-
* This utility consolidates the duplicate pagination validation logic found across
|
|
28
|
-
* multiple services (UserService, TradeService).
|
|
29
|
-
*
|
|
30
|
-
* ## Replaces Patterns
|
|
31
|
-
*
|
|
32
|
-
* This function replaces duplicate pagination validation across services:
|
|
33
|
-
*
|
|
34
|
-
* ### Before (Duplicate Private Methods):
|
|
35
|
-
* ```typescript
|
|
36
|
-
* // UserService.ts (lines 403-427)
|
|
37
|
-
* private validateUserPagination(options: { page: number; limit: number }): void {
|
|
38
|
-
* if (typeof options.page !== 'number' ||
|
|
39
|
-
* options.page < USER_CONSTRAINTS.PAGINATION.MIN_PAGE ||
|
|
40
|
-
* options.page > USER_CONSTRAINTS.PAGINATION.MAX_PAGE) {
|
|
41
|
-
* throw new ValidationError(...);
|
|
42
|
-
* }
|
|
43
|
-
* if (typeof options.limit !== 'number' ||
|
|
44
|
-
* options.limit < USER_CONSTRAINTS.PAGINATION.MIN_LIMIT ||
|
|
45
|
-
* options.limit > USER_CONSTRAINTS.PAGINATION.MAX_LIMIT) {
|
|
46
|
-
* throw new ValidationError(...);
|
|
47
|
-
* }
|
|
48
|
-
* }
|
|
49
|
-
*
|
|
50
|
-
* // TradeService.ts (lines 121-145) - IDENTICAL STRUCTURE
|
|
51
|
-
* private validateTradePagination(options: { page: number; limit: number }): void {
|
|
52
|
-
* // Same pattern, different constraints
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* ### After (Single Source of Truth):
|
|
57
|
-
* ```typescript
|
|
58
|
-
* // UserService.ts
|
|
59
|
-
* import { assertValidPagination } from '../utils/validation-helpers';
|
|
60
|
-
* assertValidPagination(page, limit, USER_CONSTRAINTS);
|
|
61
|
-
*
|
|
62
|
-
* // TradeService.ts
|
|
63
|
-
* import { assertValidPagination } from '../utils/validation-helpers';
|
|
64
|
-
* assertValidPagination(page, limit, TRADE_CONSTRAINTS);
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
34
|
* @param page - Page number to validate (1-based)
|
|
68
35
|
* @param limit - Results per page limit to validate
|
|
69
36
|
* @param constraints - Constraint object with PAGINATION bounds
|
|
@@ -115,33 +82,12 @@ export declare const ADDRESS_PATTERNS: {
|
|
|
115
82
|
readonly ETH_ADDRESS: RegExp;
|
|
116
83
|
/** Backend address format: eth| followed by optional 0x and 40 hexadecimal characters */
|
|
117
84
|
readonly BACKEND_ADDRESS: RegExp;
|
|
118
|
-
/** Client address format: client| followed by alphanumeric characters (variable length) */
|
|
85
|
+
/** Client address format: client| followed by alphanumeric characters, hyphens, underscores (variable length) */
|
|
119
86
|
readonly CLIENT_ADDRESS: RegExp;
|
|
120
87
|
};
|
|
121
88
|
/**
|
|
122
89
|
* Type guard to check if a value is a non-empty string
|
|
123
90
|
*
|
|
124
|
-
* This utility consolidates the common validation pattern found across the SDK:
|
|
125
|
-
* checking if a value exists, is a string, and is not empty after trimming.
|
|
126
|
-
*
|
|
127
|
-
* ## Replaces Pattern
|
|
128
|
-
*
|
|
129
|
-
* ### Before (Repeated ~40 times):
|
|
130
|
-
* ```typescript
|
|
131
|
-
* if (!value || typeof value !== 'string' || value.trim().length === 0) {
|
|
132
|
-
* throw new ValidationError('Value required', 'fieldName');
|
|
133
|
-
* }
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
* ### After (Single Source of Truth):
|
|
137
|
-
* ```typescript
|
|
138
|
-
* import { isNonEmptyString } from '../utils/validation-helpers';
|
|
139
|
-
*
|
|
140
|
-
* if (!isNonEmptyString(value)) {
|
|
141
|
-
* throw new ValidationError('Value required', 'fieldName');
|
|
142
|
-
* }
|
|
143
|
-
* ```
|
|
144
|
-
*
|
|
145
91
|
* @param value - Value to check
|
|
146
92
|
* @returns True if value is a string with non-whitespace content
|
|
147
93
|
*
|
|
@@ -172,98 +118,87 @@ export declare const ADDRESS_PATTERNS: {
|
|
|
172
118
|
*/
|
|
173
119
|
export declare function isNonEmptyString(value: unknown): value is string;
|
|
174
120
|
/**
|
|
175
|
-
*
|
|
121
|
+
* Check if a value is "empty" (null, undefined, or empty string)
|
|
176
122
|
*
|
|
177
|
-
* This
|
|
178
|
-
*
|
|
123
|
+
* This is a common check used across parsers and validators to determine
|
|
124
|
+
* if a value should be treated as "not provided". Consolidates the pattern:
|
|
125
|
+
* `value === null || value === undefined || value === ''`
|
|
179
126
|
*
|
|
180
|
-
*
|
|
127
|
+
* @param value - Value to check
|
|
128
|
+
* @returns True if value is null, undefined, or empty string
|
|
181
129
|
*
|
|
182
|
-
*
|
|
130
|
+
* @example Basic usage
|
|
183
131
|
* ```typescript
|
|
184
|
-
* //
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* }
|
|
132
|
+
* isEmptyValue(null); // true
|
|
133
|
+
* isEmptyValue(undefined); // true
|
|
134
|
+
* isEmptyValue(''); // true
|
|
135
|
+
* isEmptyValue('hello'); // false
|
|
136
|
+
* isEmptyValue(0); // false (0 is a valid value)
|
|
137
|
+
* isEmptyValue(false); // false (false is a valid value)
|
|
191
138
|
* ```
|
|
192
139
|
*
|
|
193
|
-
*
|
|
140
|
+
* @example In parser functions
|
|
194
141
|
* ```typescript
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
142
|
+
* function safeParseFloat(value: unknown, fallback: number = 0): number {
|
|
143
|
+
* if (isEmptyValue(value)) {
|
|
144
|
+
* return fallback;
|
|
145
|
+
* }
|
|
146
|
+
* // ... parsing logic
|
|
199
147
|
* }
|
|
200
148
|
* ```
|
|
201
149
|
*
|
|
202
|
-
* @
|
|
203
|
-
|
|
150
|
+
* @since 6.17.0
|
|
151
|
+
*/
|
|
152
|
+
export declare function isEmptyValue(value: unknown): value is null | undefined | '';
|
|
153
|
+
/**
|
|
154
|
+
* Check if a value is nullish (null or undefined, but NOT empty string)
|
|
204
155
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* isValidAddress('0x123'); // false (too short)
|
|
209
|
-
* ```
|
|
156
|
+
* Use this when you want to distinguish between "not provided" (null/undefined)
|
|
157
|
+
* and "explicitly empty" (empty string). For most parsing scenarios, use
|
|
158
|
+
* `isEmptyValue()` instead which treats empty string as equivalent to null.
|
|
210
159
|
*
|
|
211
|
-
* @
|
|
212
|
-
*
|
|
213
|
-
* isValidAddress('eth|1234567890abcdef1234567890abcdef12345678'); // true
|
|
214
|
-
* isValidAddress('eth|123'); // false (too short)
|
|
215
|
-
* ```
|
|
160
|
+
* @param value - Value to check
|
|
161
|
+
* @returns True if value is null or undefined
|
|
216
162
|
*
|
|
217
|
-
* @example
|
|
163
|
+
* @example Basic usage
|
|
218
164
|
* ```typescript
|
|
219
|
-
*
|
|
220
|
-
*
|
|
165
|
+
* isNullish(null); // true
|
|
166
|
+
* isNullish(undefined); // true
|
|
167
|
+
* isNullish(''); // false (empty string is NOT nullish)
|
|
168
|
+
* isNullish('hello'); // false
|
|
169
|
+
* isNullish(0); // false
|
|
221
170
|
* ```
|
|
171
|
+
*
|
|
172
|
+
* @since 6.17.0
|
|
222
173
|
*/
|
|
223
|
-
export declare function
|
|
174
|
+
export declare function isNullish(value: unknown): value is null | undefined;
|
|
224
175
|
/**
|
|
225
|
-
*
|
|
176
|
+
* Validates optional pagination parameters (page and limit)
|
|
226
177
|
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* ## Replaces Patterns
|
|
232
|
-
*
|
|
233
|
-
* ### Before (Duplicate Private Method):
|
|
234
|
-
* ```typescript
|
|
235
|
-
* // GalaChainService.ts (lines 708-713)
|
|
236
|
-
* private formatAddressForBackend(address: string): string {
|
|
237
|
-
* if (address.startsWith('0x')) {
|
|
238
|
-
* return `eth|${address.slice(2)}`;
|
|
239
|
-
* }
|
|
240
|
-
* return address;
|
|
241
|
-
* }
|
|
242
|
-
* ```
|
|
178
|
+
* @param page - Optional page number to validate (1-based)
|
|
179
|
+
* @param limit - Optional results per page to validate
|
|
180
|
+
* @param maxLimit - Maximum allowed limit (default: 100)
|
|
181
|
+
* @throws ValidationError if page or limit is invalid
|
|
243
182
|
*
|
|
244
|
-
*
|
|
183
|
+
* @example Basic usage
|
|
245
184
|
* ```typescript
|
|
246
|
-
* import {
|
|
185
|
+
* import { validatePaginationOptions } from '../utils/validation-helpers';
|
|
247
186
|
*
|
|
248
|
-
*
|
|
187
|
+
* function validateListOptions(options: ListOptions): void {
|
|
188
|
+
* validatePaginationOptions(options.page, options.limit);
|
|
189
|
+
* // Validation passed - proceed with fetch
|
|
190
|
+
* }
|
|
249
191
|
* ```
|
|
250
192
|
*
|
|
251
|
-
* @
|
|
252
|
-
* @returns Address in backend format (eth|40hex)
|
|
253
|
-
*
|
|
254
|
-
* @example Ethereum address conversion
|
|
193
|
+
* @example With custom max limit
|
|
255
194
|
* ```typescript
|
|
256
|
-
*
|
|
257
|
-
*
|
|
195
|
+
* // For endpoints with smaller page sizes
|
|
196
|
+
* validatePaginationOptions(options.page, options.limit, 50);
|
|
258
197
|
* ```
|
|
259
198
|
*
|
|
260
|
-
* @
|
|
261
|
-
* ```typescript
|
|
262
|
-
* formatAddressForBackend('eth|1234567890abcdef1234567890abcdef12345678');
|
|
263
|
-
* // Returns: 'eth|1234567890abcdef1234567890abcdef12345678' (unchanged)
|
|
264
|
-
* ```
|
|
199
|
+
* @since 6.4.0
|
|
265
200
|
*/
|
|
266
|
-
export declare function
|
|
201
|
+
export declare function validatePaginationOptions(page?: number, limit?: number, maxLimit?: number): void;
|
|
267
202
|
/**
|
|
268
203
|
* Type guard function signature
|
|
269
204
|
* A function that checks if a value matches a specific type and narrows the type accordingly
|
|
@@ -272,56 +207,6 @@ export type TypeGuard<T> = (value: unknown) => value is T;
|
|
|
272
207
|
/**
|
|
273
208
|
* Creates a validation function from a type guard
|
|
274
209
|
*
|
|
275
|
-
* This utility eliminates the need for boilerplate validation wrapper methods
|
|
276
|
-
* that simply call a type guard and throw an error. Common pattern across services.
|
|
277
|
-
*
|
|
278
|
-
* ## Replaces Patterns
|
|
279
|
-
*
|
|
280
|
-
* ### Before (Multiple Duplicate Wrapper Methods):
|
|
281
|
-
* ```typescript
|
|
282
|
-
* // GalaChainService.ts - 3 separate validation methods (~30 lines total)
|
|
283
|
-
* private validateFetchPoolDetailsData(data: FetchPoolDetailsData): void {
|
|
284
|
-
* if (!isFetchPoolDetailsData(data)) {
|
|
285
|
-
* throw new ValidationError(
|
|
286
|
-
* 'Invalid fetch pool details data',
|
|
287
|
-
* 'data',
|
|
288
|
-
* 'INVALID_DATA'
|
|
289
|
-
* );
|
|
290
|
-
* }
|
|
291
|
-
* }
|
|
292
|
-
*
|
|
293
|
-
* private validateTransferGalaData(data: TransferGalaData): void {
|
|
294
|
-
* if (!isTransferGalaData(data)) {
|
|
295
|
-
* throw new ValidationError(
|
|
296
|
-
* 'Invalid transfer GALA data',
|
|
297
|
-
* 'data',
|
|
298
|
-
* 'INVALID_DATA'
|
|
299
|
-
* );
|
|
300
|
-
* }
|
|
301
|
-
* }
|
|
302
|
-
*
|
|
303
|
-
* private validateTransferTokenData(data: TransferTokenData): void {
|
|
304
|
-
* if (!isTransferTokenData(data)) {
|
|
305
|
-
* throw new ValidationError(
|
|
306
|
-
* 'Invalid transfer token data',
|
|
307
|
-
* 'data',
|
|
308
|
-
* 'INVALID_DATA'
|
|
309
|
-
* );
|
|
310
|
-
* }
|
|
311
|
-
* }
|
|
312
|
-
* ```
|
|
313
|
-
*
|
|
314
|
-
* ### After (Single Factory Function):
|
|
315
|
-
* ```typescript
|
|
316
|
-
* import { createValidator } from '../utils/validation-helpers';
|
|
317
|
-
*
|
|
318
|
-
* // Create validators inline
|
|
319
|
-
* const data = req.body;
|
|
320
|
-
* createValidator(isFetchPoolDetailsData, 'fetch pool details data')(data);
|
|
321
|
-
* createValidator(isTransferGalaData, 'transfer GALA data')(data);
|
|
322
|
-
* createValidator(isTransferTokenData, 'transfer token data')(data);
|
|
323
|
-
* ```
|
|
324
|
-
*
|
|
325
210
|
* @param typeGuard - Type guard function that validates the data type
|
|
326
211
|
* @param dataTypeName - Human-readable name for error messages (e.g., 'transfer data', 'pool details')
|
|
327
212
|
* @param fieldName - Optional field name for error context (defaults to 'data')
|
|
@@ -365,6 +250,109 @@ export type TypeGuard<T> = (value: unknown) => value is T;
|
|
|
365
250
|
* ```
|
|
366
251
|
*/
|
|
367
252
|
export declare function createValidator<T>(typeGuard: TypeGuard<T>, dataTypeName: string, fieldName?: string, errorCode?: string): (value: unknown) => asserts value is T;
|
|
253
|
+
/**
|
|
254
|
+
* Creates a type guard function for string enums
|
|
255
|
+
*
|
|
256
|
+
* This utility eliminates boilerplate for enum validation functions that follow the pattern:
|
|
257
|
+
* ```typescript
|
|
258
|
+
* function isEnumValue(value: unknown): value is MyEnum {
|
|
259
|
+
* return typeof value === 'string' && Object.values(MyEnum).includes(value as MyEnum);
|
|
260
|
+
* }
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* ## Replaces Patterns
|
|
264
|
+
*
|
|
265
|
+
* ### Before (Duplicate across DTOs):
|
|
266
|
+
* ```typescript
|
|
267
|
+
* // content-flag.dto.ts
|
|
268
|
+
* export function isContentType(value: unknown): value is ContentType {
|
|
269
|
+
* return typeof value === 'string' && Object.values(ContentType).includes(value as ContentType);
|
|
270
|
+
* }
|
|
271
|
+
* export function isFlagReason(value: unknown): value is FlagReason {
|
|
272
|
+
* return typeof value === 'string' && Object.values(FlagReason).includes(value as FlagReason);
|
|
273
|
+
* }
|
|
274
|
+
* // ... repeated for each enum
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
277
|
+
* ### After (Single Source of Truth):
|
|
278
|
+
* ```typescript
|
|
279
|
+
* import { createEnumTypeGuard } from '../utils/validation-helpers';
|
|
280
|
+
* export const isContentType = createEnumTypeGuard(ContentType);
|
|
281
|
+
* export const isFlagReason = createEnumTypeGuard(FlagReason);
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @param enumObj - The TypeScript enum object to create a type guard for
|
|
285
|
+
* @returns A type guard function that checks if a value is a member of the enum
|
|
286
|
+
*
|
|
287
|
+
* @example Basic usage with ContentType enum
|
|
288
|
+
* ```typescript
|
|
289
|
+
* import { createEnumTypeGuard } from '../utils/validation-helpers';
|
|
290
|
+
*
|
|
291
|
+
* enum ContentType {
|
|
292
|
+
* CHAT_MESSAGE = 'CHAT_MESSAGE',
|
|
293
|
+
* COMMENT = 'COMMENT',
|
|
294
|
+
* STREAM = 'STREAM',
|
|
295
|
+
* }
|
|
296
|
+
*
|
|
297
|
+
* export const isContentType = createEnumTypeGuard(ContentType);
|
|
298
|
+
*
|
|
299
|
+
* // Usage
|
|
300
|
+
* if (isContentType(value)) {
|
|
301
|
+
* // value is narrowed to ContentType
|
|
302
|
+
* }
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @since 6.0.0
|
|
306
|
+
*/
|
|
307
|
+
export declare function createEnumTypeGuard<T extends Record<string, string>>(enumObj: T): (value: unknown) => value is T[keyof T];
|
|
308
|
+
/**
|
|
309
|
+
* Derives an array of values from a const object
|
|
310
|
+
*
|
|
311
|
+
* This utility eliminates the repetitive pattern of creating parallel arrays
|
|
312
|
+
* from const objects using `Object.values()`.
|
|
313
|
+
*
|
|
314
|
+
* ## Replaces Patterns
|
|
315
|
+
*
|
|
316
|
+
* ### Before (Duplicate across DTOs):
|
|
317
|
+
* ```typescript
|
|
318
|
+
* // api-key.dto.ts
|
|
319
|
+
* export const API_KEY_ROLE = { MODERATOR: 'MODERATOR', MANAGER: 'MANAGER' } as const;
|
|
320
|
+
* export type ApiKeyRole = (typeof API_KEY_ROLE)[keyof typeof API_KEY_ROLE];
|
|
321
|
+
* export const API_KEY_ROLES: ApiKeyRole[] = Object.values(API_KEY_ROLE);
|
|
322
|
+
*
|
|
323
|
+
* // moderator.dto.ts
|
|
324
|
+
* export const MODERATOR_ROLE = { ... } as const;
|
|
325
|
+
* export type ModeratorRole = (typeof MODERATOR_ROLE)[keyof typeof MODERATOR_ROLE];
|
|
326
|
+
* export const MODERATOR_ROLES: ModeratorRole[] = Object.values(MODERATOR_ROLE);
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* ### After (Single Source of Truth):
|
|
330
|
+
* ```typescript
|
|
331
|
+
* import { enumValues } from '../utils/validation-helpers';
|
|
332
|
+
* export const API_KEY_ROLES = enumValues(API_KEY_ROLE);
|
|
333
|
+
* export const MODERATOR_ROLES = enumValues(MODERATOR_ROLE);
|
|
334
|
+
* ```
|
|
335
|
+
*
|
|
336
|
+
* @param enumObj - The const object to extract values from
|
|
337
|
+
* @returns A typed array of all values in the const object
|
|
338
|
+
*
|
|
339
|
+
* @example Basic usage with role const
|
|
340
|
+
* ```typescript
|
|
341
|
+
* import { enumValues } from '../utils/validation-helpers';
|
|
342
|
+
*
|
|
343
|
+
* const API_KEY_ROLE = {
|
|
344
|
+
* MODERATOR: 'MODERATOR',
|
|
345
|
+
* MANAGER: 'MANAGER',
|
|
346
|
+
* } as const;
|
|
347
|
+
*
|
|
348
|
+
* type ApiKeyRole = (typeof API_KEY_ROLE)[keyof typeof API_KEY_ROLE];
|
|
349
|
+
* const API_KEY_ROLES = enumValues(API_KEY_ROLE); // ['MODERATOR', 'MANAGER']
|
|
350
|
+
* // Type: ApiKeyRole[]
|
|
351
|
+
* ```
|
|
352
|
+
*
|
|
353
|
+
* @since 6.11.0
|
|
354
|
+
*/
|
|
355
|
+
export declare function enumValues<T extends Record<string, string>>(enumObj: T): T[keyof T][];
|
|
368
356
|
/**
|
|
369
357
|
* Result of mutual exclusivity validation
|
|
370
358
|
*/
|
|
@@ -440,4 +428,739 @@ export declare function validateMutualExclusive(obj: Record<string, unknown>, fi
|
|
|
440
428
|
/** Whether empty strings should count as "not provided" (default: true) */
|
|
441
429
|
treatEmptyAsNull?: boolean;
|
|
442
430
|
}): MutualExclusivityResult;
|
|
431
|
+
export type { TokenNameConstraint };
|
|
432
|
+
/**
|
|
433
|
+
* Validates a launchpad token name using configurable constraints
|
|
434
|
+
*
|
|
435
|
+
* Consolidates duplicate token name validation logic found across multiple DTO files:
|
|
436
|
+
* - streaming.dto.ts (validateStreamingTokenName)
|
|
437
|
+
* - content-flag.dto.ts (validateFlagTokenName)
|
|
438
|
+
* - comment.dto.ts (inline validation)
|
|
439
|
+
* - ban.dto.ts (inline validation)
|
|
440
|
+
* - moderator.dto.ts (inline validation)
|
|
441
|
+
*
|
|
442
|
+
* ## Usage
|
|
443
|
+
*
|
|
444
|
+
* ### With default constraints (3-20 alphanumeric)
|
|
445
|
+
* ```typescript
|
|
446
|
+
* validateLaunchpadTokenName(tokenName); // Uses LAUNCHPAD_TOKEN_NAME_CONSTRAINT
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* ### With custom constraints from DTO
|
|
450
|
+
* ```typescript
|
|
451
|
+
* import { STREAMING_CONSTRAINTS } from '../types/streaming.dto';
|
|
452
|
+
* validateLaunchpadTokenName(tokenName, 'tokenName', STREAMING_CONSTRAINTS.TOKEN_NAME);
|
|
453
|
+
* ```
|
|
454
|
+
*
|
|
455
|
+
* ### With custom field name for error messages
|
|
456
|
+
* ```typescript
|
|
457
|
+
* validateLaunchpadTokenName(options.tokenName, 'tokenName', BAN_CONSTRAINTS.TOKEN_NAME);
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @param tokenName - Token name to validate
|
|
461
|
+
* @param field - Field name for error messages (defaults to 'tokenName')
|
|
462
|
+
* @param constraint - Token name constraint configuration (defaults to LAUNCHPAD_TOKEN_NAME_CONSTRAINT)
|
|
463
|
+
* @throws {ValidationError} If token name is invalid (empty, too short, too long, or invalid format)
|
|
464
|
+
*
|
|
465
|
+
* @since 6.4.0
|
|
466
|
+
*/
|
|
467
|
+
export declare function validateLaunchpadTokenName(tokenName: string, field?: string, constraint?: TokenNameConstraint): void;
|
|
468
|
+
/**
|
|
469
|
+
* Validates an optional token name (allows undefined/null, but validates if present)
|
|
470
|
+
*
|
|
471
|
+
* Use this for optional token name fields that should be validated when provided.
|
|
472
|
+
* Consolidates duplicate logic from tokenNameValidator.ts.
|
|
473
|
+
*
|
|
474
|
+
* @param tokenName - The token name to validate (may be undefined/null)
|
|
475
|
+
* @param field - The field name for error messages (default: 'tokenName')
|
|
476
|
+
* @param constraint - Token name constraint (default: LAUNCHPAD_TOKEN_NAME_CONSTRAINT)
|
|
477
|
+
* @throws {ValidationError} If token name is provided but invalid
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* // No error - undefined is allowed
|
|
482
|
+
* validateOptionalTokenName(undefined);
|
|
483
|
+
*
|
|
484
|
+
* // Throws ValidationError - provided but invalid
|
|
485
|
+
* validateOptionalTokenName('ab');
|
|
486
|
+
*
|
|
487
|
+
* // Success - valid token name
|
|
488
|
+
* validateOptionalTokenName('myToken123');
|
|
489
|
+
* ```
|
|
490
|
+
*
|
|
491
|
+
* @since 6.12.0
|
|
492
|
+
*/
|
|
493
|
+
export declare function validateOptionalTokenName(tokenName: unknown, field?: string, constraint?: TokenNameConstraint): void;
|
|
494
|
+
/**
|
|
495
|
+
* Checks if a token name is valid without throwing
|
|
496
|
+
*
|
|
497
|
+
* Use this for conditional checks where you don't want exceptions.
|
|
498
|
+
* Consolidates duplicate logic from tokenNameValidator.ts.
|
|
499
|
+
*
|
|
500
|
+
* @param tokenName - The token name to check
|
|
501
|
+
* @param constraint - Token name constraint (default: LAUNCHPAD_TOKEN_NAME_CONSTRAINT)
|
|
502
|
+
* @returns true if valid, false otherwise
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```typescript
|
|
506
|
+
* if (isValidTokenName(userInput)) {
|
|
507
|
+
* // Proceed with token lookup
|
|
508
|
+
* } else {
|
|
509
|
+
* // Show validation error to user
|
|
510
|
+
* }
|
|
511
|
+
* ```
|
|
512
|
+
*
|
|
513
|
+
* @since 6.12.0
|
|
514
|
+
*/
|
|
515
|
+
export declare function isValidTokenName(tokenName: unknown, constraint?: TokenNameConstraint): tokenName is string;
|
|
516
|
+
/**
|
|
517
|
+
* Validates a token name with constraint-specific error messages
|
|
518
|
+
*
|
|
519
|
+
* Enhanced version that provides the exact length constraint in error messages.
|
|
520
|
+
* This is the recommended function for service methods.
|
|
521
|
+
*
|
|
522
|
+
* @param tokenName - Token name to validate
|
|
523
|
+
* @param field - Field name for error messages (default: 'tokenName')
|
|
524
|
+
* @param constraint - Token name constraint with MIN_LENGTH, MAX_LENGTH, PATTERN
|
|
525
|
+
* @throws {ValidationError} If token name is invalid
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```typescript
|
|
529
|
+
* // Throws: "tokenName must be 3-20 alphanumeric characters"
|
|
530
|
+
* validateTokenName('ab', 'tokenName', LAUNCHPAD_TOKEN_NAME_CONSTRAINT);
|
|
531
|
+
* ```
|
|
532
|
+
*
|
|
533
|
+
* @since 6.12.0
|
|
534
|
+
*/
|
|
535
|
+
export declare function validateTokenName(tokenName: unknown, field?: string, constraint?: TokenNameConstraint): void;
|
|
536
|
+
/**
|
|
537
|
+
* Field validator configuration for structural type guards
|
|
538
|
+
*
|
|
539
|
+
* Specifies how to validate a single field in a type guard.
|
|
540
|
+
*
|
|
541
|
+
* @since 6.12.0
|
|
542
|
+
*/
|
|
543
|
+
export interface FieldTypeValidator {
|
|
544
|
+
/** Field name to validate */
|
|
545
|
+
field: string;
|
|
546
|
+
/** Expected type: 'string', 'number', 'boolean', 'object' */
|
|
547
|
+
type: 'string' | 'number' | 'boolean' | 'object';
|
|
548
|
+
/** Whether null is an acceptable value (default: false) */
|
|
549
|
+
nullable?: boolean;
|
|
550
|
+
/** Whether undefined is acceptable (field may be missing) (default: false) */
|
|
551
|
+
optional?: boolean;
|
|
552
|
+
/** Custom validator for complex checks (return true if valid) */
|
|
553
|
+
validator?: (value: unknown) => boolean;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Creates a structural type guard function from field specifications
|
|
557
|
+
*
|
|
558
|
+
* This factory eliminates repetitive type guard boilerplate found across DTO files.
|
|
559
|
+
* Each type guard follows the same pattern: check object exists, cast to Record,
|
|
560
|
+
* then validate each field's type.
|
|
561
|
+
*
|
|
562
|
+
* ## Before (Duplicate across DTOs):
|
|
563
|
+
* ```typescript
|
|
564
|
+
* export function isBanData(obj: unknown): obj is BanData {
|
|
565
|
+
* if (!obj || typeof obj !== 'object') return false;
|
|
566
|
+
* const o = obj as Record<string, unknown>;
|
|
567
|
+
* return (
|
|
568
|
+
* typeof o.id === 'number' &&
|
|
569
|
+
* typeof o.userAddress === 'string' &&
|
|
570
|
+
* typeof o.bannedBy === 'string' &&
|
|
571
|
+
* typeof o.createdAt === 'string' &&
|
|
572
|
+
* typeof o.isPermanent === 'boolean' &&
|
|
573
|
+
* (o.tokenName === null || typeof o.tokenName === 'string') &&
|
|
574
|
+
* (o.reason === null || typeof o.reason === 'string') &&
|
|
575
|
+
* (o.expiresAt === null || typeof o.expiresAt === 'string')
|
|
576
|
+
* );
|
|
577
|
+
* }
|
|
578
|
+
* ```
|
|
579
|
+
*
|
|
580
|
+
* ## After (Single declaration):
|
|
581
|
+
* ```typescript
|
|
582
|
+
* export const isBanData = createStructuralTypeGuard<BanData>([
|
|
583
|
+
* { field: 'id', type: 'number' },
|
|
584
|
+
* { field: 'userAddress', type: 'string' },
|
|
585
|
+
* { field: 'bannedBy', type: 'string' },
|
|
586
|
+
* { field: 'createdAt', type: 'string' },
|
|
587
|
+
* { field: 'isPermanent', type: 'boolean' },
|
|
588
|
+
* { field: 'tokenName', type: 'string', nullable: true },
|
|
589
|
+
* { field: 'reason', type: 'string', nullable: true },
|
|
590
|
+
* { field: 'expiresAt', type: 'string', nullable: true },
|
|
591
|
+
* ]);
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @param fields - Array of field validators specifying required fields and their types
|
|
595
|
+
* @returns A type guard function that checks if an object matches the specified structure
|
|
596
|
+
*
|
|
597
|
+
* @example Basic usage with required fields
|
|
598
|
+
* ```typescript
|
|
599
|
+
* const isUser = createStructuralTypeGuard<User>([
|
|
600
|
+
* { field: 'id', type: 'number' },
|
|
601
|
+
* { field: 'name', type: 'string' },
|
|
602
|
+
* { field: 'isActive', type: 'boolean' },
|
|
603
|
+
* ]);
|
|
604
|
+
*
|
|
605
|
+
* if (isUser(data)) {
|
|
606
|
+
* console.log(data.name); // data is typed as User
|
|
607
|
+
* }
|
|
608
|
+
* ```
|
|
609
|
+
*
|
|
610
|
+
* @example With nullable and optional fields
|
|
611
|
+
* ```typescript
|
|
612
|
+
* const isComment = createStructuralTypeGuard<Comment>([
|
|
613
|
+
* { field: 'id', type: 'number' },
|
|
614
|
+
* { field: 'content', type: 'string' },
|
|
615
|
+
* { field: 'parentId', type: 'number', nullable: true },
|
|
616
|
+
* { field: 'metadata', type: 'object', optional: true },
|
|
617
|
+
* ]);
|
|
618
|
+
* ```
|
|
619
|
+
*
|
|
620
|
+
* @since 6.12.0
|
|
621
|
+
*/
|
|
622
|
+
export declare function createStructuralTypeGuard<T>(fields: FieldTypeValidator[]): (obj: unknown) => obj is T;
|
|
623
|
+
import type { FieldValidatorConfig, OptionsValidatorWithErrors } from '../types/common';
|
|
624
|
+
/**
|
|
625
|
+
* Common field validators for reuse across validation functions
|
|
626
|
+
*
|
|
627
|
+
* These validators can be used with `createOptionsValidator` or directly.
|
|
628
|
+
*
|
|
629
|
+
* @since 6.12.0
|
|
630
|
+
*/
|
|
631
|
+
export declare const commonValidators: {
|
|
632
|
+
/**
|
|
633
|
+
* Creates a validator for required non-empty string fields
|
|
634
|
+
*/
|
|
635
|
+
requiredString: (field: string) => (value: unknown) => string | undefined;
|
|
636
|
+
/**
|
|
637
|
+
* Creates a validator for max length string fields
|
|
638
|
+
*/
|
|
639
|
+
maxLength: (field: string, max: number) => (value: unknown) => string | undefined;
|
|
640
|
+
/**
|
|
641
|
+
* Creates a validator for positive integer fields
|
|
642
|
+
*/
|
|
643
|
+
positiveInteger: (field: string) => (value: unknown) => string | undefined;
|
|
644
|
+
/**
|
|
645
|
+
* Creates a validator for required positive integer fields
|
|
646
|
+
*/
|
|
647
|
+
requiredPositiveInteger: (field: string) => (value: unknown) => string | undefined;
|
|
648
|
+
/**
|
|
649
|
+
* Creates a validator for enum values
|
|
650
|
+
*/
|
|
651
|
+
enumValue: <T extends string>(field: string, validValues: readonly T[]) => (value: unknown) => string | undefined;
|
|
652
|
+
/**
|
|
653
|
+
* Creates a validator for required enum values
|
|
654
|
+
*/
|
|
655
|
+
requiredEnumValue: <T extends string>(field: string, validValues: readonly T[]) => (value: unknown) => string | undefined;
|
|
656
|
+
/**
|
|
657
|
+
* Creates a validator for ISO date strings
|
|
658
|
+
*/
|
|
659
|
+
isoDate: (field: string) => (value: unknown) => string | undefined;
|
|
660
|
+
/**
|
|
661
|
+
* Creates a validator for wallet addresses
|
|
662
|
+
*/
|
|
663
|
+
walletAddress: (field: string, required?: boolean) => (value: unknown) => string | undefined;
|
|
664
|
+
};
|
|
665
|
+
/**
|
|
666
|
+
* Creates an options validator from field configurations
|
|
667
|
+
*
|
|
668
|
+
* This factory eliminates duplicate validation boilerplate across DTO files.
|
|
669
|
+
* Returns an array of error messages (empty if valid), which aligns with
|
|
670
|
+
* moderator.dto.ts and api-key.dto.ts validation patterns.
|
|
671
|
+
*
|
|
672
|
+
* ## Usage
|
|
673
|
+
*
|
|
674
|
+
* ### Basic field validation
|
|
675
|
+
* ```typescript
|
|
676
|
+
* import { createOptionsValidator, commonValidators } from '../utils/validation-helpers';
|
|
677
|
+
*
|
|
678
|
+
* const validateCreateOptions = createOptionsValidator<CreateOptions>([
|
|
679
|
+
* { field: 'name', required: true, type: 'string' },
|
|
680
|
+
* { field: 'description', validator: commonValidators.maxLength('description', 255) },
|
|
681
|
+
* { field: 'status', validator: commonValidators.enumValue('status', ['active', 'inactive']) },
|
|
682
|
+
* ]);
|
|
683
|
+
*
|
|
684
|
+
* // Usage
|
|
685
|
+
* const errors = validateCreateOptions(options);
|
|
686
|
+
* if (errors.length > 0) {
|
|
687
|
+
* throw new ValidationError(errors[0], 'options', 'VALIDATION_FAILED');
|
|
688
|
+
* }
|
|
689
|
+
* ```
|
|
690
|
+
*
|
|
691
|
+
* ### With custom validators
|
|
692
|
+
* ```typescript
|
|
693
|
+
* const validateOptions = createOptionsValidator<MyOptions>([
|
|
694
|
+
* { field: 'tokenName', validator: (value) => {
|
|
695
|
+
* try {
|
|
696
|
+
* validateLaunchpadTokenName(value as string, 'tokenName');
|
|
697
|
+
* return undefined;
|
|
698
|
+
* } catch (e) {
|
|
699
|
+
* return (e as Error).message;
|
|
700
|
+
* }
|
|
701
|
+
* }},
|
|
702
|
+
* ]);
|
|
703
|
+
* ```
|
|
704
|
+
*
|
|
705
|
+
* @param configs - Array of field validator configurations
|
|
706
|
+
* @returns Validation function that returns an array of error messages
|
|
707
|
+
*
|
|
708
|
+
* @since 6.12.0
|
|
709
|
+
*/
|
|
710
|
+
export declare function createOptionsValidator<T extends Record<string, unknown>>(configs: FieldValidatorConfig[]): OptionsValidatorWithErrors<T>;
|
|
711
|
+
/**
|
|
712
|
+
* Regular expression pattern for validating decimal amount strings
|
|
713
|
+
*
|
|
714
|
+
* Matches positive decimal numbers like "123", "45.67", "0.001"
|
|
715
|
+
* Does NOT match negative numbers, leading/trailing dots, or scientific notation.
|
|
716
|
+
*
|
|
717
|
+
* @since 6.18.0
|
|
718
|
+
*/
|
|
719
|
+
export declare const DECIMAL_AMOUNT_PATTERN: RegExp;
|
|
720
|
+
/**
|
|
721
|
+
* Validates a decimal amount string
|
|
722
|
+
*
|
|
723
|
+
* Used for validating token amounts in transfer, lock, unlock, burn operations.
|
|
724
|
+
* Consolidates duplicate validation logic from transfer.dto.ts, lock.dto.ts, burn.dto.ts.
|
|
725
|
+
*
|
|
726
|
+
* @param amount - Amount string to validate
|
|
727
|
+
* @param fieldPath - Field path for error messages (e.g., 'amount', 'tokens[0].amount')
|
|
728
|
+
* @param options - Validation options
|
|
729
|
+
* @throws {ValidationError} If amount is invalid
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```typescript
|
|
733
|
+
* // Basic usage
|
|
734
|
+
* validateDecimalAmount(data.amount, 'amount');
|
|
735
|
+
*
|
|
736
|
+
* // In batch validation
|
|
737
|
+
* validateDecimalAmount(entry.amount, `tokens[${index}].amount`);
|
|
738
|
+
*
|
|
739
|
+
* // Allow zero
|
|
740
|
+
* validateDecimalAmount(data.amount, 'amount', { allowZero: true });
|
|
741
|
+
* ```
|
|
742
|
+
*
|
|
743
|
+
* @since 6.18.0
|
|
744
|
+
*/
|
|
745
|
+
export declare function validateDecimalAmount(amount: unknown, fieldPath: string, options?: {
|
|
746
|
+
allowZero?: boolean;
|
|
747
|
+
}): void;
|
|
748
|
+
/**
|
|
749
|
+
* Validates a token name against a regex pattern
|
|
750
|
+
*
|
|
751
|
+
* Used for validating token names in batch operations where full launchpad validation
|
|
752
|
+
* is not appropriate. Consolidates duplicate validation from lock.dto.ts, burn.dto.ts.
|
|
753
|
+
*
|
|
754
|
+
* @param tokenName - Token name to validate
|
|
755
|
+
* @param fieldPath - Field path for error messages (e.g., 'tokenName', 'tokens[0].tokenName')
|
|
756
|
+
* @param pattern - Regex pattern for validation
|
|
757
|
+
* @throws {ValidationError} If token name is invalid
|
|
758
|
+
*
|
|
759
|
+
* @example
|
|
760
|
+
* ```typescript
|
|
761
|
+
* import { TOKEN_NAME_PATTERN } from './constraints';
|
|
762
|
+
*
|
|
763
|
+
* // In batch validation
|
|
764
|
+
* if (entry.tokenName !== undefined) {
|
|
765
|
+
* validateTokenNamePattern(entry.tokenName, `tokens[${index}].tokenName`, TOKEN_NAME_PATTERN);
|
|
766
|
+
* }
|
|
767
|
+
* ```
|
|
768
|
+
*
|
|
769
|
+
* @since 6.18.0
|
|
770
|
+
*/
|
|
771
|
+
export declare function validateTokenNamePattern(tokenName: unknown, fieldPath: string, pattern: RegExp): void;
|
|
772
|
+
/**
|
|
773
|
+
* Validates that a batch array meets size constraints
|
|
774
|
+
*
|
|
775
|
+
* Consolidates duplicate validation from lock.dto.ts, burn.dto.ts for batch operations.
|
|
776
|
+
*
|
|
777
|
+
* @param array - Array to validate
|
|
778
|
+
* @param fieldName - Field name for error messages (e.g., 'tokens')
|
|
779
|
+
* @param maxSize - Maximum allowed array size
|
|
780
|
+
* @throws {ValidationError} If array is invalid or exceeds max size
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* validateBatchArray(data.tokens, 'tokens', MAX_LOCK_BATCH_SIZE);
|
|
785
|
+
* ```
|
|
786
|
+
*
|
|
787
|
+
* @since 6.18.0
|
|
788
|
+
*/
|
|
789
|
+
export declare function validateBatchArray(array: unknown, fieldName: string, maxSize: number): void;
|
|
790
|
+
/**
|
|
791
|
+
* Validates an optional unique key string
|
|
792
|
+
*
|
|
793
|
+
* Consolidates duplicate validation from transfer.dto.ts, lock.dto.ts, burn.dto.ts.
|
|
794
|
+
*
|
|
795
|
+
* @param uniqueKey - Unique key to validate (may be undefined)
|
|
796
|
+
* @param maxLength - Maximum allowed length
|
|
797
|
+
* @throws {ValidationError} If unique key is invalid
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* import { UNIQUE_KEY_CONSTRAINT } from './constraints';
|
|
802
|
+
*
|
|
803
|
+
* validateUniqueKey(data.uniqueKey, UNIQUE_KEY_CONSTRAINT.MAX_LENGTH);
|
|
804
|
+
* ```
|
|
805
|
+
*
|
|
806
|
+
* @since 6.18.0
|
|
807
|
+
*/
|
|
808
|
+
export declare function validateUniqueKey(uniqueKey: unknown, maxLength: number): void;
|
|
809
|
+
/**
|
|
810
|
+
* Validates an optional private key string
|
|
811
|
+
*
|
|
812
|
+
* Simple type check for optional private key override.
|
|
813
|
+
* Consolidates duplicate validation from transfer.dto.ts, lock.dto.ts, burn.dto.ts.
|
|
814
|
+
*
|
|
815
|
+
* @param privateKey - Private key to validate (may be undefined)
|
|
816
|
+
* @throws {ValidationError} If private key is not a string
|
|
817
|
+
*
|
|
818
|
+
* @since 6.18.0
|
|
819
|
+
*/
|
|
820
|
+
export declare function validateOptionalPrivateKey(privateKey: unknown): void;
|
|
821
|
+
/**
|
|
822
|
+
* Validates that at least one of two token identifier fields is provided
|
|
823
|
+
*
|
|
824
|
+
* Common pattern in batch operations where either tokenId or tokenName is required.
|
|
825
|
+
* Consolidates duplicate validation from lock.dto.ts, burn.dto.ts.
|
|
826
|
+
*
|
|
827
|
+
* @param entry - Object containing tokenId and/or tokenName
|
|
828
|
+
* @param fieldPath - Base field path for error messages (e.g., 'tokens[0]')
|
|
829
|
+
* @throws {ValidationError} If neither tokenId nor tokenName is provided
|
|
830
|
+
*
|
|
831
|
+
* @example
|
|
832
|
+
* ```typescript
|
|
833
|
+
* validateTokenIdentifier(entry, `tokens[${index}]`);
|
|
834
|
+
* ```
|
|
835
|
+
*
|
|
836
|
+
* @since 6.18.0
|
|
837
|
+
*/
|
|
838
|
+
export declare function validateTokenIdentifier(entry: {
|
|
839
|
+
tokenId?: unknown;
|
|
840
|
+
tokenName?: unknown;
|
|
841
|
+
}, fieldPath: string): void;
|
|
842
|
+
/**
|
|
843
|
+
* NOTE: The primary `isValidAddress()` function is in address-formatter.ts
|
|
844
|
+
*
|
|
845
|
+
* Import it from there:
|
|
846
|
+
* ```typescript
|
|
847
|
+
* import { isValidAddress } from './address-formatter';
|
|
848
|
+
* ```
|
|
849
|
+
*
|
|
850
|
+
* This consolidation ensures all address validation uses a single,
|
|
851
|
+
* well-tested implementation with ADDRESS_PATTERNS for consistency.
|
|
852
|
+
*/
|
|
853
|
+
/**
|
|
854
|
+
* Throws ValidationError if required field is null/undefined with customizable messages
|
|
855
|
+
*
|
|
856
|
+
* Use this to validate that required fields are present. Supports generic type
|
|
857
|
+
* narrowing so TypeScript knows the value is not null/undefined after this check.
|
|
858
|
+
*
|
|
859
|
+
* @template T The type of the value being validated
|
|
860
|
+
* @param value The value to check (can be T, null, or undefined)
|
|
861
|
+
* @param fieldName Internal field name for error codes (e.g., 'wallet', 'signatureHelper')
|
|
862
|
+
* @param displayName Optional user-friendly display name for error messages (e.g., 'Wallet instance')
|
|
863
|
+
* @returns The value if it's not null/undefined (strongly typed as T)
|
|
864
|
+
* @throws {ValidationError} If value is null or undefined with fieldName and error code REQUIRED
|
|
865
|
+
*
|
|
866
|
+
* @example
|
|
867
|
+
* ```typescript
|
|
868
|
+
* // Simple validation
|
|
869
|
+
* const wallet = throwIfMissing(this.wallet, 'wallet', 'Wallet instance');
|
|
870
|
+
* // wallet is now guaranteed to be non-null by TypeScript
|
|
871
|
+
*
|
|
872
|
+
* // Multi-field validation
|
|
873
|
+
* throwIfMissing(this.wallet, 'wallet', 'Wallet instance');
|
|
874
|
+
* throwIfMissing(this.signatureHelper, 'signatureHelper', 'Signature helper');
|
|
875
|
+
* // Both are now guaranteed non-null
|
|
876
|
+
*
|
|
877
|
+
* // Generic type preservation
|
|
878
|
+
* interface Config { apiKey: string }
|
|
879
|
+
* const config = throwIfMissing<Config>(userConfig, 'config', 'Configuration object');
|
|
880
|
+
* // config is now Config (not Config | null | undefined)
|
|
881
|
+
* ```
|
|
882
|
+
*
|
|
883
|
+
* @since 3.50.0
|
|
884
|
+
*/
|
|
885
|
+
export declare function throwIfMissing<T>(value: T | null | undefined, fieldName: string, displayName?: string): T;
|
|
886
|
+
/**
|
|
887
|
+
* Check if array has no elements (length === 0)
|
|
888
|
+
*
|
|
889
|
+
* Provides a readable way to check for empty arrays. Handles null/undefined
|
|
890
|
+
* gracefully by returning true (treating them as "empty").
|
|
891
|
+
*
|
|
892
|
+
* @template T The type of array elements
|
|
893
|
+
* @param arr The array to check (can be T[], null, or undefined)
|
|
894
|
+
* @returns True if array is null, undefined, or has length === 0; false otherwise
|
|
895
|
+
*
|
|
896
|
+
* @example Basic empty check
|
|
897
|
+
* ```typescript
|
|
898
|
+
* import { isEmptyArray } from '@gala-chain/launchpad-sdk';
|
|
899
|
+
*
|
|
900
|
+
* const tokens = []; // or null, or undefined
|
|
901
|
+
*
|
|
902
|
+
* if (isEmptyArray(tokens)) {
|
|
903
|
+
* console.log('No tokens to process');
|
|
904
|
+
* return;
|
|
905
|
+
* }
|
|
906
|
+
* ```
|
|
907
|
+
*
|
|
908
|
+
* @example In conditional logic
|
|
909
|
+
* ```typescript
|
|
910
|
+
* import { isEmptyArray } from '@gala-chain/launchpad-sdk';
|
|
911
|
+
*
|
|
912
|
+
* if (!symbols || isEmptyArray(symbols)) {
|
|
913
|
+
* throw new ValidationError('At least one symbol is required');
|
|
914
|
+
* }
|
|
915
|
+
* ```
|
|
916
|
+
*
|
|
917
|
+
* @example With different array types
|
|
918
|
+
* ```typescript
|
|
919
|
+
* import { isEmptyArray } from '@gala-chain/launchpad-sdk';
|
|
920
|
+
*
|
|
921
|
+
* // Works with objects
|
|
922
|
+
* if (isEmptyArray(this.tokenInstances)) return undefined;
|
|
923
|
+
*
|
|
924
|
+
* // Works with strings
|
|
925
|
+
* if (isEmptyArray(errors)) {
|
|
926
|
+
* console.log('Validation passed');
|
|
927
|
+
* }
|
|
928
|
+
*
|
|
929
|
+
* // Works with numbers
|
|
930
|
+
* const amounts: number[] = [];
|
|
931
|
+
* if (isEmptyArray(amounts)) {
|
|
932
|
+
* console.log('No amounts provided');
|
|
933
|
+
* }
|
|
934
|
+
* ```
|
|
935
|
+
*
|
|
936
|
+
* @since 3.50.0
|
|
937
|
+
*/
|
|
938
|
+
export declare function isEmptyArray<T>(arr: T[] | null | undefined): boolean;
|
|
939
|
+
/**
|
|
940
|
+
* Check if string is empty or contains only whitespace
|
|
941
|
+
*
|
|
942
|
+
* A concise alternative to `str.trim().length === 0` or `!str || !str.trim()`.
|
|
943
|
+
* Returns true if the string is null, undefined, empty, or contains only whitespace characters.
|
|
944
|
+
* Whitespace includes spaces, tabs, line breaks, carriage returns, form feeds, and non-breaking spaces.
|
|
945
|
+
*
|
|
946
|
+
* @param value String to check
|
|
947
|
+
* @returns true if string is empty or only contains whitespace
|
|
948
|
+
*
|
|
949
|
+
* @example Basic check
|
|
950
|
+
* ```typescript
|
|
951
|
+
* import { isEmptyOrWhitespace } from '@gala-chain/launchpad-sdk';
|
|
952
|
+
*
|
|
953
|
+
* if (isEmptyOrWhitespace(userInput)) {
|
|
954
|
+
* console.log('Please provide valid input');
|
|
955
|
+
* }
|
|
956
|
+
* ```
|
|
957
|
+
*
|
|
958
|
+
* @example Validation in form handlers
|
|
959
|
+
* ```typescript
|
|
960
|
+
* const validateReason = (reason: string) => {
|
|
961
|
+
* if (isEmptyOrWhitespace(reason)) {
|
|
962
|
+
* throw new Error('Reason is required');
|
|
963
|
+
* }
|
|
964
|
+
* return reason.trim();
|
|
965
|
+
* };
|
|
966
|
+
* ```
|
|
967
|
+
*
|
|
968
|
+
* @example Filtering whitespace-only values
|
|
969
|
+
* ```typescript
|
|
970
|
+
* const values = ['hello', ' ', '', 'world', '\t\n'];
|
|
971
|
+
* const filtered = values.filter(v => !isEmptyOrWhitespace(v));
|
|
972
|
+
* // Result: ['hello', 'world']
|
|
973
|
+
* ```
|
|
974
|
+
*
|
|
975
|
+
* @example Conditional logic
|
|
976
|
+
* ```typescript
|
|
977
|
+
* const displayName = !isEmptyOrWhitespace(nickname) ? nickname : fullName;
|
|
978
|
+
* ```
|
|
979
|
+
*
|
|
980
|
+
* @since 3.50.0
|
|
981
|
+
*/
|
|
982
|
+
export declare function isEmptyOrWhitespace(value: string): boolean;
|
|
983
|
+
/**
|
|
984
|
+
* Supported DEX fee tiers in basis points
|
|
985
|
+
*
|
|
986
|
+
* Basis points (bps) are used for precise fee tier representation.
|
|
987
|
+
* 1 basis point = 0.01% = 1/100th of a percent.
|
|
988
|
+
*
|
|
989
|
+
* @constant
|
|
990
|
+
* @example
|
|
991
|
+
* ```typescript
|
|
992
|
+
* import { FEE_TIERS } from '@gala-chain/launchpad-sdk';
|
|
993
|
+
*
|
|
994
|
+
* const fees = [FEE_TIERS.LOW, FEE_TIERS.MEDIUM, FEE_TIERS.HIGH];
|
|
995
|
+
* // [500, 3000, 10000]
|
|
996
|
+
*
|
|
997
|
+
* const feeName = {
|
|
998
|
+
* [FEE_TIERS.LOW]: '0.05%',
|
|
999
|
+
* [FEE_TIERS.MEDIUM]: '0.30%',
|
|
1000
|
+
* [FEE_TIERS.HIGH]: '1.00%'
|
|
1001
|
+
* };
|
|
1002
|
+
* ```
|
|
1003
|
+
*
|
|
1004
|
+
* @since 5.20.0
|
|
1005
|
+
*/
|
|
1006
|
+
export declare const FEE_TIERS: {
|
|
1007
|
+
readonly LOW: 500;
|
|
1008
|
+
readonly MEDIUM: 3000;
|
|
1009
|
+
readonly HIGH: 10000;
|
|
1010
|
+
};
|
|
1011
|
+
/**
|
|
1012
|
+
* Type-safe fee tier validation assertion
|
|
1013
|
+
*
|
|
1014
|
+
* Validates that a value is one of the recognized fee tiers (500, 3000, 10000).
|
|
1015
|
+
* Throws ValidationError if the value is not a valid fee tier.
|
|
1016
|
+
*
|
|
1017
|
+
* Uses enumValidationWithObjectValues for consistent enum validation.
|
|
1018
|
+
*
|
|
1019
|
+
* @param value - Value to validate as a fee tier
|
|
1020
|
+
* @param field - Optional field name for error messages (default: 'feeTier')
|
|
1021
|
+
* @throws ValidationError if value is not a recognized fee tier
|
|
1022
|
+
*
|
|
1023
|
+
* @example Basic validation
|
|
1024
|
+
* ```typescript
|
|
1025
|
+
* import { validateFeeTier } from '@gala-chain/launchpad-sdk';
|
|
1026
|
+
*
|
|
1027
|
+
* function createPool(fee: number) {
|
|
1028
|
+
* validateFeeTier(fee);
|
|
1029
|
+
* // Safe to use fee
|
|
1030
|
+
* }
|
|
1031
|
+
* ```
|
|
1032
|
+
*
|
|
1033
|
+
* @example With custom field name
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* try {
|
|
1036
|
+
* validateFeeTier(5000, 'poolFee');
|
|
1037
|
+
* } catch (error) {
|
|
1038
|
+
* console.log(error.message); // 'Invalid poolFee: 5000'
|
|
1039
|
+
* }
|
|
1040
|
+
* ```
|
|
1041
|
+
*
|
|
1042
|
+
* @example In form validation
|
|
1043
|
+
* ```typescript
|
|
1044
|
+
* const validatePoolForm = (data: PoolFormData) => {
|
|
1045
|
+
* try {
|
|
1046
|
+
* validateFeeTier(data.fee, 'fee');
|
|
1047
|
+
* } catch (error) {
|
|
1048
|
+
* return { field: 'fee', error: 'Invalid fee tier' };
|
|
1049
|
+
* }
|
|
1050
|
+
* };
|
|
1051
|
+
* ```
|
|
1052
|
+
*
|
|
1053
|
+
* @since 5.20.0
|
|
1054
|
+
*/
|
|
1055
|
+
export declare function validateFeeTier(value: unknown, field?: string): void;
|
|
1056
|
+
/**
|
|
1057
|
+
* Type guard to check if value is a valid fee tier
|
|
1058
|
+
*
|
|
1059
|
+
* Returns true if value is one of the recognized fee tiers (500, 3000, 10000).
|
|
1060
|
+
* Returns false for any other value including null, undefined, and invalid numbers.
|
|
1061
|
+
*
|
|
1062
|
+
* Use this for conditional logic and filtering without throwing errors.
|
|
1063
|
+
*
|
|
1064
|
+
* @param value - Value to check
|
|
1065
|
+
* @returns true if value is a recognized fee tier
|
|
1066
|
+
*
|
|
1067
|
+
* @example Conditional logic
|
|
1068
|
+
* ```typescript
|
|
1069
|
+
* import { isValidFeeTier } from '@gala-chain/launchpad-sdk';
|
|
1070
|
+
*
|
|
1071
|
+
* const userFee = getUserInput();
|
|
1072
|
+
* if (isValidFeeTier(userFee)) {
|
|
1073
|
+
* createPool({ fee: userFee });
|
|
1074
|
+
* } else {
|
|
1075
|
+
* showError('Please select a valid fee tier');
|
|
1076
|
+
* }
|
|
1077
|
+
* ```
|
|
1078
|
+
*
|
|
1079
|
+
* @example Filtering
|
|
1080
|
+
* ```typescript
|
|
1081
|
+
* const fees = [500, 1000, 3000, 5000, 10000];
|
|
1082
|
+
* const validFees = fees.filter(fee => isValidFeeTier(fee));
|
|
1083
|
+
* // Result: [500, 3000, 10000]
|
|
1084
|
+
* ```
|
|
1085
|
+
*
|
|
1086
|
+
* @example Type narrowing
|
|
1087
|
+
* ```typescript
|
|
1088
|
+
* const processFee = (value: unknown) => {
|
|
1089
|
+
* if (isValidFeeTier(value)) {
|
|
1090
|
+
* // TypeScript knows value is number here
|
|
1091
|
+
* const tier = value * 0.0001; // Convert to percentage
|
|
1092
|
+
* return tier;
|
|
1093
|
+
* }
|
|
1094
|
+
* return null;
|
|
1095
|
+
* };
|
|
1096
|
+
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* @since 5.20.0
|
|
1099
|
+
*/
|
|
1100
|
+
export declare function isValidFeeTier(value: unknown): value is number;
|
|
1101
|
+
/**
|
|
1102
|
+
* Normalize fee percentage to basis points
|
|
1103
|
+
*
|
|
1104
|
+
* Converts decimal percentage values (0.05, 0.30, 1.0) to basis points (500, 3000, 10000).
|
|
1105
|
+
* Useful for converting user-friendly percentage input to internal fee tier representation.
|
|
1106
|
+
*
|
|
1107
|
+
* Returns null if the percentage doesn't correspond to a standard fee tier.
|
|
1108
|
+
*
|
|
1109
|
+
* @param percentage - Fee percentage in decimal format (0.05 = 0.05%, 0.30 = 0.30%, etc.)
|
|
1110
|
+
* @returns Basis points equivalent (500, 3000, 10000) or null if not a standard tier
|
|
1111
|
+
*
|
|
1112
|
+
* @example Converting percentages
|
|
1113
|
+
* ```typescript
|
|
1114
|
+
* import { normalizeFeeTier } from '@gala-chain/launchpad-sdk';
|
|
1115
|
+
*
|
|
1116
|
+
* normalizeFeeTier(0.05) // Returns: 500
|
|
1117
|
+
* normalizeFeeTier(0.30) // Returns: 3000
|
|
1118
|
+
* normalizeFeeTier(1.00) // Returns: 10000
|
|
1119
|
+
* normalizeFeeTier(0.50) // Returns: null (not a standard tier)
|
|
1120
|
+
* ```
|
|
1121
|
+
*
|
|
1122
|
+
* @example Form input conversion
|
|
1123
|
+
* ```typescript
|
|
1124
|
+
* const handleFeeInput = (percentageInput: string) => {
|
|
1125
|
+
* const percentage = parseFloat(percentageInput) / 100;
|
|
1126
|
+
* const basisPoints = normalizeFeeTier(percentage);
|
|
1127
|
+
*
|
|
1128
|
+
* if (basisPoints === null) {
|
|
1129
|
+
* showError('Please select a standard fee tier');
|
|
1130
|
+
* return;
|
|
1131
|
+
* }
|
|
1132
|
+
*
|
|
1133
|
+
* createPool({ fee: basisPoints });
|
|
1134
|
+
* };
|
|
1135
|
+
* ```
|
|
1136
|
+
*
|
|
1137
|
+
* @example With fallback
|
|
1138
|
+
* ```typescript
|
|
1139
|
+
* const feeBasisPoints = normalizeFeeTier(userInput) ?? FEE_TIERS.MEDIUM;
|
|
1140
|
+
* ```
|
|
1141
|
+
*
|
|
1142
|
+
* @since 5.20.0
|
|
1143
|
+
*/
|
|
1144
|
+
export declare function normalizeFeeTier(percentage: number): number | null;
|
|
1145
|
+
/**
|
|
1146
|
+
* Extracts and concatenates error messages from Zod validation errors
|
|
1147
|
+
*
|
|
1148
|
+
* Consolidates the pattern of extracting error messages from Zod validation results:
|
|
1149
|
+
* `result.error.errors.map(e => e.message).join('; ')`
|
|
1150
|
+
*
|
|
1151
|
+
* @param errors - Array of Zod validation errors
|
|
1152
|
+
* @returns Array of error message strings
|
|
1153
|
+
*
|
|
1154
|
+
* @example
|
|
1155
|
+
* ```typescript
|
|
1156
|
+
* const result = schema.safeParse(data);
|
|
1157
|
+
* if (!result.success) {
|
|
1158
|
+
* const messages = collectValidationErrors(result.error.errors);
|
|
1159
|
+
* // Returns: ['Field is required', 'Must be at least 3 characters']
|
|
1160
|
+
* }
|
|
1161
|
+
* ```
|
|
1162
|
+
*
|
|
1163
|
+
* @since 6.30.0
|
|
1164
|
+
*/
|
|
1165
|
+
export declare function collectValidationErrors(errors: unknown[]): string[];
|
|
443
1166
|
//# sourceMappingURL=validation-helpers.d.ts.map
|