Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(repeater): refrain from utilizing non-standard ports #404

Merged
merged 37 commits into from
Jul 31, 2023

Conversation

lsndr
Copy link
Contributor

@lsndr lsndr commented Jul 21, 2023

BREAKING CHANGE: Remote repeater scripts are deprecated and no longer supported. Instead, please utilize the local scripts with the following command:

bright-cli --id <id> --token <token> --scripts '{"example.com": "./hmac.js"}'

closes #419

@lsndr lsndr self-assigned this Jul 21, 2023
@lsndr lsndr force-pushed the feat/implement-repeater-server-bus branch from fce13e5 to 476bd79 Compare July 21, 2023 09:44
@lsndr lsndr requested a review from derevnjuk July 24, 2023 06:21
src/Config/CliBuilder.ts Outdated Show resolved Hide resolved
package-lock.json Show resolved Hide resolved
src/Repeater/Repeater.ts Outdated Show resolved Hide resolved
src/Repeater/Repeater.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeaterLauncher.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeater.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeater.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeaterLauncher.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeaterLauncher.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeater.ts Outdated Show resolved Hide resolved
@lsndr lsndr force-pushed the feat/implement-repeater-server-bus branch 5 times, most recently from 92e4a62 to 98dbdad Compare July 25, 2023 08:19
@lsndr lsndr marked this pull request as ready for review July 25, 2023 10:52
@lsndr lsndr marked this pull request as draft July 25, 2023 10:52
@lsndr lsndr requested a review from derevnjuk July 25, 2023 10:52
src/Repeater/DefaultRepeaterServer.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeaterServer.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeaterServer.ts Show resolved Hide resolved
src/Repeater/DefaultRepeaterServer.ts Outdated Show resolved Hide resolved
src/Repeater/Repeater.ts Outdated Show resolved Hide resolved
src/Repeater/RepeaterLauncher.ts Show resolved Hide resolved
src/Repeater/RepeaterServer.ts Outdated Show resolved Hide resolved
src/Repeater/ServerRepeaterLauncher.ts Outdated Show resolved Hide resolved
src/Repeater/ServerRepeaterLauncher.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeaterServer.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeaterServer.ts Show resolved Hide resolved
@lsndr lsndr force-pushed the feat/implement-repeater-server-bus branch from d740100 to 9f1a70d Compare July 27, 2023 09:17
@lsndr lsndr requested a review from derevnjuk July 27, 2023 09:26
@lsndr lsndr marked this pull request as ready for review July 28, 2023 06:22
@lsndr lsndr force-pushed the feat/implement-repeater-server-bus branch from 67eff22 to 78ea71e Compare July 28, 2023 06:25
@lsndr lsndr changed the title feat(repeater): replace rabbitmq with repeater server feat(repeater): replace Rabbit MQ repeater with Repeater Server implementation Jul 28, 2023
@lsndr lsndr changed the title feat(repeater): replace Rabbit MQ repeater with Repeater Server implementation feat(repeater): replace Rabbit MQ implementation of repeater with Repeater Server Jul 28, 2023
@lsndr lsndr added the Type: enhancement New feature or request. label Jul 28, 2023
src/Commands/RunRepeater.ts Outdated Show resolved Hide resolved
src/Repeater/DefaultRepeaterServer.ts Outdated Show resolved Hide resolved
Comment on lines 44 to 46
export type RepeaterServerEventHandler<P, R = void> = P extends undefined
? () => R | Promise<R>
: (payload: P) => R | Promise<R>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event listeners have nothing in common with each other. Let's inline their types to make it more cohesive.

Additionally, if you're not interested in the return value, declare the return type as unknown, this is the more user-friendly approach. Also, get rid of redundant wrappers, such RepeaterServerReconnectionFailedEvent

For details please refer to the example below:

requestReceived(
    handler: (request: RepeaterServerRequestEvent) => RepeaterServerRequestResponse | Promise< RepeaterServerRequestResponse >
  ): void;

  reconnectionFailed(
    handler: (error: Error) => unknown
  ): void;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

But I preserved void type for handlers which are not supposed to return anything. It seems to be more clear from handler's contract perspective. If I used unknown it would mean that handlers expect some data to be returned, that further will be processed. But with void it clearly says that no data is needed to be returned

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I used unknown it would mean that handlers expect some data to be returned, that further will be processed.

You already handle the never type silently, hiding these details from the public API by using the void type.

Avoid using the void return type for callbacks when the return value will be ignored or handled (e.g. the never type). Instead, use unknown to explain clearly that you are not interested in the return value, regardless of what it might be, and gracefully handle all cases.

Anyway, you can keep it as for now, since this is part of internal API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using the void return type for callbacks when the return value will be ignored or handled (e.g. the never type). Instead, use unknown to explain clearly that you are not interested in the return value, regardless of what it might be, and gracefully handle all cases.

I think I don't fully understand what benefits unknown gives us in such cases.

unknown exactly says that i'm interested in returned value, but not in it's type. void says that it doesn't expect any value to be returned, so it won't be processed even if returned

Copy link
Member

@derevnjuk derevnjuk Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, so it won't be processed even if returned

However, you do. You silently handle the never, is not it so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yes, but that's an implementation detail which in combination with void type will not happen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not implementation details. Such "details" represent the post- and pre-conditions of any interface. Using the void here could potentially result in incorrect inheritance, contract and LSP violations.

@lsndr lsndr requested a review from derevnjuk July 31, 2023 06:56
@derevnjuk derevnjuk changed the title feat(repeater): replace Rabbit MQ implementation of repeater with Repeater Server feat(repeater): refrain from utilizing non-standard ports for repeaters. Jul 31, 2023
@derevnjuk derevnjuk changed the title feat(repeater): refrain from utilizing non-standard ports for repeaters. feat(repeater): refrain from utilizing non-standard ports Jul 31, 2023
@derevnjuk derevnjuk merged commit 014ea6b into next Jul 31, 2023
@derevnjuk derevnjuk deleted the feat/implement-repeater-server-bus branch July 31, 2023 07:49
@derevnjuk derevnjuk linked an issue Aug 2, 2023 that may be closed by this pull request
derevnjuk pushed a commit that referenced this pull request Aug 3, 2023
derevnjuk pushed a commit that referenced this pull request Aug 17, 2023
derevnjuk pushed a commit that referenced this pull request Aug 31, 2023
derevnjuk added a commit that referenced this pull request Sep 25, 2023
derevnjuk added a commit that referenced this pull request Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace Rabbit MQ implementation of repeater with Repeater Server
2 participants