applesauce-common 6.2.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/README.md +1 -0
  2. package/dist/casts/_circular-import.d.ts +3 -0
  3. package/dist/casts/_circular-import.js +3 -0
  4. package/dist/casts/app-handler.d.ts +56 -0
  5. package/dist/casts/app-handler.js +105 -0
  6. package/dist/casts/app-recommendation.d.ts +26 -0
  7. package/dist/casts/app-recommendation.js +41 -0
  8. package/dist/casts/external-identities.d.ts +9 -0
  9. package/dist/casts/external-identities.js +14 -0
  10. package/dist/casts/forum-thread.d.ts +17 -0
  11. package/dist/casts/forum-thread.js +31 -0
  12. package/dist/casts/git-issue.d.ts +18 -0
  13. package/dist/casts/git-issue.js +26 -0
  14. package/dist/casts/git-patch.d.ts +49 -0
  15. package/dist/casts/git-patch.js +88 -0
  16. package/dist/casts/git-pull-request.d.ts +67 -0
  17. package/dist/casts/git-pull-request.js +122 -0
  18. package/dist/casts/git-repository.d.ts +9 -0
  19. package/dist/casts/git-repository.js +16 -0
  20. package/dist/casts/git-thread.d.ts +33 -0
  21. package/dist/casts/git-thread.js +65 -0
  22. package/dist/casts/index.d.ts +11 -0
  23. package/dist/casts/index.js +11 -0
  24. package/dist/casts/napplet.d.ts +98 -0
  25. package/dist/casts/napplet.js +196 -0
  26. package/dist/casts/note.d.ts +8 -0
  27. package/dist/casts/note.js +21 -1
  28. package/dist/casts/nsite.d.ts +134 -0
  29. package/dist/casts/nsite.js +249 -0
  30. package/dist/casts/profile.d.ts +20 -0
  31. package/dist/casts/profile.js +30 -0
  32. package/dist/casts/reaction.d.ts +1 -1
  33. package/dist/casts/relay-discovery.d.ts +4 -0
  34. package/dist/casts/relay-discovery.js +9 -1
  35. package/dist/casts/report.d.ts +28 -15
  36. package/dist/casts/report.js +42 -19
  37. package/dist/casts/share.d.ts +1 -1
  38. package/dist/casts/torrent.d.ts +5 -0
  39. package/dist/casts/torrent.js +8 -1
  40. package/dist/casts/trusted-assertions.d.ts +2 -0
  41. package/dist/casts/trusted-assertions.js +19 -18
  42. package/dist/casts/user-status.d.ts +33 -0
  43. package/dist/casts/user-status.js +69 -0
  44. package/dist/casts/user.d.ts +7 -0
  45. package/dist/casts/user.js +20 -1
  46. package/dist/factories/app-handler.d.ts +31 -0
  47. package/dist/factories/app-handler.js +50 -0
  48. package/dist/factories/app-recommendation.d.ts +21 -0
  49. package/dist/factories/app-recommendation.js +28 -0
  50. package/dist/factories/chat-message.d.ts +37 -0
  51. package/dist/factories/chat-message.js +56 -0
  52. package/dist/factories/comment.d.ts +8 -7
  53. package/dist/factories/comment.js +2 -2
  54. package/dist/factories/external-identities.d.ts +17 -0
  55. package/dist/factories/external-identities.js +28 -0
  56. package/dist/factories/forum-thread.d.ts +34 -0
  57. package/dist/factories/forum-thread.js +50 -0
  58. package/dist/factories/git-applied-status.d.ts +39 -0
  59. package/dist/factories/git-applied-status.js +53 -0
  60. package/dist/factories/git-closed-status.d.ts +18 -0
  61. package/dist/factories/git-closed-status.js +24 -0
  62. package/dist/factories/git-draft-status.d.ts +18 -0
  63. package/dist/factories/git-draft-status.js +24 -0
  64. package/dist/factories/git-issue.d.ts +19 -0
  65. package/dist/factories/git-issue.js +25 -0
  66. package/dist/factories/git-open-status.d.ts +18 -0
  67. package/dist/factories/git-open-status.js +22 -0
  68. package/dist/factories/git-patch.d.ts +59 -0
  69. package/dist/factories/git-patch.js +102 -0
  70. package/dist/factories/git-pull-request-update.d.ts +23 -0
  71. package/dist/factories/git-pull-request-update.js +33 -0
  72. package/dist/factories/git-pull-request.d.ts +39 -0
  73. package/dist/factories/git-pull-request.js +64 -0
  74. package/dist/factories/index.d.ts +22 -0
  75. package/dist/factories/index.js +22 -0
  76. package/dist/factories/internal/git-pull-request.d.ts +19 -0
  77. package/dist/factories/internal/git-pull-request.js +26 -0
  78. package/dist/factories/internal/git-status.d.ts +11 -0
  79. package/dist/factories/internal/git-status.js +12 -0
  80. package/dist/factories/internal/git-thread.d.ts +19 -0
  81. package/dist/factories/internal/git-thread.js +29 -0
  82. package/dist/factories/internal/napplet-manifest.d.ts +52 -0
  83. package/dist/factories/internal/napplet-manifest.js +85 -0
  84. package/dist/factories/internal/nsite-manifest.d.ts +45 -0
  85. package/dist/factories/internal/nsite-manifest.js +68 -0
  86. package/dist/factories/legacy-message.d.ts +2 -0
  87. package/dist/factories/legacy-message.js +9 -2
  88. package/dist/factories/named-napplet.d.ts +20 -0
  89. package/dist/factories/named-napplet.js +30 -0
  90. package/dist/factories/named-nsite.d.ts +28 -0
  91. package/dist/factories/named-nsite.js +53 -0
  92. package/dist/factories/napplet-snapshot.d.ts +18 -0
  93. package/dist/factories/napplet-snapshot.js +38 -0
  94. package/dist/factories/nsite-snapshot.d.ts +18 -0
  95. package/dist/factories/nsite-snapshot.js +29 -0
  96. package/dist/factories/reaction.d.ts +3 -2
  97. package/dist/factories/report.d.ts +48 -0
  98. package/dist/factories/report.js +66 -0
  99. package/dist/factories/root-napplet.d.ts +18 -0
  100. package/dist/factories/root-napplet.js +24 -0
  101. package/dist/factories/root-nsite.d.ts +23 -0
  102. package/dist/factories/root-nsite.js +44 -0
  103. package/dist/factories/torrent.d.ts +24 -10
  104. package/dist/factories/torrent.js +48 -44
  105. package/dist/factories/trusted-provider-list.d.ts +23 -0
  106. package/dist/factories/trusted-provider-list.js +39 -0
  107. package/dist/factories/user-status.d.ts +26 -0
  108. package/dist/factories/user-status.js +52 -0
  109. package/dist/helpers/app-data.js +15 -7
  110. package/dist/helpers/app-handler.d.ts +43 -6
  111. package/dist/helpers/app-handler.js +53 -3
  112. package/dist/helpers/app-recommendation.d.ts +24 -0
  113. package/dist/helpers/app-recommendation.js +30 -0
  114. package/dist/helpers/bookmark.js +5 -2
  115. package/dist/helpers/comment.d.ts +11 -5
  116. package/dist/helpers/comment.js +7 -1
  117. package/dist/helpers/content.d.ts +3 -1
  118. package/dist/helpers/emoji-pack.js +11 -6
  119. package/dist/helpers/emoji.d.ts +2 -2
  120. package/dist/helpers/encrypted-content-cache.js +18 -1
  121. package/dist/helpers/external-id.js +13 -19
  122. package/dist/helpers/external-identities.d.ts +29 -0
  123. package/dist/helpers/external-identities.js +52 -0
  124. package/dist/helpers/file-metadata.js +5 -6
  125. package/dist/helpers/forum-thread.d.ts +10 -0
  126. package/dist/helpers/forum-thread.js +10 -0
  127. package/dist/helpers/gift-wrap.d.ts +40 -15
  128. package/dist/helpers/gift-wrap.js +110 -33
  129. package/dist/helpers/git-issue.d.ts +13 -0
  130. package/dist/helpers/git-issue.js +19 -0
  131. package/dist/helpers/git-patch.d.ts +41 -0
  132. package/dist/helpers/git-patch.js +73 -0
  133. package/dist/helpers/git-pull-request.d.ts +57 -0
  134. package/dist/helpers/git-pull-request.js +111 -0
  135. package/dist/helpers/git-repository.d.ts +4 -0
  136. package/dist/helpers/git-repository.js +16 -0
  137. package/dist/helpers/git-status.d.ts +44 -0
  138. package/dist/helpers/git-status.js +93 -0
  139. package/dist/helpers/git.d.ts +2 -0
  140. package/dist/helpers/git.js +4 -0
  141. package/dist/helpers/groups.d.ts +5 -2
  142. package/dist/helpers/groups.js +40 -18
  143. package/dist/helpers/hashtag.d.ts +4 -2
  144. package/dist/helpers/index.d.ts +10 -0
  145. package/dist/helpers/index.js +10 -0
  146. package/dist/helpers/lists.js +14 -2
  147. package/dist/helpers/lnurl.js +1 -1
  148. package/dist/helpers/mute.js +18 -7
  149. package/dist/helpers/napplet.d.ts +89 -0
  150. package/dist/helpers/napplet.js +144 -0
  151. package/dist/helpers/nsite.d.ts +90 -0
  152. package/dist/helpers/nsite.js +217 -0
  153. package/dist/helpers/relay-discovery.d.ts +4 -0
  154. package/dist/helpers/relay-discovery.js +8 -0
  155. package/dist/helpers/reports.d.ts +35 -0
  156. package/dist/helpers/reports.js +36 -5
  157. package/dist/helpers/threading.d.ts +4 -2
  158. package/dist/helpers/torrent.d.ts +9 -6
  159. package/dist/helpers/torrent.js +23 -15
  160. package/dist/helpers/trusted-assertions.d.ts +7 -0
  161. package/dist/helpers/trusted-assertions.js +41 -2
  162. package/dist/helpers/user-status.d.ts +13 -1
  163. package/dist/helpers/user-status.js +15 -0
  164. package/dist/models/app-handler.d.ts +21 -0
  165. package/dist/models/app-handler.js +47 -0
  166. package/dist/models/git.d.ts +34 -0
  167. package/dist/models/git.js +144 -0
  168. package/dist/models/index.d.ts +3 -0
  169. package/dist/models/index.js +3 -0
  170. package/dist/models/nsite.d.ts +22 -0
  171. package/dist/models/nsite.js +67 -0
  172. package/dist/models/thread.d.ts +4 -1
  173. package/dist/models/thread.js +34 -5
  174. package/dist/models/user-status.d.ts +8 -4
  175. package/dist/models/user-status.js +16 -22
  176. package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
  177. package/dist/observable/filter-timeline-by-mutes.js +5 -1
  178. package/dist/operations/app-handler.d.ts +24 -0
  179. package/dist/operations/app-handler.js +58 -0
  180. package/dist/operations/app-recommendation.d.ts +13 -0
  181. package/dist/operations/app-recommendation.js +40 -0
  182. package/dist/operations/calendar-event.js +3 -2
  183. package/dist/operations/chat-message.d.ts +9 -0
  184. package/dist/operations/chat-message.js +12 -0
  185. package/dist/operations/client.d.ts +1 -4
  186. package/dist/operations/client.js +1 -23
  187. package/dist/operations/comment.d.ts +9 -3
  188. package/dist/operations/comment.js +12 -9
  189. package/dist/operations/external-identities.d.ts +8 -0
  190. package/dist/operations/external-identities.js +23 -0
  191. package/dist/operations/forum-thread.d.ts +3 -0
  192. package/dist/operations/forum-thread.js +6 -0
  193. package/dist/operations/gift-wrap.js +38 -14
  194. package/dist/operations/git-issue.d.ts +18 -0
  195. package/dist/operations/git-issue.js +31 -0
  196. package/dist/operations/git-patch.d.ts +30 -0
  197. package/dist/operations/git-patch.js +75 -0
  198. package/dist/operations/git-pull-request.d.ts +29 -0
  199. package/dist/operations/git-pull-request.js +74 -0
  200. package/dist/operations/git-repository.js +4 -4
  201. package/dist/operations/git-status.d.ts +28 -0
  202. package/dist/operations/git-status.js +116 -0
  203. package/dist/operations/git-thread.d.ts +13 -0
  204. package/dist/operations/git-thread.js +39 -0
  205. package/dist/operations/index.d.ts +15 -0
  206. package/dist/operations/index.js +15 -0
  207. package/dist/operations/internal/git-commits.d.ts +2 -0
  208. package/dist/operations/internal/git-commits.js +16 -0
  209. package/dist/operations/napplet.d.ts +51 -0
  210. package/dist/operations/napplet.js +121 -0
  211. package/dist/operations/nsite.d.ts +51 -0
  212. package/dist/operations/nsite.js +112 -0
  213. package/dist/operations/reaction.d.ts +12 -2
  214. package/dist/operations/reaction.js +1 -1
  215. package/dist/operations/report.d.ts +33 -0
  216. package/dist/operations/report.js +60 -0
  217. package/dist/operations/stream.js +5 -4
  218. package/dist/operations/torrent.d.ts +1 -4
  219. package/dist/operations/torrent.js +24 -11
  220. package/dist/operations/trusted-providers.d.ts +14 -0
  221. package/dist/operations/trusted-providers.js +33 -0
  222. package/dist/operations/user-status.d.ts +11 -0
  223. package/dist/operations/user-status.js +29 -0
  224. package/package.json +9 -9
