@domain-first/project-structure 4.0.0 → 4.2.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 +27 -2
- package/dist/201.js +699 -0
- package/dist/config-file.d.ts +71 -0
- package/dist/dependency-rules.d.ts +82 -0
- package/dist/dependency-rules.spec.d.ts +1 -0
- package/dist/index.cjs +122 -17
- package/dist/index.js +19 -584
- package/dist/lint.cjs +864 -0
- package/dist/lint.d.ts +2 -0
- package/dist/lint.js +296 -0
- package/dist/project-lint.d.ts +27 -0
- package/dist/project-lint.spec.d.ts +1 -0
- package/dist/wiring.d.ts +10 -5
- package/package.json +3 -2
- package/skills/df-ps-implement/SKILL.md +12 -3
- package/skills/df-ps-scaffold/SKILL.md +3 -3
- package/skills/df-ps-scaffold/references/choosing-components.md +3 -3
- package/skills/df-ps-scaffold/references/generators.md +1 -1
- package/skills/df-ps-implement/scripts/check-context-isolation.mjs +0 -204
package/dist/config-file.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* `df-lint` checks that `rules.lint` can turn off.
|
|
4
|
+
*/
|
|
5
|
+
export declare const lintChecks: readonly ["context-isolation", "shared-layer", "layers", "dependencies", "react", "clock"];
|
|
6
|
+
export type LintCheck = (typeof lintChecks)[number];
|
|
2
7
|
declare const configSchema: z.ZodObject<{
|
|
3
8
|
rootFolder: z.ZodString;
|
|
4
9
|
domainFirstPackages: z.ZodArray<z.ZodEnum<{
|
|
@@ -13,6 +18,68 @@ declare const configSchema: z.ZodObject<{
|
|
|
13
18
|
useReact: z.ZodBoolean;
|
|
14
19
|
storybookFramework: z.ZodOptional<z.ZodString>;
|
|
15
20
|
testingLibrary: z.ZodOptional<z.ZodString>;
|
|
21
|
+
rules: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
dependencies: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
|
|
23
|
+
repositories: "repositories";
|
|
24
|
+
"domain-services": "domain-services";
|
|
25
|
+
"application-ports": "application-ports";
|
|
26
|
+
"application-services": "application-services";
|
|
27
|
+
"use-cases": "use-cases";
|
|
28
|
+
"execution-commands": "execution-commands";
|
|
29
|
+
"execution-queries": "execution-queries";
|
|
30
|
+
"orchestration-commands": "orchestration-commands";
|
|
31
|
+
"orchestration-queries": "orchestration-queries";
|
|
32
|
+
"infrastructure-services": "infrastructure-services";
|
|
33
|
+
"presentation-services": "presentation-services";
|
|
34
|
+
}> & z.core.$partial, z.ZodUnion<readonly [z.ZodArray<z.ZodEnum<{
|
|
35
|
+
repositories: "repositories";
|
|
36
|
+
"domain-services": "domain-services";
|
|
37
|
+
"application-ports": "application-ports";
|
|
38
|
+
"application-services": "application-services";
|
|
39
|
+
"use-cases": "use-cases";
|
|
40
|
+
"execution-commands": "execution-commands";
|
|
41
|
+
"execution-queries": "execution-queries";
|
|
42
|
+
"orchestration-commands": "orchestration-commands";
|
|
43
|
+
"orchestration-queries": "orchestration-queries";
|
|
44
|
+
"infrastructure-services": "infrastructure-services";
|
|
45
|
+
"presentation-services": "presentation-services";
|
|
46
|
+
}>>, z.ZodObject<{
|
|
47
|
+
add: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
48
|
+
repositories: "repositories";
|
|
49
|
+
"domain-services": "domain-services";
|
|
50
|
+
"application-ports": "application-ports";
|
|
51
|
+
"application-services": "application-services";
|
|
52
|
+
"use-cases": "use-cases";
|
|
53
|
+
"execution-commands": "execution-commands";
|
|
54
|
+
"execution-queries": "execution-queries";
|
|
55
|
+
"orchestration-commands": "orchestration-commands";
|
|
56
|
+
"orchestration-queries": "orchestration-queries";
|
|
57
|
+
"infrastructure-services": "infrastructure-services";
|
|
58
|
+
"presentation-services": "presentation-services";
|
|
59
|
+
}>>>;
|
|
60
|
+
remove: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
61
|
+
repositories: "repositories";
|
|
62
|
+
"domain-services": "domain-services";
|
|
63
|
+
"application-ports": "application-ports";
|
|
64
|
+
"application-services": "application-services";
|
|
65
|
+
"use-cases": "use-cases";
|
|
66
|
+
"execution-commands": "execution-commands";
|
|
67
|
+
"execution-queries": "execution-queries";
|
|
68
|
+
"orchestration-commands": "orchestration-commands";
|
|
69
|
+
"orchestration-queries": "orchestration-queries";
|
|
70
|
+
"infrastructure-services": "infrastructure-services";
|
|
71
|
+
"presentation-services": "presentation-services";
|
|
72
|
+
}>>>;
|
|
73
|
+
}, z.core.$strip>]>>>;
|
|
74
|
+
lint: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
|
|
75
|
+
"context-isolation": "context-isolation";
|
|
76
|
+
"shared-layer": "shared-layer";
|
|
77
|
+
layers: "layers";
|
|
78
|
+
dependencies: "dependencies";
|
|
79
|
+
react: "react";
|
|
80
|
+
clock: "clock";
|
|
81
|
+
}> & z.core.$partial, z.ZodBoolean>>;
|
|
82
|
+
}, z.core.$strip>>;
|
|
16
83
|
}, z.core.$strip>;
|
|
17
84
|
export declare class ConfigFile {
|
|
18
85
|
readonly data: z.infer<typeof configSchema>;
|
|
@@ -22,4 +89,8 @@ export declare class ConfigFile {
|
|
|
22
89
|
static get exists(): boolean;
|
|
23
90
|
static write: (config: z.infer<typeof configSchema>) => void;
|
|
24
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The dependency rules: the defaults with the config's `rules.dependencies`.
|
|
94
|
+
*/
|
|
95
|
+
export declare const configuredDependencyRules: () => import("./dependency-rules").DependencyRules;
|
|
25
96
|
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Kinds of modules the dependency rules are written in: the folders
|
|
4
|
+
* under `wiring/`, with commands and queries split by mode.
|
|
5
|
+
*/
|
|
6
|
+
export declare const moduleKinds: readonly ["repositories", "domain-services", "application-ports", "application-services", "use-cases", "execution-commands", "execution-queries", "orchestration-commands", "orchestration-queries", "infrastructure-services", "presentation-services"];
|
|
7
|
+
export type ModuleKind = (typeof moduleKinds)[number];
|
|
8
|
+
export type DependencyRules = Record<ModuleKind, ReadonlySet<ModuleKind>>;
|
|
9
|
+
/**
|
|
10
|
+
* What each kind of module may depend on. Repositories, execution
|
|
11
|
+
* commands and queries, and ports are their implementations here.
|
|
12
|
+
*/
|
|
13
|
+
export declare const defaultDependencies: Record<ModuleKind, ModuleKind[]>;
|
|
14
|
+
/**
|
|
15
|
+
* A list replaces the default one; `add` and `remove` change it.
|
|
16
|
+
*/
|
|
17
|
+
export declare const dependencyRulesSchema: z.ZodRecord<z.ZodEnum<{
|
|
18
|
+
repositories: "repositories";
|
|
19
|
+
"domain-services": "domain-services";
|
|
20
|
+
"application-ports": "application-ports";
|
|
21
|
+
"application-services": "application-services";
|
|
22
|
+
"use-cases": "use-cases";
|
|
23
|
+
"execution-commands": "execution-commands";
|
|
24
|
+
"execution-queries": "execution-queries";
|
|
25
|
+
"orchestration-commands": "orchestration-commands";
|
|
26
|
+
"orchestration-queries": "orchestration-queries";
|
|
27
|
+
"infrastructure-services": "infrastructure-services";
|
|
28
|
+
"presentation-services": "presentation-services";
|
|
29
|
+
}> & z.core.$partial, z.ZodUnion<readonly [z.ZodArray<z.ZodEnum<{
|
|
30
|
+
repositories: "repositories";
|
|
31
|
+
"domain-services": "domain-services";
|
|
32
|
+
"application-ports": "application-ports";
|
|
33
|
+
"application-services": "application-services";
|
|
34
|
+
"use-cases": "use-cases";
|
|
35
|
+
"execution-commands": "execution-commands";
|
|
36
|
+
"execution-queries": "execution-queries";
|
|
37
|
+
"orchestration-commands": "orchestration-commands";
|
|
38
|
+
"orchestration-queries": "orchestration-queries";
|
|
39
|
+
"infrastructure-services": "infrastructure-services";
|
|
40
|
+
"presentation-services": "presentation-services";
|
|
41
|
+
}>>, z.ZodObject<{
|
|
42
|
+
add: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
43
|
+
repositories: "repositories";
|
|
44
|
+
"domain-services": "domain-services";
|
|
45
|
+
"application-ports": "application-ports";
|
|
46
|
+
"application-services": "application-services";
|
|
47
|
+
"use-cases": "use-cases";
|
|
48
|
+
"execution-commands": "execution-commands";
|
|
49
|
+
"execution-queries": "execution-queries";
|
|
50
|
+
"orchestration-commands": "orchestration-commands";
|
|
51
|
+
"orchestration-queries": "orchestration-queries";
|
|
52
|
+
"infrastructure-services": "infrastructure-services";
|
|
53
|
+
"presentation-services": "presentation-services";
|
|
54
|
+
}>>>;
|
|
55
|
+
remove: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
56
|
+
repositories: "repositories";
|
|
57
|
+
"domain-services": "domain-services";
|
|
58
|
+
"application-ports": "application-ports";
|
|
59
|
+
"application-services": "application-services";
|
|
60
|
+
"use-cases": "use-cases";
|
|
61
|
+
"execution-commands": "execution-commands";
|
|
62
|
+
"execution-queries": "execution-queries";
|
|
63
|
+
"orchestration-commands": "orchestration-commands";
|
|
64
|
+
"orchestration-queries": "orchestration-queries";
|
|
65
|
+
"infrastructure-services": "infrastructure-services";
|
|
66
|
+
"presentation-services": "presentation-services";
|
|
67
|
+
}>>>;
|
|
68
|
+
}, z.core.$strip>]>>;
|
|
69
|
+
export type DependencyRulesConfig = z.infer<typeof dependencyRulesSchema>;
|
|
70
|
+
export declare const resolveDependencyRules: (config?: DependencyRulesConfig) => DependencyRules;
|
|
71
|
+
export declare const defaultDependencyRules: DependencyRules;
|
|
72
|
+
/**
|
|
73
|
+
* The kind of a wired module: its folder under `wiring/`; commands and
|
|
74
|
+
* queries by the folder of their type, `execution/` or `orchestration/`.
|
|
75
|
+
*/
|
|
76
|
+
export declare const wiredModuleKind: (wiringKind: string, typeFile: string) => "repositories" | "domain-services" | "application-ports" | "application-services" | "use-cases" | "execution-commands" | "execution-queries" | "orchestration-commands" | "orchestration-queries" | "infrastructure-services" | "presentation-services" | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* The kind of a module file, from its path inside a context or the
|
|
79
|
+
* Shared Layer (`application/use-cases/…`), or undefined for other files
|
|
80
|
+
* such as entities, value objects and errors.
|
|
81
|
+
*/
|
|
82
|
+
export declare const fileModuleKind: (segments: string[]) => ModuleKind | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,105 @@ const external_node_path_namespaceObject = require("node:path");
|
|
|
31
31
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
32
32
|
const external_zod_namespaceObject = require("zod");
|
|
33
33
|
var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
|
|
34
|
+
const moduleKinds = [
|
|
35
|
+
'repositories',
|
|
36
|
+
'domain-services',
|
|
37
|
+
'application-ports',
|
|
38
|
+
'application-services',
|
|
39
|
+
'use-cases',
|
|
40
|
+
'execution-commands',
|
|
41
|
+
'execution-queries',
|
|
42
|
+
'orchestration-commands',
|
|
43
|
+
'orchestration-queries',
|
|
44
|
+
'infrastructure-services',
|
|
45
|
+
'presentation-services'
|
|
46
|
+
];
|
|
47
|
+
const domain = [
|
|
48
|
+
'repositories',
|
|
49
|
+
'domain-services'
|
|
50
|
+
];
|
|
51
|
+
const commandsAndQueries = [
|
|
52
|
+
'execution-commands',
|
|
53
|
+
'execution-queries',
|
|
54
|
+
'orchestration-commands',
|
|
55
|
+
'orchestration-queries'
|
|
56
|
+
];
|
|
57
|
+
const infrastructure = [
|
|
58
|
+
...domain,
|
|
59
|
+
'application-ports',
|
|
60
|
+
'infrastructure-services'
|
|
61
|
+
];
|
|
62
|
+
const defaultDependencies = {
|
|
63
|
+
'domain-services': domain,
|
|
64
|
+
repositories: [
|
|
65
|
+
'domain-services',
|
|
66
|
+
'application-ports',
|
|
67
|
+
'infrastructure-services'
|
|
68
|
+
],
|
|
69
|
+
'application-ports': infrastructure,
|
|
70
|
+
'application-services': [
|
|
71
|
+
...domain,
|
|
72
|
+
'application-ports'
|
|
73
|
+
],
|
|
74
|
+
'use-cases': [
|
|
75
|
+
...domain,
|
|
76
|
+
'application-ports',
|
|
77
|
+
'application-services',
|
|
78
|
+
...commandsAndQueries
|
|
79
|
+
],
|
|
80
|
+
'execution-commands': infrastructure,
|
|
81
|
+
'execution-queries': infrastructure,
|
|
82
|
+
'orchestration-commands': [
|
|
83
|
+
...domain,
|
|
84
|
+
'execution-commands',
|
|
85
|
+
'execution-queries'
|
|
86
|
+
],
|
|
87
|
+
'orchestration-queries': [
|
|
88
|
+
...domain,
|
|
89
|
+
'execution-queries'
|
|
90
|
+
],
|
|
91
|
+
'infrastructure-services': infrastructure,
|
|
92
|
+
'presentation-services': [
|
|
93
|
+
'application-ports',
|
|
94
|
+
'application-services',
|
|
95
|
+
'use-cases',
|
|
96
|
+
...commandsAndQueries,
|
|
97
|
+
'presentation-services'
|
|
98
|
+
]
|
|
99
|
+
};
|
|
100
|
+
const kindSchema = external_zod_default()["enum"](moduleKinds);
|
|
101
|
+
const dependencyRulesSchema = external_zod_default().partialRecord(kindSchema, external_zod_default().union([
|
|
102
|
+
external_zod_default().array(kindSchema),
|
|
103
|
+
external_zod_default().object({
|
|
104
|
+
add: external_zod_default().array(kindSchema).optional(),
|
|
105
|
+
remove: external_zod_default().array(kindSchema).optional()
|
|
106
|
+
})
|
|
107
|
+
]));
|
|
108
|
+
const resolveDependencyRules = (config = {})=>{
|
|
109
|
+
const entries = moduleKinds.map((kind)=>{
|
|
110
|
+
const override = config[kind];
|
|
111
|
+
if (Array.isArray(override)) return [
|
|
112
|
+
kind,
|
|
113
|
+
new Set(override)
|
|
114
|
+
];
|
|
115
|
+
const kinds = new Set([
|
|
116
|
+
...defaultDependencies[kind],
|
|
117
|
+
...override?.add ?? []
|
|
118
|
+
]);
|
|
119
|
+
for (const removed of override?.remove ?? [])kinds.delete(removed);
|
|
120
|
+
return [
|
|
121
|
+
kind,
|
|
122
|
+
kinds
|
|
123
|
+
];
|
|
124
|
+
});
|
|
125
|
+
return Object.fromEntries(entries);
|
|
126
|
+
};
|
|
127
|
+
const defaultDependencyRules = resolveDependencyRules();
|
|
128
|
+
const isModuleKind = (value)=>moduleKinds.includes(value);
|
|
129
|
+
const wiredModuleKind = (wiringKind, typeFile)=>{
|
|
130
|
+
const kind = 'commands' === wiringKind || 'queries' === wiringKind ? `${'execution' === external_node_path_default().basename(external_node_path_default().dirname(typeFile)) ? 'execution' : 'orchestration'}-${wiringKind}` : wiringKind;
|
|
131
|
+
return isModuleKind(kind) ? kind : void 0;
|
|
132
|
+
};
|
|
34
133
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
35
134
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
36
135
|
const pendingFiles = new Map();
|
|
@@ -182,6 +281,14 @@ class ProjectRoot {
|
|
|
182
281
|
throw new Error('No package.json was found');
|
|
183
282
|
}
|
|
184
283
|
}
|
|
284
|
+
const lintChecks = [
|
|
285
|
+
'context-isolation',
|
|
286
|
+
'shared-layer',
|
|
287
|
+
'layers',
|
|
288
|
+
'dependencies',
|
|
289
|
+
'react',
|
|
290
|
+
'clock'
|
|
291
|
+
];
|
|
185
292
|
const configFileName = 'domain-first.project-structure.config.json';
|
|
186
293
|
const configSchema = external_zod_default().object({
|
|
187
294
|
rootFolder: external_zod_default().string(),
|
|
@@ -196,7 +303,11 @@ const configSchema = external_zod_default().object({
|
|
|
196
303
|
withInMemoryDb: external_zod_default().boolean().optional(),
|
|
197
304
|
useReact: external_zod_default().boolean(),
|
|
198
305
|
storybookFramework: external_zod_default().string().optional(),
|
|
199
|
-
testingLibrary: external_zod_default().string().optional()
|
|
306
|
+
testingLibrary: external_zod_default().string().optional(),
|
|
307
|
+
rules: external_zod_default().object({
|
|
308
|
+
dependencies: dependencyRulesSchema.optional(),
|
|
309
|
+
lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
|
|
310
|
+
}).optional()
|
|
200
311
|
});
|
|
201
312
|
class ConfigFile {
|
|
202
313
|
data;
|
|
@@ -220,6 +331,7 @@ class ConfigFile {
|
|
|
220
331
|
new File(ConfigFile.path).data = JSON.stringify(config, null, '\t');
|
|
221
332
|
};
|
|
222
333
|
}
|
|
334
|
+
const configuredDependencyRules = ()=>resolveDependencyRules(ConfigFile.exists ? ConfigFile.Instance.data.rules?.dependencies : void 0);
|
|
223
335
|
const external_node_util_namespaceObject = require("node:util");
|
|
224
336
|
const printNextSteps = (nextSteps)=>{
|
|
225
337
|
const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
|
|
@@ -1462,25 +1574,18 @@ const findWiredModules = (contextPath)=>{
|
|
|
1462
1574
|
walk(external_node_path_default().join(contextPath, 'wiring'));
|
|
1463
1575
|
return result.sort((a, b)=>a.typeName.localeCompare(b.typeName));
|
|
1464
1576
|
};
|
|
1465
|
-
const
|
|
1466
|
-
const
|
|
1467
|
-
const commandOrQueryRule = (candidate, consumer)=>isExecution(consumer) ? !isCommandOrQuery(candidate) : 'application' !== candidate.layer || isExecution(candidate);
|
|
1468
|
-
const layerRules = {
|
|
1469
|
-
infrastructure: (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind
|
|
1470
|
-
};
|
|
1471
|
-
const kindRules = {
|
|
1472
|
-
'application-services': (candidate)=>'application' !== candidate.layer || 'application-ports' === candidate.kind,
|
|
1473
|
-
'use-cases': (candidate)=>'use-cases' !== candidate.kind,
|
|
1474
|
-
repositories: (candidate)=>'repositories' !== candidate.kind,
|
|
1475
|
-
commands: commandOrQueryRule,
|
|
1476
|
-
queries: commandOrQueryRule
|
|
1477
|
-
};
|
|
1577
|
+
const moduleKindOf = (module)=>wiredModuleKind(module.kind, module.typeFile);
|
|
1578
|
+
const layerRule = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && ('infrastructure' !== consumer.implementationsLayer || 'application' !== candidate.layer || 'application-ports' === candidate.kind);
|
|
1478
1579
|
const wiring_implementationType = (consumer, implementation)=>consumer.branched ? external_node_path_default().basename(external_node_path_default().dirname(implementation.file)) : void 0;
|
|
1479
1580
|
const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${external_node_path_default().basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
|
|
1480
|
-
const canDependOn = (consumer, candidate
|
|
1481
|
-
const
|
|
1581
|
+
const canDependOn = (consumer, candidate, rules = defaultDependencyRules)=>{
|
|
1582
|
+
const consumerKind = moduleKindOf(consumer);
|
|
1583
|
+
const candidateKind = moduleKindOf(candidate);
|
|
1584
|
+
return consumerKind && candidateKind ? rules[consumerKind].has(candidateKind) : layerRule(consumer, candidate);
|
|
1585
|
+
};
|
|
1586
|
+
const availableDependencies = (consumer, implementation, candidates, rules = configuredDependencyRules())=>{
|
|
1482
1587
|
const wired = wiredDependencyNames(new File(consumer.wireFile).data, implementation.className);
|
|
1483
|
-
return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate) && !wired.includes(candidate.wireName));
|
|
1588
|
+
return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate, rules) && !wired.includes(candidate.wireName));
|
|
1484
1589
|
};
|
|
1485
1590
|
const relativeImport = (fromFile, toFile)=>{
|
|
1486
1591
|
const relativePath = external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile).replace(/\.ts$/, '').split(external_node_path_default().sep).join('/');
|