@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,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnalysisWorker - worker thread for parallel AST analysis
|
|
3
|
+
*
|
|
4
|
+
* Each worker:
|
|
5
|
+
* 1. Connects to RFDB server
|
|
6
|
+
* 2. Receives file paths to analyze
|
|
7
|
+
* 3. Parses AST and writes nodes/edges directly to RFDB
|
|
8
|
+
*
|
|
9
|
+
* Communication:
|
|
10
|
+
* Main -> Worker: { type: 'analyze', file, moduleId, moduleName }
|
|
11
|
+
* Worker -> Main: { type: 'done', file, stats } | { type: 'error', file, error }
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { parentPort, workerData } from 'worker_threads';
|
|
15
|
+
import { readFileSync } from 'fs';
|
|
16
|
+
import { parse, ParserPlugin } from '@babel/parser';
|
|
17
|
+
import traverseModule from '@babel/traverse';
|
|
18
|
+
import type { ImportDeclaration, FunctionDeclaration, ArrowFunctionExpression, ClassDeclaration, CallExpression, Identifier } from '@babel/types';
|
|
19
|
+
import type { NodePath } from '@babel/traverse';
|
|
20
|
+
|
|
21
|
+
import { RFDBClient } from '@grafema/rfdb-client';
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
const traverse = (traverseModule as any).default || traverseModule;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Worker data from main thread
|
|
28
|
+
*/
|
|
29
|
+
interface WorkerDataInput {
|
|
30
|
+
workerId?: number;
|
|
31
|
+
socketPath?: string;
|
|
32
|
+
autoConnect?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Message types from main thread
|
|
37
|
+
*/
|
|
38
|
+
interface ConnectMessage {
|
|
39
|
+
type: 'connect';
|
|
40
|
+
socketPath?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface AnalyzeMessage {
|
|
44
|
+
type: 'analyze';
|
|
45
|
+
file: string;
|
|
46
|
+
moduleId: string;
|
|
47
|
+
moduleName: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface DisconnectMessage {
|
|
51
|
+
type: 'disconnect';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface ExitMessage {
|
|
55
|
+
type: 'exit';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type WorkerMessage = ConnectMessage | AnalyzeMessage | DisconnectMessage | ExitMessage;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Analysis stats
|
|
62
|
+
*/
|
|
63
|
+
interface AnalysisStats {
|
|
64
|
+
nodes: number;
|
|
65
|
+
edges: number;
|
|
66
|
+
functions: number;
|
|
67
|
+
calls: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Wire node for RFDB
|
|
72
|
+
*/
|
|
73
|
+
interface WireNode {
|
|
74
|
+
id: string;
|
|
75
|
+
type: string;
|
|
76
|
+
name: string;
|
|
77
|
+
file: string;
|
|
78
|
+
metadata?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Wire edge for RFDB
|
|
83
|
+
*/
|
|
84
|
+
interface WireEdge {
|
|
85
|
+
src: string;
|
|
86
|
+
dst: string;
|
|
87
|
+
type: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Worker state
|
|
91
|
+
let client: RFDBClient | null = null;
|
|
92
|
+
const workerId = (workerData as WorkerDataInput)?.workerId || 0;
|
|
93
|
+
let socketPath = (workerData as WorkerDataInput)?.socketPath || '/tmp/rfdb.sock';
|
|
94
|
+
let connected = false;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Connect to RFDB server
|
|
98
|
+
*/
|
|
99
|
+
async function connect(): Promise<void> {
|
|
100
|
+
if (connected) return;
|
|
101
|
+
|
|
102
|
+
client = new RFDBClient(socketPath);
|
|
103
|
+
await client.connect();
|
|
104
|
+
connected = true;
|
|
105
|
+
|
|
106
|
+
parentPort?.postMessage({ type: 'ready', workerId });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Parse a file and write results directly to RFDB
|
|
111
|
+
*/
|
|
112
|
+
async function analyzeFile(filePath: string, moduleId: string, moduleName: string): Promise<AnalysisStats> {
|
|
113
|
+
const stats: AnalysisStats = { nodes: 0, edges: 0, functions: 0, calls: 0 };
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const code = readFileSync(filePath, 'utf-8');
|
|
117
|
+
|
|
118
|
+
const ast = parse(code, {
|
|
119
|
+
sourceType: 'module',
|
|
120
|
+
plugins: ['jsx', 'typescript'] as ParserPlugin[],
|
|
121
|
+
errorRecovery: true
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Collections to batch write
|
|
125
|
+
const nodes: WireNode[] = [];
|
|
126
|
+
const edges: WireEdge[] = [];
|
|
127
|
+
|
|
128
|
+
// Counters for unique IDs
|
|
129
|
+
let callCounter = 0;
|
|
130
|
+
|
|
131
|
+
// Add module node
|
|
132
|
+
nodes.push({
|
|
133
|
+
id: moduleId,
|
|
134
|
+
type: 'MODULE',
|
|
135
|
+
name: moduleName,
|
|
136
|
+
file: filePath
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Extract imports
|
|
140
|
+
traverse(ast, {
|
|
141
|
+
ImportDeclaration(path: NodePath<ImportDeclaration>) {
|
|
142
|
+
const node = path.node;
|
|
143
|
+
const source = node.source.value;
|
|
144
|
+
|
|
145
|
+
node.specifiers.forEach(spec => {
|
|
146
|
+
let importedName: string;
|
|
147
|
+
let localName: string;
|
|
148
|
+
|
|
149
|
+
if (spec.type === 'ImportDefaultSpecifier') {
|
|
150
|
+
importedName = 'default';
|
|
151
|
+
localName = spec.local.name;
|
|
152
|
+
} else if (spec.type === 'ImportNamespaceSpecifier') {
|
|
153
|
+
importedName = '*';
|
|
154
|
+
localName = spec.local.name;
|
|
155
|
+
} else {
|
|
156
|
+
importedName = (spec.imported as Identifier)?.name || spec.local.name;
|
|
157
|
+
localName = spec.local.name;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const importId = `IMPORT#${localName}#${filePath}#${node.loc!.start.line}`;
|
|
161
|
+
nodes.push({
|
|
162
|
+
id: importId,
|
|
163
|
+
type: 'IMPORT',
|
|
164
|
+
name: localName,
|
|
165
|
+
file: filePath,
|
|
166
|
+
metadata: JSON.stringify({ importedName, source, line: node.loc!.start.line })
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
edges.push({ src: moduleId, dst: importId, type: 'CONTAINS' });
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Extract functions
|
|
175
|
+
traverse(ast, {
|
|
176
|
+
FunctionDeclaration(path: NodePath<FunctionDeclaration>) {
|
|
177
|
+
if (path.getFunctionParent()) return;
|
|
178
|
+
|
|
179
|
+
const node = path.node;
|
|
180
|
+
if (!node.id) return;
|
|
181
|
+
|
|
182
|
+
const funcName = node.id.name;
|
|
183
|
+
const functionId = `FUNCTION#${funcName}#${filePath}#${node.loc!.start.line}`;
|
|
184
|
+
|
|
185
|
+
nodes.push({
|
|
186
|
+
id: functionId,
|
|
187
|
+
type: 'FUNCTION',
|
|
188
|
+
name: funcName,
|
|
189
|
+
file: filePath,
|
|
190
|
+
metadata: JSON.stringify({
|
|
191
|
+
line: node.loc!.start.line,
|
|
192
|
+
async: node.async || false,
|
|
193
|
+
generator: node.generator || false,
|
|
194
|
+
exported: path.parent?.type?.includes('Export') || false
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
edges.push({ src: moduleId, dst: functionId, type: 'CONTAINS' });
|
|
199
|
+
stats.functions++;
|
|
200
|
+
|
|
201
|
+
// Extract parameters
|
|
202
|
+
node.params.forEach((param, index) => {
|
|
203
|
+
if (param.type === 'Identifier') {
|
|
204
|
+
const paramId = `PARAMETER#${param.name}#${functionId}#${index}`;
|
|
205
|
+
nodes.push({
|
|
206
|
+
id: paramId,
|
|
207
|
+
type: 'PARAMETER',
|
|
208
|
+
name: param.name,
|
|
209
|
+
file: filePath,
|
|
210
|
+
metadata: JSON.stringify({ index, functionId })
|
|
211
|
+
});
|
|
212
|
+
edges.push({ src: functionId, dst: paramId, type: 'CONTAINS' });
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
ArrowFunctionExpression(path: NodePath<ArrowFunctionExpression>) {
|
|
218
|
+
// Only process top-level arrow functions assigned to variables
|
|
219
|
+
if (path.getFunctionParent()) return;
|
|
220
|
+
|
|
221
|
+
const parent = path.parent;
|
|
222
|
+
if (parent.type !== 'VariableDeclarator') return;
|
|
223
|
+
if (!('id' in parent) || !parent.id || parent.id.type !== 'Identifier') return;
|
|
224
|
+
|
|
225
|
+
const funcName = parent.id.name;
|
|
226
|
+
const functionId = `FUNCTION#${funcName}#${filePath}#${path.node.loc!.start.line}`;
|
|
227
|
+
|
|
228
|
+
nodes.push({
|
|
229
|
+
id: functionId,
|
|
230
|
+
type: 'FUNCTION',
|
|
231
|
+
name: funcName,
|
|
232
|
+
file: filePath,
|
|
233
|
+
metadata: JSON.stringify({
|
|
234
|
+
line: path.node.loc!.start.line,
|
|
235
|
+
async: path.node.async || false,
|
|
236
|
+
arrowFunction: true
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
edges.push({ src: moduleId, dst: functionId, type: 'CONTAINS' });
|
|
241
|
+
stats.functions++;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Extract classes
|
|
246
|
+
traverse(ast, {
|
|
247
|
+
ClassDeclaration(path: NodePath<ClassDeclaration>) {
|
|
248
|
+
if (path.getFunctionParent()) return;
|
|
249
|
+
|
|
250
|
+
const node = path.node;
|
|
251
|
+
if (!node.id) return;
|
|
252
|
+
|
|
253
|
+
const className = node.id.name;
|
|
254
|
+
const classId = `CLASS#${className}#${filePath}#${node.loc!.start.line}`;
|
|
255
|
+
|
|
256
|
+
nodes.push({
|
|
257
|
+
id: classId,
|
|
258
|
+
type: 'CLASS',
|
|
259
|
+
name: className,
|
|
260
|
+
file: filePath,
|
|
261
|
+
metadata: JSON.stringify({
|
|
262
|
+
line: node.loc!.start.line,
|
|
263
|
+
superClass: (node.superClass as Identifier)?.name || null
|
|
264
|
+
})
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
edges.push({ src: moduleId, dst: classId, type: 'CONTAINS' });
|
|
268
|
+
|
|
269
|
+
// Extract methods
|
|
270
|
+
node.body.body.forEach(member => {
|
|
271
|
+
if (member.type === 'ClassMethod' && member.key.type === 'Identifier') {
|
|
272
|
+
const methodName = member.key.name;
|
|
273
|
+
const methodId = `METHOD#${className}.${methodName}#${filePath}#${member.loc!.start.line}`;
|
|
274
|
+
|
|
275
|
+
nodes.push({
|
|
276
|
+
id: methodId,
|
|
277
|
+
type: 'METHOD',
|
|
278
|
+
name: methodName,
|
|
279
|
+
file: filePath,
|
|
280
|
+
metadata: JSON.stringify({
|
|
281
|
+
className,
|
|
282
|
+
line: member.loc!.start.line,
|
|
283
|
+
async: member.async || false,
|
|
284
|
+
static: member.static || false,
|
|
285
|
+
isConstructor: member.kind === 'constructor'
|
|
286
|
+
})
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
edges.push({ src: classId, dst: methodId, type: 'CONTAINS' });
|
|
290
|
+
stats.functions++;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// Extract call expressions (simplified)
|
|
297
|
+
traverse(ast, {
|
|
298
|
+
CallExpression(path: NodePath<CallExpression>) {
|
|
299
|
+
const node = path.node;
|
|
300
|
+
|
|
301
|
+
if (node.callee.type === 'Identifier') {
|
|
302
|
+
const callId = `CALL#${node.callee.name}#${filePath}#${node.loc!.start.line}:${callCounter++}`;
|
|
303
|
+
|
|
304
|
+
nodes.push({
|
|
305
|
+
id: callId,
|
|
306
|
+
type: 'CALL',
|
|
307
|
+
name: node.callee.name,
|
|
308
|
+
file: filePath,
|
|
309
|
+
metadata: JSON.stringify({
|
|
310
|
+
line: node.loc!.start.line,
|
|
311
|
+
argsCount: node.arguments.length
|
|
312
|
+
})
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// Find parent function to connect
|
|
316
|
+
const parentFunc = path.getFunctionParent();
|
|
317
|
+
if (parentFunc) {
|
|
318
|
+
const parentName =
|
|
319
|
+
(parentFunc.node as { id?: Identifier }).id?.name ||
|
|
320
|
+
((parentFunc.parent as { id?: Identifier })?.id?.name) ||
|
|
321
|
+
'anonymous';
|
|
322
|
+
edges.push({
|
|
323
|
+
src: `FUNCTION#${parentName}#${filePath}#${parentFunc.node.loc!.start.line}`,
|
|
324
|
+
dst: callId,
|
|
325
|
+
type: 'CONTAINS'
|
|
326
|
+
});
|
|
327
|
+
} else {
|
|
328
|
+
edges.push({ src: moduleId, dst: callId, type: 'CONTAINS' });
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
stats.calls++;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Batch write to RFDB
|
|
337
|
+
if (nodes.length > 0 && client) {
|
|
338
|
+
await client.addNodes(nodes);
|
|
339
|
+
stats.nodes = nodes.length;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (edges.length > 0 && client) {
|
|
343
|
+
await client.addEdges(edges, true); // skipValidation for speed
|
|
344
|
+
stats.edges = edges.length;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return stats;
|
|
348
|
+
} catch (err) {
|
|
349
|
+
throw new Error(`Failed to analyze ${filePath}: ${(err as Error).message}`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Handle messages from main thread
|
|
355
|
+
*/
|
|
356
|
+
if (parentPort) {
|
|
357
|
+
parentPort.on('message', async (msg: WorkerMessage) => {
|
|
358
|
+
switch (msg.type) {
|
|
359
|
+
case 'connect':
|
|
360
|
+
try {
|
|
361
|
+
socketPath = msg.socketPath || socketPath;
|
|
362
|
+
await connect();
|
|
363
|
+
} catch (err) {
|
|
364
|
+
parentPort!.postMessage({ type: 'error', error: (err as Error).message });
|
|
365
|
+
}
|
|
366
|
+
break;
|
|
367
|
+
|
|
368
|
+
case 'analyze':
|
|
369
|
+
try {
|
|
370
|
+
const stats = await analyzeFile(msg.file, msg.moduleId, msg.moduleName);
|
|
371
|
+
parentPort!.postMessage({
|
|
372
|
+
type: 'done',
|
|
373
|
+
file: msg.file,
|
|
374
|
+
stats,
|
|
375
|
+
workerId
|
|
376
|
+
});
|
|
377
|
+
} catch (err) {
|
|
378
|
+
parentPort!.postMessage({
|
|
379
|
+
type: 'error',
|
|
380
|
+
file: msg.file,
|
|
381
|
+
error: (err as Error).message,
|
|
382
|
+
workerId
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
break;
|
|
386
|
+
|
|
387
|
+
case 'disconnect':
|
|
388
|
+
if (client) {
|
|
389
|
+
await client.close();
|
|
390
|
+
connected = false;
|
|
391
|
+
}
|
|
392
|
+
parentPort!.postMessage({ type: 'disconnected', workerId });
|
|
393
|
+
break;
|
|
394
|
+
|
|
395
|
+
case 'exit':
|
|
396
|
+
if (client) {
|
|
397
|
+
await client.close();
|
|
398
|
+
}
|
|
399
|
+
process.exit(0);
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// Auto-connect on start if socketPath provided
|
|
405
|
+
if ((workerData as WorkerDataInput)?.autoConnect) {
|
|
406
|
+
connect().catch(err => {
|
|
407
|
+
parentPort!.postMessage({ type: 'error', error: (err as Error).message });
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphBackend - abstract base class for graph storage implementations
|
|
3
|
+
*
|
|
4
|
+
* This defines the full contract for graph storage backends.
|
|
5
|
+
* All operations are async for compatibility with disk-based storage.
|
|
6
|
+
*
|
|
7
|
+
* Implementations:
|
|
8
|
+
* - RFDBServerBackend (Rust-based, production)
|
|
9
|
+
* - TestBackend (wrapper over RFDBServerBackend for tests)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { NodeRecord } from '@grafema/types';
|
|
13
|
+
import type { EdgeRecord, EdgeType } from '@grafema/types';
|
|
14
|
+
|
|
15
|
+
// Re-export types for convenience
|
|
16
|
+
export type { NodeRecord as Node } from '@grafema/types';
|
|
17
|
+
export type { EdgeRecord as Edge, EdgeType } from '@grafema/types';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Query filter for finding nodes by attributes
|
|
21
|
+
*/
|
|
22
|
+
export interface AttrQuery {
|
|
23
|
+
kind?: number;
|
|
24
|
+
version?: string;
|
|
25
|
+
file_id?: string;
|
|
26
|
+
file?: string;
|
|
27
|
+
exported?: boolean;
|
|
28
|
+
type?: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Graph statistics
|
|
35
|
+
*/
|
|
36
|
+
export interface GraphStats {
|
|
37
|
+
nodeCount: number;
|
|
38
|
+
edgeCount: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Exported graph data
|
|
43
|
+
*/
|
|
44
|
+
export interface GraphExport {
|
|
45
|
+
nodes: NodeRecord[];
|
|
46
|
+
edges: EdgeRecord[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Abstract GraphBackend class - base for all graph storage implementations
|
|
51
|
+
*/
|
|
52
|
+
export abstract class GraphBackend {
|
|
53
|
+
/**
|
|
54
|
+
* Initialize backend
|
|
55
|
+
*/
|
|
56
|
+
abstract initialize(): Promise<void>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Connect to storage (alias for initialize)
|
|
60
|
+
*/
|
|
61
|
+
async connect(): Promise<void> {
|
|
62
|
+
return this.initialize();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Close connection and flush data to disk
|
|
67
|
+
*/
|
|
68
|
+
abstract close(): Promise<void>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Clear all data
|
|
72
|
+
*/
|
|
73
|
+
abstract clear(): Promise<void>;
|
|
74
|
+
|
|
75
|
+
// ========================================
|
|
76
|
+
// Node Operations
|
|
77
|
+
// ========================================
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Add a single node
|
|
81
|
+
*/
|
|
82
|
+
abstract addNode(node: NodeRecord): Promise<void>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Add multiple nodes (batch operation)
|
|
86
|
+
*/
|
|
87
|
+
abstract addNodes(nodes: NodeRecord[]): Promise<void>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get node by ID
|
|
91
|
+
*/
|
|
92
|
+
abstract getNode(id: string): Promise<NodeRecord | null>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Check if node exists
|
|
96
|
+
*/
|
|
97
|
+
abstract nodeExists(id: string): Promise<boolean>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Delete a node
|
|
101
|
+
*/
|
|
102
|
+
abstract deleteNode(id: string): Promise<void>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Find nodes by attributes
|
|
106
|
+
* @returns Array of node IDs
|
|
107
|
+
*/
|
|
108
|
+
abstract findByAttr(query: AttrQuery): Promise<string[]>;
|
|
109
|
+
|
|
110
|
+
// ========================================
|
|
111
|
+
// Edge Operations
|
|
112
|
+
// ========================================
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Add a single edge
|
|
116
|
+
*/
|
|
117
|
+
abstract addEdge(edge: EdgeRecord): Promise<void>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Add multiple edges (batch operation)
|
|
121
|
+
*/
|
|
122
|
+
abstract addEdges(edges: EdgeRecord[]): Promise<void>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Delete an edge
|
|
126
|
+
*/
|
|
127
|
+
abstract deleteEdge(src: string, dst: string, type: string): Promise<void>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Get outgoing edges from a node
|
|
131
|
+
* @param nodeId - Node ID
|
|
132
|
+
* @param edgeTypes - Filter by edge types (optional)
|
|
133
|
+
*/
|
|
134
|
+
abstract getOutgoingEdges(nodeId: string, edgeTypes?: EdgeType[] | null): Promise<EdgeRecord[]>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get incoming edges to a node
|
|
138
|
+
* @param nodeId - Node ID
|
|
139
|
+
* @param edgeTypes - Filter by edge types (optional)
|
|
140
|
+
*/
|
|
141
|
+
abstract getIncomingEdges(nodeId: string, edgeTypes?: EdgeType[] | null): Promise<EdgeRecord[]>;
|
|
142
|
+
|
|
143
|
+
// ========================================
|
|
144
|
+
// Graph Traversal
|
|
145
|
+
// ========================================
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* BFS traversal from start nodes
|
|
149
|
+
* @param startIds - Starting nodes
|
|
150
|
+
* @param maxDepth - Maximum depth
|
|
151
|
+
* @param edgeTypes - Edge types to traverse (as numbers)
|
|
152
|
+
* @returns Array of reachable node IDs
|
|
153
|
+
*/
|
|
154
|
+
abstract bfs(startIds: string[], maxDepth: number, edgeTypes: number[]): Promise<string[]>;
|
|
155
|
+
|
|
156
|
+
// ========================================
|
|
157
|
+
// Persistence
|
|
158
|
+
// ========================================
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Flush data to disk
|
|
162
|
+
*/
|
|
163
|
+
abstract flush(): Promise<void>;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Get graph statistics
|
|
167
|
+
*/
|
|
168
|
+
abstract getStats(): Promise<GraphStats>;
|
|
169
|
+
|
|
170
|
+
// ========================================
|
|
171
|
+
// Compatibility Methods (for tests and GUI)
|
|
172
|
+
// ========================================
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Export entire graph to memory (only for tests!)
|
|
176
|
+
* WARNING: Do not use on large graphs
|
|
177
|
+
*/
|
|
178
|
+
abstract export(): Promise<GraphExport>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Find nodes by predicate (for demo-gui compatibility)
|
|
182
|
+
* WARNING: May be slow on large graphs
|
|
183
|
+
*/
|
|
184
|
+
abstract findNodes(predicate: (node: NodeRecord) => boolean): Promise<NodeRecord[]>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get all nodes (for GUI - only for first level visualization)
|
|
188
|
+
* WARNING: Do not use on large graphs
|
|
189
|
+
*/
|
|
190
|
+
abstract getAllNodes(): Promise<NodeRecord[]>;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get all edges (for GUI)
|
|
194
|
+
* WARNING: Do not use on large graphs
|
|
195
|
+
*/
|
|
196
|
+
abstract getAllEdges(): Promise<EdgeRecord[]>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Node type to numeric kind mapping
|
|
201
|
+
*/
|
|
202
|
+
const NODE_TYPE_TO_KIND: Record<string, number> = {
|
|
203
|
+
'PROJECT': 1,
|
|
204
|
+
'SERVICE': 2,
|
|
205
|
+
'FUNCTION': 3,
|
|
206
|
+
'CLASS': 4,
|
|
207
|
+
'METHOD': 5,
|
|
208
|
+
'VARIABLE': 6,
|
|
209
|
+
'PARAMETER': 7,
|
|
210
|
+
'MODULE': 8,
|
|
211
|
+
'ROUTE': 9,
|
|
212
|
+
'ENDPOINT': 10,
|
|
213
|
+
'FILE': 11,
|
|
214
|
+
'EXTERNAL_MODULE': 12,
|
|
215
|
+
'IMPORT': 13,
|
|
216
|
+
'EXPORT': 14,
|
|
217
|
+
'CALL_SITE': 15,
|
|
218
|
+
'METHOD_CALL': 16,
|
|
219
|
+
'SCOPE': 17,
|
|
220
|
+
'VARIABLE_DECLARATION': 18,
|
|
221
|
+
'CONSTANT': 19,
|
|
222
|
+
'EVENT_LISTENER': 20,
|
|
223
|
+
'HTTP_REQUEST': 21,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Convert node type to numeric kind
|
|
228
|
+
*/
|
|
229
|
+
export function typeToKind(type: string): number {
|
|
230
|
+
return NODE_TYPE_TO_KIND[type] || 0;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Edge type to numeric mapping
|
|
235
|
+
*/
|
|
236
|
+
const EDGE_TYPE_TO_NUMBER: Record<string, number> = {
|
|
237
|
+
'CONTAINS': 1,
|
|
238
|
+
'DEPENDS_ON': 2,
|
|
239
|
+
'CALLS': 3,
|
|
240
|
+
'EXTENDS': 4,
|
|
241
|
+
'IMPLEMENTS': 5,
|
|
242
|
+
'USES': 6,
|
|
243
|
+
'DEFINES': 7,
|
|
244
|
+
'IMPORTS': 8,
|
|
245
|
+
'EXPORTS': 9,
|
|
246
|
+
'ROUTES_TO': 10,
|
|
247
|
+
'DECLARES': 11,
|
|
248
|
+
'HAS_SCOPE': 12,
|
|
249
|
+
'CAPTURES': 13,
|
|
250
|
+
'MODIFIES': 14,
|
|
251
|
+
'WRITES_TO': 15,
|
|
252
|
+
'INSTANCE_OF': 16,
|
|
253
|
+
'HANDLED_BY': 17,
|
|
254
|
+
'HAS_CALLBACK': 18,
|
|
255
|
+
'MAKES_REQUEST': 19,
|
|
256
|
+
'IMPORTS_FROM': 20,
|
|
257
|
+
'EXPORTS_TO': 21,
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Convert edge type to number
|
|
262
|
+
*/
|
|
263
|
+
export function edgeTypeToNumber(type: string): number {
|
|
264
|
+
return EDGE_TYPE_TO_NUMBER[type] || 0;
|
|
265
|
+
}
|