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 340 : function import_ManifestKeyword(val: JsonValue): ManifestKeyword {
23 340 : const obj = import_json_object(val);
24 340 : return {
25 340 : matches: get(obj, "matches", v => import_array(v, import_string)),
26 340 : goto: get_optional(obj, "goto", import_string),
27 340 : weight: get_optional(obj, "weight", import_number),
28 340 : translate: get_optional(obj, "translate", import_boolean),
29 340 : };
30 340 : }
31 :
32 : export interface ManifestDocs {
33 : label: string;
34 : url: string;
35 : }
36 :
37 340 : function import_ManifestDocs(val: JsonValue): ManifestDocs {
38 340 : const obj = import_json_object(val);
39 340 : return {
40 340 : label: get(obj, "label", import_string),
41 340 : url: get(obj, "url", import_string),
42 340 : };
43 340 : }
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 340 : function import_ManifestEntry(val: JsonValue): ManifestEntry {
54 340 : const obj = import_json_object(val);
55 340 : return {
56 340 : path: get_optional(obj, "path", import_string),
57 340 : label: get_optional(obj, "label", import_string),
58 340 : order: get_optional(obj, "order", import_number),
59 340 : docs: get_optional(obj, "docs", v => import_array(v, import_ManifestDocs)),
60 340 : keywords: get_optional(obj, "keywords", v => import_array(v, import_ManifestKeyword)),
61 340 : };
62 340 : }
63 :
64 : export interface ManifestSection {
65 : [name: string]: ManifestEntry;
66 : }
67 :
68 340 : function import_ManifestSection(val: JsonValue): ManifestSection {
69 340 : return import_record(val, import_ManifestEntry);
70 340 : }
71 :
72 : export interface ManifestParentSection {
73 : component: string | undefined;
74 : docs: ManifestDocs[] | undefined;
75 : }
76 :
77 340 : function import_ManifestParentSection(val: JsonValue): ManifestParentSection {
78 340 : const obj = import_json_object(val);
79 340 : return {
80 340 : component: get_optional(obj, "component", import_string),
81 340 : docs: get_optional(obj, "docs", v => import_array(v, import_ManifestDocs))
82 340 : };
83 340 : }
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 340 : function import_Manifest(val: JsonValue): Manifest {
96 340 : const obj = import_json_object(val);
97 340 : return {
98 340 : dashboard: get_optional(obj, "dashboard", import_ManifestSection),
99 340 : menu: get_optional(obj, "menu", import_ManifestSection),
100 340 : tools: get_optional(obj, "tools", import_ManifestSection),
101 340 : preload: get_optional(obj, "preload", v => import_array(v, import_string)),
102 340 : parent: get_optional(obj, "parent", import_ManifestParentSection),
103 340 : ".checksum": get_optional(obj, ".checksum", import_string),
104 340 : };
105 340 : }
106 :
107 : export interface Manifests {
108 : [pkg: string]: Manifest;
109 : }
110 :
111 340 : export function import_Manifests(val: JsonValue): Manifests {
112 340 : const obj = import_json_object(val);
113 340 : const res: Manifests = { };
114 340 : for (const pkg in obj) {
115 340 : const m = validate("manifests." + pkg, obj[pkg], import_Manifest, null);
116 340 : if (m)
117 340 : res[pkg] = m;
118 340 : }
119 340 : return res;
120 340 : }
121 :
122 : export interface ShellManifest {
123 : docs: ManifestDocs[] | undefined;
124 : locales: { [id: string]: string } | undefined;
125 : }
126 :
127 340 : export function import_ShellManifest(val: JsonValue): ShellManifest {
128 340 : const obj = import_json_object(val);
129 340 : return {
130 340 : docs: get_optional(obj, "docs", v => import_array(v, import_ManifestDocs)),
131 340 : locales: get_optional(obj, "locales", v => import_record(v, import_string)),
132 340 : };
133 340 : }
|