applesauce-common 6.2.0 → 7.1.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 (251) 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 +12 -0
  23. package/dist/casts/index.js +12 -0
  24. package/dist/casts/napplet-handlers.d.ts +39 -0
  25. package/dist/casts/napplet-handlers.js +91 -0
  26. package/dist/casts/napplet.d.ts +98 -0
  27. package/dist/casts/napplet.js +196 -0
  28. package/dist/casts/note.d.ts +8 -0
  29. package/dist/casts/note.js +21 -1
  30. package/dist/casts/nsite.d.ts +134 -0
  31. package/dist/casts/nsite.js +249 -0
  32. package/dist/casts/profile.d.ts +20 -0
  33. package/dist/casts/profile.js +30 -0
  34. package/dist/casts/reaction.d.ts +1 -1
  35. package/dist/casts/relay-discovery.d.ts +4 -0
  36. package/dist/casts/relay-discovery.js +9 -1
  37. package/dist/casts/report.d.ts +28 -15
  38. package/dist/casts/report.js +42 -19
  39. package/dist/casts/share.d.ts +1 -1
  40. package/dist/casts/torrent.d.ts +5 -0
  41. package/dist/casts/torrent.js +8 -1
  42. package/dist/casts/trusted-assertions.d.ts +2 -0
  43. package/dist/casts/trusted-assertions.js +19 -18
  44. package/dist/casts/user-status.d.ts +33 -0
  45. package/dist/casts/user-status.js +69 -0
  46. package/dist/casts/user.d.ts +7 -0
  47. package/dist/casts/user.js +20 -1
  48. package/dist/factories/app-handler.d.ts +31 -0
  49. package/dist/factories/app-handler.js +50 -0
  50. package/dist/factories/app-recommendation.d.ts +21 -0
  51. package/dist/factories/app-recommendation.js +28 -0
  52. package/dist/factories/chat-message.d.ts +37 -0
  53. package/dist/factories/chat-message.js +56 -0
  54. package/dist/factories/comment.d.ts +8 -7
  55. package/dist/factories/comment.js +2 -2
  56. package/dist/factories/external-identities.d.ts +17 -0
  57. package/dist/factories/external-identities.js +28 -0
  58. package/dist/factories/file-message.d.ts +24 -0
  59. package/dist/factories/file-message.js +37 -0
  60. package/dist/factories/forum-thread.d.ts +34 -0
  61. package/dist/factories/forum-thread.js +50 -0
  62. package/dist/factories/git-applied-status.d.ts +39 -0
  63. package/dist/factories/git-applied-status.js +53 -0
  64. package/dist/factories/git-closed-status.d.ts +18 -0
  65. package/dist/factories/git-closed-status.js +24 -0
  66. package/dist/factories/git-draft-status.d.ts +18 -0
  67. package/dist/factories/git-draft-status.js +24 -0
  68. package/dist/factories/git-issue.d.ts +19 -0
  69. package/dist/factories/git-issue.js +25 -0
  70. package/dist/factories/git-open-status.d.ts +18 -0
  71. package/dist/factories/git-open-status.js +22 -0
  72. package/dist/factories/git-patch.d.ts +59 -0
  73. package/dist/factories/git-patch.js +102 -0
  74. package/dist/factories/git-pull-request-update.d.ts +23 -0
  75. package/dist/factories/git-pull-request-update.js +33 -0
  76. package/dist/factories/git-pull-request.d.ts +39 -0
  77. package/dist/factories/git-pull-request.js +64 -0
  78. package/dist/factories/index.d.ts +24 -0
  79. package/dist/factories/index.js +24 -0
  80. package/dist/factories/internal/git-pull-request.d.ts +19 -0
  81. package/dist/factories/internal/git-pull-request.js +26 -0
  82. package/dist/factories/internal/git-status.d.ts +11 -0
  83. package/dist/factories/internal/git-status.js +12 -0
  84. package/dist/factories/internal/git-thread.d.ts +19 -0
  85. package/dist/factories/internal/git-thread.js +29 -0
  86. package/dist/factories/internal/napplet-manifest.d.ts +52 -0
  87. package/dist/factories/internal/napplet-manifest.js +85 -0
  88. package/dist/factories/internal/nsite-manifest.d.ts +45 -0
  89. package/dist/factories/internal/nsite-manifest.js +68 -0
  90. package/dist/factories/legacy-message.d.ts +2 -0
  91. package/dist/factories/legacy-message.js +9 -2
  92. package/dist/factories/named-napplet.d.ts +20 -0
  93. package/dist/factories/named-napplet.js +30 -0
  94. package/dist/factories/named-nsite.d.ts +28 -0
  95. package/dist/factories/named-nsite.js +53 -0
  96. package/dist/factories/napplet-handlers.d.ts +34 -0
  97. package/dist/factories/napplet-handlers.js +77 -0
  98. package/dist/factories/napplet-snapshot.d.ts +18 -0
  99. package/dist/factories/napplet-snapshot.js +38 -0
  100. package/dist/factories/nsite-snapshot.d.ts +18 -0
  101. package/dist/factories/nsite-snapshot.js +29 -0
  102. package/dist/factories/reaction.d.ts +3 -2
  103. package/dist/factories/report.d.ts +48 -0
  104. package/dist/factories/report.js +66 -0
  105. package/dist/factories/root-napplet.d.ts +18 -0
  106. package/dist/factories/root-napplet.js +24 -0
  107. package/dist/factories/root-nsite.d.ts +23 -0
  108. package/dist/factories/root-nsite.js +44 -0
  109. package/dist/factories/torrent.d.ts +24 -10
  110. package/dist/factories/torrent.js +48 -44
  111. package/dist/factories/trusted-provider-list.d.ts +23 -0
  112. package/dist/factories/trusted-provider-list.js +39 -0
  113. package/dist/factories/user-status.d.ts +26 -0
  114. package/dist/factories/user-status.js +52 -0
  115. package/dist/factories/wrapped-message.js +10 -4
  116. package/dist/helpers/app-data.js +15 -7
  117. package/dist/helpers/app-handler.d.ts +43 -6
  118. package/dist/helpers/app-handler.js +53 -3
  119. package/dist/helpers/app-recommendation.d.ts +24 -0
  120. package/dist/helpers/app-recommendation.js +30 -0
  121. package/dist/helpers/bookmark.js +5 -2
  122. package/dist/helpers/comment.d.ts +11 -5
  123. package/dist/helpers/comment.js +7 -1
  124. package/dist/helpers/content.d.ts +3 -1
  125. package/dist/helpers/emoji-pack.js +11 -6
  126. package/dist/helpers/emoji.d.ts +2 -2
  127. package/dist/helpers/encrypted-content-cache.d.ts +2 -11
  128. package/dist/helpers/encrypted-content-cache.js +6 -14
  129. package/dist/helpers/encrypted-file.d.ts +41 -0
  130. package/dist/helpers/encrypted-file.js +64 -0
  131. package/dist/helpers/external-id.js +13 -19
  132. package/dist/helpers/external-identities.d.ts +29 -0
  133. package/dist/helpers/external-identities.js +52 -0
  134. package/dist/helpers/file-message.d.ts +18 -0
  135. package/dist/helpers/file-message.js +44 -0
  136. package/dist/helpers/file-metadata.d.ts +9 -4
  137. package/dist/helpers/file-metadata.js +21 -6
  138. package/dist/helpers/forum-thread.d.ts +10 -0
  139. package/dist/helpers/forum-thread.js +10 -0
  140. package/dist/helpers/gift-wrap.d.ts +40 -15
  141. package/dist/helpers/gift-wrap.js +110 -33
  142. package/dist/helpers/git-issue.d.ts +13 -0
  143. package/dist/helpers/git-issue.js +19 -0
  144. package/dist/helpers/git-patch.d.ts +41 -0
  145. package/dist/helpers/git-patch.js +73 -0
  146. package/dist/helpers/git-pull-request.d.ts +57 -0
  147. package/dist/helpers/git-pull-request.js +111 -0
  148. package/dist/helpers/git-repository.d.ts +4 -0
  149. package/dist/helpers/git-repository.js +16 -0
  150. package/dist/helpers/git-status.d.ts +44 -0
  151. package/dist/helpers/git-status.js +93 -0
  152. package/dist/helpers/git.d.ts +2 -0
  153. package/dist/helpers/git.js +4 -0
  154. package/dist/helpers/groups.d.ts +5 -2
  155. package/dist/helpers/groups.js +40 -18
  156. package/dist/helpers/hashtag.d.ts +4 -2
  157. package/dist/helpers/index.d.ts +13 -0
  158. package/dist/helpers/index.js +13 -0
  159. package/dist/helpers/lists.js +14 -2
  160. package/dist/helpers/lnurl.js +1 -1
  161. package/dist/helpers/messages.js +3 -2
  162. package/dist/helpers/mute.js +20 -9
  163. package/dist/helpers/napplet-handlers.d.ts +79 -0
  164. package/dist/helpers/napplet-handlers.js +187 -0
  165. package/dist/helpers/napplet.d.ts +107 -0
  166. package/dist/helpers/napplet.js +177 -0
  167. package/dist/helpers/nsite.d.ts +90 -0
  168. package/dist/helpers/nsite.js +217 -0
  169. package/dist/helpers/relay-discovery.d.ts +4 -0
  170. package/dist/helpers/relay-discovery.js +8 -0
  171. package/dist/helpers/reports.d.ts +35 -0
  172. package/dist/helpers/reports.js +36 -5
  173. package/dist/helpers/threading.d.ts +4 -2
  174. package/dist/helpers/torrent.d.ts +9 -6
  175. package/dist/helpers/torrent.js +23 -15
  176. package/dist/helpers/trusted-assertions.d.ts +7 -0
  177. package/dist/helpers/trusted-assertions.js +41 -2
  178. package/dist/helpers/user-status.d.ts +13 -1
  179. package/dist/helpers/user-status.js +15 -0
  180. package/dist/helpers/wrapped-messages.d.ts +2 -0
  181. package/dist/helpers/wrapped-messages.js +6 -1
  182. package/dist/models/app-handler.d.ts +21 -0
  183. package/dist/models/app-handler.js +47 -0
  184. package/dist/models/git.d.ts +34 -0
  185. package/dist/models/git.js +144 -0
  186. package/dist/models/index.d.ts +4 -0
  187. package/dist/models/index.js +4 -0
  188. package/dist/models/legacy-messages.js +6 -1
  189. package/dist/models/napplet-handlers.d.ts +16 -0
  190. package/dist/models/napplet-handlers.js +45 -0
  191. package/dist/models/nsite.d.ts +22 -0
  192. package/dist/models/nsite.js +67 -0
  193. package/dist/models/thread.d.ts +4 -1
  194. package/dist/models/thread.js +34 -5
  195. package/dist/models/user-status.d.ts +8 -4
  196. package/dist/models/user-status.js +16 -22
  197. package/dist/models/wrapped-messages.js +9 -7
  198. package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
  199. package/dist/observable/filter-timeline-by-mutes.js +6 -2
  200. package/dist/operations/app-handler.d.ts +24 -0
  201. package/dist/operations/app-handler.js +58 -0
  202. package/dist/operations/app-recommendation.d.ts +13 -0
  203. package/dist/operations/app-recommendation.js +40 -0
  204. package/dist/operations/calendar-event.js +3 -2
  205. package/dist/operations/chat-message.d.ts +9 -0
  206. package/dist/operations/chat-message.js +12 -0
  207. package/dist/operations/client.d.ts +1 -4
  208. package/dist/operations/client.js +1 -23
  209. package/dist/operations/comment.d.ts +9 -3
  210. package/dist/operations/comment.js +12 -9
  211. package/dist/operations/external-identities.d.ts +8 -0
  212. package/dist/operations/external-identities.js +23 -0
  213. package/dist/operations/file-message.d.ts +7 -0
  214. package/dist/operations/file-message.js +34 -0
  215. package/dist/operations/forum-thread.d.ts +3 -0
  216. package/dist/operations/forum-thread.js +6 -0
  217. package/dist/operations/gift-wrap.js +38 -14
  218. package/dist/operations/git-issue.d.ts +18 -0
  219. package/dist/operations/git-issue.js +31 -0
  220. package/dist/operations/git-patch.d.ts +30 -0
  221. package/dist/operations/git-patch.js +75 -0
  222. package/dist/operations/git-pull-request.d.ts +29 -0
  223. package/dist/operations/git-pull-request.js +74 -0
  224. package/dist/operations/git-repository.js +4 -4
  225. package/dist/operations/git-status.d.ts +28 -0
  226. package/dist/operations/git-status.js +116 -0
  227. package/dist/operations/git-thread.d.ts +13 -0
  228. package/dist/operations/git-thread.js +39 -0
  229. package/dist/operations/index.d.ts +17 -0
  230. package/dist/operations/index.js +17 -0
  231. package/dist/operations/internal/git-commits.d.ts +2 -0
  232. package/dist/operations/internal/git-commits.js +16 -0
  233. package/dist/operations/napplet-handlers.d.ts +47 -0
  234. package/dist/operations/napplet-handlers.js +161 -0
  235. package/dist/operations/napplet.d.ts +51 -0
  236. package/dist/operations/napplet.js +121 -0
  237. package/dist/operations/nsite.d.ts +51 -0
  238. package/dist/operations/nsite.js +112 -0
  239. package/dist/operations/reaction.d.ts +12 -2
  240. package/dist/operations/reaction.js +1 -1
  241. package/dist/operations/report.d.ts +33 -0
  242. package/dist/operations/report.js +60 -0
  243. package/dist/operations/stream.js +5 -4
  244. package/dist/operations/torrent.d.ts +1 -4
  245. package/dist/operations/torrent.js +24 -11
  246. package/dist/operations/trusted-providers.d.ts +14 -0
  247. package/dist/operations/trusted-providers.js +33 -0
  248. package/dist/operations/user-status.d.ts +11 -0
  249. package/dist/operations/user-status.js +29 -0
  250. package/dist/operations/wrapped-message.js +2 -2
  251. package/package.json +13 -17
