@hypericon/node-red-hypertable
Version:
Node-RED plugin to interact with Hypertable
46 lines (36 loc) • 1.42 kB
JavaScript
/**
* Read connection settings from a node's connection property node.
* @param {*} connection The hypertable-connection node
* @returns strings for: `baseUrl` (with trailking slash), `workspaceId`, `projectId`, and `apiKey`
* @throws an error if any connection property is missing
* @example ```js
* this.connection = RED.nodes.getNode(config.connection);
* const { baseUrl, projectId, apiKey } = readConnection(this.connection);
* ```
*/
function readConnection(connection) {
// Ensure the connection is defined
if (!connection) throw new Error("No Hypertable connection is defined");
/** @type string */
let baseUrl = connection.baseUrl;
if (!baseUrl) throw new Error("No base URL is specified in the connection");
baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
// /** @type string */
// const workspaceId = connection.workspaceId;
// if (!workspaceId) throw new Error("No workspace ID is specified in the connection");
/** @type string */
const projectId = connection.projectId;
if (!projectId) throw new Error("No project ID is specified in the connection");
/** @type string */
const apiKey = connection.apiKey;
if (!apiKey) throw new Error("No API key is specified in the connection");
return {
baseUrl,
// workspaceId,
projectId,
apiKey,
};
}
module.exports = {
readConnection,
};