@domain-first/project-structure 8.6.1 → 8.7.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.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/bin/df-skills.mjs +55 -9
  3. package/dist/287.js +44 -138
  4. package/dist/38.js +36 -0
  5. package/dist/561.js +9 -1
  6. package/dist/947.js +11 -1
  7. package/dist/agent-cli.d.ts +9 -2
  8. package/dist/agent-principles.cjs +116 -0
  9. package/dist/agent-principles.d.ts +9 -0
  10. package/dist/agent-principles.js +64 -0
  11. package/dist/agent-principles.spec.d.ts +1 -0
  12. package/dist/agent-requests.d.ts +16 -2
  13. package/dist/graph.cjs +10 -0
  14. package/dist/in-memory-db.d.ts +1 -6
  15. package/dist/index.cjs +64 -137
  16. package/dist/index.js +4 -1
  17. package/dist/init.cjs +12 -21
  18. package/dist/integration.cjs +61 -137
  19. package/dist/lint.cjs +46 -0
  20. package/dist/react.cjs +61 -137
  21. package/dist/use-cases/add-integration.d.ts +1 -1
  22. package/dist/use-cases/index.d.ts +1 -0
  23. package/dist/use-cases/scaffold-new-infrastructure-helper.d.ts +7 -0
  24. package/dist/wiring.d.ts +2 -2
  25. package/package.json +3 -2
  26. package/principles/df-principles.md +33 -0
  27. package/skills/df-ps-implement/SKILL.md +26 -1
  28. package/skills/df-ps-plan-feature/SKILL.md +22 -18
  29. package/skills/df-ps-react/SKILL.md +2 -9
  30. package/skills/df-ps-react/references/generators.md +9 -9
  31. package/skills/df-ps-scaffold/SKILL.md +20 -126
  32. package/skills/df-ps-scaffold/references/agent-mode.md +2 -2
  33. package/skills/df-ps-scaffold/references/agent-operations.md +1 -0
  34. package/skills/df-ps-scaffold/references/choosing-components.md +65 -49
  35. package/skills/df-ps-scaffold/references/generators.md +33 -11
  36. package/skills/df-ps-scaffold/references/units/aggregate.md +3 -5
  37. package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
  38. package/skills/df-ps-scaffold/references/units/command-query.md +6 -8
  39. package/skills/df-ps-scaffold/references/units/delete.md +0 -2
  40. package/skills/df-ps-scaffold/references/units/endpoint.md +1 -4
  41. package/skills/df-ps-scaffold/references/units/entity-value-object.md +0 -4
  42. package/skills/df-ps-scaffold/references/units/errors.md +0 -4
  43. package/skills/df-ps-scaffold/references/units/helper.md +30 -0
  44. package/skills/df-ps-scaffold/references/units/implementation.md +1 -5
  45. package/skills/df-ps-scaffold/references/units/move-or-rename.md +0 -4
  46. package/skills/df-ps-scaffold/references/units/port.md +3 -6
  47. package/skills/df-ps-scaffold/references/units/services.md +4 -6
  48. package/skills/df-ps-scaffold/references/units/use-case.md +1 -2
  49. package/skills/df-ps-scaffold/references/units/wire-dependency.md +0 -2
  50. package/skills/df-ps-scaffold/references/work-plan.md +73 -0
  51. package/skills/df-ps-scaffold/scripts/drive.mjs +0 -252
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ applyPrinciples: ()=>applyPrinciples,
41
+ principlesState: ()=>principlesState
42
+ });
43
+ const external_node_fs_namespaceObject = require("node:fs");
44
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
45
+ const external_node_path_namespaceObject = require("node:path");
46
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
47
+ const copyName = 'df-principles.md';
48
+ const blockStart = '<!-- df-principles:start -->';
49
+ const blockEnd = '<!-- df-principles:end -->';
50
+ const read = (file)=>external_node_fs_default().existsSync(file) ? external_node_fs_default().readFileSync(file, 'utf8') : void 0;
51
+ const write = (file, content)=>{
52
+ external_node_fs_default().mkdirSync(external_node_path_default().dirname(file), {
53
+ recursive: true
54
+ });
55
+ external_node_fs_default().writeFileSync(file, content);
56
+ };
57
+ const withParagraph = (content, paragraph)=>content?.trim() ? `${content.trimEnd()}\n\n${paragraph}\n` : `${paragraph}\n`;
58
+ const claudeEntries = (root)=>[
59
+ {
60
+ file: external_node_path_default().join(root, 'CLAUDE.md'),
61
+ line: `@.claude/${copyName}`
62
+ },
63
+ {
64
+ file: external_node_path_default().join(root, '.claude', 'CLAUDE.md'),
65
+ line: `@${copyName}`
66
+ }
67
+ ];
68
+ const connectedClaudeEntry = (root)=>claudeEntries(root).find(({ file, line })=>read(file)?.split('\n').some((candidate)=>candidate.trim() === line));
69
+ const occurrences = (content, marker)=>content.split(marker).length - 1;
70
+ const blockState = (content = '')=>{
71
+ const starts = occurrences(content, blockStart);
72
+ const ends = occurrences(content, blockEnd);
73
+ if (!starts && !ends) return 'absent';
74
+ return 1 === starts && 1 === ends && content.indexOf(blockStart) < content.indexOf(blockEnd) ? 'connected' : 'broken';
75
+ };
76
+ const applyToClaude = (root, text, install)=>{
77
+ const copy = external_node_path_default().join(root, '.claude', copyName);
78
+ if (connectedClaudeEntry(root)) {
79
+ write(copy, text);
80
+ return 'updated';
81
+ }
82
+ if (!install) return 'skipped';
83
+ const [rootEntry, nestedEntry] = claudeEntries(root);
84
+ const entry = !external_node_fs_default().existsSync(rootEntry.file) && external_node_fs_default().existsSync(nestedEntry.file) ? nestedEntry : rootEntry;
85
+ write(copy, text);
86
+ write(entry.file, withParagraph(read(entry.file), entry.line));
87
+ return 'added';
88
+ };
89
+ const applyToCodex = (root, text, install)=>{
90
+ const file = external_node_path_default().join(root, 'AGENTS.md');
91
+ const content = read(file);
92
+ const state = blockState(content);
93
+ if ('broken' === state) return 'conflict';
94
+ const block = `${blockStart}\n${text.trim()}\n${blockEnd}`;
95
+ if ('connected' === state && void 0 !== content) {
96
+ write(file, content.slice(0, content.indexOf(blockStart)) + block + content.slice(content.indexOf(blockEnd) + blockEnd.length));
97
+ return 'updated';
98
+ }
99
+ if (!install) return 'skipped';
100
+ write(file, withParagraph(content, block));
101
+ return 'added';
102
+ };
103
+ const principlesState = (root, agent)=>{
104
+ if ('codex' === agent) return blockState(read(external_node_path_default().join(root, 'AGENTS.md')));
105
+ return connectedClaudeEntry(root) ? 'connected' : 'absent';
106
+ };
107
+ const applyPrinciples = (root, agent, text, install)=>('codex' === agent ? applyToCodex : applyToClaude)(root, text, install);
108
+ exports.applyPrinciples = __webpack_exports__.applyPrinciples;
109
+ exports.principlesState = __webpack_exports__.principlesState;
110
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
111
+ "applyPrinciples",
112
+ "principlesState"
113
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
114
+ Object.defineProperty(exports, '__esModule', {
115
+ value: true
116
+ });
@@ -0,0 +1,9 @@
1
+ export type PrinciplesAgent = 'claude' | 'codex';
2
+ export type PrinciplesState = 'connected' | 'absent' | 'broken';
3
+ export type PrinciplesResult = 'added' | 'updated' | 'skipped' | 'conflict';
4
+ export declare const principlesState: (root: string, agent: PrinciplesAgent) => PrinciplesState;
5
+ /**
6
+ * Refreshes connected principles. Connects them only with `install`, so
7
+ * a project that removed them stays without them.
8
+ */
9
+ export declare const applyPrinciples: (root: string, agent: PrinciplesAgent, text: string, install: boolean) => PrinciplesResult;
@@ -0,0 +1,64 @@
1
+ import node_fs from "node:fs";
2
+ import node_path from "node:path";
3
+ const copyName = 'df-principles.md';
4
+ const blockStart = '<!-- df-principles:start -->';
5
+ const blockEnd = '<!-- df-principles:end -->';
6
+ const read = (file)=>node_fs.existsSync(file) ? node_fs.readFileSync(file, 'utf8') : void 0;
7
+ const write = (file, content)=>{
8
+ node_fs.mkdirSync(node_path.dirname(file), {
9
+ recursive: true
10
+ });
11
+ node_fs.writeFileSync(file, content);
12
+ };
13
+ const withParagraph = (content, paragraph)=>content?.trim() ? `${content.trimEnd()}\n\n${paragraph}\n` : `${paragraph}\n`;
14
+ const claudeEntries = (root)=>[
15
+ {
16
+ file: node_path.join(root, 'CLAUDE.md'),
17
+ line: `@.claude/${copyName}`
18
+ },
19
+ {
20
+ file: node_path.join(root, '.claude', 'CLAUDE.md'),
21
+ line: `@${copyName}`
22
+ }
23
+ ];
24
+ const connectedClaudeEntry = (root)=>claudeEntries(root).find(({ file, line })=>read(file)?.split('\n').some((candidate)=>candidate.trim() === line));
25
+ const occurrences = (content, marker)=>content.split(marker).length - 1;
26
+ const blockState = (content = '')=>{
27
+ const starts = occurrences(content, blockStart);
28
+ const ends = occurrences(content, blockEnd);
29
+ if (!starts && !ends) return 'absent';
30
+ return 1 === starts && 1 === ends && content.indexOf(blockStart) < content.indexOf(blockEnd) ? 'connected' : 'broken';
31
+ };
32
+ const applyToClaude = (root, text, install)=>{
33
+ const copy = node_path.join(root, '.claude', copyName);
34
+ if (connectedClaudeEntry(root)) {
35
+ write(copy, text);
36
+ return 'updated';
37
+ }
38
+ if (!install) return 'skipped';
39
+ const [rootEntry, nestedEntry] = claudeEntries(root);
40
+ const entry = !node_fs.existsSync(rootEntry.file) && node_fs.existsSync(nestedEntry.file) ? nestedEntry : rootEntry;
41
+ write(copy, text);
42
+ write(entry.file, withParagraph(read(entry.file), entry.line));
43
+ return 'added';
44
+ };
45
+ const applyToCodex = (root, text, install)=>{
46
+ const file = node_path.join(root, 'AGENTS.md');
47
+ const content = read(file);
48
+ const state = blockState(content);
49
+ if ('broken' === state) return 'conflict';
50
+ const block = `${blockStart}\n${text.trim()}\n${blockEnd}`;
51
+ if ('connected' === state && void 0 !== content) {
52
+ write(file, content.slice(0, content.indexOf(blockStart)) + block + content.slice(content.indexOf(blockEnd) + blockEnd.length));
53
+ return 'updated';
54
+ }
55
+ if (!install) return 'skipped';
56
+ write(file, withParagraph(content, block));
57
+ return 'added';
58
+ };
59
+ const principlesState = (root, agent)=>{
60
+ if ('codex' === agent) return blockState(read(node_path.join(root, 'AGENTS.md')));
61
+ return connectedClaudeEntry(root) ? 'connected' : 'absent';
62
+ };
63
+ const applyPrinciples = (root, agent, text, install)=>('codex' === agent ? applyToCodex : applyToClaude)(root, text, install);
64
+ export { applyPrinciples, principlesState };
@@ -0,0 +1 @@
1
+ export {};
@@ -68,6 +68,13 @@ export declare const scaffoldRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject
68
68
  context: z.ZodString;
