Skip to content

Commit 72ac248

Browse files
committed
style(reactive-rpc): 💄 run Prettier
1 parent d25c6b2 commit 72ac248

File tree

5 files changed

+36
-30
lines changed

5 files changed

+36
-30
lines changed

src/reactive-rpc/server/http1/Http1Server.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,19 @@ export class Http1Server implements Printable {
135135
const codecs = this.codecs;
136136
const ip = this.findIp(req);
137137
const token = this.findToken(req);
138-
const ctx = new Http1ConnectionContext(req, res, path, query, ip, token, match.params, new NullObject(), codecs.value.json, codecs.value.json, codecs.messages.compact);
138+
const ctx = new Http1ConnectionContext(
139+
req,
140+
res,
141+
path,
142+
query,
143+
ip,
144+
token,
145+
match.params,
146+
new NullObject(),
147+
codecs.value.json,
148+
codecs.value.json,
149+
codecs.messages.compact,
150+
);
139151
const headers = req.headers;
140152
const contentType = headers['content-type'];
141153
if (typeof contentType === 'string') ctx.setCodecs(contentType, codecs);
@@ -180,12 +192,7 @@ export class Http1Server implements Printable {
180192

181193
public findIp(req: http.IncomingMessage): string {
182194
const headers = req.headers;
183-
const ip = (
184-
headers['x-forwarded-for'] ||
185-
headers['x-real-ip'] ||
186-
req.socket.remoteAddress ||
187-
''
188-
);
195+
const ip = headers['x-forwarded-for'] || headers['x-real-ip'] || req.socket.remoteAddress || '';
189196
return ip instanceof Array ? ip[0] : ip;
190197
}
191198

@@ -236,9 +243,12 @@ export class Http1Server implements Printable {
236243
// ---------------------------------------------------------------- Printable
237244

238245
public toString(tab: string = ''): string {
239-
return `${this.constructor.name}` + printTree(tab, [
240-
(tab) => `HTTP ${this.httpRouter.toString(tab)}`,
241-
(tab) => `WebSocket ${this.wsRouter.toString(tab)}`,
242-
]);
246+
return (
247+
`${this.constructor.name}` +
248+
printTree(tab, [
249+
(tab) => `HTTP ${this.httpRouter.toString(tab)}`,
250+
(tab) => `WebSocket ${this.wsRouter.toString(tab)}`,
251+
])
252+
);
243253
}
244254
}

src/reactive-rpc/server/http1/RpcServer.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export class RpcServer implements Printable {
5252
public readonly http1: Http1Server;
5353
protected readonly batchProcessor: RpcMessageBatchProcessor<ConnectionContext>;
5454

55-
constructor (protected readonly opts: RpcServerOpts) {
56-
const http1 = this.http1 = opts.http1;
55+
constructor(protected readonly opts: RpcServerOpts) {
56+
const http1 = (this.http1 = opts.http1);
5757
const onInternalError = http1.oninternalerror;
5858
http1.oninternalerror = (error, res, req) => {
5959
if (error instanceof RpcError) {
@@ -116,8 +116,6 @@ export class RpcServer implements Printable {
116116
// ---------------------------------------------------------------- Printable
117117

118118
public toString(tab: string = ''): string {
119-
return `${this.constructor.name}` + printTree(tab, [
120-
(tab) => `HTTP/1.1 ${this.http1.toString(tab)}`,
121-
]);
119+
return `${this.constructor.name}` + printTree(tab, [(tab) => `HTTP/1.1 ${this.http1.toString(tab)}`]);
122120
}
123121
}

src/reactive-rpc/server/ws/codec/WsFrameEncoder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ export class WsFrameEncoder<W extends IWriter & IWriterGrowable = IWriter & IWri
8585
const writer = this.writer;
8686
if (length < 126) {
8787
const octet2 = maskBit | length;
88-
writer.u16((octet1 << 8) | octet2);
88+
writer.u16((octet1 << 8) | octet2);
8989
} else if (length < 0x10000) {
9090
const octet2 = maskBit | 126;
91-
writer.u32((((octet1 << 8) | octet2) * 0x10000) + length);
91+
writer.u32(((octet1 << 8) | octet2) * 0x10000 + length);
9292
} else {
9393
const octet2 = maskBit | 127;
9494
writer.u16((octet1 << 8) | octet2);

src/reactive-rpc/server/ws/codec/__tests__/encoder.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ describe('control frames', () => {
9090
});
9191
});
9292

93-
9493
describe('data frames', () => {
9594
test('can encode an empty BINARY data frame', () => {
9695
const encoder = new WsFrameEncoder();
@@ -139,7 +138,7 @@ describe('data frames', () => {
139138
const data2 = decoder.reader.buf(frame.length);
140139
expect(data2).toEqual(data);
141140
});
142-
141+
143142
describe('can encode different message sizes', () => {
144143
const sizes = [0, 1, 2, 125, 126, 127, 128, 129, 255, 1234, 65535, 65536, 65537, 7777777, 2 ** 31 - 1];
145144
const encoder = new WsFrameEncoder();

src/reactive-rpc/server/ws/server/WsServerConnection.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ export class WsServerConnection {
2323
public onpong: (data: Uint8Array | null) => void = () => {};
2424
public onclose: (code: number, reason: string) => void = () => {};
2525

26-
constructor(
27-
protected readonly encoder: WsFrameEncoder,
28-
public readonly socket: net.Socket,
29-
head: Buffer,
30-
) {
26+
constructor(protected readonly encoder: WsFrameEncoder, public readonly socket: net.Socket, head: Buffer) {
3127
const decoder = new WsFrameDecoder();
3228
if (head.length) decoder.push(head);
3329
let currentFrame: WsFrameHeader | null = null;
@@ -95,11 +91,14 @@ export class WsServerConnection {
9591
public upgrade(secWebSocketKey: string, secWebSocketProtocol: string, secWebSocketExtensions: string): void {
9692
const accept = secWebSocketKey + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
9793
const acceptSha1 = crypto.createHash('sha1').update(accept).digest('base64');
98-
this.socket.write('HTTP/1.1 101 Switching Protocols\r\n' +
99-
'Upgrade: websocket\r\n' +
100-
'Connection: Upgrade\r\n' +
101-
'Sec-WebSocket-Accept: ' + acceptSha1 + '\r\n' +
102-
'\r\n'
94+
this.socket.write(
95+
'HTTP/1.1 101 Switching Protocols\r\n' +
96+
'Upgrade: websocket\r\n' +
97+
'Connection: Upgrade\r\n' +
98+
'Sec-WebSocket-Accept: ' +
99+
acceptSha1 +
100+
'\r\n' +
101+
'\r\n',
103102
);
104103
}
105104

0 commit comments

Comments
 (0)