From 180e5ba8f306af2a5414976112817c110c58f104 Mon Sep 17 00:00:00 2001 From: Antonin MOREL Date: Sat, 26 Sep 2026 12:21:16 +0200 Subject: [PATCH] chore(example): migrate example to effect v4 - @effect/platform -> effect/unstable/http + effect/unstable/httpapi - @effect/platform-bun on v4, server via HttpApiBuilder.layer + HttpRouter.serve + HttpRouter.cors - onError handlers updated for v4 error types (SchemaError, HttpClientError) - depend on @spiko-tech/effect-react-query ^2.0.0 --- example/package.json | 7 +++---- example/src/App.tsx | 6 ++---- example/src/api.ts | 11 ++++++----- example/src/backend.ts | 18 ++++++------------ example/src/client.ts | 5 +++-- 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/example/package.json b/example/package.json index d352042..c3633d7 100644 --- a/example/package.json +++ b/example/package.json @@ -9,10 +9,9 @@ "build": "bun build ./src/index.html --outdir=dist --sourcemap --target=browser --minify --define:process.env.NODE_ENV='\"production\"' --env='BUN_PUBLIC_*'" }, "dependencies": { - "@effect/platform": "^0.96.1", - "@effect/platform-bun": "^0.89.0", - "@spiko-tech/effect-react-query": "^1.1.0", - "effect": "^3.21.2", + "@effect/platform-bun": "4.0.0-rc.117", + "@spiko-tech/effect-react-query": "^2.0.0", + "effect": "4.0.0-rc.117", "react": "^19.2.5", "react-dom": "^19.2.5" }, diff --git a/example/src/App.tsx b/example/src/App.tsx index 2761675..32d4801 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -13,10 +13,8 @@ export function App() { apiClient.pipe(Effect.flatMap((client) => client.api.testMutation({ payload }))), onSuccess: () => console.log("Fetched successfully"), onError: Match.valueTags({ - HttpApiDecodeError: (e) => console.error("Decode error:", e.message), - ParseError: (e) => console.error("Parse error:", e.message), - RequestError: (e) => console.error("Request error:", e.message), - ResponseError: (e) => console.error("Response error:", e.message), + SchemaError: (e) => console.error("Schema error:", e.message), + HttpClientError: (e) => console.error("Http client error:", e.message), BadRequest: () => console.error("BadRequest"), }), }); diff --git a/example/src/api.ts b/example/src/api.ts index 132581d..633539a 100644 --- a/example/src/api.ts +++ b/example/src/api.ts @@ -1,15 +1,16 @@ -import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup } from "@effect/platform"; import { Schema } from "effect"; +import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/unstable/httpapi"; export const HelloResponse = Schema.Struct({ message: Schema.String, method: Schema.String, }); -const mutationEndpoint = HttpApiEndpoint.put("testMutation", "/mutation-test") - .setPayload(Schema.Literal("success", "error", "die")) - .addSuccess(HelloResponse) - .addError(HttpApiError.BadRequest); +const mutationEndpoint = HttpApiEndpoint.put("testMutation", "/mutation-test", { + payload: Schema.Literals(["success", "error", "die"]), + success: HelloResponse, + error: HttpApiError.BadRequest, +}); export const ApiGroup = HttpApiGroup.make("api").add(mutationEndpoint).prefix("/api"); diff --git a/example/src/backend.ts b/example/src/backend.ts index 0dbbe10..4a85754 100644 --- a/example/src/backend.ts +++ b/example/src/backend.ts @@ -1,6 +1,7 @@ -import { HttpApiBuilder, HttpApiError, HttpServer } from "@effect/platform"; import { BunHttpServer, BunRuntime } from "@effect/platform-bun"; import { Effect, Layer, Match } from "effect"; +import { HttpRouter } from "effect/unstable/http"; +import { HttpApiBuilder, HttpApiError } from "effect/unstable/httpapi"; import { Api } from "./api"; export const ApiGroupLive = HttpApiBuilder.group(Api, "api", (handlers) => @@ -19,17 +20,10 @@ export const ApiGroupLive = HttpApiBuilder.group(Api, "api", (handlers) => ), ); -const ApiLive = HttpApiBuilder.api(Api).pipe(Layer.provide(ApiGroupLive)); +const ApiLive = HttpApiBuilder.layer(Api).pipe(Layer.provide(ApiGroupLive)); -const ServerLive = HttpApiBuilder.serve().pipe( - Layer.provide( - HttpApiBuilder.middlewareCors({ - allowedOrigins: ["http://localhost:3200"], - }), - ), - Layer.provide(ApiLive), - HttpServer.withLogAddress, - Layer.provide(BunHttpServer.layer({ port: 3000 })), -); +const ServerLive = HttpRouter.serve( + Layer.mergeAll(ApiLive, HttpRouter.cors({ allowedOrigins: ["http://localhost:3200"] })), +).pipe(Layer.provide(BunHttpServer.layer({ port: 3000 }))); BunRuntime.runMain(Layer.launch(ServerLive)); diff --git a/example/src/client.ts b/example/src/client.ts index 579461d..397fe35 100644 --- a/example/src/client.ts +++ b/example/src/client.ts @@ -1,6 +1,7 @@ -import { FetchHttpClient, HttpApiClient } from "@effect/platform"; -import { Api } from "./api.js"; import { Effect } from "effect"; +import { FetchHttpClient } from "effect/unstable/http"; +import { HttpApiClient } from "effect/unstable/httpapi"; +import { Api } from "./api.js"; export const apiClient = HttpApiClient.make(Api, { baseUrl: "http://localhost:3000",