@domain-first/project-structure 3.2.0 → 3.2.2
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/dist/in-memory-db.d.ts +10 -0
- package/dist/index.cjs +33 -19
- package/dist/index.js +33 -19
- package/dist/use-cases/scaffold-new-aggregate.d.ts +1 -1
- package/dist/use-cases/wire-dependency.d.ts +7 -2
- package/package.json +1 -1
- package/skills/df-ps-implement/SKILL.md +1 -1
- package/skills/df-ps-scaffold/SKILL.md +1 -1
- package/skills/df-ps-scaffold/references/choosing-components.md +1 -0
- package/skills/df-ps-scaffold/references/generators.md +5 -5
- package/skills/df-ps-scaffold/scripts/drive.mjs +1 -1
package/dist/in-memory-db.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { File, Folder } from './file-system';
|
|
2
2
|
import { UnknownFormatNaming } from './unknown-format-naming';
|
|
3
|
+
import { type WiredModule } from './wiring';
|
|
3
4
|
/**
|
|
4
5
|
* The shared in-memory DB with its spec and wire, as the config says.
|
|
5
6
|
*/
|
|
@@ -23,6 +24,15 @@ export declare const inMemoryDbTypeImport: (fromFile: string) => string;
|
|
|
23
24
|
* in-memory DB as `data`.
|
|
24
25
|
*/
|
|
25
26
|
export declare const inMemoryDbSectionMembers: (field: string, derived: boolean) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Puts one section of the in-memory DB in place of the implementation's
|
|
29
|
+
* empty constructor.
|
|
30
|
+
*/
|
|
31
|
+
export declare const keepInMemoryDbSection: (classFile: File, field: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the wired module is the in-memory DB.
|
|
34
|
+
*/
|
|
35
|
+
export declare const isInMemoryDb: (module: WiredModule) => boolean;
|
|
26
36
|
/**
|
|
27
37
|
* Injects the whole in-memory DB into the implementation's constructor.
|
|
28
38
|
*/
|
package/dist/index.cjs
CHANGED
|
@@ -1230,6 +1230,7 @@ const visibleLayers = {
|
|
|
1230
1230
|
],
|
|
1231
1231
|
infrastructure: [
|
|
1232
1232
|
'domain',
|
|
1233
|
+
'application',
|
|
1233
1234
|
'infrastructure'
|
|
1234
1235
|
],
|
|
1235
1236
|
presentation: [
|
|
@@ -1351,6 +1352,9 @@ const findWiredModules = (contextPath)=>{
|
|
|
1351
1352
|
const isCommandOrQuery = (module)=>'commands' === module.kind || 'queries' === module.kind;
|
|
1352
1353
|
const isExecution = (module)=>isCommandOrQuery(module) && 'execution' === external_node_path_default().basename(external_node_path_default().dirname(module.typeFile));
|
|
1353
1354
|
const commandOrQueryRule = (candidate, consumer)=>isExecution(consumer) ? !isCommandOrQuery(candidate) : 'application' !== candidate.layer || isExecution(candidate);
|
|
1355
|
+
const layerRules = {
|
|
1356
|
+
infrastructure: (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind
|
|
1357
|
+
};
|
|
1354
1358
|
const kindRules = {
|
|
1355
1359
|
'application-services': (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind,
|
|
1356
1360
|
'use-cases': (candidate)=>'use-cases' !== candidate.kind,
|
|
@@ -1360,7 +1364,7 @@ const kindRules = {
|
|
|
1360
1364
|
};
|
|
1361
1365
|
const wiring_implementationType = (consumer, implementation)=>consumer.branched ? external_node_path_default().basename(external_node_path_default().dirname(implementation.file)) : void 0;
|
|
1362
1366
|
const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${external_node_path_default().basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
|
|
1363
|
-
const canDependOn = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && (kindRules[consumer.kind]?.(candidate, consumer) ?? true);
|
|
1367
|
+
const canDependOn = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && (layerRules[consumer.implementationsLayer]?.(candidate) ?? true) && (kindRules[consumer.kind]?.(candidate, consumer) ?? true);
|
|
1364
1368
|
const availableDependencies = (consumer, implementation, candidates)=>{
|
|
1365
1369
|
const wired = wiredDependencyNames(new File(consumer.wireFile).data, implementation.className);
|
|
1366
1370
|
return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate) && !wired.includes(candidate.wireName));
|
|
@@ -1713,6 +1717,10 @@ const inMemoryDbSectionMembers = (field, derived)=>`
|
|
|
1713
1717
|
${derived ? 'super()\n ' : ''}this.data = ${in_memory_db_parameterName}.${field}
|
|
1714
1718
|
}
|
|
1715
1719
|
`.trim();
|
|
1720
|
+
const keepInMemoryDbSection = (classFile, field)=>{
|
|
1721
|
+
classFile.update(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)).replace('constructor() {}', inMemoryDbSectionMembers(field, false)));
|
|
1722
|
+
};
|
|
1723
|
+
const isInMemoryDb = (module)=>module.wireName === in_memory_db_wireName;
|
|
1716
1724
|
const injectInMemoryDb = (classFile, implementationName)=>{
|
|
1717
1725
|
classFile.update(addConstructorParameters(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)), implementationName, [
|
|
1718
1726
|
`private readonly ${in_memory_db_parameterName}: ${in_memory_db_className}`
|
|
@@ -1742,7 +1750,8 @@ const groupedChoices = (items, suggested = [])=>{
|
|
|
1742
1750
|
new prompts_namespaceObject.Separator('── Suggested'),
|
|
1743
1751
|
...suggested.map((x)=>({
|
|
1744
1752
|
name: x.label,
|
|
1745
|
-
value: x
|
|
1753
|
+
value: x,
|
|
1754
|
+
checked: true
|
|
1746
1755
|
}))
|
|
1747
1756
|
] : [];
|
|
1748
1757
|
const kinds = [
|
|
@@ -1783,7 +1792,7 @@ const contextAndSharedModules = (boundedContextFolder)=>{
|
|
|
1783
1792
|
}))
|
|
1784
1793
|
];
|
|
1785
1794
|
};
|
|
1786
|
-
const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations)=>{
|
|
1795
|
+
const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations, customWiring)=>{
|
|
1787
1796
|
const options = contextAndSharedModules(boundedContextFolder);
|
|
1788
1797
|
let asked = false;
|
|
1789
1798
|
for (const implementation of implementations){
|
|
@@ -1799,13 +1808,14 @@ const promptDependencies = async (boundedContextFolder, consumer, implementation
|
|
|
1799
1808
|
pageSize: groupedPageSize,
|
|
1800
1809
|
loop: false
|
|
1801
1810
|
});
|
|
1802
|
-
|
|
1811
|
+
const defaultWired = dependencies.map((x)=>x.module).filter((x)=>!customWiring?.(implementation, x));
|
|
1812
|
+
if (defaultWired.length) wireDependencies(consumer, implementation, defaultWired);
|
|
1803
1813
|
}
|
|
1804
1814
|
return asked;
|
|
1805
1815
|
};
|
|
1806
|
-
const wireNewModuleDependencies = async (boundedContextFolder, wireFile)=>{
|
|
1816
|
+
const wireNewModuleDependencies = async (boundedContextFolder, wireFile, customWiring)=>{
|
|
1807
1817
|
const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
|
|
1808
|
-
if (consumer) await promptDependencies(boundedContextFolder, consumer);
|
|
1818
|
+
if (consumer) await promptDependencies(boundedContextFolder, consumer, consumer.implementations, customWiring);
|
|
1809
1819
|
};
|
|
1810
1820
|
const wireDependency = async (boundedContextFolder)=>{
|
|
1811
1821
|
const modules = findWiredModules(boundedContextFolder.path);
|
|
@@ -2323,7 +2333,8 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
|
2323
2333
|
'aggregates',
|
|
2324
2334
|
aggregateName
|
|
2325
2335
|
]);
|
|
2326
|
-
|
|
2336
|
+
const withTypes = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
|
|
2337
|
+
aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, withTypes ? `
|
|
2327
2338
|
import { domainType } from '@domain-first/types'
|
|
2328
2339
|
|
|
2329
2340
|
export class ${aggregateNaming.ClassName} extends domainType() {
|
|
@@ -2337,11 +2348,11 @@ import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggr
|
|
|
2337
2348
|
let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
|
|
2338
2349
|
|
|
2339
2350
|
beforeEach(() => {
|
|
2340
|
-
${aggregateNaming.variableName} = new ${aggregateNaming.ClassName}()
|
|
2351
|
+
${aggregateNaming.variableName} = ${withTypes ? `${aggregateNaming.ClassName}.of({})` : `new ${aggregateNaming.ClassName}()`}
|
|
2341
2352
|
})
|
|
2342
2353
|
|
|
2343
2354
|
describe('${aggregateNaming.withSpaces}', () => {
|
|
2344
|
-
test('can be instantiated via constructor', () => {
|
|
2355
|
+
test('can be instantiated via ${withTypes ? 'of' : 'constructor'}', () => {
|
|
2345
2356
|
expect(${aggregateNaming.variableName}).toBeDefined()
|
|
2346
2357
|
})
|
|
2347
2358
|
})
|
|
@@ -2376,7 +2387,7 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2376
2387
|
naming.fileName
|
|
2377
2388
|
]);
|
|
2378
2389
|
const repositoryFileName = `${naming.fileName}-${aggregateName}-repository.ts`;
|
|
2379
|
-
if (usesInMemoryDb(implementation)) {
|
|
2390
|
+
if (usesInMemoryDb(implementation) && !ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2380
2391
|
const section = addInMemoryDbSection(aggregateNaming, aggregatesFolder.path);
|
|
2381
2392
|
repositoryFolder.createFile(repositoryFileName, `
|
|
2382
2393
|
${inMemoryDbTypeImport(repositoryFolder.subitem([
|
|
@@ -2441,8 +2452,12 @@ export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
|
2441
2452
|
production: wire${implementationNaming.ClassName}Implementation
|
|
2442
2453
|
})
|
|
2443
2454
|
`.trim());
|
|
2444
|
-
|
|
2445
|
-
|
|
2455
|
+
await wireNewModuleDependencies(boundedContextFolder, wireFile, (implementation, dependency)=>{
|
|
2456
|
+
if (!isInMemoryDb(dependency)) return false;
|
|
2457
|
+
keepInMemoryDbSection(new File(implementation.file), addInMemoryDbSection(aggregateNaming, aggregatesFolder.path));
|
|
2458
|
+
wireInMemoryDb(wireFile, implementation.className);
|
|
2459
|
+
return true;
|
|
2460
|
+
});
|
|
2446
2461
|
}
|
|
2447
2462
|
}
|
|
2448
2463
|
};
|
|
@@ -2686,7 +2701,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${namin
|
|
|
2686
2701
|
}
|
|
2687
2702
|
}
|
|
2688
2703
|
`.trim());
|
|
2689
|
-
if (usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
|
|
2704
|
+
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
|
|
2690
2705
|
}
|
|
2691
2706
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.subitem([
|
|
2692
2707
|
'execution'
|
|
@@ -2750,7 +2765,6 @@ export const wire${naming.ClassName}Command = envBranchedWire({
|
|
|
2750
2765
|
production: wire${implementationNaming.ClassName}Implementation
|
|
2751
2766
|
})
|
|
2752
2767
|
`.trim());
|
|
2753
|
-
for (const implementation of implementationTypes.filter(usesInMemoryDb))wireInMemoryDb(wireFile, `${new UnknownFormatNaming(implementation).ClassName}${naming.ClassName}Command`);
|
|
2754
2768
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2755
2769
|
}
|
|
2756
2770
|
return;
|
|
@@ -2841,7 +2855,8 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
2841
2855
|
kindFolderName
|
|
2842
2856
|
]);
|
|
2843
2857
|
const fileName = `${naming.fileName}.${kind}`;
|
|
2844
|
-
|
|
2858
|
+
const withTypes = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
|
|
2859
|
+
folder.createFile(`${fileName}.ts`, withTypes ? `
|
|
2845
2860
|
import { domainType } from '@domain-first/types'
|
|
2846
2861
|
|
|
2847
2862
|
export class ${naming.ClassName} extends domainType() {
|
|
@@ -2858,11 +2873,11 @@ import { ${naming.ClassName} } from './${fileName}'
|
|
|
2858
2873
|
let ${naming.variableName}: ${naming.ClassName}
|
|
2859
2874
|
|
|
2860
2875
|
beforeEach(() => {
|
|
2861
|
-
${naming.variableName} = new ${naming.ClassName}()
|
|
2876
|
+
${naming.variableName} = ${withTypes ? `${naming.ClassName}.of({})` : `new ${naming.ClassName}()`}
|
|
2862
2877
|
})
|
|
2863
2878
|
|
|
2864
2879
|
describe('${naming.withSpaces}', () => {
|
|
2865
|
-
test('can be instantiated via constructor', () => {
|
|
2880
|
+
test('can be instantiated via ${withTypes ? 'of' : 'constructor'}', () => {
|
|
2866
2881
|
expect(${naming.variableName}).toBeDefined()
|
|
2867
2882
|
})
|
|
2868
2883
|
})
|
|
@@ -3199,7 +3214,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.
|
|
|
3199
3214
|
}
|
|
3200
3215
|
}
|
|
3201
3216
|
`.trim());
|
|
3202
|
-
if (usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
|
|
3217
|
+
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
|
|
3203
3218
|
}
|
|
3204
3219
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.subitem([
|
|
3205
3220
|
'execution'
|
|
@@ -3263,7 +3278,6 @@ export const wire${naming.ClassName}Query = envBranchedWire({
|
|
|
3263
3278
|
production: wire${implementationNaming.ClassName}Implementation
|
|
3264
3279
|
})
|
|
3265
3280
|
`.trim());
|
|
3266
|
-
for (const implementation of implementationTypes.filter(usesInMemoryDb))wireInMemoryDb(wireFile, `${new UnknownFormatNaming(implementation).ClassName}${naming.ClassName}Query`);
|
|
3267
3281
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
3268
3282
|
}
|
|
3269
3283
|
return;
|
package/dist/index.js
CHANGED
|
@@ -1200,6 +1200,7 @@ const visibleLayers = {
|
|
|
1200
1200
|
],
|
|
1201
1201
|
infrastructure: [
|
|
1202
1202
|
'domain',
|
|
1203
|
+
'application',
|
|
1203
1204
|
'infrastructure'
|
|
1204
1205
|
],
|
|
1205
1206
|
presentation: [
|
|
@@ -1321,6 +1322,9 @@ const findWiredModules = (contextPath)=>{
|
|
|
1321
1322
|
const isCommandOrQuery = (module)=>'commands' === module.kind || 'queries' === module.kind;
|
|
1322
1323
|
const isExecution = (module)=>isCommandOrQuery(module) && 'execution' === node_path.basename(node_path.dirname(module.typeFile));
|
|
1323
1324
|
const commandOrQueryRule = (candidate, consumer)=>isExecution(consumer) ? !isCommandOrQuery(candidate) : 'application' !== candidate.layer || isExecution(candidate);
|
|
1325
|
+
const layerRules = {
|
|
1326
|
+
infrastructure: (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind
|
|
1327
|
+
};
|
|
1324
1328
|
const kindRules = {
|
|
1325
1329
|
'application-services': (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind,
|
|
1326
1330
|
'use-cases': (candidate)=>'use-cases' !== candidate.kind,
|
|
@@ -1330,7 +1334,7 @@ const kindRules = {
|
|
|
1330
1334
|
};
|
|
1331
1335
|
const wiring_implementationType = (consumer, implementation)=>consumer.branched ? node_path.basename(node_path.dirname(implementation.file)) : void 0;
|
|
1332
1336
|
const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${node_path.basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
|
|
1333
|
-
const canDependOn = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && (kindRules[consumer.kind]?.(candidate, consumer) ?? true);
|
|
1337
|
+
const canDependOn = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && (layerRules[consumer.implementationsLayer]?.(candidate) ?? true) && (kindRules[consumer.kind]?.(candidate, consumer) ?? true);
|
|
1334
1338
|
const availableDependencies = (consumer, implementation, candidates)=>{
|
|
1335
1339
|
const wired = wiredDependencyNames(new File(consumer.wireFile).data, implementation.className);
|
|
1336
1340
|
return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate) && !wired.includes(candidate.wireName));
|
|
@@ -1683,6 +1687,10 @@ const inMemoryDbSectionMembers = (field, derived)=>`
|
|
|
1683
1687
|
${derived ? 'super()\n ' : ''}this.data = ${in_memory_db_parameterName}.${field}
|
|
1684
1688
|
}
|
|
1685
1689
|
`.trim();
|
|
1690
|
+
const keepInMemoryDbSection = (classFile, field)=>{
|
|
1691
|
+
classFile.update(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)).replace('constructor() {}', inMemoryDbSectionMembers(field, false)));
|
|
1692
|
+
};
|
|
1693
|
+
const isInMemoryDb = (module)=>module.wireName === in_memory_db_wireName;
|
|
1686
1694
|
const injectInMemoryDb = (classFile, implementationName)=>{
|
|
1687
1695
|
classFile.update(addConstructorParameters(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)), implementationName, [
|
|
1688
1696
|
`private readonly ${in_memory_db_parameterName}: ${in_memory_db_className}`
|
|
@@ -1712,7 +1720,8 @@ const groupedChoices = (items, suggested = [])=>{
|
|
|
1712
1720
|
new Separator('── Suggested'),
|
|
1713
1721
|
...suggested.map((x)=>({
|
|
1714
1722
|
name: x.label,
|
|
1715
|
-
value: x
|
|
1723
|
+
value: x,
|
|
1724
|
+
checked: true
|
|
1716
1725
|
}))
|
|
1717
1726
|
] : [];
|
|
1718
1727
|
const kinds = [
|
|
@@ -1753,7 +1762,7 @@ const contextAndSharedModules = (boundedContextFolder)=>{
|
|
|
1753
1762
|
}))
|
|
1754
1763
|
];
|
|
1755
1764
|
};
|
|
1756
|
-
const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations)=>{
|
|
1765
|
+
const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations, customWiring)=>{
|
|
1757
1766
|
const options = contextAndSharedModules(boundedContextFolder);
|
|
1758
1767
|
let asked = false;
|
|
1759
1768
|
for (const implementation of implementations){
|
|
@@ -1769,13 +1778,14 @@ const promptDependencies = async (boundedContextFolder, consumer, implementation
|
|
|
1769
1778
|
pageSize: groupedPageSize,
|
|
1770
1779
|
loop: false
|
|
1771
1780
|
});
|
|
1772
|
-
|
|
1781
|
+
const defaultWired = dependencies.map((x)=>x.module).filter((x)=>!customWiring?.(implementation, x));
|
|
1782
|
+
if (defaultWired.length) wireDependencies(consumer, implementation, defaultWired);
|
|
1773
1783
|
}
|
|
1774
1784
|
return asked;
|
|
1775
1785
|
};
|
|
1776
|
-
const wireNewModuleDependencies = async (boundedContextFolder, wireFile)=>{
|
|
1786
|
+
const wireNewModuleDependencies = async (boundedContextFolder, wireFile, customWiring)=>{
|
|
1777
1787
|
const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
|
|
1778
|
-
if (consumer) await promptDependencies(boundedContextFolder, consumer);
|
|
1788
|
+
if (consumer) await promptDependencies(boundedContextFolder, consumer, consumer.implementations, customWiring);
|
|
1779
1789
|
};
|
|
1780
1790
|
const wireDependency = async (boundedContextFolder)=>{
|
|
1781
1791
|
const modules = findWiredModules(boundedContextFolder.path);
|
|
@@ -2293,7 +2303,8 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
|
2293
2303
|
'aggregates',
|
|
2294
2304
|
aggregateName
|
|
2295
2305
|
]);
|
|
2296
|
-
|
|
2306
|
+
const withTypes = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
|
|
2307
|
+
aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, withTypes ? `
|
|
2297
2308
|
import { domainType } from '@domain-first/types'
|
|
2298
2309
|
|
|
2299
2310
|
export class ${aggregateNaming.ClassName} extends domainType() {
|
|
@@ -2307,11 +2318,11 @@ import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggr
|
|
|
2307
2318
|
let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
|
|
2308
2319
|
|
|
2309
2320
|
beforeEach(() => {
|
|
2310
|
-
${aggregateNaming.variableName} = new ${aggregateNaming.ClassName}()
|
|
2321
|
+
${aggregateNaming.variableName} = ${withTypes ? `${aggregateNaming.ClassName}.of({})` : `new ${aggregateNaming.ClassName}()`}
|
|
2311
2322
|
})
|
|
2312
2323
|
|
|
2313
2324
|
describe('${aggregateNaming.withSpaces}', () => {
|
|
2314
|
-
test('can be instantiated via constructor', () => {
|
|
2325
|
+
test('can be instantiated via ${withTypes ? 'of' : 'constructor'}', () => {
|
|
2315
2326
|
expect(${aggregateNaming.variableName}).toBeDefined()
|
|
2316
2327
|
})
|
|
2317
2328
|
})
|
|
@@ -2346,7 +2357,7 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2346
2357
|
naming.fileName
|
|
2347
2358
|
]);
|
|
2348
2359
|
const repositoryFileName = `${naming.fileName}-${aggregateName}-repository.ts`;
|
|
2349
|
-
if (usesInMemoryDb(implementation)) {
|
|
2360
|
+
if (usesInMemoryDb(implementation) && !ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2350
2361
|
const section = addInMemoryDbSection(aggregateNaming, aggregatesFolder.path);
|
|
2351
2362
|
repositoryFolder.createFile(repositoryFileName, `
|
|
2352
2363
|
${inMemoryDbTypeImport(repositoryFolder.subitem([
|
|
@@ -2411,8 +2422,12 @@ export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
|
2411
2422
|
production: wire${implementationNaming.ClassName}Implementation
|
|
2412
2423
|
})
|
|
2413
2424
|
`.trim());
|
|
2414
|
-
|
|
2415
|
-
|
|
2425
|
+
await wireNewModuleDependencies(boundedContextFolder, wireFile, (implementation, dependency)=>{
|
|
2426
|
+
if (!isInMemoryDb(dependency)) return false;
|
|
2427
|
+
keepInMemoryDbSection(new File(implementation.file), addInMemoryDbSection(aggregateNaming, aggregatesFolder.path));
|
|
2428
|
+
wireInMemoryDb(wireFile, implementation.className);
|
|
2429
|
+
return true;
|
|
2430
|
+
});
|
|
2416
2431
|
}
|
|
2417
2432
|
}
|
|
2418
2433
|
};
|
|
@@ -2656,7 +2671,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${namin
|
|
|
2656
2671
|
}
|
|
2657
2672
|
}
|
|
2658
2673
|
`.trim());
|
|
2659
|
-
if (usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
|
|
2674
|
+
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
|
|
2660
2675
|
}
|
|
2661
2676
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.subitem([
|
|
2662
2677
|
'execution'
|
|
@@ -2720,7 +2735,6 @@ export const wire${naming.ClassName}Command = envBranchedWire({
|
|
|
2720
2735
|
production: wire${implementationNaming.ClassName}Implementation
|
|
2721
2736
|
})
|
|
2722
2737
|
`.trim());
|
|
2723
|
-
for (const implementation of implementationTypes.filter(usesInMemoryDb))wireInMemoryDb(wireFile, `${new UnknownFormatNaming(implementation).ClassName}${naming.ClassName}Command`);
|
|
2724
2738
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2725
2739
|
}
|
|
2726
2740
|
return;
|
|
@@ -2811,7 +2825,8 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
2811
2825
|
kindFolderName
|
|
2812
2826
|
]);
|
|
2813
2827
|
const fileName = `${naming.fileName}.${kind}`;
|
|
2814
|
-
|
|
2828
|
+
const withTypes = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
|
|
2829
|
+
folder.createFile(`${fileName}.ts`, withTypes ? `
|
|
2815
2830
|
import { domainType } from '@domain-first/types'
|
|
2816
2831
|
|
|
2817
2832
|
export class ${naming.ClassName} extends domainType() {
|
|
@@ -2828,11 +2843,11 @@ import { ${naming.ClassName} } from './${fileName}'
|
|
|
2828
2843
|
let ${naming.variableName}: ${naming.ClassName}
|
|
2829
2844
|
|
|
2830
2845
|
beforeEach(() => {
|
|
2831
|
-
${naming.variableName} = new ${naming.ClassName}()
|
|
2846
|
+
${naming.variableName} = ${withTypes ? `${naming.ClassName}.of({})` : `new ${naming.ClassName}()`}
|
|
2832
2847
|
})
|
|
2833
2848
|
|
|
2834
2849
|
describe('${naming.withSpaces}', () => {
|
|
2835
|
-
test('can be instantiated via constructor', () => {
|
|
2850
|
+
test('can be instantiated via ${withTypes ? 'of' : 'constructor'}', () => {
|
|
2836
2851
|
expect(${naming.variableName}).toBeDefined()
|
|
2837
2852
|
})
|
|
2838
2853
|
})
|
|
@@ -3169,7 +3184,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.
|
|
|
3169
3184
|
}
|
|
3170
3185
|
}
|
|
3171
3186
|
`.trim());
|
|
3172
|
-
if (usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
|
|
3187
|
+
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
|
|
3173
3188
|
}
|
|
3174
3189
|
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.subitem([
|
|
3175
3190
|
'execution'
|
|
@@ -3233,7 +3248,6 @@ export const wire${naming.ClassName}Query = envBranchedWire({
|
|
|
3233
3248
|
production: wire${implementationNaming.ClassName}Implementation
|
|
3234
3249
|
})
|
|
3235
3250
|
`.trim());
|
|
3236
|
-
for (const implementation of implementationTypes.filter(usesInMemoryDb))wireInMemoryDb(wireFile, `${new UnknownFormatNaming(implementation).ClassName}${naming.ClassName}Query`);
|
|
3237
3251
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
3238
3252
|
}
|
|
3239
3253
|
return;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Folder } from '../file-system';
|
|
2
2
|
export declare const scaffoldNewAggregateUseCase: (boundedContextFolder: Folder) => Promise<void>;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { type File, Folder } from '../file-system';
|
|
2
|
-
import { type WiredModule } from '../wiring';
|
|
2
|
+
import { type WiredClass, type WiredModule } from '../wiring';
|
|
3
|
+
/**
|
|
4
|
+
* Wires a chosen dependency in its own way. Returns false to leave it to
|
|
5
|
+
* the default wiring.
|
|
6
|
+
*/
|
|
7
|
+
export type CustomWiring = (implementation: WiredClass, dependency: WiredModule) => boolean;
|
|
3
8
|
/**
|
|
4
9
|
* The last step of generators that create a wire.
|
|
5
10
|
*/
|
|
6
|
-
export declare const wireNewModuleDependencies: (boundedContextFolder: Folder, wireFile: File) => Promise<void>;
|
|
11
|
+
export declare const wireNewModuleDependencies: (boundedContextFolder: Folder, wireFile: File, customWiring?: CustomWiring) => Promise<void>;
|
|
7
12
|
export declare const wireDependency: (boundedContextFolder: Folder) => Promise<void>;
|
|
8
13
|
/**
|
|
9
14
|
* The endpoint's handler, from the context's queries, commands, and use
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ Generated files contain placeholders: empty classes, `{}` schemas, `[]` dependen
|
|
|
11
11
|
|
|
12
12
|
- New files need an approved work plan (`df-ps-scaffold`, rule 1) and come only via df-ps or its listed exceptions (rule 2). Edits to existing files don't need approval; report them.
|
|
13
13
|
- Keep generated names and paths: barrels, wiring, specs, and `presentation/rest/wires.ts` import them.
|
|
14
|
-
- Layers: domain imports nothing from other layers. Application uses domain and its own abstractions. Infrastructure implements repositories, contracts, and ports. Presentation calls application handlers. Only `wiring/` knows concrete classes.
|
|
14
|
+
- Layers: domain imports nothing from other layers. Application uses domain and its own abstractions. Infrastructure implements repositories, contracts, and ports, and may use application ports (of its context and the Shared Layer), never other application modules. Infrastructure needing logic from an application service means the logic is misplaced: pure logic without ports → a domain service; logic over ports → call those ports directly; technical logic (mapping, retries, formatting for an external API) → an infrastructure service. Presentation calls application handlers. Only `wiring/` knows concrete classes.
|
|
15
15
|
- Constructors take abstractions (`OrderRepository`, abstract `PlaceOrderCommand`, port `PaymentGateway`), never `PrismaOrderRepository`.
|
|
16
16
|
- Implementation order: domain → application → schema tool runs (migrations, only if infrastructure needs data the database lacks) → infrastructure (repositories, execution commands/queries, adapters) → endpoints → other tool runs (OpenAPI, API client) → React. Widgets need the regenerated client. How to run tools and handle their output: the project's scripts skill (`project-scripts`), if there is one.
|
|
17
17
|
- Run the project's tsc/lint/tests after each component.
|
|
@@ -112,7 +112,7 @@ node scripts/drive.mjs "pick:Bounded Context: sales" pick:Domain "pick:New Aggre
|
|
|
112
112
|
| `pick:<label>` | select | Types a **prefix of the choice text** + Enter. Aborts before submitting if the highlighted choice doesn't match. |
|
|
113
113
|
| `text:<v>` / `default` | input | Types a value / accepts the default. |
|
|
114
114
|
| `yes` / `no` | confirm | |
|
|
115
|
-
| `toggle:1,3` / `none` | checkbox | Init, `Dependencies:`, `Dependencies for <Implementation>:`.
|
|
115
|
+
| `toggle:1,3` / `none` | checkbox | Init, `Dependencies:`, `Dependencies for <Implementation>:`. `Suggested` items come checked: toggling unchecks. |
|
|
116
116
|
|
|
117
117
|
Check every run: exit code 0, no `WARNING`/`ABORTED`, and exactly the planned files. "Still waiting for input" means too few steps; nothing was written. If the raw output ends at `Overwrite them?`, the run would replace files the plan didn't flag: show the user the listed files and ask, never just add `yes`. If prompts get out of sync, retry with `--delay 1200`.
|
|
118
118
|
|
|
@@ -53,6 +53,7 @@ Example: `order-confirmation` prepares a message and calls the injected `mailer`
|
|
|
53
53
|
| Use case / application service | Use case = one action with `handle`. Application service = helper used by use cases. |
|
|
54
54
|
| Use case / orchestrator | Use case = action exposed outside. Orchestrator = reusable operation called by use cases. |
|
|
55
55
|
| Application / infrastructure service | Used by use cases → application. Only by adapters/repositories → infrastructure. |
|
|
56
|
+
| Logic infrastructure needs from an application service | Infrastructure never sees application services. Pure logic without ports → domain service. Logic over ports → infrastructure calls the ports directly. Technical (mapping, retries, external API formats) → infrastructure service. |
|
|
56
57
|
| Clock | Always a port (`clock`, usually in Shared Layer). |
|
|
57
58
|
|
|
58
59
|
## React page, widget, UI-kit component or shared hook
|
|
@@ -6,7 +6,7 @@ Every step list starts with `"pick:Bounded Context: <ctx>"` or `"pick:Shared Lay
|
|
|
6
6
|
|
|
7
7
|
Any generator: if the run would replace existing files, the last prompt is the confirm `Overwrite them?` (the files are listed above it). Without it, nothing extra is asked. Added lines (barrels, errors, wiring indexes) never trigger it.
|
|
8
8
|
|
|
9
|
-
{wire} Generators that create a wire (all below except endpoints, which ask their own two selects) then ask the checkbox `Dependencies:`, before `Overwrite them?`. It lists wired modules of `<C>` and of the Shared Layer (`(shared)` suffix), grouped under headers in this order: Repositories, Domain services, Ports, Application services, Queries, Commands, Use cases, Infrastructure services, Presentation services. Inside a group: by type name, `<C>` first. Headers are not counted: `toggle:<n,..>` numbers only modules, top to bottom. Answer `toggle:<n,..>` or `none`. It is skipped when nothing fits, so check `<C>/wiring/` and `<rootFolder>/shared/wiring/` before counting steps. What fits depends on the layer of the class the wire builds: domain → domain; application → domain, application; infrastructure (repository, execution command/query, and port implementations) → domain,
|
|
9
|
+
{wire} Generators that create a wire (all below except endpoints, which ask their own two selects) then ask the checkbox `Dependencies:`, before `Overwrite them?`. It lists wired modules of `<C>` and of the Shared Layer (`(shared)` suffix), grouped under headers in this order: Repositories, Domain services, Ports, Application services, Queries, Commands, Use cases, Infrastructure services, Presentation services. Inside a group: by type name, `<C>` first. Headers are not counted: `toggle:<n,..>` numbers only modules, top to bottom. Answer `toggle:<n,..>` or `none`. It is skipped when nothing fits, so check `<C>/wiring/` and `<rootFolder>/shared/wiring/` before counting steps. What fits depends on the layer of the class the wire builds: domain → domain; application → domain, application; infrastructure (repository, execution command/query, and port implementations, infrastructure services) → domain, application ports (of `<C>` and the Shared Layer; no other application modules), infrastructure; presentation → application, presentation. On top of that, application services see only ports from application, use cases never see use cases, repository implementations never see repositories, execution command/query implementations never see commands or queries, and orchestration commands/queries see only execution commands and queries from application. Endpoints are never listed. Each chosen module goes into the wire (`wireClass(X, [wireUserRepository])`) and the constructor (`private readonly userRepository: UserRepository`, with `import type`), in the same order. An env-branched wire (repository, execution command/query, port) wires each implementation in isolation: instead of `Dependencies:` it asks `Dependencies for <Implementation>:` once per implementation, in the order of the wire (main, then test). Each list leaves out only what that implementation already has, and a list with nothing to choose is skipped. It may start with a `Suggested` group: infrastructure modules whose file name has the implementation label (its folder, e.g. `prisma`, `in-memory`) as whole words, such as `in-memory-db-infrastructure-service` for `in-memory`. They are listed there only, so numbering starts with them, and they are **checked**: `none` keeps them, `toggle:<n>` on one of them unchecks it.
|
|
10
10
|
|
|
11
11
|
## Bounded context
|
|
12
12
|
|
|
@@ -21,7 +21,7 @@ Prompts: name → `With Repository` → if yes: implementation (default = config
|
|
|
21
21
|
- `<C>/domain/aggregates/n/`: `n.aggregate-root.ts` (`class N extends domainType()` {types}), `index.ts`, spec; with repository: `n-repository.ts` (`abstract class NRepository`), spec
|
|
22
22
|
- `<C>/infrastructure/repositories/I/I-n-repository.ts` per implementation (`class INRepository implements NRepository`)
|
|
23
23
|
- {wire} `<C>/wiring/repositories/wire-n-repository.ts` (env-branched)
|
|
24
|
-
- With `withInMemoryDb` in the config, the `in-memory` implementation
|
|
24
|
+
- With `withInMemoryDb` in the config, the `in-memory` implementation can keep its section of the DB: `private readonly data: InMemoryDbInfrastructureService['ns']`, set in the constructor from its `inMemoryDbInfrastructureService` parameter; `ns = this.section<N>('NS');` is added to `<rootFolder>/shared/infrastructure/services/in-memory-db-infrastructure-service.ts` if missing (`N` needs an `id`). Without {wire} this always happens. {wire} `Dependencies for InMemoryNRepository:` lists the DB under `Suggested`, checked: kept, it gets the section and `wireInMemoryDbInfrastructureService` in its `wireClass`; unchecked, the implementation stays empty (`constructor() {}`) and no section is added.
|
|
25
25
|
|
|
26
26
|
## Domain → New Entity / New Value Object (context and Shared Layer)
|
|
27
27
|
|
|
@@ -78,7 +78,7 @@ Execution:
|
|
|
78
78
|
- `<C>/application/commands/execution/n-command.ts`: abstract `NCommand` ({handlers} schemas + abstract `handle: Handler<…>`), spec
|
|
79
79
|
- `<C>/infrastructure/commands/I/I-n-command.ts` per implementation (`extends NCommand`, implements `handle`)
|
|
80
80
|
- {wire} `<C>/wiring/commands/wire-n-command.ts` (env-branched)
|
|
81
|
-
- With `withInMemoryDb` in the config, the `in-memory` implementation
|
|
81
|
+
- With `withInMemoryDb` in the config, the `in-memory` implementation can get the whole DB: `constructor(private readonly inMemoryDbInfrastructureService: InMemoryDbInfrastructureService)`. No section is added. Without {wire} this always happens; {wire} it is the checked `Suggested` choice of `Dependencies for InMemoryN<Suffix>:`, and unchecking it leaves the implementation empty.
|
|
82
82
|
|
|
83
83
|
Orchestrator: `<C>/application/commands/orchestration/n-command.ts` (concrete class), spec, {wire} `wire-n-command.ts`.
|
|
84
84
|
|
|
@@ -225,7 +225,7 @@ Without wire: import `<Class>` from `<noWire>`, use `new <Class>()` and the test
|
|
|
225
225
|
|
|
226
226
|
| Component | Spec next to | `<Type>` / `<var>` | `<wirePath>` | `<label>` | `<Class>` from `<noWire>`, `<noWireTest>` |
|
|
227
227
|
| -------------------- | ---------------------------- | ----------------------------- | ------------------------------------------------ | -------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
228
|
-
| Aggregate root | `n.aggregate-root.ts` | `N` / `v` | none:
|
|
228
|
+
| Aggregate root | `n.aggregate-root.ts` | `N` / `v` | none: `N.of({})` {types} (`can be instantiated via of`), `new N()` otherwise | `n words` | `N` `./n.aggregate-root`, `can be instantiated via constructor` |
|
|
229
229
|
| Repository* | `n-repository.ts` | `NRepository` / `vRepository` | `../../../wiring/repositories/wire-n-repository` | `n words repository` | `INRepository` `../../../infrastructure/repositories/I/I-n-repository`, `can be created via constructor` |
|
|
230
230
|
| Service | `n-L-service.ts` | `NLService` / `vLService` | `../../wiring/L-services/wire-n-L-service` | `n words` | `NLService` `./n-L-service`, `can be created` |
|
|
231
231
|
| Use case | `n-use-case.ts` | `NUseCase` / `vUseCase` | `../../wiring/use-cases/wire-n-use-case` | `n words use case` | `NUseCase` `./n-use-case`, `can be created` |
|
|
@@ -233,4 +233,4 @@ Without wire: import `<Class>` from `<noWire>`, use `new <Class>()` and the test
|
|
|
233
233
|
| Orchestrator command | `orchestration/n-command.ts` | `NCommand` / `vCommand` | `../../../wiring/commands/wire-n-command` | `n words command` | `NCommand` `./n-command`, `can be created via constructor` |
|
|
234
234
|
| Port | `n.ts` | `N` / `v` | `../../wiring/application-ports/wire-n` | `n words` | `IN` `../../infrastructure/application-adapters/I/I-n`, `can be created via constructor` |
|
|
235
235
|
|
|
236
|
-
`n words` = the name with spaces instead of hyphens. Queries are the same as commands. \*The repository spec imports the wire first, then `import type { NRepository } from './n-repository'`.
|
|
236
|
+
Entities and value objects (`n.entity.ts`, `n.value-object.ts`) follow the aggregate root row. `n words` = the name with spaces instead of hyphens. Queries are the same as commands. \*The repository spec imports the wire first, then `import type { NRepository } from './n-repository'`.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* yes | no confirm prompt
|
|
14
14
|
* toggle:<n,..> checkbox prompt: toggle 1-based items (headers not counted),
|
|
15
15
|
* moving with the arrow keys, then press Enter
|
|
16
|
-
* none checkbox prompt: submit
|
|
16
|
+
* none checkbox prompt: submit as is (pre-checked items stay checked)
|
|
17
17
|
*/
|
|
18
18
|
import { spawn } from 'node:child_process';
|
|
19
19
|
import fs from 'node:fs';
|