applesauce-common 6.1.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/README.md +1 -0
  2. package/dist/casts/_circular-import.d.ts +3 -0
  3. package/dist/casts/_circular-import.js +3 -0
  4. package/dist/casts/app-handler.d.ts +56 -0
  5. package/dist/casts/app-handler.js +105 -0
  6. package/dist/casts/app-recommendation.d.ts +26 -0
  7. package/dist/casts/app-recommendation.js +41 -0
  8. package/dist/casts/external-identities.d.ts +9 -0
  9. package/dist/casts/external-identities.js +14 -0
  10. package/dist/casts/forum-thread.d.ts +17 -0
  11. package/dist/casts/forum-thread.js +31 -0
  12. package/dist/casts/git-issue.d.ts +18 -0
  13. package/dist/casts/git-issue.js +26 -0
  14. package/dist/casts/git-patch.d.ts +49 -0
  15. package/dist/casts/git-patch.js +88 -0
  16. package/dist/casts/git-pull-request.d.ts +67 -0
  17. package/dist/casts/git-pull-request.js +122 -0
  18. package/dist/casts/git-repository.d.ts +9 -0
  19. package/dist/casts/git-repository.js +16 -0
  20. package/dist/casts/git-thread.d.ts +33 -0
  21. package/dist/casts/git-thread.js +65 -0
  22. package/dist/casts/index.d.ts +11 -0
  23. package/dist/casts/index.js +11 -0
  24. package/dist/casts/napplet.d.ts +98 -0
  25. package/dist/casts/napplet.js +196 -0
  26. package/dist/casts/note.d.ts +8 -0
  27. package/dist/casts/note.js +21 -1
  28. package/dist/casts/nsite.d.ts +134 -0
  29. package/dist/casts/nsite.js +249 -0
  30. package/dist/casts/profile.d.ts +20 -0
  31. package/dist/casts/profile.js +30 -0
  32. package/dist/casts/reaction.d.ts +1 -1
  33. package/dist/casts/relay-discovery.d.ts +4 -0
  34. package/dist/casts/relay-discovery.js +9 -1
  35. package/dist/casts/report.d.ts +28 -15
  36. package/dist/casts/report.js +42 -19
  37. package/dist/casts/share.d.ts +1 -1
  38. package/dist/casts/torrent.d.ts +5 -0
  39. package/dist/casts/torrent.js +8 -1
  40. package/dist/casts/trusted-assertions.d.ts +4 -2
  41. package/dist/casts/trusted-assertions.js +20 -19
  42. package/dist/casts/user-status.d.ts +33 -0
  43. package/dist/casts/user-status.js +69 -0
  44. package/dist/casts/user.d.ts +7 -0
  45. package/dist/casts/user.js +20 -1
  46. package/dist/factories/app-handler.d.ts +31 -0
  47. package/dist/factories/app-handler.js +50 -0
  48. package/dist/factories/app-recommendation.d.ts +21 -0
  49. package/dist/factories/app-recommendation.js +28 -0
  50. package/dist/factories/chat-message.d.ts +37 -0
  51. package/dist/factories/chat-message.js +56 -0
  52. package/dist/factories/comment.d.ts +8 -7
  53. package/dist/factories/comment.js +2 -2
  54. package/dist/factories/external-identities.d.ts +17 -0
  55. package/dist/factories/external-identities.js +28 -0
  56. package/dist/factories/forum-thread.d.ts +34 -0
  57. package/dist/factories/forum-thread.js +50 -0
  58. package/dist/factories/git-applied-status.d.ts +39 -0
  59. package/dist/factories/git-applied-status.js +53 -0
  60. package/dist/factories/git-closed-status.d.ts +18 -0
  61. package/dist/factories/git-closed-status.js +24 -0
  62. package/dist/factories/git-draft-status.d.ts +18 -0
  63. package/dist/factories/git-draft-status.js +24 -0
  64. package/dist/factories/git-issue.d.ts +19 -0
  65. package/dist/factories/git-issue.js +25 -0
  66. package/dist/factories/git-open-status.d.ts +18 -0
  67. package/dist/factories/git-open-status.js +22 -0
  68. package/dist/factories/git-patch.d.ts +59 -0
  69. package/dist/factories/git-patch.js +102 -0
  70. package/dist/factories/git-pull-request-update.d.ts +23 -0
  71. package/dist/factories/git-pull-request-update.js +33 -0
  72. package/dist/factories/git-pull-request.d.ts +39 -0
  73. package/dist/factories/git-pull-request.js +64 -0
  74. package/dist/factories/index.d.ts +23 -0
  75. package/dist/factories/index.js +23 -0
  76. package/dist/factories/internal/git-pull-request.d.ts +19 -0
  77. package/dist/factories/internal/git-pull-request.js +26 -0
  78. package/dist/factories/internal/git-status.d.ts +11 -0
  79. package/dist/factories/internal/git-status.js +12 -0
  80. package/dist/factories/internal/git-thread.d.ts +19 -0
  81. package/dist/factories/internal/git-thread.js +29 -0
  82. package/dist/factories/internal/napplet-manifest.d.ts +52 -0
  83. package/dist/factories/internal/napplet-manifest.js +85 -0
  84. package/dist/factories/internal/nsite-manifest.d.ts +45 -0
  85. package/dist/factories/internal/nsite-manifest.js +68 -0
  86. package/dist/factories/legacy-message.d.ts +2 -0
  87. package/dist/factories/legacy-message.js +9 -2
  88. package/dist/factories/named-napplet.d.ts +20 -0
  89. package/dist/factories/named-napplet.js +30 -0
  90. package/dist/factories/named-nsite.d.ts +28 -0
  91. package/dist/factories/named-nsite.js +53 -0
  92. package/dist/factories/napplet-snapshot.d.ts +18 -0
  93. package/dist/factories/napplet-snapshot.js +38 -0
  94. package/dist/factories/nostr-web-token.d.ts +39 -0
  95. package/dist/factories/nostr-web-token.js +95 -0
  96. package/dist/factories/nsite-snapshot.d.ts +18 -0
  97. package/dist/factories/nsite-snapshot.js +29 -0
  98. package/dist/factories/reaction.d.ts +3 -2
  99. package/dist/factories/report.d.ts +48 -0
  100. package/dist/factories/report.js +66 -0
  101. package/dist/factories/root-napplet.d.ts +18 -0
  102. package/dist/factories/root-napplet.js +24 -0
  103. package/dist/factories/root-nsite.d.ts +23 -0
  104. package/dist/factories/root-nsite.js +44 -0
  105. package/dist/factories/torrent.d.ts +24 -10
  106. package/dist/factories/torrent.js +48 -44
  107. package/dist/factories/trusted-provider-list.d.ts +23 -0
  108. package/dist/factories/trusted-provider-list.js +39 -0
  109. package/dist/factories/user-status.d.ts +26 -0
  110. package/dist/factories/user-status.js +52 -0
  111. package/dist/helpers/app-data.js +15 -7
  112. package/dist/helpers/app-handler.d.ts +43 -6
  113. package/dist/helpers/app-handler.js +53 -3
  114. package/dist/helpers/app-recommendation.d.ts +24 -0
  115. package/dist/helpers/app-recommendation.js +30 -0
  116. package/dist/helpers/bookmark.js +5 -2
  117. package/dist/helpers/comment.d.ts +11 -5
  118. package/dist/helpers/comment.js +7 -1
  119. package/dist/helpers/content.d.ts +3 -1
  120. package/dist/helpers/emoji-pack.js +11 -6
  121. package/dist/helpers/emoji.d.ts +2 -2
  122. package/dist/helpers/encrypted-content-cache.js +18 -1
  123. package/dist/helpers/external-id.d.ts +1 -0
  124. package/dist/helpers/external-id.js +21 -46
  125. package/dist/helpers/external-identities.d.ts +29 -0
  126. package/dist/helpers/external-identities.js +52 -0
  127. package/dist/helpers/file-metadata.js +5 -6
  128. package/dist/helpers/forum-thread.d.ts +10 -0
  129. package/dist/helpers/forum-thread.js +10 -0
  130. package/dist/helpers/gift-wrap.d.ts +40 -15
  131. package/dist/helpers/gift-wrap.js +110 -33
  132. package/dist/helpers/git-issue.d.ts +13 -0
  133. package/dist/helpers/git-issue.js +19 -0
  134. package/dist/helpers/git-patch.d.ts +41 -0
  135. package/dist/helpers/git-patch.js +73 -0
  136. package/dist/helpers/git-pull-request.d.ts +57 -0
  137. package/dist/helpers/git-pull-request.js +111 -0
  138. package/dist/helpers/git-repository.d.ts +4 -0
  139. package/dist/helpers/git-repository.js +16 -0
  140. package/dist/helpers/git-status.d.ts +44 -0
  141. package/dist/helpers/git-status.js +93 -0
  142. package/dist/helpers/git.d.ts +2 -0
  143. package/dist/helpers/git.js +4 -0
  144. package/dist/helpers/groups.d.ts +5 -2
  145. package/dist/helpers/groups.js +40 -18
  146. package/dist/helpers/hashtag.d.ts +4 -2
  147. package/dist/helpers/index.d.ts +11 -0
  148. package/dist/helpers/index.js +11 -0
  149. package/dist/helpers/lists.js +14 -2
  150. package/dist/helpers/lnurl.js +1 -1
  151. package/dist/helpers/mute.js +18 -7
  152. package/dist/helpers/napplet.d.ts +89 -0
  153. package/dist/helpers/napplet.js +144 -0
  154. package/dist/helpers/nostr-web-token.d.ts +54 -0
  155. package/dist/helpers/nostr-web-token.js +124 -0
  156. package/dist/helpers/nsite.d.ts +90 -0
  157. package/dist/helpers/nsite.js +217 -0
  158. package/dist/helpers/relay-discovery.d.ts +4 -0
  159. package/dist/helpers/relay-discovery.js +8 -0
  160. package/dist/helpers/reports.d.ts +35 -0
  161. package/dist/helpers/reports.js +36 -5
  162. package/dist/helpers/threading.d.ts +4 -2
  163. package/dist/helpers/torrent.d.ts +9 -6
  164. package/dist/helpers/torrent.js +23 -15
  165. package/dist/helpers/trusted-assertions.d.ts +7 -0
  166. package/dist/helpers/trusted-assertions.js +41 -2
  167. package/dist/helpers/user-status.d.ts +13 -1
  168. package/dist/helpers/user-status.js +15 -0
  169. package/dist/models/app-handler.d.ts +21 -0
  170. package/dist/models/app-handler.js +47 -0
  171. package/dist/models/git.d.ts +34 -0
  172. package/dist/models/git.js +144 -0
  173. package/dist/models/index.d.ts +3 -0
  174. package/dist/models/index.js +3 -0
  175. package/dist/models/nsite.d.ts +22 -0
  176. package/dist/models/nsite.js +67 -0
  177. package/dist/models/thread.d.ts +4 -1
  178. package/dist/models/thread.js +34 -5
  179. package/dist/models/user-status.d.ts +8 -4
  180. package/dist/models/user-status.js +16 -22
  181. package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
  182. package/dist/observable/filter-timeline-by-mutes.js +5 -1
  183. package/dist/operations/app-handler.d.ts +24 -0
  184. package/dist/operations/app-handler.js +58 -0
  185. package/dist/operations/app-recommendation.d.ts +13 -0
  186. package/dist/operations/app-recommendation.js +40 -0
  187. package/dist/operations/calendar-event.js +3 -2
  188. package/dist/operations/chat-message.d.ts +9 -0
  189. package/dist/operations/chat-message.js +12 -0
  190. package/dist/operations/client.d.ts +1 -4
  191. package/dist/operations/client.js +1 -23
  192. package/dist/operations/comment.d.ts +9 -3
  193. package/dist/operations/comment.js +12 -9
  194. package/dist/operations/external-identities.d.ts +8 -0
  195. package/dist/operations/external-identities.js +23 -0
  196. package/dist/operations/forum-thread.d.ts +3 -0
  197. package/dist/operations/forum-thread.js +6 -0
  198. package/dist/operations/gift-wrap.js +38 -14
  199. package/dist/operations/git-issue.d.ts +18 -0
  200. package/dist/operations/git-issue.js +31 -0
  201. package/dist/operations/git-patch.d.ts +30 -0
  202. package/dist/operations/git-patch.js +75 -0
  203. package/dist/operations/git-pull-request.d.ts +29 -0
  204. package/dist/operations/git-pull-request.js +74 -0
  205. package/dist/operations/git-repository.js +4 -4
  206. package/dist/operations/git-status.d.ts +28 -0
  207. package/dist/operations/git-status.js +116 -0
  208. package/dist/operations/git-thread.d.ts +13 -0
  209. package/dist/operations/git-thread.js +39 -0
  210. package/dist/operations/index.d.ts +16 -0
  211. package/dist/operations/index.js +16 -0
  212. package/dist/operations/internal/git-commits.d.ts +2 -0
  213. package/dist/operations/internal/git-commits.js +16 -0
  214. package/dist/operations/napplet.d.ts +51 -0
  215. package/dist/operations/napplet.js +121 -0
  216. package/dist/operations/nostr-web-token.d.ts +27 -0
  217. package/dist/operations/nostr-web-token.js +58 -0
  218. package/dist/operations/nsite.d.ts +51 -0
  219. package/dist/operations/nsite.js +112 -0
  220. package/dist/operations/reaction.d.ts +12 -2
  221. package/dist/operations/reaction.js +1 -1
  222. package/dist/operations/report.d.ts +33 -0
  223. package/dist/operations/report.js +60 -0
  224. package/dist/operations/stream.js +5 -4
  225. package/dist/operations/torrent.d.ts +1 -4
  226. package/dist/operations/torrent.js +24 -11
  227. package/dist/operations/trusted-providers.d.ts +14 -0
  228. package/dist/operations/trusted-providers.js +33 -0
  229. package/dist/operations/user-status.d.ts +11 -0
  230. package/dist/operations/user-status.js +29 -0
  231. package/package.json +10 -10
