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

Deprecate getServicesInfo() in favor of Sep24.info() #166

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

CassioMG
Copy link
Contributor

@CassioMG CassioMG commented Aug 24, 2024

We currently have the below get info functions for the related classes and SEPs:

The proposal of this PR is to deprecate both getServicesInfo() functions and consolidate them into a single info() function like the below for consistency and simplicity:

  • Sep6.info(): hits GET /info for the Sep6 server
  • Sep38.info(): hits GET /info for the Sep38 server
  • Sep24.info(): hits GET /info for the Sep24 server

This PR also adds support for the lang parameter on Sep6.info() and Sep24.info() as covered by the Sep-6 and Sep-24 specs.

* @throws {ServerRequestFailedError} If the server request to fetch information fails.
*/
async info(
shouldRefresh?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the optional value come before the required one? Even though it has a default value, I don't think shouldRefresh can be in the first position and optional while lang is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aristidesstaffieri thanks for the review!
I think both params are actually optional here, the = this.anchor.language initializer is there to set a default value for an optional param. Typescript won't let me do something like this: lang?: string = this.anchor.language.
The JSDoc also explicits that through the use of brackets syntax like [paramName] which is meant for optional params.

Since they both could be considered as optional we could invert them (like putting lang first), but the downside is that it would be a breaking change for people out there using the existing Sep6.info() function like this Sep6.info(true), they would need to update it to Sep6.info(undefined, true).

Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it yeah that does make sense. I guess the only downside is that users of info now can't leave off shouldRefresh while setting lang but this is probably fine imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO lang should come first, as I don't see shouldRefresh being set very often (you generally should be fine with cached info)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the lang param won't be used as much as well since in most cases it'll probably be derived from this.anchor.language.

But I agree that putting lang first does look better than having shouldRefresh first.

I guess we can revert them and make a BREAKING CHANGE note (which in reality I believe won't break for many people out there as it uses the default anchor language as mentioned earlier).

Another alternative yet is using an object as the function input so that the order of the parameters won't really matter. I think this object-input approach generally makes things more robust and scalable as it prevents bugs related to input params out of order and seems easier to maintain.

Something like this:

  async info({
    lang = this.anchor.language,
    shouldRefresh,
  }: {
    lang?: string,
    shouldRefresh?: boolean,
  }): Promise<Sep24Info> {
...

How do you guys feel about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the lang param won't be used as much as well since in most cases it'll probably be derived from this.anchor.language.

That's a good point, I think you are 100% right

Copy link
Contributor

Choose a reason for hiding this comment

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

Another alternative yet is using an object as the function input so that the order of the parameters won't really matter. I think this object-input approach generally makes things more robust and scalable as it prevents bugs related to input params out of order and seems easier to maintain.

+1 on that, but I think it will be breaking, won't it? Maybe a 2.0 change?

Copy link
Contributor Author

@CassioMG CassioMG Aug 27, 2024

Choose a reason for hiding this comment

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

Maybe a 2.0 change?

I like the 2.0 change approach. Maybe we could take this as an opportunity to review and make all SDK functions take objects as arguments. I see our current codebase has a mix of functions taking objects vs taking separate parameters, I think it would be great to establish this code convention on 2.0 and stick with it going forward.
What do you guys think?

We could merge this PR "as is" for 1.7 and plan for the wider change on 2.0.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds great!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, just created this issue to potentially tackle it in next iteration (sprint): [TS Wallet SDK] Release 2.0 to consolidate object as function input

* @throws {ServerRequestFailedError} If the server request to fetch information fails.
*/
async info(
shouldRefresh?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO lang should come first, as I don't see shouldRefresh being set very often (you generally should be fine with cached info)

@CassioMG CassioMG merged commit a115895 into main Sep 2, 2024
8 checks passed
@CassioMG CassioMG deleted the cg-consolidate-get-info branch September 2, 2024 15:09
@CassioMG CassioMG mentioned this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants