@welshman/app 0.0.1 → 0.0.2
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 +40 -0
- package/build/src/collection.cjs.map +1 -0
- package/build/src/collection.d.ts +15 -0
- package/build/src/collection.mjs +36 -0
- package/build/src/collection.mjs.map +1 -0
- package/build/src/core.cjs +32 -0
- package/build/src/core.cjs.map +1 -0
- package/build/src/core.d.ts +16 -0
- package/build/src/core.mjs +26 -0
- package/build/src/core.mjs.map +1 -0
- package/build/src/follows.cjs +31 -0
- package/build/src/follows.cjs.map +1 -0
- package/build/src/follows.d.ts +9 -0
- package/build/src/follows.mjs +27 -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 +43 -0
- package/build/src/handles.cjs.map +1 -0
- package/build/src/handles.d.ts +16 -0
- package/build/src/handles.mjs +37 -0
- package/build/src/handles.mjs.map +1 -0
- package/build/src/index.cjs +23 -2
- package/build/src/index.cjs.map +1 -1
- package/build/src/index.d.ts +15 -2
- package/build/src/index.mjs +23 -2
- package/build/src/index.mjs.map +1 -1
- package/build/src/mutes.cjs +31 -0
- package/build/src/mutes.cjs.map +1 -0
- package/build/src/mutes.d.ts +9 -0
- package/build/src/mutes.mjs +27 -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 +13 -0
- package/build/src/profiles.mjs +34 -0
- package/build/src/profiles.mjs.map +1 -0
- package/build/src/relaySelections.cjs +28 -0
- package/build/src/relaySelections.cjs.map +1 -0
- package/build/src/relaySelections.d.ts +12 -0
- package/build/src/relaySelections.mjs +22 -0
- package/build/src/relaySelections.mjs.map +1 -0
- package/build/src/relays.cjs +122 -0
- package/build/src/relays.cjs.map +1 -0
- package/build/src/relays.d.ts +28 -0
- package/build/src/relays.mjs +115 -0
- package/build/src/relays.mjs.map +1 -0
- package/build/src/session.cjs +27 -18
- package/build/src/session.cjs.map +1 -1
- package/build/src/session.d.ts +13 -1
- package/build/src/session.mjs +23 -18
- package/build/src/session.mjs.map +1 -1
- package/build/src/storage.cjs +91 -0
- package/build/src/storage.cjs.map +1 -0
- package/build/src/storage.d.ts +21 -0
- package/build/src/storage.mjs +82 -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 +43 -0
- package/build/src/zappers.cjs.map +1 -0
- package/build/src/zappers.d.ts +10 -0
- package/build/src/zappers.mjs +38 -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,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensurePlaintext = exports.setPlaintext = exports.getPlaintext = exports.plaintext = 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 signer_1 = require("@welshman/signer");
|
|
8
|
+
const session_1 = require("./session.cjs");
|
|
9
|
+
exports.plaintext = (0, store_2.withGetter)((0, store_1.writable)({}));
|
|
10
|
+
const getPlaintext = (e) => exports.plaintext.get()[e.id];
|
|
11
|
+
exports.getPlaintext = getPlaintext;
|
|
12
|
+
const setPlaintext = (e, content) => exports.plaintext.update((0, lib_1.assoc)(e.id, content));
|
|
13
|
+
exports.setPlaintext = setPlaintext;
|
|
14
|
+
const ensurePlaintext = async (e) => {
|
|
15
|
+
if (e.content && !(0, exports.getPlaintext)(e)) {
|
|
16
|
+
const $signer = (0, session_1.getSigner)((0, session_1.getSession)(e.pubkey));
|
|
17
|
+
if ($signer) {
|
|
18
|
+
(0, exports.setPlaintext)(e, await (0, signer_1.decrypt)($signer, e.pubkey, e.content));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return (0, exports.getPlaintext)(e);
|
|
22
|
+
};
|
|
23
|
+
exports.ensurePlaintext = ensurePlaintext;
|
|
24
|
+
//# sourceMappingURL=plaintext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plaintext.cjs","sourceRoot":"","sources":["../../src/plaintext.ts"],"names":[],"mappings":";;;AAAA,wCAAqC;AACrC,uCAAmC;AAEnC,2CAA0C;AAC1C,6CAAwC;AACxC,2CAA+C;AAElC,QAAA,SAAS,GAAG,IAAA,kBAAU,EAAC,IAAA,gBAAQ,EAAyB,EAAE,CAAC,CAAC,CAAA;AAElE,MAAM,YAAY,GAAG,CAAC,CAAe,EAAE,EAAE,CAAC,iBAAS,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAAzD,QAAA,YAAY,gBAA6C;AAE/D,MAAM,YAAY,GAAG,CAAC,CAAe,EAAE,OAAe,EAAE,EAAE,CAC/D,iBAAS,CAAC,MAAM,CAAC,IAAA,WAAK,EAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;AAD3B,QAAA,YAAY,gBACe;AAEjC,MAAM,eAAe,GAAG,KAAK,EAAE,CAAe,EAAE,EAAE;IACvD,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,IAAA,oBAAY,EAAC,CAAC,CAAC,EAAE;QACjC,MAAM,OAAO,GAAG,IAAA,mBAAS,EAAC,IAAA,oBAAU,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;QAE/C,IAAI,OAAO,EAAE;YACX,IAAA,oBAAY,EAAC,CAAC,EAAE,MAAM,IAAA,gBAAO,EAAC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;SAC7D;KACF;IAED,OAAO,IAAA,oBAAY,EAAC,CAAC,CAAC,CAAA;AACxB,CAAC,CAAA;AAVY,QAAA,eAAe,mBAU3B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import type { TrustedEvent } from '@welshman/util';
|
|
3
|
+
export declare const plaintext: import("svelte/store").Writable<Record<string, string>> & {
|
|
4
|
+
get: () => Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
export declare const getPlaintext: (e: TrustedEvent) => string;
|
|
7
|
+
export declare const setPlaintext: (e: TrustedEvent, content: string) => void;
|
|
8
|
+
export declare const ensurePlaintext: (e: TrustedEvent) => Promise<string>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
import { assoc } from '@welshman/lib';
|
|
3
|
+
import { withGetter } from '@welshman/store';
|
|
4
|
+
import { decrypt } from "@welshman/signer";
|
|
5
|
+
import { getSigner, getSession } from "./session.mjs";
|
|
6
|
+
export const plaintext = withGetter(writable({}));
|
|
7
|
+
export const getPlaintext = (e) => plaintext.get()[e.id];
|
|
8
|
+
export const setPlaintext = (e, content) => plaintext.update(assoc(e.id, content));
|
|
9
|
+
export const ensurePlaintext = async (e) => {
|
|
10
|
+
if (e.content && !getPlaintext(e)) {
|
|
11
|
+
const $signer = getSigner(getSession(e.pubkey));
|
|
12
|
+
if ($signer) {
|
|
13
|
+
setPlaintext(e, await decrypt($signer, e.pubkey, e.content));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return getPlaintext(e);
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=plaintext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plaintext.mjs","sourceRoot":"","sources":["../../src/plaintext.ts"],"names":[],"mappings":"OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc;OAC9B,EAAC,KAAK,EAAC,MAAM,eAAe;OAE5B,EAAC,UAAU,EAAC,MAAM,iBAAiB;OACnC,EAAC,OAAO,EAAC,MAAM,kBAAkB;OACjC,EAAC,SAAS,EAAE,UAAU,EAAC;AAE9B,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAyB,EAAE,CAAC,CAAC,CAAA;AAEzE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAe,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAEtE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAe,EAAE,OAAe,EAAE,EAAE,CAC/D,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;AAExC,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,CAAe,EAAE,EAAE;IACvD,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE;QACjC,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;QAE/C,IAAI,OAAO,EAAE;YACX,YAAY,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;SAC7D;KACF;IAED,OAAO,YAAY,CAAC,CAAC,CAAC,CAAA;AACxB,CAAC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.deriveProfileDisplay = exports.displayProfileByPubkey = exports.profileSearch = exports.loadProfile = exports.deriveProfile = exports.profilesByPubkey = exports.profiles = void 0;
|
|
5
|
+
const store_1 = require("svelte/store");
|
|
6
|
+
const util_1 = require("@welshman/util");
|
|
7
|
+
const store_2 = require("@welshman/store");
|
|
8
|
+
const core_1 = require("./core.cjs");
|
|
9
|
+
const util_2 = require("./util.cjs");
|
|
10
|
+
const collection_1 = require("./collection.cjs");
|
|
11
|
+
const relaySelections_1 = require("./relaySelections.cjs");
|
|
12
|
+
exports.profiles = (0, store_2.deriveEventsMapped)(core_1.repository, {
|
|
13
|
+
filters: [{ kinds: [util_1.PROFILE] }],
|
|
14
|
+
eventToItem: util_1.readProfile,
|
|
15
|
+
itemToEvent: item => item.event,
|
|
16
|
+
});
|
|
17
|
+
_a = (0, collection_1.collection)({
|
|
18
|
+
name: "profiles",
|
|
19
|
+
store: exports.profiles,
|
|
20
|
+
getKey: profile => profile.event.pubkey,
|
|
21
|
+
load: async (pubkey, hints = [], request = {}) => {
|
|
22
|
+
const relays = (0, relaySelections_1.getWriteRelayUrls)(await (0, relaySelections_1.loadRelaySelections)(pubkey, hints));
|
|
23
|
+
return (0, core_1.load)({
|
|
24
|
+
...request,
|
|
25
|
+
relays: [...relays, ...hints],
|
|
26
|
+
filters: [{ kinds: [util_1.PROFILE], authors: [pubkey] }],
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
}), exports.profilesByPubkey = _a.indexStore, exports.deriveProfile = _a.deriveItem, exports.loadProfile = _a.loadItem;
|
|
30
|
+
exports.profileSearch = (0, store_1.derived)(exports.profiles, $profiles => (0, util_2.createSearch)($profiles, {
|
|
31
|
+
getValue: (profile) => profile.event.pubkey,
|
|
32
|
+
fuseOptions: {
|
|
33
|
+
keys: ["name", "display_name", { name: "about", weight: 0.3 }],
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
const displayProfileByPubkey = (pubkey) => (0, util_1.displayProfile)(exports.profilesByPubkey.get().get(pubkey), (0, util_1.displayPubkey)(pubkey));
|
|
37
|
+
exports.displayProfileByPubkey = displayProfileByPubkey;
|
|
38
|
+
const deriveProfileDisplay = (pubkey) => (0, store_1.derived)((0, exports.deriveProfile)(pubkey), $profile => (0, util_1.displayProfile)($profile, (0, util_1.displayPubkey)(pubkey)));
|
|
39
|
+
exports.deriveProfileDisplay = deriveProfileDisplay;
|
|
40
|
+
//# sourceMappingURL=profiles.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.cjs","sourceRoot":"","sources":["../../src/profiles.ts"],"names":[],"mappings":";;;;AAAA,wCAAoC;AACpC,yCAAkF;AAGlF,2CAAkD;AAClD,qCAAuC;AACvC,qCAAmC;AACnC,iDAAuC;AACvC,2DAAwE;AAE3D,QAAA,QAAQ,GAAG,IAAA,0BAAkB,EAAmB,iBAAU,EAAE;IACvE,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,cAAO,CAAC,EAAC,CAAC;IAC7B,WAAW,EAAE,kBAAW;IACxB,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK;CAChC,CAAC,CAAA;AAEW,KAIT,IAAA,uBAAU,EAAC;IACb,IAAI,EAAE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,eAAO,EAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAA,qBAAc,EAAC,QAAQ,EAAE,IAAA,oBAAa,EAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AADhF,QAAA,oBAAoB,wBAC4D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import { type SubscribeRequest } from "@welshman/net";
|
|
3
|
+
import { type PublishedProfile } from "@welshman/util";
|
|
4
|
+
export declare const profiles: {
|
|
5
|
+
set: (newValue: PublishedProfile[]) => void;
|
|
6
|
+
subscribe: (sub: import("svelte/store").Subscriber<PublishedProfile[]>) => () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const profilesByPubkey: import("svelte/store").Readable<Map<string, PublishedProfile>> & {
|
|
9
|
+
get: () => Map<string, PublishedProfile>;
|
|
10
|
+
}, deriveProfile: (key: import("@welshman/lib").Maybe<string>, hints?: any, request?: Partial<SubscribeRequest> | undefined) => import("svelte/store").Readable<PublishedProfile | undefined>, loadProfile: (key: string, hints?: any, request?: Partial<SubscribeRequest> | undefined) => Promise<PublishedProfile | undefined>;
|
|
11
|
+
export declare const profileSearch: import("svelte/store").Readable<import("./util").Search<string, PublishedProfile>>;
|
|
12
|
+
export declare const displayProfileByPubkey: (pubkey: string) => string;
|
|
13
|
+
export declare const deriveProfileDisplay: (pubkey: string) => import("svelte/store").Readable<string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { derived } from 'svelte/store';
|
|
2
|
+
import { readProfile, displayProfile, displayPubkey, PROFILE } from '@welshman/util';
|
|
3
|
+
import { deriveEventsMapped } from '@welshman/store';
|
|
4
|
+
import { repository, load } from "./core.mjs";
|
|
5
|
+
import { createSearch } from "./util.mjs";
|
|
6
|
+
import { collection } from "./collection.mjs";
|
|
7
|
+
import { getWriteRelayUrls, loadRelaySelections } from "./relaySelections.mjs";
|
|
8
|
+
export const profiles = deriveEventsMapped(repository, {
|
|
9
|
+
filters: [{ kinds: [PROFILE] }],
|
|
10
|
+
eventToItem: readProfile,
|
|
11
|
+
itemToEvent: item => item.event,
|
|
12
|
+
});
|
|
13
|
+
export const { indexStore: profilesByPubkey, deriveItem: deriveProfile, loadItem: loadProfile, } = collection({
|
|
14
|
+
name: "profiles",
|
|
15
|
+
store: profiles,
|
|
16
|
+
getKey: profile => profile.event.pubkey,
|
|
17
|
+
load: async (pubkey, hints = [], request = {}) => {
|
|
18
|
+
const relays = getWriteRelayUrls(await loadRelaySelections(pubkey, hints));
|
|
19
|
+
return load({
|
|
20
|
+
...request,
|
|
21
|
+
relays: [...relays, ...hints],
|
|
22
|
+
filters: [{ kinds: [PROFILE], authors: [pubkey] }],
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
export const profileSearch = derived(profiles, $profiles => createSearch($profiles, {
|
|
27
|
+
getValue: (profile) => profile.event.pubkey,
|
|
28
|
+
fuseOptions: {
|
|
29
|
+
keys: ["name", "display_name", { name: "about", weight: 0.3 }],
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
export const displayProfileByPubkey = (pubkey) => displayProfile(profilesByPubkey.get().get(pubkey), displayPubkey(pubkey));
|
|
33
|
+
export const deriveProfileDisplay = (pubkey) => derived(deriveProfile(pubkey), $profile => displayProfile($profile, displayPubkey(pubkey)));
|
|
34
|
+
//# sourceMappingURL=profiles.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.mjs","sourceRoot":"","sources":["../../src/profiles.ts"],"names":[],"mappings":"OAAO,EAAC,OAAO,EAAC,MAAM,cAAc;OAC7B,EAAC,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,OAAO,EAAC,MAAM,gBAAgB;OAG3E,EAAC,kBAAkB,EAAC,MAAM,iBAAiB;OAC3C,EAAC,UAAU,EAAE,IAAI,EAAC;OAClB,EAAC,YAAY,EAAC;OACd,EAAC,UAAU,EAAC;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IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAC,CAAC;KAC7D;CACF,CAAC,CACH,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAE,EAAE,CACvD,cAAc,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;AAE3E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAE,EAAE,CACrD,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.loadRelaySelections = exports.deriveRelaySelections = exports.relaySelectionsByPubkey = exports.relaySelections = exports.getWriteRelayUrls = exports.getReadRelayUrls = 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 getReadRelayUrls = (event) => (0, util_1.getRelayTags)((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
10
|
+
.filter((t) => !t[2] || t[2] === "read")
|
|
11
|
+
.map((t) => (0, util_1.normalizeRelayUrl)(t[1]));
|
|
12
|
+
exports.getReadRelayUrls = getReadRelayUrls;
|
|
13
|
+
const getWriteRelayUrls = (event) => (0, util_1.getRelayTags)((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
14
|
+
.filter((t) => !t[2] || t[2] === "write")
|
|
15
|
+
.map((t) => (0, util_1.normalizeRelayUrl)(t[1]));
|
|
16
|
+
exports.getWriteRelayUrls = getWriteRelayUrls;
|
|
17
|
+
exports.relaySelections = (0, store_1.deriveEvents)(core_1.repository, { filters: [{ kinds: [util_1.RELAYS] }] });
|
|
18
|
+
_a = (0, collection_1.collection)({
|
|
19
|
+
name: "relaySelections",
|
|
20
|
+
store: exports.relaySelections,
|
|
21
|
+
getKey: relaySelections => relaySelections.pubkey,
|
|
22
|
+
load: (pubkey, relays, request = {}) => (0, core_1.load)({
|
|
23
|
+
...request,
|
|
24
|
+
relays,
|
|
25
|
+
filters: [{ kinds: [util_1.RELAYS], authors: [pubkey] }],
|
|
26
|
+
}),
|
|
27
|
+
}), exports.relaySelectionsByPubkey = _a.indexStore, exports.deriveRelaySelections = _a.deriveItem, exports.loadRelaySelections = _a.loadItem;
|
|
28
|
+
//# sourceMappingURL=relaySelections.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relaySelections.cjs","sourceRoot":"","sources":["../../src/relaySelections.ts"],"names":[],"mappings":";;;;AAAA,yCAAyF;AAEzF,2CAA4C;AAC5C,qCAAuC;AACvC,iDAAuC;AAEhC,MAAM,gBAAgB,GAAG,CAAC,KAAoB,EAAY,EAAE,CACjE,IAAA,mBAAY,EAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,KAAI,EAAE,CAAC;KAC5B,MAAM,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC;KACjD,GAAG,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,IAAA,wBAAiB,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAHrC,QAAA,gBAAgB,oBAGqB;AAE3C,MAAM,iBAAiB,GAAG,CAAC,KAAoB,EAAY,EAAE,CAClE,IAAA,mBAAY,EAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,KAAI,EAAE,CAAC;KAC5B,MAAM,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;KAClD,GAAG,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,IAAA,wBAAiB,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAHrC,QAAA,iBAAiB,qBAGoB;AAErC,QAAA,eAAe,GAAG,IAAA,oBAAY,EAAC,iBAAU,EAAE,EAAC,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,aAAM,CAAC,EAAC,CAAC,EAAC,CAAC,CAAA;AAE1E,KAIT,IAAA,uBAAU,EAAC;IACb,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,uBAAe;IACtB,MAAM,EAAE,eAAe,CAAC,EAAE,CAAC,eAAe,CAAC,MAAM;IACjD,IAAI,EAAE,CAAC,MAAc,EAAE,MAAgB,EAAE,UAAqC,EAAE,EAAE,EAAE,CAClF,IAAA,WAAI,EAAC;QACH,GAAG,OAAO;QACV,MAAM;QACN,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,aAAM,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC;KAChD,CAAC;CACL,CAAC,EAbY,+BAAuB,kBACvB,6BAAqB,kBACvB,2BAAmB,eAW7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import { type TrustedEvent } from '@welshman/util';
|
|
3
|
+
import { type SubscribeRequest } from "@welshman/net";
|
|
4
|
+
export declare const getReadRelayUrls: (event?: TrustedEvent) => string[];
|
|
5
|
+
export declare const getWriteRelayUrls: (event?: TrustedEvent) => string[];
|
|
6
|
+
export declare const relaySelections: {
|
|
7
|
+
set: (newValue: TrustedEvent[]) => void;
|
|
8
|
+
subscribe: (sub: import("svelte/store").Subscriber<TrustedEvent[]>) => () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const relaySelectionsByPubkey: import("svelte/store").Readable<Map<string, TrustedEvent>> & {
|
|
11
|
+
get: () => Map<string, TrustedEvent>;
|
|
12
|
+
}, deriveRelaySelections: (key: import("@welshman/lib").Maybe<string>, relays: string[], request?: Partial<SubscribeRequest> | undefined) => import("svelte/store").Readable<TrustedEvent | undefined>, loadRelaySelections: (key: string, relays: string[], request?: Partial<SubscribeRequest> | undefined) => Promise<TrustedEvent | undefined>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RELAYS, getRelayTags, normalizeRelayUrl } from '@welshman/util';
|
|
2
|
+
import { deriveEvents } from '@welshman/store';
|
|
3
|
+
import { load, repository } from "./core.mjs";
|
|
4
|
+
import { collection } from "./collection.mjs";
|
|
5
|
+
export const getReadRelayUrls = (event) => getRelayTags((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
6
|
+
.filter((t) => !t[2] || t[2] === "read")
|
|
7
|
+
.map((t) => normalizeRelayUrl(t[1]));
|
|
8
|
+
export const getWriteRelayUrls = (event) => getRelayTags((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
9
|
+
.filter((t) => !t[2] || t[2] === "write")
|
|
10
|
+
.map((t) => normalizeRelayUrl(t[1]));
|
|
11
|
+
export const relaySelections = deriveEvents(repository, { filters: [{ kinds: [RELAYS] }] });
|
|
12
|
+
export const { indexStore: relaySelectionsByPubkey, deriveItem: deriveRelaySelections, loadItem: loadRelaySelections, } = collection({
|
|
13
|
+
name: "relaySelections",
|
|
14
|
+
store: relaySelections,
|
|
15
|
+
getKey: relaySelections => relaySelections.pubkey,
|
|
16
|
+
load: (pubkey, relays, request = {}) => load({
|
|
17
|
+
...request,
|
|
18
|
+
relays,
|
|
19
|
+
filters: [{ kinds: [RELAYS], authors: [pubkey] }],
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=relaySelections.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relaySelections.mjs","sourceR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GAAG,UAAU,CAAC;IACb,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,eAAe;IACtB,MAAM,EAAE,eAAe,CAAC,EAAE,CAAC,eAAe,CAAC,MAAM;IACjD,IAAI,EAAE,CAAC,MAAc,EAAE,MAAgB,EAAE,UAAqC,EAAE,EAAE,EAAE,CAClF,IAAI,CAAC;QACH,GAAG,OAAO;QACV,MAAM;QACN,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC;KAChD,CAAC;CACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.trackRelayStats = exports.relaySearch = exports.loadRelay = exports.deriveRelay = exports.relaysByUrl = exports.fetchRelayProfiles = exports.relaysByPubkey = exports.relays = exports.makeRelayStats = 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 net_1 = require("@welshman/net");
|
|
9
|
+
const core_1 = require("./core.cjs");
|
|
10
|
+
const util_1 = require("./util.cjs");
|
|
11
|
+
const collection_1 = require("./collection.cjs");
|
|
12
|
+
// Relays
|
|
13
|
+
const makeRelayStats = () => ({
|
|
14
|
+
first_seen: (0, lib_1.now)(),
|
|
15
|
+
event_count: 0,
|
|
16
|
+
request_count: 0,
|
|
17
|
+
publish_count: 0,
|
|
18
|
+
connect_count: 0,
|
|
19
|
+
recent_errors: [],
|
|
20
|
+
last_auth_status: net_1.AuthStatus.Pending,
|
|
21
|
+
});
|
|
22
|
+
exports.makeRelayStats = makeRelayStats;
|
|
23
|
+
exports.relays = (0, store_2.withGetter)((0, store_1.writable)([]));
|
|
24
|
+
exports.relaysByPubkey = (0, store_1.derived)(exports.relays, $relays => (0, lib_1.groupBy)($relay => { var _a; return (_a = $relay.profile) === null || _a === void 0 ? void 0 : _a.pubkey; }, $relays.filter($relay => { var _a; return (_a = $relay.profile) === null || _a === void 0 ? void 0 : _a.pubkey; })));
|
|
25
|
+
const fetchRelayProfiles = (urls) => {
|
|
26
|
+
const base = core_1.env.DUFFLEPUD_URL;
|
|
27
|
+
if (!base) {
|
|
28
|
+
throw new Error("DUFFLEPUD_URL is required to fetch relay metadata");
|
|
29
|
+
}
|
|
30
|
+
const res = (0, lib_1.postJson)(`${base}/relay/info`, { urls });
|
|
31
|
+
const profilesByUrl = new Map();
|
|
32
|
+
for (const { url, info } of (res === null || res === void 0 ? void 0 : res.data) || []) {
|
|
33
|
+
profilesByUrl.set(url, info);
|
|
34
|
+
}
|
|
35
|
+
return profilesByUrl;
|
|
36
|
+
};
|
|
37
|
+
exports.fetchRelayProfiles = fetchRelayProfiles;
|
|
38
|
+
_a = (0, collection_1.collection)({
|
|
39
|
+
name: "relays",
|
|
40
|
+
store: exports.relays,
|
|
41
|
+
getKey: (relay) => relay.url,
|
|
42
|
+
load: (0, lib_1.batcher)(800, async (urls) => {
|
|
43
|
+
const profilesByUrl = await (0, exports.fetchRelayProfiles)((0, lib_1.uniq)(urls));
|
|
44
|
+
const index = exports.relaysByUrl.get();
|
|
45
|
+
const items = urls.map(url => {
|
|
46
|
+
const relay = index.get(url);
|
|
47
|
+
const profile = profilesByUrl.get(url) || (relay === null || relay === void 0 ? void 0 : relay.profile);
|
|
48
|
+
return { ...relay, profile, url };
|
|
49
|
+
});
|
|
50
|
+
exports.relays.update($relays => (0, lib_1.uniqBy)($relay => $relay.url, [...$relays, ...items]));
|
|
51
|
+
return items;
|
|
52
|
+
}),
|
|
53
|
+
}), exports.relaysByUrl = _a.indexStore, exports.deriveRelay = _a.deriveItem, exports.loadRelay = _a.loadItem;
|
|
54
|
+
exports.relaySearch = (0, store_1.derived)(exports.relays, $relays => (0, util_1.createSearch)($relays, {
|
|
55
|
+
getValue: (relay) => relay.url,
|
|
56
|
+
fuseOptions: {
|
|
57
|
+
keys: ["url", "name", { name: "description", weight: 0.3 }],
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
const updateRelayStats = (0, lib_1.batch)(500, (updates) => {
|
|
61
|
+
const updatesByUrl = (0, lib_1.groupBy)((0, lib_1.nth)(0), updates);
|
|
62
|
+
exports.relays.update($relays => {
|
|
63
|
+
return $relays.map($relay => {
|
|
64
|
+
for (const [_, update] of updatesByUrl.get($relay.url) || []) {
|
|
65
|
+
if (!$relay.stats) {
|
|
66
|
+
$relay.stats = (0, exports.makeRelayStats)();
|
|
67
|
+
}
|
|
68
|
+
update($relay.stats);
|
|
69
|
+
}
|
|
70
|
+
return $relay;
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
const onConnectionError = ({ url }) => updateRelayStats([url, stats => {
|
|
75
|
+
stats.recent_errors = stats.recent_errors.concat((0, lib_1.now)()).slice(-10);
|
|
76
|
+
}]);
|
|
77
|
+
const onConnectionSend = ({ url }, socketMessage) => {
|
|
78
|
+
const [verb] = (0, net_1.asMessage)(socketMessage);
|
|
79
|
+
if (verb === 'REQ') {
|
|
80
|
+
updateRelayStats([url, stats => {
|
|
81
|
+
stats.request_count = stats.request_count + 1;
|
|
82
|
+
}]);
|
|
83
|
+
}
|
|
84
|
+
else if (verb === 'EVENT') {
|
|
85
|
+
updateRelayStats([url, stats => {
|
|
86
|
+
stats.publish_count = stats.publish_count + 1;
|
|
87
|
+
}]);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const onConnectionReceive = ({ url }, socketMessage) => {
|
|
91
|
+
const [verb] = (0, net_1.asMessage)(socketMessage);
|
|
92
|
+
if (verb === 'EVENT') {
|
|
93
|
+
updateRelayStats([url, stats => {
|
|
94
|
+
stats.event_count = stats.event_count + 1;
|
|
95
|
+
}]);
|
|
96
|
+
}
|
|
97
|
+
else if (verb === 'OK') {
|
|
98
|
+
updateRelayStats([url, stats => {
|
|
99
|
+
stats.last_auth_status = net_1.AuthStatus.Ok;
|
|
100
|
+
}]);
|
|
101
|
+
}
|
|
102
|
+
else if (verb === 'AUTH') {
|
|
103
|
+
updateRelayStats([url, stats => {
|
|
104
|
+
stats.last_auth_status = net_1.AuthStatus.Unauthorized;
|
|
105
|
+
}]);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const trackRelayStats = (connection) => {
|
|
109
|
+
updateRelayStats([connection.url, stats => {
|
|
110
|
+
stats.connect_count = stats.connect_count + 1;
|
|
111
|
+
}]);
|
|
112
|
+
connection.on('error', onConnectionError);
|
|
113
|
+
connection.on('send', onConnectionSend);
|
|
114
|
+
connection.on('receive', onConnectionReceive);
|
|
115
|
+
return () => {
|
|
116
|
+
connection.off('error', onConnectionError);
|
|
117
|
+
connection.off('send', onConnectionSend);
|
|
118
|
+
connection.off('receive', onConnectionReceive);
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
exports.trackRelayStats = trackRelayStats;
|
|
122
|
+
//# sourceMappingURL=relays.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relays.cjs","sourceRoot":"","sources":["../../src/relays.ts"],"names":[],"mappings":";;;;AAAA,wCAA8C;AAC9C,2CAA0C;AAC1C,uCAAuF;AAEvF,uCAAwF;AACxF,qCAA0B;AAC1B,qCAAmC;AACnC,iDAAuC;AAYvC,SAAS;AAEF,MAAM,cAAc,GAAG,GAAe,EAAE,CAAC,CAAC;IAC/C,UAAU,EAAE,IAAA,SAAG,GAAE;IACjB,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,EAAE;IACjB,gBAAgB,EAAE,gBAAU,CAAC,OAAO;CACrC,CAAC,CAAA;AARW,QAAA,cAAc,kBAQzB;AAQW,QAAA,MAAM,GAAG,IAAA,kBAAU,EAAC,IAAA,gBAAQ,EAAU,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EAAE;QACV,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;QAC1C,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;QACxC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;IAChD,CAAC,CAAA;AACH,CAAC,CAAA;AAdY,QAAA,eAAe,mBAc3B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import { type RelayProfile } from "@welshman/util";
|
|
3
|
+
import { AuthStatus, type Connection } from '@welshman/net';
|
|
4
|
+
export type RelayStats = {
|
|
5
|
+
first_seen: number;
|
|
6
|
+
event_count: number;
|
|
7
|
+
request_count: number;
|
|
8
|
+
publish_count: number;
|
|
9
|
+
connect_count: number;
|
|
10
|
+
recent_errors: number[];
|
|
11
|
+
last_auth_status: AuthStatus;
|
|
12
|
+
};
|
|
13
|
+
export declare const makeRelayStats: () => RelayStats;
|
|
14
|
+
export type Relay = {
|
|
15
|
+
url: string;
|
|
16
|
+
stats?: RelayStats;
|
|
17
|
+
profile?: RelayProfile;
|
|
18
|
+
};
|
|
19
|
+
export declare const relays: import("svelte/store").Writable<Relay[]> & {
|
|
20
|
+
get: () => Relay[];
|
|
21
|
+
};
|
|
22
|
+
export declare const relaysByPubkey: import("svelte/store").Readable<Map<string | undefined, Relay[]>>;
|
|
23
|
+
export declare const fetchRelayProfiles: (urls: string[]) => Map<string, RelayProfile>;
|
|
24
|
+
export declare const relaysByUrl: import("svelte/store").Readable<Map<string, Relay>> & {
|
|
25
|
+
get: () => Map<string, Relay>;
|
|
26
|
+
}, deriveRelay: (key: import("@welshman/lib").Maybe<string>) => import("svelte/store").Readable<Relay | undefined>, loadRelay: (key: string) => Promise<Relay | undefined>;
|
|
27
|
+
export declare const relaySearch: import("svelte/store").Readable<import("./util").Search<string, Relay>>;
|
|
28
|
+
export declare const trackRelayStats: (connection: Connection) => () => void;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { writable, derived } from 'svelte/store';
|
|
2
|
+
import { withGetter } from '@welshman/store';
|
|
3
|
+
import { groupBy, batch, nth, now, uniq, uniqBy, batcher, postJson } from '@welshman/lib';
|
|
4
|
+
import { AuthStatus, asMessage } from '@welshman/net';
|
|
5
|
+
import { env } from "./core.mjs";
|
|
6
|
+
import { createSearch } from "./util.mjs";
|
|
7
|
+
import { collection } from "./collection.mjs";
|
|
8
|
+
// Relays
|
|
9
|
+
export const makeRelayStats = () => ({
|
|
10
|
+
first_seen: now(),
|
|
11
|
+
event_count: 0,
|
|
12
|
+
request_count: 0,
|
|
13
|
+
publish_count: 0,
|
|
14
|
+
connect_count: 0,
|
|
15
|
+
recent_errors: [],
|
|
16
|
+
last_auth_status: AuthStatus.Pending,
|
|
17
|
+
});
|
|
18
|
+
export const relays = withGetter(writable([]));
|
|
19
|
+
export const relaysByPubkey = derived(relays, $relays => groupBy($relay => { var _a; return (_a = $relay.profile) === null || _a === void 0 ? void 0 : _a.pubkey; }, $relays.filter($relay => { var _a; return (_a = $relay.profile) === null || _a === void 0 ? void 0 : _a.pubkey; })));
|
|
20
|
+
export const fetchRelayProfiles = (urls) => {
|
|
21
|
+
const base = env.DUFFLEPUD_URL;
|
|
22
|
+
if (!base) {
|
|
23
|
+
throw new Error("DUFFLEPUD_URL is required to fetch relay metadata");
|
|
24
|
+
}
|
|
25
|
+
const res = postJson(`${base}/relay/info`, { urls });
|
|
26
|
+
const profilesByUrl = new Map();
|
|
27
|
+
for (const { url, info } of (res === null || res === void 0 ? void 0 : res.data) || []) {
|
|
28
|
+
profilesByUrl.set(url, info);
|
|
29
|
+
}
|
|
30
|
+
return profilesByUrl;
|
|
31
|
+
};
|
|
32
|
+
export const { indexStore: relaysByUrl, deriveItem: deriveRelay, loadItem: loadRelay, } = collection({
|
|
33
|
+
name: "relays",
|
|
34
|
+
store: relays,
|
|
35
|
+
getKey: (relay) => relay.url,
|
|
36
|
+
load: batcher(800, async (urls) => {
|
|
37
|
+
const profilesByUrl = await fetchRelayProfiles(uniq(urls));
|
|
38
|
+
const index = relaysByUrl.get();
|
|
39
|
+
const items = urls.map(url => {
|
|
40
|
+
const relay = index.get(url);
|
|
41
|
+
const profile = profilesByUrl.get(url) || (relay === null || relay === void 0 ? void 0 : relay.profile);
|
|
42
|
+
return { ...relay, profile, url };
|
|
43
|
+
});
|
|
44
|
+
relays.update($relays => uniqBy($relay => $relay.url, [...$relays, ...items]));
|
|
45
|
+
return items;
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
export const relaySearch = derived(relays, $relays => createSearch($relays, {
|
|
49
|
+
getValue: (relay) => relay.url,
|
|
50
|
+
fuseOptions: {
|
|
51
|
+
keys: ["url", "name", { name: "description", weight: 0.3 }],
|
|
52
|
+
},
|
|
53
|
+
}));
|
|
54
|
+
const updateRelayStats = batch(500, (updates) => {
|
|
55
|
+
const updatesByUrl = groupBy(nth(0), updates);
|
|
56
|
+
relays.update($relays => {
|
|
57
|
+
return $relays.map($relay => {
|
|
58
|
+
for (const [_, update] of updatesByUrl.get($relay.url) || []) {
|
|
59
|
+
if (!$relay.stats) {
|
|
60
|
+
$relay.stats = makeRelayStats();
|
|
61
|
+
}
|
|
62
|
+
update($relay.stats);
|
|
63
|
+
}
|
|
64
|
+
return $relay;
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
const onConnectionError = ({ url }) => updateRelayStats([url, stats => {
|
|
69
|
+
stats.recent_errors = stats.recent_errors.concat(now()).slice(-10);
|
|
70
|
+
}]);
|
|
71
|
+
const onConnectionSend = ({ url }, socketMessage) => {
|
|
72
|
+
const [verb] = asMessage(socketMessage);
|
|
73
|
+
if (verb === 'REQ') {
|
|
74
|
+
updateRelayStats([url, stats => {
|
|
75
|
+
stats.request_count = stats.request_count + 1;
|
|
76
|
+
}]);
|
|
77
|
+
}
|
|
78
|
+
else if (verb === 'EVENT') {
|
|
79
|
+
updateRelayStats([url, stats => {
|
|
80
|
+
stats.publish_count = stats.publish_count + 1;
|
|
81
|
+
}]);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const onConnectionReceive = ({ url }, socketMessage) => {
|
|
85
|
+
const [verb] = asMessage(socketMessage);
|
|
86
|
+
if (verb === 'EVENT') {
|
|
87
|
+
updateRelayStats([url, stats => {
|
|
88
|
+
stats.event_count = stats.event_count + 1;
|
|
89
|
+
}]);
|
|
90
|
+
}
|
|
91
|
+
else if (verb === 'OK') {
|
|
92
|
+
updateRelayStats([url, stats => {
|
|
93
|
+
stats.last_auth_status = AuthStatus.Ok;
|
|
94
|
+
}]);
|
|
95
|
+
}
|
|
96
|
+
else if (verb === 'AUTH') {
|
|
97
|
+
updateRelayStats([url, stats => {
|
|
98
|
+
stats.last_auth_status = AuthStatus.Unauthorized;
|
|
99
|
+
}]);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
export const trackRelayStats = (connection) => {
|
|
103
|
+
updateRelayStats([connection.url, stats => {
|
|
104
|
+
stats.connect_count = stats.connect_count + 1;
|
|
105
|
+
}]);
|
|
106
|
+
connection.on('error', onConnectionError);
|
|
107
|
+
connection.on('send', onConnectionSend);
|
|
108
|
+
connection.on('receive', onConnectionReceive);
|
|
109
|
+
return () => {
|
|
110
|
+
connection.off('error', onConnectionError);
|
|
111
|
+
connection.off('send', onConnectionSend);
|
|
112
|
+
connection.off('receive', onConnectionReceive);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=relays.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relays.mjs","sourceRoot":"","sources":["../../src/relays.ts"],"names":[],"mappings":"OAAO,EAAC,QAAQ,EAAE,OAAO,EAAC,MAAM,cAAc;OACvC,EAAC,UAAU,EAAC,MAAM,iBAAiB;OACnC,EAAC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE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AA;KACJ;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAsB,EAAE,EAAE;IACxD,gBAAgB,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE;YACxC,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,GAAG,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAC,CAAA;IAEH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;IACzC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IACvC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;IAE7C,OAAO,GAAG,EAAE;QACV,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;QAC1C,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;QACxC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAA;IAChD,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/build/src/session.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signer = exports.getSigner = exports.nip46Perms = exports.addSession = exports.getSession = exports.session = exports.sessions = exports.pubkey = void 0;
|
|
3
|
+
exports.onAuth = exports.authChallenges = exports.signer = exports.getSigner = exports.nip46Perms = exports.dropSession = exports.updateSession = exports.putSession = exports.addSession = exports.getSession = exports.session = exports.sessions = exports.pubkey = void 0;
|
|
4
4
|
const store_1 = require("svelte/store");
|
|
5
5
|
const lib_1 = require("@welshman/lib");
|
|
6
6
|
const util_1 = require("@welshman/util");
|
|
@@ -17,6 +17,16 @@ const addSession = (session) => {
|
|
|
17
17
|
exports.pubkey.set(session.pubkey);
|
|
18
18
|
};
|
|
19
19
|
exports.addSession = addSession;
|
|
20
|
+
const putSession = (session) => {
|
|
21
|
+
if (!(0, lib_1.equals)((0, exports.getSession)(session.pubkey), session)) {
|
|
22
|
+
exports.sessions.update((0, lib_1.assoc)(session.pubkey, session));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.putSession = putSession;
|
|
26
|
+
const updateSession = (pubkey, f) => (0, exports.putSession)(f((0, exports.getSession)(pubkey)));
|
|
27
|
+
exports.updateSession = updateSession;
|
|
28
|
+
const dropSession = (pubkey) => exports.sessions.update($sessions => (0, lib_1.omit)([pubkey], $sessions));
|
|
29
|
+
exports.dropSession = dropSession;
|
|
20
30
|
exports.nip46Perms = "sign_event:22242,nip04_encrypt,nip04_decrypt,nip44_encrypt,nip44_decrypt";
|
|
21
31
|
exports.getSigner = (0, lib_1.memoize)((session) => {
|
|
22
32
|
switch (session === null || session === void 0 ? void 0 : session.method) {
|
|
@@ -31,21 +41,20 @@ exports.getSigner = (0, lib_1.memoize)((session) => {
|
|
|
31
41
|
}
|
|
32
42
|
});
|
|
33
43
|
exports.signer = (0, store_2.withGetter)((0, store_1.derived)(exports.session, exports.getSigner));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
44
|
+
exports.authChallenges = new Set();
|
|
45
|
+
const onAuth = async (url, challenge) => {
|
|
46
|
+
if (exports.authChallenges.has(challenge) || !exports.signer.get()) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
exports.authChallenges.add(challenge);
|
|
50
|
+
const event = await exports.signer.get().sign((0, util_1.createEvent)(22242, {
|
|
51
|
+
tags: [
|
|
52
|
+
["relay", url],
|
|
53
|
+
["challenge", challenge],
|
|
54
|
+
],
|
|
55
|
+
}));
|
|
56
|
+
net_1.NetworkContext.pool.get(url).send(["AUTH", event]);
|
|
57
|
+
return event;
|
|
58
|
+
};
|
|
59
|
+
exports.onAuth = onAuth;
|
|
51
60
|
//# sourceMappingURL=session.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.cjs","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":";;;AAAA,wCAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"session.cjs","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":";;;AAAA,wCAAoC;AACpC,uCAA0D;AAC1D,yCAA0C;AAC1C,2CAAkD;AAElD,uCAA4C;AAC5C,6CAAmF;AAUtE,QAAA,MAAM,GAAG,IAAA,kBAAU,EAAC,IAAA,cAAM,EAAgB,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;AAE1D,QAAA,QAAQ,GAAG,IAAA,kBAAU,EAAC,IAAA,cAAM,EAA0B,UAAU,EAAE,EAAE,CAAC,CAAC,CAAA;AAEtE,QAAA,OAAO,GAAG,IAAA,kBAAU,EAC/B,IAAA,eAAO,EAAC,CAAC,cAAM,EAAE,gBAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAC7F,CAAA;AAEM,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,gBAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAA;AAAvD,QAAA,UAAU,cAA6C;AAE7D,MAAM,UAAU,GAAG,CAAC,OAAgB,EAAE,EAAE;IAC7C,gBAAQ,CAAC,MAAM,CAAC,IAAA,WAAK,EAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAC/C,cAAM,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,CAAC,C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