UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

160 lines 5.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SQL_RUN_STORED_PROCEDURE = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../../createNodeDescriptor"); const errors_1 = require("../../../../errors"); const sqlConnection_1 = require("./sqlConnection"); exports.SQL_RUN_STORED_PROCEDURE = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "sqlRunStoredProcedure", defaultLabel: "Run StoredProcedure", summary: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__SUMMARY", fields: [ { key: "connection", type: "connection", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__CONNECTION__LABEL", params: { required: true, connectionType: sqlConnection_1.SQL_CONNECTION.type } }, { key: "storedProcedure", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__STORED_PROCEDURE__LABEL", type: "cognigyText", params: { required: true } }, { key: "inputs", type: "json", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__INPUTS__LABEL" }, { key: "outputs", type: "json", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__OUTPUTS__LABEL" }, { key: "storeLocation", type: "select", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__STORE_LOCATION__LABEL", params: { options: [ { label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__STORE_LOCATION__INPUT__LABEL", value: "input" }, { label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__STORE_LOCATION__CONTEXT__LABEL", value: "context" } ], required: true }, defaultValue: "input" }, { key: "inputKey", type: "cognigyText", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__INPUT_KEY__LABEL", defaultValue: "sqlresult", condition: { key: "storeLocation", value: "input", } }, { key: "contextKey", type: "cognigyText", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__CONTEXT_KEY__LABEL", condition: { key: "storeLocation", value: "context", } }, { key: "stopOnError", type: "toggle", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__STOP_ON_ERROR__LABEL", defaultValue: false } ], sections: [ { key: "storage", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__STORAGE__LABEL", defaultCollapsed: true, fields: [ "storeLocation", "inputKey", "contextKey", ] }, { key: "advanced", label: "UI__NODE_EDITOR__SQL__SQL_RUN_STORED_PROCEDURE__ADVANCED__LABEL", defaultCollapsed: true, fields: [ "stopOnError" ] } ], form: [ { type: "field", key: "connection" }, { type: "field", key: "storedProcedure" }, { type: "field", key: "inputs" }, { type: "field", key: "outputs" }, { type: "section", key: "storage" }, { type: "section", key: "advanced" } ], preview: { key: "storedProcedure", type: "text" }, tags: ["data", "service", "sql"], function: async ({ cognigy, config }) => { const { api, input } = cognigy; const { connection = {}, storeLocation, contextKey, inputKey, inputs, outputs, storedProcedure, stopOnError } = config; if (!connection) { throw new errors_1.InvalidArgumentError("A connection has to be selected"); } if (storeLocation === "context" && !contextKey) { throw new errors_1.InvalidArgumentError("A context key has to be specified"); } if (storeLocation === "input" && !inputKey) { throw new errors_1.InvalidArgumentError("An input key has to be specified"); } try { if (storeLocation === "context") api.deleteContext(contextKey); const result = await api.runSQLStoredProcedure({ connection, inputs, outputs, storedProcedure, traceId: input.traceId }); if (storeLocation === "context") api.addToContext(contextKey, result, "simple"); else input[inputKey] = result; } catch (err) { if (stopOnError) { throw err; } const resultObject = { result: null, error: err.message }; if (storeLocation === "context") api.addToContext(contextKey, resultObject, "simple"); else api.addToInput(inputKey, resultObject); } } }); //# sourceMappingURL=runStoredProcedure.js.map