@domain-first/project-structure 2.9.1 → 2.10.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 +2 -1
- package/dist/file-system.d.ts +4 -0
- package/dist/index.cjs +71 -5
- package/dist/index.js +71 -5
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/scaffold-new-domain-object.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ A bounded context groups a business area and its implementation. Within it, each
|
|
|
84
84
|
| `presentation/` | REST endpoints and presentation services. |
|
|
85
85
|
| `wiring/` | Factories that construct components and select implementations, when `@domain-first/wire` is enabled. |
|
|
86
86
|
|
|
87
|
-
The **Shared Layer** menu provides cross-context errors, application ports, and application, infrastructure, and presentation services under `<rootFolder>/shared`.
|
|
87
|
+
The **Shared Layer** menu provides cross-context errors, entities and value objects, application ports, and application, infrastructure, and presentation services under `<rootFolder>/shared`.
|
|
88
88
|
|
|
89
89
|
A project using handler and wiring integrations can grow into this structure:
|
|
90
90
|
|
|
@@ -131,6 +131,7 @@ Choose a bounded context, then a layer:
|
|
|
131
131
|
| Layer / menu option | Generated output |
|
|
132
132
|
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
133
133
|
| Domain → New Aggregate | Aggregate root and barrel export; optional repository contract, primary and test implementations, tests, and repository wiring. |
|
|
134
|
+
| Domain → New Entity / New Value Object | Entity or value object class with tests, in the `entities/` or `value-objects/` folder of a chosen aggregate (exported from its barrel) or of the context's `domain/`. Also in the Shared Layer, under `shared/domain/`. |
|
|
134
135
|
| Domain → Errors | Errors in the context namespace, nested namespaces, and exports. Uses `@domain-first/errors`. |
|
|
135
136
|
| Domain → New Service | Domain service class, with optional tests and wiring. |
|
|
136
137
|
| Application → New Use Case | Use case class; handler schemas and `handle` when enabled; optional tests and wiring. |
|
package/dist/file-system.d.ts
CHANGED
|
@@ -18,5 +18,9 @@ export declare class File extends FileSystemItem {
|
|
|
18
18
|
get data(): string;
|
|
19
19
|
set data(content: string);
|
|
20
20
|
addLine: (newLine: string, separator?: string) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Re-running a generator for the same name must not duplicate the line.
|
|
23
|
+
*/
|
|
24
|
+
addLineIfMissing: (newLine: string, separator?: string) => void;
|
|
21
25
|
}
|
|
22
26
|
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -99,6 +99,10 @@ class File extends FileSystemItem {
|
|
|
99
99
|
newLine.trim()
|
|
100
100
|
].filter((x)=>!!x).join(separator), 'utf8');
|
|
101
101
|
};
|
|
102
|
+
addLineIfMissing = (newLine, separator = '\n')=>{
|
|
103
|
+
const alreadyAdded = this.exists && this.data.split('\n').some((line)=>line.trim() === newLine.trim());
|
|
104
|
+
if (!alreadyAdded) this.addLine(newLine, separator);
|
|
105
|
+
};
|
|
102
106
|
}
|
|
103
107
|
class ProjectRoot {
|
|
104
108
|
path;
|
|
@@ -719,6 +723,60 @@ test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
|
|
|
719
723
|
})
|
|
720
724
|
`.trim());
|
|
721
725
|
};
|
|
726
|
+
const noAggregate = 'No aggregate';
|
|
727
|
+
const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
728
|
+
const name = await (0, prompts_namespaceObject.input)({
|
|
729
|
+
message: 'Name: '
|
|
730
|
+
});
|
|
731
|
+
const naming = new UnknownFormatNaming(name);
|
|
732
|
+
const aggregatesFolder = boundedContextFolder.subitem([
|
|
733
|
+
'domain',
|
|
734
|
+
'aggregates'
|
|
735
|
+
]);
|
|
736
|
+
const aggregateNames = aggregatesFolder.content.subfolderNames;
|
|
737
|
+
const aggregate = aggregateNames.length ? await (0, prompts_namespaceObject.select)({
|
|
738
|
+
message: 'Aggregate:',
|
|
739
|
+
choices: [
|
|
740
|
+
...aggregateNames,
|
|
741
|
+
noAggregate
|
|
742
|
+
]
|
|
743
|
+
}) : noAggregate;
|
|
744
|
+
const kindFolderName = 'entity' === kind ? 'entities' : 'value-objects';
|
|
745
|
+
const folder = aggregate === noAggregate ? boundedContextFolder.subitem([
|
|
746
|
+
'domain',
|
|
747
|
+
kindFolderName
|
|
748
|
+
]) : aggregatesFolder.subitem([
|
|
749
|
+
aggregate,
|
|
750
|
+
kindFolderName
|
|
751
|
+
]);
|
|
752
|
+
const fileName = `${naming.fileName}.${kind}`;
|
|
753
|
+
folder.createFile(`${fileName}.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types') ? `
|
|
754
|
+
import { domainType } from '@domain-first/types'
|
|
755
|
+
|
|
756
|
+
export class ${naming.ClassName} extends domainType() {
|
|
757
|
+
|
|
758
|
+
}`.trim() : `export class ${naming.ClassName} {}`);
|
|
759
|
+
if (aggregate !== noAggregate) aggregatesFolder.subitem([
|
|
760
|
+
aggregate
|
|
761
|
+
]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
|
|
762
|
+
const { testingLibrary } = ConfigFile.Instance.data;
|
|
763
|
+
if (testingLibrary) folder.createFile(`${fileName}.spec.ts`, `
|
|
764
|
+
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
765
|
+
import { ${naming.ClassName} } from './${fileName}'
|
|
766
|
+
|
|
767
|
+
let ${naming.variableName}: ${naming.ClassName}
|
|
768
|
+
|
|
769
|
+
beforeEach(() => {
|
|
770
|
+
${naming.variableName} = new ${naming.ClassName}()
|
|
771
|
+
})
|
|
772
|
+
|
|
773
|
+
describe('${naming.withSpaces}', () => {
|
|
774
|
+
test('can be instantiated via constructor', () => {
|
|
775
|
+
expect(${naming.variableName}).toBeDefined()
|
|
776
|
+
})
|
|
777
|
+
})
|
|
778
|
+
`.trim());
|
|
779
|
+
};
|
|
722
780
|
const scaffoldNewDomainService = async (boundedContextFolder)=>{
|
|
723
781
|
const portName = await (0, prompts_namespaceObject.input)({
|
|
724
782
|
message: 'Name:'
|
|
@@ -785,7 +843,7 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
785
843
|
message: 'Error name:'
|
|
786
844
|
});
|
|
787
845
|
const naming = new UnknownFormatNaming(errorName);
|
|
788
|
-
currentErrorFolder.file('index.ts').
|
|
846
|
+
currentErrorFolder.file('index.ts').addLineIfMissing(`export const ${naming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
|
|
789
847
|
return;
|
|
790
848
|
}
|
|
791
849
|
if ('New namespace' === selectedVariant) {
|
|
@@ -793,12 +851,12 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
793
851
|
message: 'Namespace name:'
|
|
794
852
|
});
|
|
795
853
|
const { ClassName, fileName } = new UnknownFormatNaming(namespaceName);
|
|
796
|
-
currentErrorFolder.createFile(`${fileName}.ts`, `
|
|
854
|
+
if (!currentErrorFolder.file(`${fileName}.ts`).exists) currentErrorFolder.createFile(`${fileName}.ts`, `
|
|
797
855
|
import { errorNamespace } from '@domain-first/errors'
|
|
798
856
|
|
|
799
857
|
export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors = errorNamespace('${boundedContextFolder.name}').subnamespace('${fileName}')
|
|
800
|
-
|
|
801
|
-
currentErrorFolder.file('index.ts').
|
|
858
|
+
`.trim());
|
|
859
|
+
currentErrorFolder.file('index.ts').addLineIfMissing(`export * from './${fileName}'`, '\n\n');
|
|
802
860
|
return;
|
|
803
861
|
}
|
|
804
862
|
const namespace = selectedVariant.substring(23);
|
|
@@ -807,7 +865,7 @@ export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).Cl
|
|
|
807
865
|
message: 'Error name:'
|
|
808
866
|
});
|
|
809
867
|
const { ClassName, fileName } = new UnknownFormatNaming(errorName);
|
|
810
|
-
currentErrorFolder.file(`${namespace}.ts`).
|
|
868
|
+
currentErrorFolder.file(`${namespace}.ts`).addLineIfMissing(`export const ${ClassName}${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${fileName}')`, '\n\n');
|
|
811
869
|
};
|
|
812
870
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
813
871
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
@@ -1537,15 +1595,23 @@ const main = async ()=>{
|
|
|
1537
1595
|
message: 'Domain layer operation:',
|
|
1538
1596
|
choices: specificContext ? [
|
|
1539
1597
|
'New Aggregate',
|
|
1598
|
+
'New Entity',
|
|
1599
|
+
'New Value Object',
|
|
1540
1600
|
'Errors',
|
|
1541
1601
|
'New Service'
|
|
1542
1602
|
] : [
|
|
1603
|
+
'New Entity',
|
|
1604
|
+
'New Value Object',
|
|
1543
1605
|
'Errors'
|
|
1544
1606
|
]
|
|
1545
1607
|
});
|
|
1546
1608
|
switch(operation){
|
|
1547
1609
|
case 'New Aggregate':
|
|
1548
1610
|
return void await scaffoldNewAggregateUseCase(boundedContextFolder);
|
|
1611
|
+
case 'New Entity':
|
|
1612
|
+
return void await scaffoldNewDomainObject(boundedContextFolder, 'entity');
|
|
1613
|
+
case 'New Value Object':
|
|
1614
|
+
return void await scaffoldNewDomainObject(boundedContextFolder, 'value-object');
|
|
1549
1615
|
case 'Errors':
|
|
1550
1616
|
return void await scaffoldNewErrorUseCase(boundedContextFolder);
|
|
1551
1617
|
case 'New Service':
|
package/dist/index.js
CHANGED
|
@@ -69,6 +69,10 @@ class File extends FileSystemItem {
|
|
|
69
69
|
newLine.trim()
|
|
70
70
|
].filter((x)=>!!x).join(separator), 'utf8');
|
|
71
71
|
};
|
|
72
|
+
addLineIfMissing = (newLine, separator = '\n')=>{
|
|
73
|
+
const alreadyAdded = this.exists && this.data.split('\n').some((line)=>line.trim() === newLine.trim());
|
|
74
|
+
if (!alreadyAdded) this.addLine(newLine, separator);
|
|
75
|
+
};
|
|
72
76
|
}
|
|
73
77
|
class ProjectRoot {
|
|
74
78
|
path;
|
|
@@ -689,6 +693,60 @@ test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
|
|
|
689
693
|
})
|
|
690
694
|
`.trim());
|
|
691
695
|
};
|
|
696
|
+
const noAggregate = 'No aggregate';
|
|
697
|
+
const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
698
|
+
const name = await input({
|
|
699
|
+
message: 'Name: '
|
|
700
|
+
});
|
|
701
|
+
const naming = new UnknownFormatNaming(name);
|
|
702
|
+
const aggregatesFolder = boundedContextFolder.subitem([
|
|
703
|
+
'domain',
|
|
704
|
+
'aggregates'
|
|
705
|
+
]);
|
|
706
|
+
const aggregateNames = aggregatesFolder.content.subfolderNames;
|
|
707
|
+
const aggregate = aggregateNames.length ? await prompts_select({
|
|
708
|
+
message: 'Aggregate:',
|
|
709
|
+
choices: [
|
|
710
|
+
...aggregateNames,
|
|
711
|
+
noAggregate
|
|
712
|
+
]
|
|
713
|
+
}) : noAggregate;
|
|
714
|
+
const kindFolderName = 'entity' === kind ? 'entities' : 'value-objects';
|
|
715
|
+
const folder = aggregate === noAggregate ? boundedContextFolder.subitem([
|
|
716
|
+
'domain',
|
|
717
|
+
kindFolderName
|
|
718
|
+
]) : aggregatesFolder.subitem([
|
|
719
|
+
aggregate,
|
|
720
|
+
kindFolderName
|
|
721
|
+
]);
|
|
722
|
+
const fileName = `${naming.fileName}.${kind}`;
|
|
723
|
+
folder.createFile(`${fileName}.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types') ? `
|
|
724
|
+
import { domainType } from '@domain-first/types'
|
|
725
|
+
|
|
726
|
+
export class ${naming.ClassName} extends domainType() {
|
|
727
|
+
|
|
728
|
+
}`.trim() : `export class ${naming.ClassName} {}`);
|
|
729
|
+
if (aggregate !== noAggregate) aggregatesFolder.subitem([
|
|
730
|
+
aggregate
|
|
731
|
+
]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
|
|
732
|
+
const { testingLibrary } = ConfigFile.Instance.data;
|
|
733
|
+
if (testingLibrary) folder.createFile(`${fileName}.spec.ts`, `
|
|
734
|
+
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
735
|
+
import { ${naming.ClassName} } from './${fileName}'
|
|
736
|
+
|
|
737
|
+
let ${naming.variableName}: ${naming.ClassName}
|
|
738
|
+
|
|
739
|
+
beforeEach(() => {
|
|
740
|
+
${naming.variableName} = new ${naming.ClassName}()
|
|
741
|
+
})
|
|
742
|
+
|
|
743
|
+
describe('${naming.withSpaces}', () => {
|
|
744
|
+
test('can be instantiated via constructor', () => {
|
|
745
|
+
expect(${naming.variableName}).toBeDefined()
|
|
746
|
+
})
|
|
747
|
+
})
|
|
748
|
+
`.trim());
|
|
749
|
+
};
|
|
692
750
|
const scaffoldNewDomainService = async (boundedContextFolder)=>{
|
|
693
751
|
const portName = await input({
|
|
694
752
|
message: 'Name:'
|
|
@@ -755,7 +813,7 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
755
813
|
message: 'Error name:'
|
|
756
814
|
});
|
|
757
815
|
const naming = new UnknownFormatNaming(errorName);
|
|
758
|
-
currentErrorFolder.file('index.ts').
|
|
816
|
+
currentErrorFolder.file('index.ts').addLineIfMissing(`export const ${naming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
|
|
759
817
|
return;
|
|
760
818
|
}
|
|
761
819
|
if ('New namespace' === selectedVariant) {
|
|
@@ -763,12 +821,12 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
763
821
|
message: 'Namespace name:'
|
|
764
822
|
});
|
|
765
823
|
const { ClassName, fileName } = new UnknownFormatNaming(namespaceName);
|
|
766
|
-
currentErrorFolder.createFile(`${fileName}.ts`, `
|
|
824
|
+
if (!currentErrorFolder.file(`${fileName}.ts`).exists) currentErrorFolder.createFile(`${fileName}.ts`, `
|
|
767
825
|
import { errorNamespace } from '@domain-first/errors'
|
|
768
826
|
|
|
769
827
|
export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors = errorNamespace('${boundedContextFolder.name}').subnamespace('${fileName}')
|
|
770
|
-
|
|
771
|
-
currentErrorFolder.file('index.ts').
|
|
828
|
+
`.trim());
|
|
829
|
+
currentErrorFolder.file('index.ts').addLineIfMissing(`export * from './${fileName}'`, '\n\n');
|
|
772
830
|
return;
|
|
773
831
|
}
|
|
774
832
|
const namespace = selectedVariant.substring(23);
|
|
@@ -777,7 +835,7 @@ export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).Cl
|
|
|
777
835
|
message: 'Error name:'
|
|
778
836
|
});
|
|
779
837
|
const { ClassName, fileName } = new UnknownFormatNaming(errorName);
|
|
780
|
-
currentErrorFolder.file(`${namespace}.ts`).
|
|
838
|
+
currentErrorFolder.file(`${namespace}.ts`).addLineIfMissing(`export const ${ClassName}${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${fileName}')`, '\n\n');
|
|
781
839
|
};
|
|
782
840
|
const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
783
841
|
const restPresentationFolder = boundedContextFolder.subitem([
|
|
@@ -1507,15 +1565,23 @@ const main = async ()=>{
|
|
|
1507
1565
|
message: 'Domain layer operation:',
|
|
1508
1566
|
choices: specificContext ? [
|
|
1509
1567
|
'New Aggregate',
|
|
1568
|
+
'New Entity',
|
|
1569
|
+
'New Value Object',
|
|
1510
1570
|
'Errors',
|
|
1511
1571
|
'New Service'
|
|
1512
1572
|
] : [
|
|
1573
|
+
'New Entity',
|
|
1574
|
+
'New Value Object',
|
|
1513
1575
|
'Errors'
|
|
1514
1576
|
]
|
|
1515
1577
|
});
|
|
1516
1578
|
switch(operation){
|
|
1517
1579
|
case 'New Aggregate':
|
|
1518
1580
|
return void await scaffoldNewAggregateUseCase(boundedContextFolder);
|
|
1581
|
+
case 'New Entity':
|
|
1582
|
+
return void await scaffoldNewDomainObject(boundedContextFolder, 'entity');
|
|
1583
|
+
case 'New Value Object':
|
|
1584
|
+
return void await scaffoldNewDomainObject(boundedContextFolder, 'value-object');
|
|
1519
1585
|
case 'Errors':
|
|
1520
1586
|
return void await scaffoldNewErrorUseCase(boundedContextFolder);
|
|
1521
1587
|
case 'New Service':
|
|
@@ -4,6 +4,7 @@ export * from './scaffold-new-application-port';
|
|
|
4
4
|
export * from './scaffold-new-application-service';
|
|
5
5
|
export * from './scaffold-new-bounded-context';
|
|
6
6
|
export * from './scaffold-new-command';
|
|
7
|
+
export * from './scaffold-new-domain-object';
|
|
7
8
|
export * from './scaffold-new-domain-service';
|
|
8
9
|
export * from './scaffold-new-error';
|
|
9
10
|
export * from './scaffold-new-handlers-rest-endpoint';
|