Get rid of loadOne since it only works for id-based filters, not addresses

This commit is contained in:
Jon Staab
2024-09-04 17:29:31 -07:00
parent 8874884b9b
commit 25845dc837
6 changed files with 11 additions and 25 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ import {indexBy, type Maybe, now} from '@welshman/lib'
import {getIdFilters} from '@welshman/util'
import type {TrustedEvent} from '@welshman/util'
import {withGetter, deriveEvents} from '@welshman/store'
import {repository, loadOne} from './core'
import {repository, load} from './core'
import {getFreshness, setFreshness} from './freshness'
export const collection = <T, LoadArgs extends any[]>({
@@ -71,7 +71,7 @@ export const deriveEvent = (idOrAddress: string, request: Partial<SubscribeReque
deriveEvents(repository, {filters, includeDeleted: true}),
(events: TrustedEvent[]) => {
if (!attempted && events.length === 0) {
loadOne({...request, filters})
load({...request, filters})
attempted = true
}
-14
View File
@@ -79,17 +79,3 @@ export const load = (request: PartialSubscribeRequest) =>
sub.emitter.on("event", (url: string, e: TrustedEvent) => events.push(e))
sub.emitter.on("complete", () => resolve(events))
})
export const loadOne = (request: PartialSubscribeRequest) =>
new Promise<TrustedEvent | null>(resolve => {
const sub = subscribe({closeOnEose: true, timeout: AppContext.requestTimeout, ...request})
sub.emitter.on("event", (url: string, event: TrustedEvent) => {
resolve(event)
sub.close()
})
sub.emitter.on("complete", () => {
resolve(null)
})
})
+2 -2
View File
@@ -2,7 +2,7 @@ import {FOLLOWS, asDecryptedEvent, readList} from '@welshman/util'
import {type TrustedEvent, type PublishedList} from '@welshman/util'
import {type SubscribeRequest} from "@welshman/net"
import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, loadOne} from './core'
import {repository, load} from './core'
import {collection} from './collection'
import {ensurePlaintext} from './plaintext'
@@ -28,5 +28,5 @@ export const {
store: follows,
getKey: follows => follows.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
loadOne({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]}),
load({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]}),
})
+2 -2
View File
@@ -2,7 +2,7 @@ import {MUTES, asDecryptedEvent, readList} from '@welshman/util'
import {type TrustedEvent, type PublishedList} from '@welshman/util'
import {type SubscribeRequest} from "@welshman/net"
import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, loadOne} from './core'
import {repository, load} from './core'
import {collection} from './collection'
import {ensurePlaintext} from './plaintext'
@@ -28,5 +28,5 @@ export const {
store: mutes,
getKey: mute => mute.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
loadOne({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}),
load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}),
})
+2 -2
View File
@@ -3,7 +3,7 @@ import {readProfile, displayProfile, displayPubkey, PROFILE} from '@welshman/uti
import {type SubscribeRequest} from "@welshman/net"
import {type PublishedProfile} from "@welshman/util"
import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, loadOne} from './core'
import {repository, load} from './core'
import {createSearch} from './util'
import {collection} from './collection'
@@ -24,7 +24,7 @@ export const {
store: profiles,
getKey: profile => profile.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
loadOne({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]}),
load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]}),
})
export const profileSearch = derived(profiles, $profiles =>
+3 -3
View File
@@ -1,7 +1,7 @@
import {INBOX_RELAYS, RELAYS, getRelayTags, normalizeRelayUrl, type TrustedEvent} from '@welshman/util'
import {type SubscribeRequest} from "@welshman/net"
import {deriveEvents, withGetter} from '@welshman/store'
import {loadOne, repository} from './core'
import {load, repository} from './core'
import {collection} from './collection'
export const getRelayUrls = (event?: TrustedEvent): string[] =>
@@ -29,7 +29,7 @@ export const {
store: relaySelections,
getKey: relaySelections => relaySelections.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
loadOne({...request, filters: [{kinds: [RELAYS], authors: [pubkey]}]}),
load({...request, filters: [{kinds: [RELAYS], authors: [pubkey]}]}),
})
export const inboxRelaySelections = withGetter(deriveEvents(repository, {filters: [{kinds: [RELAYS]}]}))
@@ -43,5 +43,5 @@ export const {
store: inboxRelaySelections,
getKey: inboxRelaySelections => inboxRelaySelections.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
loadOne({...request, filters: [{kinds: [INBOX_RELAYS], authors: [pubkey]}]}),
load({...request, filters: [{kinds: [INBOX_RELAYS], authors: [pubkey]}]}),
})