@domain-first/project-structure 6.0.0 → 7.0.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.
Files changed (46) hide show
  1. package/README.md +16 -19
  2. package/dist/201.js +46 -35
  3. package/dist/287.js +1685 -1612
  4. package/dist/config-file.d.ts +2 -2
  5. package/dist/dependency-rules.d.ts +1 -1
  6. package/dist/file-system.d.ts +5 -0
  7. package/dist/in-memory-db.d.ts +5 -0
  8. package/dist/index.cjs +100 -916
  9. package/dist/index.js +6 -46
  10. package/dist/init.cjs +868 -0
  11. package/dist/init.d.ts +2 -0
  12. package/dist/init.js +36 -0
  13. package/dist/integration.cjs +412 -33
  14. package/dist/integration.js +4 -4
  15. package/dist/integrations/in-memory-db.d.ts +6 -0
  16. package/dist/integrations/index.d.ts +2 -0
  17. package/dist/integrations/missing-domain-first-packages.d.ts +8 -0
  18. package/dist/integrations/rest-endpoint-generator.d.ts +18 -0
  19. package/dist/integrations/rest-endpoint-generator.spec.d.ts +1 -0
  20. package/dist/lint.cjs +8 -8
  21. package/dist/lint.js +7 -7
  22. package/dist/print-next-steps.d.ts +2 -2
  23. package/dist/react.cjs +915 -0
  24. package/dist/react.d.ts +2 -0
  25. package/dist/react.js +73 -0
  26. package/dist/use-cases/rest-endpoint-generator.d.ts +1 -1
  27. package/package.json +3 -1
  28. package/skills/df-ps-implement/SKILL.md +10 -55
  29. package/skills/df-ps-plan-feature/SKILL.md +6 -6
  30. package/skills/df-ps-project-scripts/SKILL.md +1 -1
  31. package/skills/df-ps-react/SKILL.md +82 -0
  32. package/skills/df-ps-react/references/generators.md +80 -0
  33. package/skills/df-ps-scaffold/SKILL.md +38 -20
  34. package/skills/df-ps-scaffold/references/choosing-components.md +7 -28
  35. package/skills/df-ps-scaffold/references/generators.md +6 -179
  36. package/skills/df-ps-scaffold/references/units/aggregate.md +47 -0
  37. package/skills/df-ps-scaffold/references/units/bounded-context.md +13 -0
  38. package/skills/df-ps-scaffold/references/units/command-query.md +32 -0
  39. package/skills/df-ps-scaffold/references/units/endpoint.md +28 -0
  40. package/skills/df-ps-scaffold/references/units/entity-value-object.md +27 -0
  41. package/skills/df-ps-scaffold/references/units/errors.md +26 -0
  42. package/skills/df-ps-scaffold/references/units/port.md +23 -0
  43. package/skills/df-ps-scaffold/references/units/services.md +28 -0
  44. package/skills/df-ps-scaffold/references/units/use-case.md +25 -0
  45. package/skills/df-ps-scaffold/references/units/wire-dependency.md +15 -0
  46. package/skills/df-ps-scaffold/scripts/drive.mjs +12 -4
package/dist/index.cjs CHANGED
@@ -130,7 +130,7 @@ const pendingDeletions = new Map();
130
130
  const filesToOverwrite = ()=>[
131
131
  ...pendingFiles
132
132
  ].filter(([filePath, { replacesFile }])=>replacesFile && external_node_fs_default().existsSync(filePath)).map(([filePath])=>filePath);
133
- const discardPendingChanges = ()=>{
133
+ const file_system_discardPendingChanges = ()=>{
134
134
  pendingFolders.clear();
135
135
  pendingFiles.clear();
136
136
  pendingMoves.clear();
@@ -164,7 +164,7 @@ const writePendingChanges = ()=>{
164
164
  });
165
165
  for (const [filePath, stopAt] of pendingDeletions)removeEmptyFolders(external_node_path_default().dirname(filePath), stopAt);
166
166
  for (const { sourcePath, stopAt } of pendingMoves.values())removeEmptyFolders(external_node_path_default().dirname(sourcePath), stopAt);
167
- discardPendingChanges();
167
+ file_system_discardPendingChanges();
168
168
  };
169
169
  class FileSystemItem {
170
170
  path;
@@ -274,7 +274,7 @@ class project_root_ProjectRoot {
274
274
  }
275
275
  const lintChecks = [
276
276
  'context-isolation',
277
- 'shared-layer',
277
+ 'shared-kernel',
278
278
  'layers',
279
279
  'dependencies',
280
280
  'react',
@@ -323,56 +323,6 @@ class config_file_ConfigFile {
323
323
  };
324
324
  }
325
325
  const configuredDependencyRules = ()=>resolveDependencyRules(config_file_ConfigFile.exists ? config_file_ConfigFile.Instance.data.rules?.dependencies : void 0);
326
- const external_node_util_namespaceObject = require("node:util");
327
- const installCommand = /^\s*npm (?:i|install)((?:\s+(?:--save-dev|-D))?)\s+(.+)$/;
328
- const mergeInstallCommands = (commands)=>{
329
- const runtime = new Set();
330
- const development = new Set();
331
- const rest = [];
332
- for (const command of commands){
333
- const match = installCommand.exec(command);
334
- if (!match) {
335
- rest.push(command);
336
- continue;
337
- }
338
- for (const name of match[2].trim().split(/\s+/))(match[1] ? development : runtime).add(name);
339
- }
340
- const devOnly = [
341
- ...development
342
- ].filter((name)=>!runtime.has(name));
343
- return [
344
- ...runtime.size ? [
345
- `npm install ${[
346
- ...runtime
347
- ].join(' ')}`
348
- ] : [],
349
- ...devOnly.length ? [
350
- `npm install --save-dev ${devOnly.join(' ')}`
351
- ] : [],
352
- ...rest
353
- ];
354
- };
355
- const print_next_steps_printNextSteps = (nextSteps)=>{
356
- const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
357
- const commands = mergeInstallCommands(nextSteps.filter(isCommand));
358
- const notes = nextSteps.filter((line)=>!isCommand(line));
359
- const sections = [];
360
- if (commands.length) sections.push([
361
- 'Run these commands to install the required dependencies:',
362
- ...commands.map((line)=>(0, external_node_util_namespaceObject.styleText)([
363
- 'bold',
364
- 'cyan'
365
- ], line))
366
- ].join('\n'));
367
- if (notes.length) sections.push([
368
- 'Additional information:',
369
- ...notes.map((line)=>line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + (0, external_node_util_namespaceObject.styleText)([
370
- 'bold',
371
- 'cyan'
372
- ], path)))
373
- ].join('\n'));
374
- if (sections.length) console.log(sections.join('\n\n'));
375
- };
376
326
  const save_pending_changes_savePendingChanges = async ()=>{
377
327
  const overwrittenFiles = filesToOverwrite();
378
328
  if (overwrittenFiles.length) {
@@ -384,7 +334,7 @@ const save_pending_changes_savePendingChanges = async ()=>{
384
334
  default: false
385
335
  });
386
336
  if (!overwrite) {
387
- discardPendingChanges();
337
+ file_system_discardPendingChanges();
388
338
  console.log('Cancelled: nothing was written.');
389
339
  return false;
390
340
  }
@@ -392,9 +342,7 @@ const save_pending_changes_savePendingChanges = async ()=>{
392
342
  writePendingChanges();
393
343
  return true;
394
344
  };
395
- require("node:module");
396
- const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
397
- class UnknownFormatNaming {
345
+ class unknown_format_naming_UnknownFormatNaming {
398
346
  rawSource;
399
347
  camelCase;
400
348
  PascalCase;
@@ -422,51 +370,6 @@ class UnknownFormatNaming {
422
370
  return this.fileName.replaceAll('-', ' ');
423
371
  }
424
372
  }
425
- const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
426
- class NestedName {
427
- folders;
428
- folderName;
429
- fileName;
430
- ClassName;
431
- classNameSegments;
432
- constructor(rawSource){
433
- const segments = splitSegments(rawSource);
434
- this.folders = segments.slice(0, -1);
435
- this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
436
- this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
437
- this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
438
- this.ClassName = this.classNameSegments.join('');
439
- }
440
- static validate = (rawSource)=>{
441
- const segments = splitSegments(rawSource);
442
- if (!segments.length) return 'Name is required';
443
- if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
444
- return true;
445
- };
446
- }
447
- const scaffold_react_page_reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
448
- ${[
449
- ...imports,
450
- "import { type FC } from 'react'"
451
- ].join('\n')}
452
-
453
- export type ${ClassName}PageProps = {}
454
-
455
- export const ${ClassName}Page: FC<${ClassName}PageProps> = (props) => {
456
- return ${body}
457
- }
458
- `.trim();
459
- const scaffoldReactPage = async (presentationReactFolder)=>{
460
- const name = await (0, prompts_namespaceObject.input)({
461
- message: 'Provide name (folders split by "/"):',
462
- validate: NestedName.validate
463
- });
464
- const { folders, ClassName, fileName } = new NestedName(name);
465
- presentationReactFolder.subitem([
466
- 'pages',
467
- ...folders
468
- ]).createFile(`${fileName}-page.tsx`, scaffold_react_page_reactPageContent(ClassName));
469
- };
470
373
  const wiring_layers = [
471
374
  'domain',
472
375
  'application',
@@ -548,7 +451,7 @@ const readWiredModule = (wireFile, contextPath)=>{
548
451
  const wiringRelativePath = external_node_path_default().relative(external_node_path_default().join(contextPath, 'wiring'), wireFile);
549
452
  if (isEndpointWire(wiringRelativePath)) return;
550
453
  const source = new file_system_File(wireFile).data;
551
- const wireName = `wire${new UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
454
+ const wireName = `wire${new unknown_format_naming_UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
552
455
  const exportMatch = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*`).exec(source);
553
456
  if (!exportMatch) return;
554
457
  const branched = source.slice(exportMatch.index + exportMatch[0].length).startsWith('envBranchedWire(');
@@ -613,7 +516,7 @@ const availableDependencies = (consumer, implementation, candidates, rules = con
613
516
  const wired = wiredDependencyNames(new file_system_File(consumer.wireFile).data, implementation.className);
614
517
  return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate, rules) && !wired.includes(candidate.wireName));
615
518
  };
