applesauce-core 0.0.0-next-20250311171842 → 0.0.0-next-20250311175838

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,6 +1,7 @@
1
1
  import { Filter, NostrEvent } from "nostr-tools";
2
2
  import { Observable } from "rxjs";
3
3
  import { Database } from "./database.js";
4
+ export declare const EventStoreSymbol: unique symbol;
4
5
  export declare class EventStore {
5
6
  database: Database;
6
7
  /** Enable this to keep old versions of replaceable events */
@@ -30,8 +31,8 @@ export declare class EventStore {
30
31
  /** Get all events matching a filter */
31
32
  getAll(filters: Filter[]): Set<NostrEvent>;
32
33
  /** Check if the store has an event */
33
- hasEvent(uid: string): boolean;
34
- getEvent(uid: string): NostrEvent | undefined;
34
+ hasEvent(id: string): boolean;
35
+ getEvent(id: string): NostrEvent | undefined;
35
36
  /** Check if the store has a replaceable event */
36
37
  hasReplaceable(kind: number, pubkey: string, d?: string): boolean;
37
38
  /** Gets the latest version of a replaceable event */
@@ -9,6 +9,7 @@ import { addSeenRelay, getSeenRelays } from "../helpers/relays.js";
9
9
  import { getDeleteCoordinates, getDeleteIds } from "../helpers/delete.js";
10
10
  import { claimEvents } from "../observable/claim-events.js";
11
11
  import { claimLatest } from "../observable/claim-latest.js";
12
+ export const EventStoreSymbol = Symbol.for("event-store");
12
13
  function sortDesc(a, b) {
13
14
  return b.created_at - a.created_at;
14
15
  }
@@ -27,6 +28,14 @@ export class EventStore {
27
28
  if (this.verifyEvent && this.verifyEvent(event) === false)
28
29
  throw new Error("Invalid event");
29
30
  };
31
+ // when events are added to the database, add the symbol
32
+ this.database.inserted.subscribe((event) => {
33
+ Reflect.set(event, EventStoreSymbol, this);
34
+ });
35
+ // when events are removed from the database, remove the symbol
36
+ this.database.removed.subscribe((event) => {
37
+ Reflect.deleteProperty(event, EventStoreSymbol);
38
+ });
30
39
  this.updates = this.database.updated;
31
40
  }
32
41
  // delete state
@@ -123,11 +132,11 @@ export class EventStore {
123
132
  return this.database.getEventsForFilters(filters);
124
133
  }
125
134
  /** Check if the store has an event */
126
- hasEvent(uid) {
127
- return this.database.hasEvent(uid);
135
+ hasEvent(id) {
136
+ return this.database.hasEvent(id);
128
137
  }
129
- getEvent(uid) {
130
- return this.database.getEvent(uid);
138
+ getEvent(id) {
139
+ return this.database.getEvent(id);
131
140
  }
132
141
  /** Check if the store has a replaceable event */
133
142
  hasReplaceable(kind, pubkey, d) {
@@ -1,4 +1,5 @@
1
1
  import { EventTemplate, NostrEvent, VerifiedEvent } from "nostr-tools";
2
+ import { EventStore } from "../event-store/event-store.js";
2
3
  export declare const EventUIDSymbol: unique symbol;
3
4
  export declare const EventIndexableTagsSymbol: unique symbol;
4
5
  export declare const FromCacheSymbol: unique symbol;
@@ -41,6 +42,8 @@ export declare function fakeVerifyEvent(event: NostrEvent): event is VerifiedEve
41
42
  export declare function markFromCache(event: NostrEvent): void;
42
43
  /** Returns if an event was from a cache */
43
44
  export declare function isFromCache(event: NostrEvent): boolean;
45
+ /** Returns the EventStore of an event if its been added to one */
46
+ export declare function getParentEventStore(event: NostrEvent): EventStore | undefined;
44
47
  /**
45
48
  * Returns the replaceable identifier for a replaceable event
46
49
  * @throws
@@ -3,6 +3,7 @@ import { INDEXABLE_TAGS } from "../event-store/common.js";
3
3
  import { getHiddenTags } from "./hidden-tags.js";
4
4
  import { getOrComputeCachedValue } from "./cache.js";
5
5
  import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
6
+ import { EventStoreSymbol } from "../event-store/event-store.js";
6
7
  export const EventUIDSymbol = Symbol.for("event-uid");
7
8
  export const EventIndexableTagsSymbol = Symbol.for("indexable-tags");
8
9
  export const FromCacheSymbol = Symbol.for("from-cache");
@@ -90,6 +91,10 @@ export function markFromCache(event) {
90
91
  export function isFromCache(event) {
91
92
  return !!event[FromCacheSymbol];
92
93
  }
94
+ /** Returns the EventStore of an event if its been added to one */
95
+ export function getParentEventStore(event) {
96
+ return Reflect.get(event, EventStoreSymbol);
97
+ }
93
98
  /**
94
99
  * Returns the replaceable identifier for a replaceable event
95
100
  * @throws
@@ -1,5 +1,6 @@
1
1
  import * as kinds from "nostr-tools/kinds";
2
2
  import { GROUPS_LIST_KIND } from "./groups.js";
3
+ import { getParentEventStore } from "./event.js";
3
4
  export const HiddenContentSymbol = Symbol.for("hidden-content");
4
5
  /** Various event kinds that can have encrypted tags in their content and which encryption method they use */
5
6
  export const EventContentEncryptionMethod = {
@@ -67,5 +68,9 @@ export async function unlockHiddenContent(event, signer) {
67
68
  const encryption = getHiddenContentEncryptionMethods(event.kind, signer);
68
69
  const plaintext = await encryption.decrypt(event.pubkey, event.content);
69
70
  Reflect.set(event, HiddenContentSymbol, plaintext);
71
+ // if the event has been added to an event store, notify it
72
+ const eventStore = getParentEventStore(event);
73
+ if (eventStore)
74
+ eventStore.update(event);
70
75
  return plaintext;
71
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20250311171842",
3
+ "version": "0.0.0-next-20250311175838",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",