@dataparade/cli 0.0.9 → 0.0.10

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.
Files changed (164) hide show
  1. package/README.md +1 -1
  2. package/dist/package.json +1 -1
  3. package/dist/src/ai-enrichment/lambda-init-error.d.ts +5 -0
  4. package/dist/src/ai-enrichment/lambda-init-error.js +38 -0
  5. package/dist/src/ai-enrichment/providers/platform-proxy-provider.d.ts +5 -0
  6. package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +27 -1
  7. package/dist/src/analyzers/cpp/cpp-detection-config.d.ts +73 -0
  8. package/dist/src/analyzers/cpp/cpp-detection-config.js +137 -0
  9. package/dist/src/analyzers/cpp/dependency-manifests.d.ts +8 -0
  10. package/dist/src/analyzers/cpp/dependency-manifests.js +130 -0
  11. package/dist/src/analyzers/cpp/detector.d.ts +3 -0
  12. package/dist/src/analyzers/cpp/detector.js +21 -0
  13. package/dist/src/analyzers/cpp/index.d.ts +2 -0
  14. package/dist/src/analyzers/cpp/index.js +11 -0
  15. package/dist/src/analyzers/cpp/manifest-parsers.d.ts +13 -0
  16. package/dist/src/analyzers/cpp/manifest-parsers.js +104 -0
  17. package/dist/src/analyzers/cpp/parser.d.ts +35 -0
  18. package/dist/src/analyzers/cpp/parser.js +206 -0
  19. package/dist/src/analyzers/cpp/patterns.d.ts +3 -0
  20. package/dist/src/analyzers/cpp/patterns.js +37 -0
  21. package/dist/src/analyzers/csharp/csharp-detection-config.d.ts +100 -0
  22. package/dist/src/analyzers/csharp/csharp-detection-config.js +160 -0
  23. package/dist/src/analyzers/csharp/dependency-manifests.d.ts +13 -0
  24. package/dist/src/analyzers/csharp/dependency-manifests.js +184 -0
  25. package/dist/src/analyzers/csharp/detector.d.ts +3 -0
  26. package/dist/src/analyzers/csharp/detector.js +21 -0
  27. package/dist/src/analyzers/csharp/index.d.ts +2 -0
  28. package/dist/src/analyzers/csharp/index.js +11 -0
  29. package/dist/src/analyzers/csharp/manifest-parsers.d.ts +34 -0
  30. package/dist/src/analyzers/csharp/manifest-parsers.js +130 -0
  31. package/dist/src/analyzers/csharp/parser.d.ts +48 -0
  32. package/dist/src/analyzers/csharp/parser.js +277 -0
  33. package/dist/src/analyzers/csharp/patterns.d.ts +3 -0
  34. package/dist/src/analyzers/csharp/patterns.js +57 -0
  35. package/dist/src/analyzers/go/dependency-manifests.d.ts +10 -0
  36. package/dist/src/analyzers/go/dependency-manifests.js +117 -0
  37. package/dist/src/analyzers/go/detector.d.ts +3 -0
  38. package/dist/src/analyzers/go/detector.js +21 -0
  39. package/dist/src/analyzers/go/go-detection-config.d.ts +97 -0
  40. package/dist/src/analyzers/go/go-detection-config.js +164 -0
  41. package/dist/src/analyzers/go/index.d.ts +2 -0
  42. package/dist/src/analyzers/go/index.js +11 -0
  43. package/dist/src/analyzers/go/manifest-parsers.d.ts +20 -0
  44. package/dist/src/analyzers/go/manifest-parsers.js +104 -0
  45. package/dist/src/analyzers/go/parser.d.ts +40 -0
  46. package/dist/src/analyzers/go/parser.js +186 -0
  47. package/dist/src/analyzers/go/patterns.d.ts +3 -0
  48. package/dist/src/analyzers/go/patterns.js +50 -0
  49. package/dist/src/analyzers/jvm/dependency-manifests.d.ts +16 -0
  50. package/dist/src/analyzers/jvm/dependency-manifests.js +205 -0
  51. package/dist/src/analyzers/jvm/detector.d.ts +3 -0
  52. package/dist/src/analyzers/jvm/detector.js +21 -0
  53. package/dist/src/analyzers/jvm/index.d.ts +9 -0
  54. package/dist/src/analyzers/jvm/index.js +18 -0
  55. package/dist/src/analyzers/jvm/jvm-detection-config.d.ts +136 -0
  56. package/dist/src/analyzers/jvm/jvm-detection-config.js +195 -0
  57. package/dist/src/analyzers/jvm/manifest-parsers.d.ts +61 -0
  58. package/dist/src/analyzers/jvm/manifest-parsers.js +246 -0
  59. package/dist/src/analyzers/jvm/parser.d.ts +54 -0
  60. package/dist/src/analyzers/jvm/parser.js +419 -0
  61. package/dist/src/analyzers/jvm/patterns.d.ts +3 -0
  62. package/dist/src/analyzers/jvm/patterns.js +64 -0
  63. package/dist/src/analyzers/python/detector.js +1 -1
  64. package/dist/src/analyzers/python/parser.d.ts +1 -0
  65. package/dist/src/analyzers/python/parser.js +7 -0
  66. package/dist/src/analyzers/python/patterns.d.ts +1 -0
  67. package/dist/src/analyzers/python/patterns.js +22 -77
  68. package/dist/src/analyzers/python/python-detection-config.d.ts +18 -0
  69. package/dist/src/analyzers/python/python-detection-config.js +20 -0
  70. package/dist/src/analyzers/registry.js +15 -0
  71. package/dist/src/analyzers/shared/c-family-calls.d.ts +26 -0
  72. package/dist/src/analyzers/shared/c-family-calls.js +118 -0
  73. package/dist/src/analyzers/shared/strip-comments.d.ts +32 -0
  74. package/dist/src/analyzers/shared/strip-comments.js +167 -0
  75. package/dist/src/analyzers/typescript/detector.js +1 -1
  76. package/dist/src/analyzers/typescript/typescript-detection-config.d.ts +37 -0
  77. package/dist/src/analyzers/typescript/typescript-detection-config.js +48 -0
  78. package/dist/src/analyzers/typescript/typescript-detection.d.ts +1 -0
  79. package/dist/src/analyzers/typescript/typescript-detection.js +27 -29
  80. package/dist/src/cli.js +1 -1
  81. package/dist/src/config/file.js +5 -0
  82. package/dist/src/config/resolve.js +5 -0
  83. package/dist/src/core/pipeline/graph-mapping.js +3 -0
  84. package/dist/src/core/pipeline/structural-scan.js +154 -31
  85. package/dist/src/core/schema/scan-config.schema.d.ts +5 -0
  86. package/dist/src/core/schema/scan-config.schema.js +5 -0
  87. package/dist/src/core/schema/scan-result.schema.d.ts +5 -0
  88. package/dist/src/core/schema/scan-result.schema.js +5 -0
  89. package/dist/src/core/sectioning/discover-service-sections.js +27 -1
  90. package/dist/src/core/types/file.d.ts +1 -1
  91. package/dist/src/ingest/file-system.js +27 -0
  92. package/dist/src/patterns/config.d.ts +8 -0
  93. package/dist/src/patterns/config.js +136 -0
  94. package/dist/src/patterns/detectors/cpp.d.ts +8 -0
  95. package/dist/src/patterns/detectors/cpp.js +243 -0
  96. package/dist/src/patterns/detectors/csharp.d.ts +9 -0
  97. package/dist/src/patterns/detectors/csharp.js +385 -0
  98. package/dist/src/patterns/detectors/go.d.ts +9 -0
  99. package/dist/src/patterns/detectors/go.js +298 -0
  100. package/dist/src/patterns/detectors/helpers.d.ts +3 -0
  101. package/dist/src/patterns/detectors/helpers.js +5 -0
  102. package/dist/src/patterns/detectors/jvm.d.ts +15 -0
  103. package/dist/src/patterns/detectors/jvm.js +537 -0
  104. package/dist/src/patterns/detectors/python.d.ts +1 -0
  105. package/dist/src/patterns/detectors/python.js +92 -5
  106. package/dist/src/patterns/detectors/typescript.d.ts +2 -0
  107. package/dist/src/patterns/detectors/typescript.js +156 -4
  108. package/dist/src/patterns/engine.d.ts +18 -0
  109. package/dist/src/patterns/engine.js +30 -0
  110. package/dist/src/patterns/scan-exclusions.js +20 -0
  111. package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.d.ts +1 -0
  112. package/dist/tests/unit/ai-enrichment/lambda-init-error.spec.js +11 -0
  113. package/dist/tests/unit/ai-enrichment/platform-proxy-provider.spec.js +80 -0
  114. package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.d.ts +1 -0
  115. package/dist/tests/unit/analyzers/cpp/dependency-manifests.spec.js +66 -0
  116. package/dist/tests/unit/analyzers/cpp/parser.spec.d.ts +1 -0
  117. package/dist/tests/unit/analyzers/cpp/parser.spec.js +80 -0
  118. package/dist/tests/unit/analyzers/cpp/patterns.spec.d.ts +1 -0
  119. package/dist/tests/unit/analyzers/cpp/patterns.spec.js +141 -0
  120. package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.d.ts +1 -0
  121. package/dist/tests/unit/analyzers/csharp/dependency-manifests.spec.js +75 -0
  122. package/dist/tests/unit/analyzers/csharp/parser.spec.d.ts +1 -0
  123. package/dist/tests/unit/analyzers/csharp/parser.spec.js +118 -0
  124. package/dist/tests/unit/analyzers/csharp/patterns.spec.d.ts +1 -0
  125. package/dist/tests/unit/analyzers/csharp/patterns.spec.js +210 -0
  126. package/dist/tests/unit/analyzers/go/dependency-manifests.spec.d.ts +1 -0
  127. package/dist/tests/unit/analyzers/go/dependency-manifests.spec.js +96 -0
  128. package/dist/tests/unit/analyzers/go/parser.spec.d.ts +1 -0
  129. package/dist/tests/unit/analyzers/go/parser.spec.js +110 -0
  130. package/dist/tests/unit/analyzers/go/patterns.spec.d.ts +1 -0
  131. package/dist/tests/unit/analyzers/go/patterns.spec.js +239 -0
  132. package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.d.ts +1 -0
  133. package/dist/tests/unit/analyzers/jvm/dependency-manifests.spec.js +179 -0
  134. package/dist/tests/unit/analyzers/jvm/parser.spec.d.ts +1 -0
  135. package/dist/tests/unit/analyzers/jvm/parser.spec.js +195 -0
  136. package/dist/tests/unit/analyzers/jvm/patterns.spec.d.ts +1 -0
  137. package/dist/tests/unit/analyzers/jvm/patterns.spec.js +284 -0
  138. package/dist/tests/unit/analyzers/python/patterns.spec.js +169 -0
  139. package/dist/tests/unit/analyzers/typescript/detector.spec.js +188 -0
  140. package/dist/tests/unit/core/cpp-dotnet-scan.spec.d.ts +1 -0
  141. package/dist/tests/unit/core/cpp-dotnet-scan.spec.js +67 -0
  142. package/dist/tests/unit/core/cpp-dotnet-sections.spec.d.ts +1 -0
  143. package/dist/tests/unit/core/cpp-dotnet-sections.spec.js +46 -0
  144. package/dist/tests/unit/core/go-scan.spec.d.ts +1 -0
  145. package/dist/tests/unit/core/go-scan.spec.js +78 -0
  146. package/dist/tests/unit/core/graph-mapping.spec.js +75 -0
  147. package/dist/tests/unit/core/jvm-scan.spec.d.ts +1 -0
  148. package/dist/tests/unit/core/jvm-scan.spec.js +94 -0
  149. package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.d.ts +1 -0
  150. package/dist/tests/unit/ingest/cpp-dotnet-languages.spec.js +56 -0
  151. package/dist/tests/unit/ingest/jvm-languages.spec.d.ts +1 -0
  152. package/dist/tests/unit/ingest/jvm-languages.spec.js +47 -0
  153. package/package.json +1 -1
  154. package/patterns/cpp.md +176 -0
  155. package/patterns/cpp.patterns.yaml +314 -0
  156. package/patterns/csharp.md +211 -0
  157. package/patterns/csharp.patterns.yaml +375 -0
  158. package/patterns/go.md +211 -0
  159. package/patterns/go.patterns.yaml +429 -0
  160. package/patterns/jvm.md +160 -0
  161. package/patterns/jvm.patterns.yaml +884 -0
  162. package/patterns/python.patterns.yaml +177 -0
  163. package/patterns/third-party.patterns.yaml +5 -0
  164. package/patterns/typescript.patterns.yaml +222 -0
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.isJvmBuildManifestName = isJvmBuildManifestName;
40
+ exports.isSpringConfigName = isSpringConfigName;
41
+ exports.parseJvmDependencyManifests = parseJvmDependencyManifests;
42
+ exports.detectJvmPatternsFromDependencyManifests = detectJvmPatternsFromDependencyManifests;
43
+ const promises_1 = __importDefault(require("fs/promises"));
44
+ const path = __importStar(require("path"));
45
+ const engine_1 = require("../../patterns/engine");
46
+ const manifest_budgets_1 = require("../shared/manifest-budgets");
47
+ const manifest_fs_1 = require("../shared/manifest-fs");
48
+ const jvm_detection_config_1 = require("./jvm-detection-config");
49
+ const manifest_parsers_1 = require("./manifest-parsers");
50
+ function toPosixPath(p) {
51
+ return p.split(path.sep).join("/");
52
+ }
53
+ function createManifestFileInfo(manifestRelativePath) {
54
+ return {
55
+ path: manifestRelativePath,
56
+ name: path.basename(manifestRelativePath),
57
+ content: "",
58
+ language: "java",
59
+ size: 0,
60
+ };
61
+ }
62
+ function isJvmBuildManifestName(name) {
63
+ const lower = name.toLowerCase();
64
+ return (lower === "pom.xml" ||
65
+ lower === "build.gradle" ||
66
+ lower === "build.gradle.kts" ||
67
+ lower === "libs.versions.toml");
68
+ }
69
+ function isSpringConfigName(name) {
70
+ const lower = name.toLowerCase();
71
+ return ((lower.startsWith("application") || lower.startsWith("bootstrap")) &&
72
+ (lower.endsWith(".properties") ||
73
+ lower.endsWith(".yml") ||
74
+ lower.endsWith(".yaml")));
75
+ }
76
+ function extractCoordinates(manifestName, raw) {
77
+ const lower = manifestName.toLowerCase();
78
+ if (lower === "pom.xml")
79
+ return (0, manifest_parsers_1.extractCoordinatesFromPom)(raw);
80
+ if (lower === "libs.versions.toml") {
81
+ return (0, manifest_parsers_1.extractCoordinatesFromVersionCatalog)(raw);
82
+ }
83
+ return (0, manifest_parsers_1.extractCoordinatesFromGradle)(raw);
84
+ }
85
+ async function parseJvmDependencyManifests(rootPath, opts) {
86
+ const rootDir = path.resolve(rootPath);
87
+ const manifests = [];
88
+ const state = (0, manifest_budgets_1.budgetStateFromOptions)(opts);
89
+ await (0, manifest_fs_1.walkForManifests)(rootDir, manifests, {
90
+ rootDir,
91
+ state,
92
+ excludePaths: opts?.excludePaths,
93
+ isManifestFile: (_entry, entryPath) => isJvmBuildManifestName(path.basename(entryPath)),
94
+ });
95
+ const byManifest = [];
96
+ let bytesRead = 0;
97
+ const maxBytes = state.maxTotalManifestReadBytes;
98
+ for (const manifestAbsPath of manifests) {
99
+ if (bytesRead >= maxBytes)
100
+ break;
101
+ const manifestName = path.basename(manifestAbsPath);
102
+ const manifestRelativePath = toPosixPath(path.relative(rootDir, manifestAbsPath));
103
+ let raw;
104
+ try {
105
+ raw = await promises_1.default.readFile(manifestAbsPath, "utf8");
106
+ }
107
+ catch {
108
+ continue;
109
+ }
110
+ bytesRead += raw.length;
111
+ const packages = extractCoordinates(manifestName, raw);
112
+ if (packages.length === 0)
113
+ continue;
114
+ byManifest.push({
115
+ manifestRelativePath,
116
+ packages: Array.from(new Set(packages)),
117
+ });
118
+ }
119
+ return byManifest;
120
+ }
121
+ /**
122
+ * Third-party and dependency detection from JVM build manifests, plus the
123
+ * datasource URIs declared in `application.properties` / `application.yml` —
124
+ * usually the only place a Spring service names the databases it talks to.
125
+ */
126
+ async function detectJvmPatternsFromDependencyManifests(rootPath, opts) {
127
+ const findings = [];
128
+ const manifestPackages = await parseJvmDependencyManifests(rootPath, opts);
129
+ for (const manifest of manifestPackages) {
130
+ const manifestFile = createManifestFileInfo(manifest.manifestRelativePath);
131
+ const imports = manifest.packages.map((coordinate) => {
132
+ const [groupId, artifactId] = coordinate.split(":");
133
+ const segments = groupId.split(".").filter(Boolean);
134
+ return {
135
+ module: coordinate,
136
+ names: Array.from(new Set([coordinate, groupId, artifactId, ...segments])).filter(Boolean),
137
+ };
138
+ });
139
+ findings.push(...(0, engine_1.matchPatterns)({
140
+ language: "java",
141
+ file: manifestFile,
142
+ normalizedPath: manifestFile.path,
143
+ imports,
144
+ }));
145
+ }
146
+ findings.push(...(await detectSpringDatasourceConfig(rootPath, opts)));
147
+ return findings;
148
+ }
149
+ async function detectSpringDatasourceConfig(rootPath, opts) {
150
+ const rootDir = path.resolve(rootPath);
151
+ const configFiles = [];
152
+ const state = (0, manifest_budgets_1.budgetStateFromOptions)(opts);
153
+ await (0, manifest_fs_1.walkForManifests)(rootDir, configFiles, {
154
+ rootDir,
155
+ state,
156
+ excludePaths: opts?.excludePaths,
157
+ isManifestFile: (_entry, entryPath) => isSpringConfigName(path.basename(entryPath)),
158
+ });
159
+ if (configFiles.length === 0)
160
+ return [];
161
+ const jdbcUrl = (0, jvm_detection_config_1.loadJvmPatternConfig)().jdbcUrl;
162
+ const findings = [];
163
+ for (const absPath of configFiles) {
164
+ const relativePath = toPosixPath(path.relative(rootDir, absPath));
165
+ const name = path.basename(relativePath).toLowerCase();
166
+ let raw;
167
+ try {
168
+ raw = await promises_1.default.readFile(absPath, "utf8");
169
+ }
170
+ catch {
171
+ continue;
172
+ }
173
+ findings.push({
174
+ pattern: "config_file",
175
+ name: path.basename(relativePath),
176
+ confidence: 0.9,
177
+ location: { filePath: relativePath, startLine: 1, endLine: 1 },
178
+ properties: {},
179
+ });
180
+ if (!jdbcUrl)
181
+ continue;
182
+ const refs = name.endsWith(".properties")
183
+ ? (0, manifest_parsers_1.extractDatasourceRefsFromProperties)(raw)
184
+ : (0, manifest_parsers_1.extractDatasourceRefsFromYaml)(raw);
185
+ const seen = new Set();
186
+ for (const ref of refs) {
187
+ if (seen.has(ref.driver))
188
+ continue;
189
+ seen.add(ref.driver);
190
+ findings.push({
191
+ pattern: "database_connection",
192
+ name: `${jdbcUrl.name}:${ref.driver}`,
193
+ confidence: 0.85,
194
+ location: { filePath: relativePath, startLine: 1, endLine: 1 },
195
+ properties: {
196
+ client: "spring_datasource",
197
+ databaseType: jdbcUrl.drivers[ref.driver] ?? jdbcUrl.defaultDatabaseType,
198
+ driver: ref.driver,
199
+ key: ref.key,
200
+ },
201
+ });
202
+ }
203
+ }
204
+ return findings;
205
+ }
@@ -0,0 +1,3 @@
1
+ import type { FileInfo } from "../../core/types/file";
2
+ import type { RawFinding } from "../../core/types/detection";
3
+ export declare function detectJvmPatterns(file: FileInfo): RawFinding[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectJvmPatterns = detectJvmPatterns;
4
+ const property_inference_1 = require("../shared/property-inference");
5
+ const parser_1 = require("./parser");
6
+ const patterns_1 = require("./patterns");
7
+ function detectJvmPatterns(file) {
8
+ const model = (0, parser_1.parseJvmSourceFile)(file);
9
+ if (model.file.language !== "java" && model.file.language !== "kotlin") {
10
+ return [];
11
+ }
12
+ const findings = (0, patterns_1.detectJvmPatternsFromModel)(model);
13
+ // Merge pattern-matched component properties (from YAML) into each finding.
14
+ for (const finding of findings) {
15
+ const detected = (0, property_inference_1.getPropertiesFromFinding)(finding, file.content);
16
+ if (Object.keys(detected).length > 0) {
17
+ finding.properties = { ...(finding.properties ?? {}), ...detected };
18
+ }
19
+ }
20
+ return findings;
21
+ }
@@ -0,0 +1,9 @@
1
+ import type { Analyzer } from "../types";
2
+ /**
3
+ * One analyzer serves both Java and Kotlin: they share the JVM package
4
+ * namespace, the Maven/Gradle coordinate space, the Spring and Jakarta
5
+ * annotation vocabulary, and JDBC. Where the languages genuinely differ
6
+ * (declaration grammar, Ktor, Exposed) the parser branches on
7
+ * `FileInfo.language` and the rules are gated by import package.
8
+ */
9
+ export declare function createJvmAnalyzer(): Analyzer;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createJvmAnalyzer = createJvmAnalyzer;
4
+ const detector_1 = require("./detector");
5
+ /**
6
+ * One analyzer serves both Java and Kotlin: they share the JVM package
7
+ * namespace, the Maven/Gradle coordinate space, the Spring and Jakarta
8
+ * annotation vocabulary, and JDBC. Where the languages genuinely differ
9
+ * (declaration grammar, Ktor, Exposed) the parser branches on
10
+ * `FileInfo.language` and the rules are gated by import package.
11
+ */
12
+ function createJvmAnalyzer() {
13
+ return {
14
+ detect(file) {
15
+ return (0, detector_1.detectJvmPatterns)(file);
16
+ },
17
+ };
18
+ }
@@ -0,0 +1,136 @@
1
+ import { type PatternId } from "../../core/types/detection";
2
+ export interface JvmRouteRegex {
3
+ regex: RegExp;
4
+ methodGroup?: number;
5
+ pathGroup?: number;
6
+ defaultMethod?: string;
7
+ }
8
+ export interface JvmAnnotationRoute {
9
+ annotation: string;
10
+ method?: string;
11
+ }
12
+ export interface JvmDbClientConfig {
13
+ id: string;
14
+ patternId: PatternId;
15
+ databaseType: string;
16
+ importPackages: string[];
17
+ packageCoordinates: string[];
18
+ callNames: string[];
19
+ annotationNames: string[];
20
+ confidence: number;
21
+ }
22
+ export interface JvmAuthLibraryConfig {
23
+ id: string;
24
+ patternId: PatternId;
25
+ importPackages: string[];
26
+ packageCoordinates: string[];
27
+ callNames: string[];
28
+ contentRegexes: RegExp[];
29
+ strategy?: string;
30
+ confidence: number;
31
+ }
32
+ export interface JvmAuthAnnotationConfig {
33
+ id: string;
34
+ patternId: PatternId;
35
+ annotationNames: string[];
36
+ strategy?: string;
37
+ confidence: number;
38
+ }
39
+ export interface JvmRouteFrameworkConfig {
40
+ id: string;
41
+ patternId: PatternId;
42
+ importPackages: string[];
43
+ controllerAnnotations: string[];
44
+ controllerRouteAnnotations: string[];
45
+ /**
46
+ * Annotations that carry a member's sub-path when the route annotation
47
+ * itself does not — JAX-RS splits `@GET` from `@Path("/{id}")`.
48
+ */
49
+ pathAnnotations: string[];
50
+ annotationRoutes: JvmAnnotationRoute[];
51
+ routeRegexes: JvmRouteRegex[];
52
+ confidence: number;
53
+ }
54
+ export interface JvmServerlessHandlerConfig {
55
+ id: string;
56
+ patternId: PatternId;
57
+ importPackages: string[];
58
+ packageCoordinates: string[];
59
+ annotationNames: string[];
60
+ baseTypes: string[];
61
+ typeNames: string[];
62
+ callNames: string[];
63
+ confidence: number;
64
+ }
65
+ export interface JvmConfigLoader {
66
+ id: string;
67
+ importPackages: string[];
68
+ packageCoordinates: string[];
69
+ callNames: string[];
70
+ }
71
+ export interface JvmHttpClientConfig {
72
+ id: string;
73
+ patternId: PatternId;
74
+ clientName: string;
75
+ importPackages: string[];
76
+ callNames: string[];
77
+ callNameSuffixes: string[];
78
+ urlRegex: RegExp;
79
+ /**
80
+ * Require a literal URL in the call arguments before emitting. Needed where
81
+ * a client shares method names with a server routing DSL (Ktor), so a route
82
+ * registration cannot be reported as an outbound call.
83
+ */
84
+ requireUrlMatch: boolean;
85
+ confidence: number;
86
+ }
87
+ export interface JvmPatternConfig {
88
+ dbClients: JvmDbClientConfig[];
89
+ jdbcUrl?: {
90
+ patternId: PatternId;
91
+ regex: RegExp;
92
+ name: string;
93
+ confidence: number;
94
+ /** JDBC sub-protocol (`jdbc:<driver>:`) → component `databaseType`. */
95
+ drivers: Record<string, string>;
96
+ defaultDatabaseType: string;
97
+ };
98
+ auth: {
99
+ libraries: JvmAuthLibraryConfig[];
100
+ annotations: JvmAuthAnnotationConfig[];
101
+ };
102
+ routes: {
103
+ frameworks: JvmRouteFrameworkConfig[];
104
+ };
105
+ serverless: {
106
+ handlers: JvmServerlessHandlerConfig[];
107
+ };
108
+ envConfig: {
109
+ envVariable?: {
110
+ patternId: PatternId;
111
+ regex: RegExp;
112
+ confidence: number;
113
+ };
114
+ propertyKeys?: {
115
+ patternId: PatternId;
116
+ regexes: RegExp[];
117
+ confidence: number;
118
+ };
119
+ configLoaders?: {
120
+ patternId: PatternId;
121
+ confidence: number;
122
+ loaders: JvmConfigLoader[];
123
+ };
124
+ configFile?: {
125
+ patternId: PatternId;
126
+ fileNameRegex: RegExp;
127
+ name: string;
128
+ confidence: number;
129
+ };
130
+ };
131
+ externalApis: {
132
+ httpClients: JvmHttpClientConfig[];
133
+ };
134
+ }
135
+ export declare function clearJvmPatternConfigCache(): void;
136
+ export declare function loadJvmPatternConfig(): JvmPatternConfig;
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.clearJvmPatternConfigCache = clearJvmPatternConfigCache;
7
+ exports.loadJvmPatternConfig = loadJvmPatternConfig;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const yaml_1 = __importDefault(require("yaml"));
11
+ const detection_1 = require("../../core/types/detection");
12
+ const DEFAULT_CONFIDENCE = 0.8;
13
+ const DEFAULT_URL_REGEX = '"(https?:\\/\\/[^\\s"]+)"';
14
+ function validatePatternId(raw, context) {
15
+ const id = String(raw);
16
+ if (!detection_1.PATTERN_IDS.includes(id)) {
17
+ throw new Error(`Invalid patternId '${raw}' in ${context}`);
18
+ }
19
+ return id;
20
+ }
21
+ function compileRegex(pattern, context) {
22
+ try {
23
+ return new RegExp(pattern);
24
+ }
25
+ catch (err) {
26
+ const msg = err instanceof Error ? err.message : String(err);
27
+ throw new Error(`Invalid regex in ${context}: ${msg}`);
28
+ }
29
+ }
30
+ function getConfigPath() {
31
+ const parts = __dirname.split(path_1.default.sep);
32
+ const distIndex = parts.lastIndexOf("dist");
33
+ const cliRoot = distIndex !== -1
34
+ ? parts.slice(0, distIndex).join(path_1.default.sep)
35
+ : path_1.default.resolve(__dirname, "../../..");
36
+ return path_1.default.join(cliRoot, "patterns", "jvm.patterns.yaml");
37
+ }
38
+ function normalizeTokens(values) {
39
+ return (values ?? []).map((v) => v.trim()).filter(Boolean);
40
+ }
41
+ function normalizeRouteRegexes(raw, context) {
42
+ return (raw ?? []).map((entry, index) => ({
43
+ regex: compileRegex(entry.regex, `${context}.routeRegexes[${index}]`),
44
+ methodGroup: entry.methodGroup,
45
+ pathGroup: entry.pathGroup,
46
+ defaultMethod: entry.defaultMethod,
47
+ }));
48
+ }
49
+ function normalizeRawConfig(raw) {
50
+ const dbClients = raw.db_clients?.map((c) => ({
51
+ id: c.id,
52
+ patternId: validatePatternId(c.patternId, `jvm.db_clients entry '${c.id}'`),
53
+ databaseType: c.databaseType,
54
+ importPackages: normalizeTokens(c.importPackages),
55
+ packageCoordinates: normalizeTokens(c.packageCoordinates),
56
+ callNames: c.callNames ?? [],
57
+ annotationNames: c.annotationNames ?? [],
58
+ confidence: c.confidence ?? DEFAULT_CONFIDENCE,
59
+ })) ?? [];
60
+ const jdbcUrlRaw = raw.jdbc_url;
61
+ const jdbcUrl = jdbcUrlRaw && jdbcUrlRaw.patternId && jdbcUrlRaw.regex
62
+ ? {
63
+ patternId: validatePatternId(jdbcUrlRaw.patternId, "jvm.jdbc_url.patternId"),
64
+ regex: compileRegex(jdbcUrlRaw.regex, "jvm.jdbc_url.regex"),
65
+ name: jdbcUrlRaw.name ?? "jdbc",
66
+ confidence: jdbcUrlRaw.confidence ?? DEFAULT_CONFIDENCE,
67
+ drivers: jdbcUrlRaw.drivers ?? {},
68
+ defaultDatabaseType: jdbcUrlRaw.defaultDatabaseType ?? "sql",
69
+ }
70
+ : undefined;
71
+ const authLibraries = raw.auth?.libraries?.map((lib) => ({
72
+ id: lib.id,
73
+ patternId: validatePatternId(lib.patternId, `jvm.auth.libraries['${lib.id}']`),
74
+ importPackages: normalizeTokens(lib.importPackages),
75
+ packageCoordinates: normalizeTokens(lib.packageCoordinates),
76
+ callNames: lib.callNames ?? [],
77
+ contentRegexes: (lib.contentRegexes ?? []).map((p) => compileRegex(p, `jvm.auth.libraries['${lib.id}'].contentRegexes`)),
78
+ strategy: lib.strategy,
79
+ confidence: lib.confidence ?? DEFAULT_CONFIDENCE,
80
+ })) ?? [];
81
+ const authAnnotations = raw.auth?.annotations?.map((entry) => ({
82
+ id: entry.id,
83
+ patternId: validatePatternId(entry.patternId, `jvm.auth.annotations['${entry.id}']`),
84
+ annotationNames: normalizeTokens(entry.annotationNames),
85
+ strategy: entry.strategy,
86
+ confidence: entry.confidence ?? DEFAULT_CONFIDENCE,
87
+ })) ?? [];
88
+ const routeFrameworks = raw.routes?.frameworks?.map((fw) => ({
89
+ id: fw.id,
90
+ patternId: validatePatternId(fw.patternId, `jvm.routes.frameworks['${fw.id}']`),
91
+ importPackages: normalizeTokens(fw.importPackages),
92
+ controllerAnnotations: normalizeTokens(fw.controllerAnnotations),
93
+ controllerRouteAnnotations: normalizeTokens(fw.controllerRouteAnnotations),
94
+ pathAnnotations: normalizeTokens(fw.pathAnnotations),
95
+ annotationRoutes: (fw.annotationRoutes ?? []).map((entry) => ({
96
+ annotation: entry.annotation,
97
+ method: entry.method,
98
+ })),
99
+ routeRegexes: normalizeRouteRegexes(fw.routeRegexes, `jvm.routes.frameworks['${fw.id}']`),
100
+ confidence: fw.confidence ?? DEFAULT_CONFIDENCE,
101
+ })) ?? [];
102
+ const serverlessHandlers = raw.serverless?.handlers?.map((handler) => ({
103
+ id: handler.id,
104
+ patternId: validatePatternId(handler.patternId, `jvm.serverless.handlers['${handler.id}']`),
105
+ importPackages: normalizeTokens(handler.importPackages),
106
+ packageCoordinates: normalizeTokens(handler.packageCoordinates),
107
+ annotationNames: normalizeTokens(handler.annotationNames),
108
+ baseTypes: normalizeTokens(handler.baseTypes),
109
+ typeNames: normalizeTokens(handler.typeNames),
110
+ callNames: handler.callNames ?? [],
111
+ confidence: handler.confidence ?? DEFAULT_CONFIDENCE,
112
+ })) ?? [];
113
+ const envVarRaw = raw.env_config?.envVariable;
114
+ const envVariable = envVarRaw && envVarRaw.patternId && envVarRaw.regex
115
+ ? {
116
+ patternId: validatePatternId(envVarRaw.patternId, "jvm.env_config.envVariable.patternId"),
117
+ regex: compileRegex(envVarRaw.regex, "jvm.env_config.envVariable.regex"),
118
+ confidence: envVarRaw.confidence ?? DEFAULT_CONFIDENCE,
119
+ }
120
+ : undefined;
121
+ const propertyKeysRaw = raw.env_config?.propertyKeys;
122
+ const propertyKeys = propertyKeysRaw && propertyKeysRaw.patternId
123
+ ? {
124
+ patternId: validatePatternId(propertyKeysRaw.patternId, "jvm.env_config.propertyKeys.patternId"),
125
+ regexes: (propertyKeysRaw.regexes ?? []).map((p, index) => compileRegex(p, `jvm.env_config.propertyKeys.regexes[${index}]`)),
126
+ confidence: propertyKeysRaw.confidence ?? DEFAULT_CONFIDENCE,
127
+ }
128
+ : undefined;
129
+ const configLoadersRaw = raw.env_config?.configLoaders;
130
+ const configLoaders = configLoadersRaw && configLoadersRaw.patternId
131
+ ? {
132
+ patternId: validatePatternId(configLoadersRaw.patternId, "jvm.env_config.configLoaders.patternId"),
133
+ confidence: configLoadersRaw.confidence ?? DEFAULT_CONFIDENCE,
134
+ loaders: (configLoadersRaw.loaders ?? []).map((loader) => ({
135
+ id: loader.id,
136
+ importPackages: normalizeTokens(loader.importPackages),
137
+ packageCoordinates: normalizeTokens(loader.packageCoordinates),
138
+ callNames: loader.callNames ?? [],
139
+ })),
140
+ }
141
+ : undefined;
142
+ const configFileRaw = raw.env_config?.configFile;
143
+ const configFile = configFileRaw && configFileRaw.patternId && configFileRaw.fileNameRegex
144
+ ? {
145
+ patternId: validatePatternId(configFileRaw.patternId, "jvm.env_config.configFile.patternId"),
146
+ fileNameRegex: compileRegex(configFileRaw.fileNameRegex, "jvm.env_config.configFile.fileNameRegex"),
147
+ name: configFileRaw.name ?? "jvm_config",
148
+ confidence: configFileRaw.confidence ?? DEFAULT_CONFIDENCE,
149
+ }
150
+ : undefined;
151
+ const httpClients = raw.external_apis?.httpClients?.map((client) => ({
152
+ id: client.id,
153
+ patternId: validatePatternId(client.patternId, `jvm.external_apis.httpClients['${client.id}']`),
154
+ clientName: client.clientName,
155
+ importPackages: normalizeTokens(client.importPackages),
156
+ callNames: client.callNames ?? [],
157
+ callNameSuffixes: client.callNameSuffixes ?? [],
158
+ urlRegex: compileRegex(client.urlRegex ?? DEFAULT_URL_REGEX, `jvm.external_apis.httpClients['${client.id}'].urlRegex`),
159
+ requireUrlMatch: client.requireUrlMatch ?? false,
160
+ confidence: client.confidence ?? DEFAULT_CONFIDENCE,
161
+ })) ?? [];
162
+ return {
163
+ dbClients,
164
+ jdbcUrl,
165
+ auth: { libraries: authLibraries, annotations: authAnnotations },
166
+ routes: { frameworks: routeFrameworks },
167
+ serverless: { handlers: serverlessHandlers },
168
+ envConfig: { envVariable, propertyKeys, configLoaders, configFile },
169
+ externalApis: { httpClients },
170
+ };
171
+ }
172
+ let cachedConfig;
173
+ function clearJvmPatternConfigCache() {
174
+ cachedConfig = undefined;
175
+ }
176
+ function loadJvmPatternConfig() {
177
+ if (cachedConfig)
178
+ return cachedConfig;
179
+ const configPath = getConfigPath();
180
+ let rawYaml;
181
+ try {
182
+ rawYaml = fs_1.default.readFileSync(configPath, "utf8");
183
+ }
184
+ catch (err) {
185
+ const msg = err instanceof Error ? err.message : String(err);
186
+ throw new Error(`JVM pattern config is required but could not be read from '${configPath}': ${msg}`);
187
+ }
188
+ const parsed = yaml_1.default.parse(rawYaml);
189
+ if (!parsed || typeof parsed !== "object") {
190
+ throw new Error(`JVM pattern config at '${configPath}' did not parse to an object.`);
191
+ }
192
+ const normalized = normalizeRawConfig(parsed);
193
+ cachedConfig = normalized;
194
+ return normalized;
195
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Dependency extraction for JVM build manifests.
3
+ *
4
+ * Covers Maven (`pom.xml`), Gradle in both the Groovy and Kotlin DSLs
5
+ * (`build.gradle`, `build.gradle.kts`), and Gradle version catalogs
6
+ * (`gradle/libs.versions.toml`).
7
+ *
8
+ * All three normalize to a Maven coordinate — `groupId:artifactId`, version
9
+ * dropped. Unlike Go, that token is *not* what appears in an `import`
10
+ * statement (`org.springframework.boot:spring-boot-starter-data-jpa` versus
11
+ * `org.springframework.data.jpa.repository`), which is why JVM rules carry
12
+ * `packageCoordinates` separately from `importPackages`.
13
+ */
14
+ /**
15
+ * Maven `pom.xml`. The `<parent>` coordinate is included: on Spring Boot
16
+ * projects it is `spring-boot-starter-parent`, which is often the clearest
17
+ * statement of what the module is.
18
+ */
19
+ export declare function extractCoordinatesFromPom(content: string): string[];
20
+ /**
21
+ * Gradle build scripts, Groovy and Kotlin DSL alike:
22
+ *
23
+ * implementation 'org.postgresql:postgresql:42.7.1'
24
+ * implementation("org.postgresql:postgresql:42.7.1")
25
+ * implementation group: 'org.postgresql', name: 'postgresql'
26
+ *
27
+ * Version-catalog references (`implementation(libs.spring.boot.web)`) carry no
28
+ * coordinate here; they resolve from `gradle/libs.versions.toml` instead.
29
+ */
30
+ export declare function extractCoordinatesFromGradle(content: string): string[];
31
+ /**
32
+ * Gradle version catalog (`gradle/libs.versions.toml`), `[libraries]` section:
33
+ *
34
+ * postgres = { module = "org.postgresql:postgresql", version.ref = "pg" }
35
+ * jedis = { group = "redis.clients", name = "jedis" }
36
+ */
37
+ export declare function extractCoordinatesFromVersionCatalog(content: string): string[];
38
+ export interface SpringDatasourceRef {
39
+ /** Property key, e.g. `spring.datasource.url`. */
40
+ key: string;
41
+ /**
42
+ * Engine token to resolve against the shared driver table: the JDBC/R2DBC
43
+ * sub-protocol (`postgresql`) or a URI scheme (`mongodb`, `redis`).
44
+ */
45
+ driver: string;
46
+ }
47
+ /**
48
+ * Read the engine out of a Spring datasource URI.
49
+ *
50
+ * Only the driver token is returned. These values routinely embed credentials
51
+ * (`jdbc:postgresql://user:password@host/db`), so the URI itself never leaves
52
+ * this function.
53
+ */
54
+ export declare function driverTokenFromUri(value: string): string | undefined;
55
+ /** `application.properties` — flat `key=value` lines. */
56
+ export declare function extractDatasourceRefsFromProperties(content: string): SpringDatasourceRef[];
57
+ /**
58
+ * `application.yml` — nested, and frequently multi-document, since Spring
59
+ * separates per-profile configuration with `---`.
60
+ */
61
+ export declare function extractDatasourceRefsFromYaml(content: string): SpringDatasourceRef[];