@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,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IncrementalModuleIndexer - индексирует модули по требованию через очередь
|
|
3
|
+
* Стартует с entry файла, затем анализирует импорты и добавляет новые файлы в очередь
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { readFileSync, existsSync } from 'fs';
|
|
7
|
+
import { join, dirname, resolve, extname, relative } from 'path';
|
|
8
|
+
import { createHash } from 'crypto';
|
|
9
|
+
import { parse, ParserPlugin } from '@babel/parser';
|
|
10
|
+
import traverseModule from '@babel/traverse';
|
|
11
|
+
import type { NodePath } from '@babel/traverse';
|
|
12
|
+
import type { ImportDeclaration, CallExpression, Identifier } from '@babel/types';
|
|
13
|
+
import { Plugin, createSuccessResult, createErrorResult } from '../Plugin.js';
|
|
14
|
+
import type { PluginContext, PluginResult, PluginMetadata } from '../Plugin.js';
|
|
15
|
+
import type { NodeRecord } from '@grafema/types';
|
|
16
|
+
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
const traverse = (traverseModule as any).default || traverseModule;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Edge to add - compatible with InputEdge
|
|
22
|
+
*/
|
|
23
|
+
interface EdgeToAdd {
|
|
24
|
+
src: string;
|
|
25
|
+
dst: string;
|
|
26
|
+
type: string;
|
|
27
|
+
version?: string;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Pending import edge
|
|
33
|
+
*/
|
|
34
|
+
interface PendingImport {
|
|
35
|
+
src: string;
|
|
36
|
+
dst: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class IncrementalModuleIndexer extends Plugin {
|
|
40
|
+
get metadata(): PluginMetadata {
|
|
41
|
+
return {
|
|
42
|
+
name: 'IncrementalModuleIndexer',
|
|
43
|
+
phase: 'INDEXING',
|
|
44
|
+
priority: 90,
|
|
45
|
+
creates: {
|
|
46
|
+
nodes: ['MODULE'],
|
|
47
|
+
edges: ['CONTAINS', 'IMPORTS_FROM']
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Resolve module path from import
|
|
54
|
+
*/
|
|
55
|
+
private resolveModule(fromFile: string, importPath: string, projectRoot: string): string | null {
|
|
56
|
+
// Absolute path (starts with /)
|
|
57
|
+
if (importPath.startsWith('/')) {
|
|
58
|
+
const fullPath = join(projectRoot, importPath);
|
|
59
|
+
return this.tryResolve(fullPath);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Relative path (starts with . or ..)
|
|
63
|
+
if (importPath.startsWith('.')) {
|
|
64
|
+
const fromDir = dirname(fromFile);
|
|
65
|
+
const resolved = resolve(fromDir, importPath);
|
|
66
|
+
return this.tryResolve(resolved);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Bare specifier (could be alias inside monorepo, e.g. pkg/svc/...)
|
|
70
|
+
// Heuristic: if it contains a slash and not "node_modules" treat as project-root relative
|
|
71
|
+
if (importPath.includes('/') && !importPath.startsWith('node:')) {
|
|
72
|
+
const candidate = join(projectRoot, importPath);
|
|
73
|
+
const resolved = this.tryResolve(candidate);
|
|
74
|
+
if (resolved) return resolved;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// node builtin or unresolved external - skip for incremental indexing
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Try to resolve file with different extensions
|
|
83
|
+
*/
|
|
84
|
+
private tryResolve(basePath: string): string | null {
|
|
85
|
+
if (existsSync(basePath)) {
|
|
86
|
+
if (!extname(basePath)) {
|
|
87
|
+
// Try as directory with index.js
|
|
88
|
+
const indexPath = join(basePath, 'index.js');
|
|
89
|
+
if (existsSync(indexPath)) return indexPath;
|
|
90
|
+
|
|
91
|
+
// Try adding .js
|
|
92
|
+
if (existsSync(basePath + '.js')) return basePath + '.js';
|
|
93
|
+
}
|
|
94
|
+
return basePath;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Try with .js extension
|
|
98
|
+
if (existsSync(basePath + '.js')) return basePath + '.js';
|
|
99
|
+
|
|
100
|
+
// Try as directory
|
|
101
|
+
const indexPath = join(basePath, 'index.js');
|
|
102
|
+
if (existsSync(indexPath)) return indexPath;
|
|
103
|
+
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Calculate file hash
|
|
109
|
+
*/
|
|
110
|
+
private calculateFileHash(filePath: string): string | null {
|
|
111
|
+
try {
|
|
112
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
113
|
+
return createHash('sha256').update(content).digest('hex');
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Parse imports from file
|
|
121
|
+
*/
|
|
122
|
+
private parseImports(filePath: string, projectRoot: string): string[] {
|
|
123
|
+
try {
|
|
124
|
+
const code = readFileSync(filePath, 'utf-8');
|
|
125
|
+
const ast = parse(code, {
|
|
126
|
+
sourceType: 'module',
|
|
127
|
+
plugins: ['jsx', 'typescript'] as ParserPlugin[],
|
|
128
|
+
errorRecovery: true
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const imports: string[] = [];
|
|
132
|
+
traverse(ast, {
|
|
133
|
+
ImportDeclaration: (path: NodePath<ImportDeclaration>) => {
|
|
134
|
+
const importPath = path.node.source.value;
|
|
135
|
+
const resolved = this.resolveModule(filePath, importPath, projectRoot);
|
|
136
|
+
if (resolved) {
|
|
137
|
+
imports.push(resolved);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
CallExpression: (path: NodePath<CallExpression>) => {
|
|
141
|
+
if ((path.node.callee as Identifier).name === 'require' &&
|
|
142
|
+
path.node.arguments[0]?.type === 'StringLiteral') {
|
|
143
|
+
const importPath = (path.node.arguments[0] as { value: string }).value;
|
|
144
|
+
const resolved = this.resolveModule(filePath, importPath, projectRoot);
|
|
145
|
+
if (resolved) {
|
|
146
|
+
imports.push(resolved);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return imports;
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.error(` ⚠️ Failed to parse imports from ${relative(projectRoot, filePath)}: ${(err as Error).message}`);
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async execute(context: PluginContext): Promise<PluginResult> {
|
|
160
|
+
try {
|
|
161
|
+
const { manifest, graph } = context;
|
|
162
|
+
// Cast manifest to expected shape
|
|
163
|
+
const typedManifest = manifest as { projectPath: string; service: { id: string; name: string }; entryFile: string } | undefined;
|
|
164
|
+
const { projectPath, service, entryFile } = typedManifest!;
|
|
165
|
+
|
|
166
|
+
if (!entryFile) {
|
|
167
|
+
throw new Error('IncrementalModuleIndexer requires entryFile in manifest');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const queue: string[] = [entryFile];
|
|
171
|
+
const processed = new Set<string>();
|
|
172
|
+
const pendingImports: PendingImport[] = []; // Store imports to create edges after all nodes exist
|
|
173
|
+
let nodesCreated = 0;
|
|
174
|
+
let edgesCreated = 0;
|
|
175
|
+
let totalImportsParsed = 0;
|
|
176
|
+
let unresolvedImports = 0;
|
|
177
|
+
|
|
178
|
+
console.log(`📦 Starting incremental indexing from: ${relative(projectPath, entryFile)}\n`);
|
|
179
|
+
|
|
180
|
+
while (queue.length > 0) {
|
|
181
|
+
const file = queue.shift()!;
|
|
182
|
+
|
|
183
|
+
if (processed.has(file)) continue;
|
|
184
|
+
processed.add(file);
|
|
185
|
+
|
|
186
|
+
// Create MODULE node
|
|
187
|
+
const fileHash = this.calculateFileHash(file);
|
|
188
|
+
const relativePath = relative(projectPath, file);
|
|
189
|
+
|
|
190
|
+
const moduleNode: NodeRecord = {
|
|
191
|
+
id: `${file}:MODULE:${file}:0`,
|
|
192
|
+
type: 'MODULE',
|
|
193
|
+
name: relativePath,
|
|
194
|
+
file: file,
|
|
195
|
+
contentHash: fileHash
|
|
196
|
+
} as unknown as NodeRecord;
|
|
197
|
+
|
|
198
|
+
await graph.addNode(moduleNode);
|
|
199
|
+
nodesCreated++;
|
|
200
|
+
|
|
201
|
+
// Link to SERVICE
|
|
202
|
+
await graph.addEdge({
|
|
203
|
+
src: service.id,
|
|
204
|
+
dst: moduleNode.id,
|
|
205
|
+
type: 'CONTAINS',
|
|
206
|
+
version: 'main'
|
|
207
|
+
} as EdgeToAdd);
|
|
208
|
+
edgesCreated++;
|
|
209
|
+
|
|
210
|
+
// Parse imports and add to queue
|
|
211
|
+
const imports = this.parseImports(file, projectPath);
|
|
212
|
+
totalImportsParsed += imports.length;
|
|
213
|
+
for (const importFile of imports) {
|
|
214
|
+
// Store for later edge creation
|
|
215
|
+
pendingImports.push({
|
|
216
|
+
src: moduleNode.id,
|
|
217
|
+
dst: `${importFile}:MODULE:${importFile}:0`
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
if (!processed.has(importFile)) {
|
|
221
|
+
queue.push(importFile);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Simple unresolved import heuristic: look for raw import strings we failed to resolve
|
|
226
|
+
// Re-parse quickly and count any that did not get resolved (debug aid)
|
|
227
|
+
try {
|
|
228
|
+
const code = readFileSync(file, 'utf-8');
|
|
229
|
+
const ast = parse(code, {
|
|
230
|
+
sourceType: 'module',
|
|
231
|
+
plugins: ['jsx', 'typescript'] as ParserPlugin[],
|
|
232
|
+
errorRecovery: true
|
|
233
|
+
});
|
|
234
|
+
traverse(ast, {
|
|
235
|
+
ImportDeclaration: (p: NodePath<ImportDeclaration>) => {
|
|
236
|
+
const ip = p.node.source.value;
|
|
237
|
+
const isResolved = this.resolveModule(file, ip, projectPath);
|
|
238
|
+
if (!isResolved) unresolvedImports++;
|
|
239
|
+
},
|
|
240
|
+
CallExpression: (p: NodePath<CallExpression>) => {
|
|
241
|
+
if ((p.node.callee as Identifier).name === 'require' &&
|
|
242
|
+
p.node.arguments[0]?.type === 'StringLiteral') {
|
|
243
|
+
const ip = (p.node.arguments[0] as { value: string }).value;
|
|
244
|
+
const isResolved = this.resolveModule(file, ip, projectPath);
|
|
245
|
+
if (!isResolved) unresolvedImports++;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
} catch {
|
|
250
|
+
// Ignore parse errors for unresolved count
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (processed.size % 10 === 0) {
|
|
254
|
+
process.stdout.write(`\r 📦 Indexed ${processed.size} modules (${queue.length} in queue)...`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
console.log(`\r ✅ Indexed ${processed.size} modules\n`);
|
|
259
|
+
console.log(` 📥 Parsed ${totalImportsParsed} import specifiers (unresolved: ${unresolvedImports})`);
|
|
260
|
+
console.log(` 🔗 Pending IMPORTS edges to create: ${pendingImports.length}\n`);
|
|
261
|
+
console.log(` 📊 Creating IMPORTS edges...\n`);
|
|
262
|
+
|
|
263
|
+
// Now create all IMPORTS edges after all MODULE nodes exist
|
|
264
|
+
for (const { src, dst } of pendingImports) {
|
|
265
|
+
await graph.addEdge({
|
|
266
|
+
src,
|
|
267
|
+
dst,
|
|
268
|
+
type: 'IMPORTS',
|
|
269
|
+
version: 'main'
|
|
270
|
+
} as EdgeToAdd);
|
|
271
|
+
edgesCreated++;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
console.log(` 📊 Created ${nodesCreated} MODULE nodes and ${edgesCreated} edges`);
|
|
275
|
+
console.log(` 📈 IMPORTS edges created: ${pendingImports.length}\n`);
|
|
276
|
+
|
|
277
|
+
return createSuccessResult(
|
|
278
|
+
{ nodes: nodesCreated, edges: edgesCreated },
|
|
279
|
+
{ filesScanned: processed.size }
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.error(`[IncrementalModuleIndexer] Error:`, error);
|
|
284
|
+
return createErrorResult(error as Error);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSModuleIndexer - плагин для индексации JavaScript/TypeScript модулей
|
|
3
|
+
* Строит дерево зависимостей от entrypoint через DFS (как в file2host.js)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { readFileSync, existsSync } from 'fs';
|
|
7
|
+
import { join, resolve, dirname } from 'path';
|
|
8
|
+
import { createHash } from 'crypto';
|
|
9
|
+
import { Plugin, createSuccessResult, createErrorResult } from '../Plugin.js';
|
|
10
|
+
import type { PluginContext, PluginResult, PluginMetadata } from '../Plugin.js';
|
|
11
|
+
// @ts-expect-error - no type declarations for node-source-walk
|
|
12
|
+
import Walker from 'node-source-walk';
|
|
13
|
+
import { NodeFactory } from '../../core/NodeFactory.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Manifest with service info
|
|
17
|
+
*/
|
|
18
|
+
interface IndexerManifest {
|
|
19
|
+
projectPath: string;
|
|
20
|
+
service: {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
path: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Test file patterns (can be overridden in config)
|
|
28
|
+
const DEFAULT_TEST_PATTERNS: RegExp[] = [
|
|
29
|
+
/[/\\]test[/\\]/, // /test/
|
|
30
|
+
/[/\\]tests[/\\]/, // /tests/
|
|
31
|
+
/[/\\]__tests__[/\\]/, // /__tests__/
|
|
32
|
+
/[/\\]spec[/\\]/, // /spec/
|
|
33
|
+
/\.test\.[jt]sx?$/, // .test.js, .test.ts, .test.jsx, .test.tsx
|
|
34
|
+
/\.spec\.[jt]sx?$/, // .spec.js, .spec.ts, .spec.jsx, .spec.tsx
|
|
35
|
+
/_test\.[jt]sx?$/, // _test.js (Go-style)
|
|
36
|
+
/[/\\]fixtures?[/\\]/, // /fixture/ or /fixtures/
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Stack item for DFS traversal
|
|
41
|
+
*/
|
|
42
|
+
interface StackItem {
|
|
43
|
+
file: string;
|
|
44
|
+
depth: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Edge to add
|
|
49
|
+
*/
|
|
50
|
+
interface EdgeToAdd {
|
|
51
|
+
src: string;
|
|
52
|
+
dst: string;
|
|
53
|
+
type: string;
|
|
54
|
+
etype?: string;
|
|
55
|
+
version?: string;
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* AST node types from walker
|
|
61
|
+
*/
|
|
62
|
+
interface ASTNode {
|
|
63
|
+
type: string;
|
|
64
|
+
callee?: { name?: string };
|
|
65
|
+
source?: { type: string; value?: string; name?: string };
|
|
66
|
+
arguments?: Array<{ type: string; value?: string; name?: string }>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class JSModuleIndexer extends Plugin {
|
|
70
|
+
private walker: Walker;
|
|
71
|
+
private cache: Map<string, string[] | Error>;
|
|
72
|
+
private testPatterns: RegExp[];
|
|
73
|
+
private markTestFiles: boolean;
|
|
74
|
+
|
|
75
|
+
constructor() {
|
|
76
|
+
super();
|
|
77
|
+
this.walker = new Walker();
|
|
78
|
+
this.cache = new Map(); // Кеш зависимостей файла
|
|
79
|
+
this.testPatterns = DEFAULT_TEST_PATTERNS;
|
|
80
|
+
this.markTestFiles = true; // Default: enabled
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Check if file is a test file based on path patterns
|
|
85
|
+
*/
|
|
86
|
+
private isTestFile(filePath: string): boolean {
|
|
87
|
+
if (!this.markTestFiles) return false;
|
|
88
|
+
return this.testPatterns.some(pattern => pattern.test(filePath));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get metadata(): PluginMetadata {
|
|
92
|
+
return {
|
|
93
|
+
name: 'JSModuleIndexer',
|
|
94
|
+
phase: 'INDEXING',
|
|
95
|
+
priority: 90,
|
|
96
|
+
creates: {
|
|
97
|
+
nodes: ['MODULE'],
|
|
98
|
+
edges: ['CONTAINS', 'DEPENDS_ON']
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private calculateFileHash(filePath: string): string | null {
|
|
104
|
+
try {
|
|
105
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
106
|
+
return createHash('sha256').update(content).digest('hex');
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Парсит файл и извлекает все зависимости:
|
|
114
|
+
* - require('...')
|
|
115
|
+
* - import ... from '...'
|
|
116
|
+
* - export * from '...'
|
|
117
|
+
* - export { ... } from '...'
|
|
118
|
+
*/
|
|
119
|
+
private processFile(filePath: string, _projectPath: string): string[] | Error {
|
|
120
|
+
if (this.cache.has(filePath)) {
|
|
121
|
+
return this.cache.get(filePath)!;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const result: string[] = [];
|
|
125
|
+
let content: string;
|
|
126
|
+
let ast: unknown;
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
if (!existsSync(filePath)) {
|
|
130
|
+
this.cache.set(filePath, new Error('ENOENT'));
|
|
131
|
+
return new Error('ENOENT');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
content = readFileSync(filePath, 'utf-8');
|
|
135
|
+
ast = this.walker.parse(content);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
if (filePath.endsWith('.json')) {
|
|
138
|
+
this.cache.set(filePath, []);
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
this.cache.set(filePath, new Error((e as Error).message));
|
|
142
|
+
return new Error((e as Error).message);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.walker.traverse(ast, (node: ASTNode) => {
|
|
146
|
+
const isRequire = node.type === 'CallExpression' && node.callee?.name === 'require';
|
|
147
|
+
const isImport = node.type === 'ImportDeclaration';
|
|
148
|
+
// export * from './module.js'
|
|
149
|
+
const isExportAll = node.type === 'ExportAllDeclaration';
|
|
150
|
+
// export { foo } from './module.js'
|
|
151
|
+
const isExportNamed = node.type === 'ExportNamedDeclaration' && node.source;
|
|
152
|
+
|
|
153
|
+
if (!isRequire && !isImport && !isExportAll && !isExportNamed) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let source: { type: string; value?: string; name?: string } | undefined;
|
|
158
|
+
if (isImport || isExportAll || isExportNamed) {
|
|
159
|
+
source = node.source;
|
|
160
|
+
} else {
|
|
161
|
+
source = node.arguments?.[0];
|
|
162
|
+
}
|
|
163
|
+
if (!source || !['Identifier', 'StringLiteral'].includes(source.type)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const name = source.value || source.name;
|
|
168
|
+
if (!name) return;
|
|
169
|
+
|
|
170
|
+
// Игнорируем встроенные модули
|
|
171
|
+
if (name.startsWith('internal/')) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Резолвим относительные пути
|
|
176
|
+
if (name.startsWith('.') || name.startsWith('/')) {
|
|
177
|
+
const dir = dirname(filePath);
|
|
178
|
+
const resolved = resolve(dir, name);
|
|
179
|
+
result.push(resolved);
|
|
180
|
+
} else {
|
|
181
|
+
// npm пакет - помечаем специально
|
|
182
|
+
result.push(`package::${name}`);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
this.cache.set(filePath, result);
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Резолвит путь к модулю (добавляет .js/.ts если нужно)
|
|
192
|
+
*/
|
|
193
|
+
private resolveModulePath(path: string): string {
|
|
194
|
+
if (existsSync(path)) return path;
|
|
195
|
+
// Try JavaScript extensions
|
|
196
|
+
if (existsSync(path + '.js')) return path + '.js';
|
|
197
|
+
if (existsSync(path + '.mjs')) return path + '.mjs';
|
|
198
|
+
if (existsSync(path + '.jsx')) return path + '.jsx';
|
|
199
|
+
// Try TypeScript extensions
|
|
200
|
+
if (existsSync(path + '.ts')) return path + '.ts';
|
|
201
|
+
if (existsSync(path + '.tsx')) return path + '.tsx';
|
|
202
|
+
// Try index files
|
|
203
|
+
if (existsSync(join(path, 'index.js'))) return join(path, 'index.js');
|
|
204
|
+
if (existsSync(join(path, 'index.ts'))) return join(path, 'index.ts');
|
|
205
|
+
if (existsSync(join(path, 'index.mjs'))) return join(path, 'index.mjs');
|
|
206
|
+
if (existsSync(join(path, 'index.tsx'))) return join(path, 'index.tsx');
|
|
207
|
+
return path;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async execute(context: PluginContext): Promise<PluginResult> {
|
|
211
|
+
try {
|
|
212
|
+
const { graph, onProgress, config } = context;
|
|
213
|
+
const manifest = context.manifest as IndexerManifest | undefined;
|
|
214
|
+
const projectPath = manifest?.projectPath ?? '';
|
|
215
|
+
const service = manifest?.service ?? { id: '', name: '', path: '' };
|
|
216
|
+
|
|
217
|
+
// Check config for test file marking
|
|
218
|
+
if ((config as { analysis?: { tests?: { markTestFiles?: boolean } } })?.analysis?.tests?.markTestFiles === false) {
|
|
219
|
+
this.markTestFiles = false;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const entrypoint = service.path;
|
|
223
|
+
// const pkgPath = join(projectPath, 'pkg');
|
|
224
|
+
|
|
225
|
+
// Резолвим entrypoint относительно projectPath
|
|
226
|
+
const absoluteEntrypoint = entrypoint.startsWith('/')
|
|
227
|
+
? entrypoint
|
|
228
|
+
: join(projectPath, entrypoint);
|
|
229
|
+
|
|
230
|
+
console.log(`[JSModuleIndexer] Building dependency tree from ${service.name}`);
|
|
231
|
+
|
|
232
|
+
// DFS через стек (как в file2host.js)
|
|
233
|
+
const visited = new Set<string>();
|
|
234
|
+
const stack: StackItem[] = [{ file: absoluteEntrypoint, depth: 0 }];
|
|
235
|
+
visited.add(absoluteEntrypoint);
|
|
236
|
+
|
|
237
|
+
let nodesCreated = 0;
|
|
238
|
+
let edgesCreated = 0;
|
|
239
|
+
// const skipped = 0;
|
|
240
|
+
|
|
241
|
+
const MAX_MODULES = 2000; // Safety limit per service
|
|
242
|
+
const MAX_DEPTH = 50; // Max dependency depth
|
|
243
|
+
|
|
244
|
+
// Collect DEPENDS_ON edges to create after all nodes exist
|
|
245
|
+
const pendingDependsOnEdges: EdgeToAdd[] = [];
|
|
246
|
+
let lastProgressReport = 0;
|
|
247
|
+
const PROGRESS_INTERVAL = 10; // Report every N files
|
|
248
|
+
|
|
249
|
+
while (stack.length > 0 && visited.size < MAX_MODULES) {
|
|
250
|
+
const { file: currentFile, depth } = stack.pop()!;
|
|
251
|
+
|
|
252
|
+
// Report progress every PROGRESS_INTERVAL files
|
|
253
|
+
if (onProgress && visited.size - lastProgressReport >= PROGRESS_INTERVAL) {
|
|
254
|
+
onProgress({
|
|
255
|
+
phase: 'indexing',
|
|
256
|
+
currentPlugin: 'JSModuleIndexer',
|
|
257
|
+
message: `${service.name}: indexed ${visited.size} files`,
|
|
258
|
+
processedFiles: visited.size,
|
|
259
|
+
currentService: service.name
|
|
260
|
+
});
|
|
261
|
+
lastProgressReport = visited.size;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
console.log(`[JSModuleIndexer] Processing: ${currentFile.replace(projectPath, '')} (depth ${depth})`);
|
|
265
|
+
|
|
266
|
+
if (depth > MAX_DEPTH) {
|
|
267
|
+
console.log(`[JSModuleIndexer] Max depth ${MAX_DEPTH} reached at ${currentFile}`);
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Парсим зависимости
|
|
272
|
+
const deps = this.processFile(currentFile, projectPath);
|
|
273
|
+
console.log(`[JSModuleIndexer] Found ${deps instanceof Error ? 0 : deps.length} dependencies in ${currentFile.replace(projectPath, '')}`);
|
|
274
|
+
|
|
275
|
+
if (deps instanceof Error) {
|
|
276
|
+
if (!deps.message.includes('ENOENT')) {
|
|
277
|
+
console.log(`[JSModuleIndexer] Error parsing ${currentFile}: ${deps.message}`);
|
|
278
|
+
}
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Создаём MODULE ноду для текущего файла
|
|
283
|
+
const fileHash = this.calculateFileHash(currentFile);
|
|
284
|
+
const moduleId = `MODULE:${fileHash}`; // StableID-based for deduplication
|
|
285
|
+
|
|
286
|
+
// Используем NodeFactory для создания MODULE ноды
|
|
287
|
+
// ВСЕГДА создаём ноду в графе (граф может быть пустой после force)
|
|
288
|
+
const isTest = this.isTestFile(currentFile);
|
|
289
|
+
const moduleNode = NodeFactory.createModule(currentFile, projectPath, {
|
|
290
|
+
contentHash: fileHash ?? undefined,
|
|
291
|
+
isTest
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
console.log(`[JSModuleIndexer] Creating MODULE node: ${moduleNode.id}`);
|
|
295
|
+
await graph.addNode(moduleNode);
|
|
296
|
+
nodesCreated++;
|
|
297
|
+
|
|
298
|
+
// Always create SERVICE -> CONTAINS -> MODULE edge (even if module exists)
|
|
299
|
+
await graph.addEdge({
|
|
300
|
+
src: service.id,
|
|
301
|
+
dst: moduleId,
|
|
302
|
+
type: 'CONTAINS',
|
|
303
|
+
version: 'main'
|
|
304
|
+
});
|
|
305
|
+
// Обрабатываем зависимости
|
|
306
|
+
for (const dep of deps) {
|
|
307
|
+
if (dep.startsWith('package::')) {
|
|
308
|
+
// npm пакет - игнорируем пока
|
|
309
|
+
console.log(`[JSModuleIndexer] Skipping npm package: ${dep}`);
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const resolvedDep = this.resolveModulePath(dep);
|
|
314
|
+
console.log(`[JSModuleIndexer] Resolved: ${dep} -> ${resolvedDep.replace(projectPath, '')}`);
|
|
315
|
+
|
|
316
|
+
// Добавляем в стек если ещё не посещали
|
|
317
|
+
if (!visited.has(resolvedDep)) {
|
|
318
|
+
visited.add(resolvedDep);
|
|
319
|
+
stack.push({ file: resolvedDep, depth: depth + 1 });
|
|
320
|
+
console.log(`[JSModuleIndexer] Added to stack (depth ${depth + 1})`);
|
|
321
|
+
} else {
|
|
322
|
+
console.log(`[JSModuleIndexer] Already visited, skipping`);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Queue DEPENDS_ON edges for later (after all nodes exist)
|
|
326
|
+
const depHash = this.calculateFileHash(resolvedDep);
|
|
327
|
+
const depModuleId = `MODULE:${depHash}`;
|
|
328
|
+
pendingDependsOnEdges.push({
|
|
329
|
+
src: moduleId,
|
|
330
|
+
dst: depModuleId,
|
|
331
|
+
type: 'DEPENDS_ON',
|
|
332
|
+
version: 'main'
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Create all DEPENDS_ON edges in one batch (faster than loop)
|
|
338
|
+
if (pendingDependsOnEdges.length > 0) {
|
|
339
|
+
await graph.addEdges(pendingDependsOnEdges);
|
|
340
|
+
edgesCreated += pendingDependsOnEdges.length;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Warning if hit MAX_MODULES limit
|
|
344
|
+
if (visited.size >= MAX_MODULES) {
|
|
345
|
+
console.warn(`[JSModuleIndexer] ⚠️ ${service.name} hit MAX_MODULES limit (${MAX_MODULES})!`);
|
|
346
|
+
console.warn(`[JSModuleIndexer] This service may be pulling in too many dependencies.`);
|
|
347
|
+
console.warn(`[JSModuleIndexer] Unprocessed files in stack: ${stack.length}`);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Final progress report
|
|
351
|
+
if (onProgress) {
|
|
352
|
+
onProgress({
|
|
353
|
+
phase: 'indexing',
|
|
354
|
+
currentPlugin: 'JSModuleIndexer',
|
|
355
|
+
message: `${service.name}: indexed ${visited.size} files`,
|
|
356
|
+
totalFiles: visited.size,
|
|
357
|
+
processedFiles: visited.size,
|
|
358
|
+
currentService: service.name
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
console.log(`[JSModuleIndexer] ${service.name}: ${nodesCreated} modules, ${visited.size} total in tree`);
|
|
363
|
+
|
|
364
|
+
return createSuccessResult(
|
|
365
|
+
{ nodes: nodesCreated, edges: edgesCreated },
|
|
366
|
+
{ totalModules: visited.size }
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
} catch (error) {
|
|
370
|
+
console.error(`[JSModuleIndexer] Error:`, error);
|
|
371
|
+
return createErrorResult(error as Error);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|