applesauce-core 0.12.1 → 1.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.
Files changed (81) hide show
  1. package/README.md +28 -10
  2. package/dist/__tests__/exports.test.d.ts +1 -0
  3. package/dist/__tests__/exports.test.js +17 -0
  4. package/dist/event-store/__tests__/event-store.test.js +52 -1
  5. package/dist/event-store/database.js +3 -3
  6. package/dist/event-store/event-store.js +15 -8
  7. package/dist/event-store/interface.d.ts +11 -7
  8. package/dist/helpers/__tests__/bookmarks.test.d.ts +1 -0
  9. package/dist/helpers/__tests__/bookmarks.test.js +88 -0
  10. package/dist/helpers/__tests__/comment.test.js +14 -0
  11. package/dist/helpers/__tests__/contacts.test.d.ts +1 -0
  12. package/dist/helpers/__tests__/contacts.test.js +34 -0
  13. package/dist/helpers/__tests__/events.test.d.ts +1 -0
  14. package/dist/helpers/__tests__/events.test.js +32 -0
  15. package/dist/helpers/__tests__/exports.test.d.ts +1 -0
  16. package/dist/helpers/__tests__/exports.test.js +220 -0
  17. package/dist/helpers/__tests__/mutes.test.d.ts +1 -0
  18. package/dist/helpers/__tests__/mutes.test.js +55 -0
  19. package/dist/helpers/blossom.d.ts +2 -0
  20. package/dist/helpers/blossom.js +18 -0
  21. package/dist/helpers/bookmarks.d.ts +6 -1
  22. package/dist/helpers/bookmarks.js +52 -7
  23. package/dist/helpers/comment.d.ts +7 -3
  24. package/dist/helpers/comment.js +6 -1
  25. package/dist/helpers/contacts.d.ts +11 -0
  26. package/dist/helpers/contacts.js +34 -0
  27. package/dist/helpers/event.d.ts +8 -3
  28. package/dist/helpers/event.js +21 -13
  29. package/dist/helpers/lists.d.ts +40 -12
  30. package/dist/helpers/lists.js +62 -23
  31. package/dist/helpers/mutes.d.ts +8 -0
  32. package/dist/helpers/mutes.js +66 -5
  33. package/dist/helpers/nip-19.d.ts +14 -0
  34. package/dist/helpers/nip-19.js +29 -0
  35. package/dist/helpers/pointers.js +6 -6
  36. package/dist/helpers/profile.js +1 -1
  37. package/dist/observable/__tests__/exports.test.d.ts +1 -0
  38. package/dist/observable/__tests__/exports.test.js +18 -0
  39. package/dist/observable/__tests__/listen-latest-updates.test.d.ts +1 -0
  40. package/dist/observable/__tests__/listen-latest-updates.test.js +55 -0
  41. package/dist/observable/defined.d.ts +3 -0
  42. package/dist/observable/defined.js +5 -0
  43. package/dist/observable/get-observable-value.d.ts +4 -1
  44. package/dist/observable/get-observable-value.js +4 -1
  45. package/dist/observable/index.d.ts +5 -1
  46. package/dist/observable/index.js +6 -1
  47. package/dist/observable/listen-latest-updates.d.ts +5 -0
  48. package/dist/observable/listen-latest-updates.js +12 -0
  49. package/dist/promise/__tests__/exports.test.d.ts +1 -0
  50. package/dist/promise/__tests__/exports.test.js +11 -0
  51. package/dist/queries/__tests__/exports.test.d.ts +1 -0
  52. package/dist/queries/__tests__/exports.test.js +41 -0
  53. package/dist/queries/blossom.js +1 -6
  54. package/dist/queries/bookmarks.d.ts +5 -5
  55. package/dist/queries/bookmarks.js +18 -17
  56. package/dist/queries/channels.js +41 -53
  57. package/dist/queries/comments.js +6 -9
  58. package/dist/queries/contacts.d.ts +6 -1
  59. package/dist/queries/contacts.js +21 -9
  60. package/dist/queries/index.d.ts +1 -0
  61. package/dist/queries/index.js +1 -0
  62. package/dist/queries/mailboxes.js +4 -7
  63. package/dist/queries/mutes.d.ts +6 -6
  64. package/dist/queries/mutes.js +20 -19
  65. package/dist/queries/pins.d.ts +1 -0
  66. package/dist/queries/pins.js +4 -6
  67. package/dist/queries/profile.js +1 -6
  68. package/dist/queries/reactions.js +11 -14
  69. package/dist/queries/relays.d.ts +27 -0
  70. package/dist/queries/relays.js +44 -0
  71. package/dist/queries/simple.js +5 -22
  72. package/dist/queries/thread.js +45 -51
  73. package/dist/queries/user-status.js +23 -29
  74. package/dist/queries/zaps.js +10 -13
  75. package/dist/query-store/__tests__/exports.test.d.ts +1 -0
  76. package/dist/query-store/__tests__/exports.test.js +12 -0
  77. package/dist/query-store/query-store.d.ts +7 -6
  78. package/dist/query-store/query-store.js +13 -8
  79. package/package.json +3 -3
  80. package/dist/observable/share-latest-value.d.ts +0 -6
  81. package/dist/observable/share-latest-value.js +0 -24
