Move filter types into filter.ts
This commit is contained in:
parent
baace5ea2d
commit
c18d7b952f
|
@ -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<typeof RelayPool>;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<K extends number = number> extends Filter<K> {
|
||||
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 };
|
||||
|
|
|
@ -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<K extends number>(
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<K extends number = number> implements AsyncIterable<Event<K>> {
|
||||
filters: DittoFilter<K>[];
|
||||
|
|
17
src/types.ts
17
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<K extends number = number> extends Filter<K> {
|
||||
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 };
|
||||
|
|
Loading…
Reference in New Issue