async function prepEval(groups, groupName) {
  const {module, package: pkg, query, input, included} = getGroupData(groups, groupName)
  const base = ['eval', '--fail'] // Fail on undefined
  const rest = []
  const moduleFilenameMap = {}

  try {
    let tmpModule = await tmpFile({postfix: '.rego'})
    await promFS.writeFile(tmpModule, module)
    rest.push('-d', tmpModule, '--package', pkg)
    moduleFilenameMap[tmpModule] = EVAL_MODULE_NAME

    if (input) {
      let stringified = ''
      try {
        stringified = JSON.stringify(input)
      } catch (e) {
        throw new ChainedError('input cannot be stringified', e)
      }
      const tmpInput = await tmpFile({postfix: '.json'})
      await promFS.writeFile(tmpInput, stringified)
      rest.push('--input', tmpInput)
    }

    if (query) {
      rest.push(query)
    } else { // Simulate playground default behavior
      if (included) {
        rest.push('data')
      } else {
        rest.push(`data.${pkg}`)
      }
    }

    if (included) {
      for (let [incName, incModule] of Object.entries(included)) {
        let tmpIncluded = await tmpFile({postfix: '.rego'})
        await promFS.writeFile(tmpIncluded, incModule)
        rest.push('-d', tmpIncluded)
        moduleFilenameMap[tmpIncluded] = incName
      }
    }

    return [(format) => [...base, `--format=${format}`, ...rest], moduleFilenameMap]
  } catch (e) {
    throw new ChainedError('a problem occurred while preparing to evaluate', e)
  }
}
// Returns 1st a function that consumes a string for the output format you want and produces an array of arguments and 2nd a map of module file names to strings that should be replaced in error messages. May throw a user-friendly error.
Returns 1st a function that consumes a string for the output format you want and produces an array of arguments and 2nd a map of module file names to strings that should be replaced in error messages. May throw a user-friendly error.
Returns 1st a function that consumes a string for the output format you want and produces an array of arguments and 2nd a map of module file names to strings that should be replaced in error messages . May throw a user - friendly error .
async function prepEval(groups, groupName) {
  const {module, package: pkg, query, input, included} = getGroupData(groups, groupName)
  const base = ['eval', '--fail'] 
  const rest = []
  const moduleFilenameMap = {}
  try {
    let tmpModule = await tmpFile({postfix: '.rego'})
    await promFS.writeFile(tmpModule, module)
    rest.push('-d', tmpModule, '--package', pkg)
    moduleFilenameMap[tmpModule] = EVAL_MODULE_NAME
    if (input) {
      let stringified = ''
      try {
        stringified = JSON.stringify(input)
      } catch (e) {
        throw new ChainedError('input cannot be stringified', e)
      }
      const tmpInput = await tmpFile({postfix: '.json'})
      await promFS.writeFile(tmpInput, stringified)
      rest.push('--input', tmpInput)
    }
    if (query) {
      rest.push(query)
    } else { 
      if (included) {
        rest.push('data')
      } else {
        rest.push(`data.${pkg}`)
      }
    }
    if (included) {
      for (let [incName, incModule] of Object.entries(included)) {
        let tmpIncluded = await tmpFile({postfix: '.rego'})
        await promFS.writeFile(tmpIncluded, incModule)
        rest.push('-d', tmpIncluded)
        moduleFilenameMap[tmpIncluded] = incName
      }
    }
    return [(format) => [...base, `--format=${format}`, ...rest], moduleFilenameMap]
  } catch (e) {
    throw new ChainedError('a problem occurred while preparing to evaluate', e)
  }
}
async function prepEval ( groups , groupName ) { const { module , package : pkg , query , input , included } = getGroupData ( groups , groupName ) const base = [ 'eval' , '--fail' ] const rest = [ ] const moduleFilenameMap = { } try { let tmpModule = await tmpFile ( { postfix : '.rego' } ) await promFS . writeFile ( tmpModule , module ) rest . push ( '-d' , tmpModule , '--package' , pkg ) moduleFilenameMap [ tmpModule ] = EVAL_MODULE_NAME if ( input ) { let stringified = '' try { stringified = JSON . stringify ( input ) } catch ( e ) { throw new ChainedError ( 'input cannot be stringified' , e ) } const tmpInput = await tmpFile ( { postfix : '.json' } ) await promFS . writeFile ( tmpInput , stringified ) rest . push ( '--input' , tmpInput ) } if ( query ) { rest . push ( query ) } else { if ( included ) { rest . push ( 'data' ) } else { rest . push ( ` ${ pkg } ` ) } } if ( included ) { for ( let [ incName , incModule ] of Object . entries ( included ) ) { let tmpIncluded = await tmpFile ( { postfix : '.rego' } ) await promFS . writeFile ( tmpIncluded , incModule ) rest . push ( '-d' , tmpIncluded ) moduleFilenameMap [ tmpIncluded ] = incName } } return [ ( format ) => [ ... base , ` ${ format } ` , ... rest ] , moduleFilenameMap ] } catch ( e ) { throw new ChainedError ( 'a problem occurred while preparing to evaluate' , e ) } }
Returns 1st a function that consumes a string for the output format you want and produces an array of arguments and 2nd a map of module file names to strings that should be replaced in error messages.
Returns 1st a function that consumes a string for the output format you want and produces an array of arguments and 2nd a map of module file names to strings that should be replaced in error messages .
// Fail on undefined // Simulate playground default behavior