Files
speckle-server/packages/server/modules/shared/services/paginatedItems.ts
T
andrewwallacespeckle c89fe339ec refactor: fix pagination with stable resolveKey, use reactive default… (#4951)
* refactor: fix pagination with stable resolveKey, use reactive defaultRoles, and remove email permission check

* Changes from call

* More changes from call

* WIP fixing team composite cursor

* paginated items fix

* minor rename

* composite cursor tools improved

* fe undoing debugging stuff

* extra fixes

* invitable collabs fix

---------

Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
2025-06-19 10:28:31 +03:00

29 lines
789 B
TypeScript

import { Collection } from '@/modules/shared/helpers/graphqlHelper'
import { MaybeNullOrUndefined } from '@speckle/shared'
type GetPaginatedItemsArgs = {
limit: number
cursor?: MaybeNullOrUndefined<string>
}
export const getPaginatedItemsFactory =
<TArgs extends GetPaginatedItemsArgs, T>({
getItems,
getTotalCount
}: {
getItems: (args: TArgs) => Promise<{ items: T[]; cursor: string | null }>
getTotalCount: (args: Omit<TArgs, 'cursor' | 'limit'>) => Promise<number>
}) =>
async (args: TArgs): Promise<Collection<T>> => {
const [totalCount, { items, cursor }] = await Promise.all([
getTotalCount(args),
args.limit === 0 ? { cursor: null, items: [] } : getItems(args)
])
return {
items,
cursor,
totalCount
}
}