-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix(pagination): allow nested keys in sortBy pagination params utility type PE-7428 #343
base: alpha
Are you sure you want to change the base?
Conversation
fedellen
commented
Jan 14, 2025
•
edited
Loading
edited
src/types/io.ts
Outdated
type NestedKeys<T> = T extends object | ||
? T extends readonly unknown[] // Detect arrays precisely | ||
? never // Exclude arrays | ||
: { | ||
[K in keyof T & string]: T[K] extends object | ||
? `${K}.${NestedKeys<T[K]>}` | K | ||
: K; | ||
}[keyof T & string] | ||
: never; |
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.
nice
@@ -302,7 +302,8 @@ export function paginationParamsFromOptions<O extends PaginationCLIOptions>( | |||
return { | |||
cursor, | |||
limit: numberLimit, | |||
sortBy, | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
sortBy: sortBy as any, |
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.
nit: does unknown
work better here? otherwise you can provide another type to the generic and do a SortBy on it.
it('should be able to get a page of gateways sorted by nested key like `weights.compositeWeight`', async () => { | ||
const gateways = await ario.getGateways({ | ||
limit: 3, | ||
sortBy: 'weights.compositeWeight', |
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.
👏
1a3df69
to
b06369b
Compare
got an issue here in the tests, don't merge yet -- will come back to this after some airdrop eventing cycles |