Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

optimistic-ordered-refetch-probe.ts

22 lines996 Bytes

1import { applyPredicates } from '../e2e/query-filter.js'
2import type { LoadSubsetOptions } from '@tanstack/db'
3​
4export type Row = { id: number; folder: `inbox` | `archive`; at: number }
5​
6// A boundary probe may omit ordering, but its predicate must select one rank.
7// Add another row at that rank so a key-specific request cannot masquerade as
8// a rank-tie probe. Evaluate the whole predicate scope, not the capped answer.
9export function isNarrowRankTieProbe(
10 options: LoadSubsetOptions,
11 remote: Array<Row>,
12): boolean {
13 if (options.orderBy !== undefined || options.where === undefined) return false
14 const matches = applyPredicates(remote, { where: options.where })
15 if (matches.length === 0) return false
16 const rank = matches[0]!.at
17 if (matches.some((row) => row.at !== rank)) return false
18 const additionalTie: Row = { ...matches[0]!, id: 1000 }
19 return applyPredicates([...remote, additionalTie], {
20 where: options.where,
21 }).some((row) => row.id === additionalTie.id)