@domain-first/project-structure 8.6.1 → 8.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/bin/df-skills.mjs +55 -9
  3. package/dist/287.js +44 -138
  4. package/dist/38.js +36 -0
  5. package/dist/561.js +9 -1
  6. package/dist/947.js +11 -1
  7. package/dist/agent-cli.d.ts +9 -2
  8. package/dist/agent-principles.cjs +116 -0
  9. package/dist/agent-principles.d.ts +9 -0
  10. package/dist/agent-principles.js +64 -0
  11. package/dist/agent-principles.spec.d.ts +1 -0
  12. package/dist/agent-requests.d.ts +16 -2
  13. package/dist/graph.cjs +10 -0
  14. package/dist/in-memory-db.d.ts +1 -6
  15. package/dist/index.cjs +64 -137
  16. package/dist/index.js +4 -1
  17. package/dist/init.cjs +12 -21
  18. package/dist/integration.cjs +61 -137
  19. package/dist/lint.cjs +46 -0
  20. package/dist/react.cjs +61 -137
  21. package/dist/use-cases/add-integration.d.ts +1 -1
  22. package/dist/use-cases/index.d.ts +1 -0
  23. package/dist/use-cases/scaffold-new-infrastructure-helper.d.ts +7 -0
  24. package/dist/wiring.d.ts +2 -2
  25. package/package.json +3 -2
  26. package/principles/df-principles.md +33 -0
  27. package/skills/df-ps-implement/SKILL.md +26 -1
  28. package/skills/df-ps-plan-feature/SKILL.md +22 -18
  29. package/skills/df-ps-react/SKILL.md +2 -9
  30. package/skills/df-ps-react/references/generators.md +9 -9
  31. package/skills/df-ps-scaffold/SKILL.md +20 -126
  32. package/skills/df-ps-scaffold/references/agent-mode.md +2 -2
  33. package/skills/df-ps-scaffold/references/agent-operations.md +1 -0
  34. package/skills/df-ps-scaffold/references/choosing-components.md +65 -49
  35. package/skills/df-ps-scaffold/references/generators.md +33 -11
  36. package/skills/df-ps-scaffold/references/units/aggregate.md +3 -5
  37. package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
  38. package/skills/df-ps-scaffold/references/units/command-query.md +6 -8
  39. package/skills/df-ps-scaffold/references/units/delete.md +0 -2
  40. package/skills/df-ps-scaffold/references/units/endpoint.md +1 -4
  41. package/skills/df-ps-scaffold/references/units/entity-value-object.md +0 -4
  42. package/skills/df-ps-scaffold/references/units/errors.md +0 -4
  43. package/skills/df-ps-scaffold/references/units/helper.md +30 -0
  44. package/skills/df-ps-scaffold/references/units/implementation.md +1 -5
  45. package/skills/df-ps-scaffold/references/units/move-or-rename.md +0 -4
  46. package/skills/df-ps-scaffold/references/units/port.md +3 -6
  47. package/skills/df-ps-scaffold/references/units/services.md +4 -6
  48. package/skills/df-ps-scaffold/references/units/use-case.md +1 -2
  49. package/skills/df-ps-scaffold/references/units/wire-dependency.md +0 -2
  50. package/skills/df-ps-scaffold/references/work-plan.md +73 -0
  51. package/skills/df-ps-scaffold/scripts/drive.mjs +0 -252
package/README.md CHANGED
@@ -347,7 +347,7 @@ The package ships skills that teach coding agents to plan features, scaffold wit
347
347
  npx df-skills --claude
348
348
  ```
349
349
 
350
- Run it again after upgrading the package to get the new versions.
350
+ Run it again after upgrading the package to get the new versions. Add `--principles` to also connect the programming principles to `CLAUDE.md` and `AGENTS.md`.
351
351
 
352
352
  ## License
353
353
 
package/bin/df-skills.mjs CHANGED
@@ -1,17 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { cpSync, existsSync, readdirSync, rmSync } from 'node:fs';
3
+ import { cpSync, existsSync, readdirSync, readFileSync, rmSync } from 'node:fs';
4
4
  import { homedir } from 'node:os';
5
5
  import { dirname, join, relative, resolve } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { parseArgs } from 'node:util';
8
- import { checkbox, select } from '@inquirer/prompts';
8
+ import { checkbox, confirm, select } from '@inquirer/prompts';
9
+ import { applyPrinciples, principlesState } from '../dist/agent-principles.js';
9
10
 
10
- const SKILLS_SOURCE = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'skills');
11
+ const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
12
+ const SKILLS_SOURCE = join(PACKAGE_ROOT, 'skills');
13
+ const PRINCIPLES_SOURCE = join(PACKAGE_ROOT, 'principles', 'df-principles.md');
11
14
 
12
15
  const AGENTS = {
13
- claude: { title: 'Claude Code', folder: join('.claude', 'skills') },
14
- codex: { title: 'Codex', folder: join('.agents', 'skills') },
16
+ claude: { title: 'Claude Code', folder: join('.claude', 'skills'), entry: 'CLAUDE.md' },
17
+ codex: { title: 'Codex', folder: join('.agents', 'skills'), entry: 'AGENTS.md' },
15
18
  };
16
19
 
17
20
  const HELP = `Usage: df-skills [options]
@@ -20,16 +23,19 @@ Copies Domain-First (df-ps) agent skills into your project.
20
23
  Runs interactively when no agent is given.
21
24
 
22
25
  Options:
23
- --claude install for Claude Code (.claude/skills)
24
- --codex install for Codex (.agents/skills)
25
- --global install into the home directory instead of the current project
26
- -h, --help show this help`;
26
+ --claude install for Claude Code (.claude/skills)
27
+ --codex install for Codex (.agents/skills)
28
+ --global install into the home directory instead of the current project
29
+ --principles connect the programming principles to CLAUDE.md and AGENTS.md
30
+ (connected ones are refreshed without this flag; not with --global)
31
+ -h, --help show this help`;
27
32
 
28
33
  const { values } = parseArgs({
29
34
  options: {
30
35
  claude: { type: 'boolean', default: false },
31
36
  codex: { type: 'boolean', default: false },
32
37
  global: { type: 'boolean', default: false },
38
+ principles: { type: 'boolean', default: false },
33
39
  help: { type: 'boolean', short: 'h', default: false },
34
40
  },
35
41
  });
@@ -39,6 +45,20 @@ if (values.help) {
39
45
  process.exit(0);
40
46
  }
41
47
 
48
+ const principles = readFileSync(PRINCIPLES_SOURCE, 'utf8');
49
+
50
+ const refuse = (message) => {
51
+ console.error(message);
52
+ process.exit(1);
53
+ };
54
+
55
+ if (values.principles && values.global) {
56
+ refuse('--principles is not available with --global: they apply to one project.');
57
+ }
58
+ if (values.principles && !principles.trim()) {
59
+ refuse('This version of the package has no programming principles to connect.');
60
+ }
61
+
42
62
  const skills = readdirSync(SKILLS_SOURCE, { withFileTypes: true })
43
63
  .filter((entry) => entry.isDirectory())
44
64
  .map((entry) => entry.name);
@@ -70,6 +90,22 @@ const global =
70
90
 
71
91
  const root = global ? homedir() : process.cwd();
72
92
 
93
+ // The principles of one architecture don't belong in every project of the user.
94
+ const withPrinciples = !global && Boolean(principles.trim());
95
+ const notConnected = withPrinciples
96
+ ? agents.filter((agent) => principlesState(root, agent) === 'absent')
97
+ : [];
98
+ const installPrinciples =
99
+ values.principles ||
100
+ (interactive && notConnected.length > 0
101
+ ? await confirm({
102
+ message: `Add the programming principles to ${notConnected
103
+ .map((agent) => AGENTS[agent].entry)
104
+ .join(' and ')}?`,
105
+ default: true,
106
+ })
107
+ : false);
108
+
73
109
  for (const agent of agents) {
74
110
  const target = join(root, AGENTS[agent].folder);
75
111
  console.log(`\n${AGENTS[agent].title} → ${global ? target : relative(root, target)}`);
@@ -82,4 +118,14 @@ for (const agent of agents) {
82
118
  cpSync(join(SKILLS_SOURCE, skill), destination, { recursive: true });
83
119
  console.log(` ${existed ? 'updated' : 'added '} ${skill}`);
84
120
  }
121
+
122
+ if (!withPrinciples) continue;
123
+ const result = applyPrinciples(root, agent, principles, installPrinciples);
124
+ if (result === 'conflict') {
125
+ console.warn(
126
+ ` skipped principles: fix the df-principles markers in ${AGENTS[agent].entry} (one start, then one end)`
127
+ );
128
+ } else if (result !== 'skipped') {
129
+ console.log(` ${result === 'updated' ? 'updated' : 'added '} principles`);
130
+ }
85
131
  }