616
- const relativeImport = (fromFile, toFile)=>{
519
+ const wiring_relativeImport = (fromFile, toFile)=>{
617
520
  const relativePath = external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile).replace(/\.ts$/, '').split(external_node_path_default().sep).join('/');
618
521
  return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
619
522
  };
@@ -767,153 +670,21 @@ const parameterName = (typeName)=>typeName.substring(0, 1).toLowerCase() + typeN
767
670
  const wireDependencies = (consumer, implementation, dependencies)=>{
768
671
  const wireFile = new file_system_File(consumer.wireFile);
769
672
  let wireSource = wireFile.data;
770
- for (const dependency of dependencies)wireSource = addImport(wireSource, `import { ${dependency.wireName} } from '${relativeImport(consumer.wireFile, dependency.wireFile)}'`);
673
+ for (const dependency of dependencies)wireSource = addImport(wireSource, `import { ${dependency.wireName} } from '${wiring_relativeImport(consumer.wireFile, dependency.wireFile)}'`);
771
674
  wireFile.update(addWireDependencies(wireSource, implementation.className, dependencies.map((x)=>x.wireName)));
772
675
  const classFile = new file_system_File(implementation.file);
773
676
  let classSource = classFile.data;
774
- for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${relativeImport(implementation.file, dependency.typeFile)}'`);
677
+ for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${wiring_relativeImport(implementation.file, dependency.typeFile)}'`);
775
678
  classFile.update(addConstructorParameters(classSource, implementation.className, dependencies.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
776
679
  };
777
680
  const inMemoryImplementationType = 'in-memory';
778
681
  const in_memory_db_className = 'InMemoryDbInfrastructureService';
779
682
  const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
780
683
  const in_memory_db_parameterName = 'inMemoryDbInfrastructureService';
781
- const inMemoryDbService = `type Entry = {
782
- id: unknown;
783
- item: any;
784
- };
785
-
786
- declare global {
787
- var ___SHARED_IN_MEMORY_DB___: Record<string, Array<Entry>> | undefined;
788
- }
789
-
790
- type Section<T, TId> = {
791
- all: (predicate?: (x: T) => boolean) => T[];
792
- first: (predicate: (x: T) => boolean) => T | null;
793
- withId: (id: TId) => T | null;
794
- lastAddedItem: () => T | null;
795
- save: (payload: T extends { id: TId } ? T : [TId, T]) => void;
796
- deleteById: (id: TId) => void;
797
- delete: (predicate: (x: T) => boolean) => void;
798
- };
799
-
800
- type IdsAreEqual<TId> = (a: TId, b: TId) => boolean;
801
-
802
- const comparisonMethodNames = ['equals', 'same', 'isSame', 'isEqual'] as const;
803
-
804
- const defaultIdsAreEqual = (a: unknown, b: unknown): boolean => {
805
- if (typeof a !== 'object' || a === null) {
806
- return Object.is(a, b);
807
- }
808
-
809
- for (const methodName of comparisonMethodNames) {
810
- const method: unknown = (a as Record<string, unknown>)[methodName];
811
- if (typeof method === 'function') {
812
- return Boolean(method.call(a, b));
813
- }
814
- }
815
-
816
- return Object.is(a, b);
817
- };
818
-
819
- const hasId = (x: unknown): x is { id: unknown } =>
820
- typeof x === 'object' && x !== null && 'id' in x;
821
-
822
- export class InMemoryDbInfrastructureService {
823
- protected section<T extends { id: unknown }>(
824
- key: string,
825
- idsAreEqual?: IdsAreEqual<T['id']>
826
- ): Section<T, T['id']>;
827
- protected section<T, TId>(
828
- key: string,
829
- idsAreEqual?: IdsAreEqual<TId>
830
- ): Section<T, TId>;
831
- protected section<T, TId>(
832
- key: string,
833
- idsAreEqual: IdsAreEqual<TId> = defaultIdsAreEqual
834
- ): Section<T, TId> {
835
- if (!globalThis.___SHARED_IN_MEMORY_DB___) {
836
- globalThis.___SHARED_IN_MEMORY_DB___ = {};
837
- }
838
-
839
- if (!globalThis.___SHARED_IN_MEMORY_DB___[key]) {
840
- globalThis.___SHARED_IN_MEMORY_DB___[key] = [];
841
- }
842
-
843
- const items = (): T[] =>
844
- globalThis.___SHARED_IN_MEMORY_DB___![key].map(
845
- (entry) => entry.item
846
- );
847
-
848
- return {
849
- all: (predicate: (x: T) => boolean = () => true): T[] =>
850
- items().filter(predicate),
851
- first: (predicate: (x: T) => boolean): T | null =>
852
- items().find(predicate) ?? null,
853
- withId: (id: TId): T | null =>
854
- items().find(
855
- (x: T) => hasId(x) && idsAreEqual(x.id as TId, id)
856
- ) ?? null,
857
- lastAddedItem: (): T | null =>
858
- globalThis.___SHARED_IN_MEMORY_DB___![key].at(-1)?.item ?? null,
859
- save: (payload: T extends { id: TId } ? T : [TId, T]) => {
860
- const id = Array.isArray(payload) ? payload[0] : payload.id;
861
- const item = Array.isArray(payload) ? payload[1] : payload;
862
- const entries = globalThis.___SHARED_IN_MEMORY_DB___![key];
863
- const existing = entries.find((entry) =>
864
- idsAreEqual(entry.id as TId, id)
865
- );
866
- if (existing) {
867
- existing.item = item;
868
- return;
869
- }
870
- entries.push({ id, item });
871
- },
872
- deleteById: (id: TId) => {
873
- globalThis.___SHARED_IN_MEMORY_DB___![key] =
874
- globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
875
- (entry) => !idsAreEqual(entry.id as TId, id)
876
- );
877
- },
878
- delete: (predicate: (x: T) => boolean) => {
879
- globalThis.___SHARED_IN_MEMORY_DB___![key] =
880
- globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
881
- (entry) => !predicate(entry.item)
882
- );
883
- }
884
- };
885
- }
886
- }
887
- `;
888
- const inMemoryDbWiring = `import { wireClass } from '@domain-first/wire';
889
- import { InMemoryDbInfrastructureService } from '../../infrastructure/services/in-memory-db-infrastructure-service';
890
-
891
- export const wireInMemoryDbInfrastructureService = wireClass(
892
- InMemoryDbInfrastructureService,
893
- []
894
- );
895
- `;
896
- const inMemoryDbSpec = (testingLibrary, withWiring)=>`
897
- import { describe, test, expect, beforeEach } from '${testingLibrary}'
898
- ${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
899
- import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
900
-
901
- let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
902
-
903
- beforeEach(() => {
904
- inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
905
- })
906
-
907
- describe('in memory db', () => {
908
- test('can be ${withWiring ? 'wired' : 'created'}', () => {
909
- expect(inMemoryDbInfrastructureService).toBeDefined()
910
- })
911
- })
912
- `.trim();
913
684
  const in_memory_db_withWiring = ()=>config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
914
685
  const in_memory_db_sharedFolder = ()=>new file_system_Folder(new project_root_ProjectRoot().path).subitem([
915
686
  config_file_ConfigFile.Instance.data.rootFolder,
916
- 'shared'
687
+ 'shared-kernel'
917
688
  ]);
918
689
  const serviceFile = ()=>new file_system_File(in_memory_db_sharedFolder().path).subitem([
919
690
  'infrastructure',
@@ -925,20 +696,8 @@ const in_memory_db_wireFile = ()=>new file_system_File(in_memory_db_sharedFolder
925
696
  'infrastructure-services',
926
697
  'wire-in-memory-db-infrastructure-service.ts'
927
698
  ]);
928
- const scaffoldInMemoryDb = (shared)=>{
929
- const { testingLibrary } = config_file_ConfigFile.Instance.data;
930
- const servicesFolder = shared.subitem([
931
- 'infrastructure',
932
- 'services'
933
- ]);
934
- servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
935
- if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
936
- if (in_memory_db_withWiring()) shared.subitem([
937
- 'wiring',
938
- 'infrastructure-services'
939
- ]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
940
- };
941
- const usesInMemoryDb = (implementationType)=>Boolean(config_file_ConfigFile.Instance.data.withInMemoryDb) && new UnknownFormatNaming(implementationType).fileName === inMemoryImplementationType && serviceFile().exists && (!in_memory_db_withWiring() || in_memory_db_wireFile().exists);
699
+ const in_memory_db_inMemoryDbScaffolded = ()=>serviceFile().exists && (!in_memory_db_withWiring() || in_memory_db_wireFile().exists);
700
+ const usesInMemoryDb = (implementationType)=>Boolean(config_file_ConfigFile.Instance.data.withInMemoryDb) && new unknown_format_naming_UnknownFormatNaming(implementationType).fileName === inMemoryImplementationType && in_memory_db_inMemoryDbScaffolded();
942
701
  const plural = (word)=>{
943
702
  if (/[^aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`;
944
703
  if (/(s|x|z|ch|sh)$/i.test(word)) return `${word}es`;
@@ -946,14 +705,14 @@ const plural = (word)=>{
946
705
  };
947
706
  const addInMemoryDbSection = (typeNaming, typeImportTarget)=>{
948
707
  const file = serviceFile();
949
- const sectionNaming = new UnknownFormatNaming(plural(typeNaming.fileName));
708
+ const sectionNaming = new unknown_format_naming_UnknownFormatNaming(plural(typeNaming.fileName));
950
709
  const field = sectionNaming.variableName;
951
710
  if (new RegExp(`\\b${field}\\s*=\\s*this\\.section\\b`).test(file.data)) return field;
952
- const withImport = addImport(file.data, `import type { ${typeNaming.ClassName} } from '${relativeImport(file.path, typeImportTarget)}';`);
711
+ const withImport = addImport(file.data, `import type { ${typeNaming.ClassName} } from '${wiring_relativeImport(file.path, typeImportTarget)}';`);
953
712
  file.update(addClassMember(withImport, in_memory_db_className, `${field} = this.section<${typeNaming.ClassName}>('${sectionNaming.fileName.toUpperCase()}');`));
954
713
  return field;
955
714
  };
956
- const inMemoryDbTypeImport = (fromFile)=>`import type { ${in_memory_db_className} } from '${relativeImport(fromFile, serviceFile().path)}'`;
715
+ const inMemoryDbTypeImport = (fromFile)=>`import type { ${in_memory_db_className} } from '${wiring_relativeImport(fromFile, serviceFile().path)}'`;
957
716
  const inMemoryDbSectionMembers = (field, derived)=>`
958
717
  private readonly data: ${in_memory_db_className}['${field}']
959
718
 
@@ -971,13 +730,14 @@ const injectInMemoryDb = (classFile, implementationName)=>{
971
730
  ]));
972
731
  };
973
732
  const wireInMemoryDb = (consumerWireFile, implementationName)=>{
974
- consumerWireFile.update(addWireDependencies(addImport(consumerWireFile.data, `import { ${in_memory_db_wireName} } from '${relativeImport(consumerWireFile.path, in_memory_db_wireFile().path)}'`), implementationName, [
733
+ consumerWireFile.update(addWireDependencies(addImport(consumerWireFile.data, `import { ${in_memory_db_wireName} } from '${wiring_relativeImport(consumerWireFile.path, in_memory_db_wireFile().path)}'`), implementationName, [
975
734
  in_memory_db_wireName
976
735
  ]));
977
736
  };
978
737
  const passInMemoryDb = (specFile, implementationName)=>{
979
- 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}())`));
738
+ specFile.update(addImport(specFile.data, `import { ${in_memory_db_className} } from '${wiring_relativeImport(specFile.path, serviceFile().path)}'`).replace(`new ${implementationName}()`, `new ${implementationName}(new ${in_memory_db_className}())`));
980
739
  };
740
+ require("node:module");
981
741
  const kindTitles = {
982
742
  repositories: 'Repositories',
983
743
  'domain-services': 'Domain services',
@@ -1022,7 +782,7 @@ const groupedPageSize = 20;
1022
782
  const contextAndSharedModules = (boundedContextFolder)=>{
1023
783
  const sharedFolder = new file_system_Folder(new project_root_ProjectRoot().path).subitem([
1024
784
  config_file_ConfigFile.Instance.data.rootFolder,
1025
- 'shared'
785
+ 'shared-kernel'
1026
786
  ]);
1027
787
  const isShared = sharedFolder.path === boundedContextFolder.path;
1028
788
  return [
@@ -1032,7 +792,7 @@ const contextAndSharedModules = (boundedContextFolder)=>{
1032
792
  })),
1033
793
  ...isShared ? [] : findWiredModules(sharedFolder.path).map((x)=>({
1034
794
  module: x,
1035
- label: `${x.typeName} (shared)`
795
+ label: `${x.typeName} (shared-kernel)`
1036
796
  }))
1037
797
  ];
1038
798
  };
@@ -1097,8 +857,8 @@ const promptEndpointHandler = async (boundedContextFolder)=>{
1097
857
  loop: false
1098
858
  })).module : void 0;
1099
859
  };
1100
- const createPresentationService = (boundedContextFolder, name, classFile)=>{
1101
- const naming = new UnknownFormatNaming(name);
860
+ const scaffold_new_presentation_service_createPresentationService = (boundedContextFolder, name, classFile)=>{
861
+ const naming = new unknown_format_naming_UnknownFormatNaming(name);
1102
862
  const className = `${naming.ClassName}PresentationService`;
1103
863
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
1104
864
  const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
@@ -1146,34 +906,11 @@ const scaffoldNewPresentationService = async (boundedContextFolder)=>{
1146
906
  const name = await (0, prompts_namespaceObject.input)({
1147
907
  message: 'Name: '
1148
908
  });
1149
- const wireFile = createPresentationService(boundedContextFolder, name);
909
+ const wireFile = scaffold_new_presentation_service_createPresentationService(boundedContextFolder, name);
1150
910
  if (wireFile) await wireNewModuleDependencies(boundedContextFolder, wireFile);
1151
911
  };
1152
912
  const rest_endpoint_generator_name = 'rest-endpoint-generator';
1153
- const scaffoldRestEndpointGenerator = (sharedFolder, { withNextAdapter = false } = {})=>createPresentationService(sharedFolder, rest_endpoint_generator_name, (className)=>{
1154
- const adapter = withNextAdapter ? 'nextAdapter' : 'adapter';
1155
- return `
1156
- import {
1157
- ${withNextAdapter ? '' : ' type Adapter,\n'} type EndpointGenerator,
1158
- createEndpoint,
1159
- invalidRequest
1160
- } from '@domain-first/handlers-rest'
1161
- ${withNextAdapter ? "import { nextAdapter } from '@domain-first/handlers-next'" : `
1162
- /**
1163
- * The adapter of your HTTP framework.
1164
- */
1165
- const adapter = undefined as unknown as Adapter<any[], any>`}
1166
-
1167
- export class ${className} {
1168
- get withoutGuards(): EndpointGenerator {
1169
- return createEndpoint({
1170
- errors: [invalidRequest()]
1171
- })(${adapter}) as EndpointGenerator
1172
- }
1173
- }
1174
- `.trim();
1175
- });
1176
- const findRestEndpointGenerator = (sharedFolder)=>{
913
+ const rest_endpoint_generator_findRestEndpointGenerator = (sharedFolder)=>{
1177
914
  const typeFile = external_node_path_default().join(sharedFolder.path, 'presentation', 'services', `${rest_endpoint_generator_name}-presentation-service.ts`);
1178
915
  if (!new file_system_File(typeFile).exists) return;
1179
916
  return {
@@ -1183,109 +920,8 @@ const findRestEndpointGenerator = (sharedFolder)=>{
1183
920
  wireFile: external_node_path_default().join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
1184
921
  };
1185
922
  };
1186
- const hasDependency = (root, name)=>{
1187
- const manifestFile = new file_system_File(external_node_path_default().join(root, 'package.json'));
1188
- if (!manifestFile.exists) return false;
1189
- const manifest = JSON.parse(manifestFile.data);
1190
- return [
1191
- manifest.dependencies,
1192
- manifest.devDependencies,
1193
- manifest.optionalDependencies
1194
- ].some((dependencies)=>dependencies && Object.hasOwn(dependencies, name));
1195
- };
1196
- const initializeUseCase = async ()=>{
1197
- const nextSteps = [];
1198
- const rootFolderName = await (0, prompts_namespaceObject.input)({
1199
- message: 'Root folder (use "/" for inner folders):',
1200
- default: 'src'
1201
- });
1202
- const domainFirstPackages = await (0, prompts_namespaceObject.checkbox)({
1203
- message: '@domain-first packages',
1204
- choices: [
1205
- '@domain-first/types',
1206
- '@domain-first/errors',
1207
- '@domain-first/handlers',
1208
- '@domain-first/wire',
1209
- '@domain-first/handlers-rest'
1210
- ]
1211
- });
1212
- const withNextAdapter = domainFirstPackages.includes('@domain-first/handlers-rest') && hasDependency(new project_root_ProjectRoot().path, 'next') && await (0, prompts_namespaceObject.confirm)({
1213
- message: 'Use Next adapter for REST endpoints'
1214
- });
1215
- const defaultPersistenceLayerImplementation = await (0, prompts_namespaceObject.input)({
1216
- message: 'Default persistence layer implementation:'
1217
- });
1218
- const withInMemoryDb = await (0, prompts_namespaceObject.confirm)({
1219
- message: 'Scaffold in-memory DB for test implementations'
1220
- });
1221
- const useReact = await (0, prompts_namespaceObject.confirm)({
1222
- message: 'Use React'
1223
- });
1224
- let storybookFramework;
1225
- const withStorybook = useReact ? await (0, prompts_namespaceObject.confirm)({
1226
- message: 'Use Storybook'
1227
- }) : false;
1228
- if (withStorybook) storybookFramework = await (0, prompts_namespaceObject.input)({
1229
- message: 'Storybook framework package:',
1230
- default: '@storybook/react-vite'
1231
- });
1232
- let testingLibrary;
1233
- const withTests = await (0, prompts_namespaceObject.confirm)({
1234
- message: 'Scaffold unit tests'
1235
- });
1236
- if (withTests) testingLibrary = await (0, prompts_namespaceObject.input)({
1237
- message: 'Unit testing library:',
1238
- default: 'vitest'
1239
- });
1240
- config_file_ConfigFile.write({
1241
- rootFolder: rootFolderName,
1242
- domainFirstPackages,
1243
- defaultPersistenceLayerImplementation,
1244
- withInMemoryDb,
1245
- useReact,
1246
- storybookFramework,
1247
- testingLibrary
1248
- });
1249
- const { path } = new project_root_ProjectRoot();
1250
- const rootFolder = new file_system_Folder(path);
1251
- if (domainFirstPackages.includes('@domain-first/wire')) rootFolder.subitem([
1252
- rootFolderName,
1253
- 'shared',
1254
- 'wiring'
1255
- ]).createFile('env-branched-wire.ts', `
1256
- import { branchedWire } from '@domain-first/wire'
1257
-
1258
- export const envBranchedWire = branchedWire(() => {
1259
- return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
1260
- });
1261
- `.trim());
1262
- if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
1263
- rootFolderName,
1264
- 'shared'
1265
- ]));
1266
- if (domainFirstPackages.includes('@domain-first/errors')) rootFolder.subitem([
1267
- rootFolderName,
1268
- 'shared'
1269
- ]).subitem([
1270
- 'domain',
1271
- 'errors'
1272
- ]).createFile('index.ts', `
1273
- import { errorNamespace } from '@domain-first/errors'
1274
-
1275
- export const SharedErrors = errorNamespace('shared')
1276
- `.trim());
1277
- if (domainFirstPackages.includes('@domain-first/handlers-rest')) {
1278
- scaffoldRestEndpointGenerator(rootFolder.subitem([
1279
- rootFolderName,
1280
- 'shared'
1281
- ]), {
1282
- withNextAdapter
1283
- });
1284
- if (withNextAdapter && !hasDependency(path, '@domain-first/handlers-next')) nextSteps.push('npm i @domain-first/handlers-next');
1285
- }
1286
- return nextSteps;
1287
- };
1288
- const ignoredFolders = new Set([
923
+ require("node:util");
924
+ new Set([
1289
925
  'node_modules',
1290
926
  '.git',
1291
927
  '.next',
@@ -1295,241 +931,11 @@ const ignoredFolders = new Set([
1295
931
  'coverage',
1296
932
  'storybook-static'
1297
933
  ]);
1298
- const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx)$/;
1299
- const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1300
- const react_module_move_walk = (folder)=>{
1301
- if (!external_node_fs_default().existsSync(folder)) return [];
1302
- return external_node_fs_default().readdirSync(folder, {
1303
- withFileTypes: true
1304
- }).flatMap((entry)=>{
1305
- const entryPath = external_node_path_default().join(folder, entry.name);
1306
- if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : react_module_move_walk(entryPath);
1307
- return entry.isFile() ? [
1308
- entryPath
1309
- ] : [];
1310
- });
1311
- };
1312
- const toPosix = (value)=>value.split(external_node_path_default().sep).join('/');
1313
- const nestedName = (folders, fileBase)=>{
1314
- const prefix = `${folders.join('-')}-`;
1315
- const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
1316
- return [
1317
- ...folders,
1318
- last
1319
- ].join('/');
1320
- };
1321
- const declaredClassName = (filePath, suffix, name)=>{
1322
- const content = external_node_fs_default().readFileSync(filePath, 'utf8');
1323
- const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
1324
- return declared ?? new NestedName(name).ClassName;
1325
- };
1326
- const findReactModules = (reactFolder, kind)=>{
1327
- const modules = 'page' === kind ? react_module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
1328
- const folders = external_node_path_default().relative(external_node_path_default().join(reactFolder, 'pages'), external_node_path_default().dirname(file)).split(external_node_path_default().sep).filter((segment)=>!!segment);
1329
- const fileBase = external_node_path_default().basename(file, '-page.tsx');
1330
- const name = nestedName(folders, fileBase);
1331
- return {
1332
- kind,
1333
- name,
1334
- path: file,
1335
- fileBase,
1336
- ClassName: declaredClassName(file, 'Page', name)
1337
- };
1338
- }) : react_module_move_walk(external_node_path_default().join(reactFolder, 'widgets')).filter((file)=>file.endsWith('-widget.tsx')).map((file)=>{
1339
- const folder = external_node_path_default().dirname(file);
1340
- const name = toPosix(external_node_path_default().relative(external_node_path_default().join(reactFolder, 'widgets'), folder));
1341
- return {
1342
- kind,
1343
- name,
1344
- path: folder,
1345
- fileBase: external_node_path_default().basename(file, '-widget.tsx'),
1346
- ClassName: declaredClassName(file, 'Widget', name)
1347
- };
1348
- });
1349
- return modules.sort((a, b)=>a.name.localeCompare(b.name));
1350
- };
1351
- const react_module_move_targetPath = (reactFolder, module, rawName)=>{
1352
- const { folders, folderName, fileName } = new NestedName(rawName);
1353
- return 'page' === module.kind ? external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`) : external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName);
1354
- };
1355
- const validateMove = (reactFolder, module, rawName)=>{
1356
- const nameError = NestedName.validate(rawName);
1357
- if (true !== nameError) return nameError;
1358
- const target = react_module_move_targetPath(reactFolder, module, rawName);
1359
- if (target !== module.path && external_node_fs_default().existsSync(target)) return `${external_node_path_default().relative(reactFolder, target)} already exists`;
1360
- if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
1361
- return true;
1362
- };
1363
- const readAliases = (projectRoot)=>{
1364
- const tsconfig = external_node_path_default().join(projectRoot, 'tsconfig.json');
1365
- if (!external_node_fs_default().existsSync(tsconfig)) return [];
1366
- try {
1367
- const { compilerOptions = {} } = JSON.parse(stripJsonComments(external_node_fs_default().readFileSync(tsconfig, 'utf8')));
1368
- const base = external_node_path_default().resolve(projectRoot, compilerOptions.baseUrl ?? '.');
1369
- return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
1370
- prefix: pattern.slice(0, -1),
1371
- target: external_node_path_default().resolve(base, target.slice(0, -1))
1372
- }));
1373
- } catch {
1374
- return [];
1375
- }
1376
- };
1377
- const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
1378
- const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
1379
- const importPaths = (file)=>{
1380
- const withoutExtension = file.replace(codeExtension, '');
1381
- return 'index' === external_node_path_default().basename(withoutExtension) ? [
1382
- withoutExtension,
1383
- external_node_path_default().dirname(withoutExtension)
1384
- ] : [
1385
- withoutExtension
1386
- ];
1387
- };
1388
- const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
1389
- const newName = new NestedName(rawName);
1390
- const target = react_module_move_targetPath(reactFolder, module, rawName);
1391
- const newClassName = newName.ClassName;
1392
- const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.])`), (_, use = '')=>`${use}${newName.fileName}`);
1393
- const oldFolder = 'page' === module.kind ? external_node_path_default().dirname(module.path) : module.path;
1394
- const newFolder = 'page' === module.kind ? external_node_path_default().dirname(target) : target;
1395
- const ownsPath = (candidate)=>'page' === module.kind ? external_node_path_default().dirname(candidate) === oldFolder && new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`).test(external_node_path_default().basename(candidate)) : candidate === oldFolder || candidate.startsWith(`${oldFolder}${external_node_path_default().sep}`);
1396
- const movedPath = (candidate)=>{
1397
- if (!ownsPath(candidate)) return;
1398
- const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
1399
- const last = segments.length - 1;
1400
- segments[last] = renameFile(segments[last]);
1401
- return external_node_path_default().join(newFolder, ...segments);
1402
- };
1403
- const moduleFiles = 'page' === module.kind ? external_node_fs_default().readdirSync(oldFolder).map((name)=>external_node_path_default().join(oldFolder, name)).filter((file)=>external_node_fs_default().statSync(file).isFile() && ownsPath(file)) : react_module_move_walk(oldFolder);
1404
- const moves = new Map(moduleFiles.map((file)=>[
1405
- file,
1406
- movedPath(file) ?? file
1407
- ]));
1408
- const aliases = readAliases(projectRoot);
1409
- const resolve = (specifier, fromFile)=>{
1410
- if (specifier.startsWith('.')) return {
1411
- resolved: external_node_path_default().resolve(external_node_path_default().dirname(fromFile), specifier),
1412
- alias: void 0
1413
- };
1414
- const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
1415
- return alias ? {
1416
- resolved: external_node_path_default().resolve(alias.target, specifier.slice(alias.prefix.length)),
1417
- alias
1418
- } : void 0;
1419
- };
1420
- const specifierFor = (fromFile, toPath, alias)=>{
1421
- const aliased = alias && toPosix(external_node_path_default().relative(alias.target, toPath));
1422
- if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
1423
- const relative = toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
1424
- return relative.startsWith('.') ? relative : `./${relative}`;
1425
- };
1426
- const suffixes = 'page' === module.kind ? 'Page' : 'Widget|UIModel';
1427
- const classPattern = new RegExp(`(?<![\\w$])(use)?${escapeRegExp(module.ClassName)}(?=${suffixes})`, 'g');
1428
- const oldTitle = `Widgets/${module.name.split('/').map((segment)=>new NestedName(segment).ClassName).join('/')}`;
1429
- const titlePattern = new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
1430
- const newTitle = [
1431
- 'Widgets',
1432
- ...newName.classNameSegments
1433
- ].join('/');
1434
- const codeFiles = new Map(react_module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
1435
- file,
1436
- external_node_fs_default().readFileSync(file, 'utf8')
1437
- ]));
1438
- const barrels = new Set();
1439
- const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
1440
- for(let found = true; found;){
1441
- found = false;
1442
- for (const [file, content] of codeFiles){
1443
- if (moves.has(file) || isBarrel(file)) continue;
1444
- const reExportsModule = [
1445
- ...content.matchAll(reExportPattern)
1446
- ].some(([, , specifier])=>{
1447
- const resolution = resolve(specifier, file);
1448
- return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
1449
- });
1450
- if (reExportsModule) {
1451
- for (const importPath of importPaths(file))barrels.add(importPath);
1452
- found = true;
1453
- }
1454
- }
1455
- }
1456
- const rewrite = (content, oldFile, newFile)=>{
1457
- let referencesModule = false;
1458
- const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
1459
- const resolution = resolve(specifier, oldFile);
1460
- if (!resolution) return match;
1461
- const moved = movedPath(resolution.resolved);
1462
- if (moved || isBarrel(resolution.resolved)) referencesModule = true;
1463
- if (!moved && oldFile === newFile) return match;
1464
- const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
1465
- return `${keyword}${quote}${next}${quote}`;
1466
- });
1467
- if (!referencesModule && !moves.has(oldFile)) return content;
1468
- const renamed = rewritten.replace(classPattern, (_, use = '')=>`${use}${newClassName}`);
1469
- return moves.has(oldFile) && 'widget' === module.kind ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
1470
- };
1471
- for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, reactFolder);
1472
- const updated = [];
1473
- for (const [file, content] of codeFiles){
1474
- const newFile = moves.get(file);
1475
- const next = rewrite(content, file, newFile ?? file);
1476
- if (newFile && newFile !== file) {
1477
- new file_system_File(newFile).data = next;
1478
- new file_system_File(file).delete(reactFolder);
1479
- } else if (next !== content) {
1480
- new file_system_File(file).update(next);
1481
- if (!newFile) updated.push(file);
1482
- }
1483
- }
1484
- return {
1485
- moves: [
1486
- ...moves
1487
- ].filter(([from, to])=>from !== to),
1488
- updated
1489
- };
1490
- };
1491
- const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
1492
- const reactFolder = presentationReactFolder.path;
1493
- const modules = findReactModules(reactFolder, kind);
1494
- if (!modules.length) return void console.log(`No ${kind}s generated by df-scaffold were found.`);
1495
- const module = await (0, prompts_namespaceObject.select)({
1496
- message: 'page' === kind ? 'Page:' : 'Widget:',
1497
- choices: modules.map((value)=>({
1498
- name: value.name,
1499
- value,
1500
- description: external_node_path_default().relative(reactFolder, value.path)
1501
- }))
1502
- });
1503
- const name = await (0, prompts_namespaceObject.input)({
1504
- message: 'New name (folders split by "/"):',
1505
- default: module.name,
1506
- validate: (value)=>validateMove(reactFolder, module, value)
1507
- });
1508
- const root = new project_root_ProjectRoot().path;
1509
- const { moves, updated } = moveReactModule(root, reactFolder, module, name);
1510
- if (!moves.length && !updated.length) return void console.log('Nothing to change.');
1511
- const relative = (file)=>external_node_path_default().relative(root, file);
1512
- console.log([
1513
- 'Files to move:',
1514
- ...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
1515
- ...updated.length ? [
1516
- 'Files with updated imports:',
1517
- ...updated.map((file)=>` ${relative(file)}`)
1518
- ] : []
1519
- ].join('\n'));
1520
- if (!await (0, prompts_namespaceObject.confirm)({
1521
- message: 'Apply?',
1522
- default: true
1523
- })) {
1524
- discardPendingChanges();
1525
- console.log('Cancelled: nothing was written.');
1526
- }
1527
- };
1528
934
  const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
