Add missing "error" event to on and off type definitions

This commit is contained in:
Tristan
2022-12-25 13:43:38 +01:00
committed by fiatjaf
parent c37d10bb9d
commit cc2250da1f

View File

@@ -3,6 +3,8 @@
import {Event, verifySignature, validateEvent} from './event'
import {Filter, matchFilters} from './filter'
type RelayEvent = 'connect' | 'disconnect' | 'error' | 'notice'
export type Relay = {
url: string
status: number
@@ -10,8 +12,8 @@ export type Relay = {
close: () => Promise<void>
sub: (filters: Filter[], opts: SubscriptionOptions) => Sub
publish: (event: Event) => Pub
on: (type: 'connect' | 'disconnect' | 'notice', cb: any) => void
off: (type: 'connect' | 'disconnect' | 'notice', cb: any) => void
on: (type: RelayEvent, cb: any) => void
off: (type: RelayEvent, cb: any) => void
}
export type Pub = {
on: (type: 'ok' | 'seen' | 'failed', cb: any) => void
@@ -185,7 +187,7 @@ export function relayInit(url: string): Relay {
url,
sub,
on: (
type: 'connect' | 'disconnect' | 'error' | 'notice',
type: RelayEvent,
cb: any
): void => {
listeners[type].push(cb)
@@ -194,7 +196,7 @@ export function relayInit(url: string): Relay {
}
},
off: (
type: 'connect' | 'disconnect' | 'error' | 'notice',
type: RelayEvent,
cb: any
): void => {
let index = listeners[type].indexOf(cb)