@@ -0,0 +1,68 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { addNsiteApp, addNsiteServer, removeNsiteApp, removeNsiteFile, removeNsiteServer, setNsiteDescription, setNsiteFile, setNsiteParent, setNsiteRoot, setNsiteSource, setNsiteTitle, updateNsiteAggregateHash, } from "../../operations/nsite.js";
3
+ /** A shared implementation of nsite manifest operations */
4
+ export class NsiteManifestFactory extends EventFactory {
5
+ /**
6
+ * Adds or replaces a file mapping and refreshes the aggregate hash
7
+ * @throws if the path or hash is invalid
8
+ */
9
+ file(path, hash) {
10
+ return this.chain(setNsiteFile(path, hash));
11
+ }
12
+ /** Removes a file mapping and refreshes the aggregate hash */
13
+ removeFile(path) {
14
+ return this.chain(removeNsiteFile(path));
15
+ }
16
+ /** Updates the aggregate hash from the current manifest */
17
+ aggregate() {
18
+ return this.chain(updateNsiteAggregateHash());
19
+ }
20
+ /** Sets or removes the site's title */
21
+ title(value) {
22
+ return this.chain(setNsiteTitle(value));
23
+ }
24
+ /** Sets or removes the site's description */
25
+ description(value) {
26
+ return this.chain(setNsiteDescription(value));
27
+ }
28
+ /** Sets or removes the site's source URL */
29
+ source(value) {
30
+ return this.chain(setNsiteSource(value));
31
+ }
32
+ /** Adds a Blossom server hint */
33
+ server(url) {
34
+ return this.chain(addNsiteServer(url));
35
+ }
36
+ /** Removes a Blossom server hint */
37
+ removeServer(url) {
38
+ return this.chain(removeNsiteServer(url));
39
+ }
40
+ /**
41
+ * Adds or replaces an upstream app descriptor reference
42
+ * @throws if the address is not addressable
43
+ */
44
+ app(pointer) {
45
+ return this.chain(addNsiteApp(pointer));
46
+ }
47
+ /**
48
+ * Removes an upstream app descriptor reference
49
+ * @throws if the address is not addressable
50
+ */
51
+ removeApp(pointer) {
52
+ return this.chain(removeNsiteApp(pointer));
53
+ }
54
+ /**
55
+ * Sets or removes the immediate parent site
56
+ * @throws if the address does not reference a root or named site
57
+ */
58
+ parent(pointer) {
59
+ return this.chain(setNsiteParent(pointer));
60
+ }
61
+ /**
62
+ * Sets or removes the origin site of the copy lineage
63
+ * @throws if the address does not reference a root or named site
64
+ */
65
+ root(pointer) {
66
+ return this.chain(setNsiteRoot(pointer));
67
+ }
68
+ }
@@ -4,6 +4,8 @@ export type LegacyMessageTemplate = KnownEventTemplate<kinds.EncryptedDirectMess
4
4
  export declare class LegacyMessageFactory extends EventFactory<kinds.EncryptedDirectMessage, LegacyMessageTemplate> {
5
5
  static create(recipient: string, message: string): LegacyMessageFactory;
6
6
  static reply(parent: NostrEvent, recipient: string, message: string): LegacyMessageFactory;
7
+ /** Sets the "p" tag of the user the message is addressed to */
8
+ recipient(pubkey: string): this;
7
9
  /** Sets the parent message "e" tag for NIP-04 reply threading */
8
10
  replyTo(parent: NostrEvent | string): this;
9
11
  }
