Remote / foldkit-remote-drizzle

Windowed collection relations

A Selection can ask for a bounded connection instead of the full collection:

ts
import { Selection } from 'foldkit-remote'

const PostView = Selection.make(Post, {
  id: true,
  comments: Selection.connection(Comment, {
    first: 10,
  }),
})

For several parent posts, the Source ranks children per parent in one SQL statement (row_number() over (partition by ...)) and keeps the requested page plus the extra row needed to determine the boundary. The statement count does not grow with the number of parents.

The result carries:

ts
{
  refs,
  hasNext,
  hasPrevious,
}

first and last work per parent. after / before cursor pagination is only accepted when the read targets one parent because a single cursor is ambiguous across several parents.

When the client asks for another cursor page, Remote's reducer merges it onto the stored relation page: after appends and before prepends.