Todos service
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
"@effect/platform": "^0.58.12",
|
||||
"@effect/platform-bun": "^0.38.11",
|
||||
"@effect/schema": "^0.68.11",
|
||||
"@thilawyn/thilalib": "^0.1.3",
|
||||
"@todo-tests/common": "workspace:*",
|
||||
"effect": "^3.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
5
packages/server/src/Todos.ts
Normal file
5
packages/server/src/Todos.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { Todo } from "@todo-tests/common/data"
|
||||
import { Context, Ref } from "effect"
|
||||
|
||||
|
||||
export class Todos extends Context.Tag("Todos")<Todos, Ref.Ref<Todo[]>>() {}
|
||||
36
packages/server/src/index.ts
Normal file
36
packages/server/src/index.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { BunRuntime } from "@effect/platform-bun"
|
||||
import { Todo } from "@todo-tests/common/data"
|
||||
import { Array, Effect, Option, Ref } from "effect"
|
||||
import { Todos } from "./Todos"
|
||||
|
||||
|
||||
const createDefaultTodos = Todos.pipe(
|
||||
Effect.flatMap(ref =>
|
||||
Ref.update(ref, todos =>
|
||||
Array.appendAll(todos, [
|
||||
new Todo({
|
||||
id: "1",
|
||||
title: "A test todo",
|
||||
content: "Lorem ipsum",
|
||||
due: Option.none(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
])
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
const main = Effect.gen(function*() {
|
||||
yield* createDefaultTodos
|
||||
|
||||
const todos = yield* Todos
|
||||
console.log(yield* Ref.get(todos))
|
||||
})
|
||||
|
||||
const runnableMain = main.pipe(
|
||||
Effect.provideServiceEffect(Todos, Ref.make(Array.empty()))
|
||||
)
|
||||
|
||||
BunRuntime.runMain(runnableMain)
|
||||
Reference in New Issue
Block a user