Move deduplicateEvents to util
This commit is contained in:
@@ -84,7 +84,7 @@ const authEvent = makeBlossomAuthEvent({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Sign the auth event with your signer
|
// Sign the auth event with your signer
|
||||||
const signedAuthEvent = await signer.signEvent(authEvent)
|
const signedAuthEvent = await signer.sign(authEvent)
|
||||||
|
|
||||||
// Upload a file
|
// Upload a file
|
||||||
const file = new File(["Hello world"], "hello.txt", { type: "text/plain" })
|
const file = new File(["Hello world"], "hello.txt", { type: "text/plain" })
|
||||||
|
|||||||
@@ -87,6 +87,9 @@ export declare const getIdentifier: (e: EventTemplate) => string | undefined;
|
|||||||
export declare const getIdOrAddress: (e: HashedEvent) => string;
|
export declare const getIdOrAddress: (e: HashedEvent) => string;
|
||||||
export declare const getIdAndAddress: (e: HashedEvent) => string[];
|
export declare const getIdAndAddress: (e: HashedEvent) => string[];
|
||||||
|
|
||||||
|
// Event deduplication by id or address
|
||||||
|
export declare const deduplicateEvents: (e: TrustedEvent) => TrustedEvent[];
|
||||||
|
|
||||||
// Event type checking
|
// Event type checking
|
||||||
export declare const isEphemeral: (e: EventTemplate) => boolean;
|
export declare const isEphemeral: (e: EventTemplate) => boolean;
|
||||||
export declare const isReplaceable: (e: EventTemplate) => boolean;
|
export declare const isReplaceable: (e: EventTemplate) => boolean;
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman",
|
"name": "@welshman",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/app",
|
"name": "@welshman/app",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of svelte stores for use in building nostr client applications.",
|
"description": "A collection of svelte stores for use in building nostr client applications.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/content",
|
"name": "@welshman/content",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of utilities for parsing nostr note content.",
|
"description": "A collection of utilities for parsing nostr note content.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/editor",
|
"name": "@welshman/editor",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A batteries-included nostr editor.",
|
"description": "A batteries-included nostr editor.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/feeds",
|
"name": "@welshman/feeds",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Utilities for building dynamic nostr feeds.",
|
"description": "Utilities for building dynamic nostr feeds.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/lib",
|
"name": "@welshman/lib",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of utilities.",
|
"description": "A collection of utilities.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/net",
|
"name": "@welshman/net",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "Utilities for connecting with nostr relays.",
|
"description": "Utilities for connecting with nostr relays.",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
on,
|
on,
|
||||||
uniq,
|
uniq,
|
||||||
lte,
|
|
||||||
flatten,
|
flatten,
|
||||||
addToMapKey,
|
addToMapKey,
|
||||||
defer,
|
defer,
|
||||||
@@ -13,10 +12,10 @@ import {
|
|||||||
} from "@welshman/lib"
|
} from "@welshman/lib"
|
||||||
import {
|
import {
|
||||||
Filter,
|
Filter,
|
||||||
getAddress,
|
|
||||||
unionFilters,
|
unionFilters,
|
||||||
matchFilters,
|
matchFilters,
|
||||||
TrustedEvent,
|
TrustedEvent,
|
||||||
|
deduplicateEvents,
|
||||||
getFilterResultCardinality,
|
getFilterResultCardinality,
|
||||||
} from "@welshman/util"
|
} from "@welshman/util"
|
||||||
import {RelayMessage, ClientMessageType, isRelayEvent, isRelayEose} from "./message.js"
|
import {RelayMessage, ClientMessageType, isRelayEvent, isRelayEose} from "./message.js"
|
||||||
@@ -25,20 +24,6 @@ import {SocketEvent, SocketStatus} from "./socket.js"
|
|||||||
import {netContext} from "./context.js"
|
import {netContext} from "./context.js"
|
||||||
import {Tracker} from "./tracker.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 = {
|
export type BaseRequestOptions = {
|
||||||
signal?: AbortSignal
|
signal?: AbortSignal
|
||||||
tracker?: Tracker
|
tracker?: Tracker
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/relay",
|
"name": "@welshman/relay",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "An in-memory nostr relay implementation.",
|
"description": "An in-memory nostr relay implementation.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/router",
|
"name": "@welshman/router",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of utilities for nostr relay selection.",
|
"description": "A collection of utilities for nostr relay selection.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/signer",
|
"name": "@welshman/signer",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A nostr signer implemenation supporting several login methods.",
|
"description": "A nostr signer implemenation supporting several login methods.",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/store",
|
"name": "@welshman/store",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of utilities based on svelte/store for use with welshman",
|
"description": "A collection of utilities based on svelte/store for use with welshman",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@welshman/util",
|
"name": "@welshman/util",
|
||||||
"version": "0.4.6",
|
"version": "0.4.7",
|
||||||
"author": "hodlbod",
|
"author": "hodlbod",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"description": "A collection of nostr-related utilities.",
|
"description": "A collection of nostr-related utilities.",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {verifiedSymbol, verifyEvent as verifyEventPure} from "nostr-tools/pure"
|
import {verifiedSymbol, verifyEvent as verifyEventPure} from "nostr-tools/pure"
|
||||||
import {setNostrWasm, verifyEvent as verifyEventWasm} from "nostr-tools/wasm"
|
import {setNostrWasm, verifyEvent as verifyEventWasm} from "nostr-tools/wasm"
|
||||||
import {initNostrWasm} from "nostr-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 {getReplyTags, getCommentTags, getReplyTagValues, getCommentTagValues} from "./Tags.js"
|
||||||
import {getAddress, Address} from "./Address.js"
|
import {getAddress, Address} from "./Address.js"
|
||||||
import {
|
import {
|
||||||
@@ -136,6 +136,20 @@ export const getIdOrAddress = (e: HashedEvent) => (isReplaceable(e) ? getAddress
|
|||||||
export const getIdAndAddress = (e: HashedEvent) =>
|
export const getIdAndAddress = (e: HashedEvent) =>
|
||||||
isReplaceable(e) ? [e.id, getAddress(e)] : [e.id]
|
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 isEphemeral = (e: EventTemplate) => isEphemeralKind(e.kind)
|
||||||
|
|
||||||
export const isReplaceable = (e: EventTemplate) => isReplaceableKind(e.kind)
|
export const isReplaceable = (e: EventTemplate) => isReplaceableKind(e.kind)
|
||||||
|
|||||||
Reference in New Issue
Block a user