How to use @hpcc-js/util - 10 common examples

To help you get started, we’ve selected a few @hpcc-js/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hpcc-systems / Visualization / tests / test-util / src / observer.spec.ts View on Github external
it("reference counter", function () {
        function echoEvent() {
            // logger.debug(args);
        }
        const et = new Observable("aaa", "bbb", "zzz");
        expect(et.hasObserver()).is.false;
        et.addObserver("aaa", echoEvent);
        expect(et.hasObserver()).is.true;
        expect(et.hasObserver("aaa")).is.true;
        expect(et.hasObserver("bbb")).is.false;
        et.addObserver("bbb", echoEvent);
        const h = et.addObserver("bbb", echoEvent);
        expect(et.hasObserver()).is.true;
        expect(et.hasObserver("aaa")).is.true;
        expect(et.hasObserver("bbb")).is.true;
        et.removeObserver("aaa", echoEvent);
        expect(et.hasObserver()).is.true;
        expect(et.hasObserver("aaa")).is.false;
        expect(et.hasObserver("bbb")).is.true;
        h.release();
        expect(et.hasObserver()).is.false;
github hpcc-systems / Visualization / demos / dashy / src / index.ts View on Github external
import { event as d3Event } from "@hpcc-js/common";
import { Connection, Result } from "@hpcc-js/comms";
import { Dashboard, Dashy, Databomb, ElementContainer, Form, FormField, LogicalFile, RoxieResult, RoxieService, WU, WUResult } from "@hpcc-js/marshaller";
import { Comms } from "@hpcc-js/other";
import { exists, scopedLogger } from "@hpcc-js/util";
import { sample } from "./sample";

const logger = scopedLogger("index.ts");

/* Test race condition  ---
import { hookSend, IOptions, ResponseType, SendFunc } from "@hpcc-js/comms";
let delay = 0;
const origSend: SendFunc = hookSend(function mySend(opts: IOptions, action: string, request: any, responseType: ResponseType) {
    return new Promise((resolve, reject) => {
        origSend(opts, action, request, responseType).then(response => {
            delay += 1000;
            if (delay > 5000) delay = 0;
            setTimeout(() => {
                resolve(response);
            }, delay);
        });
    });
});
*/
github hpcc-systems / Visualization / packages / marshaller / src / ddl2 / dashboardDockPanel.ts View on Github external
syncWidgets() {
        const prevWidgets = this.widgets();
        const diffWidgets = compare(prevWidgets, this._ec.elements().filter(e => e.visualization().visibility() === "normal").map(viz => viz.visualization().chartPanel()));

        let refit = false;
        for (const w of diffWidgets.removed) {
            this.removeWidget(w);
        }

        for (const w of diffWidgets.added) {
            const element: Element = this._ec.element(w);
            this.addWidget(w, this.tabTitle(element), "split-bottom", undefined, this.hideSingleTabs() ? undefined : this);
            refit = this.syncMinSize(w) || refit;  // ensure syncMinSize is called
        }

        for (const w of diffWidgets.unchanged) {
            this.updateTitle(w);
            refit = this.syncMinSize(w) || refit;  // ensure syncMinSize is called
        }
github hpcc-systems / Visualization / packages / common / src / Utility.ts View on Github external
if (arguments.length === 2 && typeof arguments[1] === "object") {
        args = arguments[1];
    } else {
        args = new Array(arguments.length - 1);
        for (let i = 1; i < arguments.length; ++i) {
            args[i - 1] = arguments[i];
        }
    }

    if (!args || !args.hasOwnProperty) {
        args = {};
    }

    //  Array handling
    for (const key in args) {
        if (isArray(args[key])) {
            args[key].forEach(function (row, idx) {
                args[key + "[" + idx + "]"] = row;
            });
        }
    }

    return tpl
        .replace(nargs2, function replaceArg(match, i) {
            const result = args.hasOwnProperty(i) ? args[i] : null;
            if (result === null || result === undefined) {
                return match;
            }
            return removeHTMLFromString(result);
        })
        .replace(nargs, function replaceArg(match, i, index) {
            const result = args.hasOwnProperty(i) ? args[i] : null;
github hpcc-systems / Visualization / packages / comms / src / index.node.ts View on Github external
// tslint:disable: no-require-imports

// DOM Parser polyfill  ---
import { root } from "@hpcc-js/util";
import { DOMParser } from "xmldom";
root.DOMParser = DOMParser;

//  fetch polyfill  ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
    root.fetch = fetch;

    // tslint:disable-next-line: no-var-requires
    const https = require("https");
    root.fetch.__agent = new https.Agent({
        rejectUnauthorized: false
    });
}

//  btoa polyfill  ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
    root.btoa = function (str: string) {
        return Buffer.from(str || "", "utf8").toString("base64");
    };
}

export * from "./index-common";

//  Client Tools  ---
export * from "./clienttools/eclcc";
github hpcc-systems / Visualization / packages / comms / src / index.node.ts View on Github external
// tslint:disable: no-require-imports

// DOM Parser polyfill  ---
import { root } from "@hpcc-js/util";
import { DOMParser } from "xmldom";
root.DOMParser = DOMParser;

//  fetch polyfill  ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
    root.fetch = fetch;

    // tslint:disable-next-line: no-var-requires
    const https = require("https");
    root.fetch.__agent = new https.Agent({
        rejectUnauthorized: false
    });
}

//  btoa polyfill  ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
    root.btoa = function (str: string) {
        return Buffer.from(str || "", "utf8").toString("base64");
    };
}
github hpcc-systems / Visualization / packages / comms / src / index.node.ts View on Github external
// tslint:disable: no-require-imports

// DOM Parser polyfill  ---
import { root } from "@hpcc-js/util";
import { DOMParser } from "xmldom";
root.DOMParser = DOMParser;

//  fetch polyfill  ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
    root.fetch = fetch;

    // tslint:disable-next-line: no-var-requires
    const https = require("https");
    root.fetch.__agent = new https.Agent({
        rejectUnauthorized: false
    });
}

