@domain-first/project-structure 3.1.0 → 3.2.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 CHANGED
@@ -28,7 +28,7 @@ The full technical specification lives in [API.md](./API.md).
28
28
 
29
29
  ### How to initialize a project
30
30
 
31
- Run `df-ps` in a project with a `package.json`. The first run asks for the source folder, the `@domain-first` packages you use, the default persistence implementation, React, Storybook and the testing library, then writes `domain-first.project-structure.config.json` and exits. With `@domain-first/handlers-rest`, it also scaffolds the [endpoint generator](#how-to-add-a-rest-endpoint); if `next` is among your dependencies, it offers to connect `nextAdapter` from `@domain-first/handlers-next` right away and prints the install command for it when it's missing.
31
+ Run `df-ps` in a project with a `package.json`. The first run asks for the source folder, the `@domain-first` packages you use, the default persistence implementation, whether to scaffold a shared in-memory DB for test implementations, React, Storybook and the testing library, then writes `domain-first.project-structure.config.json` and exits. With `@domain-first/handlers-rest`, it also scaffolds the [endpoint generator](#how-to-add-a-rest-endpoint); if `next` is among your dependencies, it offers to connect `nextAdapter` from `@domain-first/handlers-next` right away and prints the install command for it when it's missing.
32
32
 
33
33
  ```
34
34
  npx df-ps
@@ -44,6 +44,7 @@ npx df-ps
44
44
  "@domain-first/wire"
45
45
  ],
46
46
  "defaultPersistenceLayerImplementation": "prisma",
47
+ "withInMemoryDb": true,
47
48
  "useReact": false,
48
49
  "testingLibrary": "vitest"
49
50
  }
@@ -9,6 +9,7 @@ declare const configSchema: z.ZodObject<{
9
9
  "@domain-first/handlers-rest": "@domain-first/handlers-rest";
10
10
  }>>;
11
11
  defaultPersistenceLayerImplementation: z.ZodString;
12
+ withInMemoryDb: z.ZodOptional<z.ZodBoolean>;
12
13
  useReact: z.ZodBoolean;
13
14
  storybookFramework: z.ZodOptional<z.ZodString>;
14
15
  testingLibrary: z.ZodOptional<z.ZodString>;
@@ -0,0 +1,48 @@
1
+ import { File, Folder } from './file-system';
2
+ import { UnknownFormatNaming } from './unknown-format-naming';
3
+ import { type WiredModule } from './wiring';
4
+ /**
5
+ * The shared in-memory DB with its spec and wire, as the config says.
6
+ */
7
+ export declare const scaffoldInMemoryDb: (shared: Folder) => void;
8
+ /**
9
+ * Whether implementations of this type get the in-memory DB: it is
10
+ * enabled in the config and its files are there.
11
+ */
12
+ export declare const usesInMemoryDb: (implementationType: string) => boolean;
13
+ /**
14
+ * Adds a section of the type to the in-memory DB, unless it is there,
15
+ * and returns the section's field name.
16
+ */
17
+ export declare const addInMemoryDbSection: (typeNaming: UnknownFormatNaming, typeImportTarget: string) => string;
18
+ /**
19
+ * Import of the in-memory DB type for a file.
20
+ */
21
+ export declare const inMemoryDbTypeImport: (fromFile: string) => string;
22
+ /**
23
+ * Constructor of an implementation that keeps one section of the
24
+ * in-memory DB as `data`.
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;
36
+ /**
37
+ * Injects the whole in-memory DB into the implementation's constructor.
38
+ */
39
+ export declare const injectInMemoryDb: (classFile: File, implementationName: string) => void;
40
+ /**
41
+ * Passes the in-memory DB wire to the implementation's `wireClass`.
42
+ */
43
+ export declare const wireInMemoryDb: (consumerWireFile: File, implementationName: string) => void;
44
+ /**
45
+ * A spec without wiring builds the implementation itself, so it has to
46
+ * pass the in-memory DB.
47
+ */
48
+ export declare const passInMemoryDb: (specFile: File, implementationName: string) => void;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.cjs CHANGED
@@ -193,6 +193,7 @@ const configSchema = external_zod_default().object({
193
193
  '@domain-first/handlers-rest'
194
194
  ])),
195
195
  defaultPersistenceLayerImplementation: external_zod_default().string(),
196
+ withInMemoryDb: external_zod_default().boolean().optional(),
196
197
  useReact: external_zod_default().boolean(),
197
198
  storybookFramework: external_zod_default().string().optional(),
198
199
  testingLibrary: external_zod_default().string().optional()
@@ -1488,6 +1489,15 @@ const addConstructorParameters = (source, className, parameters)=>{
1488
1489
  ...parameters
1489
1490
  ], indent) + source.slice(closeIndex);
1490
1491
  };
1492
+ const addClassMember = (source, className, member)=>{
1493
+ const classMatch = new RegExp(`class\\s+${className}\\b[^{]*\\{`).exec(codeOnly(source));
1494
+ if (!classMatch) throw new Error(`Class ${className} not found`);
1495
+ const bodyStart = classMatch.index + classMatch[0].length;
1496
+ const bodyEnd = closingIndex(source, bodyStart - 1);
1497
+ const body = source.slice(bodyStart, bodyEnd).trimEnd();
1498
+ const separator = body.trim() ? '\n\n' : '\n';
1499
+ return `${source.slice(0, bodyStart)}${body}${separator} ${member}\n${source.slice(bodyEnd)}`;
1500
+ };
1491
1501
  const wireListRange = (source, className)=>{
1492
1502
  const match = new RegExp(`wireClass\\(\\s*${className}\\s*,\\s*\\[`).exec(codeOnly(source));
1493
1503
  if (!match) throw new Error(`wireClass(${className}, [...]) not found`);
@@ -1516,6 +1526,210 @@ const wireDependencies = (consumer, implementation, dependencies)=>{
1516
1526
  for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${relativeImport(implementation.file, dependency.typeFile)}'`);
1517
1527
  classFile.update(addConstructorParameters(classSource, implementation.className, dependencies.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
1518
1528
  };
1529
+ const inMemoryImplementationType = 'in-memory';
1530
+ const in_memory_db_className = 'InMemoryDbInfrastructureService';
1531
+ const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
1532
+ const in_memory_db_parameterName = 'inMemoryDbInfrastructureService';
1533
+ const inMemoryDbService = `type Entry = {
1534
+ id: unknown;
1535
+ item: any;
1536
+ };
1537
+
1538
+ declare global {
1539
+ var ___SHARED_IN_MEMORY_DB___: Record<string, Array<Entry>> | undefined;
1540
+ }
1541
+
1542
+ type Section<T, TId> = {
1543
+ all: (predicate?: (x: T) => boolean) => T[];
1544
+ first: (predicate: (x: T) => boolean) => T | null;
1545
+ withId: (id: TId) => T | null;
1546
+ lastAddedItem: () => T | null;
1547
+ save: (payload: T extends { id: TId } ? T : [TId, T]) => void;
1548
+ deleteById: (id: TId) => void;
1549
+ delete: (predicate: (x: T) => boolean) => void;
1550
+ };
1551
+
1552
+ type IdsAreEqual<TId> = (a: TId, b: TId) => boolean;
1553
+
1554
+ const comparisonMethodNames = ['equals', 'same', 'isSame', 'isEqual'] as const;
1555
+
1556
+ const defaultIdsAreEqual = (a: unknown, b: unknown): boolean => {
1557
+ if (typeof a !== 'object' || a === null) {
1558
+ return Object.is(a, b);
1559
+ }
1560
+
1561
+ for (const methodName of comparisonMethodNames) {
1562
+ const method: unknown = (a as Record<string, unknown>)[methodName];
1563
+ if (typeof method === 'function') {
1564
+ return Boolean(method.call(a, b));
1565
+ }
1566
+ }
1567
+
1568
+ return Object.is(a, b);
1569
+ };
1570
+
1571
+ const hasId = (x: unknown): x is { id: unknown } =>
1572
+ typeof x === 'object' && x !== null && 'id' in x;
1573
+
1574
+ export class InMemoryDbInfrastructureService {
1575
+ protected section<T extends { id: unknown }>(
1576
+ key: string,
1577
+ idsAreEqual?: IdsAreEqual<T['id']>
1578
+ ): Section<T, T['id']>;
1579
+ protected section<T, TId>(
1580
+ key: string,
1581
+ idsAreEqual?: IdsAreEqual<TId>
1582
+ ): Section<T, TId>;
1583
+ protected section<T, TId>(
1584
+ key: string,
1585
+ idsAreEqual: IdsAreEqual<TId> = defaultIdsAreEqual
1586
+ ): Section<T, TId> {
1587
+ if (!globalThis.___SHARED_IN_MEMORY_DB___) {
1588
+ globalThis.___SHARED_IN_MEMORY_DB___ = {};
1589
+ }
1590
+
1591
+ if (!globalThis.___SHARED_IN_MEMORY_DB___[key]) {
1592
+ globalThis.___SHARED_IN_MEMORY_DB___[key] = [];
1593
+ }
1594
+
1595
+ const items = (): T[] =>
1596
+ globalThis.___SHARED_IN_MEMORY_DB___![key].map(
1597
+ (entry) => entry.item
1598
+ );
1599
+
1600
+ return {
1601
+ all: (predicate: (x: T) => boolean = () => true): T[] =>
1602
+ items().filter(predicate),
1603
+ first: (predicate: (x: T) => boolean): T | null =>
1604
+ items().find(predicate) ?? null,
1605
+ withId: (id: TId): T | null =>
1606
+ items().find(
1607
+ (x: T) => hasId(x) && idsAreEqual(x.id as TId, id)
1608
+ ) ?? null,
1609
+ lastAddedItem: (): T | null =>
1610
+ globalThis.___SHARED_IN_MEMORY_DB___![key].at(-1)?.item ?? null,
1611
+ save: (payload: T extends { id: TId } ? T : [TId, T]) => {
1612
+ const id = Array.isArray(payload) ? payload[0] : payload.id;
1613
+ const item = Array.isArray(payload) ? payload[1] : payload;
1614
+ const entries = globalThis.___SHARED_IN_MEMORY_DB___![key];
1615
+ const existing = entries.find((entry) =>
1616
+ idsAreEqual(entry.id as TId, id)
1617
+ );
1618
+ if (existing) {
1619
+ existing.item = item;
1620
+ return;
1621
+ }
1622
+ entries.push({ id, item });
1623
+ },
1624
+ deleteById: (id: TId) => {
1625
+ globalThis.___SHARED_IN_MEMORY_DB___![key] =
1626
+ globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
1627
+ (entry) => !idsAreEqual(entry.id as TId, id)
1628
+ );
1629
+ },
1630
+ delete: (predicate: (x: T) => boolean) => {
1631
+ globalThis.___SHARED_IN_MEMORY_DB___![key] =
1632
+ globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
1633
+ (entry) => !predicate(entry.item)
1634
+ );
1635
+ }
1636
+ };
1637
+ }
1638
+ }
1639
+ `;
1640
+ const inMemoryDbWiring = `import { wireClass } from '@domain-first/wire';
1641
+ import { InMemoryDbInfrastructureService } from '../../infrastructure/services/in-memory-db-infrastructure-service';
1642
+
1643
+ export const wireInMemoryDbInfrastructureService = wireClass(
1644
+ InMemoryDbInfrastructureService,
1645
+ []
1646
+ );
1647
+ `;
1648
+ const inMemoryDbSpec = (testingLibrary, withWiring)=>`
1649
+ import { describe, test, expect, beforeEach } from '${testingLibrary}'
1650
+ ${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
1651
+ import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
1652
+
1653
+ let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
1654
+
1655
+ beforeEach(() => {
1656
+ inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
1657
+ })
1658
+
1659
+ describe('in memory db', () => {
1660
+ test('can be ${withWiring ? 'wired' : 'created'}', () => {
1661
+ expect(inMemoryDbInfrastructureService).toBeDefined()
1662
+ })
1663
+ })
1664
+ `.trim();
1665
+ const in_memory_db_withWiring = ()=>ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
1666
+ const in_memory_db_sharedFolder = ()=>new Folder(new ProjectRoot().path).subitem([
1667
+ ConfigFile.Instance.data.rootFolder,
1668
+ 'shared'
1669
+ ]);
1670
+ const serviceFile = ()=>new File(in_memory_db_sharedFolder().path).subitem([
1671
+ 'infrastructure',
1672
+ 'services',
1673
+ 'in-memory-db-infrastructure-service.ts'
1674
+ ]);
1675
+ const in_memory_db_wireFile = ()=>new File(in_memory_db_sharedFolder().path).subitem([
1676
+ 'wiring',
1677
+ 'infrastructure-services',
1678
+ 'wire-in-memory-db-infrastructure-service.ts'
1679
+ ]);
1680
+ const scaffoldInMemoryDb = (shared)=>{
1681
+ const { testingLibrary } = ConfigFile.Instance.data;
1682
+ const servicesFolder = shared.subitem([
1683
+ 'infrastructure',
1684
+ 'services'
1685
+ ]);
1686
+ servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
1687
+ if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
1688
+ if (in_memory_db_withWiring()) shared.subitem([
1689
+ 'wiring',
1690
+ 'infrastructure-services'
1691
+ ]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
1692
+ };
1693
+ const usesInMemoryDb = (implementationType)=>Boolean(ConfigFile.Instance.data.withInMemoryDb) && new UnknownFormatNaming(implementationType).fileName === inMemoryImplementationType && serviceFile().exists && (!in_memory_db_withWiring() || in_memory_db_wireFile().exists);
1694
+ const plural = (word)=>{
1695
+ if (/[^aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`;
1696
+ if (/(s|x|z|ch|sh)$/i.test(word)) return `${word}es`;
1697
+ return `${word}s`;
1698
+ };
1699
+ const addInMemoryDbSection = (typeNaming, typeImportTarget)=>{
1700
+ const file = serviceFile();
1701
+ const sectionNaming = new UnknownFormatNaming(plural(typeNaming.fileName));
1702
+ const field = sectionNaming.variableName;
1703
+ if (new RegExp(`\\b${field}\\s*=\\s*this\\.section\\b`).test(file.data)) return field;
1704
+ const withImport = addImport(file.data, `import type { ${typeNaming.ClassName} } from '${relativeImport(file.path, typeImportTarget)}';`);
1705
+ file.update(addClassMember(withImport, in_memory_db_className, `${field} = this.section<${typeNaming.ClassName}>('${sectionNaming.fileName.toUpperCase()}');`));
1706
+ return field;
1707
+ };
1708
+ const inMemoryDbTypeImport = (fromFile)=>`import type { ${in_memory_db_className} } from '${relativeImport(fromFile, serviceFile().path)}'`;
1709
+ const inMemoryDbSectionMembers = (field, derived)=>`
1710
+ private readonly data: ${in_memory_db_className}['${field}']
1711
+
1712
+ constructor(${in_memory_db_parameterName}: ${in_memory_db_className}) {
1713
+ ${derived ? 'super()\n ' : ''}this.data = ${in_memory_db_parameterName}.${field}
1714
+ }
1715
+ `.trim();
1716
+ const keepInMemoryDbSection = (classFile, field)=>{
1717
+ classFile.update(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)).replace('constructor() {}', inMemoryDbSectionMembers(field, false)));
1718
+ };
1719
+ const isInMemoryDb = (module)=>module.wireName === in_memory_db_wireName;
1720
+ const injectInMemoryDb = (classFile, implementationName)=>{
1721
+ classFile.update(addConstructorParameters(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)), implementationName, [
1722
+ `private readonly ${in_memory_db_parameterName}: ${in_memory_db_className}`
1723
+ ]));
1724
+ };
1725
+ const wireInMemoryDb = (consumerWireFile, implementationName)=>{
1726
+ consumerWireFile.update(addWireDependencies(addImport(consumerWireFile.data, `import { ${in_memory_db_wireName} } from '${relativeImport(consumerWireFile.path, in_memory_db_wireFile().path)}'`), implementationName, [
1727
+ in_memory_db_wireName
1728
+ ]));
1729
+ };
1730
+ const passInMemoryDb = (specFile, implementationName)=>{
1731
+ 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}())`));
1732
+ };
1519
1733
  const kindTitles = {
1520
1734
  repositories: 'Repositories',
1521
1735
  'domain-services': 'Domain services',
@@ -1532,7 +1746,8 @@ const groupedChoices = (items, suggested = [])=>{
1532
1746
  new prompts_namespaceObject.Separator('── Suggested'),
1533
1747
  ...suggested.map((x)=>({
1534
1748
  name: x.label,
1535
- value: x
1749
+ value: x,
1750
+ checked: true
1536
1751
  }))
1537
1752
  ] : [];
1538
1753
  const kinds = [
@@ -1573,7 +1788,7 @@ const contextAndSharedModules = (boundedContextFolder)=>{
1573
1788
  }))
1574
1789
  ];
1575
1790
  };
1576
- const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations)=>{
1791
+ const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations, customWiring)=>{
1577
1792
  const options = contextAndSharedModules(boundedContextFolder);
1578
1793
  let asked = false;
1579
1794
  for (const implementation of implementations){
@@ -1589,13 +1804,14 @@ const promptDependencies = async (boundedContextFolder, consumer, implementation
1589
1804
  pageSize: groupedPageSize,
1590
1805
  loop: false
1591
1806
  });
1592
- if (dependencies.length) wireDependencies(consumer, implementation, dependencies.map((x)=>x.module));
1807
+ const defaultWired = dependencies.map((x)=>x.module).filter((x)=>!customWiring?.(implementation, x));
1808
+ if (defaultWired.length) wireDependencies(consumer, implementation, defaultWired);
1593
1809
  }
1594
1810
  return asked;
1595
1811
  };
1596
- const wireNewModuleDependencies = async (boundedContextFolder, wireFile)=>{
1812
+ const wireNewModuleDependencies = async (boundedContextFolder, wireFile, customWiring)=>{
1597
1813
  const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
1598
- if (consumer) await promptDependencies(boundedContextFolder, consumer);
1814
+ if (consumer) await promptDependencies(boundedContextFolder, consumer, consumer.implementations, customWiring);
1599
1815
  };
1600
1816
  const wireDependency = async (boundedContextFolder)=>{
1601
1817
  const modules = findWiredModules(boundedContextFolder.path);
@@ -1766,6 +1982,9 @@ const initializeUseCase = async ()=>{
1766
1982
  const defaultPersistenceLayerImplementation = await (0, prompts_namespaceObject.input)({
1767
1983
  message: 'Default persistence layer implementation:'
1768
1984
  });
1985
+ const withInMemoryDb = await (0, prompts_namespaceObject.confirm)({
1986
+ message: 'Scaffold in-memory DB for test implementations'
1987
+ });
1769
1988
  const useReact = await (0, prompts_namespaceObject.confirm)({
1770
1989
  message: 'Use React'
1771
1990
  });
@@ -1789,6 +2008,7 @@ const initializeUseCase = async ()=>{
1789
2008
  rootFolder: rootFolderName,
1790
2009
  domainFirstPackages,
1791
2010
  defaultPersistenceLayerImplementation,
2011
+ withInMemoryDb,
1792
2012
  useReact,
1793
2013
  storybookFramework,
1794
2014
  testingLibrary
@@ -1806,6 +2026,10 @@ export const envBranchedWire = branchedWire(() => {
1806
2026
  return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
1807
2027
  });
1808
2028
  `.trim());
2029
+ if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
2030
+ rootFolderName,
2031
+ 'shared'
2032
+ ]));
1809
2033
  if (domainFirstPackages.includes('@domain-first/errors')) rootFolder.subitem([
1810
2034
  rootFolderName,
1811
2035
  'shared'
@@ -2105,7 +2329,8 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
2105
2329
  'aggregates',
2106
2330
  aggregateName
2107
2331
  ]);
2108
- aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types') ? `
2332
+ const withTypes = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
2333
+ aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, withTypes ? `
2109
2334
  import { domainType } from '@domain-first/types'
2110
2335
 
2111
2336
  export class ${aggregateNaming.ClassName} extends domainType() {
@@ -2119,11 +2344,11 @@ import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggr
2119
2344
  let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
2120
2345
 
2121
2346
  beforeEach(() => {
2122
- ${aggregateNaming.variableName} = new ${aggregateNaming.ClassName}()
2347
+ ${aggregateNaming.variableName} = ${withTypes ? `${aggregateNaming.ClassName}.of({})` : `new ${aggregateNaming.ClassName}()`}
2123
2348
  })
2124
2349
 
2125
2350
  describe('${aggregateNaming.withSpaces}', () => {
2126
- test('can be instantiated via constructor', () => {
2351
+ test('can be instantiated via ${withTypes ? 'of' : 'constructor'}', () => {
2127
2352
  expect(${aggregateNaming.variableName}).toBeDefined()
2128
2353
  })
2129
2354
  })
@@ -2154,9 +2379,25 @@ describe('${aggregateNaming.withSpaces}', () => {
2154
2379
  ].filter((x)=>!!x);
2155
2380
  for (const implementation of implementationTypes){
2156
2381
  const naming = new UnknownFormatNaming(implementation);
2157
- infrastructureRepositoriesFolder.subitem([
2382
+ const repositoryFolder = infrastructureRepositoriesFolder.subitem([
2158
2383
  naming.fileName
2159
- ]).createFile(`${naming.fileName}-${aggregateName}-repository.ts`, `
2384
+ ]);
2385
+ const repositoryFileName = `${naming.fileName}-${aggregateName}-repository.ts`;
2386
+ if (usesInMemoryDb(implementation) && !ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
2387
+ const section = addInMemoryDbSection(aggregateNaming, aggregatesFolder.path);
2388
+ repositoryFolder.createFile(repositoryFileName, `
2389
+ ${inMemoryDbTypeImport(repositoryFolder.subitem([
2390
+ repositoryFileName
2391
+ ]).path)}
2392
+ import { ${aggregateNaming.ClassName}Repository } from '../../../domain/aggregates/${aggregateName}'
2393
+
2394
+ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implements ${aggregateNaming.ClassName}Repository {
2395
+ ${inMemoryDbSectionMembers(section, false)}
2396
+ }
2397
+ `.trim());
2398
+ continue;
2399
+ }
2400
+ repositoryFolder.createFile(repositoryFileName, `
2160
2401
  import { ${aggregateNaming.ClassName}Repository } from '../../../domain/aggregates/${aggregateName}'
2161
2402
 
2162
2403
  export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implements ${aggregateNaming.ClassName}Repository {
@@ -2167,7 +2408,7 @@ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implement
2167
2408
  }
2168
2409
  if (scaffoldUnitTests) {
2169
2410
  const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
2170
- aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
2411
+ const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
2171
2412
  import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
2172
2413
  ${ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
2173
2414
  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'
@@ -2186,6 +2427,7 @@ describe('${aggregateNaming.withSpaces} repository', () => {
2186
2427
  })
2187
2428
  })
2188
2429
  `.trim());
2430
+ if (!ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
2189
2431
  }
2190
2432
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
2191
2433
  const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
@@ -2206,7 +2448,12 @@ export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
2206
2448
  production: wire${implementationNaming.ClassName}Implementation
2207
2449
  })
2208
2450
  `.trim());
2209
- await wireNewModuleDependencies(boundedContextFolder, wireFile);
2451
+ await wireNewModuleDependencies(boundedContextFolder, wireFile, (implementation, dependency)=>{
2452
+ if (!isInMemoryDb(dependency)) return false;
2453
+ keepInMemoryDbSection(new File(implementation.file), addInMemoryDbSection(aggregateNaming, aggregatesFolder.path));
2454
+ wireInMemoryDb(wireFile, implementation.className);
2455
+ return true;
2456
+ });
2210
2457
  }
2211
2458
  }
2212
2459
  };
@@ -2422,7 +2669,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
2422
2669
  ].filter((x)=>!!x);
2423
2670
  for (const implementation of implementationTypes){
2424
2671
  const formatNaming = new UnknownFormatNaming(implementation);
2425
- infrastructureFolder.subitem([
2672
+ const implementationFile = infrastructureFolder.subitem([
2426
2673
  formatNaming.fileName
2427
2674
  ]).createFile(`${formatNaming.fileName}-${naming.fileName}-command.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
2428
2675
  import { defineHandler } from '@domain-first/handlers'
@@ -2450,6 +2697,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${namin
2450
2697
  }
2451
2698
  }
2452
2699
  `.trim());
2700
+ if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
2453
2701
  }
2454
2702
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.subitem([
2455
2703
  'execution'
@@ -2471,7 +2719,7 @@ export abstract class ${naming.ClassName}Command {
2471
2719
  }`.trim());
2472
2720
  if (scaffoldUnitTests) {
2473
2721
  const implementationNaming = new UnknownFormatNaming(implementationType);
2474
- commandsFolder.subitem([
2722
+ const specFile = commandsFolder.subitem([
2475
2723
  'execution'
2476
2724
  ]).createFile(`${naming.fileName}-command.spec.ts`, `
2477
2725
  import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
@@ -2492,6 +2740,7 @@ describe('${naming.withSpaces} command', () => {
2492
2740
  })
2493
2741
  })
2494
2742
  `.trim());
2743
+ if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
2495
2744
  }
2496
2745
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
2497
2746
  const implementationNaming = new UnknownFormatNaming(implementationType);
@@ -2602,7 +2851,8 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
2602
2851
  kindFolderName
2603
2852
  ]);
2604
2853
  const fileName = `${naming.fileName}.${kind}`;
2605
- folder.createFile(`${fileName}.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types') ? `
2854
+ const withTypes = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
2855
+ folder.createFile(`${fileName}.ts`, withTypes ? `
2606
2856
  import { domainType } from '@domain-first/types'
2607
2857
 
2608
2858
  export class ${naming.ClassName} extends domainType() {
@@ -2619,11 +2869,11 @@ import { ${naming.ClassName} } from './${fileName}'
2619
2869
  let ${naming.variableName}: ${naming.ClassName}
2620
2870
 
2621
2871
  beforeEach(() => {
2622
- ${naming.variableName} = new ${naming.ClassName}()
2872
+ ${naming.variableName} = ${withTypes ? `${naming.ClassName}.of({})` : `new ${naming.ClassName}()`}
2623
2873
  })
2624
2874
 
2625
2875
  describe('${naming.withSpaces}', () => {
2626
- test('can be instantiated via constructor', () => {
2876
+ test('can be instantiated via ${withTypes ? 'of' : 'constructor'}', () => {
2627
2877
  expect(${naming.variableName}).toBeDefined()
2628
2878
  })
2629
2879
  })
@@ -2932,7 +3182,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
2932
3182
  ].filter((x)=>!!x);
2933
3183
  for (const implementation of implementationTypes){
2934
3184
  const formatNaming = new UnknownFormatNaming(implementation);
2935
- infrastructureFolder.subitem([
3185
+ const implementationFile = infrastructureFolder.subitem([
2936
3186
  formatNaming.fileName
2937
3187
  ]).createFile(`${formatNaming.fileName}-${naming.fileName}-query.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
2938
3188
  import { defineHandler } from '@domain-first/handlers'
@@ -2960,6 +3210,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.
2960
3210
  }
2961
3211
  }
2962
3212
  `.trim());
3213
+ if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
2963
3214
  }
2964
3215
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.subitem([
2965
3216
  'execution'
@@ -2981,7 +3232,7 @@ export abstract class ${naming.ClassName}Query {
2981
3232
  }`.trim());
