applesauce-common 6.0.2 → 6.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 (93) hide show
  1. package/dist/casts/_circular-import.d.ts +2 -0
  2. package/dist/casts/_circular-import.js +2 -0
  3. package/dist/casts/git-grasp-list.d.ts +8 -0
  4. package/dist/casts/git-grasp-list.js +13 -0
  5. package/dist/casts/git-lists.d.ts +42 -0
  6. package/dist/casts/git-lists.js +94 -0
  7. package/dist/casts/git-repository.d.ts +29 -0
  8. package/dist/casts/git-repository.js +68 -0
  9. package/dist/casts/index.d.ts +3 -0
  10. package/dist/casts/index.js +3 -0
  11. package/dist/casts/reaction.d.ts +3 -1
  12. package/dist/casts/reaction.js +6 -2
  13. package/dist/casts/relay-lists.d.ts +6 -2
  14. package/dist/casts/relay-lists.js +11 -2
  15. package/dist/casts/user.d.ts +4 -0
  16. package/dist/casts/user.js +23 -1
  17. package/dist/factories/calendar-event.d.ts +0 -5
  18. package/dist/factories/calendar-event.js +0 -9
  19. package/dist/factories/calendar-rsvp.d.ts +1 -0
  20. package/dist/factories/calendar-rsvp.js +1 -0
  21. package/dist/factories/code-snippet.d.ts +0 -2
  22. package/dist/factories/code-snippet.js +0 -5
  23. package/dist/factories/comment.d.ts +0 -2
  24. package/dist/factories/comment.js +5 -8
  25. package/dist/factories/favorite-git-repos.d.ts +17 -0
  26. package/dist/factories/favorite-git-repos.js +43 -0
  27. package/dist/factories/gift-wrap.js +2 -2
  28. package/dist/factories/git-authors.d.ts +17 -0
  29. package/dist/factories/git-authors.js +24 -0
  30. package/dist/factories/git-grasp-list.d.ts +14 -0
  31. package/dist/factories/git-grasp-list.js +25 -0
  32. package/dist/factories/git-repository.d.ts +51 -0
  33. package/dist/factories/git-repository.js +96 -0
  34. package/dist/factories/group.d.ts +5 -7
  35. package/dist/factories/group.js +8 -14
  36. package/dist/factories/highlight.d.ts +1 -10
  37. package/dist/factories/highlight.js +2 -12
  38. package/dist/factories/index.d.ts +5 -4
  39. package/dist/factories/index.js +5 -4
  40. package/dist/factories/legacy-message.d.ts +0 -1
  41. package/dist/factories/list.d.ts +0 -10
  42. package/dist/factories/list.js +0 -21
  43. package/dist/factories/picture-post.d.ts +3 -4
  44. package/dist/factories/picture-post.js +3 -7
  45. package/dist/factories/poll-response.d.ts +0 -2
  46. package/dist/factories/poll-response.js +0 -5
  47. package/dist/factories/poll.d.ts +9 -6
  48. package/dist/factories/poll.js +12 -9
  49. package/dist/factories/relay-lists.d.ts +46 -0
  50. package/dist/factories/relay-lists.js +93 -0
  51. package/dist/factories/relay-set.d.ts +1 -1
  52. package/dist/factories/relay-set.js +1 -1
  53. package/dist/factories/share.d.ts +0 -7
  54. package/dist/factories/share.js +0 -11
  55. package/dist/factories/stream-chat-message.d.ts +0 -3
  56. package/dist/factories/stream-chat-message.js +0 -5
  57. package/dist/factories/torrent.d.ts +0 -2
  58. package/dist/factories/torrent.js +0 -5
  59. package/dist/factories/zap-goal.d.ts +0 -2
  60. package/dist/factories/zap-goal.js +0 -5
  61. package/dist/helpers/git-grasp-list.d.ts +8 -0
  62. package/dist/helpers/git-grasp-list.js +15 -0
  63. package/dist/helpers/git-lists.d.ts +20 -0
  64. package/dist/helpers/git-lists.js +28 -0
  65. package/dist/helpers/git-repository.d.ts +39 -0
  66. package/dist/helpers/git-repository.js +104 -0
  67. package/dist/helpers/index.d.ts +3 -0
  68. package/dist/helpers/index.js +3 -0
  69. package/dist/helpers/relay-list.d.ts +5 -0
  70. package/dist/helpers/relay-list.js +8 -0
  71. package/dist/observable/cast-stream.d.ts +1 -8
  72. package/dist/observable/cast-stream.js +2 -29
  73. package/dist/observable/chainable.d.ts +1 -1
  74. package/dist/observable/chainable.js +1 -1
  75. package/dist/operations/git-grasp-list.d.ts +7 -0
  76. package/dist/operations/git-grasp-list.js +18 -0
  77. package/dist/operations/git-repository.d.ts +45 -0
  78. package/dist/operations/git-repository.js +160 -0
  79. package/dist/operations/hashtags.d.ts +2 -0
  80. package/dist/operations/hashtags.js +7 -0
  81. package/dist/operations/index.d.ts +2 -0
  82. package/dist/operations/index.js +2 -0
  83. package/dist/operations/poll.d.ts +3 -2
  84. package/dist/operations/poll.js +4 -3
  85. package/package.json +3 -3
  86. package/dist/factories/blocked-relays.d.ts +0 -10
  87. package/dist/factories/blocked-relays.js +0 -16
  88. package/dist/factories/dm-relays.d.ts +0 -10
  89. package/dist/factories/dm-relays.js +0 -16
  90. package/dist/factories/favorite-relays.d.ts +0 -16
  91. package/dist/factories/favorite-relays.js +0 -31
  92. package/dist/factories/search-relays.d.ts +0 -10
  93. package/dist/factories/search-relays.js +0 -16
