vechain / vechain-sdk-js

The official JavaScript SDK for VeChain.
24 stars 9 forks source link

Refactor `thor-client.ts` and remove circular dependencies #1450

Open freemanzMrojo opened 1 week ago

freemanzMrojo commented 1 week ago

Summary

The purpose of this ticket is to refactor thor-client.ts (so the ThorClient class) and remove its circular dependencies.

This is one example when instantiating the class, we use this to instantiate our own attributes:

    constructor(
        readonly httpClient: IHttpClient,
        options?: BlocksModuleOptions
    ) {
        this.accounts = new AccountsModule(this);
        this.nodes = new NodesModule(this);
        this.blocks = new BlocksModule(this, options);
        this.logs = new LogsModule(this);
        this.transactions = new TransactionsModule(this);
        this.contracts = new ContractsModule(this);
        this.gas = new GasModule(this);
        this.debug = new DebugModule(this);
    }

The idea is to keep the current functionality as much as possible and get a better idea about to how to perform the next steps with regards to refactor the network package and remove the other circular dependencies + a bigger picture on how to perform that refactor.

Basic Example

In the network package.json, remove the condition that counts the number of circular dependencies so we can check the ThorClient ones. There is no need as part of this ticket to fix all of them since it would imply a bigger refactor, so the condition should be put back once we have addressed the circular dependencies for ThorClient (maybe rather than being 11, should be less):

"check:circular-dependencies": "npx madge --json --circular --extensions ts src | jq '. | length' | awk '{if($1 > 11) exit 1}'",
lucanicoladebiasi commented 1 week ago

[x] #1461 HTTP refactoring [x] #1464 account-module refactoring [ ] #1490 debug-module refactoring