laravel-mix-glob
Version:
Laravel mix extension that add support for globs usage with an extensive concise api. For a more natural boosted productivity and dynamic. Configure once and forget about adding the files each time.
98 lines (97 loc) • 3.15 kB
TypeScript
import { Cache as FlatCache } from 'flat-cache';
import { IOptions, IWatchingCacheData } from './types';
import { MetaCache } from './MetaCache';
/**
* Cache handler that allow us to read the data from the cache.
* Reset the cache after that. While the data will be accessible through values prop
* The design is that every mix initial process would have it's own session
* Every session is a flat-cache
* Then there is the meta cache that track all sessions. So that we can detect orphans processes
* And clean them through cleanOrphans() function.
*
* Actual meta cache flat cache structure.
*
* ```json
* [
* { sessions: '1' },
* ['2', '3', '4'],
* { id: '5', masterProcessId: 66865 },
* { id: '6', masterProcessId: 73938 },
* { id: '7', masterProcessId: 80739 },
* 'laravel-mix-glob:session-a61493e5-48e4-4a56-ae07-4b2b22300569',
* 'laravel-mix-glob:session-a3f49d5a-37a3-4884-9270-5d7f4e5a9418',
* 'laravel-mix-glob:session-8f9f63db-9046-4624-a89d-3bf1876bc90e',
* ];
* ```
* ```ts
* export interface IMetaData {
* sessions: ISession[];
* }
*
* export interface ISession {
* id: string;
* masterProcessId: number;
* }
* ```
* NOTE: You can find it on `node_modules/flat-cache/.cache/laravel-mix-glob:meta`
*
* Every session cache would go as:
*
* ```ts
* export interface IWatchingCacheData {
* childPids: number[];
* }
* ```
*
* With a flat cache id like `laravel-mix-glob:session-0ba13e16-22fb-4dbd-a0a6-905727b6aef5`
*
* where the session id is `session-0ba13e16-22fb-4dbd-a0a6-905727b6aef5` generated using uuid v4.
*/
export declare class Cache {
flatCache: FlatCache;
metaCache: MetaCache;
sessionId: string;
private _values;
constructor(options?: IOptions);
get values(): IWatchingCacheData;
private _getSessionCacheId;
/**
* Load cache data to values and update cache ref
*
* NOTE: After reset of the cache the values are not reset
*/
syncWithCache(): this;
destroy(): void;
/**
* commit and save the changes to the cache
* @returns this
*/
save(): this;
/**
* Push child pids into the list with keeping unicity
* @param pids child pids to push to the list
* @returns true if new elements are added. False if none new are added.
*/
addChildPids(pids: number[]): this;
/**
* Remove child pids from the list with keeping unicity
* @param pids child pids to remove from the list
* @returns true if new elements are remove. False if none are removed.
*/
removeChildPids(pids: number[]): this;
resetChildPids(): this;
/**
* Set a specific cache entry
* @param key entry key
* @param value entry value
* @returns this
*/
set<T extends keyof IWatchingCacheData>(key: T, value: IWatchingCacheData[T]): this;
/**
* Clean orphan sessions (clean cache and processes)
* - kill any orphans processes
* - delete cache documents
* @returns this
*/
cleanOrphans(): this;
}