add PIN kind utilities

This commit is contained in:
Ticruz
2025-01-16 17:47:28 +01:00
parent 3c100a8ce6
commit b334da9389
4 changed files with 53 additions and 2 deletions
+28
View File
@@ -0,0 +1,28 @@
import {PINS, asDecryptedEvent, readList} from "@welshman/util"
import {type TrustedEvent, type PublishedList} from "@welshman/util"
import {type SubscribeRequestWithHandlers} from "@welshman/net"
import {deriveEventsMapped} from "@welshman/store"
import {repository} from "./core.js"
import {load} from "./subscribe.js"
import {collection} from "./collection.js"
import {loadRelaySelections} from "./relaySelections.js"
export const pins = deriveEventsMapped<PublishedList>(repository, {
filters: [{kinds: [PINS]}],
itemToEvent: item => item.event,
eventToItem: (event: TrustedEvent) => readList(asDecryptedEvent(event)),
})
export const {
indexStore: pinsByPubkey,
deriveItem: derivePins,
loadItem: loadPins,
} = collection({
name: "pins",
store: pins,
getKey: pins => pins.event.pubkey,
load: async (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) => {
await loadRelaySelections(pubkey, request)
await load({...request, filters: [{kinds: [PINS], authors: [pubkey]}]})
},
})