UNPKG

3.04 kBTypeScriptView Raw
1// Type definitions for file-entry-cache 5.0
2// Project: https://github.com/royriojas/file-entry-cache#readme
3// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/// <reference types="node" />
7
8/**
9 * @param pathToCache - the path to the cache file (this combines the cache name and directory
10 * @param useCheckSum - Whether to use md5 checksum to verify if file changed.
11 * If false the default will be to use the mtime and size of the file
12 */
13export function createFromFile(pathToCache: string, useCheckSum?: boolean): FileEntryCache;
14
15/**
16 * @param cacheName - the name of the cache to be created
17 * @param directory - the directory to load the cache from
18 * @param usecheckSum - Whether to use md5 checksum to verify if file changed.
19 * If false the default will be to use the mtime and size of the file
20 */
21export function create(cacheName: string, directory?: string, usecheckSum?: boolean): FileEntryCache;
22
23export interface FileEntryCache {
24 /** the flat cache storage used to persist the metadata of the `files */
25 cache: object;
26 /** Given a buffer, calculate md5 hash of its content. */
27 getHash(buffer: Buffer): string;
28 /** Return whether or not a file has changed since last time reconcile was called */
29 hasFileChanged(file: string): boolean;
30 /**
31 * given an array of file paths it return and object with three arrays:
32 * - changedFiles: Files that changed since previous run
33 * - notChangedFiles: Files that haven't change
34 * - notFoundFiles: Files that were not found, probably deleted
35 */
36 analyzeFiles(files?: string[]): AnalyzedFilesInfo;
37 getFileDescriptor(file: string): FileDescriptor;
38 /**
39 * Return the list o the files that changed compared
40 * against the ones stored in the cache
41 */
42 getUpdatedFiles(files?: string[]): string[];
43 /**
44 * return the list of file
45 */
46 normalizeEntries(files?: string[]): FileDescriptor[];
47 /**
48 * Remove an entry from the file-entry-cache.
49 * Useful to force the file to still be considered
50 * modified the next time the process is run
51 */
52 removeEntry(entryName: string): void;
53 /**
54 * Delete the cache file from the disk
55 */
56 deleteCacheFile(): void;
57 /**
58 * remove the cache from the file and clear the memory cache
59 */
60 destroy(): void;
61 /**
62 * Sync the files and persist them to the cache
63 */
64 reconcile(noPrune?: boolean): void;
65}
66
67export interface AnalyzedFilesInfo {
68 readonly changedFiles: string[];
69 readonly notFoundFiles: string[];
70 readonly notChangedFiles: string[];
71}
72
73export interface FileDescriptor {
74 readonly key: string;
75 readonly notFound: boolean;
76 readonly err?: Error | undefined;
77 readonly changed?: boolean | undefined;
78 readonly meta?: {
79 readonly size?: number | undefined;
80 readonly mtime?: number | undefined;
81 readonly hash?: string | undefined;
82 } | undefined;
83}