How to use the @node-red/util.util function in @node-red/util

To help you get started, we’ve selected a few @node-red/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 node-red / node-red / packages / node_modules / @node-red / runtime / lib / nodes / context / localfilesystem.js View on Github external
*  $HOME/.node-red/contexts
 *  ├── global
 *  │     └── global_context.json
 *  ├── 
 *  │     ├── flow_context.json
 *  │     ├── .json
 *  │     └── .json
 *  └── 
 *         ├── flow_context.json
 *         ├── .json
 *         └── .json
 */

var fs = require('fs-extra');
var path = require("path");
var util = require("@node-red/util").util;
var log = require("@node-red/util").log;

var safeJSONStringify = require("json-stringify-safe");
var MemoryStore = require("./memory");


function getStoragePath(storageBaseDir, scope) {
    if(scope.indexOf(":") === -1){
        if(scope === "global"){
            return path.join(storageBaseDir,"global",scope);
        }else{ // scope:flow
            return path.join(storageBaseDir,scope,"flow");
        }
    }else{ // scope:local
        var ids = scope.split(":")
        return path.join(storageBaseDir,ids[1],ids[0]);
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / nodes / context / index.js View on Github external
* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var clone = require("clone");
var log = require("@node-red/util").log;
var util = require("@node-red/util").util;
var memory = require("./memory");
var flows;

var settings;

// A map of scope id to context instance
var contexts = {};

// A map of store name to instance
var stores = {};
var storeList = [];
var defaultStore;

// Whether there context storage has been configured or left as default
var hasConfiguredStore = false;
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / settings.js View on Github external
* You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var when = require("when");
var clone = require("clone");
var assert = require("assert");
var log = require("@node-red/util").log; // TODO: separate module
var util = require("@node-red/util").util;

// localSettings are those provided in the runtime settings.js file
var localSettings = null;
// globalSettings are provided by storage - .config.json on localfilesystem
var globalSettings = null;
// nodeSettings are those settings that a node module defines as being available
var nodeSettings = null;

// A subset of globalSettings that deal with per-user settings
var userSettings = null;

var disableNodeSettings = null;
var storage = null;

var persistentSettings = {
    init: function(settings) {
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / index.js View on Github external
return redNodes.closeContextsPlugin();
    });
}

// This is the internal api
var runtime = {
    version: getVersion,
    get log() { return log },
    get i18n() { return i18n },
    settings: settings,
    storage: storage,
    events: events,
    nodes: redNodes,
    library: library,
    exec: exec,
    util: require("@node-red/util").util,
    get adminApi() { return adminApi },
    get adminApp() { return adminApp },
    get nodeApp() { return nodeApp },
    get server() { return server },
    isStarted: function() {
        return started;
    }
};

/**
 * This module provides the core runtime component of Node-RED.
 * It does *not* include the Node-RED editor. All interaction with
 * this module is done using the api provided.
 *
 * @namespace @node-red/runtime
 */
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / nodes / flows / index.js View on Github external
var clone = require("clone");
var when = require("when");

var Flow = require('./Flow');

var typeRegistry = require("@node-red/registry");
var deprecated = typeRegistry.deprecated;


var context = require("../context")
var credentials = require("../credentials");

var flowUtil = require("./util");
var log;
var events = require("../../events");
var redUtil = require("@node-red/util").util;

var storage = null;
var settings = null;

var activeConfig = null;
var activeFlowConfig = null;

var activeFlows = {};
var started = false;
var credentialsPendingReset = false;

var activeNodesToFlow = {};

var typeEventRegistered = false;

function init(runtime) {
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / nodes / flows / util.js View on Github external
* Copyright JS Foundation and other contributors, http://js.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
var clone = require("clone");
var redUtil = require("@node-red/util").util;
var Log = require("@node-red/util").log;
var subflowInstanceRE = /^subflow:(.+)$/;
var typeRegistry = require("@node-red/registry");

var envVarExcludes = {};

function diffNodes(oldNode,newNode) {
    if (oldNode == null) {
        return true;
    }
    var oldKeys = Object.keys(oldNode).filter(function(p) { return p != "x" && p != "y" && p != "wires" });
    var newKeys = Object.keys(newNode).filter(function(p) { return p != "x" && p != "y" && p != "wires" });
    if (oldKeys.length != newKeys.length) {
        return true;
    }
    for (var i=0;i
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / nodes / flows / Flow.js View on Github external
*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var clone = require("clone");
var redUtil = require("@node-red/util").util;
var flowUtil = require("./util");
var events = require("../../events");

var Subflow;
var Log;

var nodeCloseTimeout = 15000;

/**
 * This class represents a flow within the runtime. It is responsible for
 * creating, starting and stopping all nodes within the flow.
 */
class Flow {

    /**
     * Create a Flow object.
github node-red / node-red / packages / node_modules / node-red / lib / red.js View on Github external
})
    },

    /**
     * Logging utilities
     * @see @node-red/util_log
     * @memberof node-red
     */
    log: redUtil.log,

    /**
     * General utilities
     * @see @node-red/util_util
     * @memberof node-red
     */
    util: redUtil.util,


    /**
     * This provides access to the internal nodes module of the
     * runtime. The details of this API remain undocumented as they should not
     * be used directly.
     *
     * Most administrative actions should be performed use the runtime api
     * under [node-red.runtime]{@link node-red.runtime}.
     *
     * @memberof node-red
     */
    get nodes() { return runtime._.nodes },

    /**
     * Runtime events emitter
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / api / context.js View on Github external
* http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

/**
 * @mixin @node-red/runtime_context
 */

var runtime;

var util = require("@node-red/util").util;

function exportContextStore(scope,ctx, store, result, callback) {
    ctx.keys(store,function(err, keys) {
        if (err) {
            return callback(err);
        }
        result[store] = {};
        var c = keys.length;
        if (c === 0) {
            callback(null);
        } else {
            keys.forEach(function(key) {
                ctx.get(key,store,function(err, v) {
                    if (err) {
                        return callback(err);
                    }
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / nodes / context / memory.js View on Github external
* Copyright JS Foundation and other contributors, http://js.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var util = require("@node-red/util").util;

function Memory(config){
    this.data = {};
}

Memory.prototype.open = function(){
    return Promise.resolve();
};

Memory.prototype.close = function(){
    return Promise.resolve();
};

Memory.prototype._getOne = function(scope, key) {
    var value;
    var error;