applesauce-common 6.0.1 → 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.
- package/dist/casts/_circular-import.d.ts +2 -0
- package/dist/casts/_circular-import.js +2 -0
- package/dist/casts/git-grasp-list.d.ts +8 -0
- package/dist/casts/git-grasp-list.js +13 -0
- package/dist/casts/git-lists.d.ts +42 -0
- package/dist/casts/git-lists.js +94 -0
- package/dist/casts/git-repository.d.ts +29 -0
- package/dist/casts/git-repository.js +68 -0
- package/dist/casts/index.d.ts +3 -0
- package/dist/casts/index.js +3 -0
- package/dist/casts/reaction.d.ts +3 -1
- package/dist/casts/reaction.js +6 -2
- package/dist/casts/relay-lists.d.ts +6 -2
- package/dist/casts/relay-lists.js +11 -2
- package/dist/casts/user.d.ts +4 -0
- package/dist/casts/user.js +23 -1
- package/dist/factories/calendar-event.d.ts +0 -5
- package/dist/factories/calendar-event.js +0 -9
- package/dist/factories/calendar-rsvp.d.ts +1 -0
- package/dist/factories/calendar-rsvp.js +1 -0
- package/dist/factories/code-snippet.d.ts +0 -2
- package/dist/factories/code-snippet.js +0 -5
- package/dist/factories/comment.d.ts +0 -2
- package/dist/factories/comment.js +5 -8
- package/dist/factories/favorite-git-repos.d.ts +17 -0
- package/dist/factories/favorite-git-repos.js +43 -0
- package/dist/factories/gift-wrap.js +2 -2
- package/dist/factories/git-authors.d.ts +17 -0
- package/dist/factories/git-authors.js +24 -0
- package/dist/factories/git-grasp-list.d.ts +14 -0
- package/dist/factories/git-grasp-list.js +25 -0
- package/dist/factories/git-repository.d.ts +51 -0
- package/dist/factories/git-repository.js +96 -0
- package/dist/factories/group.d.ts +5 -7
- package/dist/factories/group.js +8 -14
- package/dist/factories/highlight.d.ts +1 -10
- package/dist/factories/highlight.js +2 -12
- package/dist/factories/index.d.ts +5 -4
- package/dist/factories/index.js +5 -4
- package/dist/factories/legacy-message.d.ts +0 -1
- package/dist/factories/list.d.ts +0 -10
- package/dist/factories/list.js +0 -21
- package/dist/factories/picture-post.d.ts +3 -4
- package/dist/factories/picture-post.js +3 -7
- package/dist/factories/poll-response.d.ts +0 -2
- package/dist/factories/poll-response.js +0 -5
- package/dist/factories/poll.d.ts +9 -6
- package/dist/factories/poll.js +12 -9
- package/dist/factories/relay-lists.d.ts +46 -0
- package/dist/factories/relay-lists.js +93 -0
- package/dist/factories/relay-set.d.ts +1 -1
- package/dist/factories/relay-set.js +1 -1
- package/dist/factories/share.d.ts +0 -7
- package/dist/factories/share.js +0 -11
- package/dist/factories/stream-chat-message.d.ts +0 -3
- package/dist/factories/stream-chat-message.js +0 -5
- package/dist/factories/torrent.d.ts +0 -2
- package/dist/factories/torrent.js +0 -5
- package/dist/factories/zap-goal.d.ts +0 -2
- package/dist/factories/zap-goal.js +0 -5
- package/dist/helpers/git-grasp-list.d.ts +8 -0
- package/dist/helpers/git-grasp-list.js +15 -0
- package/dist/helpers/git-lists.d.ts +20 -0
- package/dist/helpers/git-lists.js +28 -0
- package/dist/helpers/git-repository.d.ts +39 -0
- package/dist/helpers/git-repository.js +104 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +3 -0
- package/dist/helpers/relay-list.d.ts +5 -0
- package/dist/helpers/relay-list.js +8 -0
- package/dist/models/thread.js +14 -11
- package/dist/observable/cast-stream.d.ts +1 -8
- package/dist/observable/cast-stream.js +2 -29
- package/dist/observable/chainable.d.ts +1 -1
- package/dist/observable/chainable.js +1 -1
- package/dist/operations/git-grasp-list.d.ts +7 -0
- package/dist/operations/git-grasp-list.js +18 -0
- package/dist/operations/git-repository.d.ts +45 -0
- package/dist/operations/git-repository.js +160 -0
- package/dist/operations/hashtags.d.ts +2 -0
- package/dist/operations/hashtags.js +7 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/index.js +2 -0
- package/dist/operations/poll.d.ts +3 -2
- package/dist/operations/poll.js +4 -3
- package/package.json +4 -4
- package/dist/factories/blocked-relays.d.ts +0 -10
- package/dist/factories/blocked-relays.js +0 -16
- package/dist/factories/dm-relays.d.ts +0 -10
- package/dist/factories/dm-relays.js +0 -16
- package/dist/factories/favorite-relays.d.ts +0 -16
- package/dist/factories/favorite-relays.js +0 -31
- package/dist/factories/search-relays.d.ts +0 -10
- package/dist/factories/search-relays.js +0 -16
package/dist/models/thread.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventModels } from "applesauce-core/event-store";
|
|
2
2
|
import { buildCommonEventRelationFilters } from "applesauce-core/helpers";
|
|
3
3
|
import { getEventUID, kinds } from "applesauce-core/helpers/event";
|
|
4
|
-
import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer,
|
|
4
|
+
import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer, isAddressPointerSame, isEventPointer, isEventPointerSame, } from "applesauce-core/helpers/pointers";
|
|
5
5
|
import { map } from "rxjs/operators";
|
|
6
6
|
import { COMMENT_KIND, getCommentReplyPointer } from "../helpers/comment.js";
|
|
7
7
|
import { getNip10References } from "../helpers/threading.js";
|
|
@@ -67,7 +67,9 @@ export function ThreadModel(root, opts) {
|
|
|
67
67
|
/** A model that gets all legacy and NIP-10, and NIP-22 replies for an event */
|
|
68
68
|
export function RepliesModel(event, overrideKinds) {
|
|
69
69
|
return (events) => {
|
|
70
|
-
const filter = {
|
|
70
|
+
const filter = {
|
|
71
|
+
kinds: overrideKinds ?? (event.kind === 1 ? [1, COMMENT_KIND] : [COMMENT_KIND]),
|
|
72
|
+
};
|
|
71
73
|
return events.timeline(buildCommonEventRelationFilters(filter, event)).pipe(map((events) =>
|
|
72
74
|
// Filter for direct replies
|
|
73
75
|
events.filter((reply) => {
|
|
@@ -78,14 +80,15 @@ export function RepliesModel(event, overrideKinds) {
|
|
|
78
80
|
if (!refs.reply)
|
|
79
81
|
return false;
|
|
80
82
|
// If the input was provided as an event pointer, test the reply.e
|
|
81
|
-
if (isEventPointer(event))
|
|
83
|
+
if (isEventPointer(event)) {
|
|
82
84
|
return refs.reply?.e && isEventPointerSame(event, refs.reply.e);
|
|
83
|
-
// If the input was provided as an address pointer, test the reply.a
|
|
84
|
-
else if (isAddressPointer(event))
|
|
85
|
+
} // If the input was provided as an address pointer, test the reply.a
|
|
86
|
+
else if (isAddressPointer(event)) {
|
|
85
87
|
return refs.reply?.a && isAddressPointerSame(event, refs.reply.a);
|
|
86
|
-
// Else test the reply against the event
|
|
87
|
-
else
|
|
88
|
+
} // Else test the reply against the event
|
|
89
|
+
else {
|
|
88
90
|
return eventMatchesPointer(event, refs.reply?.a || refs.reply?.e);
|
|
91
|
+
}
|
|
89
92
|
}
|
|
90
93
|
else if (reply.kind === COMMENT_KIND) {
|
|
91
94
|
// Check if a NIP-22 reply is a direct reply to this event
|
|
@@ -96,12 +99,12 @@ export function RepliesModel(event, overrideKinds) {
|
|
|
96
99
|
if (pointer.type === "external")
|
|
97
100
|
return true;
|
|
98
101
|
// Input is an event pointer, check if they match
|
|
99
|
-
if (isEventPointer(event))
|
|
102
|
+
if (isEventPointer(event)) {
|
|
100
103
|
return pointer.type === "event" ? isEventPointerSame(event, pointer) : false;
|
|
101
|
-
// Input is an address pointer, check if they match
|
|
102
|
-
else if (isAddressPointer(event))
|
|
104
|
+
} // Input is an address pointer, check if they match
|
|
105
|
+
else if (isAddressPointer(event)) {
|
|
103
106
|
return pointer.type === "address" ? isAddressPointerSame(event, pointer) : false;
|
|
104
|
-
// Else test the reply against the event
|
|
107
|
+
} // Else test the reply against the event
|
|
105
108
|
else
|
|
106
109
|
return eventMatchesPointer(event, pointer);
|
|
107
110
|
}
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
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";
|
|
@@ -1,29 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { castEvent } from "../casts/cast.js";
|
|
4
|
-
/** Casts an event to a specific type */
|
|
5
|
-
export function castEventStream(cls, store) {
|
|
6
|
-
return (source) => source.pipe(map((event) => {
|
|
7
|
-
if (!event)
|
|
8
|
-
return undefined;
|
|
9
|
-
try {
|
|
10
|
-
return castEvent(event, cls, store);
|
|
11
|
-
}
|
|
12
|
-
catch { }
|
|
13
|
-
return undefined;
|
|
14
|
-
}));
|
|
15
|
-
}
|
|
16
|
-
/** Casts and array of events to an array of casted events and filters out undefined values */
|
|
17
|
-
export function castTimelineStream(cls, store) {
|
|
18
|
-
return (source) => source.pipe(map((events) => {
|
|
19
|
-
const castedEvents = [];
|
|
20
|
-
for (const event of events) {
|
|
21
|
-
try {
|
|
22
|
-
const casted = castEvent(event, cls, store);
|
|
23
|
-
castedEvents.push(casted);
|
|
24
|
-
}
|
|
25
|
-
catch { }
|
|
26
|
-
}
|
|
27
|
-
return castedEvents;
|
|
28
|
-
}), defined());
|
|
29
|
-
}
|
|
1
|
+
// Re-exported from applesauce-core — chainable now lives in the core package
|
|
2
|
+
export * from "applesauce-core/observable/cast-stream";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "applesauce-core/observable/chainable";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Re-exported from applesauce-core — chainable now lives in the core package
|
|
2
|
-
export
|
|
2
|
+
export * from "applesauce-core/observable/chainable";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
/** Adds a grasp server URL. */
|
|
3
|
+
export declare function addGitGraspServer(url: string): EventOperation;
|
|
4
|
+
/** Removes a grasp server URL. */
|
|
5
|
+
export declare function removeGitGraspServer(url: string): EventOperation;
|
|
6
|
+
/** Replaces all grasp servers. */
|
|
7
|
+
export declare function setGitGraspServers(urls: string[]): EventOperation;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { normalizeRelayUrl, relaySet } from "applesauce-core/helpers/relays";
|
|
2
|
+
import { addRelayTag, removeRelayTag } from "applesauce-core/operations/tag/relay";
|
|
3
|
+
import { modifyPublicTags } from "applesauce-core/operations/tags";
|
|
4
|
+
/** Adds a grasp server URL. */
|
|
5
|
+
export function addGitGraspServer(url) {
|
|
6
|
+
return modifyPublicTags(addRelayTag(normalizeRelayUrl(url), "g"));
|
|
7
|
+
}
|
|
8
|
+
/** Removes a grasp server URL. */
|
|
9
|
+
export function removeGitGraspServer(url) {
|
|
10
|
+
return modifyPublicTags(removeRelayTag(normalizeRelayUrl(url), "g"));
|
|
11
|
+
}
|
|
12
|
+
/** Replaces all grasp servers. */
|
|
13
|
+
export function setGitGraspServers(urls) {
|
|
14
|
+
return modifyPublicTags((tags) => [
|
|
15
|
+
...tags.filter((tag) => tag[0] !== "g"),
|
|
16
|
+
...relaySet(urls).map((url) => ["g", url]),
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
import { GitRepositoryPointer } from "../helpers/git-repository.js";
|
|
3
|
+
/** Sets the repository identifier `d` tag. */
|
|
4
|
+
export declare function setGitRepositoryIdentifier(identifier: string): EventOperation;
|
|
5
|
+
/** Sets or removes the repository name. */
|
|
6
|
+
export declare function setGitRepositoryName(name: string | null): EventOperation;
|
|
7
|
+
/** Sets or removes the repository description. */
|
|
8
|
+
export declare function setGitRepositoryDescription(description: string | null): EventOperation;
|
|
9
|
+
/** Sets the repository web URLs (single `web` tag, NIP-34 flat list). */
|
|
10
|
+
export declare function setGitRepositoryWebUrls(urls: string[]): EventOperation;
|
|
11
|
+
/** Sets the git clone URLs (single `clone` tag). */
|
|
12
|
+
export declare function setGitRepositoryCloneUrls(urls: string[]): EventOperation;
|
|
13
|
+
/** Sets the repository relay URLs (single `relays` tag, normalized). */
|
|
14
|
+
export declare function setGitRepositoryRelays(relays: string[]): EventOperation;
|
|
15
|
+
/** Adds a web browsing URL. */
|
|
16
|
+
export declare function addGitRepositoryWebUrl(url: string): EventOperation;
|
|
17
|
+
/** Removes a web browsing URL. */
|
|
18
|
+
export declare function removeGitRepositoryWebUrl(url: string): EventOperation;
|
|
19
|
+
/** Adds a git clone URL. */
|
|
20
|
+
export declare function addGitRepositoryCloneUrl(url: string): EventOperation;
|
|
21
|
+
/** Removes a git clone URL. */
|
|
22
|
+
export declare function removeGitRepositoryCloneUrl(url: string): EventOperation;
|
|
23
|
+
/** Adds a repository relay URL. */
|
|
24
|
+
export declare function addGitRepositoryRelay(relay: string): EventOperation;
|
|
25
|
+
/** Removes a repository relay URL. */
|
|
26
|
+
export declare function removeGitRepositoryRelay(relay: string): EventOperation;
|
|
27
|
+
/** Sets or removes the earliest unique commit marker. */
|
|
28
|
+
export declare function setGitRepositoryEarliestUniqueCommit(commit: string | null): EventOperation;
|
|
29
|
+
/** Sets the recognized maintainer pubkeys (single `maintainers` tag). */
|
|
30
|
+
export declare function setGitRepositoryMaintainers(pubkeys: string[]): EventOperation;
|
|
31
|
+
/** Adds a recognized maintainer pubkey. */
|
|
32
|
+
export declare function addGitRepositoryMaintainer(pubkey: string): EventOperation;
|
|
33
|
+
/** Removes a recognized maintainer pubkey. */
|
|
34
|
+
export declare function removeGitRepositoryMaintainer(pubkey: string): EventOperation;
|
|
35
|
+
/** Sets repository hashtags (NIP-34: multiple `["t", "<topic>"]` tags). */
|
|
36
|
+
export declare function setGitRepositoryHashtags(hashtags: string[]): EventOperation;
|
|
37
|
+
/** Adds a repository hashtag (NIP-34: `["t", "<topic>"]`). */
|
|
38
|
+
export declare function addGitRepositoryHashtag(hashtag: string): EventOperation;
|
|
39
|
+
/** Removes a repository hashtag. */
|
|
40
|
+
export declare function removeGitRepositoryHashtag(hashtag: string): EventOperation;
|
|
41
|
+
/**
|
|
42
|
+
* Sets or clears the upstream repository pointer (the repo this one was forked from).
|
|
43
|
+
* Writes a `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setGitRepositoryUpstream(pointer: GitRepositoryPointer | null): EventOperation;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { getReplaceableAddressFromPointer } from "applesauce-core/helpers/pointers";
|
|
2
|
+
import { isSafeRelayURL } from "applesauce-core/helpers/relays";
|
|
3
|
+
import { normalizeURL } from "applesauce-core/helpers/url";
|
|
4
|
+
import { includeSingletonTag, modifyPublicTags } from "applesauce-core/operations/tags";
|
|
5
|
+
import { removeSingletonTag, setSingletonTag } from "applesauce-core/operations/tag/common";
|
|
6
|
+
import { GIT_REPOSITORY_KIND } from "../helpers/git-repository.js";
|
|
7
|
+
import { addHashtag, removeHashtag, setHashtags } from "./hashtags.js";
|
|
8
|
+
/** NIP-34 uses one tag per name with all values in that tag: `["web", url1, url2, ...]`. */
|
|
9
|
+
function collectFlatTagValues(tags, name) {
|
|
10
|
+
const values = [];
|
|
11
|
+
for (const t of tags) {
|
|
12
|
+
if (t[0] === name && t.length > 1)
|
|
13
|
+
values.push(...t.slice(1));
|
|
14
|
+
}
|
|
15
|
+
return values;
|
|
16
|
+
}
|
|
17
|
+
function stripTagsNamed(tags, name) {
|
|
18
|
+
return tags.filter((t) => t[0] !== name);
|
|
19
|
+
}
|
|
20
|
+
function withFlatListTag(tags, name, values) {
|
|
21
|
+
const base = stripTagsNamed(tags, name);
|
|
22
|
+
if (values.length === 0)
|
|
23
|
+
return base;
|
|
24
|
+
return [...base, [name, ...values]];
|
|
25
|
+
}
|
|
26
|
+
/** Sets the repository identifier `d` tag. */
|
|
27
|
+
export function setGitRepositoryIdentifier(identifier) {
|
|
28
|
+
return includeSingletonTag(["d", identifier], true);
|
|
29
|
+
}
|
|
30
|
+
/** Sets or removes the repository name. */
|
|
31
|
+
export function setGitRepositoryName(name) {
|
|
32
|
+
return modifyPublicTags(name === null ? removeSingletonTag("name") : setSingletonTag(["name", name], true));
|
|
33
|
+
}
|
|
34
|
+
/** Sets or removes the repository description. */
|
|
35
|
+
export function setGitRepositoryDescription(description) {
|
|
36
|
+
return modifyPublicTags(description === null ? removeSingletonTag("description") : setSingletonTag(["description", description], true));
|
|
37
|
+
}
|
|
38
|
+
/** Sets the repository web URLs (single `web` tag, NIP-34 flat list). */
|
|
39
|
+
export function setGitRepositoryWebUrls(urls) {
|
|
40
|
+
return modifyPublicTags((tags) => withFlatListTag(tags, "web", urls));
|
|
41
|
+
}
|
|
42
|
+
/** Sets the git clone URLs (single `clone` tag). */
|
|
43
|
+
export function setGitRepositoryCloneUrls(urls) {
|
|
44
|
+
return modifyPublicTags((tags) => withFlatListTag(tags, "clone", urls));
|
|
45
|
+
}
|
|
46
|
+
/** Sets the repository relay URLs (single `relays` tag, normalized). */
|
|
47
|
+
export function setGitRepositoryRelays(relays) {
|
|
48
|
+
return modifyPublicTags((tags) => {
|
|
49
|
+
const normalized = relays.map((relay) => new URL(relay).toString());
|
|
50
|
+
return withFlatListTag(tags, "relays", normalized);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Adds a web browsing URL. */
|
|
54
|
+
export function addGitRepositoryWebUrl(url) {
|
|
55
|
+
return modifyPublicTags((tags) => {
|
|
56
|
+
const cur = collectFlatTagValues(tags, "web");
|
|
57
|
+
if (cur.includes(url))
|
|
58
|
+
return withFlatListTag(tags, "web", cur);
|
|
59
|
+
return withFlatListTag(tags, "web", [...cur, url]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** Removes a web browsing URL. */
|
|
63
|
+
export function removeGitRepositoryWebUrl(url) {
|
|
64
|
+
return modifyPublicTags((tags) => {
|
|
65
|
+
const cur = collectFlatTagValues(tags, "web").filter((u) => u !== url);
|
|
66
|
+
return withFlatListTag(tags, "web", cur);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Adds a git clone URL. */
|
|
70
|
+
export function addGitRepositoryCloneUrl(url) {
|
|
71
|
+
return modifyPublicTags((tags) => {
|
|
72
|
+
const cur = collectFlatTagValues(tags, "clone");
|
|
73
|
+
if (cur.includes(url))
|
|
74
|
+
return withFlatListTag(tags, "clone", cur);
|
|
75
|
+
return withFlatListTag(tags, "clone", [...cur, url]);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Removes a git clone URL. */
|
|
79
|
+
export function removeGitRepositoryCloneUrl(url) {
|
|
80
|
+
return modifyPublicTags((tags) => {
|
|
81
|
+
const cur = collectFlatTagValues(tags, "clone").filter((u) => u !== url);
|
|
82
|
+
return withFlatListTag(tags, "clone", cur);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** Adds a repository relay URL. */
|
|
86
|
+
export function addGitRepositoryRelay(relay) {
|
|
87
|
+
const normalized = new URL(relay).toString();
|
|
88
|
+
return modifyPublicTags((tags) => {
|
|
89
|
+
const cur = collectFlatTagValues(tags, "relays");
|
|
90
|
+
if (cur.includes(normalized))
|
|
91
|
+
return withFlatListTag(tags, "relays", cur);
|
|
92
|
+
return withFlatListTag(tags, "relays", [...cur, normalized]);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** Removes a repository relay URL. */
|
|
96
|
+
export function removeGitRepositoryRelay(relay) {
|
|
97
|
+
const normalized = new URL(relay).toString();
|
|
98
|
+
return modifyPublicTags((tags) => {
|
|
99
|
+
const cur = collectFlatTagValues(tags, "relays").filter((r) => r !== normalized);
|
|
100
|
+
return withFlatListTag(tags, "relays", cur);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/** Sets or removes the earliest unique commit marker. */
|
|
104
|
+
export function setGitRepositoryEarliestUniqueCommit(commit) {
|
|
105
|
+
return modifyPublicTags((tags) => {
|
|
106
|
+
const filtered = tags.filter((tag) => !(tag[0] === "r" && tag[2] === "euc"));
|
|
107
|
+
return commit === null ? filtered : [...filtered, ["r", commit, "euc"]];
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/** Sets the recognized maintainer pubkeys (single `maintainers` tag). */
|
|
111
|
+
export function setGitRepositoryMaintainers(pubkeys) {
|
|
112
|
+
return modifyPublicTags((tags) => withFlatListTag(tags, "maintainers", pubkeys));
|
|
113
|
+
}
|
|
114
|
+
/** Adds a recognized maintainer pubkey. */
|
|
115
|
+
export function addGitRepositoryMaintainer(pubkey) {
|
|
116
|
+
return modifyPublicTags((tags) => {
|
|
117
|
+
const cur = collectFlatTagValues(tags, "maintainers");
|
|
118
|
+
if (cur.includes(pubkey))
|
|
119
|
+
return withFlatListTag(tags, "maintainers", cur);
|
|
120
|
+
return withFlatListTag(tags, "maintainers", [...cur, pubkey]);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/** Removes a recognized maintainer pubkey. */
|
|
124
|
+
export function removeGitRepositoryMaintainer(pubkey) {
|
|
125
|
+
return modifyPublicTags((tags) => {
|
|
126
|
+
const cur = collectFlatTagValues(tags, "maintainers").filter((pk) => pk !== pubkey);
|
|
127
|
+
return withFlatListTag(tags, "maintainers", cur);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/** Sets repository hashtags (NIP-34: multiple `["t", "<topic>"]` tags). */
|
|
131
|
+
export function setGitRepositoryHashtags(hashtags) {
|
|
132
|
+
return setHashtags(hashtags);
|
|
133
|
+
}
|
|
134
|
+
/** Adds a repository hashtag (NIP-34: `["t", "<topic>"]`). */
|
|
135
|
+
export function addGitRepositoryHashtag(hashtag) {
|
|
136
|
+
return addHashtag(hashtag);
|
|
137
|
+
}
|
|
138
|
+
/** Removes a repository hashtag. */
|
|
139
|
+
export function removeGitRepositoryHashtag(hashtag) {
|
|
140
|
+
return removeHashtag(hashtag);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Sets or clears the upstream repository pointer (the repo this one was forked from).
|
|
144
|
+
* Writes a `["u", "30617:<pubkey>:<identifier>", "<relay hint>"]` tag.
|
|
145
|
+
*/
|
|
146
|
+
export function setGitRepositoryUpstream(pointer) {
|
|
147
|
+
return modifyPublicTags((tags) => {
|
|
148
|
+
const filtered = tags.filter((tag) => tag[0] !== "u");
|
|
149
|
+
if (!pointer)
|
|
150
|
+
return filtered;
|
|
151
|
+
if (pointer.kind !== GIT_REPOSITORY_KIND)
|
|
152
|
+
throw new Error(`Upstream pointer must reference kind ${GIT_REPOSITORY_KIND}`);
|
|
153
|
+
if (!pointer.identifier)
|
|
154
|
+
throw new Error("Upstream pointer must include an identifier");
|
|
155
|
+
const address = getReplaceableAddressFromPointer(pointer);
|
|
156
|
+
const hint = pointer.relays?.find((url) => isSafeRelayURL(url));
|
|
157
|
+
const tag = hint ? ["u", address, normalizeURL(hint)] : ["u", address];
|
|
158
|
+
return [...filtered, tag];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
@@ -3,5 +3,7 @@ import { EventOperation } from "applesauce-core/factories";
|
|
|
3
3
|
export declare function addHashtag(hashtag: string): EventOperation;
|
|
4
4
|
/** Removes a hashtag from the live event */
|
|
5
5
|
export declare function removeHashtag(hashtag: string): EventOperation;
|
|
6
|
+
/** Sets all the hashtags on an event. */
|
|
7
|
+
export declare function setHashtags(hashtags: string[]): EventOperation;
|
|
6
8
|
/** Adds "t" tags for an array of hashtags */
|
|
7
9
|
export declare function includeHashtags(hashtags: string[]): EventOperation;
|
|
@@ -11,6 +11,13 @@ export function removeHashtag(hashtag) {
|
|
|
11
11
|
const cleanTag = (hashtag.startsWith("#") ? hashtag.slice(1) : hashtag).toLocaleLowerCase();
|
|
12
12
|
return modifyPublicTags((tags) => tags.filter((t) => t[0] !== "t" || t[1].toLocaleLowerCase() !== cleanTag));
|
|
13
13
|
}
|
|
14
|
+
/** Sets all the hashtags on an event. */
|
|
15
|
+
export function setHashtags(hashtags) {
|
|
16
|
+
return modifyPublicTags((tags) => [
|
|
17
|
+
...tags.filter((t) => t[0] !== "t"),
|
|
18
|
+
...hashtags.map((hashtag) => ["t", hashtag.toLocaleLowerCase()]),
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
14
21
|
/** Adds "t" tags for an array of hashtags */
|
|
15
22
|
export function includeHashtags(hashtags) {
|
|
16
23
|
return modifyPublicTags(...hashtags.map((hashtag) => addNameValueTag(["t", hashtag.toLocaleLowerCase()])));
|
|
@@ -11,6 +11,8 @@ export * as Comment from "./comment.js";
|
|
|
11
11
|
export * as FileMetadata from "./file-metadata.js";
|
|
12
12
|
export * as Geohash from "./geohash.js";
|
|
13
13
|
export * as GiftWrap from "./gift-wrap.js";
|
|
14
|
+
export * as GitGraspList from "./git-grasp-list.js";
|
|
15
|
+
export * as GitRepository from "./git-repository.js";
|
|
14
16
|
export * as Group from "./group.js";
|
|
15
17
|
export * as Hashtags from "./hashtags.js";
|
|
16
18
|
export * as Highlight from "./highlight.js";
|
package/dist/operations/index.js
CHANGED
|
@@ -11,6 +11,8 @@ export * as Comment from "./comment.js";
|
|
|
11
11
|
export * as FileMetadata from "./file-metadata.js";
|
|
12
12
|
export * as Geohash from "./geohash.js";
|
|
13
13
|
export * as GiftWrap from "./gift-wrap.js";
|
|
14
|
+
export * as GitGraspList from "./git-grasp-list.js";
|
|
15
|
+
export * as GitRepository from "./git-repository.js";
|
|
14
16
|
export * as Group from "./group.js";
|
|
15
17
|
export * as Hashtags from "./hashtags.js";
|
|
16
18
|
export * as Highlight from "./highlight.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { EventOperation } from "applesauce-core/factories";
|
|
2
|
+
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
2
3
|
import { PollType } from "../helpers/poll.js";
|
|
3
|
-
/** Sets the content
|
|
4
|
-
export declare function setQuestion(question: string): EventOperation;
|
|
4
|
+
/** Sets the poll question as event content, with hashtag / mention / quote / custom emoji handling */
|
|
5
|
+
export declare function setQuestion(question: string, options?: TextContentOptions): EventOperation;
|
|
5
6
|
/** Adds an option to a poll with an option ID and label */
|
|
6
7
|
export declare function addOption(optionId: string, label: string): EventOperation;
|
|
7
8
|
/** Sets multiple poll options at once, replacing any existing option tags */
|
package/dist/operations/poll.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { modifyPublicTags } from "applesauce-core/operations";
|
|
2
|
+
import { setShortTextContent } from "applesauce-core/operations/content";
|
|
2
3
|
import { includeSingletonTag } from "applesauce-core/operations/tags";
|
|
3
|
-
/** Sets the content
|
|
4
|
-
export function setQuestion(question) {
|
|
5
|
-
return (
|
|
4
|
+
/** Sets the poll question as event content, with hashtag / mention / quote / custom emoji handling */
|
|
5
|
+
export function setQuestion(question, options) {
|
|
6
|
+
return setShortTextContent(question, options);
|
|
6
7
|
}
|
|
7
8
|
/** Adds an option to a poll with an option ID and label */
|
|
8
9
|
export function addOption(optionId, label) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-common",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Common NIP-specific helpers and models for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@scure/base": "^1.2.4",
|
|
86
|
-
"applesauce-core": "^6.
|
|
86
|
+
"applesauce-core": "^6.1.0",
|
|
87
87
|
"hash-sum": "^2.0.0",
|
|
88
88
|
"light-bolt11-decoder": "^3.2.0",
|
|
89
89
|
"nanoid": "^5.0.9",
|
|
@@ -95,13 +95,13 @@
|
|
|
95
95
|
"@types/debug": "^4.1.12",
|
|
96
96
|
"@types/hash-sum": "^1.0.2",
|
|
97
97
|
"@types/node": "^22.19.1",
|
|
98
|
-
"ajv": "^8.
|
|
98
|
+
"ajv": "^8.20.0",
|
|
99
99
|
"ajv-formats": "^3.0.1",
|
|
100
100
|
"nostr-tools": "^2.19",
|
|
101
101
|
"rimraf": "^6.0.1",
|
|
102
102
|
"typescript": "^5.8.3",
|
|
103
103
|
"vitest": "^4.0.15",
|
|
104
|
-
"yaml": "^2.
|
|
104
|
+
"yaml": "^2.9.0"
|
|
105
105
|
},
|
|
106
106
|
"funding": {
|
|
107
107
|
"type": "lightning",
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { kinds, KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
2
|
-
import { NIP51RelayListFactory } from "./list.js";
|
|
3
|
-
export type DmRelaysTemplate = KnownEventTemplate<kinds.DirectMessageRelaysList>;
|
|
4
|
-
/** A factory class for building kind 10050 direct message relays list events */
|
|
5
|
-
export declare class DmRelaysFactory extends NIP51RelayListFactory<kinds.DirectMessageRelaysList, DmRelaysTemplate> {
|
|
6
|
-
/** Creates a new DM relays factory */
|
|
7
|
-
static create(): DmRelaysFactory;
|
|
8
|
-
/** Creates a new DM relays factory from an existing DM relays event */
|
|
9
|
-
static modify(event: NostrEvent | KnownEvent<kinds.DirectMessageRelaysList>): DmRelaysFactory;
|
|
10
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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 10050 direct message relays list events */
|
|
5
|
-
export class DmRelaysFactory extends NIP51RelayListFactory {
|
|
6
|
-
/** Creates a new DM relays factory */
|
|
7
|
-
static create() {
|
|
8
|
-
return new DmRelaysFactory((res) => res(blankEventTemplate(kinds.DirectMessageRelaysList)));
|
|
9
|
-
}
|
|
10
|
-
/** Creates a new DM relays factory from an existing DM relays event */
|
|
11
|
-
static modify(event) {
|
|
12
|
-
if (!isKind(event, kinds.DirectMessageRelaysList))
|
|
13
|
-
throw new Error("Event is not a DM relays event");
|
|
14
|
-
return new DmRelaysFactory((res) => res(toEventTemplate(event)));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { KnownEvent, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
2
|
-
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
-
import { FAVORITE_RELAYS_KIND } from "../helpers/relay-list.js";
|
|
4
|
-
import { NIP51RelayListFactory } from "./list.js";
|
|
5
|
-
export type FavoriteRelaysTemplate = KnownEventTemplate<typeof FAVORITE_RELAYS_KIND>;
|
|
6
|
-
/** A factory class for building kind 10012 favorite relays list events */
|
|
7
|
-
export declare class FavoriteRelaysFactory extends NIP51RelayListFactory<typeof FAVORITE_RELAYS_KIND, FavoriteRelaysTemplate> {
|
|
8
|
-
/** Creates a new favorite relays factory */
|
|
9
|
-
static create(): FavoriteRelaysFactory;
|
|
10
|
-
/** Creates a new favorite relays factory from an existing favorite relays event */
|
|
11
|
-
static modify(event: NostrEvent | KnownEvent<typeof FAVORITE_RELAYS_KIND>): FavoriteRelaysFactory;
|
|
12
|
-
/** Adds a relay set (address pointer) to the favorite relays event */
|
|
13
|
-
addRelaySet(addr: AddressPointer | AddressPointer[], hidden?: boolean): this;
|
|
14
|
-
/** Removes a relay set (address pointer) from the favorite relays event */
|
|
15
|
-
removeRelaySet(addr: AddressPointer | AddressPointer[], hidden?: boolean): this;
|
|
16
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { blankEventTemplate, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
-
import { addAddressPointerTag, removeAddressPointerTag } from "applesauce-core/operations/tag/common";
|
|
3
|
-
import { FAVORITE_RELAYS_KIND } from "../helpers/relay-list.js";
|
|
4
|
-
import { NIP51RelayListFactory } from "./list.js";
|
|
5
|
-
/** A factory class for building kind 10012 favorite relays list events */
|
|
6
|
-
export class FavoriteRelaysFactory extends NIP51RelayListFactory {
|
|
7
|
-
/** Creates a new favorite relays factory */
|
|
8
|
-
static create() {
|
|
9
|
-
return new FavoriteRelaysFactory((res) => res(blankEventTemplate(FAVORITE_RELAYS_KIND)));
|
|
10
|
-
}
|
|
11
|
-
/** Creates a new favorite relays factory from an existing favorite relays event */
|
|
12
|
-
static modify(event) {
|
|
13
|
-
if (event.kind !== FAVORITE_RELAYS_KIND)
|
|
14
|
-
throw new Error("Event is not a favorite relays event");
|
|
15
|
-
return new FavoriteRelaysFactory((res) => res(toEventTemplate(event)));
|
|
16
|
-
}
|
|
17
|
-
/** Adds a relay set (address pointer) to the favorite relays event */
|
|
18
|
-
addRelaySet(addr, hidden = false) {
|
|
19
|
-
const addrs = Array.isArray(addr) ? addr : [addr];
|
|
20
|
-
return hidden
|
|
21
|
-
? this.modifyHiddenTags(...addrs.map((a) => addAddressPointerTag(a)))
|
|
22
|
-
: this.modifyPublicTags(...addrs.map((a) => addAddressPointerTag(a)));
|
|
23
|
-
}
|
|
24
|
-
/** Removes a relay set (address pointer) from the favorite relays event */
|
|
25
|
-
removeRelaySet(addr, hidden = false) {
|
|
26
|
-
const addrs = Array.isArray(addr) ? addr : [addr];
|
|
27
|
-
return hidden
|
|
28
|
-
? this.modifyHiddenTags(...addrs.map((a) => removeAddressPointerTag(a)))
|
|
29
|
-
: this.modifyPublicTags(...addrs.map((a) => removeAddressPointerTag(a)));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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 10007 search relays list events */
|
|
5
|
-
export class SearchRelaysFactory extends NIP51RelayListFactory {
|
|
6
|
-
/** Creates a new search relays factory */
|
|
7
|
-
static create() {
|
|
8
|
-
return new SearchRelaysFactory((res) => res(blankEventTemplate(kinds.SearchRelaysList)));
|
|
9
|
-
}
|
|
10
|
-
/** Creates a new search relays factory from an existing search relays event */
|
|
11
|
-
static modify(event) {
|
|
12
|
-
if (!isKind(event, kinds.SearchRelaysList))
|
|
13
|
-
throw new Error("Event is not a search relays event");
|
|
14
|
-
return new SearchRelaysFactory((res) => res(toEventTemplate(event)));
|
|
15
|
-
}
|
|
16
|
-
}
|