Bounded paged collections

luastra/collection

Maintains a bounded window over a cursor-paginated collection while presenting one flat ordered snapshot to UI. It supports loading in both directions, explicit refresh, stable local edits, anchor-aware eviction, and edge-specific retry state.

Translate each backend page into items plus opaque previous and next cursors, then settle the exact ticket returned by begin.

Set the anchor to a visible stable item before extending the window so eviction prefers pages farther from the user's current position.

Complete example

local Collection = require("luastra/collection")

local feed = Collection.new {
    key = function(item: { id: string }): string
        return item.id
    end,
    maxItems = 200,
    maxPages = 8,
}

local ticket = feed.begin("initial", requestId)
feed.resolve(ticket, {
    items = pageItems,
    nextCursor = nextCursor,
})

local snapshot = feed.snapshot()

Detail pages

Collection.ErrorCollection.DirectionCollection.StatusCollection.PageCollection.TicketCollection.OptionsCollection.SnapshotCollection.ResolveResultCollection.StateCollection.new