@welshman/net 0.0.43 → 0.0.45
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/Connection.d.ts +8 -8
- package/build/src/Connection.js +58 -0
- package/build/src/Connection.js.map +1 -0
- package/build/src/ConnectionAuth.d.ts +1 -1
- package/build/src/ConnectionAuth.js +99 -0
- package/build/src/ConnectionAuth.js.map +1 -0
- package/build/src/{ConnectionEvent.mjs → ConnectionEvent.js} +1 -1
- package/build/src/ConnectionEvent.js.map +1 -0
- package/build/src/ConnectionSender.d.ts +3 -3
- package/build/src/{ConnectionSender.mjs → ConnectionSender.js} +16 -14
- package/build/src/ConnectionSender.js.map +1 -0
- package/build/src/ConnectionState.d.ts +2 -2
- package/build/src/{ConnectionState.mjs → ConnectionState.js} +21 -21
- package/build/src/ConnectionState.js.map +1 -0
- package/build/src/ConnectionStats.d.ts +1 -1
- package/build/src/{ConnectionStats.mjs → ConnectionStats.js} +31 -30
- package/build/src/ConnectionStats.js.map +1 -0
- package/build/src/Context.d.ts +7 -7
- package/build/src/{Context.mjs → Context.js} +8 -9
- package/build/src/Context.js.map +1 -0
- package/build/src/Executor.d.ts +7 -6
- package/build/src/{Executor.mjs → Executor.js} +31 -30
- package/build/src/Executor.js.map +1 -0
- package/build/src/{Negentropy.mjs → Negentropy.js} +1 -1
- package/build/src/Negentropy.js.map +1 -0
- package/build/src/Pool.d.ts +2 -2
- package/build/src/{Pool.mjs → Pool.js} +5 -4
- package/build/src/Pool.js.map +1 -0
- package/build/src/Publish.d.ts +3 -3
- package/build/src/{Publish.mjs → Publish.js} +5 -6
- package/build/src/Publish.js.map +1 -0
- package/build/src/Socket.d.ts +2 -2
- package/build/src/Socket.js +110 -0
- package/build/src/Socket.js.map +1 -0
- package/build/src/Subscribe.d.ts +4 -4
- package/build/src/{Subscribe.mjs → Subscribe.js} +14 -16
- package/build/src/Subscribe.js.map +1 -0
- package/build/src/Sync.d.ts +2 -2
- package/build/src/{Sync.mjs → Sync.js} +11 -12
- package/build/src/Sync.js.map +1 -0
- package/build/src/Tracker.d.ts +2 -2
- package/build/src/Tracker.js +63 -0
- package/build/src/Tracker.js.map +1 -0
- package/build/src/index.d.ts +25 -19
- package/build/src/index.js +20 -0
- package/build/src/index.js.map +1 -0
- package/build/src/target/Echo.d.ts +2 -2
- package/build/src/target/Echo.js +13 -0
- package/build/src/target/Echo.js.map +1 -0
- package/build/src/target/Local.d.ts +4 -4
- package/build/src/target/Local.js +25 -0
- package/build/src/target/Local.js.map +1 -0
- package/build/src/target/Multi.d.ts +4 -4
- package/build/src/target/{Multi.mjs → Multi.js} +8 -7
- package/build/src/target/Multi.js.map +1 -0
- package/build/src/target/Relay.d.ts +3 -3
- package/build/src/target/Relay.js +24 -0
- package/build/src/target/Relay.js.map +1 -0
- package/build/src/target/Relays.d.ts +3 -3
- package/build/src/target/Relays.js +25 -0
- package/build/src/target/Relays.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +7 -10
- package/build/src/Connection.cjs +0 -55
- package/build/src/Connection.cjs.map +0 -1
- package/build/src/Connection.mjs +0 -51
- package/build/src/Connection.mjs.map +0 -1
- package/build/src/ConnectionAuth.cjs +0 -109
- package/build/src/ConnectionAuth.cjs.map +0 -1
- package/build/src/ConnectionAuth.mjs +0 -105
- package/build/src/ConnectionAuth.mjs.map +0 -1
- package/build/src/ConnectionEvent.cjs +0 -16
- package/build/src/ConnectionEvent.cjs.map +0 -1
- package/build/src/ConnectionEvent.mjs.map +0 -1
- package/build/src/ConnectionSender.cjs +0 -50
- package/build/src/ConnectionSender.cjs.map +0 -1
- package/build/src/ConnectionSender.mjs.map +0 -1
- package/build/src/ConnectionState.cjs +0 -84
- package/build/src/ConnectionState.cjs.map +0 -1
- package/build/src/ConnectionState.mjs.map +0 -1
- package/build/src/ConnectionStats.cjs +0 -86
- package/build/src/ConnectionStats.cjs.map +0 -1
- package/build/src/ConnectionStats.mjs.map +0 -1
- package/build/src/Context.cjs +0 -47
- package/build/src/Context.cjs.map +0 -1
- package/build/src/Context.mjs.map +0 -1
- package/build/src/Executor.cjs +0 -109
- package/build/src/Executor.cjs.map +0 -1
- package/build/src/Executor.mjs.map +0 -1
- package/build/src/Negentropy.cjs +0 -516
- package/build/src/Negentropy.cjs.map +0 -1
- package/build/src/Negentropy.mjs.map +0 -1
- package/build/src/Pool.cjs +0 -38
- package/build/src/Pool.cjs.map +0 -1
- package/build/src/Pool.mjs.map +0 -1
- package/build/src/Publish.cjs +0 -74
- package/build/src/Publish.cjs.map +0 -1
- package/build/src/Publish.mjs.map +0 -1
- package/build/src/Socket.cjs +0 -120
- package/build/src/Socket.cjs.map +0 -1
- package/build/src/Socket.mjs +0 -113
- package/build/src/Socket.mjs.map +0 -1
- package/build/src/Subscribe.cjs +0 -294
- package/build/src/Subscribe.cjs.map +0 -1
- package/build/src/Subscribe.mjs.map +0 -1
- package/build/src/Sync.cjs +0 -136
- package/build/src/Sync.cjs.map +0 -1
- package/build/src/Sync.mjs.map +0 -1
- package/build/src/Tracker.cjs +0 -68
- package/build/src/Tracker.cjs.map +0 -1
- package/build/src/Tracker.mjs +0 -64
- package/build/src/Tracker.mjs.map +0 -1
- package/build/src/index.cjs +0 -36
- package/build/src/index.cjs.map +0 -1
- package/build/src/index.mjs +0 -20
- package/build/src/index.mjs.map +0 -1
- package/build/src/target/Echo.cjs +0 -20
- package/build/src/target/Echo.cjs.map +0 -1
- package/build/src/target/Echo.mjs +0 -16
- package/build/src/target/Echo.mjs.map +0 -1
- package/build/src/target/Local.cjs +0 -28
- package/build/src/target/Local.cjs.map +0 -1
- package/build/src/target/Local.mjs +0 -24
- package/build/src/target/Local.mjs.map +0 -1
- package/build/src/target/Multi.cjs +0 -25
- package/build/src/target/Multi.cjs.map +0 -1
- package/build/src/target/Multi.mjs.map +0 -1
- package/build/src/target/Relay.cjs +0 -27
- package/build/src/target/Relay.cjs.map +0 -1
- package/build/src/target/Relay.mjs +0 -23
- package/build/src/target/Relay.mjs.map +0 -1
- package/build/src/target/Relays.cjs +0 -28
- package/build/src/target/Relays.cjs.map +0 -1
- package/build/src/target/Relays.mjs +0 -24
- package/build/src/target/Relays.mjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Emitter } from
|
|
2
|
-
import { Socket } from
|
|
3
|
-
import type { Message } from
|
|
4
|
-
import { ConnectionEvent } from
|
|
5
|
-
import { ConnectionState } from
|
|
6
|
-
import { ConnectionStats } from
|
|
7
|
-
import { ConnectionAuth } from
|
|
8
|
-
import { ConnectionSender } from
|
|
1
|
+
import { Emitter } from "@welshman/lib";
|
|
2
|
+
import { Socket } from "./Socket.js";
|
|
3
|
+
import type { Message } from "./Socket.js";
|
|
4
|
+
import { ConnectionEvent } from "./ConnectionEvent.js";
|
|
5
|
+
import { ConnectionState } from "./ConnectionState.js";
|
|
6
|
+
import { ConnectionStats } from "./ConnectionStats.js";
|
|
7
|
+
import { ConnectionAuth } from "./ConnectionAuth.js";
|
|
8
|
+
import { ConnectionSender } from "./ConnectionSender.js";
|
|
9
9
|
export declare enum ConnectionStatus {
|
|
10
10
|
Open = "open",
|
|
11
11
|
Closed = "Closed"
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Emitter } from "@welshman/lib";
|
|
2
|
+
import { normalizeRelayUrl } from "@welshman/util";
|
|
3
|
+
import { Socket } from "./Socket.js";
|
|
4
|
+
import { ConnectionState } from "./ConnectionState.js";
|
|
5
|
+
import { ConnectionStats } from "./ConnectionStats.js";
|
|
6
|
+
import { ConnectionAuth } from "./ConnectionAuth.js";
|
|
7
|
+
import { ConnectionSender } from "./ConnectionSender.js";
|
|
8
|
+
export var ConnectionStatus;
|
|
9
|
+
(function (ConnectionStatus) {
|
|
10
|
+
ConnectionStatus["Open"] = "open";
|
|
11
|
+
ConnectionStatus["Closed"] = "Closed";
|
|
12
|
+
})(ConnectionStatus || (ConnectionStatus = {}));
|
|
13
|
+
const { Open, Closed } = ConnectionStatus;
|
|
14
|
+
export class Connection extends Emitter {
|
|
15
|
+
url;
|
|
16
|
+
socket;
|
|
17
|
+
sender;
|
|
18
|
+
state;
|
|
19
|
+
stats;
|
|
20
|
+
auth;
|
|
21
|
+
status = Open;
|
|
22
|
+
constructor(url) {
|
|
23
|
+
super();
|
|
24
|
+
if (url !== normalizeRelayUrl(url)) {
|
|
25
|
+
console.warn(`Attempted to open connection to non-normalized url ${url}`);
|
|
26
|
+
}
|
|
27
|
+
this.url = url;
|
|
28
|
+
this.socket = new Socket(this);
|
|
29
|
+
this.sender = new ConnectionSender(this);
|
|
30
|
+
this.state = new ConnectionState(this);
|
|
31
|
+
this.stats = new ConnectionStats(this);
|
|
32
|
+
this.auth = new ConnectionAuth(this);
|
|
33
|
+
this.setMaxListeners(100);
|
|
34
|
+
}
|
|
35
|
+
emit = (type, ...args) => super.emit(type, this, ...args);
|
|
36
|
+
send = async (message) => {
|
|
37
|
+
if (this.status !== Open) {
|
|
38
|
+
throw new Error(`Attempted to send message on ${this.status} connection`);
|
|
39
|
+
}
|
|
40
|
+
this.socket.open();
|
|
41
|
+
this.sender.push(message);
|
|
42
|
+
};
|
|
43
|
+
open = () => {
|
|
44
|
+
this.status = Open;
|
|
45
|
+
this.socket.open();
|
|
46
|
+
this.sender.worker.resume();
|
|
47
|
+
};
|
|
48
|
+
close = () => {
|
|
49
|
+
this.status = Closed;
|
|
50
|
+
this.socket.close();
|
|
51
|
+
this.sender.worker.pause();
|
|
52
|
+
};
|
|
53
|
+
cleanup = () => {
|
|
54
|
+
this.close();
|
|
55
|
+
this.removeAllListeners();
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=Connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AACrC,OAAO,EAAC,iBAAiB,EAAC,MAA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e,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IAED,IAAI,GAAG,CAAC,IAAqB,EAAE,GAAG,IAAW,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;IAEjF,IAAI,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE;QAChC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,MAAM,aAAa,CAAC,CAAA;QAC3E,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC3B,CAAC,CAAA;IAED,IAAI,GAAG,GAAG,EAAE;QACV,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;QAClB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;IAC7B,CAAC,CAAA;IAED,KAAK,GAAG,GAAG,EAAE;QACX,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACnB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;IAC5B,CAAC,CAAA;IAED,OAAO,GAAG,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,IAAI,CAAC,kBAAkB,EAAE,CAAA;IAC3B,CAAC,CAAA;CACF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ctx, sleep } from "@welshman/lib";
|
|
2
|
+
import { CLIENT_AUTH, createEvent } from "@welshman/util";
|
|
3
|
+
import { ConnectionEvent } from "./ConnectionEvent.js";
|
|
4
|
+
export var AuthMode;
|
|
5
|
+
(function (AuthMode) {
|
|
6
|
+
AuthMode["Implicit"] = "implicit";
|
|
7
|
+
AuthMode["Explicit"] = "explicit";
|
|
8
|
+
})(AuthMode || (AuthMode = {}));
|
|
9
|
+
export var AuthStatus;
|
|
10
|
+
(function (AuthStatus) {
|
|
11
|
+
AuthStatus["None"] = "none";
|
|
12
|
+
AuthStatus["Requested"] = "requested";
|
|
13
|
+
AuthStatus["PendingSignature"] = "pending_signature";
|
|
14
|
+
AuthStatus["DeniedSignature"] = "denied_signature";
|
|
15
|
+
AuthStatus["PendingResponse"] = "pending_response";
|
|
16
|
+
AuthStatus["Forbidden"] = "forbidden";
|
|
17
|
+
AuthStatus["Ok"] = "ok";
|
|
18
|
+
})(AuthStatus || (AuthStatus = {}));
|
|
19
|
+
const { None, Requested, PendingSignature, DeniedSignature, PendingResponse, Forbidden, Ok } = AuthStatus;
|
|
20
|
+
export class ConnectionAuth {
|
|
21
|
+
cxn;
|
|
22
|
+
challenge;
|
|
23
|
+
request;
|
|
24
|
+
message;
|
|
25
|
+
status = None;
|
|
26
|
+
constructor(cxn) {
|
|
27
|
+
this.cxn = cxn;
|
|
28
|
+
this.cxn.on(ConnectionEvent.Close, this.#onClose);
|
|
29
|
+
this.cxn.on(ConnectionEvent.Receive, this.#onReceive);
|
|
30
|
+
}
|
|
31
|
+
#onReceive = (cxn, [verb, ...extra]) => {
|
|
32
|
+
if (verb === "OK") {
|
|
33
|
+
const [id, ok, message] = extra;
|
|
34
|
+
if (id === this.request) {
|
|
35
|
+
this.message = message;
|
|
36
|
+
this.status = ok ? Ok : Forbidden;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (verb === "AUTH" && extra[0] !== this.challenge) {
|
|
40
|
+
this.challenge = extra[0];
|
|
41
|
+
this.request = undefined;
|
|
42
|
+
this.message = undefined;
|
|
43
|
+
this.status = Requested;
|
|
44
|
+
if (ctx.net.authMode === AuthMode.Implicit) {
|
|
45
|
+
this.respond();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
#onClose = (cxn) => {
|
|
50
|
+
this.challenge = undefined;
|
|
51
|
+
this.request = undefined;
|
|
52
|
+
this.message = undefined;
|
|
53
|
+
this.status = None;
|
|
54
|
+
};
|
|
55
|
+
waitFor = async (condition, timeout = 300) => {
|
|
56
|
+
const start = Date.now();
|
|
57
|
+
while (Date.now() - timeout <= start) {
|
|
58
|
+
await sleep(100);
|
|
59
|
+
if (condition()) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
waitForChallenge = async (timeout = 300) => this.waitFor(() => Boolean(this.challenge), timeout);
|
|
65
|
+
waitForResolution = async (timeout = 300) => this.waitFor(() => [None, DeniedSignature, Forbidden, Ok].includes(this.status), timeout);
|
|
66
|
+
respond = async () => {
|
|
67
|
+
if (!this.challenge) {
|
|
68
|
+
throw new Error("Attempted to authenticate with no challenge");
|
|
69
|
+
}
|
|
70
|
+
if (this.status !== Requested) {
|
|
71
|
+
throw new Error(`Attempted to authenticate when auth is already ${this.status}`);
|
|
72
|
+
}
|
|
73
|
+
this.status = PendingSignature;
|
|
74
|
+
const template = createEvent(CLIENT_AUTH, {
|
|
75
|
+
tags: [
|
|
76
|
+
["relay", this.cxn.url],
|
|
77
|
+
["challenge", this.challenge],
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
const [event] = await Promise.all([ctx.net.signEvent(template), this.cxn.socket.open()]);
|
|
81
|
+
if (event) {
|
|
82
|
+
this.request = event.id;
|
|
83
|
+
this.cxn.send(["AUTH", event]);
|
|
84
|
+
this.status = PendingResponse;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.status = DeniedSignature;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
attempt = async (timeout = 300) => {
|
|
91
|
+
await this.cxn.socket.open();
|
|
92
|
+
await this.waitForChallenge(timeout);
|
|
93
|
+
if (this.status === Requested) {
|
|
94
|
+
await this.respond();
|
|
95
|
+
}
|
|
96
|
+
await this.waitForResolution(timeout);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=ConnectionAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionAuth.js","sourceRoot":"","sources":["../../src/ConnectionAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,KAAK,EAAC,MAAM,eAAe,CAAA;AACxC,OAAO,EAAC,WAAW,EAAE,WAAW,EAAC,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAA;AAIpD,MAAM,CAAN,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,iCAAqB,CAAA;IACrB,iCAAqB,CAAA;AACvB,CAAC,EAHW,QAAQ,KAAR,QAAQ,QAGnB;AAED,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,qCAAuB,CAAA;IACvB,oDAAsC,CAAA;IACtC,kDAAoC,CAAA;IACpC,kDAAoC,CAAA;IACpC,qCAAuB,CAAA;IACvB,uBAAS,CAAA;AACX,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB;AAED,MAAM,EAAC,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,EAAC,GACxF,UAAU,CAAA;AAEZ,MAAM,OAAO,cAAc;IAMJ;IALrB,SAAS,CAAoB;IAC7B,OAAO,CAAoB;IAC3B,OAAO,CAAoB;IAC3B,MAAM,GAAG,IAAI,CAAA;IAEb,YAAqB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;QAClC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QACjD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;IACv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message } from
|
|
3
|
-
import type { Connection } from
|
|
1
|
+
import { Worker } from "@welshman/lib";
|
|
2
|
+
import type { Message } from "./Socket.js";
|
|
3
|
+
import type { Connection } from "./Connection.js";
|
|
4
4
|
export declare class ConnectionSender {
|
|
5
5
|
readonly cxn: Connection;
|
|
6
6
|
worker: Worker<Message>;
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
import { Worker } from
|
|
2
|
-
import { AUTH_JOIN } from
|
|
3
|
-
import { SocketStatus } from "./Socket.
|
|
4
|
-
import { AuthStatus } from "./ConnectionAuth.
|
|
1
|
+
import { Worker } from "@welshman/lib";
|
|
2
|
+
import { AUTH_JOIN } from "@welshman/util";
|
|
3
|
+
import { SocketStatus } from "./Socket.js";
|
|
4
|
+
import { AuthStatus } from "./ConnectionAuth.js";
|
|
5
5
|
export class ConnectionSender {
|
|
6
|
+
cxn;
|
|
7
|
+
worker;
|
|
6
8
|
constructor(cxn) {
|
|
7
9
|
this.cxn = cxn;
|
|
8
|
-
this.push = (message) => {
|
|
9
|
-
this.worker.push(message);
|
|
10
|
-
};
|
|
11
10
|
this.worker = new Worker({
|
|
12
11
|
shouldDefer: ([verb, ...extra]) => {
|
|
13
12
|
// Always send CLOSE to clean up pending requests, even if the connection is closed
|
|
14
|
-
if (verb ===
|
|
13
|
+
if (verb === "CLOSE")
|
|
15
14
|
return false;
|
|
16
15
|
// If we're not connected, nothing we can do
|
|
17
16
|
if (cxn.socket.status !== SocketStatus.Open)
|
|
18
17
|
return true;
|
|
19
18
|
// Always allow sending AUTH
|
|
20
|
-
if (verb ===
|
|
19
|
+
if (verb === "AUTH")
|
|
21
20
|
return false;
|
|
22
21
|
// Always allow sending join requests
|
|
23
|
-
if (verb ===
|
|
22
|
+
if (verb === "EVENT" && extra[0].kind === AUTH_JOIN)
|
|
24
23
|
return false;
|
|
25
24
|
// Wait for auth
|
|
26
25
|
if (![AuthStatus.None, AuthStatus.Ok].includes(cxn.auth.status))
|
|
27
26
|
return true;
|
|
28
27
|
// Limit concurrent requests
|
|
29
|
-
if (verb ===
|
|
28
|
+
if (verb === "REQ")
|
|
30
29
|
return cxn.state.pendingRequests.size >= 8;
|
|
31
30
|
return false;
|
|
32
31
|
},
|
|
33
32
|
});
|
|
34
33
|
this.worker.addGlobalHandler(([verb, ...extra]) => {
|
|
35
34
|
// If we ended up handling a CLOSE before we handled the REQ, don't send the REQ
|
|
36
|
-
if (verb ===
|
|
37
|
-
this.worker.buffer = this.worker.buffer.filter(m => !(m[0] ===
|
|
35
|
+
if (verb === "CLOSE") {
|
|
36
|
+
this.worker.buffer = this.worker.buffer.filter(m => !(m[0] === "REQ" && m[1] === extra[0]));
|
|
38
37
|
}
|
|
39
38
|
// Re-check socket status since we let CLOSE through
|
|
40
39
|
if (cxn.socket.status === SocketStatus.Open) {
|
|
@@ -42,5 +41,8 @@ export class ConnectionSender {
|
|
|
42
41
|
}
|
|
43
42
|
});
|
|
44
43
|
}
|
|
44
|
+
push = (message) => {
|
|
45
|
+
this.worker.push(message);
|
|
46
|
+
};
|
|
45
47
|
}
|
|
46
|
-
//# sourceMappingURL=ConnectionSender.
|
|
48
|
+
//# sourceMappingURL=ConnectionSender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionSender.js","sourceRoot":"","sources":["../../src/ConnectionSender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAA;AACpC,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAA;AAGxC,OAAO,EAAC,UAAU,EAAC,MAAM,qBAAqB,CAAA;AAE9C,MAAM,OAAO,gBAAgB;IAGN;IAFrB,MAAM,CAAiB;IAEvB,YAAqB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;QAClC,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC;YACvB,WAAW,EAAE,CAAC,CAAC,IAAI,EAA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K,YAAY,CAAC,IAAI,EAAE,CAAC;gBAC5C,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAA;YACnC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,GAAG,CAAC,OAAgB,EAAE,EAAE;QAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC3B,CAAC,CAAA;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SignedEvent, Filter } from
|
|
2
|
-
import type { Connection } from
|
|
1
|
+
import type { SignedEvent, Filter } from "@welshman/util";
|
|
2
|
+
import type { Connection } from "./Connection.js";
|
|
3
3
|
export type PublishState = {
|
|
4
4
|
sent: number;
|
|
5
5
|
event: SignedEvent;
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { sleep } from
|
|
2
|
-
import { AUTH_JOIN } from
|
|
3
|
-
import { ConnectionEvent } from "./ConnectionEvent.
|
|
1
|
+
import { sleep } from "@welshman/lib";
|
|
2
|
+
import { AUTH_JOIN } from "@welshman/util";
|
|
3
|
+
import { ConnectionEvent } from "./ConnectionEvent.js";
|
|
4
4
|
export class ConnectionState {
|
|
5
|
+
cxn;
|
|
6
|
+
pendingPublishes = new Map();
|
|
7
|
+
pendingRequests = new Map();
|
|
5
8
|
constructor(cxn) {
|
|
6
9
|
this.cxn = cxn;
|
|
7
|
-
this.pendingPublishes = new Map();
|
|
8
|
-
this.pendingRequests = new Map();
|
|
9
10
|
cxn.sender.worker.addGlobalHandler(([verb, ...extra]) => {
|
|
10
|
-
if (verb ===
|
|
11
|
+
if (verb === "REQ") {
|
|
11
12
|
const [reqId, ...filters] = extra;
|
|
12
13
|
this.pendingRequests.set(reqId, { filters, sent: Date.now() });
|
|
13
14
|
}
|
|
14
|
-
if (verb ===
|
|
15
|
+
if (verb === "CLOSE") {
|
|
15
16
|
const [reqId] = extra;
|
|
16
17
|
this.pendingRequests.delete(reqId);
|
|
17
18
|
}
|
|
18
|
-
if (verb ===
|
|
19
|
+
if (verb === "EVENT") {
|
|
19
20
|
const [event] = extra;
|
|
20
21
|
this.pendingPublishes.set(event.id, { sent: Date.now(), event });
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
cxn.socket.worker.addGlobalHandler(([verb, ...extra]) => {
|
|
24
|
-
|
|
25
|
-
if (verb === 'OK') {
|
|
25
|
+
if (verb === "OK") {
|
|
26
26
|
const [eventId, _ok, notice] = extra;
|
|
27
27
|
const pub = this.pendingPublishes.get(eventId);
|
|
28
28
|
if (!pub)
|
|
29
29
|
return;
|
|
30
30
|
// Re-enqueue pending events when auth challenge is received
|
|
31
|
-
if (
|
|
32
|
-
this.cxn.send([
|
|
31
|
+
if (notice?.startsWith("auth-required:") && pub.event.kind !== AUTH_JOIN) {
|
|
32
|
+
this.cxn.send(["EVENT", pub.event]);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
this.pendingPublishes.delete(eventId);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
if (verb ===
|
|
38
|
+
if (verb === "EOSE") {
|
|
39
39
|
const [reqId] = extra;
|
|
40
40
|
const req = this.pendingRequests.get(reqId);
|
|
41
41
|
if (req) {
|
|
42
42
|
req.eose = true;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
if (verb ===
|
|
45
|
+
if (verb === "CLOSED") {
|
|
46
46
|
const [reqId] = extra;
|
|
47
47
|
// Re-enqueue pending reqs when auth challenge is received
|
|
48
|
-
if (
|
|
48
|
+
if (extra[1]?.startsWith("auth-required:")) {
|
|
49
49
|
const req = this.pendingRequests.get(reqId);
|
|
50
50
|
if (req) {
|
|
51
|
-
this.cxn.send([
|
|
51
|
+
this.cxn.send(["REQ", reqId, ...req.filters]);
|
|
52
52
|
}
|
|
53
53
|
if (extra[1]) {
|
|
54
54
|
this.cxn.emit(ConnectionEvent.Notice, extra[1]);
|
|
@@ -56,7 +56,7 @@ export class ConnectionState {
|
|
|
56
56
|
}
|
|
57
57
|
this.pendingRequests.delete(reqId);
|
|
58
58
|
}
|
|
59
|
-
if (verb ===
|
|
59
|
+
if (verb === "NOTICE") {
|
|
60
60
|
const [notice] = extra;
|
|
61
61
|
this.cxn.emit(ConnectionEvent.Notice, notice);
|
|
62
62
|
}
|
|
@@ -64,17 +64,17 @@ export class ConnectionState {
|
|
|
64
64
|
// Whenever we reconnect, re-enqueue pending stuff. Delay this so that if a connection
|
|
65
65
|
// is flapping we're not sending too much noise.
|
|
66
66
|
cxn.on(ConnectionEvent.Close, async (cxn) => {
|
|
67
|
-
await sleep(
|
|
67
|
+
await sleep(10_000);
|
|
68
68
|
if (this.pendingRequests.size > 0 || this.pendingPublishes.size > 0) {
|
|
69
69
|
this.cxn.open();
|
|
70
70
|
}
|
|
71
71
|
for (const [reqId, req] of this.pendingRequests.entries()) {
|
|
72
|
-
this.cxn.send([
|
|
72
|
+
this.cxn.send(["REQ", reqId, ...req.filters]);
|
|
73
73
|
}
|
|
74
74
|
for (const [_, pub] of this.pendingPublishes.entries()) {
|
|
75
|
-
this.cxn.send([
|
|
75
|
+
this.cxn.send(["EVENT", pub.event]);
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
//# sourceMappingURL=ConnectionState.
|
|
80
|
+
//# sourceMappingURL=ConnectionState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionState.js","sourceRoot":"","sources":["../../src/ConnectionState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAA;AACnC,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAA;AAIxC,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAA;AAapD,MAAM,OAAO,eAAe;IAIL;IAHrB,gBAAgB,GAAG,IAAI,GAAG,EAAwB,CAAA;IAClD,eAAe,GAAG,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|
|
4
|
+
openCount = 0;
|
|
5
|
+
closeCount = 0;
|
|
6
|
+
errorCount = 0;
|
|
7
|
+
publishCount = 0;
|
|
8
|
+
requestCount = 0;
|
|
9
|
+
eventCount = 0;
|
|
10
|
+
lastOpen = 0;
|
|
11
|
+
lastClose = 0;
|
|
12
|
+
lastError = 0;
|
|
13
|
+
lastPublish = 0;
|
|
14
|
+
lastRequest = 0;
|
|
15
|
+
lastEvent = 0;
|
|
16
|
+
lastAuth = 0;
|
|
17
|
+
publishTimer = 0;
|
|
18
|
+
publishSuccessCount = 0;
|
|
19
|
+
publishFailureCount = 0;
|
|
20
|
+
eoseCount = 0;
|
|
21
|
+
eoseTimer = 0;
|
|
22
|
+
noticeCount = 0;
|
|
3
23
|
constructor(cxn) {
|
|
4
24
|
this.cxn = cxn;
|
|
5
|
-
this.openCount = 0;
|
|
6
|
-
this.closeCount = 0;
|
|
7
|
-
this.errorCount = 0;
|
|
8
|
-
this.publishCount = 0;
|
|
9
|
-
this.requestCount = 0;
|
|
10
|
-
this.eventCount = 0;
|
|
11
|
-
this.lastOpen = 0;
|
|
12
|
-
this.lastClose = 0;
|
|
13
|
-
this.lastError = 0;
|
|
14
|
-
this.lastPublish = 0;
|
|
15
|
-
this.lastRequest = 0;
|
|
16
|
-
this.lastEvent = 0;
|
|
17
|
-
this.lastAuth = 0;
|
|
18
|
-
this.publishTimer = 0;
|
|
19
|
-
this.publishSuccessCount = 0;
|
|
20
|
-
this.publishFailureCount = 0;
|
|
21
|
-
this.eoseCount = 0;
|
|
22
|
-
this.eoseTimer = 0;
|
|
23
|
-
this.noticeCount = 0;
|
|
24
|
-
this.getRequestSpeed = () => this.eoseCount ? this.eoseTimer / this.eoseCount : 0;
|
|
25
|
-
this.getPublishSpeed = () => this.publishSuccessCount ? this.publishTimer / this.publishSuccessCount : 0;
|
|
26
25
|
cxn.on(ConnectionEvent.Open, (cxn) => {
|
|
27
26
|
this.openCount++;
|
|
28
27
|
this.lastOpen = Date.now();
|
|
@@ -36,17 +35,17 @@ export class ConnectionStats {
|
|
|
36
35
|
this.lastError = Date.now();
|
|
37
36
|
});
|
|
38
37
|
cxn.on(ConnectionEvent.Send, (cxn, [verb]) => {
|
|
39
|
-
if (verb ===
|
|
38
|
+
if (verb === "REQ") {
|
|
40
39
|
this.requestCount++;
|
|
41
40
|
this.lastRequest = Date.now();
|
|
42
41
|
}
|
|
43
|
-
if (verb ===
|
|
42
|
+
if (verb === "EVENT") {
|
|
44
43
|
this.publishCount++;
|
|
45
44
|
this.lastPublish = Date.now();
|
|
46
45
|
}
|
|
47
46
|
});
|
|
48
47
|
cxn.on(ConnectionEvent.Receive, (cxn, [verb, ...extra]) => {
|
|
49
|
-
if (verb ===
|
|
48
|
+
if (verb === "OK") {
|
|
50
49
|
const pub = this.cxn.state.pendingPublishes.get(extra[0]);
|
|
51
50
|
if (pub) {
|
|
52
51
|
this.publishTimer += Date.now() - pub.sent;
|
|
@@ -58,14 +57,14 @@ export class ConnectionStats {
|
|
|
58
57
|
this.publishFailureCount++;
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
if (verb ===
|
|
60
|
+
if (verb === "AUTH") {
|
|
62
61
|
this.lastAuth = Date.now();
|
|
63
62
|
}
|
|
64
|
-
if (verb ===
|
|
63
|
+
if (verb === "EVENT") {
|
|
65
64
|
this.eventCount++;
|
|
66
65
|
this.lastEvent = Date.now();
|
|
67
66
|
}
|
|
68
|
-
if (verb ===
|
|
67
|
+
if (verb === "EOSE") {
|
|
69
68
|
const request = this.cxn.state.pendingRequests.get(extra[0]);
|
|
70
69
|
// Only count the first eose
|
|
71
70
|
if (request && !request.eose) {
|
|
@@ -73,10 +72,12 @@ export class ConnectionStats {
|
|
|
73
72
|
this.eoseTimer += Date.now() - request.sent;
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
|
-
if (verb ===
|
|
75
|
+
if (verb === "NOTICE") {
|
|
77
76
|
this.noticeCount++;
|
|
78
77
|
}
|
|
79
78
|
});
|
|
80
79
|
}
|
|
80
|
+
getRequestSpeed = () => (this.eoseCount ? this.eoseTimer / this.eoseCount : 0);
|
|
81
|
+
getPublishSpeed = () => this.publishSuccessCount ? this.publishTimer / this.publishSuccessCount : 0;
|
|
81
82
|
}
|
|
82
|
-
//# sourceMappingURL=ConnectionStats.
|
|
83
|
+
//# sourceMappingURL=ConnectionStats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionStats.js","sourceRoot":"","sources":["../../src/ConnectionStats.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAA;AAEpD,MAAM,OAAO,eAAe;IAqBL;IApBrB,SAAS,GAAG,CAAC,CAAA;IACb,UAAU,GAAG,CAAC,CAAA;IACd,UAAU,GAAG,CAAC,CAAA;IACd,YAAY,GAAG,CAAC,CAAA;IAChB,YAAY,GAAG,CAAC,CAAA;IAChB,UAAU,GAAG,CAAC,CAAA;IACd,QAAQ,GAAG,CAAC,CAAA;IACZ,SAAS,GAAG,CAAC,CAAA;IACb,SAAS,GAAG,CAAC,CAAA;IACb,WAAW,GAAG,CAAC,CAAA;IACf,WAAW,GAAG,CAAC,CAAA;IACf,SAAS,GAAG,CAAC,CAAA;IACb,QAAQ,GAAG,CAAC,CAAA;IACZ,YAAY,GAAG,CAAC,CAAA;IAChB,mBAAmB,GAAG,CAAC,CAAA;IACvB,mBAAmB,GAAG,CAAC,CAAA;IACvB,SAAS,GAAG,CAAC,CAAA;IACb,SAAS,GAAG,CAAC,CAAA;IACb,WAAW,GAAG,CAAC,CAAA;IAEf,YAAqB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;QAClC,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,GAAe,EAAE,EAAE;YAC/C,IAAI,CAAC,SAAS,EAAE,CAAA;YAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC5B,CAAC,CAAC,C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AAY,GAAG,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAA;CAC9E"}
|
package/build/src/Context.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { StampedEvent, SignedEvent, Filter, TrustedEvent } from
|
|
2
|
-
import { Pool } from "./Pool";
|
|
3
|
-
import { Executor } from "./Executor";
|
|
4
|
-
import { AuthMode } from "./ConnectionAuth";
|
|
5
|
-
import type { Subscription, RelaysAndFilters } from "./Subscribe";
|
|
1
|
+
import type { StampedEvent, SignedEvent, Filter, TrustedEvent } from "@welshman/util";
|
|
2
|
+
import { Pool } from "./Pool.js";
|
|
3
|
+
import { Executor } from "./Executor.js";
|
|
4
|
+
import { AuthMode } from "./ConnectionAuth.js";
|
|
5
|
+
import type { Subscription, RelaysAndFilters } from "./Subscribe.js";
|
|
6
6
|
export type NetContext = {
|
|
7
7
|
pool: Pool;
|
|
8
8
|
authMode: AuthMode;
|
|
@@ -23,8 +23,8 @@ export declare const isEventValid: (url: string, event: TrustedEvent) => boolean
|
|
|
23
23
|
export declare const getDefaultNetContext: (overrides?: Partial<NetContext>) => {
|
|
24
24
|
pool: Pool;
|
|
25
25
|
authMode: AuthMode;
|
|
26
|
-
onEvent: ((
|
|
27
|
-
signEvent: ((
|
|
26
|
+
onEvent: ((...args: unknown[]) => undefined) | ((url: string, event: TrustedEvent) => void);
|
|
27
|
+
signEvent: ((...args: unknown[]) => undefined) | ((event: StampedEvent) => Promise<SignedEvent | undefined>);
|
|
28
28
|
getExecutor: (relays: string[]) => Executor;
|
|
29
29
|
isDeleted: (url: string, event: TrustedEvent) => boolean;
|
|
30
30
|
isValid: (url: string, event: TrustedEvent) => boolean;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ctx, randomInt, uniq, noop, always } from
|
|
2
|
-
import { LOCAL_RELAY_URL, matchFilters, unionFilters, isSignedEvent, hasValidSignature } from
|
|
3
|
-
import { Pool } from "./Pool.
|
|
4
|
-
import { Executor } from "./Executor.
|
|
5
|
-
import { AuthMode } from "./ConnectionAuth.
|
|
6
|
-
import { Relays } from "./target/Relays.
|
|
7
|
-
export const defaultOptimizeSubscriptions = (subs) => uniq(subs.flatMap(sub => sub.request.relays || []))
|
|
8
|
-
.map(relay => {
|
|
1
|
+
import { ctx, randomInt, uniq, noop, always } from "@welshman/lib";
|
|
2
|
+
import { LOCAL_RELAY_URL, matchFilters, unionFilters, isSignedEvent, hasValidSignature, } from "@welshman/util";
|
|
3
|
+
import { Pool } from "./Pool.js";
|
|
4
|
+
import { Executor } from "./Executor.js";
|
|
5
|
+
import { AuthMode } from "./ConnectionAuth.js";
|
|
6
|
+
import { Relays } from "./target/Relays.js";
|
|
7
|
+
export const defaultOptimizeSubscriptions = (subs) => uniq(subs.flatMap(sub => sub.request.relays || [])).map(relay => {
|
|
9
8
|
const relaySubs = subs.filter(sub => sub.request.relays.includes(relay));
|
|
10
9
|
const filters = unionFilters(relaySubs.flatMap(sub => sub.request.filters));
|
|
11
10
|
return { relays: [relay], filters };
|
|
@@ -38,4 +37,4 @@ export const getDefaultNetContext = (overrides = {}) => ({
|
|
|
38
37
|
optimizeSubscriptions: defaultOptimizeSubscriptions,
|
|
39
38
|
...overrides,
|
|
40
39
|
});
|
|
41
|
-
//# sourceMappingURL=Context.
|
|
40
|
+
//# sourceMappingURL=Context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/Context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAC,MAAM,eAAe,CAAA;AAChE,OAAO,EACL,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,iBAAiB,GAClB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AAC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G,EAAE,CAAC;QACjC,qBAAqB,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9D,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAiC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5E,IAAI,EAAE,IAAI,IAAI,EAAE;IAChB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;IAC3B,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC;IACxB,OAAO,EAAE,YAAY;IACrB,WAAW,EAAE,CAAC,MAAgB,EAAE,EAAE,CAChC,IAAI,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClF,YAAY,EAAE,CAAC,GAAW,EAAE,OAAiB,EAAE,KAAmB,EAAE,EAAE,CACpE,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;IAC9B,qBAAqB,EAAE,4BAA4B;IACnD,GAAG,SAAS;CACb,CAAC,CAAA"}
|
package/build/src/Executor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Emitter } from
|
|
2
|
-
import type { SignedEvent, TrustedEvent, Filter } from
|
|
3
|
-
import type { Message } from
|
|
4
|
-
import type { Connection } from
|
|
1
|
+
import type { Emitter } from "@welshman/lib";
|
|
2
|
+
import type { SignedEvent, TrustedEvent, Filter } from "@welshman/util";
|
|
3
|
+
import type { Message } from "./Socket.js";
|
|
4
|
+
import type { Connection } from "./Connection.js";
|
|
5
5
|
export type Target = Emitter & {
|
|
6
6
|
connections: Connection[];
|
|
7
7
|
send: (...args: Message) => Promise<void>;
|
|
@@ -16,10 +16,11 @@ type EoseCallback = (url: string) => void;
|
|
|
16
16
|
type CloseCallback = () => void;
|
|
17
17
|
type OkCallback = (url: string, id: string, ...extra: any[]) => void;
|
|
18
18
|
type ErrorCallback = (url: string, id: string, ...extra: any[]) => void;
|
|
19
|
-
type
|
|
19
|
+
type DiffMessage = {
|
|
20
20
|
have: string[];
|
|
21
21
|
need: string[];
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
|
+
type DiffMessageCallback = (url: string, { have, need }: DiffMessage) => void;
|
|
23
24
|
type SubscribeOpts = {
|
|
24
25
|
onEvent?: EventCallback;
|
|
25
26
|
onEose?: EoseCallback;
|