atmx-cli 0.55.0 → 0.57.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.
|
@@ -59,44 +59,45 @@ function generateSdk(multiIr, isReact = false) {
|
|
|
59
59
|
lines.push(`};\n`);
|
|
60
60
|
return lines.join("\n");
|
|
61
61
|
}
|
|
62
|
+
// FILE: atmx-cli/src/generators/sdk-generator.ts (Partial replacement)
|
|
62
63
|
function generateEndpointMethod(ep, ns, camelNs, isReact) {
|
|
63
64
|
const rawParams = ep.parameters || [];
|
|
64
65
|
const params = Array.isArray(rawParams)
|
|
65
66
|
? rawParams
|
|
66
67
|
: Object.values(rawParams);
|
|
68
|
+
const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
|
|
69
|
+
const rawReturnType = (0, utils_1.mapTypeToTs)(ep.returnType, camelNs);
|
|
70
|
+
const returnType = rawReturnType === "void" || rawReturnType === "any"
|
|
71
|
+
? rawReturnType
|
|
72
|
+
: prefixModels(rawReturnType);
|
|
73
|
+
// Map camelCase TS args back to original IR snake_case names!
|
|
74
|
+
const argsMapping = params
|
|
75
|
+
.map((p) => `if (args && '${(0, utils_1.camelCase)(p.name)}' in args) { mappedArgs["${p.name}"] = (args as any)["${(0, utils_1.camelCase)(p.name)}"]; delete mappedArgs["${(0, utils_1.camelCase)(p.name)}"]; }`)
|
|
76
|
+
.join("\n ");
|
|
67
77
|
if (params.length === 0) {
|
|
68
78
|
if (isReact) {
|
|
69
|
-
const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
|
|
70
|
-
const rawReturnType = (0, utils_1.mapTypeToTs)(ep.returnType, camelNs);
|
|
71
|
-
const returnType = rawReturnType === "void" || rawReturnType === "any"
|
|
72
|
-
? rawReturnType
|
|
73
|
-
: prefixModels(rawReturnType);
|
|
74
79
|
const decLogic = generateLambda(ep.returnType, "fromJson", camelNs);
|
|
75
80
|
return `
|
|
76
|
-
get${(0, utils_1.pascalCase)(ep.name)}Def(): AxiomQueryDef<${returnType}> {
|
|
81
|
+
get${(0, utils_1.pascalCase)(ep.name)}Def(args?: Record<string, any>): AxiomQueryDef<${returnType}> {
|
|
77
82
|
return {
|
|
78
83
|
namespace: "${ns}", name: "${ep.name}", endpointId: ${ep.id},
|
|
79
84
|
method: "${ep.method ? ep.method.toUpperCase() : "GET"}", path: "${ep.path}",
|
|
80
|
-
args: {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
|
|
85
|
+
args: args || {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
|
|
81
86
|
};
|
|
82
87
|
},
|
|
83
88
|
use${(0, utils_1.pascalCase)(ep.name)}${!isQuery ? "Mutation" : ""}(options?: { enabled?: boolean }) {
|
|
84
|
-
${isQuery ? `return useAxiomQuery<${returnType}>(this.get${(0, utils_1.pascalCase)(ep.name)}Def(), options);` : `return useAxiomMutation<${returnType}, void | Record<string,any>>(() => this.get${(0, utils_1.pascalCase)(ep.name)}Def());`}
|
|
89
|
+
${isQuery ? `return useAxiomQuery<${returnType}>(this.get${(0, utils_1.pascalCase)(ep.name)}Def(), options);` : `return useAxiomMutation<${returnType}, void | Record<string,any>>((a) => this.get${(0, utils_1.pascalCase)(ep.name)}Def(a));`}
|
|
85
90
|
},`;
|
|
86
91
|
}
|
|
87
92
|
else {
|
|
88
93
|
return `
|
|
89
|
-
${(0, utils_1.camelCase)(ep.name)}(): string {
|
|
90
|
-
|
|
94
|
+
${(0, utils_1.camelCase)(ep.name)}(args?: Record<string, any>): string {
|
|
95
|
+
const argsStr = args && Object.keys(args).length > 0 ? JSON.stringify(args) : '';
|
|
96
|
+
return \`${ns}.${ep.name}(\${argsStr})\`;
|
|
91
97
|
},`;
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
|
-
const argType = `{ ${params.map((p) => `${(0, utils_1.camelCase)(p.name)}
|
|
95
|
-
const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
|
|
96
|
-
const rawReturnType = (0, utils_1.mapTypeToTs)(ep.returnType, camelNs);
|
|
97
|
-
const returnType = rawReturnType === "void" || rawReturnType === "any"
|
|
98
|
-
? rawReturnType
|
|
99
|
-
: prefixModels(rawReturnType);
|
|
100
|
+
const argType = `{ ${params.map((p) => `${(0, utils_1.camelCase)(p.name)}${p.isOptional ? "?" : ""}: ${prefixModels((0, utils_1.mapTypeToTs)(p.typeRef, camelNs))}`).join(", ")} }`;
|
|
100
101
|
if (isReact) {
|
|
101
102
|
const bodyParam = params.find((p) => p.source === "body");
|
|
102
103
|
const payloadLogic = bodyParam
|
|
@@ -109,10 +110,13 @@ function generateEndpointMethod(ep, ns, camelNs, isReact) {
|
|
|
109
110
|
return `
|
|
110
111
|
get${(0, utils_1.pascalCase)(ep.name)}Def(args?: ${argType}): AxiomQueryDef<${returnType}> {
|
|
111
112
|
${payloadLogic}
|
|
113
|
+
const mappedArgs: any = { ...(args || {}) };
|
|
114
|
+
${argsMapping}
|
|
115
|
+
|
|
112
116
|
return {
|
|
113
117
|
namespace: "${ns}", name: "${ep.name}", endpointId: ${ep.id},
|
|
114
118
|
method: "${ep.method ? ep.method.toUpperCase() : "GET"}", path: "${ep.path}",
|
|
115
|
-
payload: payload, args:
|
|
119
|
+
payload: payload, args: mappedArgs, decoder: ${decLogic}, serializer: ${serLogic}, isStream: ${ep.isStream === true}
|
|
116
120
|
};
|
|
117
121
|
},
|
|
118
122
|
use${(0, utils_1.pascalCase)(ep.name)}${!isQuery ? "Mutation" : ""}(args?: ${argType}, options?: { enabled?: boolean }) {
|
|
@@ -122,7 +126,9 @@ function generateEndpointMethod(ep, ns, camelNs, isReact) {
|
|
|
122
126
|
else {
|
|
123
127
|
return `
|
|
124
128
|
${(0, utils_1.camelCase)(ep.name)}(args?: ${argType}): string {
|
|
125
|
-
const
|
|
129
|
+
const mappedArgs: any = { ...(args || {}) };
|
|
130
|
+
${argsMapping}
|
|
131
|
+
const argsStr = Object.keys(mappedArgs).length > 0 ? JSON.stringify(mappedArgs) : '';
|
|
126
132
|
return \`${ns}.${ep.name}(\${argsStr})\`;
|
|
127
133
|
},`;
|
|
128
134
|
}
|
package/package.json
CHANGED
|
@@ -76,6 +76,8 @@ export function generateSdk(
|
|
|
76
76
|
return lines.join("\n");
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// FILE: atmx-cli/src/generators/sdk-generator.ts (Partial replacement)
|
|
80
|
+
|
|
79
81
|
function generateEndpointMethod(
|
|
80
82
|
ep: AxiomEndpoint,
|
|
81
83
|
ns: string,
|
|
@@ -87,41 +89,45 @@ function generateEndpointMethod(
|
|
|
87
89
|
? rawParams
|
|
88
90
|
: Object.values(rawParams);
|
|
89
91
|
|
|
92
|
+
const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
|
|
93
|
+
const rawReturnType = mapTypeToTs(ep.returnType, camelNs);
|
|
94
|
+
const returnType =
|
|
95
|
+
rawReturnType === "void" || rawReturnType === "any"
|
|
96
|
+
? rawReturnType
|
|
97
|
+
: prefixModels(rawReturnType);
|
|
98
|
+
|
|
99
|
+
// Map camelCase TS args back to original IR snake_case names!
|
|
100
|
+
const argsMapping = params
|
|
101
|
+
.map(
|
|
102
|
+
(p: any) =>
|
|
103
|
+
`if (args && '${camelCase(p.name)}' in args) { mappedArgs["${p.name}"] = (args as any)["${camelCase(p.name)}"]; delete mappedArgs["${camelCase(p.name)}"]; }`,
|
|
104
|
+
)
|
|
105
|
+
.join("\n ");
|
|
106
|
+
|
|
90
107
|
if (params.length === 0) {
|
|
91
108
|
if (isReact) {
|
|
92
|
-
const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
|
|
93
|
-
const rawReturnType = mapTypeToTs(ep.returnType, camelNs);
|
|
94
|
-
const returnType =
|
|
95
|
-
rawReturnType === "void" || rawReturnType === "any"
|
|
96
|
-
? rawReturnType
|
|
97
|
-
: prefixModels(rawReturnType);
|
|
98
109
|
const decLogic = generateLambda(ep.returnType, "fromJson", camelNs);
|
|
99
110
|
return `
|
|
100
|
-
get${pascalCase(ep.name)}Def(): AxiomQueryDef<${returnType}> {
|
|
111
|
+
get${pascalCase(ep.name)}Def(args?: Record<string, any>): AxiomQueryDef<${returnType}> {
|
|
101
112
|
return {
|
|
102
113
|
namespace: "${ns}", name: "${ep.name}", endpointId: ${ep.id},
|
|
103
114
|
method: "${ep.method ? ep.method.toUpperCase() : "GET"}", path: "${ep.path}",
|
|
104
|
-
args: {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
|
|
115
|
+
args: args || {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
|
|
105
116
|
};
|
|
106
117
|
},
|
|
107
118
|
use${pascalCase(ep.name)}${!isQuery ? "Mutation" : ""}(options?: { enabled?: boolean }) {
|
|
108
|
-
${isQuery ? `return useAxiomQuery<${returnType}>(this.get${pascalCase(ep.name)}Def(), options);` : `return useAxiomMutation<${returnType}, void | Record<string,any>>(() => this.get${pascalCase(ep.name)}Def());`}
|
|
119
|
+
${isQuery ? `return useAxiomQuery<${returnType}>(this.get${pascalCase(ep.name)}Def(), options);` : `return useAxiomMutation<${returnType}, void | Record<string,any>>((a) => this.get${pascalCase(ep.name)}Def(a));`}
|
|
109
120
|
},`;
|
|
110
121
|
} else {
|
|
111
122
|
return `
|
|
112
|
-
${camelCase(ep.name)}(): string {
|
|
113
|
-
|
|
123
|
+
${camelCase(ep.name)}(args?: Record<string, any>): string {
|
|
124
|
+
const argsStr = args && Object.keys(args).length > 0 ? JSON.stringify(args) : '';
|
|
125
|
+
return \`${ns}.${ep.name}(\${argsStr})\`;
|
|
114
126
|
},`;
|
|
115
127
|
}
|
|
116
128
|
}
|
|
117
129
|
|
|
118
|
-
const argType = `{ ${params.map((p: any) => `${camelCase(p.name)}
|
|
119
|
-
const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
|
|
120
|
-
const rawReturnType = mapTypeToTs(ep.returnType, camelNs);
|
|
121
|
-
const returnType =
|
|
122
|
-
rawReturnType === "void" || rawReturnType === "any"
|
|
123
|
-
? rawReturnType
|
|
124
|
-
: prefixModels(rawReturnType);
|
|
130
|
+
const argType = `{ ${params.map((p: any) => `${camelCase(p.name)}${p.isOptional ? "?" : ""}: ${prefixModels(mapTypeToTs(p.typeRef, camelNs))}`).join(", ")} }`;
|
|
125
131
|
|
|
126
132
|
if (isReact) {
|
|
127
133
|
const bodyParam = params.find(
|
|
@@ -138,10 +144,13 @@ function generateEndpointMethod(
|
|
|
138
144
|
return `
|
|
139
145
|
get${pascalCase(ep.name)}Def(args?: ${argType}): AxiomQueryDef<${returnType}> {
|
|
140
146
|
${payloadLogic}
|
|
147
|
+
const mappedArgs: any = { ...(args || {}) };
|
|
148
|
+
${argsMapping}
|
|
149
|
+
|
|
141
150
|
return {
|
|
142
151
|
namespace: "${ns}", name: "${ep.name}", endpointId: ${ep.id},
|
|
143
152
|
method: "${ep.method ? ep.method.toUpperCase() : "GET"}", path: "${ep.path}",
|
|
144
|
-
payload: payload, args:
|
|
153
|
+
payload: payload, args: mappedArgs, decoder: ${decLogic}, serializer: ${serLogic}, isStream: ${ep.isStream === true}
|
|
145
154
|
};
|
|
146
155
|
},
|
|
147
156
|
use${pascalCase(ep.name)}${!isQuery ? "Mutation" : ""}(args?: ${argType}, options?: { enabled?: boolean }) {
|
|
@@ -150,7 +159,9 @@ function generateEndpointMethod(
|
|
|
150
159
|
} else {
|
|
151
160
|
return `
|
|
152
161
|
${camelCase(ep.name)}(args?: ${argType}): string {
|
|
153
|
-
const
|
|
162
|
+
const mappedArgs: any = { ...(args || {}) };
|
|
163
|
+
${argsMapping}
|
|
164
|
+
const argsStr = Object.keys(mappedArgs).length > 0 ? JSON.stringify(mappedArgs) : '';
|
|
154
165
|
return \`${ns}.${ep.name}(\${argsStr})\`;
|
|
155
166
|
},`;
|
|
156
167
|
}
|