2020-12-02 10:25:10 +01:00
|
|
|
/*!
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2015-04-07 17:02:15 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
**/
|
|
|
|
|
2019-01-28 15:40:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This module provides the node registry for the Node-RED runtime.
|
|
|
|
*
|
|
|
|
* It is responsible for loading node modules and making them available
|
|
|
|
* to the runtime.
|
|
|
|
*
|
|
|
|
* @namespace @node-red/registry
|
|
|
|
*/
|
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
var registry = require("./registry");
|
|
|
|
var loader = require("./loader");
|
2015-11-09 12:29:48 +01:00
|
|
|
var installer = require("./installer");
|
2018-04-26 13:32:05 +02:00
|
|
|
var library = require("./library");
|
2020-12-10 17:01:55 +01:00
|
|
|
var plugins = require("./plugins");
|
2015-04-07 17:02:15 +02:00
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Initialise the registry with a reference to a runtime object
|
|
|
|
* @param {Object} runtime - a runtime object
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-11-17 22:12:43 +01:00
|
|
|
function init(runtime) {
|
2020-12-02 10:25:10 +01:00
|
|
|
installer.init(runtime.settings);
|
|
|
|
// Loader requires the full runtime object because it initialises
|
|
|
|
// the util module it. The Util module is responsible for constructing the
|
|
|
|
// RED object passed to node modules when they are loaded.
|
2015-11-17 22:12:43 +01:00
|
|
|
loader.init(runtime);
|
2020-12-10 17:01:55 +01:00
|
|
|
plugins.init(runtime.settings);
|
2020-12-02 10:25:10 +01:00
|
|
|
registry.init(runtime.settings,loader);
|
2018-04-26 13:32:05 +02:00
|
|
|
library.init();
|
2016-07-15 01:11:28 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Triggers the intial discovery and loading of all Node-RED node modules.
|
|
|
|
* found on the node path.
|
|
|
|
* @return {Promise} - resolves when the registry has finised discovering node modules.
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2016-07-15 01:11:28 +02:00
|
|
|
function load() {
|
|
|
|
registry.load();
|
2016-10-12 23:30:32 +02:00
|
|
|
return installer.checkPrereq().then(loader.load);
|
2015-04-07 17:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addModule(module) {
|
|
|
|
return loader.addModule(module).then(function() {
|
|
|
|
return registry.getModuleInfo(module);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableNodeSet(typeOrId) {
|
2015-05-27 15:11:11 +02:00
|
|
|
return registry.enableNodeSet(typeOrId).then(function() {
|
|
|
|
var nodeSet = registry.getNodeInfo(typeOrId);
|
|
|
|
if (!nodeSet.loaded) {
|
|
|
|
return loader.loadNodeSet(registry.getFullNodeInfo(typeOrId)).then(function() {
|
|
|
|
return registry.getNodeInfo(typeOrId);
|
|
|
|
});
|
|
|
|
}
|
2018-04-25 00:49:57 +02:00
|
|
|
return Promise.resolve(nodeSet);
|
2015-05-27 15:11:11 +02:00
|
|
|
});
|
2015-04-07 17:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init:init,
|
2016-07-15 01:11:28 +02:00
|
|
|
load:load,
|
2015-04-07 17:02:15 +02:00
|
|
|
clear: registry.clear,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a node constructor function.
|
|
|
|
*
|
|
|
|
* @param {Object} nodeSet - the Node Set object the constructor is for
|
|
|
|
* @param {String} type - the node type
|
|
|
|
* @param {Function} constructor - the node constructor function
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
registerType: registry.registerNodeConstructor,
|
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Get a node constructor function.
|
|
|
|
*
|
|
|
|
* @param {String} type - the node type
|
|
|
|
* @return {Function} the node constructor function
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
get: registry.getNodeConstructor,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
2020-08-28 17:36:11 +02:00
|
|
|
registerSubflow: registry.registerSubflow,
|
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Get a node's set information.
|
|
|
|
*
|
|
|
|
* @param {String} type - the node type or set identifier
|
|
|
|
* @return {Object} the node set information
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
getNodeInfo: registry.getNodeInfo,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all nodes in the registry.
|
|
|
|
*
|
|
|
|
* @return {Object} the node list
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
getNodeList: registry.getNodeList,
|
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Get a modules's information.
|
|
|
|
*
|
|
|
|
* @param {String} type - the module identifier
|
|
|
|
* @return {Object} the module information
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
getModuleInfo: registry.getModuleInfo,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all moduless in the registry.
|
|
|
|
*
|
|
|
|
* @return {Object} the module list
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
getModuleList: registry.getModuleList,
|
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Get the HTML configs for all nodes in the registry.
|
|
|
|
*
|
|
|
|
* @param {String} lang - the language to return, default `en-US`
|
|
|
|
* @return {String} the node configs
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
getNodeConfigs: registry.getAllNodeConfigs,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the HTML config for a single node set.
|
|
|
|
*
|
|
|
|
* @param {String} id - the node identifier
|
|
|
|
* @param {String} lang - the language to return, default `en-US`
|
|
|
|
* @return {String} the node config
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
getNodeConfig: registry.getNodeConfig,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the local path to a node's icon file.
|
|
|
|
*
|
|
|
|
* @param {String} module - the module that provides the icon
|
|
|
|
* @param {String} icon - the name of the icon
|
|
|
|
* @return {String} the local path to the icon
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2017-02-15 23:54:32 +01:00
|
|
|
getNodeIconPath: registry.getNodeIconPath,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the full list of all icons available.
|
|
|
|
*
|
|
|
|
* @return {String} the icon list
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2017-11-30 14:13:35 +01:00
|
|
|
getNodeIcons: registry.getNodeIcons,
|
2015-04-07 17:02:15 +02:00
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Enables a node set, making it available for use.
|
|
|
|
*
|
|
|
|
* @param {String} type - the node type or set identifier
|
|
|
|
* @return {Promise} A promise that resolves when the node set has been enabled
|
|
|
|
* @throws if the identifier is not recognised or runtime settings are unavailable
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
enableNode: enableNodeSet,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables a node set, making it unavailable for use.
|
|
|
|
*
|
|
|
|
* @param {String} type - the node type or set identifier
|
|
|
|
* @return {Promise} A promise that resolves when the node set has been disabled
|
|
|
|
* @throws if the identifier is not recognised or runtime settings are unavailable
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
disableNode: registry.disableNodeSet,
|
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a new module into the registry.
|
|
|
|
*
|
|
|
|
* This will rescan the node module paths looking for this module.
|
|
|
|
*
|
|
|
|
* @param {String} module - the name of the module to add
|
|
|
|
* @return {Promise<Object>} A promise that resolves with the module information once it has been added
|
|
|
|
* @throws if the module has already been added or the runtime settings are unavailable
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
addModule: addModule,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a module from the registry.
|
|
|
|
*
|
|
|
|
* @param {String} module - the name of the module to remove
|
|
|
|
* @return {Promise<Array>} A promise that resolves with the list of removed node sets
|
|
|
|
* @throws if the module is not found or the runtime settings are unavailable
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-04-07 17:02:15 +02:00
|
|
|
removeModule: registry.removeModule,
|
2017-02-15 23:54:32 +01:00
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Installs a new node module using npm and then add to the registry
|
|
|
|
*
|
|
|
|
* @param {String|Buffer} module - the name of the module to install, or a Buffer containing a module tar file
|
|
|
|
* @param {String} version - the version of the module to install, default: `latest`
|
|
|
|
* @param {String} url - (optional) a url to install the module from
|
|
|
|
* @return {Promise<Array>} A promise that resolves with the module information once it has been installed
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-11-09 12:29:48 +01:00
|
|
|
installModule: installer.installModule,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uninstalls a module using npm
|
|
|
|
*
|
|
|
|
* @param {String} module - the name of the module to uninstall
|
|
|
|
* @return {Promise<Array>} A promise that resolves when the module has been removed
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2015-11-09 12:29:48 +01:00
|
|
|
uninstallModule: installer.uninstallModule,
|
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Update to internal list of available modules based on what has been actually
|
|
|
|
* loaded.
|
|
|
|
*
|
2020-12-23 23:05:58 +01:00
|
|
|
* The `externalModules.autoInstall` (previously `autoInstallModules`)
|
|
|
|
* runtime option means the runtime may try to install
|
2020-12-02 10:25:10 +01:00
|
|
|
* missing modules after the initial load is complete. If that flag is not set
|
|
|
|
* this function is used to remove the modules from the registry's saved list.
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2016-10-12 23:30:32 +02:00
|
|
|
cleanModuleList: registry.cleanModuleList,
|
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Check if the regisrty is able to install/remove modules.
|
|
|
|
*
|
|
|
|
* This is based on whether it has found `npm` on the command-line.
|
|
|
|
* @return {Boolean} whether the installer is enabled
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2020-12-02 14:14:39 +01:00
|
|
|
installerEnabled: installer.installerEnabled,
|
2018-04-26 13:32:05 +02:00
|
|
|
|
2020-12-02 10:25:10 +01:00
|
|
|
/**
|
|
|
|
* Get a list of all example flows provided by nodes in the registry.
|
|
|
|
* @return {Object} an object, indexed by module, listing all example flows
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2018-04-26 13:32:05 +02:00
|
|
|
getNodeExampleFlows: library.getExampleFlows,
|
2020-12-02 10:25:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the full path to a node example
|
|
|
|
* @param {String} module - the name of the module providing the example
|
|
|
|
* @param {String} path - the relative path of the example
|
|
|
|
* @return {String} the full path to the example
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
* @memberof @node-red/registry
|
|
|
|
*/
|
2018-04-26 13:32:05 +02:00
|
|
|
getNodeExampleFlowPath: library.getExampleFlowPath,
|
|
|
|
|
2020-12-10 17:01:55 +01:00
|
|
|
registerPlugin: plugins.registerPlugin,
|
|
|
|
getPlugin: plugins.getPlugin,
|
|
|
|
getPluginsByType: plugins.getPluginsByType,
|
|
|
|
getPluginList: plugins.getPluginList,
|
|
|
|
getPluginConfigs: plugins.getPluginConfigs,
|
|
|
|
|
2018-04-26 13:32:05 +02:00
|
|
|
deprecated: require("./deprecated")
|
|
|
|
|
2015-04-07 17:02:15 +02:00
|
|
|
};
|