Repository navigation
refactor(client): compose action factories without as unknown casts - #224
Open
HusseinAdeiza wants to merge 1 commit into
Open
HusseinAdeiza wants to merge 1 commit into
HusseinAdeiza wants to merge 1 commit into
Conversation
Every action factory was declared against the full `GenLayerClient`, so `createClient` had to launder each intermediate step through `as unknown as GenLayerClient<GenLayerChain>`: seven double-casts that disabled type checking exactly where the composition is most fragile. Each factory only reads a slice of the client, so those slices are now named (`ClientRequester`, `TransactionActionInput`, `TransactionReader`, `ContractWriter`, `ChainSwitcher`) and declared as the factory parameters. `createClient` type-checks hop by hop and needs a single narrowing assertion on the return. Two real mismatches surfaced once the casts stopped hiding them: - `transactionActions` reads viem's `getTransaction` and then installs its own GenLayer-typed override as a returned method, so its input cannot be typed as the override it produces (`TransactionActionInput`). - `ClientConfig.chain` was a loose structural type, so `GenLayerChain` never propagated and every chain consumer needed a cast. No behaviour change. `ClientRequestFn` keeps checking method names and argument shapes; the factories cast their own results either way. Tests: 209 passed, `tsc --noEmit` clean, typecheck clean, build and check:chains clean. `tests/client-action-surfaces.test.ts` fails to compile against the pre-fix tree (5 errors), so it pins the narrowed surfaces. Closes genlayerlabs#30
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #30
What
createClientcomposed seven action factories, and every hop went throughas unknown as GenLayerClient<GenLayerChain>. Each factory was declared against the fullGenLayerClienteven though it reads a small slice of it, so the composition could not type-check at any intermediate step and the casts were load-bearing.This names those slices and declares them as the factory parameters, so the chain type-checks hop by hop:
ClientRequesterTransactionActionInputgetTransactionTransactionReadergetTransactionContractWritersendRawTransactionhelpersChainSwitcherchain, forconnect()One narrowing assertion remains on the return, because a spread of extended viem clients cannot prove the full public shape. That is one cast instead of seven double-casts.
Two real mismatches the casts were hiding
transactionActionsreads viem'sgetTransaction, then installs its own GenLayer-typed override as a returned method. Its input therefore cannot be typed as the override it produces, henceTransactionActionInputbeing separate fromTransactionReader. Typing it the other way would have madereceiptActions(which does consume the override) unsatisfiable.ClientConfig.chainwas a loose structural type, soGenLayerChainnever propagated pastcreateClientand every chain consumer downstream needed its own cast. It is nowchain?: GenLayerChain.Notes
ClientRequestFnstill checks method names and argument shapes; the factories cast their own results either way, so this does not loosen the RPC surface, only the client composition.transaction.result as numberin the Studio path is a narrowing of a value the raw RPC record types asunknown.Validation
npx tsc --noEmit -p tsconfig.json— cleannpx vitest run --typecheck— 209 passed, no type errorsnpm run build— cleannpm run check:chains— no driftnpx eslint src/— cleantests/client-action-surfaces.test.tsis load-bearing in the type-check sense, which is the only sense available for a type-level change: it fails to compile against the pre-fix tree with 5 errors (has no exported member 'ClientRequester'and friends) and compiles clean after. Its runtime assertions pin that the built client still exposes every factory's methods, which a cast-only regression would not catch.