applesauce-core 0.0.0-next-20250120191411 → 0.0.0-next-20250123205825

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.
Files changed (115) hide show
  1. package/package.json +1 -1
  2. package/dist/event-store/common.d.ts +0 -1
  3. package/dist/event-store/common.js +0 -2
  4. package/dist/event-store/database.d.ts +0 -64
  5. package/dist/event-store/database.js +0 -311
  6. package/dist/event-store/event-store.d.ts +0 -49
  7. package/dist/event-store/event-store.js +0 -389
  8. package/dist/event-store/index.d.ts +0 -2
  9. package/dist/event-store/index.js +0 -2
  10. package/dist/helpers/bolt11.d.ts +0 -9
  11. package/dist/helpers/bolt11.js +0 -15
  12. package/dist/helpers/cache.d.ts +0 -5
  13. package/dist/helpers/cache.js +0 -17
  14. package/dist/helpers/comment.d.ts +0 -47
  15. package/dist/helpers/comment.js +0 -116
  16. package/dist/helpers/content.d.ts +0 -3
  17. package/dist/helpers/content.js +0 -8
  18. package/dist/helpers/delete.d.ts +0 -3
  19. package/dist/helpers/delete.js +0 -7
  20. package/dist/helpers/emoji.d.ts +0 -11
  21. package/dist/helpers/emoji.js +0 -16
  22. package/dist/helpers/event.d.ts +0 -48
  23. package/dist/helpers/event.js +0 -105
  24. package/dist/helpers/external-id.d.ts +0 -29
  25. package/dist/helpers/external-id.js +0 -20
  26. package/dist/helpers/file-metadata.d.ts +0 -53
  27. package/dist/helpers/file-metadata.js +0 -90
  28. package/dist/helpers/file-metadata.test.d.ts +0 -1
  29. package/dist/helpers/file-metadata.test.js +0 -103
  30. package/dist/helpers/filter.d.ts +0 -10
  31. package/dist/helpers/filter.js +0 -46
  32. package/dist/helpers/hashtag.d.ts +0 -2
  33. package/dist/helpers/hashtag.js +0 -7
  34. package/dist/helpers/hidden-tags.d.ts +0 -48
  35. package/dist/helpers/hidden-tags.js +0 -108
  36. package/dist/helpers/hidden-tags.test.d.ts +0 -1
  37. package/dist/helpers/hidden-tags.test.js +0 -28
  38. package/dist/helpers/index.d.ts +0 -26
  39. package/dist/helpers/index.js +0 -26
  40. package/dist/helpers/json.d.ts +0 -2
  41. package/dist/helpers/json.js +0 -9
  42. package/dist/helpers/lnurl.d.ts +0 -4
  43. package/dist/helpers/lnurl.js +0 -40
  44. package/dist/helpers/lru.d.ts +0 -32
  45. package/dist/helpers/lru.js +0 -148
  46. package/dist/helpers/mailboxes.d.ts +0 -11
  47. package/dist/helpers/mailboxes.js +0 -36
  48. package/dist/helpers/mailboxes.test.d.ts +0 -1
  49. package/dist/helpers/mailboxes.test.js +0 -81
  50. package/dist/helpers/media-attachment.d.ts +0 -42
  51. package/dist/helpers/media-attachment.js +0 -72
  52. package/dist/helpers/media-attachment.test.d.ts +0 -1
  53. package/dist/helpers/media-attachment.test.js +0 -59
  54. package/dist/helpers/media-post.d.ts +0 -4
  55. package/dist/helpers/media-post.js +0 -6
  56. package/dist/helpers/picture-post.d.ts +0 -4
  57. package/dist/helpers/picture-post.js +0 -6
  58. package/dist/helpers/pipe.d.ts +0 -10
  59. package/dist/helpers/pipe.js +0 -3
  60. package/dist/helpers/pointers.d.ts +0 -55
  61. package/dist/helpers/pointers.js +0 -205
  62. package/dist/helpers/profile.d.ts +0 -20
  63. package/dist/helpers/profile.js +0 -31
  64. package/dist/helpers/relays.d.ts +0 -12
  65. package/dist/helpers/relays.js +0 -31
  66. package/dist/helpers/string.d.ts +0 -10
  67. package/dist/helpers/string.js +0 -15
  68. package/dist/helpers/tags.d.ts +0 -25
  69. package/dist/helpers/tags.js +0 -42
  70. package/dist/helpers/tags.test.d.ts +0 -1
  71. package/dist/helpers/tags.test.js +0 -16
  72. package/dist/helpers/threading.d.ts +0 -55
  73. package/dist/helpers/threading.js +0 -94
  74. package/dist/helpers/threading.test.d.ts +0 -1
  75. package/dist/helpers/threading.test.js +0 -41
  76. package/dist/helpers/time.d.ts +0 -2
  77. package/dist/helpers/time.js +0 -4
  78. package/dist/helpers/url.d.ts +0 -14
  79. package/dist/helpers/url.js +0 -30
  80. package/dist/helpers/zap.d.ts +0 -39
  81. package/dist/helpers/zap.js +0 -95
  82. package/dist/index.d.ts +0 -5
  83. package/dist/index.js +0 -5
  84. package/dist/logger.d.ts +0 -2
  85. package/dist/logger.js +0 -2
  86. package/dist/observable/get-value.d.ts +0 -3
  87. package/dist/observable/get-value.js +0 -14
  88. package/dist/observable/index.d.ts +0 -2
  89. package/dist/observable/index.js +0 -2
  90. package/dist/observable/share-latest-value.d.ts +0 -8
  91. package/dist/observable/share-latest-value.js +0 -21
  92. package/dist/promise/deferred.d.ts +0 -6
  93. package/dist/promise/deferred.js +0 -15
  94. package/dist/promise/index.d.ts +0 -1
  95. package/dist/promise/index.js +0 -1
  96. package/dist/queries/comment.d.ts +0 -4
  97. package/dist/queries/comment.js +0 -14
  98. package/dist/queries/comments.d.ts +0 -4
  99. package/dist/queries/comments.js +0 -14
  100. package/dist/queries/index.d.ts +0 -7
  101. package/dist/queries/index.js +0 -7
  102. package/dist/queries/mailboxes.d.ts +0 -6
  103. package/dist/queries/mailboxes.js +0 -13
  104. package/dist/queries/profile.d.ts +0 -4
  105. package/dist/queries/profile.js +0 -12
  106. package/dist/queries/reactions.d.ts +0 -4
  107. package/dist/queries/reactions.js +0 -19
  108. package/dist/queries/simple.d.ts +0 -16
  109. package/dist/queries/simple.js +0 -38
  110. package/dist/queries/thread.d.ts +0 -25
  111. package/dist/queries/thread.js +0 -92
  112. package/dist/queries/zaps.d.ts +0 -5
  113. package/dist/queries/zaps.js +0 -21
  114. package/dist/query-store/index.d.ts +0 -57
  115. package/dist/query-store/index.js +0 -68
