Files
speckle-server/packages/server/modules/shared/services/paginatedItems.ts
T
Kristaps Fabians Geikins 4b06f42db7 chore(server): run TS files directly (no compilation) (#5134)
* sort of works

* type fixes

* added option to run old way too
2025-07-23 11:20:40 +02:00

29 lines
794 B
TypeScript

import type { Collection } from '@/modules/shared/helpers/dbHelper'
import type { 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
}
}