atmx-cli 0.33.0 → 0.34.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/dist/generators/utils.js +54 -20
- package/package.json +1 -1
- package/src/generators/utils.ts +83 -37
package/dist/generators/utils.js
CHANGED
|
@@ -7,27 +7,55 @@ exports.normalizeIr = normalizeIr;
|
|
|
7
7
|
exports.mapTypeToTs = mapTypeToTs;
|
|
8
8
|
function pascalCase(str) {
|
|
9
9
|
if (!str)
|
|
10
|
-
return
|
|
10
|
+
return "";
|
|
11
11
|
return str
|
|
12
12
|
.split(/[_\-\s]+/)
|
|
13
|
-
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
|
14
|
-
.join(
|
|
13
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
14
|
+
.join("");
|
|
15
15
|
}
|
|
16
16
|
function camelCase(str) {
|
|
17
17
|
const pascal = pascalCase(str);
|
|
18
18
|
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
19
19
|
}
|
|
20
20
|
function normalizeIr(obj) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (obj !== null && typeof obj === 'object') {
|
|
21
|
+
// ✨ FIX: Recursively convert Axiom Core HashMaps back into Arrays for the generator
|
|
22
|
+
if (obj !== null && typeof obj === "object") {
|
|
24
23
|
const newObj = {};
|
|
25
24
|
for (const key of Object.keys(obj)) {
|
|
26
25
|
const camelKey = key.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
|
27
26
|
newObj[camelKey] = normalizeIr(obj[key]);
|
|
28
27
|
}
|
|
28
|
+
// Convert common Maps to Arrays if they exist
|
|
29
|
+
if (newObj.endpoints &&
|
|
30
|
+
typeof newObj.endpoints === "object" &&
|
|
31
|
+
!Array.isArray(newObj.endpoints)) {
|
|
32
|
+
newObj.endpoints = Object.values(newObj.endpoints);
|
|
33
|
+
}
|
|
34
|
+
if (newObj.models &&
|
|
35
|
+
typeof newObj.models === "object" &&
|
|
36
|
+
!Array.isArray(newObj.models)) {
|
|
37
|
+
newObj.models = Object.values(newObj.models);
|
|
38
|
+
}
|
|
39
|
+
if (newObj.enums &&
|
|
40
|
+
typeof newObj.enums === "object" &&
|
|
41
|
+
!Array.isArray(newObj.enums)) {
|
|
42
|
+
newObj.enums = Object.values(newObj.enums);
|
|
43
|
+
}
|
|
44
|
+
// Traverse down into models to normalize fields
|
|
45
|
+
if (Array.isArray(newObj.models)) {
|
|
46
|
+
newObj.models = newObj.models.map((model) => {
|
|
47
|
+
if (model.fields &&
|
|
48
|
+
typeof model.fields === "object" &&
|
|
49
|
+
!Array.isArray(model.fields)) {
|
|
50
|
+
model.fields = Object.values(model.fields);
|
|
51
|
+
}
|
|
52
|
+
return model;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
29
55
|
return newObj;
|
|
30
56
|
}
|
|
57
|
+
if (Array.isArray(obj))
|
|
58
|
+
return obj.map(normalizeIr);
|
|
31
59
|
return obj;
|
|
32
60
|
}
|
|
33
61
|
/**
|
|
@@ -35,25 +63,31 @@ function normalizeIr(obj) {
|
|
|
35
63
|
*/
|
|
36
64
|
function mapTypeToTs(typeRef, ns) {
|
|
37
65
|
if (!typeRef)
|
|
38
|
-
return
|
|
39
|
-
if (typeRef.kind ===
|
|
66
|
+
return "any";
|
|
67
|
+
if (typeRef.kind === "primitive") {
|
|
40
68
|
switch (typeRef.value) {
|
|
41
|
-
case
|
|
42
|
-
|
|
43
|
-
case
|
|
44
|
-
case
|
|
45
|
-
case
|
|
46
|
-
|
|
47
|
-
case
|
|
48
|
-
|
|
69
|
+
case "string":
|
|
70
|
+
return "string";
|
|
71
|
+
case "int":
|
|
72
|
+
case "float":
|
|
73
|
+
case "double":
|
|
74
|
+
return "number";
|
|
75
|
+
case "boolean":
|
|
76
|
+
return "boolean";
|
|
77
|
+
case "dateTime":
|
|
78
|
+
return "Date";
|
|
79
|
+
case "bytes":
|
|
80
|
+
return "Uint8Array";
|
|
81
|
+
default:
|
|
82
|
+
return "any";
|
|
49
83
|
}
|
|
50
84
|
}
|
|
51
|
-
if (typeRef.kind ===
|
|
85
|
+
if (typeRef.kind === "named") {
|
|
52
86
|
const name = pascalCase(typeRef.value);
|
|
53
|
-
return ns ? `${ns}${name}` : name;
|
|
87
|
+
return ns ? `${ns}${name}` : name;
|
|
54
88
|
}
|
|
55
|
-
if (typeRef.kind ===
|
|
89
|
+
if (typeRef.kind === "list") {
|
|
56
90
|
return `${mapTypeToTs(typeRef.value, ns)}[]`;
|
|
57
91
|
}
|
|
58
|
-
return
|
|
92
|
+
return "any";
|
|
59
93
|
}
|
package/package.json
CHANGED
package/src/generators/utils.ts
CHANGED
|
@@ -1,58 +1,104 @@
|
|
|
1
1
|
// atmx-cli/src/generators/utils.ts
|
|
2
2
|
|
|
3
3
|
export function pascalCase(str: string): string {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
if (!str) return "";
|
|
5
|
+
return str
|
|
6
|
+
.split(/[_\-\s]+/)
|
|
7
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
8
|
+
.join("");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function camelCase(str: string): string {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const pascal = pascalCase(str);
|
|
13
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function normalizeIr(obj: any): any {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
// ✨ FIX: Recursively convert Axiom Core HashMaps back into Arrays for the generator
|
|
18
|
+
if (obj !== null && typeof obj === "object") {
|
|
19
|
+
const newObj: any = {};
|
|
20
|
+
for (const key of Object.keys(obj)) {
|
|
21
|
+
const camelKey = key.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
|
22
|
+
newObj[camelKey] = normalizeIr(obj[key]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Convert common Maps to Arrays if they exist
|
|
26
|
+
if (
|
|
27
|
+
newObj.endpoints &&
|
|
28
|
+
typeof newObj.endpoints === "object" &&
|
|
29
|
+
!Array.isArray(newObj.endpoints)
|
|
30
|
+
) {
|
|
31
|
+
newObj.endpoints = Object.values(newObj.endpoints);
|
|
32
|
+
}
|
|
33
|
+
if (
|
|
34
|
+
newObj.models &&
|
|
35
|
+
typeof newObj.models === "object" &&
|
|
36
|
+
!Array.isArray(newObj.models)
|
|
37
|
+
) {
|
|
38
|
+
newObj.models = Object.values(newObj.models);
|
|
39
|
+
}
|
|
40
|
+
if (
|
|
41
|
+
newObj.enums &&
|
|
42
|
+
typeof newObj.enums === "object" &&
|
|
43
|
+
!Array.isArray(newObj.enums)
|
|
44
|
+
) {
|
|
45
|
+
newObj.enums = Object.values(newObj.enums);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Traverse down into models to normalize fields
|
|
49
|
+
if (Array.isArray(newObj.models)) {
|
|
50
|
+
newObj.models = newObj.models.map((model: any) => {
|
|
51
|
+
if (
|
|
52
|
+
model.fields &&
|
|
53
|
+
typeof model.fields === "object" &&
|
|
54
|
+
!Array.isArray(model.fields)
|
|
55
|
+
) {
|
|
56
|
+
model.fields = Object.values(model.fields);
|
|
23
57
|
}
|
|
24
|
-
return
|
|
58
|
+
return model;
|
|
59
|
+
});
|
|
25
60
|
}
|
|
26
|
-
|
|
61
|
+
|
|
62
|
+
return newObj;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (Array.isArray(obj)) return obj.map(normalizeIr);
|
|
66
|
+
return obj;
|
|
27
67
|
}
|
|
28
68
|
|
|
29
69
|
/**
|
|
30
70
|
* @param scopedNamespace If provided (e.g. 'Auth'), prefixes named types with 'models.Auth.'
|
|
31
71
|
*/
|
|
32
72
|
export function mapTypeToTs(typeRef: any, ns?: string): string {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (typeRef.kind === 'primitive') {
|
|
36
|
-
switch (typeRef.value) {
|
|
37
|
-
case 'string': return 'string';
|
|
38
|
-
case 'int':
|
|
39
|
-
case 'float':
|
|
40
|
-
case 'double': return 'number';
|
|
41
|
-
case 'boolean': return 'boolean';
|
|
42
|
-
case 'dateTime': return 'Date';
|
|
43
|
-
case 'bytes': return 'Uint8Array';
|
|
44
|
-
default: return 'any';
|
|
45
|
-
}
|
|
46
|
-
}
|
|
73
|
+
if (!typeRef) return "any";
|
|
47
74
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
if (typeRef.kind === "primitive") {
|
|
76
|
+
switch (typeRef.value) {
|
|
77
|
+
case "string":
|
|
78
|
+
return "string";
|
|
79
|
+
case "int":
|
|
80
|
+
case "float":
|
|
81
|
+
case "double":
|
|
82
|
+
return "number";
|
|
83
|
+
case "boolean":
|
|
84
|
+
return "boolean";
|
|
85
|
+
case "dateTime":
|
|
86
|
+
return "Date";
|
|
87
|
+
case "bytes":
|
|
88
|
+
return "Uint8Array";
|
|
89
|
+
default:
|
|
90
|
+
return "any";
|
|
51
91
|
}
|
|
92
|
+
}
|
|
52
93
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
94
|
+
if (typeRef.kind === "named") {
|
|
95
|
+
const name = pascalCase(typeRef.value);
|
|
96
|
+
return ns ? `${ns}${name}` : name;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (typeRef.kind === "list") {
|
|
100
|
+
return `${mapTypeToTs(typeRef.value, ns)}[]`;
|
|
101
|
+
}
|
|
56
102
|
|
|
57
|
-
|
|
58
|
-
}
|
|
103
|
+
return "any";
|
|
104
|
+
}
|