applesauce-core
AppleSauce Core is an interpretation layer for nostr clients, Push events into the in-memory database and get nicely formatted data out with queries
Example
import { EventStore, QueryStore } from "applesauce-core";
import { Relay } from "nostr-tools/relay";
const eventStore = new EventStore();
const queryStore = new QueryStore(eventStore);
const relay = await Relay.connect("wss://relay.example.com");
const sub = relay.subscribe([{ authors: ["266815e0c9210dfa324c6cba3573b14bee49da4209a9456f9484e5106cd408a5"] }], {
onevent(event) {
eventStore.add(event);
},
});
const profile = queryStore.profile("266815e0c9210dfa324c6cba3573b14bee49da4209a9456f9484e5106cd408a5");
profile.subscribe((parsed) => {
if (parsed) console.log(parsed);
});
const timeline = queryStore.timeline({ kinds: [1] });
timeline.subscribe((events) => {
console.log(events);
});