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:
@@ -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[]) {
|
||||
|
||||
Reference in New Issue
Block a user