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

fix(pagination): allow nested keys in sortBy pagination params utility type PE-7428 #343

Open
wants to merge 4 commits into
base: alpha
Choose a base branch
from

Conversation

fedellen
Copy link
Contributor

@fedellen fedellen commented Jan 14, 2025

image

@fedellen fedellen requested a review from a team as a code owner January 14, 2025 19:40
@fedellen fedellen self-assigned this Jan 14, 2025
src/types/io.ts Outdated
Comment on lines 34 to 42
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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

src/types/io.ts Outdated Show resolved Hide resolved
@@ -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,
Copy link
Collaborator

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',
Copy link
Collaborator

Choose a reason for hiding this comment

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

👏

@dtfiedler dtfiedler force-pushed the pagination-type-fix branch from 1a3df69 to b06369b Compare January 15, 2025 07:03
@fedellen
Copy link
Contributor Author

got an issue here in the tests, don't merge yet -- will come back to this after some airdrop eventing cycles

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.

2 participants