0.10.3 • Published 9 months ago

@e-mc/document v0.10.3

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

@e-mc/document

  • NodeJS 16
  • ES2020

General Usage

Interface

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

import type { IFileManager, IScopeOrigin } from "./index";
import type { ExternalAsset, FileCommand, IFileThread, OutputFinalize } from "./asset";
import type { HostInitConfig, IClient } from "./core";
import type { AsSourceFileOptions, ConfigOrTransformer, CustomizeOptions, GenerateLintTableOptions, LintMessage, PluginConfig, SourceCode, SourceInput, SourceMap, SourceMapOptions, TransformAction, TransformCallback, TransformOutput, TransformResult, UpdateGradleOptions } from "./document";
import type { PostFinalizeCallback } from "./filemanager";
import type { LogComponent } from "./logger";
import type { DocumentComponent, DocumentComponentOption, DocumentModule } from "./settings";
import type { IFileGroup, WatchInitResult } from "./watch";

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

interface DocumentConstructor extends ModuleConstructor {
    finalize(this: IFileManager, instance: IDocument): Promise<unknown>;
    createSourceMap(code: string, remove: boolean): SourceMap;
    createSourceMap(code: string, uri?: string, remove?: boolean): SourceMap;
    writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): string | undefined;
    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: IFileManager, instance: IDocument): Promise<unknown>;
    sanitizeAssets?(assets: ExternalAsset[], exclusions?: unknown[]): ExternalAsset[];
    readonly prototype: IDocument;
    new(module?: DocumentModule, ...args: unknown[]): IDocument;
}

Settings

import type { PermittedDirectories } from "./core";
import type { DbModule, DbSettings, DocumentComponentOptions, PurgeComponent } from "./settings";

interface DocumentModule {
    // handler: "@pi-r/chrome";
    extensions?: string[];
    db?: DbModule<DbSettings>;
    eval?: {
        function?: boolean;
        absolute?: boolean;
        template?: boolean;
        userconfig?: boolean;
    };
    format?: {
        uuid?: {
            dictionary?: string;
            pathname?: string;
            filename?: string;
        };
    };
    imports?: StringMap;
    settings?: {
        broadcast_id?: string | string[];
        users?: Record<string, {
            extensions?: string[] | null;
            imports?: StringMap;
            imports_strict?: boolean;
            pages?: unknown;
            transform?: unknown;
            view_engine?: unknown;
        }>;
        cache_dir?: string;
        imports_strict?: boolean;
        directory?: {
            template?: string;
            data?: string;
            export?: string;
            schema?: string;
            package?: string;
        };
        purge?: PurgeComponent;
        options?: DocumentComponentOptions<boolean | number>;
        pages?: Record<string, Record<string, unknown>>;
        transform?: {
            html?: Record<string, Record<string, unknown>>;
            css?: Record<string, Record<string, unknown>>;
            js?: Record<string, Record<string, unknown>>;
        };
        view_engine?: Record<string, Record<string, unknown>>;
        export?: Record<string, string | (...args: unknown[]) => unknown>;
    };
    permission?: PermittedDirectories;
}

Example usage

const Document = require("@e-mc/document"); // @pi-r/chrome

const assets = [
    { pathname: "output", filename: "image1.png", uri: "http://hostname/path/document1.png" },
    { pathname: "output", filename: "image2.png", uri: "http://hostname/path/document2.png" }
];

const instance = new Document({
    eval: {
        function: true,
        template: true
    },
    imports: {
        "http://hostname/path/": "build/"
    },
    settings: {
        imports_strict: true,
        users: {
            "nodejs-001": {
                imports_strict: false,
                imports: {
                  "http://hostname/path": "build"
                }
            }
        },
        directory: {
            template: "../chrome/template" // ../chrome/template/users/nodejs-001
        }
    }
});
// instance.host = new Host();
instance.init(assets);

NOTE: @e-mc/document is an abstract base class and cannot be instantiated. Document is more commonly called through @pi-r/chrome.

References

LICENSE

BSD 3-Clause

0.5.10

12 months ago

0.5.11

11 months ago

0.5.16

9 months ago

0.5.14

9 months ago

0.5.15

9 months ago

0.5.12

11 months ago

0.5.13

10 months ago

0.9.8

11 months ago

0.7.11

11 months ago

0.9.7

11 months ago

0.7.10

12 months ago

0.7.13

11 months ago

0.9.9

11 months ago

0.7.12

11 months ago

0.9.4

1 year ago

0.5.8

1 year ago

0.9.3

1 year ago

0.5.7

1 year ago

0.9.6

12 months ago

0.5.9

12 months ago

0.9.5

12 months ago

0.7.15

9 months ago

0.7.14

10 months ago

0.7.17

9 months ago

0.7.16

9 months ago

0.10.1

11 months ago

0.10.2

10 months ago

0.10.3

9 months ago

0.10.0

11 months ago

0.9.12

9 months ago

0.9.13

9 months ago

0.6.7

12 months ago

0.6.6

12 months ago

0.9.10

10 months ago

0.6.9

11 months ago

0.9.11

9 months ago

0.6.8

11 months ago

0.6.10

11 months ago

0.6.12

9 months ago

0.6.11

10 months ago

0.6.14

9 months ago

0.6.13

9 months ago

0.9.2

1 year ago

0.7.9

12 months ago

0.8.21

9 months ago

0.7.8

1 year ago

0.8.20

9 months ago

0.7.7

1 year ago

0.8.12

1 year ago

0.8.11

1 year ago

0.8.14

12 months ago

0.8.13

12 months ago

0.8.19

9 months ago

0.8.16

11 months ago

0.8.15

11 months ago

0.8.18

10 months ago

0.8.17

11 months ago

0.6.5

1 year 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