Update docs

This commit is contained in:
Jon Staab
2026-06-10 14:12:47 -07:00
parent a33af11b1b
commit dbd043f105
35 changed files with 164 additions and 179 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ The `netContext` global provides sensible defaults:
import {netContext} from '@welshman/net'
// Override event validation
netContext.isEventValid: (event, url) => {
netContext.isEventValid = (event, url) => {
return event.kind < 30000 && verifyEvent(event)
}
+4 -3
View File
@@ -5,6 +5,7 @@ Type definitions and utilities for Nostr protocol messages.
## Relay Message Types
**Enums:**
- `RelayMessageType.Notice` - Human-readable notice from relay
- `RelayMessageType.Auth` - Authentication challenge
- `RelayMessageType.Closed` - Subscription closed
- `RelayMessageType.Eose` - End of stored events
@@ -15,11 +16,11 @@ Type definitions and utilities for Nostr protocol messages.
**Type Definitions:**
- `RelayMessage` - Base relay message type
- `RelayAuth`, `RelayClosed`, `RelayEose`, `RelayEvent`, `RelayNegErr`, `RelayNegMsg`, `RelayOk` - Specific message types
- `RelayAuthPayload`, `RelayClosedPayload`, etc. - Payload types for each message
- `RelayNotice`, `RelayAuth`, `RelayClosed`, `RelayEose`, `RelayEvent`, `RelayNegErr`, `RelayNegMsg`, `RelayOk` - Specific message types
- `RelayNoticePayload`, `RelayAuthPayload`, `RelayClosedPayload`, etc. - Payload types for each message
**Type Guards:**
- `isRelayAuth()`, `isRelayClosed()`, `isRelayEose()`, `isRelayEvent()`, `isRelayNegErr()`, `isRelayNegMsg()`, `isRelayOk()`
- `isRelayNotice()`, `isRelayAuth()`, `isRelayClosed()`, `isRelayEose()`, `isRelayEvent()`, `isRelayNegErr()`, `isRelayNegMsg()`, `isRelayOk()`
## Client Message Types
+4
View File
@@ -13,6 +13,10 @@ The contract for socket policies. Takes a Socket object and returns a cleanup fu
## Built-in Policies
### `socketPolicyPing`
Sends a PING message every 30 seconds when the socket is open and has been idle (no send or receive activity in the last 30 seconds). Keeps connections alive through NAT/firewall idle timeouts.
### `socketPolicyAuthBuffer`
Buffers messages during authentication flow and replays them after successful auth.
+1 -6
View File
@@ -12,16 +12,11 @@ A connection pool that creates and manages Socket instances for different relay
- `static get()` - Returns the singleton pool instance
- `has(url)` - Checks if a socket exists for the given URL
- `get(url)` - Gets or creates a socket for the given URL
- `makeSocket(url)` - Creates a Socket for the given URL, using `PoolOptions.makeSocket` if provided, otherwise applies `defaultSocketPolicies`
- `subscribe(callback)` - Subscribes to new socket creation events
- `remove(url)` - Removes and cleans up a socket
- `clear()` - Removes all sockets from the pool
## Functions
### makeSocket(url, policies)
Creates a new Socket instance with the given URL and applies default policies.
## Example
```typescript
+5 -3
View File
@@ -16,7 +16,9 @@ Requests events from a single relay using the given filters. Returns a promise t
- `context?` - Adapter context
- `autoClose?` - Auto-close subscription after EOSE
- Validation functions: `isEventValid`, `isEventDeleted`
- Callback functions: `onEvent`, `onDeleted`, `onInvalid`, `onFiltered`, `onDuplicate`, `onDisconnect`, `onEose`, `onClose`
- Callback functions: `onEvent`, `onDeleted`, `onInvalid`, `onFiltered`, `onDuplicate`, `onDisconnect`, `onEose`, `onClosed`, `onClose`
- `onClosed?: (message: string, url: string) => void` - Called when the relay sends a CLOSED message, receiving the close reason and relay URL
- `onClose?: () => void` - Called when the subscription is fully closed
### request(options)
@@ -38,9 +40,9 @@ Creates a batched loader function that delays and combines requests for efficien
- `threshold?` - Relay completion threshold
- Validation functions and context options
### load(filters, relays, options)
### load(options)
Pre-configured loader with 200ms delay, 3s timeout, and 0.5 threshold.
Pre-configured loader with 200ms delay, 3s timeout, and 0.5 threshold. Takes a `LoadOptions` object containing `relays`, `filters`, and optional callback fields (`onEvent`, `onDisconnect`, `onEose`, `onClose`) and an optional `signal`.
## Example