applesauce-core 4.1.0 → 4.2.0
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.
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { NostrEvent } from "nostr-tools";
|
|
1
|
+
import { kinds, NostrEvent } from "nostr-tools";
|
|
2
|
+
import { KnownEvent } from "./index.js";
|
|
3
|
+
/** Type for validated article events */
|
|
4
|
+
export type ArticleEvent = KnownEvent<kinds.LongFormArticle>;
|
|
2
5
|
/** Returns an articles title, if it exists */
|
|
6
|
+
export declare function getArticleTitle(article: ArticleEvent): string;
|
|
3
7
|
export declare function getArticleTitle(article: NostrEvent): string | undefined;
|
|
4
8
|
/** Returns an articles image, if it exists */
|
|
5
9
|
export declare function getArticleImage(article: NostrEvent): string | undefined;
|
|
@@ -7,3 +11,5 @@ export declare function getArticleImage(article: NostrEvent): string | undefined
|
|
|
7
11
|
export declare function getArticleSummary(article: NostrEvent): string | undefined;
|
|
8
12
|
/** Returns an articles published date, if it exists */
|
|
9
13
|
export declare function getArticlePublished(article: NostrEvent): number;
|
|
14
|
+
/** validates that an event is a valid article event */
|
|
15
|
+
export declare function isValidArticle(article: NostrEvent): article is ArticleEvent;
|
package/dist/helpers/article.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { kinds } from "nostr-tools";
|
|
1
2
|
import { getTagValue } from "./event-tags.js";
|
|
2
|
-
/** Returns an articles title, if it exists */
|
|
3
3
|
export function getArticleTitle(article) {
|
|
4
4
|
return getTagValue(article, "title");
|
|
5
5
|
}
|
|
@@ -19,3 +19,7 @@ export function getArticlePublished(article) {
|
|
|
19
19
|
else
|
|
20
20
|
return article.created_at;
|
|
21
21
|
}
|
|
22
|
+
/** validates that an event is a valid article event */
|
|
23
|
+
export function isValidArticle(article) {
|
|
24
|
+
return article.kind === kinds.LongFormArticle && getArticleTitle(article) !== undefined && article.content.length > 0;
|
|
25
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ProfilePointer } from "
|
|
1
|
+
import { ProfilePointer } from "./pointers.js";
|
|
2
|
+
import { Filter } from "./filter.js";
|
|
2
3
|
export type SelectOptimalRelaysOptions = {
|
|
3
4
|
/** Maximum number of connections (relays) to select */
|
|
4
5
|
maxConnections: number;
|
|
@@ -13,5 +14,11 @@ export declare function setFallbackRelays(users: ProfilePointer[], fallbacks: st
|
|
|
13
14
|
export declare function removeBlacklistedRelays(users: ProfilePointer[], blacklist: string[]): ProfilePointer[];
|
|
14
15
|
/** A map of pubkeys by relay */
|
|
15
16
|
export type OutboxMap = Record<string, ProfilePointer[]>;
|
|
16
|
-
/**
|
|
17
|
+
/** A map of filters by relay */
|
|
18
|
+
export type FilterMap = Record<string, Filter | Filter[]>;
|
|
19
|
+
/** Creates an {@link OutboxMap} for an array of profile points (groups users by relay) */
|
|
17
20
|
export declare function groupPubkeysByRelay(pointers: ProfilePointer[]): OutboxMap;
|
|
21
|
+
/** Alias for {@link groupPubkeysByRelay} */
|
|
22
|
+
export declare const createOutboxMap: typeof groupPubkeysByRelay;
|
|
23
|
+
/** Creates a {@link FilterMap} for an {@link OutboxMap} */
|
|
24
|
+
export declare function createFilterMap(outboxMap: OutboxMap, filter: Omit<Filter, "authors">): FilterMap;
|
|
@@ -86,7 +86,7 @@ export function removeBlacklistedRelays(users, blacklist) {
|
|
|
86
86
|
return { ...user, relays: user.relays.filter((relay) => !blacklist.includes(relay)) };
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
/**
|
|
89
|
+
/** Creates an {@link OutboxMap} for an array of profile points (groups users by relay) */
|
|
90
90
|
export function groupPubkeysByRelay(pointers) {
|
|
91
91
|
const outbox = {};
|
|
92
92
|
for (const pointer of pointers) {
|
|
@@ -100,3 +100,12 @@ export function groupPubkeysByRelay(pointers) {
|
|
|
100
100
|
}
|
|
101
101
|
return outbox;
|
|
102
102
|
}
|
|
103
|
+
/** Alias for {@link groupPubkeysByRelay} */
|
|
104
|
+
export const createOutboxMap = groupPubkeysByRelay;
|
|
105
|
+
/** Creates a {@link FilterMap} for an {@link OutboxMap} */
|
|
106
|
+
export function createFilterMap(outboxMap, filter) {
|
|
107
|
+
return Object.fromEntries(Array.from(Object.entries(outboxMap)).map(([relay, users]) => [
|
|
108
|
+
relay,
|
|
109
|
+
{ authors: users.map((user) => user.pubkey), ...filter },
|
|
110
|
+
]));
|
|
111
|
+
}
|
|
@@ -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
|
+
}
|