1529
935
  const aggregateName = await (0, prompts_namespaceObject.input)({
1530
936
  message: 'Aggregate name:'
1531
937
  });
1532
- const aggregateNaming = new UnknownFormatNaming(aggregateName);
938
+ const aggregateNaming = new unknown_format_naming_UnknownFormatNaming(aggregateName);
1533
939
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
1534
940
  const withRepository = await (0, prompts_namespaceObject.confirm)({
1535
941
  message: 'With Repository'
@@ -1588,7 +994,7 @@ describe('${aggregateNaming.withSpaces}', () => {
1588
994
  testImplementationType
1589
995
  ].filter((x)=>!!x);
1590
996
  for (const implementation of implementationTypes){
1591
- const naming = new UnknownFormatNaming(implementation);
997
+ const naming = new unknown_format_naming_UnknownFormatNaming(implementation);
1592
998
  const repositoryFolder = infrastructureRepositoriesFolder.subitem([
1593
999
  naming.fileName
1594
1000
  ]);
@@ -1617,7 +1023,7 @@ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implement
1617
1023
  `.trim());
1618
1024
  }
1619
1025
  if (scaffoldUnitTests) {
1620
- const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
1026
+ const implementationNaming = new unknown_format_naming_UnknownFormatNaming(infrastructureImplementationType);
1621
1027
  const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
1622
1028
  import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
1623
1029
  ${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
@@ -1640,17 +1046,17 @@ describe('${aggregateNaming.withSpaces} repository', () => {
1640
1046
  if (!config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
1641
1047
  }
1642
1048
  if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
1643
- const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
1644
- const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
1049
+ const implementationNaming = new unknown_format_naming_UnknownFormatNaming(infrastructureImplementationType);
1050
+ const testImplementationNaming = new unknown_format_naming_UnknownFormatNaming(testImplementationType);
1645
1051
  const wireFile = boundedContextFolder.subitem([
1646
1052
  'wiring',
1647
1053
  'repositories'
1648
1054
  ]).createFile(`wire-${aggregateNaming.fileName}-repository.ts`, `
1649
1055
  import { wireClass } from '@domain-first/wire'
1650
- import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
1651
- ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${aggregateNaming.ClassName}Repository } from '../../infrastructure/repositories/${fileName}/${fileName}-${aggregateNaming.fileName}-repository'`).join('\n')}
1056
+ import { envBranchedWire } from '../../../../shared-kernel/wiring/env-branched-wire'
1057
+ ${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${aggregateNaming.ClassName}Repository } from '../../infrastructure/repositories/${fileName}/${fileName}-${aggregateNaming.fileName}-repository'`).join('\n')}
1652
1058
 
1653
- ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${aggregateNaming.ClassName}Repository, [])`).join('\n\n')}
1059
+ ${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${aggregateNaming.ClassName}Repository, [])`).join('\n\n')}
1654
1060
 
