@topogram/cli 0.3.34

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 (257) hide show
  1. package/ARCHITECTURE.md +67 -0
  2. package/CHANGELOG.md +240 -0
  3. package/README.md +223 -0
  4. package/package.json +51 -0
  5. package/src/adoption/index.js +3 -0
  6. package/src/adoption/plan.js +702 -0
  7. package/src/adoption/reporting.js +464 -0
  8. package/src/adoption/review-groups.js +313 -0
  9. package/src/agent-ops/query-builders.js +5012 -0
  10. package/src/archive/archive.js +141 -0
  11. package/src/archive/compact.js +26 -0
  12. package/src/archive/jsonl.js +70 -0
  13. package/src/archive/resolver-bridge.js +82 -0
  14. package/src/archive/schema.js +87 -0
  15. package/src/archive/unarchive.js +108 -0
  16. package/src/catalog.js +752 -0
  17. package/src/cli/catalog-alias.js +166 -0
  18. package/src/cli.js +9738 -0
  19. package/src/component-behavior.js +173 -0
  20. package/src/example-implementation.js +91 -0
  21. package/src/format.js +19 -0
  22. package/src/generator/adapters.d.ts +4 -0
  23. package/src/generator/adapters.js +325 -0
  24. package/src/generator/api.d.ts +1 -0
  25. package/src/generator/api.js +1196 -0
  26. package/src/generator/check.js +355 -0
  27. package/src/generator/component-conformance.js +767 -0
  28. package/src/generator/components.js +39 -0
  29. package/src/generator/context/bundle.js +291 -0
  30. package/src/generator/context/diff.js +256 -0
  31. package/src/generator/context/digest.js +182 -0
  32. package/src/generator/context/domain-coverage.js +94 -0
  33. package/src/generator/context/domain-page.js +137 -0
  34. package/src/generator/context/index.js +42 -0
  35. package/src/generator/context/report.js +121 -0
  36. package/src/generator/context/shared.js +1397 -0
  37. package/src/generator/context/slice.js +703 -0
  38. package/src/generator/context/task-mode.js +466 -0
  39. package/src/generator/docs.js +327 -0
  40. package/src/generator/index.js +161 -0
  41. package/src/generator/native/parity-bundle.js +311 -0
  42. package/src/generator/output.js +300 -0
  43. package/src/generator/registry.js +482 -0
  44. package/src/generator/runtime/app-bundle.js +456 -0
  45. package/src/generator/runtime/bundle-shared.js +166 -0
  46. package/src/generator/runtime/compile-check.js +163 -0
  47. package/src/generator/runtime/deployment.js +287 -0
  48. package/src/generator/runtime/environment.js +635 -0
  49. package/src/generator/runtime/index.js +32 -0
  50. package/src/generator/runtime/runtime-check.js +554 -0
  51. package/src/generator/runtime/shared.js +515 -0
  52. package/src/generator/runtime/smoke.js +219 -0
  53. package/src/generator/schema.js +204 -0
  54. package/src/generator/sdlc/board.js +66 -0
  55. package/src/generator/sdlc/doc-page.js +53 -0
  56. package/src/generator/sdlc/index.js +23 -0
  57. package/src/generator/sdlc/release-notes.js +62 -0
  58. package/src/generator/sdlc/traceability-matrix.js +65 -0
  59. package/src/generator/shared.js +29 -0
  60. package/src/generator/surfaces/contracts.js +146 -0
  61. package/src/generator/surfaces/databases/contract.js +40 -0
  62. package/src/generator/surfaces/databases/index.js +84 -0
  63. package/src/generator/surfaces/databases/lifecycle-shared.d.ts +1 -0
  64. package/src/generator/surfaces/databases/lifecycle-shared.js +612 -0
  65. package/src/generator/surfaces/databases/migration-plan.js +281 -0
  66. package/src/generator/surfaces/databases/postgres/capabilities.js +14 -0
  67. package/src/generator/surfaces/databases/postgres/drizzle.js +99 -0
  68. package/src/generator/surfaces/databases/postgres/index.js +9 -0
  69. package/src/generator/surfaces/databases/postgres/lifecycle.js +16 -0
  70. package/src/generator/surfaces/databases/postgres/prisma.js +159 -0
  71. package/src/generator/surfaces/databases/postgres/sql-migration.js +102 -0
  72. package/src/generator/surfaces/databases/postgres/sql-schema.js +34 -0
  73. package/src/generator/surfaces/databases/shared.d.ts +1 -0
  74. package/src/generator/surfaces/databases/shared.js +350 -0
  75. package/src/generator/surfaces/databases/snapshot.js +96 -0
  76. package/src/generator/surfaces/databases/sqlite/capabilities.js +14 -0
  77. package/src/generator/surfaces/databases/sqlite/index.js +8 -0
  78. package/src/generator/surfaces/databases/sqlite/lifecycle.js +16 -0
  79. package/src/generator/surfaces/databases/sqlite/prisma.js +143 -0
  80. package/src/generator/surfaces/databases/sqlite/sql-migration.js +65 -0
  81. package/src/generator/surfaces/databases/sqlite/sql-schema.js +27 -0
  82. package/src/generator/surfaces/index.js +25 -0
  83. package/src/generator/surfaces/native/swiftui-app.js +38 -0
  84. package/src/generator/surfaces/native/swiftui-templates/Package.swift.txt +20 -0
  85. package/src/generator/surfaces/native/swiftui-templates/README.generated.md +26 -0
  86. package/src/generator/surfaces/native/swiftui-templates/runtime/DynamicScreens.swift +682 -0
  87. package/src/generator/surfaces/native/swiftui-templates/runtime/TodoAPIClient.swift +156 -0
  88. package/src/generator/surfaces/native/swiftui-templates/runtime/TodoSwiftUIApp.swift +44 -0
  89. package/src/generator/surfaces/native/swiftui-templates/runtime/Visibility.swift +183 -0
  90. package/src/generator/surfaces/services/express.d.ts +1 -0
  91. package/src/generator/surfaces/services/express.js +766 -0
  92. package/src/generator/surfaces/services/hono.d.ts +1 -0
  93. package/src/generator/surfaces/services/hono.js +204 -0
  94. package/src/generator/surfaces/services/index.js +42 -0
  95. package/src/generator/surfaces/services/persistence-wiring.js +240 -0
  96. package/src/generator/surfaces/services/runtime-helpers.js +631 -0
  97. package/src/generator/surfaces/services/server-contract.js +80 -0
  98. package/src/generator/surfaces/services/stateless.d.ts +1 -0
  99. package/src/generator/surfaces/services/stateless.js +97 -0
  100. package/src/generator/surfaces/shared.js +64 -0
  101. package/src/generator/surfaces/web/api-client.js +1 -0
  102. package/src/generator/surfaces/web/forms.js +1 -0
  103. package/src/generator/surfaces/web/index.d.ts +2 -0
  104. package/src/generator/surfaces/web/index.js +53 -0
  105. package/src/generator/surfaces/web/react-components.js +248 -0
  106. package/src/generator/surfaces/web/react.js +538 -0
  107. package/src/generator/surfaces/web/routes.js +1 -0
  108. package/src/generator/surfaces/web/screens.js +1 -0
  109. package/src/generator/surfaces/web/shared.js +369 -0
  110. package/src/generator/surfaces/web/sveltekit-actions.js +28 -0
  111. package/src/generator/surfaces/web/sveltekit-components.js +234 -0
  112. package/src/generator/surfaces/web/sveltekit.js +426 -0
  113. package/src/generator/surfaces/web/ui-web-contract.js +65 -0
  114. package/src/generator/surfaces/web/vanilla.js +239 -0
  115. package/src/generator/verification.js +84 -0
  116. package/src/generator.js +1 -0
  117. package/src/import/core/context.js +52 -0
  118. package/src/import/core/contracts.js +23 -0
  119. package/src/import/core/registry.js +81 -0
  120. package/src/import/core/runner.js +646 -0
  121. package/src/import/core/shared.js +910 -0
  122. package/src/import/enrichers/auth-session.js +18 -0
  123. package/src/import/enrichers/django-rest.js +226 -0
  124. package/src/import/enrichers/doc-linking.js +20 -0
  125. package/src/import/enrichers/rails-controllers.js +246 -0
  126. package/src/import/enrichers/rails-models.js +130 -0
  127. package/src/import/enrichers/workflow-target-state.js +10 -0
  128. package/src/import/extractors/api/aspnet-core.js +304 -0
  129. package/src/import/extractors/api/django-routes.js +318 -0
  130. package/src/import/extractors/api/express.js +154 -0
  131. package/src/import/extractors/api/fastify.js +371 -0
  132. package/src/import/extractors/api/flutter-dio.js +135 -0
  133. package/src/import/extractors/api/generic-route-fallback.js +90 -0
  134. package/src/import/extractors/api/graphql-code-first.js +565 -0
  135. package/src/import/extractors/api/graphql-sdl.js +309 -0
  136. package/src/import/extractors/api/jaxrs.js +303 -0
  137. package/src/import/extractors/api/micronaut.js +213 -0
  138. package/src/import/extractors/api/next-route.js +50 -0
  139. package/src/import/extractors/api/next-server-action.js +51 -0
  140. package/src/import/extractors/api/nextauth.js +52 -0
  141. package/src/import/extractors/api/openapi-code.js +242 -0
  142. package/src/import/extractors/api/openapi.js +232 -0
  143. package/src/import/extractors/api/rails-routes.js +230 -0
  144. package/src/import/extractors/api/react-native-repository.js +128 -0
  145. package/src/import/extractors/api/retrofit.js +103 -0
  146. package/src/import/extractors/api/spring-web.js +372 -0
  147. package/src/import/extractors/api/swift-webapi.js +116 -0
  148. package/src/import/extractors/api/trpc.js +212 -0
  149. package/src/import/extractors/db/django-models.js +232 -0
  150. package/src/import/extractors/db/dotnet-models.js +93 -0
  151. package/src/import/extractors/db/drizzle.js +242 -0
  152. package/src/import/extractors/db/ef-core.js +221 -0
  153. package/src/import/extractors/db/flutter-entities.js +120 -0
  154. package/src/import/extractors/db/jpa.js +120 -0
  155. package/src/import/extractors/db/liquibase.js +180 -0
  156. package/src/import/extractors/db/mybatis-xml.js +145 -0
  157. package/src/import/extractors/db/prisma.js +185 -0
  158. package/src/import/extractors/db/rails-schema.js +175 -0
  159. package/src/import/extractors/db/react-native-entities.js +95 -0
  160. package/src/import/extractors/db/room.js +193 -0
  161. package/src/import/extractors/db/snapshot.js +112 -0
  162. package/src/import/extractors/db/sql.js +180 -0
  163. package/src/import/extractors/db/swiftdata.js +137 -0
  164. package/src/import/extractors/ui/android-compose.js +230 -0
  165. package/src/import/extractors/ui/backend-only.js +70 -0
  166. package/src/import/extractors/ui/blazor.js +227 -0
  167. package/src/import/extractors/ui/flutter-screens.js +152 -0
  168. package/src/import/extractors/ui/maui-xaml.js +135 -0
  169. package/src/import/extractors/ui/next-app-router.js +83 -0
  170. package/src/import/extractors/ui/next-pages-router.js +141 -0
  171. package/src/import/extractors/ui/razor-pages.js +181 -0
  172. package/src/import/extractors/ui/react-native-screens.js +166 -0
  173. package/src/import/extractors/ui/react-router.js +139 -0
  174. package/src/import/extractors/ui/sveltekit.js +123 -0
  175. package/src/import/extractors/ui/swiftui.js +193 -0
  176. package/src/import/extractors/ui/uikit.js +175 -0
  177. package/src/import/extractors/verification/generic.js +290 -0
  178. package/src/import/extractors/workflows/generic.js +137 -0
  179. package/src/import/index.js +7 -0
  180. package/src/import/provenance.js +158 -0
  181. package/src/new-project.js +2107 -0
  182. package/src/parser.js +439 -0
  183. package/src/policy/review-boundaries.js +165 -0
  184. package/src/project-config.js +535 -0
  185. package/src/proofs/backend-parity.js +19 -0
  186. package/src/proofs/contract-audit.js +220 -0
  187. package/src/proofs/ios-parity.js +7 -0
  188. package/src/proofs/issues-parity.js +10 -0
  189. package/src/proofs/web-parity.js +50 -0
  190. package/src/realization/api/build-api-realization.js +5 -0
  191. package/src/realization/api/index.js +1 -0
  192. package/src/realization/backend/build-backend-runtime-realization.js +82 -0
  193. package/src/realization/backend/index.d.ts +1 -0
  194. package/src/realization/backend/index.js +4 -0
  195. package/src/realization/db/build-db-realization.js +17 -0
  196. package/src/realization/db/index.js +3 -0
  197. package/src/realization/db/migration-plan.js +5 -0
  198. package/src/realization/db/snapshot.js +5 -0
  199. package/src/realization/ui/build-ui-shared-realization.js +305 -0
  200. package/src/realization/ui/build-web-realization.js +189 -0
  201. package/src/realization/ui/index.js +2 -0
  202. package/src/reconcile/docs.js +280 -0
  203. package/src/reconcile/index.js +3 -0
  204. package/src/reconcile/journeys.js +441 -0
  205. package/src/resolver/docs.js +1 -0
  206. package/src/resolver/enrich/acceptance-criterion.js +14 -0
  207. package/src/resolver/enrich/bug.js +12 -0
  208. package/src/resolver/enrich/component.js +2 -0
  209. package/src/resolver/enrich/index.js +1 -0
  210. package/src/resolver/enrich/pitch.js +18 -0
  211. package/src/resolver/enrich/requirement.js +20 -0
  212. package/src/resolver/enrich/task.js +16 -0
  213. package/src/resolver/expressions.js +1 -0
  214. package/src/resolver/index.js +2422 -0
  215. package/src/resolver/normalize.js +1 -0
  216. package/src/resolver.js +1 -0
  217. package/src/sdlc/adopt.js +65 -0
  218. package/src/sdlc/check.js +86 -0
  219. package/src/sdlc/dod/acceptance-criterion.js +22 -0
  220. package/src/sdlc/dod/bug.js +26 -0
  221. package/src/sdlc/dod/document.js +23 -0
  222. package/src/sdlc/dod/index.js +25 -0
  223. package/src/sdlc/dod/pitch.js +23 -0
  224. package/src/sdlc/dod/requirement.js +34 -0
  225. package/src/sdlc/dod/task.js +39 -0
  226. package/src/sdlc/explain.js +116 -0
  227. package/src/sdlc/history.js +80 -0
  228. package/src/sdlc/paths.js +11 -0
  229. package/src/sdlc/release.js +106 -0
  230. package/src/sdlc/scaffold.js +89 -0
  231. package/src/sdlc/status-filter.js +54 -0
  232. package/src/sdlc/transition.js +112 -0
  233. package/src/sdlc/transitions/acceptance-criterion.js +28 -0
  234. package/src/sdlc/transitions/bug.js +31 -0
  235. package/src/sdlc/transitions/document.js +29 -0
  236. package/src/sdlc/transitions/index.js +56 -0
  237. package/src/sdlc/transitions/pitch.js +34 -0
  238. package/src/sdlc/transitions/requirement.js +31 -0
  239. package/src/sdlc/transitions/task.js +34 -0
  240. package/src/template-trust.js +597 -0
  241. package/src/validator/expressions.js +1 -0
  242. package/src/validator/index.js +3424 -0
  243. package/src/validator/kinds.js +346 -0
  244. package/src/validator/per-kind/acceptance-criterion.js +91 -0
  245. package/src/validator/per-kind/bug.js +77 -0
  246. package/src/validator/per-kind/component.js +274 -0
  247. package/src/validator/per-kind/domain.js +205 -0
  248. package/src/validator/per-kind/pitch.js +101 -0
  249. package/src/validator/per-kind/requirement.js +75 -0
  250. package/src/validator/per-kind/task.js +96 -0
  251. package/src/validator/registry.js +1 -0
  252. package/src/validator/utils.js +12 -0
  253. package/src/validator.js +1 -0
  254. package/src/workflows.js +7597 -0
  255. package/src/workspace-docs.js +265 -0
  256. package/template-helpers/react.js +5 -0
  257. package/template-helpers/sveltekit.js +5 -0
