forked from effect-app/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogPostRepo.ts
More file actions
39 lines (35 loc) · 1.03 KB
/
BlogPostRepo.ts
File metadata and controls
39 lines (35 loc) · 1.03 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
import { BlogPost, BlogPostId } from "@effect-app-boilerplate/models/Blog"
import { RepositoryDefaultImpl } from "@effect-app/infra/services/RepositoryBase"
export interface BlogPostPersistenceModel extends BlogPost.Encoded {
_etag: string | undefined
}
export type BlogPostSeed = "sample" | ""
/**
* @tsplus type BlogPostRepo
* @tsplus companion BlogPostRepo.Ops
*/
export class BlogPostRepo extends RepositoryDefaultImpl<BlogPostRepo>()<BlogPostPersistenceModel>()(
"BlogPost",
BlogPost,
(pm) => pm,
(e, _etag) => ({ ...e, _etag })
) {}
/**
* @tsplus static BlogPostRepo.Ops Live
*/
export function LiveBlogPostRepo(seed: BlogPostSeed) {
const makeInitial = Effect.sync(() => {
const items = seed === "sample"
? [
new BlogPost({
id: BlogPostId("post-test123"),
title: ReasonableString("Test post"),
body: LongString("imma test body")
})
] as const
: []
return items
})
return BlogPostRepo
.toLayer((_: Iterable<never>) => Effect.unit, makeInitial)
}