@@ -1,17 +1,24 @@
1
1
  import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
2
2
  import { kinds } from "applesauce-core/helpers";
3
- import { setMessageParent } from "../operations/legacy-message.js";
3
+ import { setMessageAddress, setMessageParent } from "../operations/legacy-message.js";
4
4
  export class LegacyMessageFactory extends EventFactory {
5
5
  static create(recipient, message) {
6
- return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage))).encryptedContent(recipient, message, "nip04");
6
+ return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage)))
7
+ .recipient(recipient)
8
+ .encryptedContent(recipient, message, "nip04");
7
9
  }
8
10
  static reply(parent, recipient, message) {
9
11
  if (parent.kind !== kinds.EncryptedDirectMessage)
10
12
  throw new Error("Parent must be a legacy message (kind 4)");
11
13
  return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage)))
14
+ .recipient(recipient)
12
15
  .encryptedContent(recipient, message, "nip04")
13
16
  .replyTo(parent);
14
17
  }
18
+ /** Sets the "p" tag of the user the message is addressed to */
19
+ recipient(pubkey) {
20
+ return this.chain(setMessageAddress(pubkey));
21
+ }
15
22
  /** Sets the parent message "e" tag for NIP-04 reply threading */
16
23
  replyTo(parent) {
17
24
  return this.chain(setMessageParent(parent));
@@ -0,0 +1,20 @@
1
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { NAPPLET_KIND } from "../helpers/napplet.js";
3
+ import { NappletManifestFactory } from "./internal/napplet-manifest.js";
4
+ /** An event template for a named napplet manifest */
5
+ export type NamedNappletTemplate = KnownEventTemplate<typeof NAPPLET_KIND>;
6
+ /** A factory for named napplet manifests (kind 35129) */
7
+ export declare class NamedNappletFactory extends NappletManifestFactory<typeof NAPPLET_KIND> {
8
+ /**
9
+ * Creates a named napplet manifest
10
+ * @throws if the artifact hash is invalid
11
+ */
12
+ static create(identifier: string, artifactHash: string, description: string): NamedNappletFactory;
13
+ /**
14
+ * Creates a factory for modifying a named napplet manifest
15
+ * @throws if the event is not a valid named napplet manifest
16
+ */
17
+ static modify(event: NostrEvent): NamedNappletFactory;
18
+ /** Sets the named napplet's identifier */
19
+ identifier(value: string): this;
20
+ }
@@ -0,0 +1,30 @@
1
+ import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
2
+ import { isValidNamedNapplet, NAPPLET_KIND } from "../helpers/napplet.js";
3
+ import { NappletManifestFactory } from "./internal/napplet-manifest.js";
4
+ import { setNappletIdentifier } from "../operations/napplet.js";
5
+ /** A factory for named napplet manifests (kind 35129) */
6
+ export class NamedNappletFactory extends NappletManifestFactory {
7
+ /**
8
+ * Creates a named napplet manifest
9
+ * @throws if the artifact hash is invalid
10
+ */
11
+ static create(identifier, artifactHash, description) {
12
+ return new NamedNappletFactory((res) => res(blankEventTemplate(NAPPLET_KIND)))
13
+ .identifier(identifier)
14
+ .artifact(artifactHash)
15
+ .description(description);
16
+ }
17
+ /**
18
+ * Creates a factory for modifying a named napplet manifest
19
+ * @throws if the event is not a valid named napplet manifest
20
+ */
21
+ static modify(event) {
22
+ if (!isValidNamedNapplet(event))
23
+ throw new Error("Expected a named napplet manifest");
24
+ return new NamedNappletFactory((res) => res(toEventTemplate(event)));
25
+ }
26
+ /** Sets the named napplet's identifier */
27
+ identifier(value) {
28
+ return this.chain(setNappletIdentifier(value));
29
+ }
30
+ }
@@ -0,0 +1,28 @@
1
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { NSITE_KIND, NsiteFile } from "../helpers/nsite.js";
3
+ import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
4
+ /** An event template for a named nsite manifest */
5
+ export type NamedNsiteTemplate = KnownEventTemplate<typeof NSITE_KIND>;
6
+ /** A factory for named nsite manifests (kind 35128) */
7
+ export declare class NamedNsiteFactory extends NsiteManifestFactory<typeof NSITE_KIND> {
8
+ /**
9
+ * Creates a named nsite manifest
10
+ * @throws if the manifest is empty or a path, hash or identifier is invalid
11
+ */
12
+ static create(identifier: string, files: NsiteFile[]): NamedNsiteFactory;
13
+ /**
14
+ * Copies a root or named site into a new named manifest with copy lineage
15
+ * @throws if the source is invalid or is a snapshot, or the identifier is invalid
16
+ */
17
+ static copy(site: NostrEvent, identifier: string): NamedNsiteFactory;
18
+ /**
19
+ * Creates a factory for modifying a named nsite manifest
20
+ * @throws if the event is not a valid named nsite manifest
21
+ */
22
+ static modify(event: NostrEvent): NamedNsiteFactory;
23
+ /**
24
+ * Sets the named nsite's identifier
25
+ * @throws if the identifier is invalid
26
+ */
27
+ identifier(value: string): this;
28
+ }
@@ -0,0 +1,53 @@
1
+ import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
2
+ import { isValidNamedNsite, NSITE_KIND } from "../helpers/nsite.js";
3
+ import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
4
+ import { setNsiteIdentifier } from "../operations/nsite.js";
5
+ import { getReplaceableAddressForEvent } from "applesauce-core/helpers/pointers";
6
+ import { unixNow } from "applesauce-core/helpers/time";
7
+ import { isValidNsite, isNsiteSnapshot, getNsiteRootPointer } from "../helpers/nsite.js";
8
+ /** A factory for named nsite manifests (kind 35128) */
9
+ export class NamedNsiteFactory extends NsiteManifestFactory {
10
+ /**
11
+ * Creates a named nsite manifest
12
+ * @throws if the manifest is empty or a path, hash or identifier is invalid
13
+ */
14
+ static create(identifier, files) {
15
+ if (!files.length)
16
+ throw new Error("An nsite must include at least one file");
17
+ let factory = new NamedNsiteFactory((res) => res(blankEventTemplate(NSITE_KIND)));
18
+ for (const file of files)
19
+ factory = factory.file(file.path, file.sha256);
20
+ return factory.identifier(identifier);
21
+ }
22
+ /**
23
+ * Copies a root or named site into a new named manifest with copy lineage
24
+ * @throws if the source is invalid or is a snapshot, or the identifier is invalid
25
+ */
26
+ static copy(site, identifier) {
27
+ if (!isValidNsite(site) || isNsiteSnapshot(site))
28
+ throw new Error("Expected a root or named nsite");
29
+ const kind = NSITE_KIND;
30
+ const tags = site.tags.filter((t) => t[0] !== "d" && t[0] !== "a").map((t) => [...t]);
31
+ let factory = new NamedNsiteFactory((res) => res({ kind, created_at: unixNow(), content: site.content, tags })).parent(getReplaceableAddressForEvent(site));
32
+ if (!getNsiteRootPointer(site))
33
+ factory = factory.root(getReplaceableAddressForEvent(site));
34
+ factory = factory.identifier(identifier);
35
+ return factory;
36
+ }
37
+ /**
38
+ * Creates a factory for modifying a named nsite manifest
39
+ * @throws if the event is not a valid named nsite manifest
40
+ */
41
+ static modify(event) {
42
+ if (!isValidNamedNsite(event))
43
+ throw new Error("Expected a named nsite manifest");
44
+ return new NamedNsiteFactory((res) => res(toEventTemplate(event)));
45
+ }
46
+ /**
47
+ * Sets the named nsite's identifier
48
+ * @throws if the identifier is invalid
49
+ */
50
+ identifier(value) {
51
+ return this.chain(setNsiteIdentifier(value));
52
+ }
53
+ }
@@ -0,0 +1,18 @@
1
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { NAPPLET_SNAPSHOT_KIND } from "../helpers/napplet.js";
3
+ import { NappletManifestFactory } from "./internal/napplet-manifest.js";
4
+ /** An event template for a snapshot napplet manifest */
5
+ export type NappletSnapshotTemplate = KnownEventTemplate<typeof NAPPLET_SNAPSHOT_KIND>;
6
+ /** A factory for snapshot napplet manifests (kind 5129) */
7
+ export declare class NappletSnapshotFactory extends NappletManifestFactory<typeof NAPPLET_SNAPSHOT_KIND> {
8
+ /**
9
+ * Creates a snapshot of the current manifest and preserves its lineage
10
+ * @throws if the source is invalid
11
+ */
12
+ static create(napplet: NostrEvent): NappletSnapshotFactory;
13
+ /**
14
+ * Creates a factory for modifying a snapshot napplet manifest
15
+ * @throws if the event is not a valid snapshot napplet manifest
16
+ */
17
+ static modify(event: NostrEvent): NappletSnapshotFactory;
18
+ }
@@ -0,0 +1,38 @@
1
+ import { toEventTemplate } from "applesauce-core/factories";
2
+ import { isValidNappletSnapshot, NAPPLET_SNAPSHOT_KIND } from "../helpers/napplet.js";
3
+ import { NappletManifestFactory } from "./internal/napplet-manifest.js";
4
+ import { getReplaceableAddressForEvent } from "applesauce-core/helpers/pointers";
5
+ import { unixNow } from "applesauce-core/helpers/time";
6
+ import { isValidNapplet, isNappletSnapshot } from "../helpers/napplet.js";
7
+ /** A factory for snapshot napplet manifests (kind 5129) */
8
+ export class NappletSnapshotFactory extends NappletManifestFactory {
9
+ /**
10
+ * Creates a snapshot of the current manifest and preserves its lineage
11
+ * @throws if the source is invalid
12
+ */
13
+ static create(napplet) {
14
+ if (!isValidNapplet(napplet))
15
+ throw new Error("Expected a napplet manifest event");
16
+ // A snapshot of a snapshot keeps the source lineage since snapshots cannot be addressed
17
+ const coordinate = getReplaceableAddressForEvent(napplet);
18
+ const lineage = (name) => napplet.tags.find((t) => t[0] === name && t[1])?.[1];
19
+ const parent = isNappletSnapshot(napplet) ? lineage("a") : coordinate;
20
+ const root = isNappletSnapshot(napplet) ? lineage("A") : coordinate;
21
+ const tags = napplet.tags.filter((t) => t[0] !== "d" && t[0] !== "a" && t[0] !== "A");
22
+ let factory = new NappletSnapshotFactory((res) => res({ kind: NAPPLET_SNAPSHOT_KIND, created_at: unixNow(), content: napplet.content, tags }));
23
+ if (parent)
24
+ factory = factory.parent(parent);
25
+ if (root)
26
+ factory = factory.root(root);
27
+ return factory;
28
+ }
29
+ /**
30
+ * Creates a factory for modifying a snapshot napplet manifest
31
+ * @throws if the event is not a valid snapshot napplet manifest
32
+ */
33
+ static modify(event) {
34
+ if (!isValidNappletSnapshot(event))
35
+ throw new Error("Expected a snapshot napplet manifest");
36
+ return new NappletSnapshotFactory((res) => res(toEventTemplate(event)));
37
+ }
38
+ }
@@ -0,0 +1,18 @@
1
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { NSITE_SNAPSHOT_KIND } from "../helpers/nsite.js";
3
+ import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
4
+ /** An event template for a snapshot nsite manifest */
5
+ export type NsiteSnapshotTemplate = KnownEventTemplate<typeof NSITE_SNAPSHOT_KIND>;
6
+ /** A factory for snapshot nsite manifests (kind 5128) */
7
+ export declare class NsiteSnapshotFactory extends NsiteManifestFactory<typeof NSITE_SNAPSHOT_KIND> {
8
+ /**
9
+ * Creates a snapshot of the current manifest and preserves its lineage
10
+ * @throws if the source is invalid, is a snapshot, or lacks an aggregate hash
11
+ */
12
+ static create(site: NostrEvent): NsiteSnapshotFactory;
13
+ /**
14
+ * Creates a factory for modifying a snapshot nsite manifest
15
+ * @throws if the event is not a valid snapshot nsite manifest
16
+ */
17
+ static modify(event: NostrEvent): NsiteSnapshotFactory;
18
+ }
@@ -0,0 +1,29 @@
1
+ import { toEventTemplate } from "applesauce-core/factories";
2
+ import { isValidNsiteSnapshot, NSITE_SNAPSHOT_KIND } from "../helpers/nsite.js";
3
+ import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
4
+ import { getReplaceableAddressForEvent } from "applesauce-core/helpers/pointers";
5
+ import { unixNow } from "applesauce-core/helpers/time";
6
+ import { isValidNsite, isNsiteSnapshot } from "../helpers/nsite.js";
7
+ /** A factory for snapshot nsite manifests (kind 5128) */
8
+ export class NsiteSnapshotFactory extends NsiteManifestFactory {
9
+ /**
10
+ * Creates a snapshot of the current manifest and preserves its lineage
11
+ * @throws if the source is invalid, is a snapshot, or lacks an aggregate hash
12
+ */
13
+ static create(site) {
14
+ if (!isValidNsite(site) || isNsiteSnapshot(site) || !site.tags.some((t) => t[0] === "x" && t[2] === "aggregate"))
15
+ throw new Error("Expected a root or named nsite with an aggregate hash");
16
+ // Preserve the source x and A tags unchanged; a identifies the site being snapshotted.
17
+ const tags = site.tags.filter((t) => t[0] !== "d" && t[0] !== "a").map((t) => [...t]);
18
+ return new NsiteSnapshotFactory((res) => res({ kind: NSITE_SNAPSHOT_KIND, created_at: unixNow(), content: site.content, tags })).parent(getReplaceableAddressForEvent(site));
19
+ }
20
+ /**
21
+ * Creates a factory for modifying a snapshot nsite manifest
22
+ * @throws if the event is not a valid snapshot nsite manifest
23
+ */
24
+ static modify(event) {
25
+ if (!isValidNsiteSnapshot(event))
26
+ throw new Error("Expected a snapshot nsite manifest");
27
+ return new NsiteSnapshotFactory((res) => res(toEventTemplate(event)));
28
+ }
29
+ }
@@ -1,5 +1,6 @@
1
1
  import { EventFactory } from "applesauce-core/factories";
2
2
  import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
3
+ import { ReactionParent } from "../operations/reaction.js";
3
4
  import { Emoji } from "../helpers/emoji.js";
4
5
  export type ReactionTemplate = KnownEventTemplate<kinds.Reaction>;
5
6
  /** A factory class for building kind 7 reaction events */
@@ -10,13 +11,13 @@ export declare class ReactionFactory extends EventFactory<kinds.Reaction, Reacti
10
11
  * @param emoji - The emoji to react with (default: "+")
11
12
  * @returns A new reaction factory
12
13
  */
13
- static create(event: NostrEvent, emoji?: string | Emoji): ReactionFactory;
14
+ static create(event: ReactionParent, emoji?: string | Emoji): ReactionFactory;
14
15
  /** Creates a "+" like reaction for an event */
15
16
  static like(event: NostrEvent): ReactionFactory;
16
17
  /** Creates a "-" dislike reaction for an event */
17
18
  static dislike(event: NostrEvent): ReactionFactory;
18
19
  /** Sets the parent event being reacted to */
19
- reactTo(event: NostrEvent): this;
20
+ reactTo(event: ReactionParent): this;
20
21
  /** Sets the reaction emoji */
21
22
  reaction(emoji: "+" | "-" | string | Emoji): this;
22
23
  }
