Remove some methods from router, rename inbox_relays kind

This commit is contained in:
Jon Staab
2024-06-21 13:55:55 -07:00
parent fafbb345f1
commit e7967b72d5
6 changed files with 14 additions and 35 deletions
+4 -4
View File
@@ -3090,7 +3090,7 @@
"version": "0.0.12", "version": "0.0.12",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@welshman/util": "0.0.15" "@welshman/util": "0.0.16"
}, },
"devDependencies": { "devDependencies": {
"gts": "^5.0.1", "gts": "^5.0.1",
@@ -3124,11 +3124,11 @@
}, },
"packages/net": { "packages/net": {
"name": "@welshman/net", "name": "@welshman/net",
"version": "0.0.13", "version": "0.0.14",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@welshman/lib": "0.0.10", "@welshman/lib": "0.0.10",
"@welshman/util": "0.0.15", "@welshman/util": "0.0.16",
"isomorphic-ws": "^5.0.0", "isomorphic-ws": "^5.0.0",
"ws": "^8.16.0" "ws": "^8.16.0"
}, },
@@ -3140,7 +3140,7 @@
}, },
"packages/util": { "packages/util": {
"name": "@welshman/util", "name": "@welshman/util",
"version": "0.0.15", "version": "0.0.16",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@welshman/lib": "0.0.10", "@welshman/lib": "0.0.10",
+1 -1
View File
@@ -31,6 +31,6 @@
"typescript": "~5.1.6" "typescript": "~5.1.6"
}, },
"dependencies": { "dependencies": {
"@welshman/util": "0.0.15" "@welshman/util": "0.0.16"
} }
} }
+1 -1
View File
@@ -32,7 +32,7 @@
}, },
"dependencies": { "dependencies": {
"@welshman/lib": "0.0.10", "@welshman/lib": "0.0.10",
"@welshman/util": "0.0.15", "@welshman/util": "0.0.16",
"isomorphic-ws": "^5.0.0", "isomorphic-ws": "^5.0.0",
"ws": "^8.16.0" "ws": "^8.16.0"
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@welshman/util", "name": "@welshman/util",
"version": "0.0.15", "version": "0.0.16",
"author": "hodlbod", "author": "hodlbod",
"license": "MIT", "license": "MIT",
"description": "A collection of nostr-related utilities.", "description": "A collection of nostr-related utilities.",
+1 -1
View File
@@ -101,7 +101,7 @@ export const GROUPS = 10009
export const FEEDS = 10014 export const FEEDS = 10014
export const TOPICS = 10015 export const TOPICS = 10015
export const EMOJIS = 10030 export const EMOJIS = 10030
export const DM_INBOX_RELAYS = 10050 export const INBOX_RELAYS = 10050
export const FILE_SERVERS = 10096 export const FILE_SERVERS = 10096
export const LIGHTNING_PUB_RPC = 21000 export const LIGHTNING_PUB_RPC = 21000
export const CLIENT_AUTH = 22242 export const CLIENT_AUTH = 22242
+6 -27
View File
@@ -1,13 +1,13 @@
import {first, splitAt, identity, sortBy, uniq, shuffle, pushToMapKey} from '@welshman/lib' import {first, splitAt, identity, sortBy, uniq, shuffle, pushToMapKey} from '@welshman/lib'
import {Tags, Tag} from './Tags' import {Tags} from './Tags'
import type {TrustedEvent} from './Events' import type {TrustedEvent} from './Events'
import {isReplaceable} from './Events'
import {isShareableRelayUrl} from './Relay' import {isShareableRelayUrl} from './Relay'
import {getAddress, isCommunityAddress, isGroupAddress} from './Address' import {isCommunityAddress, isGroupAddress} from './Address'
export enum RelayMode { export enum RelayMode {
Read = "read", Read = "read",
Write = "write", Write = "write",
Inbox = "inbox"
} }
export type RouterOptions = { export type RouterOptions = {
@@ -34,7 +34,7 @@ export type RouterOptions = {
/** /**
* Retrieves relays for the specified public key and mode. * Retrieves relays for the specified public key and mode.
* @param pubkey - The public key to retrieve relays for. * @param pubkey - The public key to retrieve relays for.
* @param mode - The relay mode (optional). * @param mode - The relay mode (optional). May be "read", "write", or "inbox".
* @returns An array of relay URLs as strings. * @returns An array of relay URLs as strings.
*/ */
getPubkeyRelays?: (pubkey: string, mode?: RelayMode) => string[] getPubkeyRelays?: (pubkey: string, mode?: RelayMode) => string[]
@@ -168,8 +168,8 @@ export class Router {
PublishMessage = (pubkey: string) => PublishMessage = (pubkey: string) =>
this.scenario([ this.scenario([
...this.getUserSelections(RelayMode.Write), ...this.getUserSelections(RelayMode.Inbox),
this.getPubkeySelection(pubkey, RelayMode.Read), this.getPubkeySelection(pubkey, RelayMode.Inbox),
]).policy(this.addMinimalFallbacks) ]).policy(this.addMinimalFallbacks)
Event = (event: TrustedEvent) => Event = (event: TrustedEvent) =>
@@ -264,27 +264,6 @@ export class Router {
addMinimalFallbacks = (count: number, redundancy: number) => count > 0 ? 0 : 1 addMinimalFallbacks = (count: number, redundancy: number) => count > 0 ? 0 : 1
addMaximalFallbacks = (count: number, redundancy: number) => redundancy - count addMaximalFallbacks = (count: number, redundancy: number) => redundancy - count
// Higher level utils that use hints
tagPubkey = (pubkey: string) =>
Tag.from(["p", pubkey, this.FromPubkeys([pubkey]).getUrl()])
tagEventId = (event: TrustedEvent, mark = "") =>
Tag.from(["e", event.id, this.Event(event).getUrl(), mark, event.pubkey])
tagEventAddress = (event: TrustedEvent, mark = "") =>
Tag.from(["a", getAddress(event), this.Event(event).getUrl(), mark, event.pubkey])
tagEvent = (event: TrustedEvent, mark = "") => {
const tags = [this.tagEventId(event, mark)]
if (isReplaceable(event)) {
tags.push(this.tagEventAddress(event, mark))
}
return new Tags(tags)
}
} }
// Router Scenario // Router Scenario