Todos service

This commit is contained in:
Julien Valverdé
2024-06-27 10:35:52 +02:00
parent d6517365a7
commit 3dbb465500
10 changed files with 74 additions and 1 deletions

1
.npmrc Normal file
View File

@@ -0,0 +1 @@
@thilawyn:registry=https://git.jvalver.de/api/packages/thilawyn/npm/

BIN
bun.lockb

Binary file not shown.

2
bunfig.toml Normal file
View File

@@ -0,0 +1,2 @@
[install.scopes]
"@thilawyn" = "https://git.jvalver.de/api/packages/thilawyn/npm/"

View File

@@ -4,6 +4,8 @@
"private": true, "private": true,
"workspaces": ["packages/*"], "workspaces": ["packages/*"],
"devDependencies": { "devDependencies": {
"npm-check-updates": "^16.14.20",
"npm-sort": "^0.0.4",
"typescript": "^5.5.2" "typescript": "^5.5.2"
} }
} }

View File

@@ -1,5 +1,13 @@
{ {
"name": "@todo-tests/common", "name": "@todo-tests/common",
"type": "module", "type": "module",
"private": true "exports": {
"./data": "./src/data/index.ts"
},
"private": true,
"dependencies": {
"@effect/schema": "^0.68.12",
"@thilawyn/thilalib": "^0.1.3",
"effect": "^3.4.5"
}
} }

View File

@@ -0,0 +1,16 @@
import { Schema as S } from "@effect/schema"
import { Tag } from "@thilawyn/thilalib/effect/schema"
import { Class } from "@thilawyn/thilalib/effect/schema/class"
export class Todo extends Class<Todo>("Todo")({
_tag: Tag("Todo"),
id: S.String,
title: S.String,
content: S.String,
due: S.optional(S.DateFromSelf, { as: "Option" }),
createdAt: S.DateFromSelf,
updatedAt: S.DateFromSelf,
}) {}

View File

@@ -0,0 +1 @@
export * from "./Todo"

View File

@@ -6,6 +6,8 @@
"@effect/platform": "^0.58.12", "@effect/platform": "^0.58.12",
"@effect/platform-bun": "^0.38.11", "@effect/platform-bun": "^0.38.11",
"@effect/schema": "^0.68.11", "@effect/schema": "^0.68.11",
"@thilawyn/thilalib": "^0.1.3",
"@todo-tests/common": "workspace:*",
"effect": "^3.4.4" "effect": "^3.4.4"
} }
} }

View 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[]>>() {}

View 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)