@@ -1,72 +0,0 @@
1
- import { getOrComputeCachedValue } from "./cache.js";
2
- /**
3
- * Parses a imeta tag into a {@link MediaAttachment}
4
- * @throws
5
- */
6
- export function parseMediaAttachmentTag(tag) {
7
- const parts = tag.slice(1);
8
- const fields = {};
9
- let fallback = undefined;
10
- for (const part of parts) {
11
- const match = part.match(/^(.+?)\s(.+)$/);
12
- if (match) {
13
- const [_, name, value] = match;
14
- switch (name) {
15
- case "fallback":
16
- fallback = fallback ? [...fallback, value] : [value];
17
- break;
18
- default:
19
- fields[name] = value;
20
- break;
21
- }
22
- }
23
- }
24
- if (!fields.url)
25
- throw new Error("Missing required url in attachment");
26
- const attachment = { url: fields.url, fallback };
27
- // parse size
28
- if (fields.size)
29
- attachment.size = parseInt(fields.size);
30
- // copy optional fields
31
- if (fields.m)
32
- attachment.type = fields.m;
33
- if (fields.x)
34
- attachment.sha256 = fields.x;
35
- if (fields.ox)
36
- attachment.originalSha256 = fields.ox;
37
- if (fields.dim)
38
- attachment.dimensions = fields.dim;
39
- if (fields.magnet)
40
- attachment.magnet = fields.magnet;
41
- if (fields.i)
42
- attachment.infohash = fields.i;
43
- if (fields.thumb)
44
- attachment.thumbnail = fields.thumb;
45
- if (fields.image)
46
- attachment.image = fields.image;
47
- if (fields.summary)
48
- attachment.summary = fields.summary;
49
- if (fields.alt)
50
- attachment.alt = fields.alt;
51
- if (fields.blurhash)
52
- attachment.blurhash = fields.blurhash;
53
- return attachment;
54
- }
55
- export const MediaAttachmentsSymbol = Symbol.for("media-attachments");
56
- /** Gets all the media attachments on an event */
57
- export function getMediaAttachments(event) {
58
- return getOrComputeCachedValue(event, MediaAttachmentsSymbol, () => {
59
- return event.tags
60
- .filter((t) => t[0] === "imeta")
61
- .map((tag) => {
62
- try {
63
- return parseMediaAttachmentTag(tag);
64
- }
65
- catch (error) {
66
- // ignore invalid attachments
67
- return undefined;
68
- }
69
- })
70
- .filter((a) => !!a);
71
- });
72
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { parseMediaAttachmentTag } from "./media-attachment.js";
3
- describe("media attachment helpers", () => {
4
- describe("parseMediaAttachmentTag", () => {
5
- it("should parse simple imeta tag", () => {
6
- expect(parseMediaAttachmentTag([
7
- "imeta",
8
- "url https://blossom.primal.net/3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c.jpg",
9
- "x 3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c",
10
- "dim 1024x1024",
11
- "m image/jpeg",
12
- "blurhash ggH{Aws:RPWBRjaeay?^ozV@aeRjaej[$gt7kCofWVofkCrrofxuofa|ozbHx]s:tRofaet7ay",
13
- ])).toEqual({
14
- url: "https://blossom.primal.net/3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c.jpg",
15
- sha256: "3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c",
16
- dimensions: "1024x1024",
17
- type: "image/jpeg",
18
- blurhash: "ggH{Aws:RPWBRjaeay?^ozV@aeRjaej[$gt7kCofWVofkCrrofxuofa|ozbHx]s:tRofaet7ay",
19
- });
20
- });
21
- it("should parse thumbnail url", () => {
22
- expect(parseMediaAttachmentTag([
23
- "imeta",
24
- "url https://blossom.primal.net/3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c.jpg",
25
- "x 3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c",
26
- "dim 1024x1024",
27
- "m image/jpeg",
28
- "blurhash ggH{Aws:RPWBRjaeay?^ozV@aeRjaej[$gt7kCofWVofkCrrofxuofa|ozbHx]s:tRofaet7ay",
29
- "thumb https://exmaple.com/thumb.jpg",
30
- ])).toEqual({
31
- url: "https://blossom.primal.net/3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c.jpg",
32
- sha256: "3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c",
33
- dimensions: "1024x1024",
34
- type: "image/jpeg",
35
- blurhash: "ggH{Aws:RPWBRjaeay?^ozV@aeRjaej[$gt7kCofWVofkCrrofxuofa|ozbHx]s:tRofaet7ay",
36
- thumbnail: "https://exmaple.com/thumb.jpg",
37
- });
38
- });
39
- it("should parse multiple fallback urls", () => {
40
- expect(parseMediaAttachmentTag([
41
- "imeta",
42
- "url https://blossom.primal.net/3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c.jpg",
43
- "x 3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c",
44
- "dim 1024x1024",
45
- "m image/jpeg",
46
- "blurhash ggH{Aws:RPWBRjaeay?^ozV@aeRjaej[$gt7kCofWVofkCrrofxuofa|ozbHx]s:tRofaet7ay",
47
- "fallback https://exmaple.com/image2.jpg",
48
- "fallback https://exmaple.com/image3.jpg",
49
- ])).toEqual({
50
- url: "https://blossom.primal.net/3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c.jpg",
51
- sha256: "3f4dbf2797ac4e90b00bcfe2728e5c8367ed909c48230ac454cc325f1993646c",
52
- dimensions: "1024x1024",
53
- type: "image/jpeg",
54
- blurhash: "ggH{Aws:RPWBRjaeay?^ozV@aeRjaej[$gt7kCofWVofkCrrofxuofa|ozbHx]s:tRofaet7ay",
55
- fallback: ["https://exmaple.com/image2.jpg", "https://exmaple.com/image3.jpg"],
56
- });
57
- });
58
- });
59
- });
@@ -1,4 +0,0 @@
1
- import { NostrEvent } from "nostr-tools";
2
- export declare const MEDIA_POST_KIND = 20;
3
- /** Return the media attachments from a kind 20 media post */
4
- export declare function getMediaPostAttachments(post: NostrEvent): import("./file-metadata.js").FileMetadata[];
@@ -1,6 +0,0 @@
1
- import { getMediaAttachments } from "./file-metadata.js";
2
- export const MEDIA_POST_KIND = 20;
3
- /** Return the media attachments from a kind 20 media post */
4
- export function getMediaPostAttachments(post) {
5
- return getMediaAttachments(post);
6
- }
@@ -1,4 +0,0 @@
1
- import { NostrEvent } from "nostr-tools";
2
- export declare const PICTURE_POST_KIND = 20;
3
- /** Return the media attachments from a kind 20 media post */
4
- export declare function getPicturePostAttachments(post: NostrEvent): import("./file-metadata.js").FileMetadata[];
@@ -1,6 +0,0 @@
1
- import { getMediaAttachments } from "./file-metadata.js";
2
- export const PICTURE_POST_KIND = 20;
3
- /** Return the media attachments from a kind 20 media post */
4
- export function getPicturePostAttachments(post) {
5
- return getMediaAttachments(post);
6
- }
@@ -1,10 +0,0 @@
1
- export type Pipe = {
2
- <A>(a: A): A;
3
- <A, B>(a: A, ab: (a: A) => B): B;
4
- <A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C;
5
- <A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D;
6
- <A, B, C, D, E>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E;
7
- <A, B, C, D, E, F>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F;
8
- <A, B, C, D, E, F, G>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): G;
9
- };
10
- export declare const pipe: Pipe;
@@ -1,3 +0,0 @@
1
- export const pipe = (initial, ...fns) => {
2
- return fns.reduce((acc, fn) => fn(acc), initial);
3
- };
@@ -1,55 +0,0 @@
1
- import { AddressPointer, DecodeResult, EventPointer, ProfilePointer } from "nostr-tools/nip19";
2
- import { NostrEvent } from "nostr-tools";
3
- export type AddressPointerWithoutD = Omit<AddressPointer, "identifier"> & {
4
- identifier?: string;
5
- };
6
- /** Parse the value of an "a" tag into an AddressPointer */
7
- export declare function parseCoordinate(a: string): AddressPointerWithoutD | null;
8
- export declare function parseCoordinate(a: string, requireD: false): AddressPointerWithoutD | null;
9
- export declare function parseCoordinate(a: string, requireD: true): AddressPointer | null;
10
- export declare function parseCoordinate(a: string, requireD: false, silent: false): AddressPointerWithoutD;
11
- export declare function parseCoordinate(a: string, requireD: true, silent: false): AddressPointer;
12
- export declare function parseCoordinate(a: string, requireD: true, silent: true): AddressPointer | null;
13
- export declare function parseCoordinate(a: string, requireD: false, silent: true): AddressPointerWithoutD | null;
14
- /** Extra a pubkey from the result of nip19.decode */
15
- export declare function getPubkeyFromDecodeResult(result?: DecodeResult): string | undefined;
16
- /** Encodes the result of nip19.decode */
17
- export declare function encodeDecodeResult(result: DecodeResult): "" | `nprofile1${string}` | `nevent1${string}` | `naddr1${string}` | `nsec1${string}` | `npub1${string}` | `note1${string}`;
18
- /**
19
- * Gets an EventPointer form a common "e" tag
20
- * @throws
21
- */
22
- export declare function getEventPointerFromETag(tag: string[]): EventPointer;
23
- /**
24
- * Gets an EventPointer form a "q" tag
25
- * @throws
26
- */
27
- export declare function getEventPointerFromQTag(tag: string[]): EventPointer;
28
- /**
29
- * Get an AddressPointer from an "a" tag
30
- * @throws
31
- */
32
- export declare function getAddressPointerFromATag(tag: string[]): AddressPointer;
33
- /**
34
- * Gets a ProfilePointer from a "p" tag
35
- * @throws
36
- */
37
- export declare function getProfilePointerFromPTag(tag: string[]): ProfilePointer;
38
- /** Parses "e", "a", "p", and "q" tags into a pointer */
39
- export declare function getPointerFromTag(tag: string[]): DecodeResult | null;
40
- export declare function isAddressPointer(pointer: DecodeResult["data"]): pointer is AddressPointer;
41
- export declare function isEventPointer(pointer: DecodeResult["data"]): pointer is EventPointer;
42
- /** Returns the coordinate string for an AddressPointer */
43
- export declare function getCoordinateFromAddressPointer(pointer: AddressPointer): string;
44
- /**
45
- * Returns an AddressPointer for a replaceable event
46
- * @throws
47
- */
48
- export declare function getAddressPointerForEvent(event: NostrEvent, relays?: string[]): AddressPointer;
49
- /**
50
- * Returns an EventPointer for an event
51
- * @throws
52
- */
53
- export declare function getEventPointerForEvent(event: NostrEvent, relays?: string[]): EventPointer;
54
- /** Returns a pointer for a given event */
55
- export declare function getPointerForEvent(event: NostrEvent, relays?: string[]): DecodeResult;
@@ -1,205 +0,0 @@
1
- import { naddrEncode, neventEncode, noteEncode, nprofileEncode, npubEncode, nsecEncode, } from "nostr-tools/nip19";
2
- import { getPublicKey, kinds } from "nostr-tools";
3
- import { getReplaceableIdentifier } from "./event.js";
4
- import { safeRelayUrls } from "./relays.js";
5
- import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
6
- export function parseCoordinate(a, requireD = false, silent = true) {
7
- const parts = a.split(":");
8
- const kind = parts[0] && parseInt(parts[0]);
9
- const pubkey = parts[1];
10
- const d = parts[2];
11
- if (!kind) {
12
- if (silent)
13
- return null;
14
- else
15
- throw new Error("Missing kind");
16
- }
17
- if (!pubkey) {
18
- if (silent)
19
- return null;
20
- else
21
- throw new Error("Missing pubkey");
22
- }
23
- if (requireD && d === undefined) {
24
- if (silent)
25
- return null;
26
- else
27
- throw new Error("Missing identifier");
28
- }
29
- return {
30
- kind,
31
- pubkey,
32
- identifier: d,
33
- };
34
- }
35
- /** Extra a pubkey from the result of nip19.decode */
36
- export function getPubkeyFromDecodeResult(result) {
37
- if (!result)
38
- return;
39
- switch (result.type) {
40
- case "naddr":
41
- case "nprofile":
42
- return result.data.pubkey;
43
- case "npub":
44
- return result.data;
45
- case "nsec":
46
- return getPublicKey(result.data);
47
- default:
48
- return undefined;
49
- }
50
- }
51
- /** Encodes the result of nip19.decode */
52
- export function encodeDecodeResult(result) {
53
- switch (result.type) {
54
- case "naddr":
55
- return naddrEncode(result.data);
56
- case "nprofile":
57
- return nprofileEncode(result.data);
58
- case "nevent":
59
- return neventEncode(result.data);
60
- case "nsec":
61
- return nsecEncode(result.data);
62
- case "npub":
63
- return npubEncode(result.data);
64
- case "note":
65
- return noteEncode(result.data);
66
- }
67
- return "";
68
- }
69
- /**
70
- * Gets an EventPointer form a common "e" tag
71
- * @throws
72
- */
73
- export function getEventPointerFromETag(tag) {
74
- if (!tag[1])
75
- throw new Error("Missing event id in tag");
76
- let pointer = { id: tag[1] };
77
- if (tag[2])
78
- pointer.relays = safeRelayUrls([tag[2]]);
79
- return pointer;
80
- }
81
- /**
82
- * Gets an EventPointer form a "q" tag
83
- * @throws
84
- */
85
- export function getEventPointerFromQTag(tag) {
86
- if (!tag[1])
87
- throw new Error("Missing event id in tag");
88
- let pointer = { id: tag[1] };
89
- if (tag[2])
90
- pointer.relays = safeRelayUrls([tag[2]]);
91
- if (tag[3] && tag[3].length === 64)
92
- pointer.author = tag[3];
93
- return pointer;
94
- }
95
- /**
96
- * Get an AddressPointer from an "a" tag
97
- * @throws
98
- */
99
- export function getAddressPointerFromATag(tag) {
100
- if (!tag[1])
101
- throw new Error("Missing coordinate in tag");
102
- const pointer = parseCoordinate(tag[1], true, false);
103
- if (tag[2])
104
- pointer.relays = safeRelayUrls([tag[2]]);
105
- return pointer;
106
- }
107
- /**
108
- * Gets a ProfilePointer from a "p" tag
109
- * @throws
110
- */
111
- export function getProfilePointerFromPTag(tag) {
112
- if (!tag[1])
113
- throw new Error("Missing pubkey in tag");
114
- const pointer = { pubkey: tag[1] };
115
- if (tag[2])
116
- pointer.relays = safeRelayUrls([tag[2]]);
117
- return pointer;
118
- }
119
- /** Parses "e", "a", "p", and "q" tags into a pointer */
120
- export function getPointerFromTag(tag) {
121
- try {
122
- switch (tag[0]) {
123
- case "e":
124
- return { type: "nevent", data: getEventPointerFromETag(tag) };
125
- case "a":
126
- return {
127
- type: "naddr",
128
- data: getAddressPointerFromATag(tag),
129
- };
130
- case "p":
131
- return { type: "nprofile", data: getProfilePointerFromPTag(tag) };
132
- // NIP-18 quote tags
133
- case "q":
134
- return { type: "nevent", data: getEventPointerFromETag(tag) };
135
- }
136
- }
137
- catch (error) { }
138
- return null;
139
- }
140
- export function isAddressPointer(pointer) {
141
- return (typeof pointer !== "string" &&
142
- Reflect.has(pointer, "identifier") &&
143
- Reflect.has(pointer, "pubkey") &&
144
- Reflect.has(pointer, "kind"));
145
- }
146
- export function isEventPointer(pointer) {
147
- return typeof pointer !== "string" && Reflect.has(pointer, "id");
148
- }
149
- /** Returns the coordinate string for an AddressPointer */
150
- export function getCoordinateFromAddressPointer(pointer) {
151
- return `${pointer.kind}:${pointer.pubkey}:${pointer.identifier}`;
152
- }
153
- /**
154
- * Returns an AddressPointer for a replaceable event
155
- * @throws
156
- */
157
- export function getAddressPointerForEvent(event, relays) {
158
- if (!isParameterizedReplaceableKind(event.kind))
159
- throw new Error("Cant get AddressPointer for non-replaceable event");
160
- const d = getReplaceableIdentifier(event);
161
- return {
162
- identifier: d,
163
- kind: event.kind,
164
- pubkey: event.pubkey,
165
- relays,
166
- };
167
- }
168
- /**
169
- * Returns an EventPointer for an event
170
- * @throws
171
- */
172
- export function getEventPointerForEvent(event, relays) {
173
- return {
174
- id: event.id,
175
- kind: event.kind,
176
- author: event.pubkey,
177
- relays,
178
- };
179
- }
180
- /** Returns a pointer for a given event */
181
- export function getPointerForEvent(event, relays) {
182
- if (kinds.isParameterizedReplaceableKind(event.kind)) {
183
- const d = getReplaceableIdentifier(event);
184
- return {
185
- type: "naddr",
186
- data: {
187
- identifier: d,
188
- kind: event.kind,
189
- pubkey: event.pubkey,
190
- relays,
191
- },
192
- };
193
- }
194
- else {
195
- return {
196
- type: "nevent",
197
- data: {
198
- id: event.id,
199
- kind: event.kind,
200
- author: event.pubkey,
201
- relays,
202
- },
203
- };
204
- }
205
- }
@@ -1,20 +0,0 @@
1
- import { NostrEvent } from "nostr-tools";
2
- export declare const ProfileContentSymbol: unique symbol;
3
- export type ProfileContent = {
4
- name?: string;
5
- display_name?: string;
6
- displayName?: string;
7
- about?: string;
8
- /** @deprecated */
9
- image?: string;
10
- picture?: string;
11
- banner?: string;
12
- website?: string;
13
- lud16?: string;
14
- lud06?: string;
15
- nip05?: string;
16
- };
17
- /** Returns the parsed profile content for a kind 0 event */
18
- export declare function getProfileContent(event: NostrEvent): ProfileContent;
19
- /** Checks if the content of the kind 0 event is valid JSON */
20
- export declare function isValidProfile(profile?: NostrEvent): boolean;
@@ -1,31 +0,0 @@
1
- import { kinds } from "nostr-tools";
2
- import { getOrComputeCachedValue } from "./cache.js";
3
- export const ProfileContentSymbol = Symbol.for("profile-content");
4
- /** Returns the parsed profile content for a kind 0 event */
5
- export function getProfileContent(event) {
6
- return getOrComputeCachedValue(event, ProfileContentSymbol, () => {
7
- const profile = JSON.parse(event.content);
8
- // ensure nip05 is a string
9
- if (profile.nip05 && typeof profile.nip05 !== "string")
10
- profile.nip05 = String(profile.nip05);
11
- // add missing protocol to website
12
- if (profile.website && profile.website?.length > 0 && profile.website?.startsWith("http") === false) {
13
- profile.website = "https://" + profile.website;
14
- }
15
- return profile;
16
- });
17
- }
18
- /** Checks if the content of the kind 0 event is valid JSON */
19
- export function isValidProfile(profile) {
20
- if (!profile)
21
- return false;
22
- if (profile.kind !== kinds.Metadata)
23
- return false;
24
- try {
25
- getProfileContent(profile);
26
- return true;
27
- }
28
- catch (error) {
29
- return false;
30
- }
31
- }
@@ -1,12 +0,0 @@
1
- import { NostrEvent } from "nostr-tools";
2
- export declare const SeenRelaysSymbol: unique symbol;
3
- declare module "nostr-tools" {
4
- interface Event {
5
- [SeenRelaysSymbol]?: Set<string>;
6
- }
7
- }
8
- export declare function addSeenRelay(event: NostrEvent, relay: string): Set<string>;
9
- export declare function getSeenRelays(event: NostrEvent): Set<string> | undefined;
10
- export declare function validateRelayURL(relay: string | URL): URL;
11
- export declare function safeRelayUrl(relayUrl: string | URL): string | null;
12
- export declare function safeRelayUrls(urls: Iterable<string>): string[];
@@ -1,31 +0,0 @@
1
- export const SeenRelaysSymbol = Symbol.for("seen-relays");
2
- // Seen relays
3
- export function addSeenRelay(event, relay) {
4
- if (!event[SeenRelaysSymbol])
5
- event[SeenRelaysSymbol] = new Set();
6
- event[SeenRelaysSymbol].add(relay);
7
- return event[SeenRelaysSymbol];
8
- }
9
- export function getSeenRelays(event) {
10
- return event[SeenRelaysSymbol];
11
- }
12
- // Relay URLs
13
- export function validateRelayURL(relay) {
14
- if (typeof relay === "string" && relay.includes(",ws"))
15
- throw new Error("Can not have multiple relays in one string");
16
- const url = typeof relay === "string" ? new URL(relay) : relay;
17
- if (url.protocol !== "wss:" && url.protocol !== "ws:")
18
- throw new Error("Incorrect protocol");
19
- return url;
20
- }
21
- export function safeRelayUrl(relayUrl) {
22
- try {
23
- return validateRelayURL(relayUrl).toString();
24
- }
25
- catch (e) {
26
- return null;
27
- }
28
- }
29
- export function safeRelayUrls(urls) {
30
- return Array.from(urls).map(safeRelayUrl).filter(Boolean);
31
- }
@@ -1,10 +0,0 @@
1
- /** Tests if a string is hex */
2
- export declare function isHex(str?: string): boolean;
3
- /** Tests if a string is a 64 length hex string */
4
- export declare function isHexKey(key?: string): boolean;
5
- /**
6
- * Remove invisible characters from a string
7
- * @see read more https://www.regular-expressions.info/unicode.html#category
8
- */
9
- export declare function stripInvisibleChar(str: string): string;
10
- export declare function stripInvisibleChar(str?: string | undefined): string | undefined;
@@ -1,15 +0,0 @@
1
- /** Tests if a string is hex */
2
- export function isHex(str) {
3
- if (str?.match(/^[0-9a-f]+$/i))
4
- return true;
5
- return false;
6
- }
7
- /** Tests if a string is a 64 length hex string */
8
- export function isHexKey(key) {
9
- if (key?.toLowerCase()?.match(/^[0-9a-f]{64}$/))
10
- return true;
11
- return false;
12
- }
13
- export function stripInvisibleChar(str) {
14
- return str && str.replaceAll(/[\p{Cf}\p{Zs}]/gu, "");
15
- }
@@ -1,25 +0,0 @@
1
- /** Checks if tag is an "e" tag and has at least one value */
2
- export declare function isETag(tag: string[]): tag is ["e", string, ...string[]];
3
- /** Checks if tag is an "p" tag and has at least one value */
4
- export declare function isPTag(tag: string[]): tag is ["p", string, ...string[]];
5
- /** Checks if tag is an "r" tag and has at least one value */
6
- export declare function isRTag(tag: string[]): tag is ["r", string, ...string[]];
7
- /** Checks if tag is an "d" tag and has at least one value */
8
- export declare function isDTag(tag: string[]): tag is ["d", string, ...string[]];
9
- /** Checks if tag is an "a" tag and has at least one value */
10
- export declare function isATag(tag: string[]): tag is ["a", string, ...string[]];
11
- /** Checks if tag is an "a" tag and has at least one value */
12
- export declare function isTTag(tag: string[]): tag is ["t", string, ...string[]];
13
- /** A pipeline that filters and maps each tag */
14
- type TagPipe = {
15
- <A>(tags: string[][], ta: (tag: string[]) => A | undefined): A[];
16
- <A, B>(tags: string[][], ta: (tag: string[]) => A | undefined, ab: (a: A) => B | undefined): B[];
17
- <A, B, C>(tags: string[][], ta: (tag: string[]) => A | undefined, ab: (a: A) => B | undefined, bc: (b: B) => C | undefined): C[];
18
- <A, B, C, D>(tags: string[][], ta: (tag: string[]) => A | undefined, ab: (a: A) => B | undefined, bc: (b: B) => C | undefined, cd: (c: C) => D | undefined): D[];
19
- <A, B, C, D, E>(tags: string[][], ta: (tag: string[]) => A | undefined, ab: (a: A) => B | undefined, bc: (b: B) => C | undefined, cd: (c: C) => D | undefined, de: (d: D) => E | undefined): E[];
20
- <A, B, C, D, E, F>(tags: string[][], ta: (tag: string[]) => A | undefined, ab: (a: A) => B | undefined, bc: (b: B) => C | undefined, cd: (c: C) => D | undefined, de: (d: D) => E | undefined, ef: (e: E) => F | undefined): F[];
21
- <A, B, C, D, E, F, G>(tags: string[][], ta: (tag: string[]) => A | undefined, ab: (a: A) => B | undefined, bc: (b: B) => C | undefined, cd: (c: C) => D | undefined, de: (d: D) => E | undefined, ef: (e: E) => F | undefined, fg: (f: F) => G | undefined): G[];
22
- };
23
- /** Filter and transform tags */
24
- export declare const processTags: TagPipe;
25
- export {};
@@ -1,42 +0,0 @@
1
- /** Checks if tag is an "e" tag and has at least one value */
2
- export function isETag(tag) {
3
- return tag[0] === "e" && tag[1] !== undefined;
4
- }
5
- /** Checks if tag is an "p" tag and has at least one value */
6
- export function isPTag(tag) {
7
- return tag[0] === "p" && tag[1] !== undefined;
8
- }
9
- /** Checks if tag is an "r" tag and has at least one value */
10
- export function isRTag(tag) {
11
- return tag[0] === "r" && tag[1] !== undefined;
12
- }
13
- /** Checks if tag is an "d" tag and has at least one value */
14
- export function isDTag(tag) {
15
- return tag[0] === "d" && tag[1] !== undefined;
16
- }
17
- /** Checks if tag is an "a" tag and has at least one value */
18
- export function isATag(tag) {
19
- return tag[0] === "a" && tag[1] !== undefined;
20
- }
21
- /** Checks if tag is an "a" tag and has at least one value */
22
- export function isTTag(tag) {
23
- return tag[0] === "a" && tag[1] !== undefined;
24
- }
25
- /** Filter and transform tags */
26
- export const processTags = (tags, ...fns) => {
27
- return fns.reduce((step, fn) => {
28
- const next = [];
29
- for (const value of step) {
30
- try {
31
- const result = fn(value);
32
- if (result === undefined)
33
- continue; // value is undefined, ignore
34
- next.push(result);
35
- }
36
- catch (error) {
37
- // failed to process value, ignore
38
- }
39
- }
40
- return next;
41
- }, tags);
42
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { isATag, processTags } from "./tags.js";
3
- import { getAddressPointerFromATag } from "./pointers.js";
4
- describe("tag helpers", () => {
5
- describe("processTags", () => {
6
- it("should filter out errors", () => {
7
- expect(processTags([["a", "bad coordinate"], ["e"], ["a", "30000:pubkey:list"]], getAddressPointerFromATag)).toEqual([{ identifier: "list", kind: 30000, pubkey: "pubkey" }]);
8
- });
9
- it("should filter out undefined", () => {
10
- expect(processTags([["a", "bad coordinate"], ["e"], ["a", "30000:pubkey:list"]], (tag) => isATag(tag) ? tag : undefined)).toEqual([
11
- ["a", "bad coordinate"],
12
- ["a", "30000:pubkey:list"],
13
- ]);
14
- });
15
- });
16
- });