applesauce-core 0.0.0-next-20241114194041 → 0.0.0-next-20241115160057

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,10 +1,5 @@
1
1
  import { NostrEvent } from "nostr-tools";
2
2
  export declare const ProfileContentSymbol: unique symbol;
3
- declare module "nostr-tools" {
4
- interface Event {
5
- [ProfileContentSymbol]?: ProfileContent | Error;
6
- }
7
- }
8
3
  export type ProfileContent = {
9
4
  name?: string;
10
5
  display_name?: string;
@@ -21,5 +16,3 @@ export type ProfileContent = {
21
16
  };
22
17
  /** Returns the parsed profile content for a kind 0 event */
23
18
  export declare function getProfileContent(event: NostrEvent): ProfileContent;
24
- export declare function getProfileContent(event: NostrEvent, quite: false): ProfileContent;
25
- export declare function getProfileContent(event: NostrEvent, quite: true): ProfileContent | Error;
@@ -1,28 +1,16 @@
1
+ import { getOrComputeCachedValue } from "./cache.js";
1
2
  export const ProfileContentSymbol = Symbol.for("profile-content");
2
- export function getProfileContent(event, quite = false) {
3
- let cached = event[ProfileContentSymbol];
4
- if (!cached) {
5
- try {
6
- const profile = JSON.parse(event.content);
7
- // ensure nip05 is a string
8
- if (profile.nip05 && typeof profile.nip05 !== "string")
9
- profile.nip05 = String(profile.nip05);
10
- cached = event[ProfileContentSymbol] = profile;
3
+ /** Returns the parsed profile content for a kind 0 event */
4
+ export function getProfileContent(event) {
5
+ return getOrComputeCachedValue(event, ProfileContentSymbol, () => {
6
+ const profile = JSON.parse(event.content);
7
+ // ensure nip05 is a string
8
+ if (profile.nip05 && typeof profile.nip05 !== "string")
9
+ profile.nip05 = String(profile.nip05);
10
+ // add missing protocol to website
11
+ if (profile.website?.startsWith("http") === false) {
12
+ profile.website = "https://" + profile.website;
11
13
  }
12
- catch (e) {
13
- if (e instanceof Error)
14
- cached = event[ProfileContentSymbol] = e;
15
- }
16
- }
17
- if (cached === undefined) {
18
- throw new Error("Failed to parse profile");
19
- }
20
- else if (cached instanceof Error) {
21
- if (!quite)
22
- throw cached;
23
- else
24
- return cached;
25
- }
26
- else
27
- return cached;
14
+ return profile;
15
+ });
28
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20241114194041",
3
+ "version": "0.0.0-next-20241115160057",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",