"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/cli/commands/monitor/process-json-monitor.ts" (20 Feb 2024, 815 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import { GoodResult, BadResult } from './types';
    2 
    3 export function processJsonMonitorResponse(
    4   results: Array<GoodResult | BadResult>,
    5 ): string {
    6   let dataToSend = results.map((result) => {
    7     if (result.ok) {
    8       const jsonData = JSON.parse(result.data);
    9       if (result.projectName) {
   10         jsonData.projectName = result.projectName;
   11       }
   12       return jsonData;
   13     }
   14     return { ok: false, error: result.data.message, path: result.path };
   15   });
   16   // backwards compat - strip array if only one result
   17   dataToSend = dataToSend.length === 1 ? dataToSend[0] : dataToSend;
   18   const stringifiedData = JSON.stringify(dataToSend, null, 2);
   19 
   20   if (results.every((res) => res.ok)) {
   21     return stringifiedData;
   22   }
   23   const err = new Error(stringifiedData) as any;
   24   err.json = stringifiedData;
   25   throw err;
   26 }