0.10.3 • Published 8 months ago

@e-mc/core v0.10.3

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
8 months ago

@e-mc/core

  • NodeJS 16
  • ES2020

General Usage

Interface

import type { DataSource, LogStatus } from "./squared";

import type { IHost, IModule, ModuleConstructor } from "./index";
import type { CacheOptions, HostInitConfig, JoinQueueOptions, PermissionReadWrite, ResumeThreadOptions, StoreResultOptions, ThreadCountStat } from "./core";
import type { QueryResult, TimeoutAction } from "./db";
import type { AddEventListenerOptions } from "./dom";
import type { LogState, StatusType } from "./logger";
import type { Settings } from "./node";
import type { ClientDbSettings, ClientModule, ClientSettings, DbCacheValue, DbCoerceSettings, DbCoerceValue, DbSourceOptions } from "./settings";

interface IHost extends IModule {
    restartable: boolean;
    readonly modules: Set<IModule>;
    readonly subProcesses: Set<IModule>;
    readonly startTime: number;
    using(...items: unknown[] | [boolean, ...unknown[]]): this;
    contains(item: unknown, condition?: (...args: any[]) => boolean): boolean;
    find(name: string): IModule | undefined;
    findAll(name: string): IModule[];
    willLog(name: string): boolean;
    ignoreLog(values: boolean | string | 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[]): IModule | null;
    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: number | number[]): number;
    getThreadCount(full: true): ThreadCountStat;
    getThreadCount(username: string, iv?: BinaryLike): ThreadCountStat;
    getThreadCount(username?: string | boolean, iv?: BinaryLike): number;
    getPermissionFromSettings(): IPermission;
    readonly prototype: IHost;
    new(config?: HostInitConfig): IHost;
}

interface IClient extends IModule<IHost> {
    module: ClientModule;
    init(...args: unknown[]): this;
    getUserSettings(): unknown;
    get settings(): ClientSettings;
    set cacheDir(value: string);
    get cacheDir(): string;
    set extensions(values: unknown[]);
    get extensions(): ((...args: unknown[]) => unknown)[];
}

interface ClientConstructor extends ModuleConstructor {
    readonly prototype: IClient;
    new(module?: ClientModule): IClient;
}

interface IClientDb extends IClient<IHost, ClientModule<ClientDbSettings>> {
    database: DataSource[];
    cacheExpires: number;
    add(item: DataSource, state?: number): void;
    hasCache(source: string, sessionKey?: string): boolean;
    hasCoerce(source: string, component: keyof DbCoerceSettings, uuidKey: Undef<string>): boolean;
    hasCoerce(source: string, component: keyof DbCoerceSettings, credential?: unknown): boolean;
    getQueryResult(source: string, credential: unknown, queryString: string, renewCache: boolean): QueryResult | undefined;
    getQueryResult(source: string, credential: unknown, queryString: string, sessionKey?: string, renewCache?: boolean): QueryResult | undefined;
    getQueryResult(source: string, credential: unknown, queryString: string, options?: CacheOptions, renewCache?: boolean): QueryResult | undefined;
    setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, sessionKey?: string): QueryResult;
    setQueryResult(source: string, credential: unknown, queryString: string, result: unknown, options?: CacheOptions): QueryResult;
    getCacheResult(source: string, credential: unknown, queryString: string, cacheValue: CacheOptions, ignoreCache?: unknown): QueryResult | undefined;
    applyState(items: DataSource | DataSource[], value: number, as?: boolean): void;
    commit(items?: DataSource[]): Promise<boolean>;
    valueOfKey(credential: unknown, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
    settingsOf(source: string, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
    settingsKey(uuidKey: string, name: keyof DbSourceOptions, component?: keyof DbCoerceSettings): unknown;
    get pending(): DataSource[];
    get committed(): DataSource[];
    get failed(): DataSource[];
}

interface ClientDbConstructor extends ClientConstructor<IHost, ClientModule> {
    STORE_RESULT_PARTITION_SIZE: number;
    STORE_RESULT_PARTITION_MULT: number;
    readonly TRANSACTION_ACTIVE: number;
    readonly TRANSACTION_PARTIAL: number;
    readonly TRANSACTION_COMMIT: number;
    readonly TRANSACTION_TERMINATE: number;
    readonly TRANSACTION_ABORT: number;
    readonly TRANSACTION_FAIL: number;
    loadSettings(settings: Pick<Settings, "process" | "memory">, password?: string): boolean;
    getTimeout(value: number | string | TimeoutAction | undefined): number;
    convertTime(value: number | string): number;
    findResult(source: string, credential: unknown, queryString: string, timeout: number, sessionKey?: string | boolean, renewCache?: boolean): QueryResult | undefined;
    storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, options: StoreResultOptions): QueryResult;
    storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, sessionKey: string, sessionExpires: number): QueryResult;
    storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue): QueryResult;
    storeResult(source: string, credential: unknown, queryString: string, result: QueryResult, cache: DbCacheValue | undefined, options: StoreResultOptions): QueryResult;
    purgeResult(prefix?: string): Promise<number>;
    extractUUID(credential: unknown): string;
    setPoolConfig(value: unknown): void;
    getPoolConfig(source: string): unknown;
    keyOfResult(source: string, credential: unknown, uuidOnly?: boolean): string;
    readonly prototype: IClientDb;
    new(module?: ClientModule, database?: DataSource[]): IClientDb;
}

