@domain-first/project-structure 8.1.1 → 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 +17 -2
- package/dist/201.js +1 -1
- package/dist/287.js +278 -9
- package/dist/38.js +268 -0
- 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/graph.cjs +933 -0
- package/dist/graph.d.ts +2 -0
- package/dist/graph.js +337 -0
- package/dist/index.cjs +300 -12
- package/dist/index.js +4 -2
- package/dist/init.cjs +111 -57
- package/dist/integration.cjs +297 -11
- package/dist/interaction.d.ts +9 -0
- package/dist/interaction.spec.d.ts +1 -0
- package/dist/lint.js +8 -273
- package/dist/project-graph.d.ts +53 -0
- package/dist/project-graph.spec.d.ts +1 -0
- package/dist/project-lint.d.ts +10 -0
- package/dist/react-module-move.d.ts +21 -0
- package/dist/react.cjs +304 -12
- 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 +3 -2
- package/skills/df-ps-plan-feature/SKILL.md +2 -0
- 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/dist/38.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { canDependOn, namedImportFiles, isCrossContextImplementation, findWiredModules, moduleKindOf, readWiredModule, crossContextImportAllowed, compilerOption, wiredDependencyNames } from "./201.js";
|
|
4
|
+
import { defaultDependencyRules, fileModuleKind } from "./870.js";
|
|
5
|
+
const readAliases = (projectRoot)=>{
|
|
6
|
+
const tsconfig = node_path.join(projectRoot, 'tsconfig.json');
|
|
7
|
+
const paths = compilerOption(tsconfig, 'paths');
|
|
8
|
+
if (!paths || 'object' != typeof paths) return [];
|
|
9
|
+
const baseUrl = compilerOption(tsconfig, 'baseUrl');
|
|
10
|
+
const base = node_path.resolve(projectRoot, 'string' == typeof baseUrl ? baseUrl : '.');
|
|
11
|
+
return Object.entries(paths).filter(([, targets])=>targets.length).map(([key, [target]])=>{
|
|
12
|
+
const wildcard = key.endsWith('*');
|
|
13
|
+
return {
|
|
14
|
+
prefix: wildcard ? key.slice(0, -1) : key,
|
|
15
|
+
wildcard,
|
|
16
|
+
target: node_path.resolve(base, wildcard ? target.replace(/\*$/, '') : target)
|
|
17
|
+
};
|
|
18
|
+
}).sort((a, b)=>b.prefix.length - a.prefix.length);
|
|
19
|
+
};
|
|
20
|
+
const resolveSpecifier = (specifier, fromFile, aliases)=>{
|
|
21
|
+
if (specifier.startsWith('.')) return node_path.resolve(node_path.dirname(fromFile), specifier);
|
|
22
|
+
for (const { prefix, wildcard, target } of aliases)if (wildcard ? specifier.startsWith(prefix) : specifier === prefix) return node_path.join(target, wildcard ? specifier.slice(prefix.length) : '');
|
|
23
|
+
};
|
|
24
|
+
const inside = (folder, file)=>{
|
|
25
|
+
const relativePath = node_path.relative(folder, file);
|
|
26
|
+
return !relativePath || relativePath.startsWith('..') || node_path.isAbsolute(relativePath) ? void 0 : relativePath.split(node_path.sep);
|
|
27
|
+
};
|
|
28
|
+
const sourceFiles = (folder)=>{
|
|
29
|
+
if (!node_fs.existsSync(folder)) return [];
|
|
30
|
+
return node_fs.readdirSync(folder, {
|
|
31
|
+
withFileTypes: true
|
|
32
|
+
}).flatMap((entry)=>{
|
|
33
|
+
const entryPath = node_path.join(folder, entry.name);
|
|
34
|
+
if (entry.isDirectory()) return 'node_modules' === entry.name ? [] : sourceFiles(entryPath);
|
|
35
|
+
return /\.(c|m)?tsx?$/.test(entry.name) && !entry.name.endsWith('.d.ts') ? [
|
|
36
|
+
entryPath
|
|
37
|
+
] : [];
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const importPattern = /\b(?:(import|export)\s+(type\s+)?(?:(?!\b(?:import|export)\b)[\w*{}\s,$])*?\s*from\s*|import\s*\(\s*|require\s*\(\s*|import\s*)(['"])([^'"\n]+)\3/g;
|
|
41
|
+
const lineAt = (source, index)=>source.slice(0, index).split('\n').length;
|
|
42
|
+
const importsOf = (source, file, aliases)=>[
|
|
43
|
+
...source.matchAll(importPattern)
|
|
44
|
+
].map((match)=>({
|
|
45
|
+
typeOnly: 'import' === match[1] && Boolean(match[2]),
|
|
46
|
+
target: resolveSpecifier(match[4], file, aliases),
|
|
47
|
+
line: lineAt(source, match.index),
|
|
48
|
+
statement: match[0].replace(/\s+/g, ' ')
|
|
49
|
+
}));
|
|
50
|
+
const isSpec = (file)=>/\.(spec|test)\.(c|m)?tsx?$/.test(file);
|
|
51
|
+
const layerImportRules = {
|
|
52
|
+
domain: {
|
|
53
|
+
allows: ([layer])=>'domain' === layer,
|
|
54
|
+
rule: 'domain imports outside the domain layer:'
|
|
55
|
+
},
|
|
56
|
+
application: {
|
|
57
|
+
allows: ([layer])=>'domain' === layer || 'application' === layer,
|
|
58
|
+
rule: 'application imports outside domain and application:'
|
|
59
|
+
},
|
|
60
|
+
infrastructure: {
|
|
61
|
+
allows: ([layer, part])=>'domain' === layer || 'infrastructure' === layer || 'application' === layer && ('ports' === part || 'commands' === part || 'queries' === part),
|
|
62
|
+
rule: 'infrastructure imports outside domain, infrastructure, application ports and command and query contracts:'
|
|
63
|
+
},
|
|
64
|
+
presentation: {
|
|
65
|
+
allows: ([layer])=>'infrastructure' !== layer,
|
|
66
|
+
rule: 'presentation imports infrastructure (only wiring knows concrete classes):'
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const baseName = (file)=>node_path.basename(file).replace(/\.[^.]+$/, '');
|
|
70
|
+
const isOwnContract = (file, target)=>baseName(file).endsWith(`-${baseName(target)}`);
|
|
71
|
+
const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
72
|
+
const root = node_path.resolve(projectRoot, rootFolder);
|
|
73
|
+
const contextsFolder = node_path.join(root, 'bounded-contexts');
|
|
74
|
+
const sharedFolder = node_path.join(root, 'shared-kernel');
|
|
75
|
+
const reactFolder = node_path.join(root, 'presentation', 'react');
|
|
76
|
+
const uiKitFolder = node_path.join(reactFolder, 'ui-kit');
|
|
77
|
+
const widgetsFolder = node_path.join(reactFolder, 'widgets');
|
|
78
|
+
const hooksFolder = node_path.join(reactFolder, 'hooks');
|
|
79
|
+
const inMemoryDbFile = node_path.join(sharedFolder, 'infrastructure', 'services', 'in-memory-db-infrastructure-service.ts');
|
|
80
|
+
const aliases = readAliases(projectRoot);
|
|
81
|
+
const violations = [];
|
|
82
|
+
const locate = (file)=>{
|
|
83
|
+
const inContext = inside(contextsFolder, file);
|
|
84
|
+
if (inContext && inContext.length > 1) {
|
|
85
|
+
const [owner, ...segments] = inContext;
|
|
86
|
+
return {
|
|
87
|
+
owner,
|
|
88
|
+
segments
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const inShared = inside(sharedFolder, file);
|
|
92
|
+
return inShared && {
|
|
93
|
+
owner: 'shared-kernel',
|
|
94
|
+
segments: inShared
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const isDomainModel = ([layer, part], target)=>'domain' === layer && [
|
|
98
|
+
'aggregates',
|
|
99
|
+
'entities',
|
|
100
|
+
'value-objects'
|
|
101
|
+
].includes(part) && !/-repository(\.tsx?)?$/.test(node_path.basename(target));
|
|
102
|
+
const widgetFolders = new Map();
|
|
103
|
+
const isWidgetFolder = (folder)=>{
|
|
104
|
+
if (!widgetFolders.has(folder)) widgetFolders.set(folder, node_fs.existsSync(folder) && node_fs.statSync(folder).isDirectory() && node_fs.readdirSync(folder).some((name)=>name.endsWith('-widget.tsx')));
|
|
105
|
+
return widgetFolders.get(folder);
|
|
106
|
+
};
|
|
107
|
+
const widgetOf = (file)=>{
|
|
108
|
+
for(let folder = file; inside(widgetsFolder, folder); folder = node_path.dirname(folder))if (isWidgetFolder(folder)) return folder;
|
|
109
|
+
};
|
|
110
|
+
const files = [
|
|
111
|
+
contextsFolder,
|
|
112
|
+
sharedFolder,
|
|
113
|
+
reactFolder
|
|
114
|
+
].flatMap(sourceFiles);
|
|
115
|
+
for (const file of files){
|
|
116
|
+
const source = node_fs.readFileSync(file, 'utf8');
|
|
117
|
+
const from = locate(file);
|
|
118
|
+
const ownContext = inside(contextsFolder, file)?.[0];
|
|
119
|
+
const directWiring = ownContext && from?.segments[0] === 'wiring' && readWiredModule(file, node_path.join(contextsFolder, ownContext))?.implementations.some((implementation)=>isCrossContextImplementation(implementation.file));
|
|
120
|
+
const report = (check, rule, imported)=>violations.push({
|
|
121
|
+
check,
|
|
122
|
+
rule,
|
|
123
|
+
file,
|
|
124
|
+
line: imported.line,
|
|
125
|
+
text: imported.statement
|
|
126
|
+
});
|
|
127
|
+
for (const imported of importsOf(source, file, aliases)){
|
|
128
|
+
const target = imported.target;
|
|
129
|
+
if (!target) continue;
|
|
130
|
+
const to = locate(target);
|
|
131
|
+
const targetContext = inside(contextsFolder, target)?.[0];
|
|
132
|
+
const crossContextAllowed = true === crossContextImportAllowed(file, target) && (from?.segments[0] !== 'wiring' || directWiring);
|
|
133
|
+
if (ownContext) {
|
|
134
|
+
if (targetContext && targetContext !== ownContext && !crossContextAllowed) report('context-isolation', `[${ownContext}] imports another context:`, imported);
|
|
135
|
+
} else if (inside(sharedFolder, file)) {
|
|
136
|
+
const allowed = !to || 'shared-kernel' === to.owner || 'domain' === to.segments[0] && 'errors' === to.segments[1] || file === inMemoryDbFile && isDomainModel(to.segments, target);
|
|
137
|
+
if (!allowed) report('shared-kernel', '[shared-kernel] imports a bounded context outside its domain/errors (and domain models for the in-memory DB):', imported);
|
|
138
|
+
} else if (inside(uiKitFolder, file) || inside(hooksFolder, file)) {
|
|
139
|
+
const [area] = inside(reactFolder, target) ?? [];
|
|
140
|
+
const forbidden = inside(uiKitFolder, file) ? [
|
|
141
|
+
'widgets',
|
|
142
|
+
'pages'
|
|
143
|
+
] : [
|
|
144
|
+
'ui-kit',
|
|
145
|
+
'widgets',
|
|
146
|
+
'pages'
|
|
147
|
+
];
|
|
148
|
+
if (targetContext || forbidden.includes(area)) report('react', inside(uiKitFolder, file) ? '[presentation/react/ui-kit] imports a bounded context, widget or page:' : '[presentation/react/hooks] a shared hook imports a bounded context, UI-kit, widget or page:', imported);
|
|
149
|
+
} else if (targetContext && !(imported.typeOnly && to?.segments[0] === 'presentation' && 'rest' === to.segments[1])) report('react', '[presentation/react] imports a context other than `import type` from presentation/rest:', imported);
|
|
150
|
+
const ownWidget = widgetOf(file);
|
|
151
|
+
const targetWidget = widgetOf(target);
|
|
152
|
+
if (ownWidget && targetWidget && targetWidget !== ownWidget) report('react', '[presentation/react/widgets] a widget imports another widget:', imported);
|
|
153
|
+
if (!from || !to) continue;
|
|
154
|
+
if (crossContextAllowed) continue;
|
|
155
|
+
if (isSpec(file)) continue;
|
|
156
|
+
const fromKind = fileModuleKind(from.segments);
|
|
157
|
+
const toKind = fileModuleKind(to.segments);
|
|
158
|
+
if (fromKind && toKind) {
|
|
159
|
+
if (!rules[fromKind].has(toKind) && !(fromKind === toKind && isOwnContract(file, target))) report('dependencies', `[${from.owner}] ${fromKind} may not use ${toKind} (dependency rules):`, imported);
|
|
160
|
+
if ('infrastructure' !== to.segments[0]) continue;
|
|
161
|
+
}
|
|
162
|
+
const layerRule = layerImportRules[from.segments[0]];
|
|
163
|
+
if (layerRule && !layerRule.allows(to.segments)) report('layers', `[${from.owner}] ${layerRule.rule}`, imported);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return violations;
|
|
167
|
+
};
|
|
168
|
+
const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
169
|
+
const root = node_path.resolve(projectRoot, rootFolder);
|
|
170
|
+
const sharedFolder = node_path.join(root, 'shared-kernel');
|
|
171
|
+
const contextsFolder = node_path.join(root, 'bounded-contexts');
|
|
172
|
+
const sharedModules = findWiredModules(sharedFolder);
|
|
173
|
+
const owners = [
|
|
174
|
+
{
|
|
175
|
+
name: 'shared-kernel',
|
|
176
|
+
modules: sharedModules
|
|
177
|
+
},
|
|
178
|
+
...node_fs.existsSync(contextsFolder) ? node_fs.readdirSync(contextsFolder, {
|
|
179
|
+
withFileTypes: true
|
|
180
|
+
}).filter((entry)=>entry.isDirectory()).map((entry)=>({
|
|
181
|
+
name: entry.name,
|
|
182
|
+
modules: findWiredModules(node_path.join(contextsFolder, entry.name))
|
|
183
|
+
})) : []
|
|
184
|
+
];
|
|
185
|
+
const violations = [];
|
|
186
|
+
const allModules = new Map(owners.flatMap(({ modules })=>modules).map((module)=>[
|
|
187
|
+
module.wireFile,
|
|
188
|
+
module
|
|
189
|
+
]));
|
|
190
|
+
const aliases = readAliases(projectRoot);
|
|
191
|
+
for (const { name, modules } of owners){
|
|
192
|
+
const visible = new Map([
|
|
193
|
+
...sharedModules,
|
|
194
|
+
...modules
|
|
195
|
+
].map((x)=>[
|
|
196
|
+
x.wireName,
|
|
197
|
+
x
|
|
198
|
+
]));
|
|
199
|
+
for (const consumer of modules){
|
|
200
|
+
const source = node_fs.readFileSync(consumer.wireFile, 'utf8');
|
|
201
|
+
const imported = namedImportFiles(source, consumer.wireFile, (specifier, file)=>resolveSpecifier(specifier, file, aliases));
|
|
202
|
+
for (const implementation of consumer.implementations){
|
|
203
|
+
let dependencies;
|
|
204
|
+
try {
|
|
205
|
+
dependencies = wiredDependencyNames(source, implementation.className);
|
|
206
|
+
} catch {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const listStart = source.search(new RegExp(`wireClass\\(\\s*${implementation.className}\\b`));
|
|
210
|
+
for (const dependency of dependencies){
|
|
211
|
+
const target = imported.get(dependency);
|
|
212
|
+
const candidate = (target ? allModules.get(target) : void 0) ?? visible.get(dependency);
|
|
213
|
+
if (!candidate || canDependOn(consumer, candidate, rules, implementation)) continue;
|
|
214
|
+
const index = source.indexOf(dependency, listStart);
|
|
215
|
+
violations.push({
|
|
216
|
+
check: 'dependencies',
|
|
217
|
+
rule: `[${name}] wiring: a dependency the dependency rules don't allow:`,
|
|
218
|
+
file: consumer.wireFile,
|
|
219
|
+
line: lineAt(source, index),
|
|
220
|
+
text: `${implementation.className} (${moduleKindOf(consumer) ?? consumer.kind}) ← ${candidate.typeName} (${moduleKindOf(candidate) ?? candidate.kind})`
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return violations;
|
|
227
|
+
};
|
|
228
|
+
const clockViolations = (projectRoot, rootFolder)=>{
|
|
229
|
+
const root = node_path.resolve(projectRoot, rootFolder);
|
|
230
|
+
const folders = [
|
|
231
|
+
node_path.join(root, 'shared-kernel'),
|
|
232
|
+
...node_fs.existsSync(node_path.join(root, 'bounded-contexts')) ? node_fs.readdirSync(node_path.join(root, 'bounded-contexts')).map((name)=>node_path.join(root, 'bounded-contexts', name)) : []
|
|
233
|
+
].flatMap((folder)=>[
|
|
234
|
+
node_path.join(folder, 'domain'),
|
|
235
|
+
node_path.join(folder, 'application')
|
|
236
|
+
]);
|
|
237
|
+
return folders.flatMap(sourceFiles).filter((file)=>!isSpec(file)).flatMap((file)=>{
|
|
238
|
+
const source = node_fs.readFileSync(file, 'utf8');
|
|
239
|
+
return [
|
|
240
|
+
...source.matchAll(/\bnew\s+Date\s*\(\s*\)|\bDate\.now\s*\(/g)
|
|
241
|
+
].map((match)=>({
|
|
242
|
+
check: 'clock',
|
|
243
|
+
rule: 'domain or application reads the current time directly (use the clock port):',
|
|
244
|
+
file,
|
|
245
|
+
line: lineAt(source, match.index),
|
|
246
|
+
text: match[0]
|
|
247
|
+
}));
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
const lintProject = (projectRoot, rootFolder, { rules = defaultDependencyRules, checks = {} } = {})=>[
|
|
251
|
+
...importViolations(projectRoot, rootFolder, rules),
|
|
252
|
+
...wiringViolations(projectRoot, rootFolder, rules),
|
|
253
|
+
...clockViolations(projectRoot, rootFolder)
|
|
254
|
+
].filter((x)=>false !== checks[x.check]);
|
|
255
|
+
const formatViolations = (violations, projectRoot)=>{
|
|
256
|
+
const groups = new Map();
|
|
257
|
+
for (const { rule, file, line, text } of violations)groups.set(rule, [
|
|
258
|
+
...groups.get(rule) ?? [],
|
|
259
|
+
` ${node_path.relative(projectRoot, file)}:${line}: ${text}`
|
|
260
|
+
]);
|
|
261
|
+
return [
|
|
262
|
+
...groups
|
|
263
|
+
].map(([rule, lines])=>[
|
|
264
|
+
rule,
|
|
265
|
+
...lines
|
|
266
|
+
].join('\n')).join('\n\n');
|
|
267
|
+
};
|
|
268
|
+
export { formatViolations, lintProject, readAliases, resolveSpecifier };
|
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 {};
|