Files
welshman/packages/domain/src/TopicList.ts
T
hodlbod b6b129fdc9
tests / tests (push) Failing after 5m8s
Rewrite domain objects as a Reader/Builder split
Replace the single DomainObject/EncryptableList classes with a read/write split
that removes the optional-event ambiguity:

- base.ts: EventReader<P> (static kind; fromEvent(event, signer?) eagerly computes
  a generic `plain`, validates leniently, throws-or-passes; lazy method accessors;
  group/protect/expires + extraTags carry-over; builder()) and EventBuilder<P>
  (chainable setters, buildTags/buildContent, validate-on-emit).
- List.ts: ListReader/ListBuilder for NIP-51 lists (decrypt-on-read into `plain`,
  re-encrypt-on-emit, tag mutators).
- Every kind converted to a <Noun> reader + <Noun>Builder pair; membership ops
  split into per-kind reader/builder pairs over a shared abstract base.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V67tPYdvh1qCkjEBhJGZUR
2026-06-19 00:35:06 +00:00

48 lines
1.2 KiB
TypeScript

import {uniq} from "@welshman/lib"
import {TOPICS, getTopicTagValues, getAddressTagValues} from "@welshman/util"
import {ListReader, ListBuilder} from "./List.js"
// NIP-51 kind-10015 interests/followed-topics list. Followed hashtags are stored
// as `t` tags; the list may also reference interest sets (kind 30015) via `a`
// tags. Extends ListReader/ListBuilder so entries may be public (tags) or private
// (encrypted content), treated as one merged set by the accessors.
export class TopicList extends ListReader {
static kind = TOPICS
topics() {
return uniq(getTopicTagValues(this.tags()))
}
addresses() {
return uniq(getAddressTagValues(this.tags()))
}
includes(topic: string) {
return this.topics().includes(topic)
}
builder() {
return this.seedList(new TopicListBuilder())
}
}
export class TopicListBuilder extends ListBuilder {
static kind = TOPICS
followPublicly(topic: string) {
return this.addPublicTags(["t", topic])
}
followPrivately(topic: string) {
return this.addPrivateTags(["t", topic])
}
follow(topic: string) {
return this.followPublicly(topic)
}
unfollow(topic: string) {
return this.removeTagsWithValue(topic)
}
}