Skip to content

Commit 15300ed

Browse files
committed
fix: fixing usage of Host and Port types to be internal
[ci skip]
1 parent d7fb531 commit 15300ed

42 files changed

Lines changed: 229 additions & 257 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/PolykeyAgent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,8 @@ class PolykeyAgent {
970970
nodeId: this.keyRing.getNodeId(),
971971
clientHost: this.webSocketServerClient.getHost(),
972972
clientPort: this.webSocketServerClient.getPort(),
973-
agentHost: this.quicSocket.host as Host,
974-
agentPort: this.quicSocket.port as Port,
973+
agentHost: this.quicSocket.host,
974+
agentPort: this.quicSocket.port,
975975
});
976976
this.logger.info(`Started ${this.constructor.name}`);
977977
} catch (e) {

src/bin/utils/processors.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { FileSystem } from '../../types';
22
import type { RecoveryCode } from '../../keys/types';
33
import type { NodeId } from '../../ids/types';
4-
import type { Host, Port } from '../../network/types';
54
import type {
65
StatusStarting,
76
StatusLive,
@@ -203,14 +202,14 @@ async function processRecoveryCode(
203202
async function processClientOptions(
204203
nodePath: string,
205204
nodeId?: NodeId,
206-
clientHost?: Host,
207-
clientPort?: Port,
205+
clientHost?: string,
206+
clientPort?: number,
208207
fs = require('fs'),
209208
logger = new Logger(processClientOptions.name),
210209
): Promise<{
211210
nodeId: NodeId;
212-
clientHost: Host;
213-
clientPort: Port;
211+
clientHost: string;
212+
clientPort: number;
214213
}> {
215214
if (nodeId != null && clientHost != null && clientPort != null) {
216215
return {
@@ -266,31 +265,31 @@ async function processClientOptions(
266265
async function processClientStatus(
267266
nodePath: string,
268267
nodeId?: NodeId,
269-
clientHost?: Host,
270-
clientPort?: Port,
268+
clientHost?: string,
269+
clientPort?: number,
271270
fs = require('fs'),
272271
logger = new Logger(processClientStatus.name),
273272
): Promise<
274273
| {
275274
statusInfo: StatusStarting | StatusStopping | StatusDead;
276275
status: Status;
277276
nodeId: NodeId | undefined;
278-
clientHost: Host | undefined;
279-
clientPort: Port | undefined;
277+
clientHost: string | undefined;
278+
clientPort: number | undefined;
280279
}
281280
| {
282281
statusInfo: StatusLive;
283282
status: Status;
284283
nodeId: NodeId;
285-
clientHost: Host;
286-
clientPort: Port;
284+
clientHost: string;
285+
clientPort: number;
287286
}
288287
| {
289288
statusInfo: undefined;
290289
status: undefined;
291290
nodeId: NodeId;
292-
clientHost: Host;
293-
clientPort: Port;
291+
clientHost: string;
292+
clientPort: number;
294293
}
295294
> {
296295
if (nodeId != null && clientHost != null && clientPort != null) {

src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ const config = {
9191
},
9292
networkConfig: {
9393
// Config for the QUICSocket
94-
agentHost: '127.0.0.1' as Host,
95-
agentPort: 0 as Port,
94+
agentHost: '127.0.0.1',
95+
agentPort: 0,
9696
ipv6Only: false,
9797
// Config for the websocket server
98-
clientHost: '127.0.0.1' as Host,
99-
clientPort: 0 as Port,
98+
clientHost: '127.0.0.1',
99+
clientPort: 0,
100100
// Websocket server config
101101
maxReadableStreamBytes: 1_000_000_000, // About 1 GB
102102
connectionIdleTimeoutTime: 120, // 2 minutes

src/websockets/WebSocketServer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
WebSocket,
1010
} from 'uWebSockets.js';
1111
import type { FileSystem, JSONValue, PromiseDeconstructed } from '../types';
12-
import type { Host, Port, TLSConfig } from '../network/types';
12+
import type { TLSConfig } from '../network/types';
1313
import { WritableStream, ReadableStream } from 'stream/web';
1414
import path from 'path';
1515
import os from 'os';
@@ -233,13 +233,13 @@ class WebSocketServer extends EventTarget {
233233
}
234234

235235
@startStop.ready(new webSocketErrors.ErrorWebSocketServerNotRunning())
236-
public getPort(): Port {
237-
return this._port as Port;
236+
public getPort(): number {
237+
return this._port;
238238
}
239239

240240
@startStop.ready(new webSocketErrors.ErrorWebSocketServerNotRunning())
241-
public getHost(): Host {
242-
return this._host as Host;
241+
public getHost(): string {
242+
return this._host;
243243
}
244244

245245
/**

tests/PolykeyClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('PolykeyClient', () => {
6060
fs,
6161
logger,
6262
fresh: true,
63-
rpcClientClient: {},
63+
rpcClientClient: {} as any,
6464
});
6565
expect(await session.readToken()).toBeUndefined();
6666
await session.writeToken('abc' as SessionToken);

tests/bin/agent/start.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -876,11 +876,11 @@ describe('start', () => {
876876
let agent2Status: StatusLive;
877877
let agent2Close: () => Promise<void>;
878878
let seedNodeId1: NodeId;
879-
let seedNodeHost1: Host;
880-
let seedNodePort1: Port;
879+
let seedNodeHost1: string;
880+
let seedNodePort1: number;
881881
let seedNodeId2: NodeId;
882-
let seedNodeHost2: Host;
883-
let seedNodePort2: Port;
882+
let seedNodeHost2: string;
883+
let seedNodePort2: number;
884884
beforeEach(async () => {
885885
// Additional seed node
886886
agentDataDir = await fs.promises.mkdtemp(
@@ -926,8 +926,8 @@ describe('start', () => {
926926
.mockValue({
927927
mainnet: {
928928
[seedNodeId2]: {
929-
host: seedNodeHost2,
930-
port: seedNodePort2,
929+
host: seedNodeHost2 as Host,
930+
port: seedNodePort2 as Port,
931931
},
932932
},
933933
testnet: {},
@@ -994,8 +994,8 @@ describe('start', () => {
994994
mainnet: {},
995995
testnet: {
996996
[seedNodeId2]: {
997-
host: seedNodeHost2,
998-
port: seedNodePort2,
997+
host: seedNodeHost2 as Host,
998+
port: seedNodePort2 as Port,
999999
},
10001000
},
10011001
});

tests/bin/identities/allowDisallowPermissions.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Host, Port } from '@/network/types';
21
import type { IdentityId, ProviderId } from '@/identities/types';
32
import type { NodeId } from '@/ids/types';
43
import type { ClaimLinkIdentity } from '@/claims/payloads/index';
@@ -37,8 +36,8 @@ describe('allow/disallow/permissions', () => {
3736
let pkAgent: PolykeyAgent;
3837
let node: PolykeyAgent;
3938
let nodeId: NodeId;
40-
let nodeHost: Host;
41-
let nodePort: Port;
39+
let nodeHost: string;
40+
let nodePort: number;
4241
beforeEach(async () => {
4342
dataDir = await fs.promises.mkdtemp(
4443
path.join(globalThis.tmpDir, 'polykey-test-'),
@@ -48,8 +47,8 @@ describe('allow/disallow/permissions', () => {
4847
password,
4948
nodePath,
5049
networkConfig: {
51-
agentHost: '127.0.0.1' as Host,
52-
clientHost: '127.0.0.1' as Host,
50+
agentHost: '127.0.0.1',
51+
clientHost: '127.0.0.1',
5352
},
5453
logger,
5554
keyRingConfig: {
@@ -65,8 +64,8 @@ describe('allow/disallow/permissions', () => {
6564
password,
6665
nodePath: nodePathGestalt,
6766
networkConfig: {
68-
agentHost: '127.0.0.1' as Host,
69-
clientHost: '127.0.0.1' as Host,
67+
agentHost: '127.0.0.1',
68+
clientHost: '127.0.0.1',
7069
},
7170
logger,
7271
keyRingConfig: {
@@ -76,8 +75,8 @@ describe('allow/disallow/permissions', () => {
7675
},
7776
});
7877
nodeId = node.keyRing.getNodeId();
79-
nodeHost = node.quicServerAgent.host as Host;
80-
nodePort = node.quicServerAgent.port as Port;
78+
nodeHost = node.quicServerAgent.host;
79+
nodePort = node.quicServerAgent.port;
8180
node.identitiesManager.registerProvider(provider);
8281
await node.identitiesManager.putToken(provider.id, identity, {
8382
accessToken: 'def456',

tests/bin/identities/authenticateAuthenticated.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { IdentityId, ProviderId } from '@/identities/types';
2-
import type { Host } from '@/network/types';
32
import path from 'path';
43
import fs from 'fs';
54
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
@@ -38,8 +37,8 @@ describe('authenticate/authenticated', () => {
3837
password,
3938
nodePath,
4039
networkConfig: {
41-
agentHost: '127.0.0.1' as Host,
42-
clientHost: '127.0.0.1' as Host,
40+
agentHost: '127.0.0.1',
41+
clientHost: '127.0.0.1',
4342
},
4443
logger,
4544
keyRingConfig: {

tests/bin/identities/claim.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
ProviderId,
44
ProviderIdentityClaimId,
55
} from '@/identities/types';
6-
import type { Host } from '@/network/types';
76
import path from 'path';
87
import fs from 'fs';
98
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
@@ -40,8 +39,8 @@ describe('claim', () => {
4039
password,
4140
nodePath,
4241
networkConfig: {
43-
agentHost: '127.0.0.1' as Host,
44-
clientHost: '127.0.0.1' as Host,
42+
agentHost: '127.0.0.1',
43+
clientHost: '127.0.0.1',
4544
},
4645
logger,
4746
keyRingConfig: {

tests/bin/identities/discoverGet.test.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { IdentityId, ProviderId } from '@/identities/types';
2-
import type { Host, Port } from '@/network/types';
32
import type { NodeId } from '@/ids/types';
43
import type { ClaimLinkIdentity } from '@/claims/payloads/index';
54
import type { SignedClaim } from '@/claims/types';
@@ -34,8 +33,8 @@ describe('discover/get', () => {
3433
let nodeB: PolykeyAgent;
3534
let nodeAId: NodeId;
3635
let nodeBId: NodeId;
37-
let nodeAHost: Host;
38-
let nodeAPort: Port;
36+
let nodeAHost: string;
37+
let nodeAPort: number;
3938
beforeEach(async () => {
4039
dataDir = await fs.promises.mkdtemp(
4140
path.join(globalThis.tmpDir, 'polykey-test-'),
@@ -46,8 +45,8 @@ describe('discover/get', () => {
4645
password,
4746
nodePath: path.join(dataDir, 'nodeA'),
4847
networkConfig: {
49-
agentHost: '127.0.0.1' as Host,
50-
clientHost: '127.0.0.1' as Host,
48+
agentHost: '127.0.0.1',
49+
clientHost: '127.0.0.1',
5150
},
5251
logger,
5352
keyRingConfig: {
@@ -57,14 +56,14 @@ describe('discover/get', () => {
5756
},
5857
});
5958
nodeAId = nodeA.keyRing.getNodeId();
60-
nodeAHost = nodeA.quicServerAgent.host as Host;
61-
nodeAPort = nodeA.quicServerAgent.port as Port;
59+
nodeAHost = nodeA.quicServerAgent.host;
60+
nodeAPort = nodeA.quicServerAgent.port;
6261
nodeB = await PolykeyAgent.createPolykeyAgent({
6362
password,
6463
nodePath: path.join(dataDir, 'nodeB'),
6564
networkConfig: {
66-
agentHost: '127.0.0.1' as Host,
67-
clientHost: '127.0.0.1' as Host,
65+
agentHost: '127.0.0.1',
66+
clientHost: '127.0.0.1',
6867
},
6968
logger,
7069
keyRingConfig: {
@@ -81,8 +80,8 @@ describe('discover/get', () => {
8180
password,
8281
nodePath,
8382
networkConfig: {
84-
agentHost: '127.0.0.1' as Host,
85-
clientHost: '127.0.0.1' as Host,
83+
agentHost: '127.0.0.1',
84+
clientHost: '127.0.0.1',
8685
},
8786
logger,
8887
keyRingConfig: {

0 commit comments

Comments
 (0)