applesauce-core 0.12.1 → 1.0.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 (66) hide show
  1. package/README.md +28 -10
  2. package/dist/event-store/__tests__/event-store.test.js +52 -1
  3. package/dist/event-store/database.js +3 -3
  4. package/dist/event-store/event-store.js +15 -8
  5. package/dist/event-store/interface.d.ts +11 -7
  6. package/dist/helpers/__tests__/bookmarks.test.d.ts +1 -0
  7. package/dist/helpers/__tests__/bookmarks.test.js +88 -0
  8. package/dist/helpers/__tests__/comment.test.js +14 -0
  9. package/dist/helpers/__tests__/contacts.test.d.ts +1 -0
  10. package/dist/helpers/__tests__/contacts.test.js +34 -0
  11. package/dist/helpers/__tests__/events.test.d.ts +1 -0
  12. package/dist/helpers/__tests__/events.test.js +32 -0
  13. package/dist/helpers/__tests__/mutes.test.d.ts +1 -0
  14. package/dist/helpers/__tests__/mutes.test.js +55 -0
  15. package/dist/helpers/bookmarks.d.ts +6 -1
  16. package/dist/helpers/bookmarks.js +52 -7
  17. package/dist/helpers/comment.d.ts +7 -3
  18. package/dist/helpers/comment.js +6 -1
  19. package/dist/helpers/contacts.d.ts +11 -0
  20. package/dist/helpers/contacts.js +34 -0
  21. package/dist/helpers/event.d.ts +8 -3
  22. package/dist/helpers/event.js +21 -13
  23. package/dist/helpers/lists.d.ts +40 -12
  24. package/dist/helpers/lists.js +62 -23
  25. package/dist/helpers/mutes.d.ts +8 -0
  26. package/dist/helpers/mutes.js +66 -5
  27. package/dist/helpers/nip-19.d.ts +14 -0
  28. package/dist/helpers/nip-19.js +29 -0
  29. package/dist/helpers/pointers.js +6 -6
  30. package/dist/observable/__tests__/listen-latest-updates.test.d.ts +1 -0
  31. package/dist/observable/__tests__/listen-latest-updates.test.js +55 -0
  32. package/dist/observable/defined.d.ts +3 -0
  33. package/dist/observable/defined.js +5 -0
  34. package/dist/observable/get-observable-value.d.ts +4 -1
  35. package/dist/observable/get-observable-value.js +4 -1
  36. package/dist/observable/index.d.ts +3 -1
  37. package/dist/observable/index.js +3 -1
  38. package/dist/observable/listen-latest-updates.d.ts +5 -0
  39. package/dist/observable/listen-latest-updates.js +12 -0
  40. package/dist/queries/blossom.js +1 -6
  41. package/dist/queries/bookmarks.d.ts +5 -5
  42. package/dist/queries/bookmarks.js +18 -17
  43. package/dist/queries/channels.js +41 -53
  44. package/dist/queries/comments.js +6 -9
  45. package/dist/queries/contacts.d.ts +6 -1
  46. package/dist/queries/contacts.js +21 -9
  47. package/dist/queries/index.d.ts +1 -0
  48. package/dist/queries/index.js +1 -0
  49. package/dist/queries/mailboxes.js +4 -7
  50. package/dist/queries/mutes.d.ts +6 -6
  51. package/dist/queries/mutes.js +20 -19
  52. package/dist/queries/pins.d.ts +1 -0
  53. package/dist/queries/pins.js +4 -6
  54. package/dist/queries/profile.js +1 -6
  55. package/dist/queries/reactions.js +11 -14
  56. package/dist/queries/relays.d.ts +27 -0
  57. package/dist/queries/relays.js +44 -0
  58. package/dist/queries/simple.js +5 -22
  59. package/dist/queries/thread.js +45 -51
  60. package/dist/queries/user-status.js +23 -29
  61. package/dist/queries/zaps.js +10 -13
  62. package/dist/query-store/query-store.d.ts +7 -6
  63. package/dist/query-store/query-store.js +13 -8
  64. package/package.json +3 -3
  65. package/dist/observable/share-latest-value.d.ts +0 -6
  66. package/dist/observable/share-latest-value.js +0 -24