package/dist/287.js CHANGED
@@ -4,7 +4,7 @@ import { Separator, checkbox as prompts_checkbox, confirm as prompts_confirm, in
4
4
  import { styleText } from "node:util";
5
5
  import node_fs from "node:fs";
6
6
  import { addImport, availableDependencies, findWiredModules, UnknownFormatNaming, readWiredModule, addClassMember, hasNeighboringBoundedContext, addBranchedImplementation, addWireDependencies, boundedContextLocation, addConstructorParameters, relativeImport, wireBranches, wireDependencies, implementationType as wiring_implementationType, crossContextImportAllowed, crossContextImplementation, isSuggestedFor } from "./947.js";
7
- import { implementationLabelSchema, withoutOverwrites, domainFirstPackages as config_file_domainFirstPackages, scaffoldBackendRules, branchNameSchema, discardPendingChanges, ConfigFile, filesToOverwrite, Folder, writePendingChanges, File, ProjectRoot, compilerOption } from "./780.js";
7
+ import { implementationLabelSchema, withoutOverwrites, domainFirstPackages as config_file_domainFirstPackages, scaffoldBackendRules, branchNameSchema, discardPendingChanges, ConfigFile, filesToOverwrite, Folder, writePendingChanges, File, ProjectRoot, implementationKinds, compilerOption } from "./780.js";
8
8
  import { missingDomainFirstPackages, walk, projectImports, escapeRegExp, pathParameterAsName, hasLegacyRootEndpoints, stageModuleMove, toPosix, rootStaticSegments, openapiExtractorPath, restControllers, hasDependency, openapiExtractor, missingPackages, codeExtension, isPathParameterName } from "./526.js";
9
9
  const moduleId = (module)=>`${boundedContextLocation(module.typeFile)?.name ?? 'shared-kernel'}:${module.typeName}`;
10
10
  const unitId = (unit)=>`${unit.kind}:${unit.aggregate ? `${unit.aggregate}/` : ''}${unit.name}`;
@@ -127,23 +127,6 @@ export const wireInMemoryDbInfrastructureService = wireClass(
127
127
  []
128
128
  );
129
129
  `;
130
- const inMemoryDbSpec = (testingLibrary, withWiring)=>`
131
- import { describe, test, expect, beforeEach } from '${testingLibrary}'
132
- ${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
133
- import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
134
-
135
- let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
136
-
137
- beforeEach(() => {
138
- inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
139
- })
140
-
141
- describe('in memory db', () => {
142
- test('can be ${withWiring ? 'wired' : 'created'}', () => {
143
- expect(inMemoryDbInfrastructureService).toBeDefined()
144
- })
145
- })
146
- `.trim();
147
130
  const in_memory_db_withWiring = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
148
131
  const in_memory_db_sharedFolder = ()=>new Folder(new ProjectRoot().path).subitem([
149
132
  ConfigFile.Instance.data.project.rootFolder,
@@ -160,13 +143,11 @@ const in_memory_db_wireFile = ()=>new File(in_memory_db_sharedFolder().path).sub
160
143
  'wire-in-memory-db-infrastructure-service.ts'
161
144
  ]);
162
145
  const scaffoldInMemoryDb = (shared)=>{
163
- const { testingLibrary } = ConfigFile.backend;
164
146
  const servicesFolder = shared.subitem([
165
147
  'infrastructure',
166
148
  'services'
167
149
  ]);
168
150
  servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
169
- if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
170
151
  if (in_memory_db_withWiring()) shared.subitem([
171
152
  'wiring',
172
153
  'infrastructure-services'
@@ -228,9 +209,6 @@ const wireInMemoryDb = (consumerWireFile, implementationName)=>{
228
209
  in_memory_db_wireName
229
210
  ]));
230
211
  };
231
- const passInMemoryDb = (specFile, implementationName)=>{
232
- specFile.update(addImport(specFile.data, `import { ${in_memory_db_className} } from '${relativeImport(specFile.path, serviceFile().path)}'`).replace(`new ${implementationName}()`, `new ${implementationName}(new ${in_memory_db_className}())`));
233
- };
234
212
  const addInMemoryDb = ()=>{
235
213
  const config = ConfigFile.Instance.data;
236
214
  if (!ConfigFile.backend.withInMemoryDb) ConfigFile.update({
@@ -3500,29 +3478,6 @@ describe('${aggregateNaming.withSpaces}', () => {
3500
3478
  labels: []
3501
3479
  };
3502
3480
  for (const implementation of implementationTypes)createImplementation(boundedContextFolder, repository, new UnknownFormatNaming(implementation).fileName);
3503
- if (scaffoldUnitTests) {
3504
- const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
3505
- const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
3506
- import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
3507
- ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
3508
- import type { ${aggregateNaming.ClassName}Repository } from './${aggregateNaming.fileName}-repository'` : `import { ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository } from '../../../infrastructure/repositories/${implementationNaming.fileName}/${implementationNaming.fileName}-${aggregateNaming.fileName}-repository'
3509
-
3510
- type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`}
3511
-
3512
- let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
3513
-
3514
- beforeEach(() => {
3515
- ${aggregateNaming.variableName}Repository = ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${aggregateNaming.ClassName}Repository()` : `new ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository()`}
3516
- })
3517
-
3518
- describe('${aggregateNaming.withSpaces} repository', () => {
3519
- test('can be ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
3520
- expect(${aggregateNaming.variableName}Repository).toBeDefined()
3521
- })
3522
- })
3523
- `.trim());
3524
- if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
3525
- }
3526
3481
  if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
3527
3482
  const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
3528
3483
  const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
@@ -3548,7 +3503,6 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
3548
3503
  message: 'Name: '
3549
3504
  });
