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,25 +1,33 @@
|
||||
import {uniqBy} from "@welshman/lib"
|
||||
import {MESSAGING_RELAYS, getTagValues, normalizeRelayUrl} from "@welshman/util"
|
||||
import {EncryptableList} from "./List.js"
|
||||
import {ListReader, ListBuilder} from "./List.js"
|
||||
|
||||
// NIP-17 kind-10050 messaging/inbox relays. Entries are marker-less
|
||||
// ['relay', url] tags (NOT NIP-65 'r' tags with read/write markers, and the
|
||||
// RelayMode.Messaging marker is not used per-tag here). `urls()` drives where
|
||||
// encrypted DM gift-wraps are sent and fetched, so it stays a flat, normalized
|
||||
// set. Identical structure to BlockedRelayList/SearchRelayList.
|
||||
export class MessagingRelayList extends EncryptableList {
|
||||
readonly kind = MESSAGING_RELAYS
|
||||
export class MessagingRelayList extends ListReader {
|
||||
static kind = MESSAGING_RELAYS
|
||||
|
||||
urls() {
|
||||
return uniqBy(normalizeRelayUrl, getTagValues("relay", this.tags()))
|
||||
}
|
||||
|
||||
builder() {
|
||||
return this.seedList(new MessagingRelayListBuilder())
|
||||
}
|
||||
}
|
||||
|
||||
export class MessagingRelayListBuilder extends ListBuilder {
|
||||
static kind = MESSAGING_RELAYS
|
||||
|
||||
addRelay(url: string) {
|
||||
return this.addPublicTags(["relay", normalizeRelayUrl(url)])
|
||||
}
|
||||
|
||||
removeRelay(url: string) {
|
||||
return this.removeTagsWithValue(url)
|
||||
return this.removeTagsWithValue(normalizeRelayUrl(url))
|
||||
}
|
||||
|
||||
setRelays(urls: string[]) {
|
||||
|
||||
Reference in New Issue
Block a user