@@ -1,8 +1,8 @@
1
1
  import { Bookmarks } from "../helpers/bookmarks.js";
2
2
  import { Query } from "../query-store/index.js";
3
+ /** A query that returns all the bookmarks of a user */
3
4
  export declare function UserBookmarkQuery(pubkey: string): Query<Bookmarks | undefined>;
4
- export declare function UserHiddenBookmarkQuery(pubkey: string): Query<(Bookmarks & {
5
- locked: false;
6
- }) | {
7
- locked: true;
8
- } | undefined>;
5
+ /** A query that returns all the public bookmarks of a user */
6
+ export declare function UserPublicBookmarkQuery(pubkey: string): Query<Bookmarks | undefined>;
7
+ /** A query that returns all the hidden bookmarks of a user */
8
+ export declare function UserHiddenBookmarkQuery(pubkey: string): Query<Bookmarks | null | undefined>;
@@ -1,23 +1,24 @@
1
1
  import { kinds } from "nostr-tools";
2
2
  import { map } from "rxjs/operators";
3
- import { isHiddenTagsLocked } from "../helpers/index.js";
4
- import { getBookmarks, getHiddenBookmarks } from "../helpers/bookmarks.js";
3
+ import { getBookmarks, getHiddenBookmarks, getPublicBookmarks } from "../helpers/bookmarks.js";
4
+ import { listenLatestUpdates } from "../observable/index.js";
5
+ /** A query that returns all the bookmarks of a user */
5
6
  export function UserBookmarkQuery(pubkey) {
6
- return {
7
- key: pubkey,
8
- run: (store) => store.replaceable(kinds.Mutelist, pubkey).pipe(map((event) => event && getBookmarks(event))),
9
- };
7
+ return (events) => events.replaceable(kinds.Mutelist, pubkey).pipe(
8
+ // listen for event updates (hidden tags unlocked)
9
+ listenLatestUpdates(events),
10
+ // Get all bookmarks
11
+ map((event) => event && getBookmarks(event)));
10
12
  }
13
+ /** A query that returns all the public bookmarks of a user */
14
+ export function UserPublicBookmarkQuery(pubkey) {
15
+ return (events) => events.replaceable(kinds.Mutelist, pubkey).pipe(map((event) => event && getPublicBookmarks(event)));
16
+ }
17
+ /** A query that returns all the hidden bookmarks of a user */
11
18
  export function UserHiddenBookmarkQuery(pubkey) {
12
- return {
13
- key: pubkey,
14
- run: (store) => store.replaceable(kinds.Mutelist, pubkey).pipe(map((event) => {
15
- if (!event)
16
- return undefined;
17
- const bookmarks = getHiddenBookmarks(event);
18
- if (isHiddenTagsLocked(event) || !bookmarks)
19
- return { locked: true };
20
- return { locked: false, ...bookmarks };
21
- })),
22
- };
19
+ return (events) => events.replaceable(kinds.Mutelist, pubkey).pipe(
20
+ // listen for event updates (hidden tags unlocked)
21
+ listenLatestUpdates(events),
22
+ // Get hidden bookmarks
23
+ map((event) => event && (getHiddenBookmarks(event) ?? null)));
23
24
  }
@@ -4,70 +4,58 @@ import { map } from "rxjs";
4
4
  import { getChannelMetadataContent } from "../helpers/channels.js";
