codesearch-mcp 0.2.3-alpha → 0.4.0-alpha
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/CHANGELOG.md +88 -5
- package/LICENSE +661 -21
- package/README.md +76 -40
- package/dist/app.js +17 -38
- package/dist/src/ast/CallExtractor.d.ts +8 -0
- package/dist/src/ast/CallExtractor.js +68 -0
- package/dist/src/ast/GraphqlNameExtractor.d.ts +22 -0
- package/dist/src/ast/GraphqlNameExtractor.js +240 -0
- package/dist/src/ast/ImportEdgeExtractor.d.ts +11 -0
- package/dist/src/ast/ImportEdgeExtractor.js +129 -0
- package/dist/src/ast/IndexedNodeResolver.d.ts +14 -0
- package/dist/src/ast/IndexedNodeResolver.js +217 -0
- package/dist/src/ast/MemberExtractor.d.ts +8 -0
- package/dist/src/ast/MemberExtractor.js +129 -0
- package/dist/src/ast/TopLevelSymbolExtractor.d.ts +5 -0
- package/dist/src/ast/TopLevelSymbolExtractor.js +86 -0
- package/dist/src/ast/graphql-grammar.d.ts +24 -0
- package/dist/src/ast/graphql-grammar.js +93 -0
- package/dist/src/ast/node-helpers.d.ts +11 -0
- package/dist/src/ast/node-helpers.js +55 -0
- package/dist/src/chunking/AstChunker.d.ts +12 -0
- package/dist/src/chunking/AstChunker.js +30 -0
- package/dist/src/chunking/CharacterChunkStrategy.d.ts +8 -0
- package/dist/src/chunking/CharacterChunkStrategy.js +15 -0
- package/dist/src/chunking/DeclarationChunkStrategy.d.ts +15 -0
- package/dist/src/chunking/DeclarationChunkStrategy.js +87 -0
- package/dist/src/chunking/FragmentMerger.d.ts +11 -0
- package/dist/src/chunking/FragmentMerger.js +61 -0
- package/dist/src/chunking/ImportOnlyFilter.d.ts +5 -0
- package/dist/src/chunking/ImportOnlyFilter.js +14 -0
- package/dist/src/chunking/LangchainTextSplitter.d.ts +21 -0
- package/dist/src/chunking/LangchainTextSplitter.js +133 -0
- package/dist/src/chunking/MinSizeSplitPolicy.d.ts +9 -0
- package/dist/src/chunking/MinSizeSplitPolicy.js +18 -0
- package/dist/src/chunking/RunPacker.d.ts +12 -0
- package/dist/src/chunking/RunPacker.js +84 -0
- package/dist/src/chunking/create-chunker.d.ts +3 -0
- package/dist/src/chunking/create-chunker.js +15 -0
- package/dist/src/chunking/interfaces.d.ts +27 -0
- package/dist/src/commands/ConfigCommand.js +1 -9
- package/dist/src/commands/EvalCommand.d.ts +10 -5
- package/dist/src/commands/EvalCommand.js +60 -149
- package/dist/src/commands/IndexCommand.d.ts +10 -4
- package/dist/src/commands/IndexCommand.js +52 -146
- package/dist/src/commands/McpCommand.d.ts +6 -3
- package/dist/src/commands/McpCommand.js +19 -20
- package/dist/src/commands/WebCommand.d.ts +9 -3
- package/dist/src/commands/WebCommand.js +17 -11
- package/dist/src/commands/eval/baseline-comparison.d.ts +6 -0
- package/dist/src/commands/eval/baseline-comparison.js +54 -0
- package/dist/src/commands/eval/eval-args.d.ts +6 -0
- package/dist/src/commands/eval/eval-args.js +71 -0
- package/dist/src/commands/eval/eval-corpora.d.ts +6 -0
- package/dist/src/commands/eval/eval-corpora.js +76 -0
- package/dist/src/commands/eval/eval-metadata.d.ts +17 -0
- package/dist/src/commands/eval/eval-metadata.js +75 -0
- package/dist/src/commands/eval/index-inspector.d.ts +3 -0
- package/dist/src/commands/eval/index-inspector.js +21 -0
- package/dist/src/commands/eval/staged-search.d.ts +3 -0
- package/dist/src/commands/eval/staged-search.js +20 -0
- package/dist/src/commands/eval/suite-loader.d.ts +8 -0
- package/dist/src/commands/eval/suite-loader.js +52 -0
- package/dist/src/commands/index/backend-probe.d.ts +2 -0
- package/dist/src/commands/index/backend-probe.js +15 -0
- package/dist/src/commands/index/embedding-setup.d.ts +3 -0
- package/dist/src/commands/index/embedding-setup.js +16 -0
- package/dist/src/commands/index/index-summary.d.ts +2 -0
- package/dist/src/commands/index/index-summary.js +22 -0
- package/dist/src/commands/index/legacy-ollama-guard.d.ts +3 -0
- package/dist/src/commands/index/legacy-ollama-guard.js +23 -0
- package/dist/src/commands/index/prune-step.d.ts +3 -0
- package/dist/src/commands/index/prune-step.js +22 -0
- package/dist/src/commands/index/scan-targets.d.ts +8 -0
- package/dist/src/commands/index/scan-targets.js +107 -0
- package/dist/src/config-error.d.ts +0 -4
- package/dist/src/config-error.js +0 -4
- package/dist/src/config-store.d.ts +1 -55
- package/dist/src/config-store.js +11 -73
- package/dist/src/config.d.ts +9 -18
- package/dist/src/config.js +36 -35
- package/dist/src/constants.d.ts +17 -28
- package/dist/src/constants.js +35 -29
- package/dist/src/container.d.ts +10 -2
- package/dist/src/container.js +19 -8
- package/dist/src/db/drizzle-types.d.ts +7 -0
- package/dist/src/db/drizzle-types.js +2 -0
- package/dist/src/db/index.d.ts +1 -0
- package/dist/src/db/schema-steps.d.ts +8 -0
- package/dist/src/db/schema-steps.js +105 -0
- package/dist/src/db/schema.d.ts +17 -0
- package/dist/src/db/schema.js +1 -6
- package/dist/src/declarations/DeclarationTree.d.ts +19 -0
- package/dist/src/declarations/DeclarationTree.js +66 -0
- package/dist/src/declarations/DeclarationTreeBuilder.d.ts +22 -0
- package/dist/src/declarations/DeclarationTreeBuilder.js +179 -0
- package/dist/src/declarations/SourceLines.d.ts +37 -0
- package/dist/src/declarations/SourceLines.js +415 -0
- package/dist/src/dependency-traversal.d.ts +0 -6
- package/dist/src/dependency-traversal.js +0 -6
- package/dist/src/enriched-prompt.d.ts +0 -6
- package/dist/src/enriched-prompt.js +0 -6
- package/dist/src/error-record.d.ts +12 -0
- package/dist/src/error-record.js +248 -0
- package/dist/src/eval-corpus.d.ts +16 -0
- package/dist/src/eval-corpus.js +169 -0
- package/dist/src/eval-results.d.ts +6 -3
- package/dist/src/eval-results.js +323 -26
- package/dist/src/eval-vector-index.d.ts +5 -0
- package/dist/src/eval-vector-index.js +60 -0
- package/dist/src/file-utils.d.ts +0 -5
- package/dist/src/file-utils.js +0 -5
- package/dist/src/graph.d.ts +0 -25
- package/dist/src/graph.js +0 -28
- package/dist/src/help.js +9 -1
- package/dist/src/hnsw-settings.d.ts +3 -0
- package/dist/src/hnsw-settings.js +24 -0
- package/dist/src/index-args.d.ts +13 -0
- package/dist/src/index-args.js +48 -0
- package/dist/src/indexing/AnalysisBatcher.d.ts +12 -0
- package/dist/src/indexing/AnalysisBatcher.js +28 -0
- package/dist/src/indexing/ChunkEmbedder.d.ts +24 -0
- package/dist/src/indexing/ChunkEmbedder.js +37 -0
- package/dist/src/indexing/ConsoleScanReporter.d.ts +10 -0
- package/dist/src/indexing/ConsoleScanReporter.js +73 -0
- package/dist/src/indexing/EmbeddingSchemaPreparer.d.ts +14 -0
- package/dist/src/indexing/EmbeddingSchemaPreparer.js +66 -0
- package/dist/src/indexing/FileIngestor.d.ts +22 -0
- package/dist/src/indexing/FileIngestor.js +116 -0
- package/dist/src/indexing/IndexStore.d.ts +24 -0
- package/dist/src/indexing/IndexStore.js +69 -0
- package/dist/src/indexing/StaleFilePruner.d.ts +8 -0
- package/dist/src/indexing/StaleFilePruner.js +55 -0
- package/dist/src/indexing/analysis-rows.d.ts +4 -0
- package/dist/src/indexing/analysis-rows.js +65 -0
- package/dist/src/indexing/project-notices.d.ts +2 -0
- package/dist/src/indexing/project-notices.js +63 -0
- package/dist/src/interfaces/IAstParser.d.ts +4 -40
- package/dist/src/interfaces/ICallGraph.d.ts +28 -0
- package/dist/src/interfaces/ICallGraph.js +2 -0
- package/dist/src/interfaces/IChunkSearch.d.ts +42 -0
- package/dist/src/interfaces/IChunkSearch.js +2 -0
- package/dist/src/interfaces/IChunker.d.ts +3 -12
- package/dist/src/interfaces/ICorpusInspector.d.ts +7 -0
- package/dist/src/interfaces/ICorpusInspector.js +2 -0
- package/dist/src/interfaces/IDatabase.d.ts +8 -24
- package/dist/src/interfaces/IDependencyGraph.d.ts +24 -0
- package/dist/src/interfaces/IDependencyGraph.js +2 -0
- package/dist/src/interfaces/IEmbedder.d.ts +0 -9
- package/dist/src/interfaces/IIndexIdentityGuard.d.ts +3 -0
- package/dist/src/interfaces/IIndexIdentityGuard.js +2 -0
- package/dist/src/interfaces/IIndexedNodeResolver.d.ts +10 -0
- package/dist/src/interfaces/IIndexedNodeResolver.js +2 -0
- package/dist/src/interfaces/ILogger.d.ts +1 -11
- package/dist/src/interfaces/IMcpReadiness.d.ts +12 -0
- package/dist/src/interfaces/IMcpReadiness.js +2 -0
- package/dist/src/interfaces/IMcpToolHandler.d.ts +0 -5
- package/dist/src/interfaces/IMonorepoResolver.d.ts +0 -22
- package/dist/src/interfaces/IProjectCatalog.d.ts +13 -0
- package/dist/src/interfaces/IProjectCatalog.js +2 -0
- package/dist/src/interfaces/IProjectDiscovery.d.ts +0 -17
- package/dist/src/interfaces/IProjectRoots.d.ts +3 -0
- package/dist/src/interfaces/IProjectRoots.js +2 -0
- package/dist/src/interfaces/IRetrievalEvaluator.d.ts +153 -12
- package/dist/src/interfaces/IScanReporter.d.ts +13 -0
- package/dist/src/interfaces/IScanReporter.js +2 -0
- package/dist/src/interfaces/ISymbolLookup.d.ts +49 -0
- package/dist/src/interfaces/ISymbolLookup.js +2 -0
- package/dist/src/interfaces/IToolPaths.d.ts +62 -0
- package/dist/src/interfaces/IToolPaths.js +2 -0
- package/dist/src/interfaces/IWorkspaceFiles.d.ts +28 -0
- package/dist/src/interfaces/IWorkspaceFiles.js +2 -0
- package/dist/src/interfaces/SymbolKind.d.ts +1 -0
- package/dist/src/interfaces/SymbolKind.js +2 -0
- package/dist/src/interfaces/index.d.ts +12 -1
- package/dist/src/interrupt.js +0 -2
- package/dist/src/owner-path.d.ts +9 -10
- package/dist/src/owner-path.js +11 -23
- package/dist/src/project-scope.d.ts +1 -12
- package/dist/src/project-scope.js +5 -12
- package/dist/src/project-selector.d.ts +0 -5
- package/dist/src/project-selector.js +0 -11
- package/dist/src/retrieval-eval.d.ts +15 -6
- package/dist/src/retrieval-eval.js +388 -59
- package/dist/src/search/CallGraph.d.ts +9 -0
- package/dist/src/search/CallGraph.js +84 -0
- package/dist/src/search/ChunkSearch.d.ts +23 -0
- package/dist/src/search/ChunkSearch.js +115 -0
- package/dist/src/search/DependencyGraph.d.ts +19 -0
- package/dist/src/search/DependencyGraph.js +180 -0
- package/dist/src/search/IndexIdentityGuard.d.ts +11 -0
- package/dist/src/search/IndexIdentityGuard.js +37 -0
- package/dist/src/search/ProjectCatalog.d.ts +11 -0
- package/dist/src/search/ProjectCatalog.js +38 -0
- package/dist/src/search/SymbolLookup.d.ts +24 -0
- package/dist/src/search/SymbolLookup.js +97 -0
- package/dist/src/search/chunks/CandidateFetcher.d.ts +19 -0
- package/dist/src/search/chunks/CandidateFetcher.js +40 -0
- package/dist/src/search/chunks/IterativeScanGate.d.ts +10 -0
- package/dist/src/search/chunks/IterativeScanGate.js +42 -0
- package/dist/src/search/chunks/RerankStage.d.ts +15 -0
- package/dist/src/search/chunks/RerankStage.js +42 -0
- package/dist/src/search/chunks/search-metrics.d.ts +18 -0
- package/dist/src/search/chunks/search-metrics.js +32 -0
- package/dist/src/search/chunks/search-plan.d.ts +18 -0
- package/dist/src/search/chunks/search-plan.js +19 -0
- package/dist/src/search/create-search-services.d.ts +26 -0
- package/dist/src/search/create-search-services.js +29 -0
- package/dist/src/search/index-paths.d.ts +1 -0
- package/dist/src/search/index-paths.js +5 -0
- package/dist/src/search/result-shaping.d.ts +4 -0
- package/dist/src/search/result-shaping.js +19 -0
- package/dist/src/search/symbol-sql.d.ts +13 -0
- package/dist/src/search/symbol-sql.js +66 -0
- package/dist/src/search/symbols/SymbolGrepFallback.d.ts +19 -0
- package/dist/src/search/symbols/SymbolGrepFallback.js +106 -0
- package/dist/src/search/symbols/SymbolIndexQuery.d.ts +14 -0
- package/dist/src/search/symbols/SymbolIndexQuery.js +52 -0
- package/dist/src/search/symbols/SymbolTextSearch.d.ts +13 -0
- package/dist/src/search/symbols/SymbolTextSearch.js +84 -0
- package/dist/src/search/symbols/TargetColumnGate.d.ts +7 -0
- package/dist/src/search/symbols/TargetColumnGate.js +23 -0
- package/dist/src/search/symbols/find-symbol-constants.d.ts +4 -0
- package/dist/src/search/symbols/find-symbol-constants.js +8 -0
- package/dist/src/search/symbols/grep-args.d.ts +3 -0
- package/dist/src/search/symbols/grep-args.js +7 -0
- package/dist/src/search/symbols/grep-patterns.d.ts +4 -0
- package/dist/src/search/symbols/grep-patterns.js +60 -0
- package/dist/src/services/AstParserService.d.ts +10 -106
- package/dist/src/services/AstParserService.js +37 -1068
- package/dist/src/services/DatabaseService.d.ts +10 -17
- package/dist/src/services/DatabaseService.js +71 -115
- package/dist/src/services/EmbedderFactory.d.ts +0 -4
- package/dist/src/services/EmbedderFactory.js +0 -5
- package/dist/src/services/IndexerService.d.ts +7 -26
- package/dist/src/services/IndexerService.js +38 -286
- package/dist/src/services/InfinityEmbedder.d.ts +0 -21
- package/dist/src/services/InfinityEmbedder.js +0 -15
- package/dist/src/services/LoggerService.d.ts +7 -5
- package/dist/src/services/LoggerService.js +37 -41
- package/dist/src/services/McpReadiness.d.ts +18 -0
- package/dist/src/services/McpReadiness.js +73 -0
- package/dist/src/services/McpServer.d.ts +50 -19
- package/dist/src/services/McpServer.js +132 -62
- package/dist/src/services/MonorepoAwareDiscoveryService.d.ts +1 -45
- package/dist/src/services/MonorepoAwareDiscoveryService.js +1 -51
- package/dist/src/services/NxMonorepoResolver.d.ts +0 -29
- package/dist/src/services/NxMonorepoResolver.js +5 -56
- package/dist/src/services/OpenAICompatibleEmbedder.d.ts +0 -6
- package/dist/src/services/OpenAICompatibleEmbedder.js +0 -14
- package/dist/src/services/ProjectDiscoveryService.d.ts +0 -4
- package/dist/src/services/ProjectDiscoveryService.js +0 -4
- package/dist/src/services/VoyageEmbedder.d.ts +0 -6
- package/dist/src/services/VoyageEmbedder.js +0 -6
- package/dist/src/services/WebServerService.d.ts +5 -56
- package/dist/src/services/WebServerService.js +25 -63
- package/dist/src/services/http-retry.d.ts +0 -7
- package/dist/src/services/http-retry.js +1 -10
- package/dist/src/services/infinity-provisioning.d.ts +0 -74
- package/dist/src/services/infinity-provisioning.js +5 -88
- package/dist/src/services/legacy-ollama-index.d.ts +0 -16
- package/dist/src/services/legacy-ollama-index.js +0 -23
- package/dist/src/services/reranker.d.ts +0 -9
- package/dist/src/services/reranker.js +46 -12
- package/dist/src/setup.d.ts +24 -24
- package/dist/src/setup.js +205 -103
- package/dist/src/symbol-name.d.ts +1 -12
- package/dist/src/symbol-name.js +16 -25
- package/dist/src/symbol-rows.d.ts +0 -14
- package/dist/src/symbol-rows.js +0 -14
- package/dist/src/tool-call-log.d.ts +2 -0
- package/dist/src/tool-call-log.js +24 -0
- package/dist/src/tools/FindSymbolTool.d.ts +17 -7
- package/dist/src/tools/FindSymbolTool.js +54 -35
- package/dist/src/tools/GetCallersTool.d.ts +16 -8
- package/dist/src/tools/GetCallersTool.js +65 -35
- package/dist/src/tools/GetDependenciesTool.d.ts +16 -8
- package/dist/src/tools/GetDependenciesTool.js +36 -29
- package/dist/src/tools/GetDependentsTool.d.ts +20 -8
- package/dist/src/tools/GetDependentsTool.js +48 -34
- package/dist/src/tools/ListFilesTool.d.ts +16 -8
- package/dist/src/tools/ListFilesTool.js +20 -26
- package/dist/src/tools/ListProjectsTool.d.ts +11 -7
- package/dist/src/tools/ListProjectsTool.js +13 -11
- package/dist/src/tools/McpTool.d.ts +17 -0
- package/dist/src/tools/McpTool.js +28 -0
- package/dist/src/tools/ReadFileRangeTool.d.ts +16 -8
- package/dist/src/tools/ReadFileRangeTool.js +23 -25
- package/dist/src/tools/ReadFileTool.d.ts +15 -8
- package/dist/src/tools/ReadFileTool.js +19 -24
- package/dist/src/tools/SearchCodebaseTool.d.ts +22 -10
- package/dist/src/tools/SearchCodebaseTool.js +71 -50
- package/dist/src/tools/format-helpers.d.ts +9 -9
- package/dist/src/tools/format-helpers.js +146 -28
- package/dist/src/tools/tool-args.d.ts +38 -0
- package/dist/src/tools/tool-args.js +95 -0
- package/dist/src/web/dashboard.d.ts +0 -8
- package/dist/src/web/dashboard.js +7 -10
- package/dist/src/workspace/GrepRunner.d.ts +15 -0
- package/dist/src/workspace/GrepRunner.js +104 -0
- package/dist/src/workspace/ProjectRoots.d.ts +22 -0
- package/dist/src/workspace/ProjectRoots.js +102 -0
- package/dist/src/workspace/ToolPaths.d.ts +31 -0
- package/dist/src/workspace/ToolPaths.js +312 -0
- package/dist/src/workspace/WorkspaceFiles.d.ts +19 -0
- package/dist/src/workspace/WorkspaceFiles.js +285 -0
- package/dist/src/workspace/fs-access.d.ts +9 -0
- package/dist/src/workspace/fs-access.js +47 -0
- package/dist/src/workspace/path-helpers.d.ts +3 -0
- package/dist/src/workspace/path-helpers.js +43 -0
- package/package.json +5 -4
- package/dist/src/interfaces/ISearcher.d.ts +0 -35
- package/dist/src/services/AstChunker.d.ts +0 -42
- package/dist/src/services/AstChunker.js +0 -158
- package/dist/src/services/SearcherService.d.ts +0 -342
- package/dist/src/services/SearcherService.js +0 -1199
- package/docs/web-dashboard.md +0 -206
- /package/dist/src/{interfaces/ISearcher.js → chunking/interfaces.js} +0 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphqlNameExtractor = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const node_helpers_1 = require("./node-helpers");
|
|
6
|
+
const graphql_grammar_1 = require("./graphql-grammar");
|
|
7
|
+
class GraphqlNameExtractor {
|
|
8
|
+
resolver;
|
|
9
|
+
logger;
|
|
10
|
+
resolveDeclaration;
|
|
11
|
+
constructor(resolver, logger, resolveDeclaration = node_helpers_1.defaultResolveDeclaration) {
|
|
12
|
+
this.resolver = resolver;
|
|
13
|
+
this.logger = logger;
|
|
14
|
+
this.resolveDeclaration = resolveDeclaration;
|
|
15
|
+
}
|
|
16
|
+
buildGraphqlImportMap(sourceFile) {
|
|
17
|
+
const map = new Map();
|
|
18
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
19
|
+
if (decl.getModuleSpecifierValue() !== graphql_grammar_1.GRAPHQL_MODULE)
|
|
20
|
+
continue;
|
|
21
|
+
for (const named of decl.getNamedImports()) {
|
|
22
|
+
const exportedName = named.getName();
|
|
23
|
+
const localName = named.getAliasNode()?.getText() ?? exportedName;
|
|
24
|
+
map.set(localName, exportedName);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return map;
|
|
28
|
+
}
|
|
29
|
+
recognizedDecorator(dec, importMap) {
|
|
30
|
+
const idNode = (0, graphql_grammar_1.decoratorIdentifier)(dec);
|
|
31
|
+
if (!idNode)
|
|
32
|
+
return null;
|
|
33
|
+
const exported = importMap.get(idNode.getText());
|
|
34
|
+
if (!exported)
|
|
35
|
+
return null;
|
|
36
|
+
const expr = dec.getExpression();
|
|
37
|
+
const args = ts_morph_1.Node.isCallExpression(expr) ? expr.getArguments() : [];
|
|
38
|
+
return { name: exported, args };
|
|
39
|
+
}
|
|
40
|
+
deriveGraphqlName(args, allowOptionsName, fallbackName) {
|
|
41
|
+
if (args.length > 0) {
|
|
42
|
+
const first = args[0];
|
|
43
|
+
const { inner, wrapped } = (0, graphql_grammar_1.peekThroughWrapper)(first);
|
|
44
|
+
const literal = (0, graphql_grammar_1.literalStringValue)(inner);
|
|
45
|
+
if (literal !== null) {
|
|
46
|
+
if (wrapped)
|
|
47
|
+
return { ok: false, reason: 'non-literal-name' };
|
|
48
|
+
return (0, graphql_grammar_1.checkGraphqlGrammar)(literal);
|
|
49
|
+
}
|
|
50
|
+
const isTypeFnOrOptions = ts_morph_1.Node.isArrowFunction(inner) || ts_morph_1.Node.isFunctionExpression(inner) || ts_morph_1.Node.isObjectLiteralExpression(inner);
|
|
51
|
+
if (!isTypeFnOrOptions)
|
|
52
|
+
return { ok: false, reason: 'non-literal-name' };
|
|
53
|
+
}
|
|
54
|
+
if (allowOptionsName) {
|
|
55
|
+
for (const arg of args) {
|
|
56
|
+
const { inner, wrapped } = (0, graphql_grammar_1.peekThroughWrapper)(arg);
|
|
57
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(inner))
|
|
58
|
+
continue;
|
|
59
|
+
if (wrapped)
|
|
60
|
+
return { ok: false, reason: 'non-literal-name' };
|
|
61
|
+
const nameProp = (0, graphql_grammar_1.findNameProperty)(inner);
|
|
62
|
+
if (!nameProp)
|
|
63
|
+
continue;
|
|
64
|
+
if (ts_morph_1.Node.isShorthandPropertyAssignment(nameProp))
|
|
65
|
+
return { ok: false, reason: 'non-literal-name' };
|
|
66
|
+
const init = nameProp.getInitializer();
|
|
67
|
+
const value = init ? (0, graphql_grammar_1.literalStringValue)(init) : null;
|
|
68
|
+
if (value !== null)
|
|
69
|
+
return (0, graphql_grammar_1.checkGraphqlGrammar)(value);
|
|
70
|
+
return { ok: false, reason: 'non-literal-name' };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return (0, graphql_grammar_1.checkGraphqlGrammar)(fallbackName);
|
|
74
|
+
}
|
|
75
|
+
logGraphqlSkip(filePath, declaration, decorator, reason, value) {
|
|
76
|
+
const fields = { filePath, declaration, decorator, reason };
|
|
77
|
+
if (value !== undefined)
|
|
78
|
+
fields.value = value;
|
|
79
|
+
this.logger.debug('AstParser: graphql row skipped', fields);
|
|
80
|
+
}
|
|
81
|
+
declarationNameFor(node, fallback) {
|
|
82
|
+
const described = this.resolver.describeIndexedNode(node);
|
|
83
|
+
return described ? this.resolver.qualifiedName(described) : fallback;
|
|
84
|
+
}
|
|
85
|
+
classGraphqlTypeName(declClass) {
|
|
86
|
+
const declImportMap = this.buildGraphqlImportMap(declClass.getSourceFile());
|
|
87
|
+
const decorators = declClass.getDecorators();
|
|
88
|
+
const hasAnyTypeSpelledDecorator = decorators.some((d) => {
|
|
89
|
+
const idNode = (0, graphql_grammar_1.decoratorIdentifier)(d);
|
|
90
|
+
const text = idNode?.getText();
|
|
91
|
+
return text === 'ObjectType' || text === 'InterfaceType';
|
|
92
|
+
});
|
|
93
|
+
const recognized = decorators
|
|
94
|
+
.map(d => this.recognizedDecorator(d, declImportMap))
|
|
95
|
+
.find(r => r?.name === 'ObjectType')
|
|
96
|
+
?? decorators.map(d => this.recognizedDecorator(d, declImportMap)).find(r => r?.name === 'InterfaceType');
|
|
97
|
+
if (recognized) {
|
|
98
|
+
const fallbackName = declClass.getName() ?? (declClass.isDefaultExport() ? 'default' : '');
|
|
99
|
+
const nameResult = this.deriveGraphqlName(recognized.args, false, fallbackName);
|
|
100
|
+
return nameResult.ok ? { ok: true, name: nameResult.name } : { ok: false };
|
|
101
|
+
}
|
|
102
|
+
if (hasAnyTypeSpelledDecorator)
|
|
103
|
+
return { ok: false };
|
|
104
|
+
const name = declClass.getName();
|
|
105
|
+
if (!name)
|
|
106
|
+
return { ok: false };
|
|
107
|
+
return graphql_grammar_1.GRAPHQL_NAME_RE.test(name) ? { ok: true, name } : { ok: false, value: name };
|
|
108
|
+
}
|
|
109
|
+
resolveResolverParentType(cls, importMap) {
|
|
110
|
+
const resolverDec = cls.getDecorators()
|
|
111
|
+
.map(d => this.recognizedDecorator(d, importMap))
|
|
112
|
+
.find(r => r?.name === 'Resolver');
|
|
113
|
+
if (!resolverDec || resolverDec.args.length === 0)
|
|
114
|
+
return { ok: false };
|
|
115
|
+
const argNode = resolverDec.args[0];
|
|
116
|
+
const literal = (0, graphql_grammar_1.literalStringValue)(argNode);
|
|
117
|
+
if (literal !== null) {
|
|
118
|
+
return graphql_grammar_1.GRAPHQL_NAME_RE.test(literal) ? { ok: true, name: literal } : { ok: false, value: literal };
|
|
119
|
+
}
|
|
120
|
+
const identifier = (0, graphql_grammar_1.extractResolverIdentifier)(argNode);
|
|
121
|
+
if (!identifier)
|
|
122
|
+
return { ok: false };
|
|
123
|
+
const resolve = this.resolveDeclaration;
|
|
124
|
+
const declaration = resolve(identifier);
|
|
125
|
+
if (!declaration || !ts_morph_1.Node.isClassDeclaration(declaration))
|
|
126
|
+
return { ok: false };
|
|
127
|
+
return this.classGraphqlTypeName(declaration);
|
|
128
|
+
}
|
|
129
|
+
extractClassTypeRows(cls, importMap, ownByDeclNode, filePath, serviceName, entries) {
|
|
130
|
+
const own = ownByDeclNode.get(cls);
|
|
131
|
+
const declaration = this.declarationNameFor(cls, own?.entry.name ?? cls.getName() ?? 'default');
|
|
132
|
+
const seenNames = new Set();
|
|
133
|
+
for (const dec of cls.getDecorators()) {
|
|
134
|
+
const rec = this.recognizedDecorator(dec, importMap);
|
|
135
|
+
if (!rec || !graphql_grammar_1.GRAPHQL_TYPE_DECORATORS.has(rec.name))
|
|
136
|
+
continue;
|
|
137
|
+
if ((0, graphql_grammar_1.isAbstractGraphqlType)(rec.args)) {
|
|
138
|
+
this.logGraphqlSkip(filePath, declaration, rec.name, 'abstract-type');
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (!own) {
|
|
142
|
+
this.logGraphqlSkip(filePath, declaration, rec.name, 'no-symbol-row');
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const nameResult = this.deriveGraphqlName(rec.args, false, own.entry.name);
|
|
146
|
+
if (!nameResult.ok) {
|
|
147
|
+
this.logGraphqlSkip(filePath, declaration, rec.name, nameResult.reason, nameResult.reason === 'invalid-name' ? nameResult.value : undefined);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (seenNames.has(nameResult.name)) {
|
|
151
|
+
this.logGraphqlSkip(filePath, declaration, rec.name, 'duplicate', own.entry.name);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
seenNames.add(nameResult.name);
|
|
155
|
+
entries.push({
|
|
156
|
+
project: serviceName, filePath, name: nameResult.name, kind: 'graphql_type',
|
|
157
|
+
signature: own.entry.signature, line: own.entry.line, endLine: own.entry.endLine, col: own.entry.col,
|
|
158
|
+
container: null, isStatic: false, target: declaration,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
extractResolveFieldRow(method, rec, own, declaration, importMap, filePath, serviceName, entries) {
|
|
163
|
+
if (!own) {
|
|
164
|
+
this.logGraphqlSkip(filePath, declaration, 'ResolveField', 'no-symbol-row');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const cls = method.getParent();
|
|
168
|
+
if (!cls || !ts_morph_1.Node.isClassDeclaration(cls)) {
|
|
169
|
+
this.logGraphqlSkip(filePath, declaration, 'ResolveField', 'unresolvable-parent');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const parent = this.resolveResolverParentType(cls, importMap);
|
|
173
|
+
if (!parent.ok) {
|
|
174
|
+
this.logGraphqlSkip(filePath, declaration, 'ResolveField', 'unresolvable-parent', parent.value);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const nameResult = this.deriveGraphqlName(rec.args, true, own.entry.name);
|
|
178
|
+
if (!nameResult.ok) {
|
|
179
|
+
this.logGraphqlSkip(filePath, declaration, 'ResolveField', nameResult.reason, nameResult.reason === 'invalid-name' ? nameResult.value : undefined);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
entries.push({
|
|
183
|
+
project: serviceName, filePath, name: nameResult.name, kind: 'graphql_field',
|
|
184
|
+
signature: own.entry.signature, line: own.entry.line, endLine: own.entry.endLine, col: own.entry.col,
|
|
185
|
+
container: parent.name, isStatic: own.entry.isStatic, target: declaration,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
extractMethodOperationRows(method, importMap, ownByDeclNode, filePath, serviceName, entries) {
|
|
189
|
+
const own = ownByDeclNode.get(method);
|
|
190
|
+
const declaration = this.declarationNameFor(method, own?.entry.name ?? (0, node_helpers_1.memberName)(method.getNameNode()) ?? '<anonymous>');
|
|
191
|
+
for (const dec of method.getDecorators()) {
|
|
192
|
+
const rec = this.recognizedDecorator(dec, importMap);
|
|
193
|
+
if (!rec)
|
|
194
|
+
continue;
|
|
195
|
+
if (rec.name === 'ResolveField') {
|
|
196
|
+
try {
|
|
197
|
+
this.extractResolveFieldRow(method, rec, own, declaration, importMap, filePath, serviceName, entries);
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
this.logGraphqlSkip(filePath, declaration, 'ResolveField', 'unresolvable-parent');
|
|
201
|
+
}
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const kind = graphql_grammar_1.GRAPHQL_OPERATION_KIND[rec.name];
|
|
205
|
+
if (!kind)
|
|
206
|
+
continue;
|
|
207
|
+
if (!own) {
|
|
208
|
+
this.logGraphqlSkip(filePath, declaration, rec.name, 'no-symbol-row');
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const nameResult = this.deriveGraphqlName(rec.args, true, own.entry.name);
|
|
212
|
+
if (!nameResult.ok) {
|
|
213
|
+
this.logGraphqlSkip(filePath, declaration, rec.name, nameResult.reason, nameResult.reason === 'invalid-name' ? nameResult.value : undefined);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
entries.push({
|
|
217
|
+
project: serviceName, filePath, name: nameResult.name, kind,
|
|
218
|
+
signature: own.entry.signature, line: own.entry.line, endLine: own.entry.endLine, col: own.entry.col,
|
|
219
|
+
container: rec.name, isStatic: own.entry.isStatic, target: declaration,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
extractGraphqlNames(sourceFile, filePath, serviceName, ownRows) {
|
|
224
|
+
const importMap = this.buildGraphqlImportMap(sourceFile);
|
|
225
|
+
if (importMap.size === 0)
|
|
226
|
+
return [];
|
|
227
|
+
const ownByDeclNode = new Map();
|
|
228
|
+
for (const c of ownRows)
|
|
229
|
+
ownByDeclNode.set(c.declNode, c);
|
|
230
|
+
const entries = [];
|
|
231
|
+
for (const cls of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ClassDeclaration)) {
|
|
232
|
+
this.extractClassTypeRows(cls, importMap, ownByDeclNode, filePath, serviceName, entries);
|
|
233
|
+
}
|
|
234
|
+
for (const method of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.MethodDeclaration)) {
|
|
235
|
+
this.extractMethodOperationRows(method, importMap, ownByDeclNode, filePath, serviceName, entries);
|
|
236
|
+
}
|
|
237
|
+
return entries;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.GraphqlNameExtractor = GraphqlNameExtractor;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SourceFile } from 'ts-morph';
|
|
2
|
+
import type { DepEdge } from '../interfaces/IAstParser';
|
|
3
|
+
import type { ILogger } from '../interfaces';
|
|
4
|
+
export declare class ImportEdgeExtractor {
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(logger: ILogger);
|
|
7
|
+
extractEdges(sourceFile: SourceFile, filePath: string, serviceName: string): DepEdge[];
|
|
8
|
+
private resolveSideEffectModuleSpecifier;
|
|
9
|
+
private resolveFromSymbol;
|
|
10
|
+
private buildUsageMap;
|
|
11
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportEdgeExtractor = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
class ImportEdgeExtractor {
|
|
6
|
+
logger;
|
|
7
|
+
constructor(logger) {
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
}
|
|
10
|
+
extractEdges(sourceFile, filePath, serviceName) {
|
|
11
|
+
const edges = [];
|
|
12
|
+
const usageMap = this.buildUsageMap(sourceFile);
|
|
13
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
14
|
+
const namedImports = decl.getNamedImports();
|
|
15
|
+
const defaultImport = decl.getDefaultImport();
|
|
16
|
+
const namespaceImport = decl.getNamespaceImport();
|
|
17
|
+
const hasClause = Boolean(defaultImport || namespaceImport || namedImports.length > 0);
|
|
18
|
+
const resolved = decl.getModuleSpecifierSourceFile();
|
|
19
|
+
let toFile = resolved ? resolved.getFilePath() : null;
|
|
20
|
+
if (!toFile && !hasClause) {
|
|
21
|
+
toFile = this.resolveSideEffectModuleSpecifier(decl, sourceFile, filePath);
|
|
22
|
+
}
|
|
23
|
+
if (!toFile) {
|
|
24
|
+
const specifier = decl.getModuleSpecifierValue();
|
|
25
|
+
const isCodeImport = !/\.(json|css|scss|less|svg|png|jpg|gif|ico|woff2?|ttf|eot)(\?.*)?$/.test(specifier);
|
|
26
|
+
if (specifier.startsWith('.') && isCodeImport) {
|
|
27
|
+
this.logger.debug('AstParser: unresolved import', { specifier, file: filePath });
|
|
28
|
+
}
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (toFile.includes('/node_modules/'))
|
|
32
|
+
continue;
|
|
33
|
+
if (!hasClause) {
|
|
34
|
+
edges.push({
|
|
35
|
+
project: serviceName, fromFile: filePath, fromSymbol: null,
|
|
36
|
+
toFile, toSymbol: null, depType: 'import-side-effect',
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (defaultImport) {
|
|
41
|
+
const fromSymbol = this.resolveFromSymbol(defaultImport.getText(), usageMap);
|
|
42
|
+
edges.push({
|
|
43
|
+
project: serviceName, fromFile: filePath, fromSymbol,
|
|
44
|
+
toFile, toSymbol: null, depType: 'import-default',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (namespaceImport) {
|
|
48
|
+
const fromSymbol = this.resolveFromSymbol(namespaceImport.getText(), usageMap);
|
|
49
|
+
edges.push({
|
|
50
|
+
project: serviceName, fromFile: filePath, fromSymbol,
|
|
51
|
+
toFile, toSymbol: null, depType: 'import-namespace',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
for (const named of namedImports) {
|
|
55
|
+
const localName = named.getAliasNode()?.getText() ?? named.getName();
|
|
56
|
+
const fromSymbol = this.resolveFromSymbol(localName, usageMap);
|
|
57
|
+
edges.push({
|
|
58
|
+
project: serviceName, fromFile: filePath, fromSymbol,
|
|
59
|
+
toFile, toSymbol: named.getName(), depType: 'import',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const decl of sourceFile.getExportDeclarations()) {
|
|
64
|
+
const resolved = decl.getModuleSpecifierSourceFile();
|
|
65
|
+
if (!resolved)
|
|
66
|
+
continue;
|
|
67
|
+
const toFile = resolved.getFilePath();
|
|
68
|
+
if (toFile.includes('/node_modules/'))
|
|
69
|
+
continue;
|
|
70
|
+
const namedExports = decl.getNamedExports();
|
|
71
|
+
if (namedExports.length > 0) {
|
|
72
|
+
for (const named of namedExports) {
|
|
73
|
+
edges.push({
|
|
74
|
+
project: serviceName, fromFile: filePath, fromSymbol: null,
|
|
75
|
+
toFile, toSymbol: named.getName(), depType: 'reexport',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
edges.push({
|
|
81
|
+
project: serviceName, fromFile: filePath, fromSymbol: null,
|
|
82
|
+
toFile, toSymbol: null, depType: 'reexport-namespace',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return edges;
|
|
87
|
+
}
|
|
88
|
+
resolveSideEffectModuleSpecifier(decl, sourceFile, filePath) {
|
|
89
|
+
const specifier = decl.getModuleSpecifierValue();
|
|
90
|
+
const compilerOptions = sourceFile.getProject().getCompilerOptions();
|
|
91
|
+
const result = ts_morph_1.ts.resolveModuleName(specifier, filePath, compilerOptions, ts_morph_1.ts.sys);
|
|
92
|
+
const resolvedFileName = result.resolvedModule?.resolvedFileName;
|
|
93
|
+
if (!resolvedFileName)
|
|
94
|
+
return null;
|
|
95
|
+
return sourceFile.getProject().getSourceFile(resolvedFileName)?.getFilePath() ?? null;
|
|
96
|
+
}
|
|
97
|
+
resolveFromSymbol(localName, usageMap) {
|
|
98
|
+
const users = usageMap.get(localName);
|
|
99
|
+
return users?.length === 1 ? users[0] : null;
|
|
100
|
+
}
|
|
101
|
+
buildUsageMap(sourceFile) {
|
|
102
|
+
const map = new Map();
|
|
103
|
+
const containers = [
|
|
104
|
+
...sourceFile.getClasses().flatMap(n => n.getName() ? [{ name: n.getName(), node: n }] : []),
|
|
105
|
+
...sourceFile.getFunctions().flatMap(n => n.getName() ? [{ name: n.getName(), node: n }] : []),
|
|
106
|
+
...sourceFile.getVariableStatements()
|
|
107
|
+
.flatMap(stmt => stmt.getDeclarations())
|
|
108
|
+
.flatMap(n => {
|
|
109
|
+
const name = n.getName();
|
|
110
|
+
return name ? [{ name, node: n }] : [];
|
|
111
|
+
}),
|
|
112
|
+
];
|
|
113
|
+
for (const { name, node } of containers) {
|
|
114
|
+
for (const id of node.getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)) {
|
|
115
|
+
const text = id.getText();
|
|
116
|
+
const existing = map.get(text);
|
|
117
|
+
if (existing) {
|
|
118
|
+
if (!existing.includes(name))
|
|
119
|
+
existing.push(name);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
map.set(text, [name]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return map;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.ImportEdgeExtractor = ImportEdgeExtractor;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Node } from 'ts-morph';
|
|
2
|
+
import type { IIndexedNodeResolver, IndexedNodeDescription } from '../interfaces/IIndexedNodeResolver';
|
|
3
|
+
export declare class IndexedNodeResolver implements IIndexedNodeResolver {
|
|
4
|
+
private static isValidSegment;
|
|
5
|
+
private isModuleOrNamespaceLevelVariable;
|
|
6
|
+
private classExpressionRoot;
|
|
7
|
+
private objectLiteralRootValid;
|
|
8
|
+
private isTopLevelOrNamespaceDirect;
|
|
9
|
+
private walkStep;
|
|
10
|
+
private containerSegments;
|
|
11
|
+
describeIndexedNode(node: Node): IndexedNodeDescription | null;
|
|
12
|
+
qualifiedName(described: IndexedNodeDescription): string;
|
|
13
|
+
findFromSymbol(node: Node): string | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexedNodeResolver = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const node_helpers_1 = require("./node-helpers");
|
|
6
|
+
const VALID_SEGMENT = /^#?[\w$]+$/;
|
|
7
|
+
class IndexedNodeResolver {
|
|
8
|
+
static isValidSegment(s) {
|
|
9
|
+
return VALID_SEGMENT.test(s);
|
|
10
|
+
}
|
|
11
|
+
isModuleOrNamespaceLevelVariable(varDecl) {
|
|
12
|
+
const stmt = varDecl.getParent()?.getParent();
|
|
13
|
+
const stmtParent = stmt?.getParent();
|
|
14
|
+
return ts_morph_1.Node.isSourceFile(stmtParent) || ts_morph_1.Node.isModuleBlock(stmtParent);
|
|
15
|
+
}
|
|
16
|
+
classExpressionRoot(classExpr) {
|
|
17
|
+
const parent = (0, node_helpers_1.unwrapParent)(classExpr);
|
|
18
|
+
if (!parent)
|
|
19
|
+
return null;
|
|
20
|
+
if (ts_morph_1.Node.isVariableDeclaration(parent)) {
|
|
21
|
+
const name = parent.getName();
|
|
22
|
+
return name ? { name, namingParent: parent } : null;
|
|
23
|
+
}
|
|
24
|
+
if (ts_morph_1.Node.isExportAssignment(parent) && !parent.isExportEquals()) {
|
|
25
|
+
return { name: 'default', namingParent: parent };
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
objectLiteralRootValid(obj) {
|
|
30
|
+
const parent = (0, node_helpers_1.unwrapParent)(obj);
|
|
31
|
+
if (!parent)
|
|
32
|
+
return false;
|
|
33
|
+
if (ts_morph_1.Node.isPropertyAssignment(parent))
|
|
34
|
+
return true;
|
|
35
|
+
if (ts_morph_1.Node.isVariableDeclaration(parent))
|
|
36
|
+
return this.isModuleOrNamespaceLevelVariable(parent);
|
|
37
|
+
if (ts_morph_1.Node.isExportAssignment(parent) && !parent.isExportEquals())
|
|
38
|
+
return true;
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
isTopLevelOrNamespaceDirect(node) {
|
|
42
|
+
return ts_morph_1.Node.isSourceFile(node) || ts_morph_1.Node.isModuleBlock(node);
|
|
43
|
+
}
|
|
44
|
+
walkStep(node) {
|
|
45
|
+
if (ts_morph_1.Node.isModuleDeclaration(node)) {
|
|
46
|
+
if (node.compilerNode.flags & ts_morph_1.NodeFlags.GlobalAugmentation)
|
|
47
|
+
return { kind: 'exclude' };
|
|
48
|
+
const nameNode = node.getNameNode();
|
|
49
|
+
if (ts_morph_1.Node.isStringLiteral(nameNode))
|
|
50
|
+
return { kind: 'exclude' };
|
|
51
|
+
return { kind: 'segment', text: nameNode.getText() };
|
|
52
|
+
}
|
|
53
|
+
if (ts_morph_1.Node.isClassDeclaration(node)) {
|
|
54
|
+
const name = node.getName();
|
|
55
|
+
if (name)
|
|
56
|
+
return { kind: 'segment', text: name };
|
|
57
|
+
if (node.isDefaultExport())
|
|
58
|
+
return { kind: 'segment', text: 'default' };
|
|
59
|
+
return { kind: 'exclude' };
|
|
60
|
+
}
|
|
61
|
+
if (ts_morph_1.Node.isClassExpression(node)) {
|
|
62
|
+
const root = this.classExpressionRoot(node);
|
|
63
|
+
if (!root)
|
|
64
|
+
return { kind: 'exclude' };
|
|
65
|
+
return { kind: 'segment', text: root.name, skipTo: root.namingParent };
|
|
66
|
+
}
|
|
67
|
+
if (ts_morph_1.Node.isFunctionDeclaration(node)) {
|
|
68
|
+
const name = node.getName();
|
|
69
|
+
return name ? { kind: 'segment', text: name } : { kind: 'transparent' };
|
|
70
|
+
}
|
|
71
|
+
if (ts_morph_1.Node.isMethodDeclaration(node) || ts_morph_1.Node.isGetAccessorDeclaration(node) || ts_morph_1.Node.isSetAccessorDeclaration(node)) {
|
|
72
|
+
const name = (0, node_helpers_1.memberName)(node.getNameNode());
|
|
73
|
+
return name !== null ? { kind: 'segment', text: name } : { kind: 'exclude' };
|
|
74
|
+
}
|
|
75
|
+
if (ts_morph_1.Node.isConstructorDeclaration(node)) {
|
|
76
|
+
return { kind: 'segment', text: 'constructor' };
|
|
77
|
+
}
|
|
78
|
+
if (ts_morph_1.Node.isPropertyDeclaration(node) || ts_morph_1.Node.isPropertyAssignment(node)) {
|
|
79
|
+
const name = (0, node_helpers_1.memberName)(node.getNameNode());
|
|
80
|
+
return name !== null ? { kind: 'segment', text: name } : { kind: 'exclude' };
|
|
81
|
+
}
|
|
82
|
+
if (ts_morph_1.Node.isInterfaceDeclaration(node)) {
|
|
83
|
+
return { kind: 'segment', text: node.getName() };
|
|
84
|
+
}
|
|
85
|
+
if (ts_morph_1.Node.isTypeAliasDeclaration(node)) {
|
|
86
|
+
return { kind: 'segment', text: node.getName() };
|
|
87
|
+
}
|
|
88
|
+
if (ts_morph_1.Node.isVariableDeclaration(node)) {
|
|
89
|
+
return { kind: 'segment', text: node.getName() };
|
|
90
|
+
}
|
|
91
|
+
if (ts_morph_1.Node.isObjectLiteralExpression(node)) {
|
|
92
|
+
return this.objectLiteralRootValid(node) ? { kind: 'transparent' } : { kind: 'exclude' };
|
|
93
|
+
}
|
|
94
|
+
return { kind: 'transparent' };
|
|
95
|
+
}
|
|
96
|
+
containerSegments(node) {
|
|
97
|
+
const segments = [];
|
|
98
|
+
let current = node.getParent();
|
|
99
|
+
while (current) {
|
|
100
|
+
const step = this.walkStep(current);
|
|
101
|
+
if (step.kind === 'exclude')
|
|
102
|
+
return null;
|
|
103
|
+
if (step.kind === 'segment') {
|
|
104
|
+
if (!IndexedNodeResolver.isValidSegment(step.text))
|
|
105
|
+
return null;
|
|
106
|
+
segments.unshift(step.text);
|
|
107
|
+
current = step.skipTo ? step.skipTo.getParent() : current.getParent();
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
current = current.getParent();
|
|
111
|
+
}
|
|
112
|
+
return segments;
|
|
113
|
+
}
|
|
114
|
+
describeIndexedNode(node) {
|
|
115
|
+
if (ts_morph_1.Node.isClassDeclaration(node)) {
|
|
116
|
+
const name = node.getName() ?? (node.isDefaultExport() ? 'default' : null);
|
|
117
|
+
if (name === null)
|
|
118
|
+
return null;
|
|
119
|
+
const container = this.containerSegments(node);
|
|
120
|
+
return container === null ? null : { name, container };
|
|
121
|
+
}
|
|
122
|
+
if (ts_morph_1.Node.isClassExpression(node)) {
|
|
123
|
+
const root = this.classExpressionRoot(node);
|
|
124
|
+
if (!root)
|
|
125
|
+
return null;
|
|
126
|
+
const container = this.containerSegments(root.namingParent);
|
|
127
|
+
return container === null ? null : { name: root.name, container };
|
|
128
|
+
}
|
|
129
|
+
if (ts_morph_1.Node.isFunctionDeclaration(node)) {
|
|
130
|
+
const name = node.getName();
|
|
131
|
+
if (!name || !this.isTopLevelOrNamespaceDirect(node.getParent()))
|
|
132
|
+
return null;
|
|
133
|
+
const container = this.containerSegments(node);
|
|
134
|
+
return container === null ? null : { name, container };
|
|
135
|
+
}
|
|
136
|
+
if (ts_morph_1.Node.isMethodDeclaration(node) || ts_morph_1.Node.isGetAccessorDeclaration(node) || ts_morph_1.Node.isSetAccessorDeclaration(node)) {
|
|
137
|
+
const name = (0, node_helpers_1.memberName)(node.getNameNode());
|
|
138
|
+
if (name === null)
|
|
139
|
+
return null;
|
|
140
|
+
const container = this.containerSegments(node);
|
|
141
|
+
return container === null ? null : { name, container };
|
|
142
|
+
}
|
|
143
|
+
if (ts_morph_1.Node.isConstructorDeclaration(node)) {
|
|
144
|
+
const container = this.containerSegments(node);
|
|
145
|
+
return container === null ? null : { name: 'constructor', container };
|
|
146
|
+
}
|
|
147
|
+
if (ts_morph_1.Node.isPropertyDeclaration(node) || ts_morph_1.Node.isPropertyAssignment(node)) {
|
|
148
|
+
const init = node.getInitializer();
|
|
149
|
+
if (!init)
|
|
150
|
+
return null;
|
|
151
|
+
const unwrapped = (0, node_helpers_1.unwrapExpr)(init);
|
|
152
|
+
if (!(ts_morph_1.Node.isArrowFunction(unwrapped) || ts_morph_1.Node.isFunctionExpression(unwrapped)))
|
|
153
|
+
return null;
|
|
154
|
+
const name = (0, node_helpers_1.memberName)(node.getNameNode());
|
|
155
|
+
if (name === null)
|
|
156
|
+
return null;
|
|
157
|
+
const container = this.containerSegments(node);
|
|
158
|
+
return container === null ? null : { name, container };
|
|
159
|
+
}
|
|
160
|
+
if (ts_morph_1.Node.isInterfaceDeclaration(node)) {
|
|
161
|
+
if (!this.isTopLevelOrNamespaceDirect(node.getParent()))
|
|
162
|
+
return null;
|
|
163
|
+
const container = this.containerSegments(node);
|
|
164
|
+
return container === null ? null : { name: node.getName(), container };
|
|
165
|
+
}
|
|
166
|
+
if (ts_morph_1.Node.isTypeAliasDeclaration(node)) {
|
|
167
|
+
if (!this.isTopLevelOrNamespaceDirect(node.getParent()))
|
|
168
|
+
return null;
|
|
169
|
+
const container = this.containerSegments(node);
|
|
170
|
+
return container === null ? null : { name: node.getName(), container };
|
|
171
|
+
}
|
|
172
|
+
if (ts_morph_1.Node.isVariableDeclaration(node)) {
|
|
173
|
+
if (!this.isModuleOrNamespaceLevelVariable(node))
|
|
174
|
+
return null;
|
|
175
|
+
const container = this.containerSegments(node);
|
|
176
|
+
return container === null ? null : { name: node.getName(), container };
|
|
177
|
+
}
|
|
178
|
+
if (ts_morph_1.Node.isMethodSignature(node) || ts_morph_1.Node.isPropertySignature(node)) {
|
|
179
|
+
if (ts_morph_1.Node.isPropertySignature(node)) {
|
|
180
|
+
const typeNode = node.getTypeNode();
|
|
181
|
+
if (!typeNode || !ts_morph_1.Node.isFunctionTypeNode(typeNode))
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const parent = node.getParent();
|
|
185
|
+
let validParent = false;
|
|
186
|
+
if (ts_morph_1.Node.isInterfaceDeclaration(parent)) {
|
|
187
|
+
validParent = true;
|
|
188
|
+
}
|
|
189
|
+
else if (ts_morph_1.Node.isTypeLiteral(parent)) {
|
|
190
|
+
const aliasParent = parent.getParent();
|
|
191
|
+
validParent = ts_morph_1.Node.isTypeAliasDeclaration(aliasParent) && aliasParent.getTypeNode() === parent;
|
|
192
|
+
}
|
|
193
|
+
if (!validParent)
|
|
194
|
+
return null;
|
|
195
|
+
const name = (0, node_helpers_1.memberName)(node.getNameNode());
|
|
196
|
+
if (name === null)
|
|
197
|
+
return null;
|
|
198
|
+
const container = this.containerSegments(node);
|
|
199
|
+
return container === null ? null : { name, container };
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
qualifiedName(described) {
|
|
204
|
+
return described.container.length ? `${described.container.join('.')}.${described.name}` : described.name;
|
|
205
|
+
}
|
|
206
|
+
findFromSymbol(node) {
|
|
207
|
+
let current = node.getParent();
|
|
208
|
+
while (current) {
|
|
209
|
+
const described = this.describeIndexedNode(current);
|
|
210
|
+
if (described)
|
|
211
|
+
return this.qualifiedName(described);
|
|
212
|
+
current = current.getParent();
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.IndexedNodeResolver = IndexedNodeResolver;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type SourceFile } from 'ts-morph';
|
|
2
|
+
import type { IIndexedNodeResolver } from '../interfaces';
|
|
3
|
+
import type { DeclarationCandidate } from '../declarations/DeclarationTreeBuilder';
|
|
4
|
+
export declare class MemberExtractor {
|
|
5
|
+
private readonly resolver;
|
|
6
|
+
constructor(resolver: IIndexedNodeResolver);
|
|
7
|
+
extractMembers(sourceFile: SourceFile, filePath: string, serviceName: string): DeclarationCandidate[];
|
|
8
|
+
}
|