@dataparade/cli 0.0.8 → 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 +10 -10
  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,419 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseJvmSourceFile = parseJvmSourceFile;
37
+ const nodePath = __importStar(require("path"));
38
+ const c_family_calls_1 = require("../shared/c-family-calls");
39
+ const strip_comments_1 = require("../shared/strip-comments");
40
+ const PACKAGE_REGEX = /^package\s+([A-Za-z_][\w.]*)/;
41
+ // The `*` lives in the character class rather than as an optional suffix: a
42
+ // greedy `[\w.]*` would otherwise swallow the dot before `.*` could match it.
43
+ const IMPORT_REGEX = /^import\s+(static\s+)?([A-Za-z_][\w.*]*)\s*(?:as\s+([A-Za-z_]\w*))?\s*;?/;
44
+ const JAVA_TYPE_MODIFIERS = "public|private|protected|abstract|final|static|sealed|non-sealed|strictfp";
45
+ const JAVA_TYPE_REGEX = new RegExp(`^(?:(?:${JAVA_TYPE_MODIFIERS})\\s+)*(class|interface|enum|record|@interface)\\s+([A-Za-z_]\\w*)`);
46
+ const KOTLIN_TYPE_MODIFIERS = "public|private|protected|internal|open|abstract|final|sealed|data|inner|value|inline|annotation|companion|expect|actual";
47
+ const KOTLIN_TYPE_REGEX = new RegExp(`^(?:(?:${KOTLIN_TYPE_MODIFIERS})\\s+)*(class|interface|object|enum\\s+class|annotation\\s+class)\\s+([A-Za-z_]\\w*)`);
48
+ const KOTLIN_FUNCTION_REGEX = /^(?:(?:public|private|protected|internal|open|override|abstract|final|inline|suspend|operator|infix|tailrec|external|expect|actual)\s+)*fun\s+(?:<[^>]*>\s*)?(?:[A-Za-z_][\w.<>,\s?]*\.)?([A-Za-z_]\w*)\s*\(/;
49
+ const JAVA_METHOD_REGEX = /^(?:(?:public|private|protected|static|final|abstract|synchronized|native|strictfp|default)\s+)*(?:<[^>]*>\s*)?[A-Za-z_][\w.<>,\[\]?\s]*\s+([A-Za-z_]\w*)\s*\(/;
50
+ /**
51
+ * First tokens that make a line look like a Java method declaration when it is
52
+ * actually a statement (`return foo(...)`, `throw new X(...)`).
53
+ */
54
+ const JAVA_STATEMENT_STARTERS = new Set([
55
+ "return",
56
+ "throw",
57
+ "new",
58
+ "if",
59
+ "for",
60
+ "while",
61
+ "switch",
62
+ "catch",
63
+ "do",
64
+ "else",
65
+ "case",
66
+ "assert",
67
+ "synchronized",
68
+ "import",
69
+ "package",
70
+ "yield",
71
+ ]);
72
+ function normalizePath(p) {
73
+ if (!p)
74
+ return "";
75
+ const normalized = p.split("\\").join("/");
76
+ return normalizedPathIsRelativeToCwd(normalized)
77
+ ? normalized
78
+ : normalized.replace(nodePath.resolve(), "").replace(/^\/+/, "");
79
+ }
80
+ function normalizedPathIsRelativeToCwd(p) {
81
+ return !p.startsWith("/") && !p.match(/^[A-Za-z]:\//);
82
+ }
83
+ /**
84
+ * Consume one `@Annotation(...)` from the start of `text`, following the
85
+ * argument list across lines when it does not close on the current one —
86
+ * Spring routinely wraps `@RequestMapping(value = ..., method = ...)`.
87
+ *
88
+ * Returns the annotation, the remainder of the line it ended on, and that
89
+ * line's index.
90
+ */
91
+ function consumeAnnotation(lines, lineIndex, text) {
92
+ const nameMatch = text.match(/^@\s*(?:([A-Za-z_]\w*)\s*:\s*)?([A-Za-z_][\w.]*)/);
93
+ if (!nameMatch)
94
+ return null;
95
+ // Kotlin use-site targets (`@field:Autowired`) are dropped; the annotation
96
+ // identity is what rules match on.
97
+ const qualified = nameMatch[2];
98
+ const name = qualified.includes(".")
99
+ ? (qualified.split(".").pop() ?? qualified)
100
+ : qualified;
101
+ let rest = text.slice(nameMatch[0].length);
102
+ let endIndex = lineIndex;
103
+ let argumentsSnippet = "";
104
+ if (rest.trimStart().startsWith("(")) {
105
+ rest = rest.trimStart();
106
+ let depth = 0;
107
+ let inString = false;
108
+ let quote = "";
109
+ let collected = "";
110
+ let consumed = false;
111
+ while (endIndex < lines.length && !consumed) {
112
+ const source = endIndex === lineIndex ? rest : (lines[endIndex] ?? "");
113
+ let cursor = 0;
114
+ for (; cursor < source.length; cursor += 1) {
115
+ const char = source[cursor];
116
+ if (inString) {
117
+ if (char === "\\") {
118
+ cursor += 1;
119
+ continue;
120
+ }
121
+ if (char === quote)
122
+ inString = false;
123
+ continue;
124
+ }
125
+ if (char === '"' || char === "'") {
126
+ inString = true;
127
+ quote = char;
128
+ continue;
129
+ }
130
+ if (char === "(") {
131
+ depth += 1;
132
+ }
133
+ else if (char === ")") {
134
+ depth -= 1;
135
+ if (depth === 0) {
136
+ consumed = true;
137
+ break;
138
+ }
139
+ }
140
+ }
141
+ if (consumed) {
142
+ collected += source.slice(0, cursor);
143
+ rest = source.slice(cursor + 1).trim();
144
+ }
145
+ else {
146
+ collected += `${source} `;
147
+ endIndex += 1;
148
+ rest = "";
149
+ }
150
+ }
151
+ // Unbalanced parentheses: treat the annotation as argument-less rather
152
+ // than swallowing the rest of the file.
153
+ if (!consumed)
154
+ return null;
155
+ argumentsSnippet = collected.replace(/^\s*\(/, "").trim();
156
+ }
157
+ else {
158
+ rest = rest.trim();
159
+ }
160
+ return {
161
+ annotation: {
162
+ name,
163
+ argumentsSnippet,
164
+ raw: argumentsSnippet ? `${name}(${argumentsSnippet})` : name,
165
+ },
166
+ rest,
167
+ endIndex,
168
+ };
169
+ }
170
+ /** Supertypes from a Java `extends A implements B, C` header. */
171
+ function javaBaseTypes(header) {
172
+ const bases = [];
173
+ const extendsMatch = header.match(/\bextends\s+([^{]+?)(?=\bimplements\b|\{|$)/);
174
+ if (extendsMatch)
175
+ bases.push(...splitTypeList(extendsMatch[1]));
176
+ const implementsMatch = header.match(/\bimplements\s+([^{]+?)(?=\{|$)/);
177
+ if (implementsMatch)
178
+ bases.push(...splitTypeList(implementsMatch[1]));
179
+ return bases;
180
+ }
181
+ /** Supertypes from a Kotlin `class X(...) : A(), B` header. */
182
+ function kotlinBaseTypes(header) {
183
+ // Skip the primary constructor's parameter list so its types are not read
184
+ // as supertypes.
185
+ let depth = 0;
186
+ let colonIndex = -1;
187
+ for (let i = 0; i < header.length; i += 1) {
188
+ const char = header[i];
189
+ if (char === "(" || char === "<")
190
+ depth += 1;
191
+ else if (char === ")" || char === ">")
192
+ depth -= 1;
193
+ else if (char === ":" && depth === 0) {
194
+ colonIndex = i;
195
+ break;
196
+ }
197
+ else if (char === "{" && depth === 0)
198
+ break;
199
+ }
200
+ if (colonIndex === -1)
201
+ return [];
202
+ const tail = header.slice(colonIndex + 1).replace(/\{.*$/, "");
203
+ return splitTypeList(tail);
204
+ }
205
+ /** Split a comma-separated type list, ignoring commas inside generics/args. */
206
+ function splitTypeList(raw) {
207
+ const parts = [];
208
+ let depth = 0;
209
+ let current = "";
210
+ for (const char of raw) {
211
+ if (char === "<" || char === "(")
212
+ depth += 1;
213
+ else if (char === ">" || char === ")")
214
+ depth -= 1;
215
+ if (char === "," && depth === 0) {
216
+ parts.push(current);
217
+ current = "";
218
+ continue;
219
+ }
220
+ current += char;
221
+ }
222
+ parts.push(current);
223
+ return parts
224
+ // Keep the bare type name: `Foo<Bar>()` and `Foo<Bar>` both yield `Foo`.
225
+ .map((part) => part.trim().replace(/[<(].*$/, "").trim())
226
+ .filter((part) => Boolean(part) && /^[A-Za-z_][\w.]*$/.test(part));
227
+ }
228
+ function emptyModel(file, normalizedPath, isKotlin, warnings) {
229
+ return {
230
+ file,
231
+ normalizedPath,
232
+ strippedContent: "",
233
+ isKotlin,
234
+ imports: [],
235
+ types: [],
236
+ methods: [],
237
+ calls: [],
238
+ warnings,
239
+ };
240
+ }
241
+ function parseJvmSourceFile(file) {
242
+ const warnings = [];
243
+ const normalizedPath = normalizePath(file.path);
244
+ const isKotlin = file.language === "kotlin";
245
+ if (file.language !== "java" && file.language !== "kotlin") {
246
+ warnings.push(`Unsupported language '${file.language}' for JVM parser in file '${file.path}'.`);
247
+ return emptyModel(file, normalizedPath, isKotlin, warnings);
248
+ }
249
+ const content = file.content ?? "";
250
+ if (content.includes("\u0000")) {
251
+ warnings.push(`File '${file.path}' appears unreadable (contains null bytes); parser will continue with best-effort analysis.`);
252
+ }
253
+ const strippedContent = (0, strip_comments_1.stripCommentsPreservingLayout)(content, {
254
+ tripleQuotedStrings: true,
255
+ nestedBlockComments: isKotlin,
256
+ });
257
+ const lines = strippedContent.split(/\r?\n/);
258
+ const imports = [];
259
+ const types = [];
260
+ const methods = [];
261
+ let packageName;
262
+ let currentType;
263
+ let pendingAnnotations = [];
264
+ const toLocation = (startLine, endLine) => ({
265
+ filePath: file.path,
266
+ startLine,
267
+ endLine,
268
+ });
269
+ const typeRegex = isKotlin ? KOTLIN_TYPE_REGEX : JAVA_TYPE_REGEX;
270
+ for (let i = 0; i < lines.length; i += 1) {
271
+ let text = (lines[i] ?? "").trim();
272
+ // The line an annotation's arguments finished on; declarations on that
273
+ // same line still belong to `i`'s pending annotations.
274
+ let declarationLineIndex = i;
275
+ if (!text)
276
+ continue;
277
+ // Annotations may sit on their own line, wrap across several, or share a
278
+ // line with the member they decorate.
279
+ while (text.startsWith("@")) {
280
+ const consumed = consumeAnnotation(lines, declarationLineIndex, text);
281
+ if (!consumed)
282
+ break;
283
+ pendingAnnotations.push(consumed.annotation);
284
+ text = consumed.rest;
285
+ declarationLineIndex = consumed.endIndex;
286
+ i = consumed.endIndex;
287
+ }
288
+ if (!text)
289
+ continue;
290
+ const lineNumber = declarationLineIndex + 1;
291
+ if (!packageName) {
292
+ const packageMatch = text.match(PACKAGE_REGEX);
293
+ if (packageMatch) {
294
+ packageName = packageMatch[1];
295
+ pendingAnnotations = [];
296
+ continue;
297
+ }
298
+ }
299
+ const importMatch = text.match(IMPORT_REGEX);
300
+ if (importMatch) {
301
+ const raw = importMatch[2];
302
+ const isWildcard = raw.endsWith("*");
303
+ imports.push({
304
+ qualifiedName: raw.replace(/\.?\*$/, ""),
305
+ alias: importMatch[3],
306
+ isStatic: Boolean(importMatch[1]),
307
+ isWildcard,
308
+ location: toLocation(lineNumber, lineNumber),
309
+ });
310
+ pendingAnnotations = [];
311
+ continue;
312
+ }
313
+ const typeMatch = text.match(typeRegex);
314
+ if (typeMatch) {
315
+ const name = typeMatch[2];
316
+ currentType = name;
317
+ types.push({
318
+ name,
319
+ kind: normalizeTypeKind(typeMatch[1]),
320
+ baseTypes: isKotlin ? kotlinBaseTypes(text) : javaBaseTypes(text),
321
+ annotations: pendingAnnotations,
322
+ location: toLocation(lineNumber, lineNumber),
323
+ });
324
+ pendingAnnotations = [];
325
+ continue;
326
+ }
327
+ const methodMatch = isKotlin
328
+ ? text.match(KOTLIN_FUNCTION_REGEX)
329
+ : matchJavaMethod(text);
330
+ if (methodMatch) {
331
+ methods.push({
332
+ name: methodMatch[1],
333
+ annotations: pendingAnnotations,
334
+ declaringType: currentType,
335
+ location: toLocation(lineNumber, findMemberEndLine(lines, declarationLineIndex)),
336
+ });
337
+ pendingAnnotations = [];
338
+ continue;
339
+ }
340
+ pendingAnnotations = [];
341
+ }
342
+ const calls = (0, c_family_calls_1.extractCFamilyCalls)(lines, { filePath: file.path });
343
+ return {
344
+ file,
345
+ normalizedPath,
346
+ strippedContent,
347
+ isKotlin,
348
+ packageName,
349
+ imports,
350
+ types,
351
+ methods,
352
+ calls,
353
+ warnings,
354
+ };
355
+ }
356
+ /**
357
+ * Java method declarations have no leading keyword of their own — a
358
+ * package-private `void handle()` is just a type followed by a name — so
359
+ * statements that share that shape are rejected explicitly.
360
+ */
361
+ function matchJavaMethod(text) {
362
+ const firstToken = text.match(/^([A-Za-z_]\w*)/)?.[1];
363
+ if (firstToken && JAVA_STATEMENT_STARTERS.has(firstToken))
364
+ return null;
365
+ const match = text.match(JAVA_METHOD_REGEX);
366
+ if (!match)
367
+ return null;
368
+ // An assignment is a field initializer, not a declaration:
369
+ // `private final Foo foo = new Foo(...)`.
370
+ const beforeParen = text.slice(0, text.indexOf("("));
371
+ if (beforeParen.includes("="))
372
+ return null;
373
+ return match;
374
+ }
375
+ function normalizeTypeKind(raw) {
376
+ const normalized = raw.replace(/\s+/g, " ").trim();
377
+ if (normalized === "interface")
378
+ return "interface";
379
+ if (normalized === "@interface" || normalized === "annotation class") {
380
+ return "annotation";
381
+ }
382
+ if (normalized === "enum" || normalized === "enum class")
383
+ return "enum";
384
+ if (normalized === "record")
385
+ return "record";
386
+ if (normalized === "object")
387
+ return "object";
388
+ return "class";
389
+ }
390
+ /**
391
+ * Walk braces forward from a declaration to find its closing line. Abstract
392
+ * and interface methods, and Kotlin expression bodies, end on their own line.
393
+ */
394
+ function findMemberEndLine(lines, startIndex) {
395
+ const startLine = lines[startIndex] ?? "";
396
+ const trimmed = startLine.trimEnd();
397
+ if (trimmed.endsWith(";"))
398
+ return startIndex + 1;
399
+ if (/=\s*[^=]*$/.test(trimmed) && !trimmed.endsWith("{")) {
400
+ return startIndex + 1;
401
+ }
402
+ let depth = 0;
403
+ let seenOpening = false;
404
+ for (let i = startIndex; i < lines.length; i += 1) {
405
+ const line = lines[i] ?? "";
406
+ for (const char of line) {
407
+ if (char === "{") {
408
+ depth += 1;
409
+ seenOpening = true;
410
+ }
411
+ else if (char === "}") {
412
+ depth -= 1;
413
+ }
414
+ }
415
+ if (seenOpening && depth <= 0)
416
+ return i + 1;
417
+ }
418
+ return startIndex + 1;
419
+ }
@@ -0,0 +1,3 @@
1
+ import type { RawFinding } from "../../core/types/detection";
2
+ import type { JvmSourceFileModel } from "./parser";
3
+ export declare function detectJvmPatternsFromModel(model: JvmSourceFileModel): RawFinding[];
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectJvmPatternsFromModel = detectJvmPatternsFromModel;
4
+ const engine_1 = require("../../patterns/engine");
5
+ /**
6
+ * Represent a JVM import as a language-agnostic import.
7
+ *
8
+ * The shared third-party catalog matches lowercase fragments (`stripe`,
9
+ * `sendgrid`) while JVM fully-qualified names mix cases
10
+ * (`com.stripe.StripeClient`), so the lowercased forms are carried alongside
11
+ * the segments.
12
+ */
13
+ function importsForEngine(model) {
14
+ return model.imports.map((entry) => {
15
+ const qualifiedName = entry.qualifiedName;
16
+ const segments = qualifiedName.split(".").filter(Boolean);
17
+ const names = Array.from(new Set([
18
+ qualifiedName,
19
+ qualifiedName.toLowerCase(),
20
+ ...segments,
21
+ ...segments.map((segment) => segment.toLowerCase()),
22
+ ...(entry.alias ? [entry.alias] : []),
23
+ ])).filter(Boolean);
24
+ return { module: qualifiedName, names };
25
+ });
26
+ }
27
+ /**
28
+ * Annotations are carried as decorator strings, both with and without their
29
+ * argument list: `GetMapping("/{id}")` and `GetMapping`.
30
+ */
31
+ function annotationsAsDecorators(annotations) {
32
+ const decorators = new Set();
33
+ for (const annotation of annotations) {
34
+ decorators.add(annotation.raw);
35
+ decorators.add(annotation.name);
36
+ }
37
+ return Array.from(decorators);
38
+ }
39
+ function detectJvmPatternsFromModel(model) {
40
+ return (0, engine_1.matchPatterns)({
41
+ language: model.file.language,
42
+ file: model.file,
43
+ normalizedPath: model.normalizedPath,
44
+ strippedContent: model.strippedContent,
45
+ imports: importsForEngine(model),
46
+ functions: model.methods.map((method) => ({
47
+ name: method.name,
48
+ decorators: annotationsAsDecorators(method.annotations),
49
+ location: method.location,
50
+ })),
51
+ types: model.types.map((type) => ({
52
+ name: type.name,
53
+ kind: type.kind,
54
+ baseTypes: type.baseTypes,
55
+ decorators: annotationsAsDecorators(type.annotations),
56
+ location: type.location,
57
+ })),
58
+ moduleLevelCalls: model.calls.map((call) => ({
59
+ callee: call.callee,
60
+ argumentsSnippet: call.argumentsSnippet,
61
+ location: call.location,
62
+ })),
63
+ });
64
+ }
@@ -10,7 +10,7 @@ function detectPythonPatterns(file) {
10
10
  return [];
11
11
  }
12
12
  const findings = [];
13
- findings.push(...(0, patterns_1.detectPythonRoutePatterns)(moduleModel), ...(0, patterns_1.detectPythonDatabaseConnections)(moduleModel), ...(0, patterns_1.detectPythonExternalApiCalls)(moduleModel), ...(0, patterns_1.detectPythonAuthPatterns)(moduleModel), ...(0, patterns_1.detectPythonConfigAndEnvUsage)(moduleModel));
13
+ findings.push(...(0, patterns_1.detectPythonRoutePatterns)(moduleModel), ...(0, patterns_1.detectPythonDatabaseConnections)(moduleModel), ...(0, patterns_1.detectPythonExternalApiCalls)(moduleModel), ...(0, patterns_1.detectPythonAuthPatterns)(moduleModel), ...(0, patterns_1.detectPythonConfigAndEnvUsage)(moduleModel), ...(0, patterns_1.detectPythonServerlessHandlers)(moduleModel));
14
14
  // Merge pattern-matched component properties (from YAML) into each finding.
15
15
  for (const finding of findings) {
16
16
  const detected = (0, property_inference_1.getPropertiesFromFinding)(finding, file.content);
@@ -18,6 +18,7 @@ export interface PythonModuleLevelCallEntry {
18
18
  export interface PythonModuleModel {
19
19
  file: FileInfo;
20
20
  normalizedPath: string;
21
+ strippedContent: string;
21
22
  imports: PythonImportEntry[];
22
23
  functions: PythonFunctionEntry[];
23
24
  moduleLevelCalls: PythonModuleLevelCallEntry[];
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.parsePythonModule = parsePythonModule;
37
37
  const nodePath = __importStar(require("path"));
38
+ const strip_comments_1 = require("../shared/strip-comments");
38
39
  function parsePythonModule(file) {
39
40
  const warnings = [];
40
41
  const normalizedPath = normalizePath(file.path);
@@ -43,6 +44,7 @@ function parsePythonModule(file) {
43
44
  return {
44
45
  file,
45
46
  normalizedPath,
47
+ strippedContent: "",
46
48
  imports: [],
47
49
  functions: [],
48
50
  moduleLevelCalls: [],
@@ -50,6 +52,10 @@ function parsePythonModule(file) {
50
52
  };
51
53
  }
52
54
  const content = file.content ?? "";
55
+ const strippedContent = (0, strip_comments_1.stripCommentsPreservingLayout)(content, {
56
+ hashComments: true,
57
+ tripleQuoteStrings: true,
58
+ });
53
59
  if (content.includes("\u0000")) {
54
60
  warnings.push(`File '${file.path}' appears unreadable (contains null bytes); parser will continue with best-effort analysis.`);
55
61
  }
@@ -168,6 +174,7 @@ function parsePythonModule(file) {
168
174
  return {
169
175
  file,
170
176
  normalizedPath,
177
+ strippedContent,
171
178
  imports,
172
179
  functions,
173
180
  moduleLevelCalls,
@@ -5,3 +5,4 @@ export declare function detectPythonDatabaseConnections(moduleModel: PythonModul
5
5
  export declare function detectPythonExternalApiCalls(moduleModel: PythonModuleModel): RawFinding[];
6
6
  export declare function detectPythonAuthPatterns(moduleModel: PythonModuleModel): RawFinding[];
7
7
  export declare function detectPythonConfigAndEnvUsage(moduleModel: PythonModuleModel): RawFinding[];
8
+ export declare function detectPythonServerlessHandlers(moduleModel: PythonModuleModel): RawFinding[];
@@ -5,102 +5,47 @@ exports.detectPythonDatabaseConnections = detectPythonDatabaseConnections;
5
5
  exports.detectPythonExternalApiCalls = detectPythonExternalApiCalls;
6
6
  exports.detectPythonAuthPatterns = detectPythonAuthPatterns;
7
7
  exports.detectPythonConfigAndEnvUsage = detectPythonConfigAndEnvUsage;
8
+ exports.detectPythonServerlessHandlers = detectPythonServerlessHandlers;
8
9
  const engine_1 = require("../../patterns/engine");
9
- function createLocation(filePath, startLine, endLine, code) {
10
- return {
11
- filePath,
12
- startLine,
13
- endLine: endLine ?? startLine,
14
- code,
15
- };
16
- }
17
- function createFinding(params) {
18
- return {
19
- pattern: params.pattern,
20
- name: params.name,
21
- confidence: params.confidence,
22
- location: params.location,
23
- properties: params.properties ?? {},
24
- };
25
- }
26
- function hasImportModule(imports, predicate) {
27
- return imports.some((imp) => predicate(imp.module));
28
- }
29
- function hasImportedName(imports, name) {
30
- return imports.some((imp) => imp.names.includes(name));
31
- }
32
- function functionHasDecorator(fn, predicate) {
33
- return fn.decorators.some((dec) => predicate(dec));
34
- }
35
- function detectPythonRoutePatterns(moduleModel) {
36
- const { file, imports, functions, normalizedPath } = moduleModel;
10
+ function buildPythonPatternContext(moduleModel) {
11
+ const { file, imports, functions, normalizedPath, strippedContent } = moduleModel;
37
12
  const importsForEngine = imports.map((imp) => ({
38
13
  module: imp.module,
39
14
  names: imp.names,
40
15
  }));
41
- return (0, engine_1.matchPatterns)({
16
+ return {
42
17
  language: "python",
43
18
  file,
44
19
  imports: importsForEngine,
20
+ strippedContent,
21
+ normalizedPath,
45
22
  functions: functions.map((fn) => ({
46
23
  name: fn.name,
47
24
  decorators: fn.decorators,
48
25
  location: fn.location,
49
26
  })),
50
- normalizedPath,
51
- }).filter((f) => f.pattern === "express_route");
52
- }
53
- function detectPythonDatabaseConnections(moduleModel) {
54
- const { file, imports } = moduleModel;
55
- const importsForEngine = imports.map((imp) => ({
56
- module: imp.module,
57
- names: imp.names,
58
- }));
59
- return (0, engine_1.matchPatterns)({
60
- language: "python",
61
- file,
62
- imports: importsForEngine,
63
- }).filter((f) => f.pattern === "database_connection");
64
- }
65
- function detectPythonExternalApiCalls(moduleModel) {
66
- const { file, imports, moduleLevelCalls } = moduleModel;
67
- const importsForEngine = imports.map((imp) => ({
68
- module: imp.module,
69
- names: imp.names,
70
- }));
71
- return (0, engine_1.matchPatterns)({
72
- language: "python",
73
- file,
74
- imports: importsForEngine,
75
- moduleLevelCalls: moduleLevelCalls.map((call) => ({
27
+ moduleLevelCalls: moduleModel.moduleLevelCalls.map((call) => ({
76
28
  callee: call.callee,
77
29
  argumentsSnippet: call.argumentsSnippet,
78
30
  location: call.location,
79
31
  })),
80
- }).filter((f) => f.pattern === "external_api_call");
32
+ };
33
+ }
34
+ function detectPythonRoutePatterns(moduleModel) {
35
+ return (0, engine_1.matchPatterns)(buildPythonPatternContext(moduleModel)).filter((f) => f.pattern === "express_route");
36
+ }
37
+ function detectPythonDatabaseConnections(moduleModel) {
38
+ return (0, engine_1.matchPatterns)(buildPythonPatternContext(moduleModel)).filter((f) => f.pattern === "database_connection");
39
+ }
40
+ function detectPythonExternalApiCalls(moduleModel) {
41
+ return (0, engine_1.matchPatterns)(buildPythonPatternContext(moduleModel)).filter((f) => f.pattern === "external_api_call");
81
42
  }
82
43
  function detectPythonAuthPatterns(moduleModel) {
83
- const { file, imports } = moduleModel;
84
- const importsForEngine = imports.map((imp) => ({
85
- module: imp.module,
86
- names: imp.names,
87
- }));
88
- return (0, engine_1.matchPatterns)({
89
- language: "python",
90
- file,
91
- imports: importsForEngine,
92
- }).filter((f) => f.pattern === "auth_middleware");
44
+ return (0, engine_1.matchPatterns)(buildPythonPatternContext(moduleModel)).filter((f) => f.pattern === "auth_middleware");
93
45
  }
94
46
  function detectPythonConfigAndEnvUsage(moduleModel) {
95
- const { file, imports } = moduleModel;
96
- const importsForEngine = imports.map((imp) => ({
97
- module: imp.module,
98
- names: imp.names,
99
- }));
100
- return (0, engine_1.matchPatterns)({
101
- language: "python",
102
- file,
103
- imports: importsForEngine,
104
- }).filter((f) => f.pattern === "env_variable" ||
105
- f.pattern === "config_file");
47
+ return (0, engine_1.matchPatterns)(buildPythonPatternContext(moduleModel)).filter((f) => f.pattern === "env_variable" || f.pattern === "config_file");
48
+ }
49
+ function detectPythonServerlessHandlers(moduleModel) {
50
+ return (0, engine_1.matchPatterns)(buildPythonPatternContext(moduleModel)).filter((f) => f.pattern === "lambda_handler");
106
51
  }