/// <reference path="type.d.ts" />
/// <reference path="object.d.ts" />

import type { DataSource, DbDataSource, IncrementalMatch, LogStatus, TaskAction, ViewEngine } from './squared';

import type { ExternalAsset, FileCommand, FileData, IFileThread, OutputFinalize } from './asset';
import type { BucketWebsiteOptions, CloudDatabase, CloudFeatures, CloudFunctions, CloudService, CloudStorage, CloudStorageDownload, CloudStorageUpload, UploadAssetOptions } from './cloud';
import type { BufferResult, CompressFormat, CompressLevel, ReadableOptions, TryFileCompressor } from './compress';
import type { ClientDbConstructor, HostInitConfig, IAbortComponent, IClient, IClientDb, IPermission, JoinQueueOptions, PermissionReadWrite, ResumeThreadOptions, ThreadCountStat } from './core';
import type { BatchQueryResult, DB_TYPE, ErrorQueryCallback, ExecuteBatchQueryOptions, ExecuteQueryOptions, HandleFailOptions, ProcessRowsOptions, QueryResult, SQL_COMMAND } from './db';
import type { AsSourceFileOptions, ConfigOrTransformer, CustomizeOptions as CustomizeDocument, GenerateLintTableOptions, LintMessage, PluginConfig, SourceCode, SourceInput, SourceMap, SourceMapOptions, TransformAction, TransformCallback, TransformOutput, TransformResult, UpdateGradleOptions } from './document';
import type { AssetContentOptions, ChecksumOptions, DeleteFileAddendum, FileOutput, FinalizeResult, FindAssetOptions, IHttpDiskCache, IHttpMemoryCache, ImageMimeMap, InstallData, PostFinalizeCallback, ReplaceOptions } from './filemanager';
import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from './http';
import type { CommandData, CropData, QualityData, ResizeData, RotateData, TransformOptions } from './image';
import type { ExecCommand, LOG_TYPE, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogState, LogTime, LogType, LogValue, STATUS_TYPE, StatusType } from './logger';
import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, FileTypeFormat, GlobDirOptions, MoveFileOptions, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, TempDirOptions, WriteFileOptions } from './module';
import type { RequestData, Settings } from './node';
import type { ApplyOptions, Aria2Options, BufferFormat, DataEncodedResult, DataObjectResult, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, PutOptions, ReadExpectType, RequestInit, StatusOnCallback } from './request';
import type { ClientModule, CloudAuthSettings, CloudModule, CloudServiceOptions, CompressModule, CompressSettings, DbCoerceSettings, DbModule, DbSourceOptions, DnsLookupSettings, DocumentComponent, DocumentComponentOption, DocumentModule, HandlerSettings, HttpConnectSettings, HttpMemorySettings, ImageModule, LoggerFormat, LoggerFormatSettings, PoolConfig, RequestModule, RequestSettings, TaskModule, WatchModule } from './settings';
import type { Command, SpawnResult } from './task';
import type { IFileGroup, ModifiedPostFinalizeListener, SecureOptions, WatchInitResult } from './watch';

import type { SpawnOptions } from 'child_process';
import type { BinaryLike, BinaryToTextEncoding, HashOptions } from 'crypto';
import type { NoParamCallback, WriteStream } from 'fs';
import type { ClientRequest, OutgoingHttpHeaders } from 'http';
import type { LookupFunction } from 'net';
import type { Readable, Writable } from 'stream';
import type { SecureContextOptions } from 'tls';
import type { BrotliCompress, Gzip } from 'zlib';
// @ts-ignore
import type { FileTypeResult } from 'file-type';

import type * as EventEmitter from 'events';
// @ts-ignore
import type * as ws from 'ws';

type BufferView = Bufferable | NodeJS.ArrayBufferView;
type CpuUsage = NodeJS.CpuUsage;

declare namespace functions {
    type WatchInstance<T extends ExternalAsset, U extends WatchModule = WatchModule> = IWatch<IFileManager<T>, T, U, ModifiedPostFinalizeListener<T>>;
    type FormatMessageArgs = [type: LogType, title: string, value: LogValue, message: unknown, options: LogMessageOptions];

    interface IScopeOrigin<T extends IHost = IHost, U extends IModule = IModule> {
        host?: T;
        instance?: U;
    }

    interface IExternalConfig<T extends HandlerSettings, U extends PlainObject = PlainObject> {
        module: T;
        init(...args: unknown[]): this;
        get settings(): U;
    }

    interface IExternalFunction<T extends FunctionType<any, any>> {
        set extensions(values: unknown[]);
        get extensions(): T[];
    }

    interface ICompress<T extends CompressModule = CompressModule, U extends CompressSettings = CompressSettings> extends IModule, IExternalConfig<T, U> {
        level: ObjectMap<number>;
        compressors: ObjectMap<TryFileCompressor>;
        register(format: string, callback: TryFileCompressor): void;
        getLevel(value: string, fallback?: number): Undef<number>;
        getReadable(file: string | URL | Buffer, options?: ReadableOptions): Readable;
        createGzip(file: string | Buffer, options?: CompressLevel): Gzip;
        createBrotliCompress(file: string | Buffer, options?: CompressLevel): BrotliCompress;
        createWriteStreamAsGzip(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
        createWriteStreamAsBrotli(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
        writeGzip(file: string | Buffer, output: string, options?: CompressLevel): Promise<void>;
        writeBrotli(file: string | Buffer, output: string, options?: CompressLevel): Promise<void>;
        tryFile(file: string | Buffer, options: CompressFormat): Promise<BufferResult>;
        tryFile(file: string | Buffer, output: string, options?: CompressFormat): Promise<BufferResult>;
        tryImage(file: string, options: CompressFormat): Promise<BufferResult>;
        tryImage(file: string | Buffer, output: string, options?: CompressFormat): Promise<BufferResult>;
        set chunkSize(value: Undef<number | string>);
        get chunkSize(): Undef<number>;
    }

    interface CompressConstructor<T extends CompressModule = CompressModule, U extends CompressSettings = CompressSettings> extends ModuleConstructor {
        singleton(): ICompress<T, U>;
        readonly prototype: ICompress<T, U>;
        new(module?: U): ICompress<T, U>;
    }

    interface IImage<T extends IHost = IHost, U extends ImageModule = ImageModule> extends IClient<T, U> {
        resizeData?: ResizeData;
        cropData?: CropData;
        rotateData?: RotateData;
        qualityData?: QualityData;
        methodData?: [string, unknown[]?][];
        opacityValue?: number;
        setCommand(value: string | CommandData, outputAs?: string): void;
        getCommand(): string;
        parseCommand(value: string): CommandData;
        parseMethod(value: string): Undef<[string, unknown[]?][]>;
        parseResize(value: string): Undef<ResizeData>;
        parseCrop(value: string): Undef<CropData>;
        parseRotate(value: string): Undef<RotateData>;
        parseQuality(value: string): Undef<QualityData>;
        parseOpacity(value: string): number;
        using?<V extends ExternalAsset>(data: IFileThread<V>, command: string): Promise<unknown>;
        get outputAs(): string;
    }

    interface ImageConstructor<T extends IHost = IHost, U extends ImageModule = ImageModule> extends ModuleConstructor {
        readonly REGEXP_SIZERANGE: RegExp;
        transform<V extends TransformOptions>(file: string, command: string, options?: V): Promise<V extends { tempFile: true } ? string : Null<Buffer>>;
        clamp(value: unknown, min?: number, max?: number): number;
        isBinary(mime: unknown): mime is string;
        toABGR(buffer: Uint8Array | Buffer): Buffer;
        readonly prototype: IImage<T, U>;
        new(module?: U, ...args: unknown[]): IImage<T, U>;
    }

    interface ITask<T extends IHost = IHost, U extends TaskModule = TaskModule> extends IClient<T, U> {
        using?<V extends ExternalAsset>(data: IFileThread<V>): Promise<unknown>;
        collect?(items: unknown[], preceding?: boolean): Promise<SpawnResult>[];
        map?(tasks: Command[]): Promise<Void<SpawnResult>>[];
        series?(tasks: Command[]): Promise<unknown>;
        parallel?(tasks: Command[]): Promise<unknown>;
        spawn?(task: PlainObject, callback: (result?: SpawnResult) => void): void;
        execute?<V extends IFileManager<W>, W extends ExternalAsset>(manager: V, task: PlainObject, callback: (value?: unknown) => void): void;
    }

    interface TaskConstructor<T extends IHost = IHost, U extends TaskModule = TaskModule> extends ModuleConstructor {
        finalize<V extends ExternalAsset>(this: T, instance: ITask<T, U>, assets: V[]): Promise<unknown>;
        readonly prototype: ITask<T, U>;
        new(module?: U, ...args: unknown[]): ITask<T, U>;
    }

    interface IDb<T extends IHost = IHost, U extends DbModule = DbModule, V extends DbDataSource = DbDataSource, W extends DbSourceOptions = DbSourceOptions, X extends DbCoerceSettings = DbCoerceSettings> extends IClientDb<T, U, V, W, X> {
        setCredential(item: V): Promise<void>;
        getCredential<Y = PlainObject>(item: V): Undef<Y>;
        hasSource(source: string, ...type: number[]): boolean;
        applyCommand(...items: V[]): void;
        executeQuery(item: V, callback: ErrorQueryCallback): Promise<QueryResult>;
        executeQuery(item: V, sessionKey: string): Promise<QueryResult>;
        executeQuery(item: V, options?: ExecuteQueryOptions | string): Promise<QueryResult>;
        executeBatchQuery(batch: V[], callback: ErrorQueryCallback, outResult?: BatchQueryResult): Promise<BatchQueryResult>;
        executeBatchQuery(batch: V[], sessionKey: string, outResult?: BatchQueryResult): Promise<BatchQueryResult>;
        executeBatchQuery(batch: V[], options?: ExecuteBatchQueryOptions | string, outResult?: BatchQueryResult): Promise<BatchQueryResult>;
        processRows(batch: V[], tasks: Promise<Null<QueryResult>>[], parallel: boolean): Promise<BatchQueryResult>;
        processRows(batch: V[], tasks: Promise<Null<QueryResult>>[], options?: ProcessRowsOptions, outResult?: BatchQueryResult): Promise<BatchQueryResult>;
        handleFail(err: unknown, item: V, options?: HandleFailOptions): boolean;
        readTLSCert(value: unknown, cache?: boolean): string;
        readTLSConfig(options: SecureContextOptions, cache?: boolean): void;
        settingsOf(source: string, name: keyof Omit<W, "coerce">): unknown;
        settingsOf(source: string, name: "coerce", component: keyof X): unknown;
        settingsKey(source: string, name: keyof Omit<W, "coerce">): unknown;
        settingsKey(source: string, name: "coerce", component: keyof X): unknown;
        getPoolConfig(source: string, uuidKey?: string): Undef<Required<PoolConfig>>;
        get sourceType(): DB_TYPE;
        get commandType(): SQL_COMMAND;
    }

    interface DbConstructor<T extends IHost = IHost, U extends DbModule = DbModule, V extends DbDataSource = DbDataSource> extends ClientDbConstructor<T> {
        setPoolConfig(value: ObjectMap<PoolConfig>): void;
        getPoolConfig(source: string): Undef<Required<PoolConfig>>;
        readonly prototype: IDb<T, U, V>;
        new(module?: U, database?: V[], ...args: unknown[]): IDb<T, U, V>;
    }

    interface ICloud<T extends IHost = IHost, U extends CloudModule = CloudModule, V extends CloudDatabase = CloudDatabase, W extends CloudServiceOptions = CloudServiceOptions, X extends DbCoerceSettings = DbCoerceSettings & CloudAuthSettings> extends IClientDb<T, U, V, W, X> {
        readonly uploaded: string[];
        readonly downloaded: string[];
        createBucket(service: string, credential: unknown, bucket: string, acl?: unknown, options?: unknown): Promise<boolean>;
        createBucket(service: string, credential: unknown, bucket: string, publicRead?: boolean): Promise<boolean>;
        setBucketPolicy(service: string, credential: unknown, bucket: string, options: unknown): Promise<boolean>;
        setBucketTagging(service: string, credential: unknown, bucket: string, options: unknown): Promise<boolean>;
        setBucketWebsite(service: string, credential: unknown, bucket: string, options: BucketWebsiteOptions): Promise<boolean>;
        deleteObjects(service: string, credential: unknown, bucket: string, recursive?: boolean): Promise<void>;
        uploadObject(service: string, credential: unknown, bucket: string, upload: CloudStorageUpload, localUri: string, beforeResolve?: (value: string) => Void<Promise<void>>): Promise<string>;
        downloadObject(service: string, credential: unknown, bucket: string, download: CloudStorageDownload, beforeResolve?: (value: Null<Bufferable>) => Void<Promise<Undef<string>>>): Promise<Bufferable>;
        getStorage(action: CloudFunctions, data: Undef<CloudStorage[]>): Undef<CloudStorage>;
        hasStorage(action: CloudFunctions, storage: CloudStorage): CloudStorageUpload | false;
        getDatabaseRows(item: V, ignoreErrors: boolean, sessionKey?: string): Promise<QueryResult>;
        getDatabaseRows(item: V, sessionKey?: string): Promise<QueryResult>;
        getDatabaseBatchRows(batch: V[], ignoreErrors: boolean, sessionKey?: string): Promise<BatchQueryResult>;
        getDatabaseBatchRows(batch: V[], sessionKey?: string): Promise<BatchQueryResult>;
        hasCredential(feature: CloudFeatures, data: CloudService, credential?: unknown): boolean;
        getCredential(item: CloudService, unused?: boolean): PlainObject;
        getSettings(service: string): Undef<AnyObject>;
        settingsOf(service: string, name: "cache"): unknown;
        settingsOf(service: string, name: "coerce", component: keyof DbCoerceSettings): unknown;
        settingsOf(service: string, name: "auth", component: keyof CloudAuthSettings): unknown;
        getUploadHandler(service: string, credential: unknown): FunctionType<void>;
        getDownloadHandler(service: string, credential: unknown): FunctionType<void>;
        resolveService(service: string, folder?: string): string;
    }

    interface CloudConstructor<T extends IHost = IHost, U extends CloudModule = CloudModule, V extends CloudDatabase = CloudDatabase> extends ClientDbConstructor<T> {
        LOG_CLOUD_FAIL: LogMessageOptions;
        LOG_CLOUD_COMMAND: LogMessageOptions;
        LOG_CLOUD_WARN: LogMessageOptions;
        LOG_CLOUD_UPLOAD: LogMessageOptions;
        LOG_CLOUD_DOWNLOAD: LogMessageOptions;
        LOG_CLOUD_DELETE: LogMessageOptions;
        LOG_CLOUD_DELAYED: LogMessageOptions;
        finalize(this: T, instance: ICloud<T, U, V>): Promise<void>;
        uploadAsset<W extends IFileManager<X>, X extends ExternalAsset>(state: IScopeOrigin<W, ICloud<W>>, file: X, options: UploadAssetOptions): Promise<void>[];
        uploadAsset<W extends IFileManager<X>, X extends ExternalAsset>(state: IScopeOrigin<W, ICloud<W>>, file: X, ignoreProcess: boolean): Promise<void>[];
        uploadAsset<W extends IFileManager<X>, X extends ExternalAsset>(state: IScopeOrigin<W, ICloud<W>>, file: X, contentType?: string | boolean | UploadAssetOptions, ignoreProcess?: boolean): Promise<void>[];
        sanitizeAssets<W extends ExternalAsset>(assets: W[]): W[];
        readonly prototype: ICloud<T, U, V>;
        new(module?: U, database?: CloudDatabase[], ...args: unknown[]): ICloud<T, U, V>;
    }

    interface IDocument<T extends IFileManager<U>, U extends ExternalAsset = ExternalAsset, V extends ClientModule = DocumentModule, W extends DocumentComponent = DocumentComponent, X extends DocumentComponentOption = DocumentComponentOption, Y extends ICloud = ICloud<T>> extends IClient<T, V, TransformCallback<T, U>> {
        Db: Null<IDb>;
        assets: U[];
        config: StandardMap;
        init(assets: U[], config?: HostInitConfig): this;
        customize(options?: CustomizeDocument): void;
        findConfig(data: object, name: string, type?: string): PluginConfig;
        loadConfig(data: object, name: string): Optional<ConfigOrTransformer>;
        asSourceFile(value: string, cache: boolean): unknown;
        asSourceFile(value: string, options?: AsSourceFileOptions): unknown;
        findVersion(name: ArrayOf<string>, fallback?: string): string;
        findSourceScope(uri: string, imports: AnyObject): StringMap[];
        findSourceRoot(uri: string, imports?: StringMap): Undef<string>;
        resolveDir(name: string, ...paths: string[]): Undef<string>;
        locateSourceFiles(file: U, code?: string, bundleContent?: string[]): (imports?: StringMap) => Undef<SourceInput>;
        resolveSourceFile(file: U): (code?: string, imports?: StringMap) => Undef<SourceInput<string>>;
        tryParse(source: string, format: string, options?: PlainObject): unknown;
        forDb(item: DataSource): boolean;
        hasEval(name: string): boolean;
        settingsOf(name: keyof W, option: keyof X): unknown;
        parseTemplate(viewEngine: ViewEngine | string, template: string, data: unknown[]): Promise<Null<string>>;
        transform(type: string, code: string, format: ArrayOf<string>, options?: TransformOutput & TransformAction): Promise<Void<TransformResult>>;
        abort(err: Error): void;
        abort(name?: keyof W, reason?: unknown): void;
        restart(): void;
        using?(data: IFileThread<U>): Promise<unknown>;
        setLocalUri?(file: U, replace?: boolean): void;
        resolveUri?(file: U, source: string): string;
        resolveUri?(file: U, source: string, trailing: string): TupleOf<string>;
        resolveImports?(file: U, code: string, baseFile?: string | U): Undef<string>;
        replaceContent?(source: string, statement: RegExpExecArray | string, mimeType?: string): Undef<string>;
        addCopy?(data: FileCommand<U>, saveAs: string, replace?: boolean): Undef<string>;
        writeImage?(output: OutputFinalize<U>): boolean;
        cloudInit?(state: IScopeOrigin<T, Y>): void;
        cloudObject?(state: IScopeOrigin<T, Y>, file: U): boolean;
        cloudUpload?(state: IScopeOrigin<T, Y>, file: U, url: string, active: boolean): Promise<boolean>;
        cloudFinalize?(state: IScopeOrigin<T, Y>): Promise<unknown[]>;
        watchInit?(watch: IFileGroup<U>, assets: U[], sanitize?: boolean): Undef<WatchInitResult>;
        watchModified?(watch: IFileGroup<U>, assets?: U[]): PostFinalizeCallback;
        set dataSource(value: DataSource[]);
        get dataSource(): DataSource[];
        set imports(value);
        get imports(): StringMap;
        get watching(): boolean;
    }

    interface DocumentConstructor<T extends IFileManager<U>, U extends ExternalAsset = ExternalAsset, V extends ClientModule = DocumentModule, W extends DocumentComponent = DocumentComponent, X extends DocumentComponentOption = DocumentComponentOption, Y extends ICloud = ICloud<T>> extends ModuleConstructor {
        finalize(this: T, instance: IDocument<T, U, V, W, X, Y>): Promise<unknown>;
        /** @deprecated */
        createSourceMap(code: string, remove: boolean): SourceMap;
        /** @deprecated */
        createSourceMap(code: string, uri?: string, remove?: boolean): SourceMap;
        writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): Undef<string>;
        updateGradle(source: string, namespaces: string[], value: string, upgrade: boolean): string;
        updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions): string;
        generateLintTable(messages: LintMessage[], options: GenerateLintTableOptions): LogComponent[];
        cleanup?(this: T, instance: IDocument<T, U, V, W, X, Y>): Promise<unknown>;
        sanitizeAssets?(assets: U[], exclusions?: unknown[]): U[];
        readonly prototype: IDocument<T, U, V, W, X, Y>;
        new(module?: V, ...args: unknown[]): IDocument<T, U, V, W, X, Y>;
    }