@@ -0,0 +1,196 @@
1
+ import { withImmediateValueOrDefault } from "applesauce-core";
2
+ import { User } from "applesauce-core/casts/user";
3
+ import { addRelayHintsToPointer, encodePointer, getAddressPointerForEvent, getEventPointerForEvent, } from "applesauce-core/helpers/pointers";
4
+ import { map, of } from "rxjs";
5
+ import { getNappletArchetypes, getNappletArtifactHash, getNappletDescription, getNappletIcon, getNappletIdentifier, getNappletIntents, getNappletOptionalDomains, getNappletParentPointer, getNappletRequiredDomains, getNappletRootPointer, getNappletServers, getNappletSource, getNappletTitle, isNamedNapplet, isNappletSnapshot, isRootNapplet, isValidNamedNapplet, isValidNapplet, isValidNappletSnapshot, isValidRootNapplet, NAPPLET_KIND, NAPPLET_ROOT_KIND, NAPPLET_SNAPSHOT_KIND, } from "../helpers/napplet.js";
6
+ import { CommentsModel } from "../models/comments.js";
7
+ import { ReactionsModel } from "../models/reactions.js";
8
+ import { SharesModel } from "../models/shares.js";
9
+ import { EventZapsModel } from "../models/zaps.js";
10
+ import { castEventStream, castTimelineStream } from "../observable/cast-stream.js";
11
+ import { EventCast } from "./cast.js";
12
+ import { Comment } from "./comment.js";
13
+ import { Reaction } from "./reaction.js";
14
+ import { Share } from "./share.js";
15
+ import { Zap } from "./zap.js";
16
+ /** Cast for any NIP-5D napplet manifest (kinds 5129, 15129 and 35129) */
17
+ export class Napplet extends EventCast {
18
+ constructor(event, store) {
19
+ if (!isValidNapplet(event))
20
+ throw new Error("Invalid napplet manifest");
21
+ super(event, store);
22
+ }
23
+ /** The sha256 of the napplet `index.html` artifact */
24
+ get artifactHash() {
25
+ return getNappletArtifactHash(this.event);
26
+ }
27
+ /** The plain-text description of the napplet */
28
+ get description() {
29
+ return getNappletDescription(this.event);
30
+ }
31
+ /** The short display label */
32
+ get title() {
33
+ return getNappletTitle(this.event);
34
+ }
35
+ /** The archetypes the napplet advertises */
36
+ get archetypes() {
37
+ return getNappletArchetypes(this.event);
38
+ }
39
+ /** The intents the napplet accepts */
40
+ get intents() {
41
+ return getNappletIntents(this.event);
42
+ }
43
+ /** The NAP domains required for full functionality */
44
+ get requiredDomains() {
45
+ return getNappletRequiredDomains(this.event);
46
+ }
47
+ /** The optional NAP domains */
48
+ get optionalDomains() {
49
+ return getNappletOptionalDomains(this.event);
50
+ }
51
+ /** The content-addressed icon, if valid */
52
+ get icon() {
53
+ return getNappletIcon(this.event);
54
+ }
55
+ /** The Blossom server hints for the artifact and icon blobs */
56
+ get servers() {
57
+ return getNappletServers(this.event);
58
+ }
59
+ /** The source URL */
60
+ get source() {
61
+ return getNappletSource(this.event);
62
+ }
63
+ /** Whether this is a kind 5129 snapshot */
64
+ get isSnapshot() {
65
+ return isNappletSnapshot(this.event);
66
+ }
67
+ /** Whether this is a kind 15129 root napplet */
68
+ get isRoot() {
69
+ return isRootNapplet(this.event);
70
+ }
71
+ /** Whether this is a kind 35129 named napplet */
72
+ get isNamed() {
73
+ return isNamedNapplet(this.event);
74
+ }
75
+ /** An address pointer for root and named napplets, or an event pointer for snapshots */
76
+ get pointer() {
77
+ return getAddressPointerForEvent(this.event) ?? getEventPointerForEvent(this.event);
78
+ }
79
+ /** An observable of the pointer with relay hints from the authors outboxes */
80
+ get pointer$() {
81
+ return this.author.outboxes$.pipe(withImmediateValueOrDefault(undefined), map((outboxes) => (outboxes ? addRelayHintsToPointer(this.pointer, outboxes.slice(0, 3)) : this.pointer)));
82
+ }
83
+ /** The NIP-19 naddr, or nevent for snapshots */
84
+ get address() {
85
+ return encodePointer(this.pointer);
86
+ }
87
+ /** An observable of the NIP-19 address with relay hints from the authors outboxes */
88
+ get address$() {
89
+ return this.pointer$.pipe(map((pointer) => encodePointer(pointer)));
90
+ }
91
+ /** Subscribes to the NIP-22 comments on this napplet */
92
+ get comments$() {
93
+ return this.$$ref("comments$", (store) => store.model(CommentsModel, this.event).pipe(castTimelineStream(Comment, store)));
94
+ }
95
+ /** Subscribes to the reactions to this napplet */
96
+ get reactions$() {
97
+ return this.$$ref("reactions$", (store) => store.model(ReactionsModel, this.event).pipe(castTimelineStream(Reaction, store)));
98
+ }
99
+ /** Subscribes to the zaps of this napplet */
100
+ get zaps$() {
101
+ return this.$$ref("zaps$", (store) => store.model(EventZapsModel, this.event).pipe(castTimelineStream(Zap, store)));
102
+ }
103
+ /** Subscribes to the shares of this napplet */
104
+ get shares$() {
105
+ return this.$$ref("shares$", (store) => store.model(SharesModel, this.event).pipe(castTimelineStream(Share, store)));
106
+ }
107
+ }
108
+ /** Base class for root and named napplets that snapshots can derive from */
109
+ class AddressableNapplet extends Napplet {
110
+ /** The `kind:pubkey:identifier` address used by snapshot `a` and `A` tags */
111
+ get coordinate() {
112
+ return super.coordinate;
113
+ }
114
+ /** Subscribes to the snapshots that derive directly from this napplet */
115
+ get snapshots$() {
116
+ return this.$$ref("snapshots$", (store) => store
117
+ .timeline({ kinds: [NAPPLET_SNAPSHOT_KIND], "#a": [this.coordinate] })
118
+ .pipe(castTimelineStream(NappletSnapshot, store)));
119
+ }
120
+ /** Subscribes to every snapshot whose lineage originates from this napplet */
121
+ get lineage$() {
122
+ return this.$$ref("lineage$", (store) => store
123
+ .timeline({ kinds: [NAPPLET_SNAPSHOT_KIND], "#A": [this.coordinate] })
124
+ .pipe(castTimelineStream(NappletSnapshot, store)));
125
+ }
126
+ }
127
+ /** Cast for a NIP-5D root napplet (kind 15129) */
128
+ export class RootNapplet extends AddressableNapplet {
129
+ constructor(event, store) {
130
+ if (!isValidRootNapplet(event))
131
+ throw new Error("Invalid root napplet");
132
+ super(event, store);
133
+ }
134
+ }
135
+ /** Cast for a NIP-5D named napplet (kind 35129) */
136
+ export class NamedNapplet extends AddressableNapplet {
137
+ constructor(event, store) {
138
+ if (!isValidNamedNapplet(event))
139
+ throw new Error("Invalid named napplet");
140
+ super(event, store);
141
+ }
142
+ /** The `d` tag identifier of the napplet */
143
+ get identifier() {
144
+ return getNappletIdentifier(this.event);
145
+ }
146
+ }
147
+ /** Cast for a NIP-5D napplet snapshot (kind 5129) */
148
+ export class NappletSnapshot extends Napplet {
149
+ constructor(event, store) {
150
+ if (!isValidNappletSnapshot(event))
151
+ throw new Error("Invalid napplet snapshot");
152
+ super(event, store);
153
+ }
154
+ /** The address of the napplet this snapshot derives from */
155
+ get parentPointer() {
156
+ return getNappletParentPointer(this.event);
157
+ }
158
+ /** The address of the root napplet this snapshot's lineage originates from */
159
+ get rootPointer() {
160
+ return getNappletRootPointer(this.event);
161
+ }
162
+ /** Subscribes to the napplet this snapshot derives from */
163
+ get parent$() {
164
+ return this.$$ref("parent$", (store) => {
165
+ const pointer = this.parentPointer;
166
+ return pointer ? store.replaceable(pointer).pipe(castEventStream(Napplet, store)) : of(undefined);
167
+ });
168
+ }
169
+ /** Alias for {@link parent$} */
170
+ get upstream$() {
171
+ return this.parent$;
172
+ }
173
+ /** Subscribes to the root napplet this snapshot's lineage originates from */
174
+ get root$() {
175
+ return this.$$ref("root$", (store) => {
176
+ const pointer = this.rootPointer;
177
+ return pointer ? store.replaceable(pointer).pipe(castEventStream(Napplet, store)) : of(undefined);
178
+ });
179
+ }
180
+ }
181
+ Object.defineProperty(User.prototype, "napplets$", {
182
+ get() {
183
+ return this.$$ref("napplets$", (store) => store
184
+ .timeline({ kinds: [NAPPLET_ROOT_KIND, NAPPLET_KIND], authors: [this.pubkey] })
185
+ .pipe(castTimelineStream(Napplet, store)));
186
+ },
187
+ configurable: true,
188
+ enumerable: false,
189
+ });
190
+ Object.defineProperty(User.prototype, "napplet$", {
191
+ get() {
192
+ return this.$$ref("napplet$", (store) => store.replaceable({ kind: NAPPLET_ROOT_KIND, pubkey: this.pubkey }).pipe(castEventStream(RootNapplet, store)));
193
+ },
194
+ configurable: true,
195
+ enumerable: false,
196
+ });
@@ -1,4 +1,6 @@
1
+ import { Report } from "./report.js";
1
2
  import { EventPointer, KnownEvent, NostrEvent } from "applesauce-core/helpers";
