Refine domain, integrate into app
tests / tests (push) Failing after 5m14s

This commit is contained in:
Jon Staab
2026-06-19 12:50:34 -07:00
parent 1bd62d3024
commit e2a6ef21cd
115 changed files with 1354 additions and 3176 deletions
+14 -17
View File
@@ -1,32 +1,25 @@
import {derived, readable} from "svelte/store"
import {
readProfile,
displayProfile,
displayPubkey,
isPublishedProfile,
createProfile,
editProfile,
PROFILE,
} from "@welshman/util"
import type {Profile} from "@welshman/util"
import {PROFILE} from "@welshman/util"
import type {Maybe} from "@welshman/lib"
import {Profile, ProfileBuilder, displayPubkey} from "@welshman/domain"
import {DerivedPlugin, projection} from "./base.js"
import type {Projection} from "./base.js"
import {Network} from "./network.js"
import {Router} from "./router.js"
import {Thunks} from "./thunk.js"
import {User} from "../user.js"
import type {IApp} from "../app.js"
/**
* Kind-0 profiles, keyed by pubkey. Loaded via the outbox model (the author's
* write relays), resolved through the relay-list collection at fetch time.
*/
export class Profiles extends DerivedPlugin<ReturnType<typeof readProfile>> {
export class Profiles extends DerivedPlugin<Profile> {
constructor(app: IApp) {
super(app, {
filters: [{kinds: [PROFILE]}],
eventToItem: readProfile,
getKey: profile => profile.event.pubkey,
eventToItem: Profile.factory(app.user?.signer),
getKey: profile => profile.author(),
})
}
@@ -34,17 +27,21 @@ export class Profiles extends DerivedPlugin<ReturnType<typeof readProfile>> {
return this.app.use(Network).loadUsingOutbox(pubkey, {kinds: [PROFILE]}, relayHints)
}
publish = (profile: Profile) => {
// Publish the app user's kind-0, merging `values` over their current profile
// (preserving any unknown metadata fields and source tags).
publish = async (values: Record<string, any>) => {
const user = User.require(this.app)
const router = this.app.use(Router)
const relays = router.merge([router.Index(), router.FromUser()]).getUrls()
const event = isPublishedProfile(profile) ? editProfile(profile) : createProfile(profile)
const builder = new ProfileBuilder(this.get(user.pubkey)).update(values)
const event = await builder.toTemplate()
return this.app.use(Thunks).publish({event, relays})
}
display = (pubkey: string | undefined, ...args: any[]): Projection<string> => {
const read = ($profile: Maybe<ReturnType<typeof readProfile>>) =>
pubkey ? displayProfile($profile, displayPubkey(pubkey)) : ""
const read = ($profile: Maybe<Profile>) =>
pubkey ? ($profile?.display() ?? displayPubkey(pubkey)) : ""
return projection(
pubkey ? derived(this.one(pubkey, ...args), read) : readable(""),