LCOV - code coverage report
Current view: top level - pkg/shell - manifests.ts Coverage Total Hit
Test: cockpit Lines: 100.0 % 64 64
Test Date: 2026-06-16 14:09:37

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2024 Red Hat, Inc.
       3              :  * SPDX-License-Identifier: LGPL-2.1-or-later
       4              :  */
       5              : 
       6              : import { JsonValue } from "cockpit";
       7              : 
       8              : import {
       9              :     import_json_object,
      10              :     import_string, import_number, import_boolean, import_record, import_array,
      11              :     get, get_optional,
      12              :     validate,
      13              : } from "import-json";
      14              : 
      15              : export interface ManifestKeyword {
      16              :     matches: string[];
      17              :     goto: string | undefined;
      18              :     weight: number | undefined;
      19              :     translate: boolean | undefined;
      20              : }
      21              : 
      22          123 : function import_ManifestKeyword(val: JsonValue): ManifestKeyword {
      23          123 :     const obj = import_json_object(val);
      24          123 :     return {
      25          123 :         matches: get(obj, "matches", v => import_array(v, import_string)),
      26          123 :         goto: get_optional(obj, "goto", import_string),
      27          123 :         weight: get_optional(obj, "weight", import_number),
      28          123 :         translate: get_optional(obj, "translate", import_boolean),
      29          123 :     };
      30          123 : }
      31              : 
      32              : export interface ManifestDocs {
      33              :     label: string;
      34              :     url: string;
      35              : }
      36              : 
      37          123 : function import_ManifestDocs(val: JsonValue): ManifestDocs {
      38          123 :     const obj = import_json_object(val);
      39          123 :     return {
      40          123 :         label: get(obj, "label", import_string),
      41          123 :         url: get(obj, "url", import_string),
      42          123 :     };
      43          123 : }
      44              : 
      45              : export interface ManifestEntry {
      46              :     path: string | undefined;
      47              :     label: string | undefined;
      48              :     order: number | undefined;
      49              :     docs: ManifestDocs[] | undefined;
      50              :     keywords: ManifestKeyword[] | undefined;
      51              : }
      52              : 
      53          123 : function import_ManifestEntry(val: JsonValue): ManifestEntry {
      54          123 :     const obj = import_json_object(val);
      55          123 :     return {
      56          123 :         path: get_optional(obj, "path", import_string),
      57          123 :         label: get_optional(obj, "label", import_string),
      58          123 :         order: get_optional(obj, "order", import_number),
      59          123 :         docs: get_optional(obj, "docs", v => import_array(v, import_ManifestDocs)),
      60          123 :         keywords: get_optional(obj, "keywords", v => import_array(v, import_ManifestKeyword)),
      61          123 :     };
      62          123 : }
      63              : 
      64              : export interface ManifestSection {
      65              :     [name: string]: ManifestEntry;
      66              : }
      67              : 
      68          123 : function import_ManifestSection(val: JsonValue): ManifestSection {
      69          123 :     return import_record(val, import_ManifestEntry);
      70          123 : }
      71              : 
      72              : export interface ManifestParentSection {
      73              :     component: string | undefined;
      74              :     docs: ManifestDocs[] | undefined;
      75              : }
      76              : 
      77          123 : function import_ManifestParentSection(val: JsonValue): ManifestParentSection {
      78          123 :     const obj = import_json_object(val);
      79          123 :     return {
      80          123 :         component: get_optional(obj, "component", import_string),
      81          123 :         docs: get_optional(obj, "docs", v => import_array(v, import_ManifestDocs))
      82          123 :     };
      83          123 : }
      84              : 
      85              : export interface Manifest {
      86              :     dashboard: ManifestSection | undefined;
      87              :     menu: ManifestSection | undefined;
      88              :     tools: ManifestSection | undefined;
      89              : 
      90              :     preload: string[] | undefined;
      91              :     parent: ManifestParentSection | undefined;
      92              :     ".checksum": string | undefined;
      93              : }
      94              : 
      95          123 : function import_Manifest(val: JsonValue): Manifest {
      96          123 :     const obj = import_json_object(val);
      97          123 :     return {
      98          123 :         dashboard: get_optional(obj, "dashboard", import_ManifestSection),
      99          123 :         menu: get_optional(obj, "menu", import_ManifestSection),
     100          123 :         tools: get_optional(obj, "tools", import_ManifestSection),
     101          123 :         preload: get_optional(obj, "preload", v => import_array(v, import_string)),
     102          123 :         parent: get_optional(obj, "parent", import_ManifestParentSection),
     103          123 :         ".checksum": get_optional(obj, ".checksum", import_string),
     104          123 :     };
     105          123 : }
     106              : 
     107              : export interface Manifests {
     108              :     [pkg: string]: Manifest;
     109              : }
     110              : 
     111          123 : export function import_Manifests(val: JsonValue): Manifests {
     112          123 :     const obj = import_json_object(val);
     113          123 :     const res: Manifests = { };
     114          123 :     for (const pkg in obj) {
     115          123 :         const m = validate("manifests." + pkg, obj[pkg], import_Manifest, null);
     116          123 :         if (m)
     117          123 :             res[pkg] = m;
     118          123 :     }
     119          123 :     return res;
     120          123 : }
     121              : 
     122              : export interface ShellManifest {
     123              :     docs: ManifestDocs[] | undefined;
     124              :     locales: { [id: string]: string } | undefined;
     125              : }
     126              : 
     127          123 : export function import_ShellManifest(val: JsonValue): ShellManifest {
     128          123 :     const obj = import_json_object(val);
     129          123 :     return {
     130          123 :         docs: get_optional(obj, "docs", v => import_array(v, import_ManifestDocs)),
     131          123 :         locales: get_optional(obj, "locales", v => import_record(v, import_string)),
     132          123 :     };
     133          123 : }
        

Generated by: LCOV version 2.0-1