UNPKG

code-relation-analyzer

Version:

A TypeScript project dependency analysis tool that generates function-level dependency graphs

204 lines 5.52 kB
/** * 依赖关系相关类型定义 */ export interface FileDependency { /** 依赖关系唯一标识符 */ id: string; /** 源文件ID */ sourceFileId: string; /** 目标文件ID */ targetFileId: string; /** 源文件路径 */ sourceFile: string; /** 目标文件路径 */ targetFile: string; /** 导入类型 */ importType: ImportType; /** 导入的符号 */ importedSymbols: string[]; /** 行号 */ lineNumber: number; /** 是否仅类型导入 */ isTypeOnly: boolean; /** 依赖强度 */ strength: DependencyStrength; } export type ImportType = 'default' | 'named' | 'namespace' | 'dynamic'; export type DependencyStrength = 'weak' | 'medium' | 'strong'; export interface InheritanceRelation { /** 继承关系唯一标识符 */ id: string; /** 子类ID */ childClassId: string; /** 父类ID */ parentClassId: string; /** 子类名称 */ childClass: string; /** 父类名称 */ parentClass: string; /** 关系类型 */ type: InheritanceType; /** 文件路径 */ filePath: string; /** 行号 */ lineNumber: number; /** 继承深度 */ depth: number; /** 继承的方法 */ methods?: string[]; } export type InheritanceType = 'extends' | 'implements'; export interface FunctionCall { /** 函数调用唯一标识符 */ id: string; /** 调用者函数ID */ callerFunctionId: string; /** 被调用函数ID */ calledFunctionId: string; /** 调用者函数名 */ callerFunction: string; /** 被调用函数名 */ calledFunction: string; /** 调用者文件 */ callerFile: string; /** 被调用文件 */ calledFile: string; /** 调用类型 */ callType: CallType; /** 参数列表 */ parameters: CallParameter[]; /** 行号 */ lineNumber: number; /** 调用次数 */ callCount: number; /** 是否递归调用 */ isRecursive: boolean; } export type CallType = 'direct' | 'method' | 'constructor' | 'callback'; export interface CallParameter { /** 参数名称 */ name: string; /** 参数类型 */ type: string; /** 参数值(如果是字面量) */ value?: string; /** 是否为变量引用 */ isReference: boolean; } export interface ParameterFlow { /** 参数流唯一标识符 */ id: string; /** 源组件 */ sourceComponent: string; /** 目标组件 */ targetComponent: string; /** 参数名称 */ parameterName: string; /** 参数类型 */ parameterType: string; /** 流类型 */ flowType: FlowType; /** 文件路径 */ filePath: string; /** 数据流方向 */ direction: FlowDirection; /** 转换函数 */ transformer?: string; } export type FlowType = 'props' | 'callback' | 'context' | 'store' | 'event'; export type FlowDirection = 'input' | 'output' | 'bidirectional'; export interface GlobalDependency { /** 全局依赖唯一标识符 */ id: string; /** 全局变量名 */ globalName: string; /** 使用该全局变量的文件 */ usageFiles: string[]; /** 定义该全局变量的文件 */ definitionFile?: string; /** 依赖类型 */ dependencyType: GlobalDependencyType; /** 使用次数 */ usageCount: number; /** 风险等级 */ riskLevel: RiskLevel; } export type GlobalDependencyType = 'global-variable' | 'global-function' | 'window-property' | 'environment-variable' | 'external-library'; export type RiskLevel = 'low' | 'medium' | 'high' | 'critical'; export interface DependencyGraph { /** 图唯一标识符 */ id: string; /** 图类型 */ type: GraphType; /** 节点列表 */ nodes: GraphNode[]; /** 边列表 */ edges: GraphEdge[]; /** 图的元数据 */ metadata: GraphMetadata; } export type GraphType = 'file-dependency' | 'inheritance' | 'function-call' | 'parameter-flow' | 'global-dependency'; export interface GraphNode { /** 节点ID */ id: string; /** 节点标签 */ label: string; /** 节点类型 */ type: NodeType; /** 节点属性 */ properties: Record<string, any>; /** 位置信息 */ position?: Position; /** 样式信息 */ style?: NodeStyle; } export type NodeType = 'file' | 'class' | 'function' | 'interface' | 'component' | 'module'; export interface Position { x: number; y: number; } export interface NodeStyle { color?: string; size?: number; shape?: string; opacity?: number; } export interface GraphEdge { /** 边ID */ id: string; /** 源节点ID */ source: string; /** 目标节点ID */ target: string; /** 边类型 */ type: EdgeType; /** 边权重 */ weight: number; /** 边属性 */ properties: Record<string, any>; /** 样式信息 */ style?: EdgeStyle; } export type EdgeType = 'import' | 'extends' | 'implements' | 'calls' | 'uses' | 'depends'; export interface EdgeStyle { color?: string; width?: number; style?: 'solid' | 'dashed' | 'dotted'; opacity?: number; arrow?: boolean; } export interface GraphMetadata { /** 创建时间 */ createdAt: Date; /** 节点数量 */ nodeCount: number; /** 边数量 */ edgeCount: number; /** 图的复杂度 */ complexity: number; /** 最大深度 */ maxDepth: number; /** 循环依赖数量 */ circularDependencies: number; } //# sourceMappingURL=dependency.d.ts.map