Skip to content

Commit

Permalink
Release v2.2.1
Browse files Browse the repository at this point in the history
KP-1172 (Release v2.2.1)
  • Loading branch information
xkcm authored May 15, 2023
2 parents f293f4a + af8eb59 commit fb1019b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
17 changes: 15 additions & 2 deletions autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ function mapAutocompleteFuncParamsToObject(params) {

function findMatchingMethodDefinition(sortedParamNames) {
const config = loadConfiguration();
const accountParamNames = config.auth ? _.map(config.auth.params, "name") : [];
const cleanParamNames = _.difference(sortedParamNames, accountParamNames);
const accountParamNames = new Set(config.auth ? _.map(config.auth.params, "name") : []);
const cleanParamNames = sortedParamNames.filter((paramName) => {
if (accountParamNames.has(paramName)) {
accountParamNames.delete(paramName);
return false;
}
return true;
});

const matchingMethodDefinition = config.methods.find((method) => (
_.isEqual(
Expand All @@ -49,6 +55,13 @@ function readAutocompleteFunctionArguments(params, settings, autocompleteFunctio
const paramNames = _.sortBy(_.map(params, "name"));
const methodDefinition = findMatchingMethodDefinition(paramNames);

if (!methodDefinition) {
return {
...mapAutocompleteFuncParamsToObject(settings),
...mapAutocompleteFuncParamsToObject(params),
};
}

const autocompleteParamIndex = methodDefinition.params.findIndex((param) => (
param.type === "autocomplete" && param.functionName === autocompleteFunctionName
));
Expand Down
32 changes: 26 additions & 6 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const validators = require("./validators");
const {
loadMethodFromConfiguration,
loadAccountFromConfiguration,
loadConfiguration,
} = require("./config-loader");

const CREATE_TEMPORARY_FILE_LINUX_COMMAND = "mktemp -p /tmp kaholo_plugin_library.XXXXXX";
Expand All @@ -22,15 +23,33 @@ async function readActionArguments(
methodDefinition = loadMethodFromConfiguration(action.method.name),
) {
const accountDefinition = loadAccountFromConfiguration();

const paramValues = removeUndefinedAndEmpty(action.params);
const settingsValues = removeUndefinedAndEmpty(settings);

if (_.isNil(methodDefinition)) {
throw new Error(`Could not find a method "${action.method.name}" in config.json`);
}

const settingsParamsDefinition = loadConfiguration()?.settings ?? [];
const settingsParsingPromises = settingsParamsDefinition.map(async (settingDefinition) => {
settingsValues[settingDefinition.name] = await parseParameter(
settingDefinition,
settingsValues[settingDefinition.name],
);

const { validationType } = settingDefinition;
if (validationType) {
validateParamValue(
settingsValues[settingDefinition.name],
validationType,
);
}
});
await Promise.all(settingsParsingPromises);

const paramsParsingPromises = methodDefinition.params.map(async (paramDefinition) => {
paramValues[paramDefinition.name] = await parseMethodParameter(
paramValues[paramDefinition.name] = await parseParameter(
paramDefinition,
paramValues[paramDefinition.name],
settingsValues[paramDefinition.name],
Expand All @@ -44,12 +63,11 @@ async function readActionArguments(
);
}
});

await Promise.all(paramsParsingPromises);

if (accountDefinition) {
const accountParsingPromises = accountDefinition.params.map(async (paramDefinition) => {
paramValues[paramDefinition.name] = await parseMethodParameter(
paramValues[paramDefinition.name] = await parseParameter(
paramDefinition,
paramValues[paramDefinition.name],
settingsValues[paramDefinition.name],
Expand All @@ -63,11 +81,13 @@ async function readActionArguments(
);
}
});

await Promise.all(accountParsingPromises);
}

return removeUndefinedAndEmpty(paramValues);
return removeUndefinedAndEmpty({
...settingsValues,
...paramValues,
});
}

async function temporaryFileSentinel(fileDataArray, functionToWatch) {
Expand Down Expand Up @@ -151,7 +171,7 @@ function removeUndefinedAndEmpty(object) {
return _.omitBy(object, (value) => value === "" || _.isNil(value) || (_.isObjectLike(value) && _.isEmpty(value)));
}

function parseMethodParameter(paramDefinition, paramValue, settingsValue) {
function parseParameter(paramDefinition, paramValue, settingsValue) {
const valueToParse = paramValue ?? settingsValue ?? paramDefinition.default;
if (_.isNil(valueToParse)) {
if (paramDefinition.required) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kaholo/plugin-library",
"version": "2.2.0",
"version": "2.2.1",
"description": "Kaholo library for plugins",
"main": "kaholo-plugin-library.js",
"scripts": {
Expand Down

0 comments on commit fb1019b

Please sign in to comment.