@domain-first/project-structure 8.2.0 → 8.3.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 +5 -1
- package/dist/287.js +221 -6
- package/dist/561.js +22 -5
- package/dist/agent-cli.d.ts +17 -0
- package/dist/agent-requests.d.ts +34 -0
- package/dist/backend-module-move.d.ts +16 -0
- package/dist/index.cjs +244 -10
- package/dist/index.js +4 -2
- package/dist/init.cjs +55 -55
- package/dist/integration.cjs +241 -9
- package/dist/react-module-move.d.ts +21 -0
- package/dist/react.cjs +248 -10
- package/dist/react.js +8 -2
- package/dist/use-cases/delete-backend-unit.d.ts +6 -0
- package/dist/use-cases/delete-react-module.d.ts +8 -0
- package/dist/use-cases/index.d.ts +2 -0
- package/package.json +1 -1
- package/skills/df-ps-react/SKILL.md +5 -3
- package/skills/df-ps-react/references/generators.md +4 -0
- package/skills/df-ps-scaffold/SKILL.md +5 -4
- package/skills/df-ps-scaffold/references/agent-mode.md +1 -0
- package/skills/df-ps-scaffold/references/agent-operations.md +3 -0
- package/skills/df-ps-scaffold/references/units/delete.md +19 -0
- package/skills/df-ps-scaffold/scripts/drive.mjs +5 -0
package/README.md
CHANGED
|
@@ -204,6 +204,10 @@ Choose **Infrastructure → New Implementation** to give an existing repository,
|
|
|
204
204
|
|
|
205
205
|
Choose **Move or rename** in the context menu: rename an aggregate, entity, value object, service, port, query, command or use case, move it to another bounded context or to the Shared Kernel, or move an entity in or out of an aggregate. Its files, implementations, wire, specs and every import and derived name in the project follow it: `OrderRepository`, `PrismaOrderRepository`, `wireOrderRepository`, the `orderRepository` parameter of a use case, the in-memory DB section. A move that would introduce a forbidden import between contexts is refused, with the list of imports that would cross the boundary.
|
|
206
206
|
|
|
207
|
+
### How to delete a module
|
|
208
|
+
|
|
209
|
+
Choose **Delete** in the context menu and pick the module. All its files go: the contract, implementations, wire and specs, an aggregate with its whole folder, plus the lines generators added for it elsewhere (an entity's re-export in its aggregate, an aggregate's in-memory DB section). While another file still imports it, nothing is deleted and the CLI lists those imports, so nothing is left broken.
|
|
210
|
+
|
|
207
211
|
### How to add errors
|
|
208
212
|
|
|
209
213
|
Choose **Domain → Errors** to add an error to the context namespace, create a nested namespace, or add an error to it. The context namespace (`SalesErrors = errorNamespace('sales')` in `domain/errors/index.ts`) is created with the first error added without a namespace.
|
|
@@ -265,7 +269,7 @@ admin/panel/users → pages/admin/panel/admin-panel-users-page.tsx (AdminPane
|
|
|
265
269
|
|
|
266
270
|
With Next.js, a new page also gets its App Router route, `app/admin/panel/users/page.tsx`, which renders `AdminPanelUsersPage`. An existing route is never overwritten.
|
|
267
271
|
|
|
268
|
-
**Move or rename page** and **Move or rename widget** move the files and update every import in the project. With Next.js, moving a page also offers to move its route, `app/admin/users/` → `app/backoffice/users/`, since its URL changes with it.
|
|
272
|
+
**Move or rename page** and **Move or rename widget** move the files and update every import in the project. **Delete page** and **Delete widget** remove them once nothing imports them, a Next.js page's own route included if you say so. With Next.js, moving a page also offers to move its route, `app/admin/users/` → `app/backoffice/users/`, since its URL changes with it.
|
|
269
273
|
|
|
270
274
|
### How to add tooling
|
|
271
275
|
|
package/dist/287.js
CHANGED
|
@@ -2651,6 +2651,75 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
2651
2651
|
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
2652
2652
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2653
2653
|
};
|
|
2654
|
+
const importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
2655
|
+
const importLine = /^\s*(?:import|export)\b[^'"\n]*\bfrom\s*(['"])([^'"\n]+)\1;?\s*$/;
|
|
2656
|
+
const deleteBackendUnit = (projectRoot, rootFolderPath, unit)=>{
|
|
2657
|
+
const files = [
|
|
2658
|
+
...unitMoves(unit, unit).keys()
|
|
2659
|
+
];
|
|
2660
|
+
const fileSet = new Set(files);
|
|
2661
|
+
const stems = new Set(files.map((file)=>file.replace(codeExtension, '')));
|
|
2662
|
+
const aggregateFolder = 'aggregate' === unit.kind ? node_path.join(unit.ownerPath, 'domain/aggregates', unit.name) : void 0;
|
|
2663
|
+
const parentAggregate = unit.aggregate ? node_path.join(unit.ownerPath, 'domain/aggregates', unit.aggregate) : void 0;
|
|
2664
|
+
const isUnit = (resolved)=>stems.has(resolved) || !!aggregateFolder && (resolved === aggregateFolder || resolved.startsWith(`${aggregateFolder}${node_path.sep}`));
|
|
2665
|
+
const isParentBarrel = (resolved)=>!!parentAggregate && (resolved === parentAggregate || resolved === node_path.join(parentAggregate, 'index'));
|
|
2666
|
+
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
2667
|
+
const resolved = (specifier, file)=>resolve(specifier, file)?.resolved;
|
|
2668
|
+
const withoutUnitImports = (content, file)=>content.split('\n').filter((line)=>{
|
|
2669
|
+
const specifier = line.match(importLine)?.[2];
|
|
2670
|
+
const target = specifier && resolved(specifier, file);
|
|
2671
|
+
return !(target && isUnit(target));
|
|
2672
|
+
}).join('\n');
|
|
2673
|
+
const cleaned = new Map();
|
|
2674
|
+
const inMemoryDb = inMemoryDbFile(rootFolderPath);
|
|
2675
|
+
if ('aggregate' === unit.kind && codeFiles.has(inMemoryDb)) {
|
|
2676
|
+
const section = new UnknownFormatNaming(plural(unit.name));
|
|
2677
|
+
const original = codeFiles.get(inMemoryDb);
|
|
2678
|
+
const content = withoutUnitImports(original.replace(new RegExp(`^[ \\t]*${escapeRegExp(section.variableName)}\\s*=\\s*this\\.section<[^\\n]*\\n?`, 'm'), ''), inMemoryDb);
|
|
2679
|
+
if (content !== original) cleaned.set(inMemoryDb, content);
|
|
2680
|
+
}
|
|
2681
|
+
if (parentAggregate) {
|
|
2682
|
+
const index = node_path.join(parentAggregate, 'index.ts');
|
|
2683
|
+
const original = codeFiles.get(index);
|
|
2684
|
+
if (void 0 !== original) {
|
|
2685
|
+
const content = withoutUnitImports(original, index);
|
|
2686
|
+
if (content !== original) cleaned.set(index, content);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
const ClassName = new UnknownFormatNaming(unit.name).ClassName;
|
|
2690
|
+
const namedImports = /import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*(['"])([^'"\n]+)\2/g;
|
|
2691
|
+
const usedBy = [];
|
|
2692
|
+
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
2693
|
+
for (const [file, original] of codeFiles){
|
|
2694
|
+
if (fileSet.has(file)) continue;
|
|
2695
|
+
const content = cleaned.get(file) ?? original;
|
|
2696
|
+
for (const [, , specifier] of content.matchAll(importSpecifier)){
|
|
2697
|
+
const target = resolved(specifier, file);
|
|
2698
|
+
if (target && isUnit(target)) usedBy.push([
|
|
2699
|
+
relative(file),
|
|
2700
|
+
relative(target)
|
|
2701
|
+
]);
|
|
2702
|
+
}
|
|
2703
|
+
for (const [, names, , specifier] of content.matchAll(namedImports)){
|
|
2704
|
+
const target = resolved(specifier, file);
|
|
2705
|
+
if (target && isParentBarrel(target) && new RegExp(`(?<![\\w$])${ClassName}(?![\\w$])`).test(names)) usedBy.push([
|
|
2706
|
+
relative(file),
|
|
2707
|
+
`${relative(target)} (${ClassName})`
|
|
2708
|
+
]);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
if (usedBy.length) return {
|
|
2712
|
+
usedBy
|
|
2713
|
+
};
|
|
2714
|
+
for (const file of files)new File(file).delete(rootFolderPath);
|
|
2715
|
+
for (const [file, content] of cleaned)new File(file).update(content);
|
|
2716
|
+
return {
|
|
2717
|
+
deleted: files,
|
|
2718
|
+
updated: [
|
|
2719
|
+
...cleaned.keys()
|
|
2720
|
+
]
|
|
2721
|
+
};
|
|
2722
|
+
};
|
|
2654
2723
|
const contractKinds = [
|
|
2655
2724
|
'aggregate',
|
|
2656
2725
|
'command',
|
|
@@ -2834,7 +2903,7 @@ const validateMove = (reactFolder, module, rawName)=>{
|
|
|
2834
2903
|
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
2835
2904
|
return true;
|
|
2836
2905
|
};
|
|
2837
|
-
const
|
|
2906
|
+
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
2838
2907
|
const { folders, folderName } = new NestedName(rawName);
|
|
2839
2908
|
return node_path.join(appFolder, ...folders, folderName);
|
|
2840
2909
|
};
|
|
@@ -2896,6 +2965,51 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
|
2896
2965
|
}
|
|
2897
2966
|
});
|
|
2898
2967
|
};
|
|
2968
|
+
const pageRouteFolder = (appFolder, page)=>{
|
|
2969
|
+
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
2970
|
+
const routePage = node_path.join(folder, 'page.tsx');
|
|
2971
|
+
return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
2972
|
+
};
|
|
2973
|
+
const reactModuleFiles = (module)=>{
|
|
2974
|
+
if ('widget' === module.kind) return walk(module.path);
|
|
2975
|
+
const folder = node_path.dirname(module.path);
|
|
2976
|
+
const own = new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`);
|
|
2977
|
+
return node_fs.readdirSync(folder, {
|
|
2978
|
+
withFileTypes: true
|
|
2979
|
+
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
|
|
2980
|
+
};
|
|
2981
|
+
const react_module_move_importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
2982
|
+
const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
2983
|
+
const moduleFiles = reactModuleFiles(module);
|
|
2984
|
+
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
2985
|
+
const own = new Set([
|
|
2986
|
+
...moduleFiles,
|
|
2987
|
+
...routeFileList
|
|
2988
|
+
]);
|
|
2989
|
+
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
2990
|
+
const isModule = (resolved)=>stems.has(resolved) || 'widget' === module.kind && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
|
|
2991
|
+
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
2992
|
+
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
2993
|
+
const usedBy = [];
|
|
2994
|
+
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(react_module_move_importSpecifier)){
|
|
2995
|
+
const target = resolve(specifier, file)?.resolved;
|
|
2996
|
+
if (target && isModule(target)) usedBy.push([
|
|
2997
|
+
relative(file),
|
|
2998
|
+
relative(target)
|
|
2999
|
+
]);
|
|
3000
|
+
}
|
|
3001
|
+
if (usedBy.length) return {
|
|
3002
|
+
usedBy
|
|
3003
|
+
};
|
|
3004
|
+
for (const file of moduleFiles)new File(file).delete(reactFolder);
|
|
3005
|
+
for (const file of routeFileList)new File(file).delete(route.appFolder);
|
|
3006
|
+
return {
|
|
3007
|
+
deleted: [
|
|
3008
|
+
...moduleFiles,
|
|
3009
|
+
...routeFileList
|
|
3010
|
+
]
|
|
3011
|
+
};
|
|
3012
|
+
};
|
|
2899
3013
|
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
2900
3014
|
if ('ports' === kind) return crossContext ? [
|
|
2901
3015
|
{
|
|
@@ -2910,6 +3024,108 @@ const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
|
2910
3024
|
}
|
|
2911
3025
|
] : [];
|
|
2912
3026
|
};
|
|
3027
|
+
const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
3028
|
+
const root = new ProjectRoot().path;
|
|
3029
|
+
const rootFolderPath = node_path.join(root, ConfigFile.Instance.data.project.rootFolder);
|
|
3030
|
+
const units = findBackendUnits(ownerFolder.path);
|
|
3031
|
+
if (!units.length) return void report('No modules generated by df-scaffold were found here.');
|
|
3032
|
+
const unit = await interaction_select({
|
|
3033
|
+
key: 'module',
|
|
3034
|
+
id: unitId,
|
|
3035
|
+
message: 'Module to delete:',
|
|
3036
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
3037
|
+
const group = units.filter((x)=>x.kind === kind);
|
|
3038
|
+
return group.length ? [
|
|
3039
|
+
new Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
3040
|
+
...group.map((value)=>({
|
|
3041
|
+
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3042
|
+
value
|
|
3043
|
+
}))
|
|
3044
|
+
] : [];
|
|
3045
|
+
}),
|
|
3046
|
+
pageSize: 20
|
|
3047
|
+
});
|
|
3048
|
+
const result = deleteBackendUnit(root, rootFolderPath, unit);
|
|
3049
|
+
if (result.usedBy) {
|
|
3050
|
+
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', 'Other files still use the module.', {
|
|
3051
|
+
usedBy: result.usedBy
|
|
3052
|
+
});
|
|
3053
|
+
report([
|
|
3054
|
+
'Nothing was deleted: these files still use it.',
|
|
3055
|
+
...result.usedBy.map(([file, used])=>` ${file} → ${used}`),
|
|
3056
|
+
'Remove those uses first (Wire dependency edits wiring; imports and constructor parameters are yours).'
|
|
3057
|
+
].join('\n'));
|
|
3058
|
+
return;
|
|
3059
|
+
}
|
|
3060
|
+
const relative = (file)=>node_path.relative(root, file);
|
|
3061
|
+
report([
|
|
3062
|
+
'Files to delete:',
|
|
3063
|
+
...result.deleted.map((file)=>` ${relative(file)}`),
|
|
3064
|
+
...result.updated.length ? [
|
|
3065
|
+
'Files to update:',
|
|
3066
|
+
...result.updated.map((file)=>` ${relative(file)}`)
|
|
3067
|
+
] : []
|
|
3068
|
+
].join('\n'));
|
|
3069
|
+
if (!await interaction_confirm({
|
|
3070
|
+
key: 'apply',
|
|
3071
|
+
message: 'Delete?',
|
|
3072
|
+
default: false
|
|
3073
|
+
})) {
|
|
3074
|
+
discardPendingChanges();
|
|
3075
|
+
report('Cancelled: nothing was deleted.');
|
|
3076
|
+
}
|
|
3077
|
+
};
|
|
3078
|
+
const deleteReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
3079
|
+
const reactFolder = presentationReactFolder.path;
|
|
3080
|
+
const modules = findReactModules(reactFolder, kind);
|
|
3081
|
+
if (!modules.length) return void report(`No ${kind}s generated by df-react were found.`);
|
|
3082
|
+
const module = await interaction_select({
|
|
3083
|
+
key: 'module',
|
|
3084
|
+
id: (value)=>value.name,
|
|
3085
|
+
message: 'page' === kind ? 'Page to delete:' : 'Widget to delete:',
|
|
3086
|
+
choices: modules.map((value)=>({
|
|
3087
|
+
name: value.name,
|
|
3088
|
+
value,
|
|
3089
|
+
description: node_path.relative(reactFolder, value.path)
|
|
3090
|
+
}))
|
|
3091
|
+
});
|
|
3092
|
+
const root = new ProjectRoot().path;
|
|
3093
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3094
|
+
const appFolder = node_path.join(root, nextAppFolder(root));
|
|
3095
|
+
const routeFolder = 'page' === kind && usesNext() ? pageRouteFolder(appFolder, module) : void 0;
|
|
3096
|
+
const withRoute = !!routeFolder && await interaction_confirm({
|
|
3097
|
+
key: 'deleteRoute',
|
|
3098
|
+
message: `Delete its Next.js route too: ${relative(routeFolder)}? Its URL stops working.`,
|
|
3099
|
+
default: true
|
|
3100
|
+
});
|
|
3101
|
+
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder ? {
|
|
3102
|
+
appFolder,
|
|
3103
|
+
folder: routeFolder
|
|
3104
|
+
} : void 0);
|
|
3105
|
+
if (result.usedBy) {
|
|
3106
|
+
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', `Other files still use the ${kind}.`, {
|
|
3107
|
+
usedBy: result.usedBy
|
|
3108
|
+
});
|
|
3109
|
+
report([
|
|
3110
|
+
'Nothing was deleted: these files still use it.',
|
|
3111
|
+
...result.usedBy.map(([file, used])=>` ${file} → ${used}`),
|
|
3112
|
+
'Remove those uses first.'
|
|
3113
|
+
].join('\n'));
|
|
3114
|
+
return;
|
|
3115
|
+
}
|
|
3116
|
+
report([
|
|
3117
|
+
'Files to delete:',
|
|
3118
|
+
...result.deleted.map((file)=>` ${relative(file)}`)
|
|
3119
|
+
].join('\n'));
|
|
3120
|
+
if (!await interaction_confirm({
|
|
3121
|
+
key: 'apply',
|
|
3122
|
+
message: 'Delete?',
|
|
3123
|
+
default: false
|
|
3124
|
+
})) {
|
|
3125
|
+
discardPendingChanges();
|
|
3126
|
+
report('Cancelled: nothing was deleted.');
|
|
3127
|
+
}
|
|
3128
|
+
};
|
|
2913
3129
|
const configurationSections = [
|
|
2914
3130
|
'project',
|
|
2915
3131
|
'backend',
|
|
@@ -3289,11 +3505,10 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3289
3505
|
const promptRouteMove = async (root, page, newName)=>{
|
|
3290
3506
|
if (!usesNext()) return;
|
|
3291
3507
|
const appFolder = node_path.join(root, nextAppFolder(root));
|
|
3292
|
-
const from =
|
|
3293
|
-
const to =
|
|
3508
|
+
const from = pageRouteFolder(appFolder, page);
|
|
3509
|
+
const to = react_module_move_routeFolder(appFolder, newName);
|
|
3294
3510
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3295
|
-
|
|
3296
|
-
if (from === to || !node_fs.existsSync(routePage) || !new RegExp(`\\b${page.ClassName}Page\\b`).test(node_fs.readFileSync(routePage, 'utf8'))) return;
|
|
3511
|
+
if (!from || from === to) return;
|
|
3297
3512
|
if (node_fs.existsSync(node_path.join(to, 'page.tsx'))) return void report(`${relative(to)}/page.tsx already exists: the route ${relative(from)} stays.`);
|
|
3298
3513
|
const move = await interaction_confirm({
|
|
3299
3514
|
key: 'moveRoute',
|
|
@@ -4579,4 +4794,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
4579
4794
|
break;
|
|
4580
4795
|
}
|
|
4581
4796
|
};
|
|
4582
|
-
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|
|
4797
|
+
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|
package/dist/561.js
CHANGED
|
@@ -3,7 +3,7 @@ import node_path from "node:path";
|
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
4
|
import zod from "zod";
|
|
5
5
|
import { implementationLabelSchema, discardPendingChanges, filesToOverwrite, ConfigFile, Folder, implementationKinds, ProjectRoot, pendingChanges } from "./870.js";
|
|
6
|
-
import { scaffoldNewHandlersRestEndpoint, addIntegration, findContracts, scaffoldNewAggregateUseCase, scaffoldNewInfrastructureService, scaffoldNewQuery, runWithAnswers, scaffoldNewCommand, moveBackendUnitUseCase, findReactModules, scaffoldReactUIKitComponent, scaffoldReactSharedHook, moveReactModuleUseCase, integrationIds, scaffoldNewImplementation, scaffoldNewApplicationService, savedImplementations, RequestError, moduleId, assertAnswersConsumed, scaffoldNewDomainService, findRestEndpointGenerator, scaffoldNewErrorUseCase, scaffoldReactWidget, savePendingChanges, systemImplementationChoices, unitId, scaffoldReactPage, scaffoldNewPresentationService, findBackendUnits, scaffoldNewUseCase, integrationDescriptions, wireDependency, scaffoldNewDomainObject, scaffoldNewBoundedContextUseCase, scaffoldNewApplicationPort } from "./287.js";
|
|
6
|
+
import { scaffoldNewHandlersRestEndpoint, addIntegration, findContracts, scaffoldNewAggregateUseCase, scaffoldNewInfrastructureService, scaffoldNewQuery, runWithAnswers, scaffoldNewCommand, moveBackendUnitUseCase, findReactModules, scaffoldReactUIKitComponent, scaffoldReactSharedHook, moveReactModuleUseCase, deleteBackendUnitUseCase, integrationIds, scaffoldNewImplementation, scaffoldNewApplicationService, savedImplementations, RequestError, deleteReactModuleUseCase, moduleId, assertAnswersConsumed, scaffoldNewDomainService, findRestEndpointGenerator, scaffoldNewErrorUseCase, scaffoldReactWidget, savePendingChanges, systemImplementationChoices, unitId, scaffoldReactPage, scaffoldNewPresentationService, findBackendUnits, scaffoldNewUseCase, integrationDescriptions, wireDependency, scaffoldNewDomainObject, scaffoldNewBoundedContextUseCase, scaffoldNewApplicationPort } from "./287.js";
|
|
7
7
|
import { findWiredModules, availableDependencies, hasNeighboringBoundedContext } from "./201.js";
|
|
8
8
|
const agent_requests_name = implementationLabelSchema;
|
|
9
9
|
const nestedName = zod.string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*(?:\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*)*$/);
|
|
@@ -122,6 +122,11 @@ const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
|
|
|
122
122
|
module: id.describe('Exact wiring target ID, including implementation class, from --describe.'),
|
|
123
123
|
dependencies: dependencies
|
|
124
124
|
}),
|
|
125
|
+
operation('delete', {
|
|
126
|
+
...common,
|
|
127
|
+
...agent_requests_owner,
|
|
128
|
+
module: id.describe('Exact unit ID from --describe. Refused while other files use it.')
|
|
129
|
+
}),
|
|
125
130
|
operation('move', {
|
|
126
131
|
...common,
|
|
127
132
|
...agent_requests_owner,
|
|
@@ -159,6 +164,15 @@ const reactRequestSchema = zod.discriminatedUnion('operation', [
|
|
|
159
164
|
name: nestedName,
|
|
160
165
|
moveRoute: zod.boolean().optional().describe('With Next.js and a route at the page path: move it too (default true). Omit it without such a route.')
|
|
161
166
|
}),
|
|
167
|
+
operation('delete-page', {
|
|
168
|
+
...common,
|
|
169
|
+
module: nestedName,
|
|
170
|
+
deleteRoute: zod.boolean().optional().describe("With Next.js and the page's own route: delete it too (default true). Omit it without such a route.")
|
|
171
|
+
}),
|
|
172
|
+
operation('delete-widget', {
|
|
173
|
+
...common,
|
|
174
|
+
module: nestedName
|
|
175
|
+
}),
|
|
162
176
|
operation('move-widget', {
|
|
163
177
|
...common,
|
|
164
178
|
module: nestedName,
|
|
@@ -363,7 +377,7 @@ const executeScaffold = async (request, owner)=>{
|
|
|
363
377
|
'errors'
|
|
364
378
|
]).content.fileNames.includes(request.namespace)) throw new RequestError('TARGET_NOT_FOUND', `Unknown namespace: ${request.namespace}.`);
|
|
365
379
|
if ('implementation' === request.operation && !findContracts(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No contracts in this context.');
|
|
366
|
-
if ('move' === request.operation && !findBackendUnits(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No modules in this context.');
|
|
380
|
+
if (('move' === request.operation || 'delete' === request.operation) && !findBackendUnits(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No modules in this context.');
|
|
367
381
|
if ('wire-dependency' === request.operation && (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') || !findWiredModules(owner.path).length)) throw new RequestError('TARGET_NOT_FOUND', 'No wired modules in this context.');
|
|
368
382
|
if ('endpoint' === request.operation) {
|
|
369
383
|
if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers-rest') || !findRestEndpointGenerator(new Folder(requireProject()).subitem([
|
|
@@ -392,7 +406,8 @@ const executeScaffold = async (request, owner)=>{
|
|
|
392
406
|
implementation: ()=>scaffoldNewImplementation(owner),
|
|
393
407
|
endpoint: ()=>scaffoldNewHandlersRestEndpoint(owner),
|
|
394
408
|
'wire-dependency': ()=>wireDependency(owner),
|
|
395
|
-
move: ()=>moveBackendUnitUseCase(owner)
|
|
409
|
+
move: ()=>moveBackendUnitUseCase(owner),
|
|
410
|
+
delete: ()=>deleteBackendUnitUseCase(owner)
|
|
396
411
|
};
|
|
397
412
|
return actions[request.operation]();
|
|
398
413
|
};
|
|
@@ -401,14 +416,16 @@ const executeReact = async (request)=>{
|
|
|
401
416
|
ConfigFile.Instance.data.project.rootFolder,
|
|
402
417
|
'presentation/react'
|
|
403
418
|
]);
|
|
404
|
-
if (request.operation
|
|
419
|
+
if (/^(move|delete)-/.test(request.operation) && !findReactModules(folder.path, request.operation.endsWith('-page') ? 'page' : 'widget').length) throw new RequestError('TARGET_NOT_FOUND', `No React ${request.operation.endsWith('-page') ? 'pages' : 'widgets'} here.`);
|
|
405
420
|
const actions = {
|
|
406
421
|
page: ()=>scaffoldReactPage(folder),
|
|
407
422
|
widget: ()=>scaffoldReactWidget(folder),
|
|
408
423
|
'ui-kit-component': ()=>scaffoldReactUIKitComponent(folder),
|
|
409
424
|
'shared-hook': ()=>scaffoldReactSharedHook(folder),
|
|
410
425
|
'move-page': ()=>moveReactModuleUseCase(folder, 'page'),
|
|
411
|
-
'move-widget': ()=>moveReactModuleUseCase(folder, 'widget')
|
|
426
|
+
'move-widget': ()=>moveReactModuleUseCase(folder, 'widget'),
|
|
427
|
+
'delete-page': ()=>deleteReactModuleUseCase(folder, 'page'),
|
|
428
|
+
'delete-widget': ()=>deleteReactModuleUseCase(folder, 'widget')
|
|
412
429
|
};
|
|
413
430
|
return actions[request.operation]();
|
|
414
431
|
};
|
package/dist/agent-cli.d.ts
CHANGED
|
@@ -183,6 +183,12 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
|
|
|
183
183
|
context: z.ZodString;
|
|
184
184
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
185
185
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
186
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
187
|
+
operation: z.ZodLiteral<"delete">;
|
|
188
|
+
module: z.ZodString;
|
|
189
|
+
context: z.ZodString;
|
|
190
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
191
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
186
192
|
}, z.core.$strict>, z.ZodObject<{
|
|
187
193
|
operation: z.ZodLiteral<"move">;
|
|
188
194
|
module: z.ZodString;
|
|
@@ -224,6 +230,17 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
|
|
|
224
230
|
moveRoute: z.ZodOptional<z.ZodBoolean>;
|
|
225
231
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
226
232
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
233
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
234
|
+
operation: z.ZodLiteral<"delete-page">;
|
|
235
|
+
module: z.ZodString;
|
|
236
|
+
deleteRoute: z.ZodOptional<z.ZodBoolean>;
|
|
237
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
238
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
239
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
240
|
+
operation: z.ZodLiteral<"delete-widget">;
|
|
241
|
+
module: z.ZodString;
|
|
242
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
243
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
227
244
|
}, z.core.$strict>, z.ZodObject<{
|
|
228
245
|
operation: z.ZodLiteral<"move-widget">;
|
|
229
246
|
module: z.ZodString;
|
package/dist/agent-requests.d.ts
CHANGED
|
@@ -161,6 +161,12 @@ export declare const scaffoldRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject
|
|
|
161
161
|
context: z.ZodString;
|
|
162
162
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
163
163
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
164
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
165
|
+
operation: z.ZodLiteral<"delete">;
|
|
166
|
+
module: z.ZodString;
|
|
167
|
+
context: z.ZodString;
|
|
168
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
169
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
164
170
|
}, z.core.$strict>, z.ZodObject<{
|
|
165
171
|
operation: z.ZodLiteral<"move">;
|
|
166
172
|
module: z.ZodString;
|
|
@@ -203,6 +209,17 @@ export declare const reactRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
203
209
|
moveRoute: z.ZodOptional<z.ZodBoolean>;
|
|
204
210
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
205
211
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
212
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
213
|
+
operation: z.ZodLiteral<"delete-page">;
|
|
214
|
+
module: z.ZodString;
|
|
215
|
+
deleteRoute: z.ZodOptional<z.ZodBoolean>;
|
|
216
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
217
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
218
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
219
|
+
operation: z.ZodLiteral<"delete-widget">;
|
|
220
|
+
module: z.ZodString;
|
|
221
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
222
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
206
223
|
}, z.core.$strict>, z.ZodObject<{
|
|
207
224
|
operation: z.ZodLiteral<"move-widget">;
|
|
208
225
|
module: z.ZodString;
|
|
@@ -407,6 +424,12 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
|
|
|
407
424
|
context: z.ZodString;
|
|
408
425
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
409
426
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
427
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
428
|
+
operation: z.ZodLiteral<"delete">;
|
|
429
|
+
module: z.ZodString;
|
|
430
|
+
context: z.ZodString;
|
|
431
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
432
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
410
433
|
}, z.core.$strict>, z.ZodObject<{
|
|
411
434
|
operation: z.ZodLiteral<"move">;
|
|
412
435
|
module: z.ZodString;
|
|
@@ -448,6 +471,17 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
|
|
|
448
471
|
moveRoute: z.ZodOptional<z.ZodBoolean>;
|
|
449
472
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
450
473
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
474
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
475
|
+
operation: z.ZodLiteral<"delete-page">;
|
|
476
|
+
module: z.ZodString;
|
|
477
|
+
deleteRoute: z.ZodOptional<z.ZodBoolean>;
|
|
478
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
479
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
480
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
481
|
+
operation: z.ZodLiteral<"delete-widget">;
|
|
482
|
+
module: z.ZodString;
|
|
483
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
484
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
451
485
|
}, z.core.$strict>, z.ZodObject<{
|
|
452
486
|
operation: z.ZodLiteral<"move-widget">;
|
|
453
487
|
module: z.ZodString;
|
|
@@ -51,4 +51,20 @@ export type BackendMoveResult = {
|
|
|
51
51
|
* are returned instead, with paths after the move.
|
|
52
52
|
*/
|
|
53
53
|
export declare const moveBackendUnit: (projectRoot: string, rootFolderPath: string, unit: BackendUnit, target: UnitPlace) => BackendMoveResult;
|
|
54
|
+
export type BackendDeleteResult = {
|
|
55
|
+
/** Files outside the unit that still import it: [file, import]. */
|
|
56
|
+
usedBy: [string, string][];
|
|
57
|
+
} | {
|
|
58
|
+
deleted: string[];
|
|
59
|
+
updated: string[];
|
|
60
|
+
usedBy?: undefined;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Stages the deletion of a unit: every file of it (an aggregate with its
|
|
64
|
+
* whole folder). What the generators added for it elsewhere goes too: an
|
|
65
|
+
* entity's re-export in its aggregate's barrel, an aggregate's in-memory
|
|
66
|
+
* DB section. Nothing is staged while other files still import the unit;
|
|
67
|
+
* those imports are returned instead.
|
|
68
|
+
*/
|
|
69
|
+
export declare const deleteBackendUnit: (projectRoot: string, rootFolderPath: string, unit: BackendUnit) => BackendDeleteResult;
|
|
54
70
|
export {};
|