69
69
  overwrite: z.ZodOptional<z.ZodBoolean>;
70
70
  dryRun: z.ZodOptional<z.ZodBoolean>;
71
+ }, z.core.$strict>, z.ZodObject<{
72
+ operation: z.ZodLiteral<"helper">;
73
+ name: z.ZodString;
74
+ implementationType: z.ZodString;
75
+ context: z.ZodString;
76
+ overwrite: z.ZodOptional<z.ZodBoolean>;
77
+ dryRun: z.ZodOptional<z.ZodBoolean>;
71
78
  }, z.core.$strict>, z.ZodObject<{
72
79
  operation: z.ZodLiteral<"presentation-service">;
73
80
  dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
@@ -252,9 +259,9 @@ export declare const reactRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
252
259
  export declare const integrationRequestSchema: z.ZodObject<{
253
260
  operation: z.ZodLiteral<"add">;
254
261
  integrations: z.ZodArray<z.ZodEnum<{
262
+ prisma: "prisma";
255
263
  openapi: "openapi";
256
264
  orval: "orval";
257
- prisma: "prisma";
258
265
  "rest-endpoint-generator": "rest-endpoint-generator";
259
266
  storybook: "storybook";
260
267
  vitest: "vitest";
@@ -353,6 +360,13 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
353
360
  context: z.ZodString;
354
361
  overwrite: z.ZodOptional<z.ZodBoolean>;
355
362
  dryRun: z.ZodOptional<z.ZodBoolean>;
363
+ }, z.core.$strict>, z.ZodObject<{
364
+ operation: z.ZodLiteral<"helper">;
365
+ name: z.ZodString;
366
+ implementationType: z.ZodString;
367
+ context: z.ZodString;
368
+ overwrite: z.ZodOptional<z.ZodBoolean>;
369
+ dryRun: z.ZodOptional<z.ZodBoolean>;
356
370
  }, z.core.$strict>, z.ZodObject<{
357
371
  operation: z.ZodLiteral<"presentation-service">;
358
372
  dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
@@ -535,9 +549,9 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
535
549
  }, z.core.$strict>], "operation"> | z.ZodObject<{
536
550
  operation: z.ZodLiteral<"add">;
537
551
  integrations: z.ZodArray<z.ZodEnum<{
552
+ prisma: "prisma";
538
553
  openapi: "openapi";
539
554
  orval: "orval";
540
- prisma: "prisma";
541
555
  "rest-endpoint-generator": "rest-endpoint-generator";
542
556
  storybook: "storybook";
543
557
  vitest: "vitest";
package/dist/graph.cjs CHANGED
@@ -498,6 +498,16 @@ const wiring_findWiredModules = (contextPath)=>{
498
498
  walk(external_node_path_default().join(contextPath, 'wiring'));
499
499
  return result.sort((a, b)=>a.typeName.localeCompare(b.typeName));
500
500
  };
501
+ new Map([
502
+ [
503
+ 'prisma',
504
+ 'prisma-infrastructure-service'
505
+ ],
506
+ [
507
+ 'in-memory',
508
+ 'in-memory-db-infrastructure-service'
509
+ ]
510
+ ]);
501
511
  const codeOnly = (source)=>{
502
512
  let result = '';
503
513
  let index = 0;
@@ -2,7 +2,7 @@ import { File, Folder } from './file-system';
2
2
  import { UnknownFormatNaming } from './unknown-format-naming';
3
3
  import { type WiredModule } from './wiring';
4
4
  /**
5
- * The shared in-memory DB with its spec and wire, as the config says.
5
+ * The shared in-memory DB with its wire, as the config says.
6
6
  */
7
7
  export declare const scaffoldInMemoryDb: (shared: Folder) => void;
8
8
  /**
@@ -51,8 +51,3 @@ export declare const injectInMemoryDb: (classFile: File, implementationName: str
51
51
  * Passes the in-memory DB wire to the implementation's `wireClass`.
52
52
  */
53
53
  export declare const wireInMemoryDb: (consumerWireFile: File, implementationName: string) => void;
54
- /**
55
- * A spec without wiring builds the implementation itself, so it has to
56
- * pass the in-memory DB.
57
- */
58
- export declare const passInMemoryDb: (specFile: File, implementationName: string) => void;
package/dist/index.cjs CHANGED
@@ -641,7 +641,17 @@ const findWiredModules = (contextPath)=>{
641
641
  const moduleKindOf = (module)=>wiredModuleKind(module.kind);
642
642
  const layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
643
643
  const wiring_implementationType = (consumer, implementation)=>consumer.branched ? external_node_path_default().basename(external_node_path_default().dirname(implementation.file)) : void 0;
644
- const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${external_node_path_default().basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
644
+ const systemInfrastructureServices = new Map([
645
+ [
646
+ 'prisma',
647
+ 'prisma-infrastructure-service'
648
+ ],
649
+ [
650
+ 'in-memory',
651
+ 'in-memory-db-infrastructure-service'
652
+ ]
653
+ ]);
654
+ const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && external_node_path_default().basename(candidate.typeFile, '.ts') === systemInfrastructureServices.get(implementation);
645
655
  const canDependOn = (consumer, candidate, rules = defaultDependencyRules, implementation = consumer.implementations[0])=>{
646
656
  const crossContext = crossContextImportAllowed(consumer.wireFile, candidate.wireFile);
647
657
  if (void 0 !== crossContext) return crossContext && 'infrastructure' === consumer.implementationsLayer && 'application' === candidate.layer && !!implementation && true === crossContextImportAllowed(implementation.file, candidate.typeFile);
@@ -1013,23 +1023,6 @@ export const wireInMemoryDbInfrastructureService = wireClass(
1013
1023
  []
1014
1024
  );
1015
1025
  `;
1016
- const inMemoryDbSpec = (testingLibrary, withWiring)=>`
1017
- import { describe, test, expect, beforeEach } from '${testingLibrary}'
1018
- ${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
1019
- import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
1020
-
1021
- let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
1022
-
1023
- beforeEach(() => {
1024
- inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
1025
- })
1026
-
1027
- describe('in memory db', () => {
1028
- test('can be ${withWiring ? 'wired' : 'created'}', () => {
1029
- expect(inMemoryDbInfrastructureService).toBeDefined()
1030
- })
1031
- })
1032
- `.trim();
1033
1026
  const in_memory_db_withWiring = ()=>config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
1034
1027
  const in_memory_db_sharedFolder = ()=>new file_system_Folder(new project_root_ProjectRoot().path).subitem([
1035
1028
  config_file_ConfigFile.Instance.data.project.rootFolder,
@@ -1046,13 +1039,11 @@ const in_memory_db_wireFile = ()=>new file_system_File(in_memory_db_sharedFolder
1046
1039
  'wire-in-memory-db-infrastructure-service.ts'
1047
1040
  ]);
1048
1041
  const in_memory_db_scaffoldInMemoryDb = (shared)=>{
1049
- const { testingLibrary } = config_file_ConfigFile.backend;
1050
1042
  const servicesFolder = shared.subitem([
1051
1043
  'infrastructure',
1052
1044
  'services'
1053
1045
  ]);
1054
1046
  servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
1055
- if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
1056
1047
  if (in_memory_db_withWiring()) shared.subitem([
1057
1048
  'wiring',
1058
1049
  'infrastructure-services'
@@ -1114,9 +1105,6 @@ const wireInMemoryDb = (consumerWireFile, implementationName)=>{
1114
1105
  in_memory_db_wireName
1115
1106
  ]));
1116
1107
  };
1117
- const passInMemoryDb = (specFile, implementationName)=>{
1118
- 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}())`));
1119
- };
1120
1108
  const addInMemoryDb = ()=>{
1121
1109
  const config = config_file_ConfigFile.Instance.data;
1122
1110
  if (!config_file_ConfigFile.backend.withInMemoryDb) config_file_ConfigFile.update({
@@ -3176,6 +3164,12 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
3176
3164
  ...named,
3177
3165
  ...agent_requests_wired
3178
3166
  }),
3167
+ agent_requests_operation('helper', {
3168
+ ...common,
3169
+ ...agent_requests_owner,
3170
+ name: agent_requests_nestedName.describe('Kebab-case, folders split by "/": mappers/social-network-type.'),
3171
+ implementationType: agent_requests_name.describe('A saved or system implementation type: a helper belongs to one.')
3172
+ }),
3179
3173
  agent_requests_operation('presentation-service', {
3180
3174
  ...named,
3181
3175
  ...agent_requests_wired
@@ -4697,29 +4691,6 @@ describe('${aggregateNaming.withSpaces}', () => {
4697
4691
  labels: []
4698
4692
  };
4699
4693
  for (const implementation of implementationTypes)createImplementation(boundedContextFolder, repository, new UnknownFormatNaming(implementation).fileName);
4700
- if (scaffoldUnitTests) {
4701
- const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
4702
- const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
4703
- import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
4704
- ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
4705
- 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'
4706
-
4707
- type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`}
4708
-
4709
- let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
4710
-
4711
- beforeEach(() => {
4712
- ${aggregateNaming.variableName}Repository = ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${aggregateNaming.ClassName}Repository()` : `new ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository()`}
4713
- })
4714
-
4715
- describe('${aggregateNaming.withSpaces} repository', () => {
4716
- test('can be ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
4717
- expect(${aggregateNaming.variableName}Repository).toBeDefined()
4718
- })
4719
- })
4720
- `.trim());
4721
- if (!config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
4722
- }
4723
4694
  if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
4724
4695
  const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
4725
4696
  const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
@@ -4745,7 +4716,6 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
4745
4716
  message: 'Name: '
4746
4717
  });
4747
4718
  const naming = new UnknownFormatNaming(name);
4748
- const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
4749
4719
  const wiringFolder = boundedContextFolder.subitem([
4750
4720
  'wiring',
4751
4721
  'application-ports'
@@ -4785,28 +4755,6 @@ export abstract class ${naming.ClassName} {
4785
4755
  ownerPath: boundedContextFolder.path,
4786
4756
  labels: []
4787
4757
  }, implementation);
4788
- if (scaffoldUnitTests) {
4789
- const implementationNaming = new UnknownFormatNaming(implementationType);
4790
- applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
4791
- import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
4792
- ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
4793
- import { wire${naming.ClassName} } from '../../wiring/application-ports/wire-${naming.fileName}'` : `import { ${implementationNaming.ClassName}${naming.ClassName} } from '../../infrastructure/application-adapters/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}'
4794
-
4795
- type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`}
4796
-
4797
- let ${naming.variableName}: ${naming.ClassName}
4798
-
4799
- beforeEach(() => {
4800
- ${naming.variableName} = ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${naming.ClassName}()` : `new ${implementationNaming.ClassName}${naming.ClassName}()`}
4801
- })
4802
-
4803
- describe('${naming.withSpaces}', () => {
4804
- test('can be ${config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
4805
- expect(${naming.variableName}).toBeDefined()
4806
- })
4807
- })
4808
- `.trim());
4809
- }
4810
4758
  if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
4811
4759
  const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
4812
4760
  import { wireClass } from '@domain-first/wire'
@@ -4902,9 +4850,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
4902
4850
  key: 'name',
4903
4851
  message: 'Name: '
4904
4852
  });
4905
- const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
4906
4853
  const naming = new UnknownFormatNaming(commandName);
4907
- const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
4908
4854
  const { label: implementationType } = await promptImplementationType('Command infrastructure implementation type:', 'commands');
4909
4855
  let addTestImplementation = false;
4910
4856
  let testImplementationType = '';
@@ -4942,29 +4888,6 @@ export abstract class ${naming.ClassName}Command {
4942
4888
  export abstract class ${naming.ClassName}Command {
4943
4889
 
4944
4890
  }`.trim());
4945
- if (scaffoldUnitTests) {
4946
- const implementationNaming = new UnknownFormatNaming(implementationType);
4947
- const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
4948
- import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
4949
- ${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
4950
- import { wire${naming.ClassName}Command } from '../../wiring/commands/wire-${naming.fileName}-command'` : `import { ${implementationNaming.ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}-command'
4951
-
4952
- type ${naming.ClassName}Command = ${implementationNaming.ClassName}${naming.ClassName}Command`}
4953
-
4954
- let ${naming.variableName}Command: ${naming.ClassName}Command
4955
-
4956
- beforeEach(() => {
4957
- ${naming.variableName}Command = ${withWiring ? `wire${naming.ClassName}Command()` : `new ${implementationNaming.ClassName}${naming.ClassName}Command()`}
4958
- })
4959
-
4960
- describe('${naming.withSpaces} command', () => {
4961
- test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
4962
- expect(${naming.variableName}Command).toBeDefined()
4963
- })
4964
- })
4965
- `.trim());
4966
- if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
4967
- }
4968
4891
  if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
4969
4892
  const implementationNaming = new UnknownFormatNaming(implementationType);
4970
4893
  const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
@@ -5414,13 +5337,54 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
5414
5337
  for (const implementation of unused)report(`${implementation.className} is no longer used in any environment.`);
5415
5338
  await wireNewImplementationDependencies(ownerFolder, wireFile, className, inMemoryRepositoryWiring(ownerFolder, unit, wireFile));
5416
5339
  };
5340
+ const helperImplementationTypes = ()=>[
5341
+ ...new Set(implementationKinds.flatMap((kind)=>[
5342
+ ...savedImplementations(kind, 'primary'),
5343
+ ...savedImplementations(kind, 'test'),
5344
+ ...systemImplementationChoices(kind).map(({ value })=>value)
5345
+ ]))
5346
+ ].filter((label)=>label !== crossContextImplementation);
5347
+ const validateName = (value)=>{
5348
+ const valid = NestedName.validate(value);
5349
+ if (true !== valid) return valid;
5350
+ const { folders, folderName } = new NestedName(value);
5351
+ return [
5352
+ ...folders,
5353
+ folderName
5354
+ ].every((part)=>kebabName.test(part)) ? true : 'Use lowercase kebab-case split by "/", e.g. mappers/social-network-type';
5355
+ };
5356
+ const scaffoldNewInfrastructureHelper = async (ownerFolder)=>{
5357
+ const types = helperImplementationTypes();
5358
+ if (!types.length) return void report('No implementation types yet: a helper belongs to one, so add an implementation first.');
5359
+ const name = new NestedName(await interaction_input({
5360
+ key: 'name',
5361
+ message: 'Name (folders split by "/"): ',
5362
+ validate: validateName
5363
+ }));
5364
+ const label = await interaction_select({
5365
+ key: 'implementationType',
5366
+ message: 'Implementation:',
5367
+ choices: types.map((value)=>({
5368
+ name: value,
5369
+ value
5370
+ }))
5371
+ });
5372
+ const fileName = name.folderName.startsWith(`${label}-`) ? name.folderName : `${label}-${name.folderName}`;
5373
+ const naming = new UnknownFormatNaming(fileName);
5374
+ const folder = ownerFolder.subitem([
5375
+ 'infrastructure',
5376
+ 'helpers',
5377
+ label,
5378
+ ...name.folders
5379
+ ]);
5380
+ folder.createFile(`${fileName}.ts`, `export const ${naming.variableName} = () => {}`);
5381
+ };
5417
5382
  const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
5418
5383
  const name = await interaction_input({
5419
5384
  key: 'name',
5420
5385
  message: 'Name: '
5421
5386
  });
5422
5387
  const naming = new UnknownFormatNaming(name);
5423
- const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
5424
5388
  const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
5425
5389
  const wiringFolder = boundedContextFolder.subitem([
5426
5390
  'wiring',
@@ -5435,23 +5399,6 @@ export class ${naming.ClassName}InfrastructureService {
5435
5399
 
5436
5400
  }
5437
5401
  `.trim());