    interface IWatch<T extends IFileManager<U>, U extends ExternalAsset = ExternalAsset, V extends WatchModule = WatchModule, W extends FunctionType<unknown, any> = ModifiedPostFinalizeListener<U>> extends IClient<T, V, W> {
        connectTimeout: number;
        init(config?: HostInitConfig): this;
        start(assets: U[], permission?: Null<IPermission>): void;
        modified(watch: IFileGroup<U>): Promise<Void<FinalizeResult>>;
        configureServer(options: SecureOptions): boolean;
        setCA(value: string): boolean;
        setSSLKey(value: string): boolean;
        setSSLCert(value: string): boolean;
        hasSecureProtocol(): boolean;
        whenModified?(assets: U[], postFinalize: PostFinalizeCallback): IFileManager<U>;
        whenModified?(assets: U[], sanitize?: boolean, postFinalize?: PostFinalizeCallback): IFileManager<U>;
        set assets(value: U[]);
        get assets(): U[];
        set interval(value);
        get interval(): number;
        set port(value);
        get port(): number;
        set securePort(value);
        get securePort(): number;
    }

    interface WatchConstructor<T extends IFileManager<U>, U extends ExternalAsset = ExternalAsset, V extends WatchModule = WatchModule, W extends FunctionType<unknown, any> = ModifiedPostFinalizeListener<U>> extends ModuleConstructor {
        createServer(port: number, active: boolean): Null<ws.Server>;
        createServer(port: number, secure?: Null<SecureOptions>, active?: boolean): Null<ws.Server>;
        shutdown(): void;
        setTimeout(value: number | string): void;
        checkTimeout(client: ws): boolean;
        readonly prototype: IWatch<T, U, V, W>;
        new(module?: V): IWatch<T, U, V, W>;
        new(interval?: number, port?: number, securePort?: number, extensions?: unknown[]): IWatch<T, U, V, W>;
    }

