From c18d7b952fc0c089515cd55ab2effd824b0c74ab Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 25 Aug 2023 13:38:21 -0500 Subject: [PATCH] Move filter types into filter.ts --- src/client.ts | 2 +- src/db/events.ts | 2 +- src/filter.ts | 19 ++++++++++++++++--- src/mixer.ts | 2 +- src/subs.ts | 3 ++- src/subscription.ts | 4 ++-- src/types.ts | 17 +---------------- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/client.ts b/src/client.ts index 0c55d64..dd0efcc 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3,7 +3,7 @@ import { type Event, type Filter, matchFilters, RelayPool, TTLCache } from '@/de import * as pipeline from '@/pipeline.ts'; import { Time } from '@/utils.ts'; -import type { GetFiltersOpts } from '@/types.ts'; +import type { GetFiltersOpts } from '@/filter.ts'; type Pool = InstanceType; diff --git a/src/db/events.ts b/src/db/events.ts index 77d0204..48b9666 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -1,7 +1,7 @@ import { db, type TagRow } from '@/db.ts'; import { type Event, type Insertable } from '@/deps.ts'; -import type { DittoFilter, GetFiltersOpts } from '@/types.ts'; +import type { DittoFilter, GetFiltersOpts } from '@/filter.ts'; type TagCondition = ({ event, count }: { event: Event; count: number }) => boolean; diff --git a/src/filter.ts b/src/filter.ts index 9cde0d1..605d4cb 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -1,6 +1,19 @@ -import { type Event, matchFilters } from '@/deps.ts'; +import { type Event, type Filter, matchFilters } from '@/deps.ts'; -import type { DittoFilter, EventData } from '@/types.ts'; +import type { EventData } from '@/types.ts'; + +/** Custom filter interface that extends Nostr filters with extra options for Ditto. */ +interface DittoFilter extends Filter { + local?: boolean; +} + +/** Additional options to apply to the whole subscription. */ +interface GetFiltersOpts { + /** How long to wait (in milliseconds) until aborting the request. */ + timeout?: number; + /** Event limit for the whole subscription. */ + limit?: number; +} function matchDittoFilter(filter: DittoFilter, event: Event, data: EventData): boolean { if (filter.local && !data.user) { @@ -24,4 +37,4 @@ function matchDittoFilters(filters: DittoFilter[], event: Event, data: EventData return false; } -export { matchDittoFilters }; +export { type DittoFilter, type GetFiltersOpts, matchDittoFilters }; diff --git a/src/mixer.ts b/src/mixer.ts index c2e6b3a..4c160b3 100644 --- a/src/mixer.ts +++ b/src/mixer.ts @@ -4,7 +4,7 @@ import * as client from '@/client.ts'; import * as eventsDB from '@/db/events.ts'; import { eventDateComparator } from '@/utils.ts'; -import type { DittoFilter, GetFiltersOpts } from '@/types.ts'; +import type { DittoFilter, GetFiltersOpts } from '@/filter.ts'; /** Get filters from the database and pool, and mix the best results together. */ async function getFilters( diff --git a/src/subs.ts b/src/subs.ts index f550678..5c175c3 100644 --- a/src/subs.ts +++ b/src/subs.ts @@ -1,7 +1,8 @@ import { type Event } from '@/deps.ts'; import { Subscription } from '@/subscription.ts'; -import type { DittoFilter, EventData } from '@/types.ts'; +import type { DittoFilter } from '@/filter.ts'; +import type { EventData } from '@/types.ts'; /** * Manages Ditto event subscriptions. diff --git a/src/subscription.ts b/src/subscription.ts index 24a78f0..227c2f4 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -1,7 +1,7 @@ import { type Event } from '@/deps.ts'; -import { matchDittoFilters } from '@/filter.ts'; +import { type DittoFilter, matchDittoFilters } from '@/filter.ts'; -import type { DittoFilter, EventData } from '@/types.ts'; +import type { EventData } from '@/types.ts'; class Subscription implements AsyncIterable> { filters: DittoFilter[]; diff --git a/src/types.ts b/src/types.ts index beb184b..11f933d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,21 +1,6 @@ import { UserRow } from '@/db.ts'; -import { type Filter } from '@/deps.ts'; - -/** Custom filter interface that extends Nostr filters with extra options for Ditto. */ -interface DittoFilter extends Filter { - local?: boolean; -} - -/** Additional options to apply to the whole subscription. */ -interface GetFiltersOpts { - /** How long to wait (in milliseconds) until aborting the request. */ - timeout?: number; - /** Event limit for the whole subscription. */ - limit?: number; -} - interface EventData { user: UserRow | undefined; } -export type { DittoFilter, EventData, GetFiltersOpts }; +export type { EventData };