Skip to content

Commit 549859b

Browse files
authored
chore: update effect dependencies (sukovanej#448)
1 parent cfb91a8 commit 549859b

19 files changed

+1580
-1528
lines changed

.changeset/twelve-weeks-vanish.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"effect-http-node": patch
3+
"effect-http": patch
4+
---
5+
6+
Update effect dependencies.

README.md

+36-32
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ Bootstrap a simple API specification.
6363

6464
```typescript
6565
import { Schema } from "@effect/schema";
66-
import { Effect, pipe } from "effect";
67-
import { Api, Client, RouterBuilder } from "effect-http";
68-
import { NodeServer } from "effect-http-node";
66+
import { Api } from "effect-http";
6967

7068
const User = Schema.struct({
7169
name: Schema.string,
@@ -84,6 +82,9 @@ const api = Api.api({ title: "Users API" }).pipe(
8482
Create the app implementation.
8583

8684
```typescript
85+
import { Effect, pipe } from "effect";
86+
import { RouterBuilder } from "effect-http";
87+
8788
const app = pipe(
8889
RouterBuilder.make(api),
8990
RouterBuilder.handle("getUser", ({ query }) =>
@@ -96,21 +97,27 @@ const app = pipe(
9697
Now, we can generate an object providing the HTTP client interface using `Client.make`.
9798

9899
```typescript
100+
import { Client } from "effect-http";
101+
99102
const client = Client.make(api, { baseUrl: "http://localhost:3000" });
100103
```
101104

102105
Spawn the server on port 3000,
103106

104107
```typescript
105-
app.pipe(NodeServer.listen({ port: 3000 }), runMain);
108+
import { NodeRuntime } from "@effect/platform-node"
109+
import { NodeServer } from "effect-http-node";
110+
111+
app.pipe(NodeServer.listen({ port: 3000 }), NodeRuntime.runMain);
106112
```
107113

108114
and call it using the `client`.
109115

110116
```ts
111-
const callServer = pipe(
117+
const response = pipe(
112118
client.getUser({ query: { id: 12 } }),
113119
Effect.flatMap((user) => Effect.log(`Got ${user.name}, nice!`)),
120+
Effect.scoped,
114121
);
115122
```
116123

@@ -193,7 +200,7 @@ a mapping from header names onto their schemas. The example below shows an API w
193200
a single endpoint `/hello` which expects a header `X-Client-Id` to be present.
194201

195202
```typescript
196-
import { runMain } from "@effect/platform-node/Runtime";
203+
import { NodeRuntime } from "@effect/platform-node";
197204
import { Schema } from "@effect/schema";
198205
import { pipe } from "effect";
199206
import { Api, ExampleServer, RouterBuilder } from "effect-http";
@@ -212,7 +219,7 @@ pipe(
212219
ExampleServer.make(api),
213220
RouterBuilder.build,
214221
NodeServer.listen({ port: 3000 }),
215-
runMain,
222+
NodeRuntime.runMain,
216223
);
217224
```
218225

@@ -403,6 +410,7 @@ import { NodeTesting } from 'effect-http-node';
403410
test("test /hello endpoint", async () => {
404411
const response = await NodeTesting.make(app, api).pipe(
405412
Effect.flatMap((client) => client.hello({ query: { input: 12 } })),
413+
Effect.scoped,
406414
Effect.runPromise,
407415
);
408416

@@ -481,39 +489,35 @@ so we can see the failure behavior.
481489

482490
```typescript
483491
interface UserRepository {
484-
existsByName: (name: string) => Effect.Effect<never, never, boolean>;
485-
store: (user: string) => Effect.Effect<never, never, void>;
492+
userExistsByName: (name: string) => Effect.Effect<boolean>;
493+
storeUser: (user: string) => Effect.Effect<void>;
486494
}
487495

488-
const UserRepository = Context.Tag<UserRepository>();
496+
const UserRepository = Context.GenericTag<UserRepository>("UserRepository");
489497

490498
const mockUserRepository = UserRepository.of({
491-
existsByName: () => Effect.succeed(true),
492-
store: () => Effect.unit,
499+
userExistsByName: () => Effect.succeed(true),
500+
storeUser: () => Effect.unit,
493501
});
502+
503+
const { userExistsByName, storeUser } = Effect.serviceFunctions(UserRepository);
494504
```
495505

496506
And finally, we have the actual `App` implementation.
497507

498508
```typescript
509+
499510
const app = RouterBuilder.make(api).pipe(
500511
RouterBuilder.handle("storeUser", ({ body }) =>
501512
pipe(
502-
Effect.flatMap(UserRepository, (userRepository) =>
503-
userRepository.existsByName(body.name),
504-
),
513+
userExistsByName(body.name),
505514
Effect.filterOrFail(
506515
(alreadyExists) => !alreadyExists,
507516
() => ServerError.conflictError(`User "${body.name}" already exists.`),
508517
),
509-
Effect.flatMap(() =>
510-
Effect.flatMap(UserRepository, (repository) =>
511-
repository.store(body.name),
512-
),
513-
),
518+
Effect.andThen(storeUser(body.name)),
514519
Effect.map(() => `User "${body.name}" stored.`),
515-
),
516-
),
520+
)),
517521
RouterBuilder.build,
518522
);
519523
```
@@ -525,7 +529,7 @@ the `mockUserRepository` service.
525529
app.pipe(
526530
NodeServer.listen({ port: 3000 }),
527531
Effect.provideService(UserRepository, mockUserRepository),
528-
Effect.runPromise,
532+
NodeRuntime.runMain
529533
);
530534
```
531535

@@ -570,7 +574,7 @@ This enables separability of concers for big APIs and provides information for
570574
generation of tags for the OpenAPI specification.
571575
572576
```typescript
573-
import { runMain } from "@effect/platform-node/Runtime";
577+
import { NodeRuntime } from "@effect/platform-node";
574578
import { Schema } from "@effect/schema";
575579
import { Api, ExampleServer, RouterBuilder } from "effect-http";
576580
import { NodeServer } from "effect-http-node";
@@ -604,7 +608,7 @@ const api = Api.api().pipe(
604608
ExampleServer.make(api).pipe(
605609
RouterBuilder.build,
606610
NodeServer.listen({ port: 3000 }),
607-
runMain,
611+
NodeRuntime.runMain,
608612
);
609613
```
610614
@@ -638,8 +642,8 @@ For an operation-level description, call the API endpoint method (`Api.get`,
638642
desired description.
639643
640644
```ts
641-
import { runMain } from "@effect/platform-node/Runtime";
642-
import * as Schema from "@effect/schema/Schema";
645+
import { NodeRuntime } from "@effect/platform-node";
646+
import { Schema } from "@effect/schema";
643647
import { Effect, pipe } from "effect";
644648
import { Api, RouterBuilder } from "effect-http";
645649
import { NodeServer } from "effect-http-node";
@@ -676,7 +680,7 @@ const app = RouterBuilder.make(api).pipe(
676680
RouterBuilder.build,
677681
);
678682
679-
app.pipe(NodeServer.listen({ port: 3000 }), runMain);
683+
app.pipe(NodeServer.listen({ port: 3000 }), NodeRuntime.runMain);
680684
```
681685
682686
## Representations
@@ -716,7 +720,7 @@ be used, and if there is no representation matching the incomming `Accept` media
716720
it will choose the first representation in the list.
717721
718722
```ts
719-
import { runMain } from "@effect/platform-node/Runtime";
723+
import { NodeRuntime } from "@effect/platform-node";
720724
import { Schema } from "@effect/schema";
721725
import { Effect } from "effect";
722726
import { Api, Representation, RouterBuilder } from "effect-http";
@@ -745,7 +749,7 @@ const program = app.pipe(
745749
Effect.provide(PrettyLogger.layer()),
746750
);
747751
748-
runMain(program);
752+
NodeRuntime.runMain(program);
749753
```
750754
751755
Try running the server above and call the root path with different
@@ -790,7 +794,7 @@ helpful in the following and probably many more cases.
790794
Use `ExampleServer.make` combinator to generate a `RouterBuilder` from an `Api`.
791795
792796
```typescript
793-
import { runMain } from "@effect/platform-node/Runtime";
797+
import { NodeRuntime } from "@effect/platform-node";
794798
import { Schema } from "@effect/schema";
795799
import { Effect, pipe } from "effect";
796800
import { Api, ExampleServer, RouterBuilder } from "effect-http";
@@ -807,7 +811,7 @@ pipe(
807811
ExampleServer.make(api),
808812
RouterBuilder.build,
809813
NodeServer.listen({ port: 3000 }),
810-
runMain,
814+
NodeRuntime.runMain,
811815
);
812816
```
813817

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
"@effect/dtslint": "^0.0.4",
3232
"@effect/eslint-plugin": "^0.1.2",
3333
"@effect/language-service": "^0.1.0",
34-
"@types/node": "^20.11.18",
34+
"@types/node": "^20.11.19",
3535
"@types/swagger-ui-dist": "^3.30.4",
36-
"@typescript-eslint/eslint-plugin": "^7.0.1",
37-
"@typescript-eslint/parser": "^7.0.1",
38-
"@vitest/coverage-v8": "^1.2.2",
36+
"@typescript-eslint/eslint-plugin": "^7.0.2",
37+
"@typescript-eslint/parser": "^7.0.2",
38+
"@vitest/coverage-v8": "^1.3.0",
3939
"babel-plugin-annotate-pure-calls": "^0.4.0",
4040
"eslint": "^8.56.0",
4141
"eslint-import-resolver-typescript": "^3.6.1",
@@ -50,7 +50,7 @@
5050
"rimraf": "^5.0.5",
5151
"tsx": "^4.7.1",
5252
"typescript": "^5.3.3",
53-
"vitest": "^1.2.2"
53+
"vitest": "^1.3.0"
5454
},
5555
"pnpm": {
5656
"patchedDependencies": {

packages/effect-http-node/examples/conflict-error-example.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,28 @@ const api = pipe(
1717
)
1818

1919
interface UserRepository {
20-
existsByName: (name: string) => Effect.Effect<boolean>
21-
store: (user: string) => Effect.Effect<void>
20+
userExistsByName: (name: string) => Effect.Effect<boolean>
21+
storeUser: (user: string) => Effect.Effect<void>
2222
}
2323

24-
const UserRepository = Context.GenericTag<UserRepository>("@services/UserRepository")
24+
const UserRepository = Context.GenericTag<UserRepository>("UserRepository")
2525

2626
const mockUserRepository = UserRepository.of({
27-
existsByName: () => Effect.succeed(true),
28-
store: () => Effect.unit
27+
userExistsByName: () => Effect.succeed(true),
28+
storeUser: () => Effect.unit
2929
})
3030

31+
const { storeUser, userExistsByName } = Effect.serviceFunctions(UserRepository)
32+
3133
const app = RouterBuilder.make(api).pipe(
3234
RouterBuilder.handle("storeUser", ({ body }) =>
3335
pipe(
34-
Effect.flatMap(UserRepository, (userRepository) => userRepository.existsByName(body.name)),
36+
userExistsByName(body.name),
3537
Effect.filterOrFail(
3638
(alreadyExists) => !alreadyExists,
3739
() => ServerError.conflictError(`User "${body.name}" already exists.`)
3840
),
39-
Effect.flatMap(() => Effect.flatMap(UserRepository, (repository) => repository.store(body.name))),
41+
Effect.andThen(storeUser(body.name)),
4042
Effect.map(() => `User "${body.name}" stored.`)
4143
)),
4244
RouterBuilder.build,

packages/effect-http-node/examples/esm-example/schemas.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export const CreateItemResponse = Item.pipe(Schema.pick("id", "createdAt"))
2525
export const GetItemsQuery = Item.pipe(
2626
Schema.pick("title", "content"),
2727
Schema.extend(Schema.struct({ id: IntegerFromString })),
28-
Schema.partial
28+
(schema) => Schema.partial(schema)
2929
)
3030
export type GetItemsQuery = Schema.Schema.To<typeof GetItemsQuery>

packages/effect-http-node/examples/handle-raw.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { HttpServer } from "@effect/platform"
2+
import { NodeRuntime } from "@effect/platform-node"
23
import { Schema } from "@effect/schema"
34
import { Effect } from "effect"
45
import { Api, RouterBuilder } from "effect-http"
@@ -31,4 +32,4 @@ const program = app.pipe(
3132
Effect.provide(PrettyLogger.layer())
3233
)
3334

34-
Effect.runPromise(program)
35+
NodeRuntime.runMain(program)

packages/effect-http-node/examples/headers-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ Effect.all(
2424
Effect.catchAll((e) => Effect.logInfo(`Error ${JSON.stringify(e)}`)),
2525
ReadonlyArray.replicate(1000000)
2626
)
27-
).pipe(Effect.runPromise)
27+
).pipe(Effect.scoped, Effect.runPromise)

packages/effect-http-node/examples/readme-quickstart.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const client = Client.make(api, { baseUrl: "http://localhost:3000" })
3434

3535
const program = pipe(
3636
client.getUser({ query: { id: 12 } }),
37-
Effect.flatMap((user) => Effect.log(`Got ${user.name}, nice!`))
37+
Effect.flatMap((user) => Effect.log(`Got ${user.name}, nice!`)),
38+
Effect.scoped
3839
)
3940

4041
Effect.runPromise(program)

packages/effect-http-node/package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
"coverage": "vitest --coverage"
3030
},
3131
"dependencies": {
32-
"swagger-ui-dist": "^5.11.3"
32+
"swagger-ui-dist": "^5.11.7"
3333
},
3434
"peerDependencies": {
35-
"@effect/platform": "^0.44.2",
36-
"@effect/platform-node": "^0.43.2",
37-
"@effect/schema": "^0.62.1",
38-
"effect": "^2.3.1",
35+
"@effect/platform": "^0.45.5",
36+
"@effect/platform-node": "^0.44.6",
37+
"@effect/schema": "^0.62.8",
38+
"effect": "^2.3.7",
3939
"effect-http": "workspace:^"
4040
},
4141
"devDependencies": {
42-
"@effect/platform": "^0.44.2",
43-
"@effect/platform-bun": "^0.31.2",
44-
"@effect/platform-node": "^0.43.2",
45-
"@effect/schema": "^0.62.1",
46-
"@types/node": "^20.11.17",
47-
"effect": "^2.3.1",
42+
"@effect/platform": "^0.45.5",
43+
"@effect/platform-bun": "^0.32.5",
44+
"@effect/platform-node": "^0.44.6",
45+
"@effect/schema": "^0.62.8",
46+
"@types/node": "^20.11.19",
47+
"effect": "^2.3.7",
4848
"effect-http": "workspace:^",
49-
"effect-log": "^0.29.0"
49+
"effect-log": "^0.30.0"
5050
}
5151
}

packages/effect-http-node/src/NodeTesting.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const makeRaw: <R, E>(
4747
app: HttpServer.app.Default<R, E>
4848
) => Effect.Effect<
4949
HttpClient.client.Client<
50-
never,
50+
Scope.Scope,
5151
HttpClient.error.HttpClientError,
5252
HttpClient.response.ClientResponse
5353
>,

0 commit comments

Comments
 (0)