@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,212 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dedupeCandidateRecords,
|
|
3
|
+
findImportFiles,
|
|
4
|
+
inferApiEntityIdFromPath,
|
|
5
|
+
makeCandidateRecord,
|
|
6
|
+
pluralizeCandidateTerm,
|
|
7
|
+
relativeTo,
|
|
8
|
+
titleCase
|
|
9
|
+
} from "../../core/shared.js";
|
|
10
|
+
|
|
11
|
+
function splitTopLevelProperties(block) {
|
|
12
|
+
const props = [];
|
|
13
|
+
let current = "";
|
|
14
|
+
let depth = 0;
|
|
15
|
+
let inString = false;
|
|
16
|
+
let quote = null;
|
|
17
|
+
for (let i = 0; i < block.length; i += 1) {
|
|
18
|
+
const ch = block[i];
|
|
19
|
+
const prev = block[i - 1];
|
|
20
|
+
if (inString) {
|
|
21
|
+
current += ch;
|
|
22
|
+
if (ch === quote && prev !== "\\") {
|
|
23
|
+
inString = false;
|
|
24
|
+
quote = null;
|
|
25
|
+
}
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
29
|
+
inString = true;
|
|
30
|
+
quote = ch;
|
|
31
|
+
current += ch;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (ch === "{" || ch === "[" || ch === "(") {
|
|
35
|
+
depth += 1;
|
|
36
|
+
current += ch;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (ch === "}" || ch === "]" || ch === ")") {
|
|
40
|
+
depth -= 1;
|
|
41
|
+
current += ch;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (ch === "," && depth === 0) {
|
|
45
|
+
if (current.trim()) props.push(current.trim());
|
|
46
|
+
current = "";
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
current += ch;
|
|
50
|
+
}
|
|
51
|
+
if (current.trim()) props.push(current.trim());
|
|
52
|
+
return props;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parseInputFields(entryBody) {
|
|
56
|
+
const objectMatch = entryBody.match(/\.input\s*\(\s*z\.object\s*\(\s*\{([\s\S]*?)\}\s*\)\s*(?:,|\))/m);
|
|
57
|
+
if (!objectMatch) return [];
|
|
58
|
+
const fields = [];
|
|
59
|
+
for (const prop of splitTopLevelProperties(objectMatch[1])) {
|
|
60
|
+
const propMatch = prop.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*:/);
|
|
61
|
+
if (propMatch) fields.push(propMatch[1]);
|
|
62
|
+
}
|
|
63
|
+
return [...new Set(fields)].sort();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function parseNamedSelects(text) {
|
|
67
|
+
const namedSelects = new Map();
|
|
68
|
+
for (const match of text.matchAll(/const\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*\{([\s\S]*?)\}\s*satisfies\s+Prisma\.[A-Za-z_][A-Za-z0-9_]*Select/g)) {
|
|
69
|
+
const fields = [];
|
|
70
|
+
for (const prop of splitTopLevelProperties(match[2])) {
|
|
71
|
+
const propMatch = prop.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*:/);
|
|
72
|
+
if (propMatch) fields.push(propMatch[1]);
|
|
73
|
+
}
|
|
74
|
+
namedSelects.set(match[1], [...new Set(fields)].sort());
|
|
75
|
+
}
|
|
76
|
+
return namedSelects;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function inferOutputFields(entryBody, procedureType, resource, namedSelects) {
|
|
80
|
+
const returnObjectMatch = entryBody.match(/return\s*\{([\s\S]*?)\}\s*;?\s*$/m);
|
|
81
|
+
if (returnObjectMatch) {
|
|
82
|
+
const fields = [];
|
|
83
|
+
for (const prop of splitTopLevelProperties(returnObjectMatch[1])) {
|
|
84
|
+
const propMatch = prop.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*[:(]/);
|
|
85
|
+
if (propMatch) fields.push(propMatch[1]);
|
|
86
|
+
}
|
|
87
|
+
return [...new Set(fields)].sort();
|
|
88
|
+
}
|
|
89
|
+
const selectRefMatch = entryBody.match(/select\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/);
|
|
90
|
+
if (selectRefMatch && namedSelects.has(selectRefMatch[1])) {
|
|
91
|
+
return namedSelects.get(selectRefMatch[1]) || [];
|
|
92
|
+
}
|
|
93
|
+
if (procedureType === "query" && /\bfindUnique\b|\bbyId\b/.test(entryBody)) {
|
|
94
|
+
return [resource];
|
|
95
|
+
}
|
|
96
|
+
if (procedureType === "mutation" && /\bcreate\b/.test(entryBody)) {
|
|
97
|
+
return [resource];
|
|
98
|
+
}
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function inferCapabilityId(routerResource, procedureName, procedureType) {
|
|
103
|
+
const resource = routerResource.replace(/-/g, "_");
|
|
104
|
+
if (/^list$/i.test(procedureName)) return `cap_list_${pluralizeCandidateTerm(resource)}`;
|
|
105
|
+
if (/^(byid|get|detail)$/i.test(procedureName)) return `cap_get_${resource}`;
|
|
106
|
+
if (/^(add|create|new)$/i.test(procedureName)) return `cap_create_${resource}`;
|
|
107
|
+
if (/^(update|edit|patch)$/i.test(procedureName)) return `cap_update_${resource}`;
|
|
108
|
+
if (/^(delete|remove)$/i.test(procedureName)) return `cap_delete_${resource}`;
|
|
109
|
+
const verb = procedureType === "mutation" ? "mutate" : "get";
|
|
110
|
+
return `cap_${verb}_${resource}_${procedureName.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase()}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function inferEndpointPath(routerResource, procedureName, procedureType) {
|
|
114
|
+
const resourcePath = `/${pluralizeCandidateTerm(routerResource).replace(/_/g, "-")}`;
|
|
115
|
+
if (/^list$/i.test(procedureName)) return { method: "GET", path: resourcePath };
|
|
116
|
+
if (/^(byid|get|detail)$/i.test(procedureName)) return { method: "GET", path: `${resourcePath}/{id}` };
|
|
117
|
+
if (/^(add|create|new)$/i.test(procedureName)) return { method: "POST", path: resourcePath };
|
|
118
|
+
if (/^(update|edit|patch)$/i.test(procedureName)) return { method: "PATCH", path: `${resourcePath}/{id}` };
|
|
119
|
+
if (/^(delete|remove)$/i.test(procedureName)) return { method: "DELETE", path: `${resourcePath}/{id}` };
|
|
120
|
+
return { method: procedureType === "mutation" ? "POST" : "GET", path: `${resourcePath}/${procedureName}` };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parseRouterProcedures(filePath, text) {
|
|
124
|
+
const routerDecl = text.match(/export\s+const\s+([A-Za-z_][A-Za-z0-9_]*)Router\s*=\s*router\s*\(\s*\{/m);
|
|
125
|
+
if (!routerDecl) return [];
|
|
126
|
+
const routerName = routerDecl[1];
|
|
127
|
+
const routerResource = routerName.replace(/Router$/, "").replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
128
|
+
const routerText = text.slice(routerDecl.index);
|
|
129
|
+
const namedSelects = parseNamedSelects(text);
|
|
130
|
+
const procedures = [];
|
|
131
|
+
for (const entryMatch of routerText.matchAll(/(^|\n)\s*([A-Za-z_][A-Za-z0-9_]*)\s*:\s*publicProcedure([\s\S]*?)\.(query|mutation)\s*\(\s*async\s*\([^)]*\)\s*=>\s*\{([\s\S]*?)\}\s*\)\s*,?/g)) {
|
|
132
|
+
const procedureName = entryMatch[2];
|
|
133
|
+
const entryBody = entryMatch[3];
|
|
134
|
+
const procedureType = entryMatch[4];
|
|
135
|
+
const resolverBody = entryMatch[5];
|
|
136
|
+
const endpoint = inferEndpointPath(routerResource, procedureName, procedureType);
|
|
137
|
+
const capabilityId = inferCapabilityId(routerResource, procedureName, procedureType);
|
|
138
|
+
procedures.push({
|
|
139
|
+
file: filePath,
|
|
140
|
+
routerName,
|
|
141
|
+
routerResource,
|
|
142
|
+
procedureName,
|
|
143
|
+
procedureType,
|
|
144
|
+
id_hint: capabilityId,
|
|
145
|
+
endpoint,
|
|
146
|
+
input_fields: parseInputFields(entryBody),
|
|
147
|
+
output_fields: inferOutputFields(resolverBody, procedureType, routerResource, namedSelects),
|
|
148
|
+
entity_id: inferApiEntityIdFromPath(endpoint.path),
|
|
149
|
+
auth_hint: /protectedProcedure/.test(entryBody) ? "secured" : "public"
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return procedures;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const trpcExtractor = {
|
|
156
|
+
id: "api.trpc",
|
|
157
|
+
track: "api",
|
|
158
|
+
detect(context) {
|
|
159
|
+
const routerFiles = findImportFiles(context.paths, (filePath) => /src\/server\/routers\/.+\.(ts|tsx|js|jsx)$/i.test(filePath));
|
|
160
|
+
const trpcHandler = findImportFiles(context.paths, (filePath) => /src\/pages\/api\/trpc\/\[trpc\]\.(ts|tsx|js|jsx)$/i.test(filePath));
|
|
161
|
+
return {
|
|
162
|
+
score: routerFiles.length > 0 && trpcHandler.length > 0 ? 88 : 0,
|
|
163
|
+
reasons: routerFiles.length > 0 && trpcHandler.length > 0 ? ["Found tRPC router modules and Next.js tRPC handler"] : []
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
extract(context) {
|
|
167
|
+
const routerFiles = findImportFiles(context.paths, (filePath) => /src\/server\/routers\/.+\.(ts|tsx|js|jsx)$/i.test(filePath))
|
|
168
|
+
.filter((filePath) => !/\/_app\.(ts|tsx|js|jsx)$/i.test(filePath) && !/\.test\./i.test(filePath));
|
|
169
|
+
const procedures = routerFiles.flatMap((filePath) => parseRouterProcedures(filePath, context.helpers.readTextIfExists(filePath) || ""));
|
|
170
|
+
const findings = [];
|
|
171
|
+
const candidates = { capabilities: [], routes: [], stacks: [] };
|
|
172
|
+
if (procedures.length > 0) {
|
|
173
|
+
findings.push({
|
|
174
|
+
kind: "trpc_procedures",
|
|
175
|
+
files: [...new Set(procedures.map((entry) => relativeTo(context.paths.repoRoot, entry.file)))],
|
|
176
|
+
capability_count: procedures.length
|
|
177
|
+
});
|
|
178
|
+
candidates.capabilities.push(...procedures.map((entry) => makeCandidateRecord({
|
|
179
|
+
kind: "capability",
|
|
180
|
+
idHint: entry.id_hint,
|
|
181
|
+
label: titleCase(entry.id_hint.replace(/^cap_/, "")),
|
|
182
|
+
confidence: "high",
|
|
183
|
+
sourceKind: "route_code",
|
|
184
|
+
provenance: `${relativeTo(context.paths.repoRoot, entry.file)}#${entry.routerName}.${entry.procedureName}`,
|
|
185
|
+
endpoint: entry.endpoint,
|
|
186
|
+
path_params: /\{id\}/.test(entry.endpoint.path) ? [{ name: "id", required: true, type: null }] : [],
|
|
187
|
+
query_params: [],
|
|
188
|
+
header_params: [],
|
|
189
|
+
input_fields: entry.input_fields,
|
|
190
|
+
output_fields: entry.output_fields,
|
|
191
|
+
auth_hint: entry.auth_hint,
|
|
192
|
+
entity_id: entry.entity_id,
|
|
193
|
+
track: "api"
|
|
194
|
+
})));
|
|
195
|
+
candidates.routes.push(...procedures.map((entry) => ({
|
|
196
|
+
path: entry.endpoint.path,
|
|
197
|
+
method: entry.endpoint.method,
|
|
198
|
+
confidence: "high",
|
|
199
|
+
source_kind: "route_code",
|
|
200
|
+
provenance: `${relativeTo(context.paths.repoRoot, entry.file)}#${entry.routerName}.${entry.procedureName}`
|
|
201
|
+
})));
|
|
202
|
+
candidates.stacks.push("trpc");
|
|
203
|
+
}
|
|
204
|
+
candidates.capabilities = dedupeCandidateRecords(candidates.capabilities, (record) => record.id_hint);
|
|
205
|
+
candidates.routes = dedupeCandidateRecords(
|
|
206
|
+
candidates.routes.map((route) => ({ ...route, id_hint: `${route.method}_${route.path}` })),
|
|
207
|
+
(record) => `${record.method}:${record.path}:${record.source_kind}`
|
|
208
|
+
).map(({ id_hint, ...route }) => route);
|
|
209
|
+
candidates.stacks = [...new Set(candidates.stacks)].sort();
|
|
210
|
+
return { findings, candidates };
|
|
211
|
+
}
|
|
212
|
+
};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
canonicalCandidateTerm,
|
|
5
|
+
dedupeCandidateRecords,
|
|
6
|
+
findImportFiles,
|
|
7
|
+
idHintify,
|
|
8
|
+
makeCandidateRecord,
|
|
9
|
+
relativeTo,
|
|
10
|
+
titleCase
|
|
11
|
+
} from "../../core/shared.js";
|
|
12
|
+
|
|
13
|
+
function splitClassBlocks(text) {
|
|
14
|
+
const lines = String(text || "").split(/\r?\n/);
|
|
15
|
+
const blocks = [];
|
|
16
|
+
let current = null;
|
|
17
|
+
|
|
18
|
+
for (const line of lines) {
|
|
19
|
+
const classMatch = line.match(/^class\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([^)]*)\)\s*:/);
|
|
20
|
+
if (classMatch) {
|
|
21
|
+
if (current) {
|
|
22
|
+
blocks.push(current);
|
|
23
|
+
}
|
|
24
|
+
current = {
|
|
25
|
+
name: classMatch[1],
|
|
26
|
+
bases: classMatch[2],
|
|
27
|
+
lines: [line]
|
|
28
|
+
};
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (current) {
|
|
32
|
+
current.lines.push(line);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (current) {
|
|
37
|
+
blocks.push(current);
|
|
38
|
+
}
|
|
39
|
+
return blocks;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function collectModelAssignments(lines) {
|
|
43
|
+
const assignments = [];
|
|
44
|
+
let current = null;
|
|
45
|
+
let balance = 0;
|
|
46
|
+
|
|
47
|
+
for (const rawLine of lines) {
|
|
48
|
+
const line = rawLine.replace(/\s+#.*$/, "");
|
|
49
|
+
if (!current) {
|
|
50
|
+
const match = line.match(/^\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*models\.([A-Za-z_][A-Za-z0-9_]*)\((.*)$/);
|
|
51
|
+
if (!match) continue;
|
|
52
|
+
current = {
|
|
53
|
+
fieldName: match[1],
|
|
54
|
+
fieldType: match[2],
|
|
55
|
+
raw: match[3]
|
|
56
|
+
};
|
|
57
|
+
balance = (match[3].match(/\(/g) || []).length - (match[3].match(/\)/g) || []).length + 1;
|
|
58
|
+
if (balance <= 0) {
|
|
59
|
+
assignments.push(current);
|
|
60
|
+
current = null;
|
|
61
|
+
balance = 0;
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
current.raw += `\n${line}`;
|
|
67
|
+
balance += (line.match(/\(/g) || []).length - (line.match(/\)/g) || []).length;
|
|
68
|
+
if (balance <= 0) {
|
|
69
|
+
assignments.push(current);
|
|
70
|
+
current = null;
|
|
71
|
+
balance = 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return assignments;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function extractRelatedModel(rawArgs, currentClassName) {
|
|
79
|
+
const quoted = String(rawArgs || "").match(/^\s*['"]([^'"]+)['"]/);
|
|
80
|
+
const bare = String(rawArgs || "").match(/^\s*([A-Za-z_][A-Za-z0-9_.]*)\s*(?:,|\))/);
|
|
81
|
+
const value = quoted?.[1] || bare?.[1] || null;
|
|
82
|
+
if (!value) return null;
|
|
83
|
+
if (value === "self") {
|
|
84
|
+
return currentClassName;
|
|
85
|
+
}
|
|
86
|
+
const modelName = value.split(".").pop();
|
|
87
|
+
return modelName || null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function normalizeFieldType(fieldType, relatedModel) {
|
|
91
|
+
const normalized = String(fieldType || "").toLowerCase();
|
|
92
|
+
if (normalized === "charfield" || normalized === "textfield" || normalized === "slugfield" || normalized === "emailfield" || normalized === "urlfield") {
|
|
93
|
+
return "string";
|
|
94
|
+
}
|
|
95
|
+
if (normalized === "booleanfield") {
|
|
96
|
+
return "boolean";
|
|
97
|
+
}
|
|
98
|
+
if (normalized === "integerfield" || normalized === "autofield" || normalized === "bigintegerfield") {
|
|
99
|
+
return "int";
|
|
100
|
+
}
|
|
101
|
+
if (normalized === "datetimefield") {
|
|
102
|
+
return "datetime";
|
|
103
|
+
}
|
|
104
|
+
if (["foreignkey", "onetoonefield", "manytomanyfield"].includes(normalized) && relatedModel) {
|
|
105
|
+
return idHintify(relatedModel);
|
|
106
|
+
}
|
|
107
|
+
return normalized.replace(/field$/, "") || normalized;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function parseModelClass(block, provenance) {
|
|
111
|
+
const body = block.lines.join("\n");
|
|
112
|
+
if (/class\s+Meta\s*:[\s\S]*?abstract\s*=\s*True/.test(body)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const assignments = collectModelAssignments(block.lines.slice(1));
|
|
116
|
+
if (assignments.length === 0) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const entityStem = canonicalCandidateTerm(block.name);
|
|
121
|
+
const entityId = `entity_${entityStem}`;
|
|
122
|
+
const fields = [];
|
|
123
|
+
const relations = [];
|
|
124
|
+
|
|
125
|
+
for (const assignment of assignments) {
|
|
126
|
+
const relatedModel = extractRelatedModel(assignment.raw, block.name);
|
|
127
|
+
const normalizedType = String(assignment.fieldType || "").toLowerCase();
|
|
128
|
+
const required = !/blank\s*=\s*True/.test(assignment.raw) && !/null\s*=\s*True/.test(assignment.raw);
|
|
129
|
+
const unique = /unique\s*=\s*True/.test(assignment.raw);
|
|
130
|
+
const list = normalizedType === "manytomanyfield";
|
|
131
|
+
const primaryKey = /primary_key\s*=\s*True/.test(assignment.raw);
|
|
132
|
+
|
|
133
|
+
fields.push({
|
|
134
|
+
name: assignment.fieldName,
|
|
135
|
+
field_type: normalizeFieldType(assignment.fieldType, relatedModel),
|
|
136
|
+
required,
|
|
137
|
+
list,
|
|
138
|
+
unique,
|
|
139
|
+
primary_key: primaryKey
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
if (["foreignkey", "onetoonefield", "manytomanyfield"].includes(normalizedType) && relatedModel) {
|
|
143
|
+
relations.push({
|
|
144
|
+
from_entity: entityId,
|
|
145
|
+
to_entity: `entity_${canonicalCandidateTerm(relatedModel)}`,
|
|
146
|
+
relation_field: assignment.fieldName,
|
|
147
|
+
fields: [assignment.fieldName],
|
|
148
|
+
references: ["id"],
|
|
149
|
+
relation_type: normalizedType
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
entity: {
|
|
156
|
+
id_hint: entityId,
|
|
157
|
+
label: titleCase(entityStem),
|
|
158
|
+
model_name: block.name,
|
|
159
|
+
django_bases: block.bases.split(",").map((entry) => entry.trim()).filter(Boolean),
|
|
160
|
+
fields,
|
|
161
|
+
track: "db",
|
|
162
|
+
provenance
|
|
163
|
+
},
|
|
164
|
+
relations
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export const djangoModelsExtractor = {
|
|
169
|
+
id: "db.django-models",
|
|
170
|
+
track: "db",
|
|
171
|
+
detect(context) {
|
|
172
|
+
const modelFiles = findImportFiles(context.paths, (filePath) => /\/models\.py$/i.test(filePath));
|
|
173
|
+
const manageFiles = findImportFiles(context.paths, (filePath) => /\/manage\.py$/i.test(filePath));
|
|
174
|
+
const score = modelFiles.length > 0 && manageFiles.length > 0 ? 91 : 0;
|
|
175
|
+
return {
|
|
176
|
+
score,
|
|
177
|
+
reasons: score > 0 ? ["Found Django manage.py and app models.py files"] : []
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
extract(context) {
|
|
181
|
+
const modelFiles = findImportFiles(context.paths, (filePath) => /\/models\.py$/i.test(filePath));
|
|
182
|
+
const findings = [];
|
|
183
|
+
const candidates = { entities: [], enums: [], relations: [], indexes: [] };
|
|
184
|
+
|
|
185
|
+
for (const filePath of modelFiles) {
|
|
186
|
+
const text = context.helpers.readTextIfExists(filePath) || "";
|
|
187
|
+
const provenance = relativeTo(context.paths.repoRoot, filePath);
|
|
188
|
+
const blocks = splitClassBlocks(text);
|
|
189
|
+
let entityCount = 0;
|
|
190
|
+
|
|
191
|
+
for (const block of blocks) {
|
|
192
|
+
const parsed = parseModelClass(block, provenance);
|
|
193
|
+
if (!parsed) continue;
|
|
194
|
+
entityCount += 1;
|
|
195
|
+
candidates.entities.push(makeCandidateRecord({
|
|
196
|
+
kind: "entity",
|
|
197
|
+
idHint: parsed.entity.id_hint,
|
|
198
|
+
label: parsed.entity.label,
|
|
199
|
+
confidence: "high",
|
|
200
|
+
sourceKind: "schema",
|
|
201
|
+
provenance,
|
|
202
|
+
model_name: parsed.entity.model_name,
|
|
203
|
+
django_bases: parsed.entity.django_bases,
|
|
204
|
+
fields: parsed.entity.fields,
|
|
205
|
+
track: "db"
|
|
206
|
+
}));
|
|
207
|
+
candidates.relations.push(...parsed.relations.map((relation) => makeCandidateRecord({
|
|
208
|
+
kind: "relation",
|
|
209
|
+
idHint: `${relation.from_entity}_${relation.relation_field}_${relation.to_entity}`.replace(/[^a-zA-Z0-9_]+/g, "_").toLowerCase(),
|
|
210
|
+
label: `${relation.from_entity} -> ${relation.to_entity}`,
|
|
211
|
+
confidence: "medium",
|
|
212
|
+
sourceKind: "schema",
|
|
213
|
+
provenance,
|
|
214
|
+
...relation,
|
|
215
|
+
track: "db"
|
|
216
|
+
})));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (entityCount > 0) {
|
|
220
|
+
findings.push({
|
|
221
|
+
kind: "django_models",
|
|
222
|
+
file: provenance,
|
|
223
|
+
entity_count: entityCount
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
candidates.entities = dedupeCandidateRecords(candidates.entities, (record) => record.id_hint);
|
|
229
|
+
candidates.relations = dedupeCandidateRecords(candidates.relations, (record) => record.id_hint);
|
|
230
|
+
return { findings, candidates };
|
|
231
|
+
}
|
|
232
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalCandidateTerm,
|
|
3
|
+
dedupeCandidateRecords,
|
|
4
|
+
findImportFiles,
|
|
5
|
+
idHintify,
|
|
6
|
+
makeCandidateRecord,
|
|
7
|
+
relativeTo,
|
|
8
|
+
titleCase
|
|
9
|
+
} from "../../core/shared.js";
|
|
10
|
+
|
|
11
|
+
function normalizeCsType(typeName) {
|
|
12
|
+
const normalized = String(typeName || "").replace(/\?$/, "").trim();
|
|
13
|
+
switch (normalized.toLowerCase()) {
|
|
14
|
+
case "string": return "string";
|
|
15
|
+
case "int":
|
|
16
|
+
case "int32": return "int";
|
|
17
|
+
case "long":
|
|
18
|
+
case "int64": return "bigint";
|
|
19
|
+
case "bool":
|
|
20
|
+
case "boolean": return "boolean";
|
|
21
|
+
case "double": return "double";
|
|
22
|
+
case "float": return "float";
|
|
23
|
+
default: return idHintify(normalized) || "string";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseCsModel(text, provenance) {
|
|
28
|
+
const classMatch = String(text || "").match(/class\s+([A-Za-z_][A-Za-z0-9_]*)\s*(?::\s*([A-Za-z0-9_, ]+))?\s*\{([\s\S]*?)\n\}/m);
|
|
29
|
+
if (!classMatch) return null;
|
|
30
|
+
const className = classMatch[1];
|
|
31
|
+
const body = classMatch[3];
|
|
32
|
+
const fields = [];
|
|
33
|
+
for (const match of body.matchAll(/public\s+([A-Za-z0-9_<>,?.]+)\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{/g)) {
|
|
34
|
+
const [, typeName, name] = match;
|
|
35
|
+
const normalizedName = /^ID$/i.test(name) ? "id" : name.charAt(0).toLowerCase() + name.slice(1);
|
|
36
|
+
fields.push({
|
|
37
|
+
name: normalizedName,
|
|
38
|
+
field_type: normalizeCsType(typeName),
|
|
39
|
+
required: !String(typeName).includes("?"),
|
|
40
|
+
list: /^IEnumerable<|^List</.test(typeName),
|
|
41
|
+
unique: false,
|
|
42
|
+
primary_key: /^id$/i.test(name)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (fields.length === 0) return null;
|
|
46
|
+
const stem = canonicalCandidateTerm(idHintify(className.replace(/([a-z0-9])([A-Z])/g, "$1_$2")));
|
|
47
|
+
return makeCandidateRecord({
|
|
48
|
+
kind: "entity",
|
|
49
|
+
idHint: `entity_${stem}`,
|
|
50
|
+
label: titleCase(stem),
|
|
51
|
+
confidence: "medium",
|
|
52
|
+
sourceKind: "schema",
|
|
53
|
+
provenance,
|
|
54
|
+
model_name: className,
|
|
55
|
+
fields,
|
|
56
|
+
track: "db"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const dotnetModelsExtractor = {
|
|
61
|
+
id: "db.dotnet-models",
|
|
62
|
+
track: "db",
|
|
63
|
+
detect(context) {
|
|
64
|
+
const modelFiles = findImportFiles(context.paths, (filePath) => /\/Models\/.+\.cs$/i.test(filePath));
|
|
65
|
+
const csprojFiles = findImportFiles(context.paths, (filePath) => /\.csproj$/i.test(filePath));
|
|
66
|
+
const score = modelFiles.length > 0 && csprojFiles.length > 0 ? 78 : 0;
|
|
67
|
+
return {
|
|
68
|
+
score,
|
|
69
|
+
reasons: score > 0 ? ["Found .NET model classes in a project with .csproj"] : []
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
extract(context) {
|
|
73
|
+
const modelFiles = findImportFiles(context.paths, (filePath) => /\/Models\/.+\.cs$/i.test(filePath));
|
|
74
|
+
const findings = [];
|
|
75
|
+
const entities = [];
|
|
76
|
+
for (const filePath of modelFiles) {
|
|
77
|
+
const provenance = relativeTo(context.paths.repoRoot, filePath);
|
|
78
|
+
const entity = parseCsModel(context.helpers.readTextIfExists(filePath) || "", provenance);
|
|
79
|
+
if (!entity) continue;
|
|
80
|
+
entities.push(entity);
|
|
81
|
+
findings.push({ kind: "dotnet_model", file: provenance, entity_id: entity.id_hint });
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
findings,
|
|
85
|
+
candidates: {
|
|
86
|
+
entities: dedupeCandidateRecords(entities, (record) => record.id_hint),
|
|
87
|
+
enums: [],
|
|
88
|
+
relations: [],
|
|
89
|
+
indexes: []
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|