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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): introducing EffectHttpResponse type #87

Merged
merged 7 commits into from Dec 9, 2018

Conversation

JozefFlakus
Copy link
Member

@JozefFlakus JozefFlakus commented Dec 7, 2018

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[x] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

  • EffectResponse interface is restricted only to HTTP protocol. It should be only represented as a base type which could be used outside, eg. in websockets protocol.

What is the new behavior?

  • The basic Effect generic interface extends EffectResponse defaulting to EffectHttpResponse type - because we are targeting HTTP protocol by default. From now it allows us to build Effects, not restricted only to HTTP protocol.
export interface EffectResponse<T = any> {
  body?: T;
}

export interface EffectHttpResponse<T = any> extends EffectResponse<T> {
  status?: HttpStatus;
  headers?: HttpHeaders;
}
  • removed bumped-up lint-staged to version 8.1.0 馃憠 removed rxjs-compat
  • added support for TypeScript v3.2.2

Does this PR introduce a breaking change?

[x] Yes
[ ] No

@JozefFlakus JozefFlakus added enhancement New feature or request next Feature or enhancement that will be added in 'next' major version scope: core Relates to @marblejs/core package labels Dec 7, 2018
@JozefFlakus JozefFlakus added this to the 2.0.0 milestone Dec 7, 2018
@JozefFlakus JozefFlakus self-assigned this Dec 7, 2018
@JozefFlakus JozefFlakus added this to In progress in @marblejs/next via automation Dec 7, 2018
@JozefFlakus JozefFlakus changed the title Imp/next/core/effect response feat(core): introducing EffectHttpResponse type Dec 7, 2018
@codecov
Copy link

codecov bot commented Dec 7, 2018

Codecov Report

Merging #87 into next will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@         Coverage Diff         @@
##           next    #87   +/-   ##
===================================
  Coverage   100%   100%           
===================================
  Files        45     45           
  Lines       499    499           
  Branches     62     62           
===================================
  Hits        499    499
Impacted Files Coverage 螖
packages/core/src/http.interface.ts 100% <酶> (酶) 猬嗭笍
packages/core/src/http.listener.ts 100% <100%> (酶) 猬嗭笍
packages/core/src/response/response.handler.ts 100% <100%> (酶) 猬嗭笍
packages/core/src/router/router.resolver.ts 100% <100%> (酶) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 5a9f2ae...938944f. Read the comment docs.

@marblejs/next automation moved this from In progress to Reviewer approved Dec 7, 2018
sebastianmusial
sebastianmusial previously approved these changes Dec 7, 2018
@@ -13,8 +16,12 @@ export interface Middleware<
> extends Effect<I, O> {}

export interface ErrorEffect<T extends Error = Error>
extends Effect<HttpRequest, EffectResponse, T> {}
extends Effect<HttpRequest, EffectHttpResponse, T> {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it extends Effect<HttpRequest, EffectHttpResponse>, shouldn't it be HttpErrorEffect?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I will name it as HttpErrorEffect then it will be a huge breaking change because constructs like Effect, ErrorEffect, Middleware are more commonly used compared to raw Error<..., ...> definitions. 馃

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe ErrorEffect should be more generic? Eg. like Middleware 馃

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, if the Effect and ErrorEffect should be HTTP independent then both ErrorEffect, Middleware and base Effect interfaces should have an ability to construct new types upon it:

export interface Middleware<
  I extends HttpRequest = HttpRequest,
  O extends HttpRequest = HttpRequest,
  T = HttpResponse
> extends Effect<I, O, any, T> {}

export interface ErrorEffect<
  T extends Error = Error,
  U = HttpRequest,
  V = EffectHttpResponse,
> extends Effect<U, V, T> {}

export interface Effect<
  T = HttpRequest,
  U = EffectHttpResponse,
  V = any,
  W = HttpResponse,
> {
  (req$: Observable<T>, res: W, meta: V): Observable<U>;
}

@krzysztof-miemiec WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Then we can construct new Websockets-related interfaces for WsEffect, WsErrorEffect and WsMiddleware

Copy link
Member Author

Choose a reason for hiding this comment

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

Or to only define the fully compassable Effect interface and leave ErrorEffect and Middleware as it is.

export interface Effect<
  T = HttpRequest,
  U = EffectHttpResponse,
  V = any,
  W = HttpResponse,
> {
  (req$: Observable<T>, res: W, meta: V): Observable<U>;
}

Then we can create WsEffect, WsErrorEffect and WsMiddleware types basing only on 鈽濓笍 it.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO the better is the last solution. 馃

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, I think that the latter solution would be best. Default way of working with Marble would be HTTP, and WS is added as additional feature. 馃憣 BTW. Should we add support for server push (with http2) in Marble.js 2.0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but these are our priorities for v2.0:
Websockets >> http2

@marblejs/next automation moved this from Reviewer approved to Needs review Dec 9, 2018
@JozefFlakus JozefFlakus merged commit e15ea78 into next Dec 9, 2018
@marblejs/next automation moved this from Needs review to Done Dec 9, 2018
@JozefFlakus JozefFlakus deleted the imp/next/core/EffectResponse branch December 9, 2018 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request next Feature or enhancement that will be added in 'next' major version scope: core Relates to @marblejs/core package
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants