| 1 | import * as Fly from "alchemy/Fly"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | |
| 4 | export interface User { |
| 5 | id: string; |
| 6 | name: string; |
| 7 | } |
| 8 | |
| 9 | export const USERS: User[] = [ |
| 10 | { id: "u1", name: "Ada" }, |
| 11 | { id: "u2", name: "Grace" }, |
| 12 | ]; |
| 13 | |
| 14 | /** |
| 15 | * Private Service. `public: false` gives it no internet address, and |
| 16 | * `network: Fly.stackNetwork` puts it on a private network that only this |
| 17 | * stage's Services join. It returns methods, which Services that bind it |
| 18 | * with `Fly.bindService(Users)` call. |
| 19 | */ |
| 20 | export default class Users extends Fly.Service<Users>()( |
| 21 | "Users", |
| 22 | Effect.gen(function* () { |
| 23 | return { |
| 24 | main: import.meta.url, |
| 25 | public: false, |
| 26 | network: yield* Fly.stackNetwork, |
| 27 | }; |
| 28 | }), |
| 29 | Effect.gen(function* () { |
| 30 | return { |
| 31 | list: () => Effect.succeed(USERS), |
| 32 | get: (id: string) => Effect.succeed(USERS.find((user) => user.id === id)), |
| 33 | }; |
| 34 | }), |
| 35 | ) {} |