fix: validate queryEvents parameter#23
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
|
| */ | ||
| async queryEvents(input: QueryEventsParams): Promise<PaginatedEvents> { | ||
| if (Object.keys(input.query).length > 1) | ||
| throw new Error('Invalid query parameters, please provide only one query object'); |
There was a problem hiding this comment.
We don't generally do runtime validation of query inputs, and have generally relied on errors returned from the API and typescript to enforce correct usage.
I am a little hesitant to start adding this kind of validation only to specific methods, leading to an inconsistent experience.
If you wanted to improve this, I think the correct way to do this would be to update the generator that creates these types to be more strict:
This could either be by updating the types to be something like { TimeRange: string, Sender?: never } | { TimeRange?: never, Sender: string } or by creating a wrapping type utility that dynamically transforms these union types
There was a problem hiding this comment.
@hayes-mysten Thanks for your reviewing! I might need some time to try to improve and learn how to fix that
Descriptiona
Fix the issue that parameter of
queryEventscan't be a multi objects.The Typescript type checker won’t throw error if developers pass multi objects as
query, but this is invalid format for sending request to rpc and the error message returned from rpc response isn't clear. Therefore, I added a validation logic and more clear error message before request to check keyof input objectI have not found any additional rules or pattern for contributing open source code, so if I make something wrong, please tell me
Test plan
Added error test in e2e test cases