@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,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic Node ID generation scheme for the graph
|
|
3
|
+
*
|
|
4
|
+
* Format: TYPE|SCOPE|FILE|IDENTIFIER|LINE:COL
|
|
5
|
+
*
|
|
6
|
+
* Components:
|
|
7
|
+
* - TYPE: node type (MODULE, FUNCTION, CLASS, METHOD, VARIABLE, etc.)
|
|
8
|
+
* - SCOPE: context/scope (path to parent or project)
|
|
9
|
+
* - FILE: relative file path from project root
|
|
10
|
+
* - IDENTIFIER: entity name (for MODULE can be empty)
|
|
11
|
+
* - LINE:COL: position in file (for uniqueness of anonymous functions)
|
|
12
|
+
*
|
|
13
|
+
* Examples:
|
|
14
|
+
* MODULE|/project|src/index.js||0:0
|
|
15
|
+
* FUNCTION|/project|src/index.js|handleRequest|42:5
|
|
16
|
+
* CLASS|/project|src/User.js|User|10:0
|
|
17
|
+
* METHOD|User|src/User.js|login|25:2
|
|
18
|
+
* VARIABLE|handleRequest|src/index.js|userId|45:10
|
|
19
|
+
* EXTERNAL_MODULE|/project||express|0:0
|
|
20
|
+
*/
|
|
21
|
+
import { createHash } from 'crypto';
|
|
22
|
+
/**
|
|
23
|
+
* Compute deterministic Node ID
|
|
24
|
+
*/
|
|
25
|
+
export function computeNodeId({ type, scope = '', file = '', identifier = '', line = 0, column = 0 }) {
|
|
26
|
+
// Normalize: remove empty values
|
|
27
|
+
const parts = [
|
|
28
|
+
type,
|
|
29
|
+
scope || '',
|
|
30
|
+
file || '',
|
|
31
|
+
identifier || '',
|
|
32
|
+
`${line}:${column}`
|
|
33
|
+
];
|
|
34
|
+
return parts.join('|');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Compute u128 numeric ID from string (for Rust backend)
|
|
38
|
+
* Uses SHA-256 hash and takes first 16 bytes
|
|
39
|
+
*/
|
|
40
|
+
export function computeNumericId(stringId) {
|
|
41
|
+
const hash = createHash('sha256').update(stringId).digest();
|
|
42
|
+
// Take first 16 bytes (128 bits) and convert to BigInt
|
|
43
|
+
let numericId = 0n;
|
|
44
|
+
for (let i = 0; i < 16; i++) {
|
|
45
|
+
numericId = (numericId << 8n) | BigInt(hash[i]);
|
|
46
|
+
}
|
|
47
|
+
return numericId;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parse Node ID back into components
|
|
51
|
+
*/
|
|
52
|
+
export function parseNodeId(nodeId) {
|
|
53
|
+
const parts = nodeId.split('|');
|
|
54
|
+
if (parts.length !== 5) {
|
|
55
|
+
throw new Error(`Invalid Node ID format: ${nodeId}`);
|
|
56
|
+
}
|
|
57
|
+
const [lineStr, columnStr] = parts[4].split(':');
|
|
58
|
+
return {
|
|
59
|
+
type: parts[0],
|
|
60
|
+
scope: parts[1],
|
|
61
|
+
file: parts[2],
|
|
62
|
+
identifier: parts[3],
|
|
63
|
+
line: Number(lineStr),
|
|
64
|
+
column: Number(columnStr)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Helper for creating MODULE ID
|
|
69
|
+
*/
|
|
70
|
+
export function createModuleId(filePath, projectPath = '/project') {
|
|
71
|
+
return computeNodeId({
|
|
72
|
+
type: 'MODULE',
|
|
73
|
+
scope: projectPath,
|
|
74
|
+
file: filePath,
|
|
75
|
+
identifier: '',
|
|
76
|
+
line: 0,
|
|
77
|
+
column: 0
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Helper for creating FUNCTION ID
|
|
82
|
+
*/
|
|
83
|
+
export function createFunctionId(filePath, functionName, line, column, scope = '/project') {
|
|
84
|
+
return computeNodeId({
|
|
85
|
+
type: 'FUNCTION',
|
|
86
|
+
scope,
|
|
87
|
+
file: filePath,
|
|
88
|
+
identifier: functionName,
|
|
89
|
+
line,
|
|
90
|
+
column
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Helper for creating CLASS ID
|
|
95
|
+
*/
|
|
96
|
+
export function createClassId(filePath, className, line, column, scope = '/project') {
|
|
97
|
+
return computeNodeId({
|
|
98
|
+
type: 'CLASS',
|
|
99
|
+
scope,
|
|
100
|
+
file: filePath,
|
|
101
|
+
identifier: className,
|
|
102
|
+
line,
|
|
103
|
+
column
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Helper for creating METHOD ID
|
|
108
|
+
*/
|
|
109
|
+
export function createMethodId(filePath, className, methodName, line, column) {
|
|
110
|
+
return computeNodeId({
|
|
111
|
+
type: 'METHOD',
|
|
112
|
+
scope: className, // Scope = parent class
|
|
113
|
+
file: filePath,
|
|
114
|
+
identifier: methodName,
|
|
115
|
+
line,
|
|
116
|
+
column
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Helper for creating VARIABLE ID
|
|
121
|
+
*/
|
|
122
|
+
export function createVariableId(filePath, varName, line, column, scope) {
|
|
123
|
+
return computeNodeId({
|
|
124
|
+
type: 'VARIABLE',
|
|
125
|
+
scope, // Scope = containing function/class
|
|
126
|
+
file: filePath,
|
|
127
|
+
identifier: varName,
|
|
128
|
+
line,
|
|
129
|
+
column
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Helper for creating EXTERNAL_MODULE ID
|
|
134
|
+
*/
|
|
135
|
+
export function createExternalModuleId(moduleName, projectPath = '/project') {
|
|
136
|
+
return computeNodeId({
|
|
137
|
+
type: 'EXTERNAL_MODULE',
|
|
138
|
+
scope: projectPath,
|
|
139
|
+
file: '',
|
|
140
|
+
identifier: moduleName,
|
|
141
|
+
line: 0,
|
|
142
|
+
column: 0
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Helper for creating IMPORT ID
|
|
147
|
+
*/
|
|
148
|
+
export function createImportId(filePath, source, localName, line, scope = '/project') {
|
|
149
|
+
return computeNodeId({
|
|
150
|
+
type: 'IMPORT',
|
|
151
|
+
scope,
|
|
152
|
+
file: filePath,
|
|
153
|
+
identifier: `${source}:${localName}`,
|
|
154
|
+
line,
|
|
155
|
+
column: 0
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Helper for creating EXPORT ID
|
|
160
|
+
*/
|
|
161
|
+
export function createExportId(filePath, exportName, line, scope = '/project') {
|
|
162
|
+
return computeNodeId({
|
|
163
|
+
type: 'EXPORT',
|
|
164
|
+
scope,
|
|
165
|
+
file: filePath,
|
|
166
|
+
identifier: exportName,
|
|
167
|
+
line,
|
|
168
|
+
column: 0
|
|
169
|
+
});
|
|
170
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ParallelAnalyzer - orchestrates parallel AST analysis using worker threads
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Configurable number of workers (default: CPU cores)
|
|
6
|
+
* - Each worker connects to RFDB server directly
|
|
7
|
+
* - Real-time statistics available during analysis
|
|
8
|
+
* - Concurrent reads while writes are happening
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* const analyzer = new ParallelAnalyzer({
|
|
12
|
+
* socketPath: '/tmp/rfdb.sock',
|
|
13
|
+
* maxWorkers: 4,
|
|
14
|
+
* });
|
|
15
|
+
* await analyzer.start();
|
|
16
|
+
* const stats = await analyzer.analyzeFiles(files);
|
|
17
|
+
* await analyzer.stop();
|
|
18
|
+
*/
|
|
19
|
+
import { EventEmitter } from 'events';
|
|
20
|
+
/**
|
|
21
|
+
* Analyzer options
|
|
22
|
+
*/
|
|
23
|
+
export interface ParallelAnalyzerOptions {
|
|
24
|
+
socketPath?: string;
|
|
25
|
+
maxWorkers?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* File info for analysis
|
|
29
|
+
*/
|
|
30
|
+
export interface FileInfo {
|
|
31
|
+
file: string;
|
|
32
|
+
id?: string;
|
|
33
|
+
moduleId?: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
moduleName?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Analysis stats per file
|
|
39
|
+
*/
|
|
40
|
+
export interface FileStats {
|
|
41
|
+
nodes?: number;
|
|
42
|
+
edges?: number;
|
|
43
|
+
functions?: number;
|
|
44
|
+
calls?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Overall analysis statistics
|
|
48
|
+
*/
|
|
49
|
+
export interface AnalysisStats {
|
|
50
|
+
filesTotal: number;
|
|
51
|
+
filesProcessed: number;
|
|
52
|
+
filesFailed: number;
|
|
53
|
+
nodesCreated: number;
|
|
54
|
+
edgesCreated: number;
|
|
55
|
+
functionsFound: number;
|
|
56
|
+
callsFound: number;
|
|
57
|
+
startTime: number | null;
|
|
58
|
+
errors: Array<{
|
|
59
|
+
file: string;
|
|
60
|
+
error: string;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Graph stats from RFDB
|
|
65
|
+
*/
|
|
66
|
+
export interface GraphStats {
|
|
67
|
+
nodeCount: number;
|
|
68
|
+
edgeCount: number;
|
|
69
|
+
nodesByType: Record<string, number>;
|
|
70
|
+
edgesByType: Record<string, number>;
|
|
71
|
+
}
|
|
72
|
+
export declare class ParallelAnalyzer extends EventEmitter {
|
|
73
|
+
private socketPath;
|
|
74
|
+
private maxWorkers;
|
|
75
|
+
private workers;
|
|
76
|
+
private readyWorkers;
|
|
77
|
+
private taskQueue;
|
|
78
|
+
private pendingTasks;
|
|
79
|
+
private taskIdCounter;
|
|
80
|
+
private running;
|
|
81
|
+
private stats;
|
|
82
|
+
private statsClient;
|
|
83
|
+
constructor(options?: ParallelAnalyzerOptions);
|
|
84
|
+
/**
|
|
85
|
+
* Start the analyzer (spawn workers)
|
|
86
|
+
*/
|
|
87
|
+
start(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Stop the analyzer (terminate workers)
|
|
90
|
+
*/
|
|
91
|
+
stop(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Analyze multiple files in parallel
|
|
94
|
+
*/
|
|
95
|
+
analyzeFiles(files: FileInfo[]): Promise<AnalysisStats>;
|
|
96
|
+
/**
|
|
97
|
+
* Get current statistics (can be called during analysis)
|
|
98
|
+
*/
|
|
99
|
+
getStats(): AnalysisStats & {
|
|
100
|
+
elapsed: number;
|
|
101
|
+
activeWorkers: number;
|
|
102
|
+
queuedTasks: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Get graph statistics from RFDB (can be called during analysis)
|
|
106
|
+
*/
|
|
107
|
+
getGraphStats(): Promise<GraphStats>;
|
|
108
|
+
/**
|
|
109
|
+
* Query nodes from RFDB (can be called during analysis)
|
|
110
|
+
*/
|
|
111
|
+
queryNodes(nodeType: string): Promise<string[]>;
|
|
112
|
+
private _analyzeFile;
|
|
113
|
+
private _dispatchTask;
|
|
114
|
+
private _handleWorkerMessage;
|
|
115
|
+
private _workerReady;
|
|
116
|
+
private _handleWorkerError;
|
|
117
|
+
private _handleWorkerExit;
|
|
118
|
+
}
|
|
119
|
+
export default ParallelAnalyzer;
|
|
120
|
+
//# sourceMappingURL=ParallelAnalyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParallelAnalyzer.d.ts","sourceRoot":"","sources":["../../src/core/ParallelAnalyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAWtC;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AAsCD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,YAAY,CAAW;IAC/B,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,YAAY,CAA4B;IAChD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,WAAW,CAAoB;gBAE3B,OAAO,GAAE,uBAA4B;IAiCjD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA8D5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA6B3B;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAqC7D;;OAEG;IACH,QAAQ,IAAI,aAAa,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;IAS3F;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC;IAe1C;;OAEG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAWrD,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,oBAAoB;IA4D5B,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,iBAAiB;CAY1B;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ParallelAnalyzer - orchestrates parallel AST analysis using worker threads
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Configurable number of workers (default: CPU cores)
|
|
6
|
+
* - Each worker connects to RFDB server directly
|
|
7
|
+
* - Real-time statistics available during analysis
|
|
8
|
+
* - Concurrent reads while writes are happening
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* const analyzer = new ParallelAnalyzer({
|
|
12
|
+
* socketPath: '/tmp/rfdb.sock',
|
|
13
|
+
* maxWorkers: 4,
|
|
14
|
+
* });
|
|
15
|
+
* await analyzer.start();
|
|
16
|
+
* const stats = await analyzer.analyzeFiles(files);
|
|
17
|
+
* await analyzer.stop();
|
|
18
|
+
*/
|
|
19
|
+
import { Worker } from 'worker_threads';
|
|
20
|
+
import { EventEmitter } from 'events';
|
|
21
|
+
import { cpus } from 'os';
|
|
22
|
+
import { fileURLToPath } from 'url';
|
|
23
|
+
import { dirname, join } from 'path';
|
|
24
|
+
import { RFDBClient } from '@grafema/rfdb-client';
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = dirname(__filename);
|
|
27
|
+
const WORKER_SCRIPT = join(__dirname, 'AnalysisWorker.js');
|
|
28
|
+
export class ParallelAnalyzer extends EventEmitter {
|
|
29
|
+
socketPath;
|
|
30
|
+
maxWorkers;
|
|
31
|
+
workers;
|
|
32
|
+
readyWorkers;
|
|
33
|
+
taskQueue;
|
|
34
|
+
pendingTasks;
|
|
35
|
+
taskIdCounter;
|
|
36
|
+
running;
|
|
37
|
+
stats;
|
|
38
|
+
statsClient;
|
|
39
|
+
constructor(options = {}) {
|
|
40
|
+
super();
|
|
41
|
+
// Configuration
|
|
42
|
+
this.socketPath = options.socketPath || '/tmp/rfdb.sock';
|
|
43
|
+
this.maxWorkers = options.maxWorkers || cpus().length;
|
|
44
|
+
this.maxWorkers = Math.min(this.maxWorkers, 16); // Cap at 16
|
|
45
|
+
// State
|
|
46
|
+
this.workers = [];
|
|
47
|
+
this.readyWorkers = [];
|
|
48
|
+
this.taskQueue = [];
|
|
49
|
+
this.pendingTasks = new Map();
|
|
50
|
+
this.taskIdCounter = 0;
|
|
51
|
+
this.running = false;
|
|
52
|
+
// Stats (updated in real-time)
|
|
53
|
+
this.stats = {
|
|
54
|
+
filesTotal: 0,
|
|
55
|
+
filesProcessed: 0,
|
|
56
|
+
filesFailed: 0,
|
|
57
|
+
nodesCreated: 0,
|
|
58
|
+
edgesCreated: 0,
|
|
59
|
+
functionsFound: 0,
|
|
60
|
+
callsFound: 0,
|
|
61
|
+
startTime: null,
|
|
62
|
+
errors: []
|
|
63
|
+
};
|
|
64
|
+
// Stats client (for reading during analysis)
|
|
65
|
+
this.statsClient = null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Start the analyzer (spawn workers)
|
|
69
|
+
*/
|
|
70
|
+
async start() {
|
|
71
|
+
if (this.running)
|
|
72
|
+
return;
|
|
73
|
+
console.log(`[ParallelAnalyzer] Starting ${this.maxWorkers} workers...`);
|
|
74
|
+
// Connect stats client for real-time queries
|
|
75
|
+
this.statsClient = new RFDBClient(this.socketPath);
|
|
76
|
+
await this.statsClient.connect();
|
|
77
|
+
// Spawn workers
|
|
78
|
+
const initPromises = [];
|
|
79
|
+
for (let i = 0; i < this.maxWorkers; i++) {
|
|
80
|
+
const worker = new Worker(WORKER_SCRIPT, {
|
|
81
|
+
workerData: {
|
|
82
|
+
workerId: i,
|
|
83
|
+
socketPath: this.socketPath,
|
|
84
|
+
autoConnect: true
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
const initPromise = new Promise((resolve, reject) => {
|
|
88
|
+
const timeout = setTimeout(() => {
|
|
89
|
+
reject(new Error(`Worker ${i} initialization timeout`));
|
|
90
|
+
}, 30000);
|
|
91
|
+
const onMessage = (msg) => {
|
|
92
|
+
if (msg.type === 'ready') {
|
|
93
|
+
clearTimeout(timeout);
|
|
94
|
+
worker.removeListener('message', onMessage);
|
|
95
|
+
resolve();
|
|
96
|
+
}
|
|
97
|
+
else if (msg.type === 'error' && !this.running) {
|
|
98
|
+
clearTimeout(timeout);
|
|
99
|
+
worker.removeListener('message', onMessage);
|
|
100
|
+
reject(new Error(msg.error));
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
worker.on('message', onMessage);
|
|
104
|
+
worker.once('error', (err) => {
|
|
105
|
+
clearTimeout(timeout);
|
|
106
|
+
reject(err);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
worker.on('message', (msg) => this._handleWorkerMessage(worker, msg));
|
|
110
|
+
worker.on('error', (err) => this._handleWorkerError(worker, err));
|
|
111
|
+
worker.on('exit', (code) => this._handleWorkerExit(worker, code));
|
|
112
|
+
this.workers.push(worker);
|
|
113
|
+
initPromises.push(initPromise);
|
|
114
|
+
}
|
|
115
|
+
await Promise.all(initPromises);
|
|
116
|
+
this.readyWorkers = [...this.workers];
|
|
117
|
+
this.running = true;
|
|
118
|
+
console.log(`[ParallelAnalyzer] ${this.maxWorkers} workers ready`);
|
|
119
|
+
this.emit('started', { workerCount: this.maxWorkers });
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Stop the analyzer (terminate workers)
|
|
123
|
+
*/
|
|
124
|
+
async stop() {
|
|
125
|
+
if (!this.running)
|
|
126
|
+
return;
|
|
127
|
+
console.log('[ParallelAnalyzer] Stopping workers...');
|
|
128
|
+
// Close stats client
|
|
129
|
+
if (this.statsClient) {
|
|
130
|
+
await this.statsClient.close();
|
|
131
|
+
this.statsClient = null;
|
|
132
|
+
}
|
|
133
|
+
// Terminate workers
|
|
134
|
+
const terminatePromises = this.workers.map(worker => {
|
|
135
|
+
return new Promise((resolve) => {
|
|
136
|
+
worker.once('exit', () => resolve());
|
|
137
|
+
worker.postMessage({ type: 'exit' });
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
await Promise.all(terminatePromises);
|
|
141
|
+
this.workers = [];
|
|
142
|
+
this.readyWorkers = [];
|
|
143
|
+
this.running = false;
|
|
144
|
+
console.log('[ParallelAnalyzer] Stopped');
|
|
145
|
+
this.emit('stopped');
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Analyze multiple files in parallel
|
|
149
|
+
*/
|
|
150
|
+
async analyzeFiles(files) {
|
|
151
|
+
if (!this.running) {
|
|
152
|
+
throw new Error('Analyzer not started. Call start() first.');
|
|
153
|
+
}
|
|
154
|
+
this.stats = {
|
|
155
|
+
filesTotal: files.length,
|
|
156
|
+
filesProcessed: 0,
|
|
157
|
+
filesFailed: 0,
|
|
158
|
+
nodesCreated: 0,
|
|
159
|
+
edgesCreated: 0,
|
|
160
|
+
functionsFound: 0,
|
|
161
|
+
callsFound: 0,
|
|
162
|
+
startTime: Date.now(),
|
|
163
|
+
errors: []
|
|
164
|
+
};
|
|
165
|
+
console.log(`[ParallelAnalyzer] Analyzing ${files.length} files with ${this.maxWorkers} workers...`);
|
|
166
|
+
// Create promises for all files
|
|
167
|
+
const promises = files.map(f => this._analyzeFile(f));
|
|
168
|
+
// Wait for all to complete
|
|
169
|
+
await Promise.all(promises);
|
|
170
|
+
const duration = Date.now() - this.stats.startTime;
|
|
171
|
+
const filesPerSecond = (this.stats.filesProcessed / (duration / 1000)).toFixed(2);
|
|
172
|
+
console.log(`[ParallelAnalyzer] Done in ${duration}ms (${filesPerSecond} files/sec)`);
|
|
173
|
+
console.log(`[ParallelAnalyzer] ${this.stats.filesProcessed} succeeded, ${this.stats.filesFailed} failed`);
|
|
174
|
+
console.log(`[ParallelAnalyzer] ${this.stats.nodesCreated} nodes, ${this.stats.edgesCreated} edges`);
|
|
175
|
+
this.emit('completed', { ...this.stats, duration });
|
|
176
|
+
return this.stats;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get current statistics (can be called during analysis)
|
|
180
|
+
*/
|
|
181
|
+
getStats() {
|
|
182
|
+
return {
|
|
183
|
+
...this.stats,
|
|
184
|
+
elapsed: this.stats.startTime ? Date.now() - this.stats.startTime : 0,
|
|
185
|
+
activeWorkers: this.maxWorkers - this.readyWorkers.length,
|
|
186
|
+
queuedTasks: this.taskQueue.length
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get graph statistics from RFDB (can be called during analysis)
|
|
191
|
+
*/
|
|
192
|
+
async getGraphStats() {
|
|
193
|
+
if (!this.statsClient) {
|
|
194
|
+
throw new Error('Analyzer not started');
|
|
195
|
+
}
|
|
196
|
+
const [nodeCount, edgeCount, nodesByType, edgesByType] = await Promise.all([
|
|
197
|
+
this.statsClient.nodeCount(),
|
|
198
|
+
this.statsClient.edgeCount(),
|
|
199
|
+
this.statsClient.countNodesByType(),
|
|
200
|
+
this.statsClient.countEdgesByType()
|
|
201
|
+
]);
|
|
202
|
+
return { nodeCount, edgeCount, nodesByType, edgesByType };
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Query nodes from RFDB (can be called during analysis)
|
|
206
|
+
*/
|
|
207
|
+
async queryNodes(nodeType) {
|
|
208
|
+
if (!this.statsClient) {
|
|
209
|
+
throw new Error('Analyzer not started');
|
|
210
|
+
}
|
|
211
|
+
return this.statsClient.findByType(nodeType);
|
|
212
|
+
}
|
|
213
|
+
// ===========================================================================
|
|
214
|
+
// Internal methods
|
|
215
|
+
// ===========================================================================
|
|
216
|
+
_analyzeFile(fileInfo) {
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
const taskId = this.taskIdCounter++;
|
|
219
|
+
const task = {
|
|
220
|
+
taskId,
|
|
221
|
+
file: fileInfo.file,
|
|
222
|
+
moduleId: fileInfo.moduleId || fileInfo.id || fileInfo.file,
|
|
223
|
+
moduleName: fileInfo.moduleName || fileInfo.name || fileInfo.file,
|
|
224
|
+
resolve,
|
|
225
|
+
reject
|
|
226
|
+
};
|
|
227
|
+
this.pendingTasks.set(taskId, task);
|
|
228
|
+
this._dispatchTask(task);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
_dispatchTask(task) {
|
|
232
|
+
if (this.readyWorkers.length > 0) {
|
|
233
|
+
const worker = this.readyWorkers.pop();
|
|
234
|
+
worker.postMessage({
|
|
235
|
+
type: 'analyze',
|
|
236
|
+
file: task.file,
|
|
237
|
+
moduleId: task.moduleId,
|
|
238
|
+
moduleName: task.moduleName,
|
|
239
|
+
taskId: task.taskId
|
|
240
|
+
});
|
|
241
|
+
this.emit('taskStarted', { file: task.file });
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
this.taskQueue.push(task);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
_handleWorkerMessage(worker, msg) {
|
|
248
|
+
switch (msg.type) {
|
|
249
|
+
case 'done': {
|
|
250
|
+
// Find task by file (workers don't track taskId internally)
|
|
251
|
+
let task = null;
|
|
252
|
+
for (const [id, t] of this.pendingTasks) {
|
|
253
|
+
if (t.file === msg.file) {
|
|
254
|
+
task = t;
|
|
255
|
+
this.pendingTasks.delete(id);
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (task) {
|
|
260
|
+
// Update stats
|
|
261
|
+
this.stats.filesProcessed++;
|
|
262
|
+
this.stats.nodesCreated += msg.stats?.nodes || 0;
|
|
263
|
+
this.stats.edgesCreated += msg.stats?.edges || 0;
|
|
264
|
+
this.stats.functionsFound += msg.stats?.functions || 0;
|
|
265
|
+
this.stats.callsFound += msg.stats?.calls || 0;
|
|
266
|
+
this.emit('fileCompleted', { file: msg.file, stats: msg.stats });
|
|
267
|
+
task.resolve(msg.stats);
|
|
268
|
+
}
|
|
269
|
+
this._workerReady(worker);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case 'error': {
|
|
273
|
+
let task = null;
|
|
274
|
+
for (const [id, t] of this.pendingTasks) {
|
|
275
|
+
if (t.file === msg.file) {
|
|
276
|
+
task = t;
|
|
277
|
+
this.pendingTasks.delete(id);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (task) {
|
|
282
|
+
this.stats.filesFailed++;
|
|
283
|
+
this.stats.errors.push({ file: msg.file, error: msg.error });
|
|
284
|
+
this.emit('fileError', { file: msg.file, error: msg.error });
|
|
285
|
+
task.resolve(null); // Don't reject, just continue
|
|
286
|
+
}
|
|
287
|
+
this._workerReady(worker);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case 'ready':
|
|
291
|
+
// Worker reconnected
|
|
292
|
+
if (!this.readyWorkers.includes(worker)) {
|
|
293
|
+
this._workerReady(worker);
|
|
294
|
+
}
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
_workerReady(worker) {
|
|
299
|
+
if (this.taskQueue.length > 0) {
|
|
300
|
+
const nextTask = this.taskQueue.shift();
|
|
301
|
+
worker.postMessage({
|
|
302
|
+
type: 'analyze',
|
|
303
|
+
file: nextTask.file,
|
|
304
|
+
moduleId: nextTask.moduleId,
|
|
305
|
+
moduleName: nextTask.moduleName,
|
|
306
|
+
taskId: nextTask.taskId
|
|
307
|
+
});
|
|
308
|
+
this.emit('taskStarted', { file: nextTask.file });
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
this.readyWorkers.push(worker);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
_handleWorkerError(worker, error) {
|
|
315
|
+
console.error('[ParallelAnalyzer] Worker error:', error);
|
|
316
|
+
this.emit('workerError', { error });
|
|
317
|
+
}
|
|
318
|
+
_handleWorkerExit(worker, code) {
|
|
319
|
+
if (code !== 0 && this.running) {
|
|
320
|
+
console.error(`[ParallelAnalyzer] Worker exited with code ${code}`);
|
|
321
|
+
}
|
|
322
|
+
// Remove from lists
|
|
323
|
+
const idx = this.workers.indexOf(worker);
|
|
324
|
+
if (idx !== -1)
|
|
325
|
+
this.workers.splice(idx, 1);
|
|
326
|
+
const readyIdx = this.readyWorkers.indexOf(worker);
|
|
327
|
+
if (readyIdx !== -1)
|
|
328
|
+
this.readyWorkers.splice(readyIdx, 1);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
export default ParallelAnalyzer;
|