t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Fly/fixtures/rpc-users.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

55 lines
1.6 KiB
TypeScript

import * as Fly from "@/Fly";
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import { HttpServerRequest } from "effect/http/HttpServerRequest";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
export const USERS = [
{ id: "u1", name: "Ada" },
{ id: "u2", name: "Grace" },
];
/**
* Private Service on the stack network. It serves methods to bound callers,
* plain HTTP routes, and an admin port (9000) for `Fly.bindEndpoint`.
*/
export default class RpcUsers extends Fly.Service<RpcUsers>()(
"RpcUsers",
Effect.gen(function* () {
return {
main: import.meta.url,
region: "iad",
public: false,
network: yield* Fly.stackNetwork,
guest: { cpuKind: "shared" as const, cpus: 1, memoryMb: 256 },
services: [
{
protocol: "tcp",
internalPort: 3000,
autostop: "off" as const,
ports: [{ port: 80, handlers: ["http"] }],
},
{
protocol: "tcp",
internalPort: 3000,
autostop: "off" as const,
ports: [{ port: 9000, handlers: ["http"] }],
},
],
};
}),
Effect.gen(function* () {
return {
listUsers: () => Effect.succeed(USERS),
getUser: (id: string) =>
Effect.succeed(USERS.find((user) => user.id === id)),
streamUsers: () => Stream.fromIterable(USERS),
fetch: Effect.gen(function* () {
const request = yield* HttpServerRequest;
return HttpServerResponse.text(
`users-http ${request.headers["fly-forwarded-port"] ?? ""} ${request.url}`,
);
}),
};
}),
) {}