@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,77 @@
|
|
|
1
|
+
import { writable, derived } from 'svelte/store';
|
|
2
|
+
import { withGetter } from '@welshman/store';
|
|
3
|
+
import { ctx, tryCatch, fetchJson, uniq, batcher, postJson, last } from '@welshman/lib';
|
|
4
|
+
import { collection } from "./collection.mjs";
|
|
5
|
+
import { deriveProfile } from "./profiles.mjs";
|
|
6
|
+
export const NIP05_REGEX = /^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$/;
|
|
7
|
+
export async function queryProfile(nip05) {
|
|
8
|
+
const match = nip05.match(NIP05_REGEX);
|
|
9
|
+
if (!match)
|
|
10
|
+
return undefined;
|
|
11
|
+
const [_, name = '_', domain] = match;
|
|
12
|
+
try {
|
|
13
|
+
const { names, relays = {}, nip46 = {} } = await fetchJson(`https://${domain}/.well-known/nostr.json?name=${name}`);
|
|
14
|
+
const pubkey = names[name];
|
|
15
|
+
if (!pubkey) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
nip05,
|
|
20
|
+
pubkey,
|
|
21
|
+
nip46: nip46[pubkey],
|
|
22
|
+
relays: relays[pubkey],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch (_e) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const handles = withGetter(writable([]));
|
|
30
|
+
export const fetchHandles = async (nip05s) => {
|
|
31
|
+
const base = ctx.app.dufflepudUrl;
|
|
32
|
+
const handlesByNip05 = new Map();
|
|
33
|
+
// Use dufflepud if we it's set up to protect user privacy, otherwise fetch directly
|
|
34
|
+
if (base) {
|
|
35
|
+
const res = await tryCatch(async () => await postJson(`${base}/handle/info`, { handles: nip05s }));
|
|
36
|
+
for (const { handle: nip05, info } of (res === null || res === void 0 ? void 0 : res.data) || []) {
|
|
37
|
+
handlesByNip05.set(nip05, info);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const results = await Promise.all(nip05s.map(async (nip05) => ({ nip05, info: await tryCatch(async () => await queryProfile(nip05)) })));
|
|
42
|
+
for (const { nip05, info } of results) {
|
|
43
|
+
if (info) {
|
|
44
|
+
handlesByNip05.set(nip05, info);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return handlesByNip05;
|
|
49
|
+
};
|
|
50
|
+
export const { indexStore: handlesByNip05, deriveItem: deriveHandle, loadItem: loadHandle, } = collection({
|
|
51
|
+
name: "handles",
|
|
52
|
+
store: handles,
|
|
53
|
+
getKey: (handle) => handle.nip05,
|
|
54
|
+
load: batcher(800, async (nip05s) => {
|
|
55
|
+
const fresh = await fetchHandles(uniq(nip05s));
|
|
56
|
+
const stale = handlesByNip05.get();
|
|
57
|
+
const items = nip05s.map(nip05 => {
|
|
58
|
+
const newHandle = fresh.get(nip05);
|
|
59
|
+
const oldHandle = stale.get(nip05);
|
|
60
|
+
if (newHandle) {
|
|
61
|
+
stale.set(nip05, { ...newHandle, nip05 });
|
|
62
|
+
}
|
|
63
|
+
return { ...oldHandle, ...newHandle, nip05 };
|
|
64
|
+
});
|
|
65
|
+
handles.set(Array.from(stale.values()));
|
|
66
|
+
return items;
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
export const deriveHandleForPubkey = (pubkey, request = {}) => derived([handlesByNip05, deriveProfile(pubkey, request)], ([$handlesByNip05, $profile]) => {
|
|
70
|
+
if (!($profile === null || $profile === void 0 ? void 0 : $profile.nip05)) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
loadHandle($profile.nip05);
|
|
74
|
+
return $handlesByNip05.get($profile.nip05);
|
|
75
|
+
});
|
|
76
|
+
export const displayHandle = (handle) => handle.nip05.startsWith("_@") ? last(handle.nip05.split("@")) : handle.nip05;
|
|
77
|
+
//# sourceMappingURL=handles.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handles.mjs","sourceRoot":"","sources":["../../src/handles.ts"],"names":[],"mappings":"OAAO,EAAC,QAAQ,EAAE,OAAO,EAAC,MAAM,cAAc;OACvC,EAAC,UAAU,EAAC,MAAM,iBAAiB;OAEnC,EAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAC,MAAM,eAAe;OAC9E,EAAC,UAAU,EAAC;OACZ,EAAC,aAAa,EAAC;AAStB,MAAM,CAAC,MAAM,WAAW,GAAG,yCAAyC,CAAA;AAEpE,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,KAAa;IAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IAEtC,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IAE5B,MAAM,CAAC,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,MAAM,CAAC,GAAG,KAAK,CAAA;IAErC,IAAI;QACF,MAAM,EAAC,KAAK,EAAE,MAAM,GAAG,EAAE,EAAE,KAAK,GAAG,EAAE,EAAC,GAAG,MAAM,SAAS,CAAC,WAAW,MAAM,gCAAgC,IAAI,EAAE,CAAC,CAAA;QAEjH,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;QAE1B,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,SAAS,CAAA;SACjB;QAED,OAAO;YACL,KAAK;YACL,MAAM;YACN,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC;YACpB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;SACvB,CAAA;KACF;IAAC,OAAO,EAAE,EAAE;QACX,OAAO,SAAS,CAAA;KACjB;AACH,CAAC;AAED,MAAM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B;IAED,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC5C,CAAC,CACF,CAAA;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE,CAC9C,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAA"}
|
package/build/src/index.cjs
CHANGED
|
@@ -14,7 +14,22 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./context.cjs"), exports);
|
|
18
|
+
__exportStar(require("./core.cjs"), exports);
|
|
19
|
+
__exportStar(require("./collection.cjs"), exports);
|
|
20
|
+
__exportStar(require("./freshness.cjs"), exports);
|
|
21
|
+
__exportStar(require("./follows.cjs"), exports);
|
|
22
|
+
__exportStar(require("./handles.cjs"), exports);
|
|
23
|
+
__exportStar(require("./mutes.cjs"), exports);
|
|
24
|
+
__exportStar(require("./plaintext.cjs"), exports);
|
|
25
|
+
__exportStar(require("./profiles.cjs"), exports);
|
|
26
|
+
__exportStar(require("./relays.cjs"), exports);
|
|
27
|
+
__exportStar(require("./relaySelections.cjs"), exports);
|
|
28
|
+
__exportStar(require("./router.cjs"), exports);
|
|
19
29
|
__exportStar(require("./session.cjs"), exports);
|
|
30
|
+
__exportStar(require("./storage.cjs"), exports);
|
|
31
|
+
__exportStar(require("./thunk.cjs"), exports);
|
|
32
|
+
__exportStar(require("./topics.cjs"), exports);
|
|
33
|
+
__exportStar(require("./util.cjs"), exports);
|
|
34
|
+
__exportStar(require("./zappers.cjs"), exports);
|
|
20
35
|
//# sourceMappingURL=index.cjs.map
|
package/build/src/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAuB;AACvB,8CAAuB;AACvB,gDAAyB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAAyB;AACzB,6CAAsB;AACtB,mDAA4B;AAC5B,kDAA2B;AAC3B,gDAAyB;AACzB,gDAAyB;AACzB,8CAAuB;AACvB,kDAA2B;AAC3B,iDAA0B;AAC1B,+CAAwB;AACxB,wDAAiC;AACjC,+CAAwB;AACxB,gDAAyB;AACzB,gDAAyB;AACzB,8CAAuB;AACvB,+CAAwB;AACxB,6CAAsB;AACtB,gDAAyB"}
|
package/build/src/index.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './core';
|
|
3
|
+
export * from './collection';
|
|
4
|
+
export * from './freshness';
|
|
5
|
+
export * from './follows';
|
|
6
|
+
export * from './handles';
|
|
7
|
+
export * from './mutes';
|
|
8
|
+
export * from './plaintext';
|
|
9
|
+
export * from './profiles';
|
|
10
|
+
export * from './relays';
|
|
11
|
+
export * from './relaySelections';
|
|
12
|
+
export * from './router';
|
|
3
13
|
export * from './session';
|
|
14
|
+
export * from './storage';
|
|
15
|
+
export * from './thunk';
|
|
16
|
+
export * from './topics';
|
|
17
|
+
export * from './util';
|
|
18
|
+
export * from './zappers';
|
package/build/src/index.mjs
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./context.mjs";
|
|
2
|
+
export * from "./core.mjs";
|
|
3
|
+
export * from "./collection.mjs";
|
|
4
|
+
export * from "./freshness.mjs";
|
|
5
|
+
export * from "./follows.mjs";
|
|
6
|
+
export * from "./handles.mjs";
|
|
7
|
+
export * from "./mutes.mjs";
|
|
8
|
+
export * from "./plaintext.mjs";
|
|
9
|
+
export * from "./profiles.mjs";
|
|
10
|
+
export * from "./relays.mjs";
|
|
11
|
+
export * from "./relaySelections.mjs";
|
|
12
|
+
export * from "./router.mjs";
|
|
3
13
|
export * from "./session.mjs";
|
|
14
|
+
export * from "./storage.mjs";
|
|
15
|
+
export * from "./thunk.mjs";
|
|
16
|
+
export * from "./topics.mjs";
|
|
17
|
+
export * from "./util.mjs";
|
|
18
|
+
export * from "./zappers.mjs";
|
|
4
19
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.loadMutes = exports.deriveMutes = exports.mutesByPubkey = exports.mutes = 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.mutes = (0, store_1.withGetter)((0, store_1.deriveEventsMapped)(core_1.repository, {
|
|
12
|
+
filters: [{ kinds: [util_1.MUTES] }],
|
|
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: "mutes",
|
|
20
|
+
store: exports.mutes,
|
|
21
|
+
getKey: mute => mute.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.MUTES], authors: [pubkey] }] });
|
|
25
|
+
},
|
|
26
|
+
}), exports.mutesByPubkey = _a.indexStore, exports.deriveMutes = _a.deriveItem, exports.loadMutes = _a.loadItem;
|
|
27
|
+
//# sourceMappingURL=mutes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutes.cjs","sourceRoot":"","sources":["../../src/mutes.ts"],"names":[],"mappings":";;;;AAAA,yCAAgE;AAGhE,2CAA8D;AAC9D,qCAAuC;AACvC,iDAAuC;AACvC,+CAA2C;AAC3C,2DAAqD;AAExC,QAAA,KAAK,GAAG,IAAA,kBAAU,EAC7B,IAAA,0BAAkB,EAAgB,iBAAU,EAAE;IAC5C,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,YAAK,CAAC,EAAC,CAAC;IAC3B,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,OAAO;IACb,KAAK,EAAE,aAAK;IACZ,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM;IACjC,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,YAAK,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,EAAC,CAAC,CAAA;IAC1E,CAAC;CACF,CAAC,EAXY,qBAAa,kBACb,mBAAW,kBACb,iBAAS,eASnB"}
|
|
@@ -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 mutes: import("svelte/store").Readable<PublishedList[]> & {
|
|
5
|
+
get: () => PublishedList[];
|
|
6
|
+
};
|
|
7
|
+
export declare const mutesByPubkey: import("svelte/store").Readable<Map<string, PublishedList>> & {
|
|
8
|
+
get: () => Map<string, PublishedList>;
|
|
9
|
+
}, deriveMutes: (key: import("@welshman/lib").Maybe<string>, request?: Partial<SubscribeRequest> | undefined) => import("svelte/store").Readable<PublishedList | undefined>, loadMutes: (key: string, request?: Partial<SubscribeRequest> | undefined) => Promise<PublishedList | undefined>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MUTES, 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 mutes = withGetter(deriveEventsMapped(repository, {
|
|
8
|
+
filters: [{ kinds: [MUTES] }],
|
|
9
|
+
itemToEvent: item => item.event,
|
|
10
|
+
eventToItem: async (event) => readList(asDecryptedEvent(event, {
|
|
11
|
+
content: await ensurePlaintext(event),
|
|
12
|
+
})),
|
|
13
|
+
}));
|
|
14
|
+
export const { indexStore: mutesByPubkey, deriveItem: deriveMutes, loadItem: loadMutes, } = collection({
|
|
15
|
+
name: "mutes",
|
|
16
|
+
store: mutes,
|
|
17
|
+
getKey: mute => mute.event.pubkey,
|
|
18
|
+
load: async (pubkey, request = {}) => {
|
|
19
|
+
await loadRelaySelections(pubkey, request);
|
|
20
|
+
await load({ ...request, filters: [{ kinds: [MUTES], authors: [pubkey] }] });
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=mutes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutes.mjs","sourceRoot":"","sources":["../../src/mutes.ts"],"names":[],"mappings":"OAAO,EAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAC,MAAM,gBAAgB;OAGzD,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,KAAK,GAAG,UAAU,CAC7B,kBAAkB,CAAgB,UAAU,EAAE;IAC5C,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,KAAK,CAAC,EAAC,CAAC;IAC3B,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,aAAa,EACzB,UAAU,EAAE,WAAW,EACvB,QAAQ,EAAE,SAAS,GACpB,GAAG,UAAU,CAAC;IACb,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM;IACjC,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,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,EAAC,CAAC,CAAA;IAC1E,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -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.withGetter)((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, request = {}) => {
|
|
22
|
+
await (0, relaySelections_1.loadRelaySelections)(pubkey, request);
|
|
23
|
+
await (0, core_1.load)({ ...request, filters: [{ kinds: [util_1.PROFILE], authors: [pubkey] }] });
|
|
24
|
+
},
|
|
25
|
+
}), exports.profilesByPubkey = _a.indexStore, exports.deriveProfile = _a.deriveItem, exports.loadProfile = _a.loadItem;
|
|
26
|
+
exports.profileSearch = (0, store_1.derived)(exports.profiles, $profiles => (0, util_2.createSearch)($profiles, {
|
|
27
|
+
getValue: (profile) => profile.event.pubkey,
|
|
28
|
+
fuseOptions: {
|
|
29
|
+
keys: ["name", "display_name", { name: "about", weight: 0.3 }],
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
const displayProfileByPubkey = (pubkey) => pubkey
|
|
33
|
+
? (0, util_1.displayProfile)(exports.profilesByPubkey.get().get(pubkey), (0, util_1.displayPubkey)(pubkey))
|
|
34
|
+
: "";
|
|
35
|
+
exports.displayProfileByPubkey = displayProfileByPubkey;
|
|
36
|
+
const deriveProfileDisplay = (pubkey) => pubkey
|
|
37
|
+
? (0, store_1.derived)((0, exports.deriveProfile)(pubkey), $profile => (0, util_1.displayProfile)($profile, (0, util_1.displayPubkey)(pubkey)))
|
|
38
|
+
: (0, store_1.readable)("");
|
|
39
|
+
exports.deriveProfileDisplay = deriveProfileDisplay;
|
|
40
|
+
//# sourceMappingURL=profiles.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.cjs","sourceRoot":"","sources":["../../src/profiles.ts"],"names":[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D;CACF,CAAC,CACH,CAAA;AAEM,MAAM,sBAAsB,GAAG,CAAC,MAA0B,EAAE,EAAE,CACnE,MAAM;IACJ,CAAC,CAAC,IAAA,qBAAc,EAAC,wBAAgB,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAA,oBAAa,EAAC,MAAM,CAAC,CAAC;IAC3E,CAAC,CAAC,EAAE,CAAA;AAHK,QAAA,sBAAsB,0BAG3B;AAED,MAAM,oBAAoB,GAAG,CAAC,MAA0B,EAAE,EAAE,CACjE,MAAM;IACJ,CAAC,CAAC,IAAA,eAAO,EAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAA,qBAAc,EAAC,QAAQ,EAAE,IAAA,oBAAa,EAAC,MAAM,CAAC,CAAC,CAAC;IAC7F,CAAC,CAAC,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAA;AAHL,QAAA,oBAAoB,wBAGf"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import { type SubscribeRequest } from "@welshman/net";
|
|
3
|
+
import { type PublishedProfile } from "@welshman/util";
|
|
4
|
+
export declare const profiles: import("svelte/store").Readable<PublishedProfile[]> & {
|
|
5
|
+
get: () => PublishedProfile[];
|
|
6
|
+
};
|
|
7
|
+
export declare const profilesByPubkey: import("svelte/store").Readable<Map<string, PublishedProfile>> & {
|
|
8
|
+
get: () => Map<string, PublishedProfile>;
|
|
9
|
+
}, deriveProfile: (key: import("@welshman/lib").Maybe<string>, request?: Partial<SubscribeRequest> | undefined) => import("svelte/store").Readable<PublishedProfile | undefined>, loadProfile: (key: string, request?: Partial<SubscribeRequest> | undefined) => Promise<PublishedProfile | undefined>;
|
|
10
|
+
export declare const profileSearch: import("svelte/store").Readable<import("./util").Search<string, PublishedProfile>>;
|
|
11
|
+
export declare const displayProfileByPubkey: (pubkey: string | undefined) => string;
|
|
12
|
+
export declare const deriveProfileDisplay: (pubkey: string | undefined) => import("svelte/store").Readable<string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { derived, readable } from 'svelte/store';
|
|
2
|
+
import { readProfile, displayProfile, displayPubkey, PROFILE } from '@welshman/util';
|
|
3
|
+
import { deriveEventsMapped, withGetter } from '@welshman/store';
|
|
4
|
+
import { repository, load } from "./core.mjs";
|
|
5
|
+
import { createSearch } from "./util.mjs";
|
|
6
|
+
import { collection } from "./collection.mjs";
|
|
7
|
+
import { loadRelaySelections } from "./relaySelections.mjs";
|
|
8
|
+
export const profiles = withGetter(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, request = {}) => {
|
|
18
|
+
await loadRelaySelections(pubkey, request);
|
|
19
|
+
await load({ ...request, filters: [{ kinds: [PROFILE], authors: [pubkey] }] });
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
export const profileSearch = derived(profiles, $profiles => createSearch($profiles, {
|
|
23
|
+
getValue: (profile) => profile.event.pubkey,
|
|
24
|
+
fuseOptions: {
|
|
25
|
+
keys: ["name", "display_name", { name: "about", weight: 0.3 }],
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
export const displayProfileByPubkey = (pubkey) => pubkey
|
|
29
|
+
? displayProfile(profilesByPubkey.get().get(pubkey), displayPubkey(pubkey))
|
|
30
|
+
: "";
|
|
31
|
+
export const deriveProfileDisplay = (pubkey) => pubkey
|
|
32
|
+
? derived(deriveProfile(pubkey), $profile => displayProfile($profile, displayPubkey(pubkey)))
|
|
33
|
+
: readable("");
|
|
34
|
+
//#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AAA;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CACzD,YAAY,CAAC,SAAS,EAAE;IACtB,QAAQ,EAAE,CAAC,OAAyB,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM;IAC7D,WAAW,EAAE;QACX,IAAI,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,EAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAC,CAAC;KAC7D;CACF,CAAC,CACH,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,MAA0B,EAAE,EAAE,CACnE,MAAM;IACJ,CAAC,CAAC,cAAc,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3E,CAAC,CAAC,EAAE,CAAA;AAER,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAA0B,EAAE,EAAE,CACjE,MAAM;IACJ,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7F,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.loadInboxRelaySelections = exports.deriveInboxRelaySelections = exports.inboxRelaySelectionsByPubkey = exports.inboxRelaySelections = exports.loadRelaySelections = exports.deriveRelaySelections = exports.relaySelectionsByPubkey = exports.relaySelections = exports.getWriteRelayUrls = exports.getReadRelayUrls = exports.getRelayUrls = 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 getRelayUrls = (event) => (0, util_1.getRelayTags)((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
10
|
+
.map((t) => (0, util_1.normalizeRelayUrl)(t[1]));
|
|
11
|
+
exports.getRelayUrls = getRelayUrls;
|
|
12
|
+
const getReadRelayUrls = (event) => (0, util_1.getRelayTags)((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
13
|
+
.filter((t) => !t[2] || t[2] === "read")
|
|
14
|
+
.map((t) => (0, util_1.normalizeRelayUrl)(t[1]));
|
|
15
|
+
exports.getReadRelayUrls = getReadRelayUrls;
|
|
16
|
+
const getWriteRelayUrls = (event) => (0, util_1.getRelayTags)((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
17
|
+
.filter((t) => !t[2] || t[2] === "write")
|
|
18
|
+
.map((t) => (0, util_1.normalizeRelayUrl)(t[1]));
|
|
19
|
+
exports.getWriteRelayUrls = getWriteRelayUrls;
|
|
20
|
+
exports.relaySelections = (0, store_1.withGetter)((0, store_1.deriveEvents)(core_1.repository, { filters: [{ kinds: [util_1.RELAYS] }] }));
|
|
21
|
+
_a = (0, collection_1.collection)({
|
|
22
|
+
name: "relaySelections",
|
|
23
|
+
store: exports.relaySelections,
|
|
24
|
+
getKey: relaySelections => relaySelections.pubkey,
|
|
25
|
+
load: (pubkey, request = {}) => (0, core_1.load)({ ...request, filters: [{ kinds: [util_1.RELAYS], authors: [pubkey] }] }),
|
|
26
|
+
}), exports.relaySelectionsByPubkey = _a.indexStore, exports.deriveRelaySelections = _a.deriveItem, exports.loadRelaySelections = _a.loadItem;
|
|
27
|
+
exports.inboxRelaySelections = (0, store_1.withGetter)((0, store_1.deriveEvents)(core_1.repository, { filters: [{ kinds: [util_1.RELAYS] }] }));
|
|
28
|
+
_b = (0, collection_1.collection)({
|
|
29
|
+
name: "inboxRelaySelections",
|
|
30
|
+
store: exports.inboxRelaySelections,
|
|
31
|
+
getKey: inboxRelaySelections => inboxRelaySelections.pubkey,
|
|
32
|
+
load: (pubkey, request = {}) => (0, core_1.load)({ ...request, filters: [{ kinds: [util_1.INBOX_RELAYS], authors: [pubkey] }] }),
|
|
33
|
+
}), exports.inboxRelaySelectionsByPubkey = _b.indexStore, exports.deriveInboxRelaySelections = _b.deriveItem, exports.loadInboxRelaySelections = _b.loadItem;
|
|
34
|
+
//# sourceMappingURL=relaySelections.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relaySelections.cjs","sourceRoot":"","sources":["../../src/relaySelections.ts"],"names":[],"mappings":";;;;AAAA,yCAAuG;AAEvG,2CAAwD;AACxD,qCAAuC;AACvC,iDAAuC;AAEhC,MAAM,YAAY,GAAG,CAAC,KAAoB,EAAY,EAAE,CAC7D,IAAA,mBAAY,EAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,KAAI,EAAE,CAAC;KAC5B,GAAG,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,IAAA,wBAAiB,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAFrC,QAAA,YAAY,gBAEyB;AAE3C,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,EA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AC,EAAE,CAAC,oBAAoB,CAAC,MAAM;IAC3D,IAAI,EAAE,CAAC,MAAc,EAAE,UAAqC,EAAE,EAAE,EAAE,CAChE,IAAA,WAAI,EAAC,EAAC,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,mBAAY,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,EAAC,CAAC;CAC5E,CAAC,EATY,oCAA4B,kBAC5B,kCAA0B,kBAC5B,gCAAwB,eAOlC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import { type TrustedEvent } from '@welshman/util';
|
|
3
|
+
import { type SubscribeRequest } from "@welshman/net";
|
|
4
|
+
export declare const getRelayUrls: (event?: TrustedEvent) => string[];
|
|
5
|
+
export declare const getReadRelayUrls: (event?: TrustedEvent) => string[];
|
|
6
|
+
export declare const getWriteRelayUrls: (event?: TrustedEvent) => string[];
|
|
7
|
+
export declare const relaySelections: import("svelte/store").Readable<TrustedEvent[]> & {
|
|
8
|
+
get: () => TrustedEvent[];
|
|
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>, request?: Partial<SubscribeRequest> | undefined) => import("svelte/store").Readable<TrustedEvent | undefined>, loadRelaySelections: (key: string, request?: Partial<SubscribeRequest> | undefined) => Promise<TrustedEvent | undefined>;
|
|
13
|
+
export declare const inboxRelaySelections: import("svelte/store").Readable<TrustedEvent[]> & {
|
|
14
|
+
get: () => TrustedEvent[];
|
|
15
|
+
};
|
|
16
|
+
export declare const inboxRelaySelectionsByPubkey: import("svelte/store").Readable<Map<string, TrustedEvent>> & {
|
|
17
|
+
get: () => Map<string, TrustedEvent>;
|
|
18
|
+
}, deriveInboxRelaySelections: (key: import("@welshman/lib").Maybe<string>, request?: Partial<SubscribeRequest> | undefined) => import("svelte/store").Readable<TrustedEvent | undefined>, loadInboxRelaySelections: (key: string, request?: Partial<SubscribeRequest> | undefined) => Promise<TrustedEvent | undefined>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { INBOX_RELAYS, RELAYS, getRelayTags, normalizeRelayUrl } from '@welshman/util';
|
|
2
|
+
import { deriveEvents, withGetter } from '@welshman/store';
|
|
3
|
+
import { load, repository } from "./core.mjs";
|
|
4
|
+
import { collection } from "./collection.mjs";
|
|
5
|
+
export const getRelayUrls = (event) => getRelayTags((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
6
|
+
.map((t) => normalizeRelayUrl(t[1]));
|
|
7
|
+
export const getReadRelayUrls = (event) => getRelayTags((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
8
|
+
.filter((t) => !t[2] || t[2] === "read")
|
|
9
|
+
.map((t) => normalizeRelayUrl(t[1]));
|
|
10
|
+
export const getWriteRelayUrls = (event) => getRelayTags((event === null || event === void 0 ? void 0 : event.tags) || [])
|
|
11
|
+
.filter((t) => !t[2] || t[2] === "write")
|
|
12
|
+
.map((t) => normalizeRelayUrl(t[1]));
|
|
13
|
+
export const relaySelections = withGetter(deriveEvents(repository, { filters: [{ kinds: [RELAYS] }] }));
|
|
14
|
+
export const { indexStore: relaySelectionsByPubkey, deriveItem: deriveRelaySelections, loadItem: loadRelaySelections, } = collection({
|
|
15
|
+
name: "relaySelections",
|
|
16
|
+
store: relaySelections,
|
|
17
|
+
getKey: relaySelections => relaySelections.pubkey,
|
|
18
|
+
load: (pubkey, request = {}) => load({ ...request, filters: [{ kinds: [RELAYS], authors: [pubkey] }] }),
|
|
19
|
+
});
|
|
20
|
+
export const inboxRelaySelections = withGetter(deriveEvents(repository, { filters: [{ kinds: [RELAYS] }] }));
|
|
21
|
+
export const { indexStore: inboxRelaySelectionsByPubkey, deriveItem: deriveInboxRelaySelections, loadItem: loadInboxRelaySelections, } = collection({
|
|
22
|
+
name: "inboxRelaySelections",
|
|
23
|
+
store: inboxRelaySelections,
|
|
24
|
+
getKey: inboxRelaySelections => inboxRelaySelections.pubkey,
|
|
25
|
+
load: (pubkey, request = {}) => load({ ...request, filters: [{ kinds: [INBOX_RELAYS], authors: [pubkey] }] }),
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=relaySelections.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relaySelections.mjs","sourceRoot":"","sources":["../../src/relaySelections.ts"],"names":[],"mappings":"OAAO,EAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,EAAoB,MAAM,gBAAgB;OAEhG,EAAC,YAAY,EAAE,UAAU,EAAC,MAAM,iBAAiB;OACjD,EAAC,IAAI,EAAE,UAAU,EAAC;OAClB,EAAC,UAAU,EAAC;AAEnB,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAoB,EAAY,EAAE,CAC7D,YAAY,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,KAAI,EAAE,CAAC;KAC5B,GAAG,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAoB,EAAY,EAAE,CACjE,YAAY,CAAC,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,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAElD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAoB,EAAY,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,wBAAwB,GACnC,GAAG,UAAU,CAAC;IACb,IAAI,EAAE,sBAAsB;IAC5B,KAAK,EAAE,oBAAoB;IAC3B,MAAM,EAAE,oBAAoB,CAAC,EAAE,CAAC,oBAAoB,CAAC,MAAM;IAC3D,IAAI,EAAE,CAAC,MAAc,EAAE,UAAqC,EAAE,EAAE,EAAE,CAChE,IAAI,CAAC,EAAC,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,EAAC,KAAK,EAAE,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAC,CAAC,EAAC,CAAC;CAC5E,CAAC,CAAA"}
|
|
@@ -0,0 +1,116 @@
|
|
|
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 util_1 = require("./util.cjs");
|
|
10
|
+
const collection_1 = require("./collection.cjs");
|
|
11
|
+
// Relays
|
|
12
|
+
const makeRelayStats = () => ({
|
|
13
|
+
first_seen: (0, lib_1.now)(),
|
|
14
|
+
event_count: 0,
|
|
15
|
+
request_count: 0,
|
|
16
|
+
publish_count: 0,
|
|
17
|
+
connect_count: 0,
|
|
18
|
+
recent_errors: [],
|
|
19
|
+
last_auth_status: net_1.AuthStatus.Pending,
|
|
20
|
+
});
|
|
21
|
+
exports.makeRelayStats = makeRelayStats;
|
|
22
|
+
exports.relays = (0, store_2.withGetter)((0, store_1.writable)([]));
|
|
23
|
+
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; })));
|
|
24
|
+
const fetchRelayProfiles = (urls) => {
|
|
25
|
+
const base = lib_1.ctx.app.dufflepudUrl;
|
|
26
|
+
if (!base) {
|
|
27
|
+
throw new Error("ctx.app.dufflepudUrl is required to fetch relay metadata");
|
|
28
|
+
}
|
|
29
|
+
const res = (0, lib_1.postJson)(`${base}/relay/info`, { urls });
|
|
30
|
+
const profilesByUrl = new Map();
|
|
31
|
+
for (const { url, info } of (res === null || res === void 0 ? void 0 : res.data) || []) {
|
|
32
|
+
profilesByUrl.set(url, info);
|
|
33
|
+
}
|
|
34
|
+
return profilesByUrl;
|
|
35
|
+
};
|
|
36
|
+
exports.fetchRelayProfiles = fetchRelayProfiles;
|
|
37
|
+
_a = (0, collection_1.collection)({
|
|
38
|
+
name: "relays",
|
|
39
|
+
store: exports.relays,
|
|
40
|
+
getKey: (relay) => relay.url,
|
|
41
|
+
load: (0, lib_1.batcher)(800, async (urls) => {
|
|
42
|
+
const profilesByUrl = await (0, exports.fetchRelayProfiles)((0, lib_1.uniq)(urls));
|
|
43
|
+
const index = exports.relaysByUrl.get();
|
|
44
|
+
const items = urls.map(url => {
|
|
45
|
+
const relay = index.get(url);
|
|
46
|
+
const profile = profilesByUrl.get(url) || (relay === null || relay === void 0 ? void 0 : relay.profile);
|
|
47
|
+
return { ...relay, profile, url };
|
|
48
|
+
});
|
|
49
|
+
exports.relays.update($relays => (0, lib_1.uniqBy)($relay => $relay.url, [...$relays, ...items]));
|
|
50
|
+
return items;
|
|
51
|
+
}),
|
|
52
|
+
}), exports.relaysByUrl = _a.indexStore, exports.deriveRelay = _a.deriveItem, exports.loadRelay = _a.loadItem;
|
|
53
|
+
exports.relaySearch = (0, store_1.derived)(exports.relays, $relays => (0, util_1.createSearch)($relays, {
|
|
54
|
+
getValue: (relay) => relay.url,
|
|
55
|
+
fuseOptions: {
|
|
56
|
+
keys: ["url", "name", { name: "description", weight: 0.3 }],
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
const updateRelayStats = (0, lib_1.batch)(500, (updates) => {
|
|
60
|
+
exports.relays.update($relays => {
|
|
61
|
+
const $relaysByUrl = (0, lib_1.indexBy)(r => r.url, $relays);
|
|
62
|
+
const $itemsByUrl = (0, lib_1.groupBy)(([url]) => url, updates);
|
|
63
|
+
for (const [url, items] of $itemsByUrl.entries()) {
|
|
64
|
+
const $relay = $relaysByUrl.get(url) || { url };
|
|
65
|
+
if (!$relay.stats) {
|
|
66
|
+
$relay.stats = (0, exports.makeRelayStats)();
|
|
67
|
+
}
|
|
68
|
+
for (const [_, update] of items) {
|
|
69
|
+
update($relay.stats);
|
|
70
|
+
}
|
|
71
|
+
$relaysByUrl.set(url, $relay);
|
|
72
|
+
}
|
|
73
|
+
return Array.from($relaysByUrl.values());
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
const onConnectionSend = ({ url }, socketMessage) => {
|
|
77
|
+
const [verb] = (0, net_1.asMessage)(socketMessage);
|
|
78
|
+
if (verb === 'REQ') {
|
|
79
|
+
updateRelayStats([url, stats => ++stats.request_count]);
|
|
80
|
+
}
|
|
81
|
+
else if (verb === 'EVENT') {
|
|
82
|
+
updateRelayStats([url, stats => ++stats.publish_count]);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const onConnectionReceive = ({ url }, socketMessage) => {
|
|
86
|
+
const [verb] = (0, net_1.asMessage)(socketMessage);
|
|
87
|
+
if (verb === 'EVENT') {
|
|
88
|
+
updateRelayStats([url, stats => ++stats.event_count]);
|
|
89
|
+
}
|
|
90
|
+
else if (verb === 'OK') {
|
|
91
|
+
updateRelayStats([url, stats => {
|
|
92
|
+
stats.last_auth_status = net_1.AuthStatus.Ok;
|
|
93
|
+
}]);
|
|
94
|
+
}
|
|
95
|
+
else if (verb === 'AUTH') {
|
|
96
|
+
updateRelayStats([url, stats => {
|
|
97
|
+
stats.last_auth_status = net_1.AuthStatus.Unauthorized;
|
|
98
|
+
}]);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const onConnectionFault = ({ url }) => updateRelayStats([url, stats => {
|
|
102
|
+
stats.recent_errors = stats.recent_errors.concat((0, lib_1.now)()).slice(-10);
|
|
103
|
+
}]);
|
|
104
|
+
const trackRelayStats = (connection) => {
|
|
105
|
+
updateRelayStats([connection.url, stats => ++stats.connect_count]);
|
|
106
|
+
connection.on('send', onConnectionSend);
|
|
107
|
+
connection.on('receive', onConnectionReceive);
|
|
108
|
+
connection.on('fault', onConnectionFault);
|
|
109
|
+
return () => {
|
|
110
|
+
connection.off('send', onConnectionSend);
|
|
111
|
+
connection.off('receive', onConnectionReceive);
|
|
112
|
+
connection.off('fault', onConnectionFault);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
exports.trackRelayStats = trackRelayStats;
|
|
116
|
+
//# sourceMappingURL=relays.cjs.map
|