    interface IRequest<T extends RequestModule = RequestModule, U extends RequestSettings = RequestSettings> extends IModule, IExternalConfig<T, U> {
        startTime: number;
        acceptEncoding: boolean;
        keepAlive: Null<boolean>;
        readTimeout: number;
        readExpect: ReadExpectType;
        proxy: Null<ProxySettings>;
        init(config?: RequestInit): this;
        apply(options: ApplyOptions): this;
        addDns(hostname: string, address: string, timeout: number): void;
        addDns(hostname: string, address: string, family?: number | string, timeout?: number): void;
        lookupDns(hostname: string): LookupFunction;
        proxyOf(uri: string, localhost?: boolean): Undef<ProxySettings>;
        statusOn(name: ArrayOf<number>, callback: StatusOnCallback): void;
        statusOn(name: ArrayOf<number>, globUrl: string, callback: StatusOnCallback): void;
        headersOn(name: ArrayOf<string>, callback: HeadersOnCallback): void;
        headersOn(name: ArrayOf<string>, globUrl: string, callback: HeadersOnCallback): void;
        headersOf(uri: string): Undef<OutgoingHttpHeaders>;
        aria2c(uri: string | URL, pathname: string): Promise<string[]>;
        aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
        json(uri: string | URL, options?: OpenOptions): Promise<Null<object>>;
        pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
        opts(url: string | URL, options?: OpenOptions): HostConfig;
        open(uri: string | URL, options: OpenOptions): HttpRequestClient;
        head(uri: string | URL, options?: OpenOptions): ClientRequest;
        put<V extends { format: undefined; encoding: undefined }>(uri: string | URL, data: unknown, contentType: string): Promise<DataObjectResult<V>>;
        put<V extends PutOptions>(uri: string | URL, data: unknown, options: V): Promise<DataObjectResult<V>>;
        put<V extends PutOptions>(uri: string | URL, data: unknown, contentType?: string | V, options?: V): Promise<DataObjectResult<V>>;
        post<V extends { format: undefined; encoding: undefined }>(uri: string | URL, data: unknown, contentType: string): Promise<DataObjectResult<V>>;
        post<V extends { format: undefined; encoding: undefined }>(uri: string | URL, parts: FormDataPart[]): Promise<DataObjectResult<V>>;
        post<V extends { format: undefined; encoding: undefined }>(uri: string | URL, form: AnyObject, parts: FormDataPart[]): Promise<DataObjectResult<V>>;
        post<V extends PostOptions>(uri: string | URL, data: unknown, options: V): Promise<DataObjectResult<V>>;
        post<V extends PostOptions>(uri: string | URL, data: unknown, contentType?: string | FormDataPart[] | V, options?: V): Promise<DataObjectResult<V>>;
        get<V extends OpenOptions, W extends V | BufferFormat>(uri: string | URL, options?: W): Promise<W extends BufferFormat ? Null<object> : DataEncodedResult<V>>;
        detach(singleton?: boolean): void;
        reset(): void;
        close(): void;
        set agentTimeout(value);
        get agentTimeout(): number;
        set httpVersion(value);
        get httpVersion(): Null<HttpProtocolVersion>;
        set ipVersion(value);
        get ipVersion(): InternetProtocolVersion;
    }

    interface RequestConstructor<T extends RequestModule = RequestModule, U extends RequestSettings = RequestSettings> extends ModuleConstructor {
        readCACert(value: string, cache?: boolean): string;
        readTLSKey(value: string, cache?: boolean): string;
        readTLSCert(value: string, cache?: boolean): string;
        isCert(value: string): boolean;
        fromURL(url: URL, value: string): string;
        fromStatusCode(value: number | string): string;
        defineHttpAgent(options: HttpAgentSettings): void;
        defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
        getAria2Path(): string;
        readonly prototype: IRequest<T, U>;
        new(module?: T): IRequest<T, U>;
    }

