@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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Prints the steps left after a use case: installation commands first,
3
+ * then additional information.
4
+ */
5
+ export declare const printNextSteps: (nextSteps: string[]) => void;
@@ -1 +1,4 @@
1
- export declare const initializeUseCase: () => Promise<void>;
1
+ /**
2
+ * Initializes the project and returns the steps left to the user.
3
+ */
4
+ export declare const initializeUseCase: () => Promise<string[]>;
@@ -0,0 +1,20 @@
1
+ import { File, type Folder } from '../file-system';
2
+ /**
3
+ * The one endpoint generator of the project: a Shared Layer presentation
4
+ * service, scaffolded like any other. Every generating method is a getter
5
+ * typed as `EndpointGenerator`. With `withNextAdapter`, the adapter is
6
+ * `nextAdapter` of `@domain-first/handlers-next` instead of a placeholder.
7
+ */
8
+ export declare const scaffoldRestEndpointGenerator: (sharedFolder: Folder, { withNextAdapter }?: {
9
+ withNextAdapter?: boolean;
10
+ }) => File | undefined;
11
+ /**
12
+ * The generator's type and factory, or undefined in projects initialized
13
+ * without it.
14
+ */
15
+ export declare const findRestEndpointGenerator: (sharedFolder: Folder) => {
16
+ typeName: string;
17
+ typeFile: string;
18
+ wireName: string;
19
+ wireFile: string;
20
+ } | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,7 @@
1
1
  import type { Folder } from '../file-system';
2
+ /**
3
+ * Creates the service class, its spec and its factory. Returns the
4
+ * factory file, or undefined without wiring.
5
+ */
6
+ export declare const createPresentationService: (boundedContextFolder: Folder, name: string, classFile?: (className: string) => string) => import("../file-system").File | undefined;
2
7
  export declare const scaffoldNewPresentationService: (boundedContextFolder: Folder) => Promise<void>;
@@ -6,12 +6,7 @@ import { type WiredModule } from '../wiring';
6
6
  export declare const wireNewModuleDependencies: (boundedContextFolder: Folder, wireFile: File) => Promise<void>;
7
7
  export declare const wireDependency: (boundedContextFolder: Folder) => Promise<void>;
8
8
  /**
9
- * The endpoint's constructor parameters: an endpoint generator from the
10
- * presentation services of the context and the Shared Layer, and a
11
- * handler from the context's queries, commands, and use cases. Either is
12
- * undefined when there is nothing to choose from.
9
+ * The endpoint's handler, from the context's queries, commands, and use
10
+ * cases. Undefined when there is nothing to choose from.
13
11
  */