2982
3233
  if (scaffoldUnitTests) {
2983
3234
  const implementationNaming = new UnknownFormatNaming(implementationType);
2984
- queriesFolder.subitem([
3235
+ const specFile = queriesFolder.subitem([
2985
3236
  'execution'
2986
3237
  ]).createFile(`${naming.fileName}-query.spec.ts`, `
2987
3238
  import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
@@ -3002,6 +3253,7 @@ describe('${naming.withSpaces} query', () => {
3002
3253
  })
3003
3254
  })
3004
3255
  `.trim());
3256
+ if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
3005
3257
  }
3006
3258
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
3007
3259
  const implementationNaming = new UnknownFormatNaming(implementationType);
package/dist/index.js CHANGED
@@ -164,6 +164,7 @@ const configSchema = zod.object({
164
164
  '@domain-first/handlers-rest'
165
165
  ])),
166
166
  defaultPersistenceLayerImplementation: zod.string(),
167
+ withInMemoryDb: zod.boolean().optional(),
167
168
  useReact: zod.boolean(),
168
169
  storybookFramework: zod.string().optional(),
169
170
  testingLibrary: zod.string().optional()
@@ -1458,6 +1459,15 @@ const addConstructorParameters = (source, className, parameters)=>{
1458
1459
  ...parameters
1459
1460
  ], indent) + source.slice(closeIndex);
