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
@@ -2,6 +2,10 @@ import { ChainableObservable } from "../observable/chainable.js";
2
2
  export { castUser, User } from "applesauce-core/casts";
3
3
  declare module "applesauce-core/casts" {
4
4
  interface User {
5
+ /** Subscribes to reports referencing this user in the store */
6
+ get reports$(): ChainableObservable<import("./report.js").Report[]>;
7
+ /** Subscribes to reports published by this user in the store */
8
+ get reportsSent$(): ChainableObservable<import("./report.js").Report[]>;
5
9
  get profile$(): ChainableObservable<import("./profile.js").Profile | undefined>;
6
10
  get contacts$(): ChainableObservable<User[]>;
7
11
  get mutes$(): ChainableObservable<import("./mutes.js").Mutes | undefined>;
@@ -16,7 +20,10 @@ declare module "applesauce-core/casts" {
16
20
  get favoriteRelays$(): ChainableObservable<import("./relay-lists.js").FavoriteRelays | undefined>;
17
21
  get gitAuthors$(): ChainableObservable<import("./git-lists.js").GitAuthors | undefined>;
18
22
  get favoriteGitRepos$(): ChainableObservable<import("./git-lists.js").FavoriteGitRepos | undefined>;
23
+ get identities$(): ChainableObservable<import("./external-identities.js").ExternalIdentities | undefined>;
19
24
  get graspServers$(): ChainableObservable<import("./git-grasp-list.js").GitGraspList | undefined>;
25
+ /** Subscribes to the git repositories announced by the user that are in the event store */
26
+ get gitRepositories$(): ChainableObservable<import("./git-repository.js").GitRepository[]>;
20
27
  get searchRelays$(): ChainableObservable<import("./relay-lists.js").SearchRelays | undefined>;
21
28
  get lookupRelayList$(): ChainableObservable<import("./relay-lists.js").LookupRelayList | undefined>;
22
29
  get blockedRelays$(): ChainableObservable<import("./relay-lists.js").BlockedRelays | undefined>;
@@ -1,15 +1,18 @@
1
+ import { REPORT_KIND, isValidReport } from "../helpers/reports.js";
1
2
  import { castUser as coreCastUser, User } from "applesauce-core/casts";
2
3
  import { kinds, nprofileEncode } from "applesauce-core/helpers";
3
4
  import { combineLatest, defer, from, map, ReplaySubject, share, switchMap, tap } from "rxjs";
4
5
  import { BLOSSOM_SERVER_LIST_KIND, getBlossomServersFromList } from "../helpers/blossom.js";
5
6
  import { FAVORITE_EMOJI_PACKS_KIND } from "../helpers/emoji-pack.js";
7
+ import { EXTERNAL_IDENTITIES_KIND } from "../helpers/external-identities.js";
6
8
  import { GIT_GRASP_LIST_KIND } from "../helpers/git-grasp-list.js";
7
9
  import { GIT_AUTHORS_KIND, FAVORITE_GIT_REPOS_KIND } from "../helpers/git-lists.js";
10
+ import { GIT_REPOSITORY_KIND } from "../helpers/git-repository.js";
8
11
  import { GROUPS_LIST_KIND } from "../helpers/groups.js";
9
12
  import { getRelaysFromList } from "../helpers/lists.js";
10
13
  import { FAVORITE_RELAYS_KIND, LOOKUP_RELAY_LIST_KIND } from "../helpers/relay-list.js";
11
14
  import { TRUSTED_PROVIDER_LIST_KIND } from "../helpers/trusted-assertions.js";
12
- import { castEventStream } from "../observable/cast-stream.js";
15
+ import { castEventStream, castTimelineStream } from "../observable/cast-stream.js";
13
16
  // Re-export castUser and User from core so consumers don't need to change imports
14
17
  export { castUser, User } from "applesauce-core/casts";
15
18
  function memoize() {
@@ -51,6 +54,12 @@ Object.defineProperty(User.prototype, "nprofile", {
51
54
  configurable: true,
52
55
  enumerable: false,
53
56
  });
57
+ defineGetter("reports$", function () {
58
+ return this.$$ref("reports$", (store) => Circular.pipe(switchMap(({ Report }) => store.timeline({ kinds: [REPORT_KIND], "#p": [this.pubkey] }).pipe(map((events) => events.filter(isValidReport)), castTimelineStream(Report, store)))));
59
+ });
60
+ defineGetter("reportsSent$", function () {
61
+ return this.$$ref("reportsSent$", (store) => Circular.pipe(switchMap(({ Report }) => store.timeline({ kinds: [REPORT_KIND], authors: [this.pubkey] }).pipe(map((events) => events.filter(isValidReport)), castTimelineStream(Report, store)))));
62
+ });
54
63
  defineGetter("profile$", function () {
55
64
  return this.$$ref("profile$", (store) => Circular.pipe(switchMap(({ Profile }) => store.replaceable({ kind: kinds.Metadata, pubkey: this.pubkey }).pipe(castEventStream(Profile, store)))));
56
65
  });
@@ -98,11 +107,21 @@ defineGetter("favoriteGitRepos$", function () {
98
107
  .replaceable({ kind: FAVORITE_GIT_REPOS_KIND, pubkey: this.pubkey, relays: outboxes })
99
108
  .pipe(castEventStream(FavoriteGitRepos, store)))));
100
109
  });
110
+ defineGetter("identities$", function () {
111
+ return this.$$ref("identities$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ ExternalIdentities }, outboxes]) => store
112
+ .replaceable({ kind: EXTERNAL_IDENTITIES_KIND, pubkey: this.pubkey, relays: outboxes })
113
+ .pipe(castEventStream(ExternalIdentities, store)))));
114
+ });
101
115
  defineGetter("graspServers$", function () {
102
116
  return this.$$ref("graspServers$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ GitGraspList }, outboxes]) => store
103
117
  .replaceable({ kind: GIT_GRASP_LIST_KIND, pubkey: this.pubkey, relays: outboxes })
104
118
  .pipe(castEventStream(GitGraspList, store)))));