1655
1061
  export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
1656
1062
  test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
@@ -1671,7 +1077,7 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
1671
1077
  const name = await (0, prompts_namespaceObject.input)({
1672
1078
  message: 'Name: '
1673
1079
  });
1674
- const naming = new UnknownFormatNaming(name);
1080
+ const naming = new unknown_format_naming_UnknownFormatNaming(name);
1675
1081
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
1676
1082
  const wiringFolder = boundedContextFolder.subitem([
1677
1083
  'wiring',
@@ -1707,7 +1113,7 @@ export abstract class ${naming.ClassName} {
1707
1113
  testImplementationType
1708
1114
  ].filter((x)=>!!x);
1709
1115
  for (const implementation of implementationTypes){
1710
- const currentNaming = new UnknownFormatNaming(`${implementation}-${naming.fileName}`);
1116
+ const currentNaming = new unknown_format_naming_UnknownFormatNaming(`${implementation}-${naming.fileName}`);
1711
1117
  infrastructureFolder.subitem([
1712
1118
  implementation
1713
1119
  ]).createFile(`${currentNaming.fileName}.ts`, `
@@ -1719,7 +1125,7 @@ export class ${currentNaming.ClassName} extends ${naming.ClassName} {
1719
1125
  `.trim());
1720
1126
  }
1721
1127
  if (scaffoldUnitTests) {
1722
- const implementationNaming = new UnknownFormatNaming(implementationType);
1128
+ const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
1723
1129
  applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
1724
1130
  import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
1725
1131
  ${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
@@ -1743,21 +1149,21 @@ describe('${naming.withSpaces}', () => {
1743
1149
  if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
1744
1150
  const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
1745
1151
  import { wireClass } from '@domain-first/wire'
1746
- import { envBranchedWire } from '../../../${'shared' === boundedContextFolder.name ? '' : '../'}shared/wiring/env-branched-wire'
1152
+ import { envBranchedWire } from '../../../${'shared-kernel' === boundedContextFolder.name ? '' : '../'}shared-kernel/wiring/env-branched-wire'
1747
1153
  ${implementationTypes.map((x)=>({
1748
- naming: new UnknownFormatNaming(`${x}-${naming.fileName}`),
1154
+ naming: new unknown_format_naming_UnknownFormatNaming(`${x}-${naming.fileName}`),
1749
1155
  implementation: x
1750
1156
  })).map(({ naming: { ClassName, fileName }, implementation })=>`import { ${ClassName} } from '../../infrastructure/application-adapters/${implementation}/${fileName}'`).join('\n')}
1751
1157
 
1752
1158
  ${implementationTypes.map((x)=>({
1753
- naming: new UnknownFormatNaming(`${x}-${naming.fileName}`),
1159
+ naming: new unknown_format_naming_UnknownFormatNaming(`${x}-${naming.fileName}`),
1754
1160
  implementation: x
1755
- })).map(({ naming: { ClassName }, implementation })=>`const wire${new UnknownFormatNaming(implementation).ClassName}Implementation = wireClass(${ClassName}, [])`).join('\n\n')}
1161
+ })).map(({ naming: { ClassName }, implementation })=>`const wire${new unknown_format_naming_UnknownFormatNaming(implementation).ClassName}Implementation = wireClass(${ClassName}, [])`).join('\n\n')}
1756
1162
 
1757
1163
  export const wire${naming.ClassName} = envBranchedWire({
1758
- test: wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName},
1759
- development: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName},
1760
- production: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}
1164
+ test: wire${new unknown_format_naming_UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName},
1165
+ development: wire${new unknown_format_naming_UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName},
1166
+ production: wire${new unknown_format_naming_UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}
1761
1167
  })
