Add shortcut handlers to subscribe

This commit is contained in:
Jon Staab
2024-09-05 11:47:38 -07:00
parent 25845dc837
commit 233a4e3576
5 changed files with 38 additions and 46 deletions
+6 -6
View File
@@ -1,6 +1,6 @@
import {uniq} from '@welshman/lib'
import {matchFilters, unionFilters, hasValidSignature} from '@welshman/util'
import type {Filter, SignedEvent} from '@welshman/util'
import {matchFilters, unionFilters, isSignedEvent, hasValidSignature} from '@welshman/util'
import type {Filter, TrustedEvent} from '@welshman/util'
import {Pool} from "./Pool"
import {Executor} from "./Executor"
import {Relays} from "./target/Relays"
@@ -11,17 +11,17 @@ export const defaultPool = new Pool()
export const defaultGetExecutor = (relays: string[]) =>
new Executor(new Relays(relays.map((relay: string) => NetworkContext.pool.get(relay))))
const defaultOnEvent = (url: string, event: SignedEvent) => null
const defaultOnEvent = (url: string, event: TrustedEvent) => null
const defaultOnAuth = (url: string, challenge: string) => null
const defaultOnOk = (url: string, id: string, ok: boolean, message: string) => null
const defaultIsDeleted = (url: string, event: SignedEvent) => false
const defaultIsDeleted = (url: string, event: TrustedEvent) => false
const defaultHasValidSignature = (url: string, event: SignedEvent) => hasValidSignature(event)
const defaultHasValidSignature = (url: string, event: TrustedEvent) => isSignedEvent(event) && hasValidSignature(event)
const defaultMatchFilters = (url: string, filters: Filter[], event: SignedEvent) => matchFilters(filters, event)
const defaultMatchFilters = (url: string, filters: Filter[], event: TrustedEvent) => matchFilters(filters, event)
export function* defaultOptimizeSubscriptions(subs: Subscription[]) {
for (const relay of uniq(subs.flatMap(sub => sub.request.relays || []))) {