Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Better Result class implementation #23335

Merged
merged 38 commits into from Jul 19, 2023

Conversation

zharinov
Copy link
Collaborator

@zharinov zharinov commented Jul 12, 2023

Changes

  • this PR introduces AsyncResult class for wrapping and transforming promise-based results
    • when dealing with promises, it's useful to apply .transform() without intermixing it with await clauses
    • it renames back some fields (e.g., success to ok)
  • removes value and error getters
    • .unwrap() method should be used instead
    • otherwise, some type guarantees are lost which can lead to incorrect code
    • instead, mental model should be: wrap callback or promise to the Result, perform type-safe transforms, then unwrap the final result
  • enforce non-nullable constraint for T and E type parameters

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@zharinov zharinov requested review from rarkins and viceice July 12, 2023 17:03
rarkins
rarkins previously approved these changes Jul 12, 2023
@zharinov zharinov marked this pull request as draft July 12, 2023 18:38
@zharinov zharinov changed the title feat: Tranforms and fallbacks for promise-based Result<T, E> refactor: Add AsyncResult<T, E> class and support transforms Jul 13, 2023
@zharinov zharinov changed the title refactor: Add AsyncResult<T, E> class and support transforms refactor: Add AsyncResult<T, E> class with transforms support Jul 13, 2023
@zharinov zharinov marked this pull request as ready for review July 13, 2023 10:57
lib/util/result.spec.ts Outdated Show resolved Hide resolved
lib/util/result.ts Outdated Show resolved Hide resolved
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to need some more code changes, see annotations

@zharinov zharinov marked this pull request as draft July 14, 2023 10:07
@zharinov zharinov changed the title refactor: Add AsyncResult<T, E> class with transforms support refactor: Async support for Result utility class Jul 14, 2023
@zharinov zharinov requested a review from viceice July 14, 2023 10:17
@zharinov zharinov self-assigned this Jul 14, 2023
@zharinov zharinov marked this pull request as ready for review July 14, 2023 10:17
lib/modules/datasource/rubygems/index.ts Outdated Show resolved Hide resolved
lib/util/result.ts Show resolved Hide resolved
lib/util/result.ts Show resolved Hide resolved
lib/util/result.ts Show resolved Hide resolved
lib/util/result.ts Show resolved Hide resolved
@zharinov zharinov requested a review from viceice July 17, 2023 18:28
@zharinov zharinov marked this pull request as draft July 17, 2023 18:44
@zharinov zharinov marked this pull request as ready for review July 17, 2023 19:42
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM

lib/util/result.ts Show resolved Hide resolved
@zharinov
Copy link
Collaborator Author

:shipit:

@zharinov zharinov requested review from viceice and rarkins July 18, 2023 05:49
@zharinov zharinov removed their assignment Jul 19, 2023
@zharinov
Copy link
Collaborator Author

Please, merge this one

@viceice viceice enabled auto-merge July 19, 2023 11:29
@viceice viceice added this pull request to the merge queue Jul 19, 2023
Merged via the queue into renovatebot:main with commit b641ec2 Jul 19, 2023
36 checks passed
@viceice viceice deleted the feat/result-promise-transform branch July 19, 2023 11:40
zharinov added a commit to zharinov/renovate that referenced this pull request Jul 19, 2023
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 36.13.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants