Skip to content

Commit

Permalink
chore: update effect dependencies (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukovanej committed Sep 16, 2024
1 parent 6abb467 commit 2e4eaf8
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 455 deletions.
6 changes: 6 additions & 0 deletions .changeset/clever-hotels-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"effect-http-node": minor
"effect-http": minor
---

Update effect dependencies.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,13 +589,13 @@
Instead of

```ts
const client = pipe(api, Http.client(url, options));
const client = pipe(api, Http.client.execute(url, options));
```

use

```ts
const client = Http.client(api, url, options);
const client = Http.client.execute(api, url, options);
```

- e0fa6e6: Remove `effect-log` and logging functionality.
Expand Down Expand Up @@ -660,7 +660,7 @@
headers: { "X-Another": Schema.string },
},
],
}),
})
);
```

Expand Down Expand Up @@ -1007,7 +1007,7 @@
server,
Http.listen({ port: 3000 }),
Effect.provideLayer(layer),
Effect.runPromise,
Effect.runPromise
);
```

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
"@changesets/cli": "^2.27.8",
"@effect/build-utils": "^0.7.8",
"@effect/docgen": "^0.4.4",
"@effect/dtslint": "^0.1.0",
"@effect/dtslint": "^0.1.1",
"@effect/eslint-plugin": "^0.2.0",
"@effect/language-service": "^0.1.0",
"@effect/vitest": "^0.9.2",
"@types/node": "^22.5.4",
"@effect/vitest": "^0.10.0",
"@types/node": "^22.5.5",
"@types/swagger-ui-dist": "^3.30.5",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/coverage-v8": "^2.1.1",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "^3.6.3",
Expand All @@ -49,9 +49,9 @@
"madge": "^8.0.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"tsx": "^4.19.0",
"tsx": "^4.19.1",
"typescript": "^5.6.2",
"vitest": "^2.0.5"
"vitest": "^2.1.1"
},
"pnpm": {
"updateConfig": {
Expand Down
44 changes: 23 additions & 21 deletions packages/effect-http-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,23 @@
import { NodeTesting } from "effect-http-node";

const myEndpoint = Api.get("myEndpoint", "/my-endpoint").pipe(
Api.setResponseBody(Schema.Struct({ hello: Schema.String })),
Api.setResponseBody(Schema.Struct({ hello: Schema.String }))
);

const myHandler = Handler.make(myEndpoint, () =>
Effect.succeed({ hello: "world" }),
Effect.succeed({ hello: "world" })
);

it.scoped("myHandler", () =>
Effect.gen(function* () {
const client = yield* NodeTesting.handler(myHandler);
const response = yield* client(HttpClientRequest.get("/my-endpoint"));
const response = yield* client.execute(
HttpClientRequest.get("/my-endpoint")
);

expect(response.status).toEqual(200);
expect(yield* response.json).toEqual({ hello: "world" });
}),
})
);
```

Expand Down Expand Up @@ -322,13 +324,13 @@
const myEndpointHandler = RouterBuilder.handler(
api,
"myEndpoint",
({ query }) => Effect.succeed(query.country),
({ query }) => Effect.succeed(query.country)
);
const app = pipe(
RouterBuilder.make(api),
RouterBuilder.handle(myEndpointHandler),
RouterBuilder.build,
RouterBuilder.build
);
```

Expand Down Expand Up @@ -484,9 +486,9 @@
scheme: "basic",
},
schema: Schema.Secret,
}),
),
),
})
)
)
);
```

Expand All @@ -497,9 +499,9 @@
Api.addEndpoint(
Api.post("mySecuredEndpoint", "/my-secured-endpoint").pipe(
Api.setResponseBody(Schema.string),
Api.setSecurity(Security.basic()),
),
),
Api.setSecurity(Security.basic())
)
)
);
```

Expand Down Expand Up @@ -564,7 +566,7 @@
Api.get("getUser", "/user", {
response: User,
request: { query: GetUserQuery },
}),
})
);
```

Expand All @@ -577,9 +579,9 @@
pipe(
Api.get("getUser", "/user"),
Api.setResponseBody(UserResponse),
Api.setRequestQuery(GetUserQuery),
),
),
Api.setRequestQuery(GetUserQuery)
)
)
);
```

Expand All @@ -601,9 +603,9 @@
pipe(
Api.post("createUser", "/user"),
Api.setResponseStatus(201),
Api.setResponseBody(UserResponse),
),
),
Api.setResponseBody(UserResponse)
)
)
);

const client = Client.make(api);
Expand All @@ -622,7 +624,7 @@
Api.addResponse({
status: 204,
headers: Schema.struct({ "x-another": Schema.NumberFromString }),
}),
})
);
```
Expand All @@ -635,7 +637,7 @@
```ts
const mySecuredEnpoint = Api.post("security", "/testSecurity").pipe(
Api.setResponseBody(Schema.string),
Api.addSecurity("myAwesomeBearerAuth", mySecuritySchema),
Api.addSecurity("myAwesomeBearerAuth", mySecuritySchema)
);

