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,23 +1,27 @@
1
+ import { logger } from "applesauce-core";
1
2
  import { EventMemory } from "applesauce-core/event-store";
2
3
  import { safeParse } from "applesauce-core/helpers";
4
+ import { setCachedValue } from "applesauce-core/helpers/cache";
3
5
  import { getEncryptedContent, isEncryptedContentUnlocked, lockEncryptedContent, unlockEncryptedContent, } from "applesauce-core/helpers/encrypted-content";
4
- import { kinds, notifyEventUpdate, verifyWrappedEvent, } from "applesauce-core/helpers/event";
6
+ import { kinds, notifyEventUpdate, verifyRumor, verifyWrappedEvent, } from "applesauce-core/helpers/event";
7
+ // GiftWrapSymbol/SealSymbol/RumorSymbol are owned by applesauce-core (members of
8
+ // PRESERVE_EVENT_SYMBOLS) and re-exported here so existing common consumers keep resolving
9
+ // them; Symbol.for() registry identity is unchanged regardless of which module imports it.
10
+ import { GiftWrapSymbol, RumorSymbol, SealSymbol } from "applesauce-core/helpers/gift-wrap";
5
11
  /**
6
12
  * An internal event set to keep track of seals and rumors
7
13
  * This is intentionally isolated from the main applications event store so to prevent seals and rumors from being leaked
8
14
  */
9
15
  export const internalGiftWrapEvents = new EventMemory();
10
- /** Used to store a reference to the seal event on gift wraps (downstream) or the seal event on rumors (upstream[]) */
11
- export const SealSymbol = Symbol.for("seal");
12
- /** Used to store a reference to the rumor on seals (downstream) */
13
- export const RumorSymbol = Symbol.for("rumor");
14
- /** Used to store a reference to the parent gift wrap event on seals (upstream) */
15
- export const GiftWrapSymbol = Symbol.for("gift-wrap");
16
+ const log = logger.extend("GiftWrap");
17
+ export { GiftWrapSymbol, RumorSymbol, SealSymbol };
16
18
  /** Adds a parent reference to a seal or rumor */
17
19
  function addParentSealReference(rumor, seal) {
18
20
  const parents = Reflect.get(rumor, SealSymbol);
21
+ // Mutated in place across calls (the Set gains members over time), the same shape as
22
+ // applesauce-core's SeenRelaysSymbol — accumulated state (see cache.ts taxonomy), not a memo.
19
23
  if (!parents)
20
- Reflect.set(rumor, SealSymbol, new Set([seal]));
24
+ setCachedValue(rumor, SealSymbol, new Set([seal]));
21
25
  else
22
26
  parents.add(seal);
23
27
  }
@@ -40,6 +44,22 @@ export function isRumor(event) {
40
44
  typeof event.created_at === "number" &&
41
45
  event.created_at > 0);
42
46
  }
47
+ /**
48
+ * Checks that an event is a seal and that its id and signature are valid.
49
+ *
50
+ * The seal's signature is the ONLY authorship proof in a NIP-59 envelope — the gift wrap is
51
+ * signed by a throwaway key that says nothing about who wrote the message, and the rumor is
52
+ * unsigned by definition. Everything downstream that attributes a rumor to an author (notably
53
+ * getSealRumor's `rumor.pubkey !== seal.pubkey` binding) rests on this check having passed.
54
+ *
55
+ * Cheap to repeat: verifyWrappedEvent -> nostr-tools' verifyEvent memoises both outcomes on the
56
+ * event via `verifiedSymbol`, so calls after the first are a symbol read. That is what makes it
57
+ * affordable to re-assert this at every boundary a seal can enter through rather than trusting
58
+ * the caller to have checked.
59
+ */
60
+ export function isValidSeal(event) {
61
+ return event.kind === kinds.Seal && verifyWrappedEvent(event);
62
+ }
43
63
  export function getSealGiftWrap(seal) {
44
64
  return Reflect.get(seal, GiftWrapSymbol);
45
65
  }
@@ -48,7 +68,9 @@ export function getRumorSeals(rumor) {
48
68
  let set = Reflect.get(rumor, SealSymbol);
49
69
  if (!set) {
50
70
  set = new Set();
51
- Reflect.set(rumor, SealSymbol, set);
71
+ // Lazily initializes the same mutable Set addParentSealReference (line ~53) grows over
72
+ // time — accumulated state (see cache.ts taxonomy), not a memo.
73
+ setCachedValue(rumor, SealSymbol, set);
52
74
  }
53
75
  return Array.from(set);
54
76
  }
@@ -63,7 +85,13 @@ export function getRumorGiftWraps(rumor) {
63
85
  }
64
86
  return Array.from(giftWraps);
65
87
  }
66
- /** Checks if a seal event is locked and casts it to the {@link UnlockedSeal} type */
88
+ /**
89
+ * Checks if a seal event is locked and casts it to the {@link UnlockedSeal} type
90
+ *
91
+ * The presence test is only sound because getSealRumor never writes an `undefined` RumorSymbol
92
+ * — see the invariant documented there. If it did, this would narrow a seal that never yielded
93
+ * a rumor to UnlockedSeal.
94
+ */
67
95
  export function isSealUnlocked(seal) {
68
96
  return RumorSymbol in seal || (isEncryptedContentUnlocked(seal) === true && getSealRumor(seal) !== undefined);
69
97
  }
