@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.
- package/ARCHITECTURE.md +67 -0
- package/CHANGELOG.md +240 -0
- package/README.md +223 -0
- package/package.json +51 -0
- package/src/adoption/index.js +3 -0
- package/src/adoption/plan.js +702 -0
- package/src/adoption/reporting.js +464 -0
- package/src/adoption/review-groups.js +313 -0
- package/src/agent-ops/query-builders.js +5012 -0
- package/src/archive/archive.js +141 -0
- package/src/archive/compact.js +26 -0
- package/src/archive/jsonl.js +70 -0
- package/src/archive/resolver-bridge.js +82 -0
- package/src/archive/schema.js +87 -0
- package/src/archive/unarchive.js +108 -0
- package/src/catalog.js +752 -0
- package/src/cli/catalog-alias.js +166 -0
- package/src/cli.js +9738 -0
- package/src/component-behavior.js +173 -0
- package/src/example-implementation.js +91 -0
- package/src/format.js +19 -0
- package/src/generator/adapters.d.ts +4 -0
- package/src/generator/adapters.js +325 -0
- package/src/generator/api.d.ts +1 -0
- package/src/generator/api.js +1196 -0
- package/src/generator/check.js +355 -0
- package/src/generator/component-conformance.js +767 -0
- package/src/generator/components.js +39 -0
- package/src/generator/context/bundle.js +291 -0
- package/src/generator/context/diff.js +256 -0
- package/src/generator/context/digest.js +182 -0
- package/src/generator/context/domain-coverage.js +94 -0
- package/src/generator/context/domain-page.js +137 -0
- package/src/generator/context/index.js +42 -0
- package/src/generator/context/report.js +121 -0
- package/src/generator/context/shared.js +1397 -0
- package/src/generator/context/slice.js +703 -0
- package/src/generator/context/task-mode.js +466 -0
- package/src/generator/docs.js +327 -0
- package/src/generator/index.js +161 -0
- package/src/generator/native/parity-bundle.js +311 -0
- package/src/generator/output.js +300 -0
- package/src/generator/registry.js +482 -0
- package/src/generator/runtime/app-bundle.js +456 -0
- package/src/generator/runtime/bundle-shared.js +166 -0
- package/src/generator/runtime/compile-check.js +163 -0
- package/src/generator/runtime/deployment.js +287 -0
- package/src/generator/runtime/environment.js +635 -0
- package/src/generator/runtime/index.js +32 -0
- package/src/generator/runtime/runtime-check.js +554 -0
- package/src/generator/runtime/shared.js +515 -0
- package/src/generator/runtime/smoke.js +219 -0
- package/src/generator/schema.js +204 -0
- package/src/generator/sdlc/board.js +66 -0
- package/src/generator/sdlc/doc-page.js +53 -0
- package/src/generator/sdlc/index.js +23 -0
- package/src/generator/sdlc/release-notes.js +62 -0
- package/src/generator/sdlc/traceability-matrix.js +65 -0
- package/src/generator/shared.js +29 -0
- package/src/generator/surfaces/contracts.js +146 -0
- package/src/generator/surfaces/databases/contract.js +40 -0
- package/src/generator/surfaces/databases/index.js +84 -0
- package/src/generator/surfaces/databases/lifecycle-shared.d.ts +1 -0
- package/src/generator/surfaces/databases/lifecycle-shared.js +612 -0
- package/src/generator/surfaces/databases/migration-plan.js +281 -0
- package/src/generator/surfaces/databases/postgres/capabilities.js +14 -0
- package/src/generator/surfaces/databases/postgres/drizzle.js +99 -0
- package/src/generator/surfaces/databases/postgres/index.js +9 -0
- package/src/generator/surfaces/databases/postgres/lifecycle.js +16 -0
- package/src/generator/surfaces/databases/postgres/prisma.js +159 -0
- package/src/generator/surfaces/databases/postgres/sql-migration.js +102 -0
- package/src/generator/surfaces/databases/postgres/sql-schema.js +34 -0
- package/src/generator/surfaces/databases/shared.d.ts +1 -0
- package/src/generator/surfaces/databases/shared.js +350 -0
- package/src/generator/surfaces/databases/snapshot.js +96 -0
- package/src/generator/surfaces/databases/sqlite/capabilities.js +14 -0
- package/src/generator/surfaces/databases/sqlite/index.js +8 -0
- package/src/generator/surfaces/databases/sqlite/lifecycle.js +16 -0
- package/src/generator/surfaces/databases/sqlite/prisma.js +143 -0
- package/src/generator/surfaces/databases/sqlite/sql-migration.js +65 -0
- package/src/generator/surfaces/databases/sqlite/sql-schema.js +27 -0
- package/src/generator/surfaces/index.js +25 -0
- package/src/generator/surfaces/native/swiftui-app.js +38 -0
- package/src/generator/surfaces/native/swiftui-templates/Package.swift.txt +20 -0
- package/src/generator/surfaces/native/swiftui-templates/README.generated.md +26 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/DynamicScreens.swift +682 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/TodoAPIClient.swift +156 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/TodoSwiftUIApp.swift +44 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/Visibility.swift +183 -0
- package/src/generator/surfaces/services/express.d.ts +1 -0
- package/src/generator/surfaces/services/express.js +766 -0
- package/src/generator/surfaces/services/hono.d.ts +1 -0
- package/src/generator/surfaces/services/hono.js +204 -0
- package/src/generator/surfaces/services/index.js +42 -0
- package/src/generator/surfaces/services/persistence-wiring.js +240 -0
- package/src/generator/surfaces/services/runtime-helpers.js +631 -0
- package/src/generator/surfaces/services/server-contract.js +80 -0
- package/src/generator/surfaces/services/stateless.d.ts +1 -0
- package/src/generator/surfaces/services/stateless.js +97 -0
- package/src/generator/surfaces/shared.js +64 -0
- package/src/generator/surfaces/web/api-client.js +1 -0
- package/src/generator/surfaces/web/forms.js +1 -0
- package/src/generator/surfaces/web/index.d.ts +2 -0
- package/src/generator/surfaces/web/index.js +53 -0
- package/src/generator/surfaces/web/react-components.js +248 -0
- package/src/generator/surfaces/web/react.js +538 -0
- package/src/generator/surfaces/web/routes.js +1 -0
- package/src/generator/surfaces/web/screens.js +1 -0
- package/src/generator/surfaces/web/shared.js +369 -0
- package/src/generator/surfaces/web/sveltekit-actions.js +28 -0
- package/src/generator/surfaces/web/sveltekit-components.js +234 -0
- package/src/generator/surfaces/web/sveltekit.js +426 -0
- package/src/generator/surfaces/web/ui-web-contract.js +65 -0
- package/src/generator/surfaces/web/vanilla.js +239 -0
- package/src/generator/verification.js +84 -0
- package/src/generator.js +1 -0
- package/src/import/core/context.js +52 -0
- package/src/import/core/contracts.js +23 -0
- package/src/import/core/registry.js +81 -0
- package/src/import/core/runner.js +646 -0
- package/src/import/core/shared.js +910 -0
- package/src/import/enrichers/auth-session.js +18 -0
- package/src/import/enrichers/django-rest.js +226 -0
- package/src/import/enrichers/doc-linking.js +20 -0
- package/src/import/enrichers/rails-controllers.js +246 -0
- package/src/import/enrichers/rails-models.js +130 -0
- package/src/import/enrichers/workflow-target-state.js +10 -0
- package/src/import/extractors/api/aspnet-core.js +304 -0
- package/src/import/extractors/api/django-routes.js +318 -0
- package/src/import/extractors/api/express.js +154 -0
- package/src/import/extractors/api/fastify.js +371 -0
- package/src/import/extractors/api/flutter-dio.js +135 -0
- package/src/import/extractors/api/generic-route-fallback.js +90 -0
- package/src/import/extractors/api/graphql-code-first.js +565 -0
- package/src/import/extractors/api/graphql-sdl.js +309 -0
- package/src/import/extractors/api/jaxrs.js +303 -0
- package/src/import/extractors/api/micronaut.js +213 -0
- package/src/import/extractors/api/next-route.js +50 -0
- package/src/import/extractors/api/next-server-action.js +51 -0
- package/src/import/extractors/api/nextauth.js +52 -0
- package/src/import/extractors/api/openapi-code.js +242 -0
- package/src/import/extractors/api/openapi.js +232 -0
- package/src/import/extractors/api/rails-routes.js +230 -0
- package/src/import/extractors/api/react-native-repository.js +128 -0
- package/src/import/extractors/api/retrofit.js +103 -0
- package/src/import/extractors/api/spring-web.js +372 -0
- package/src/import/extractors/api/swift-webapi.js +116 -0
- package/src/import/extractors/api/trpc.js +212 -0
- package/src/import/extractors/db/django-models.js +232 -0
- package/src/import/extractors/db/dotnet-models.js +93 -0
- package/src/import/extractors/db/drizzle.js +242 -0
- package/src/import/extractors/db/ef-core.js +221 -0
- package/src/import/extractors/db/flutter-entities.js +120 -0
- package/src/import/extractors/db/jpa.js +120 -0
- package/src/import/extractors/db/liquibase.js +180 -0
- package/src/import/extractors/db/mybatis-xml.js +145 -0
- package/src/import/extractors/db/prisma.js +185 -0
- package/src/import/extractors/db/rails-schema.js +175 -0
- package/src/import/extractors/db/react-native-entities.js +95 -0
- package/src/import/extractors/db/room.js +193 -0
- package/src/import/extractors/db/snapshot.js +112 -0
- package/src/import/extractors/db/sql.js +180 -0
- package/src/import/extractors/db/swiftdata.js +137 -0
- package/src/import/extractors/ui/android-compose.js +230 -0
- package/src/import/extractors/ui/backend-only.js +70 -0
- package/src/import/extractors/ui/blazor.js +227 -0
- package/src/import/extractors/ui/flutter-screens.js +152 -0
- package/src/import/extractors/ui/maui-xaml.js +135 -0
- package/src/import/extractors/ui/next-app-router.js +83 -0
- package/src/import/extractors/ui/next-pages-router.js +141 -0
- package/src/import/extractors/ui/razor-pages.js +181 -0
- package/src/import/extractors/ui/react-native-screens.js +166 -0
- package/src/import/extractors/ui/react-router.js +139 -0
- package/src/import/extractors/ui/sveltekit.js +123 -0
- package/src/import/extractors/ui/swiftui.js +193 -0
- package/src/import/extractors/ui/uikit.js +175 -0
- package/src/import/extractors/verification/generic.js +290 -0
- package/src/import/extractors/workflows/generic.js +137 -0
- package/src/import/index.js +7 -0
- package/src/import/provenance.js +158 -0
- package/src/new-project.js +2107 -0
- package/src/parser.js +439 -0
- package/src/policy/review-boundaries.js +165 -0
- package/src/project-config.js +535 -0
- package/src/proofs/backend-parity.js +19 -0
- package/src/proofs/contract-audit.js +220 -0
- package/src/proofs/ios-parity.js +7 -0
- package/src/proofs/issues-parity.js +10 -0
- package/src/proofs/web-parity.js +50 -0
- package/src/realization/api/build-api-realization.js +5 -0
- package/src/realization/api/index.js +1 -0
- package/src/realization/backend/build-backend-runtime-realization.js +82 -0
- package/src/realization/backend/index.d.ts +1 -0
- package/src/realization/backend/index.js +4 -0
- package/src/realization/db/build-db-realization.js +17 -0
- package/src/realization/db/index.js +3 -0
- package/src/realization/db/migration-plan.js +5 -0
- package/src/realization/db/snapshot.js +5 -0
- package/src/realization/ui/build-ui-shared-realization.js +305 -0
- package/src/realization/ui/build-web-realization.js +189 -0
- package/src/realization/ui/index.js +2 -0
- package/src/reconcile/docs.js +280 -0
- package/src/reconcile/index.js +3 -0
- package/src/reconcile/journeys.js +441 -0
- package/src/resolver/docs.js +1 -0
- package/src/resolver/enrich/acceptance-criterion.js +14 -0
- package/src/resolver/enrich/bug.js +12 -0
- package/src/resolver/enrich/component.js +2 -0
- package/src/resolver/enrich/index.js +1 -0
- package/src/resolver/enrich/pitch.js +18 -0
- package/src/resolver/enrich/requirement.js +20 -0
- package/src/resolver/enrich/task.js +16 -0
- package/src/resolver/expressions.js +1 -0
- package/src/resolver/index.js +2422 -0
- package/src/resolver/normalize.js +1 -0
- package/src/resolver.js +1 -0
- package/src/sdlc/adopt.js +65 -0
- package/src/sdlc/check.js +86 -0
- package/src/sdlc/dod/acceptance-criterion.js +22 -0
- package/src/sdlc/dod/bug.js +26 -0
- package/src/sdlc/dod/document.js +23 -0
- package/src/sdlc/dod/index.js +25 -0
- package/src/sdlc/dod/pitch.js +23 -0
- package/src/sdlc/dod/requirement.js +34 -0
- package/src/sdlc/dod/task.js +39 -0
- package/src/sdlc/explain.js +116 -0
- package/src/sdlc/history.js +80 -0
- package/src/sdlc/paths.js +11 -0
- package/src/sdlc/release.js +106 -0
- package/src/sdlc/scaffold.js +89 -0
- package/src/sdlc/status-filter.js +54 -0
- package/src/sdlc/transition.js +112 -0
- package/src/sdlc/transitions/acceptance-criterion.js +28 -0
- package/src/sdlc/transitions/bug.js +31 -0
- package/src/sdlc/transitions/document.js +29 -0
- package/src/sdlc/transitions/index.js +56 -0
- package/src/sdlc/transitions/pitch.js +34 -0
- package/src/sdlc/transitions/requirement.js +31 -0
- package/src/sdlc/transitions/task.js +34 -0
- package/src/template-trust.js +597 -0
- package/src/validator/expressions.js +1 -0
- package/src/validator/index.js +3424 -0
- package/src/validator/kinds.js +346 -0
- package/src/validator/per-kind/acceptance-criterion.js +91 -0
- package/src/validator/per-kind/bug.js +77 -0
- package/src/validator/per-kind/component.js +274 -0
- package/src/validator/per-kind/domain.js +205 -0
- package/src/validator/per-kind/pitch.js +101 -0
- package/src/validator/per-kind/requirement.js +75 -0
- package/src/validator/per-kind/task.js +96 -0
- package/src/validator/registry.js +1 -0
- package/src/validator/utils.js +12 -0
- package/src/validator.js +1 -0
- package/src/workflows.js +7597 -0
- package/src/workspace-docs.js +265 -0
- package/template-helpers/react.js +5 -0
- package/template-helpers/sveltekit.js +5 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
canonicalCandidateTerm,
|
|
5
|
+
dedupeCandidateRecords,
|
|
6
|
+
findImportFiles,
|
|
7
|
+
idHintify,
|
|
8
|
+
makeCandidateRecord,
|
|
9
|
+
relativeTo,
|
|
10
|
+
slugify,
|
|
11
|
+
titleCase
|
|
12
|
+
} from "../../core/shared.js";
|
|
13
|
+
|
|
14
|
+
function splitTopLevelEntries(block) {
|
|
15
|
+
const entries = [];
|
|
16
|
+
let current = "";
|
|
17
|
+
let depth = 0;
|
|
18
|
+
let inString = false;
|
|
19
|
+
let stringQuote = null;
|
|
20
|
+
for (let index = 0; index < block.length; index += 1) {
|
|
21
|
+
const char = block[index];
|
|
22
|
+
const prev = block[index - 1];
|
|
23
|
+
if (inString) {
|
|
24
|
+
current += char;
|
|
25
|
+
if (char === stringQuote && prev !== "\\") {
|
|
26
|
+
inString = false;
|
|
27
|
+
stringQuote = null;
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (char === "'" || char === '"' || char === "`") {
|
|
32
|
+
inString = true;
|
|
33
|
+
stringQuote = char;
|
|
34
|
+
current += char;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (char === "{" || char === "[" || char === "(") {
|
|
38
|
+
depth += 1;
|
|
39
|
+
current += char;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (char === "}" || char === "]" || char === ")") {
|
|
43
|
+
depth -= 1;
|
|
44
|
+
current += char;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (char === "," && depth === 0) {
|
|
48
|
+
if (current.trim()) entries.push(current.trim());
|
|
49
|
+
current = "";
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
current += char;
|
|
53
|
+
}
|
|
54
|
+
if (current.trim()) entries.push(current.trim());
|
|
55
|
+
return entries;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function parseDrizzleFieldType(rawExpression) {
|
|
59
|
+
const expression = String(rawExpression || "");
|
|
60
|
+
const typeMatch = expression.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(/);
|
|
61
|
+
const fieldType = typeMatch ? typeMatch[1] : "unknown";
|
|
62
|
+
const enumMatch = expression.match(/\benum:\s*\[([^\]]+)\]/);
|
|
63
|
+
const enumValues = enumMatch
|
|
64
|
+
? enumMatch[1]
|
|
65
|
+
.split(",")
|
|
66
|
+
.map((entry) => entry.trim().replace(/^["'`]|["'`]$/g, ""))
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
: [];
|
|
69
|
+
const referencesMatch = expression.match(/\.references\s*\(\s*\(\s*\)\s*=>\s*([A-Za-z_][A-Za-z0-9_]*)\.([A-Za-z_][A-Za-z0-9_]*)/);
|
|
70
|
+
return {
|
|
71
|
+
field_type: fieldType,
|
|
72
|
+
enum_values: enumValues,
|
|
73
|
+
required: /\.notNull\s*\(/.test(expression),
|
|
74
|
+
unique: /\.unique\s*\(/.test(expression),
|
|
75
|
+
primary_key: /\.primaryKey\s*\(/.test(expression),
|
|
76
|
+
references: referencesMatch
|
|
77
|
+
? {
|
|
78
|
+
target_table_symbol: referencesMatch[1],
|
|
79
|
+
target_field: referencesMatch[2]
|
|
80
|
+
}
|
|
81
|
+
: null
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function parseDrizzleTables(schemaText) {
|
|
86
|
+
const entities = [];
|
|
87
|
+
const enums = [];
|
|
88
|
+
const relations = [];
|
|
89
|
+
const indexes = [];
|
|
90
|
+
const tableSymbolToEntity = new Map();
|
|
91
|
+
const enumRegistry = new Map();
|
|
92
|
+
|
|
93
|
+
for (const match of schemaText.matchAll(/export\s+const\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*pgTable\s*\(\s*["'`]([^"'`]+)["'`]\s*,\s*\{([\s\S]*?)\}\s*(?:,\s*\(([^)]*?)\)\s*=>\s*\(\{([\s\S]*?)\}\))?\s*\)/g)) {
|
|
94
|
+
const [, tableSymbol, tableName, rawFieldsBlock, _tableArgs, rawIndexesBlock = ""] = match;
|
|
95
|
+
const entityStem = canonicalCandidateTerm(tableName);
|
|
96
|
+
const entityId = `entity_${entityStem}`;
|
|
97
|
+
const fields = [];
|
|
98
|
+
tableSymbolToEntity.set(tableSymbol, entityId);
|
|
99
|
+
|
|
100
|
+
for (const entry of splitTopLevelEntries(rawFieldsBlock)) {
|
|
101
|
+
const fieldMatch = entry.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([\s\S]+)$/);
|
|
102
|
+
if (!fieldMatch) continue;
|
|
103
|
+
const [, fieldName, rawExpression] = fieldMatch;
|
|
104
|
+
const parsedField = parseDrizzleFieldType(rawExpression);
|
|
105
|
+
fields.push({
|
|
106
|
+
name: fieldName,
|
|
107
|
+
field_type: parsedField.field_type,
|
|
108
|
+
required: parsedField.required || parsedField.primary_key,
|
|
109
|
+
list: false,
|
|
110
|
+
unique: parsedField.unique,
|
|
111
|
+
primary_key: parsedField.primary_key
|
|
112
|
+
});
|
|
113
|
+
if (parsedField.enum_values.length > 0) {
|
|
114
|
+
const enumId = `${entityStem}_${canonicalCandidateTerm(fieldName)}`;
|
|
115
|
+
if (!enumRegistry.has(enumId)) {
|
|
116
|
+
enumRegistry.set(enumId, {
|
|
117
|
+
id_hint: enumId,
|
|
118
|
+
label: titleCase(enumId),
|
|
119
|
+
values: parsedField.enum_values
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
fields[fields.length - 1].field_type = enumId;
|
|
123
|
+
}
|
|
124
|
+
if (parsedField.references) {
|
|
125
|
+
relations.push({
|
|
126
|
+
from_entity: entityId,
|
|
127
|
+
to_entity_symbol: parsedField.references.target_table_symbol,
|
|
128
|
+
relation_field: fieldName,
|
|
129
|
+
fields: [fieldName],
|
|
130
|
+
references: [parsedField.references.target_field]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
for (const indexEntry of splitTopLevelEntries(rawIndexesBlock)) {
|
|
136
|
+
const indexMatch = indexEntry.match(/([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(unique|index)\s*\(\s*["'`]([^"'`]+)["'`]\s*\)\.on\(([\s\S]+)\)$/);
|
|
137
|
+
if (!indexMatch) continue;
|
|
138
|
+
const [, , indexType, indexName, rawColumns] = indexMatch;
|
|
139
|
+
const fieldsForIndex = [...rawColumns.matchAll(/table\.([A-Za-z_][A-Za-z0-9_]*)/g)].map((entry) => entry[1]);
|
|
140
|
+
indexes.push({
|
|
141
|
+
id_hint: idHintify(indexName),
|
|
142
|
+
entity: entityId,
|
|
143
|
+
fields: fieldsForIndex,
|
|
144
|
+
unique: indexType === "unique"
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
entities.push({
|
|
149
|
+
name: entityStem,
|
|
150
|
+
table_name: tableName,
|
|
151
|
+
fields
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (const relation of relations) {
|
|
156
|
+
relation.to_entity = tableSymbolToEntity.get(relation.to_entity_symbol) || `entity_${canonicalCandidateTerm(relation.to_entity_symbol)}`;
|
|
157
|
+
delete relation.to_entity_symbol;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
entities,
|
|
162
|
+
enums: [...enumRegistry.values()],
|
|
163
|
+
relations,
|
|
164
|
+
indexes
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export const drizzleExtractor = {
|
|
169
|
+
id: "db.drizzle",
|
|
170
|
+
track: "db",
|
|
171
|
+
detect(context) {
|
|
172
|
+
const hasConfig = findImportFiles(context.paths, (filePath) => /drizzle\.config\.(ts|js|mjs|cjs)$/i.test(path.basename(filePath))).length > 0;
|
|
173
|
+
const hasSchema = findImportFiles(context.paths, (filePath) => /src\/schema\.(ts|js|mjs|cjs)$/i.test(filePath)).length > 0;
|
|
174
|
+
return {
|
|
175
|
+
score: hasConfig || hasSchema ? 95 : 0,
|
|
176
|
+
reasons: hasConfig || hasSchema ? ["Found Drizzle config/schema source"] : []
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
extract(context) {
|
|
180
|
+
const schemaFiles = findImportFiles(context.paths, (filePath) => /src\/schema\.(ts|js|mjs|cjs)$/i.test(filePath));
|
|
181
|
+
const findings = [];
|
|
182
|
+
const candidates = { entities: [], enums: [], relations: [], indexes: [] };
|
|
183
|
+
for (const filePath of schemaFiles) {
|
|
184
|
+
const parsed = parseDrizzleTables(context.helpers.readTextIfExists(filePath) || "");
|
|
185
|
+
const provenance = relativeTo(context.paths.repoRoot, filePath);
|
|
186
|
+
findings.push({
|
|
187
|
+
kind: "drizzle_schema",
|
|
188
|
+
file: provenance,
|
|
189
|
+
entity_count: parsed.entities.length,
|
|
190
|
+
enum_count: parsed.enums.length
|
|
191
|
+
});
|
|
192
|
+
candidates.entities.push(...parsed.entities.map((entity) => makeCandidateRecord({
|
|
193
|
+
kind: "entity",
|
|
194
|
+
idHint: `entity_${slugify(entity.name)}`,
|
|
195
|
+
label: titleCase(entity.name),
|
|
196
|
+
confidence: "high",
|
|
197
|
+
sourceKind: "schema",
|
|
198
|
+
provenance,
|
|
199
|
+
table_name: entity.table_name,
|
|
200
|
+
fields: entity.fields,
|
|
201
|
+
track: "db"
|
|
202
|
+
})));
|
|
203
|
+
candidates.enums.push(...parsed.enums.map((entry) => makeCandidateRecord({
|
|
204
|
+
kind: "enum",
|
|
205
|
+
idHint: entry.id_hint,
|
|
206
|
+
label: entry.label,
|
|
207
|
+
confidence: "high",
|
|
208
|
+
sourceKind: "schema",
|
|
209
|
+
provenance,
|
|
210
|
+
values: entry.values,
|
|
211
|
+
track: "db"
|
|
212
|
+
})));
|
|
213
|
+
candidates.relations.push(...parsed.relations.map((relation) => makeCandidateRecord({
|
|
214
|
+
kind: "relation",
|
|
215
|
+
idHint: slugify(`${relation.from_entity}_${relation.relation_field}_${relation.to_entity}`),
|
|
216
|
+
label: `${relation.from_entity} -> ${relation.to_entity}`,
|
|
217
|
+
confidence: "high",
|
|
218
|
+
sourceKind: "schema",
|
|
219
|
+
provenance,
|
|
220
|
+
...relation,
|
|
221
|
+
track: "db"
|
|
222
|
+
})));
|
|
223
|
+
candidates.indexes.push(...parsed.indexes.map((index) => makeCandidateRecord({
|
|
224
|
+
kind: "index",
|
|
225
|
+
idHint: index.id_hint,
|
|
226
|
+
label: titleCase(index.id_hint.replace(/^index_/, "")),
|
|
227
|
+
confidence: "medium",
|
|
228
|
+
sourceKind: "schema",
|
|
229
|
+
provenance,
|
|
230
|
+
entity: index.entity,
|
|
231
|
+
fields: index.fields,
|
|
232
|
+
unique: index.unique,
|
|
233
|
+
track: "db"
|
|
234
|
+
})));
|
|
235
|
+
}
|
|
236
|
+
candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
|
|
237
|
+
candidates.enums = dedupeCandidateRecords(candidates.enums, (record) => record.id_hint);
|
|
238
|
+
candidates.relations = dedupeCandidateRecords(candidates.relations, (record) => record.id_hint);
|
|
239
|
+
candidates.indexes = dedupeCandidateRecords(candidates.indexes, (record) => record.id_hint);
|
|
240
|
+
return { findings, candidates };
|
|
241
|
+
}
|
|
242
|
+
};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalCandidateTerm,
|
|
3
|
+
dedupeCandidateRecords,
|
|
4
|
+
findImportFiles,
|
|
5
|
+
makeCandidateRecord,
|
|
6
|
+
readTextIfExists,
|
|
7
|
+
relativeTo,
|
|
8
|
+
titleCase
|
|
9
|
+
} from "../../core/shared.js";
|
|
10
|
+
|
|
11
|
+
function splitClassBlocks(text) {
|
|
12
|
+
const lines = String(text || "").split(/\r?\n/);
|
|
13
|
+
const blocks = [];
|
|
14
|
+
let current = null;
|
|
15
|
+
|
|
16
|
+
for (const line of lines) {
|
|
17
|
+
const match = line.match(/^public\s+class\s+([A-Za-z_][A-Za-z0-9_]*)\b/);
|
|
18
|
+
if (match) {
|
|
19
|
+
if (current) blocks.push(current);
|
|
20
|
+
current = { name: match[1], lines: [line] };
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (current) current.lines.push(line);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (current) blocks.push(current);
|
|
27
|
+
return blocks;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function parseProperties(block) {
|
|
31
|
+
const properties = [];
|
|
32
|
+
const notMapped = new Set();
|
|
33
|
+
let pendingNotMapped = false;
|
|
34
|
+
|
|
35
|
+
for (const rawLine of block.lines.slice(1)) {
|
|
36
|
+
const line = rawLine.trim();
|
|
37
|
+
if (!line) continue;
|
|
38
|
+
if (/^\[NotMapped\]/.test(line)) {
|
|
39
|
+
pendingNotMapped = true;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const match = line.match(/^public\s+([A-Za-z0-9_<>\[\]\?., ]+)\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{/);
|
|
43
|
+
if (!match) continue;
|
|
44
|
+
const [, typeName, name] = match;
|
|
45
|
+
properties.push({ name, typeName: typeName.trim(), notMapped: pendingNotMapped });
|
|
46
|
+
if (pendingNotMapped) {
|
|
47
|
+
notMapped.add(name);
|
|
48
|
+
pendingNotMapped = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return properties;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizeScalarType(typeName) {
|
|
56
|
+
const normalized = String(typeName || "").replace(/\?$/, "").trim();
|
|
57
|
+
if (["string", "byte[]"].includes(normalized)) return "string";
|
|
58
|
+
if (["int", "long", "short"].includes(normalized)) return "int";
|
|
59
|
+
if (["bool", "boolean"].includes(normalized.toLowerCase())) return "boolean";
|
|
60
|
+
if (["DateTime", "DateTimeOffset"].includes(normalized)) return "datetime";
|
|
61
|
+
return normalized;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function unwrapListType(typeName) {
|
|
65
|
+
const listMatch = String(typeName || "").match(/List<([^>]+)>/);
|
|
66
|
+
return listMatch ? listMatch[1].trim() : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function domainEntityInfo(name, properties, trackedNames) {
|
|
70
|
+
const scalarFields = [];
|
|
71
|
+
const relations = [];
|
|
72
|
+
|
|
73
|
+
const entityStem =
|
|
74
|
+
name === "Person" ? "user" :
|
|
75
|
+
canonicalCandidateTerm(name);
|
|
76
|
+
|
|
77
|
+
const entityId = `entity_${entityStem}`;
|
|
78
|
+
|
|
79
|
+
const scalarLike = (typeName) => {
|
|
80
|
+
const base = String(typeName || "").replace(/\?$/, "").trim();
|
|
81
|
+
return ["string", "int", "long", "short", "bool", "byte[]", "DateTime", "DateTimeOffset"].includes(base);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const scalarIdOnlyCount = properties.filter((property) => /Id$/.test(property.name)).length;
|
|
85
|
+
const relationReferenceCount = properties.filter((property) => {
|
|
86
|
+
const base = property.typeName.replace(/\?$/, "").trim();
|
|
87
|
+
return trackedNames.has(base) || trackedNames.has((unwrapListType(base) || "").trim());
|
|
88
|
+
}).length;
|
|
89
|
+
const relationOnlyEntity =
|
|
90
|
+
properties.length > 0 &&
|
|
91
|
+
scalarIdOnlyCount >= 2 &&
|
|
92
|
+
relationReferenceCount >= 2 &&
|
|
93
|
+
properties.every((property) => {
|
|
94
|
+
const base = property.typeName.replace(/\?$/, "").trim();
|
|
95
|
+
return /Id$/.test(property.name) || trackedNames.has(base) || trackedNames.has((unwrapListType(base) || "").trim());
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
for (const property of properties) {
|
|
99
|
+
if (property.notMapped) continue;
|
|
100
|
+
const baseType = property.typeName.replace(/\?$/, "").trim();
|
|
101
|
+
const listType = unwrapListType(baseType);
|
|
102
|
+
const required = !property.typeName.includes("?") && baseType !== "string" && baseType !== "byte[]";
|
|
103
|
+
|
|
104
|
+
if (scalarLike(baseType)) {
|
|
105
|
+
if (["Hash", "Salt"].includes(property.name)) continue;
|
|
106
|
+
scalarFields.push({
|
|
107
|
+
name: property.name.charAt(0).toLowerCase() + property.name.slice(1),
|
|
108
|
+
field_type: normalizeScalarType(baseType),
|
|
109
|
+
required: baseType !== "string" ? required : false,
|
|
110
|
+
list: false,
|
|
111
|
+
unique: ["Email", "Username", "Slug", "TagId"].includes(property.name),
|
|
112
|
+
primary_key: /Id$/.test(property.name) && [name, "Tag"].some((part) => property.name === `${part}Id`)
|
|
113
|
+
});
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (trackedNames.has(baseType)) {
|
|
118
|
+
relations.push({
|
|
119
|
+
from_entity: entityId,
|
|
120
|
+
to_entity: `entity_${baseType === "Person" ? "user" : canonicalCandidateTerm(baseType)}`,
|
|
121
|
+
relation_field: property.name.charAt(0).toLowerCase() + property.name.slice(1),
|
|
122
|
+
fields: [property.name.charAt(0).toLowerCase() + property.name.slice(1)],
|
|
123
|
+
references: ["id"],
|
|
124
|
+
relation_type: "reference"
|
|
125
|
+
});
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (listType && trackedNames.has(listType)) {
|
|
130
|
+
relations.push({
|
|
131
|
+
from_entity: entityId,
|
|
132
|
+
to_entity: `entity_${listType === "Person" ? "user" : canonicalCandidateTerm(listType)}`,
|
|
133
|
+
relation_field: property.name.charAt(0).toLowerCase() + property.name.slice(1),
|
|
134
|
+
fields: [property.name.charAt(0).toLowerCase() + property.name.slice(1)],
|
|
135
|
+
references: ["id"],
|
|
136
|
+
relation_type: "collection"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
entity: {
|
|
143
|
+
id_hint: entityId,
|
|
144
|
+
label: titleCase(entityStem),
|
|
145
|
+
model_name: name,
|
|
146
|
+
fields: scalarFields,
|
|
147
|
+
noise_candidate: relationOnlyEntity,
|
|
148
|
+
noise_reason: relationOnlyEntity ? "EF Core relationship-link entity inferred as implementation noise." : null
|
|
149
|
+
},
|
|
150
|
+
relations
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const efCoreExtractor = {
|
|
155
|
+
id: "db.ef-core",
|
|
156
|
+
track: "db",
|
|
157
|
+
detect(context) {
|
|
158
|
+
const csprojFiles = findImportFiles(context.paths, (filePath) => /\.csproj$/i.test(filePath));
|
|
159
|
+
const dbContextFiles = findImportFiles(context.paths, (filePath) => /DbContext|Context\.cs$/i.test(filePath));
|
|
160
|
+
const score = csprojFiles.length > 0 && dbContextFiles.some((filePath) => /DbContext/.test(readTextIfExists(filePath) || "")) ? 89 : 0;
|
|
161
|
+
return {
|
|
162
|
+
score,
|
|
163
|
+
reasons: score > 0 ? ["Found .NET project with EF Core DbContext"] : []
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
extract(context) {
|
|
167
|
+
const dbContextFiles = findImportFiles(context.paths, (filePath) => /DbContext|Context\.cs$/i.test(filePath));
|
|
168
|
+
const domainFiles = findImportFiles(context.paths, (filePath) => /\/Domain\/.+\.cs$/i.test(filePath));
|
|
169
|
+
const findings = [];
|
|
170
|
+
const candidates = { entities: [], enums: [], relations: [], indexes: [] };
|
|
171
|
+
|
|
172
|
+
const trackedNames = new Set();
|
|
173
|
+
for (const filePath of dbContextFiles) {
|
|
174
|
+
const text = readTextIfExists(filePath) || "";
|
|
175
|
+
for (const match of text.matchAll(/DbSet<([A-Za-z_][A-Za-z0-9_]*)>/g)) {
|
|
176
|
+
trackedNames.add(match[1]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
for (const filePath of domainFiles) {
|
|
181
|
+
const text = readTextIfExists(filePath) || "";
|
|
182
|
+
const provenance = relativeTo(context.paths.repoRoot, filePath);
|
|
183
|
+
for (const block of splitClassBlocks(text)) {
|
|
184
|
+
if (!trackedNames.has(block.name)) continue;
|
|
185
|
+
const parsed = domainEntityInfo(block.name, parseProperties(block), trackedNames);
|
|
186
|
+
findings.push({
|
|
187
|
+
kind: "ef_core_entity",
|
|
188
|
+
file: provenance,
|
|
189
|
+
entity: parsed.entity.id_hint
|
|
190
|
+
});
|
|
191
|
+
candidates.entities.push(makeCandidateRecord({
|
|
192
|
+
kind: "entity",
|
|
193
|
+
idHint: parsed.entity.id_hint,
|
|
194
|
+
label: parsed.entity.label,
|
|
195
|
+
confidence: "high",
|
|
196
|
+
sourceKind: "schema",
|
|
197
|
+
provenance,
|
|
198
|
+
model_name: parsed.entity.model_name,
|
|
199
|
+
fields: parsed.entity.fields,
|
|
200
|
+
noise_candidate: parsed.entity.noise_candidate,
|
|
201
|
+
noise_reason: parsed.entity.noise_reason,
|
|
202
|
+
track: "db"
|
|
203
|
+
}));
|
|
204
|
+
candidates.relations.push(...parsed.relations.map((relation) => makeCandidateRecord({
|
|
205
|
+
kind: "relation",
|
|
206
|
+
idHint: `${relation.from_entity}_${relation.relation_field}_${relation.to_entity}`.replace(/[^a-zA-Z0-9_]+/g, "_").toLowerCase(),
|
|
207
|
+
label: `${relation.from_entity} -> ${relation.to_entity}`,
|
|
208
|
+
confidence: "medium",
|
|
209
|
+
sourceKind: "schema",
|
|
210
|
+
provenance,
|
|
211
|
+
...relation,
|
|
212
|
+
track: "db"
|
|
213
|
+
})));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
|
|
218
|
+
candidates.relations = dedupeCandidateRecords(candidates.relations, (record) => record.id_hint);
|
|
219
|
+
return { findings, candidates };
|
|
220
|
+
}
|
|
221
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalCandidateTerm,
|
|
3
|
+
dedupeCandidateRecords,
|
|
4
|
+
findImportFiles,
|
|
5
|
+
idHintify,
|
|
6
|
+
makeCandidateRecord,
|
|
7
|
+
relativeTo,
|
|
8
|
+
titleCase
|
|
9
|
+
} from "../../core/shared.js";
|
|
10
|
+
|
|
11
|
+
function normalizeDartFieldType(typeName) {
|
|
12
|
+
const normalized = String(typeName || "").replace(/\?$/, "").trim();
|
|
13
|
+
switch (normalized) {
|
|
14
|
+
case "String": return "string";
|
|
15
|
+
case "int": return "int";
|
|
16
|
+
case "double": return "double";
|
|
17
|
+
case "bool": return "boolean";
|
|
18
|
+
case "DateTime": return "datetime";
|
|
19
|
+
default: return idHintify(normalized) || "string";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function featureStemFromPath(filePath) {
|
|
24
|
+
return canonicalCandidateTerm(filePath.match(/\/features\/([^/]+)\//)?.[1] || "item");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseEntityFile(text, provenance, filePath) {
|
|
28
|
+
const classMatch = String(text || "").match(/class\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{/m);
|
|
29
|
+
if (!classMatch) return null;
|
|
30
|
+
const className = classMatch[1];
|
|
31
|
+
const fields = [...String(text || "").matchAll(/final\s+([A-Za-z0-9_<>\?]+)\s+([A-Za-z_][A-Za-z0-9_]*)\s*;/g)]
|
|
32
|
+
.map((match) => ({
|
|
33
|
+
name: match[2],
|
|
34
|
+
field_type: normalizeDartFieldType(match[1]),
|
|
35
|
+
required: !String(match[1]).includes("?"),
|
|
36
|
+
list: /^List</.test(match[1]),
|
|
37
|
+
unique: false,
|
|
38
|
+
primary_key: /^id$/i.test(match[2])
|
|
39
|
+
}));
|
|
40
|
+
if (fields.length === 0) return null;
|
|
41
|
+
const stem = featureStemFromPath(filePath);
|
|
42
|
+
return makeCandidateRecord({
|
|
43
|
+
kind: "entity",
|
|
44
|
+
idHint: `entity_${stem}`,
|
|
45
|
+
label: titleCase(stem),
|
|
46
|
+
confidence: "high",
|
|
47
|
+
sourceKind: "schema",
|
|
48
|
+
provenance,
|
|
49
|
+
model_name: className,
|
|
50
|
+
fields,
|
|
51
|
+
track: "db"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parseEnums(text, provenance, filePath) {
|
|
56
|
+
const stem = featureStemFromPath(filePath);
|
|
57
|
+
const enums = [];
|
|
58
|
+
for (const match of String(text || "").matchAll(/enum\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\}/g)) {
|
|
59
|
+
const enumName = canonicalCandidateTerm(idHintify(match[1].replace(/([a-z0-9])([A-Z])/g, "$1_$2")));
|
|
60
|
+
const values = match[2]
|
|
61
|
+
.split(",")
|
|
62
|
+
.map((value) => value.trim())
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.map((value) => value.replace(/\(.*$/, "").trim())
|
|
65
|
+
.filter(Boolean);
|
|
66
|
+
if (values.length === 0) continue;
|
|
67
|
+
enums.push(makeCandidateRecord({
|
|
68
|
+
kind: "enum",
|
|
69
|
+
idHint: `enum_${stem}_${enumName}`,
|
|
70
|
+
label: titleCase(enumName),
|
|
71
|
+
confidence: "medium",
|
|
72
|
+
sourceKind: "schema",
|
|
73
|
+
provenance,
|
|
74
|
+
values,
|
|
75
|
+
track: "db"
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
return enums;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const flutterEntitiesExtractor = {
|
|
82
|
+
id: "db.flutter-entities",
|
|
83
|
+
track: "db",
|
|
84
|
+
detect(context) {
|
|
85
|
+
const entityFiles = findImportFiles(
|
|
86
|
+
context.paths,
|
|
87
|
+
(filePath) => /\/lib\/features\/.+\/domain\/entities\/.+_entity\.dart$/i.test(filePath)
|
|
88
|
+
);
|
|
89
|
+
const score = entityFiles.length > 0 ? 83 : 0;
|
|
90
|
+
return {
|
|
91
|
+
score,
|
|
92
|
+
reasons: score > 0 ? ["Found Flutter feature domain entities"] : []
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
extract(context) {
|
|
96
|
+
const entityFiles = findImportFiles(
|
|
97
|
+
context.paths,
|
|
98
|
+
(filePath) => /\/lib\/features\/.+\/domain\/entities\/.+_entity\.dart$/i.test(filePath)
|
|
99
|
+
);
|
|
100
|
+
const findings = [];
|
|
101
|
+
const candidates = { entities: [], enums: [], relations: [], indexes: [] };
|
|
102
|
+
for (const filePath of entityFiles) {
|
|
103
|
+
const text = context.helpers.readTextIfExists(filePath) || "";
|
|
104
|
+
const provenance = relativeTo(context.paths.repoRoot, filePath);
|
|
105
|
+
const entity = parseEntityFile(text, provenance, filePath);
|
|
106
|
+
if (entity) {
|
|
107
|
+
candidates.entities.push(entity);
|
|
108
|
+
}
|
|
109
|
+
candidates.enums.push(...parseEnums(text, provenance, filePath));
|
|
110
|
+
findings.push({
|
|
111
|
+
kind: "flutter_domain_entity",
|
|
112
|
+
file: provenance,
|
|
113
|
+
entity_id: entity?.id_hint || null
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
|
|
117
|
+
candidates.enums = dedupeCandidateRecords(candidates.enums, (record) => record.id_hint);
|
|
118
|
+
return { findings, candidates };
|
|
119
|
+
}
|
|
120
|
+
};
|