forked from effect-app/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApi.ts
More file actions
31 lines (26 loc) · 1.16 KB
/
Api.ts
File metadata and controls
31 lines (26 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { BlogPost, BlogPostId } from "Domain/Blog.js"
import { S } from "lib/resources.js"
import { InvalidStateError, NotFoundError, OptimisticConcurrencyException } from "effect-app/client"
import { OperationId } from "effect-app/Operations"
import { BlogPostView } from "./PostView.js"
export class CreatePost extends S.Req<CreatePost>()("CreatePost", BlogPost.pick("title", "body"), {
allowRoles: ["user"],
success: S.Struct({ id: BlogPostId }),
failure: S.Union(NotFoundError, InvalidStateError, OptimisticConcurrencyException)
}) {}
export class FindPost extends S.Req<FindPost>()("FindPost", {
id: BlogPostId
}, { allowAnonymous: true, allowRoles: ["user"], success: S.NullOr(BlogPostView) }) {}
export class Index extends S.Req<Index>()("Index", {}, {
allowAnonymous: true,
allowRoles: ["user"],
success: S.Struct({
items: S.Array(BlogPostView)
})
}) {}
export class PublishPost extends S.Req<PublishPost>()("PublishPost", {
id: BlogPostId
}, { allowRoles: ["user"], success: OperationId, failure: S.Union(NotFoundError) }) {}
//// codegen:start {preset: meta, sourcePrefix: src/Blog/}
export const meta = { moduleName: "Blog" } as const
// codegen:end