@shepherdjerred/helm-types 1.1.0 → 1.2.0-dev.893
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 +11 -2
- package/dist/cli.js +4570 -3203
- package/dist/index.js +8 -20585
- package/package.json +5 -1
- package/src/chart-fetcher.ts +37 -16
- package/src/chart-info-parser.ts +54 -34
- package/src/cli.ts +76 -58
- package/src/code-generator.ts +57 -22
- package/src/comment-parser.ts +79 -55
- package/src/config.ts +12 -5
- package/src/helm-types.ts +16 -46
- package/src/index.ts +14 -1
- package/src/interface-generator.ts +58 -23
- package/src/schemas.ts +3 -1
- package/src/type-converter-helpers.ts +180 -0
- package/src/type-converter.ts +273 -300
- package/src/type-inference.ts +302 -194
- package/src/utils.ts +2 -2
- package/src/yaml-comment-filters.ts +103 -0
- package/src/yaml-comment-regex-parser.ts +150 -0
- package/src/yaml-comments.ts +216 -508
- package/src/yaml-preprocess.ts +235 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
JSONSchemaProperty,
|
|
3
|
+
TypeScriptInterface,
|
|
4
|
+
TypeProperty,
|
|
5
|
+
} from "./types.ts";
|
|
6
|
+
import {
|
|
7
|
+
StringSchema,
|
|
8
|
+
ActualNumberSchema,
|
|
9
|
+
ActualBooleanSchema,
|
|
10
|
+
StringBooleanSchema,
|
|
11
|
+
} from "./schemas.ts";
|
|
12
|
+
|
|
13
|
+
export type PropertyConversionContext = {
|
|
14
|
+
value: unknown;
|
|
15
|
+
nestedTypeName: string;
|
|
16
|
+
schema?: JSONSchemaProperty;
|
|
17
|
+
propertyName?: string;
|
|
18
|
+
yamlComment?: string;
|
|
19
|
+
yamlComments?: Map<string, string>;
|
|
20
|
+
fullKey?: string;
|
|
21
|
+
chartName?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Merge description from schema and YAML comments
|
|
26
|
+
*/
|
|
27
|
+
export function mergeDescriptions(
|
|
28
|
+
schemaDescription: string | undefined,
|
|
29
|
+
yamlComment: string | undefined,
|
|
30
|
+
): string | undefined {
|
|
31
|
+
if (yamlComment == null || yamlComment === "") {
|
|
32
|
+
return schemaDescription;
|
|
33
|
+
}
|
|
34
|
+
return schemaDescription != null && schemaDescription !== ""
|
|
35
|
+
? `${yamlComment}\n\n${schemaDescription}`
|
|
36
|
+
: yamlComment;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Infer a primitive TypeProperty from a runtime value (no schema)
|
|
41
|
+
*/
|
|
42
|
+
export function inferPrimitiveType(
|
|
43
|
+
value: unknown,
|
|
44
|
+
yamlComment?: string,
|
|
45
|
+
): TypeProperty {
|
|
46
|
+
if (ActualBooleanSchema.safeParse(value).success) {
|
|
47
|
+
return {
|
|
48
|
+
type: "boolean",
|
|
49
|
+
optional: true,
|
|
50
|
+
description: yamlComment,
|
|
51
|
+
default: value,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (ActualNumberSchema.safeParse(value).success) {
|
|
56
|
+
return {
|
|
57
|
+
type: "number",
|
|
58
|
+
optional: true,
|
|
59
|
+
description: yamlComment,
|
|
60
|
+
default: value,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (StringBooleanSchema.safeParse(value).success) {
|
|
65
|
+
return {
|
|
66
|
+
type: "boolean",
|
|
67
|
+
optional: true,
|
|
68
|
+
description: yamlComment,
|
|
69
|
+
default: value,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const stringCheckForNumber = StringSchema.safeParse(value);
|
|
74
|
+
if (stringCheckForNumber.success) {
|
|
75
|
+
const trimmed = stringCheckForNumber.data.trim();
|
|
76
|
+
if (
|
|
77
|
+
trimmed !== "" &&
|
|
78
|
+
!Number.isNaN(Number(trimmed)) &&
|
|
79
|
+
Number.isFinite(Number(trimmed))
|
|
80
|
+
) {
|
|
81
|
+
return {
|
|
82
|
+
type: "number",
|
|
83
|
+
optional: true,
|
|
84
|
+
description: yamlComment,
|
|
85
|
+
default: value,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const stringCheckForPlain = StringSchema.safeParse(value);
|
|
91
|
+
if (stringCheckForPlain.success) {
|
|
92
|
+
if (stringCheckForPlain.data === "default") {
|
|
93
|
+
return {
|
|
94
|
+
type: "string | number | boolean",
|
|
95
|
+
optional: true,
|
|
96
|
+
description: yamlComment,
|
|
97
|
+
default: value,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
type: "string",
|
|
102
|
+
optional: true,
|
|
103
|
+
description: yamlComment,
|
|
104
|
+
default: value,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.warn(
|
|
109
|
+
`Unrecognized value type for: ${String(value)}, using 'unknown'`,
|
|
110
|
+
);
|
|
111
|
+
return { type: "unknown", optional: true, description: yamlComment };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Augment a Kubernetes resource spec interface with both requests and limits.
|
|
116
|
+
* If only one is present, copy its type structure to the other.
|
|
117
|
+
*/
|
|
118
|
+
export function augmentK8sResourceSpec(iface: TypeScriptInterface): void {
|
|
119
|
+
const hasRequests = "requests" in iface.properties;
|
|
120
|
+
const hasLimits = "limits" in iface.properties;
|
|
121
|
+
|
|
122
|
+
// If we have requests but not limits, add limits with the same structure
|
|
123
|
+
if (hasRequests && !hasLimits) {
|
|
124
|
+
const requestsProp = iface.properties["requests"];
|
|
125
|
+
if (requestsProp) {
|
|
126
|
+
// Create limits property with the same type but different name for the nested interface
|
|
127
|
+
const limitsTypeName = requestsProp.type.replace("Requests", "Limits");
|
|
128
|
+
|
|
129
|
+
// If there's a nested interface, create a copy for limits
|
|
130
|
+
if (requestsProp.nested) {
|
|
131
|
+
const limitsNested: TypeScriptInterface = {
|
|
132
|
+
name: limitsTypeName,
|
|
133
|
+
properties: { ...requestsProp.nested.properties },
|
|
134
|
+
allowArbitraryProps: requestsProp.nested.allowArbitraryProps,
|
|
135
|
+
};
|
|
136
|
+
iface.properties["limits"] = {
|
|
137
|
+
type: limitsTypeName,
|
|
138
|
+
optional: true,
|
|
139
|
+
nested: limitsNested,
|
|
140
|
+
description: "Kubernetes resource limits (memory, cpu, etc.)",
|
|
141
|
+
};
|
|
142
|
+
} else {
|
|
143
|
+
// No nested interface, just copy the type
|
|
144
|
+
iface.properties["limits"] = {
|
|
145
|
+
type: requestsProp.type,
|
|
146
|
+
optional: true,
|
|
147
|
+
description: "Kubernetes resource limits (memory, cpu, etc.)",
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// If we have limits but not requests, add requests with the same structure
|
|
154
|
+
if (hasLimits && !hasRequests) {
|
|
155
|
+
const limitsProp = iface.properties["limits"];
|
|
156
|
+
if (limitsProp) {
|
|
157
|
+
const requestsTypeName = limitsProp.type.replace("Limits", "Requests");
|
|
158
|
+
|
|
159
|
+
if (limitsProp.nested) {
|
|
160
|
+
const requestsNested: TypeScriptInterface = {
|
|
161
|
+
name: requestsTypeName,
|
|
162
|
+
properties: { ...limitsProp.nested.properties },
|
|
163
|
+
allowArbitraryProps: limitsProp.nested.allowArbitraryProps,
|
|
164
|
+
};
|
|
165
|
+
iface.properties["requests"] = {
|
|
166
|
+
type: requestsTypeName,
|
|
167
|
+
optional: true,
|
|
168
|
+
nested: requestsNested,
|
|
169
|
+
description: "Kubernetes resource requests (memory, cpu, etc.)",
|
|
170
|
+
};
|
|
171
|
+
} else {
|
|
172
|
+
iface.properties["requests"] = {
|
|
173
|
+
type: limitsProp.type,
|
|
174
|
+
optional: true,
|
|
175
|
+
description: "Kubernetes resource requests (memory, cpu, etc.)",
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|