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
@@ -1,32 +1,26 @@
1
- import { getReplaceableIdentifier, kinds } from "applesauce-core/helpers/event";
1
+ import { kinds } from "applesauce-core/helpers/event";
2
2
  import { map } from "rxjs";
3
- import { getUserStatusPointer } from "../helpers/user-status.js";
4
- /** A model that returns a parsed {@link UserStatus} for a certain type */
3
+ import { getUserStatusPointer, getUserStatusType, isUserStatusCleared, isValidUserStatus, } from "../helpers/user-status.js";
4
+ function parseUserStatus(event) {
5
+ return { ...getUserStatusPointer(event), event, content: event.content };
6
+ }
7
+ /** A model that returns a parsed {@link UserStatus} for a certain type, or undefined when missing or cleared */
5
8
  export function UserStatusModel(pubkey, type = "general") {
6
9
  return (events) => events.replaceable(kinds.UserStatuses, pubkey, type).pipe(map((event) => {
7
- if (!event)
10
+ if (!event || !isValidUserStatus(event) || isUserStatusCleared(event))
8
11
  return undefined;
9
- const pointer = getUserStatusPointer(event);
10
- if (!pointer)
11
- return null;
12
- return {
13
- ...pointer,
14
- event,
15
- content: event.content,
16
- };
12
+ return parseUserStatus(event);
17
13
  }));
18
14
  }
19
- /** A model that returns a directory of parsed {@link UserStatus} for a pubkey */
15
+ /** A model that returns a directory of parsed {@link UserStatus} for a pubkey, excluding cleared statuses */
20
16
  export function UserStatusesModel(pubkey) {
21
17
  return (events) => events.timeline([{ kinds: [kinds.UserStatuses], authors: [pubkey] }]).pipe(map((events) => {
22
- return events.reduce((dir, event) => {
23
- try {
24
- const d = getReplaceableIdentifier(event);
25
- return { ...dir, [d]: { event, ...getUserStatusPointer(event), content: event.content } };
26
- }
27
- catch (error) {
28
- return dir;
29
- }
30
- }, {});
18
+ const dir = {};
19
+ for (const event of events) {
20
+ if (!isValidUserStatus(event) || isUserStatusCleared(event))
21
+ continue;
22
+ dir[getUserStatusType(event)] = parseUserStatus(event);
23
+ }
24
+ return dir;
31
25
  }));
32
26
  }
@@ -3,7 +3,7 @@ import { kinds } from "applesauce-core/helpers/event";
3
3
  import { map } from "rxjs";
4
4
  import { getGiftWrapRumor } from "../helpers/gift-wrap.js";
5
5
  import { createConversationIdentifier, getConversationIdentifierFromMessage, getConversationParticipants, } from "../helpers/messages.js";
6
- import { getWrappedMessageParent } from "../helpers/wrapped-messages.js";
6
+ import { getWrappedMessageParent, isWrappedMessage } from "../helpers/wrapped-messages.js";
7
7
  /**
8
8
  * A model that returns all wrapped messages for a pubkey
9
9
  * @param self - The pubkey of the user
@@ -13,11 +13,13 @@ export function WrappedMessagesModel(self) {
13
13
  // Watch for updates to the gift wraps
14
14
  watchEventsUpdates(store),
15
15
  // Get rumors and filter out locked
16
- map((rumors) => rumors
17
- .map((gift) => getGiftWrapRumor(gift))
18
- .filter((e) => !!e)
19
- .filter((e) => e.kind === kinds.PrivateDirectMessage)
20
- .sort((a, b) => b.created_at - a.created_at)));
16
+ map((rumors) => [
17
+ ...new Map(rumors
18
+ .map((gift) => getGiftWrapRumor(gift))
19
+ .filter((e) => !!e)
20
+ .filter((e) => isWrappedMessage(e) && getConversationParticipants(e).includes(self))
21
+ .map((rumor) => [rumor.id, rumor])).values(),
22
+ ].sort((a, b) => b.created_at - a.created_at)));
21
23
  }
22
24
  /** A model that returns all conversations that a pubkey is participating in */
