diff --git a/src/backend/src/util/objutil.js b/src/backend/src/util/objutil.js index 8022cd2e1..6d635ad14 100644 --- a/src/backend/src/util/objutil.js +++ b/src/backend/src/util/objutil.js @@ -1,10 +1,16 @@ +const { config } = require("yargs"); const { whatis } = require("./langutil"); +const DO_NOT_DEFINE = Symbol('DO_NOT_DEFINE'); + const createTransformedValues = (input, options = {}, state = {}) => { // initialize state if ( ! state.keys ) state.keys = []; if ( whatis(input) === 'array' ) { + if ( options.doNotProcessArrays ) { + return DO_NOT_DEFINE; + } const output = []; for ( let i=0 ; i < input.length; i++ ) { const value = input[i]; @@ -19,7 +25,10 @@ const createTransformedValues = (input, options = {}, state = {}) => { Object.setPrototypeOf(output, input); for ( const k in input ) { state.keys.push(k); - output[k] = createTransformedValues(input[k], options); + const new_value = createTransformedValues(input[k], options); + if ( new_value !== DO_NOT_DEFINE ) { + output[k] = new_value; + } state.keys.pop(); } return output; @@ -31,6 +40,21 @@ const createTransformedValues = (input, options = {}, state = {}) => { return value; }; + +config.__set_config_object__(createTransformedValues(config, { + mutateValue: (input, { state }) => { + const path = state.keys.join('.'); // or jq + // .... + if ( should_replace ) { + return 'replacement'; + } else { + return DO_NOT_DEFINE; + } + } +})) + + module.exports = { createTransformedValues, + DO_NOT_DEFINE, };