//  btoa polyfill  ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
    root.btoa = function (str: string) {
        return Buffer.from(str || "", "utf8").toString("base64");
    };
}
github hpcc-systems / Visualization / packages / comms / src / index.node.ts View on Github external
//  fetch polyfill  ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
    root.fetch = fetch;

    // tslint:disable-next-line: no-var-requires
    const https = require("https");
    root.fetch.__agent = new https.Agent({
        rejectUnauthorized: false
    });
}

//  btoa polyfill  ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
    root.btoa = function (str: string) {
        return Buffer.from(str || "", "utf8").toString("base64");
    };
}

export * from "./index-common";

//  Client Tools  ---
export * from "./clienttools/eclcc";
export * from "./clienttools/eclMeta";
github hpcc-systems / Visualization / packages / comms / src / index.node.ts View on Github external
//  fetch polyfill  ---
import fetch from "node-fetch";
if (typeof root.fetch === "undefined") {
    root.fetch = fetch;

    // tslint:disable-next-line: no-var-requires
    const https = require("https");
    root.fetch.__agent = new https.Agent({
        rejectUnauthorized: false
    });
}

//  btoa polyfill  ---
import { Buffer } from "safe-buffer";
if (typeof root.btoa === "undefined") {
    root.btoa = function (str: string) {
        return Buffer.from(str || "", "utf8").toString("base64");
    };
}

export * from "./index-common";

//  Client Tools  ---
export * from "./clienttools/eclcc";
export * from "./clienttools/eclMeta";
github hpcc-systems / Visualization / tests / test-util / src / debounce.spec.ts View on Github external
for (let i = 0; i < 100; ++i) {
            func().then(val => {
                expect(funcCallCount).to.equal(1);
            });
        }
        for (let i = 1; i < 100; ++i) {
            await func().then(val => {
                expect(funcCallCount).to.equal(i);
                expect(val).to.equal(42);
            });
        }
        expect(funcCallCount).to.equal(99);
    });

    let funcHalfSecCallCount = 0;
    const funcHalfSec = debounce(async (): Promise => {
        ++funcHalfSecCallCount;
        console.log(`funcHalfSec - ${funcHalfSecCallCount}`);
        return 42;
    }, 500);

    it("0.5 sec timeout", async function (): Promise {
        return new Promise((resolve, reject) => {
            const startTime = Date.now();
            funcHalfSec();
            const interval = setInterval(() => {
                funcHalfSec();
                const elapsed = Date.now() - startTime;
                console.log(`elapsed - ${elapsed}`);
                if (elapsed > 1500) {
                    expect(funcHalfSecCallCount).to.equal(4);
                    clearInterval(interval);