applesauce-loaders 0.11.0 → 0.12.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IEventStore, QueryStore } from "applesauce-core";
|
|
2
2
|
import { ProfilePointer } from "nostr-tools/nip19";
|
|
3
3
|
import { Observable } from "rxjs";
|
|
4
4
|
import { ReplaceableLoader } from "./replaceable-loader.js";
|
|
@@ -11,7 +11,7 @@ export declare class RequestLoader {
|
|
|
11
11
|
constructor(store: QueryStore);
|
|
12
12
|
protected runWithTimeout<T extends unknown, Args extends Array<any>>(queryConstructor: (...args: Args) => {
|
|
13
13
|
key: string;
|
|
14
|
-
run: (events:
|
|
14
|
+
run: (events: IEventStore, store: QueryStore) => Observable<T>;
|
|
15
15
|
}, ...args: Args): Promise<NonNullable<T>>;
|
|
16
16
|
protected checkReplaceable(): ReplaceableLoader;
|
|
17
17
|
/** Requests a single replaceable event */
|
|
@@ -25,4 +25,6 @@ export declare class RequestLoader {
|
|
|
25
25
|
}>;
|
|
26
26
|
/** Loads a pubkeys profile */
|
|
27
27
|
contacts(pointer: ProfilePointer, force?: boolean): Promise<ProfilePointer[]>;
|
|
28
|
+
/** Loads a pubkeys blossom servers */
|
|
29
|
+
blossomServers(pointer: ProfilePointer, force?: boolean): Promise<URL[]>;
|
|
28
30
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { kinds } from "nostr-tools";
|
|
2
|
-
import { MailboxesQuery, ProfileQuery, ReplaceableQuery, UserContactsQuery } from "applesauce-core/queries";
|
|
2
|
+
import { MailboxesQuery, ProfileQuery, ReplaceableQuery, UserBlossomServersQuery, UserContactsQuery, } from "applesauce-core/queries";
|
|
3
3
|
import { getObservableValue, simpleTimeout } from "applesauce-core/observable";
|
|
4
4
|
import { filter } from "rxjs";
|
|
5
|
+
import { BLOSSOM_SERVER_LIST_KIND } from "applesauce-core/helpers";
|
|
5
6
|
/** A special Promised based loader built on the {@link QueryStore} */
|
|
6
7
|
export class RequestLoader {
|
|
7
8
|
store;
|
|
@@ -12,7 +13,11 @@ export class RequestLoader {
|
|
|
12
13
|
}
|
|
13
14
|
// hacky method to run queries with timeouts
|
|
14
15
|
async runWithTimeout(queryConstructor, ...args) {
|
|
15
|
-
return getObservableValue(this.store.createQuery(queryConstructor, ...args).pipe(
|
|
16
|
+
return getObservableValue(this.store.createQuery(queryConstructor, ...args).pipe(
|
|
17
|
+
// ignore undefined and null values
|
|
18
|
+
filter((v) => v !== undefined && v !== null),
|
|
19
|
+
// timeout with an error is not values
|
|
20
|
+
simpleTimeout(this.requestTimeout)));
|
|
16
21
|
}
|
|
17
22
|
checkReplaceable() {
|
|
18
23
|
if (!this.replaceableLoader)
|
|
@@ -39,4 +44,14 @@ export class RequestLoader {
|
|
|
39
44
|
this.checkReplaceable().next({ kind: kinds.Contacts, pubkey: pointer.pubkey, relays: pointer.relays, force });
|
|
40
45
|
return this.runWithTimeout(UserContactsQuery, pointer.pubkey);
|
|
41
46
|
}
|
|
47
|
+
/** Loads a pubkeys blossom servers */
|
|
48
|
+
blossomServers(pointer, force) {
|
|
49
|
+
this.checkReplaceable().next({
|
|
50
|
+
kind: BLOSSOM_SERVER_LIST_KIND,
|
|
51
|
+
pubkey: pointer.pubkey,
|
|
52
|
+
relays: pointer.relays,
|
|
53
|
+
force,
|
|
54
|
+
});
|
|
55
|
+
return this.runWithTimeout(UserBlossomServersQuery, pointer.pubkey);
|
|
56
|
+
}
|
|
42
57
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-loaders",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "A collection of observable based loaders built on rx-nostr",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"keywords": [
|
|
9
|
-
"nostr"
|
|
9
|
+
"nostr",
|
|
10
|
+
"applesauce"
|
|
10
11
|
],
|
|
11
12
|
"author": "hzrd149",
|
|
12
13
|
"license": "MIT",
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
}
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"applesauce-core": "^0.
|
|
56
|
+
"applesauce-core": "^0.12.0",
|
|
56
57
|
"nanoid": "^5.0.9",
|
|
57
58
|
"nostr-tools": "^2.10.4",
|
|
58
59
|
"rx-nostr": "^3.5.0",
|