@dimassetoid/septum-mcp 0.2.1 → 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 +46 -45
- package/package.json +8 -6
- package/src/cli/commands/check.ts +41 -26
- package/src/cli/commands/hook.ts +77 -105
- package/src/cli/commands/init.ts +35 -9
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +35 -9
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +15 -51
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +51 -27
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +46 -35
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +299 -178
- package/src/core/boundary/staged-auditor.ts +188 -34
- package/src/core/config/domain-ownership.ts +47 -0
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +82 -54
- package/src/core/config/schema.ts +24 -46
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +326 -543
- package/src/core/database/repositories/domain.repository.ts +48 -4
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -259
- package/src/core/database/repository.ts +138 -24
- package/src/core/database/schema.ts +28 -33
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +269 -0
- package/src/core/discovery/topology-detector.ts +153 -170
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +378 -212
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +16 -4
- package/src/core/parser/extractors/csharp.ts +9 -5
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +400 -516
- package/src/core/parser/extractors/elysia-semantic.ts +172 -496
- package/src/core/parser/extractors/express-semantic.ts +195 -398
- package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
- package/src/core/parser/extractors/fastify-semantic.ts +216 -732
- package/src/core/parser/extractors/flask-semantic.ts +92 -388
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +210 -508
- 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 -530
- package/src/core/parser/extractors/java.ts +7 -5
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +169 -333
- 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 +84 -336
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
- 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 +17 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +9 -8
- package/src/core/parser/extractors/registry.ts +28 -5
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +10 -7
- package/src/core/parser/extractors/rust.ts +35 -17
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +75 -262
- 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 +36 -216
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- 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 +375 -311
- 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 +162 -181
- package/src/core/resolver/interpretation-inputs.ts +65 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +133 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +74 -0
- package/src/core/resolver/module-resolver.ts +18 -7
- 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 +94 -0
- package/src/core/resolver/slice-format.ts +22 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +477 -0
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +57 -278
- package/src/core/resources/ignore.ts +21 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +116 -0
- package/src/core/retrieval/context.ts +457 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/source-context.ts +448 -0
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +293 -0
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +225 -37
- package/src/index.ts +0 -3
- 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 -1105
- package/src/mcp/server.ts +263 -597
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +69 -4
- package/src/mcp/tools/map.ts +126 -0
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +480 -26
- 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 +102 -18
- package/src/mcp/workspace-watcher.ts +38 -19
- package/src/types/index.ts +47 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/check-boundary.ts +0 -387
- package/src/mcp/tools/domain.ts +0 -40
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-domain-catalog.ts +0 -226
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/get-symbol-impact.ts +0 -64
- package/src/mcp/tools/get-symbol.ts +0 -175
- package/src/mcp/tools/locate-symbol.ts +0 -196
- package/src/mcp/tools/register-domain.ts +0 -75
- package/src/mcp/tools/register-feature.ts +0 -110
- package/src/mcp/tools/trace-vertical-slice.ts +0 -80
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Accumulate all mount paths at each router before propagating them to descendants. */
|
|
2
|
+
export function composeMountPrefixes<Key>(
|
|
3
|
+
roots: ReadonlyMap<Key, string | undefined>,
|
|
4
|
+
mounts: ReadonlyArray<{ parent: Key; child: Key; prefix: string | undefined }>,
|
|
5
|
+
signal?: AbortSignal,
|
|
6
|
+
): Map<Key, Set<string>> {
|
|
7
|
+
const children = new Map<Key, typeof mounts[number][]>();
|
|
8
|
+
const incoming = new Map<Key, number>();
|
|
9
|
+
for (const mount of mounts) {
|
|
10
|
+
const edges = children.get(mount.parent) ?? [];
|
|
11
|
+
edges.push(mount);
|
|
12
|
+
children.set(mount.parent, edges);
|
|
13
|
+
incoming.set(mount.child, (incoming.get(mount.child) ?? 0) + 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const prefixes = new Map<Key, Set<string>>();
|
|
17
|
+
const queue: Key[] = [];
|
|
18
|
+
for (const [key, prefix] of roots) {
|
|
19
|
+
if (incoming.has(key)) continue;
|
|
20
|
+
queue.push(key);
|
|
21
|
+
prefixes.set(key, new Set(prefix === undefined ? [] : [prefix]));
|
|
22
|
+
}
|
|
23
|
+
for (let index = 0; index < queue.length; index++) {
|
|
24
|
+
signal?.throwIfAborted();
|
|
25
|
+
const parent = queue[index]!;
|
|
26
|
+
for (const edge of children.get(parent) ?? []) {
|
|
27
|
+
const paths = prefixes.get(edge.child) ?? new Set<string>();
|
|
28
|
+
if (edge.prefix !== undefined) {
|
|
29
|
+
for (const path of prefixes.get(parent) ?? []) {
|
|
30
|
+
signal?.throwIfAborted();
|
|
31
|
+
paths.add(path + edge.prefix);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
prefixes.set(edge.child, paths);
|
|
35
|
+
const remaining = incoming.get(edge.child)! - 1;
|
|
36
|
+
incoming.set(edge.child, remaining);
|
|
37
|
+
if (!remaining) queue.push(edge.child);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Cycles (and routes depending on them) have no complete registration path.
|
|
41
|
+
for (const [key, remaining] of incoming) if (remaining) prefixes.delete(key);
|
|
42
|
+
return prefixes;
|
|
43
|
+
}
|
|
@@ -79,19 +79,22 @@ export class RubyExtractor implements CodeExtractor {
|
|
|
79
79
|
continue;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
if (methodName === "require" || methodName === "require_relative") {
|
|
82
|
+
if ((methodName === "require" || methodName === "require_relative") && !child.childForFieldName("receiver")) {
|
|
83
83
|
const argsNode = child.childForFieldName("arguments") ?? child.namedChildren[1];
|
|
84
84
|
if (argsNode) {
|
|
85
|
-
const
|
|
85
|
+
const arg = argsNode.namedChildren[0];
|
|
86
|
+
const literal = arg?.type === "string" && !arg.namedChildren.some(c => c.type === "interpolation")
|
|
87
|
+
&& !arg.text.includes("\\") && argsNode.namedChildren.length === 1;
|
|
88
|
+
const rawTarget = literal ? arg.text.slice(1, -1) : `dynamic:${child.text}`;
|
|
86
89
|
const isRel = methodName === "require_relative";
|
|
87
90
|
const leaf = rawTarget.split("/").pop() || rawTarget;
|
|
88
91
|
|
|
89
92
|
dependencies.push({
|
|
90
93
|
target: rawTarget,
|
|
91
|
-
statement:
|
|
94
|
+
statement: child.text.trim(),
|
|
92
95
|
line_number: child.startPosition.row + 1,
|
|
93
|
-
is_external: this.isExternalRequire(rawTarget, isRel),
|
|
94
|
-
imported_symbols: [leaf],
|
|
96
|
+
is_external: literal ? this.isExternalRequire(rawTarget, isRel) : false,
|
|
97
|
+
...(literal ? { imported_symbols: [leaf] } : {}),
|
|
95
98
|
});
|
|
96
99
|
}
|
|
97
100
|
}
|
|
@@ -107,7 +110,7 @@ export class RubyExtractor implements CodeExtractor {
|
|
|
107
110
|
const fullName = scopeName ? `${scopeName}::${baseName}` : baseName;
|
|
108
111
|
const lineStart = child.startPosition.row + 1;
|
|
109
112
|
const lineEnd = Math.max(lineStart, child.endPosition.row + 1);
|
|
110
|
-
const headerLine = getNodeHeader(child);
|
|
113
|
+
const headerLine = getNodeHeader(child, content);
|
|
111
114
|
const kind = child.type === "class" ? "class" : "interface";
|
|
112
115
|
|
|
113
116
|
symbols.push({
|
|
@@ -142,7 +145,7 @@ export class RubyExtractor implements CodeExtractor {
|
|
|
142
145
|
: methodName;
|
|
143
146
|
const lineStart = child.startPosition.row + 1;
|
|
144
147
|
const lineEnd = Math.max(lineStart, child.endPosition.row + 1);
|
|
145
|
-
const headerLine = getNodeHeader(child);
|
|
148
|
+
const headerLine = getNodeHeader(child, content);
|
|
146
149
|
const nestingDepth = calculateAstControlFlowNesting(
|
|
147
150
|
child,
|
|
148
151
|
RUBY_CONTROL_FLOW_NODES,
|
|
@@ -68,23 +68,41 @@ export class RustExtractor implements CodeExtractor {
|
|
|
68
68
|
const body = node.childForFieldName("body");
|
|
69
69
|
if (name && body) {
|
|
70
70
|
for (const child of body.namedChildren) processItem(child, qualify(name.text));
|
|
71
|
+
} else if (name) {
|
|
72
|
+
dependencies.push({ target: `mod:${name.text}`, statement: node.text.trim(),
|
|
73
|
+
line_number: node.startPosition.row + 1, is_external: false, imported_symbols: [name.text] });
|
|
71
74
|
}
|
|
72
75
|
return;
|
|
73
76
|
}
|
|
74
77
|
if (node.type === "use_declaration") {
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
const argument = node.childForFieldName("argument");
|
|
79
|
+
const addUse = (item: Parser.SyntaxNode, prefix = ""): void => {
|
|
80
|
+
if (item.type === "line_comment" || item.type === "block_comment") return;
|
|
81
|
+
if (item.type === "scoped_use_list") {
|
|
82
|
+
const scope = item.childForFieldName("path")?.text;
|
|
83
|
+
const list = item.childForFieldName("list");
|
|
84
|
+
const nestedPrefix = [prefix, scope].filter(Boolean).join("::");
|
|
85
|
+
if (list) for (const child of list.namedChildren) addUse(child, nestedPrefix);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (item.type === "use_list") {
|
|
89
|
+
for (const child of item.namedChildren) addUse(child, prefix);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const alias = item.type === "use_as_clause" ? item.childForFieldName("alias")?.text : undefined;
|
|
93
|
+
const importPath = item.type === "use_as_clause" ? item.childForFieldName("path")?.text : item.text;
|
|
94
|
+
if (!importPath) return;
|
|
95
|
+
const target = importPath === "self" && prefix ? prefix : [prefix, importPath].filter(Boolean).join("::");
|
|
96
|
+
const leaf = target.split("::").pop()!;
|
|
97
|
+
dependencies.push({
|
|
98
|
+
target,
|
|
99
|
+
statement: node.text.trim().replace(/;$/, ""),
|
|
100
|
+
line_number: node.startPosition.row + 1,
|
|
101
|
+
is_external: this.isExternalUse(target),
|
|
102
|
+
imported_symbols: [...new Set([leaf, ...(alias ? [alias] : [])])],
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
if (argument) addUse(argument);
|
|
88
106
|
return;
|
|
89
107
|
}
|
|
90
108
|
|
|
@@ -97,7 +115,7 @@ export class RustExtractor implements CodeExtractor {
|
|
|
97
115
|
const fnName = nameNode.text;
|
|
98
116
|
const lineStart = node.startPosition.row + 1;
|
|
99
117
|
const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
|
|
100
|
-
const headerLine = getNodeHeader(node);
|
|
118
|
+
const headerLine = getNodeHeader(node, content);
|
|
101
119
|
const nestingDepth = calculateAstControlFlowNesting(
|
|
102
120
|
node,
|
|
103
121
|
RUST_CONTROL_FLOW_NODES,
|
|
@@ -126,7 +144,7 @@ export class RustExtractor implements CodeExtractor {
|
|
|
126
144
|
const structName = nameNode.text;
|
|
127
145
|
const lineStart = node.startPosition.row + 1;
|
|
128
146
|
const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
|
|
129
|
-
const headerLine = getNodeHeader(node);
|
|
147
|
+
const headerLine = getNodeHeader(node, content);
|
|
130
148
|
|
|
131
149
|
symbols.push({
|
|
132
150
|
name: qualify(structName),
|
|
@@ -150,7 +168,7 @@ export class RustExtractor implements CodeExtractor {
|
|
|
150
168
|
const enumName = nameNode.text;
|
|
151
169
|
const lineStart = node.startPosition.row + 1;
|
|
152
170
|
const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
|
|
153
|
-
const headerLine = getNodeHeader(node);
|
|
171
|
+
const headerLine = getNodeHeader(node, content);
|
|
154
172
|
|
|
155
173
|
symbols.push({
|
|
156
174
|
name: qualify(enumName),
|
|
@@ -174,7 +192,7 @@ export class RustExtractor implements CodeExtractor {
|
|
|
174
192
|
const traitName = nameNode.text;
|
|
175
193
|
const lineStart = node.startPosition.row + 1;
|
|
176
194
|
const lineEnd = Math.max(lineStart, node.endPosition.row + 1);
|
|
177
|
-
const headerLine = getNodeHeader(node);
|
|
195
|
+
const headerLine = getNodeHeader(node, content);
|
|
178
196
|
|
|
179
197
|
symbols.push({
|
|
180
198
|
name: qualify(traitName),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { VerticalSliceRecord } from "../../../types/index.ts";
|
|
2
|
+
import type { SourceInventory } from "../../resources/source-inventory.ts";
|
|
2
3
|
|
|
3
4
|
export type VerticalSliceCandidate = Omit<VerticalSliceRecord, "id" | "created_at">;
|
|
4
5
|
|
|
@@ -17,6 +18,7 @@ export interface SemanticSliceExtractor {
|
|
|
17
18
|
extractSlices(
|
|
18
19
|
projectRoot: string,
|
|
19
20
|
domainId?: number,
|
|
20
|
-
signal?: AbortSignal
|
|
21
|
+
signal?: AbortSignal,
|
|
22
|
+
inventory?: SourceInventory
|
|
21
23
|
): Promise<VerticalSliceCandidate[]> | VerticalSliceCandidate[];
|
|
22
24
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type Parser from "web-tree-sitter";
|
|
2
|
+
import { children, importsFor, literal, phpSections } from "./php-ast-helpers.ts";
|
|
3
|
+
|
|
4
|
+
type Node = Parser.SyntaxNode;
|
|
5
|
+
type RouteAttribute = { path: string; name?: string; methods: string[] };
|
|
6
|
+
type ResolveClass = (name: string) => string | undefined;
|
|
7
|
+
|
|
8
|
+
const routeClasses = new Set([
|
|
9
|
+
"symfony\\component\\routing\\attribute\\route",
|
|
10
|
+
"symfony\\component\\routing\\annotation\\route",
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
function routeAttributes(node: Node, resolveClass: ResolveClass): Node[] {
|
|
14
|
+
return children(node.childForFieldName("attributes")).flatMap(group =>
|
|
15
|
+
children(group).filter(attribute => {
|
|
16
|
+
const name = children(attribute)[0];
|
|
17
|
+
return attribute.type === "attribute" && !!name &&
|
|
18
|
+
routeClasses.has(resolveClass(name.text)?.toLowerCase() ?? "");
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function readAttribute(node: Node): RouteAttribute | undefined {
|
|
24
|
+
if (node.hasError) return undefined;
|
|
25
|
+
const fields = new Map<string, Node>();
|
|
26
|
+
const positional = ["path", "name", "requirements", "options", "defaults", "host", "methods"];
|
|
27
|
+
let position = 0;
|
|
28
|
+
for (const arg of children(node.childForFieldName("parameters"))) {
|
|
29
|
+
const label = arg.childForFieldName("name");
|
|
30
|
+
const key = label?.text ?? positional[position++];
|
|
31
|
+
const values = children(arg).slice(label ? 1 : 0);
|
|
32
|
+
if (arg.type !== "argument" || values.length !== 1 || values[0]?.type === "variadic_unpacking") return undefined;
|
|
33
|
+
if (key && fields.has(key)) return undefined;
|
|
34
|
+
if (key) fields.set(key, values[0]!);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const pathNode = fields.get("path");
|
|
38
|
+
const nameNode = fields.get("name");
|
|
39
|
+
const path = !pathNode || pathNode.type === "null" ? "" : literal(pathNode);
|
|
40
|
+
const name = literal(nameNode);
|
|
41
|
+
if (path === undefined || (nameNode && nameNode.type !== "null" && name === undefined)) return undefined;
|
|
42
|
+
|
|
43
|
+
const methodNode = fields.get("methods");
|
|
44
|
+
const values = methodNode?.type === "array_creation_expression"
|
|
45
|
+
? children(methodNode).map(item => {
|
|
46
|
+
const parts = children(item);
|
|
47
|
+
return parts.length === 1 ? literal(parts[0]) : undefined;
|
|
48
|
+
})
|
|
49
|
+
: methodNode ? [literal(methodNode)] : [];
|
|
50
|
+
if (!values.every((value): value is string => value !== undefined && /^[a-z][a-z-]*$/i.test(value))) return undefined;
|
|
51
|
+
return { path, name, methods: values.map(value => value.toUpperCase()) };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function visitSymfonyRoutes(
|
|
55
|
+
root: Node,
|
|
56
|
+
visit: (route: {
|
|
57
|
+
uri: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
methods: string[];
|
|
60
|
+
className: string;
|
|
61
|
+
action: Node;
|
|
62
|
+
resolveClass: ResolveClass;
|
|
63
|
+
}) => void,
|
|
64
|
+
signal?: AbortSignal,
|
|
65
|
+
): void {
|
|
66
|
+
for (const { namespace, statements } of phpSections(root)) {
|
|
67
|
+
const imports = importsFor(statements);
|
|
68
|
+
const resolveClass: ResolveClass = name => {
|
|
69
|
+
if (name.startsWith("\\")) return name.slice(1);
|
|
70
|
+
const [head, ...tail] = name.split("\\");
|
|
71
|
+
const key = head!.toLowerCase();
|
|
72
|
+
if (key === "namespace" && tail.length) return [namespace, ...tail].filter(Boolean).join("\\");
|
|
73
|
+
if (!imports.has(key)) return [namespace, name].filter(Boolean).join("\\");
|
|
74
|
+
const imported = imports.get(key);
|
|
75
|
+
return imported ? [imported, ...tail].join("\\") : undefined;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
for (const node of statements) {
|
|
79
|
+
signal?.throwIfAborted();
|
|
80
|
+
if (node.type !== "class_declaration" || children(node).some(child => child.type === "abstract_modifier")) continue;
|
|
81
|
+
const name = node.childForFieldName("name")?.text;
|
|
82
|
+
if (!name) continue;
|
|
83
|
+
const className = [namespace, name].filter(Boolean).join("\\");
|
|
84
|
+
const classAttributes = routeAttributes(node, resolveClass);
|
|
85
|
+
const methods = children(node.childForFieldName("body"))
|
|
86
|
+
.filter(member => member.type === "method_declaration" && member.childForFieldName("body"))
|
|
87
|
+
.map(action => ({ action, attributes: routeAttributes(action, resolveClass) }));
|
|
88
|
+
|
|
89
|
+
const emit = (action: Node, attributes: Node[], prefix?: RouteAttribute) => {
|
|
90
|
+
for (const attribute of attributes) {
|
|
91
|
+
signal?.throwIfAborted();
|
|
92
|
+
const route = readAttribute(attribute);
|
|
93
|
+
if (!route) continue;
|
|
94
|
+
const methods = [...new Set([...(prefix?.methods ?? []), ...route.methods])];
|
|
95
|
+
const uri = "/" + [prefix?.path, route.path].filter(Boolean).join("").replace(/^\/+/, "");
|
|
96
|
+
visit({
|
|
97
|
+
uri, name: route.name === undefined ? undefined : (prefix?.name ?? "") + route.name,
|
|
98
|
+
methods: methods.length ? methods : ["ANY"], className, action, resolveClass,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (methods.some(method => method.attributes.length)) {
|
|
104
|
+
const prefixAttribute = classAttributes[0];
|
|
105
|
+
const prefix = prefixAttribute && readAttribute(prefixAttribute);
|
|
106
|
+
if (prefixAttribute && !prefix) continue;
|
|
107
|
+
for (const { action, attributes } of methods) emit(action, attributes, prefix);
|
|
108
|
+
} else {
|
|
109
|
+
const invokable = methods.find(({ action }) => action.childForFieldName("name")?.text.toLowerCase() === "__invoke");
|
|
110
|
+
if (invokable) emit(invokable.action, classAttributes);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|