@domain-first/project-structure 3.0.0 → 3.2.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 +18 -19
- package/dist/config-file.d.ts +1 -0
- package/dist/in-memory-db.d.ts +38 -0
- package/dist/in-memory-db.spec.d.ts +1 -0
- package/dist/index.cjs +322 -55
- package/dist/index.js +321 -54
- 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 +5 -2
- package/dist/use-cases/rest-endpoint-generator.spec.d.ts +1 -0
- package/dist/wiring.d.ts +4 -0
- package/package.json +1 -1
- package/skills/df-ps-implement/SKILL.md +1 -1
- package/skills/df-ps-scaffold/references/generators.md +2 -0
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. With `@domain-first/handlers-rest`, it also scaffolds the [endpoint generator](#how-to-add-a-rest-endpoint).
|
|
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, whether to scaffold a shared in-memory DB for test implementations, 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
|
|
@@ -44,6 +44,7 @@ npx df-ps
|
|
|
44
44
|
"@domain-first/wire"
|
|
45
45
|
],
|
|
46
46
|
"defaultPersistenceLayerImplementation": "prisma",
|
|
47
|
+
"withInMemoryDb": true,
|
|
47
48
|
"useReact": false,
|
|
48
49
|
"testingLibrary": "vitest"
|
|
49
50
|
}
|
|
@@ -156,36 +157,34 @@ src/bounded-contexts/sales/presentation/rest/orders/recent/GET.ts // GET /sale
|
|
|
156
157
|
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
|
|
|
158
159
|
```ts
|
|
160
|
+
/**
|
|
161
|
+
* The adapter of your HTTP framework.
|
|
162
|
+
*/
|
|
163
|
+
const adapter = undefined as unknown as Adapter<any[], any>
|
|
164
|
+
|
|
159
165
|
export class RestEndpointGeneratorPresentationService {
|
|
166
|
+
/**
|
|
167
|
+
* Default errors of a client request, to spread into a generator's
|
|
168
|
+
* own checks.
|
|
169
|
+
*/
|
|
170
|
+
private get defaultClientRequestErrors(): ErrorStatuses[number]['checks'] {
|
|
171
|
+
return [RequestParsingError.is, InputMappingError.is]
|
|
172
|
+
}
|
|
173
|
+
|
|
160
174
|
get withoutGuards(): EndpointGenerator {
|
|
161
175
|
return createEndpoint({
|
|
162
176
|
errorStatuses: {
|
|
163
177
|
400: {
|
|
164
|
-
checks: this.
|
|
178
|
+
checks: this.defaultClientRequestErrors,
|
|
165
179
|
description: 'Invalid request'
|
|
166
180
|
}
|
|
167
181
|
}
|
|
168
|
-
})(
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Default checks of an invalid request, to spread into a generator's
|
|
173
|
-
* own checks.
|
|
174
|
-
*/
|
|
175
|
-
private get invalidRequestChecks(): ErrorStatuses[number]['checks'] {
|
|
176
|
-
return [RequestParsingError.is, InputMappingError.is]
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* The adapter of your HTTP framework.
|
|
181
|
-
*/
|
|
182
|
-
private get adapter(): Adapter<any[], any> {
|
|
183
|
-
throw new Error('REST adapter is not set')
|
|
182
|
+
})(adapter) as EndpointGenerator
|
|
184
183
|
}
|
|
185
184
|
}
|
|
186
185
|
```
|
|
187
186
|
|
|
188
|
-
Set `adapter` to the adapter of your HTTP framework. 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.
|
|
187
|
+
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(...)`.
|
|
189
188
|
|
|
190
189
|
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.
|
|
191
190
|
|
package/dist/config-file.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare const configSchema: z.ZodObject<{
|
|
|
9
9
|
"@domain-first/handlers-rest": "@domain-first/handlers-rest";
|
|
10
10
|
}>>;
|
|
11
11
|
defaultPersistenceLayerImplementation: z.ZodString;
|
|
12
|
+
withInMemoryDb: z.ZodOptional<z.ZodBoolean>;
|
|
12
13
|
useReact: z.ZodBoolean;
|
|
13
14
|
storybookFramework: z.ZodOptional<z.ZodString>;
|
|
14
15
|
testingLibrary: z.ZodOptional<z.ZodString>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { File, Folder } from './file-system';
|
|
2
|
+
import { UnknownFormatNaming } from './unknown-format-naming';
|
|
3
|
+
/**
|
|
4
|
+
* The shared in-memory DB with its spec and wire, as the config says.
|
|
5
|
+
*/
|
|
6
|
+
export declare const scaffoldInMemoryDb: (shared: Folder) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Whether implementations of this type get the in-memory DB: it is
|
|
9
|
+
* enabled in the config and its files are there.
|
|
10
|
+
*/
|
|
11
|
+
export declare const usesInMemoryDb: (implementationType: string) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Adds a section of the type to the in-memory DB, unless it is there,
|
|
14
|
+
* and returns the section's field name.
|
|
15
|
+
*/
|
|
16
|
+
export declare const addInMemoryDbSection: (typeNaming: UnknownFormatNaming, typeImportTarget: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Import of the in-memory DB type for a file.
|
|
19
|
+
*/
|
|
20
|
+
export declare const inMemoryDbTypeImport: (fromFile: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Constructor of an implementation that keeps one section of the
|
|
23
|
+
* in-memory DB as `data`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const inMemoryDbSectionMembers: (field: string, derived: boolean) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Injects the whole in-memory DB into the implementation's constructor.
|
|
28
|
+
*/
|
|
29
|
+
export declare const injectInMemoryDb: (classFile: File, implementationName: string) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Passes the in-memory DB wire to the implementation's `wireClass`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const wireInMemoryDb: (consumerWireFile: File, implementationName: string) => void;
|
|
34
|
+
/**
|
|
35
|
+
* A spec without wiring builds the implementation itself, so it has to
|
|
36
|
+
* pass the in-memory DB.
|
|
37
|
+
*/
|
|
38
|
+
export declare const passInMemoryDb: (specFile: File, implementationName: string) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|