@zipbul/gildash 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.ko.md +234 -290
- package/README.md +337 -341
- package/dist/index.js +6 -4
- package/dist/index.js.map +15 -14
- package/dist/migrations/0001_add_line_count.sql +1 -0
- package/dist/migrations/meta/_journal.json +7 -0
- package/dist/src/extractor/types.d.ts +5 -1
- package/dist/src/gildash.d.ts +379 -3
- package/dist/src/index.d.ts +3 -1
- package/dist/src/indexer/index-coordinator.d.ts +21 -0
- package/dist/src/search/dependency-graph.d.ts +28 -0
- package/dist/src/search/index.d.ts +2 -0
- package/dist/src/search/pattern-search.d.ts +30 -0
- package/dist/src/search/symbol-search.d.ts +12 -0
- package/dist/src/store/repositories/file.repository.d.ts +2 -0
- package/dist/src/store/repositories/symbol.repository.d.ts +2 -0
- package/dist/src/store/schema.d.ts +17 -0
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE `files` ADD COLUMN `line_count` integer;
|
|
@@ -141,13 +141,15 @@ export interface ImportReference {
|
|
|
141
141
|
* A relationship between two symbols/files extracted from source code.
|
|
142
142
|
*
|
|
143
143
|
* - `'imports'` — file A imports from file B
|
|
144
|
+
* - `'type-references'` — file A type-only imports from file B (`import type`)
|
|
145
|
+
* - `'re-exports'` — file A re-exports from file B (`export { ... } from`)
|
|
144
146
|
* - `'calls'` — symbol in file A calls a symbol in file B
|
|
145
147
|
* - `'extends'` — class/interface in file A extends one in file B
|
|
146
148
|
* - `'implements'` — class in file A implements an interface in file B
|
|
147
149
|
*/
|
|
148
150
|
export interface CodeRelation {
|
|
149
151
|
/** The kind of relationship. */
|
|
150
|
-
type: 'imports' | 'calls' | 'extends' | 'implements';
|
|
152
|
+
type: 'imports' | 'type-references' | 're-exports' | 'calls' | 'extends' | 'implements';
|
|
151
153
|
/** File path where the relationship originates. */
|
|
152
154
|
srcFilePath: string;
|
|
153
155
|
/** Source symbol name, or `null` for module-level relationships. */
|
|
@@ -158,5 +160,7 @@ export interface CodeRelation {
|
|
|
158
160
|
dstSymbolName: string | null;
|
|
159
161
|
/** Optional JSON-encoded metadata about the relation. */
|
|
160
162
|
metaJson?: string;
|
|
163
|
+
/** Parsed metadata object derived from `metaJson`. */
|
|
164
|
+
meta?: Record<string, unknown>;
|
|
161
165
|
}
|
|
162
166
|
export type { SourcePosition, SourceSpan };
|
package/dist/src/gildash.d.ts
CHANGED
|
@@ -2,10 +2,9 @@ import { type Result } from '@zipbul/result';
|
|
|
2
2
|
import type { ParsedFile } from './parser/types';
|
|
3
3
|
import { parseSource as defaultParseSource } from './parser/parse-source';
|
|
4
4
|
import { ParseCache } from './parser/parse-cache';
|
|
5
|
-
import type { ExtractedSymbol } from './extractor/types';
|
|
5
|
+
import type { ExtractedSymbol, SymbolKind, CodeRelation } from './extractor/types';
|
|
6
6
|
import { extractSymbols as defaultExtractSymbols } from './extractor/symbol-extractor';
|
|
7
7
|
import { extractRelations as defaultExtractRelations } from './extractor/relation-extractor';
|
|
8
|
-
import type { CodeRelation } from './extractor/types';
|
|
9
8
|
import { DbConnection } from './store/connection';
|
|
10
9
|
import { FileRepository } from './store/repositories/file.repository';
|
|
11
10
|
import type { FileRecord } from './store/repositories/file.repository';
|
|
@@ -26,6 +25,7 @@ import type { SymbolSearchQuery, SymbolSearchResult } from './search/symbol-sear
|
|
|
26
25
|
import { relationSearch as defaultRelationSearch } from './search/relation-search';
|
|
27
26
|
import type { RelationSearchQuery } from './search/relation-search';
|
|
28
27
|
import type { SymbolStats } from './store/repositories/symbol.repository';
|
|
28
|
+
import type { PatternMatch } from './search/pattern-search';
|
|
29
29
|
import { type GildashError } from './errors';
|
|
30
30
|
/**
|
|
31
31
|
* Minimal logger interface accepted by {@link Gildash}.
|
|
@@ -36,6 +36,117 @@ export interface Logger {
|
|
|
36
36
|
/** Log one or more error-level messages. */
|
|
37
37
|
error(...args: unknown[]): void;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Result of a {@link Gildash.diffSymbols} call.
|
|
41
|
+
*/
|
|
42
|
+
export interface SymbolDiff {
|
|
43
|
+
/** Symbols present in `after` but not in `before`. */
|
|
44
|
+
added: SymbolSearchResult[];
|
|
45
|
+
/** Symbols present in `before` but not in `after`. */
|
|
46
|
+
removed: SymbolSearchResult[];
|
|
47
|
+
/** Symbols present in both but with a different `fingerprint`. */
|
|
48
|
+
modified: Array<{
|
|
49
|
+
before: SymbolSearchResult;
|
|
50
|
+
after: SymbolSearchResult;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Public interface of a module — its exported symbols with key metadata.
|
|
55
|
+
* Returned by {@link Gildash.getModuleInterface}.
|
|
56
|
+
*/
|
|
57
|
+
export interface ModuleInterface {
|
|
58
|
+
filePath: string;
|
|
59
|
+
exports: Array<{
|
|
60
|
+
name: string;
|
|
61
|
+
kind: SymbolKind;
|
|
62
|
+
parameters?: string;
|
|
63
|
+
returnType?: string;
|
|
64
|
+
jsDoc?: string;
|
|
65
|
+
}>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A node in the heritage chain tree returned by {@link Gildash.getHeritageChain}.
|
|
69
|
+
*/
|
|
70
|
+
export interface HeritageNode {
|
|
71
|
+
symbolName: string;
|
|
72
|
+
filePath: string;
|
|
73
|
+
/** Relationship kind (`extends` or `implements`). Undefined for the root query node. */
|
|
74
|
+
kind?: 'extends' | 'implements';
|
|
75
|
+
children: HeritageNode[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Full symbol detail including members, documentation, and type information.
|
|
79
|
+
* Returned by {@link Gildash.getFullSymbol}.
|
|
80
|
+
*/
|
|
81
|
+
export interface FullSymbol extends SymbolSearchResult {
|
|
82
|
+
members?: Array<{
|
|
83
|
+
name: string;
|
|
84
|
+
kind: string;
|
|
85
|
+
type?: string;
|
|
86
|
+
visibility?: string;
|
|
87
|
+
isStatic?: boolean;
|
|
88
|
+
isReadonly?: boolean;
|
|
89
|
+
}>;
|
|
90
|
+
/** JSDoc comment attached to the symbol. */
|
|
91
|
+
jsDoc?: string;
|
|
92
|
+
/** Stringified parameter list (functions/methods). */
|
|
93
|
+
parameters?: string;
|
|
94
|
+
/** Stringified return type (functions/methods). */
|
|
95
|
+
returnType?: string;
|
|
96
|
+
/** Superclass/interface names (classes/interfaces with heritage). */
|
|
97
|
+
heritage?: string[];
|
|
98
|
+
/** Decorators applied to the symbol. */
|
|
99
|
+
decorators?: Array<{
|
|
100
|
+
name: string;
|
|
101
|
+
arguments?: string;
|
|
102
|
+
}>;
|
|
103
|
+
/** Stringified type parameters (generic symbols). */
|
|
104
|
+
typeParameters?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* File-level statistics for an indexed file.
|
|
108
|
+
* Returned by {@link Gildash.getFileStats}.
|
|
109
|
+
*/
|
|
110
|
+
export interface FileStats {
|
|
111
|
+
/** Absolute file path. */
|
|
112
|
+
filePath: string;
|
|
113
|
+
/** Number of lines in the file at the time of last indexing. */
|
|
114
|
+
lineCount: number;
|
|
115
|
+
/** Number of symbols indexed in the file. */
|
|
116
|
+
symbolCount: number;
|
|
117
|
+
/** Number of outgoing relations (imports, calls, etc.) from the file. */
|
|
118
|
+
relationCount: number;
|
|
119
|
+
/** File size in bytes at the time of last indexing. */
|
|
120
|
+
size: number;
|
|
121
|
+
/** Number of exported symbols in the file. */
|
|
122
|
+
exportedSymbolCount: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Import-graph fan metrics for a single file.
|
|
126
|
+
* Returned by {@link Gildash.getFanMetrics}.
|
|
127
|
+
*/
|
|
128
|
+
export interface FanMetrics {
|
|
129
|
+
/** Absolute file path queried. */
|
|
130
|
+
filePath: string;
|
|
131
|
+
/** Number of files that import this file (fan-in). */
|
|
132
|
+
fanIn: number;
|
|
133
|
+
/** Number of files this file imports (fan-out). */
|
|
134
|
+
fanOut: number;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Result of following a re-export chain to the original symbol definition.
|
|
138
|
+
*/
|
|
139
|
+
export interface ResolvedSymbol {
|
|
140
|
+
/** The name of the symbol at the end of the re-export chain (may differ from the queried name due to aliasing). */
|
|
141
|
+
originalName: string;
|
|
142
|
+
/** Absolute path of the file that originally defines the symbol. */
|
|
143
|
+
originalFilePath: string;
|
|
144
|
+
/** Ordered list of re-export hops between the queried file and the original definition. */
|
|
145
|
+
reExportChain: Array<{
|
|
146
|
+
filePath: string;
|
|
147
|
+
exportedAs: string;
|
|
148
|
+
}>;
|
|
149
|
+
}
|
|
39
150
|
/**
|
|
40
151
|
* Options for creating a {@link Gildash} instance via {@link Gildash.open}.
|
|
41
152
|
*
|
|
@@ -66,6 +177,17 @@ export interface GildashOptions {
|
|
|
66
177
|
parseCacheCapacity?: number;
|
|
67
178
|
/** Logger for error output. Defaults to `console`. */
|
|
68
179
|
logger?: Logger;
|
|
180
|
+
/**
|
|
181
|
+
* When `false`, disables the file watcher and runs in scan-only mode:
|
|
182
|
+
* ownership contention is skipped, heartbeat and signal handlers are not
|
|
183
|
+
* registered, and only the initial `fullIndex()` is performed.
|
|
184
|
+
*
|
|
185
|
+
* Set `cleanup: true` in {@link Gildash.close} to remove the database files
|
|
186
|
+
* after a one-shot scan.
|
|
187
|
+
*
|
|
188
|
+
* @default true
|
|
189
|
+
*/
|
|
190
|
+
watchMode?: boolean;
|
|
69
191
|
}
|
|
70
192
|
interface GildashInternalOptions {
|
|
71
193
|
existsSyncFn?: (p: string) => boolean;
|
|
@@ -90,7 +212,16 @@ interface GildashInternalOptions {
|
|
|
90
212
|
extractRelationsFn?: typeof defaultExtractRelations;
|
|
91
213
|
symbolSearchFn?: typeof defaultSymbolSearch;
|
|
92
214
|
relationSearchFn?: typeof defaultRelationSearch;
|
|
215
|
+
patternSearchFn?: (opts: {
|
|
216
|
+
pattern: string;
|
|
217
|
+
filePaths: string[];
|
|
218
|
+
}) => Promise<PatternMatch[]>;
|
|
93
219
|
loadTsconfigPathsFn?: typeof loadTsconfigPaths;
|
|
220
|
+
readFileFn?: (filePath: string) => Promise<string>;
|
|
221
|
+
unlinkFn?: (filePath: string) => Promise<void>;
|
|
222
|
+
makeExternalCoordinatorFn?: (packageDir: string, project: string) => {
|
|
223
|
+
fullIndex(): Promise<IndexResult>;
|
|
224
|
+
};
|
|
94
225
|
}
|
|
95
226
|
/**
|
|
96
227
|
* Main entry point for gildash.
|
|
@@ -141,6 +272,11 @@ export declare class Gildash {
|
|
|
141
272
|
private readonly extractRelationsFn;
|
|
142
273
|
private readonly symbolSearchFn;
|
|
143
274
|
private readonly relationSearchFn;
|
|
275
|
+
private readonly patternSearchFn;
|
|
276
|
+
private readonly readFileFn;
|
|
277
|
+
private readonly unlinkFn;
|
|
278
|
+
private readonly existsSyncFn;
|
|
279
|
+
private readonly makeExternalCoordinatorFn?;
|
|
144
280
|
private readonly logger;
|
|
145
281
|
private readonly defaultProject;
|
|
146
282
|
/** Current watcher role: `'owner'` (can reindex) or `'reader'` (read-only). */
|
|
@@ -151,6 +287,10 @@ export declare class Gildash {
|
|
|
151
287
|
private tsconfigPaths;
|
|
152
288
|
private boundaries;
|
|
153
289
|
private readonly onIndexedCallbacks;
|
|
290
|
+
/** Cached DependencyGraph — invalidated on each index run. */
|
|
291
|
+
private graphCache;
|
|
292
|
+
/** Project key of the cached graph (`project ?? '__cross__'`). */
|
|
293
|
+
private graphCacheKey;
|
|
154
294
|
private constructor();
|
|
155
295
|
/**
|
|
156
296
|
* Create and initialise a new `Gildash` instance.
|
|
@@ -193,7 +333,9 @@ export declare class Gildash {
|
|
|
193
333
|
* }
|
|
194
334
|
* ```
|
|
195
335
|
*/
|
|
196
|
-
close(
|
|
336
|
+
close(opts?: {
|
|
337
|
+
cleanup?: boolean;
|
|
338
|
+
}): Promise<Result<void, GildashError>>;
|
|
197
339
|
/**
|
|
198
340
|
* Register a callback that fires after each indexing run completes.
|
|
199
341
|
*
|
|
@@ -272,6 +414,15 @@ export declare class Gildash {
|
|
|
272
414
|
* ```
|
|
273
415
|
*/
|
|
274
416
|
extractRelations(parsed: ParsedFile): Result<CodeRelation[], GildashError>;
|
|
417
|
+
/** Invalidate the cached DependencyGraph (called after every index run). */
|
|
418
|
+
private invalidateGraphCache;
|
|
419
|
+
/**
|
|
420
|
+
* Return a cached or freshly-built {@link DependencyGraph} for the given project.
|
|
421
|
+
*
|
|
422
|
+
* Builds once per `project ?? '__cross__'` key; subsequent calls with the same key
|
|
423
|
+
* return the cached instance. Cache is invalidated by {@link invalidateGraphCache}.
|
|
424
|
+
*/
|
|
425
|
+
private getOrBuildGraph;
|
|
275
426
|
/**
|
|
276
427
|
* Trigger a full re-index of all tracked files.
|
|
277
428
|
*
|
|
@@ -348,6 +499,60 @@ export declare class Gildash {
|
|
|
348
499
|
* ```
|
|
349
500
|
*/
|
|
350
501
|
searchRelations(query: RelationSearchQuery): Result<CodeRelation[], GildashError>;
|
|
502
|
+
/**
|
|
503
|
+
* Search symbols across all projects (no project filter).
|
|
504
|
+
*
|
|
505
|
+
* @param query - Search filters (see {@link SymbolSearchQuery}). The `project` field is ignored.
|
|
506
|
+
* @returns An array of {@link SymbolSearchResult} entries, or `Err<GildashError>` with
|
|
507
|
+
* `type='closed'` if the instance is closed,
|
|
508
|
+
* `type='search'` if the query fails.
|
|
509
|
+
*/
|
|
510
|
+
searchAllSymbols(query: Omit<SymbolSearchQuery, 'project'> & {
|
|
511
|
+
project?: string;
|
|
512
|
+
}): Result<SymbolSearchResult[], GildashError>;
|
|
513
|
+
/**
|
|
514
|
+
* Search relations across all projects (no project filter).
|
|
515
|
+
*
|
|
516
|
+
* @param query - Search filters (see {@link RelationSearchQuery}). The `project` field is ignored.
|
|
517
|
+
* @returns An array of {@link CodeRelation} entries, or `Err<GildashError>` with
|
|
518
|
+
* `type='closed'` if the instance is closed,
|
|
519
|
+
* `type='search'` if the query fails.
|
|
520
|
+
*/
|
|
521
|
+
searchAllRelations(query: RelationSearchQuery): Result<CodeRelation[], GildashError>;
|
|
522
|
+
/**
|
|
523
|
+
* List all files indexed for a given project.
|
|
524
|
+
*
|
|
525
|
+
* @param project - Project name. Defaults to the primary project.
|
|
526
|
+
* @returns An array of {@link FileRecord} entries, or `Err<GildashError>` with
|
|
527
|
+
* `type='closed'` if the instance is closed,
|
|
528
|
+
* `type='store'` if the repository query fails.
|
|
529
|
+
*/
|
|
530
|
+
listIndexedFiles(project?: string): Result<FileRecord[], GildashError>;
|
|
531
|
+
/**
|
|
532
|
+
* Get all intra-file relations for a given file (relations where both source and destination
|
|
533
|
+
* are within the same file).
|
|
534
|
+
*
|
|
535
|
+
* @param filePath - Path of the file to query.
|
|
536
|
+
* @param project - Project name. Defaults to the primary project.
|
|
537
|
+
* @returns An array of {@link CodeRelation} entries, or `Err<GildashError>` with
|
|
538
|
+
* `type='closed'` if the instance is closed,
|
|
539
|
+
* `type='search'` if the query fails.
|
|
540
|
+
*/
|
|
541
|
+
getInternalRelations(filePath: string, project?: string): Result<CodeRelation[], GildashError>;
|
|
542
|
+
/**
|
|
543
|
+
* Compare two snapshots of symbol search results and return a structured diff.
|
|
544
|
+
*
|
|
545
|
+
* Symbols are keyed by `name::filePath`. A symbol is:
|
|
546
|
+
* - **added** if it appears only in `after`
|
|
547
|
+
* - **removed** if it appears only in `before`
|
|
548
|
+
* - **modified** if it appears in both but with a different `fingerprint`
|
|
549
|
+
* - **unchanged** otherwise
|
|
550
|
+
*
|
|
551
|
+
* @param before - Snapshot of symbols before the change.
|
|
552
|
+
* @param after - Snapshot of symbols after the change.
|
|
553
|
+
* @returns A {@link SymbolDiff} object.
|
|
554
|
+
*/
|
|
555
|
+
diffSymbols(before: SymbolSearchResult[], after: SymbolSearchResult[]): SymbolDiff;
|
|
351
556
|
/**
|
|
352
557
|
* List the files that a given file directly imports.
|
|
353
558
|
*
|
|
@@ -422,6 +627,177 @@ export declare class Gildash {
|
|
|
422
627
|
* ```
|
|
423
628
|
*/
|
|
424
629
|
hasCycle(project?: string): Promise<Result<boolean, GildashError>>;
|
|
630
|
+
/**
|
|
631
|
+
* Return the full import graph for a project as an adjacency list.
|
|
632
|
+
*
|
|
633
|
+
* Builds a {@link DependencyGraph} and exposes its internal adjacency list.
|
|
634
|
+
* Each file appears as a key; its value lists the files it directly imports.
|
|
635
|
+
* Files that are imported but do not themselves import appear as keys with empty arrays.
|
|
636
|
+
*
|
|
637
|
+
* @param project - Project name. Defaults to the primary project.
|
|
638
|
+
* @returns A `Map<filePath, importedFilePaths[]>`, or `Err<GildashError>` with
|
|
639
|
+
* `type='closed'` / `type='search'`.
|
|
640
|
+
*/
|
|
641
|
+
getImportGraph(project?: string): Promise<Result<Map<string, string[]>, GildashError>>;
|
|
642
|
+
/**
|
|
643
|
+
* Return all files that `filePath` transitively imports (forward BFS).
|
|
644
|
+
*
|
|
645
|
+
* @param filePath - Absolute path of the starting file.
|
|
646
|
+
* @param project - Project name. Defaults to the primary project.
|
|
647
|
+
* @returns An array of file paths that `filePath` directly or indirectly imports,
|
|
648
|
+
* or `Err<GildashError>` with `type='closed'` / `type='search'`.
|
|
649
|
+
*/
|
|
650
|
+
getTransitiveDependencies(filePath: string, project?: string): Promise<Result<string[], GildashError>>;
|
|
651
|
+
/**
|
|
652
|
+
* Return all cycle paths in the import graph.
|
|
653
|
+
*
|
|
654
|
+
* Uses DFS with canonical form deduplication.
|
|
655
|
+
*
|
|
656
|
+
* @param project - Project name. Defaults to the primary project.
|
|
657
|
+
* @returns An array of cycle paths (`string[][]`), each starting at the lexicographically
|
|
658
|
+
* smallest node in the cycle. Returns `[]` if no cycles exist.
|
|
659
|
+
* Returns `Err<GildashError>` with `type='closed'` / `type='search'`.
|
|
660
|
+
*/
|
|
661
|
+
getCyclePaths(project?: string): Promise<Result<string[][], GildashError>>;
|
|
662
|
+
/**
|
|
663
|
+
* Find exported symbols that are never imported anywhere in the project.
|
|
664
|
+
*
|
|
665
|
+
* A symbol is considered "dead" if no `imports` or `re-exports` relation in the
|
|
666
|
+
* project references it by name (matching both `dstFilePath` and `dstSymbolName`).
|
|
667
|
+
* Exports from entry-point files are excluded by default.
|
|
668
|
+
*
|
|
669
|
+
* @param project - Project name. Defaults to the primary project.
|
|
670
|
+
* @param opts.entryPoints - File paths whose exports are excluded from dead-export detection.
|
|
671
|
+
* Defaults to files named `index.ts`, `index.mts`, or `main.ts` anywhere in the project.
|
|
672
|
+
* Pass `[]` to disable all entry-point filtering.
|
|
673
|
+
* @returns An array of `{ symbolName, filePath }` for dead exports,
|
|
674
|
+
* or `Err<GildashError>` with `type='closed'` / `type='store'`.
|
|
675
|
+
*/
|
|
676
|
+
getDeadExports(project?: string, opts?: {
|
|
677
|
+
entryPoints?: string[];
|
|
678
|
+
}): Result<Array<{
|
|
679
|
+
symbolName: string;
|
|
680
|
+
filePath: string;
|
|
681
|
+
}>, GildashError>;
|
|
682
|
+
/**
|
|
683
|
+
* Retrieve full details for a named symbol in a specific file,
|
|
684
|
+
* including members, documentation, and type information.
|
|
685
|
+
*
|
|
686
|
+
* @param symbolName - Exact symbol name to look up.
|
|
687
|
+
* @param filePath - Absolute path of the file containing the symbol.
|
|
688
|
+
* @param project - Project scope override (defaults to `defaultProject`).
|
|
689
|
+
* @returns A {@link FullSymbol} on success, or `Err<GildashError>` with
|
|
690
|
+
* `type='closed'` if the instance is closed,
|
|
691
|
+
* `type='search'` if the symbol is not found or the query fails.
|
|
692
|
+
*/
|
|
693
|
+
getFullSymbol(symbolName: string, filePath: string, project?: string): Result<FullSymbol, GildashError>;
|
|
694
|
+
/**
|
|
695
|
+
* Retrieve statistics for an indexed file (line count, symbol count, etc.).
|
|
696
|
+
*
|
|
697
|
+
* @param filePath - Absolute path of the file to query.
|
|
698
|
+
* @param project - Project scope override (defaults to `defaultProject`).
|
|
699
|
+
* @returns A {@link FileStats} on success, or `Err<GildashError>` with
|
|
700
|
+
* `type='closed'` if the instance is closed,
|
|
701
|
+
* `type='search'` if the file is not in the index,
|
|
702
|
+
* `type='store'` if the query throws.
|
|
703
|
+
*/
|
|
704
|
+
getFileStats(filePath: string, project?: string): Result<FileStats, GildashError>;
|
|
705
|
+
/**
|
|
706
|
+
* Compute import-graph fan metrics (fan-in / fan-out) for a single file.
|
|
707
|
+
*
|
|
708
|
+
* Builds a full {@link DependencyGraph} each call (O(relations)).
|
|
709
|
+
* For repeated calls, consider caching the graph externally.
|
|
710
|
+
*
|
|
711
|
+
* @param filePath - Absolute path of the file to query.
|
|
712
|
+
* @param project - Project scope override (defaults to `defaultProject`).
|
|
713
|
+
* @returns A {@link FanMetrics} on success, or `Err<GildashError>` with
|
|
714
|
+
* `type='closed'` if the instance is closed,
|
|
715
|
+
* `type='search'` if the graph build fails.
|
|
716
|
+
*/
|
|
717
|
+
getFanMetrics(filePath: string, project?: string): Promise<Result<FanMetrics, GildashError>>;
|
|
718
|
+
/**
|
|
719
|
+
* Resolve the original definition location of a symbol by following its re-export chain.
|
|
720
|
+
*
|
|
721
|
+
* Traverses `re-exports` relations iteratively until no further hop is found or a
|
|
722
|
+
* circular chain is detected.
|
|
723
|
+
*
|
|
724
|
+
* @param symbolName - The exported name to resolve.
|
|
725
|
+
* @param filePath - The file from which the symbol is exported.
|
|
726
|
+
* @param project - Project scope override (defaults to `defaultProject`).
|
|
727
|
+
* @returns A {@link ResolvedSymbol} on success, or `Err<GildashError>` with
|
|
728
|
+
* `type='closed'` if the instance is closed,
|
|
729
|
+
* `type='search'` if a circular re-export chain is detected.
|
|
730
|
+
*/
|
|
731
|
+
resolveSymbol(symbolName: string, filePath: string, project?: string): Result<ResolvedSymbol, GildashError>;
|
|
732
|
+
/**
|
|
733
|
+
* Search for an AST structural pattern across indexed TypeScript files.
|
|
734
|
+
*
|
|
735
|
+
* Uses ast-grep's `findInFiles` under the hood. Provide `opts.filePaths` to
|
|
736
|
+
* limit search scope; otherwise all files tracked by the project index are searched.
|
|
737
|
+
*
|
|
738
|
+
* @param pattern - ast-grep structural pattern (e.g. `'console.log($$$)'`).
|
|
739
|
+
* @param opts - Optional scope: file paths and/or project override.
|
|
740
|
+
* @returns An array of {@link PatternMatch} on success, or `Err<GildashError>` with
|
|
741
|
+
* `type='closed'` if the instance is closed,
|
|
742
|
+
* `type='search'` if the underlying search fails.
|
|
743
|
+
*/
|
|
744
|
+
findPattern(pattern: string, opts?: {
|
|
745
|
+
filePaths?: string[];
|
|
746
|
+
project?: string;
|
|
747
|
+
}): Promise<Result<PatternMatch[], GildashError>>;
|
|
748
|
+
/**
|
|
749
|
+
* Index the TypeScript type declarations (`.d.ts` files) of one or more
|
|
750
|
+
* `node_modules` packages.
|
|
751
|
+
*
|
|
752
|
+
* Each package is indexed under a dedicated `@external/<packageName>` project
|
|
753
|
+
* so it does not pollute the main project index. Subsequent calls re-index
|
|
754
|
+
* (incremental diff) the same package.
|
|
755
|
+
*
|
|
756
|
+
* @param packages - Package names as they appear in `node_modules/`
|
|
757
|
+
* (e.g. `['react', 'typescript']`).
|
|
758
|
+
* @param opts - Optional overrides (unused currently, reserved for future use).
|
|
759
|
+
* @returns An array of {@link IndexResult} — one per package — on success,
|
|
760
|
+
* or `Err<GildashError>` with:
|
|
761
|
+
* - `type='closed'` if the instance is closed or in reader mode,
|
|
762
|
+
* - `type='validation'` if a requested package is not found in `node_modules/`,
|
|
763
|
+
* - `type='store'` if indexing fails at runtime.
|
|
764
|
+
*/
|
|
765
|
+
indexExternalPackages(packages: string[], opts?: {
|
|
766
|
+
project?: string;
|
|
767
|
+
}): Promise<Result<IndexResult[], GildashError>>;
|
|
768
|
+
/**
|
|
769
|
+
* Parse multiple files concurrently and return a map of results.
|
|
770
|
+
*
|
|
771
|
+
* Files that fail to read or parse are silently excluded from the result map.
|
|
772
|
+
* The operation does not fail even if every file fails — it returns an empty `Map`.
|
|
773
|
+
*
|
|
774
|
+
* @param filePaths - Absolute paths of files to parse.
|
|
775
|
+
* @returns A `Map<filePath, ParsedFile>` for every successfully-parsed file,
|
|
776
|
+
* or `Err<GildashError>` with `type='closed'` if the instance is closed.
|
|
777
|
+
*/
|
|
778
|
+
batchParse(filePaths: string[]): Promise<Result<Map<string, ParsedFile>, GildashError>>;
|
|
779
|
+
/**
|
|
780
|
+
* Return the public interface of a module: all exported symbols with key metadata.
|
|
781
|
+
*
|
|
782
|
+
* @param filePath - Absolute path of the file.
|
|
783
|
+
* @param project - Project name. Defaults to the primary project.
|
|
784
|
+
* @returns A {@link ModuleInterface} object, or `Err<GildashError>` with
|
|
785
|
+
* `type='closed'` / `type='search'`.
|
|
786
|
+
*/
|
|
787
|
+
getModuleInterface(filePath: string, project?: string): Result<ModuleInterface, GildashError>;
|
|
788
|
+
/**
|
|
789
|
+
* Recursively traverse `extends`/`implements` relations to build a heritage tree.
|
|
790
|
+
*
|
|
791
|
+
* The root node represents `symbolName`/`filePath`. Its `children` are the symbols
|
|
792
|
+
* it extends or implements, and so on transitively. A visited set prevents cycles.
|
|
793
|
+
*
|
|
794
|
+
* @param symbolName - Name of the starting symbol.
|
|
795
|
+
* @param filePath - Absolute path of the file containing the symbol.
|
|
796
|
+
* @param project - Project name. Defaults to the primary project.
|
|
797
|
+
* @returns A {@link HeritageNode} tree, or `Err<GildashError>` with
|
|
798
|
+
* `type='closed'` / `type='search'`.
|
|
799
|
+
*/
|
|
800
|
+
getHeritageChain(symbolName: string, filePath: string, project?: string): Promise<Result<HeritageNode, GildashError>>;
|
|
425
801
|
/**
|
|
426
802
|
* Retrieve a previously-parsed AST from the internal LRU cache.
|
|
427
803
|
*
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Gildash } from "./gildash";
|
|
2
|
-
export type { GildashOptions, Logger } from "./gildash";
|
|
2
|
+
export type { GildashOptions, Logger, SymbolDiff, ModuleInterface, HeritageNode, FullSymbol, FileStats, FanMetrics, ResolvedSymbol } from "./gildash";
|
|
3
3
|
export { gildashError } from "./errors";
|
|
4
4
|
export type { GildashError, GildashErrorType } from "./errors";
|
|
5
5
|
export { symbolSearch } from "./search/symbol-search";
|
|
@@ -7,6 +7,8 @@ export type { SymbolSearchQuery, SymbolSearchResult } from "./search/symbol-sear
|
|
|
7
7
|
export { relationSearch } from "./search/relation-search";
|
|
8
8
|
export type { RelationSearchQuery } from "./search/relation-search";
|
|
9
9
|
export { DependencyGraph } from "./search/dependency-graph";
|
|
10
|
+
export { patternSearch } from "./search/pattern-search";
|
|
11
|
+
export type { PatternMatch, PatternSearchOptions } from "./search/pattern-search";
|
|
10
12
|
export type { IndexResult } from "./indexer/index-coordinator";
|
|
11
13
|
export type { ProjectBoundary } from "./common/project-discovery";
|
|
12
14
|
export type { CodeRelation, SymbolKind } from "./extractor/types";
|
|
@@ -31,6 +31,27 @@ export interface IndexResult {
|
|
|
31
31
|
deletedFiles: string[];
|
|
32
32
|
/** Absolute paths of files that failed to index. */
|
|
33
33
|
failedFiles: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Symbol-level diff compared to the previous index state.
|
|
36
|
+
* On the very first full index (empty DB), all symbols appear in `added`.
|
|
37
|
+
*/
|
|
38
|
+
changedSymbols: {
|
|
39
|
+
added: Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
filePath: string;
|
|
42
|
+
kind: string;
|
|
43
|
+
}>;
|
|
44
|
+
modified: Array<{
|
|
45
|
+
name: string;
|
|
46
|
+
filePath: string;
|
|
47
|
+
kind: string;
|
|
48
|
+
}>;
|
|
49
|
+
removed: Array<{
|
|
50
|
+
name: string;
|
|
51
|
+
filePath: string;
|
|
52
|
+
kind: string;
|
|
53
|
+
}>;
|
|
54
|
+
};
|
|
34
55
|
}
|
|
35
56
|
export interface IndexCoordinatorOptions {
|
|
36
57
|
projectRoot: string;
|
|
@@ -68,4 +68,32 @@ export declare class DependencyGraph {
|
|
|
68
68
|
* @returns Paths of all transitively-dependent files.
|
|
69
69
|
*/
|
|
70
70
|
getAffectedByChange(changedFiles: string[]): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Return the full import graph as an adjacency list.
|
|
73
|
+
*
|
|
74
|
+
* Each key is a file path (both source and destination files are included as keys).
|
|
75
|
+
* The associated value lists the files it directly imports.
|
|
76
|
+
*
|
|
77
|
+
* @returns A new `Map<filePath, importedFilePaths[]>`.
|
|
78
|
+
*/
|
|
79
|
+
getAdjacencyList(): Map<string, string[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Return all files that `filePath` transitively imports
|
|
82
|
+
* (breadth-first forward walk).
|
|
83
|
+
*
|
|
84
|
+
* @param filePath - Absolute file path.
|
|
85
|
+
* @returns Paths of all transitively-imported files. Does not include `filePath` itself
|
|
86
|
+
* unless a cycle exists.
|
|
87
|
+
*/
|
|
88
|
+
getTransitiveDependencies(filePath: string): string[];
|
|
89
|
+
/**
|
|
90
|
+
* Return the distinct cycle paths in the import graph.
|
|
91
|
+
*
|
|
92
|
+
* Each cycle is represented as a list of file paths in canonical form
|
|
93
|
+
* (rotated so the lexicographically smallest node comes first).
|
|
94
|
+
* Duplicate cycles are deduplicated.
|
|
95
|
+
*
|
|
96
|
+
* @returns An array of cycles, where each cycle is a `string[]` of file paths.
|
|
97
|
+
*/
|
|
98
|
+
getCyclePaths(): string[][];
|
|
71
99
|
}
|
|
@@ -4,3 +4,5 @@ export { relationSearch } from './relation-search';
|
|
|
4
4
|
export type { RelationSearchQuery, IRelationRepo } from './relation-search';
|
|
5
5
|
export { DependencyGraph } from './dependency-graph';
|
|
6
6
|
export type { IDependencyGraphRepo } from './dependency-graph';
|
|
7
|
+
export { patternSearch } from './pattern-search';
|
|
8
|
+
export type { PatternMatch, PatternSearchOptions } from './pattern-search';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single structural-pattern match found in a source file.
|
|
3
|
+
*/
|
|
4
|
+
export interface PatternMatch {
|
|
5
|
+
/** Absolute path of the file containing the match. */
|
|
6
|
+
filePath: string;
|
|
7
|
+
/** 1-based start line number of the matched node. */
|
|
8
|
+
startLine: number;
|
|
9
|
+
/** 1-based end line number of the matched node. */
|
|
10
|
+
endLine: number;
|
|
11
|
+
/** Source text of the matched node. */
|
|
12
|
+
matchedText: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Options for {@link patternSearch}.
|
|
16
|
+
*/
|
|
17
|
+
export interface PatternSearchOptions {
|
|
18
|
+
/** An ast-grep structural pattern string (e.g. `'console.log($$$)'`). */
|
|
19
|
+
pattern: string;
|
|
20
|
+
/** Absolute file paths (or directories) to search within. */
|
|
21
|
+
filePaths: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Search for a structural AST pattern across a set of TypeScript/TSX files
|
|
25
|
+
* using ast-grep's `findInFiles` API.
|
|
26
|
+
*
|
|
27
|
+
* @param opts - Pattern and file paths to search.
|
|
28
|
+
* @returns An array of {@link PatternMatch} entries for all matching nodes.
|
|
29
|
+
*/
|
|
30
|
+
export declare function patternSearch(opts: PatternSearchOptions): Promise<PatternMatch[]>;
|
|
@@ -20,6 +20,16 @@ export interface SymbolSearchQuery {
|
|
|
20
20
|
project?: string;
|
|
21
21
|
/** Maximum number of results. Defaults to `100`. */
|
|
22
22
|
limit?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Filter by decorator name (LEG-1).
|
|
25
|
+
* Restricts results to symbols annotated with this decorator (matched against `detailJson.decorators[].name`).
|
|
26
|
+
*/
|
|
27
|
+
decorator?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Filter by regex pattern applied to the symbol name (FR-19).
|
|
30
|
+
* Requires the `REGEXP` SQL function to be registered in the DB connection.
|
|
31
|
+
*/
|
|
32
|
+
regex?: string;
|
|
23
33
|
}
|
|
24
34
|
/**
|
|
25
35
|
* A single result returned by {@link symbolSearch}.
|
|
@@ -62,6 +72,8 @@ export interface ISymbolRepo {
|
|
|
62
72
|
isExported?: boolean;
|
|
63
73
|
project?: string;
|
|
64
74
|
limit: number;
|
|
75
|
+
decorator?: string;
|
|
76
|
+
regex?: string;
|
|
65
77
|
}): (SymbolRecord & {
|
|
66
78
|
id: number;
|
|
67
79
|
})[];
|
|
@@ -18,6 +18,8 @@ export interface FileRecord {
|
|
|
18
18
|
contentHash: string;
|
|
19
19
|
/** ISO 8601 timestamp of the last index update. */
|
|
20
20
|
updatedAt: string;
|
|
21
|
+
/** Number of lines in the file at the time of indexing. */
|
|
22
|
+
lineCount?: number | null;
|
|
21
23
|
}
|
|
22
24
|
export declare class FileRepository {
|
|
23
25
|
private readonly db;
|