applesauce-common 0.0.0-next-20251209200210 → 0.0.0-next-20251231055351

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 (116) hide show
  1. package/README.md +45 -4
  2. package/dist/blueprints/__register__.d.ts +7 -0
  3. package/dist/blueprints/__register__.js +8 -0
  4. package/dist/blueprints/comment.d.ts +3 -2
  5. package/dist/blueprints/group-mangement.d.ts +25 -0
  6. package/dist/blueprints/group-mangement.js +40 -0
  7. package/dist/blueprints/index.d.ts +1 -0
  8. package/dist/blueprints/index.js +1 -0
  9. package/dist/blueprints/torrent.d.ts +7 -0
  10. package/dist/blueprints/torrent.js +5 -1
  11. package/dist/casts/article.d.ts +19 -0
  12. package/dist/casts/article.js +47 -0
  13. package/dist/casts/bookmarks.d.ts +35 -0
  14. package/dist/casts/bookmarks.js +91 -0
  15. package/dist/casts/cast.d.ts +30 -0
  16. package/dist/casts/cast.js +67 -0
  17. package/dist/casts/comment.d.ts +18 -0
  18. package/dist/casts/comment.js +54 -0
  19. package/dist/casts/groups.d.ts +19 -0
  20. package/dist/casts/groups.js +43 -0
  21. package/dist/casts/index.d.ts +18 -0
  22. package/dist/casts/index.js +18 -0
  23. package/dist/casts/mutes.d.ts +23 -0
  24. package/dist/casts/mutes.js +54 -0
  25. package/dist/casts/note.d.ts +25 -0
  26. package/dist/casts/note.js +76 -0
  27. package/dist/casts/profile.d.ts +24 -0
  28. package/dist/casts/profile.js +52 -0
  29. package/dist/casts/reaction.d.ts +17 -0
  30. package/dist/casts/reaction.js +46 -0
  31. package/dist/casts/relay-discovery.d.ts +29 -0
  32. package/dist/casts/relay-discovery.js +54 -0
  33. package/dist/casts/relay-lists.d.ts +33 -0
  34. package/dist/casts/relay-lists.js +72 -0
  35. package/dist/casts/relay-monitor.d.ts +21 -0
  36. package/dist/casts/relay-monitor.js +41 -0
  37. package/dist/casts/report.d.ts +31 -0
  38. package/dist/casts/report.js +74 -0
  39. package/dist/casts/share.d.ts +15 -0
  40. package/dist/casts/share.js +34 -0
  41. package/dist/casts/stream.d.ts +43 -0
  42. package/dist/casts/stream.js +116 -0
  43. package/dist/casts/torrent.d.ts +31 -0
  44. package/dist/casts/torrent.js +62 -0
  45. package/dist/casts/user.d.ts +40 -0
  46. package/dist/casts/user.js +181 -0
  47. package/dist/casts/zap.d.ts +17 -0
  48. package/dist/casts/zap.js +47 -0
  49. package/dist/helpers/bookmark.d.ts +18 -17
  50. package/dist/helpers/bookmark.js +36 -49
  51. package/dist/helpers/calendar-event.d.ts +7 -1
  52. package/dist/helpers/calendar-event.js +8 -10
  53. package/dist/helpers/channels.d.ts +1 -1
  54. package/dist/helpers/channels.js +5 -8
  55. package/dist/helpers/comment.d.ts +3 -1
  56. package/dist/helpers/comment.js +12 -2
  57. package/dist/helpers/encrypted-content-cache.js +23 -25
  58. package/dist/helpers/external-id.d.ts +32 -0
  59. package/dist/helpers/external-id.js +85 -0
  60. package/dist/helpers/file-metadata.d.ts +1 -4
  61. package/dist/helpers/file-metadata.js +1 -4
  62. package/dist/helpers/gift-wrap.js +11 -5
  63. package/dist/helpers/groups.d.ts +129 -7
  64. package/dist/helpers/groups.js +317 -15
  65. package/dist/helpers/index.d.ts +1 -1
  66. package/dist/helpers/index.js +1 -1
  67. package/dist/helpers/lists.d.ts +0 -1
  68. package/dist/helpers/lists.js +4 -5
  69. package/dist/helpers/mute.d.ts +14 -11
  70. package/dist/helpers/mute.js +9 -4
  71. package/dist/helpers/relay-list.d.ts +14 -0
  72. package/dist/helpers/relay-list.js +18 -0
  73. package/dist/helpers/reports.d.ts +4 -1
  74. package/dist/helpers/reports.js +14 -10
  75. package/dist/helpers/stream-chat.d.ts +4 -1
  76. package/dist/helpers/stream-chat.js +4 -1
  77. package/dist/index.d.ts +1 -0
  78. package/dist/index.js +1 -0
  79. package/dist/models/__register__.d.ts +5 -0
  80. package/dist/models/__register__.js +6 -0
  81. package/dist/models/blossom.d.ts +2 -2
  82. package/dist/models/blossom.js +1 -1
  83. package/dist/models/bookmarks.d.ts +3 -5
  84. package/dist/models/bookmarks.js +2 -10
  85. package/dist/models/channels.js +3 -9
  86. package/dist/models/comments.d.ts +3 -2
  87. package/dist/models/comments.js +19 -1
  88. package/dist/models/index.d.ts +3 -1
  89. package/dist/models/index.js +4 -1
  90. package/dist/models/mutes.d.ts +5 -5
  91. package/dist/models/{relays.js → relay-lists.js} +2 -1
  92. package/dist/models/shares.d.ts +3 -0
  93. package/dist/models/shares.js +5 -0
  94. package/dist/models/thread.js +30 -24
  95. package/dist/observable/cast-stream.d.ts +8 -0
  96. package/dist/observable/cast-stream.js +29 -0
  97. package/dist/observable/chainable.d.ts +50 -0
  98. package/dist/observable/chainable.js +79 -0
  99. package/dist/observable/index.d.ts +2 -0
  100. package/dist/observable/index.js +2 -0
  101. package/dist/operations/comment.d.ts +3 -2
  102. package/dist/operations/comment.js +19 -5
  103. package/dist/operations/group.d.ts +14 -1
  104. package/dist/operations/group.js +42 -4
  105. package/dist/operations/index.d.ts +1 -1
  106. package/dist/operations/index.js +1 -1
  107. package/dist/operations/tag/bookmarks.d.ts +3 -2
  108. package/dist/operations/tag/bookmarks.js +34 -14
  109. package/dist/operations/torrent.d.ts +2 -0
  110. package/dist/operations/torrent.js +4 -0
  111. package/dist/register.d.ts +2 -11
  112. package/dist/register.js +2 -11
  113. package/package.json +12 -2
  114. package/dist/helpers/mailboxes.d.ts +0 -7
  115. package/dist/helpers/mailboxes.js +0 -49
  116. /package/dist/models/{relays.d.ts → relay-lists.d.ts} +0 -0
