Move deduplicateEvents to util

This commit is contained in:
Jon Staab
2025-09-17 09:41:20 -07:00
parent a3295dc2fe
commit beadfc571c
16 changed files with 32 additions and 30 deletions
+1 -16
View File
@@ -1,7 +1,6 @@
import {
on,
uniq,
lte,
flatten,
addToMapKey,
defer,
@@ -13,10 +12,10 @@ import {
} from "@welshman/lib"
import {
Filter,
getAddress,
unionFilters,
matchFilters,
TrustedEvent,
deduplicateEvents,
getFilterResultCardinality,
} from "@welshman/util"
import {RelayMessage, ClientMessageType, isRelayEvent, isRelayEose} from "./message.js"
@@ -25,20 +24,6 @@ import {SocketEvent, SocketStatus} from "./socket.js"
import {netContext} from "./context.js"
import {Tracker} from "./tracker.js"
const deduplicateEvents = (events: TrustedEvent[]) => {
const eventsByAddress = new Map<string, TrustedEvent>()
for (const event of events) {
const address = getAddress(event)
if (lte(eventsByAddress.get(address)?.created_at, event.created_at)) {
eventsByAddress.set(address, event)
}
}
return Array.from(eventsByAddress.values())
}
export type BaseRequestOptions = {
signal?: AbortSignal
tracker?: Tracker