applesauce-core 0.0.0-next-20250128171228 → 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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20250128171228",
3
+ "version": "0.0.0-next-20250128182541",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",