@e-mc/watch
TypeScript icon, indicating that this package has built-in type declarations

0.9.1 • Public • Published

@e-mc/watch

  • NodeJS 16
  • ES2020

General Usage

Interface

import type { IFileManager, ModuleConstructor } from "./index";
import type { ExternalAsset } from "./asset";
import type { HostInitConfig, IClient, IPermission } from "./core";
import type { FinalizeResult, PostFinalizeCallback } from "./filemanager";
import type { WatchModule } from "./settings";
import type { IFileGroup, ModifiedPostFinalizeListener, SecureOptions } from "./watch";

import type * as ws from "ws";

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

interface WatchConstructor extends ModuleConstructor {
    createServer(port: number, active: boolean): ws.Server | null;
    createServer(port: number, secure?: SecureOptions | null, active?: boolean): ws.Server | null;
    shutdown(): void;
    setTimeout(value: number | string): void;
    checkTimeout(client: ws): boolean;
    readonly prototype: IWatch;
    new(module?: WatchModule): IWatch;
}

Settings

import type { PermittedDirectories } from "./core";

import type { SecureVersion } from "tls";

interface WatchModule {
    // handler: "@e-mc/watch";
    extensions?: string[];
    timeout?: number | string;
    interval?: number | string;
    port?: number;
    secure?: {
        port?: number;
        ca?: string;
        key?: string;
        cert?: string;
        passphrase?: string;
        version?: SecureVersion;
    };
    settings?: {
        broadcast_id?: string | string[];
        users?: Record<string, Record<string, unknown>>;
    };
    permission?: PermittedDirectories;
}

Example usage

const Watch = require("@e-mc/watch");

const instance = new Watch({ interval: 100, port: 8080 });
instance.init();

instance.whenModified = (assets) => {
    assets.forEach(item => console.log(item.uri));
};

const assets = [
    { localUri: "/path/workspace/output/image1.png", uri: "http://hostname/path/document1.png", watch: true },
    { localUri: "/path/workspace/output/image2.png", uri: "http://hostname/path/document2.png", watch: true }
];

instance.start(assets, { disk_read: ["/path/workspace/output/**"] });

References

LICENSE

BSD 3-Clause

Package Sidebar

Install

npm i @e-mc/watch

Weekly Downloads

674

Version

0.9.1

License

BSD 3-Clause

Unpacked Size

49.5 kB

Total Files

7

Last publish

Collaborators

  • anpham6