14
- export declare const promptEndpointDependencies: (boundedContextFolder: Folder) => Promise<{
15
- endpointGenerator: WiredModule | undefined;
16
- handler: WiredModule | undefined;
17
- }>;
12
+ export declare const promptEndpointHandler: (boundedContextFolder: Folder) => Promise<WiredModule | undefined>;
package/dist/wiring.d.ts CHANGED
@@ -53,10 +53,6 @@ export declare const implementationType: (consumer: WiredModule, implementation:
53
53
  * as whole words: `in-memory-db-infrastructure-service` for `in-memory`.
54
54
  */
55
55
  export declare const isSuggestedFor: (candidate: WiredModule, implementation: string) => boolean;
56
- /**
57
- * A likely endpoint generator: a service with `endpoint` in its name.
58
- */
59
- export declare const isSuggestedEndpointGenerator: (candidate: WiredModule) => boolean;
60
56
  export declare const canDependOn: (consumer: WiredModule, candidate: WiredModule) => boolean;
61
57
  /**
62
58
  * What an implementation of the consumer can depend on: modules of the
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domain-first/project-structure",
3
3
  "description": "Build and manage your Domain-First project structure with CLI",
4
- "version": "2.18.1",
4
+ "version": "3.1.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -77,9 +77,9 @@ export const wirePlaceOrderUseCase = wireClass(PlaceOrderUseCase, [wireOrderRepo
77
77
 
78
78
  ## REST endpoints ({handlers-rest})
79
79
 
80
- 1. Generator: once per project, before the first endpoint, generate Shared Layer → Presentation → New Service `rest-endpoint-generator` with `readonly generate = createEndpoint({ context, errorStatuses })(adapter)`. Map domain errors to statuses in `errorStatuses`, importing them from the contexts' `domain/errors` (the only thing `shared/` may import from a context). Generate the exposed handler before the endpoint too: with wire, the endpoint generator takes both picks and fills the types and the wire (`[wireRestEndpointGeneratorPresentationService, wireGetRecentOrdersUseCase]`).
80
+ 1. Generator: initialization creates `RestEndpointGeneratorPresentationService` in `<rootFolder>/shared/presentation/services/`; every endpoint uses it. Set the module-level `const adapter` above the class (`undefined` until set) to the HTTP framework's adapter; the class reads it through closure. If initialization connected the Next adapter, the file already imports `nextAdapter` from `@domain-first/handlers-next` and passes it instead; just make sure that package is installed. The default `400` checks live in the private `defaultClientRequestErrors` getter; extend a status with `checks: [...this.defaultClientRequestErrors, MyError.is]`. Map domain errors to statuses in the generator's `errorStatuses`, importing them from the contexts' `domain/errors` (the only thing `shared/` may import from a context). A new kind of endpoint (auth, other context) is a new getter returning `createEndpoint({ context, errorStatuses })(adapter) as EndpointGenerator` (`nextAdapter` with the Next adapter), next to `withoutGuards`. Generate the exposed handler before the endpoint: with wire, the `Handler:` pick fills its type and the wire (`[wireRestEndpointGeneratorPresentationService, wireGetRecentOrdersUseCase]`).
81
81
  2. If `handler: never` is left (no handler existed at generation), re-run the endpoint generator as an approved overwrite to pick it (rule 3); don't replace it by hand.
82
- 3. Complete `get handle()`: call the picked service's generating method (`this.endpointGenerator.generate(...)` instead of `this.endpointGenerator(...)`), then `.input(...)`, `.mapInput(...)`, optional `.output(...)`, `.mapOutput(...)`.
82
+ 3. Complete `get handle()`: the generated `this.endpointGenerator(...)` doesn't compile on purpose. Pick the generating getter that fits the endpoint (`this.endpointGenerator.withoutGuards(...)`, or one with the needed guards), then `.input(...)`, `.mapInput(...)`, optional `.output(...)`, `.mapOutput(...)`.
83
83
  4. Register `restHandlers` from `<rootFolder>/presentation/rest/index.ts` in the server bootstrap (rule 2, exception 5).
84
84
 
85
85
  ## React
@@ -79,7 +79,7 @@ Moving or renaming a page or widget is a df-ps run too (`Move or rename page` /
79
79
 
80
80
  ### 3. New dependencies only through df-ps
81
81
 
82
- With `@domain-first/wire`, every new dependency of a wired class (a constructor parameter plus its wire) is added by `df-ps`: the generator's `Dependencies:` step for a new module, `Wire dependency` for an existing one, and the `Endpoint generator:` / `Handler:` picks for an endpoint. Don't add constructor parameters or wire entries by hand, and don't reorder or remove the ones `df-ps` added.
82
+ With `@domain-first/wire`, every new dependency of a wired class (a constructor parameter plus its wire) is added by `df-ps`: the generator's `Dependencies:` step for a new module, `Wire dependency` for an existing one, and the `Handler:` pick for an endpoint (its generator is added automatically). Don't add constructor parameters or wire entries by hand, and don't reorder or remove the ones `df-ps` added.
83
83
 
84
84
  - List each module's dependencies in the plan as run options (`deps: OrderRepository`), with a `Wire dependency` run for existing modules.
85
85
  - A dependency the CLI doesn't offer is forbidden by the wiring rules (layer, kind, or another context): change the design (a port, an execution query or command, an infrastructure service) instead of adding it by hand.
@@ -102,15 +102,15 @@ Edits the wire and the implementation classes in place; this never triggers `Ove
102
102
 
103
103
  ## Presentation → New Handlers-REST Endpoint (context only, needs handlers-rest)
104
104
 
105
- Prompts: controller (select: existing | `New controller` → name) → method (`get` `post` `patch` `delete` `put`) → relative path (may be empty: `default`) → {wire} `Endpoint generator:` (select: presentation services of `<C>` and the Shared Layer, `(shared)` suffix; those with `endpoint` in the name come first under `Suggested`; skipped if there are none) → {wire} `Handler:` (select: queries, commands, and use cases of `<C>`, grouped; skipped if there are none).
105
+ Prompts: controller (select: existing | `New controller` → name) → method (`get` `post` `patch` `delete` `put`) → relative path (may be empty: `default`) → {wire} `Handler:` (select: queries, commands, and use cases of `<C>`, grouped; skipped if there are none).
106
106
 
107
- `… pick:Presentation "pick:New Handlers" "pick:New controller" text:orders pick:get text:recent pick:RestEndpointGenerator pick:GetRecentOrders`
108
- `… pick:Presentation "pick:New Handlers" pick:orders pick:post default pick:RestEndpointGenerator pick:PlaceOrder`
107
+ `… pick:Presentation "pick:New Handlers" "pick:New controller" text:orders pick:get text:recent pick:GetRecentOrders`
108
+ `… pick:Presentation "pick:New Handlers" pick:orders pick:post default pick:PlaceOrder`
109
109
 
110
110
  For `sales`, `orders`, `get`, `recent`:
111
111
 
112
- - `<C>/presentation/rest/orders/recent/GET.ts`: `class OrdersRecentGetEndpoint(endpointGenerator, handler)`, route `['sales','orders','recent']`. With the picks: `endpointGenerator: RestEndpointGeneratorPresentationService` and `handler: GetRecentOrdersUseCase`, both `import type`. Without a pick: `EndpointGenerator` from handlers-rest and `handler: never`. `get handle()` calls `this.endpointGenerator(...)` either way: with a picked service, choose its generating method there (`this.endpointGenerator.generate(...)`).
113
- - {wire} `<C>/wiring/presentation/rest/orders/wire-orders-recent-get-endpoint.ts` (`[wireRestEndpointGeneratorPresentationService, wireGetRecentOrdersUseCase]`; `[]` without a generator) + a line in that folder's `index.ts`
112
+ - `<C>/presentation/rest/orders/recent/GET.ts`: `class OrdersRecentGetEndpoint(endpointGenerator, handler)`, route `['sales','orders','recent']`. `endpointGenerator: RestEndpointGeneratorPresentationService` (the Shared Layer generator from initialization) and `handler: GetRecentOrdersUseCase` (`never` without a pick), both `import type`. `get handle()` calls `this.endpointGenerator(...)`, which doesn't compile until a generating getter is picked (`this.endpointGenerator.withoutGuards(...)`); that's expected, not a generator bug. Projects without the generator file get `EndpointGenerator` from handlers-rest.
113
+ - {wire} `<C>/wiring/presentation/rest/orders/wire-orders-recent-get-endpoint.ts` (`[wireRestEndpointGeneratorPresentationService, wireGetRecentOrdersUseCase]`; `[]` without the generator file) + a line in that folder's `index.ts`
114
114
  - {wire}, new controller only: `<C>/wiring/presentation/rest/index.ts`, `<rootFolder>/presentation/rest/wires.ts` (lines appended), `<rootFolder>/presentation/rest/index.ts` (`restHandlers`, created once)
115
115
 
116
116
  The same controller, path, and method replace the existing endpoint (after `Overwrite them?`).