Replace Subscription with Subscribe, add NetworkContext

This commit is contained in:
Jon Staab
2024-03-28 09:56:17 -07:00
parent 46e91c54ec
commit 59511be1aa
9 changed files with 393 additions and 157 deletions
+35
View File
@@ -0,0 +1,35 @@
import type {Event} from 'nostr-tools'
import {matchFilters, hasValidSignature} from '@coracle.social/util'
import type {Filter} from '@coracle.social/util'
import {Pool} from "./Pool"
import {Executor} from "./Executor"
import {Relays} from "./target/Relays"
import type {Subscription} from "./Subscribe"
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: Event) => null
const defaultOnAuth = (url: string, challenge: string) => null
const defaultOnOk = (url: string, id: string, ok: boolean, message: string) => null
const defaultIsDeleted = (url: string, event: Event) => false
const defaultHasValidSignature = (url: string, event: Event) => hasValidSignature(event)
const defaultMatchFilters = (url: string, filters: Filter[], event: Event) => matchFilters(filters, event)
export const NetworkContext = {
pool: defaultPool,
getExecutor: defaultGetExecutor,
onEvent: defaultOnEvent,
onAuth: defaultOnAuth,
onOk: defaultOnOk,
isDeleted: defaultIsDeleted,
hasValidSignature: defaultHasValidSignature,
matchFilters: defaultMatchFilters,
}