@@ -0,0 +1,67 @@
1
+ import { getReplaceableAddressForEvent, getReplaceableAddressFromPointer, } from "applesauce-core/helpers/pointers";
2
+ import { map } from "rxjs";
3
+ import { isValidNsite, isValidNsiteSnapshot, isValidRootNsite, NSITE_KIND, NSITE_ROOT_KIND, NSITE_SNAPSHOT_KIND, } from "../helpers/nsite.js";
4
+ function coordinate(site) {
5
+ return typeof site === "string"
6
+ ? site
7
+ : "id" in site
8
+ ? getReplaceableAddressForEvent(site)
9
+ : getReplaceableAddressFromPointer(site);
10
+ }
11
+ /** A model that resolves a site or snapshot pointer and validates its manifest */
12
+ export function NsiteModel(pointer) {
13
+ return (store) => store.event(pointer).pipe(map((event) => (isValidNsite(event) ? event : undefined)));
14
+ }
15
+ /** A model that returns a user's root and named sites */
16
+ export function UserNsitesModel(user) {
17
+ const pubkey = typeof user === "string" ? user : user.pubkey;
18
+ return (store) => store
19
+ .timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND], authors: [pubkey] })
20
+ .pipe(map((events) => events.filter(isValidNsite)));
21
+ }
22
+ /** A model that returns a user's root site */
23
+ export function RootNsiteModel(user) {
24
+ const pointer = typeof user === "string" ? { pubkey: user } : user;
25
+ return (store) => store
26
+ .replaceable({ ...pointer, kind: NSITE_ROOT_KIND })
27
+ .pipe(map((event) => (isValidRootNsite(event) ? event : undefined)));
28
+ }
29
+ /** A model that returns a user's manifest snapshots */
30
+ export function UserNsiteSnapshotsModel(user) {
31
+ const pubkey = typeof user === "string" ? user : user.pubkey;
32
+ return (store) => store
33
+ .timeline({ kinds: [NSITE_SNAPSHOT_KIND], authors: [pubkey] })
34
+ .pipe(map((events) => events.filter(isValidNsiteSnapshot)));
35
+ }
36
+ /** A model that returns snapshots of a specific site */
37
+ export function NsiteSnapshotsModel(site) {
38
+ return (store) => store
39
+ .timeline({ kinds: [NSITE_SNAPSHOT_KIND], "#a": [coordinate(site)] })
40
+ .pipe(map((events) => events.filter(isValidNsiteSnapshot)));
41
+ }
42
+ /** A model that returns sites copied directly from a site */
43
+ export function NsiteCopiesModel(site) {
44
+ return (store) => store
45
+ .timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND], "#a": [coordinate(site)] })
46
+ .pipe(map((events) => events.filter(isValidNsite)));
47
+ }
48
+ /** A model that returns copied sites and snapshots with a shared lineage origin */
49
+ export function NsiteLineageModel(site) {
50
+ return (store) => store
51
+ .timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND, NSITE_SNAPSHOT_KIND], "#A": [coordinate(site)] })
52
+ .pipe(map((events) => events.filter(isValidNsite)));
53
+ }
54
+ /** A model that returns manifests belonging to an upstream app descriptor */
55
+ export function AppNsitesModel(app) {
56
+ const address = coordinate(app);
57
+ // NIP-01 indexes only single-letter tags; app linkage must be filtered locally.
58
+ return (store) => store
59
+ .timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND, NSITE_SNAPSHOT_KIND] })
60
+ .pipe(map((events) => events.filter((event) => isValidNsite(event) && event.tags.some((tag) => tag[0] === "app" && tag[1] === address))));
61
+ }
62
+ /** A model that returns manifests advertising an aggregate hash */
63
+ export function NsitesByHashModel(hash) {
64
+ return (store) => store
65
+ .timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND, NSITE_SNAPSHOT_KIND], "#x": [hash] })
66
+ .pipe(map((events) => events.filter(isValidNsite)));
67
+ }
@@ -19,9 +19,12 @@ export type ThreadItem = {
19
19
  replies: Set<ThreadItem>;
20
20
  };
