(
orderByInfo: Pick<
OrderByOptimizationInfo,
'orderBy' | 'valueExtractorForRawRow' | 'offset'
>,
biggestSentRow: unknown | undefined,
lastLoadRequestKey: string | undefined,
alias: string,
limit: number,
)
| 430 | * otherwise `{ minValues, normalizedOrderBy, loadRequestKey }`. |
| 431 | */ |
| 432 | export function computeOrderedLoadCursor( |
| 433 | orderByInfo: Pick< |
| 434 | OrderByOptimizationInfo, |
| 435 | 'orderBy' | 'valueExtractorForRawRow' | 'offset' |
| 436 | >, |
| 437 | biggestSentRow: unknown | undefined, |
| 438 | lastLoadRequestKey: string | undefined, |
| 439 | alias: string, |
| 440 | limit: number, |
| 441 | ): |
| 442 | | { |
| 443 | minValues: Array<unknown> | undefined |
| 444 | normalizedOrderBy: OrderBy |
| 445 | loadRequestKey: string |
| 446 | } |
| 447 | | undefined { |
| 448 | const { orderBy, valueExtractorForRawRow, offset } = orderByInfo |
| 449 | |
| 450 | // Extract all orderBy column values from the biggest sent row |
| 451 | // For single-column: returns single value, for multi-column: returns array |
| 452 | const extractedValues = biggestSentRow |
| 453 | ? valueExtractorForRawRow(biggestSentRow as Record<string, unknown>) |
| 454 | : undefined |
| 455 | |
| 456 | // Normalize to array format for minValues |
| 457 | let minValues: Array<unknown> | undefined |
| 458 | if (extractedValues !== undefined) { |
| 459 | minValues = Array.isArray(extractedValues) |
| 460 | ? extractedValues |
| 461 | : [extractedValues] |
| 462 | } |
| 463 | |
| 464 | // Deduplicate: skip if we already issued an identical load request |
| 465 | const loadRequestKey = serializeValue({ |
| 466 | minValues: minValues ?? null, |
| 467 | offset, |
| 468 | limit, |
| 469 | }) |
| 470 | if (lastLoadRequestKey === loadRequestKey) { |
| 471 | return undefined |
| 472 | } |
| 473 | |
| 474 | const normalizedOrderBy = normalizeOrderByPaths(orderBy, alias) |
| 475 | |
| 476 | return { minValues, normalizedOrderBy, loadRequestKey } |
| 477 | } |
no test coverage detected