1762
1168
 
1763
1169
  `.trim());
@@ -1768,7 +1174,7 @@ const scaffoldNewApplicationService = async (boundedContextFolder)=>{
1768
1174
  const name = await (0, prompts_namespaceObject.input)({
1769
1175
  message: 'Name: '
1770
1176
  });
1771
- const naming = new UnknownFormatNaming(name);
1177
+ const naming = new unknown_format_naming_UnknownFormatNaming(name);
1772
1178
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
1773
1179
  const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
1774
1180
  const wiringFolder = boundedContextFolder.subitem([
@@ -1826,14 +1232,6 @@ const scaffoldNewBoundedContextUseCase = async ()=>{
1826
1232
  'bounded-contexts',
1827
1233
  name
1828
1234
  ]);
1829
- if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/errors')) folder.subitem([
1830
- 'domain',
1831
- 'errors'
1832
- ]).createFile('index.ts', `
1833
- import { errorNamespace } from '@domain-first/errors'
1834
-
1835
- export const ${new UnknownFormatNaming(name).ClassName}Errors = errorNamespace('${name}')
1836
- `.trim());
1837
1235
  folder.createIfNotExisted();
1838
1236
  };
1839
1237
  const scaffoldNewCommand = async (boundedContextFolder)=>{
@@ -1849,7 +1247,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
1849
1247
  message: 'Name: '
1850
1248
  });
1851
1249
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
1852
- const naming = new UnknownFormatNaming(commandName);
1250
+ const naming = new unknown_format_naming_UnknownFormatNaming(commandName);
1853
1251
  const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
1854
1252
  const implementationType = await (0, prompts_namespaceObject.input)({
1855
1253
  message: 'Command infrastructure implementation type:',
@@ -1869,7 +1267,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
1869
1267
  testImplementationType
1870
1268
  ].filter((x)=>!!x);
1871
1269
  for (const implementation of implementationTypes){
1872
- const formatNaming = new UnknownFormatNaming(implementation);
1270
+ const formatNaming = new unknown_format_naming_UnknownFormatNaming(implementation);
1873
1271
  const implementationFile = infrastructureFolder.subitem([
1874
1272
  formatNaming.fileName
1875
1273
  ]).createFile(`${formatNaming.fileName}-${naming.fileName}-command.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