    interface IFileManager<T extends ExternalAsset = ExternalAsset> extends IHost, Set<string> {
        processTimeout: number;
        cacheToDisk: IHttpDiskCache<T>;
        cacheToMemory: IHttpMemoryCache<T>;
        Request: IRequest;
        Document: InstallData<IDocument<IFileManager<T>, T>, DocumentConstructor<IFileManager<T>, T>>[];
        Task: InstallData<ITask, TaskConstructor>[];
        Image: Null<ImageMimeMap>;
        Cloud: Null<ICloud>;
        Watch: Null<WatchInstance<T>>;
        Compress: Null<ICompress>;
        readonly documentAssets: T[];
        readonly taskAssets: (T & Required<TaskAction>)[];
        readonly dataSourceItems: DataSource[];
        readonly files: Set<string>;
        readonly filesQueued: Set<string>;
        readonly filesToRemove: Set<string>;
        readonly filesToCompare: Map<T, string[]>;
        readonly contentToAppend: Map<string, string[]>;
        readonly contentToReplace: Map<string, string[]>;
        readonly processing: IFileThread<T>[];
        readonly fetchedAssets: T[];
        readonly copiedAssets: T[];
        readonly emptyDir: Set<string>;
        install(name: "document", handler: string, module?: DocumentModule, ...args: unknown[]): Undef<IDocument<IFileManager<T>, T>>;
        install(name: "document", target: DocumentConstructor<IFileManager<T>, T>, module?: DocumentModule, ...args: unknown[]): Undef<IDocument<IFileManager<T>, T>>;
        install(name: "task", handler: string, module?: TaskModule, ...args: unknown[]): Undef<ITask>;
        install(name: "task", target: TaskConstructor, module?: TaskModule, ...args: unknown[]): Undef<ITask>;
        install(name: "cloud", handler: string, module?: CloudModule, ...args: unknown[]): Undef<ICloud>;
        install(name: "cloud", module?: CloudModule): Undef<ICloud>;
        install(name: "image", handler: string, module?: ImageModule, ...args: unknown[]): Undef<IImage>;
        install(name: "image", target: ImageConstructor, module?: ImageModule, ...args: unknown[]): Undef<IImage>;
        install(name: "image", targets: Map<string, ImageConstructor>, module?: ImageModule): void;
        install(name: "watch", module: WatchModule): Undef<WatchInstance<T>>;
        install(name: "watch", interval?: number | string, port?: number | string, securePort?: number | string, extensions?: unknown[]): Undef<WatchInstance<T>>;
        install(name: "compress", module?: CompressModule): Undef<ICompress>;
        install(name: string, ...args: unknown[]): Undef<IModule>;
        using(...items: FirstOf<T>): this;
        contains(item: T, condition?: FunctionArgs<[T], boolean>): boolean;
        removeCwd(value: unknown): string;
        findAsset(value: string | URL, instance?: IModule | FindAssetOptions<T>): Undef<T>;
        removeAsset(file: T): boolean;
        replace(file: T, replaceWith: string, mimeType: Undef<string>): boolean;
        replace(file: T, replaceWith: string, options?: ReplaceOptions): boolean;
        rename(file: T, value: string): boolean;
        performAsyncTask(): void;
        removeAsyncTask(): void;
        completeAsyncTask(err?: unknown, uri?: string, parent?: T, type?: number): void;
        performFinalize(override?: boolean): void;
        hasDocument(instance: IModule, document: Undef<ArrayOf<string>>): boolean;
        getDocumentAssets(instance: IModule, condition?: FunctionArgs<[T], boolean>): T[];
        getDataSourceItems(instance: IModule, condition?: FunctionArgs<[DataSource], boolean>): DataSource[];
        checkFilename(file: T, pathname?: string): string;
        setLocalUri(file: T, replace?: boolean): FileOutput;
        getLocalUri(data: FileData<T>): string;
        getMimeType(data: FileData<T>): string;
        openThread(instance: IModule, data: IFileThread<T>, timeout?: number): boolean;
        closeThread(instance: Null<IModule>, data: IFileThread<T>, callback?: FunctionType<void>): boolean;
        addProcessTimeout(instance: IModule, file: T, timeout: number): void;
        removeProcessTimeout(instance: IModule, file: T): void;
        getProcessTimeout(handler: InstallData): number;
        clearProcessTimeout(): void;
        scheduleTask(url: string | URL, data: unknown, priority: number): Promise<unknown>;
        scheduleTask(url: string | URL, data: unknown, thenCallback?: FunctionType, catchCallback?: FunctionType, priority?: number): Promise<unknown>;
        setTaskLimit(value: number): void;
        addDownload(value: number | Bufferable, encoding: BufferEncoding): number;
        addDownload(value: number | Bufferable, type?: number | BufferEncoding, encoding?: BufferEncoding): number;
        getDownload(type?: number): TupleOf<number>;
        transformAsset(data: IFileThread<T>, parent?: T, override?: boolean): Promise<boolean>;
        addCopy(data: FileCommand<T>, saveAs?: string, replace?: boolean): Undef<string>;
        findMime(file: T, rename?: boolean): Promise<string>;
        getUTF8String(file: T, uri?: string): string;
        getBuffer<U>(file: T, minStreamSize?: U): U extends number ? Promise<Null<Buffer>> : Null<Buffer>;
        getCacheDir(url: string | URL, createDir?: boolean): string;
        setAssetContent(file: T, content: string, options?: AssetContentOptions): string;
        getAssetContent(file: T, content?: string): Undef<string>;
        writeBuffer(file: T, options?: WriteFileOptions): Null<Buffer>;
        writeImage(document: ArrayOf<string>, output: OutputFinalize<T>): boolean;
        compressFile(file: T, overwrite?: boolean): Promise<unknown>;
        fetchObject(uri: string | URL, format: BufferFormat): Promise<Null<object>>;
        fetchObject(uri: string | URL, options?: OpenOptions | BufferFormat): Promise<Null<object>>;
        fetchBuffer<U extends OpenOptions>(uri: string | URL, options?: U): Promise<DataEncodedResult<U>>;
        fetchFiles(uri: string | URL, pathname: string): Promise<string[]>;
        fetchFiles(uri: string | URL, options?: Aria2Options): Promise<string[]>;
        updateProgress(name: "request", id: number | string, receivedBytes: number, totalBytes: number, dataTime?: HighResolutionTime): void;
        start(emptyDir?: boolean): Promise<FinalizeResult>;
        processAssets(emptyDir?: boolean, using?: T[]): void;
        deleteFile<U extends Promise<void>>(src: string, promises: boolean): U;
        deleteFile<U extends Promise<void>>(src: string, options: DeleteFileOptions & DeleteFileAddendum, promises: boolean): U;
        deleteFile<U extends NoParamCallback>(src: string, callback?: U): unknown;
        deleteFile<U extends NoParamCallback>(src: string, options: DeleteFileOptions & DeleteFileAddendum, callback?: U): unknown;
        restart(recursive?: boolean | "abort", emptyDir?: boolean): void;
        restart(recursive?: boolean | "abort", exclusions?: string[], emptyDir?: boolean): void;
        finalizeCompress(assets: T[]): Promise<void>;
        finalizeDocument(): Promise<void>;
        finalizeTask(assets: (T & Required<TaskAction>)[]): Promise<void>;
        finalizeCloud(): Promise<void>;
        finalizeChecksum(): Promise<void>;
        finalizeCleanup(): Promise<void>;
        finalize(): Promise<void>;
        close(): void;
        reset(): boolean;
        get baseDirectory(): string;
        get config(): RequestData<T>;
        get assets(): T[];
        get incremental(): IncrementalMatch;
        set restarting(value);
        get restarting(): boolean;
        get delayed(): number;
        set cleared(value);
        get cleared(): boolean;
        set finalizeState(value);
        get finalizeState(): number;

