Add memoize and batcher, bump versions

This commit is contained in:
Jon Staab
2024-08-12 11:17:27 -07:00
parent a8d0f5bc4f
commit 5d2186825b
15 changed files with 132 additions and 108 deletions
+4 -4
View File
@@ -48,22 +48,22 @@ export const normalizeRelayUrl = (url: string, {allowInsecure = false}: Normaliz
return prefix + url
}
export class Relay extends Emitter {
export class Relay<T extends TrustedEvent> extends Emitter {
subs = new Map<string, Filter[]>()
constructor(readonly repository: Repository) {
constructor(readonly repository: Repository<T>) {
super()
}
send(type: string, ...message: any[]) {
switch(type) {
case 'EVENT': return this.handleEVENT(message as [TrustedEvent])
case 'EVENT': return this.handleEVENT(message as [T])
case 'CLOSE': return this.handleCLOSE(message as [string])
case 'REQ': return this.handleREQ(message as [string, ...Filter[]])
}
}
handleEVENT([event]: [TrustedEvent]) {
handleEVENT([event]: [T]) {
this.repository.publish(event)
// Callers generally expect async relays