Debian Codegraph @

pkg/shell/manifests.ts

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