@domain-first/project-structure 7.2.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -26
- package/dist/201.js +87 -338
- package/dist/287.js +1235 -575
- package/dist/561.js +519 -0
- package/dist/711.js +22 -0
- package/dist/870.js +438 -0
- package/dist/agent-cli.d.ts +379 -0
- package/dist/agent-cli.spec.d.ts +1 -0
- package/dist/agent-identifiers.d.ts +4 -0
- package/dist/agent-requests.d.ts +490 -0
- package/dist/config-file.d.ts +231 -26
- package/dist/config-file.spec.d.ts +1 -0
- package/dist/context-dependencies.d.ts +16 -0
- package/dist/dependency-rules.d.ts +17 -17
- package/dist/file-system.d.ts +10 -1
- package/dist/implementation-choices.d.ts +8 -0
- package/dist/implementation-choices.spec.d.ts +1 -0
- package/dist/implementation-options-schema.d.ts +14 -0
- package/dist/index.cjs +3645 -584
- package/dist/index.js +20 -7
- package/dist/init.cjs +717 -122
- package/dist/init.js +24 -12
- package/dist/integration.cjs +3783 -186
- package/dist/integration.js +29 -17
- package/dist/integrations/rest-endpoint-generator.d.ts +4 -2
- package/dist/integrations/storybook.d.ts +1 -0
- package/dist/interaction.d.ts +41 -0
- package/dist/lint.cjs +165 -41
- package/dist/lint.js +22 -7
- package/dist/module-move.d.ts +6 -2
- package/dist/next-app.d.ts +7 -0
- package/dist/react-module-move.d.ts +17 -2
- package/dist/react.cjs +5181 -421
- package/dist/react.js +72 -60
- package/dist/system-implementations.d.ts +6 -0
- package/dist/upgrade-steps.d.ts +81 -0
- package/dist/upgrade-steps.spec.d.ts +1 -0
- package/dist/upgrade.cjs +593 -0
- package/dist/upgrade.d.ts +2 -0
- package/dist/upgrade.js +235 -0
- package/dist/use-cases/add-integration.d.ts +16 -1
- package/dist/use-cases/cross-context-dependencies.spec.d.ts +1 -0
- package/dist/use-cases/initialize.d.ts +4 -4
- package/dist/use-cases/initialize.spec.d.ts +1 -0
- package/dist/use-cases/prompt-implementation-type.d.ts +20 -0
- package/dist/use-cases/scaffold-react-page.d.ts +3 -1
- package/dist/wire-branches.d.ts +26 -0
- package/dist/wiring.d.ts +3 -2
- package/package.json +3 -2
- package/skills/df-ps-implement/SKILL.md +9 -8
- package/skills/df-ps-plan-feature/SKILL.md +8 -7
- package/skills/df-ps-react/SKILL.md +14 -8
- package/skills/df-ps-react/references/generators.md +6 -2
- package/skills/df-ps-scaffold/SKILL.md +28 -17
- package/skills/df-ps-scaffold/references/agent-mode.md +72 -0
- package/skills/df-ps-scaffold/references/agent-operations.md +155 -0
- package/skills/df-ps-scaffold/references/choosing-components.md +13 -13
- package/skills/df-ps-scaffold/references/generators.md +20 -3
- package/skills/df-ps-scaffold/references/units/aggregate.md +4 -3
- package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
- package/skills/df-ps-scaffold/references/units/command-query.md +12 -12
- package/skills/df-ps-scaffold/references/units/implementation.md +2 -2
- package/skills/df-ps-scaffold/references/units/move-or-rename.md +1 -1
- package/skills/df-ps-scaffold/references/units/port.md +7 -4
- package/skills/df-ps-scaffold/references/units/use-case.md +1 -1
- 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
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))
|
|
412
|
-
const
|
|
413
|
-
if (
|
|
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 =
|
|
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
|
|
502
|
-
|
|
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
|
-
|
|
666
|
-
|
|
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 {
|
|
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 };
|