/** * Symbol Repository - PostgreSQL Implementation * * All queries use raw SQL via $queryRaw / $executeRaw to avoid the * Prisma 7.7.0 + Bun ORM bug (isObjectEnumValue is not a function). */ import { type StructuralFqnCandidate } from "../../services/structural/fqn-codec.js"; import type { GraphGenerationLease } from "../graph-generation/graph-generation-contract.js"; export type SymbolKind = "module" | "namespace" | "class" | "interface" | "trait" | "enum" | "function" | "method" | "constructor" | "property" | "field" | "variable" | "constant" | "type" | "type_parameter" | "export" | "heading" | "key"; export type RefKind = "call" | "type_ref" | "import" | "extend" | "implement" | "data_flow" | "http_call" | "emit" | "listen"; export type WorkspaceStatus = "pending" | "indexing" | "indexed" | "error"; export interface SymbolFileRow { project_id: string; relative_path: string; content_hash: string; mtime: number; size: number; indexed_at: number; symbol_count: number; chunk_count: number; generation_id?: string; language?: string; dialect?: string; grammar_version?: string; query_pack_version?: string; resolver_version?: string; parser_status?: "legacy" | "ok" | "recovered" | "unsupported" | "failed"; parser_error_count?: number; diagnostics?: readonly Record[]; is_stale?: boolean; last_known_good_generation_id?: string; last_successful_at?: number; } export interface SymbolDefinition { id: string; project_id: string; file_path: string; name: string; kind: SymbolKind; line_start: number; line_end: number; exported: boolean; doc_comment?: string; indexed_at: number; qualified_name?: string; canonical_signature?: string; signature_hash?: string; legacy_fqn?: string; source_span?: Record; } export interface SymbolReference { id?: number; project_id: string; from_file: string; from_line: number; symbol_name: string; target_fqn?: string; ref_kind: RefKind; /** Typed-edge metadata (D1): stored natively as JSONB in PG. */ meta?: Record | null; source_span?: Record; } export interface SymbolImport { id?: number; project_id: string; from_file: string; to_file?: string; specifier: string; imported_names: string[]; is_external: boolean; is_type_only: boolean; } export interface CentralityEntry { project_id: string; file_path: string; score: number; updated_at: number; } export interface WorkspaceRow { project_id: string; project_path: string; display_name?: string; status: WorkspaceStatus; last_indexed_at?: number; last_error?: string; files_count: number; chunks_count: number; symbols_count: number; created_at: number; updated_at: number; } /** * All graph-backed inputs needed by project_map, captured from one active * generation while the workspace row is share-locked in one transaction. */ export interface ProjectMapGraphSnapshot { workspace: WorkspaceRow; generationId: string | null; counts: { files: number; definitions: number; references: number; imports: number; centrality: number; }; diagnostics: { recovered: number; hardFailures: number; staleFiles: number; errors: number; }; languages: Record; topCentralFiles: CentralityEntry[]; symbolsByKind: Record; filesByLanguage: Record; recentFiles: Array<{ filePath: string; indexedAt: number | null; }>; edgesByKind: Record; architecture: { files: string[]; importEdges: Array<{ from_file: string; to_file?: string; }>; definitions: SymbolDefinition[]; httpEdges: SymbolReference[]; centrality: Map; }; } export interface ProjectMapSnapshotOptions { centralityLimit?: number; recentLimit?: number; /** @internal Deterministic concurrency sensor used by DB-backed tests. */ afterGenerationCaptured?: (generationId: string | null) => void | Promise; } export interface ActiveGenerationScope { projectId: string; generationId: string; } export interface GenerationFileWrite { file: SymbolFileRow; definitions: readonly SymbolDefinition[]; references: readonly SymbolReference[]; imports: readonly SymbolImport[]; } export type DefinitionFqnResolution = { found: true; ambiguous: false; definition: SymbolDefinition; } | { found: false; ambiguous: false; fqn: string; candidates: readonly []; } | { found: false; ambiguous: false; legacyFqn: string; candidates: readonly []; } | { found: false; ambiguous: true; legacyFqn: string; candidates: readonly StructuralFqnCandidate[]; }; export declare class SymbolRepositoryPg { private static instance; private constructor(); static getInstance(): SymbolRepositoryPg; upsertWorkspace(ws: Omit & { created_at?: number; }): Promise; updateWorkspaceStatus(projectId: string, status: WorkspaceStatus, opts?: { lastError?: string | null; lastIndexedAt?: number; filesCount?: number; chunksCount?: number; symbolsCount?: number; } | string): Promise; getWorkspace(projectId: string): Promise; listWorkspaces(): Promise; deleteWorkspace(projectId: string): Promise; upsertFile(file: SymbolFileRow): Promise; getFile(projectId: string, relativePath: string): Promise; upsertDefinition(def: SymbolDefinition): Promise; deleteDefinitionsByFile(projectId: string, filePath: string): Promise; searchDefinitions(projectId: string, query?: string, kinds?: SymbolKind[], exportedOnly?: boolean, limit?: number, filePath?: string): Promise; getDefinition(projectId: string, fqn: string): Promise; insertReference(ref: SymbolReference): Promise; deleteReferencesByFile(projectId: string, filePath: string): Promise; getReferences(projectId: string, symbolName: string, limit?: number): Promise; insertImport(imp: SymbolImport): Promise; deleteImportsByFile(projectId: string, filePath: string): Promise; getImportsFrom(projectId: string, filePath: string): Promise; upsertCentrality(entry: CentralityEntry): Promise; getTopCentralFiles(projectId: string, limit?: number): Promise; /** * Aggregates used to build a project map in a single round trip: * symbols grouped by kind, files grouped by extension, and the most * recently indexed files (absolute timestamp for the caller to format). */ getProjectMapAggregates(projectId: string, recentLimit?: number): Promise<{ symbolsByKind: Record; filesByLanguage: Record; recentFiles: Array<{ filePath: string; indexedAt: number | null; }>; }>; /** * Capture every graph-backed project-map input from one active generation. * The workspace share lock prevents activation from changing the pointer * until all reads finish; every query is additionally scoped by the captured * generation id so pending rows can never leak into the response. */ getProjectMapSnapshot(projectId: string, opts?: ProjectMapSnapshotOptions): Promise; getCentrality(projectId: string): Promise>; batchUpsertDefinitions(defs: SymbolDefinition[]): Promise; batchInsertReferences(refs: SymbolReference[]): Promise; batchInsertImports(imports: SymbolImport[]): Promise; copyFileGeneration(lease: GraphGenerationLease, sourceGenerationId: string, filePath: string): Promise<{ status: "copied" | "missing" | "lease_lost"; }>; writeFileGeneration(input: { lease: GraphGenerationLease; } & GenerationFileWrite): Promise<{ status: "written" | "lease_lost"; }>; deleteFileGeneration(lease: GraphGenerationLease, filePath: string): Promise<{ status: "deleted" | "lease_lost"; }>; markFileStaleGeneration(lease: GraphGenerationLease, filePath: string, input: { lastKnownGoodGenerationId: string; diagnostics: readonly Record[]; parserErrorCount: number; }): Promise<{ status: "stale" | "lease_lost"; }>; updateCentralityGeneration(lease: GraphGenerationLease, entries: readonly { filePath: string; score: number; }[]): Promise<{ status: "written" | "lease_lost"; }>; writeFileSymbols(projectId: string, filePath: string, defs: SymbolDefinition[], refs: SymbolReference[], imports: SymbolImport[]): Promise; clearProject(projectId: string): Promise; getActiveGenerationScope(projectId: string): Promise; resolveDefinitionFqn(projectId: string, fqn: string): Promise; getActiveGraphSnapshot(projectId: string): Promise<{ generationId: string; counts: { files: number; definitions: number; references: number; imports: number; centrality: number; }; diagnostics: { recovered: number; hardFailures: number; staleFiles: number; errors: number; }; languages: Record; } | null>; findDefinitionsByName(projectId: string, name: string): Promise; findDefinitionByFqn(projectId: string, fqn: string): Promise; /** All file paths for a project (used by centrality / hasData checks). */ allFiles(projectId: string): Promise; /** All import edges for a project (used by PageRank). */ allImportEdges(projectId: string): Promise; /** Imports originating from a specific file (alias for getImportsFrom). */ findDependencies(projectId: string, fromFile: string): Promise; /** Reverse-import query: files that import `filePath` (PG parity with PostgreSQL). */ findImporters(projectId: string, filePath: string): Promise; /** References matching by target FQN. */ findReferencesByFqn(projectId: string, fqn: string): Promise; /** References matching by symbol name. */ findReferencesByName(projectId: string, symbolName: string): Promise; /** * Query typed structural edges with optional filtering (D1). * Mirrors the PostgreSQL SymbolRepository.findEdges contract. */ findEdges(projectId: string, opts?: { types?: RefKind[]; fromSymbol?: string; toSymbol?: string; fromFile?: string; direction?: "outgoing" | "incoming" | "both"; limit?: number; }): Promise; /** Count edges grouped by ref_kind — used by project_map for typed-edge stats. */ countEdgesByKind(projectId: string): Promise>; /** List definitions with filter options (mirrors PostgreSQL SymbolRepository.listDefinitions). */ listDefinitions(projectId: string, opts?: { search?: string; kind?: string[]; file?: string; exportedOnly?: boolean; limit?: number; }): Promise; /** * Return ALL symbol definitions for a project (no default LIMIT). Capped only * by a high safety ceiling (200k) to guard against pathological repos. Used * by the resolve-stage project-wide name→FQN map where the default LIMIT 100 * of {@link listDefinitions} would silently truncate and drop cross-file * callees. Mirrors the PostgreSQL {@link SymbolRepository.listAllDefinitions}. */ listAllDefinitions(projectId: string, opts?: { kind?: string[]; exportedOnly?: boolean; }): Promise; /** Batch-update centrality scores computed by PageRank. */ updateCentrality(projectId: string, scores: Map): Promise; } //# sourceMappingURL=symbol-repository-pg.d.ts.map