Skip to content

Commit

Permalink
refactor: make class properties private
Browse files Browse the repository at this point in the history
BREAKING CHANGE: class properties are now private
  • Loading branch information
wolfy1339 authored Aug 23, 2024
1 parent b0247a1 commit 2a7f674
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ interface Options {
}

class Client {
source: string;
target: string;
fetch: typeof global.fetch;
logger: Pick<Console, Severity>;
events!: EventSource;
#source: string;
#target: string;
#fetch: typeof global.fetch;
#logger: Pick<Console, Severity>;
#events!: EventSource;

constructor({
source,
target,
logger = console,
fetch = undiciFetch,
}: Options) {
this.source = source;
this.target = target;
this.logger = logger!;
this.fetch = fetch;
this.#source = source;
this.#target = target;
this.#logger = logger!;
this.#fetch = fetch;

if (!validator.isURL(this.source)) {

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18 and ubuntu-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18 and macos-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 18 and windows-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20 and ubuntu-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20 and macos-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 20 and windows-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 22 and ubuntu-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 22 and macos-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22

Check failure on line 39 in index.ts

View workflow job for this annotation

GitHub Actions / Test on Node 22 and windows-latest

test/index.test.ts > client > onmessage > returns a new channel

TypeError: Expected a string but received a undefined ❯ assertString node_modules/validator/lib/util/assertString.js:13:11 ❯ Object.isURL node_modules/validator/lib/isURL.js:59:29 ❯ new Client index.ts:39:20 ❯ test/index.test.ts:86:22
throw new Error("The provided URL is invalid.");
Expand All @@ -57,7 +57,7 @@ class Client {
async onmessage(msg: MessageEvent<string>) {
const data = JSON.parse(msg.data);

const target = url.parse(this.target, true);
const target = url.parse(this.#target, true);
const mergedQuery = { ...target.query, ...data.query };
target.search = querystring.stringify(mergedQuery);

Expand All @@ -80,28 +80,28 @@ class Client {
headers["content-type"] = "application/json";

try {
const response = await this.fetch(url.format(target), {
const response = await this.#fetch(url.format(target), {
method: "POST",
mode: data["sec-fetch-mode"],
body,
headers,
});
this.logger.info(`POST ${response.url} - ${response.status}`);
this.#logger.info(`POST ${response.url} - ${response.status}`);
} catch (err) {
this.logger.error(err);
this.#logger.error(err);
}
}

onopen() {
this.logger.info("Connected", this.events.url);
this.#logger.info("Connected", this.events.url);
}

onerror(err: ErrorEvent) {
this.logger.error(err);
this.#logger.error(err);
}

start() {
const events = new EventSource(this.source, {
const events = new EventSource(this.#source, {
dispatcher: new EnvHttpProxyAgent(),
});

Expand All @@ -112,8 +112,8 @@ class Client {
events.addEventListener("open", this.onopen.bind(this));
events.addEventListener("error", this.onerror.bind(this));

this.logger.info(`Forwarding ${this.source} to ${this.target}`);
this.events = events;
this.#logger.info(`Forwarding ${this.#source} to ${this.#target}`);
this.#events = events;

return events;
}
Expand Down

0 comments on commit 2a7f674

Please sign in to comment.