UNPKG

web-dev-server

Version:

Node.js simple http server for common development or training purposes.

111 lines (110 loc) 4.61 kB
/// <reference types="node" /> import { Server, IApplication } from "../Server"; import { Record } from "./Registers/Record"; import { ErrorsHandler } from "../Handlers/Error"; export declare class Register { /** * @summary Server instance pointer. */ protected server: Server; /** * @summary Server error handler submodule pointer. */ protected errorsHandler: ErrorsHandler; /** * @summary Store of cached application instances. * Keys are index script directories, values are `Record` types. */ protected store: Map<string, Record>; /** * @summary Store with keys as application instance index script directories full paths * and values as application instances dependent files full paths. */ protected dependencies: Map<string, Set<string>>; /** * @summary Store with keys as watched filesystem directories and values as * dependent application instance index script directories full paths. */ protected watchedDirs: Map<string, Set<string>>; protected watchHandleTimeouts: Map<string, NodeJS.Timeout>; /** * @summary Register constructor with stored server instance to call it back. * @param server */ constructor(server: Server); /** * @summary Set internal `Server` handling functionality. * @param errorsHandler */ SetErrorsHandler(errorsHandler: ErrorsHandler): this; /** * @summary Initialize filesystem change or rename handler for given * fullpath file to clear necessary require cache modules (only if necessary): */ AddWatchHandlers(requiredByFullPath: string, cacheKeysToWatchFullPaths: string[]): void; protected addWatchHandler(dirFullPathToWatch: string, dependentIndexScriptDirFullPath: string): void; /** * @summary Clear instance cache and require cache for all dependent index script directories. */ protected clearInstanceAndRequireCacheOnChange(dirFullPathToWatch: string, changedFileFullPath: string): Promise<boolean>; /** * @summary Check if given directory full path has already any other * parent directory recursive watched or if the given directory itself has a watched. * @param dirFullPath * @return Already watched full path to cover this directory. */ protected hasWatchHandler(dirFullPath: string): string; /** * @summary Try to search in application scripts cache for * any application instance to handle given directory or virtual directory request. * @param pathsToFound */ TryToFindParentDirectoryIndexScriptModule(pathsToFound: string[]): Record | null; GetIndexScriptModuleRecord(fullPath: string): Record | null; /** * @summary Set new application instance cache record. * @param appInstance * @param indexScriptModTime * @param indexScriptFileName * @param dirFullPath */ SetNewApplicationCacheRecord(appInstance: IApplication, indexScriptModTime: number, indexScriptFileName: string, dirFullPath: string): Register; /** * @summary Get registered running apps count. */ GetSize(): number; /** * @summary Stop all running registered app instances. * @param cb */ StopAll(cb?: () => void): void; /** * @summary Delete cached module from Node.JS require cache by full path. * @param indexScriptDirFullPath */ ClearModuleInstanceAndModuleRequireCache(indexScriptDirFullPath: string): void; /** * @summary Delete cached application index script module instance. * @param indexScriptDirFullPath */ ClearModuleInstance(indexScriptDirFullPath: string): this; /** * @summary Delete require cache for dependencies of application index script dir full path * delete require cache for index script file itself. * @param indexScriptDirFullPath * @param indexScriptFullPath */ ClearModuleRequireCache(cacheRecord: Record): this; /** * @summary Clear all require cache. */ ClearAllRequireCache(): Register; /** * @summary Get all required full paths as difference between application call and after application call. * @param cacheKeysBeforeRequire * @param cacheKeysAfterRequire * @param requiredBy * @param doNotIncludePaths */ static GetRequireCacheDifferenceKeys(cacheKeysBeforeRequire: string[], cacheKeysAfterRequire: string[], requiredBy: string, doNotIncludePaths: string[]): string[]; }