From eff9ea9579f713a8322a723bcff47e0b6fab5c0f Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 17 May 2025 18:51:26 -0300 Subject: [PATCH] remove deprecated subscribeManyMap() --- abstract-pool.ts | 115 ----------------------------------------------- jsr.json | 2 +- package.json | 2 +- 3 files changed, 2 insertions(+), 117 deletions(-) diff --git a/abstract-pool.ts b/abstract-pool.ts index 3caa12b..9ddd031 100644 --- a/abstract-pool.ts +++ b/abstract-pool.ts @@ -180,121 +180,6 @@ export class AbstractSimplePool { } } - /** - * @deprecated Use subscribeMap instead. - */ - subscribeManyMap(requests: { [relay: string]: Filter[] }, params: SubscribeManyParams): SubCloser { - if (this.trackRelays) { - params.receivedEvent = (relay: AbstractRelay, id: string) => { - let set = this.seenOn.get(id) - if (!set) { - set = new Set() - this.seenOn.set(id, set) - } - set.add(relay) - } - } - - const _knownIds = new Set() - const subs: Subscription[] = [] - const relaysLength = Object.keys(requests).length - - // batch all EOSEs into a single - const eosesReceived: boolean[] = [] - let handleEose = (i: number) => { - if (eosesReceived[i]) return // do not act twice for the same relay - eosesReceived[i] = true - if (eosesReceived.filter(a => a).length === relaysLength) { - params.oneose?.() - handleEose = () => {} - } - } - // batch all closes into a single - const closesReceived: string[] = [] - let handleClose = (i: number, reason: string) => { - if (closesReceived[i]) return // do not act twice for the same relay - handleEose(i) - closesReceived[i] = reason - if (closesReceived.filter(a => a).length === relaysLength) { - params.onclose?.(closesReceived) - handleClose = () => {} - } - } - - const localAlreadyHaveEventHandler = (id: string) => { - if (params.alreadyHaveEvent?.(id)) { - return true - } - const have = _knownIds.has(id) - _knownIds.add(id) - return have - } - - // open a subscription in all given relays - const allOpened = Promise.all( - Object.entries(requests).map(async (req, i, arr) => { - if (arr.indexOf(req) !== i) { - // duplicate - handleClose(i, 'duplicate url') - return - } - - let [url, filters] = req - url = normalizeURL(url) - - let relay: AbstractRelay - try { - relay = await this.ensureRelay(url, { - connectionTimeout: params.maxWait ? Math.max(params.maxWait * 0.8, params.maxWait - 1000) : undefined, - }) - } catch (err) { - handleClose(i, (err as any)?.message || String(err)) - return - } - - let subscription = relay.subscribe(filters, { - ...params, - oneose: () => handleEose(i), - onclose: reason => { - if (reason.startsWith('auth-required:') && params.doauth) { - relay - .auth(params.doauth) - .then(() => { - relay.subscribe(filters, { - ...params, - oneose: () => handleEose(i), - onclose: reason => { - handleClose(i, reason) // the second time we won't try to auth anymore - }, - alreadyHaveEvent: localAlreadyHaveEventHandler, - eoseTimeout: params.maxWait, - }) - }) - .catch(err => { - handleClose(i, `auth was required and attempted, but failed with: ${err}`) - }) - } else { - handleClose(i, reason) - } - }, - alreadyHaveEvent: localAlreadyHaveEventHandler, - eoseTimeout: params.maxWait, - }) - - subs.push(subscription) - }), - ) - - return { - async close() { - await allOpened - subs.forEach(sub => { - sub.close() - }) - }, - } - } - subscribeEose( relays: string[], filter: Filter, diff --git a/jsr.json b/jsr.json index 177ef21..019a470 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@nostr/tools", - "version": "2.13.0", + "version": "2.13.1", "exports": { ".": "./index.ts", "./core": "./core.ts", diff --git a/package.json b/package.json index 8519e7d..07ac319 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "nostr-tools", - "version": "2.13.0", + "version": "2.13.1", "description": "Tools for making a Nostr client.", "repository": { "type": "git",