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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/app",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of svelte stores for use in building nostr client applications.",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/content",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of utilities for parsing nostr note content.",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/editor",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "A batteries-included nostr editor.",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/feeds",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "Utilities for building dynamic nostr feeds.",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/lib",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of utilities.",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/net",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "Utilities for connecting with nostr relays.",
+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
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/relay",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "An in-memory nostr relay implementation.",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/router",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of utilities for nostr relay selection.",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/signer",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "A nostr signer implemenation supporting several login methods.",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/store",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of utilities based on svelte/store for use with welshman",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/util",
"version": "0.4.6",
"version": "0.4.7",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of nostr-related utilities.",
+15 -1
View File
@@ -1,7 +1,7 @@
import {verifiedSymbol, verifyEvent as verifyEventPure} from "nostr-tools/pure"
import {setNostrWasm, verifyEvent as verifyEventWasm} from "nostr-tools/wasm"
import {initNostrWasm} from "nostr-wasm"
import {mapVals, first, pick, now} from "@welshman/lib"
import {mapVals, lte, first, pick, now} from "@welshman/lib"
import {getReplyTags, getCommentTags, getReplyTagValues, getCommentTagValues} from "./Tags.js"
import {getAddress, Address} from "./Address.js"
import {
@@ -136,6 +136,20 @@ export const getIdOrAddress = (e: HashedEvent) => (isReplaceable(e) ? getAddress
export const getIdAndAddress = (e: HashedEvent) =>
isReplaceable(e) ? [e.id, getAddress(e)] : [e.id]
export const deduplicateEvents = (events: TrustedEvent[]) => {
const eventsByKey = new Map<string, TrustedEvent>()
for (const event of events) {
const key = getIdOrAddress(event)
if (lte(eventsByKey.get(key)?.created_at, event.created_at)) {
eventsByKey.set(key, event)
}
}
return Array.from(eventsByKey.values())
}
export const isEphemeral = (e: EventTemplate) => isEphemeralKind(e.kind)
export const isReplaceable = (e: EventTemplate) => isReplaceableKind(e.kind)