@zipbul/gildash 0.0.1

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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.ko.md +386 -0
  3. package/README.md +445 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +2736 -0
  6. package/dist/index.js.map +42 -0
  7. package/dist/migrations/0000_soft_revanche.sql +56 -0
  8. package/dist/migrations/meta/0000_snapshot.json +408 -0
  9. package/dist/migrations/meta/_journal.json +13 -0
  10. package/dist/migrations/migrations/0000_soft_revanche.sql +56 -0
  11. package/dist/migrations/migrations/meta/0000_snapshot.json +408 -0
  12. package/dist/migrations/migrations/meta/_journal.json +13 -0
  13. package/dist/src/codeledger.d.ts +103 -0
  14. package/dist/src/common/hasher.d.ts +2 -0
  15. package/dist/src/common/index.d.ts +5 -0
  16. package/dist/src/common/lru-cache.d.ts +10 -0
  17. package/dist/src/common/path-utils.d.ts +2 -0
  18. package/dist/src/common/project-discovery.d.ts +6 -0
  19. package/dist/src/common/tsconfig-resolver.d.ts +6 -0
  20. package/dist/src/errors.d.ts +42 -0
  21. package/dist/src/extractor/calls-extractor.d.ts +3 -0
  22. package/dist/src/extractor/extractor-utils.d.ts +5 -0
  23. package/dist/src/extractor/heritage-extractor.d.ts +3 -0
  24. package/dist/src/extractor/imports-extractor.d.ts +4 -0
  25. package/dist/src/extractor/index.d.ts +7 -0
  26. package/dist/src/extractor/relation-extractor.d.ts +4 -0
  27. package/dist/src/extractor/symbol-extractor.d.ts +3 -0
  28. package/dist/src/extractor/types.d.ts +162 -0
  29. package/dist/src/gildash.d.ts +284 -0
  30. package/dist/src/index.d.ts +8 -0
  31. package/dist/src/indexer/file-indexer.d.ts +27 -0
  32. package/dist/src/indexer/index-coordinator.d.ts +80 -0
  33. package/dist/src/indexer/index.d.ts +8 -0
  34. package/dist/src/indexer/relation-indexer.d.ts +24 -0
  35. package/dist/src/indexer/symbol-indexer.d.ts +29 -0
  36. package/dist/src/parser/ast-utils.d.ts +10 -0
  37. package/dist/src/parser/index.d.ts +6 -0
  38. package/dist/src/parser/jsdoc-parser.d.ts +2 -0
  39. package/dist/src/parser/parse-cache.d.ts +10 -0
  40. package/dist/src/parser/parse-source.d.ts +3 -0
  41. package/dist/src/parser/source-position.d.ts +3 -0
  42. package/dist/src/parser/types.d.ts +16 -0
  43. package/dist/src/search/dependency-graph.d.ts +71 -0
  44. package/dist/src/search/index.d.ts +6 -0
  45. package/dist/src/search/relation-search.d.ts +45 -0
  46. package/dist/src/search/symbol-search.d.ts +76 -0
  47. package/dist/src/store/connection.d.ts +30 -0
  48. package/dist/src/store/index.d.ts +10 -0
  49. package/dist/src/store/repositories/file.repository.d.ts +18 -0
  50. package/dist/src/store/repositories/fts-utils.d.ts +1 -0
  51. package/dist/src/store/repositories/relation.repository.d.ts +29 -0
  52. package/dist/src/store/repositories/symbol.repository.d.ts +46 -0
  53. package/dist/src/store/schema.d.ts +634 -0
  54. package/dist/src/watcher/index.d.ts +3 -0
  55. package/dist/src/watcher/ownership.d.ts +22 -0
  56. package/dist/src/watcher/project-watcher.d.ts +13 -0
  57. package/dist/src/watcher/types.d.ts +11 -0
  58. package/package.json +58 -0