        /* Set */
        add(value: string, parent?: T, type?: number): this;
        delete(value: string, emptyDir?: boolean): boolean;
        has(value: unknown): value is string;

        /* EventEmitter */
        on(event: "end", listener: PostFinalizeCallback): this;
        on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
        on(event: "error", listener: (err: Error) => void): this;
        on(event: "file:read", listener: (src: string, data: Bufferable, options?: ReadFileOptions) => void): this;
        on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
        on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
        on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
        on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
        on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
        on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
        once(event: "end", listener: PostFinalizeCallback): this;
        once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
        once(event: "error", listener: (err: Error) => void): this;
        once(event: "file:read", listener: (src: string, data: Bufferable, options?: ReadFileOptions) => void): this;
        once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
        once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
        once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
        once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
        once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
        once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
        emit(event: "end", result: FinalizeResult): boolean;
        emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
        emit(event: "error", err: Error): boolean;
        emit(event: "file:read", src: string, data: Bufferable, options?: ReadFileOptions): boolean;
        emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
        emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
        emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
        emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
        emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
        emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
    }

    interface FileManagerConstructor<T extends ExternalAsset> extends HostConstructor {
        purgeMemory(percent?: number, limit?: number | boolean, parent?: number | boolean): Promise<number>;
        loadSettings(settings: Settings, password?: string): boolean;
        loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
        sanitizeAssets(assets: T[], exclusions?: string[]): T[];
        writeChecksum(root: string, options: ChecksumOptions): Promise<string[]>;
        writeChecksum(root: string, to?: string | ChecksumOptions, options?: ChecksumOptions): Promise<Null<string[]>>;
        verifyChecksum(root: string, options: ChecksumOptions): Promise<Null<[string[], string[], number]>>;
        verifyChecksum(root: string, from?: string | ChecksumOptions, options?: ChecksumOptions): Promise<Null<[string[], string[], number]>>;
        createFileThread(host: IFileManager<T>, file: T): IFileThread<T>;
        setTimeout(options: ObjectMap<number | string>): void;
        defineHttpCache(options: HttpMemorySettings, disk?: boolean): void;
        defineHttpConnect(options: HttpConnectSettings): void;
        readonly prototype: IFileManager<T>;
        new(baseDirectory: string, config: RequestData<T>, postFinalize?: PostFinalizeCallback): IFileManager<T>;
        new(baseDirectory: string, config: RequestData<T>, permission?: Null<IPermission>, postFinalize?: PostFinalizeCallback): IFileManager<T>;
    }

    interface IHost extends IModule {
        restartable: boolean;
        readonly modules: Set<IModule>;
        readonly subProcesses: Set<IModule>;
        readonly startTime: number;
        using(...items: FirstOf<unknown>): this;
        contains(item: unknown, condition?: FunctionType<boolean, any>): boolean;
        find(name: string): Undef<IModule>;
        findAll(name: string): IModule[];
        willLog(name: string): boolean;
        ignoreLog(values: boolean | ArrayOf<string>): void;
        collectLog(level?: boolean): LogStatus<StatusType>[];
        pauseLog(type?: string): void;
        resumeLog(type?: string): void;
        hasLog(type: string): boolean;
        delayMessage(...args: unknown[]): void;
        willAbort(value: string | IModule): boolean;
        loadModule(name: string, ...args: any[]): Null<IModule>;
        retain(process: IModule): void;
        release(process: IModule, log?: boolean): boolean;
        restart(...args: unknown[]): void;
        joinQueue(options?: JoinQueueOptions): boolean;
        updateProgress(name: string, ...args: unknown[]): void;
        resumeThread?(options: ResumeThreadOptions): void;
        set host(value);
        get host(): null;
        get config(): Readonly<HostInitConfig>;
        get username(): string;
        set done(value);
        get done(): boolean;
        get queued(): boolean;
        get logState(): LogState;
        get errorCount(): number;
    }

    interface HostConstructor extends ModuleConstructor {
        loadSettings(settings: Settings, password?: string): boolean;
        loadSettings(settings: Settings, permission?: PermissionReadWrite, password?: string): boolean;
        isPermission(value: unknown): value is IPermission;
        createPermission(all?: boolean, freeze?: boolean): IPermission;
        kill(username: string, iv: BinaryLike, all: true): number;
        kill(username: string, iv: BinaryLike, pid: ArrayOf<number>): number;
        getThreadCount(full: true): ThreadCountStat;
        getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
        getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
        getLogDelayed(): FormatMessageArgs[];
        getPermissionFromSettings(): IPermission;
        readonly prototype: IHost;
        new(config?: HostInitConfig): IHost;
    }

