From 2d4d9117bdd940f8f81cee08fb22d8742af7554d Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 8 Nov 2023 15:17:37 +0000 Subject: [PATCH] fix: events --- packages/system/src/connection.ts | 13 ++++--------- packages/system/src/nostr-system.ts | 9 ++------- packages/system/src/query.ts | 16 +++------------- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/packages/system/src/connection.ts b/packages/system/src/connection.ts index 40aa760b..43a83f41 100644 --- a/packages/system/src/connection.ts +++ b/packages/system/src/connection.ts @@ -1,14 +1,14 @@ import { v4 as uuid } from "uuid"; import debug from "debug"; import WebSocket from "isomorphic-ws"; -import { ExternalStore, unixNowMs, dedupe } from "@snort/shared"; +import { unixNowMs, dedupe } from "@snort/shared"; +import EventEmitter from "eventemitter3"; import { DefaultConnectTimeout } from "./const"; import { ConnectionStats } from "./connection-stats"; import { NostrEvent, ReqCommand, ReqFilter, TaggedNostrEvent, u256 } from "./nostr"; import { RelayInfo } from "./relay-info"; import EventKind from "./event-kind"; -import EventEmitter from "events"; /** * Relay settings @@ -55,12 +55,7 @@ interface ConnectionEvents { notice: (msg: string) => void; } -export declare interface Connection { - on(event: U, listener: ConnectionEvents[U]): this; - once(event: U, listener: ConnectionEvents[U]): this; -} - -export class Connection extends EventEmitter { +export class Connection extends EventEmitter { #log: debug.Debugger; #ephemeralCheck?: ReturnType; #activity: number = unixNowMs(); @@ -243,7 +238,7 @@ export class Connection extends EventEmitter { break; } case "NOTICE": { - this.emit("notice", msg[1]); + this.emit("notice", msg[1] as string); this.#log(`NOTICE: ${msg[1]}`); break; } diff --git a/packages/system/src/nostr-system.ts b/packages/system/src/nostr-system.ts index 8c90f6d2..1e36fc50 100644 --- a/packages/system/src/nostr-system.ts +++ b/packages/system/src/nostr-system.ts @@ -1,5 +1,5 @@ import debug from "debug"; -import EventEmitter from "events"; +import EventEmitter from "eventemitter3"; import { unwrap, sanitizeRelayUrl, FeedCache, removeUndefined } from "@snort/shared"; import { NostrEvent, TaggedNostrEvent } from "./nostr"; @@ -32,15 +32,10 @@ interface NostrSystemEvents { event: (ev: TaggedNostrEvent) => void; } -export declare interface NostrSystem { - on(event: U, listener: NostrSystemEvents[U]): this; - once(event: U, listener: NostrSystemEvents[U]): this; -} - /** * Manages nostr content retrieval system */ -export class NostrSystem extends EventEmitter implements SystemInterface { +export class NostrSystem extends EventEmitter implements SystemInterface { #log = debug("System"); /** diff --git a/packages/system/src/query.ts b/packages/system/src/query.ts index 25321352..945c1a46 100644 --- a/packages/system/src/query.ts +++ b/packages/system/src/query.ts @@ -1,12 +1,12 @@ import { v4 as uuid } from "uuid"; import debug from "debug"; +import EventEmitter from "eventemitter3"; import { unixNowMs, unwrap } from "@snort/shared"; import { Connection, ReqFilter, Nips, TaggedNostrEvent } from "."; import { NoteStore } from "./note-collection"; import { BuiltRawReqFilter } from "./request-builder"; import { eventMatchesFilter } from "./request-matcher"; -import EventEmitter from "events"; interface QueryTraceEvents { change: () => void; @@ -14,15 +14,10 @@ interface QueryTraceEvents { eose: (id: string, connId: string, wasForced: boolean) => void; } -export declare interface QueryTrace { - on(event: U, listener: QueryTraceEvents[U]): this; - once(event: U, listener: QueryTraceEvents[U]): this; -} - /** * Tracing for relay query status */ -export class QueryTrace extends EventEmitter { +export class QueryTrace extends EventEmitter { readonly id: string; readonly start: number; sent?: number; @@ -122,15 +117,10 @@ interface QueryEvents { trace: (report: TraceReport) => void; } -export declare interface Query { - on(event: U, listener: QueryEvents[U]): this; - once(event: U, listener: QueryEvents[U]): this; -} - /** * Active or queued query on the system */ -export class Query extends EventEmitter implements QueryBase { +export class Query extends EventEmitter implements QueryBase { /** * Uniquie ID of this query */