@@ -1,20 +1,20 @@
1
1
  import { naddrEncode, neventEncode, noteEncode, nprofileEncode, npubEncode, nsecEncode, } from "nostr-tools/nip19";
2
2
  import { getPublicKey, kinds } from "nostr-tools";
3
3
  import { getReplaceableIdentifier } from "./event.js";
4
- import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
4
+ import { isAddressableKind } from "nostr-tools/kinds";
5
5
  import { isSafeRelayURL } from "./relays.js";
6
6
  export function parseCoordinate(a, requireD = false, silent = true) {
7
7
  const parts = a.split(":");
8
- const kind = parts[0] && parseInt(parts[0]);
8
+ const kind = parts[0] ? parseInt(parts[0]) : undefined;
9
9
  const pubkey = parts[1];
10
10
  const d = parts[2];
11
- if (!kind) {
11
+ if (kind === undefined) {
12
12
  if (silent)
13
13
  return null;
14
14
  else
15
15
  throw new Error("Missing kind");
16
16
  }
17
- if (!pubkey) {
17
+ if (pubkey === undefined || pubkey === "") {
18
18
  if (silent)
19
19
  return null;
20
20
  else
@@ -155,7 +155,7 @@ export function getCoordinateFromAddressPointer(pointer) {
155
155
  * @throws
156
156
  */
157
157
  export function getAddressPointerForEvent(event, relays) {
158
- if (!isParameterizedReplaceableKind(event.kind))
158
+ if (!isAddressableKind(event.kind))
159
159
  throw new Error("Cant get AddressPointer for non-replaceable event");
160
160
  const d = getReplaceableIdentifier(event);
161
161
  return {
@@ -179,7 +179,7 @@ export function getEventPointerForEvent(event, relays) {
179
179
  }
180
180
  /** Returns a pointer for a given event */
181
181
  export function getPointerForEvent(event, relays) {
182
- if (kinds.isParameterizedReplaceableKind(event.kind)) {
182
+ if (kinds.isAddressableKind(event.kind)) {
183
183
  const d = getReplaceableIdentifier(event);
184
184
  return {
185
185
  type: "naddr",
@@ -0,0 +1,55 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+ import { subscribeSpyTo } from "@hirez_io/observer-spy";
3
+ import { of } from "rxjs";
4
+ import { EventStore } from "../../event-store/event-store.js";
5
+ import { listenLatestUpdates } from "../listen-latest-updates.js";
6
+ import { FakeUser } from "../../__tests__/fixtures.js";
7
+ let eventStore;
8
+ let user;
9
+ let event;
10
+ beforeEach(() => {
11
+ eventStore = new EventStore();
12
+ user = new FakeUser();
13
+ event = user.note("original content");
14
+ });
15
+ describe("listenLatestUpdates", () => {
16
+ it("should emit the initial event", () => {
17
+ const source = of(event);
18
+ const spy = subscribeSpyTo(source.pipe(listenLatestUpdates(eventStore)));
19
+ expect(spy.getValues()).toEqual([event]);
20
+ });
21
+ it("should emit the event again when it's updated in the event store", () => {
22
+ // Add the event to the store first
23
+ eventStore.add(event);
24
+ // Create a source that emits the event
25
+ const source = of(event);
26
+ const spy = subscribeSpyTo(source.pipe(listenLatestUpdates(eventStore)));
27
+ // Create an updated version of the event
28
+ Reflect.set(event, Symbol.for("new-prop"), "testing");
29
+ // Update the event in the store
30
+ eventStore.update(event);
31
+ // Should have received both the original and updated event
32
+ expect(spy.getValues()).toEqual([event, event]);
33
+ });
34
+ it("should not emit updates for other events", () => {
35
+ // Add the event to the store
36
+ eventStore.add(event);
37
+ // Create a source that emits the event
38
+ const source = of(event);
39
+ const spy = subscribeSpyTo(source.pipe(listenLatestUpdates(eventStore)));
40
+ // Create a different event
41
+ const otherEvent = user.note("other content");
42
+ // Add the other event to the store
43
+ eventStore.add(otherEvent);
44
+ // Should only have received the original event
45
+ expect(spy.getValues()).toEqual([event]);
46
+ });
47
+ it("should handle undefined initial event", () => {
48
+ const source = of(undefined);
49
+ const spy = subscribeSpyTo(source.pipe(listenLatestUpdates(eventStore)));
50
+ expect(spy.getValues()).toEqual([undefined]);
51
+ // Adding events to the store should not trigger emissions
52
+ eventStore.add(event);
53
+ expect(spy.getValues()).toEqual([undefined]);
54
+ });
55
+ });
@@ -0,0 +1,3 @@
1
+ import { OperatorFunction } from "rxjs";
2
+ /** Filters out undefined and null values */
3
+ export declare function defined<T>(): OperatorFunction<T | undefined, NonNullable<T>>;
@@ -0,0 +1,5 @@
1
+ import { filter } from "rxjs";
2
+ /** Filters out undefined and null values */
3
+ export function defined() {
4
+ return (source) => source.pipe(filter((v) => v !== undefined && v !== null));
5
+ }
@@ -1,3 +1,6 @@
1
1
  import { Observable } from "rxjs";
2
- /** Subscribes and returns the observables current or next value */
2
+ /**
3
+ * Subscribes and returns the observables current or next value
4
+ * @deprecated use `firstValueFrom` instead
5
+ */
3
6
  export declare function getObservableValue<T>(observable: Observable<T>): T | Promise<T>;
@@ -1,5 +1,8 @@
1
1
  import { BehaviorSubject, firstValueFrom } from "rxjs";
2
- /** Subscribes and returns the observables current or next value */
2
+ /**
3
+ * Subscribes and returns the observables current or next value
4
+ * @deprecated use `firstValueFrom` instead
5
+ */
3
6
  export function getObservableValue(observable) {
4
7
  if (observable instanceof BehaviorSubject)
5
8
  return observable.value;
@@ -1,3 +1,5 @@
1
+ export * from "./defined.js";
1
2
  export * from "./get-observable-value.js";
2
- export * from "./share-latest-value.js";
3
+ export * from "./listen-latest-updates.js";
3
4
  export * from "./simple-timeout.js";
5
+ export * from "./with-immediate-value.js";
@@ -1,3 +1,5 @@
1
+ export * from "./defined.js";
1
2
  export * from "./get-observable-value.js";
2
- export * from "./share-latest-value.js";
3
+ export * from "./listen-latest-updates.js";
3
4
  export * from "./simple-timeout.js";
5
+ export * from "./with-immediate-value.js";
@@ -0,0 +1,5 @@
1
+ import { NostrEvent } from "nostr-tools";
2
+ import { MonoTypeOperatorFunction } from "rxjs";
3
+ import { IStreamEventStore } from "../event-store/interface.js";
4
+ /** Lists for any updates to the latest event and remits it */
5
+ export declare function listenLatestUpdates(eventStore: IStreamEventStore): MonoTypeOperatorFunction<NostrEvent | undefined>;
@@ -0,0 +1,12 @@
1
+ import { filter, merge, tap } from "rxjs";
2
+ /** Lists for any updates to the latest event and remits it */
3
+ export function listenLatestUpdates(eventStore) {
4
+ return (source) => {
5
+ let latest;
6
+ return merge(
7
+ // Get the latest event
8
+ source.pipe(tap((value) => (latest = value))),
9
+ // listen for updates
10
+ eventStore.updates.pipe(filter((e) => e.id === latest?.id)));
11
+ };
12
+ }
@@ -1,10 +1,5 @@
1
1
  import { map } from "rxjs/operators";
2
2
  import { BLOSSOM_SERVER_LIST_KIND, getBlossomServersFromList } from "../helpers/blossom.js";
3
3
  export function UserBlossomServersQuery(pubkey) {
4
- return {
5
- key: pubkey,
6
- run: (store) => store
7
- .replaceable(BLOSSOM_SERVER_LIST_KIND, pubkey)
8
- .pipe(map((event) => event && getBlossomServersFromList(event))),
9
- };
4
+ return (store) => store.replaceable(BLOSSOM_SERVER_LIST_KIND, pubkey).pipe(map((event) => event && getBlossomServersFromList(event)));
10
5
  }
@@ -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>;