Skip to content

Commit d23b6e4

Browse files
committed
refactor: enable erasableSyntaxOnly
1 parent 2cad948 commit d23b6e4

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

src/fast-tracker.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class FastTracker<ConnectionContext extends Record<string, unknown>>
4646
implements Tracker<ConnectionContext>
4747
{
4848
public readonly settings: FastTrackerSettings;
49+
#sendMessage: (json: UnknownObject, connection: ConnectionContext) => void;
4950

5051
readonly #swarms = new Map<string, Swarm<ConnectionContext>>();
5152
public get swarms() {
@@ -83,11 +84,9 @@ export class FastTracker<ConnectionContext extends Record<string, unknown>>
8384

8485
public constructor(
8586
settings: Partial<FastTrackerSettings> | undefined,
86-
private sendMessage: (
87-
json: UnknownObject,
88-
connection: ConnectionContext,
89-
) => void,
87+
sendMessage: (json: UnknownObject, connection: ConnectionContext) => void,
9088
) {
89+
this.#sendMessage = sendMessage;
9190
this.settings = {
9291
maxOffers: 20,
9392
announceInterval: 20,
@@ -319,7 +318,7 @@ export class FastTracker<ConnectionContext extends Record<string, unknown>>
319318

320319
const complete = swarm.completedPeers?.size ?? 0;
321320

322-
this.sendMessage(
321+
this.#sendMessage(
323322
{
324323
action: "announce",
325324
interval: this.settings.announceInterval,
@@ -368,7 +367,7 @@ export class FastTracker<ConnectionContext extends Record<string, unknown>>
368367
const offersIterator = offers.values();
369368
for (const toPeer of peers) {
370369
if (toPeer !== peer) {
371-
this.sendMessage(
370+
this.#sendMessage(
372371
getSendOfferJson(
373372
offersIterator.next().value,
374373
peer.peerId,
@@ -388,7 +387,7 @@ export class FastTracker<ConnectionContext extends Record<string, unknown>>
388387
if (toPeer === peer) {
389388
i--; // do one more iteration
390389
} else {
391-
this.sendMessage(
390+
this.#sendMessage(
392391
getSendOfferJson(offers[i], peer.peerId, infoHash),
393392
toPeer.connection,
394393
);
@@ -417,7 +416,7 @@ export class FastTracker<ConnectionContext extends Record<string, unknown>>
417416
}
418417

419418
delete json.to_peer_id;
420-
this.sendMessage(json, toPeer.connection);
419+
this.#sendMessage(json, toPeer.connection);
421420

422421
if (debugEnabled) {
423422
debug(
@@ -505,7 +504,7 @@ export class FastTracker<ConnectionContext extends Record<string, unknown>>
505504
}
506505
}
507506

508-
this.sendMessage({ action: "scrape", files }, connection);
507+
this.#sendMessage({ action: "scrape", files }, connection);
509508
}
510509

511510
public dispose() {

src/multi-worker-tracker/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,27 @@ export class MultiWorkerTracker<
3535
this.#onRemovePeer = callback ?? undefined;
3636
}
3737

38+
#workerPorts: MessagePort[];
39+
#sendMessage: (
40+
json: Record<string, unknown>,
41+
connection: ConnectionContext,
42+
) => void;
43+
3844
constructor(
39-
private workerPorts: MessagePort[],
40-
private sendMessage: (
45+
workerPorts: MessagePort[],
46+
sendMessage: (
4147
json: Record<string, unknown>,
4248
connection: ConnectionContext,
4349
) => void,
44-
) {}
50+
) {
51+
this.#workerPorts = workerPorts;
52+
this.#sendMessage = sendMessage;
53+
}
4554

4655
async getSwarms() {
4756
const swarms = [];
4857

49-
for (const workerPort of this.workerPorts) {
58+
for (const workerPort of this.#workerPorts) {
5059
const stats = await new Promise<TrackerWorkerOutEvent>((resolve) => {
5160
const requestId = Math.random();
5261

@@ -94,9 +103,9 @@ export class MultiWorkerTracker<
94103
infoHash.charCodeAt(1) +
95104
infoHash.charCodeAt(2) +
96105
infoHash.charCodeAt(3)) %
97-
this.workerPorts.length;
106+
this.#workerPorts.length;
98107

99-
const workerPort = this.workerPorts[workerIndex];
108+
const workerPort = this.#workerPorts[workerIndex];
100109

101110
let peer = connection[peerId] as
102111
| PeerPortWithConnection<ConnectionContext>
@@ -155,7 +164,7 @@ export class MultiWorkerTracker<
155164
// json.event,
156165
// );
157166

158-
this.sendMessage(json, peerPort.connection);
167+
this.#sendMessage(json, peerPort.connection);
159168
};
160169

161170
processPeerPortClose = (event: Event) => {

src/uws-tracker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface PartialUwsTrackerSettings {
6464

6565
export class UWebSocketsTracker {
6666
public readonly settings: UwsTrackerSettings;
67+
public readonly tracker: Readonly<Tracker<UwsConnectionContext>>;
6768

6869
private webSocketsCount = 0;
6970
private validateOrigin = false;
@@ -72,9 +73,10 @@ export class UWebSocketsTracker {
7273
readonly #app: TemplatedApp;
7374

7475
public constructor(
75-
public readonly tracker: Readonly<Tracker<UwsConnectionContext>>,
76+
tracker: Readonly<Tracker<UwsConnectionContext>>,
7677
settings: PartialUwsTrackerSettings,
7778
) {
79+
this.tracker = tracker;
7880
this.settings = {
7981
server: {
8082
port: 8000,

tsconfig.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2020",
3+
"target": "ESnext",
44
"module": "NodeNext",
5-
"lib": ["ES2020"],
5+
"lib": ["ES2024"],
66
"moduleResolution": "NodeNext",
7-
"declaration": true,
7+
"types": ["node"],
8+
9+
"skipLibCheck": true,
10+
"resolveJsonModule": true,
11+
"isolatedModules": true,
12+
"esModuleInterop": true,
13+
814
"outDir": "./lib",
15+
916
"strict": true,
17+
"noImplicitAny": true,
1018
"noUnusedLocals": true,
1119
"noUnusedParameters": false,
12-
"forceConsistentCasingInFileNames": true,
1320
"noFallthroughCasesInSwitch": true,
21+
"erasableSyntaxOnly": true,
22+
"noUncheckedSideEffectImports": true,
23+
"useDefineForClassFields": true,
24+
"forceConsistentCasingInFileNames": true,
1425
"noImplicitReturns": true,
15-
"types": ["node"]
26+
27+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.tsbuildinfo"
1628
},
1729
"compileOnSave": true,
1830
"include": ["src/**/*"]

0 commit comments

Comments
 (0)