    interface IModule<T extends IHost = IHost> extends EventEmitter, IAbortComponent {
        readonly status: LogStatus<StatusType>[];
        readonly errors: unknown[];
        supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
        supports(name: string, value?: boolean): boolean;
        getTempDir(options: TempDirOptions): string;
        getTempDir(uuidDir: boolean, createDir: boolean): string;
        getTempDir(pathname: string, createDir: boolean): string;
        getTempDir(uuidDir: boolean, filename?: string, createDir?: boolean): string;
        getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
        canRead(uri: string | URL, options?: PermissionOptions): boolean;
        canWrite(uri: string | URL, options?: PermissionOptions): boolean;
        readFile(src: string | URL): Undef<Buffer>;
        readFile<U extends ReadFileOptions>(src: string | URL, options?: U): Undef<U extends { encoding: string } ? U extends { minStreamSize: number | string } ? Promise<string> : string : U extends { minStreamSize: number | string } ? Promise<Buffer> : Buffer>;
        readFile<U extends Buffer>(src: string | URL, promises: true): Promise<Undef<U>>;
        readFile<U extends Bufferable, V extends ReadFileOptions>(src: string | URL, options: V, promises: true): Promise<Undef<V extends { encoding: string } ? string : U>>;
        readFile<U extends ReadFileCallback>(src: string | URL, callback: U): Undef<U extends ReadFileCallback<infer W> ? W : Bufferable>;
        readFile<U extends ReadFileCallback, V extends ReadFileOptions>(src: string | URL, options: V, callback: U): Undef<V extends { encoding: string } ? string : U extends ReadFileCallback<infer W> ? W : Bufferable>;
        writeFile<U extends boolean>(src: string | URL, data: BufferView, options?: WriteFileOptions): U;
        writeFile<U extends Promise<boolean>>(src: string | URL, data: BufferView, promises: true): U;
        writeFile<U extends Promise<boolean>>(src: string | URL, data: BufferView, options: WriteFileOptions, promises: true): U;
        writeFile<U extends NoParamCallback>(src: string | URL, data: BufferView, callback: U): void;
        writeFile<U extends NoParamCallback>(src: string | URL, data: BufferView, options: WriteFileOptions, callback: U): void;
        deleteFile<U extends boolean>(src: string | URL, options?: DeleteFileOptions): U;
        deleteFile<U extends Promise<boolean>>(src: string | URL, promises: true): U;
        deleteFile<U extends Promise<boolean>>(src: string | URL, options: DeleteFileOptions, promises: true): U;
        deleteFile<U extends NoParamCallback>(src: string | URL, callback: U): void;
        deleteFile<U extends NoParamCallback>(src: string | URL, options: DeleteFileOptions, callback: U): void;
        copyFile<U extends boolean>(src: string | URL, dest: string | URL, options?: CopyFileOptions): U;
        copyFile<U extends Promise<boolean>>(src: string | URL, dest: string | URL, promises: true): U;
        copyFile<U extends Promise<boolean>>(src: string | URL, dest: string | URL, options: CopyFileOptions, promises: true): U;
        copyFile<U extends NoParamCallback>(src: string | URL, dest: string | URL, callback: U): void;
        copyFile<U extends NoParamCallback>(src: string | URL, dest: string | URL, options: CopyFileOptions, callback: U): void;
        moveFile<U extends boolean>(src: string | URL, dest: string | URL, options?: MoveFileOptions): U;
        moveFile<U extends Promise<boolean>>(src: string | URL, dest: string | URL, promises: true): U;
        moveFile<U extends Promise<boolean>>(src: string | URL, dest: string | URL, options: MoveFileOptions, promises: true): U;
        moveFile<U extends NoParamCallback>(src: string | URL, dest: string | URL, callback: U): void;
        moveFile<U extends NoParamCallback>(src: string | URL, dest: string | URL, options: MoveFileOptions, callback: U): void;
        createDir<U extends boolean>(src: string | URL, options?: CreateDirOptions): U;
        createDir<U extends Promise<boolean>>(src: string | URL, promises: true): U;
        createDir<U extends Promise<boolean>>(src: string | URL, options: CreateDirOptions, promises: true): U;
        createDir<U extends NoParamCallback>(src: string | URL, callback: U): void;
        createDir<U extends NoParamCallback>(src: string | URL, options: CreateDirOptions, callback: U): void;
        removeDir<U extends boolean>(src: string | URL, options?: RemoveDirOptions): U;
        removeDir<U extends Promise<boolean>>(src: string | URL, promises: true): U;
        removeDir<U extends Promise<boolean>>(src: string | URL, options: RemoveDirOptions, promises: true): U;
        removeDir<U extends NoParamCallback>(src: string | URL, callback: U): void;
        removeDir<U extends NoParamCallback>(src: string | URL, options: RemoveDirOptions, callback: U): void;
        allSettled<U>(values: readonly (U | PromiseLike<U>)[], rejected?: LogValue, type?: LogType): Promise<PromiseFulfilledResult<U>[]>;
        allSettled<U>(values: readonly (U | PromiseLike<U>)[], rejected?: LogValue, options?: LogFailOptions): Promise<PromiseFulfilledResult<U>[]>;
        formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
        formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
        writeFail(value: LogValue, message?: unknown, type?: LogType): void;
        writeFail(value: LogValue, message?: unknown, options?: LogFailOptions): void;
        writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
        writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
        checkPackage(err: unknown, name: Undef<string>, type: LogType): boolean;
        checkPackage(err: unknown, name: Undef<string>, options: LogFailOptions): boolean;
        checkPackage(err: unknown, name: Undef<string>, value?: LogValue, options?: LogFailOptions | LogType): boolean;
        checkFail(message: unknown, options: LogFailOptions): Undef<LogArguments | false>;
        writeLog(component: LogComponent, queue?: boolean): void;
        writeLog(type: StatusType, value: unknown, options: LogOptions): void;
        writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
        addLog(component: LogComponent, queue?: boolean): void;
        addLog(type: StatusType, value: unknown, options: LogOptions): void;
        addLog(type: StatusType, value: unknown, from: string, source?: string): void;
        addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
        addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
        getLog(...type: StatusType[]): LogStatus<StatusType>[];
        flushLog(): void;
        willAbort(value: unknown): boolean;
        hasOwnPermission(): boolean;
        isFatal(err?: unknown): boolean;
        detach(): void;
        reset(): void;
        get moduleName(): string;
        set host(value);
        get host(): Null<T>;
        set permission(value);
        get permission(): Null<IPermission>;
        get aborted(): boolean;
        set abortable(value);
        get abortable(): boolean;
        get threadable(): boolean;
        set sessionId(value);
        get sessionId(): string;
        set broadcastId(value);
        get broadcastId(): ArrayOf<string>;
        set silent(value);
        get silent(): boolean;
        get logType(): LOG_TYPE;
        set logLevel(value: number | string);
        get logLevel(): number;
        get statusType(): STATUS_TYPE;
        set tempDir(value);
        get tempDir(): string;

