@welshman/app 0.0.1 → 0.0.3
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/build/src/collection.cjs +53 -0
- package/build/src/collection.cjs.map +1 -0
- package/build/src/collection.d.ts +15 -0
- package/build/src/collection.mjs +49 -0
- package/build/src/collection.mjs.map +1 -0
- package/build/src/context.cjs +38 -0
- package/build/src/context.cjs.map +1 -0
- package/build/src/context.d.ts +30 -0
- package/build/src/context.mjs +33 -0
- package/build/src/context.mjs.map +1 -0
- package/build/src/core.cjs +54 -0
- package/build/src/core.cjs.map +1 -0
- package/build/src/core.d.ts +14 -0
- package/build/src/core.mjs +49 -0
- package/build/src/core.mjs.map +1 -0
- package/build/src/follows.cjs +27 -0
- package/build/src/follows.cjs.map +1 -0
- package/build/src/follows.d.ts +9 -0
- package/build/src/follows.mjs +23 -0
- package/build/src/follows.mjs.map +1 -0
- package/build/src/freshness.cjs +21 -0
- package/build/src/freshness.cjs.map +1 -0
- package/build/src/freshness.d.ts +8 -0
- package/build/src/freshness.mjs +14 -0
- package/build/src/freshness.mjs.map +1 -0
- package/build/src/handles.cjs +85 -0
- package/build/src/handles.cjs.map +1 -0
- package/build/src/handles.d.ts +24 -0
- package/build/src/handles.mjs +77 -0
- package/build/src/handles.mjs.map +1 -0
- package/build/src/index.cjs +17 -2
- package/build/src/index.cjs.map +1 -1
- package/build/src/index.d.ts +17 -2
- package/build/src/index.mjs +17 -2
- package/build/src/mutes.cjs +27 -0
- package/build/src/mutes.cjs.map +1 -0
- package/build/src/mutes.d.ts +9 -0
- package/build/src/mutes.mjs +23 -0
- package/build/src/mutes.mjs.map +1 -0
- package/build/src/plaintext.cjs +24 -0
- package/build/src/plaintext.cjs.map +1 -0
- package/build/src/plaintext.d.ts +8 -0
- package/build/src/plaintext.mjs +18 -0
- package/build/src/plaintext.mjs.map +1 -0
- package/build/src/profiles.cjs +40 -0
- package/build/src/profiles.cjs.map +1 -0
- package/build/src/profiles.d.ts +12 -0
- package/build/src/profiles.mjs +34 -0
- package/build/src/profiles.mjs.map +1 -0
- package/build/src/relaySelections.cjs +34 -0
- package/build/src/relaySelections.cjs.map +1 -0
- package/build/src/relaySelections.d.ts +18 -0
- package/build/src/relaySelections.mjs +27 -0
- package/build/src/relaySelections.mjs.map +1 -0
- package/build/src/relays.cjs +116 -0
- package/build/src/relays.cjs.map +1 -0
- package/build/src/relays.d.ts +28 -0
- package/build/src/relays.mjs +109 -0
- package/build/src/relays.mjs.map +1 -0
- package/build/src/router.cjs +375 -0
- package/build/src/router.cjs.map +1 -0
- package/build/src/router.d.ts +197 -0
- package/build/src/router.mjs +355 -0
- package/build/src/router.mjs.map +1 -0
- package/build/src/session.cjs +27 -19
- package/build/src/session.cjs.map +1 -1
- package/build/src/session.d.ts +13 -1
- package/build/src/session.mjs +23 -19
- package/build/src/session.mjs.map +1 -1
- package/build/src/storage.cjs +101 -0
- package/build/src/storage.cjs.map +1 -0
- package/build/src/storage.d.ts +45 -0
- package/build/src/storage.mjs +92 -0
- package/build/src/storage.mjs.map +1 -0
- package/build/src/thunk.cjs +44 -0
- package/build/src/thunk.cjs.map +1 -0
- package/build/src/thunk.d.ts +37 -0
- package/build/src/thunk.mjs +39 -0
- package/build/src/thunk.mjs.map +1 -0
- package/build/src/topics.cjs +30 -0
- package/build/src/topics.cjs.map +1 -0
- package/build/src/topics.d.ts +10 -0
- package/build/src/topics.mjs +27 -0
- package/build/src/topics.mjs.map +1 -0
- package/build/src/util.cjs +62 -0
- package/build/src/util.cjs.map +1 -0
- package/build/src/util.d.ts +22 -0
- package/build/src/util.mjs +47 -0
- package/build/src/util.mjs.map +1 -0
- package/build/src/zappers.cjs +64 -0
- package/build/src/zappers.cjs.map +1 -0
- package/build/src/zappers.d.ts +11 -0
- package/build/src/zappers.mjs +58 -0
- package/build/src/zappers.mjs.map +1 -0
- package/package.json +10 -4
- package/build/src/relay.cjs +0 -13
- package/build/src/relay.cjs.map +0 -1
- package/build/src/relay.d.ts +0 -6
- package/build/src/relay.mjs +0 -10
- package/build/src/relay.mjs.map +0 -1
- package/build/src/types.cjs +0 -3
- package/build/src/types.cjs.map +0 -1
- package/build/src/types.d.ts +0 -15
- package/build/src/types.mjs +0 -2
- package/build/src/types.mjs.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collection = void 0;
|
|
4
|
+
const store_1 = require("svelte/store");
|
|
5
|
+
const lib_1 = require("@welshman/lib");
|
|
6
|
+
const store_2 = require("@welshman/store");
|
|
7
|
+
const freshness_1 = require("./freshness.cjs");
|
|
8
|
+
const collection = ({ name, store, getKey, load, }) => {
|
|
9
|
+
const indexStore = (0, store_2.withGetter)((0, store_1.derived)(store, $items => (0, lib_1.indexBy)(getKey, $items)));
|
|
10
|
+
const getItem = (key) => indexStore.get().get(key);
|
|
11
|
+
const pending = new Map();
|
|
12
|
+
const loadAttempts = new Map();
|
|
13
|
+
const loadItem = async (key, ...args) => {
|
|
14
|
+
const stale = getItem(key);
|
|
15
|
+
const freshness = (0, freshness_1.getFreshness)(name, key);
|
|
16
|
+
// If we have an item, reload if it's stale
|
|
17
|
+
if (stale && freshness > (0, lib_1.now)() - 3600) {
|
|
18
|
+
return stale;
|
|
19
|
+
}
|
|
20
|
+
// If we already are loading, await and return
|
|
21
|
+
if (pending.has(key)) {
|
|
22
|
+
return pending.get(key).then(() => getItem(key));
|
|
23
|
+
}
|
|
24
|
+
const attempt = loadAttempts.get(key) || 0;
|
|
25
|
+
// Use exponential backoff to throttle attempts
|
|
26
|
+
if (freshness > (0, lib_1.now)() - Math.pow(2, attempt)) {
|
|
27
|
+
return stale;
|
|
28
|
+
}
|
|
29
|
+
loadAttempts.set(key, attempt + 1);
|
|
30
|
+
(0, freshness_1.setFreshness)(name, key, (0, lib_1.now)());
|
|
31
|
+
const promise = load(key, ...args);
|
|
32
|
+
pending.set(key, promise);
|
|
33
|
+
await promise;
|
|
34
|
+
pending.delete(key);
|
|
35
|
+
const fresh = getItem(key);
|
|
36
|
+
if (fresh) {
|
|
37
|
+
loadAttempts.delete(key);
|
|
38
|
+
}
|
|
39
|
+
return fresh;
|
|
40
|
+
};
|
|
41
|
+
const deriveItem = (key, ...args) => {
|
|
42
|
+
if (!key) {
|
|
43
|
+
return (0, store_1.readable)(undefined);
|
|
44
|
+
}
|
|
45
|
+
// If we don't yet have the item, or it's stale, trigger a request for it. The derived
|
|
46
|
+
// store will update when it arrives
|
|
47
|
+
loadItem(key, ...args);
|
|
48
|
+
return (0, store_1.derived)(indexStore, $index => $index.get(key));
|
|
49
|
+
};
|
|
50
|
+
return { indexStore, deriveItem, loadItem, getItem };
|
|
51
|
+
};
|
|
52
|
+
exports.collection = collection;
|
|
53
|
+
//# sourceMappingURL=collection.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.cjs","sourceRoot":"","sources":["../../src/collection.ts"],"names":[],"mappings":";;;AAAA,wCAA6D;AAC7D,uCAAsD;AACtD,2CAA0C;AAC1C,+CAAsD;AAE/C,MAAM,UAAU,GAAG,CAA4B,EACpD,IAAI,EACJ,KAAK,EACL,MAAM,EACN,IAAI,GAML,EAAE,EAAE;IACH,MAAM,UAAU,GAAG,IAAA,kBAAU,EAAC,IAAA,eAAO,EAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,IAAA,aAAO,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IAChF,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC1D,MAAM,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAA;IACpD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAA;IAE9C,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAW,EAAE,GAAG,IAAc,EAAE,EA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AAkB,EAAE,GAAG,IAAc,EAAE,EAAE;QAC3D,IAAI,CAAC,GAAG,EAAE;YACR,OAAO,IAAA,gBAAQ,EAAC,SAAS,CAAC,CAAA;SAC3B;QAED,sFAAsF;QACtF,oCAAoC;QACpC,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAEtB,OAAO,IAAA,eAAO,EAAC,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,CAAC,CAAA;IAED,OAAO,EAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAC,CAAA;AACpD,CAAC,CAAA;AAvEY,QAAA,UAAU,cAuEtB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Readable } from 'svelte/store';
|
|
2
|
+
import { type Maybe } from '@welshman/lib';
|
|
3
|
+
export declare const collection: <T, LoadArgs extends any[]>({ name, store, getKey, load, }: {
|
|
4
|
+
name: string;
|
|
5
|
+
store: Readable<T[]>;
|
|
6
|
+
getKey: (item: T) => string;
|
|
7
|
+
load: (key: string, ...args: LoadArgs) => Promise<any>;
|
|
8
|
+
}) => {
|
|
9
|
+
indexStore: Readable<Map<string, T>> & {
|
|
10
|
+
get: () => Map<string, T>;
|
|
11
|
+
};
|
|
12
|
+
deriveItem: (key: Maybe<string>, ...args: LoadArgs) => Readable<T | undefined>;
|
|
13
|
+
loadItem: (key: string, ...args: LoadArgs) => Promise<T | undefined>;
|
|
14
|
+
getItem: (key: string) => T | undefined;
|
|
15
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { readable, derived } from 'svelte/store';
|
|
2
|
+
import { indexBy, now } from '@welshman/lib';
|
|
3
|
+
import { withGetter } from '@welshman/store';
|
|
4
|
+
import { getFreshness, setFreshness } from "./freshness.mjs";
|
|
5
|
+
export const collection = ({ name, store, getKey, load, }) => {
|
|
6
|
+
const indexStore = withGetter(derived(store, $items => indexBy(getKey, $items)));
|
|
7
|
+
const getItem = (key) => indexStore.get().get(key);
|
|
8
|
+
const pending = new Map();
|
|
9
|
+
const loadAttempts = new Map();
|
|
10
|
+
const loadItem = async (key, ...args) => {
|
|
11
|
+
const stale = getItem(key);
|
|
12
|
+
const freshness = getFreshness(name, key);
|
|
13
|
+
// If we have an item, reload if it's stale
|
|
14
|
+
if (stale && freshness > now() - 3600) {
|
|
15
|
+
return stale;
|
|
16
|
+
}
|
|
17
|
+
// If we already are loading, await and return
|
|
18
|
+
if (pending.has(key)) {
|
|
19
|
+
return pending.get(key).then(() => getItem(key));
|
|
20
|
+
}
|
|
21
|
+
const attempt = loadAttempts.get(key) || 0;
|
|
22
|
+
// Use exponential backoff to throttle attempts
|
|
23
|
+
if (freshness > now() - Math.pow(2, attempt)) {
|
|
24
|
+
return stale;
|
|
25
|
+
}
|
|
26
|
+
loadAttempts.set(key, attempt + 1);
|
|
27
|
+
setFreshness(name, key, now());
|
|
28
|
+
const promise = load(key, ...args);
|
|
29
|
+
pending.set(key, promise);
|
|
30
|
+
await promise;
|
|
31
|
+
pending.delete(key);
|
|
32
|
+
const fresh = getItem(key);
|
|
33
|
+
if (fresh) {
|
|
34
|
+
loadAttempts.delete(key);
|
|
35
|
+
}
|
|
36
|
+
return fresh;
|
|
37
|
+
};
|
|
38
|
+
const deriveItem = (key, ...args) => {
|
|
39
|
+
if (!key) {
|
|
40
|
+
return readable(undefined);
|
|
41
|
+
}
|
|
42
|
+
// If we don't yet have the item, or it's stale, trigger a request for it. The derived
|
|
43
|
+
// store will update when it arrives
|
|
44
|
+
loadItem(key, ...args);
|
|
45
|
+
return derived(indexStore, $index => $index.get(key));
|
|
46
|
+
};
|
|
47
|
+
return { indexStore, deriveItem, loadItem, getItem };
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=collection.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.mjs","sourceRoot":"","sources":["../../src/collection.ts"],"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= void 0;
|
|
4
|
+
const lib_1 = require("@welshman/lib");
|
|
5
|
+
const net_1 = require("@welshman/net");
|
|
6
|
+
const util_1 = require("@welshman/util");
|
|
7
|
+
const core_1 = require("./core.cjs");
|
|
8
|
+
const router_1 = require("./router.cjs");
|
|
9
|
+
const session_1 = require("./session.cjs");
|
|
10
|
+
const getDefaultNetContext = (overrides = {}) => ({
|
|
11
|
+
...(0, net_1.getDefaultNetContext)(),
|
|
12
|
+
onAuth: session_1.onAuth,
|
|
13
|
+
onEvent: (url, event) => core_1.tracker.track(event.id, url),
|
|
14
|
+
isDeleted: (url, event) => core_1.repository.isDeleted(event),
|
|
15
|
+
isValid: (url, event) => (0, session_1.getSession)(event.pubkey) || ((0, util_1.isSignedEvent)(event) && (0, util_1.hasValidSignature)(event)),
|
|
16
|
+
optimizeSubscriptions: (subs) => {
|
|
17
|
+
const [withRelays, withoutRelays] = (0, lib_1.partition)(sub => sub.request.relays.length > 0, subs);
|
|
18
|
+
const filters = (0, util_1.unionFilters)(withoutRelays.flatMap(sub => sub.request.filters));
|
|
19
|
+
const selections = (0, net_1.defaultOptimizeSubscriptions)(withRelays);
|
|
20
|
+
if (filters.length > 0) {
|
|
21
|
+
for (const selection of (0, router_1.getFilterSelections)(filters)) {
|
|
22
|
+
selections.push(selection);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return selections;
|
|
26
|
+
},
|
|
27
|
+
...overrides,
|
|
28
|
+
});
|
|
29
|
+
exports.getDefaultNetContext = getDefaultNetContext;
|
|
30
|
+
const getDefaultAppContext = (overrides = {}) => ({
|
|
31
|
+
router: (0, router_1.makeRouter)(),
|
|
32
|
+
requestDelay: 50,
|
|
33
|
+
authTimeout: 300,
|
|
34
|
+
requestTimeout: 3000,
|
|
35
|
+
...overrides,
|
|
36
|
+
});
|
|
37
|
+
exports.getDefaultAppContext = getDefaultAppContext;
|
|
38
|
+
//# sourceMappingURL=context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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AAE;gBACrD,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;aAC3B;SACF;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;IACD,GAAG,SAAS;CACb,CAAC,CAAA;AArBW,QAAA,oBAAoB,wBAqB/B;AAEK,MAAM,oBAAoB,GAAG,CAAC,YAAiC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5E,MAAM,EAAE,IAAA,mBAAU,GAAE;IACpB,YAAY,EAAE,EAAE;IAChB,WAAW,EAAE,GAAG;IAChB,cAAc,EAAE,IAAI;IACpB,GAAG,SAAS;CACb,CAAC,CAAA;AANW,QAAA,oBAAoB,wBAM/B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Subscription, RelaysAndFilters, NetContext } from "@welshman/net";
|
|
2
|
+
import type { TrustedEvent } from "@welshman/util";
|
|
3
|
+
import type { Router } from './router';
|
|
4
|
+
export type AppContext = {
|
|
5
|
+
router: Router;
|
|
6
|
+
requestDelay: number;
|
|
7
|
+
authTimeout: number;
|
|
8
|
+
requestTimeout: number;
|
|
9
|
+
dufflepudUrl?: string;
|
|
10
|
+
indexerRelays?: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare const getDefaultNetContext: (overrides?: Partial<NetContext>) => {
|
|
13
|
+
pool: import("@welshman/net").Pool;
|
|
14
|
+
getExecutor: (relays: string[]) => import("@welshman/net").Executor;
|
|
15
|
+
onEvent: (url: string, event: TrustedEvent) => void;
|
|
16
|
+
onAuth: (url: string, challenge: string) => void;
|
|
17
|
+
onOk: ((url: string, id: string, ok: boolean, message: string) => void) | ((...args: unknown[]) => undefined);
|
|
18
|
+
isDeleted: (url: string, event: TrustedEvent) => boolean;
|
|
19
|
+
isValid: ((url: string, event: TrustedEvent) => import("./session").Session) | ((url: string, event: TrustedEvent) => boolean);
|
|
20
|
+
matchFilters: (url: string, filters: import("@welshman/util").Filter[], event: TrustedEvent) => boolean;
|
|
21
|
+
optimizeSubscriptions: (subs: Subscription[]) => RelaysAndFilters[];
|
|
22
|
+
};
|
|
23
|
+
export declare const getDefaultAppContext: (overrides?: Partial<AppContext>) => {
|
|
24
|
+
router: Router;
|
|
25
|
+
requestDelay: number;
|
|
26
|
+
authTimeout: number;
|
|
27
|
+
requestTimeout: number;
|
|
28
|
+
dufflepudUrl?: string | undefined;
|
|
29
|
+
indexerRelays?: string[] | undefined;
|
|
30
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { partition } from "@welshman/lib";
|
|
2
|
+
import { defaultOptimizeSubscriptions, getDefaultNetContext as originalGetDefaultNetContext } from "@welshman/net";
|
|
3
|
+
import { unionFilters, isSignedEvent, hasValidSignature } from "@welshman/util";
|
|
4
|
+
import { tracker, repository } from "./core.mjs";
|
|
5
|
+
import { makeRouter, getFilterSelections } from "./router.mjs";
|
|
6
|
+
import { onAuth, getSession } from "./session.mjs";
|
|
7
|
+
export const getDefaultNetContext = (overrides = {}) => ({
|
|
8
|
+
...originalGetDefaultNetContext(),
|
|
9
|
+
onAuth: onAuth,
|
|
10
|
+
onEvent: (url, event) => tracker.track(event.id, url),
|
|
11
|
+
isDeleted: (url, event) => repository.isDeleted(event),
|
|
12
|
+
isValid: (url, event) => getSession(event.pubkey) || (isSignedEvent(event) && hasValidSignature(event)),
|
|
13
|
+
optimizeSubscriptions: (subs) => {
|
|
14
|
+
const [withRelays, withoutRelays] = partition(sub => sub.request.relays.length > 0, subs);
|
|
15
|
+
const filters = unionFilters(withoutRelays.flatMap(sub => sub.request.filters));
|
|
16
|
+
const selections = defaultOptimizeSubscriptions(withRelays);
|
|
17
|
+
if (filters.length > 0) {
|
|
18
|
+
for (const selection of getFilterSelections(filters)) {
|
|
19
|
+
selections.push(selection);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return selections;
|
|
23
|
+
},
|
|
24
|
+
...overrides,
|
|
25
|
+
});
|
|
26
|
+
export const getDefaultAppContext = (overrides = {}) => ({
|
|
27
|
+
router: makeRouter(),
|
|
28
|
+
requestDelay: 50,
|
|
29
|
+
authTimeout: 300,
|
|
30
|
+
requestTimeout: 3000,
|
|
31
|
+
...overrides,
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=context.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.mjs","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"OAAO,EAAC,SAAS,EAAC,MAAM,eAAe;OAChC,EAAC,4BAA4B,EAAE,oBAAoB,IAAI,4BAA4B,EAAC,MAAM,eAAe;OAEzG,EAAC,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAC,MAAM,gBAAgB;OAEtE,EAAC,OAAO,EAAE,UAAU,EAAC;OACrB,EAAC,UAAU,EAAE,mBAAmB,EAAC;OACjC,EAAC,MAAM,EAAE,UAAU,EAAC;AAY3B,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAiC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5E,GAAG,4BAA4B,EAAE;IACjC,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,CAAC,GAAW,EAAE,KAAmB,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC;IAC3E,SAAS,EAAE,CAAC,GAAW,EAAE,KAAmB,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC;IAC5E,OAAO,EAAE,CAAC,GAAW,EAAE,KAAmB,EAAE,EAAE,CAC5C,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAChF,qBAAqB,EAAE,CAAC,IAAoB,EAAE,EAAE;QAC9C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,CAAA;QACzF,MAAM,OAAO,GAAG,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;QAC/E,MAAM,UAAU,GAAuB,4BAA4B,CAAC,UAAU,CAAC,CAAA;QAE/E,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YACtB,KAAK,MAAM,SAAS,IAAK,mBAAmB,CAAC,OAAO,CAAC,EAAE;gBACrD,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;aAC3B;SACF;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;IACD,GAAG,SAAS;CACb,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAiC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5E,MAAM,EAAE,UAAU,EAAE;IACpB,YAAY,EAAE,EAAE;IAChB,WAAW,EAAE,GAAG;IAChB,cAAc,EAAE,IAAI;IACpB,GAAG,SAAS;CACb,CAAC,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.load = exports.subscribe = exports.tracker = exports.relay = exports.events = exports.repository = void 0;
|
|
4
|
+
const lib_1 = require("@welshman/lib");
|
|
5
|
+
const util_1 = require("@welshman/util");
|
|
6
|
+
const net_1 = require("@welshman/net");
|
|
7
|
+
const store_1 = require("@welshman/store");
|
|
8
|
+
exports.repository = new util_1.Repository();
|
|
9
|
+
exports.events = (0, store_1.createEventStore)(exports.repository);
|
|
10
|
+
exports.relay = new util_1.Relay(exports.repository);
|
|
11
|
+
exports.tracker = new net_1.Tracker();
|
|
12
|
+
const subscribe = (request) => {
|
|
13
|
+
const events = [];
|
|
14
|
+
// If we already have all results for any filter, don't send the filter to the network
|
|
15
|
+
if (request.closeOnEose) {
|
|
16
|
+
for (const filter of request.filters.splice(0)) {
|
|
17
|
+
const cardinality = (0, util_1.getFilterResultCardinality)(filter);
|
|
18
|
+
if (!(0, lib_1.isNil)(cardinality)) {
|
|
19
|
+
const results = exports.repository.query([filter]);
|
|
20
|
+
if (results.length === cardinality) {
|
|
21
|
+
for (const event of results) {
|
|
22
|
+
events.push(event);
|
|
23
|
+
}
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
request.filters.push(filter);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Make sure to query our local relay too
|
|
31
|
+
const delay = lib_1.ctx.app.requestDelay;
|
|
32
|
+
const timeout = lib_1.ctx.app.requestTimeout;
|
|
33
|
+
const authTimeout = lib_1.ctx.app.authTimeout;
|
|
34
|
+
const sub = (0, net_1.subscribe)({ delay, timeout, authTimeout, relays: [], ...request });
|
|
35
|
+
sub.emitter.on("event", (url, e) => {
|
|
36
|
+
exports.repository.publish(e);
|
|
37
|
+
});
|
|
38
|
+
// Keep cached results async so the caller can set up handlers
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
for (const event of events) {
|
|
41
|
+
sub.emitter.emit("event", util_1.LOCAL_RELAY_URL, event);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return sub;
|
|
45
|
+
};
|
|
46
|
+
exports.subscribe = subscribe;
|
|
47
|
+
const load = (request) => new Promise(resolve => {
|
|
48
|
+
const sub = (0, exports.subscribe)({ closeOnEose: true, timeout: lib_1.ctx.app.requestTimeout, ...request });
|
|
49
|
+
const events = [];
|
|
50
|
+
sub.emitter.on("event", (url, e) => events.push(e));
|
|
51
|
+
sub.emitter.on("complete", () => resolve(events));
|
|
52
|
+
});
|
|
53
|
+
exports.load = load;
|
|
54
|
+
//# sourceMappingURL=core.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.cjs","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AACxC,yCAA6F;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AAG,OAAO,EAAC,CAAC,CAAA;IAEhF,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAW,EAAE,CAAe,EAAE,EAAE;QACvD,kBAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IACvB,CAAC,CAAC,CAAA;IAEF,8DAA8D;IAC9D,UAAU,CAAC,GAAG,EAAE;QACd,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,sBAAe,EAAE,KAAK,CAAC,CAAA;SAClD;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AA1CY,QAAA,SAAS,aA0CrB;AAEM,MAAM,IAAI,GAAG,CAAC,OAAgC,EAAE,EAAE,CACvD,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;IACpC,MAAM,GAAG,GAAG,IAAA,iBAAS,EAAC,EAAC,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,SAAG,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,OAAO,EAAC,CAAC,CAAA;IACvF,MAAM,MAAM,GAAmB,EAAE,CAAA;IAEjC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAW,EAAE,CAAe,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACzE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;AACnD,CAAC,CAAC,CAAA;AAPS,QAAA,IAAI,QAOb"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import { Repository, Relay } from "@welshman/util";
|
|
3
|
+
import type { TrustedEvent, Filter } from "@welshman/util";
|
|
4
|
+
import { Tracker } from "@welshman/net";
|
|
5
|
+
import type { SubscribeRequestWithHandlers } from "@welshman/net";
|
|
6
|
+
export declare const repository: Repository<TrustedEvent>;
|
|
7
|
+
export declare const events: import("svelte/store").Writable<TrustedEvent[]>;
|
|
8
|
+
export declare const relay: Relay<TrustedEvent>;
|
|
9
|
+
export declare const tracker: Tracker;
|
|
10
|
+
export type PartialSubscribeRequest = Partial<SubscribeRequestWithHandlers> & {
|
|
11
|
+
filters: Filter[];
|
|
12
|
+
};
|
|
13
|
+
export declare const subscribe: (request: PartialSubscribeRequest) => import("@welshman/net").Subscription;
|
|
14
|
+
export declare const load: (request: PartialSubscribeRequest) => Promise<TrustedEvent[]>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ctx, isNil } from "@welshman/lib";
|
|
2
|
+
import { Repository, Relay, LOCAL_RELAY_URL, getFilterResultCardinality } from "@welshman/util";
|
|
3
|
+
import { Tracker, subscribe as baseSubscribe } from "@welshman/net";
|
|
4
|
+
import { createEventStore } from "@welshman/store";
|
|
5
|
+
export const repository = new Repository();
|
|
6
|
+
export const events = createEventStore(repository);
|
|
7
|
+
export const relay = new Relay(repository);
|
|
8
|
+
export const tracker = new Tracker();
|
|
9
|
+
export const subscribe = (request) => {
|
|
10
|
+
const events = [];
|
|
11
|
+
// If we already have all results for any filter, don't send the filter to the network
|
|
12
|
+
if (request.closeOnEose) {
|
|
13
|
+
for (const filter of request.filters.splice(0)) {
|
|
14
|
+
const cardinality = getFilterResultCardinality(filter);
|
|
15
|
+
if (!isNil(cardinality)) {
|
|
16
|
+
const results = repository.query([filter]);
|
|
17
|
+
if (results.length === cardinality) {
|
|
18
|
+
for (const event of results) {
|
|
19
|
+
events.push(event);
|
|
20
|
+
}
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
request.filters.push(filter);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Make sure to query our local relay too
|
|
28
|
+
const delay = ctx.app.requestDelay;
|
|
29
|
+
const timeout = ctx.app.requestTimeout;
|
|
30
|
+
const authTimeout = ctx.app.authTimeout;
|
|
31
|
+
const sub = baseSubscribe({ delay, timeout, authTimeout, relays: [], ...request });
|
|
32
|
+
sub.emitter.on("event", (url, e) => {
|
|
33
|
+
repository.publish(e);
|
|
34
|
+
});
|
|
35
|
+
// Keep cached results async so the caller can set up handlers
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
for (const event of events) {
|
|
38
|
+
sub.emitter.emit("event", LOCAL_RELAY_URL, event);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return sub;
|
|
42
|
+
};
|
|
43
|
+
export const load = (request) => new Promise(resolve => {
|
|
44
|
+
const sub = subscribe({ closeOnEose: true, timeout: ctx.app.requestTimeout, ...request });
|
|
45
|
+
const events = [];
|
|
46
|
+
sub.emitter.on("event", (url, e) => events.push(e));
|
|
47
|
+
sub.emitter.on("complete", () => resolve(events));
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=core.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.mjs","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"OAAO,EAAC,GAAG,EAAE,KAAK,EAAC,MAAM,eAAe;OACjC,EAAC,UAAU,EAAE,KAAK,EAAE,eAAe,EAAE,0BAA0B,EAAC,MAAM,gBAAgB;OAEtF,EAAC,OAAO,EAAE,SAAS,IAAI,aAAa,EAAC,MAAM,eAAe;OAE1D,EAAC,gBAAgB,EAAC,MAAM,iBAAiB;AAEhD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAgB,CAAA;AAExD,MAAM,CAAC,MAAM,MAAM,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAA;AAElD,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,UAAU,CAAC,CAAA;AAE1C,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAIpC,MAAM,CAAC,MAAM,SAAS,GAAG,CAA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AC,IAAI,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,CAAA;SAClD;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAgC,EAAE,EAAE,CACvD,IAAI,OAAO,CAAiB,OAAO,CAAC,EAAE;IACpC,MAAM,GAAG,GAAG,SAAS,CAAC,EAAC,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,OAAO,EAAC,CAAC,CAAA;IACvF,MAAM,MAAM,GAAmB,EAAE,CAAA;IAEjC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAW,EAAE,CAAe,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACzE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;AACnD,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.loadFollows = exports.deriveFollows = exports.followsByPubkey = exports.follows = void 0;
|
|
5
|
+
const util_1 = require("@welshman/util");
|
|
6
|
+
const store_1 = require("@welshman/store");
|
|
7
|
+
const core_1 = require("./core.cjs");
|
|
8
|
+
const collection_1 = require("./collection.cjs");
|
|
9
|
+
const plaintext_1 = require("./plaintext.cjs");
|
|
10
|
+
const relaySelections_1 = require("./relaySelections.cjs");
|
|
11
|
+
exports.follows = (0, store_1.withGetter)((0, store_1.deriveEventsMapped)(core_1.repository, {
|
|
12
|
+
filters: [{ kinds: [util_1.FOLLOWS] }],
|
|
13
|
+
itemToEvent: item => item.event,
|
|
14
|
+
eventToItem: async (event) => (0, util_1.readList)((0, util_1.asDecryptedEvent)(event, {
|
|
15
|
+
content: await (0, plaintext_1.ensurePlaintext)(event),
|
|
16
|
+
})),
|
|
17
|
+
}));
|
|
18
|
+
_a = (0, collection_1.collection)({
|
|
19
|
+
name: "follows",
|
|
20
|
+
store: exports.follows,
|
|
21
|
+
getKey: follows => follows.event.pubkey,
|
|
22
|
+
load: async (pubkey, request = {}) => {
|
|
23
|
+
await (0, relaySelections_1.loadRelaySelections)(pubkey, request);
|
|
24
|
+
await (0, core_1.load)({ ...request, filters: [{ kinds: [util_1.FOLLOWS], authors: [pubkey] }] });
|
|
25
|
+
},
|
|
26
|
+
}), exports.followsByPubkey = _a.indexStore, exports.deriveFollows = _a.deriveItem, exports.loadFollows = _a.loadItem;
|
|
27
|
+
//# sourceMappingURL=follows.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"follows.cjs","sourceRoot":"","sources":["../../src/follows.ts"],"names":[],"mappings":";;;;AAAA,yCAAkE;AAGlE,2CAA8D;AAC9D,qCAAuC;AACvC,iDAAuC;AACvC,+CAA2C;AAC3C,2DAAqD;AAExC,QAAA,OAAO,GAAG,IAAA,kBAAU,EAC/B,IAAA,0BAAkB,EAAgB,iBAAU,EAAE;IAC5C,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,cAAO,CAAC,EAAC,CAAC;IAC7B,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK;IAC/B,WAAW,EAAE,KAAK,EAAE,KAAmB,EAAE,EAAE,CACzC,IAAA,eAAQ,EACN,IAAA,uBAAgB,EAAC,KAAK,EAAE;QACtB,OAAO,EAAE,MAAM,IAAA,2BAAe,EAAC,KAAK,CAAC;KACtC,CAAC,CACH;CACJ,CAAC,CACH,CAAA;AAEY,KAIT,IAAA,uBAAU,EAAC;IACb,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,eAAO;IACd,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM;IACvC,IAAI,EAAE,KAAK,EAAE,MAAc,EAAE,UAAqC,EAAE,EAAE,EAAE;QACtE,MAAM,IAAA,qCAAmB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC1C,MAAM,IAAA,WAAI,EAAC,EAAC,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,cAAO,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,EAAC,CAAC,CAAA;IAC5E,CAAC;CACF,CAAC,EAXY,uBAAe,kBACf,qBAAa,kBACf,mBAAW,eASrB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import { type PublishedList } from '@welshman/util';
|
|
3
|
+
import { type SubscribeRequest } from "@welshman/net";
|
|
4
|
+
export declare const follows: import("svelte/store").Readable<PublishedList[]> & {
|
|
5
|
+
get: () => PublishedList[];
|
|
6
|
+
};
|
|
7
|
+
export declare const followsByPubkey: import("svelte/store").Readable<Map<string, PublishedList>> & {
|
|
8
|
+
get: () => Map<string, PublishedList>;
|
|
9
|
+
}, deriveFollows: (key: import("@welshman/lib").Maybe<string>, request?: Partial<SubscribeRequest> | undefined) => import("svelte/store").Readable<PublishedList | undefined>, loadFollows: (key: string, request?: Partial<SubscribeRequest> | undefined) => Promise<PublishedList | undefined>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FOLLOWS, asDecryptedEvent, readList } from '@welshman/util';
|
|
2
|
+
import { deriveEventsMapped, withGetter } from '@welshman/store';
|
|
3
|
+
import { repository, load } from "./core.mjs";
|
|
4
|
+
import { collection } from "./collection.mjs";
|
|
5
|
+
import { ensurePlaintext } from "./plaintext.mjs";
|
|
6
|
+
import { loadRelaySelections } from "./relaySelections.mjs";
|
|
7
|
+
export const follows = withGetter(deriveEventsMapped(repository, {
|
|
8
|
+
filters: [{ kinds: [FOLLOWS] }],
|
|
9
|
+
itemToEvent: item => item.event,
|
|
10
|
+
eventToItem: async (event) => readList(asDecryptedEvent(event, {
|
|
11
|
+
content: await ensurePlaintext(event),
|
|
12
|
+
})),
|
|
13
|
+
}));
|
|
14
|
+
export const { indexStore: followsByPubkey, deriveItem: deriveFollows, loadItem: loadFollows, } = collection({
|
|
15
|
+
name: "follows",
|
|
16
|
+
store: follows,
|
|
17
|
+
getKey: follows => follows.event.pubkey,
|
|
18
|
+
load: async (pubkey, request = {}) => {
|
|
19
|
+
await loadRelaySelections(pubkey, request);
|
|
20
|
+
await load({ ...request, filters: [{ kinds: [FOLLOWS], authors: [pubkey] }] });
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=follows.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"follows.mjs","sourceRoot":"","sources":["../../src/follows.ts"],"names":[],"mappings":"OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAC,MAAM,gBAAgB;OAG3D,EAAC,kBAAkB,EAAE,UAAU,EAAC,MAAM,iBAAiB;OACvD,EAAC,UAAU,EAAE,IAAI,EAAC;OAClB,EAAC,UAAU,EAAC;OACZ,EAAC,eAAe,EAAC;OACjB,EAAC,mBAAmB,EAAC;AAE5B,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAC/B,kBAAkB,CAAgB,UAAU,EAAE;IAC5C,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAC,CAAC;IAC7B,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK;IAC/B,WAAW,EAAE,KAAK,EAAE,KAAmB,EAAE,EAAE,CACzC,QAAQ,CACN,gBAAgB,CAAC,KAAK,EAAE;QACtB,OAAO,EAAE,MAAM,eAAe,CAAC,KAAK,CAAC;KACtC,CAAC,CACH;CACJ,CAAC,CACH,CAAA;AAED,MAAM,CAAC,MAAM,EACX,UAAU,EAAE,eAAe,EAC3B,UAAU,EAAE,aAAa,EACzB,QAAQ,EAAE,WAAW,GACtB,GAAG,UAAU,CAAC;IACb,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM;IACvC,IAAI,EAAE,KAAK,EAAE,MAAc,EAAE,UAAqC,EAAE,EAAE,EAAE;QACtE,MAAM,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC1C,MAAM,IAAI,CAAC,EAAC,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,EAAC,CAAC,CAAA;IAC5E,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setFreshnessBulk = exports.setFreshness = exports.getFreshness = exports.getFreshnessKey = exports.freshness = void 0;
|
|
4
|
+
const store_1 = require("svelte/store");
|
|
5
|
+
const lib_1 = require("@welshman/lib");
|
|
6
|
+
const store_2 = require("@welshman/store");
|
|
7
|
+
exports.freshness = (0, store_2.withGetter)((0, store_1.writable)({}));
|
|
8
|
+
const getFreshnessKey = (ns, key) => `${ns}:${key}`;
|
|
9
|
+
exports.getFreshnessKey = getFreshnessKey;
|
|
10
|
+
const getFreshness = (ns, key) => exports.freshness.get()[(0, exports.getFreshnessKey)(ns, key)] || 0;
|
|
11
|
+
exports.getFreshness = getFreshness;
|
|
12
|
+
const setFreshness = (ns, key, ts) => exports.freshness.update((0, lib_1.assoc)((0, exports.getFreshnessKey)(ns, key), ts));
|
|
13
|
+
exports.setFreshness = setFreshness;
|
|
14
|
+
const setFreshnessBulk = (ns, updates) => exports.freshness.update($freshness => {
|
|
15
|
+
for (const [key, ts] of Object.entries(updates)) {
|
|
16
|
+
$freshness[key] = ts;
|
|
17
|
+
}
|
|
18
|
+
return $freshness;
|
|
19
|
+
});
|
|
20
|
+
exports.setFreshnessBulk = setFreshnessBulk;
|
|
21
|
+
//# sourceMappingURL=freshness.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freshness.cjs","sourceRoot":"","sources":["../../src/freshness.ts"],"names":[],"mappings":";;;AAAA,wCAAqC;AACrC,uCAAmC;AACnC,2CAA0C;AAE7B,QAAA,SAAS,GAAG,IAAA,kBAAU,EAAC,IAAA,gBAAQ,EAAyB,EAAE,CAAC,CAAC,CAAA;AAElE,MAAM,eAAe,GAAG,CAAC,EAAU,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAA;AAA7D,QAAA,eAAe,mBAA8C;AAEnE,MAAM,YAAY,GAAG,CAAC,EAAU,EAAE,GAAW,EAAE,EAAE,CACtD,iBAAS,CAAC,GAAG,EAAE,CAAC,IAAA,uBAAe,EAAC,EAAE,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAA;AADnC,QAAA,YAAY,gBACuB;AAEzC,MAAM,YAAY,GAAG,CAAC,EAAU,EAAE,GAAW,EAAE,EAAU,EAAE,EAAE,CAClE,iBAAS,CAAC,MAAM,CAAC,IAAA,WAAK,EAAC,IAAA,uBAAe,EAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAD1C,QAAA,YAAY,gBAC8B;AAEhD,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAE,OAA+B,EAAE,EAAE,CAC9E,iBAAS,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;IAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC/C,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;KACrB;IAED,OAAO,UAAU,CAAA;AACnB,CAAC,CAAC,CAAA;AAPS,QAAA,gBAAgB,oBAOzB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
export declare const freshness: import("svelte/store").Writable<Record<string, number>> & {
|
|
3
|
+
get: () => Record<string, number>;
|
|
4
|
+
};
|
|
5
|
+
export declare const getFreshnessKey: (ns: string, key: string) => string;
|
|
6
|
+
export declare const getFreshness: (ns: string, key: string) => number;
|
|
7
|
+
export declare const setFreshness: (ns: string, key: string, ts: number) => void;
|
|
8
|
+
export declare const setFreshnessBulk: (ns: string, updates: Record<string, number>) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
import { assoc } from '@welshman/lib';
|
|
3
|
+
import { withGetter } from '@welshman/store';
|
|
4
|
+
export const freshness = withGetter(writable({}));
|
|
5
|
+
export const getFreshnessKey = (ns, key) => `${ns}:${key}`;
|
|
6
|
+
export const getFreshness = (ns, key) => freshness.get()[getFreshnessKey(ns, key)] || 0;
|
|
7
|
+
export const setFreshness = (ns, key, ts) => freshness.update(assoc(getFreshnessKey(ns, key), ts));
|
|
8
|
+
export const setFreshnessBulk = (ns, updates) => freshness.update($freshness => {
|
|
9
|
+
for (const [key, ts] of Object.entries(updates)) {
|
|
10
|
+
$freshness[key] = ts;
|
|
11
|
+
}
|
|
12
|
+
return $freshness;
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=freshness.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freshness.mjs","sourceRoot":"","sources":["../../src/freshness.ts"],"names":[],"mappings":"OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc;OAC9B,EAAC,KAAK,EAAC,MAAM,eAAe;OAC5B,EAAC,UAAU,EAAC,MAAM,iBAAiB;AAE1C,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAyB,EAAE,CAAC,CAAC,CAAA;AAEzE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAU,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAA;AAE1E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAU,EAAE,GAAW,EAAE,EAAE,CACtD,SAAS,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAA;AAEhD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAU,EAAE,GAAW,EAAE,EAAU,EAAE,EAAE,CAClE,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAEvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAE,OAA+B,EAAE,EAAE,CAC9E,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;IAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC/C,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;KACrB;IAED,OAAO,UAAU,CAAA;AACnB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.displayHandle = exports.deriveHandleForPubkey = exports.loadHandle = exports.deriveHandle = exports.handlesByNip05 = exports.fetchHandles = exports.handles = exports.queryProfile = exports.NIP05_REGEX = void 0;
|
|
5
|
+
const store_1 = require("svelte/store");
|
|
6
|
+
const store_2 = require("@welshman/store");
|
|
7
|
+
const lib_1 = require("@welshman/lib");
|
|
8
|
+
const collection_1 = require("./collection.cjs");
|
|
9
|
+
const profiles_1 = require("./profiles.cjs");
|
|
10
|
+
exports.NIP05_REGEX = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/;
|
|
11
|
+
async function queryProfile(nip05) {
|
|
12
|
+
const match = nip05.match(exports.NIP05_REGEX);
|
|
13
|
+
if (!match)
|
|
14
|
+
return undefined;
|
|
15
|
+
const [_, name = '_', domain] = match;
|
|
16
|
+
try {
|
|
17
|
+
const { names, relays = {}, nip46 = {} } = await (0, lib_1.fetchJson)(`https://${domain}/.well-known/nostr.json?name=${name}`);
|
|
18
|
+
const pubkey = names[name];
|
|
19
|
+
if (!pubkey) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
nip05,
|
|
24
|
+
pubkey,
|
|
25
|
+
nip46: nip46[pubkey],
|
|
26
|
+
relays: relays[pubkey],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (_e) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.queryProfile = queryProfile;
|
|
34
|
+
exports.handles = (0, store_2.withGetter)((0, store_1.writable)([]));
|
|
35
|
+
const fetchHandles = async (nip05s) => {
|
|
36
|
+
const base = lib_1.ctx.app.dufflepudUrl;
|
|
37
|
+
const handlesByNip05 = new Map();
|
|
38
|
+
// Use dufflepud if we it's set up to protect user privacy, otherwise fetch directly
|
|
39
|
+
if (base) {
|
|
40
|
+
const res = await (0, lib_1.tryCatch)(async () => await (0, lib_1.postJson)(`${base}/handle/info`, { handles: nip05s }));
|
|
41
|
+
for (const { handle: nip05, info } of (res === null || res === void 0 ? void 0 : res.data) || []) {
|
|
42
|
+
handlesByNip05.set(nip05, info);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const results = await Promise.all(nip05s.map(async (nip05) => ({ nip05, info: await (0, lib_1.tryCatch)(async () => await queryProfile(nip05)) })));
|
|
47
|
+
for (const { nip05, info } of results) {
|
|
48
|
+
if (info) {
|
|
49
|
+
handlesByNip05.set(nip05, info);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return handlesByNip05;
|
|
54
|
+
};
|
|
55
|
+
exports.fetchHandles = fetchHandles;
|
|
56
|
+
_a = (0, collection_1.collection)({
|
|
57
|
+
name: "handles",
|
|
58
|
+
store: exports.handles,
|
|
59
|
+
getKey: (handle) => handle.nip05,
|
|
60
|
+
load: (0, lib_1.batcher)(800, async (nip05s) => {
|
|
61
|
+
const fresh = await (0, exports.fetchHandles)((0, lib_1.uniq)(nip05s));
|
|
62
|
+
const stale = exports.handlesByNip05.get();
|
|
63
|
+
const items = nip05s.map(nip05 => {
|
|
64
|
+
const newHandle = fresh.get(nip05);
|
|
65
|
+
const oldHandle = stale.get(nip05);
|
|
66
|
+
if (newHandle) {
|
|
67
|
+
stale.set(nip05, { ...newHandle, nip05 });
|
|
68
|
+
}
|
|
69
|
+
return { ...oldHandle, ...newHandle, nip05 };
|
|
70
|
+
});
|
|
71
|
+
exports.handles.set(Array.from(stale.values()));
|
|
72
|
+
return items;
|
|
73
|
+
}),
|
|
74
|
+
}), exports.handlesByNip05 = _a.indexStore, exports.deriveHandle = _a.deriveItem, exports.loadHandle = _a.loadItem;
|
|
75
|
+
const deriveHandleForPubkey = (pubkey, request = {}) => (0, store_1.derived)([exports.handlesByNip05, (0, profiles_1.deriveProfile)(pubkey, request)], ([$handlesByNip05, $profile]) => {
|
|
76
|
+
if (!($profile === null || $profile === void 0 ? void 0 : $profile.nip05)) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
(0, exports.loadHandle)($profile.nip05);
|
|
80
|
+
return $handlesByNip05.get($profile.nip05);
|
|
81
|
+
});
|
|
82
|
+
exports.deriveHandleForPubkey = deriveHandleForPubkey;
|
|
83
|
+
const displayHandle = (handle) => handle.nip05.startsWith("_@") ? (0, lib_1.last)(handle.nip05.split("@")) : handle.nip05;
|
|
84
|
+
exports.displayHandle = displayHandle;
|
|
85
|
+
//# sourceMappingURL=handles.cjs.map
|
|
@@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AC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,UAAI,EAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAA;AADjE,QAAA,aAAa,iBACoD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import { type SubscribeRequest } from "@welshman/net";
|
|
3
|
+
export type Handle = {
|
|
4
|
+
nip05: string;
|
|
5
|
+
pubkey?: string;
|
|
6
|
+
nip46?: string[];
|
|
7
|
+
relays?: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare const NIP05_REGEX: RegExp;
|
|
10
|
+
export declare function queryProfile(nip05: string): Promise<{
|
|
11
|
+
nip05: string;
|
|
12
|
+
pubkey: any;
|
|
13
|
+
nip46: any;
|
|
14
|
+
relays: any;
|
|
15
|
+
} | undefined>;
|
|
16
|
+
export declare const handles: import("svelte/store").Writable<Handle[]> & {
|
|
17
|
+
get: () => Handle[];
|
|
18
|
+
};
|
|
19
|
+
export declare const fetchHandles: (nip05s: string[]) => Promise<Map<string, Handle>>;
|
|
20
|
+
export declare const handlesByNip05: import("svelte/store").Readable<Map<string, Handle>> & {
|
|
21
|
+
get: () => Map<string, Handle>;
|
|
22
|
+
}, deriveHandle: (key: import("@welshman/lib").Maybe<string>) => import("svelte/store").Readable<Handle | undefined>, loadHandle: (key: string) => Promise<Handle | undefined>;
|
|
23
|
+
export declare const deriveHandleForPubkey: (pubkey: string, request?: Partial<SubscribeRequest>) => import("svelte/store").Readable<Handle | undefined>;
|
|
24
|
+
export declare const displayHandle: (handle: Handle) => string;
|