Add `supportedNips` to all storages

This commit is contained in:
Alex Gleason 2024-01-03 21:39:54 -06:00
parent 8ab0fefbf2
commit a4bc951eee
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
6 changed files with 13 additions and 5 deletions

View File

@ -59,6 +59,7 @@ function storeEvent(event: Event, opts: StoreEventOpts = {}): Promise<void> {
}
const client: EventStore = {
supportedNips: [1],
getEvents,
storeEvent,
countEvents: () => Promise.reject(new Error('COUNT not implemented')),

View File

@ -32,6 +32,8 @@ class Reqmeister extends EventEmitter<{ [filterId: string]: (event: Event) => an
#promise!: Promise<void>;
#resolve!: () => void;
supportedNips = [];
constructor(opts: ReqmeisterOpts = {}) {
super();
this.#opts = opts;

View File

@ -56,6 +56,9 @@ class EventsDB implements EventStore {
#db: Kysely<DittoDB>;
#debug = Debug('ditto:db:events');
/** NIPs supported by this storage method. */
supportedNips = [1, 45, 50];
constructor(db: Kysely<DittoDB>) {
this.#db = db;
}

View File

@ -8,15 +8,13 @@ class Memorelay implements EventStore {
#debug = Debug('ditto:memorelay');
#cache: LRUCache<string, Event>;
/** NIPs supported by this storage method. */
supportedNips = [1, 45];
constructor(...args: ConstructorParameters<typeof LRUCache<string, Event>>) {
this.#cache = new LRUCache<string, Event>(...args);
}
/** NIPs supported by this storage method. */
get supportedNips(): number[] {
return [1];
}
/** Iterate stored events. */
*#events(): Generator<Event> {
for (const event of this.#cache.values()) {

View File

@ -13,6 +13,8 @@ class Optimizer implements EventStore {
#cache: EventStore;
#client: EventStore;
supportedNips = [1];
constructor(opts: OptimizerOpts) {
this.#db = opts.db;
this.#cache = opts.cache;

View File

@ -33,6 +33,8 @@ interface DittoEvent<K extends number = number> extends Event<K> {
/** Storage interface for Nostr events. */
interface EventStore {
/** Indicates NIPs supported by this data store, similar to NIP-11. For example, `50` would indicate support for `search` filters. */
supportedNips: readonly number[];
/** Add an event to the store. */
storeEvent(event: Event, opts?: StoreEventOpts): Promise<void>;
/** Get events from filters. */