diff --git a/relay.ts b/relay.ts index 4970ef0..4686fcd 100644 --- a/relay.ts +++ b/relay.ts @@ -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 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)