From f58c2098f04648c901dc93eff3a2c14b8dbc5acb Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 23 Jan 2024 11:17:31 -0600 Subject: [PATCH] Add DittoEvent and DittoFilter dedicated interface modules --- src/deps.ts | 2 ++ src/interfaces/DittoEvent.ts | 24 ++++++++++++++++++++++++ src/interfaces/DittoFilter.ts | 14 ++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/interfaces/DittoEvent.ts create mode 100644 src/interfaces/DittoFilter.ts diff --git a/src/deps.ts b/src/deps.ts index fa7ff6f..53a07e9 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -91,6 +91,8 @@ export { type LNURLDetails, type MapCache, NIP05, + type NostrEvent, + type NostrFilter, } from 'https://gitlab.com/soapbox-pub/nlib/-/raw/5d711597f3b2a163817cc1fb0f1f3ce8cede7cf7/mod.ts'; export type * as TypeFest from 'npm:type-fest@^4.3.0'; diff --git a/src/interfaces/DittoEvent.ts b/src/interfaces/DittoEvent.ts new file mode 100644 index 0000000..ed327d4 --- /dev/null +++ b/src/interfaces/DittoEvent.ts @@ -0,0 +1,24 @@ +import { type NostrEvent } from '@/deps.ts'; + +/** Ditto internal stats for the event's author. */ +export interface AuthorStats { + followers_count: number; + following_count: number; + notes_count: number; +} + +/** Ditto internal stats for the event. */ +export interface EventStats { + replies_count: number; + reposts_count: number; + reactions_count: number; +} + +/** Internal Event representation used by Ditto, including extra keys. */ +export interface DittoEvent extends NostrEvent { + author?: DittoEvent; + author_stats?: AuthorStats; + event_stats?: EventStats; + d_author?: DittoEvent; + user?: DittoEvent; +} diff --git a/src/interfaces/DittoFilter.ts b/src/interfaces/DittoFilter.ts new file mode 100644 index 0000000..4ecda96 --- /dev/null +++ b/src/interfaces/DittoFilter.ts @@ -0,0 +1,14 @@ +import { type NostrEvent, type NostrFilter } from '@/deps.ts'; + +import { type DittoEvent } from './DittoEvent.ts'; + +/** Additional properties that may be added by Ditto to events. */ +export type DittoRelation = Exclude; + +/** Custom filter interface that extends Nostr filters with extra options for Ditto. */ +export interface DittoFilter extends NostrFilter { + /** Whether the event was authored by a local user. */ + local?: boolean; + /** Additional fields to add to the returned event. */ + relations?: DittoRelation[]; +}