@estiva-app/interop 0.89.0 → 0.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ import type { Relay } from '@estiva-app/protocol'
2
+
3
+ /**
4
+ * Whether a live watch must name teams to hear them.
5
+ *
6
+ * A relay that lists {@link LIVE_AS_STORED_EXTENSION} in its NIP-11
7
+ * `supported_extensions` sends a request kept open every new event that
8
+ * asking again would return for the same reader, from inside teams too,
9
+ * without the request naming them (SPEC §5). Ours has since 9 Nov 2026
10
+ * (buzz 460f3d77f). Upstream Buzz delivers a team's event live only to a
11
+ * request that names the team by `#h`, so a watch stops naming teams only on
12
+ * a relay that says so.
13
+ *
14
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-request-kept-open-hears-what-asking-again-would-return.md
15
+ */
16
+ export const LIVE_AS_STORED_EXTENSION = 'buzz-live-as-stored'
17
+
18
+ /**
19
+ * Whether a watch must name teams on the relay whose NIP-11 document is
20
+ * `info`: false when it lists {@link LIVE_AS_STORED_EXTENSION}, true
21
+ * otherwise, including for a document that is missing or malformed.
22
+ */
23
+ export function namesTeamsOn(info: unknown): boolean {
24
+ const extensions = (info as { supported_extensions?: unknown } | null | undefined)?.supported_extensions
25
+ return !(Array.isArray(extensions) && extensions.includes(LIVE_AS_STORED_EXTENSION))
26
+ }
27
+
28
+ const asked = new WeakMap<object, Promise<boolean>>()
29
+
30
+ /**
31
+ * `namesTeams` for {@link watchListedConversations} and
32
+ * {@link watchTopicActivity} on `relay`, from its NIP-11 document: pass the
33
+ * promise as it is (`namesTeams: relayNamesTeams(relay)`). Read once per relay
34
+ * object; a relay that does not answer is asked again next time, and until
35
+ * then the watch names teams.
36
+ */
37
+ export function relayNamesTeams(relay: Pick<Relay, 'info'>): Promise<boolean> {
38
+ const held = asked.get(relay)
39
+ if (held) return held
40
+ const answer = relay.info().then(namesTeamsOn, () => {
41
+ asked.delete(relay)
42
+ return true
43
+ })
44
+ asked.set(relay, answer)
45
+ return answer
46
+ }
package/src/topics.ts CHANGED
@@ -346,6 +346,8 @@ export interface ReadTopic {
346
346
  object: ForeignObject
347
347
  /** Its Folder, from its root (§6.2): where an entry on its list is filed. */
348
348
  folder: string
349
+ /** Its first record's time, Unix seconds: its time in the order of topics when nothing has happened in it since. */
350
+ createdAt: number
349
351
  /** Its list, as {@link topicLists} reads it. */
350
352
  listed: ListedFile[]
351
353
  /**
@@ -434,7 +436,7 @@ function personInFilesFilters(person: string, files: readonly string[]): Record<
434
436
  }
435
437
 
436
438
  /** Whether an event answers a filter, as NIP-01 reads it: kinds, authors, `#x` tags, `since` and `until`. */
437
- function answers(event: SignedEvent, filter: Record<string, unknown>): boolean {
439
+ export function answers(event: SignedEvent, filter: Record<string, unknown>): boolean {
438
440
  const { kinds, authors, since, until } = filter as { kinds?: number[]; authors?: string[]; since?: number; until?: number }
439
441
  if (kinds && !kinds.includes(event.kind)) return false
440
442
  if (authors && !authors.includes(event.pubkey)) return false
@@ -452,7 +454,7 @@ function answers(event: SignedEvent, filter: Record<string, unknown>): boolean {
452
454
  * nothing fills a page, as at Miky's scale; never a silent cut at the relay's
453
455
  * cap. A second holding a page's worth on its own ends the walk there.
454
456
  */
455
- async function readAll(query: QueryFn, filters: readonly Record<string, unknown>[]): Promise<SignedEvent[]> {
457
+ export async function readAll(query: QueryFn, filters: readonly Record<string, unknown>[]): Promise<SignedEvent[]> {
456
458
  const out = new Map<string, SignedEvent>()
457
459
  let open = filters.map((filter) => ({ ...filter, limit: RELAY_PAGE_CEILING }))
458
460
  while (open.length) {
@@ -555,7 +557,7 @@ export async function readTopics(
555
557
  const address = object.address!
556
558
  // The team is the topic's own Folder; a team's default reaches no topic, so its roster is not needed (§11.8).
557
559
  const following = followingOf({ address, team: folder }, me, { events: [root, ...(byTopic.get(address) ?? [])], listing: states })
558
- return [{ address, object, folder, listed: lists.get(address) ?? [], following, yours: following.in, space: spaces.has(address) }]
560
+ return [{ address, object, folder, createdAt: root.created_at, listed: lists.get(address) ?? [], following, yours: following.in, space: spaces.has(address) }]
559
561
  })
560
562
  return { me, topics, membership, mentionedIn, inConversations }
561
563
  }