@granular-software/fractory 0.0.0-stage → 0.1.24
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/LICENSE +4 -0
- package/README.md +28 -2
- package/dist/activity-volume.d.ts +18 -0
- package/dist/activity-volume.js +94 -0
- package/dist/annotations.d.ts +118 -0
- package/dist/annotations.js +304 -0
- package/dist/benchmark-cli.d.ts +1 -0
- package/dist/benchmark-cli.js +95 -0
- package/dist/benchmark-worker.d.ts +2 -0
- package/dist/benchmark-worker.js +22 -0
- package/dist/benchmarks.d.ts +19 -0
- package/dist/benchmarks.js +414 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +63 -0
- package/dist/block-cli.d.ts +1 -0
- package/dist/block-cli.js +88 -0
- package/dist/block-documents.d.ts +35 -0
- package/dist/block-documents.js +84 -0
- package/dist/change-impact.d.ts +55 -0
- package/dist/change-impact.js +223 -0
- package/dist/check-source.d.ts +2 -0
- package/dist/check-source.js +66 -0
- package/dist/checks-model.d.ts +64 -0
- package/dist/checks-model.js +36 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +359 -0
- package/dist/code-model.d.ts +38 -0
- package/dist/code-model.js +94 -0
- package/dist/code-store.d.ts +9 -0
- package/dist/code-store.js +79 -0
- package/dist/compare-artifact.d.ts +6 -0
- package/dist/compare-artifact.js +277 -0
- package/dist/compare.d.ts +81 -0
- package/dist/compare.js +291 -0
- package/dist/compiler.d.ts +10 -0
- package/dist/compiler.js +1083 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +206 -0
- package/dist/coverage-cli.d.ts +1 -0
- package/dist/coverage-cli.js +42 -0
- package/dist/declaration-sources.d.ts +3 -0
- package/dist/declaration-sources.js +51 -0
- package/dist/declared-graph.d.ts +3 -0
- package/dist/declared-graph.js +66 -0
- package/dist/display-name.d.ts +2 -0
- package/dist/display-name.js +8 -0
- package/dist/error-heat.d.ts +58 -0
- package/dist/error-heat.js +96 -0
- package/dist/evidence.d.ts +3 -0
- package/dist/evidence.js +68 -0
- package/dist/factory-graph.d.ts +4 -0
- package/dist/factory-graph.js +318 -0
- package/dist/factory-model.d.ts +97 -0
- package/dist/factory-model.js +1 -0
- package/dist/git-code.d.ts +47 -0
- package/dist/git-code.js +352 -0
- package/dist/git-refs.d.ts +4 -0
- package/dist/git-refs.js +37 -0
- package/dist/history-activity.d.ts +4 -0
- package/dist/history-activity.js +129 -0
- package/dist/history-churn.d.ts +36 -0
- package/dist/history-churn.js +302 -0
- package/dist/history-git.d.ts +21 -0
- package/dist/history-git.js +125 -0
- package/dist/history-ledger.d.ts +43 -0
- package/dist/history-ledger.js +450 -0
- package/dist/history-ownership.d.ts +10 -0
- package/dist/history-ownership.js +75 -0
- package/dist/history-source.d.ts +13 -0
- package/dist/history-source.js +100 -0
- package/dist/integrations-cli.d.ts +2 -0
- package/dist/integrations-cli.js +159 -0
- package/dist/issue-cache.d.ts +9 -0
- package/dist/issue-cache.js +68 -0
- package/dist/issue-cli.d.ts +1 -0
- package/dist/issue-cli.js +89 -0
- package/dist/issue-links.d.ts +15 -0
- package/dist/issue-links.js +125 -0
- package/dist/linear-issues.d.ts +19 -0
- package/dist/linear-issues.js +124 -0
- package/dist/local-runtime.d.ts +8 -0
- package/dist/local-runtime.js +59 -0
- package/dist/map-activity.d.ts +73 -0
- package/dist/map-activity.js +234 -0
- package/dist/map-model.d.ts +5 -0
- package/dist/map-model.js +166 -0
- package/dist/map-quality.d.ts +14 -0
- package/dist/map-quality.js +56 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +182 -0
- package/dist/model.js +66 -0
- package/dist/operation-benchmark-worker.d.ts +2 -0
- package/dist/operation-benchmark-worker.js +60 -0
- package/dist/operation-benchmark.d.ts +29 -0
- package/dist/operation-benchmark.js +1 -0
- package/dist/otel-metrics.d.ts +21 -0
- package/dist/otel-metrics.js +146 -0
- package/dist/performance-model.d.ts +185 -0
- package/dist/performance-model.js +396 -0
- package/dist/product-map.d.ts +69 -0
- package/dist/product-map.js +168 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -0
- package/dist/reports-cli.d.ts +1 -0
- package/dist/reports-cli.js +111 -0
- package/dist/reports-model.d.ts +27 -0
- package/dist/reports-model.js +39 -0
- package/dist/reports.d.ts +23 -0
- package/dist/reports.js +223 -0
- package/dist/repository-map.d.ts +22 -0
- package/dist/repository-map.js +151 -0
- package/dist/resource-cache.d.ts +17 -0
- package/dist/resource-cache.js +65 -0
- package/dist/review-cli.d.ts +19 -0
- package/dist/review-cli.js +224 -0
- package/dist/review.d.ts +48 -0
- package/dist/review.js +289 -0
- package/dist/runtime-metrics.d.ts +26 -0
- package/dist/runtime-metrics.js +290 -0
- package/dist/scope.d.ts +12 -0
- package/dist/scope.js +94 -0
- package/dist/sentry-activity.d.ts +39 -0
- package/dist/sentry-activity.js +174 -0
- package/dist/sentry.d.ts +130 -0
- package/dist/sentry.js +369 -0
- package/dist/service-release.d.ts +16 -0
- package/dist/service-release.js +14 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +52 -0
- package/dist/setup-kit.cjs +163 -0
- package/dist/setup-kit.d.cts +32 -0
- package/dist/source-index.d.ts +37 -0
- package/dist/source-index.js +166 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +103 -0
- package/dist/source-review.d.ts +16 -0
- package/dist/source-review.js +493 -0
- package/dist/telemetry.d.ts +17 -0
- package/dist/telemetry.js +51 -0
- package/dist/time-window.d.ts +9 -0
- package/dist/time-window.js +35 -0
- package/dist/trace-evidence.d.ts +23 -0
- package/dist/trace-evidence.js +55 -0
- package/dist/trace-model.d.ts +26 -0
- package/dist/trace-model.js +1 -0
- package/dist/tracing.d.ts +44 -0
- package/dist/tracing.js +123 -0
- package/dist/work-check.d.ts +17 -0
- package/dist/work-check.js +110 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +148 -0
- package/dist/work-context.d.ts +57 -0
- package/dist/work-context.js +568 -0
- package/dist/work-intents.d.ts +6 -0
- package/dist/work-intents.js +140 -0
- package/dist/work-items.d.ts +58 -0
- package/dist/work-items.js +86 -0
- package/dist/work-model.d.ts +110 -0
- package/dist/work-model.js +261 -0
- package/dist/work-review-git.d.ts +8 -0
- package/dist/work-review-git.js +111 -0
- package/dist/work-review.d.ts +26 -0
- package/dist/work-review.js +426 -0
- package/dist/work-switcher-model.d.ts +43 -0
- package/dist/work-switcher-model.js +79 -0
- package/dist/work-switcher.d.ts +6 -0
- package/dist/work-switcher.js +171 -0
- package/dist/working-cli.d.ts +1 -0
- package/dist/working-cli.js +33 -0
- package/dist/working-code.d.ts +74 -0
- package/dist/working-code.js +421 -0
- package/dist/workspace-notes.d.ts +71 -0
- package/dist/workspace-notes.js +177 -0
- package/dist/workspace-tests.d.ts +21 -0
- package/dist/workspace-tests.js +573 -0
- package/package.json +547 -4
- package/src/activity-volume.ts +149 -0
- package/src/annotations.ts +481 -0
- package/src/benchmark-cli.ts +118 -0
- package/src/benchmark-worker.ts +22 -0
- package/src/benchmarks.ts +493 -0
- package/src/bin.ts +54 -0
- package/src/block-cli.ts +106 -0
- package/src/block-documents.ts +117 -0
- package/src/change-impact.ts +280 -0
- package/src/check-source.ts +82 -0
- package/src/checks-model.ts +108 -0
- package/src/cli.ts +440 -0
- package/src/code-model.ts +159 -0
- package/src/code-store.ts +98 -0
- package/src/compare-artifact.ts +314 -0
- package/src/compare.ts +440 -0
- package/src/compiler.ts +1326 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +357 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +74 -0
- package/src/display-name.ts +8 -0
- package/src/error-heat.ts +161 -0
- package/src/evidence.ts +94 -0
- package/src/factory-graph.ts +378 -0
- package/src/factory-model.ts +73 -0
- package/src/git-code.ts +461 -0
- package/src/git-refs.ts +43 -0
- package/src/history-activity.ts +146 -0
- package/src/history-churn.ts +416 -0
- package/src/history-git.ts +163 -0
- package/src/history-ledger.ts +636 -0
- package/src/history-ownership.ts +116 -0
- package/src/history-source.ts +117 -0
- package/src/integrations-cli.ts +187 -0
- package/src/issue-cache.ts +96 -0
- package/src/issue-cli.ts +137 -0
- package/src/issue-links.ts +153 -0
- package/src/linear-issues.ts +154 -0
- package/src/local-runtime.ts +70 -0
- package/src/map-activity.ts +309 -0
- package/src/map-model.ts +213 -0
- package/src/map-quality.ts +61 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +221 -0
- package/src/operation-benchmark-worker.ts +60 -0
- package/src/operation-benchmark.ts +28 -0
- package/src/otel-metrics.ts +176 -0
- package/src/performance-model.ts +575 -0
- package/src/product-map.ts +236 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -0
- package/src/reports-cli.ts +125 -0
- package/src/reports-model.ts +73 -0
- package/src/reports.ts +276 -0
- package/src/repository-map.ts +189 -0
- package/src/resource-cache.ts +76 -0
- package/src/review-cli.ts +256 -0
- package/src/review.ts +376 -0
- package/src/runtime-metrics.ts +386 -0
- package/src/scope.ts +103 -0
- package/src/sentry-activity.ts +234 -0
- package/src/sentry.ts +545 -0
- package/src/service-release.ts +18 -0
- package/src/setup-cli.ts +58 -0
- package/src/setup-kit.cjs +163 -0
- package/src/setup-kit.d.cts +32 -0
- package/src/source-index.ts +205 -0
- package/src/source-review-git.ts +129 -0
- package/src/source-review.ts +637 -0
- package/src/telemetry.ts +68 -0
- package/src/time-window.ts +51 -0
- package/src/trace-evidence.ts +80 -0
- package/src/trace-model.ts +26 -0
- package/src/tracing.ts +165 -0
- package/src/work-check.ts +143 -0
- package/src/work-cli.ts +195 -0
- package/src/work-context.ts +713 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-model.ts +400 -0
- package/src/work-review-git.ts +130 -0
- package/src/work-review.ts +573 -0
- package/src/work-switcher-model.ts +121 -0
- package/src/work-switcher.ts +191 -0
- package/src/working-cli.ts +38 -0
- package/src/working-code.ts +582 -0
- package/src/workspace-notes.ts +203 -0
- package/src/workspace-tests.ts +654 -0
- package/toolkit/GUIDE.md +305 -0
- package/toolkit/SKILL.md +131 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,1083 @@
|
|
|
1
|
+
/** Build-time only: collect declarations and types without importing application code. */
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { resolve, relative, dirname, isAbsolute, join } from "node:path";
|
|
5
|
+
import { readdirSync, readFileSync, existsSync } from "node:fs";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
const digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
8
|
+
const names = new Set(["Block", "Interface", "Method", "Process"]);
|
|
9
|
+
/** Incremental build entry discovery: inspect source text, never import app modules. */
|
|
10
|
+
export function annotatedFiles(root, directories = ["apps", "packages", "src"]) {
|
|
11
|
+
const files = [];
|
|
12
|
+
const visit = (directory) => {
|
|
13
|
+
if (!existsSync(directory))
|
|
14
|
+
return;
|
|
15
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
16
|
+
if ((entry.isDirectory() && entry.name.startsWith(".")) ||
|
|
17
|
+
[
|
|
18
|
+
"node_modules",
|
|
19
|
+
".git",
|
|
20
|
+
".next",
|
|
21
|
+
".next-fractal",
|
|
22
|
+
"dist",
|
|
23
|
+
"generated",
|
|
24
|
+
"__tests__",
|
|
25
|
+
"test",
|
|
26
|
+
"e2e",
|
|
27
|
+
].includes(entry.name))
|
|
28
|
+
continue;
|
|
29
|
+
const file = join(directory, entry.name);
|
|
30
|
+
if (entry.isDirectory())
|
|
31
|
+
visit(file);
|
|
32
|
+
else if (/\.tsx?$/.test(entry.name) &&
|
|
33
|
+
!/\.(test|spec|d)\.tsx?$/.test(entry.name) &&
|
|
34
|
+
/from\s*["']@granular-software\/fract(?:al|ory)(?:\/annotations)?["']/.test(readFileSync(file, "utf8")))
|
|
35
|
+
files.push(relative(root, file));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
for (const directory of directories)
|
|
39
|
+
visit(resolve(root, directory));
|
|
40
|
+
return files.sort();
|
|
41
|
+
}
|
|
42
|
+
export function compileFactory(options) {
|
|
43
|
+
const root = resolve(options.root);
|
|
44
|
+
const sdkSource = options.sdkSource ||
|
|
45
|
+
resolve(dirname(fileURLToPath(import.meta.url)), "../src/annotations.ts");
|
|
46
|
+
// Public workspace packages point to dist for consumers. Architecture and
|
|
47
|
+
// contracts must come from source, regardless of local build state.
|
|
48
|
+
// Runtime hosts may carry a generated copy (e.g. a standalone CommonJS
|
|
49
|
+
// container). Always resolve the annotation API to this compiler's canonical
|
|
50
|
+
// SDK source so build artifacts cannot silently erase declarations.
|
|
51
|
+
const paths = {
|
|
52
|
+
"@granular-software/fractal/annotations": [sdkSource],
|
|
53
|
+
"@granular-software/fractory/annotations": [sdkSource],
|
|
54
|
+
};
|
|
55
|
+
const packages = new Set();
|
|
56
|
+
for (const file of options.files) {
|
|
57
|
+
let directory = dirname(resolve(root, file));
|
|
58
|
+
while (directory !== root && !relative(root, directory).startsWith("..")) {
|
|
59
|
+
const manifest = join(directory, "package.json");
|
|
60
|
+
if (existsSync(manifest)) {
|
|
61
|
+
if (!packages.has(directory)) {
|
|
62
|
+
packages.add(directory);
|
|
63
|
+
const name = JSON.parse(readFileSync(manifest, "utf8")).name;
|
|
64
|
+
const entry = ["src/index.ts", "src/index.tsx"]
|
|
65
|
+
.map((path) => join(directory, path))
|
|
66
|
+
.find(existsSync);
|
|
67
|
+
if (typeof name === "string" && entry)
|
|
68
|
+
paths[name] = [entry];
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
directory = dirname(directory);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const compilerOptions = {
|
|
76
|
+
target: ts.ScriptTarget.ES2022,
|
|
77
|
+
module: ts.ModuleKind.ESNext,
|
|
78
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
79
|
+
skipLibCheck: true,
|
|
80
|
+
noEmit: true,
|
|
81
|
+
types: [],
|
|
82
|
+
allowJs: true,
|
|
83
|
+
resolveJsonModule: true,
|
|
84
|
+
baseUrl: root,
|
|
85
|
+
paths,
|
|
86
|
+
};
|
|
87
|
+
// Alias resolution belongs to the importing host, not one monorepo-wide base
|
|
88
|
+
// folder. Reuse its real tsconfig paths while retaining canonical SDK source.
|
|
89
|
+
const host = ts.createCompilerHost(compilerOptions);
|
|
90
|
+
const resolutions = new Map();
|
|
91
|
+
host.resolveModuleNames = (names, containingFile) => {
|
|
92
|
+
const config = ts.findConfigFile(dirname(containingFile), ts.sys.fileExists, "tsconfig.json");
|
|
93
|
+
const key = config || root;
|
|
94
|
+
if (!resolutions.has(key)) {
|
|
95
|
+
let localPaths = {};
|
|
96
|
+
if (config) {
|
|
97
|
+
const read = ts.readConfigFile(config, ts.sys.readFile);
|
|
98
|
+
if (!read.error) {
|
|
99
|
+
const parsed = ts.parseJsonConfigFileContent({ ...read.config, files: [], include: [], exclude: [] }, ts.sys, dirname(config));
|
|
100
|
+
const base = parsed.options.baseUrl || dirname(config);
|
|
101
|
+
localPaths = Object.fromEntries(Object.entries(parsed.options.paths || {}).map(([name, values]) => [
|
|
102
|
+
name,
|
|
103
|
+
values.map((value) => resolve(base, value)),
|
|
104
|
+
]));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const options = {
|
|
108
|
+
...compilerOptions,
|
|
109
|
+
paths: { ...localPaths, ...paths },
|
|
110
|
+
};
|
|
111
|
+
resolutions.set(key, {
|
|
112
|
+
options,
|
|
113
|
+
cache: ts.createModuleResolutionCache(root, (f) => f, options),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const resolution = resolutions.get(key);
|
|
117
|
+
return names.map((name) => ts.resolveModuleName(name, containingFile, resolution.options, host, resolution.cache).resolvedModule);
|
|
118
|
+
};
|
|
119
|
+
const program = ts.createProgram(options.files.map((file) => resolve(root, file)), compilerOptions, host);
|
|
120
|
+
const checker = program.getTypeChecker();
|
|
121
|
+
const model = {
|
|
122
|
+
schema: "fractal.factory.v2",
|
|
123
|
+
revision: "",
|
|
124
|
+
blocks: [],
|
|
125
|
+
interfaces: [],
|
|
126
|
+
methods: [],
|
|
127
|
+
processes: [],
|
|
128
|
+
dependencies: [],
|
|
129
|
+
diagnostics: [],
|
|
130
|
+
};
|
|
131
|
+
const blocks = new Map();
|
|
132
|
+
const apis = new Map();
|
|
133
|
+
const pending = [];
|
|
134
|
+
const methodDeclarations = new Map();
|
|
135
|
+
const fileName = (node) => relative(root, node.getSourceFile().fileName).replaceAll("\\", "/");
|
|
136
|
+
const source = (node) => ({
|
|
137
|
+
file: fileName(node),
|
|
138
|
+
line: node.getSourceFile().getLineAndCharacterOfPosition(node.getStart()).line +
|
|
139
|
+
1,
|
|
140
|
+
digest: digest(node.getSourceFile().text).slice(0, 16),
|
|
141
|
+
});
|
|
142
|
+
const problem = (node, message) => model.diagnostics.push({
|
|
143
|
+
file: fileName(node),
|
|
144
|
+
line: source(node).line,
|
|
145
|
+
message,
|
|
146
|
+
});
|
|
147
|
+
const symbol = (node) => {
|
|
148
|
+
let value = checker.getSymbolAtLocation(node);
|
|
149
|
+
if (value && value.flags & ts.SymbolFlags.Alias)
|
|
150
|
+
value = checker.getAliasedSymbol(value);
|
|
151
|
+
return value;
|
|
152
|
+
};
|
|
153
|
+
const annotation = (call) => {
|
|
154
|
+
const value = symbol(call.expression);
|
|
155
|
+
if (!value || !names.has(value.name))
|
|
156
|
+
return;
|
|
157
|
+
// Only our SDK: a different library's @Method must not enter this model.
|
|
158
|
+
if (!value.declarations?.some((decl) => resolve(decl.getSourceFile().fileName) === resolve(sdkSource) ||
|
|
159
|
+
/(?:^|\/)fractal\/src\/annotations\.ts$/.test(decl.getSourceFile().fileName.replaceAll("\\", "/"))))
|
|
160
|
+
return;
|
|
161
|
+
return value.name;
|
|
162
|
+
};
|
|
163
|
+
const property = (node, key) => {
|
|
164
|
+
if (!node || !ts.isObjectLiteralExpression(node))
|
|
165
|
+
return;
|
|
166
|
+
const member = node.properties.find((p) => p.name?.getText().replace(/['"]/g, "") === key);
|
|
167
|
+
return member && ts.isPropertyAssignment(member)
|
|
168
|
+
? member.initializer
|
|
169
|
+
: undefined;
|
|
170
|
+
};
|
|
171
|
+
const text = (node) => node &&
|
|
172
|
+
(ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node))
|
|
173
|
+
? node.text
|
|
174
|
+
: undefined;
|
|
175
|
+
const strings = (node) => !node
|
|
176
|
+
? []
|
|
177
|
+
: ts.isArrayLiteralExpression(node)
|
|
178
|
+
? node.elements.flatMap((e) => (text(e) ? [text(e)] : []))
|
|
179
|
+
: text(node)
|
|
180
|
+
? [text(node)]
|
|
181
|
+
: [];
|
|
182
|
+
const attachments = (config, owner) => {
|
|
183
|
+
const paths = (key) => strings(property(config, key)).map((path) => {
|
|
184
|
+
const [file, fragment] = path.split("#");
|
|
185
|
+
const full = isAbsolute(file)
|
|
186
|
+
? file
|
|
187
|
+
: resolve(dirname(owner.getSourceFile().fileName), file);
|
|
188
|
+
return (relative(root, full).replaceAll("\\", "/") +
|
|
189
|
+
(fragment ? `#${fragment}` : ""));
|
|
190
|
+
});
|
|
191
|
+
const auth = property(config, "auth");
|
|
192
|
+
const documented = [owner];
|
|
193
|
+
let container = owner.parent;
|
|
194
|
+
while (container &&
|
|
195
|
+
documented.length < 8 &&
|
|
196
|
+
(ts.isCallExpression(container) ||
|
|
197
|
+
ts.isVariableDeclaration(container) ||
|
|
198
|
+
ts.isVariableDeclarationList(container) ||
|
|
199
|
+
ts.isVariableStatement(container) ||
|
|
200
|
+
ts.isExpressionStatement(container) ||
|
|
201
|
+
ts.isParenthesizedExpression(container) ||
|
|
202
|
+
ts.isPropertyAssignment(container))) {
|
|
203
|
+
documented.push(container);
|
|
204
|
+
container = container.parent;
|
|
205
|
+
}
|
|
206
|
+
const documentation = documented
|
|
207
|
+
.filter((node) => !!node)
|
|
208
|
+
.flatMap((node) => ts.getJSDocCommentsAndTags(node))
|
|
209
|
+
.find((node) => node.kind === ts.SyntaxKind.JSDoc);
|
|
210
|
+
const comment = typeof documentation?.comment === "string"
|
|
211
|
+
? documentation.comment
|
|
212
|
+
: documentation?.comment?.map((part) => part.text).join("");
|
|
213
|
+
const description = text(property(config, "description")) ||
|
|
214
|
+
comment
|
|
215
|
+
?.split(/\n\s*\n/)[0]
|
|
216
|
+
.replace(/\s+/g, " ")
|
|
217
|
+
.trim();
|
|
218
|
+
return {
|
|
219
|
+
docs: paths("docs"),
|
|
220
|
+
tests: paths("tests"),
|
|
221
|
+
...(paths("benchmarks").length
|
|
222
|
+
? { benchmarks: paths("benchmarks") }
|
|
223
|
+
: {}),
|
|
224
|
+
...(description ? { description } : {}),
|
|
225
|
+
...(auth
|
|
226
|
+
? {
|
|
227
|
+
auth: {
|
|
228
|
+
symbol: symbol(auth)?.name || "inline policy",
|
|
229
|
+
source: source(auth),
|
|
230
|
+
},
|
|
231
|
+
}
|
|
232
|
+
: {}),
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
const configOf = (call) => ts.isObjectLiteralExpression(call.arguments[0])
|
|
236
|
+
? call.arguments[0]
|
|
237
|
+
: call.arguments[1];
|
|
238
|
+
const resolvedNode = (expression) => {
|
|
239
|
+
if (!expression)
|
|
240
|
+
return;
|
|
241
|
+
if (ts.isArrowFunction(expression)) {
|
|
242
|
+
if (ts.isBlock(expression.body)) {
|
|
243
|
+
const statement = expression.body.statements.find(ts.isReturnStatement);
|
|
244
|
+
return resolvedNode(statement?.expression);
|
|
245
|
+
}
|
|
246
|
+
return resolvedNode(expression.body);
|
|
247
|
+
}
|
|
248
|
+
if (ts.isParenthesizedExpression(expression) ||
|
|
249
|
+
ts.isAsExpression(expression))
|
|
250
|
+
return resolvedNode(expression.expression);
|
|
251
|
+
const declaration = symbol(expression)?.valueDeclaration ||
|
|
252
|
+
symbol(expression)?.declarations?.[0];
|
|
253
|
+
if (declaration &&
|
|
254
|
+
(ts.isVariableDeclaration(declaration) ||
|
|
255
|
+
ts.isExportAssignment(declaration)) &&
|
|
256
|
+
(ts.isVariableDeclaration(declaration)
|
|
257
|
+
? declaration.initializer
|
|
258
|
+
: declaration.expression)) {
|
|
259
|
+
const value = ts.isVariableDeclaration(declaration)
|
|
260
|
+
? declaration.initializer
|
|
261
|
+
: declaration.expression;
|
|
262
|
+
if (ts.isCallExpression(value) &&
|
|
263
|
+
ts.isCallExpression(value.expression) &&
|
|
264
|
+
annotation(value.expression) &&
|
|
265
|
+
value.arguments[0] &&
|
|
266
|
+
(callable(value.arguments[0]) ||
|
|
267
|
+
annotation(value.expression) === "Block"))
|
|
268
|
+
return value.arguments[0];
|
|
269
|
+
if (ts.isIdentifier(value) || ts.isPropertyAccessExpression(value))
|
|
270
|
+
return resolvedNode(value);
|
|
271
|
+
}
|
|
272
|
+
return declaration;
|
|
273
|
+
};
|
|
274
|
+
const nearestBlock = (node) => {
|
|
275
|
+
let parent = node.parent;
|
|
276
|
+
while (parent) {
|
|
277
|
+
if (blocks.has(parent))
|
|
278
|
+
return blocks.get(parent);
|
|
279
|
+
parent = parent.parent;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const callable = (node) => {
|
|
283
|
+
if (ts.isMethodDeclaration(node) ||
|
|
284
|
+
ts.isFunctionDeclaration(node) ||
|
|
285
|
+
ts.isFunctionExpression(node) ||
|
|
286
|
+
ts.isArrowFunction(node))
|
|
287
|
+
return node;
|
|
288
|
+
return;
|
|
289
|
+
};
|
|
290
|
+
const typeSources = (declaration) => {
|
|
291
|
+
const seen = new Set(), files = new Map();
|
|
292
|
+
const pending = [
|
|
293
|
+
...declaration.parameters.flatMap((parameter) => parameter.type ? [parameter.type] : []),
|
|
294
|
+
...(declaration.type ? [declaration.type] : []),
|
|
295
|
+
];
|
|
296
|
+
while (pending.length && seen.size < 256) {
|
|
297
|
+
const node = pending.pop();
|
|
298
|
+
if (seen.has(node))
|
|
299
|
+
continue;
|
|
300
|
+
seen.add(node);
|
|
301
|
+
const visit = (part) => {
|
|
302
|
+
if (ts.isTypeReferenceNode(part) || ts.isTypeQueryNode(part)) {
|
|
303
|
+
const target = resolvedNode(ts.isTypeReferenceNode(part) ? part.typeName : part.exprName);
|
|
304
|
+
if (target) {
|
|
305
|
+
const file = fileName(target);
|
|
306
|
+
if (!file.startsWith("..") &&
|
|
307
|
+
!file.includes("node_modules/") &&
|
|
308
|
+
!target.getSourceFile().isDeclarationFile) {
|
|
309
|
+
if (!files.has(file))
|
|
310
|
+
files.set(file, source(target));
|
|
311
|
+
if (ts.isInterfaceDeclaration(target) ||
|
|
312
|
+
ts.isTypeAliasDeclaration(target) ||
|
|
313
|
+
ts.isTypeParameterDeclaration(target))
|
|
314
|
+
pending.push(target);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
ts.forEachChild(part, visit);
|
|
319
|
+
};
|
|
320
|
+
visit(node);
|
|
321
|
+
}
|
|
322
|
+
return [...files.values()].sort((a, b) => a.file.localeCompare(b.file));
|
|
323
|
+
};
|
|
324
|
+
const allFiles = program
|
|
325
|
+
.getSourceFiles()
|
|
326
|
+
.filter((file) => !file.isDeclarationFile &&
|
|
327
|
+
!file.fileName.includes("node_modules") &&
|
|
328
|
+
!relative(root, file.fileName).startsWith(".."));
|
|
329
|
+
for (const file of allFiles) {
|
|
330
|
+
const visit = (node) => {
|
|
331
|
+
if (ts.canHaveDecorators(node))
|
|
332
|
+
for (const decorator of ts.getDecorators(node) || []) {
|
|
333
|
+
if (!ts.isCallExpression(decorator.expression))
|
|
334
|
+
continue;
|
|
335
|
+
const kind = annotation(decorator.expression);
|
|
336
|
+
if (kind)
|
|
337
|
+
pending.push({ node, call: decorator.expression, kind });
|
|
338
|
+
}
|
|
339
|
+
// Native inline form: Method(() => Owner.interface)(existing function expression).
|
|
340
|
+
if (ts.isCallExpression(node) && ts.isCallExpression(node.expression)) {
|
|
341
|
+
const kind = annotation(node.expression);
|
|
342
|
+
if (kind &&
|
|
343
|
+
node.arguments[0] &&
|
|
344
|
+
(callable(node.arguments[0]) || kind === "Block"))
|
|
345
|
+
pending.push({
|
|
346
|
+
node: node.arguments[0],
|
|
347
|
+
call: node.expression,
|
|
348
|
+
kind,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
if (ts.isVariableDeclaration(node) &&
|
|
352
|
+
node.initializer &&
|
|
353
|
+
ts.isCallExpression(node.initializer) &&
|
|
354
|
+
annotation(node.initializer) === "Interface" &&
|
|
355
|
+
(property(node.initializer.arguments[0], "parent") ||
|
|
356
|
+
text(node.initializer.arguments[0])))
|
|
357
|
+
pending.push({ node, call: node.initializer, kind: "Interface" });
|
|
358
|
+
ts.forEachChild(node, visit);
|
|
359
|
+
};
|
|
360
|
+
visit(file);
|
|
361
|
+
}
|
|
362
|
+
for (const item of pending.filter((p) => p.kind === "Block" || p.kind === "Process")) {
|
|
363
|
+
const { node, call, kind } = item;
|
|
364
|
+
const config = configOf(call);
|
|
365
|
+
const id = text(call.arguments[0]) || text(property(config, "id"));
|
|
366
|
+
if (!id?.trim()) {
|
|
367
|
+
problem(node, "Block/process needs one stable literal identity");
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (model.blocks.some((block) => block.id === id)) {
|
|
371
|
+
problem(node, `Duplicate block identity: ${id}`);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const label = text(property(config, "label")) || id.split("/").at(-1);
|
|
375
|
+
const block = {
|
|
376
|
+
id,
|
|
377
|
+
...(text(property(config, "inputLabel"))
|
|
378
|
+
? { inputLabel: text(property(config, "inputLabel")) }
|
|
379
|
+
: {}),
|
|
380
|
+
...(text(property(config, "eventLabel"))
|
|
381
|
+
? { eventLabel: text(property(config, "eventLabel")) }
|
|
382
|
+
: {}),
|
|
383
|
+
label,
|
|
384
|
+
source: source(node),
|
|
385
|
+
attachments: attachments(config, node),
|
|
386
|
+
};
|
|
387
|
+
blocks.set(node, block);
|
|
388
|
+
model.blocks.push(block);
|
|
389
|
+
if (kind === "Block" &&
|
|
390
|
+
!ts.isClassDeclaration(node) &&
|
|
391
|
+
!callable(node) &&
|
|
392
|
+
!ts.isNewExpression(node) &&
|
|
393
|
+
!ts.isObjectLiteralExpression(node) &&
|
|
394
|
+
!ts.isCallExpression(node))
|
|
395
|
+
problem(node, "@Block requires an existing class, function or object");
|
|
396
|
+
if (kind === "Process" && !callable(node))
|
|
397
|
+
problem(node, "@Process requires an existing callable");
|
|
398
|
+
}
|
|
399
|
+
for (const item of pending.filter((p) => p.kind === "Block" || p.kind === "Process")) {
|
|
400
|
+
const block = blocks.get(item.node);
|
|
401
|
+
if (!block)
|
|
402
|
+
continue;
|
|
403
|
+
const parentRef = property(configOf(item.call), "parent");
|
|
404
|
+
const parentNode = resolvedNode(parentRef);
|
|
405
|
+
const parent = parentRef
|
|
406
|
+
? parentNode && blocks.get(parentNode)
|
|
407
|
+
: nearestBlock(item.node);
|
|
408
|
+
if (parentRef && !parent)
|
|
409
|
+
problem(item.node, "Logical parent must reference an annotated block/process declaration");
|
|
410
|
+
if (parent)
|
|
411
|
+
block.parent = parent.id;
|
|
412
|
+
}
|
|
413
|
+
for (const { node, call } of pending.filter((p) => p.kind === "Interface")) {
|
|
414
|
+
const config = call.arguments[0] && ts.isStringLiteral(call.arguments[0])
|
|
415
|
+
? call.arguments[1]
|
|
416
|
+
: call.arguments[0];
|
|
417
|
+
const standalone = ts.isVariableDeclaration(node);
|
|
418
|
+
if (!standalone &&
|
|
419
|
+
(!ts.isPropertyDeclaration(node) ||
|
|
420
|
+
!ts
|
|
421
|
+
.getModifiers(node)
|
|
422
|
+
?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword) ||
|
|
423
|
+
ts
|
|
424
|
+
.getModifiers(node)
|
|
425
|
+
?.some((m) => m.kind === ts.SyntaxKind.PrivateKeyword) ||
|
|
426
|
+
ts.isPrivateIdentifier(node.name))) {
|
|
427
|
+
problem(node, "@Interface requires a public static field");
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
const ownerNode = standalone
|
|
431
|
+
? resolvedNode(property(config, "parent"))
|
|
432
|
+
: node.parent;
|
|
433
|
+
const owner = ownerNode && blocks.get(ownerNode);
|
|
434
|
+
if (!owner && (!standalone || property(config, "parent"))) {
|
|
435
|
+
problem(node, "Interface must reference an annotated block");
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
const explicitId = text(call.arguments[0]) || text(property(config, "id"));
|
|
439
|
+
if (standalone && !explicitId) {
|
|
440
|
+
problem(node, "A standalone interface needs one stable identity");
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
const name = standalone
|
|
444
|
+
? explicitId.split("/").at(-1)
|
|
445
|
+
: node.name.getText().replace(/['"]/g, "");
|
|
446
|
+
const id = explicitId || `${owner.id}::${name}`;
|
|
447
|
+
const blockId = owner?.id ||
|
|
448
|
+
(id.includes("/") ? id.slice(0, id.lastIndexOf("/")) : "factory");
|
|
449
|
+
if (model.interfaces.some((api) => api.id === id)) {
|
|
450
|
+
problem(node, `Duplicate interface: ${id}`);
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
apis.set(node, id);
|
|
454
|
+
model.interfaces.push({
|
|
455
|
+
id,
|
|
456
|
+
blockId,
|
|
457
|
+
name,
|
|
458
|
+
...(text(property(config, "label"))
|
|
459
|
+
? { label: text(property(config, "label")) }
|
|
460
|
+
: {}),
|
|
461
|
+
source: source(node),
|
|
462
|
+
attachments: attachments(config, node),
|
|
463
|
+
methods: [],
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
for (const { node, call, kind } of pending.filter((p) => p.kind === "Method" ||
|
|
467
|
+
(p.kind === "Process" &&
|
|
468
|
+
!pending.some((other) => other.node === p.node && other.kind === "Method")))) {
|
|
469
|
+
const declaration = callable(node);
|
|
470
|
+
if (!declaration) {
|
|
471
|
+
problem(node, "A method/process annotation requires a callable");
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
const apiNode = kind === "Method" ? resolvedNode(call.arguments[0]) : undefined;
|
|
475
|
+
const interfaceId = apiNode && apis.get(apiNode);
|
|
476
|
+
const api = model.interfaces.find((api) => api.id === interfaceId);
|
|
477
|
+
if (kind === "Method" && !api) {
|
|
478
|
+
problem(node, "@Method must reference a declared interface");
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
const block = kind === "Process"
|
|
482
|
+
? blocks.get(node)
|
|
483
|
+
: blocks.get(node) ||
|
|
484
|
+
model.blocks.find((block) => block.id === api?.blockId) ||
|
|
485
|
+
(api ? { id: api.blockId } : undefined);
|
|
486
|
+
if (!block)
|
|
487
|
+
continue;
|
|
488
|
+
let parent = node.parent;
|
|
489
|
+
while (parent &&
|
|
490
|
+
(ts.isCallExpression(parent) ||
|
|
491
|
+
ts.isParenthesizedExpression(parent) ||
|
|
492
|
+
ts.isAsExpression(parent)))
|
|
493
|
+
parent = parent.parent;
|
|
494
|
+
const inferredName = declaration.name?.getText() ||
|
|
495
|
+
(ts.isVariableDeclaration(parent) ? parent.name.getText() : undefined);
|
|
496
|
+
const name = text(property(call.arguments[1], "name")) || inferredName;
|
|
497
|
+
if (!name) {
|
|
498
|
+
problem(node, "Anonymous callable must be assigned to a named declaration");
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const id = `${interfaceId || block.id}#${name}`;
|
|
502
|
+
if (model.methods.some((method) => method.id === id)) {
|
|
503
|
+
problem(node, `Duplicate interface member: ${id}`);
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
const signature = checker.getSignatureFromDeclaration(declaration);
|
|
507
|
+
const type = (node) => checker.typeToString(checker.getTypeAtLocation(node), node, ts.TypeFormatFlags.NoTruncation);
|
|
508
|
+
const config = kind === "Method" ? call.arguments[1] : configOf(call);
|
|
509
|
+
let route = node.parent;
|
|
510
|
+
let endpoint;
|
|
511
|
+
while (route && !ts.isSourceFile(route) && !ts.isFunctionLike(route)) {
|
|
512
|
+
if (ts.isCallExpression(route) &&
|
|
513
|
+
ts.isPropertyAccessExpression(route.expression) &&
|
|
514
|
+
/^(get|post|put|patch|delete|all|options|head)$/.test(route.expression.name.text) &&
|
|
515
|
+
text(route.arguments[0])) {
|
|
516
|
+
endpoint = {
|
|
517
|
+
method: route.expression.name.text.toUpperCase(),
|
|
518
|
+
path: text(route.arguments[0]),
|
|
519
|
+
};
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
route = route.parent;
|
|
523
|
+
}
|
|
524
|
+
if (!endpoint &&
|
|
525
|
+
ts.isVariableDeclaration(parent) &&
|
|
526
|
+
ts.isIdentifier(parent.name) &&
|
|
527
|
+
/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)$/.test(parent.name.text) &&
|
|
528
|
+
ts.isVariableStatement(parent.parent.parent) &&
|
|
529
|
+
parent.parent.parent.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
530
|
+
const nextRoute = fileName(node).match(/(?:^|\/)(?:src\/)?app(\/api\/.*)\/route\.[cm]?[jt]s$/);
|
|
531
|
+
if (nextRoute)
|
|
532
|
+
endpoint = { method: parent.name.text, path: nextRoute[1] };
|
|
533
|
+
}
|
|
534
|
+
const method = {
|
|
535
|
+
...(text(property(config, "label"))
|
|
536
|
+
? { label: text(property(config, "label")) }
|
|
537
|
+
: {}),
|
|
538
|
+
...(endpoint ? { endpoint } : {}),
|
|
539
|
+
id,
|
|
540
|
+
blockId: block.id,
|
|
541
|
+
...(interfaceId ? { interfaceId } : {}),
|
|
542
|
+
name,
|
|
543
|
+
source: source(node),
|
|
544
|
+
signature: signature
|
|
545
|
+
? checker.signatureToString(signature, declaration, ts.TypeFormatFlags.NoTruncation)
|
|
546
|
+
: declaration.getText().split("{")[0],
|
|
547
|
+
contract: {
|
|
548
|
+
args: declaration.parameters.map((parameter) => ({
|
|
549
|
+
name: parameter.name.getText(),
|
|
550
|
+
type: type(parameter),
|
|
551
|
+
optional: !!parameter.questionToken || !!parameter.initializer,
|
|
552
|
+
rest: !!parameter.dotDotDotToken,
|
|
553
|
+
})),
|
|
554
|
+
result: signature
|
|
555
|
+
? checker.typeToString(checker.getReturnTypeOfSignature(signature), declaration, ts.TypeFormatFlags.NoTruncation)
|
|
556
|
+
: "unknown",
|
|
557
|
+
typeSources: typeSources(declaration),
|
|
558
|
+
runtimeValidation: !!property(config, "contract"),
|
|
559
|
+
},
|
|
560
|
+
attachments: attachments(config, node),
|
|
561
|
+
};
|
|
562
|
+
if (!method.attachments.description && kind === "Method") {
|
|
563
|
+
const process = pending.find((item) => item.node === node && item.kind === "Process");
|
|
564
|
+
if (process)
|
|
565
|
+
method.attachments.description = attachments(configOf(process.call), node).description;
|
|
566
|
+
}
|
|
567
|
+
model.methods.push(method);
|
|
568
|
+
methodDeclarations.set(node, method);
|
|
569
|
+
if (ts.isVariableDeclaration(parent))
|
|
570
|
+
methodDeclarations.set(parent, method);
|
|
571
|
+
api?.methods.push(id);
|
|
572
|
+
if (kind === "Process" ||
|
|
573
|
+
(blocks.has(node) &&
|
|
574
|
+
pending.some((other) => other.node === node && other.kind === "Process")))
|
|
575
|
+
model.processes.push({ blockId: block.id, entryMethodId: id });
|
|
576
|
+
if (ts.isFunctionExpression(node) && !node.name)
|
|
577
|
+
problem(node, "Inline functions need a function name for matching runtime identity; use a named function expression");
|
|
578
|
+
}
|
|
579
|
+
// Bodies belong to declared boundaries, not files. Follow real typed helpers
|
|
580
|
+
// between those boundaries; keep helpers as evidence rather than inventing boxes.
|
|
581
|
+
const owners = new Map();
|
|
582
|
+
for (const [node, method] of methodDeclarations) {
|
|
583
|
+
const process = model.processes.find((p) => p.entryMethodId === method.id);
|
|
584
|
+
owners.set(node, process?.blockId || method.id);
|
|
585
|
+
}
|
|
586
|
+
for (const [node, block] of blocks)
|
|
587
|
+
if (callable(node))
|
|
588
|
+
owners.set(node, block.id);
|
|
589
|
+
else if (ts.isObjectLiteralExpression(node))
|
|
590
|
+
owners.set(node, block.id);
|
|
591
|
+
else if (ts.isClassDeclaration(node)) {
|
|
592
|
+
// Public implementation belongs to the declared black box even when a
|
|
593
|
+
// forwarding method is not a separate mapped method. Private helpers are
|
|
594
|
+
// followed only when called; no extra cards or inferred file owners.
|
|
595
|
+
for (const member of node.members)
|
|
596
|
+
if ((ts.isMethodDeclaration(member) ||
|
|
597
|
+
ts.isGetAccessorDeclaration(member) ||
|
|
598
|
+
ts.isSetAccessorDeclaration(member)) &&
|
|
599
|
+
!member.modifiers?.some((modifier) => [
|
|
600
|
+
ts.SyntaxKind.PrivateKeyword,
|
|
601
|
+
ts.SyntaxKind.ProtectedKeyword,
|
|
602
|
+
ts.SyntaxKind.StaticKeyword,
|
|
603
|
+
].includes(modifier.kind)) &&
|
|
604
|
+
!(member.name && ts.isPrivateIdentifier(member.name)) &&
|
|
605
|
+
!owners.has(member))
|
|
606
|
+
owners.set(member, block.id);
|
|
607
|
+
}
|
|
608
|
+
const bodyOf = (node) => {
|
|
609
|
+
if (!node)
|
|
610
|
+
return;
|
|
611
|
+
if (ts.isVariableDeclaration(node) && node.initializer) {
|
|
612
|
+
const value = node.initializer;
|
|
613
|
+
if (ts.isArrowFunction(value) || ts.isFunctionExpression(value))
|
|
614
|
+
return value;
|
|
615
|
+
if (ts.isCallExpression(value)) {
|
|
616
|
+
if (ts.isCallExpression(value.expression) &&
|
|
617
|
+
annotation(value.expression))
|
|
618
|
+
return value.arguments[0];
|
|
619
|
+
// useCallback/useMemo and ordinary function factories retain inline bodies.
|
|
620
|
+
const callbacks = value.arguments.filter((arg) => ts.isArrowFunction(arg) || ts.isFunctionExpression(arg));
|
|
621
|
+
if (callbacks.length === 1)
|
|
622
|
+
return callbacks[0];
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return callable(node) ||
|
|
626
|
+
ts.isObjectLiteralExpression(node) ||
|
|
627
|
+
ts.isGetAccessorDeclaration(node) ||
|
|
628
|
+
ts.isSetAccessorDeclaration(node)
|
|
629
|
+
? node
|
|
630
|
+
: undefined;
|
|
631
|
+
};
|
|
632
|
+
const local = (node) => !node.getSourceFile().isDeclarationFile &&
|
|
633
|
+
!node.getSourceFile().fileName.includes("node_modules") &&
|
|
634
|
+
!relative(root, node.getSourceFile().fileName).startsWith("..");
|
|
635
|
+
// Resolve parameter-property injection only from actual production constructor
|
|
636
|
+
// bindings. An interface's list of implementers is never evidence of a call.
|
|
637
|
+
const injected = new Map();
|
|
638
|
+
const fieldKey = (owner, name) => `${owner.getSourceFile().fileName}:${owner.pos}:${name}`;
|
|
639
|
+
const concreteClass = (expression) => {
|
|
640
|
+
let value = expression;
|
|
641
|
+
const declaration = resolvedNode(value);
|
|
642
|
+
if (declaration &&
|
|
643
|
+
ts.isVariableDeclaration(declaration) &&
|
|
644
|
+
declaration.initializer &&
|
|
645
|
+
ts.isVariableDeclarationList(declaration.parent) &&
|
|
646
|
+
declaration.parent.flags & ts.NodeFlags.Const)
|
|
647
|
+
value = declaration.initializer;
|
|
648
|
+
return checker
|
|
649
|
+
.getTypeAtLocation(value)
|
|
650
|
+
.getSymbol()
|
|
651
|
+
?.declarations?.find(ts.isClassDeclaration);
|
|
652
|
+
};
|
|
653
|
+
for (const file of program.getSourceFiles().filter(local)) {
|
|
654
|
+
const collect = (node) => {
|
|
655
|
+
if (ts.isNewExpression(node)) {
|
|
656
|
+
const constructor = checker.getResolvedSignature(node)?.declaration;
|
|
657
|
+
if (constructor &&
|
|
658
|
+
local(constructor) &&
|
|
659
|
+
ts.isConstructorDeclaration(constructor) &&
|
|
660
|
+
ts.isClassDeclaration(constructor.parent)) {
|
|
661
|
+
for (const [index, parameter] of constructor.parameters.entries()) {
|
|
662
|
+
if (!ts.isIdentifier(parameter.name) ||
|
|
663
|
+
!parameter.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword))
|
|
664
|
+
continue;
|
|
665
|
+
let reassigned = false;
|
|
666
|
+
const fieldName = parameter.name.text;
|
|
667
|
+
const checkWrites = (child) => {
|
|
668
|
+
if (ts.isBinaryExpression(child) &&
|
|
669
|
+
child.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
670
|
+
child.operatorToken.kind <= ts.SyntaxKind.LastAssignment &&
|
|
671
|
+
ts.isPropertyAccessExpression(child.left) &&
|
|
672
|
+
child.left.expression.kind === ts.SyntaxKind.ThisKeyword &&
|
|
673
|
+
child.left.name.text === fieldName)
|
|
674
|
+
reassigned = true;
|
|
675
|
+
ts.forEachChild(child, checkWrites);
|
|
676
|
+
};
|
|
677
|
+
checkWrites(constructor.parent);
|
|
678
|
+
if (reassigned)
|
|
679
|
+
continue;
|
|
680
|
+
const argument = node.arguments?.[index] || parameter.initializer;
|
|
681
|
+
// An omitted optional dependency does not introduce an implementation.
|
|
682
|
+
if (!argument && parameter.questionToken)
|
|
683
|
+
continue;
|
|
684
|
+
const key = fieldKey(constructor.parent, parameter.name.text);
|
|
685
|
+
const bindings = injected.get(key) || new Map();
|
|
686
|
+
const implementation = argument
|
|
687
|
+
? concreteClass(argument)
|
|
688
|
+
: undefined;
|
|
689
|
+
bindings.set(implementation, [
|
|
690
|
+
...(bindings.get(implementation) || []),
|
|
691
|
+
node,
|
|
692
|
+
]);
|
|
693
|
+
injected.set(key, bindings);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
ts.forEachChild(node, collect);
|
|
698
|
+
};
|
|
699
|
+
collect(file);
|
|
700
|
+
}
|
|
701
|
+
const injectionEvidence = new Map();
|
|
702
|
+
const readonlyBinding = (value) => {
|
|
703
|
+
if (!ts.isPropertyAccessExpression(value) ||
|
|
704
|
+
value.expression.kind !== ts.SyntaxKind.ThisKeyword)
|
|
705
|
+
return;
|
|
706
|
+
let parent = value.parent;
|
|
707
|
+
while (parent && !ts.isClassDeclaration(parent))
|
|
708
|
+
parent = parent.parent;
|
|
709
|
+
return parent && ts.isClassDeclaration(parent)
|
|
710
|
+
? injected.get(fieldKey(parent, value.name.text))
|
|
711
|
+
: undefined;
|
|
712
|
+
};
|
|
713
|
+
const parameterBindings = new Map();
|
|
714
|
+
for (const file of program.getSourceFiles().filter(local)) {
|
|
715
|
+
const collect = (node) => {
|
|
716
|
+
if (ts.isCallExpression(node)) {
|
|
717
|
+
const resolved = resolvedNode(node.expression), body = bodyOf(resolved);
|
|
718
|
+
if (body && owners.has(body) && ts.isFunctionLike(body))
|
|
719
|
+
for (const [index, parameter] of body.parameters.entries()) {
|
|
720
|
+
if (!ts.isIdentifier(parameter.name))
|
|
721
|
+
continue;
|
|
722
|
+
let reassigned = false;
|
|
723
|
+
const check = (child) => {
|
|
724
|
+
if (ts.isBinaryExpression(child) &&
|
|
725
|
+
child.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
726
|
+
child.operatorToken.kind <= ts.SyntaxKind.LastAssignment &&
|
|
727
|
+
ts.isIdentifier(child.left) &&
|
|
728
|
+
checker.getSymbolAtLocation(child.left) ===
|
|
729
|
+
checker.getSymbolAtLocation(parameter.name))
|
|
730
|
+
reassigned = true;
|
|
731
|
+
ts.forEachChild(child, check);
|
|
732
|
+
};
|
|
733
|
+
check(body);
|
|
734
|
+
const argument = node.arguments[index] || parameter.initializer;
|
|
735
|
+
if (!argument && parameter.questionToken)
|
|
736
|
+
continue;
|
|
737
|
+
const values = argument && readonlyBinding(argument);
|
|
738
|
+
const bindings = parameterBindings.get(parameter) || new Map();
|
|
739
|
+
if (!reassigned && values?.size === 1 && !values.has(undefined)) {
|
|
740
|
+
const [implementation, sites] = [...values][0];
|
|
741
|
+
bindings.set(implementation, [
|
|
742
|
+
...(bindings.get(implementation) || []),
|
|
743
|
+
...sites,
|
|
744
|
+
node,
|
|
745
|
+
]);
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
const implementation = !reassigned && argument ? concreteClass(argument) : undefined;
|
|
749
|
+
bindings.set(implementation, [
|
|
750
|
+
...(bindings.get(implementation) || []),
|
|
751
|
+
node,
|
|
752
|
+
]);
|
|
753
|
+
}
|
|
754
|
+
parameterBindings.set(parameter, bindings);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
ts.forEachChild(node, collect);
|
|
758
|
+
};
|
|
759
|
+
collect(file);
|
|
760
|
+
}
|
|
761
|
+
const httpTargets = new Map();
|
|
762
|
+
const httpAppRoots = new Set();
|
|
763
|
+
for (const [node, method] of methodDeclarations) {
|
|
764
|
+
const app = method.source.file.match(/^(.*?)(?:src\/)?app\/api\//)?.[1];
|
|
765
|
+
const body = bodyOf(node);
|
|
766
|
+
if (app !== undefined && method.endpoint && body) {
|
|
767
|
+
httpAppRoots.add(app);
|
|
768
|
+
httpTargets.set(`${app} ${method.endpoint.method} ${method.endpoint.path}`, body);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
const httpCalls = new Map();
|
|
772
|
+
const sameOriginTarget = (expression, call) => {
|
|
773
|
+
if (!ts.isIdentifier(expression) || expression.text !== "fetch")
|
|
774
|
+
return;
|
|
775
|
+
const value = checker.getSymbolAtLocation(expression);
|
|
776
|
+
if (value &&
|
|
777
|
+
(value.flags & ts.SymbolFlags.Alias || value.declarations?.some(local)))
|
|
778
|
+
return;
|
|
779
|
+
const app = [...httpAppRoots]
|
|
780
|
+
.sort((a, b) => b.length - a.length)
|
|
781
|
+
.find((root) => fileName(call).startsWith(root + "src/") ||
|
|
782
|
+
fileName(call).startsWith(root + "app/"));
|
|
783
|
+
const url = call.arguments[0];
|
|
784
|
+
if (app === undefined ||
|
|
785
|
+
!url ||
|
|
786
|
+
!ts.isStringLiteral(url) ||
|
|
787
|
+
!url.text.startsWith("/api/"))
|
|
788
|
+
return;
|
|
789
|
+
const options = call.arguments[1];
|
|
790
|
+
let method = !options ? "GET" : undefined;
|
|
791
|
+
if (options &&
|
|
792
|
+
ts.isObjectLiteralExpression(options) &&
|
|
793
|
+
!options.properties.some(ts.isSpreadAssignment)) {
|
|
794
|
+
const member = property(options, "method");
|
|
795
|
+
method = !member
|
|
796
|
+
? "GET"
|
|
797
|
+
: ts.isStringLiteral(member)
|
|
798
|
+
? member.text.toUpperCase()
|
|
799
|
+
: undefined;
|
|
800
|
+
}
|
|
801
|
+
if (!method)
|
|
802
|
+
return;
|
|
803
|
+
const path = url.text.split("?")[0], target = httpTargets.get(`${app} ${method} ${path}`);
|
|
804
|
+
if (target)
|
|
805
|
+
httpCalls.set(call, { label: `${method} ${path}` });
|
|
806
|
+
return target;
|
|
807
|
+
};
|
|
808
|
+
const injectedTarget = (expression, call) => {
|
|
809
|
+
if (!ts.isPropertyAccessExpression(expression))
|
|
810
|
+
return;
|
|
811
|
+
const receiver = expression.expression;
|
|
812
|
+
const parameter = ts.isIdentifier(receiver)
|
|
813
|
+
? checker.getSymbolAtLocation(receiver)?.valueDeclaration
|
|
814
|
+
: undefined;
|
|
815
|
+
const bindings = parameter && ts.isParameter(parameter)
|
|
816
|
+
? parameterBindings.get(parameter)
|
|
817
|
+
: readonlyBinding(receiver);
|
|
818
|
+
if (!bindings || bindings.size !== 1 || bindings.has(undefined))
|
|
819
|
+
return;
|
|
820
|
+
const [implementation, sites] = [...bindings][0];
|
|
821
|
+
const member = implementation?.name &&
|
|
822
|
+
checker.getPropertyOfType(checker.getTypeAtLocation(implementation.name), expression.name.text)?.valueDeclaration;
|
|
823
|
+
const body = member && bodyOf(member);
|
|
824
|
+
if (!body || !local(body))
|
|
825
|
+
return;
|
|
826
|
+
injectionEvidence.set(call, sites.map(source));
|
|
827
|
+
return body;
|
|
828
|
+
};
|
|
829
|
+
const callTarget = (expression, call) => {
|
|
830
|
+
const resolved = resolvedNode(expression);
|
|
831
|
+
if (resolved && owners.has(resolved))
|
|
832
|
+
return resolved;
|
|
833
|
+
const body = bodyOf(resolved);
|
|
834
|
+
if (body && local(body))
|
|
835
|
+
return body;
|
|
836
|
+
if (call) {
|
|
837
|
+
const http = sameOriginTarget(expression, call);
|
|
838
|
+
if (http)
|
|
839
|
+
return http;
|
|
840
|
+
const injectedBody = injectedTarget(expression, call);
|
|
841
|
+
if (injectedBody)
|
|
842
|
+
return injectedBody;
|
|
843
|
+
const declaration = checker.getResolvedSignature(call)?.declaration;
|
|
844
|
+
if (declaration && local(declaration))
|
|
845
|
+
return bodyOf(declaration);
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
const shortType = (node) => checker.typeToString(checker.getTypeAtLocation(node), node, ts.TypeFormatFlags.NoTruncation);
|
|
849
|
+
const seenEdges = new Set();
|
|
850
|
+
const add = (edge) => {
|
|
851
|
+
if (edge.source === edge.target)
|
|
852
|
+
return;
|
|
853
|
+
const key = [
|
|
854
|
+
edge.source,
|
|
855
|
+
edge.target,
|
|
856
|
+
edge.relation || "calls",
|
|
857
|
+
edge.at.file,
|
|
858
|
+
edge.at.line,
|
|
859
|
+
edge.label || "",
|
|
860
|
+
].join("|");
|
|
861
|
+
if (!seenEdges.has(key)) {
|
|
862
|
+
seenEdges.add(key);
|
|
863
|
+
model.dependencies.push(edge);
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
const rootBodies = new Set();
|
|
867
|
+
const roots = [...owners].filter(([node]) => {
|
|
868
|
+
const body = bodyOf(node);
|
|
869
|
+
if (!body || rootBodies.has(body))
|
|
870
|
+
return false;
|
|
871
|
+
rootBodies.add(body);
|
|
872
|
+
return true;
|
|
873
|
+
});
|
|
874
|
+
for (const [entry, owner] of roots) {
|
|
875
|
+
const visited = new Set();
|
|
876
|
+
let scanned = 0;
|
|
877
|
+
const scan = (declaration, via, depth) => {
|
|
878
|
+
const fn = bodyOf(declaration);
|
|
879
|
+
if (!fn || !local(fn) || visited.has(fn))
|
|
880
|
+
return;
|
|
881
|
+
visited.add(fn);
|
|
882
|
+
if (depth > 14 || ++scanned > 1600) {
|
|
883
|
+
(model.interactionGaps ||= []).push({
|
|
884
|
+
source: source(fn),
|
|
885
|
+
expression: owner,
|
|
886
|
+
reason: "Interaction traversal limit reached; no additional relationships were invented.",
|
|
887
|
+
});
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
const follow = (target, at, relation = "calls") => {
|
|
891
|
+
if (!target)
|
|
892
|
+
return;
|
|
893
|
+
const boundVia = [...via, ...(injectionEvidence.get(at) || [])];
|
|
894
|
+
const boundary = owners.get(target);
|
|
895
|
+
if (boundary) {
|
|
896
|
+
const signature = ts.isCallExpression(at)
|
|
897
|
+
? checker.getResolvedSignature(at)
|
|
898
|
+
: undefined;
|
|
899
|
+
const exchange = signature && ts.isCallExpression(at)
|
|
900
|
+
? {
|
|
901
|
+
inputs: at.arguments.map((arg, index) => ({
|
|
902
|
+
name: signature.parameters[index]?.name || `arg${index + 1}`,
|
|
903
|
+
type: shortType(arg),
|
|
904
|
+
})),
|
|
905
|
+
output: checker.typeToString(signature.getReturnType()),
|
|
906
|
+
}
|
|
907
|
+
: undefined;
|
|
908
|
+
add({
|
|
909
|
+
source: owner,
|
|
910
|
+
target: boundary,
|
|
911
|
+
...(httpCalls.has(at)
|
|
912
|
+
? { label: httpCalls.get(at).label, transport: "HTTP" }
|
|
913
|
+
: {}),
|
|
914
|
+
...(blocks.get(target)?.inputLabel
|
|
915
|
+
? { label: blocks.get(target).inputLabel }
|
|
916
|
+
: {}),
|
|
917
|
+
at: source(at),
|
|
918
|
+
...(relation !== "calls" ? { relation } : {}),
|
|
919
|
+
...(boundVia.length ? { via: boundVia } : {}),
|
|
920
|
+
...(exchange ? { exchange } : {}),
|
|
921
|
+
});
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
if (local(target))
|
|
925
|
+
scan(target, [...boundVia, source(at)], depth + 1);
|
|
926
|
+
};
|
|
927
|
+
const visit = (child) => {
|
|
928
|
+
if (ts.isObjectLiteralExpression(fn) &&
|
|
929
|
+
(ts.isPropertyAssignment(child) ||
|
|
930
|
+
ts.isShorthandPropertyAssignment(child))) {
|
|
931
|
+
const value = ts.isPropertyAssignment(child)
|
|
932
|
+
? child.initializer
|
|
933
|
+
: child.name;
|
|
934
|
+
const wrapped = ts.isCallExpression(value) &&
|
|
935
|
+
ts.isCallExpression(value.expression) &&
|
|
936
|
+
annotation(value.expression)
|
|
937
|
+
? value.arguments[0]
|
|
938
|
+
: undefined;
|
|
939
|
+
const target = wrapped ||
|
|
940
|
+
(ts.isShorthandPropertyAssignment(child)
|
|
941
|
+
? checker.getShorthandAssignmentValueSymbol(child)
|
|
942
|
+
?.valueDeclaration
|
|
943
|
+
: resolvedNode(value));
|
|
944
|
+
const boundary = target && owners.get(target);
|
|
945
|
+
if (boundary && boundary !== owner) {
|
|
946
|
+
const path = [child.name.getText()];
|
|
947
|
+
let parent = child.parent;
|
|
948
|
+
while (parent && parent !== fn) {
|
|
949
|
+
if (ts.isPropertyAssignment(parent))
|
|
950
|
+
path.unshift(parent.name.getText());
|
|
951
|
+
parent = parent.parent;
|
|
952
|
+
}
|
|
953
|
+
// This object exposes the supplied handler. It is registration
|
|
954
|
+
// evidence, never a claim that the callback was invoked.
|
|
955
|
+
add({
|
|
956
|
+
source: owner,
|
|
957
|
+
target: boundary,
|
|
958
|
+
relation: "exposes",
|
|
959
|
+
label: path.join("."),
|
|
960
|
+
at: source(child.name),
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (child !== fn && owners.has(child))
|
|
965
|
+
return;
|
|
966
|
+
if ((ts.isFunctionDeclaration(child) || ts.isMethodDeclaration(child)) &&
|
|
967
|
+
child !== fn)
|
|
968
|
+
return;
|
|
969
|
+
if (child !== fn &&
|
|
970
|
+
(ts.isArrowFunction(child) || ts.isFunctionExpression(child)) &&
|
|
971
|
+
ts.isVariableDeclaration(child.parent))
|
|
972
|
+
return;
|
|
973
|
+
if (ts.isJsxOpeningElement(child) ||
|
|
974
|
+
ts.isJsxSelfClosingElement(child)) {
|
|
975
|
+
const target = callTarget(child.tagName), boundary = target && owners.get(target);
|
|
976
|
+
const attrs = child.attributes.properties.filter(ts.isJsxAttribute);
|
|
977
|
+
if (boundary) {
|
|
978
|
+
const values = attrs.filter((attr) => attr.name.getText() !== "key" && attr.name.getText() !== "ref");
|
|
979
|
+
const inputs = values
|
|
980
|
+
.filter((attr) => !/^on[A-Z]/.test(attr.name.getText()))
|
|
981
|
+
.map((attr) => ({
|
|
982
|
+
name: attr.name.getText(),
|
|
983
|
+
type: attr.initializer && ts.isStringLiteral(attr.initializer)
|
|
984
|
+
? "string"
|
|
985
|
+
: attr.initializer &&
|
|
986
|
+
ts.isJsxExpression(attr.initializer) &&
|
|
987
|
+
attr.initializer.expression
|
|
988
|
+
? shortType(attr.initializer.expression)
|
|
989
|
+
: "boolean",
|
|
990
|
+
}));
|
|
991
|
+
add({
|
|
992
|
+
source: owner,
|
|
993
|
+
target: boundary,
|
|
994
|
+
relation: "renders",
|
|
995
|
+
label: blocks.get(target)?.inputLabel ||
|
|
996
|
+
inputs
|
|
997
|
+
.slice(0, 3)
|
|
998
|
+
.map((input) => input.name)
|
|
999
|
+
.join(" · ") ||
|
|
1000
|
+
"UI",
|
|
1001
|
+
exchange: { inputs },
|
|
1002
|
+
at: source(child),
|
|
1003
|
+
...(via.length ? { via } : {}),
|
|
1004
|
+
});
|
|
1005
|
+
for (const attr of values.filter((attr) => /^on[A-Z]/.test(attr.name.getText()))) {
|
|
1006
|
+
if (!attr.initializer ||
|
|
1007
|
+
!ts.isJsxExpression(attr.initializer) ||
|
|
1008
|
+
!attr.initializer.expression)
|
|
1009
|
+
continue;
|
|
1010
|
+
const callback = attr.initializer.expression, signature = checker.getSignaturesOfType(checker.getTypeAtLocation(callback), ts.SignatureKind.Call)[0];
|
|
1011
|
+
if (!signature)
|
|
1012
|
+
continue;
|
|
1013
|
+
// An actual callback is supplied here. This is a capability to call
|
|
1014
|
+
// back, not a claim that the callback ran or a fabricated sequence.
|
|
1015
|
+
add({
|
|
1016
|
+
source: boundary,
|
|
1017
|
+
target: owner,
|
|
1018
|
+
relation: "callbacks",
|
|
1019
|
+
label: attr.name.getText(),
|
|
1020
|
+
...(blocks.get(target)?.eventLabel
|
|
1021
|
+
? { displayLabel: blocks.get(target).eventLabel }
|
|
1022
|
+
: {}),
|
|
1023
|
+
exchange: {
|
|
1024
|
+
inputs: signature.parameters.map((p) => ({
|
|
1025
|
+
name: p.name,
|
|
1026
|
+
type: checker.typeToString(checker.getTypeOfSymbolAtLocation(p, callback)),
|
|
1027
|
+
})),
|
|
1028
|
+
output: checker.typeToString(signature.getReturnType()),
|
|
1029
|
+
},
|
|
1030
|
+
at: source(attr),
|
|
1031
|
+
...(via.length ? { via } : {}),
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
else if (target && local(target))
|
|
1036
|
+
scan(target, [...via, source(child)], depth + 1);
|
|
1037
|
+
}
|
|
1038
|
+
if (ts.isCallExpression(child)) {
|
|
1039
|
+
follow(callTarget(child.expression, child), child);
|
|
1040
|
+
// Callback registration is different from invocation (e.g. SWR fetchers).
|
|
1041
|
+
const signature = checker.getResolvedSignature(child);
|
|
1042
|
+
for (const [index, arg] of child.arguments.entries()) {
|
|
1043
|
+
const parameter = signature?.parameters[Math.min(index, signature.parameters.length - 1)];
|
|
1044
|
+
const acceptsCallback = (type) => checker.getSignaturesOfType(checker.getNonNullableType(type), ts.SignatureKind.Call).length > 0 ||
|
|
1045
|
+
(type.isUnion() && type.types.some(acceptsCallback));
|
|
1046
|
+
if (!parameter ||
|
|
1047
|
+
!acceptsCallback(checker.getTypeOfSymbolAtLocation(parameter, child)))
|
|
1048
|
+
continue;
|
|
1049
|
+
if (ts.isIdentifier(arg) || ts.isPropertyAccessExpression(arg)) {
|
|
1050
|
+
const target = callTarget(arg);
|
|
1051
|
+
if (target)
|
|
1052
|
+
follow(target, arg, "delegates");
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
ts.forEachChild(child, visit);
|
|
1057
|
+
};
|
|
1058
|
+
visit(fn);
|
|
1059
|
+
};
|
|
1060
|
+
scan(entry, [], 0);
|
|
1061
|
+
}
|
|
1062
|
+
for (const block of model.blocks) {
|
|
1063
|
+
const seen = new Set();
|
|
1064
|
+
let current = block;
|
|
1065
|
+
while (current) {
|
|
1066
|
+
if (seen.has(current.id)) {
|
|
1067
|
+
problem([...blocks].find(([, b]) => b.id === block.id)[0], `Ownership cycle at ${block.id}`);
|
|
1068
|
+
break;
|
|
1069
|
+
}
|
|
1070
|
+
seen.add(current.id);
|
|
1071
|
+
current = model.blocks.find((candidate) => candidate.id === current.parent);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
for (const collection of [model.blocks, model.interfaces, model.methods])
|
|
1075
|
+
collection.sort((a, b) => a.id.localeCompare(b.id));
|
|
1076
|
+
model.processes.sort((a, b) => a.blockId.localeCompare(b.blockId));
|
|
1077
|
+
for (const api of model.interfaces)
|
|
1078
|
+
api.methods.sort();
|
|
1079
|
+
model.dependencies.sort((a, b) => `${a.source}:${a.target}:${a.at.line}`.localeCompare(`${b.source}:${b.target}:${b.at.line}`));
|
|
1080
|
+
model.revision = digest(JSON.stringify({ ...model, revision: "" })).slice(0, 16);
|
|
1081
|
+
return model;
|
|
1082
|
+
}
|
|
1083
|
+
export { factoryGraph } from "./factory-graph.js";
|