Skip to content

Commit

Permalink
alt: still separate Domain.
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Jan 19, 2025
1 parent db3d959 commit c68ea81
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 53 deletions.
40 changes: 15 additions & 25 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@
}
},
"imports": {
"#api/*": {
"import": {
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
},
"require": {
"types": "./dist/*.d.ts",
"default": "./_cjs/*.cjs"
}
},
"#core/*": {
"import": {
"types": "./dist/core/*.d.ts",
Expand All @@ -75,16 +65,6 @@
"default": "./_cjs/core/*.cjs"
}
},
"#models": {
"import": {
"types": "./dist/models.d.ts",
"default": "./dist/models.js"
},
"require": {
"types": "./dist/models.d.ts",
"default": "./_cjs/models.cjs"
}
},
"#resources": {
"import": {
"types": "./dist/resources.d.ts",
Expand All @@ -95,14 +75,14 @@
"default": "./_cjs/resources.cjs"
}
},
"#models/*": {
"#Domain/*": {
"import": {
"types": "./dist/models/*.d.ts",
"default": "./dist/models/*.js"
"types": "./dist/Domain/*.d.ts",
"default": "./dist/Domain/*.js"
},
"require": {
"types": "./dist/models/*.d.ts",
"default": "./_cjs/models/*.cjs"
"types": "./dist/Domain/*.d.ts",
"default": "./_cjs/Domain/*.cjs"
}
},
"#resources/*": {
Expand All @@ -114,6 +94,16 @@
"types": "./dist/resources/*.d.ts",
"default": "./_cjs/resources/*.cjs"
}
},
"#api/*": {
"import": {
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
},
"require": {
"types": "./dist/*.d.ts",
"default": "./_cjs/*.cjs"
}
}
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions api/src/Accounts/UserRepo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { RepoConfig } from "#api/config"
import { RepoDefault } from "#api/lib/layers"
import { User } from "#Domain/User"
import type { UserId } from "#Domain/User"
import { Model } from "@effect-app/infra"
import { NotFoundError, NotLoggedInError } from "@effect-app/infra/errors"
import { Q } from "@effect-app/infra/Model"
Expand All @@ -9,8 +11,6 @@ import { fakerArb } from "effect-app/faker"
import { Email } from "effect-app/Schema"
import fc from "fast-check"
import { UserProfile } from "../UserProfile.js"
import type { UserId } from "./models.js"
import { User } from "./models.js"

export type UserSeed = "sample" | ""

Expand Down
2 changes: 1 addition & 1 deletion api/src/Accounts/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UserId } from "#Domain/User"
import { clientFor } from "#resources/lib"
import { Effect, Exit, Request, RequestResolver } from "effect"
import { Array, Option, pipe, S } from "effect-app"
import { ApiClientFactory, NotFoundError } from "effect-app/client"
import { type Schema } from "effect-app/Schema"
import { UserId } from "./models.js"
import { AccountsRsc, UserView } from "./resources.js"

