@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,213 @@
|
|
|
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 buildJavaFileIndex(paths) {
|
|
14
|
+
const files = findImportFiles(paths, (filePath) => /\.java$/i.test(filePath));
|
|
15
|
+
return files.map((filePath) => ({
|
|
16
|
+
filePath,
|
|
17
|
+
relativePath: relativeTo(paths.repoRoot, filePath),
|
|
18
|
+
text: readTextIfExists(filePath) || ""
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function explicitHandlerHint(methodName, routePath, httpMethod) {
|
|
23
|
+
const low = String(methodName || "").toLowerCase();
|
|
24
|
+
if (httpMethod === "GET" && /\/articles\/feed$/.test(routePath)) return "feed_article";
|
|
25
|
+
if (httpMethod === "POST" && /\/articles\/\{slug\}\/favorite$/.test(routePath)) return "favorite_article";
|
|
26
|
+
if (httpMethod === "DELETE" && /\/articles\/\{slug\}\/favorite$/.test(routePath)) return "unfavorite_article";
|
|
27
|
+
if (httpMethod === "GET" && /\/articles\/\{slug\}\/comments$/.test(routePath)) return "list_comments";
|
|
28
|
+
if (httpMethod === "POST" && /\/articles\/\{slug\}\/comments$/.test(routePath)) return "create_comment";
|
|
29
|
+
if (httpMethod === "DELETE" && /\/articles\/\{slug\}\/comments\/\{id\}$/.test(routePath)) return "delete_comment";
|
|
30
|
+
if (httpMethod === "GET" && /\/profiles\/\{username\}$/.test(routePath)) return "get_profile";
|
|
31
|
+
if (httpMethod === "POST" && /\/profiles\/\{username\}\/follow$/.test(routePath)) return "follow_profile";
|
|
32
|
+
if (httpMethod === "DELETE" && /\/profiles\/\{username\}\/follow$/.test(routePath)) return "unfollow_profile";
|
|
33
|
+
if (httpMethod === "POST" && /\/users\/login$/.test(routePath)) return "sign_in_account";
|
|
34
|
+
if (httpMethod === "POST" && routePath === "/users") return "create_user";
|
|
35
|
+
if (httpMethod === "GET" && routePath === "/user") return "get_user";
|
|
36
|
+
if ((httpMethod === "PUT" || httpMethod === "PATCH") && routePath === "/user") return "update_user";
|
|
37
|
+
if (httpMethod === "GET" && routePath === "/tags") return "list_tags";
|
|
38
|
+
if (httpMethod === "GET" && /\/articles\/\{slug\}$/.test(routePath)) return "get_article";
|
|
39
|
+
if (httpMethod === "GET" && routePath === "/articles") return "list_articles";
|
|
40
|
+
if (httpMethod === "POST" && routePath === "/articles") return "create_article";
|
|
41
|
+
if ((httpMethod === "PUT" || httpMethod === "PATCH") && /\/articles\/\{slug\}$/.test(routePath)) return "update_article";
|
|
42
|
+
if (httpMethod === "DELETE" && /\/articles\/\{slug\}$/.test(routePath)) return "delete_article";
|
|
43
|
+
if (low.includes("favorite")) return low.startsWith("un") ? "unfavorite_article" : "favorite_article";
|
|
44
|
+
if (low.includes("comment")) {
|
|
45
|
+
if (low.startsWith("delete")) return "delete_comment";
|
|
46
|
+
if (low.startsWith("add") || low.startsWith("create")) return "create_comment";
|
|
47
|
+
return "list_comments";
|
|
48
|
+
}
|
|
49
|
+
if (low.includes("follow")) return low.startsWith("un") ? "unfollow_profile" : "follow_profile";
|
|
50
|
+
if (low === "login") return "sign_in_account";
|
|
51
|
+
if (low === "register") return "create_user";
|
|
52
|
+
if (low === "current") return "get_user";
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function parseRecordFields(recordText) {
|
|
57
|
+
const ctorMatch = String(recordText || "").match(/record\s+[A-Za-z_][A-Za-z0-9_]*\s*\(([\s\S]*?)\)\s*(?:implements[^{]+)?\{/);
|
|
58
|
+
if (!ctorMatch) return [];
|
|
59
|
+
return ctorMatch[1]
|
|
60
|
+
.split(",")
|
|
61
|
+
.map((part) => part.trim())
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.map((part) => {
|
|
64
|
+
const cleaned = part.replace(/@[A-Za-z_][A-Za-z0-9_.]*(?:\((?:[^()]|\([^)]*\))*\))?\s*/g, "").trim();
|
|
65
|
+
const match = cleaned.match(/([A-Za-z0-9_<>\[\]\?\.]+)\s+([A-Za-z_][A-Za-z0-9_]*)$/);
|
|
66
|
+
return match ? { type: match[1], name: match[2] } : null;
|
|
67
|
+
})
|
|
68
|
+
.filter(Boolean);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function parseClassFields(classText) {
|
|
72
|
+
return [...String(classText || "").matchAll(/((?:\s*@[\w.]+(?:\((?:[^()]|\([^)]*\))*\))?\s*)*)\s*private\s+([A-Za-z0-9_<>\[\]\?\.]+)\s+([A-Za-z_][A-Za-z0-9_]*)\s*;/g)]
|
|
73
|
+
.map((entry) => ({
|
|
74
|
+
annotations: entry[1] || "",
|
|
75
|
+
type: entry[2],
|
|
76
|
+
name: entry[3]
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function findJavaTypeBlock(typeName, files, preferredFile = null) {
|
|
81
|
+
const bare = String(typeName || "").split(".").pop();
|
|
82
|
+
if (!bare) return null;
|
|
83
|
+
const patterns = [
|
|
84
|
+
new RegExp(`(?:public\\s+)?record\\s+${bare}\\b[\\s\\S]{0,2400}?\\n\\}`, "m"),
|
|
85
|
+
new RegExp(`(?:public\\s+)?class\\s+${bare}\\b[\\s\\S]{0,3600}?\\n\\}`, "m"),
|
|
86
|
+
new RegExp(`(?:public\\s+)?interface\\s+${bare}\\b[\\s\\S]{0,2400}?\\n\\}`, "m")
|
|
87
|
+
];
|
|
88
|
+
const orderedFiles = preferredFile
|
|
89
|
+
? [...files.filter((file) => file.filePath === preferredFile), ...files.filter((file) => file.filePath !== preferredFile)]
|
|
90
|
+
: files;
|
|
91
|
+
for (const file of orderedFiles) {
|
|
92
|
+
for (const pattern of patterns) {
|
|
93
|
+
const match = file.text.match(pattern);
|
|
94
|
+
if (match) return { filePath: file.filePath, text: match[0] };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function flattenFieldsFromType(typeName, files, preferredFile = null, seen = new Set()) {
|
|
101
|
+
const bare = String(typeName || "").split(".").pop();
|
|
102
|
+
const key = `${preferredFile || ""}:${bare}`;
|
|
103
|
+
if (!bare || seen.has(key)) return [];
|
|
104
|
+
seen.add(key);
|
|
105
|
+
const block = findJavaTypeBlock(typeName, files, preferredFile);
|
|
106
|
+
if (!block) return [];
|
|
107
|
+
const recordFields = parseRecordFields(block.text);
|
|
108
|
+
if (recordFields.length > 0) return [...new Set(recordFields.map((field) => field.name))];
|
|
109
|
+
return [...new Set(parseClassFields(block.text).map((field) => field.name))];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function parseQueryParams(parameters) {
|
|
113
|
+
return [...String(parameters || "").matchAll(/@QueryValue(?:\(value\s*=\s*"([^"]+)".*?\))?\s+@Nullable\s+([A-Za-z0-9_<>\[\]\?\.]+)\s+([A-Za-z_][A-Za-z0-9_]*)|@QueryValue(?:\(value\s*=\s*"([^"]+)".*?\))?\s+([A-Za-z0-9_<>\[\]\?\.]+)\s+([A-Za-z_][A-Za-z0-9_]*)/g)]
|
|
114
|
+
.map((entry) => ({
|
|
115
|
+
name: entry[1] || entry[4] || entry[3] || entry[6],
|
|
116
|
+
required: false,
|
|
117
|
+
type: entry[2] || entry[5] || null
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function parsePathParams(parameters) {
|
|
122
|
+
return [...String(parameters || "").matchAll(/@PathVariable\("([^"]+)"\)\s+([A-Za-z0-9_<>\[\]\?\.]+)\s+([A-Za-z_][A-Za-z0-9_]*)/g)]
|
|
123
|
+
.map((entry) => ({ name: entry[1] || entry[3], required: true, type: entry[2] || null }));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function parseBodyType(parameters) {
|
|
127
|
+
const match = String(parameters || "").match(/@Body\s+([A-Za-z0-9_<>\[\]\?\.]+)\s+([A-Za-z_][A-Za-z0-9_]*)/);
|
|
128
|
+
return match ? match[1] : null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function parseMicronautRoutes(files, repoRoot) {
|
|
132
|
+
const opFiles = files.filter((file) => /\/api\/operation\/.+Operations\.java$/.test(file.relativePath) || /io\.micronaut\.http\.annotation\./.test(file.text));
|
|
133
|
+
const routes = [];
|
|
134
|
+
const methodPattern = /((?:\s*@[\w.]+(?:\((?:[^()]|\([^)]*\))*\))?\s*)+)\s*(?:public\s+)?(?:default\s+)?([A-Za-z0-9_<>\[\]\?., ]+)\s+([A-Za-z_][A-Za-z0-9_]*)\(([\s\S]*?)\)\s*;/g;
|
|
135
|
+
for (const file of opFiles) {
|
|
136
|
+
for (const match of file.text.matchAll(methodPattern)) {
|
|
137
|
+
const [, annotations, returnType, methodName, parameters] = match;
|
|
138
|
+
const verb = annotations.match(/@(Get|Post|Put|Patch|Delete)\(/)?.[1];
|
|
139
|
+
const pathRaw = annotations.match(/@(Get|Post|Put|Patch|Delete)\("([^"]+)"\)/)?.[2];
|
|
140
|
+
if (!verb || !pathRaw) continue;
|
|
141
|
+
const pathValue = normalizeOpenApiPath(pathRaw.replace(/\{\?[^}]+\}/g, ""));
|
|
142
|
+
const bodyType = parseBodyType(parameters);
|
|
143
|
+
routes.push({
|
|
144
|
+
method: verb.toUpperCase(),
|
|
145
|
+
path: pathValue,
|
|
146
|
+
handler_hint: explicitHandlerHint(methodName, pathValue, verb.toUpperCase()),
|
|
147
|
+
controller: file.relativePath.split("/").pop()?.replace(/\.java$/, "") || "MicronautOperations",
|
|
148
|
+
action: methodName,
|
|
149
|
+
auth_hint: pathValue === "/users/login" || pathValue === "/users" || pathValue === "/tags" || pathValue === "/articles" || /^\/profiles\/\{username\}$/.test(pathValue) ? "public" : "secured",
|
|
150
|
+
path_params: parsePathParams(parameters),
|
|
151
|
+
query_params: parseQueryParams(parameters),
|
|
152
|
+
header_params: [],
|
|
153
|
+
input_fields: bodyType ? flattenFieldsFromType(bodyType, files, file.filePath) : [],
|
|
154
|
+
output_fields: flattenFieldsFromType(returnType, files, file.filePath),
|
|
155
|
+
provenance: `${relativeTo(repoRoot, file.filePath)}#${verb.toUpperCase()} ${pathValue}`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return routes;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export const micronautExtractor = {
|
|
163
|
+
id: "api.micronaut",
|
|
164
|
+
track: "api",
|
|
165
|
+
detect(context) {
|
|
166
|
+
const javaFiles = findImportFiles(context.paths, (filePath) => /\.java$/i.test(filePath));
|
|
167
|
+
const count = javaFiles.filter((filePath) => /io\.micronaut\.http\.annotation|@Controller\(|@Get\(|@Post\(|@Put\(|@Delete\(/.test(readTextIfExists(filePath) || "")).length;
|
|
168
|
+
return {
|
|
169
|
+
score: count > 0 ? 95 : 0,
|
|
170
|
+
reasons: count > 0 ? ["Found Micronaut HTTP annotations or operation interfaces"] : []
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
extract(context) {
|
|
174
|
+
const javaFiles = buildJavaFileIndex(context.paths);
|
|
175
|
+
const routes = parseMicronautRoutes(javaFiles, context.paths.repoRoot);
|
|
176
|
+
const findings = [];
|
|
177
|
+
const candidates = { capabilities: [], routes: [], stacks: [] };
|
|
178
|
+
if (routes.length > 0) {
|
|
179
|
+
findings.push({
|
|
180
|
+
kind: "micronaut_routes",
|
|
181
|
+
route_count: routes.length,
|
|
182
|
+
files: [...new Set(routes.map((route) => route.provenance.split("#")[0]))]
|
|
183
|
+
});
|
|
184
|
+
candidates.stacks.push("micronaut");
|
|
185
|
+
}
|
|
186
|
+
candidates.capabilities.push(...routes.map((route) => makeCandidateRecord({
|
|
187
|
+
kind: "capability",
|
|
188
|
+
idHint: inferRouteCapabilityId(route),
|
|
189
|
+
label: route.handler_hint ? titleCase(route.handler_hint) : `${route.method} ${route.path}`,
|
|
190
|
+
confidence: "high",
|
|
191
|
+
sourceKind: "route_code",
|
|
192
|
+
provenance: route.provenance,
|
|
193
|
+
endpoint: { method: route.method, path: route.path },
|
|
194
|
+
path_params: route.path_params,
|
|
195
|
+
query_params: route.query_params,
|
|
196
|
+
header_params: route.header_params,
|
|
197
|
+
input_fields: route.input_fields,
|
|
198
|
+
output_fields: route.output_fields,
|
|
199
|
+
auth_hint: route.auth_hint,
|
|
200
|
+
entity_id: route.handler_hint === "sign_in_account" ? "entity_account" : inferApiEntityIdFromPath(route.path),
|
|
201
|
+
track: "api"
|
|
202
|
+
})));
|
|
203
|
+
candidates.routes.push(...routes.map((route) => ({
|
|
204
|
+
path: route.path,
|
|
205
|
+
method: route.method,
|
|
206
|
+
confidence: "high",
|
|
207
|
+
source_kind: "route_code",
|
|
208
|
+
provenance: route.provenance
|
|
209
|
+
})));
|
|
210
|
+
candidates.capabilities = dedupeCandidateRecords(candidates.capabilities, (record) => record.id_hint);
|
|
211
|
+
return { findings, candidates };
|
|
212
|
+
}
|
|
213
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { inferNextApiRoutes, inferRouteCapabilityId, makeCandidateRecord, normalizeOpenApiPath, relativeTo } from "../../core/shared.js";
|
|
2
|
+
|
|
3
|
+
export const nextRouteExtractor = {
|
|
4
|
+
id: "api.next-route",
|
|
5
|
+
track: "api",
|
|
6
|
+
detect(context) {
|
|
7
|
+
const routes = inferNextApiRoutes(context.paths.workspaceRoot, context.helpers);
|
|
8
|
+
return {
|
|
9
|
+
score: routes.length > 0 ? 95 : 0,
|
|
10
|
+
reasons: routes.length > 0 ? ["Found Next.js app/api route handlers"] : []
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
extract(context) {
|
|
14
|
+
const routes = inferNextApiRoutes(context.paths.workspaceRoot, context.helpers);
|
|
15
|
+
const findings = [];
|
|
16
|
+
const candidates = { capabilities: [], routes: [], stacks: [] };
|
|
17
|
+
if (routes.length > 0) {
|
|
18
|
+
findings.push({
|
|
19
|
+
kind: "route_inventory",
|
|
20
|
+
files: [...new Set(routes.map((route) => relativeTo(context.paths.repoRoot, route.file)))],
|
|
21
|
+
route_count: routes.length
|
|
22
|
+
});
|
|
23
|
+
candidates.capabilities.push(...routes.map((route) => makeCandidateRecord({
|
|
24
|
+
kind: "capability",
|
|
25
|
+
idHint: inferRouteCapabilityId(route),
|
|
26
|
+
label: `${route.method} ${route.path}`,
|
|
27
|
+
confidence: "medium",
|
|
28
|
+
sourceKind: "route_code",
|
|
29
|
+
provenance: `${relativeTo(context.paths.repoRoot, route.file)}#${route.method} ${route.path}`,
|
|
30
|
+
endpoint: { method: route.method, path: normalizeOpenApiPath(route.path) },
|
|
31
|
+
path_params: (route.path_params || []).map((name) => ({ name, required: true, type: null })),
|
|
32
|
+
query_params: (route.query_params || []).map((name) => ({ name, required: false, type: null })),
|
|
33
|
+
header_params: [],
|
|
34
|
+
input_fields: [],
|
|
35
|
+
output_fields: route.output_fields || [],
|
|
36
|
+
auth_hint: route.auth_hint || "unknown",
|
|
37
|
+
track: "api"
|
|
38
|
+
})));
|
|
39
|
+
candidates.routes.push(...routes.map((route) => ({
|
|
40
|
+
path: normalizeOpenApiPath(route.path),
|
|
41
|
+
method: route.method,
|
|
42
|
+
confidence: "medium",
|
|
43
|
+
source_kind: "route_code",
|
|
44
|
+
provenance: `${relativeTo(context.paths.repoRoot, route.file)}#${route.method} ${route.path}`
|
|
45
|
+
})));
|
|
46
|
+
candidates.stacks.push("next_app_router");
|
|
47
|
+
}
|
|
48
|
+
return { findings, candidates };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { inferCapabilityEntityId, inferFormDataFields, inferInputNames, inferNextServerActionCapabilities, makeCandidateRecord, normalizeOpenApiPath, relativeTo, titleCase } from "../../core/shared.js";
|
|
2
|
+
|
|
3
|
+
export const nextServerActionExtractor = {
|
|
4
|
+
id: "api.next-server-action",
|
|
5
|
+
track: "api",
|
|
6
|
+
detect(context) {
|
|
7
|
+
const actions = inferNextServerActionCapabilities(context.paths.workspaceRoot, context.helpers);
|
|
8
|
+
return {
|
|
9
|
+
score: actions.length > 0 ? 90 : 0,
|
|
10
|
+
reasons: actions.length > 0 ? ["Found Next.js server actions"] : []
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
extract(context) {
|
|
14
|
+
const actions = inferNextServerActionCapabilities(context.paths.workspaceRoot, context.helpers);
|
|
15
|
+
const findings = [];
|
|
16
|
+
const candidates = { capabilities: [], routes: [], stacks: [] };
|
|
17
|
+
if (actions.length > 0) {
|
|
18
|
+
findings.push({
|
|
19
|
+
kind: "next_server_actions",
|
|
20
|
+
files: [...new Set(actions.map((action) => relativeTo(context.paths.repoRoot, action.file)))],
|
|
21
|
+
action_count: actions.length
|
|
22
|
+
});
|
|
23
|
+
candidates.capabilities.push(...actions.map((action) => makeCandidateRecord({
|
|
24
|
+
kind: "capability",
|
|
25
|
+
idHint: action.id_hint,
|
|
26
|
+
label: titleCase(action.id_hint.replace(/^cap_/, "")),
|
|
27
|
+
confidence: "medium",
|
|
28
|
+
sourceKind: action.source_kind,
|
|
29
|
+
provenance: `${relativeTo(context.paths.repoRoot, action.file)}#${action.function_name}`,
|
|
30
|
+
endpoint: { method: action.method, path: normalizeOpenApiPath(action.path) },
|
|
31
|
+
path_params: (action.path_params || []).map((name) => ({ name, required: true, type: null })),
|
|
32
|
+
query_params: [],
|
|
33
|
+
header_params: [],
|
|
34
|
+
input_fields: action.input_fields || [],
|
|
35
|
+
output_fields: action.output_fields || [],
|
|
36
|
+
auth_hint: action.auth_hint || "unknown",
|
|
37
|
+
entity_id: action.entity_id || inferCapabilityEntityId({ endpoint: { path: action.path }, id_hint: action.id_hint }),
|
|
38
|
+
track: "api"
|
|
39
|
+
})));
|
|
40
|
+
candidates.routes.push(...actions.map((action) => ({
|
|
41
|
+
path: normalizeOpenApiPath(action.path),
|
|
42
|
+
method: action.method,
|
|
43
|
+
confidence: "medium",
|
|
44
|
+
source_kind: action.source_kind,
|
|
45
|
+
provenance: `${relativeTo(context.paths.repoRoot, action.file)}#${action.function_name}`
|
|
46
|
+
})));
|
|
47
|
+
candidates.stacks.push("next_app_router");
|
|
48
|
+
}
|
|
49
|
+
return { findings, candidates };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { inferNextAuthCapabilities, makeCandidateRecord, normalizeOpenApiPath } from "../../core/shared.js";
|
|
2
|
+
|
|
3
|
+
export const nextAuthExtractor = {
|
|
4
|
+
id: "api.nextauth",
|
|
5
|
+
track: "api",
|
|
6
|
+
detect(context) {
|
|
7
|
+
const capabilities = inferNextAuthCapabilities(context.paths, context.helpers);
|
|
8
|
+
return {
|
|
9
|
+
score: capabilities.length > 0 ? 88 : 0,
|
|
10
|
+
reasons: capabilities.length > 0 ? ["Found NextAuth-style auth flows"] : []
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
extract(context) {
|
|
14
|
+
const capabilities = inferNextAuthCapabilities(context.paths, context.helpers);
|
|
15
|
+
const findings = [];
|
|
16
|
+
const candidates = { capabilities: [], routes: [], stacks: [] };
|
|
17
|
+
if (capabilities.length > 0) {
|
|
18
|
+
findings.push({
|
|
19
|
+
kind: "next_auth_flows",
|
|
20
|
+
files: [...new Set(capabilities.flatMap((capability) => capability.provenance || []))],
|
|
21
|
+
capability_count: capabilities.length
|
|
22
|
+
});
|
|
23
|
+
candidates.capabilities.push(...capabilities.map((capability) => makeCandidateRecord({
|
|
24
|
+
kind: "capability",
|
|
25
|
+
idHint: capability.id_hint,
|
|
26
|
+
label: capability.label,
|
|
27
|
+
confidence: "medium",
|
|
28
|
+
sourceKind: capability.source_kind,
|
|
29
|
+
provenance: capability.provenance,
|
|
30
|
+
endpoint: { method: capability.method, path: normalizeOpenApiPath(capability.path) },
|
|
31
|
+
path_params: [],
|
|
32
|
+
query_params: [],
|
|
33
|
+
header_params: [],
|
|
34
|
+
input_fields: capability.input_fields || [],
|
|
35
|
+
output_fields: capability.output_fields || [],
|
|
36
|
+
auth_hint: capability.auth_hint || "unknown",
|
|
37
|
+
entity_id: capability.entity_id,
|
|
38
|
+
target_state: capability.target_state || null,
|
|
39
|
+
track: "api"
|
|
40
|
+
})));
|
|
41
|
+
candidates.routes.push(...capabilities.map((capability) => ({
|
|
42
|
+
path: normalizeOpenApiPath(capability.path),
|
|
43
|
+
method: capability.method,
|
|
44
|
+
confidence: "medium",
|
|
45
|
+
source_kind: capability.source_kind,
|
|
46
|
+
provenance: capability.provenance
|
|
47
|
+
})));
|
|
48
|
+
candidates.stacks.push("nextauth");
|
|
49
|
+
}
|
|
50
|
+
return { findings, candidates };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
dedupeCandidateRecords,
|
|
5
|
+
findImportFiles,
|
|
6
|
+
inferApiCapabilityIdFromOperation,
|
|
7
|
+
inferApiEntityIdFromPath,
|
|
8
|
+
makeCandidateRecord,
|
|
9
|
+
normalizeOpenApiPath,
|
|
10
|
+
pluralizeCandidateTerm,
|
|
11
|
+
relativeTo,
|
|
12
|
+
titleCase
|
|
13
|
+
} from "../../core/shared.js";
|
|
14
|
+
|
|
15
|
+
function splitTopLevelProperties(block) {
|
|
16
|
+
const props = [];
|
|
17
|
+
let current = "";
|
|
18
|
+
let depth = 0;
|
|
19
|
+
let inString = false;
|
|
20
|
+
let quote = null;
|
|
21
|
+
for (let i = 0; i < block.length; i += 1) {
|
|
22
|
+
const ch = block[i];
|
|
23
|
+
const prev = block[i - 1];
|
|
24
|
+
if (inString) {
|
|
25
|
+
current += ch;
|
|
26
|
+
if (ch === quote && prev !== "\\") {
|
|
27
|
+
inString = false;
|
|
28
|
+
quote = null;
|
|
29
|
+
}
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
33
|
+
inString = true;
|
|
34
|
+
quote = ch;
|
|
35
|
+
current += ch;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (ch === "{" || ch === "[" || ch === "(") {
|
|
39
|
+
depth += 1;
|
|
40
|
+
current += ch;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (ch === "}" || ch === "]" || ch === ")") {
|
|
44
|
+
depth -= 1;
|
|
45
|
+
current += ch;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (ch === "," && depth === 0) {
|
|
49
|
+
if (current.trim()) props.push(current.trim());
|
|
50
|
+
current = "";
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
current += ch;
|
|
54
|
+
}
|
|
55
|
+
if (current.trim()) props.push(current.trim());
|
|
56
|
+
return props;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseZodObjectSchemaFields(schemaText) {
|
|
60
|
+
const schemaFields = new Map();
|
|
61
|
+
for (const match of schemaText.matchAll(/export\s+const\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*z\s*\.\s*object\s*\([^)]*?\.shape\)\s*\.pick\(\s*\{([\s\S]*?)\}\s*\)/g)) {
|
|
62
|
+
const schemaName = match[1];
|
|
63
|
+
const fields = [];
|
|
64
|
+
for (const prop of splitTopLevelProperties(match[2])) {
|
|
65
|
+
const propMatch = prop.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*:/);
|
|
66
|
+
if (propMatch) fields.push(propMatch[1]);
|
|
67
|
+
}
|
|
68
|
+
schemaFields.set(schemaName, [...new Set(fields)].sort());
|
|
69
|
+
}
|
|
70
|
+
for (const match of schemaText.matchAll(/export\s+const\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*z\s*\.\s*object\s*\(\s*\{([\s\S]*?)\}\s*\)/g)) {
|
|
71
|
+
const schemaName = match[1];
|
|
72
|
+
const fields = [];
|
|
73
|
+
for (const prop of splitTopLevelProperties(match[2])) {
|
|
74
|
+
const propMatch = prop.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*:/);
|
|
75
|
+
if (propMatch) fields.push(propMatch[1]);
|
|
76
|
+
}
|
|
77
|
+
schemaFields.set(schemaName, [...new Set(fields)].sort());
|
|
78
|
+
}
|
|
79
|
+
return schemaFields;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function extractRequestSchemaRefs(block) {
|
|
83
|
+
return {
|
|
84
|
+
body: block.match(/request\s*:\s*\{[\s\S]*?body\s*:\s*\{[\s\S]*?schema\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/m)?.[1] || null,
|
|
85
|
+
params: block.match(/request\s*:\s*\{[\s\S]*?params\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/m)?.[1] || null,
|
|
86
|
+
query: block.match(/request\s*:\s*\{[\s\S]*?query\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/m)?.[1] || null,
|
|
87
|
+
headers: block.match(/request\s*:\s*\{[\s\S]*?headers\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/m)?.[1] || null
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function extractSecurity(block) {
|
|
92
|
+
return /security\s*:\s*\[\s*\{\s*bearerAuth\s*:\s*\[\s*\]\s*\}\s*\]/m.test(block) ? ["bearerAuth"] : [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function extractTags(block) {
|
|
96
|
+
const match = block.match(/tags\s*:\s*\[([\s\S]*?)\]/m);
|
|
97
|
+
if (!match) return [];
|
|
98
|
+
return [...match[1].matchAll(/["'`]([^"'`]+)["'`]/g)].map((entry) => entry[1]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function singularStemFromSchemaRef(schemaRef) {
|
|
102
|
+
return String(schemaRef || "")
|
|
103
|
+
.replace(/(?:DataSchema|ResponseDataSchema|Schema)$/g, "")
|
|
104
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
105
|
+
.toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function inferOutputFieldsFromExpression(expression, schemaFields, entry) {
|
|
109
|
+
const trimmed = String(expression || "").trim();
|
|
110
|
+
if (!trimmed) return [];
|
|
111
|
+
const simpleRef = trimmed.match(/^([A-Za-z_][A-Za-z0-9_]*)$/);
|
|
112
|
+
if (simpleRef) {
|
|
113
|
+
return schemaFields.get(simpleRef[1]) || [];
|
|
114
|
+
}
|
|
115
|
+
const arrayRef = trimmed.match(/^z\s*\.\s*array\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)$/);
|
|
116
|
+
if (arrayRef) {
|
|
117
|
+
const base = singularStemFromSchemaRef(arrayRef[1]).replace(/_schema$/, "");
|
|
118
|
+
return [pluralizeCandidateTerm(base)];
|
|
119
|
+
}
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function extractSuccessResponseMeta(block, schemaFields, entry) {
|
|
124
|
+
const successBlockMatch = block.match(/responses\s*:\s*\{[\s\S]*?(20[0-9])\s*:\s*\{([\s\S]*?)\n\s*\}\s*(?:,|\n\s*\})/m);
|
|
125
|
+
if (!successBlockMatch) {
|
|
126
|
+
return { responseSchema: null, outputFields: [] };
|
|
127
|
+
}
|
|
128
|
+
const successBlock = successBlockMatch[2];
|
|
129
|
+
const extendMatch = successBlock.match(/schema\s*:\s*SuccessResponseSchema\s*\.extend\(\s*\{([\s\S]*?)\}\s*\)/m);
|
|
130
|
+
if (extendMatch) {
|
|
131
|
+
const dataMatch = extendMatch[1].match(/data\s*:\s*([^,\n}]+)/m);
|
|
132
|
+
const responseExpr = dataMatch ? dataMatch[1].trim() : null;
|
|
133
|
+
return {
|
|
134
|
+
responseSchema: responseExpr,
|
|
135
|
+
outputFields: responseExpr ? inferOutputFieldsFromExpression(responseExpr, schemaFields, entry) : schemaFields.get("SuccessResponseSchema") || []
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const schemaRef = successBlock.match(/schema\s*:\s*([A-Za-z_][A-Za-z0-9_]*)/m)?.[1] || null;
|
|
139
|
+
return {
|
|
140
|
+
responseSchema: schemaRef,
|
|
141
|
+
outputFields: schemaRef ? schemaFields.get(schemaRef) || [] : []
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function parseOpenApiRegisterPaths(text, schemaFields) {
|
|
146
|
+
const entries = [];
|
|
147
|
+
for (const match of text.matchAll(/registry\.registerPath\(\s*\{([\s\S]*?)\n\}\s*\);/g)) {
|
|
148
|
+
const block = match[1];
|
|
149
|
+
const methodMatch = block.match(/method\s*:\s*["'`]([A-Za-z]+)["'`]/);
|
|
150
|
+
const pathMatch = block.match(/path\s*:\s*["'`]([^"'`]+)["'`]/);
|
|
151
|
+
if (!methodMatch || !pathMatch) continue;
|
|
152
|
+
const summaryMatch = block.match(/summary\s*:\s*["'`]([^"'`]+)["'`]/);
|
|
153
|
+
const requestSchemas = extractRequestSchemaRefs(block);
|
|
154
|
+
const securitySchemes = extractSecurity(block);
|
|
155
|
+
const tags = extractTags(block);
|
|
156
|
+
const entry = {
|
|
157
|
+
method: methodMatch[1].toUpperCase(),
|
|
158
|
+
path: pathMatch[1],
|
|
159
|
+
summary: summaryMatch ? summaryMatch[1] : null,
|
|
160
|
+
tags,
|
|
161
|
+
requestSchemas,
|
|
162
|
+
security_schemes: securitySchemes
|
|
163
|
+
};
|
|
164
|
+
const responseMeta = extractSuccessResponseMeta(block, schemaFields, entry);
|
|
165
|
+
entries.push({
|
|
166
|
+
...entry,
|
|
167
|
+
requestSchema: requestSchemas.body,
|
|
168
|
+
responseSchema: responseMeta.responseSchema,
|
|
169
|
+
input_fields: requestSchemas.body ? schemaFields.get(requestSchemas.body) || [] : [],
|
|
170
|
+
query_params: requestSchemas.query ? (schemaFields.get(requestSchemas.query) || []).map((name) => ({ name, required: false, type: null })) : [],
|
|
171
|
+
path_params: requestSchemas.params
|
|
172
|
+
? (schemaFields.get(requestSchemas.params) || []).map((name) => ({ name, required: true, type: null }))
|
|
173
|
+
: [...pathMatch[1].matchAll(/\{([^}]+)\}/g)].map((param) => ({ name: param[1], required: true, type: null })),
|
|
174
|
+
header_params: requestSchemas.headers ? (schemaFields.get(requestSchemas.headers) || []).map((name) => ({ name, required: false, type: null })) : [],
|
|
175
|
+
output_fields: responseMeta.outputFields,
|
|
176
|
+
entity_id: inferApiEntityIdFromPath(pathMatch[1], { tags, summary: summaryMatch ? summaryMatch[1] : null })
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return entries;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const openApiCodeExtractor = {
|
|
183
|
+
id: "api.openapi-code",
|
|
184
|
+
track: "api",
|
|
185
|
+
detect(context) {
|
|
186
|
+
const openApiFiles = findImportFiles(context.paths, (filePath) => /src\/docs\/openapi\.(ts|js|mjs|cjs)$/i.test(filePath));
|
|
187
|
+
return {
|
|
188
|
+
score: openApiFiles.length > 0 ? 92 : 0,
|
|
189
|
+
reasons: openApiFiles.length > 0 ? ["Found code-generated OpenAPI source"] : []
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
extract(context) {
|
|
193
|
+
const openApiFiles = findImportFiles(context.paths, (filePath) => /src\/docs\/openapi\.(ts|js|mjs|cjs)$/i.test(filePath));
|
|
194
|
+
const schemaFile = findImportFiles(context.paths, (filePath) => /src\/docs\/openapi-schemas\.(ts|js|mjs|cjs)$/i.test(filePath))[0];
|
|
195
|
+
const schemaFields = schemaFile ? parseZodObjectSchemaFields(context.helpers.readTextIfExists(schemaFile) || "") : new Map();
|
|
196
|
+
const findings = [];
|
|
197
|
+
const candidates = { capabilities: [], routes: [], stacks: [] };
|
|
198
|
+
for (const filePath of openApiFiles) {
|
|
199
|
+
const provenanceBase = relativeTo(context.paths.repoRoot, filePath);
|
|
200
|
+
const parsed = parseOpenApiRegisterPaths(context.helpers.readTextIfExists(filePath) || "", schemaFields);
|
|
201
|
+
findings.push({
|
|
202
|
+
kind: "openapi_code",
|
|
203
|
+
file: provenanceBase,
|
|
204
|
+
capability_count: parsed.length
|
|
205
|
+
});
|
|
206
|
+
candidates.capabilities.push(...parsed.map((entry) => makeCandidateRecord({
|
|
207
|
+
kind: "capability",
|
|
208
|
+
idHint: inferApiCapabilityIdFromOperation(entry),
|
|
209
|
+
label: entry.summary || titleCase(inferApiCapabilityIdFromOperation(entry).replace(/^cap_/, "")),
|
|
210
|
+
confidence: "high",
|
|
211
|
+
sourceKind: "openapi",
|
|
212
|
+
provenance: `${provenanceBase}#${entry.method} ${entry.path}`,
|
|
213
|
+
endpoint: { method: entry.method, path: entry.path },
|
|
214
|
+
path_params: entry.path_params || [],
|
|
215
|
+
query_params: entry.query_params || [],
|
|
216
|
+
header_params: entry.header_params || [],
|
|
217
|
+
input_fields: entry.input_fields,
|
|
218
|
+
output_fields: entry.output_fields,
|
|
219
|
+
security_schemes: entry.security_schemes,
|
|
220
|
+
auth_hint: entry.security_schemes.length > 0 ? "secured" : "public",
|
|
221
|
+
entity_id: entry.entity_id,
|
|
222
|
+
tags: entry.tags,
|
|
223
|
+
track: "api"
|
|
224
|
+
})));
|
|
225
|
+
candidates.routes.push(...parsed.map((entry) => ({
|
|
226
|
+
path: normalizeOpenApiPath(entry.path),
|
|
227
|
+
method: entry.method,
|
|
228
|
+
confidence: "high",
|
|
229
|
+
source_kind: "openapi",
|
|
230
|
+
provenance: `${provenanceBase}#${entry.method} ${entry.path}`
|
|
231
|
+
})));
|
|
232
|
+
candidates.stacks.push("openapi_code");
|
|
233
|
+
}
|
|
234
|
+
candidates.capabilities = dedupeCandidateRecords(candidates.capabilities, (record) => record.id_hint);
|
|
235
|
+
candidates.routes = dedupeCandidateRecords(
|
|
236
|
+
candidates.routes.map((route) => ({ ...route, id_hint: `${route.method}_${route.path}` })),
|
|
237
|
+
(record) => `${record.method}:${record.path}:${record.source_kind}`
|
|
238
|
+
).map(({ id_hint, ...route }) => route);
|
|
239
|
+
candidates.stacks = [...new Set(candidates.stacks)].sort();
|
|
240
|
+
return { findings, candidates };
|
|
241
|
+
}
|
|
242
|
+
};
|