Files
2026-11-27 06:03:56 +00:00

24 lines
1.2 KiB
Plaintext

type PostRow { id: data.post.id, created_at: DateTime, title: Text, author_id: data.author.id, note: Text? }
type AuthorRow { id: data.author.id, created_at: DateTime, name: Text, note: Text?, posts: List<PostRow> }
type Page { items: List<AuthorRow>, page: Int, size: Int, total: Int, pages: Int }
type Error { error NotLoaded }
loop posts(rows: List<data.post.Post>) (out: List<PostRow>)
| each row in rows | result |
| out | list PostRow { id = row.id, created_at = row.created_at, title = row.title, author_id = row.author_id, note = row.note } |
rule loaded(value: Related<List<data.post.Post>>) (out: List<PostRow>)
| value | out |
| Loaded(rows) | posts(rows) |
| Unloaded | fail(Error.NotLoaded) |
loop authors(rows: List<data.author.Author>) (out: List<AuthorRow>)
| each row in rows | result |
| out | list AuthorRow { id = row.id, created_at = row.created_at, name = row.name, note = row.note, posts = loaded(row.posts) } |
flow page(page: Int, size: Int) (out: Page)
| step | kind | do |
| found | data | data.author.page(order = id.asc, with = [posts], page = page, size = size) |
| items | loop | authors(found.items) |
| out | calc | Page { items = items, page = found.page, size = found.size, total = found.total, pages = found.pages } |