Finish pass on docs

This commit is contained in:
Jon Staab
2025-06-10 15:48:00 -07:00
parent 1a81768e8e
commit ee6fa8b956
19 changed files with 545 additions and 435 deletions
+53 -1
View File
@@ -2,7 +2,7 @@
[![version](https://badgen.net/npm/v/@welshman/relay)](https://npmjs.com/package/@welshman/relay)
Core networking layer for nostr applications, handling relay connections, message management, and event delivery.
A few utilites for storing nostr events in memory.
## What's Included
@@ -12,6 +12,58 @@ Core networking layer for nostr applications, handling relay connections, messag
## Quick Example
```typescript
import {Repository, LocalRelay} from "@welshman/relay"
// Create an in-memory event repository
const repository = Repository.get()
// Publish events directly to the repository
const textNote = {
id: "event123",
pubkey: "author-pubkey",
created_at: Math.floor(Date.now() / 1000),
kind: 1,
tags: [],
content: "Hello, world!",
sig: "signature"
}
repository.publish(textNote)
// Query events using filters
const recentNotes = repository.query([{kinds: [1], limit: 10}])
console.log(`Found ${recentNotes.length} text notes`)
// Listen for repository updates
repository.on("update", ({added, removed}) => {
console.log(`Added ${added.length} events, removed ${removed.size} events`)
})
// Create a local relay that adapts Nostr messages to the repository
const relay = new LocalRelay(repository)
// Listen for relay messages
relay.on("EVENT", (subId, event) => {
console.log(`Received event ${event.id} for subscription ${subId}`)
})
relay.on("OK", (eventId, success, message) => {
console.log(`Event ${eventId} ${success ? "accepted" : "rejected"}: ${message}`)
})
// Use relay protocol to publish and subscribe
relay.send("EVENT", {
id: "event456",
pubkey: "another-author",
created_at: Math.floor(Date.now() / 1000),
kind: 1,
tags: [["t", "welshman"]],
content: "Using LocalRelay!",
sig: "signature"
})
// Subscribe to events with hashtag
relay.send("REQ", "tagged", {kinds: [1], "#t": ["welshman"]})
```
## Installation