@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,277 @@
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.parseCSharpCompilationUnit = parseCSharpCompilationUnit;
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 USING_REGEX = /^(global\s+)?using\s+(static\s+)?([A-Za-z_][\w.]*)(?:\s*=\s*([A-Za-z_][\w.<>,\s]*))?\s*;/;
41
+ const NAMESPACE_REGEX = /^namespace\s+([A-Za-z_][\w.]*)/;
42
+ const TYPE_REGEX = /^(?:(?:public|internal|private|protected|abstract|sealed|static|partial|readonly|unsafe)\s+)*(class|interface|record\s+class|record\s+struct|record|struct|enum)\s+([A-Za-z_]\w*)(?:\s*<[^>]*>)?\s*(?::\s*([^{]+))?/;
43
+ const METHOD_REGEX = /^(?:(?:public|private|protected|internal|static|async|virtual|override|sealed|partial|extern|unsafe|new)\s+)+(?:[A-Za-z_][\w<>,.\[\]?\s]*\s+)?([A-Za-z_]\w*)\s*(?:<[^>]*>)?\s*\(/;
44
+ const ATTRIBUTE_ENTRY_REGEX = /([A-Za-z_][\w.]*)\s*(\([^)]*\))?/g;
45
+ /**
46
+ * Split a leading `[...]` attribute group off a line, returning its contents
47
+ * and whatever follows. Brackets are counted and string literals skipped, so
48
+ * route templates such as `[Route("api/[controller]")]` stay intact.
49
+ */
50
+ function splitLeadingAttributeGroup(text) {
51
+ if (!text.startsWith("["))
52
+ return null;
53
+ let depth = 0;
54
+ let inString = false;
55
+ let quote = "";
56
+ for (let i = 0; i < text.length; i += 1) {
57
+ const char = text[i];
58
+ if (inString) {
59
+ if (char === "\\") {
60
+ i += 1;
61
+ continue;
62
+ }
63
+ if (char === quote)
64
+ inString = false;
65
+ continue;
66
+ }
67
+ if (char === '"' || char === "'") {
68
+ inString = true;
69
+ quote = char;
70
+ continue;
71
+ }
72
+ if (char === "[") {
73
+ depth += 1;
74
+ }
75
+ else if (char === "]") {
76
+ depth -= 1;
77
+ if (depth === 0) {
78
+ return { inner: text.slice(1, i), rest: text.slice(i + 1).trim() };
79
+ }
80
+ }
81
+ }
82
+ return null;
83
+ }
84
+ /** Attribute-looking lines that are not member attributes. */
85
+ const NON_ATTRIBUTE_PREFIXES = ["assembly:", "module:", "return:"];
86
+ function normalizePath(p) {
87
+ if (!p)
88
+ return "";
89
+ const normalized = p.split("\\").join("/");
90
+ return normalizedPathIsRelativeToCwd(normalized)
91
+ ? normalized
92
+ : normalized.replace(nodePath.resolve(), "").replace(/^\/+/, "");
93
+ }
94
+ function normalizedPathIsRelativeToCwd(p) {
95
+ return !p.startsWith("/") && !p.match(/^[A-Za-z]:\//);
96
+ }
97
+ function parseAttributeList(inner) {
98
+ const trimmed = inner.trim();
99
+ if (!trimmed)
100
+ return [];
101
+ if (NON_ATTRIBUTE_PREFIXES.some((prefix) => trimmed.toLowerCase().startsWith(prefix))) {
102
+ return [];
103
+ }
104
+ const attributes = [];
105
+ ATTRIBUTE_ENTRY_REGEX.lastIndex = 0;
106
+ let match;
107
+ while ((match = ATTRIBUTE_ENTRY_REGEX.exec(trimmed)) !== null) {
108
+ const name = match[1];
109
+ if (!name)
110
+ continue;
111
+ const argsWithParens = match[2] ?? "";
112
+ const argumentsSnippet = argsWithParens.slice(1, -1);
113
+ attributes.push({
114
+ name: name.replace(/Attribute$/, ""),
115
+ argumentsSnippet,
116
+ raw: `${name}${argsWithParens}`,
117
+ });
118
+ }
119
+ return attributes;
120
+ }
121
+ function emptyModel(file, normalizedPath, warnings) {
122
+ return {
123
+ file,
124
+ normalizedPath,
125
+ strippedContent: "",
126
+ usings: [],
127
+ types: [],
128
+ methods: [],
129
+ calls: [],
130
+ warnings,
131
+ };
132
+ }
133
+ function parseCSharpCompilationUnit(file) {
134
+ const warnings = [];
135
+ const normalizedPath = normalizePath(file.path);
136
+ if (file.language !== "csharp") {
137
+ warnings.push(`Unsupported language '${file.language}' for C# parser in file '${file.path}'.`);
138
+ return emptyModel(file, normalizedPath, warnings);
139
+ }
140
+ const content = file.content ?? "";
141
+ if (content.includes("\u0000")) {
142
+ warnings.push(`File '${file.path}' appears unreadable (contains null bytes); parser will continue with best-effort analysis.`);
143
+ }
144
+ const strippedContent = (0, strip_comments_1.stripCommentsPreservingLayout)(content, {
145
+ verbatimStrings: true,
146
+ });
147
+ const lines = strippedContent.split(/\r?\n/);
148
+ const usings = [];
149
+ const types = [];
150
+ const methods = [];
151
+ let namespaceName;
152
+ let currentType;
153
+ let pendingAttributes = [];
154
+ const toLocation = (startLine, endLine) => ({
155
+ filePath: file.path,
156
+ startLine,
157
+ endLine,
158
+ });
159
+ for (let i = 0; i < lines.length; i += 1) {
160
+ let text = (lines[i] ?? "").trim();
161
+ const lineNumber = i + 1;
162
+ if (!text)
163
+ continue;
164
+ // Attributes may sit on their own line or share a line with the member
165
+ // they decorate: `[HttpGet("{id}")] public IActionResult Get(int id)`.
166
+ let attributeGroup = splitLeadingAttributeGroup(text);
167
+ while (attributeGroup) {
168
+ pendingAttributes.push(...parseAttributeList(attributeGroup.inner));
169
+ text = attributeGroup.rest;
170
+ attributeGroup = text ? splitLeadingAttributeGroup(text) : null;
171
+ }
172
+ if (!text)
173
+ continue;
174
+ const usingMatch = text.match(USING_REGEX);
175
+ if (usingMatch) {
176
+ const isAlias = Boolean(usingMatch[4]);
177
+ usings.push({
178
+ namespace: isAlias ? usingMatch[4].trim() : usingMatch[3],
179
+ alias: isAlias ? usingMatch[3] : undefined,
180
+ isStatic: Boolean(usingMatch[2]),
181
+ isGlobal: Boolean(usingMatch[1]),
182
+ location: toLocation(lineNumber, lineNumber),
183
+ });
184
+ pendingAttributes = [];
185
+ continue;
186
+ }
187
+ const namespaceMatch = text.match(NAMESPACE_REGEX);
188
+ if (namespaceMatch) {
189
+ namespaceName = namespaceMatch[1];
190
+ pendingAttributes = [];
191
+ continue;
192
+ }
193
+ const typeMatch = text.match(TYPE_REGEX);
194
+ if (typeMatch) {
195
+ const baseTypes = (typeMatch[3] ?? "")
196
+ .split(",")
197
+ .map((base) => base.trim())
198
+ .filter(Boolean);
199
+ const name = typeMatch[2];
200
+ currentType = name;
201
+ types.push({
202
+ name,
203
+ kind: normalizeTypeKind(typeMatch[1]),
204
+ baseTypes,
205
+ attributes: pendingAttributes,
206
+ location: toLocation(lineNumber, lineNumber),
207
+ });
208
+ pendingAttributes = [];
209
+ continue;
210
+ }
211
+ const methodMatch = text.match(METHOD_REGEX);
212
+ if (methodMatch) {
213
+ const name = methodMatch[1];
214
+ methods.push({
215
+ name,
216
+ isAsync: /\basync\b/.test(text),
217
+ attributes: pendingAttributes,
218
+ declaringType: currentType,
219
+ location: toLocation(lineNumber, findMethodEndLine(lines, i)),
220
+ });
221
+ pendingAttributes = [];
222
+ continue;
223
+ }
224
+ pendingAttributes = [];
225
+ }
226
+ const calls = (0, c_family_calls_1.extractCFamilyCalls)(lines, { filePath: file.path });
227
+ return {
228
+ file,
229
+ normalizedPath,
230
+ strippedContent,
231
+ namespaceName,
232
+ usings,
233
+ types,
234
+ methods,
235
+ calls,
236
+ warnings,
237
+ };
238
+ }
239
+ function normalizeTypeKind(raw) {
240
+ const normalized = raw.replace(/\s+/g, " ").trim();
241
+ if (normalized.startsWith("record"))
242
+ return "record";
243
+ if (normalized === "interface")
244
+ return "interface";
245
+ if (normalized === "struct")
246
+ return "struct";
247
+ if (normalized === "enum")
248
+ return "enum";
249
+ return "class";
250
+ }
251
+ /**
252
+ * Walk braces forward from a method signature to find its closing line.
253
+ * Expression-bodied members (`=> Ok();`) end on their own line.
254
+ */
255
+ function findMethodEndLine(lines, startIndex) {
256
+ const startLine = lines[startIndex] ?? "";
257
+ if (/=>/.test(startLine) && startLine.trimEnd().endsWith(";")) {
258
+ return startIndex + 1;
259
+ }
260
+ let depth = 0;
261
+ let seenOpening = false;
262
+ for (let i = startIndex; i < lines.length; i += 1) {
263
+ const line = lines[i] ?? "";
264
+ for (const char of line) {
265
+ if (char === "{") {
266
+ depth += 1;
267
+ seenOpening = true;
268
+ }
269
+ else if (char === "}") {
270
+ depth -= 1;
271
+ }
272
+ }
273
+ if (seenOpening && depth <= 0)
274
+ return i + 1;
275
+ }
276
+ return startIndex + 1;
277
+ }
@@ -0,0 +1,3 @@
1
+ import type { RawFinding } from "../../core/types/detection";
2
+ import type { CSharpCompilationUnitModel } from "./parser";
3
+ export declare function detectCSharpPatternsFromModel(model: CSharpCompilationUnitModel): RawFinding[];
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectCSharpPatternsFromModel = detectCSharpPatternsFromModel;
4
+ const engine_1 = require("../../patterns/engine");
5
+ /**
6
+ * Represent a `using` as a language-agnostic import. The shared third-party
7
+ * catalog matches lowercase fragments (`stripe`, `sendgrid`), while .NET
8
+ * namespaces are PascalCase, so the lowercased forms are carried alongside.
9
+ */
10
+ function usingsAsImports(model) {
11
+ return model.usings.map((entry) => {
12
+ const namespaceName = entry.namespace;
13
+ const segments = namespaceName.split(".").filter(Boolean);
14
+ const names = Array.from(new Set([
15
+ namespaceName,
16
+ namespaceName.toLowerCase(),
17
+ ...segments,
18
+ ...segments.map((segment) => segment.toLowerCase()),
19
+ ])).filter(Boolean);
20
+ return { module: namespaceName, names };
21
+ });
22
+ }
23
+ /** Attributes are carried as decorator strings: both `HttpGet("x")` and `HttpGet`. */
24
+ function attributesAsDecorators(attributes) {
25
+ const decorators = new Set();
26
+ for (const attribute of attributes) {
27
+ decorators.add(attribute.raw);
28
+ decorators.add(attribute.name);
29
+ }
30
+ return Array.from(decorators);
31
+ }
32
+ function detectCSharpPatternsFromModel(model) {
33
+ return (0, engine_1.matchPatterns)({
34
+ language: "csharp",
35
+ file: model.file,
36
+ normalizedPath: model.normalizedPath,
37
+ strippedContent: model.strippedContent,
38
+ imports: usingsAsImports(model),
39
+ functions: model.methods.map((method) => ({
40
+ name: method.name,
41
+ decorators: attributesAsDecorators(method.attributes),
42
+ location: method.location,
43
+ })),
44
+ types: model.types.map((type) => ({
45
+ name: type.name,
46
+ kind: type.kind,
47
+ baseTypes: type.baseTypes,
48
+ decorators: attributesAsDecorators(type.attributes),
49
+ location: type.location,
50
+ })),
51
+ moduleLevelCalls: model.calls.map((call) => ({
52
+ callee: call.callee,
53
+ argumentsSnippet: call.argumentsSnippet,
54
+ location: call.location,
55
+ })),
56
+ });
57
+ }
@@ -0,0 +1,10 @@
1
+ import type { RawFinding } from "../../core/types/detection";
2
+ import { type ManifestScanBudgetOptions } from "../shared/manifest-budgets";
3
+ export interface GoManifestPackages {
4
+ manifestRelativePath: string;
5
+ /** The module's own path, from the `module` declaration. */
6
+ modulePath?: string;
7
+ packages: string[];
8
+ }
9
+ export declare function parseGoDependencyManifests(rootPath: string, opts?: ManifestScanBudgetOptions): Promise<GoManifestPackages[]>;
10
+ export declare function detectGoPatternsFromDependencyManifests(rootPath: string, opts?: ManifestScanBudgetOptions): Promise<RawFinding[]>;
@@ -0,0 +1,117 @@
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.parseGoDependencyManifests = parseGoDependencyManifests;
40
+ exports.detectGoPatternsFromDependencyManifests = detectGoPatternsFromDependencyManifests;
41
+ const promises_1 = __importDefault(require("fs/promises"));
42
+ const path = __importStar(require("path"));
43
+ const engine_1 = require("../../patterns/engine");
44
+ const manifest_budgets_1 = require("../shared/manifest-budgets");
45
+ const manifest_fs_1 = require("../shared/manifest-fs");
46
+ const manifest_parsers_1 = require("./manifest-parsers");
47
+ function toPosixPath(p) {
48
+ return p.split(path.sep).join("/");
49
+ }
50
+ function createManifestFileInfo(manifestRelativePath) {
51
+ return {
52
+ path: manifestRelativePath,
53
+ name: path.basename(manifestRelativePath),
54
+ content: "",
55
+ language: "go",
56
+ size: 0,
57
+ };
58
+ }
59
+ async function parseGoDependencyManifests(rootPath, opts) {
60
+ const rootDir = path.resolve(rootPath);
61
+ const manifests = [];
62
+ const state = (0, manifest_budgets_1.budgetStateFromOptions)(opts);
63
+ await (0, manifest_fs_1.walkForManifests)(rootDir, manifests, {
64
+ rootDir,
65
+ state,
66
+ excludePaths: opts?.excludePaths,
67
+ isManifestFile: (_entry, entryPath) => path.basename(entryPath).toLowerCase() === "go.mod",
68
+ });
69
+ const byManifest = [];
70
+ let bytesRead = 0;
71
+ const maxBytes = state.maxTotalManifestReadBytes;
72
+ for (const manifestAbsPath of manifests) {
73
+ if (bytesRead >= maxBytes)
74
+ break;
75
+ const manifestRelativePath = toPosixPath(path.relative(rootDir, manifestAbsPath));
76
+ let raw;
77
+ try {
78
+ raw = await promises_1.default.readFile(manifestAbsPath, "utf8");
79
+ }
80
+ catch {
81
+ continue;
82
+ }
83
+ bytesRead += raw.length;
84
+ const parsed = (0, manifest_parsers_1.parseGoMod)(raw);
85
+ if (parsed.requires.length === 0)
86
+ continue;
87
+ byManifest.push({
88
+ manifestRelativePath,
89
+ modulePath: parsed.modulePath,
90
+ packages: Array.from(new Set(parsed.requires)),
91
+ });
92
+ }
93
+ return byManifest;
94
+ }
95
+ async function detectGoPatternsFromDependencyManifests(rootPath, opts) {
96
+ const manifestPackages = await parseGoDependencyManifests(rootPath, opts);
97
+ if (manifestPackages.length === 0)
98
+ return [];
99
+ const findings = [];
100
+ for (const manifest of manifestPackages) {
101
+ const manifestFile = createManifestFileInfo(manifest.manifestRelativePath);
102
+ const imports = manifest.packages.map((p) => {
103
+ const segments = p.split("/").filter(Boolean);
104
+ return {
105
+ module: p,
106
+ names: Array.from(new Set([p, ...segments])),
107
+ };
108
+ });
109
+ findings.push(...(0, engine_1.matchPatterns)({
110
+ language: "go",
111
+ file: manifestFile,
112
+ normalizedPath: manifestFile.path,
113
+ imports,
114
+ }));
115
+ }
116
+ return findings;
117
+ }
@@ -0,0 +1,3 @@
1
+ import type { FileInfo } from "../../core/types/file";
2
+ import type { RawFinding } from "../../core/types/detection";
3
+ export declare function detectGoPatterns(file: FileInfo): RawFinding[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectGoPatterns = detectGoPatterns;
4
+ const property_inference_1 = require("../shared/property-inference");
5
+ const parser_1 = require("./parser");
6
+ const patterns_1 = require("./patterns");
7
+ function detectGoPatterns(file) {
8
+ const model = (0, parser_1.parseGoSourceFile)(file);
9
+ if (model.file.language !== "go") {
10
+ return [];
11
+ }
12
+ const findings = (0, patterns_1.detectGoPatternsFromModel)(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,97 @@
1
+ import { type PatternId } from "../../core/types/detection";
2
+ export interface GoRouteRegex {
3
+ regex: RegExp;
4
+ methodGroup?: number;
5
+ pathGroup?: number;
6
+ defaultMethod?: string;
7
+ }
8
+ export interface GoDbClientConfig {
9
+ id: string;
10
+ patternId: PatternId;
11
+ databaseType: string;
12
+ importPaths: string[];
13
+ callNames: string[];
14
+ confidence: number;
15
+ }
16
+ export interface GoAuthLibraryConfig {
17
+ id: string;
18
+ patternId: PatternId;
19
+ importPaths: string[];
20
+ callNames: string[];
21
+ contentRegexes: RegExp[];
22
+ strategy?: string;
23
+ confidence: number;
24
+ }
25
+ export interface GoRouteFrameworkConfig {
26
+ id: string;
27
+ patternId: PatternId;
28
+ importPaths: string[];
29
+ routeRegexes: GoRouteRegex[];
30
+ confidence: number;
31
+ }
32
+ export interface GoServerlessHandlerConfig {
33
+ id: string;
34
+ patternId: PatternId;
35
+ importPaths: string[];
36
+ callNames: string[];
37
+ confidence: number;
38
+ }
39
+ export interface GoConfigLoader {
40
+ id: string;
41
+ importPaths: string[];
42
+ callNames: string[];
43
+ }
44
+ export interface GoHttpClientConfig {
45
+ id: string;
46
+ patternId: PatternId;
47
+ clientName: string;
48
+ importPaths: string[];
49
+ callNames: string[];
50
+ callNameSuffixes: string[];
51
+ urlRegex: RegExp;
52
+ confidence: number;
53
+ }
54
+ export interface GoPatternConfig {
55
+ dbClients: GoDbClientConfig[];
56
+ sqlOpen?: {
57
+ patternId: PatternId;
58
+ regex: RegExp;
59
+ name: string;
60
+ confidence: number;
61
+ /** Driver name (as passed to `sql.Open`) → component `databaseType`. */
62
+ drivers: Record<string, string>;
63
+ defaultDatabaseType: string;
64
+ };
65
+ auth: {
66
+ libraries: GoAuthLibraryConfig[];
67
+ };
68
+ routes: {
69
+ frameworks: GoRouteFrameworkConfig[];
70
+ };
71
+ serverless: {
72
+ handlers: GoServerlessHandlerConfig[];
73
+ };
74
+ envConfig: {
75
+ envVariable?: {
76
+ patternId: PatternId;
77
+ regex: RegExp;
78
+ confidence: number;
79
+ };
80
+ configLoaders?: {
81
+ patternId: PatternId;
82
+ confidence: number;
83
+ loaders: GoConfigLoader[];
84
+ };
85
+ configFile?: {
86
+ patternId: PatternId;
87
+ fileNameRegex: RegExp;
88
+ name: string;
89
+ confidence: number;
90
+ };
91
+ };
92
+ externalApis: {
93
+ httpClients: GoHttpClientConfig[];
94
+ };
95
+ }
96
+ export declare function clearGoPatternConfigCache(): void;
97
+ export declare function loadGoPatternConfig(): GoPatternConfig;