@@ -1915,7 +1313,7 @@ export abstract class ${naming.ClassName}Command {
1915
1313
 
1916
1314
  }`.trim());
1917
1315
  if (scaffoldUnitTests) {
1918
- const implementationNaming = new UnknownFormatNaming(implementationType);
1316
+ const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
1919
1317
  const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
1920
1318
  import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
1921
1319
  ${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
@@ -1938,17 +1336,17 @@ describe('${naming.withSpaces} command', () => {
1938
1336
  if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
1939
1337
  }
1940
1338
  if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
1941
- const implementationNaming = new UnknownFormatNaming(implementationType);
1942
- const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
1339
+ const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
1340
+ const testImplementationNaming = new unknown_format_naming_UnknownFormatNaming(testImplementationType);
1943
1341
  const wireFile = boundedContextFolder.subitem([
1944
1342
  'wiring',
1945
1343
  'commands'
1946
1344
  ]).createFile(`wire-${naming.fileName}-command.ts`, `
1947
1345
  import { wireClass } from '@domain-first/wire'
1948
- import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
1949
- ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${fileName}/${fileName}-${naming.fileName}-command'`).join('\n')}
1346
+ import { envBranchedWire } from '../../../../shared-kernel/wiring/env-branched-wire'
1347
+ ${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${fileName}/${fileName}-${naming.fileName}-command'`).join('\n')}
1950
1348
 
1951
- ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Command, [])`).join('\n\n')}
1349
+ ${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Command, [])`).join('\n\n')}
1952
1350
 
