The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import { dieOnStore } from "./errors.ts"; |
| 6 | import { Links, LinksSql } from "./Links.ts"; |
| 7 | import { serve } from "./serve.ts"; |
| 8 | import { ShortyApi } from "./ShortyApi.ts"; |
| 9 | import { NeonStorage } from "./Storage.ts"; |
| 10 | |
| 11 | // #region show |
| 12 | export default Cloudflare.Worker( |
| 13 | "Api", |
| 14 | { main: import.meta.url }, |
| 15 | Effect.gen(function* () { |
| 16 | const links = yield* Links; |
| 17 | // #region handlers |
| 18 | |
| 19 | const handlers = HttpApiBuilder.group( |
| 20 | ShortyApi, |
| 21 | "links", |
| 22 | (h) => |
| 23 | h |
| 24 | .handle("create", ({ payload }) => links.create(payload.url).pipe(Effect.orDie)) |
| 25 | // #region get |
| 26 | .handle("get", ({ params }) => links.get(params.code).pipe(dieOnStore)) |
| 27 | // #endregion get |
| 28 | // #region list |
| 29 | .handle("list", () => links.list().pipe(Effect.orDie)), |
| 30 | // #endregion list |
| 31 | ); |
| 32 | // #endregion handlers |
| 33 | // #region fetch |
| 34 | |
| 35 | return { fetch: yield* serve(handlers) }; |
| 36 | // #endregion fetch |
| 37 | }).pipe(Effect.provide(LinksSql.pipe(Layer.provide(NeonStorage)))), |
| 38 | ); |
| 39 | // #endregion show |