config2ts 2.7.0 → 2.8.1
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/lib/config2ts.js +12 -1
- package/package.json +16 -4
package/lib/config2ts.js
CHANGED
|
@@ -235,6 +235,17 @@ function csv2ts(csvString, moduleName) {
|
|
|
235
235
|
template += ` };\n\n`;
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
+
// A single array literal holding more than ~1000 object literals makes tsc's
|
|
239
|
+
// subtype reduction (removeSubtypes) bail out with "ts(2590) Expression
|
|
240
|
+
// produces a union type that is too complex to represent". The only thing
|
|
241
|
+
// that makes every row a distinct object literal type is the EnumIndex
|
|
242
|
+
// (key) field, whose value is a unique literal per row. Falling that field
|
|
243
|
+
// back to string for large tables makes every row share one type, so the
|
|
244
|
+
// array literal union collapses instantly and the error disappears. The
|
|
245
|
+
// `key` union and `keyList` are still emitted (they do not trigger the
|
|
246
|
+
// limit), so cross-table RefEnum references keep working.
|
|
247
|
+
const maxRowsToKeepEnumKeyType = 1000;
|
|
248
|
+
const largeTable = result.length > maxRowsToKeepEnumKeyType;
|
|
238
249
|
template += " export interface Record {\n";
|
|
239
250
|
let indexField = null;
|
|
240
251
|
for (const field in convert) {
|
|
@@ -244,7 +255,7 @@ function csv2ts(csvString, moduleName) {
|
|
|
244
255
|
fieldType = field;
|
|
245
256
|
}
|
|
246
257
|
else if (convert[field] == EnumIndexStr) {
|
|
247
|
-
fieldType = field;
|
|
258
|
+
fieldType = largeTable ? "string" : field;
|
|
248
259
|
indexField = field;
|
|
249
260
|
}
|
|
250
261
|
else if (convert[field] == IndexStr) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "config2ts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "Generate type-safe TypeScript from CSV/INI/TOML config tables — inferred types, enums, cross-table references, and a typed asset index, all from one CLI command.",
|
|
5
5
|
"main": "lib/config2ts.js",
|
|
6
6
|
"types": "lib/config2ts.d.ts",
|
|
@@ -27,19 +27,31 @@
|
|
|
27
27
|
"url": "https://github.com/livingyang/config2ts/issues"
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/livingyang/config2ts#readme",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
},
|
|
30
33
|
"dependencies": {
|
|
31
34
|
"change-case": "^4.1.2",
|
|
32
35
|
"commander": "^9.5.0",
|
|
33
36
|
"d3-dsv": "^3.0.1",
|
|
34
37
|
"ini": "^3.0.1",
|
|
35
38
|
"json5": "^2.2.3",
|
|
36
|
-
"toml": "^
|
|
39
|
+
"toml": "^4.1.2"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@types/jest": "^30.0.0",
|
|
40
43
|
"@types/node": "^24.5.2",
|
|
41
|
-
"jest": "^
|
|
42
|
-
"ts-jest": "^29.4.
|
|
44
|
+
"jest": "^30.5.1",
|
|
45
|
+
"ts-jest": "^29.4.12",
|
|
43
46
|
"typescript": "^5.9.2"
|
|
47
|
+
},
|
|
48
|
+
"overrides": {
|
|
49
|
+
"@babel/core": "^7.29.6",
|
|
50
|
+
"browserslist": "^4.28.7",
|
|
51
|
+
"handlebars": "^4.7.9",
|
|
52
|
+
"js-yaml": "^3.14.2",
|
|
53
|
+
"minimatch@^3.0.0": "^3.1.3",
|
|
54
|
+
"picomatch@^2.0.0": "^2.3.2",
|
|
55
|
+
"brace-expansion@^1.0.0": "^1.1.16"
|
|
44
56
|
}
|
|
45
57
|
}
|