79 lines
2.6 KiB
TypeScript
79 lines
2.6 KiB
TypeScript
import { BunRuntime } from "@effect/platform-bun"
|
|
import { Todo, type IdentifiedTodo } from "@todo-tests/common/data"
|
|
import { Identifiable } from "@todo-tests/common/traits"
|
|
import { Chunk, Effect, Layer, Stream } from "effect"
|
|
import { ServicesLive } from "./Services"
|
|
import { TodoRepository, createDefaultTodos } from "./TodoRepository"
|
|
import { ExpressApp } from "./express/ExpressApp"
|
|
import { ExpressHTTPServer } from "./express/ExpressHTTPServer"
|
|
import { RPCPlaygroundRoute } from "./rpc/RPCPlaygroundRoute"
|
|
import { RPCRouter } from "./rpc/RPCRouter"
|
|
import { RPCServerRoute } from "./rpc/RPCServerRoute"
|
|
import { RPCProcedureBuilder } from "./rpc/procedures/RPCProcedureBuilder"
|
|
import { TRPCBuilder } from "./trpc/TRPCBuilder"
|
|
import { TRPCContextCreator } from "./trpc/TRPCContextCreator"
|
|
|
|
|
|
const ServerDev = ExpressHTTPServer.Live.pipe(
|
|
Layer.provide(RPCServerRoute.Live),
|
|
Layer.provide(RPCPlaygroundRoute.Dev),
|
|
Layer.provide(RPCRouter.Live),
|
|
Layer.provide(RPCProcedureBuilder.Live),
|
|
Layer.provide(TRPCBuilder.Live),
|
|
Layer.provide(TRPCContextCreator.Live),
|
|
Layer.provide(ExpressApp.Live),
|
|
)
|
|
|
|
|
|
const watchTodoChanges = Effect.gen(function*() {
|
|
const todos = yield* TodoRepository
|
|
// yield* Stream.runForEach(todos.todos.changes, todos => Console.log(`Todos changed: ${ todos }`))
|
|
yield* todos.todos.changes.pipe(
|
|
Stream.runFold(
|
|
Chunk.empty<IdentifiedTodo>(),
|
|
|
|
(prev, curr) => {
|
|
console.log(`Added todos: ${ Chunk.differenceWith<Todo>(Identifiable.equals)(curr, prev) }`)
|
|
console.log(`Removed todos: ${ Chunk.differenceWith<Todo>(Identifiable.equals)(prev, curr) }`)
|
|
|
|
return curr
|
|
},
|
|
)
|
|
)
|
|
})
|
|
|
|
const main = Effect.gen(function*() {
|
|
// const watcher = yield* Effect.fork(watchTodoChanges)
|
|
yield* createDefaultTodos
|
|
|
|
// const todos = yield* TodoRepository
|
|
|
|
// const secondTodo = yield* yield* todos.todos.get.pipe(
|
|
// Effect.map(Array.get(1))
|
|
// )
|
|
// const secondTodoModified = new Todo({
|
|
// ...secondTodo,
|
|
// completed: true,
|
|
// })
|
|
// yield* todos.update(secondTodoModified)
|
|
|
|
// yield* todos.add(new Todo({
|
|
// id: Option.none(),
|
|
// title: "Put the dishes in the dishwasher",
|
|
// content: "Lorem ipsum",
|
|
// due: Option.none(),
|
|
// completed: false,
|
|
// createdAt: new Date(),
|
|
// updatedAt: new Date(),
|
|
// })).pipe(
|
|
// Effect.delay(Duration.seconds(1))
|
|
// )
|
|
|
|
// yield* Fiber.join(watcher)
|
|
yield* Layer.launch(ServerDev)
|
|
})
|
|
|
|
BunRuntime.runMain(main.pipe(
|
|
Effect.provide(ServicesLive)
|
|
))
|