@domain-first/project-structure 7.1.1 → 7.2.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 +4 -0
- package/dist/201.js +61 -6
- package/dist/287.js +255 -134
- package/dist/backend-module-move.d.ts +1 -0
- package/dist/implementations.d.ts +48 -0
- package/dist/index.cjs +313 -134
- package/dist/index.js +5 -2
- package/dist/lint.cjs +8 -5
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/scaffold-new-aggregate.d.ts +1 -1
- package/dist/use-cases/scaffold-new-implementation.d.ts +6 -0
- package/dist/use-cases/scaffold-new-implementation.spec.d.ts +1 -0
- package/dist/use-cases/wire-dependency.d.ts +5 -0
- package/dist/wiring.d.ts +21 -0
- package/package.json +1 -1
- package/skills/df-ps-scaffold/SKILL.md +3 -2
- package/skills/df-ps-scaffold/references/choosing-components.md +1 -0
- package/skills/df-ps-scaffold/references/units/implementation.md +20 -0
package/dist/index.cjs
CHANGED
|
@@ -579,9 +579,9 @@ const closingIndex = (source, openIndex)=>{
|
|
|
579
579
|
}
|
|
580
580
|
return -1;
|
|
581
581
|
};
|
|
582
|
-
const
|
|
582
|
+
const topLevelItemRanges = (content)=>{
|
|
583
583
|
const code = codeOnly(content);
|
|
584
|
-
const
|
|
584
|
+
const ranges = [];
|
|
585
585
|
let depth = 0;
|
|
586
586
|
let itemStart = 0;
|
|
587
587
|
for(let index = 0; index <= code.length; index++){
|
|
@@ -589,16 +589,19 @@ const splitTopLevel = (content)=>{
|
|
|
589
589
|
if (void 0 !== char && char in brackets) depth++;
|
|
590
590
|
else if (Object.values(brackets).includes(char)) depth--;
|
|
591
591
|
if (index === code.length || ',' === char && 0 === depth) {
|
|
592
|
-
const item = content.slice(itemStart, index);
|
|
593
592
|
const itemCode = code.slice(itemStart, index);
|
|
594
593
|
const first = itemCode.search(/\S/);
|
|
595
594
|
const last = itemCode.search(/\S\s*$/);
|
|
596
|
-
if (-1 !== first)
|
|
595
|
+
if (-1 !== first) ranges.push({
|
|
596
|
+
start: itemStart + first,
|
|
597
|
+
end: itemStart + last + 1
|
|
598
|
+
});
|
|
597
599
|
itemStart = index + 1;
|
|
598
600
|
}
|
|
599
601
|
}
|
|
600
|
-
return
|
|
602
|
+
return ranges;
|
|
601
603
|
};
|
|
604
|
+
const splitTopLevel = (content)=>topLevelItemRanges(content).map(({ start, end })=>content.slice(start, end));
|
|
602
605
|
const appendItems = (content, items)=>{
|
|
603
606
|
const code = codeOnly(content);
|
|
604
607
|
const lastCode = code.search(/\S\s*$/);
|
|
@@ -677,6 +680,58 @@ const wireDependencies = (consumer, implementation, dependencies)=>{
|
|
|
677
680
|
for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${wiring_relativeImport(implementation.file, dependency.typeFile)}'`);
|
|
678
681
|
classFile.update(addConstructorParameters(classSource, implementation.className, dependencies.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
|
|
679
682
|
};
|
|
683
|
+
const branchesRange = (source, wireName)=>{
|
|
684
|
+
const match = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*envBranchedWire\\(\\s*\\{`).exec(codeOnly(source));
|
|
685
|
+
if (!match) throw new Error(`${wireName} = envBranchedWire({...}) not found`);
|
|
686
|
+
const openIndex = match.index + match[0].length - 1;
|
|
687
|
+
return {
|
|
688
|
+
declarationIndex: match.index,
|
|
689
|
+
openIndex,
|
|
690
|
+
closeIndex: closingIndex(source, openIndex)
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
const branchItems = (content)=>topLevelItemRanges(content).map(({ start, end })=>{
|
|
694
|
+
const item = content.slice(start, end);
|
|
695
|
+
const colon = codeOnly(item).indexOf(':');
|
|
696
|
+
if (-1 === colon) return {
|
|
697
|
+
key: item,
|
|
698
|
+
valueStart: start,
|
|
699
|
+
end,
|
|
700
|
+
shorthand: true
|
|
701
|
+
};
|
|
702
|
+
const valueStart = start + colon + 1 + item.slice(colon + 1).search(/\S/);
|
|
703
|
+
return {
|
|
704
|
+
key: item.slice(0, colon).trim(),
|
|
705
|
+
valueStart,
|
|
706
|
+
end,
|
|
707
|
+
shorthand: false
|
|
708
|
+
};
|
|
709
|
+
});
|
|
710
|
+
const wireBranches = (source, wireName)=>{
|
|
711
|
+
const { openIndex, closeIndex } = branchesRange(source, wireName);
|
|
712
|
+
const content = source.slice(openIndex + 1, closeIndex);
|
|
713
|
+
return new Map(branchItems(content).map(({ key, valueStart, end })=>[
|
|
714
|
+
key,
|
|
715
|
+
content.slice(valueStart, end)
|
|
716
|
+
]));
|
|
717
|
+
};
|
|
718
|
+
const setWireBranches = (source, wireName, environments, branchWire)=>{
|
|
719
|
+
const { openIndex, closeIndex } = branchesRange(source, wireName);
|
|
720
|
+
let content = source.slice(openIndex + 1, closeIndex);
|
|
721
|
+
const items = branchItems(content);
|
|
722
|
+
for (const { key, valueStart, end, shorthand } of [
|
|
723
|
+
...items
|
|
724
|
+
].reverse())if (environments.includes(key)) content = content.slice(0, valueStart) + (shorthand ? `${key}: ${branchWire}` : branchWire) + content.slice(end);
|
|
725
|
+
const missing = environments.filter((environment)=>!items.some((x)=>x.key === environment));
|
|
726
|
+
if (missing.length) content = appendItems(content, missing.map((environment)=>`${environment}: ${branchWire}`));
|
|
727
|
+
return source.slice(0, openIndex + 1) + content + source.slice(closeIndex);
|
|
728
|
+
};
|
|
729
|
+
const addBranchedImplementation = (source, wireName, implementation)=>{
|
|
730
|
+
const withImport = addImport(source, implementation.importLine);
|
|
731
|
+
const { declarationIndex } = branchesRange(withImport, wireName);
|
|
732
|
+
const withWireClass = `${withImport.slice(0, declarationIndex)}const ${implementation.wireName} = wireClass(${implementation.className}, [])\n\n${withImport.slice(declarationIndex)}`;
|
|
733
|
+
return setWireBranches(withWireClass, wireName, implementation.environments, implementation.wireName);
|
|
734
|
+
};
|
|
680
735
|
const inMemoryImplementationType = 'in-memory';
|
|
681
736
|
const in_memory_db_className = 'InMemoryDbInfrastructureService';
|
|
682
737
|
const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
|
|
@@ -840,6 +895,13 @@ const wireNewModuleDependencies = async (boundedContextFolder, wireFile, customW
|
|
|
840
895
|
const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
|
|
841
896
|
if (consumer) await promptDependencies(boundedContextFolder, consumer, consumer.implementations, customWiring);
|
|
842
897
|
};
|
|
898
|
+
const wireNewImplementationDependencies = async (boundedContextFolder, wireFile, className, customWiring)=>{
|
|
899
|
+
const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
|
|
900
|
+
const implementation = consumer?.implementations.find((x)=>x.className === className);
|
|
901
|
+
if (consumer && implementation) await promptDependencies(boundedContextFolder, consumer, [
|
|
902
|
+
implementation
|
|
903
|
+
], customWiring);
|
|
904
|
+
};
|
|
843
905
|
const wireDependency = async (boundedContextFolder)=>{
|
|
844
906
|
const modules = findWiredModules(boundedContextFolder.path);
|
|
845
907
|
if (!modules.length) return void console.log('No wired modules here yet.');
|
|
@@ -1493,6 +1555,139 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
1493
1555
|
console.log('Cancelled: nothing was written.');
|
|
1494
1556
|
}
|
|
1495
1557
|
};
|
|
1558
|
+
const contractKinds = [
|
|
1559
|
+
'aggregate',
|
|
1560
|
+
'command',
|
|
1561
|
+
'query',
|
|
1562
|
+
'port'
|
|
1563
|
+
];
|
|
1564
|
+
const implementations_withWiring = ()=>config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
1565
|
+
const withHandlers = ()=>config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers');
|
|
1566
|
+
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` : kindLayouts[unit.kind].files(unit, [])[0];
|
|
1567
|
+
const findContracts = (ownerPath)=>findBackendUnits(ownerPath).filter((unit)=>contractKinds.includes(unit.kind) && external_node_fs_default().existsSync(external_node_path_default().join(ownerPath, contractFile(unit))));
|
|
1568
|
+
const implementationWireName = (label)=>`wire${new unknown_format_naming_UnknownFormatNaming(label).ClassName}Implementation`;
|
|
1569
|
+
const contractClassName = (unit)=>kindLayouts[unit.kind].core(new unknown_format_naming_UnknownFormatNaming(unit.name).ClassName);
|
|
1570
|
+
const implementationClassName = (unit, label)=>`${new unknown_format_naming_UnknownFormatNaming(label).ClassName}${contractClassName(unit)}`;
|
|
1571
|
+
const implementationFile = (unit, label)=>{
|
|
1572
|
+
const { implementations } = kindLayouts[unit.kind];
|
|
1573
|
+
return kindLayouts[unit.kind].files(unit, [
|
|
1574
|
+
label
|
|
1575
|
+
]).find((file)=>file.startsWith(`${implementations}/`));
|
|
1576
|
+
};
|
|
1577
|
+
const contractWireFile = (unit)=>kindLayouts[unit.kind].files(unit, []).find((file)=>file.startsWith('wiring/'));
|
|
1578
|
+
const handlerImplementation = (ContractName, ClassName, contractImport)=>withHandlers() ? `
|
|
1579
|
+
import { defineHandler } from '@domain-first/handlers'
|
|
1580
|
+
import { ${ContractName} } from '${contractImport}'
|
|
1581
|
+
|
|
1582
|
+
export class ${ClassName} extends ${ContractName} {
|
|
1583
|
+
constructor() {
|
|
1584
|
+
super()
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
handle = defineHandler({
|
|
1588
|
+
inputSchema: ${ContractName}.inputSchema,
|
|
1589
|
+
outputSchema: ${ContractName}.outputSchema,
|
|
1590
|
+
handler: async (input) => {
|
|
1591
|
+
return {}
|
|
1592
|
+
}
|
|
1593
|
+
})
|
|
1594
|
+
}
|
|
1595
|
+
`.trim() : `
|
|
1596
|
+
import { ${ContractName} } from '${contractImport}'
|
|
1597
|
+
|
|
1598
|
+
export class ${ClassName} extends ${ContractName} {
|
|
1599
|
+
constructor() {
|
|
1600
|
+
super()
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
`.trim();
|
|
1604
|
+
const createImplementation = (ownerFolder, unit, label)=>{
|
|
1605
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(unit.name);
|
|
1606
|
+
const ContractName = contractClassName(unit);
|
|
1607
|
+
const className = implementationClassName(unit, label);
|
|
1608
|
+
const [folder, fileName] = [
|
|
1609
|
+
external_node_path_default().dirname(implementationFile(unit, label)),
|
|
1610
|
+
external_node_path_default().basename(implementationFile(unit, label))
|
|
1611
|
+
];
|
|
1612
|
+
const implementationFolder = ownerFolder.subitem(folder.split('/'));
|
|
1613
|
+
const inMemoryDb = !implementations_withWiring() && usesInMemoryDb(label);
|
|
1614
|
+
switch(unit.kind){
|
|
1615
|
+
case 'aggregate':
|
|
1616
|
+
{
|
|
1617
|
+
const contractImport = `../../../domain/aggregates/${unit.name}`;
|
|
1618
|
+
if (inMemoryDb) {
|
|
1619
|
+
const section = addInMemoryDbSection(naming, ownerFolder.subitem([
|
|
1620
|
+
'domain',
|
|
1621
|
+
'aggregates',
|
|
1622
|
+
unit.name
|
|
1623
|
+
]).path);
|
|
1624
|
+
const file = implementationFolder.createFile(fileName, `
|
|
1625
|
+
${inMemoryDbTypeImport(implementationFolder.subitem([
|
|
1626
|
+
fileName
|
|
1627
|
+
]).path)}
|
|
1628
|
+
import { ${ContractName} } from '${contractImport}'
|
|
1629
|
+
|
|
1630
|
+
export class ${className} implements ${ContractName} {
|
|
1631
|
+
${inMemoryDbSectionMembers(section, false)}
|
|
1632
|
+
}
|
|
1633
|
+
`.trim());
|
|
1634
|
+
return {
|
|
1635
|
+
file,
|
|
1636
|
+
className
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
const file = implementationFolder.createFile(fileName, `
|
|
1640
|
+
import { ${ContractName} } from '${contractImport}'
|
|
1641
|
+
|
|
1642
|
+
export class ${className} implements ${ContractName} {
|
|
1643
|
+
constructor() {}
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
`.trim());
|
|
1647
|
+
return {
|
|
1648
|
+
file,
|
|
1649
|
+
className
|
|
1650
|
+
};
|
|
1651
|
+
}
|
|
1652
|
+
case 'command':
|
|
1653
|
+
case 'query':
|
|
1654
|
+
{
|
|
1655
|
+
const folderName = 'command' === unit.kind ? 'commands' : 'queries';
|
|
1656
|
+
const file = implementationFolder.createFile(fileName, handlerImplementation(ContractName, className, `../../../application/${folderName}/${naming.fileName}-${unit.kind}`));
|
|
1657
|
+
if (inMemoryDb) injectInMemoryDb(file, className);
|
|
1658
|
+
return {
|
|
1659
|
+
file,
|
|
1660
|
+
className
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1663
|
+
case 'port':
|
|
1664
|
+
{
|
|
1665
|
+
const file = implementationFolder.createFile(fileName, `
|
|
1666
|
+
import { ${ContractName} } from '../../../application/ports/${naming.fileName}'
|
|
1667
|
+
|
|
1668
|
+
export class ${className} extends ${ContractName} {
|
|
1669
|
+
|
|
1670
|
+
}
|
|
1671
|
+
`.trim());
|
|
1672
|
+
return {
|
|
1673
|
+
file,
|
|
1674
|
+
className
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
default:
|
|
1678
|
+
throw new Error(`${unit.kind} has no implementations`);
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
const inMemoryRepositoryWiring = (ownerFolder, unit, wireFile)=>(implementation, dependency)=>{
|
|
1682
|
+
if ('aggregate' !== unit.kind || !isInMemoryDb(dependency)) return false;
|
|
1683
|
+
keepInMemoryDbSection(new file_system_File(implementation.file), addInMemoryDbSection(new unknown_format_naming_UnknownFormatNaming(unit.name), ownerFolder.subitem([
|
|
1684
|
+
'domain',
|
|
1685
|
+
'aggregates',
|
|
1686
|
+
unit.name
|
|
1687
|
+
]).path));
|
|
1688
|
+
wireInMemoryDb(wireFile, implementation.className);
|
|
1689
|
+
return true;
|
|
1690
|
+
};
|
|
1496
1691
|
const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
1497
1692
|
const aggregateName = await (0, prompts_namespaceObject.input)({
|
|
1498
1693
|
message: 'Aggregate name:'
|
|
@@ -1547,43 +1742,17 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
1547
1742
|
message: 'Test Repository infrastructure implementation type:',
|
|
1548
1743
|
default: 'in-memory'
|
|
1549
1744
|
});
|
|
1550
|
-
const infrastructureRepositoriesFolder = boundedContextFolder.subitem([
|
|
1551
|
-
'infrastructure',
|
|
1552
|
-
'repositories'
|
|
1553
|
-
]);
|
|
1554
1745
|
const implementationTypes = [
|
|
1555
1746
|
infrastructureImplementationType,
|
|
1556
1747
|
testImplementationType
|
|
1557
1748
|
].filter((x)=>!!x);
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
]
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
const section = addInMemoryDbSection(aggregateNaming, aggregatesFolder.path);
|
|
1566
|
-
repositoryFolder.createFile(repositoryFileName, `
|
|
1567
|
-
${inMemoryDbTypeImport(repositoryFolder.subitem([
|
|
1568
|
-
repositoryFileName
|
|
1569
|
-
]).path)}
|
|
1570
|
-
import { ${aggregateNaming.ClassName}Repository } from '../../../domain/aggregates/${aggregateName}'
|
|
1571
|
-
|
|
1572
|
-
export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implements ${aggregateNaming.ClassName}Repository {
|
|
1573
|
-
${inMemoryDbSectionMembers(section, false)}
|
|
1574
|
-
}
|
|
1575
|
-
`.trim());
|
|
1576
|
-
continue;
|
|
1577
|
-
}
|
|
1578
|
-
repositoryFolder.createFile(repositoryFileName, `
|
|
1579
|
-
import { ${aggregateNaming.ClassName}Repository } from '../../../domain/aggregates/${aggregateName}'
|
|
1580
|
-
|
|
1581
|
-
export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implements ${aggregateNaming.ClassName}Repository {
|
|
1582
|
-
constructor() {}
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
`.trim());
|
|
1586
|
-
}
|
|
1749
|
+
const repository = {
|
|
1750
|
+
kind: 'aggregate',
|
|
1751
|
+
name: aggregateName,
|
|
1752
|
+
ownerPath: boundedContextFolder.path,
|
|
1753
|
+
labels: []
|
|
1754
|
+
};
|
|
1755
|
+
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, repository, new unknown_format_naming_UnknownFormatNaming(implementation).fileName);
|
|
1587
1756
|
if (scaffoldUnitTests) {
|
|
1588
1757
|
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(infrastructureImplementationType);
|
|
1589
1758
|
const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
@@ -1626,12 +1795,7 @@ export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
|
1626
1795
|
production: wire${implementationNaming.ClassName}Implementation
|
|
1627
1796
|
})
|
|
1628
1797
|
`.trim());
|
|
1629
|
-
await wireNewModuleDependencies(boundedContextFolder, wireFile, (
|
|
1630
|
-
if (!isInMemoryDb(dependency)) return false;
|
|
1631
|
-
keepInMemoryDbSection(new file_system_File(implementation.file), addInMemoryDbSection(aggregateNaming, aggregatesFolder.path));
|
|
1632
|
-
wireInMemoryDb(wireFile, implementation.className);
|
|
1633
|
-
return true;
|
|
1634
|
-
});
|
|
1798
|
+
await wireNewModuleDependencies(boundedContextFolder, wireFile, inMemoryRepositoryWiring(boundedContextFolder, repository, wireFile));
|
|
1635
1799
|
}
|
|
1636
1800
|
}
|
|
1637
1801
|
};
|
|
@@ -1666,26 +1830,16 @@ export abstract class ${naming.ClassName} {
|
|
|
1666
1830
|
message: 'Test adapter implementation type:',
|
|
1667
1831
|
default: 'mock'
|
|
1668
1832
|
});
|
|
1669
|
-
const infrastructureFolder = boundedContextFolder.subitem([
|
|
1670
|
-
'infrastructure',
|
|
1671
|
-
'application-adapters'
|
|
1672
|
-
]);
|
|
1673
1833
|
const implementationTypes = [
|
|
1674
1834
|
implementationType,
|
|
1675
1835
|
testImplementationType
|
|
1676
|
-
].filter((x)=>!!x);
|
|
1677
|
-
for (const implementation of implementationTypes){
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
]
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
export class ${currentNaming.ClassName} extends ${naming.ClassName} {
|
|
1685
|
-
|
|
1686
|
-
}
|
|
1687
|
-
`.trim());
|
|
1688
|
-
}
|
|
1836
|
+
].filter((x)=>!!x).map((x)=>new unknown_format_naming_UnknownFormatNaming(x).fileName);
|
|
1837
|
+
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, {
|
|
1838
|
+
kind: 'port',
|
|
1839
|
+
name: naming.fileName,
|
|
1840
|
+
ownerPath: boundedContextFolder.path,
|
|
1841
|
+
labels: []
|
|
1842
|
+
}, implementation);
|
|
1689
1843
|
if (scaffoldUnitTests) {
|
|
1690
1844
|
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
|
|
1691
1845
|
applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
@@ -1801,10 +1955,6 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
1801
1955
|
'application',
|
|
1802
1956
|
'commands'
|
|
1803
1957
|
]);
|
|
1804
|
-
const infrastructureFolder = boundedContextFolder.subitem([
|
|
1805
|
-
'infrastructure',
|
|
1806
|
-
'commands'
|
|
1807
|
-
]);
|
|
1808
1958
|
const commandName = await (0, prompts_namespaceObject.input)({
|
|
1809
1959
|
message: 'Name: '
|
|
1810
1960
|
});
|
|
@@ -1828,38 +1978,12 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
1828
1978
|
implementationType,
|
|
1829
1979
|
testImplementationType
|
|
1830
1980
|
].filter((x)=>!!x);
|
|
1831
|
-
for (const implementation of implementationTypes){
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
]
|
|
1836
|
-
|
|
1837
|
-
import { ${naming.ClassName}Command } from '../../../application/commands/${naming.fileName}-command'
|
|
1838
|
-
|
|
1839
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${naming.ClassName}Command {
|
|
1840
|
-
constructor() {
|
|
1841
|
-
super()
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
handle = defineHandler({
|
|
1845
|
-
inputSchema: ${naming.ClassName}Command.inputSchema,
|
|
1846
|
-
outputSchema: ${naming.ClassName}Command.outputSchema,
|
|
1847
|
-
handler: async (input) => {
|
|
1848
|
-
return {}
|
|
1849
|
-
}
|
|
1850
|
-
})
|
|
1851
|
-
}
|
|
1852
|
-
`.trim() : `
|
|
1853
|
-
import { ${naming.ClassName}Command } from '../../../application/commands/${naming.fileName}-command'
|
|
1854
|
-
|
|
1855
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${naming.ClassName}Command {
|
|
1856
|
-
constructor() {
|
|
1857
|
-
super()
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
`.trim());
|
|
1861
|
-
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
|
|
1862
|
-
}
|
|
1981
|
+
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, {
|
|
1982
|
+
kind: 'command',
|
|
1983
|
+
name: naming.fileName,
|
|
1984
|
+
ownerPath: boundedContextFolder.path,
|
|
1985
|
+
labels: []
|
|
1986
|
+
}, new unknown_format_naming_UnknownFormatNaming(implementation).fileName);
|
|
1863
1987
|
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.createFile(`${naming.fileName}-command.ts`, `
|
|
1864
1988
|
import type { Handler } from '@domain-first/handlers'
|
|
1865
1989
|
|
|
@@ -2212,6 +2336,88 @@ export const wire${endpointClassName} = wireClass(
|
|
|
2212
2336
|
wiringFolder.file('index.ts').addLine(`export * from './${wireNaming.fileName}'`);
|
|
2213
2337
|
}
|
|
2214
2338
|
};
|
|
2339
|
+
const scaffold_new_implementation_kindTitles = {
|
|
2340
|
+
aggregate: 'Repositories',
|
|
2341
|
+
command: 'Commands',
|
|
2342
|
+
query: 'Queries',
|
|
2343
|
+
port: 'Ports'
|
|
2344
|
+
};
|
|
2345
|
+
const scaffold_new_implementation_environments = [
|
|
2346
|
+
'test',
|
|
2347
|
+
'development',
|
|
2348
|
+
'production'
|
|
2349
|
+
];
|
|
2350
|
+
const branchesOf = (wireFile, wireName)=>{
|
|
2351
|
+
if (!wireFile.exists) return;
|
|
2352
|
+
try {
|
|
2353
|
+
return wireBranches(wireFile.data, wireName);
|
|
2354
|
+
} catch {
|
|
2355
|
+
return;
|
|
2356
|
+
}
|
|
2357
|
+
};
|
|
2358
|
+
const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
2359
|
+
const contracts = findContracts(ownerFolder.path);
|
|
2360
|
+
if (!contracts.length) return void console.log('No repositories, commands, queries or ports here yet.');
|
|
2361
|
+
const unit = await (0, prompts_namespaceObject.select)({
|
|
2362
|
+
message: 'Contract:',
|
|
2363
|
+
choices: contractKinds.flatMap((kind)=>{
|
|
2364
|
+
const group = contracts.filter((x)=>x.kind === kind);
|
|
2365
|
+
return group.length ? [
|
|
2366
|
+
new prompts_namespaceObject.Separator(`── ${scaffold_new_implementation_kindTitles[kind]}`),
|
|
2367
|
+
...group.map((value)=>({
|
|
2368
|
+
name: value.labels.length ? `${value.name} (${value.labels.join(', ')})` : value.name,
|
|
2369
|
+
value
|
|
2370
|
+
}))
|
|
2371
|
+
] : [];
|
|
2372
|
+
}),
|
|
2373
|
+
pageSize: 20
|
|
2374
|
+
});
|
|
2375
|
+
const label = (await (0, prompts_namespaceObject.input)({
|
|
2376
|
+
message: 'Implementation type:',
|
|
2377
|
+
validate: (value)=>{
|
|
2378
|
+
const type = value.trim();
|
|
2379
|
+
if (!kebabName.test(type)) return 'Use lowercase kebab-case, e.g. api or in-memory.';
|
|
2380
|
+
return unit.labels.includes(type) ? `${unit.name} already has the ${type} implementation.` : true;
|
|
2381
|
+
}
|
|
2382
|
+
})).trim();
|
|
2383
|
+
const { file, className } = createImplementation(ownerFolder, unit, label);
|
|
2384
|
+
if (!config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) return;
|
|
2385
|
+
const wireFile = new file_system_File(ownerFolder.path).subitem(contractWireFile(unit).split('/'));
|
|
2386
|
+
const wireName = `wire${contractClassName(unit)}`;
|
|
2387
|
+
const branches = branchesOf(wireFile, wireName);
|
|
2388
|
+
if (!branches) return void console.log(`${wireFile.path} has no ${wireName} = envBranchedWire({...}): wire ${className} there yourself.`);
|
|
2389
|
+
const labelOfWire = new Map(unit.labels.map((x)=>[
|
|
2390
|
+
implementationWireName(x),
|
|
2391
|
+
x
|
|
2392
|
+
]));
|
|
2393
|
+
const chosenEnvironments = await (0, prompts_namespaceObject.checkbox)({
|
|
2394
|
+
message: 'Environments:',
|
|
2395
|
+
choices: [
|
|
2396
|
+
...new Set([
|
|
2397
|
+
...scaffold_new_implementation_environments,
|
|
2398
|
+
...branches.keys()
|
|
2399
|
+
])
|
|
2400
|
+
].map((environment)=>{
|
|
2401
|
+
const current = branches.get(environment);
|
|
2402
|
+
return {
|
|
2403
|
+
name: current ? `${environment} (now: ${labelOfWire.get(current) ?? current})` : environment,
|
|
2404
|
+
value: environment
|
|
2405
|
+
};
|
|
2406
|
+
}),
|
|
2407
|
+
required: true
|
|
2408
|
+
});
|
|
2409
|
+
const before = readWiredModule(wireFile.path, ownerFolder.path);
|
|
2410
|
+
wireFile.update(addBranchedImplementation(wireFile.data, wireName, {
|
|
2411
|
+
importLine: `import { ${className} } from '${wiring_relativeImport(wireFile.path, file.path)}'`,
|
|
2412
|
+
className,
|
|
2413
|
+
wireName: implementationWireName(label),
|
|
2414
|
+
environments: chosenEnvironments
|
|
2415
|
+
}));
|
|
2416
|
+
const after = readWiredModule(wireFile.path, ownerFolder.path);
|
|
2417
|
+
const unused = (before?.implementations ?? []).filter((x)=>!after?.implementations.some((y)=>y.className === x.className));
|
|
2418
|
+
for (const implementation of unused)console.log(`${implementation.className} is no longer used in any environment.`);
|
|
2419
|
+
await wireNewImplementationDependencies(ownerFolder, wireFile, className, inMemoryRepositoryWiring(ownerFolder, unit, wireFile));
|
|
2420
|
+
};
|
|
2215
2421
|
const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
|
|
2216
2422
|
const name = await (0, prompts_namespaceObject.input)({
|
|
2217
2423
|
message: 'Name: '
|
|
@@ -2267,10 +2473,6 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
2267
2473
|
'application',
|
|
2268
2474
|
'queries'
|
|
2269
2475
|
]);
|
|
2270
|
-
const infrastructureFolder = boundedContextFolder.subitem([
|
|
2271
|
-
'infrastructure',
|
|
2272
|
-
'queries'
|
|
2273
|
-
]);
|
|
2274
2476
|
const queryName = await (0, prompts_namespaceObject.input)({
|
|
2275
2477
|
message: 'Name: '
|
|
2276
2478
|
});
|
|
@@ -2294,38 +2496,12 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
2294
2496
|
implementationType,
|
|
2295
2497
|
testImplementationType
|
|
2296
2498
|
].filter((x)=>!!x);
|
|
2297
|
-
for (const implementation of implementationTypes){
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
]
|
|
2302
|
-
|
|
2303
|
-
import { ${naming.ClassName}Query } from '../../../application/queries/${naming.fileName}-query'
|
|
2304
|
-
|
|
2305
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.ClassName}Query {
|
|
2306
|
-
constructor() {
|
|
2307
|
-
super()
|
|
2308
|
-
}
|
|
2309
|
-
|
|
2310
|
-
handle = defineHandler({
|
|
2311
|
-
inputSchema: ${naming.ClassName}Query.inputSchema,
|
|
2312
|
-
outputSchema: ${naming.ClassName}Query.outputSchema,
|
|
2313
|
-
handler: async (input) => {
|
|
2314
|
-
return {}
|
|
2315
|
-
}
|
|
2316
|
-
})
|
|
2317
|
-
}
|
|
2318
|
-
`.trim() : `
|
|
2319
|
-
import { ${naming.ClassName}Query } from '../../../application/queries/${naming.fileName}-query'
|
|
2320
|
-
|
|
2321
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.ClassName}Query {
|
|
2322
|
-
constructor() {
|
|
2323
|
-
super()
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
`.trim());
|
|
2327
|
-
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
|
|
2328
|
-
}
|
|
2499
|
+
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, {
|
|
2500
|
+
kind: 'query',
|
|
2501
|
+
name: naming.fileName,
|
|
2502
|
+
ownerPath: boundedContextFolder.path,
|
|
2503
|
+
labels: []
|
|
2504
|
+
}, new unknown_format_naming_UnknownFormatNaming(implementation).fileName);
|
|
2329
2505
|
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.createFile(`${naming.fileName}-query.ts`, `
|
|
2330
2506
|
import type { Handler } from '@domain-first/handlers'
|
|
2331
2507
|
|
|
@@ -2569,10 +2745,13 @@ const main = async ()=>{
|
|
|
2569
2745
|
const operation = await (0, prompts_namespaceObject.select)({
|
|
2570
2746
|
message: 'Infrastructure layer operation:',
|
|
2571
2747
|
choices: [
|
|
2572
|
-
'New Service'
|
|
2748
|
+
'New Service',
|
|
2749
|
+
'New Implementation'
|
|
2573
2750
|
]
|
|
2574
2751
|
});
|
|
2575
2752
|
switch(operation){
|
|
2753
|
+
case 'New Implementation':
|
|
2754
|
+
return void await scaffoldNewImplementation(boundedContextFolder);
|
|
2576
2755
|
case 'New Service':
|
|
2577
2756
|
return void await scaffoldNewInfrastructureService(boundedContextFolder);
|
|
2578
2757
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { select as prompts_select } from "@inquirer/prompts";
|
|
3
3
|
import { ProjectRoot, ConfigFile, Folder } from "./201.js";
|
|
4
|
-
import { scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewAggregateUseCase, scaffoldNewQuery, scaffoldNewInfrastructureService, scaffoldNewHandlersRestEndpoint, savePendingChanges, moveBackendUnitUseCase, scaffoldNewCommand, scaffoldNewPresentationService, scaffoldNewApplicationService, scaffoldNewUseCase, wireDependency, scaffoldNewBoundedContextUseCase, scaffoldNewDomainObject, scaffoldNewApplicationPort } from "./287.js";
|
|
4
|
+
import { scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewAggregateUseCase, scaffoldNewQuery, scaffoldNewInfrastructureService, scaffoldNewHandlersRestEndpoint, savePendingChanges, moveBackendUnitUseCase, scaffoldNewCommand, scaffoldNewPresentationService, scaffoldNewApplicationService, scaffoldNewUseCase, scaffoldNewImplementation, wireDependency, scaffoldNewBoundedContextUseCase, scaffoldNewDomainObject, scaffoldNewApplicationPort } from "./287.js";
|
|
5
5
|
const main = async ()=>{
|
|
6
6
|
if (!ConfigFile.exists) {
|
|
7
7
|
console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
|
|
@@ -119,10 +119,13 @@ const main = async ()=>{
|
|
|
119
119
|
const operation = await prompts_select({
|
|
120
120
|
message: 'Infrastructure layer operation:',
|
|
121
121
|
choices: [
|
|
122
|
-
'New Service'
|
|
122
|
+
'New Service',
|
|
123
|
+
'New Implementation'
|
|
123
124
|
]
|
|
124
125
|
});
|
|
125
126
|
switch(operation){
|
|
127
|
+
case 'New Implementation':
|
|
128
|
+
return void await scaffoldNewImplementation(boundedContextFolder);
|
|
126
129
|
case 'New Service':
|
|
127
130
|
return void await scaffoldNewInfrastructureService(boundedContextFolder);
|
|
128
131
|
}
|
package/dist/lint.cjs
CHANGED
|
@@ -522,9 +522,9 @@ const closingIndex = (source, openIndex)=>{
|
|
|
522
522
|
}
|
|
523
523
|
return -1;
|
|
524
524
|
};
|
|
525
|
-
const
|
|
525
|
+
const topLevelItemRanges = (content)=>{
|
|
526
526
|
const code = codeOnly(content);
|
|
527
|
-
const
|
|
527
|
+
const ranges = [];
|
|
528
528
|
let depth = 0;
|
|
529
529
|
let itemStart = 0;
|
|
530
530
|
for(let index = 0; index <= code.length; index++){
|
|
@@ -532,16 +532,19 @@ const splitTopLevel = (content)=>{
|
|
|
532
532
|
if (void 0 !== char && char in brackets) depth++;
|
|
533
533
|
else if (Object.values(brackets).includes(char)) depth--;
|
|
534
534
|
if (index === code.length || ',' === char && 0 === depth) {
|
|
535
|
-
const item = content.slice(itemStart, index);
|
|
536
535
|
const itemCode = code.slice(itemStart, index);
|
|
537
536
|
const first = itemCode.search(/\S/);
|
|
538
537
|
const last = itemCode.search(/\S\s*$/);
|
|
539
|
-
if (-1 !== first)
|
|
538
|
+
if (-1 !== first) ranges.push({
|
|
539
|
+
start: itemStart + first,
|
|
540
|
+
end: itemStart + last + 1
|
|
541
|
+
});
|
|
540
542
|
itemStart = index + 1;
|
|
541
543
|
}
|
|
542
544
|
}
|
|
543
|
-
return
|
|
545
|
+
return ranges;
|
|
544
546
|
};
|
|
547
|
+
const splitTopLevel = (content)=>topLevelItemRanges(content).map(({ start, end })=>content.slice(start, end));
|
|
545
548
|
const wireListRange = (source, className)=>{
|
|
546
549
|
const match = new RegExp(`wireClass\\(\\s*${className}\\s*,\\s*\\[`).exec(codeOnly(source));
|
|
547
550
|
if (!match) throw new Error(`wireClass(${className}, [...]) not found`);
|
|
@@ -11,6 +11,7 @@ export * from './scaffold-new-domain-object';
|
|
|
11
11
|
export * from './scaffold-new-domain-service';
|
|
12
12
|
export * from './scaffold-new-error';
|
|
13
13
|
export * from './scaffold-new-handlers-rest-endpoint';
|
|
14
|
+
export * from './scaffold-new-implementation';
|
|
14
15
|
export * from './scaffold-new-infrastructure-service';
|
|
15
16
|
export * from './scaffold-new-presentation-service';
|
|
16
17
|
export * from './scaffold-new-query';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Folder } from '../file-system';
|
|
2
2
|
export declare const scaffoldNewAggregateUseCase: (boundedContextFolder: Folder) => Promise<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Folder } from '../file-system';
|
|
2
|
+
/**
|
|
3
|
+
* Adds one more implementation to an existing repository, command,
|
|
4
|
+
* query or port, and with wiring picks the environments that use it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const scaffoldNewImplementation: (ownerFolder: Folder) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,6 +9,11 @@ export type CustomWiring = (implementation: WiredClass, dependency: WiredModule)
|
|
|
9
9
|
* The last step of generators that create a wire.
|
|
10
10
|
*/
|
|
11
11
|
export declare const wireNewModuleDependencies: (boundedContextFolder: Folder, wireFile: File, customWiring?: CustomWiring) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* The last step of adding an implementation to a branched wire: only
|
|
14
|
+
* the new implementation is asked about.
|
|
15
|
+
*/
|
|
16
|
+
export declare const wireNewImplementationDependencies: (boundedContextFolder: Folder, wireFile: File, className: string, customWiring?: CustomWiring) => Promise<void>;
|
|
12
17
|
export declare const wireDependency: (boundedContextFolder: Folder) => Promise<void>;
|
|
13
18
|
/**
|
|
14
19
|
* The endpoint's handler, from the context's queries, commands, and use
|