@@ -1,7 +1,10 @@
1
1
  import { EventFactory } from "applesauce-core/factories";
2
2
  import { KnownEventTemplate } from "applesauce-core/helpers";
3
+ import { TextContentOptions } from "applesauce-core/operations/content";
4
+ import { MetaTagOptions } from "applesauce-core/operations/event";
3
5
  import { POLL_KIND, PollType } from "../helpers/poll.js";
4
6
  import { ZapOptions } from "../operations/zap-split.js";
7
+ export type PollFactoryCreateOptions = TextContentOptions & MetaTagOptions;
5
8
  export interface PollOption {
6
9
  id: string;
7
10
  label: string;
@@ -11,13 +14,13 @@ export type PollTemplate = KnownEventTemplate<typeof POLL_KIND>;
11
14
  export declare class PollFactory extends EventFactory<typeof POLL_KIND, PollTemplate> {
12
15
  /**
13
16
  * Creates a new poll factory
14
- * @param question - The poll question
15
- * @param options - The poll options
16
- * @returns A new poll factory
17
+ * @param question - The poll question (content); hashtags and `:shortcode:` emojis are reflected in tags when using {@link TextContentOptions}
18
+ * @param pollOptions - The poll answer options
19
+ * @param options - Text content options (custom emojis, content warning) and/or meta tags (e.g. `alt`)
17
20
  */
18
- static create(question: string, options: PollOption[]): PollFactory;
19
- /** Sets the poll question */
20
- question(question: string): this;
21
+ static create(question: string, pollOptions: PollOption[], options?: PollFactoryCreateOptions): PollFactory;
22
+ /** Sets the poll question as event content (hashtags, nostr links, custom emojis) */
23
+ question(question: string, options?: TextContentOptions): this;
21
24
  /** Sets the poll options */
22
25
  options(options: PollOption[]): this;
23
26
  /** Sets the poll type (singlechoice or multiplechoice) */
@@ -6,16 +6,19 @@ import { setZapSplit } from "../operations/zap-split.js";
6
6
  export class PollFactory extends EventFactory {
7
7
  /**
8
8
  * Creates a new poll factory
9
- * @param question - The poll question
10
- * @param options - The poll options
11
- * @returns A new poll factory
9
+ * @param question - The poll question (content); hashtags and `:shortcode:` emojis are reflected in tags when using {@link TextContentOptions}
10
+ * @param pollOptions - The poll answer options
11
+ * @param options - Text content options (custom emojis, content warning) and/or meta tags (e.g. `alt`)
12
12
  */
13
- static create(question, options) {
14
- return new PollFactory((res) => res(blankEventTemplate(POLL_KIND))).question(question).options(options);
15
- }
16
- /** Sets the poll question */
17
- question(question) {
18
- return this.chain((draft) => Poll.setQuestion(question)(draft));
13
+ static create(question, pollOptions, options) {
14
+ return new PollFactory((res) => res(blankEventTemplate(POLL_KIND)))
15
+ .question(question, options)
16
+ .options(pollOptions)
17
+ .meta({ alt: "A poll", ...options });
18
+ }
19
+ /** Sets the poll question as event content (hashtags, nostr links, custom emojis) */
20
+ question(question, options) {
21
+ return this.chain(Poll.setQuestion(question, options));
19
22
  }
20
23
  /** Sets the poll options */
21
24
  options(options) {
@@ -0,0 +1,46 @@
1
+ import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
2
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
3
+ import { FAVORITE_RELAYS_KIND, LOOKUP_RELAY_LIST_KIND } from "../helpers/relay-list.js";
4
+ import { ListFactory } from "./list.js";
5
+ /**
6
+ * A base factory class for NIP-51 lists that contain relay URLs (`relay` tags).
7
+ * Provides `addRelay` and `removeRelay` in addition to `title`, `description`, and `image`.
8
+ */
9
+ export declare class NIP51RelayListFactory<K extends number = number, T extends KnownEventTemplate<K> = KnownEventTemplate<K>> extends ListFactory<K, T> {
10
+ /** Adds a relay URL to the list's public tags */
11
+ addRelay(relay: string | string[], hidden?: boolean): this;
12
+ /** Removes a relay URL from the list */
13
+ removeRelay(relay: string | string[], hidden?: boolean): this;
14
+ }
15
+ export type BlockedRelaysTemplate = KnownEventTemplate<kinds.BlockedRelaysList>;
16
+ /** A factory class for building kind 10006 blocked relays list events */
17
+ export declare class BlockedRelaysFactory extends NIP51RelayListFactory<kinds.BlockedRelaysList, BlockedRelaysTemplate> {
18
+ static create(): BlockedRelaysFactory;
19
+ static modify(event: NostrEvent | KnownEvent<kinds.BlockedRelaysList>): BlockedRelaysFactory;
20
+ }
21
+ export type DmRelaysTemplate = KnownEventTemplate<kinds.DirectMessageRelaysList>;
22
+ /** A factory class for building kind 10050 direct message relays list events */
23
+ export declare class DmRelaysFactory extends NIP51RelayListFactory<kinds.DirectMessageRelaysList, DmRelaysTemplate> {
24
+ static create(): DmRelaysFactory;
25
+ static modify(event: NostrEvent | KnownEvent<kinds.DirectMessageRelaysList>): DmRelaysFactory;
26
+ }
27
+ export type FavoriteRelaysTemplate = KnownEventTemplate<typeof FAVORITE_RELAYS_KIND>;
28
+ /** A factory class for building kind 10012 favorite relays list events */
29
+ export declare class FavoriteRelaysFactory extends NIP51RelayListFactory<typeof FAVORITE_RELAYS_KIND, FavoriteRelaysTemplate> {
30
+ static create(): FavoriteRelaysFactory;
31
+ static modify(event: NostrEvent | KnownEvent<typeof FAVORITE_RELAYS_KIND>): FavoriteRelaysFactory;
32
+ addRelaySet(addr: AddressPointer | AddressPointer[], hidden?: boolean): this;
33
+ removeRelaySet(addr: AddressPointer | AddressPointer[], hidden?: boolean): this;
34
+ }
35
+ export type LookupRelayListTemplate = KnownEventTemplate<typeof LOOKUP_RELAY_LIST_KIND>;
36
+ /** A factory class for building kind 10086 lookup / indexer relays list events */
37
+ export declare class LookupRelayListFactory extends NIP51RelayListFactory<typeof LOOKUP_RELAY_LIST_KIND, LookupRelayListTemplate> {
38
+ static create(): LookupRelayListFactory;
39
+ static modify(event: NostrEvent | KnownEvent<typeof LOOKUP_RELAY_LIST_KIND>): LookupRelayListFactory;
40
+ }
41
+ export type SearchRelaysTemplate = KnownEventTemplate<kinds.SearchRelaysList>;
42
+ /** A factory class for building kind 10007 search relays list events */
43
+ export declare class SearchRelaysFactory extends NIP51RelayListFactory<kinds.SearchRelaysList, SearchRelaysTemplate> {
44
+ static create(): SearchRelaysFactory;
45
+ static modify(event: NostrEvent | KnownEvent<kinds.SearchRelaysList>): SearchRelaysFactory;
46
+ }
@@ -0,0 +1,93 @@
1
+ import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
2
+ import { isKind, kinds } from "applesauce-core/helpers";
3
+ import { addAddressPointerTag, removeAddressPointerTag } from "applesauce-core/operations/tag/common";
4
+ import { addRelayTag, removeRelayTag } from "applesauce-core/operations/tag/relay";
5
+ import { FAVORITE_RELAYS_KIND, LOOKUP_RELAY_LIST_KIND } from "../helpers/relay-list.js";
6
+ import { ListFactory } from "./list.js";
7
+ /**
8
+ * A base factory class for NIP-51 lists that contain relay URLs (`relay` tags).
9
+ * Provides `addRelay` and `removeRelay` in addition to `title`, `description`, and `image`.
10
+ */
11
+ export class NIP51RelayListFactory extends ListFactory {
12
+ /** Adds a relay URL to the list's public tags */
13
+ addRelay(relay, hidden = false) {
14
+ const relays = Array.isArray(relay) ? relay : [relay];
15
+ return hidden
16
+ ? this.modifyHiddenTags(...relays.map((r) => addRelayTag(r)))
17
+ : this.modifyPublicTags(...relays.map((r) => addRelayTag(r)));
18
+ }
19
+ /** Removes a relay URL from the list */
20
+ removeRelay(relay, hidden = false) {
21
+ const relays = Array.isArray(relay) ? relay : [relay];
22
+ return hidden
23
+ ? this.modifyHiddenTags(...relays.map((r) => removeRelayTag(r)))
24
+ : this.modifyPublicTags(...relays.map((r) => removeRelayTag(r)));
25
+ }
26
+ }
27
+ /** A factory class for building kind 10006 blocked relays list events */
28
+ export class BlockedRelaysFactory extends NIP51RelayListFactory {
29
+ static create() {
30
+ return new BlockedRelaysFactory((res) => res(blankEventTemplate(kinds.BlockedRelaysList)));
31
+ }
32
+ static modify(event) {
33
+ if (!isKind(event, kinds.BlockedRelaysList))
34
+ throw new Error("Event is not a blocked relays event");
35
+ return new BlockedRelaysFactory((res) => res(toEventTemplate(event)));
36
+ }
37
+ }
38
+ /** A factory class for building kind 10050 direct message relays list events */
39
+ export class DmRelaysFactory extends NIP51RelayListFactory {
40
+ static create() {
41
+ return new DmRelaysFactory((res) => res(blankEventTemplate(kinds.DirectMessageRelaysList)));
42
+ }
43
+ static modify(event) {
44
+ if (!isKind(event, kinds.DirectMessageRelaysList))
45
+ throw new Error("Event is not a DM relays event");
46
+ return new DmRelaysFactory((res) => res(toEventTemplate(event)));
47
+ }
48
+ }
49
+ /** A factory class for building kind 10012 favorite relays list events */
50
+ export class FavoriteRelaysFactory extends NIP51RelayListFactory {
51
+ static create() {
52
+ return new FavoriteRelaysFactory((res) => res(blankEventTemplate(FAVORITE_RELAYS_KIND)));
53
+ }
54
+ static modify(event) {
55
+ if (event.kind !== FAVORITE_RELAYS_KIND)
56
+ throw new Error("Event is not a favorite relays event");
57
+ return new FavoriteRelaysFactory((res) => res(toEventTemplate(event)));
58
+ }
59
+ addRelaySet(addr, hidden = false) {
60
+ const addrs = Array.isArray(addr) ? addr : [addr];
61
+ return hidden
62
+ ? this.modifyHiddenTags(...addrs.map((a) => addAddressPointerTag(a)))
63
+ : this.modifyPublicTags(...addrs.map((a) => addAddressPointerTag(a)));
64
+ }
65
+ removeRelaySet(addr, hidden = false) {
66
+ const addrs = Array.isArray(addr) ? addr : [addr];
67
+ return hidden
68
+ ? this.modifyHiddenTags(...addrs.map((a) => removeAddressPointerTag(a)))
69
+ : this.modifyPublicTags(...addrs.map((a) => removeAddressPointerTag(a)));
70
+ }
71
+ }
72
+ /** A factory class for building kind 10086 lookup / indexer relays list events */
73
+ export class LookupRelayListFactory extends NIP51RelayListFactory {
74
+ static create() {
75
+ return new LookupRelayListFactory((res) => res(blankEventTemplate(LOOKUP_RELAY_LIST_KIND)));
76
+ }
77
+ static modify(event) {
78
+ if (event.kind !== LOOKUP_RELAY_LIST_KIND)
79
+ throw new Error("Event is not a lookup relay list event");
80
+ return new LookupRelayListFactory((res) => res(toEventTemplate(event)));
81
+ }
82
+ }
83
+ /** A factory class for building kind 10007 search relays list events */
84
+ export class SearchRelaysFactory extends NIP51RelayListFactory {
85
+ static create() {
86
+ return new SearchRelaysFactory((res) => res(blankEventTemplate(kinds.SearchRelaysList)));
87
+ }
88
+ static modify(event) {
89
+ if (!isKind(event, kinds.SearchRelaysList))
90
+ throw new Error("Event is not a search relays event");
91
+ return new SearchRelaysFactory((res) => res(toEventTemplate(event)));
92
+ }
93
+ }
@@ -1,5 +1,5 @@
1
1
  import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
2
- import { NIP51RelayListFactory } from "./list.js";
2
+ import { NIP51RelayListFactory } from "./relay-lists.js";
3
3
  export type RelaySetTemplate = KnownEventTemplate<kinds.Relaysets>;
4
4
  /** A factory class for building kind 30002 relay set events */
5
5
  export declare class RelaySetFactory extends NIP51RelayListFactory<kinds.Relaysets, RelaySetTemplate> {
@@ -2,7 +2,7 @@ import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
2
2
  import { isKind, kinds } from "applesauce-core/helpers";
3
3
  import { includeReplaceableIdentifier } from "applesauce-core/operations/index";
4
4
  import { nanoid } from "nanoid";
5
- import { NIP51RelayListFactory } from "./list.js";
5
+ import { NIP51RelayListFactory } from "./relay-lists.js";
6
6
  /** A factory class for building kind 30002 relay set events */
7
7
  export class RelaySetFactory extends NIP51RelayListFactory {
8
8
  /** Creates a new relay set factory with an auto-generated identifier */
@@ -8,17 +8,10 @@ export declare class ShareFactory extends EventFactory<number, EventTemplate> {
8
8
  /**
9
9
  * Creates a new share factory
10
10
  * @param event - The event being shared
11
- * @returns A new share factory
12
11
  */
13
12
  static create(event: NostrEvent): ShareFactory;
14
13
  /** Creates a new share event for an existing event */
15
14
  static share(event: NostrEvent): ShareFactory;
16
- /**
17
- * Creates a quote-repost: sets the event reference tags and uses a custom comment as content
18
- * @param event - The event being quoted
19
- * @param comment - The quote comment text
20
- */
21
- static quote(event: NostrEvent, comment: string): ShareFactory;
22
15
  /** Sets the event being shared */
23
16
  setEvent(event: NostrEvent): this;
24
17
  /** Sets zap split configuration */
@@ -7,7 +7,6 @@ export class ShareFactory extends EventFactory {
7
7
  /**
8
8
  * Creates a new share factory
9
9
  * @param event - The event being shared
10
- * @returns A new share factory
11
10
  */
12
11
  static create(event) {
13
12
  return new ShareFactory((res) => res(blankEventTemplate(kinds.Repost))).setEvent(event);
@@ -16,16 +15,6 @@ export class ShareFactory extends EventFactory {
16
15
  static share(event) {
17
16
  return ShareFactory.create(event);
18
17
  }
19
- /**
20
- * Creates a quote-repost: sets the event reference tags and uses a custom comment as content
21
- * @param event - The event being quoted
22
- * @param comment - The quote comment text
23
- */
24
- static quote(event, comment) {
25
- return new ShareFactory((res) => res(blankEventTemplate(kinds.Repost)))
26
- .setEvent(event)
27
- .chain((draft) => ({ ...draft, content: comment }));
28
- }
29
18
  /** Sets the event being shared */
30
19
  setEvent(event) {
31
20
  return this.chain(pipeFromAsyncArray([
@@ -1,7 +1,6 @@
1
1
  import { EventFactory } from "applesauce-core/factories";
2
2
  import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
3
3
  import { TextContentOptions } from "applesauce-core/operations/content";
4
- import { MetaTagOptions } from "applesauce-core/operations/event";
5
4
  import { AddressPointer } from "applesauce-core/helpers/pointers";
6
5
  export type StreamChatMessageTemplate = KnownEventTemplate<kinds.LiveChatMessage>;
7
6
  /** A factory class for building NIP-53 stream chat message events (kind 1311) */
@@ -17,6 +16,4 @@ export declare class StreamChatMessageFactory extends EventFactory<kinds.LiveCha
17
16
  stream(stream: NostrEvent | AddressPointer): this;
18
17
  /** Sets the message content */
19
18
  message(content: string, options?: TextContentOptions): this;
20
- /** Sets meta tags */
21
- meta(options: MetaTagOptions): this;
22
19
  }
@@ -1,6 +1,5 @@
1
1
  import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
2
2
  import { kinds } from "applesauce-core/helpers";
3
- import { setMetaTags } from "applesauce-core/operations/event";
4
3
  import { setMessage, setStream } from "../operations/stream-chat.js";
5
4
  /** A factory class for building NIP-53 stream chat message events (kind 1311) */
6
5
  export class StreamChatMessageFactory extends EventFactory {
@@ -24,8 +23,4 @@ export class StreamChatMessageFactory extends EventFactory {
24
23
  message(content, options) {
25
24
  return this.chain(setMessage(content, options));
26
25
  }
27
- /** Sets meta tags */
28
- meta(options) {
29
- return this.chain(setMetaTags(options));
30
- }
31
26
  }
@@ -52,6 +52,4 @@ export declare class TorrentFactory extends EventFactory<typeof TORRENT_KIND, To
52
52
  addExternalId(id: TorrentExternalIdentifier): this;
53
53
  /** Adds external identifiers */
54
54
  externalIds(ids: TorrentExternalIdentifier[]): this;
55
- /** Sets meta tags */
56
- meta(options: MetaTagOptions): this;
57
55
  }
@@ -1,5 +1,4 @@
1
1
  import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
2
- import { setMetaTags } from "applesauce-core/operations/event";
3
2
  import { TORRENT_KIND } from "../helpers/torrent.js";
4
3
  import { addTorrentExternalIdentifier, addTorrentFile, addTorrentSearchTag, addTorrentTracker, setTorrentCategory, setTorrentCategoryPath, setTorrentInfoHash, setTorrentTitle, } from "../operations/torrent.js";
5
4
  /** A factory class for building NIP-35 torrent events (kind 2003) */
@@ -86,8 +85,4 @@ export class TorrentFactory extends EventFactory {
86
85
  return result;
87
86
  });
88
87
  }
89
- /** Sets meta tags */
90
- meta(options) {
91
- return this.chain((draft) => setMetaTags(options)(draft));
92
- }
93
88
  }
@@ -30,6 +30,4 @@ export declare class ZapGoalFactory extends EventFactory<typeof ZAP_GOAL_KIND, Z
30
30
  goal(goalId: string, relay?: string): this;
31
31
  /** Sets the zap split for the zap goal */
32
32
  zapSplit(options: ZapOptions): this;
33
- /** Sets the meta tags for the zap goal */
34
- meta(options: MetaTagOptions): this;
35
33
  }
@@ -1,5 +1,4 @@
1
1
  import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
2
- import { setMetaTags } from "applesauce-core/operations/event";
3
2
  import { ZAP_GOAL_KIND } from "../helpers/zap-goal.js";
4
3
  import * as ZapGoal from "../operations/zap-goal.js";
5
4
  import { setZapSplit } from "../operations/zap-split.js";
@@ -42,8 +41,4 @@ export class ZapGoalFactory extends EventFactory {
42
41
  zapSplit(options) {
43
42
  return this.chain(setZapSplit(options, undefined));
44
43
  }
45
- /** Sets the meta tags for the zap goal */
46
- meta(options) {
47
- return this.chain(setMetaTags(options));
48
- }
49
44
  }
@@ -0,0 +1,8 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ export declare const GIT_GRASP_LIST_KIND = 10317;
3
+ export declare const GitGraspServersSymbol: unique symbol;
4
+ export type GitGraspListEvent = KnownEvent<typeof GIT_GRASP_LIST_KIND>;
5
+ /** Checks if an event is a NIP-34 user grasp server list. */
6
+ export declare function isValidGitGraspList(event?: NostrEvent): event is GitGraspListEvent;
7
+ /** Returns grasp service websocket URLs in preference order. */
8
+ export declare function getGitGraspServers(event?: NostrEvent): string[];
@@ -0,0 +1,15 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { relaySet } from "applesauce-core/helpers/relays";
3
+ import { processTags } from "applesauce-core/helpers/tags";
4
+ export const GIT_GRASP_LIST_KIND = 10317;
5
+ export const GitGraspServersSymbol = Symbol.for("git-grasp-servers");
6
+ /** Checks if an event is a NIP-34 user grasp server list. */
7
+ export function isValidGitGraspList(event) {
8
+ return !!event && event.kind === GIT_GRASP_LIST_KIND;
9
+ }
10
+ /** Returns grasp service websocket URLs in preference order. */
11
+ export function getGitGraspServers(event) {
12
+ if (!isValidGitGraspList(event))
13
+ return [];
14
+ return getOrComputeCachedValue(event, GitGraspServersSymbol, () => relaySet(processTags(event.tags, (tag) => (tag[0] === "g" ? tag[1] : undefined))));
15
+ }
@@ -0,0 +1,20 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { ProfilePointer } from "applesauce-core/helpers/pointers";
3
+ import { GitRepositoryPointer } from "./git-repository.js";
4
+ import { ReadListTags } from "./lists.js";
5
+ /** NIP-51 git authors list kind */
6
+ export declare const GIT_AUTHORS_KIND = 10017;
7
+ /** NIP-51 git repositories list kind */
8
+ export declare const FAVORITE_GIT_REPOS_KIND = 10018;
9
+ /** NIP-34 repository announcement event kind */
10
+ export declare const REPOSITORY_ANNOUNCEMENT_KIND = 30617;
11
+ export type GitAuthorsListEvent = KnownEvent<typeof GIT_AUTHORS_KIND>;
12
+ export type FavoriteGitReposListEvent = KnownEvent<typeof FAVORITE_GIT_REPOS_KIND>;
13
+ /** Validates that an event is a NIP-51 git authors list */
14
+ export declare function isValidGitAuthorsList(event: NostrEvent): event is GitAuthorsListEvent;
15
+ /** Validates that an event is a NIP-51 git repositories list */
16
+ export declare function isValidFavoriteGitReposList(event: NostrEvent): event is FavoriteGitReposListEvent;
17
+ /** Returns git author profile pointers from a git authors list */
18
+ export declare function getGitAuthors(list: NostrEvent, type?: ReadListTags): ProfilePointer[];
19
+ /** Returns NIP-34 repository pointers from a git repositories list */
20
+ export declare function getFavoriteGitReposPointers(list: NostrEvent, type?: ReadListTags): GitRepositoryPointer[];
@@ -0,0 +1,28 @@
1
+ import { setHiddenTagsEncryptionMethod } from "applesauce-core/helpers/hidden-tags";
2
+ import { GIT_REPOSITORY_KIND } from "./git-repository.js";
3
+ import { getAddressPointersFromList, getProfilePointersFromList } from "./lists.js";
4
+ /** NIP-51 git authors list kind */
5
+ export const GIT_AUTHORS_KIND = 10017;
6
+ /** NIP-51 git repositories list kind */
7
+ export const FAVORITE_GIT_REPOS_KIND = 10018;
8
+ /** NIP-34 repository announcement event kind */
9
+ export const REPOSITORY_ANNOUNCEMENT_KIND = GIT_REPOSITORY_KIND;
10
+ // Set the default encrypted content method for the kinds
11
+ setHiddenTagsEncryptionMethod(GIT_AUTHORS_KIND, "nip44");
12
+ setHiddenTagsEncryptionMethod(FAVORITE_GIT_REPOS_KIND, "nip44");
13
+ /** Validates that an event is a NIP-51 git authors list */
14
+ export function isValidGitAuthorsList(event) {
15
+ return event.kind === GIT_AUTHORS_KIND;
16
+ }
17
+ /** Validates that an event is a NIP-51 git repositories list */
18
+ export function isValidFavoriteGitReposList(event) {
19
+ return event.kind === FAVORITE_GIT_REPOS_KIND;
20
+ }
21
+ /** Returns git author profile pointers from a git authors list */
22
+ export function getGitAuthors(list, type) {
23
+ return getProfilePointersFromList(list, type);
24
+ }
25
+ /** Returns NIP-34 repository pointers from a git repositories list */
26
+ export function getFavoriteGitReposPointers(list, type) {
27
+ return getAddressPointersFromList(list, type).filter((pointer) => pointer.kind === REPOSITORY_ANNOUNCEMENT_KIND);
28
+ }
@@ -0,0 +1,39 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
3
+ export declare const GIT_REPOSITORY_KIND = 30617;
4
+ export type GitRepositoryEvent = KnownEvent<typeof GIT_REPOSITORY_KIND>;
5
+ export type GitRepositoryPointer = AddressPointer & {
6
+ kind: typeof GIT_REPOSITORY_KIND;
7
+ };
8
+ export declare const GitRepositoryWebUrlsSymbol: unique symbol;
9
+ export declare const GitRepositoryCloneUrlsSymbol: unique symbol;
10
+ export declare const GitRepositoryRelaysSymbol: unique symbol;
11
+ export declare const GitRepositoryMaintainersSymbol: unique symbol;
12
+ export declare const GitRepositoryHashtagsSymbol: unique symbol;
13
+ export declare const GitRepositoryUpstreamSymbol: unique symbol;
14
+ /** Checks if an event is a valid NIP-34 repository announcement. */
15
+ export declare function isValidGitRepository(event?: NostrEvent): event is GitRepositoryEvent;
16
+ /** Returns the repository identifier from the `d` tag. */
17
+ export declare function getGitRepositoryIdentifier(event: GitRepositoryEvent): string;
18
+ export declare function getGitRepositoryIdentifier(event?: NostrEvent): string | undefined;
19
+ /** Returns the repository display name. */
20
+ export declare function getGitRepositoryName(event?: NostrEvent): string | undefined;
21
+ /** Returns the repository description. */
22
+ export declare function getGitRepositoryDescription(event?: NostrEvent): string | undefined;
23
+ /** Returns all web URLs declared by the repository announcement. */
24
+ export declare function getGitRepositoryWebUrls(event?: NostrEvent): string[];
25
+ /** Returns all clone URLs declared by the repository announcement. */
26
+ export declare function getGitRepositoryCloneUrls(event?: NostrEvent): string[];
27
+ /** Returns relays monitored by the repository. */
28
+ export declare function getGitRepositoryRelays(event?: NostrEvent): string[];
29
+ /** Returns the earliest unique commit ID, if declared. */
30
+ export declare function getGitRepositoryEarliestUniqueCommit(event?: NostrEvent): string | undefined;
31
+ /** Returns all recognized maintainer pubkeys including the author of the repository event. */
32
+ export declare function getGitRepositoryMaintainers(event?: NostrEvent): string[];
33
+ /** Returns repository topic tags (NIP-34: values from each `["t", ...]` tag). */
34
+ export declare function getGitRepositoryHashtags(event?: NostrEvent): string[];
35
+ /**
36
+ * Returns the upstream repository pointer (the repo this one was forked from), if declared.
37
+ * Parsed from the `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
38
+ */
39
+ export declare function getGitRepositoryUpstream(event?: NostrEvent): GitRepositoryPointer | undefined;
@@ -0,0 +1,104 @@
1
+ import { isHexKey, relaySet } from "applesauce-core/helpers";
2
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
3
+ import { getReplaceableIdentifier, getTagValue } from "applesauce-core/helpers/event";
4
+ import { isSafeRelayURL } from "applesauce-core/helpers/relays";
5
+ import { normalizeURL } from "applesauce-core/helpers/url";
6
+ export const GIT_REPOSITORY_KIND = 30617;
7
+ export const GitRepositoryWebUrlsSymbol = Symbol.for("git-repository-web-urls");
8
+ export const GitRepositoryCloneUrlsSymbol = Symbol.for("git-repository-clone-urls");
9
+ export const GitRepositoryRelaysSymbol = Symbol.for("git-repository-relays");
10
+ export const GitRepositoryMaintainersSymbol = Symbol.for("git-repository-maintainers");
11
+ export const GitRepositoryHashtagsSymbol = Symbol.for("git-repository-hashtags");
12
+ export const GitRepositoryUpstreamSymbol = Symbol.for("git-repository-upstream");
13
+ function getTagValues(event, name) {
14
+ return event.tags.filter((tag) => tag[0] === name && tag[1]).flatMap((tag) => tag.slice(1));
15
+ }
16
+ /** Checks if an event is a valid NIP-34 repository announcement. */
17
+ export function isValidGitRepository(event) {
18
+ return !!event && event.kind === GIT_REPOSITORY_KIND && !!getReplaceableIdentifier(event);
19
+ }
20
+ export function getGitRepositoryIdentifier(event) {
21
+ if (!isValidGitRepository(event))
22
+ return undefined;
23
+ return getReplaceableIdentifier(event) || undefined;
24
+ }
25
+ /** Returns the repository display name. */
26
+ export function getGitRepositoryName(event) {
27
+ if (!isValidGitRepository(event))
28
+ return undefined;
29
+ return getTagValue(event, "name") || undefined;
30
+ }
31
+ /** Returns the repository description. */
32
+ export function getGitRepositoryDescription(event) {
33
+ if (!isValidGitRepository(event))
34
+ return undefined;
35
+ return getTagValue(event, "description") || undefined;
36
+ }
37
+ /** Returns all web URLs declared by the repository announcement. */
38
+ export function getGitRepositoryWebUrls(event) {
39
+ if (!isValidGitRepository(event))
40
+ return [];
41
+ return getOrComputeCachedValue(event, GitRepositoryWebUrlsSymbol, () => getTagValues(event, "web"));
42
+ }
43
+ /** Returns all clone URLs declared by the repository announcement. */
44
+ export function getGitRepositoryCloneUrls(event) {
45
+ if (!isValidGitRepository(event))
46
+ return [];
47
+ return getOrComputeCachedValue(event, GitRepositoryCloneUrlsSymbol, () => getTagValues(event, "clone"));
48
+ }
49
+ /** Returns relays monitored by the repository. */
50
+ export function getGitRepositoryRelays(event) {
51
+ if (!isValidGitRepository(event))
52
+ return [];
53
+ return getOrComputeCachedValue(event, GitRepositoryRelaysSymbol, () => relaySet(getTagValues(event, "relays")));
54
+ }
55
+ /** Returns the earliest unique commit ID, if declared. */
56
+ export function getGitRepositoryEarliestUniqueCommit(event) {
57
+ if (!isValidGitRepository(event))
58
+ return undefined;
59
+ return event.tags.find((tag) => tag[0] === "r" && tag[2] === "euc")?.[1];
60
+ }
61
+ /** Returns all recognized maintainer pubkeys including the author of the repository event. */
62
+ export function getGitRepositoryMaintainers(event) {
63
+ if (!isValidGitRepository(event))
64
+ return [];
65
+ return getOrComputeCachedValue(event, GitRepositoryMaintainersSymbol, () => {
66
+ const pubkeys = getTagValues(event, "maintainers").filter(isHexKey);
67
+ return pubkeys.includes(event.pubkey) ? pubkeys : [event.pubkey, ...pubkeys];
68
+ });
69
+ }
70
+ /** Returns repository topic tags (NIP-34: values from each `["t", ...]` tag). */
71
+ export function getGitRepositoryHashtags(event) {
72
+ if (!isValidGitRepository(event))
73
+ return [];
74
+ return getOrComputeCachedValue(event, GitRepositoryHashtagsSymbol, () => getTagValues(event, "t"));
75
+ }
76
+ /**
77
+ * Returns the upstream repository pointer (the repo this one was forked from), if declared.
78
+ * Parsed from the `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
79
+ */
80
+ export function getGitRepositoryUpstream(event) {
81
+ if (!isValidGitRepository(event))
82
+ return undefined;
83
+ return getOrComputeCachedValue(event, GitRepositoryUpstreamSymbol, () => {
84
+ const tag = event.tags.find((t) => t[0] === "u" && t[1]);
85
+ if (!tag || !tag[1])
86
+ return undefined;
87
+ const parts = tag[1].split(":");
88
+ if (parts.length < 3)
89
+ return undefined;
90
+ const kind = parseInt(parts[0]);
91
+ const pubkey = parts[1];
92
+ const identifier = parts.slice(2).join(":");
93
+ if (kind !== GIT_REPOSITORY_KIND)
94
+ return undefined;
95
+ if (!pubkey || !/^[0-9a-f]{64}$/i.test(pubkey))
96
+ return undefined;
97
+ if (!identifier)
98
+ return undefined;
99
+ const pointer = { kind: GIT_REPOSITORY_KIND, pubkey: pubkey.toLowerCase(), identifier };
100
+ if (tag[2] && isSafeRelayURL(tag[2]))
101
+ pointer.relays = [normalizeURL(tag[2])];
102
+ return pointer;
103
+ });
104
+ }
@@ -16,6 +16,9 @@ export * from "./emoji-pack.js";
16
16
  export * from "./encrypted-content-cache.js";
17
17
  export * from "./file-metadata.js";
18
18
  export * from "./gift-wrap.js";
19
+ export * from "./git-grasp-list.js";
20
+ export * from "./git-lists.js";
21
+ export * from "./git-repository.js";
19
22
  export * from "./groups.js";
20
23
  export * from "./hashtag.js";
21
24
  export * from "./highlight.js";
@@ -16,6 +16,9 @@ export * from "./emoji-pack.js";
16
16
  export * from "./encrypted-content-cache.js";
17
17
  export * from "./file-metadata.js";
18
18
  export * from "./gift-wrap.js";
19
+ export * from "./git-grasp-list.js";
20
+ export * from "./git-lists.js";
21
+ export * from "./git-repository.js";
19
22
  export * from "./groups.js";
20
23
  export * from "./hashtag.js";
21
24
  export * from "./highlight.js";
@@ -1,11 +1,16 @@
1
1
  import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
2
  export declare const FAVORITE_RELAYS_KIND = 10012;
3
+ /** Indexer / lookup relays: where to fetch or publish kinds 0 and 10002 (NIP-51 `relay` tags). */
4
+ export declare const LOOKUP_RELAY_LIST_KIND = 10086;
3
5
  export type FavoriteRelaysListEvent = KnownEvent<typeof FAVORITE_RELAYS_KIND>;
6
+ export type LookupRelayListEvent = KnownEvent<typeof LOOKUP_RELAY_LIST_KIND>;
4
7
  export type SearchRelaysListEvent = KnownEvent<typeof kinds.SearchRelaysList>;
5
8
  export type BlockedRelaysListEvent = KnownEvent<typeof kinds.BlockedRelaysList>;
6
9
  export type DMRelaysListEvent = KnownEvent<typeof kinds.DirectMessageRelaysList>;
7
10
  /** Validates that an event is a valid favorite relays list (kind 10012) */
8
11
  export declare function isValidFavoriteRelaysList(event: NostrEvent): event is FavoriteRelaysListEvent;
12
+ /** Validates that an event is a valid lookup / indexer relays list (kind 10086) */
13
+ export declare function isValidLookupRelayList(event: NostrEvent): event is LookupRelayListEvent;
9
14
  /** Validates that an event is a valid search relays list (kind 10007) */
10
15
  export declare function isValidSearchRelaysList(event: NostrEvent): event is SearchRelaysListEvent;
11
16
  /** Validates that an event is a valid blocked relays list (kind 10006) */
@@ -1,9 +1,17 @@
1
+ import { setHiddenTagsEncryptionMethod } from "applesauce-core/helpers/hidden-tags";
1
2
  import { kinds } from "applesauce-core/helpers/event";
2
3
  export const FAVORITE_RELAYS_KIND = 10012;
4
+ /** Indexer / lookup relays: where to fetch or publish kinds 0 and 10002 (NIP-51 `relay` tags). */
5
+ export const LOOKUP_RELAY_LIST_KIND = 10086;
6
+ setHiddenTagsEncryptionMethod(LOOKUP_RELAY_LIST_KIND, "nip04");
3
7
  /** Validates that an event is a valid favorite relays list (kind 10012) */
4
8
  export function isValidFavoriteRelaysList(event) {
5
9
  return event.kind === FAVORITE_RELAYS_KIND;
6
10
  }
11
+ /** Validates that an event is a valid lookup / indexer relays list (kind 10086) */
12
+ export function isValidLookupRelayList(event) {
13
+ return event.kind === LOOKUP_RELAY_LIST_KIND;
14
+ }
7
15
  /** Validates that an event is a valid search relays list (kind 10007) */
8
16
  export function isValidSearchRelaysList(event) {
9
17
  return event.kind === kinds.SearchRelaysList;
@@ -1,8 +1 @@
1
- import type { NostrEvent } from "applesauce-core/helpers/event";
2
- import { OperatorFunction } from "rxjs";
3
- import type { CastConstructor, CastRefEventStore } from "../casts/cast.js";
4
- import { EventCast } from "../casts/cast.js";
5
- /** Casts an event to a specific type */
6
- export declare function castEventStream<C extends EventCast>(cls: CastConstructor<C>, store?: CastRefEventStore): OperatorFunction<NostrEvent | undefined, C | undefined>;
7
- /** Casts and array of events to an array of casted events and filters out undefined values */
8
- export declare function castTimelineStream<C extends EventCast>(cls: CastConstructor<C>, store?: CastRefEventStore): OperatorFunction<NostrEvent[], C[]>;
1
+ export * from "applesauce-core/observable/cast-stream";