        /* EventEmitter */
        on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
        on(event: "error", listener: (err: Error) => void): this;
        on(event: "file:read", listener: (src: string, data: Bufferable, options?: ReadFileOptions) => void): this;
        on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
        on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
        on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
        on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
        on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
        on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
        once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
        once(event: "error", listener: (err: Error) => void): this;
        once(event: "file:read", listener: (src: string, data: Bufferable, options?: ReadFileOptions) => void): this;
        once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
        once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
        once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
        once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
        once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
        once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
        emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
        emit(event: "error", err: Error): boolean;
        emit(event: "file:read", src: string, data: Bufferable, options?: ReadFileOptions): boolean;
        emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
        emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
        emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
        emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
        emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
        emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
    }

    interface ModuleConstructor<T extends IHost = IHost> {
        PROCESS_TIMEOUT: number;
        LOG_STYLE_FAIL: LogMessageOptions;
        LOG_STYLE_SUCCESS: LogMessageOptions;
        LOG_STYLE_INFO: LogMessageOptions;
        LOG_STYLE_WARN: LogMessageOptions;
        LOG_STYLE_NOTICE: LogMessageOptions;
        LOG_STYLE_REVERSE: LogMessageOptions;
        readonly VERSION: string;
        readonly LOG_TYPE: LOG_TYPE;
        readonly LOG_FORMAT: LoggerFormatSettings<LoggerFormat<number>>;
        readonly STATUS_TYPE: STATUS_TYPE;
        readonly PLATFORM_WIN32: boolean;
        readonly MAX_TIMEOUT: number;
        readonly TEMP_DIR: string;
        /** @deprecated Types.supported */
        supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
        formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
        writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
        enabled(key: string, username?: string): boolean;
        parseFunction<U = unknown, V = unknown>(value: unknown, options?: ParseFunctionOptions): Null<FunctionType<Promise<U> | U, V>>;
        parseFunction<U = unknown, V = unknown>(value: unknown, absolute: boolean, sync?: boolean): Null<FunctionType<Promise<U> | U, V>>;
        asString(value: unknown, cacheKey?: boolean | "throws"): string;
        asHash(data: BinaryLike, options?: AsHashOptions): string;
        asHash(data: BinaryLike, algorithm?: string, options?: HashOptions): string;
        asHash(data: BinaryLike, algorithm?: string, digest?: BinaryToTextEncoding): string;
        readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
        toPosix(value: unknown, normalize: boolean): string;
        toPosix(value: unknown, filename?: string, normalize?: boolean): string;
        hasLogType(value: LogType): boolean;
        isURL(value: string, ...exclude: string[]): boolean;
        isFile(value: string | URL, type?: ProtocolType): boolean;
        isDir(value: string | URL): boolean;
        isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
        isPath(value: string | URL, isFile?: boolean): boolean;
        isErrorCode(err: unknown, ...code: string[]): boolean;
        fromLocalPath(value: string): string;
        resolveFile(value: string): string;
        resolvePath(value: string, base: string | URL): string;
        joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
        joinPath(...values: unknown[]): string;
        normalizePath(value: unknown, flags?: boolean | number): string;
        createDir(value: string | URL, overwrite?: boolean): boolean;
        removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
        removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
        copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
        copyDir(src: string | URL, dest: string | URL, options?: CopyDirOptions): Promise<CopyDirResult>;
        globDir(src: string | URL, pattern: ArrayOf<string>, recursive: boolean | number): Promise<string[]>;
        globDir(src: string | URL, pattern: ArrayOf<string>, options?: GlobDirOptions): Promise<string[]>;
        renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
        streamFile<U extends Bufferable>(value: string | URL, cache: boolean): Promise<U>;
        streamFile<U extends ReadBufferOptions>(value: string | URL, options: U): Promise<U extends { encoding: string } ? string : Buffer>;
        streamFile<U extends ReadBufferOptions>(value: string | URL, cache?: boolean | U, options?: U): Promise<U extends { encoding: string } ? string : Buffer>;
        readText(value: string | URL, cache: boolean): string;
        readText<U extends ReadTextOptions>(value: string | URL, options: U): U extends { minStreamSize: number | string } ? Promise<string> : string;
        readText(value: string | URL, encoding?: BufferEncoding | ReadTextOptions, cache?: boolean): string;
        readBuffer<U extends ReadBufferOptions>(value: string | URL, options: U): U extends { minStreamSize: number | string } ? Promise<Null<Buffer>> : Null<Buffer>;
        readBuffer(value: string | URL, cache?: boolean | ReadBufferOptions): Null<Buffer>;
        resolveMime(data: FileTypeFormat): Promise<Undef<FileTypeResult>>;
        lookupMime(value: string, extension?: boolean): string;
        initCpuUsage(instance?: IModule): CpuUsage;
        getCpuUsage(start: CpuUsage, format: true): string;
        getCpuUsage(start: CpuUsage, format?: boolean): number;
        getMemUsage(format: true): string;
        getMemUsage(format?: boolean): number;
        formatCpuMem(start: CpuUsage, all?: boolean): string;
        getPackageVersion(name: string | TupleOf<string>, startDir: string, baseDir?: string): string;
        getPackageVersion(name: string | TupleOf<string>, unstable?: boolean, startDir?: string, baseDir?: string): string;
        checkSemVer(name: string | TupleOf<string>, options: CheckSemVerOptions): boolean;
        /** @deprecated options */
        checkSemVer(name: string | TupleOf<string>, min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
        checkSemVer(name: string | TupleOf<string>, min: number | string, max: number | string, options?: Omit<CheckSemVerOptions, "min" | "max" | "equals">): boolean;
        sanitizeCmd(value: string): string;
        sanitizeArgs(value: string, doubleQuote?: boolean): string;
        sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
        purgeMemory(percent: number, limit: number, parent?: boolean): Promise<number>;
        purgeMemory(percent?: number, limit?: number | boolean, parent?: unknown): Promise<number>;
        canWrite(name: "temp" | "home"): boolean;
        loadSettings(settings: Settings, password?: string): boolean;
        readonly prototype: IModule<T>;
        new(): IModule<T>;
    }
}

export = functions;
