@domain-first/project-structure 7.2.0 → 8.0.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 +124 -25
- package/dist/201.js +87 -338
- package/dist/287.js +1183 -568
- package/dist/561.js +518 -0
- package/dist/711.js +22 -0
- package/dist/870.js +438 -0
- package/dist/agent-cli.d.ts +378 -0
- package/dist/agent-cli.spec.d.ts +1 -0
- package/dist/agent-identifiers.d.ts +4 -0
- package/dist/agent-requests.d.ts +488 -0
- package/dist/config-file.d.ts +231 -26
- package/dist/config-file.spec.d.ts +1 -0
- package/dist/context-dependencies.d.ts +16 -0
- package/dist/dependency-rules.d.ts +17 -17
- package/dist/file-system.d.ts +10 -1
- package/dist/implementation-choices.d.ts +8 -0
- package/dist/implementation-choices.spec.d.ts +1 -0
- package/dist/implementation-options-schema.d.ts +14 -0
- package/dist/index.cjs +3598 -583
- package/dist/index.js +20 -7
- package/dist/init.cjs +717 -122
- package/dist/init.js +24 -12
- package/dist/integration.cjs +3737 -186
- package/dist/integration.js +29 -17
- package/dist/integrations/rest-endpoint-generator.d.ts +4 -2
- package/dist/integrations/storybook.d.ts +1 -0
- package/dist/interaction.d.ts +41 -0
- package/dist/lint.cjs +165 -41
- package/dist/lint.js +22 -7
- package/dist/next-app.d.ts +7 -0
- package/dist/react.cjs +5128 -414
- package/dist/react.js +72 -60
- package/dist/system-implementations.d.ts +6 -0
- package/dist/upgrade-steps.d.ts +81 -0
- package/dist/upgrade-steps.spec.d.ts +1 -0
- package/dist/upgrade.cjs +593 -0
- package/dist/upgrade.d.ts +2 -0
- package/dist/upgrade.js +235 -0
- package/dist/use-cases/add-integration.d.ts +16 -1
- package/dist/use-cases/cross-context-dependencies.spec.d.ts +1 -0
- package/dist/use-cases/initialize.d.ts +4 -4
- package/dist/use-cases/initialize.spec.d.ts +1 -0
- package/dist/use-cases/prompt-implementation-type.d.ts +20 -0
- package/dist/use-cases/scaffold-react-page.d.ts +3 -1
- package/dist/wire-branches.d.ts +26 -0
- package/dist/wiring.d.ts +3 -2
- package/package.json +3 -2
- package/skills/df-ps-implement/SKILL.md +9 -8
- package/skills/df-ps-plan-feature/SKILL.md +8 -7
- package/skills/df-ps-react/SKILL.md +13 -7
- package/skills/df-ps-react/references/generators.md +6 -2
- package/skills/df-ps-scaffold/SKILL.md +28 -17
- package/skills/df-ps-scaffold/references/agent-mode.md +72 -0
- package/skills/df-ps-scaffold/references/agent-operations.md +155 -0
- package/skills/df-ps-scaffold/references/choosing-components.md +13 -13
- package/skills/df-ps-scaffold/references/generators.md +20 -3
- package/skills/df-ps-scaffold/references/units/aggregate.md +4 -3
- package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
- package/skills/df-ps-scaffold/references/units/command-query.md +12 -12
- package/skills/df-ps-scaffold/references/units/implementation.md +2 -2
- package/skills/df-ps-scaffold/references/units/move-or-rename.md +1 -1
- package/skills/df-ps-scaffold/references/units/port.md +7 -4
- package/skills/df-ps-scaffold/references/units/use-case.md +1 -1
- package/skills/df-ps-scaffold/scripts/drive.mjs +9 -1
package/dist/561.js
ADDED
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import zod from "zod";
|
|
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";
|
|
7
|
+
import { findWiredModules, availableDependencies, hasNeighboringBoundedContext } from "./201.js";
|
|
8
|
+
const agent_requests_name = implementationLabelSchema;
|
|
9
|
+
const nestedName = zod.string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*(?:\/[a-z][a-z0-9]*(?:-[a-z0-9]+)*)*$/);
|
|
10
|
+
const id = zod.string().min(1);
|
|
11
|
+
const agent_requests_implementation = zod.strictObject({
|
|
12
|
+
type: agent_requests_name,
|
|
13
|
+
save: zod.boolean().optional().describe('Remember this ordinary type for future runs. Default: false.')
|
|
14
|
+
});
|
|
15
|
+
const dependencies = zod.record(zod.string().regex(/^[A-Z][A-Za-z0-9]*$/), zod.array(id)).describe('Implementation/class name -> exact module IDs from --describe. Omitted entries keep suggested dependencies; [] selects none.');
|
|
16
|
+
const common = {
|
|
17
|
+
overwrite: zod.boolean().optional(),
|
|
18
|
+
dryRun: zod.boolean().optional()
|
|
19
|
+
};
|
|
20
|
+
const agent_requests_owner = {
|
|
21
|
+
context: agent_requests_name.describe('A bounded-context name, or shared-kernel.')
|
|
22
|
+
};
|
|
23
|
+
const wired = {
|
|
24
|
+
dependencies: dependencies.optional()
|
|
25
|
+
};
|
|
26
|
+
const implementations = {
|
|
27
|
+
implementation: agent_requests_implementation,
|
|
28
|
+
testImplementation: agent_requests_implementation.optional(),
|
|
29
|
+
...wired
|
|
30
|
+
};
|
|
31
|
+
const named = {
|
|
32
|
+
...common,
|
|
33
|
+
...agent_requests_owner,
|
|
34
|
+
name: agent_requests_name
|
|
35
|
+
};
|
|
36
|
+
const operation = (value, shape)=>zod.strictObject({
|
|
37
|
+
operation: zod.literal(value),
|
|
38
|
+
...shape
|
|
39
|
+
});
|
|
40
|
+
const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
|
|
41
|
+
operation('bounded-context', {
|
|
42
|
+
...common,
|
|
43
|
+
name: agent_requests_name.refine((value)=>'shared-kernel' !== value, 'shared-kernel is reserved for the Shared Kernel.')
|
|
44
|
+
}),
|
|
45
|
+
operation('aggregate', {
|
|
46
|
+
...named,
|
|
47
|
+
withRepository: zod.boolean().optional(),
|
|
48
|
+
implementation: agent_requests_implementation.optional(),
|
|
49
|
+
testImplementation: agent_requests_implementation.optional(),
|
|
50
|
+
...wired
|
|
51
|
+
}),
|
|
52
|
+
operation('entity', {
|
|
53
|
+
...named,
|
|
54
|
+
aggregate: agent_requests_name.optional()
|
|
55
|
+
}),
|
|
56
|
+
operation('value-object', {
|
|
57
|
+
...named,
|
|
58
|
+
aggregate: agent_requests_name.optional()
|
|
59
|
+
}),
|
|
60
|
+
operation('error', {
|
|
61
|
+
...named,
|
|
62
|
+
namespace: agent_requests_name.optional()
|
|
63
|
+
}),
|
|
64
|
+
operation('error-namespace', named),
|
|
65
|
+
operation('domain-service', {
|
|
66
|
+
...named,
|
|
67
|
+
...wired
|
|
68
|
+
}),
|
|
69
|
+
operation('application-service', {
|
|
70
|
+
...named,
|
|
71
|
+
...wired
|
|
72
|
+
}),
|
|
73
|
+
operation('infrastructure-service', {
|
|
74
|
+
...named,
|
|
75
|
+
...wired
|
|
76
|
+
}),
|
|
77
|
+
operation('presentation-service', {
|
|
78
|
+
...named,
|
|
79
|
+
...wired
|
|
80
|
+
}),
|
|
81
|
+
operation('use-case', {
|
|
82
|
+
...named,
|
|
83
|
+
...wired
|
|
84
|
+
}),
|
|
85
|
+
operation('command', {
|
|
86
|
+
...named,
|
|
87
|
+
...implementations
|
|
88
|
+
}),
|
|
89
|
+
operation('query', {
|
|
90
|
+
...named,
|
|
91
|
+
...implementations
|
|
92
|
+
}),
|
|
93
|
+
operation('port', {
|
|
94
|
+
...named,
|
|
95
|
+
...implementations
|
|
96
|
+
}),
|
|
97
|
+
operation('implementation', {
|
|
98
|
+
...common,
|
|
99
|
+
...agent_requests_owner,
|
|
100
|
+
contract: id.describe('Exact contract ID from --describe.'),
|
|
101
|
+
implementation: agent_requests_implementation,
|
|
102
|
+
environments: zod.array(agent_requests_name).min(1).optional().describe('Required when the contract wire is envBranchedWire; omit it otherwise.'),
|
|
103
|
+
...wired
|
|
104
|
+
}),
|
|
105
|
+
operation('endpoint', {
|
|
106
|
+
...common,
|
|
107
|
+
...agent_requests_owner,
|
|
108
|
+
controller: agent_requests_name,
|
|
109
|
+
method: zod["enum"]([
|
|
110
|
+
'get',
|
|
111
|
+
'post',
|
|
112
|
+
'put',
|
|
113
|
+
'patch',
|
|
114
|
+
'delete'
|
|
115
|
+
]),
|
|
116
|
+
path: zod.string().regex(/^(?:\/?(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*))*\/?$/),
|
|
117
|
+
handler: id.optional().describe('Exact handler module ID from --describe. Required when the context has wired queries, commands or use cases; omit it otherwise.')
|
|
118
|
+
}),
|
|
119
|
+
operation('wire-dependency', {
|
|
120
|
+
...common,
|
|
121
|
+
...agent_requests_owner,
|
|
122
|
+
module: id.describe('Exact wiring target ID, including implementation class, from --describe.'),
|
|
123
|
+
dependencies: dependencies
|
|
124
|
+
}),
|
|
125
|
+
operation('move', {
|
|
126
|
+
...common,
|
|
127
|
+
...agent_requests_owner,
|
|
128
|
+
module: id.describe('Exact unit ID from --describe.'),
|
|
129
|
+
targetContext: agent_requests_name.optional(),
|
|
130
|
+
name: agent_requests_name.optional(),
|
|
131
|
+
aggregate: agent_requests_name.optional()
|
|
132
|
+
})
|
|
133
|
+
]);
|
|
134
|
+
const reactRequestSchema = zod.discriminatedUnion('operation', [
|
|
135
|
+
operation('page', {
|
|
136
|
+
...common,
|
|
137
|
+
name: nestedName
|
|
138
|
+
}),
|
|
139
|
+
operation('widget', {
|
|
140
|
+
...common,
|
|
141
|
+
name: nestedName,
|
|
142
|
+
widgetType: zod["enum"]([
|
|
143
|
+
'monolithic',
|
|
144
|
+
'separated',
|
|
145
|
+
'headless'
|
|
146
|
+
]).optional()
|
|
147
|
+
}),
|
|
148
|
+
operation('ui-kit-component', {
|
|
149
|
+
...common,
|
|
150
|
+
name: agent_requests_name
|
|
151
|
+
}),
|
|
152
|
+
operation('shared-hook', {
|
|
153
|
+
...common,
|
|
154
|
+
name: agent_requests_name
|
|
155
|
+
}),
|
|
156
|
+
operation('move-page', {
|
|
157
|
+
...common,
|
|
158
|
+
module: nestedName,
|
|
159
|
+
name: nestedName
|
|
160
|
+
}),
|
|
161
|
+
operation('move-widget', {
|
|
162
|
+
...common,
|
|
163
|
+
module: nestedName,
|
|
164
|
+
name: nestedName
|
|
165
|
+
})
|
|
166
|
+
]);
|
|
167
|
+
const relativePath = zod.string().regex(/^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.-]+)*$/).refine((value)=>!value.split('/').some((part)=>'.' === part || '..' === part), 'Use a project-relative path without . or .. segments.');
|
|
168
|
+
const integrationRequestSchema = operation('add', {
|
|
169
|
+
...common,
|
|
170
|
+
integrations: zod.array(zod["enum"](integrationIds)).min(1),
|
|
171
|
+
nextAdapter: zod.boolean().optional(),
|
|
172
|
+
configureReact: zod.boolean().optional(),
|
|
173
|
+
replaceTestingLibrary: zod.boolean().optional(),
|
|
174
|
+
withService: zod.boolean().optional(),
|
|
175
|
+
routePrefix: zod.string().regex(/^\/?[a-zA-Z0-9_/-]*$/).optional(),
|
|
176
|
+
openapiPath: relativePath.optional(),
|
|
177
|
+
withExtractor: zod.boolean().optional(),
|
|
178
|
+
swaggerPage: zod.boolean().optional(),
|
|
179
|
+
targets: zod.array(zod["enum"]([
|
|
180
|
+
'hooks',
|
|
181
|
+
'client'
|
|
182
|
+
])).min(1).optional(),
|
|
183
|
+
scriptConflicts: zod.record(id, zod["enum"]([
|
|
184
|
+
'keep',
|
|
185
|
+
'replace',
|
|
186
|
+
'rename'
|
|
187
|
+
])).optional(),
|
|
188
|
+
scriptNames: zod.record(id, zod.string().regex(/^[a-zA-Z0-9:_-]+$/)).optional()
|
|
189
|
+
});
|
|
190
|
+
const requestSchemaFor = (command)=>({
|
|
191
|
+
'df-scaffold': scaffoldRequestSchema,
|
|
192
|
+
'df-react': reactRequestSchema,
|
|
193
|
+
'df-integration': integrationRequestSchema
|
|
194
|
+
})[command];
|
|
195
|
+
const requireProject = ()=>{
|
|
196
|
+
try {
|
|
197
|
+
return new ProjectRoot().path;
|
|
198
|
+
} catch {
|
|
199
|
+
throw new RequestError('PROJECT_NOT_FOUND', 'Run inside a project with package.json.');
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const ownerFolders = (root)=>{
|
|
203
|
+
const source = new Folder(root).subitem([
|
|
204
|
+
ConfigFile.Instance.data.project.rootFolder
|
|
205
|
+
]);
|
|
206
|
+
return [
|
|
207
|
+
{
|
|
208
|
+
name: 'shared-kernel',
|
|
209
|
+
folder: source.subitem([
|
|
210
|
+
'shared-kernel'
|
|
211
|
+
])
|
|
212
|
+
},
|
|
213
|
+
...source.subitem([
|
|
214
|
+
'bounded-contexts'
|
|
215
|
+
]).content.subfolderNames.sort().map((name)=>({
|
|
216
|
+
name,
|
|
217
|
+
folder: source.subitem([
|
|
218
|
+
'bounded-contexts',
|
|
219
|
+
name
|
|
220
|
+
])
|
|
221
|
+
}))
|
|
222
|
+
];
|
|
223
|
+
};
|
|
224
|
+
const ownerFor = (context)=>{
|
|
225
|
+
const owner = ownerFolders(requireProject()).find((owner)=>owner.name === context);
|
|
226
|
+
if (!owner) throw new RequestError('CONTEXT_NOT_FOUND', `Unknown context: ${context}.`, {
|
|
227
|
+
context
|
|
228
|
+
});
|
|
229
|
+
return owner.folder;
|
|
230
|
+
};
|
|
231
|
+
const precondition = (command)=>{
|
|
232
|
+
requireProject();
|
|
233
|
+
if (!ConfigFile.exists) throw new RequestError('CONFIG_NOT_FOUND', 'Ask the project owner to run df-init.');
|
|
234
|
+
if (ConfigFile.outdated) throw new RequestError('CONFIG_OUTDATED', 'The config has the format of an earlier major version: ask the project owner to run df-upgrade.');
|
|
235
|
+
if ('df-scaffold' === command && !ConfigFile.Instance.data.backend) throw new RequestError('BACKEND_NOT_CONFIGURED', 'Ask the project owner to run df-init --section backend.');
|
|
236
|
+
if ('df-react' === command && !ConfigFile.Instance.data.frontend?.react) throw new RequestError('FRONTEND_NOT_CONFIGURED', 'Ask the project owner to run df-init --section frontend.');
|
|
237
|
+
};
|
|
238
|
+
const describeAgentCommand = (command)=>{
|
|
239
|
+
let root;
|
|
240
|
+
try {
|
|
241
|
+
root = new ProjectRoot().path;
|
|
242
|
+
} catch {}
|
|
243
|
+
const configStatus = root && ConfigFile.exists ? ConfigFile.outdated ? 'outdated' : 'current' : 'missing';
|
|
244
|
+
const configured = 'current' === configStatus;
|
|
245
|
+
const config = configured ? ConfigFile.Instance.data : void 0;
|
|
246
|
+
const owners = configured ? ownerFolders(root) : [];
|
|
247
|
+
const modules = owners.flatMap((owner)=>findWiredModules(owner.folder.path));
|
|
248
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
249
|
+
return {
|
|
250
|
+
schemaVersion: 1,
|
|
251
|
+
command,
|
|
252
|
+
requestSchema: zod.toJSONSchema(requestSchemaFor(command)),
|
|
253
|
+
project: root ? {
|
|
254
|
+
root,
|
|
255
|
+
configured,
|
|
256
|
+
configStatus,
|
|
257
|
+
config,
|
|
258
|
+
contexts: owners.map((owner)=>({
|
|
259
|
+
name: owner.name,
|
|
260
|
+
units: findBackendUnits(owner.folder.path).map((unit)=>({
|
|
261
|
+
id: unitId(unit),
|
|
262
|
+
kind: unit.kind,
|
|
263
|
+
name: unit.name,
|
|
264
|
+
aggregate: unit.aggregate,
|
|
265
|
+
implementations: unit.labels
|
|
266
|
+
})),
|
|
267
|
+
contracts: findContracts(owner.folder.path).map((unit)=>({
|
|
268
|
+
id: unitId(unit),
|
|
269
|
+
kind: unit.kind,
|
|
270
|
+
implementations: unit.labels
|
|
271
|
+
})),
|
|
272
|
+
modules: findWiredModules(owner.folder.path).map((module)=>({
|
|
273
|
+
id: moduleId(module),
|
|
274
|
+
kind: module.kind,
|
|
275
|
+
file: relative(module.typeFile),
|
|
276
|
+
implementations: module.implementations.map((implementation)=>({
|
|
277
|
+
className: implementation.className,
|
|
278
|
+
target: `${moduleId(module)}:${implementation.className}`,
|
|
279
|
+
dependencies: availableDependencies(module, implementation, 'shared-kernel' === owner.name ? modules.filter((module)=>moduleId(module).startsWith('shared-kernel:')) : modules).map(moduleId)
|
|
280
|
+
}))
|
|
281
|
+
})),
|
|
282
|
+
implementationTypes: config?.backend ? Object.fromEntries(implementationKinds.map((kind)=>[
|
|
283
|
+
kind,
|
|
284
|
+
{
|
|
285
|
+
primary: savedImplementations(kind, 'primary'),
|
|
286
|
+
test: savedImplementations(kind, 'test'),
|
|
287
|
+
system: systemImplementationChoices(kind, 'shared-kernel' !== owner.name && hasNeighboringBoundedContext(owner.folder.path))
|
|
288
|
+
}
|
|
289
|
+
])) : void 0
|
|
290
|
+
})),
|
|
291
|
+
integrations: integrationDescriptionsSafe(configured),
|
|
292
|
+
reactModules: config?.frontend?.react ? [
|
|
293
|
+
'page',
|
|
294
|
+
'widget'
|
|
295
|
+
].flatMap((kind)=>findReactModules(node_path.join(root, config.project.rootFolder, 'presentation/react'), kind).map((module)=>({
|
|
296
|
+
kind,
|
|
297
|
+
name: module.name,
|
|
298
|
+
file: relative(module.path)
|
|
299
|
+
}))) : []
|
|
300
|
+
} : null
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
const integrationDescriptionsSafe = (configured)=>configured ? integrationDescriptions() : [];
|
|
304
|
+
const answersFor = (command, request, owner)=>{
|
|
305
|
+
const answers = {};
|
|
306
|
+
const defaults = {
|
|
307
|
+
overwrite: request.overwrite ?? false,
|
|
308
|
+
apply: true,
|
|
309
|
+
withRepository: false,
|
|
310
|
+
widgetType: 'with separated ui'
|
|
311
|
+
};
|
|
312
|
+
const ignored = new Set([
|
|
313
|
+
'operation',
|
|
314
|
+
'context',
|
|
315
|
+
'overwrite',
|
|
316
|
+
'dryRun',
|
|
317
|
+
'dependencies',
|
|
318
|
+
"scriptConflicts",
|
|
319
|
+
"scriptNames",
|
|
320
|
+
'namespace'
|
|
321
|
+
]);
|
|
322
|
+
for (const [key, value] of Object.entries(request))if (!ignored.has(key)) answers[key] = value;
|
|
323
|
+
for (const [implementation, ids] of Object.entries(request.dependencies ?? {}))answers[`dependencies.${implementation}`] = ids;
|
|
324
|
+
for (const [script, action] of Object.entries(request.scriptConflicts ?? {}))answers[`scriptConflicts.${script}`] = ({
|
|
325
|
+
keep: 'Keep existing',
|
|
326
|
+
replace: 'Replace',
|
|
327
|
+
rename: 'Use another name'
|
|
328
|
+
})[action];
|
|
329
|
+
for (const [script, name] of Object.entries(request.scriptNames ?? {}))answers[`scriptNames.${script}`] = name;
|
|
330
|
+
defaults.withTestImplementation = Boolean(request.testImplementation);
|
|
331
|
+
if ('entity' === request.operation || 'value-object' === request.operation) defaults.aggregate = 'No aggregate';
|
|
332
|
+
if ('separated' === request.widgetType) answers.widgetType = 'with separated ui';
|
|
333
|
+
if ('df-scaffold' === command) {
|
|
334
|
+
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';
|
|
335
|
+
if ('endpoint' === request.operation) {
|
|
336
|
+
delete answers.controller;
|
|
337
|
+
const existing = owner.subitem([
|
|
338
|
+
'presentation',
|
|
339
|
+
'rest'
|
|
340
|
+
]).content.subfolderNames.includes(request.controller);
|
|
341
|
+
answers.controllerSelection = existing ? request.controller : 'New controller';
|
|
342
|
+
if (!existing) answers.controllerName = request.controller;
|
|
343
|
+
}
|
|
344
|
+
if ('move' === request.operation) defaults.targetContext = request.context;
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
answers,
|
|
348
|
+
defaults
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
const executeScaffold = async (request, owner)=>{
|
|
352
|
+
if ('shared-kernel' === request.context && [
|
|
353
|
+
'aggregate',
|
|
354
|
+
'use-case',
|
|
355
|
+
'command',
|
|
356
|
+
'query',
|
|
357
|
+
'endpoint'
|
|
358
|
+
].includes(request.operation)) throw new RequestError('OPERATION_NOT_AVAILABLE', 'This operation requires a bounded context.');
|
|
359
|
+
if ('aggregate' === request.operation && !request.withRepository && (request.implementation || request.testImplementation || request.dependencies)) throw new RequestError('INVALID_REQUEST', 'Repository options require withRepository: true.');
|
|
360
|
+
if ('error' === request.operation && request.namespace && !owner.subitem([
|
|
361
|
+
'domain',
|
|
362
|
+
'errors'
|
|
363
|
+
]).content.fileNames.includes(request.namespace)) throw new RequestError('TARGET_NOT_FOUND', `Unknown namespace: ${request.namespace}.`);
|
|
364
|
+
if ('implementation' === request.operation && !findContracts(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No contracts in this context.');
|
|
365
|
+
if ('move' === request.operation && !findBackendUnits(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No modules in this context.');
|
|
366
|
+
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.');
|
|
367
|
+
if ('endpoint' === request.operation) {
|
|
368
|
+
if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers-rest') || !findRestEndpointGenerator(new Folder(requireProject()).subitem([
|
|
369
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
370
|
+
'shared-kernel'
|
|
371
|
+
]))) throw new RequestError('REST_NOT_CONFIGURED', 'Add the REST endpoint generator integration first.');
|
|
372
|
+
}
|
|
373
|
+
if (('entity' === request.operation || 'value-object' === request.operation) && request.aggregate && !owner.subitem([
|
|
374
|
+
'domain',
|
|
375
|
+
'aggregates'
|
|
376
|
+
]).content.subfolderNames.includes(request.aggregate)) throw new RequestError('TARGET_NOT_FOUND', `Unknown aggregate: ${request.aggregate}.`);
|
|
377
|
+
const actions = {
|
|
378
|
+
aggregate: ()=>scaffoldNewAggregateUseCase(owner),
|
|
379
|
+
entity: ()=>scaffoldNewDomainObject(owner, 'entity'),
|
|
380
|
+
'value-object': ()=>scaffoldNewDomainObject(owner, 'value-object'),
|
|
381
|
+
error: ()=>scaffoldNewErrorUseCase(owner),
|
|
382
|
+
'error-namespace': ()=>scaffoldNewErrorUseCase(owner),
|
|
383
|
+
'domain-service': ()=>scaffoldNewDomainService(owner),
|
|
384
|
+
'application-service': ()=>scaffoldNewApplicationService(owner),
|
|
385
|
+
'infrastructure-service': ()=>scaffoldNewInfrastructureService(owner),
|
|
386
|
+
'presentation-service': ()=>scaffoldNewPresentationService(owner),
|
|
387
|
+
'use-case': ()=>scaffoldNewUseCase(owner),
|
|
388
|
+
command: ()=>scaffoldNewCommand(owner),
|
|
389
|
+
query: ()=>scaffoldNewQuery(owner),
|
|
390
|
+
port: ()=>scaffoldNewApplicationPort(owner),
|
|
391
|
+
implementation: ()=>scaffoldNewImplementation(owner),
|
|
392
|
+
endpoint: ()=>scaffoldNewHandlersRestEndpoint(owner),
|
|
393
|
+
'wire-dependency': ()=>wireDependency(owner),
|
|
394
|
+
move: ()=>moveBackendUnitUseCase(owner)
|
|
395
|
+
};
|
|
396
|
+
return actions[request.operation]();
|
|
397
|
+
};
|
|
398
|
+
const executeReact = async (request)=>{
|
|
399
|
+
const folder = new Folder(requireProject()).subitem([
|
|
400
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
401
|
+
'presentation/react'
|
|
402
|
+
]);
|
|
403
|
+
if (request.operation.startsWith('move-') && !findReactModules(folder.path, 'move-page' === request.operation ? 'page' : 'widget').length) throw new RequestError('TARGET_NOT_FOUND', 'No React modules to move.');
|
|
404
|
+
const actions = {
|
|
405
|
+
page: ()=>scaffoldReactPage(folder),
|
|
406
|
+
widget: ()=>scaffoldReactWidget(folder),
|
|
407
|
+
'ui-kit-component': ()=>scaffoldReactUIKitComponent(folder),
|
|
408
|
+
'shared-hook': ()=>scaffoldReactSharedHook(folder),
|
|
409
|
+
'move-page': ()=>moveReactModuleUseCase(folder, 'page'),
|
|
410
|
+
'move-widget': ()=>moveReactModuleUseCase(folder, 'widget')
|
|
411
|
+
};
|
|
412
|
+
return actions[request.operation]();
|
|
413
|
+
};
|
|
414
|
+
const executeAgentRequest = async (command, value)=>{
|
|
415
|
+
discardPendingChanges();
|
|
416
|
+
try {
|
|
417
|
+
const parsed = requestSchemaFor(command).safeParse(value);
|
|
418
|
+
if (!parsed.success) throw new RequestError('INVALID_REQUEST', 'Request does not match the operation schema.', {
|
|
419
|
+
issues: parsed.error.issues.map((issue)=>({
|
|
420
|
+
field: issue.path.join('.'),
|
|
421
|
+
message: issue.message
|
|
422
|
+
}))
|
|
423
|
+
});
|
|
424
|
+
const request = parsed.data;
|
|
425
|
+
precondition(command);
|
|
426
|
+
const root = requireProject();
|
|
427
|
+
const owner = 'df-scaffold' === command && 'bounded-context' !== request.operation ? ownerFor(request.context) : void 0;
|
|
428
|
+
const { answers, defaults } = answersFor(command, request, owner);
|
|
429
|
+
const execution = await runWithAnswers(answers, defaults, async ()=>{
|
|
430
|
+
let nextSteps = [];
|
|
431
|
+
if ('df-scaffold' === command) if ('bounded-context' === request.operation) await scaffoldNewBoundedContextUseCase();
|
|
432
|
+
else await executeScaffold(request, owner);
|
|
433
|
+
else if ('df-react' === command) await executeReact(request);
|
|
434
|
+
else nextSteps = await addIntegration({
|
|
435
|
+
save: false
|
|
436
|
+
});
|
|
437
|
+
assertAnswersConsumed();
|
|
438
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
439
|
+
const planned = pendingChanges();
|
|
440
|
+
const files = {
|
|
441
|
+
created: planned.created.map(relative),
|
|
442
|
+
updated: planned.updated.map(relative),
|
|
443
|
+
deleted: planned.deleted.map(relative)
|
|
444
|
+
};
|
|
445
|
+
const directories = planned.directories.map(relative);
|
|
446
|
+
const overwriteRequired = filesToOverwrite({
|
|
447
|
+
changedOnly: true
|
|
448
|
+
}).map(relative);
|
|
449
|
+
if (request.dryRun) discardPendingChanges();
|
|
450
|
+
else if (!await savePendingChanges()) throw new RequestError('CANCELLED', 'Nothing was written.');
|
|
451
|
+
return {
|
|
452
|
+
schemaVersion: 1,
|
|
453
|
+
ok: true,
|
|
454
|
+
operation: request.operation,
|
|
455
|
+
dryRun: request.dryRun ?? false,
|
|
456
|
+
files,
|
|
457
|
+
directories,
|
|
458
|
+
overwriteRequired,
|
|
459
|
+
nextSteps
|
|
460
|
+
};
|
|
461
|
+
});
|
|
462
|
+
return {
|
|
463
|
+
...execution.result,
|
|
464
|
+
messages: execution.messages
|
|
465
|
+
};
|
|
466
|
+
} catch (error) {
|
|
467
|
+
discardPendingChanges();
|
|
468
|
+
throw error;
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
const agentError = (error)=>({
|
|
472
|
+
schemaVersion: 1,
|
|
473
|
+
ok: false,
|
|
474
|
+
error: {
|
|
475
|
+
code: error instanceof RequestError ? error.code : error instanceof zod.ZodError ? 'INVALID_CONFIG' : 'OPERATION_FAILED',
|
|
476
|
+
message: error instanceof Error ? error.message : String(error),
|
|
477
|
+
...error instanceof RequestError && error.details ? {
|
|
478
|
+
details: error.details
|
|
479
|
+
} : {}
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
const runCLI = async (command, interactive)=>{
|
|
483
|
+
const args = process.argv.slice(2);
|
|
484
|
+
const machine = args.some((arg)=>'--request' === arg || arg.startsWith('--request=') || '--describe' === arg || arg.startsWith('--describe='));
|
|
485
|
+
if (!machine) {
|
|
486
|
+
if ('df-scaffold' === command && args.some((arg)=>'--help' !== arg && '-h' !== arg)) throw new RequestError('INVALID_ARGUMENTS', 'Use --request <json|->, --describe, or run without arguments.');
|
|
487
|
+
await interactive();
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
const { values } = parseArgs({
|
|
492
|
+
args,
|
|
493
|
+
options: {
|
|
494
|
+
request: {
|
|
495
|
+
type: 'string'
|
|
496
|
+
},
|
|
497
|
+
describe: {
|
|
498
|
+
type: 'boolean'
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
if (values.describe && void 0 !== values.request) throw new RequestError('INVALID_ARGUMENTS', 'Choose --describe or --request.');
|
|
503
|
+
if (values.describe) console.log(JSON.stringify(describeAgentCommand(command)));
|
|
504
|
+
else {
|
|
505
|
+
let value;
|
|
506
|
+
try {
|
|
507
|
+
value = JSON.parse('-' === values.request ? node_fs.readFileSync(0, 'utf8') : values.request);
|
|
508
|
+
} catch {
|
|
509
|
+
throw new RequestError('INVALID_JSON', 'Provide valid JSON in --request, or use --request - with JSON on stdin.');
|
|
510
|
+
}
|
|
511
|
+
console.log(JSON.stringify(await executeAgentRequest(command, value)));
|
|
512
|
+
}
|
|
513
|
+
} catch (error) {
|
|
514
|
+
console.log(JSON.stringify(agentError(error)));
|
|
515
|
+
process.exitCode = 1;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
export { runCLI };
|
package/dist/711.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { ProjectRoot, ConfigFile, File } from "./870.js";
|
|
3
|
+
const hasDependency = (name)=>{
|
|
4
|
+
const manifestFile = new File(node_path.join(new ProjectRoot().path, 'package.json'));
|
|
5
|
+
if (!manifestFile.exists) return false;
|
|
6
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
7
|
+
return [
|
|
8
|
+
manifest.dependencies,
|
|
9
|
+
manifest.devDependencies,
|
|
10
|
+
manifest.optionalDependencies
|
|
11
|
+
].some((dependencies)=>dependencies && Object.hasOwn(dependencies, name));
|
|
12
|
+
};
|
|
13
|
+
const missingPackages = (packages)=>{
|
|
14
|
+
const missing = [
|
|
15
|
+
...new Set(packages)
|
|
16
|
+
].filter((name)=>!hasDependency(name));
|
|
17
|
+
return missing.length ? [
|
|
18
|
+
`npm i ${missing.join(' ')}`
|
|
19
|
+
] : [];
|
|
20
|
+
};
|
|
21
|
+
const missingDomainFirstPackages = ()=>missingPackages(ConfigFile.backend.domainFirstPackages);
|
|
22
|
+
export { hasDependency, missingDomainFirstPackages, missingPackages };
|