1460
1461
  };
1462
+ const addClassMember = (source, className, member)=>{
1463
+ const classMatch = new RegExp(`class\\s+${className}\\b[^{]*\\{`).exec(codeOnly(source));
1464
+ if (!classMatch) throw new Error(`Class ${className} not found`);
1465
+ const bodyStart = classMatch.index + classMatch[0].length;
1466
+ const bodyEnd = closingIndex(source, bodyStart - 1);
1467
+ const body = source.slice(bodyStart, bodyEnd).trimEnd();
1468
+ const separator = body.trim() ? '\n\n' : '\n';
1469
+ return `${source.slice(0, bodyStart)}${body}${separator} ${member}\n${source.slice(bodyEnd)}`;
1470
+ };
1461
1471
  const wireListRange = (source, className)=>{
1462
1472
  const match = new RegExp(`wireClass\\(\\s*${className}\\s*,\\s*\\[`).exec(codeOnly(source));
1463
1473
  if (!match) throw new Error(`wireClass(${className}, [...]) not found`);
@@ -1486,6 +1496,210 @@ const wireDependencies = (consumer, implementation, dependencies)=>{
1486
1496
  for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${relativeImport(implementation.file, dependency.typeFile)}'`);
1487
1497
  classFile.update(addConstructorParameters(classSource, implementation.className, dependencies.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
1488
1498
  };
1499
+ const inMemoryImplementationType = 'in-memory';
1500
+ const in_memory_db_className = 'InMemoryDbInfrastructureService';
1501
+ const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
1502
+ const in_memory_db_parameterName = 'inMemoryDbInfrastructureService';
1503
+ const inMemoryDbService = `type Entry = {
1504
+ id: unknown;
1505
+ item: any;
1506
+ };
1507
+
1508
+ declare global {
1509
+ var ___SHARED_IN_MEMORY_DB___: Record<string, Array<Entry>> | undefined;
1510
+ }
1511
+
1512
+ type Section<T, TId> = {
1513
+ all: (predicate?: (x: T) => boolean) => T[];
1514
+ first: (predicate: (x: T) => boolean) => T | null;
1515
+ withId: (id: TId) => T | null;
1516
+ lastAddedItem: () => T | null;
1517
+ save: (payload: T extends { id: TId } ? T : [TId, T]) => void;
1518
+ deleteById: (id: TId) => void;
1519
+ delete: (predicate: (x: T) => boolean) => void;
1520
+ };
1521
+
1522
+ type IdsAreEqual<TId> = (a: TId, b: TId) => boolean;
1523
+
1524
+ const comparisonMethodNames = ['equals', 'same', 'isSame', 'isEqual'] as const;
1525
+
1526
+ const defaultIdsAreEqual = (a: unknown, b: unknown): boolean => {
1527
+ if (typeof a !== 'object' || a === null) {
1528
+ return Object.is(a, b);
1529
+ }
1530
+
1531
+ for (const methodName of comparisonMethodNames) {
1532
+ const method: unknown = (a as Record<string, unknown>)[methodName];
1533
+ if (typeof method === 'function') {
1534
+ return Boolean(method.call(a, b));
1535
+ }
1536
+ }
1537
+
1538
+ return Object.is(a, b);
1539
+ };
1540
+
1541
+ const hasId = (x: unknown): x is { id: unknown } =>
1542
+ typeof x === 'object' && x !== null && 'id' in x;
1543
+
1544
+ export class InMemoryDbInfrastructureService {
1545
+ protected section<T extends { id: unknown }>(
1546
+ key: string,
1547
+ idsAreEqual?: IdsAreEqual<T['id']>
1548
+ ): Section<T, T['id']>;
1549
+ protected section<T, TId>(
1550
+ key: string,
1551
+ idsAreEqual?: IdsAreEqual<TId>
1552
+ ): Section<T, TId>;
1553
+ protected section<T, TId>(
1554
+ key: string,
1555
+ idsAreEqual: IdsAreEqual<TId> = defaultIdsAreEqual
1556
+ ): Section<T, TId> {
1557
+ if (!globalThis.___SHARED_IN_MEMORY_DB___) {
1558
+ globalThis.___SHARED_IN_MEMORY_DB___ = {};
1559
+ }
1560
+
1561
+ if (!globalThis.___SHARED_IN_MEMORY_DB___[key]) {
1562
+ globalThis.___SHARED_IN_MEMORY_DB___[key] = [];
1563
+ }
1564
+
1565
+ const items = (): T[] =>
1566
+ globalThis.___SHARED_IN_MEMORY_DB___![key].map(
1567
+ (entry) => entry.item
1568
+ );
1569
+
1570
+ return {
1571
+ all: (predicate: (x: T) => boolean = () => true): T[] =>
1572
+ items().filter(predicate),
1573
+ first: (predicate: (x: T) => boolean): T | null =>
1574
+ items().find(predicate) ?? null,
1575
+ withId: (id: TId): T | null =>
1576
+ items().find(
1577
+ (x: T) => hasId(x) && idsAreEqual(x.id as TId, id)
1578
+ ) ?? null,
1579
+ lastAddedItem: (): T | null =>
1580
+ globalThis.___SHARED_IN_MEMORY_DB___![key].at(-1)?.item ?? null,
1581
+ save: (payload: T extends { id: TId } ? T : [TId, T]) => {
1582
+ const id = Array.isArray(payload) ? payload[0] : payload.id;
1583
+ const item = Array.isArray(payload) ? payload[1] : payload;
1584
+ const entries = globalThis.___SHARED_IN_MEMORY_DB___![key];
1585
+ const existing = entries.find((entry) =>
1586
+ idsAreEqual(entry.id as TId, id)
1587
+ );
1588
+ if (existing) {
1589
+ existing.item = item;
1590
+ return;
1591
+ }
1592
+ entries.push({ id, item });
1593
+ },
1594
+ deleteById: (id: TId) => {
1595
+ globalThis.___SHARED_IN_MEMORY_DB___![key] =
1596
+ globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
1597
+ (entry) => !idsAreEqual(entry.id as TId, id)
1598
+ );
1599
+ },
1600
+ delete: (predicate: (x: T) => boolean) => {
1601
+ globalThis.___SHARED_IN_MEMORY_DB___![key] =
1602
+ globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
1603
+ (entry) => !predicate(entry.item)
1604
+ );
1605
+ }
1606
+ };
1607
+ }
1608
+ }
1609
+ `;
1610
+ const inMemoryDbWiring = `import { wireClass } from '@domain-first/wire';
1611
+ import { InMemoryDbInfrastructureService } from '../../infrastructure/services/in-memory-db-infrastructure-service';
1612
+
1613
+ export const wireInMemoryDbInfrastructureService = wireClass(
1614
+ InMemoryDbInfrastructureService,
1615
+ []
1616
+ );
1617
+ `;
1618
+ const inMemoryDbSpec = (testingLibrary, withWiring)=>`
1619
+ import { describe, test, expect, beforeEach } from '${testingLibrary}'
1620
+ ${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
1621
+ import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
1622
+
1623
+ let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
1624
+
1625
+ beforeEach(() => {
1626
+ inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
1627
+ })
1628
+
1629
+ describe('in memory db', () => {
1630
+ test('can be ${withWiring ? 'wired' : 'created'}', () => {
1631
+ expect(inMemoryDbInfrastructureService).toBeDefined()
1632
+ })
1633
+ })
1634
+ `.trim();
1635
+ const in_memory_db_withWiring = ()=>ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
1636
+ const in_memory_db_sharedFolder = ()=>new Folder(new ProjectRoot().path).subitem([
1637
+ ConfigFile.Instance.data.rootFolder,
1638
+ 'shared'
1639
+ ]);
1640
+ const serviceFile = ()=>new File(in_memory_db_sharedFolder().path).subitem([
1641
+ 'infrastructure',
1642
+ 'services',
1643
+ 'in-memory-db-infrastructure-service.ts'
1644
+ ]);
1645
+ const in_memory_db_wireFile = ()=>new File(in_memory_db_sharedFolder().path).subitem([
1646
+ 'wiring',
1647
+ 'infrastructure-services',
1648
+ 'wire-in-memory-db-infrastructure-service.ts'
1649
+ ]);
1650
+ const scaffoldInMemoryDb = (shared)=>{
1651
+ const { testingLibrary } = ConfigFile.Instance.data;
1652
+ const servicesFolder = shared.subitem([
1653
+ 'infrastructure',
1654
+ 'services'
1655
+ ]);
1656
+ servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
1657
+ if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
1658
+ if (in_memory_db_withWiring()) shared.subitem([
1659
+ 'wiring',
1660
+ 'infrastructure-services'
1661
+ ]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
1662
+ };
1663
+ const usesInMemoryDb = (implementationType)=>Boolean(ConfigFile.Instance.data.withInMemoryDb) && new UnknownFormatNaming(implementationType).fileName === inMemoryImplementationType && serviceFile().exists && (!in_memory_db_withWiring() || in_memory_db_wireFile().exists);
1664
+ const plural = (word)=>{
1665
+ if (/[^aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`;
1666
+ if (/(s|x|z|ch|sh)$/i.test(word)) return `${word}es`;
1667
+ return `${word}s`;
1668
+ };
1669
+ const addInMemoryDbSection = (typeNaming, typeImportTarget)=>{
1670
+ const file = serviceFile();
1671
+ const sectionNaming = new UnknownFormatNaming(plural(typeNaming.fileName));
1672
+ const field = sectionNaming.variableName;
1673
+ if (new RegExp(`\\b${field}\\s*=\\s*this\\.section\\b`).test(file.data)) return field;
1674
+ const withImport = addImport(file.data, `import type { ${typeNaming.ClassName} } from '${relativeImport(file.path, typeImportTarget)}';`);
1675
+ file.update(addClassMember(withImport, in_memory_db_className, `${field} = this.section<${typeNaming.ClassName}>('${sectionNaming.fileName.toUpperCase()}');`));
1676
+ return field;
1677
+ };
1678
+ const inMemoryDbTypeImport = (fromFile)=>`import type { ${in_memory_db_className} } from '${relativeImport(fromFile, serviceFile().path)}'`;
1679
+ const inMemoryDbSectionMembers = (field, derived)=>`
1680
+ private readonly data: ${in_memory_db_className}['${field}']
1681
+
1682
+ constructor(${in_memory_db_parameterName}: ${in_memory_db_className}) {
1683
+ ${derived ? 'super()\n ' : ''}this.data = ${in_memory_db_parameterName}.${field}
1684
+ }
1685
+ `.trim();
1686
+ const keepInMemoryDbSection = (classFile, field)=>{
1687
+ classFile.update(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)).replace('constructor() {}', inMemoryDbSectionMembers(field, false)));
1688
+ };
1689
+ const isInMemoryDb = (module)=>module.wireName === in_memory_db_wireName;
1690
+ const injectInMemoryDb = (classFile, implementationName)=>{
1691
+ classFile.update(addConstructorParameters(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)), implementationName, [
1692
+ `private readonly ${in_memory_db_parameterName}: ${in_memory_db_className}`
1693
+ ]));
1694
+ };
1695
+ const wireInMemoryDb = (consumerWireFile, implementationName)=>{
1696
+ consumerWireFile.update(addWireDependencies(addImport(consumerWireFile.data, `import { ${in_memory_db_wireName} } from '${relativeImport(consumerWireFile.path, in_memory_db_wireFile().path)}'`), implementationName, [
1697
+ in_memory_db_wireName
1698
+ ]));
1699
+ };
1700
+ const passInMemoryDb = (specFile, implementationName)=>{
1701
+ 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}())`));
1702
+ };
1489
1703
  const kindTitles = {
1490
1704
  repositories: 'Repositories',
1491
1705
  'domain-services': 'Domain services',
@@ -1502,7 +1716,8 @@ const groupedChoices = (items, suggested = [])=>{
1502
1716
  new Separator('── Suggested'),
1503
1717
  ...suggested.map((x)=>({
1504
1718
  name: x.label,
1505
- value: x
1719
+ value: x,
1720
+ checked: true
1506
1721
  }))
1507
1722
  ] : [];
1508
1723
  const kinds = [
@@ -1543,7 +1758,7 @@ const contextAndSharedModules = (boundedContextFolder)=>{
1543
1758
  }))
1544
1759
  ];
1545
1760
  };
1546
- const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations)=>{
1761
+ const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations, customWiring)=>{
1547
1762
  const options = contextAndSharedModules(boundedContextFolder);
1548
1763
  let asked = false;
1549
1764
  for (const implementation of implementations){
@@ -1559,13 +1774,14 @@ const promptDependencies = async (boundedContextFolder, consumer, implementation
1559
1774
  pageSize: groupedPageSize,
1560
1775
  loop: false
1561
1776
  });
1562
- if (dependencies.length) wireDependencies(consumer, implementation, dependencies.map((x)=>x.module));
1777
+ const defaultWired = dependencies.map((x)=>x.module).filter((x)=>!customWiring?.(implementation, x));
1778
+ if (defaultWired.length) wireDependencies(consumer, implementation, defaultWired);
1563
1779
  }
1564
1780
  return asked;
1565
1781
  };
