From c6434028a6dd24b091184cac23f39d681ac01ca3 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Fri, 1 Aug 2025 14:32:57 -0700 Subject: [PATCH] Add docs for new stuff --- docs/.vitepress/config.mts | 2 + docs/app/commands.md | 76 ++++++++++++++++++++++++++ docs/app/user.md | 107 +++++++++++++++++++++++++++++++++++++ docs/net/policy.md | 9 ++++ docs/util/list.md | 6 +++ 5 files changed, 200 insertions(+) create mode 100644 docs/app/commands.md create mode 100644 docs/app/user.md diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 66bd238..6f25457 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -32,6 +32,8 @@ export default defineConfig({ {text: "Web of Trust", link: "/app/wot"}, {text: "Storage", link: "/app/storage"}, {text: "Context", link: "/app/context"}, + {text: "Commands", link: "/app/commands"}, + {text: "User", link: "/app/user"}, ], }, { diff --git a/docs/app/commands.md b/docs/app/commands.md new file mode 100644 index 0000000..ef19caf --- /dev/null +++ b/docs/app/commands.md @@ -0,0 +1,76 @@ +# Commands + +Commands are functions which pull from app state to publish events on behalf of the user. Most are async and return a thunk + +## Relay Management (NIP 65) + +```typescript +removeRelay(url: string, mode: RelayMode): Promise +addRelay(url: string, mode: RelayMode): Promise +``` + +## Inbox Relay Management (NIP 17) + +```typescript +removeInboxRelay(url: string): Promise +addInboxRelay(url: string): Promise +``` + +## Profile Management (NIP 01) + +```typescript +setProfile(profile: Profile): Thunk +``` + +## Follow Management (NIP 02) + +```typescript +unfollow(value: string): Promise +follow(tag: string[]): Promise +``` + +## Mute Management + +```typescript +unmute(value: string): Promise +mutePublicly(tag: string[]): Promise +mutePrivately(tag: string[]): Promise +setMutes(options: { + publicTags?: string[][] + privateTags?: string[][] +}): Promise +``` + +## Pin Management + +```typescript +unpin(value: string): Promise +pin(tag: string[]): Promise +``` + +## Wrapped Messages (NIP 59) + +```typescript +type SendWrappedOptions = Omit & { + template: EventTemplate + pubkeys: string[] +} + +sendWrapped(options: SendWrappedOptions): Promise +``` + +## Relay Management (NIP 86) + +```typescript +manageRelay(url: string, request: ManagementRequest): Promise +``` + +## Room Management (NIP 29) + +```typescript +createRoom(url: string, room: RoomMeta): Thunk +deleteRoom(url: string, room: RoomMeta): Thunk +editRoom(url: string, room: RoomMeta): Thunk +joinRoom(url: string, room: RoomMeta): Thunk +leaveRoom(url: string, room: RoomMeta): Thunk +``` diff --git a/docs/app/user.md b/docs/app/user.md new file mode 100644 index 0000000..4a26888 --- /dev/null +++ b/docs/app/user.md @@ -0,0 +1,107 @@ +# User Data Loading + +The User Data module provides utilities for loading and managing user-specific data like profiles, follows, mutes, pins, and relay selections. It includes both reactive stores and manual loading functions. + +## Types + +### UserDataLoader +```typescript +type UserDataLoader = (pubkey: string, relays?: string[], force?: boolean) => unknown +``` + +Function type for loading user data with optional relay specification and force refresh. + +### MakeUserDataOptions +```typescript +type MakeUserDataOptions = { + mapStore: Readable> + loadItem: UserDataLoader +} +``` + +Configuration for creating user data stores. + +## User Data Stores + +These reactive stores automatically load and cache user data: + +```typescript +// User profile +export const userProfile: Store + +// User follows list +export const userFollows: Store + +// User mutes list +export const userMutes: Store + +// User pins list +export const userPins: Store + +// User relay selections +export const userRelaySelections: Store + +// User inbox relay selections +export const userInboxRelaySelections: Store + +// User blossom servers +export const userBlossomServers: Store +``` + +## Manual Loading Functions + +These functions allow manual loading of user data with optional relay specification and force refresh: + +```typescript +// Load user profile +function loadUserProfile(relays?: string[], force?: boolean): Promise + +// Load user follows +function loadUserFollows(relays?: string[], force?: boolean): Promise + +// Load user mutes +function loadUserMutes(relays?: string[], force?: boolean): Promise + +// Load user pins +function loadUserPins(relays?: string[], force?: boolean): Promise + +// Load user relay selections +function loadUserRelaySelections(relays?: string[], force?: boolean): Promise + +// Load user inbox relay selections +function loadUserInboxRelaySelections(relays?: string[], force?: boolean): Promise + +// Load user blossom servers +function loadUserBlossomServers(relays?: string[], force?: boolean): Promise +``` + +## Usage Examples + +### Using Reactive Stores +```typescript +import { userProfile, userFollows } from '@welshman/app' + +// Subscribe to user profile changes +userProfile.subscribe(profile => { + if (profile) { + console.log('User profile:', profile) + } +}) + +// Get current follows list +const follows = userFollows.get() +``` + +### Manual Loading +```typescript +import { loadUserMutes, loadUserRelaySelections } from '@welshman/app' + +// Load user mutes from specific relays +await loadUserMutes(['wss://relay1.com', 'wss://relay2.com']) + +// Force refresh user relay selections +await loadUserRelaySelections([], true) + +// Load from default relays +await loadUserProfile() +``` diff --git a/docs/net/policy.md b/docs/net/policy.md index 988e95b..6c56650 100644 --- a/docs/net/policy.md +++ b/docs/net/policy.md @@ -2,6 +2,15 @@ Socket policies provide automated behavior for socket connections. They are intended to be applied on socket creation via `makeSocket` or `PoolOptions.makeSocket`. +## Types + +### SocketPolicy +```typescript +type SocketPolicy = (socket: Socket) => Unsubscriber +``` + +The contract for socket policies. Takes a Socket object and returns a cleanup function that should be called when the policy is no longer needed. + ## Built-in Policies ### `socketPolicyAuthBuffer` diff --git a/docs/util/list.md b/docs/util/list.md index db84ad5..35f5ad7 100644 --- a/docs/util/list.md +++ b/docs/util/list.md @@ -87,6 +87,12 @@ function addToListPrivately( list: List, ...tags: string[][] ): Encryptable + +// Update list with new tags +function updateList( + list: List, + options: {publicTags?: string[][], privateTags?: string[][]} +): Encryptable ``` ## Usage Examples