applesauce-core 0.0.0-next-20250128165956 → 0.0.0-next-20250128171228
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/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/lists.d.ts +28 -0
- package/dist/helpers/lists.js +65 -0
- package/package.json +1 -1
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -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
|
+
}
|