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