forked from effect-app/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresources.ts
More file actions
48 lines (40 loc) · 1.62 KB
/
resources.ts
File metadata and controls
48 lines (40 loc) · 1.62 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { UserViewFromId } from "#api/Accounts/resolvers"
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"),
author: S.propertySignature(UserViewFromId).pipe(S.fromKey("authorId"))
}) {}
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 GetPosts extends S.Req<GetPosts>()("GetPosts", {}, {
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/}
export const meta = { moduleName: "Blog" } as const
// codegen:end
// codegen:start {preset: model}
//
/* eslint-disable */
export namespace BlogPostView {
export interface Encoded extends S.Struct.Encoded<typeof BlogPostView["fields"]> {}
}
/* eslint-enable */
//
// codegen:end
export * as BlogRsc from "./resources.js"