@domain-first/project-structure 8.4.0 → 8.5.1

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 CHANGED
@@ -88,7 +88,8 @@ All settings and saved implementation types live in `domain-first.project-struct
88
88
  "layers": true,
89
89
  "dependencies": true,
90
90
  "react": true,
91
- "clock": true
91
+ "clock": true,
92
+ "config": true
92
93
  }
93
94
  }
94
95
  },
@@ -238,6 +239,8 @@ With `@domain-first/handlers-rest`, choose **Presentation → New Handlers-REST
238
239
  src/bounded-contexts/sales/presentation/rest/orders/recent/GET.ts // GET /sales/orders/recent
239
240
  ```
240
241
 
242
+ For the context itself, pick **No controller (context root)**: context `social-networks`, an empty path and `get` give `GET /social-networks` in `src/bounded-contexts/social-networks/presentation/rest/GET.ts` (`SocialNetworksGetEndpoint`); path `:id` gives `GET /social-networks/:id`.
243
+
241
244
  Every endpoint uses the one endpoint generator of the project, `RestEndpointGeneratorPresentationService` in `src/shared-kernel/presentation/services/`. Initialization scaffolds it as a regular Shared Kernel presentation service (class, spec and wire):
242
245
 
243
246
  ```ts
@@ -283,13 +286,13 @@ The endpoint generator and the in-memory DB are what `df-init` scaffolds; as int
283
286
  npx df-lint
284
287
  ```
285
288
 
286
- It reports what breaks the Domain-First rules: forbidden imports between bounded contexts, imports against the layers, modules using kinds the dependency rules don't allow (in imports and in wiring), React modules importing what they shouldn't, and reading the time without the clock port. It exits with 1 when something is found, so you can run it in CI.
289
+ It reports what breaks the Domain-First rules: forbidden imports between bounded contexts, imports against the layers, modules using kinds the dependency rules don't allow (in imports and in wiring), React modules importing what they shouldn't, and reading the time or environment variables without the clock and config ports. It exits with 1 when something is found, so you can run it in CI.
287
290
 
288
291
  `df-init` scaffolds all standard rules into `backend.rules` during backend setup. Teams can edit these entries directly: what each kind of module may depend on (`backend.rules.dependencies`) and which checks run (`backend.rules.lint`). `df-scaffold` offers dependencies by the same rules. For older or manually shortened configs without `backend.rules`, the defaults apply and every check runs; kinds and checks you don't mention keep their defaults.
289
292
 
290
293
  - Kinds in `backend.rules.dependencies` (as keys and in lists): `repositories`, `domain-services`, `application-ports`, `application-services`, `use-cases`, `commands`, `queries`, `infrastructure-services`, `presentation-services`.
291
294
  - A kind's value: a list that replaces its defaults, or `{ "add": [...], "remove": [...] }`.
292
- - Checks in `backend.rules.lint`: `context-isolation`, `shared-kernel`, `layers`, `dependencies`, `react`, `clock`.
295
+ - Checks in `backend.rules.lint`: `context-isolation`, `shared-kernel`, `layers`, `dependencies`, `react`, `clock`, `config`.
293
296
 
