N14
Error
Requests
N14 — A pages or streamed an endpoint cannot have
A read may answer a page at a time — pages .number(param: page), .cursor(param: after, next: p => p.next) or .link — or a line at a time, streamed. Each is a read's, each gathers a list, and each names what it needs: the parameter the next page goes in, which the first call need not give, and where a page's items are when it is not a list itself. for await walks only a streamed endpoint's lines.
What the compiler said
error[N14]: `pages .cursor` on `Social.feed` says nothing of where the next page starts --> src/App.wf:5:5 | 5 | get feed(after: String?) at "feed" -> FeedPage! | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Name it from a page: `next: p => p.nextCursor` = docs: https://webfluent.monzeromer.dev/errors/N14
The fix
Broken
type Post { id: String, title: String }
type FeedPage { posts: [Post], nextCursor: String? }
api Social(base: "/api") {
get feed(after: String?) at "feed" -> FeedPage!
pages .cursor(param: after)
}
page P(path: "/", title: "T", description: "D") {
resource feed = Social.feed()
Heading("Feed").h1
for p in feed.items by p.id { Text(p.title) }
}
Fixed
type Post { id: String, title: String }
type FeedPage { posts: [Post], nextCursor: String? }
api Social(base: "/api") {
get feed(after: String?) at "feed" -> FeedPage!
pages .cursor(param: after, next: p => p.nextCursor, items: p => p.posts)
}
page P(path: "/", title: "T", description: "D") {
resource feed = Social.feed()
Heading("Feed").h1
for p in feed.items by p.id { Text(p.title) }
}
Say what the style needs — the parameter, where the next page starts, where a page's items are — or answer a list.
Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).
Why this rule exists
Error.
An endpoint may answer more than once for one read. It may answer a page at a time:
pages .number(param: page)asks for page 1, 2, 3 and stops at the
first empty page;
pages .cursor(param: after, next: p => p.nextCursor)asks for the next
page with the cursor the last one gave, and stops when there is none;
pages .linkasks for the address the answer'sLinkheader names
rel="next" (RFC 8288), and stops when there is none.
Or it may answer a line at a time, -> [Line]! streamed, one JSON value
a line.
Either way a read of it holds a list: every page's items, or every line
so far. So each must say what it needs. The parameter the next page goes
in is one of the endpoint's, and the first call need not give it: it has
a default, or may be null. A page that is not a list itself says where
its items are, items: p => p.posts. A streamed endpoint answers a list.
Both are reads, gets: a write is sent once. And for await walks only
a streamed endpoint's lines.
lints cannot lower it: it would ship a broken page.