interface IAbortComponent extends AbortController {
    reset(): void;
    get aborted(): boolean;
}

interface AbortComponentConstructor {
    attach(instance: IAbortComponent, signal: AbortSignal, options?: AddEventListenerOptions): void;
    detach(instance: IAbortComponent, signal: AbortSignal): void;
    readonly prototype: IAbortComponent;
    new(): IAbortComponent;
}

interface IPermission {
    setDiskRead(pathname?: string | string[], enabled?: boolean): void;
    setDiskWrite(pathname?: string | string[], enabled?: boolean): void;
    setUNCRead(pathname?: string | string[], enabled?: boolean): void;
    setUNCWrite(pathname?: string | string[], enabled?: boolean): void;
    getDiskRead(): string | string[];
    getDiskWrite(): string | string[];
    getUNCRead(): string | string[];
    getUNCWrite(): string | string[];
    hasDiskRead(pathname: string): boolean;
    hasDiskWrite(pathname: string): boolean;
    hasUNCRead(pathname: string): boolean;
    hasUNCWrite(pathname: string): boolean;
    get diskRead(): boolean;
    get diskWrite(): boolean;
    get uncRead(): boolean;
    get uncWrite(): boolean;
}

Settings

import type { ExecOptions } from "./settings";

import type { MinimatchOptions } from "minimatch";
import type { PicomatchOptions } from "picomatch";

interface ProcessModule {
    thread?: {
        admin: {
            users?: string[];
            private?: boolean;
        };
        queue?: {
            limit?: number;
            expires?: number | string;
            priority: {
                bypass?: number;
                min?: number;
                max?: number;
            };
        };
        limit?: number;
        expires?: number | string;
    };
}

interface PermissionModule {
    disk_read?: string | string[];
    disk_write?: string | string[];
    unc_read?: string | string[];
    unc_write?: string | string[];
    settings?: {
        broadcast_id?: string | string[];
        picomatch?: PicomatchOptions | null;
        minimatch?: MinimatchOptions | null;
    };
}

Example usage

const { Host } = require("@e-mc/core");

Host.loadSettings({ // Global
    process: {
        thread: { limit: 8 }
    },
    permission: {
        disk_read: ["**/*"],
        disk_write: ["/tmp/**"]
    }
});

NOTE: @e-mc/core is mostly a collection of abstract base classes which cannot be instantiated. Host is more commonly called through @e-mc/file-manager.

References

LICENSE

BSD 3-Clause

0.5.10

11 months ago

0.5.11

11 months ago

0.5.16

8 months ago

0.5.14

9 months ago

0.5.15

9 months ago

0.5.12

10 months ago

0.5.13

9 months ago

0.9.8

10 months ago

0.7.11

11 months ago

0.9.7

11 months ago

0.7.10

11 months ago

0.7.13

10 months ago

0.9.9

10 months ago

0.7.12

10 months ago

0.9.4

12 months ago

0.5.8

12 months ago

0.9.3

1 year ago

0.5.7

1 year ago

0.9.6

11 months ago

0.5.9

12 months ago

0.9.5

12 months ago

0.7.15

9 months ago

0.7.14

9 months ago

0.7.17

8 months ago

0.7.16

9 months ago

0.10.1

10 months ago

0.10.2

9 months ago

0.10.3

8 months ago

0.10.0

11 months ago

0.9.12

9 months ago

0.9.13

8 months ago

0.6.7

11 months ago

0.6.6

12 months ago

0.9.10

9 months ago

0.6.9

10 months ago

0.9.11

9 months ago

0.6.8

11 months ago

0.6.10

10 months ago

0.6.12

9 months ago

0.6.11

9 months ago

0.6.14

8 months ago

0.6.13

9 months ago

0.9.2

1 year ago

0.7.9

12 months ago

0.8.21

8 months ago

0.7.8

12 months ago

0.8.20

9 months ago

0.7.7

1 year ago

0.8.12

12 months ago

0.8.11

1 year ago

0.8.14

11 months ago

0.8.13

12 months ago

0.8.19

9 months ago

0.8.16

10 months ago

0.8.15

11 months ago

0.8.18

9 months ago

0.8.17

10 months ago

0.6.5

12 months ago

0.6.4

1 year ago

0.8.9

1 year ago

0.8.8

1 year ago

0.7.6

1 year ago

0.7.5

1 year ago

0.8.10

1 year ago

0.6.3

1 year ago

0.7.4

1 year ago

0.5.6

1 year ago

0.9.1

1 year ago

0.9.0

1 year ago

0.8.7

1 year ago

0.6.2

1 year ago

0.7.3

1 year ago

0.5.5

1 year ago

0.8.6

1 year ago

0.7.2

1 year ago

0.5.4

1 year ago

0.6.1

1 year ago

0.8.5

1 year ago

0.8.4

1 year ago

0.8.3

1 year ago

0.8.2

1 year ago

0.8.1

1 year ago

0.8.0

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.3

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago