@md-code/follow-architecture 0.3.0 → 0.3.3
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/CHANGELOG.md +38 -0
- package/README.md +1341 -472
- package/dist/args.d.ts +4 -0
- package/dist/args.js +18 -1
- package/dist/bin/follow-architecture.js +3 -3
- package/dist/closure-project.d.ts +4 -0
- package/dist/closure-project.js +122 -0
- package/dist/code-entities/classify.d.ts +11 -0
- package/dist/code-entities/classify.js +45 -0
- package/dist/code-entities/connector.d.ts +8 -0
- package/dist/code-entities/connector.js +119 -0
- package/dist/code-entities/entities.d.ts +9 -0
- package/dist/{code-roles/roles.js → code-entities/entities.js} +81 -54
- package/dist/code-entities/project.d.ts +21 -0
- package/dist/code-entities/project.js +249 -0
- package/dist/code-entities/walk.d.ts +31 -0
- package/dist/code-entities/walk.js +95 -0
- package/dist/config-options.d.ts +23 -0
- package/dist/config-options.js +18 -1
- package/dist/config-project.js +10 -2
- package/dist/config-report.d.ts +1 -1
- package/dist/config-report.js +20 -3
- package/dist/config-rule.d.ts +25 -0
- package/dist/config-rule.js +89 -6
- package/dist/config-state.d.ts +14 -3
- package/dist/config-state.js +180 -17
- package/dist/config.d.ts +25 -0
- package/dist/css/index.d.ts +11 -7
- package/dist/css/index.js +124 -23
- package/dist/css/syntax/css/gate.js +5 -5
- package/dist/css/syntax/css/index.d.ts +1 -1
- package/dist/css/syntax/css/index.js +1 -1
- package/dist/css/syntax/css/reference.d.ts +1 -1
- package/dist/css/syntax/css/reference.js +15 -3
- package/dist/css/syntax/language.d.ts +1 -1
- package/dist/css/syntax/language.js +4 -2
- package/dist/css/syntax/scss/index.d.ts +2 -2
- package/dist/css/syntax/scss/index.js +1 -1
- package/dist/css/syntax/scss/reference.d.ts +1 -1
- package/dist/css/syntax/scss/reference.js +7 -1
- package/dist/css/syntax/styled/document.d.ts +3 -3
- package/dist/css/syntax/styled/document.js +17 -7
- package/dist/css/syntax/styled/markup.d.ts +1 -1
- package/dist/css/syntax/styled/markup.js +22 -14
- package/dist/css/syntax/styled/tags.d.ts +2 -0
- package/dist/css/syntax/styled/tags.js +22 -0
- package/dist/css/syntax/styled/template.js +10 -4
- package/dist/css/syntax/tailwind/tailwind.js +4 -4
- package/dist/css/value/check.d.ts +1 -1
- package/dist/css/value/check.js +1 -1
- package/dist/css/value/expression/arithmetic.d.ts +2 -2
- package/dist/css/value/expression/arithmetic.js +7 -3
- package/dist/css/value/expression/block.d.ts +2 -2
- package/dist/css/value/expression/block.js +4 -3
- package/dist/css/value/expression/conditional.d.ts +2 -2
- package/dist/css/value/expression/conditional.js +1 -1
- package/dist/css/value/expression/index.d.ts +2 -2
- package/dist/css/value/expression/index.js +10 -6
- package/dist/css/value/expression/map.d.ts +2 -2
- package/dist/css/value/expression/map.js +2 -2
- package/dist/css/value/object/index.d.ts +2 -2
- package/dist/css/value/object/index.js +14 -4
- package/dist/css/value/object/members.d.ts +2 -2
- package/dist/css/value/object/node.js +9 -4
- package/dist/css/value/object/path.d.ts +3 -3
- package/dist/css/value/object/path.js +10 -4
- package/dist/css/value/pieces.d.ts +3 -3
- package/dist/css/value/pieces.js +14 -4
- package/dist/css/value/resolve.js +15 -5
- package/dist/css/value/scope.d.ts +3 -2
- package/dist/css/value/scope.js +25 -7
- package/dist/css/value/substitute.js +43 -11
- package/dist/entities/architecture.d.ts +28 -25
- package/dist/entities/ast/assignments-raw.d.ts +1 -1
- package/dist/entities/ast/assignments-raw.js +61 -8
- package/dist/entities/ast/assignments-tagged.d.ts +1 -1
- package/dist/entities/ast/assignments-tagged.js +22 -7
- package/dist/entities/ast/assignments.d.ts +1 -1
- package/dist/entities/ast/assignments.js +6 -4
- package/dist/entities/ast/branches.d.ts +1 -1
- package/dist/entities/ast/calls.d.ts +1 -1
- package/dist/entities/ast/calls.js +19 -3
- package/dist/entities/ast/classes.d.ts +1 -1
- package/dist/entities/ast/classes.js +5 -1
- package/dist/entities/ast/comments.d.ts +3 -2
- package/dist/entities/ast/comments.js +47 -17
- package/dist/entities/ast/declaration.d.ts +1 -1
- package/dist/entities/ast/depth.d.ts +2 -2
- package/dist/entities/ast/depth.js +15 -8
- package/dist/entities/ast/enums.d.ts +1 -1
- package/dist/entities/ast/export-chain.d.ts +15 -0
- package/dist/entities/ast/export-chain.js +171 -0
- package/dist/entities/ast/file-exports.d.ts +1 -1
- package/dist/entities/ast/file-exports.js +26 -3
- package/dist/entities/ast/file-facts.d.ts +6 -3
- package/dist/entities/ast/file-facts.js +33 -4
- package/dist/entities/ast/file-imports.d.ts +1 -1
- package/dist/entities/ast/file-imports.js +26 -3
- package/dist/entities/ast/file.d.ts +2 -2
- package/dist/entities/ast/file.js +2 -1
- package/dist/entities/ast/functions.d.ts +1 -1
- package/dist/entities/ast/functions.js +13 -4
- package/dist/entities/ast/heritage.d.ts +1 -1
- package/dist/entities/ast/heritage.js +9 -1
- package/dist/entities/ast/index.d.ts +6 -3
- package/dist/entities/ast/index.js +82 -26
- package/dist/entities/ast/kind.d.ts +1 -1
- package/dist/entities/ast/kind.js +7 -1
- package/dist/entities/ast/modifiers.d.ts +1 -1
- package/dist/entities/ast/modifiers.js +4 -4
- package/dist/entities/ast/project.js +33 -2
- package/dist/entities/ast/properties.d.ts +1 -1
- package/dist/entities/ast/properties.js +10 -5
- package/dist/entities/ast/resolve.d.ts +1 -1
- package/dist/entities/ast/resolve.js +4 -4
- package/dist/entities/ast/tree.d.ts +4 -2
- package/dist/entities/ast/tree.js +184 -17
- package/dist/entities/ast/types.d.ts +1 -1
- package/dist/entities/ast/types.js +2 -1
- package/dist/entities/ast/usage.d.ts +1 -1
- package/dist/entities/ast/usage.js +1 -1
- package/dist/entities/ast/variables.d.ts +1 -1
- package/dist/entities/context.d.ts +4 -4
- package/dist/entities/facts.d.ts +36 -13
- package/dist/entities/findings.d.ts +3 -3
- package/dist/entities/kinds.d.ts +1 -1
- package/dist/entities/kinds.js +131 -30
- package/dist/entities/location/homes.d.ts +10 -10
- package/dist/entities/location/homes.js +74 -48
- package/dist/entities/location/place.d.ts +1 -1
- package/dist/entities/location/place.js +10 -3
- package/dist/entities/location/where.d.ts +8 -6
- package/dist/entities/location/where.js +79 -30
- package/dist/entities/location.d.ts +3 -3
- package/dist/entities/location.js +17 -17
- package/dist/entities/operators.js +1 -1
- package/dist/entities/overview/data.d.ts +6 -6
- package/dist/entities/overview/decision.d.ts +11 -11
- package/dist/entities/overview/finding.d.ts +10 -10
- package/dist/entities/overview/graph.d.ts +28 -11
- package/dist/entities/overview/input.d.ts +2 -2
- package/dist/entities/overview/summaries.d.ts +17 -15
- package/dist/entities/queries.d.ts +1 -1
- package/dist/entities/queries.js +72 -12
- package/dist/entities/repair.d.ts +1 -1
- package/dist/entities/repair.js +8 -2
- package/dist/entities/schema.d.ts +17 -3
- package/dist/entities/schema.js +74 -16
- package/dist/entities/story.d.ts +5 -5
- package/dist/entities/structure-facts.d.ts +1 -1
- package/dist/entities/token.d.ts +4 -4
- package/dist/entities/tree/build.d.ts +4 -3
- package/dist/entities/tree/build.js +95 -44
- package/dist/entities/tree/entries.d.ts +3 -3
- package/dist/entities/tree/entries.js +41 -16
- package/dist/entities/tree/index.d.ts +2 -2
- package/dist/entities/tree/index.js +1 -1
- package/dist/entities/tree/match.d.ts +2 -2
- package/dist/entities/tree/match.js +9 -5
- package/dist/fa-index.d.ts +16 -0
- package/dist/fa-index.js +165 -0
- package/dist/fa-open.d.ts +51 -0
- package/dist/fa-open.js +232 -0
- package/dist/fa-store.d.ts +22 -0
- package/dist/fa-store.js +222 -0
- package/dist/fa-values.d.ts +37 -0
- package/dist/fa-values.js +104 -0
- package/dist/facts-record.d.ts +45 -0
- package/dist/facts-record.js +287 -0
- package/dist/frameworks/angular/index.d.ts +2 -2
- package/dist/frameworks/angular/index.js +2 -1
- package/dist/frameworks/facet.d.ts +3 -1
- package/dist/frameworks/facet.js +13 -0
- package/dist/frameworks/index.d.ts +1 -1
- package/dist/frameworks/index.js +8 -4
- package/dist/frameworks/react/index.d.ts +2 -2
- package/dist/frameworks/react/index.js +33 -10
- package/dist/frameworks/test/index.d.ts +6 -0
- package/dist/frameworks/test/index.js +157 -0
- package/dist/frameworks/vue/index.d.ts +2 -2
- package/dist/frameworks/vue/index.js +2 -1
- package/dist/ignore.d.ts +3 -0
- package/dist/ignore.js +48 -0
- package/dist/index-file.d.ts +43 -0
- package/dist/index-file.js +218 -0
- package/dist/index-run.d.ts +39 -0
- package/dist/index-run.js +217 -0
- package/dist/index-zone.d.ts +25 -0
- package/dist/index-zone.js +209 -0
- package/dist/main.d.ts +5 -2
- package/dist/main.js +207 -34
- package/dist/nodes/child-entities.d.ts +3 -0
- package/dist/nodes/child-entities.js +12 -0
- package/dist/nodes/children.d.ts +4 -4
- package/dist/nodes/children.js +54 -11
- package/dist/nodes/finally/emit.d.ts +3 -3
- package/dist/nodes/finally/emit.js +26 -10
- package/dist/nodes/finally/entities.d.ts +13 -0
- package/dist/nodes/finally/entities.js +42 -0
- package/dist/nodes/finally/index.d.ts +6 -6
- package/dist/nodes/finally/index.js +8 -8
- package/dist/nodes/finally/queries.d.ts +2 -2
- package/dist/nodes/finally/queries.js +7 -4
- package/dist/nodes/finally/relations-access.d.ts +2 -2
- package/dist/nodes/finally/relations-access.js +22 -18
- package/dist/nodes/finally/relations-edge.d.ts +5 -5
- package/dist/nodes/finally/relations-edge.js +67 -44
- package/dist/nodes/finally/relations-group.d.ts +7 -7
- package/dist/nodes/finally/relations-group.js +28 -25
- package/dist/nodes/finally/relations.d.ts +2 -2
- package/dist/nodes/finally/relations.js +16 -12
- package/dist/nodes/finally/required.d.ts +3 -3
- package/dist/nodes/finally/required.js +9 -7
- package/dist/nodes/finally/violation.d.ts +2 -2
- package/dist/nodes/similar.d.ts +3 -3
- package/dist/nodes/similar.js +61 -49
- package/dist/piece-forms.d.ts +9 -0
- package/dist/piece-forms.js +68 -0
- package/dist/{pipeline-roles.d.ts → pipeline-entities.d.ts} +2 -2
- package/dist/{pipeline-roles.js → pipeline-entities.js} +32 -28
- package/dist/pipeline-facts.d.ts +4 -3
- package/dist/pipeline-facts.js +47 -55
- package/dist/{pipeline-unroled.d.ts → pipeline-unclassified.d.ts} +2 -2
- package/dist/{pipeline-unroled.js → pipeline-unclassified.js} +58 -63
- package/dist/pipeline.js +19 -64
- package/dist/release-file.d.ts +3 -0
- package/dist/release-file.js +13 -0
- package/dist/report/asks.d.ts +3 -3
- package/dist/report/asks.js +16 -6
- package/dist/report/configErrors.d.ts +55 -27
- package/dist/report/configErrors.js +81 -35
- package/dist/report/errorTypes/codes/structure.d.ts +1 -1
- package/dist/report/errorTypes/codes/structure.js +9 -9
- package/dist/report/errorTypes/decision-maker.d.ts +5 -5
- package/dist/report/errorTypes/decision-maker.js +4 -4
- package/dist/report/errorTypes/destinations.d.ts +5 -5
- package/dist/report/errorTypes/destinations.js +52 -34
- package/dist/report/errorTypes/finding-type.d.ts +3 -3
- package/dist/report/errorTypes/index.d.ts +1 -1
- package/dist/report/errorTypes/types/fileContents.d.ts +4 -4
- package/dist/report/errorTypes/types/fileContents.js +11 -5
- package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
- package/dist/report/errorTypes/types/{unknownRole.js → unknownEntity.js} +12 -7
- package/dist/report/errorTypes/types/wrongAction.d.ts +5 -5
- package/dist/report/errorTypes/types/wrongAction.js +18 -13
- package/dist/report/errorTypes/types/wrongPlacement.d.ts +4 -4
- package/dist/report/errorTypes/types/wrongPlacement.js +19 -9
- package/dist/report/errorTypes/vocabulary/ids.d.ts +2 -2
- package/dist/report/errorTypes/vocabulary/ids.js +3 -3
- package/dist/report/errorTypes/vocabulary/phrases.d.ts +2 -2
- package/dist/report/errorTypes/vocabulary/phrases.js +39 -26
- package/dist/report/errorTypes/vocabulary/places.d.ts +3 -3
- package/dist/report/errorTypes/vocabulary/places.js +13 -13
- package/dist/report/finding-from.d.ts +3 -3
- package/dist/report/finding-from.js +14 -9
- package/dist/report/notices.d.ts +6 -1
- package/dist/report/notices.js +46 -20
- package/dist/report/observed.d.ts +19 -0
- package/dist/report/observed.js +87 -0
- package/dist/report/render-report.d.ts +1 -1
- package/dist/report/render-report.js +33 -30
- package/dist/report/user-report/build/bundle.js +9 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +799 -297
- package/dist/report/user-report/data/collect.d.ts +2 -2
- package/dist/report/user-report/data/collect.js +15 -12
- package/dist/report/user-report/data/entities.d.ts +7 -0
- package/dist/report/user-report/data/{roles.js → entities.js} +27 -22
- package/dist/report/user-report/data/{role-examples.d.ts → entity-examples.d.ts} +3 -3
- package/dist/report/user-report/data/entity-examples.js +126 -0
- package/dist/report/user-report/data/{role-filters.d.ts → entity-filters.d.ts} +2 -2
- package/dist/report/user-report/data/{role-filters.js → entity-filters.js} +7 -7
- package/dist/report/user-report/data/entity-marks.d.ts +5 -0
- package/dist/report/user-report/data/{role-marks.js → entity-marks.js} +11 -11
- package/dist/report/user-report/data/file-tree.d.ts +3 -3
- package/dist/report/user-report/data/file-tree.js +13 -5
- package/dist/report/user-report/data/finding-boundary.d.ts +4 -4
- package/dist/report/user-report/data/finding-boundary.js +2 -2
- package/dist/report/user-report/data/finding-plan.d.ts +5 -5
- package/dist/report/user-report/data/finding-plan.js +10 -10
- package/dist/report/user-report/data/finding-title.d.ts +2 -2
- package/dist/report/user-report/data/finding-title.js +8 -8
- package/dist/report/user-report/data/findings.d.ts +4 -4
- package/dist/report/user-report/data/findings.js +30 -20
- package/dist/report/user-report/data/graph-edges.d.ts +4 -4
- package/dist/report/user-report/data/graph-edges.js +19 -19
- package/dist/report/user-report/data/graph-entities.d.ts +6 -0
- package/dist/report/user-report/data/graph-entities.js +158 -0
- package/dist/report/user-report/data/graph-helpers.d.ts +5 -5
- package/dist/report/user-report/data/graph-helpers.js +15 -15
- package/dist/report/user-report/data/graph.d.ts +5 -4
- package/dist/report/user-report/data/graph.js +28 -21
- package/dist/report/user-report/data/nodes.d.ts +2 -2
- package/dist/report/user-report/data/nodes.js +16 -16
- package/dist/report/user-report/data/rules.d.ts +7 -0
- package/dist/report/user-report/data/{invariants.js → rules.js} +13 -13
- package/dist/report/user-report/data/scan.d.ts +1 -1
- package/dist/report/user-report/data/scan.js +2 -2
- package/dist/report/user-report/html/shell.d.ts +1 -1
- package/dist/report/user-report/html/shell.js +1 -1
- package/dist/report/user-report/index.d.ts +1 -1
- package/dist/report/user-report/shared/describe.d.ts +1 -1
- package/dist/report/user-report/shared/describe.js +6 -6
- package/dist/rules/index.d.ts +7 -0
- package/dist/{invariants → rules}/index.js +85 -57
- package/dist/{invariants → rules}/list-vars.d.ts +2 -2
- package/dist/{invariants → rules}/list-vars.js +9 -3
- package/dist/{invariants → rules}/name.js +2 -2
- package/dist/rules/normalize.d.ts +5 -0
- package/dist/{invariants → rules}/normalize.js +35 -32
- package/dist/{invariants → rules}/vars.d.ts +9 -7
- package/dist/{invariants → rules}/vars.js +5 -5
- package/dist/scan-run.d.ts +20 -0
- package/dist/scan-run.js +130 -0
- package/dist/scripts/audit-report.js +2 -2
- package/dist/usage-index.d.ts +4 -0
- package/dist/usage-index.js +272 -0
- package/dist/usage-mode.d.ts +7 -0
- package/dist/usage-mode.js +16 -0
- package/dist/usage-pass.d.ts +19 -0
- package/dist/usage-pass.js +136 -0
- package/dist/usage-prepare.d.ts +2 -0
- package/dist/usage-prepare.js +22 -0
- package/dist/usage-sweep.d.ts +10 -0
- package/dist/usage-sweep.js +254 -0
- package/dist/utils/aliases.d.ts +22 -0
- package/dist/utils/aliases.js +163 -0
- package/dist/utils/classify.d.ts +2 -2
- package/dist/utils/classify.js +4 -4
- package/dist/utils/distinct.js +4 -2
- package/dist/utils/files.js +24 -30
- package/dist/utils/fixpoint.js +2 -2
- package/dist/utils/host.d.ts +1 -1
- package/dist/utils/host.js +4 -1
- package/dist/utils/imports.js +66 -12
- package/dist/utils/keyed.js +2 -2
- package/dist/utils/map-record.js +2 -2
- package/dist/utils/packages.d.ts +15 -0
- package/dist/utils/packages.js +197 -0
- package/dist/utils/path-label.js +3 -1
- package/dist/utils/pattern.d.ts +5 -4
- package/dist/utils/pattern.js +38 -8
- package/dist/utils/permission.d.ts +3 -3
- package/dist/utils/permission.js +4 -2
- package/dist/utils/plural.js +2 -2
- package/dist/utils/qualified.js +4 -4
- package/dist/utils/rank.js +2 -2
- package/dist/utils/record.js +1 -1
- package/dist/utils/search.js +7 -2
- package/dist/utils/speak.js +1 -1
- package/dist/utils/split.js +14 -1
- package/dist/utils/template.d.ts +1 -1
- package/dist/utils/template.js +1 -1
- package/dist/utils/tokenize.js +6 -1
- package/dist/utils/typed-field.js +2 -2
- package/dist/utils/verdicts.js +1 -1
- package/entities/operators.ts +1 -1
- package/package.json +101 -90
- package/report/errorTypes/vocabulary/ids.ts +7 -2
- package/report/errorTypes/vocabulary/phrases.ts +47 -27
- package/report/errorTypes/vocabulary/places.ts +21 -16
- package/report/user-report/shared/describe.ts +7 -7
- package/dist/code-roles/classify.d.ts +0 -11
- package/dist/code-roles/classify.js +0 -43
- package/dist/code-roles/connector.d.ts +0 -5
- package/dist/code-roles/connector.js +0 -114
- package/dist/code-roles/project.d.ts +0 -12
- package/dist/code-roles/project.js +0 -122
- package/dist/code-roles/roles.d.ts +0 -8
- package/dist/invariants/index.d.ts +0 -6
- package/dist/invariants/normalize.d.ts +0 -4
- package/dist/nodes/child-roles.d.ts +0 -3
- package/dist/nodes/child-roles.js +0 -12
- package/dist/nodes/finally/roles.d.ts +0 -13
- package/dist/nodes/finally/roles.js +0 -41
- package/dist/report/errorTypes/types/unknownRole.d.ts +0 -9
- package/dist/report/user-report/data/graph-roles.d.ts +0 -5
- package/dist/report/user-report/data/graph-roles.js +0 -71
- package/dist/report/user-report/data/invariants.d.ts +0 -7
- package/dist/report/user-report/data/role-examples.js +0 -94
- package/dist/report/user-report/data/role-marks.d.ts +0 -5
- package/dist/report/user-report/data/roles.d.ts +0 -7
- /package/dist/{invariants → rules}/name.d.ts +0 -0
package/dist/entities/kinds.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.declaredActions = exports.changesState = exports.CHANGES_STATE = exports.EDGE_FACTS = exports.FACT_KINDS = exports.VIA = exports.RELATION = void 0;
|
|
27
|
-
const configError = __importStar(require("
|
|
27
|
+
const configError = __importStar(require("@md-code/follow-architecture/report/configErrors"));
|
|
28
28
|
// THE VOCABULARY, as an enum: one name per relation, one spelling everywhere.
|
|
29
29
|
const RELATION = Object.freeze({
|
|
30
30
|
IMPORT: "import",
|
|
@@ -47,15 +47,15 @@ const CHANGES_STATE = new Set([RELATION.MUTATE, RELATION.ASSIGN]);
|
|
|
47
47
|
exports.CHANGES_STATE = CHANGES_STATE;
|
|
48
48
|
const changesState = (relation) => CHANGES_STATE.has(relation);
|
|
49
49
|
exports.changesState = changesState;
|
|
50
|
-
// The
|
|
51
|
-
const
|
|
50
|
+
// The entity of the piece of code a fact belongs to, by the piece's name.
|
|
51
|
+
const entityOfPiece = (facts, piece) => piece ? ((facts.candidates ?? []).find((c) => c.name === piece && c.entity)?.entity ?? null) : null;
|
|
52
52
|
// Is a module path a FILE of this repo?
|
|
53
53
|
const isRepoModule = (facts, module) => Boolean(module) && (facts.repoFiles ?? []).includes(module ?? "");
|
|
54
54
|
// The line a candidate starts on.
|
|
55
55
|
const lineOf = (c) => c.lines?.[0] ?? 1;
|
|
56
56
|
// The shape EVERY edge has: the target, the piece it belongs to and whether the
|
|
57
57
|
// target is a library, plus the structured `fact` and its sentence.
|
|
58
|
-
const edgeOf = (facts, edge) => ({ ...edge,
|
|
58
|
+
const edgeOf = (facts, edge) => ({ ...edge, entity: entityOfPiece(facts, edge.piece) });
|
|
59
59
|
const callsOf = (facts) => (facts.candidates ?? []).flatMap((c) => (c.calls ?? [])
|
|
60
60
|
.filter((call) => call.module && !call.receiverOnly)
|
|
61
61
|
.map((call) => ({
|
|
@@ -84,16 +84,22 @@ const writeWhat = ({ target, module, method, onThis, mutate }) => {
|
|
|
84
84
|
const writePath = (facts, a, mutate) => {
|
|
85
85
|
if (!mutate)
|
|
86
86
|
return facts.location.path;
|
|
87
|
-
return a.onThis ? facts.location.path : a.module ?? null;
|
|
87
|
+
return a.onThis ? facts.location.path : (a.module ?? null);
|
|
88
88
|
};
|
|
89
|
-
const writeExternal = (facts, a, mutate) =>
|
|
89
|
+
const writeExternal = (facts, a, mutate) => mutate && !a.onThis ? !isRepoModule(facts, a.module) : false;
|
|
90
90
|
const assignmentEdge = (facts, c, a, mutate) => edgeOf(facts, {
|
|
91
91
|
path: writePath(facts, a, mutate),
|
|
92
92
|
line: a.line ?? lineOf(c),
|
|
93
93
|
piece: c.name ?? null,
|
|
94
94
|
external: writeExternal(facts, a, mutate),
|
|
95
95
|
// THE FACT — what the code did, as data.
|
|
96
|
-
fact: {
|
|
96
|
+
fact: {
|
|
97
|
+
kind: mutate ? RELATION.MUTATE : RELATION.ASSIGN,
|
|
98
|
+
target: a.target ?? null,
|
|
99
|
+
module: a.module ?? null,
|
|
100
|
+
method: a.method ?? null,
|
|
101
|
+
onThis: Boolean(a.onThis),
|
|
102
|
+
},
|
|
97
103
|
what: writeWhat({ target: a.target, module: a.module, method: a.method, onThis: Boolean(a.onThis), mutate }),
|
|
98
104
|
});
|
|
99
105
|
const assignmentsOf = (facts, { mutate }) => (facts.candidates ?? []).flatMap((c) => (c.assignments ?? [])
|
|
@@ -123,10 +129,55 @@ const exportPiece = (facts, exp, names) => {
|
|
|
123
129
|
return null;
|
|
124
130
|
return (facts.candidates ?? []).some((c) => c.name === names[0]) ? names[0] : null;
|
|
125
131
|
};
|
|
126
|
-
|
|
132
|
+
// The file each re-exported name is declared in (a barrel re-exported by a
|
|
133
|
+
// facade hides the same declaring file as the import it stands for).
|
|
134
|
+
const exportGroups = (exp, names) => {
|
|
135
|
+
const groups = new Map();
|
|
136
|
+
if (!exp.from)
|
|
137
|
+
return groups;
|
|
138
|
+
names.forEach((name, at) => {
|
|
139
|
+
const file = exp.declaring?.[at] ?? null;
|
|
140
|
+
if (!file || file === exp.from)
|
|
141
|
+
return;
|
|
142
|
+
const group = groups.get(file) ?? [];
|
|
143
|
+
group.push(name);
|
|
144
|
+
groups.set(file, group);
|
|
145
|
+
});
|
|
146
|
+
return groups;
|
|
147
|
+
};
|
|
148
|
+
const exportFromEdges = (facts) => (facts.exports ?? []).flatMap((exp) => {
|
|
127
149
|
const names = exp.named ?? [];
|
|
128
|
-
const
|
|
129
|
-
|
|
150
|
+
const groups = exportGroups(exp, names);
|
|
151
|
+
const stayed = names.filter((_, at) => {
|
|
152
|
+
const file = exp.declaring?.[at] ?? null;
|
|
153
|
+
return !file || file === exp.from;
|
|
154
|
+
});
|
|
155
|
+
const fact = (resolved) => ({
|
|
156
|
+
kind: "export",
|
|
157
|
+
form: exp.form ?? "named",
|
|
158
|
+
names: stayed,
|
|
159
|
+
name: exp.name ?? null,
|
|
160
|
+
source: exp.source ?? null,
|
|
161
|
+
resolved,
|
|
162
|
+
reExport: Boolean(exp.from),
|
|
163
|
+
});
|
|
164
|
+
const moduleEdge = edgeOf(facts, {
|
|
165
|
+
path: exp.from ?? facts.location.path,
|
|
166
|
+
line: exp.line ?? 1,
|
|
167
|
+
piece: exportPiece(facts, exp, names),
|
|
168
|
+
external: exp.from ? !isRepoModule(facts, exp.from) : false,
|
|
169
|
+
fact: fact(exp.from ?? null),
|
|
170
|
+
what: exportWhat(exp, exp.from && groups.size ? stayed : names),
|
|
171
|
+
});
|
|
172
|
+
const declaredEdges = [...groups].map(([file, grouped]) => edgeOf(facts, {
|
|
173
|
+
path: file,
|
|
174
|
+
line: exp.line ?? 1,
|
|
175
|
+
piece: null,
|
|
176
|
+
external: !isRepoModule(facts, file),
|
|
177
|
+
fact: { ...fact(file), names: grouped, resolved: file },
|
|
178
|
+
what: `re-exports \`${grouped.join("`, `")}\` of \`${file}\``,
|
|
179
|
+
}));
|
|
180
|
+
return [...(groups.size && !stayed.length ? [] : [moduleEdge]), ...declaredEdges];
|
|
130
181
|
});
|
|
131
182
|
const declaredExportEdges = (facts) => (facts.candidates ?? [])
|
|
132
183
|
.filter((c) => c.exported)
|
|
@@ -135,7 +186,14 @@ const declaredExportEdges = (facts) => (facts.candidates ?? [])
|
|
|
135
186
|
line: lineOf(c),
|
|
136
187
|
piece: c.name ?? null,
|
|
137
188
|
external: false,
|
|
138
|
-
fact: {
|
|
189
|
+
fact: {
|
|
190
|
+
kind: "export",
|
|
191
|
+
form: "declared",
|
|
192
|
+
names: c.name ? [c.name] : [],
|
|
193
|
+
name: c.name ?? null,
|
|
194
|
+
source: null,
|
|
195
|
+
reExport: false,
|
|
196
|
+
},
|
|
139
197
|
what: "is exported",
|
|
140
198
|
}));
|
|
141
199
|
// A declaration that only RENAMES another module's value (`const a = b.c`).
|
|
@@ -156,29 +214,72 @@ const declareEdge = (facts, c) => {
|
|
|
156
214
|
what: renames ? `re-declares \`${renames.action}\` of \`${renames.module}\`` : "is declared here",
|
|
157
215
|
});
|
|
158
216
|
};
|
|
217
|
+
// A named import asks the module to PASS A NAME ON; the law names the file that
|
|
218
|
+
// declares it. Grouping the names by declaring file keeps one edge per target,
|
|
219
|
+
// and a name the chain could not follow stays on the module file.
|
|
220
|
+
const declaredGroups = (imp) => {
|
|
221
|
+
const groups = new Map();
|
|
222
|
+
const module = imp.resolved ?? "";
|
|
223
|
+
(imp.named ?? []).forEach((name, at) => {
|
|
224
|
+
const file = imp.declaring?.[at] ?? null;
|
|
225
|
+
if (!file || file === module)
|
|
226
|
+
return;
|
|
227
|
+
const names = groups.get(file) ?? [];
|
|
228
|
+
names.push(imp.imported?.[at] ?? name);
|
|
229
|
+
groups.set(file, names);
|
|
230
|
+
});
|
|
231
|
+
return groups;
|
|
232
|
+
};
|
|
233
|
+
// The imported TEXT of one target: the module form is unchanged, a declaring
|
|
234
|
+
// file is named with the symbols the file asked it for.
|
|
235
|
+
const importWhat = (imp, file, names) => {
|
|
236
|
+
if (!names?.length || !file)
|
|
237
|
+
return imp.form === "statement" ? `imports \`${imp.resolved}\`` : `requires \`${imp.source}\``;
|
|
238
|
+
return `imports \`${names.join("`, `")}\` of \`${file}\``;
|
|
239
|
+
};
|
|
240
|
+
// Everything a named import touches: the module it wrote (for the names that
|
|
241
|
+
// stayed) plus the file each group of names is declared in.
|
|
242
|
+
const importEdges = (facts, imp, kind) => {
|
|
243
|
+
const groups = declaredGroups(imp);
|
|
244
|
+
const base = { line: imp.line ?? 1, piece: imp.piece ?? null };
|
|
245
|
+
// The plain edge keeps the fact it always had: a target and no symbols.
|
|
246
|
+
const factOf = (file, names) => {
|
|
247
|
+
const base = kind === RELATION.IMPORT
|
|
248
|
+
? { kind, form: imp.form ?? null, source: imp.source ?? null, resolved: file }
|
|
249
|
+
: { kind, source: imp.source ?? null, resolved: file };
|
|
250
|
+
return names?.length ? { ...base, names } : base;
|
|
251
|
+
};
|
|
252
|
+
const edges = [];
|
|
253
|
+
const stayed = (imp.named ?? []).filter((_, at) => !groups.size || !(imp.declaring?.[at] && imp.declaring[at] !== imp.resolved));
|
|
254
|
+
if (stayed.length || !groups.size) {
|
|
255
|
+
edges.push(edgeOf(facts, {
|
|
256
|
+
path: imp.resolved ?? null,
|
|
257
|
+
...base,
|
|
258
|
+
external: !isRepoModule(facts, imp.resolved),
|
|
259
|
+
fact: factOf(imp.resolved ?? null, groups.size ? stayed : null),
|
|
260
|
+
what: importWhat(imp, null, null),
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
for (const [file, names] of groups) {
|
|
264
|
+
edges.push(edgeOf(facts, {
|
|
265
|
+
path: file,
|
|
266
|
+
...base,
|
|
267
|
+
external: !isRepoModule(facts, file),
|
|
268
|
+
fact: factOf(file, names),
|
|
269
|
+
what: importWhat(imp, file, names),
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
return edges;
|
|
273
|
+
};
|
|
159
274
|
const EDGE_FACTS = {
|
|
160
275
|
// `import … from "x"` — a resolved static import.
|
|
161
276
|
[RELATION.IMPORT]: (facts) => (facts.imports ?? [])
|
|
162
277
|
.filter((imp) => imp.resolved && !imp.typeOnly)
|
|
163
|
-
.
|
|
164
|
-
path: imp.resolved ?? null,
|
|
165
|
-
line: imp.line ?? 1,
|
|
166
|
-
piece: imp.piece ?? null,
|
|
167
|
-
external: !isRepoModule(facts, imp.resolved),
|
|
168
|
-
fact: { kind: "import", form: imp.form ?? null, source: imp.source ?? null, resolved: imp.resolved ?? null },
|
|
169
|
-
what: imp.form === "statement" ? `imports \`${imp.resolved}\`` : `requires \`${imp.source}\``,
|
|
170
|
-
})),
|
|
278
|
+
.flatMap((imp) => importEdges(facts, imp, RELATION.IMPORT)),
|
|
171
279
|
// `import type … from "x"` — a TYPE dependency.
|
|
172
280
|
[RELATION.TYPE_IMPORT]: (facts) => (facts.imports ?? [])
|
|
173
281
|
.filter((imp) => imp.resolved && imp.typeOnly)
|
|
174
|
-
.
|
|
175
|
-
path: imp.resolved ?? null,
|
|
176
|
-
line: imp.line ?? 1,
|
|
177
|
-
piece: imp.piece ?? null,
|
|
178
|
-
external: !isRepoModule(facts, imp.resolved),
|
|
179
|
-
fact: { kind: "typeImport", source: imp.source ?? null, resolved: imp.resolved ?? null },
|
|
180
|
-
what: `names a type of \`${imp.resolved}\``,
|
|
181
|
-
})),
|
|
282
|
+
.flatMap((imp) => importEdges(facts, imp, RELATION.TYPE_IMPORT)),
|
|
182
283
|
// EVERY way code leaves the module, whatever the spelling.
|
|
183
284
|
[RELATION.EXPORT]: (facts) => [...exportFromEdges(facts), ...declaredExportEdges(facts)],
|
|
184
285
|
// EVERY declaration: `const`/`let`/`var`, `function`, `class`, and a
|
|
@@ -194,11 +295,11 @@ const EDGE_FACTS = {
|
|
|
194
295
|
[RELATION.READ]: readsOf,
|
|
195
296
|
};
|
|
196
297
|
exports.EDGE_FACTS = EDGE_FACTS;
|
|
197
|
-
// Which
|
|
298
|
+
// Which entities declare an ACTION for each relation: `Map<factKind, Map<entitySlug,
|
|
198
299
|
// action>>`.
|
|
199
300
|
const declaredActions = (arch) => {
|
|
200
301
|
const byFact = new Map();
|
|
201
|
-
for (const [slug, def] of Object.entries(arch.
|
|
302
|
+
for (const [slug, def] of Object.entries(arch.entities ?? {})) {
|
|
202
303
|
for (const [key, action] of Object.entries(def.actions ?? {})) {
|
|
203
304
|
const factKind = action.of ?? key;
|
|
204
305
|
if (!byFact.has(factKind))
|
|
@@ -209,7 +310,7 @@ const declaredActions = (arch) => {
|
|
|
209
310
|
return byFact;
|
|
210
311
|
};
|
|
211
312
|
exports.declaredActions = declaredActions;
|
|
212
|
-
//
|
|
313
|
+
// An entity may only say `of: <kind>` for a relation the engine can see, and every
|
|
213
314
|
// declared kind must have a producer. Checked at load, so a typo fails loudly.
|
|
214
315
|
for (const kind of FACT_KINDS) {
|
|
215
316
|
if (!EDGE_FACTS[kind])
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Arch,
|
|
2
|
-
declare const homesOf: (arch: Arch,
|
|
1
|
+
import type { Arch, EntityHome } from "@md-code/follow-architecture/entities/architecture";
|
|
2
|
+
declare const homesOf: (arch: Arch, entity: string) => EntityHome[];
|
|
3
3
|
type Destination = {
|
|
4
4
|
slug: string | null;
|
|
5
5
|
path: string | null;
|
|
@@ -12,17 +12,17 @@ type Place = {
|
|
|
12
12
|
folder: boolean;
|
|
13
13
|
};
|
|
14
14
|
declare const sharedPrefix: (template: string, rel: string | null) => number;
|
|
15
|
-
declare const destinationsIn: (arch: Arch,
|
|
16
|
-
declare const destinationOf: (arch: Arch,
|
|
17
|
-
declare const placeFor: (arch: Arch,
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
20
|
-
declare const
|
|
21
|
-
|
|
15
|
+
declare const destinationsIn: (arch: Arch, entity: string, rel: string) => Destination[];
|
|
16
|
+
declare const destinationOf: (arch: Arch, entity: string, rel: string) => Destination | null;
|
|
17
|
+
declare const placeFor: (arch: Arch, entity: string, rel: string) => Place | null;
|
|
18
|
+
declare const entityFitsAt: (arch: Arch, entity: string, rel: string | null | undefined) => boolean;
|
|
19
|
+
declare const entitiesAtPath: (arch: Arch, path: string | null | undefined) => string[];
|
|
20
|
+
declare const homeForEntity: (arch: Arch, entity: string, rel: string) => {
|
|
21
|
+
entity: string;
|
|
22
22
|
path: string;
|
|
23
23
|
folder: boolean;
|
|
24
24
|
concrete: boolean;
|
|
25
25
|
node: string | null;
|
|
26
26
|
} | null;
|
|
27
|
-
export { homesOf, sharedPrefix, destinationsIn, destinationOf, placeFor,
|
|
27
|
+
export { homesOf, sharedPrefix, destinationsIn, destinationOf, placeFor, entityFitsAt, entitiesAtPath, homeForEntity };
|
|
28
28
|
export type { Destination, Place };
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
// THE
|
|
3
|
+
exports.homeForEntity = exports.entitiesAtPath = exports.entityFitsAt = exports.placeFor = exports.destinationOf = exports.destinationsIn = exports.sharedPrefix = exports.homesOf = void 0;
|
|
4
|
+
// THE ENTITY → PLACE ANSWER. "Where does code of this entity live" is the SAME
|
|
5
5
|
// question as "what does this place entry resolve to", so this module owns both
|
|
6
6
|
// the declared homes and the concrete place-for-this-file answer.
|
|
7
7
|
//
|
|
8
|
-
// homesOf(arch,
|
|
9
|
-
// placeFor(arch,
|
|
10
|
-
// destinationOf(arch,
|
|
8
|
+
// homesOf(arch, entity) — the path templates that entity may occupy
|
|
9
|
+
// placeFor(arch, entity, rel) — where this entity's code belongs FOR THIS FILE
|
|
10
|
+
// destinationOf(arch, entity, rel) — the concrete, hostable place, or null
|
|
11
11
|
//
|
|
12
|
-
// Nothing here is stored on the
|
|
12
|
+
// Nothing here is stored on the entity: an entity knows what code IS, never which
|
|
13
13
|
// folder it is in. Anything that needs a location asks the tree.
|
|
14
|
-
const match_1 = require("
|
|
14
|
+
const match_1 = require("@md-code/follow-architecture/entities/tree/match");
|
|
15
15
|
const where_1 = require("./where");
|
|
16
16
|
const place_1 = require("./place");
|
|
17
|
-
const rank_1 = require("
|
|
18
|
-
// Every path the tree gives this
|
|
19
|
-
const homesOf = (arch,
|
|
17
|
+
const rank_1 = require("@md-code/follow-architecture/utils/rank");
|
|
18
|
+
// Every path the tree gives this entity, in the order the config declares them.
|
|
19
|
+
const homesOf = (arch, entity) => arch.nodes.entityHomes[entity] ?? [];
|
|
20
20
|
exports.homesOf = homesOf;
|
|
21
21
|
// How much of the template's start this file shares. Used only to pick which
|
|
22
22
|
// branch of a repeating node the file belongs to — never to allow or deny.
|
|
@@ -39,7 +39,9 @@ const sharedPrefix = (template, rel) => {
|
|
|
39
39
|
exports.sharedPrefix = sharedPrefix;
|
|
40
40
|
// The directory a home names: a file child contributes its parent folder.
|
|
41
41
|
const homeDir = (template) => {
|
|
42
|
-
const segs = String(template)
|
|
42
|
+
const segs = String(template)
|
|
43
|
+
.split("/")
|
|
44
|
+
.filter((s) => s !== "**");
|
|
43
45
|
return /\.[A-Za-z0-9]+$/.test(segs[segs.length - 1] ?? "") ? segs.slice(0, -1) : segs;
|
|
44
46
|
};
|
|
45
47
|
// The folder OF A FILE as segments.
|
|
@@ -55,28 +57,43 @@ const sameBranch = (home, dir) => {
|
|
|
55
57
|
// Whether this home is in the file's branch. A home that names ONE FILE only
|
|
56
58
|
// answers for files of exactly that folder; a FOLDER home may sit in a general
|
|
57
59
|
// branch (`packages/utils`) that still applies.
|
|
58
|
-
const branchFor = (fileHome, home, dir) =>
|
|
60
|
+
const branchFor = (fileHome, home, dir) => fileHome ? home.length === dir.length && sameBranch(home, dir) : sameBranch(home, dir);
|
|
59
61
|
const scoreEntry = (entry, i, dir, rel) => {
|
|
60
62
|
const home = homeDir(entry.template);
|
|
61
|
-
const last = String(entry.template)
|
|
63
|
+
const last = String(entry.template)
|
|
64
|
+
.split("/")
|
|
65
|
+
.filter((seg) => seg !== "**")
|
|
66
|
+
.pop() ?? "";
|
|
62
67
|
const fileHome = /\.[A-Za-z0-9]+$/.test(last);
|
|
63
68
|
const branch = branchFor(fileHome, home, dir);
|
|
64
69
|
return { entry, i, keep: branch || !fileHome, branch, score: sharedPrefix(entry.template, rel) };
|
|
65
70
|
};
|
|
66
|
-
// The concrete places
|
|
71
|
+
// The concrete places an entity's code may go FOR THIS FILE, best first. The
|
|
67
72
|
// score-keep-rank walk is the shared `rankedOffers` core — the same one the
|
|
68
73
|
// folder lookalikes use; the scoring policy (branch, prefix, declared order)
|
|
69
74
|
// is this module's own.
|
|
70
|
-
const destinationsIn = (arch,
|
|
71
|
-
const entries = homesOf(arch,
|
|
75
|
+
const destinationsIn = (arch, entity, rel) => {
|
|
76
|
+
const entries = homesOf(arch, entity);
|
|
72
77
|
if (!entries.length)
|
|
73
78
|
return [];
|
|
74
|
-
//
|
|
79
|
+
// An entity with ONE declared place has no branch question to answer.
|
|
75
80
|
if (entries.length === 1 && !/\*\*\s*$/.test(entries[0].template)) {
|
|
76
|
-
return [
|
|
81
|
+
return [
|
|
82
|
+
{
|
|
83
|
+
slug: entries[0].node,
|
|
84
|
+
path: (0, where_1.fillTemplate)(entries[0].template, rel),
|
|
85
|
+
folder: false,
|
|
86
|
+
template: entries[0].template,
|
|
87
|
+
},
|
|
88
|
+
];
|
|
77
89
|
}
|
|
78
90
|
const dir = fileDir(rel);
|
|
79
|
-
const destinationOfEntry = (entry) => ({
|
|
91
|
+
const destinationOfEntry = (entry) => ({
|
|
92
|
+
slug: entry.node,
|
|
93
|
+
path: (0, where_1.fillTemplate)(entry.template, rel),
|
|
94
|
+
folder: /\*\*\s*$/.test(entry.template),
|
|
95
|
+
template: entry.template,
|
|
96
|
+
});
|
|
80
97
|
const kept = (0, rank_1.rankedOffers)(entries.map((entry, i) => ({ entry, i })), ({ entry, i }) => {
|
|
81
98
|
const scored = scoreEntry(entry, i, dir, rel);
|
|
82
99
|
return scored.keep ? { ...destinationOfEntry(entry), branch: scored.branch, score: scored.score, i } : null;
|
|
@@ -84,7 +101,7 @@ const destinationsIn = (arch, role, rel) => {
|
|
|
84
101
|
return kept.map(({ slug, path, folder, template }) => ({ slug, path, folder, template }));
|
|
85
102
|
};
|
|
86
103
|
exports.destinationsIn = destinationsIn;
|
|
87
|
-
// The place
|
|
104
|
+
// The place an entity's code belongs FOR THIS FILE, and only when that place can
|
|
88
105
|
// exist: the FOLDER has to be a real node instance, while a home that names a
|
|
89
106
|
// FILE may still be created — its parent being an instance is enough.
|
|
90
107
|
// Does the node that owns the folder own it for THIS destination (the node
|
|
@@ -93,13 +110,13 @@ const ownsDest = (arch, hit, dest) => {
|
|
|
93
110
|
const parent = arch.nodes.bySlug[dest.slug ?? ""]?.parents[0] ?? null;
|
|
94
111
|
return hit.slug === dest.slug || (parent != null && hit.slug === parent);
|
|
95
112
|
};
|
|
96
|
-
const hostFolder = (dest) => (dest.folder ? dest.path ?? "" : (0, place_1.dirOf)(dest.path ?? ""));
|
|
113
|
+
const hostFolder = (dest) => (dest.folder ? (dest.path ?? "") : (0, place_1.dirOf)(dest.path ?? ""));
|
|
97
114
|
const nodeOk = (arch, dest) => {
|
|
98
115
|
const destNode = arch.nodes.bySlug[dest.slug ?? ""];
|
|
99
116
|
return !destNode || (0, match_1.ancestorsAreReal)(destNode, dest.path ?? "", arch);
|
|
100
117
|
};
|
|
101
|
-
const destinationOf = (arch,
|
|
102
|
-
for (const dest of destinationsIn(arch,
|
|
118
|
+
const destinationOf = (arch, entity, rel) => {
|
|
119
|
+
for (const dest of destinationsIn(arch, entity, rel)) {
|
|
103
120
|
if (!dest?.slug || !dest.path)
|
|
104
121
|
continue;
|
|
105
122
|
if (!nodeOk(arch, dest))
|
|
@@ -114,19 +131,22 @@ const destinationOf = (arch, role, rel) => {
|
|
|
114
131
|
return null;
|
|
115
132
|
};
|
|
116
133
|
exports.destinationOf = destinationOf;
|
|
117
|
-
// WHERE
|
|
118
|
-
const placeFor = (arch,
|
|
119
|
-
const dest = destinationOf(arch,
|
|
134
|
+
// WHERE an entity's code belongs FOR THIS FILE — the ONE answer every caller uses.
|
|
135
|
+
const placeFor = (arch, entity, rel) => {
|
|
136
|
+
const dest = destinationOf(arch, entity, rel);
|
|
120
137
|
if (dest?.path)
|
|
121
138
|
return { path: dest.path, concrete: true, folder: Boolean(dest.folder) };
|
|
122
|
-
const homes = homesOf(arch,
|
|
123
|
-
//
|
|
139
|
+
const homes = homesOf(arch, entity).map((h) => h.template);
|
|
140
|
+
// An entity with SEVERAL homes and none of them hostable here has no answer for
|
|
124
141
|
// this file: picking one would be a guess dressed as advice.
|
|
125
142
|
if (homes.length !== 1) {
|
|
126
|
-
const nearest = destinationsIn(arch,
|
|
143
|
+
const nearest = destinationsIn(arch, entity, rel)[0];
|
|
127
144
|
if (!nearest?.template)
|
|
128
145
|
return null;
|
|
129
|
-
const last = nearest.template
|
|
146
|
+
const last = nearest.template
|
|
147
|
+
.split("/")
|
|
148
|
+
.filter((seg) => seg !== "**")
|
|
149
|
+
.pop() ?? "";
|
|
130
150
|
const folder = /\*\*\s*$/.test(nearest.template) || !/\.[A-Za-z0-9]+$/.test(last);
|
|
131
151
|
return { path: nearest.template.replace(/\/\*\*$/, ""), concrete: false, folder };
|
|
132
152
|
}
|
|
@@ -136,34 +156,40 @@ const placeFor = (arch, role, rel) => {
|
|
|
136
156
|
return { path: only.replace(/\/\*\*$/, ""), concrete: false, folder: true };
|
|
137
157
|
};
|
|
138
158
|
exports.placeFor = placeFor;
|
|
139
|
-
// Does this file sit inside one of the
|
|
140
|
-
const
|
|
159
|
+
// Does this file sit inside one of the entity's homes, asked THROUGH the tree?
|
|
160
|
+
const entityFitsAt = (arch, entity, rel) => {
|
|
141
161
|
if (!rel)
|
|
142
162
|
return false;
|
|
143
|
-
return (arch.nodes.
|
|
163
|
+
return (arch.nodes.entityHomes[entity] ?? []).some((h) => (0, where_1.matchesWhere)({ type: "template", template: h.template }, rel, arch, null, null));
|
|
144
164
|
};
|
|
145
|
-
exports.
|
|
146
|
-
// The
|
|
147
|
-
const
|
|
165
|
+
exports.entityFitsAt = entityFitsAt;
|
|
166
|
+
// The entities whose declared home covers this path — MOST SPECIFIC FIRST.
|
|
167
|
+
const entitiesAtPath = (arch, path) => {
|
|
148
168
|
if (!path)
|
|
149
169
|
return [];
|
|
150
|
-
return Object.keys(arch.nodes.
|
|
151
|
-
.filter((
|
|
152
|
-
.map((
|
|
153
|
-
|
|
170
|
+
return Object.keys(arch.nodes.entityHomes)
|
|
171
|
+
.filter((entity) => entityFitsAt(arch, entity, path))
|
|
172
|
+
.map((entity, i) => ({
|
|
173
|
+
entity,
|
|
154
174
|
i,
|
|
155
|
-
depth: Math.max(0, ...homesOf(arch,
|
|
175
|
+
depth: Math.max(0, ...homesOf(arch, entity).map((h) => sharedPrefix(h.template, path))),
|
|
156
176
|
}))
|
|
157
177
|
.sort((a, b) => b.depth - a.depth || a.i - b.i)
|
|
158
|
-
.map((x) => x.
|
|
178
|
+
.map((x) => x.entity);
|
|
159
179
|
};
|
|
160
|
-
exports.
|
|
161
|
-
// Where
|
|
162
|
-
const
|
|
163
|
-
const place = placeFor(arch,
|
|
180
|
+
exports.entitiesAtPath = entitiesAtPath;
|
|
181
|
+
// Where an entity's code belongs FOR THIS FILE, as the BOX and the PATH together.
|
|
182
|
+
const homeForEntity = (arch, entity, rel) => {
|
|
183
|
+
const place = placeFor(arch, entity, rel);
|
|
164
184
|
if (!place?.path)
|
|
165
185
|
return null;
|
|
166
186
|
const folder = place.folder ? place.path : (0, place_1.dirOf)(place.path);
|
|
167
|
-
return {
|
|
187
|
+
return {
|
|
188
|
+
entity,
|
|
189
|
+
path: place.path,
|
|
190
|
+
folder: place.folder,
|
|
191
|
+
concrete: Boolean(place.concrete),
|
|
192
|
+
node: (0, match_1.folderOwner)(arch, folder)?.slug ?? null,
|
|
193
|
+
};
|
|
168
194
|
};
|
|
169
|
-
exports.
|
|
195
|
+
exports.homeForEntity = homeForEntity;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Leaf, Place } from "
|
|
1
|
+
import type { Leaf, Place } from "@md-code/follow-architecture/entities/facts";
|
|
2
2
|
declare const wordsIn: (name: string | null | undefined) => string[];
|
|
3
3
|
declare const nameOnly: (name: string | null | undefined) => string;
|
|
4
4
|
declare const segmentsOf: (rel: string | null | undefined) => string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dirOf = exports.placeholdersOf = exports.placeOf = exports.leafOf = exports.parentOf = exports.segmentsOf = exports.nameOnly = exports.wordsIn = void 0;
|
|
4
|
-
const split_1 = require("
|
|
4
|
+
const split_1 = require("@md-code/follow-architecture/utils/split");
|
|
5
5
|
const wordsIn = (name) => String(name ?? "")
|
|
6
6
|
// camelCase and ALLCAPS runs: `fileName` → file name, `HTMLParser` → HTML Parser
|
|
7
7
|
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
@@ -32,7 +32,13 @@ const leafOf = (rel) => {
|
|
|
32
32
|
const name = segments[segments.length - 1] ?? "";
|
|
33
33
|
const fileName = nameOnly(name);
|
|
34
34
|
// `x.spec.ts` → [".spec", ".ts"]; `.env` is a name, not an extension.
|
|
35
|
-
const exts = fileName === name
|
|
35
|
+
const exts = fileName === name
|
|
36
|
+
? []
|
|
37
|
+
: name
|
|
38
|
+
.slice(fileName.length)
|
|
39
|
+
.split(".")
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.map((e) => `.${e}`);
|
|
36
42
|
return { path, segments, exts, fileName, words: wordsIn(fileName) };
|
|
37
43
|
};
|
|
38
44
|
exports.leafOf = leafOf;
|
|
@@ -46,7 +52,8 @@ const placeOf = (rel, repoFiles = []) => {
|
|
|
46
52
|
exports.placeOf = placeOf;
|
|
47
53
|
// The placeholders a template still has (`{kebab-case}`), for a sentence that
|
|
48
54
|
// tells the reader what to fill in.
|
|
49
|
-
const placeholdersOf = (template) => [...new Set(String(template ?? "").match(/\{[^}]+\}/g) ?? [])].map((p) => `\`${p}\``).join(", ") ||
|
|
55
|
+
const placeholdersOf = (template) => [...new Set(String(template ?? "").match(/\{[^}]+\}/g) ?? [])].map((p) => `\`${p}\``).join(", ") ||
|
|
56
|
+
"its placeholders";
|
|
50
57
|
exports.placeholdersOf = placeholdersOf;
|
|
51
58
|
// The folder of a path: a file contributes its parent, a folder is itself.
|
|
52
59
|
const dirOf = (path) => {
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
1
|
+
import { type Aliases } from "@md-code/follow-architecture/utils/aliases";
|
|
2
|
+
import { toList, type FieldValue } from "@md-code/follow-architecture/utils/field";
|
|
3
|
+
import type { Arch, WhereEntry } from "@md-code/follow-architecture/entities/architecture";
|
|
4
|
+
import type { FileFacts } from "@md-code/follow-architecture/entities/facts";
|
|
4
5
|
type Caps = Record<string, string | undefined>;
|
|
5
|
-
declare const parseWhereEntry: (entry: FieldValue,
|
|
6
|
-
declare const parseWhere: (value: FieldValue | null | undefined,
|
|
6
|
+
declare const parseWhereEntry: (entry: FieldValue, entities?: Set<string> | null, aliases?: Aliases | null) => WhereEntry;
|
|
7
|
+
declare const parseWhere: (value: FieldValue | null | undefined, entities?: Set<string> | null, aliases?: Aliases | null) => WhereEntry[];
|
|
7
8
|
declare const matchesWhere: (entry: WhereEntry, rel: string, arch: Arch, facts: FileFacts, targetCaps?: Caps) => boolean;
|
|
8
9
|
declare const checkWhere: (entries: WhereEntry[], rel: string, arch: Arch, facts: FileFacts, targetCaps?: Caps) => boolean;
|
|
9
10
|
declare const accessorLabel: (e: {
|
|
10
11
|
scope?: string | null;
|
|
11
12
|
segments?: string[] | null;
|
|
13
|
+
type?: string | null;
|
|
12
14
|
} | null | undefined) => string;
|
|
13
15
|
declare const labelOf: (entry: WhereEntry | null | undefined) => string;
|
|
14
16
|
declare const fillTemplate: (template: string | null | undefined, rel?: string | null, caps?: Caps | null) => string | null;
|
|
15
17
|
declare const entryKey: (entry: WhereEntry, rel: string, arch: Arch, facts: FileFacts | null | undefined) => string | null;
|
|
16
|
-
export { toList, parseWhereEntry, parseWhere, matchesWhere, checkWhere, accessorLabel, labelOf, fillTemplate, entryKey };
|
|
18
|
+
export { toList, parseWhereEntry, parseWhere, matchesWhere, checkWhere, accessorLabel, labelOf, fillTemplate, entryKey, };
|
|
17
19
|
export type { Caps };
|