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

Ensure tableId is valid type at runtime #472

Merged
merged 1 commit into from
May 5, 2023
Merged

Ensure tableId is valid type at runtime #472

merged 1 commit into from
May 5, 2023

Conversation

joewagner
Copy link
Contributor

Overview

This makes the error message returned from an invalid call to Validator.getTableById() easier to understand.

Details

@dtbuchholz After looking into this I was reminded that the types are being generated from our API spec, so allowing tableId to be number or string or BigNumber was not a good solution. Forcing the type to be string at runtime seems like the best path.
Interesting side note: in the process of setting this up I noticed that if you call
validator.getTableById({chainId: 31337, tableId: 9007199254740993});
the resulting http request is
<api path>/tables/31337/9007199254740992
Specifically anything bigger than Number.MAX_SAFE_INTEGER will potentially result in a request for the wrong table. Not a big deal because there are nowhere near that many tables.

fixes #470

@dtbuchholz
Copy link
Contributor

gotcha. and one day, we'll hit that max!! until then...makes sense.

@joewagner joewagner changed the base branch from main to staging April 28, 2023 20:07
@dtbuchholz
Copy link
Contributor

@joewagner i do wonder, though, if this will lead to confusion because i'd definitely assume tableId is a number, considering it's a numeric value to the human eye as well as its on-chain representation.

thinking about it again, maybe BigInt and .toString() could be used to ensure spec conformity?

const tokenId = BigInt(Number.MAX_SAFE_INTEGER + 1)
console.log(tokenId.toString());
// 9007199254740993 -> pass this to the API

@joewagner
Copy link
Contributor Author

@joewagner i do wonder, though, if this will lead to confusion because i'd definitely assume tableId is a number, considering it's a numeric value to the human eye as well as its on-chain representation.

thinking about it again, maybe BigInt and .toString() could be used to ensure spec conformity?

I can definitely understand wanting to allow bigint or number here. The allowed type is defined in the spec https://github.com/tablelandnetwork/docs/blob/main/specs/validator/tableland-openapi-spec.yaml#L182
I can definitely find a way to work around things for typescript folks, but it feels weird to have a type defined in the spec that's different than what the SDK allows. @carsonfarmer do you have any suggestions, or thoughts here?

@joewagner joewagner changed the base branch from staging to main May 5, 2023 02:55
awmuncy
awmuncy previously approved these changes May 5, 2023
Copy link
Contributor

@awmuncy awmuncy left a comment

Choose a reason for hiding this comment

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

I'd agree; the SDK should take the args in the spec. If someone has a big int, and they see it takes either a string or number, they can toString() it themselves, no?

@joewagner
Copy link
Contributor Author

I'd agree; the SDK should take the args in the spec. If someone has a big int, and they see it takes either a string or number, they can toString() it themselves, no?

Yeah after thinking this over a bit, we should avoid deviating from the spec whenever possible.
I'll rebase this and point it at staging now so we can get it into next week's ship.

@joewagner joewagner changed the base branch from main to staging May 5, 2023 19:52
@joewagner joewagner dismissed awmuncy’s stale review May 5, 2023 19:52

The base branch was changed.

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.

[JST-23] Validator getTableById does not map chainId nor tableId
3 participants