Implement NStore interface from NLib

This commit is contained in:
Alex Gleason
2024-01-23 14:06:16 -06:00
parent 0a58233b4e
commit c6062874bd
32 changed files with 193 additions and 218 deletions

View File

@@ -134,7 +134,7 @@ const accountStatusesController: AppController = async (c) => {
const { pinned, limit, exclude_replies, tagged } = accountStatusesQuerySchema.parse(c.req.query());
if (pinned) {
const [pinEvent] = await eventsDB.filter([{ kinds: [10001], authors: [pubkey], limit: 1 }]);
const [pinEvent] = await eventsDB.query([{ kinds: [10001], authors: [pubkey], limit: 1 }]);
if (pinEvent) {
const pinnedEventIds = getTagSet(pinEvent.tags, 'e');
return renderStatuses(c, [...pinnedEventIds].reverse());
@@ -156,7 +156,7 @@ const accountStatusesController: AppController = async (c) => {
filter['#t'] = [tagged];
}
let events = await eventsDB.filter([filter]);
let events = await eventsDB.query([filter]);
if (exclude_replies) {
events = events.filter((event) => !findReplyTag(event.tags));
@@ -293,7 +293,7 @@ const favouritesController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
const params = paginationSchema.parse(c.req.query());
const events7 = await eventsDB.filter(
const events7 = await eventsDB.query(
[{ kinds: [7], authors: [pubkey], ...params }],
{ signal: AbortSignal.timeout(1000) },
);
@@ -302,7 +302,7 @@ const favouritesController: AppController = async (c) => {
.map((event) => event.tags.find((tag) => tag[0] === 'e')?.[1])
.filter((id): id is string => !!id);
const events1 = await eventsDB.filter(
const events1 = await eventsDB.query(
[{ kinds: [1], ids, relations: ['author', 'event_stats', 'author_stats'] }],
{
signal: AbortSignal.timeout(1000),

View File

@@ -39,9 +39,9 @@ const adminAccountsController: AppController = async (c) => {
const { since, until, limit } = paginationSchema.parse(c.req.query());
const events = await eventsDB.filter([{ kinds: [30361], authors: [Conf.pubkey], since, until, limit }]);
const events = await eventsDB.query([{ kinds: [30361], authors: [Conf.pubkey], since, until, limit }]);
const pubkeys = events.map((event) => event.tags.find(([name]) => name === 'd')?.[1]!);
const authors = await eventsDB.filter([{ kinds: [0], authors: pubkeys }]);
const authors = await eventsDB.query([{ kinds: [0], authors: pubkeys }]);
for (const event of events) {
const d = event.tags.find(([name]) => name === 'd')?.[1];

View File

@@ -7,7 +7,7 @@ import { renderAccounts } from '@/views.ts';
const blocksController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
const [event10000] = await eventsDB.filter([
const [event10000] = await eventsDB.query([
{ kinds: [10000], authors: [pubkey], limit: 1 },
]);

View File

@@ -7,7 +7,7 @@ import { renderStatuses } from '@/views.ts';
const bookmarksController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
const [event10003] = await eventsDB.filter([
const [event10003] = await eventsDB.query([
{ kinds: [10003], authors: [pubkey], limit: 1 },
]);

View File

@@ -6,7 +6,7 @@ import { eventsDB } from '@/storages.ts';
const instanceController: AppController = async (c) => {
const { host, protocol } = Conf.url;
const [event] = await eventsDB.filter([{ kinds: [0], authors: [Conf.pubkey], limit: 1 }]);
const [event] = await eventsDB.query([{ kinds: [0], authors: [Conf.pubkey], limit: 1 }]);
const meta = jsonServerMetaSchema.parse(event?.content);
/** Protocol to use for WebSocket URLs, depending on the protocol of the `LOCAL_DOMAIN`. */

View File

@@ -7,7 +7,7 @@ const notificationsController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
const { since, until } = paginationSchema.parse(c.req.query());
const events = await eventsDB.filter(
const events = await eventsDB.query(
[{ kinds: [1], '#p': [pubkey], since, until }],
{ signal: AbortSignal.timeout(3000) },
);

View File

@@ -8,7 +8,7 @@ import { createAdminEvent } from '@/utils/api.ts';
import { jsonSchema } from '@/schema.ts';
const frontendConfigController: AppController = async (c) => {
const [event] = await eventsDB.filter([{
const [event] = await eventsDB.query([{
kinds: [30078],
authors: [Conf.pubkey],
'#d': ['pub.ditto.pleroma.config'],
@@ -36,7 +36,7 @@ const frontendConfigController: AppController = async (c) => {
const configController: AppController = async (c) => {
const { pubkey } = Conf;
const [event] = await eventsDB.filter([{
const [event] = await eventsDB.query([{
kinds: [30078],
authors: [pubkey],
'#d': ['pub.ditto.pleroma.config'],
@@ -54,7 +54,7 @@ const configController: AppController = async (c) => {
const updateConfigController: AppController = async (c) => {
const { pubkey } = Conf;
const [event] = await eventsDB.filter([{
const [event] = await eventsDB.query([{
kinds: [30078],
authors: [pubkey],
'#d': ['pub.ditto.pleroma.config'],

View File

@@ -78,7 +78,7 @@ function searchEvents({ q, type, limit, account_id }: SearchQuery, signal: Abort
filter.authors = [account_id];
}
return searchStore.filter([filter], { signal });
return searchStore.query([filter], { signal });
}
/** Get event kinds to search from `type` query param. */
@@ -96,7 +96,7 @@ function typeToKinds(type: SearchQuery['type']): number[] {
/** Resolve a searched value into an event, if applicable. */
async function lookupEvent(query: SearchQuery, signal: AbortSignal): Promise<NostrEvent | undefined> {
const filters = await getLookupFilters(query, signal);
const [event] = await searchStore.filter(filters, { limit: 1, signal });
const [event] = await searchStore.query(filters, { limit: 1, signal });
return event;
}

View File

@@ -32,7 +32,7 @@ const hashtagTimelineController: AppController = (c) => {
/** Render statuses for timelines. */
async function renderStatuses(c: AppContext, filters: DittoFilter[], signal = AbortSignal.timeout(1000)) {
const events = await eventsDB.filter(
const events = await eventsDB.query(
filters.map((filter) => ({ ...filter, relations: ['author', 'event_stats', 'author_stats'] })),
{ signal },
);