diff --git a/core.js b/core.js index 4e6a764..408f503 100644 --- a/core.js +++ b/core.js @@ -46,7 +46,7 @@ function generatePluginMethod(method) { throw shouldRedactSecrets ? redaction.redactSecrets(error, secrets) : error; } - if (!allowEmptyResult && (_.isNil(result) || _.isEmpty(result))) { + if (!allowEmptyResult && helpers.isResultEmpty(result)) { return consts.OPERATION_FINISHED_SUCCESSFULLY_MESSAGE; } @@ -56,13 +56,16 @@ function generatePluginMethod(method) { function generateAutocompleteFunction(autocompleteFunction, functionName) { return async (query, settings, params) => { - const parsedParams = await autocomplete.readAutocompleteFunctionArguments( + const { + params: parsedParams, + settings: parsedSettings, + } = await autocomplete.readAutocompleteFunctionArguments( params, settings, functionName, ); - return autocompleteFunction(query, parsedParams, { settings, params }); + return autocompleteFunction(query, parsedParams, { settings, params, parsedSettings }); }; } diff --git a/helpers.js b/helpers.js index 325d293..0474b6e 100644 --- a/helpers.js +++ b/helpers.js @@ -202,6 +202,15 @@ function generateRandomString() { return Math.random().toString(36).slice(2); } +function isResultEmpty(result) { + return ( + _.isNil(result) // null or undefined + || (_.isArray(result) && result.length === 0) // empty arrays + || (_.isPlainObject(result) && _.keys(result).length === 0) // empty objects + || (_.isString(result) && result.length === 0) // empty strings + ); +} + module.exports = { readActionArguments, temporaryFileSentinel, @@ -210,4 +219,5 @@ module.exports = { generateRandomTemporaryPath, generateRandomEnvironmentVariableName, analyzePath: parsers.filePath, + isResultEmpty, }; diff --git a/package.json b/package.json index 064c454..e2da7bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kaholo/plugin-library", - "version": "2.3.0", + "version": "2.3.1", "description": "Kaholo library for plugins", "main": "kaholo-plugin-library.js", "scripts": {