refactor: Side-effect free utils
#3322
Open
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.
This pull request refactors and improves utility modules in the codebase, focusing on the
LoggerandSigningUtilclasses, as well as minor optimizations in binary utilities and error handling. The main changes include a redesign of the logger initialization for better encapsulation, simplification of the signing utility instantiation logic, and minor performance and correctness tweaks.Note
This is just the first step (alongside the recent
utilsrefactoring). Other packages will follow to make the whole thing much more convenient to use.Changes
Logger improvements:
Loggerclass to encapsulate the root logger initialization in a static method, removing the globalrootLoggervariable and improving encapsulation. The logger now lazily initializes the root logger as needed. [1] [2] [3]Signing utility simplification:
SigningUtil.getInstancemethod by replacing the statickeyTypeToInstancemap with a switch statement that directly instantiates the correct class for each key type. This removes unnecessary static instances and clarifies the instantiation logic. [1] [2]Utility optimizations:
binaryUtils.tsto create newTextEncoderandTextDecoderinstances on each call instead of using shared instances, preventing potential state issues and improving reliability.Error handling improvements:
executeSafePromisefunction to ensure a fresh logger is used for each invocation, and removed the unnecessary top-level logger instance.Future steps