3550
3505
  const naming = new UnknownFormatNaming(name);
3551
- const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
3552
3506
  const wiringFolder = boundedContextFolder.subitem([
3553
3507
  'wiring',
3554
3508
  'application-ports'
@@ -3588,28 +3542,6 @@ export abstract class ${naming.ClassName} {
3588
3542
  ownerPath: boundedContextFolder.path,
3589
3543
  labels: []
3590
3544
  }, implementation);
3591
- if (scaffoldUnitTests) {
3592
- const implementationNaming = new UnknownFormatNaming(implementationType);
3593
- applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
3594
- import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
3595
- ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
3596
- import { wire${naming.ClassName} } from '../../wiring/application-ports/wire-${naming.fileName}'` : `import { ${implementationNaming.ClassName}${naming.ClassName} } from '../../infrastructure/application-adapters/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}'
3597
-
3598
- type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`}
3599
-
3600
- let ${naming.variableName}: ${naming.ClassName}
3601
-
3602
- beforeEach(() => {
3603
- ${naming.variableName} = ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${naming.ClassName}()` : `new ${implementationNaming.ClassName}${naming.ClassName}()`}
3604
- })
3605
-
3606
- describe('${naming.withSpaces}', () => {
3607
- test('can be ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
3608
- expect(${naming.variableName}).toBeDefined()
3609
- })
3610
- })
3611
- `.trim());
3612
- }
3613
3545
  if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
3614
3546
  const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
3615
3547
  import { wireClass } from '@domain-first/wire'
@@ -3705,9 +3637,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
3705
3637
  key: 'name',
3706
3638
  message: 'Name: '
3707
3639
  });
3708
- const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
3709
3640
  const naming = new UnknownFormatNaming(commandName);
3710
- const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
3711
3641
  const { label: implementationType } = await promptImplementationType('Command infrastructure implementation type:', 'commands');
3712
3642
  let addTestImplementation = false;
3713
3643
  let testImplementationType = '';
@@ -3745,29 +3675,6 @@ export abstract class ${naming.ClassName}Command {
3745
3675
  export abstract class ${naming.ClassName}Command {
3746
3676
 
3747
3677
  }`.trim());
3748
- if (scaffoldUnitTests) {
3749
- const implementationNaming = new UnknownFormatNaming(implementationType);
3750
- const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
3751
- import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
3752
- ${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
3753
- import { wire${naming.ClassName}Command } from '../../wiring/commands/wire-${naming.fileName}-command'` : `import { ${implementationNaming.ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}-command'
3754
-
3755
- type ${naming.ClassName}Command = ${implementationNaming.ClassName}${naming.ClassName}Command`}
3756
-
3757
- let ${naming.variableName}Command: ${naming.ClassName}Command
3758
-
3759
- beforeEach(() => {
3760
- ${naming.variableName}Command = ${withWiring ? `wire${naming.ClassName}Command()` : `new ${implementationNaming.ClassName}${naming.ClassName}Command()`}
3761
- })
3762
-
3763
- describe('${naming.withSpaces} command', () => {
3764
- test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
3765
- expect(${naming.variableName}Command).toBeDefined()
3766
- })
3767
- })
3768
- `.trim());
3769
- if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
3770
- }
3771
3678
  if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
3772
3679
  const implementationNaming = new UnknownFormatNaming(implementationType);
3773
3680
  const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
@@ -4217,13 +4124,54 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
4217
4124
  for (const implementation of unused)report(`${implementation.className} is no longer used in any environment.`);
4218
4125
  await wireNewImplementationDependencies(ownerFolder, wireFile, className, inMemoryRepositoryWiring(ownerFolder, unit, wireFile));
4219
4126
  };