interface GetUserViewById extends Request.Request<UserView, NotFoundError<"User">> {
Expand Down
2 changes: 1 addition & 1 deletion api/src/Accounts/resources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { User, UserId } from "#Domain/User"
import { S } from "#resources/lib"
import { NotFoundError } from "effect-app/client"
import { User, UserId } from "./models.js"

export class UserView extends S.ExtendedClass<UserView, UserView.Encoded>()({
...User.pick("id", "role"),
Expand Down
4 changes: 2 additions & 2 deletions api/src/Blog/BlogPostRepo.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { UserFromIdResolver } from "#Accounts/models"
import { UserRepo } from "#Accounts/UserRepo"
import { RepoDefault } from "#api/lib/layers"
import { BlogPost } from "#Domain/Blog"
import { UserFromIdResolver } from "#Domain/User"
import { Model } from "@effect-app/infra"
import { Effect } from "effect"
import { Context } from "effect-app"
import { NonEmptyString255, NonEmptyString2k } from "effect-app/Schema"
import { BlogPost } from "./models.js"

export type BlogPostSeed = "sample" | ""

Expand Down
2 changes: 1 addition & 1 deletion api/src/Blog/controllers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { UserRepo } from "#api/Accounts/UserRepo"
import { Events } from "#api/Events"
import { matchFor, Router } from "#api/lib/routing"
import { BlogPost } from "#Domain/Blog"
import { BogusEvent } from "#resources/Events"
import { Operations } from "@effect-app/infra/Operations"
import { Duration, Effect, Schedule } from "effect"
import { Option } from "effect-app"
import { NonEmptyString2k, NonNegativeInt } from "effect-app/Schema"
import { OperationsDefault } from "../lib/layers.js"
import { BlogPostRepo } from "./BlogPostRepo.js"
import { BlogPost } from "./models.js"
import { BlogRsc } from "./resources.js"

export default Router(BlogRsc)({
Expand Down
2 changes: 1 addition & 1 deletion api/src/Blog/resources.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { UserViewFromId } from "#api/Accounts/resolvers"
import { BlogPost, BlogPostId } from "#Domain/Blog"
import { S } from "#resources/lib"
import { InvalidStateError, NotFoundError, OptimisticConcurrencyException } from "effect-app/client"
import { OperationId } from "effect-app/Operations"
import { BlogPost, BlogPostId } from "./models.js"

export class BlogPostView extends S.ExtendedClass<BlogPostView, BlogPostView.Encoded>()({
...BlogPost.omit("author"),
Expand Down
2 changes: 1 addition & 1 deletion api/src/Blog/models.ts → api/src/Domain/Blog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UserFromId } from "#Accounts/models"
import { S } from "effect-app"
import { UserFromId } from "./User.js"

export const BlogPostId = S.prefixedStringId<BlogPostId>()("post", "BlogPostId")
export interface BlogPostIdBrand {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion api/src/HelloWorld/controllers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { User } from "#api/Accounts/models"
import { UserRepo } from "#api/Accounts/UserRepo"
import { matchFor, Router } from "#api/lib/routing"
import { User } from "#Domain/User"
import { getRequestContext } from "@effect-app/infra/api/setupRequest"
import { generate } from "@effect-app/infra/test"
import { Effect, S } from "effect-app"
Expand Down
2 changes: 1 addition & 1 deletion api/src/UserProfile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Role } from "#Domain/User"
import { parseJwt } from "@effect-app/infra/api/routing/schema/jwt"
import { Context, S } from "effect-app"
import { UserProfileId } from "effect-app/ids"
import { Role } from "./Accounts/models.js"

export class UserProfile extends Context.assignTag<UserProfile>()(
S.Class<UserProfile>()({
Expand Down
2 changes: 1 addition & 1 deletion api/src/resources/lib/req.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Role } from "#api/Accounts/models"
import type { Role } from "#Domain/User"
import { NotLoggedInError, UnauthorizedError } from "@effect-app/infra/errors"
import { Duration, Layer, Request as EffectRequest } from "effect-app"
import type { RPCContextMap } from "effect-app/client"
Expand Down
10 changes: 2 additions & 8 deletions api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@
"#resources": [
"./src/resources.js"
],
"#models": [
"./src/models.js"
],
"#resources/*": [
"./src/resources/*.js"
],
"#models/*": [
"./src/models/*.js"
"#Domain/*": [
"./src/Domain/*.js"
],
"#api/*": [
"./src/*.js"
Expand Down
7 changes: 2 additions & 5 deletions api/tsconfig.src.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@
"#resources": [
"./src/resources.js"
],
"#models": [
"./src/models.js"
],
"#resources/*": [
"./src/resources/*.js"
],
"#models/*": [
"./src/models/*.js"
"#Domain/*": [
"./src/Domain/*.js"
],
"#api/*": [
"./src/*.js"
Expand Down
2 changes: 1 addition & 1 deletion frontend/composables/currentUser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Naive login, good enough for the start

import type { UserId } from "#Accounts/models"
import type { UserId } from "#Domain/User"

export function getUserId() {
return useCookie("user-id")
Expand Down
2 changes: 1 addition & 1 deletion frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export default defineNuxtConfig({

alias: {
...[
"Domain",
// TODO: auto gen
"Accounts",
"Blog",
"Operations",
"HelloWorld",
"resources",
"models",
].reduce(
(prev, cur) => {
prev[`#${cur}`] = fileURLToPath(
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/blog/[id].vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { BlogPostId } from "#Blog/models"
import { BlogRsc } from "#Blog/resources"
import { BlogPostId } from "#Domain/Blog"
import type { ClientEvents } from "#resources/Events"
const { id } = useRouteParams({ id: BlogPostId })
Expand Down

0 comments on commit c68ea81

Please sign in to comment.