3
+ import { AppHandler } from "./app-handler.js";
2
4
  import { CastRefEventStore, EventCast } from "./cast.js";
3
5
  import { Comment } from "./comment.js";
4
6
  import { Reaction } from "./reaction.js";
@@ -6,9 +8,15 @@ import { Share } from "./share.js";
6
8
  import { Zap } from "./zap.js";
7
9
  export declare class Note extends EventCast<KnownEvent<1>> {
8
10
  constructor(event: NostrEvent, store: CastRefEventStore);
11
+ /** Subscribes to reports referencing this event in the store */
12
+ get reports$(): import("applesauce-core").ChainableObservable<Report[]>;
9
13
  get references(): import("../helpers/threading.js").ThreadReferences;
10
14
  get isReply(): boolean;
11
15
  get isRoot(): boolean;
16
+ /** The NIP-89 client that published the note */
17
+ get client(): import("../helpers/app-handler.js").ClientTag | undefined;
18
+ /** Subscribes to the NIP-89 handler referenced by the note's client tag */
19
+ get client$(): import("applesauce-core").ChainableObservable<AppHandler | undefined>;
12
20
  /** An array of events that this note is quoting */
13
21
  get quotePointers(): EventPointer[];
14
22
  /** Gets the NIP-10 root event */
@@ -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
+ });