4127
+ const helperImplementationTypes = ()=>[
4128
+ ...new Set(implementationKinds.flatMap((kind)=>[
4129
+ ...savedImplementations(kind, 'primary'),
4130
+ ...savedImplementations(kind, 'test'),
4131
+ ...systemImplementationChoices(kind).map(({ value })=>value)
4132
+ ]))
4133
+ ].filter((label)=>label !== crossContextImplementation);
4134
+ const validateName = (value)=>{
4135
+ const valid = NestedName.validate(value);
4136
+ if (true !== valid) return valid;
4137
+ const { folders, folderName } = new NestedName(value);
4138
+ return [
4139
+ ...folders,
4140
+ folderName
4141
+ ].every((part)=>kebabName.test(part)) ? true : 'Use lowercase kebab-case split by "/", e.g. mappers/social-network-type';
4142
+ };
4143
+ const scaffoldNewInfrastructureHelper = async (ownerFolder)=>{
4144
+ const types = helperImplementationTypes();
4145
+ if (!types.length) return void report('No implementation types yet: a helper belongs to one, so add an implementation first.');
4146
+ const name = new NestedName(await interaction_input({
4147
+ key: 'name',
4148
+ message: 'Name (folders split by "/"): ',
4149
+ validate: validateName
4150
+ }));
4151
+ const label = await interaction_select({
4152
+ key: 'implementationType',
4153
+ message: 'Implementation:',
4154
+ choices: types.map((value)=>({
4155
+ name: value,
4156
+ value
4157
+ }))
4158
+ });
4159
+ const fileName = name.folderName.startsWith(`${label}-`) ? name.folderName : `${label}-${name.folderName}`;
4160
+ const naming = new UnknownFormatNaming(fileName);
4161
+ const folder = ownerFolder.subitem([
4162
+ 'infrastructure',
4163
+ 'helpers',
4164
+ label,
4165
+ ...name.folders
4166
+ ]);
4167
+ folder.createFile(`${fileName}.ts`, `export const ${naming.variableName} = () => {}`);
4168
+ };
4220
4169
  const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
4221
4170
  const name = await interaction_input({
4222
4171
  key: 'name',
4223
4172
  message: 'Name: '
4224
4173
  });
4225
4174
  const naming = new UnknownFormatNaming(name);
4226
- const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
4227
4175
  const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
4228
4176
  const wiringFolder = boundedContextFolder.subitem([
4229
4177
  'wiring',
@@ -4238,23 +4186,6 @@ export class ${naming.ClassName}InfrastructureService {
4238
4186
 
4239
4187
  }
4240
4188
  `.trim());
4241
- if (scaffoldUnitTests) infrastructureServicesFolder.createFile(`${naming.fileName}-infrastructure-service.spec.ts`, `
4242
- import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
4243
- ${withWiring ? `import { type ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'
4244
- import { wire${naming.ClassName}InfrastructureService } from '../../wiring/infrastructure-services/wire-${naming.fileName}-infrastructure-service'` : `import { ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'`}
4245
-
4246
- let ${naming.variableName}InfrastructureService: ${naming.ClassName}InfrastructureService
4247
-
4248
- beforeEach(() => {
4249
- ${naming.variableName}InfrastructureService = ${withWiring ? `wire${naming.ClassName}InfrastructureService()` : `new ${naming.ClassName}InfrastructureService()`}
4250
- })
4251
-
4252
- describe('${naming.withSpaces}', () => {
4253
- test('can be ${withWiring ? 'wired' : 'created'}', () => {
4254
- expect(${naming.variableName}InfrastructureService).toBeDefined()
4255
- })
4256
- })
4257
- `.trim());
4258
4189
  if (withWiring) {
4259
4190
  const wireFile = wiringFolder.createFile(`wire-${naming.fileName}-infrastructure-service.ts`, `
4260
4191
  import { wireClass } from '@domain-first/wire'
@@ -4277,9 +4208,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
4277
4208
  key: 'name',
4278
4209
  message: 'Name: '
4279
4210
  });
