From 6fce702f5fd2cb7f427e95f117d1cc0562402852 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sun, 27 Oct 2024 08:44:17 +0100 Subject: [PATCH 01/11] play with vertical slice incomplete (frontend not updated) --- api/src/{ => Blog}/Blog.controllers.ts | 14 ++++++++------ .../{resources/Blog.ts => Blog/Blog.resources.ts} | 10 +++++----- api/src/{models => Blog}/Blog.ts | 2 +- .../{services/DBContext => Blog}/BlogPostRepo.ts | 6 +++--- api/src/{resources/views => Blog}/PostView.ts | 6 +++--- api/src/{resources => }/Events.ts | 2 +- api/src/HelloWorld.controllers.ts | 8 ++++---- .../HelloWorld.ts => HelloWorld.resources.ts} | 8 ++++---- api/src/Operations.controllers.ts | 4 ++-- .../Operations.ts => Operations.resources.ts} | 7 +++---- api/src/{ => User}/Me.controllers.ts | 6 +++--- api/src/User/Me.resources.ts | 9 +++++++++ api/src/{models => User}/User.ts | 0 api/src/{services/DBContext => User}/UserRepo.ts | 7 +++---- .../{resources/resolvers => User}/UserResolver.ts | 8 ++++---- api/src/{resources/views => User}/UserView.ts | 4 ++-- api/src/{ => User}/Users.controllers.ts | 9 +++++---- .../Users.ts => User/Users.resources.ts} | 10 +++++----- api/src/controllers.ts | 5 +---- api/src/lib.ts | 10 ++++++++++ api/src/{resources => }/lib/req.ts | 12 ++---------- api/src/{resources => }/lib/schema.ts | 0 api/src/resources.ts | 14 +++++++------- api/src/resources/Me.ts | 9 --------- api/src/resources/lib.ts | 5 ----- api/src/resources/views.ts | 4 ---- api/src/services.ts | 1 - api/src/services/DBContext.ts | 4 ---- api/src/services/UserProfile.ts | 2 +- 29 files changed, 86 insertions(+), 100 deletions(-) rename api/src/{ => Blog}/Blog.controllers.ts (87%) rename api/src/{resources/Blog.ts => Blog/Blog.resources.ts} (79%) rename api/src/{models => Blog}/Blog.ts (94%) rename api/src/{services/DBContext => Blog}/BlogPostRepo.ts (90%) rename api/src/{resources/views => Blog}/PostView.ts (74%) rename api/src/{resources => }/Events.ts (93%) rename api/src/{resources/HelloWorld.ts => HelloWorld.resources.ts} (68%) rename api/src/{resources/Operations.ts => Operations.resources.ts} (92%) rename api/src/{ => User}/Me.controllers.ts (67%) create mode 100644 api/src/User/Me.resources.ts rename api/src/{models => User}/User.ts (100%) rename api/src/{services/DBContext => User}/UserRepo.ts (95%) rename api/src/{resources/resolvers => User}/UserResolver.ts (90%) rename api/src/{resources/views => User}/UserView.ts (82%) rename api/src/{ => User}/Users.controllers.ts (71%) rename api/src/{resources/Users.ts => User/Users.resources.ts} (50%) create mode 100644 api/src/lib.ts rename api/src/{resources => }/lib/req.ts (75%) rename api/src/{resources => }/lib/schema.ts (100%) delete mode 100644 api/src/resources/Me.ts delete mode 100644 api/src/resources/lib.ts delete mode 100644 api/src/resources/views.ts delete mode 100644 api/src/services/DBContext.ts diff --git a/api/src/Blog.controllers.ts b/api/src/Blog/Blog.controllers.ts similarity index 87% rename from api/src/Blog.controllers.ts rename to api/src/Blog/Blog.controllers.ts index 57ac255ed..365e65c87 100644 --- a/api/src/Blog.controllers.ts +++ b/api/src/Blog/Blog.controllers.ts @@ -1,14 +1,16 @@ +import { BogusEvent } from "api/Events.js" +import { OperationsDefault } from "api/lib/layers.js" import { matchFor } from "api/lib/routing.js" -import { BlogPostRepo, Events, Operations, UserRepo } from "api/services.js" +import { Events, Operations } from "api/services.js" +import { UserRepo } from "api/User/UserRepo.js" import { Duration, Effect, Schedule } from "effect" import { Option } from "effect-app" import { NonEmptyString2k, NonNegativeInt } from "effect-app/Schema" -import { BlogPost } from "models/Blog.js" -import { BlogRsc } from "resources.js" -import { BogusEvent } from "resources/Events.js" -import { OperationsDefault } from "./lib/layers.js" +import { BlogResources } from "resources.js" +import { BlogPost } from "./Blog.js" +import { BlogPostRepo } from "./BlogPostRepo.js" -export default matchFor(BlogRsc)([ +export default matchFor(BlogResources)([ BlogPostRepo.Default, UserRepo.Default, OperationsDefault, diff --git a/api/src/resources/Blog.ts b/api/src/Blog/Blog.resources.ts similarity index 79% rename from api/src/resources/Blog.ts rename to api/src/Blog/Blog.resources.ts index 01078c2d7..7316f6e79 100644 --- a/api/src/resources/Blog.ts +++ b/api/src/Blog/Blog.resources.ts @@ -1,8 +1,8 @@ +import { S } from "api/lib.js" import { InvalidStateError, NotFoundError, OptimisticConcurrencyException } from "effect-app/client" import { OperationId } from "effect-app/Operations" -import { BlogPost, BlogPostId } from "models/Blog.js" -import { S } from "./lib.js" -import { BlogPostView } from "./views.js" +import { BlogPost, BlogPostId } from "./Blog.js" +import { BlogPostView } from "./PostView.js" export class CreatePost extends S.Req()("CreatePost", BlogPost.pick("title", "body"), { allowRoles: ["user"], @@ -26,6 +26,6 @@ export class PublishPost extends S.Req()("PublishPost", { id: BlogPostId }, { allowRoles: ["user"], success: OperationId, failure: S.Union(NotFoundError) }) {} -// codegen:start {preset: meta, sourcePrefix: src/resources/} -export const meta = { moduleName: "Blog" } as const +// codegen:start {preset: meta, sourcePrefix: src/Blog/} +export const meta = { moduleName: "Blog.resources" } as const // codegen:end diff --git a/api/src/models/Blog.ts b/api/src/Blog/Blog.ts similarity index 94% rename from api/src/models/Blog.ts rename to api/src/Blog/Blog.ts index ffb31e216..61791f2a1 100644 --- a/api/src/models/Blog.ts +++ b/api/src/Blog/Blog.ts @@ -1,5 +1,5 @@ +import { UserFromId } from "api/User/User.js" import { S } from "effect-app" -import { UserFromId } from "./User.js" export const BlogPostId = S.prefixedStringId()("post", "BlogPostId") export interface BlogPostIdBrand { diff --git a/api/src/services/DBContext/BlogPostRepo.ts b/api/src/Blog/BlogPostRepo.ts similarity index 90% rename from api/src/services/DBContext/BlogPostRepo.ts rename to api/src/Blog/BlogPostRepo.ts index 33a76d384..2cc7ff5e0 100644 --- a/api/src/services/DBContext/BlogPostRepo.ts +++ b/api/src/Blog/BlogPostRepo.ts @@ -1,11 +1,11 @@ import { Model } from "@effect-app/infra" import { RepoDefault } from "api/lib/layers.js" +import { UserFromIdResolver } from "api/User/User.js" +import { UserRepo } from "api/User/UserRepo.js" import { Effect } from "effect" import { Context } from "effect-app" import { NonEmptyString255, NonEmptyString2k } from "effect-app/Schema" -import { BlogPost } from "models/Blog.js" -import { UserFromIdResolver } from "models/User.js" -import { UserRepo } from "./UserRepo.js" +import { BlogPost } from "./Blog.js" export type BlogPostSeed = "sample" | "" diff --git a/api/src/resources/views/PostView.ts b/api/src/Blog/PostView.ts similarity index 74% rename from api/src/resources/views/PostView.ts rename to api/src/Blog/PostView.ts index c313a0be5..67ee27b60 100644 --- a/api/src/resources/views/PostView.ts +++ b/api/src/Blog/PostView.ts @@ -1,6 +1,6 @@ -import { BlogPost } from "models/Blog.js" -import { S } from "resources/lib.js" -import { UserViewFromId } from "../resolvers/UserResolver.js" +import { S } from "api/lib.js" +import { UserViewFromId } from "api/User/UserResolver.js" +import { BlogPost } from "./Blog.js" export class BlogPostView extends S.ExtendedClass()({ ...BlogPost.omit("author"), diff --git a/api/src/resources/Events.ts b/api/src/Events.ts similarity index 93% rename from api/src/resources/Events.ts rename to api/src/Events.ts index 7775dc776..201a867e2 100644 --- a/api/src/resources/Events.ts +++ b/api/src/Events.ts @@ -1,5 +1,5 @@ +import { S } from "api/lib.js" import type { Schema } from "effect-app/Schema" -import { S } from "resources/lib.js" export class BogusEvent extends S.ExtendedTaggedClass()("BogusEvent", { id: S.StringId.withDefault, diff --git a/api/src/HelloWorld.controllers.ts b/api/src/HelloWorld.controllers.ts index fdefb1ad8..90a29ff49 100644 --- a/api/src/HelloWorld.controllers.ts +++ b/api/src/HelloWorld.controllers.ts @@ -1,12 +1,12 @@ import { getRequestContext } from "@effect-app/infra/api/setupRequest" import { generate } from "@effect-app/infra/test" import { matchFor } from "api/lib/routing.js" -import { UserRepo } from "api/services.js" import { Effect, S } from "effect-app" -import { User } from "models/User.js" -import { HelloWorldRsc } from "resources.js" +import { HelloWorldResources } from "resources.js" +import { User } from "./User/User.js" +import { UserRepo } from "./User/UserRepo.js" -export default matchFor(HelloWorldRsc)([ +export default matchFor(HelloWorldResources)([ UserRepo.Default ], ({ GetHelloWorld }) => Effect.gen(function*() { diff --git a/api/src/resources/HelloWorld.ts b/api/src/HelloWorld.resources.ts similarity index 68% rename from api/src/resources/HelloWorld.ts rename to api/src/HelloWorld.resources.ts index 3f5cb5211..b8acc98ab 100644 --- a/api/src/resources/HelloWorld.ts +++ b/api/src/HelloWorld.resources.ts @@ -1,6 +1,6 @@ import { RequestContext } from "@effect-app/infra/RequestContext" -import { S } from "./lib.js" -import { UserView } from "./views.js" +import { S } from "api/lib.js" +import { UserView } from "./User/UserView.js" class Response extends S.Class()({ now: S.Date.withDefault, @@ -14,6 +14,6 @@ export class GetHelloWorld extends S.Req()("GetHelloWorld", { echo: S.String }, { allowAnonymous: true, allowRoles: ["user"], success: Response }) {} -// codegen:start {preset: meta, sourcePrefix: src/resources/} -export const meta = { moduleName: "HelloWorld" } as const +// codegen:start {preset: meta, sourcePrefix: src/} +export const meta = { moduleName: "HelloWorld.resources" } as const // codegen:end diff --git a/api/src/Operations.controllers.ts b/api/src/Operations.controllers.ts index 11e54b94a..9060bcf99 100644 --- a/api/src/Operations.controllers.ts +++ b/api/src/Operations.controllers.ts @@ -1,10 +1,10 @@ import { matchFor } from "api/lib/routing.js" import { Operations } from "api/services.js" import { Effect } from "effect-app" -import { OperationsRsc } from "resources.js" +import { OperationsResources } from "resources.js" import { OperationsDefault } from "./lib/layers.js" -export default matchFor(OperationsRsc)([ +export default matchFor(OperationsResources)([ OperationsDefault ], ({ FindOperation }) => Effect.gen(function*() { diff --git a/api/src/resources/Operations.ts b/api/src/Operations.resources.ts similarity index 92% rename from api/src/resources/Operations.ts rename to api/src/Operations.resources.ts index ca301f991..37e3dc578 100644 --- a/api/src/resources/Operations.ts +++ b/api/src/Operations.resources.ts @@ -1,15 +1,14 @@ +import { clientFor, S } from "api/lib.js" import { Duration, Effect } from "effect-app" import { NotFoundError } from "effect-app/client" import { Operation, OperationFailure, OperationId } from "effect-app/Operations" -import { clientFor } from "./lib.js" -import * as S from "./lib/schema.js" export class FindOperation extends S.Req()("FindOperation", { id: OperationId }, { allowAnonymous: true, allowRoles: ["user"], success: S.NullOr(Operation) }) {} -// codegen:start {preset: meta, sourcePrefix: src/resources/} -export const meta = { moduleName: "Operations" } as const +// codegen:start {preset: meta, sourcePrefix: src/} +export const meta = { moduleName: "Operations.resources" } as const // codegen:end // Extensions diff --git a/api/src/Me.controllers.ts b/api/src/User/Me.controllers.ts similarity index 67% rename from api/src/Me.controllers.ts rename to api/src/User/Me.controllers.ts index 948e4df11..db98dbe44 100644 --- a/api/src/Me.controllers.ts +++ b/api/src/User/Me.controllers.ts @@ -1,9 +1,9 @@ import { matchFor } from "api/lib/routing.js" -import { UserRepo } from "api/services.js" import { Effect } from "effect-app" -import { MeRsc } from "resources.js" +import { MeResources } from "resources.js" +import { UserRepo } from "./UserRepo.js" -export default matchFor(MeRsc)([ +export default matchFor(MeResources)([ UserRepo.Default ], ({ GetMe }) => Effect.gen(function*() { diff --git a/api/src/User/Me.resources.ts b/api/src/User/Me.resources.ts new file mode 100644 index 000000000..cd5080e6e --- /dev/null +++ b/api/src/User/Me.resources.ts @@ -0,0 +1,9 @@ +import { S } from "api/lib.js" +import { NotFoundError } from "effect-app/client" +import { User } from "./User.js" + +export class GetMe extends S.Req()("GetMe", {}, { success: User, failure: NotFoundError }) {} + +// codegen:start {preset: meta, sourcePrefix: src/User/} +export const meta = { moduleName: "Me.resources" } as const +// codegen:end diff --git a/api/src/models/User.ts b/api/src/User/User.ts similarity index 100% rename from api/src/models/User.ts rename to api/src/User/User.ts diff --git a/api/src/services/DBContext/UserRepo.ts b/api/src/User/UserRepo.ts similarity index 95% rename from api/src/services/DBContext/UserRepo.ts rename to api/src/User/UserRepo.ts index 942584331..64ae8689f 100644 --- a/api/src/services/DBContext/UserRepo.ts +++ b/api/src/User/UserRepo.ts @@ -3,14 +3,13 @@ import { NotFoundError, NotLoggedInError } from "@effect-app/infra/errors" import { generate } from "@effect-app/infra/test" import { RepoConfig } from "api/config.js" import { RepoDefault } from "api/lib/layers.js" +import { Q, UserProfile } from "api/services.js" import { Array, Effect, Exit, Layer, Option, pipe, Request, RequestResolver, S } from "effect-app" import { fakerArb } from "effect-app/faker" import { Email } from "effect-app/Schema" import fc from "fast-check" -import type { UserId } from "models/User.js" -import { User } from "models/User.js" -import { Q } from "../lib.js" -import { UserProfile } from "../UserProfile.js" +import type { UserId } from "./User.js" +import { User } from "./User.js" export type UserSeed = "sample" | "" diff --git a/api/src/resources/resolvers/UserResolver.ts b/api/src/User/UserResolver.ts similarity index 90% rename from api/src/resources/resolvers/UserResolver.ts rename to api/src/User/UserResolver.ts index f40c38b8d..ec2469e56 100644 --- a/api/src/resources/resolvers/UserResolver.ts +++ b/api/src/User/UserResolver.ts @@ -1,12 +1,12 @@ +import { clientFor } from "api/lib.js" import { Effect, Exit, Request, RequestResolver } from "effect" import { Array, Option, pipe, S } from "effect-app" import { ApiConfig, NotFoundError } from "effect-app/client" import { HttpClient } from "effect-app/http" import { type Schema } from "effect-app/Schema" -import { UserId } from "models/User.js" -import { clientFor } from "resources/lib.js" -import * as UsersRsc from "../Users.js" -import { UserView } from "../views/UserView.js" +import { UserId } from "./User.js" +import * as UsersRsc from "./Users.resources.js" +import { UserView } from "./UserView.js" interface GetUserViewById extends Request.Request> { readonly _tag: "GetUserViewById" diff --git a/api/src/resources/views/UserView.ts b/api/src/User/UserView.ts similarity index 82% rename from api/src/resources/views/UserView.ts rename to api/src/User/UserView.ts index 3e6d16cf5..f60c21176 100644 --- a/api/src/resources/views/UserView.ts +++ b/api/src/User/UserView.ts @@ -1,5 +1,5 @@ -import { User } from "models/User.js" -import { S } from "resources/lib.js" +import { S } from "api/lib.js" +import { User } from "./User.js" export class UserView extends S.ExtendedClass()({ ...User.pick("id", "role"), diff --git a/api/src/Users.controllers.ts b/api/src/User/Users.controllers.ts similarity index 71% rename from api/src/Users.controllers.ts rename to api/src/User/Users.controllers.ts index 20d5b6860..2f5a06c62 100644 --- a/api/src/Users.controllers.ts +++ b/api/src/User/Users.controllers.ts @@ -1,11 +1,12 @@ import { matchFor } from "api/lib/routing.js" -import { Q, UserRepo } from "api/services.js" +import { Q } from "api/services.js" import { Array } from "effect" import { Effect, Order } from "effect-app" -import { UsersRsc } from "resources.js" -import type { UserView } from "resources/views.js" +import { UsersResources } from "resources.js" +import { UserRepo } from "./UserRepo.js" +import type { UserView } from "./UserView.js" -export default matchFor(UsersRsc)([ +export default matchFor(UsersResources)([ UserRepo.Default ], ({ IndexUsers }) => Effect.gen(function*() { diff --git a/api/src/resources/Users.ts b/api/src/User/Users.resources.ts similarity index 50% rename from api/src/resources/Users.ts rename to api/src/User/Users.resources.ts index 024a2e813..47305eba6 100644 --- a/api/src/resources/Users.ts +++ b/api/src/User/Users.resources.ts @@ -1,6 +1,6 @@ -import { UserId } from "models/User.js" -import { S } from "./lib.js" -import { UserView } from "./views/UserView.js" +import { S } from "api/lib.js" +import { UserId } from "./User.js" +import { UserView } from "./UserView.js" export class IndexUsers extends S.Req()("IndexUsers", { filterByIds: S.NonEmptyArray(UserId) @@ -12,6 +12,6 @@ export class IndexUsers extends S.Req()("IndexUsers", { }) }) {} -// codegen:start {preset: meta, sourcePrefix: src/resources/} -export const meta = { moduleName: "Users" } as const +// codegen:start {preset: meta, sourcePrefix: src/User/} +export const meta = { moduleName: "Users.resources" } as const // codegen:end diff --git a/api/src/controllers.ts b/api/src/controllers.ts index ca2e26754..121215332 100644 --- a/api/src/controllers.ts +++ b/api/src/controllers.ts @@ -1,9 +1,6 @@ // codegen:start {preset: barrel, include: ./*.controllers.ts, import: default} -import blogControllers from "./Blog.controllers.js" import helloWorldControllers from "./HelloWorld.controllers.js" -import meControllers from "./Me.controllers.js" import operationsControllers from "./Operations.controllers.js" -import usersControllers from "./Users.controllers.js" -export { blogControllers, helloWorldControllers, meControllers, operationsControllers, usersControllers } +export { helloWorldControllers, operationsControllers } // codegen:end diff --git a/api/src/lib.ts b/api/src/lib.ts new file mode 100644 index 000000000..5e932f4a8 --- /dev/null +++ b/api/src/lib.ts @@ -0,0 +1,10 @@ +// codegen:start {preset: barrel, include: ./lib/*.ts, exclude: ./lib/schema.ts} +export * from "./lib/basicRuntime.js" +export * from "./lib/layers.js" +export * from "./lib/middleware.js" +export * from "./lib/observability.js" +export * from "./lib/req.js" +export * from "./lib/routing.js" +// codegen:end + +export * as S from "./lib/schema.js" diff --git a/api/src/resources/lib/req.ts b/api/src/lib/req.ts similarity index 75% rename from api/src/resources/lib/req.ts rename to api/src/lib/req.ts index 854a110c4..0a0b5d29a 100644 --- a/api/src/resources/lib/req.ts +++ b/api/src/lib/req.ts @@ -1,10 +1,9 @@ import { NotLoggedInError, UnauthorizedError } from "@effect-app/infra/errors" -import { Duration, Layer, Request as EffectRequest } from "effect-app" +import type { Role } from "api/User/User.js" import type { RPCContextMap } from "effect-app/client" import { makeRpcClient } from "effect-app/client" -import type { Role } from "models/User.js" - import { makeClientFor } from "effect-app/client/clientFor" +import { RequestCacheLayers } from "./routing.js" type CTXMap = { // we put `never`, because we can't access this service here in the client, and we also don't need to @@ -26,11 +25,4 @@ export const { TaggedRequest: Req } = makeRpcClient({ requireRoles: UnauthorizedError }) -export const RequestCacheLayers = Layer.mergeAll( - Layer.setRequestCache( - EffectRequest.makeCache({ capacity: 500, timeToLive: Duration.hours(8) }) - ), - Layer.setRequestCaching(true), - Layer.setRequestBatching(true) -) export const clientFor = makeClientFor(RequestCacheLayers) diff --git a/api/src/resources/lib/schema.ts b/api/src/lib/schema.ts similarity index 100% rename from api/src/resources/lib/schema.ts rename to api/src/lib/schema.ts diff --git a/api/src/resources.ts b/api/src/resources.ts index 5426feae9..826f53253 100644 --- a/api/src/resources.ts +++ b/api/src/resources.ts @@ -1,11 +1,11 @@ import type {} from "@effect/platform/HttpClient" -export { ClientEvents } from "./resources/Events.js" +export { ClientEvents } from "./Events.js" -// codegen:start {preset: barrel, include: ./resources/*.ts, exclude: [./resources/index.ts, ./resources/lib.ts, ./resources/integrationEvents.ts, ./resources/Messages.ts, ./resources/views.ts, ./resources/Events.ts], export: { as: 'PascalCase', postfix: 'Rsc' }} -export * as BlogRsc from "./resources/Blog.js" -export * as HelloWorldRsc from "./resources/HelloWorld.js" -export * as MeRsc from "./resources/Me.js" -export * as OperationsRsc from "./resources/Operations.js" -export * as UsersRsc from "./resources/Users.js" +// codegen:start {preset: barrel, include: ./**/*.resources.ts, exclude: [./resources/index.ts, ./resources/lib.ts, ./resources/integrationEvents.ts, ./resources/Messages.ts, ./resources/views.ts, ./resources/Events.ts], export: { as: 'PascalCase' }} +export * as BlogResources from "./Blog/Blog.resources.js" +export * as HelloWorldResources from "./HelloWorld.resources.js" +export * as OperationsResources from "./Operations.resources.js" +export * as MeResources from "./User/Me.resources.js" +export * as UsersResources from "./User/Users.resources.js" // codegen:end diff --git a/api/src/resources/Me.ts b/api/src/resources/Me.ts deleted file mode 100644 index d18c32df4..000000000 --- a/api/src/resources/Me.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { NotFoundError } from "effect-app/client" -import { User } from "models/User.js" -import { S } from "./lib.js" - -export class GetMe extends S.Req()("GetMe", {}, { success: User, failure: NotFoundError }) {} - -// codegen:start {preset: meta, sourcePrefix: src/resources/} -export const meta = { moduleName: "Me" } as const -// codegen:end diff --git a/api/src/resources/lib.ts b/api/src/resources/lib.ts deleted file mode 100644 index 61d4ddce7..000000000 --- a/api/src/resources/lib.ts +++ /dev/null @@ -1,5 +0,0 @@ -// codegen:start {preset: barrel, include: ./lib/*.ts, exclude: ./lib/schema.ts} -export * from "./lib/req.js" -// codegen:end - -export * as S from "./lib/schema.js" diff --git a/api/src/resources/views.ts b/api/src/resources/views.ts deleted file mode 100644 index b09859be2..000000000 --- a/api/src/resources/views.ts +++ /dev/null @@ -1,4 +0,0 @@ -// codegen:start {preset: barrel, include: ./views/*.ts} -export * from "./views/PostView.js" -export * from "./views/UserView.js" -// codegen:end diff --git a/api/src/services.ts b/api/src/services.ts index eb74b1bc2..692fe6fb7 100644 --- a/api/src/services.ts +++ b/api/src/services.ts @@ -1,5 +1,4 @@ // codegen:start {preset: barrel, include: services/*.ts } -export * from "./services/DBContext.js" export * from "./services/Events.js" export * from "./services/lib.js" export * from "./services/UserProfile.js" diff --git a/api/src/services/DBContext.ts b/api/src/services/DBContext.ts deleted file mode 100644 index f3dec88d7..000000000 --- a/api/src/services/DBContext.ts +++ /dev/null @@ -1,4 +0,0 @@ -// codegen:start {preset: barrel, include: ./DBContext/* } -export * from "./DBContext/BlogPostRepo.js" -export * from "./DBContext/UserRepo.js" -// codegen:end diff --git a/api/src/services/UserProfile.ts b/api/src/services/UserProfile.ts index bcf26a9e2..7edd9c6ed 100644 --- a/api/src/services/UserProfile.ts +++ b/api/src/services/UserProfile.ts @@ -1,7 +1,7 @@ import { parseJwt } from "@effect-app/infra/api/routing/schema/jwt" +import { Role } from "api/User/User.js" import { Context, S } from "effect-app" import { UserProfileId } from "effect-app/ids" -import { Role } from "models/User.js" export class UserProfile extends Context.assignTag()( S.Class()({ From 08e155ae4703d0429a8bfec8f230bc457ca0f667 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sun, 27 Oct 2024 08:49:16 +0100 Subject: [PATCH 02/11] cleanup --- .../{ => HelloWorld}/HelloWorld.controllers.ts | 4 ++-- .../{ => HelloWorld}/HelloWorld.resources.ts | 4 ++-- .../{ => Operations}/Operations.controllers.ts | 2 +- .../{ => Operations}/Operations.resources.ts | 2 +- api/src/controllers.ts | 17 +++++++++++++---- api/src/resources.ts | 4 ++-- 6 files changed, 21 insertions(+), 12 deletions(-) rename api/src/{ => HelloWorld}/HelloWorld.controllers.ts (92%) rename api/src/{ => HelloWorld}/HelloWorld.resources.ts (82%) rename api/src/{ => Operations}/Operations.controllers.ts (91%) rename api/src/{ => Operations}/Operations.resources.ts (97%) diff --git a/api/src/HelloWorld.controllers.ts b/api/src/HelloWorld/HelloWorld.controllers.ts similarity index 92% rename from api/src/HelloWorld.controllers.ts rename to api/src/HelloWorld/HelloWorld.controllers.ts index 90a29ff49..4cf66a7f5 100644 --- a/api/src/HelloWorld.controllers.ts +++ b/api/src/HelloWorld/HelloWorld.controllers.ts @@ -1,10 +1,10 @@ import { getRequestContext } from "@effect-app/infra/api/setupRequest" import { generate } from "@effect-app/infra/test" import { matchFor } from "api/lib/routing.js" +import { User } from "api/User/User.js" +import { UserRepo } from "api/User/UserRepo.js" import { Effect, S } from "effect-app" import { HelloWorldResources } from "resources.js" -import { User } from "./User/User.js" -import { UserRepo } from "./User/UserRepo.js" export default matchFor(HelloWorldResources)([ UserRepo.Default diff --git a/api/src/HelloWorld.resources.ts b/api/src/HelloWorld/HelloWorld.resources.ts similarity index 82% rename from api/src/HelloWorld.resources.ts rename to api/src/HelloWorld/HelloWorld.resources.ts index b8acc98ab..09469dfdb 100644 --- a/api/src/HelloWorld.resources.ts +++ b/api/src/HelloWorld/HelloWorld.resources.ts @@ -1,6 +1,6 @@ import { RequestContext } from "@effect-app/infra/RequestContext" import { S } from "api/lib.js" -import { UserView } from "./User/UserView.js" +import { UserView } from "api/User/UserView.js" class Response extends S.Class()({ now: S.Date.withDefault, @@ -14,6 +14,6 @@ export class GetHelloWorld extends S.Req()("GetHelloWorld", { echo: S.String }, { allowAnonymous: true, allowRoles: ["user"], success: Response }) {} -// codegen:start {preset: meta, sourcePrefix: src/} +// codegen:start {preset: meta, sourcePrefix: src/HelloWorld/} export const meta = { moduleName: "HelloWorld.resources" } as const // codegen:end diff --git a/api/src/Operations.controllers.ts b/api/src/Operations/Operations.controllers.ts similarity index 91% rename from api/src/Operations.controllers.ts rename to api/src/Operations/Operations.controllers.ts index 9060bcf99..3a76224aa 100644 --- a/api/src/Operations.controllers.ts +++ b/api/src/Operations/Operations.controllers.ts @@ -1,8 +1,8 @@ +import { OperationsDefault } from "api/lib.js" import { matchFor } from "api/lib/routing.js" import { Operations } from "api/services.js" import { Effect } from "effect-app" import { OperationsResources } from "resources.js" -import { OperationsDefault } from "./lib/layers.js" export default matchFor(OperationsResources)([ OperationsDefault diff --git a/api/src/Operations.resources.ts b/api/src/Operations/Operations.resources.ts similarity index 97% rename from api/src/Operations.resources.ts rename to api/src/Operations/Operations.resources.ts index 37e3dc578..a68fcb987 100644 --- a/api/src/Operations.resources.ts +++ b/api/src/Operations/Operations.resources.ts @@ -7,7 +7,7 @@ export class FindOperation extends S.Req()("FindOperation", { id: OperationId }, { allowAnonymous: true, allowRoles: ["user"], success: S.NullOr(Operation) }) {} -// codegen:start {preset: meta, sourcePrefix: src/} +// codegen:start {preset: meta, sourcePrefix: src/Operations/} export const meta = { moduleName: "Operations.resources" } as const // codegen:end diff --git a/api/src/controllers.ts b/api/src/controllers.ts index 121215332..6e5a79380 100644 --- a/api/src/controllers.ts +++ b/api/src/controllers.ts @@ -1,6 +1,15 @@ -// codegen:start {preset: barrel, include: ./*.controllers.ts, import: default} -import helloWorldControllers from "./HelloWorld.controllers.js" -import operationsControllers from "./Operations.controllers.js" +// codegen:start {preset: barrel, include: ./**/*.controllers.ts, import: default} +import blogBlogControllers from "./Blog/Blog.controllers.js" +import helloWorldHelloWorldControllers from "./HelloWorld/HelloWorld.controllers.js" +import operationsOperationsControllers from "./Operations/Operations.controllers.js" +import userMeControllers from "./User/Me.controllers.js" +import userUsersControllers from "./User/Users.controllers.js" -export { helloWorldControllers, operationsControllers } +export { + blogBlogControllers, + helloWorldHelloWorldControllers, + operationsOperationsControllers, + userMeControllers, + userUsersControllers +} // codegen:end diff --git a/api/src/resources.ts b/api/src/resources.ts index 826f53253..35e0de13f 100644 --- a/api/src/resources.ts +++ b/api/src/resources.ts @@ -4,8 +4,8 @@ export { ClientEvents } from "./Events.js" // codegen:start {preset: barrel, include: ./**/*.resources.ts, exclude: [./resources/index.ts, ./resources/lib.ts, ./resources/integrationEvents.ts, ./resources/Messages.ts, ./resources/views.ts, ./resources/Events.ts], export: { as: 'PascalCase' }} export * as BlogResources from "./Blog/Blog.resources.js" -export * as HelloWorldResources from "./HelloWorld.resources.js" -export * as OperationsResources from "./Operations.resources.js" +export * as HelloWorldResources from "./HelloWorld/HelloWorld.resources.js" +export * as OperationsResources from "./Operations/Operations.resources.js" export * as MeResources from "./User/Me.resources.js" export * as UsersResources from "./User/Users.resources.js" // codegen:end From ce5a038a6c54d54c7d672e1eac8cb9e26e95387b Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sun, 27 Oct 2024 08:54:31 +0100 Subject: [PATCH 03/11] more like effect-http-play --- api/src/{Blog => }/Blog.controllers.ts | 4 ++-- api/src/Blog/Blog.resources.ts | 2 +- api/src/Blog/BlogPostRepo.ts | 4 ++-- api/src/Blog/PostView.ts | 2 +- api/src/{Blog => Domain}/Blog.ts | 2 +- api/src/{User => Domain}/User.ts | 0 .../{HelloWorld => }/HelloWorld.controllers.ts | 2 +- api/src/{User => }/Me.controllers.ts | 2 +- .../{Operations => }/Operations.controllers.ts | 0 api/src/User/Me.resources.ts | 2 +- api/src/User/UserRepo.ts | 4 ++-- api/src/User/UserResolver.ts | 2 +- api/src/User/UserView.ts | 2 +- api/src/User/Users.resources.ts | 2 +- api/src/controllers.ts | 16 +++++----------- api/src/lib/req.ts | 2 +- api/src/services/UserProfile.ts | 2 +- 17 files changed, 22 insertions(+), 28 deletions(-) rename api/src/{Blog => }/Blog.controllers.ts (96%) rename api/src/{Blog => Domain}/Blog.ts (94%) rename api/src/{User => Domain}/User.ts (100%) rename api/src/{HelloWorld => }/HelloWorld.controllers.ts (96%) rename api/src/{User => }/Me.controllers.ts (87%) rename api/src/{Operations => }/Operations.controllers.ts (100%) diff --git a/api/src/Blog/Blog.controllers.ts b/api/src/Blog.controllers.ts similarity index 96% rename from api/src/Blog/Blog.controllers.ts rename to api/src/Blog.controllers.ts index 365e65c87..dce5dd36b 100644 --- a/api/src/Blog/Blog.controllers.ts +++ b/api/src/Blog.controllers.ts @@ -7,8 +7,8 @@ import { Duration, Effect, Schedule } from "effect" import { Option } from "effect-app" import { NonEmptyString2k, NonNegativeInt } from "effect-app/Schema" import { BlogResources } from "resources.js" -import { BlogPost } from "./Blog.js" -import { BlogPostRepo } from "./BlogPostRepo.js" +import { BlogPostRepo } from "./Blog/BlogPostRepo.js" +import { BlogPost } from "./Domain/Blog.js" export default matchFor(BlogResources)([ BlogPostRepo.Default, diff --git a/api/src/Blog/Blog.resources.ts b/api/src/Blog/Blog.resources.ts index 7316f6e79..f7f8e9cf0 100644 --- a/api/src/Blog/Blog.resources.ts +++ b/api/src/Blog/Blog.resources.ts @@ -1,7 +1,7 @@ +import { BlogPost, BlogPostId } from "api/Domain/Blog.js" import { S } from "api/lib.js" import { InvalidStateError, NotFoundError, OptimisticConcurrencyException } from "effect-app/client" import { OperationId } from "effect-app/Operations" -import { BlogPost, BlogPostId } from "./Blog.js" import { BlogPostView } from "./PostView.js" export class CreatePost extends S.Req()("CreatePost", BlogPost.pick("title", "body"), { diff --git a/api/src/Blog/BlogPostRepo.ts b/api/src/Blog/BlogPostRepo.ts index 2cc7ff5e0..a08009373 100644 --- a/api/src/Blog/BlogPostRepo.ts +++ b/api/src/Blog/BlogPostRepo.ts @@ -1,11 +1,11 @@ import { Model } from "@effect-app/infra" +import { BlogPost } from "api/Domain/Blog.js" +import { UserFromIdResolver } from "api/Domain/User.js" import { RepoDefault } from "api/lib/layers.js" -import { UserFromIdResolver } from "api/User/User.js" import { UserRepo } from "api/User/UserRepo.js" import { Effect } from "effect" import { Context } from "effect-app" import { NonEmptyString255, NonEmptyString2k } from "effect-app/Schema" -import { BlogPost } from "./Blog.js" export type BlogPostSeed = "sample" | "" diff --git a/api/src/Blog/PostView.ts b/api/src/Blog/PostView.ts index 67ee27b60..e10d08d9d 100644 --- a/api/src/Blog/PostView.ts +++ b/api/src/Blog/PostView.ts @@ -1,6 +1,6 @@ +import { BlogPost } from "api/Domain/Blog.js" import { S } from "api/lib.js" import { UserViewFromId } from "api/User/UserResolver.js" -import { BlogPost } from "./Blog.js" export class BlogPostView extends S.ExtendedClass()({ ...BlogPost.omit("author"), diff --git a/api/src/Blog/Blog.ts b/api/src/Domain/Blog.ts similarity index 94% rename from api/src/Blog/Blog.ts rename to api/src/Domain/Blog.ts index 61791f2a1..ffb31e216 100644 --- a/api/src/Blog/Blog.ts +++ b/api/src/Domain/Blog.ts @@ -1,5 +1,5 @@ -import { UserFromId } from "api/User/User.js" import { S } from "effect-app" +import { UserFromId } from "./User.js" export const BlogPostId = S.prefixedStringId()("post", "BlogPostId") export interface BlogPostIdBrand { diff --git a/api/src/User/User.ts b/api/src/Domain/User.ts similarity index 100% rename from api/src/User/User.ts rename to api/src/Domain/User.ts diff --git a/api/src/HelloWorld/HelloWorld.controllers.ts b/api/src/HelloWorld.controllers.ts similarity index 96% rename from api/src/HelloWorld/HelloWorld.controllers.ts rename to api/src/HelloWorld.controllers.ts index 4cf66a7f5..981f8b2d9 100644 --- a/api/src/HelloWorld/HelloWorld.controllers.ts +++ b/api/src/HelloWorld.controllers.ts @@ -1,10 +1,10 @@ import { getRequestContext } from "@effect-app/infra/api/setupRequest" import { generate } from "@effect-app/infra/test" import { matchFor } from "api/lib/routing.js" -import { User } from "api/User/User.js" import { UserRepo } from "api/User/UserRepo.js" import { Effect, S } from "effect-app" import { HelloWorldResources } from "resources.js" +import { User } from "./Domain/User.js" export default matchFor(HelloWorldResources)([ UserRepo.Default diff --git a/api/src/User/Me.controllers.ts b/api/src/Me.controllers.ts similarity index 87% rename from api/src/User/Me.controllers.ts rename to api/src/Me.controllers.ts index db98dbe44..978ebb16b 100644 --- a/api/src/User/Me.controllers.ts +++ b/api/src/Me.controllers.ts @@ -1,7 +1,7 @@ import { matchFor } from "api/lib/routing.js" import { Effect } from "effect-app" import { MeResources } from "resources.js" -import { UserRepo } from "./UserRepo.js" +import { UserRepo } from "./User/UserRepo.js" export default matchFor(MeResources)([ UserRepo.Default diff --git a/api/src/Operations/Operations.controllers.ts b/api/src/Operations.controllers.ts similarity index 100% rename from api/src/Operations/Operations.controllers.ts rename to api/src/Operations.controllers.ts diff --git a/api/src/User/Me.resources.ts b/api/src/User/Me.resources.ts index cd5080e6e..0a20ea203 100644 --- a/api/src/User/Me.resources.ts +++ b/api/src/User/Me.resources.ts @@ -1,6 +1,6 @@ +import { User } from "api/Domain/User.js" import { S } from "api/lib.js" import { NotFoundError } from "effect-app/client" -import { User } from "./User.js" export class GetMe extends S.Req()("GetMe", {}, { success: User, failure: NotFoundError }) {} diff --git a/api/src/User/UserRepo.ts b/api/src/User/UserRepo.ts index 64ae8689f..07172c2fd 100644 --- a/api/src/User/UserRepo.ts +++ b/api/src/User/UserRepo.ts @@ -2,14 +2,14 @@ import { Model } from "@effect-app/infra" import { NotFoundError, NotLoggedInError } from "@effect-app/infra/errors" import { generate } from "@effect-app/infra/test" import { RepoConfig } from "api/config.js" +import type { UserId } from "api/Domain/User.js" +import { User } from "api/Domain/User.js" import { RepoDefault } from "api/lib/layers.js" import { Q, UserProfile } from "api/services.js" import { Array, Effect, Exit, Layer, Option, pipe, Request, RequestResolver, S } from "effect-app" import { fakerArb } from "effect-app/faker" import { Email } from "effect-app/Schema" import fc from "fast-check" -import type { UserId } from "./User.js" -import { User } from "./User.js" export type UserSeed = "sample" | "" diff --git a/api/src/User/UserResolver.ts b/api/src/User/UserResolver.ts index ec2469e56..ea130dd08 100644 --- a/api/src/User/UserResolver.ts +++ b/api/src/User/UserResolver.ts @@ -1,10 +1,10 @@ +import { UserId } from "api/Domain/User.js" import { clientFor } from "api/lib.js" import { Effect, Exit, Request, RequestResolver } from "effect" import { Array, Option, pipe, S } from "effect-app" import { ApiConfig, NotFoundError } from "effect-app/client" import { HttpClient } from "effect-app/http" import { type Schema } from "effect-app/Schema" -import { UserId } from "./User.js" import * as UsersRsc from "./Users.resources.js" import { UserView } from "./UserView.js" diff --git a/api/src/User/UserView.ts b/api/src/User/UserView.ts index f60c21176..f38c1cc31 100644 --- a/api/src/User/UserView.ts +++ b/api/src/User/UserView.ts @@ -1,5 +1,5 @@ +import { User } from "api/Domain/User.js" import { S } from "api/lib.js" -import { User } from "./User.js" export class UserView extends S.ExtendedClass()({ ...User.pick("id", "role"), diff --git a/api/src/User/Users.resources.ts b/api/src/User/Users.resources.ts index 47305eba6..2b7efa830 100644 --- a/api/src/User/Users.resources.ts +++ b/api/src/User/Users.resources.ts @@ -1,5 +1,5 @@ +import { UserId } from "api/Domain/User.js" import { S } from "api/lib.js" -import { UserId } from "./User.js" import { UserView } from "./UserView.js" export class IndexUsers extends S.Req()("IndexUsers", { diff --git a/api/src/controllers.ts b/api/src/controllers.ts index 6e5a79380..53eae7fdc 100644 --- a/api/src/controllers.ts +++ b/api/src/controllers.ts @@ -1,15 +1,9 @@ // codegen:start {preset: barrel, include: ./**/*.controllers.ts, import: default} -import blogBlogControllers from "./Blog/Blog.controllers.js" -import helloWorldHelloWorldControllers from "./HelloWorld/HelloWorld.controllers.js" -import operationsOperationsControllers from "./Operations/Operations.controllers.js" -import userMeControllers from "./User/Me.controllers.js" +import blogControllers from "./Blog.controllers.js" +import helloWorldControllers from "./HelloWorld.controllers.js" +import meControllers from "./Me.controllers.js" +import operationsControllers from "./Operations.controllers.js" import userUsersControllers from "./User/Users.controllers.js" -export { - blogBlogControllers, - helloWorldHelloWorldControllers, - operationsOperationsControllers, - userMeControllers, - userUsersControllers -} +export { blogControllers, helloWorldControllers, meControllers, operationsControllers, userUsersControllers } // codegen:end diff --git a/api/src/lib/req.ts b/api/src/lib/req.ts index 0a0b5d29a..85e61f1f2 100644 --- a/api/src/lib/req.ts +++ b/api/src/lib/req.ts @@ -1,5 +1,5 @@ import { NotLoggedInError, UnauthorizedError } from "@effect-app/infra/errors" -import type { Role } from "api/User/User.js" +import type { Role } from "api/Domain/User.js" import type { RPCContextMap } from "effect-app/client" import { makeRpcClient } from "effect-app/client" import { makeClientFor } from "effect-app/client/clientFor" diff --git a/api/src/services/UserProfile.ts b/api/src/services/UserProfile.ts index 7edd9c6ed..9029bc250 100644 --- a/api/src/services/UserProfile.ts +++ b/api/src/services/UserProfile.ts @@ -1,5 +1,5 @@ import { parseJwt } from "@effect-app/infra/api/routing/schema/jwt" -import { Role } from "api/User/User.js" +import { Role } from "api/Domain/User.js" import { Context, S } from "effect-app" import { UserProfileId } from "effect-app/ids" From 5e8b9422ed55a91a39038a5408105cde3bcaa561 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sun, 27 Oct 2024 08:57:47 +0100 Subject: [PATCH 04/11] Cleanup --- api/src/{Blog.controllers.ts => Blog.ts} | 2 +- api/src/{ => Domain}/Events.ts | 0 .../{HelloWorld.controllers.ts => HelloWorld.ts} | 0 api/src/{Me.controllers.ts => Me.ts} | 0 .../{Operations.controllers.ts => Operations.ts} | 0 api/src/{User/Users.controllers.ts => Users.ts} | 4 ++-- api/src/controllers.ts | 14 +++++++------- api/src/resources.ts | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) rename api/src/{Blog.controllers.ts => Blog.ts} (98%) rename api/src/{ => Domain}/Events.ts (100%) rename api/src/{HelloWorld.controllers.ts => HelloWorld.ts} (100%) rename api/src/{Me.controllers.ts => Me.ts} (100%) rename api/src/{Operations.controllers.ts => Operations.ts} (100%) rename api/src/{User/Users.controllers.ts => Users.ts} (87%) diff --git a/api/src/Blog.controllers.ts b/api/src/Blog.ts similarity index 98% rename from api/src/Blog.controllers.ts rename to api/src/Blog.ts index dce5dd36b..dc7c945db 100644 --- a/api/src/Blog.controllers.ts +++ b/api/src/Blog.ts @@ -1,4 +1,3 @@ -import { BogusEvent } from "api/Events.js" import { OperationsDefault } from "api/lib/layers.js" import { matchFor } from "api/lib/routing.js" import { Events, Operations } from "api/services.js" @@ -9,6 +8,7 @@ import { NonEmptyString2k, NonNegativeInt } from "effect-app/Schema" import { BlogResources } from "resources.js" import { BlogPostRepo } from "./Blog/BlogPostRepo.js" import { BlogPost } from "./Domain/Blog.js" +import { BogusEvent } from "./Domain/Events.js" export default matchFor(BlogResources)([ BlogPostRepo.Default, diff --git a/api/src/Events.ts b/api/src/Domain/Events.ts similarity index 100% rename from api/src/Events.ts rename to api/src/Domain/Events.ts diff --git a/api/src/HelloWorld.controllers.ts b/api/src/HelloWorld.ts similarity index 100% rename from api/src/HelloWorld.controllers.ts rename to api/src/HelloWorld.ts diff --git a/api/src/Me.controllers.ts b/api/src/Me.ts similarity index 100% rename from api/src/Me.controllers.ts rename to api/src/Me.ts diff --git a/api/src/Operations.controllers.ts b/api/src/Operations.ts similarity index 100% rename from api/src/Operations.controllers.ts rename to api/src/Operations.ts diff --git a/api/src/User/Users.controllers.ts b/api/src/Users.ts similarity index 87% rename from api/src/User/Users.controllers.ts rename to api/src/Users.ts index 2f5a06c62..29ba7a74d 100644 --- a/api/src/User/Users.controllers.ts +++ b/api/src/Users.ts @@ -3,8 +3,8 @@ import { Q } from "api/services.js" import { Array } from "effect" import { Effect, Order } from "effect-app" import { UsersResources } from "resources.js" -import { UserRepo } from "./UserRepo.js" -import type { UserView } from "./UserView.js" +import { UserRepo } from "./User/UserRepo.js" +import type { UserView } from "./User/UserView.js" export default matchFor(UsersResources)([ UserRepo.Default diff --git a/api/src/controllers.ts b/api/src/controllers.ts index 53eae7fdc..cad9b4134 100644 --- a/api/src/controllers.ts +++ b/api/src/controllers.ts @@ -1,9 +1,9 @@ -// codegen:start {preset: barrel, include: ./**/*.controllers.ts, import: default} -import blogControllers from "./Blog.controllers.js" -import helloWorldControllers from "./HelloWorld.controllers.js" -import meControllers from "./Me.controllers.js" -import operationsControllers from "./Operations.controllers.js" -import userUsersControllers from "./User/Users.controllers.js" +// codegen:start {preset: barrel, include: './[A-Z]*.ts', import: default} +import blog from "./Blog.js" +import helloWorld from "./HelloWorld.js" +import me from "./Me.js" +import operations from "./Operations.js" +import users from "./Users.js" -export { blogControllers, helloWorldControllers, meControllers, operationsControllers, userUsersControllers } +export { blog, helloWorld, me, operations, users } // codegen:end diff --git a/api/src/resources.ts b/api/src/resources.ts index 35e0de13f..bb6efca57 100644 --- a/api/src/resources.ts +++ b/api/src/resources.ts @@ -1,6 +1,6 @@ import type {} from "@effect/platform/HttpClient" -export { ClientEvents } from "./Events.js" +export { ClientEvents } from "./Domain/Events.js" // codegen:start {preset: barrel, include: ./**/*.resources.ts, exclude: [./resources/index.ts, ./resources/lib.ts, ./resources/integrationEvents.ts, ./resources/Messages.ts, ./resources/views.ts, ./resources/Events.ts], export: { as: 'PascalCase' }} export * as BlogResources from "./Blog/Blog.resources.js" From 83c20878a258187870860172d06f76269d9d9e74 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sun, 27 Oct 2024 09:05:39 +0100 Subject: [PATCH 05/11] cleanup --- api/src/Blog.ts | 6 +++--- api/src/Blog/{Blog.resources.ts => Api.ts} | 4 ++-- api/src/Blog/BlogPostRepo.ts | 2 +- api/src/Blog/PostView.ts | 2 +- api/src/HelloWorld.ts | 6 +++--- .../HelloWorld/{HelloWorld.resources.ts => Api.ts} | 6 +++--- api/src/Me.ts | 6 +++--- api/src/{User/Me.resources.ts => Me/Api.ts} | 4 ++-- api/src/Operations.ts | 4 ++-- .../Operations/{Operations.resources.ts => Api.ts} | 4 ++-- api/src/Users.ts | 8 ++++---- api/src/{User/Users.resources.ts => Users/Api.ts} | 4 ++-- api/src/{User => Users}/UserRepo.ts | 0 api/src/{User => Users}/UserResolver.ts | 4 ++-- api/src/{User => Users}/UserView.ts | 0 api/src/lib/middleware/events.ts | 2 +- api/src/resources.ts | 14 +++++++------- api/src/services/Events.ts | 2 +- 18 files changed, 39 insertions(+), 39 deletions(-) rename api/src/Blog/{Blog.resources.ts => Api.ts} (90%) rename api/src/HelloWorld/{HelloWorld.resources.ts => Api.ts} (72%) rename api/src/{User/Me.resources.ts => Me/Api.ts} (67%) rename api/src/Operations/{Operations.resources.ts => Api.ts} (95%) rename api/src/{User/Users.resources.ts => Users/Api.ts} (74%) rename api/src/{User => Users}/UserRepo.ts (100%) rename api/src/{User => Users}/UserResolver.ts (95%) rename api/src/{User => Users}/UserView.ts (100%) diff --git a/api/src/Blog.ts b/api/src/Blog.ts index dc7c945db..0ba9fe755 100644 --- a/api/src/Blog.ts +++ b/api/src/Blog.ts @@ -1,16 +1,16 @@ import { OperationsDefault } from "api/lib/layers.js" import { matchFor } from "api/lib/routing.js" import { Events, Operations } from "api/services.js" -import { UserRepo } from "api/User/UserRepo.js" +import { UserRepo } from "api/Users/UserRepo.js" import { Duration, Effect, Schedule } from "effect" import { Option } from "effect-app" import { NonEmptyString2k, NonNegativeInt } from "effect-app/Schema" -import { BlogResources } from "resources.js" +import { blogApi } from "resources.js" import { BlogPostRepo } from "./Blog/BlogPostRepo.js" import { BlogPost } from "./Domain/Blog.js" import { BogusEvent } from "./Domain/Events.js" -export default matchFor(BlogResources)([ +export default matchFor(blogApi)([ BlogPostRepo.Default, UserRepo.Default, OperationsDefault, diff --git a/api/src/Blog/Blog.resources.ts b/api/src/Blog/Api.ts similarity index 90% rename from api/src/Blog/Blog.resources.ts rename to api/src/Blog/Api.ts index f7f8e9cf0..61d4e7d8b 100644 --- a/api/src/Blog/Blog.resources.ts +++ b/api/src/Blog/Api.ts @@ -26,6 +26,6 @@ export class PublishPost extends S.Req()("PublishPost", { id: BlogPostId }, { allowRoles: ["user"], success: OperationId, failure: S.Union(NotFoundError) }) {} -// codegen:start {preset: meta, sourcePrefix: src/Blog/} -export const meta = { moduleName: "Blog.resources" } as const +//// codegen:start {preset: meta, sourcePrefix: src/Blog/} +export const meta = { moduleName: "Blog" } as const // codegen:end diff --git a/api/src/Blog/BlogPostRepo.ts b/api/src/Blog/BlogPostRepo.ts index a08009373..1db04cf47 100644 --- a/api/src/Blog/BlogPostRepo.ts +++ b/api/src/Blog/BlogPostRepo.ts @@ -2,7 +2,7 @@ import { Model } from "@effect-app/infra" import { BlogPost } from "api/Domain/Blog.js" import { UserFromIdResolver } from "api/Domain/User.js" import { RepoDefault } from "api/lib/layers.js" -import { UserRepo } from "api/User/UserRepo.js" +import { UserRepo } from "api/Users/UserRepo.js" import { Effect } from "effect" import { Context } from "effect-app" import { NonEmptyString255, NonEmptyString2k } from "effect-app/Schema" diff --git a/api/src/Blog/PostView.ts b/api/src/Blog/PostView.ts index e10d08d9d..313a8bc3e 100644 --- a/api/src/Blog/PostView.ts +++ b/api/src/Blog/PostView.ts @@ -1,6 +1,6 @@ import { BlogPost } from "api/Domain/Blog.js" import { S } from "api/lib.js" -import { UserViewFromId } from "api/User/UserResolver.js" +import { UserViewFromId } from "api/Users/UserResolver.js" export class BlogPostView extends S.ExtendedClass()({ ...BlogPost.omit("author"), diff --git a/api/src/HelloWorld.ts b/api/src/HelloWorld.ts index 981f8b2d9..fa3b8ba3d 100644 --- a/api/src/HelloWorld.ts +++ b/api/src/HelloWorld.ts @@ -1,12 +1,12 @@ import { getRequestContext } from "@effect-app/infra/api/setupRequest" import { generate } from "@effect-app/infra/test" import { matchFor } from "api/lib/routing.js" -import { UserRepo } from "api/User/UserRepo.js" +import { UserRepo } from "api/Users/UserRepo.js" import { Effect, S } from "effect-app" -import { HelloWorldResources } from "resources.js" +import { helloWorldApi } from "resources.js" import { User } from "./Domain/User.js" -export default matchFor(HelloWorldResources)([ +export default matchFor(helloWorldApi)([ UserRepo.Default ], ({ GetHelloWorld }) => Effect.gen(function*() { diff --git a/api/src/HelloWorld/HelloWorld.resources.ts b/api/src/HelloWorld/Api.ts similarity index 72% rename from api/src/HelloWorld/HelloWorld.resources.ts rename to api/src/HelloWorld/Api.ts index 09469dfdb..aad0e1314 100644 --- a/api/src/HelloWorld/HelloWorld.resources.ts +++ b/api/src/HelloWorld/Api.ts @@ -1,6 +1,6 @@ import { RequestContext } from "@effect-app/infra/RequestContext" import { S } from "api/lib.js" -import { UserView } from "api/User/UserView.js" +import { UserView } from "api/Users/UserView.js" class Response extends S.Class()({ now: S.Date.withDefault, @@ -14,6 +14,6 @@ export class GetHelloWorld extends S.Req()("GetHelloWorld", { echo: S.String }, { allowAnonymous: true, allowRoles: ["user"], success: Response }) {} -// codegen:start {preset: meta, sourcePrefix: src/HelloWorld/} -export const meta = { moduleName: "HelloWorld.resources" } as const +//// codegen:start {preset: meta, sourcePrefix: src/HelloWorld/} +export const meta = { moduleName: "HelloWorld" } as const // codegen:end diff --git a/api/src/Me.ts b/api/src/Me.ts index 978ebb16b..238e7d5d5 100644 --- a/api/src/Me.ts +++ b/api/src/Me.ts @@ -1,9 +1,9 @@ import { matchFor } from "api/lib/routing.js" import { Effect } from "effect-app" -import { MeResources } from "resources.js" -import { UserRepo } from "./User/UserRepo.js" +import { meApi } from "resources.js" +import { UserRepo } from "./Users/UserRepo.js" -export default matchFor(MeResources)([ +export default matchFor(meApi)([ UserRepo.Default ], ({ GetMe }) => Effect.gen(function*() { diff --git a/api/src/User/Me.resources.ts b/api/src/Me/Api.ts similarity index 67% rename from api/src/User/Me.resources.ts rename to api/src/Me/Api.ts index 0a20ea203..3fe0272b2 100644 --- a/api/src/User/Me.resources.ts +++ b/api/src/Me/Api.ts @@ -4,6 +4,6 @@ import { NotFoundError } from "effect-app/client" export class GetMe extends S.Req()("GetMe", {}, { success: User, failure: NotFoundError }) {} -// codegen:start {preset: meta, sourcePrefix: src/User/} -export const meta = { moduleName: "Me.resources" } as const +//// codegen:start {preset: meta, sourcePrefix: src/User/} +export const meta = { moduleName: "Me" } as const // codegen:end diff --git a/api/src/Operations.ts b/api/src/Operations.ts index 3a76224aa..ca8b9ee49 100644 --- a/api/src/Operations.ts +++ b/api/src/Operations.ts @@ -2,9 +2,9 @@ import { OperationsDefault } from "api/lib.js" import { matchFor } from "api/lib/routing.js" import { Operations } from "api/services.js" import { Effect } from "effect-app" -import { OperationsResources } from "resources.js" +import { operationsApi } from "resources.js" -export default matchFor(OperationsResources)([ +export default matchFor(operationsApi)([ OperationsDefault ], ({ FindOperation }) => Effect.gen(function*() { diff --git a/api/src/Operations/Operations.resources.ts b/api/src/Operations/Api.ts similarity index 95% rename from api/src/Operations/Operations.resources.ts rename to api/src/Operations/Api.ts index a68fcb987..19db36446 100644 --- a/api/src/Operations/Operations.resources.ts +++ b/api/src/Operations/Api.ts @@ -7,8 +7,8 @@ export class FindOperation extends S.Req()("FindOperation", { id: OperationId }, { allowAnonymous: true, allowRoles: ["user"], success: S.NullOr(Operation) }) {} -// codegen:start {preset: meta, sourcePrefix: src/Operations/} -export const meta = { moduleName: "Operations.resources" } as const +//// codegen:start {preset: meta, sourcePrefix: src/Operations/} +export const meta = { moduleName: "Operations" } as const // codegen:end // Extensions diff --git a/api/src/Users.ts b/api/src/Users.ts index 29ba7a74d..5561a425b 100644 --- a/api/src/Users.ts +++ b/api/src/Users.ts @@ -2,11 +2,11 @@ import { matchFor } from "api/lib/routing.js" import { Q } from "api/services.js" import { Array } from "effect" import { Effect, Order } from "effect-app" -import { UsersResources } from "resources.js" -import { UserRepo } from "./User/UserRepo.js" -import type { UserView } from "./User/UserView.js" +import { usersApi } from "resources.js" +import { UserRepo } from "./Users/UserRepo.js" +import type { UserView } from "./Users/UserView.js" -export default matchFor(UsersResources)([ +export default matchFor(usersApi)([ UserRepo.Default ], ({ IndexUsers }) => Effect.gen(function*() { diff --git a/api/src/User/Users.resources.ts b/api/src/Users/Api.ts similarity index 74% rename from api/src/User/Users.resources.ts rename to api/src/Users/Api.ts index 2b7efa830..2e1e1965f 100644 --- a/api/src/User/Users.resources.ts +++ b/api/src/Users/Api.ts @@ -12,6 +12,6 @@ export class IndexUsers extends S.Req()("IndexUsers", { }) }) {} -// codegen:start {preset: meta, sourcePrefix: src/User/} -export const meta = { moduleName: "Users.resources" } as const +//// codegen:start {preset: meta, sourcePrefix: src/User/} +export const meta = { moduleName: "Users" } as const // codegen:end diff --git a/api/src/User/UserRepo.ts b/api/src/Users/UserRepo.ts similarity index 100% rename from api/src/User/UserRepo.ts rename to api/src/Users/UserRepo.ts diff --git a/api/src/User/UserResolver.ts b/api/src/Users/UserResolver.ts similarity index 95% rename from api/src/User/UserResolver.ts rename to api/src/Users/UserResolver.ts index ea130dd08..54179d38a 100644 --- a/api/src/User/UserResolver.ts +++ b/api/src/Users/UserResolver.ts @@ -5,7 +5,7 @@ import { Array, Option, pipe, S } from "effect-app" import { ApiConfig, NotFoundError } from "effect-app/client" import { HttpClient } from "effect-app/http" import { type Schema } from "effect-app/Schema" -import * as UsersRsc from "./Users.resources.js" +import { IndexUsers } from "./Api.js" import { UserView } from "./UserView.js" interface GetUserViewById extends Request.Request> { @@ -14,7 +14,7 @@ interface GetUserViewById extends Request.Request("GetUserViewById") -const userClient = clientFor(UsersRsc) +const userClient = clientFor({ IndexUsers }) const getUserViewByIdResolver = RequestResolver .makeBatched((requests: GetUserViewById[]) => diff --git a/api/src/User/UserView.ts b/api/src/Users/UserView.ts similarity index 100% rename from api/src/User/UserView.ts rename to api/src/Users/UserView.ts diff --git a/api/src/lib/middleware/events.ts b/api/src/lib/middleware/events.ts index 622dd1842..7439ac670 100644 --- a/api/src/lib/middleware/events.ts +++ b/api/src/lib/middleware/events.ts @@ -1,6 +1,6 @@ import { makeSSE } from "@effect-app/infra/api/middlewares" +import { ClientEvents } from "api/Domain/Events.js" import { Events } from "api/services.js" import { Effect } from "effect-app" -import { ClientEvents } from "resources.js" export const makeEvents = Events.pipe(Effect.map((events) => makeSSE(events.stream, ClientEvents))) diff --git a/api/src/resources.ts b/api/src/resources.ts index bb6efca57..dbd345f1a 100644 --- a/api/src/resources.ts +++ b/api/src/resources.ts @@ -1,11 +1,11 @@ import type {} from "@effect/platform/HttpClient" -export { ClientEvents } from "./Domain/Events.js" +// codegen:start {preset: barrel, include: './[A-Z]*/Api.ts', import: star} +import * as blogApi from "./Blog/Api.js" +import * as helloWorldApi from "./HelloWorld/Api.js" +import * as meApi from "./Me/Api.js" +import * as operationsApi from "./Operations/Api.js" +import * as usersApi from "./Users/Api.js" -// codegen:start {preset: barrel, include: ./**/*.resources.ts, exclude: [./resources/index.ts, ./resources/lib.ts, ./resources/integrationEvents.ts, ./resources/Messages.ts, ./resources/views.ts, ./resources/Events.ts], export: { as: 'PascalCase' }} -export * as BlogResources from "./Blog/Blog.resources.js" -export * as HelloWorldResources from "./HelloWorld/HelloWorld.resources.js" -export * as OperationsResources from "./Operations/Operations.resources.js" -export * as MeResources from "./User/Me.resources.js" -export * as UsersResources from "./User/Users.resources.js" +export { blogApi, helloWorldApi, meApi, operationsApi, usersApi } // codegen:end diff --git a/api/src/services/Events.ts b/api/src/services/Events.ts index 6b19154fb..95bb53637 100644 --- a/api/src/services/Events.ts +++ b/api/src/services/Events.ts @@ -1,7 +1,7 @@ import { storeId } from "@effect-app/infra/Store/Memory" +import type { ClientEvents } from "api/Domain/Events.js" import { Effect, FiberRef, PubSub, Stream } from "effect-app" import type { NonEmptyReadonlyArray } from "effect/Array" -import type { ClientEvents } from "resources.js" export class Events extends Effect.Service()("Events", { accessors: true, From 608f81ae89f2fc6badb121488213f5950dc15e52 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sun, 27 Oct 2024 09:05:47 +0100 Subject: [PATCH 06/11] include dir in tab --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0c49f65fc..474547a32 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "workbench.editor.labelFormat": "short", "explorer.sortOrderLexicographicOptions": "upper", "typescript.preferences.includePackageJsonAutoImports": "on", "typescript.preferences.autoImportFileExcludePatterns": [ From 09ba1a5aaa8373829cb2de03f9b5cd3e036beef4 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sun, 27 Oct 2024 09:10:33 +0100 Subject: [PATCH 07/11] integrate Users and Me into Accounts --- api/src/{Users.ts => Accounts.ts} | 16 ++++++++-------- api/src/{Users => Accounts}/Api.ts | 7 +++++-- api/src/{Users => Accounts}/UserRepo.ts | 0 api/src/{Users => Accounts}/UserResolver.ts | 0 api/src/{Users => Accounts}/UserView.ts | 0 api/src/Blog.ts | 2 +- api/src/Blog/BlogPostRepo.ts | 2 +- api/src/Blog/PostView.ts | 2 +- api/src/HelloWorld.ts | 2 +- api/src/HelloWorld/Api.ts | 2 +- api/src/Me.ts | 14 -------------- api/src/Me/Api.ts | 9 --------- api/src/controllers.ts | 5 ++--- api/src/resources.ts | 5 ++--- 14 files changed, 22 insertions(+), 44 deletions(-) rename api/src/{Users.ts => Accounts.ts} (55%) rename api/src/{Users => Accounts}/Api.ts (59%) rename api/src/{Users => Accounts}/UserRepo.ts (100%) rename api/src/{Users => Accounts}/UserResolver.ts (100%) rename api/src/{Users => Accounts}/UserView.ts (100%) delete mode 100644 api/src/Me.ts delete mode 100644 api/src/Me/Api.ts diff --git a/api/src/Users.ts b/api/src/Accounts.ts similarity index 55% rename from api/src/Users.ts rename to api/src/Accounts.ts index 5561a425b..ae6d41dc8 100644 --- a/api/src/Users.ts +++ b/api/src/Accounts.ts @@ -1,17 +1,17 @@ import { matchFor } from "api/lib/routing.js" -import { Q } from "api/services.js" -import { Array } from "effect" -import { Effect, Order } from "effect-app" -import { usersApi } from "resources.js" -import { UserRepo } from "./Users/UserRepo.js" -import type { UserView } from "./Users/UserView.js" +import { Array, Effect, Order } from "effect-app" +import { accountsApi } from "resources.js" +import { UserRepo } from "./Accounts/UserRepo.js" +import type { UserView } from "./Accounts/UserView.js" +import { Q } from "./services.js" -export default matchFor(usersApi)([ +export default matchFor(accountsApi)([ UserRepo.Default -], ({ IndexUsers }) => +], ({ GetMe, IndexUsers }) => Effect.gen(function*() { const userRepo = yield* UserRepo return { + GetMe: GetMe(userRepo.getCurrentUser), IndexUsers: IndexUsers((req) => userRepo .query(Q.where("id", "in", req.filterByIds)) diff --git a/api/src/Users/Api.ts b/api/src/Accounts/Api.ts similarity index 59% rename from api/src/Users/Api.ts rename to api/src/Accounts/Api.ts index 2e1e1965f..7b5a79b5e 100644 --- a/api/src/Users/Api.ts +++ b/api/src/Accounts/Api.ts @@ -1,7 +1,10 @@ -import { UserId } from "api/Domain/User.js" +import { User, UserId } from "api/Domain/User.js" import { S } from "api/lib.js" +import { NotFoundError } from "effect-app/client" import { UserView } from "./UserView.js" +export class GetMe extends S.Req()("GetMe", {}, { success: User, failure: NotFoundError }) {} + export class IndexUsers extends S.Req()("IndexUsers", { filterByIds: S.NonEmptyArray(UserId) }, { @@ -13,5 +16,5 @@ export class IndexUsers extends S.Req()("IndexUsers", { }) {} //// codegen:start {preset: meta, sourcePrefix: src/User/} -export const meta = { moduleName: "Users" } as const +export const meta = { moduleName: "Me" } as const // codegen:end diff --git a/api/src/Users/UserRepo.ts b/api/src/Accounts/UserRepo.ts similarity index 100% rename from api/src/Users/UserRepo.ts rename to api/src/Accounts/UserRepo.ts diff --git a/api/src/Users/UserResolver.ts b/api/src/Accounts/UserResolver.ts similarity index 100% rename from api/src/Users/UserResolver.ts rename to api/src/Accounts/UserResolver.ts diff --git a/api/src/Users/UserView.ts b/api/src/Accounts/UserView.ts similarity index 100% rename from api/src/Users/UserView.ts rename to api/src/Accounts/UserView.ts diff --git a/api/src/Blog.ts b/api/src/Blog.ts index 0ba9fe755..70725647e 100644 --- a/api/src/Blog.ts +++ b/api/src/Blog.ts @@ -1,11 +1,11 @@ import { OperationsDefault } from "api/lib/layers.js" import { matchFor } from "api/lib/routing.js" import { Events, Operations } from "api/services.js" -import { UserRepo } from "api/Users/UserRepo.js" import { Duration, Effect, Schedule } from "effect" import { Option } from "effect-app" import { NonEmptyString2k, NonNegativeInt } from "effect-app/Schema" import { blogApi } from "resources.js" +import { UserRepo } from "./Accounts/UserRepo.js" import { BlogPostRepo } from "./Blog/BlogPostRepo.js" import { BlogPost } from "./Domain/Blog.js" import { BogusEvent } from "./Domain/Events.js" diff --git a/api/src/Blog/BlogPostRepo.ts b/api/src/Blog/BlogPostRepo.ts index 1db04cf47..67aa16cdf 100644 --- a/api/src/Blog/BlogPostRepo.ts +++ b/api/src/Blog/BlogPostRepo.ts @@ -1,8 +1,8 @@ import { Model } from "@effect-app/infra" +import { UserRepo } from "api/Accounts/UserRepo.js" import { BlogPost } from "api/Domain/Blog.js" import { UserFromIdResolver } from "api/Domain/User.js" import { RepoDefault } from "api/lib/layers.js" -import { UserRepo } from "api/Users/UserRepo.js" import { Effect } from "effect" import { Context } from "effect-app" import { NonEmptyString255, NonEmptyString2k } from "effect-app/Schema" diff --git a/api/src/Blog/PostView.ts b/api/src/Blog/PostView.ts index 313a8bc3e..6b53e1520 100644 --- a/api/src/Blog/PostView.ts +++ b/api/src/Blog/PostView.ts @@ -1,6 +1,6 @@ +import { UserViewFromId } from "api/Accounts/UserResolver.js" import { BlogPost } from "api/Domain/Blog.js" import { S } from "api/lib.js" -import { UserViewFromId } from "api/Users/UserResolver.js" export class BlogPostView extends S.ExtendedClass()({ ...BlogPost.omit("author"), diff --git a/api/src/HelloWorld.ts b/api/src/HelloWorld.ts index fa3b8ba3d..36665ee16 100644 --- a/api/src/HelloWorld.ts +++ b/api/src/HelloWorld.ts @@ -1,9 +1,9 @@ import { getRequestContext } from "@effect-app/infra/api/setupRequest" import { generate } from "@effect-app/infra/test" import { matchFor } from "api/lib/routing.js" -import { UserRepo } from "api/Users/UserRepo.js" import { Effect, S } from "effect-app" import { helloWorldApi } from "resources.js" +import { UserRepo } from "./Accounts/UserRepo.js" import { User } from "./Domain/User.js" export default matchFor(helloWorldApi)([ diff --git a/api/src/HelloWorld/Api.ts b/api/src/HelloWorld/Api.ts index aad0e1314..d3cdfa4f9 100644 --- a/api/src/HelloWorld/Api.ts +++ b/api/src/HelloWorld/Api.ts @@ -1,6 +1,6 @@ import { RequestContext } from "@effect-app/infra/RequestContext" +import { UserView } from "api/Accounts/UserView.js" import { S } from "api/lib.js" -import { UserView } from "api/Users/UserView.js" class Response extends S.Class()({ now: S.Date.withDefault, diff --git a/api/src/Me.ts b/api/src/Me.ts deleted file mode 100644 index 238e7d5d5..000000000 --- a/api/src/Me.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { matchFor } from "api/lib/routing.js" -import { Effect } from "effect-app" -import { meApi } from "resources.js" -import { UserRepo } from "./Users/UserRepo.js" - -export default matchFor(meApi)([ - UserRepo.Default -], ({ GetMe }) => - Effect.gen(function*() { - const userRepo = yield* UserRepo - return { - GetMe: GetMe(userRepo.getCurrentUser) - } - })) diff --git a/api/src/Me/Api.ts b/api/src/Me/Api.ts deleted file mode 100644 index 3fe0272b2..000000000 --- a/api/src/Me/Api.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { User } from "api/Domain/User.js" -import { S } from "api/lib.js" -import { NotFoundError } from "effect-app/client" - -export class GetMe extends S.Req()("GetMe", {}, { success: User, failure: NotFoundError }) {} - -//// codegen:start {preset: meta, sourcePrefix: src/User/} -export const meta = { moduleName: "Me" } as const -// codegen:end diff --git a/api/src/controllers.ts b/api/src/controllers.ts index cad9b4134..b1c7def1e 100644 --- a/api/src/controllers.ts +++ b/api/src/controllers.ts @@ -1,9 +1,8 @@ // codegen:start {preset: barrel, include: './[A-Z]*.ts', import: default} +import accounts from "./Accounts.js" import blog from "./Blog.js" import helloWorld from "./HelloWorld.js" -import me from "./Me.js" import operations from "./Operations.js" -import users from "./Users.js" -export { blog, helloWorld, me, operations, users } +export { accounts, blog, helloWorld, operations } // codegen:end diff --git a/api/src/resources.ts b/api/src/resources.ts index dbd345f1a..259f90eee 100644 --- a/api/src/resources.ts +++ b/api/src/resources.ts @@ -1,11 +1,10 @@ import type {} from "@effect/platform/HttpClient" // codegen:start {preset: barrel, include: './[A-Z]*/Api.ts', import: star} +import * as accountsApi from "./Accounts/Api.js" import * as blogApi from "./Blog/Api.js" import * as helloWorldApi from "./HelloWorld/Api.js" -import * as meApi from "./Me/Api.js" import * as operationsApi from "./Operations/Api.js" -import * as usersApi from "./Users/Api.js" -export { blogApi, helloWorldApi, meApi, operationsApi, usersApi } +export { accountsApi, blogApi, helloWorldApi, operationsApi } // codegen:end From 559ee0c6b87fe19d3619e0c7c5aa2bbd2cbcb18b Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sun, 27 Oct 2024 09:14:20 +0100 Subject: [PATCH 08/11] rename actions --- api/src/Accounts.ts | 4 ++-- api/src/Accounts/Api.ts | 2 +- api/src/Accounts/UserResolver.ts | 6 +++--- api/src/Blog.ts | 4 ++-- api/src/Blog/Api.ts | 2 +- frontend/pages/blog/index.vue | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/src/Accounts.ts b/api/src/Accounts.ts index ae6d41dc8..af055b7c9 100644 --- a/api/src/Accounts.ts +++ b/api/src/Accounts.ts @@ -7,12 +7,12 @@ import { Q } from "./services.js" export default matchFor(accountsApi)([ UserRepo.Default -], ({ GetMe, IndexUsers }) => +], ({ GetMe, Index }) => Effect.gen(function*() { const userRepo = yield* UserRepo return { GetMe: GetMe(userRepo.getCurrentUser), - IndexUsers: IndexUsers((req) => + Index: Index((req) => userRepo .query(Q.where("id", "in", req.filterByIds)) .pipe(Effect.andThen((users) => ({ diff --git a/api/src/Accounts/Api.ts b/api/src/Accounts/Api.ts index 7b5a79b5e..18ca00bcf 100644 --- a/api/src/Accounts/Api.ts +++ b/api/src/Accounts/Api.ts @@ -5,7 +5,7 @@ import { UserView } from "./UserView.js" export class GetMe extends S.Req()("GetMe", {}, { success: User, failure: NotFoundError }) {} -export class IndexUsers extends S.Req()("IndexUsers", { +export class Index extends S.Req()("Index", { filterByIds: S.NonEmptyArray(UserId) }, { allowAnonymous: true, diff --git a/api/src/Accounts/UserResolver.ts b/api/src/Accounts/UserResolver.ts index 54179d38a..c29c58ff1 100644 --- a/api/src/Accounts/UserResolver.ts +++ b/api/src/Accounts/UserResolver.ts @@ -5,7 +5,7 @@ import { Array, Option, pipe, S } from "effect-app" import { ApiConfig, NotFoundError } from "effect-app/client" import { HttpClient } from "effect-app/http" import { type Schema } from "effect-app/Schema" -import { IndexUsers } from "./Api.js" +import { Index } from "./Api.js" import { UserView } from "./UserView.js" interface GetUserViewById extends Request.Request> { @@ -14,12 +14,12 @@ interface GetUserViewById extends Request.Request("GetUserViewById") -const userClient = clientFor({ IndexUsers }) +const userClient = clientFor({ Index }) const getUserViewByIdResolver = RequestResolver .makeBatched((requests: GetUserViewById[]) => userClient - .IndexUsers + .Index .handler({ filterByIds: pipe(requests.map((_) => _.id), Array.toNonEmptyArray, Option.getOrUndefined)! }) .pipe( Effect.andThen(({ users }) => diff --git a/api/src/Blog.ts b/api/src/Blog.ts index 70725647e..ba4fb166d 100644 --- a/api/src/Blog.ts +++ b/api/src/Blog.ts @@ -15,7 +15,7 @@ export default matchFor(blogApi)([ UserRepo.Default, OperationsDefault, Events.Default -], ({ CreatePost, FindPost, GetPosts, PublishPost }) => +], ({ CreatePost, FindPost, Index, PublishPost }) => Effect.gen(function*() { const blogPostRepo = yield* BlogPostRepo const userRepo = yield* UserRepo @@ -29,7 +29,7 @@ export default matchFor(blogApi)([ .pipe(Effect.andThen(Option.getOrNull)) ), - GetPosts: GetPosts( + Index: Index( blogPostRepo .all .pipe(Effect.andThen((items) => ({ items }))) diff --git a/api/src/Blog/Api.ts b/api/src/Blog/Api.ts index 61d4e7d8b..57780b63f 100644 --- a/api/src/Blog/Api.ts +++ b/api/src/Blog/Api.ts @@ -14,7 +14,7 @@ export class FindPost extends S.Req()("FindPost", { id: BlogPostId }, { allowAnonymous: true, allowRoles: ["user"], success: S.NullOr(BlogPostView) }) {} -export class GetPosts extends S.Req()("GetPosts", {}, { +export class Index extends S.Req()("Index", {}, { allowAnonymous: true, allowRoles: ["user"], success: S.Struct({ diff --git a/frontend/pages/blog/index.vue b/frontend/pages/blog/index.vue index 2bbe96ed1..01370075a 100644 --- a/frontend/pages/blog/index.vue +++ b/frontend/pages/blog/index.vue @@ -5,7 +5,7 @@ import { S } from "effect-app" const blogClient = clientFor(BlogRsc) const [, createPost] = useSafeMutation(blogClient.CreatePost) -const [r] = useSafeQuery(blogClient.GetPosts) +const [r] = useSafeQuery(blogClient.Index)