applesauce-core 0.4.0 → 0.6.0
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.
- package/dist/event-store/database.d.ts +18 -0
- package/dist/event-store/database.js +11 -0
- package/dist/event-store/event-store.d.ts +6 -1
- package/dist/event-store/event-store.js +104 -30
- package/dist/helpers/cache.d.ts +5 -0
- package/dist/helpers/cache.js +17 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +3 -0
- package/dist/helpers/string.d.ts +2 -0
- package/dist/helpers/string.js +10 -0
- package/dist/helpers/tags.d.ts +6 -0
- package/dist/helpers/tags.js +18 -0
- package/dist/helpers/time.d.ts +2 -0
- package/dist/helpers/time.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/promise/deferred.d.ts +1 -1
- package/dist/promise/deferred.js +1 -1
- package/dist/queries/index.d.ts +0 -2
- package/dist/queries/index.js +0 -2
- package/dist/queries/simple.d.ts +11 -0
- package/dist/queries/simple.js +18 -0
- package/dist/query-store/index.d.ts +8 -7
- package/dist/query-store/index.js +8 -4
- package/package.json +21 -9
- package/dist/helpers/channel.d.ts +0 -15
- package/dist/helpers/channel.js +0 -27
- package/dist/helpers/mute.d.ts +0 -21
- package/dist/helpers/mute.js +0 -52
- package/dist/queries/channel.d.ts +0 -11
- package/dist/queries/channel.js +0 -72
- package/dist/queries/mute.d.ts +0 -7
- package/dist/queries/mute.js +0 -16
|
@@ -15,6 +15,7 @@ export declare class Database {
|
|
|
15
15
|
/** LRU cache of last events touched */
|
|
16
16
|
events: LRU<import("nostr-tools").Event>;
|
|
17
17
|
private insertedSignal;
|
|
18
|
+
private updatedSignal;
|
|
18
19
|
private deletedSignal;
|
|
19
20
|
/** A stream of events inserted into the database */
|
|
20
21
|
inserted: {
|
|
@@ -29,6 +30,19 @@ export declare class Database {
|
|
|
29
30
|
flatMap<R_2>(callback: (value: import("nostr-tools").Event) => ZenObservable.ObservableLike<R_2>): import("zen-observable")<R_2>;
|
|
30
31
|
concat<R_3>(...observable: import("zen-observable")<R_3>[]): import("zen-observable")<R_3>;
|
|
31
32
|
};
|
|
33
|
+
/** A stream of events that have been updated */
|
|
34
|
+
updated: {
|
|
35
|
+
subscribe(observer: ZenObservable.Observer<import("nostr-tools").Event>): ZenObservable.Subscription;
|
|
36
|
+
subscribe(onNext: (value: import("nostr-tools").Event) => void, onError?: ((error: any) => void) | undefined, onComplete?: (() => void) | undefined): ZenObservable.Subscription;
|
|
37
|
+
forEach(callback: (value: import("nostr-tools").Event) => void): Promise<void>;
|
|
38
|
+
map<R>(callback: (value: import("nostr-tools").Event) => R): import("zen-observable")<R>;
|
|
39
|
+
filter<S extends import("nostr-tools").Event>(callback: (value: import("nostr-tools").Event) => value is S): import("zen-observable")<S>;
|
|
40
|
+
filter(callback: (value: import("nostr-tools").Event) => boolean): import("zen-observable")<import("nostr-tools").Event>;
|
|
41
|
+
reduce(callback: (previousValue: import("nostr-tools").Event, currentValue: import("nostr-tools").Event) => import("nostr-tools").Event, initialValue?: import("nostr-tools").Event | undefined): import("zen-observable")<import("nostr-tools").Event>;
|
|
42
|
+
reduce<R_1>(callback: (previousValue: R_1, currentValue: import("nostr-tools").Event) => R_1, initialValue?: R_1 | undefined): import("zen-observable")<R_1>;
|
|
43
|
+
flatMap<R_2>(callback: (value: import("nostr-tools").Event) => ZenObservable.ObservableLike<R_2>): import("zen-observable")<R_2>;
|
|
44
|
+
concat<R_3>(...observable: import("zen-observable")<R_3>[]): import("zen-observable")<R_3>;
|
|
45
|
+
};
|
|
32
46
|
/** A stream of events removed of the database */
|
|
33
47
|
deleted: {
|
|
34
48
|
subscribe(observer: ZenObservable.Observer<import("nostr-tools").Event>): ZenObservable.Subscription;
|
|
@@ -55,7 +69,11 @@ export declare class Database {
|
|
|
55
69
|
hasReplaceable(kind: number, pubkey: string, d?: string): boolean;
|
|
56
70
|
/** Gets a replaceable event and touches it */
|
|
57
71
|
getReplaceable(kind: number, pubkey: string, d?: string): import("nostr-tools").Event | undefined;
|
|
72
|
+
/** Inserts an event into the database and notifies all subscriptions */
|
|
58
73
|
addEvent(event: NostrEvent): import("nostr-tools").Event;
|
|
74
|
+
/** Inserts and event into the database and notifies all subscriptions that the event has updated */
|
|
75
|
+
updateEvent(event: NostrEvent): import("nostr-tools").Event;
|
|
76
|
+
/** Deletes an event from the database and notifies all subscriptions */
|
|
59
77
|
deleteEvent(eventOrUID: string | NostrEvent): boolean;
|
|
60
78
|
/** Sets the claim on the event and touches it */
|
|
61
79
|
claimEvent(event: NostrEvent, claim: any): void;
|
|
@@ -17,9 +17,12 @@ export class Database {
|
|
|
17
17
|
/** LRU cache of last events touched */
|
|
18
18
|
events = new LRU();
|
|
19
19
|
insertedSignal = new PushStream();
|
|
20
|
+
updatedSignal = new PushStream();
|
|
20
21
|
deletedSignal = new PushStream();
|
|
21
22
|
/** A stream of events inserted into the database */
|
|
22
23
|
inserted = this.insertedSignal.observable;
|
|
24
|
+
/** A stream of events that have been updated */
|
|
25
|
+
updated = this.updatedSignal.observable;
|
|
23
26
|
/** A stream of events removed of the database */
|
|
24
27
|
deleted = this.deletedSignal.observable;
|
|
25
28
|
claims = new WeakMap();
|
|
@@ -69,6 +72,7 @@ export class Database {
|
|
|
69
72
|
getReplaceable(kind, pubkey, d) {
|
|
70
73
|
return this.events.get(getReplaceableUID(kind, pubkey, d));
|
|
71
74
|
}
|
|
75
|
+
/** Inserts an event into the database and notifies all subscriptions */
|
|
72
76
|
addEvent(event) {
|
|
73
77
|
const uid = getEventUID(event);
|
|
74
78
|
const current = this.events.get(uid);
|
|
@@ -86,6 +90,13 @@ export class Database {
|
|
|
86
90
|
this.insertedSignal.next(event);
|
|
87
91
|
return event;
|
|
88
92
|
}
|
|
93
|
+
/** Inserts and event into the database and notifies all subscriptions that the event has updated */
|
|
94
|
+
updateEvent(event) {
|
|
95
|
+
const inserted = this.addEvent(event);
|
|
96
|
+
this.updatedSignal.next(inserted);
|
|
97
|
+
return inserted;
|
|
98
|
+
}
|
|
99
|
+
/** Deletes an event from the database and notifies all subscriptions */
|
|
89
100
|
deleteEvent(eventOrUID) {
|
|
90
101
|
let event = typeof eventOrUID === "string" ? this.events.get(eventOrUID) : eventOrUID;
|
|
91
102
|
if (!event)
|
|
@@ -2,12 +2,15 @@ import { Filter, NostrEvent } from "nostr-tools";
|
|
|
2
2
|
import Observable from "zen-observable";
|
|
3
3
|
import { Database } from "./database.js";
|
|
4
4
|
export declare class EventStore {
|
|
5
|
-
|
|
5
|
+
database: Database;
|
|
6
6
|
private singles;
|
|
7
7
|
private streams;
|
|
8
8
|
private timelines;
|
|
9
9
|
constructor();
|
|
10
|
+
/** Adds an event to the database */
|
|
10
11
|
add(event: NostrEvent, fromRelay?: string): import("nostr-tools").Event;
|
|
12
|
+
/** Add an event to the store and notifies all subscribes it has updated */
|
|
13
|
+
update(event: NostrEvent): import("nostr-tools").Event;
|
|
11
14
|
getAll(filters: Filter[]): Set<import("nostr-tools").Event>;
|
|
12
15
|
hasEvent(uid: string): import("nostr-tools").Event | undefined;
|
|
13
16
|
getEvent(uid: string): import("nostr-tools").Event | undefined;
|
|
@@ -15,6 +18,8 @@ export declare class EventStore {
|
|
|
15
18
|
getReplaceable(kind: number, pubkey: string, d?: string): import("nostr-tools").Event | undefined;
|
|
16
19
|
/** Creates an observable that updates a single event */
|
|
17
20
|
event(uid: string): Observable<import("nostr-tools").Event | undefined>;
|
|
21
|
+
/** Creates an observable that subscribes to multiple events */
|
|
22
|
+
events(uids: string[]): Observable<Map<string, import("nostr-tools").Event>>;
|
|
18
23
|
/** Creates an observable that updates a single replaceable event */
|
|
19
24
|
replaceable(kind: number, pubkey: string, d?: string): Observable<import("nostr-tools").Event | undefined>;
|
|
20
25
|
/** Creates an observable that streams all events that match the filter */
|
|
@@ -5,58 +5,68 @@ import { getEventUID, getReplaceableUID } from "../helpers/event.js";
|
|
|
5
5
|
import { matchFilters } from "../helpers/filter.js";
|
|
6
6
|
import { addSeenRelay } from "../helpers/relays.js";
|
|
7
7
|
export class EventStore {
|
|
8
|
-
|
|
8
|
+
database;
|
|
9
9
|
singles = new Map();
|
|
10
10
|
streams = new Map();
|
|
11
11
|
timelines = new Map();
|
|
12
12
|
constructor() {
|
|
13
|
-
this.
|
|
13
|
+
this.database = new Database();
|
|
14
14
|
}
|
|
15
|
+
/** Adds an event to the database */
|
|
15
16
|
add(event, fromRelay) {
|
|
16
|
-
const inserted = this.
|
|
17
|
+
const inserted = this.database.addEvent(event);
|
|
17
18
|
if (fromRelay)
|
|
18
19
|
addSeenRelay(inserted, fromRelay);
|
|
19
20
|
return inserted;
|
|
20
21
|
}
|
|
22
|
+
/** Add an event to the store and notifies all subscribes it has updated */
|
|
23
|
+
update(event) {
|
|
24
|
+
return this.database.updateEvent(event);
|
|
25
|
+
}
|
|
21
26
|
getAll(filters) {
|
|
22
|
-
return this.
|
|
27
|
+
return this.database.getForFilters(filters);
|
|
23
28
|
}
|
|
24
29
|
hasEvent(uid) {
|
|
25
|
-
return this.
|
|
30
|
+
return this.database.hasEvent(uid);
|
|
26
31
|
}
|
|
27
32
|
getEvent(uid) {
|
|
28
|
-
return this.
|
|
33
|
+
return this.database.getEvent(uid);
|
|
29
34
|
}
|
|
30
35
|
hasReplaceable(kind, pubkey, d) {
|
|
31
|
-
return this.
|
|
36
|
+
return this.database.hasReplaceable(kind, pubkey, d);
|
|
32
37
|
}
|
|
33
38
|
getReplaceable(kind, pubkey, d) {
|
|
34
|
-
return this.
|
|
39
|
+
return this.database.getReplaceable(kind, pubkey, d);
|
|
35
40
|
}
|
|
36
41
|
/** Creates an observable that updates a single event */
|
|
37
42
|
event(uid) {
|
|
38
43
|
return new Observable((observer) => {
|
|
39
|
-
let current = this.
|
|
44
|
+
let current = this.database.getEvent(uid);
|
|
40
45
|
if (current) {
|
|
41
46
|
observer.next(current);
|
|
42
|
-
this.
|
|
47
|
+
this.database.claimEvent(current, observer);
|
|
43
48
|
}
|
|
44
49
|
// subscribe to future events
|
|
45
|
-
const inserted = this.
|
|
50
|
+
const inserted = this.database.inserted.subscribe((event) => {
|
|
46
51
|
if (getEventUID(event) === uid && (!current || event.created_at > current.created_at)) {
|
|
47
52
|
// remove old claim
|
|
48
53
|
if (current)
|
|
49
|
-
this.
|
|
54
|
+
this.database.removeClaim(current, observer);
|
|
50
55
|
current = event;
|
|
51
56
|
observer.next(event);
|
|
52
57
|
// claim new event
|
|
53
|
-
this.
|
|
58
|
+
this.database.claimEvent(current, observer);
|
|
54
59
|
}
|
|
55
60
|
});
|
|
61
|
+
// subscribe to updates
|
|
62
|
+
const updated = this.database.updated.subscribe((event) => {
|
|
63
|
+
if (event === current)
|
|
64
|
+
observer.next(event);
|
|
65
|
+
});
|
|
56
66
|
// subscribe to deleted events
|
|
57
|
-
const deleted = this.
|
|
67
|
+
const deleted = this.database.deleted.subscribe((event) => {
|
|
58
68
|
if (getEventUID(event) === uid && current) {
|
|
59
|
-
this.
|
|
69
|
+
this.database.removeClaim(current, observer);
|
|
60
70
|
current = undefined;
|
|
61
71
|
observer.next(undefined);
|
|
62
72
|
}
|
|
@@ -65,9 +75,66 @@ export class EventStore {
|
|
|
65
75
|
return () => {
|
|
66
76
|
inserted.unsubscribe();
|
|
67
77
|
deleted.unsubscribe();
|
|
78
|
+
updated.unsubscribe();
|
|
68
79
|
this.singles.delete(observer);
|
|
69
80
|
if (current)
|
|
70
|
-
this.
|
|
81
|
+
this.database.removeClaim(current, observer);
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** Creates an observable that subscribes to multiple events */
|
|
86
|
+
events(uids) {
|
|
87
|
+
return new Observable((observer) => {
|
|
88
|
+
const events = new Map();
|
|
89
|
+
for (const uid of uids) {
|
|
90
|
+
const e = this.getEvent(uid);
|
|
91
|
+
if (e) {
|
|
92
|
+
events.set(uid, e);
|
|
93
|
+
this.database.claimEvent(e, observer);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
observer.next(events);
|
|
97
|
+
// subscribe to future events
|
|
98
|
+
const inserted = this.database.inserted.subscribe((event) => {
|
|
99
|
+
const uid = getEventUID(event);
|
|
100
|
+
if (uids.includes(uid)) {
|
|
101
|
+
const current = events.get(uid);
|
|
102
|
+
// remove old claim
|
|
103
|
+
if (!current || event.created_at > current.created_at) {
|
|
104
|
+
if (current)
|
|
105
|
+
this.database.removeClaim(current, observer);
|
|
106
|
+
events.set(uid, event);
|
|
107
|
+
observer.next(events);
|
|
108
|
+
// claim new event
|
|
109
|
+
this.database.claimEvent(event, observer);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
// subscribe to updates
|
|
114
|
+
const updated = this.database.updated.subscribe((event) => {
|
|
115
|
+
const uid = getEventUID(event);
|
|
116
|
+
if (uids.includes(uid))
|
|
117
|
+
observer.next(events);
|
|
118
|
+
});
|
|
119
|
+
// subscribe to deleted events
|
|
120
|
+
const deleted = this.database.deleted.subscribe((event) => {
|
|
121
|
+
const uid = getEventUID(event);
|
|
122
|
+
if (uids.includes(uid)) {
|
|
123
|
+
const current = events.get(uid);
|
|
124
|
+
if (current) {
|
|
125
|
+
this.database.removeClaim(current, observer);
|
|
126
|
+
events.delete(uid);
|
|
127
|
+
observer.next(events);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return () => {
|
|
132
|
+
inserted.unsubscribe();
|
|
133
|
+
deleted.unsubscribe();
|
|
134
|
+
updated.unsubscribe();
|
|
135
|
+
for (const [_uid, event] of events) {
|
|
136
|
+
this.database.removeClaim(event, observer);
|
|
137
|
+
}
|
|
71
138
|
};
|
|
72
139
|
});
|
|
73
140
|
}
|
|
@@ -79,17 +146,17 @@ export class EventStore {
|
|
|
79
146
|
stream(filters) {
|
|
80
147
|
return new Observable((observer) => {
|
|
81
148
|
let claimed = new Set();
|
|
82
|
-
let events = this.
|
|
149
|
+
let events = this.database.getForFilters(filters);
|
|
83
150
|
for (const event of events) {
|
|
84
151
|
observer.next(event);
|
|
85
|
-
this.
|
|
152
|
+
this.database.claimEvent(event, observer);
|
|
86
153
|
claimed.add(event);
|
|
87
154
|
}
|
|
88
155
|
// subscribe to future events
|
|
89
|
-
const sub = this.
|
|
156
|
+
const sub = this.database.inserted.subscribe((event) => {
|
|
90
157
|
if (matchFilters(filters, event)) {
|
|
91
158
|
observer.next(event);
|
|
92
|
-
this.
|
|
159
|
+
this.database.claimEvent(event, observer);
|
|
93
160
|
claimed.add(event);
|
|
94
161
|
}
|
|
95
162
|
});
|
|
@@ -99,7 +166,7 @@ export class EventStore {
|
|
|
99
166
|
this.streams.delete(observer);
|
|
100
167
|
// remove all claims
|
|
101
168
|
for (const event of claimed)
|
|
102
|
-
this.
|
|
169
|
+
this.database.removeClaim(event, observer);
|
|
103
170
|
claimed.clear();
|
|
104
171
|
};
|
|
105
172
|
});
|
|
@@ -110,15 +177,15 @@ export class EventStore {
|
|
|
110
177
|
const seen = new Map();
|
|
111
178
|
const timeline = [];
|
|
112
179
|
// build initial timeline
|
|
113
|
-
const events = this.
|
|
180
|
+
const events = this.database.getForFilters(filters);
|
|
114
181
|
for (const event of events) {
|
|
115
182
|
insertEventIntoDescendingList(timeline, event);
|
|
116
|
-
this.
|
|
183
|
+
this.database.claimEvent(event, observer);
|
|
117
184
|
seen.set(getEventUID(event), event);
|
|
118
185
|
}
|
|
119
186
|
observer.next([...timeline]);
|
|
120
187
|
// subscribe to future events
|
|
121
|
-
const inserted = this.
|
|
188
|
+
const inserted = this.database.inserted.subscribe((event) => {
|
|
122
189
|
if (matchFilters(filters, event)) {
|
|
123
190
|
const uid = getEventUID(event);
|
|
124
191
|
let current = seen.get(uid);
|
|
@@ -129,21 +196,27 @@ export class EventStore {
|
|
|
129
196
|
observer.next([...timeline]);
|
|
130
197
|
// update the claim
|
|
131
198
|
seen.set(uid, event);
|
|
132
|
-
this.
|
|
133
|
-
this.
|
|
199
|
+
this.database.removeClaim(current, observer);
|
|
200
|
+
this.database.claimEvent(event, observer);
|
|
134
201
|
}
|
|
135
202
|
}
|
|
136
203
|
else {
|
|
137
204
|
insertEventIntoDescendingList(timeline, event);
|
|
138
205
|
observer.next([...timeline]);
|
|
139
206
|
// claim new event
|
|
140
|
-
this.
|
|
207
|
+
this.database.claimEvent(event, observer);
|
|
141
208
|
seen.set(getEventUID(event), event);
|
|
142
209
|
}
|
|
143
210
|
}
|
|
144
211
|
});
|
|
212
|
+
// subscribe to updates
|
|
213
|
+
const updated = this.database.updated.subscribe((event) => {
|
|
214
|
+
if (seen.has(getEventUID(event))) {
|
|
215
|
+
observer.next([...timeline]);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
145
218
|
// subscribe to removed events
|
|
146
|
-
const deleted = this.
|
|
219
|
+
const deleted = this.database.deleted.subscribe((event) => {
|
|
147
220
|
const uid = getEventUID(event);
|
|
148
221
|
let current = seen.get(uid);
|
|
149
222
|
if (current) {
|
|
@@ -152,7 +225,7 @@ export class EventStore {
|
|
|
152
225
|
observer.next([...timeline]);
|
|
153
226
|
// remove the claim
|
|
154
227
|
seen.delete(uid);
|
|
155
|
-
this.
|
|
228
|
+
this.database.removeClaim(current, observer);
|
|
156
229
|
}
|
|
157
230
|
});
|
|
158
231
|
this.timelines.set(observer, filters);
|
|
@@ -160,9 +233,10 @@ export class EventStore {
|
|
|
160
233
|
this.timelines.delete(observer);
|
|
161
234
|
inserted.unsubscribe();
|
|
162
235
|
deleted.unsubscribe();
|
|
236
|
+
updated.unsubscribe();
|
|
163
237
|
// remove all claims
|
|
164
238
|
for (const [_, event] of seen) {
|
|
165
|
-
this.
|
|
239
|
+
this.database.removeClaim(event, observer);
|
|
166
240
|
}
|
|
167
241
|
seen.clear();
|
|
168
242
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { EventTemplate, NostrEvent } from "nostr-tools";
|
|
2
|
+
export declare function getCachedValue<T extends unknown>(event: NostrEvent | EventTemplate, symbol: symbol): T | undefined;
|
|
3
|
+
export declare function setCachedValue<T extends unknown>(event: NostrEvent | EventTemplate, symbol: symbol, value: T): void;
|
|
4
|
+
/** Internal method used to cache computed values on events */
|
|
5
|
+
export declare function getOrComputeCachedValue<T extends unknown>(event: NostrEvent | EventTemplate, symbol: symbol, compute: (event: NostrEvent | EventTemplate) => T): T;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function getCachedValue(event, symbol) {
|
|
2
|
+
// @ts-expect-error
|
|
3
|
+
return event[symbol];
|
|
4
|
+
}
|
|
5
|
+
export function setCachedValue(event, symbol, value) {
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
event[symbol] = value;
|
|
8
|
+
}
|
|
9
|
+
/** Internal method used to cache computed values on events */
|
|
10
|
+
export function getOrComputeCachedValue(event, symbol, compute) {
|
|
11
|
+
let cached = getCachedValue(event, symbol);
|
|
12
|
+
if (!cached) {
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
cached = event[symbol] = compute(event);
|
|
15
|
+
}
|
|
16
|
+
return cached;
|
|
17
|
+
}
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function isETag(tag: string[]): tag is ["e", string, ...string[]];
|
|
2
|
+
export declare function isPTag(tag: string[]): tag is ["p", string, ...string[]];
|
|
3
|
+
export declare function isRTag(tag: string[]): tag is ["r", string, ...string[]];
|
|
4
|
+
export declare function isDTag(tag: string[]): tag is ["d", string, ...string[]];
|
|
5
|
+
export declare function isATag(tag: string[]): tag is ["a", string, ...string[]];
|
|
6
|
+
export declare function isTTag(tag: string[]): tag is ["t", string, ...string[]];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function isETag(tag) {
|
|
2
|
+
return tag[0] === "e" && tag[1] !== undefined;
|
|
3
|
+
}
|
|
4
|
+
export function isPTag(tag) {
|
|
5
|
+
return tag[0] === "p" && tag[1] !== undefined;
|
|
6
|
+
}
|
|
7
|
+
export function isRTag(tag) {
|
|
8
|
+
return tag[0] === "r" && tag[1] !== undefined;
|
|
9
|
+
}
|
|
10
|
+
export function isDTag(tag) {
|
|
11
|
+
return tag[0] === "d" && tag[1] !== undefined;
|
|
12
|
+
}
|
|
13
|
+
export function isATag(tag) {
|
|
14
|
+
return tag[0] === "a" && tag[1] !== undefined;
|
|
15
|
+
}
|
|
16
|
+
export function isTTag(tag) {
|
|
17
|
+
return tag[0] === "a" && tag[1] !== undefined;
|
|
18
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/promise/deferred.js
CHANGED
package/dist/queries/index.d.ts
CHANGED
package/dist/queries/index.js
CHANGED
package/dist/queries/simple.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { Filter, NostrEvent } from "nostr-tools";
|
|
2
2
|
import { Query } from "../query-store/index.js";
|
|
3
|
+
/** Creates a Query that returns a single event or undefined */
|
|
3
4
|
export declare function SingleEventQuery(uid: string): Query<NostrEvent | undefined>;
|
|
5
|
+
/** Creates a Query that returns a multiple events in a map */
|
|
6
|
+
export declare function MultipleEventsQuery(uids: string[]): Query<Map<string, NostrEvent>>;
|
|
7
|
+
/** Creates a Query returning the latest version of a replaceable event */
|
|
4
8
|
export declare function ReplaceableQuery(kind: number, pubkey: string, d?: string): Query<NostrEvent | undefined>;
|
|
9
|
+
/** Creates a Query that returns an array of sorted events matching the filters */
|
|
5
10
|
export declare function TimelineQuery(filters: Filter | Filter[]): Query<NostrEvent[]>;
|
|
11
|
+
/** Creates a Query that returns a directory of events by their UID */
|
|
12
|
+
export declare function ReplaceableSetQuery(pointers: {
|
|
13
|
+
kind: number;
|
|
14
|
+
pubkey: string;
|
|
15
|
+
identifier?: string;
|
|
16
|
+
}[]): Query<Map<string, NostrEvent>>;
|
package/dist/queries/simple.js
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
import stringify from "json-stringify-deterministic";
|
|
2
2
|
import { getReplaceableUID } from "../helpers/event.js";
|
|
3
|
+
/** Creates a Query that returns a single event or undefined */
|
|
3
4
|
export function SingleEventQuery(uid) {
|
|
4
5
|
return {
|
|
5
6
|
key: uid,
|
|
6
7
|
run: (events) => events.event(uid),
|
|
7
8
|
};
|
|
8
9
|
}
|
|
10
|
+
/** Creates a Query that returns a multiple events in a map */
|
|
11
|
+
export function MultipleEventsQuery(uids) {
|
|
12
|
+
return {
|
|
13
|
+
key: uids.join(","),
|
|
14
|
+
run: (events) => events.events(uids),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Creates a Query returning the latest version of a replaceable event */
|
|
9
18
|
export function ReplaceableQuery(kind, pubkey, d) {
|
|
10
19
|
return {
|
|
11
20
|
key: getReplaceableUID(kind, pubkey, d),
|
|
12
21
|
run: (events) => events.replaceable(kind, pubkey, d),
|
|
13
22
|
};
|
|
14
23
|
}
|
|
24
|
+
/** Creates a Query that returns an array of sorted events matching the filters */
|
|
15
25
|
export function TimelineQuery(filters) {
|
|
16
26
|
return {
|
|
17
27
|
key: stringify(filters),
|
|
18
28
|
run: (events) => events.timeline(Array.isArray(filters) ? filters : [filters]),
|
|
19
29
|
};
|
|
20
30
|
}
|
|
31
|
+
/** Creates a Query that returns a directory of events by their UID */
|
|
32
|
+
export function ReplaceableSetQuery(pointers) {
|
|
33
|
+
const cords = pointers.map((pointer) => getReplaceableUID(pointer.kind, pointer.pubkey, pointer.identifier));
|
|
34
|
+
return {
|
|
35
|
+
key: stringify(pointers),
|
|
36
|
+
run: (events) => events.events(cords),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -21,8 +21,16 @@ export declare class QueryStore {
|
|
|
21
21
|
}): (...args: Args) => Observable<T>;
|
|
22
22
|
/** Returns a single event */
|
|
23
23
|
event(id: string): Observable<import("nostr-tools").Event | undefined>;
|
|
24
|
+
/** Returns a single event */
|
|
25
|
+
events(ids: string[]): Observable<Map<string, import("nostr-tools").Event>>;
|
|
24
26
|
/** Returns the latest version of a replaceable event */
|
|
25
27
|
replaceable(kind: number, pubkey: string, d?: string): Observable<import("nostr-tools").Event | undefined>;
|
|
28
|
+
/** Returns a directory of events by their UID */
|
|
29
|
+
replaceableSet(pointers: {
|
|
30
|
+
kind: number;
|
|
31
|
+
pubkey: string;
|
|
32
|
+
identifier?: string;
|
|
33
|
+
}[]): Observable<Map<string, import("nostr-tools").Event>>;
|
|
26
34
|
/** Returns an array of events that match the filter */
|
|
27
35
|
timeline(filters: Filter | Filter[]): Observable<import("nostr-tools").Event[]>;
|
|
28
36
|
/** Returns the parsed profile (0) for a pubkey */
|
|
@@ -34,13 +42,6 @@ export declare class QueryStore {
|
|
|
34
42
|
inboxes: Set<string>;
|
|
35
43
|
outboxes: Set<string>;
|
|
36
44
|
} | undefined>;
|
|
37
|
-
/** Returns the parsed mute list for the pubkey */
|
|
38
|
-
mute(pubkey: string): Observable<{
|
|
39
|
-
words: Set<string>;
|
|
40
|
-
pubkeys: Set<string>;
|
|
41
|
-
threads: Set<string>;
|
|
42
|
-
hashtags: Set<string>;
|
|
43
|
-
} | undefined>;
|
|
44
45
|
thread(root: string | EventPointer | AddressPointer): Observable<Queries.Thread>;
|
|
45
46
|
}
|
|
46
47
|
export { Queries };
|
|
@@ -25,10 +25,18 @@ export class QueryStore {
|
|
|
25
25
|
event(id) {
|
|
26
26
|
return this.runQuery(Queries.SingleEventQuery)(id);
|
|
27
27
|
}
|
|
28
|
+
/** Returns a single event */
|
|
29
|
+
events(ids) {
|
|
30
|
+
return this.runQuery(Queries.MultipleEventsQuery)(ids);
|
|
31
|
+
}
|
|
28
32
|
/** Returns the latest version of a replaceable event */
|
|
29
33
|
replaceable(kind, pubkey, d) {
|
|
30
34
|
return this.runQuery(Queries.ReplaceableQuery)(kind, pubkey, d);
|
|
31
35
|
}
|
|
36
|
+
/** Returns a directory of events by their UID */
|
|
37
|
+
replaceableSet(pointers) {
|
|
38
|
+
return this.runQuery(Queries.ReplaceableSetQuery)(pointers);
|
|
39
|
+
}
|
|
32
40
|
/** Returns an array of events that match the filter */
|
|
33
41
|
timeline(filters) {
|
|
34
42
|
return this.runQuery(Queries.TimelineQuery)(filters);
|
|
@@ -45,10 +53,6 @@ export class QueryStore {
|
|
|
45
53
|
mailboxes(pubkey) {
|
|
46
54
|
return this.runQuery(Queries.MailboxesQuery)(pubkey);
|
|
47
55
|
}
|
|
48
|
-
/** Returns the parsed mute list for the pubkey */
|
|
49
|
-
mute(pubkey) {
|
|
50
|
-
return this.runQuery(Queries.UserMuteQuery)(pubkey);
|
|
51
|
-
}
|
|
52
56
|
thread(root) {
|
|
53
57
|
return this.runQuery(Queries.ThreadQuery)(root);
|
|
54
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,10 +22,26 @@
|
|
|
22
22
|
"import": "./dist/helpers/index.js",
|
|
23
23
|
"types": "./dist/helpers/index.d.ts"
|
|
24
24
|
},
|
|
25
|
+
"./helpers/*": {
|
|
26
|
+
"import": "./dist/helpers/*.js",
|
|
27
|
+
"types": "./dist/helpers/*.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./queries": {
|
|
30
|
+
"import": "./dist/queries/index.js",
|
|
31
|
+
"types": "./dist/queries/index.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./queries/*": {
|
|
34
|
+
"import": "./dist/queries/*.js",
|
|
35
|
+
"types": "./dist/queries/*.d.ts"
|
|
36
|
+
},
|
|
25
37
|
"./observable": {
|
|
26
38
|
"import": "./dist/observable/index.js",
|
|
27
39
|
"types": "./dist/observable/index.d.ts"
|
|
28
40
|
},
|
|
41
|
+
"./promise": {
|
|
42
|
+
"import": "./dist/promise/index.js",
|
|
43
|
+
"types": "./dist/promise/index.d.ts"
|
|
44
|
+
},
|
|
29
45
|
"./query-store": {
|
|
30
46
|
"import": "./dist/query-store/index.js",
|
|
31
47
|
"types": "./dist/query-store/index.d.ts"
|
|
@@ -33,28 +49,24 @@
|
|
|
33
49
|
"./event-store": {
|
|
34
50
|
"import": "./dist/event-store/index.js",
|
|
35
51
|
"types": "./dist/event-store/index.d.ts"
|
|
36
|
-
},
|
|
37
|
-
"./queries": {
|
|
38
|
-
"import": "./dist/queries/index.js",
|
|
39
|
-
"types": "./dist/queries/index.d.ts"
|
|
40
52
|
}
|
|
41
53
|
},
|
|
42
54
|
"dependencies": {
|
|
43
|
-
"@types/zen-push": "^0.1.4",
|
|
44
55
|
"debug": "^4.3.7",
|
|
45
56
|
"json-stringify-deterministic": "^1.0.12",
|
|
46
57
|
"nanoid": "^5.0.7",
|
|
47
58
|
"nostr-tools": "^2.7.2",
|
|
48
|
-
"zen-push": "^0.3.1"
|
|
59
|
+
"zen-push": "^0.3.1",
|
|
60
|
+
"zen-observable": "^0.10.0"
|
|
49
61
|
},
|
|
50
62
|
"devDependencies": {
|
|
63
|
+
"@types/zen-push": "^0.1.4",
|
|
51
64
|
"@jest/globals": "^29.7.0",
|
|
52
65
|
"@types/debug": "^4.1.12",
|
|
53
66
|
"@types/jest": "^29.5.13",
|
|
54
67
|
"@types/zen-observable": "^0.8.7",
|
|
55
68
|
"jest": "^29.7.0",
|
|
56
|
-
"jest-extended": "^4.0.2"
|
|
57
|
-
"zen-observable": "^0.10.0"
|
|
69
|
+
"jest-extended": "^4.0.2"
|
|
58
70
|
},
|
|
59
71
|
"jest": {
|
|
60
72
|
"roots": [
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { nip19, NostrEvent } from "nostr-tools";
|
|
2
|
-
import { ChannelMetadata } from "nostr-tools/nip28";
|
|
3
|
-
export declare const ChannelMetadataSymbol: unique symbol;
|
|
4
|
-
declare module "nostr-tools" {
|
|
5
|
-
interface Event {
|
|
6
|
-
[ChannelMetadataSymbol]?: ChannelMetadataContent;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export type ChannelMetadataContent = ChannelMetadata & {
|
|
10
|
-
relays?: string[];
|
|
11
|
-
};
|
|
12
|
-
/** Gets the parsed metadata on a channel creation or channel metadata event */
|
|
13
|
-
export declare function getChannelMetadataContent(channel: NostrEvent): ChannelMetadataContent;
|
|
14
|
-
/** gets the EventPointer for a channel message or metadata event */
|
|
15
|
-
export declare function getChannelPointer(event: NostrEvent): nip19.EventPointer | undefined;
|
package/dist/helpers/channel.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const ChannelMetadataSymbol = Symbol.for("channel-metadata");
|
|
2
|
-
function parseChannelMetadataContent(channel) {
|
|
3
|
-
const metadata = JSON.parse(channel.content);
|
|
4
|
-
if (metadata.name === undefined)
|
|
5
|
-
throw new Error("Missing name");
|
|
6
|
-
if (metadata.about === undefined)
|
|
7
|
-
throw new Error("Missing about");
|
|
8
|
-
if (metadata.picture === undefined)
|
|
9
|
-
throw new Error("Missing picture");
|
|
10
|
-
if (metadata.relays && !Array.isArray(metadata.relays))
|
|
11
|
-
throw new Error("Invalid relays");
|
|
12
|
-
return metadata;
|
|
13
|
-
}
|
|
14
|
-
/** Gets the parsed metadata on a channel creation or channel metadata event */
|
|
15
|
-
export function getChannelMetadataContent(channel) {
|
|
16
|
-
let metadata = channel[ChannelMetadataSymbol];
|
|
17
|
-
if (!metadata)
|
|
18
|
-
metadata = channel[ChannelMetadataSymbol] = parseChannelMetadataContent(channel);
|
|
19
|
-
return metadata;
|
|
20
|
-
}
|
|
21
|
-
/** gets the EventPointer for a channel message or metadata event */
|
|
22
|
-
export function getChannelPointer(event) {
|
|
23
|
-
const tag = event.tags.find((t) => t[0] === "e" && t[1]);
|
|
24
|
-
if (!tag)
|
|
25
|
-
return undefined;
|
|
26
|
-
return tag[2] ? { id: tag[1], relays: [tag[2]] } : { id: tag[1] };
|
|
27
|
-
}
|
package/dist/helpers/mute.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { NostrEvent } from "nostr-tools";
|
|
2
|
-
export declare const MutePubkeysSymbol: unique symbol;
|
|
3
|
-
export declare const MuteThreadsSymbol: unique symbol;
|
|
4
|
-
export declare const MuteHashtagsSymbol: unique symbol;
|
|
5
|
-
export declare const MuteWordsSymbol: unique symbol;
|
|
6
|
-
declare module "nostr-tools" {
|
|
7
|
-
interface Event {
|
|
8
|
-
[MutePubkeysSymbol]?: Set<string>;
|
|
9
|
-
[MuteThreadsSymbol]?: Set<string>;
|
|
10
|
-
[MuteHashtagsSymbol]?: Set<string>;
|
|
11
|
-
[MuteWordsSymbol]?: Set<string>;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/** Returns a set of muted pubkeys */
|
|
15
|
-
export declare function getMutedPubkeys(mute: NostrEvent): Set<string>;
|
|
16
|
-
/** Returns a set of muted threads */
|
|
17
|
-
export declare function getMutedThreads(mute: NostrEvent): Set<string>;
|
|
18
|
-
/** Returns a set of muted words ( lowercase ) */
|
|
19
|
-
export declare function getMutedWords(mute: NostrEvent): Set<string>;
|
|
20
|
-
/** Returns a set of muted hashtags ( lowercase ) */
|
|
21
|
-
export declare function getMutedHashtags(mute: NostrEvent): Set<string>;
|
package/dist/helpers/mute.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export const MutePubkeysSymbol = Symbol.for("mute-pubkeys");
|
|
2
|
-
export const MuteThreadsSymbol = Symbol.for("mute-threads");
|
|
3
|
-
export const MuteHashtagsSymbol = Symbol.for("mute-hashtags");
|
|
4
|
-
export const MuteWordsSymbol = Symbol.for("mute-words");
|
|
5
|
-
/** Returns a set of muted pubkeys */
|
|
6
|
-
export function getMutedPubkeys(mute) {
|
|
7
|
-
let pubkeys = mute[MutePubkeysSymbol];
|
|
8
|
-
if (!pubkeys) {
|
|
9
|
-
pubkeys = mute[MutePubkeysSymbol] = new Set();
|
|
10
|
-
for (const tag of mute.tags) {
|
|
11
|
-
if (tag[0] === "p" && tag[1])
|
|
12
|
-
pubkeys.add(tag[1]);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return pubkeys;
|
|
16
|
-
}
|
|
17
|
-
/** Returns a set of muted threads */
|
|
18
|
-
export function getMutedThreads(mute) {
|
|
19
|
-
let threads = mute[MuteThreadsSymbol];
|
|
20
|
-
if (!threads) {
|
|
21
|
-
threads = mute[MuteThreadsSymbol] = new Set();
|
|
22
|
-
for (const tag of mute.tags) {
|
|
23
|
-
if (tag[0] === "e" && tag[1])
|
|
24
|
-
threads.add(tag[1]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return threads;
|
|
28
|
-
}
|
|
29
|
-
/** Returns a set of muted words ( lowercase ) */
|
|
30
|
-
export function getMutedWords(mute) {
|
|
31
|
-
let words = mute[MuteWordsSymbol];
|
|
32
|
-
if (!words) {
|
|
33
|
-
words = mute[MuteWordsSymbol] = new Set();
|
|
34
|
-
for (const tag of mute.tags) {
|
|
35
|
-
if (tag[0] === "word" && tag[1])
|
|
36
|
-
words.add(tag[1].toLocaleLowerCase());
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return words;
|
|
40
|
-
}
|
|
41
|
-
/** Returns a set of muted hashtags ( lowercase ) */
|
|
42
|
-
export function getMutedHashtags(mute) {
|
|
43
|
-
let hashtags = mute[MuteHashtagsSymbol];
|
|
44
|
-
if (!hashtags) {
|
|
45
|
-
hashtags = mute[MuteHashtagsSymbol] = new Set();
|
|
46
|
-
for (const tag of mute.tags) {
|
|
47
|
-
if (tag[0] === "t" && tag[1])
|
|
48
|
-
hashtags.add(tag[1].toLocaleLowerCase());
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return hashtags;
|
|
52
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { NostrEvent } from "nostr-tools";
|
|
2
|
-
import { Query } from "../query-store/index.js";
|
|
3
|
-
import { ChannelMetadataContent } from "../helpers/channel.js";
|
|
4
|
-
/** Creates a query that returns the latest parsed metadata */
|
|
5
|
-
export declare function ChannelMetadataQuery(channel: NostrEvent): Query<ChannelMetadataContent | undefined>;
|
|
6
|
-
/** Creates a query that returns a map of hidden messages Map<id, reason> */
|
|
7
|
-
export declare function ChannelHiddenQuery(channel: NostrEvent, authors?: string[]): Query<Map<string, string>>;
|
|
8
|
-
/** Creates a query that returns a map of muted users Map<pubkey, reason> */
|
|
9
|
-
export declare function ChannelMutedQuery(channel: NostrEvent, authors?: string[]): Query<Map<string, string>>;
|
|
10
|
-
/** Creates a query that returns all messages in a channel */
|
|
11
|
-
export declare function ChannelMessagesQuery(channel: NostrEvent): Query<NostrEvent[]>;
|
package/dist/queries/channel.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { kinds } from "nostr-tools";
|
|
2
|
-
import { getChannelMetadataContent } from "../helpers/channel.js";
|
|
3
|
-
import { safeParse } from "../helpers/json.js";
|
|
4
|
-
/** Creates a query that returns the latest parsed metadata */
|
|
5
|
-
export function ChannelMetadataQuery(channel) {
|
|
6
|
-
return {
|
|
7
|
-
key: channel.id,
|
|
8
|
-
run: (events) => {
|
|
9
|
-
const filters = [
|
|
10
|
-
{ ids: [channel.id] },
|
|
11
|
-
{ kinds: [kinds.ChannelMetadata], "#e": [channel.id], authors: [channel.pubkey] },
|
|
12
|
-
];
|
|
13
|
-
let latest = channel;
|
|
14
|
-
return events.stream(filters).map((event) => {
|
|
15
|
-
try {
|
|
16
|
-
if (event.pubkey === latest.pubkey && event.created_at > latest.created_at) {
|
|
17
|
-
latest = event;
|
|
18
|
-
}
|
|
19
|
-
return getChannelMetadataContent(latest);
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/** Creates a query that returns a map of hidden messages Map<id, reason> */
|
|
29
|
-
export function ChannelHiddenQuery(channel, authors = []) {
|
|
30
|
-
return {
|
|
31
|
-
key: channel.id,
|
|
32
|
-
run: (events) => {
|
|
33
|
-
const hidden = new Map();
|
|
34
|
-
return events
|
|
35
|
-
.stream([{ kinds: [kinds.ChannelHideMessage], "#e": [channel.id], authors: [channel.pubkey, ...authors] }])
|
|
36
|
-
.map((event) => {
|
|
37
|
-
const reason = safeParse(event.content)?.reason;
|
|
38
|
-
for (const tag of event.tags) {
|
|
39
|
-
if (tag[0] === "e" && tag[1])
|
|
40
|
-
hidden.set(tag[1], reason ?? "");
|
|
41
|
-
}
|
|
42
|
-
return hidden;
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
/** Creates a query that returns a map of muted users Map<pubkey, reason> */
|
|
48
|
-
export function ChannelMutedQuery(channel, authors = []) {
|
|
49
|
-
return {
|
|
50
|
-
key: channel.id + authors.join(","),
|
|
51
|
-
run: (events) => {
|
|
52
|
-
const muted = new Map();
|
|
53
|
-
return events
|
|
54
|
-
.stream([{ kinds: [kinds.ChannelMuteUser], "#e": [channel.id], authors: [channel.pubkey, ...authors] }])
|
|
55
|
-
.map((event) => {
|
|
56
|
-
const reason = safeParse(event.content)?.reason;
|
|
57
|
-
for (const tag of event.tags) {
|
|
58
|
-
if (tag[0] === "p" && tag[1])
|
|
59
|
-
muted.set(tag[1], reason ?? "");
|
|
60
|
-
}
|
|
61
|
-
return muted;
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/** Creates a query that returns all messages in a channel */
|
|
67
|
-
export function ChannelMessagesQuery(channel) {
|
|
68
|
-
return {
|
|
69
|
-
key: channel.id,
|
|
70
|
-
run: (events) => events.timeline([{ kinds: [kinds.ChannelMessage], "#e": [channel.id] }]),
|
|
71
|
-
};
|
|
72
|
-
}
|
package/dist/queries/mute.d.ts
DELETED
package/dist/queries/mute.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { kinds } from "nostr-tools";
|
|
2
|
-
import { getMutedHashtags, getMutedPubkeys, getMutedThreads, getMutedWords } from "../helpers/mute.js";
|
|
3
|
-
export function UserMuteQuery(pubkey) {
|
|
4
|
-
return {
|
|
5
|
-
key: pubkey,
|
|
6
|
-
run: (store) => store.replaceable(kinds.Mutelist, pubkey).map((event) => {
|
|
7
|
-
if (!event)
|
|
8
|
-
return;
|
|
9
|
-
const pubkeys = getMutedPubkeys(event);
|
|
10
|
-
const threads = getMutedThreads(event);
|
|
11
|
-
const hashtags = getMutedHashtags(event);
|
|
12
|
-
const words = getMutedWords(event);
|
|
13
|
-
return { pubkeys, threads, hashtags, words };
|
|
14
|
-
}),
|
|
15
|
-
};
|
|
16
|
-
}
|