applesauce-common 6.1.0 → 7.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 (231) hide show
  1. package/README.md +1 -0
  2. package/dist/casts/_circular-import.d.ts +3 -0
  3. package/dist/casts/_circular-import.js +3 -0
  4. package/dist/casts/app-handler.d.ts +56 -0
  5. package/dist/casts/app-handler.js +105 -0
  6. package/dist/casts/app-recommendation.d.ts +26 -0
  7. package/dist/casts/app-recommendation.js +41 -0
  8. package/dist/casts/external-identities.d.ts +9 -0
  9. package/dist/casts/external-identities.js +14 -0
  10. package/dist/casts/forum-thread.d.ts +17 -0
  11. package/dist/casts/forum-thread.js +31 -0
  12. package/dist/casts/git-issue.d.ts +18 -0
  13. package/dist/casts/git-issue.js +26 -0
  14. package/dist/casts/git-patch.d.ts +49 -0
  15. package/dist/casts/git-patch.js +88 -0
  16. package/dist/casts/git-pull-request.d.ts +67 -0
  17. package/dist/casts/git-pull-request.js +122 -0
  18. package/dist/casts/git-repository.d.ts +9 -0
  19. package/dist/casts/git-repository.js +16 -0
  20. package/dist/casts/git-thread.d.ts +33 -0
  21. package/dist/casts/git-thread.js +65 -0
  22. package/dist/casts/index.d.ts +11 -0
  23. package/dist/casts/index.js +11 -0
  24. package/dist/casts/napplet.d.ts +98 -0
  25. package/dist/casts/napplet.js +196 -0
  26. package/dist/casts/note.d.ts +8 -0
  27. package/dist/casts/note.js +21 -1
  28. package/dist/casts/nsite.d.ts +134 -0
  29. package/dist/casts/nsite.js +249 -0
  30. package/dist/casts/profile.d.ts +20 -0
  31. package/dist/casts/profile.js +30 -0
  32. package/dist/casts/reaction.d.ts +1 -1
  33. package/dist/casts/relay-discovery.d.ts +4 -0
  34. package/dist/casts/relay-discovery.js +9 -1
  35. package/dist/casts/report.d.ts +28 -15
  36. package/dist/casts/report.js +42 -19
  37. package/dist/casts/share.d.ts +1 -1
  38. package/dist/casts/torrent.d.ts +5 -0
  39. package/dist/casts/torrent.js +8 -1
  40. package/dist/casts/trusted-assertions.d.ts +4 -2
  41. package/dist/casts/trusted-assertions.js +20 -19
  42. package/dist/casts/user-status.d.ts +33 -0
  43. package/dist/casts/user-status.js +69 -0
  44. package/dist/casts/user.d.ts +7 -0
  45. package/dist/casts/user.js +20 -1
  46. package/dist/factories/app-handler.d.ts +31 -0
  47. package/dist/factories/app-handler.js +50 -0
  48. package/dist/factories/app-recommendation.d.ts +21 -0
  49. package/dist/factories/app-recommendation.js +28 -0
  50. package/dist/factories/chat-message.d.ts +37 -0
  51. package/dist/factories/chat-message.js +56 -0
  52. package/dist/factories/comment.d.ts +8 -7
  53. package/dist/factories/comment.js +2 -2
  54. package/dist/factories/external-identities.d.ts +17 -0
  55. package/dist/factories/external-identities.js +28 -0
  56. package/dist/factories/forum-thread.d.ts +34 -0
  57. package/dist/factories/forum-thread.js +50 -0
  58. package/dist/factories/git-applied-status.d.ts +39 -0
  59. package/dist/factories/git-applied-status.js +53 -0
  60. package/dist/factories/git-closed-status.d.ts +18 -0
  61. package/dist/factories/git-closed-status.js +24 -0
  62. package/dist/factories/git-draft-status.d.ts +18 -0
  63. package/dist/factories/git-draft-status.js +24 -0
  64. package/dist/factories/git-issue.d.ts +19 -0
  65. package/dist/factories/git-issue.js +25 -0
  66. package/dist/factories/git-open-status.d.ts +18 -0
  67. package/dist/factories/git-open-status.js +22 -0
  68. package/dist/factories/git-patch.d.ts +59 -0
  69. package/dist/factories/git-patch.js +102 -0
  70. package/dist/factories/git-pull-request-update.d.ts +23 -0
  71. package/dist/factories/git-pull-request-update.js +33 -0
  72. package/dist/factories/git-pull-request.d.ts +39 -0
  73. package/dist/factories/git-pull-request.js +64 -0
  74. package/dist/factories/index.d.ts +23 -0
  75. package/dist/factories/index.js +23 -0
  76. package/dist/factories/internal/git-pull-request.d.ts +19 -0
  77. package/dist/factories/internal/git-pull-request.js +26 -0
  78. package/dist/factories/internal/git-status.d.ts +11 -0
  79. package/dist/factories/internal/git-status.js +12 -0
  80. package/dist/factories/internal/git-thread.d.ts +19 -0
  81. package/dist/factories/internal/git-thread.js +29 -0
  82. package/dist/factories/internal/napplet-manifest.d.ts +52 -0
  83. package/dist/factories/internal/napplet-manifest.js +85 -0
  84. package/dist/factories/internal/nsite-manifest.d.ts +45 -0
  85. package/dist/factories/internal/nsite-manifest.js +68 -0
  86. package/dist/factories/legacy-message.d.ts +2 -0
  87. package/dist/factories/legacy-message.js +9 -2
  88. package/dist/factories/named-napplet.d.ts +20 -0
  89. package/dist/factories/named-napplet.js +30 -0
  90. package/dist/factories/named-nsite.d.ts +28 -0
  91. package/dist/factories/named-nsite.js +53 -0
  92. package/dist/factories/napplet-snapshot.d.ts +18 -0
  93. package/dist/factories/napplet-snapshot.js +38 -0
  94. package/dist/factories/nostr-web-token.d.ts +39 -0
  95. package/dist/factories/nostr-web-token.js +95 -0
  96. package/dist/factories/nsite-snapshot.d.ts +18 -0
  97. package/dist/factories/nsite-snapshot.js +29 -0
  98. package/dist/factories/reaction.d.ts +3 -2
  99. package/dist/factories/report.d.ts +48 -0
  100. package/dist/factories/report.js +66 -0
  101. package/dist/factories/root-napplet.d.ts +18 -0
  102. package/dist/factories/root-napplet.js +24 -0
  103. package/dist/factories/root-nsite.d.ts +23 -0
  104. package/dist/factories/root-nsite.js +44 -0
  105. package/dist/factories/torrent.d.ts +24 -10
  106. package/dist/factories/torrent.js +48 -44
  107. package/dist/factories/trusted-provider-list.d.ts +23 -0
  108. package/dist/factories/trusted-provider-list.js +39 -0
  109. package/dist/factories/user-status.d.ts +26 -0
  110. package/dist/factories/user-status.js +52 -0
  111. package/dist/helpers/app-data.js +15 -7
  112. package/dist/helpers/app-handler.d.ts +43 -6
  113. package/dist/helpers/app-handler.js +53 -3
  114. package/dist/helpers/app-recommendation.d.ts +24 -0
  115. package/dist/helpers/app-recommendation.js +30 -0
  116. package/dist/helpers/bookmark.js +5 -2
  117. package/dist/helpers/comment.d.ts +11 -5
  118. package/dist/helpers/comment.js +7 -1
  119. package/dist/helpers/content.d.ts +3 -1
  120. package/dist/helpers/emoji-pack.js +11 -6
  121. package/dist/helpers/emoji.d.ts +2 -2
  122. package/dist/helpers/encrypted-content-cache.js +18 -1
  123. package/dist/helpers/external-id.d.ts +1 -0
  124. package/dist/helpers/external-id.js +21 -46
  125. package/dist/helpers/external-identities.d.ts +29 -0
  126. package/dist/helpers/external-identities.js +52 -0
  127. package/dist/helpers/file-metadata.js +5 -6
  128. package/dist/helpers/forum-thread.d.ts +10 -0
  129. package/dist/helpers/forum-thread.js +10 -0
  130. package/dist/helpers/gift-wrap.d.ts +40 -15
  131. package/dist/helpers/gift-wrap.js +110 -33
  132. package/dist/helpers/git-issue.d.ts +13 -0
  133. package/dist/helpers/git-issue.js +19 -0
  134. package/dist/helpers/git-patch.d.ts +41 -0
  135. package/dist/helpers/git-patch.js +73 -0
  136. package/dist/helpers/git-pull-request.d.ts +57 -0
  137. package/dist/helpers/git-pull-request.js +111 -0
  138. package/dist/helpers/git-repository.d.ts +4 -0
  139. package/dist/helpers/git-repository.js +16 -0
  140. package/dist/helpers/git-status.d.ts +44 -0
  141. package/dist/helpers/git-status.js +93 -0
  142. package/dist/helpers/git.d.ts +2 -0
  143. package/dist/helpers/git.js +4 -0
  144. package/dist/helpers/groups.d.ts +5 -2
  145. package/dist/helpers/groups.js +40 -18
  146. package/dist/helpers/hashtag.d.ts +4 -2
  147. package/dist/helpers/index.d.ts +11 -0
  148. package/dist/helpers/index.js +11 -0
  149. package/dist/helpers/lists.js +14 -2
  150. package/dist/helpers/lnurl.js +1 -1
  151. package/dist/helpers/mute.js +18 -7
  152. package/dist/helpers/napplet.d.ts +89 -0
  153. package/dist/helpers/napplet.js +144 -0
  154. package/dist/helpers/nostr-web-token.d.ts +54 -0
  155. package/dist/helpers/nostr-web-token.js +124 -0
  156. package/dist/helpers/nsite.d.ts +90 -0
  157. package/dist/helpers/nsite.js +217 -0
  158. package/dist/helpers/relay-discovery.d.ts +4 -0
  159. package/dist/helpers/relay-discovery.js +8 -0
  160. package/dist/helpers/reports.d.ts +35 -0
  161. package/dist/helpers/reports.js +36 -5
  162. package/dist/helpers/threading.d.ts +4 -2
  163. package/dist/helpers/torrent.d.ts +9 -6
  164. package/dist/helpers/torrent.js +23 -15
  165. package/dist/helpers/trusted-assertions.d.ts +7 -0
  166. package/dist/helpers/trusted-assertions.js +41 -2
  167. package/dist/helpers/user-status.d.ts +13 -1
  168. package/dist/helpers/user-status.js +15 -0
  169. package/dist/models/app-handler.d.ts +21 -0
  170. package/dist/models/app-handler.js +47 -0
  171. package/dist/models/git.d.ts +34 -0
  172. package/dist/models/git.js +144 -0
  173. package/dist/models/index.d.ts +3 -0
  174. package/dist/models/index.js +3 -0
  175. package/dist/models/nsite.d.ts +22 -0
  176. package/dist/models/nsite.js +67 -0
  177. package/dist/models/thread.d.ts +4 -1
  178. package/dist/models/thread.js +34 -5
  179. package/dist/models/user-status.d.ts +8 -4
  180. package/dist/models/user-status.js +16 -22
  181. package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
  182. package/dist/observable/filter-timeline-by-mutes.js +5 -1
  183. package/dist/operations/app-handler.d.ts +24 -0
  184. package/dist/operations/app-handler.js +58 -0
  185. package/dist/operations/app-recommendation.d.ts +13 -0
  186. package/dist/operations/app-recommendation.js +40 -0
  187. package/dist/operations/calendar-event.js +3 -2
  188. package/dist/operations/chat-message.d.ts +9 -0
  189. package/dist/operations/chat-message.js +12 -0
  190. package/dist/operations/client.d.ts +1 -4
  191. package/dist/operations/client.js +1 -23
  192. package/dist/operations/comment.d.ts +9 -3
  193. package/dist/operations/comment.js +12 -9
  194. package/dist/operations/external-identities.d.ts +8 -0
  195. package/dist/operations/external-identities.js +23 -0
  196. package/dist/operations/forum-thread.d.ts +3 -0
  197. package/dist/operations/forum-thread.js +6 -0
  198. package/dist/operations/gift-wrap.js +38 -14
  199. package/dist/operations/git-issue.d.ts +18 -0
  200. package/dist/operations/git-issue.js +31 -0
  201. package/dist/operations/git-patch.d.ts +30 -0
  202. package/dist/operations/git-patch.js +75 -0
  203. package/dist/operations/git-pull-request.d.ts +29 -0
  204. package/dist/operations/git-pull-request.js +74 -0
  205. package/dist/operations/git-repository.js +4 -4
  206. package/dist/operations/git-status.d.ts +28 -0
  207. package/dist/operations/git-status.js +116 -0
  208. package/dist/operations/git-thread.d.ts +13 -0
  209. package/dist/operations/git-thread.js +39 -0
  210. package/dist/operations/index.d.ts +16 -0
  211. package/dist/operations/index.js +16 -0
  212. package/dist/operations/internal/git-commits.d.ts +2 -0
  213. package/dist/operations/internal/git-commits.js +16 -0
  214. package/dist/operations/napplet.d.ts +51 -0
  215. package/dist/operations/napplet.js +121 -0
  216. package/dist/operations/nostr-web-token.d.ts +27 -0
  217. package/dist/operations/nostr-web-token.js +58 -0
  218. package/dist/operations/nsite.d.ts +51 -0
  219. package/dist/operations/nsite.js +112 -0
  220. package/dist/operations/reaction.d.ts +12 -2
  221. package/dist/operations/reaction.js +1 -1
  222. package/dist/operations/report.d.ts +33 -0
  223. package/dist/operations/report.js +60 -0
  224. package/dist/operations/stream.js +5 -4
  225. package/dist/operations/torrent.d.ts +1 -4
  226. package/dist/operations/torrent.js +24 -11
  227. package/dist/operations/trusted-providers.d.ts +14 -0
  228. package/dist/operations/trusted-providers.js +33 -0
  229. package/dist/operations/user-status.d.ts +11 -0
  230. package/dist/operations/user-status.js +29 -0
  231. package/package.json +10 -10
