UNPKG

container.ts

Version:
53 lines (52 loc) 1.94 kB
/// <reference types="node" /> import { IModuleHook, Module } from "../../../container"; import { ErrorChain } from "../../error"; /** Assets files may be cached when read. */ export interface IAssetsCache { [key: string]: Buffer | string; } /** Assets log names. */ export declare enum EAssetsLog { Information = "Assets.Information" } /** Assets error codes. */ export declare enum EAssetsError { ReadFile = "AssetsError.ReadFile", JsonParse = "AssetsError.JsonParse", ReadDirectory = "AssetsError.ReadDirectory" } /** Assets error class. */ export declare class AssetsError extends ErrorChain { constructor(code: EAssetsError, cause?: Error, context?: object); } /** Assets file read options. */ export interface IAssetsReadOptions { encoding?: string; cache?: boolean; } /** Assets environment variable names. */ export declare enum EAssetsEnv { /** Assets directory path (required). */ Path = "ASSETS_PATH" } /** Assets read only files module. */ export declare class Assets extends Module { /** Default module name. */ static readonly moduleName: string; /** Absolute path to assets files directory. */ readonly envPath: string; /** Internal assets cache. */ protected readonly assetsCache: IAssetsCache; moduleUp(...args: IModuleHook[]): Promise<void>; /** Returns true if target file is cached. */ isCached(target: string, encoding?: string): boolean; readFile(target: string, options?: { cache?: boolean; }): Promise<Buffer>; readFile(target: string, options: IAssetsReadOptions): Promise<string>; /** Read asset file contents and parse JSON object. */ readJson<T>(target: string, options?: IAssetsReadOptions): Promise<T>; /** Read contents of assets directory. */ readDirectory(target?: string): Promise<string[]>; protected assetsRead(target: string, options?: IAssetsReadOptions): Promise<string | Buffer>; }