diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..93f962e --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@thilawyn:registry=https://git.jvalver.de/api/packages/thilawyn/npm/ diff --git a/bun.lockb b/bun.lockb index 87e2e98..ac6a6e8 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..bb40fbe --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,2 @@ +[install.scopes] +"@thilawyn" = "https://git.jvalver.de/api/packages/thilawyn/npm/" diff --git a/package.json b/package.json index e995c57..8e9f209 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "private": true, "workspaces": ["packages/*"], "devDependencies": { + "npm-check-updates": "^16.14.20", + "npm-sort": "^0.0.4", "typescript": "^5.5.2" } } diff --git a/packages/common/package.json b/packages/common/package.json index 16fcc2a..2b908bb 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,5 +1,13 @@ { "name": "@todo-tests/common", "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" + } } diff --git a/packages/common/src/data/Todo.ts b/packages/common/src/data/Todo.ts new file mode 100644 index 0000000..d3bb435 --- /dev/null +++ b/packages/common/src/data/Todo.ts @@ -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")({ + _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, +}) {} diff --git a/packages/common/src/data/index.ts b/packages/common/src/data/index.ts new file mode 100644 index 0000000..d5dbbf5 --- /dev/null +++ b/packages/common/src/data/index.ts @@ -0,0 +1 @@ +export * from "./Todo" diff --git a/packages/server/package.json b/packages/server/package.json index 7076209..7039a46 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -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" } } diff --git a/packages/server/src/Todos.ts b/packages/server/src/Todos.ts new file mode 100644 index 0000000..9da8fc5 --- /dev/null +++ b/packages/server/src/Todos.ts @@ -0,0 +1,5 @@ +import type { Todo } from "@todo-tests/common/data" +import { Context, Ref } from "effect" + + +export class Todos extends Context.Tag("Todos")>() {} diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts new file mode 100644 index 0000000..f76c65a --- /dev/null +++ b/packages/server/src/index.ts @@ -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)