applesauce-common 5.2.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 -40
- package/dist/casts/user.js +105 -161
- 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 +0 -4
- package/dist/helpers/emoji.js +0 -16
- 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/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 +12 -11
- 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
package/dist/casts/user.d.ts
CHANGED
|
@@ -1,42 +1,24 @@
|
|
|
1
|
-
import { NostrEvent, ProfilePointer } from "applesauce-core/helpers";
|
|
2
|
-
import { Observable } from "rxjs";
|
|
3
1
|
import { ChainableObservable } from "../observable/chainable.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
inboxes: string[];
|
|
27
|
-
outboxes: string[];
|
|
28
|
-
} | undefined>;
|
|
29
|
-
get outboxes$(): ChainableObservable<string[] | undefined>;
|
|
30
|
-
get inboxes$(): ChainableObservable<string[] | undefined>;
|
|
31
|
-
get bookmarks$(): ChainableObservable<import("./bookmarks.js").BookmarksList | undefined>;
|
|
32
|
-
get favoriteRelays$(): ChainableObservable<import("./relay-lists.js").FavoriteRelays | undefined>;
|
|
33
|
-
get searchRelays$(): ChainableObservable<import("./relay-lists.js").SearchRelays | undefined>;
|
|
34
|
-
get blockedRelays$(): ChainableObservable<import("./relay-lists.js").BlockedRelays | undefined>;
|
|
35
|
-
get directMessageRelays$(): ChainableObservable<string[] | undefined>;
|
|
36
|
-
/** Get the users kind 10063 Blossom servers list */
|
|
37
|
-
get blossomServers$(): ChainableObservable<URL[] | undefined>;
|
|
38
|
-
/** Gets the users list of NIP-29 groups */
|
|
39
|
-
get groups$(): ChainableObservable<import("./groups.js").GroupsList | undefined>;
|
|
40
|
-
/** Get the latest live stream for the user */
|
|
41
|
-
get live$(): ChainableObservable<import("./stream.js").Stream | undefined>;
|
|
2
|
+
export { castUser, User } from "applesauce-core/casts";
|
|
3
|
+
declare module "applesauce-core/casts" {
|
|
4
|
+
interface User {
|
|
5
|
+
get profile$(): ChainableObservable<import("./profile.js").Profile | undefined>;
|
|
6
|
+
get contacts$(): ChainableObservable<User[]>;
|
|
7
|
+
get mutes$(): ChainableObservable<import("./mutes.js").Mutes | undefined>;
|
|
8
|
+
get mailboxes$(): ChainableObservable<{
|
|
9
|
+
inboxes: string[];
|
|
10
|
+
outboxes: string[];
|
|
11
|
+
} | undefined>;
|
|
12
|
+
get outboxes$(): ChainableObservable<string[] | undefined>;
|
|
13
|
+
get inboxes$(): ChainableObservable<string[] | undefined>;
|
|
14
|
+
get bookmarks$(): ChainableObservable<import("./bookmarks.js").BookmarksList | undefined>;
|
|
15
|
+
get favoriteEmojis$(): ChainableObservable<import("./favorite-emojis.js").FavoriteEmojis | undefined>;
|
|
16
|
+
get favoriteRelays$(): ChainableObservable<import("./relay-lists.js").FavoriteRelays | undefined>;
|
|
17
|
+
get searchRelays$(): ChainableObservable<import("./relay-lists.js").SearchRelays | undefined>;
|
|
18
|
+
get blockedRelays$(): ChainableObservable<import("./relay-lists.js").BlockedRelays | undefined>;
|
|
19
|
+
get directMessageRelays$(): ChainableObservable<string[] | undefined>;
|
|
20
|
+
get blossomServers$(): ChainableObservable<URL[] | undefined>;
|
|
21
|
+
get groups$(): ChainableObservable<import("./groups.js").GroupsList | undefined>;
|
|
22
|
+
get trustedProviders$(): ChainableObservable<import("./trusted-assertions.js").TrustedProviderList | undefined>;
|
|
23
|
+
}
|
|
42
24
|
}
|
package/dist/casts/user.js
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { castUser as coreCastUser, User } from "applesauce-core/casts";
|
|
2
|
+
import { kinds, nprofileEncode } from "applesauce-core/helpers";
|
|
3
|
+
import { combineLatest, defer, from, map, ReplaySubject, share, switchMap, tap } from "rxjs";
|
|
3
4
|
import { BLOSSOM_SERVER_LIST_KIND, getBlossomServersFromList } from "../helpers/blossom.js";
|
|
5
|
+
import { FAVORITE_EMOJI_PACKS_KIND } from "../helpers/emoji-pack.js";
|
|
4
6
|
import { GROUPS_LIST_KIND } from "../helpers/groups.js";
|
|
5
7
|
import { getRelaysFromList } from "../helpers/lists.js";
|
|
6
8
|
import { FAVORITE_RELAYS_KIND } from "../helpers/relay-list.js";
|
|
9
|
+
import { TRUSTED_PROVIDER_LIST_KIND } from "../helpers/trusted-assertions.js";
|
|
7
10
|
import { castEventStream } from "../observable/cast-stream.js";
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
if (isEvent(user)) {
|
|
11
|
-
return castUser(user.pubkey, store);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
const pubkey = typeof user === "string" ? user : user.pubkey;
|
|
15
|
-
// Skip creating a new instance if this pubkey has already been cast
|
|
16
|
-
const existing = User.cache.get(pubkey);
|
|
17
|
-
if (existing)
|
|
18
|
-
return existing;
|
|
19
|
-
// Create a new instance and cache it
|
|
20
|
-
const newUser = new User(pubkey, store);
|
|
21
|
-
User.cache.set(pubkey, newUser);
|
|
22
|
-
return newUser;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
11
|
+
// Re-export castUser and User from core so consumers don't need to change imports
|
|
12
|
+
export { castUser, User } from "applesauce-core/casts";
|
|
25
13
|
function memoize() {
|
|
26
14
|
return share({
|
|
27
15
|
connector: () => new ReplaySubject(1),
|
|
@@ -29,146 +17,102 @@ function memoize() {
|
|
|
29
17
|
resetOnComplete: false,
|
|
30
18
|
});
|
|
31
19
|
}
|
|
32
|
-
// IMPORTANT: this
|
|
33
|
-
const Circular =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
static cache = new Map();
|
|
48
|
-
constructor(user, store) {
|
|
49
|
-
if (typeof user === "string" && !isHexKey(user))
|
|
50
|
-
throw new Error("Invalid pubkey for user");
|
|
51
|
-
const pubkey = typeof user === "string" ? user : user.pubkey;
|
|
52
|
-
this.#store = store;
|
|
53
|
-
this.pubkey = pubkey;
|
|
54
|
-
}
|
|
55
|
-
/** A cache of observable references */
|
|
56
|
-
#refs = {};
|
|
57
|
-
/** Internal method for creating a reference */
|
|
58
|
-
$$ref(key, builder) {
|
|
59
|
-
// Return cached observable
|
|
60
|
-
if (this.#refs[key])
|
|
61
|
-
return this.#refs[key];
|
|
62
|
-
// Build a new observable and cache it
|
|
63
|
-
const observable = chainable(builder(this.#store));
|
|
64
|
-
this.#refs[key] = observable;
|
|
65
|
-
return observable;
|
|
66
|
-
}
|
|
67
|
-
// Public getters
|
|
68
|
-
get npub() {
|
|
69
|
-
return npubEncode(this.pubkey);
|
|
70
|
-
}
|
|
71
|
-
get pointer() {
|
|
72
|
-
return {
|
|
73
|
-
pubkey: this.pubkey,
|
|
74
|
-
relays: this.#outboxes?.slice(0, 3) ?? [],
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
get nprofile() {
|
|
78
|
-
return nprofileEncode(this.pointer);
|
|
79
|
-
}
|
|
80
|
-
// Request methods
|
|
81
|
-
replaceable(kind, identifier, relays) {
|
|
82
|
-
return chainable(this.#store.replaceable({ kind, pubkey: this.pubkey, identifier, relays }));
|
|
83
|
-
}
|
|
84
|
-
addressable(kind, identifier, relays) {
|
|
85
|
-
return chainable(this.#store.addressable({ kind, pubkey: this.pubkey, identifier, relays }));
|
|
86
|
-
}
|
|
87
|
-
// Observable interfaces
|
|
88
|
-
get profile$() {
|
|
89
|
-
return this.$$ref("profile$", (store) => Circular.Profile.pipe(switchMap(({ Profile }) => store.replaceable({ kind: kinds.Metadata, pubkey: this.pubkey }).pipe(castEventStream(Profile, store)))));
|
|
90
|
-
}
|
|
91
|
-
get contacts$() {
|
|
92
|
-
return this.$$ref("contacts$", (store) => this.outboxes$.pipe(
|
|
93
|
-
// Fetch the contacts from the outboxes
|
|
94
|
-
switchMap((outboxes) => store.contacts({ pubkey: this.pubkey, relays: outboxes })),
|
|
95
|
-
// Cast to users
|
|
96
|
-
map((arr) => arr.map((p) => castUser(p, this.#store)))));
|
|
97
|
-
}
|
|
98
|
-
get mutes$() {
|
|
99
|
-
return this.$$ref("mutes$", (store) => combineLatest([Circular.Mutes, this.outboxes$]).pipe(
|
|
100
|
-
// Create the mute list event with the outboxes
|
|
101
|
-
switchMap(([{ Mutes }, outboxes]) => store
|
|
102
|
-
.event({ kind: kinds.Mutelist, pubkey: this.pubkey, relays: outboxes })
|
|
103
|
-
.pipe(castEventStream(Mutes, store)))));
|
|
104
|
-
}
|
|
105
|
-
get mailboxes$() {
|
|
106
|
-
return this.$$ref("mailboxes$", (store) => store.mailboxes({ pubkey: this.pubkey }).pipe(
|
|
107
|
-
// Cache the outboxes for creating a profile pointer relay hints
|
|
108
|
-
tap((mailboxes) => (this.#outboxes = mailboxes?.outboxes))));
|
|
109
|
-
}
|
|
110
|
-
get outboxes$() {
|
|
111
|
-
return this.mailboxes$.outboxes;
|
|
112
|
-
}
|
|
113
|
-
get inboxes$() {
|
|
114
|
-
return this.mailboxes$.inboxes;
|
|
115
|
-
}
|
|
116
|
-
get bookmarks$() {
|
|
117
|
-
return this.$$ref("bookmarks$", (store) => combineLatest([Circular.Bookmarks, this.outboxes$]).pipe(switchMap(([{ BookmarksList }, outboxes]) =>
|
|
118
|
-
// Fetch the bookmarks list event from the outboxes
|
|
119
|
-
store
|
|
120
|
-
.replaceable({ kind: kinds.BookmarkList, pubkey: this.pubkey, relays: outboxes })
|
|
121
|
-
.pipe(castEventStream(BookmarksList, store)))));
|
|
122
|
-
}
|
|
123
|
-
get favoriteRelays$() {
|
|
124
|
-
return this.$$ref("favoriteRelays$", (store) => combineLatest([Circular.RelayLists, this.outboxes$]).pipe(
|
|
125
|
-
// Fetch the favorite relays list event from the outboxes
|
|
126
|
-
switchMap(([{ FavoriteRelays }, outboxes]) => store
|
|
127
|
-
.replaceable({ kind: FAVORITE_RELAYS_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
128
|
-
.pipe(castEventStream(FavoriteRelays, store)))));
|
|
129
|
-
}
|
|
130
|
-
get searchRelays$() {
|
|
131
|
-
return this.$$ref("searchRelays$", (store) => combineLatest([Circular.RelayLists, this.outboxes$]).pipe(
|
|
132
|
-
// Fetch the search relays list event from the outboxes
|
|
133
|
-
switchMap(([{ SearchRelays }, outboxes]) => store
|
|
134
|
-
.replaceable({ kind: kinds.SearchRelaysList, pubkey: this.pubkey, relays: outboxes })
|
|
135
|
-
.pipe(castEventStream(SearchRelays, store)))));
|
|
136
|
-
}
|
|
137
|
-
get blockedRelays$() {
|
|
138
|
-
return this.$$ref("blockedRelays$", (store) => combineLatest([Circular.RelayLists, this.outboxes$]).pipe(
|
|
139
|
-
// Fetch the blocked relays list event from the outboxes
|
|
140
|
-
switchMap(([{ BlockedRelays }, outboxes]) => store
|
|
141
|
-
.replaceable({ kind: kinds.BlockedRelaysList, pubkey: this.pubkey, relays: outboxes })
|
|
142
|
-
.pipe(castEventStream(BlockedRelays, store)))));
|
|
143
|
-
}
|
|
144
|
-
get directMessageRelays$() {
|
|
145
|
-
return this.$$ref("dmRelays$", (store) => this.outboxes$.pipe(
|
|
146
|
-
// Fetch the DM relays list event from the outboxes
|
|
147
|
-
switchMap((outboxes) => store
|
|
148
|
-
.replaceable({ kind: kinds.DirectMessageRelaysList, pubkey: this.pubkey, relays: outboxes })
|
|
149
|
-
.pipe(map((event) => event && getRelaysFromList(event))))));
|
|
150
|
-
}
|
|
151
|
-
/** Get the users kind 10063 Blossom servers list */
|
|
152
|
-
get blossomServers$() {
|
|
153
|
-
return this.$$ref("blossomServers$", (store) => this.outboxes$.pipe(
|
|
154
|
-
// Fetch the blossom servers list event from the outboxes
|
|
155
|
-
switchMap((outboxes) => store
|
|
156
|
-
.replaceable({ kind: BLOSSOM_SERVER_LIST_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
157
|
-
.pipe(map((event) => event && getBlossomServersFromList(event))))));
|
|
158
|
-
}
|
|
159
|
-
/** Gets the users list of NIP-29 groups */
|
|
160
|
-
get groups$() {
|
|
161
|
-
return this.$$ref("groups$", (store) => combineLatest([Circular.Groups, this.outboxes$]).pipe(switchMap(([{ GroupsList }, outboxes]) => store
|
|
162
|
-
.replaceable({ kind: GROUPS_LIST_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
163
|
-
.pipe(castEventStream(GroupsList, store)))));
|
|
164
|
-
}
|
|
165
|
-
/** Get the latest live stream for the user */
|
|
166
|
-
get live$() {
|
|
167
|
-
return this.$$ref("live$", (store) => defer(() => import("./stream.js").then((m) => m.Stream)).pipe(switchMap((Stream) => store
|
|
168
|
-
.timeline([
|
|
169
|
-
{ kinds: [kinds.LiveEvent], "#p": [this.pubkey] },
|
|
170
|
-
{ kinds: [kinds.LiveEvent], authors: [this.pubkey] },
|
|
171
|
-
])
|
|
172
|
-
.pipe(map((events) => events[0]), castEventStream(Stream, store)))));
|
|
173
|
-
}
|
|
20
|
+
// IMPORTANT: this module MUST use async import() to import the other classes so that we do not get circular dependency errors
|
|
21
|
+
const Circular = defer(() => from(import("./_circular-import.js"))).pipe(memoize());
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Outbox cache — WeakMap so it's GC-safe and doesn't pollute User instances
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
const outboxCache = new WeakMap();
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Prototype augmentation — attach Nostr-specific observable getters to User
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
function defineGetter(name, fn) {
|
|
30
|
+
Object.defineProperty(User.prototype, name, {
|
|
31
|
+
get: fn,
|
|
32
|
+
configurable: true,
|
|
33
|
+
enumerable: false,
|
|
34
|
+
});
|
|
174
35
|
}
|
|
36
|
+
// Override pointer to include relay hints from outboxes
|
|
37
|
+
Object.defineProperty(User.prototype, "pointer", {
|
|
38
|
+
get() {
|
|
39
|
+
return { pubkey: this.pubkey, relays: outboxCache.get(this)?.slice(0, 3) ?? [] };
|
|
40
|
+
},
|
|
41
|
+
configurable: true,
|
|
42
|
+
enumerable: false,
|
|
43
|
+
});
|
|
44
|
+
// Override nprofile to use the enriched pointer
|
|
45
|
+
Object.defineProperty(User.prototype, "nprofile", {
|
|
46
|
+
get() {
|
|
47
|
+
return nprofileEncode(this.pointer);
|
|
48
|
+
},
|
|
49
|
+
configurable: true,
|
|
50
|
+
enumerable: false,
|
|
51
|
+
});
|
|
52
|
+
defineGetter("profile$", function () {
|
|
53
|
+
return this.$$ref("profile$", (store) => Circular.pipe(switchMap(({ Profile }) => store.replaceable({ kind: kinds.Metadata, pubkey: this.pubkey }).pipe(castEventStream(Profile, store)))));
|
|
54
|
+
});
|
|
55
|
+
defineGetter("contacts$", function () {
|
|
56
|
+
return this.$$ref("contacts$", (store) => this.outboxes$.pipe(switchMap((outboxes) => store.contacts({ pubkey: this.pubkey, relays: outboxes })), map((arr) => arr.map((p) => coreCastUser(p, store)))));
|
|
57
|
+
});
|
|
58
|
+
defineGetter("mutes$", function () {
|
|
59
|
+
return this.$$ref("mutes$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ Mutes }, outboxes]) => store
|
|
60
|
+
.event({ kind: kinds.Mutelist, pubkey: this.pubkey, relays: outboxes })
|
|
61
|
+
.pipe(castEventStream(Mutes, store)))));
|
|
62
|
+
});
|
|
63
|
+
defineGetter("mailboxes$", function () {
|
|
64
|
+
return this.$$ref("mailboxes$", (store) => store
|
|
65
|
+
.mailboxes({ pubkey: this.pubkey })
|
|
66
|
+
.pipe(tap((mailboxes) => outboxCache.set(this, mailboxes?.outboxes))));
|
|
67
|
+
});
|
|
68
|
+
defineGetter("outboxes$", function () {
|
|
69
|
+
return this.mailboxes$.outboxes;
|
|
70
|
+
});
|
|
71
|
+
defineGetter("inboxes$", function () {
|
|
72
|
+
return this.mailboxes$.inboxes;
|
|
73
|
+
});
|
|
74
|
+
defineGetter("bookmarks$", function () {
|
|
75
|
+
return this.$$ref("bookmarks$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ BookmarksList }, outboxes]) => store
|
|
76
|
+
.replaceable({ kind: kinds.BookmarkList, pubkey: this.pubkey, relays: outboxes })
|
|
77
|
+
.pipe(castEventStream(BookmarksList, store)))));
|
|
78
|
+
});
|
|
79
|
+
defineGetter("favoriteRelays$", function () {
|
|
80
|
+
return this.$$ref("favoriteRelays$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ FavoriteRelays }, outboxes]) => store
|
|
81
|
+
.replaceable({ kind: FAVORITE_RELAYS_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
82
|
+
.pipe(castEventStream(FavoriteRelays, store)))));
|
|
83
|
+
});
|
|
84
|
+
defineGetter("favoriteEmojis$", function () {
|
|
85
|
+
return this.$$ref("favoriteEmojis$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ FavoriteEmojis }, outboxes]) => store
|
|
86
|
+
.replaceable({ kind: FAVORITE_EMOJI_PACKS_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
87
|
+
.pipe(castEventStream(FavoriteEmojis, store)))));
|
|
88
|
+
});
|
|
89
|
+
defineGetter("searchRelays$", function () {
|
|
90
|
+
return this.$$ref("searchRelays$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ SearchRelays }, outboxes]) => store
|
|
91
|
+
.replaceable({ kind: kinds.SearchRelaysList, pubkey: this.pubkey, relays: outboxes })
|
|
92
|
+
.pipe(castEventStream(SearchRelays, store)))));
|
|
93
|
+
});
|
|
94
|
+
defineGetter("blockedRelays$", function () {
|
|
95
|
+
return this.$$ref("blockedRelays$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ BlockedRelays }, outboxes]) => store
|
|
96
|
+
.replaceable({ kind: kinds.BlockedRelaysList, pubkey: this.pubkey, relays: outboxes })
|
|
97
|
+
.pipe(castEventStream(BlockedRelays, store)))));
|
|
98
|
+
});
|
|
99
|
+
defineGetter("directMessageRelays$", function () {
|
|
100
|
+
return this.$$ref("dmRelays$", (store) => this.outboxes$.pipe(switchMap((outboxes) => store
|
|
101
|
+
.replaceable({ kind: kinds.DirectMessageRelaysList, pubkey: this.pubkey, relays: outboxes })
|
|
102
|
+
.pipe(map((event) => event && getRelaysFromList(event))))));
|
|
103
|
+
});
|
|
104
|
+
defineGetter("blossomServers$", function () {
|
|
105
|
+
return this.$$ref("blossomServers$", (store) => this.outboxes$.pipe(switchMap((outboxes) => store
|
|
106
|
+
.replaceable({ kind: BLOSSOM_SERVER_LIST_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
107
|
+
.pipe(map((event) => event && getBlossomServersFromList(event))))));
|
|
108
|
+
});
|
|
109
|
+
defineGetter("groups$", function () {
|
|
110
|
+
return this.$$ref("groups$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ GroupsList }, outboxes]) => store
|
|
111
|
+
.replaceable({ kind: GROUPS_LIST_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
112
|
+
.pipe(castEventStream(GroupsList, store)))));
|
|
113
|
+
});
|
|
114
|
+
defineGetter("trustedProviders$", function () {
|
|
115
|
+
return this.$$ref("trustedProviders$", (store) => combineLatest([Circular, this.outboxes$]).pipe(switchMap(([{ TrustedProviderList }, outboxes]) => store
|
|
116
|
+
.replaceable({ kind: TRUSTED_PROVIDER_LIST_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
117
|
+
.pipe(castEventStream(TrustedProviderList, store)))));
|
|
118
|
+
});
|
package/dist/casts/zap-goal.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class ZapGoal extends EventCast<ZapGoalEvent> {
|
|
|
12
12
|
get beneficiaries(): import("../helpers/zap.js").ZapSplit[] | undefined;
|
|
13
13
|
get description(): string;
|
|
14
14
|
/** An observable of all zaps contributing to this goal */
|
|
15
|
-
get zaps$(): import("
|
|
15
|
+
get zaps$(): import("applesauce-core").ChainableObservable<import("applesauce-core/helpers").KnownEvent<9735>[]>;
|
|
16
16
|
/** An observable of the goal progress */
|
|
17
|
-
get progress$(): import("
|
|
17
|
+
get progress$(): import("applesauce-core").ChainableObservable<ZapGoalProgress | undefined>;
|
|
18
18
|
}
|
package/dist/casts/zap.d.ts
CHANGED
|
@@ -4,14 +4,14 @@ import { CastRefEventStore, EventCast } from "./cast.js";
|
|
|
4
4
|
/** Cast a kind 9735 event to a Zap */
|
|
5
5
|
export declare class Zap extends EventCast<ZapEvent> {
|
|
6
6
|
constructor(event: NostrEvent, store: CastRefEventStore);
|
|
7
|
-
get sender(): import("
|
|
8
|
-
get recipient(): import("
|
|
7
|
+
get sender(): import("applesauce-core/casts").User;
|
|
8
|
+
get recipient(): import("applesauce-core/casts").User;
|
|
9
9
|
get payment(): import("../helpers/bolt11.js").ParsedInvoice;
|
|
10
10
|
get amount(): number;
|
|
11
11
|
get preimage(): string | undefined;
|
|
12
|
-
get request():
|
|
12
|
+
get request(): import("../helpers/zap.js").ZapRequestEvent;
|
|
13
13
|
get addressPointer(): import("nostr-tools/nip19").AddressPointer | null;
|
|
14
14
|
get eventPointer(): import("nostr-tools/nip19").EventPointer | null;
|
|
15
15
|
/** An observable of the zapped event */
|
|
16
|
-
get event$(): import("
|
|
16
|
+
get event$(): import("applesauce-core").ChainableObservable<NostrEvent | undefined>;
|
|
17
17
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { EncryptionMethod } from "applesauce-core/helpers/encrypted-content";
|
|
4
|
+
import { APP_DATA_KIND } from "../helpers/app-data.js";
|
|
5
|
+
export type AppDataTemplate = KnownEventTemplate<typeof APP_DATA_KIND>;
|
|
6
|
+
export declare class AppDataFactory<Data extends unknown = unknown> extends EventFactory<typeof APP_DATA_KIND, AppDataTemplate> {
|
|
7
|
+
/** Creates a new app data factory */
|
|
8
|
+
static create<Data>(identifier: string, data: Data, encryption?: boolean | EncryptionMethod): AppDataFactory<Data>;
|
|
9
|
+
/** Creates a new app data factory from an existing app data event */
|
|
10
|
+
static modify<Data = unknown>(event: NostrEvent | KnownEvent<typeof APP_DATA_KIND>): AppDataFactory<Data>;
|
|
11
|
+
/** Sets the data for the app data */
|
|
12
|
+
data(data: Data, encryption?: boolean | EncryptionMethod): this;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isKind, unixNow } from "applesauce-core/helpers";
|
|
3
|
+
import { APP_DATA_KIND } from "../helpers/app-data.js";
|
|
4
|
+
import { setContent } from "../operations/app-data.js";
|
|
5
|
+
export class AppDataFactory extends EventFactory {
|
|
6
|
+
/** Creates a new app data factory */
|
|
7
|
+
static create(identifier, data, encryption) {
|
|
8
|
+
return new AppDataFactory((res) => res({ kind: APP_DATA_KIND, content: "", created_at: unixNow(), tags: [["d", identifier]] })).data(data, encryption);
|
|
9
|
+
}
|
|
10
|
+
/** Creates a new app data factory from an existing app data event */
|
|
11
|
+
static modify(event) {
|
|
12
|
+
if (!isKind(event, APP_DATA_KIND))
|
|
13
|
+
throw new Error("Event is not a app data event");
|
|
14
|
+
return new AppDataFactory((res) => res(toEventTemplate(event)));
|
|
15
|
+
}
|
|
16
|
+
/** Sets the data for the app data */
|
|
17
|
+
data(data, encryption) {
|
|
18
|
+
return this.chain(setContent(data, encryption));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
4
|
+
import type { ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
5
|
+
import { addRecipient, setBadgePointer } from "../operations/badge-award.js";
|
|
6
|
+
export type BadgeAwardTemplate = KnownEventTemplate<typeof kinds.BadgeAward>;
|
|
7
|
+
/** Factory for badge award events (kind 8) */
|
|
8
|
+
export declare class BadgeAwardFactory extends EventFactory<typeof kinds.BadgeAward, BadgeAwardTemplate> {
|
|
9
|
+
/** Creates a badge award factory */
|
|
10
|
+
static create(): BadgeAwardFactory;
|
|
11
|
+
/** Creates a factory configured to modify an existing award */
|
|
12
|
+
static modify(event: NostrEvent): BadgeAwardFactory;
|
|
13
|
+
/** Sets the badge definition pointer */
|
|
14
|
+
badge(address: Parameters<typeof setBadgePointer>[0], relayHint?: Parameters<typeof setBadgePointer>[1]): this;
|
|
15
|
+
/** Removes the badge definition pointer */
|
|
16
|
+
clearBadge(): this;
|
|
17
|
+
/** Replaces recipients with the provided list */
|
|
18
|
+
recipients(recipients: Array<string | ProfilePointer>): this;
|
|
19
|
+
/** Adds a recipient */
|
|
20
|
+
addRecipient(recipient: string | ProfilePointer, relayHint?: Parameters<typeof addRecipient>[1]): this;
|
|
21
|
+
/** Removes a specific recipient */
|
|
22
|
+
removeRecipient(recipient: string | ProfilePointer): this;
|
|
23
|
+
/** Clears all recipients */
|
|
24
|
+
clearRecipients(): this;
|
|
25
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
3
|
+
import { addRecipient, clearBadgePointer, clearRecipients, removeRecipient, setBadgePointer, setRecipients, } from "../operations/badge-award.js";
|
|
4
|
+
/** Factory for badge award events (kind 8) */
|
|
5
|
+
export class BadgeAwardFactory extends EventFactory {
|
|
6
|
+
/** Creates a badge award factory */
|
|
7
|
+
static create() {
|
|
8
|
+
return new BadgeAwardFactory((res) => res(blankEventTemplate(kinds.BadgeAward)));
|
|
9
|
+
}
|
|
10
|
+
/** Creates a factory configured to modify an existing award */
|
|
11
|
+
static modify(event) {
|
|
12
|
+
if (event.kind !== kinds.BadgeAward)
|
|
13
|
+
throw new Error("Expected a badge award event");
|
|
14
|
+
return new BadgeAwardFactory((res) => res(toEventTemplate(event)));
|
|
15
|
+
}
|
|
16
|
+
/** Sets the badge definition pointer */
|
|
17
|
+
badge(address, relayHint) {
|
|
18
|
+
return this.chain(setBadgePointer(address, relayHint));
|
|
19
|
+
}
|
|
20
|
+
/** Removes the badge definition pointer */
|
|
21
|
+
clearBadge() {
|
|
22
|
+
return this.chain(clearBadgePointer());
|
|
23
|
+
}
|
|
24
|
+
/** Replaces recipients with the provided list */
|
|
25
|
+
recipients(recipients) {
|
|
26
|
+
return this.chain(setRecipients(recipients));
|
|
27
|
+
}
|
|
28
|
+
/** Adds a recipient */
|
|
29
|
+
addRecipient(recipient, relayHint) {
|
|
30
|
+
const hint = relayHint ?? (typeof recipient === "string" ? undefined : recipient.relays?.[0]);
|
|
31
|
+
return this.chain(addRecipient(recipient, hint));
|
|
32
|
+
}
|
|
33
|
+
/** Removes a specific recipient */
|
|
34
|
+
removeRecipient(recipient) {
|
|
35
|
+
return this.chain(removeRecipient(recipient));
|
|
36
|
+
}
|
|
37
|
+
/** Clears all recipients */
|
|
38
|
+
clearRecipients() {
|
|
39
|
+
return this.chain(clearRecipients());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
4
|
+
type ImageDimensions = {
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
};
|
|
8
|
+
export type BadgeTemplate = KnownEventTemplate<typeof kinds.BadgeDefinition>;
|
|
9
|
+
/** Factory for NIP-58 badge definition events (kind 30009) */
|
|
10
|
+
export declare class BadgeFactory extends EventFactory<typeof kinds.BadgeDefinition, BadgeTemplate> {
|
|
11
|
+
/** Creates a fresh badge definition factory */
|
|
12
|
+
static create(): BadgeFactory;
|
|
13
|
+
/** Creates a factory configured to modify an existing badge event */
|
|
14
|
+
static modify(event: NostrEvent): BadgeFactory;
|
|
15
|
+
/** Sets the badge identifier */
|
|
16
|
+
identifier(value: string): this;
|
|
17
|
+
/** Sets or clears the badge name */
|
|
18
|
+
name(value: string | null): this;
|
|
19
|
+
/** Sets or clears the badge description */
|
|
20
|
+
description(value: string | null): this;
|
|
21
|
+
/** Sets the hero image metadata */
|
|
22
|
+
image(url: string, dimensions?: ImageDimensions): this;
|
|
23
|
+
/** Removes the hero image tag */
|
|
24
|
+
clearImage(): this;
|
|
25
|
+
/** Adds or replaces a thumbnail entry */
|
|
26
|
+
thumbnail(url: string, dimensions?: ImageDimensions): this;
|
|
27
|
+
/** Removes a thumbnail for the provided URL */
|
|
28
|
+
removeThumbnail(url: string): this;
|
|
29
|
+
/** Clears every thumbnail tag */
|
|
30
|
+
clearThumbnails(): this;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
3
|
+
import { addThumbnail, clearHeroImage, clearThumbnails, removeThumbnail, setDescription, setHeroImage, setIdentifier, setName, } from "../operations/badge.js";
|
|
4
|
+
/** Factory for NIP-58 badge definition events (kind 30009) */
|
|
5
|
+
export class BadgeFactory extends EventFactory {
|
|
6
|
+
/** Creates a fresh badge definition factory */
|
|
7
|
+
static create() {
|
|
8
|
+
return new BadgeFactory((res) => res(blankEventTemplate(kinds.BadgeDefinition)));
|
|
9
|
+
}
|
|
10
|
+
/** Creates a factory configured to modify an existing badge event */
|
|
11
|
+
static modify(event) {
|
|
12
|
+
if (event.kind !== kinds.BadgeDefinition)
|
|
13
|
+
throw new Error("Expected a badge definition event");
|
|
14
|
+
return new BadgeFactory((res) => res(toEventTemplate(event)));
|
|
15
|
+
}
|
|
16
|
+
/** Sets the badge identifier */
|
|
17
|
+
identifier(value) {
|
|
18
|
+
return this.chain(setIdentifier(value));
|
|
19
|
+
}
|
|
20
|
+
/** Sets or clears the badge name */
|
|
21
|
+
name(value) {
|
|
22
|
+
return this.chain(setName(value));
|
|
23
|
+
}
|
|
24
|
+
/** Sets or clears the badge description */
|
|
25
|
+
description(value) {
|
|
26
|
+
return this.chain(setDescription(value));
|
|
27
|
+
}
|
|
28
|
+
/** Sets the hero image metadata */
|
|
29
|
+
image(url, dimensions) {
|
|
30
|
+
const { width, height } = dimensions ?? {};
|
|
31
|
+
return this.chain(setHeroImage(url, { width, height }));
|
|
32
|
+
}
|
|
33
|
+
/** Removes the hero image tag */
|
|
34
|
+
clearImage() {
|
|
35
|
+
return this.chain(clearHeroImage());
|
|
36
|
+
}
|
|
37
|
+
/** Adds or replaces a thumbnail entry */
|
|
38
|
+
thumbnail(url, dimensions) {
|
|
39
|
+
const { width, height } = dimensions ?? {};
|
|
40
|
+
return this.chain(addThumbnail(url, { width, height }));
|
|
41
|
+
}
|
|
42
|
+
/** Removes a thumbnail for the provided URL */
|
|
43
|
+
removeThumbnail(url) {
|
|
44
|
+
return this.chain(removeThumbnail(url));
|
|
45
|
+
}
|
|
46
|
+
/** Clears every thumbnail tag */
|
|
47
|
+
clearThumbnails() {
|
|
48
|
+
return this.chain(clearThumbnails());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
2
|
+
import { NIP51RelayListFactory } from "./list.js";
|
|
3
|
+
export type BlockedRelaysTemplate = KnownEventTemplate<kinds.BlockedRelaysList>;
|
|
4
|
+
/** A factory class for building kind 10006 blocked relays list events */
|
|
5
|
+
export declare class BlockedRelaysFactory extends NIP51RelayListFactory<kinds.BlockedRelaysList, BlockedRelaysTemplate> {
|
|
6
|
+
/** Creates a new blocked relays factory */
|
|
7
|
+
static create(): BlockedRelaysFactory;
|
|
8
|
+
/** Creates a new blocked relays factory from an existing blocked relays event */
|
|
9
|
+
static modify(event: NostrEvent | KnownEvent<kinds.BlockedRelaysList>): BlockedRelaysFactory;
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { isKind, kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { NIP51RelayListFactory } from "./list.js";
|
|
4
|
+
/** A factory class for building kind 10006 blocked relays list events */
|
|
5
|
+
export class BlockedRelaysFactory extends NIP51RelayListFactory {
|
|
6
|
+
/** Creates a new blocked relays factory */
|
|
7
|
+
static create() {
|
|
8
|
+
return new BlockedRelaysFactory((res) => res(blankEventTemplate(kinds.BlockedRelaysList)));
|
|
9
|
+
}
|
|
10
|
+
/** Creates a new blocked relays factory from an existing blocked relays event */
|
|
11
|
+
static modify(event) {
|
|
12
|
+
if (!isKind(event, kinds.BlockedRelaysList))
|
|
13
|
+
throw new Error("Event is not a blocked relays event");
|
|
14
|
+
return new BlockedRelaysFactory((res) => res(toEventTemplate(event)));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { BLOSSOM_SERVER_LIST_KIND } from "../helpers/blossom.js";
|
|
4
|
+
export type BlossomServerListTemplate = KnownEventTemplate<typeof BLOSSOM_SERVER_LIST_KIND>;
|
|
5
|
+
/** A factory class for building kind 10063 Blossom server list events */
|
|
6
|
+
export declare class BlossomServerListFactory extends EventFactory<typeof BLOSSOM_SERVER_LIST_KIND, BlossomServerListTemplate> {
|
|
7
|
+
/** Creates a new Blossom server list factory */
|
|
8
|
+
static create(): BlossomServerListFactory;
|
|
9
|
+
/** Creates a new Blossom server list factory from an existing Blossom server list event */
|
|
10
|
+
static modify(event: NostrEvent | KnownEvent<typeof BLOSSOM_SERVER_LIST_KIND>): BlossomServerListFactory;
|
|
11
|
+
/** Adds a Blossom server to the list */
|
|
12
|
+
addServer(url: string | URL): this;
|
|
13
|
+
/** Removes a Blossom server from the list */
|
|
14
|
+
removeServer(url: string | URL): this;
|
|
15
|
+
/** Moves a server to the top of the list, making it the default */
|
|
16
|
+
setDefaultServer(url: string | URL): this;
|
|
17
|
+
/** Replaces all servers with the given list */
|
|
18
|
+
servers(urls: (string | URL)[]): this;
|
|
19
|
+
}
|