@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.
- package/README.md +1 -1
- package/bin/df-skills.mjs +55 -9
- package/dist/287.js +44 -138
- package/dist/38.js +36 -0
- package/dist/561.js +9 -1
- package/dist/947.js +11 -1
- package/dist/agent-cli.d.ts +9 -2
- package/dist/agent-principles.cjs +116 -0
- package/dist/agent-principles.d.ts +9 -0
- package/dist/agent-principles.js +64 -0
- package/dist/agent-principles.spec.d.ts +1 -0
- package/dist/agent-requests.d.ts +16 -2
- package/dist/graph.cjs +10 -0
- package/dist/in-memory-db.d.ts +1 -6
- package/dist/index.cjs +64 -137
- package/dist/index.js +4 -1
- package/dist/init.cjs +12 -21
- package/dist/integration.cjs +61 -137
- package/dist/lint.cjs +46 -0
- package/dist/react.cjs +61 -137
- package/dist/use-cases/add-integration.d.ts +1 -1
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/scaffold-new-infrastructure-helper.d.ts +7 -0
- package/dist/wiring.d.ts +2 -2
- package/package.json +3 -2
- package/principles/df-principles.md +33 -0
- package/skills/df-ps-implement/SKILL.md +26 -1
- package/skills/df-ps-plan-feature/SKILL.md +22 -18
- package/skills/df-ps-react/SKILL.md +2 -9
- package/skills/df-ps-react/references/generators.md +9 -9
- package/skills/df-ps-scaffold/SKILL.md +20 -126
- package/skills/df-ps-scaffold/references/agent-mode.md +2 -2
- package/skills/df-ps-scaffold/references/agent-operations.md +1 -0
- package/skills/df-ps-scaffold/references/choosing-components.md +65 -49
- package/skills/df-ps-scaffold/references/generators.md +33 -11
- package/skills/df-ps-scaffold/references/units/aggregate.md +3 -5
- package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
- package/skills/df-ps-scaffold/references/units/command-query.md +6 -8
- package/skills/df-ps-scaffold/references/units/delete.md +0 -2
- package/skills/df-ps-scaffold/references/units/endpoint.md +1 -4
- package/skills/df-ps-scaffold/references/units/entity-value-object.md +0 -4
- package/skills/df-ps-scaffold/references/units/errors.md +0 -4
- package/skills/df-ps-scaffold/references/units/helper.md +30 -0
- package/skills/df-ps-scaffold/references/units/implementation.md +1 -5
- package/skills/df-ps-scaffold/references/units/move-or-rename.md +0 -4
- package/skills/df-ps-scaffold/references/units/port.md +3 -6
- package/skills/df-ps-scaffold/references/units/services.md +4 -6
- package/skills/df-ps-scaffold/references/units/use-case.md +1 -2
- package/skills/df-ps-scaffold/references/units/wire-dependency.md +0 -2
- package/skills/df-ps-scaffold/references/work-plan.md +73 -0
- package/skills/df-ps-scaffold/scripts/drive.mjs +0 -252
package/dist/init.cjs
CHANGED
|
@@ -268,14 +268,14 @@ class file_system_File extends FileSystemItem {
|
|
|
268
268
|
if (!alreadyAdded) this.addLine(newLine, separator);
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
|
-
const
|
|
271
|
+
const implementation_options_schema_implementationKinds = [
|
|
272
272
|
'repositories',
|
|
273
273
|
'commands',
|
|
274
274
|
'queries',
|
|
275
275
|
'ports'
|
|
276
276
|
];
|
|
277
277
|
const implementation_options_schema_implementationLabelSchema = external_zod_default().string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/);
|
|
278
|
-
const implementationOptionsSchema = external_zod_default().partialRecord(external_zod_default()["enum"](
|
|
278
|
+
const implementationOptionsSchema = external_zod_default().partialRecord(external_zod_default()["enum"](implementation_options_schema_implementationKinds), external_zod_default().object({
|
|
279
279
|
primary: external_zod_default().array(implementation_options_schema_implementationLabelSchema).default([]),
|
|
280
280
|
test: external_zod_default().array(implementation_options_schema_implementationLabelSchema).default([])
|
|
281
281
|
}).strict());
|
|
@@ -631,6 +631,16 @@ const save_pending_changes_savePendingChanges = async ()=>{
|
|
|
631
631
|
writePendingChanges();
|
|
632
632
|
return true;
|
|
633
633
|
};
|
|
634
|
+
new Map([
|
|
635
|
+
[
|
|
636
|
+
'prisma',
|
|
637
|
+
'prisma-infrastructure-service'
|
|
638
|
+
],
|
|
639
|
+
[
|
|
640
|
+
'in-memory',
|
|
641
|
+
'in-memory-db-infrastructure-service'
|
|
642
|
+
]
|
|
643
|
+
]);
|
|
634
644
|
const wiring_relativeImport = (fromFile, toFile)=>{
|
|
635
645
|
const relativePath = external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile).replace(/\.ts$/, '').split(external_node_path_default().sep).join('/');
|
|
636
646
|
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
@@ -750,32 +760,13 @@ export const wireInMemoryDbInfrastructureService = wireClass(
|
|
|
750
760
|
[]
|
|
751
761
|
);
|
|
752
762
|
`;
|
|
753
|
-
const inMemoryDbSpec = (testingLibrary, withWiring)=>`
|
|
754
|
-
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
755
|
-
${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
|
|
756
|
-
import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
|
|
757
|
-
|
|
758
|
-
let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
|
|
759
|
-
|
|
760
|
-
beforeEach(() => {
|
|
761
|
-
inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
|
|
762
|
-
})
|
|
763
|
-
|
|
764
|
-
describe('in memory db', () => {
|
|
765
|
-
test('can be ${withWiring ? 'wired' : 'created'}', () => {
|
|
766
|
-
expect(inMemoryDbInfrastructureService).toBeDefined()
|
|
767
|
-
})
|
|
768
|
-
})
|
|
769
|
-
`.trim();
|
|
770
763
|
const in_memory_db_withWiring = ()=>config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
771
764
|
const in_memory_db_scaffoldInMemoryDb = (shared)=>{
|
|
772
|
-
const { testingLibrary } = config_file_ConfigFile.backend;
|
|
773
765
|
const servicesFolder = shared.subitem([
|
|
774
766
|
'infrastructure',
|
|
775
767
|
'services'
|
|
776
768
|
]);
|
|
777
769
|
servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
|
|
778
|
-
if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
|
|
779
770
|
if (in_memory_db_withWiring()) shared.subitem([
|
|
780
771
|
'wiring',
|
|
781
772
|
'infrastructure-services'
|
package/dist/integration.cjs
CHANGED
|
@@ -640,7 +640,17 @@ const findWiredModules = (contextPath)=>{
|
|
|
640
640
|
const moduleKindOf = (module)=>wiredModuleKind(module.kind);
|
|
641
641
|
const layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
|
|
642
642
|
const wiring_implementationType = (consumer, implementation)=>consumer.branched ? external_node_path_default().basename(external_node_path_default().dirname(implementation.file)) : void 0;
|
|
643
|
-
const
|
|
643
|
+
const systemInfrastructureServices = new Map([
|
|
644
|
+
[
|
|
645
|
+
'prisma',
|
|
646
|
+
'prisma-infrastructure-service'
|
|
647
|
+
],
|
|
648
|
+
[
|
|
649
|
+
'in-memory',
|
|
650
|
+
'in-memory-db-infrastructure-service'
|
|
651
|
+
]
|
|
652
|
+
]);
|
|
653
|
+
const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && external_node_path_default().basename(candidate.typeFile, '.ts') === systemInfrastructureServices.get(implementation);
|
|
644
654
|
const canDependOn = (consumer, candidate, rules = defaultDependencyRules, implementation = consumer.implementations[0])=>{
|
|
645
655
|
const crossContext = crossContextImportAllowed(consumer.wireFile, candidate.wireFile);
|
|
646
656
|
if (void 0 !== crossContext) return crossContext && 'infrastructure' === consumer.implementationsLayer && 'application' === candidate.layer && !!implementation && true === crossContextImportAllowed(implementation.file, candidate.typeFile);
|
|
@@ -1012,23 +1022,6 @@ export const wireInMemoryDbInfrastructureService = wireClass(
|
|
|
1012
1022
|
[]
|
|
1013
1023
|
);
|
|
1014
1024
|
`;
|
|
1015
|
-
const inMemoryDbSpec = (testingLibrary, withWiring)=>`
|
|
1016
|
-
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
1017
|
-
${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
|
|
1018
|
-
import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
|
|
1019
|
-
|
|
1020
|
-
let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
|
|
1021
|
-
|
|
1022
|
-
beforeEach(() => {
|
|
1023
|
-
inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
|
|
1024
|
-
})
|
|
1025
|
-
|
|
1026
|
-
describe('in memory db', () => {
|
|
1027
|
-
test('can be ${withWiring ? 'wired' : 'created'}', () => {
|
|
1028
|
-
expect(inMemoryDbInfrastructureService).toBeDefined()
|
|
1029
|
-
})
|
|
1030
|
-
})
|
|
1031
|
-
`.trim();
|
|
1032
1025
|
const in_memory_db_withWiring = ()=>config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
1033
1026
|
const in_memory_db_sharedFolder = ()=>new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
1034
1027
|
config_file_ConfigFile.Instance.data.project.rootFolder,
|
|
@@ -1045,13 +1038,11 @@ const in_memory_db_wireFile = ()=>new file_system_File(in_memory_db_sharedFolder
|
|
|
1045
1038
|
'wire-in-memory-db-infrastructure-service.ts'
|
|
1046
1039
|
]);
|
|
1047
1040
|
const in_memory_db_scaffoldInMemoryDb = (shared)=>{
|
|
1048
|
-
const { testingLibrary } = config_file_ConfigFile.backend;
|
|
1049
1041
|
const servicesFolder = shared.subitem([
|
|
1050
1042
|
'infrastructure',
|
|
1051
1043
|
'services'
|
|
1052
1044
|
]);
|
|
1053
1045
|
servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
|
|
1054
|
-
if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
|
|
1055
1046
|
if (in_memory_db_withWiring()) shared.subitem([
|
|
1056
1047
|
'wiring',
|
|
1057
1048
|
'infrastructure-services'
|
|
@@ -1113,9 +1104,6 @@ const wireInMemoryDb = (consumerWireFile, implementationName)=>{
|
|
|
1113
1104
|
in_memory_db_wireName
|
|
1114
1105
|
]));
|
|
1115
1106
|
};
|
|
1116
|
-
const passInMemoryDb = (specFile, implementationName)=>{
|
|
1117
|
-
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}())`));
|
|
1118
|
-
};
|
|
1119
1107
|
const addInMemoryDb = ()=>{
|
|
1120
1108
|
const config = config_file_ConfigFile.Instance.data;
|
|
1121
1109
|
if (!config_file_ConfigFile.backend.withInMemoryDb) config_file_ConfigFile.update({
|
|
@@ -3176,6 +3164,12 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3176
3164
|
...named,
|
|
3177
3165
|
...agent_requests_wired
|
|
3178
3166
|
}),
|
|
3167
|
+
agent_requests_operation('helper', {
|
|
3168
|
+
...common,
|
|
3169
|
+
...agent_requests_owner,
|
|
3170
|
+
name: agent_requests_nestedName.describe('Kebab-case, folders split by "/": mappers/social-network-type.'),
|
|
3171
|
+
implementationType: agent_requests_name.describe('A saved or system implementation type: a helper belongs to one.')
|
|
3172
|
+
}),
|
|
3179
3173
|
agent_requests_operation('presentation-service', {
|
|
3180
3174
|
...named,
|
|
3181
3175
|
...agent_requests_wired
|
|
@@ -4697,29 +4691,6 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
4697
4691
|
labels: []
|
|
4698
4692
|
};
|
|
4699
4693
|
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, repository, new UnknownFormatNaming(implementation).fileName);
|
|
4700
|
-
if (scaffoldUnitTests) {
|
|
4701
|
-
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
4702
|
-
const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
4703
|
-
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
|
|
4704
|
-
${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
|
|
4705
|
-
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'
|
|
4706
|
-
|
|
4707
|
-
type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`}
|
|
4708
|
-
|
|
4709
|
-
let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
|
|
4710
|
-
|
|
4711
|
-
beforeEach(() => {
|
|
4712
|
-
${aggregateNaming.variableName}Repository = ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${aggregateNaming.ClassName}Repository()` : `new ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository()`}
|
|
4713
|
-
})
|
|
4714
|
-
|
|
4715
|
-
describe('${aggregateNaming.withSpaces} repository', () => {
|
|
4716
|
-
test('can be ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
4717
|
-
expect(${aggregateNaming.variableName}Repository).toBeDefined()
|
|
4718
|
-
})
|
|
4719
|
-
})
|
|
4720
|
-
`.trim());
|
|
4721
|
-
if (!config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
|
|
4722
|
-
}
|
|
4723
4694
|
if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
4724
4695
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
4725
4696
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
@@ -4745,7 +4716,6 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
|
4745
4716
|
message: 'Name: '
|
|
4746
4717
|
});
|
|
4747
4718
|
const naming = new UnknownFormatNaming(name);
|
|
4748
|
-
const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
|
|
4749
4719
|
const wiringFolder = boundedContextFolder.subitem([
|
|
4750
4720
|
'wiring',
|
|
4751
4721
|
'application-ports'
|
|
@@ -4785,28 +4755,6 @@ export abstract class ${naming.ClassName} {
|
|
|
4785
4755
|
ownerPath: boundedContextFolder.path,
|
|
4786
4756
|
labels: []
|
|
4787
4757
|
}, implementation);
|
|
4788
|
-
if (scaffoldUnitTests) {
|
|
4789
|
-
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
4790
|
-
applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
4791
|
-
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
|
|
4792
|
-
${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
|
|
4793
|
-
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}'
|
|
4794
|
-
|
|
4795
|
-
type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`}
|
|
4796
|
-
|
|
4797
|
-
let ${naming.variableName}: ${naming.ClassName}
|
|
4798
|
-
|
|
4799
|
-
beforeEach(() => {
|
|
4800
|
-
${naming.variableName} = ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${naming.ClassName}()` : `new ${implementationNaming.ClassName}${naming.ClassName}()`}
|
|
4801
|
-
})
|
|
4802
|
-
|
|
4803
|
-
describe('${naming.withSpaces}', () => {
|
|
4804
|
-
test('can be ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
4805
|
-
expect(${naming.variableName}).toBeDefined()
|
|
4806
|
-
})
|
|
4807
|
-
})
|
|
4808
|
-
`.trim());
|
|
4809
|
-
}
|
|
4810
4758
|
if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
4811
4759
|
const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
|
|
4812
4760
|
import { wireClass } from '@domain-first/wire'
|
|
@@ -4902,9 +4850,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
4902
4850
|
key: 'name',
|
|
4903
4851
|
message: 'Name: '
|
|
4904
4852
|
});
|
|
4905
|
-
const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
|
|
4906
4853
|
const naming = new UnknownFormatNaming(commandName);
|
|
4907
|
-
const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
4908
4854
|
const { label: implementationType } = await promptImplementationType('Command infrastructure implementation type:', 'commands');
|
|
4909
4855
|
let addTestImplementation = false;
|
|
4910
4856
|
let testImplementationType = '';
|
|
@@ -4942,29 +4888,6 @@ export abstract class ${naming.ClassName}Command {
|
|
|
4942
4888
|
export abstract class ${naming.ClassName}Command {
|
|
4943
4889
|
|
|
4944
4890
|
}`.trim());
|
|
4945
|
-
if (scaffoldUnitTests) {
|
|
4946
|
-
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
4947
|
-
const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
|
|
4948
|
-
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
|
|
4949
|
-
${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
|
|
4950
|
-
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'
|
|
4951
|
-
|
|
4952
|
-
type ${naming.ClassName}Command = ${implementationNaming.ClassName}${naming.ClassName}Command`}
|
|
4953
|
-
|
|
4954
|
-
let ${naming.variableName}Command: ${naming.ClassName}Command
|
|
4955
|
-
|
|
4956
|
-
beforeEach(() => {
|
|
4957
|
-
${naming.variableName}Command = ${withWiring ? `wire${naming.ClassName}Command()` : `new ${implementationNaming.ClassName}${naming.ClassName}Command()`}
|
|
4958
|
-
})
|
|
4959
|
-
|
|
4960
|
-
describe('${naming.withSpaces} command', () => {
|
|
4961
|
-
test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
|
|
4962
|
-
expect(${naming.variableName}Command).toBeDefined()
|
|
4963
|
-
})
|
|
4964
|
-
})
|
|
4965
|
-
`.trim());
|
|
4966
|
-
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
|
|
4967
|
-
}
|
|
4968
4891
|
if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
4969
4892
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
4970
4893
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
@@ -5414,13 +5337,54 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
5414
5337
|
for (const implementation of unused)report(`${implementation.className} is no longer used in any environment.`);
|
|
5415
5338
|
await wireNewImplementationDependencies(ownerFolder, wireFile, className, inMemoryRepositoryWiring(ownerFolder, unit, wireFile));
|
|
5416
5339
|
};
|
|
5340
|
+
const helperImplementationTypes = ()=>[
|
|
5341
|
+
...new Set(implementationKinds.flatMap((kind)=>[
|
|
5342
|
+
...savedImplementations(kind, 'primary'),
|
|
5343
|
+
...savedImplementations(kind, 'test'),
|
|
5344
|
+
...systemImplementationChoices(kind).map(({ value })=>value)
|
|
5345
|
+
]))
|
|
5346
|
+
].filter((label)=>label !== crossContextImplementation);
|
|
5347
|
+
const validateName = (value)=>{
|
|
5348
|
+
const valid = NestedName.validate(value);
|
|
5349
|
+
if (true !== valid) return valid;
|
|
5350
|
+
const { folders, folderName } = new NestedName(value);
|
|
5351
|
+
return [
|
|
5352
|
+
...folders,
|
|
5353
|
+
folderName
|
|
5354
|
+
].every((part)=>kebabName.test(part)) ? true : 'Use lowercase kebab-case split by "/", e.g. mappers/social-network-type';
|
|
5355
|
+
};
|
|
5356
|
+
const scaffoldNewInfrastructureHelper = async (ownerFolder)=>{
|
|
5357
|
+
const types = helperImplementationTypes();
|
|
5358
|
+
if (!types.length) return void report('No implementation types yet: a helper belongs to one, so add an implementation first.');
|
|
5359
|
+
const name = new NestedName(await interaction_input({
|
|
5360
|
+
key: 'name',
|
|
5361
|
+
message: 'Name (folders split by "/"): ',
|
|
5362
|
+
validate: validateName
|
|
5363
|
+
}));
|
|
5364
|
+
const label = await interaction_select({
|
|
5365
|
+
key: 'implementationType',
|
|
5366
|
+
message: 'Implementation:',
|
|
5367
|
+
choices: types.map((value)=>({
|
|
5368
|
+
name: value,
|
|
5369
|
+
value
|
|
5370
|
+
}))
|
|
5371
|
+
});
|
|
5372
|
+
const fileName = name.folderName.startsWith(`${label}-`) ? name.folderName : `${label}-${name.folderName}`;
|
|
5373
|
+
const naming = new UnknownFormatNaming(fileName);
|
|
5374
|
+
const folder = ownerFolder.subitem([
|
|
5375
|
+
'infrastructure',
|
|
5376
|
+
'helpers',
|
|
5377
|
+
label,
|
|
5378
|
+
...name.folders
|
|
5379
|
+
]);
|
|
5380
|
+
folder.createFile(`${fileName}.ts`, `export const ${naming.variableName} = () => {}`);
|
|
5381
|
+
};
|
|
5417
5382
|
const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
|
|
5418
5383
|
const name = await interaction_input({
|
|
5419
5384
|
key: 'name',
|
|
5420
5385
|
message: 'Name: '
|
|
5421
5386
|
});
|
|
5422
5387
|
const naming = new UnknownFormatNaming(name);
|
|
5423
|
-
const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
|
|
5424
5388
|
const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
5425
5389
|
const wiringFolder = boundedContextFolder.subitem([
|
|
5426
5390
|
'wiring',
|
|
@@ -5435,23 +5399,6 @@ export class ${naming.ClassName}InfrastructureService {
|
|
|
5435
5399
|
|
|
5436
5400
|
}
|
|
5437
5401
|
`.trim());
|
|
5438
|
-
if (scaffoldUnitTests) infrastructureServicesFolder.createFile(`${naming.fileName}-infrastructure-service.spec.ts`, `
|
|
5439
|
-
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
|
|
5440
|
-
${withWiring ? `import { type ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'
|
|
5441
|
-
import { wire${naming.ClassName}InfrastructureService } from '../../wiring/infrastructure-services/wire-${naming.fileName}-infrastructure-service'` : `import { ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'`}
|
|
5442
|
-
|
|
5443
|
-
let ${naming.variableName}InfrastructureService: ${naming.ClassName}InfrastructureService
|
|
5444
|
-
|
|
5445
|
-
beforeEach(() => {
|
|
5446
|
-
${naming.variableName}InfrastructureService = ${withWiring ? `wire${naming.ClassName}InfrastructureService()` : `new ${naming.ClassName}InfrastructureService()`}
|
|
5447
|
-
})
|
|
5448
|
-
|
|
5449
|
-
describe('${naming.withSpaces}', () => {
|
|
5450
|
-
test('can be ${withWiring ? 'wired' : 'created'}', () => {
|
|
5451
|
-
expect(${naming.variableName}InfrastructureService).toBeDefined()
|
|
5452
|
-
})
|
|
5453
|
-
})
|
|
5454
|
-
`.trim());
|
|
5455
5402
|
if (withWiring) {
|
|
5456
5403
|
const wireFile = wiringFolder.createFile(`wire-${naming.fileName}-infrastructure-service.ts`, `
|
|
5457
5404
|
import { wireClass } from '@domain-first/wire'
|
|
@@ -5474,9 +5421,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
5474
5421
|
key: 'name',
|
|
5475
5422
|
message: 'Name: '
|
|
5476
5423
|
});
|
|
5477
|
-
const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
|
|
5478
5424
|
const naming = new UnknownFormatNaming(queryName);
|
|
5479
|
-
const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
5480
5425
|
const { label: implementationType } = await promptImplementationType('Query infrastructure implementation type:', 'queries');
|
|
5481
5426
|
let addTestImplementation = false;
|
|
5482
5427
|
let testImplementationType = '';
|
|
@@ -5514,29 +5459,6 @@ export abstract class ${naming.ClassName}Query {
|
|
|
5514
5459
|
export abstract class ${naming.ClassName}Query {
|
|
5515
5460
|
|
|
5516
5461
|
}`.trim());
|
|
5517
|
-
if (scaffoldUnitTests) {
|
|
5518
|
-
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
5519
|
-
const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
|
|
5520
|
-
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
|
|
5521
|
-
${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
|
|
5522
|
-
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'
|
|
5523
|
-
|
|
5524
|
-
type ${naming.ClassName}Query = ${implementationNaming.ClassName}${naming.ClassName}Query`}
|
|
5525
|
-
|
|
5526
|
-
let ${naming.variableName}Query: ${naming.ClassName}Query
|
|
5527
|
-
|
|
5528
|
-
beforeEach(() => {
|
|
5529
|
-
${naming.variableName}Query = ${withWiring ? `wire${naming.ClassName}Query()` : `new ${implementationNaming.ClassName}${naming.ClassName}Query()`}
|
|
5530
|
-
})
|
|
5531
|
-
|
|
5532
|
-
describe('${naming.withSpaces} query', () => {
|
|
5533
|
-
test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
|
|
5534
|
-
expect(${naming.variableName}Query).toBeDefined()
|
|
5535
|
-
})
|
|
5536
|
-
})
|
|
5537
|
-
`.trim());
|
|
5538
|
-
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
|
|
5539
|
-
}
|
|
5540
5462
|
if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
5541
5463
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
5542
5464
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
@@ -5986,6 +5908,7 @@ const executeScaffold = async (request, owner)=>{
|
|
|
5986
5908
|
]).content.fileNames.includes(request.namespace)) throw new RequestError('TARGET_NOT_FOUND', `Unknown namespace: ${request.namespace}.`);
|
|
5987
5909
|
if ('implementation' === request.operation && !findContracts(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No contracts in this context.');
|
|
5988
5910
|
if (('move' === request.operation || 'delete' === request.operation) && !findBackendUnits(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No modules in this context.');
|
|
5911
|
+
if ('helper' === request.operation && !helperImplementationTypes().length) throw new RequestError('TARGET_NOT_FOUND', 'No implementation types yet: add an implementation first.');
|
|
5989
5912
|
if ('wire-dependency' === request.operation && (!config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') || !findWiredModules(owner.path).length)) throw new RequestError('TARGET_NOT_FOUND', 'No wired modules in this context.');
|
|
5990
5913
|
if ('endpoint' === request.operation) {
|
|
5991
5914
|
if (!config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers-rest') || !findRestEndpointGenerator(new file_system_Folder(requireProject()).subitem([
|
|
@@ -6006,6 +5929,7 @@ const executeScaffold = async (request, owner)=>{
|
|
|
6006
5929
|
'domain-service': ()=>scaffoldNewDomainService(owner),
|
|
6007
5930
|
'application-service': ()=>scaffoldNewApplicationService(owner),
|
|
6008
5931
|
'infrastructure-service': ()=>scaffoldNewInfrastructureService(owner),
|
|
5932
|
+
helper: ()=>scaffoldNewInfrastructureHelper(owner),
|
|
6009
5933
|
'presentation-service': ()=>scaffoldNewPresentationService(owner),
|
|
6010
5934
|
'use-case': ()=>scaffoldNewUseCase(owner),
|
|
6011
5935
|
command: ()=>scaffoldNewCommand(owner),
|
package/dist/lint.cjs
CHANGED
|
@@ -579,6 +579,16 @@ const findWiredModules = (contextPath)=>{
|
|
|
579
579
|
};
|
|
580
580
|
const moduleKindOf = (module)=>wiredModuleKind(module.kind);
|
|
581
581
|
const wiring_layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
|
|
582
|
+
new Map([
|
|
583
|
+
[
|
|
584
|
+
'prisma',
|
|
585
|
+
'prisma-infrastructure-service'
|
|
586
|
+
],
|
|
587
|
+
[
|
|
588
|
+
'in-memory',
|
|
589
|
+
'in-memory-db-infrastructure-service'
|
|
590
|
+
]
|
|
591
|
+
]);
|
|
582
592
|
const canDependOn = (consumer, candidate, rules = defaultDependencyRules, implementation = consumer.implementations[0])=>{
|
|
583
593
|
const crossContext = context_dependencies_crossContextImportAllowed(consumer.wireFile, candidate.wireFile);
|
|
584
594
|
if (void 0 !== crossContext) return crossContext && 'infrastructure' === consumer.implementationsLayer && 'application' === candidate.layer && !!implementation && true === context_dependencies_crossContextImportAllowed(implementation.file, candidate.typeFile);
|
|
@@ -736,6 +746,32 @@ const layerImportRules = {
|
|
|
736
746
|
};
|
|
737
747
|
const baseName = (file)=>external_node_path_default().basename(file).replace(/\.[^.]+$/, '');
|
|
738
748
|
const isOwnContract = (file, target)=>baseName(file).endsWith(`-${baseName(target)}`);
|
|
749
|
+
const helperOf = ([layer, kind, ...rest])=>'infrastructure' === layer && 'helpers' === kind && rest.length ? {
|
|
750
|
+
label: rest.length > 1 ? rest[0] : void 0
|
|
751
|
+
} : void 0;
|
|
752
|
+
const implementationLabelOf = ([layer, kind, label, ...rest])=>'infrastructure' === layer && [
|
|
753
|
+
'repositories',
|
|
754
|
+
'commands',
|
|
755
|
+
'queries',
|
|
756
|
+
'application-adapters'
|
|
757
|
+
].includes(kind) && rest.length ? label : void 0;
|
|
758
|
+
const helperImportRule = (from, to, typeOnly)=>{
|
|
759
|
+
const fromHelper = helperOf(from);
|
|
760
|
+
const toHelper = helperOf(to);
|
|
761
|
+
if (toHelper && 'wiring' === from[0]) return 'wiring imports an infrastructure helper:';
|
|
762
|
+
if (fromHelper && !toHelper) {
|
|
763
|
+
const toKind = fileModuleKind(to);
|
|
764
|
+
if ('infrastructure' === to[0] || toKind && !(typeOnly && [
|
|
765
|
+
'queries',
|
|
766
|
+
'commands',
|
|
767
|
+
'application-ports'
|
|
768
|
+
].includes(toKind))) return 'an infrastructure helper imports a module (only domain models, other helpers and `import type` of query, command and port contracts):';
|
|
769
|
+
}
|
|
770
|
+
if (toHelper?.label) {
|
|
771
|
+
const label = fromHelper ? fromHelper.label : implementationLabelOf(from);
|
|
772
|
+
if ((fromHelper || label) && label !== toHelper.label) return 'imports a helper of another implementation:';
|
|
773
|
+
}
|
|
774
|
+
};
|
|
739
775
|
const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
740
776
|
const root = external_node_path_default().resolve(projectRoot, rootFolder);
|
|
741
777
|
const contextsFolder = external_node_path_default().join(root, 'bounded-contexts');
|
|
@@ -783,6 +819,14 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
783
819
|
for (const file of files){
|
|
784
820
|
const source = external_node_fs_default().readFileSync(file, 'utf8');
|
|
785
821
|
const from = locate(file);
|
|
822
|
+
const helper = from && helperOf(from.segments);
|
|
823
|
+
if (helper && !helper.label) violations.push({
|
|
824
|
+
check: 'layers',
|
|
825
|
+
rule: `[${from.owner}] a helper outside the folder of its implementation (code shared by implementations is an infrastructure service):`,
|
|
826
|
+
file,
|
|
827
|
+
line: 1,
|
|
828
|
+
text: external_node_path_default().basename(file)
|
|
829
|
+
});
|
|
786
830
|
const ownContext = inside(contextsFolder, file)?.[0];
|
|
787
831
|
const directWiring = ownContext && from?.segments[0] === 'wiring' && readWiredModule(file, external_node_path_default().join(contextsFolder, ownContext))?.implementations.some((implementation)=>isCrossContextImplementation(implementation.file));
|
|
788
832
|
const report = (check, rule, imported)=>violations.push({
|
|
@@ -821,6 +865,8 @@ const importViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
821
865
|
if (!from || !to) continue;
|
|
822
866
|
if (crossContextAllowed) continue;
|
|
823
867
|
if (isSpec(file)) continue;
|
|
868
|
+
const helperRule = helperImportRule(from.segments, to.segments, imported.typeOnly);
|
|
869
|
+
if (helperRule) report('layers', `[${from.owner}] ${helperRule}`, imported);
|
|
824
870
|
const fromKind = fileModuleKind(from.segments);
|
|
825
871
|
const toKind = fileModuleKind(to.segments);
|
|
826
872
|
if (fromKind && toKind) {
|