| 1 | /**
|
|---|
| 2 | * Guardianship (FEP-633c) — the owner-only dashboard queues.
|
|---|
| 3 | *
|
|---|
| 4 | * Three OrderedCollections on the actor (shaer:queues), same contract as the
|
|---|
| 5 | * Shaer test daemon so the iOS/Android dashboards read them as-is:
|
|---|
| 6 | * - offers: pending handshake offers where I am a party (§3), with the full
|
|---|
| 7 | * accept tally so the client shows the right action
|
|---|
| 8 | * - follows: pending gated follows for my wards (§5.3) — Fase 2, empty for now
|
|---|
| 9 | * - wards: my committed wards
|
|---|
| 10 | */
|
|---|
| 11 | import * as offers from './offers.js';
|
|---|
| 12 | import * as relations from './relations.js';
|
|---|
| 13 | import * as availability from './availability.js';
|
|---|
| 14 | import * as outgoing from './outgoing.js';
|
|---|
| 15 | import * as handshake from './handshake.js';
|
|---|
| 16 |
|
|---|
| 17 | const collection = (id, items) => ({
|
|---|
| 18 | id, type: 'OrderedCollection', totalItems: items.length, orderedItems: items,
|
|---|
| 19 | });
|
|---|
| 20 |
|
|---|
| 21 | /** Pending offers where the local site is a party, each with its accept
|
|---|
| 22 | * tally. The same collection carries the running lapses (§3.6.3) this
|
|---|
| 23 | * account is a party to, exactly as the daemon serves them, so the Shaer
|
|---|
| 24 | * clients render both without a second fetch. */
|
|---|
| 25 | export function offersCollection(id, slug, me) {
|
|---|
| 26 | // §4.2: a handshake whose candidate could not be dereferenced is deferred,
|
|---|
| 27 | // not decided, and the last Accept may already have landed — so nothing else
|
|---|
| 28 | // would ever retry it. This poll is the schedule. Not awaited: the read
|
|---|
| 29 | // answers with what is true now, and a retry that succeeds surfaces in the
|
|---|
| 30 | // next one. `listForParty` settles closed windows on the way past.
|
|---|
| 31 | handshake.retryDeferred(slug).catch(() => { /* the next read tries again */ });
|
|---|
| 32 | const items = offers.listForParty(slug, me).map((o) => offers.queueItem(o, me));
|
|---|
| 33 | items.push(...availability.lapseQueueItems(slug, me, Date.now()));
|
|---|
| 34 | return collection(id, items);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /** Gated follows awaiting guardian approval — not built in Klonkt yet (Fase 2). */
|
|---|
| 38 | export function followsCollection(id) {
|
|---|
| 39 | return collection(id, []);
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | /** §5.3 outbound: this ward's own follow requests, waiting for its guardians. */
|
|---|
| 43 | export function outgoingFollowsCollection(id, slug, me) {
|
|---|
| 44 | return collection(id, outgoing.listForWard(slug).map((o) => outgoing.queueItem(o, me)));
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | /** The guardian's committed wards, with cached handle for display. */
|
|---|
| 48 | export function wardsCollection(id, slug) {
|
|---|
| 49 | const items = relations.listWards(slug)
|
|---|
| 50 | .map((r) => ({ id: r.other_uri, 'shaer:handle': r.other_handle || undefined, since: r.created_at }));
|
|---|
| 51 | return collection(id, items);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | /** The ward's guardians with their availability (§3.6.1: never public,
|
|---|
| 55 | * owner-only): the real size of the safety net. Same shape as the daemon. */
|
|---|
| 56 | export function guardiansCollection(id, slug) {
|
|---|
| 57 | const uris = relations.listGuardians(slug).map((r) => r.other_uri);
|
|---|
| 58 | return collection(id, availability.statusesFor(slug, uris, Date.now()));
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | export default { offersCollection, followsCollection, outgoingFollowsCollection, wardsCollection, guardiansCollection };
|
|---|