Skip to content

Commit

Permalink
swap type parameters for /platform data types (#2376)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim <hello@timsmart.co>
  • Loading branch information
vecerek and tim-smart committed Mar 31, 2024
1 parent 9be300e commit b712862
Show file tree
Hide file tree
Showing 19 changed files with 585 additions and 566 deletions.
15 changes: 15 additions & 0 deletions .changeset/mighty-trees-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@effect/platform": minor
"@effect/platform-browser": minor
"@effect/platform-bun": minor
"@effect/platform-node": minor
"@effect/platform-node-shared": minor
---

Swap type parameters in /platform data types

A codemod has been released to make migration easier:

```
npx @effect/codemod platform-0.49 src/**/*
```
2 changes: 1 addition & 1 deletion packages/platform-bun/src/internal/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const make = (
middleware
? middleware(App.withDefaultMiddleware(respond(httpApp)))
: App.withDefaultMiddleware(respond(httpApp))
) as App.Default<never, unknown>
) as App.Default<unknown>

return pipe(
Effect.runtime<never>(),
Expand Down
6 changes: 3 additions & 3 deletions packages/platform-node/src/Http/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export const make: (
*/
export const makeHandler: {
<R, E>(
httpApp: App.Default<R, E>
httpApp: App.Default<E, R>
): Effect.Effect<
(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse<Http.IncomingMessage>) => void,
never,
Exclude<R, Scope.Scope | ServerRequest.ServerRequest>
>
<R, E, App extends App.Default<any, any>>(
httpApp: App.Default<R, E>,
middleware: Middleware.Middleware.Applied<R, E, App>
httpApp: App.Default<E, R>,
middleware: Middleware.Middleware.Applied<App, E, R>
): Effect.Effect<
(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse<Http.IncomingMessage>) => void,
never,
Expand Down
10 changes: 5 additions & 5 deletions packages/platform-node/src/internal/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ export const make = (

/** @internal */
export const makeHandler: {
<R, E>(httpApp: App.Default<R, E>): Effect.Effect<
<R, E>(httpApp: App.Default<E, R>): Effect.Effect<
(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void,
never,
Exclude<R, ServerRequest.ServerRequest | Scope.Scope>
>
<R, E, App extends App.Default<any, any>>(
httpApp: App.Default<R, E>,
middleware: Middleware.Middleware.Applied<R, E, App>
httpApp: App.Default<E, R>,
middleware: Middleware.Middleware.Applied<App, E, R>
): Effect.Effect<
(nodeRequest: Http.IncomingMessage, nodeResponse: Http.ServerResponse) => void,
never,
Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest | Scope.Scope>
>
} = <R, E>(httpApp: App.Default<R, E>, middleware?: Middleware.Middleware) => {
} = <R, E>(httpApp: App.Default<E, R>, middleware?: Middleware.Middleware) => {
const handledApp = Effect.scoped(
middleware
? middleware(App.withDefaultMiddleware(respond(httpApp)))
Expand Down Expand Up @@ -162,7 +162,7 @@ export const makeHandler: {
/** @internal */
export const makeUpgradeHandler = <R, E>(
lazyWss: Effect.Effect<WS.WebSocketServer>,
httpApp: App.Default<R, E>,
httpApp: App.Default<E, R>,
middleware?: Middleware.Middleware
) => {
const handledApp = Effect.scoped(
Expand Down
20 changes: 11 additions & 9 deletions packages/platform/src/Http/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@ import * as ServerResponse from "./ServerResponse.js"
* @since 1.0.0
* @category models
*/
export interface HttpApp<R, E, A> extends Effect.Effect<A, E, R | ServerRequest.ServerRequest> {}
export interface HttpApp<A = ServerResponse.ServerResponse, E = never, R = never>
extends Effect.Effect<A, E, R | ServerRequest.ServerRequest>
{}

/**
* @since 1.0.0
* @category models
*/
export type Default<R, E> = HttpApp<R, E, ServerResponse.ServerResponse>
export type Default<E = never, R = never> = HttpApp<ServerResponse.ServerResponse, E, R>

/**
* @since 1.0.0
* @category combinators
*/
export const withDefaultMiddleware = <R, E>(
self: Default<R, E>
): Default<R, E> => internalMiddleware.tracer(self)
self: Default<E, R>
): Default<E, R> => internalMiddleware.tracer(self)

/**
* @since 1.0.0
Expand Down Expand Up @@ -94,8 +96,8 @@ export const appendPreResponseHandler: (handler: PreResponseHandler) => Effect.E
* @category fiber refs
*/
export const withPreResponseHandler = dual<
(handler: PreResponseHandler) => <R, E, A>(self: HttpApp<R, E, A>) => HttpApp<R, E, A>,
<R, E, A>(self: HttpApp<R, E, A>, handler: PreResponseHandler) => HttpApp<R, E, A>
(handler: PreResponseHandler) => <R, E, A>(self: HttpApp<A, E, R>) => HttpApp<A, E, R>,
<R, E, A>(self: HttpApp<A, E, R>, handler: PreResponseHandler) => HttpApp<A, E, R>
>(2, (self, handler) =>
Effect.locallyWith(
self,
Expand All @@ -109,7 +111,7 @@ export const withPreResponseHandler = dual<
*/
export const toWebHandlerRuntime = <R>(runtime: Runtime.Runtime<R>) => {
const run = Runtime.runFork(runtime)
return <E>(self: Default<R | Scope.Scope, E>) => {
return <E>(self: Default<E, R | Scope.Scope>) => {
self = withDefaultMiddleware(self)
return (request: Request): Promise<Response> =>
new Promise((resolve, reject) => {
Expand Down Expand Up @@ -138,15 +140,15 @@ export const toWebHandlerRuntime = <R>(runtime: Runtime.Runtime<R>) => {
* @since 1.0.0
* @category conversions
*/
export const toWebHandler: <E>(self: Default<Scope.Scope, E>) => (request: Request) => Promise<Response> =
export const toWebHandler: <E>(self: Default<E, Scope.Scope>) => (request: Request) => Promise<Response> =
toWebHandlerRuntime(Runtime.defaultRuntime)

/**
* @since 1.0.0
* @category conversions
*/
export const toWebHandlerLayer = <R, E, RE>(
self: Default<R | Scope.Scope, E>,
self: Default<E, R | Scope.Scope>,
layer: Layer.Layer<R, RE>
): {
readonly close: () => Promise<void>
Expand Down
Loading

0 comments on commit b712862

Please sign in to comment.