Skip to content

Commit

Permalink
test(pagination): add e2e test for nested sort keys PE-7428
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen authored and dtfiedler committed Jan 15, 2025
1 parent 466e8f8 commit b06369b
Show file tree
Hide file tree
Showing 3 changed files with 741 additions and 710 deletions.
3 changes: 2 additions & 1 deletion src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
sortOrder,
};
}
Expand Down
10 changes: 8 additions & 2 deletions src/types/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ type NestedKeys<T> = T extends object
}[keyof T & string]
: never;

type SortBy<T> = T extends string
? string
: keyof T extends never
? string
: NestedKeys<T>;

export type PaginationParams<T = Record<string, never>> = {
cursor?: string;
limit?: number;
sortBy?: keyof T extends never ? string : NestedKeys<T>; // default to string if T is empty
sortBy?: SortBy<T>; // default to string if T is empty
sortOrder?: 'asc' | 'desc';
};

Expand All @@ -53,7 +59,7 @@ export type PaginationResult<T> = {
nextCursor?: string;
limit: number;
totalItems: number;
sortBy?: T extends string ? string : keyof T;
sortBy?: SortBy<T>;
sortOrder: 'asc' | 'desc';
hasMore: boolean;
};
Expand Down
Loading

0 comments on commit b06369b

Please sign in to comment.