applesauce-core 0.0.0-next-20250404095409 → 0.0.0-next-20250411160531
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.
|
@@ -47,6 +47,45 @@ describe("add", () => {
|
|
|
47
47
|
eventStore.add(profile);
|
|
48
48
|
expect(eventStore.getEvent(profile.id)).toBeUndefined();
|
|
49
49
|
});
|
|
50
|
+
it("should remove profile events when delete event is added", () => {
|
|
51
|
+
// Add initial replaceable event
|
|
52
|
+
eventStore.add(profile);
|
|
53
|
+
expect(eventStore.getEvent(profile.id)).toBeDefined();
|
|
54
|
+
const deleteEvent = {
|
|
55
|
+
id: "delete event id",
|
|
56
|
+
kind: kinds.EventDeletion,
|
|
57
|
+
created_at: profile.created_at + 100,
|
|
58
|
+
pubkey: user.pubkey,
|
|
59
|
+
tags: [["a", `${profile.kind}:${profile.pubkey}`]],
|
|
60
|
+
sig: "this should be ignored for the test",
|
|
61
|
+
content: "test",
|
|
62
|
+
};
|
|
63
|
+
// Add delete event with coordinate
|
|
64
|
+
eventStore.add(deleteEvent);
|
|
65
|
+
// Profile should be removed since delete event is newer
|
|
66
|
+
expect(eventStore.getEvent(profile.id)).toBeUndefined();
|
|
67
|
+
expect(eventStore.getReplaceable(profile.kind, profile.pubkey)).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
it("should remove addressable replaceable events when delete event is added", () => {
|
|
70
|
+
// Add initial replaceable event
|
|
71
|
+
const event = user.event({ content: "test", kind: 30000, tags: [["d", "test"]] });
|
|
72
|
+
eventStore.add(event);
|
|
73
|
+
expect(eventStore.getEvent(event.id)).toBeDefined();
|
|
74
|
+
const deleteEvent = {
|
|
75
|
+
id: "delete event id",
|
|
76
|
+
kind: kinds.EventDeletion,
|
|
77
|
+
created_at: event.created_at + 100,
|
|
78
|
+
pubkey: user.pubkey,
|
|
79
|
+
tags: [["a", `${event.kind}:${event.pubkey}:test`]],
|
|
80
|
+
sig: "this should be ignored for the test",
|
|
81
|
+
content: "test",
|
|
82
|
+
};
|
|
83
|
+
// Add delete event with coordinate
|
|
84
|
+
eventStore.add(deleteEvent);
|
|
85
|
+
// Profile should be removed since delete event is newer
|
|
86
|
+
expect(eventStore.getEvent(event.id)).toBeUndefined();
|
|
87
|
+
expect(eventStore.getReplaceable(event.kind, event.pubkey)).toBeUndefined();
|
|
88
|
+
});
|
|
50
89
|
});
|
|
51
90
|
describe("inserts", () => {
|
|
52
91
|
it("should emit newer replaceable events", () => {
|
|
@@ -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
|
+
import { parseCoordinate } from "../helpers/pointers.js";
|
|
12
13
|
export const EventStoreSymbol = Symbol.for("event-store");
|
|
13
14
|
function sortDesc(a, b) {
|
|
14
15
|
return b.created_at - a.created_at;
|
|
@@ -74,10 +75,16 @@ export class EventStore {
|
|
|
74
75
|
const coords = getDeleteCoordinates(deleteEvent);
|
|
75
76
|
for (const coord of coords) {
|
|
76
77
|
this.deletedCoords.set(coord, Math.max(this.deletedCoords.get(coord) ?? 0, deleteEvent.created_at));
|
|
77
|
-
//
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
|
|
78
|
+
// Parse the nostr address coordinate
|
|
79
|
+
const parsed = parseCoordinate(coord);
|
|
80
|
+
if (!parsed)
|
|
81
|
+
continue;
|
|
82
|
+
// Remove older versions of replaceable events
|
|
83
|
+
const events = this.database.getReplaceable(parsed.kind, parsed.pubkey, parsed.identifier) ?? [];
|
|
84
|
+
for (const event of events) {
|
|
85
|
+
if (event.created_at < deleteEvent.created_at)
|
|
86
|
+
this.database.removeEvent(event);
|
|
87
|
+
}
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
90
|
/** Copies important metadata from and identical event to another */
|
package/dist/helpers/pointers.js
CHANGED
|
@@ -5,16 +5,16 @@ import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
|
|
|
5
5
|
import { isSafeRelayURL } from "./relays.js";
|
|
6
6
|
export function parseCoordinate(a, requireD = false, silent = true) {
|
|
7
7
|
const parts = a.split(":");
|
|
8
|
-
const kind = parts[0]
|
|
8
|
+
const kind = parts[0] ? parseInt(parts[0]) : undefined;
|
|
9
9
|
const pubkey = parts[1];
|
|
10
10
|
const d = parts[2];
|
|
11
|
-
if (
|
|
11
|
+
if (kind === undefined) {
|
|
12
12
|
if (silent)
|
|
13
13
|
return null;
|
|
14
14
|
else
|
|
15
15
|
throw new Error("Missing kind");
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
17
|
+
if (pubkey === undefined || pubkey === "") {
|
|
18
18
|
if (silent)
|
|
19
19
|
return null;
|
|
20
20
|
else
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-core",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250411160531",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"@hirez_io/observer-spy": "^2.2.0",
|
|
77
77
|
"@types/debug": "^4.1.12",
|
|
78
78
|
"@types/hash-sum": "^1.0.2",
|
|
79
|
-
"typescript": "^5.
|
|
80
|
-
"vitest": "^3.
|
|
79
|
+
"typescript": "^5.8.3",
|
|
80
|
+
"vitest": "^3.1.1"
|
|
81
81
|
},
|
|
82
82
|
"funding": {
|
|
83
83
|
"type": "lightning",
|