applesauce-core 0.9.0 → 0.10.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/README.md +1 -1
- package/dist/event-store/database.d.ts +17 -13
- package/dist/event-store/database.js +50 -33
- package/dist/event-store/event-store.d.ts +37 -14
- package/dist/event-store/event-store.js +249 -96
- package/dist/helpers/bolt11.d.ts +1 -0
- package/dist/helpers/bolt11.js +1 -0
- package/dist/helpers/comment.d.ts +48 -0
- package/dist/helpers/comment.js +116 -0
- package/dist/helpers/content.d.ts +3 -0
- package/dist/helpers/content.js +8 -0
- package/dist/helpers/delete.d.ts +3 -0
- package/dist/helpers/delete.js +7 -0
- package/dist/helpers/emoji.d.ts +10 -1
- package/dist/helpers/emoji.js +12 -0
- package/dist/helpers/event.d.ts +9 -1
- package/dist/helpers/event.js +25 -1
- package/dist/helpers/external-id.d.ts +29 -0
- package/dist/helpers/external-id.js +20 -0
- package/dist/helpers/filter.d.ts +0 -2
- package/dist/helpers/filter.js +3 -7
- package/dist/helpers/hidden-tags.d.ts +48 -0
- package/dist/helpers/hidden-tags.js +108 -0
- package/dist/helpers/hidden-tags.test.d.ts +1 -0
- package/dist/helpers/hidden-tags.test.js +28 -0
- package/dist/helpers/index.d.ts +16 -8
- package/dist/helpers/index.js +16 -8
- package/dist/helpers/json.d.ts +1 -0
- package/dist/helpers/json.js +1 -0
- package/dist/helpers/lnurl.d.ts +4 -0
- package/dist/helpers/lnurl.js +40 -0
- package/dist/helpers/mailboxes.test.js +13 -12
- package/dist/helpers/media-attachment.d.ts +33 -0
- package/dist/helpers/media-attachment.js +60 -0
- package/dist/helpers/pointers.d.ts +38 -5
- package/dist/helpers/pointers.js +101 -17
- package/dist/helpers/profile.js +1 -1
- package/dist/helpers/string.d.ts +6 -0
- package/dist/helpers/string.js +2 -0
- package/dist/helpers/tags.d.ts +6 -0
- package/dist/helpers/tags.js +6 -0
- package/dist/helpers/threading.d.ts +6 -6
- package/dist/helpers/threading.js +30 -9
- package/dist/helpers/threading.test.d.ts +1 -0
- package/dist/helpers/threading.test.js +41 -0
- package/dist/helpers/url.d.ts +4 -1
- package/dist/helpers/url.js +4 -3
- package/dist/helpers/zap.d.ts +25 -0
- package/dist/helpers/zap.js +32 -3
- package/dist/observable/{getValue.d.ts → get-value.d.ts} +1 -0
- package/dist/observable/{getValue.js → get-value.js} +1 -0
- package/dist/observable/index.d.ts +1 -1
- package/dist/observable/index.js +1 -1
- package/dist/promise/deferred.d.ts +1 -0
- package/dist/promise/deferred.js +1 -0
- package/dist/queries/comments.d.ts +4 -0
- package/dist/queries/comments.js +14 -0
- package/dist/queries/index.d.ts +3 -2
- package/dist/queries/index.js +3 -2
- package/dist/queries/mailboxes.d.ts +1 -0
- package/dist/queries/mailboxes.js +1 -0
- package/dist/queries/profile.d.ts +1 -0
- package/dist/queries/profile.js +1 -0
- package/dist/queries/reactions.d.ts +1 -1
- package/dist/queries/reactions.js +1 -1
- package/dist/queries/simple.d.ts +3 -3
- package/dist/queries/simple.js +13 -13
- package/dist/queries/thread.d.ts +2 -0
- package/dist/queries/thread.js +29 -3
- package/dist/queries/zaps.d.ts +1 -0
- package/dist/queries/zaps.js +1 -0
- package/dist/query-store/index.d.ts +22 -12
- package/dist/query-store/index.js +36 -30
- package/package.json +10 -18
package/dist/helpers/zap.js
CHANGED
|
@@ -2,43 +2,56 @@ import { kinds, nip57 } from "nostr-tools";
|
|
|
2
2
|
import { getOrComputeCachedValue } from "./cache.js";
|
|
3
3
|
import { getTagValue } from "./event.js";
|
|
4
4
|
import { isATag, isETag } from "./tags.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getAddressPointerFromATag, getEventPointerFromETag } from "./pointers.js";
|
|
6
6
|
import { parseBolt11 } from "./bolt11.js";
|
|
7
7
|
export const ZapRequestSymbol = Symbol.for("zap-request");
|
|
8
8
|
export const ZapFromSymbol = Symbol.for("zap-from");
|
|
9
9
|
export const ZapInvoiceSymbol = Symbol.for("zap-bolt11");
|
|
10
10
|
export const ZapEventPointerSymbol = Symbol.for("zap-event-pointer");
|
|
11
11
|
export const ZapAddressPointerSymbol = Symbol.for("zap-address-pointer");
|
|
12
|
+
/** Returns the senders pubkey */
|
|
12
13
|
export function getZapSender(zap) {
|
|
13
14
|
return getTagValue(zap, "P") || getZapRequest(zap).pubkey;
|
|
14
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets the receivers pubkey
|
|
18
|
+
* @throws
|
|
19
|
+
*/
|
|
15
20
|
export function getZapRecipient(zap) {
|
|
16
21
|
const recipient = getTagValue(zap, "p");
|
|
17
22
|
if (!recipient)
|
|
18
23
|
throw new Error("Missing recipient");
|
|
19
24
|
return recipient;
|
|
20
25
|
}
|
|
26
|
+
/** Returns the parsed bolt11 invoice */
|
|
21
27
|
export function getZapPayment(zap) {
|
|
22
28
|
return getOrComputeCachedValue(zap, ZapInvoiceSymbol, () => {
|
|
23
29
|
const bolt11 = getTagValue(zap, "bolt11");
|
|
24
30
|
return bolt11 ? parseBolt11(bolt11) : undefined;
|
|
25
31
|
});
|
|
26
32
|
}
|
|
33
|
+
/** Gets the AddressPointer that was zapped */
|
|
27
34
|
export function getZapAddressPointer(zap) {
|
|
28
35
|
return getOrComputeCachedValue(zap, ZapAddressPointerSymbol, () => {
|
|
29
36
|
const a = zap.tags.find(isATag);
|
|
30
|
-
return a ?
|
|
37
|
+
return a ? getAddressPointerFromATag(a) : null;
|
|
31
38
|
});
|
|
32
39
|
}
|
|
40
|
+
/** Gets the EventPointer that was zapped */
|
|
33
41
|
export function getZapEventPointer(zap) {
|
|
34
42
|
return getOrComputeCachedValue(zap, ZapEventPointerSymbol, () => {
|
|
35
43
|
const e = zap.tags.find(isETag);
|
|
36
|
-
return e ?
|
|
44
|
+
return e ? getEventPointerFromETag(e) : null;
|
|
37
45
|
});
|
|
38
46
|
}
|
|
47
|
+
/** Gets the preimage for the bolt11 invoice */
|
|
39
48
|
export function getZapPreimage(zap) {
|
|
40
49
|
return getTagValue(zap, "preimage");
|
|
41
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns the zap request event inside the zap receipt
|
|
53
|
+
* @throws
|
|
54
|
+
*/
|
|
42
55
|
export function getZapRequest(zap) {
|
|
43
56
|
return getOrComputeCachedValue(zap, ZapRequestSymbol, () => {
|
|
44
57
|
const description = getTagValue(zap, "description");
|
|
@@ -50,6 +63,10 @@ export function getZapRequest(zap) {
|
|
|
50
63
|
return JSON.parse(description);
|
|
51
64
|
});
|
|
52
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the zap is valid
|
|
68
|
+
* DOES NOT validate LNURL address
|
|
69
|
+
*/
|
|
53
70
|
export function isValidZap(zap) {
|
|
54
71
|
if (!zap)
|
|
55
72
|
return false;
|
|
@@ -64,3 +81,15 @@ export function isValidZap(zap) {
|
|
|
64
81
|
return false;
|
|
65
82
|
}
|
|
66
83
|
}
|
|
84
|
+
/** Returns the zap splits for an event */
|
|
85
|
+
export function getZapSplits(event) {
|
|
86
|
+
const tags = event.tags.filter((t) => t[0] === "zap" && t[1] && t[3]);
|
|
87
|
+
if (tags.length > 0) {
|
|
88
|
+
const targets = tags
|
|
89
|
+
.map((t) => ({ pubkey: t[1], relay: t[2], weight: parseFloat(t[3]) }))
|
|
90
|
+
.filter((p) => Number.isFinite(p.weight));
|
|
91
|
+
const total = targets.reduce((v, p) => v + p.weight, 0);
|
|
92
|
+
return targets.map((p) => ({ ...p, percent: p.weight / total }));
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./get-value.js";
|
|
2
2
|
export * from "./share-latest-value.js";
|
package/dist/observable/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./get-value.js";
|
|
2
2
|
export * from "./share-latest-value.js";
|
package/dist/promise/deferred.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { COMMENT_KIND, getEventUID } from "../helpers/index.js";
|
|
2
|
+
import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
|
|
3
|
+
/** Returns all NIP-22 comment replies for the event */
|
|
4
|
+
export function CommentsQuery(parent) {
|
|
5
|
+
return {
|
|
6
|
+
key: `${getEventUID(parent)}-comments`,
|
|
7
|
+
run: (events) => {
|
|
8
|
+
const filter = { kinds: [COMMENT_KIND], "#e": [parent.id] };
|
|
9
|
+
if (isParameterizedReplaceableKind(parent.kind))
|
|
10
|
+
filter["#a"] = [getEventUID(parent)];
|
|
11
|
+
return events.timeline(filter);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
package/dist/queries/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./profile.js";
|
|
1
|
+
export * from "./comments.js";
|
|
3
2
|
export * from "./mailboxes.js";
|
|
3
|
+
export * from "./profile.js";
|
|
4
4
|
export * from "./reactions.js";
|
|
5
|
+
export * from "./simple.js";
|
|
5
6
|
export * from "./thread.js";
|
|
6
7
|
export * from "./zaps.js";
|
package/dist/queries/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./profile.js";
|
|
1
|
+
export * from "./comments.js";
|
|
3
2
|
export * from "./mailboxes.js";
|
|
3
|
+
export * from "./profile.js";
|
|
4
4
|
export * from "./reactions.js";
|
|
5
|
+
export * from "./simple.js";
|
|
5
6
|
export * from "./thread.js";
|
|
6
7
|
export * from "./zaps.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { kinds } from "nostr-tools";
|
|
2
2
|
import { map } from "rxjs/operators";
|
|
3
3
|
import { getInboxes, getOutboxes } from "../helpers/mailboxes.js";
|
|
4
|
+
/** A query that gets and parses the inbox and outbox relays for a pubkey */
|
|
4
5
|
export function MailboxesQuery(pubkey) {
|
|
5
6
|
return {
|
|
6
7
|
key: pubkey,
|
package/dist/queries/profile.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { kinds } from "nostr-tools";
|
|
2
2
|
import { filter, map } from "rxjs/operators";
|
|
3
3
|
import { getProfileContent, isValidProfile } from "../helpers/profile.js";
|
|
4
|
+
/** A query that gets and parses the kind 0 metadata for a pubkey */
|
|
4
5
|
export function ProfileQuery(pubkey) {
|
|
5
6
|
return {
|
|
6
7
|
key: pubkey,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { NostrEvent } from "nostr-tools";
|
|
2
2
|
import { Query } from "../query-store/index.js";
|
|
3
|
-
/**
|
|
3
|
+
/** A query that returns all reactions to an event (supports replaceable events) */
|
|
4
4
|
export declare function ReactionsQuery(event: NostrEvent): Query<NostrEvent[]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { kinds } from "nostr-tools";
|
|
2
2
|
import { getEventUID, isReplaceable } from "../helpers/event.js";
|
|
3
|
-
/**
|
|
3
|
+
/** A query that returns all reactions to an event (supports replaceable events) */
|
|
4
4
|
export function ReactionsQuery(event) {
|
|
5
5
|
return {
|
|
6
6
|
key: getEventUID(event),
|
package/dist/queries/simple.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Filter, NostrEvent } from "nostr-tools";
|
|
2
2
|
import { Query } from "../query-store/index.js";
|
|
3
3
|
/** Creates a Query that returns a single event or undefined */
|
|
4
|
-
export declare function SingleEventQuery(
|
|
4
|
+
export declare function SingleEventQuery(id: string): Query<NostrEvent | undefined>;
|
|
5
5
|
/** Creates a Query that returns a multiple events in a map */
|
|
6
|
-
export declare function MultipleEventsQuery(
|
|
6
|
+
export declare function MultipleEventsQuery(ids: string[]): Query<Map<string, NostrEvent>>;
|
|
7
7
|
/** Creates a Query returning the latest version of a replaceable event */
|
|
8
8
|
export declare function ReplaceableQuery(kind: number, pubkey: string, d?: string): Query<NostrEvent | undefined>;
|
|
9
9
|
/** Creates a Query that returns an array of sorted events matching the filters */
|
|
10
|
-
export declare function TimelineQuery(filters: Filter | Filter[]): Query<NostrEvent[]>;
|
|
10
|
+
export declare function TimelineQuery(filters: Filter | Filter[], keepOldVersions?: boolean): Query<NostrEvent[]>;
|
|
11
11
|
/** Creates a Query that returns a directory of events by their UID */
|
|
12
12
|
export declare function ReplaceableSetQuery(pointers: {
|
|
13
13
|
kind: number;
|
package/dist/queries/simple.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import hash_sum from "hash-sum";
|
|
2
2
|
import { getReplaceableUID } from "../helpers/event.js";
|
|
3
3
|
/** Creates a Query that returns a single event or undefined */
|
|
4
|
-
export function SingleEventQuery(
|
|
4
|
+
export function SingleEventQuery(id) {
|
|
5
5
|
return {
|
|
6
|
-
key:
|
|
7
|
-
run: (events) => events.event(
|
|
6
|
+
key: id,
|
|
7
|
+
run: (events) => events.event(id),
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
/** Creates a Query that returns a multiple events in a map */
|
|
11
|
-
export function MultipleEventsQuery(
|
|
11
|
+
export function MultipleEventsQuery(ids) {
|
|
12
12
|
return {
|
|
13
|
-
key:
|
|
14
|
-
run: (events) => events.events(
|
|
13
|
+
key: ids.join(","),
|
|
14
|
+
run: (events) => events.events(ids),
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
/** Creates a Query returning the latest version of a replaceable event */
|
|
@@ -22,17 +22,17 @@ export function ReplaceableQuery(kind, pubkey, d) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
/** Creates a Query that returns an array of sorted events matching the filters */
|
|
25
|
-
export function TimelineQuery(filters) {
|
|
25
|
+
export function TimelineQuery(filters, keepOldVersions) {
|
|
26
|
+
filters = Array.isArray(filters) ? filters : [filters];
|
|
26
27
|
return {
|
|
27
|
-
key:
|
|
28
|
-
run: (events) => events.timeline(
|
|
28
|
+
key: hash_sum(filters) + (keepOldVersions ? "-history" : ""),
|
|
29
|
+
run: (events) => events.timeline(filters, keepOldVersions),
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
/** Creates a Query that returns a directory of events by their UID */
|
|
32
33
|
export function ReplaceableSetQuery(pointers) {
|
|
33
|
-
const cords = pointers.map((pointer) => getReplaceableUID(pointer.kind, pointer.pubkey, pointer.identifier));
|
|
34
34
|
return {
|
|
35
|
-
key:
|
|
36
|
-
run: (events) => events.
|
|
35
|
+
key: hash_sum(pointers),
|
|
36
|
+
run: (events) => events.replaceableSet(pointers),
|
|
37
37
|
};
|
|
38
38
|
}
|
package/dist/queries/thread.d.ts
CHANGED
|
@@ -21,3 +21,5 @@ export type ThreadQueryOptions = {
|
|
|
21
21
|
kinds?: number[];
|
|
22
22
|
};
|
|
23
23
|
export declare function ThreadQuery(root: string | AddressPointer | EventPointer, opts?: ThreadQueryOptions): Query<Thread>;
|
|
24
|
+
/** A query that gets all legacy and NIP-10, and NIP-22 replies for an event */
|
|
25
|
+
export declare function RepliesQuery(event: NostrEvent, overrideKinds?: number[]): Query<NostrEvent[]>;
|
package/dist/queries/thread.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { kinds } from "nostr-tools";
|
|
2
|
+
import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
|
|
2
3
|
import { map } from "rxjs/operators";
|
|
3
|
-
import { getNip10References } from "../helpers/threading.js";
|
|
4
|
-
import { getCoordinateFromAddressPointer, isAddressPointer } from "../helpers/pointers.js";
|
|
5
|
-
import { getEventUID } from "../helpers/event.js";
|
|
4
|
+
import { getNip10References, interpretThreadTags } from "../helpers/threading.js";
|
|
5
|
+
import { getCoordinateFromAddressPointer, isAddressPointer, isEventPointer } from "../helpers/pointers.js";
|
|
6
|
+
import { getEventUID, getReplaceableUID, getTagValue, isEvent } from "../helpers/event.js";
|
|
7
|
+
import { COMMENT_KIND } from "../helpers/comment.js";
|
|
6
8
|
const defaultOptions = {
|
|
7
9
|
kinds: [kinds.ShortTextNote],
|
|
8
10
|
};
|
|
@@ -64,3 +66,27 @@ export function ThreadQuery(root, opts) {
|
|
|
64
66
|
})),
|
|
65
67
|
};
|
|
66
68
|
}
|
|
69
|
+
/** A query that gets all legacy and NIP-10, and NIP-22 replies for an event */
|
|
70
|
+
export function RepliesQuery(event, overrideKinds) {
|
|
71
|
+
return {
|
|
72
|
+
key: getEventUID(event),
|
|
73
|
+
run: (events) => {
|
|
74
|
+
const kinds = overrideKinds || event.kind === 1 ? [1, COMMENT_KIND] : [COMMENT_KIND];
|
|
75
|
+
const filter = { kinds };
|
|
76
|
+
if (isEvent(parent) || isEventPointer(event))
|
|
77
|
+
filter["#e"] = [event.id];
|
|
78
|
+
const address = isParameterizedReplaceableKind(event.kind)
|
|
79
|
+
? getReplaceableUID(event.kind, event.pubkey, getTagValue(event, "d"))
|
|
80
|
+
: undefined;
|
|
81
|
+
if (address) {
|
|
82
|
+
filter["#a"] = [address];
|
|
83
|
+
}
|
|
84
|
+
return events.timeline(filter).pipe(map((events) => {
|
|
85
|
+
return events.filter((e) => {
|
|
86
|
+
const refs = interpretThreadTags(e.tags);
|
|
87
|
+
return refs.reply?.e?.[1] === event.id || refs.reply?.a?.[1] === address;
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
package/dist/queries/zaps.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AddressPointer, EventPointer } from "nostr-tools/nip19";
|
|
2
2
|
import { NostrEvent } from "nostr-tools";
|
|
3
3
|
import { Query } from "../query-store/index.js";
|
|
4
|
+
/** A query that gets all zap events for an event */
|
|
4
5
|
export declare function EventZapsQuery(id: string | EventPointer | AddressPointer): Query<NostrEvent[]>;
|
package/dist/queries/zaps.js
CHANGED
|
@@ -2,6 +2,7 @@ import { map } from "rxjs";
|
|
|
2
2
|
import { kinds } from "nostr-tools";
|
|
3
3
|
import { getCoordinateFromAddressPointer, isAddressPointer } from "../helpers/pointers.js";
|
|
4
4
|
import { isValidZap } from "../helpers/zap.js";
|
|
5
|
+
/** A query that gets all zap events for an event */
|
|
5
6
|
export function EventZapsQuery(id) {
|
|
6
7
|
return {
|
|
7
8
|
key: JSON.stringify(id),
|
|
@@ -5,7 +5,15 @@ import { LRU } from "../helpers/lru.js";
|
|
|
5
5
|
import * as Queries from "../queries/index.js";
|
|
6
6
|
import { AddressPointer, EventPointer } from "nostr-tools/nip19";
|
|
7
7
|
export type Query<T extends unknown> = {
|
|
8
|
+
/**
|
|
9
|
+
* A unique key for this query. this is used to detect duplicate queries
|
|
10
|
+
*/
|
|
8
11
|
key: string;
|
|
12
|
+
/** The args array this query was created with. This is mostly for debugging */
|
|
13
|
+
args?: Array<any>;
|
|
14
|
+
/**
|
|
15
|
+
* The meat of the query, this should return an Observables that subscribes to the eventStore in some way
|
|
16
|
+
*/
|
|
9
17
|
run: (events: EventStore, store: QueryStore) => Observable<T>;
|
|
10
18
|
};
|
|
11
19
|
export type QueryConstructor<T extends unknown, Args extends Array<any>> = (...args: Args) => Query<T>;
|
|
@@ -13,35 +21,37 @@ export declare class QueryStore {
|
|
|
13
21
|
static Queries: typeof Queries;
|
|
14
22
|
store: EventStore;
|
|
15
23
|
constructor(store: EventStore);
|
|
16
|
-
queries: LRU<
|
|
24
|
+
queries: LRU<Query<any>>;
|
|
25
|
+
observables: WeakMap<Query<any>, Observable<any> | BehaviorSubject<any>>;
|
|
17
26
|
/** Creates a cached query */
|
|
18
|
-
|
|
27
|
+
createQuery<T extends unknown, Args extends Array<any>>(queryConstructor: (...args: Args) => {
|
|
19
28
|
key: string;
|
|
20
29
|
run: (events: EventStore, store: QueryStore) => Observable<T>;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
30
|
+
}, ...args: Args): Observable<T>;
|
|
31
|
+
/** Creates a SingleEventQuery */
|
|
23
32
|
event(id: string): Observable<import("nostr-tools").Event | undefined>;
|
|
24
|
-
/**
|
|
33
|
+
/** Creates a MultipleEventsQuery */
|
|
25
34
|
events(ids: string[]): Observable<Map<string, import("nostr-tools").Event>>;
|
|
26
|
-
/**
|
|
35
|
+
/** Creates a ReplaceableQuery */
|
|
27
36
|
replaceable(kind: number, pubkey: string, d?: string): Observable<import("nostr-tools").Event | undefined>;
|
|
28
|
-
/**
|
|
37
|
+
/** Creates a ReplaceableSetQuery */
|
|
29
38
|
replaceableSet(pointers: {
|
|
30
39
|
kind: number;
|
|
31
40
|
pubkey: string;
|
|
32
41
|
identifier?: string;
|
|
33
42
|
}[]): Observable<Map<string, import("nostr-tools").Event>>;
|
|
34
|
-
/**
|
|
35
|
-
timeline(filters: Filter | Filter[]): Observable<import("nostr-tools").Event[]>;
|
|
36
|
-
/**
|
|
43
|
+
/** Creates a TimelineQuery */
|
|
44
|
+
timeline(filters: Filter | Filter[], keepOldVersions?: boolean): Observable<import("nostr-tools").Event[]>;
|
|
45
|
+
/** Creates a ProfileQuery */
|
|
37
46
|
profile(pubkey: string): Observable<import("../helpers/profile.js").ProfileContent | undefined>;
|
|
38
|
-
/**
|
|
47
|
+
/** Creates a ReactionsQuery */
|
|
39
48
|
reactions(event: NostrEvent): Observable<import("nostr-tools").Event[]>;
|
|
40
|
-
/**
|
|
49
|
+
/** Creates a MailboxesQuery */
|
|
41
50
|
mailboxes(pubkey: string): Observable<{
|
|
42
51
|
inboxes: string[];
|
|
43
52
|
outboxes: string[];
|
|
44
53
|
} | undefined>;
|
|
54
|
+
/** Creates a ThreadQuery */
|
|
45
55
|
thread(root: string | EventPointer | AddressPointer): Observable<Queries.Thread>;
|
|
46
56
|
}
|
|
47
57
|
export { Queries };
|
|
@@ -8,53 +8,59 @@ export class QueryStore {
|
|
|
8
8
|
this.store = store;
|
|
9
9
|
}
|
|
10
10
|
queries = new LRU();
|
|
11
|
+
observables = new WeakMap();
|
|
11
12
|
/** Creates a cached query */
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
createQuery(queryConstructor, ...args) {
|
|
14
|
+
const tempQuery = queryConstructor(...args);
|
|
15
|
+
const key = `${queryConstructor.name}|${tempQuery.key}`;
|
|
16
|
+
let query = this.queries.get(key);
|
|
17
|
+
if (!query) {
|
|
18
|
+
query = tempQuery;
|
|
19
|
+
this.queries.set(key, tempQuery);
|
|
20
|
+
}
|
|
21
|
+
if (!this.observables.has(query)) {
|
|
22
|
+
query.args = args;
|
|
23
|
+
const observable = query.run(this.store, this).pipe(shareLatestValue());
|
|
24
|
+
this.observables.set(query, observable);
|
|
25
|
+
return observable;
|
|
26
|
+
}
|
|
27
|
+
return this.observables.get(query);
|
|
28
|
+
}
|
|
29
|
+
/** Creates a SingleEventQuery */
|
|
25
30
|
event(id) {
|
|
26
|
-
return this.
|
|
31
|
+
return this.createQuery(Queries.SingleEventQuery, id);
|
|
27
32
|
}
|
|
28
|
-
/**
|
|
33
|
+
/** Creates a MultipleEventsQuery */
|
|
29
34
|
events(ids) {
|
|
30
|
-
return this.
|
|
35
|
+
return this.createQuery(Queries.MultipleEventsQuery, ids);
|
|
31
36
|
}
|
|
32
|
-
/**
|
|
37
|
+
/** Creates a ReplaceableQuery */
|
|
33
38
|
replaceable(kind, pubkey, d) {
|
|
34
|
-
return this.
|
|
39
|
+
return this.createQuery(Queries.ReplaceableQuery, kind, pubkey, d);
|
|
35
40
|
}
|
|
36
|
-
/**
|
|
41
|
+
/** Creates a ReplaceableSetQuery */
|
|
37
42
|
replaceableSet(pointers) {
|
|
38
|
-
return this.
|
|
43
|
+
return this.createQuery(Queries.ReplaceableSetQuery, pointers);
|
|
39
44
|
}
|
|
40
|
-
/**
|
|
41
|
-
timeline(filters) {
|
|
42
|
-
return this.
|
|
45
|
+
/** Creates a TimelineQuery */
|
|
46
|
+
timeline(filters, keepOldVersions) {
|
|
47
|
+
return this.createQuery(Queries.TimelineQuery, filters, keepOldVersions);
|
|
43
48
|
}
|
|
44
|
-
/**
|
|
49
|
+
/** Creates a ProfileQuery */
|
|
45
50
|
profile(pubkey) {
|
|
46
|
-
return this.
|
|
51
|
+
return this.createQuery(Queries.ProfileQuery, pubkey);
|
|
47
52
|
}
|
|
48
|
-
/**
|
|
53
|
+
/** Creates a ReactionsQuery */
|
|
49
54
|
reactions(event) {
|
|
50
|
-
return this.
|
|
55
|
+
return this.createQuery(Queries.ReactionsQuery, event);
|
|
51
56
|
}
|
|
52
|
-
/**
|
|
57
|
+
/** Creates a MailboxesQuery */
|
|
53
58
|
mailboxes(pubkey) {
|
|
54
|
-
return this.
|
|
59
|
+
return this.createQuery(Queries.MailboxesQuery, pubkey);
|
|
55
60
|
}
|
|
61
|
+
/** Creates a ThreadQuery */
|
|
56
62
|
thread(root) {
|
|
57
|
-
return this.
|
|
63
|
+
return this.createQuery(Queries.ThreadQuery, root);
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
export { Queries };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,28 +52,20 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
+
"@scure/base": "^1.1.9",
|
|
55
56
|
"debug": "^4.3.7",
|
|
56
|
-
"
|
|
57
|
+
"fast-deep-equal": "^3.1.3",
|
|
58
|
+
"hash-sum": "^2.0.0",
|
|
57
59
|
"light-bolt11-decoder": "^3.2.0",
|
|
58
60
|
"nanoid": "^5.0.7",
|
|
59
|
-
"nostr-tools": "^2.10.
|
|
61
|
+
"nostr-tools": "^2.10.3",
|
|
60
62
|
"rxjs": "^7.8.1"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
63
|
-
"@jest/globals": "^29.7.0",
|
|
64
65
|
"@types/debug": "^4.1.12",
|
|
65
|
-
"@types/
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"typescript": "^5.6.3"
|
|
69
|
-
},
|
|
70
|
-
"jest": {
|
|
71
|
-
"roots": [
|
|
72
|
-
"dist"
|
|
73
|
-
],
|
|
74
|
-
"setupFilesAfterEnv": [
|
|
75
|
-
"jest-extended/all"
|
|
76
|
-
]
|
|
66
|
+
"@types/hash-sum": "^1.0.2",
|
|
67
|
+
"typescript": "^5.6.3",
|
|
68
|
+
"vitest": "^2.1.8"
|
|
77
69
|
},
|
|
78
70
|
"funding": {
|
|
79
71
|
"type": "lightning",
|
|
@@ -82,7 +74,7 @@
|
|
|
82
74
|
"scripts": {
|
|
83
75
|
"build": "tsc",
|
|
84
76
|
"watch:build": "tsc --watch > /dev/null",
|
|
85
|
-
"test": "
|
|
86
|
-
"watch:test": "
|
|
77
|
+
"test": "vitest run --passWithNoTests",
|
|
78
|
+
"watch:test": "vitest"
|
|
87
79
|
}
|
|
88
80
|
}
|