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