|
| 1 | +import * as ts from "typescript"; |
| 2 | +import { |
| 3 | + IClassInfo, |
| 4 | + ICodebaseMap, |
| 5 | + IEnumInfo, |
| 6 | + IFunctionInfo, |
| 7 | + IInterfaceInfo, |
| 8 | + IProperty, |
| 9 | + TNode, |
| 10 | +} from "./generic.interface"; |
| 11 | +import { Result } from "../result"; |
| 12 | + |
| 13 | +export interface ITypeScriptCodeMapper { |
| 14 | + /** |
| 15 | + * Extracts information about a TypeScript class declaration. |
| 16 | + * |
| 17 | + * @param node The TypeScript class declaration to extract information from. |
| 18 | + * @param sourceFile The source file containing the class declaration. |
| 19 | + * @returns An IClassInfo object containing the name, methods, properties, interfaces, and enums of the class. |
| 20 | + */ |
| 21 | + extractClassMetaData( |
| 22 | + node: ts.ClassDeclaration, |
| 23 | + sourceFile: ts.SourceFile |
| 24 | + ): Result<IClassInfo>; |
| 25 | + |
| 26 | + /** |
| 27 | + * Extracts property information from a TypeScript property declaration. |
| 28 | + * |
| 29 | + * @param node A property declaration node. |
| 30 | + * @param sourceFile The source file containing the node. |
| 31 | + * @returns An object with 'name' and 'type' properties. |
| 32 | + */ |
| 33 | + extractPropertyParameters( |
| 34 | + node: ts.PropertyDeclaration, |
| 35 | + sourceFile: ts.SourceFile |
| 36 | + ): Result<IProperty>; |
| 37 | + |
| 38 | + /** |
| 39 | + * Extracts the parameters of a function from a given node. |
| 40 | + * |
| 41 | + * @param node The node containing the function parameters. |
| 42 | + * @param sourceFile The source file containing the node. |
| 43 | + * @returns An array of function parameter objects. |
| 44 | + */ |
| 45 | + extractFunctionParameters( |
| 46 | + node: ts.FunctionDeclaration | ts.MethodDeclaration, |
| 47 | + sourceFile: ts.SourceFile |
| 48 | + ): Result<IProperty[]>; |
| 49 | + |
| 50 | + /** |
| 51 | + * Retrieves and returns function details from a given function declaration or method declaration node. |
| 52 | + * |
| 53 | + * @param node The function declaration or method declaration node to extract details from. |
| 54 | + * @param sourceFile The source file containing the node. |
| 55 | + * @returns An object containing function details, or null if the node has no name. |
| 56 | + */ |
| 57 | + getFunctionDetails( |
| 58 | + node: ts.FunctionDeclaration | ts.MethodDeclaration, |
| 59 | + sourceFile: ts.SourceFile |
| 60 | + ): Result<IFunctionInfo> | null; |
| 61 | + |
| 62 | + /** |
| 63 | + * Retrieves the type of a given function or method declaration. |
| 64 | + * |
| 65 | + * @param node A function or method declaration node. |
| 66 | + * @returns A string representation of the function or method type, or undefined if type checking is unavailable. |
| 67 | + */ |
| 68 | + getTypeAtLocation( |
| 69 | + node: |
| 70 | + | ts.FunctionDeclaration |
| 71 | + | ts.MethodDeclaration |
| 72 | + | ts.ParameterDeclaration |
| 73 | + | ts.PropertyDeclaration |
| 74 | + | ts.PropertySignature |
| 75 | + ): Result<string | undefined>; |
| 76 | + |
| 77 | + /** |
| 78 | + * Retrieves and concatenates JSDoc comments associated with a given TypeScript node. |
| 79 | + * |
| 80 | + * @param node The TypeScript node to extract comments from. |
| 81 | + * @returns Concatenated JSDoc comments. |
| 82 | + */ |
| 83 | + getComment(node: TNode): string; |
| 84 | + |
| 85 | + /** |
| 86 | + * Generates a string representation of a given function or method declaration node. |
| 87 | + * This method leverages the TypeScript printer to produce a source code string, |
| 88 | + * removing any comments and using line feed as the new line character. |
| 89 | + * |
| 90 | + * @param node The function or method declaration node to be printed. |
| 91 | + * @param sourceFile The source file that contains the node to be printed. |
| 92 | + * @returns A string representation of the given node. |
| 93 | + */ |
| 94 | + getPrintedNode( |
| 95 | + node: ts.FunctionDeclaration | ts.MethodDeclaration, |
| 96 | + sourceFile: ts.SourceFile |
| 97 | + ): string; |
| 98 | + |
| 99 | + /** |
| 100 | + * Finds the root directory of a project by searching for a 'package.json' file |
| 101 | + * starting from the given current directory and traversing up the directory tree. |
| 102 | + * |
| 103 | + * @param currentDir The directory to start searching from. |
| 104 | + * @returns The root directory of the project, or the current working directory if no 'package.json' file is found. |
| 105 | + */ |
| 106 | + findProjectRoot(currentDir: string): string; |
| 107 | + |
| 108 | + /** |
| 109 | + * Retrieves a list of TypeScript files, excluding test and mock files. |
| 110 | + * @returns A promise that resolves with a list of TypeScript files. |
| 111 | + */ |
| 112 | + getTsFiles(): Promise<string[]>; |
| 113 | + |
| 114 | + /** |
| 115 | + * Builds a hierarchical map of the codebase by traversing TypeScript files |
| 116 | + * and extracting module and class information. |
| 117 | + */ |
| 118 | + buildCodebaseMap(): Promise<Result<ICodebaseMap>>; |
| 119 | + |
| 120 | + /** |
| 121 | + * Extracts interface information from a TypeScript interface declaration. |
| 122 | + * |
| 123 | + * @param node The interface declaration node to extract information from. |
| 124 | + * @param sourceFile The source file containing the interface declaration. |
| 125 | + * @returns An IInterfaceInfo object containing the name, properties, and summary of the interface. |
| 126 | + */ |
| 127 | + extractInterfaceInfo( |
| 128 | + node: ts.InterfaceDeclaration, |
| 129 | + sourceFile: ts.SourceFile |
| 130 | + ): Result<IInterfaceInfo>; |
| 131 | + |
| 132 | + /** |
| 133 | + * Extracts enum information from a TypeScript enum declaration. |
| 134 | + * |
| 135 | + * @param node The enum declaration node to extract information from. |
| 136 | + * @param sourceFile The source file containing the enum declaration. |
| 137 | + * @returns An IEnumInfo object containing the name, members, and summary of the enum. |
| 138 | + */ |
| 139 | + extractEnumInfo( |
| 140 | + node: ts.EnumDeclaration, |
| 141 | + sourceFile: ts.SourceFile |
| 142 | + ): Result<IEnumInfo>; |
| 143 | + |
| 144 | + /** |
| 145 | + * Builds a dependency graph for a TypeScript source file. |
| 146 | + * |
| 147 | + * @param sourceFile The TypeScript source file to build the dependency graph for. |
| 148 | + * @returns An array of dependencies for the source file. |
| 149 | + */ |
| 150 | + buildDependencyGraph(sourceFile: ts.SourceFile): string[]; |
| 151 | +} |
0 commit comments