@welshman/app 0.0.20 → 0.0.21

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.
@@ -1,6 +1,5 @@
1
- import { Tags } from '@welshman/util';
2
- import type { TrustedEvent, Filter } from '@welshman/util';
3
- import type { RelaysAndFilters } from '@welshman/net';
1
+ import type { TrustedEvent, Filter } from "@welshman/util";
2
+ import type { RelaysAndFilters } from "@welshman/net";
4
3
  export declare const INDEXED_KINDS: number[];
5
4
  export declare enum RelayMode {
6
5
  Read = "read",
@@ -13,18 +12,6 @@ export type RouterOptions = {
13
12
  * @returns The user's public key as a string, or null if not available.
14
13
  */
15
14
  getUserPubkey?: () => string | null;
16
- /**
17
- * Retrieves group relays for the specified community.
18
- * @param address - The address to retrieve group relays for.
19
- * @returns An array of group relay URLs as strings.
20
- */
21
- getGroupRelays?: (address: string) => string[];
22
- /**
23
- * Retrieves relays for the specified community.
24
- * @param address - The address to retrieve community relays for.
25
- * @returns An array of community relay URLs as strings.
26
- */
27
- getCommunityRelays?: (address: string) => string[];
28
15
  /**
29
16
  * Retrieves relays for the specified public key and mode.
30
17
  * @param pubkey - The public key to retrieve relays for.
@@ -53,11 +40,6 @@ export type RouterOptions = {
53
40
  * @returns The quality of the relay as a number between 0 and 1 inclusive.
54
41
  */
55
42
  getRelayQuality?: (url: string) => number;
56
- /**
57
- * Retrieves the redundancy setting, which is how many relays to use per selection value.
58
- * @returns The redundancy setting as a number.
59
- */
60
- getRedundancy?: () => number;
61
43
  /**
62
44
  * Retrieves the limit setting, which is the maximum number of relays that should be
63
45
  * returned from getUrls and getSelections.
@@ -65,135 +47,141 @@ export type RouterOptions = {
65
47
  */
66
48
  getLimit?: () => number;
67
49
  };
68
- export type ValuesByRelay = Map<string, string[]>;
69
- export type RelayValues = {
70
- relay: string;
71
- values: string[];
72
- };
73
- export type ValueRelays = {
74
- value: string;
50
+ export type Selection = {
51
+ weight: number;
75
52
  relays: string[];
76
53
  };
77
54
  export type FallbackPolicy = (count: number, limit: number) => number;
78
- export declare const addNoFallbacks: (count: number, redundancy: number) => number;
79
- export declare const addMinimalFallbacks: (count: number, redundancy: number) => 0 | 1;
80
- export declare const addMaximalFallbacks: (count: number, redundancy: number) => number;
55
+ export declare const addNoFallbacks: (count: number, limit: number) => number;
56
+ export declare const addMinimalFallbacks: (count: number, limit: number) => 0 | 1;
57
+ export declare const addMaximalFallbacks: (count: number, limit: number) => number;
81
58
  export declare class Router {
82
59
  readonly options: RouterOptions;
83
60
  constructor(options: RouterOptions);
84
- getPubkeySelection: (pubkey: string, mode?: RelayMode) => {
85
- value: string;
86
- relays: string[];
87
- };
88
- getPubkeySelections: (pubkeys: string[], mode?: RelayMode) => {
89
- value: string;
90
- relays: string[];
91
- }[];
92
- getUserSelections: (mode?: RelayMode) => {
93
- value: string;
94
- relays: string[];
95
- }[];
96
- getContextSelections: (tags: Tags) => {
97
- value: string;
98
- relays: string[];
99
- }[];
100
- selection: (value: string, relays: Iterable<string>) => {
101
- value: string;
102
- relays: string[];
103
- };
104
- selections: (values: string[], relays: string[]) => {
105
- value: string;
106
- relays: string[];
107
- }[];
108
- forceValue: (value: string, selections: ValueRelays[]) => {
109
- value: string;
110
- relays: string[];
111
- }[];
112
- relaySelectionsFromMap: (valuesByRelay: ValuesByRelay) => {
113
- relay: string;
114
- values: string[];
115
- }[];
116
- scoreRelaySelection: ({ values, relay }: RelayValues) => number;
117
- sortRelaySelections: (relaySelections: RelayValues[]) => RelayValues[];
118
- scenario: (selections: ValueRelays[]) => RouterScenario;
61
+ getRelaysForPubkey: (pubkey: string, mode?: RelayMode) => string[];
62
+ getRelaysForPubkeys: (pubkeys: string[], mode?: RelayMode) => string[][];
63
+ getRelaysForUser: (mode?: RelayMode) => string[];
64
+ scenario: (selections: Selection[]) => RouterScenario;
119
65
  merge: (scenarios: RouterScenario[]) => RouterScenario;
120
- product: (values: string[], relays: string[]) => RouterScenario;
121
- fromRelays: (relays: string[]) => RouterScenario;
122
- User: () => RouterScenario;
123
- ReadRelays: () => RouterScenario;
124
- WriteRelays: () => RouterScenario;
125
- InboxRelays: () => RouterScenario;
126
- Messages: (pubkeys: string[]) => RouterScenario;
127
- PublishMessage: (pubkey: string) => RouterScenario;
66
+ FromRelays: (relays: string[]) => RouterScenario;
67
+ ForUser: () => RouterScenario;
68
+ FromUser: () => RouterScenario;
69
+ UserInbox: () => RouterScenario;
70
+ ForPubkey: (pubkey: string) => RouterScenario;
71
+ FromPubkey: (pubkey: string) => RouterScenario;
72
+ PubkeyInbox: (pubkey: string) => RouterScenario;
73
+ ForPubkeys: (pubkeys: string[]) => RouterScenario;
74
+ FromPubkeys: (pubkeys: string[]) => RouterScenario;
75
+ PubkeyInboxes: (pubkeys: string[]) => RouterScenario;
128
76
  Event: (event: TrustedEvent) => RouterScenario;
129
- EventChildren: (event: TrustedEvent) => RouterScenario;
77
+ Replies: (event: TrustedEvent) => RouterScenario;
78
+ Quote: (event: TrustedEvent, value: string, relays?: never[]) => RouterScenario;
130
79
  EventAncestors: (event: TrustedEvent, type: "mentions" | "replies" | "roots") => RouterScenario;
131
80
  EventMentions: (event: TrustedEvent) => RouterScenario;
132
81
  EventParents: (event: TrustedEvent) => RouterScenario;
133
82
  EventRoots: (event: TrustedEvent) => RouterScenario;
134
83
  PublishEvent: (event: TrustedEvent) => RouterScenario;
135
- FromPubkeys: (pubkeys: string[]) => RouterScenario;
136
- ForPubkeys: (pubkeys: string[]) => RouterScenario;
137
- WithinGroup: (address: string, relays?: string) => RouterScenario;
138
- WithinCommunity: (address: string) => RouterScenario;
139
- WithinContext: (address: string) => RouterScenario;
140
- WithinMultipleContexts: (addresses: string[]) => RouterScenario;
141
- Search: (term: string, relays?: string[]) => RouterScenario;
142
84
  }
143
85
  export type RouterScenarioOptions = {
144
- redundancy?: number;
145
86
  policy?: FallbackPolicy;
146
87
  limit?: number;
147
88
  };
148
89
  export declare class RouterScenario {
149
90
  readonly router: Router;
150
- readonly selections: ValueRelays[];
91
+ readonly selections: Selection[];
151
92
  readonly options: RouterScenarioOptions;
152
- constructor(router: Router, selections: ValueRelays[], options?: RouterScenarioOptions);
93
+ constructor(router: Router, selections: Selection[], options?: RouterScenarioOptions);
153
94
  clone: (options: RouterScenarioOptions) => RouterScenario;
154
- filter: (f: (selection: ValueRelays) => boolean) => RouterScenario;
155
- update: (f: (selection: ValueRelays) => ValueRelays) => RouterScenario;
156
- redundancy: (redundancy: number) => RouterScenario;
95
+ filter: (f: (selection: Selection) => boolean) => RouterScenario;
96
+ update: (f: (selection: Selection) => Selection) => RouterScenario;
157
97
  policy: (policy: FallbackPolicy) => RouterScenario;
158
98
  limit: (limit: number) => RouterScenario;
159
- getRedundancy: () => number;
160
- getPolicy: () => (count: number, redundancy: number) => number;
99
+ weight: (scale: number) => RouterScenario;
100
+ getPolicy: () => (count: number, limit: number) => number;
161
101
  getLimit: () => number;
162
- getSelections: () => {
163
- relay: string;
164
- values: string[];
165
- }[];
166
102
  getUrls: () => string[];
167
103
  getUrl: () => string;
168
104
  }
169
- export declare const getRelayQuality: (url: string) => number;
105
+ export declare const getRelayQuality: (url: string) => 0 | 1;
170
106
  export declare const getPubkeyRelays: (pubkey: string, mode?: string) => string[];
171
107
  export declare const getIndexerRelays: () => string[];
172
108
  export declare const getFallbackRelays: () => string[];
173
109
  export declare const getSearchRelays: () => string[];
174
110
  export declare const makeRouter: (options?: Partial<RouterOptions>) => Router;
175
- export type FilterSelection = {
176
- id: string;
111
+ type FilterScenario = {
177
112
  filter: Filter;
178
113
  scenario: RouterScenario;
179
114
  };
180
- type FilterSelectionRuleState = {
115
+ type FilterSelectionRule = (filter: Filter) => FilterScenario[];
116
+ export declare const getFilterSelectionsForSearch: (filter: Filter) => {
181
117
  filter: Filter;
182
- selections: FilterSelection[];
183
- };
184
- type FilterSelectionRule = (state: FilterSelectionRuleState) => boolean;
185
- export declare const makeFilterSelection: (id: string, filter: Filter, scenario: RouterScenario) => {
186
- id: string;
118
+ scenario: RouterScenario;
119
+ }[];
120
+ export declare const getFilterSelectionsForWraps: (filter: Filter) => {
121
+ filter: {
122
+ kinds: number[];
123
+ ids?: string[] | undefined;
124
+ authors?: string[] | undefined;
125
+ since?: number | undefined;
126
+ until?: number | undefined;
127
+ limit?: number | undefined;
128
+ search?: string | undefined;
129
+ };
130
+ scenario: RouterScenario;
131
+ }[];
132
+ export declare const getFilterSelectionsForIndexedKinds: (filter: Filter) => {
133
+ filter: {
134
+ kinds: number[];
135
+ ids?: string[] | undefined;
136
+ authors?: string[] | undefined;
137
+ since?: number | undefined;
138
+ until?: number | undefined;
139
+ limit?: number | undefined;
140
+ search?: string | undefined;
141
+ };
142
+ scenario: RouterScenario;
143
+ }[];
144
+ export declare const getFilterSelectionsForAuthors: (filter: Filter) => {
145
+ filter: {
146
+ authors: string[];
147
+ ids?: string[] | undefined;
148
+ kinds?: number[] | undefined;
149
+ since?: number | undefined;
150
+ until?: number | undefined;
151
+ limit?: number | undefined;
152
+ search?: string | undefined;
153
+ };
154
+ scenario: RouterScenario;
155
+ }[];
156
+ export declare const getFilterSelectionsForUser: (filter: Filter) => {
187
157
  filter: Filter;
188
158
  scenario: RouterScenario;
189
- };
190
- export declare const getFilterSelectionsForLocalRelay: (state: FilterSelectionRuleState) => boolean;
191
- export declare const getFilterSelectionsForSearch: (state: FilterSelectionRuleState) => boolean;
192
- export declare const getFilterSelectionsForContext: (state: FilterSelectionRuleState) => boolean;
193
- export declare const getFilterSelectionsForWraps: (state: FilterSelectionRuleState) => boolean;
194
- export declare const getFilterSelectionsForIndexedKinds: (state: FilterSelectionRuleState) => boolean;
195
- export declare const getFilterSelectionsForAuthors: (state: FilterSelectionRuleState) => boolean;
196
- export declare const getFilterSelectionsForUser: (state: FilterSelectionRuleState) => boolean;
197
- export declare const defaultFilterSelectionRules: ((state: FilterSelectionRuleState) => boolean)[];
159
+ }[];
160
+ export declare const defaultFilterSelectionRules: (((filter: Filter) => {
161
+ filter: Filter;
162
+ scenario: RouterScenario;
163
+ }[]) | ((filter: Filter) => {
164
+ filter: {
165
+ kinds: number[];
166
+ ids?: string[] | undefined;
167
+ authors?: string[] | undefined;
168
+ since?: number | undefined;
169
+ until?: number | undefined;
170
+ limit?: number | undefined;
171
+ search?: string | undefined;
172
+ };
173
+ scenario: RouterScenario;
174
+ }[]) | ((filter: Filter) => {
175
+ filter: {
176
+ authors: string[];
177
+ ids?: string[] | undefined;
178
+ kinds?: number[] | undefined;
179
+ since?: number | undefined;
180
+ until?: number | undefined;
181
+ limit?: number | undefined;
182
+ search?: string | undefined;
183
+ };
184
+ scenario: RouterScenario;
185
+ }[]))[];
198
186
  export declare const getFilterSelections: (filters: Filter[], rules?: FilterSelectionRule[]) => RelaysAndFilters[];
199
187
  export {};