1566
- const wireNewModuleDependencies = async (boundedContextFolder, wireFile)=>{
1782
+ const wireNewModuleDependencies = async (boundedContextFolder, wireFile, customWiring)=>{
1567
1783
  const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
1568
- if (consumer) await promptDependencies(boundedContextFolder, consumer);
1784
+ if (consumer) await promptDependencies(boundedContextFolder, consumer, consumer.implementations, customWiring);
1569
1785
  };
1570
1786
  const wireDependency = async (boundedContextFolder)=>{
1571
1787
  const modules = findWiredModules(boundedContextFolder.path);
@@ -1736,6 +1952,9 @@ const initializeUseCase = async ()=>{
1736
1952
  const defaultPersistenceLayerImplementation = await input({
1737
1953
  message: 'Default persistence layer implementation:'
1738
1954
  });
1955
+ const withInMemoryDb = await prompts_confirm({
1956
+ message: 'Scaffold in-memory DB for test implementations'
1957
+ });
1739
1958
  const useReact = await prompts_confirm({
1740
1959
  message: 'Use React'
1741
1960
  });
@@ -1759,6 +1978,7 @@ const initializeUseCase = async ()=>{
1759
1978
  rootFolder: rootFolderName,
1760
1979
  domainFirstPackages,
1761
1980
  defaultPersistenceLayerImplementation,
1981
+ withInMemoryDb,
1762
1982
  useReact,
1763
1983
  storybookFramework,
1764
1984
  testingLibrary
@@ -1776,6 +1996,10 @@ export const envBranchedWire = branchedWire(() => {
1776
1996
  return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
1777
1997
  });
1778
1998
  `.trim());
1999
+ if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
2000
+ rootFolderName,
2001
+ 'shared'
2002
+ ]));
1779
2003
  if (domainFirstPackages.includes('@domain-first/errors')) rootFolder.subitem([
1780
2004
  rootFolderName,
1781
2005
  'shared'
@@ -2075,7 +2299,8 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
2075
2299
  'aggregates',
2076
2300
  aggregateName
2077
2301
  ]);
2078
- aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types') ? `
2302
+ const withTypes = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
2303
+ aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, withTypes ? `
2079
2304
  import { domainType } from '@domain-first/types'
2080
2305
 
2081
2306
  export class ${aggregateNaming.ClassName} extends domainType() {
@@ -2089,11 +2314,11 @@ import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggr
2089
2314
  let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
2090
2315
 
2091
2316
  beforeEach(() => {
2092
- ${aggregateNaming.variableName} = new ${aggregateNaming.ClassName}()
2317
+ ${aggregateNaming.variableName} = ${withTypes ? `${aggregateNaming.ClassName}.of({})` : `new ${aggregateNaming.ClassName}()`}
2093
2318
  })
2094
2319
 
2095
2320
  describe('${aggregateNaming.withSpaces}', () => {
2096
- test('can be instantiated via constructor', () => {
2321
+ test('can be instantiated via ${withTypes ? 'of' : 'constructor'}', () => {
2097
2322
  expect(${aggregateNaming.variableName}).toBeDefined()
2098
2323
  })
2099
2324
  })
@@ -2124,9 +2349,25 @@ describe('${aggregateNaming.withSpaces}', () => {
2124
2349
  ].filter((x)=>!!x);
2125
2350
  for (const implementation of implementationTypes){
2126
2351
  const naming = new UnknownFormatNaming(implementation);
2127
- infrastructureRepositoriesFolder.subitem([
2352
+ const repositoryFolder = infrastructureRepositoriesFolder.subitem([
2128
2353
  naming.fileName
2129
- ]).createFile(`${naming.fileName}-${aggregateName}-repository.ts`, `
2354
+ ]);
2355
+ const repositoryFileName = `${naming.fileName}-${aggregateName}-repository.ts`;
2356
+ if (usesInMemoryDb(implementation) && !ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
2357
+ const section = addInMemoryDbSection(aggregateNaming, aggregatesFolder.path);
2358
+ repositoryFolder.createFile(repositoryFileName, `
2359
+ ${inMemoryDbTypeImport(repositoryFolder.subitem([
2360
+ repositoryFileName
2361
+ ]).path)}
2362
+ import { ${aggregateNaming.ClassName}Repository } from '../../../domain/aggregates/${aggregateName}'
2363
+
2364
+ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implements ${aggregateNaming.ClassName}Repository {
2365
+ ${inMemoryDbSectionMembers(section, false)}
2366
+ }
2367
+ `.trim());
2368
+ continue;
2369
+ }
2370
+ repositoryFolder.createFile(repositoryFileName, `
2130
2371
  import { ${aggregateNaming.ClassName}Repository } from '../../../domain/aggregates/${aggregateName}'
2131
2372
 
2132
2373
  export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implements ${aggregateNaming.ClassName}Repository {
@@ -2137,7 +2378,7 @@ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implement
2137
2378
  }
2138
2379
  if (scaffoldUnitTests) {
2139
2380
  const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
2140
- aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
2381
+ const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
2141
2382
  import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
2142
2383
  ${ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
2143
2384
  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'
@@ -2156,6 +2397,7 @@ describe('${aggregateNaming.withSpaces} repository', () => {
2156
2397
  })
2157
2398
  })
2158
2399
  `.trim());
2400
+ if (!ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
2159
2401
  }
2160
2402
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
2161
2403
  const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
@@ -2176,7 +2418,12 @@ export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
2176
2418
  production: wire${implementationNaming.ClassName}Implementation
2177
2419
  })
