Todos service
This commit is contained in:
1
.npmrc
Normal file
1
.npmrc
Normal file
@@ -0,0 +1 @@
|
|||||||
|
@thilawyn:registry=https://git.jvalver.de/api/packages/thilawyn/npm/
|
||||||
2
bunfig.toml
Normal file
2
bunfig.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[install.scopes]
|
||||||
|
"@thilawyn" = "https://git.jvalver.de/api/packages/thilawyn/npm/"
|
||||||
@@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
packages/common/src/data/Todo.ts
Normal file
16
packages/common/src/data/Todo.ts
Normal 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,
|
||||||
|
}) {}
|
||||||
1
packages/common/src/data/index.ts
Normal file
1
packages/common/src/data/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from "./Todo"
|
||||||
@@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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