@afora/fastify 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +17 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -15,12 +15,20 @@ bun add @afora/core @afora/fastify fastify typebox
15
15
  import {
16
16
  blueprintOf,
17
17
  commandOf,
18
+ entityOf,
18
19
  outputOf,
20
+ RepositoryEntityNotFound,
21
+ repositoryOf,
19
22
  Route,
20
23
  useCaseOf,
21
24
  } from "@afora/core";
22
25
  import { fastify } from "@afora/fastify";
23
26
 
27
+ class Post extends entityOf(
28
+ blueprintOf((ctx) => ({ title: ctx.text, slug: ctx.slug })),
29
+ ) {}
30
+ const Posts = repositoryOf({ entity: Post, actions: ["findBySlug", "create"] });
31
+
24
32
  @Route("GET", "/posts/{slug}")
25
33
  class GetPost extends useCaseOf({
26
34
  name: "GetPost",
@@ -29,7 +37,14 @@ class GetPost extends useCaseOf({
29
37
  dependencies: { posts: Posts },
30
38
  }) {
31
39
  override async execute() {
32
- return { post: await this.dependencies.posts.findBySlug(this.input.slug) };
40
+ const post = await this.dependencies.posts.findBySlug(this.input.slug);
41
+ if (!post) {
42
+ throw new RepositoryEntityNotFound({
43
+ source: "GetPost",
44
+ details: { id: this.input.slug },
45
+ }); // a 404
46
+ }
47
+ return { post };
33
48
  }
34
49
  }
35
50
 
@@ -98,6 +113,7 @@ The requests are handled by the route table of the core (`compileRoutes` of `@af
98
113
 
99
114
  ## Middlewares and your own app
100
115
 
116
+ <!-- docs:code skip: fragment: the second argument of the stage; tenantOf stands for your code -->
101
117
  ```ts
102
118
  fastify(
103
119
  { context: { variables: { tenant: "tenant" } } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afora/fastify",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A Fastify sink for afora outputs: one route per operation, problem+json errors, sensitive data masked, declared access enforced and an optional OpenAPI document.",
5
5
  "keywords": [
6
6
  "afora",