@grafema/core 0.1.1-alpha → 0.2.0-beta
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/dist/Orchestrator.d.ts +7 -0
- package/dist/Orchestrator.d.ts.map +1 -1
- package/dist/Orchestrator.js +25 -3
- package/dist/config/ConfigLoader.d.ts +18 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -1
- package/dist/config/ConfigLoader.js +65 -3
- package/dist/core/FileExplainer.d.ts +101 -0
- package/dist/core/FileExplainer.d.ts.map +1 -0
- package/dist/core/FileExplainer.js +139 -0
- package/dist/core/NodeFactory.d.ts +44 -5
- package/dist/core/NodeFactory.d.ts.map +1 -1
- package/dist/core/NodeFactory.js +52 -7
- package/dist/core/nodes/ArrayLiteralNode.d.ts.map +1 -1
- package/dist/core/nodes/ArrayLiteralNode.js +4 -2
- package/dist/core/nodes/BranchNode.d.ts +41 -0
- package/dist/core/nodes/BranchNode.d.ts.map +1 -0
- package/dist/core/nodes/BranchNode.js +82 -0
- package/dist/core/nodes/CallSiteNode.d.ts +2 -2
- package/dist/core/nodes/CallSiteNode.d.ts.map +1 -1
- package/dist/core/nodes/CallSiteNode.js +9 -5
- package/dist/core/nodes/CaseNode.d.ts +43 -0
- package/dist/core/nodes/CaseNode.d.ts.map +1 -0
- package/dist/core/nodes/CaseNode.js +81 -0
- package/dist/core/nodes/ClassNode.d.ts +2 -2
- package/dist/core/nodes/ClassNode.d.ts.map +1 -1
- package/dist/core/nodes/ClassNode.js +8 -4
- package/dist/core/nodes/ConstantNode.d.ts +2 -2
- package/dist/core/nodes/ConstantNode.d.ts.map +1 -1
- package/dist/core/nodes/ConstantNode.js +6 -4
- package/dist/core/nodes/ConstructorCallNode.d.ts +51 -0
- package/dist/core/nodes/ConstructorCallNode.d.ts.map +1 -0
- package/dist/core/nodes/ConstructorCallNode.js +171 -0
- package/dist/core/nodes/DatabaseQueryNode.d.ts +3 -2
- package/dist/core/nodes/DatabaseQueryNode.d.ts.map +1 -1
- package/dist/core/nodes/DatabaseQueryNode.js +5 -2
- package/dist/core/nodes/DecoratorNode.d.ts +2 -2
- package/dist/core/nodes/DecoratorNode.d.ts.map +1 -1
- package/dist/core/nodes/DecoratorNode.js +5 -3
- package/dist/core/nodes/EnumNode.d.ts +2 -2
- package/dist/core/nodes/EnumNode.d.ts.map +1 -1
- package/dist/core/nodes/EnumNode.js +5 -3
- package/dist/core/nodes/EventListenerNode.d.ts +4 -4
- package/dist/core/nodes/EventListenerNode.d.ts.map +1 -1
- package/dist/core/nodes/EventListenerNode.js +7 -4
- package/dist/core/nodes/ExportNode.d.ts +2 -2
- package/dist/core/nodes/ExportNode.d.ts.map +1 -1
- package/dist/core/nodes/ExportNode.js +8 -4
- package/dist/core/nodes/ExpressionNode.d.ts +2 -2
- package/dist/core/nodes/ExpressionNode.d.ts.map +1 -1
- package/dist/core/nodes/ExpressionNode.js +6 -4
- package/dist/core/nodes/ExternalModuleNode.d.ts +4 -0
- package/dist/core/nodes/ExternalModuleNode.d.ts.map +1 -1
- package/dist/core/nodes/ExternalModuleNode.js +10 -2
- package/dist/core/nodes/HttpRequestNode.d.ts +4 -4
- package/dist/core/nodes/HttpRequestNode.d.ts.map +1 -1
- package/dist/core/nodes/HttpRequestNode.js +7 -4
- package/dist/core/nodes/ImportNode.d.ts +10 -2
- package/dist/core/nodes/ImportNode.d.ts.map +1 -1
- package/dist/core/nodes/ImportNode.js +21 -4
- package/dist/core/nodes/InterfaceNode.d.ts +2 -2
- package/dist/core/nodes/InterfaceNode.d.ts.map +1 -1
- package/dist/core/nodes/InterfaceNode.js +5 -3
- package/dist/core/nodes/LiteralNode.d.ts +2 -2
- package/dist/core/nodes/LiteralNode.d.ts.map +1 -1
- package/dist/core/nodes/LiteralNode.js +6 -4
- package/dist/core/nodes/MethodCallNode.d.ts +2 -2
- package/dist/core/nodes/MethodCallNode.d.ts.map +1 -1
- package/dist/core/nodes/MethodCallNode.js +9 -5
- package/dist/core/nodes/MethodNode.d.ts +2 -2
- package/dist/core/nodes/MethodNode.d.ts.map +1 -1
- package/dist/core/nodes/MethodNode.js +8 -4
- package/dist/core/nodes/ObjectLiteralNode.d.ts.map +1 -1
- package/dist/core/nodes/ObjectLiteralNode.js +4 -2
- package/dist/core/nodes/ParameterNode.d.ts +2 -2
- package/dist/core/nodes/ParameterNode.d.ts.map +1 -1
- package/dist/core/nodes/ParameterNode.js +5 -3
- package/dist/core/nodes/TypeNode.d.ts +2 -2
- package/dist/core/nodes/TypeNode.d.ts.map +1 -1
- package/dist/core/nodes/TypeNode.js +5 -3
- package/dist/core/nodes/VariableDeclarationNode.d.ts +2 -2
- package/dist/core/nodes/VariableDeclarationNode.d.ts.map +1 -1
- package/dist/core/nodes/VariableDeclarationNode.js +9 -5
- package/dist/core/nodes/index.d.ts +3 -0
- package/dist/core/nodes/index.d.ts.map +1 -1
- package/dist/core/nodes/index.js +3 -0
- package/dist/data/builtins/BuiltinRegistry.d.ts +78 -0
- package/dist/data/builtins/BuiltinRegistry.d.ts.map +1 -0
- package/dist/data/builtins/BuiltinRegistry.js +110 -0
- package/dist/data/builtins/definitions.d.ts +28 -0
- package/dist/data/builtins/definitions.d.ts.map +1 -0
- package/dist/data/builtins/definitions.js +250 -0
- package/dist/data/builtins/index.d.ts +10 -0
- package/dist/data/builtins/index.d.ts.map +1 -0
- package/dist/data/builtins/index.js +8 -0
- package/dist/data/builtins/jsGlobals.d.ts +18 -0
- package/dist/data/builtins/jsGlobals.d.ts.map +1 -0
- package/dist/data/builtins/jsGlobals.js +26 -0
- package/dist/data/builtins/types.d.ts +34 -0
- package/dist/data/builtins/types.d.ts.map +1 -0
- package/dist/data/builtins/types.js +7 -0
- package/dist/data/globals/definitions.d.ts +27 -0
- package/dist/data/globals/definitions.d.ts.map +1 -0
- package/dist/data/globals/definitions.js +117 -0
- package/dist/data/globals/index.d.ts +36 -0
- package/dist/data/globals/index.d.ts.map +1 -0
- package/dist/data/globals/index.js +52 -0
- package/dist/diagnostics/DiagnosticReporter.d.ts +23 -0
- package/dist/diagnostics/DiagnosticReporter.d.ts.map +1 -1
- package/dist/diagnostics/DiagnosticReporter.js +88 -0
- package/dist/diagnostics/index.d.ts +1 -1
- package/dist/diagnostics/index.d.ts.map +1 -1
- package/dist/errors/GrafemaError.d.ts +43 -0
- package/dist/errors/GrafemaError.d.ts.map +1 -1
- package/dist/errors/GrafemaError.js +50 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -1
- package/dist/plugins/analysis/DatabaseAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/DatabaseAnalyzer.js +3 -2
- package/dist/plugins/analysis/ExpressAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/ExpressAnalyzer.js +3 -1
- package/dist/plugins/analysis/ExpressResponseAnalyzer.d.ts +148 -0
- package/dist/plugins/analysis/ExpressResponseAnalyzer.d.ts.map +1 -0
- package/dist/plugins/analysis/ExpressResponseAnalyzer.js +495 -0
- package/dist/plugins/analysis/ExpressRouteAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/ExpressRouteAnalyzer.js +53 -18
- package/dist/plugins/analysis/FetchAnalyzer.d.ts +40 -0
- package/dist/plugins/analysis/FetchAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/FetchAnalyzer.js +163 -15
- package/dist/plugins/analysis/JSASTAnalyzer.d.ts +157 -26
- package/dist/plugins/analysis/JSASTAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/JSASTAnalyzer.js +2418 -191
- package/dist/plugins/analysis/RustAnalyzer.js +4 -4
- package/dist/plugins/analysis/SQLiteAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/SQLiteAnalyzer.js +4 -2
- package/dist/plugins/analysis/SocketIOAnalyzer.d.ts +9 -0
- package/dist/plugins/analysis/SocketIOAnalyzer.d.ts.map +1 -1
- package/dist/plugins/analysis/SocketIOAnalyzer.js +91 -7
- package/dist/plugins/analysis/ast/GraphBuilder.d.ts +173 -0
- package/dist/plugins/analysis/ast/GraphBuilder.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/GraphBuilder.js +1256 -65
- package/dist/plugins/analysis/ast/types.d.ts +294 -0
- package/dist/plugins/analysis/ast/types.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/ASTVisitor.d.ts +5 -1
- package/dist/plugins/analysis/ast/visitors/ASTVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.d.ts +1 -0
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.js +12 -1
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.d.ts +10 -0
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/FunctionVisitor.js +62 -0
- package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.d.ts +4 -0
- package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.js +101 -0
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.d.ts +16 -1
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.d.ts.map +1 -1
- package/dist/plugins/analysis/ast/visitors/VariableVisitor.js +233 -39
- package/dist/plugins/discovery/WorkspaceDiscovery.d.ts.map +1 -1
- package/dist/plugins/discovery/WorkspaceDiscovery.js +9 -4
- package/dist/plugins/enrichment/AliasTracker.d.ts.map +1 -1
- package/dist/plugins/enrichment/AliasTracker.js +16 -1
- package/dist/plugins/enrichment/ArgumentParameterLinker.d.ts +32 -0
- package/dist/plugins/enrichment/ArgumentParameterLinker.d.ts.map +1 -0
- package/dist/plugins/enrichment/ArgumentParameterLinker.js +175 -0
- package/dist/plugins/enrichment/ClosureCaptureEnricher.d.ts +51 -0
- package/dist/plugins/enrichment/ClosureCaptureEnricher.d.ts.map +1 -0
- package/dist/plugins/enrichment/ClosureCaptureEnricher.js +205 -0
- package/dist/plugins/enrichment/ExternalCallResolver.d.ts +42 -0
- package/dist/plugins/enrichment/ExternalCallResolver.d.ts.map +1 -0
- package/dist/plugins/enrichment/ExternalCallResolver.js +213 -0
- package/dist/plugins/enrichment/FunctionCallResolver.d.ts +58 -0
- package/dist/plugins/enrichment/FunctionCallResolver.d.ts.map +1 -0
- package/dist/plugins/enrichment/FunctionCallResolver.js +340 -0
- package/dist/plugins/enrichment/HTTPConnectionEnricher.d.ts +16 -3
- package/dist/plugins/enrichment/HTTPConnectionEnricher.d.ts.map +1 -1
- package/dist/plugins/enrichment/HTTPConnectionEnricher.js +64 -20
- package/dist/plugins/enrichment/MethodCallResolver.d.ts.map +1 -1
- package/dist/plugins/enrichment/MethodCallResolver.js +15 -1
- package/dist/plugins/enrichment/MountPointResolver.d.ts +14 -12
- package/dist/plugins/enrichment/MountPointResolver.d.ts.map +1 -1
- package/dist/plugins/enrichment/MountPointResolver.js +172 -151
- package/dist/plugins/enrichment/NodejsBuiltinsResolver.d.ts +44 -0
- package/dist/plugins/enrichment/NodejsBuiltinsResolver.d.ts.map +1 -0
- package/dist/plugins/enrichment/NodejsBuiltinsResolver.js +271 -0
- package/dist/plugins/enrichment/ValueDomainAnalyzer.d.ts +5 -27
- package/dist/plugins/enrichment/ValueDomainAnalyzer.d.ts.map +1 -1
- package/dist/plugins/enrichment/ValueDomainAnalyzer.js +62 -139
- package/dist/plugins/indexing/JSModuleIndexer.d.ts +15 -0
- package/dist/plugins/indexing/JSModuleIndexer.d.ts.map +1 -1
- package/dist/plugins/indexing/JSModuleIndexer.js +58 -0
- package/dist/plugins/indexing/RustModuleIndexer.d.ts +1 -1
- package/dist/plugins/indexing/RustModuleIndexer.js +4 -4
- package/dist/plugins/validation/BrokenImportValidator.d.ts +31 -0
- package/dist/plugins/validation/BrokenImportValidator.d.ts.map +1 -0
- package/dist/plugins/validation/BrokenImportValidator.js +249 -0
- package/dist/plugins/validation/CallResolverValidator.d.ts +21 -10
- package/dist/plugins/validation/CallResolverValidator.d.ts.map +1 -1
- package/dist/plugins/validation/CallResolverValidator.js +101 -76
- package/dist/plugins/validation/DataFlowValidator.d.ts.map +1 -1
- package/dist/plugins/validation/DataFlowValidator.js +49 -41
- package/dist/plugins/validation/GraphConnectivityValidator.d.ts.map +1 -1
- package/dist/plugins/validation/GraphConnectivityValidator.js +25 -1
- package/dist/plugins/validation/SQLInjectionValidator.d.ts.map +1 -1
- package/dist/plugins/validation/SQLInjectionValidator.js +2 -3
- package/dist/queries/findCallsInFunction.d.ts +52 -0
- package/dist/queries/findCallsInFunction.d.ts.map +1 -0
- package/dist/queries/findCallsInFunction.js +135 -0
- package/dist/queries/findContainingFunction.d.ts +45 -0
- package/dist/queries/findContainingFunction.d.ts.map +1 -0
- package/dist/queries/findContainingFunction.js +54 -0
- package/dist/queries/index.d.ts +14 -0
- package/dist/queries/index.d.ts.map +1 -0
- package/dist/queries/index.js +11 -0
- package/dist/queries/traceValues.d.ts +70 -0
- package/dist/queries/traceValues.d.ts.map +1 -0
- package/dist/queries/traceValues.js +299 -0
- package/dist/queries/types.d.ts +163 -0
- package/dist/queries/types.d.ts.map +1 -0
- package/dist/queries/types.js +9 -0
- package/dist/schema/GraphSchemaExtractor.d.ts +53 -0
- package/dist/schema/GraphSchemaExtractor.d.ts.map +1 -0
- package/dist/schema/GraphSchemaExtractor.js +124 -0
- package/dist/schema/InterfaceSchemaExtractor.d.ts +73 -0
- package/dist/schema/InterfaceSchemaExtractor.d.ts.map +1 -0
- package/dist/schema/InterfaceSchemaExtractor.js +112 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +2 -0
- package/dist/storage/backends/RFDBServerBackend.d.ts +12 -18
- package/dist/storage/backends/RFDBServerBackend.d.ts.map +1 -1
- package/dist/storage/backends/RFDBServerBackend.js +41 -52
- package/dist/storage/backends/typeValidation.d.ts.map +1 -1
- package/dist/storage/backends/typeValidation.js +1 -0
- package/package.json +3 -3
- package/src/Orchestrator.ts +35 -3
- package/src/config/ConfigLoader.ts +94 -3
- package/src/core/FileExplainer.ts +179 -0
- package/src/core/NodeFactory.ts +72 -8
- package/src/core/nodes/ArrayLiteralNode.ts +3 -2
- package/src/core/nodes/BranchNode.ts +113 -0
- package/src/core/nodes/CallSiteNode.ts +7 -5
- package/src/core/nodes/CaseNode.ts +123 -0
- package/src/core/nodes/ClassNode.ts +6 -4
- package/src/core/nodes/ConstantNode.ts +5 -4
- package/src/core/nodes/ConstructorCallNode.ts +217 -0
- package/src/core/nodes/DatabaseQueryNode.ts +5 -1
- package/src/core/nodes/DecoratorNode.ts +4 -3
- package/src/core/nodes/EnumNode.ts +4 -3
- package/src/core/nodes/EventListenerNode.ts +7 -4
- package/src/core/nodes/ExportNode.ts +6 -4
- package/src/core/nodes/ExpressionNode.ts +5 -4
- package/src/core/nodes/ExternalModuleNode.ts +11 -2
- package/src/core/nodes/HttpRequestNode.ts +7 -4
- package/src/core/nodes/ImportNode.ts +31 -4
- package/src/core/nodes/InterfaceNode.ts +4 -3
- package/src/core/nodes/LiteralNode.ts +5 -4
- package/src/core/nodes/MethodCallNode.ts +7 -5
- package/src/core/nodes/MethodNode.ts +6 -4
- package/src/core/nodes/ObjectLiteralNode.ts +3 -2
- package/src/core/nodes/ParameterNode.ts +4 -3
- package/src/core/nodes/TypeNode.ts +4 -3
- package/src/core/nodes/VariableDeclarationNode.ts +7 -5
- package/src/core/nodes/index.ts +3 -0
- package/src/data/builtins/BuiltinRegistry.ts +124 -0
- package/src/data/builtins/definitions.ts +267 -0
- package/src/data/builtins/index.ts +10 -0
- package/src/data/builtins/jsGlobals.ts +28 -0
- package/src/data/builtins/types.ts +36 -0
- package/src/data/globals/definitions.ts +156 -0
- package/src/data/globals/index.ts +66 -0
- package/src/diagnostics/DiagnosticReporter.ts +120 -0
- package/src/diagnostics/index.ts +1 -1
- package/src/errors/GrafemaError.ts +65 -0
- package/src/index.ts +45 -0
- package/src/plugins/analysis/DatabaseAnalyzer.ts +4 -2
- package/src/plugins/analysis/ExpressAnalyzer.ts +5 -1
- package/src/plugins/analysis/ExpressResponseAnalyzer.ts +636 -0
- package/src/plugins/analysis/ExpressRouteAnalyzer.ts +57 -18
- package/src/plugins/analysis/FetchAnalyzer.ts +204 -16
- package/src/plugins/analysis/JSASTAnalyzer.ts +2958 -260
- package/src/plugins/analysis/RustAnalyzer.ts +4 -4
- package/src/plugins/analysis/SQLiteAnalyzer.ts +5 -2
- package/src/plugins/analysis/SocketIOAnalyzer.ts +121 -7
- package/src/plugins/analysis/ast/GraphBuilder.ts +1578 -70
- package/src/plugins/analysis/ast/types.ts +387 -0
- package/src/plugins/analysis/ast/visitors/ASTVisitor.ts +8 -0
- package/src/plugins/analysis/ast/visitors/CallExpressionVisitor.ts +16 -1
- package/src/plugins/analysis/ast/visitors/FunctionVisitor.ts +77 -2
- package/src/plugins/analysis/ast/visitors/ImportExportVisitor.ts +112 -1
- package/src/plugins/analysis/ast/visitors/VariableVisitor.ts +272 -47
- package/src/plugins/discovery/WorkspaceDiscovery.ts +11 -4
- package/src/plugins/enrichment/AliasTracker.ts +22 -1
- package/src/plugins/enrichment/ArgumentParameterLinker.ts +240 -0
- package/src/plugins/enrichment/ClosureCaptureEnricher.ts +267 -0
- package/src/plugins/enrichment/ExternalCallResolver.ts +262 -0
- package/src/plugins/enrichment/FunctionCallResolver.ts +456 -0
- package/src/plugins/enrichment/HTTPConnectionEnricher.ts +70 -20
- package/src/plugins/enrichment/MethodCallResolver.ts +21 -1
- package/src/plugins/enrichment/MountPointResolver.ts +206 -198
- package/src/plugins/enrichment/NodejsBuiltinsResolver.ts +365 -0
- package/src/plugins/enrichment/ValueDomainAnalyzer.ts +67 -184
- package/src/plugins/indexing/JSModuleIndexer.ts +66 -0
- package/src/plugins/indexing/RustModuleIndexer.ts +4 -4
- package/src/plugins/validation/BrokenImportValidator.ts +325 -0
- package/src/plugins/validation/CallResolverValidator.ts +129 -109
- package/src/plugins/validation/DataFlowValidator.ts +75 -58
- package/src/plugins/validation/GraphConnectivityValidator.ts +39 -1
- package/src/plugins/validation/SQLInjectionValidator.ts +2 -5
- package/src/queries/README.md +46 -0
- package/src/queries/findCallsInFunction.ts +206 -0
- package/src/queries/findContainingFunction.ts +83 -0
- package/src/queries/index.ts +23 -0
- package/src/queries/traceValues.ts +398 -0
- package/src/queries/types.ts +187 -0
- package/src/schema/GraphSchemaExtractor.ts +177 -0
- package/src/schema/InterfaceSchemaExtractor.ts +173 -0
- package/src/schema/index.ts +5 -0
- package/src/storage/backends/RFDBServerBackend.ts +58 -70
- package/src/storage/backends/typeValidation.ts +1 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the FUNCTION, CLASS, or MODULE that contains a node.
|
|
3
|
+
*
|
|
4
|
+
* Graph structure (backward traversal):
|
|
5
|
+
* ```
|
|
6
|
+
* CALL <- CONTAINS <- SCOPE <- ... <- SCOPE <- HAS_SCOPE <- FUNCTION
|
|
7
|
+
* VARIABLE <- DECLARES <- SCOPE <- ... <- SCOPE <- HAS_SCOPE <- FUNCTION
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Algorithm:
|
|
11
|
+
* 1. BFS up the containment tree via CONTAINS and DECLARES edges
|
|
12
|
+
* 2. Also follow HAS_SCOPE edges (connects FUNCTION to its body SCOPE)
|
|
13
|
+
* 3. Stop when we find FUNCTION, CLASS, or MODULE
|
|
14
|
+
*
|
|
15
|
+
* @module queries/findContainingFunction
|
|
16
|
+
*/
|
|
17
|
+
import type { CallerInfo } from './types.js';
|
|
18
|
+
/**
|
|
19
|
+
* Graph backend interface (minimal surface)
|
|
20
|
+
*/
|
|
21
|
+
interface GraphBackend {
|
|
22
|
+
getNode(id: string): Promise<{
|
|
23
|
+
id: string;
|
|
24
|
+
type: string;
|
|
25
|
+
name: string;
|
|
26
|
+
file?: string;
|
|
27
|
+
line?: number;
|
|
28
|
+
} | null>;
|
|
29
|
+
getIncomingEdges(nodeId: string, edgeTypes: string[] | null): Promise<Array<{
|
|
30
|
+
src: string;
|
|
31
|
+
dst: string;
|
|
32
|
+
type: string;
|
|
33
|
+
}>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Find the FUNCTION, CLASS, or MODULE that contains a node.
|
|
37
|
+
*
|
|
38
|
+
* @param backend - Graph backend for queries
|
|
39
|
+
* @param nodeId - ID of the node to find container for
|
|
40
|
+
* @param maxDepth - Maximum traversal depth (default: 15)
|
|
41
|
+
* @returns CallerInfo or null if no container found
|
|
42
|
+
*/
|
|
43
|
+
export declare function findContainingFunction(backend: GraphBackend, nodeId: string, maxDepth?: number): Promise<CallerInfo | null>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=findContainingFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findContainingFunction.d.ts","sourceRoot":"","sources":["../../src/queries/findContainingFunction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,UAAU,YAAY;IACpB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAC3B,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,IAAI,CAAC,CAAC;IACV,gBAAgB,CACd,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,GACzB,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CAC/D;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,MAAW,GACpB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAkC5B"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the FUNCTION, CLASS, or MODULE that contains a node.
|
|
3
|
+
*
|
|
4
|
+
* Graph structure (backward traversal):
|
|
5
|
+
* ```
|
|
6
|
+
* CALL <- CONTAINS <- SCOPE <- ... <- SCOPE <- HAS_SCOPE <- FUNCTION
|
|
7
|
+
* VARIABLE <- DECLARES <- SCOPE <- ... <- SCOPE <- HAS_SCOPE <- FUNCTION
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Algorithm:
|
|
11
|
+
* 1. BFS up the containment tree via CONTAINS and DECLARES edges
|
|
12
|
+
* 2. Also follow HAS_SCOPE edges (connects FUNCTION to its body SCOPE)
|
|
13
|
+
* 3. Stop when we find FUNCTION, CLASS, or MODULE
|
|
14
|
+
*
|
|
15
|
+
* @module queries/findContainingFunction
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Find the FUNCTION, CLASS, or MODULE that contains a node.
|
|
19
|
+
*
|
|
20
|
+
* @param backend - Graph backend for queries
|
|
21
|
+
* @param nodeId - ID of the node to find container for
|
|
22
|
+
* @param maxDepth - Maximum traversal depth (default: 15)
|
|
23
|
+
* @returns CallerInfo or null if no container found
|
|
24
|
+
*/
|
|
25
|
+
export async function findContainingFunction(backend, nodeId, maxDepth = 15) {
|
|
26
|
+
const visited = new Set();
|
|
27
|
+
const queue = [{ id: nodeId, depth: 0 }];
|
|
28
|
+
while (queue.length > 0) {
|
|
29
|
+
const { id, depth } = queue.shift();
|
|
30
|
+
if (visited.has(id) || depth > maxDepth)
|
|
31
|
+
continue;
|
|
32
|
+
visited.add(id);
|
|
33
|
+
// Get incoming edges: CONTAINS, HAS_SCOPE, and DECLARES (for variables)
|
|
34
|
+
const edges = await backend.getIncomingEdges(id, ['CONTAINS', 'HAS_SCOPE', 'DECLARES']);
|
|
35
|
+
for (const edge of edges) {
|
|
36
|
+
const parentNode = await backend.getNode(edge.src);
|
|
37
|
+
if (!parentNode || visited.has(parentNode.id))
|
|
38
|
+
continue;
|
|
39
|
+
// Found container!
|
|
40
|
+
if (parentNode.type === 'FUNCTION' || parentNode.type === 'CLASS' || parentNode.type === 'MODULE') {
|
|
41
|
+
return {
|
|
42
|
+
id: parentNode.id,
|
|
43
|
+
name: parentNode.name || '<anonymous>',
|
|
44
|
+
type: parentNode.type,
|
|
45
|
+
file: parentNode.file,
|
|
46
|
+
line: parentNode.line,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Continue searching
|
|
50
|
+
queue.push({ id: parentNode.id, depth: depth + 1 });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph Query Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities for querying the code graph.
|
|
5
|
+
* Used by MCP, CLI, and other tools.
|
|
6
|
+
*
|
|
7
|
+
* @module queries
|
|
8
|
+
*/
|
|
9
|
+
export { findCallsInFunction } from './findCallsInFunction.js';
|
|
10
|
+
export { findContainingFunction } from './findContainingFunction.js';
|
|
11
|
+
export { traceValues, aggregateValues, NONDETERMINISTIC_PATTERNS, NONDETERMINISTIC_OBJECTS } from './traceValues.js';
|
|
12
|
+
export type { CallInfo, CallerInfo, FindCallsOptions } from './types.js';
|
|
13
|
+
export type { TracedValue, ValueSource, UnknownReason, TraceValuesOptions, ValueSetResult, TraceValuesGraphBackend, NondeterministicPattern, } from './types.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/queries/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAErH,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACzE,YAAY,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph Query Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities for querying the code graph.
|
|
5
|
+
* Used by MCP, CLI, and other tools.
|
|
6
|
+
*
|
|
7
|
+
* @module queries
|
|
8
|
+
*/
|
|
9
|
+
export { findCallsInFunction } from './findCallsInFunction.js';
|
|
10
|
+
export { findContainingFunction } from './findContainingFunction.js';
|
|
11
|
+
export { traceValues, aggregateValues, NONDETERMINISTIC_PATTERNS, NONDETERMINISTIC_OBJECTS } from './traceValues.js';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value Tracing Utility (REG-244)
|
|
3
|
+
*
|
|
4
|
+
* Traces a node through ASSIGNED_FROM/DERIVES_FROM edges to find
|
|
5
|
+
* all possible literal values or mark as unknown.
|
|
6
|
+
*
|
|
7
|
+
* Graph structure:
|
|
8
|
+
* ```
|
|
9
|
+
* VARIABLE -[ASSIGNED_FROM]-> LITERAL (concrete value)
|
|
10
|
+
* VARIABLE -[ASSIGNED_FROM]-> PARAMETER (unknown: runtime input)
|
|
11
|
+
* VARIABLE -[ASSIGNED_FROM]-> CALL (unknown: function return)
|
|
12
|
+
* VARIABLE -[DERIVES_FROM]-> EXPRESSION (check nondeterministic patterns)
|
|
13
|
+
* VARIABLE -[ASSIGNED_FROM]-> VARIABLE (chain - recurse)
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Used by:
|
|
17
|
+
* - CLI trace command (sink-based tracing)
|
|
18
|
+
* - ValueDomainAnalyzer (computed member access resolution)
|
|
19
|
+
*
|
|
20
|
+
* @module queries/traceValues
|
|
21
|
+
*/
|
|
22
|
+
import type { TracedValue, TraceValuesOptions, TraceValuesGraphBackend, ValueSetResult, NondeterministicPattern } from './types.js';
|
|
23
|
+
/**
|
|
24
|
+
* Nondeterministic MemberExpression patterns.
|
|
25
|
+
* object.property combinations that represent external/user input.
|
|
26
|
+
*/
|
|
27
|
+
export declare const NONDETERMINISTIC_PATTERNS: NondeterministicPattern[];
|
|
28
|
+
/**
|
|
29
|
+
* Nondeterministic object prefixes.
|
|
30
|
+
* Any property access on these is nondeterministic.
|
|
31
|
+
*/
|
|
32
|
+
export declare const NONDETERMINISTIC_OBJECTS: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Trace a node to all its possible literal values.
|
|
35
|
+
*
|
|
36
|
+
* Starting from the given node, follows ASSIGNED_FROM (and optionally
|
|
37
|
+
* DERIVES_FROM) edges backwards to find:
|
|
38
|
+
* - LITERAL nodes: concrete values
|
|
39
|
+
* - PARAMETER nodes: runtime inputs (unknown)
|
|
40
|
+
* - CALL nodes: function return values (unknown)
|
|
41
|
+
* - EXPRESSION nodes: checks for nondeterministic patterns
|
|
42
|
+
*
|
|
43
|
+
* @param backend - Graph backend for queries
|
|
44
|
+
* @param nodeId - Starting node ID
|
|
45
|
+
* @param options - Traversal options
|
|
46
|
+
* @returns Array of traced values with sources
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const values = await traceValues(backend, variableId);
|
|
50
|
+
* for (const v of values) {
|
|
51
|
+
* if (v.isUnknown) {
|
|
52
|
+
* console.log(`Unknown from ${v.source.file}:${v.source.line} (${v.reason})`);
|
|
53
|
+
* } else {
|
|
54
|
+
* console.log(`Value: ${v.value} from ${v.source.file}:${v.source.line}`);
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*/
|
|
58
|
+
export declare function traceValues(backend: TraceValuesGraphBackend, nodeId: string, options?: TraceValuesOptions): Promise<TracedValue[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Aggregate traced values into a simplified result.
|
|
61
|
+
* Useful for consumers who don't need source locations.
|
|
62
|
+
*
|
|
63
|
+
* Note: null and undefined values are NOT included in the values array.
|
|
64
|
+
* If you need to detect "assigned to null", check the raw TracedValue[] instead.
|
|
65
|
+
*
|
|
66
|
+
* @param traced - Array of traced values
|
|
67
|
+
* @returns Aggregated result with unique values and hasUnknown flag
|
|
68
|
+
*/
|
|
69
|
+
export declare function aggregateValues(traced: TracedValue[]): ValueSetResult;
|
|
70
|
+
//# sourceMappingURL=traceValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceValues.d.ts","sourceRoot":"","sources":["../../src/queries/traceValues.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,uBAAuB,EAExB,MAAM,YAAY,CAAC;AAMpB;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,uBAAuB,EAiB9D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAO5C,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,uBAAuB,EAChC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,EAAE,CAAC,CAoBxB;AAuPD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,CAgBrE"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value Tracing Utility (REG-244)
|
|
3
|
+
*
|
|
4
|
+
* Traces a node through ASSIGNED_FROM/DERIVES_FROM edges to find
|
|
5
|
+
* all possible literal values or mark as unknown.
|
|
6
|
+
*
|
|
7
|
+
* Graph structure:
|
|
8
|
+
* ```
|
|
9
|
+
* VARIABLE -[ASSIGNED_FROM]-> LITERAL (concrete value)
|
|
10
|
+
* VARIABLE -[ASSIGNED_FROM]-> PARAMETER (unknown: runtime input)
|
|
11
|
+
* VARIABLE -[ASSIGNED_FROM]-> CALL (unknown: function return)
|
|
12
|
+
* VARIABLE -[DERIVES_FROM]-> EXPRESSION (check nondeterministic patterns)
|
|
13
|
+
* VARIABLE -[ASSIGNED_FROM]-> VARIABLE (chain - recurse)
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Used by:
|
|
17
|
+
* - CLI trace command (sink-based tracing)
|
|
18
|
+
* - ValueDomainAnalyzer (computed member access resolution)
|
|
19
|
+
*
|
|
20
|
+
* @module queries/traceValues
|
|
21
|
+
*/
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// NONDETERMINISTIC PATTERNS (moved from ValueDomainAnalyzer)
|
|
24
|
+
// =============================================================================
|
|
25
|
+
/**
|
|
26
|
+
* Nondeterministic MemberExpression patterns.
|
|
27
|
+
* object.property combinations that represent external/user input.
|
|
28
|
+
*/
|
|
29
|
+
export const NONDETERMINISTIC_PATTERNS = [
|
|
30
|
+
// Environment variables
|
|
31
|
+
{ object: 'process', property: 'env' },
|
|
32
|
+
// HTTP request data (Express.js patterns)
|
|
33
|
+
{ object: 'req', property: 'body' },
|
|
34
|
+
{ object: 'req', property: 'query' },
|
|
35
|
+
{ object: 'req', property: 'params' },
|
|
36
|
+
{ object: 'req', property: 'headers' },
|
|
37
|
+
{ object: 'req', property: 'cookies' },
|
|
38
|
+
{ object: 'request', property: 'body' },
|
|
39
|
+
{ object: 'request', property: 'query' },
|
|
40
|
+
{ object: 'request', property: 'params' },
|
|
41
|
+
// Context patterns (Koa, etc.)
|
|
42
|
+
{ object: 'ctx', property: 'request' },
|
|
43
|
+
{ object: 'ctx', property: 'body' },
|
|
44
|
+
{ object: 'ctx', property: 'query' },
|
|
45
|
+
{ object: 'ctx', property: 'params' },
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* Nondeterministic object prefixes.
|
|
49
|
+
* Any property access on these is nondeterministic.
|
|
50
|
+
*/
|
|
51
|
+
export const NONDETERMINISTIC_OBJECTS = [
|
|
52
|
+
'process.env', // process.env.ANY_VAR
|
|
53
|
+
'req.body', // req.body.userId
|
|
54
|
+
'req.query', // req.query.filter
|
|
55
|
+
'req.params', // req.params.id
|
|
56
|
+
'request.body',
|
|
57
|
+
'ctx.request',
|
|
58
|
+
];
|
|
59
|
+
// =============================================================================
|
|
60
|
+
// MAIN FUNCTION
|
|
61
|
+
// =============================================================================
|
|
62
|
+
/**
|
|
63
|
+
* Trace a node to all its possible literal values.
|
|
64
|
+
*
|
|
65
|
+
* Starting from the given node, follows ASSIGNED_FROM (and optionally
|
|
66
|
+
* DERIVES_FROM) edges backwards to find:
|
|
67
|
+
* - LITERAL nodes: concrete values
|
|
68
|
+
* - PARAMETER nodes: runtime inputs (unknown)
|
|
69
|
+
* - CALL nodes: function return values (unknown)
|
|
70
|
+
* - EXPRESSION nodes: checks for nondeterministic patterns
|
|
71
|
+
*
|
|
72
|
+
* @param backend - Graph backend for queries
|
|
73
|
+
* @param nodeId - Starting node ID
|
|
74
|
+
* @param options - Traversal options
|
|
75
|
+
* @returns Array of traced values with sources
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* const values = await traceValues(backend, variableId);
|
|
79
|
+
* for (const v of values) {
|
|
80
|
+
* if (v.isUnknown) {
|
|
81
|
+
* console.log(`Unknown from ${v.source.file}:${v.source.line} (${v.reason})`);
|
|
82
|
+
* } else {
|
|
83
|
+
* console.log(`Value: ${v.value} from ${v.source.file}:${v.source.line}`);
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
*/
|
|
87
|
+
export async function traceValues(backend, nodeId, options) {
|
|
88
|
+
const results = [];
|
|
89
|
+
const visited = new Set();
|
|
90
|
+
const maxDepth = options?.maxDepth ?? 10;
|
|
91
|
+
const followDerivesFrom = options?.followDerivesFrom ?? true;
|
|
92
|
+
const detectNondeterministic = options?.detectNondeterministic ?? true;
|
|
93
|
+
await traceRecursive(backend, nodeId, visited, 0, maxDepth, followDerivesFrom, detectNondeterministic, results);
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Recursive tracing function
|
|
98
|
+
*/
|
|
99
|
+
async function traceRecursive(backend, nodeId, visited, depth, maxDepth, followDerivesFrom, detectNondeterministic, results) {
|
|
100
|
+
// Cycle protection
|
|
101
|
+
if (visited.has(nodeId)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
visited.add(nodeId);
|
|
105
|
+
// Get node
|
|
106
|
+
const node = await backend.getNode(nodeId);
|
|
107
|
+
if (!node) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const nodeType = node.type || node.nodeType;
|
|
111
|
+
const source = {
|
|
112
|
+
id: node.id,
|
|
113
|
+
file: node.file || '',
|
|
114
|
+
line: node.line || 0,
|
|
115
|
+
};
|
|
116
|
+
// Depth protection - check after getting node for source info
|
|
117
|
+
if (depth > maxDepth) {
|
|
118
|
+
results.push({
|
|
119
|
+
value: undefined,
|
|
120
|
+
source,
|
|
121
|
+
isUnknown: true,
|
|
122
|
+
reason: 'max_depth',
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// Terminal: LITERAL - found concrete value
|
|
127
|
+
if (nodeType === 'LITERAL') {
|
|
128
|
+
results.push({
|
|
129
|
+
value: node.value,
|
|
130
|
+
source,
|
|
131
|
+
isUnknown: false,
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// Terminal: PARAMETER - runtime input
|
|
136
|
+
if (nodeType === 'PARAMETER') {
|
|
137
|
+
results.push({
|
|
138
|
+
value: undefined,
|
|
139
|
+
source,
|
|
140
|
+
isUnknown: true,
|
|
141
|
+
reason: 'parameter',
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// Terminal: CALL / METHOD_CALL - function return value
|
|
146
|
+
if (nodeType === 'CALL' || nodeType === 'METHOD_CALL') {
|
|
147
|
+
// Check for HTTP_RECEIVES edges (cross-service data flow)
|
|
148
|
+
const httpEdges = await backend.getOutgoingEdges(nodeId, ['HTTP_RECEIVES']);
|
|
149
|
+
if (httpEdges.length > 0) {
|
|
150
|
+
// Follow HTTP boundary to backend response
|
|
151
|
+
for (const edge of httpEdges) {
|
|
152
|
+
await traceRecursive(backend, edge.dst, visited, depth + 1, maxDepth, followDerivesFrom, detectNondeterministic, results);
|
|
153
|
+
}
|
|
154
|
+
return; // Traced through HTTP boundary, don't mark as unknown
|
|
155
|
+
}
|
|
156
|
+
// Original behavior - mark as unknown
|
|
157
|
+
results.push({
|
|
158
|
+
value: undefined,
|
|
159
|
+
source,
|
|
160
|
+
isUnknown: true,
|
|
161
|
+
reason: 'call_result',
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// Check nondeterministic EXPRESSION patterns
|
|
166
|
+
if (nodeType === 'EXPRESSION' && detectNondeterministic) {
|
|
167
|
+
if (isNondeterministicExpression(node)) {
|
|
168
|
+
results.push({
|
|
169
|
+
value: undefined,
|
|
170
|
+
source,
|
|
171
|
+
isUnknown: true,
|
|
172
|
+
reason: 'nondeterministic',
|
|
173
|
+
});
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Terminal: OBJECT_LITERAL - a valid structured value
|
|
178
|
+
// OBJECT_LITERAL without edges is valid (e.g., {} or {key: value})
|
|
179
|
+
if (nodeType === 'OBJECT_LITERAL') {
|
|
180
|
+
results.push({
|
|
181
|
+
value: node.value,
|
|
182
|
+
source,
|
|
183
|
+
isUnknown: false,
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
// REG-334: Special case - CONSTRUCTOR_CALL for Promise
|
|
188
|
+
// Follow RESOLVES_TO edges to find actual data sources from resolve() calls
|
|
189
|
+
if (nodeType === 'CONSTRUCTOR_CALL') {
|
|
190
|
+
const className = node.className;
|
|
191
|
+
if (className === 'Promise') {
|
|
192
|
+
// Look for incoming RESOLVES_TO edges (resolve/reject calls)
|
|
193
|
+
const resolveEdges = await backend.getIncomingEdges(nodeId, ['RESOLVES_TO']);
|
|
194
|
+
if (resolveEdges.length > 0) {
|
|
195
|
+
// Follow resolve/reject calls to their arguments
|
|
196
|
+
for (const edge of resolveEdges) {
|
|
197
|
+
// edge.src is the resolve(value) CALL node
|
|
198
|
+
// We need to find what value was passed to resolve()
|
|
199
|
+
// The CALL node should have PASSES_ARGUMENT edge to the value
|
|
200
|
+
const argEdges = await backend.getOutgoingEdges(edge.src, ['PASSES_ARGUMENT']);
|
|
201
|
+
for (const argEdge of argEdges) {
|
|
202
|
+
// Check if this is the first argument (argIndex 0)
|
|
203
|
+
const argIndex = argEdge.metadata?.argIndex;
|
|
204
|
+
if (argIndex === 0) {
|
|
205
|
+
// Recursively trace the argument value
|
|
206
|
+
await traceRecursive(backend, argEdge.dst, visited, depth + 1, maxDepth, followDerivesFrom, detectNondeterministic, results);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return; // Traced through resolve, don't mark as unknown
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Non-Promise constructor or no resolve edges - mark as unknown
|
|
214
|
+
results.push({
|
|
215
|
+
value: undefined,
|
|
216
|
+
source,
|
|
217
|
+
isUnknown: true,
|
|
218
|
+
reason: 'constructor_call',
|
|
219
|
+
});
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// Get outgoing data flow edges
|
|
223
|
+
const edgeTypes = ['ASSIGNED_FROM'];
|
|
224
|
+
if (followDerivesFrom) {
|
|
225
|
+
edgeTypes.push('DERIVES_FROM');
|
|
226
|
+
}
|
|
227
|
+
const edges = await backend.getOutgoingEdges(nodeId, edgeTypes);
|
|
228
|
+
// No edges case - unknown
|
|
229
|
+
if (edges.length === 0) {
|
|
230
|
+
results.push({
|
|
231
|
+
value: undefined,
|
|
232
|
+
source,
|
|
233
|
+
isUnknown: true,
|
|
234
|
+
reason: 'no_sources',
|
|
235
|
+
});
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// Recurse through sources
|
|
239
|
+
for (const edge of edges) {
|
|
240
|
+
await traceRecursive(backend, edge.dst, visited, depth + 1, maxDepth, followDerivesFrom, detectNondeterministic, results);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// =============================================================================
|
|
244
|
+
// HELPERS
|
|
245
|
+
// =============================================================================
|
|
246
|
+
/**
|
|
247
|
+
* Check if an EXPRESSION node represents a nondeterministic pattern.
|
|
248
|
+
* E.g., process.env.VAR, req.body.userId, etc.
|
|
249
|
+
*/
|
|
250
|
+
function isNondeterministicExpression(node) {
|
|
251
|
+
if (node.expressionType !== 'MemberExpression') {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
const object = node.object;
|
|
255
|
+
const property = node.property;
|
|
256
|
+
if (!object || !property) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
// Check exact patterns (object.property)
|
|
260
|
+
for (const pattern of NONDETERMINISTIC_PATTERNS) {
|
|
261
|
+
if (object === pattern.object && property === pattern.property) {
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Check if object is a known nondeterministic prefix
|
|
266
|
+
// e.g., process.env.VAR where object is 'process.env'
|
|
267
|
+
for (const prefix of NONDETERMINISTIC_OBJECTS) {
|
|
268
|
+
if (object === prefix || object.startsWith(prefix + '.')) {
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Aggregate traced values into a simplified result.
|
|
276
|
+
* Useful for consumers who don't need source locations.
|
|
277
|
+
*
|
|
278
|
+
* Note: null and undefined values are NOT included in the values array.
|
|
279
|
+
* If you need to detect "assigned to null", check the raw TracedValue[] instead.
|
|
280
|
+
*
|
|
281
|
+
* @param traced - Array of traced values
|
|
282
|
+
* @returns Aggregated result with unique values and hasUnknown flag
|
|
283
|
+
*/
|
|
284
|
+
export function aggregateValues(traced) {
|
|
285
|
+
const valueSet = new Set();
|
|
286
|
+
let hasUnknown = false;
|
|
287
|
+
for (const t of traced) {
|
|
288
|
+
if (t.isUnknown) {
|
|
289
|
+
hasUnknown = true;
|
|
290
|
+
}
|
|
291
|
+
else if (t.value !== undefined && t.value !== null) {
|
|
292
|
+
valueSet.add(t.value);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
values: Array.from(valueSet),
|
|
297
|
+
hasUnknown,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Types for Graph Query Utilities
|
|
3
|
+
*
|
|
4
|
+
* These types are used by findCallsInFunction, findContainingFunction,
|
|
5
|
+
* and other query utilities.
|
|
6
|
+
*
|
|
7
|
+
* @module queries/types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Information about a function/method call found in code
|
|
11
|
+
*/
|
|
12
|
+
export interface CallInfo {
|
|
13
|
+
/** Node ID of the call site */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Called function/method name */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Node type: 'CALL' or 'METHOD_CALL' */
|
|
18
|
+
type: 'CALL' | 'METHOD_CALL';
|
|
19
|
+
/** Object name for method calls (e.g., 'response' for response.json()) */
|
|
20
|
+
object?: string;
|
|
21
|
+
/** Whether the call target was resolved (has CALLS edge) */
|
|
22
|
+
resolved: boolean;
|
|
23
|
+
/** Target function info if resolved */
|
|
24
|
+
target?: {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
file?: string;
|
|
28
|
+
line?: number;
|
|
29
|
+
};
|
|
30
|
+
/** File where call occurs */
|
|
31
|
+
file?: string;
|
|
32
|
+
/** Line number of call */
|
|
33
|
+
line?: number;
|
|
34
|
+
/** Depth in transitive call chain (0 = direct call) */
|
|
35
|
+
depth?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Information about a function that calls another function
|
|
39
|
+
*/
|
|
40
|
+
export interface CallerInfo {
|
|
41
|
+
/** Caller function ID */
|
|
42
|
+
id: string;
|
|
43
|
+
/** Caller function name */
|
|
44
|
+
name: string;
|
|
45
|
+
/** Caller function type (FUNCTION, CLASS, MODULE) */
|
|
46
|
+
type: string;
|
|
47
|
+
/** File containing the caller */
|
|
48
|
+
file?: string;
|
|
49
|
+
/** Line of the call site */
|
|
50
|
+
line?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for finding calls in a function
|
|
54
|
+
*/
|
|
55
|
+
export interface FindCallsOptions {
|
|
56
|
+
/** Maximum depth for scope traversal (default: 10) */
|
|
57
|
+
maxDepth?: number;
|
|
58
|
+
/** Follow transitive calls (default: false) */
|
|
59
|
+
transitive?: boolean;
|
|
60
|
+
/** Maximum depth for transitive traversal (default: 5) */
|
|
61
|
+
transitiveDepth?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Location of a value source in the graph
|
|
65
|
+
*/
|
|
66
|
+
export interface ValueSource {
|
|
67
|
+
/** Node ID in the graph */
|
|
68
|
+
id: string;
|
|
69
|
+
/** File path */
|
|
70
|
+
file: string;
|
|
71
|
+
/** Line number (1-based) */
|
|
72
|
+
line: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reason why a value could not be determined statically.
|
|
76
|
+
* Used for debugging and user-facing messages.
|
|
77
|
+
*/
|
|
78
|
+
export type UnknownReason = 'parameter' | 'call_result' | 'constructor_call' | 'nondeterministic' | 'max_depth' | 'no_sources';
|
|
79
|
+
/**
|
|
80
|
+
* A single traced value from the graph.
|
|
81
|
+
* Represents either a concrete value (from LITERAL) or an unknown value
|
|
82
|
+
* (from PARAMETER, CALL, nondeterministic source, etc.)
|
|
83
|
+
*/
|
|
84
|
+
export interface TracedValue {
|
|
85
|
+
/** The literal value (undefined if unknown) */
|
|
86
|
+
value: unknown;
|
|
87
|
+
/** Source location in the codebase */
|
|
88
|
+
source: ValueSource;
|
|
89
|
+
/** Whether value could not be determined statically */
|
|
90
|
+
isUnknown: boolean;
|
|
91
|
+
/** Why the value is unknown (for debugging/display) */
|
|
92
|
+
reason?: UnknownReason;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Options for traceValues()
|
|
96
|
+
*/
|
|
97
|
+
export interface TraceValuesOptions {
|
|
98
|
+
/** Maximum traversal depth (default: 10) */
|
|
99
|
+
maxDepth?: number;
|
|
100
|
+
/** Follow DERIVES_FROM edges in addition to ASSIGNED_FROM (default: true) */
|
|
101
|
+
followDerivesFrom?: boolean;
|
|
102
|
+
/** Detect nondeterministic patterns like process.env (default: true) */
|
|
103
|
+
detectNondeterministic?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Aggregated result from tracing.
|
|
107
|
+
* Convenience type for consumers who don't need individual sources.
|
|
108
|
+
*/
|
|
109
|
+
export interface ValueSetResult {
|
|
110
|
+
/** All unique concrete values found */
|
|
111
|
+
values: unknown[];
|
|
112
|
+
/** Whether any path led to unknown value */
|
|
113
|
+
hasUnknown: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Edge record for traceValues
|
|
117
|
+
*/
|
|
118
|
+
export interface TraceValuesEdge {
|
|
119
|
+
src: string;
|
|
120
|
+
dst: string;
|
|
121
|
+
type: string;
|
|
122
|
+
metadata?: {
|
|
123
|
+
argIndex?: number;
|
|
124
|
+
isReject?: boolean;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Node record for traceValues
|
|
129
|
+
*/
|
|
130
|
+
export interface TraceValuesNode {
|
|
131
|
+
id: string;
|
|
132
|
+
type?: string;
|
|
133
|
+
nodeType?: string;
|
|
134
|
+
value?: unknown;
|
|
135
|
+
file?: string;
|
|
136
|
+
line?: number;
|
|
137
|
+
expressionType?: string;
|
|
138
|
+
object?: string;
|
|
139
|
+
property?: string;
|
|
140
|
+
className?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Minimal graph backend interface for traceValues().
|
|
144
|
+
* Works with both RFDBServerBackend and internal Graph interface.
|
|
145
|
+
*/
|
|
146
|
+
export interface TraceValuesGraphBackend {
|
|
147
|
+
getNode(id: string): Promise<TraceValuesNode | null>;
|
|
148
|
+
getOutgoingEdges(nodeId: string, edgeTypes: string[] | null): Promise<TraceValuesEdge[]>;
|
|
149
|
+
/**
|
|
150
|
+
* Get incoming edges to a node (REG-334: needed for RESOLVES_TO)
|
|
151
|
+
* Required for Promise tracing - must be implemented by all backends
|
|
152
|
+
*/
|
|
153
|
+
getIncomingEdges(nodeId: string, edgeTypes: string[] | null): Promise<TraceValuesEdge[]>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Nondeterministic MemberExpression pattern.
|
|
157
|
+
* object.property combinations that represent external/user input.
|
|
158
|
+
*/
|
|
159
|
+
export interface NondeterministicPattern {
|
|
160
|
+
object: string;
|
|
161
|
+
property: string;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/queries/types.ts"],"names":[],"mappings":"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"}
|