applesauce-core 0.0.0-next-20250128165956 → 0.0.0-next-20250128182541

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.
@@ -1,3 +1,4 @@
1
+ import { NostrEvent } from "nostr-tools";
1
2
  export declare const GROUPS_LIST_KIND = 10009;
2
3
  export declare const GROUP_MESSAGE_KIND = 9;
3
4
  /** NIP-29 group pointer */
@@ -13,3 +14,11 @@ export type GroupPointer = {
13
14
  export declare function decodeGroupPointer(str: string): GroupPointer;
14
15
  /** Converts a group pointer into a group identifier */
15
16
  export declare function encodeGroupPointer(pointer: GroupPointer): string;
17
+ export declare const GroupsPublicSymbol: unique symbol;
18
+ export declare const GroupsHiddenSymbol: unique symbol;
19
+ /** gets a {@link GroupPointer} from a "group" tag */
20
+ export declare function getGroupPointerFromGroupTag(tag: string[]): GroupPointer;
21
+ /** Returns all the public groups from a k:10009 list */
22
+ export declare function getPublicGroups(bookmark: NostrEvent): GroupPointer[];
23
+ /** Returns all the hidden groups from a k:10009 list */
24
+ export declare function getHiddenGroups(bookmark: NostrEvent): GroupPointer[] | undefined;
@@ -1,3 +1,6 @@
1
+ import { getOrComputeCachedValue } from "./cache.js";
2
+ import { processTags } from "./tags.js";
3
+ import { getHiddenTags } from "./hidden-tags.js";
1
4
  export const GROUPS_LIST_KIND = 10009;
2
5
  export const GROUP_MESSAGE_KIND = 9;
3
6
  /**
@@ -15,3 +18,22 @@ export function encodeGroupPointer(pointer) {
15
18
  const hostname = URL.canParse(pointer.relay) ? new URL(pointer.relay).hostname : pointer.relay;
16
19
  return `${hostname}'${pointer.id}`;
17
20
  }
21
+ export const GroupsPublicSymbol = Symbol.for("groups-public");
22
+ export const GroupsHiddenSymbol = Symbol.for("groups-hidden");
23
+ /** gets a {@link GroupPointer} from a "group" tag */
24
+ export function getGroupPointerFromGroupTag(tag) {
25
+ const [_, id, relay, name] = tag;
26
+ return { id, relay, name };
27
+ }
28
+ /** Returns all the public groups from a k:10009 list */
29
+ export function getPublicGroups(bookmark) {
30
+ return getOrComputeCachedValue(bookmark, GroupsPublicSymbol, () => processTags(bookmark.tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag));
31
+ }
32
+ /** Returns all the hidden groups from a k:10009 list */
33
+ export function getHiddenGroups(bookmark) {
34
+ return getOrComputeCachedValue(bookmark, GroupsHiddenSymbol, () => {
35
+ const tags = getHiddenTags(bookmark);
36
+ return (tags &&
37
+ processTags(bookmark.tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag));
38
+ });
39
+ }
@@ -15,6 +15,7 @@ export * from "./groups.js";
15
15
  export * from "./hashtag.js";
16
16
  export * from "./hidden-tags.js";
17
17
  export * from "./json.js";
18
+ export * from "./lists.js";
18
19
  export * from "./lnurl.js";
19
20
  export * from "./lru.js";
20
21
  export * from "./mailboxes.js";
@@ -15,6 +15,7 @@ export * from "./groups.js";
15
15
  export * from "./hashtag.js";
16
16
  export * from "./hidden-tags.js";
17
17
  export * from "./json.js";
18
+ export * from "./lists.js";
18
19
  export * from "./lnurl.js";
19
20
  export * from "./lru.js";
20
21
  export * from "./mailboxes.js";
@@ -0,0 +1,28 @@
1
+ import { AddressPointer, EventPointer, ProfilePointer } from "nostr-tools/nip19";
2
+ import { NostrEvent } from "nostr-tools";
3
+ /**
4
+ * Checks if an event pointer is anywhere in a list or set
5
+ * NOTE: Ignores the `relay` field in EventPointer
6
+ * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
7
+ */
8
+ export declare function isEventPointerInList(list: NostrEvent, pointer: string | EventPointer): boolean;
9
+ /**
10
+ * Checks if an address pointer is anywhere in a list or set
11
+ * NOTE: Ignores the `relay` field in AddressPointer
12
+ * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
13
+ */
14
+ export declare function isAddressPointerInList(list: NostrEvent, pointer: string | AddressPointer): boolean;
15
+ /**
16
+ * Checks if an profile pointer is anywhere in a list or set
17
+ * NOTE: Ignores the `relay` field in ProfilePointer
18
+ * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
19
+ */
20
+ export declare function isProfilePointerInList(list: NostrEvent, pointer: string | ProfilePointer): boolean;
21
+ /** Returns all the EventPointer in a list or set */
22
+ export declare function getEventPointersFromList(list: NostrEvent): EventPointer[];
23
+ /** Returns all the AddressPointer in a list or set */
24
+ export declare function getAddressPointersFromList(list: NostrEvent): AddressPointer[];
25
+ /** Returns all the ProfilePointer in a list or set */
26
+ export declare function getProfilePointersFromList(list: NostrEvent): ProfilePointer[];
27
+ /** Returns if an event is a valid list or set */
28
+ export declare function isValidList(event: NostrEvent): boolean;
@@ -0,0 +1,65 @@
1
+ import { isParameterizedReplaceableKind, isReplaceableKind } from "nostr-tools/kinds";
2
+ import { getHiddenTags } from "./hidden-tags.js";
3
+ import { getAddressPointerFromATag, getCoordinateFromAddressPointer, getEventPointerFromETag, getProfilePointerFromPTag, } from "./pointers.js";
4
+ import { isATag, isETag, isPTag, processTags } from "./tags.js";
5
+ import { getReplaceableIdentifier } from "./event.js";
6
+ function listGetAllTags(list) {
7
+ const hidden = getHiddenTags(list);
8
+ return hidden ? [...hidden, ...list.tags] : list.tags;
9
+ }
10
+ /**
11
+ * Checks if an event pointer is anywhere in a list or set
12
+ * NOTE: Ignores the `relay` field in EventPointer
13
+ * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
14
+ */
15
+ export function isEventPointerInList(list, pointer) {
16
+ const id = typeof pointer === "string" ? pointer : pointer.id;
17
+ return listGetAllTags(list).some((t) => t[0] === "e" && t[1] === id);
18
+ }
19
+ /**
20
+ * Checks if an address pointer is anywhere in a list or set
21
+ * NOTE: Ignores the `relay` field in AddressPointer
22
+ * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
23
+ */
24
+ export function isAddressPointerInList(list, pointer) {
25
+ const cord = typeof pointer === "string" ? pointer : getCoordinateFromAddressPointer(pointer);
26
+ return listGetAllTags(list).some((t) => t[0] === "a" && t[1] === cord);
27
+ }
28
+ /**
29
+ * Checks if an profile pointer is anywhere in a list or set
30
+ * NOTE: Ignores the `relay` field in ProfilePointer
31
+ * NOTE: This will check the hidden tags if the list has hidden tags and they are unlocked
32
+ */
33
+ export function isProfilePointerInList(list, pointer) {
34
+ const pubkey = typeof pointer === "string" ? pointer : pointer.pubkey;
35
+ return listGetAllTags(list).some((t) => t[0] === "p" && t[1] === pubkey);
36
+ }
37
+ /** Returns all the EventPointer in a list or set */
38
+ export function getEventPointersFromList(list) {
39
+ return processTags(listGetAllTags(list), (tag) => (isETag(tag) ? tag : undefined), getEventPointerFromETag);
40
+ }
41
+ /** Returns all the AddressPointer in a list or set */
42
+ export function getAddressPointersFromList(list) {
43
+ return processTags(listGetAllTags(list), (t) => (isATag(t) ? t : undefined), getAddressPointerFromATag);
44
+ }
45
+ /** Returns all the ProfilePointer in a list or set */
46
+ export function getProfilePointersFromList(list) {
47
+ return processTags(listGetAllTags(list), (t) => (isPTag(t) ? t : undefined), getProfilePointerFromPTag);
48
+ }
49
+ /** Returns if an event is a valid list or set */
50
+ export function isValidList(event) {
51
+ try {
52
+ if (isParameterizedReplaceableKind(event.kind)) {
53
+ // event is a set
54
+ // ensure the set has an identifier
55
+ getReplaceableIdentifier(event);
56
+ return true;
57
+ }
58
+ else if (isReplaceableKind(event.kind) && event.kind >= 10000 && event.kind < 20000) {
59
+ // event is a list
60
+ return true;
61
+ }
62
+ }
63
+ catch (error) { }
64
+ return false;
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20250128165956",
3
+ "version": "0.0.0-next-20250128182541",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",