5438
- if (scaffoldUnitTests) infrastructureServicesFolder.createFile(`${naming.fileName}-infrastructure-service.spec.ts`, `
5439
- import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
5440
- ${withWiring ? `import { type ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'
5441
- import { wire${naming.ClassName}InfrastructureService } from '../../wiring/infrastructure-services/wire-${naming.fileName}-infrastructure-service'` : `import { ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'`}
5442
-
5443
- let ${naming.variableName}InfrastructureService: ${naming.ClassName}InfrastructureService
5444
-
5445
- beforeEach(() => {
5446
- ${naming.variableName}InfrastructureService = ${withWiring ? `wire${naming.ClassName}InfrastructureService()` : `new ${naming.ClassName}InfrastructureService()`}
5447
- })
5448
-
5449
- describe('${naming.withSpaces}', () => {
5450
- test('can be ${withWiring ? 'wired' : 'created'}', () => {
5451
- expect(${naming.variableName}InfrastructureService).toBeDefined()
5452
- })
5453
- })
5454
- `.trim());
5455
5402
  if (withWiring) {
5456
5403
  const wireFile = wiringFolder.createFile(`wire-${naming.fileName}-infrastructure-service.ts`, `
5457
5404
  import { wireClass } from '@domain-first/wire'
@@ -5474,9 +5421,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
5474
5421
  key: 'name',
5475
5422
  message: 'Name: '
5476
5423
  });
5477
- const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
5478
5424
  const naming = new UnknownFormatNaming(queryName);
5479
- const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
5480
5425
  const { label: implementationType } = await promptImplementationType('Query infrastructure implementation type:', 'queries');
5481
5426
  let addTestImplementation = false;
5482
5427
  let testImplementationType = '';
@@ -5514,29 +5459,6 @@ export abstract class ${naming.ClassName}Query {
5514
5459
  export abstract class ${naming.ClassName}Query {
5515
5460
 
5516
5461
  }`.trim());
5517
- if (scaffoldUnitTests) {
5518
- const implementationNaming = new UnknownFormatNaming(implementationType);
5519
- const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
5520
- import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
5521
- ${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
5522
- import { wire${naming.ClassName}Query } from '../../wiring/queries/wire-${naming.fileName}-query'` : `import { ${implementationNaming.ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}-query'
5523
-
5524
- type ${naming.ClassName}Query = ${implementationNaming.ClassName}${naming.ClassName}Query`}
5525
-
5526
- let ${naming.variableName}Query: ${naming.ClassName}Query
5527
-
5528
- beforeEach(() => {
5529
- ${naming.variableName}Query = ${withWiring ? `wire${naming.ClassName}Query()` : `new ${implementationNaming.ClassName}${naming.ClassName}Query()`}
5530
- })
5531
-
5532
- describe('${naming.withSpaces} query', () => {
5533
- test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
5534
- expect(${naming.variableName}Query).toBeDefined()
5535
- })
5536
- })
5537
- `.trim());
5538
- if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
5539
- }
5540
5462
  if (config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
5541
5463
  const implementationNaming = new UnknownFormatNaming(implementationType);
5542
5464
  const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
@@ -5986,6 +5908,7 @@ const executeScaffold = async (request, owner)=>{
5986
5908
  ]).content.fileNames.includes(request.namespace)) throw new RequestError('TARGET_NOT_FOUND', `Unknown namespace: ${request.namespace}.`);
5987
5909
  if ('implementation' === request.operation && !findContracts(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No contracts in this context.');
5988
5910
  if (('move' === request.operation || 'delete' === request.operation) && !findBackendUnits(owner.path).length) throw new RequestError('TARGET_NOT_FOUND', 'No modules in this context.');
5911
+ if ('helper' === request.operation && !helperImplementationTypes().length) throw new RequestError('TARGET_NOT_FOUND', 'No implementation types yet: add an implementation first.');
5989
5912
  if ('wire-dependency' === request.operation && (!config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') || !findWiredModules(owner.path).length)) throw new RequestError('TARGET_NOT_FOUND', 'No wired modules in this context.');
5990
5913
  if ('endpoint' === request.operation) {
5991
5914
  if (!config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers-rest') || !findRestEndpointGenerator(new file_system_Folder(requireProject()).subitem([
@@ -6006,6 +5929,7 @@ const executeScaffold = async (request, owner)=>{
6006
5929
  'domain-service': ()=>scaffoldNewDomainService(owner),
6007
5930
  'application-service': ()=>scaffoldNewApplicationService(owner),
6008
5931
  'infrastructure-service': ()=>scaffoldNewInfrastructureService(owner),
5932
+ helper: ()=>scaffoldNewInfrastructureHelper(owner),
6009
5933
  'presentation-service': ()=>scaffoldNewPresentationService(owner),
6010
5934
  'use-case': ()=>scaffoldNewUseCase(owner),
6011
5935
  command: ()=>scaffoldNewCommand(owner),
@@ -6275,12 +6199,15 @@ const main = async ()=>{
6275
6199
  message: 'Infrastructure layer operation:',
6276
6200
  choices: [
6277
6201
  'New Service',
6202
+ 'New Helper',
6278
6203
  'New Implementation'
6279
6204
  ]
6280
6205
  });
6281
6206
  switch(operation){
6282
6207
  case 'New Implementation':
6283
6208
  return void await scaffoldNewImplementation(boundedContextFolder);
6209
+ case 'New Helper':
6210
+ return void await scaffoldNewInfrastructureHelper(boundedContextFolder);
6284
6211
  case 'New Service':
6285
6212
  return void await scaffoldNewInfrastructureService(boundedContextFolder);
6286
6213
  }
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { select as prompts_select } from "@inquirer/prompts";
3
3
  import { runCLI } from "./561.js";
4
4
  import { outdatedConfigMessage, ProjectRoot, ConfigFile, Folder } from "./780.js";
5
- import { scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewAggregateUseCase, scaffoldNewQuery, scaffoldNewInfrastructureService, scaffoldNewHandlersRestEndpoint, savePendingChanges, moveBackendUnitUseCase, scaffoldNewCommand, scaffoldNewPresentationService, deleteBackendUnitUseCase, scaffoldNewApplicationService, scaffoldNewUseCase, scaffoldNewImplementation, wireDependency, scaffoldNewBoundedContextUseCase, scaffoldNewDomainObject, scaffoldNewApplicationPort } from "./287.js";
5
+ import { scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewAggregateUseCase, scaffoldNewQuery, scaffoldNewInfrastructureService, scaffoldNewHandlersRestEndpoint, savePendingChanges, moveBackendUnitUseCase, scaffoldNewCommand, scaffoldNewPresentationService, scaffoldNewInfrastructureHelper, deleteBackendUnitUseCase, scaffoldNewApplicationService, scaffoldNewUseCase, scaffoldNewImplementation, wireDependency, scaffoldNewBoundedContextUseCase, scaffoldNewDomainObject, scaffoldNewApplicationPort } from "./287.js";
6
6
  const main = async ()=>{
7
7
  if (!ConfigFile.exists) {
8
8
  console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
@@ -131,12 +131,15 @@ const main = async ()=>{
131
131
  message: 'Infrastructure layer operation:',
132
132
  choices: [
133
133
  'New Service',
134
+ 'New Helper',
134
135
  'New Implementation'
135
136
  ]
136
137
  });
137
138
  switch(operation){
138
139
  case 'New Implementation':
139
140
  return void await scaffoldNewImplementation(boundedContextFolder);
141
+ case 'New Helper':
142
+ return void await scaffoldNewInfrastructureHelper(boundedContextFolder);
140
143
  case 'New Service':
141
144
  return void await scaffoldNewInfrastructureService(boundedContextFolder);
142
145
  }