applesauce-core 0.0.0-next-20250425210455 → 0.0.0-next-20250428164231

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,28 +1,56 @@
1
1
  import { AddressPointer, EventPointer, ProfilePointer } from "nostr-tools/nip19";
2
2
  import { NostrEvent } from "nostr-tools";
3
+ export declare const FAVORITE_RELAYS_KIND = 10012;
4
+ export type ReadListTags = "public" | "hidden" | "all";
5
+ /** Returns all the tags of a list or set */
6
+ export declare function getListTags(list: NostrEvent, type?: ReadListTags): string[][];
3
7
  /**
4
8
  * Checks if an event pointer is anywhere in a list or set
5
9
  * NOTE: Ignores the `relay` field in EventPointer
6
- * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
10
+ * @param list - The list or set to check
11
+ * @param pointer - The event pointer to check
12
+ * @param type - Which types of tags to check
7
13
  */
8
- export declare function isEventPointerInList(list: NostrEvent, pointer: string | EventPointer): boolean;
14
+ export declare function isEventPointerInList(list: NostrEvent, pointer: string | EventPointer, type?: ReadListTags): boolean;
9
15
  /**
10
16
  * Checks if an address pointer is anywhere in a list or set
11
17
  * NOTE: Ignores the `relay` field in AddressPointer
12
- * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
18
+ * @param list - The list or set to check
19
+ * @param pointer - The address pointer to check
20
+ * @param type - Which types of tags to check
13
21
  */
14
- export declare function isAddressPointerInList(list: NostrEvent, pointer: string | AddressPointer): boolean;
22
+ export declare function isAddressPointerInList(list: NostrEvent, pointer: string | AddressPointer, type?: ReadListTags): boolean;
15
23
  /**
16
24
  * Checks if an profile pointer is anywhere in a list or set
17
25
  * NOTE: Ignores the `relay` field in ProfilePointer
18
- * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
26
+ * @param list - The list or set to check
27
+ * @param pointer - The profile pointer to check
28
+ * @param type - Which types of tags to check
19
29
  */
20
- export declare function isProfilePointerInList(list: NostrEvent, pointer: string | ProfilePointer): boolean;
21
- /** Returns all the EventPointer in a list or set */
22
- export declare function getEventPointersFromList(list: NostrEvent): EventPointer[];
23
- /** Returns all the AddressPointer in a list or set */
24
- export declare function getAddressPointersFromList(list: NostrEvent): AddressPointer[];
25
- /** Returns all the ProfilePointer in a list or set */
26
- export declare function getProfilePointersFromList(list: NostrEvent): ProfilePointer[];
30
+ export declare function isProfilePointerInList(list: NostrEvent, pointer: string | ProfilePointer, type?: ReadListTags): boolean;
31
+ /**
32
+ * Returns all the EventPointer in a list or set
33
+ * @param list - The list or set to get the event pointers from
34
+ * @param type - Which types of tags to read
35
+ */
36
+ export declare function getEventPointersFromList(list: NostrEvent, type?: ReadListTags): EventPointer[];
37
+ /**
38
+ * Returns all the AddressPointer in a list or set
39
+ * @param list - The list or set to get the address pointers from
40
+ * @param type - Which types of tags to read
41
+ */
42
+ export declare function getAddressPointersFromList(list: NostrEvent, type?: ReadListTags): AddressPointer[];
43
+ /**
44
+ * Returns all the ProfilePointer in a list or set
45
+ * @param list - The list or set to get the profile pointers from
46
+ * @param type - Which types of tags to read
47
+ */
48
+ export declare function getProfilePointersFromList(list: NostrEvent, type?: ReadListTags): ProfilePointer[];
49
+ /**
50
+ * Returns a deduplicated array of all 'relay' tags in a list or set
51
+ * @param list - The list or set to get the relays from
52
+ * @param type - Which types of tags to read
53
+ */
54
+ export declare function getRelaysFromList(list: NostrEvent, type?: ReadListTags): string[];
27
55
  /** Returns if an event is a valid list or set */
28
56
  export declare function isValidList(event: NostrEvent): boolean;
@@ -3,48 +3,87 @@ import { getHiddenTags } from "./hidden-tags.js";
3
3
  import { getAddressPointerFromATag, getCoordinateFromAddressPointer, getEventPointerFromETag, getProfilePointerFromPTag, } from "./pointers.js";
