@domain-first/project-structure 8.5.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 +2 -0
- package/dist/287.js +70 -46
- package/dist/561.js +10 -7
- package/dist/agent-cli.d.ts +1 -1
- package/dist/agent-requests.d.ts +2 -2
- package/dist/index.cjs +80 -53
- package/dist/integration.cjs +80 -53
- package/dist/react.cjs +80 -53
- package/package.json +1 -1
- package/skills/df-ps-scaffold/references/agent-mode.md +1 -1
- package/skills/df-ps-scaffold/references/agent-operations.md +1 -1
- package/skills/df-ps-scaffold/references/units/endpoint.md +3 -1
package/README.md
CHANGED
|
@@ -239,6 +239,8 @@ With `@domain-first/handlers-rest`, choose **Presentation → New Handlers-REST
|
|
|
239
239
|
src/bounded-contexts/sales/presentation/rest/orders/recent/GET.ts // GET /sales/orders/recent
|
|
240
240
|
```
|
|
241
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
|
+
|
|
242
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):
|
|
243
245
|
|
|
244
246
|
```ts
|
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
|
-
|
|
597
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
4292
|
+
newController,
|
|
4293
|
+
withoutController
|
|
4283
4294
|
]
|
|
4284
4295
|
});
|
|
4285
|
-
if (
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
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
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
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
|
-
|
|
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: [
|
|
4360
|
-
|
|
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/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
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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/agent-cli.d.ts
CHANGED
|
@@ -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";
|
package/dist/agent-requests.d.ts
CHANGED
|
@@ -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";
|
package/dist/index.cjs
CHANGED
|
@@ -1531,10 +1531,11 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
|
1531
1531
|
path: readonly string[];
|
|
1532
1532
|
}): OpenApiData | undefined => {
|
|
1533
1533
|
try {
|
|
1534
|
-
|
|
1535
|
-
|
|
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;
|
|
1536
1537
|
|
|
1537
|
-
if (!currentBoundedContext
|
|
1538
|
+
if (!currentBoundedContext) {
|
|
1538
1539
|
return undefined;
|
|
1539
1540
|
}
|
|
1540
1541
|
|
|
@@ -1544,7 +1545,6 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
|
1544
1545
|
currentBoundedContext,
|
|
1545
1546
|
'presentation',
|
|
1546
1547
|
'rest',
|
|
1547
|
-
controller,
|
|
1548
1548
|
...relativePath.map(pathParameterAsName),
|
|
1549
1549
|
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
1550
1550
|
)
|
|
@@ -3200,7 +3200,7 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3200
3200
|
agent_requests_operation('endpoint', {
|
|
3201
3201
|
...common,
|
|
3202
3202
|
...agent_requests_owner,
|
|
3203
|
-
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.'),
|
|
3204
3204
|
method: external_zod_default()["enum"]([
|
|
3205
3205
|
'get',
|
|
3206
3206
|
'post',
|
|
@@ -5130,46 +5130,45 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
5130
5130
|
const namespaceFile = currentErrorFolder.file(`${namespace}.ts`);
|
|
5131
5131
|
namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
|
|
5132
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
|
+
]);
|
|
5133
5143
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
5134
5144
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
5135
5145
|
'presentation',
|
|
5136
5146
|
'rest'
|
|
5137
5147
|
]);
|
|
5138
|
-
const controllers = restPresentationFolder.content.subfolderNames;
|
|
5139
|
-
let
|
|
5148
|
+
const controllers = restPresentationFolder.content.subfolderNames.filter((x)=>!isPathParameterName(x));
|
|
5149
|
+
let controllerChoice = await interaction_select({
|
|
5140
5150
|
key: 'controllerSelection',
|
|
5141
5151
|
message: 'Controller: ',
|
|
5142
5152
|
choices: [
|
|
5143
5153
|
...controllers,
|
|
5144
|
-
|
|
5154
|
+
newController,
|
|
5155
|
+
withoutController
|
|
5145
5156
|
]
|
|
5146
5157
|
});
|
|
5147
|
-
if (
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
'presentation',
|
|
5162
|
-
'rest'
|
|
5163
|
-
]);
|
|
5164
|
-
sharedRestFolder.file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
|
|
5165
|
-
if (!sharedRestFolder.file('index.ts').exists) sharedRestFolder.createFile('index.ts', `
|
|
5166
|
-
import * as wires from './wires'
|
|
5167
|
-
|
|
5168
|
-
const restWires = Object.values(wires)
|
|
5169
|
-
|
|
5170
|
-
export const restHandlers = restWires.map(x => x().handle)
|
|
5171
|
-
`.trim());
|
|
5172
|
-
}
|
|
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}'`);
|
|
5173
5172
|
}
|
|
5174
5173
|
const method = await interaction_select({
|
|
5175
5174
|
key: 'method',
|
|
@@ -5184,21 +5183,32 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
5184
5183
|
});
|
|
5185
5184
|
const routeSegments = (await interaction_input({
|
|
5186
5185
|
key: 'path',
|
|
5187
|
-
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
|
+
}
|
|
5188
5191
|
})).split('/').filter((x)=>!!x);
|
|
5189
|
-
const
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
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`;
|
|
5195
5207
|
const endpointClassName = [
|
|
5196
|
-
|
|
5197
|
-
...routeSegments,
|
|
5208
|
+
...nameSegments,
|
|
5198
5209
|
method,
|
|
5199
5210
|
'endpoint'
|
|
5200
5211
|
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
|
|
5201
|
-
const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
5202
5212
|
const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
5203
5213
|
'..',
|
|
5204
5214
|
'..',
|
|
@@ -5218,8 +5228,11 @@ export class ${endpointClassName} {
|
|
|
5218
5228
|
|
|
5219
5229
|
get handle() {
|
|
5220
5230
|
return this.endpointGenerator(this.handler.handle, {
|
|
5221
|
-
route: { method: '${method}', path: [
|
|
5222
|
-
|
|
5231
|
+
route: { method: '${method}', path: [${[
|
|
5232
|
+
boundedContextFolder.name,
|
|
5233
|
+
...folderSegments
|
|
5234
|
+
].map((x)=>`'${x}'`).join(', ')}] },
|
|
5235
|
+
tags: ['${boundedContextFolder.name}${controller ? `: ${controller}` : ''}'],
|
|
5223
5236
|
})
|
|
5224
5237
|
}
|
|
5225
5238
|
}
|
|
@@ -5229,7 +5242,9 @@ export class ${endpointClassName} {
|
|
|
5229
5242
|
'wiring',
|
|
5230
5243
|
'presentation',
|
|
5231
5244
|
'rest',
|
|
5232
|
-
controller
|
|
5245
|
+
...controller ? [
|
|
5246
|
+
controller
|
|
5247
|
+
] : []
|
|
5233
5248
|
]);
|
|
5234
5249
|
const wireNameBase = `wire-${nameBase}`;
|
|
5235
5250
|
const wireNaming = new UnknownFormatNaming(wireNameBase);
|
|
@@ -5249,6 +5264,15 @@ export const wire${endpointClassName} = wireClass(
|
|
|
5249
5264
|
)
|
|
5250
5265
|
`.trim());
|
|
5251
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());
|
|
5252
5276
|
}
|
|
5253
5277
|
};
|
|
5254
5278
|
const scaffold_new_implementation_kindTitles = {
|
|
@@ -5888,12 +5912,15 @@ const answersFor = (command, request, owner)=>{
|
|
|
5888
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';
|
|
5889
5913
|
if ('endpoint' === request.operation) {
|
|
5890
5914
|
delete answers.controller;
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
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
|
+
}
|
|
5897
5924
|
}
|
|
5898
5925
|
if ('move' === request.operation) defaults.targetContext = request.context;
|
|
5899
5926
|
}
|
package/dist/integration.cjs
CHANGED
|
@@ -1531,10 +1531,11 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
|
1531
1531
|
path: readonly string[];
|
|
1532
1532
|
}): OpenApiData | undefined => {
|
|
1533
1533
|
try {
|
|
1534
|
-
|
|
1535
|
-
|
|
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;
|
|
1536
1537
|
|
|
1537
|
-
if (!currentBoundedContext
|
|
1538
|
+
if (!currentBoundedContext) {
|
|
1538
1539
|
return undefined;
|
|
1539
1540
|
}
|
|
1540
1541
|
|
|
@@ -1544,7 +1545,6 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
|
1544
1545
|
currentBoundedContext,
|
|
1545
1546
|
'presentation',
|
|
1546
1547
|
'rest',
|
|
1547
|
-
controller,
|
|
1548
1548
|
...relativePath.map(pathParameterAsName),
|
|
1549
1549
|
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
1550
1550
|
)
|
|
@@ -3200,7 +3200,7 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3200
3200
|
agent_requests_operation('endpoint', {
|
|
3201
3201
|
...common,
|
|
3202
3202
|
...agent_requests_owner,
|
|
3203
|
-
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.'),
|
|
3204
3204
|
method: external_zod_default()["enum"]([
|
|
3205
3205
|
'get',
|
|
3206
3206
|
'post',
|
|
@@ -5130,46 +5130,45 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
5130
5130
|
const namespaceFile = currentErrorFolder.file(`${namespace}.ts`);
|
|
5131
5131
|
namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
|
|
5132
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
|
+
]);
|
|
5133
5143
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
5134
5144
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
5135
5145
|
'presentation',
|
|
5136
5146
|
'rest'
|
|
5137
5147
|
]);
|
|
5138
|
-
const controllers = restPresentationFolder.content.subfolderNames;
|
|
5139
|
-
let
|
|
5148
|
+
const controllers = restPresentationFolder.content.subfolderNames.filter((x)=>!isPathParameterName(x));
|
|
5149
|
+
let controllerChoice = await interaction_select({
|
|
5140
5150
|
key: 'controllerSelection',
|
|
5141
5151
|
message: 'Controller: ',
|
|
5142
5152
|
choices: [
|
|
5143
5153
|
...controllers,
|
|
5144
|
-
|
|
5154
|
+
newController,
|
|
5155
|
+
withoutController
|
|
5145
5156
|
]
|
|
5146
5157
|
});
|
|
5147
|
-
if (
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
'presentation',
|
|
5162
|
-
'rest'
|
|
5163
|
-
]);
|
|
5164
|
-
sharedRestFolder.file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
|
|
5165
|
-
if (!sharedRestFolder.file('index.ts').exists) sharedRestFolder.createFile('index.ts', `
|
|
5166
|
-
import * as wires from './wires'
|
|
5167
|
-
|
|
5168
|
-
const restWires = Object.values(wires)
|
|
5169
|
-
|
|
5170
|
-
export const restHandlers = restWires.map(x => x().handle)
|
|
5171
|
-
`.trim());
|
|
5172
|
-
}
|
|
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}'`);
|
|
5173
5172
|
}
|
|
5174
5173
|
const method = await interaction_select({
|
|
5175
5174
|
key: 'method',
|
|
@@ -5184,21 +5183,32 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
5184
5183
|
});
|
|
5185
5184
|
const routeSegments = (await interaction_input({
|
|
5186
5185
|
key: 'path',
|
|
5187
|
-
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
|
+
}
|
|
5188
5191
|
})).split('/').filter((x)=>!!x);
|
|
5189
|
-
const
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
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`;
|
|
5195
5207
|
const endpointClassName = [
|
|
5196
|
-
|
|
5197
|
-
...routeSegments,
|
|
5208
|
+
...nameSegments,
|
|
5198
5209
|
method,
|
|
5199
5210
|
'endpoint'
|
|
5200
5211
|
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
|
|
5201
|
-
const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
5202
5212
|
const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
5203
5213
|
'..',
|
|
5204
5214
|
'..',
|
|
@@ -5218,8 +5228,11 @@ export class ${endpointClassName} {
|
|
|
5218
5228
|
|
|
5219
5229
|
get handle() {
|
|
5220
5230
|
return this.endpointGenerator(this.handler.handle, {
|
|
5221
|
-
route: { method: '${method}', path: [
|
|
5222
|
-
|
|
5231
|
+
route: { method: '${method}', path: [${[
|
|
5232
|
+
boundedContextFolder.name,
|
|
5233
|
+
...folderSegments
|
|
5234
|
+
].map((x)=>`'${x}'`).join(', ')}] },
|
|
5235
|
+
tags: ['${boundedContextFolder.name}${controller ? `: ${controller}` : ''}'],
|
|
5223
5236
|
})
|
|
5224
5237
|
}
|
|
5225
5238
|
}
|
|
@@ -5229,7 +5242,9 @@ export class ${endpointClassName} {
|
|
|
5229
5242
|
'wiring',
|
|
5230
5243
|
'presentation',
|
|
5231
5244
|
'rest',
|
|
5232
|
-
controller
|
|
5245
|
+
...controller ? [
|
|
5246
|
+
controller
|
|
5247
|
+
] : []
|
|
5233
5248
|
]);
|
|
5234
5249
|
const wireNameBase = `wire-${nameBase}`;
|
|
5235
5250
|
const wireNaming = new UnknownFormatNaming(wireNameBase);
|
|
@@ -5249,6 +5264,15 @@ export const wire${endpointClassName} = wireClass(
|
|
|
5249
5264
|
)
|
|
5250
5265
|
`.trim());
|
|
5251
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());
|
|
5252
5276
|
}
|
|
5253
5277
|
};
|
|
5254
5278
|
const scaffold_new_implementation_kindTitles = {
|
|
@@ -5888,12 +5912,15 @@ const answersFor = (command, request, owner)=>{
|
|
|
5888
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';
|
|
5889
5913
|
if ('endpoint' === request.operation) {
|
|
5890
5914
|
delete answers.controller;
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
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
|
+
}
|
|
5897
5924
|
}
|
|
5898
5925
|
if ('move' === request.operation) defaults.targetContext = request.context;
|
|
5899
5926
|
}
|
package/dist/react.cjs
CHANGED
|
@@ -1531,10 +1531,11 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
|
1531
1531
|
path: readonly string[];
|
|
1532
1532
|
}): OpenApiData | undefined => {
|
|
1533
1533
|
try {
|
|
1534
|
-
|
|
1535
|
-
|
|
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;
|
|
1536
1537
|
|
|
1537
|
-
if (!currentBoundedContext
|
|
1538
|
+
if (!currentBoundedContext) {
|
|
1538
1539
|
return undefined;
|
|
1539
1540
|
}
|
|
1540
1541
|
|
|
@@ -1544,7 +1545,6 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
|
1544
1545
|
currentBoundedContext,
|
|
1545
1546
|
'presentation',
|
|
1546
1547
|
'rest',
|
|
1547
|
-
controller,
|
|
1548
1548
|
...relativePath.map(pathParameterAsName),
|
|
1549
1549
|
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
1550
1550
|
)
|
|
@@ -3200,7 +3200,7 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3200
3200
|
agent_requests_operation('endpoint', {
|
|
3201
3201
|
...common,
|
|
3202
3202
|
...agent_requests_owner,
|
|
3203
|
-
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.'),
|
|
3204
3204
|
method: external_zod_default()["enum"]([
|
|
3205
3205
|
'get',
|
|
3206
3206
|
'post',
|
|
@@ -5130,46 +5130,45 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
5130
5130
|
const namespaceFile = currentErrorFolder.file(`${namespace}.ts`);
|
|
5131
5131
|
namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
|
|
5132
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
|
+
]);
|
|
5133
5143
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
5134
5144
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
5135
5145
|
'presentation',
|
|
5136
5146
|
'rest'
|
|
5137
5147
|
]);
|
|
5138
|
-
const controllers = restPresentationFolder.content.subfolderNames;
|
|
5139
|
-
let
|
|
5148
|
+
const controllers = restPresentationFolder.content.subfolderNames.filter((x)=>!isPathParameterName(x));
|
|
5149
|
+
let controllerChoice = await interaction_select({
|
|
5140
5150
|
key: 'controllerSelection',
|
|
5141
5151
|
message: 'Controller: ',
|
|
5142
5152
|
choices: [
|
|
5143
5153
|
...controllers,
|
|
5144
|
-
|
|
5154
|
+
newController,
|
|
5155
|
+
withoutController
|
|
5145
5156
|
]
|
|
5146
5157
|
});
|
|
5147
|
-
if (
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
'presentation',
|
|
5162
|
-
'rest'
|
|
5163
|
-
]);
|
|
5164
|
-
sharedRestFolder.file('wires.ts').addLine(`export * from '../../bounded-contexts/${boundedContextFolder.name}/wiring/presentation/rest/${controller}'`);
|
|
5165
|
-
if (!sharedRestFolder.file('index.ts').exists) sharedRestFolder.createFile('index.ts', `
|
|
5166
|
-
import * as wires from './wires'
|
|
5167
|
-
|
|
5168
|
-
const restWires = Object.values(wires)
|
|
5169
|
-
|
|
5170
|
-
export const restHandlers = restWires.map(x => x().handle)
|
|
5171
|
-
`.trim());
|
|
5172
|
-
}
|
|
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}'`);
|
|
5173
5172
|
}
|
|
5174
5173
|
const method = await interaction_select({
|
|
5175
5174
|
key: 'method',
|
|
@@ -5184,21 +5183,32 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
5184
5183
|
});
|
|
5185
5184
|
const routeSegments = (await interaction_input({
|
|
5186
5185
|
key: 'path',
|
|
5187
|
-
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
|
+
}
|
|
5188
5191
|
})).split('/').filter((x)=>!!x);
|
|
5189
|
-
const
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
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`;
|
|
5195
5207
|
const endpointClassName = [
|
|
5196
|
-
|
|
5197
|
-
...routeSegments,
|
|
5208
|
+
...nameSegments,
|
|
5198
5209
|
method,
|
|
5199
5210
|
'endpoint'
|
|
5200
5211
|
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
|
|
5201
|
-
const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
5202
5212
|
const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
5203
5213
|
'..',
|
|
5204
5214
|
'..',
|
|
@@ -5218,8 +5228,11 @@ export class ${endpointClassName} {
|
|
|
5218
5228
|
|
|
5219
5229
|
get handle() {
|
|
5220
5230
|
return this.endpointGenerator(this.handler.handle, {
|
|
5221
|
-
route: { method: '${method}', path: [
|
|
5222
|
-
|
|
5231
|
+
route: { method: '${method}', path: [${[
|
|
5232
|
+
boundedContextFolder.name,
|
|
5233
|
+
...folderSegments
|
|
5234
|
+
].map((x)=>`'${x}'`).join(', ')}] },
|
|
5235
|
+
tags: ['${boundedContextFolder.name}${controller ? `: ${controller}` : ''}'],
|
|
5223
5236
|
})
|
|
5224
5237
|
}
|
|
5225
5238
|
}
|
|
@@ -5229,7 +5242,9 @@ export class ${endpointClassName} {
|
|
|
5229
5242
|
'wiring',
|
|
5230
5243
|
'presentation',
|
|
5231
5244
|
'rest',
|
|
5232
|
-
controller
|
|
5245
|
+
...controller ? [
|
|
5246
|
+
controller
|
|
5247
|
+
] : []
|
|
5233
5248
|
]);
|
|
5234
5249
|
const wireNameBase = `wire-${nameBase}`;
|
|
5235
5250
|
const wireNaming = new UnknownFormatNaming(wireNameBase);
|
|
@@ -5249,6 +5264,15 @@ export const wire${endpointClassName} = wireClass(
|
|
|
5249
5264
|
)
|
|
5250
5265
|
`.trim());
|
|
5251
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());
|
|
5252
5276
|
}
|
|
5253
5277
|
};
|
|
5254
5278
|
const scaffold_new_implementation_kindTitles = {
|
|
@@ -5888,12 +5912,15 @@ const answersFor = (command, request, owner)=>{
|
|
|
5888
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';
|
|
5889
5913
|
if ('endpoint' === request.operation) {
|
|
5890
5914
|
delete answers.controller;
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
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
|
+
}
|
|
5897
5924
|
}
|
|
5898
5925
|
if ('move' === request.operation) defaults.targetContext = request.context;
|
|
5899
5926
|
}
|
package/package.json
CHANGED
|
@@ -40,7 +40,7 @@ npx df-integration --request '{"operation":"add","integrations":["storybook"]}'
|
|
|
40
40
|
- `dependencies`: implementation/class name → array of qualified module IDs. Omitted entries keep the generator's checked suggestions; `[]` explicitly selects none when that selection applies. When wiring is off or no candidates exist, omit the group; see the [dependency conditions](agent-operations.md#dependency-keys-and-system-implementations). Every supplied dependency group must apply to the operation. Different primary/test implementations have independent lists.
|
|
41
41
|
- Aggregate repositories require `withRepository: true` and an `implementation`. Without it, aggregate creation makes no repository.
|
|
42
42
|
- New implementations use a `contract` ID and, with a branched wire, an explicit `environments` array. Moves use a `module` unit ID and optional `targetContext`, `aggregate` and `name`. `wire-dependency` uses a wiring target ID in `module` plus its `dependencies` entry.
|
|
43
|
-
- Endpoints use `controller`, lowercase `method`, relative `path` and a qualified `handler` ID when a wired handler is available. A new controller is created when its name does not exist.
|
|
43
|
+
- Endpoints use `controller`, lowercase `method`, relative `path` and a qualified `handler` ID when a wired handler is available. A new controller is created when its name does not exist; omit `controller` for an endpoint at the context root (`/<context>`, `/<context>/:id`).
|
|
44
44
|
- Integration-specific fields and script conflict decisions are in the integration request schema. Conflicts require explicit decisions, e.g. `"scriptConflicts": { "storybook": "keep" }`. Configuration changes that require confirmation interactively also require their explicit request field.
|
|
45
45
|
|
|
46
46
|
## Check the result
|
|
@@ -25,7 +25,7 @@ All operations support `dryRun` and `overwrite`. Except `bounded-context`, they
|
|
|
25
25
|
| `query` | `name`, `implementation` | `testImplementation`, `dependencies`. Bounded contexts only. |
|
|
26
26
|
| `port` | `name`, `implementation` | `testImplementation`, `dependencies`. `cross-context` is available only with a neighboring context, never in Shared Kernel. |
|
|
27
27
|
| `implementation` | `contract`, `implementation` | For a usable branched wire, `environments` is required and nonempty; otherwise omit it. `dependencies` is available for the newly added implementation when wiring applies. |
|
|
28
|
-
| `endpoint` | `
|
|
28
|
+
| `endpoint` | `method`, `path`, optional `controller` (omit for the context root; `path` then empty or starting with `:param`) | REST package and generator must exist. With wiring and selectable handlers, provide `handler`. Without selectable handlers, omit it; the generated handler remains `never` and needs a later approved generator rerun. |
|
|
29
29
|
| `wire-dependency` | `module`, `dependencies` | `module` is a wiring target ID, not a contract/unit ID. Adds only eligible dependencies not already wired to that implementation. |
|
|
30
30
|
| `move` | `module` | `module` is a unit ID. Optional `name`, `targetContext`, `aggregate`; omitted name/context keep the existing ones. A same-owner entity/value-object keeps its aggregate by default. The target aggregate must exist; the target context must be a discovered, allowed destination for that unit kind. Illegal cross-context imports reject the move. |
|
|
31
31
|
| `delete` | `module` | `module` is a unit ID. Deletes every file of the unit and its generated references (aggregate barrel re-export, in-memory DB section). Refused with `DELETE_NOT_ALLOWED` and `details.usedBy` while other files import it; nothing changes. |
|
|
@@ -4,7 +4,7 @@ When: an HTTP entry point (`../choosing-components.md`, step 2). It exposes a qu
|
|
|
4
4
|
|
|
5
5
|
## Generate (context only)
|
|
6
6
|
|
|
7
|
-
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).
|
|
7
|
+
Prompts: controller (select: existing | `New controller` → name | `No controller (context root)`) → 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).
|
|
8
8
|
|
|
9
9
|
`… pick:Presentation "pick:New Handlers" "pick:New controller" text:orders pick:get text:recent pick:RecentOrdersQuery`
|
|
10
10
|
`… pick:Presentation "pick:New Handlers" pick:orders pick:post default pick:PlaceOrder`
|
|
@@ -15,6 +15,8 @@ For `sales`, `orders`, `get`, `recent`:
|
|
|
15
15
|
- {wire} `<C>/wiring/presentation/rest/orders/wire-orders-recent-get-endpoint.ts` (`[wireRestEndpointGeneratorPresentationService, wireRecentOrdersQuery]`; `[]` without the generator file) + a line in that folder's `index.ts`
|
|
16
16
|
- {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)
|
|
17
17
|
|
|
18
|
+
- No controller, context `social-networks`, `get`, empty path: `<C>/presentation/rest/GET.ts`, `class SocialNetworksGetEndpoint`, route `['social-networks']`, tag `'social-networks'`; {wire} `<C>/wiring/presentation/rest/wire-social-networks-get-endpoint.ts`, a line in `<C>/wiring/presentation/rest/index.ts` and one in `<rootFolder>/presentation/rest/wires.ts`. Use it for collection endpoints of the context (`GET /social-networks`, `POST /social-networks`, `GET /social-networks/:id`) instead of a `list` controller or `/social-networks/social-networks`. Its path is empty or starts with `:param`: a static first segment is a controller.
|
|
19
|
+
|
|
18
20
|
The same controller, path, and method replace the existing endpoint (after `Overwrite them?`). Generate the exposed handler first, so `Handler:` lists it. If `handler: never` is left, re-run the endpoint generator once the handler exists, as an approved overwrite; don't replace it by hand.
|
|
19
21
|
|
|
20
22
|
## Implement
|