@@ -0,0 +1,48 @@
1
+ import { EventFactory } from "applesauce-core/factories";
2
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
3
+ import { REPORT_KIND, ReportReason, ReportTarget } from "../helpers/reports.js";
4
+ import { ReportEventTarget } from "../operations/report.js";
5
+ /** A kind 1984 report draft */
6
+ export type ReportTemplate = KnownEventTemplate<typeof REPORT_KIND>;
7
+ /** A factory for NIP-56 reports */
8
+ export declare class ReportFactory extends EventFactory<typeof REPORT_KIND, ReportTemplate> {
9
+ /**
10
+ * Creates a user or event report
11
+ * @throws if the target identity or reason is invalid
12
+ */
13
+ static create(target: string | ReportEventTarget, reason: ReportReason): ReportFactory;
14
+ /**
15
+ * Creates a blob report with its containing event and author
16
+ * @throws if the hash, event identity, or reason is invalid
17
+ */
18
+ static blob(hash: string, event: ReportEventTarget, reason: ReportReason): ReportFactory;
19
+ /**
20
+ * Creates a factory from an existing report
21
+ * @throws if the event is not kind 1984
22
+ */
23
+ static modify(event: NostrEvent): ReportFactory;
24
+ /**
25
+ * Adds or updates a reported user
26
+ * @throws if the public key or reason is invalid
27
+ */
28
+ reportUser(pubkey: string, reason: ReportReason): this;
29
+ /**
30
+ * Adds or updates a reported event
31
+ * @throws if the event identity or reason is invalid
32
+ */
33
+ reportEvent(event: ReportEventTarget, reason: ReportReason): this;
34
+ /**
35
+ * Adds or updates a reported blob
36
+ * @throws if the hash, event identity, or reason is invalid
37
+ */
38
+ reportBlob(hash: string, event: ReportEventTarget, reason: ReportReason): this;
39
+ /** Removes a target tag while preserving unrelated tags */
40
+ removeTarget(type: ReportTarget["type"], value: string): this;
41
+ /**
42
+ * Adds a media server or direct media URL
43
+ * @throws if the URL is invalid or does not use HTTP or HTTPS
44
+ */
45
+ server(url: string): this;
46
+ /** Removes a media server or direct media URL */
47
+ removeServer(url: string): this;
48
+ }
@@ -0,0 +1,66 @@
1
+ import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
2
+ import { REPORT_KIND } from "../helpers/reports.js";
3
+ import { addReportBlob, addReportEvent, addReportServer, addReportUser, removeReportServer, removeReportTarget, } from "../operations/report.js";
4
+ /** A factory for NIP-56 reports */
5
+ export class ReportFactory extends EventFactory {
6
+ /**
7
+ * Creates a user or event report
8
+ * @throws if the target identity or reason is invalid
9
+ */
10
+ static create(target, reason) {
11
+ const factory = new ReportFactory((resolve) => resolve(blankEventTemplate(REPORT_KIND)));
12
+ return typeof target === "string" ? factory.reportUser(target, reason) : factory.reportEvent(target, reason);
13
+ }
14
+ /**
15
+ * Creates a blob report with its containing event and author
16
+ * @throws if the hash, event identity, or reason is invalid
17
+ */
18
+ static blob(hash, event, reason) {
19
+ return new ReportFactory((resolve) => resolve(blankEventTemplate(REPORT_KIND))).reportBlob(hash, event, reason);
20
+ }
21
+ /**
22
+ * Creates a factory from an existing report
23
+ * @throws if the event is not kind 1984
24
+ */
25
+ static modify(event) {
26
+ if (event.kind !== REPORT_KIND)
27
+ throw new Error("Expected a report event");
28
+ return new ReportFactory((resolve) => resolve(toEventTemplate(event)));
29
+ }
30
+ /**
31
+ * Adds or updates a reported user
32
+ * @throws if the public key or reason is invalid
33
+ */
34
+ reportUser(pubkey, reason) {
35
+ return this.chain(addReportUser(pubkey, reason));
36
+ }
37
+ /**
38
+ * Adds or updates a reported event
39
+ * @throws if the event identity or reason is invalid
40
+ */
41
+ reportEvent(event, reason) {
42
+ return this.chain(addReportEvent(event, reason));
43
+ }
44
+ /**
45
+ * Adds or updates a reported blob
46
+ * @throws if the hash, event identity, or reason is invalid
47
+ */
48
+ reportBlob(hash, event, reason) {
49
+ return this.chain(addReportBlob(hash, event, reason));
50
+ }
51
+ /** Removes a target tag while preserving unrelated tags */
52
+ removeTarget(type, value) {
53
+ return this.chain(removeReportTarget(type, value));
54
+ }
55
+ /**
56
+ * Adds a media server or direct media URL
57
+ * @throws if the URL is invalid or does not use HTTP or HTTPS
58
+ */
59
+ server(url) {
60
+ return this.chain(addReportServer(url));
61
+ }
62
+ /** Removes a media server or direct media URL */
63
+ removeServer(url) {
64
+ return this.chain(removeReportServer(url));
65
+ }
66
+ }
@@ -0,0 +1,18 @@
1
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { NAPPLET_ROOT_KIND } from "../helpers/napplet.js";
3
+ import { NappletManifestFactory } from "./internal/napplet-manifest.js";
4
+ /** An event template for a root napplet manifest */
5
+ export type RootNappletTemplate = KnownEventTemplate<typeof NAPPLET_ROOT_KIND>;
6
+ /** A factory for root napplet manifests (kind 15129) */
7
+ export declare class RootNappletFactory extends NappletManifestFactory<typeof NAPPLET_ROOT_KIND> {
8
+ /**
9
+ * Creates a root napplet manifest
10
+ * @throws if the artifact hash is invalid
11
+ */
12
+ static create(artifactHash: string, description: string): RootNappletFactory;
13
+ /**
14
+ * Creates a factory for modifying a root napplet manifest
15
+ * @throws if the event is not a valid root napplet manifest
16
+ */
17
+ static modify(event: NostrEvent): RootNappletFactory;
18
+ }
@@ -0,0 +1,24 @@
1
+ import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
2
+ import { isValidRootNapplet, NAPPLET_ROOT_KIND } from "../helpers/napplet.js";
3
+ import { NappletManifestFactory } from "./internal/napplet-manifest.js";
4
+ /** A factory for root napplet manifests (kind 15129) */
5
+ export class RootNappletFactory extends NappletManifestFactory {
6
+ /**
7
+ * Creates a root napplet manifest
8
+ * @throws if the artifact hash is invalid
9
+ */
10
+ static create(artifactHash, description) {
11
+ return new RootNappletFactory((res) => res(blankEventTemplate(NAPPLET_ROOT_KIND)))
12
+ .artifact(artifactHash)
13
+ .description(description);
14
+ }
15
+ /**
16
+ * Creates a factory for modifying a root napplet manifest
17
+ * @throws if the event is not a valid root napplet manifest
18
+ */
19
+ static modify(event) {
20
+ if (!isValidRootNapplet(event))
21
+ throw new Error("Expected a root napplet manifest");
22
+ return new RootNappletFactory((res) => res(toEventTemplate(event)));
23
+ }
24
+ }
@@ -0,0 +1,23 @@
1
+ import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { NSITE_ROOT_KIND, NsiteFile } from "../helpers/nsite.js";
3
+ import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
4
+ /** An event template for a root nsite manifest */
5
+ export type RootNsiteTemplate = KnownEventTemplate<typeof NSITE_ROOT_KIND>;
6
+ /** A factory for root nsite manifests (kind 15128) */
7
+ export declare class RootNsiteFactory extends NsiteManifestFactory<typeof NSITE_ROOT_KIND> {
8
+ /**
9
+ * Creates a root nsite manifest
10
+ * @throws if the manifest is empty or a path or hash is invalid
11
+ */
12
+ static create(files: NsiteFile[]): RootNsiteFactory;
13
+ /**
14
+ * Copies a root or named site into a new root manifest with copy lineage
15
+ * @throws if the source is invalid or is a snapshot
16
+ */
17
+ static copy(site: NostrEvent): RootNsiteFactory;
18
+ /**
19
+ * Creates a factory for modifying a root nsite manifest
20
+ * @throws if the event is not a valid root nsite manifest
21
+ */
22
+ static modify(event: NostrEvent): RootNsiteFactory;
23
+ }
@@ -0,0 +1,44 @@
1
+ import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
2
+ import { isValidRootNsite, NSITE_ROOT_KIND } from "../helpers/nsite.js";
3
+ import { NsiteManifestFactory } from "./internal/nsite-manifest.js";
4
+ import { getReplaceableAddressForEvent } from "applesauce-core/helpers/pointers";
5
+ import { unixNow } from "applesauce-core/helpers/time";
6
+ import { isValidNsite, isNsiteSnapshot, getNsiteRootPointer } from "../helpers/nsite.js";
7
+ /** A factory for root nsite manifests (kind 15128) */
8
+ export class RootNsiteFactory extends NsiteManifestFactory {
9
+ /**
10
+ * Creates a root nsite manifest
11
+ * @throws if the manifest is empty or a path or hash is invalid
12
+ */
13
+ static create(files) {
14
+ if (!files.length)
15
+ throw new Error("An nsite must include at least one file");
16
+ let factory = new RootNsiteFactory((res) => res(blankEventTemplate(NSITE_ROOT_KIND)));
17
+ for (const file of files)
18
+ factory = factory.file(file.path, file.sha256);
19
+ return factory;
20
+ }
21
+ /**
22
+ * Copies a root or named site into a new root manifest with copy lineage
23
+ * @throws if the source is invalid or is a snapshot
24
+ */
25
+ static copy(site) {
26
+ if (!isValidNsite(site) || isNsiteSnapshot(site))
27
+ throw new Error("Expected a root or named nsite");
28
+ const kind = NSITE_ROOT_KIND;
29
+ const tags = site.tags.filter((t) => t[0] !== "d" && t[0] !== "a").map((t) => [...t]);
30
+ let factory = new RootNsiteFactory((res) => res({ kind, created_at: unixNow(), content: site.content, tags })).parent(getReplaceableAddressForEvent(site));
31
+ if (!getNsiteRootPointer(site))
32
+ factory = factory.root(getReplaceableAddressForEvent(site));
33
+ return factory;
34
+ }
35
+ /**
36
+ * Creates a factory for modifying a root nsite manifest
37
+ * @throws if the event is not a valid root nsite manifest
38
+ */
39
+ static modify(event) {
40
+ if (!isValidRootNsite(event))
41
+ throw new Error("Expected a root nsite manifest");
42
+ return new RootNsiteFactory((res) => res(toEventTemplate(event)));
43
+ }
44
+ }