294
297
  Defaults and details: [Dependency rules](API.md#dependency-rules), [`df-lint`](API.md#df-lint).
295
298
 
package/dist/287.js CHANGED
@@ -593,10 +593,11 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
593
593
  path: readonly string[];
594
594
  }): OpenApiData | undefined => {
595
595
  try {
596
- const [currentBoundedContext, controller, ...relativePath] =
597
- routeMetadata.path;
596
+ // The controller, if any, is the first folder of the path:
597
+ // context-root endpoints live right in presentation/rest.
598
+ const [currentBoundedContext, ...relativePath] = routeMetadata.path;
598
599
 
599
- if (!currentBoundedContext || !controller) {
600
+ if (!currentBoundedContext) {
600
601
  return undefined;
601
602
  }
602
603
 
@@ -606,7 +607,6 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
606
607
  currentBoundedContext,
607
608
  'presentation',
608
609
  'rest',
609
- controller,
610
610
  ...relativePath.map(pathParameterAsName),
611
611
  \`\${routeMetadata.method.toUpperCase()}.ts\`
612
612
  )
@@ -4268,46 +4268,45 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
4268
4268
  const namespaceFile = currentErrorFolder.file(`${namespace}.ts`);
4269
4269
  namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
4270
4270
  };
4271
+ const newController = 'New controller';
4272
+ const withoutController = 'No controller (context root)';
4273
+ const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
4274
+ const isPathParameterName = (name)=>name.startsWith(':') || /^_.+_$/.test(name);
4275
+ const sharedRestFolder = (boundedContextFolder)=>boundedContextFolder.subitem([
4276
+ '..',
4277
+ '..',
4278
+ 'presentation',
4279
+ 'rest'
4280
+ ]);
4271
4281
  const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
4272
4282
  const restPresentationFolder = boundedContextFolder.subitem([
4273
4283
  'presentation',
4274
4284
  'rest'
4275
4285
  ]);
4276
- const controllers = restPresentationFolder.content.subfolderNames;
4277
- let controller = await interaction_select({
4286
+ const controllers = restPresentationFolder.content.subfolderNames.filter((x)=>!isPathParameterName(x));
4287
+ let controllerChoice = await interaction_select({
4278
4288
  key: 'controllerSelection',
4279
4289
  message: 'Controller: ',
4280
4290
  choices: [
4281
4291
  ...controllers,
4282
- 'New controller'
4292
+ newController,
4293
+ withoutController
4283
4294
  ]
4284
4295
  });
4285
- if ('New controller' === controller) {
4286
- controller = await interaction_input({
4287
- key: 'controllerName',
4288
- message: 'Name: '
4289
- });
4290
- if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
4291
- boundedContextFolder.subitem([
4292
- 'wiring',
4293
- 'presentation',
4294
- 'rest'
4295
- ]).file('index.ts').addLine(`export * from './${controller}'`);
4296
- const sharedRestFolder = boundedContextFolder.subitem([
4297
- '..',
4298
- '..',
4299
- 'presentation',
4300
- 'rest'
4301
- ]);
4302
- sharedRestFolder.file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
4303
- if (!sharedRestFolder.file('index.ts').exists) sharedRestFolder.createFile('index.ts', `
4304
- import * as wires from './wires'
4305
-
4306
- const restWires = Object.values(wires)
4307
-
4308
- export const restHandlers = restWires.map(x => x().handle)
4309
- `.trim());
4310
- }
4296
+ if (controllerChoice === newController) controllerChoice = await interaction_input({
4297
+ key: 'controllerName',
4298
+ message: 'Name: ',
4299
+ validate: (value)=>value.trim() ? isPathParameterName(value) || value.includes('/') ? 'A controller is one static path segment' : true : `Name is required; pick "${withoutController}" for an endpoint at the context root`
4300
+ });
4301
+ const controller = controllerChoice === withoutController ? void 0 : controllerChoice;
4302
+ const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
4303
+ if (controller && !controllers.includes(controller) && withWiring) {
4304
+ boundedContextFolder.subitem([
4305
+ 'wiring',
4306
+ 'presentation',
4307
+ 'rest'
4308
+ ]).file('index.ts').addLine(`export * from './${controller}'`);
4309
+ sharedRestFolder(boundedContextFolder).file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
4311
4310
  }
4312
4311
  const method = await interaction_select({
4313
4312
  key: 'method',
@@ -4322,21 +4321,32 @@ export const restHandlers = restWires.map(x => x().handle)
4322
4321
  });
4323
4322
  const routeSegments = (await interaction_input({
4324
4323
  key: 'path',
4325
- message: 'Relative path (split by "/"):'
4324
+ message: 'Relative path (split by "/"):',
4325
+ validate: (value)=>{
4326
+ const [first] = value.split('/').filter((x)=>!!x);
4327
+ return controller || !first || first.startsWith(':') ? true : `Without a controller, the path is empty or starts with a path parameter; "${first}" is a controller`;
4328
+ }
4326
4329
  })).split('/').filter((x)=>!!x);
4327
- const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
4328
- const controllerFolder = restPresentationFolder.subitem([
4329
- controller
4330
- ]);
4331
- const endpointFolder = controllerFolder.subitem(routeSegments.map(pathParameterAsName));
4332
- const nameBase = `${controller}-${routeSegments.length ? `${routeSegments.map(pathParameterAsName).join('-')}-` : ''}${method}-endpoint`;
4330
+ const folderSegments = [
4331
+ ...controller ? [
4332
+ controller
4333
+ ] : [],
4334
+ ...routeSegments
4335
+ ];
4336
+ const endpointFolder = restPresentationFolder.subitem(folderSegments.map(pathParameterAsName));
4337
+ const nameSegments = [
4338
+ controller ?? boundedContextFolder.name,
4339
+ ...routeSegments
4340
+ ];
4341
+ const nameBase = `${[
4342
+ ...nameSegments.map(pathParameterAsName),
4343
+ method
4344
+ ].join('-')}-endpoint`;
4333
4345
  const endpointClassName = [
4334
- controller,
4335
- ...routeSegments,
4346
+ ...nameSegments,
4336
4347
  method,
4337
4348
  'endpoint'
4338
4349
  ].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
4339
- const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
4340
4350
  const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
4341
4351
  '..',
4342
4352
  '..',
@@ -4356,8 +4366,11 @@ export class ${endpointClassName} {
4356
4366
 
4357
4367
  get handle() {
4358
4368
  return this.endpointGenerator(this.handler.handle, {
4359
- route: { method: '${method}', path: ['${boundedContextFolder.name}', '${controller}'${routeSegments.length ? `, ${routeSegments.map((x)=>`'${x}'`).join(', ')}` : ''}] },
4360
- tags: ['${boundedContextFolder.name}: ${controller}'],
4369
+ route: { method: '${method}', path: [${[
4370
+ boundedContextFolder.name,
4371
+ ...folderSegments
4372
+ ].map((x)=>`'${x}'`).join(', ')}] },
4373
+ tags: ['${boundedContextFolder.name}${controller ? `: ${controller}` : ''}'],
4361
4374
  })
4362
4375
  }
4363
4376
  }
@@ -4367,7 +4380,9 @@ export class ${endpointClassName} {
4367
4380
  'wiring',
4368
4381
  'presentation',
4369
4382
  'rest',
4370
- controller
4383
+ ...controller ? [
4384
+ controller
4385
+ ] : []
4371
4386
  ]);
4372
4387
  const wireNameBase = `wire-${nameBase}`;
4373
4388
  const wireNaming = new UnknownFormatNaming(wireNameBase);
@@ -4387,6 +4402,15 @@ export const wire${endpointClassName} = wireClass(
4387
4402
  )
4388
4403
  `.trim());
4389
4404
  wiringFolder.file('index.ts').addLineIfMissing(`export * from './${wireNaming.fileName}'`);
4405
+ if (!controller) sharedRestFolder(boundedContextFolder).file('wires.ts').addLineIfMissing(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${wireNaming.fileName}'`);
4406
+ const restHandlersFile = sharedRestFolder(boundedContextFolder).file('index.ts');
4407
+ if (!restHandlersFile.exists) sharedRestFolder(boundedContextFolder).createFile('index.ts', `
4408
+ import * as wires from './wires'
4409
+
4410
+ const restWires = Object.values(wires)
4411
+
4412
+ export const restHandlers = restWires.map(x => x().handle)
4413
+ `.trim());
4390
4414
  }
4391
4415
  };
4392
4416
  const scaffold_new_implementation_kindTitles = {
package/dist/38.js CHANGED
@@ -225,7 +225,19 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
225
225
  }
226
226
  return violations;
227
227
  };
