file-entry-cache
- Version 11.1.1
- Published
- 87.3 kB
- 1 dependency
- MIT license
Install
npm i file-entry-cacheyarn add file-entry-cachepnpm add file-entry-cacheOverview
A lightweight cache for file metadata, ideal for processes that work on a specific set of files and only need to reprocess files that have changed since the last run
Index
Functions
Classes
FileEntryCache
- analyzeFiles()
- cache
- createFileKey()
- cwd
- deleteCacheFile()
- destroy()
- getAbsolutePath()
- getAbsolutePathWithCwd()
- getFileDescriptor()
- getFileDescriptorsByPath()
- getHash()
- getUpdatedFiles()
- hasFileChanged()
- hashAlgorithm
- isRelativePath()
- logger
- normalizeEntries()
- reconcile()
- removeEntry()
- renameCacheKeys()
- restrictAccessToCwd
- useAbsolutePathAsKey
- useCheckSum
- useModifiedTime
Type Aliases
Functions
function create
create: ( cacheId: string, cacheDirectory?: string, options?: CreateOptions) => FileEntryCache;Create a new FileEntryCache instance
Parameter cacheId
The cache file name
Parameter cacheDirectory
The directory to store the cache file (default: undefined, cache won't be persisted)
Parameter options
Whether to use checksum to detect file changes (default: false)
Returns
A new FileEntryCache instance
function createFromFile
createFromFile: (filePath: string, options?: CreateOptions) => FileEntryCache;Create a new FileEntryCache instance from a file path
Parameter filePath
The path to the cache file
Parameter options
create options such as useChecksum, cwd, and more
Returns
A new FileEntryCache instance
Classes
class FileEntryCache
class FileEntryCache {}constructor
constructor(options?: FileEntryCacheOptions);Create a new FileEntryCache instance
Parameter options
The options for the FileEntryCache (all properties are optional with defaults)
property cache
cache: FlatCache;Get the cache
Returns
{FlatCache} The cache
property cwd
cwd: string;Get the current working directory
Returns
{string} The current working directory (default: process.cwd())
property hashAlgorithm
hashAlgorithm: string;Get the hash algorithm
Returns
{string} The hash algorithm (default: 'md5')
property logger
logger: ILogger;Get the logger
Returns
{ILogger | undefined} The logger instance
property restrictAccessToCwd
restrictAccessToCwd: boolean;Get whether to restrict paths to cwd boundaries
Returns
{boolean} Whether strict path checking is enabled (default: true)
property useAbsolutePathAsKey
useAbsolutePathAsKey: boolean;Get whether to use absolute path as cache key
Returns
{boolean} Whether cache keys use absolute paths (default: false)
property useCheckSum
useCheckSum: boolean;Use the hash to check if the file has changed
Returns
{boolean} if the hash is used to check if the file has changed (default: false)
property useModifiedTime
useModifiedTime: boolean;Get whether to use modified time for change detection
Returns
{boolean} Whether modified time (mtime) is used for change detection (default: true)
method analyzeFiles
analyzeFiles: (files: string[]) => AnalyzedFiles;Analyze the files analyzeFiles
Parameter files
The files to analyze
Returns
{AnalyzedFiles} The analysis of the files
method createFileKey
createFileKey: (filePath: string) => string;Create the key for the file path used for caching. createFileKey
Parameter filePath
{String}
method deleteCacheFile
deleteCacheFile: () => boolean;Delete the cache file from the disk deleteCacheFile {boolean} true if the file was deleted, false otherwise
method destroy
destroy: () => void;Remove the cache from the file and clear the memory cache destroy
method getAbsolutePath
getAbsolutePath: (filePath: string) => string;Get the Absolute Path. If it is already absolute it will return the path as is. When restrictAccessToCwd is enabled, ensures the resolved path stays within cwd boundaries. getAbsolutePath
Parameter filePath
The file path to get the absolute path for
Returns
{string}
Throws
{Error} When restrictAccessToCwd is true and path would resolve outside cwd
method getAbsolutePathWithCwd
getAbsolutePathWithCwd: (filePath: string, cwd: string) => string;Get the Absolute Path with a custom working directory. If it is already absolute it will return the path as is. When restrictAccessToCwd is enabled, ensures the resolved path stays within the provided cwd boundaries. getAbsolutePathWithCwd
Parameter filePath
The file path to get the absolute path for
Parameter cwd
The custom working directory to resolve relative paths from
Returns
{string}
Throws
{Error} When restrictAccessToCwd is true and path would resolve outside the provided cwd
method getFileDescriptor
getFileDescriptor: ( filePath: string, options?: GetFileDescriptorOptions) => FileDescriptor;Get the file descriptor for the file path getFileDescriptor
Parameter filePath
The file path to get the file descriptor for
Parameter options
The options for getting the file descriptor
Returns
The file descriptor
method getFileDescriptorsByPath
getFileDescriptorsByPath: (filePath: string) => FileDescriptor[];Get the file descriptors by path prefix getFileDescriptorsByPath
Parameter filePath
the path prefix to match
Returns
{FileDescriptor[]} The file descriptors
method getHash
getHash: (buffer: Buffer) => string;Given a buffer, calculate md5 hash of its content. getHash
Parameter buffer
buffer to calculate hash on {String} content hash digest
method getUpdatedFiles
getUpdatedFiles: (files: string[]) => string[];Get the updated files getUpdatedFiles
Parameter files
The files to get the updated files for
Returns
{string[]} The updated files
method hasFileChanged
hasFileChanged: (filePath: string) => boolean;Check if the file has changed hasFileChanged
Parameter filePath
The file path to check
Returns
{boolean} if the file has changed, false otherwise
method isRelativePath
isRelativePath: (filePath: string) => boolean;Check if the file path is a relative path isRelativePath
Parameter filePath
The file path to check
Returns
{boolean} if the file path is a relative path, false otherwise
method normalizeEntries
normalizeEntries: (files?: string[]) => FileDescriptor[];Get the file descriptors for the files normalizeEntries
Parameter files
?: string[] - The files to get the file descriptors for
Returns
The file descriptors
method reconcile
reconcile: () => void;Reconcile the cache reconcile
method removeEntry
removeEntry: (filePath: string) => void;Remove and Entry From the Cache removeEntry
Parameter filePath
The file path to remove from the cache
method renameCacheKeys
renameCacheKeys: (oldPath: string, newPath: string) => void;Rename cache keys that start with a given path prefix. renameCacheKeys
Parameter oldPath
The old path prefix to rename
Parameter newPath
The new path prefix to rename to
class FileEntryDefault
class FileEntryDefault {}property create
static create: ( cacheId: string, cacheDirectory?: string, options?: CreateOptions) => FileEntryCache;property createFromFile
static createFromFile: ( filePath: string, options?: CreateOptions) => FileEntryCache;Type Aliases
type AnalyzedFiles
type AnalyzedFiles = { /** Array of file paths that have changed since last cache */ changedFiles: string[]; /** Array of file paths that were not found */ notFoundFiles: string[]; /** Array of file paths that have not changed since last cache */ notChangedFiles: string[];};type CreateOptions
type CreateOptions = Omit<FileEntryCacheOptions, 'cache'>;type FileDescriptor
type FileDescriptor = { /** The cache key for this file (typically the file path) */ key: string; /** Whether the file has changed since last cache check */ changed?: boolean; /** Metadata about the file */ meta: FileDescriptorMeta; /** Whether the file was not found */ notFound?: boolean; /** Error encountered when accessing the file */ err?: Error;};type FileDescriptorMeta
type FileDescriptorMeta = { /** File size in bytes */ size?: number; /** File modification time (timestamp in milliseconds) */ mtime?: number; /** File content hash (when useCheckSum is enabled) */ hash?: string; /** Custom data associated with the file (e.g., lint results, metadata) */ data?: unknown; /** Allow any additional custom properties */ [key: string]: unknown;};type FileEntryCacheOptions
type FileEntryCacheOptions = { /** Whether to use file modified time for change detection (default: true) */ useModifiedTime?: boolean; /** Whether to use checksum for change detection (default: false) */ useCheckSum?: boolean; /** Hash algorithm to use for checksum (default: 'md5') */ hashAlgorithm?: string; /** Current working directory for resolving relative paths (default: process.cwd()) */ cwd?: string; /** Restrict file access to within cwd boundaries (default: true) */ restrictAccessToCwd?: boolean; /** Whether to use absolute path as cache key (default: false) */ useAbsolutePathAsKey?: boolean; /** Logger instance for logging (default: undefined) */ logger?: ILogger; /** Options for the underlying flat cache */ cache?: FlatCacheOptions;};type GetFileDescriptorOptions
type GetFileDescriptorOptions = { /** Whether to use checksum for this specific file check instead of modified time (mtime) (overrides instance setting) */ useCheckSum?: boolean; /** Whether to use file modified time for change detection (default: true) */ useModifiedTime?: boolean;};type ILogger
type ILogger = { /** Current log level */ level?: string; /** Trace level logging */ trace: (message: string | object, ...args: unknown[]) => void; /** Debug level logging */ debug: (message: string | object, ...args: unknown[]) => void; /** Info level logging */ info: (message: string | object, ...args: unknown[]) => void; /** Warning level logging */ warn: (message: string | object, ...args: unknown[]) => void; /** Error level logging */ error: (message: string | object, ...args: unknown[]) => void; /** Fatal level logging */ fatal: (message: string | object, ...args: unknown[]) => void;};Package Files (1)
Dependencies (1)
Dev Dependencies (8)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/file-entry-cache.
- Markdown[](https://www.jsdocs.io/package/file-entry-cache)
- HTML<a href="https://www.jsdocs.io/package/file-entry-cache"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3788 ms. - Missing or incorrect documentation? Open an issue for this package.