const api = Api.make().pipe(Api.addEndpoint(mySecuredEnpoint));
Expand Down
20 changes: 10 additions & 10 deletions packages/effect-http-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
"swagger-ui-dist": "^5.17.14"
},
"peerDependencies": {
"@effect/platform": "^0.64.0",
"@effect/platform-node": "^0.59.0",
"@effect/schema": "^0.72.0",
"effect": "^3.7.0",
"@effect/platform": "^0.65.0",
"@effect/platform-node": "^0.60.0",
"@effect/schema": "^0.73.0",
"effect": "^3.8.0",
"effect-http": "workspace:^"
},
"devDependencies": {
"@effect/platform": "^0.64.0",
"@effect/platform-bun": "^0.44.0",
"@effect/platform-node": "^0.59.0",
"@effect/schema": "^0.72.3",
"@types/node": "^22.5.4",
"effect": "^3.7.2",
"@effect/platform": "^0.65.1",
"@effect/platform-bun": "^0.45.1",
"@effect/platform-node": "^0.60.1",
"@effect/schema": "^0.73.0",
"@types/node": "^22.5.5",
"effect": "^3.8.0",
"effect-http": "workspace:^"
}
}
6 changes: 3 additions & 3 deletions packages/effect-http-node/src/NodeTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const make: <R, E, A extends Api.Api.Any>(
export const makeRaw: <R, E>(
app: HttpApp.Default<E, R>
) => Effect.Effect<
HttpClient.HttpClient.Default,
HttpClient.HttpClient.Service,
never,
| Scope.Scope
| Exclude<
Expand Down Expand Up @@ -90,7 +90,7 @@ export const makeRaw: <R, E>(
*
* Effect.gen(function*() {
* const client = yield* NodeTesting.handler(myHandler)
* const response = yield* client(HttpClientRequest.get("/my-endpoint"))
* const response = yield* client.execute(HttpClientRequest.get("/my-endpoint"))
*
* assert.deepStrictEqual(response.status, 200)
* assert.deepStrictEqual(yield* response.json, { hello: "world" })
Expand All @@ -102,7 +102,7 @@ export const makeRaw: <R, E>(
export const handler: <A extends ApiEndpoint.ApiEndpoint.Any, E, R>(
app: Handler.Handler<A, E, R>
) => Effect.Effect<
HttpClient.HttpClient.Default,
HttpClient.HttpClient.Service,
never,
| Scope.Scope
| Exclude<
Expand Down
29 changes: 20 additions & 9 deletions packages/effect-http-node/src/internal/node-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { createServer } from "http"

import * as NodeContext from "@effect/platform-node/NodeContext"
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"
import * as FetchHttpClient from "@effect/platform/FetchHttpClient"
import type * as HttpApp from "@effect/platform/HttpApp"
import * as HttpClient from "@effect/platform/HttpClient"
import * as HttpClientRequest from "@effect/platform/HttpClientRequest"
import * as HttpServer from "@effect/platform/HttpServer"
import * as Context from "effect/Context"
import * as Deferred from "effect/Deferred"
import * as Effect from "effect/Effect"
import * as Layer from "effect/Layer"
import type * as Scope from "effect/Scope"

import type * as Api from "effect-http/Api"
import type * as ApiEndpoint from "effect-http/ApiEndpoint"
Expand All @@ -18,6 +21,14 @@ import type * as SwaggerRouter from "effect-http/SwaggerRouter"

import * as NodeSwaggerFiles from "../NodeSwaggerFiles.js"

/** @internal */
const defaultHttpClient = FetchHttpClient.layer.pipe(
Layer.build,
Effect.map(Context.get(HttpClient.HttpClient)),
Effect.scoped,
Effect.runSync
)

/** @internal */
export const make = <R, E, A extends Api.Api.Any>(
app: HttpApp.Default<R | SwaggerRouter.SwaggerFiles, E>,
Expand All @@ -28,7 +39,7 @@ export const make = <R, E, A extends Api.Api.Any>(
Effect.map((url) =>
Client.make(api, {
...options,
httpClient: makeHttpClient(options?.httpClient ?? HttpClient.fetch, url)
httpClient: makeHttpClient(options?.httpClient ?? defaultHttpClient, url)
})
),
Effect.provide(NodeSwaggerFiles.SwaggerFilesLive),
Expand All @@ -40,7 +51,7 @@ export const makeRaw = <R, E>(
app: HttpApp.Default<E, R | SwaggerRouter.SwaggerFiles>
) =>
startTestServer(app).pipe(
Effect.map((url) => makeHttpClient(HttpClient.fetch, url)),
Effect.map((url) => makeHttpClient(defaultHttpClient, url)),
Effect.provide(NodeSwaggerFiles.SwaggerFilesLive),
Effect.provide(NodeContext.layer)
)
Expand All @@ -50,7 +61,7 @@ export const handler = <A extends ApiEndpoint.ApiEndpoint.Any, E, R>(
handler: Handler.Handler<A, E, R>
) =>
startTestServer(Handler.getRouter(handler)).pipe(
Effect.map((url) => makeHttpClient(HttpClient.fetch, url)),
Effect.map((url) => makeHttpClient(defaultHttpClient, url)),
Effect.provide(NodeContext.layer)
)

Expand All @@ -68,14 +79,14 @@ const startTestServer = <R, E>(
))

/** @internal */
const makeHttpClient = (client: HttpClient.HttpClient.Default, url: string) =>
const makeHttpClient = (client: HttpClient.HttpClient.Service, url: string) =>
client.pipe(
HttpClient.mapRequest(HttpClientRequest.prependUrl(url)),
HttpClient.transform(
Effect.locallyWith(
HttpClient.currentFetchOptions,
(currentFetchOptions) => ({ keepalive: false, ...currentFetchOptions })
)
HttpClient.transformResponse(
Effect.mapInputContext((ctx: Context.Context<Scope.Scope>) => {
const init = ctx.unsafeMap.get(FetchHttpClient.RequestInit.key) ?? {}
return Context.add(ctx, FetchHttpClient.RequestInit, { keepalive: false, ...init })
})
)
)

Expand Down
Loading

0 comments on commit 2e4eaf8

Please sign in to comment.