Fix compilation error, add mergeRepositoryUpdates
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@welshman/net",
|
||||
"version": "0.6.1",
|
||||
"version": "0.6.2",
|
||||
"author": "hodlbod",
|
||||
"license": "MIT",
|
||||
"description": "Utilities for connecting with nostr relays.",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import EventEmitter from "events"
|
||||
import {call, sleep, mergeRight, on} from "@welshman/lib"
|
||||
import {isRelayUrl, matchFilters, Filter} from "@welshman/util"
|
||||
import {LOCAL_RELAY_URL, Repository} from "./repository"
|
||||
import {LOCAL_RELAY_URL, Repository} from "./repository.js"
|
||||
import {
|
||||
RelayMessage,
|
||||
RelayMessageType,
|
||||
|
||||
@@ -20,6 +20,24 @@ export type RepositoryUpdate = {
|
||||
removed: Set<string>
|
||||
}
|
||||
|
||||
export const mergeRepositoryUpdates = (updates: RepositoryUpdate[]): RepositoryUpdate => {
|
||||
const added: TrustedEvent[] = []
|
||||
const removed = new Set<string>()
|
||||
|
||||
for (const update of updates) {
|
||||
for (const event of update.added) {
|
||||
added.push(event)
|
||||
removed.delete(event.id)
|
||||
}
|
||||
|
||||
for (const id of update.removed) {
|
||||
removed.add(id)
|
||||
}
|
||||
}
|
||||
|
||||
return {added, removed}
|
||||
}
|
||||
|
||||
export class Repository extends Emitter {
|
||||
eventsById = new Map<string, TrustedEvent>()
|
||||
eventsByAddress = new Map<string, TrustedEvent>()
|
||||
|
||||
Reference in New Issue
Block a user