23
25
  export function WrappedMessagesGroups(self) {
@@ -45,7 +47,7 @@ export function WrappedMessagesGroup(self, participants) {
45
47
  const identifier = createConversationIdentifier(self, participants);
46
48
  return (store) => store.model(WrappedMessagesModel, self).pipe(
47
49
  // Only select direct messages for this conversation
48
- map((rumors) => rumors.filter((rumor) => rumor.kind === kinds.PrivateDirectMessage &&
50
+ map((rumors) => rumors.filter((rumor) => isWrappedMessage(rumor) &&
49
51
  // Only select message for this conversation (the identifier from the message will include "self")
50
52
  getConversationIdentifierFromMessage(rumor) === identifier)));
51
53
  }
@@ -3,4 +3,4 @@ import { NostrEvent } from "applesauce-core/helpers/event";
3
3
  import { ProfilePointer } from "applesauce-core/helpers/pointers";
4
4
  import { MonoTypeOperatorFunction } from "rxjs";
5
5
  /** Filters a timeline of events by a users mutes */
6
- export declare function filterTimelineByMutes<T extends NostrEvent>(eventStore: IEventModelMixin<IEventStore | IAsyncEventStore>, user: string | ProfilePointer): MonoTypeOperatorFunction<T[]>;
6
+ export declare function filterTimelineByMutes<T extends NostrEvent>(eventStore: IEventModelMixin<NostrEvent, IEventStore | IAsyncEventStore>, user: string | ProfilePointer): MonoTypeOperatorFunction<T[]>;
@@ -2,6 +2,10 @@ import { combineLatest, map } from "rxjs";
2
2
  import { matchMutes } from "../helpers/mute.js";
3
3
  import { MuteModel } from "../models/mutes.js";
4
4
  /** Filters a timeline of events by a users mutes */
5
- export function filterTimelineByMutes(eventStore, user) {
6
- return (source) => combineLatest([source, eventStore.model(MuteModel, user)]).pipe(map(([source, mutes]) => (mutes ? source.filter((event) => matchMutes(mutes, event)) : source)));
5
+ export function filterTimelineByMutes(
6
+ // Gate-driven fix (02-02): IEventModelMixin gained a required <E> parameter when the D-02/WR-02
7
+ // seam was closed in applesauce-core; MuteModel is NostrEvent-only, so E is pinned explicitly
8
+ // to restore the arity this bare 1-arg usage relied on.
9
+ eventStore, user) {
10
+ return (source) => combineLatest([source, eventStore.model(MuteModel, user)]).pipe(map(([source, mutes]) => (mutes ? source.filter((event) => !matchMutes(mutes, event)) : source)));
7
11
  }
@@ -0,0 +1,24 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { ProfileContent } from "applesauce-core/helpers/profile";
3
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
4
+ import { HandlerLinkPlatform, HandlerLinkType } from "../helpers/app-handler.js";
5
+ /** Sets the handler's kind:0-style metadata, or clears it to fall back to the author's profile */
6
+ export declare function setHandlerMetadata(metadata: ProfileContent | null): EventOperation;
7
+ /** Adds a supported event kind */
8
+ export declare function addHandlerKind(kind: number): EventOperation;
9
+ /** Removes a supported event kind */
10
+ export declare function removeHandlerKind(kind: number): EventOperation;
11
+ /** Sets the URL template for a platform and NIP-19 entity type, or the generic template when type is omitted */
12
+ export declare function setHandlerLink(platform: HandlerLinkPlatform, url: string, type?: HandlerLinkType): EventOperation;
13
+ /** Removes the URL template for a platform and NIP-19 entity type */
14
+ export declare function removeHandlerLink(platform: HandlerLinkPlatform, type?: HandlerLinkType): EventOperation;
15
+ /**
16
+ * Sets or removes the named nsite the handler currently serves
17
+ * @throws if the address is not a named nsite (kind 35128)
18
+ */
19
+ export declare function setHandlerLatest(site: AddressPointer | string | null): EventOperation;
20
+ /**
21
+ * Sets or removes the named nsite the handler is rolling out
22
+ * @throws if the address is not a named nsite (kind 35128)
23
+ */
24
+ export declare function setHandlerNext(site: AddressPointer | string | null): EventOperation;
@@ -0,0 +1,58 @@
1
+ import { getReplaceableAddressFromPointer, parseReplaceableAddress, } from "applesauce-core/helpers/pointers";
2
+ import { isSafeRelayURL } from "applesauce-core/helpers/relays";
3
+ import { normalizeURL } from "applesauce-core/helpers/url";
4
+ import { setContent } from "applesauce-core/operations/content";
5
+ import { addNameValueTag, removeNameValueTag } from "applesauce-core/operations/tag/common";
6
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
7
+ import { isNsiteAddressPointer, NSITE_KIND } from "../helpers/nsite.js";
8
+ function sameLink(t, platform, type) {
9
+ return t[0] === platform && (t[2] || undefined) === type;
10
+ }
11
+ function nsiteTag(name, site) {
12
+ let tag;
13
+ if (site !== null) {
14
+ const pointer = typeof site === "string" ? parseReplaceableAddress(site) : site;
15
+ if (!pointer || pointer.kind !== NSITE_KIND || !isNsiteAddressPointer(pointer))
16
+ throw new Error("Expected a named nsite address");
17
+ const relay = pointer.relays?.find(isSafeRelayURL);
18
+ tag = [name, getReplaceableAddressFromPointer(pointer), ...(relay ? [normalizeURL(relay)] : [])];
19
+ }
20
+ return modifyPublicTags((tags) => [...tags.filter((t) => t[0] !== name), ...(tag ? [tag] : [])]);
21
+ }
22
+ /** Sets the handler's kind:0-style metadata, or clears it to fall back to the author's profile */
23
+ export function setHandlerMetadata(metadata) {
24
+ return setContent(metadata ? JSON.stringify(metadata) : "");
25
+ }
26
+ /** Adds a supported event kind */
27
+ export function addHandlerKind(kind) {
28
+ return modifyPublicTags(addNameValueTag(["k", String(kind)]));
29
+ }
30
+ /** Removes a supported event kind */
31
+ export function removeHandlerKind(kind) {
32
+ return modifyPublicTags(removeNameValueTag(["k", String(kind)]));
33
+ }
34
+ /** Sets the URL template for a platform and NIP-19 entity type, or the generic template when type is omitted */
35
+ export function setHandlerLink(platform, url, type) {
36
+ return modifyPublicTags((tags) => [
37
+ ...tags.filter((t) => !sameLink(t, platform, type)),
38
+ type ? [platform, url, type] : [platform, url],
39
+ ]);
40
+ }
41
+ /** Removes the URL template for a platform and NIP-19 entity type */
42
+ export function removeHandlerLink(platform, type) {
43
+ return modifyPublicTags((tags) => tags.filter((t) => !sameLink(t, platform, type)));
44
+ }
45
+ /**
46
+ * Sets or removes the named nsite the handler currently serves
47
+ * @throws if the address is not a named nsite (kind 35128)
48
+ */
49
+ export function setHandlerLatest(site) {
50
+ return nsiteTag("latest", site);
51
+ }
52
+ /**
53
+ * Sets or removes the named nsite the handler is rolling out
54
+ * @throws if the address is not a named nsite (kind 35128)
55
+ */
56
+ export function setHandlerNext(site) {
57
+ return nsiteTag("next", site);
58
+ }
@@ -0,0 +1,13 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
3
+ import { HandlerLinkPlatform } from "../helpers/app-handler.js";
4
+ /**
5
+ * Adds or replaces a recommended handler for a platform
6
+ * @throws if the address is not a handler information event (kind 31990)
7
+ */
8
+ export declare function addRecommendedHandler(handler: AddressPointer | string, platform?: HandlerLinkPlatform): EventOperation;
9
+ /**
10
+ * Removes a recommended handler for every platform, one platform, or only the entry without a platform when `null`
11
+ * @throws if the address is not a handler information event (kind 31990)
12
+ */
13
+ export declare function removeRecommendedHandler(handler: AddressPointer | string, platform?: HandlerLinkPlatform | null): EventOperation;
@@ -0,0 +1,40 @@
1
+ import { getReplaceableAddressFromPointer, parseReplaceableAddress, } from "applesauce-core/helpers/pointers";
2
+ import { isSafeRelayURL } from "applesauce-core/helpers/relays";
3
+ import { normalizeURL } from "applesauce-core/helpers/url";
4
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
5
+ import { APP_HANDLER_KIND } from "../helpers/app-handler.js";
6
+ function handlerPointer(handler) {
7
+ const pointer = typeof handler === "string" ? parseReplaceableAddress(handler) : handler;
8
+ if (!pointer || pointer.kind !== APP_HANDLER_KIND)
9
+ throw new Error("Expected a NIP-89 handler address");
10
+ return pointer;
11
+ }
12
+ /**
13
+ * Adds or replaces a recommended handler for a platform
14
+ * @throws if the address is not a handler information event (kind 31990)
15
+ */
16
+ export function addRecommendedHandler(handler, platform) {
17
+ const pointer = handlerPointer(handler);
18
+ const address = getReplaceableAddressFromPointer(pointer);
19
+ const relay = pointer.relays?.find(isSafeRelayURL);
20
+ // The relay hint is positional, so keep an empty slot when only the platform is known
21
+ const tag = [
22
+ "a",
23
+ address,
24
+ ...(relay || platform ? [relay ? normalizeURL(relay) : ""] : []),
25
+ ...(platform ? [platform] : []),
26
+ ];
27
+ return modifyPublicTags((tags) => [
28
+ ...tags.filter((t) => !(t[0] === "a" && t[1] === address && t[3] === platform)),
29
+ tag,
30
+ ]);
31
+ }
32
+ /**
33
+ * Removes a recommended handler for every platform, one platform, or only the entry without a platform when `null`
34
+ * @throws if the address is not a handler information event (kind 31990)
35
+ */
36
+ export function removeRecommendedHandler(handler, platform) {
37
+ const address = getReplaceableAddressFromPointer(handlerPointer(handler));
38
+ const matches = (t) => (platform === undefined ? true : platform === null ? !t[3] : t[3] === platform);
39
+ return modifyPublicTags((tags) => tags.filter((t) => !(t[0] === "a" && t[1] === address && matches(t))));
40
+ }
@@ -1,3 +1,4 @@
1
+ import { serializeURL } from "applesauce-core/helpers/url";
1
2
  import { addNameValueTag, removeNameValueTag, setSingletonTag } from "applesauce-core/operations/tag/common";
2
3
  import { includeNameValueTag, includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
3
4
  import { createCalendarEventParticipantTag } from "../helpers/calendar-event.js";
@@ -32,11 +33,11 @@ export function removeLocation(location) {
32
33
  }
33
34
  /** Adds a location to a calendar event */
34
35
  export function addReferenceLink(link) {
35
- return modifyPublicTags(addNameValueTag(["r", new URL(link).toString()], true));
36
+ return modifyPublicTags(addNameValueTag(["r", serializeURL(link)], true));
36
37
  }
37
38
  /** Removes a location from a calendar event */
38
39
  export function removeReferenceLink(link) {
39
- return modifyPublicTags(removeNameValueTag(["r", new URL(link).toString()]));
40
+ return modifyPublicTags(removeNameValueTag(["r", serializeURL(link)]));
40
41
  }
41
42
  /** Removes all locations from a calendar event */
42
43
  export function clearLocations() {
@@ -0,0 +1,9 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { EventPointer } from "applesauce-core/helpers/pointers";
4
+ /**
5
+ * Adds a NIP-C7 `q` reply tag pointing at the parent chat message. A reply to a
6
+ * kind 9 is another kind 9 that quotes its parent with a `q` tag
7
+ * (`["q", <id>, <relay>, <pubkey>]`).
8
+ */
9
+ export declare function includeChatReply(parent: NostrEvent | EventPointer): EventOperation;
@@ -0,0 +1,12 @@
1
+ import { ensureQuoteEventPointerTag } from "applesauce-core/helpers/factory";
2
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
3
+ /**
4
+ * Adds a NIP-C7 `q` reply tag pointing at the parent chat message. A reply to a
5
+ * kind 9 is another kind 9 that quotes its parent with a `q` tag
6
+ * (`["q", <id>, <relay>, <pubkey>]`).
7
+ */
8
+ export function includeChatReply(parent) {
9
+ // Normalize a full event to an EventPointer (pubkey -> author)
10
+ const pointer = "pubkey" in parent ? { id: parent.id, author: parent.pubkey } : parent;
11
+ return modifyPublicTags((tags) => ensureQuoteEventPointerTag(tags, pointer));
12
+ }
@@ -1,4 +1 @@
1
- import { EventOperation } from "applesauce-core/factories";
2
- import { AddressPointer } from "applesauce-core/helpers/pointers";
3
- /** Includes a NIP-89 client tag in an event*/
4
- export declare function setClient(name: string, pointer?: Omit<AddressPointer, "kind" | "relays">, replace?: boolean): EventOperation;
1
+ export { setClient } from "applesauce-core/operations/client";
@@ -1,23 +1 @@
1
- import { kinds } from "applesauce-core/helpers/event";
2
- import { getReplaceableAddressFromPointer } from "applesauce-core/helpers/pointers";
3
- import { fillAndTrimTag } from "applesauce-core/helpers/tags";
4
- import { includeSingletonTag } from "applesauce-core/operations/tags";
5
- // A list of event kinds to never attach the "client" tag to
6
- const NEVER_ATTACH_CLIENT_TAG = [kinds.EncryptedDirectMessage, kinds.GiftWrap, kinds.Seal];
7
- /** Includes a NIP-89 client tag in an event*/
8
- export function setClient(name, pointer, replace = true) {
9
- return (draft) => {
10
- if (NEVER_ATTACH_CLIENT_TAG.includes(draft.kind))
11
- return draft;
12
- else {
13
- const coordinate = pointer
14
- ? getReplaceableAddressFromPointer({
15
- pubkey: pointer.pubkey,
16
- identifier: pointer.identifier,
17
- kind: kinds.Handlerinformation,
18
- })
19
- : undefined;
20
- return includeSingletonTag(fillAndTrimTag(["client", name, coordinate]), replace)(draft);
21
- }
22
- };
23
- }
1
+ export { setClient } from "applesauce-core/operations/client";
@@ -1,9 +1,15 @@
1
1
  import { EventOperation } from "applesauce-core/factories";
2
- import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { NostrEvent, Rumor } from "applesauce-core/helpers/event";
3
3
  import { CommentPointer } from "../helpers/comment.js";
4
+ /**
5
+ * The event a comment points to. A full event/rumor carries its tags (so a reply
6
+ * to another comment can inherit that comment's root pointer), or a
7
+ * {@link CommentPointer} for cases where only the identity is known.
8
+ */
9
+ export type CommentParent = NostrEvent | Rumor | CommentPointer;
4
10
  /**
5
11
  * Sets the necessary tags for a NIP-22 comment event to point to a parent event or pointer
6
- * @param parent - Parent event or comment pointer
12
+ * @param parent - Parent event, rumor, or comment pointer
7
13
  * @param getRelayHint - Optional function to get relay hint for event ID
8
14
  */
9
- export declare function setParent(parent: NostrEvent | CommentPointer, getRelayHint?: (eventId: string) => Promise<string | undefined>): EventOperation;
15
+ export declare function setParent(parent: CommentParent, getRelayHint?: (eventId: string) => Promise<string | undefined>): EventOperation;
@@ -1,15 +1,23 @@
1
- import { isEvent } from "applesauce-core/helpers/event";
2
1
  import { COMMENT_KIND, createCommentTagsForEvent, createCommentTagsFromCommentPointer, } from "../helpers/comment.js";
3
2
  /**
4
3
  * Sets the necessary tags for a NIP-22 comment event to point to a parent event or pointer
5
- * @param parent - Parent event or comment pointer
4
+ * @param parent - Parent event, rumor, or comment pointer
6
5
  * @param getRelayHint - Optional function to get relay hint for event ID
7
6
  */
8
7
  export function setParent(parent, getRelayHint) {
9
8
  return async (draft) => {
10
9
  let tags = Array.from(draft.tags);
11
- // If parent is a CommentPointer (not a NostrEvent), handle it directly
12
- if (!isEvent(parent)) {
10
+ // Only a full event or rumor carries tags; a pointer is just an identity.
11
+ // Discriminate on that rather than on the signature — an unsigned rumor
12
+ // (e.g. a NIP-59 seal's inner event) has everything needed to build tags.
13
+ if ("tags" in parent) {
14
+ const relayHint = getRelayHint ? await getRelayHint(parent.id) : undefined;
15
+ tags.push(...createCommentTagsForEvent(parent, relayHint));
16
+ }
17
+ else {
18
+ // A pointer to a comment carries no root tags, and NIP-22 requires nested
19
+ // replies to stay rooted on the original event — so the full comment
20
+ // event is the only thing correct root tags can be built from.
13
21
  if (parent.kind === COMMENT_KIND)
14
22
  throw new Error("Comment pointer cannot be a comment kind. please pass the full nip-22 comment event");
15
23
  // For CommentPointer, treat as root comment: both root and reply tags point to the same pointer
@@ -19,11 +27,6 @@ export function setParent(parent, getRelayHint) {
19
27
  // Add reply tags (lowercase)
20
28
  tags.push(...createCommentTagsFromCommentPointer(parent, false));
21
29
  }
22
- else {
23
- // If parent is a NostrEvent, use existing logic
24
- const relayHint = getRelayHint ? await getRelayHint(parent.id) : undefined;
25
- tags.push(...createCommentTagsForEvent(parent, relayHint));
26
- }
27
30
  return { ...draft, tags };
28
31
  };
29
32
  }
@@ -0,0 +1,8 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { ExternalIdentity } from "../helpers/external-identities.js";
3
+ /** Adds or replaces an external identity */
4
+ export declare function addExternalIdentity(identity: ExternalIdentity): EventOperation;
5
+ /** Removes an external identity */
6
+ export declare function removeExternalIdentity(platform: string, identity: string): EventOperation;
7
+ /** Replaces all external identities */
8
+ export declare function setExternalIdentities(identities: ExternalIdentity[]): EventOperation;
@@ -0,0 +1,23 @@
1
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
2
+ import { createExternalIdentityTag } from "../helpers/external-identities.js";
3
+ function isIdentityTag(tag, platform, identity) {
4
+ return tag[0] === "i" && tag[1] === `${platform}:${identity}`;
5
+ }
6
+ /** Adds or replaces an external identity */
7
+ export function addExternalIdentity(identity) {
8
+ return modifyPublicTags((tags) => [
9
+ ...tags.filter((tag) => !isIdentityTag(tag, identity.platform, identity.identity)),
10
+ createExternalIdentityTag(identity),
11
+ ]);
12
+ }
13
+ /** Removes an external identity */
14
+ export function removeExternalIdentity(platform, identity) {
15
+ return modifyPublicTags((tags) => tags.filter((tag) => !isIdentityTag(tag, platform, identity)));
16
+ }
17
+ /** Replaces all external identities */
18
+ export function setExternalIdentities(identities) {
19
+ return modifyPublicTags((tags) => [
20
+ ...tags.filter((tag) => tag[0] !== "i"),
21
+ ...identities.map(createExternalIdentityTag),
22
+ ]);
23
+ }
@@ -0,0 +1,7 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { FileMetadataFields } from "../helpers/file-metadata.js";
3
+ /**
4
+ * Sets the URL and file tags of a NIP-17 kind 15 file message
5
+ * @throws if the file has no URL
6
+ */
7
+ export declare function setFileMessage(file: FileMetadataFields): EventOperation;
@@ -0,0 +1,34 @@
1
+ import { eventPipe } from "applesauce-core/helpers/pipeline";
2
+ import { setContent } from "applesauce-core/operations/content";
3
+ import { addNameValueTag, removeSingletonTag, setSingletonTag } from "applesauce-core/operations/tag/common";
4
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
5
+ /** The kind 15 tags written for each file field, in NIP-17 order */
6
+ const FILE_MESSAGE_TAGS = [
7
+ ["file-type", "type"],
8
+ ["encryption-algorithm", "encryptionAlgorithm"],
9
+ ["decryption-key", "decryptionKey"],
10
+ ["decryption-nonce", "decryptionNonce"],
11
+ ["x", "sha256"],
12
+ ["ox", "originalSha256"],
13
+ ["size", "size"],
14
+ ["dim", "dimensions"],
15
+ ["blurhash", "blurhash"],
16
+ ["thumb", "thumbnail"],
17
+ ["alt", "alt"],
18
+ ];
19
+ /**
20
+ * Sets the URL and file tags of a NIP-17 kind 15 file message
21
+ * @throws if the file has no URL
22
+ */
23
+ export function setFileMessage(file) {
24
+ if (!file.url)
25
+ throw new Error("File message requires a URL");
26
+ const tagOperations = FILE_MESSAGE_TAGS.map(([name, field]) => {
27
+ const value = file[field];
28
+ if (value === undefined || value === "")
29
+ return removeSingletonTag(name);
30
+ return setSingletonTag([name, String(value)], true);
31
+ });
32
+ const fallbackOperations = (file.fallback ?? []).map((url) => addNameValueTag(["fallback", url]));
33
+ return eventPipe(setContent(file.url), modifyPublicTags(...tagOperations, ...fallbackOperations));
34
+ }
@@ -0,0 +1,3 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ /** Sets the NIP-7D `title` tag on a forum thread (kind 11) */
3
+ export declare function setTitle(title: string): EventOperation;
@@ -0,0 +1,6 @@
1
+ import { setSingletonTag } from "applesauce-core/operations/tag/common";
2
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
3
+ /** Sets the NIP-7D `title` tag on a forum thread (kind 11) */
4
+ export function setTitle(title) {
5
+ return modifyPublicTags(setSingletonTag(["title", title]));
6
+ }
@@ -1,19 +1,18 @@
1
1
  // Read https://github.com/nostr-protocol/nips/blob/master/59.md#overview for details on rumors and seals
2
2
  // Gift wrap (signed random key) -> seal (signed sender key) -> rumor (unsigned)
3
3
  import { blankEventTemplate } from "applesauce-core/factories";
4
+ import { setCachedValue } from "applesauce-core/helpers/cache";
4
5
  import { EncryptedContentSymbol } from "applesauce-core/helpers/encrypted-content";
5
6
  import { nip44 } from "applesauce-core/helpers/encryption";
6
7
  import { finalizeEvent, getEventHash, kinds, } from "applesauce-core/helpers/event";
7
8
  import { generateSecretKey } from "applesauce-core/helpers/keys";
8
- import { eventPipe, PRESERVE_EVENT_SYMBOLS } from "applesauce-core/helpers/pipeline";
9
+ import { eventPipe } from "applesauce-core/helpers/pipeline";
9
10
  import { unixNow } from "applesauce-core/helpers/time";
10
11
  import { setEncryptedContent } from "applesauce-core/operations/encrypted-content";
11
12
  import { setMetaTags, stamp } from "applesauce-core/operations/event";
12
13
  import { GiftWrapSymbol, RumorSymbol, SealSymbol } from "../helpers/gift-wrap.js";
13
- // Preserve gift-wrap and seal symbols when building gift-wrap events
14
- PRESERVE_EVENT_SYMBOLS.add(GiftWrapSymbol);
15
- PRESERVE_EVENT_SYMBOLS.add(SealSymbol);
16
- PRESERVE_EVENT_SYMBOLS.add(RumorSymbol);
14
+ // GiftWrapSymbol/SealSymbol/RumorSymbol are static members of applesauce-core's
15
+ // PRESERVE_EVENT_SYMBOLS (see core/helpers/pipeline.ts) — no import-time mutation needed here.
17
16
  /** Create a timestamp with a random offset of an hour */
18
17
  function randomNow() {
19
18
  return unixNow() - Math.floor(Math.random() * 60 * 60);
@@ -56,14 +55,23 @@ export function sealRumor(pubkey, signer) {
56
55
  // Stamp the seal with the signer's pubkey
57
56
  stamp(signer))({ ...blankEventTemplate(kinds.Seal), created_at: randomNow() });
58
57
  const seal = await signer.signEvent(unsigned);
59
- // Set the downstream reference on the seal
60
- Reflect.set(seal, RumorSymbol, rumor);
58
+ // Set the downstream reference on the seal: an object-reference link to `rumor`, not a
59
+ // value copy. `RumorSymbol` is a static member of `PRESERVE_EVENT_SYMBOLS` (applesauce-core),
60
+ // which stops `eventPipe`'s delete loop from scrubbing it mid-pipe — it is NOT carried onto a
61
+ // redelivered duplicate of this event by `EventStore.copySymbolsToDuplicateEvent`'s merge
62
+ // list, which has no gift-wrap symbols — accumulated state (see cache.ts one-rule doc block).
63
+ // Written non-enumerable via setCachedValue so a plain spread drops it instead of silently
64
+ // carrying a stale reference forward.
65
+ setCachedValue(seal, RumorSymbol, rumor);
61
66
  // Add the upstream reference to the rumor
62
67
  const seals = Reflect.get(rumor, SealSymbol);
63
68
  if (seals)
64
69
  seals.add(seal);
70
+ // Initializes the mutable Set that grows in place elsewhere (helpers/gift-wrap.ts's
71
+ // addParentSealReference) — accumulated state (see cache.ts one-rule doc block), not a memo.
72
+ // Written non-enumerable via setCachedValue.
65
73
  else
66
- Reflect.set(rumor, SealSymbol, new Set([seal]));
74
+ setCachedValue(rumor, SealSymbol, new Set([seal]));
67
75
  return seal;
68
76
  };
69
77
  }
@@ -81,12 +89,28 @@ export function wrapSeal(pubkey, opts) {
81
89
  tags: [["p", pubkey]],
82
90
  });
83
91
  const gift = finalizeEvent(draft, key);
84
- // Set the upstream references on the seal
85
- Reflect.set(seal, GiftWrapSymbol, gift);
86
- // Set the downstream reference on the gift wrap
87
- Reflect.set(gift, SealSymbol, seal);
88
- // Set the encrypted content on the gift wrap
89
- Reflect.set(gift, EncryptedContentSymbol, plaintext);
92
+ // Set the upstream reference on the seal: an object-reference link to `gift`, not a
93
+ // value copy. `GiftWrapSymbol` is a static member of `PRESERVE_EVENT_SYMBOLS` (applesauce-core),
94
+ // which stops `eventPipe`'s delete loop from scrubbing it mid-pipe — it is NOT carried onto a
95
+ // redelivered duplicate of this event by `EventStore.copySymbolsToDuplicateEvent`'s merge
96
+ // list, which has no gift-wrap symbols — accumulated state (see cache.ts one-rule doc block).
97
+ // Written non-enumerable via setCachedValue.
98
+ setCachedValue(seal, GiftWrapSymbol, gift);
99
+ // Set the downstream reference on the gift wrap: an object-reference link to `seal`, not
100
+ // a value copy. `SealSymbol`'s static membership in `PRESERVE_EVENT_SYMBOLS` (applesauce-core)
101
+ // buys survival of `eventPipe`'s delete loop, nothing more — it is NOT carried onto a
102
+ // redelivered duplicate of this event by that merge list, which has no gift-wrap symbols
103
+ // — accumulated state (see cache.ts one-rule doc block). Written non-enumerable via
104
+ // setCachedValue.
105
+ setCachedValue(gift, SealSymbol, seal);
106
+ // Set the encrypted content on the gift wrap: a build-path write, like applesauce-core's
107
+ // operations/tags.ts's modifyHiddenTags return and operations/encrypted-content.ts's
108
+ // setEncryptedContent return. `wrapSeal` is the last step of the `giftWrap` eventPipe, so this
109
+ // write survives because PRESERVE_EVENT_SYMBOLS keeps it through the delete loop that runs
110
+ // immediately after this operation — it is set directly on this operation's own returned
111
+ // event (`gift`), not inherited from a prior step's carry-forward. Written non-enumerable via
112
+ // setCachedValue (see cache.ts one-rule doc block).
113
+ setCachedValue(gift, EncryptedContentSymbol, plaintext);
90
114
  return gift;
91
115
  };
92
116
  }
@@ -0,0 +1,18 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { NostrEvent } from "applesauce-core/helpers/event";
3
+ import { GitRepositoryPointer } from "../helpers/git-repository.js";
4
+ /** Returns the `a`, `p` and `r` tags that link an event to a repository */
5
+ export { createGitRepositoryTags } from "./git-thread.js";
6
+ /**
7
+ * Sets the repository an issue belongs to
8
+ * @throws if the event or pointer is not a valid repository
9
+ */
10
+ export declare function setGitIssueRepository(repo: GitRepositoryPointer | NostrEvent): EventOperation;
11
+ /** Sets or removes the issue subject */
12
+ export declare function setGitIssueSubject(subject: string | null): EventOperation;
13
+ /** Adds a label `t` tag */
14
+ export declare function addGitIssueLabel(label: string): EventOperation;
15
+ /** Removes a label `t` tag */
16
+ export declare function removeGitIssueLabel(label: string): EventOperation;
17
+ /** Replaces all label `t` tags */
18
+ export declare function setGitIssueLabels(labels: string[]): EventOperation;
@@ -0,0 +1,31 @@
1
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
2
+ import { removeSingletonTag, setSingletonTag } from "applesauce-core/operations/tag/common";
3
+ import { setGitThreadRepository } from "./git-thread.js";
4
+ /** Returns the `a`, `p` and `r` tags that link an event to a repository */
5
+ export { createGitRepositoryTags } from "./git-thread.js";
6
+ /**
7
+ * Sets the repository an issue belongs to
8
+ * @throws if the event or pointer is not a valid repository
9
+ */
10
+ export function setGitIssueRepository(repo) {
11
+ return setGitThreadRepository(repo);
12
+ }
13
+ /** Sets or removes the issue subject */
14
+ export function setGitIssueSubject(subject) {
15
+ return modifyPublicTags(subject === null ? removeSingletonTag("subject") : setSingletonTag(["subject", subject]));
16
+ }
17
+ /** Adds a label `t` tag */
18
+ export function addGitIssueLabel(label) {
19
+ return modifyPublicTags((tags) => [...tags.filter((t) => !(t[0] === "t" && t[1] === label)), ["t", label]]);
20
+ }
21
+ /** Removes a label `t` tag */
22
+ export function removeGitIssueLabel(label) {
23
+ return modifyPublicTags((tags) => tags.filter((t) => !(t[0] === "t" && t[1] === label)));
24
+ }
25
+ /** Replaces all label `t` tags */
26
+ export function setGitIssueLabels(labels) {
27
+ return modifyPublicTags((tags) => [
28
+ ...tags.filter((t) => t[0] !== "t"),
29
+ ...[...new Set(labels)].map((label) => ["t", label]),
30
+ ]);
31
+ }