Remove deprecated getFilter (singular) functions
This commit is contained in:
parent
96641a6fa0
commit
5515c40df3
|
@ -73,11 +73,6 @@ function getFilters<K extends number>(filters: Filter<K>[], opts: GetFiltersOpts
|
|||
});
|
||||
}
|
||||
|
||||
/** @deprecated Use `getFilters` instead. */
|
||||
function getFilter<K extends number>(filter: Filter<K>, opts: GetFiltersOpts = {}): Promise<SignedEvent<K>[]> {
|
||||
return getFilters([filter], opts);
|
||||
}
|
||||
|
||||
/** Get a Nostr event by its ID. */
|
||||
const getEvent = async <K extends number = number>(id: string, kind?: K): Promise<SignedEvent<K> | undefined> => {
|
||||
const event = await (getPool().getEventById(id, Conf.poolRelays, 0) as Promise<SignedEvent>);
|
||||
|
@ -102,7 +97,7 @@ const getAuthor = async (pubkey: string, timeout = 1000): Promise<SignedEvent<0>
|
|||
|
||||
/** Get users the given pubkey follows. */
|
||||
const getFollows = async (pubkey: string): Promise<SignedEvent<3> | undefined> => {
|
||||
const [event] = await getFilter({ authors: [pubkey], kinds: [3] }, { timeout: 5000 });
|
||||
const [event] = await getFilters([{ authors: [pubkey], kinds: [3] }], { timeout: 5000 });
|
||||
|
||||
// TODO: figure out a better, more generic & flexible way to handle event cache (and timeouts?)
|
||||
// Prewarm cache in GET `/api/v1/accounts/verify_credentials`
|
||||
|
@ -128,13 +123,13 @@ async function getFeed(event3: Event<3>, params: PaginationParams): Promise<Sign
|
|||
...params,
|
||||
};
|
||||
|
||||
const results = await getFilter(filter, { timeout: 5000 }) as SignedEvent<1>[];
|
||||
const results = await getFilters([filter], { timeout: 5000 }) as SignedEvent<1>[];
|
||||
return results.sort(eventDateComparator);
|
||||
}
|
||||
|
||||
/** Get a feed of all known text notes. */
|
||||
async function getPublicFeed(params: PaginationParams): Promise<SignedEvent<1>[]> {
|
||||
const results = await getFilter({ kinds: [1], ...params }, { timeout: 5000 });
|
||||
const results = await getFilters([{ kinds: [1], ...params }], { timeout: 5000 });
|
||||
return results.sort(eventDateComparator);
|
||||
}
|
||||
|
||||
|
@ -157,7 +152,7 @@ async function getAncestors(event: Event<1>, result = [] as Event<1>[]): Promise
|
|||
}
|
||||
|
||||
function getDescendants(eventId: string): Promise<SignedEvent<1>[]> {
|
||||
return getFilter({ kinds: [1], '#e': [eventId], limit: 200 }, { timeout: 2000 }) as Promise<SignedEvent<1>[]>;
|
||||
return getFilters([{ kinds: [1], '#e': [eventId] }], { limit: 200, timeout: 2000 }) as Promise<SignedEvent<1>[]>;
|
||||
}
|
||||
|
||||
/** Publish an event to the Nostr relay. */
|
||||
|
@ -170,15 +165,4 @@ function publish(event: SignedEvent, relays = Conf.publishRelays): void {
|
|||
}
|
||||
}
|
||||
|
||||
export {
|
||||
getAncestors,
|
||||
getAuthor,
|
||||
getDescendants,
|
||||
getEvent,
|
||||
getFeed,
|
||||
getFilter,
|
||||
getFilters,
|
||||
getFollows,
|
||||
getPublicFeed,
|
||||
publish,
|
||||
};
|
||||
export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFilters, getFollows, getPublicFeed, publish };
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import event55920b75 from '~/fixtures/events/55920b75.json' assert { type: 'json' };
|
||||
import { assertEquals } from '@/deps-test.ts';
|
||||
|
||||
import { getFilter, insertEvent } from './events.ts';
|
||||
import { getFilters, insertEvent } from './events.ts';
|
||||
|
||||
Deno.test('insert and filter events', async () => {
|
||||
await insertEvent(event55920b75);
|
||||
|
||||
assertEquals(await getFilter({ kinds: [1] }), [event55920b75]);
|
||||
assertEquals(await getFilter({ kinds: [3] }), []);
|
||||
assertEquals(await getFilter({ since: 1691091000 }), [event55920b75]);
|
||||
assertEquals(await getFilter({ until: 1691091000 }), []);
|
||||
assertEquals(await getFilters([{ kinds: [1] }]), [event55920b75]);
|
||||
assertEquals(await getFilters([{ kinds: [3] }]), []);
|
||||
assertEquals(await getFilters([{ since: 1691091000 }]), [event55920b75]);
|
||||
assertEquals(await getFilters([{ until: 1691091000 }]), []);
|
||||
assertEquals(
|
||||
await getFilter({ '#proxy': ['https://gleasonator.com/objects/8f6fac53-4f66-4c6e-ac7d-92e5e78c3e79'] }),
|
||||
await getFilters([{ '#proxy': ['https://gleasonator.com/objects/8f6fac53-4f66-4c6e-ac7d-92e5e78c3e79'] }]),
|
||||
[event55920b75],
|
||||
);
|
||||
});
|
||||
|
|
|
@ -119,11 +119,6 @@ async function getFilters<K extends number>(
|
|||
));
|
||||
}
|
||||
|
||||
/** @deprecated Use `getFilters` instead. */
|
||||
function getFilter<K extends number = number>(filter: DittoFilter<K>): Promise<SignedEvent<K>[]> {
|
||||
return getFilters<K>([filter]);
|
||||
}
|
||||
|
||||
/** Returns whether the pubkey is followed by a local user. */
|
||||
async function isLocallyFollowed(pubkey: string): Promise<boolean> {
|
||||
return Boolean(
|
||||
|
@ -136,4 +131,4 @@ async function isLocallyFollowed(pubkey: string): Promise<boolean> {
|
|||
);
|
||||
}
|
||||
|
||||
export { getFilter, getFilters, insertEvent, isLocallyFollowed };
|
||||
export { getFilters, insertEvent, isLocallyFollowed };
|
||||
|
|
Loading…
Reference in New Issue