applesauce-core 0.12.0 → 1.0.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 +28 -10
- package/dist/event-store/__tests__/event-store.test.js +83 -1
- package/dist/event-store/database.d.ts +1 -0
- package/dist/event-store/database.js +7 -8
- package/dist/event-store/event-store.d.ts +4 -0
- package/dist/event-store/event-store.js +61 -22
- package/dist/event-store/interface.d.ts +11 -5
- package/dist/helpers/__tests__/bookmarks.test.d.ts +1 -0
- package/dist/helpers/__tests__/bookmarks.test.js +88 -0
- package/dist/helpers/__tests__/comment.test.js +14 -0
- package/dist/helpers/__tests__/contacts.test.d.ts +1 -0
- package/dist/helpers/__tests__/contacts.test.js +34 -0
- package/dist/helpers/__tests__/events.test.d.ts +1 -0
- package/dist/helpers/__tests__/events.test.js +32 -0
- package/dist/helpers/__tests__/mutes.test.d.ts +1 -0
- package/dist/helpers/__tests__/mutes.test.js +55 -0
- package/dist/helpers/bookmarks.d.ts +6 -1
- package/dist/helpers/bookmarks.js +52 -7
- package/dist/helpers/comment.d.ts +7 -3
- package/dist/helpers/comment.js +6 -1
- package/dist/helpers/contacts.d.ts +11 -0
- package/dist/helpers/contacts.js +34 -0
- package/dist/helpers/event.d.ts +8 -3
- package/dist/helpers/event.js +21 -13
- package/dist/helpers/lists.d.ts +40 -12
- package/dist/helpers/lists.js +62 -23
- package/dist/helpers/mutes.d.ts +8 -0
- package/dist/helpers/mutes.js +66 -5
- package/dist/helpers/nip-19.d.ts +14 -0
- package/dist/helpers/nip-19.js +29 -0
- package/dist/helpers/pointers.js +6 -6
- package/dist/observable/__tests__/listen-latest-updates.test.d.ts +1 -0
- package/dist/observable/__tests__/listen-latest-updates.test.js +55 -0
- package/dist/observable/defined.d.ts +3 -0
- package/dist/observable/defined.js +5 -0
- package/dist/observable/get-observable-value.d.ts +4 -1
- package/dist/observable/get-observable-value.js +4 -1
- package/dist/observable/index.d.ts +3 -1
- package/dist/observable/index.js +3 -1
- package/dist/observable/listen-latest-updates.d.ts +5 -0
- package/dist/observable/listen-latest-updates.js +12 -0
- package/dist/queries/blossom.js +1 -6
- package/dist/queries/bookmarks.d.ts +5 -5
- package/dist/queries/bookmarks.js +18 -17
- package/dist/queries/channels.js +41 -53
- package/dist/queries/comments.js +6 -9
- package/dist/queries/contacts.d.ts +6 -1
- package/dist/queries/contacts.js +21 -9
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/index.js +1 -0
- package/dist/queries/mailboxes.js +4 -7
- package/dist/queries/mutes.d.ts +6 -6
- package/dist/queries/mutes.js +20 -19
- package/dist/queries/pins.d.ts +1 -0
- package/dist/queries/pins.js +4 -6
- package/dist/queries/profile.js +1 -6
- package/dist/queries/reactions.js +11 -14
- package/dist/queries/relays.d.ts +27 -0
- package/dist/queries/relays.js +44 -0
- package/dist/queries/simple.js +5 -22
- package/dist/queries/thread.js +45 -51
- package/dist/queries/user-status.js +23 -29
- package/dist/queries/zaps.js +10 -13
- package/dist/query-store/query-store.d.ts +7 -6
- package/dist/query-store/query-store.js +13 -8
- package/package.json +3 -3
- package/dist/observable/share-latest-value.d.ts +0 -6
- package/dist/observable/share-latest-value.js +0 -24
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { filter, finalize, ReplaySubject, share, timer } from "rxjs";
|
|
1
|
+
import { filter, finalize, firstValueFrom, ReplaySubject, share, timer } from "rxjs";
|
|
2
2
|
import hash_sum from "hash-sum";
|
|
3
3
|
import * as Queries from "../queries/index.js";
|
|
4
|
-
import { getObservableValue } from "../observable/get-observable-value.js";
|
|
5
4
|
import { withImmediateValueOrDefault } from "../observable/with-immediate-value.js";
|
|
6
5
|
export class QueryStore {
|
|
7
6
|
static Queries = Queries;
|
|
@@ -22,19 +21,17 @@ export class QueryStore {
|
|
|
22
21
|
observables = new Map();
|
|
23
22
|
this.queries.set(queryConstructor, observables);
|
|
24
23
|
}
|
|
25
|
-
const key = hash_sum(args);
|
|
24
|
+
const key = queryConstructor.getKey ? queryConstructor.getKey(...args) : hash_sum(args);
|
|
26
25
|
let observable = observables.get(key);
|
|
27
26
|
if (!observable) {
|
|
28
27
|
const cleanup = () => {
|
|
29
28
|
if (observables.get(key) === observable)
|
|
30
29
|
observables.delete(key);
|
|
31
30
|
};
|
|
32
|
-
observable = queryConstructor(...args)
|
|
33
|
-
.run(this.store, this)
|
|
34
|
-
.pipe(
|
|
31
|
+
observable = queryConstructor(...args)(this.store, this).pipe(
|
|
35
32
|
// always emit undefined so the observable is sync
|
|
36
33
|
withImmediateValueOrDefault(undefined),
|
|
37
|
-
// remove the observable when its
|
|
34
|
+
// remove the observable when its unsubscribed
|
|
38
35
|
finalize(cleanup),
|
|
39
36
|
// only create a single observable for all components
|
|
40
37
|
share({
|
|
@@ -51,7 +48,7 @@ export class QueryStore {
|
|
|
51
48
|
/** Creates a query and waits for the next value */
|
|
52
49
|
async executeQuery(queryConstructor, ...args) {
|
|
53
50
|
const query = this.createQuery(queryConstructor, ...args).pipe(filter((v) => v !== undefined));
|
|
54
|
-
return
|
|
51
|
+
return firstValueFrom(query);
|
|
55
52
|
}
|
|
56
53
|
/** Creates a SingleEventQuery */
|
|
57
54
|
event(id) {
|
|
@@ -77,6 +74,14 @@ export class QueryStore {
|
|
|
77
74
|
profile(pubkey) {
|
|
78
75
|
return this.createQuery(Queries.ProfileQuery, pubkey);
|
|
79
76
|
}
|
|
77
|
+
/** Creates a ContactsQuery */
|
|
78
|
+
contacts(pubkey) {
|
|
79
|
+
return this.createQuery(Queries.ContactsQuery, pubkey);
|
|
80
|
+
}
|
|
81
|
+
/** Creates a MuteQuery */
|
|
82
|
+
mutes(pubkey) {
|
|
83
|
+
return this.createQuery(Queries.MuteQuery, pubkey);
|
|
84
|
+
}
|
|
80
85
|
/** Creates a ReactionsQuery */
|
|
81
86
|
reactions(event) {
|
|
82
87
|
return this.createQuery(Queries.ReactionsQuery, event);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { OperatorFunction } from "rxjs";
|
|
2
|
-
/**
|
|
3
|
-
* Creates an operator that adds a 'value' property and multiplexes the source
|
|
4
|
-
* @param config Optional ShareConfig for customizing sharing behavior
|
|
5
|
-
*/
|
|
6
|
-
export declare function shareLatestValue<T>(): OperatorFunction<T, T | undefined>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { BehaviorSubject, share } from "rxjs";
|
|
2
|
-
/**
|
|
3
|
-
* Creates an operator that adds a 'value' property and multiplexes the source
|
|
4
|
-
* @param config Optional ShareConfig for customizing sharing behavior
|
|
5
|
-
*/
|
|
6
|
-
export function shareLatestValue() {
|
|
7
|
-
return (source$) => source$.pipe(share({ connector: () => new BehaviorSubject(undefined) }));
|
|
8
|
-
// return (source: Observable<T>): Observable<T> & { value: T | undefined } => {
|
|
9
|
-
// // Create storage for latest value
|
|
10
|
-
// let latestValue: T | undefined = undefined;
|
|
11
|
-
// // Create shared source with value tracking
|
|
12
|
-
// const shared$ = source.pipe(
|
|
13
|
-
// tap((value) => {
|
|
14
|
-
// latestValue = value;
|
|
15
|
-
// }),
|
|
16
|
-
// share(config),
|
|
17
|
-
// );
|
|
18
|
-
// // Add value property
|
|
19
|
-
// Object.defineProperty(shared$, "value", {
|
|
20
|
-
// get: () => latestValue,
|
|
21
|
-
// });
|
|
22
|
-
// return shared$ as Observable<T> & { value: T | undefined };
|
|
23
|
-
// };
|
|
24
|
-
}
|