@domain-first/project-structure 7.2.0 → 8.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 (64) hide show
  1. package/README.md +124 -25
  2. package/dist/201.js +87 -338
  3. package/dist/287.js +1183 -568
  4. package/dist/561.js +518 -0
  5. package/dist/711.js +22 -0
  6. package/dist/870.js +438 -0
  7. package/dist/agent-cli.d.ts +378 -0
  8. package/dist/agent-cli.spec.d.ts +1 -0
  9. package/dist/agent-identifiers.d.ts +4 -0
  10. package/dist/agent-requests.d.ts +488 -0
  11. package/dist/config-file.d.ts +231 -26
  12. package/dist/config-file.spec.d.ts +1 -0
  13. package/dist/context-dependencies.d.ts +16 -0
  14. package/dist/dependency-rules.d.ts +17 -17
  15. package/dist/file-system.d.ts +10 -1
  16. package/dist/implementation-choices.d.ts +8 -0
  17. package/dist/implementation-choices.spec.d.ts +1 -0
  18. package/dist/implementation-options-schema.d.ts +14 -0
  19. package/dist/index.cjs +3598 -583
  20. package/dist/index.js +20 -7
  21. package/dist/init.cjs +717 -122
  22. package/dist/init.js +24 -12
  23. package/dist/integration.cjs +3737 -186
  24. package/dist/integration.js +29 -17
  25. package/dist/integrations/rest-endpoint-generator.d.ts +4 -2
  26. package/dist/integrations/storybook.d.ts +1 -0
  27. package/dist/interaction.d.ts +41 -0
  28. package/dist/lint.cjs +165 -41
  29. package/dist/lint.js +22 -7
  30. package/dist/next-app.d.ts +7 -0
  31. package/dist/react.cjs +5128 -414
  32. package/dist/react.js +72 -60
  33. package/dist/system-implementations.d.ts +6 -0
  34. package/dist/upgrade-steps.d.ts +81 -0
  35. package/dist/upgrade-steps.spec.d.ts +1 -0
  36. package/dist/upgrade.cjs +593 -0
  37. package/dist/upgrade.d.ts +2 -0
  38. package/dist/upgrade.js +235 -0
  39. package/dist/use-cases/add-integration.d.ts +16 -1
  40. package/dist/use-cases/cross-context-dependencies.spec.d.ts +1 -0
  41. package/dist/use-cases/initialize.d.ts +4 -4
  42. package/dist/use-cases/initialize.spec.d.ts +1 -0
  43. package/dist/use-cases/prompt-implementation-type.d.ts +20 -0
  44. package/dist/use-cases/scaffold-react-page.d.ts +3 -1
  45. package/dist/wire-branches.d.ts +26 -0
  46. package/dist/wiring.d.ts +3 -2
  47. package/package.json +3 -2
  48. package/skills/df-ps-implement/SKILL.md +9 -8
  49. package/skills/df-ps-plan-feature/SKILL.md +8 -7
  50. package/skills/df-ps-react/SKILL.md +13 -7
  51. package/skills/df-ps-react/references/generators.md +6 -2
  52. package/skills/df-ps-scaffold/SKILL.md +28 -17
  53. package/skills/df-ps-scaffold/references/agent-mode.md +72 -0
  54. package/skills/df-ps-scaffold/references/agent-operations.md +155 -0
  55. package/skills/df-ps-scaffold/references/choosing-components.md +13 -13
  56. package/skills/df-ps-scaffold/references/generators.md +20 -3
  57. package/skills/df-ps-scaffold/references/units/aggregate.md +4 -3
  58. package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
  59. package/skills/df-ps-scaffold/references/units/command-query.md +12 -12
  60. package/skills/df-ps-scaffold/references/units/implementation.md +2 -2
  61. package/skills/df-ps-scaffold/references/units/move-or-rename.md +1 -1
  62. package/skills/df-ps-scaffold/references/units/port.md +7 -4
  63. package/skills/df-ps-scaffold/references/units/use-case.md +1 -1
  64. package/skills/df-ps-scaffold/scripts/drive.mjs +9 -1
