t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Git/fixtures/http.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

41 lines
1.5 KiB
TypeScript

import * as Http from "@/Http/index.ts";
import * as Layer from "effect/Layer";
/** Standard Effect HTTP group registration with an application user handler. */
import { GitApi, GroupsLive, InternalApiLive, Handlers } from "@/Git/index.ts";
import * as Effect from "effect/Effect";
import * as Option from "effect/Option";
import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import { TestCaller, TestAuthLive } from "./test-auth.ts";
export const GitHubLive = HttpApiBuilder.group(GitApi, "github", (h) =>
Effect.map(Handlers, (git) =>
h.handleAll({
...git.github,
user: () =>
Effect.gen(function* () {
const caller = yield* Effect.serviceOption(TestCaller);
const user = Option.isSome(caller) ? caller.value.user : null;
return user === null
? HttpServerResponse.jsonUnsafe(
{ message: "Requires authentication" },
{ status: 401 },
)
: HttpServerResponse.jsonUnsafe({
login: user.name,
id: 1,
type: "User",
});
}),
}),
),
);
/** The test application's router: public Git routes plus the internal hash route. */
export const TestRoutes = Layer.mergeAll(
HttpApiBuilder.layer(GitApi).pipe(
Layer.provide(Layer.mergeAll(GroupsLive, GitHubLive)),
Layer.provide(TestAuthLive),
),
InternalApiLive,
).pipe(Layer.provide(Http.Platform));