@@ -0,0 +1,162 @@
1
+ import type { SourcePosition, SourceSpan } from '../parser/types';
2
+ /**
3
+ * The kind of a symbol extracted from TypeScript source.
4
+ *
5
+ * - `'function'` — standalone function declarations and expressions
6
+ * - `'method'` — class methods, getters, setters, and constructors
7
+ * - `'class'` — class declarations
8
+ * - `'variable'` — `const`, `let`, `var` declarations
9
+ * - `'type'` — type alias declarations
10
+ * - `'interface'` — interface declarations
11
+ * - `'enum'` — enum declarations
12
+ * - `'property'` — class properties and interface/type members
13
+ */
14
+ export type SymbolKind = 'function' | 'method' | 'class' | 'variable' | 'type' | 'interface' | 'enum' | 'property';
15
+ /**
16
+ * TypeScript declaration modifiers attached to a symbol.
17
+ */
18
+ export type Modifier = 'async' | 'static' | 'abstract' | 'readonly' | 'private' | 'protected' | 'public' | 'override' | 'declare' | 'const';
19
+ /**
20
+ * A function/method parameter.
21
+ */
22
+ export interface Parameter {
23
+ /** Parameter name. */
24
+ name: string;
25
+ /** Type annotation as raw source text, e.g. `"string"`, `"number[]"`. */
26
+ type?: string;
27
+ /** Whether the parameter is optional (has `?` or a default value). */
28
+ isOptional: boolean;
29
+ /** Default value expression as source text. */
30
+ defaultValue?: string;
31
+ /** Decorators applied to this parameter (e.g. `@Inject`, `@Body`). */
32
+ decorators?: Decorator[];
33
+ }
34
+ /**
35
+ * A class/interface heritage clause (`extends` or `implements`).
36
+ */
37
+ export interface Heritage {
38
+ /** Whether this is an `extends` or `implements` clause. */
39
+ kind: 'extends' | 'implements';
40
+ /** Name of the base class or implemented interface. */
41
+ name: string;
42
+ /** Generic type arguments, e.g. `['T', 'U']`. */
43
+ typeArguments?: string[];
44
+ }
45
+ /**
46
+ * A decorator applied to a class, method, property, or parameter.
47
+ */
48
+ export interface Decorator {
49
+ /** Decorator name without `@`. */
50
+ name: string;
51
+ /** Decorator call arguments as source text. */
52
+ arguments?: string[];
53
+ }
54
+ /**
55
+ * A single JSDoc tag parsed from a documentation comment.
56
+ *
57
+ * @example
58
+ * For `@param name - The user's name`:
59
+ * ```ts
60
+ * { tag: 'param', name: 'name', type: '', description: "The user's name", optional: false }
61
+ * ```
62
+ */
63
+ export interface JsDocTag {
64
+ /** Tag name without `@` (e.g. `'param'`, `'returns'`, `'deprecated'`). */
65
+ tag: string;
66
+ /** First word after the tag, typically a parameter name for `@param`. */
67
+ name: string;
68
+ /** Type in curly braces (e.g. `'{string}'` → `'string'`). Empty if absent. */
69
+ type: string;
70
+ /** Description text following the name. */
71
+ description: string;
72
+ /** `true` if the name is wrapped in `[brackets]` (optional parameter). */
73
+ optional: boolean;
74
+ /** Default value if `[name=default]` syntax is used. */
75
+ default?: string;
76
+ }
77
+ /**
78
+ * A parsed JSDoc documentation comment block.
79
+ */
80
+ export interface JsDocBlock {
81
+ /** Full description text before any tags. */
82
+ description: string;
83
+ /** Parsed `@tag` entries. */
84
+ tags: JsDocTag[];
85
+ }
86
+ /**
87
+ * A symbol extracted from a TypeScript source file.
88
+ *
89
+ * Represents a single named declaration (function, class, variable, type, etc.)
90
+ * with its location, metadata, and optional nested members.
91
+ */
92
+ export interface ExtractedSymbol {
93
+ /** What kind of symbol this is. */
94
+ kind: SymbolKind;
95
+ /** Symbol name (e.g. `'MyClass'`, `'handleClick'`). */
96
+ name: string;
97
+ /** Source location (start/end line and column). */
98
+ span: SourceSpan;
99
+ /** Whether this symbol is exported from its module. */
100
+ isExported: boolean;
101
+ /** For methods: distinguishes `'method'`, `'getter'`, `'setter'`, or `'constructor'`. */
102
+ methodKind?: 'method' | 'getter' | 'setter' | 'constructor';
103
+ /** Function/method parameters. Present for functions, methods, and constructors. */
104
+ parameters?: Parameter[];
105
+ /** Return type annotation as source text. */
106
+ returnType?: string;
107
+ /** Generic type parameter names (e.g. `['T', 'U extends Foo']`). */
108
+ typeParameters?: string[];
109
+ /** Declaration modifiers (e.g. `async`, `static`, `readonly`). */
110
+ modifiers: Modifier[];
111
+ /** Heritage clauses (`extends` / `implements`). Present for classes and interfaces. */
112
+ heritage?: Heritage[];
113
+ /** Decorators applied to this symbol. */
114
+ decorators?: Decorator[];
115
+ /** Nested members (class fields, methods, interface properties, enum members). */
116
+ members?: ExtractedSymbol[];
117
+ /** Parsed JSDoc comment associated with this symbol. */
118
+ jsDoc?: JsDocBlock;
119
+ }
120
+ /**
121
+ * A dot-separated qualified name (e.g. `a.b.c`).
122
+ */
123
+ export interface QualifiedName {
124
+ /** Leftmost identifier (e.g. `'a'` in `'a.b.c'`). */
125
+ root: string;
126
+ /** Subsequent parts (e.g. `['b', 'c']`). */
127
+ parts: string[];
128
+ /** Full joined string (e.g. `'a.b.c'`). */
129
+ full: string;
130
+ }
131
+ /**
132
+ * An import reference resolved from an import statement.
133
+ */
134
+ export interface ImportReference {
135
+ /** Resolved absolute path of the imported module. */
136
+ path: string;
137
+ /** The imported name: `'default'` for default imports, `'*'` for namespace, or the named identifier. */
138
+ importedName: string;
139
+ }
140
+ /**
141
+ * A relationship between two symbols/files extracted from source code.
142
+ *
143
+ * - `'imports'` — file A imports from file B
144
+ * - `'calls'` — symbol in file A calls a symbol in file B
145
+ * - `'extends'` — class/interface in file A extends one in file B
146
+ * - `'implements'` — class in file A implements an interface in file B
147
+ */
148
+ export interface CodeRelation {
149
+ /** The kind of relationship. */
150
+ type: 'imports' | 'calls' | 'extends' | 'implements';
151
+ /** File path where the relationship originates. */
152
+ srcFilePath: string;
153
+ /** Source symbol name, or `null` for module-level relationships. */
154
+ srcSymbolName: string | null;
155
+ /** File path of the target. */
156
+ dstFilePath: string;
157
+ /** Target symbol name, or `null` for module-level imports. */
158
+ dstSymbolName: string | null;
159
+ /** Optional JSON-encoded metadata about the relation. */
160
+ metaJson?: string;
161
+ }
162
+ export type { SourcePosition, SourceSpan };
@@ -0,0 +1,284 @@
1
+ import type { ParsedFile } from './parser/types';
2
+ import { parseSource as defaultParseSource } from './parser/parse-source';
3
+ import { ParseCache } from './parser/parse-cache';
4
+ import type { ExtractedSymbol } from './extractor/types';
5
+ import { extractSymbols as defaultExtractSymbols } from './extractor/symbol-extractor';
6
+ import { extractRelations as defaultExtractRelations } from './extractor/relation-extractor';
7
+ import type { CodeRelation } from './extractor/types';
8
+ import { DbConnection } from './store/connection';
9
+ import { FileRepository } from './store/repositories/file.repository';
10
+ import { SymbolRepository } from './store/repositories/symbol.repository';
11
+ import { RelationRepository } from './store/repositories/relation.repository';
12
+ import { ProjectWatcher } from './watcher/project-watcher';
13
+ import { IndexCoordinator } from './indexer/index-coordinator';
14
+ import type { IndexResult } from './indexer/index-coordinator';
15
+ import type { FileChangeEvent } from './watcher/types';
16
+ import { acquireWatcherRole, releaseWatcherRole, updateHeartbeat } from './watcher/ownership';
17
+ import type { WatcherOwnerStore } from './watcher/ownership';
18
+ import { discoverProjects } from './common/project-discovery';
19
+ import type { ProjectBoundary } from './common/project-discovery';
20
+ import { loadTsconfigPaths } from './common/tsconfig-resolver';
21
+ import type { TsconfigPaths } from './common/tsconfig-resolver';
22
+ import { symbolSearch as defaultSymbolSearch } from './search/symbol-search';
23
+ import type { SymbolSearchQuery, SymbolSearchResult } from './search/symbol-search';
24
+ import { relationSearch as defaultRelationSearch } from './search/relation-search';
25
+ import type { RelationSearchQuery } from './search/relation-search';
26
+ import type { SymbolStats } from './store/repositories/symbol.repository';
27
+ /**
28
+ * Minimal logger interface accepted by {@link Gildash}.
29
+ *
30
+ * Any object with an `error` method (including `console`) satisfies this interface.
31
+ */
32
+ export interface Logger {
33
+ /** Log one or more error-level messages. */
34
+ error(...args: unknown[]): void;
35
+ }
36
+ /**
37
+ * Options for creating a {@link Gildash} instance via {@link Gildash.open}.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const ledger = await Gildash.open({
42
+ * projectRoot: '/absolute/path/to/project',
43
+ * extensions: ['.ts', '.tsx'],
44
+ * ignorePatterns: ['vendor'],
45
+ * });
46
+ * ```
47
+ */
48
+ export interface GildashOptions {
49
+ /** Absolute path to the project root directory. */
50
+ projectRoot: string;
51
+ /** File extensions to index. Defaults to `['.ts', '.mts', '.cts']`. */
52
+ extensions?: string[];
53
+ /** Glob patterns to ignore during indexing. */
54
+ ignorePatterns?: string[];
55
+ /** Maximum number of parsed ASTs to keep in the LRU cache. Defaults to `500`. */
56
+ parseCacheCapacity?: number;
57
+ /** Logger for error output. Defaults to `console`. */
58
+ logger?: Logger;
59
+ }
60
+ interface GildashInternalOptions {
61
+ existsSyncFn?: (p: string) => boolean;
62
+ dbConnectionFactory?: () => Pick<DbConnection, 'open' | 'close' | 'transaction'> & WatcherOwnerStore;
63
+ watcherFactory?: () => Pick<ProjectWatcher, 'start' | 'close'>;
64
+ coordinatorFactory?: () => Pick<IndexCoordinator, 'fullIndex' | 'shutdown' | 'onIndexed'> & {
65
+ tsconfigPaths?: Promise<TsconfigPaths | null>;
66
+ handleWatcherEvent?(event: FileChangeEvent): void;
67
+ };
68
+ repositoryFactory?: () => {
69
+ fileRepo: Pick<FileRepository, 'upsertFile' | 'getAllFiles' | 'getFilesMap' | 'deleteFile'>;
70
+ symbolRepo: SymbolRepository;
71
+ relationRepo: RelationRepository;
72
+ parseCache: Pick<ParseCache, 'set' | 'get' | 'invalidate'>;
73
+ };
74
+ acquireWatcherRoleFn?: typeof acquireWatcherRole;
75
+ releaseWatcherRoleFn?: typeof releaseWatcherRole;
76
+ updateHeartbeatFn?: typeof updateHeartbeat;
77
+ discoverProjectsFn?: typeof discoverProjects;
78
+ parseSourceFn?: typeof defaultParseSource;
79
+ extractSymbolsFn?: typeof defaultExtractSymbols;
80
+ extractRelationsFn?: typeof defaultExtractRelations;
81
+ symbolSearchFn?: typeof defaultSymbolSearch;
82
+ relationSearchFn?: typeof defaultRelationSearch;
83
+ loadTsconfigPathsFn?: typeof loadTsconfigPaths;
84
+ }
85
+ /**
86
+ * Main entry point for gildash.
87
+ *
88
+ * `Gildash` indexes TypeScript source code into a local SQLite database,
89
+ * watches for file changes, and provides search / dependency-graph queries.
90
+ *
91
+ * Create an instance with the static {@link Gildash.open} factory.
92
+ * Always call {@link Gildash.close} when done to release resources.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { Gildash } from '@zipbul/gildash';
97
+ *
98
+ * const ledger = await Gildash.open({ projectRoot: '/my/project' });
99
+ * const symbols = ledger.searchSymbols({ text: 'handle', kind: 'function' });
100
+ * await ledger.close();
101
+ * ```
102
+ */
103
+ export declare class Gildash {
104
+ /** Absolute path to the indexed project root. */
105
+ readonly projectRoot: string;
106
+ private readonly db;
107
+ private readonly symbolRepo;
108
+ private readonly relationRepo;
109
+ private readonly parseCache;
110
+ private coordinator;
111
+ private watcher;
112
+ private readonly releaseWatcherRoleFn;
113
+ private readonly parseSourceFn;
114
+ private readonly extractSymbolsFn;
115
+ private readonly extractRelationsFn;
116
+ private readonly symbolSearchFn;
117
+ private readonly relationSearchFn;
118
+ private readonly logger;
119
+ private readonly defaultProject;
120
+ private readonly role;
121
+ private timer;
122
+ private signalHandlers;
123
+ private closed;
124
+ private tsconfigPaths;
125
+ private boundaries;
126
+ private readonly onIndexedCallbacks;
127
+ private constructor();
128
+ /**
129
+ * Create and initialise a new `Gildash` instance.
130
+ *
131
+ * Opens (or creates) a SQLite database alongside the project root,
132
+ * discovers sub-projects, acquires a watcher role, performs initial indexing,
133
+ * and begins watching for file changes.
134
+ *
135
+ * @param options - Configuration for the instance.
136
+ * @returns A fully-initialised `Gildash` ready for queries.
137
+ * @throws {Error} If `projectRoot` is not absolute or does not exist.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const ledger = await Gildash.open({
142
+ * projectRoot: '/home/user/my-app',
143
+ * extensions: ['.ts', '.tsx'],
144
+ * });
145
+ * ```
146
+ */
147
+ static open(options: GildashOptions & GildashInternalOptions): Promise<Gildash>;
148
+ /**
149
+ * Shut down the instance and release all resources.
150
+ *
151
+ * Stops the file watcher, shuts down the index coordinator,
152
+ * releases the watcher ownership role, and closes the database.
153
+ * Calling `close()` more than once is safe (subsequent calls are no-ops).
154
+ *
155
+ * @throws {AggregateError} If one or more sub-systems fail during shutdown.
156
+ */
157
+ close(): Promise<void>;
158
+ /**
159
+ * Register a callback that fires after each indexing run completes.
160
+ *
161
+ * @param callback - Receives the {@link IndexResult} for the completed run.
162
+ * @returns An unsubscribe function. Call it to remove the listener.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * const off = ledger.onIndexed(result => {
167
+ * console.log(`Indexed ${result.filesProcessed} files`);
168
+ * });
169
+ * // later…
170
+ * off();
171
+ * ```
172
+ */
173
+ onIndexed(callback: (result: IndexResult) => void): () => void;
174
+ /**
175
+ * Parse a TypeScript source string into an AST and cache the result.
176
+ *
177
+ * @param filePath - File path used as the cache key and for diagnostics.
178
+ * @param sourceText - Raw TypeScript source code.
179
+ * @returns The parsed file representation.
180
+ * @throws {Error} If the instance is closed.
181
+ */
182
+ parseSource(filePath: string, sourceText: string): ParsedFile;
183
+ /**
184
+ * Extract all symbol declarations from a previously parsed file.
185
+ *
186
+ * @param parsed - A {@link ParsedFile} obtained from {@link parseSource}.
187
+ * @returns An array of {@link ExtractedSymbol} entries.
188
+ * @throws {Error} If the instance is closed.
189
+ */
190
+ extractSymbols(parsed: ParsedFile): ExtractedSymbol[];
191
+ /**
192
+ * Extract inter-file relationships (imports, calls, extends, implements)
193
+ * from a previously parsed file.
194
+ *
195
+ * @param parsed - A {@link ParsedFile} obtained from {@link parseSource}.
196
+ * @returns An array of {@link CodeRelation} entries.
197
+ * @throws {Error} If the instance is closed.
198
+ */
199
+ extractRelations(parsed: ParsedFile): CodeRelation[];
200
+ /**
201
+ * Trigger a full re-index of all tracked files.
202
+ *
203
+ * Only available to the instance that holds the *owner* role.
204
+ *
205
+ * @returns The indexing result summary.
206
+ * @throws {Error} If the instance is closed or is a reader.
207
+ */
208
+ reindex(): Promise<IndexResult>;
209
+ /**
210
+ * Discovered project boundaries within the project root.
211
+ *
212
+ * Each entry contains a project name and its root directory.
213
+ */
214
+ get projects(): ProjectBoundary[];
215
+ /**
216
+ * Return aggregate symbol statistics for the given project.
217
+ *
218
+ * @param project - Project name. Defaults to the auto-discovered primary project.
219
+ * @returns Counts grouped by symbol kind.
220
+ * @throws {Error} If the instance is closed.
221
+ */
222
+ getStats(project?: string): SymbolStats;
223
+ /**
224
+ * Search indexed symbols by name, kind, file path, or export status.
225
+ *
226
+ * @param query - Search filters. All fields are optional; omitted fields match everything.
227
+ * @returns Matching {@link SymbolSearchResult} entries.
228
+ * @throws {Error} If the instance is closed.
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * const fns = ledger.searchSymbols({ kind: 'function', isExported: true });
233
+ * ```
234
+ */
235
+ searchSymbols(query: SymbolSearchQuery): SymbolSearchResult[];
236
+ /**
237
+ * Search indexed code relationships (imports, calls, extends, implements).
238
+ *
239
+ * @param query - Search filters. All fields are optional.
240
+ * @returns Matching {@link CodeRelation} entries.
241
+ * @throws {Error} If the instance is closed.
242
+ */
243
+ searchRelations(query: RelationSearchQuery): CodeRelation[];
244
+ /**
245
+ * List the files that a given file directly imports.
246
+ *
247
+ * @param filePath - Absolute path of the source file.
248
+ * @param project - Project name. Defaults to the primary project.
249
+ * @param limit - Maximum results. Defaults to `10_000`.
250
+ * @returns Absolute paths of imported files.
251
+ * @throws {Error} If the instance is closed.
252
+ */
253
+ getDependencies(filePath: string, project?: string, limit?: number): string[];
254
+ /**
255
+ * List the files that directly import a given file.
256
+ *
257
+ * @param filePath - Absolute path of the target file.
258
+ * @param project - Project name. Defaults to the primary project.
259
+ * @param limit - Maximum results. Defaults to `10_000`.
260
+ * @returns Absolute paths of files that import the target.
261
+ * @throws {Error} If the instance is closed.
262
+ */
263
+ getDependents(filePath: string, project?: string, limit?: number): string[];
264
+ /**
265
+ * Compute the full set of files transitively affected by changes.
266
+ *
267
+ * Builds a dependency graph and walks all reverse edges from each changed file.
268
+ *
269
+ * @param changedFiles - Absolute paths of files that changed.
270
+ * @param project - Project name. Defaults to the primary project.
271
+ * @returns Paths of all transitively-dependent files (excludes the changed files themselves).
272
+ * @throws {Error} If the instance is closed.
273
+ */
274
+ getAffected(changedFiles: string[], project?: string): Promise<string[]>;
275
+ /**
276
+ * Check whether the import graph contains a circular dependency.
277
+ *
278
+ * @param project - Project name. Defaults to the primary project.
279
+ * @returns `true` if at least one cycle exists.
280
+ * @throws {Error} If the instance is closed.
281
+ */
282
+ hasCycle(project?: string): Promise<boolean>;
283
+ }
284
+ export {};
@@ -0,0 +1,8 @@
1
+ export { Gildash } from "./gildash";
2
+ export type { GildashOptions, Logger } from "./gildash";
3
+ export { GildashError, WatcherError, ParseError, ExtractError, IndexError, StoreError, SearchError, } from "./errors";
4
+ export { symbolSearch } from "./search/symbol-search";
5
+ export type { SymbolSearchQuery, SymbolSearchResult } from "./search/symbol-search";
6
+ export { relationSearch } from "./search/relation-search";
7
+ export type { RelationSearchQuery } from "./search/relation-search";
8
+ export { DependencyGraph } from "./search/dependency-graph";
@@ -0,0 +1,27 @@
1
+ export interface FileChangeRecord {
2
+ filePath: string;
3
+ contentHash: string;
4
+ mtimeMs: number;
5
+ size: number;
6
+ }
7
+ export interface DetectChangesResult {
8
+ changed: FileChangeRecord[];
9
+ unchanged: FileChangeRecord[];
10
+ deleted: string[];
11
+ }
12
+ interface FileRepoPart {
13
+ getFilesMap(): Map<string, {
14
+ filePath: string;
15
+ mtimeMs: number;
16
+ size: number;
17
+ contentHash: string;
18
+ }>;
19
+ }
20
+ export interface DetectChangesOptions {
21
+ projectRoot: string;
22
+ extensions: string[];
23
+ ignorePatterns: string[];
24
+ fileRepo: FileRepoPart;
25
+ }
26
+ export declare function detectChanges(opts: DetectChangesOptions): Promise<DetectChangesResult>;
27
+ export {};
@@ -0,0 +1,80 @@
1
+ import type { FileChangeEvent } from '../watcher/types';
2
+ import type { ProjectBoundary } from '../common/project-discovery';
3
+ import { discoverProjects } from '../common/project-discovery';
4
+ import type { TsconfigPaths } from '../common/tsconfig-resolver';
5
+ import { parseSource } from '../parser/parse-source';
6
+ import type { DbConnection } from '../store/connection';
7
+ import type { FileRecord } from '../store/repositories/file.repository';
8
+ import type { SymbolRecord } from '../store/repositories/symbol.repository';
9
+ import type { RelationRecord } from '../store/repositories/relation.repository';
10
+ import type { Logger } from '../gildash';
11
+ export declare const WATCHER_DEBOUNCE_MS = 100;
12
+ export interface IndexResult {
13
+ indexedFiles: number;
14
+ removedFiles: number;
15
+ totalSymbols: number;
16
+ totalRelations: number;
17
+ durationMs: number;
18
+ changedFiles: string[];
19
+ deletedFiles: string[];
20
+ failedFiles: string[];
21
+ }
22
+ export interface IndexCoordinatorOptions {
23
+ projectRoot: string;
24
+ boundaries: ProjectBoundary[];
25
+ extensions: string[];
26
+ ignorePatterns: string[];
27
+ dbConnection: {
28
+ transaction<T>(fn: (tx: DbConnection) => T): T;
29
+ };
30
+ parseCache: {
31
+ set(key: string, value: unknown): void;
32
+ get(key: string): unknown;
33
+ invalidate(key: string): void;
34
+ };
35
+ fileRepo: {
36
+ getFilesMap(project: string): Map<string, FileRecord>;
37
+ getAllFiles(project: string): FileRecord[];
38
+ upsertFile(record: FileRecord): void;
39
+ deleteFile(project: string, filePath: string): void;
40
+ };
41
+ symbolRepo: {
42
+ replaceFileSymbols(project: string, filePath: string, contentHash: string, symbols: ReadonlyArray<Partial<SymbolRecord>>): void;
43
+ getFileSymbols(project: string, filePath: string): SymbolRecord[];
44
+ getByFingerprint(project: string, fingerprint: string): SymbolRecord[];
45
+ deleteFileSymbols(project: string, filePath: string): void;
46
+ };
47
+ relationRepo: {
48
+ replaceFileRelations(project: string, filePath: string, relations: ReadonlyArray<Partial<RelationRecord>>): void;
49
+ retargetRelations(project: string, oldFile: string, oldSymbol: string | null, newFile: string, newSymbol: string | null): void;
50
+ deleteFileRelations(project: string, filePath: string): void;
51
+ };
52
+ parseSourceFn?: typeof parseSource;
53
+ discoverProjectsFn?: typeof discoverProjects;
54
+ logger?: Logger;
55
+ }
56
+ export declare class IndexCoordinator {
57
+ private readonly opts;
58
+ private readonly logger;
59
+ private readonly callbacks;
60
+ private indexingLock;
61
+ private pendingEvents;
62
+ private debounceTimer;
63
+ private currentIndexing;
64
+ private pendingFullIndex;
65
+ private pendingFullIndexWaiters;
66
+ private tsconfigPathsRaw;
67
+ private boundariesRefresh;
68
+ constructor(opts: IndexCoordinatorOptions);
69
+ get tsconfigPaths(): Promise<TsconfigPaths | null>;
70
+ fullIndex(): Promise<IndexResult>;
71
+ incrementalIndex(events?: FileChangeEvent[]): Promise<IndexResult>;
72
+ onIndexed(cb: (result: IndexResult) => void): () => void;
73
+ handleWatcherEvent(event: FileChangeEvent): void;
74
+ shutdown(): Promise<void>;
75
+ private startIndex;
76
+ private doIndex;
77
+ private processFile;
78
+ private fireCallbacks;
79
+ private flushPending;
80
+ }
@@ -0,0 +1,8 @@
1
+ export { detectChanges } from './file-indexer';
2
+ export type { DetectChangesOptions, DetectChangesResult, FileChangeRecord } from './file-indexer';
3
+ export { indexFileSymbols } from './symbol-indexer';
4
+ export type { IndexFileSymbolsOptions, SymbolDbRow } from './symbol-indexer';
5
+ export { indexFileRelations } from './relation-indexer';
6
+ export type { IndexFileRelationsOptions, RelationDbRow } from './relation-indexer';
7
+ export { IndexCoordinator, WATCHER_DEBOUNCE_MS } from './index-coordinator';
8
+ export type { IndexCoordinatorOptions, IndexResult } from './index-coordinator';
@@ -0,0 +1,24 @@
1
+ import type { Program } from 'oxc-parser';
2
+ import type { TsconfigPaths } from '../common/tsconfig-resolver';
3
+ export interface RelationDbRow {
4
+ project: string;
5
+ type: string;
6
+ srcFilePath: string;
7
+ srcSymbolName: string | null;
8
+ dstFilePath: string;
9
+ dstSymbolName: string | null;
10
+ metaJson: string | null;
11
+ }
12
+ interface RelationRepoPart {
13
+ replaceFileRelations(project: string, filePath: string, relations: RelationDbRow[]): void;
14
+ }
15
+ export interface IndexFileRelationsOptions {
16
+ ast: Program;
17
+ project: string;
18
+ filePath: string;
19
+ relationRepo: RelationRepoPart;
20
+ projectRoot: string;
21
+ tsconfigPaths?: TsconfigPaths;
22
+ }
23
+ export declare function indexFileRelations(opts: IndexFileRelationsOptions): number;
24
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { ParsedFile } from '../parser/types';
2
+ export interface SymbolDbRow {
3
+ project: string;
4
+ filePath: string;
5
+ kind: string;
6
+ name: string;
7
+ startLine: number;
8
+ startColumn: number;
9
+ endLine: number;
10
+ endColumn: number;
11
+ isExported: number;
12
+ signature: string | null;
13
+ fingerprint: string | null;
14
+ detailJson: string | null;
15
+ contentHash: string;
16
+ indexedAt: string;
17
+ }
18
+ interface SymbolRepoPart {
19
+ replaceFileSymbols(project: string, filePath: string, contentHash: string, symbols: SymbolDbRow[]): void;
20
+ }
21
+ export interface IndexFileSymbolsOptions {
22
+ parsed: ParsedFile;
23
+ project: string;
24
+ filePath: string;
25
+ contentHash: string;
26
+ symbolRepo: SymbolRepoPart;
27
+ }
28
+ export declare function indexFileSymbols(opts: IndexFileSymbolsOptions): void;
29
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { QualifiedName } from '../extractor/types';
2
+ export declare function isNode(value: unknown): value is Record<string, unknown>;
3
+ export declare function isNodeArray(value: unknown): value is ReadonlyArray<unknown>;
4
+ export declare function visit(node: unknown, callback: (node: Record<string, unknown>) => void): void;
5
+ export declare function collectNodes(root: unknown, predicate: (node: Record<string, unknown>) => boolean): Record<string, unknown>[];
6
+ export declare function getNodeHeader(node: Record<string, unknown>, parent?: Record<string, unknown> | null): string;
7
+ export declare function isFunctionNode(node: Record<string, unknown>): boolean;
8
+ export declare function getNodeName(node: unknown): string | null;
9
+ export declare function getStringLiteralValue(node: unknown): string | null;
10
+ export declare function getQualifiedName(expr: unknown): QualifiedName | null;
@@ -0,0 +1,6 @@
1
+ export { parseSource } from './parse-source';
2
+ export { ParseCache } from './parse-cache';
3
+ export { buildLineOffsets, getLineColumn, } from './source-position';
4
+ export { isNode, isNodeArray, visit, collectNodes, getNodeHeader, isFunctionNode, getNodeName, getStringLiteralValue, getQualifiedName, } from './ast-utils';
5
+ export { parseJsDoc } from './jsdoc-parser';
6
+ export type { ParsedFile, SourcePosition, SourceSpan } from './types';
@@ -0,0 +1,2 @@
1
+ import type { JsDocBlock } from '../extractor/types';
2
+ export declare function parseJsDoc(commentText: string): JsDocBlock;
@@ -0,0 +1,10 @@
1
+ import type { ParsedFile } from './types';
2
+ export declare class ParseCache {
3
+ private readonly lru;
4
+ constructor(capacity?: number);
5
+ get(filePath: string): ParsedFile | undefined;
6
+ set(filePath: string, parsed: ParsedFile): void;
7
+ invalidate(filePath: string): void;
8
+ invalidateAll(): void;
9
+ size(): number;
10
+ }
@@ -0,0 +1,3 @@
1
+ import { parseSync as defaultParseSync } from 'oxc-parser';
2
+ import type { ParsedFile } from './types';
3
+ export declare function parseSource(filePath: string, sourceText: string, parseSyncFn?: typeof defaultParseSync): ParsedFile;
@@ -0,0 +1,3 @@
1
+ import type { SourcePosition } from './types';
2
+ export declare function buildLineOffsets(sourceText: string): number[];
3
+ export declare function getLineColumn(offsets: number[], offset: number): SourcePosition;