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

chore: allow string arrays on sort parameters #1326

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1793,13 +1793,17 @@ export type Sort<T> = {
[P in keyof T]?: AscDesc;
};

export type SortMember<T> = {
MartinCupela marked this conversation as resolved.
Show resolved Hide resolved
[P in keyof T]?: AscDesc | string[];
};

export type UserSort<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> =
| Sort<UserResponse<StreamChatGenerics>>
| Array<Sort<UserResponse<StreamChatGenerics>>>;

export type MemberSort<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> =
| Sort<Pick<UserResponse<StreamChatGenerics>, 'id' | 'created_at' | 'name'>>
| Array<Sort<Pick<UserResponse<StreamChatGenerics>, 'id' | 'created_at' | 'name'>>>;
| SortMember<Pick<UserResponse<StreamChatGenerics>, 'id' | 'created_at' | 'name' | 'channel_role'>>
| Array<SortMember<Pick<UserResponse<StreamChatGenerics>, 'id' | 'created_at' | 'name' | 'channel_role'>>>;

export type SearchMessageSortBase<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Sort<
StreamChatGenerics['messageType']
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function addFileToFormData(

return data;
}
export function normalizeQuerySort<T extends Record<string, AscDesc | undefined>>(sort: T | T[]) {
export function normalizeQuerySort<T extends Record<string, AscDesc | undefined | string[]>>(sort: T | T[]) {
const sortFields: Array<{ direction: AscDesc; field: keyof T }> = [];
const sortArr = Array.isArray(sort) ? sort : [sort];
for (const item of sortArr) {
Expand Down
Loading