5
5
  /** A query that returns a map of hidden messages Map<id, reason> */
6
6
  export function ChannelHiddenQuery(channel, authors = []) {
7
- return {
8
- key: channel.id,
9
- run: (events) => {
10
- const hidden = new Map();
11
- return events
12
- .filters([{ kinds: [kinds.ChannelHideMessage], "#e": [channel.id], authors: [channel.pubkey, ...authors] }])
13
- .pipe(map((event) => {
14
- const reason = safeParse(event.content)?.reason;
15
- for (const tag of event.tags) {
16
- if (tag[0] === "e" && tag[1])
17
- hidden.set(tag[1], reason ?? "");
18
- }
19
- return hidden;
20
- }));
21
- },
7
+ return (events) => {
8
+ const hidden = new Map();
9
+ return events
10
+ .filters([{ kinds: [kinds.ChannelHideMessage], "#e": [channel.id], authors: [channel.pubkey, ...authors] }])
11
+ .pipe(map((event) => {
12
+ const reason = safeParse(event.content)?.reason;
13
+ for (const tag of event.tags) {
14
+ if (tag[0] === "e" && tag[1])
15
+ hidden.set(tag[1], reason ?? "");
16
+ }
17
+ return hidden;
18
+ }));
22
19
  };
23
20
  }
24
21
  /** A query that returns all messages in a channel */
25
22
  export function ChannelMessagesQuery(channel) {
26
- return {
27
- key: channel.id,
28
- run: (events) => events.timeline([{ kinds: [kinds.ChannelMessage], "#e": [channel.id] }]),
29
- };
23
+ return (events) => events.timeline([{ kinds: [kinds.ChannelMessage], "#e": [channel.id] }]);
30
24
  }
31
25
  /** A query that returns the latest parsed metadata */
32
26
  export function ChannelMetadataQuery(channel) {
33
- return {
34
- key: channel.id,
35
- run: (events) => {
36
- const filters = [
37
- { ids: [channel.id] },
38
- { kinds: [kinds.ChannelMetadata], "#e": [channel.id], authors: [channel.pubkey] },
39
- ];
40
- let latest = channel;
41
- return events.filters(filters).pipe(map((event) => {
42
- try {
43
- if (event.pubkey === latest.pubkey && event.created_at > latest.created_at) {
44
- latest = event;
45
- }
46
- return getChannelMetadataContent(latest);
27
+ return (events) => {
28
+ const filters = [
29
+ { ids: [channel.id] },
30
+ { kinds: [kinds.ChannelMetadata], "#e": [channel.id], authors: [channel.pubkey] },
31
+ ];
32
+ let latest = channel;
33
+ return events.filters(filters).pipe(map((event) => {
34
+ try {
35
+ if (event.pubkey === latest.pubkey && event.created_at > latest.created_at) {
36
+ latest = event;
47
37
  }
48
- catch (error) {
49
- return undefined;
50
- }
51
- }));
52
- },
38
+ return getChannelMetadataContent(latest);
39
+ }
40
+ catch (error) {
41
+ return undefined;
42
+ }
43
+ }));
53
44
  };
54
45
  }
55
46
  /** A query that returns a map of muted users Map<pubkey, reason> */
56
47
  export function ChannelMutedQuery(channel, authors = []) {
57
- return {
58
- key: channel.id + authors.join(","),
59
- run: (events) => {
60
- const muted = new Map();
61
- return events
62
- .filters([{ kinds: [kinds.ChannelMuteUser], "#e": [channel.id], authors: [channel.pubkey, ...authors] }])
63
- .pipe(map((event) => {
64
- const reason = safeParse(event.content)?.reason;
65
- for (const tag of event.tags) {
66
- if (tag[0] === "p" && tag[1])
67
- muted.set(tag[1], reason ?? "");
68
- }
69
- return muted;
70
- }));
71
- },
48
+ return (events) => {
49
+ const muted = new Map();
50
+ return events
51
+ .filters([{ kinds: [kinds.ChannelMuteUser], "#e": [channel.id], authors: [channel.pubkey, ...authors] }])
52
+ .pipe(map((event) => {
53
+ const reason = safeParse(event.content)?.reason;
54
+ for (const tag of event.tags) {
55
+ if (tag[0] === "p" && tag[1])
56
+ muted.set(tag[1], reason ?? "");
57
+ }
58
+ return muted;
59
+ }));
72
60
  };
73
61
  }
@@ -1,14 +1,11 @@
1
1
  import { COMMENT_KIND, getEventUID } from "../helpers/index.js";
2
- import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
2
+ import { isAddressableKind } from "nostr-tools/kinds";
3
3
  /** Returns all NIP-22 comment replies for the event */
4
4
  export function CommentsQuery(parent) {
5
- return {
6
- key: `${getEventUID(parent)}-comments`,
7
- run: (events) => {
8
- const filter = { kinds: [COMMENT_KIND], "#e": [parent.id] };
9
- if (isParameterizedReplaceableKind(parent.kind))
10
- filter["#a"] = [getEventUID(parent)];
11
- return events.timeline(filter);
12
- },
5
+ return (events) => {
6
+ const filter = { kinds: [COMMENT_KIND], "#e": [parent.id] };
7
+ if (isAddressableKind(parent.kind))
8
+ filter["#a"] = [getEventUID(parent)];
9
+ return events.timeline(filter);
13
10
  };
14
11
  }
@@ -1,3 +1,8 @@
1
1
  import { ProfilePointer } from "nostr-tools/nip19";
2
2
  import { Query } from "../query-store/index.js";
3
- export declare function UserContactsQuery(pubkey: string): Query<ProfilePointer[] | undefined>;
3
+ /** A query that returns all contacts for a user */
4
+ export declare function ContactsQuery(pubkey: string): Query<ProfilePointer[] | undefined>;
5
+ /** A query that returns all public contacts for a user */
6
+ export declare function PublicContactsQuery(pubkey: string): Query<ProfilePointer[] | undefined>;
7
+ /** A query that returns all hidden contacts for a user */
8
+ export declare function HiddenContactsQuery(pubkey: string): Query<ProfilePointer[] | null | undefined>;
@@ -1,12 +1,24 @@
1
1
  import { kinds } from "nostr-tools";
2
2
  import { map } from "rxjs/operators";
3
- import { isPTag, processTags } from "../helpers/tags.js";
4
- import { getProfilePointerFromPTag } from "../helpers/pointers.js";
5
- export function UserContactsQuery(pubkey) {
6
- return {
7
- key: pubkey,
8
- run: (store) => store
9
- .replaceable(kinds.Contacts, pubkey)
10
- .pipe(map((event) => event && processTags(event.tags.filter(isPTag), getProfilePointerFromPTag))),
11
- };
3
+ import { getContacts, getHiddenContacts, getPublicContacts } from "../helpers/contacts.js";
4
+ import { listenLatestUpdates } from "../observable/index.js";
5
+ /** A query that returns all contacts for a user */
6
+ export function ContactsQuery(pubkey) {
7
+ return (events) => events.replaceable(kinds.Contacts, pubkey).pipe(
8
+ // listen for event updates (hidden tags unlocked)
9
+ listenLatestUpdates(events),
10
+ // Get all contacts
11
+ map((e) => e && getContacts(e)));
12
+ }
13
+ /** A query that returns all public contacts for a user */
14
+ export function PublicContactsQuery(pubkey) {
15
+ return (events) => events.replaceable(kinds.Contacts, pubkey).pipe(map((e) => e && getPublicContacts(e)));
16
+ }
17
+ /** A query that returns all hidden contacts for a user */
18
+ export function HiddenContactsQuery(pubkey) {
19
+ return (events) => events.replaceable(kinds.Contacts, pubkey).pipe(
20
+ // listen for event updates (hidden tags unlocked)
21
+ listenLatestUpdates(events),
22
+ // Get hidden contacts
23
+ map((e) => e && (getHiddenContacts(e) ?? null)));
12
24
  }
@@ -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";
@@ -3,11 +3,8 @@ import { map } from "rxjs/operators";
3
3
  import { getInboxes, getOutboxes } from "../helpers/mailboxes.js";
4
4
  /** A query that gets and parses the inbox and outbox relays for a pubkey */
5
5
  export function MailboxesQuery(pubkey) {
6
- return {
7
- key: pubkey,
8
- run: (events) => events.replaceable(kinds.RelayList, pubkey).pipe(map((event) => event && {
9
- inboxes: getInboxes(event),
10
- outboxes: getOutboxes(event),
11
- })),
12
- };
6
+ return (events) => events.replaceable(kinds.RelayList, pubkey).pipe(map((event) => event && {
7
+ inboxes: getInboxes(event),
8
+ outboxes: getOutboxes(event),
9
+ }));
13
10
  }
@@ -1,8 +1,8 @@
1
1
  import { Mutes } from "../helpers/mutes.js";
2
2
  import { Query } from "../query-store/index.js";
3
- export declare function UserMuteQuery(pubkey: string): Query<Mutes | undefined>;
4
- export declare function UserHiddenMuteQuery(pubkey: string): Query<(Mutes & {
5
- locked: false;
6
- }) | {
7
- locked: true;
8
- } | undefined>;
3
+ /** A query that returns all a users muted things */
4
+ export declare function MuteQuery(pubkey: string): Query<Mutes | undefined>;
5
+ /** A query that returns all a users public muted things */
6
+ export declare function PublicMuteQuery(pubkey: string): Query<Mutes | undefined>;
7
+ /** A query that returns all a users hidden muted things */
8
+ export declare function HiddenMuteQuery(pubkey: string): Query<Mutes | null | undefined>;
@@ -1,23 +1,24 @@
1
1
  import { kinds } from "nostr-tools";
2
2
  import { map } from "rxjs/operators";
3
- import { getHiddenMutedThings, getMutedThings } from "../helpers/mutes.js";
4
- import { isHiddenTagsLocked } from "../helpers/hidden-tags.js";
5
- export function UserMuteQuery(pubkey) {
6
- return {
7
- key: pubkey,
8
- run: (event) => event.replaceable(kinds.Mutelist, pubkey).pipe(map((event) => event && getMutedThings(event))),
9
- };
3
+ import { getHiddenMutedThings, getMutedThings, getPublicMutedThings } from "../helpers/mutes.js";
4
+ import { listenLatestUpdates } from "../observable/listen-latest-updates.js";
5
+ /** A query that returns all a users muted things */
6
+ export function MuteQuery(pubkey) {
7
+ return (events) => events.replaceable(kinds.Mutelist, pubkey).pipe(
8
+ // listen for event updates (hidden tags unlocked)
9
+ listenLatestUpdates(events),
10
+ // Get all muted things
11
+ map((event) => event && getMutedThings(event)));
10
12
  }
11
- export function UserHiddenMuteQuery(pubkey) {
12
- return {
13
- key: pubkey,
14
- run: (store) => store.replaceable(kinds.Mutelist, pubkey).pipe(map((event) => {
15
- if (!event)
16
- return undefined;
17
- const muted = getHiddenMutedThings(event);
18
- if (isHiddenTagsLocked(event) || !muted)
19
- return { locked: true };
20
- return { locked: false, ...muted };
21
- })),
22
- };
13
+ /** A query that returns all a users public muted things */
14
+ export function PublicMuteQuery(pubkey) {
15
+ return (events) => events.replaceable(kinds.Mutelist, pubkey).pipe(map((event) => event && getPublicMutedThings(event)));
16
+ }
17
+ /** A query that returns all a users hidden muted things */
18
+ export function HiddenMuteQuery(pubkey) {
19
+ return (events) => events.replaceable(kinds.Mutelist, pubkey).pipe(
20
+ // listen for event updates (hidden tags unlocked)
21
+ listenLatestUpdates(events),
22
+ // Get hidden muted things
23
+ map((event) => event && getHiddenMutedThings(event)));
23
24
  }
@@ -1,3 +1,4 @@
1
1
  import { Query } from "applesauce-core";
2
2
  import { EventPointer } from "nostr-tools/nip19";
3
+ /** A query that returns all pinned pointers for a user */
3
4
  export declare function UserPinnedQuery(pubkey: string): Query<EventPointer[] | undefined>;
@@ -2,11 +2,9 @@ import { kinds } from "nostr-tools";
2
2
  import { map } from "rxjs/operators";
3
3
  import { isETag, processTags } from "../helpers/tags.js";
4
4
  import { getEventPointerFromETag } from "../helpers/pointers.js";
5
+ /** A query that returns all pinned pointers for a user */
5
6
  export function UserPinnedQuery(pubkey) {
6
- return {
7
- key: pubkey,
8
- run: (store) => store
9
- .replaceable(kinds.Pinlist, pubkey)
10
- .pipe(map((event) => event && processTags(event.tags.filter(isETag), getEventPointerFromETag))),
11
- };
7
+ return (events) => events
8
+ .replaceable(kinds.Pinlist, pubkey)
9
+ .pipe(map((event) => event && processTags(event.tags.filter(isETag), getEventPointerFromETag)));
12
10
  }
@@ -3,10 +3,5 @@ import { filter, map } from "rxjs/operators";
3
3
  import { getProfileContent, isValidProfile } from "../helpers/profile.js";
4
4
  /** A query that gets and parses the kind 0 metadata for a pubkey */
5
5
  export function ProfileQuery(pubkey) {
6
- return {
7
- key: pubkey,
8
- run: (events) => {
9
- return events.replaceable(kinds.Metadata, pubkey).pipe(filter(isValidProfile), map((event) => event && getProfileContent(event)));
10
- },
11
- };
6
+ return (events) => events.replaceable(kinds.Metadata, pubkey).pipe(filter(isValidProfile), map((event) => event && getProfileContent(event)));
12
7
  }
@@ -2,18 +2,15 @@ import { kinds } from "nostr-tools";
2
2
  import { getEventUID, isReplaceable } from "../helpers/event.js";
3
3
  /** A query that returns all reactions to an event (supports replaceable events) */
4
4
  export function ReactionsQuery(event) {
5
- return {
6
- key: getEventUID(event),
7
- run: (events) => events.timeline(isReplaceable(event.kind)
8
- ? [
9
- { kinds: [kinds.Reaction], "#e": [event.id] },
10
- { kinds: [kinds.Reaction], "#a": [getEventUID(event)] },
11
- ]
12
- : [
13
- {
14
- kinds: [kinds.Reaction],
15
- "#e": [event.id],
16
- },
17
- ]),
18
- };
5
+ return (events) => events.timeline(isReplaceable(event.kind)
6
+ ? [
7
+ { kinds: [kinds.Reaction], "#e": [event.id] },
8
+ { kinds: [kinds.Reaction], "#a": [getEventUID(event)] },
9
+ ]
10
+ : [
11
+ {
12
+ kinds: [kinds.Reaction],
13
+ "#e": [event.id],
14
+ },
15
+ ]);
19
16
  }
@@ -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
+ }
@@ -1,38 +1,21 @@
1
- import hash_sum from "hash-sum";
2
- import { getReplaceableUID } from "../helpers/event.js";
3
1
  /** Creates a Query that returns a single event or undefined */
4
2
  export function SingleEventQuery(id) {
5
- return {
6
- key: id,
7
- run: (events) => events.event(id),
8
- };
3
+ return (events) => events.event(id);
9
4
  }
10
5
  /** Creates a Query that returns a multiple events in a map */
11
6
  export function MultipleEventsQuery(ids) {
12
- return {
13
- key: ids.join(","),
14
- run: (events) => events.events(ids),
15
- };
7
+ return (events) => events.events(ids);
16
8
  }
17
9
  /** Creates a Query returning the latest version of a replaceable event */
18
10
  export function ReplaceableQuery(kind, pubkey, d) {
19
- return {
20
- key: getReplaceableUID(kind, pubkey, d),
21
- run: (events) => events.replaceable(kind, pubkey, d),
22
- };
11
+ return (events) => events.replaceable(kind, pubkey, d);
23
12
  }
24
13
  /** Creates a Query that returns an array of sorted events matching the filters */
25
14
  export function TimelineQuery(filters, includeOldVersion) {
26
15
  filters = Array.isArray(filters) ? filters : [filters];
27
- return {
28
- key: hash_sum(filters) + (includeOldVersion ? "-history" : ""),
29
- run: (events) => events.timeline(filters, includeOldVersion),
30
- };
16
+ return (events) => events.timeline(filters, includeOldVersion);
31
17
  }
32
18
  /** Creates a Query that returns a directory of events by their UID */
33
19
  export function ReplaceableSetQuery(pointers) {
34
- return {
35
- key: hash_sum(pointers),
36
- run: (events) => events.replaceableSet(pointers),
37
- };
20
+ return (events) => events.replaceableSet(pointers);
38
21
  }