@@ -0,0 +1,43 @@
1
+ import { hasHiddenContent } from "applesauce-core/helpers";
2
+ import { watchEventUpdates } from "applesauce-core/observable";
3
+ import { map, of } from "rxjs";
4
+ import { getHiddenGroups, getPublicGroups, GROUPS_LIST_KIND, isHiddenGroupsUnlocked, unlockHiddenGroups, } from "../helpers/groups.js";
5
+ import { EventCast } from "./cast.js";
6
+ function isValidGroupsList(event) {
7
+ return event.kind === GROUPS_LIST_KIND;
8
+ }
9
+ export class GroupsList extends EventCast {
10
+ constructor(event, store) {
11
+ if (!isValidGroupsList(event))
12
+ throw new Error("Invalid groups list");
13
+ super(event, store);
14
+ }
15
+ /** The public groups in the list */
16
+ get groups() {
17
+ return getPublicGroups(this.event);
18
+ }
19
+ /** Get the unlocked hidden groups */
20
+ get hidden() {
21
+ return getHiddenGroups(this.event);
22
+ }
23
+ /** An observable that updates when hidden groups are unlocked */
24
+ get hidden$() {
25
+ return this.$$ref("hidden$", (store) => of(this.event).pipe(
26
+ // Watch for event updates
27
+ watchEventUpdates(store),
28
+ // Get hidden groups
29
+ map((event) => event && getHiddenGroups(event))));
30
+ }
31
+ /** Whether the groups list has hidden groups */
32
+ get hasHidden() {
33
+ return hasHiddenContent(this.event);
34
+ }
35
+ /** Whether the groups list is unlocked */
36
+ get unlocked() {
37
+ return isHiddenGroupsUnlocked(this.event);
38
+ }
39
+ /** Unlocks the hidden groups on the groups list */
40
+ async unlock(signer) {
41
+ return unlockHiddenGroups(this.event, signer);
42
+ }
43
+ }
@@ -0,0 +1,18 @@
1
+ export * from "./article.js";
2
+ export * from "./bookmarks.js";
3
+ export * from "./cast.js";
4
+ export * from "./comment.js";
5
+ export * from "./groups.js";
6
+ export * from "./mutes.js";
7
+ export * from "./note.js";
8
+ export * from "./profile.js";
9
+ export * from "./reaction.js";
10
+ export * from "./relay-discovery.js";
11
+ export * from "./relay-lists.js";
12
+ export * from "./relay-monitor.js";
13
+ export * from "./report.js";
14
+ export * from "./share.js";
15
+ export * from "./stream.js";
16
+ export * from "./torrent.js";
17
+ export * from "./user.js";
18
+ export * from "./zap.js";
@@ -0,0 +1,18 @@
1
+ export * from "./article.js";
2
+ export * from "./bookmarks.js";
3
+ export * from "./cast.js";
4
+ export * from "./comment.js";
5
+ export * from "./groups.js";
6
+ export * from "./mutes.js";
7
+ export * from "./note.js";
8
+ export * from "./profile.js";
9
+ export * from "./reaction.js";
10
+ export * from "./relay-discovery.js";
11
+ export * from "./relay-lists.js";
12
+ export * from "./relay-monitor.js";
13
+ export * from "./report.js";
14
+ export * from "./share.js";
15
+ export * from "./stream.js";
16
+ export * from "./torrent.js";
17
+ export * from "./user.js";
18
+ export * from "./zap.js";
@@ -0,0 +1,23 @@
1
+ import { NostrEvent } from "applesauce-core/helpers";
2
+ import { HiddenContentSigner } from "applesauce-core/helpers/hidden-content";
3
+ import { MuteListEvent, type MutedThings } from "../helpers/mute.js";
4
+ import { CastRefEventStore, EventCast } from "./cast.js";
5
+ /** Class for mute lists (kind 10000) */
6
+ export declare class Mutes extends EventCast<MuteListEvent> implements MutedThings {
7
+ constructor(event: NostrEvent, store: CastRefEventStore);
8
+ get mutes(): MutedThings;
9
+ get hashtags(): Set<string>;
10
+ get words(): Set<string>;
11
+ get pubkeys(): Set<string>;
12
+ get threads(): Set<string>;
13
+ /** Get the unlocked hidden mutes */
14
+ get hidden(): MutedThings | undefined;
15
+ /** An observable that updates when hidden mutes are unlocked */
16
+ get hidden$(): import("../observable/chainable.js").ChainableObservable<MutedThings>;
17
+ /** Whether the mute list has hidden mutes */
18
+ get hasHidden(): boolean;
19
+ /** Whether the mute list is unlocked */
20
+ get unlocked(): boolean;
21
+ /** Unlocks the hidden mutes on the mute list */
22
+ unlock(signer: HiddenContentSigner): Promise<MutedThings>;
23
+ }
@@ -0,0 +1,54 @@
1
+ import { defined, watchEventUpdates } from "applesauce-core";
2
+ import { hasHiddenTags } from "applesauce-core/helpers";
3
+ import { map, of } from "rxjs";
4
+ import { getHiddenMutedThings, getPublicMutedThings, isHiddenMutesUnlocked, isValidMuteList, unlockHiddenMutes, } from "../helpers/mute.js";
5
+ import { EventCast } from "./cast.js";
6
+ /** Class for mute lists (kind 10000) */
7
+ export class Mutes extends EventCast {
8
+ constructor(event, store) {
9
+ if (!isValidMuteList(event))
10
+ throw new Error("Invalid mute list");
11
+ super(event, store);
12
+ }
13
+ get mutes() {
14
+ return getPublicMutedThings(this.event);
15
+ }
16
+ get hashtags() {
17
+ return this.mutes.hashtags;
18
+ }
19
+ get words() {
20
+ return this.mutes.words;
21
+ }
22
+ get pubkeys() {
23
+ return this.mutes.pubkeys;
24
+ }
25
+ get threads() {
26
+ return this.mutes.threads;
27
+ }
28
+ /** Get the unlocked hidden mutes */
29
+ get hidden() {
30
+ return getHiddenMutedThings(this.event);
31
+ }
32
+ /** An observable that updates when hidden mutes are unlocked */
33
+ get hidden$() {
34
+ return this.$$ref("hidden$", (store) => of(this.event).pipe(
35
+ // Watch for event updates
36
+ watchEventUpdates(store),
37
+ // Get hidden mutes
38
+ map((event) => event && getHiddenMutedThings(event)),
39
+ // Only emit when the hidden mutes are unlocked
40
+ defined()));
41
+ }
42
+ /** Whether the mute list has hidden mutes */
43
+ get hasHidden() {
44
+ return hasHiddenTags(this.event);
45
+ }
46
+ /** Whether the mute list is unlocked */
47
+ get unlocked() {
48
+ return isHiddenMutesUnlocked(this.event);
49
+ }
50
+ /** Unlocks the hidden mutes on the mute list */
51
+ unlock(signer) {
52
+ return unlockHiddenMutes(this.event, signer);
53
+ }
54
+ }
@@ -0,0 +1,25 @@
1
+ import { EventPointer, KnownEvent, NostrEvent } from "applesauce-core/helpers";
2
+ import { CastRefEventStore, EventCast } from "./cast.js";
3
+ import { Comment } from "./comment.js";
4
+ import { Reaction } from "./reaction.js";
5
+ import { Share } from "./share.js";
6
+ import { Zap } from "./zap.js";
7
+ export declare class Note extends EventCast<KnownEvent<1>> {
8
+ constructor(event: NostrEvent, store: CastRefEventStore);
9
+ get references(): import("../helpers/threading.js").ThreadReferences;
10
+ get isReply(): boolean;
11
+ get isRoot(): boolean;
12
+ /** An array of events that this note is quoting */
13
+ get quotePointers(): EventPointer[];
14
+ /** Gets the NIP-10 root event */
15
+ get threadRoot$(): import("../observable/chainable.js").ChainableObservable<import("nostr-tools").Event | undefined>;
16
+ /** Gets the NIP-10 reply event */
17
+ get replyingTo$(): import("../observable/chainable.js").ChainableObservable<import("nostr-tools").Event | undefined>;
18
+ /** Gets the NIP-10 replies to this event */
19
+ get replies$(): import("../observable/chainable.js").ChainableObservable<Note[]>;
20
+ /** Gets the NIP-22 comments to this event */
21
+ get comments$(): import("../observable/chainable.js").ChainableObservable<Comment[]>;
22
+ get zaps$(): import("../observable/chainable.js").ChainableObservable<Zap[]>;
23
+ get shares$(): import("../observable/chainable.js").ChainableObservable<Share[]>;
24
+ get reactions$(): import("../observable/chainable.js").ChainableObservable<Reaction[]>;
25
+ }
@@ -0,0 +1,76 @@
1
+ import { getEventPointerFromQTag, isQTag, kinds, processTags, } from "applesauce-core/helpers";
2
+ import { getNip10References } from "../helpers/threading.js";
3
+ import { CommentsModel } from "../models/comments.js";
4
+ import { ReactionsModel } from "../models/reactions.js";
5
+ import { SharesModel } from "../models/shares.js";
6
+ import { RepliesModel } from "../models/thread.js";
7
+ import { EventZapsModel } from "../models/zaps.js";
8
+ import { castTimelineStream } from "../observable/cast-stream.js";
9
+ import { EventCast } from "./cast.js";
10
+ import { Comment } from "./comment.js";
11
+ import { Reaction } from "./reaction.js";
12
+ import { Share } from "./share.js";
13
+ import { Zap } from "./zap.js";
14
+ import { of } from "rxjs";
15
+ function isValidNote(event) {
16
+ return event.kind === kinds.ShortTextNote;
17
+ }
18
+ export class Note extends EventCast {
19
+ constructor(event, store) {
20
+ if (!isValidNote(event))
21
+ throw new Error("Invalid note");
22
+ super(event, store);
23
+ }
24
+ get references() {
25
+ return getNip10References(this.event);
26
+ }
27
+ get isReply() {
28
+ return !!this.references.reply?.e || !!this.references.reply?.a;
29
+ }
30
+ get isRoot() {
31
+ return !this.references.reply && !this.references.root;
32
+ }
33
+ /** An array of events that this note is quoting */
34
+ get quotePointers() {
35
+ return processTags(this.event.tags, (t) => (isQTag(t) ? t : undefined), (t) => getEventPointerFromQTag(t) ?? undefined);
36
+ }
37
+ /** Gets the NIP-10 root event */
38
+ get threadRoot$() {
39
+ return this.$$ref("threadRoot$", (store) => {
40
+ const pointer = this.references.root;
41
+ // Return undefined if no root reference
42
+ if (pointer === undefined)
43
+ return of(undefined);
44
+ // Get the event by either the address or event pointer
45
+ return store.event(pointer.a ?? pointer.e);
46
+ });
47
+ }
48
+ /** Gets the NIP-10 reply event */
49
+ get replyingTo$() {
50
+ return this.$$ref("replyingTo$", (store) => {
51
+ const pointer = this.references.reply;
52
+ // Return undefined if no reply reference
53
+ if (pointer === undefined)
54
+ return of(undefined);
55
+ // Get the event by either the address or event pointer
56
+ return store.event(pointer.a ?? pointer.e);
57
+ });
58
+ }
59
+ /** Gets the NIP-10 replies to this event */
60
+ get replies$() {
61
+ return this.$$ref("replies$", (store) => store.model(RepliesModel, this.event, [kinds.ShortTextNote]).pipe(castTimelineStream(Note, store)));
62
+ }
63
+ /** Gets the NIP-22 comments to this event */
64
+ get comments$() {
65
+ return this.$$ref("comments$", (store) => store.model(CommentsModel, this.event).pipe(castTimelineStream(Comment, store)));
66
+ }
67
+ get zaps$() {
68
+ return this.$$ref("zaps$", (store) => store.model(EventZapsModel, this.event).pipe(castTimelineStream(Zap, store)));
69
+ }
70
+ get shares$() {
71
+ return this.$$ref("shares$", (store) => store.model(SharesModel, this.event).pipe(castTimelineStream(Share, store)));
72
+ }
73
+ get reactions$() {
74
+ return this.$$ref("reactions$", (store) => store.model(ReactionsModel, this.event).pipe(castTimelineStream(Reaction, store)));
75
+ }
76
+ }
@@ -0,0 +1,24 @@
1
+ import { NostrEvent, ProfileEvent } from "applesauce-core/helpers";
2
+ import { CastRefEventStore, EventCast } from "./cast.js";
3
+ /** Cast a kind 0 event to a Profile */
4
+ export declare class Profile extends EventCast<ProfileEvent> {
5
+ constructor(event: NostrEvent, store: CastRefEventStore);
6
+ get metadata(): import("applesauce-core/helpers").ProfileContent;
7
+ get name(): string | undefined;
8
+ get displayName(): string | undefined;
9
+ get about(): string | undefined;
10
+ get picture(): string | undefined;
11
+ get banner(): string | undefined;
12
+ get dnsIdentity(): string | undefined;
13
+ get website(): string | undefined;
14
+ get lud16(): string | undefined;
15
+ get lud06(): string | undefined;
16
+ get lightningAddress(): string | undefined;
17
+ get bot(): boolean | undefined;
18
+ get birthday(): {
19
+ year?: number;
20
+ month?: number;
21
+ day?: number;
22
+ } | undefined;
23
+ get languages(): string[] | undefined;
24
+ }
@@ -0,0 +1,52 @@
1
+ import { getDisplayName, getProfileContent, getProfilePicture, isValidProfile } from "applesauce-core/helpers/profile";
2
+ import { EventCast } from "./cast.js";
3
+ /** Cast a kind 0 event to a Profile */
4
+ export class Profile extends EventCast {
5
+ constructor(event, store) {
6
+ if (!isValidProfile(event))
7
+ throw new Error("Invalid profile");
8
+ super(event, store);
9
+ }
10
+ get metadata() {
11
+ return getProfileContent(this.event);
12
+ }
13
+ get name() {
14
+ return this.metadata.name;
15
+ }
16
+ get displayName() {
17
+ return getDisplayName(this.metadata);
18
+ }
19
+ get about() {
20
+ return this.metadata.about;
21
+ }
22
+ get picture() {
23
+ return getProfilePicture(this.metadata);
24
+ }
25
+ get banner() {
26
+ return this.metadata.banner;
27
+ }
28
+ get dnsIdentity() {
29
+ return this.metadata.nip05;
30
+ }
31
+ get website() {
32
+ return this.metadata.website;
33
+ }
34
+ get lud16() {
35
+ return this.metadata.lud16;
36
+ }
37
+ get lud06() {
38
+ return this.metadata.lud06;
39
+ }
40
+ get lightningAddress() {
41
+ return this.metadata.lud16 || this.metadata.lud06;
42
+ }
43
+ get bot() {
44
+ return this.metadata.bot;
45
+ }
46
+ get birthday() {
47
+ return this.metadata.birthday;
48
+ }
49
+ get languages() {
50
+ return this.metadata.languages;
51
+ }
52
+ }
@@ -0,0 +1,17 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { CastRefEventStore, EventCast } from "./cast.js";
3
+ export declare class Reaction extends EventCast<KnownEvent<7>> {
4
+ constructor(event: NostrEvent, store: CastRefEventStore);
5
+ /** Get the emoji content of the reaction (defaults to "+" if empty) */
6
+ get content(): string;
7
+ /** Get the custom emoji if this reaction uses a custom emoji */
8
+ get emoji(): import("../helpers/emoji.js").Emoji | undefined;
9
+ /** Get the event pointer for the event being reacted to */
10
+ get eventPointer(): import("nostr-tools/nip19").EventPointer | undefined;
11
+ /** Get the address pointer for the event being reacted to (for replaceable events) */
12
+ get addressPointer(): import("nostr-tools/nip19").AddressPointer | undefined;
13
+ /** Get the pointer (event or address) for the event being reacted to */
14
+ get pointer(): import("nostr-tools/nip19").EventPointer | import("nostr-tools/nip19").AddressPointer | undefined;
15
+ /** Get the event that this reaction is reacting to */
16
+ get reactedTo$(): import("../observable/chainable.js").ChainableObservable<import("nostr-tools").Event | undefined>;
17
+ }
@@ -0,0 +1,46 @@
1
+ import { kinds } from "applesauce-core/helpers/event";
2
+ import { of } from "rxjs";
3
+ import { getReactionEmoji } from "../helpers/emoji.js";
4
+ import { getReactionAddressPointer, getReactionEventPointer } from "../helpers/reaction.js";
5
+ import { EventCast } from "./cast.js";
6
+ import { addRelayHintsToPointer } from "applesauce-core/helpers";
7
+ function isValidReaction(event) {
8
+ return event.kind === kinds.Reaction;
9
+ }
10
+ export class Reaction extends EventCast {
11
+ constructor(event, store) {
12
+ if (!isValidReaction(event))
13
+ throw new Error("Invalid reaction");
14
+ super(event, store);
15
+ }
16
+ /** Get the emoji content of the reaction (defaults to "+" if empty) */
17
+ get content() {
18
+ return this.event.content || "+";
19
+ }
20
+ /** Get the custom emoji if this reaction uses a custom emoji */
21
+ get emoji() {
22
+ return getReactionEmoji(this.event);
23
+ }
24
+ /** Get the event pointer for the event being reacted to */
25
+ get eventPointer() {
26
+ return getReactionEventPointer(this.event);
27
+ }
28
+ /** Get the address pointer for the event being reacted to (for replaceable events) */
29
+ get addressPointer() {
30
+ return getReactionAddressPointer(this.event);
31
+ }
32
+ /** Get the pointer (event or address) for the event being reacted to */
33
+ get pointer() {
34
+ return this.addressPointer || this.eventPointer;
35
+ }
36
+ /** Get the event that this reaction is reacting to */
37
+ get reactedTo$() {
38
+ return this.$$ref("reactedTo$", (store) => {
39
+ const pointer = this.pointer;
40
+ if (!pointer)
41
+ return of(undefined);
42
+ else
43
+ return store.event(addRelayHintsToPointer(pointer, this.seen));
44
+ });
45
+ }
46
+ }
@@ -0,0 +1,29 @@
1
+ import { NostrEvent } from "applesauce-core/helpers";
2
+ import { RelayDiscoveryEvent } from "../helpers/relay-discovery.js";
3
+ import { CastRefEventStore, EventCast } from "./cast.js";
4
+ /** Cast a kind 30166 event to a RelayDiscovery */
5
+ export declare class RelayDiscovery extends EventCast<RelayDiscoveryEvent> {
6
+ constructor(event: NostrEvent, store: CastRefEventStore);
7
+ /** Gets the relay URL from this discovery event (from the `d` tag) */
8
+ get url(): string | undefined;
9
+ /** Gets the round-trip time (RTT) for opening the relay connection (in milliseconds) */
10
+ get rttOpen(): number | undefined;
11
+ /** Gets the round-trip time (RTT) for reading from the relay (in milliseconds) */
12
+ get rttRead(): number | undefined;
13
+ /** Gets the round-trip time (RTT) for writing to the relay (in milliseconds) */
14
+ get rttWrite(): number | undefined;
15
+ /** Gets the network type from this discovery event (clearnet, tor, i2p, loki) */
16
+ get networkType(): string | undefined;
17
+ /** Gets all relay attributes from this discovery event (from `W` tags) */
18
+ get attributes(): string[];
19
+ /** Gets all supported NIPs from this discovery event (from `N` tags) */
20
+ get supportedNIPs(): string[];
21
+ /** Gets all requirements from this discovery event (from `R` tags) */
22
+ get requirements(): string[];
23
+ /** Gets all topics from this discovery event (from `t` tags) */
24
+ get topics(): string[];
25
+ /** Gets all accepted and unaccepted kinds from this discovery event (from `k` tags) */
26
+ get acceptedKinds(): string[];
27
+ /** Gets the geohash from this discovery event (NIP-52 geohash) */
28
+ get geohash(): string | undefined;
29
+ }
@@ -0,0 +1,54 @@
1
+ import { getRelayDiscoveryAcceptedKinds, getRelayDiscoveryAttributes, getRelayDiscoveryGeohash, getRelayDiscoveryNetworkType, getRelayDiscoveryRequirements, getRelayDiscoveryRTT, getRelayDiscoverySupportedNIPs, getRelayDiscoveryTopics, getRelayDiscoveryURL, isValidRelayDiscovery, } from "../helpers/relay-discovery.js";
2
+ import { EventCast } from "./cast.js";
3
+ /** Cast a kind 30166 event to a RelayDiscovery */
4
+ export class RelayDiscovery extends EventCast {
5
+ constructor(event, store) {
6
+ if (!isValidRelayDiscovery(event))
7
+ throw new Error("Invalid relay discovery event");
8
+ super(event, store);
9
+ }
10
+ /** Gets the relay URL from this discovery event (from the `d` tag) */
11
+ get url() {
12
+ return getRelayDiscoveryURL(this.event);
13
+ }
14
+ /** Gets the round-trip time (RTT) for opening the relay connection (in milliseconds) */
15
+ get rttOpen() {
16
+ return getRelayDiscoveryRTT(this.event, "open");
17
+ }
18
+ /** Gets the round-trip time (RTT) for reading from the relay (in milliseconds) */
19
+ get rttRead() {
20
+ return getRelayDiscoveryRTT(this.event, "read");
21
+ }
22
+ /** Gets the round-trip time (RTT) for writing to the relay (in milliseconds) */
23
+ get rttWrite() {
24
+ return getRelayDiscoveryRTT(this.event, "write");
25
+ }
26
+ /** Gets the network type from this discovery event (clearnet, tor, i2p, loki) */
27
+ get networkType() {
28
+ return getRelayDiscoveryNetworkType(this.event);
29
+ }
30
+ /** Gets all relay attributes from this discovery event (from `W` tags) */
31
+ get attributes() {
32
+ return getRelayDiscoveryAttributes(this.event);
33
+ }
34
+ /** Gets all supported NIPs from this discovery event (from `N` tags) */
35
+ get supportedNIPs() {
36
+ return getRelayDiscoverySupportedNIPs(this.event);
37
+ }
38
+ /** Gets all requirements from this discovery event (from `R` tags) */
39
+ get requirements() {
40
+ return getRelayDiscoveryRequirements(this.event);
41
+ }
42
+ /** Gets all topics from this discovery event (from `t` tags) */
43
+ get topics() {
44
+ return getRelayDiscoveryTopics(this.event);
45
+ }
46
+ /** Gets all accepted and unaccepted kinds from this discovery event (from `k` tags) */
47
+ get acceptedKinds() {
48
+ return getRelayDiscoveryAcceptedKinds(this.event);
49
+ }
50
+ /** Gets the geohash from this discovery event (NIP-52 geohash) */
51
+ get geohash() {
52
+ return getRelayDiscoveryGeohash(this.event);
53
+ }
54
+ }
@@ -0,0 +1,33 @@
1
+ import { HiddenContentSigner } from "applesauce-core/helpers";
2
+ import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
3
+ import { BlockedRelaysListEvent, FAVORITE_RELAYS_KIND, FavoriteRelaysListEvent, SearchRelaysListEvent } from "../helpers/relay-list.js";
4
+ import { CastRefEventStore, EventCast } from "./cast.js";
5
+ /** Base class for relay lists */
6
+ declare class RelayListBase<T extends KnownEvent<typeof FAVORITE_RELAYS_KIND | typeof kinds.SearchRelaysList | kinds.BlockedRelaysList>> extends EventCast<T> {
7
+ constructor(event: T, store: CastRefEventStore);
8
+ /** The public relays in the relay list */
9
+ get relays(): string[];
10
+ /** The hidden relays in the relay list */
11
+ get hidden(): string[];
12
+ /** An observable that updates when the hidden relays are unlocked */
13
+ get hidden$(): import("../observable/chainable.js").ChainableObservable<string[]>;
14
+ /** Whether the relay list has hidden relays */
15
+ get hasHidden(): boolean;
16
+ /** Whether the relay list is unlocked */
17
+ get unlocked(): boolean;
18
+ /** Unlocks the hidden relays on the relay list */
19
+ unlock(signer: HiddenContentSigner): Promise<string[]>;
20
+ }
21
+ /** Class for favorite relays lists (kind 10012) */
22
+ export declare class FavoriteRelays extends RelayListBase<FavoriteRelaysListEvent> {
23
+ constructor(event: NostrEvent, store: CastRefEventStore);
24
+ }
25
+ /** Class for search relays lists (kind 10007) */
26
+ export declare class SearchRelays extends RelayListBase<SearchRelaysListEvent> {
27
+ constructor(event: NostrEvent, store: CastRefEventStore);
28
+ }
29
+ /** Class for blocked relays lists (kind 10006) */
30
+ export declare class BlockedRelays extends RelayListBase<BlockedRelaysListEvent> {
31
+ constructor(event: NostrEvent, store: CastRefEventStore);
32
+ }
33
+ export {};
@@ -0,0 +1,72 @@
1
+ import { defined, watchEventUpdates } from "applesauce-core";
2
+ import { hasHiddenTags, isHiddenTagsUnlocked, unlockHiddenTags } from "applesauce-core/helpers";
3
+ import { kinds } from "applesauce-core/helpers/event";
4
+ import { map, of } from "rxjs";
5
+ import { getRelaysFromList } from "../helpers/lists.js";
6
+ import { FAVORITE_RELAYS_KIND, isValidBlockedRelaysList, isValidFavoriteRelaysList, isValidSearchRelaysList, } from "../helpers/relay-list.js";
7
+ import { EventCast } from "./cast.js";
8
+ /** Base class for relay lists */
9
+ class RelayListBase extends EventCast {
10
+ constructor(event, store) {
11
+ if (event.kind !== FAVORITE_RELAYS_KIND &&
12
+ event.kind !== kinds.SearchRelaysList &&
13
+ event.kind !== kinds.BlockedRelaysList)
14
+ throw new Error(`Invalid relay list (kind ${event.kind})`);
15
+ super(event, store);
16
+ }
17
+ /** The public relays in the relay list */
18
+ get relays() {
19
+ return getRelaysFromList(this.event);
20
+ }
21
+ /** The hidden relays in the relay list */
22
+ get hidden() {
23
+ return getRelaysFromList(this.event, "hidden");
24
+ }
25
+ /** An observable that updates when the hidden relays are unlocked */
26
+ get hidden$() {
27
+ return this.$$ref("hidden$", (store) => of(this.event).pipe(
28
+ // Watch for event updates
29
+ watchEventUpdates(store),
30
+ // Get the hidden relays
31
+ map((event) => event && getRelaysFromList(event, "hidden")),
32
+ // Only emit when the hidden relays are unlocked
33
+ defined()));
34
+ }
35
+ /** Whether the relay list has hidden relays */
36
+ get hasHidden() {
37
+ return hasHiddenTags(this.event);
38
+ }
39
+ /** Whether the relay list is unlocked */
40
+ get unlocked() {
41
+ return isHiddenTagsUnlocked(this.event);
42
+ }
43
+ /** Unlocks the hidden relays on the relay list */
44
+ async unlock(signer) {
45
+ await unlockHiddenTags(this.event, signer);
46
+ return this.hidden;
47
+ }
48
+ }
49
+ /** Class for favorite relays lists (kind 10012) */
50
+ export class FavoriteRelays extends RelayListBase {
51
+ constructor(event, store) {
52
+ if (!isValidFavoriteRelaysList(event))
53
+ throw new Error("Invalid favorite relays list");
54
+ super(event, store);
55
+ }
56
+ }
57
+ /** Class for search relays lists (kind 10007) */
58
+ export class SearchRelays extends RelayListBase {
59
+ constructor(event, store) {
60
+ if (!isValidSearchRelaysList(event))
61
+ throw new Error("Invalid search relays list");
62
+ super(event, store);
63
+ }
64
+ }
65
+ /** Class for blocked relays lists (kind 10006) */
66
+ export class BlockedRelays extends RelayListBase {
67
+ constructor(event, store) {
68
+ if (!isValidBlockedRelaysList(event))
69
+ throw new Error("Invalid blocked relays list");
70
+ super(event, store);
71
+ }
72
+ }
@@ -0,0 +1,21 @@
1
+ import { NostrEvent } from "applesauce-core/helpers";
2
+ import { RelayMonitorAnnouncementEvent } from "../helpers/relay-discovery.js";
3
+ import { CastRefEventStore, EventCast } from "./cast.js";
4
+ import { RelayDiscovery } from "./relay-discovery.js";
5
+ /** Cast a kind 10166 event to a RelayMonitor */
6
+ export declare class RelayMonitor extends EventCast<RelayMonitorAnnouncementEvent> {
7
+ constructor(event: NostrEvent, store: CastRefEventStore);
8
+ /** Gets the frequency at which this monitor publishes events (in seconds) */
9
+ get frequency(): number | undefined;
10
+ /** Gets all timeout values from this monitor announcement */
11
+ get timeouts(): {
12
+ test?: string;
13
+ timeout: number;
14
+ }[];
15
+ /** Gets all checks conducted by this monitor */
16
+ get checks(): string[];
17
+ /** Gets the geohash from this monitor announcement (NIP-52 geohash) */
18
+ get geohash(): string | undefined;
19
+ /** Get the status of a relay from this monitor */
20
+ relayStatus(relay: string): import("../observable/chainable.js").ChainableObservable<RelayDiscovery | undefined>;
21
+ }
@@ -0,0 +1,41 @@
1
+ import { switchMap } from "rxjs";
2
+ import { getMonitorChecks, getMonitorFrequency, getMonitorGeohash, getMonitorTimeouts, isValidRelayMonitorAnnouncement, RELAY_DISCOVERY_KIND, } from "../helpers/relay-discovery.js";
3
+ import { castEventStream } from "../observable/cast-stream.js";
4
+ import { chainable } from "../observable/chainable.js";
5
+ import { EventCast } from "./cast.js";
6
+ import { RelayDiscovery } from "./relay-discovery.js";
7
+ /** Cast a kind 10166 event to a RelayMonitor */
8
+ export class RelayMonitor extends EventCast {
9
+ constructor(event, store) {
10
+ if (!isValidRelayMonitorAnnouncement(event))
11
+ throw new Error("Invalid relay monitor announcement");
12
+ super(event, store);
13
+ }
14
+ /** Gets the frequency at which this monitor publishes events (in seconds) */
15
+ get frequency() {
16
+ return getMonitorFrequency(this.event);
17
+ }
18
+ /** Gets all timeout values from this monitor announcement */
19
+ get timeouts() {
20
+ return getMonitorTimeouts(this.event);
21
+ }
22
+ /** Gets all checks conducted by this monitor */
23
+ get checks() {
24
+ return getMonitorChecks(this.event);
25
+ }
26
+ /** Gets the geohash from this monitor announcement (NIP-52 geohash) */
27
+ get geohash() {
28
+ return getMonitorGeohash(this.event);
29
+ }
30
+ /** Get the status of a relay from this monitor */
31
+ relayStatus(relay) {
32
+ return chainable(this.author.outboxes$.pipe(switchMap((outboxes) => this.store
33
+ .replaceable({
34
+ kind: RELAY_DISCOVERY_KIND,
35
+ pubkey: this.author.pubkey,
36
+ identifier: relay,
37
+ relays: outboxes,
38
+ })
39
+ .pipe(castEventStream(RelayDiscovery, this.store)))));
40
+ }
41
+ }