@shepherdjerred/helm-types 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # @shepherdjerred/helm-types
2
+
3
+ Generate TypeScript types from Helm chart values.
4
+
5
+ ## What it does
6
+
7
+ This tool fetches Helm charts and generates strongly-typed TypeScript interfaces from their
8
+ `values.yaml` and `values.schema.json` files. Use it to get type-safe Helm configurations in your
9
+ TypeScript projects.
10
+
11
+ **Features:**
12
+
13
+ - Fetch charts from any Helm repository
14
+ - Generate nested interfaces with proper types
15
+ - Parse YAML comments for JSDoc documentation
16
+ - Support for arrays, unions, enums, and optional properties
17
+ - Handle reserved keywords and special characters
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @shepherdjerred/helm-types
23
+ # or
24
+ bun add @shepherdjerred/helm-types
25
+ ```
26
+
27
+ ## Requirements
28
+
29
+ - **Node.js 18+** or **Bun**
30
+ - **Helm CLI** installed and available in PATH
31
+
32
+ ## CLI Usage
33
+
34
+ Generate types directly with npx/bunx:
35
+
36
+ ```bash
37
+ # Generate types for ArgoCD
38
+ npx @shepherdjerred/helm-types \
39
+ --name argo-cd \
40
+ --repo https://argoproj.github.io/argo-helm \
41
+ --version 8.3.1 \
42
+ --output argo-cd.types.ts
43
+
44
+ # Short flags
45
+ npx @shepherdjerred/helm-types \
46
+ -n argo-cd \
47
+ -r https://argoproj.github.io/argo-helm \
48
+ -v 8.3.1 \
49
+ -o argo-cd.types.ts
50
+
51
+ # Print to stdout
52
+ npx @shepherdjerred/helm-types \
53
+ -n argo-cd \
54
+ -r https://argoproj.github.io/argo-helm \
55
+ -v 8.3.1
56
+
57
+ # Custom interface name
58
+ npx @shepherdjerred/helm-types \
59
+ -n argo-cd \
60
+ -r https://argoproj.github.io/argo-helm \
61
+ -v 8.3.1 \
62
+ -i CustomArgocdValues \
63
+ -o argo-cd.types.ts
64
+ ```
65
+
66
+ **Options:**
67
+
68
+ | Flag | Description |
69
+ | ----------------- | ----------------------------------------------- |
70
+ | `--name, -n` | Unique identifier for the chart (required) |
71
+ | `--chart, -c` | Chart name in repository (defaults to --name) |
72
+ | `--repo, -r` | Helm repository URL (required) |
73
+ | `--version, -v` | Chart version (required) |
74
+ | `--output, -o` | Output file path (defaults to stdout) |
75
+ | `--interface, -i` | Interface name (auto-generated if not provided) |
76
+ | `--help, -h` | Show help message |
77
+
78
+ ## Programmatic API
79
+
80
+ ```typescript
81
+ import { fetchHelmChart, convertToTypeScriptInterface, generateTypeScriptCode } from "@shepherdjerred/helm-types";
82
+
83
+ // 1. Define your chart
84
+ const chart = {
85
+ name: "argo-cd",
86
+ chartName: "argo-cd",
87
+ repoUrl: "https://argoproj.github.io/argo-helm",
88
+ version: "8.3.1",
89
+ };
90
+
91
+ // 2. Fetch and generate types
92
+ const { values, schema, yamlComments } = await fetchHelmChart(chart);
93
+ const tsInterface = convertToTypeScriptInterface(values, "ArgocdHelmValues", schema, yamlComments);
94
+ const code = generateTypeScriptCode(tsInterface, chart.name);
95
+
96
+ // 3. Write output
97
+ await fs.writeFile("argo-cd.types.ts", code);
98
+ ```
99
+
100
+ ## Generated Output
101
+
102
+ ### Values Interface
103
+
104
+ ```typescript
105
+ export type ArgocdHelmValues = {
106
+ /**
107
+ * Number of replicas
108
+ * @default 1
109
+ */
110
+ replicaCount?: number;
111
+
112
+ image?: ArgocdHelmValuesImage;
113
+ service?: ArgocdHelmValuesService;
114
+ };
115
+ ```
116
+
117
+ ### Nested Types
118
+
119
+ ```typescript
120
+ export type ArgocdHelmValuesImage = {
121
+ repository?: string;
122
+ tag?: string;
123
+ pullPolicy?: "Always" | "IfNotPresent" | "Never";
124
+ };
125
+ ```
126
+
127
+ ### Parameters Type (Flattened)
128
+
129
+ A flattened type using dot notation for Helm's `--set` parameter syntax:
130
+
131
+ ```typescript
132
+ export type ArgocdHelmParameters = {
133
+ replicaCount?: string;
134
+ "image.repository"?: string;
135
+ "image.tag"?: string;
136
+ "service.type"?: string;
137
+ };
138
+ ```
139
+
140
+ ## Type Inference
141
+
142
+ The library intelligently infers types from values:
143
+
144
+ | Value | Inferred Type |
145
+ | ------------------- | ---------------- |
146
+ | `true`, `false` | `boolean` |
147
+ | `"true"`, `"false"` | `boolean` |
148
+ | `123`, `3.14` | `number` |
149
+ | `"123"` | `number` |
150
+ | `"hello"` | `string` |
151
+ | `[]` | `unknown[]` |
152
+ | `[1, 2]` | `number[]` |
153
+ | `{}` | nested interface |
154
+
155
+ JSON schema takes precedence when available.
156
+
157
+ ## API Reference
158
+
159
+ ### `fetchHelmChart(chart: ChartInfo)`
160
+
161
+ Fetches a Helm chart and extracts configuration.
162
+
163
+ ```typescript
164
+ type ChartInfo = {
165
+ name: string; // Unique identifier
166
+ chartName: string; // Chart name in repo
167
+ repoUrl: string; // Helm repository URL
168
+ version: string; // Chart version
169
+ };
170
+
171
+ // Returns
172
+ {
173
+ values: Record<string, unknown>;
174
+ schema: JSONSchemaProperty | null;
175
+ yamlComments: Map<string, string>;
176
+ }
177
+ ```
178
+
179
+ ### `convertToTypeScriptInterface(values, name, schema?, comments?, prefix?)`
180
+
181
+ Converts Helm values to TypeScript interface definition.
182
+
183
+ - `values` - Chart values object
184
+ - `name` - Interface name
185
+ - `schema?` - Optional JSON schema for type hints
186
+ - `comments?` - Optional YAML comments for JSDoc
187
+ - `prefix?` - Optional key prefix for nested types
188
+
189
+ ### `generateTypeScriptCode(interface, chartName)`
190
+
191
+ Generates TypeScript code from interface definition. Returns a string containing the main values
192
+ interface, nested type definitions, and flattened parameters type.
193
+
194
+ ### `parseYAMLComments(yamlContent)`
195
+
196
+ Extracts YAML comments and associates them with keys.
197
+
198
+ ## License
199
+
200
+ GPL-3.0