applesauce-common 6.2.0 → 7.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/README.md +1 -0
- package/dist/casts/_circular-import.d.ts +3 -0
- package/dist/casts/_circular-import.js +3 -0
- package/dist/casts/app-handler.d.ts +56 -0
- package/dist/casts/app-handler.js +105 -0
- package/dist/casts/app-recommendation.d.ts +26 -0
- package/dist/casts/app-recommendation.js +41 -0
- package/dist/casts/external-identities.d.ts +9 -0
- package/dist/casts/external-identities.js +14 -0
- package/dist/casts/forum-thread.d.ts +17 -0
- package/dist/casts/forum-thread.js +31 -0
- package/dist/casts/git-issue.d.ts +18 -0
- package/dist/casts/git-issue.js +26 -0
- package/dist/casts/git-patch.d.ts +49 -0
- package/dist/casts/git-patch.js +88 -0
- package/dist/casts/git-pull-request.d.ts +67 -0
- package/dist/casts/git-pull-request.js +122 -0
- package/dist/casts/git-repository.d.ts +9 -0
- package/dist/casts/git-repository.js +16 -0
- package/dist/casts/git-thread.d.ts +33 -0
- package/dist/casts/git-thread.js +65 -0
- package/dist/casts/index.d.ts +12 -0
- package/dist/casts/index.js +12 -0
- package/dist/casts/napplet-handlers.d.ts +39 -0
- package/dist/casts/napplet-handlers.js +91 -0
- package/dist/casts/napplet.d.ts +98 -0
- package/dist/casts/napplet.js +196 -0
- package/dist/casts/note.d.ts +8 -0
- package/dist/casts/note.js +21 -1
- package/dist/casts/nsite.d.ts +134 -0
- package/dist/casts/nsite.js +249 -0
- package/dist/casts/profile.d.ts +20 -0
- package/dist/casts/profile.js +30 -0
- package/dist/casts/reaction.d.ts +1 -1
- package/dist/casts/relay-discovery.d.ts +4 -0
- package/dist/casts/relay-discovery.js +9 -1
- package/dist/casts/report.d.ts +28 -15
- package/dist/casts/report.js +42 -19
- package/dist/casts/share.d.ts +1 -1
- package/dist/casts/torrent.d.ts +5 -0
- package/dist/casts/torrent.js +8 -1
- package/dist/casts/trusted-assertions.d.ts +2 -0
- package/dist/casts/trusted-assertions.js +19 -18
- package/dist/casts/user-status.d.ts +33 -0
- package/dist/casts/user-status.js +69 -0
- package/dist/casts/user.d.ts +7 -0
- package/dist/casts/user.js +20 -1
- package/dist/factories/app-handler.d.ts +31 -0
- package/dist/factories/app-handler.js +50 -0
- package/dist/factories/app-recommendation.d.ts +21 -0
- package/dist/factories/app-recommendation.js +28 -0
- package/dist/factories/chat-message.d.ts +37 -0
- package/dist/factories/chat-message.js +56 -0
- package/dist/factories/comment.d.ts +8 -7
- package/dist/factories/comment.js +2 -2
- package/dist/factories/external-identities.d.ts +17 -0
- package/dist/factories/external-identities.js +28 -0
- package/dist/factories/file-message.d.ts +24 -0
- package/dist/factories/file-message.js +37 -0
- package/dist/factories/forum-thread.d.ts +34 -0
- package/dist/factories/forum-thread.js +50 -0
- package/dist/factories/git-applied-status.d.ts +39 -0
- package/dist/factories/git-applied-status.js +53 -0
- package/dist/factories/git-closed-status.d.ts +18 -0
- package/dist/factories/git-closed-status.js +24 -0
- package/dist/factories/git-draft-status.d.ts +18 -0
- package/dist/factories/git-draft-status.js +24 -0
- package/dist/factories/git-issue.d.ts +19 -0
- package/dist/factories/git-issue.js +25 -0
- package/dist/factories/git-open-status.d.ts +18 -0
- package/dist/factories/git-open-status.js +22 -0
- package/dist/factories/git-patch.d.ts +59 -0
- package/dist/factories/git-patch.js +102 -0
- package/dist/factories/git-pull-request-update.d.ts +23 -0
- package/dist/factories/git-pull-request-update.js +33 -0
- package/dist/factories/git-pull-request.d.ts +39 -0
- package/dist/factories/git-pull-request.js +64 -0
- package/dist/factories/index.d.ts +24 -0
- package/dist/factories/index.js +24 -0
- package/dist/factories/internal/git-pull-request.d.ts +19 -0
- package/dist/factories/internal/git-pull-request.js +26 -0
- package/dist/factories/internal/git-status.d.ts +11 -0
- package/dist/factories/internal/git-status.js +12 -0
- package/dist/factories/internal/git-thread.d.ts +19 -0
- package/dist/factories/internal/git-thread.js +29 -0
- package/dist/factories/internal/napplet-manifest.d.ts +52 -0
- package/dist/factories/internal/napplet-manifest.js +85 -0
- package/dist/factories/internal/nsite-manifest.d.ts +45 -0
- package/dist/factories/internal/nsite-manifest.js +68 -0
- package/dist/factories/legacy-message.d.ts +2 -0
- package/dist/factories/legacy-message.js +9 -2
- package/dist/factories/named-napplet.d.ts +20 -0
- package/dist/factories/named-napplet.js +30 -0
- package/dist/factories/named-nsite.d.ts +28 -0
- package/dist/factories/named-nsite.js +53 -0
- package/dist/factories/napplet-handlers.d.ts +34 -0
- package/dist/factories/napplet-handlers.js +77 -0
- package/dist/factories/napplet-snapshot.d.ts +18 -0
- package/dist/factories/napplet-snapshot.js +38 -0
- package/dist/factories/nsite-snapshot.d.ts +18 -0
- package/dist/factories/nsite-snapshot.js +29 -0
- package/dist/factories/reaction.d.ts +3 -2
- package/dist/factories/report.d.ts +48 -0
- package/dist/factories/report.js +66 -0
- package/dist/factories/root-napplet.d.ts +18 -0
- package/dist/factories/root-napplet.js +24 -0
- package/dist/factories/root-nsite.d.ts +23 -0
- package/dist/factories/root-nsite.js +44 -0
- package/dist/factories/torrent.d.ts +24 -10
- package/dist/factories/torrent.js +48 -44
- package/dist/factories/trusted-provider-list.d.ts +23 -0
- package/dist/factories/trusted-provider-list.js +39 -0
- package/dist/factories/user-status.d.ts +26 -0
- package/dist/factories/user-status.js +52 -0
- package/dist/factories/wrapped-message.js +10 -4
- package/dist/helpers/app-data.js +15 -7
- package/dist/helpers/app-handler.d.ts +43 -6
- package/dist/helpers/app-handler.js +53 -3
- package/dist/helpers/app-recommendation.d.ts +24 -0
- package/dist/helpers/app-recommendation.js +30 -0
- package/dist/helpers/bookmark.js +5 -2
- package/dist/helpers/comment.d.ts +11 -5
- package/dist/helpers/comment.js +7 -1
- package/dist/helpers/content.d.ts +3 -1
- package/dist/helpers/emoji-pack.js +11 -6
- package/dist/helpers/emoji.d.ts +2 -2
- package/dist/helpers/encrypted-content-cache.d.ts +2 -11
- package/dist/helpers/encrypted-content-cache.js +6 -14
- package/dist/helpers/encrypted-file.d.ts +41 -0
- package/dist/helpers/encrypted-file.js +64 -0
- package/dist/helpers/external-id.js +13 -19
- package/dist/helpers/external-identities.d.ts +29 -0
- package/dist/helpers/external-identities.js +52 -0
- package/dist/helpers/file-message.d.ts +18 -0
- package/dist/helpers/file-message.js +44 -0
- package/dist/helpers/file-metadata.d.ts +9 -4
- package/dist/helpers/file-metadata.js +21 -6
- package/dist/helpers/forum-thread.d.ts +10 -0
- package/dist/helpers/forum-thread.js +10 -0
- package/dist/helpers/gift-wrap.d.ts +40 -15
- package/dist/helpers/gift-wrap.js +110 -33
- package/dist/helpers/git-issue.d.ts +13 -0
- package/dist/helpers/git-issue.js +19 -0
- package/dist/helpers/git-patch.d.ts +41 -0
- package/dist/helpers/git-patch.js +73 -0
- package/dist/helpers/git-pull-request.d.ts +57 -0
- package/dist/helpers/git-pull-request.js +111 -0
- package/dist/helpers/git-repository.d.ts +4 -0
- package/dist/helpers/git-repository.js +16 -0
- package/dist/helpers/git-status.d.ts +44 -0
- package/dist/helpers/git-status.js +93 -0
- package/dist/helpers/git.d.ts +2 -0
- package/dist/helpers/git.js +4 -0
- package/dist/helpers/groups.d.ts +5 -2
- package/dist/helpers/groups.js +40 -18
- package/dist/helpers/hashtag.d.ts +4 -2
- package/dist/helpers/index.d.ts +13 -0
- package/dist/helpers/index.js +13 -0
- package/dist/helpers/lists.js +14 -2
- package/dist/helpers/lnurl.js +1 -1
- package/dist/helpers/messages.js +3 -2
- package/dist/helpers/mute.js +20 -9
- package/dist/helpers/napplet-handlers.d.ts +79 -0
- package/dist/helpers/napplet-handlers.js +187 -0
- package/dist/helpers/napplet.d.ts +107 -0
- package/dist/helpers/napplet.js +177 -0
- package/dist/helpers/nsite.d.ts +90 -0
- package/dist/helpers/nsite.js +217 -0
- package/dist/helpers/relay-discovery.d.ts +4 -0
- package/dist/helpers/relay-discovery.js +8 -0
- package/dist/helpers/reports.d.ts +35 -0
- package/dist/helpers/reports.js +36 -5
- package/dist/helpers/threading.d.ts +4 -2
- package/dist/helpers/torrent.d.ts +9 -6
- package/dist/helpers/torrent.js +23 -15
- package/dist/helpers/trusted-assertions.d.ts +7 -0
- package/dist/helpers/trusted-assertions.js +41 -2
- package/dist/helpers/user-status.d.ts +13 -1
- package/dist/helpers/user-status.js +15 -0
- package/dist/helpers/wrapped-messages.d.ts +2 -0
- package/dist/helpers/wrapped-messages.js +6 -1
- package/dist/models/app-handler.d.ts +21 -0
- package/dist/models/app-handler.js +47 -0
- package/dist/models/git.d.ts +34 -0
- package/dist/models/git.js +144 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +4 -0
- package/dist/models/legacy-messages.js +6 -1
- package/dist/models/napplet-handlers.d.ts +16 -0
- package/dist/models/napplet-handlers.js +45 -0
- package/dist/models/nsite.d.ts +22 -0
- package/dist/models/nsite.js +67 -0
- package/dist/models/thread.d.ts +4 -1
- package/dist/models/thread.js +34 -5
- package/dist/models/user-status.d.ts +8 -4
- package/dist/models/user-status.js +16 -22
- package/dist/models/wrapped-messages.js +9 -7
- package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
- package/dist/observable/filter-timeline-by-mutes.js +6 -2
- package/dist/operations/app-handler.d.ts +24 -0
- package/dist/operations/app-handler.js +58 -0
- package/dist/operations/app-recommendation.d.ts +13 -0
- package/dist/operations/app-recommendation.js +40 -0
- package/dist/operations/calendar-event.js +3 -2
- package/dist/operations/chat-message.d.ts +9 -0
- package/dist/operations/chat-message.js +12 -0
- package/dist/operations/client.d.ts +1 -4
- package/dist/operations/client.js +1 -23
- package/dist/operations/comment.d.ts +9 -3
- package/dist/operations/comment.js +12 -9
- package/dist/operations/external-identities.d.ts +8 -0
- package/dist/operations/external-identities.js +23 -0
- package/dist/operations/file-message.d.ts +7 -0
- package/dist/operations/file-message.js +34 -0
- package/dist/operations/forum-thread.d.ts +3 -0
- package/dist/operations/forum-thread.js +6 -0
- package/dist/operations/gift-wrap.js +38 -14
- package/dist/operations/git-issue.d.ts +18 -0
- package/dist/operations/git-issue.js +31 -0
- package/dist/operations/git-patch.d.ts +30 -0
- package/dist/operations/git-patch.js +75 -0
- package/dist/operations/git-pull-request.d.ts +29 -0
- package/dist/operations/git-pull-request.js +74 -0
- package/dist/operations/git-repository.js +4 -4
- package/dist/operations/git-status.d.ts +28 -0
- package/dist/operations/git-status.js +116 -0
- package/dist/operations/git-thread.d.ts +13 -0
- package/dist/operations/git-thread.js +39 -0
- package/dist/operations/index.d.ts +17 -0
- package/dist/operations/index.js +17 -0
- package/dist/operations/internal/git-commits.d.ts +2 -0
- package/dist/operations/internal/git-commits.js +16 -0
- package/dist/operations/napplet-handlers.d.ts +47 -0
- package/dist/operations/napplet-handlers.js +161 -0
- package/dist/operations/napplet.d.ts +51 -0
- package/dist/operations/napplet.js +121 -0
- package/dist/operations/nsite.d.ts +51 -0
- package/dist/operations/nsite.js +112 -0
- package/dist/operations/reaction.d.ts +12 -2
- package/dist/operations/reaction.js +1 -1
- package/dist/operations/report.d.ts +33 -0
- package/dist/operations/report.js +60 -0
- package/dist/operations/stream.js +5 -4
- package/dist/operations/torrent.d.ts +1 -4
- package/dist/operations/torrent.js +24 -11
- package/dist/operations/trusted-providers.d.ts +14 -0
- package/dist/operations/trusted-providers.js +33 -0
- package/dist/operations/user-status.d.ts +11 -0
- package/dist/operations/user-status.js +29 -0
- package/dist/operations/wrapped-message.js +2 -2
- package/package.json +13 -17
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
|
+
import { getReplaceableIdentifier, kinds } from "applesauce-core/helpers/event";
|
|
2
3
|
import { getAddressPointerFromATag, getEventPointerFromETag, getProfilePointerFromPTag, } from "applesauce-core/helpers/pointers";
|
|
4
|
+
/** The event kind for NIP-38 user statuses */
|
|
5
|
+
export const USER_STATUS_KIND = kinds.UserStatuses;
|
|
3
6
|
export const UserStatusPointerSymbol = Symbol.for("user-status-pointer");
|
|
4
7
|
function getStatusPointer(status) {
|
|
5
8
|
const pTag = status.tags.find((t) => t[0] === "p" && t[1]);
|
|
@@ -25,6 +28,18 @@ function getStatusPointer(status) {
|
|
|
25
28
|
return { type: "url", data: rTag[1] };
|
|
26
29
|
return null;
|
|
27
30
|
}
|
|
31
|
+
/** Checks if an event is a valid NIP-38 user status */
|
|
32
|
+
export function isValidUserStatus(event) {
|
|
33
|
+
return !!event && event.kind === kinds.UserStatuses && event.tags.some((t) => t[0] === "d");
|
|
34
|
+
}
|
|
35
|
+
/** Gets the status type (the "d" tag) of a user status event */
|
|
36
|
+
export function getUserStatusType(status) {
|
|
37
|
+
return getReplaceableIdentifier(status);
|
|
38
|
+
}
|
|
39
|
+
/** Checks if a user status has been cleared (empty content) */
|
|
40
|
+
export function isUserStatusCleared(status) {
|
|
41
|
+
return status.content.trim() === "";
|
|
42
|
+
}
|
|
28
43
|
/** Gets the {@link UserStatusPointer} for a status event */
|
|
29
44
|
export function getUserStatusPointer(status) {
|
|
30
45
|
return getOrComputeCachedValue(status, UserStatusPointerSymbol, () => getStatusPointer(status));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Rumor } from "./gift-wrap.js";
|
|
2
|
+
/** Checks if a rumor is a NIP-17 chat message (kind 14) or a valid file message (kind 15) */
|
|
3
|
+
export declare function isWrappedMessage(rumor: Rumor): boolean;
|
|
2
4
|
/** Returns the subject of a wrapped direct message */
|
|
3
5
|
export declare function getWrappedMessageSubject(message: Rumor): string | undefined;
|
|
4
6
|
/** Returns the parent id of a wrapped direct message */
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { getTagValue } from "applesauce-core/helpers/event";
|
|
1
|
+
import { getTagValue, kinds } from "applesauce-core/helpers/event";
|
|
2
|
+
import { isValidFileMessage } from "./file-message.js";
|
|
2
3
|
import { getConversationParticipants } from "./messages.js";
|
|
4
|
+
/** Checks if a rumor is a NIP-17 chat message (kind 14) or a valid file message (kind 15) */
|
|
5
|
+
export function isWrappedMessage(rumor) {
|
|
6
|
+
return rumor.kind === kinds.PrivateDirectMessage || isValidFileMessage(rumor);
|
|
7
|
+
}
|
|
3
8
|
/** Returns the subject of a wrapped direct message */
|
|
4
9
|
export function getWrappedMessageSubject(message) {
|
|
5
10
|
return getTagValue(message, "subject");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Model } from "applesauce-core/event-store";
|
|
2
|
+
import { ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
import { AppHandlerEvent } from "../helpers/app-handler.js";
|
|
4
|
+
import { AppRecommendationEvent } from "../helpers/app-recommendation.js";
|
|
5
|
+
/** A handler ranked by the authors that recommend it */
|
|
6
|
+
export interface RankedAppHandler {
|
|
7
|
+
/** The handler information event */
|
|
8
|
+
handler: AppHandlerEvent;
|
|
9
|
+
/** The pubkeys of the authors recommending the handler */
|
|
10
|
+
recommenders: string[];
|
|
11
|
+
}
|
|
12
|
+
/** A model that returns NIP-89 handlers that advertise support for an event kind */
|
|
13
|
+
export declare function AppHandlersModel(kind: number): Model<AppHandlerEvent[]>;
|
|
14
|
+
/** A model that returns NIP-89 handler recommendations for an event kind, optionally from a set of authors */
|
|
15
|
+
export declare function AppRecommendationsModel(kind: number, authors?: string[]): Model<AppRecommendationEvent[]>;
|
|
16
|
+
/** A model that returns the handlers a user has published */
|
|
17
|
+
export declare function UserAppHandlersModel(user: string | ProfilePointer): Model<AppHandlerEvent[]>;
|
|
18
|
+
/** A model that returns a user's handler recommendations for every event kind */
|
|
19
|
+
export declare function UserAppRecommendationsModel(user: string | ProfilePointer): Model<AppRecommendationEvent[]>;
|
|
20
|
+
/** A model that returns the handlers recommended for an event kind, ranked by how many authors recommend each */
|
|
21
|
+
export declare function RecommendedAppHandlersModel(kind: number, authors?: string[]): Model<RankedAppHandler[]>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getReplaceableAddressFromPointer } from "applesauce-core/helpers/pointers";
|
|
2
|
+
import { combineLatest, map, of, switchMap } from "rxjs";
|
|
3
|
+
import { APP_HANDLER_KIND, getAppHandlersFilter, isValidAppHandler } from "../helpers/app-handler.js";
|
|
4
|
+
import { APP_RECOMMENDATION_KIND, getAppRecommendationsFilter, getRecommendedHandlers, isValidAppRecommendation, } from "../helpers/app-recommendation.js";
|
|
5
|
+
/** A model that returns NIP-89 handlers that advertise support for an event kind */
|
|
6
|
+
export function AppHandlersModel(kind) {
|
|
7
|
+
return (store) => store.timeline(getAppHandlersFilter(kind)).pipe(map((events) => events.filter(isValidAppHandler)));
|
|
8
|
+
}
|
|
9
|
+
/** A model that returns NIP-89 handler recommendations for an event kind, optionally from a set of authors */
|
|
10
|
+
export function AppRecommendationsModel(kind, authors) {
|
|
11
|
+
return (store) => store
|
|
12
|
+
.timeline(getAppRecommendationsFilter(kind, authors))
|
|
13
|
+
.pipe(map((events) => events.filter(isValidAppRecommendation)));
|
|
14
|
+
}
|
|
15
|
+
/** A model that returns the handlers a user has published */
|
|
16
|
+
export function UserAppHandlersModel(user) {
|
|
17
|
+
const pubkey = typeof user === "string" ? user : user.pubkey;
|
|
18
|
+
return (store) => store
|
|
19
|
+
.timeline({ kinds: [APP_HANDLER_KIND], authors: [pubkey] })
|
|
20
|
+
.pipe(map((events) => events.filter(isValidAppHandler)));
|
|
21
|
+
}
|
|
22
|
+
/** A model that returns a user's handler recommendations for every event kind */
|
|
23
|
+
export function UserAppRecommendationsModel(user) {
|
|
24
|
+
const pubkey = typeof user === "string" ? user : user.pubkey;
|
|
25
|
+
return (store) => store
|
|
26
|
+
.timeline({ kinds: [APP_RECOMMENDATION_KIND], authors: [pubkey] })
|
|
27
|
+
.pipe(map((events) => events.filter(isValidAppRecommendation)));
|
|
28
|
+
}
|
|
29
|
+
/** A model that returns the handlers recommended for an event kind, ranked by how many authors recommend each */
|
|
30
|
+
export function RecommendedAppHandlersModel(kind, authors) {
|
|
31
|
+
return (store) => store.model(AppRecommendationsModel, kind, authors).pipe(switchMap((recommendations) => {
|
|
32
|
+
const ranked = new Map();
|
|
33
|
+
for (const recommendation of recommendations) {
|
|
34
|
+
// A set counts each author once, even if they list the handler for several platforms
|
|
35
|
+
for (const { pointer } of getRecommendedHandlers(recommendation)) {
|
|
36
|
+
const address = getReplaceableAddressFromPointer(pointer);
|
|
37
|
+
const entry = ranked.get(address) ?? { pointer, recommenders: new Set() };
|
|
38
|
+
entry.recommenders.add(recommendation.pubkey);
|
|
39
|
+
ranked.set(address, entry);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (ranked.size === 0)
|
|
43
|
+
return of([]);
|
|
44
|
+
const entries = [...ranked.values()].sort((a, b) => b.recommenders.size - a.recommenders.size);
|
|
45
|
+
return combineLatest(entries.map((e) => store.replaceable(e.pointer))).pipe(map((events) => events.flatMap((handler, i) => isValidAppHandler(handler) ? [{ handler, recommenders: [...entries[i].recommenders] }] : [])));
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Model } from "applesauce-core/event-store";
|
|
2
|
+
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import { GitPatchEvent } from "../helpers/git-patch.js";
|
|
4
|
+
import { GitPullRequestEvent, GitPullRequestUpdateEvent, GitPullRequestState } from "../helpers/git-pull-request.js";
|
|
5
|
+
import { GitRepositoryPointer } from "../helpers/git-repository.js";
|
|
6
|
+
import { GitStatus, GitStatusEvent } from "../helpers/git-status.js";
|
|
7
|
+
/** A model that returns the latest authorized status event for an issue, patch or pull request */
|
|
8
|
+
export declare function GitStatusEventModel(root: NostrEvent, maintainers?: string[]): Model<GitStatusEvent | undefined>;
|
|
9
|
+
/** A model that returns the current status of an issue, patch or pull request */
|
|
10
|
+
export declare function GitStatusModel(root: NostrEvent, maintainers?: string[]): Model<GitStatus>;
|
|
11
|
+
/** A model that returns all NIP-22 comments in an issue, patch or pull request thread */
|
|
12
|
+
export declare function GitThreadCommentsModel(root: NostrEvent): Model<NostrEvent[]>;
|
|
13
|
+
/** A model that returns the updates to a pull request */
|
|
14
|
+
export declare function GitPullRequestUpdatesModel(pr: NostrEvent): Model<GitPullRequestUpdateEvent[]>;
|
|
15
|
+
/** A model that returns the latest complete fetch state of a pull request */
|
|
16
|
+
export declare function GitPullRequestStateModel(pr: GitPullRequestEvent): Model<GitPullRequestState>;
|
|
17
|
+
/** A model that resolves the first patch of the current series or revision */
|
|
18
|
+
export declare function GitPatchSeriesRootModel(patch: NostrEvent): Model<GitPatchEvent | undefined>;
|
|
19
|
+
/** A model that resolves the original root through patch and revision ancestors */
|
|
20
|
+
export declare function GitPatchOriginalRootModel(patch: NostrEvent): Model<GitPatchEvent | undefined>;
|
|
21
|
+
/** A model that returns patches in dependency order within a series, excluding other revisions */
|
|
22
|
+
export declare function GitPatchSeriesModel(patch: NostrEvent): Model<GitPatchEvent[]>;
|
|
23
|
+
/** A model that returns revision roots pointing to the original root patch */
|
|
24
|
+
export declare function GitPatchRevisionsModel(patch: NostrEvent): Model<GitPatchEvent[]>;
|
|
25
|
+
/** A model that returns the original root's latest authorized status event for a patch */
|
|
26
|
+
export declare function GitPatchStatusEventModel(patch: NostrEvent, maintainers?: string[]): Model<GitStatusEvent | undefined>;
|
|
27
|
+
/** A model that inherits original status and closes unaccepted revisions after application */
|
|
28
|
+
export declare function GitPatchStatusModel(patch: NostrEvent, maintainers?: string[]): Model<GitStatus>;
|
|
29
|
+
/** A model that returns the issues of a repository */
|
|
30
|
+
export declare function GitRepositoryIssuesModel(repo: GitRepositoryPointer): Model<NostrEvent[]>;
|
|
31
|
+
/** A model that returns the pull requests of a repository */
|
|
32
|
+
export declare function GitRepositoryPullRequestsModel(repo: GitRepositoryPointer): Model<NostrEvent[]>;
|
|
33
|
+
/** A model that returns the root patches (the first patch of each series) of a repository */
|
|
34
|
+
export declare function GitRepositoryPatchesModel(repo: GitRepositoryPointer): Model<NostrEvent[]>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { getReplaceableAddressFromPointer } from "applesauce-core/helpers/pointers";
|
|
2
|
+
import { combineLatest, map, of, switchMap } from "rxjs";
|
|
3
|
+
import { COMMENT_KIND, getCommentRootPointer, isValidComment } from "../helpers/comment.js";
|
|
4
|
+
import { GIT_ISSUE_KIND } from "../helpers/git-issue.js";
|
|
5
|
+
import { GIT_PATCH_KIND, getGitPatchPreviousPointer, isGitPatchRoot, isGitPatchRootRevision, isValidGitPatch, } from "../helpers/git-patch.js";
|
|
6
|
+
import { GIT_PULL_REQUEST_KIND, GIT_PULL_REQUEST_UPDATE_KIND, getGitPullRequestUpdateAuthor, getGitPullRequestUpdateTarget, getGitPullRequestState, isValidGitPullRequestUpdate, } from "../helpers/git-pull-request.js";
|
|
7
|
+
import { getGitRepositoryReference } from "../helpers/git-repository.js";
|
|
8
|
+
import { getGitCurrentStatusEvent, getGitStatusType, GIT_STATUS_KINDS, getGitStatusAcceptedRevisionId, getGitStatusAppliedPatchIds, } from "../helpers/git-status.js";
|
|
9
|
+
/** A model that returns the latest authorized status event for an issue, patch or pull request */
|
|
10
|
+
export function GitStatusEventModel(root, maintainers = []) {
|
|
11
|
+
return (store) => store
|
|
12
|
+
.timeline({ kinds: GIT_STATUS_KINDS, "#e": [root.id] })
|
|
13
|
+
.pipe(map((statuses) => getGitCurrentStatusEvent(root, statuses, maintainers)));
|
|
14
|
+
}
|
|
15
|
+
/** A model that returns the current status of an issue, patch or pull request */
|
|
16
|
+
export function GitStatusModel(root, maintainers = []) {
|
|
17
|
+
return (store) => store
|
|
18
|
+
.model(GitStatusEventModel, root, maintainers)
|
|
19
|
+
.pipe(map((status) => (status ? getGitStatusType(status) : "open")));
|
|
20
|
+
}
|
|
21
|
+
/** A model that returns all NIP-22 comments in an issue, patch or pull request thread */
|
|
22
|
+
export function GitThreadCommentsModel(root) {
|
|
23
|
+
return (store) => store.timeline({ kinds: [COMMENT_KIND], "#E": [root.id] }).pipe(map((comments) => comments.filter((event) => {
|
|
24
|
+
if (!isValidComment(event))
|
|
25
|
+
return false;
|
|
26
|
+
const pointer = getCommentRootPointer(event);
|
|
27
|
+
return pointer.type === "event" && pointer.id === root.id && pointer.kind === root.kind;
|
|
28
|
+
})));
|
|
29
|
+
}
|
|
30
|
+
/** A model that returns the updates to a pull request */
|
|
31
|
+
export function GitPullRequestUpdatesModel(pr) {
|
|
32
|
+
return (store) => store
|
|
33
|
+
.timeline({ kinds: [GIT_PULL_REQUEST_UPDATE_KIND], "#E": [pr.id] })
|
|
34
|
+
.pipe(map((updates) => updates.filter((update) => isValidGitPullRequestUpdate(update) &&
|
|
35
|
+
getGitPullRequestUpdateTarget(update) === pr.id &&
|
|
36
|
+
getGitPullRequestUpdateAuthor(update) === pr.pubkey &&
|
|
37
|
+
update.pubkey === pr.pubkey &&
|
|
38
|
+
update.created_at >= pr.created_at)));
|
|
39
|
+
}
|
|
40
|
+
/** A model that returns the latest complete fetch state of a pull request */
|
|
41
|
+
export function GitPullRequestStateModel(pr) {
|
|
42
|
+
return (store) => store.model(GitPullRequestUpdatesModel, pr).pipe(map((updates) => getGitPullRequestState(updates[0] ?? pr)));
|
|
43
|
+
}
|
|
44
|
+
function patchRootModel(patch, original, visited = []) {
|
|
45
|
+
return (store) => {
|
|
46
|
+
if (!isValidGitPatch(patch) || visited.includes(patch.id))
|
|
47
|
+
return of(undefined);
|
|
48
|
+
if (isGitPatchRoot(patch) && (!original || !isGitPatchRootRevision(patch)))
|
|
49
|
+
return of(patch);
|
|
50
|
+
const previous = getGitPatchPreviousPointer(patch);
|
|
51
|
+
if (!previous)
|
|
52
|
+
return of(undefined);
|
|
53
|
+
return store.event(previous).pipe(switchMap((parent) => {
|
|
54
|
+
if (!parent ||
|
|
55
|
+
getGitRepositoryReference(parent)?.pubkey !== getGitRepositoryReference(patch)?.pubkey ||
|
|
56
|
+
getGitRepositoryReference(parent)?.identifier !== getGitRepositoryReference(patch)?.identifier)
|
|
57
|
+
return of(undefined);
|
|
58
|
+
return patchRootModel(parent, original, [...visited, patch.id])(store);
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** A model that resolves the first patch of the current series or revision */
|
|
63
|
+
export function GitPatchSeriesRootModel(patch) {
|
|
64
|
+
return patchRootModel(patch, false);
|
|
65
|
+
}
|
|
66
|
+
/** A model that resolves the original root through patch and revision ancestors */
|
|
67
|
+
export function GitPatchOriginalRootModel(patch) {
|
|
68
|
+
return patchRootModel(patch, true);
|
|
69
|
+
}
|
|
70
|
+
/** A model that returns patches in dependency order within a series, excluding other revisions */
|
|
71
|
+
export function GitPatchSeriesModel(patch) {
|
|
72
|
+
return (store) => store.model(GitPatchSeriesRootModel, patch).pipe(switchMap((root) => {
|
|
73
|
+
const repo = root && getGitRepositoryReference(root);
|
|
74
|
+
if (!root || !repo)
|
|
75
|
+
return of([]);
|
|
76
|
+
return store.timeline({ kinds: [GIT_PATCH_KIND], "#a": [getReplaceableAddressFromPointer(repo)] }).pipe(map((events) => {
|
|
77
|
+
const result = [root];
|
|
78
|
+
const seen = new Set([root.id]);
|
|
79
|
+
let frontier = [root.id];
|
|
80
|
+
while (frontier.length) {
|
|
81
|
+
const next = events
|
|
82
|
+
.filter((event) => isValidGitPatch(event) &&
|
|
83
|
+
!isGitPatchRoot(event) &&
|
|
84
|
+
!seen.has(event.id) &&
|
|
85
|
+
frontier.includes(getGitPatchPreviousPointer(event)?.id ?? ""))
|
|
86
|
+
.sort((a, b) => a.created_at - b.created_at || a.id.localeCompare(b.id));
|
|
87
|
+
result.push(...next);
|
|
88
|
+
frontier = next.map((event) => event.id);
|
|
89
|
+
for (const id of frontier)
|
|
90
|
+
seen.add(id);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}));
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
/** A model that returns revision roots pointing to the original root patch */
|
|
97
|
+
export function GitPatchRevisionsModel(patch) {
|
|
98
|
+
return (store) => store.model(GitPatchOriginalRootModel, patch).pipe(switchMap((root) => {
|
|
99
|
+
if (!root)
|
|
100
|
+
return of([]);
|
|
101
|
+
return store
|
|
102
|
+
.timeline({ kinds: [GIT_PATCH_KIND], "#e": [root.id] })
|
|
103
|
+
.pipe(map((events) => events.filter((event) => isValidGitPatch(event) &&
|
|
104
|
+
isGitPatchRootRevision(event) &&
|
|
105
|
+
getGitPatchPreviousPointer(event)?.id === root.id &&
|
|
106
|
+
getGitRepositoryReference(event)?.pubkey === getGitRepositoryReference(root)?.pubkey &&
|
|
107
|
+
getGitRepositoryReference(event)?.identifier === getGitRepositoryReference(root)?.identifier)));
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
/** A model that returns the original root's latest authorized status event for a patch */
|
|
111
|
+
export function GitPatchStatusEventModel(patch, maintainers = []) {
|
|
112
|
+
return (store) => store
|
|
113
|
+
.model(GitPatchOriginalRootModel, patch)
|
|
114
|
+
.pipe(switchMap((root) => (root ? store.model(GitStatusEventModel, root, maintainers) : of(undefined))));
|
|
115
|
+
}
|
|
116
|
+
/** A model that inherits original status and closes unaccepted revisions after application */
|
|
117
|
+
export function GitPatchStatusModel(patch, maintainers = []) {
|
|
118
|
+
return (store) => combineLatest([
|
|
119
|
+
store.model(GitPatchSeriesRootModel, patch),
|
|
120
|
+
store.model(GitPatchStatusEventModel, patch, maintainers),
|
|
121
|
+
store.model(GitPatchSeriesModel, patch),
|
|
122
|
+
]).pipe(map(([seriesRoot, status, series]) => {
|
|
123
|
+
const type = status ? getGitStatusType(status) : "open";
|
|
124
|
+
if (type !== "applied" || !seriesRoot || !isGitPatchRootRevision(seriesRoot) || !status)
|
|
125
|
+
return type;
|
|
126
|
+
const accepted = getGitStatusAcceptedRevisionId(status);
|
|
127
|
+
const applied = getGitStatusAppliedPatchIds(status);
|
|
128
|
+
return accepted === seriesRoot.id || series.some((event) => applied.includes(event.id)) ? "applied" : "closed";
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
/** A model that returns the issues of a repository */
|
|
132
|
+
export function GitRepositoryIssuesModel(repo) {
|
|
133
|
+
return (store) => store.timeline({ kinds: [GIT_ISSUE_KIND], "#a": [getReplaceableAddressFromPointer(repo)] });
|
|
134
|
+
}
|
|
135
|
+
/** A model that returns the pull requests of a repository */
|
|
136
|
+
export function GitRepositoryPullRequestsModel(repo) {
|
|
137
|
+
return (store) => store.timeline({ kinds: [GIT_PULL_REQUEST_KIND], "#a": [getReplaceableAddressFromPointer(repo)] });
|
|
138
|
+
}
|
|
139
|
+
/** A model that returns the root patches (the first patch of each series) of a repository */
|
|
140
|
+
export function GitRepositoryPatchesModel(repo) {
|
|
141
|
+
return (store) => store
|
|
142
|
+
.timeline({ kinds: [GIT_PATCH_KIND], "#a": [getReplaceableAddressFromPointer(repo)] })
|
|
143
|
+
.pipe(map((patches) => patches.filter(isGitPatchRoot)));
|
|
144
|
+
}
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export * from "./app-handler.js";
|
|
1
2
|
export * from "./blossom.js";
|
|
2
3
|
export * from "./bookmarks.js";
|
|
3
4
|
export * from "./calendar.js";
|
|
4
5
|
export * from "./channels.js";
|
|
5
6
|
export * from "./comments.js";
|
|
7
|
+
export * from "./git.js";
|
|
6
8
|
export * from "./legacy-messages.js";
|
|
7
9
|
export * from "./mutes.js";
|
|
8
10
|
export * from "./pins.js";
|
|
@@ -18,3 +20,5 @@ export * from "./shares.js";
|
|
|
18
20
|
export * from "./zap-goals.js";
|
|
19
21
|
export * from "applesauce-core/models";
|
|
20
22
|
import "./__register__.js";
|
|
23
|
+
export * from "./nsite.js";
|
|
24
|
+
export * from "./napplet-handlers.js";
|
package/dist/models/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export * from "./app-handler.js";
|
|
1
2
|
export * from "./blossom.js";
|
|
2
3
|
export * from "./bookmarks.js";
|
|
3
4
|
export * from "./calendar.js";
|
|
4
5
|
export * from "./channels.js";
|
|
5
6
|
export * from "./comments.js";
|
|
7
|
+
export * from "./git.js";
|
|
6
8
|
export * from "./legacy-messages.js";
|
|
7
9
|
export * from "./mutes.js";
|
|
8
10
|
export * from "./pins.js";
|
|
@@ -20,3 +22,5 @@ export * from "./zap-goals.js";
|
|
|
20
22
|
export * from "applesauce-core/models";
|
|
21
23
|
// Register the common models with the event store
|
|
22
24
|
import "./__register__.js";
|
|
25
|
+
export * from "./nsite.js";
|
|
26
|
+
export * from "./napplet-handlers.js";
|
|
@@ -5,7 +5,12 @@ import { getLegacyMessageCorrespondent, getLegacyMessageParent } from "../helper
|
|
|
5
5
|
import { getConversationIdentifierFromMessage, getConversationParticipants } from "../helpers/messages.js";
|
|
6
6
|
/** A model that returns all legacy message groups (1-1) that a pubkey is participating in */
|
|
7
7
|
export function LegacyMessagesGroups(self) {
|
|
8
|
-
return (store) => store
|
|
8
|
+
return (store) => store
|
|
9
|
+
.timeline([
|
|
10
|
+
{ kinds: [kinds.EncryptedDirectMessage], "#p": [self] },
|
|
11
|
+
{ kinds: [kinds.EncryptedDirectMessage], authors: [self] },
|
|
12
|
+
])
|
|
13
|
+
.pipe(map((messages) => {
|
|
9
14
|
const groups = {};
|
|
10
15
|
for (const message of messages) {
|
|
11
16
|
const id = getConversationIdentifierFromMessage(message);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Model } from "applesauce-core/event-store";
|
|
2
|
+
import { NappletHandlerRef, NappletHandlersEvent } from "../helpers/napplet-handlers.js";
|
|
3
|
+
import { NappletEvent } from "../helpers/napplet.js";
|
|
4
|
+
/** A napplet recommended as a handler, with the authors recommending it */
|
|
5
|
+
export interface RecommendedNappletHandler {
|
|
6
|
+
/** The napplet manifest or pinned snapshot */
|
|
7
|
+
napplet: NappletEvent;
|
|
8
|
+
/** The reference the recommenders used */
|
|
9
|
+
ref: NappletHandlerRef;
|
|
10
|
+
/** The pubkeys of the authors recommending the napplet */
|
|
11
|
+
recommenders: string[];
|
|
12
|
+
}
|
|
13
|
+
/** A model that returns handler preferences for an archetype, optionally from a set of authors */
|
|
14
|
+
export declare function NappletHandlersModel(archetype: string, authors?: string[]): Model<NappletHandlersEvent[]>;
|
|
15
|
+
/** A model that returns the napplets others publicly recommend for an archetype or intent, ranked by recommender count */
|
|
16
|
+
export declare function RecommendedNappletHandlersModel(archetype: string, authors?: string[], identity?: string): Model<RecommendedNappletHandler[]>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { combineLatest, map, of, switchMap } from "rxjs";
|
|
2
|
+
import { getNappletHandlerRefKey, getNappletHandlersFilter, getPublicNappletHandlers, isValidNappletHandlers, } from "../helpers/napplet-handlers.js";
|
|
3
|
+
import { isValidNapplet, isValidNappletSnapshot, nappletSupportsConvention } from "../helpers/napplet.js";
|
|
4
|
+
/** Subscribes to the manifest a handler reference points to, if it is a valid napplet */
|
|
5
|
+
function subscribeHandlerNapplet(store, ref) {
|
|
6
|
+
// A pin must resolve to a snapshot, never to the napplet it derives from
|
|
7
|
+
if (ref.type === "snapshot") {
|
|
8
|
+
return store.event(ref.pointer).pipe(map((event) => (isValidNappletSnapshot(event) ? event : undefined)));
|
|
9
|
+
}
|
|
10
|
+
return store.replaceable(ref.pointer).pipe(map((event) => (isValidNapplet(event) ? event : undefined)));
|
|
11
|
+
}
|
|
12
|
+
/** A model that returns handler preferences for an archetype, optionally from a set of authors */
|
|
13
|
+
export function NappletHandlersModel(archetype, authors) {
|
|
14
|
+
return (store) => store
|
|
15
|
+
.timeline(getNappletHandlersFilter(archetype, authors))
|
|
16
|
+
.pipe(map((events) => events.filter(isValidNappletHandlers)));
|
|
17
|
+
}
|
|
18
|
+
/** A model that returns the napplets others publicly recommend for an archetype or intent, ranked by recommender count */
|
|
19
|
+
export function RecommendedNappletHandlersModel(archetype, authors, identity) {
|
|
20
|
+
return (store) => store.model(NappletHandlersModel, archetype, authors).pipe(switchMap((events) => {
|
|
21
|
+
const ranked = new Map();
|
|
22
|
+
for (const event of events) {
|
|
23
|
+
// Only public entries are recommendations, and they can only suggest a handler
|
|
24
|
+
const entries = getPublicNappletHandlers(event);
|
|
25
|
+
const refs = identity ? [...(entries.intents.get(identity) ?? []), ...entries.handlers] : entries.handlers;
|
|
26
|
+
for (const ref of refs) {
|
|
27
|
+
const key = getNappletHandlerRefKey(ref);
|
|
28
|
+
const entry = ranked.get(key) ?? { ref, recommenders: new Set() };
|
|
29
|
+
entry.recommenders.add(event.pubkey);
|
|
30
|
+
ranked.set(key, entry);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (ranked.size === 0)
|
|
34
|
+
return of([]);
|
|
35
|
+
const sorted = [...ranked.values()].sort((a, b) => b.recommenders.size - a.recommenders.size);
|
|
36
|
+
return combineLatest(sorted.map((entry) => subscribeHandlerNapplet(store, entry.ref))).pipe(map((napplets) => napplets.flatMap((napplet, i) => {
|
|
37
|
+
if (!napplet)
|
|
38
|
+
return [];
|
|
39
|
+
// Skip napplets whose manifest does not advertise the requested convention
|
|
40
|
+
if (identity && !nappletSupportsConvention(napplet, identity))
|
|
41
|
+
return [];
|
|
42
|
+
return [{ napplet, ref: sorted[i].ref, recommenders: [...sorted[i].recommenders] }];
|
|
43
|
+
})));
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Model } from "applesauce-core/event-store";
|
|
2
|
+
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
|
+
import { AddressPointer, EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import { NsiteEvent, NsiteSnapshotEvent, RootNsiteEvent } from "../helpers/nsite.js";
|
|
5
|
+
/** A model that resolves a site or snapshot pointer and validates its manifest */
|
|
6
|
+
export declare function NsiteModel(pointer: AddressPointer | EventPointer | string): Model<NsiteEvent | undefined>;
|
|
7
|
+
/** A model that returns a user's root and named sites */
|
|
8
|
+
export declare function UserNsitesModel(user: string | ProfilePointer): Model<NsiteEvent[]>;
|
|
9
|
+
/** A model that returns a user's root site */
|
|
10
|
+
export declare function RootNsiteModel(user: string | ProfilePointer): Model<RootNsiteEvent | undefined>;
|
|
11
|
+
/** A model that returns a user's manifest snapshots */
|
|
12
|
+
export declare function UserNsiteSnapshotsModel(user: string | ProfilePointer): Model<NsiteSnapshotEvent[]>;
|
|
13
|
+
/** A model that returns snapshots of a specific site */
|
|
14
|
+
export declare function NsiteSnapshotsModel(site: NostrEvent | AddressPointer | string): Model<NsiteSnapshotEvent[]>;
|
|
15
|
+
/** A model that returns sites copied directly from a site */
|
|
16
|
+
export declare function NsiteCopiesModel(site: NostrEvent | AddressPointer | string): Model<NsiteEvent[]>;
|
|
17
|
+
/** A model that returns copied sites and snapshots with a shared lineage origin */
|
|
18
|
+
export declare function NsiteLineageModel(site: NostrEvent | AddressPointer | string): Model<NsiteEvent[]>;
|
|
19
|
+
/** A model that returns manifests belonging to an upstream app descriptor */
|
|
20
|
+
export declare function AppNsitesModel(app: NostrEvent | AddressPointer | string): Model<NsiteEvent[]>;
|
|
21
|
+
/** A model that returns manifests advertising an aggregate hash */
|
|
22
|
+
export declare function NsitesByHashModel(hash: string): Model<NsiteEvent[]>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getReplaceableAddressForEvent, getReplaceableAddressFromPointer, } from "applesauce-core/helpers/pointers";
|
|
2
|
+
import { map } from "rxjs";
|
|
3
|
+
import { isValidNsite, isValidNsiteSnapshot, isValidRootNsite, NSITE_KIND, NSITE_ROOT_KIND, NSITE_SNAPSHOT_KIND, } from "../helpers/nsite.js";
|
|
4
|
+
function coordinate(site) {
|
|
5
|
+
return typeof site === "string"
|
|
6
|
+
? site
|
|
7
|
+
: "id" in site
|
|
8
|
+
? getReplaceableAddressForEvent(site)
|
|
9
|
+
: getReplaceableAddressFromPointer(site);
|
|
10
|
+
}
|
|
11
|
+
/** A model that resolves a site or snapshot pointer and validates its manifest */
|
|
12
|
+
export function NsiteModel(pointer) {
|
|
13
|
+
return (store) => store.event(pointer).pipe(map((event) => (isValidNsite(event) ? event : undefined)));
|
|
14
|
+
}
|
|
15
|
+
/** A model that returns a user's root and named sites */
|
|
16
|
+
export function UserNsitesModel(user) {
|
|
17
|
+
const pubkey = typeof user === "string" ? user : user.pubkey;
|
|
18
|
+
return (store) => store
|
|
19
|
+
.timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND], authors: [pubkey] })
|
|
20
|
+
.pipe(map((events) => events.filter(isValidNsite)));
|
|
21
|
+
}
|
|
22
|
+
/** A model that returns a user's root site */
|
|
23
|
+
export function RootNsiteModel(user) {
|
|
24
|
+
const pointer = typeof user === "string" ? { pubkey: user } : user;
|
|
25
|
+
return (store) => store
|
|
26
|
+
.replaceable({ ...pointer, kind: NSITE_ROOT_KIND })
|
|
27
|
+
.pipe(map((event) => (isValidRootNsite(event) ? event : undefined)));
|
|
28
|
+
}
|
|
29
|
+
/** A model that returns a user's manifest snapshots */
|
|
30
|
+
export function UserNsiteSnapshotsModel(user) {
|
|
31
|
+
const pubkey = typeof user === "string" ? user : user.pubkey;
|
|
32
|
+
return (store) => store
|
|
33
|
+
.timeline({ kinds: [NSITE_SNAPSHOT_KIND], authors: [pubkey] })
|
|
34
|
+
.pipe(map((events) => events.filter(isValidNsiteSnapshot)));
|
|
35
|
+
}
|
|
36
|
+
/** A model that returns snapshots of a specific site */
|
|
37
|
+
export function NsiteSnapshotsModel(site) {
|
|
38
|
+
return (store) => store
|
|
39
|
+
.timeline({ kinds: [NSITE_SNAPSHOT_KIND], "#a": [coordinate(site)] })
|
|
40
|
+
.pipe(map((events) => events.filter(isValidNsiteSnapshot)));
|
|
41
|
+
}
|
|
42
|
+
/** A model that returns sites copied directly from a site */
|
|
43
|
+
export function NsiteCopiesModel(site) {
|
|
44
|
+
return (store) => store
|
|
45
|
+
.timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND], "#a": [coordinate(site)] })
|
|
46
|
+
.pipe(map((events) => events.filter(isValidNsite)));
|
|
47
|
+
}
|
|
48
|
+
/** A model that returns copied sites and snapshots with a shared lineage origin */
|
|
49
|
+
export function NsiteLineageModel(site) {
|
|
50
|
+
return (store) => store
|
|
51
|
+
.timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND, NSITE_SNAPSHOT_KIND], "#A": [coordinate(site)] })
|
|
52
|
+
.pipe(map((events) => events.filter(isValidNsite)));
|
|
53
|
+
}
|
|
54
|
+
/** A model that returns manifests belonging to an upstream app descriptor */
|
|
55
|
+
export function AppNsitesModel(app) {
|
|
56
|
+
const address = coordinate(app);
|
|
57
|
+
// NIP-01 indexes only single-letter tags; app linkage must be filtered locally.
|
|
58
|
+
return (store) => store
|
|
59
|
+
.timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND, NSITE_SNAPSHOT_KIND] })
|
|
60
|
+
.pipe(map((events) => events.filter((event) => isValidNsite(event) && event.tags.some((tag) => tag[0] === "app" && tag[1] === address))));
|
|
61
|
+
}
|
|
62
|
+
/** A model that returns manifests advertising an aggregate hash */
|
|
63
|
+
export function NsitesByHashModel(hash) {
|
|
64
|
+
return (store) => store
|
|
65
|
+
.timeline({ kinds: [NSITE_ROOT_KIND, NSITE_KIND, NSITE_SNAPSHOT_KIND], "#x": [hash] })
|
|
66
|
+
.pipe(map((events) => events.filter(isValidNsite)));
|
|
67
|
+
}
|
package/dist/models/thread.d.ts
CHANGED
|
@@ -19,9 +19,12 @@ export type ThreadItem = {
|
|
|
19
19
|
replies: Set<ThreadItem>;
|
|
20
20
|
};
|
|
21
21
|
export type ThreadModelOptions = {
|
|
22
|
+
/** The NIP-10 reply kinds to include, defaults to kind 1 */
|
|
22
23
|
kinds?: number[];
|
|
24
|
+
/** Whether to include NIP-22 comments, defaults to true */
|
|
25
|
+
comments?: boolean;
|
|
23
26
|
};
|
|
24
|
-
/** A model that returns a NIP-10
|
|
27
|
+
/** A model that returns a thread of NIP-10 replies and NIP-22 comments */
|
|
25
28
|
export declare function ThreadModel(root: string | AddressPointer | EventPointer, opts?: ThreadModelOptions): Model<Thread>;
|
|
26
29
|
/** A model that gets all legacy and NIP-10, and NIP-22 replies for an event */
|
|
27
30
|
export declare function RepliesModel(event: NostrEvent | EventPointer | AddressPointer, overrideKinds?: number[]): Model<NostrEvent[]>;
|
package/dist/models/thread.js
CHANGED
|
@@ -3,39 +3,68 @@ import { buildCommonEventRelationFilters } from "applesauce-core/helpers";
|
|
|
3
3
|
import { getEventUID, kinds } from "applesauce-core/helpers/event";
|
|
4
4
|
import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer, isAddressPointerSame, isEventPointer, isEventPointerSame, } from "applesauce-core/helpers/pointers";
|
|
5
5
|
import { map } from "rxjs/operators";
|
|
6
|
-
import { COMMENT_KIND, getCommentReplyPointer } from "../helpers/comment.js";
|
|
6
|
+
import { COMMENT_KIND, getCommentReplyPointer, getCommentRootPointer } from "../helpers/comment.js";
|
|
7
7
|
import { getNip10References } from "../helpers/threading.js";
|
|
8
8
|
const defaultOptions = {
|
|
9
9
|
kinds: [kinds.ShortTextNote],
|
|
10
|
+
comments: true,
|
|
10
11
|
};
|
|
11
|
-
/**
|
|
12
|
+
/** Converts a NIP-22 comment pointer into a NIP-10 style thread reference */
|
|
13
|
+
function commentPointerToReference(pointer) {
|
|
14
|
+
if (pointer?.type === "event") {
|
|
15
|
+
const { id, kind, pubkey, relay } = pointer;
|
|
16
|
+
return { e: { id, kind, author: pubkey, relays: relay ? [relay] : undefined }, a: undefined };
|
|
17
|
+
}
|
|
18
|
+
if (pointer?.type === "address") {
|
|
19
|
+
const { kind, pubkey, identifier, relay } = pointer;
|
|
20
|
+
return { e: undefined, a: { kind, pubkey, identifier, relays: relay ? [relay] : undefined } };
|
|
21
|
+
}
|
|
22
|
+
// External roots have no event in the thread
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/** Gets the thread references of a NIP-10 reply or a NIP-22 comment */
|
|
26
|
+
function getThreadReferences(event) {
|
|
27
|
+
if (event.kind !== COMMENT_KIND)
|
|
28
|
+
return getNip10References(event);
|
|
29
|
+
return {
|
|
30
|
+
root: commentPointerToReference(getCommentRootPointer(event)),
|
|
31
|
+
reply: commentPointerToReference(getCommentReplyPointer(event)),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** A model that returns a thread of NIP-10 replies and NIP-22 comments */
|
|
12
35
|
export function ThreadModel(root, opts) {
|
|
13
36
|
const parentReferences = new Map();
|
|
14
37
|
const items = new Map();
|
|
15
|
-
const { kinds } = { ...defaultOptions, ...opts };
|
|
38
|
+
const { kinds, comments } = { ...defaultOptions, ...opts };
|
|
16
39
|
let rootUID = "";
|
|
17
40
|
const rootFilter = {};
|
|
18
41
|
const replyFilter = { kinds };
|
|
42
|
+
// NIP-22 comments reference the root with uppercase tags at every depth
|
|
43
|
+
const commentFilter = { kinds: [COMMENT_KIND] };
|
|
19
44
|
if (isAddressPointer(root)) {
|
|
20
45
|
rootUID = getReplaceableAddressFromPointer(root);
|
|
21
46
|
rootFilter.kinds = [root.kind];
|
|
22
47
|
rootFilter.authors = [root.pubkey];
|
|
23
48
|
rootFilter["#d"] = [root.identifier];
|
|
24
49
|
replyFilter["#a"] = [rootUID];
|
|
50
|
+
commentFilter["#A"] = [rootUID];
|
|
25
51
|
}
|
|
26
52
|
else if (typeof root === "string") {
|
|
27
53
|
rootUID = root;
|
|
28
54
|
rootFilter.ids = [root];
|
|
29
55
|
replyFilter["#e"] = [root];
|
|
56
|
+
commentFilter["#E"] = [root];
|
|
30
57
|
}
|
|
31
58
|
else {
|
|
32
59
|
rootUID = root.id;
|
|
33
60
|
rootFilter.ids = [root.id];
|
|
34
61
|
replyFilter["#e"] = [root.id];
|
|
62
|
+
commentFilter["#E"] = [root.id];
|
|
35
63
|
}
|
|
36
|
-
|
|
64
|
+
const filters = comments ? [rootFilter, replyFilter, commentFilter] : [rootFilter, replyFilter];
|
|
65
|
+
return (events) => events.filters(filters).pipe(map((event) => {
|
|
37
66
|
if (!items.has(getEventUID(event))) {
|
|
38
|
-
const refs =
|
|
67
|
+
const refs = getThreadReferences(event);
|
|
39
68
|
const replies = parentReferences.get(getEventUID(event)) || new Set();
|
|
40
69
|
const item = { event, refs, replies };
|
|
41
70
|
for (const child of replies) {
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Model } from "applesauce-core/event-store";
|
|
2
2
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
3
3
|
import { UserStatusPointer } from "../helpers/user-status.js";
|
|
4
|
-
|
|
4
|
+
/** A parsed user status, the pointer fields are only set when the status links to something */
|
|
5
|
+
export type UserStatus = (UserStatusPointer | {
|
|
6
|
+
type?: undefined;
|
|
7
|
+
data?: undefined;
|
|
8
|
+
}) & {
|
|
5
9
|
event: NostrEvent;
|
|
6
10
|
content: string;
|
|
7
11
|
};
|
|
8
|
-
/** A model that returns a parsed {@link UserStatus} for a certain type */
|
|
9
|
-
export declare function UserStatusModel(pubkey: string, type?: string): Model<UserStatus | undefined
|
|
10
|
-
/** A model that returns a directory of parsed {@link UserStatus} for a pubkey */
|
|
12
|
+
/** A model that returns a parsed {@link UserStatus} for a certain type, or undefined when missing or cleared */
|
|
13
|
+
export declare function UserStatusModel(pubkey: string, type?: string): Model<UserStatus | undefined>;
|
|
14
|
+
/** A model that returns a directory of parsed {@link UserStatus} for a pubkey, excluding cleared statuses */
|
|
11
15
|
export declare function UserStatusesModel(pubkey: string): Model<Record<string, UserStatus>>;
|