feat: improve XDM messenger developer experience #492
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improve XDM Messenger Developer Experience
Summary
Enhances the developer experience for XDM messenger functions by improving type safety, documentation, and testing. This PR refactors
initiateChannelandcloseChannelto use user-friendlyChaintypes instead of rawCodectypes, adds comprehensive JSDoc documentation with examples, and introduces explicit return type annotations across messenger and transfer functions.Motivation and Context
The XDM messenger functions (
initiateChannelandcloseChannel) previously required developers to work with low-level Polkadot.jsCodectypes and lacked proper documentation.This PR aligns the messenger functions with the existing patterns established in
transfer.tsandinfo.ts, providing:Chaintype ('consensus' | { domainId: number })Implementation Details
Type Safety Improvements
packages/auto-xdm/src/messenger.ts:initiateChannelparameter fromCodectoChaintypecloseChannelparameters fromCodecandstringtoChainandnumber | string | bigintSubmittableExtrinsic<'promise', ISubmittableResult>chainToChainIdCodechelper for internal type conversionasynctosync(functions only create transactions, don't submit them)packages/auto-xdm/src/transfer.ts:SubmittableExtrinsic<'promise', ISubmittableResult>Documentation Enhancements
Both
initiateChannelandcloseChannelnow include:Testing
integration-tests/suites/auto-xdm/messenger.test.ts(new file):initiateChannel: verifies transaction creation, submission, and channel openingcloseChannel: verifies transaction creation, submission, and channel closingwaitUntilhelperintegration-tests/helpers/xdm.ts:setupXDMhelper to useinitiateChannelwrapper function instead of raw API calls