applesauce-core 0.0.0-next-20250628162548 → 0.0.0-next-20250630153459

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
  import { Observable } from "rxjs";
2
3
  import { IEventStoreStreams } from "../event-store/interface.js";
3
4
  /** A symbol that is used to mark encrypted content as being from a cache */
@@ -11,5 +12,11 @@ export interface EncryptedContentCache {
11
12
  export declare function markEncryptedContentFromCache<T extends object>(event: T): void;
12
13
  /** Checks if the encrypted content is from a cache */
13
14
  export declare function isEncryptedContentFromCache<T extends object>(event: T): boolean;
14
- /** Starts a process that persists and restores all encrypted content */
15
- export declare function persistEncryptedContent(eventStore: IEventStoreStreams, storage: EncryptedContentCache | Observable<EncryptedContentCache>): () => void;
15
+ /**
16
+ * Starts a process that persists and restores all encrypted content
17
+ * @param eventStore - The event store to listen to
18
+ * @param storage - The storage to use
19
+ * @param fallback - A function that will be called when the encrypted content is not found in storage
20
+ * @returns A function that can be used to stop the process
21
+ */
22
+ export declare function persistEncryptedContent(eventStore: IEventStoreStreams, storage: EncryptedContentCache | Observable<EncryptedContentCache>, fallback?: (event: NostrEvent) => any | Promise<any>): () => void;
@@ -15,9 +15,19 @@ export function isEncryptedContentFromCache(event) {
15
15
  return Reflect.has(event, EncryptedContentFromCacheSymbol);
16
16
  }
17
17
  const log = logger.extend("EncryptedContentCache");
18
- /** Starts a process that persists and restores all encrypted content */
19
- export function persistEncryptedContent(eventStore, storage) {
18
+ /**
19
+ * Starts a process that persists and restores all encrypted content
20
+ * @param eventStore - The event store to listen to
21
+ * @param storage - The storage to use
22
+ * @param fallback - A function that will be called when the encrypted content is not found in storage
23
+ * @returns A function that can be used to stop the process
24
+ */
25
+ export function persistEncryptedContent(eventStore, storage, fallback) {
20
26
  const storage$ = isObservable(storage) ? storage : of(storage);
27
+ // Get the encrypted content from storage or call the fallback
28
+ const getItem = async (storage, event) => {
29
+ return (await storage.getItem(event.id)) || (fallback ? await fallback(event) : null);
30
+ };
21
31
  // Restore encrypted content when it is inserted
22
32
  const restore = eventStore.insert$
23
33
  .pipe(
@@ -26,7 +36,7 @@ export function persistEncryptedContent(eventStore, storage) {
26
36
  // Get the encrypted content from storage
27
37
  mergeMap((event) =>
28
38
  // Wait for storage to be available
29
- storage$.pipe(switchMap((storage) => combineLatest([of(event), storage.getItem(event.id)])), catchError((error) => {
39
+ storage$.pipe(switchMap((storage) => combineLatest([of(event), getItem(storage, event)])), catchError((error) => {
30
40
  log(`Failed to restore encrypted content for ${event.id}`, error);
31
41
  return EMPTY;
32
42
  }))))
@@ -52,7 +62,7 @@ export function persistEncryptedContent(eventStore, storage) {
52
62
  // Get encrypted content from storage
53
63
  mergeMap(([gift, seal]) =>
54
64
  // Wait for storage to be available
55
- storage$.pipe(switchMap((storage) => combineLatest([of(gift), of(seal), storage.getItem(seal.id)])), catchError((error) => {
65
+ storage$.pipe(switchMap((storage) => combineLatest([of(gift), of(seal), getItem(storage, seal)])), catchError((error) => {
56
66
  log(`Failed to restore encrypted content for ${seal.id}`, error);
57
67
  return EMPTY;
58
68
  }))))
@@ -16,6 +16,7 @@ export function WrappedMessagesModel(self) {
16
16
  map((rumors) => rumors
17
17
  .map((gift) => getGiftWrapRumor(gift))
18
18
  .filter((e) => !!e)
19
+ .filter((e) => e.kind === kinds.PrivateDirectMessage)
19
20
  .sort((a, b) => b.created_at - a.created_at)));
20
21
  }
21
22
  /** A model that returns all conversations that a pubkey is participating in */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20250628162548",
3
+ "version": "0.0.0-next-20250630153459",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",