@@ -81,8 +109,13 @@ export function isGiftWrapUnlocked(gift) {
81
109
  return true;
82
110
  }
83
111
  export function getSealRumor(seal) {
84
- // Non seal events cant have rumors
85
- if (seal.kind !== kinds.Seal)
112
+ // Non seal events, and seals whose id/signature do not check out, cant have rumors. Seals
113
+ // reached via getGiftWrapSeal were already verified there, and the verdict is memoised, so
114
+ // this costs a symbol read on that path. It earns its place on the other one: getSealRumor
115
+ // and unlockSeal are exported and take any NostrEvent, so a consumer can hand in a seal that
116
+ // never passed through getGiftWrapSeal. Without this, the `rumor.pubkey !== seal.pubkey`
117
+ // check below would be comparing against an unverified `seal.pubkey` and would prove nothing.
118
+ if (!isValidSeal(seal))
86
119
  return undefined;
87
120
  // If unlocked return the rumor
88
121
  if (RumorSymbol in seal)
@@ -94,26 +127,50 @@ export function getSealRumor(seal) {
94
127
  return undefined;
95
128
  // Parse the content as a rumor event
96
129
  let rumor = safeParse(content);
97
- // Failed to parse rumor, save undefined and return undefined
98
- if (!rumor) {
99
- Reflect.set(seal, RumorSymbol, undefined);
130
+ // Failed to parse rumor — return WITHOUT caching anything.
131
+ //
132
+ // INVARIANT: RumorSymbol is only ever written with a real Rumor, never with `undefined`.
133
+ // Both readers below depend on it, because both test for presence rather than value:
134
+ // - isSealUnlocked's `RumorSymbol in seal` would report a seal that never yielded a rumor
135
+ // as unlocked, and narrow it to UnlockedSeal.
136
+ // - unlockSeal then returns `seal[RumorSymbol]` — `undefined` typed as `Rumor` — walking
137
+ // past its own `if (!rumor) throw` guard and handing the caller a value its signature
138
+ // says cannot exist.
139
+ // A negative memo would also be permanent: the seal could never be re-read even once its
140
+ // content became parseable.
141
+ if (!rumor)
142
+ return undefined;
143
+ // Reject mismatched ids before they can select or populate a cached rumor.
144
+ if (!verifyRumor(rumor)) {
145
+ log("Dropping rumor %s: id does not match its contents", rumor.id);
100
146
  return undefined;
101
147
  }
102
- // Check if the rumor event already exists in the internal event set
148
+ // Check if the rumor event already exists in the internal event set. Resolve the instance
149
+ // first but do NOT record it yet — the author check below has to run against whatever we are
150
+ // actually about to return, and a rejected rumor must not be left behind in the set.
103
151
  const existing = internalGiftWrapEvents.getEvent(rumor.id);
152
+ // Reuse the existing rumor instance
104
153
  if (existing)
105
- // Reuse the existing rumor instance
106
154
  rumor = existing;
107
- else
108
- // Add to the internal event set
155
+ // A rumor whose author does not match its seal proves nothing about authorship, so it is
156
+ // dropped. Returning undefined rather than throwing: this is sender-controlled input that any
157
+ // stranger can put in your inbox, and every caller reaches it from inside an RxJS pipe —
158
+ // WrappedMessagesModel maps getGiftWrapRumor over the WHOLE gift-wrap timeline. A throw there
159
+ // errors the observable, which is terminal, so one malformed wrap would permanently kill the
160
+ // user's entire message list rather than skipping one message. Those call sites already
161
+ // `.filter((e) => !!e)`, so undefined is the contract they were written for.
162
+ if (rumor.pubkey !== seal.pubkey) {
163
+ log("Dropping rumor %s: author does not match its seal %s", rumor.id, seal.id);
164
+ return undefined;
165
+ }
166
+ // Add to the internal event set, now that the rumor has been accepted
167
+ if (!existing)
109
168
  internalGiftWrapEvents.add(rumor);
110
- // Throw an error if the seal and rumor authors do not match
111
- if (rumor.pubkey !== seal.pubkey)
112
- throw new Error("Seal author does not match rumor author");
113
169
  // Save a reference to the parent seal event
114
170
  addParentSealReference(rumor, seal);
115
- // Cache the rumor event
116
- Reflect.set(seal, RumorSymbol, rumor);
171
+ // Cache the rumor event. Propagated by reference across duplicate seal events rather than
172
+ // by spread — accumulated state (see cache.ts taxonomy).
173
+ setCachedValue(seal, RumorSymbol, rumor);
117
174
  return rumor;
118
175
  }
119
176
  export function getGiftWrapSeal(gift) {
@@ -126,7 +183,19 @@ export function getGiftWrapSeal(gift) {
126
183
  if (!content)
127
184
  return undefined;
128
185
  // Parse seal as nostr event
129
- let seal = JSON.parse(content);
186
+ const parsed = safeParse(content);
187
+ if (!parsed)
188
+ return undefined;
189
+ // Verify BEFORE the seal is used for anything else, including as a lookup key. verifyEvent
190
+ // rejects unless the event hashes to its own `id`, so passing this is what makes `parsed.id`
191
+ // trustworthy. Checking after the lookup below would let a sender write any id they like into
192
+ // the seal JSON and be handed back a seal they never signed — no signature checked, and the
193
+ // wrap then caches a reference to it. This is the sole insertion point for seals into
194
+ // internalGiftWrapEvents (EventMemory.add does no verification of its own), so gating here is
195
+ // what makes that set a set of authenticated seals.
196
+ if (!isValidSeal(parsed))
197
+ return undefined;
198
+ let seal = parsed;
130
199
  // Check if the seal event already exists in the internal event set
131
200
  const existing = internalGiftWrapEvents.getEvent(seal.id);
132
201
  if (existing) {
@@ -134,15 +203,15 @@ export function getGiftWrapSeal(gift) {
134
203
  seal = existing;
135
204
  }
136
205
  else {
137
- // Verify the seal event
138
- verifyWrappedEvent(seal);
139
206
  // Add to the internal event set
140
207
  internalGiftWrapEvents.add(seal);
141
- // Set the reference to the parent gift wrap event (upstream)
142
- Reflect.set(seal, GiftWrapSymbol, gift);
208
+ // Set the reference to the parent gift wrap event (upstream). Propagated by reference
209
+ // across duplicate events, not by spread — accumulated state (see cache.ts taxonomy).
210
+ setCachedValue(seal, GiftWrapSymbol, gift);
143
211
  }
144
- // Save a reference to the seal on the gift wrap (downstream)
145
- Reflect.set(gift, SealSymbol, seal);
212
+ // Save a reference to the seal on the gift wrap (downstream). Propagated by reference
213
+ // across duplicate events, not by spread — accumulated state (see cache.ts taxonomy).
214
+ setCachedValue(gift, SealSymbol, seal);
146
215
  return seal;
147
216
  }
148
217
  export function getGiftWrapRumor(gift) {
@@ -153,7 +222,12 @@ export function getGiftWrapRumor(gift) {
153
222
  }
154
223
  /**
155
224
  * Unlocks a seal event and returns the rumor event
156
- * @throws {Error} If the author of the rumor event does not match the author of the seal
225
+ *
226
+ * Unlike the getters, this throws rather than returning undefined: it is an imperative operation
227
+ * on one caller-chosen event with a non-optional return type, not a read applied across a
228
+ * timeline, so there is no observable for a throw to tear down.
229
+ * @throws {Error} If the seal does not yield a usable rumor — including an invalid seal
230
+ * signature, unparseable content, or a rumor whose author does not match its seal
157
231
  */
158
232
  export async function unlockSeal(seal, signer) {
159
233
  // If already unlocked, return the rumor
@@ -170,7 +244,10 @@ export async function unlockSeal(seal, signer) {
170
244
  }
171
245
  /**
172
246
  * Unlocks and returns the unsigned seal event in a gift-wrap
173
- * @throws {Error} If the author of the rumor event does not match the author of the seal
247
+ *
248
+ * Throws for the same reason unlockSeal does — see the note there.
249
+ * @throws {Error} If the gift wrap does not yield a usable rumor — including an invalid seal
250
+ * signature, unparseable content, or a rumor whose author does not match its seal
174
251
  */
175
252
  export async function unlockGiftWrap(gift, signer) {
176
253
  // If already unlocked, return the rumor
@@ -0,0 +1,13 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ /** The NIP-34 issue event kind */
3
+ export declare const GIT_ISSUE_KIND = 1621;
4
+ /** A validated NIP-34 issue event */
5
+ export type GitIssueEvent = KnownEvent<typeof GIT_ISSUE_KIND>;
6
+ /** The cache key for issue labels */
7
+ export declare const GitIssueLabelsSymbol: unique symbol;
8
+ /** Checks if an event is a valid NIP-34 issue that references a repository */
9
+ export declare function isValidGitIssue(event?: NostrEvent): event is GitIssueEvent;
10
+ /** Returns the issue subject from the `subject` tag */
11
+ export declare function getGitIssueSubject(event: NostrEvent): string | undefined;
12
+ /** Returns the issue labels from the `t` tags */
13
+ export declare function getGitIssueLabels(event: NostrEvent): string[];
@@ -0,0 +1,19 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getTagValue } from "applesauce-core/helpers/event";
3
+ import { getGitRepositoryReference } from "./git-repository.js";
4
+ /** The NIP-34 issue event kind */
5
+ export const GIT_ISSUE_KIND = 1621;
6
+ /** The cache key for issue labels */
7
+ export const GitIssueLabelsSymbol = Symbol.for("git-issue-labels");
8
+ /** Checks if an event is a valid NIP-34 issue that references a repository */
9
+ export function isValidGitIssue(event) {
10
+ return !!event && event.kind === GIT_ISSUE_KIND && !!getGitRepositoryReference(event);
11
+ }
12
+ /** Returns the issue subject from the `subject` tag */
13
+ export function getGitIssueSubject(event) {
14
+ return getTagValue(event, "subject") || undefined;
15
+ }
16
+ /** Returns the issue labels from the `t` tags */
17
+ export function getGitIssueLabels(event) {
18
+ return getOrComputeCachedValue(event, GitIssueLabelsSymbol, () => event.tags.filter((t) => t[0] === "t" && t[1]).map((t) => t[1]));
19
+ }
@@ -0,0 +1,41 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { EventPointer } from "applesauce-core/helpers/pointers";
3
+ /** The NIP-34 patch event kind */
4
+ export declare const GIT_PATCH_KIND = 1617;
5
+ /** A validated NIP-34 patch event */
6
+ export type GitPatchEvent = KnownEvent<typeof GIT_PATCH_KIND>;
7
+ /** The cache key for patch subjects */
8
+ export declare const GitPatchSubjectSymbol: unique symbol;
9
+ /** The cache key for patch labels */
10
+ export declare const GitPatchLabelsSymbol: unique symbol;
11
+ /** Checks if an event is a valid NIP-34 patch that references a repository */
12
+ export declare function isValidGitPatch(event?: NostrEvent): event is GitPatchEvent;
13
+ /** Checks if a patch is the first patch in a series or revision */
14
+ export declare function isGitPatchRoot(event: NostrEvent): boolean;
15
+ /** Checks if a patch is the first patch of a revision to an earlier patch series */
16
+ export declare function isGitPatchRootRevision(event: NostrEvent): boolean;
17
+ /** Returns the patch subject from the `Subject:` header of the `git format-patch` content */
18
+ export declare function getGitPatchSubject(event: NostrEvent): string | undefined;
19
+ /** Returns the patch labels from the `t` tags, excluding the `root` and `root-revision` markers */
20
+ export declare function getGitPatchLabels(event: NostrEvent): string[];
21
+ /** Returns the commit id of the patch from the `commit` tag */
22
+ export declare function getGitPatchCommit(event: NostrEvent): string | undefined;
23
+ /** Returns the parent commit id of the patch from the `parent-commit` tag */
24
+ export declare function getGitPatchParentCommit(event: NostrEvent): string | undefined;
25
+ /** Returns the previous patch, or the original root for the first patch of a revision */
26
+ export declare function getGitPatchPreviousPointer(event: NostrEvent): EventPointer | undefined;
27
+ /** Returns the commit signature, including an empty string for unsigned commits */
28
+ export declare function getGitPatchCommitSignature(event: NostrEvent): string | undefined;
29
+ /** The committer metadata needed to reproduce a patch commit */
30
+ export interface GitPatchCommitter {
31
+ /** The committer name */
32
+ name: string;
33
+ /** The committer email */
34
+ email: string;
35
+ /** The commit timestamp in seconds */
36
+ timestamp: number;
37
+ /** The timezone offset in minutes */
38
+ timezoneOffset: number;
39
+ }
40
+ /** Returns the committer metadata when its timestamp and timezone are valid */
41
+ export declare function getGitPatchCommitter(event: NostrEvent): GitPatchCommitter | undefined;
@@ -0,0 +1,73 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getTagValue } from "applesauce-core/helpers/event";
3
+ import { getEventPointerFromETag } from "applesauce-core/helpers/pointers";
4
+ import { isHexKey } from "applesauce-core/helpers/string";
5
+ import { getGitRepositoryReference } from "./git-repository.js";
6
+ /** The NIP-34 patch event kind */
7
+ export const GIT_PATCH_KIND = 1617;
8
+ /** The cache key for patch subjects */
9
+ export const GitPatchSubjectSymbol = Symbol.for("git-patch-subject");
10
+ /** The cache key for patch labels */
11
+ export const GitPatchLabelsSymbol = Symbol.for("git-patch-labels");
12
+ /** Checks if an event is a valid NIP-34 patch that references a repository */
13
+ export function isValidGitPatch(event) {
14
+ return !!event && event.kind === GIT_PATCH_KIND && !!getGitRepositoryReference(event);
15
+ }
16
+ /** Checks if a patch is the first patch in a series or revision */
17
+ export function isGitPatchRoot(event) {
18
+ return event.tags.some((t) => t[0] === "t" && (t[1] === "root" || t[1] === "root-revision"));
19
+ }
20
+ /** Checks if a patch is the first patch of a revision to an earlier patch series */
21
+ export function isGitPatchRootRevision(event) {
22
+ return event.tags.some((t) => t[0] === "t" && t[1] === "root-revision");
23
+ }
24
+ /** Returns the patch subject from the `Subject:` header of the `git format-patch` content */
25
+ export function getGitPatchSubject(event) {
26
+ return getOrComputeCachedValue(event, GitPatchSubjectSymbol, () => {
27
+ // Subject headers can be folded onto multiple lines that start with whitespace
28
+ const match = event.content.match(/^Subject:[ \t]*((?:.*)(?:\r?\n[ \t]+.*)*)/m);
29
+ if (!match)
30
+ return undefined;
31
+ const subject = match[1]
32
+ .replace(/\r?\n[ \t]+/g, " ")
33
+ .replace(/^\[[^\]]*\]\s*/, "")
34
+ .trim();
35
+ return subject || undefined;
36
+ });
37
+ }
38
+ /** Returns the patch labels from the `t` tags, excluding the `root` and `root-revision` markers */
39
+ export function getGitPatchLabels(event) {
40
+ return getOrComputeCachedValue(event, GitPatchLabelsSymbol, () => event.tags.filter((t) => t[0] === "t" && t[1] && t[1] !== "root" && t[1] !== "root-revision").map((t) => t[1]));
41
+ }
42
+ /** Returns the commit id of the patch from the `commit` tag */
43
+ export function getGitPatchCommit(event) {
44
+ return getTagValue(event, "commit") || undefined;
45
+ }
46
+ /** Returns the parent commit id of the patch from the `parent-commit` tag */
47
+ export function getGitPatchParentCommit(event) {
48
+ return getTagValue(event, "parent-commit") || undefined;
49
+ }
50
+ /** Returns the previous patch, or the original root for the first patch of a revision */
51
+ export function getGitPatchPreviousPointer(event) {
52
+ const tag = event.tags.find((t) => t[0] === "e" && t[3] === "reply");
53
+ const pointer = tag && getEventPointerFromETag(tag);
54
+ if (!tag || !pointer)
55
+ return undefined;
56
+ if (tag[4] && isHexKey(tag[4]))
57
+ pointer.author = tag[4];
58
+ return pointer;
59
+ }
60
+ /** Returns the commit signature, including an empty string for unsigned commits */
61
+ export function getGitPatchCommitSignature(event) {
62
+ return getTagValue(event, "commit-pgp-sig");
63
+ }
64
+ /** Returns the committer metadata when its timestamp and timezone are valid */
65
+ export function getGitPatchCommitter(event) {
66
+ const tag = event.tags.find((t) => t[0] === "committer");
67
+ if (!tag || tag.length < 5 || !tag[3] || !tag[4])
68
+ return undefined;
69
+ const timestamp = Number(tag[3]), timezoneOffset = Number(tag[4]);
70
+ return Number.isSafeInteger(timestamp) && timestamp >= 0 && Number.isInteger(timezoneOffset)
71
+ ? { name: tag[1], email: tag[2], timestamp, timezoneOffset }
72
+ : undefined;
73
+ }
@@ -0,0 +1,57 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { EventPointer } from "applesauce-core/helpers/pointers";
3
+ /** The NIP-34 pull request event kind */
4
+ export declare const GIT_PULL_REQUEST_KIND = 1618;
5
+ /** The NIP-34 pull request update event kind */
6
+ export declare const GIT_PULL_REQUEST_UPDATE_KIND = 1619;
7
+ /** A validated NIP-34 pull request event */
8
+ export type GitPullRequestEvent = KnownEvent<typeof GIT_PULL_REQUEST_KIND>;
9
+ /** A validated NIP-34 pull request update event */
10
+ export type GitPullRequestUpdateEvent = KnownEvent<typeof GIT_PULL_REQUEST_UPDATE_KIND>;
11
+ /** The cache key for pull request labels */
12
+ export declare const GitPullRequestLabelsSymbol: unique symbol;
13
+ /** The cache key for pull request clone URLs */
14
+ export declare const GitPullRequestCloneUrlsSymbol: unique symbol;
15
+ /** Checks if an event is a valid NIP-34 pull request that references a repository */
16
+ export declare function isValidGitPullRequest(event?: NostrEvent): event is GitPullRequestEvent;
17
+ /** Returns the pull request subject from the `subject` tag */
18
+ export declare function getGitPullRequestSubject(event: NostrEvent): string | undefined;
19
+ /** Returns the pull request labels from the `t` tags */
20
+ export declare function getGitPullRequestLabels(event: NostrEvent): string[];
21
+ /** Returns the commit id of the pull request branch tip from the `c` tag */
22
+ export declare function getGitPullRequestTipCommit(event: NostrEvent): string | undefined;
23
+ /** Returns the clone URLs where the pull request commits can be fetched */
24
+ export declare function getGitPullRequestCloneUrls(event: NostrEvent): string[];
25
+ /** Returns the recommended branch name from the `branch-name` tag */
26
+ export declare function getGitPullRequestBranchName(event: NostrEvent): string | undefined;
27
+ /** Returns the most recent common ancestor with the target branch from the `merge-base` tag */
28
+ export declare function getGitPullRequestMergeBase(event: NostrEvent): string | undefined;
29
+ /** Checks if an event is a valid NIP-34 pull request update that points to a pull request */
30
+ export declare function isValidGitPullRequestUpdate(event?: NostrEvent): event is GitPullRequestUpdateEvent;
31
+ /** Returns the id of the pull request an update targets from the `E` tag */
32
+ export declare function getGitPullRequestUpdateTarget(event: NostrEvent): string | undefined;
33
+ /** Returns the author of the pull request targeted by an update */
34
+ export declare function getGitPullRequestUpdateAuthor(event: NostrEvent): string | undefined;
35
+ /** Returns the original patch a pull request revises */
36
+ export declare function getGitPullRequestPatchId(event: NostrEvent): string | undefined;
37
+ /** The fetch state of a pull request or its latest valid update */
38
+ export interface GitPullRequestState {
39
+ /** The event supplying this state */
40
+ event: GitPullRequestEvent | GitPullRequestUpdateEvent;
41
+ /** The proposed branch tip commit */
42
+ tipCommit: string;
43
+ /** The clone URLs containing the proposed commit */
44
+ cloneUrls: string[];
45
+ /** The common ancestor with the target branch, when declared */
46
+ mergeBase?: string;
47
+ }
48
+ /** Returns a coherent fetch state from a validated pull request or update */
49
+ export declare function getGitPullRequestState(event: GitPullRequestEvent | GitPullRequestUpdateEvent): GitPullRequestState;
50
+ /** Returns the updated branch tip commit id from the `c` tag */
51
+ export declare function getGitPullRequestUpdateTipCommit(event: NostrEvent): string | undefined;
52
+ /** Returns the updated clone URLs of a pull request update */
53
+ export declare function getGitPullRequestUpdateCloneUrls(event: NostrEvent): string[];
54
+ /** Returns the target pull request pointer with its relay and author hints */
55
+ export declare function getGitPullRequestUpdatePointer(event: NostrEvent): EventPointer | undefined;
56
+ /** Returns the original patch pointer with its relay hint */
57
+ export declare function getGitPullRequestPatchPointer(event: NostrEvent): EventPointer | undefined;
@@ -0,0 +1,111 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getTagValue } from "applesauce-core/helpers/event";
3
+ import { isHexKey } from "applesauce-core/helpers/string";
4
+ import { getEventPointerFromETag } from "applesauce-core/helpers/pointers";
5
+ import { isGitCommitId } from "./git.js";
6
+ import { getGitRepositoryReference } from "./git-repository.js";
7
+ /** The NIP-34 pull request event kind */
8
+ export const GIT_PULL_REQUEST_KIND = 1618;
9
+ /** The NIP-34 pull request update event kind */
10
+ export const GIT_PULL_REQUEST_UPDATE_KIND = 1619;
11
+ /** The cache key for pull request labels */
12
+ export const GitPullRequestLabelsSymbol = Symbol.for("git-pull-request-labels");
13
+ /** The cache key for pull request clone URLs */
14
+ export const GitPullRequestCloneUrlsSymbol = Symbol.for("git-pull-request-clone-urls");
15
+ function getCloneUrls(event) {
16
+ return getOrComputeCachedValue(event, GitPullRequestCloneUrlsSymbol, () => event.tags
17
+ .filter((t) => t[0] === "clone")
18
+ .flatMap((t) => t.slice(1))
19
+ .filter((url) => !!url.trim()));
20
+ }
21
+ /** Checks if an event is a valid NIP-34 pull request that references a repository */
22
+ export function isValidGitPullRequest(event) {
23
+ return (!!event &&
24
+ event.kind === GIT_PULL_REQUEST_KIND &&
25
+ !!getGitRepositoryReference(event) &&
26
+ isGitCommitId(getGitPullRequestTipCommit(event)) &&
27
+ getCloneUrls(event).length > 0 &&
28
+ (!getTagValue(event, "merge-base") || isGitCommitId(getTagValue(event, "merge-base"))));
29
+ }
30
+ /** Returns the pull request subject from the `subject` tag */
31
+ export function getGitPullRequestSubject(event) {
32
+ return getTagValue(event, "subject") || undefined;
33
+ }
34
+ /** Returns the pull request labels from the `t` tags */
35
+ export function getGitPullRequestLabels(event) {
36
+ return getOrComputeCachedValue(event, GitPullRequestLabelsSymbol, () => event.tags.filter((t) => t[0] === "t" && t[1]).map((t) => t[1]));
37
+ }
38
+ /** Returns the commit id of the pull request branch tip from the `c` tag */
39
+ export function getGitPullRequestTipCommit(event) {
40
+ return getTagValue(event, "c") || undefined;
41
+ }
42
+ /** Returns the clone URLs where the pull request commits can be fetched */
43
+ export function getGitPullRequestCloneUrls(event) {
44
+ return getCloneUrls(event);
45
+ }
46
+ /** Returns the recommended branch name from the `branch-name` tag */
47
+ export function getGitPullRequestBranchName(event) {
48
+ return getTagValue(event, "branch-name") || undefined;
49
+ }
50
+ /** Returns the most recent common ancestor with the target branch from the `merge-base` tag */
51
+ export function getGitPullRequestMergeBase(event) {
52
+ return getTagValue(event, "merge-base") || undefined;
53
+ }
54
+ /** Checks if an event is a valid NIP-34 pull request update that points to a pull request */
55
+ export function isValidGitPullRequestUpdate(event) {
56
+ return (!!event &&
57
+ event.kind === GIT_PULL_REQUEST_UPDATE_KIND &&
58
+ !!getGitPullRequestUpdateTarget(event) &&
59
+ !!getGitPullRequestUpdateAuthor(event) &&
60
+ isGitCommitId(getGitPullRequestUpdateTipCommit(event)) &&
61
+ getCloneUrls(event).length > 0 &&
62
+ (!getTagValue(event, "merge-base") || isGitCommitId(getTagValue(event, "merge-base"))));
63
+ }
64
+ /** Returns the id of the pull request an update targets from the `E` tag */
65
+ export function getGitPullRequestUpdateTarget(event) {
66
+ const id = getTagValue(event, "E");
67
+ return id && isHexKey(id) ? id : undefined;
68
+ }
69
+ /** Returns the author of the pull request targeted by an update */
70
+ export function getGitPullRequestUpdateAuthor(event) {
71
+ const pubkey = getTagValue(event, "P");
72
+ return pubkey && isHexKey(pubkey) ? pubkey : undefined;
73
+ }
74
+ /** Returns the original patch a pull request revises */
75
+ export function getGitPullRequestPatchId(event) {
76
+ const id = getTagValue(event, "e");
77
+ return id && isHexKey(id) ? id : undefined;
78
+ }
79
+ /** Returns a coherent fetch state from a validated pull request or update */
80
+ export function getGitPullRequestState(event) {
81
+ return {
82
+ event,
83
+ tipCommit: getTagValue(event, "c"),
84
+ cloneUrls: getCloneUrls(event),
85
+ mergeBase: getGitPullRequestMergeBase(event),
86
+ };
87
+ }
88
+ /** Returns the updated branch tip commit id from the `c` tag */
89
+ export function getGitPullRequestUpdateTipCommit(event) {
90
+ return getTagValue(event, "c") || undefined;
91
+ }
92
+ /** Returns the updated clone URLs of a pull request update */
93
+ export function getGitPullRequestUpdateCloneUrls(event) {
94
+ return getCloneUrls(event);
95
+ }
96
+ /** Returns the target pull request pointer with its relay and author hints */
97
+ export function getGitPullRequestUpdatePointer(event) {
98
+ const tag = event.tags.find((t) => t[0] === "E");
99
+ const pointer = tag && getEventPointerFromETag(tag);
100
+ if (!pointer)
101
+ return undefined;
102
+ const author = getGitPullRequestUpdateAuthor(event);
103
+ if (author)
104
+ pointer.author = author;
105
+ return pointer;
106
+ }
107
+ /** Returns the original patch pointer with its relay hint */
108
+ export function getGitPullRequestPatchPointer(event) {
109
+ const tag = event.tags.find((t) => t[0] === "e");
110
+ return (tag && getEventPointerFromETag(tag)) || undefined;
111
+ }
@@ -11,6 +11,8 @@ export declare const GitRepositoryRelaysSymbol: unique symbol;
11
11
  export declare const GitRepositoryMaintainersSymbol: unique symbol;
12
12
  export declare const GitRepositoryHashtagsSymbol: unique symbol;
13
13
  export declare const GitRepositoryUpstreamSymbol: unique symbol;
14
+ /** The cache key for repository references on thread events */
15
+ export declare const GitRepositoryReferenceSymbol: unique symbol;
14
16
  /** Checks if an event is a valid NIP-34 repository announcement. */
15
17
  export declare function isValidGitRepository(event?: NostrEvent): event is GitRepositoryEvent;
16
18
  /** Returns the repository identifier from the `d` tag. */
@@ -32,6 +34,8 @@ export declare function getGitRepositoryEarliestUniqueCommit(event?: NostrEvent)
32
34
  export declare function getGitRepositoryMaintainers(event?: NostrEvent): string[];
33
35
  /** Returns repository topic tags (NIP-34: values from each `["t", ...]` tag). */
34
36
  export declare function getGitRepositoryHashtags(event?: NostrEvent): string[];
37
+ /** Returns the repository pointer from the `a` tag of a NIP-34 issue, patch, pull request or status event */
38
+ export declare function getGitRepositoryReference(event: NostrEvent): GitRepositoryPointer | undefined;
35
39
  /**
36
40
  * Returns the upstream repository pointer (the repo this one was forked from), if declared.
37
41
  * Parsed from the `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
@@ -1,6 +1,7 @@
1
1
  import { isHexKey, relaySet } from "applesauce-core/helpers";
2
2
  import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
3
3
  import { getReplaceableIdentifier, getTagValue } from "applesauce-core/helpers/event";
4
+ import { getAddressPointerFromATag } from "applesauce-core/helpers/pointers";
4
5
  import { isSafeRelayURL } from "applesauce-core/helpers/relays";
5
6
  import { normalizeURL } from "applesauce-core/helpers/url";
6
7
  export const GIT_REPOSITORY_KIND = 30617;
@@ -10,6 +11,8 @@ export const GitRepositoryRelaysSymbol = Symbol.for("git-repository-relays");
10
11
  export const GitRepositoryMaintainersSymbol = Symbol.for("git-repository-maintainers");
11
12
  export const GitRepositoryHashtagsSymbol = Symbol.for("git-repository-hashtags");
12
13
  export const GitRepositoryUpstreamSymbol = Symbol.for("git-repository-upstream");
14
+ /** The cache key for repository references on thread events */
15
+ export const GitRepositoryReferenceSymbol = Symbol.for("git-repository-reference");
13
16
  function getTagValues(event, name) {
14
17
  return event.tags.filter((tag) => tag[0] === name && tag[1]).flatMap((tag) => tag.slice(1));
15
18
  }
@@ -73,6 +76,19 @@ export function getGitRepositoryHashtags(event) {
73
76
  return [];
74
77
  return getOrComputeCachedValue(event, GitRepositoryHashtagsSymbol, () => getTagValues(event, "t"));
75
78
  }
79
+ /** Returns the repository pointer from the `a` tag of a NIP-34 issue, patch, pull request or status event */
80
+ export function getGitRepositoryReference(event) {
81
+ return getOrComputeCachedValue(event, GitRepositoryReferenceSymbol, () => {
82
+ for (const tag of event.tags) {
83
+ if (tag[0] !== "a")
84
+ continue;
85
+ const pointer = getAddressPointerFromATag(tag);
86
+ if (pointer?.kind === GIT_REPOSITORY_KIND && pointer.identifier)
87
+ return pointer;
88
+ }
89
+ return undefined;
90
+ });
91
+ }
76
92
  /**
77
93
  * Returns the upstream repository pointer (the repo this one was forked from), if declared.
78
94
  * Parsed from the `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
@@ -0,0 +1,44 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ /** The NIP-34 open status event kind */
3
+ export declare const GIT_STATUS_OPEN_KIND = 1630;
4
+ /** The NIP-34 applied status event kind */
5
+ export declare const GIT_STATUS_APPLIED_KIND = 1631;
6
+ /** The NIP-34 closed status event kind */
7
+ export declare const GIT_STATUS_CLOSED_KIND = 1632;
8
+ /** The NIP-34 draft status event kind */
9
+ export declare const GIT_STATUS_DRAFT_KIND = 1633;
10
+ /** All NIP-34 status event kinds */
11
+ export declare const GIT_STATUS_KINDS: number[];
12
+ /** The status of a NIP-34 issue, patch or pull request. "applied" means merged for patches and resolved for issues */
13
+ export type GitStatus = "open" | "applied" | "closed" | "draft";
14
+ /** The event kinds used for NIP-34 statuses */
15
+ export type GitStatusKind = typeof GIT_STATUS_OPEN_KIND | typeof GIT_STATUS_APPLIED_KIND | typeof GIT_STATUS_CLOSED_KIND | typeof GIT_STATUS_DRAFT_KIND;
16
+ /** A validated NIP-34 status event */
17
+ export type GitStatusEvent = KnownEvent<GitStatusKind>;
18
+ /** Map of status types to event kinds */
19
+ export declare const GIT_STATUS_KIND_MAP: Record<GitStatus, GitStatusKind>;
20
+ /** Checks if an event is a valid NIP-34 status event with a root `e` tag */
21
+ export declare function isValidGitStatus(event?: NostrEvent): event is GitStatusEvent;
22
+ /** Returns the status type of a status event */
23
+ export declare function getGitStatusType(event: GitStatusEvent): GitStatus;
24
+ export declare function getGitStatusType(event: NostrEvent): GitStatus | undefined;
25
+ /** Returns the id of the issue, pull request or root patch a status event applies to */
26
+ export declare function getGitStatusRootId(event: NostrEvent): string | undefined;
27
+ /** Returns the ids of the patches applied or merged by a status event from the `q` tags */
28
+ export declare function getGitStatusAppliedPatchIds(event: NostrEvent): string[];
29
+ /** Returns the merge commit id from the `merge-commit` tag */
30
+ export declare function getGitStatusMergeCommit(event: NostrEvent): string | undefined;
31
+ /**
32
+ * Returns the latest status event from the root author or a maintainer
33
+ * @param maintainers Pubkeys allowed to set the status in addition to the root author
34
+ */
35
+ export declare function getGitCurrentStatusEvent(root: NostrEvent, statuses: NostrEvent[], maintainers?: string[]): GitStatusEvent | undefined;
36
+ /**
37
+ * Returns the current status of an issue, patch or pull request, defaulting to "open"
38
+ * @param maintainers Pubkeys allowed to set the status in addition to the root author
39
+ */
40
+ export declare function getGitCurrentStatus(root: NostrEvent, statuses: NostrEvent[], maintainers?: string[]): GitStatus;
41
+ /** Returns the accepted revision root id from the marked reply tag */
42
+ export declare function getGitStatusAcceptedRevisionId(event: NostrEvent): string | undefined;
43
+ /** Returns the commits produced by applying the patches */
44
+ export declare function getGitStatusAppliedCommits(event: NostrEvent): string[];