2178
2420
  `.trim());
2179
- await wireNewModuleDependencies(boundedContextFolder, wireFile);
2421
+ await wireNewModuleDependencies(boundedContextFolder, wireFile, (implementation, dependency)=>{
2422
+ if (!isInMemoryDb(dependency)) return false;
2423
+ keepInMemoryDbSection(new File(implementation.file), addInMemoryDbSection(aggregateNaming, aggregatesFolder.path));
2424
+ wireInMemoryDb(wireFile, implementation.className);
2425
+ return true;
2426
+ });
2180
2427
  }
2181
2428
  }
2182
2429
  };
@@ -2392,7 +2639,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
2392
2639
  ].filter((x)=>!!x);
2393
2640
  for (const implementation of implementationTypes){
2394
2641
  const formatNaming = new UnknownFormatNaming(implementation);
2395
- infrastructureFolder.subitem([
2642
+ const implementationFile = infrastructureFolder.subitem([
2396
2643
  formatNaming.fileName
2397
2644
  ]).createFile(`${formatNaming.fileName}-${naming.fileName}-command.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
2398
2645
  import { defineHandler } from '@domain-first/handlers'
@@ -2420,6 +2667,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${namin
2420
2667
  }
2421
2668
  }
2422
2669
  `.trim());
2670
+ if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
2423
2671
  }
2424
2672
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.subitem([
2425
2673
  'execution'
@@ -2441,7 +2689,7 @@ export abstract class ${naming.ClassName}Command {
2441
2689
  }`.trim());
