container.ts
Version:
Modular application framework
47 lines (46 loc) • 1.65 kB
TypeScript
/// <reference types="node" />
import { IModuleOptions, Module } from "../../container";
import { Observable } from "../../container/RxJS";
import { ErrorChain } from "../error";
/** Assets files may be cached when read. */
export interface IAssetsCache {
[key: string]: Buffer | string;
}
/** Assets error class. */
export declare class AssetsError extends ErrorChain {
constructor(name: string, value: string, cause?: Error);
}
/** Assets file read options. */
export interface IAssetsReadOptions {
encoding?: string;
cache?: boolean;
}
/** Assets read only files module. */
export declare class Assets extends Module {
/** Default module name. */
static readonly moduleName: string;
/** Environment variable names. */
static readonly ENV: {
PATH: string;
};
/** Error names. */
static readonly ERROR: {
DEPENDENCY: string;
} & {
READ_FILE: string;
JSON_PARSE: string;
};
protected readonly path: string;
protected readonly cache: IAssetsCache;
constructor(options: IModuleOptions);
/** Returns true if target file is cached. */
isCached(target: string, encoding?: string): boolean;
readFile(target: string, options?: {
cache?: boolean;
}): Observable<Buffer>;
readFile(target: string, options: IAssetsReadOptions): Observable<string>;
/** Read asset file contents and parse JSON object. */
readJson<T>(target: string, options?: IAssetsReadOptions): Observable<T>;
protected readonly envPath: string;
protected read<T extends string | Buffer>(target: string, options?: IAssetsReadOptions): Observable<T>;
}