@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,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SystemDbAnalyzer - специализированный плагин для анализа system_db API
|
|
3
|
+
*
|
|
4
|
+
* Понимает семантику system_db и добавляет ноды для сайд-эффектов:
|
|
5
|
+
* - system_db.use(view, server) -> регистрирует VIEW через get_view()
|
|
6
|
+
* - system_db.subscribe(servers) -> проверяет все зарегистрированные VIEW'ы
|
|
7
|
+
* - local.use(view) -> регистрирует VIEW в get_hosts()
|
|
8
|
+
*
|
|
9
|
+
* Добавляет специальные ноды:
|
|
10
|
+
* - SYSTEM_DB_VIEW_REGISTRATION - регистрация VIEW'а
|
|
11
|
+
* - SYSTEM_DB_SUBSCRIPTION - подписка на сервер
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync } from 'fs';
|
|
14
|
+
import { parse } from '@babel/parser';
|
|
15
|
+
import traverseModule from '@babel/traverse';
|
|
16
|
+
import { Plugin, createSuccessResult, createErrorResult } from '../Plugin.js';
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
const traverse = traverseModule.default || traverseModule;
|
|
19
|
+
export class SystemDbAnalyzer extends Plugin {
|
|
20
|
+
get metadata() {
|
|
21
|
+
return {
|
|
22
|
+
name: 'SystemDbAnalyzer',
|
|
23
|
+
phase: 'ANALYSIS',
|
|
24
|
+
priority: 85, // Run after JSASTAnalyzer
|
|
25
|
+
creates: {
|
|
26
|
+
nodes: ['SYSTEM_DB_VIEW_REGISTRATION', 'SYSTEM_DB_SUBSCRIPTION'],
|
|
27
|
+
edges: ['REGISTERS_VIEW', 'CHECKS_VIEWS']
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async execute(context) {
|
|
32
|
+
try {
|
|
33
|
+
const { graph } = context;
|
|
34
|
+
let nodesCreated = 0;
|
|
35
|
+
let edgesCreated = 0;
|
|
36
|
+
// Get all MODULE nodes
|
|
37
|
+
const modules = await this.getModules(graph);
|
|
38
|
+
console.log(`[SystemDbAnalyzer] Analyzing ${modules.length} modules for system_db patterns...\n`);
|
|
39
|
+
for (const module of modules) {
|
|
40
|
+
if (!module.file)
|
|
41
|
+
continue;
|
|
42
|
+
try {
|
|
43
|
+
const code = readFileSync(module.file, 'utf-8');
|
|
44
|
+
const ast = parse(code, {
|
|
45
|
+
sourceType: 'module',
|
|
46
|
+
plugins: ['jsx', 'typescript'],
|
|
47
|
+
errorRecovery: true
|
|
48
|
+
});
|
|
49
|
+
const registrations = [];
|
|
50
|
+
const subscriptions = [];
|
|
51
|
+
traverse(ast, {
|
|
52
|
+
CallExpression: (path) => {
|
|
53
|
+
const { node } = path;
|
|
54
|
+
// system_db.use(...)
|
|
55
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
56
|
+
node.callee.object.name === 'system_db' &&
|
|
57
|
+
node.callee.property.name === 'use') {
|
|
58
|
+
const viewName = this.extractLiteral(node.arguments[0]);
|
|
59
|
+
const serverName = this.extractLiteral(node.arguments[1]);
|
|
60
|
+
if (viewName) {
|
|
61
|
+
registrations.push({
|
|
62
|
+
type: 'system_db.use',
|
|
63
|
+
viewName,
|
|
64
|
+
serverName: serverName || 'default',
|
|
65
|
+
line: node.loc?.start.line || 0,
|
|
66
|
+
column: node.loc?.start.column || 0
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// system_db.subscribe(...)
|
|
71
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
72
|
+
node.callee.object.name === 'system_db' &&
|
|
73
|
+
node.callee.property.name === 'subscribe') {
|
|
74
|
+
const servers = this.extractServerList(node.arguments[0]);
|
|
75
|
+
subscriptions.push({
|
|
76
|
+
type: 'system_db.subscribe',
|
|
77
|
+
servers,
|
|
78
|
+
line: node.loc?.start.line || 0,
|
|
79
|
+
column: node.loc?.start.column || 0
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// local.use('view_name') - косвенная регистрация через get_hosts()
|
|
83
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
84
|
+
node.callee.object.name === 'local' &&
|
|
85
|
+
node.callee.property.name === 'use') {
|
|
86
|
+
const viewName = this.extractLiteral(node.arguments[0]);
|
|
87
|
+
if (viewName) {
|
|
88
|
+
registrations.push({
|
|
89
|
+
type: 'local.use',
|
|
90
|
+
viewName,
|
|
91
|
+
serverName: 'inferred_from_hosts',
|
|
92
|
+
line: node.loc?.start.line || 0,
|
|
93
|
+
column: node.loc?.start.column || 0
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// get_view(name, server) - внутренний API
|
|
98
|
+
if (node.callee.type === 'Identifier' &&
|
|
99
|
+
node.callee.name === 'get_view') {
|
|
100
|
+
const viewName = this.extractLiteral(node.arguments[0]);
|
|
101
|
+
const serverName = this.extractLiteral(node.arguments[1]);
|
|
102
|
+
if (viewName) {
|
|
103
|
+
registrations.push({
|
|
104
|
+
type: 'get_view',
|
|
105
|
+
viewName,
|
|
106
|
+
serverName: serverName || 'default',
|
|
107
|
+
line: node.loc?.start.line || 0,
|
|
108
|
+
column: node.loc?.start.column || 0
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
// Create SYSTEM_DB_VIEW_REGISTRATION nodes
|
|
115
|
+
for (const reg of registrations) {
|
|
116
|
+
const nodeId = `${module.file}:SYSTEM_DB_VIEW_REGISTRATION:${reg.viewName}:${reg.line}`;
|
|
117
|
+
console.log(` 📌 Found: ${reg.type}('${reg.viewName}', '${reg.serverName}') at ${module.file.split('/').pop()}:${reg.line}`);
|
|
118
|
+
await graph.addNode({
|
|
119
|
+
id: nodeId,
|
|
120
|
+
type: 'SYSTEM_DB_VIEW_REGISTRATION',
|
|
121
|
+
name: `${reg.type}('${reg.viewName}', '${reg.serverName}')`,
|
|
122
|
+
file: module.file,
|
|
123
|
+
line: reg.line,
|
|
124
|
+
column: reg.column,
|
|
125
|
+
viewName: reg.viewName,
|
|
126
|
+
serverName: reg.serverName,
|
|
127
|
+
callType: reg.type
|
|
128
|
+
});
|
|
129
|
+
nodesCreated++;
|
|
130
|
+
// Link MODULE -> REGISTERS_VIEW -> REGISTRATION
|
|
131
|
+
await graph.addEdge({
|
|
132
|
+
type: 'REGISTERS_VIEW',
|
|
133
|
+
src: module.id,
|
|
134
|
+
dst: nodeId
|
|
135
|
+
});
|
|
136
|
+
edgesCreated++;
|
|
137
|
+
}
|
|
138
|
+
// Create SYSTEM_DB_SUBSCRIPTION nodes
|
|
139
|
+
for (const sub of subscriptions) {
|
|
140
|
+
const nodeId = `${module.file}:SYSTEM_DB_SUBSCRIPTION:${sub.line}`;
|
|
141
|
+
await graph.addNode({
|
|
142
|
+
id: nodeId,
|
|
143
|
+
type: 'SYSTEM_DB_SUBSCRIPTION',
|
|
144
|
+
name: `subscribe([${sub.servers.join(', ')}])`,
|
|
145
|
+
file: module.file,
|
|
146
|
+
line: sub.line,
|
|
147
|
+
column: sub.column,
|
|
148
|
+
servers: sub.servers
|
|
149
|
+
});
|
|
150
|
+
nodesCreated++;
|
|
151
|
+
// Link MODULE -> CHECKS_VIEWS -> SUBSCRIPTION
|
|
152
|
+
await graph.addEdge({
|
|
153
|
+
type: 'CHECKS_VIEWS',
|
|
154
|
+
src: module.id,
|
|
155
|
+
dst: nodeId
|
|
156
|
+
});
|
|
157
|
+
edgesCreated++;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
// Skip files that can't be parsed
|
|
162
|
+
if (err.code !== 'ENOENT') {
|
|
163
|
+
console.error(` ⚠️ Failed to analyze ${module.file}: ${err.message}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
console.log(`[SystemDbAnalyzer] Created ${nodesCreated} system_db nodes, ${edgesCreated} edges\n`);
|
|
168
|
+
return createSuccessResult({ nodes: nodesCreated, edges: edgesCreated }, { modulesAnalyzed: modules.length });
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
console.error(`[SystemDbAnalyzer] Error:`, error);
|
|
172
|
+
return createErrorResult(error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Extract literal value from AST node
|
|
177
|
+
*/
|
|
178
|
+
extractLiteral(node) {
|
|
179
|
+
if (!node)
|
|
180
|
+
return null;
|
|
181
|
+
if (node.type === 'StringLiteral') {
|
|
182
|
+
return node.value;
|
|
183
|
+
}
|
|
184
|
+
if (node.type === 'TemplateLiteral') {
|
|
185
|
+
const tl = node;
|
|
186
|
+
if (tl.quasis.length === 1) {
|
|
187
|
+
return tl.quasis[0].value.cooked;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Extract server list from subscribe() argument
|
|
194
|
+
*/
|
|
195
|
+
extractServerList(node) {
|
|
196
|
+
if (!node)
|
|
197
|
+
return ['default'];
|
|
198
|
+
// String literal: subscribe('lum-unblocker')
|
|
199
|
+
if (node.type === 'StringLiteral') {
|
|
200
|
+
return [node.value];
|
|
201
|
+
}
|
|
202
|
+
// Array: subscribe(['lum', 'lum-views'])
|
|
203
|
+
if (node.type === 'ArrayExpression') {
|
|
204
|
+
const arr = node;
|
|
205
|
+
return arr.elements
|
|
206
|
+
.map(el => (el ? this.extractLiteral(el) : null))
|
|
207
|
+
.filter((s) => s !== null);
|
|
208
|
+
}
|
|
209
|
+
return ['unknown'];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConditionParser - парсит условия if/switch и извлекает constraints
|
|
3
|
+
*
|
|
4
|
+
* Поддерживаемые паттерны:
|
|
5
|
+
* - x === "value" → { variable: "x", operator: "===", value: "value" }
|
|
6
|
+
* - x !== "value" → { variable: "x", operator: "!==", value: "value", excludes: true }
|
|
7
|
+
* - x === "a" || x === "b" → { variable: "x", operator: "in", values: ["a", "b"] }
|
|
8
|
+
* - x === "a" && y === "b" → [{ variable: "x", ... }, { variable: "y", ... }]
|
|
9
|
+
*/
|
|
10
|
+
import type * as t from '@babel/types';
|
|
11
|
+
/**
|
|
12
|
+
* Constraint operator types
|
|
13
|
+
*/
|
|
14
|
+
type ConstraintOperator = '===' | '!==' | 'in' | 'not_in' | 'truthy' | 'falsy';
|
|
15
|
+
/**
|
|
16
|
+
* Simple constraint
|
|
17
|
+
*/
|
|
18
|
+
export interface SimpleConstraint {
|
|
19
|
+
variable: string;
|
|
20
|
+
operator: ConstraintOperator;
|
|
21
|
+
value?: unknown;
|
|
22
|
+
values?: unknown[];
|
|
23
|
+
excludes?: boolean;
|
|
24
|
+
negated?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compound constraint (OR/AND groups)
|
|
28
|
+
*/
|
|
29
|
+
export interface CompoundConstraint {
|
|
30
|
+
type: 'or' | 'and';
|
|
31
|
+
constraints: Constraint[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Combined constraint type
|
|
35
|
+
*/
|
|
36
|
+
export type Constraint = SimpleConstraint | CompoundConstraint;
|
|
37
|
+
export declare class ConditionParser {
|
|
38
|
+
/**
|
|
39
|
+
* Парсит AST условия и возвращает массив constraints
|
|
40
|
+
* @param testNode - AST нода условия (ifNode.test)
|
|
41
|
+
* @returns constraints
|
|
42
|
+
*/
|
|
43
|
+
static parse(testNode: t.Node | null | undefined): Constraint[];
|
|
44
|
+
/**
|
|
45
|
+
* Рекурсивно парсит ноду условия
|
|
46
|
+
* @param node - AST нода
|
|
47
|
+
* @param constraints - массив для накопления constraints
|
|
48
|
+
* @param negated - инвертировано ли условие (для else)
|
|
49
|
+
*/
|
|
50
|
+
private static _parseNode;
|
|
51
|
+
/**
|
|
52
|
+
* Парсит BinaryExpression (===, !==, ==, !=)
|
|
53
|
+
*/
|
|
54
|
+
private static _parseBinaryExpression;
|
|
55
|
+
/**
|
|
56
|
+
* Парсит LogicalExpression (&&, ||)
|
|
57
|
+
*/
|
|
58
|
+
private static _parseLogicalExpression;
|
|
59
|
+
/**
|
|
60
|
+
* Пытается объединить OR constraints для одной переменной
|
|
61
|
+
* x === "a" || x === "b" → { variable: x, operator: "in", values: ["a", "b"] }
|
|
62
|
+
*/
|
|
63
|
+
private static _tryMergeOrConstraints;
|
|
64
|
+
/**
|
|
65
|
+
* Проверяет является ли нода литеральным значением
|
|
66
|
+
*/
|
|
67
|
+
private static _isLiteralValue;
|
|
68
|
+
/**
|
|
69
|
+
* Извлекает значение из литеральной ноды
|
|
70
|
+
*/
|
|
71
|
+
private static _getLiteralValue;
|
|
72
|
+
/**
|
|
73
|
+
* Получает имя MemberExpression как строку
|
|
74
|
+
* obj.prop → "obj.prop"
|
|
75
|
+
*/
|
|
76
|
+
private static _getMemberExpressionName;
|
|
77
|
+
/**
|
|
78
|
+
* Создаёт negated версию constraints для else-блока
|
|
79
|
+
* @param constraints - оригинальные constraints
|
|
80
|
+
* @returns negated constraints
|
|
81
|
+
*/
|
|
82
|
+
static negate(constraints: Constraint[]): Constraint[];
|
|
83
|
+
}
|
|
84
|
+
export default ConditionParser;
|
|
85
|
+
//# sourceMappingURL=ConditionParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionParser.d.ts","sourceRoot":"","sources":["../../../../src/plugins/analysis/ast/ConditionParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,KAAK,CAAC,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,KAAK,kBAAkB,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC;IACnB,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAS/D,qBAAa,eAAe;IAC1B;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,EAAE;IAQ/D;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IA+CzB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IA6CrC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IA8BtC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAoBrC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAY9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAqB/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;IA4BvC;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE;CAiCvD;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConditionParser - парсит условия if/switch и извлекает constraints
|
|
3
|
+
*
|
|
4
|
+
* Поддерживаемые паттерны:
|
|
5
|
+
* - x === "value" → { variable: "x", operator: "===", value: "value" }
|
|
6
|
+
* - x !== "value" → { variable: "x", operator: "!==", value: "value", excludes: true }
|
|
7
|
+
* - x === "a" || x === "b" → { variable: "x", operator: "in", values: ["a", "b"] }
|
|
8
|
+
* - x === "a" && y === "b" → [{ variable: "x", ... }, { variable: "y", ... }]
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Type guard for compound constraints
|
|
12
|
+
*/
|
|
13
|
+
function isCompoundConstraint(c) {
|
|
14
|
+
return 'type' in c && (c.type === 'or' || c.type === 'and');
|
|
15
|
+
}
|
|
16
|
+
export class ConditionParser {
|
|
17
|
+
/**
|
|
18
|
+
* Парсит AST условия и возвращает массив constraints
|
|
19
|
+
* @param testNode - AST нода условия (ifNode.test)
|
|
20
|
+
* @returns constraints
|
|
21
|
+
*/
|
|
22
|
+
static parse(testNode) {
|
|
23
|
+
if (!testNode)
|
|
24
|
+
return [];
|
|
25
|
+
const constraints = [];
|
|
26
|
+
this._parseNode(testNode, constraints, false);
|
|
27
|
+
return constraints;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Рекурсивно парсит ноду условия
|
|
31
|
+
* @param node - AST нода
|
|
32
|
+
* @param constraints - массив для накопления constraints
|
|
33
|
+
* @param negated - инвертировано ли условие (для else)
|
|
34
|
+
*/
|
|
35
|
+
static _parseNode(node, constraints, negated) {
|
|
36
|
+
if (!node)
|
|
37
|
+
return;
|
|
38
|
+
switch (node.type) {
|
|
39
|
+
case 'BinaryExpression':
|
|
40
|
+
this._parseBinaryExpression(node, constraints, negated);
|
|
41
|
+
break;
|
|
42
|
+
case 'LogicalExpression':
|
|
43
|
+
this._parseLogicalExpression(node, constraints, negated);
|
|
44
|
+
break;
|
|
45
|
+
case 'UnaryExpression': {
|
|
46
|
+
const unaryNode = node;
|
|
47
|
+
if (unaryNode.operator === '!') {
|
|
48
|
+
// !condition → инвертируем
|
|
49
|
+
this._parseNode(unaryNode.argument, constraints, !negated);
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'Identifier': {
|
|
54
|
+
const identNode = node;
|
|
55
|
+
// if (x) → x is truthy
|
|
56
|
+
constraints.push({
|
|
57
|
+
variable: identNode.name,
|
|
58
|
+
operator: 'truthy',
|
|
59
|
+
negated
|
|
60
|
+
});
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'MemberExpression': {
|
|
64
|
+
// if (obj.prop) → obj.prop is truthy
|
|
65
|
+
const memberName = this._getMemberExpressionName(node);
|
|
66
|
+
if (memberName) {
|
|
67
|
+
constraints.push({
|
|
68
|
+
variable: memberName,
|
|
69
|
+
operator: 'truthy',
|
|
70
|
+
negated
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Парсит BinaryExpression (===, !==, ==, !=)
|
|
79
|
+
*/
|
|
80
|
+
static _parseBinaryExpression(node, constraints, negated) {
|
|
81
|
+
const { operator, left, right } = node;
|
|
82
|
+
// Поддерживаемые операторы
|
|
83
|
+
if (!['===', '!==', '==', '!='].includes(operator)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// Определяем переменную и значение
|
|
87
|
+
let variable = null;
|
|
88
|
+
let value = null;
|
|
89
|
+
// x === "value" или "value" === x
|
|
90
|
+
if (left.type === 'Identifier' && this._isLiteralValue(right)) {
|
|
91
|
+
variable = left.name;
|
|
92
|
+
value = this._getLiteralValue(right);
|
|
93
|
+
}
|
|
94
|
+
else if (right.type === 'Identifier' && this._isLiteralValue(left)) {
|
|
95
|
+
variable = right.name;
|
|
96
|
+
value = this._getLiteralValue(left);
|
|
97
|
+
}
|
|
98
|
+
// obj.prop === "value"
|
|
99
|
+
else if (left.type === 'MemberExpression' && this._isLiteralValue(right)) {
|
|
100
|
+
variable = this._getMemberExpressionName(left);
|
|
101
|
+
value = this._getLiteralValue(right);
|
|
102
|
+
}
|
|
103
|
+
else if (right.type === 'MemberExpression' && this._isLiteralValue(left)) {
|
|
104
|
+
variable = this._getMemberExpressionName(right);
|
|
105
|
+
value = this._getLiteralValue(left);
|
|
106
|
+
}
|
|
107
|
+
if (variable === null || value === null) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// Определяем тип constraint
|
|
111
|
+
const isNegation = operator === '!==' || operator === '!=';
|
|
112
|
+
const effectiveNegated = negated ? !isNegation : isNegation;
|
|
113
|
+
constraints.push({
|
|
114
|
+
variable,
|
|
115
|
+
operator: effectiveNegated ? '!==' : '===',
|
|
116
|
+
value,
|
|
117
|
+
excludes: effectiveNegated
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Парсит LogicalExpression (&&, ||)
|
|
122
|
+
*/
|
|
123
|
+
static _parseLogicalExpression(node, constraints, negated) {
|
|
124
|
+
const { operator, left, right } = node;
|
|
125
|
+
if (operator === '||') {
|
|
126
|
+
// OR: проверяем можно ли объединить в одну constraint
|
|
127
|
+
// x === "a" || x === "b" → { variable: x, values: ["a", "b"] }
|
|
128
|
+
const leftConstraints = [];
|
|
129
|
+
const rightConstraints = [];
|
|
130
|
+
this._parseNode(left, leftConstraints, negated);
|
|
131
|
+
this._parseNode(right, rightConstraints, negated);
|
|
132
|
+
// Пытаемся объединить constraints для одной переменной
|
|
133
|
+
const merged = this._tryMergeOrConstraints(leftConstraints, rightConstraints);
|
|
134
|
+
if (merged) {
|
|
135
|
+
constraints.push(merged);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// Не удалось объединить - добавляем как OR группу
|
|
139
|
+
constraints.push({
|
|
140
|
+
type: 'or',
|
|
141
|
+
constraints: [...leftConstraints, ...rightConstraints]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (operator === '&&') {
|
|
146
|
+
// AND: обе части должны быть true
|
|
147
|
+
this._parseNode(left, constraints, negated);
|
|
148
|
+
this._parseNode(right, constraints, negated);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Пытается объединить OR constraints для одной переменной
|
|
153
|
+
* x === "a" || x === "b" → { variable: x, operator: "in", values: ["a", "b"] }
|
|
154
|
+
*/
|
|
155
|
+
static _tryMergeOrConstraints(left, right) {
|
|
156
|
+
// Проверяем что обе части - простые equality constraints для одной переменной
|
|
157
|
+
if (left.length !== 1 || right.length !== 1)
|
|
158
|
+
return null;
|
|
159
|
+
const l = left[0];
|
|
160
|
+
const r = right[0];
|
|
161
|
+
// Type guards for simple constraints
|
|
162
|
+
if (isCompoundConstraint(l) || isCompoundConstraint(r))
|
|
163
|
+
return null;
|
|
164
|
+
if (l.variable !== r.variable)
|
|
165
|
+
return null;
|
|
166
|
+
if (l.operator !== '===' || r.operator !== '===')
|
|
167
|
+
return null;
|
|
168
|
+
return {
|
|
169
|
+
variable: l.variable,
|
|
170
|
+
operator: 'in',
|
|
171
|
+
values: [l.value, r.value]
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Проверяет является ли нода литеральным значением
|
|
176
|
+
*/
|
|
177
|
+
static _isLiteralValue(node) {
|
|
178
|
+
if (!node)
|
|
179
|
+
return false;
|
|
180
|
+
return (node.type === 'StringLiteral' ||
|
|
181
|
+
node.type === 'NumericLiteral' ||
|
|
182
|
+
node.type === 'BooleanLiteral' ||
|
|
183
|
+
node.type === 'NullLiteral' ||
|
|
184
|
+
node.type === 'Literal' // для некоторых парсеров (ESTree)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Извлекает значение из литеральной ноды
|
|
189
|
+
*/
|
|
190
|
+
static _getLiteralValue(node) {
|
|
191
|
+
if (!node)
|
|
192
|
+
return null;
|
|
193
|
+
switch (node.type) {
|
|
194
|
+
case 'StringLiteral':
|
|
195
|
+
return node.value;
|
|
196
|
+
case 'NumericLiteral':
|
|
197
|
+
return node.value;
|
|
198
|
+
case 'BooleanLiteral':
|
|
199
|
+
return node.value;
|
|
200
|
+
case 'NullLiteral':
|
|
201
|
+
return null;
|
|
202
|
+
default:
|
|
203
|
+
// Handle ESTree 'Literal' type
|
|
204
|
+
if (node.type === 'Literal') {
|
|
205
|
+
return node.value;
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Получает имя MemberExpression как строку
|
|
212
|
+
* obj.prop → "obj.prop"
|
|
213
|
+
*/
|
|
214
|
+
static _getMemberExpressionName(node) {
|
|
215
|
+
if (node.type !== 'MemberExpression')
|
|
216
|
+
return null;
|
|
217
|
+
const parts = [];
|
|
218
|
+
let current = node;
|
|
219
|
+
while (current.type === 'MemberExpression') {
|
|
220
|
+
const memberNode = current;
|
|
221
|
+
if (memberNode.computed) {
|
|
222
|
+
// obj[x] - не можем статически определить
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
if (memberNode.property.type === 'Identifier') {
|
|
226
|
+
parts.unshift(memberNode.property.name);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
current = memberNode.object;
|
|
232
|
+
}
|
|
233
|
+
if (current.type === 'Identifier') {
|
|
234
|
+
parts.unshift(current.name);
|
|
235
|
+
return parts.join('.');
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Создаёт negated версию constraints для else-блока
|
|
241
|
+
* @param constraints - оригинальные constraints
|
|
242
|
+
* @returns negated constraints
|
|
243
|
+
*/
|
|
244
|
+
static negate(constraints) {
|
|
245
|
+
return constraints.map(c => {
|
|
246
|
+
if (isCompoundConstraint(c)) {
|
|
247
|
+
if (c.type === 'or') {
|
|
248
|
+
// De Morgan: !(A || B) = !A && !B
|
|
249
|
+
return {
|
|
250
|
+
type: 'and',
|
|
251
|
+
constraints: this.negate(c.constraints)
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// De Morgan: !(A && B) = !A || !B
|
|
256
|
+
return {
|
|
257
|
+
type: 'or',
|
|
258
|
+
constraints: this.negate(c.constraints)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Инвертируем operator
|
|
263
|
+
const negatedOp = c.operator === '===' ? '!==' :
|
|
264
|
+
c.operator === '!==' ? '===' :
|
|
265
|
+
c.operator === 'in' ? 'not_in' :
|
|
266
|
+
c.operator === 'truthy' ? 'falsy' :
|
|
267
|
+
c.operator;
|
|
268
|
+
return {
|
|
269
|
+
...c,
|
|
270
|
+
operator: negatedOp,
|
|
271
|
+
excludes: !c.excludes,
|
|
272
|
+
negated: !c.negated
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
export default ConditionParser;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExpressionEvaluator - utilities for evaluating AST expressions
|
|
3
|
+
*/
|
|
4
|
+
import type { Node } from '@babel/types';
|
|
5
|
+
export type LiteralValue = string | number | boolean | null | undefined | LiteralValue[] | {
|
|
6
|
+
[key: string]: LiteralValue;
|
|
7
|
+
};
|
|
8
|
+
export declare class ExpressionEvaluator {
|
|
9
|
+
/**
|
|
10
|
+
* Extract literal value from AST node
|
|
11
|
+
* Returns null if not a literal
|
|
12
|
+
*/
|
|
13
|
+
static extractLiteralValue(node: Node | null | undefined): LiteralValue | null;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ExpressionEvaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpressionEvaluator.d.ts","sourceRoot":"","sources":["../../../../src/plugins/analysis/ast/ExpressionEvaluator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACV,IAAI,EAUL,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAC;AAE3H,qBAAa,mBAAmB;IAC9B;;;OAGG;IACH,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,GAAG,IAAI;CA6F/E"}
|