import type { SyntaxKind, ts } from '../utils/ts-morph.ts'; import type { AnalysisOptions } from '../analysis/types.ts'; import type { SlugCasing } from '@renoun/mdx'; import { type PathLike } from '../utils/path.ts'; import type { TypeFilter } from '../utils/resolve-type.ts'; import type { ResolvedFileExportsResult } from '../utils/resolve-file-exports.ts'; import type { JavaScriptFileReferenceBaseData, JavaScriptFileResolvedTypesData } from './reference-artifacts.ts'; import type { Section } from './types.ts'; import type { DirectoryEntry } from './types.ts'; export type FileSystemWriteFileContent = string | Uint8Array | ArrayBuffer | ArrayBufferView; export type FileReadableStream = ReadableStream; export type FileWritableStream = WritableStream; export interface SyncFileSystem { readDirectorySync(path?: string): DirectoryEntry[]; readFileSync(path: string): string; readFileBinarySync(path: string): Uint8Array; readFileStream(path: string): FileReadableStream; /** * Get the size of a file in bytes. Implementations should return `undefined` * if the file does not exist or the size cannot be determined. */ getFileByteLengthSync(path: string): number | undefined; /** Check synchronously if a file exists at the given path. */ fileExistsSync(path: string): boolean; /** * Get the last modified timestamp of a file or directory in milliseconds. * Implementations should return `undefined` if the path does not exist or * if the timestamp cannot be determined. */ getFileLastModifiedMsSync(path: string): number | undefined; } export interface AsyncFileSystem { readDirectory(path?: string): Promise; readFile(path: string): Promise; readFileBinary(path: string): Promise; readFileStream(path: string): FileReadableStream; /** * Get the size of a file in bytes. Implementations should return `undefined` * if the file does not exist or the size cannot be determined. */ getFileByteLength(path: string): Promise; /** Check if a file exists at the given path. */ fileExists(path: string): Promise; /** * Get the last modified timestamp of a file or directory in milliseconds. * Implementations should return `undefined` if the path does not exist or * if the timestamp cannot be determined. */ getFileLastModifiedMs(path: string): Promise; } export interface WritableFileSystem { writeFileSync(path: string, content: FileSystemWriteFileContent): void; writeFile(path: string, content: FileSystemWriteFileContent): Promise; writeFileStream(path: string): FileWritableStream; deleteFileSync(path: string): void; deleteFile(path: string): Promise; createDirectory(path: string): Promise; rename(source: string, target: string, options?: { overwrite?: boolean; }): Promise; copy(source: string, target: string, options?: { overwrite?: boolean; }): Promise; } export type FileSystem = BaseFileSystem & SyncFileSystem & AsyncFileSystem & WritableFileSystem; export interface FileSystemOptions { /** Path to the tsconfig.json file to use when analyzing types and determining if a file is excluded. */ tsConfigPath?: string; /** Optional base directory for persisted cache files. */ outputDirectory?: string; } export interface TsConfig { compilerOptions?: ts.CompilerOptions; include?: string[]; exclude?: string[]; extends?: string; references?: { path: string; }[]; files?: string[]; [key: string]: unknown; } export declare abstract class BaseFileSystem { #private; readonly outputDirectory?: string; /** * Optional workspace change token used for fast cache revalidation. * * Implementations should return a deterministic token for a scoped root path * or `null` when a token cannot be produced. */ getWorkspaceChangeToken?(rootPath: string): Promise; /** * Optional stable identity used to scope persistent cache keys for different * file-system backends that may expose the same workspace-relative paths. */ getCacheIdentity?(): unknown; /** * Optional hint indicating whether persisted cache entries are deterministic * for the current file-system state. * * Returning `false` allows callers to skip persistence for cache domains that * cannot be safely revalidated (for example moving branch refs). */ isPersistentCacheDeterministic?(): boolean; /** * Optional changed-path resolver used when a workspace token changes. * * Implementations should return workspace-relative POSIX paths that changed * since `previousToken`, scoped to `rootPath`. Return `null` when the change * set cannot be determined. */ getWorkspaceChangedPathsSinceToken?(rootPath: string, previousToken: string): Promise; /** * Whether this file system should use persistent cache by default. * * Implementations that represent real and stable storage (for example local * disk or git-backed stores) should return `true`. In-memory implementations * should return `false`. */ usesPersistentCacheByDefault(): boolean; supportsServerManagedReferenceArtifacts(): boolean; /** * Whether directory `mtime` signatures should be tracked for snapshot * dependency validation in non-strict hermetic mode. */ usesDirectoryMtimeSnapshotDependencies(): boolean; /** * Whether persisted snapshot file dependencies should be validated in * non-strict hermetic mode. */ validatesPersistedFileDependenciesByDefault(): boolean; constructor(options?: FileSystemOptions); /** Stable analysis metadata used for cache partitioning and snapshot identity. */ abstract getAnalysisCacheMetadata(): AnalysisOptions; /** * Optional stable analysis scope identity for cache partitioning. * * Prefer this over reading raw analysis metadata directly. */ getAnalysisScopeId(): string | undefined; /** * Prepare a file path for analysis. * * Backends may rewrite `filePath` and/or return backend-specific analysis * options. Callers that need direct node-client access should use this. */ prepareAnalysis(filePath: string): Promise<{ filePath: string; analysisOptions: AnalysisOptions; }>; abstract getAbsolutePath(path: string): string; abstract getRelativePathToWorkspace(path: string): string; getPathname(path: PathLike, options?: { basePath?: string; rootPath?: string; }): string; /** Whether compilerOptions.stripInternal is enabled in the active tsconfig. */ shouldStripInternal(): boolean; shouldStripInternalAsync(): Promise; isFilePathExcludedFromTsConfig(filePath: string, isDirectory?: boolean): boolean; isFilePathExcludedFromTsConfigAsync(filePath: string, isDirectory?: boolean): Promise; abstract isFilePathGitIgnored(filePath: string): boolean; getFileExports(filePath: string): Promise; readFreshReferenceBaseArtifact(filePath: string, stripInternal: boolean): Promise; getCachedReferenceBaseArtifact(filePath: string, stripInternal: boolean): Promise; getCachedReferenceResolvedTypesArtifact(filePath: string): Promise; getCachedReferenceSectionsArtifact(filePath: string, options: { stripInternal: boolean; slugCasing: SlugCasing; }): Promise; resolveFileExportsWithDependencies(filePath: string, filter?: TypeFilter): Promise; getFileExportMetadata(name: string, filePath: string, position: number, kind: SyntaxKind): Promise; getFileExportText(filePath: string, position: number, kind: SyntaxKind, includeDependencies?: boolean): Promise; getOutlineRanges(filePath: string): Promise; getFoldingRanges(filePath: string): Promise; getFileExportStaticValue(filePath: string, position: number, kind: SyntaxKind): Promise; resolveTypeAtLocationWithDependencies(filePath: string, position: number, kind: SyntaxKind, filter?: TypeFilter): Promise; /** @deprecated Use `resolveTypeAtLocationWithDependencies` for dependency-aware results. */ resolveTypeAtLocation(filePath: string, position: number, kind: SyntaxKind, filter?: TypeFilter): Promise; }