UNPKG

5.58 kBTypeScriptView Raw
1import { FlatCacheOptions, FlatCache } from 'flat-cache';
2
3type FileEntryCacheOptions = {
4 currentWorkingDirectory?: string;
5 useCheckSum?: boolean;
6 hashAlgorithm?: string;
7 cache?: FlatCacheOptions;
8};
9type GetFileDescriptorOptions = {
10 useCheckSum?: boolean;
11 currentWorkingDirectory?: string;
12};
13type FileDescriptor = {
14 key: string;
15 changed?: boolean;
16 meta: FileDescriptorMeta;
17 notFound?: boolean;
18 err?: Error;
19};
20type FileDescriptorMeta = {
21 size?: number;
22 mtime?: number;
23 hash?: string;
24 data?: unknown;
25};
26type AnalyzedFiles = {
27 changedFiles: string[];
28 notFoundFiles: string[];
29 notChangedFiles: string[];
30};
31declare function createFromFile(filePath: string, useCheckSum?: boolean, currentWorkingDirectory?: string): FileEntryCache;
32declare function create(cacheId: string, cacheDirectory?: string, useCheckSum?: boolean, currentWorkingDirectory?: string): FileEntryCache;
33declare class FileEntryDefault {
34 static create: typeof create;
35 static createFromFile: typeof createFromFile;
36}
37declare class FileEntryCache {
38 private _cache;
39 private _useCheckSum;
40 private _currentWorkingDirectory;
41 private _hashAlgorithm;
42 constructor(options?: FileEntryCacheOptions);
43 get cache(): FlatCache;
44 set cache(cache: FlatCache);
45 get useCheckSum(): boolean;
46 set useCheckSum(value: boolean);
47 get hashAlgorithm(): string;
48 set hashAlgorithm(value: string);
49 get currentWorkingDirectory(): string | undefined;
50 set currentWorkingDirectory(value: string | undefined);
51 /**
52 * Given a buffer, calculate md5 hash of its content.
53 * @method getHash
54 * @param {Buffer} buffer buffer to calculate hash on
55 * @return {String} content hash digest
56 */
57 getHash(buffer: Buffer): string;
58 /**
59 * Create the key for the file path used for caching.
60 * @method createFileKey
61 * @param {String} filePath
62 * @return {String}
63 */
64 createFileKey(filePath: string, options?: {
65 currentWorkingDirectory?: string;
66 }): string;
67 /**
68 * Check if the file path is a relative path
69 * @method isRelativePath
70 * @param filePath - The file path to check
71 * @returns {boolean} if the file path is a relative path, false otherwise
72 */
73 isRelativePath(filePath: string): boolean;
74 /**
75 * Delete the cache file from the disk
76 * @method deleteCacheFile
77 * @return {boolean} true if the file was deleted, false otherwise
78 */
79 deleteCacheFile(): boolean;
80 /**
81 * Remove the cache from the file and clear the memory cache
82 * @method destroy
83 */
84 destroy(): void;
85 /**
86 * Remove and Entry From the Cache
87 * @method removeEntry
88 * @param filePath - The file path to remove from the cache
89 */
90 removeEntry(filePath: string, options?: {
91 currentWorkingDirectory?: string;
92 }): void;
93 /**
94 * Reconcile the cache
95 * @method reconcile
96 */
97 reconcile(): void;
98 /**
99 * Check if the file has changed
100 * @method hasFileChanged
101 * @param filePath - The file path to check
102 * @returns {boolean} if the file has changed, false otherwise
103 */
104 hasFileChanged(filePath: string): boolean;
105 /**
106 * Get the file descriptor for the file path
107 * @method getFileDescriptor
108 * @param filePath - The file path to get the file descriptor for
109 * @param options - The options for getting the file descriptor
110 * @returns The file descriptor
111 */
112 getFileDescriptor(filePath: string, options?: GetFileDescriptorOptions): FileDescriptor;
113 /**
114 * Get the file descriptors for the files
115 * @method normalizeEntries
116 * @param files?: string[] - The files to get the file descriptors for
117 * @returns The file descriptors
118 */
119 normalizeEntries(files?: string[]): FileDescriptor[];
120 /**
121 * Analyze the files
122 * @method analyzeFiles
123 * @param files - The files to analyze
124 * @returns {AnalyzedFiles} The analysis of the files
125 */
126 analyzeFiles(files: string[]): AnalyzedFiles;
127 /**
128 * Get the updated files
129 * @method getUpdatedFiles
130 * @param files - The files to get the updated files for
131 * @returns {string[]} The updated files
132 */
133 getUpdatedFiles(files: string[]): string[];
134 /**
135 * Get the not found files
136 * @method getFileDescriptorsByPath
137 * @param filePath - the files that you want to get from a path
138 * @returns {FileDescriptor[]} The not found files
139 */
140 getFileDescriptorsByPath(filePath: string): FileDescriptor[];
141 /**
142 * Get the Absolute Path. If it is already absolute it will return the path as is.
143 * @method getAbsolutePath
144 * @param filePath - The file path to get the absolute path for
145 * @param options - The options for getting the absolute path. The current working directory is used if not provided.
146 * @returns {string}
147 */
148 getAbsolutePath(filePath: string, options?: {
149 currentWorkingDirectory?: string;
150 }): string;
151 /**
152 * Rename the absolute path keys. This is used when a directory is changed or renamed.
153 * @method renameAbsolutePathKeys
154 * @param oldPath - The old path to rename
155 * @param newPath - The new path to rename to
156 */
157 renameAbsolutePathKeys(oldPath: string, newPath: string): void;
158}
159
160export { type AnalyzedFiles, type FileDescriptor, type FileDescriptorMeta, FileEntryCache, type FileEntryCacheOptions, type GetFileDescriptorOptions, create, createFromFile, FileEntryDefault as default };