applesauce-common 5.1.0 → 6.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.
- package/dist/casts/_circular-import.d.ts +7 -0
- package/dist/casts/_circular-import.js +9 -0
- package/dist/casts/article.d.ts +1 -1
- package/dist/casts/badge-award.d.ts +24 -0
- package/dist/casts/badge-award.js +39 -0
- package/dist/casts/badge.d.ts +19 -0
- package/dist/casts/badge.js +48 -0
- package/dist/casts/bookmarks.d.ts +5 -5
- package/dist/casts/cast.d.ts +1 -30
- package/dist/casts/cast.js +2 -67
- package/dist/casts/comment.d.ts +5 -5
- package/dist/casts/emoji-pack.d.ts +11 -0
- package/dist/casts/emoji-pack.js +25 -0
- package/dist/casts/favorite-emojis.d.ts +25 -0
- package/dist/casts/favorite-emojis.js +62 -0
- package/dist/casts/file-metadata.d.ts +22 -0
- package/dist/casts/file-metadata.js +55 -0
- package/dist/casts/groups.d.ts +1 -1
- package/dist/casts/index.d.ts +7 -0
- package/dist/casts/index.js +7 -0
- package/dist/casts/mutes.d.ts +1 -1
- package/dist/casts/note.d.ts +7 -7
- package/dist/casts/profile-badges.d.ts +28 -0
- package/dist/casts/profile-badges.js +59 -0
- package/dist/casts/reaction.d.ts +1 -1
- package/dist/casts/relay-lists.d.ts +1 -1
- package/dist/casts/relay-monitor.d.ts +1 -1
- package/dist/casts/report.d.ts +2 -2
- package/dist/casts/share.d.ts +2 -2
- package/dist/casts/stream.d.ts +9 -9
- package/dist/casts/torrent.d.ts +3 -3
- package/dist/casts/trusted-assertions.d.ts +144 -0
- package/dist/casts/trusted-assertions.js +281 -0
- package/dist/casts/user.d.ts +22 -38
- package/dist/casts/user.js +106 -153
- package/dist/casts/zap-goal.d.ts +2 -2
- package/dist/casts/zap.d.ts +4 -4
- package/dist/factories/app-data.d.ts +13 -0
- package/dist/factories/app-data.js +20 -0
- package/dist/factories/badge-award.d.ts +25 -0
- package/dist/factories/badge-award.js +41 -0
- package/dist/factories/badge.d.ts +32 -0
- package/dist/factories/badge.js +50 -0
- package/dist/factories/blocked-relays.d.ts +10 -0
- package/dist/factories/blocked-relays.js +16 -0
- package/dist/factories/blossom-server-list.d.ts +19 -0
- package/dist/factories/blossom-server-list.js +36 -0
- package/dist/factories/bookmark-list.d.ts +23 -0
- package/dist/factories/bookmark-list.js +45 -0
- package/dist/factories/bookmark-set.d.ts +25 -0
- package/dist/factories/bookmark-set.js +51 -0
- package/dist/factories/calendar-event.d.ts +88 -0
- package/dist/factories/calendar-event.js +175 -0
- package/dist/factories/calendar-rsvp.d.ts +22 -0
- package/dist/factories/calendar-rsvp.js +35 -0
- package/dist/factories/calendar.d.ts +20 -0
- package/dist/factories/calendar.js +36 -0
- package/dist/factories/code-snippet.d.ts +65 -0
- package/dist/factories/code-snippet.js +100 -0
- package/dist/factories/comment.d.ts +26 -0
- package/dist/factories/comment.js +49 -0
- package/dist/factories/contacts.d.ts +19 -0
- package/dist/factories/contacts.js +36 -0
- package/dist/factories/dm-relays.d.ts +10 -0
- package/dist/factories/dm-relays.js +16 -0
- package/dist/factories/favorite-relays.d.ts +16 -0
- package/dist/factories/favorite-relays.js +31 -0
- package/dist/factories/file-metadata.d.ts +54 -0
- package/dist/factories/file-metadata.js +92 -0
- package/dist/factories/follow-set.d.ts +12 -0
- package/dist/factories/follow-set.js +22 -0
- package/dist/factories/gift-wrap.d.ts +17 -0
- package/dist/factories/gift-wrap.js +21 -0
- package/dist/factories/group-management.d.ts +63 -0
- package/dist/factories/group-management.js +147 -0
- package/dist/factories/group.d.ts +35 -0
- package/dist/factories/group.js +69 -0
- package/dist/factories/highlight.d.ts +33 -0
- package/dist/factories/highlight.js +49 -0
- package/dist/factories/index.d.ts +41 -0
- package/dist/factories/index.js +41 -0
- package/dist/factories/legacy-message.d.ts +10 -0
- package/dist/factories/legacy-message.js +19 -0
- package/dist/factories/list.d.ts +56 -0
- package/dist/factories/list.js +120 -0
- package/dist/factories/live-stream.d.ts +48 -0
- package/dist/factories/live-stream.js +90 -0
- package/dist/factories/mute-list.d.ts +27 -0
- package/dist/factories/mute-list.js +57 -0
- package/dist/factories/note.d.ts +38 -0
- package/dist/factories/note.js +66 -0
- package/dist/factories/picture-post.d.ts +28 -0
- package/dist/factories/picture-post.js +46 -0
- package/dist/factories/pin-list.d.ts +14 -0
- package/dist/factories/pin-list.js +24 -0
- package/dist/factories/poll-response.d.ts +36 -0
- package/dist/factories/poll-response.js +46 -0
- package/dist/factories/poll.d.ts +35 -0
- package/dist/factories/poll.js +48 -0
- package/dist/factories/profile-badges.d.ts +31 -0
- package/dist/factories/profile-badges.js +52 -0
- package/dist/factories/reaction.d.ts +22 -0
- package/dist/factories/reaction.js +37 -0
- package/dist/factories/relay-set.d.ts +12 -0
- package/dist/factories/relay-set.js +22 -0
- package/dist/factories/search-relays.d.ts +10 -0
- package/dist/factories/search-relays.js +16 -0
- package/dist/factories/share.d.ts +26 -0
- package/dist/factories/share.js +44 -0
- package/dist/factories/stream-chat-message.d.ts +22 -0
- package/dist/factories/stream-chat-message.js +31 -0
- package/dist/factories/torrent.d.ts +57 -0
- package/dist/factories/torrent.js +93 -0
- package/dist/factories/wrapped-message.d.ts +22 -0
- package/dist/factories/wrapped-message.js +39 -0
- package/dist/factories/zap-goal.d.ts +35 -0
- package/dist/factories/zap-goal.js +49 -0
- package/dist/factories/zap-request.d.ts +28 -0
- package/dist/factories/zap-request.js +55 -0
- package/dist/factories/zap.d.ts +13 -0
- package/dist/factories/zap.js +21 -0
- package/dist/helpers/badge-award.d.ts +15 -0
- package/dist/helpers/badge-award.js +32 -0
- package/dist/helpers/badge.d.ts +27 -0
- package/dist/helpers/badge.js +59 -0
- package/dist/helpers/blossom.d.ts +29 -1
- package/dist/helpers/blossom.js +64 -7
- package/dist/helpers/emoji-pack.d.ts +43 -0
- package/dist/helpers/emoji-pack.js +108 -0
- package/dist/helpers/emoji.d.ts +4 -5
- package/dist/helpers/emoji.js +3 -15
- package/dist/helpers/file-metadata.d.ts +18 -13
- package/dist/helpers/file-metadata.js +10 -4
- package/dist/helpers/groups.d.ts +1 -0
- package/dist/helpers/groups.js +3 -2
- package/dist/helpers/hashtag.d.ts +1 -0
- package/dist/helpers/hashtag.js +3 -3
- package/dist/helpers/index.d.ts +7 -2
- package/dist/helpers/index.js +7 -2
- package/dist/helpers/lists.d.ts +8 -0
- package/dist/helpers/lists.js +27 -5
- package/dist/helpers/picture-post.d.ts +2 -2
- package/dist/helpers/profile-badges.d.ts +23 -0
- package/dist/helpers/profile-badges.js +51 -0
- package/dist/helpers/trusted-assertions.d.ts +81 -0
- package/dist/helpers/trusted-assertions.js +161 -0
- package/dist/helpers/zap.d.ts +8 -2
- package/dist/helpers/zap.js +31 -26
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.js +1 -1
- package/dist/models/thread.d.ts +1 -1
- package/dist/models/thread.js +23 -7
- package/dist/observable/chainable.d.ts +1 -36
- package/dist/observable/chainable.js +2 -72
- package/dist/operations/app-data.d.ts +8 -3
- package/dist/operations/app-data.js +9 -4
- package/dist/operations/badge-award.d.ts +17 -0
- package/dist/operations/badge-award.js +30 -0
- package/dist/operations/badge.d.ts +22 -0
- package/dist/operations/badge.js +54 -0
- package/dist/operations/blossom.d.ts +1 -1
- package/dist/operations/calendar-event.d.ts +1 -1
- package/dist/operations/calendar-rsvp.d.ts +1 -1
- package/dist/operations/calendar.d.ts +1 -1
- package/dist/operations/channel.d.ts +1 -1
- package/dist/operations/client.d.ts +1 -1
- package/dist/operations/client.js +2 -2
- package/dist/operations/code-snippet.d.ts +27 -0
- package/dist/operations/code-snippet.js +63 -0
- package/dist/operations/comment.d.ts +7 -3
- package/dist/operations/comment.js +8 -4
- package/dist/operations/file-metadata.d.ts +38 -4
- package/dist/operations/file-metadata.js +105 -19
- package/dist/operations/geohash.d.ts +1 -1
- package/dist/operations/gift-wrap.d.ts +19 -7
- package/dist/operations/gift-wrap.js +36 -26
- package/dist/operations/group.d.ts +1 -1
- package/dist/operations/hashtags.d.ts +1 -1
- package/dist/operations/highlight.d.ts +1 -1
- package/dist/operations/highlight.js +5 -5
- package/dist/operations/index.d.ts +7 -1
- package/dist/operations/index.js +7 -1
- package/dist/operations/legacy-message.d.ts +1 -1
- package/dist/operations/list.d.ts +1 -1
- package/dist/operations/live-stream.d.ts +7 -3
- package/dist/operations/live-stream.js +9 -5
- package/dist/operations/media-attachment.d.ts +3 -3
- package/dist/operations/note.d.ts +10 -4
- package/dist/operations/note.js +14 -8
- package/dist/operations/picture-post.d.ts +1 -1
- package/dist/operations/poll-response.d.ts +1 -1
- package/dist/operations/poll-response.js +1 -1
- package/dist/operations/poll.d.ts +1 -1
- package/dist/operations/profile-badges.d.ts +26 -0
- package/dist/operations/profile-badges.js +150 -0
- package/dist/operations/reaction.d.ts +8 -3
- package/dist/operations/reaction.js +10 -5
- package/dist/operations/share.d.ts +8 -3
- package/dist/operations/share.js +10 -5
- package/dist/operations/stream.d.ts +1 -1
- package/dist/operations/tag/bookmarks.d.ts +1 -1
- package/dist/operations/torrent.d.ts +1 -1
- package/dist/operations/wrapped-message.d.ts +1 -1
- package/dist/operations/zap-goal.d.ts +1 -1
- package/dist/operations/zap-request.d.ts +22 -0
- package/dist/operations/zap-request.js +40 -0
- package/dist/operations/zap-split.d.ts +8 -4
- package/dist/operations/zap-split.js +10 -6
- package/dist/operations/zap.d.ts +12 -0
- package/dist/operations/zap.js +34 -0
- package/package.json +13 -12
- package/dist/blueprints/__register__.d.ts +0 -7
- package/dist/blueprints/__register__.js +0 -8
- package/dist/blueprints/app-data.d.ts +0 -5
- package/dist/blueprints/app-data.js +0 -10
- package/dist/blueprints/calendar.d.ts +0 -5
- package/dist/blueprints/calendar.js +0 -7
- package/dist/blueprints/channels.d.ts +0 -6
- package/dist/blueprints/channels.js +0 -13
- package/dist/blueprints/comment.d.ts +0 -13
- package/dist/blueprints/comment.js +0 -15
- package/dist/blueprints/delete.d.ts +0 -9
- package/dist/blueprints/delete.js +0 -14
- package/dist/blueprints/file-metadata.d.ts +0 -8
- package/dist/blueprints/file-metadata.js +0 -11
- package/dist/blueprints/follow-set.d.ts +0 -11
- package/dist/blueprints/follow-set.js +0 -21
- package/dist/blueprints/gift-wrap.d.ts +0 -5
- package/dist/blueprints/gift-wrap.js +0 -6
- package/dist/blueprints/group-mangement.d.ts +0 -25
- package/dist/blueprints/group-mangement.js +0 -40
- package/dist/blueprints/group.d.ts +0 -9
- package/dist/blueprints/group.js +0 -17
- package/dist/blueprints/highlight.d.ts +0 -20
- package/dist/blueprints/highlight.js +0 -12
- package/dist/blueprints/index.d.ts +0 -25
- package/dist/blueprints/index.js +0 -26
- package/dist/blueprints/legacy-message.d.ts +0 -7
- package/dist/blueprints/legacy-message.js +0 -29
- package/dist/blueprints/live-stream.d.ts +0 -6
- package/dist/blueprints/live-stream.js +0 -9
- package/dist/blueprints/note.d.ts +0 -16
- package/dist/blueprints/note.js +0 -30
- package/dist/blueprints/picture-post.d.ts +0 -12
- package/dist/blueprints/picture-post.js +0 -17
- package/dist/blueprints/poll.d.ts +0 -41
- package/dist/blueprints/poll.js +0 -33
- package/dist/blueprints/profile.d.ts +0 -3
- package/dist/blueprints/profile.js +0 -7
- package/dist/blueprints/reaction.d.ts +0 -10
- package/dist/blueprints/reaction.js +0 -14
- package/dist/blueprints/share.d.ts +0 -12
- package/dist/blueprints/share.js +0 -25
- package/dist/blueprints/stream.d.ts +0 -6
- package/dist/blueprints/stream.js +0 -7
- package/dist/blueprints/torrent.d.ts +0 -30
- package/dist/blueprints/torrent.js +0 -29
- package/dist/blueprints/wrapped-message.d.ts +0 -20
- package/dist/blueprints/wrapped-message.js +0 -64
- package/dist/blueprints/zap-goal.d.ts +0 -16
- package/dist/blueprints/zap-goal.js +0 -12
- package/dist/register.d.ts +0 -2
- package/dist/register.js +0 -4
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isKind, kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { addEventPointerTag, addNameValueTag, removeEventPointerTag, removeNameValueTag, } from "applesauce-core/operations/tag/common";
|
|
4
|
+
import { NIP51UserListFactory } from "./list.js";
|
|
5
|
+
/** A factory class for building kind 10000 mute list events */
|
|
6
|
+
export class MuteListFactory extends NIP51UserListFactory {
|
|
7
|
+
/** Creates a new mute list factory */
|
|
8
|
+
static create() {
|
|
9
|
+
return new MuteListFactory((res) => res(blankEventTemplate(kinds.Mutelist)));
|
|
10
|
+
}
|
|
11
|
+
/** Creates a new mute list factory from an existing mute list event */
|
|
12
|
+
static modify(event) {
|
|
13
|
+
if (!isKind(event, kinds.Mutelist))
|
|
14
|
+
throw new Error("Event is not a mute list event");
|
|
15
|
+
return new MuteListFactory((res) => res(toEventTemplate(event)));
|
|
16
|
+
}
|
|
17
|
+
/** Mutes a thread by event id or EventPointer */
|
|
18
|
+
muteThread(thread, hidden = false) {
|
|
19
|
+
return hidden
|
|
20
|
+
? this.modifyHiddenTags(addEventPointerTag(thread))
|
|
21
|
+
: this.modifyPublicTags(addEventPointerTag(thread));
|
|
22
|
+
}
|
|
23
|
+
/** Unmutes a thread by event id or EventPointer */
|
|
24
|
+
unmuteThread(thread, hidden = false) {
|
|
25
|
+
return hidden
|
|
26
|
+
? this.modifyHiddenTags(removeEventPointerTag(thread))
|
|
27
|
+
: this.modifyPublicTags(removeEventPointerTag(thread));
|
|
28
|
+
}
|
|
29
|
+
/** Mutes a word */
|
|
30
|
+
muteWord(word, hidden = false) {
|
|
31
|
+
const op = addNameValueTag(["word", word.toLocaleLowerCase()], true);
|
|
32
|
+
return hidden ? this.modifyHiddenTags(op) : this.modifyPublicTags(op);
|
|
33
|
+
}
|
|
34
|
+
/** Unmutes a word */
|
|
35
|
+
unmuteWord(word, hidden = false) {
|
|
36
|
+
const op = removeNameValueTag(["word", word.toLocaleLowerCase()]);
|
|
37
|
+
return hidden ? this.modifyHiddenTags(op) : this.modifyPublicTags(op);
|
|
38
|
+
}
|
|
39
|
+
/** Mutes a hashtag */
|
|
40
|
+
muteHashtag(hashtag, hidden = false) {
|
|
41
|
+
const op = addNameValueTag(["t", hashtag.toLocaleLowerCase()], true);
|
|
42
|
+
return hidden ? this.modifyHiddenTags(op) : this.modifyPublicTags(op);
|
|
43
|
+
}
|
|
44
|
+
/** Unmutes a hashtag */
|
|
45
|
+
unmuteHashtag(hashtag, hidden = false) {
|
|
46
|
+
const op = removeNameValueTag(["t", hashtag.toLocaleLowerCase()]);
|
|
47
|
+
return hidden ? this.modifyHiddenTags(op) : this.modifyPublicTags(op);
|
|
48
|
+
}
|
|
49
|
+
/** Mutes a pubkey — semantic alias for addUser() */
|
|
50
|
+
mutePubkey(pubkey, hidden = false) {
|
|
51
|
+
return this.addUser(pubkey, hidden);
|
|
52
|
+
}
|
|
53
|
+
/** Unmutes a pubkey — semantic alias for removeUser() */
|
|
54
|
+
unmutePubkey(pubkey, hidden = false) {
|
|
55
|
+
return this.removeUser(pubkey, hidden);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
4
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
5
|
+
import { ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
6
|
+
import { ZapOptions } from "../operations/zap-split.js";
|
|
7
|
+
export type NoteTemplate = KnownEventTemplate<kinds.ShortTextNote>;
|
|
8
|
+
export type NoteBlueprintOptions = TextContentOptions & MetaTagOptions & ZapOptions;
|
|
9
|
+
/** A factory class for building kind 1 short text note events */
|
|
10
|
+
export declare class NoteFactory extends EventFactory<kinds.ShortTextNote, NoteTemplate> {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new note factory
|
|
13
|
+
* @param content - Optional initial content
|
|
14
|
+
* @returns A new note factory
|
|
15
|
+
*/
|
|
16
|
+
static create(content?: string): NoteFactory;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a note reply factory
|
|
19
|
+
* @param parent - The parent note to reply to
|
|
20
|
+
* @param content - Optional initial content
|
|
21
|
+
* @returns A new note factory configured as a reply
|
|
22
|
+
*/
|
|
23
|
+
static reply(parent: NostrEvent, content?: string): NoteFactory;
|
|
24
|
+
/** Sets the parent note for NIP-10 threading */
|
|
25
|
+
replyTo(parent: NostrEvent): this;
|
|
26
|
+
/** Sets the text content with optional formatting */
|
|
27
|
+
text(content: string, options?: TextContentOptions): this;
|
|
28
|
+
/** Adds a "p" mention tag for a pubkey or ProfilePointer */
|
|
29
|
+
mention(pubkey: string | ProfilePointer): this;
|
|
30
|
+
/** Sets the NIP-14 thread subject tag */
|
|
31
|
+
subject(subject: string): this;
|
|
32
|
+
/** Adds a hashtag "t" tag */
|
|
33
|
+
addHashtag(hashtag: string): this;
|
|
34
|
+
/** Adds multiple hashtags as "t" tags */
|
|
35
|
+
hashtags(tags: string[]): this;
|
|
36
|
+
/** Sets zap split configuration */
|
|
37
|
+
zapSplit(options: ZapOptions): this;
|
|
38
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { isKind, kinds, pipeFromAsyncArray } from "applesauce-core/helpers";
|
|
3
|
+
import { setShortTextContent } from "applesauce-core/operations/content";
|
|
4
|
+
import { includeNameValueTag } from "applesauce-core/operations/tags";
|
|
5
|
+
import { ensureProfilePointerTag } from "applesauce-core/helpers/factory";
|
|
6
|
+
import { includePubkeyNotificationTags, setThreadParent } from "../operations/note.js";
|
|
7
|
+
import { addHashtag, includeHashtags } from "../operations/hashtags.js";
|
|
8
|
+
import { setZapSplit } from "../operations/zap-split.js";
|
|
9
|
+
/** A factory class for building kind 1 short text note events */
|
|
10
|
+
export class NoteFactory extends EventFactory {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new note factory
|
|
13
|
+
* @param content - Optional initial content
|
|
14
|
+
* @returns A new note factory
|
|
15
|
+
*/
|
|
16
|
+
static create(content) {
|
|
17
|
+
const factory = new NoteFactory((res) => res(blankEventTemplate(kinds.ShortTextNote)));
|
|
18
|
+
return content ? factory.text(content) : factory;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a note reply factory
|
|
22
|
+
* @param parent - The parent note to reply to
|
|
23
|
+
* @param content - Optional initial content
|
|
24
|
+
* @returns A new note factory configured as a reply
|
|
25
|
+
*/
|
|
26
|
+
static reply(parent, content) {
|
|
27
|
+
if (!isKind(parent, kinds.ShortTextNote))
|
|
28
|
+
throw new Error("Kind 1 replies should only be used to reply to kind 1 notes");
|
|
29
|
+
const factory = new NoteFactory((res) => res(blankEventTemplate(kinds.ShortTextNote))).replyTo(parent);
|
|
30
|
+
return content ? factory.text(content) : factory;
|
|
31
|
+
}
|
|
32
|
+
/** Sets the parent note for NIP-10 threading */
|
|
33
|
+
replyTo(parent) {
|
|
34
|
+
return this.chain(pipeFromAsyncArray([
|
|
35
|
+
// Add the "e" tags for the thread
|
|
36
|
+
setThreadParent(parent, undefined),
|
|
37
|
+
// Copy the "p" tags from the parent event
|
|
38
|
+
includePubkeyNotificationTags(parent, undefined),
|
|
39
|
+
]));
|
|
40
|
+
}
|
|
41
|
+
/** Sets the text content with optional formatting */
|
|
42
|
+
text(content, options) {
|
|
43
|
+
return this.chain(setShortTextContent(content, options));
|
|
44
|
+
}
|
|
45
|
+
/** Adds a "p" mention tag for a pubkey or ProfilePointer */
|
|
46
|
+
mention(pubkey) {
|
|
47
|
+
const pointer = typeof pubkey === "string" ? { pubkey } : pubkey;
|
|
48
|
+
return this.modifyPublicTags((tags) => ensureProfilePointerTag(tags, pointer));
|
|
49
|
+
}
|
|
50
|
+
/** Sets the NIP-14 thread subject tag */
|
|
51
|
+
subject(subject) {
|
|
52
|
+
return this.chain(includeNameValueTag(["subject", subject]));
|
|
53
|
+
}
|
|
54
|
+
/** Adds a hashtag "t" tag */
|
|
55
|
+
addHashtag(hashtag) {
|
|
56
|
+
return this.chain(addHashtag(hashtag));
|
|
57
|
+
}
|
|
58
|
+
/** Adds multiple hashtags as "t" tags */
|
|
59
|
+
hashtags(tags) {
|
|
60
|
+
return this.chain(includeHashtags(tags));
|
|
61
|
+
}
|
|
62
|
+
/** Sets zap split configuration */
|
|
63
|
+
zapSplit(options) {
|
|
64
|
+
return this.chain(setZapSplit(options, undefined));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate } from "applesauce-core/helpers";
|
|
3
|
+
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
4
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
5
|
+
import { FileMetadataFields } from "../helpers/file-metadata.js";
|
|
6
|
+
import { PICTURE_POST_KIND } from "../helpers/picture-post.js";
|
|
7
|
+
export type PicturePostTemplate = KnownEventTemplate<typeof PICTURE_POST_KIND>;
|
|
8
|
+
/** A factory class for building kind 20 picture post events */
|
|
9
|
+
export declare class PicturePostFactory extends EventFactory<typeof PICTURE_POST_KIND, PicturePostTemplate> {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new picture post factory
|
|
12
|
+
* @param attachments - One or more image attachments
|
|
13
|
+
* @param caption - Optional caption text
|
|
14
|
+
*/
|
|
15
|
+
static create(attachments: FileMetadataFields | FileMetadataFields[], caption?: string): PicturePostFactory;
|
|
16
|
+
/** Adds image attachments via "imeta" tags */
|
|
17
|
+
attachments(attachments: FileMetadataFields[]): this;
|
|
18
|
+
/** Sets the image metadata (x/m tags) for the post */
|
|
19
|
+
imageMetadata(pictures: FileMetadataFields[]): this;
|
|
20
|
+
/** Sets the caption/content of the picture post */
|
|
21
|
+
caption(text: string, options?: TextContentOptions): this;
|
|
22
|
+
/** Adds a hashtag "t" tag to the post */
|
|
23
|
+
addHashtag(hashtag: string): this;
|
|
24
|
+
/** Adds multiple hashtags as "t" tags */
|
|
25
|
+
hashtags(tags: string[]): this;
|
|
26
|
+
/** Sets meta tags */
|
|
27
|
+
meta(options: MetaTagOptions): this;
|
|
28
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { setShortTextContent } from "applesauce-core/operations/content";
|
|
3
|
+
import { setMetaTags } from "applesauce-core/operations/event";
|
|
4
|
+
import { PICTURE_POST_KIND } from "../helpers/picture-post.js";
|
|
5
|
+
import { setImageMetadata } from "../operations/picture-post.js";
|
|
6
|
+
import { addMediaAttachments } from "../operations/media-attachment.js";
|
|
7
|
+
import { addHashtag, includeHashtags } from "../operations/hashtags.js";
|
|
8
|
+
/** A factory class for building kind 20 picture post events */
|
|
9
|
+
export class PicturePostFactory extends EventFactory {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new picture post factory
|
|
12
|
+
* @param attachments - One or more image attachments
|
|
13
|
+
* @param caption - Optional caption text
|
|
14
|
+
*/
|
|
15
|
+
static create(attachments, caption) {
|
|
16
|
+
const list = Array.isArray(attachments) ? attachments : [attachments];
|
|
17
|
+
let factory = new PicturePostFactory((res) => res(blankEventTemplate(PICTURE_POST_KIND))).attachments(list);
|
|
18
|
+
if (caption)
|
|
19
|
+
factory = factory.caption(caption);
|
|
20
|
+
return factory;
|
|
21
|
+
}
|
|
22
|
+
/** Adds image attachments via "imeta" tags */
|
|
23
|
+
attachments(attachments) {
|
|
24
|
+
return this.chain(addMediaAttachments(attachments));
|
|
25
|
+
}
|
|
26
|
+
/** Sets the image metadata (x/m tags) for the post */
|
|
27
|
+
imageMetadata(pictures) {
|
|
28
|
+
return this.chain(setImageMetadata(pictures));
|
|
29
|
+
}
|
|
30
|
+
/** Sets the caption/content of the picture post */
|
|
31
|
+
caption(text, options) {
|
|
32
|
+
return this.chain(setShortTextContent(text, options));
|
|
33
|
+
}
|
|
34
|
+
/** Adds a hashtag "t" tag to the post */
|
|
35
|
+
addHashtag(hashtag) {
|
|
36
|
+
return this.chain(addHashtag(hashtag));
|
|
37
|
+
}
|
|
38
|
+
/** Adds multiple hashtags as "t" tags */
|
|
39
|
+
hashtags(tags) {
|
|
40
|
+
return this.chain(includeHashtags(tags));
|
|
41
|
+
}
|
|
42
|
+
/** Sets meta tags */
|
|
43
|
+
meta(options) {
|
|
44
|
+
return this.chain(setMetaTags(options));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
2
|
+
import { NIP51ItemListFactory } from "./list.js";
|
|
3
|
+
export type PinListTemplate = KnownEventTemplate<kinds.Pinlist>;
|
|
4
|
+
/** A factory class for building kind 10001 pin list events */
|
|
5
|
+
export declare class PinListFactory extends NIP51ItemListFactory<kinds.Pinlist, PinListTemplate> {
|
|
6
|
+
/** Creates a new pin list factory */
|
|
7
|
+
static create(): PinListFactory;
|
|
8
|
+
/** Creates a new pin list factory from an existing pin list event */
|
|
9
|
+
static modify(event: NostrEvent | KnownEvent<kinds.Pinlist>): PinListFactory;
|
|
10
|
+
/** Pins an event — uses an "a" tag for replaceable events, "e" tag for others */
|
|
11
|
+
pinEvent(event: NostrEvent, hidden?: boolean): this;
|
|
12
|
+
/** Unpins an event — uses an "a" tag for replaceable events, "e" tag for others */
|
|
13
|
+
unpinEvent(event: NostrEvent, hidden?: boolean): this;
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isKind, isReplaceable, kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { NIP51ItemListFactory } from "./list.js";
|
|
4
|
+
/** A factory class for building kind 10001 pin list events */
|
|
5
|
+
export class PinListFactory extends NIP51ItemListFactory {
|
|
6
|
+
/** Creates a new pin list factory */
|
|
7
|
+
static create() {
|
|
8
|
+
return new PinListFactory((res) => res(blankEventTemplate(kinds.Pinlist)));
|
|
9
|
+
}
|
|
10
|
+
/** Creates a new pin list factory from an existing pin list event */
|
|
11
|
+
static modify(event) {
|
|
12
|
+
if (!isKind(event, kinds.Pinlist))
|
|
13
|
+
throw new Error("Event is not a pin list event");
|
|
14
|
+
return new PinListFactory((res) => res(toEventTemplate(event)));
|
|
15
|
+
}
|
|
16
|
+
/** Pins an event — uses an "a" tag for replaceable events, "e" tag for others */
|
|
17
|
+
pinEvent(event, hidden = false) {
|
|
18
|
+
return isReplaceable(event.kind) ? this.addAddressItem(event, hidden) : this.addEventItem(event, hidden);
|
|
19
|
+
}
|
|
20
|
+
/** Unpins an event — uses an "a" tag for replaceable events, "e" tag for others */
|
|
21
|
+
unpinEvent(event, hidden = false) {
|
|
22
|
+
return isReplaceable(event.kind) ? this.removeAddressItem(event, hidden) : this.removeEventItem(event.id, hidden);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { EventPointer } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
5
|
+
import { POLL_RESPONSE_KIND } from "../helpers/poll.js";
|
|
6
|
+
export type PollResponseTemplate = KnownEventTemplate<typeof POLL_RESPONSE_KIND>;
|
|
7
|
+
export type PollResponseBlueprintOptions = MetaTagOptions & {
|
|
8
|
+
comment?: string;
|
|
9
|
+
};
|
|
10
|
+
/** A factory class for building NIP-88 poll response events (kind 1018) */
|
|
11
|
+
export declare class PollResponseFactory extends EventFactory<typeof POLL_RESPONSE_KIND, PollResponseTemplate> {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new poll response factory for multiple choices
|
|
14
|
+
* @param poll - The poll event, pointer, or ID
|
|
15
|
+
* @param optionIds - The selected option IDs
|
|
16
|
+
* @returns A new poll response factory
|
|
17
|
+
*/
|
|
18
|
+
static create(poll: NostrEvent | EventPointer | string, optionIds: string[]): PollResponseFactory;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new poll response for a single choice
|
|
21
|
+
* @param poll - The poll event, pointer, or ID
|
|
22
|
+
* @param optionId - The selected option ID
|
|
23
|
+
* @returns A new poll response factory
|
|
24
|
+
*/
|
|
25
|
+
static single(poll: NostrEvent | EventPointer | string, optionId: string): PollResponseFactory;
|
|
26
|
+
/** Sets the poll being responded to */
|
|
27
|
+
poll(poll: NostrEvent | EventPointer | string): this;
|
|
28
|
+
/** Sets multiple choice selections */
|
|
29
|
+
choices(optionIds: string[]): this;
|
|
30
|
+
/** Sets a single choice selection */
|
|
31
|
+
choice(optionId: string): this;
|
|
32
|
+
/** Sets an optional comment */
|
|
33
|
+
comment(comment: string): this;
|
|
34
|
+
/** Sets meta tags */
|
|
35
|
+
meta(options: MetaTagOptions): this;
|
|
36
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { setContent } from "applesauce-core/operations/content";
|
|
3
|
+
import { setMetaTags } from "applesauce-core/operations/event";
|
|
4
|
+
import { POLL_RESPONSE_KIND } from "../helpers/poll.js";
|
|
5
|
+
import * as PollResponse from "../operations/poll-response.js";
|
|
6
|
+
/** A factory class for building NIP-88 poll response events (kind 1018) */
|
|
7
|
+
export class PollResponseFactory extends EventFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new poll response factory for multiple choices
|
|
10
|
+
* @param poll - The poll event, pointer, or ID
|
|
11
|
+
* @param optionIds - The selected option IDs
|
|
12
|
+
* @returns A new poll response factory
|
|
13
|
+
*/
|
|
14
|
+
static create(poll, optionIds) {
|
|
15
|
+
return new PollResponseFactory((res) => res(blankEventTemplate(POLL_RESPONSE_KIND))).poll(poll).choices(optionIds);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new poll response for a single choice
|
|
19
|
+
* @param poll - The poll event, pointer, or ID
|
|
20
|
+
* @param optionId - The selected option ID
|
|
21
|
+
* @returns A new poll response factory
|
|
22
|
+
*/
|
|
23
|
+
static single(poll, optionId) {
|
|
24
|
+
return new PollResponseFactory((res) => res(blankEventTemplate(POLL_RESPONSE_KIND))).poll(poll).choice(optionId);
|
|
25
|
+
}
|
|
26
|
+
/** Sets the poll being responded to */
|
|
27
|
+
poll(poll) {
|
|
28
|
+
return this.chain((draft) => PollResponse.setPollEvent(poll)(draft));
|
|
29
|
+
}
|
|
30
|
+
/** Sets multiple choice selections */
|
|
31
|
+
choices(optionIds) {
|
|
32
|
+
return this.chain((draft) => PollResponse.setChoices(optionIds)(draft));
|
|
33
|
+
}
|
|
34
|
+
/** Sets a single choice selection */
|
|
35
|
+
choice(optionId) {
|
|
36
|
+
return this.chain((draft) => PollResponse.setChoice(optionId)(draft));
|
|
37
|
+
}
|
|
38
|
+
/** Sets an optional comment */
|
|
39
|
+
comment(comment) {
|
|
40
|
+
return this.chain((draft) => setContent(comment)(draft));
|
|
41
|
+
}
|
|
42
|
+
/** Sets meta tags */
|
|
43
|
+
meta(options) {
|
|
44
|
+
return this.chain((draft) => setMetaTags(options)(draft));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate } from "applesauce-core/helpers";
|
|
3
|
+
import { POLL_KIND, PollType } from "../helpers/poll.js";
|
|
4
|
+
import { ZapOptions } from "../operations/zap-split.js";
|
|
5
|
+
export interface PollOption {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
export type PollTemplate = KnownEventTemplate<typeof POLL_KIND>;
|
|
10
|
+
/** A factory class for building NIP-88 poll events (kind 1068) */
|
|
11
|
+
export declare class PollFactory extends EventFactory<typeof POLL_KIND, PollTemplate> {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new poll factory
|
|
14
|
+
* @param question - The poll question
|
|
15
|
+
* @param options - The poll options
|
|
16
|
+
* @returns A new poll factory
|
|
17
|
+
*/
|
|
18
|
+
static create(question: string, options: PollOption[]): PollFactory;
|
|
19
|
+
/** Sets the poll question */
|
|
20
|
+
question(question: string): this;
|
|
21
|
+
/** Sets the poll options */
|
|
22
|
+
options(options: PollOption[]): this;
|
|
23
|
+
/** Sets the poll type (singlechoice or multiplechoice) */
|
|
24
|
+
pollType(type: PollType): this;
|
|
25
|
+
/** Sets when the poll ends */
|
|
26
|
+
endsAt(timestamp: number): this;
|
|
27
|
+
/** Adds a single option to the poll */
|
|
28
|
+
addOption(id: string, label: string): this;
|
|
29
|
+
/** Sets relay URLs where responses should be published */
|
|
30
|
+
relays(urls: string[]): this;
|
|
31
|
+
/** Adds a single relay URL where responses should be published */
|
|
32
|
+
addRelay(url: string): this;
|
|
33
|
+
/** Sets zap split configuration */
|
|
34
|
+
zapSplit(options: ZapOptions): this;
|
|
35
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { POLL_KIND } from "../helpers/poll.js";
|
|
3
|
+
import * as Poll from "../operations/poll.js";
|
|
4
|
+
import { setZapSplit } from "../operations/zap-split.js";
|
|
5
|
+
/** A factory class for building NIP-88 poll events (kind 1068) */
|
|
6
|
+
export class PollFactory extends EventFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new poll factory
|
|
9
|
+
* @param question - The poll question
|
|
10
|
+
* @param options - The poll options
|
|
11
|
+
* @returns A new poll factory
|
|
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));
|
|
19
|
+
}
|
|
20
|
+
/** Sets the poll options */
|
|
21
|
+
options(options) {
|
|
22
|
+
return this.chain((draft) => Poll.setOptions(options)(draft));
|
|
23
|
+
}
|
|
24
|
+
/** Sets the poll type (singlechoice or multiplechoice) */
|
|
25
|
+
pollType(type) {
|
|
26
|
+
return this.chain((draft) => Poll.setType(type)(draft));
|
|
27
|
+
}
|
|
28
|
+
/** Sets when the poll ends */
|
|
29
|
+
endsAt(timestamp) {
|
|
30
|
+
return this.chain((draft) => Poll.setEndsAt(timestamp)(draft));
|
|
31
|
+
}
|
|
32
|
+
/** Adds a single option to the poll */
|
|
33
|
+
addOption(id, label) {
|
|
34
|
+
return this.chain((draft) => Poll.addOption(id, label)(draft));
|
|
35
|
+
}
|
|
36
|
+
/** Sets relay URLs where responses should be published */
|
|
37
|
+
relays(urls) {
|
|
38
|
+
return this.chain((draft) => Poll.setRelays(urls)(draft));
|
|
39
|
+
}
|
|
40
|
+
/** Adds a single relay URL where responses should be published */
|
|
41
|
+
addRelay(url) {
|
|
42
|
+
return this.chain((draft) => Poll.addRelay(url)(draft));
|
|
43
|
+
}
|
|
44
|
+
/** Sets zap split configuration */
|
|
45
|
+
zapSplit(options) {
|
|
46
|
+
return this.chain((draft) => setZapSplit(options, undefined)(draft));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { PROFILE_BADGES_KIND } from "../helpers/profile-badges.js";
|
|
4
|
+
import type { ProfileBadgeSlotInput } from "../operations/profile-badges.js";
|
|
5
|
+
import { removeSlotByAward, removeSlotByBadge } from "../operations/profile-badges.js";
|
|
6
|
+
export type ProfileBadgesTemplate = KnownEventTemplate<typeof PROFILE_BADGES_KIND>;
|
|
7
|
+
/** Factory for profile badges events (kind 10008) */
|
|
8
|
+
export declare class ProfileBadgesFactory extends EventFactory<typeof PROFILE_BADGES_KIND, ProfileBadgesTemplate> {
|
|
9
|
+
/** Creates a profile badges factory */
|
|
10
|
+
static create(): ProfileBadgesFactory;
|
|
11
|
+
/** Creates a factory configured to modify an existing profile badge event */
|
|
12
|
+
static modify(event: NostrEvent): ProfileBadgesFactory;
|
|
13
|
+
/** Replaces all slots */
|
|
14
|
+
slots(slots: Array<ProfileBadgeSlotInput>): this;
|
|
15
|
+
/** Adds a single slot to the end */
|
|
16
|
+
addSlot(slot: ProfileBadgeSlotInput): this;
|
|
17
|
+
/** Inserts a slot at a specific position */
|
|
18
|
+
insertSlot(index: number, slot: ProfileBadgeSlotInput): this;
|
|
19
|
+
/** Inserts a slot at the beginning */
|
|
20
|
+
prependSlot(slot: ProfileBadgeSlotInput): this;
|
|
21
|
+
/** Inserts a slot at the end */
|
|
22
|
+
appendSlot(slot: ProfileBadgeSlotInput): this;
|
|
23
|
+
/** Replaces the slot at a specific position */
|
|
24
|
+
setSlot(index: number, slot: ProfileBadgeSlotInput): this;
|
|
25
|
+
/** Removes every slot */
|
|
26
|
+
clearSlots(): this;
|
|
27
|
+
/** Removes the slot tied to a badge definition */
|
|
28
|
+
removeByBadge(badge: Parameters<typeof removeSlotByBadge>[0]): this;
|
|
29
|
+
/** Removes the slot tied to an award event */
|
|
30
|
+
removeByAward(award: Parameters<typeof removeSlotByAward>[0]): this;
|
|
31
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { LEGACY_PROFILE_BADGES_KIND, PROFILE_BADGES_KIND } from "../helpers/profile-badges.js";
|
|
3
|
+
import { addSlot, appendSlot, clearSlots, insertSlot, prependSlot, removeSlotByAward, removeSlotByBadge, setSlot, setSlots, } from "../operations/profile-badges.js";
|
|
4
|
+
/** Factory for profile badges events (kind 10008) */
|
|
5
|
+
export class ProfileBadgesFactory extends EventFactory {
|
|
6
|
+
/** Creates a profile badges factory */
|
|
7
|
+
static create() {
|
|
8
|
+
return new ProfileBadgesFactory((res) => res(blankEventTemplate(PROFILE_BADGES_KIND)));
|
|
9
|
+
}
|
|
10
|
+
/** Creates a factory configured to modify an existing profile badge event */
|
|
11
|
+
static modify(event) {
|
|
12
|
+
if (event.kind !== PROFILE_BADGES_KIND && event.kind !== LEGACY_PROFILE_BADGES_KIND)
|
|
13
|
+
throw new Error("Expected a profile badges event");
|
|
14
|
+
return new ProfileBadgesFactory((res) => res(toEventTemplate(event)));
|
|
15
|
+
}
|
|
16
|
+
/** Replaces all slots */
|
|
17
|
+
slots(slots) {
|
|
18
|
+
return this.chain(setSlots(slots));
|
|
19
|
+
}
|
|
20
|
+
/** Adds a single slot to the end */
|
|
21
|
+
addSlot(slot) {
|
|
22
|
+
return this.chain(addSlot(slot));
|
|
23
|
+
}
|
|
24
|
+
/** Inserts a slot at a specific position */
|
|
25
|
+
insertSlot(index, slot) {
|
|
26
|
+
return this.chain(insertSlot(index, slot));
|
|
27
|
+
}
|
|
28
|
+
/** Inserts a slot at the beginning */
|
|
29
|
+
prependSlot(slot) {
|
|
30
|
+
return this.chain(prependSlot(slot));
|
|
31
|
+
}
|
|
32
|
+
/** Inserts a slot at the end */
|
|
33
|
+
appendSlot(slot) {
|
|
34
|
+
return this.chain(appendSlot(slot));
|
|
35
|
+
}
|
|
36
|
+
/** Replaces the slot at a specific position */
|
|
37
|
+
setSlot(index, slot) {
|
|
38
|
+
return this.chain(setSlot(index, slot));
|
|
39
|
+
}
|
|
40
|
+
/** Removes every slot */
|
|
41
|
+
clearSlots() {
|
|
42
|
+
return this.chain(clearSlots());
|
|
43
|
+
}
|
|
44
|
+
/** Removes the slot tied to a badge definition */
|
|
45
|
+
removeByBadge(badge) {
|
|
46
|
+
return this.chain(removeSlotByBadge(badge));
|
|
47
|
+
}
|
|
48
|
+
/** Removes the slot tied to an award event */
|
|
49
|
+
removeByAward(award) {
|
|
50
|
+
return this.chain(removeSlotByAward(award));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { Emoji } from "../helpers/emoji.js";
|
|
4
|
+
export type ReactionTemplate = KnownEventTemplate<kinds.Reaction>;
|
|
5
|
+
/** A factory class for building kind 7 reaction events */
|
|
6
|
+
export declare class ReactionFactory extends EventFactory<kinds.Reaction, ReactionTemplate> {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new reaction factory for an event
|
|
9
|
+
* @param event - The event being reacted to
|
|
10
|
+
* @param emoji - The emoji to react with (default: "+")
|
|
11
|
+
* @returns A new reaction factory
|
|
12
|
+
*/
|
|
13
|
+
static create(event: NostrEvent, emoji?: string | Emoji): ReactionFactory;
|
|
14
|
+
/** Creates a "+" like reaction for an event */
|
|
15
|
+
static like(event: NostrEvent): ReactionFactory;
|
|
16
|
+
/** Creates a "-" dislike reaction for an event */
|
|
17
|
+
static dislike(event: NostrEvent): ReactionFactory;
|
|
18
|
+
/** Sets the parent event being reacted to */
|
|
19
|
+
reactTo(event: NostrEvent): this;
|
|
20
|
+
/** Sets the reaction emoji */
|
|
21
|
+
reaction(emoji: "+" | "-" | string | Emoji): this;
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, pipeFromAsyncArray, skip } from "applesauce-core/helpers";
|
|
3
|
+
import { includeEmojis } from "applesauce-core/operations/content";
|
|
4
|
+
import { setReaction, setReactionParent } from "../operations/reaction.js";
|
|
5
|
+
/** A factory class for building kind 7 reaction events */
|
|
6
|
+
export class ReactionFactory extends EventFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new reaction factory for an event
|
|
9
|
+
* @param event - The event being reacted to
|
|
10
|
+
* @param emoji - The emoji to react with (default: "+")
|
|
11
|
+
* @returns A new reaction factory
|
|
12
|
+
*/
|
|
13
|
+
static create(event, emoji = "+") {
|
|
14
|
+
return new ReactionFactory((res) => res(blankEventTemplate(kinds.Reaction))).reactTo(event).reaction(emoji);
|
|
15
|
+
}
|
|
16
|
+
/** Creates a "+" like reaction for an event */
|
|
17
|
+
static like(event) {
|
|
18
|
+
return ReactionFactory.create(event, "+");
|
|
19
|
+
}
|
|
20
|
+
/** Creates a "-" dislike reaction for an event */
|
|
21
|
+
static dislike(event) {
|
|
22
|
+
return ReactionFactory.create(event, "-");
|
|
23
|
+
}
|
|
24
|
+
/** Sets the parent event being reacted to */
|
|
25
|
+
reactTo(event) {
|
|
26
|
+
return this.chain(setReactionParent(event, undefined, undefined));
|
|
27
|
+
}
|
|
28
|
+
/** Sets the reaction emoji */
|
|
29
|
+
reaction(emoji) {
|
|
30
|
+
return this.chain(pipeFromAsyncArray([
|
|
31
|
+
// Set the event content
|
|
32
|
+
setReaction(emoji),
|
|
33
|
+
// If custom emoji, include emoji tag
|
|
34
|
+
typeof emoji !== "string" ? includeEmojis([emoji]) : skip(),
|
|
35
|
+
]));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
2
|
+
import { NIP51RelayListFactory } from "./list.js";
|
|
3
|
+
export type RelaySetTemplate = KnownEventTemplate<kinds.Relaysets>;
|
|
4
|
+
/** A factory class for building kind 30002 relay set events */
|
|
5
|
+
export declare class RelaySetFactory extends NIP51RelayListFactory<kinds.Relaysets, RelaySetTemplate> {
|
|
6
|
+
/** Creates a new relay set factory with an auto-generated identifier */
|
|
7
|
+
static create(): RelaySetFactory;
|
|
8
|
+
/** Sets the "d" identifier tag */
|
|
9
|
+
identifier(id: string): this;
|
|
10
|
+
/** Creates a new relay set factory from an existing relay set event */
|
|
11
|
+
static modify(event: NostrEvent | KnownEvent<kinds.Relaysets>): RelaySetFactory;
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isKind, kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { includeReplaceableIdentifier } from "applesauce-core/operations/index";
|
|
4
|
+
import { nanoid } from "nanoid";
|
|
5
|
+
import { NIP51RelayListFactory } from "./list.js";
|
|
6
|
+
/** A factory class for building kind 30002 relay set events */
|
|
7
|
+
export class RelaySetFactory extends NIP51RelayListFactory {
|
|
8
|
+
/** Creates a new relay set factory with an auto-generated identifier */
|
|
9
|
+
static create() {
|
|
10
|
+
return new RelaySetFactory((res) => res(blankEventTemplate(kinds.Relaysets))).identifier(nanoid());
|
|
11
|
+
}
|
|
12
|
+
/** Sets the "d" identifier tag */
|
|
13
|
+
identifier(id) {
|
|
14
|
+
return this.chain(includeReplaceableIdentifier(id));
|
|
15
|
+
}
|
|
16
|
+
/** Creates a new relay set factory from an existing relay set event */
|
|
17
|
+
static modify(event) {
|
|
18
|
+
if (!isKind(event, kinds.Relaysets))
|
|
19
|
+
throw new Error("Event is not a relay set event");
|
|
20
|
+
return new RelaySetFactory((res) => res(toEventTemplate(event)));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
2
|
+
import { NIP51RelayListFactory } from "./list.js";
|
|
3
|
+
export type SearchRelaysTemplate = KnownEventTemplate<kinds.SearchRelaysList>;
|
|
4
|
+
/** A factory class for building kind 10007 search relays list events */
|
|
5
|
+
export declare class SearchRelaysFactory extends NIP51RelayListFactory<kinds.SearchRelaysList, SearchRelaysTemplate> {
|
|
6
|
+
/** Creates a new search relays factory */
|
|
7
|
+
static create(): SearchRelaysFactory;
|
|
8
|
+
/** Creates a new search relays factory from an existing search relays event */
|
|
9
|
+
static modify(event: NostrEvent | KnownEvent<kinds.SearchRelaysList>): SearchRelaysFactory;
|
|
10
|
+
}
|