2442
2690
  if (scaffoldUnitTests) {
2443
2691
  const implementationNaming = new UnknownFormatNaming(implementationType);
2444
- commandsFolder.subitem([
2692
+ const specFile = commandsFolder.subitem([
2445
2693
  'execution'
2446
2694
  ]).createFile(`${naming.fileName}-command.spec.ts`, `
2447
2695
  import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
@@ -2462,6 +2710,7 @@ describe('${naming.withSpaces} command', () => {
2462
2710
  })
2463
2711
  })
2464
2712
  `.trim());
2713
+ if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
2465
2714
  }
2466
2715
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
2467
2716
  const implementationNaming = new UnknownFormatNaming(implementationType);
@@ -2572,7 +2821,8 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
2572
2821
  kindFolderName
2573
2822
  ]);
2574
2823
  const fileName = `${naming.fileName}.${kind}`;
2575
- folder.createFile(`${fileName}.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types') ? `
2824
+ const withTypes = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
2825
+ folder.createFile(`${fileName}.ts`, withTypes ? `
2576
2826
  import { domainType } from '@domain-first/types'
2577
2827
 
2578
2828
  export class ${naming.ClassName} extends domainType() {
@@ -2589,11 +2839,11 @@ import { ${naming.ClassName} } from './${fileName}'
2589
2839
  let ${naming.variableName}: ${naming.ClassName}
2590
2840
 
2591
2841
  beforeEach(() => {
2592
- ${naming.variableName} = new ${naming.ClassName}()
2842
+ ${naming.variableName} = ${withTypes ? `${naming.ClassName}.of({})` : `new ${naming.ClassName}()`}
2593
2843
  })
2594
2844
 
2595
2845
  describe('${naming.withSpaces}', () => {
2596
- test('can be instantiated via constructor', () => {
2846
+ test('can be instantiated via ${withTypes ? 'of' : 'constructor'}', () => {
2597
2847
  expect(${naming.variableName}).toBeDefined()
2598
2848
  })
2599
2849
  })
@@ -2902,7 +3152,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
2902
3152
  ].filter((x)=>!!x);
2903
3153
  for (const implementation of implementationTypes){
2904
3154
  const formatNaming = new UnknownFormatNaming(implementation);
2905
- infrastructureFolder.subitem([
3155
+ const implementationFile = infrastructureFolder.subitem([
2906
3156
  formatNaming.fileName
2907
3157
  ]).createFile(`${formatNaming.fileName}-${naming.fileName}-query.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
2908
3158
  import { defineHandler } from '@domain-first/handlers'
@@ -2930,6 +3180,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.
2930
3180
  }
2931
3181
  }
