-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
gotcha. and one day, we'll hit that max!! until then...makes sense. |
@joewagner i do wonder, though, if this will lead to confusion because i'd definitely assume thinking about it again, maybe const tokenId = BigInt(Number.MAX_SAFE_INTEGER + 1)
console.log(tokenId.toString());
// 9007199254740993 -> pass this to the API |
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 |
There was a problem hiding this 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?
Yeah after thinking this over a bit, we should avoid deviating from the spec whenever possible. |
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