Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-nagy committed Dec 12, 2023
1 parent 148c44a commit 77565be
Show file tree
Hide file tree
Showing 50 changed files with 188 additions and 180 deletions.
16 changes: 8 additions & 8 deletions packages/browser/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ module.exports = {
parserOptions: {
EXPERIMENTAL_useProjectService: true,
project: true,
tsconfigRootDir: __dirname,
tsconfigRootDir: __dirname
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:expect-type/recommended",
"plugin:expect-type/recommended"
],
rules: {
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
caughtErrorsIgnorePattern: "^_"
}
],
"expect-type/expect": "error",
},
},
],
"expect-type/expect": "error"
}
}
]
};
3 changes: 3 additions & 0 deletions packages/browser/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "none"
}
1 change: 1 addition & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"clean": "rm -rf node_modules build",
"eslint": "eslint src",
"prettier": "prettier --check --ignore-path .gitignore .",
"prettier-fix": "prettier --write --ignore-path .gitignore .",
"test": "web-test-runner"
},
"devDependencies": {
Expand Down
40 changes: 20 additions & 20 deletions packages/browser/src/BrowserSocket/BrowserSocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TimeoutError,
firstValueFrom,
flatMap,
fromEvent,
fromEvent
} from "@daniel-nagy/transporter/Observable";

