@welshman/router 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +220 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jon Staab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { TrustedEvent, Filter, RelayMode } from "@welshman/util";
|
|
2
|
+
export declare const INDEXED_KINDS: number[];
|
|
3
|
+
export type RelaysAndFilters = {
|
|
4
|
+
relays: string[];
|
|
5
|
+
filters: Filter[];
|
|
6
|
+
};
|
|
7
|
+
export type RouterOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the user's public key.
|
|
10
|
+
* @returns The user's public key as a string, or null if not available.
|
|
11
|
+
*/
|
|
12
|
+
getUserPubkey?: () => string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves relays for the specified public key and mode.
|
|
15
|
+
* @param pubkey - The public key to retrieve relays for.
|
|
16
|
+
* @param mode - The relay mode (optional). May be "read", "write", or "inbox".
|
|
17
|
+
* @returns An array of relay URLs as strings.
|
|
18
|
+
*/
|
|
19
|
+
getPubkeyRelays?: (pubkey: string, mode?: RelayMode) => string[];
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves default relays, for use as fallbacks when no other relays can be selected.
|
|
22
|
+
* @returns An array of relay URLs as strings.
|
|
23
|
+
*/
|
|
24
|
+
getDefaultRelays?: () => string[];
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves relays that index profiles and relay selections.
|
|
27
|
+
* @returns An array of relay URLs as strings.
|
|
28
|
+
*/
|
|
29
|
+
getIndexerRelays?: () => string[];
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves relays likely to support NIP-50 search.
|
|
32
|
+
* @returns An array of relay URLs as strings.
|
|
33
|
+
*/
|
|
34
|
+
getSearchRelays?: () => string[];
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves the quality of the specified relay.
|
|
37
|
+
* @param url - The URL of the relay to retrieve quality for.
|
|
38
|
+
* @returns The quality of the relay as a number between 0 and 1 inclusive.
|
|
39
|
+
*/
|
|
40
|
+
getRelayQuality?: (url: string) => number;
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves the limit setting, which is the maximum number of relays that should be
|
|
43
|
+
* returned from getUrls and getSelections.
|
|
44
|
+
* @returns The limit setting as a number.
|
|
45
|
+
*/
|
|
46
|
+
getLimit?: () => number;
|
|
47
|
+
};
|
|
48
|
+
export type Selection = {
|
|
49
|
+
weight: number;
|
|
50
|
+
relays: string[];
|
|
51
|
+
};
|
|
52
|
+
export declare const makeSelection: (relays: string[], weight?: number) => Selection;
|
|
53
|
+
export type FallbackPolicy = (count: number, limit: number) => number;
|
|
54
|
+
export declare const addNoFallbacks: (count: number, limit: number) => number;
|
|
55
|
+
export declare const addMinimalFallbacks: (count: number, limit: number) => 0 | 1;
|
|
56
|
+
export declare const addMaximalFallbacks: (count: number, limit: number) => number;
|
|
57
|
+
export declare const routerContext: RouterOptions;
|
|
58
|
+
export declare class Router {
|
|
59
|
+
readonly options: RouterOptions;
|
|
60
|
+
static configure(options: RouterOptions): void;
|
|
61
|
+
static get(): Router;
|
|
62
|
+
constructor(options: RouterOptions);
|
|
63
|
+
getRelaysForPubkey: (pubkey: string, mode?: RelayMode) => string[];
|
|
64
|
+
getRelaysForPubkeys: (pubkeys: string[], mode?: RelayMode) => string[][];
|
|
65
|
+
getRelaysForUser: (mode?: RelayMode) => string[];
|
|
66
|
+
scenario: (selections: Selection[]) => RouterScenario;
|
|
67
|
+
merge: (scenarios: RouterScenario[]) => RouterScenario;
|
|
68
|
+
FromRelays: (relays: string[]) => RouterScenario;
|
|
69
|
+
Search: () => RouterScenario;
|
|
70
|
+
Index: () => RouterScenario;
|
|
71
|
+
Default: () => RouterScenario;
|
|
72
|
+
ForUser: () => RouterScenario;
|
|
73
|
+
FromUser: () => RouterScenario;
|
|
74
|
+
UserInbox: () => RouterScenario;
|
|
75
|
+
ForPubkey: (pubkey: string) => RouterScenario;
|
|
76
|
+
FromPubkey: (pubkey: string) => RouterScenario;
|
|
77
|
+
PubkeyInbox: (pubkey: string) => RouterScenario;
|
|
78
|
+
ForPubkeys: (pubkeys: string[]) => RouterScenario;
|
|
79
|
+
FromPubkeys: (pubkeys: string[]) => RouterScenario;
|
|
80
|
+
PubkeyInboxes: (pubkeys: string[]) => RouterScenario;
|
|
81
|
+
Event: (event: TrustedEvent) => RouterScenario;
|
|
82
|
+
Replies: (event: TrustedEvent) => RouterScenario;
|
|
83
|
+
Quote: (event: TrustedEvent, value: string, relays?: string[]) => RouterScenario;
|
|
84
|
+
EventAncestors: (event: TrustedEvent, type: "mentions" | "replies" | "roots") => RouterScenario;
|
|
85
|
+
EventMentions: (event: TrustedEvent) => RouterScenario;
|
|
86
|
+
EventParents: (event: TrustedEvent) => RouterScenario;
|
|
87
|
+
EventRoots: (event: TrustedEvent) => RouterScenario;
|
|
88
|
+
PublishEvent: (event: TrustedEvent) => RouterScenario;
|
|
89
|
+
}
|
|
90
|
+
export type RouterScenarioOptions = {
|
|
91
|
+
policy?: FallbackPolicy;
|
|
92
|
+
limit?: number;
|
|
93
|
+
allowLocal?: boolean;
|
|
94
|
+
allowOnion?: boolean;
|
|
95
|
+
allowInsecure?: boolean;
|
|
96
|
+
};
|
|
97
|
+
export declare class RouterScenario {
|
|
98
|
+
readonly router: Router;
|
|
99
|
+
readonly selections: Selection[];
|
|
100
|
+
readonly options: RouterScenarioOptions;
|
|
101
|
+
constructor(router: Router, selections: Selection[], options?: RouterScenarioOptions);
|
|
102
|
+
clone: (options: RouterScenarioOptions) => RouterScenario;
|
|
103
|
+
filter: (f: (selection: Selection) => boolean) => RouterScenario;
|
|
104
|
+
update: (f: (selection: Selection) => Selection) => RouterScenario;
|
|
105
|
+
policy: (policy: FallbackPolicy) => RouterScenario;
|
|
106
|
+
limit: (limit: number) => RouterScenario;
|
|
107
|
+
allowLocal: (allowLocal: boolean) => RouterScenario;
|
|
108
|
+
allowOnion: (allowOnion: boolean) => RouterScenario;
|
|
109
|
+
allowInsecure: (allowInsecure: boolean) => RouterScenario;
|
|
110
|
+
weight: (scale: number) => RouterScenario;
|
|
111
|
+
getPolicy: () => (count: number, limit: number) => number;
|
|
112
|
+
getLimit: () => number;
|
|
113
|
+
getUrls: () => string[];
|
|
114
|
+
getUrl: () => string | undefined;
|
|
115
|
+
}
|
|
116
|
+
type FilterScenario = {
|
|
117
|
+
filter: Filter;
|
|
118
|
+
scenario: RouterScenario;
|
|
119
|
+
};
|
|
120
|
+
type FilterSelectionRule = (filter: Filter) => FilterScenario[];
|
|
121
|
+
export declare const getFilterSelectionsForSearch: (filter: Filter) => {
|
|
122
|
+
filter: Filter;
|
|
123
|
+
scenario: RouterScenario;
|
|
124
|
+
}[];
|
|
125
|
+
export declare const getFilterSelectionsForWraps: (filter: Filter) => {
|
|
126
|
+
filter: {
|
|
127
|
+
kinds: number[];
|
|
128
|
+
ids?: string[];
|
|
129
|
+
authors?: string[];
|
|
130
|
+
since?: number;
|
|
131
|
+
until?: number;
|
|
132
|
+
limit?: number;
|
|
133
|
+
search?: string;
|
|
134
|
+
};
|
|
135
|
+
scenario: RouterScenario;
|
|
136
|
+
}[];
|
|
137
|
+
export declare const getFilterSelectionsForIndexedKinds: (filter: Filter) => {
|
|
138
|
+
filter: {
|
|
139
|
+
kinds: number[];
|
|
140
|
+
ids?: string[];
|
|
141
|
+
authors?: string[];
|
|
142
|
+
since?: number;
|
|
143
|
+
until?: number;
|
|
144
|
+
limit?: number;
|
|
145
|
+
search?: string;
|
|
146
|
+
};
|
|
147
|
+
scenario: RouterScenario;
|
|
148
|
+
}[];
|
|
149
|
+
export declare const getFilterSelectionsForAuthors: (filter: Filter) => {
|
|
150
|
+
filter: {
|
|
151
|
+
authors: string[];
|
|
152
|
+
ids?: string[];
|
|
153
|
+
kinds?: number[];
|
|
154
|
+
since?: number;
|
|
155
|
+
until?: number;
|
|
156
|
+
limit?: number;
|
|
157
|
+
search?: string;
|
|
158
|
+
};
|
|
159
|
+
scenario: RouterScenario;
|
|
160
|
+
}[];
|
|
161
|
+
export declare const getFilterSelectionsForUser: (filter: Filter) => {
|
|
162
|
+
filter: Filter;
|
|
163
|
+
scenario: RouterScenario;
|
|
164
|
+
}[];
|
|
165
|
+
export declare const defaultFilterSelectionRules: (((filter: Filter) => {
|
|
166
|
+
filter: Filter;
|
|
167
|
+
scenario: RouterScenario;
|
|
168
|
+
}[]) | ((filter: Filter) => {
|
|
169
|
+
filter: {
|
|
170
|
+
kinds: number[];
|
|
171
|
+
ids?: string[];
|
|
172
|
+
authors?: string[];
|
|
173
|
+
since?: number;
|
|
174
|
+
until?: number;
|
|
175
|
+
limit?: number;
|
|
176
|
+
search?: string;
|
|
177
|
+
};
|
|
178
|
+
scenario: RouterScenario;
|
|
179
|
+
}[]) | ((filter: Filter) => {
|
|
180
|
+
filter: {
|
|
181
|
+
authors: string[];
|
|
182
|
+
ids?: string[];
|
|
183
|
+
kinds?: number[];
|
|
184
|
+
since?: number;
|
|
185
|
+
until?: number;
|
|
186
|
+
limit?: number;
|
|
187
|
+
search?: string;
|
|
188
|
+
};
|
|
189
|
+
scenario: RouterScenario;
|
|
190
|
+
}[]))[];
|
|
191
|
+
export declare const getFilterSelections: (filters: Filter[], rules?: FilterSelectionRule[]) => RelaysAndFilters[];
|
|
192
|
+
export {};
|
|
193
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAgBL,YAAY,EACZ,MAAM,EAIN,SAAS,EACV,MAAM,gBAAgB,CAAA;AAGvB,eAAO,MAAM,aAAa,UAA2C,CAAA;AAErE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;IAExC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM,EAAE,CAAA;IAEhE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM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,MAAM,mBAAmB,GAC9B,SAAS,MAAM,EAAE,EACjB,QAAO,mBAAmB,EAAgC,KACzD,gBAAgB,EAwBlB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { uniq, intersection, mergeLeft, first, clamp, sortBy, shuffle, pushToMapKey, inc, add, take, chunks, } from "@welshman/lib";
|
|
2
|
+
import { getFilterId, isRelayUrl, isOnionUrl, isLocalUrl, isShareableRelayUrl, COMMENT, PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS, WRAP, getReplyTags, getCommentTags, getPubkeyTagValues, normalizeRelayUrl, readList, asDecryptedEvent, getRelaysFromList, RelayMode, } from "@welshman/util";
|
|
3
|
+
import { Repository } from "@welshman/relay";
|
|
4
|
+
export const INDEXED_KINDS = [PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS];
|
|
5
|
+
export const makeSelection = (relays, weight = 1) => ({
|
|
6
|
+
relays: relays.filter(isRelayUrl).map(normalizeRelayUrl),
|
|
7
|
+
weight,
|
|
8
|
+
});
|
|
9
|
+
export const addNoFallbacks = (count, limit) => 0;
|
|
10
|
+
export const addMinimalFallbacks = (count, limit) => (count > 0 ? 0 : 1);
|
|
11
|
+
export const addMaximalFallbacks = (count, limit) => limit - count;
|
|
12
|
+
// Router class
|
|
13
|
+
export const routerContext = {
|
|
14
|
+
getPubkeyRelays: (pubkey, mode) => {
|
|
15
|
+
return uniq(Repository.get()
|
|
16
|
+
.query([{ kinds: [RELAYS], authors: [pubkey] }])
|
|
17
|
+
.flatMap(event => getRelaysFromList(readList(asDecryptedEvent(event)), mode)));
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export class Router {
|
|
21
|
+
options;
|
|
22
|
+
static configure(options) {
|
|
23
|
+
Object.assign(routerContext, options);
|
|
24
|
+
}
|
|
25
|
+
static get() {
|
|
26
|
+
return new Router(routerContext);
|
|
27
|
+
}
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.options = mergeLeft(options, routerContext);
|
|
30
|
+
}
|
|
31
|
+
// Utilities derived from options
|
|
32
|
+
getRelaysForPubkey = (pubkey, mode) => this.options.getPubkeyRelays?.(pubkey, mode) || [];
|
|
33
|
+
getRelaysForPubkeys = (pubkeys, mode) => pubkeys.map(pubkey => this.getRelaysForPubkey(pubkey, mode));
|
|
34
|
+
getRelaysForUser = (mode) => {
|
|
35
|
+
const pubkey = this.options.getUserPubkey?.();
|
|
36
|
+
return pubkey ? this.getRelaysForPubkey(pubkey, mode) : [];
|
|
37
|
+
};
|
|
38
|
+
// Utilities for creating scenarios
|
|
39
|
+
scenario = (selections) => new RouterScenario(this, selections);
|
|
40
|
+
merge = (scenarios) => this.scenario(scenarios.flatMap((scenario) => scenario.selections));
|
|
41
|
+
// Routing scenarios
|
|
42
|
+
FromRelays = (relays) => this.scenario([makeSelection(relays)]);
|
|
43
|
+
Search = () => this.FromRelays(this.options.getSearchRelays?.() || []);
|
|
44
|
+
Index = () => this.FromRelays(this.options.getIndexerRelays?.() || []);
|
|
45
|
+
Default = () => this.FromRelays(this.options.getDefaultRelays?.() || []);
|
|
46
|
+
ForUser = () => this.FromRelays(this.getRelaysForUser(RelayMode.Read));
|
|
47
|
+
FromUser = () => this.FromRelays(this.getRelaysForUser(RelayMode.Write));
|
|
48
|
+
UserInbox = () => this.FromRelays(this.getRelaysForUser(RelayMode.Inbox));
|
|
49
|
+
ForPubkey = (pubkey) => this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Read));
|
|
50
|
+
FromPubkey = (pubkey) => this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Write));
|
|
51
|
+
PubkeyInbox = (pubkey) => this.FromRelays(this.getRelaysForPubkey(pubkey, RelayMode.Inbox));
|
|
52
|
+
ForPubkeys = (pubkeys) => this.merge(pubkeys.map(pubkey => this.ForPubkey(pubkey)));
|
|
53
|
+
FromPubkeys = (pubkeys) => this.merge(pubkeys.map(pubkey => this.FromPubkey(pubkey)));
|
|
54
|
+
PubkeyInboxes = (pubkeys) => this.merge(pubkeys.map(pubkey => this.PubkeyInbox(pubkey)));
|
|
55
|
+
Event = (event) => this.FromRelays(this.getRelaysForPubkey(event.pubkey, RelayMode.Write));
|
|
56
|
+
Replies = (event) => this.FromRelays(this.getRelaysForPubkey(event.pubkey, RelayMode.Read));
|
|
57
|
+
Quote = (event, value, relays = []) => {
|
|
58
|
+
const tag = event.tags.find(t => t[1] === value);
|
|
59
|
+
const scenarios = [
|
|
60
|
+
this.FromRelays(relays),
|
|
61
|
+
this.ForPubkey(event.pubkey),
|
|
62
|
+
this.FromPubkey(event.pubkey),
|
|
63
|
+
];
|
|
64
|
+
if (tag?.[2] && isShareableRelayUrl(tag[2])) {
|
|
65
|
+
scenarios.push(this.FromRelays([tag[2]]));
|
|
66
|
+
}
|
|
67
|
+
if (tag?.[3]?.length === 64) {
|
|
68
|
+
scenarios.push(this.FromPubkeys([tag[3]]));
|
|
69
|
+
}
|
|
70
|
+
return this.merge(scenarios);
|
|
71
|
+
};
|
|
72
|
+
EventAncestors = (event, type) => {
|
|
73
|
+
const ancestorTags = event.kind === COMMENT ? getCommentTags(event.tags) : getReplyTags(event.tags);
|
|
74
|
+
const tags = ancestorTags[type] || [];
|
|
75
|
+
return this.scenario(tags.flatMap(([_, value, relay, pubkey]) => {
|
|
76
|
+
const selections = [makeSelection(this.ForUser().getUrls(), 0.5)];
|
|
77
|
+
if (pubkey) {
|
|
78
|
+
selections.push(makeSelection(this.FromPubkey(pubkey).getUrls()));
|
|
79
|
+
}
|
|
80
|
+
if (relay) {
|
|
81
|
+
selections.push(makeSelection([relay], 0.9));
|
|
82
|
+
}
|
|
83
|
+
return selections;
|
|
84
|
+
}));
|
|
85
|
+
};
|
|
86
|
+
EventMentions = (event) => this.EventAncestors(event, "mentions");
|
|
87
|
+
EventParents = (event) => this.EventAncestors(event, "replies");
|
|
88
|
+
EventRoots = (event) => this.EventAncestors(event, "roots");
|
|
89
|
+
PublishEvent = (event) => {
|
|
90
|
+
const pubkeys = getPubkeyTagValues(event.tags);
|
|
91
|
+
return this.merge([
|
|
92
|
+
this.FromPubkey(event.pubkey),
|
|
93
|
+
...pubkeys.map(pubkey => this.ForPubkey(pubkey).weight(0.5)),
|
|
94
|
+
]);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export class RouterScenario {
|
|
98
|
+
router;
|
|
99
|
+
selections;
|
|
100
|
+
options;
|
|
101
|
+
constructor(router, selections, options = {}) {
|
|
102
|
+
this.router = router;
|
|
103
|
+
this.selections = selections;
|
|
104
|
+
this.options = options;
|
|
105
|
+
}
|
|
106
|
+
clone = (options) => new RouterScenario(this.router, this.selections, { ...this.options, ...options });
|
|
107
|
+
filter = (f) => new RouterScenario(this.router, this.selections.filter(selection => f(selection)), this.options);
|
|
108
|
+
update = (f) => new RouterScenario(this.router, this.selections.map(selection => f(selection)), this.options);
|
|
109
|
+
policy = (policy) => this.clone({ policy });
|
|
110
|
+
limit = (limit) => this.clone({ limit });
|
|
111
|
+
allowLocal = (allowLocal) => this.clone({ allowLocal });
|
|
112
|
+
allowOnion = (allowOnion) => this.clone({ allowOnion });
|
|
113
|
+
allowInsecure = (allowInsecure) => this.clone({ allowInsecure });
|
|
114
|
+
weight = (scale) => this.update(selection => ({ ...selection, weight: selection.weight * scale }));
|
|
115
|
+
getPolicy = () => this.options.policy || addNoFallbacks;
|
|
116
|
+
getLimit = () => this.options.limit || this.router.options.getLimit?.() || 3;
|
|
117
|
+
getUrls = () => {
|
|
118
|
+
const limit = this.getLimit();
|
|
119
|
+
const fallbackPolicy = this.getPolicy();
|
|
120
|
+
const relayWeights = new Map();
|
|
121
|
+
const { allowOnion, allowLocal, allowInsecure } = this.options;
|
|
122
|
+
for (const { weight, relays } of this.selections) {
|
|
123
|
+
for (const relay of relays) {
|
|
124
|
+
if (!isRelayUrl(relay))
|
|
125
|
+
continue;
|
|
126
|
+
if (!allowOnion && isOnionUrl(relay))
|
|
127
|
+
continue;
|
|
128
|
+
if (!allowLocal && isLocalUrl(relay))
|
|
129
|
+
continue;
|
|
130
|
+
if (!allowInsecure && relay.startsWith("ws://") && !isOnionUrl(relay))
|
|
131
|
+
continue;
|
|
132
|
+
relayWeights.set(relay, add(weight, relayWeights.get(relay)));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const scoreRelay = (relay) => {
|
|
136
|
+
const quality = this.router.options.getRelayQuality?.(relay) || 1;
|
|
137
|
+
const weight = relayWeights.get(relay);
|
|
138
|
+
// Log the weight, since it's a straight count which ends up over-weighting hubs.
|
|
139
|
+
// Also add some random noise so that we'll occasionally pick lower quality/less
|
|
140
|
+
// popular relays.
|
|
141
|
+
return quality ? -(quality * inc(Math.log(weight)) * Math.random()) : 0;
|
|
142
|
+
};
|
|
143
|
+
const relays = take(limit, sortBy(scoreRelay, Array.from(relayWeights.keys()).filter(scoreRelay)));
|
|
144
|
+
const fallbacksNeeded = fallbackPolicy(relays.length, limit);
|
|
145
|
+
const allFallbackRelays = this.router.options.getDefaultRelays?.() || [];
|
|
146
|
+
const fallbackRelays = shuffle(allFallbackRelays).slice(0, fallbacksNeeded);
|
|
147
|
+
for (const fallbackRelay of fallbackRelays) {
|
|
148
|
+
relays.push(fallbackRelay);
|
|
149
|
+
}
|
|
150
|
+
return relays;
|
|
151
|
+
};
|
|
152
|
+
getUrl = () => first(this.getUrls());
|
|
153
|
+
}
|
|
154
|
+
export const getFilterSelectionsForSearch = (filter) => {
|
|
155
|
+
if (!filter.search)
|
|
156
|
+
return [];
|
|
157
|
+
const relays = routerContext.getSearchRelays?.() || [];
|
|
158
|
+
return [{ filter, scenario: Router.get().FromRelays(relays).weight(10) }];
|
|
159
|
+
};
|
|
160
|
+
export const getFilterSelectionsForWraps = (filter) => {
|
|
161
|
+
if (!filter.kinds?.includes(WRAP) || filter.authors)
|
|
162
|
+
return [];
|
|
163
|
+
return [
|
|
164
|
+
{
|
|
165
|
+
filter: { ...filter, kinds: [WRAP] },
|
|
166
|
+
scenario: Router.get().UserInbox(),
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
};
|
|
170
|
+
export const getFilterSelectionsForIndexedKinds = (filter) => {
|
|
171
|
+
const kinds = intersection(INDEXED_KINDS, filter.kinds || []);
|
|
172
|
+
if (kinds.length === 0)
|
|
173
|
+
return [];
|
|
174
|
+
const relays = routerContext.getIndexerRelays?.() || [];
|
|
175
|
+
return [
|
|
176
|
+
{
|
|
177
|
+
filter: { ...filter, kinds },
|
|
178
|
+
scenario: Router.get().FromRelays(relays),
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
};
|
|
182
|
+
export const getFilterSelectionsForAuthors = (filter) => {
|
|
183
|
+
if (!filter.authors)
|
|
184
|
+
return [];
|
|
185
|
+
const chunkCount = clamp([1, 30], Math.round(filter.authors.length / 30));
|
|
186
|
+
return chunks(chunkCount, filter.authors).map(authors => ({
|
|
187
|
+
filter: { ...filter, authors },
|
|
188
|
+
scenario: Router.get().FromPubkeys(authors),
|
|
189
|
+
}));
|
|
190
|
+
};
|
|
191
|
+
export const getFilterSelectionsForUser = (filter) => [
|
|
192
|
+
{ filter, scenario: Router.get().ForUser().weight(0.2) },
|
|
193
|
+
];
|
|
194
|
+
export const defaultFilterSelectionRules = [
|
|
195
|
+
getFilterSelectionsForSearch,
|
|
196
|
+
getFilterSelectionsForWraps,
|
|
197
|
+
getFilterSelectionsForIndexedKinds,
|
|
198
|
+
getFilterSelectionsForAuthors,
|
|
199
|
+
getFilterSelectionsForUser,
|
|
200
|
+
];
|
|
201
|
+
export const getFilterSelections = (filters, rules = defaultFilterSelectionRules) => {
|
|
202
|
+
const filtersById = new Map();
|
|
203
|
+
const scenariosById = new Map();
|
|
204
|
+
for (const filter of filters) {
|
|
205
|
+
for (const filterScenario of rules.flatMap(rule => rule(filter))) {
|
|
206
|
+
const id = getFilterId(filterScenario.filter);
|
|
207
|
+
filtersById.set(id, filterScenario.filter);
|
|
208
|
+
pushToMapKey(scenariosById, id, filterScenario.scenario);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const result = [];
|
|
212
|
+
for (const [id, filter] of filtersById.entries()) {
|
|
213
|
+
const scenario = Router.get()
|
|
214
|
+
.merge(scenariosById.get(id) || [])
|
|
215
|
+
.policy(addMinimalFallbacks);
|
|
216
|
+
result.push({ filters: [filter], relays: scenario.getUrls() });
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
219
|
+
};
|
|
220
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,KAAK,EACL,KAAK,EACL,MAAM,EACN,OAAO,EACP,YAAY,EACZ,GAAG,EACH,GAAG,EACH,IAAI,EACJ,MAAM,GACP,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,WAAW,EACX,UAAU,EACV,UAAU,EACV,UAAU,EACV,mBAAmB,EACnB,OAAO,EACP,OAAO,EACP,MAAM,EACN,YAAY,EACZ,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EAGjB,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,GACV,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAA;AAE1C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;AA4DrE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAgB,EAAE,MAAM,GAAG,CAAC,EAAa,EAAE,CAAC,CAAC;IACzE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC;IACxD,MAAM;CACP,CAAC,CAAA;AAMF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EA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M,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts"],"version":"5.8.2"}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@welshman/router",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"author": "hodlbod",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "A collection of utilities for nostr relay selection.",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@welshman/lib": "0.2.0",
|
|
18
|
+
"@welshman/util": "0.2.0",
|
|
19
|
+
"@welshman/relay": "0.2.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"rimraf": "~6.0.0",
|
|
23
|
+
"typescript": "~5.8.0"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "pnpm run clean && pnpm run compile --force",
|
|
27
|
+
"clean": "rimraf ./dist",
|
|
28
|
+
"compile": "tsc -b tsconfig.build.json"
|
|
29
|
+
}
|
|
30
|
+
}
|