@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,304 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dedupeCandidateRecords,
|
|
3
|
+
findImportFiles,
|
|
4
|
+
inferApiEntityIdFromPath,
|
|
5
|
+
inferRouteCapabilityId,
|
|
6
|
+
makeCandidateRecord,
|
|
7
|
+
normalizeOpenApiPath,
|
|
8
|
+
readTextIfExists,
|
|
9
|
+
relativeTo,
|
|
10
|
+
titleCase
|
|
11
|
+
} from "../../core/shared.js";
|
|
12
|
+
|
|
13
|
+
function escapeRegExp(value) {
|
|
14
|
+
return String(value || "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function parsePublicProperties(text) {
|
|
18
|
+
return [...String(text || "").matchAll(/public\s+[A-Za-z0-9_<>\[\]\?., ]+\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{/g)]
|
|
19
|
+
.map((entry) => entry[1])
|
|
20
|
+
.filter((name) => !name.endsWith("Id"))
|
|
21
|
+
.map((name) => name.charAt(0).toLowerCase() + name.slice(1));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function buildDotnetFileIndex(paths) {
|
|
25
|
+
const files = findImportFiles(paths, (filePath) => /\.cs$/i.test(filePath));
|
|
26
|
+
const index = new Map();
|
|
27
|
+
for (const filePath of files) {
|
|
28
|
+
index.set(relativeTo(paths.repoRoot, filePath), readTextIfExists(filePath) || "");
|
|
29
|
+
}
|
|
30
|
+
return { files, index };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function explicitHandlerHint(controllerName, methodName, routePath, httpMethod) {
|
|
34
|
+
if (controllerName === "ArticlesController" && methodName === "GetFeed") return "feed_article";
|
|
35
|
+
if (controllerName === "FavoritesController" && methodName === "FavoriteAdd") return "favorite_article";
|
|
36
|
+
if (controllerName === "FavoritesController" && methodName === "FavoriteDelete") return "unfavorite_article";
|
|
37
|
+
if (controllerName === "FollowersController" && methodName === "Follow") return "follow_profile";
|
|
38
|
+
if (controllerName === "FollowersController" && methodName === "Unfollow") return "unfollow_profile";
|
|
39
|
+
if (controllerName === "ProfilesController" && methodName === "Get") return "get_profile";
|
|
40
|
+
if (controllerName === "UsersController" && methodName === "Login") return "sign_in_account";
|
|
41
|
+
if (controllerName === "UserController" && methodName === "GetCurrent") return "get_user";
|
|
42
|
+
if (controllerName === "UserController" && methodName === "UpdateUser") return "update_user";
|
|
43
|
+
if (controllerName === "TagsController" && methodName === "Get") return "list_tags";
|
|
44
|
+
if (controllerName === "ArticlesController" && methodName === "Get" && /\/\{slug\}$/.test(routePath)) return "get_article";
|
|
45
|
+
if (controllerName === "ArticlesController" && methodName === "Get" && httpMethod === "GET") return "list_articles";
|
|
46
|
+
if (controllerName === "ArticlesController" && methodName === "Create") return "create_article";
|
|
47
|
+
if (controllerName === "ArticlesController" && methodName === "Edit") return "update_article";
|
|
48
|
+
if (controllerName === "ArticlesController" && methodName === "Delete") return "delete_article";
|
|
49
|
+
if (controllerName === "CommentsController" && methodName === "Get") return "list_comments";
|
|
50
|
+
if (controllerName === "CommentsController" && methodName === "Create") return "create_comment";
|
|
51
|
+
if (controllerName === "CommentsController" && methodName === "Delete") return "delete_comment";
|
|
52
|
+
if (controllerName === "UsersController" && methodName === "Create") return "create_user";
|
|
53
|
+
if (controllerName === "TodoItemsController" && methodName === "List") return "list_todo_items";
|
|
54
|
+
if (controllerName === "TodoItemsController" && methodName === "Create") return "create_todo_item";
|
|
55
|
+
if (controllerName === "TodoItemsController" && methodName === "Edit") return "update_todo_item";
|
|
56
|
+
if (controllerName === "TodoItemsController" && methodName === "Delete") return "delete_todo_item";
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function explicitEntityId(controllerName, handlerHint, routePath) {
|
|
61
|
+
if (controllerName === "ProfilesController") return "entity_profile";
|
|
62
|
+
if (controllerName === "FollowersController") return "entity_profile";
|
|
63
|
+
if (controllerName === "FavoritesController") return "entity_article";
|
|
64
|
+
if (controllerName === "ArticlesController") return "entity_article";
|
|
65
|
+
if (controllerName === "CommentsController") return "entity_comment";
|
|
66
|
+
if (controllerName === "TagsController") return "entity_tag";
|
|
67
|
+
if (controllerName === "TodoItemsController") return "entity_todo-item";
|
|
68
|
+
if (controllerName === "UserController" || controllerName === "UsersController") {
|
|
69
|
+
return handlerHint === "sign_in_account" ? "entity_account" : "entity_user";
|
|
70
|
+
}
|
|
71
|
+
return inferApiEntityIdFromPath(routePath);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function routeAuthHint(bodyPrefix, methodPrefix) {
|
|
75
|
+
const combined = `${bodyPrefix}\n${methodPrefix}`;
|
|
76
|
+
return /\[Authorize/.test(combined) ? "secured" : "public";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function resolveReturnType(returnType) {
|
|
80
|
+
return String(returnType || "").trim().replace(/^Task\s*</, "").replace(/>\s*$/, "").trim();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function findTypeBlockInText(text, bare) {
|
|
84
|
+
const escaped = escapeRegExp(bare);
|
|
85
|
+
const patterns = [
|
|
86
|
+
new RegExp(`public\\s+class\\s+${escaped}\\b([\\s\\S]{0,2400})`, "m"),
|
|
87
|
+
new RegExp(`public\\s+record\\s+class\\s+${escaped}\\b([\\s\\S]{0,1600})`, "m"),
|
|
88
|
+
new RegExp(`public\\s+record\\s+${escaped}\\b([\\s\\S]{0,1600})`, "m")
|
|
89
|
+
];
|
|
90
|
+
for (const pattern of patterns) {
|
|
91
|
+
const match = String(text || "").match(pattern);
|
|
92
|
+
if (match) return match[0];
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function findBlockForType(typeName, featureFiles, options = {}) {
|
|
98
|
+
const raw = String(typeName || "");
|
|
99
|
+
const parts = raw.split(".");
|
|
100
|
+
const bare = parts.pop();
|
|
101
|
+
if (!bare) return null;
|
|
102
|
+
const preferredFileStem = parts[0] || null;
|
|
103
|
+
const preferredDirectory = options.preferredDirectory || null;
|
|
104
|
+
if (preferredFileStem && preferredDirectory) {
|
|
105
|
+
const localPreferred = featureFiles.find(({ filePath }) => filePath.startsWith(preferredDirectory) && filePath.endsWith(`/${preferredFileStem}.cs`));
|
|
106
|
+
if (localPreferred) {
|
|
107
|
+
const snippet = findTypeBlockInText(localPreferred.text, bare);
|
|
108
|
+
if (snippet) {
|
|
109
|
+
return { filePath: localPreferred.filePath, text: snippet, className: bare };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (preferredFileStem) {
|
|
114
|
+
const preferred = featureFiles.find(({ filePath }) => filePath.endsWith(`/${preferredFileStem}.cs`));
|
|
115
|
+
if (preferred) {
|
|
116
|
+
const snippet = findTypeBlockInText(preferred.text, bare);
|
|
117
|
+
if (snippet) {
|
|
118
|
+
return { filePath: preferred.filePath, text: snippet, className: bare };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const { filePath, text } of featureFiles) {
|
|
123
|
+
const snippet = findTypeBlockInText(text, bare);
|
|
124
|
+
if (snippet) {
|
|
125
|
+
return { filePath, text: snippet, className: bare };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function flattenInputFields(typeName, featureFiles, options = {}, seen = new Set()) {
|
|
132
|
+
const rawType = String(typeName || "").trim();
|
|
133
|
+
const bare = rawType.split(".").pop();
|
|
134
|
+
if (!bare || seen.has(bare)) return [];
|
|
135
|
+
seen.add(bare);
|
|
136
|
+
|
|
137
|
+
const classBlock = findBlockForType(rawType, featureFiles, options);
|
|
138
|
+
if (!classBlock) return [];
|
|
139
|
+
const blockText = classBlock.text;
|
|
140
|
+
|
|
141
|
+
const recordCtor = blockText.match(new RegExp(`${bare}\\s*\\(([^)]*)\\)`));
|
|
142
|
+
if (recordCtor) {
|
|
143
|
+
const fields = [];
|
|
144
|
+
for (const part of recordCtor[1].split(",")) {
|
|
145
|
+
const trimmed = part.trim();
|
|
146
|
+
const match = trimmed.match(/([A-Za-z0-9_<>\[\]\?\.]+)\s+([A-Za-z_][A-Za-z0-9_]*)$/);
|
|
147
|
+
if (!match) continue;
|
|
148
|
+
const [, innerType, name] = match;
|
|
149
|
+
const normalizedName = name.charAt(0).toLowerCase() + name.slice(1);
|
|
150
|
+
const nested = flattenInputFields(innerType, featureFiles, options, seen);
|
|
151
|
+
if (nested.length > 0 && ["article", "user", "model", "comment"].includes(normalizedName)) {
|
|
152
|
+
fields.push(...nested);
|
|
153
|
+
} else {
|
|
154
|
+
fields.push(normalizedName);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return [...new Set(fields)];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return [...new Set(parsePublicProperties(blockText))];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function flattenOutputFields(returnType, featureFiles) {
|
|
164
|
+
const bare = String(returnType || "").split(".").pop();
|
|
165
|
+
if (!bare) return [];
|
|
166
|
+
const envelope = findBlockForType(bare, featureFiles);
|
|
167
|
+
if (!envelope) return [];
|
|
168
|
+
const text = envelope.text;
|
|
169
|
+
const recordCtor = text.match(new RegExp(`${bare}\\s*\\(([^)]*)\\)`));
|
|
170
|
+
if (recordCtor) {
|
|
171
|
+
return recordCtor[1]
|
|
172
|
+
.split(",")
|
|
173
|
+
.map((part) => part.trim().match(/([A-Za-z_][A-Za-z0-9_]*)$/)?.[1])
|
|
174
|
+
.filter(Boolean)
|
|
175
|
+
.map((name) => name.charAt(0).toLowerCase() + name.slice(1));
|
|
176
|
+
}
|
|
177
|
+
return parsePublicProperties(text);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function parseControllerHeader(text) {
|
|
181
|
+
const headerMatch = String(text || "").match(/((?:\s*\[[^\]]+\]\s*)*)\s*public\s+class\s+([A-Za-z_][A-Za-z0-9_]*)Controller\b/m);
|
|
182
|
+
if (!headerMatch) return null;
|
|
183
|
+
return {
|
|
184
|
+
attributes: headerMatch[1] || "",
|
|
185
|
+
controllerName: `${headerMatch[2]}Controller`
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function parseControllerRoutes(filePath, text, featureFiles, repoRoot) {
|
|
190
|
+
const routes = [];
|
|
191
|
+
const preferredDirectory = filePath.slice(0, filePath.lastIndexOf("/"));
|
|
192
|
+
|
|
193
|
+
const header = parseControllerHeader(text);
|
|
194
|
+
const controllerName = header?.controllerName || filePath.split("/").pop()?.replace(/\.cs$/, "") || "";
|
|
195
|
+
const classAttributes = header?.attributes || "";
|
|
196
|
+
const classRouteTemplate = classAttributes.match(/\[Route\("([^"]+)"\)\]/)?.[1] || "";
|
|
197
|
+
const classRoute = classRouteTemplate.replace(/\[controller\]/gi, controllerName.replace(/Controller$/, ""));
|
|
198
|
+
const classAuthorized = /\[Authorize[^\]]*\]/.test(classAttributes);
|
|
199
|
+
const methodMatches = [
|
|
200
|
+
...text.matchAll(
|
|
201
|
+
/(?:^|\n)((?:\s*\[[^\]]+\]\s*)*)\s*public\s+(?!class\b)(?:async\s+)?([A-Za-z0-9_<>\[\]\?., ]+)\s+([A-Za-z_][A-Za-z0-9_]*)\(([\s\S]*?)\)\s*(?:=>|\{)/gm
|
|
202
|
+
)
|
|
203
|
+
];
|
|
204
|
+
|
|
205
|
+
for (const match of methodMatches) {
|
|
206
|
+
const [, attributes, returnTypeRaw, methodName, parameters] = match;
|
|
207
|
+
const httpMatch = attributes.match(/\[(HttpGet|HttpPost|HttpPut|HttpPatch|HttpDelete)(?:\("([^"]*)"\))?\]/);
|
|
208
|
+
if (!httpMatch) continue;
|
|
209
|
+
const httpMethod = httpMatch[1].replace(/^Http/, "").toUpperCase();
|
|
210
|
+
const methodRoute = httpMatch[2] || "";
|
|
211
|
+
const routePath = normalizeOpenApiPath(`/${[classRoute, methodRoute].filter(Boolean).join("/")}`);
|
|
212
|
+
const pathParams = [...routePath.matchAll(/\{([^}]+)\}/g)].map((entry) => ({ name: entry[1], required: true, type: null }));
|
|
213
|
+
const queryParams = [...parameters.matchAll(/\[FromQuery\]\s+([A-Za-z0-9_<>\[\]\?\.]+)\s+([A-Za-z_][A-Za-z0-9_]*)/g)].map((entry) => ({ name: entry[2], required: false, type: entry[1] || null }));
|
|
214
|
+
const bodyType = parameters.match(/\[FromBody\]\s+([A-Za-z0-9_<>\[\]\?\.]+)\s+[A-Za-z_][A-Za-z0-9_]*/)?.[1] || null;
|
|
215
|
+
const returnType = resolveReturnType(returnTypeRaw);
|
|
216
|
+
const handler_hint = explicitHandlerHint(controllerName, methodName, routePath, httpMethod);
|
|
217
|
+
|
|
218
|
+
routes.push({
|
|
219
|
+
method: httpMethod,
|
|
220
|
+
path: routePath,
|
|
221
|
+
handler_hint,
|
|
222
|
+
auth_hint: routeAuthHint(classAuthorized ? "[Authorize]" : "", attributes),
|
|
223
|
+
controller: controllerName,
|
|
224
|
+
method_name: methodName,
|
|
225
|
+
return_type: returnType,
|
|
226
|
+
body_type: bodyType,
|
|
227
|
+
path_params: pathParams,
|
|
228
|
+
query_params: queryParams,
|
|
229
|
+
input_fields: bodyType ? flattenInputFields(bodyType, featureFiles, { preferredDirectory }) : [],
|
|
230
|
+
output_fields: flattenOutputFields(returnType, featureFiles),
|
|
231
|
+
provenance: `${relativeTo(repoRoot, filePath)}#${httpMethod} ${routePath}`
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return routes;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export const aspNetCoreExtractor = {
|
|
239
|
+
id: "api.aspnet-core",
|
|
240
|
+
track: "api",
|
|
241
|
+
detect(context) {
|
|
242
|
+
const controllerFiles = findImportFiles(context.paths, (filePath) => /Controller\.cs$/i.test(filePath));
|
|
243
|
+
const programFiles = findImportFiles(context.paths, (filePath) => /Program\.cs$/i.test(filePath));
|
|
244
|
+
const score = controllerFiles.length > 0 && programFiles.some((filePath) => /WebApplication\.CreateBuilder|AddSwaggerGen|AddMvc/.test(readTextIfExists(filePath) || "")) ? 88 : 0;
|
|
245
|
+
return {
|
|
246
|
+
score,
|
|
247
|
+
reasons: score > 0 ? ["Found ASP.NET Core controllers and application bootstrap"] : []
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
extract(context) {
|
|
251
|
+
const controllerFiles = findImportFiles(context.paths, (filePath) => /Controller\.cs$/i.test(filePath));
|
|
252
|
+
const featureFiles = buildDotnetFileIndex(context.paths).files.map((filePath) => ({ filePath, text: readTextIfExists(filePath) || "" }));
|
|
253
|
+
const findings = [];
|
|
254
|
+
const candidates = { capabilities: [], routes: [], stacks: [] };
|
|
255
|
+
|
|
256
|
+
for (const filePath of controllerFiles) {
|
|
257
|
+
const text = readTextIfExists(filePath) || "";
|
|
258
|
+
const routes = parseControllerRoutes(filePath, text, featureFiles, context.paths.repoRoot);
|
|
259
|
+
if (routes.length === 0) continue;
|
|
260
|
+
findings.push({
|
|
261
|
+
kind: "aspnet_controller",
|
|
262
|
+
file: relativeTo(context.paths.repoRoot, filePath),
|
|
263
|
+
route_count: routes.length
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
candidates.capabilities.push(...routes.map((route) => makeCandidateRecord({
|
|
267
|
+
kind: "capability",
|
|
268
|
+
idHint: inferRouteCapabilityId(route),
|
|
269
|
+
label: route.handler_hint ? titleCase(route.handler_hint) : `${route.method} ${route.path}`,
|
|
270
|
+
confidence: "high",
|
|
271
|
+
sourceKind: "route_code",
|
|
272
|
+
provenance: route.provenance,
|
|
273
|
+
endpoint: { method: route.method, path: route.path },
|
|
274
|
+
path_params: route.path_params,
|
|
275
|
+
query_params: route.query_params,
|
|
276
|
+
header_params: [],
|
|
277
|
+
input_fields: route.input_fields,
|
|
278
|
+
output_fields: route.output_fields,
|
|
279
|
+
auth_hint: route.auth_hint,
|
|
280
|
+
entity_id: explicitEntityId(route.controller, route.handler_hint, route.path),
|
|
281
|
+
controller: route.controller,
|
|
282
|
+
return_type: route.return_type,
|
|
283
|
+
body_type: route.body_type,
|
|
284
|
+
track: "api"
|
|
285
|
+
})));
|
|
286
|
+
|
|
287
|
+
candidates.routes.push(...routes.map((route) => ({
|
|
288
|
+
path: route.path,
|
|
289
|
+
method: route.method,
|
|
290
|
+
confidence: "high",
|
|
291
|
+
source_kind: "route_code",
|
|
292
|
+
provenance: route.provenance
|
|
293
|
+
})));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
candidates.capabilities = dedupeCandidateRecords(candidates.capabilities, (record) => record.id_hint);
|
|
297
|
+
candidates.routes = dedupeCandidateRecords(
|
|
298
|
+
candidates.routes.map((route) => ({ ...route, id_hint: `${route.method}_${route.path}` })),
|
|
299
|
+
(record) => `${record.method}:${record.path}:${record.source_kind}`
|
|
300
|
+
).map(({ id_hint, ...route }) => route);
|
|
301
|
+
candidates.stacks = ["aspnet_core"];
|
|
302
|
+
return { findings, candidates };
|
|
303
|
+
}
|
|
304
|
+
};
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
dedupeCandidateRecords,
|
|
5
|
+
findImportFiles,
|
|
6
|
+
inferApiEntityIdFromPath,
|
|
7
|
+
inferRouteCapabilityId,
|
|
8
|
+
makeCandidateRecord,
|
|
9
|
+
normalizeOpenApiPath,
|
|
10
|
+
readTextIfExists,
|
|
11
|
+
relativeTo,
|
|
12
|
+
titleCase
|
|
13
|
+
} from "../../core/shared.js";
|
|
14
|
+
|
|
15
|
+
function splitClassBlocks(text) {
|
|
16
|
+
const lines = String(text || "").split(/\r?\n/);
|
|
17
|
+
const blocks = [];
|
|
18
|
+
let current = null;
|
|
19
|
+
let headerLines = null;
|
|
20
|
+
|
|
21
|
+
for (const line of lines) {
|
|
22
|
+
if (headerLines) {
|
|
23
|
+
headerLines.push(line);
|
|
24
|
+
if (line.includes("):")) {
|
|
25
|
+
const header = headerLines.join(" ");
|
|
26
|
+
const match = header.match(/^class\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*?)\)\s*:/);
|
|
27
|
+
if (match) {
|
|
28
|
+
if (current) blocks.push(current);
|
|
29
|
+
current = {
|
|
30
|
+
name: match[1],
|
|
31
|
+
bases: match[2],
|
|
32
|
+
lines: [...headerLines]
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
headerLines = null;
|
|
36
|
+
}
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const match = line.match(/^class\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([^)]*)\)\s*:/);
|
|
41
|
+
if (match) {
|
|
42
|
+
if (current) blocks.push(current);
|
|
43
|
+
current = {
|
|
44
|
+
name: match[1],
|
|
45
|
+
bases: match[2],
|
|
46
|
+
lines: [line]
|
|
47
|
+
};
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (/^class\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(/.test(line)) {
|
|
52
|
+
headerLines = [line];
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (current) current.lines.push(line);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (current) blocks.push(current);
|
|
60
|
+
return blocks;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function moduleNameForFile(repoRoot, filePath) {
|
|
64
|
+
return relativeTo(repoRoot, filePath)
|
|
65
|
+
.replace(/\.py$/i, "")
|
|
66
|
+
.replace(/\//g, ".");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function routeRegexToPath(regexText) {
|
|
70
|
+
const normalized = String(regexText || "")
|
|
71
|
+
.replace(/^\^/, "")
|
|
72
|
+
.replace(/\$$/, "")
|
|
73
|
+
.replace(/\/\?\$$/, "")
|
|
74
|
+
.replace(/\(\?P<([A-Za-z_][A-Za-z0-9_]*)>[^)]+\)/g, "{$1}")
|
|
75
|
+
.replace(/\/\?/g, "/")
|
|
76
|
+
.replace(/\?/g, "")
|
|
77
|
+
.replace(/\\\//g, "/");
|
|
78
|
+
const trimmed = normalized.replace(/\/+$/, "");
|
|
79
|
+
return trimmed.startsWith("/") ? (trimmed || "/") : `/${trimmed || ""}`.replace(/\/+$/, "") || "/";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function permissionAuthHint(permissionText, method) {
|
|
83
|
+
const raw = String(permissionText || "");
|
|
84
|
+
if (/AllowAny/.test(raw)) return "public";
|
|
85
|
+
if (/IsAuthenticatedOrReadOnly/.test(raw)) {
|
|
86
|
+
return method === "GET" ? "public" : "secured";
|
|
87
|
+
}
|
|
88
|
+
if (/IsAuthenticated/.test(raw)) return "secured";
|
|
89
|
+
return "unknown";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function buildViewIndex(paths) {
|
|
93
|
+
const viewFiles = findImportFiles(paths, (filePath) => /\/views\.py$/i.test(filePath));
|
|
94
|
+
const index = new Map();
|
|
95
|
+
|
|
96
|
+
for (const filePath of viewFiles) {
|
|
97
|
+
const text = readTextIfExists(filePath);
|
|
98
|
+
for (const block of splitClassBlocks(text)) {
|
|
99
|
+
const body = block.lines.join("\n");
|
|
100
|
+
index.set(block.name, {
|
|
101
|
+
name: block.name,
|
|
102
|
+
filePath,
|
|
103
|
+
body,
|
|
104
|
+
bases: block.bases,
|
|
105
|
+
serializer_class: body.match(/serializer_class\s*=\s*([A-Za-z_][A-Za-z0-9_]*)/)?.[1] || null,
|
|
106
|
+
lookup_field: body.match(/lookup_field\s*=\s*['"]([^'"]+)['"]/)?.[1] || "id",
|
|
107
|
+
permission_classes: body.match(/permission_classes\s*=\s*\(([\s\S]{0,120}?)\)/)?.[1] || "",
|
|
108
|
+
methods: [...body.matchAll(/^\s+def\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(/gm)].map((entry) => entry[1]),
|
|
109
|
+
moduleDir: path.dirname(filePath)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return index;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function viewClassRoutes(basePath, viewMeta) {
|
|
118
|
+
const routes = [];
|
|
119
|
+
const methods = new Set(viewMeta.methods || []);
|
|
120
|
+
const baseNames = String(viewMeta.bases || "");
|
|
121
|
+
const authFor = (method) => permissionAuthHint(viewMeta.permission_classes, method);
|
|
122
|
+
|
|
123
|
+
if (/RetrieveUpdateAPIView/.test(baseNames)) {
|
|
124
|
+
routes.push({ method: "GET", path: basePath, auth_hint: authFor("GET") });
|
|
125
|
+
routes.push({ method: "PUT", path: basePath, auth_hint: authFor("PUT") });
|
|
126
|
+
return routes;
|
|
127
|
+
}
|
|
128
|
+
if (/ListCreateAPIView/.test(baseNames)) {
|
|
129
|
+
routes.push({ method: "GET", path: basePath, auth_hint: authFor("GET") });
|
|
130
|
+
routes.push({ method: "POST", path: basePath, auth_hint: authFor("POST") });
|
|
131
|
+
return routes;
|
|
132
|
+
}
|
|
133
|
+
if (/DestroyAPIView/.test(baseNames)) {
|
|
134
|
+
routes.push({ method: "DELETE", path: basePath, auth_hint: authFor("DELETE") });
|
|
135
|
+
return routes;
|
|
136
|
+
}
|
|
137
|
+
if (/ListAPIView/.test(baseNames)) {
|
|
138
|
+
routes.push({ method: "GET", path: basePath, auth_hint: authFor("GET") });
|
|
139
|
+
return routes;
|
|
140
|
+
}
|
|
141
|
+
if (/RetrieveAPIView/.test(baseNames)) {
|
|
142
|
+
routes.push({ method: "GET", path: basePath, auth_hint: authFor("GET") });
|
|
143
|
+
return routes;
|
|
144
|
+
}
|
|
145
|
+
for (const [methodName, httpMethod] of [["get", "GET"], ["post", "POST"], ["put", "PUT"], ["patch", "PATCH"], ["delete", "DELETE"]]) {
|
|
146
|
+
if (methods.has(methodName)) {
|
|
147
|
+
routes.push({ method: httpMethod, path: basePath, auth_hint: authFor(httpMethod) });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return routes;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function viewSetRoutes(prefix, viewMeta) {
|
|
154
|
+
const routes = [];
|
|
155
|
+
const body = viewMeta.body || "";
|
|
156
|
+
const lookupField = viewMeta.lookup_field || "id";
|
|
157
|
+
const collectionPath = `${prefix}`.replace(/\/+$/, "") || "/";
|
|
158
|
+
const memberPath = `${collectionPath}/{${lookupField}}`.replace(/\/+$/, "") || "/";
|
|
159
|
+
const authFor = (method) => permissionAuthHint(viewMeta.permission_classes, method);
|
|
160
|
+
|
|
161
|
+
if (/ListModelMixin/.test(viewMeta.bases) || /\bdef\s+list\s*\(/.test(body)) {
|
|
162
|
+
routes.push({ method: "GET", path: collectionPath, auth_hint: authFor("GET") });
|
|
163
|
+
}
|
|
164
|
+
if (/CreateModelMixin/.test(viewMeta.bases) || /\bdef\s+create\s*\(/.test(body)) {
|
|
165
|
+
routes.push({ method: "POST", path: collectionPath, auth_hint: authFor("POST") });
|
|
166
|
+
}
|
|
167
|
+
if (/RetrieveModelMixin/.test(viewMeta.bases) || /\bdef\s+retrieve\s*\(/.test(body)) {
|
|
168
|
+
routes.push({ method: "GET", path: memberPath, auth_hint: authFor("GET") });
|
|
169
|
+
}
|
|
170
|
+
if (/UpdateModelMixin/.test(viewMeta.bases) || /\bdef\s+update\s*\(/.test(body)) {
|
|
171
|
+
routes.push({ method: "PUT", path: memberPath, auth_hint: authFor("PUT") });
|
|
172
|
+
}
|
|
173
|
+
if (/DestroyModelMixin/.test(viewMeta.bases) || /\bdef\s+destroy\s*\(/.test(body)) {
|
|
174
|
+
routes.push({ method: "DELETE", path: memberPath, auth_hint: authFor("DELETE") });
|
|
175
|
+
}
|
|
176
|
+
return routes;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function explicitHandlerHint(viewClassName, method, routePath) {
|
|
180
|
+
if (viewClassName === "ProfileFollowAPIView") {
|
|
181
|
+
return method === "POST" ? "follow_profile" : method === "DELETE" ? "unfollow_profile" : null;
|
|
182
|
+
}
|
|
183
|
+
if (viewClassName === "ArticlesFavoriteAPIView") {
|
|
184
|
+
return method === "POST" ? "favorite_article" : method === "DELETE" ? "unfavorite_article" : null;
|
|
185
|
+
}
|
|
186
|
+
if (viewClassName === "ArticlesFeedAPIView") {
|
|
187
|
+
return "feed_article";
|
|
188
|
+
}
|
|
189
|
+
if (viewClassName === "LoginAPIView") {
|
|
190
|
+
return "sign_in_account";
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function parseUrlModule(filePath, repoRoot, moduleMap, viewIndex, prefix = "", visited = new Set()) {
|
|
196
|
+
const moduleName = moduleNameForFile(repoRoot, filePath);
|
|
197
|
+
const visitKey = `${moduleName}:${prefix}`;
|
|
198
|
+
if (visited.has(visitKey)) return [];
|
|
199
|
+
visited.add(visitKey);
|
|
200
|
+
|
|
201
|
+
const text = readTextIfExists(filePath) || "";
|
|
202
|
+
const routes = [];
|
|
203
|
+
const routerRegistrations = [...text.matchAll(/router\.register\(\s*r?['"]([^'"]+)['"]\s*,\s*([A-Za-z_][A-Za-z0-9_]*)/g)]
|
|
204
|
+
.map((entry) => ({ resource: entry[1], viewClass: entry[2] }));
|
|
205
|
+
|
|
206
|
+
for (const match of text.matchAll(/url\(\s*r['"]([^'"]+)['"]\s*,\s*include\(\s*['"]([^'"]+)['"]/g)) {
|
|
207
|
+
const routePrefix = routeRegexToPath(match[1]);
|
|
208
|
+
const includeModule = match[2];
|
|
209
|
+
const includedFile = moduleMap.get(includeModule);
|
|
210
|
+
if (!includedFile) continue;
|
|
211
|
+
routes.push(...parseUrlModule(includedFile, repoRoot, moduleMap, viewIndex, `${prefix}${routePrefix}`, visited));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (/include\(\s*router\.urls\s*\)/.test(text)) {
|
|
215
|
+
for (const registration of routerRegistrations) {
|
|
216
|
+
const viewMeta = viewIndex.get(registration.viewClass);
|
|
217
|
+
if (!viewMeta) continue;
|
|
218
|
+
for (const route of viewSetRoutes(`${prefix}/${registration.resource}`.replace(/\/+/g, "/"), viewMeta)) {
|
|
219
|
+
routes.push({
|
|
220
|
+
...route,
|
|
221
|
+
view_class: registration.viewClass,
|
|
222
|
+
serializer_class: viewMeta.serializer_class,
|
|
223
|
+
handler_hint: null,
|
|
224
|
+
provenance: `${relativeTo(repoRoot, filePath)}#${route.method} ${route.path}`
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
for (const match of text.matchAll(/url\(\s*r['"]([^'"]+)['"]\s*,\s*([A-Za-z_][A-Za-z0-9_]*)\.as_view\(\)\s*\)/g)) {
|
|
231
|
+
const routePath = `${prefix}${routeRegexToPath(match[1])}`.replace(/\/+/g, "/").replace(/\/+$/, "") || "/";
|
|
232
|
+
const viewClassName = match[2];
|
|
233
|
+
const viewMeta = viewIndex.get(viewClassName);
|
|
234
|
+
if (!viewMeta) continue;
|
|
235
|
+
for (const route of viewClassRoutes(routePath, viewMeta)) {
|
|
236
|
+
routes.push({
|
|
237
|
+
...route,
|
|
238
|
+
view_class: viewClassName,
|
|
239
|
+
serializer_class: viewMeta.serializer_class,
|
|
240
|
+
handler_hint: explicitHandlerHint(viewClassName, route.method, route.path),
|
|
241
|
+
provenance: `${relativeTo(repoRoot, filePath)}#${route.method} ${route.path}`
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return routes;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export const djangoRoutesExtractor = {
|
|
250
|
+
id: "api.django-routes",
|
|
251
|
+
track: "api",
|
|
252
|
+
detect(context) {
|
|
253
|
+
const manageFiles = findImportFiles(context.paths, (filePath) => /\/manage\.py$/i.test(filePath));
|
|
254
|
+
const urlFiles = findImportFiles(context.paths, (filePath) => /\/urls\.py$/i.test(filePath));
|
|
255
|
+
const score = manageFiles.length > 0 && urlFiles.length > 0 ? 90 : 0;
|
|
256
|
+
return {
|
|
257
|
+
score,
|
|
258
|
+
reasons: score > 0 ? ["Found Django manage.py and urls.py routing files"] : []
|
|
259
|
+
};
|
|
260
|
+
},
|
|
261
|
+
extract(context) {
|
|
262
|
+
const urlFiles = findImportFiles(context.paths, (filePath) => /\/urls\.py$/i.test(filePath));
|
|
263
|
+
const moduleMap = new Map(urlFiles.map((filePath) => [moduleNameForFile(context.paths.repoRoot, filePath), filePath]));
|
|
264
|
+
const viewIndex = buildViewIndex(context.paths);
|
|
265
|
+
const rootFiles = urlFiles.filter((filePath) => !/\/apps\//.test(filePath));
|
|
266
|
+
const findings = [];
|
|
267
|
+
const candidates = { capabilities: [], routes: [], stacks: [] };
|
|
268
|
+
|
|
269
|
+
for (const rootFile of rootFiles) {
|
|
270
|
+
let routes = parseUrlModule(rootFile, context.paths.repoRoot, moduleMap, viewIndex);
|
|
271
|
+
if (routes.some((route) => normalizeOpenApiPath(route.path).startsWith("/api/"))) {
|
|
272
|
+
routes = routes.filter((route) => normalizeOpenApiPath(route.path).startsWith("/api/"));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
findings.push({
|
|
276
|
+
kind: "django_routes",
|
|
277
|
+
file: relativeTo(context.paths.repoRoot, rootFile),
|
|
278
|
+
route_count: routes.length
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
candidates.capabilities.push(...routes.map((route) => makeCandidateRecord({
|
|
282
|
+
kind: "capability",
|
|
283
|
+
idHint: inferRouteCapabilityId(route),
|
|
284
|
+
label: route.handler_hint ? titleCase(route.handler_hint) : `${route.method} ${route.path}`,
|
|
285
|
+
confidence: "high",
|
|
286
|
+
sourceKind: "route_code",
|
|
287
|
+
provenance: route.provenance,
|
|
288
|
+
endpoint: { method: route.method, path: normalizeOpenApiPath(route.path) },
|
|
289
|
+
path_params: [...normalizeOpenApiPath(route.path).matchAll(/\{([^}]+)\}/g)].map((entry) => ({ name: entry[1], required: true, type: null })),
|
|
290
|
+
query_params: [],
|
|
291
|
+
header_params: [],
|
|
292
|
+
input_fields: [],
|
|
293
|
+
output_fields: [],
|
|
294
|
+
auth_hint: route.auth_hint || "unknown",
|
|
295
|
+
entity_id: inferApiEntityIdFromPath(route.path),
|
|
296
|
+
view_class: route.view_class,
|
|
297
|
+
serializer_class: route.serializer_class,
|
|
298
|
+
track: "api"
|
|
299
|
+
})));
|
|
300
|
+
|
|
301
|
+
candidates.routes.push(...routes.map((route) => ({
|
|
302
|
+
path: normalizeOpenApiPath(route.path),
|
|
303
|
+
method: route.method,
|
|
304
|
+
confidence: "high",
|
|
305
|
+
source_kind: "route_code",
|
|
306
|
+
provenance: route.provenance
|
|
307
|
+
})));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
candidates.capabilities = dedupeCandidateRecords(candidates.capabilities, (record) => record.id_hint);
|
|
311
|
+
candidates.routes = dedupeCandidateRecords(
|
|
312
|
+
candidates.routes.map((route) => ({ ...route, id_hint: `${route.method}_${route.path}` })),
|
|
313
|
+
(record) => `${record.method}:${record.path}:${record.source_kind}`
|
|
314
|
+
).map(({ id_hint, ...route }) => route);
|
|
315
|
+
candidates.stacks = ["django"];
|
|
316
|
+
return { findings, candidates };
|
|
317
|
+
}
|
|
318
|
+
};
|