applesauce-core 0.0.0-next-20251020143053 → 0.0.0-next-20251030142514

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,3 +7,5 @@ export declare function includeMailboxes(store: IEventSubscriptions, type?: "inb
7
7
  export declare function ignoreBlacklistedRelays(blacklist: string[] | Observable<string[]>): MonoTypeOperatorFunction<ProfilePointer[]>;
8
8
  /** Sets fallback relays for any user that has 0 relays */
9
9
  export declare function includeFallbackRelays(fallbacks: string[] | Observable<string[]>): MonoTypeOperatorFunction<ProfilePointer[]>;
10
+ /** A operator calls {@link selectOptimalRelays} and filters the relays for the user */
11
+ export declare function filterOptimalRelays(maxConnections: number | Observable<number>, maxRelaysPerUser: number | Observable<number>): MonoTypeOperatorFunction<ProfilePointer[]>;
@@ -1,7 +1,7 @@
1
1
  import { combineLatest, combineLatestWith, isObservable, map, of, pipe, switchMap, } from "rxjs";
2
2
  import { getInboxes, getOutboxes } from "../helpers/mailboxes.js";
3
3
  import { addRelayHintsToPointer } from "../helpers/pointers.js";
4
- import { removeBlacklistedRelays, setFallbackRelays } from "../helpers/relay-selection.js";
4
+ import { removeBlacklistedRelays, selectOptimalRelays, setFallbackRelays } from "../helpers/relay-selection.js";
5
5
  /** RxJS operator that fetches outboxes for profile pointers from the event store */
6
6
  export function includeMailboxes(store, type = "outbox") {
7
7
  // Get the outboxes for all contacts
@@ -41,3 +41,11 @@ export function includeFallbackRelays(fallbacks) {
41
41
  // Set the fallback relays for the users
42
42
  map(([users, fallbacks]) => setFallbackRelays(users, fallbacks)));
43
43
  }
44
+ /** A operator calls {@link selectOptimalRelays} and filters the relays for the user */
45
+ export function filterOptimalRelays(maxConnections, maxRelaysPerUser) {
46
+ return pipe(
47
+ // Combine with the observable so it re-emits when the max connections and max relays per user change
48
+ combineLatestWith(isObservable(maxConnections) ? maxConnections : of(maxConnections), isObservable(maxRelaysPerUser) ? maxRelaysPerUser : of(maxRelaysPerUser)),
49
+ // Filter the relays for the user
50
+ map(([users, maxConnections, maxRelaysPerUser]) => selectOptimalRelays(users, { maxConnections, maxRelaysPerUser })));
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20251020143053",
3
+ "version": "0.0.0-next-20251030142514",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",