I need a simple JS nostr in-memory event store. Filters should be supported. e.g. events = eventstore.req({kinds: [1,6], authors: [pubkey1, pubkey2]})

window.nostrdb is good, but I want it to work in nodejs.

nostrify/NSet is good, but I need it to understand the filter API.

There is a test relay, in-memory (dunno the name), but it listens on a port, I don't need that.

Any ideas?

I am kind of clueless where I should seek such information, but that's a story for another day.

Reply to this note

Please Login to reply.

Discussion

Thanks for it!

I am developing a library (https://www.npmjs.com/package/nostr-tribes) with the least amount of dependencies. It already depends on nostr-tools (this is its only dependency), and it is not the right time to add a new 8.7megs dependency to ndk (memory cache adapter depends on ndk main package).

In my mind this module should be more like a package that others depend on, instead of a package that depends on code that supports cashu, nutzaps, nip5 and so on.

Like your asknostr.site though! Great initiative, might answer my 2nd question :)

💡 Turns out it's quite simple to write. Not very performant, but will do for now.

import { matchFilter, type Event, type Filter } from "nostr-tools"

export class MemStore {

events: Event[]

constructor() {

this.events = []

}

add(event: Event) {

this.events.push(event)

}

req(filtr: Filter): Event[] {

let r: Event[] = []

this.events.forEach(e => {

if (matchFilter(filtr, e)) {

r.push(e)

}

})

return r

}

}