import * as BrowserSocket from "./BrowserSocket";
Expand Down Expand Up @@ -171,7 +171,7 @@ describe("socket state transitions", () => {
const clock = useFakeTimers();

using socket = BrowserSocket.connect(iframe.contentWindow, {
connectTimeout: 1000,
connectTimeout: 1000
});

const seenStates: State.State[] = [];
Expand All @@ -185,7 +185,7 @@ describe("socket state transitions", () => {

const closingState = {
...State.Closing(),
error: match.instanceOf(Error.ConnectTimeoutError),
error: match.instanceOf(Error.ConnectTimeoutError)
};

assert.match(seenStates, [State.Connecting(), closingState]);
Expand All @@ -202,7 +202,7 @@ describe("socket state transitions", () => {

const iframe = await Test.createIframe(srcDoc);
using socket = BrowserSocket.connect(iframe.contentWindow, {
bufferLimit: 0,
bufferLimit: 0
});

const seenStates: State.State[] = [];
Expand All @@ -214,7 +214,7 @@ describe("socket state transitions", () => {

const closingState = {
...State.Closing(),
error: match.instanceOf(BufferOverflowError),
error: match.instanceOf(BufferOverflowError)
};

assert.match(seenStates, [State.Connecting(), closingState]);
Expand Down Expand Up @@ -257,7 +257,7 @@ describe("socket state transitions", () => {
assert.match(seenStates, [
State.Connecting(),
State.Connected(),
State.Closing(),
State.Closing()
]);
});

Expand All @@ -273,7 +273,7 @@ describe("socket state transitions", () => {
assert.match(seenStates, [
State.Connected(),
State.Closing(),
State.Closed(),
State.Closed()
]);
});

Expand All @@ -290,7 +290,7 @@ describe("socket state transitions", () => {
assert.match(seenStates, [
State.Connecting(),
State.Connected(),
State.Closing(),
State.Closing()
]);
});

Expand All @@ -300,7 +300,7 @@ describe("socket state transitions", () => {

const socket = BrowserSocket.fromPort(channel.port1, {
heartbeatInterval: 1000,
heartbeatTimeout: 1000,
heartbeatTimeout: 1000
});

const seenStates: State.State[] = [];
Expand All @@ -315,8 +315,8 @@ describe("socket state transitions", () => {
State.Connected(),
{
...State.Closing(),
error: match.instanceOf(Error.HeartbeatTimeoutError),
},
error: match.instanceOf(Error.HeartbeatTimeoutError)
}
]);
});

Expand All @@ -333,7 +333,7 @@ describe("socket state transitions", () => {
assert.match(seenStates, [
State.Connected(),
State.Closing(),
State.Closed(),
State.Closed()
]);
});

Expand All @@ -342,7 +342,7 @@ describe("socket state transitions", () => {
const channel = new MessageChannel();

const socket = BrowserSocket.fromPort(channel.port1, {
disconnectTimeout: 1000,
disconnectTimeout: 1000
});

const seenStates: State.State[] = [];
Expand All @@ -357,8 +357,8 @@ describe("socket state transitions", () => {
State.Closing(),
{
...State.Closed(),
error: match.instanceOf(Error.DisconnectTimeoutError),
},
error: match.instanceOf(Error.DisconnectTimeoutError)
}
]);
});
});
Expand Down Expand Up @@ -403,7 +403,7 @@ test("passing an origin when connecting to a window", async () => {
// 10 is somewhat arbitrary but it seems to be long enough to avoid false
// positives.
connectTimeout: 10,
origin: location.origin,
origin: location.origin
});

const seenStates: State.State[] = [];
Expand All @@ -412,7 +412,7 @@ test("passing an origin when connecting to a window", async () => {

assert.match(seenStates, [
State.Connecting(),
{ ...State.Closing(), error: match.instanceOf(Error.ConnectTimeoutError) },
{ ...State.Closing(), error: match.instanceOf(Error.ConnectTimeoutError) }
]);
});

Expand All @@ -423,7 +423,7 @@ test("the socket heartbeat is delayed until connection", async () => {
connected: false,
connectTimeout: 1000,
heartbeatInterval: 250,
heartbeatTimeout: 250,
heartbeatTimeout: 250
});

const seenStates: State.State[] = [];
Expand All @@ -443,7 +443,7 @@ test("the socket heartbeat is unsubscribed when the socket is closing", async ()
const channel = new MessageChannel();
const socket = BrowserSocket.fromPort(channel.port1, {
heartbeatInterval: 1000,
heartbeatTimeout: 1000,
heartbeatTimeout: 1000
});

const seenStates: State.State[] = [];
Expand Down Expand Up @@ -566,7 +566,7 @@ test("using a buffer overflow strategy", async () => {

using socket = BrowserSocket.connect(self, {
bufferLimit: 1,
bufferOverflowStrategy: BufferOverflowStrategy.DropOldest,
bufferOverflowStrategy: BufferOverflowStrategy.DropOldest
});

socket.send("🍔");
Expand Down
20 changes: 10 additions & 10 deletions packages/browser/src/BrowserSocket/BrowserSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
map,
take,
takeUntil,
timeout as within,
timeout as within
} from "@daniel-nagy/transporter/Observable";

import * as Error from "./Error";
Expand Down Expand Up @@ -94,7 +94,7 @@ export class BrowserSocket {
heartbeatInterval = 1000,
heartbeatTimeout = 2000,
receive,
send,
send
}: {
bufferLimit?: number;
bufferOverflowStrategy?: BufferOverflowStrategy;
Expand Down Expand Up @@ -131,20 +131,20 @@ export class BrowserSocket {
.pipe(
bufferUntil(this.connected, {
limit: bufferLimit,
overflowStrategy: bufferOverflowStrategy,
overflowStrategy: bufferOverflowStrategy
})
)
.subscribe({
error: (error: BufferOverflowError | Error.ConnectTimeoutError) =>
this.#close(error),
next: (message) => send(message),
next: (message) => send(message)
});

this.connected.subscribe(() => {
cron(heartbeatInterval, () => this.ping(heartbeatTimeout))
.pipe(takeUntil(this.closing))
.subscribe({
error: () => this.#close(new Error.HeartbeatTimeoutError()),
error: () => this.#close(new Error.HeartbeatTimeoutError())
});
});

Expand Down Expand Up @@ -265,7 +265,7 @@ export class BrowserSocket {
.subscribe({
error: (error: Error.DisconnectTimeoutError) => {
this.#onDisconnected(error);
},
}
});
}

Expand Down Expand Up @@ -343,7 +343,7 @@ export function fromPort(
const socket = new BrowserSocket({
...options,
receive: fromEvent<MessageEvent<StructuredCloneable.t>>(port, "message"),
send: (message: StructuredCloneable.t) => port.postMessage(message),
send: (message: StructuredCloneable.t) => port.postMessage(message)
});

if (connected)
Expand All @@ -363,7 +363,7 @@ function connectSharedWorker(
const channel = new MessageChannel();
const socket = fromPort(channel.port1, {
...options,
connected: false,
connected: false
});
worker.port.start();
worker.port.postMessage(Message.Connect(serverAddress), [channel.port2]);
Expand All @@ -377,7 +377,7 @@ function connectWindow(
const channel = new MessageChannel();
const socket = fromPort(channel.port1, {
...options,
connected: false,
connected: false
});
window.postMessage(Message.Connect(serverAddress), origin, [channel.port2]);
return socket;
Expand All @@ -390,7 +390,7 @@ function connectWorker(
const channel = new MessageChannel();
const socket = fromPort(channel.port1, {
...options,
connected: false,
connected: false
});
worker.postMessage(Message.Connect(serverAddress), [channel.port2]);
return socket;
Expand Down
10 changes: 5 additions & 5 deletions packages/browser/src/BrowserSocket/BrowserSocketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
map,
take,
takeUntil,
tap,
tap
} from "@daniel-nagy/transporter/Observable";

import * as BrowserSocket from "./BrowserSocket";
Expand All @@ -25,7 +25,7 @@ interface ConnectEvent<T = unknown> extends MessageEvent<T> {

export enum State {
Listening = "Listening",
Stopped = "Stopped",
Stopped = "Stopped"
}

export type SocketOptions = {
Expand Down Expand Up @@ -60,7 +60,7 @@ export class BrowserSocketServer {
address = "",
connectFilter = () => true,
receive,
socketOptions,
socketOptions
}: {
address?: string;
connectFilter?(message: ConnectEvent<Message.Connect>): boolean;
Expand Down Expand Up @@ -163,12 +163,12 @@ export function listen(options?: SocketServerOptions) {
map((event) => event.ports[0]),
tap((port) => port.start()),
flatMap((port) => fromEvent(port, "message"))
),
)
});
}

return new BrowserSocketServer({
...options,
receive: fromEvent<MessageEvent<StructuredCloneable.t>>(self, "message"),
receive: fromEvent<MessageEvent<StructuredCloneable.t>>(self, "message")
});
}
Loading

0 comments on commit 77565be

Please sign in to comment.