applesauce-loaders 0.0.0-next-20241207161834 → 0.0.0-next-20241207164640
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/loaders/replaceable-loader.js +10 -6
- package/dist/loaders/single-relay-replaceable-loader.js +2 -1
- package/dist/operators/address-pointers-request.d.ts +1 -1
- package/dist/operators/address-pointers-request.js +2 -4
- package/dist/operators/relay-request.d.ts +1 -1
- package/dist/operators/relay-request.js +1 -1
- package/package.json +2 -2
|
@@ -40,16 +40,20 @@ function* cacheFirstSequence(rxNostr, pointers, log, opts) {
|
|
|
40
40
|
// first attempt, load from cache relays
|
|
41
41
|
if (opts?.cacheRelays && opts?.cacheRelays.length > 0) {
|
|
42
42
|
log(`Checking cache`, opts.cacheRelays, remaining);
|
|
43
|
-
const results = yield from([remaining]).pipe(replaceableRequest(rxNostr, opts.cacheRelays
|
|
43
|
+
const results = yield from([remaining]).pipe(replaceableRequest(rxNostr, id, opts.cacheRelays),
|
|
44
44
|
// mark the event as from the cache
|
|
45
45
|
tap((p) => markFromCache(p.event)));
|
|
46
46
|
if (handleResults(results))
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
// load from pointer relays and default relays
|
|
50
|
+
const defaultRelays = Object.entries(rxNostr.getDefaultRelays())
|
|
51
|
+
.filter(([_relay, config]) => config.read)
|
|
52
|
+
.map(([relay]) => relay);
|
|
53
|
+
const remoteRelays = [...pointerRelays, ...defaultRelays];
|
|
54
|
+
if (remoteRelays.length > 0) {
|
|
55
|
+
log(`Requesting`, remoteRelays, remaining);
|
|
56
|
+
const results = yield from([remaining]).pipe(replaceableRequest(rxNostr, id, remoteRelays));
|
|
53
57
|
if (handleResults(results))
|
|
54
58
|
return;
|
|
55
59
|
}
|
|
@@ -59,7 +63,7 @@ function* cacheFirstSequence(rxNostr, pointers, log, opts) {
|
|
|
59
63
|
const relays = opts.lookupRelays.filter((r) => !pointerRelays.includes(r));
|
|
60
64
|
if (relays.length > 0) {
|
|
61
65
|
log(`Request from lookup`, relays, remaining);
|
|
62
|
-
const results = yield from([remaining]).pipe(replaceableRequest(rxNostr,
|
|
66
|
+
const results = yield from([remaining]).pipe(replaceableRequest(rxNostr, id, relays));
|
|
63
67
|
if (handleResults(results))
|
|
64
68
|
return;
|
|
65
69
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { bufferTime, filter, from, map, mergeMap, share } from "rxjs";
|
|
2
2
|
import { getReplaceableUID } from "applesauce-core/helpers";
|
|
3
|
+
import { nanoid } from "nanoid";
|
|
3
4
|
import { Loader } from "./loader.js";
|
|
4
5
|
import { isLoadableAddressPointer } from "../helpers/address-pointer.js";
|
|
5
6
|
import { replaceableRequest } from "../operators/address-pointers-request.js";
|
|
@@ -43,7 +44,7 @@ export class SingleRelayReplaceableLoader extends Loader {
|
|
|
43
44
|
// batch and filter
|
|
44
45
|
singleRelayBatcher(opts),
|
|
45
46
|
// breakout the batches so they can complete
|
|
46
|
-
mergeMap((pointers) => from([pointers]).pipe(replaceableRequest(rxNostr, [relay]))),
|
|
47
|
+
mergeMap((pointers) => from([pointers]).pipe(replaceableRequest(rxNostr, nanoid(8), [relay]))),
|
|
47
48
|
// share the response with all subscribers
|
|
48
49
|
share()));
|
|
49
50
|
}
|
|
@@ -2,4 +2,4 @@ import { EventPacket, RxNostr } from "rx-nostr";
|
|
|
2
2
|
import { OperatorFunction } from "rxjs";
|
|
3
3
|
import { AddressPointerWithoutD } from "applesauce-core/helpers";
|
|
4
4
|
/** Makes a request to relays for every set of address pointers */
|
|
5
|
-
export declare function replaceableRequest<T extends AddressPointerWithoutD>(rxNostr: RxNostr,
|
|
5
|
+
export declare function replaceableRequest<T extends AddressPointerWithoutD>(rxNostr: RxNostr, id: string, relays?: string[]): OperatorFunction<T[], EventPacket>;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { map, tap } from "rxjs";
|
|
2
|
-
import { nanoid } from "nanoid";
|
|
3
2
|
import { logger } from "applesauce-core";
|
|
4
3
|
import { relaysRequest } from "./relay-request.js";
|
|
5
4
|
import { createFiltersFromAddressPointers } from "../helpers/address-pointer.js";
|
|
6
5
|
/** Makes a request to relays for every set of address pointers */
|
|
7
|
-
export function replaceableRequest(rxNostr,
|
|
6
|
+
export function replaceableRequest(rxNostr, id, relays) {
|
|
8
7
|
return (source) => {
|
|
9
|
-
id = id || nanoid(8);
|
|
10
8
|
const log = logger.extend(`replaceableRequest:${id}`);
|
|
11
9
|
return source.pipe(
|
|
12
10
|
// convert pointers to filters
|
|
@@ -16,7 +14,7 @@ export function replaceableRequest(rxNostr, relays, id) {
|
|
|
16
14
|
log(`Requesting`, relays, filters);
|
|
17
15
|
}),
|
|
18
16
|
// make requests
|
|
19
|
-
relaysRequest(rxNostr,
|
|
17
|
+
relaysRequest(rxNostr, id, relays),
|
|
20
18
|
// log when complete
|
|
21
19
|
tap({
|
|
22
20
|
complete: () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { EventPacket, LazyFilter, RxNostr } from "rx-nostr";
|
|
2
2
|
import { OperatorFunction } from "rxjs";
|
|
3
3
|
/** Makes a request to relays for every set of filters */
|
|
4
|
-
export declare function relaysRequest(rxNostr: RxNostr,
|
|
4
|
+
export declare function relaysRequest(rxNostr: RxNostr, id: string, relays?: string[]): OperatorFunction<LazyFilter | LazyFilter[], EventPacket>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRxOneshotReq } from "rx-nostr";
|
|
2
2
|
import { map, mergeAll } from "rxjs";
|
|
3
3
|
/** Makes a request to relays for every set of filters */
|
|
4
|
-
export function relaysRequest(rxNostr,
|
|
4
|
+
export function relaysRequest(rxNostr, id, relays) {
|
|
5
5
|
return (source) => source.pipe(map((filters) => {
|
|
6
6
|
const req = createRxOneshotReq({ filters, rxReqId: id });
|
|
7
7
|
return rxNostr.use(req, { on: { relays } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-loaders",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20241207164640",
|
|
4
4
|
"description": "A collection of observable based loaders built on rx-nostr",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"applesauce-core": "0.0.0-next-
|
|
39
|
+
"applesauce-core": "0.0.0-next-20241207164640",
|
|
40
40
|
"nanoid": "^5.0.9",
|
|
41
41
|
"nostr-tools": "^2.10.3",
|
|
42
42
|
"rx-nostr": "^3.4.1",
|