105
119
  });
120
+ defineGetter("gitRepositories$", function () {
121
+ return this.$$ref("gitRepositories$", (store) => Circular.pipe(switchMap(({ GitRepository }) => store
122
+ .timeline({ kinds: [GIT_REPOSITORY_KIND], authors: [this.pubkey] })
123
+ .pipe(castTimelineStream(GitRepository, store)))));
124
+ });
106
125
  defineGetter("searchRelays$", function () {
107
126
  return this.$$ref("searchRelays$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ SearchRelays }, outboxes]) => store
108
127
  .replaceable({ kind: kinds.SearchRelaysList, pubkey: this.pubkey, relays: outboxes })
@@ -0,0 +1,31 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
4
+ import { ProfileContent } from "applesauce-core/helpers/profile";
5
+ import { APP_HANDLER_KIND, HandlerLinkPlatform, HandlerLinkType } from "../helpers/app-handler.js";
6
+ /** An event template for a NIP-89 handler information event */
7
+ export type AppHandlerTemplate = KnownEventTemplate<typeof APP_HANDLER_KIND>;
8
+ /** Factory for NIP-89 handler information events (kind 31990) */
9
+ export declare class AppHandlerFactory extends EventFactory<typeof APP_HANDLER_KIND, AppHandlerTemplate> {
10
+ /** Creates a handler with the given identifier, or a random one */
11
+ static create(identifier?: string): AppHandlerFactory;
12
+ /**
13
+ * Creates a factory configured to modify an existing handler
14
+ * @throws if the event is not a valid handler information event
15
+ */
16
+ static modify(event: NostrEvent): AppHandlerFactory;
17
+ /** Sets the kind:0-style metadata, or clears it to use the author's profile */
18
+ metadata(metadata: ProfileContent | null): this;
19
+ /** Adds a supported event kind */
20
+ kind(kind: number): this;
21
+ /** Removes a supported event kind */
22
+ removeKind(kind: number): this;
23
+ /** Sets a URL template for a platform and NIP-19 entity type */
24
+ link(platform: HandlerLinkPlatform, url: string, type?: HandlerLinkType): this;
25
+ /** Removes a URL template for a platform and NIP-19 entity type */
26
+ removeLink(platform: HandlerLinkPlatform, type?: HandlerLinkType): this;
27
+ /** Sets or removes the named nsite the handler currently serves */
28
+ latest(site: AddressPointer | string | null): this;
29
+ /** Sets or removes the named nsite the handler is rolling out */
30
+ next(site: AddressPointer | string | null): this;
31
+ }
@@ -0,0 +1,50 @@
1
+ import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
2
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
3
+ import { APP_HANDLER_KIND, isValidAppHandler } from "../helpers/app-handler.js";
4
+ import { addHandlerKind, removeHandlerKind, removeHandlerLink, setHandlerLatest, setHandlerLink, setHandlerMetadata, setHandlerNext, } from "../operations/app-handler.js";
5
+ /** Factory for NIP-89 handler information events (kind 31990) */
6
+ export class AppHandlerFactory extends EventFactory {
7
+ /** Creates a handler with the given identifier, or a random one */
8
+ static create(identifier) {
9
+ // The blank template already has a random identifier
10
+ const factory = new AppHandlerFactory((res) => res(blankEventTemplate(APP_HANDLER_KIND)));
11
+ return identifier ? factory.chain(includeSingletonTag(["d", identifier])) : factory;
12
+ }
13
+ /**
14
+ * Creates a factory configured to modify an existing handler
15
+ * @throws if the event is not a valid handler information event
16
+ */
17
+ static modify(event) {
18
+ if (!isValidAppHandler(event))
19
+ throw new Error("Expected a NIP-89 handler information event");
20
+ return new AppHandlerFactory((res) => res(toEventTemplate(event)));
21
+ }
22
+ /** Sets the kind:0-style metadata, or clears it to use the author's profile */
23
+ metadata(metadata) {
24
+ return this.chain(setHandlerMetadata(metadata));
25
+ }
26
+ /** Adds a supported event kind */
27
+ kind(kind) {
28
+ return this.chain(addHandlerKind(kind));
29
+ }
30
+ /** Removes a supported event kind */
31
+ removeKind(kind) {
32
+ return this.chain(removeHandlerKind(kind));
33
+ }
34
+ /** Sets a URL template for a platform and NIP-19 entity type */
35
+ link(platform, url, type) {
36
+ return this.chain(setHandlerLink(platform, url, type));
37
+ }
38
+ /** Removes a URL template for a platform and NIP-19 entity type */
39
+ removeLink(platform, type) {
40
+ return this.chain(removeHandlerLink(platform, type));
41
+ }
42
+ /** Sets or removes the named nsite the handler currently serves */
43
+ latest(site) {
44
+ return this.chain(setHandlerLatest(site));
45
+ }
46
+ /** Sets or removes the named nsite the handler is rolling out */
47
+ next(site) {
48
+ return this.chain(setHandlerNext(site));
49
+ }
50
+ }
@@ -0,0 +1,21 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
4
+ import { HandlerLinkPlatform } from "../helpers/app-handler.js";
5
+ import { APP_RECOMMENDATION_KIND } from "../helpers/app-recommendation.js";
6
+ /** An event template for a NIP-89 handler recommendation */
7
+ export type AppRecommendationTemplate = KnownEventTemplate<typeof APP_RECOMMENDATION_KIND>;
8
+ /** Factory for NIP-89 handler recommendations (kind 31989) */
9
+ export declare class AppRecommendationFactory extends EventFactory<typeof APP_RECOMMENDATION_KIND, AppRecommendationTemplate> {
10
+ /** Creates a recommendation for handlers of an event kind */
11
+ static create(kind: number): AppRecommendationFactory;
12
+ /**
13
+ * Creates a factory configured to modify an existing recommendation
14
+ * @throws if the event is not a valid handler recommendation
15
+ */
16
+ static modify(event: NostrEvent): AppRecommendationFactory;
17
+ /** Adds or replaces a recommended handler for a platform */
18
+ handler(handler: AddressPointer | string, platform?: HandlerLinkPlatform): this;
19
+ /** Removes a recommended handler for every platform, one platform, or only the entry without a platform when `null` */
20
+ removeHandler(handler: AddressPointer | string, platform?: HandlerLinkPlatform | null): this;
21
+ }
@@ -0,0 +1,28 @@
1
+ import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
2
+ import { includeSingletonTag } from "applesauce-core/operations/tags";
3
+ import { APP_RECOMMENDATION_KIND, isValidAppRecommendation } from "../helpers/app-recommendation.js";
4
+ import { addRecommendedHandler, removeRecommendedHandler } from "../operations/app-recommendation.js";
5
+ /** Factory for NIP-89 handler recommendations (kind 31989) */
6
+ export class AppRecommendationFactory extends EventFactory {
7
+ /** Creates a recommendation for handlers of an event kind */
8
+ static create(kind) {
9
+ return new AppRecommendationFactory((res) => res(blankEventTemplate(APP_RECOMMENDATION_KIND))).chain(includeSingletonTag(["d", String(kind)]));
10
+ }
11
+ /**
12
+ * Creates a factory configured to modify an existing recommendation
13
+ * @throws if the event is not a valid handler recommendation
14
+ */
15
+ static modify(event) {
16
+ if (!isValidAppRecommendation(event))
17
+ throw new Error("Expected a NIP-89 handler recommendation event");
18
+ return new AppRecommendationFactory((res) => res(toEventTemplate(event)));
19
+ }
20
+ /** Adds or replaces a recommended handler for a platform */
21
+ handler(handler, platform) {
22
+ return this.chain(addRecommendedHandler(handler, platform));
23
+ }
24
+ /** Removes a recommended handler for every platform, one platform, or only the entry without a platform when `null` */
25
+ removeHandler(handler, platform) {
26
+ return this.chain(removeRecommendedHandler(handler, platform));
27
+ }
28
+ }
@@ -0,0 +1,37 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
3
+ import { EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
4
+ import { TextContentOptions } from "applesauce-core/operations/content";
5
+ import { FileMetadataFields } from "../helpers/file-metadata.js";
6
+ import { Emoji } from "../helpers/emoji.js";
7
+ export type ChatMessageTemplate = KnownEventTemplate<kinds.ChatMessage>;
8
+ export type ChatMessageFactoryOptions = TextContentOptions;
9
+ /**
10
+ * A factory class for building NIP-C7 kind 9 chat message events. Replies are
11
+ * additional kind 9 events that quote their parent with a `q` tag.
12
+ */
13
+ export declare class ChatMessageFactory extends EventFactory<kinds.ChatMessage, ChatMessageTemplate> {
14
+ /**
15
+ * Creates a new chat message factory
16
+ * @param content - Optional initial message content
17
+ * @param options - Optional content options
18
+ */
19
+ static create(content?: string, options?: ChatMessageFactoryOptions): ChatMessageFactory;
20
+ /**
21
+ * Creates a chat message factory configured as a reply to another chat message
22
+ * @param parent - The parent chat message being replied to
23
+ * @param content - Optional initial message content
24
+ * @param options - Optional content options
25
+ */
26
+ static reply(parent: NostrEvent | EventPointer, content?: string, options?: ChatMessageFactoryOptions): ChatMessageFactory;
27
+ /** Sets the message content, tagging mentions (NIP-C7), quotes (NIP-18), and custom emojis (NIP-30) */
28
+ text(content: string, options?: ChatMessageFactoryOptions): this;
29
+ /** Adds the NIP-C7 `q` reply tag pointing at the parent message */
30
+ replyTo(parent: NostrEvent | EventPointer): this;
31
+ /** Adds a "p" mention tag for a pubkey or ProfilePointer */
32
+ mention(pubkey: string | ProfilePointer): this;
33
+ /** Adds NIP-92 "imeta" tags for media attachments */
34
+ attachments(attachments: FileMetadataFields[]): this;
35
+ /** Adds NIP-30 "emoji" tags for custom emojis */
36
+ emojis(emojis: Emoji[]): this;
37
+ }
@@ -0,0 +1,56 @@
1
+ import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
2
+ import { kinds } from "applesauce-core/helpers";
3
+ import { ensureProfilePointerTag } from "applesauce-core/helpers/factory";
4
+ import { includeEmojis, setShortTextContent } from "applesauce-core/operations/content";
5
+ import { includeChatReply } from "../operations/chat-message.js";
6
+ import { addMediaAttachments } from "../operations/media-attachment.js";
7
+ /**
8
+ * A factory class for building NIP-C7 kind 9 chat message events. Replies are
9
+ * additional kind 9 events that quote their parent with a `q` tag.
10
+ */
11
+ export class ChatMessageFactory extends EventFactory {
12
+ /**
13
+ * Creates a new chat message factory
14
+ * @param content - Optional initial message content
15
+ * @param options - Optional content options
16
+ */
17
+ static create(content, options) {
18
+ let factory = new ChatMessageFactory((res) => res(blankEventTemplate(kinds.ChatMessage)));
19
+ if (content !== undefined)
20
+ factory = factory.text(content, options);
21
+ return factory;
22
+ }
23
+ /**
24
+ * Creates a chat message factory configured as a reply to another chat message
25
+ * @param parent - The parent chat message being replied to
26
+ * @param content - Optional initial message content
27
+ * @param options - Optional content options
28
+ */
29
+ static reply(parent, content, options) {
30
+ let factory = new ChatMessageFactory((res) => res(blankEventTemplate(kinds.ChatMessage))).replyTo(parent);
31
+ if (content !== undefined)
32
+ factory = factory.text(content, options);
33
+ return factory;
34
+ }
35
+ /** Sets the message content, tagging mentions (NIP-C7), quotes (NIP-18), and custom emojis (NIP-30) */
36
+ text(content, options) {
37
+ return this.chain(setShortTextContent(content, options));
38
+ }
39
+ /** Adds the NIP-C7 `q` reply tag pointing at the parent message */
40
+ replyTo(parent) {
41
+ return this.chain(includeChatReply(parent));
42
+ }
43
+ /** Adds a "p" mention tag for a pubkey or ProfilePointer */
44
+ mention(pubkey) {
45
+ const pointer = typeof pubkey === "string" ? { pubkey } : pubkey;
46
+ return this.modifyPublicTags((tags) => ensureProfilePointerTag(tags, pointer));
47
+ }
48
+ /** Adds NIP-92 "imeta" tags for media attachments */
49
+ attachments(attachments) {
50
+ return this.chain(addMediaAttachments(attachments));
51
+ }
52
+ /** Adds NIP-30 "emoji" tags for custom emojis */
53
+ emojis(emojis) {
54
+ return this.chain(includeEmojis(emojis));
55
+ }
56
+ }
@@ -1,18 +1,19 @@
1
1
  import { EventFactory } from "applesauce-core/factories";
2
- import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
2
+ import { KnownEventTemplate } from "applesauce-core/helpers";
3
3
  import { TextContentOptions } from "applesauce-core/operations/content";
4
4
  import { MetaTagOptions } from "applesauce-core/operations/event";
5
- import { COMMENT_KIND, CommentPointer } from "../helpers/comment.js";
5
+ import { COMMENT_KIND } from "../helpers/comment.js";
6
+ import { CommentParent } from "../operations/comment.js";
6
7
  import { GroupPointer } from "../helpers/groups.js";
7
8
  export type CommentTemplate = KnownEventTemplate<typeof COMMENT_KIND>;
8
9
  export type CommentFactoryOptions = TextContentOptions & MetaTagOptions;
9
10
  export declare class CommentFactory extends EventFactory<typeof COMMENT_KIND, CommentTemplate> {
10
11
  /** Creates a new comment event */
11
- static create(parent: NostrEvent | CommentPointer, content: string, options?: CommentFactoryOptions): CommentFactory;
12
- /** Creates a new comment that is replying to a parent event or pointer */
13
- static reply(parent: NostrEvent | CommentPointer, content: string, options?: CommentFactoryOptions): CommentFactory;
14
- /** Sets the parent event or pointer that this comment is replying to */
15
- parent(parent: NostrEvent | CommentPointer): this;
12
+ static create(parent: CommentParent, content: string, options?: CommentFactoryOptions): CommentFactory;
13
+ /** Creates a new comment that is replying to a parent event, rumor, or pointer */
14
+ static reply(parent: CommentParent, content: string, options?: CommentFactoryOptions): CommentFactory;
15
+ /** Sets the parent event, rumor, or pointer that this comment is replying to */
16
+ parent(parent: CommentParent): this;
16
17
  /** Sets the text content of the comment */
17
18
  text(content: string, options?: TextContentOptions): this;
18
19
  /** Sets the NIP-29 group pointer "h" tag for this comment */
@@ -14,7 +14,7 @@ export class CommentFactory extends EventFactory {
14
14
  factory.meta(options);
15
15
  return factory;
16
16
  }
17
- /** Creates a new comment that is replying to a parent event or pointer */
17
+ /** Creates a new comment that is replying to a parent event, rumor, or pointer */
18
18
  static reply(parent, content, options) {
19
19
  let factory = new CommentFactory((res) => res(blankEventTemplate(COMMENT_KIND)))
20
20
  .parent(parent)
@@ -23,7 +23,7 @@ export class CommentFactory extends EventFactory {
23
23
  factory.meta(options);
24
24
  return factory;
25
25
  }
26
- /** Sets the parent event or pointer that this comment is replying to */
26
+ /** Sets the parent event, rumor, or pointer that this comment is replying to */
27
27
  parent(parent) {
28
28
  return this.chain(setParent(parent));
29
29
  }
@@ -0,0 +1,17 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
3
+ import { EXTERNAL_IDENTITIES_KIND, ExternalIdentity } from "../helpers/external-identities.js";
4
+ export type ExternalIdentitiesTemplate = KnownEventTemplate<typeof EXTERNAL_IDENTITIES_KIND>;
5
+ /** Factory for NIP-39 external identity lists */
6
+ export declare class ExternalIdentitiesFactory extends EventFactory<typeof EXTERNAL_IDENTITIES_KIND, ExternalIdentitiesTemplate> {
7
+ /** Creates an external identities factory */
8
+ static create(identities?: ExternalIdentity[]): ExternalIdentitiesFactory;
9
+ /** Creates a factory configured to modify an existing external identities list */
10
+ static modify(event: NostrEvent): ExternalIdentitiesFactory;
11
+ /** Replaces all external identities */
12
+ setIdentities(identities: ExternalIdentity[]): this;
13
+ /** Adds or replaces an external identity */
14
+ addIdentity(identity: ExternalIdentity): this;
15
+ /** Removes an external identity */
16
+ removeIdentity(platform: string, identity: string): this;
17
+ }
@@ -0,0 +1,28 @@
1
+ import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
2
+ import { EXTERNAL_IDENTITIES_KIND } from "../helpers/external-identities.js";
3
+ import { addExternalIdentity, removeExternalIdentity, setExternalIdentities, } from "../operations/external-identities.js";
4
+ /** Factory for NIP-39 external identity lists */
5
+ export class ExternalIdentitiesFactory extends EventFactory {
6
+ /** Creates an external identities factory */
7
+ static create(identities = []) {
8
+ return new ExternalIdentitiesFactory((res) => res(blankEventTemplate(EXTERNAL_IDENTITIES_KIND))).setIdentities(identities);
9
+ }
10
+ /** Creates a factory configured to modify an existing external identities list */
11
+ static modify(event) {
12
+ if (event.kind !== EXTERNAL_IDENTITIES_KIND)
13
+ throw new Error("Expected an external identities event");
14
+ return new ExternalIdentitiesFactory((res) => res(toEventTemplate(event)));
15
+ }
16
+ /** Replaces all external identities */
17
+ setIdentities(identities) {
18
+ return this.chain(setExternalIdentities(identities));
19
+ }
20
+ /** Adds or replaces an external identity */
21
+ addIdentity(identity) {
22
+ return this.chain(addExternalIdentity(identity));
23
+ }
24
+ /** Removes an external identity */
25
+ removeIdentity(platform, identity) {
26
+ return this.chain(removeExternalIdentity(platform, identity));
27
+ }
28
+ }
@@ -0,0 +1,24 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { kinds, KnownEventTemplate } from "applesauce-core/helpers";
3
+ import { FileMetadataFields } from "../helpers/file-metadata.js";
4
+ import { Rumor } from "../helpers/gift-wrap.js";
5
+ export type FileMessageTemplate = KnownEventTemplate<kinds.FileMessage>;
6
+ /** A factory for NIP-17 kind 15 file messages, which carry the URL and decryption key of an encrypted file */
7
+ export declare class FileMessageFactory extends EventFactory<kinds.FileMessage, FileMessageTemplate> {
8
+ /**
9
+ * Creates a new file message
10
+ * @param recipients A single recipient pubkey or an array of recipient pubkeys
11
+ * @param file The uploaded file's URL, type, hashes, and decryption fields
12
+ * @throws if the file has no URL
13
+ */
14
+ static create(recipients: string | string[], file: FileMetadataFields): FileMessageFactory;
15
+ /**
16
+ * Sets the file URL and file tags
17
+ * @throws if the file has no URL
18
+ */
19
+ file(file: FileMetadataFields): this;
20
+ /** Sets the parent message "e" tag for NIP-17 reply threading */
21
+ replyTo(parent: Rumor | string): this;
22
+ /** Sets the subject tag for the message thread */
23
+ subject(subject: string): this;
24
+ }
@@ -0,0 +1,37 @@
1
+ import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
2
+ import { kinds } from "applesauce-core/helpers";
3
+ import { includeNameValueTag } from "applesauce-core/operations/tags";
4
+ import { setFileMessage } from "../operations/file-message.js";
5
+ import { setParent, setSubject } from "../operations/wrapped-message.js";
6
+ /** A factory for NIP-17 kind 15 file messages, which carry the URL and decryption key of an encrypted file */
7
+ export class FileMessageFactory extends EventFactory {
8
+ /**
9
+ * Creates a new file message
10
+ * @param recipients A single recipient pubkey or an array of recipient pubkeys
11
+ * @param file The uploaded file's URL, type, hashes, and decryption fields
12
+ * @throws if the file has no URL
13
+ */
14
+ static create(recipients, file) {
15
+ const recipientList = typeof recipients === "string" ? [recipients] : recipients;
16
+ let factory = new FileMessageFactory((res) => res(blankEventTemplate(kinds.FileMessage))).file(file);
17
+ for (const recipient of recipientList) {
18
+ factory = factory.chain(includeNameValueTag(["p", recipient]));
19
+ }
20
+ return factory;
21
+ }
22
+ /**
23
+ * Sets the file URL and file tags
24
+ * @throws if the file has no URL
25
+ */
26
+ file(file) {
27
+ return this.chain(setFileMessage(file));
28
+ }
29
+ /** Sets the parent message "e" tag for NIP-17 reply threading */
30
+ replyTo(parent) {
31
+ return this.chain(setParent(parent));
32
+ }
33
+ /** Sets the subject tag for the message thread */
34
+ subject(subject) {
35
+ return this.chain(setSubject(subject));
36
+ }
37
+ }
@@ -0,0 +1,34 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate } from "applesauce-core/helpers";
3
+ import { ProfilePointer } from "applesauce-core/helpers/pointers";
4
+ import { TextContentOptions } from "applesauce-core/operations/content";
5
+ import { FORUM_THREAD_KIND } from "../helpers/forum-thread.js";
6
+ import { Emoji } from "../helpers/emoji.js";
7
+ export type ForumThreadTemplate = KnownEventTemplate<typeof FORUM_THREAD_KIND>;
8
+ export type ForumThreadFactoryOptions = TextContentOptions;
9
+ /**
10
+ * A factory class for building NIP-7D forum thread events (kind 11). Replies to
11
+ * a thread are NIP-22 kind 1111 comments to the root — build them with the
12
+ * `CommentFactory` (`CommentFactory.create(thread, body)`).
13
+ */
14
+ export declare class ForumThreadFactory extends EventFactory<typeof FORUM_THREAD_KIND, ForumThreadTemplate> {
15
+ /**
16
+ * Creates a new forum thread factory
17
+ * @param title - The thread title (NIP-7D `title` tag)
18
+ * @param content - Optional initial thread body
19
+ * @param options - Optional content options
20
+ */
21
+ static create(title: string, content?: string, options?: ForumThreadFactoryOptions): ForumThreadFactory;
22
+ /** Sets the NIP-7D `title` tag */
23
+ title(title: string): this;
24
+ /** Sets the thread body, tagging mentions, quotes, hashtags, and custom emojis */
25
+ text(content: string, options?: ForumThreadFactoryOptions): this;
26
+ /** Adds a "p" mention tag for a pubkey or ProfilePointer */
27
+ mention(pubkey: string | ProfilePointer): this;
28
+ /** Adds a hashtag "t" tag */
29
+ addHashtag(hashtag: string): this;
30
+ /** Adds multiple hashtags as "t" tags */
31
+ hashtags(tags: string[]): this;
32
+ /** Adds NIP-30 "emoji" tags for custom emojis */
33
+ emojis(emojis: Emoji[]): this;
34
+ }
@@ -0,0 +1,50 @@
1
+ import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
2
+ import { ensureProfilePointerTag } from "applesauce-core/helpers/factory";
3
+ import { includeEmojis, setShortTextContent } from "applesauce-core/operations/content";
4
+ import { FORUM_THREAD_KIND } from "../helpers/forum-thread.js";
5
+ import { setTitle } from "../operations/forum-thread.js";
6
+ import { addHashtag, includeHashtags } from "../operations/hashtags.js";
7
+ /**
8
+ * A factory class for building NIP-7D forum thread events (kind 11). Replies to
9
+ * a thread are NIP-22 kind 1111 comments to the root — build them with the
10
+ * `CommentFactory` (`CommentFactory.create(thread, body)`).
11
+ */
12
+ export class ForumThreadFactory extends EventFactory {
13
+ /**
14
+ * Creates a new forum thread factory
15
+ * @param title - The thread title (NIP-7D `title` tag)
16
+ * @param content - Optional initial thread body
17
+ * @param options - Optional content options
18
+ */
19
+ static create(title, content, options) {
20
+ let factory = new ForumThreadFactory((res) => res(blankEventTemplate(FORUM_THREAD_KIND))).title(title);
21
+ if (content !== undefined)
22
+ factory = factory.text(content, options);
23
+ return factory;
24
+ }
25
+ /** Sets the NIP-7D `title` tag */
26
+ title(title) {
27
+ return this.chain(setTitle(title));
28
+ }
29
+ /** Sets the thread body, tagging mentions, quotes, hashtags, and custom emojis */
30
+ text(content, options) {
31
+ return this.chain(setShortTextContent(content, options));
32
+ }
33
+ /** Adds a "p" mention tag for a pubkey or ProfilePointer */
34
+ mention(pubkey) {
35
+ const pointer = typeof pubkey === "string" ? { pubkey } : pubkey;
36
+ return this.modifyPublicTags((tags) => ensureProfilePointerTag(tags, pointer));
37
+ }
38
+ /** Adds a hashtag "t" tag */
39
+ addHashtag(hashtag) {
40
+ return this.chain(addHashtag(hashtag));
41
+ }
42
+ /** Adds multiple hashtags as "t" tags */
43
+ hashtags(tags) {
44
+ return this.chain(includeHashtags(tags));
45
+ }
46
+ /** Adds NIP-30 "emoji" tags for custom emojis */
47
+ emojis(emojis) {
48
+ return this.chain(includeEmojis(emojis));
49
+ }
50
+ }
@@ -0,0 +1,39 @@
1
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { GIT_STATUS_APPLIED_KIND } from "../helpers/git-status.js";
3
+ import { GitStatusTargetFactory } from "./internal/git-status.js";
4
+ import { EventPointer } from "applesauce-core/helpers/pointers";
5
+ /** An event template for a NIP-34 applied status */
6
+ export type GitAppliedStatusTemplate = KnownEventTemplate<typeof GIT_STATUS_APPLIED_KIND>;
7
+ /** A factory for NIP-34 applied statuses (kind 1631) */
8
+ export declare class GitAppliedStatusFactory extends GitStatusTargetFactory<typeof GIT_STATUS_APPLIED_KIND> {
9
+ /**
10
+ * Creates a applied status for an original thread root
11
+ * @throws if the target is not a supported original root
12
+ */
13
+ static create(root: NostrEvent, content?: string): GitAppliedStatusFactory;
14
+ /**
15
+ * Creates a factory for modifying a applied status draft
16
+ * @throws if the event is not a valid applied status
17
+ */
18
+ static modify(event: NostrEvent): GitAppliedStatusFactory;
19
+ /**
20
+ * Sets or removes the accepted revision
21
+ * @throws if the patch is not a revision of this status root
22
+ */
23
+ acceptedRevision(revision: NostrEvent | null, relay?: string): this;
24
+ /**
25
+ * Replaces the applied patch references
26
+ * @throws if a patch id is invalid
27
+ */
28
+ appliedPatches(patches: (string | EventPointer)[]): this;
29
+ /**
30
+ * Replaces the applied commit ids
31
+ * @throws if a commit is not a Git object id
32
+ */
33
+ appliedCommits(commits: string[]): this;
34
+ /**
35
+ * Sets or removes the merge commit
36
+ * @throws if the commit is not a Git object id
37
+ */
38
+ mergeCommit(commit: string | null): this;
39
+ }
@@ -0,0 +1,53 @@
1
+ import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
2
+ import { GIT_STATUS_APPLIED_KIND, isValidGitStatus } from "../helpers/git-status.js";
3
+ import { GitStatusTargetFactory } from "./internal/git-status.js";
4
+ import { setGitStatusAcceptedRevision, setGitStatusAppliedPatches, setGitStatusAppliedCommits, setGitStatusMergeCommit, } from "../operations/git-status.js";
5
+ /** A factory for NIP-34 applied statuses (kind 1631) */
6
+ export class GitAppliedStatusFactory extends GitStatusTargetFactory {
7
+ /**
8
+ * Creates a applied status for an original thread root
9
+ * @throws if the target is not a supported original root
10
+ */
11
+ static create(root, content = "") {
12
+ return new GitAppliedStatusFactory((res) => res(blankEventTemplate(GIT_STATUS_APPLIED_KIND)))
13
+ .root(root)
14
+ .content(content);
15
+ }
16
+ /**
17
+ * Creates a factory for modifying a applied status draft
18
+ * @throws if the event is not a valid applied status
19
+ */
20
+ static modify(event) {
21
+ if (!isValidGitStatus(event) || event.kind !== GIT_STATUS_APPLIED_KIND)
22
+ throw new Error("Expected a applied status");
23
+ return new GitAppliedStatusFactory((res) => res(toEventTemplate({ ...event, kind: GIT_STATUS_APPLIED_KIND })));
24
+ }
25
+ /**
26
+ * Sets or removes the accepted revision
27
+ * @throws if the patch is not a revision of this status root
28
+ */
29
+ acceptedRevision(revision, relay) {
30
+ return this.chain(setGitStatusAcceptedRevision(revision, relay));
31
+ }
32
+ /**
33
+ * Replaces the applied patch references
34
+ * @throws if a patch id is invalid
35
+ */
36
+ appliedPatches(patches) {
37
+ return this.chain(setGitStatusAppliedPatches(patches));
38
+ }
39
+ /**
40
+ * Replaces the applied commit ids
41
+ * @throws if a commit is not a Git object id
42
+ */
43
+ appliedCommits(commits) {
44
+ return this.chain(setGitStatusAppliedCommits(commits));
45
+ }
46
+ /**
47
+ * Sets or removes the merge commit
48
+ * @throws if the commit is not a Git object id
49
+ */
50
+ mergeCommit(commit) {
51
+ return this.chain(setGitStatusMergeCommit(commit));
52
+ }
53
+ }