21
21
  export type ThreadModelOptions = {
22
+ /** The NIP-10 reply kinds to include, defaults to kind 1 */
22
23
  kinds?: number[];
24
+ /** Whether to include NIP-22 comments, defaults to true */
25
+ comments?: boolean;
23
26
  };
24
- /** A model that returns a NIP-10 thread of events */
27
+ /** A model that returns a thread of NIP-10 replies and NIP-22 comments */
25
28
  export declare function ThreadModel(root: string | AddressPointer | EventPointer, opts?: ThreadModelOptions): Model<Thread>;
26
29
  /** A model that gets all legacy and NIP-10, and NIP-22 replies for an event */
27
30
  export declare function RepliesModel(event: NostrEvent | EventPointer | AddressPointer, overrideKinds?: number[]): Model<NostrEvent[]>;
@@ -3,39 +3,68 @@ import { buildCommonEventRelationFilters } from "applesauce-core/helpers";
3
3
  import { getEventUID, kinds } from "applesauce-core/helpers/event";
4
4
  import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer, isAddressPointerSame, isEventPointer, isEventPointerSame, } from "applesauce-core/helpers/pointers";
5
5
  import { map } from "rxjs/operators";
6
- import { COMMENT_KIND, getCommentReplyPointer } from "../helpers/comment.js";
6
+ import { COMMENT_KIND, getCommentReplyPointer, getCommentRootPointer } from "../helpers/comment.js";
7
7
  import { getNip10References } from "../helpers/threading.js";
