UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

158 lines 5.45 kB
import { __awaiter } from "tslib"; /* Custom modules */ import { createNodeDescriptor } from "../../../createNodeDescriptor"; import { InvalidArgumentError } from "../../../../errors"; import { SQL_CONNECTION } from "./sqlConnection"; export const SQL_RUN_STORED_PROCEDURE = 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: 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: ({ cognigy, config }) => __awaiter(void 0, void 0, void 0, function* () { const { api, input } = cognigy; const { connection = {}, storeLocation, contextKey, inputKey, inputs, outputs, storedProcedure, stopOnError } = config; if (!connection) { throw new InvalidArgumentError("A connection has to be selected"); } if (storeLocation === "context" && !contextKey) { throw new InvalidArgumentError("A context key has to be specified"); } if (storeLocation === "input" && !inputKey) { throw new InvalidArgumentError("An input key has to be specified"); } try { if (storeLocation === "context") api.deleteContext(contextKey); const result = yield 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