228
- const clockViolations = (projectRoot, rootFolder)=>{
228
+ const directReadChecks = [
229
+ {
230
+ check: 'clock',
231
+ pattern: /\bnew\s+Date\s*\(\s*\)|\bDate\.now\s*\(/g,
232
+ rule: 'domain or application reads the current time directly (use the clock port):'
233
+ },
234
+ {
235
+ check: 'config',
236
+ pattern: /\bprocess\s*\??\.\s*env\b|\bprocess\s*\[\s*(['"`])env\1\s*\]|\bimport\.meta\.env\b/g,
237
+ rule: 'domain or application reads environment variables directly (use the config port):'
238
+ }
239
+ ];
240
+ const directReadViolations = (projectRoot, rootFolder)=>{
229
241
  const root = node_path.resolve(projectRoot, rootFolder);
230
242
  const folders = [
231
243
  node_path.join(root, 'shared-kernel'),
@@ -236,21 +248,21 @@ const clockViolations = (projectRoot, rootFolder)=>{
236
248
  ]);
237
249
  return folders.flatMap(sourceFiles).filter((file)=>!isSpec(file)).flatMap((file)=>{
238
250
  const source = node_fs.readFileSync(file, 'utf8');
239
- return [
240
- ...source.matchAll(/\bnew\s+Date\s*\(\s*\)|\bDate\.now\s*\(/g)
241
- ].map((match)=>({
242
- check: 'clock',
243
- rule: 'domain or application reads the current time directly (use the clock port):',
244
- file,
245
- line: lineAt(source, match.index),
246
- text: match[0]
247
- }));
251
+ return directReadChecks.flatMap(({ check, pattern, rule })=>[
252
+ ...source.matchAll(pattern)
253
+ ].map((match)=>({
254
+ check,
255
+ rule,
256
+ file,
257
+ line: lineAt(source, match.index),
258
+ text: match[0]
259
+ })));
248
260
  });
249
261
  };
250
262
  const lintProject = (projectRoot, rootFolder, { rules = defaultDependencyRules, checks = {} } = {})=>[
251
263
  ...importViolations(projectRoot, rootFolder, rules),
252
264
  ...wiringViolations(projectRoot, rootFolder, rules),
253
- ...clockViolations(projectRoot, rootFolder)
265
+ ...directReadViolations(projectRoot, rootFolder)
254
266
  ].filter((x)=>false !== checks[x.check]);
255
267
  const formatViolations = (violations, projectRoot)=>{
256
268
  const groups = new Map();
package/dist/561.js CHANGED
@@ -105,7 +105,7 @@ const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
105
105
  agent_requests_operation('endpoint', {
106
106
  ...common,
107
107
  ...agent_requests_owner,
108
- controller: agent_requests_name,
108
+ controller: agent_requests_name.optional().describe('Omit for an endpoint at the context root (`/<context>`); then path is empty or starts with a :param.'),
109
109
  method: zod["enum"]([
110
110
  'get',
111
111
  'post',
@@ -369,12 +369,15 @@ const answersFor = (command, request, owner)=>{
369
369
  if ('error' === request.operation || 'error-namespace' === request.operation) defaults.errorAction = 'error-namespace' === request.operation ? 'New namespace' : request.namespace ? `New error in namespace ${request.namespace}` : 'New error without namespace';
370
370
  if ('endpoint' === request.operation) {
371
371
  delete answers.controller;
372
- const existing = owner.subitem([
373
- 'presentation',
374
- 'rest'
375
- ]).content.subfolderNames.includes(request.controller);
376
- answers.controllerSelection = existing ? request.controller : 'New controller';
377
- if (!existing) answers.controllerName = request.controller;
372
+ if (void 0 === request.controller) answers.controllerSelection = 'No controller (context root)';
373
+ else {
374
+ const existing = owner.subitem([
375
+ 'presentation',
376
+ 'rest'
377
+ ]).content.subfolderNames.includes(request.controller);
378
+ answers.controllerSelection = existing ? request.controller : 'New controller';
379
+ if (!existing) answers.controllerName = request.controller;
380
+ }
378
381
  }
379
382
  if ('move' === request.operation) defaults.targetContext = request.context;
380
383
  }
package/dist/870.js CHANGED
@@ -316,7 +316,8 @@ const lintChecks = [
316
316
  'layers',
317
317
  'dependencies',
318
318
  'react',
319
- 'clock'
319
+ 'clock',
320
+ 'config'
320
321
  ];
321
322
  const configFileName = 'domain-first.project-structure.config.json';
322
323
  const projectConfigSchema = zod.object({
@@ -163,7 +163,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
163
163
  dryRun: z.ZodOptional<z.ZodBoolean>;
164
164
  }, z.core.$strict>, z.ZodObject<{
165
165
  operation: z.ZodLiteral<"endpoint">;
166
- controller: z.ZodString;
166
+ controller: z.ZodOptional<z.ZodString>;
167
167
  method: z.ZodEnum<{
168
168
  get: "get";
169
169
  post: "post";
@@ -331,7 +331,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
331
331
  add?: ("queries" | "commands" | "use-cases" | "application-ports" | "repositories" | "domain-services" | "application-services" | "infrastructure-services" | "presentation-services")[] | undefined;
332
332
  remove?: ("queries" | "commands" | "use-cases" | "application-ports" | "repositories" | "domain-services" | "application-services" | "infrastructure-services" | "presentation-services")[] | undefined;
333
333
  }>> | undefined;
334
- lint?: Partial<Record<"context-isolation" | "shared-kernel" | "layers" | "dependencies" | "react" | "clock", boolean>> | undefined;
334
+ lint?: Partial<Record<"context-isolation" | "shared-kernel" | "layers" | "dependencies" | "react" | "clock" | "config", boolean>> | undefined;
335
335
  } | undefined;
336
336
  } | undefined;
337
337
  frontend?: {
@@ -141,7 +141,7 @@ export declare const scaffoldRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject
141
141
  dryRun: z.ZodOptional<z.ZodBoolean>;
142
142
  }, z.core.$strict>, z.ZodObject<{
143
143
  operation: z.ZodLiteral<"endpoint">;
144
- controller: z.ZodString;
144
+ controller: z.ZodOptional<z.ZodString>;
145
145
  method: z.ZodEnum<{
146
146
  get: "get";
147
147
  post: "post";
@@ -426,7 +426,7 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
426
426
  dryRun: z.ZodOptional<z.ZodBoolean>;
427
427
  }, z.core.$strict>, z.ZodObject<{
428
428
  operation: z.ZodLiteral<"endpoint">;
429
- controller: z.ZodString;
429
+ controller: z.ZodOptional<z.ZodString>;
430
430
  method: z.ZodEnum<{
431
431
  get: "get";
432
432
  post: "post";
@@ -2,7 +2,7 @@ import z from 'zod';
2
2
  /**
3
3
  * `df-lint` checks that `backend.rules.lint` can turn off.
4
4
  */
5
- export declare const lintChecks: readonly ["context-isolation", "shared-kernel", "layers", "dependencies", "react", "clock"];
5
+ export declare const lintChecks: readonly ["context-isolation", "shared-kernel", "layers", "dependencies", "react", "clock", "config"];
6
6
  export type LintCheck = (typeof lintChecks)[number];
7
7
  export declare const configFileName = "domain-first.project-structure.config.json";
8
8
  export declare const projectConfigSchema: z.ZodObject<{
@@ -61,6 +61,7 @@ export declare const rulesSchema: z.ZodObject<{
61
61
  dependencies: "dependencies";
62
62
  react: "react";
63
63
  clock: "clock";
64
+ config: "config";
64
65
  }> & z.core.$partial, z.ZodBoolean>>;
65
66
  }, z.core.$strip>;
66
67
  export declare const branchNameSchema: z.ZodString;
@@ -148,6 +149,7 @@ export declare const backendConfigSchema: z.ZodObject<{
148
149
  dependencies: "dependencies";
149
150
  react: "react";
150
151
  clock: "clock";
152
+ config: "config";
151
153
  }> & z.core.$partial, z.ZodBoolean>>;
152
154
  }, z.core.$strip>>;
153
155
  }, z.core.$loose>;
@@ -246,6 +248,7 @@ export declare const configSchema: z.ZodObject<{
246
248
  dependencies: "dependencies";
247
249
  react: "react";
248
250
  clock: "clock";
251
+ config: "config";
249
252
  }> & z.core.$partial, z.ZodBoolean>>;
250
253
  }, z.core.$strip>>;
251
254
  }, z.core.$loose>>;
package/dist/graph.cjs CHANGED
@@ -215,7 +215,8 @@ const lintChecks = [
215
215
  'layers',
216
216
  'dependencies',
217
217
  'react',
218
- 'clock'
218
+ 'clock',
219
+ 'config'
219
220
  ];
220
221
  const configFileName = 'domain-first.project-structure.config.json';
221
222
  const projectConfigSchema = external_zod_default().object({
package/dist/index.cjs CHANGED
@@ -370,7 +370,8 @@ const lintChecks = [
370
370
  'layers',
371
371
  'dependencies',
372
372
  'react',
373
- 'clock'
373
+ 'clock',
374
+ 'config'
374
375
  ];
375
376
  const config_file_configFileName = 'domain-first.project-structure.config.json';
376
377
  const projectConfigSchema = external_zod_default().object({
@@ -1530,10 +1531,11 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
1530
1531
  path: readonly string[];
1531
1532
  }): OpenApiData | undefined => {
1532
1533
  try {
1533
- const [currentBoundedContext, controller, ...relativePath] =
1534
- routeMetadata.path;
1534
+ // The controller, if any, is the first folder of the path:
1535
+ // context-root endpoints live right in presentation/rest.
1536
+ const [currentBoundedContext, ...relativePath] = routeMetadata.path;
1535
1537
 
1536
- if (!currentBoundedContext || !controller) {
1538
+ if (!currentBoundedContext) {
1537
1539
  return undefined;
1538
1540
  }
1539
1541
 
@@ -1543,7 +1545,6 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
1543
1545
  currentBoundedContext,
1544
1546
  'presentation',
1545
1547
  'rest',
1546
- controller,
1547
1548
  ...relativePath.map(pathParameterAsName),
1548
1549
  \`\${routeMetadata.method.toUpperCase()}.ts\`
1549
1550
  )
@@ -3199,7 +3200,7 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
3199
3200
  agent_requests_operation('endpoint', {
3200
3201
  ...common,
3201
3202
  ...agent_requests_owner,
3202
- controller: agent_requests_name,
3203
+ controller: agent_requests_name.optional().describe('Omit for an endpoint at the context root (`/<context>`); then path is empty or starts with a :param.'),
3203
3204
  method: external_zod_default()["enum"]([
3204
3205
  'get',
3205
3206
  'post',
@@ -5129,46 +5130,45 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
5129
5130
  const namespaceFile = currentErrorFolder.file(`${namespace}.ts`);
5130
5131
  namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
5131
5132
  };
5133
+ const newController = 'New controller';
5134
+ const withoutController = 'No controller (context root)';
5135
+ const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
5136
+ const isPathParameterName = (name)=>name.startsWith(':') || /^_.+_$/.test(name);
5137
+ const sharedRestFolder = (boundedContextFolder)=>boundedContextFolder.subitem([
5138
+ '..',
5139
+ '..',
5140
+ 'presentation',
5141
+ 'rest'
5142
+ ]);
5132
5143
  const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
5133
5144
  const restPresentationFolder = boundedContextFolder.subitem([
5134
5145
  'presentation',
5135
5146
  'rest'
5136
5147
  ]);
5137
- const controllers = restPresentationFolder.content.subfolderNames;
5138
- let controller = await interaction_select({
5148
+ const controllers = restPresentationFolder.content.subfolderNames.filter((x)=>!isPathParameterName(x));
5149
+ let controllerChoice = await interaction_select({
5139
5150
  key: 'controllerSelection',
5140
5151
  message: 'Controller: ',
5141
5152
  choices: [
5142
5153
  ...controllers,
5143
- 'New controller'
5154
+ newController,
5155
+ withoutController
5144
5156
  ]
5145
5157
  });
5146
- if ('New controller' === controller) {
5147
- controller = await interaction_input({
5148
- key: 'controllerName',
5149
- message: 'Name: '
5150
- });
5151
- if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
5152
- boundedContextFolder.subitem([
5153
- 'wiring',
5154
- 'presentation',
5155
- 'rest'
5156
- ]).file('index.ts').addLine(`export * from './${controller}'`);
5157
- const sharedRestFolder = boundedContextFolder.subitem([
5158
- '..',
5159
- '..',
5160
- 'presentation',
5161
- 'rest'
5162
- ]);
5163
- sharedRestFolder.file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
5164
- if (!sharedRestFolder.file('index.ts').exists) sharedRestFolder.createFile('index.ts', `
5165
- import * as wires from './wires'
5166
-
5167
- const restWires = Object.values(wires)
5168
-
5169
- export const restHandlers = restWires.map(x => x().handle)
5170
- `.trim());
5171
- }
5158
+ if (controllerChoice === newController) controllerChoice = await interaction_input({
5159
+ key: 'controllerName',
5160
+ message: 'Name: ',
5161
+ validate: (value)=>value.trim() ? isPathParameterName(value) || value.includes('/') ? 'A controller is one static path segment' : true : `Name is required; pick "${withoutController}" for an endpoint at the context root`
5162
+ });
5163
+ const controller = controllerChoice === withoutController ? void 0 : controllerChoice;
5164
+ const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
5165
+ if (controller && !controllers.includes(controller) && withWiring) {
5166
+ boundedContextFolder.subitem([
5167
+ 'wiring',
5168
+ 'presentation',
5169
+ 'rest'
5170
+ ]).file('index.ts').addLine(`export * from './${controller}'`);
5171
+ sharedRestFolder(boundedContextFolder).file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
5172
5172
  }
5173
5173
  const method = await interaction_select({
5174
5174
  key: 'method',
@@ -5183,21 +5183,32 @@ export const restHandlers = restWires.map(x => x().handle)
5183
5183
  });
5184
5184
  const routeSegments = (await interaction_input({
5185
5185
  key: 'path',
5186
- message: 'Relative path (split by "/"):'
5186
+ message: 'Relative path (split by "/"):',
5187
+ validate: (value)=>{
5188
+ const [first] = value.split('/').filter((x)=>!!x);
5189
+ return controller || !first || first.startsWith(':') ? true : `Without a controller, the path is empty or starts with a path parameter; "${first}" is a controller`;
5190
+ }
5187
5191
  })).split('/').filter((x)=>!!x);
5188
- const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
5189
- const controllerFolder = restPresentationFolder.subitem([
5190
- controller
5191
- ]);
5192
- const endpointFolder = controllerFolder.subitem(routeSegments.map(pathParameterAsName));
5193
- const nameBase = `${controller}-${routeSegments.length ? `${routeSegments.map(pathParameterAsName).join('-')}-` : ''}${method}-endpoint`;
5192
+ const folderSegments = [
5193
+ ...controller ? [
5194
+ controller
5195
+ ] : [],
5196
+ ...routeSegments
5197
+ ];
5198
+ const endpointFolder = restPresentationFolder.subitem(folderSegments.map(pathParameterAsName));
5199
+ const nameSegments = [
5200
+ controller ?? boundedContextFolder.name,
5201
+ ...routeSegments
5202
+ ];
5203
+ const nameBase = `${[
5204
+ ...nameSegments.map(pathParameterAsName),
5205
+ method
5206
+ ].join('-')}-endpoint`;
5194
5207
  const endpointClassName = [
5195
- controller,
5196
- ...routeSegments,
5208
+ ...nameSegments,
5197
5209
  method,
5198
5210
  'endpoint'
5199
5211
  ].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
5200
- const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
5201
5212
  const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
5202
5213
  '..',
5203
5214
  '..',
@@ -5217,8 +5228,11 @@ export class ${endpointClassName} {
5217
5228
 
5218
5229
  get handle() {
5219
5230
  return this.endpointGenerator(this.handler.handle, {
5220
- route: { method: '${method}', path: ['${boundedContextFolder.name}', '${controller}'${routeSegments.length ? `, ${routeSegments.map((x)=>`'${x}'`).join(', ')}` : ''}] },
5221
- tags: ['${boundedContextFolder.name}: ${controller}'],
5231
+ route: { method: '${method}', path: [${[
5232
+ boundedContextFolder.name,
5233
+ ...folderSegments
5234
+ ].map((x)=>`'${x}'`).join(', ')}] },
5235
+ tags: ['${boundedContextFolder.name}${controller ? `: ${controller}` : ''}'],
5222
5236
  })
5223
5237
  }
5224
5238
  }
@@ -5228,7 +5242,9 @@ export class ${endpointClassName} {
5228
5242
  'wiring',
5229
5243
  'presentation',
5230
5244
  'rest',
5231
- controller
5245
+ ...controller ? [
5246
+ controller
5247
+ ] : []
5232
5248
  ]);
5233
5249
  const wireNameBase = `wire-${nameBase}`;
5234
5250
  const wireNaming = new UnknownFormatNaming(wireNameBase);
@@ -5248,6 +5264,15 @@ export const wire${endpointClassName} = wireClass(
5248
5264
  )
5249
5265
  `.trim());
5250
5266
  wiringFolder.file('index.ts').addLineIfMissing(`export * from './${wireNaming.fileName}'`);
5267
+ if (!controller) sharedRestFolder(boundedContextFolder).file('wires.ts').addLineIfMissing(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${wireNaming.fileName}'`);
5268
+ const restHandlersFile = sharedRestFolder(boundedContextFolder).file('index.ts');
5269
+ if (!restHandlersFile.exists) sharedRestFolder(boundedContextFolder).createFile('index.ts', `
5270
+ import * as wires from './wires'
5271
+
5272
+ const restWires = Object.values(wires)
5273
+
5274
+ export const restHandlers = restWires.map(x => x().handle)
5275
+ `.trim());
5251
5276
  }
5252
5277
  };
5253
5278
  const scaffold_new_implementation_kindTitles = {
@@ -5887,12 +5912,15 @@ const answersFor = (command, request, owner)=>{
5887
5912
  if ('error' === request.operation || 'error-namespace' === request.operation) defaults.errorAction = 'error-namespace' === request.operation ? 'New namespace' : request.namespace ? `New error in namespace ${request.namespace}` : 'New error without namespace';
5888
5913
  if ('endpoint' === request.operation) {
5889
5914
  delete answers.controller;
5890
- const existing = owner.subitem([
5891
- 'presentation',
5892
- 'rest'
5893
- ]).content.subfolderNames.includes(request.controller);
5894
- answers.controllerSelection = existing ? request.controller : 'New controller';
5895
- if (!existing) answers.controllerName = request.controller;
5915
+ if (void 0 === request.controller) answers.controllerSelection = 'No controller (context root)';
5916
+ else {
5917
+ const existing = owner.subitem([
5918
+ 'presentation',
5919
+ 'rest'
5920
+ ]).content.subfolderNames.includes(request.controller);
5921
+ answers.controllerSelection = existing ? request.controller : 'New controller';
5922
+ if (!existing) answers.controllerName = request.controller;
5923
+ }
5896
5924
  }
5897
5925
  if ('move' === request.operation) defaults.targetContext = request.context;
5898
5926
  }
package/dist/init.cjs CHANGED
@@ -298,7 +298,8 @@ const lintChecks = [
298
298
  'layers',
299
299
  'dependencies',
300
300
  'react',
301
- 'clock'
301
+ 'clock',
302
+ 'config'
302
303
  ];
303
304
  const config_file_configFileName = 'domain-first.project-structure.config.json';
304
305
  const projectConfigSchema = external_zod_default().object({