atmx-cli 0.66.0 → 0.68.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.
|
@@ -6,16 +6,16 @@ function generateSdk(multiIr, isReact = false) {
|
|
|
6
6
|
const lines = [
|
|
7
7
|
`// GENERATED CODE – DO NOT EDIT.`,
|
|
8
8
|
`/* eslint-disable @typescript-eslint/no-explicit-any */`,
|
|
9
|
+
`/* eslint-disable @typescript-eslint/no-unused-vars */`,
|
|
9
10
|
`import * as models from './models';\n`,
|
|
10
11
|
];
|
|
11
12
|
if (isReact) {
|
|
12
|
-
// ✨ FIX: Auto-import the auth helpers
|
|
13
|
-
lines.push(`import { useAxiomQuery, useAxiomMutation, setAuthToken, clearAuthToken } from 'atmx-react';`);
|
|
13
|
+
// ✨ FIX: Auto-import the auth helpers and QueryManager directly
|
|
14
|
+
lines.push(`import { useAxiomQuery, useAxiomMutation, setAuthToken, clearAuthToken, axiomQueryManager } from 'atmx-react';`);
|
|
14
15
|
lines.push(`import type { AxiomQueryDef } from 'atmx-react';\n`);
|
|
15
16
|
}
|
|
16
17
|
for (const [ns, ir] of Object.entries(multiIr)) {
|
|
17
18
|
const camelNs = (0, utils_1.camelCase)(ns);
|
|
18
|
-
// 👉 THIS LINE WAS MISSING IN THE PREVIOUS STEP!
|
|
19
19
|
lines.push(`export const ${camelNs}Module = {`);
|
|
20
20
|
lines.push(` axiom: {`);
|
|
21
21
|
if (isReact) {
|
|
@@ -25,14 +25,18 @@ function generateSdk(multiIr, isReact = false) {
|
|
|
25
25
|
lines.push(` clearAuthToken(methodName: string) {`);
|
|
26
26
|
lines.push(` clearAuthToken("${ns}", methodName);`);
|
|
27
27
|
lines.push(` },`);
|
|
28
|
+
// ✨ FIX: Use the top-level axiomQueryManager instead of require()
|
|
28
29
|
lines.push(` connect(methodName: string, args?: Record<string, any>) {`);
|
|
29
|
-
lines.push(`
|
|
30
|
+
lines.push(` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`);
|
|
31
|
+
lines.push(` axiomQueryManager.connect(def);`);
|
|
30
32
|
lines.push(` },`);
|
|
31
33
|
lines.push(` disconnect(methodName: string, args?: Record<string, any>) {`);
|
|
32
|
-
lines.push(`
|
|
34
|
+
lines.push(` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`);
|
|
35
|
+
lines.push(` axiomQueryManager.disconnect(def);`);
|
|
33
36
|
lines.push(` },`);
|
|
34
37
|
lines.push(` send(methodName: string, payload: any, args?: Record<string, any>) {`);
|
|
35
|
-
lines.push(`
|
|
38
|
+
lines.push(` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`);
|
|
39
|
+
lines.push(` axiomQueryManager.send(def, payload);`);
|
|
36
40
|
lines.push(` }`);
|
|
37
41
|
}
|
|
38
42
|
else {
|
|
@@ -82,18 +86,19 @@ function generateSdk(multiIr, isReact = false) {
|
|
|
82
86
|
lines.push(`};\n`);
|
|
83
87
|
return lines.join("\n");
|
|
84
88
|
}
|
|
85
|
-
// FILE: atmx-cli/src/generators/sdk-generator.ts (Partial replacement)
|
|
86
89
|
function generateEndpointMethod(ep, ns, camelNs, isReact) {
|
|
87
90
|
const rawParams = ep.parameters || [];
|
|
88
91
|
const params = Array.isArray(rawParams)
|
|
89
92
|
? rawParams
|
|
90
93
|
: Object.values(rawParams);
|
|
91
|
-
|
|
94
|
+
// ✨ FIX: Treat "WS" as a query (subscription) instead of a mutation!
|
|
95
|
+
const isQuery = ep.method
|
|
96
|
+
? ["GET", "WS"].includes(ep.method.toUpperCase())
|
|
97
|
+
: true;
|
|
92
98
|
const rawReturnType = (0, utils_1.mapTypeToTs)(ep.returnType, camelNs);
|
|
93
99
|
const returnType = rawReturnType === "void" || rawReturnType === "any"
|
|
94
100
|
? rawReturnType
|
|
95
101
|
: prefixModels(rawReturnType);
|
|
96
|
-
// Map camelCase TS args back to original IR snake_case names!
|
|
97
102
|
const argsMapping = params
|
|
98
103
|
.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)}"]; }`)
|
|
99
104
|
.join("\n ");
|
|
@@ -108,7 +113,7 @@ function generateEndpointMethod(ep, ns, camelNs, isReact) {
|
|
|
108
113
|
args: args || {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
|
|
109
114
|
};
|
|
110
115
|
},
|
|
111
|
-
use${(0, utils_1.pascalCase)(ep.name)}${
|
|
116
|
+
use${(0, utils_1.pascalCase)(ep.name)}(${isQuery ? "options?: { enabled?: boolean }" : ""}) {
|
|
112
117
|
${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));`}
|
|
113
118
|
},`;
|
|
114
119
|
}
|
|
@@ -142,7 +147,7 @@ function generateEndpointMethod(ep, ns, camelNs, isReact) {
|
|
|
142
147
|
payload: payload, args: mappedArgs, decoder: ${decLogic}, serializer: ${serLogic}, isStream: ${ep.isStream === true}
|
|
143
148
|
};
|
|
144
149
|
},
|
|
145
|
-
use${(0, utils_1.pascalCase)(ep.name)}${
|
|
150
|
+
use${(0, utils_1.pascalCase)(ep.name)}(${isQuery ? `args?: ${argType}, options?: { enabled?: boolean }` : `args?: ${argType}`}) {
|
|
146
151
|
${isQuery ? `return useAxiomQuery<${returnType}>(this.get${(0, utils_1.pascalCase)(ep.name)}Def(args), options);` : `return useAxiomMutation<${returnType}, ${argType}>((a) => this.get${(0, utils_1.pascalCase)(ep.name)}Def(a || args));`}
|
|
147
152
|
},`;
|
|
148
153
|
}
|
package/package.json
CHANGED
|
@@ -9,21 +9,20 @@ export function generateSdk(
|
|
|
9
9
|
const lines: string[] = [
|
|
10
10
|
`// GENERATED CODE – DO NOT EDIT.`,
|
|
11
11
|
`/* eslint-disable @typescript-eslint/no-explicit-any */`,
|
|
12
|
+
`/* eslint-disable @typescript-eslint/no-unused-vars */`,
|
|
12
13
|
`import * as models from './models';\n`,
|
|
13
14
|
];
|
|
14
15
|
|
|
15
16
|
if (isReact) {
|
|
16
|
-
// ✨ FIX: Auto-import the auth helpers
|
|
17
|
+
// ✨ FIX: Auto-import the auth helpers and QueryManager directly
|
|
17
18
|
lines.push(
|
|
18
|
-
`import { useAxiomQuery, useAxiomMutation, setAuthToken, clearAuthToken } from 'atmx-react';`,
|
|
19
|
+
`import { useAxiomQuery, useAxiomMutation, setAuthToken, clearAuthToken, axiomQueryManager } from 'atmx-react';`,
|
|
19
20
|
);
|
|
20
21
|
lines.push(`import type { AxiomQueryDef } from 'atmx-react';\n`);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
for (const [ns, ir] of Object.entries(multiIr)) {
|
|
24
25
|
const camelNs = camelCase(ns);
|
|
25
|
-
|
|
26
|
-
// 👉 THIS LINE WAS MISSING IN THE PREVIOUS STEP!
|
|
27
26
|
lines.push(`export const ${camelNs}Module = {`);
|
|
28
27
|
|
|
29
28
|
lines.push(` axiom: {`);
|
|
@@ -34,26 +33,30 @@ export function generateSdk(
|
|
|
34
33
|
lines.push(` clearAuthToken(methodName: string) {`);
|
|
35
34
|
lines.push(` clearAuthToken("${ns}", methodName);`);
|
|
36
35
|
lines.push(` },`);
|
|
36
|
+
// ✨ FIX: Use the top-level axiomQueryManager instead of require()
|
|
37
37
|
lines.push(
|
|
38
38
|
` connect(methodName: string, args?: Record<string, any>) {`,
|
|
39
39
|
);
|
|
40
40
|
lines.push(
|
|
41
|
-
`
|
|
41
|
+
` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`,
|
|
42
42
|
);
|
|
43
|
+
lines.push(` axiomQueryManager.connect(def);`);
|
|
43
44
|
lines.push(` },`);
|
|
44
45
|
lines.push(
|
|
45
46
|
` disconnect(methodName: string, args?: Record<string, any>) {`,
|
|
46
47
|
);
|
|
47
48
|
lines.push(
|
|
48
|
-
`
|
|
49
|
+
` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`,
|
|
49
50
|
);
|
|
51
|
+
lines.push(` axiomQueryManager.disconnect(def);`);
|
|
50
52
|
lines.push(` },`);
|
|
51
53
|
lines.push(
|
|
52
54
|
` send(methodName: string, payload: any, args?: Record<string, any>) {`,
|
|
53
55
|
);
|
|
54
56
|
lines.push(
|
|
55
|
-
`
|
|
57
|
+
` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`,
|
|
56
58
|
);
|
|
59
|
+
lines.push(` axiomQueryManager.send(def, payload);`);
|
|
57
60
|
lines.push(` }`);
|
|
58
61
|
} else {
|
|
59
62
|
lines.push(` setAuthToken(methodName: string, token: string) {`);
|
|
@@ -130,8 +133,6 @@ export function generateSdk(
|
|
|
130
133
|
return lines.join("\n");
|
|
131
134
|
}
|
|
132
135
|
|
|
133
|
-
// FILE: atmx-cli/src/generators/sdk-generator.ts (Partial replacement)
|
|
134
|
-
|
|
135
136
|
function generateEndpointMethod(
|
|
136
137
|
ep: AxiomEndpoint,
|
|
137
138
|
ns: string,
|
|
@@ -143,14 +144,16 @@ function generateEndpointMethod(
|
|
|
143
144
|
? rawParams
|
|
144
145
|
: Object.values(rawParams);
|
|
145
146
|
|
|
146
|
-
|
|
147
|
+
// ✨ FIX: Treat "WS" as a query (subscription) instead of a mutation!
|
|
148
|
+
const isQuery = ep.method
|
|
149
|
+
? ["GET", "WS"].includes(ep.method.toUpperCase())
|
|
150
|
+
: true;
|
|
147
151
|
const rawReturnType = mapTypeToTs(ep.returnType, camelNs);
|
|
148
152
|
const returnType =
|
|
149
153
|
rawReturnType === "void" || rawReturnType === "any"
|
|
150
154
|
? rawReturnType
|
|
151
155
|
: prefixModels(rawReturnType);
|
|
152
156
|
|
|
153
|
-
// Map camelCase TS args back to original IR snake_case names!
|
|
154
157
|
const argsMapping = params
|
|
155
158
|
.map(
|
|
156
159
|
(p: any) =>
|
|
@@ -169,7 +172,7 @@ function generateEndpointMethod(
|
|
|
169
172
|
args: args || {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
|
|
170
173
|
};
|
|
171
174
|
},
|
|
172
|
-
use${pascalCase(ep.name)}${
|
|
175
|
+
use${pascalCase(ep.name)}(${isQuery ? "options?: { enabled?: boolean }" : ""}) {
|
|
173
176
|
${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));`}
|
|
174
177
|
},`;
|
|
175
178
|
} else {
|
|
@@ -207,7 +210,7 @@ function generateEndpointMethod(
|
|
|
207
210
|
payload: payload, args: mappedArgs, decoder: ${decLogic}, serializer: ${serLogic}, isStream: ${ep.isStream === true}
|
|
208
211
|
};
|
|
209
212
|
},
|
|
210
|
-
use${pascalCase(ep.name)}${
|
|
213
|
+
use${pascalCase(ep.name)}(${isQuery ? `args?: ${argType}, options?: { enabled?: boolean }` : `args?: ${argType}`}) {
|
|
211
214
|
${isQuery ? `return useAxiomQuery<${returnType}>(this.get${pascalCase(ep.name)}Def(args), options);` : `return useAxiomMutation<${returnType}, ${argType}>((a) => this.get${pascalCase(ep.name)}Def(a || args));`}
|
|
212
215
|
},`;
|
|
213
216
|
} else {
|