@domain-first/project-structure 8.5.1 → 8.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/287.js +40 -330
- package/dist/38.js +2 -2
- package/dist/526.js +376 -0
- package/dist/561.js +7 -9
- package/dist/{870.js → 780.js} +35 -1
- package/dist/{201.js → 947.js} +2 -36
- package/dist/graph.js +2 -2
- package/dist/index.cjs +94 -53
- package/dist/index.js +1 -1
- package/dist/init.cjs +7 -0
- package/dist/init.js +1 -1
- package/dist/integration.cjs +94 -53
- package/dist/integration.js +1 -1
- package/dist/integrations/openapi-extractor.d.ts +12 -0
- package/dist/lint.js +1 -1
- package/dist/react.cjs +94 -53
- package/dist/react.js +1 -1
- package/dist/rest-layout.d.ts +34 -0
- package/dist/upgrade-rest-root.d.ts +8 -0
- package/dist/upgrade-steps.d.ts +1 -0
- package/dist/upgrade.cjs +375 -7
- package/dist/upgrade.js +166 -9
- package/dist/use-cases/scaffold-new-handlers-rest-endpoint.d.ts +6 -0
- 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 +2 -2
- package/dist/711.js +0 -22
package/dist/index.cjs
CHANGED
|
@@ -1419,7 +1419,31 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
1419
1419
|
if (usesNext()) scaffoldNextRoute(nestedName, pageFile);
|
|
1420
1420
|
};
|
|
1421
1421
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
1422
|
-
const rootFolderSegments = (rootFolder)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n
|
|
1422
|
+
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
1423
|
+
const endpointFileLookup = (rootFolder)=>` const [currentBoundedContext, ...relativePath] = routeMetadata.path;
|
|
1424
|
+
|
|
1425
|
+
if (!currentBoundedContext) {
|
|
1426
|
+
return undefined;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// A controller is the first folder of the path; other routes
|
|
1430
|
+
// belong to the context root in presentation/rest/(root).
|
|
1431
|
+
const restFolder = path.join(
|
|
1432
|
+
${rootFolderSegments(rootFolder, 16)}'bounded-contexts',
|
|
1433
|
+
currentBoundedContext,
|
|
1434
|
+
'presentation',
|
|
1435
|
+
'rest'
|
|
1436
|
+
);
|
|
1437
|
+
const endpointPath = [
|
|
1438
|
+
...relativePath.map(pathParameterAsName),
|
|
1439
|
+
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
1440
|
+
];
|
|
1441
|
+
const endpointFile =
|
|
1442
|
+
project.getSourceFile(path.join(restFolder, ...endpointPath)) ??
|
|
1443
|
+
project.getSourceFile(
|
|
1444
|
+
path.join(restFolder, '(root)', ...endpointPath)
|
|
1445
|
+
);
|
|
1446
|
+
`;
|
|
1423
1447
|
const openapiExtractor = (rootFolder)=>`import path from 'node:path';
|
|
1424
1448
|
import {
|
|
1425
1449
|
type DocNode,
|
|
@@ -1531,25 +1555,7 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
|
1531
1555
|
path: readonly string[];
|
|
1532
1556
|
}): OpenApiData | undefined => {
|
|
1533
1557
|
try {
|
|
1534
|
-
|
|
1535
|
-
// context-root endpoints live right in presentation/rest.
|
|
1536
|
-
const [currentBoundedContext, ...relativePath] = routeMetadata.path;
|
|
1537
|
-
|
|
1538
|
-
if (!currentBoundedContext) {
|
|
1539
|
-
return undefined;
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
const endpointFile = project.getSourceFile(
|
|
1543
|
-
path.join(
|
|
1544
|
-
${rootFolderSegments(rootFolder)}'bounded-contexts',
|
|
1545
|
-
currentBoundedContext,
|
|
1546
|
-
'presentation',
|
|
1547
|
-
'rest',
|
|
1548
|
-
...relativePath.map(pathParameterAsName),
|
|
1549
|
-
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
1550
|
-
)
|
|
1551
|
-
);
|
|
1552
|
-
|
|
1558
|
+
${endpointFileLookup(rootFolder)}
|
|
1553
1559
|
if (!endpointFile) {
|
|
1554
1560
|
return undefined;
|
|
1555
1561
|
}
|
|
@@ -3200,7 +3206,7 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3200
3206
|
agent_requests_operation('endpoint', {
|
|
3201
3207
|
...common,
|
|
3202
3208
|
...agent_requests_owner,
|
|
3203
|
-
controller: agent_requests_name.optional().describe('Omit for
|
|
3209
|
+
controller: agent_requests_name.optional().describe('Omit for the context-root controller (root): `/<context>/<path>`.'),
|
|
3204
3210
|
method: external_zod_default()["enum"]([
|
|
3205
3211
|
'get',
|
|
3206
3212
|
'post',
|
|
@@ -4236,6 +4242,35 @@ const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
|
4236
4242
|
]
|
|
4237
4243
|
};
|
|
4238
4244
|
};
|
|
4245
|
+
const rootControllerFolder = '(root)';
|
|
4246
|
+
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
4247
|
+
const isPathParameterName = (name)=>name.startsWith(':') || /^_.+_$/.test(name);
|
|
4248
|
+
const endpointFileNames = new Set([
|
|
4249
|
+
'get',
|
|
4250
|
+
'post',
|
|
4251
|
+
'put',
|
|
4252
|
+
'patch',
|
|
4253
|
+
'delete'
|
|
4254
|
+
].map((method)=>`${method.toUpperCase()}.ts`));
|
|
4255
|
+
const rest_layout_entries = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
4256
|
+
withFileTypes: true
|
|
4257
|
+
}) : [];
|
|
4258
|
+
const rest_layout_subfolders = (folder)=>rest_layout_entries(folder).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name);
|
|
4259
|
+
const restFolders = (boundedContextFolder)=>({
|
|
4260
|
+
presentation: external_node_path_default().join(boundedContextFolder, 'presentation', 'rest'),
|
|
4261
|
+
wiring: external_node_path_default().join(boundedContextFolder, 'wiring', 'presentation', 'rest')
|
|
4262
|
+
});
|
|
4263
|
+
const restControllers = (boundedContextFolder)=>rest_layout_subfolders(restFolders(boundedContextFolder).presentation).filter((name)=>name !== rootControllerFolder && !isPathParameterName(name));
|
|
4264
|
+
const rootStaticSegments = (boundedContextFolder)=>rest_layout_subfolders(external_node_path_default().join(restFolders(boundedContextFolder).presentation, rootControllerFolder)).filter((name)=>!isPathParameterName(name));
|
|
4265
|
+
const legacyRootEndpoints = (boundedContextFolder)=>{
|
|
4266
|
+
const { presentation, wiring } = restFolders(boundedContextFolder);
|
|
4267
|
+
return {
|
|
4268
|
+
endpointFiles: rest_layout_entries(presentation).filter((entry)=>entry.isFile() && endpointFileNames.has(entry.name)).map((entry)=>external_node_path_default().join(presentation, entry.name)),
|
|
4269
|
+
parameterFolders: rest_layout_subfolders(presentation).filter(isPathParameterName).map((name)=>external_node_path_default().join(presentation, name)),
|
|
4270
|
+
wireFiles: rest_layout_entries(wiring).filter((entry)=>entry.isFile() && 'index.ts' !== entry.name && /\.ts$/.test(entry.name)).map((entry)=>external_node_path_default().join(wiring, entry.name))
|
|
4271
|
+
};
|
|
4272
|
+
};
|
|
4273
|
+
const hasLegacyRootEndpoints = (boundedContextFolder)=>Object.values(legacyRootEndpoints(boundedContextFolder)).some((paths)=>paths.length > 0);
|
|
4239
4274
|
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
4240
4275
|
if ('ports' === kind) return crossContext ? [
|
|
4241
4276
|
{
|
|
@@ -5131,45 +5166,48 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
5131
5166
|
namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
|
|
5132
5167
|
};
|
|
5133
5168
|
const newController = 'New controller';
|
|
5134
|
-
const
|
|
5135
|
-
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
5136
|
-
const isPathParameterName = (name)=>name.startsWith(':') || /^_.+_$/.test(name);
|
|
5169
|
+
const rootControllerChoice = 'No controller (context root)';
|
|
5137
5170
|
const sharedRestFolder = (boundedContextFolder)=>boundedContextFolder.subitem([
|
|
5138
5171
|
'..',
|
|
5139
5172
|
'..',
|
|
5140
5173
|
'presentation',
|
|
5141
5174
|
'rest'
|
|
5142
5175
|
]);
|
|
5176
|
+
const legacyRootEndpointsMessage = (context)=>`${context} keeps its context-root endpoints in the 8.5 layout (presentation/rest/<METHOD>.ts, _param_/). Run npx df-upgrade to move them to presentation/rest/(root)/ first.`;
|
|
5143
5177
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
5178
|
+
const context = boundedContextFolder.name;
|
|
5144
5179
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
5145
5180
|
'presentation',
|
|
5146
5181
|
'rest'
|
|
5147
5182
|
]);
|
|
5148
|
-
const controllers =
|
|
5183
|
+
const controllers = restControllers(boundedContextFolder.path);
|
|
5184
|
+
const rootSegments = rootStaticSegments(boundedContextFolder.path);
|
|
5149
5185
|
let controllerChoice = await interaction_select({
|
|
5150
5186
|
key: 'controllerSelection',
|
|
5151
5187
|
message: 'Controller: ',
|
|
5152
5188
|
choices: [
|
|
5189
|
+
{
|
|
5190
|
+
value: rootControllerChoice,
|
|
5191
|
+
name: `(root) — /${context}`
|
|
5192
|
+
},
|
|
5153
5193
|
...controllers,
|
|
5154
|
-
newController
|
|
5155
|
-
withoutController
|
|
5194
|
+
newController
|
|
5156
5195
|
]
|
|
5157
5196
|
});
|
|
5197
|
+
if (controllerChoice === rootControllerChoice && hasLegacyRootEndpoints(boundedContextFolder.path)) throw new RequestError('UPGRADE_REQUIRED', legacyRootEndpointsMessage(context));
|
|
5158
5198
|
if (controllerChoice === newController) controllerChoice = await interaction_input({
|
|
5159
5199
|
key: 'controllerName',
|
|
5160
5200
|
message: 'Name: ',
|
|
5161
|
-
validate: (value)=>
|
|
5201
|
+
validate: (value)=>{
|
|
5202
|
+
if (!value.trim()) return 'Name is required; pick "(root)" for an endpoint at the context root';
|
|
5203
|
+
if (isPathParameterName(value) || value.includes('/') || /[()]/.test(value)) return 'A controller is one static path segment';
|
|
5204
|
+
if (value === context) return `"${value}" is the context itself: pick "(root)" for /${context}`;
|
|
5205
|
+
if (rootSegments.includes(value)) return `/${context}/${value} belongs to the context root ((root)/${value}): add the endpoint there`;
|
|
5206
|
+
return true;
|
|
5207
|
+
}
|
|
5162
5208
|
});
|
|
5163
|
-
const controller = controllerChoice ===
|
|
5209
|
+
const controller = controllerChoice === rootControllerChoice ? void 0 : controllerChoice;
|
|
5164
5210
|
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
|
-
}
|
|
5173
5211
|
const method = await interaction_select({
|
|
5174
5212
|
key: 'method',
|
|
5175
5213
|
message: 'Method:',
|
|
@@ -5186,10 +5224,16 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
5186
5224
|
message: 'Relative path (split by "/"):',
|
|
5187
5225
|
validate: (value)=>{
|
|
5188
5226
|
const [first] = value.split('/').filter((x)=>!!x);
|
|
5189
|
-
return controller || !first || first.startsWith(':') ? true :
|
|
5227
|
+
return controller || !first || first.startsWith(':') || !controllers.includes(first) ? true : `/${context}/${first} belongs to controller "${first}": add the endpoint there`;
|
|
5190
5228
|
}
|
|
5191
5229
|
})).split('/').filter((x)=>!!x);
|
|
5230
|
+
const group = controller ?? "(root)";
|
|
5192
5231
|
const folderSegments = [
|
|
5232
|
+
group,
|
|
5233
|
+
...routeSegments
|
|
5234
|
+
];
|
|
5235
|
+
const routePath = [
|
|
5236
|
+
context,
|
|
5193
5237
|
...controller ? [
|
|
5194
5238
|
controller
|
|
5195
5239
|
] : [],
|
|
@@ -5197,7 +5241,7 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
5197
5241
|
];
|
|
5198
5242
|
const endpointFolder = restPresentationFolder.subitem(folderSegments.map(pathParameterAsName));
|
|
5199
5243
|
const nameSegments = [
|
|
5200
|
-
controller ??
|
|
5244
|
+
controller ?? context,
|
|
5201
5245
|
...routeSegments
|
|
5202
5246
|
];
|
|
5203
5247
|
const nameBase = `${[
|
|
@@ -5228,11 +5272,8 @@ export class ${endpointClassName} {
|
|
|
5228
5272
|
|
|
5229
5273
|
get handle() {
|
|
5230
5274
|
return this.endpointGenerator(this.handler.handle, {
|
|
5231
|
-
route: { method: '${method}', path: [${
|
|
5232
|
-
|
|
5233
|
-
...folderSegments
|
|
5234
|
-
].map((x)=>`'${x}'`).join(', ')}] },
|
|
5235
|
-
tags: ['${boundedContextFolder.name}${controller ? `: ${controller}` : ''}'],
|
|
5275
|
+
route: { method: '${method}', path: [${routePath.map((x)=>`'${x}'`).join(', ')}] },
|
|
5276
|
+
tags: ['${context}${controller ? `: ${controller}` : ''}'],
|
|
5236
5277
|
})
|
|
5237
5278
|
}
|
|
5238
5279
|
}
|
|
@@ -5242,9 +5283,7 @@ export class ${endpointClassName} {
|
|
|
5242
5283
|
'wiring',
|
|
5243
5284
|
'presentation',
|
|
5244
5285
|
'rest',
|
|
5245
|
-
|
|
5246
|
-
controller
|
|
5247
|
-
] : []
|
|
5286
|
+
group
|
|
5248
5287
|
]);
|
|
5249
5288
|
const wireNameBase = `wire-${nameBase}`;
|
|
5250
5289
|
const wireNaming = new UnknownFormatNaming(wireNameBase);
|
|
@@ -5264,7 +5303,12 @@ export const wire${endpointClassName} = wireClass(
|
|
|
5264
5303
|
)
|
|
5265
5304
|
`.trim());
|
|
5266
5305
|
wiringFolder.file('index.ts').addLineIfMissing(`export * from './${wireNaming.fileName}'`);
|
|
5267
|
-
|
|
5306
|
+
boundedContextFolder.subitem([
|
|
5307
|
+
'wiring',
|
|
5308
|
+
'presentation',
|
|
5309
|
+
'rest'
|
|
5310
|
+
]).file('index.ts').addLineIfMissing(`export * from './${group}'`);
|
|
5311
|
+
sharedRestFolder(boundedContextFolder).file('wires.ts').addLineIfMissing(`export * from '../../bounded-contexts/${context}/wiring/presentation/rest/${group}'`);
|
|
5268
5312
|
const restHandlersFile = sharedRestFolder(boundedContextFolder).file('index.ts');
|
|
5269
5313
|
if (!restHandlersFile.exists) sharedRestFolder(boundedContextFolder).createFile('index.ts', `
|
|
5270
5314
|
import * as wires from './wires'
|
|
@@ -5912,12 +5956,9 @@ const answersFor = (command, request, owner)=>{
|
|
|
5912
5956
|
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';
|
|
5913
5957
|
if ('endpoint' === request.operation) {
|
|
5914
5958
|
delete answers.controller;
|
|
5915
|
-
if (void 0 === request.controller) answers.controllerSelection =
|
|
5959
|
+
if (void 0 === request.controller) answers.controllerSelection = rootControllerChoice;
|
|
5916
5960
|
else {
|
|
5917
|
-
const existing = owner.
|
|
5918
|
-
'presentation',
|
|
5919
|
-
'rest'
|
|
5920
|
-
]).content.subfolderNames.includes(request.controller);
|
|
5961
|
+
const existing = restControllers(owner.path).includes(request.controller);
|
|
5921
5962
|
answers.controllerSelection = existing ? request.controller : 'New controller';
|
|
5922
5963
|
if (!existing) answers.controllerName = request.controller;
|
|
5923
5964
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { select as prompts_select } from "@inquirer/prompts";
|
|
3
3
|
import { runCLI } from "./561.js";
|
|
4
|
-
import { outdatedConfigMessage, ProjectRoot, ConfigFile, Folder } from "./
|
|
4
|
+
import { outdatedConfigMessage, ProjectRoot, ConfigFile, Folder } from "./780.js";
|
|
5
5
|
import { scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewAggregateUseCase, scaffoldNewQuery, scaffoldNewInfrastructureService, scaffoldNewHandlersRestEndpoint, savePendingChanges, moveBackendUnitUseCase, scaffoldNewCommand, scaffoldNewPresentationService, deleteBackendUnitUseCase, scaffoldNewApplicationService, scaffoldNewUseCase, scaffoldNewImplementation, wireDependency, scaffoldNewBoundedContextUseCase, scaffoldNewDomainObject, scaffoldNewApplicationPort } from "./287.js";
|
|
6
6
|
const main = async ()=>{
|
|
7
7
|
if (!ConfigFile.exists) {
|
package/dist/init.cjs
CHANGED
|
@@ -1529,6 +1529,13 @@ const initializeUseCase = async (section)=>{
|
|
|
1529
1529
|
return nextSteps;
|
|
1530
1530
|
};
|
|
1531
1531
|
Symbol('enter-implementation-type-once');
|
|
1532
|
+
new Set([
|
|
1533
|
+
'get',
|
|
1534
|
+
'post',
|
|
1535
|
+
'put',
|
|
1536
|
+
'patch',
|
|
1537
|
+
'delete'
|
|
1538
|
+
].map((method)=>`${method.toUpperCase()}.ts`));
|
|
1532
1539
|
const help = `Usage: df-init [--section project|backend|frontend]
|
|
1533
1540
|
|
|
1534
1541
|
Configures project, backend and frontend in order. Any section
|
package/dist/init.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import { ConfigFile, outdatedConfigMessage } from "./
|
|
3
|
+
import { ConfigFile, outdatedConfigMessage } from "./780.js";
|
|
4
4
|
import { printNextSteps, configurationSections, initializeUseCase, savePendingChanges } from "./287.js";
|
|
5
5
|
const help = `Usage: df-init [--section project|backend|frontend]
|
|
6
6
|
|
package/dist/integration.cjs
CHANGED
|
@@ -1419,7 +1419,31 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
1419
1419
|
if (usesNext()) scaffoldNextRoute(nestedName, pageFile);
|
|
1420
1420
|
};
|
|
1421
1421
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
1422
|
-
const rootFolderSegments = (rootFolder)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n
|
|
1422
|
+
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
1423
|
+
const endpointFileLookup = (rootFolder)=>` const [currentBoundedContext, ...relativePath] = routeMetadata.path;
|
|
1424
|
+
|
|
1425
|
+
if (!currentBoundedContext) {
|
|
1426
|
+
return undefined;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// A controller is the first folder of the path; other routes
|
|
1430
|
+
// belong to the context root in presentation/rest/(root).
|
|
1431
|
+
const restFolder = path.join(
|
|
1432
|
+
${rootFolderSegments(rootFolder, 16)}'bounded-contexts',
|
|
1433
|
+
currentBoundedContext,
|
|
1434
|
+
'presentation',
|
|
1435
|
+
'rest'
|
|
1436
|
+
);
|
|
1437
|
+
const endpointPath = [
|
|
1438
|
+
...relativePath.map(pathParameterAsName),
|
|
1439
|
+
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
1440
|
+
];
|
|
1441
|
+
const endpointFile =
|
|
1442
|
+
project.getSourceFile(path.join(restFolder, ...endpointPath)) ??
|
|
1443
|
+
project.getSourceFile(
|
|
1444
|
+
path.join(restFolder, '(root)', ...endpointPath)
|
|
1445
|
+
);
|
|
1446
|
+
`;
|
|
1423
1447
|
const openapiExtractor = (rootFolder)=>`import path from 'node:path';
|
|
1424
1448
|
import {
|
|
1425
1449
|
type DocNode,
|
|
@@ -1531,25 +1555,7 @@ export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
|
1531
1555
|
path: readonly string[];
|
|
1532
1556
|
}): OpenApiData | undefined => {
|
|
1533
1557
|
try {
|
|
1534
|
-
|
|
1535
|
-
// context-root endpoints live right in presentation/rest.
|
|
1536
|
-
const [currentBoundedContext, ...relativePath] = routeMetadata.path;
|
|
1537
|
-
|
|
1538
|
-
if (!currentBoundedContext) {
|
|
1539
|
-
return undefined;
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
const endpointFile = project.getSourceFile(
|
|
1543
|
-
path.join(
|
|
1544
|
-
${rootFolderSegments(rootFolder)}'bounded-contexts',
|
|
1545
|
-
currentBoundedContext,
|
|
1546
|
-
'presentation',
|
|
1547
|
-
'rest',
|
|
1548
|
-
...relativePath.map(pathParameterAsName),
|
|
1549
|
-
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
1550
|
-
)
|
|
1551
|
-
);
|
|
1552
|
-
|
|
1558
|
+
${endpointFileLookup(rootFolder)}
|
|
1553
1559
|
if (!endpointFile) {
|
|
1554
1560
|
return undefined;
|
|
1555
1561
|
}
|
|
@@ -3200,7 +3206,7 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3200
3206
|
agent_requests_operation('endpoint', {
|
|
3201
3207
|
...common,
|
|
3202
3208
|
...agent_requests_owner,
|
|
3203
|
-
controller: agent_requests_name.optional().describe('Omit for
|
|
3209
|
+
controller: agent_requests_name.optional().describe('Omit for the context-root controller (root): `/<context>/<path>`.'),
|
|
3204
3210
|
method: external_zod_default()["enum"]([
|
|
3205
3211
|
'get',
|
|
3206
3212
|
'post',
|
|
@@ -4236,6 +4242,35 @@ const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
|
4236
4242
|
]
|
|
4237
4243
|
};
|
|
4238
4244
|
};
|
|
4245
|
+
const rootControllerFolder = '(root)';
|
|
4246
|
+
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
4247
|
+
const isPathParameterName = (name)=>name.startsWith(':') || /^_.+_$/.test(name);
|
|
4248
|
+
const endpointFileNames = new Set([
|
|
4249
|
+
'get',
|
|
4250
|
+
'post',
|
|
4251
|
+
'put',
|
|
4252
|
+
'patch',
|
|
4253
|
+
'delete'
|
|
4254
|
+
].map((method)=>`${method.toUpperCase()}.ts`));
|
|
4255
|
+
const rest_layout_entries = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
4256
|
+
withFileTypes: true
|
|
4257
|
+
}) : [];
|
|
4258
|
+
const rest_layout_subfolders = (folder)=>rest_layout_entries(folder).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name);
|
|
4259
|
+
const restFolders = (boundedContextFolder)=>({
|
|
4260
|
+
presentation: external_node_path_default().join(boundedContextFolder, 'presentation', 'rest'),
|
|
4261
|
+
wiring: external_node_path_default().join(boundedContextFolder, 'wiring', 'presentation', 'rest')
|
|
4262
|
+
});
|
|
4263
|
+
const restControllers = (boundedContextFolder)=>rest_layout_subfolders(restFolders(boundedContextFolder).presentation).filter((name)=>name !== rootControllerFolder && !isPathParameterName(name));
|
|
4264
|
+
const rootStaticSegments = (boundedContextFolder)=>rest_layout_subfolders(external_node_path_default().join(restFolders(boundedContextFolder).presentation, rootControllerFolder)).filter((name)=>!isPathParameterName(name));
|
|
4265
|
+
const legacyRootEndpoints = (boundedContextFolder)=>{
|
|
4266
|
+
const { presentation, wiring } = restFolders(boundedContextFolder);
|
|
4267
|
+
return {
|
|
4268
|
+
endpointFiles: rest_layout_entries(presentation).filter((entry)=>entry.isFile() && endpointFileNames.has(entry.name)).map((entry)=>external_node_path_default().join(presentation, entry.name)),
|
|
4269
|
+
parameterFolders: rest_layout_subfolders(presentation).filter(isPathParameterName).map((name)=>external_node_path_default().join(presentation, name)),
|
|
4270
|
+
wireFiles: rest_layout_entries(wiring).filter((entry)=>entry.isFile() && 'index.ts' !== entry.name && /\.ts$/.test(entry.name)).map((entry)=>external_node_path_default().join(wiring, entry.name))
|
|
4271
|
+
};
|
|
4272
|
+
};
|
|
4273
|
+
const hasLegacyRootEndpoints = (boundedContextFolder)=>Object.values(legacyRootEndpoints(boundedContextFolder)).some((paths)=>paths.length > 0);
|
|
4239
4274
|
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
4240
4275
|
if ('ports' === kind) return crossContext ? [
|
|
4241
4276
|
{
|
|
@@ -5131,45 +5166,48 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
5131
5166
|
namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
|
|
5132
5167
|
};
|
|
5133
5168
|
const newController = 'New controller';
|
|
5134
|
-
const
|
|
5135
|
-
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
5136
|
-
const isPathParameterName = (name)=>name.startsWith(':') || /^_.+_$/.test(name);
|
|
5169
|
+
const rootControllerChoice = 'No controller (context root)';
|
|
5137
5170
|
const sharedRestFolder = (boundedContextFolder)=>boundedContextFolder.subitem([
|
|
5138
5171
|
'..',
|
|
5139
5172
|
'..',
|
|
5140
5173
|
'presentation',
|
|
5141
5174
|
'rest'
|
|
5142
5175
|
]);
|
|
5176
|
+
const legacyRootEndpointsMessage = (context)=>`${context} keeps its context-root endpoints in the 8.5 layout (presentation/rest/<METHOD>.ts, _param_/). Run npx df-upgrade to move them to presentation/rest/(root)/ first.`;
|
|
5143
5177
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
5178
|
+
const context = boundedContextFolder.name;
|
|
5144
5179
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
5145
5180
|
'presentation',
|
|
5146
5181
|
'rest'
|
|
5147
5182
|
]);
|
|
5148
|
-
const controllers =
|
|
5183
|
+
const controllers = restControllers(boundedContextFolder.path);
|
|
5184
|
+
const rootSegments = rootStaticSegments(boundedContextFolder.path);
|
|
5149
5185
|
let controllerChoice = await interaction_select({
|
|
5150
5186
|
key: 'controllerSelection',
|
|
5151
5187
|
message: 'Controller: ',
|
|
5152
5188
|
choices: [
|
|
5189
|
+
{
|
|
5190
|
+
value: rootControllerChoice,
|
|
5191
|
+
name: `(root) — /${context}`
|
|
5192
|
+
},
|
|
5153
5193
|
...controllers,
|
|
5154
|
-
newController
|
|
5155
|
-
withoutController
|
|
5194
|
+
newController
|
|
5156
5195
|
]
|
|
5157
5196
|
});
|
|
5197
|
+
if (controllerChoice === rootControllerChoice && hasLegacyRootEndpoints(boundedContextFolder.path)) throw new RequestError('UPGRADE_REQUIRED', legacyRootEndpointsMessage(context));
|
|
5158
5198
|
if (controllerChoice === newController) controllerChoice = await interaction_input({
|
|
5159
5199
|
key: 'controllerName',
|
|
5160
5200
|
message: 'Name: ',
|
|
5161
|
-
validate: (value)=>
|
|
5201
|
+
validate: (value)=>{
|
|
5202
|
+
if (!value.trim()) return 'Name is required; pick "(root)" for an endpoint at the context root';
|
|
5203
|
+
if (isPathParameterName(value) || value.includes('/') || /[()]/.test(value)) return 'A controller is one static path segment';
|
|
5204
|
+
if (value === context) return `"${value}" is the context itself: pick "(root)" for /${context}`;
|
|
5205
|
+
if (rootSegments.includes(value)) return `/${context}/${value} belongs to the context root ((root)/${value}): add the endpoint there`;
|
|
5206
|
+
return true;
|
|
5207
|
+
}
|
|
5162
5208
|
});
|
|
5163
|
-
const controller = controllerChoice ===
|
|
5209
|
+
const controller = controllerChoice === rootControllerChoice ? void 0 : controllerChoice;
|
|
5164
5210
|
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
|
-
}
|
|
5173
5211
|
const method = await interaction_select({
|
|
5174
5212
|
key: 'method',
|
|
5175
5213
|
message: 'Method:',
|
|
@@ -5186,10 +5224,16 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
5186
5224
|
message: 'Relative path (split by "/"):',
|
|
5187
5225
|
validate: (value)=>{
|
|
5188
5226
|
const [first] = value.split('/').filter((x)=>!!x);
|
|
5189
|
-
return controller || !first || first.startsWith(':') ? true :
|
|
5227
|
+
return controller || !first || first.startsWith(':') || !controllers.includes(first) ? true : `/${context}/${first} belongs to controller "${first}": add the endpoint there`;
|
|
5190
5228
|
}
|
|
5191
5229
|
})).split('/').filter((x)=>!!x);
|
|
5230
|
+
const group = controller ?? "(root)";
|
|
5192
5231
|
const folderSegments = [
|
|
5232
|
+
group,
|
|
5233
|
+
...routeSegments
|
|
5234
|
+
];
|
|
5235
|
+
const routePath = [
|
|
5236
|
+
context,
|
|
5193
5237
|
...controller ? [
|
|
5194
5238
|
controller
|
|
5195
5239
|
] : [],
|
|
@@ -5197,7 +5241,7 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
5197
5241
|
];
|
|
5198
5242
|
const endpointFolder = restPresentationFolder.subitem(folderSegments.map(pathParameterAsName));
|
|
5199
5243
|
const nameSegments = [
|
|
5200
|
-
controller ??
|
|
5244
|
+
controller ?? context,
|
|
5201
5245
|
...routeSegments
|
|
5202
5246
|
];
|
|
5203
5247
|
const nameBase = `${[
|
|
@@ -5228,11 +5272,8 @@ export class ${endpointClassName} {
|
|
|
5228
5272
|
|
|
5229
5273
|
get handle() {
|
|
5230
5274
|
return this.endpointGenerator(this.handler.handle, {
|
|
5231
|
-
route: { method: '${method}', path: [${
|
|
5232
|
-
|
|
5233
|
-
...folderSegments
|
|
5234
|
-
].map((x)=>`'${x}'`).join(', ')}] },
|
|
5235
|
-
tags: ['${boundedContextFolder.name}${controller ? `: ${controller}` : ''}'],
|
|
5275
|
+
route: { method: '${method}', path: [${routePath.map((x)=>`'${x}'`).join(', ')}] },
|
|
5276
|
+
tags: ['${context}${controller ? `: ${controller}` : ''}'],
|
|
5236
5277
|
})
|
|
5237
5278
|
}
|
|
5238
5279
|
}
|
|
@@ -5242,9 +5283,7 @@ export class ${endpointClassName} {
|
|
|
5242
5283
|
'wiring',
|
|
5243
5284
|
'presentation',
|
|
5244
5285
|
'rest',
|
|
5245
|
-
|
|
5246
|
-
controller
|
|
5247
|
-
] : []
|
|
5286
|
+
group
|
|
5248
5287
|
]);
|
|
5249
5288
|
const wireNameBase = `wire-${nameBase}`;
|
|
5250
5289
|
const wireNaming = new UnknownFormatNaming(wireNameBase);
|
|
@@ -5264,7 +5303,12 @@ export const wire${endpointClassName} = wireClass(
|
|
|
5264
5303
|
)
|
|
5265
5304
|
`.trim());
|
|
5266
5305
|
wiringFolder.file('index.ts').addLineIfMissing(`export * from './${wireNaming.fileName}'`);
|
|
5267
|
-
|
|
5306
|
+
boundedContextFolder.subitem([
|
|
5307
|
+
'wiring',
|
|
5308
|
+
'presentation',
|
|
5309
|
+
'rest'
|
|
5310
|
+
]).file('index.ts').addLineIfMissing(`export * from './${group}'`);
|
|
5311
|
+
sharedRestFolder(boundedContextFolder).file('wires.ts').addLineIfMissing(`export * from '../../bounded-contexts/${context}/wiring/presentation/rest/${group}'`);
|
|
5268
5312
|
const restHandlersFile = sharedRestFolder(boundedContextFolder).file('index.ts');
|
|
5269
5313
|
if (!restHandlersFile.exists) sharedRestFolder(boundedContextFolder).createFile('index.ts', `
|
|
5270
5314
|
import * as wires from './wires'
|
|
@@ -5912,12 +5956,9 @@ const answersFor = (command, request, owner)=>{
|
|
|
5912
5956
|
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';
|
|
5913
5957
|
if ('endpoint' === request.operation) {
|
|
5914
5958
|
delete answers.controller;
|
|
5915
|
-
if (void 0 === request.controller) answers.controllerSelection =
|
|
5959
|
+
if (void 0 === request.controller) answers.controllerSelection = rootControllerChoice;
|
|
5916
5960
|
else {
|
|
5917
|
-
const existing = owner.
|
|
5918
|
-
'presentation',
|
|
5919
|
-
'rest'
|
|
5920
|
-
]).content.subfolderNames.includes(request.controller);
|
|
5961
|
+
const existing = restControllers(owner.path).includes(request.controller);
|
|
5921
5962
|
answers.controllerSelection = existing ? request.controller : 'New controller';
|
|
5922
5963
|
if (!existing) answers.controllerName = request.controller;
|
|
5923
5964
|
}
|
package/dist/integration.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
import { runCLI } from "./561.js";
|
|
4
|
-
import { ConfigFile, outdatedConfigMessage } from "./
|
|
4
|
+
import { ConfigFile, outdatedConfigMessage } from "./780.js";
|
|
5
5
|
import { addIntegration } from "./287.js";
|
|
6
6
|
runCLI('df-integration', async ()=>{
|
|
7
7
|
const help = `Usage: df-integration
|
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
export declare const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
2
|
+
/**
|
|
3
|
+
* How 8.5.1 found the endpoint file, as scaffolded: context-root endpoints
|
|
4
|
+
* right in `presentation/rest/`. `df-upgrade` replaces it with
|
|
5
|
+
* `endpointFileLookup`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const legacyEndpointFileLookup: (rootFolder: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* A controller is the first folder of the route; any other route belongs
|
|
10
|
+
* to the context-root controller in `presentation/rest/(root)/`. The
|
|
11
|
+
* generator keeps the two apart, so at most one of the files exists.
|
|
12
|
+
*/
|
|
13
|
+
export declare const endpointFileLookup: (rootFolder: string) => string;
|
|
2
14
|
export declare const openapiExtractor: (rootFolder: string) => string;
|
package/dist/lint.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
|
-
import { configuredDependencyRules, ProjectRoot, outdatedConfigMessage, ConfigFile } from "./
|
|
3
|
+
import { configuredDependencyRules, ProjectRoot, outdatedConfigMessage, ConfigFile } from "./780.js";
|
|
4
4
|
import { lintProject, formatViolations } from "./38.js";
|
|
5
5
|
const help = `Usage: df-lint [rootFolder]
|
|
6
6
|
|