@@ -1,11 +1,16 @@
1
+ import { Report } from "./report.js";
2
+ import { REPORT_KIND, isValidReport } from "../helpers/reports.js";
3
+ import { map } from "rxjs";
1
4
  import { getEventPointerFromQTag, isQTag, kinds, processTags, } from "applesauce-core/helpers";
5
+ import { getClientTag } from "../helpers/app-handler.js";
2
6
  import { getNip10References } from "../helpers/threading.js";
3
7
  import { CommentsModel } from "../models/comments.js";
4
8
  import { ReactionsModel } from "../models/reactions.js";
5
9
  import { SharesModel } from "../models/shares.js";
6
10
  import { RepliesModel } from "../models/thread.js";
7
11
  import { EventZapsModel } from "../models/zaps.js";
8
- import { castTimelineStream } from "../observable/cast-stream.js";
12
+ import { castEventStream, castTimelineStream } from "../observable/cast-stream.js";
13
+ import { AppHandler } from "./app-handler.js";
9
14
  import { EventCast } from "./cast.js";
10
15
  import { Comment } from "./comment.js";
11
16
  import { Reaction } from "./reaction.js";
@@ -21,6 +26,10 @@ export class Note extends EventCast {
21
26
  throw new Error("Invalid note");
22
27
  super(event, store);
23
28
  }
