Skip to content

Commit d107589

Browse files
committed
lintfix
1 parent 27010f9 commit d107589

9 files changed

+63
-87
lines changed

src/WebSocketClient.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import type {
2-
Host,
32
Port,
4-
TLSVerifyCallback,
53
WebSocketClientConfigInput,
6-
WebSocketConfig,
74
} from './types';
85
import type { ContextTimed, ContextTimedInput } from '@matrixai/contexts';
96
import { AbstractEvent } from '@matrixai/events';
107
import { createDestroy } from '@matrixai/async-init';
118
import Logger from '@matrixai/logger';
129
import WebSocket from 'ws';
1310
import { Validator } from 'ip-num';
14-
import { EventAll, EventDefault } from '@matrixai/events';
11+
import { EventAll } from '@matrixai/events';
1512
import { context, timedCancellable } from '@matrixai/contexts/dist/decorators';
1613
import * as errors from './errors';
1714
import WebSocketConnection from './WebSocketConnection';

src/WebSocketConnection.ts

Lines changed: 38 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ import type {
44
ConnectionMetadata,
55
Host,
66
Port,
7-
RemoteInfo,
87
StreamCodeToReason,
98
StreamReasonToCode,
109
WebSocketConfig,
1110
} from './types';
12-
import type { DetailedPeerCertificate, TLSSocket } from 'tls';
11+
import type { TLSSocket } from 'tls';
1312
import type { StreamId } from './message';
1413
import { startStop } from '@matrixai/async-init';
1514
import { Lock } from '@matrixai/async-locks';
1615
import { context, timedCancellable } from '@matrixai/contexts/dist/decorators';
1716
import Logger from '@matrixai/logger';
1817
import * as ws from 'ws';
1918
import { Timer } from '@matrixai/timer';
20-
import { AbstractEvent, EventAll, EventDefault } from '@matrixai/events';
19+
import { AbstractEvent, EventAll } from '@matrixai/events';
2120
import { concatUInt8Array } from './message';
2221
import WebSocketStream from './WebSocketStream';
2322
import * as errors from './errors';
@@ -223,16 +222,13 @@ class WebSocketConnection {
223222
const reason = "WebSocket received data received that wasn't binary";
224223
this.dispatchEvent(
225224
new events.EventWebSocketConnectionError({
226-
detail: new errors.ErrorWebSocketConnectionLocal(
227-
reason,
228-
{
229-
cause: new errors.ErrorWebSocketUndefinedBehaviour(),
230-
data: {
231-
errorCode: utils.ConnectionErrorCode.InternalServerError,
232-
reason
233-
}
225+
detail: new errors.ErrorWebSocketConnectionLocal(reason, {
226+
cause: new errors.ErrorWebSocketUndefinedBehaviour(),
227+
data: {
228+
errorCode: utils.ConnectionErrorCode.InternalServerError,
229+
reason,
234230
},
235-
),
231+
}),
236232
}),
237233
);
238234
return;
@@ -248,19 +244,16 @@ class WebSocketConnection {
248244
remainder = postStreamIdRemainder;
249245
} catch (e) {
250246
// TODO: domain specific error
251-
const reason = "Parsing streamId failed"
247+
const reason = 'Parsing streamId failed';
252248
this.dispatchEvent(
253249
new events.EventWebSocketConnectionError({
254-
detail: new errors.ErrorWebSocketConnectionLocal(
255-
reason,
256-
{
257-
cause: e,
258-
data: {
259-
errorCode: utils.ConnectionErrorCode.InternalServerError,
260-
reason
261-
}
250+
detail: new errors.ErrorWebSocketConnectionLocal(reason, {
251+
cause: e,
252+
data: {
253+
errorCode: utils.ConnectionErrorCode.InternalServerError,
254+
reason,
262255
},
263-
),
256+
}),
264257
}),
265258
);
266259
return;
@@ -518,53 +511,45 @@ class WebSocketConnection {
518511
let reason: string;
519512
let errorCode: number;
520513
switch (e.code) {
521-
case "UNABLE_TO_VERIFY_LEAF_SIGNATURE":
514+
case 'UNABLE_TO_VERIFY_LEAF_SIGNATURE':
522515
errorCode = utils.ConnectionErrorCode.TLSHandshake;
523-
reason = 'WebSocket could not open due to failure to verify a peer\'s TLS certificate';
524-
e_ = new errors.ErrorWebSocketConnectionLocalTLS(
525-
reason,
526-
{
527-
cause: e,
528-
data: {
529-
errorCode,
530-
reason,
531-
}
532-
}
533-
);
516+
reason =
517+
"WebSocket could not open due to failure to verify a peer's TLS certificate";
518+
e_ = new errors.ErrorWebSocketConnectionLocalTLS(reason, {
519+
cause: e,
520+
data: {
521+
errorCode,
522+
reason,
523+
},
524+
});
534525
break;
535-
case "ECONNRESET":
526+
case 'ECONNRESET':
536527
reason = 'WebSocket could not open due to socket closure by peer';
537-
errorCode = utils.ConnectionErrorCode.AbnormalClosure,
538-
e_ = new errors.ErrorWebSocketConnectionPeer(
539-
reason,
540-
{
528+
(errorCode = utils.ConnectionErrorCode.AbnormalClosure),
529+
(e_ = new errors.ErrorWebSocketConnectionPeer(reason, {
541530
cause: e,
542531
data: {
543532
errorCode,
544-
reason
545-
}
546-
}
547-
);
533+
reason,
534+
},
535+
}));
548536
break;
549537
default:
550538
reason = 'WebSocket could not open due to internal error';
551-
errorCode = utils.ConnectionErrorCode.InternalServerError,
552-
e_ = new errors.ErrorWebSocketConnectionLocal(
553-
reason,
554-
{
539+
(errorCode = utils.ConnectionErrorCode.InternalServerError),
540+
(e_ = new errors.ErrorWebSocketConnectionLocal(reason, {
555541
cause: e,
556542
data: {
557543
errorCode,
558-
reason
559-
}
560-
}
561-
);
544+
reason,
545+
},
546+
}));
562547
break;
563548
}
564549
this.closeSocket(errorCode, reason);
565550
this.dispatchEvent(
566551
new events.EventWebSocketConnectionError({
567-
detail: e_
552+
detail: e_,
568553
}),
569554
);
570555
};
@@ -600,7 +585,7 @@ class WebSocketConnection {
600585
const errorCode = utils.ConnectionErrorCode.TLSHandshake;
601586
const reason =
602587
'Failed connection due to custom verification callback';
603-
// request.destroy() will make the socket dispatch a 'close' event,
588+
// Request.destroy() will make the socket dispatch a 'close' event,
604589
// so I'm setting socketLocallyClosed to true, as that is what is happening.
605590
this.socketLocallyClosed = true;
606591
request.destroy(e);

src/WebSocketServer.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@ import type tls from 'tls';
33
import type {
44
Host,
55
Port,
6-
PromiseDeconstructed,
76
StreamCodeToReason,
87
StreamReasonToCode,
98
WebSocketConfig,
109
WebSocketServerConfigInput,
1110
} from './types';
1211
import type { EventAll } from '@matrixai/events';
13-
import type { DetailedPeerCertificate, TLSSocket } from 'tls';
12+
import type { TLSSocket } from 'tls';
1413
import https from 'https';
1514
import { AbstractEvent } from '@matrixai/events';
16-
import {
17-
StartStop,
18-
status,
19-
running,
20-
ready,
21-
} from '@matrixai/async-init/dist/StartStop';
15+
import { StartStop, running, ready } from '@matrixai/async-init/dist/StartStop';
2216
import Logger from '@matrixai/logger';
2317
import * as ws from 'ws';
24-
import { EventDefault } from '@matrixai/events';
2518
import * as errors from './errors';
2619
import * as events from './events';
2720
import * as utils from './utils';

src/WebSocketStream.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
ready,
2121
running,
2222
status,
23-
initLock,
2423
} from '@matrixai/async-init/dist/StartStop';
2524
import Logger from '@matrixai/logger';
2625
import { generateStreamId } from './message';

src/errors.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { AbstractError, POJO } from '@matrixai/errors';
2-
import { ConnectionError } from './types';
1+
import type { POJO } from '@matrixai/errors';
2+
import type { ConnectionError } from './types';
3+
import { AbstractError } from '@matrixai/errors';
34

45
class ErrorWebSocket<T> extends AbstractError<T> {
56
static description = 'WebSocket error';
@@ -84,13 +85,15 @@ class ErrorWebSocketConnectionLocal<T> extends ErrorWebSocketConnection<T> {
8485
timestamp?: Date;
8586
data: POJO & ConnectionError;
8687
cause?: T;
87-
}
88+
},
8889
) {
8990
super(message, options);
9091
}
9192
}
9293

