@dimassetoid/septum-mcp 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -55
- package/package.json +7 -5
- package/src/cli/commands/check.ts +14 -10
- package/src/cli/commands/hook.ts +41 -6
- package/src/cli/commands/init.ts +10 -1
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +32 -4
- package/src/cli/index.ts +7 -0
- package/src/cli/templates/hooks.ts +3 -14
- package/src/cli/templates/skill.ts +17 -10
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +251 -114
- package/src/core/boundary/staged-auditor.ts +147 -55
- package/src/core/config/domain-ownership.ts +6 -4
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +1 -25
- package/src/core/config/schema.ts +24 -36
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +334 -572
- package/src/core/database/repositories/domain.repository.ts +2 -1
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -398
- package/src/core/database/repository.ts +68 -9
- package/src/core/database/schema.ts +26 -0
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +222 -58
- package/src/core/discovery/topology-detector.ts +93 -168
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +287 -88
- package/src/core/parser/extractors/base.ts +11 -3
- package/src/core/parser/extractors/csharp.ts +2 -2
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +397 -481
- package/src/core/parser/extractors/elysia-semantic.ts +172 -475
- package/src/core/parser/extractors/express-semantic.ts +195 -383
- package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
- package/src/core/parser/extractors/fastify-semantic.ts +216 -717
- package/src/core/parser/extractors/flask-semantic.ts +89 -352
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +205 -562
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -509
- package/src/core/parser/extractors/java.ts +2 -2
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +143 -335
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +82 -333
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +1 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +5 -9
- package/src/core/parser/extractors/registry.ts +2 -0
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +2 -2
- package/src/core/parser/extractors/rust.ts +4 -4
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +72 -226
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +23 -216
- package/src/core/parser/language-capabilities.ts +1 -1
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +169 -414
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +60 -7
- package/src/core/resolver/interpretation-inputs.ts +60 -2
- package/src/core/resolver/languages/python.ts +31 -13
- package/src/core/resolver/languages/shared.ts +4 -1
- package/src/core/resolver/module-resolver.ts +10 -3
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +21 -6
- package/src/core/resolver/slice-format.ts +13 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +104 -8
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +31 -230
- package/src/core/resources/ignore.ts +0 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +11 -4
- package/src/core/retrieval/context.ts +363 -226
- package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +3 -3
- package/src/core/retrieval/typescript-references.ts +38 -7
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +192 -49
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +253 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -746
- package/src/mcp/server.ts +269 -429
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +68 -3
- package/src/mcp/tools/map.ts +104 -4
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +469 -17
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +88 -15
- package/src/mcp/workspace-watcher.ts +30 -11
- package/src/types/index.ts +12 -0
- package/src/mcp/tools/check-boundary.ts +0 -382
- package/src/mcp/tools/get-domain-catalog.ts +0 -39
- package/src/mcp/tools/get-symbol-impact.ts +0 -104
- package/src/mcp/tools/locate-symbol.ts +0 -236
- package/src/mcp/tools/register-domain.ts +0 -113
- package/src/mcp/tools/trace-vertical-slice.ts +0 -106
|
@@ -1,51 +1,25 @@
|
|
|
1
|
-
import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
2
|
-
import type Parser from "web-tree-sitter";
|
|
3
|
-
import { parseWithTreeSitter } from "../wasm-loader.ts";
|
|
4
|
-
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
5
|
-
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
6
|
-
import * as fs from "node:fs";
|
|
7
1
|
import * as path from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import type { ExecutionChainNode } from "../../../types/index.ts";
|
|
4
|
+
import { listSourceFiles, type SourceInventory } from "../../resources/source-inventory.ts";
|
|
5
|
+
import { probeSourcePath, readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
6
|
+
import { hasPackageJsonDependency } from "./manifest-helpers.ts";
|
|
8
7
|
import type { SemanticSliceExtractor, VerticalSliceCandidate } from "./semantic-extractor.interface.ts";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
file: string;
|
|
25
|
-
relPath: string;
|
|
26
|
-
callerVar: string;
|
|
27
|
-
prefix: string;
|
|
28
|
-
targetVar: string;
|
|
29
|
-
line: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function cleanLiteral(node: Parser.SyntaxNode | null | undefined): string | undefined {
|
|
33
|
-
if (!node) return undefined;
|
|
34
|
-
if (node.type === "string") {
|
|
35
|
-
const raw = node.text.trim();
|
|
36
|
-
return raw.replace(/^['"`]|['"`]$/g, "");
|
|
37
|
-
}
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function normalizeRouteUri(prefix: string, rawPath: string): string {
|
|
42
|
-
const p = (prefix ?? "").trim().replace(/\/+$/, "");
|
|
43
|
-
let r = (rawPath ?? "").trim();
|
|
44
|
-
if (!r.startsWith("/")) r = "/" + r;
|
|
45
|
-
if (r === "/" && p.length > 0) return p;
|
|
46
|
-
if (r === "/" && p.length === 0) return "/";
|
|
47
|
-
const joined = `${p}${r}`;
|
|
48
|
-
return joined.startsWith("/") ? joined : `/${joined}`;
|
|
8
|
+
import { lineOf, literal, objectMember, TypeScriptBindings, visitRouteCalls } from "./typescript-bindings.ts";
|
|
9
|
+
import { routeContext } from "./typescript-route-context.ts";
|
|
10
|
+
|
|
11
|
+
const verbs = new Set(["get", "post", "put", "patch", "delete", "head", "options", "connect", "trace", "all"]);
|
|
12
|
+
const instanceMethods = new Set([
|
|
13
|
+
...verbs, "route", "use", "group", "guard", "decorate", "state", "derive", "resolve",
|
|
14
|
+
"model", "onRequest", "onBeforeHandle", "onAfterHandle", "onError",
|
|
15
|
+
]);
|
|
16
|
+
type Expression = ts.Expression | ts.MethodDeclaration;
|
|
17
|
+
type Route = { method: string; uri: string; call: ts.CallExpression; handler: ts.Expression; schema?: Expression };
|
|
18
|
+
type Scope = { prefix: string | undefined; routes: Map<string, Route>; schema?: Expression };
|
|
19
|
+
type Frames = ReadonlyMap<ts.ParameterDeclaration, Scope>;
|
|
20
|
+
|
|
21
|
+
function leadingSlash(value: string): string {
|
|
22
|
+
return value && !value.startsWith("/") ? "/" + value : value;
|
|
49
23
|
}
|
|
50
24
|
|
|
51
25
|
export class ElysiaSemanticExtractor implements SemanticSliceExtractor {
|
|
@@ -54,464 +28,187 @@ export class ElysiaSemanticExtractor implements SemanticSliceExtractor {
|
|
|
54
28
|
|
|
55
29
|
public canHandle(projectRoot: string, framework?: string): boolean {
|
|
56
30
|
if (framework === "elysia") return true;
|
|
57
|
-
|
|
58
|
-
const pkgPath = path.join(projectRoot, "package.json");
|
|
59
|
-
if (fs.existsSync(pkgPath)) {
|
|
60
|
-
try {
|
|
61
|
-
const pkg = JSON.parse(readOptionalSourceFile(pkgPath, "utf-8"));
|
|
62
|
-
const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
|
|
63
|
-
if (deps.elysia) return true;
|
|
64
|
-
} catch {}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Check entrypoint source code
|
|
31
|
+
if (hasPackageJsonDependency(projectRoot, ["elysia"])) return true;
|
|
68
32
|
for (const entry of ["src/index.ts", "src/app.ts", "index.ts", "app.ts", "src/server.ts"]) {
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
const content = readOptionalSourceFile(full, "utf-8");
|
|
73
|
-
if (content.includes("from \"elysia\"") || content.includes("from 'elysia'") || content.includes("require(\"elysia\")")) {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
} catch {}
|
|
33
|
+
const file = path.join(projectRoot, entry);
|
|
34
|
+
if (probeSourcePath(file) === "file" && /(?:from\s*|require\(\s*)['"]elysia['"]/.test(readOptionalSourceFile(file))) {
|
|
35
|
+
return true;
|
|
77
36
|
}
|
|
78
37
|
}
|
|
79
|
-
|
|
80
38
|
return false;
|
|
81
39
|
}
|
|
82
40
|
|
|
83
41
|
public async extractSlices(
|
|
84
42
|
projectRoot: string,
|
|
85
43
|
domainId?: number,
|
|
86
|
-
signal?: AbortSignal,
|
|
44
|
+
signal?: AbortSignal,
|
|
45
|
+
inventory?: SourceInventory,
|
|
87
46
|
): Promise<VerticalSliceCandidate[]> {
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(rootNode) => this.extractFileAst(file, relPath, rootNode, resolver, projectRoot)
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
if (fileData) {
|
|
109
|
-
allRoutes.push(...fileData.routes);
|
|
110
|
-
allMounts.push(...fileData.mounts);
|
|
111
|
-
if (fileData.resolvedImports.size > 0) {
|
|
112
|
-
fileImports.set(relPath, fileData.resolvedImports);
|
|
113
|
-
}
|
|
47
|
+
const root = path.resolve(projectRoot);
|
|
48
|
+
const files = listSourceFiles(root, /\.[cm]?[jt]sx?$/, inventory).filter(file => !/\.d\.[cm]?ts$/.test(file));
|
|
49
|
+
const bindings = new TypeScriptBindings(root, new Set(files), signal);
|
|
50
|
+
const scopes = new Map<ts.NewExpression, Scope>();
|
|
51
|
+
const mounted = new Set<Scope>();
|
|
52
|
+
const active = new Set<ts.FunctionLikeDeclaration>();
|
|
53
|
+
const fileOf = (node: ts.Node) => path.relative(root, node.getSourceFile().fileName).replace(/\\/g, "/");
|
|
54
|
+
const object = (expression?: ts.Expression) => {
|
|
55
|
+
const value = bindings.value(expression);
|
|
56
|
+
return value && ts.isObjectLiteralExpression(value) ? value : undefined;
|
|
57
|
+
};
|
|
58
|
+
const schemaFor = (expression?: ts.Expression): Expression | undefined => {
|
|
59
|
+
const opts = object(expression);
|
|
60
|
+
if (!opts) return undefined;
|
|
61
|
+
for (const field of ["body", "query", "params", "headers", "cookie", "response"]) {
|
|
62
|
+
const value = objectMember(opts, field);
|
|
63
|
+
if (value) return value;
|
|
114
64
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// Resolve Router Prefix Hierarchy
|
|
118
|
-
const routerPrefixes = this.resolvePrefixHierarchy(allMounts, fileImports);
|
|
119
|
-
|
|
120
|
-
// Build Vertical Slices (Level 0 – Level 5)
|
|
121
|
-
for (const route of allRoutes) {
|
|
122
|
-
const prefixes = routerPrefixes.get(`${route.relPath}#${route.routerVar}`) || [""];
|
|
123
|
-
|
|
124
|
-
for (const prefix of prefixes) {
|
|
125
|
-
for (const httpMethod of route.httpMethods) {
|
|
126
|
-
const fullUri = normalizeRouteUri(prefix, route.rawPath);
|
|
127
|
-
const actionSymbol = route.handler.symbol;
|
|
128
|
-
const rootIdent = actionSymbol.includes(".") ? actionSymbol.split(".")[0] : actionSymbol;
|
|
129
|
-
const imports = fileImports.get(route.relPath);
|
|
130
|
-
const resolvedControllerFile = imports?.get(rootIdent) || route.relPath;
|
|
131
|
-
const fileBase = path.basename(route.relPath).replace(/\.[^.]+$/, "");
|
|
132
|
-
const controllerClass = actionSymbol.includes(".")
|
|
133
|
-
? actionSymbol.split(".")[0]
|
|
134
|
-
: fileBase.charAt(0).toUpperCase() + fileBase.slice(1);
|
|
135
|
-
const actionName = actionSymbol.includes(".") ? actionSymbol.split(".").pop()! : actionSymbol;
|
|
136
|
-
|
|
137
|
-
const chain: Array<{ stage: string; symbol: string; file?: string; line?: number; description?: string }> = [
|
|
138
|
-
{
|
|
139
|
-
stage: "ingress",
|
|
140
|
-
symbol: `${httpMethod} ${fullUri}`,
|
|
141
|
-
file: route.relPath,
|
|
142
|
-
line: route.routeLine,
|
|
143
|
-
description: `Elysia Route: ${httpMethod} ${fullUri}`,
|
|
144
|
-
},
|
|
145
|
-
];
|
|
146
|
-
|
|
147
|
-
// L2: Validation Schema (TypeBox)
|
|
148
|
-
if (route.validationSchema) {
|
|
149
|
-
chain.push({
|
|
150
|
-
stage: "validation",
|
|
151
|
-
symbol: route.validationSchema.symbol,
|
|
152
|
-
file: route.validationSchema.file || route.relPath,
|
|
153
|
-
line: route.validationSchema.line,
|
|
154
|
-
description: `Elysia TypeBox Schema: ${route.validationSchema.symbol}`,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// L3: Controller Action
|
|
159
|
-
chain.push({
|
|
160
|
-
stage: "controller",
|
|
161
|
-
symbol: actionSymbol,
|
|
162
|
-
file: resolvedControllerFile,
|
|
163
|
-
line: route.handler.line,
|
|
164
|
-
description: `Elysia Action Handler`,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// L4–L5: Tracing Service & Persistence from handler or imported controller
|
|
168
|
-
const scanFile = resolvedControllerFile !== route.relPath ? resolvedControllerFile : route.relPath;
|
|
169
|
-
const fullScanPath = path.resolve(projectRoot, scanFile);
|
|
170
|
-
const scanContent = readOptionalSourceFile(fullScanPath, "utf-8");
|
|
171
|
-
|
|
172
|
-
if (scanContent) {
|
|
173
|
-
// Check service calls: orderService.create(...) or OrderService.process(...)
|
|
174
|
-
const sMatch = scanContent.match(/\b([a-zA-Z0-9_]+(?:Service|Usecase))\s*\.\s*([A-Za-z0-9_]+)\s*\(/i);
|
|
175
|
-
let serviceFile: string | undefined;
|
|
176
|
-
if (sMatch) {
|
|
177
|
-
const svcIdent = sMatch[1];
|
|
178
|
-
const svcMethod = sMatch[2];
|
|
179
|
-
const imports = fileImports.get(scanFile);
|
|
180
|
-
let svcImport = imports?.get(svcIdent);
|
|
181
|
-
if (!svcImport && imports) {
|
|
182
|
-
const pascal = svcIdent.charAt(0).toUpperCase() + svcIdent.slice(1);
|
|
183
|
-
svcImport = imports.get(pascal);
|
|
184
|
-
if (!svcImport) {
|
|
185
|
-
const instMatch = scanContent.match(new RegExp(`\\b(?:const|let|var)\\s+${svcIdent}\\s*=\\s*new\\s+([a-zA-Z0-9_]+)`));
|
|
186
|
-
if (instMatch) {
|
|
187
|
-
svcImport = imports.get(instMatch[1]);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
serviceFile = svcImport;
|
|
192
|
-
|
|
193
|
-
chain.push({
|
|
194
|
-
stage: "service",
|
|
195
|
-
symbol: `${svcIdent}::${svcMethod}`,
|
|
196
|
-
...(serviceFile ? { file: serviceFile } : {}),
|
|
197
|
-
description: `Elysia Service Call: ${svcIdent}::${svcMethod}`,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Check Prisma / Drizzle / TypeORM persistence in scanFile or serviceFile
|
|
202
|
-
const filesToInspect = [fullScanPath];
|
|
203
|
-
if (serviceFile) filesToInspect.push(path.resolve(projectRoot, serviceFile));
|
|
204
|
-
|
|
205
|
-
for (const inspectPath of filesToInspect) {
|
|
206
|
-
const contentToInspect = readOptionalSourceFile(inspectPath, "utf-8");
|
|
207
|
-
if (!contentToInspect) continue;
|
|
208
|
-
|
|
209
|
-
const prismaMatch = contentToInspect.match(/prisma\.([a-zA-Z0-9_]+)\.(?:find|create|update|delete|upsert)/);
|
|
210
|
-
const drizzleMatch = contentToInspect.match(/db\.(?:insert|select|update|delete)\s*\(\s*([a-zA-Z0-9_]+)\s*\)/);
|
|
211
|
-
|
|
212
|
-
const entityName =
|
|
213
|
-
prismaMatch ? (prismaMatch[1].charAt(0).toUpperCase() + prismaMatch[1].slice(1)) :
|
|
214
|
-
drizzleMatch ? (drizzleMatch[1].charAt(0).toUpperCase() + drizzleMatch[1].slice(1)) : undefined;
|
|
215
|
-
|
|
216
|
-
if (entityName && !chain.some((n) => n.stage === "entity")) {
|
|
217
|
-
const inspectRel = path.relative(projectRoot, inspectPath).replace(/\\/g, "/");
|
|
218
|
-
const entImport = fileImports.get(inspectRel)?.get(entityName);
|
|
219
|
-
|
|
220
|
-
chain.push({
|
|
221
|
-
stage: "repository",
|
|
222
|
-
symbol: `${entityName}Repository`,
|
|
223
|
-
file: inspectRel,
|
|
224
|
-
description: prismaMatch ? "Prisma ORM Client" : "Drizzle ORM Query",
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
chain.push({
|
|
228
|
-
stage: "entity",
|
|
229
|
-
symbol: entityName,
|
|
230
|
-
...(entImport ? { file: entImport } : { file: inspectRel }),
|
|
231
|
-
description: "Database Entity / Schema Model",
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
236
67
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
68
|
+
const instanceOf = (expression: ts.Expression, frames: Frames): Scope | undefined => {
|
|
69
|
+
const visited = new Set<ts.Node>();
|
|
70
|
+
let value = bindings.value(expression);
|
|
71
|
+
while (value && !visited.has(value)) {
|
|
72
|
+
visited.add(value);
|
|
73
|
+
if (ts.isIdentifier(value)) {
|
|
74
|
+
const declared = bindings.declaration(value);
|
|
75
|
+
return declared && ts.isParameter(declared) ? frames.get(declared) : undefined;
|
|
76
|
+
}
|
|
77
|
+
if (ts.isNewExpression(value)) {
|
|
78
|
+
const existing = scopes.get(value);
|
|
79
|
+
if (existing) return existing;
|
|
80
|
+
const type = bindings.packageBinding(value.expression);
|
|
81
|
+
if (type?.module !== "elysia" || type.name !== "Elysia" && type.name !== "default") return undefined;
|
|
82
|
+
const opts = object(value.arguments?.[0]);
|
|
83
|
+
const raw = opts && objectMember(opts, "prefix");
|
|
84
|
+
const dynamic = value.arguments?.length && (!opts || opts.properties.some(property =>
|
|
85
|
+
ts.isSpreadAssignment(property) || property.name && ts.isComputedPropertyName(property.name),
|
|
86
|
+
));
|
|
87
|
+
const prefix = raw && !ts.isMethodDeclaration(raw) ? literal(raw) : raw || dynamic ? undefined : "";
|
|
88
|
+
const scope = { prefix: prefix === undefined ? undefined : leadingSlash(prefix), routes: new Map<string, Route>() };
|
|
89
|
+
scopes.set(value, scope);
|
|
90
|
+
return scope;
|
|
251
91
|
}
|
|
92
|
+
if (!ts.isCallExpression(value) || value.questionDotToken || !ts.isPropertyAccessExpression(value.expression) ||
|
|
93
|
+
value.expression.questionDotToken || !instanceMethods.has(value.expression.name.text)) return undefined;
|
|
94
|
+
value = bindings.value(value.expression.expression);
|
|
252
95
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return slices;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
private extractFileAst(
|
|
259
|
-
file: string,
|
|
260
|
-
relPath: string,
|
|
261
|
-
rootNode: Parser.SyntaxNode,
|
|
262
|
-
resolver: ImportResolver,
|
|
263
|
-
_projectRoot: string
|
|
264
|
-
): {
|
|
265
|
-
routes: ExtractedRoute[];
|
|
266
|
-
mounts: ExtractedMount[];
|
|
267
|
-
resolvedImports: Map<string, string>;
|
|
268
|
-
} {
|
|
269
|
-
const routes: ExtractedRoute[] = [];
|
|
270
|
-
const mounts: ExtractedMount[] = [];
|
|
271
|
-
const resolvedImports = new Map<string, string>();
|
|
96
|
+
return undefined;
|
|
97
|
+
};
|
|
272
98
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
99
|
+
const put = (scope: Scope, route: Route) => scope.routes.set(route.method + "\0" + route.uri, route);
|
|
100
|
+
const copyRoutes = (parent: Scope, child: Scope, subpath: string) => {
|
|
101
|
+
if (parent.prefix === undefined || parent === child) return;
|
|
102
|
+
for (const route of child.routes.values()) {
|
|
103
|
+
signal?.throwIfAborted();
|
|
104
|
+
put(parent, { ...route, uri: parent.prefix + leadingSlash(subpath + route.uri) });
|
|
105
|
+
}
|
|
106
|
+
};
|
|
279
107
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
108
|
+
const visitCallback = (callback: ts.Expression | undefined, scope: Scope, frames: Frames) => {
|
|
109
|
+
const handler = bindings.handler(callback)?.node;
|
|
110
|
+
if (!handler?.body || !handler.parameters[0] || active.has(handler)) return;
|
|
111
|
+
active.add(handler);
|
|
112
|
+
try {
|
|
113
|
+
const locals = new Map(frames).set(handler.parameters[0], scope);
|
|
114
|
+
visitRouteCalls(handler.body, call => readCall(call, locals));
|
|
115
|
+
} finally { active.delete(handler); }
|
|
116
|
+
};
|
|
283
117
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
}
|
|
118
|
+
const readCall = (call: ts.CallExpression, frames: Frames) => {
|
|
119
|
+
signal?.throwIfAborted();
|
|
120
|
+
const member = call.expression;
|
|
121
|
+
if (call.questionDotToken || !ts.isPropertyAccessExpression(member) || member.questionDotToken) return;
|
|
122
|
+
const method = member.name.text;
|
|
123
|
+
if (!["use", "group", "route", "guard"].includes(method) && !verbs.has(method)) return;
|
|
124
|
+
const parent = instanceOf(member.expression, frames);
|
|
125
|
+
if (!parent) return;
|
|
126
|
+
|
|
127
|
+
if (method === "use") {
|
|
128
|
+
const use = (argument?: ts.Expression) => {
|
|
129
|
+
const value = bindings.value(argument);
|
|
130
|
+
if (!value) return;
|
|
131
|
+
if (ts.isArrayLiteralExpression(value)) {
|
|
132
|
+
for (const item of value.elements) if (!ts.isSpreadElement(item)) use(item);
|
|
133
|
+
return;
|
|
302
134
|
}
|
|
303
|
-
|
|
135
|
+
const plugin = instanceOf(value, frames);
|
|
136
|
+
if (plugin && plugin !== parent) {
|
|
137
|
+
mounted.add(plugin);
|
|
138
|
+
copyRoutes(parent, plugin, "");
|
|
139
|
+
} else if (!plugin) visitCallback(argument, parent, frames);
|
|
140
|
+
};
|
|
141
|
+
use(call.arguments[0]);
|
|
142
|
+
return;
|
|
304
143
|
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// 2. Walk call expressions for routes and sub-route mounts
|
|
308
|
-
const walkCalls = (node: Parser.SyntaxNode): void => {
|
|
309
|
-
if (node.type === "call_expression") {
|
|
310
|
-
const fnNode = node.childForFieldName("function");
|
|
311
|
-
if (fnNode && fnNode.type === "member_expression") {
|
|
312
|
-
const objNode = fnNode.childForFieldName("object");
|
|
313
|
-
const propNode = fnNode.childForFieldName("property");
|
|
314
|
-
const argsNode = node.childForFieldName("arguments");
|
|
315
|
-
|
|
316
|
-
if (objNode && propNode && argsNode) {
|
|
317
|
-
const callerVar = objNode.text.trim();
|
|
318
|
-
const methodName = propNode.text.trim();
|
|
319
|
-
const lowerMethod = methodName.toLowerCase();
|
|
320
|
-
const args = argsNode.namedChildren;
|
|
321
|
-
|
|
322
|
-
// Route Mount / Plugin: app.use(subPlugin)
|
|
323
|
-
if (lowerMethod === "use") {
|
|
324
|
-
if (args.length >= 1 && args[0].type === "identifier") {
|
|
325
|
-
mounts.push({
|
|
326
|
-
file,
|
|
327
|
-
relPath,
|
|
328
|
-
callerVar,
|
|
329
|
-
prefix: "",
|
|
330
|
-
targetVar: args[0].text.trim(),
|
|
331
|
-
line: node.startPosition.row + 1,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
} else if (lowerMethod === "group") {
|
|
335
|
-
// Group scoping: app.group('/v1', (app) => ...)
|
|
336
|
-
if (args.length >= 2) {
|
|
337
|
-
const prefixLit = cleanLiteral(args[0]);
|
|
338
|
-
const groupFn = args[1];
|
|
339
|
-
if (prefixLit !== undefined && groupFn) {
|
|
340
|
-
// Trace routes inside the group callback
|
|
341
|
-
let scopedVar = callerVar;
|
|
342
|
-
if (groupFn.type === "arrow_function" || groupFn.type === "function") {
|
|
343
|
-
const paramsNode = groupFn.childForFieldName("parameters");
|
|
344
|
-
if (paramsNode && paramsNode.namedChildren[0]) {
|
|
345
|
-
scopedVar = paramsNode.namedChildren[0].text.trim();
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
mounts.push({
|
|
349
|
-
file,
|
|
350
|
-
relPath,
|
|
351
|
-
callerVar,
|
|
352
|
-
prefix: prefixLit,
|
|
353
|
-
targetVar: scopedVar,
|
|
354
|
-
line: node.startPosition.row + 1,
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
} else if (ELYSIA_VERBS.has(lowerMethod)) {
|
|
359
|
-
// Direct route: app.get('/path', handler, options) or app.post('/path', { body: ... }, handler)
|
|
360
|
-
if (args.length >= 2) {
|
|
361
|
-
const rawPath = cleanLiteral(args[0]);
|
|
362
|
-
if (rawPath !== undefined) {
|
|
363
|
-
let handlerNode: Parser.SyntaxNode | undefined;
|
|
364
|
-
let optionsNode: Parser.SyntaxNode | undefined;
|
|
365
|
-
|
|
366
|
-
for (let i = 1; i < args.length; i++) {
|
|
367
|
-
const arg = args[i];
|
|
368
|
-
if (arg.type === "object") {
|
|
369
|
-
optionsNode = arg;
|
|
370
|
-
} else if (
|
|
371
|
-
arg.type === "identifier" ||
|
|
372
|
-
arg.type === "member_expression" ||
|
|
373
|
-
arg.type === "arrow_function" ||
|
|
374
|
-
arg.type === "function" ||
|
|
375
|
-
arg.type === "function_expression"
|
|
376
|
-
) {
|
|
377
|
-
handlerNode = arg;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
144
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const validationSchema = this.extractValidationFromOptions(optionsNode, resolvedImports);
|
|
386
|
-
const handler = this.extractSingleHandler(handlerNode || args[1]);
|
|
387
|
-
|
|
388
|
-
routes.push({
|
|
389
|
-
file,
|
|
390
|
-
relPath,
|
|
391
|
-
routerVar: callerVar,
|
|
392
|
-
httpMethods: lowerMethod === "all" ? ["GET", "POST", "PUT", "DELETE"] : [lowerMethod.toUpperCase()],
|
|
393
|
-
rawPath,
|
|
394
|
-
validationSchema,
|
|
395
|
-
handler,
|
|
396
|
-
routeLine: node.startPosition.row + 1,
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
145
|
+
if (method === "group" || method === "guard") {
|
|
146
|
+
if (method === "guard" && call.arguments.length < 2) {
|
|
147
|
+
parent.schema = schemaFor(call.arguments[0]) ?? parent.schema;
|
|
148
|
+
return;
|
|
402
149
|
}
|
|
150
|
+
const threeArguments = method === "group" && call.arguments.length >= 3;
|
|
151
|
+
const sub = method === "group" ? literal(call.arguments[0]) : "";
|
|
152
|
+
const schema = schemaFor(threeArguments || method === "guard" ? call.arguments[method === "guard" ? 0 : 1] : undefined);
|
|
153
|
+
const child: Scope = { prefix: "", routes: new Map(), schema: schema ?? parent.schema };
|
|
154
|
+
visitCallback(call.arguments[threeArguments ? 2 : 1], child, frames);
|
|
155
|
+
if (sub !== undefined) copyRoutes(parent, child, sub);
|
|
156
|
+
return;
|
|
403
157
|
}
|
|
404
158
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
159
|
+
const rawMethod = method === "route" ? literal(call.arguments[0])?.toUpperCase() : method.toUpperCase();
|
|
160
|
+
if (!rawMethod || !/^[A-Z][A-Z0-9-]*$/.test(rawMethod) || parent.prefix === undefined) return;
|
|
161
|
+
const offset = method === "route" ? 1 : 0;
|
|
162
|
+
const local = literal(call.arguments[offset]);
|
|
163
|
+
const handler = call.arguments[offset + 1];
|
|
164
|
+
if (local === undefined || !handler) return;
|
|
165
|
+
put(parent, {
|
|
166
|
+
method: rawMethod === "ALL" ? "ANY" : rawMethod, uri: parent.prefix + leadingSlash(local),
|
|
167
|
+
call, handler, schema: schemaFor(call.arguments[offset + 2]) ?? parent.schema,
|
|
168
|
+
});
|
|
408
169
|
};
|
|
409
170
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
private extractValidationFromOptions(
|
|
415
|
-
optsNode: Parser.SyntaxNode | undefined,
|
|
416
|
-
resolvedImports: Map<string, string>
|
|
417
|
-
): { symbol: string; file?: string; line?: number } | undefined {
|
|
418
|
-
if (!optsNode || optsNode.type !== "object") return undefined;
|
|
419
|
-
|
|
420
|
-
for (const pair of optsNode.namedChildren) {
|
|
421
|
-
if (pair.type === "pair") {
|
|
422
|
-
const keyNode = pair.childForFieldName("key");
|
|
423
|
-
const valNode = pair.childForFieldName("value");
|
|
424
|
-
const keyText = keyNode ? keyNode.text.trim().replace(/^['"]|['"]$/g, "") : "";
|
|
171
|
+
const rootFrames: Frames = new Map();
|
|
172
|
+
const elysiaRouteHint = /\.(?:use|group|get|post|put|patch|delete|head|options|trace|connect|all|ws|route)\s*\(|\bnew\s+Elysia\b/;
|
|
173
|
+
bindings.visitModules(files, unit => visitRouteCalls(unit.source, call => readCall(call, rootFrames)), elysiaRouteHint);
|
|
425
174
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
175
|
+
const slices: VerticalSliceCandidate[] = [];
|
|
176
|
+
for (const scope of scopes.values()) {
|
|
177
|
+
if (mounted.has(scope)) continue;
|
|
178
|
+
for (const route of scope.routes.values()) {
|
|
179
|
+
signal?.throwIfAborted();
|
|
180
|
+
const routeFile = fileOf(route.call);
|
|
181
|
+
const handler = bindings.handler(route.handler);
|
|
182
|
+
const action = handler ? (handler.name === "callback" ? "closure" : handler.name) : route.handler.getText();
|
|
183
|
+
const controllerFile = handler ? fileOf(handler.node) : null;
|
|
184
|
+
const controllerLine = handler ? lineOf(handler.node) : 0;
|
|
185
|
+
const controller = path.basename(controllerFile ?? routeFile).replace(/\.[^.]+$/, "");
|
|
186
|
+
const uri = route.uri || "/";
|
|
187
|
+
const chain: ExecutionChainNode[] = [{
|
|
188
|
+
stage: "ingress", symbol: route.method + " " + uri, file: routeFile, line: lineOf(route.call),
|
|
189
|
+
description: "Elysia Route Registration",
|
|
190
|
+
}];
|
|
191
|
+
if (route.schema) {
|
|
192
|
+
chain.push({
|
|
193
|
+
stage: "validation", symbol: route.schema.getText(), file: fileOf(route.schema), line: lineOf(route.schema),
|
|
194
|
+
description: "Elysia Route Schema Option",
|
|
195
|
+
});
|
|
437
196
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
private extractSingleHandler(node: Parser.SyntaxNode): { symbol: string; line: number; node: Parser.SyntaxNode } {
|
|
445
|
-
const line = node.startPosition.row + 1;
|
|
446
|
-
if (node.type === "identifier" || node.type === "member_expression") {
|
|
447
|
-
return { symbol: node.text.trim(), line, node };
|
|
448
|
-
}
|
|
449
|
-
if (node.type === "arrow_function" || node.type === "function_expression" || node.type === "function") {
|
|
450
|
-
const nameNode = node.childForFieldName("name");
|
|
451
|
-
const name = nameNode ? nameNode.text.trim() : "closure";
|
|
452
|
-
return { symbol: name, line, node };
|
|
453
|
-
}
|
|
454
|
-
return { symbol: "closure", line, node };
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
private resolvePrefixHierarchy(
|
|
458
|
-
allMounts: ExtractedMount[],
|
|
459
|
-
fileImports: Map<string, Map<string, string>>
|
|
460
|
-
): Map<string, string[]> {
|
|
461
|
-
const parentMap = new Map<string, Array<{ parentKey: string; prefix: string }>>();
|
|
462
|
-
const allRouterKeys = new Set<string>();
|
|
463
|
-
|
|
464
|
-
for (const m of allMounts) {
|
|
465
|
-
const parentKey = `${m.relPath}#${m.callerVar}`;
|
|
466
|
-
allRouterKeys.add(parentKey);
|
|
467
|
-
|
|
468
|
-
let targetKey: string | undefined;
|
|
469
|
-
const importedFile = fileImports.get(m.relPath)?.get(m.targetVar);
|
|
470
|
-
if (importedFile) {
|
|
471
|
-
targetKey = `${importedFile}#${m.targetVar}`;
|
|
472
|
-
} else {
|
|
473
|
-
targetKey = `${m.relPath}#${m.targetVar}`;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
allRouterKeys.add(targetKey);
|
|
477
|
-
if (!parentMap.has(targetKey)) parentMap.set(targetKey, []);
|
|
478
|
-
parentMap.get(targetKey)!.push({ parentKey, prefix: m.prefix });
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
const prefixesByRouter = new Map<string, string[]>();
|
|
482
|
-
|
|
483
|
-
for (const rKey of allRouterKeys) {
|
|
484
|
-
const parents = parentMap.get(rKey);
|
|
485
|
-
if (!parents || parents.length === 0) {
|
|
486
|
-
prefixesByRouter.set(rKey, [""]);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
const queue = Array.from(prefixesByRouter.keys());
|
|
491
|
-
const visitedEdges = new Set<string>();
|
|
492
|
-
|
|
493
|
-
while (queue.length > 0) {
|
|
494
|
-
const current = queue.shift()!;
|
|
495
|
-
const currentPrefixes = prefixesByRouter.get(current) ?? [""];
|
|
496
|
-
|
|
497
|
-
for (const [targetKey, parents] of parentMap.entries()) {
|
|
498
|
-
for (const p of parents) {
|
|
499
|
-
if (p.parentKey === current) {
|
|
500
|
-
const edgeKey = `${current}->${targetKey}:${p.prefix}`;
|
|
501
|
-
if (visitedEdges.has(edgeKey)) continue;
|
|
502
|
-
visitedEdges.add(edgeKey);
|
|
503
|
-
|
|
504
|
-
const nextPrefixes = currentPrefixes.map((cp) => normalizeRouteUri(cp, p.prefix));
|
|
505
|
-
const existing = prefixesByRouter.get(targetKey) ?? [];
|
|
506
|
-
const merged = Array.from(new Set([...existing, ...nextPrefixes]));
|
|
507
|
-
prefixesByRouter.set(targetKey, merged);
|
|
508
|
-
queue.push(targetKey);
|
|
509
|
-
}
|
|
197
|
+
if (handler && controllerFile) {
|
|
198
|
+
chain.push({
|
|
199
|
+
stage: "controller", symbol: action, file: controllerFile, line: controllerLine,
|
|
200
|
+
description: "Elysia Action Handler",
|
|
201
|
+
}, ...routeContext(handler, bindings, fileOf));
|
|
510
202
|
}
|
|
203
|
+
slices.push({
|
|
204
|
+
domain_id: domainId ?? null, feature_key: `elysia.${controller.toLowerCase()}.${action}`,
|
|
205
|
+
http_method: route.method, route_uri: uri, route_name: `${controller}.${action}`,
|
|
206
|
+
controller_class: controller, action_name: action, controller_file: controllerFile,
|
|
207
|
+
controller_line: controllerLine, architecture_style: "mvc", entry_kind: "http_route",
|
|
208
|
+
execution_chain_json: JSON.stringify(chain),
|
|
209
|
+
});
|
|
511
210
|
}
|
|
512
211
|
}
|
|
513
|
-
|
|
514
|
-
return prefixesByRouter;
|
|
212
|
+
return slices;
|
|
515
213
|
}
|
|
516
214
|
}
|
|
517
|
-
|