@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
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IncrementalAnalysisPlugin - плагин для инкрементального анализа
|
|
3
|
+
*
|
|
4
|
+
* НАЗНАЧЕНИЕ:
|
|
5
|
+
* Обнаруживает изменённые файлы через VCS (Git) и создаёт __local версии
|
|
6
|
+
* только для изменённых нод, используя fine-grained merge
|
|
7
|
+
*
|
|
8
|
+
* АЛГОРИТМ:
|
|
9
|
+
* 1. Получить список изменённых файлов из VCS
|
|
10
|
+
* 2. Для каждого файла:
|
|
11
|
+
* - Парсить новый код
|
|
12
|
+
* - Получить main версию нод
|
|
13
|
+
* - Классифицировать: added/modified/deleted/unchanged
|
|
14
|
+
* - Создать __local версии только для added/modified
|
|
15
|
+
* 3. Переанализировать изменённые ноды для создания связей
|
|
16
|
+
*
|
|
17
|
+
* ВЕРСИИ:
|
|
18
|
+
* - "main" - committed код (git HEAD)
|
|
19
|
+
* - "__local" - uncommitted изменения
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { Plugin, createSuccessResult, createErrorResult } from '../Plugin.js';
|
|
23
|
+
import type { PluginContext, PluginResult, PluginMetadata } from '../Plugin.js';
|
|
24
|
+
import type { GraphBackend } from '@grafema/types';
|
|
25
|
+
import type { NodeRecord } from '@grafema/types';
|
|
26
|
+
import { versionManager, VersionedNode } from '../../core/VersionManager.js';
|
|
27
|
+
import { VCSPluginFactory } from '../vcs/index.js';
|
|
28
|
+
import type { VCSPlugin } from '../vcs/VCSPlugin.js';
|
|
29
|
+
import { parse, ParserPlugin } from '@babel/parser';
|
|
30
|
+
import traverseModule from '@babel/traverse';
|
|
31
|
+
import type { NodePath } from '@babel/traverse';
|
|
32
|
+
import { readFile } from 'fs/promises';
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
const traverse = (traverseModule as any).default || traverseModule;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Manifest with project path
|
|
39
|
+
*/
|
|
40
|
+
interface AnalysisManifest {
|
|
41
|
+
projectPath: string;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Changed file info from VCS
|
|
47
|
+
*/
|
|
48
|
+
interface ChangedFileInfo {
|
|
49
|
+
path: string;
|
|
50
|
+
status: 'added' | 'modified' | 'deleted' | 'renamed';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Call site info
|
|
55
|
+
*/
|
|
56
|
+
interface CallSite {
|
|
57
|
+
callee: string;
|
|
58
|
+
object?: string;
|
|
59
|
+
method?: string;
|
|
60
|
+
type: 'FUNCTION_CALL' | 'METHOD_CALL';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Extended graph interface with version methods
|
|
65
|
+
*/
|
|
66
|
+
interface VersionAwareGraph extends GraphBackend {
|
|
67
|
+
getNodesByVersion(
|
|
68
|
+
version: string,
|
|
69
|
+
filter: { file: string }
|
|
70
|
+
): Promise<VersionedNode[]>;
|
|
71
|
+
getNodesByStableId(stableId: string): Promise<VersionedNode[]>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class IncrementalAnalysisPlugin extends Plugin {
|
|
75
|
+
private vcsPlugin: VCSPlugin | null = null;
|
|
76
|
+
|
|
77
|
+
get metadata(): PluginMetadata {
|
|
78
|
+
return {
|
|
79
|
+
name: 'IncrementalAnalysisPlugin',
|
|
80
|
+
phase: 'ANALYSIS',
|
|
81
|
+
priority: 85, // Запускается после JSModuleIndexer (90) но перед JSASTAnalyzer (80)
|
|
82
|
+
creates: {
|
|
83
|
+
nodes: ['FUNCTION', 'CLASS', 'VARIABLE_DECLARATION'], // Создаёт __local версии
|
|
84
|
+
edges: ['REPLACES', 'CALLS', 'USES']
|
|
85
|
+
},
|
|
86
|
+
dependencies: ['JSModuleIndexer']
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async initialize(context: PluginContext): Promise<void> {
|
|
91
|
+
// Инициализируем VCS плагин
|
|
92
|
+
const manifest = context.manifest as AnalysisManifest | undefined;
|
|
93
|
+
this.vcsPlugin = await VCSPluginFactory.detect({
|
|
94
|
+
rootPath: manifest?.projectPath
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (!this.vcsPlugin) {
|
|
98
|
+
console.log('[IncrementalAnalysis] No VCS detected, skipping incremental analysis');
|
|
99
|
+
} else {
|
|
100
|
+
console.log(`[IncrementalAnalysis] Using VCS: ${this.vcsPlugin.metadata.name}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async execute(context: PluginContext): Promise<PluginResult> {
|
|
105
|
+
try {
|
|
106
|
+
const { graph } = context;
|
|
107
|
+
const manifest = context.manifest as AnalysisManifest | undefined;
|
|
108
|
+
const projectPath = manifest?.projectPath ?? '';
|
|
109
|
+
|
|
110
|
+
// Если нет VCS - пропускаем инкрементальный анализ
|
|
111
|
+
if (!this.vcsPlugin) {
|
|
112
|
+
return createSuccessResult(
|
|
113
|
+
{ nodes: 0, edges: 0 },
|
|
114
|
+
{
|
|
115
|
+
skipped: true,
|
|
116
|
+
reason: 'No VCS detected'
|
|
117
|
+
}
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Проверяем наличие uncommitted изменений
|
|
122
|
+
const hasChanges = await this.vcsPlugin.hasUncommittedChanges();
|
|
123
|
+
if (!hasChanges) {
|
|
124
|
+
console.log('[IncrementalAnalysis] No uncommitted changes detected');
|
|
125
|
+
return createSuccessResult(
|
|
126
|
+
{ nodes: 0, edges: 0 },
|
|
127
|
+
{
|
|
128
|
+
skipped: true,
|
|
129
|
+
reason: 'No uncommitted changes'
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Получаем список изменённых файлов
|
|
135
|
+
const changedFiles = (await this.vcsPlugin.getChangedFiles()) as ChangedFileInfo[];
|
|
136
|
+
console.log(
|
|
137
|
+
`[IncrementalAnalysis] All changed files:`,
|
|
138
|
+
changedFiles.map(f => f.path)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const jsFiles = changedFiles.filter(
|
|
142
|
+
file =>
|
|
143
|
+
file.path.endsWith('.js') || file.path.endsWith('.mjs') || file.path.endsWith('.cjs')
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
if (jsFiles.length === 0) {
|
|
147
|
+
console.log('[IncrementalAnalysis] No JavaScript files changed');
|
|
148
|
+
return createSuccessResult(
|
|
149
|
+
{ nodes: 0, edges: 0 },
|
|
150
|
+
{
|
|
151
|
+
skipped: true,
|
|
152
|
+
reason: 'No JS files changed'
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
console.log(
|
|
158
|
+
`[IncrementalAnalysis] Found ${jsFiles.length} changed JS files:`,
|
|
159
|
+
jsFiles.map(f => f.path)
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
let totalNodesCreated = 0;
|
|
163
|
+
let totalEdgesCreated = 0;
|
|
164
|
+
|
|
165
|
+
// Обрабатываем каждый изменённый файл
|
|
166
|
+
for (const fileInfo of jsFiles) {
|
|
167
|
+
const result = await this.processChangedFile(
|
|
168
|
+
fileInfo,
|
|
169
|
+
projectPath,
|
|
170
|
+
graph as unknown as VersionAwareGraph
|
|
171
|
+
);
|
|
172
|
+
totalNodesCreated += result.nodesCreated;
|
|
173
|
+
totalEdgesCreated += result.edgesCreated;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
console.log(
|
|
177
|
+
`[IncrementalAnalysis] Created ${totalNodesCreated} __local nodes, ${totalEdgesCreated} edges`
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
return createSuccessResult(
|
|
181
|
+
{ nodes: totalNodesCreated, edges: totalEdgesCreated },
|
|
182
|
+
{
|
|
183
|
+
filesProcessed: jsFiles.length,
|
|
184
|
+
changedFiles: jsFiles.map(f => ({ path: f.path, status: f.status }))
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.error('[IncrementalAnalysis] Error:', error);
|
|
189
|
+
return createErrorResult(error as Error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Обработать один изменённый файл
|
|
195
|
+
*/
|
|
196
|
+
private async processChangedFile(
|
|
197
|
+
fileInfo: ChangedFileInfo,
|
|
198
|
+
projectPath: string,
|
|
199
|
+
graph: VersionAwareGraph
|
|
200
|
+
): Promise<{ nodesCreated: number; edgesCreated: number }> {
|
|
201
|
+
const { path: relativePath, status } = fileInfo;
|
|
202
|
+
// relativePath может начинаться с / или быть относительным
|
|
203
|
+
const fullPath = relativePath.startsWith('/') ? relativePath : `${projectPath}/${relativePath}`;
|
|
204
|
+
|
|
205
|
+
console.log(`[IncrementalAnalysis] Processing ${relativePath} (${status})`);
|
|
206
|
+
|
|
207
|
+
// Если файл удалён - ничего не делаем (main версия остаётся, __local не создаём)
|
|
208
|
+
if (status === 'deleted') {
|
|
209
|
+
console.log(` → File deleted, keeping main version only`);
|
|
210
|
+
return { nodesCreated: 0, edgesCreated: 0 };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Выполняем fine-grained merge
|
|
214
|
+
const result = await this.finegrainedMerge(fullPath, graph);
|
|
215
|
+
|
|
216
|
+
console.log(
|
|
217
|
+
` → Added: ${result.added}, Modified: ${result.modified}, Unchanged: ${result.unchanged}, Deleted: ${result.deleted}`
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
nodesCreated: result.added + result.modified,
|
|
222
|
+
edgesCreated: result.edgesCreated || 0
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Fine-grained merge - ключевая функция инкрементального анализа
|
|
228
|
+
*/
|
|
229
|
+
private async finegrainedMerge(
|
|
230
|
+
filePath: string,
|
|
231
|
+
graph: VersionAwareGraph
|
|
232
|
+
): Promise<{
|
|
233
|
+
added: number;
|
|
234
|
+
modified: number;
|
|
235
|
+
unchanged: number;
|
|
236
|
+
deleted: number;
|
|
237
|
+
edgesCreated: number;
|
|
238
|
+
}> {
|
|
239
|
+
// 1. Парсим новое содержимое файла
|
|
240
|
+
const newContent = await readFile(filePath, 'utf-8');
|
|
241
|
+
const newNodes = await this.extractTopLevelNodes(newContent, filePath);
|
|
242
|
+
|
|
243
|
+
console.log(` → Parsed ${newNodes.length} nodes from new content`);
|
|
244
|
+
|
|
245
|
+
// 2. Получаем существующие main ноды для этого файла
|
|
246
|
+
const mainNodes = await graph.getNodesByVersion('main', {
|
|
247
|
+
file: filePath
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const mainTopLevel = mainNodes.filter(node =>
|
|
251
|
+
['FUNCTION', 'CLASS', 'VARIABLE_DECLARATION', 'MODULE'].includes(node.type!)
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
console.log(` → Found ${mainTopLevel.length} existing main nodes`);
|
|
255
|
+
|
|
256
|
+
// 3. Классифицируем изменения
|
|
257
|
+
const changes = versionManager.classifyChanges(mainTopLevel, newNodes);
|
|
258
|
+
|
|
259
|
+
console.log(
|
|
260
|
+
` → Classification: +${changes.added.length} ~${changes.modified.length} =${changes.unchanged.length} -${changes.deleted.length}`
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
// 4. Создаём __local версии для added/modified нод
|
|
264
|
+
let edgesCreated = 0;
|
|
265
|
+
|
|
266
|
+
// 4a. ADDED nodes - просто создаём с версией __local
|
|
267
|
+
for (const node of changes.added) {
|
|
268
|
+
const enrichedNode = versionManager.enrichNodeWithVersion(node, '__local');
|
|
269
|
+
await graph.addNode(enrichedNode as unknown as NodeRecord);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// 4b. MODIFIED nodes - создаём __local версию + REPLACES ребро
|
|
273
|
+
for (const { old: oldNode, new: newNode } of changes.modified) {
|
|
274
|
+
const mainNodeId = versionManager.generateVersionedId(oldNode, 'main');
|
|
275
|
+
const enrichedNode = versionManager.enrichNodeWithVersion(newNode, '__local', {
|
|
276
|
+
replacesId: mainNodeId
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
await graph.addNode(enrichedNode as unknown as NodeRecord);
|
|
280
|
+
|
|
281
|
+
// Создаём REPLACES ребро
|
|
282
|
+
const replacesEdge = versionManager.createReplacesEdge(enrichedNode.id!, mainNodeId);
|
|
283
|
+
console.log(` [REPLACES] ${newNode.name}: ${enrichedNode.id} → ${mainNodeId}`);
|
|
284
|
+
await graph.addEdge({
|
|
285
|
+
type: replacesEdge.type,
|
|
286
|
+
src: replacesEdge.fromId,
|
|
287
|
+
dst: replacesEdge.toId
|
|
288
|
+
});
|
|
289
|
+
edgesCreated++;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// 4c. UNCHANGED nodes - не создаём __local версию (используется main)
|
|
293
|
+
// 4d. DELETED nodes - не создаём __local версию (main остаётся, показывая что было удалено)
|
|
294
|
+
|
|
295
|
+
// 5. Переанализируем изменённые ноды для создания связей (CALLS, USES)
|
|
296
|
+
const nodesToReanalyze = [...changes.added, ...changes.modified.map(m => m.new)];
|
|
297
|
+
|
|
298
|
+
if (nodesToReanalyze.length > 0) {
|
|
299
|
+
const reanalyzeResult = await this.reanalyzeNodes(nodesToReanalyze, filePath, '__local', graph);
|
|
300
|
+
edgesCreated += reanalyzeResult.edgesCreated;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
added: changes.added.length,
|
|
305
|
+
modified: changes.modified.length,
|
|
306
|
+
unchanged: changes.unchanged.length,
|
|
307
|
+
deleted: changes.deleted.length,
|
|
308
|
+
edgesCreated
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Извлечь top-level ноды из файла
|
|
314
|
+
*/
|
|
315
|
+
private async extractTopLevelNodes(content: string, filePath: string): Promise<VersionedNode[]> {
|
|
316
|
+
const nodes: VersionedNode[] = [];
|
|
317
|
+
|
|
318
|
+
try {
|
|
319
|
+
// Парсим с помощью Babel
|
|
320
|
+
const ast = parse(content, {
|
|
321
|
+
sourceType: 'module',
|
|
322
|
+
plugins: [
|
|
323
|
+
'jsx',
|
|
324
|
+
'typescript',
|
|
325
|
+
'decorators-legacy',
|
|
326
|
+
'classProperties',
|
|
327
|
+
'objectRestSpread',
|
|
328
|
+
'optionalChaining',
|
|
329
|
+
'nullishCoalescingOperator'
|
|
330
|
+
] as ParserPlugin[]
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// Обходим AST и извлекаем top-level декларации
|
|
334
|
+
traverse(ast, {
|
|
335
|
+
// Function Declarations (включая export function)
|
|
336
|
+
FunctionDeclaration: (path: NodePath) => {
|
|
337
|
+
// Только top-level функции (родитель - Program или ExportNamedDeclaration)
|
|
338
|
+
const parentType = path.parent.type;
|
|
339
|
+
if (
|
|
340
|
+
parentType !== 'Program' &&
|
|
341
|
+
parentType !== 'ExportNamedDeclaration' &&
|
|
342
|
+
parentType !== 'ExportDefaultDeclaration'
|
|
343
|
+
) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const node = path.node as {
|
|
348
|
+
id?: { name: string };
|
|
349
|
+
params: Array<{ name?: string; type: string }>;
|
|
350
|
+
async?: boolean;
|
|
351
|
+
generator?: boolean;
|
|
352
|
+
body: { start: number; end: number };
|
|
353
|
+
loc?: { start: { line: number; column: number } };
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
nodes.push({
|
|
357
|
+
type: 'FUNCTION',
|
|
358
|
+
name: node.id?.name || 'anonymous',
|
|
359
|
+
file: filePath,
|
|
360
|
+
line: node.loc?.start.line || 0,
|
|
361
|
+
column: node.loc?.start.column || 0,
|
|
362
|
+
params: node.params.map(p => p.name || p.type),
|
|
363
|
+
async: node.async || false,
|
|
364
|
+
exported:
|
|
365
|
+
this.isExported(path) ||
|
|
366
|
+
parentType === 'ExportNamedDeclaration' ||
|
|
367
|
+
parentType === 'ExportDefaultDeclaration',
|
|
368
|
+
bodyHash: versionManager.calculateBodyHash(content.substring(node.body.start, node.body.end)) ?? undefined
|
|
369
|
+
});
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
// Class Declarations
|
|
373
|
+
ClassDeclaration: (path: NodePath) => {
|
|
374
|
+
const parentType = path.parent.type;
|
|
375
|
+
if (
|
|
376
|
+
parentType !== 'Program' &&
|
|
377
|
+
parentType !== 'ExportNamedDeclaration' &&
|
|
378
|
+
parentType !== 'ExportDefaultDeclaration'
|
|
379
|
+
) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const node = path.node as {
|
|
384
|
+
id?: { name: string };
|
|
385
|
+
superClass?: { name: string };
|
|
386
|
+
body: { body: Array<{ type: string; key: { name: string } }> };
|
|
387
|
+
loc?: { start: { line: number; column: number } };
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const methods = node.body.body
|
|
391
|
+
.filter(member => member.type === 'ClassMethod')
|
|
392
|
+
.map(method => method.key.name);
|
|
393
|
+
|
|
394
|
+
nodes.push({
|
|
395
|
+
type: 'CLASS',
|
|
396
|
+
name: node.id?.name || 'anonymous',
|
|
397
|
+
file: filePath,
|
|
398
|
+
line: node.loc?.start.line || 0,
|
|
399
|
+
column: node.loc?.start.column || 0,
|
|
400
|
+
methods: methods,
|
|
401
|
+
exported:
|
|
402
|
+
this.isExported(path) ||
|
|
403
|
+
parentType === 'ExportNamedDeclaration' ||
|
|
404
|
+
parentType === 'ExportDefaultDeclaration',
|
|
405
|
+
extends: node.superClass?.name || undefined
|
|
406
|
+
});
|
|
407
|
+
},
|
|
408
|
+
|
|
409
|
+
// Variable Declarations (const, let, var)
|
|
410
|
+
VariableDeclaration: (path: NodePath) => {
|
|
411
|
+
const parentType = path.parent.type;
|
|
412
|
+
if (parentType !== 'Program' && parentType !== 'ExportNamedDeclaration') {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const node = path.node as {
|
|
417
|
+
kind: string;
|
|
418
|
+
declarations: Array<{ id: { type: string; name: string }; init: unknown | null }>;
|
|
419
|
+
loc?: { start: { line: number; column: number } };
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// Каждый declarator - отдельная нода
|
|
423
|
+
for (const declarator of node.declarations) {
|
|
424
|
+
if (declarator.id.type === 'Identifier') {
|
|
425
|
+
nodes.push({
|
|
426
|
+
type: 'VARIABLE_DECLARATION',
|
|
427
|
+
name: declarator.id.name,
|
|
428
|
+
file: filePath,
|
|
429
|
+
line: node.loc?.start.line || 0,
|
|
430
|
+
column: node.loc?.start.column || 0,
|
|
431
|
+
kind: node.kind // const, let, var
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
} catch (error) {
|
|
438
|
+
console.error(` ✗ Failed to parse ${filePath}:`, (error as Error).message);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return nodes;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Проверить, экспортируется ли нода
|
|
446
|
+
*/
|
|
447
|
+
private isExported(path: NodePath): boolean {
|
|
448
|
+
// Проверяем родительский узел
|
|
449
|
+
const parent = path.parent;
|
|
450
|
+
|
|
451
|
+
if (parent.type === 'ExportNamedDeclaration' || parent.type === 'ExportDefaultDeclaration') {
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Проверяем наличие export в том же scope
|
|
456
|
+
// export { foo, bar }
|
|
457
|
+
const programPath = path.findParent(p => p.isProgram());
|
|
458
|
+
if (programPath) {
|
|
459
|
+
const nodeName = (path.node as { id?: { name: string } }).id?.name;
|
|
460
|
+
if (!nodeName) return false;
|
|
461
|
+
|
|
462
|
+
let isExported = false;
|
|
463
|
+
programPath.traverse({
|
|
464
|
+
ExportNamedDeclaration: (exportPath: NodePath) => {
|
|
465
|
+
const specifiers = (exportPath.node as { specifiers?: Array<{ exported?: { name: string }; local?: { name: string } }> }).specifiers;
|
|
466
|
+
if (specifiers) {
|
|
467
|
+
for (const spec of specifiers) {
|
|
468
|
+
if (spec.exported?.name === nodeName || spec.local?.name === nodeName) {
|
|
469
|
+
isExported = true;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
return isExported;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Переанализировать ноды для создания CALLS/USES edges
|
|
484
|
+
*/
|
|
485
|
+
private async reanalyzeNodes(
|
|
486
|
+
nodes: VersionedNode[],
|
|
487
|
+
filePath: string,
|
|
488
|
+
version: string,
|
|
489
|
+
graph: VersionAwareGraph
|
|
490
|
+
): Promise<{ edgesCreated: number }> {
|
|
491
|
+
let edgesCreated = 0;
|
|
492
|
+
|
|
493
|
+
try {
|
|
494
|
+
// Читаем файл заново
|
|
495
|
+
const content = await readFile(filePath, 'utf-8');
|
|
496
|
+
|
|
497
|
+
// Парсим AST
|
|
498
|
+
const ast = parse(content, {
|
|
499
|
+
sourceType: 'module',
|
|
500
|
+
plugins: ['jsx', 'typescript', 'decorators-legacy'] as ParserPlugin[]
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
// Для каждой ноды ищем её в AST и анализируем
|
|
504
|
+
for (const node of nodes) {
|
|
505
|
+
if (node.type === 'FUNCTION') {
|
|
506
|
+
const functionEdges = await this.analyzeFunctionCalls(node, ast, version, graph);
|
|
507
|
+
edgesCreated += functionEdges;
|
|
508
|
+
} else if (node.type === 'CLASS') {
|
|
509
|
+
const classEdges = await this.analyzeClassMethods(node, ast, version, graph);
|
|
510
|
+
edgesCreated += classEdges;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
console.log(` → Reanalyzed ${nodes.length} nodes, created ${edgesCreated} edges`);
|
|
515
|
+
|
|
516
|
+
return { edgesCreated };
|
|
517
|
+
} catch (error) {
|
|
518
|
+
console.error(`[IncrementalAnalysis] Error reanalyzing nodes:`, error);
|
|
519
|
+
return { edgesCreated: 0 };
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Анализировать вызовы функций внутри функции
|
|
525
|
+
*/
|
|
526
|
+
private async analyzeFunctionCalls(
|
|
527
|
+
functionNode: VersionedNode,
|
|
528
|
+
ast: unknown,
|
|
529
|
+
version: string,
|
|
530
|
+
graph: VersionAwareGraph
|
|
531
|
+
): Promise<number> {
|
|
532
|
+
let edgesCreated = 0;
|
|
533
|
+
let functionPath: NodePath | null = null;
|
|
534
|
+
|
|
535
|
+
// Ищем функцию в AST по имени
|
|
536
|
+
traverse(ast, {
|
|
537
|
+
FunctionDeclaration: (path: NodePath) => {
|
|
538
|
+
const node = path.node as { id?: { name: string } };
|
|
539
|
+
if (node.id?.name === functionNode.name) {
|
|
540
|
+
functionPath = path;
|
|
541
|
+
path.stop();
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
|
|
545
|
+
// Arrow functions и function expressions в VariableDeclaration
|
|
546
|
+
VariableDeclarator: (path: NodePath) => {
|
|
547
|
+
const node = path.node as { id?: { name: string }; init?: { type: string } };
|
|
548
|
+
if (node.id?.name === functionNode.name) {
|
|
549
|
+
if (
|
|
550
|
+
node.init?.type === 'ArrowFunctionExpression' ||
|
|
551
|
+
node.init?.type === 'FunctionExpression'
|
|
552
|
+
) {
|
|
553
|
+
functionPath = path.get('init') as NodePath;
|
|
554
|
+
path.stop();
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
// Если нашли функцию, анализируем её тело
|
|
561
|
+
if (functionPath) {
|
|
562
|
+
edgesCreated = await this.traverseFunctionBody(functionPath, functionNode, version, graph);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return edgesCreated;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Traverse function body для поиска CALLS
|
|
570
|
+
*/
|
|
571
|
+
private async traverseFunctionBody(
|
|
572
|
+
path: NodePath,
|
|
573
|
+
functionNode: VersionedNode,
|
|
574
|
+
version: string,
|
|
575
|
+
graph: VersionAwareGraph
|
|
576
|
+
): Promise<number> {
|
|
577
|
+
const callSites: CallSite[] = [];
|
|
578
|
+
|
|
579
|
+
// Собираем все CallExpression внутри функции
|
|
580
|
+
path.traverse({
|
|
581
|
+
CallExpression: (callPath: NodePath) => {
|
|
582
|
+
const node = callPath.node as { callee: { type: string; name?: string; object?: { name: string }; property?: { name: string } } };
|
|
583
|
+
const callee = node.callee;
|
|
584
|
+
|
|
585
|
+
// Простые вызовы: foo()
|
|
586
|
+
if (callee.type === 'Identifier') {
|
|
587
|
+
callSites.push({
|
|
588
|
+
callee: callee.name!,
|
|
589
|
+
type: 'FUNCTION_CALL'
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// Method calls: obj.method()
|
|
594
|
+
else if (callee.type === 'MemberExpression') {
|
|
595
|
+
const objectName = callee.object?.name;
|
|
596
|
+
const methodName = callee.property?.name;
|
|
597
|
+
|
|
598
|
+
if (objectName && methodName) {
|
|
599
|
+
callSites.push({
|
|
600
|
+
callee: `${objectName}.${methodName}`,
|
|
601
|
+
object: objectName,
|
|
602
|
+
method: methodName,
|
|
603
|
+
type: 'METHOD_CALL'
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
// Создаём CALLS edges для каждого call site (последовательно)
|
|
611
|
+
let edgesCreated = 0;
|
|
612
|
+
for (const callSite of callSites) {
|
|
613
|
+
// Генерируем ID для caller (__local версия)
|
|
614
|
+
const callerId = versionManager.generateVersionedId(functionNode, version);
|
|
615
|
+
|
|
616
|
+
// Пытаемся найти callee в графе (сначала __local, потом main)
|
|
617
|
+
const calleeName = callSite.callee.split('.')[0]; // Для method calls берём объект
|
|
618
|
+
const calleeStableId = `FUNCTION:${calleeName}:${functionNode.file}`;
|
|
619
|
+
|
|
620
|
+
// Ищем callee в базе
|
|
621
|
+
try {
|
|
622
|
+
const created = await this.findCalleeAndCreateEdge(callerId, calleeStableId, version, graph);
|
|
623
|
+
if (created) edgesCreated++;
|
|
624
|
+
} catch (err) {
|
|
625
|
+
console.error(`[IncrementalAnalysis] Error creating CALLS edge:`, err);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
return edgesCreated;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Найти callee и создать CALLS edge
|
|
634
|
+
*/
|
|
635
|
+
private async findCalleeAndCreateEdge(
|
|
636
|
+
callerId: string,
|
|
637
|
+
calleeStableId: string,
|
|
638
|
+
version: string,
|
|
639
|
+
graph: VersionAwareGraph
|
|
640
|
+
): Promise<boolean> {
|
|
641
|
+
try {
|
|
642
|
+
// Ищем callee сначала в __local, потом в main
|
|
643
|
+
const calleeVersions = await graph.getNodesByStableId(calleeStableId);
|
|
644
|
+
|
|
645
|
+
if (calleeVersions.length === 0) {
|
|
646
|
+
// Callee не найден - возможно это external функция
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Предпочитаем __local версию, если есть
|
|
651
|
+
const calleeNode =
|
|
652
|
+
calleeVersions.find(n => n.version === '__local') ||
|
|
653
|
+
calleeVersions.find(n => n.version === 'main');
|
|
654
|
+
|
|
655
|
+
if (!calleeNode) {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// Создаём CALLS edge
|
|
660
|
+
await graph.addEdge({
|
|
661
|
+
type: 'CALLS',
|
|
662
|
+
src: callerId,
|
|
663
|
+
dst: calleeNode.id!
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
return true;
|
|
667
|
+
} catch (error) {
|
|
668
|
+
console.error(`[IncrementalAnalysis] Error finding callee:`, error);
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Анализировать методы класса
|
|
675
|
+
*/
|
|
676
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
677
|
+
private async analyzeClassMethods(
|
|
678
|
+
_classNode: VersionedNode,
|
|
679
|
+
_ast: unknown,
|
|
680
|
+
_version: string,
|
|
681
|
+
_graph: VersionAwareGraph
|
|
682
|
+
): Promise<number> {
|
|
683
|
+
// TODO: реализовать анализ методов класса
|
|
684
|
+
return 0;
|
|
685
|
+
}
|
|
686
|
+
}
|