BothDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sandwichfarm/nostr-watch/llms.txt
Use this file to discover all available pages before exploring further.
@nostrwatch/nocap and @nostrwatch/route66 use an adapter pattern to keep core orchestration logic separate from the concrete implementations that perform network I/O. In nocap, adapters supply the actual DNS, SSL, WebSocket, geo, and NIP-11 check logic. In route66, adapters supply local storage and WebSocket connectivity. You can swap any of these independently — replacing only the part relevant to your runtime, network topology, or service provider — without touching the rest of the stack.
nocap adapters
nocap separates check orchestration (timeouts, result aggregation, check ordering) from check execution (making DNS queries, opening sockets, fetching NIP-11 documents). All check execution lives in adapters. TheNocap class reads each adapter’s static type property to dispatch the right adapter for each requested check key.
AbstractAdapter base class
Every nocap adapter must extendAbstractAdapter:
base getter exposes the parent Nocap instance. Call this.base.finish(key, result) inside any check method to resolve that check — adapters do not return values from check methods directly.
IAdapter interface
All adapters must implementIAdapter:
Per-type interfaces
Each adapter type has its own interface specifying which check method(s) the adapter must implement. All check methods have the signature(): Promise<void> — they resolve the check by calling this.base.finish() rather than returning a value.
| Type | Interface | Required methods |
|---|---|---|
websocket | IWebsocketAdapter | check_open(), check_read(), check_write() |
dns | IDnsAdapter | check_dns() |
info | IInfoAdapter | check_info() |
ssl | ISslAdapter | check_ssl() |
geo | IGeoAdapter | check_geo() |
Custom DNS adapter example
The following is a complete, minimal DNS adapter taken from the nocap source:IResultData shape expected by base.finish():
Registering nocap adapters
Register adapters before callingcheck(). You can register one adapter at a time or pass an array or object:
useAdapter and useAdapters throw if an adapter of that type has already been registered. Each type slot can only hold one adapter at a time.Default adapters (reference implementations)
Five adapters ship with nocap inlibraries/nocap/adapters/default/. Use these as-is or as reference implementations when building custom adapters:
WebsocketAdapterDefault
Opens a WebSocket connection and performs open, read, and write checks. Uses
@nostrwatch/websocket for cross-platform socket support.DnsAdapterDefault
DNS lookup via Cloudflare DNS-over-HTTPS (1.1.1.1). Handles clearnet and IP-addressed relays.
SslAdapterDefault
TLS certificate validation using Node.js TLS APIs. Not available in browser environments.
GeoAdapterDefault
Geographic IP lookup. Depends on the DNS check result for the relay’s resolved IP.
InfoAdapterDefault
Fetches the NIP-11 relay information document from the relay’s HTTP endpoint.
route66 cache adapters
Cache adapters in route66 store NIP-66 relay check events locally and answer queries fromRelayService. They implement ICacheAdapter and extend the CacheAdapter base class.
CacheAdapter base class and ICacheAdapter interface
| Method | Description |
|---|---|
REQ(filters) | Execute a Nostr REQ query; return matching events |
COUNT(filters) | Return the count of matching events |
DELETE(filters) | Delete matching events; return deleted IDs |
DUMP() | Export the full store as a binary blob |
CLOSE(subId) | Close a subscription by ID |
WIPE() | Clear all stored events |
addEvent(event) | Insert a single event; no-op if already present |
addEvents(events) | Batch insert events |
putEvent(event) | Upsert a single event (insert or replace) |
Registering a cache adapter
Pass the adapter instance toRoute66 at construction time:
@nostrwatch/route66-cacheadapter-nostrsqlite — an SQLite-backed adapter using @nostrwatch/worker-relay in a web worker that works in both browser and Node.js.
route66 WebSocket adapters
WebSocket adapters in route66 open connections to Nostr monitoring relays and deliver incoming NIP-66 events to the rest of route66. They implementIWebsocketAdapter and extend the WebsocketAdapter base class.
Registration pattern
Like cache adapters, WebSocket adapters are provided at construction time:Reference implementation
The existing@nostrwatch/route66-wsadapter-nostrtools is the canonical reference for implementing a WebSocket adapter. It wraps nostr-tools and nostr-fetch to open pool connections and subscribe to NIP-66 event streams. Reference implementations for both adapter types are in libraries/route66/adapters/.