@alevnyacow/nzmt 0.8.4 → 0.8.6
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.
- package/README.md +19 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ NZMT is an opinionated toolkit with scaffolding for building structured Next.js
|
|
|
17
17
|
|
|
18
18
|
1. Generate Prisma client.
|
|
19
19
|
2. Install required peer dependencies (`inversify`, `zod`, `reflect-metadata`).
|
|
20
|
-
2. Enable `Experimental decorators` and `Emit Decorator Metadata` options in your tsconfig.json
|
|
20
|
+
2. Enable `Experimental decorators` and `Emit Decorator Metadata` options in your `tsconfig.json`.
|
|
21
21
|
3. Run the following:
|
|
22
22
|
|
|
23
23
|
```bash
|
|
@@ -30,13 +30,29 @@ npx nzmt entity product f:title-string,price-int.positive
|
|
|
30
30
|
# product store (with Prisma implementation, RAM implementation and DI)
|
|
31
31
|
npx nzmt store product
|
|
32
32
|
|
|
33
|
-
# product service with injected product store (with
|
|
33
|
+
# product service with injected product store (with DI)
|
|
34
34
|
npx nzmt service product i:ProductStore
|
|
35
35
|
|
|
36
|
-
# shop controller with injected
|
|
36
|
+
# shop controller with injected product service and logger (with DI)
|
|
37
37
|
npx nzmt controller shop i:Logger,ProductService
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
The entire structure and infrastructure have been generated. All that remains is developing the contracts and the logic. The organization and content of the generated files are clear, and they’re easy to understand.
|
|
41
|
+
|
|
42
|
+
You can use `fromDI` method anywhere you need an instance of a controller or a service:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// app/api/shop/route.ts
|
|
46
|
+
|
|
47
|
+
import { ShopController } from "@/server/controllers/shop"
|
|
48
|
+
import { fromDI } from "@/server/di"
|
|
49
|
+
|
|
50
|
+
const controller = fromDI<ShopController>('ShopController')
|
|
51
|
+
|
|
52
|
+
// Suppose you have implemented the list_GET method in the controller.
|
|
53
|
+
export const GET = controller.list_GET
|
|
54
|
+
```
|
|
55
|
+
|
|
40
56
|
# Design principles
|
|
41
57
|
|
|
42
58
|
## Core idea
|