AppleSauce is a collection of utilities for building reactive nostr applications. The common package provides NIP-specific helpers, models, operations, and utilities for working with various Nostr Improvement Proposals (NIPs). This package contains all the extra functionality that applications can use with nostr events that is not directly related to the core protocol.
npm install applesauce-common
or
yarn add applesauce-common
or
pnpm add applesauce-common
For detailed documentation and guides, visit:
import { EventStore } from "applesauce-core";
import { ThreadModel } from "applesauce-common/models";
import { getNip10References } from "applesauce-common/helpers/threading";
import { Relay } from "nostr-tools/relay";
// Create a single EventStore instance for your app
const eventStore = new EventStore();
// Use any nostr library for relay connections (nostr-tools, ndk, nostrify, etc...)
const relay = await Relay.connect("wss://relay.example.com");
// Subscribe to events and add them to the store
const sub = relay.subscribe([{ ids: ["event-id"] }], {
onevent(event) {
eventStore.add(event);
},
});
// Get NIP-10 thread references
const refs = getNip10References(event);
// Subscribe to a thread using ThreadModel
const thread = eventStore.model(ThreadModel, "event-id");
thread.subscribe((thread) => {
console.log(thread);
});
This package includes helpers, models, and operations for various NIPs including:
The package provides several export paths:
applesauce-common - Main exports (Helpers, Models, Operations, etc.)applesauce-common/helpers - All helper functionsapplesauce-common/helpers/* - Individual helper modulesapplesauce-common/models - All model functionsapplesauce-common/models/* - Individual model modulesapplesauce-common/operations - All operation functionsapplesauce-common/operations/* - Individual operation modulesapplesauce-common/blueprints - Event blueprintsapplesauce-common/casts - Type casting utilitiesapplesauce-common/observable - Observable utilities