"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/cli/commands/types.ts" (20 Feb 2024, 2863 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. See also the last Fossies "Diffs" side-by-side code changes report for "types.ts": 1.1275.0_vs_1.1276.0.

    1 export type MethodResult = CommandResult | string | void;
    2 
    3 export class CommandResult {
    4   result: string;
    5   constructor(result: string) {
    6     this.result = result;
    7   }
    8 
    9   public toString(): string {
   10     return this.result;
   11   }
   12 
   13   public getDisplayResults() {
   14     return this.result;
   15   }
   16 }
   17 
   18 export abstract class TestCommandResult extends CommandResult {
   19   protected jsonResult = '';
   20   protected sarifResult = '';
   21   protected jsonData = {};
   22 
   23   public getJsonResult(): string {
   24     return this.jsonResult;
   25   }
   26 
   27   public getSarifResult(): string {
   28     return this.sarifResult;
   29   }
   30 
   31   public getJsonData(): Record<string, unknown> {
   32     return this.jsonData;
   33   }
   34 
   35   public static createHumanReadableTestCommandResult(
   36     humanReadableResult: string,
   37     jsonResult: string,
   38     sarifResult?: string,
   39     jsonData?: Record<string, unknown>,
   40   ): HumanReadableTestCommandResult {
   41     return new HumanReadableTestCommandResult(
   42       humanReadableResult,
   43       jsonResult,
   44       sarifResult,
   45       jsonData,
   46     );
   47   }
   48 
   49   public static createJsonTestCommandResult(
   50     stdout: string,
   51     jsonResult?: string,
   52     sarifResult?: string,
   53     jsonPayload?: Record<string, unknown>,
   54   ): JsonTestCommandResult {
   55     return new JsonTestCommandResult(
   56       stdout,
   57       jsonResult,
   58       sarifResult,
   59       jsonPayload,
   60     );
   61   }
   62 }
   63 
   64 class HumanReadableTestCommandResult extends TestCommandResult {
   65   protected jsonResult = '';
   66   protected sarifResult = '';
   67   protected jsonData = {};
   68 
   69   constructor(
   70     humanReadableResult: string,
   71     jsonResult: string,
   72     sarifResult?: string,
   73     jsonData?: Record<string, unknown>,
   74   ) {
   75     super(humanReadableResult);
   76     this.jsonResult = jsonResult;
   77     if (sarifResult) {
   78       this.sarifResult = sarifResult;
   79     }
   80     if (jsonData) {
   81       this.jsonData = jsonData;
   82     }
   83   }
   84 
   85   public getJsonResult(): string {
   86     return this.jsonResult;
   87   }
   88 
   89   public getSarifResult(): string {
   90     return this.sarifResult;
   91   }
   92 
   93   public getJsonData(): Record<string, unknown> {
   94     return this.jsonData;
   95   }
   96 }
   97 
   98 class JsonTestCommandResult extends TestCommandResult {
   99   constructor(
  100     stdout: string,
  101     jsonResult?: string,
  102     sarifResult?: string,
  103     jsonData?: Record<string, unknown>,
  104   ) {
  105     super(stdout);
  106     if (jsonResult) {
  107       this.jsonResult = jsonResult;
  108     }
  109     if (sarifResult) {
  110       this.sarifResult = sarifResult;
  111     } else {
  112       this.jsonResult = stdout;
  113     }
  114     if (jsonData) {
  115       this.jsonData = jsonData;
  116     }
  117   }
  118 
  119   public getJsonResult(): string {
  120     return this.jsonResult;
  121   }
  122 
  123   public getSarifResult(): string {
  124     return this.sarifResult;
  125   }
  126 }
  127 
  128 export interface IgnoreMetadata {
  129   reason: string;
  130   expires: Date;
  131   created: Date;
  132 }
  133 
  134 export interface IgnoreRulePathData {
  135   [path: string]: IgnoreMetadata;
  136 }
  137 
  138 export interface IgnoreRules {
  139   [issueId: string]: IgnoreRulePathData[];
  140 }