4280
- const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
4281
4211
  const naming = new UnknownFormatNaming(queryName);
4282
- const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
4283
4212
  const { label: implementationType } = await promptImplementationType('Query infrastructure implementation type:', 'queries');
4284
4213
  let addTestImplementation = false;
4285
4214
  let testImplementationType = '';
@@ -4317,29 +4246,6 @@ export abstract class ${naming.ClassName}Query {
4317
4246
  export abstract class ${naming.ClassName}Query {
4318
4247
 
4319
4248
  }`.trim());
4320
- if (scaffoldUnitTests) {
4321
- const implementationNaming = new UnknownFormatNaming(implementationType);
4322
- const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
4323
- import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
4324
- ${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
4325
- import { wire${naming.ClassName}Query } from '../../wiring/queries/wire-${naming.fileName}-query'` : `import { ${implementationNaming.ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}-query'
4326
-
4327
- type ${naming.ClassName}Query = ${implementationNaming.ClassName}${naming.ClassName}Query`}
4328
-
4329
- let ${naming.variableName}Query: ${naming.ClassName}Query
4330
-
4331
- beforeEach(() => {
4332
- ${naming.variableName}Query = ${withWiring ? `wire${naming.ClassName}Query()` : `new ${implementationNaming.ClassName}${naming.ClassName}Query()`}
4333
- })
4334
-
4335
- describe('${naming.withSpaces} query', () => {
4336
- test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
4337
- expect(${naming.variableName}Query).toBeDefined()
4338
- })
4339
- })
4340
- `.trim());
4341
- if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
4342
- }
4343
4249
  if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
4344
4250
  const implementationNaming = new UnknownFormatNaming(implementationType);
4345
4251
  const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
@@ -4616,4 +4522,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
4616
4522
  break;
4617
4523
  }
4618
4524
  };
4619
- export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, reactKindTitles, rootControllerChoice, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
4525
+ export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, helperImplementationTypes, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, reactKindTitles, rootControllerChoice, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureHelper, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
package/dist/38.js CHANGED
@@ -68,6 +68,32 @@ const layerImportRules = {
68
68
  };
69
69
  const baseName = (file)=>node_path.basename(file).replace(/\.[^.]+$/, '');
70
70
  const isOwnContract = (file, target)=>baseName(file).endsWith(`-${baseName(target)}`);
71
+ const helperOf = ([layer, kind, ...rest])=>'infrastructure' === layer && 'helpers' === kind && rest.length ? {
72
+ label: rest.length > 1 ? rest[0] : void 0
73
+ } : void 0;
74
+ const implementationLabelOf = ([layer, kind, label, ...rest])=>'infrastructure' === layer && [
75
+ 'repositories',
76
+ 'commands',
77
+ 'queries',
78
+ 'application-adapters'
79
+ ].includes(kind) && rest.length ? label : void 0;
80
+ const helperImportRule = (from, to, typeOnly)=>{
81
+ const fromHelper = helperOf(from);
82
+ const toHelper = helperOf(to);
83
+ if (toHelper && 'wiring' === from[0]) return 'wiring imports an infrastructure helper:';
84
+ if (fromHelper && !toHelper) {
85
+ const toKind = fileModuleKind(to);
86
+ if ('infrastructure' === to[0] || toKind && !(typeOnly && [
87
+ 'queries',
88
+ 'commands',
89
+ 'application-ports'
90
+ ].includes(toKind))) return 'an infrastructure helper imports a module (only domain models, other helpers and `import type` of query, command and port contracts):';
91
+ }
92
+ if (toHelper?.label) {
93
+ const label = fromHelper ? fromHelper.label : implementationLabelOf(from);
94
+ if ((fromHelper || label) && label !== toHelper.label) return 'imports a helper of another implementation:';
95
+ }
96
+ };
71
97
  const importViolations = (projectRoot, rootFolder, rules)=>{
72
98
  const root = node_path.resolve(projectRoot, rootFolder);
73
99
  const contextsFolder = node_path.join(root, 'bounded-contexts');
@@ -115,6 +141,14 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
115
141
  for (const file of files){
116
142
  const source = node_fs.readFileSync(file, 'utf8');
117
143
  const from = locate(file);
144
+ const helper = from && helperOf(from.segments);
145
+ if (helper && !helper.label) violations.push({
146
+ check: 'layers',
147
+ rule: `[${from.owner}] a helper outside the folder of its implementation (code shared by implementations is an infrastructure service):`,
148
+ file,
149
+ line: 1,
150
+ text: node_path.basename(file)
151
+ });
118
152
  const ownContext = inside(contextsFolder, file)?.[0];
119
153
  const directWiring = ownContext && from?.segments[0] === 'wiring' && readWiredModule(file, node_path.join(contextsFolder, ownContext))?.implementations.some((implementation)=>isCrossContextImplementation(implementation.file));
120
154
  const report = (check, rule, imported)=>violations.push({
@@ -153,6 +187,8 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
153
187
  if (!from || !to) continue;
154
188
  if (crossContextAllowed) continue;
155
189
  if (isSpec(file)) continue;
190
+ const helperRule = helperImportRule(from.segments, to.segments, imported.typeOnly);
191
+ if (helperRule) report('layers', `[${from.owner}] ${helperRule}`, imported);
156
192
  const fromKind = fileModuleKind(from.segments);
157
193
  const toKind = fileModuleKind(to.segments);
158
194
  if (fromKind && toKind) {
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 "./780.js";
6
- import { scaffoldNewHandlersRestEndpoint, addIntegration, findContracts, scaffoldNewAggregateUseCase, scaffoldNewInfrastructureService, scaffoldNewQuery, runWithAnswers, scaffoldNewCommand, moveBackendUnitUseCase, findReactModules, scaffoldReactUIKitComponent, scaffoldReactSharedHook, moveReactModuleUseCase, reactKindTitles, deleteBackendUnitUseCase, integrationIds, scaffoldNewApplicationService, scaffoldNewImplementation, savedImplementations, RequestError, deleteReactModuleUseCase, rootControllerChoice, moduleId, assertAnswersConsumed, scaffoldNewDomainService, findRestEndpointGenerator, scaffoldNewErrorUseCase, scaffoldReactWidget, savePendingChanges, unitId, systemImplementationChoices, scaffoldReactPage, scaffoldNewPresentationService, findBackendUnits, scaffoldNewUseCase, integrationDescriptions, wireDependency, scaffoldNewDomainObject, scaffoldNewBoundedContextUseCase, scaffoldNewApplicationPort } from "./287.js";
6
+ import { scaffoldNewHandlersRestEndpoint, addIntegration, findContracts, helperImplementationTypes, scaffoldNewAggregateUseCase, scaffoldNewInfrastructureService, runWithAnswers, scaffoldNewCommand, scaffoldNewQuery, findReactModules, moveBackendUnitUseCase, scaffoldReactUIKitComponent, scaffoldReactSharedHook, moveReactModuleUseCase, reactKindTitles, deleteBackendUnitUseCase, integrationIds, scaffoldNewApplicationService, scaffoldNewImplementation, savedImplementations, RequestError, deleteReactModuleUseCase, rootControllerChoice, moduleId, assertAnswersConsumed, scaffoldNewDomainService, findRestEndpointGenerator, scaffoldNewErrorUseCase, scaffoldReactWidget, savePendingChanges, unitId, systemImplementationChoices, scaffoldReactPage, scaffoldNewPresentationService, scaffoldNewInfrastructureHelper, findBackendUnits, scaffoldNewUseCase, integrationDescriptions, wireDependency, scaffoldNewDomainObject, scaffoldNewBoundedContextUseCase, scaffoldNewApplicationPort } from "./287.js";
7
7
  import { findWiredModules, availableDependencies, hasNeighboringBoundedContext } from "./947.js";
8
8
  import { restControllers } from "./526.js";
9
9
  const agent_requests_name = implementationLabelSchema;
@@ -75,6 +75,12 @@ const scaffoldRequestSchema = zod.discriminatedUnion('operation', [
75
75
  ...named,
76
76
  ...wired
77
77
  }),
78
+ agent_requests_operation('helper', {
79
+ ...common,
80
+ ...agent_requests_owner,
81
+ name: nestedName.describe('Kebab-case, folders split by "/": mappers/social-network-type.'),
82
+ implementationType: agent_requests_name.describe('A saved or system implementation type: a helper belongs to one.')
83
+ }),
78
84
  agent_requests_operation('presentation-service', {
79
85
  ...named,
80
86
  ...wired
@@ -399,6 +405,7 @@ const executeScaffold = async (request, owner)=>{
399
405
  ]).content.fileNames.includes(request.namespace)) throw new RequestError('TARGET_NOT_FOUND', `Unknown namespace: ${request.namespace}.`);
400
406
  if ('implementation' === request.operation && !findContracts(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No contracts in this context.');
401
407
  if (('move' === request.operation || 'delete' === request.operation) && !findBackendUnits(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No modules in this context.');
408
+ if ('helper' === request.operation && !helperImplementationTypes().length) throw new RequestError('TARGET_NOT_FOUND', 'No implementation types yet: add an implementation first.');
402
409
  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.');
403
410
  if ('endpoint' === request.operation) {
404
411
  if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers-rest') || !findRestEndpointGenerator(new Folder(requireProject()).subitem([
@@ -419,6 +426,7 @@ const executeScaffold = async (request, owner)=>{
419
426
  'domain-service': ()=>scaffoldNewDomainService(owner),
420
427
  'application-service': ()=>scaffoldNewApplicationService(owner),
421
428
  'infrastructure-service': ()=>scaffoldNewInfrastructureService(owner),
429
+ helper: ()=>scaffoldNewInfrastructureHelper(owner),
422
430
  'presentation-service': ()=>scaffoldNewPresentationService(owner),
423
431
  'use-case': ()=>scaffoldNewUseCase(owner),
424
432
  command: ()=>scaffoldNewCommand(owner),
package/dist/947.js CHANGED
@@ -212,7 +212,17 @@ const findWiredModules = (contextPath)=>{
212
212
  const moduleKindOf = (module)=>wiredModuleKind(module.kind);
213
213
  const layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
214
214
  const implementationType = (consumer, implementation)=>consumer.branched ? node_path.basename(node_path.dirname(implementation.file)) : void 0;
215
- const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${node_path.basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
215
+ const systemInfrastructureServices = new Map([
216
+ [
217
+ 'prisma',
218
+ 'prisma-infrastructure-service'
219
+ ],
220
+ [
221
+ 'in-memory',
222
+ 'in-memory-db-infrastructure-service'
223
+ ]
224
+ ]);
225
+ const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && node_path.basename(candidate.typeFile, '.ts') === systemInfrastructureServices.get(implementation);
216
226
  const canDependOn = (consumer, candidate, rules = defaultDependencyRules, implementation = consumer.implementations[0])=>{
217
227
  const crossContext = crossContextImportAllowed(consumer.wireFile, candidate.wireFile);
218
228
  if (void 0 !== crossContext) return crossContext && 'infrastructure' === consumer.implementationsLayer && 'application' === candidate.layer && !!implementation && true === crossContextImportAllowed(implementation.file, candidate.typeFile);
@@ -90,6 +90,13 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
90
90
  context: z.ZodString;
91
91
  overwrite: z.ZodOptional<z.ZodBoolean>;
92
92
  dryRun: z.ZodOptional<z.ZodBoolean>;
93
+ }, z.core.$strict>, z.ZodObject<{
94
+ operation: z.ZodLiteral<"helper">;
95
+ name: z.ZodString;
96
+ implementationType: z.ZodString;
97
+ context: z.ZodString;
98
+ overwrite: z.ZodOptional<z.ZodBoolean>;
99
+ dryRun: z.ZodOptional<z.ZodBoolean>;
93
100
  }, z.core.$strict>, z.ZodObject<{
94
101
  operation: z.ZodLiteral<"presentation-service">;
95
102
  dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
@@ -272,9 +279,9 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
272
279
  }, z.core.$strict>], "operation"> | z.ZodObject<{
273
280
  operation: z.ZodLiteral<"add">;
274
281
  integrations: z.ZodArray<z.ZodEnum<{
282
+ prisma: "prisma";
275
283
  openapi: "openapi";
276
284
  orval: "orval";
277
- prisma: "prisma";
278
285
  "rest-endpoint-generator": "rest-endpoint-generator";
279
286
  storybook: "storybook";
280
287
  vitest: "vitest";
@@ -379,7 +386,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
379
386
  } | undefined;
380
387
  }[];
381
388
  integrations: {
382
- id: "openapi" | "orval" | "prisma" | "rest-endpoint-generator" | "storybook" | "vitest" | "testcontainers" | "in-memory-db" | "playwright";
389
+ id: "prisma" | "openapi" | "orval" | "rest-endpoint-generator" | "storybook" | "vitest" | "testcontainers" | "in-memory-db" | "playwright";
383
390
  name: string;
384
391
  group: "backend" | "frontend";
385
392
  available: boolean;