atmx-cli 0.36.0 → 0.38.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.
|
@@ -28,8 +28,11 @@ function generateSdk(multiIr) {
|
|
|
28
28
|
return lines.join("\n");
|
|
29
29
|
}
|
|
30
30
|
function generateEndpointMethod(ep, ns, pascalNs) {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// ✨ FIX: Ensure params is always an Array regardless of the IR structure
|
|
32
|
+
const rawParams = ep.parameters || [];
|
|
33
|
+
const params = Array.isArray(rawParams)
|
|
34
|
+
? rawParams
|
|
35
|
+
: Object.values(rawParams);
|
|
33
36
|
if (params.length === 0) {
|
|
34
37
|
return `
|
|
35
38
|
/** RPC String Generator for <AxQuery> or <AxMutate> */
|
|
@@ -37,7 +40,6 @@ function generateEndpointMethod(ep, ns, pascalNs) {
|
|
|
37
40
|
return \`${ns}.${ep.name}()\`;
|
|
38
41
|
}\n`;
|
|
39
42
|
}
|
|
40
|
-
// ✨ FIX: For endpoints with parameters, safely type them as optional objects
|
|
41
43
|
const argType = `{ ${params
|
|
42
44
|
.map((p) => {
|
|
43
45
|
return `${(0, utils_1.camelCase)(p.name)}?: ${prefixModels((0, utils_1.mapTypeToTs)(p.typeRef, pascalNs))}`;
|
package/dist/generators/utils.js
CHANGED
|
@@ -18,14 +18,17 @@ function camelCase(str) {
|
|
|
18
18
|
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
19
19
|
}
|
|
20
20
|
function normalizeIr(obj) {
|
|
21
|
-
// ✨ FIX:
|
|
21
|
+
// ✨ FIX: Arrays in JavaScript are Objects! We must check Array.isArray FIRST.
|
|
22
|
+
if (Array.isArray(obj)) {
|
|
23
|
+
return obj.map(normalizeIr);
|
|
24
|
+
}
|
|
22
25
|
if (obj !== null && typeof obj === "object") {
|
|
23
26
|
const newObj = {};
|
|
24
27
|
for (const key of Object.keys(obj)) {
|
|
25
28
|
const camelKey = key.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
|
26
29
|
newObj[camelKey] = normalizeIr(obj[key]);
|
|
27
30
|
}
|
|
28
|
-
// Convert common Maps to Arrays if they exist
|
|
31
|
+
// Convert common Maps to Arrays if they exist and are not already arrays
|
|
29
32
|
if (newObj.endpoints &&
|
|
30
33
|
typeof newObj.endpoints === "object" &&
|
|
31
34
|
!Array.isArray(newObj.endpoints)) {
|
|
@@ -54,8 +57,6 @@ function normalizeIr(obj) {
|
|
|
54
57
|
}
|
|
55
58
|
return newObj;
|
|
56
59
|
}
|
|
57
|
-
if (Array.isArray(obj))
|
|
58
|
-
return obj.map(normalizeIr);
|
|
59
60
|
return obj;
|
|
60
61
|
}
|
|
61
62
|
/**
|
package/package.json
CHANGED
|
@@ -40,9 +40,12 @@ function generateEndpointMethod(
|
|
|
40
40
|
ns: string,
|
|
41
41
|
pascalNs: string,
|
|
42
42
|
): string {
|
|
43
|
-
|
|
43
|
+
// ✨ FIX: Ensure params is always an Array regardless of the IR structure
|
|
44
|
+
const rawParams = ep.parameters || [];
|
|
45
|
+
const params = Array.isArray(rawParams)
|
|
46
|
+
? rawParams
|
|
47
|
+
: Object.values(rawParams);
|
|
44
48
|
|
|
45
|
-
// ✨ FIX: If there are no parameters, don't even add the `args` variable!
|
|
46
49
|
if (params.length === 0) {
|
|
47
50
|
return `
|
|
48
51
|
/** RPC String Generator for <AxQuery> or <AxMutate> */
|
|
@@ -51,9 +54,8 @@ function generateEndpointMethod(
|
|
|
51
54
|
}\n`;
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
// ✨ FIX: For endpoints with parameters, safely type them as optional objects
|
|
55
57
|
const argType = `{ ${params
|
|
56
|
-
.map((p) => {
|
|
58
|
+
.map((p: any) => {
|
|
57
59
|
return `${camelCase(p.name)}?: ${prefixModels(mapTypeToTs(p.typeRef, pascalNs))}`;
|
|
58
60
|
})
|
|
59
61
|
.join(", ")} }`;
|
package/src/generators/utils.ts
CHANGED
|
@@ -14,7 +14,11 @@ export function camelCase(str: string): string {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function normalizeIr(obj: any): any {
|
|
17
|
-
// ✨ FIX:
|
|
17
|
+
// ✨ FIX: Arrays in JavaScript are Objects! We must check Array.isArray FIRST.
|
|
18
|
+
if (Array.isArray(obj)) {
|
|
19
|
+
return obj.map(normalizeIr);
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
if (obj !== null && typeof obj === "object") {
|
|
19
23
|
const newObj: any = {};
|
|
20
24
|
for (const key of Object.keys(obj)) {
|
|
@@ -22,7 +26,7 @@ export function normalizeIr(obj: any): any {
|
|
|
22
26
|
newObj[camelKey] = normalizeIr(obj[key]);
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
// Convert common Maps to Arrays if they exist
|
|
29
|
+
// Convert common Maps to Arrays if they exist and are not already arrays
|
|
26
30
|
if (
|
|
27
31
|
newObj.endpoints &&
|
|
28
32
|
typeof newObj.endpoints === "object" &&
|
|
@@ -62,7 +66,6 @@ export function normalizeIr(obj: any): any {
|
|
|
62
66
|
return newObj;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
if (Array.isArray(obj)) return obj.map(normalizeIr);
|
|
66
69
|
return obj;
|
|
67
70
|
}
|
|
68
71
|
|