93-
class ErrorWebSocketConnectionLocalTLS<T> extends ErrorWebSocketConnectionLocal<T> {
94+
class ErrorWebSocketConnectionLocalTLS<
95+
T,
96+
> extends ErrorWebSocketConnectionLocal<T> {
9497
static description = 'WebSocket Connection local TLS error';
9598
}
9699

@@ -103,7 +106,7 @@ class ErrorWebSocketConnectionPeer<T> extends ErrorWebSocketConnection<T> {
103106
timestamp?: Date;
104107
data: POJO & ConnectionError;
105108
cause?: T;
106-
}
109+
},
107110
) {
108111
super(message, options);
109112
}

src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { DetailedPeerCertificate } from 'tls';
2-
31
// Async
42

53
/**
@@ -185,5 +183,5 @@ export type {
185183
WebSocketClientConfigInput,
186184
WebSocketServerConfigInput,
187185
Parsed,
188-
ConnectionError
186+
ConnectionError,
189187
};

tests/WebSocket.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { X509Certificate } from '@peculiar/x509';
21
import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger';
32
import { status } from '@matrixai/async-init';
43
import * as events from '@/events';
54
import WebSocketClient from '@/WebSocketClient';
65
import WebSocketServer from '@/WebSocketServer';
76
import * as utils from '@/utils';
8-
import * as errors from '@/errors';
97
import * as testsUtils from './utils';
108

119
// Process.on('unhandledRejection', (reason) => {

tests/WebSocketClient.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import type { KeyTypes } from './utils';
22
import type WebSocketConnection from '@/WebSocketConnection';
3-
import { DetailedPeerCertificate } from 'tls';
43
import Logger, { formatting, LogLevel, StreamHandler } from '@matrixai/logger';
5-
import { X509Certificate } from '@peculiar/x509';
6-
import { fc, testProp } from '@fast-check/jest';
7-
import { promise, pemToDER, ConnectionErrorCode } from '@/utils';
4+
import { promise, pemToDER } from '@/utils';
85
import * as events from '@/events';
96
import * as errors from '@/errors';
107
import WebSocketClient from '@/WebSocketClient';
@@ -393,7 +390,10 @@ describe(WebSocketClient.name, () => {
393390
verifyPeer: true,
394391
},
395392
}),
396-
).rejects.toHaveProperty('name', errors.ErrorWebSocketConnectionLocalTLS.name);
393+
).rejects.toHaveProperty(
394+
'name',
395+
errors.ErrorWebSocketConnectionLocalTLS.name,
396+
);
397397
await server.stop();
398398
});
399399
test('graceful failure verifying client', async () => {
@@ -422,7 +422,10 @@ describe(WebSocketClient.name, () => {
422422
verifyPeer: false,
423423
},
424424
}),
425-
).rejects.toHaveProperty('name', errors.ErrorWebSocketConnectionPeer.name);
425+
).rejects.toHaveProperty(
426+
'name',
427+
errors.ErrorWebSocketConnectionPeer.name,
428+
);
426429

427430
await server.stop();
428431
});
@@ -440,7 +443,6 @@ describe(WebSocketClient.name, () => {
440443
await server.start({
441444
host: localhost,
442445
});
443-
server.addEventListener(errors.ErrorWebSocketConnectionLocalTLS.name, (e) => console.log(e))
444446
// Connection should fail
445447
await expect(
446448
WebSocketClient.createWebSocketClient({
@@ -453,7 +455,10 @@ describe(WebSocketClient.name, () => {
453455
verifyPeer: true,
454456
},
455457
}),
456-
).rejects.toHaveProperty('name', errors.ErrorWebSocketConnectionLocalTLS.name);
458+
).rejects.toHaveProperty(
459+
'name',
460+
errors.ErrorWebSocketConnectionLocalTLS.name,
461+
);
457462

458463
await server.stop();
459464
});

tests/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import type { X509Certificate } from '@peculiar/x509';
2-
import type WebSocketClient from '@/WebSocketClient';
3-
import type WebSocketServer from '@/WebSocketServer';
42
import type WebSocketStream from '@/WebSocketStream';
53
import type { StreamCodeToReason, StreamReasonToCode } from '@/types';
64
import * as peculiarWebcrypto from '@peculiar/webcrypto';

0 commit comments

Comments
 (0)