b6b129fdc9
tests / tests (push) Failing after 5m8s
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
31 lines
833 B
TypeScript
31 lines
833 B
TypeScript
import {uniq} from "@welshman/lib"
|
|
import {COMMUNITIES, getAddressTagValues} from "@welshman/util"
|
|
import {ListReader, ListBuilder} from "./List.js"
|
|
|
|
// NIP-51 kind-10004 group (community) membership list. Entries are `a` tags
|
|
// pointing at kind-34550 community definitions, merged across public tags and
|
|
// decrypted private content.
|
|
export class GroupList extends ListReader {
|
|
static kind = COMMUNITIES
|
|
|
|
addresses() {
|
|
return uniq(getAddressTagValues(this.tags()))
|
|
}
|
|
|
|
builder() {
|
|
return this.seedList(new GroupListBuilder())
|
|
}
|
|
}
|
|
|
|
export class GroupListBuilder extends ListBuilder {
|
|
static kind = COMMUNITIES
|
|
|
|
addGroup(address: string, relayHint?: string) {
|
|
return this.addPublicTags(["a", address, relayHint || ""])
|
|
}
|
|
|
|
removeGroup(address: string) {
|
|
return this.removeTagsWithValue(address)
|
|
}
|
|
}
|