8
8
  const defaultOptions = {
9
9
  kinds: [kinds.ShortTextNote],
10
+ comments: true,
10
11
  };
11
- /** A model that returns a NIP-10 thread of events */
12
+ /** Converts a NIP-22 comment pointer into a NIP-10 style thread reference */
13
+ function commentPointerToReference(pointer) {
14
+ if (pointer?.type === "event") {
15
+ const { id, kind, pubkey, relay } = pointer;
16
+ return { e: { id, kind, author: pubkey, relays: relay ? [relay] : undefined }, a: undefined };
17
+ }
18
+ if (pointer?.type === "address") {
19
+ const { kind, pubkey, identifier, relay } = pointer;
20
+ return { e: undefined, a: { kind, pubkey, identifier, relays: relay ? [relay] : undefined } };
21
+ }
22
+ // External roots have no event in the thread
23
+ return undefined;
24
+ }
25
+ /** Gets the thread references of a NIP-10 reply or a NIP-22 comment */
26
+ function getThreadReferences(event) {
27
+ if (event.kind !== COMMENT_KIND)
28
+ return getNip10References(event);
29
+ return {
30
+ root: commentPointerToReference(getCommentRootPointer(event)),
31
+ reply: commentPointerToReference(getCommentReplyPointer(event)),
32
+ };
33
+ }
34
+ /** A model that returns a thread of NIP-10 replies and NIP-22 comments */
12
35
  export function ThreadModel(root, opts) {
13
36
  const parentReferences = new Map();
14
37
  const items = new Map();
15
- const { kinds } = { ...defaultOptions, ...opts };
38
+ const { kinds, comments } = { ...defaultOptions, ...opts };
16
39
  let rootUID = "";
17
40
  const rootFilter = {};
18
41
  const replyFilter = { kinds };
42
+ // NIP-22 comments reference the root with uppercase tags at every depth
43
+ const commentFilter = { kinds: [COMMENT_KIND] };
19
44
  if (isAddressPointer(root)) {
20
45
  rootUID = getReplaceableAddressFromPointer(root);
21
46
  rootFilter.kinds = [root.kind];
22
47
  rootFilter.authors = [root.pubkey];
23
48
  rootFilter["#d"] = [root.identifier];
24
49
  replyFilter["#a"] = [rootUID];
50
+ commentFilter["#A"] = [rootUID];
25
51
  }
26
52
  else if (typeof root === "string") {
27
53
  rootUID = root;
28
54
  rootFilter.ids = [root];
29
55
  replyFilter["#e"] = [root];
56
+ commentFilter["#E"] = [root];
30
57
  }
31
58
  else {
32
59
  rootUID = root.id;
33
60
  rootFilter.ids = [root.id];
34
61
  replyFilter["#e"] = [root.id];
62
+ commentFilter["#E"] = [root.id];
35
63
  }
36
- return (events) => events.filters([rootFilter, replyFilter]).pipe(map((event) => {
64
+ const filters = comments ? [rootFilter, replyFilter, commentFilter] : [rootFilter, replyFilter];
65
+ return (events) => events.filters(filters).pipe(map((event) => {
37
66
  if (!items.has(getEventUID(event))) {
38
- const refs = getNip10References(event);
67
+ const refs = getThreadReferences(event);
39
68
  const replies = parentReferences.get(getEventUID(event)) || new Set();
40
69
  const item = { event, refs, replies };
41
70
  for (const child of replies) {
@@ -1,11 +1,15 @@
1
1
  import { Model } from "applesauce-core/event-store";
2
2
  import { NostrEvent } from "applesauce-core/helpers/event";
3
3
  import { UserStatusPointer } from "../helpers/user-status.js";
4
- export type UserStatus = UserStatusPointer & {
4
+ /** A parsed user status, the pointer fields are only set when the status links to something */
5
+ export type UserStatus = (UserStatusPointer | {
6
+ type?: undefined;
7
+ data?: undefined;
8
+ }) & {
5
9
  event: NostrEvent;
6
10
  content: string;
7
11
  };
8
- /** A model that returns a parsed {@link UserStatus} for a certain type */
9
- export declare function UserStatusModel(pubkey: string, type?: string): Model<UserStatus | undefined | null>;
10
- /** A model that returns a directory of parsed {@link UserStatus} for a pubkey */
12
+ /** A model that returns a parsed {@link UserStatus} for a certain type, or undefined when missing or cleared */
13
+ export declare function UserStatusModel(pubkey: string, type?: string): Model<UserStatus | undefined>;
14
+ /** A model that returns a directory of parsed {@link UserStatus} for a pubkey, excluding cleared statuses */
11
15
  export declare function UserStatusesModel(pubkey: string): Model<Record<string, UserStatus>>;
@@ -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,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) {
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) {
6
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,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
+ }