1953
1351
  export const wire${naming.ClassName}Command = envBranchedWire({
1954
1352
  test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
@@ -1964,7 +1362,7 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
1964
1362
  const name = await (0, prompts_namespaceObject.input)({
1965
1363
  message: 'Name: '
1966
1364
  });
1967
- const naming = new UnknownFormatNaming(name);
1365
+ const naming = new unknown_format_naming_UnknownFormatNaming(name);
1968
1366
  const aggregatesFolder = boundedContextFolder.subitem([
1969
1367
  'domain',
1970
1368
  'aggregates'
@@ -2018,7 +1416,7 @@ const scaffoldNewDomainService = async (boundedContextFolder)=>{
2018
1416
  const portName = await (0, prompts_namespaceObject.input)({
2019
1417
  message: 'Name:'
2020
1418
  });
2021
- const naming = new UnknownFormatNaming(portName);
1419
+ const naming = new unknown_format_naming_UnknownFormatNaming(portName);
2022
1420
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
2023
1421
  const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
2024
1422
  const domainServicesFolder = boundedContextFolder.subitem([
@@ -2066,14 +1464,26 @@ export const wire${naming.ClassName}DomainService = wireClass(
2066
1464
  const errorNames = (boundedContextFolder)=>{
2067
1465
  const isShared = boundedContextFolder.path === new file_system_Folder(new project_root_ProjectRoot().path).subitem([
2068
1466
  config_file_ConfigFile.Instance.data.rootFolder,
2069
- 'shared'
1467
+ 'shared-kernel'
2070
1468
  ]).path;
2071
1469
  return {
2072
- namespace: (namespaceName)=>`${namespaceName}${isShared ? 'Shared' : ''}Errors`,
2073
- error: (errorName)=>`${errorName}${isShared ? 'SharedError' : ''}`
1470
+ namespace: (namespaceName)=>`${namespaceName}${isShared ? 'SharedKernel' : ''}Errors`,
1471
+ error: (errorName)=>`${errorName}${isShared ? 'SharedKernelError' : ''}`
2074
1472
  };
2075
1473
  };
2076
- const exportedNamespace = (file, fallback)=>/export\s+const\s+(\w+)\s*=\s*errorNamespace\b/.exec(file.data)?.[1] ?? fallback;
1474
+ const namespacePattern = /export\s+const\s+(\w+)\s*=\s*errorNamespace\b/;
1475
+ const exportedNamespace = (file, fallback)=>namespacePattern.exec(file.data)?.[1] ?? fallback;
1476
+ const rootNamespace = (indexFile, namespace, code)=>{
1477
+ const content = indexFile.exists ? indexFile.data.trim() : '';
1478
+ const existing = namespacePattern.exec(content)?.[1];
1479
+ if (existing) return existing;
1480
+ indexFile.update([
1481
+ "import { errorNamespace } from '@domain-first/errors'",
1482
+ `export const ${namespace} = errorNamespace('${code}')`,
1483
+ content
1484
+ ].filter((x)=>!!x).join('\n\n'));
1485
+ return namespace;
1486
+ };
2077
1487
  const errorClass = (className, namespace, code)=>`export class ${className} extends ${namespace}.define('${code}') {}`;
2078
1488
  const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
2079
1489
  const currentErrorFolder = boundedContextFolder.subitem([
@@ -2081,7 +1491,7 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
2081
1491
  'errors'
2082
1492
  ]);
2083
1493
  const names = errorNames(boundedContextFolder);
2084
- const contextNaming = new UnknownFormatNaming(boundedContextFolder.name);
1494
+ const contextNaming = new unknown_format_naming_UnknownFormatNaming(boundedContextFolder.name);
2085
1495
  const currentErrorNamespaces = currentErrorFolder.content.fileNames.filter((x)=>'index' !== x);
2086
1496
  const variants = [
2087
1497
  'New error without namespace',
@@ -2096,16 +1506,16 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
2096
1506
  const errorName = await (0, prompts_namespaceObject.input)({
2097
1507
  message: 'Error name:'
2098
1508
  });
2099
- const naming = new UnknownFormatNaming(errorName);
1509
+ const naming = new unknown_format_naming_UnknownFormatNaming(errorName);
2100
1510
  const indexFile = currentErrorFolder.file('index.ts');
2101
- indexFile.addLineIfMissing(errorClass(names.error(naming.ClassName), exportedNamespace(indexFile, `${contextNaming.ClassName}Errors`), naming.fileName), '\n\n');
1511
+ indexFile.addLineIfMissing(errorClass(names.error(naming.ClassName), rootNamespace(indexFile, `${contextNaming.ClassName}Errors`, boundedContextFolder.name), naming.fileName), '\n\n');
2102
1512
  return;
2103
1513
  }
2104
1514
  if ('New namespace' === selectedVariant) {
2105
1515
  const namespaceName = await (0, prompts_namespaceObject.input)({
2106
1516
  message: 'Namespace name:'
2107
1517
  });
2108
- const { ClassName, fileName } = new UnknownFormatNaming(namespaceName);
1518
+ const { ClassName, fileName } = new unknown_format_naming_UnknownFormatNaming(namespaceName);
2109
1519
  if (!currentErrorFolder.file(`${fileName}.ts`).exists) currentErrorFolder.createFile(`${fileName}.ts`, `
2110
1520
  import { errorNamespace } from '@domain-first/errors'
2111
1521
 
@@ -2115,11 +1525,11 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
2115
1525
  return;
2116
1526
  }
2117
1527
  const namespace = selectedVariant.substring(23);
2118
- const namespaceNaming = new UnknownFormatNaming(namespace);
1528
+ const namespaceNaming = new unknown_format_naming_UnknownFormatNaming(namespace);
2119
1529
  const errorName = await (0, prompts_namespaceObject.input)({
2120
1530
  message: 'Error name:'
2121
1531
  });
2122
- const { ClassName, fileName } = new UnknownFormatNaming(errorName);
1532
+ const { ClassName, fileName } = new unknown_format_naming_UnknownFormatNaming(errorName);
2123
1533
  const namespaceFile = currentErrorFolder.file(`${namespace}.ts`);
2124
1534
  namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
2125
1535
  };
@@ -2186,18 +1596,18 @@ export const restHandlers = restWires.map(x => x().handle)
2186
1596
  ...routeSegments,
2187
1597
  method,
2188
1598
  'endpoint'
2189
- ].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
1599
+ ].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new unknown_format_naming_UnknownFormatNaming(segment).ClassName).join('');
2190
1600
  const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
2191
- const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
1601
+ const endpointGenerator = rest_endpoint_generator_findRestEndpointGenerator(boundedContextFolder.subitem([
2192
1602
  '..',
2193
1603
  '..',
2194
- 'shared'
1604
+ 'shared-kernel'
2195
1605
  ]));
2196
1606
  const handler = withWiring ? await promptEndpointHandler(boundedContextFolder) : void 0;
2197
1607
  const endpointFile = external_node_path_default().join(endpointFolder.path, `${method.toUpperCase()}.ts`);
2198
1608
  endpointFolder.createFile(`${method.toUpperCase()}.ts`, `
2199
- ${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${relativeImport(endpointFile, endpointGenerator.typeFile)}'` : "import { EndpointGenerator } from '@domain-first/handlers-rest'"}${handler ? `
2200
- import type { ${handler.typeName} } from '${relativeImport(endpointFile, handler.typeFile)}'` : ''}
1609
+ ${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${wiring_relativeImport(endpointFile, endpointGenerator.typeFile)}'` : "import { EndpointGenerator } from '@domain-first/handlers-rest'"}${handler ? `
1610
+ import type { ${handler.typeName} } from '${wiring_relativeImport(endpointFile, handler.typeFile)}'` : ''}
2201
1611
 
2202
1612
  export class ${endpointClassName} {
2203
1613
  constructor(
@@ -2221,7 +1631,7 @@ export class ${endpointClassName} {
2221
1631
  controller
2222
1632
  ]);
2223
1633
  const wireNameBase = `wire-${nameBase}`;
2224
- const wireNaming = new UnknownFormatNaming(wireNameBase);
1634
+ const wireNaming = new unknown_format_naming_UnknownFormatNaming(wireNameBase);
2225
1635
  const wireFile = external_node_path_default().join(wiringFolder.path, `${wireNaming.fileName}.ts`);
2226
1636
  const dependencies = endpointGenerator ? [
2227
1637
  endpointGenerator,
@@ -2229,8 +1639,8 @@ export class ${endpointClassName} {
2229
1639
  ].filter((x)=>!!x) : [];
2230
1640
  wiringFolder.createFile(`${wireNaming.fileName}.ts`, `
2231
1641
  import { wireClass } from '@domain-first/wire'
2232
- import { ${endpointClassName} } from '${relativeImport(wireFile, endpointFile)}'
2233
- ${dependencies.map((x)=>`import { ${x.wireName} } from '${relativeImport(wireFile, x.wireFile)}'`).join('\n')}
1642
+ import { ${endpointClassName} } from '${wiring_relativeImport(wireFile, endpointFile)}'
1643
+ ${dependencies.map((x)=>`import { ${x.wireName} } from '${wiring_relativeImport(wireFile, x.wireFile)}'`).join('\n')}
2234
1644
 
2235
1645
  export const wire${endpointClassName} = wireClass(
2236
1646
  ${endpointClassName},
@@ -2244,7 +1654,7 @@ const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
2244
1654
  const name = await (0, prompts_namespaceObject.input)({
2245
1655
  message: 'Name: '
2246
1656
  });
2247
- const naming = new UnknownFormatNaming(name);
1657
+ const naming = new unknown_format_naming_UnknownFormatNaming(name);
2248
1658
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
2249
1659
  const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
2250
1660
  const wiringFolder = boundedContextFolder.subitem([
@@ -2303,7 +1713,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
2303
1713
  message: 'Name: '
2304
1714
  });
2305
1715
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
2306
- const naming = new UnknownFormatNaming(queryName);
1716
+ const naming = new unknown_format_naming_UnknownFormatNaming(queryName);
2307
1717
  const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
2308
1718
  const implementationType = await (0, prompts_namespaceObject.input)({
2309
1719
  message: 'Query infrastructure implementation type:',
@@ -2323,7 +1733,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
2323
1733
  testImplementationType
2324
1734
  ].filter((x)=>!!x);
2325
1735
  for (const implementation of implementationTypes){
2326
- const formatNaming = new UnknownFormatNaming(implementation);
1736
+ const formatNaming = new unknown_format_naming_UnknownFormatNaming(implementation);
2327
1737
  const implementationFile = infrastructureFolder.subitem([
2328
1738
  formatNaming.fileName
2329
1739
  ]).createFile(`${formatNaming.fileName}-${naming.fileName}-query.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
@@ -2369,7 +1779,7 @@ export abstract class ${naming.ClassName}Query {
2369
1779
 
2370
1780
  }`.trim());
2371
1781
  if (scaffoldUnitTests) {
2372
- const implementationNaming = new UnknownFormatNaming(implementationType);
1782
+ const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
2373
1783
  const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
2374
1784
  import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
2375
1785
  ${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
@@ -2392,17 +1802,17 @@ describe('${naming.withSpaces} query', () => {
2392
1802
  if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
2393
1803
  }
2394
1804
  if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
2395
- const implementationNaming = new UnknownFormatNaming(implementationType);
2396
- const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
1805
+ const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
1806
+ const testImplementationNaming = new unknown_format_naming_UnknownFormatNaming(testImplementationType);
2397
1807
  const wireFile = boundedContextFolder.subitem([
2398
1808
  'wiring',
2399
1809
  'queries'
2400
1810
  ]).createFile(`wire-${naming.fileName}-query.ts`, `
2401
1811
  import { wireClass } from '@domain-first/wire'
2402
- import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
2403
- ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${fileName}/${fileName}-${naming.fileName}-query'`).join('\n')}
1812
+ import { envBranchedWire } from '../../../../shared-kernel/wiring/env-branched-wire'
1813
+ ${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${fileName}/${fileName}-${naming.fileName}-query'`).join('\n')}
2404
1814
 
2405
- ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Query, [])`).join('\n\n')}
1815
+ ${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Query, [])`).join('\n\n')}
2406
1816
 
2407
1817
  export const wire${naming.ClassName}Query = envBranchedWire({
2408
1818
  test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
@@ -2421,7 +1831,7 @@ const scaffoldNewUseCase = async (boundedContextFolder)=>{
2421
1831
  const useCaseName = await (0, prompts_namespaceObject.input)({
2422
1832
  message: 'Name: '
2423
1833
  });
2424
- const naming = new UnknownFormatNaming(useCaseName);
1834
+ const naming = new unknown_format_naming_UnknownFormatNaming(useCaseName);
2425
1835
  const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
2426
1836
  const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
2427
1837
  useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
@@ -2480,197 +1890,10 @@ export const wire${naming.ClassName}UseCase = wireClass(
2480
1890
  await wireNewModuleDependencies(boundedContextFolder, wireFile);
2481
1891
  }
2482
1892
  };
2483
- const scaffoldReactSharedHook = async (presentationReactFolder)=>{
2484
- const name = await (0, prompts_namespaceObject.input)({
2485
- message: 'Name without "use" (e.g. debounce): '
2486
- });
2487
- const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
2488
- presentationReactFolder.subitem([
2489
- 'hooks'
2490
- ]).createFile(`use-${fileName}.ts`, `
2491
- export const use${ClassName} = () => {
2492
- return {}
2493
- }
2494
- `.trim());
2495
- };
2496
- const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
2497
- const name = await (0, prompts_namespaceObject.input)({
2498
- message: 'Name: '
2499
- });
2500
- const { ClassName, fileName } = new UnknownFormatNaming(name);
2501
- const componentFolder = presentationReactFolder.subitem([
2502
- 'ui-kit',
2503
- fileName
2504
- ]);
2505
- componentFolder.createFile('index.ts', `export * from './${fileName}'`);
2506
- componentFolder.createFile(`${fileName}.tsx`, `
2507
- import { type FC } from 'react'
2508
-
2509
- export type ${ClassName}Props = {}
2510
-
2511
- export const ${ClassName}: FC<${ClassName}Props> = (props) => {
2512
- return <></>
2513
- }
2514
- `.trim());
2515
- const { storybookFramework } = config_file_ConfigFile.Instance.data;
2516
- if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
2517
- import type { Meta, StoryObj } from '${storybookFramework}'
2518
- import { ${ClassName} } from './${fileName}'
2519
-
2520
- const meta = {
2521
- title: 'UI-kit/${ClassName}',
2522
- component: ${ClassName}
2523
- } satisfies Meta<typeof ${ClassName}>
2524
-
2525
- export default meta
2526
-
2527
- type Story = StoryObj<typeof meta>
2528
-
2529
- export const Default: Story = {
2530
- args: {}
2531
- }
2532
- `.trim());
2533
- };
2534
- const scaffoldReactWidget = async (presentationReactFolder)=>{
2535
- const widgetName = await (0, prompts_namespaceObject.input)({
2536
- message: 'Name (folders split by "/"): ',
2537
- validate: NestedName.validate
2538
- });
2539
- const widgetType = await (0, prompts_namespaceObject.select)({
2540
- choices: [
2541
- 'monolithic',
2542
- 'with separated ui',
2543
- 'headless'
2544
- ],
2545
- message: 'Type: '
2546
- });
2547
- const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
2548
- const folder = presentationReactFolder.subitem([
2549
- 'widgets',
2550
- ...folders,
2551
- folderName
2552
- ]);
2553
- const storyTitle = [
2554
- 'Widgets',
2555
- ...classNameSegments
2556
- ].join('/');
2557
- const widgetFileName = `${fileName}-widget`;
2558
- const uiFileName = `${fileName}-widget-ui`;
2559
- const uiModelFileName = `use-${fileName}-ui-model`;
2560
- folder.createFile('index.ts', `export * from './${widgetFileName}'`);
2561
- switch(widgetType){
2562
- case 'monolithic':
2563
- folder.createFile(`${widgetFileName}.tsx`, `
2564
- import { type FC } from 'react'
2565
-
2566
- export type ${ClassName}WidgetProps = {}
2567
-
2568
- export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
2569
- return <></>
2570
- }
2571
- `.trim());
2572
- break;
2573
- case 'with separated ui':
2574
- {
2575
- folder.createFile('types.ts', `
2576
- export type ${ClassName}WidgetProps = { }
2577
-
2578
- export type ${ClassName}WidgetUIProps = { }
2579
- `.trim());
2580
- folder.createFile(`${widgetFileName}.tsx`, `
2581
- import { type FC } from 'react'
2582
- import type { ${ClassName}WidgetProps } from './types'
2583
- import { ${ClassName}WidgetUI } from './ui/${uiFileName}'
2584
- import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
2585
-
2586
- export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
2587
- const uiModel = use${ClassName}UIModel(props)
2588
- return <${ClassName}WidgetUI {...uiModel} />
2589
- }
2590
-
2591
- export type { ${ClassName}WidgetProps }
2592
- `.trim());
2593
- folder.subitem([
2594
- 'ui'
2595
- ]).createFile(`${uiFileName}.tsx`, `
2596
- import { FC } from 'react'
2597
- import type { ${ClassName}WidgetUIProps } from '../types'
2598
-
2599
- export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
2600
- return <></>
2601
- }
2602
- `.trim());
2603
- const { storybookFramework } = config_file_ConfigFile.Instance.data;
2604
- if (storybookFramework) folder.subitem([
2605
- 'ui'
2606
- ]).createFile(`${uiFileName}.stories.tsx`, `
2607
- import type { Meta, StoryObj } from '${storybookFramework}'
2608
- import { ${ClassName}WidgetUI } from './${uiFileName}'
2609
-
2610
- const meta = {
2611
- title: '${storyTitle}',
2612
- component: ${ClassName}WidgetUI
2613
- } satisfies Meta<typeof ${ClassName}WidgetUI>
2614
-
2615
- export default meta
2616
-
2617
- type Story = StoryObj<typeof meta>
2618
-
2619
- export const Default: Story = {
2620
- args: {}
2621
- }
2622
- `.trim());
2623
- folder.subitem([
2624
- 'hooks'
2625
- ]).createFile(`${uiModelFileName}.ts`, `
2626
- import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
2627
-
2628
- export const use${ClassName}UIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
2629
- return {}
2630
- }
2631
- `.trim());
2632
- break;
2633
- }
2634
- case 'headless':
2635
- folder.createFile('types.ts', `
2636
- import { type FC } from 'react'
2637
-
2638
- export type ${ClassName}WidgetUIProps = { }
2639
-
2640
- export type ${ClassName}WidgetProps = {
2641
- UI: FC<${ClassName}WidgetUIProps>
2642
- }
2643
-
2644
- `.trim());
2645
- folder.createFile(`${widgetFileName}.tsx`, `
2646
- import { type FC } from 'react'
2647
- import type { ${ClassName}WidgetProps } from './types'
2648
- import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
2649
-
2650
- export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
2651
- const uiModel = use${ClassName}UIModel(props)
2652
- return <props.UI {...uiModel} />
2653
- }
2654
-
2655
- export type { ${ClassName}WidgetProps }
2656
- `.trim());
2657
- folder.subitem([
2658
- 'hooks'
2659
- ]).createFile(`${uiModelFileName}.ts`, `
2660
- import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
2661
-
2662
- export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
2663
- return {}
2664
- }
2665
- `.trim());
2666
- break;
2667
- }
2668
- };
2669
1893
  const main = async ()=>{
2670
1894
  if (!config_file_ConfigFile.exists) {
2671
- const nextSteps = await initializeUseCase();
2672
- if (await save_pending_changes_savePendingChanges()) print_next_steps_printNextSteps(nextSteps);
2673
- return;
1895
+ console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
1896
+ process.exit(1);
2674
1897
  }
2675
1898
  const rootPath = new project_root_ProjectRoot().path;
2676
1899
  const currentBoundedContextOptions = new file_system_Folder(rootPath).subitem([
@@ -2686,57 +1909,18 @@ const main = async ()=>{
2686
1909
  };
2687
1910
  const options = [
2688
1911
  ...currentBoundedContextOptions,
2689
- config_file_ConfigFile.Instance.data.useReact ? {
2690
- name: 'Scaffold React module',
2691
- action: 'Scaffold React module'
2692
- } : void 0,
2693
1912
  {
2694
- name: 'Shared Layer',
1913
+ name: 'Shared Kernel',
2695
1914
  action: 'Scaffold in bounded context'
2696
1915
  },
2697
1916
  scaffoldNewBoundedContext
2698
- ].filter((x)=>!!x);
1917
+ ];
2699
1918
  const result = await (0, prompts_namespaceObject.select)({
2700
1919
  message: '@domain-first/project-structure',
2701
1920
  choices: options.map((x)=>x.name)
2702
1921
  });
2703
1922
  const { action, name } = options.find((x)=>x.name === result);
2704
1923
  switch(action){
2705
- case 'Scaffold React module':
2706
- {
2707
- const reactFolder = new file_system_Folder(rootPath).subitem([
2708
- config_file_ConfigFile.Instance.data.rootFolder,
2709
- 'presentation',
2710
- 'react'
2711
- ]);
2712
- const action = await (0, prompts_namespaceObject.select)({
2713
- message: 'Module: ',
2714
- choices: [
2715
- 'New widget',
2716
- 'New page',
2717
- 'New UI-kit component',
2718
- 'New shared hook',
2719
- 'Move or rename widget',
2720
- 'Move or rename page'
2721
- ]
2722
- });
2723
- switch(action){
2724
- case 'New widget':
2725
- return void await scaffoldReactWidget(reactFolder);
2726
- case 'New page':
2727
- return void await scaffoldReactPage(reactFolder);
2728
- case 'New UI-kit component':
2729
- return void await scaffoldReactUIKitComponent(reactFolder);
2730
- case 'New shared hook':
2731
- return void await scaffoldReactSharedHook(reactFolder);
2732
- case 'Move or rename widget':
2733
- return void await moveReactModuleUseCase(reactFolder, 'widget');
2734
- case 'Move or rename page':
2735
- return void await moveReactModuleUseCase(reactFolder, 'page');
2736
- default:
2737
- return;
2738
- }
2739
- }
2740
1924
  case 'Scaffold new bounded context':
2741
1925
  return void await scaffoldNewBoundedContextUseCase();
2742
1926
  case 'Scaffold in bounded context':
@@ -2748,7 +1932,7 @@ const main = async ()=>{
2748
1932
  name.substring(17)
2749
1933
  ] : [
2750
1934
  config_file_ConfigFile.Instance.data.rootFolder,
2751
- 'shared'
1935
+ 'shared-kernel'
2752
1936
  ]);
2753
1937
  const layer = await (0, prompts_namespaceObject.select)({
2754
1938
  message: 'Layer:',