4
4
  import { isATag, isETag, isPTag, processTags } from "./tags.js";
5
5
  import { getReplaceableIdentifier } from "./event.js";
6
- function listGetAllTags(list) {
7
- const hidden = getHiddenTags(list);
8
- return hidden ? [...hidden, ...list.tags] : list.tags;
6
+ import { mergeRelaySets } from "./relays.js";
7
+ export const FAVORITE_RELAYS_KIND = 10012;
8
+ /** Returns all the tags of a list or set */
9
+ export function getListTags(list, type) {
10
+ switch (type) {
11
+ case "public":
12
+ return list.tags;
13
+ case "hidden":
14
+ return getHiddenTags(list) ?? [];
15
+ default:
16
+ case "all":
17
+ return [...(getHiddenTags(list) ?? []), ...list.tags];
18
+ }
9
19
  }
10
20
  /**
11
21
  * Checks if an event pointer is anywhere in a list or set
12
22
  * NOTE: Ignores the `relay` field in EventPointer
13
- * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
23
+ * @param list - The list or set to check
24
+ * @param pointer - The event pointer to check
25
+ * @param type - Which types of tags to check
14
26
  */
15
- export function isEventPointerInList(list, pointer) {
27
+ export function isEventPointerInList(list, pointer, type) {
16
28
  const id = typeof pointer === "string" ? pointer : pointer.id;
17
- return listGetAllTags(list).some((t) => t[0] === "e" && t[1] === id);
29
+ const tags = getListTags(list, type);
30
+ return tags.some((t) => t[0] === "e" && t[1] === id);
18
31
  }
19
32
  /**
20
33
  * Checks if an address pointer is anywhere in a list or set
21
34
  * NOTE: Ignores the `relay` field in AddressPointer
22
- * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
35
+ * @param list - The list or set to check
36
+ * @param pointer - The address pointer to check
37
+ * @param type - Which types of tags to check
23
38
  */
24
- export function isAddressPointerInList(list, pointer) {
39
+ export function isAddressPointerInList(list, pointer, type) {
25
40
  const cord = typeof pointer === "string" ? pointer : getCoordinateFromAddressPointer(pointer);
26
- return listGetAllTags(list).some((t) => t[0] === "a" && t[1] === cord);
41
+ const tags = getListTags(list, type);
42
+ return tags.some((t) => t[0] === "a" && t[1] === cord);
27
43
  }
28
44
  /**
29
45
  * Checks if an profile pointer is anywhere in a list or set
30
46
  * NOTE: Ignores the `relay` field in ProfilePointer
31
- * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
47
+ * @param list - The list or set to check
48
+ * @param pointer - The profile pointer to check
49
+ * @param type - Which types of tags to check
32
50
  */
33
- export function isProfilePointerInList(list, pointer) {
51
+ export function isProfilePointerInList(list, pointer, type) {
34
52
  const pubkey = typeof pointer === "string" ? pointer : pointer.pubkey;
35
- return listGetAllTags(list).some((t) => t[0] === "p" && t[1] === pubkey);
53
+ const tags = getListTags(list, type);
54
+ return tags.some((t) => t[0] === "p" && t[1] === pubkey);
36
55
  }
37
- /** Returns all the EventPointer in a list or set */
38
- export function getEventPointersFromList(list) {
39
- return processTags(listGetAllTags(list), (tag) => (isETag(tag) ? tag : undefined), getEventPointerFromETag);
56
+ /**
57
+ * Returns all the EventPointer in a list or set
58
+ * @param list - The list or set to get the event pointers from
59
+ * @param type - Which types of tags to read
60
+ */
61
+ export function getEventPointersFromList(list, type) {
62
+ return processTags(getListTags(list, type), (tag) => (isETag(tag) ? tag : undefined), getEventPointerFromETag);
63
+ }
64
+ /**
65
+ * Returns all the AddressPointer in a list or set
66
+ * @param list - The list or set to get the address pointers from
67
+ * @param type - Which types of tags to read
68
+ */
69
+ export function getAddressPointersFromList(list, type) {
70
+ return processTags(getListTags(list, type), (t) => (isATag(t) ? t : undefined), getAddressPointerFromATag);
40
71
  }
41
- /** Returns all the AddressPointer in a list or set */
42
- export function getAddressPointersFromList(list) {
43
- return processTags(listGetAllTags(list), (t) => (isATag(t) ? t : undefined), getAddressPointerFromATag);
72
+ /**
73
+ * Returns all the ProfilePointer in a list or set
74
+ * @param list - The list or set to get the profile pointers from
75
+ * @param type - Which types of tags to read
76
+ */
77
+ export function getProfilePointersFromList(list, type) {
78
+ return processTags(getListTags(list, type), (t) => (isPTag(t) ? t : undefined), getProfilePointerFromPTag);
44
79
  }
45
- /** Returns all the ProfilePointer in a list or set */
46
- export function getProfilePointersFromList(list) {
47
- return processTags(listGetAllTags(list), (t) => (isPTag(t) ? t : undefined), getProfilePointerFromPTag);
80
+ /**
81
+ * Returns a deduplicated array of all 'relay' tags in a list or set
82
+ * @param list - The list or set to get the relays from
83
+ * @param type - Which types of tags to read
84
+ */
85
+ export function getRelaysFromList(list, type) {
86
+ return mergeRelaySets(processTags(getListTags(list, type), (t) => (t[0] === "relay" ? t[1] : undefined)));
48
87
  }
49
88
  /** Returns if an event is a valid list or set */
50
89
  export function isValidList(event) {
@@ -3,6 +3,7 @@ export * from "./bookmarks.js";
3
3
  export * from "./channels.js";
4
4
  export * from "./comments.js";
5
5
  export * from "./contacts.js";
6
+ export * from "./relays.js";
6
7
  export * from "./mailboxes.js";
7
8
  export * from "./mutes.js";
8
9
  export * from "./pins.js";
@@ -3,6 +3,7 @@ export * from "./bookmarks.js";
3
3
  export * from "./channels.js";
4
4
  export * from "./comments.js";
5
5
  export * from "./contacts.js";
6
+ export * from "./relays.js";
6
7
  export * from "./mailboxes.js";
7
8
  export * from "./mutes.js";
8
9
  export * from "./pins.js";
@@ -0,0 +1,14 @@
1
+ import { AddressPointer } from "nostr-tools/nip19";
2
+ import { Query } from "../query-store/query-store.js";
3
+ /**
4
+ * A query that returns all favorite relays for a pubkey
5
+ * @param pubkey - The pubkey to get the favorite relays for
6
+ * @param hidden - Whether to read hidden tags instead of public tags
7
+ */
8
+ export declare function FavoriteRelays(pubkey: string, hidden?: boolean): Query<string[] | undefined>;
9
+ /**
10
+ * A query that returns all favorite relay sets for a pubkey
11
+ * @param pubkey - The pubkey to get the favorite relay sets for
12
+ * @param hidden - Whether to read hidden tags instead of public tags
13
+ */
14
+ export declare function FavoriteRelaySets(pubkey: string, hidden?: boolean): Query<AddressPointer[] | undefined>;
@@ -0,0 +1,24 @@
1
+ import { map } from "rxjs";
2
+ import { FAVORITE_RELAYS_KIND, getAddressPointersFromList, getRelaysFromList } from "../helpers/lists.js";
3
+ /**
4
+ * A query that returns all favorite relays for a pubkey
5
+ * @param pubkey - The pubkey to get the favorite relays for
6
+ * @param hidden - Whether to read hidden tags instead of public tags
7
+ */
8
+ export function FavoriteRelays(pubkey, hidden = false) {
9
+ return (events) => {
10
+ return events.replaceable(FAVORITE_RELAYS_KIND, pubkey).pipe(map((e) => e && getRelaysFromList(e, hidden)));
11
+ };
12
+ }
13
+ /**
14
+ * A query that returns all favorite relay sets for a pubkey
15
+ * @param pubkey - The pubkey to get the favorite relay sets for
16
+ * @param hidden - Whether to read hidden tags instead of public tags
17
+ */
18
+ export function FavoriteRelaySets(pubkey, hidden = false) {
19
+ return (events) => {
20
+ return events
21
+ .replaceable(FAVORITE_RELAYS_KIND, pubkey)
22
+ .pipe(map((e) => e && getAddressPointersFromList(e, hidden)));
23
+ };
24
+ }
@@ -0,0 +1,27 @@
1
+ import { AddressPointer } from "nostr-tools/nip19";
2
+ import { ReadListTags } from "../helpers/lists.js";
3
+ import { Query } from "../query-store/query-store.js";
4
+ /**
5
+ * A query that returns all favorite relays for a pubkey
6
+ * @param pubkey - The pubkey to get the favorite relays for
7
+ * @param type - Which types of tags to read
8
+ */
9
+ export declare function FavoriteRelays(pubkey: string, type?: ReadListTags): Query<string[] | undefined>;
10
+ /**
11
+ * A query that returns all favorite relay sets for a pubkey
12
+ * @param pubkey - The pubkey to get the favorite relay sets for
13
+ * @param type - Which types of tags to read
14
+ */
15
+ export declare function FavoriteRelaySets(pubkey: string, type?: ReadListTags): Query<AddressPointer[] | undefined>;
16
+ /**
17
+ * A query that returns all search relays for a pubkey
18
+ * @param pubkey - The pubkey to get the search relays for
19
+ * @param type - Which types of tags to read
20
+ */
21
+ export declare function SearchRelays(pubkey: string, type?: ReadListTags): Query<string[] | undefined>;
22
+ /**
23
+ * A query that returns all blocked relays for a pubkey
24
+ * @param pubkey - The pubkey to get the blocked relays for
25
+ * @param type - Which types of tags to read
26
+ */
27
+ export declare function BlockedRelays(pubkey: string, type?: ReadListTags): Query<string[] | undefined>;
@@ -0,0 +1,44 @@
1
+ import { kinds } from "nostr-tools";
2
+ import { identity, map } from "rxjs";
3
+ import { FAVORITE_RELAYS_KIND, getAddressPointersFromList, getRelaysFromList } from "../helpers/lists.js";
4
+ import { listenLatestUpdates } from "../observable/listen-latest-updates.js";
5
+ /**
6
+ * A query that returns all favorite relays for a pubkey
7
+ * @param pubkey - The pubkey to get the favorite relays for
8
+ * @param type - Which types of tags to read
9
+ */
10
+ export function FavoriteRelays(pubkey, type) {
11
+ return (events) => {
12
+ return events.replaceable(FAVORITE_RELAYS_KIND, pubkey).pipe(type !== "public" ? listenLatestUpdates(events) : map(identity), map((e) => e && getRelaysFromList(e, type)));
13
+ };
14
+ }
15
+ /**
16
+ * A query that returns all favorite relay sets for a pubkey
17
+ * @param pubkey - The pubkey to get the favorite relay sets for
18
+ * @param type - Which types of tags to read
19
+ */
20
+ export function FavoriteRelaySets(pubkey, type) {
21
+ return (events) => {
22
+ return events.replaceable(FAVORITE_RELAYS_KIND, pubkey).pipe(type !== "public" ? listenLatestUpdates(events) : map(identity), map((e) => e && getAddressPointersFromList(e, type)));
23
+ };
24
+ }
25
+ /**
26
+ * A query that returns all search relays for a pubkey
27
+ * @param pubkey - The pubkey to get the search relays for
28
+ * @param type - Which types of tags to read
29
+ */
30
+ export function SearchRelays(pubkey, type) {
31
+ return (events) => {
32
+ return events.replaceable(kinds.SearchRelaysList, pubkey).pipe(type !== "public" ? listenLatestUpdates(events) : map(identity), map((e) => e && getRelaysFromList(e, type)));
33
+ };
34
+ }
35
+ /**
36
+ * A query that returns all blocked relays for a pubkey
37
+ * @param pubkey - The pubkey to get the blocked relays for
38
+ * @param type - Which types of tags to read
39
+ */
40
+ export function BlockedRelays(pubkey, type) {
41
+ return (events) => {
42
+ return events.replaceable(kinds.BlockedRelaysList, pubkey).pipe(type !== "public" ? listenLatestUpdates(events) : map(identity), map((e) => e && getRelaysFromList(e, type)));
43
+ };
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20250425210455",
3
+ "version": "0.0.0-next-20250428164231",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",