29
+ /** Subscribes to reports referencing this event in the store */
30
+ get reports$() {
31
+ return this.$$ref("reports$", (store) => store.timeline({ kinds: [REPORT_KIND], "#e": [this.id] }).pipe(map((events) => events.filter(isValidReport)), castTimelineStream(Report, store)));
32
+ }
24
33
  get references() {
25
34
  return getNip10References(this.event);
26
35
  }
@@ -30,6 +39,17 @@ export class Note extends EventCast {
30
39
  get isRoot() {
31
40
  return !this.references.reply && !this.references.root;
32
41
  }
42
+ /** The NIP-89 client that published the note */
43
+ get client() {
44
+ return getClientTag(this.event);
45
+ }
46
+ /** Subscribes to the NIP-89 handler referenced by the note's client tag */
47
+ get client$() {
48
+ return this.$$ref("client$", (store) => {
49
+ const pointer = this.client?.pointer;
50
+ return pointer ? store.replaceable(pointer).pipe(castEventStream(AppHandler, store)) : of(undefined);
51
+ });
52
+ }
33
53
  /** An array of events that this note is quoting */
34
54
  get quotePointers() {
35
55
  return processTags(this.event.tags, (t) => (isQTag(t) ? t : undefined), (t) => getEventPointerFromQTag(t) ?? undefined);
@@ -0,0 +1,134 @@
1
+ import "./user.js";
2
+ import { ChainableObservable } from "applesauce-core";
3
+ import { NostrEvent } from "applesauce-core/helpers/event";
4
+ import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
5
+ import { Observable } from "rxjs";
6
+ import { NamedNsiteEvent, NsiteEvent, NsiteSnapshotEvent, RootNsiteEvent } from "../helpers/nsite.js";
7
+ import { CastRefEventStore, EventCast } from "./cast.js";
8
+ import { Comment } from "./comment.js";
9
+ import { Reaction } from "./reaction.js";
10
+ import { Share } from "./share.js";
11
+ import { Zap } from "./zap.js";
12
+ /** Cast for any NIP-5A nsite manifest (kinds 5128, 15128 and 35128) */
13
+ export declare class Nsite<T extends NsiteEvent = NsiteEvent> extends EventCast<T> {
14
+ /**
15
+ * Creates a cast for a validated manifest
16
+ * @throws if the event is not a valid manifest of this cast
17
+ */
18
+ constructor(event: NostrEvent, store: CastRefEventStore);
19
+ /** The valid file mappings */
20
+ get files(): import("../helpers/nsite.js").NsiteFile[];
21
+ /** The advertised aggregate hash */
22
+ get aggregateHash(): string | undefined;
23
+ /** The computed aggregate hash */
24
+ get computedAggregateHash(): string;
25
+ /** The site description */
26
+ get description(): string | undefined;
27
+ /** The site's display title */
28
+ get title(): string | undefined;
29
+ /** The Blossom server hints */
30
+ get servers(): string[];
31
+ /** The source repository or archive URL */
32
+ get source(): string | undefined;
33
+ /** The upstream app descriptor pointers */
34
+ get appPointers(): AddressPointer[];
35
+ /** The canonical DNS label on an nsite host */
36
+ get hostLabel(): string;
37
+ /**
38
+ * Returns the site's URL on an nsite host
39
+ * @throws if the host URL is invalid
40
+ */
41
+ url(host: string | URL): URL;
42
+ /** Resolves a request path with index and not-found fallbacks */
43
+ resolvePath(path: string): import("../helpers/nsite.js").NsiteFile | undefined;
44
+ /** Subscribes to manifest server hints followed by the author's Blossom servers */
45
+ get servers$(): ChainableObservable<URL[]>;
46
+ /** The immediate parent site's address */
47
+ get parentPointer(): AddressPointer | undefined;
48
+ /** The origin site address of the copy lineage */
49
+ get rootPointer(): AddressPointer | undefined;
50
+ /** Subscribes to the immediate parent site */
51
+ get parent$(): ChainableObservable<Nsite | undefined>;
52
+ /** Subscribes to the origin site of the copy lineage */
53
+ get root$(): ChainableObservable<Nsite | undefined>;
54
+ /** An alias for the immediate parent site */
55
+ get upstream$(): ChainableObservable<Nsite<NsiteEvent> | undefined>;
56
+ /** Whether this is a kind 5128 snapshot */
57
+ get isSnapshot(): boolean;
58
+ /** Whether this is a kind 15128 root nsite */
59
+ get isRoot(): boolean;
60
+ /** Whether this is a kind 35128 named nsite */
61
+ get isNamed(): boolean;
62
+ /** An address pointer for root and named nsites, or an event pointer for snapshots */
63
+ get pointer(): AddressPointer | EventPointer;
64
+ /** An observable of the pointer with relay hints from the authors outboxes */
65
+ get pointer$(): Observable<AddressPointer | EventPointer>;
66
+ /** The NIP-19 naddr, or nevent for snapshots */
67
+ get address(): string;
68
+ /** An observable of the NIP-19 address with relay hints from the authors outboxes */
69
+ get address$(): Observable<string>;
70
+ /** Subscribes to the NIP-22 comments on this nsite */
71
+ get comments$(): ChainableObservable<Comment[]>;
72
+ /** Subscribes to the reactions to this nsite */
73
+ get reactions$(): ChainableObservable<Reaction[]>;
74
+ /** Subscribes to the zaps of this nsite */
75
+ get zaps$(): ChainableObservable<Zap[]>;
76
+ /** Subscribes to the shares of this nsite */
77
+ get shares$(): ChainableObservable<Share[]>;
78
+ }
79
+ /** Base class for root and named nsites that snapshots can derive from */
80
+ declare class AddressableNsite<T extends RootNsiteEvent | NamedNsiteEvent> extends Nsite<T> {
81
+ /** The `kind:pubkey:identifier` address used by snapshot `a` and `A` tags */
82
+ get coordinate(): string;
83
+ /** Subscribes to snapshots of this site */
84
+ get snapshots$(): ChainableObservable<NsiteSnapshot[]>;
85
+ /** Subscribes to sites copied directly from this site */
86
+ get copies$(): ChainableObservable<Nsite[]>;
87
+ /** Subscribes to copied sites and snapshots whose lineage originates from this site */
88
+ get lineage$(): ChainableObservable<Nsite[]>;
89
+ }
90
+ /** Cast for a NIP-5A root nsite (kind 15128) */
91
+ export declare class RootNsite extends AddressableNsite<RootNsiteEvent> {
92
+ /**
93
+ * Creates a cast for a validated manifest
94
+ * @throws if the event is not a valid manifest of this cast
95
+ */
96
+ constructor(event: NostrEvent, store: CastRefEventStore);
97
+ }
98
+ /** Cast for a NIP-5A named nsite (kind 35128) */
99
+ export declare class NamedNsite extends AddressableNsite<NamedNsiteEvent> {
100
+ /**
101
+ * Creates a cast for a validated manifest
102
+ * @throws if the event is not a valid manifest of this cast
103
+ */
104
+ constructor(event: NostrEvent, store: CastRefEventStore);
105
+ /** The `d` tag identifier of the nsite */
106
+ get identifier(): string;
107
+ }
108
+ /** Cast for a NIP-5A nsite snapshot (kind 5128) */
109
+ export declare class NsiteSnapshot extends Nsite<NsiteSnapshotEvent> {
110
+ /**
111
+ * Creates a cast for a validated manifest
112
+ * @throws if the event is not a valid manifest of this cast
113
+ */
114
+ constructor(event: NostrEvent, store: CastRefEventStore);
115
+ }
116
+ declare module "applesauce-core/casts" {
117
+ interface User {
118
+ /** Subscribes to the user's root and named nsites */
119
+ get nsites$(): ChainableObservable<Nsite[]>;
120
+ /** Subscribes to the user's root (kind 15128) nsite */
121
+ get nsite$(): ChainableObservable<RootNsite | undefined>;
122
+ /** Subscribes to the user's nsite snapshots */
123
+ get nsiteSnapshots$(): ChainableObservable<NsiteSnapshot[]>;
124
+ }
125
+ }
126
+ declare module "./profile.js" {
127
+ interface Profile {
128
+ /** Subscribes to the author's root site */
129
+ get nsite$(): ChainableObservable<RootNsite | undefined>;
130
+ /** Subscribes to the author's root and named sites */
131
+ get nsites$(): ChainableObservable<Nsite[]>;
132
+ }
133
+ }
134
+ export {};
@@ -0,0 +1,249 @@
1
+ import "./user.js";
2
+ import { withImmediateValueOrDefault } from "applesauce-core";
3
+ import { User } from "applesauce-core/casts/user";
4
+ import { addRelayHintsToPointer, encodePointer, getAddressPointerForEvent, getEventPointerForEvent, } from "applesauce-core/helpers/pointers";
5
+ import { map, of } from "rxjs";
6
+ import { normalizeBlossomServer } from "../helpers/blossom.js";
7
+ import { NsiteCopiesModel, NsiteLineageModel, NsiteSnapshotsModel, RootNsiteModel, UserNsitesModel, UserNsiteSnapshotsModel, } from "../models/nsite.js";
8
+ import { Profile } from "./profile.js";
9
+ import { getNsiteFiles, getNsiteAggregateHash, getComputedNsiteAggregateHash, getNsiteAppPointers, getNsiteDescription, getNsiteIdentifier, getNsiteParentPointer, getNsiteRootPointer, getNsiteServers, getNsiteSource, getNsiteTitle, getNsiteHostLabel, getNsiteURL, resolveNsitePath, isNamedNsite, isNsiteSnapshot, isRootNsite, isValidNamedNsite, isValidNsite, isValidNsiteSnapshot, isValidRootNsite, } from "../helpers/nsite.js";
10
+ import { CommentsModel } from "../models/comments.js";
11
+ import { ReactionsModel } from "../models/reactions.js";
12
+ import { SharesModel } from "../models/shares.js";
13
+ import { EventZapsModel } from "../models/zaps.js";
14
+ import { castEventStream, castTimelineStream } from "../observable/cast-stream.js";
15
+ import { EventCast } from "./cast.js";
16
+ import { Comment } from "./comment.js";
17
+ import { Reaction } from "./reaction.js";
18
+ import { Share } from "./share.js";
19
+ import { Zap } from "./zap.js";
20
+ /** Cast for any NIP-5A nsite manifest (kinds 5128, 15128 and 35128) */
21
+ export class Nsite extends EventCast {
22
+ /**
23
+ * Creates a cast for a validated manifest
24
+ * @throws if the event is not a valid manifest of this cast
25
+ */
26
+ constructor(event, store) {
27
+ if (!isValidNsite(event))
28
+ throw new Error("Invalid nsite manifest");
29
+ super(event, store);
30
+ }
31
+ /** The valid file mappings */
32
+ get files() {
33
+ return getNsiteFiles(this.event);
34
+ }
35
+ /** The advertised aggregate hash */
36
+ get aggregateHash() {
37
+ return getNsiteAggregateHash(this.event);
38
+ }
39
+ /** The computed aggregate hash */
40
+ get computedAggregateHash() {
41
+ return getComputedNsiteAggregateHash(this.event);
42
+ }
43
+ /** The site description */
44
+ get description() {
45
+ return getNsiteDescription(this.event);
46
+ }
47
+ /** The site's display title */
48
+ get title() {
49
+ return getNsiteTitle(this.event);
50
+ }
51
+ /** The Blossom server hints */
52
+ get servers() {
53
+ return getNsiteServers(this.event);
54
+ }
55
+ /** The source repository or archive URL */
56
+ get source() {
57
+ return getNsiteSource(this.event);
58
+ }
59
+ /** The upstream app descriptor pointers */
60
+ get appPointers() {
61
+ return getNsiteAppPointers(this.event);
62
+ }
63
+ /** The canonical DNS label on an nsite host */
64
+ get hostLabel() {
65
+ return getNsiteHostLabel(this.event);
66
+ }
67
+ /**
68
+ * Returns the site's URL on an nsite host
69
+ * @throws if the host URL is invalid
70
+ */
71
+ url(host) {
72
+ return getNsiteURL(this.event, host);
73
+ }
74
+ /** Resolves a request path with index and not-found fallbacks */
75
+ resolvePath(path) {
76
+ return resolveNsitePath(this.event, path);
77
+ }
78
+ /** Subscribes to manifest server hints followed by the author's Blossom servers */
79
+ get servers$() {
80
+ return this.$$ref("servers$", () => this.author.blossomServers$.pipe(map((servers) => {
81
+ const hints = [];
82
+ for (const server of this.servers) {
83
+ try {
84
+ hints.push(normalizeBlossomServer(server));
85
+ }
86
+ catch { }
87
+ }
88
+ return [...new Map([...hints, ...(servers ?? [])].map((url) => [url.href, url])).values()];
89
+ })));
90
+ }
91
+ /** The immediate parent site's address */
92
+ get parentPointer() {
93
+ return getNsiteParentPointer(this.event);
94
+ }
95
+ /** The origin site address of the copy lineage */
96
+ get rootPointer() {
97
+ return getNsiteRootPointer(this.event);
98
+ }
99
+ /** Subscribes to the immediate parent site */
100
+ get parent$() {
101
+ return this.$$ref("parent$", (store) => this.parentPointer ? store.replaceable(this.parentPointer).pipe(castEventStream(Nsite, store)) : of(undefined));
102
+ }
103
+ /** Subscribes to the origin site of the copy lineage */
104
+ get root$() {
105
+ return this.$$ref("root$", (store) => this.rootPointer ? store.replaceable(this.rootPointer).pipe(castEventStream(Nsite, store)) : of(undefined));
106
+ }
107
+ /** An alias for the immediate parent site */
108
+ get upstream$() {
109
+ return this.parent$;
110
+ }
111
+ /** Whether this is a kind 5128 snapshot */
112
+ get isSnapshot() {
113
+ return isNsiteSnapshot(this.event);
114
+ }
115
+ /** Whether this is a kind 15128 root nsite */
116
+ get isRoot() {
117
+ return isRootNsite(this.event);
118
+ }
119
+ /** Whether this is a kind 35128 named nsite */
120
+ get isNamed() {
121
+ return isNamedNsite(this.event);
122
+ }
123
+ /** An address pointer for root and named nsites, or an event pointer for snapshots */
124
+ get pointer() {
125
+ return getAddressPointerForEvent(this.event) ?? getEventPointerForEvent(this.event);
126
+ }
127
+ /** An observable of the pointer with relay hints from the authors outboxes */
128
+ get pointer$() {
129
+ return this.author.outboxes$.pipe(withImmediateValueOrDefault(undefined), map((outboxes) => (outboxes ? addRelayHintsToPointer(this.pointer, outboxes.slice(0, 3)) : this.pointer)));
130
+ }
131
+ /** The NIP-19 naddr, or nevent for snapshots */
132
+ get address() {
133
+ return encodePointer(this.pointer);
134
+ }
135
+ /** An observable of the NIP-19 address with relay hints from the authors outboxes */
136
+ get address$() {
137
+ return this.pointer$.pipe(map((pointer) => encodePointer(pointer)));
138
+ }
139
+ /** Subscribes to the NIP-22 comments on this nsite */
140
+ get comments$() {
141
+ return this.$$ref("comments$", (store) => store.model(CommentsModel, this.event).pipe(castTimelineStream(Comment, store)));
142
+ }
143
+ /** Subscribes to the reactions to this nsite */
144
+ get reactions$() {
145
+ return this.$$ref("reactions$", (store) => store.model(ReactionsModel, this.event).pipe(castTimelineStream(Reaction, store)));
146
+ }
147
+ /** Subscribes to the zaps of this nsite */
148
+ get zaps$() {
149
+ return this.$$ref("zaps$", (store) => store.model(EventZapsModel, this.event).pipe(castTimelineStream(Zap, store)));
150
+ }
151
+ /** Subscribes to the shares of this nsite */
152
+ get shares$() {
153
+ return this.$$ref("shares$", (store) => store.model(SharesModel, this.event).pipe(castTimelineStream(Share, store)));
154
+ }
155
+ }
156
+ /** Base class for root and named nsites that snapshots can derive from */
157
+ class AddressableNsite extends Nsite {
158
+ /** The `kind:pubkey:identifier` address used by snapshot `a` and `A` tags */
159
+ get coordinate() {
160
+ return super.coordinate;
161
+ }
162
+ /** Subscribes to snapshots of this site */
163
+ get snapshots$() {
164
+ return this.$$ref("snapshots$", (store) => store.model(NsiteSnapshotsModel, this.event).pipe(castTimelineStream(NsiteSnapshot, store)));
165
+ }
166
+ /** Subscribes to sites copied directly from this site */
167
+ get copies$() {
168
+ return this.$$ref("copies$", (store) => store.model(NsiteCopiesModel, this.event).pipe(castTimelineStream(Nsite, store)));
169
+ }
170
+ /** Subscribes to copied sites and snapshots whose lineage originates from this site */
171
+ get lineage$() {
172
+ return this.$$ref("lineage$", (store) => store.model(NsiteLineageModel, this.event).pipe(castTimelineStream(Nsite, store)));
173
+ }
174
+ }
175
+ /** Cast for a NIP-5A root nsite (kind 15128) */
176
+ export class RootNsite extends AddressableNsite {
177
+ /**
178
+ * Creates a cast for a validated manifest
179
+ * @throws if the event is not a valid manifest of this cast
180
+ */
181
+ constructor(event, store) {
182
+ if (!isValidRootNsite(event))
183
+ throw new Error("Invalid root nsite");
184
+ super(event, store);
185
+ }
186
+ }
187
+ /** Cast for a NIP-5A named nsite (kind 35128) */
188
+ export class NamedNsite extends AddressableNsite {
189
+ /**
190
+ * Creates a cast for a validated manifest
191
+ * @throws if the event is not a valid manifest of this cast
192
+ */
193
+ constructor(event, store) {
194
+ if (!isValidNamedNsite(event))
195
+ throw new Error("Invalid named nsite");
196
+ super(event, store);
197
+ }
198
+ /** The `d` tag identifier of the nsite */
199
+ get identifier() {
200
+ return getNsiteIdentifier(this.event);
201
+ }
202
+ }
203
+ /** Cast for a NIP-5A nsite snapshot (kind 5128) */
204
+ export class NsiteSnapshot extends Nsite {
205
+ /**
206
+ * Creates a cast for a validated manifest
207
+ * @throws if the event is not a valid manifest of this cast
208
+ */
209
+ constructor(event, store) {
210
+ if (!isValidNsiteSnapshot(event))
211
+ throw new Error("Invalid nsite snapshot");
212
+ super(event, store);
213
+ }
214
+ }
215
+ Object.defineProperty(User.prototype, "nsites$", {
216
+ get() {
217
+ return this.$$ref("nsites$", (store) => store.model(UserNsitesModel, this.pubkey).pipe(castTimelineStream(Nsite, store)));
218
+ },
219
+ configurable: true,
220
+ enumerable: false,
221
+ });
222
+ Object.defineProperty(User.prototype, "nsite$", {
223
+ get() {
224
+ return this.$$ref("nsite$", (store) => store.model(RootNsiteModel, this.pointer).pipe(castEventStream(RootNsite, store)));
225
+ },
226
+ configurable: true,
227
+ enumerable: false,
228
+ });
229
+ Object.defineProperty(User.prototype, "nsiteSnapshots$", {
230
+ get() {
231
+ return this.$$ref("nsiteSnapshots$", (store) => store.model(UserNsiteSnapshotsModel, this.pubkey).pipe(castTimelineStream(NsiteSnapshot, store)));
232
+ },
233
+ configurable: true,
234
+ enumerable: false,
235
+ });
236
+ Object.defineProperty(Profile.prototype, "nsite$", {
237
+ get() {
238
+ return this.author.nsite$;
239
+ },
240
+ configurable: true,
241
+ enumerable: false,
242
+ });
243
+ Object.defineProperty(Profile.prototype, "nsites$", {
244
+ get() {
245
+ return this.author.nsites$;
246
+ },
247
+ configurable: true,
248
+ enumerable: false,
249
+ });
@@ -3,22 +3,42 @@ import { CastRefEventStore, EventCast } from "./cast.js";
3
3
  /** Cast a kind 0 event to a Profile */
4
4
  export declare class Profile extends EventCast<ProfileEvent> {
5
5
  constructor(event: NostrEvent, store: CastRefEventStore);
6
+ /** The parsed JSON content of the profile */
6
7
  get metadata(): import("applesauce-core/helpers").ProfileContent;
8
+ /** The nickname or full name of the user */
7
9
  get name(): string | undefined;
10
+ /** The display name with fallback to the name */
8
11
  get displayName(): string | undefined;
12
+ /** The short bio of the user */
9
13
  get about(): string | undefined;
14
+ /** The profile picture URL */
10
15
  get picture(): string | undefined;
16
+ /** The NIP-92 imeta metadata for the profile picture */
17
+ get pictureMetadata(): import("../helpers/file-metadata.js").FileMetadataFields | undefined;
18
+ /** The wide banner image URL */
11
19
  get banner(): string | undefined;
20
+ /** The NIP-92 imeta metadata for the banner image */
21
+ get bannerMetadata(): import("../helpers/file-metadata.js").FileMetadataFields | undefined;
22
+ /** The NIP-05 DNS identifier */
12
23
  get dnsIdentity(): string | undefined;
24
+ /** The website URL */
13
25
  get website(): string | undefined;
26
+ /** The LUD-16 lightning address */
14
27
  get lud16(): string | undefined;
28
+ /** The LUD-06 LNURL */
15
29
  get lud06(): string | undefined;
30
+ /** The LUD-16 lightning address with fallback to the LUD-06 LNURL */
16
31
  get lightningAddress(): string | undefined;
32
+ /** Whether the profile is automated */
17
33
  get bot(): boolean | undefined;
34
+ /** The birth date of the user, each field may be missing */
18
35
  get birthday(): {
19
36
  year?: number;
20
37
  month?: number;
21
38
  day?: number;
22
39
  } | undefined;
40
+ /** The preferred languages of the user in BCP 47 format */
23
41
  get languages(): string[] | undefined;
42
+ /** The lowercase hashtags from the NIP-24 "t" tags */
43
+ get hashtags(): string[];
24
44
  }
@@ -1,4 +1,6 @@
1
1
  import { getDisplayName, getProfileContent, getProfilePicture, isValidProfile } from "applesauce-core/helpers/profile";
2
+ import { isTTag } from "applesauce-core/helpers/tags";
3
+ import { getMediaAttachments } from "../helpers/file-metadata.js";
2
4
  import { EventCast } from "./cast.js";
3
5
  /** Cast a kind 0 event to a Profile */
4
6
  export class Profile extends EventCast {
@@ -7,46 +9,74 @@ export class Profile extends EventCast {
7
9
  throw new Error("Invalid profile");
8
10
  super(event, store);
9
11
  }
12
+ /** The parsed JSON content of the profile */
10
13
  get metadata() {
11
14
  return getProfileContent(this.event);
12
15
  }
16
+ /** The nickname or full name of the user */
13
17
  get name() {
14
18
  return this.metadata.name;
15
19
  }
20
+ /** The display name with fallback to the name */
16
21
  get displayName() {
17
22
  return getDisplayName(this.metadata);
18
23
  }
24
+ /** The short bio of the user */
19
25
  get about() {
20
26
  return this.metadata.about;
21
27
  }
28
+ /** The profile picture URL */
22
29
  get picture() {
23
30
  return getProfilePicture(this.metadata);
24
31
  }
32
+ /** The NIP-92 imeta metadata for the profile picture */
33
+ get pictureMetadata() {
34
+ const url = this.picture;
35
+ return url ? getMediaAttachments(this.event).find((m) => m.url === url) : undefined;
36
+ }
37
+ /** The wide banner image URL */
25
38
  get banner() {
26
39
  return this.metadata.banner;
27
40
  }
41
+ /** The NIP-92 imeta metadata for the banner image */
42
+ get bannerMetadata() {
43
+ const url = this.banner;
44
+ return url ? getMediaAttachments(this.event).find((m) => m.url === url) : undefined;
45
+ }
46
+ /** The NIP-05 DNS identifier */
28
47
  get dnsIdentity() {
29
48
  return this.metadata.nip05;
30
49
  }
50
+ /** The website URL */
31
51
  get website() {
32
52
  return this.metadata.website;
33
53
  }
54
+ /** The LUD-16 lightning address */
34
55
  get lud16() {
35
56
  return this.metadata.lud16;
36
57
  }
58
+ /** The LUD-06 LNURL */
37
59
  get lud06() {
38
60
  return this.metadata.lud06;
39
61
  }
62
+ /** The LUD-16 lightning address with fallback to the LUD-06 LNURL */
40
63
  get lightningAddress() {
41
64
  return this.metadata.lud16 || this.metadata.lud06;
42
65
  }
66
+ /** Whether the profile is automated */
43
67
  get bot() {
44
68
  return this.metadata.bot;
45
69
  }
70
+ /** The birth date of the user, each field may be missing */
46
71
  get birthday() {
47
72
  return this.metadata.birthday;
48
73
  }
74
+ /** The preferred languages of the user in BCP 47 format */
49
75
  get languages() {
50
76
  return this.metadata.languages;
51
77
  }
78
+ /** The lowercase hashtags from the NIP-24 "t" tags */
79
+ get hashtags() {
80
+ return this.event.tags.filter(isTTag).map((t) => t[1].toLowerCase());
81
+ }
52
82
  }
@@ -11,7 +11,7 @@ export declare class Reaction extends EventCast<KnownEvent<7>> {
11
11
  /** Get the address pointer for the event being reacted to (for replaceable events) */
12
12
  get addressPointer(): import("nostr-tools/nip19").AddressPointer | undefined;
13
13
  /** Get the pointer (event or address) for the event being reacted to */
14
- get reactedPointer(): import("nostr-tools/nip19").EventPointer | import("nostr-tools/nip19").AddressPointer | undefined;
14
+ get reactedPointer(): import("nostr-tools/nip19").AddressPointer | import("nostr-tools/nip19").EventPointer | undefined;
15
15
  /** Get the event that this reaction is reacting to */
16
16
  get reactedTo$(): import("applesauce-core").ChainableObservable<NostrEvent | undefined>;
17
17
  /** Alias for {@link reactedTo$} */
@@ -14,6 +14,8 @@ export declare class RelayDiscovery extends EventCast<RelayDiscoveryEvent> {
14
14
  get rttWrite(): number | undefined;
15
15
  /** Gets the network type from this discovery event (clearnet, tor, i2p, loki) */
16
16
  get networkType(): string | undefined;
17
+ /** Gets all relay types from this discovery event (from `T` tags) */
18
+ get types(): string[];
17
19
  /** Gets all relay attributes from this discovery event (from `W` tags) */
18
20
  get attributes(): string[];
19
21
  /** Gets all supported NIPs from this discovery event (from `N` tags) */
@@ -26,4 +28,6 @@ export declare class RelayDiscovery extends EventCast<RelayDiscoveryEvent> {
26
28
  get acceptedKinds(): string[];
27
29
  /** Gets the geohash from this discovery event (NIP-52 geohash) */
28
30
  get geohash(): string | undefined;
31
+ /** Gets all geohashes from this discovery event (from `g` tags) */
32
+ get geohashes(): string[];
29
33
  }
@@ -1,4 +1,4 @@
1
- import { getRelayDiscoveryAcceptedKinds, getRelayDiscoveryAttributes, getRelayDiscoveryGeohash, getRelayDiscoveryNetworkType, getRelayDiscoveryRequirements, getRelayDiscoveryRTT, getRelayDiscoverySupportedNIPs, getRelayDiscoveryTopics, getRelayDiscoveryURL, isValidRelayDiscovery, } from "../helpers/relay-discovery.js";
1
+ import { getRelayDiscoveryAcceptedKinds, getRelayDiscoveryAttributes, getRelayDiscoveryGeohash, getRelayDiscoveryGeohashes, getRelayDiscoveryNetworkType, getRelayDiscoveryRequirements, getRelayDiscoveryRTT, getRelayDiscoverySupportedNIPs, getRelayDiscoveryTopics, getRelayDiscoveryTypes, getRelayDiscoveryURL, isValidRelayDiscovery, } from "../helpers/relay-discovery.js";
2
2
  import { EventCast } from "./cast.js";
3
3
  /** Cast a kind 30166 event to a RelayDiscovery */
4
4
  export class RelayDiscovery extends EventCast {
@@ -27,6 +27,10 @@ export class RelayDiscovery extends EventCast {
27
27
  get networkType() {
28
28
  return getRelayDiscoveryNetworkType(this.event);
29
29
  }
30
+ /** Gets all relay types from this discovery event (from `T` tags) */
31
+ get types() {
32
+ return getRelayDiscoveryTypes(this.event);
33
+ }
30
34
  /** Gets all relay attributes from this discovery event (from `W` tags) */
31
35
  get attributes() {
32
36
  return getRelayDiscoveryAttributes(this.event);
@@ -51,4 +55,8 @@ export class RelayDiscovery extends EventCast {
51
55
  get geohash() {
52
56
  return getRelayDiscoveryGeohash(this.event);
53
57
  }
58
+ /** Gets all geohashes from this discovery event (from `g` tags) */
59
+ get geohashes() {
60
+ return getRelayDiscoveryGeohashes(this.event);
61
+ }
54
62
  }
@@ -1,31 +1,44 @@
1
1
  import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
- import { ReportReason, ReportedEvent, ReportedUser } from "../helpers/reports.js";
2
+ import { REPORT_KIND, ReportReason, ReportedEvent, ReportedUser } from "../helpers/reports.js";
3
3
  import { CastRefEventStore, EventCast } from "./cast.js";
4
- declare const REPORT_KIND = 1984;
5
- /** Cast a kind 1984 event to a Report */
4
+ import { EventPointer } from "applesauce-core/helpers";
5
+ /** A NIP-56 report with typed targets and related users and events */
6
6
  export declare class Report extends EventCast<KnownEvent<typeof REPORT_KIND>> {
7
+ /**
8
+ * Creates a report cast
9
+ * @throws if the event lacks valid report targets or context
10
+ */
7
11
  constructor(event: NostrEvent, store: CastRefEventStore);
8
- /** Get the parsed report data (either a user or event report) */
12
+ /** Returns every explicitly reported target with its reason */
13
+ get targets(): import("../helpers/reports.js").ReportTarget[];
14
+ /** Returns all explicitly reported users */
15
+ get reportedUsers(): import("applesauce-core/casts").User[];
16
+ /** Checks whether this report explicitly targets media */
17
+ get isBlobReport(): boolean;
18
+ /** Returns pointers to all reported events and blob context events */
19
+ get reportedEventPointers(): EventPointer[];
20
+ /** Subscribes to all reported events and blob context events */
21
+ get reportedEvents$(): import("applesauce-core").ChainableObservable<(NostrEvent | undefined)[]>;
22
+ /** Gets the parsed report data (either a user or event report) */
9
23
  get reported(): ReportedEvent | ReportedUser | null;
10
- /** Check if this is a user report */
24
+ /** Checks if this is a user report */
11
25
  get isUserReport(): boolean;
12
- /** Check if this is an event report */
26
+ /** Checks if this is an event report */
13
27
  get isEventReport(): boolean;
14
- /** Get the reason for the report */
28
+ /** Gets the reason for the report */
15
29
  get reason(): ReportReason | undefined;
16
- /** Get the comment/content of the report */
30
+ /** Gets the comment/content of the report */
17
31
  get comment(): string | undefined;
18
- /** Get the pubkey of the user being reported */
32
+ /** Gets the pubkey of the user being reported */
19
33
  get reportedPubkey(): string | undefined;
20
- /** Get the User being reported */
34
+ /** Gets the User being reported */
21
35
  get reportedUser(): import("applesauce-core/casts").User | undefined;
22
- /** Get the event ID being reported (for event reports) */
36
+ /** Gets the event ID being reported (for event reports) */
23
37
  get reportedEventId(): string | undefined;
24
- /** Get the event being reported (for event reports) */
38
+ /** Gets the event being reported (for event reports) */
25
39
  get reportedEvent$(): import("applesauce-core").ChainableObservable<NostrEvent | undefined>;
26
- /** Get the blob hashes being reported (for event reports with x tags) */
40
+ /** Gets the blob hashes being reported (for event reports with x tags) */
27
41
  get blobs(): string[] | undefined;
28
- /** Get the server URLs for blob reports */
42
+ /** Gets the server URLs for blob reports */
29
43
  get servers(): string[];
30
44
  }
31
- export {};