package/dist/201.js CHANGED
@@ -1,332 +1,50 @@
1
- import node_path from "node:path";
2
- import zod from "zod";
3
1
  import node_fs from "node:fs";
2
+ import node_path from "node:path";
4
3
  import { createRequire } from "node:module";
5
- const moduleKinds = [
6
- 'repositories',
7
- 'domain-services',
8
- 'application-ports',
9
- 'application-services',
10
- 'use-cases',
11
- 'commands',
12
- 'queries',
13
- 'infrastructure-services',
14
- 'presentation-services'
15
- ];
16
- const domain = [
17
- 'repositories',
18
- 'domain-services'
19
- ];
20
- const commandsAndQueries = [
21
- 'commands',
22
- 'queries'
23
- ];
24
- const infrastructure = [
25
- ...domain,
26
- 'application-ports',
27
- 'infrastructure-services'
28
- ];
29
- const defaultDependencies = {
30
- 'domain-services': [
31
- 'domain-services'
32
- ],
33
- repositories: [
34
- 'domain-services',
35
- 'application-ports',
36
- 'infrastructure-services'
37
- ],
38
- 'application-ports': infrastructure,
39
- 'application-services': [
40
- ...domain,
41
- 'application-ports',
42
- ...commandsAndQueries
43
- ],
44
- 'use-cases': [
45
- ...domain,
46
- 'application-ports',
47
- 'application-services',
48
- ...commandsAndQueries
49
- ],
50
- commands: [
51
- 'infrastructure-services'
52
- ],
53
- queries: [
54
- 'infrastructure-services'
55
- ],
56
- 'infrastructure-services': infrastructure,
57
- 'presentation-services': [
58
- 'application-ports',
59
- 'application-services',
60
- 'use-cases',
61
- ...commandsAndQueries,
62
- 'presentation-services'
63
- ]
64
- };
65
- const kindSchema = zod["enum"](moduleKinds);
66
- const dependencyRulesSchema = zod.partialRecord(kindSchema, zod.union([
67
- zod.array(kindSchema),
68
- zod.object({
69
- add: zod.array(kindSchema).optional(),
70
- remove: zod.array(kindSchema).optional()
71
- })
72
- ]));
73
- const resolveDependencyRules = (config = {})=>{
74
- const entries = moduleKinds.map((kind)=>{
75
- const override = config[kind];
76
- if (Array.isArray(override)) return [
77
- kind,
78
- new Set(override)
79
- ];
80
- const kinds = new Set([
81
- ...defaultDependencies[kind],
82
- ...override?.add ?? []
83
- ]);
84
- for (const removed of override?.remove ?? [])kinds.delete(removed);
85
- return [
86
- kind,
87
- kinds
88
- ];
89
- });
90
- return Object.fromEntries(entries);
91
- };
92
- const defaultDependencyRules = resolveDependencyRules();
93
- const isModuleKind = (value)=>moduleKinds.includes(value);
94
- const wiredModuleKind = (wiringKind)=>isModuleKind(wiringKind) ? wiringKind : void 0;
95
- const fileModuleKind = (segments)=>{
96
- const [layer, folder] = segments;
97
- const file = segments.at(-1) ?? '';
98
- if (/^index(\.tsx?)?$/.test(file)) return;
99
- if ('domain' === layer) {
100
- if ('services' === folder) return 'domain-services';
101
- return 'aggregates' === folder && /-repository(\.tsx?)?$/.test(file) ? 'repositories' : void 0;
102
- }
103
- if ('application' === layer) return ({
104
- commands: 'commands',
105
- queries: 'queries',
106
- ports: 'application-ports',
107
- services: 'application-services',
108
- 'use-cases': 'use-cases'
109
- })[folder];
110
- if ('infrastructure' === layer) return ({
111
- repositories: 'repositories',
112
- commands: 'commands',
113
- queries: 'queries',
114
- 'application-adapters': 'application-ports',
115
- services: 'infrastructure-services'
116
- })[folder];
117
- return 'presentation' === layer && 'services' === folder ? 'presentation-services' : void 0;
118
- };
119
- const pendingFiles = new Map();
120
- const pendingFolders = new Set();
121
- const pendingMoves = new Map();
122
- const pendingDeletions = new Map();
123
- const filesToOverwrite = ()=>[
124
- ...pendingFiles
125
- ].filter(([filePath, { replacesFile }])=>replacesFile && node_fs.existsSync(filePath)).map(([filePath])=>filePath);
126
- const withoutOverwrites = (generate)=>{
127
- const before = new Map(pendingFiles);
128
- const result = generate();
129
- for (const [filePath, change] of pendingFiles){
130
- if (before.get(filePath) === change || !change.replacesFile || !node_fs.existsSync(filePath)) continue;
131
- const previous = before.get(filePath);
132
- if (previous) pendingFiles.set(filePath, previous);
133
- else pendingFiles.delete(filePath);
134
- }
135
- return result;
4
+ import { defaultDependencyRules, configuredDependencyRules, wiredModuleKind, File } from "./870.js";
5
+ const crossContextImplementation = 'cross-context';
6
+ const hasNeighboringBoundedContext = (ownerPath)=>{
7
+ const contextsPath = node_path.dirname(ownerPath);
8
+ return 'bounded-contexts' === node_path.basename(contextsPath) && node_fs.existsSync(contextsPath) && node_fs.readdirSync(contextsPath, {
9
+ withFileTypes: true
10
+ }).some((entry)=>entry.isDirectory() && entry.name !== node_path.basename(ownerPath));
11
+ };
12
+ const boundedContextLocation = (file)=>{
13
+ const parts = node_path.resolve(file).split(node_path.sep);
14
+ const index = parts.lastIndexOf('bounded-contexts');
15
+ if (-1 === index || parts.length < index + 3) return;
16
+ return {
17
+ root: parts.slice(0, index).join(node_path.sep),
18
+ name: parts[index + 1],
19
+ segments: parts.slice(index + 2)
20
+ };
136
21
  };
137
- const discardPendingChanges = ()=>{
138
- pendingFolders.clear();
139
- pendingFiles.clear();
140
- pendingMoves.clear();
141
- pendingDeletions.clear();
142
- };
143
- const removeEmptyFolders = (folderPath, stopAt)=>{
144
- let current = folderPath;
145
- while(current.startsWith(`${stopAt}${node_path.sep}`) && node_fs.existsSync(current) && !node_fs.readdirSync(current).length){
146
- node_fs.rmdirSync(current);
147
- current = node_path.dirname(current);
148
- }
22
+ const isCrossContextImplementation = (file)=>{
23
+ const location = boundedContextLocation(file);
24
+ const [layer, kind, label] = location?.segments ?? [];
25
+ return 'infrastructure' === layer && 'application-adapters' === kind && label === crossContextImplementation;
26
+ };
27
+ const crossContextImportAllowed = (from, to)=>{
28
+ const source = boundedContextLocation(from);
29
+ const target = boundedContextLocation(to);
30
+ if (!source || !target || source.name === target.name) return;
31
+ if (source.root !== target.root) return false;
32
+ const [layer, kind] = source.segments;
33
+ const [targetLayer, targetKind] = target.segments;
34
+ if ('wiring' === targetLayer && !node_path.basename(to).startsWith('wire-')) return false;
35
+ if (/\.(spec|test)\.[^.]+$/.test(to)) return false;
36
+ const suffix = {
37
+ queries: '-query',
38
+ commands: '-command',
39
+ 'use-cases': '-use-case'
40
+ }[targetKind];
41
+ if (!suffix || !new RegExp(`${suffix}(\\.(?:c|m)?[jt]sx?)?$`).test(to)) return false;
42
+ return [
43
+ 'queries',
44
+ 'commands',
45
+ 'use-cases'
46
+ ].includes(targetKind) && (isCrossContextImplementation(from) && 'application' === targetLayer || 'wiring' === layer && 'application-ports' === kind && 'wiring' === targetLayer);
149
47
  };
150
- const writePendingChanges = ()=>{
151
- for (const folderPath of pendingFolders)node_fs.mkdirSync(folderPath, {
152
- recursive: true
153
- });
154
- for (const [filePath, { content }] of pendingFiles){
155
- node_fs.mkdirSync(node_path.dirname(filePath), {
156
- recursive: true
157
- });
158
- node_fs.writeFileSync(filePath, content, 'utf8');
159
- }
160
- for (const [targetPath, { sourcePath }] of pendingMoves){
161
- node_fs.mkdirSync(node_path.dirname(targetPath), {
162
- recursive: true
163
- });
164
- node_fs.renameSync(sourcePath, targetPath);
165
- }
166
- for (const filePath of pendingDeletions.keys())node_fs.rmSync(filePath, {
167
- force: true
168
- });
169
- for (const [filePath, stopAt] of pendingDeletions)removeEmptyFolders(node_path.dirname(filePath), stopAt);
170
- for (const { sourcePath, stopAt } of pendingMoves.values())removeEmptyFolders(node_path.dirname(sourcePath), stopAt);
171
- discardPendingChanges();
172
- };
173
- class FileSystemItem {
174
- path;
175
- constructor(path){
176
- this.path = path;
177
- }
178
- subitem = (relativePath)=>new this.constructor(node_path.resolve(this.path, ...relativePath));
179
- get exists() {
180
- return node_fs.existsSync(this.path);
181
- }
182
- }
183
- class Folder extends FileSystemItem {
184
- createIfNotExisted = ()=>{
185
- pendingFolders.add(this.path);
186
- };
187
- get content() {
188
- if (!this.exists) return {
189
- subfolderNames: [],
190
- fileNames: []
191
- };
192
- const content = node_fs.readdirSync(this.path, {
193
- withFileTypes: true
194
- });
195
- return {
196
- subfolderNames: content.filter((x)=>x.isDirectory()).map((x)=>x.name),
197
- fileNames: content.filter((x)=>!x.isDirectory()).map((x)=>node_path.parse(x.name).name)
198
- };
199
- }
200
- get name() {
201
- return node_path.basename(this.path);
202
- }
203
- createFile = (name, content)=>{
204
- this.createIfNotExisted();
205
- const file = new File(this.path).subitem([
206
- name
207
- ]);
208
- file.data = content;
209
- return file;
210
- };
211
- file = (name)=>{
212
- this.createIfNotExisted();
213
- const file = new File(this.path).subitem([
214
- name
215
- ]);
216
- return file;
217
- };
218
- }
219
- class File extends FileSystemItem {
220
- get exists() {
221
- return pendingFiles.has(this.path) || pendingMoves.has(this.path) || node_fs.existsSync(this.path) && !pendingDeletions.has(this.path);
222
- }
223
- delete = (stopAt)=>{
224
- pendingDeletions.set(this.path, stopAt);
225
- };
226
- moveTo = (targetPath, stopAt)=>{
227
- pendingMoves.set(targetPath, {
228
- sourcePath: this.path,
229
- stopAt
230
- });
231
- };
232
- get data() {
233
- const pendingFile = pendingFiles.get(this.path);
234
- if (pendingFile) return pendingFile.content;
235
- if (!this.exists) throw new Error('File does not exist');
236
- return node_fs.readFileSync(this.path, 'utf-8');
237
- }
238
- set data(content) {
239
- pendingFiles.set(this.path, {
240
- content,
241
- replacesFile: true
242
- });
243
- }
244
- update = (content)=>{
245
- pendingFiles.set(this.path, {
246
- content,
247
- replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
248
- });
249
- };
250
- addLine = (newLine, separator = '\n')=>{
251
- const content = this.exists ? this.data : '';
252
- pendingFiles.set(this.path, {
253
- content: [
254
- content.trim(),
255
- newLine.trim()
256
- ].filter((x)=>!!x).join(separator),
257
- replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
258
- });
259
- };
260
- addLineIfMissing = (newLine, separator = '\n')=>{
261
- const alreadyAdded = this.exists && this.data.split('\n').some((line)=>line.trim() === newLine.trim());
262
- if (!alreadyAdded) this.addLine(newLine, separator);
263
- };
264
- }
265
- class ProjectRoot {
266
- path;
267
- constructor(){
268
- let dir = process.cwd();
269
- while(dir !== node_path.parse(dir).root){
270
- if (node_fs.existsSync(node_path.join(dir, 'package.json'))) {
271
- this.path = dir;
272
- return;
273
- }
274
- dir = node_path.dirname(dir);
275
- }
276
- throw new Error('No package.json was found');
277
- }
278
- }
279
- const lintChecks = [
280
- 'context-isolation',
281
- 'shared-kernel',
282
- 'layers',
283
- 'dependencies',
284
- 'react',
285
- 'clock'
286
- ];
287
- const configFileName = 'domain-first.project-structure.config.json';
288
- const configSchema = zod.object({
289
- rootFolder: zod.string(),
290
- domainFirstPackages: zod.array(zod["enum"]([
291
- '@domain-first/types',
292
- '@domain-first/errors',
293
- '@domain-first/handlers',
294
- '@domain-first/wire',
295
- '@domain-first/handlers-rest'
296
- ])),
297
- defaultPersistenceLayerImplementation: zod.string(),
298
- withInMemoryDb: zod.boolean().optional(),
299
- useReact: zod.boolean(),
300
- storybookFramework: zod.string().optional(),
301
- testingLibrary: zod.string().optional(),
302
- rules: zod.object({
303
- dependencies: dependencyRulesSchema.optional(),
304
- lint: zod.partialRecord(zod["enum"](lintChecks), zod.boolean()).optional()
305
- }).optional()
306
- });
307
- class ConfigFile {
308
- data;
309
- constructor(){
310
- const filePath = ConfigFile.path;
311
- const file = new File(filePath);
312
- const configObject = JSON.parse(file.data);
313
- this.data = configSchema.parse(configObject);
314
- }
315
- static get Instance() {
316
- return new ConfigFile();
317
- }
318
- static get path() {
319
- const { path: root } = new ProjectRoot();
320
- return node_path.resolve(root, configFileName);
321
- }
322
- static get exists() {
323
- return new File(ConfigFile.path).exists;
324
- }
325
- static write = (config)=>{
326
- new File(ConfigFile.path).data = JSON.stringify(config, null, '\t');
327
- };
328
- }
329
- const configuredDependencyRules = ()=>resolveDependencyRules(ConfigFile.exists ? ConfigFile.Instance.data.rules?.dependencies : void 0);
330
48
  class UnknownFormatNaming {
331
49
  rawSource;
332
50
  camelCase;
@@ -406,11 +124,15 @@ const layerOf = (file, contextPath)=>{
406
124
  const [firstSegment] = node_path.relative(contextPath, file).split(node_path.sep);
407
125
  return wiring_layers.find((layer)=>layer === firstSegment);
408
126
  };
409
- const namedImports = (source, fromFile)=>{
127
+ const withoutScriptExtension = (file)=>file.replace(/\.(?:c|m)?[jt]s$/, '');
128
+ const namedImportFiles = (source, fromFile, resolve = (specifier, file)=>specifier.startsWith('.') ? node_path.resolve(node_path.dirname(file), specifier) : void 0)=>{
410
129
  const result = new Map();
411
- for (const [, names, importPath] of source.matchAll(/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g))for (const name of names.split(',')){
412
- const cleanName = name.replace(/^\s*type\s+/, '').trim();
413
- if (cleanName) result.set(cleanName, `${node_path.resolve(node_path.dirname(fromFile), importPath)}.ts`);
130
+ for (const [, names, importPath] of source.matchAll(/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g)){
131
+ const target = resolve(importPath, fromFile);
132
+ if (target) for (const name of names.split(',')){
133
+ const cleanName = name.replace(/^\s*type\s+/, '').trim().split(/\s+as\s+/).at(-1);
134
+ if (cleanName) result.set(cleanName, `${withoutScriptExtension(target)}.ts`);
135
+ }
414
136
  }
415
137
  return result;
416
138
  };
@@ -440,7 +162,7 @@ const readWiredModule = (wireFile, contextPath)=>{
440
162
  const exportMatch = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*`).exec(source);
441
163
  if (!exportMatch) return;
442
164
  const branched = source.slice(exportMatch.index + exportMatch[0].length).startsWith('envBranchedWire(');
443
- const imports = namedImports(source, wireFile);
165
+ const imports = namedImportFiles(source, wireFile);
444
166
  const implementations = wiredClassNames(source, wireName, exportMatch.index + exportMatch[0].length, branched).flatMap((className)=>{
445
167
  const file = imports.get(className);
446
168
  return file ? [
@@ -492,14 +214,19 @@ const moduleKindOf = (module)=>wiredModuleKind(module.kind);
492
214
  const layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
493
215
  const implementationType = (consumer, implementation)=>consumer.branched ? node_path.basename(node_path.dirname(implementation.file)) : void 0;
494
216
  const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${node_path.basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
495
- const canDependOn = (consumer, candidate, rules = defaultDependencyRules)=>{
217
+ const canDependOn = (consumer, candidate, rules = defaultDependencyRules, implementation = consumer.implementations[0])=>{
218
+ const crossContext = crossContextImportAllowed(consumer.wireFile, candidate.wireFile);
219
+ if (void 0 !== crossContext) return crossContext && 'infrastructure' === consumer.implementationsLayer && 'application' === candidate.layer && !!implementation && true === crossContextImportAllowed(implementation.file, candidate.typeFile);
496
220
  const consumerKind = moduleKindOf(consumer);
497
221
  const candidateKind = moduleKindOf(candidate);
498
222
  return consumerKind && candidateKind ? rules[consumerKind].has(candidateKind) : layerRule(consumer, candidate);
499
223
  };
500
224
  const availableDependencies = (consumer, implementation, candidates, rules = configuredDependencyRules())=>{
501
- const wired = wiredDependencyNames(new File(consumer.wireFile).data, implementation.className);
502
- return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate, rules) && !wired.includes(candidate.wireName));
225
+ const source = new File(consumer.wireFile).data;
226
+ const imported = namedImportFiles(source, consumer.wireFile);
227
+ const wired = wiredDependencyNames(source, implementation.className);
228
+ const wiredFiles = new Set(wired.map((name)=>imported.get(name)).filter(Boolean));
229
+ return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate, rules, implementation) && !wiredFiles.has(candidate.wireFile) && !(wired.includes(candidate.wireName) && !imported.has(candidate.wireName)));
503
230
  };
504
231
  const relativeImport = (fromFile, toFile)=>{
505
232
  const relativePath = node_path.relative(node_path.dirname(fromFile), toFile).replace(/\.ts$/, '').split(node_path.sep).join('/');
@@ -655,15 +382,37 @@ const addWireDependencies = (source, className, wireNames)=>{
655
382
  return source.slice(0, openIndex + 1) + appendItems(source.slice(openIndex + 1, closeIndex), wireNames) + source.slice(closeIndex);
656
383
  };
657
384
  const parameterName = (typeName)=>typeName.substring(0, 1).toLowerCase() + typeName.substring(1);
385
+ const dependencyBinding = (source, fromFile, targetFile, originalName, preferredName)=>{
386
+ const existing = [
387
+ ...namedImportFiles(source, fromFile)
388
+ ].find(([, file])=>file === targetFile);
389
+ if (existing) return existing[0];
390
+ let name = preferredName;
391
+ let suffix = 2;
392
+ while(new RegExp(`\\b${name}\\b`).test(codeOnly(source)))name = `${preferredName}${suffix++}`;
393
+ return preferredName === originalName ? originalName : name;
394
+ };
395
+ const importedAs = (name, local)=>name === local ? name : `${name} as ${local}`;
658
396
  const wireDependencies = (consumer, implementation, dependencies)=>{
659
397
  const wireFile = new File(consumer.wireFile);
660
398
  let wireSource = wireFile.data;
661
- for (const dependency of dependencies)wireSource = addImport(wireSource, `import { ${dependency.wireName} } from '${relativeImport(consumer.wireFile, dependency.wireFile)}'`);
662
- wireFile.update(addWireDependencies(wireSource, implementation.className, dependencies.map((x)=>x.wireName)));
663
399
  const classFile = new File(implementation.file);
664
400
  let classSource = classFile.data;
665
- for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${relativeImport(implementation.file, dependency.typeFile)}'`);
666
- classFile.update(addConstructorParameters(classSource, implementation.className, dependencies.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
401
+ const bindings = dependencies.map((dependency)=>{
402
+ const crossContext = crossContextImportAllowed(consumer.wireFile, dependency.wireFile);
403
+ const context = crossContext ? boundedContextLocation(dependency.wireFile) : void 0;
404
+ const prefix = context ? new UnknownFormatNaming(context.name).ClassName : '';
405
+ const wireName = dependencyBinding(wireSource, consumer.wireFile, dependency.wireFile, dependency.wireName, context ? `wire${prefix}${dependency.typeName}` : dependency.wireName);
406
+ const typeName = dependencyBinding(classSource, implementation.file, dependency.typeFile, dependency.typeName, `${prefix}${dependency.typeName}`);
407
+ wireSource = addImport(wireSource, `import { ${importedAs(dependency.wireName, wireName)} } from '${relativeImport(consumer.wireFile, dependency.wireFile)}'`);
408
+ classSource = addImport(classSource, `import type { ${importedAs(dependency.typeName, typeName)} } from '${relativeImport(implementation.file, dependency.typeFile)}'`);
409
+ return {
410
+ wireName,
411
+ typeName
412
+ };
413
+ });
414
+ wireFile.update(addWireDependencies(wireSource, implementation.className, bindings.map((x)=>x.wireName)));
415
+ classFile.update(addConstructorParameters(classSource, implementation.className, bindings.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
667
416
  };
668
417
  const branchesRange = (source, wireName)=>{
669
418
  const match = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*envBranchedWire\\(\\s*\\{`).exec(codeOnly(source));
@@ -750,4 +499,4 @@ const compilerOption = (configFile, name, seen = new Set())=>{
750
499
  if (void 0 !== value) return value;
751
500
  }
752
501
  };
753
- export { ConfigFile, File, Folder, ProjectRoot, UnknownFormatNaming, addBranchedImplementation, addClassMember, addConstructorParameters, addImport, addWireDependencies, availableDependencies, canDependOn, compilerOption, configuredDependencyRules, defaultDependencyRules, discardPendingChanges, fileModuleKind, filesToOverwrite, findWiredModules, implementationType, isSuggestedFor, moduleKindOf, readWiredModule, relativeImport, stripJsonComments, wireBranches, wireDependencies, wiredDependencyNames, withoutOverwrites, writePendingChanges };
502
+ export { UnknownFormatNaming, addBranchedImplementation, addClassMember, addConstructorParameters, addImport, addWireDependencies, availableDependencies, boundedContextLocation, canDependOn, compilerOption, crossContextImplementation, crossContextImportAllowed, findWiredModules, hasNeighboringBoundedContext, implementationType, isCrossContextImplementation, isSuggestedFor, moduleKindOf, namedImportFiles, readWiredModule, relativeImport, stripJsonComments, wireBranches, wireDependencies, wiredDependencyNames };