@@ -0,0 +1,120 @@
1
+ import { canonicalCandidateTerm, dedupeCandidateRecords, findImportFiles, makeCandidateRecord, relativeTo, slugify, titleCase } from "../../core/shared.js";
2
+
3
+ function extractAnnotatedFields(text) {
4
+ const fields = [];
5
+ const relations = [];
6
+ const enumFields = [];
7
+ for (const match of String(text || "").matchAll(/((?:\s*@[\w.]+(?:\([^)]*\))?\s*)+)\s*private\s+([A-Za-z0-9_<>\[\]\.?]+)\s+([A-Za-z_][A-Za-z0-9_]*)\s*;/g)) {
8
+ const [, annotations, rawType, name] = match;
9
+ const baseType = rawType.replace(/^Set<|^List</, "").replace(/>$/, "").split(".").pop();
10
+ const columnName = annotations.match(/@JoinColumn\(name\s*=\s*"([^"]+)"/)?.[1] || annotations.match(/@Column\(name\s*=\s*"([^"]+)"/)?.[1] || name;
11
+ const isRelation = /@(ManyToOne|OneToOne|OneToMany|ManyToMany)/.test(annotations);
12
+ if (isRelation) {
13
+ const relationTarget = canonicalCandidateTerm(baseType.replace(/Data$/, ""));
14
+ relations.push({
15
+ to_entity: `entity_${slugify(relationTarget)}`,
16
+ relation_field: columnName,
17
+ fields: [columnName],
18
+ references: ["id"]
19
+ });
20
+ if (/@(OneToMany|ManyToMany)/.test(annotations)) {
21
+ continue;
22
+ }
23
+ }
24
+ if (/@Enumerated/.test(annotations)) {
25
+ enumFields.push({ name: columnName, enum_name: baseType });
26
+ }
27
+ fields.push({
28
+ name: columnName,
29
+ field_type: rawType.toLowerCase(),
30
+ required: /nullable\s*=\s*false/.test(annotations) || /@Id\b/.test(annotations),
31
+ list: /^Set<|^List</.test(rawType),
32
+ unique: /unique\s*=\s*true/.test(annotations),
33
+ primary_key: /@Id\b/.test(annotations)
34
+ });
35
+ }
36
+ return { fields, relations, enumFields };
37
+ }
38
+
39
+ function isNoiseEntity(entityStem) {
40
+ return ["order-item", "orderitem"].includes(entityStem) || /(?:favorite|follow|tag)-?relationship$/.test(entityStem);
41
+ }
42
+
43
+ export const jpaExtractor = {
44
+ id: "db.jpa",
45
+ track: "db",
46
+ detect(context) {
47
+ const entityFiles = findImportFiles(context.paths, (filePath) => /\.java$/i.test(filePath));
48
+ const count = entityFiles.filter((filePath) => /@Entity\b/.test(context.helpers.readTextIfExists(filePath) || "")).length;
49
+ return {
50
+ score: count > 0 ? 87 : 0,
51
+ reasons: count > 0 ? ["Found JPA @Entity classes"] : []
52
+ };
53
+ },
54
+ extract(context) {
55
+ const files = findImportFiles(context.paths, (filePath) => /\.java$/i.test(filePath));
56
+ const findings = [];
57
+ const candidates = { entities: [], enums: [], relations: [], indexes: [] };
58
+
59
+ for (const filePath of files) {
60
+ const text = context.helpers.readTextIfExists(filePath) || "";
61
+ const entityName = text.match(/@Entity(?:\(name\s*=\s*"([^"]+)"\))?/)?.[1];
62
+ if (!/@Entity\b/.test(text)) continue;
63
+ const className = text.match(/class\s+([A-Za-z_][A-Za-z0-9_]*)/)?.[1] || "";
64
+ const tableName = text.match(/@Table\(name\s*=\s*"([^"]+)"\)/)?.[1] || entityName || className;
65
+ const entityStem = canonicalCandidateTerm(String(entityName || tableName || className).replace(/Data$/, ""));
66
+ const { fields, relations, enumFields } = extractAnnotatedFields(text);
67
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
68
+ const noiseCandidate = isNoiseEntity(entityStem);
69
+
70
+ findings.push({
71
+ kind: "jpa_entity",
72
+ file: provenance,
73
+ entity: entityStem,
74
+ field_count: fields.length
75
+ });
76
+
77
+ candidates.entities.push(makeCandidateRecord({
78
+ kind: "entity",
79
+ idHint: `entity_${slugify(entityStem)}`,
80
+ label: titleCase(entityStem),
81
+ confidence: "high",
82
+ sourceKind: "schema",
83
+ provenance,
84
+ table_name: tableName,
85
+ fields,
86
+ noise_candidate: noiseCandidate,
87
+ noise_reason: noiseCandidate ? "JPA implementation-noise child entity." : null,
88
+ track: "db"
89
+ }));
90
+
91
+ candidates.relations.push(...relations.map((relation) => makeCandidateRecord({
92
+ kind: "relation",
93
+ idHint: slugify(`entity_${entityStem}_${relation.relation_field}_${relation.to_entity}`),
94
+ label: `entity_${entityStem} -> ${relation.to_entity}`,
95
+ confidence: "high",
96
+ sourceKind: "schema",
97
+ provenance,
98
+ from_entity: `entity_${slugify(entityStem)}`,
99
+ ...relation,
100
+ track: "db"
101
+ })));
102
+
103
+ candidates.enums.push(...enumFields.map((entry) => makeCandidateRecord({
104
+ kind: "enum",
105
+ idHint: slugify(entry.enum_name),
106
+ label: titleCase(entry.enum_name),
107
+ confidence: "medium",
108
+ sourceKind: "schema",
109
+ provenance,
110
+ values: [],
111
+ track: "db"
112
+ })));
113
+ }
114
+
115
+ candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
116
+ candidates.relations = dedupeCandidateRecords(candidates.relations, (record) => record.id_hint);
117
+ candidates.enums = dedupeCandidateRecords(candidates.enums, (record) => record.id_hint);
118
+ return { findings, candidates };
119
+ }
120
+ };
@@ -0,0 +1,180 @@
1
+ import {
2
+ canonicalCandidateTerm,
3
+ dedupeCandidateRecords,
4
+ findImportFiles,
5
+ idHintify,
6
+ makeCandidateRecord,
7
+ relativeTo,
8
+ slugify,
9
+ titleCase
10
+ } from "../../core/shared.js";
11
+
12
+ function normalizeLiquibaseTableName(tableName) {
13
+ return String(tableName || "")
14
+ .replace(/^(tbl?|v)_/i, "")
15
+ .replace(/_/g, "-");
16
+ }
17
+
18
+ function isJoinTable(tableName, fields) {
19
+ const normalized = normalizeLiquibaseTableName(tableName);
20
+ const idFields = (fields || []).filter((field) => field.name.endsWith("_id"));
21
+ return (
22
+ ["article-tags", "favorites", "follows"].includes(normalized) ||
23
+ (idFields.length >= 2 && (fields || []).length <= 4)
24
+ );
25
+ }
26
+
27
+ function joinNoiseReason(tableName) {
28
+ const normalized = normalizeLiquibaseTableName(tableName);
29
+ if (normalized === "article-tags") return "Liquibase implementation-noise join table for article-tag linkage.";
30
+ if (normalized === "favorites" || normalized === "article-favorites") return "Liquibase implementation-noise join table for article favorites.";
31
+ if (normalized === "follows" || normalized === "follow-relation") return "Liquibase implementation-noise join table for follow relationships.";
32
+ return "Liquibase implementation-noise join table.";
33
+ }
34
+
35
+ function parseConstraints(raw) {
36
+ return {
37
+ required: /nullable="false"/.test(raw),
38
+ unique: /unique="true"/.test(raw),
39
+ primary_key: /primaryKey="true"/.test(raw),
40
+ referencedTableName: raw.match(/referencedTableName="([^"]+)"/)?.[1] || null,
41
+ referencedColumnNames: raw.match(/referencedColumnNames="([^"]+)"/)?.[1] || null
42
+ };
43
+ }
44
+
45
+ function parseLiquibaseSchema(xmlText) {
46
+ const entities = [];
47
+ const relations = [];
48
+ const indexes = [];
49
+
50
+ for (const match of String(xmlText || "").matchAll(/<createTable\s+tableName="([^"]+)"[^>]*>([\s\S]*?)<\/createTable>/g)) {
51
+ const [, tableName, tableBody] = match;
52
+ if (/^v_/i.test(tableName)) continue;
53
+ const entityStem = canonicalCandidateTerm(normalizeLiquibaseTableName(tableName));
54
+ const fields = [];
55
+
56
+ for (const columnMatch of tableBody.matchAll(/<column\s+name="([^"]+)"\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/column>|<column\s+name="([^"]+)"\s+type="([^"]+)"([^>]*)\/>/g)) {
57
+ const name = columnMatch[1] || columnMatch[4];
58
+ const fieldType = (columnMatch[2] || columnMatch[5] || "").toLowerCase();
59
+ const inner = columnMatch[3] || columnMatch[6] || "";
60
+ const constraints = parseConstraints(inner);
61
+ fields.push({
62
+ name,
63
+ field_type: fieldType,
64
+ required: constraints.required,
65
+ unique: constraints.unique,
66
+ primary_key: constraints.primary_key,
67
+ list: false
68
+ });
69
+ if (constraints.referencedTableName) {
70
+ const targetStem = canonicalCandidateTerm(normalizeLiquibaseTableName(constraints.referencedTableName));
71
+ relations.push({
72
+ from_entity: `entity_${entityStem}`,
73
+ to_entity: `entity_${targetStem}`,
74
+ relation_field: name,
75
+ fields: [name],
76
+ references: String(constraints.referencedColumnNames || "id").split(/\s*,\s*/)
77
+ });
78
+ }
79
+ }
80
+
81
+ const noiseCandidate = isJoinTable(tableName, fields);
82
+ entities.push({
83
+ id_hint: `entity_${entityStem}`,
84
+ label: titleCase(entityStem),
85
+ table_name: tableName,
86
+ fields,
87
+ noise_candidate: noiseCandidate,
88
+ noise_reason: noiseCandidate ? joinNoiseReason(tableName) : null
89
+ });
90
+ }
91
+
92
+ for (const match of String(xmlText || "").matchAll(/<createIndex\s+indexName="([^"]+)"\s+tableName="([^"]+)"[^>]*>([\s\S]*?)<\/createIndex>/g)) {
93
+ const [, indexName, tableName, body] = match;
94
+ if (/^v_/i.test(tableName)) continue;
95
+ const entityStem = canonicalCandidateTerm(normalizeLiquibaseTableName(tableName));
96
+ const fields = [...body.matchAll(/<column\s+name="([^"]+)"\s*\/>/g)].map((entry) => entry[1]);
97
+ indexes.push({
98
+ id_hint: idHintify(indexName),
99
+ entity: `entity_${entityStem}`,
100
+ fields,
101
+ unique: false
102
+ });
103
+ }
104
+
105
+ return { entities, relations, indexes };
106
+ }
107
+
108
+ export const liquibaseExtractor = {
109
+ id: "db.liquibase",
110
+ track: "db",
111
+ detect(context) {
112
+ const files = findImportFiles(context.paths, (filePath) => /db\/changelog\/.+\.(xml|ya?ml)$/i.test(filePath));
113
+ return {
114
+ score: files.length > 0 ? 88 : 0,
115
+ reasons: files.length > 0 ? ["Found Liquibase changelog files"] : []
116
+ };
117
+ },
118
+ extract(context) {
119
+ const changelogFiles = findImportFiles(context.paths, (filePath) => /db\/changelog\/.+\.xml$/i.test(filePath));
120
+ const findings = [];
121
+ const candidates = { entities: [], enums: [], relations: [], indexes: [] };
122
+
123
+ for (const filePath of changelogFiles) {
124
+ const text = context.helpers.readTextIfExists(filePath) || "";
125
+ const parsed = parseLiquibaseSchema(text);
126
+ if (parsed.entities.length === 0 && parsed.relations.length === 0) continue;
127
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
128
+
129
+ findings.push({
130
+ kind: "liquibase_schema",
131
+ file: provenance,
132
+ entity_count: parsed.entities.length,
133
+ relation_count: parsed.relations.length
134
+ });
135
+
136
+ candidates.entities.push(...parsed.entities.map((entity) => makeCandidateRecord({
137
+ kind: "entity",
138
+ idHint: entity.id_hint,
139
+ label: entity.label,
140
+ confidence: "high",
141
+ sourceKind: "schema",
142
+ provenance,
143
+ table_name: entity.table_name,
144
+ fields: entity.fields,
145
+ noise_candidate: entity.noise_candidate,
146
+ noise_reason: entity.noise_reason,
147
+ track: "db"
148
+ })));
149
+
150
+ candidates.relations.push(...parsed.relations.map((relation) => makeCandidateRecord({
151
+ kind: "relation",
152
+ idHint: slugify(`${relation.from_entity}_${relation.relation_field}_${relation.to_entity}`),
153
+ label: `${relation.from_entity} -> ${relation.to_entity}`,
154
+ confidence: "high",
155
+ sourceKind: "schema",
156
+ provenance,
157
+ ...relation,
158
+ track: "db"
159
+ })));
160
+
161
+ candidates.indexes.push(...parsed.indexes.map((index) => makeCandidateRecord({
162
+ kind: "index",
163
+ idHint: index.id_hint,
164
+ label: titleCase(index.id_hint.replace(/^ix_/, "")),
165
+ confidence: "medium",
166
+ sourceKind: "schema",
167
+ provenance,
168
+ entity: index.entity,
169
+ fields: index.fields,
170
+ unique: index.unique,
171
+ track: "db"
172
+ })));
173
+ }
174
+
175
+ candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
176
+ candidates.relations = dedupeCandidateRecords(candidates.relations, (record) => record.id_hint);
177
+ candidates.indexes = dedupeCandidateRecords(candidates.indexes, (record) => record.id_hint);
178
+ return { findings, candidates };
179
+ }
180
+ };
@@ -0,0 +1,145 @@
1
+ import { dedupeCandidateRecords, findImportFiles, makeCandidateRecord, relativeTo, selectPreferredImportFiles, slugify, titleCase, idHintify, canonicalCandidateTerm } from "../../core/shared.js";
2
+ import { parseSqlSchema } from "./sql.js";
3
+
4
+ function classifyNoiseEntity(tableName, fields) {
5
+ const normalized = String(tableName || "").toLowerCase();
6
+ const idLikeFields = (fields || []).filter((field) => /_id$/.test(field.name));
7
+ if (["article_favorites", "article_tags", "follows"].includes(normalized)) {
8
+ return {
9
+ noise_candidate: true,
10
+ noise_reason:
11
+ normalized === "article_favorites"
12
+ ? "Spring MyBatis implementation-noise join table for article favorites."
13
+ : normalized === "article_tags"
14
+ ? "Spring MyBatis implementation-noise join table for article-tag linkage."
15
+ : "Spring MyBatis implementation-noise join table for follow relationships."
16
+ };
17
+ }
18
+ if (idLikeFields.length >= 2 && (fields || []).length <= 4) {
19
+ return {
20
+ noise_candidate: true,
21
+ noise_reason: "Spring MyBatis implementation-noise join table."
22
+ };
23
+ }
24
+ return {
25
+ noise_candidate: false,
26
+ noise_reason: null
27
+ };
28
+ }
29
+
30
+ function isUsableMapperTableName(tableName) {
31
+ const normalized = String(tableName || "").trim().toLowerCase();
32
+ return normalized && !["id", "name", "count"].includes(normalized);
33
+ }
34
+
35
+ export const myBatisXmlExtractor = {
36
+ id: "db.mybatis-xml",
37
+ track: "db",
38
+ detect(context) {
39
+ const mapperFiles = findImportFiles(context.paths, (filePath) => /\/mapper\/.+\.xml$/i.test(filePath));
40
+ return {
41
+ score: mapperFiles.length > 0 ? 86 : 0,
42
+ reasons: mapperFiles.length > 0 ? ["Found MyBatis mapper XML files"] : []
43
+ };
44
+ },
45
+ extract(context) {
46
+ const mapperFiles = findImportFiles(context.paths, (filePath) => /\/mapper\/.+\.xml$/i.test(filePath));
47
+ const allSqlFiles = findImportFiles(context.paths, (filePath) => filePath.endsWith(".sql"));
48
+ const schemaSqlFiles = allSqlFiles.filter((filePath) => !/\/src\/test\//i.test(filePath));
49
+ const sqlFiles = selectPreferredImportFiles(context.paths, schemaSqlFiles, "sql");
50
+ const findings = [];
51
+ const candidates = { entities: [], enums: [], relations: [], indexes: [] };
52
+
53
+ if (mapperFiles.length === 0) {
54
+ return { findings, candidates };
55
+ }
56
+
57
+ const seenTableNames = new Set();
58
+ for (const filePath of sqlFiles) {
59
+ const parsed = parseSqlSchema(context.helpers.readTextIfExists(filePath) || "");
60
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
61
+ findings.push({
62
+ kind: "mybatis_schema",
63
+ file: provenance,
64
+ entity_count: parsed.entities.length,
65
+ relation_count: parsed.relations.length
66
+ });
67
+
68
+ for (const entity of parsed.entities) {
69
+ const tableName = entity.table_name || entity.name;
70
+ seenTableNames.add(tableName);
71
+ const noise = classifyNoiseEntity(tableName, entity.fields);
72
+ candidates.entities.push(makeCandidateRecord({
73
+ kind: "entity",
74
+ idHint: `entity_${slugify(entity.name)}`,
75
+ label: titleCase(entity.name),
76
+ confidence: "high",
77
+ sourceKind: "schema",
78
+ provenance,
79
+ table_name: tableName,
80
+ fields: entity.fields,
81
+ noise_candidate: noise.noise_candidate,
82
+ noise_reason: noise.noise_reason,
83
+ track: "db"
84
+ }));
85
+ }
86
+
87
+ candidates.relations.push(...parsed.relations.map((relation) => makeCandidateRecord({
88
+ kind: "relation",
89
+ idHint: slugify(`${relation.from_entity}_${relation.relation_field}_${relation.to_entity}`),
90
+ label: `${relation.from_entity} -> ${relation.to_entity}`,
91
+ confidence: "medium",
92
+ sourceKind: "schema",
93
+ provenance,
94
+ ...relation,
95
+ track: "db"
96
+ })));
97
+
98
+ candidates.indexes.push(...parsed.indexes.map((index) => makeCandidateRecord({
99
+ kind: "index",
100
+ idHint: index.id_hint || idHintify(index.entity),
101
+ label: titleCase((index.id_hint || index.entity || "").replace(/^index_/, "")),
102
+ confidence: "medium",
103
+ sourceKind: "schema",
104
+ provenance,
105
+ entity: index.entity,
106
+ fields: index.fields,
107
+ unique: index.unique,
108
+ track: "db"
109
+ })));
110
+ }
111
+
112
+ for (const filePath of mapperFiles) {
113
+ const text = context.helpers.readTextIfExists(filePath) || "";
114
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
115
+ const namespace = text.match(/<mapper\s+namespace="([^"]+)"/)?.[1] || "";
116
+ const mapperStem = namespace.split(".").pop()?.replace(/Mapper$|ReadService$/i, "") || filePath.split("/").pop()?.replace(/\.xml$/, "") || "";
117
+ const tableMatches = [...text.matchAll(/\b(?:from|into|update|join)\s+([a-z_][a-z0-9_]*)\b/gi)].map((entry) => entry[1]);
118
+ for (const tableName of tableMatches) {
119
+ if (!isUsableMapperTableName(tableName)) continue;
120
+ if (seenTableNames.has(tableName)) continue;
121
+ const stem = canonicalCandidateTerm(tableName);
122
+ const noise = classifyNoiseEntity(tableName, []);
123
+ candidates.entities.push(makeCandidateRecord({
124
+ kind: "entity",
125
+ idHint: `entity_${slugify(stem)}`,
126
+ label: titleCase(mapperStem || stem),
127
+ confidence: "medium",
128
+ sourceKind: "mapper_code",
129
+ provenance,
130
+ table_name: tableName,
131
+ fields: [],
132
+ noise_candidate: noise.noise_candidate,
133
+ noise_reason: noise.noise_reason,
134
+ track: "db"
135
+ }));
136
+ seenTableNames.add(tableName);
137
+ }
138
+ }
139
+
140
+ candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
141
+ candidates.relations = dedupeCandidateRecords(candidates.relations, (record) => record.id_hint);
142
+ candidates.indexes = dedupeCandidateRecords(candidates.indexes, (record) => record.id_hint);
143
+ return { findings, candidates };
144
+ }
145
+ };
@@ -0,0 +1,185 @@
1
+ import {
2
+ findImportFiles,
3
+ makeCandidateRecord,
4
+ normalizePrismaType,
5
+ relativeTo,
6
+ selectPreferredImportFiles,
7
+ slugify,
8
+ titleCase,
9
+ idHintify
10
+ } from "../../core/shared.js";
11
+
12
+ function parsePrismaSchema(schemaText) {
13
+ const enums = [];
14
+ const entities = [];
15
+ const relations = [];
16
+ const indexes = [];
17
+ const enumNames = new Set();
18
+ const modelNames = [];
19
+
20
+ for (const match of schemaText.matchAll(/^enum\s+([A-Za-z0-9_]+)\s*\{([\s\S]*?)^\}/gm)) {
21
+ const [, enumName, body] = match;
22
+ const values = body
23
+ .split(/\r?\n/)
24
+ .map((line) => line.replace(/\/\/.*$/, "").trim())
25
+ .filter((line) => line && !line.startsWith("@@"))
26
+ .map((line) => line.split(/\s+/)[0]);
27
+ enumNames.add(enumName);
28
+ enums.push({ name: enumName, values });
29
+ }
30
+
31
+ for (const match of schemaText.matchAll(/^model\s+([A-Za-z0-9_]+)\s*\{/gm)) {
32
+ modelNames.push(match[1]);
33
+ }
34
+ const modelNameSet = new Set(modelNames);
35
+
36
+ for (const match of schemaText.matchAll(/^model\s+([A-Za-z0-9_]+)\s*\{([\s\S]*?)^\}/gm)) {
37
+ const [, modelName, body] = match;
38
+ const fields = [];
39
+ const localIndexes = [];
40
+ const lines = body
41
+ .split(/\r?\n/)
42
+ .map((line) => line.replace(/\/\/.*$/, "").trim())
43
+ .filter(Boolean);
44
+
45
+ for (const line of lines) {
46
+ if (line.startsWith("@@")) {
47
+ const indexMatch = line.match(/^@@(unique|index)\(\[([^\]]+)\]/);
48
+ if (indexMatch) {
49
+ const [, type, rawFields] = indexMatch;
50
+ localIndexes.push({
51
+ id_hint: `index_${slugify(`${modelName}_${rawFields}`)}`,
52
+ fields: rawFields.split(",").map((field) => field.trim()),
53
+ unique: type === "unique"
54
+ });
55
+ }
56
+ continue;
57
+ }
58
+
59
+ const fieldMatch = line.match(/^([A-Za-z0-9_]+)\s+([^\s]+)(.*)$/);
60
+ if (!fieldMatch) continue;
61
+ const [, fieldName, rawTypeToken, remainder] = fieldMatch;
62
+ const list = rawTypeToken.endsWith("[]");
63
+ const optional = rawTypeToken.endsWith("?");
64
+ const baseType = rawTypeToken.replace(/\?|\[\]/g, "");
65
+ const referencesModel = modelNameSet.has(baseType) && !enumNames.has(baseType);
66
+ const hasRelationDirective = remainder.includes("@relation(");
67
+
68
+ if (referencesModel && hasRelationDirective) {
69
+ const relationMatch = remainder.match(/@relation\(([^)]*)\)/);
70
+ const relationArgs = relationMatch?.[1] || "";
71
+ const fieldsMatch = relationArgs.match(/fields:\s*\[([^\]]+)\]/);
72
+ const refsMatch = relationArgs.match(/references:\s*\[([^\]]+)\]/);
73
+ relations.push({
74
+ from_entity: `entity_${slugify(modelName)}`,
75
+ to_entity: `entity_${slugify(baseType)}`,
76
+ relation_field: fieldName,
77
+ fields: fieldsMatch ? fieldsMatch[1].split(",").map((field) => field.trim()) : [],
78
+ references: refsMatch ? refsMatch[1].split(",").map((field) => field.trim()) : []
79
+ });
80
+ continue;
81
+ }
82
+
83
+ if (referencesModel) continue;
84
+
85
+ const fieldType = enumNames.has(baseType) ? baseType : normalizePrismaType(baseType);
86
+ fields.push({
87
+ name: fieldName,
88
+ field_type: fieldType,
89
+ required: !optional && !list,
90
+ list,
91
+ unique: /@unique\b/.test(remainder),
92
+ primary_key: /@id\b/.test(remainder)
93
+ });
94
+
95
+ if (/@unique\b/.test(remainder)) {
96
+ localIndexes.push({
97
+ id_hint: `index_${slugify(`${modelName}_${fieldName}_unique`)}`,
98
+ fields: [fieldName],
99
+ unique: true
100
+ });
101
+ }
102
+ }
103
+
104
+ entities.push({ name: modelName, fields });
105
+ indexes.push(...localIndexes.map((index) => ({ ...index, entity: `entity_${slugify(modelName)}` })));
106
+ }
107
+
108
+ return { entities, enums, relations, indexes };
109
+ }
110
+
111
+ export const prismaExtractor = {
112
+ id: "db.prisma",
113
+ track: "db",
114
+ detect(context) {
115
+ const files = findImportFiles(context.paths, (filePath) => filePath.endsWith("/prisma/schema.prisma") || filePath.endsWith("prisma/schema.prisma"));
116
+ return {
117
+ score: files.length > 0 ? 100 : 0,
118
+ reasons: files.length > 0 ? ["Found Prisma schema"] : []
119
+ };
120
+ },
121
+ extract(context) {
122
+ const prismaFiles = selectPreferredImportFiles(
123
+ context.paths,
124
+ findImportFiles(context.paths, (filePath) => filePath.endsWith("/prisma/schema.prisma") || filePath.endsWith("prisma/schema.prisma")),
125
+ "prisma"
126
+ );
127
+ const findings = [];
128
+ const candidates = { entities: [], enums: [], relations: [], indexes: [] };
129
+ for (const filePath of prismaFiles) {
130
+ const parsed = parsePrismaSchema(context.helpers.readTextIfExists(filePath) || "");
131
+ const provenance = relativeTo(context.paths.repoRoot, filePath);
132
+ findings.push({
133
+ kind: "prisma_schema",
134
+ file: provenance,
135
+ entity_count: parsed.entities.length,
136
+ enum_count: parsed.enums.length
137
+ });
138
+ candidates.entities.push(...parsed.entities.map((entity) => makeCandidateRecord({
139
+ kind: "entity",
140
+ idHint: `entity_${slugify(entity.name)}`,
141
+ label: titleCase(entity.name),
142
+ confidence: "high",
143
+ sourceKind: "schema",
144
+ provenance,
145
+ table_name: slugify(entity.table_name || entity.name),
146
+ fields: entity.fields,
147
+ track: "db"
148
+ })));
149
+ candidates.enums.push(...parsed.enums.map((entry) => makeCandidateRecord({
150
+ kind: "enum",
151
+ idHint: idHintify(entry.name),
152
+ label: titleCase(entry.name),
153
+ confidence: "high",
154
+ sourceKind: "schema",
155
+ provenance,
156
+ values: entry.values,
157
+ track: "db"
158
+ })));
159
+ candidates.relations.push(...parsed.relations.map((relation) => makeCandidateRecord({
160
+ kind: "relation",
161
+ idHint: slugify(`${relation.from_entity}_${relation.relation_field}_${relation.to_entity}`),
162
+ label: `${relation.from_entity} -> ${relation.to_entity}`,
163
+ confidence: "high",
164
+ sourceKind: "schema",
165
+ provenance,
166
+ ...relation,
167
+ track: "db"
168
+ })));
169
+ candidates.indexes.push(...parsed.indexes.map((index) => makeCandidateRecord({
170
+ kind: "index",
171
+ idHint: index.id_hint,
172
+ label: titleCase(index.id_hint.replace(/^index_/, "")),
173
+ confidence: "medium",
174
+ sourceKind: "schema",
175
+ provenance,
176
+ entity: index.entity,
177
+ fields: index.fields,
178
+ unique: index.unique,
179
+ track: "db"
180
+ })));
181
+ }
182
+ return { findings, candidates };
183
+ }
184
+ };
185
+