@grafema/core 0.1.0-alpha.1
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/LICENSE +190 -0
- package/README.md +76 -0
- package/dist/Orchestrator.d.ts +142 -0
- package/dist/Orchestrator.d.ts.map +1 -0
- package/dist/Orchestrator.js +481 -0
- package/dist/api/GraphAPI.d.ts +87 -0
- package/dist/api/GraphAPI.d.ts.map +1 -0
- package/dist/api/GraphAPI.js +210 -0
- package/dist/api/GuaranteeAPI.d.ts +147 -0
- package/dist/api/GuaranteeAPI.d.ts.map +1 -0
- package/dist/api/GuaranteeAPI.js +288 -0
- package/dist/core/ASTWorker.d.ts +133 -0
- package/dist/core/ASTWorker.d.ts.map +1 -0
- package/dist/core/ASTWorker.js +352 -0
- package/dist/core/ASTWorkerPool.d.ts +85 -0
- package/dist/core/ASTWorkerPool.d.ts.map +1 -0
- package/dist/core/ASTWorkerPool.js +207 -0
- package/dist/core/AnalysisQueue.d.ts +104 -0
- package/dist/core/AnalysisQueue.d.ts.map +1 -0
- package/dist/core/AnalysisQueue.js +299 -0
- package/dist/core/AnalysisWorker.d.ts +14 -0
- package/dist/core/AnalysisWorker.d.ts.map +1 -0
- package/dist/core/AnalysisWorker.js +307 -0
- package/dist/core/GraphBackend.d.ts +156 -0
- package/dist/core/GraphBackend.d.ts.map +1 -0
- package/dist/core/GraphBackend.js +85 -0
- package/dist/core/GuaranteeManager.d.ts +230 -0
- package/dist/core/GuaranteeManager.d.ts.map +1 -0
- package/dist/core/GuaranteeManager.js +352 -0
- package/dist/core/ManifestStore.d.ts +71 -0
- package/dist/core/ManifestStore.d.ts.map +1 -0
- package/dist/core/ManifestStore.js +146 -0
- package/dist/core/NodeFactory.d.ts +160 -0
- package/dist/core/NodeFactory.d.ts.map +1 -0
- package/dist/core/NodeFactory.js +137 -0
- package/dist/core/NodeId.d.ts +88 -0
- package/dist/core/NodeId.d.ts.map +1 -0
- package/dist/core/NodeId.js +170 -0
- package/dist/core/ParallelAnalyzer.d.ts +120 -0
- package/dist/core/ParallelAnalyzer.d.ts.map +1 -0
- package/dist/core/ParallelAnalyzer.js +331 -0
- package/dist/core/PriorityQueue.d.ts +106 -0
- package/dist/core/PriorityQueue.d.ts.map +1 -0
- package/dist/core/PriorityQueue.js +168 -0
- package/dist/core/Profiler.d.ts +75 -0
- package/dist/core/Profiler.d.ts.map +1 -0
- package/dist/core/Profiler.js +149 -0
- package/dist/core/QueueWorker.d.ts +12 -0
- package/dist/core/QueueWorker.d.ts.map +1 -0
- package/dist/core/QueueWorker.js +567 -0
- package/dist/core/RFDBClient.d.ts +179 -0
- package/dist/core/RFDBClient.d.ts.map +1 -0
- package/dist/core/RFDBClient.js +429 -0
- package/dist/core/Task.d.ts +56 -0
- package/dist/core/Task.d.ts.map +1 -0
- package/dist/core/Task.js +85 -0
- package/dist/core/TaskTypes.d.ts +20 -0
- package/dist/core/TaskTypes.d.ts.map +1 -0
- package/dist/core/TaskTypes.js +10 -0
- package/dist/core/VersionManager.d.ts +166 -0
- package/dist/core/VersionManager.d.ts.map +1 -0
- package/dist/core/VersionManager.js +237 -0
- package/dist/core/WorkerPool.d.ts +82 -0
- package/dist/core/WorkerPool.d.ts.map +1 -0
- package/dist/core/WorkerPool.js +109 -0
- package/dist/core/nodes/CallSiteNode.d.ts +26 -0
- package/dist/core/nodes/CallSiteNode.d.ts.map +1 -0
- package/dist/core/nodes/CallSiteNode.js +44 -0
- package/dist/core/nodes/ClassNode.d.ts +25 -0
- package/dist/core/nodes/ClassNode.d.ts.map +1 -0
- package/dist/core/nodes/ClassNode.js +40 -0
- package/dist/core/nodes/ConstantNode.d.ts +24 -0
- package/dist/core/nodes/ConstantNode.d.ts.map +1 -0
- package/dist/core/nodes/ConstantNode.js +39 -0
- package/dist/core/nodes/DatabaseQueryNode.d.ts +22 -0
- package/dist/core/nodes/DatabaseQueryNode.d.ts.map +1 -0
- package/dist/core/nodes/DatabaseQueryNode.js +37 -0
- package/dist/core/nodes/EntrypointNode.d.ts +102 -0
- package/dist/core/nodes/EntrypointNode.d.ts.map +1 -0
- package/dist/core/nodes/EntrypointNode.js +119 -0
- package/dist/core/nodes/EventListenerNode.d.ts +25 -0
- package/dist/core/nodes/EventListenerNode.d.ts.map +1 -0
- package/dist/core/nodes/EventListenerNode.js +39 -0
- package/dist/core/nodes/ExportNode.d.ts +26 -0
- package/dist/core/nodes/ExportNode.d.ts.map +1 -0
- package/dist/core/nodes/ExportNode.js +40 -0
- package/dist/core/nodes/ExternalStdioNode.d.ts +17 -0
- package/dist/core/nodes/ExternalStdioNode.d.ts.map +1 -0
- package/dist/core/nodes/ExternalStdioNode.js +26 -0
- package/dist/core/nodes/FunctionNode.d.ts +27 -0
- package/dist/core/nodes/FunctionNode.d.ts.map +1 -0
- package/dist/core/nodes/FunctionNode.js +53 -0
- package/dist/core/nodes/GuaranteeNode.d.ts +76 -0
- package/dist/core/nodes/GuaranteeNode.d.ts.map +1 -0
- package/dist/core/nodes/GuaranteeNode.js +117 -0
- package/dist/core/nodes/HttpRequestNode.d.ts +24 -0
- package/dist/core/nodes/HttpRequestNode.d.ts.map +1 -0
- package/dist/core/nodes/HttpRequestNode.js +38 -0
- package/dist/core/nodes/ImportNode.d.ts +27 -0
- package/dist/core/nodes/ImportNode.d.ts.map +1 -0
- package/dist/core/nodes/ImportNode.js +43 -0
- package/dist/core/nodes/LiteralNode.d.ts +26 -0
- package/dist/core/nodes/LiteralNode.d.ts.map +1 -0
- package/dist/core/nodes/LiteralNode.js +40 -0
- package/dist/core/nodes/MethodCallNode.d.ts +29 -0
- package/dist/core/nodes/MethodCallNode.d.ts.map +1 -0
- package/dist/core/nodes/MethodCallNode.js +47 -0
- package/dist/core/nodes/MethodNode.d.ts +29 -0
- package/dist/core/nodes/MethodNode.d.ts.map +1 -0
- package/dist/core/nodes/MethodNode.js +44 -0
- package/dist/core/nodes/ModuleNode.d.ts +29 -0
- package/dist/core/nodes/ModuleNode.d.ts.map +1 -0
- package/dist/core/nodes/ModuleNode.js +49 -0
- package/dist/core/nodes/NodeKind.d.ts +91 -0
- package/dist/core/nodes/NodeKind.d.ts.map +1 -0
- package/dist/core/nodes/NodeKind.js +146 -0
- package/dist/core/nodes/ParameterNode.d.ts +26 -0
- package/dist/core/nodes/ParameterNode.d.ts.map +1 -0
- package/dist/core/nodes/ParameterNode.js +43 -0
- package/dist/core/nodes/ScopeNode.d.ts +32 -0
- package/dist/core/nodes/ScopeNode.d.ts.map +1 -0
- package/dist/core/nodes/ScopeNode.js +47 -0
- package/dist/core/nodes/ServiceNode.d.ts +44 -0
- package/dist/core/nodes/ServiceNode.d.ts.map +1 -0
- package/dist/core/nodes/ServiceNode.js +49 -0
- package/dist/core/nodes/VariableDeclarationNode.d.ts +22 -0
- package/dist/core/nodes/VariableDeclarationNode.d.ts.map +1 -0
- package/dist/core/nodes/VariableDeclarationNode.js +38 -0
- package/dist/core/nodes/index.d.ts +25 -0
- package/dist/core/nodes/index.d.ts.map +1 -0
- package/dist/core/nodes/index.js +30 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/plugins/Plugin.d.ts +44 -0
- package/dist/plugins/Plugin.d.ts.map +1 -0
- package/dist/plugins/Plugin.js +46 -0
- package/dist/plugins/analysis/DatabaseAnalyzer.d.ts +23 -0
- package/dist/plugins/analysis/DatabaseAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/DatabaseAnalyzer.js +260 -0
- package/dist/plugins/analysis/ExpressAnalyzer.d.ts +19 -0
- package/dist/plugins/analysis/ExpressAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/ExpressAnalyzer.js +306 -0
- package/dist/plugins/analysis/ExpressRouteAnalyzer.d.ts +17 -0
- package/dist/plugins/analysis/ExpressRouteAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/ExpressRouteAnalyzer.js +308 -0
- package/dist/plugins/analysis/FetchAnalyzer.d.ts +38 -0
- package/dist/plugins/analysis/FetchAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/FetchAnalyzer.js +344 -0
- package/dist/plugins/analysis/IncrementalAnalysisPlugin.d.ts +65 -0
- package/dist/plugins/analysis/IncrementalAnalysisPlugin.d.ts.map +1 -0
- package/dist/plugins/analysis/IncrementalAnalysisPlugin.js +472 -0
- package/dist/plugins/analysis/JSASTAnalyzer.d.ts +84 -0
- package/dist/plugins/analysis/JSASTAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/JSASTAnalyzer.js +1378 -0
- package/dist/plugins/analysis/ReactAnalyzer.d.ts +90 -0
- package/dist/plugins/analysis/ReactAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/ReactAnalyzer.js +1153 -0
- package/dist/plugins/analysis/RustAnalyzer.d.ts +13 -0
- package/dist/plugins/analysis/RustAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/RustAnalyzer.js +259 -0
- package/dist/plugins/analysis/SQLiteAnalyzer.d.ts +21 -0
- package/dist/plugins/analysis/SQLiteAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/SQLiteAnalyzer.js +317 -0
- package/dist/plugins/analysis/ServiceLayerAnalyzer.d.ts +35 -0
- package/dist/plugins/analysis/ServiceLayerAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/ServiceLayerAnalyzer.js +303 -0
- package/dist/plugins/analysis/SocketIOAnalyzer.d.ts +33 -0
- package/dist/plugins/analysis/SocketIOAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/SocketIOAnalyzer.js +283 -0
- package/dist/plugins/analysis/SystemDbAnalyzer.d.ts +27 -0
- package/dist/plugins/analysis/SystemDbAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/SystemDbAnalyzer.js +211 -0
- package/dist/plugins/analysis/ast/ConditionParser.d.ts +85 -0
- package/dist/plugins/analysis/ast/ConditionParser.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/ConditionParser.js +277 -0
- package/dist/plugins/analysis/ast/ExpressionEvaluator.d.ts +15 -0
- package/dist/plugins/analysis/ast/ExpressionEvaluator.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/ExpressionEvaluator.js +91 -0
- package/dist/plugins/analysis/ast/GraphBuilder.d.ts +77 -0
- package/dist/plugins/analysis/ast/GraphBuilder.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/GraphBuilder.js +1077 -0
- package/dist/plugins/analysis/ast/OxcAdapter.d.ts +41 -0
- package/dist/plugins/analysis/ast/OxcAdapter.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/OxcAdapter.js +40 -0
- package/dist/plugins/analysis/ast/types.d.ts +346 -0
- package/dist/plugins/analysis/ast/types.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/types.js +4 -0
- package/dist/plugins/analysis/ast/visitors/ASTVisitor.d.ts +93 -0
- package/dist/plugins/analysis/ast/visitors/ASTVisitor.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/visitors/ASTVisitor.js +24 -0
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.d.ts +77 -0
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.js +377 -0
- package/dist/plugins/analysis/ast/visitors/ClassVisitor.d.ts +27 -0
- package/dist/plugins/analysis/ast/visitors/ClassVisitor.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/visitors/ClassVisitor.js +232 -0
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.d.ts +25 -0
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.js +172 -0
- package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.d.ts +29 -0
- package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.js +180 -0
- package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.d.ts +14 -0
- package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.js +200 -0
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.d.ts +45 -0
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.js +150 -0
- package/dist/plugins/analysis/ast/visitors/index.d.ts +17 -0
- package/dist/plugins/analysis/ast/visitors/index.d.ts.map +1 -0
- package/dist/plugins/analysis/ast/visitors/index.js +13 -0
- package/dist/plugins/discovery/DiscoveryPlugin.d.ts +34 -0
- package/dist/plugins/discovery/DiscoveryPlugin.d.ts.map +1 -0
- package/dist/plugins/discovery/DiscoveryPlugin.js +26 -0
- package/dist/plugins/discovery/MonorepoServiceDiscovery.d.ts +26 -0
- package/dist/plugins/discovery/MonorepoServiceDiscovery.d.ts.map +1 -0
- package/dist/plugins/discovery/MonorepoServiceDiscovery.js +79 -0
- package/dist/plugins/discovery/SimpleProjectDiscovery.d.ts +14 -0
- package/dist/plugins/discovery/SimpleProjectDiscovery.d.ts.map +1 -0
- package/dist/plugins/discovery/SimpleProjectDiscovery.js +65 -0
- package/dist/plugins/discovery/ZonServiceDiscovery.d.ts +19 -0
- package/dist/plugins/discovery/ZonServiceDiscovery.d.ts.map +1 -0
- package/dist/plugins/discovery/ZonServiceDiscovery.js +204 -0
- package/dist/plugins/enrichment/AliasTracker.d.ts +40 -0
- package/dist/plugins/enrichment/AliasTracker.d.ts.map +1 -0
- package/dist/plugins/enrichment/AliasTracker.js +290 -0
- package/dist/plugins/enrichment/HTTPConnectionEnricher.d.ts +30 -0
- package/dist/plugins/enrichment/HTTPConnectionEnricher.d.ts.map +1 -0
- package/dist/plugins/enrichment/HTTPConnectionEnricher.js +135 -0
- package/dist/plugins/enrichment/ImportExportLinker.d.ts +30 -0
- package/dist/plugins/enrichment/ImportExportLinker.d.ts.map +1 -0
- package/dist/plugins/enrichment/ImportExportLinker.js +176 -0
- package/dist/plugins/enrichment/InstanceOfResolver.d.ts +21 -0
- package/dist/plugins/enrichment/InstanceOfResolver.d.ts.map +1 -0
- package/dist/plugins/enrichment/InstanceOfResolver.js +117 -0
- package/dist/plugins/enrichment/MethodCallResolver.d.ts +41 -0
- package/dist/plugins/enrichment/MethodCallResolver.d.ts.map +1 -0
- package/dist/plugins/enrichment/MethodCallResolver.js +252 -0
- package/dist/plugins/enrichment/MountPointResolver.d.ts +26 -0
- package/dist/plugins/enrichment/MountPointResolver.d.ts.map +1 -0
- package/dist/plugins/enrichment/MountPointResolver.js +189 -0
- package/dist/plugins/enrichment/PrefixEvaluator.d.ts +89 -0
- package/dist/plugins/enrichment/PrefixEvaluator.d.ts.map +1 -0
- package/dist/plugins/enrichment/PrefixEvaluator.js +415 -0
- package/dist/plugins/enrichment/RustFFIEnricher.d.ts +25 -0
- package/dist/plugins/enrichment/RustFFIEnricher.d.ts.map +1 -0
- package/dist/plugins/enrichment/RustFFIEnricher.js +170 -0
- package/dist/plugins/enrichment/ValueDomainAnalyzer.d.ts +114 -0
- package/dist/plugins/enrichment/ValueDomainAnalyzer.d.ts.map +1 -0
- package/dist/plugins/enrichment/ValueDomainAnalyzer.js +464 -0
- package/dist/plugins/indexing/IncrementalModuleIndexer.d.ts +27 -0
- package/dist/plugins/indexing/IncrementalModuleIndexer.d.ts.map +1 -0
- package/dist/plugins/indexing/IncrementalModuleIndexer.js +238 -0
- package/dist/plugins/indexing/JSModuleIndexer.d.ts +33 -0
- package/dist/plugins/indexing/JSModuleIndexer.d.ts.map +1 -0
- package/dist/plugins/indexing/JSModuleIndexer.js +299 -0
- package/dist/plugins/indexing/RustModuleIndexer.d.ts +28 -0
- package/dist/plugins/indexing/RustModuleIndexer.d.ts.map +1 -0
- package/dist/plugins/indexing/RustModuleIndexer.js +140 -0
- package/dist/plugins/indexing/ServiceDetector.d.ts +46 -0
- package/dist/plugins/indexing/ServiceDetector.d.ts.map +1 -0
- package/dist/plugins/indexing/ServiceDetector.js +164 -0
- package/dist/plugins/validation/CallResolverValidator.d.ts +23 -0
- package/dist/plugins/validation/CallResolverValidator.d.ts.map +1 -0
- package/dist/plugins/validation/CallResolverValidator.js +108 -0
- package/dist/plugins/validation/DataFlowValidator.d.ts +24 -0
- package/dist/plugins/validation/DataFlowValidator.d.ts.map +1 -0
- package/dist/plugins/validation/DataFlowValidator.js +148 -0
- package/dist/plugins/validation/EvalBanValidator.d.ts +25 -0
- package/dist/plugins/validation/EvalBanValidator.d.ts.map +1 -0
- package/dist/plugins/validation/EvalBanValidator.js +123 -0
- package/dist/plugins/validation/GraphConnectivityValidator.d.ts +11 -0
- package/dist/plugins/validation/GraphConnectivityValidator.d.ts.map +1 -0
- package/dist/plugins/validation/GraphConnectivityValidator.js +135 -0
- package/dist/plugins/validation/SQLInjectionValidator.d.ts +43 -0
- package/dist/plugins/validation/SQLInjectionValidator.d.ts.map +1 -0
- package/dist/plugins/validation/SQLInjectionValidator.js +251 -0
- package/dist/plugins/validation/ShadowingDetector.d.ts +26 -0
- package/dist/plugins/validation/ShadowingDetector.d.ts.map +1 -0
- package/dist/plugins/validation/ShadowingDetector.js +119 -0
- package/dist/plugins/validation/TypeScriptDeadCodeValidator.d.ts +21 -0
- package/dist/plugins/validation/TypeScriptDeadCodeValidator.d.ts.map +1 -0
- package/dist/plugins/validation/TypeScriptDeadCodeValidator.js +151 -0
- package/dist/plugins/vcs/GitPlugin.d.ts +84 -0
- package/dist/plugins/vcs/GitPlugin.d.ts.map +1 -0
- package/dist/plugins/vcs/GitPlugin.js +295 -0
- package/dist/plugins/vcs/VCSPlugin.d.ts +133 -0
- package/dist/plugins/vcs/VCSPlugin.d.ts.map +1 -0
- package/dist/plugins/vcs/VCSPlugin.js +82 -0
- package/dist/plugins/vcs/index.d.ts +10 -0
- package/dist/plugins/vcs/index.d.ts.map +1 -0
- package/dist/plugins/vcs/index.js +18 -0
- package/dist/storage/backends/RFDBServerBackend.d.ts +258 -0
- package/dist/storage/backends/RFDBServerBackend.d.ts.map +1 -0
- package/dist/storage/backends/RFDBServerBackend.js +565 -0
- package/dist/storage/backends/typeValidation.d.ts +47 -0
- package/dist/storage/backends/typeValidation.d.ts.map +1 -0
- package/dist/storage/backends/typeValidation.js +137 -0
- package/dist/validation/PathValidator.d.ts +81 -0
- package/dist/validation/PathValidator.d.ts.map +1 -0
- package/dist/validation/PathValidator.js +251 -0
- package/package.json +57 -0
- package/src/.rfguard/current-session.txt +1 -0
- package/src/Orchestrator.ts +673 -0
- package/src/api/GraphAPI.ts +305 -0
- package/src/api/GuaranteeAPI.ts +401 -0
- package/src/core/ASTWorker.ts +567 -0
- package/src/core/ASTWorkerPool.ts +299 -0
- package/src/core/AnalysisQueue.ts +447 -0
- package/src/core/AnalysisWorker.ts +410 -0
- package/src/core/GraphBackend.ts +265 -0
- package/src/core/GuaranteeManager.ts +581 -0
- package/src/core/ManifestStore.ts +196 -0
- package/src/core/NodeFactory.ts +274 -0
- package/src/core/NodeId.ts +257 -0
- package/src/core/ParallelAnalyzer.ts +476 -0
- package/src/core/PriorityQueue.ts +227 -0
- package/src/core/Profiler.ts +188 -0
- package/src/core/QueueWorker.ts +780 -0
- package/src/core/Task.ts +107 -0
- package/src/core/TaskTypes.ts +40 -0
- package/src/core/VersionManager.ts +404 -0
- package/src/core/WorkerPool.ts +180 -0
- package/src/core/nodes/CallSiteNode.ts +72 -0
- package/src/core/nodes/ClassNode.ts +69 -0
- package/src/core/nodes/ConstantNode.ts +63 -0
- package/src/core/nodes/DatabaseQueryNode.ts +60 -0
- package/src/core/nodes/EntrypointNode.ts +164 -0
- package/src/core/nodes/EventListenerNode.ts +64 -0
- package/src/core/nodes/ExportNode.ts +71 -0
- package/src/core/nodes/ExternalStdioNode.ts +36 -0
- package/src/core/nodes/FunctionNode.ts +78 -0
- package/src/core/nodes/GuaranteeNode.ts +162 -0
- package/src/core/nodes/HttpRequestNode.ts +63 -0
- package/src/core/nodes/ImportNode.ts +75 -0
- package/src/core/nodes/LiteralNode.ts +67 -0
- package/src/core/nodes/MethodCallNode.ts +79 -0
- package/src/core/nodes/MethodNode.ts +78 -0
- package/src/core/nodes/ModuleNode.ts +74 -0
- package/src/core/nodes/NodeKind.ts +171 -0
- package/src/core/nodes/ParameterNode.ts +73 -0
- package/src/core/nodes/ScopeNode.ts +80 -0
- package/src/core/nodes/ServiceNode.ts +86 -0
- package/src/core/nodes/VariableDeclarationNode.ts +60 -0
- package/src/core/nodes/index.ts +49 -0
- package/src/index.ts +93 -0
- package/src/plugins/Plugin.ts +74 -0
- package/src/plugins/analysis/DatabaseAnalyzer.ts +322 -0
- package/src/plugins/analysis/ExpressAnalyzer.ts +401 -0
- package/src/plugins/analysis/ExpressRouteAnalyzer.ts +414 -0
- package/src/plugins/analysis/FetchAnalyzer.ts +441 -0
- package/src/plugins/analysis/IncrementalAnalysisPlugin.ts +686 -0
- package/src/plugins/analysis/JSASTAnalyzer.ts +1680 -0
- package/src/plugins/analysis/ReactAnalyzer.ts +1368 -0
- package/src/plugins/analysis/RustAnalyzer.ts +438 -0
- package/src/plugins/analysis/SQLiteAnalyzer.ts +388 -0
- package/src/plugins/analysis/ServiceLayerAnalyzer.ts +429 -0
- package/src/plugins/analysis/SocketIOAnalyzer.ts +395 -0
- package/src/plugins/analysis/SystemDbAnalyzer.ts +284 -0
- package/src/plugins/analysis/ast/ConditionParser.ts +333 -0
- package/src/plugins/analysis/ast/ExpressionEvaluator.ts +117 -0
- package/src/plugins/analysis/ast/GraphBuilder.ts +1371 -0
- package/src/plugins/analysis/ast/OxcAdapter.ts +63 -0
- package/src/plugins/analysis/ast/types.ts +400 -0
- package/src/plugins/analysis/ast/visitors/ASTVisitor.ts +137 -0
- package/src/plugins/analysis/ast/visitors/CallExpressionVisitor.ts +528 -0
- package/src/plugins/analysis/ast/visitors/ClassVisitor.ts +339 -0
- package/src/plugins/analysis/ast/visitors/FunctionVisitor.ts +273 -0
- package/src/plugins/analysis/ast/visitors/ImportExportVisitor.ts +259 -0
- package/src/plugins/analysis/ast/visitors/TypeScriptVisitor.ts +235 -0
- package/src/plugins/analysis/ast/visitors/VariableVisitor.ts +268 -0
- package/src/plugins/analysis/ast/visitors/index.ts +36 -0
- package/src/plugins/discovery/DiscoveryPlugin.ts +50 -0
- package/src/plugins/discovery/MonorepoServiceDiscovery.ts +117 -0
- package/src/plugins/discovery/SimpleProjectDiscovery.ts +102 -0
- package/src/plugins/enrichment/AliasTracker.ts +399 -0
- package/src/plugins/enrichment/HTTPConnectionEnricher.ts +192 -0
- package/src/plugins/enrichment/ImportExportLinker.ts +221 -0
- package/src/plugins/enrichment/InstanceOfResolver.ts +165 -0
- package/src/plugins/enrichment/MethodCallResolver.ts +333 -0
- package/src/plugins/enrichment/MountPointResolver.ts +264 -0
- package/src/plugins/enrichment/PrefixEvaluator.ts +527 -0
- package/src/plugins/enrichment/RustFFIEnricher.ts +218 -0
- package/src/plugins/enrichment/ValueDomainAnalyzer.ts +682 -0
- package/src/plugins/indexing/IncrementalModuleIndexer.ts +287 -0
- package/src/plugins/indexing/JSModuleIndexer.ts +374 -0
- package/src/plugins/indexing/RustModuleIndexer.ts +160 -0
- package/src/plugins/indexing/ServiceDetector.ts +230 -0
- package/src/plugins/validation/CallResolverValidator.ts +170 -0
- package/src/plugins/validation/DataFlowValidator.ts +233 -0
- package/src/plugins/validation/EvalBanValidator.ts +175 -0
- package/src/plugins/validation/GraphConnectivityValidator.ts +201 -0
- package/src/plugins/validation/SQLInjectionValidator.ts +363 -0
- package/src/plugins/validation/ShadowingDetector.ts +173 -0
- package/src/plugins/validation/TypeScriptDeadCodeValidator.ts +203 -0
- package/src/plugins/vcs/GitPlugin.ts +344 -0
- package/src/plugins/vcs/VCSPlugin.ts +190 -0
- package/src/plugins/vcs/index.ts +32 -0
- package/src/storage/backends/RFDBServerBackend.ts +687 -0
- package/src/storage/backends/typeValidation.ts +151 -0
- package/src/validation/PathValidator.ts +342 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @grafema/core - Core analysis engine for GraphDD
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Main orchestrator
|
|
6
|
+
export { Orchestrator } from './Orchestrator.js';
|
|
7
|
+
export type {
|
|
8
|
+
OrchestratorOptions,
|
|
9
|
+
ProgressCallback,
|
|
10
|
+
ProgressInfo,
|
|
11
|
+
ParallelConfig,
|
|
12
|
+
ServiceInfo,
|
|
13
|
+
EntrypointInfo,
|
|
14
|
+
DiscoveryManifest,
|
|
15
|
+
IndexingUnit,
|
|
16
|
+
} from './Orchestrator.js';
|
|
17
|
+
|
|
18
|
+
// Plugin base
|
|
19
|
+
export { Plugin } from './plugins/Plugin.js';
|
|
20
|
+
export type { PluginContext } from './plugins/Plugin.js';
|
|
21
|
+
|
|
22
|
+
// Graph backend
|
|
23
|
+
export { GraphBackend, typeToKind, edgeTypeToNumber } from './core/GraphBackend.js';
|
|
24
|
+
export type { Node, Edge, EdgeType, AttrQuery, GraphStats, GraphExport } from './core/GraphBackend.js';
|
|
25
|
+
|
|
26
|
+
// RFDB
|
|
27
|
+
export { RFDBClient } from '@grafema/rfdb-client';
|
|
28
|
+
export { RFDBServerBackend } from './storage/backends/RFDBServerBackend.js';
|
|
29
|
+
|
|
30
|
+
// Core utilities
|
|
31
|
+
export { NodeFactory } from './core/NodeFactory.js';
|
|
32
|
+
export { Profiler } from './core/Profiler.js';
|
|
33
|
+
export { AnalysisQueue } from './core/AnalysisQueue.js';
|
|
34
|
+
export { GuaranteeManager } from './core/GuaranteeManager.js';
|
|
35
|
+
export type { GuaranteeGraph } from './core/GuaranteeManager.js';
|
|
36
|
+
|
|
37
|
+
// API
|
|
38
|
+
export { GraphAPI } from './api/GraphAPI.js';
|
|
39
|
+
export { GuaranteeAPI } from './api/GuaranteeAPI.js';
|
|
40
|
+
export type { GuaranteeGraphBackend } from './api/GuaranteeAPI.js';
|
|
41
|
+
|
|
42
|
+
// Node kinds
|
|
43
|
+
export { isGuaranteeType } from './core/nodes/NodeKind.js';
|
|
44
|
+
|
|
45
|
+
// === PLUGINS ===
|
|
46
|
+
|
|
47
|
+
// Indexing plugins
|
|
48
|
+
export { JSModuleIndexer } from './plugins/indexing/JSModuleIndexer.js';
|
|
49
|
+
export { IncrementalModuleIndexer } from './plugins/indexing/IncrementalModuleIndexer.js';
|
|
50
|
+
export { RustModuleIndexer } from './plugins/indexing/RustModuleIndexer.js';
|
|
51
|
+
export { ServiceDetector } from './plugins/indexing/ServiceDetector.js';
|
|
52
|
+
|
|
53
|
+
// Analysis plugins
|
|
54
|
+
export { JSASTAnalyzer } from './plugins/analysis/JSASTAnalyzer.js';
|
|
55
|
+
export { ExpressRouteAnalyzer } from './plugins/analysis/ExpressRouteAnalyzer.js';
|
|
56
|
+
export { ExpressAnalyzer } from './plugins/analysis/ExpressAnalyzer.js';
|
|
57
|
+
export { SocketIOAnalyzer } from './plugins/analysis/SocketIOAnalyzer.js';
|
|
58
|
+
export { DatabaseAnalyzer } from './plugins/analysis/DatabaseAnalyzer.js';
|
|
59
|
+
export { FetchAnalyzer } from './plugins/analysis/FetchAnalyzer.js';
|
|
60
|
+
export { ServiceLayerAnalyzer } from './plugins/analysis/ServiceLayerAnalyzer.js';
|
|
61
|
+
export { ReactAnalyzer } from './plugins/analysis/ReactAnalyzer.js';
|
|
62
|
+
export { RustAnalyzer } from './plugins/analysis/RustAnalyzer.js';
|
|
63
|
+
export { SQLiteAnalyzer } from './plugins/analysis/SQLiteAnalyzer.js';
|
|
64
|
+
export { SystemDbAnalyzer } from './plugins/analysis/SystemDbAnalyzer.js';
|
|
65
|
+
export { IncrementalAnalysisPlugin } from './plugins/analysis/IncrementalAnalysisPlugin.js';
|
|
66
|
+
|
|
67
|
+
// Enrichment plugins
|
|
68
|
+
export { MethodCallResolver } from './plugins/enrichment/MethodCallResolver.js';
|
|
69
|
+
export { AliasTracker } from './plugins/enrichment/AliasTracker.js';
|
|
70
|
+
export { ValueDomainAnalyzer } from './plugins/enrichment/ValueDomainAnalyzer.js';
|
|
71
|
+
export { MountPointResolver } from './plugins/enrichment/MountPointResolver.js';
|
|
72
|
+
export { PrefixEvaluator } from './plugins/enrichment/PrefixEvaluator.js';
|
|
73
|
+
export { InstanceOfResolver } from './plugins/enrichment/InstanceOfResolver.js';
|
|
74
|
+
export { HTTPConnectionEnricher } from './plugins/enrichment/HTTPConnectionEnricher.js';
|
|
75
|
+
export { ImportExportLinker } from './plugins/enrichment/ImportExportLinker.js';
|
|
76
|
+
export { RustFFIEnricher } from './plugins/enrichment/RustFFIEnricher.js';
|
|
77
|
+
|
|
78
|
+
// Validation plugins
|
|
79
|
+
export { CallResolverValidator } from './plugins/validation/CallResolverValidator.js';
|
|
80
|
+
export { EvalBanValidator } from './plugins/validation/EvalBanValidator.js';
|
|
81
|
+
export { SQLInjectionValidator } from './plugins/validation/SQLInjectionValidator.js';
|
|
82
|
+
export { ShadowingDetector } from './plugins/validation/ShadowingDetector.js';
|
|
83
|
+
export { GraphConnectivityValidator } from './plugins/validation/GraphConnectivityValidator.js';
|
|
84
|
+
export { DataFlowValidator } from './plugins/validation/DataFlowValidator.js';
|
|
85
|
+
export { TypeScriptDeadCodeValidator } from './plugins/validation/TypeScriptDeadCodeValidator.js';
|
|
86
|
+
|
|
87
|
+
// Discovery plugins
|
|
88
|
+
export { SimpleProjectDiscovery } from './plugins/discovery/SimpleProjectDiscovery.js';
|
|
89
|
+
export { DiscoveryPlugin } from './plugins/discovery/DiscoveryPlugin.js';
|
|
90
|
+
export { MonorepoServiceDiscovery } from './plugins/discovery/MonorepoServiceDiscovery.js';
|
|
91
|
+
|
|
92
|
+
// Re-export types for convenience
|
|
93
|
+
export type * from '@grafema/types';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Plugin class
|
|
3
|
+
*
|
|
4
|
+
* PLUGIN CONTRACT:
|
|
5
|
+
*
|
|
6
|
+
* 1. Metadata - plugin description
|
|
7
|
+
* 2. Execute - plugin logic execution
|
|
8
|
+
* 3. Return value - PluginResult
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
PluginMetadata,
|
|
13
|
+
PluginContext,
|
|
14
|
+
PluginResult,
|
|
15
|
+
IPlugin,
|
|
16
|
+
NodeFilter,
|
|
17
|
+
} from '@grafema/types';
|
|
18
|
+
import type { NodeRecord } from '@grafema/types';
|
|
19
|
+
|
|
20
|
+
// Re-export types for convenience
|
|
21
|
+
export type { PluginMetadata, PluginContext, PluginResult, IPlugin };
|
|
22
|
+
|
|
23
|
+
// Re-export helper functions from types/plugins.js
|
|
24
|
+
export { createSuccessResult, createErrorResult } from '@grafema/types';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Base Plugin class - extend this for all plugins
|
|
28
|
+
*/
|
|
29
|
+
export abstract class Plugin implements IPlugin {
|
|
30
|
+
config: Record<string, unknown>;
|
|
31
|
+
|
|
32
|
+
constructor(config: Record<string, unknown> = {}) {
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Plugin metadata
|
|
38
|
+
*/
|
|
39
|
+
abstract get metadata(): PluginMetadata;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Initialize plugin (optional)
|
|
43
|
+
* Called once before first execute
|
|
44
|
+
*/
|
|
45
|
+
async initialize(_context: PluginContext): Promise<void> {
|
|
46
|
+
// Optionally override
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Execute plugin
|
|
51
|
+
*/
|
|
52
|
+
abstract execute(context: PluginContext): Promise<PluginResult>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Cleanup resources (optional)
|
|
56
|
+
* Called after phase completion
|
|
57
|
+
*/
|
|
58
|
+
async cleanup(): Promise<void> {
|
|
59
|
+
// Optionally override
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Helper: Get all MODULE nodes from graph
|
|
64
|
+
* Works with RFDBServerBackend
|
|
65
|
+
*/
|
|
66
|
+
async getModules(graph: PluginContext['graph']): Promise<NodeRecord[]> {
|
|
67
|
+
const modules: NodeRecord[] = [];
|
|
68
|
+
const filter: NodeFilter = { type: 'MODULE' };
|
|
69
|
+
for await (const node of graph.queryNodes(filter)) {
|
|
70
|
+
modules.push(node);
|
|
71
|
+
}
|
|
72
|
+
return modules;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DatabaseAnalyzer - анализ database access patterns
|
|
3
|
+
* Детектирует db.query(), connection.query() и другие SQL вызовы
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
import { parse, ParserPlugin } from '@babel/parser';
|
|
8
|
+
import traverseModule from '@babel/traverse';
|
|
9
|
+
import type { CallExpression, Identifier } from '@babel/types';
|
|
10
|
+
import type { NodePath } from '@babel/traverse';
|
|
11
|
+
import { Plugin, createSuccessResult, createErrorResult } from '../Plugin.js';
|
|
12
|
+
import type { PluginContext, PluginResult, PluginMetadata } from '../Plugin.js';
|
|
13
|
+
import type { NodeRecord } from '@grafema/types';
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
const traverse = (traverseModule as any).default || traverseModule;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Database query node
|
|
20
|
+
*/
|
|
21
|
+
interface DatabaseQueryNode {
|
|
22
|
+
id: string;
|
|
23
|
+
type: 'db:query';
|
|
24
|
+
sql: string;
|
|
25
|
+
sqlSnippet: string;
|
|
26
|
+
operation: string;
|
|
27
|
+
tableName: string | null;
|
|
28
|
+
object: string;
|
|
29
|
+
method: string;
|
|
30
|
+
file: string;
|
|
31
|
+
line: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Analysis result
|
|
36
|
+
*/
|
|
37
|
+
interface AnalysisResult {
|
|
38
|
+
queries: number;
|
|
39
|
+
tables: number;
|
|
40
|
+
edges: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class DatabaseAnalyzer extends Plugin {
|
|
44
|
+
get metadata(): PluginMetadata {
|
|
45
|
+
return {
|
|
46
|
+
name: 'DatabaseAnalyzer',
|
|
47
|
+
phase: 'ANALYSIS',
|
|
48
|
+
priority: 75, // После JSASTAnalyzer (80)
|
|
49
|
+
creates: {
|
|
50
|
+
nodes: ['db:query', 'db:table', 'db:connection'],
|
|
51
|
+
edges: ['MAKES_QUERY', 'TARGETS', 'READS_FROM', 'WRITES_TO']
|
|
52
|
+
},
|
|
53
|
+
dependencies: ['JSASTAnalyzer'] // Требует MODULE и FUNCTION ноды
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async execute(context: PluginContext): Promise<PluginResult> {
|
|
58
|
+
try {
|
|
59
|
+
const { graph } = context;
|
|
60
|
+
|
|
61
|
+
// Получаем все MODULE ноды
|
|
62
|
+
const modules = await this.getModules(graph);
|
|
63
|
+
console.log(`[DatabaseAnalyzer] Processing ${modules.length} modules...`);
|
|
64
|
+
|
|
65
|
+
// Получаем все FUNCTION ноды для связывания
|
|
66
|
+
const functions = await this.getFunctions(graph);
|
|
67
|
+
|
|
68
|
+
let queriesCreated = 0;
|
|
69
|
+
let tablesCreated = 0;
|
|
70
|
+
let edgesCreated = 0;
|
|
71
|
+
const startTime = Date.now();
|
|
72
|
+
|
|
73
|
+
// Анализируем каждый модуль
|
|
74
|
+
for (let i = 0; i < modules.length; i++) {
|
|
75
|
+
const module = modules[i];
|
|
76
|
+
const result = await this.analyzeModule(module, functions, graph);
|
|
77
|
+
queriesCreated += result.queries;
|
|
78
|
+
tablesCreated += result.tables;
|
|
79
|
+
edgesCreated += result.edges;
|
|
80
|
+
|
|
81
|
+
// Progress every 20 modules
|
|
82
|
+
if ((i + 1) % 20 === 0 || i === modules.length - 1) {
|
|
83
|
+
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
84
|
+
const avgTime = ((Date.now() - startTime) / (i + 1)).toFixed(0);
|
|
85
|
+
console.log(
|
|
86
|
+
`[DatabaseAnalyzer] Progress: ${i + 1}/${modules.length} (${elapsed}s, avg ${avgTime}ms/module)`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(`[DatabaseAnalyzer] Created ${queriesCreated} queries, ${tablesCreated} tables`);
|
|
92
|
+
|
|
93
|
+
return createSuccessResult(
|
|
94
|
+
{
|
|
95
|
+
nodes: queriesCreated + tablesCreated,
|
|
96
|
+
edges: edgesCreated
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
queriesCreated,
|
|
100
|
+
tablesCreated
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error(`[DatabaseAnalyzer] Error:`, error);
|
|
105
|
+
return createErrorResult(error as Error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Получить все FUNCTION ноды из графа
|
|
111
|
+
*/
|
|
112
|
+
private async getFunctions(graph: PluginContext['graph']): Promise<NodeRecord[]> {
|
|
113
|
+
const functions: NodeRecord[] = [];
|
|
114
|
+
for await (const node of graph.queryNodes({ type: 'FUNCTION' })) {
|
|
115
|
+
functions.push(node);
|
|
116
|
+
}
|
|
117
|
+
return functions;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Анализировать один модуль на database patterns
|
|
122
|
+
*/
|
|
123
|
+
private async analyzeModule(
|
|
124
|
+
module: NodeRecord,
|
|
125
|
+
functions: NodeRecord[],
|
|
126
|
+
graph: PluginContext['graph']
|
|
127
|
+
): Promise<AnalysisResult> {
|
|
128
|
+
let queriesCreated = 0;
|
|
129
|
+
let tablesCreated = 0;
|
|
130
|
+
let edgesCreated = 0;
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
// Читаем и парсим файл
|
|
134
|
+
const code = readFileSync(module.file!, 'utf-8');
|
|
135
|
+
const ast = parse(code, {
|
|
136
|
+
sourceType: 'module',
|
|
137
|
+
plugins: ['jsx'] as ParserPlugin[]
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const databaseQueries: DatabaseQueryNode[] = [];
|
|
141
|
+
const createdTables = new Set<string>();
|
|
142
|
+
let queryCounter = 0;
|
|
143
|
+
|
|
144
|
+
// Ищем db.query() паттерны
|
|
145
|
+
traverse(ast, {
|
|
146
|
+
CallExpression: (path: NodePath<CallExpression>) => {
|
|
147
|
+
const node = path.node;
|
|
148
|
+
|
|
149
|
+
// Проверяем что это MemberExpression: db.query(), connection.execute()
|
|
150
|
+
if (node.callee.type === 'MemberExpression') {
|
|
151
|
+
const methodName = (node.callee.property as Identifier).name;
|
|
152
|
+
const objectName = (node.callee.object as Identifier).name;
|
|
153
|
+
|
|
154
|
+
// Детектируем database queries
|
|
155
|
+
const isDatabaseQuery =
|
|
156
|
+
(methodName === 'query' || methodName === 'execute') &&
|
|
157
|
+
(objectName === 'db' || objectName === 'connection' || objectName === 'pool') &&
|
|
158
|
+
node.arguments.length >= 1;
|
|
159
|
+
|
|
160
|
+
if (isDatabaseQuery) {
|
|
161
|
+
const sqlArg = node.arguments[0];
|
|
162
|
+
let sql: string | null = null;
|
|
163
|
+
let operation = 'UNKNOWN';
|
|
164
|
+
|
|
165
|
+
// Извлекаем SQL строку
|
|
166
|
+
if (sqlArg.type === 'StringLiteral') {
|
|
167
|
+
sql = sqlArg.value;
|
|
168
|
+
} else if (sqlArg.type === 'TemplateLiteral') {
|
|
169
|
+
// Template literal - собираем строку с placeholders
|
|
170
|
+
sql = sqlArg.quasis.map(q => q.value.raw).join('${...}');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Определяем тип операции и таблицу из SQL
|
|
174
|
+
if (sql) {
|
|
175
|
+
const sqlUpper = sql.trim().toUpperCase();
|
|
176
|
+
let tableName: string | null = null;
|
|
177
|
+
|
|
178
|
+
if (sqlUpper.startsWith('SELECT')) {
|
|
179
|
+
operation = 'SELECT';
|
|
180
|
+
const fromMatch = sqlUpper.match(/FROM\s+([a-zA-Z_][a-zA-Z0-9_]*)/);
|
|
181
|
+
if (fromMatch) tableName = fromMatch[1].toLowerCase();
|
|
182
|
+
} else if (sqlUpper.startsWith('INSERT')) {
|
|
183
|
+
operation = 'INSERT';
|
|
184
|
+
const intoMatch = sqlUpper.match(/INTO\s+([a-zA-Z_][a-zA-Z0-9_]*)/);
|
|
185
|
+
if (intoMatch) tableName = intoMatch[1].toLowerCase();
|
|
186
|
+
} else if (sqlUpper.startsWith('UPDATE')) {
|
|
187
|
+
operation = 'UPDATE';
|
|
188
|
+
const updateMatch = sqlUpper.match(/UPDATE\s+([a-zA-Z_][a-zA-Z0-9_]*)/);
|
|
189
|
+
if (updateMatch) tableName = updateMatch[1].toLowerCase();
|
|
190
|
+
} else if (sqlUpper.startsWith('DELETE')) {
|
|
191
|
+
operation = 'DELETE';
|
|
192
|
+
const deleteMatch = sqlUpper.match(/FROM\s+([a-zA-Z_][a-zA-Z0-9_]*)/);
|
|
193
|
+
if (deleteMatch) tableName = deleteMatch[1].toLowerCase();
|
|
194
|
+
} else if (sqlUpper.startsWith('CREATE')) {
|
|
195
|
+
operation = 'CREATE';
|
|
196
|
+
const createMatch = sqlUpper.match(/TABLE\s+([a-zA-Z_][a-zA-Z0-9_]*)/);
|
|
197
|
+
if (createMatch) tableName = createMatch[1].toLowerCase();
|
|
198
|
+
} else if (sqlUpper.startsWith('DROP')) {
|
|
199
|
+
operation = 'DROP';
|
|
200
|
+
const dropMatch = sqlUpper.match(/TABLE\s+([a-zA-Z_][a-zA-Z0-9_]*)/);
|
|
201
|
+
if (dropMatch) tableName = dropMatch[1].toLowerCase();
|
|
202
|
+
} else if (sqlUpper.startsWith('ALTER')) {
|
|
203
|
+
operation = 'ALTER';
|
|
204
|
+
const alterMatch = sqlUpper.match(/TABLE\s+([a-zA-Z_][a-zA-Z0-9_]*)/);
|
|
205
|
+
if (alterMatch) tableName = alterMatch[1].toLowerCase();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const queryId = queryCounter++;
|
|
209
|
+
const sqlSnippet = sql.length > 50 ? sql.substring(0, 50) + '...' : sql;
|
|
210
|
+
|
|
211
|
+
databaseQueries.push({
|
|
212
|
+
id: `${module.file}:DATABASE_QUERY:${queryId}`,
|
|
213
|
+
type: 'db:query',
|
|
214
|
+
sql: sql,
|
|
215
|
+
sqlSnippet: sqlSnippet,
|
|
216
|
+
operation: operation,
|
|
217
|
+
tableName: tableName,
|
|
218
|
+
object: objectName,
|
|
219
|
+
method: methodName,
|
|
220
|
+
file: module.file!,
|
|
221
|
+
line: node.loc!.start.line
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Создаём EXTERNAL_DATABASE ноду если есть хотя бы один query
|
|
230
|
+
if (databaseQueries.length > 0) {
|
|
231
|
+
const databaseId = 'EXTERNAL_DATABASE:__database__';
|
|
232
|
+
|
|
233
|
+
const existingDb = await graph.getNode(databaseId);
|
|
234
|
+
if (!existingDb) {
|
|
235
|
+
await graph.addNode({
|
|
236
|
+
id: databaseId,
|
|
237
|
+
type: 'db:connection',
|
|
238
|
+
name: '__database__'
|
|
239
|
+
} as NodeRecord);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Создаём DATABASE_QUERY ноды
|
|
243
|
+
for (const query of databaseQueries) {
|
|
244
|
+
await graph.addNode(query as unknown as NodeRecord);
|
|
245
|
+
queriesCreated++;
|
|
246
|
+
|
|
247
|
+
// Создаём TABLE ноду если есть tableName
|
|
248
|
+
if (query.tableName) {
|
|
249
|
+
const tableId = `TABLE:${query.tableName}`;
|
|
250
|
+
|
|
251
|
+
if (!createdTables.has(tableId)) {
|
|
252
|
+
await graph.addNode({
|
|
253
|
+
id: tableId,
|
|
254
|
+
type: 'db:table',
|
|
255
|
+
name: query.tableName
|
|
256
|
+
} as NodeRecord);
|
|
257
|
+
tablesCreated++;
|
|
258
|
+
createdTables.add(tableId);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// DATABASE_QUERY -> TARGETS -> TABLE
|
|
262
|
+
await graph.addEdge({
|
|
263
|
+
type: 'TARGETS',
|
|
264
|
+
src: query.id,
|
|
265
|
+
dst: tableId
|
|
266
|
+
});
|
|
267
|
+
edgesCreated++;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// DATABASE_QUERY -> (READS_FROM | WRITES_TO) -> __database__
|
|
271
|
+
const isReadOperation = query.operation === 'SELECT';
|
|
272
|
+
const edgeType = isReadOperation ? 'READS_FROM' : 'WRITES_TO';
|
|
273
|
+
|
|
274
|
+
await graph.addEdge({
|
|
275
|
+
type: edgeType,
|
|
276
|
+
src: query.id,
|
|
277
|
+
dst: databaseId
|
|
278
|
+
});
|
|
279
|
+
edgesCreated++;
|
|
280
|
+
|
|
281
|
+
// Находим родительскую функцию для MAKES_QUERY ребра
|
|
282
|
+
const parentFunction = this.findParentFunction(query, functions);
|
|
283
|
+
|
|
284
|
+
if (parentFunction) {
|
|
285
|
+
await graph.addEdge({
|
|
286
|
+
type: 'MAKES_QUERY',
|
|
287
|
+
src: parentFunction.id,
|
|
288
|
+
dst: query.id
|
|
289
|
+
});
|
|
290
|
+
edgesCreated++;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
} catch (error) {
|
|
295
|
+
console.error(`[DatabaseAnalyzer] Error analyzing ${module.file}:`, (error as Error).message);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
queries: queriesCreated,
|
|
300
|
+
tables: tablesCreated,
|
|
301
|
+
edges: edgesCreated
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Найти родительскую функцию для database query
|
|
307
|
+
*/
|
|
308
|
+
private findParentFunction(query: DatabaseQueryNode, functions: NodeRecord[]): NodeRecord | null {
|
|
309
|
+
// Ищем функцию в том же файле, которая содержит эту строку
|
|
310
|
+
const candidates = functions.filter(
|
|
311
|
+
f => f.file === query.file && (f.line ?? 0) < query.line // Функция должна начинаться раньше query
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
// Берём ближайшую (с максимальным line number меньше query.line)
|
|
315
|
+
if (candidates.length > 0) {
|
|
316
|
+
candidates.sort((a, b) => (b.line ?? 0) - (a.line ?? 0));
|
|
317
|
+
return candidates[0];
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
}
|