Add some router docs

This commit is contained in:
Jon Staab
2025-04-23 13:45:21 -07:00
parent 2996e25359
commit e2c950f751
2 changed files with 51 additions and 0 deletions
+3
View File
@@ -33,6 +33,9 @@ features:
- title: "@welshman/relay"
details: In-memory relay and event store.
link: "/relay"
- title: "@welshman/router"
details: Tools for relay selection.
link: "/router"
- title: "@welshman/content"
details: Parser and renderer for nostr notes with customizable formatting options.
link: "/content"
+48
View File
@@ -0,0 +1,48 @@
# @welshman/router
[![version](https://badgen.net/npm/v/@welshman/router)](https://npmjs.com/package/@welshman/router)
Utilities for selecting nostr relays.
## What's Included
- **Router** - A configurable router class usable as a singleton which provides common relay selection scenarios.
- **RouterScenario** - A scenario class which scores relays based on policy.
- **getFilterSelections** - A high-level utility for inferring relay selections from fitlers.
## Quick Example
```typescript
import {routerContext, addMaximalFallbacks, Router} from '@welshman/router'
// Configure the global router instance based on RouterOptions
Router.configure({
defaultRelays: ['wss://relay.example.com/'],
getPubkeyRelays: (pubkey, mode) => ['wss://myrelay.example.com/'],
})
// Get the singleton and use it to select some relays
const router = Router.get()
// Get a hint based on pubkey
router.FromPubkeys(pubkeys).getUrl()
// Send an event to the author's outbox and mentions' inboxes
router.PublishEvent(event).getUrls()
// Try as hard as we can to find a quoted note
router
.FromPubkeys(event, quotedEventId, hints)
.allowLocal(true)
.allowOnion(true)
.allowInsecure(true)
.policy(addMaximalFallbacks)
.limit(10)
.getUrls()
```
## Installation
```bash
npm install @welshman/router
```