@shepherdjerred/helm-types 0.0.0-dev.706

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,209 @@
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 {
82
+ fetchHelmChart,
83
+ convertToTypeScriptInterface,
84
+ generateTypeScriptCode,
85
+ } from "@shepherdjerred/helm-types";
86
+
87
+ // 1. Define your chart
88
+ const chart = {
89
+ name: "argo-cd",
90
+ chartName: "argo-cd",
91
+ repoUrl: "https://argoproj.github.io/argo-helm",
92
+ version: "8.3.1",
93
+ };
94
+
95
+ // 2. Fetch and generate types
96
+ const { values, schema, yamlComments } = await fetchHelmChart(chart);
97
+ const tsInterface = convertToTypeScriptInterface(
98
+ values,
99
+ "ArgocdHelmValues",
100
+ schema,
101
+ yamlComments,
102
+ );
103
+ const code = generateTypeScriptCode(tsInterface, chart.name);
104
+
105
+ // 3. Write output
106
+ await fs.writeFile("argo-cd.types.ts", code);
107
+ ```
108
+
109
+ ## Generated Output
110
+
111
+ ### Values Interface
112
+
113
+ ```typescript
114
+ export type ArgocdHelmValues = {
115
+ /**
116
+ * Number of replicas
117
+ * @default 1
118
+ */
119
+ replicaCount?: number;
120
+
121
+ image?: ArgocdHelmValuesImage;
122
+ service?: ArgocdHelmValuesService;
123
+ };
124
+ ```
125
+
126
+ ### Nested Types
127
+
128
+ ```typescript
129
+ export type ArgocdHelmValuesImage = {
130
+ repository?: string;
131
+ tag?: string;
132
+ pullPolicy?: "Always" | "IfNotPresent" | "Never";
133
+ };
134
+ ```
135
+
136
+ ### Parameters Type (Flattened)
137
+
138
+ A flattened type using dot notation for Helm's `--set` parameter syntax:
139
+
140
+ ```typescript
141
+ export type ArgocdHelmParameters = {
142
+ replicaCount?: string;
143
+ "image.repository"?: string;
144
+ "image.tag"?: string;
145
+ "service.type"?: string;
146
+ };
147
+ ```
148
+
149
+ ## Type Inference
150
+
151
+ The library intelligently infers types from values:
152
+
153
+ | Value | Inferred Type |
154
+ | ------------------- | ---------------- |
155
+ | `true`, `false` | `boolean` |
156
+ | `"true"`, `"false"` | `boolean` |
157
+ | `123`, `3.14` | `number` |
158
+ | `"123"` | `number` |
159
+ | `"hello"` | `string` |
160
+ | `[]` | `unknown[]` |
161
+ | `[1, 2]` | `number[]` |
162
+ | `{}` | nested interface |
163
+
164
+ JSON schema takes precedence when available.
165
+
166
+ ## API Reference
167
+
168
+ ### `fetchHelmChart(chart: ChartInfo)`
169
+
170
+ Fetches a Helm chart and extracts configuration.
171
+
172
+ ```typescript
173
+ type ChartInfo = {
174
+ name: string; // Unique identifier
175
+ chartName: string; // Chart name in repo
176
+ repoUrl: string; // Helm repository URL
177
+ version: string; // Chart version
178
+ };
179
+
180
+ // Returns
181
+ {
182
+ values: Record<string, unknown>;
183
+ schema: JSONSchemaProperty | null;
184
+ yamlComments: Map<string, string>;
185
+ }
186
+ ```
187
+
188
+ ### `convertToTypeScriptInterface(values, name, schema?, comments?, prefix?)`
189
+
190
+ Converts Helm values to TypeScript interface definition.
191
+
192
+ - `values` - Chart values object
193
+ - `name` - Interface name
194
+ - `schema?` - Optional JSON schema for type hints
195
+ - `comments?` - Optional YAML comments for JSDoc
196
+ - `prefix?` - Optional key prefix for nested types
197
+
198
+ ### `generateTypeScriptCode(interface, chartName)`
199
+
200
+ Generates TypeScript code from interface definition. Returns a string containing the main values
201
+ interface, nested type definitions, and flattened parameters type.
202
+
203
+ ### `parseYAMLComments(yamlContent)`
204
+
205
+ Extracts YAML comments and associates them with keys.
206
+
207
+ ## License
208
+
209
+ GPL-3.0