Rewrite domain objects as a Reader/Builder split
tests / tests (push) Failing after 5m7s

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
This commit is contained in:
2026-06-19 00:35:06 +00:00
parent 5e142e4db4
commit bfd91f2d39
45 changed files with 2305 additions and 1626 deletions
+13 -5
View File
@@ -1,27 +1,35 @@
import {uniq} from "@welshman/lib"
import {BLOSSOM_SERVERS, getTagValues, normalizeRelayUrl} from "@welshman/util"
import {EncryptableList} from "./List.js"
import {ListReader, ListBuilder} from "./List.js"
// Blossom BUD-03 user server list (kind 10063). Server endpoints are stored as
// `["server", url]` tags (NOT the `r`/`relay` tags used by relay lists), so the
// generic relay-tag helpers would miss them. Effectively public-only.
export class BlossomServerList extends EncryptableList {
readonly kind = BLOSSOM_SERVERS
export class BlossomServerList extends ListReader {
static kind = BLOSSOM_SERVERS
servers() {
return uniq(getTagValues("server", this.tags()).map(normalizeRelayUrl))
}
includes(url: string) {
return this.servers().includes(url)
return this.servers().includes(normalizeRelayUrl(url))
}
builder() {
return this.seedList(new BlossomServerListBuilder())
}
}
export class BlossomServerListBuilder extends ListBuilder {
static kind = BLOSSOM_SERVERS
addServer(url: string) {
return this.addPublicTags(["server", normalizeRelayUrl(url)])
}
removeServer(url: string) {
return this.removeTagsWithValue(url)
return this.removeTagsWithValue(normalizeRelayUrl(url))
}
setServers(urls: string[]) {