2932
3182
  `.trim());
3183
+ if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
2933
3184
  }
2934
3185
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.subitem([
2935
3186
  'execution'
@@ -2951,7 +3202,7 @@ export abstract class ${naming.ClassName}Query {
2951
3202
  }`.trim());
2952
3203
  if (scaffoldUnitTests) {
2953
3204
  const implementationNaming = new UnknownFormatNaming(implementationType);
2954
- queriesFolder.subitem([
3205
+ const specFile = queriesFolder.subitem([
2955
3206
  'execution'
2956
3207
  ]).createFile(`${naming.fileName}-query.spec.ts`, `
2957
3208
  import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
@@ -2972,6 +3223,7 @@ describe('${naming.withSpaces} query', () => {
2972
3223
  })
2973
3224
  })
2974
3225
  `.trim());
3226
+ if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
2975
3227
  }
2976
3228
  if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
2977
3229
  const implementationNaming = new UnknownFormatNaming(implementationType);
@@ -1,2 +1,2 @@
1
- import type { Folder } from '../file-system';
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/dist/wiring.d.ts CHANGED
@@ -73,6 +73,10 @@ export declare const addImport: (source: string, importLine: string) => string;
73
73
  * Appends parameters to the class constructor, adding one if missing.
74
74
  */
75
75
  export declare const addConstructorParameters: (source: string, className: string, parameters: string[]) => string;
76
+ /**
77
+ * Appends a member at the end of the class body.
78
+ */
79
+ export declare const addClassMember: (source: string, className: string, member: string) => string;
76
80
  export declare const wiredDependencyNames: (source: string, className: string) => string[];
77
81
  /**
78
82
  * Appends wires to the dependency list of `wireClass(className, [...])`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domain-first/project-structure",
3
3
  "description": "Build and manage your Domain-First project structure with CLI",
4
- "version": "3.1.0",
4
+ "version": "3.2.1",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -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
 
@@ -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, infrastructure (it implements application modules, never depends on them); 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.
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, infrastructure (it implements application modules, never depends on them); 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,6 +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 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.
24
25
 
25
26
  ## Domain → New Entity / New Value Object (context and Shared Layer)
26
27
 
@@ -77,6 +78,7 @@ Execution:
77
78
  - `<C>/application/commands/execution/n-command.ts`: abstract `NCommand` ({handlers} schemas + abstract `handle: Handler<…>`), spec
78
79
  - `<C>/infrastructure/commands/I/I-n-command.ts` per implementation (`extends NCommand`, implements `handle`)
79
80
  - {wire} `<C>/wiring/commands/wire-n-command.ts` (env-branched)
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.
80
82
 
81
83
  Orchestrator: `<C>/application/commands/orchestration/n-command.ts` (concrete class), spec, {wire} `wire-n-command.ts`.
82
84
 
@@ -223,7 +225,7 @@ Without wire: import `<Class>` from `<noWire>`, use `new <Class>()` and the test
223
225
 
224
226
  | Component | Spec next to | `<Type>` / `<var>` | `<wirePath>` | `<label>` | `<Class>` from `<noWire>`, `<noWireTest>` |
225
227
  | -------------------- | ---------------------------- | ----------------------------- | ------------------------------------------------ | -------------------- | -------------------------------------------------------------------------------------------------------- |
226
- | Aggregate root | `n.aggregate-root.ts` | `N` / `v` | none: always `new N()` | `n words` | `N` `./n.aggregate-root`, `can be instantiated via constructor` |
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` |
227
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` |
228
230
  | Service | `n-L-service.ts` | `NLService` / `vLService` | `../../wiring/L-services/wire-n-L-service` | `n words` | `NLService` `./n-L-service`, `can be created` |
229
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` |
@@ -231,4 +233,4 @@ Without wire: import `<Class>` from `<noWire>`, use `new <Class>()` and the test
231
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` |
232
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` |
233
235
 
234
- `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 with nothing selected
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';