UNPKG

n8n-nodes-tulip

Version:
114 lines 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTables = getTables; exports.getColumns = getColumns; exports.getRecordsIDs = getRecordsIDs; exports.getMachines = getMachines; const n8n_workflow_1 = require("n8n-workflow"); const transport_1 = require("../transport"); async function getTables() { const endpoint = 'tables'; const responseData = await transport_1.apiRequest.call(this, 'GET', endpoint, {}); const returnData = []; if (responseData === undefined) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No data got returned'); } for (const data of responseData) { returnData.push({ name: data.label, value: data.id, }); } returnData.sort((a, b) => { if (a.name < b.name) { return -1; } if (a.name > b.name) { return 1; } return 0; }); return returnData; } async function getColumns() { const tableId = this.getCurrentNodeParameter('tableId'); const endpoint = `tables/${tableId}`; const responseData = await transport_1.apiRequest.call(this, 'GET', endpoint, {}); const returnData = []; if (responseData === undefined) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No data got returned'); } if (responseData.columns && Array.isArray(responseData.columns)) { for (const column of responseData.columns) { returnData.push({ name: column.label, value: column.name, description: `Name: ${column.name}, Type: ${column.dataType.type}`, }); } } returnData.sort((a, b) => { if (a.name < b.name) { return -1; } if (a.name > b.name) { return 1; } return 0; }); return returnData; } async function getRecordsIDs() { const tableId = this.getCurrentNodeParameter('tableId'); const endpoint = `tables/${tableId}/records`; const responseData = await transport_1.apiRequest.call(this, 'GET', endpoint, {}); const returnData = []; if (responseData === undefined) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No data got returned'); } for (const data of responseData) { returnData.push({ name: data.id, value: data.id, }); } returnData.sort((a, b) => { if (a.name < b.name) { return -1; } if (a.name > b.name) { return 1; } return 0; }); return returnData; } async function getMachines() { const endpoint = 'machines'; const responseData = await transport_1.apiRequest.call(this, 'GET', endpoint, {}); const returnData = []; if (responseData === undefined) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No data got returned'); } for (const group of responseData) { if (group.machines && Array.isArray(group.machines)) { for (const machine of group.machines) { returnData.push({ name: machine.name, value: machine.id, }); } } } returnData.sort((a, b) => { if (a.name < b.name) { return -1; } if (a.name > b.name) { return 1; } return 0; }); return returnData; } //# sourceMappingURL=loadOptions.js.map