@domain-first/project-structure 2.18.1 → 3.1.0
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 +34 -2
- package/dist/index.cjs +602 -533
- package/dist/index.js +601 -532
- package/dist/print-next-steps.d.ts +5 -0
- package/dist/use-cases/initialize.d.ts +4 -1
- package/dist/use-cases/rest-endpoint-generator.d.ts +20 -0
- package/dist/use-cases/rest-endpoint-generator.spec.d.ts +1 -0
- package/dist/use-cases/scaffold-new-presentation-service.d.ts +5 -0
- package/dist/use-cases/wire-dependency.d.ts +3 -8
- package/dist/wiring.d.ts +0 -4
- package/package.json +1 -1
- package/skills/df-ps-implement/SKILL.md +2 -2
- package/skills/df-ps-scaffold/SKILL.md +1 -1
- package/skills/df-ps-scaffold/references/generators.md +5 -5
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ The full technical specification lives in [API.md](./API.md).
|
|
|
28
28
|
|
|
29
29
|
### How to initialize a project
|
|
30
30
|
|
|
31
|
-
Run `df-ps` in a project with a `package.json`. The first run asks for the source folder, the `@domain-first` packages you use, the default persistence implementation, React, Storybook and the testing library, then writes `domain-first.project-structure.config.json` and exits.
|
|
31
|
+
Run `df-ps` in a project with a `package.json`. The first run asks for the source folder, the `@domain-first` packages you use, the default persistence implementation, React, Storybook and the testing library, then writes `domain-first.project-structure.config.json` and exits. With `@domain-first/handlers-rest`, it also scaffolds the [endpoint generator](#how-to-add-a-rest-endpoint); if `next` is among your dependencies, it offers to connect `nextAdapter` from `@domain-first/handlers-next` right away and prints the install command for it when it's missing.
|
|
32
32
|
|
|
33
33
|
```
|
|
34
34
|
npx df-ps
|
|
@@ -153,7 +153,39 @@ With `@domain-first/handlers-rest`, choose **Presentation → New Handlers-REST
|
|
|
153
153
|
src/bounded-contexts/sales/presentation/rest/orders/recent/GET.ts // GET /sales/orders/recent
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
Every endpoint uses the one endpoint generator of the project, `RestEndpointGeneratorPresentationService` in `src/shared/presentation/services/`. Initialization scaffolds it as a regular Shared Layer presentation service (class, spec and wire):
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
/**
|
|
160
|
+
* The adapter of your HTTP framework.
|
|
161
|
+
*/
|
|
162
|
+
const adapter = undefined as unknown as Adapter<any[], any>
|
|
163
|
+
|
|
164
|
+
export class RestEndpointGeneratorPresentationService {
|
|
165
|
+
/**
|
|
166
|
+
* Default errors of a client request, to spread into a generator's
|
|
167
|
+
* own checks.
|
|
168
|
+
*/
|
|
169
|
+
private get defaultClientRequestErrors(): ErrorStatuses[number]['checks'] {
|
|
170
|
+
return [RequestParsingError.is, InputMappingError.is]
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get withoutGuards(): EndpointGenerator {
|
|
174
|
+
return createEndpoint({
|
|
175
|
+
errorStatuses: {
|
|
176
|
+
400: {
|
|
177
|
+
checks: this.defaultClientRequestErrors,
|
|
178
|
+
description: 'Invalid request'
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
})(adapter) as EndpointGenerator
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Set the module-level `adapter` constant above the class to the adapter of your HTTP framework; the class uses it through closure. If you connected the Next adapter during initialization, the file imports `nextAdapter` from `@domain-first/handlers-next` instead, with nothing to set. Each generating method is a getter returning `EndpointGenerator`: add one per kind of endpoint (for example `withAuth`, with its `context` and error statuses). Reuse the default checks there and add your own: `checks: [...this.defaultClientRequestErrors, MyError.is]`. A new endpoint calls `this.endpointGenerator(...)` and doesn't compile on purpose: choose the getter yourself in its `get handle()`, e.g. `this.endpointGenerator.withoutGuards(...)`.
|
|
187
|
+
|
|
188
|
+
With wiring, the endpoint takes the generator and a handler you pick from the context's queries, commands and use cases, and all endpoints are collected as `restHandlers` in `src/presentation/rest/index.ts`. Connect them to your HTTP server.
|
|
157
189
|
|
|
158
190
|
### How to scaffold React modules
|
|
159
191
|
|