atmx-cli 0.67.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 to bind them to the module
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,19 +25,16 @@ 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: Properly generate React WebSocket imperative methods!
28
+ // ✨ FIX: Use the top-level axiomQueryManager instead of require()
29
29
  lines.push(` connect(methodName: string, args?: Record<string, any>) {`);
30
- lines.push(` const { axiomQueryManager } = require('atmx-react');`);
31
30
  lines.push(` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`);
32
31
  lines.push(` axiomQueryManager.connect(def);`);
33
32
  lines.push(` },`);
34
33
  lines.push(` disconnect(methodName: string, args?: Record<string, any>) {`);
35
- lines.push(` const { axiomQueryManager } = require('atmx-react');`);
36
34
  lines.push(` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`);
37
35
  lines.push(` axiomQueryManager.disconnect(def);`);
38
36
  lines.push(` },`);
39
37
  lines.push(` send(methodName: string, payload: any, args?: Record<string, any>) {`);
40
- lines.push(` const { axiomQueryManager } = require('atmx-react');`);
41
38
  lines.push(` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`);
42
39
  lines.push(` axiomQueryManager.send(def, payload);`);
43
40
  lines.push(` }`);
@@ -89,18 +86,19 @@ function generateSdk(multiIr, isReact = false) {
89
86
  lines.push(`};\n`);
90
87
  return lines.join("\n");
91
88
  }
92
- // FILE: atmx-cli/src/generators/sdk-generator.ts (Partial replacement)
93
89
  function generateEndpointMethod(ep, ns, camelNs, isReact) {
94
90
  const rawParams = ep.parameters || [];
95
91
  const params = Array.isArray(rawParams)
96
92
  ? rawParams
97
93
  : Object.values(rawParams);
98
- const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
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;
99
98
  const rawReturnType = (0, utils_1.mapTypeToTs)(ep.returnType, camelNs);
100
99
  const returnType = rawReturnType === "void" || rawReturnType === "any"
101
100
  ? rawReturnType
102
101
  : prefixModels(rawReturnType);
103
- // Map camelCase TS args back to original IR snake_case names!
104
102
  const argsMapping = params
105
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)}"]; }`)
106
104
  .join("\n ");
@@ -115,7 +113,7 @@ function generateEndpointMethod(ep, ns, camelNs, isReact) {
115
113
  args: args || {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
116
114
  };
117
115
  },
118
- use${(0, utils_1.pascalCase)(ep.name)}${!isQuery ? "Mutation" : ""}(options?: { enabled?: boolean }) {
116
+ use${(0, utils_1.pascalCase)(ep.name)}(${isQuery ? "options?: { enabled?: boolean }" : ""}) {
119
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));`}
120
118
  },`;
121
119
  }
@@ -149,7 +147,7 @@ function generateEndpointMethod(ep, ns, camelNs, isReact) {
149
147
  payload: payload, args: mappedArgs, decoder: ${decLogic}, serializer: ${serLogic}, isStream: ${ep.isStream === true}
150
148
  };
151
149
  },
152
- use${(0, utils_1.pascalCase)(ep.name)}${!isQuery ? "Mutation" : ""}(args?: ${argType}, options?: { enabled?: boolean }) {
150
+ use${(0, utils_1.pascalCase)(ep.name)}(${isQuery ? `args?: ${argType}, options?: { enabled?: boolean }` : `args?: ${argType}`}) {
153
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));`}
154
152
  },`;
155
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atmx-cli",
3
- "version": "0.67.0",
3
+ "version": "0.68.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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 to bind them to the module
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,11 +33,10 @@ export function generateSdk(
34
33
  lines.push(` clearAuthToken(methodName: string) {`);
35
34
  lines.push(` clearAuthToken("${ns}", methodName);`);
36
35
  lines.push(` },`);
37
- // ✨ FIX: Properly generate React WebSocket imperative methods!
36
+ // ✨ FIX: Use the top-level axiomQueryManager instead of require()
38
37
  lines.push(
39
38
  ` connect(methodName: string, args?: Record<string, any>) {`,
40
39
  );
41
- lines.push(` const { axiomQueryManager } = require('atmx-react');`);
42
40
  lines.push(
43
41
  ` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`,
44
42
  );
@@ -47,7 +45,6 @@ export function generateSdk(
47
45
  lines.push(
48
46
  ` disconnect(methodName: string, args?: Record<string, any>) {`,
49
47
  );
50
- lines.push(` const { axiomQueryManager } = require('atmx-react');`);
51
48
  lines.push(
52
49
  ` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`,
53
50
  );
@@ -56,7 +53,6 @@ export function generateSdk(
56
53
  lines.push(
57
54
  ` send(methodName: string, payload: any, args?: Record<string, any>) {`,
58
55
  );
59
- lines.push(` const { axiomQueryManager } = require('atmx-react');`);
60
56
  lines.push(
61
57
  ` const def = (this as any)[\`get\${methodName.charAt(0).toUpperCase() + methodName.slice(1)}Def\`](args);`,
62
58
  );
@@ -137,8 +133,6 @@ export function generateSdk(
137
133
  return lines.join("\n");
138
134
  }
139
135
 
140
- // FILE: atmx-cli/src/generators/sdk-generator.ts (Partial replacement)
141
-
142
136
  function generateEndpointMethod(
143
137
  ep: AxiomEndpoint,
144
138
  ns: string,
@@ -150,14 +144,16 @@ function generateEndpointMethod(
150
144
  ? rawParams
151
145
  : Object.values(rawParams);
152
146
 
153
- const isQuery = ep.method ? ep.method.toUpperCase() === "GET" : true;
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;
154
151
  const rawReturnType = mapTypeToTs(ep.returnType, camelNs);
155
152
  const returnType =
156
153
  rawReturnType === "void" || rawReturnType === "any"
157
154
  ? rawReturnType
158
155
  : prefixModels(rawReturnType);
159
156
 
160
- // Map camelCase TS args back to original IR snake_case names!
161
157
  const argsMapping = params
162
158
  .map(
163
159
  (p: any) =>
@@ -176,7 +172,7 @@ function generateEndpointMethod(
176
172
  args: args || {}, decoder: ${decLogic}, serializer: (p: any) => p, isStream: ${ep.isStream === true}
177
173
  };
178
174
  },
179
- use${pascalCase(ep.name)}${!isQuery ? "Mutation" : ""}(options?: { enabled?: boolean }) {
175
+ use${pascalCase(ep.name)}(${isQuery ? "options?: { enabled?: boolean }" : ""}) {
180
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));`}
181
177
  },`;
182
178
  } else {
@@ -214,7 +210,7 @@ function generateEndpointMethod(
214
210
  payload: payload, args: mappedArgs, decoder: ${decLogic}, serializer: ${serLogic}, isStream: ${ep.isStream === true}
215
211
  };
216
212
  },
217
- use${pascalCase(ep.name)}${!isQuery ? "Mutation" : ""}(args?: ${argType}, options?: { enabled?: boolean }) {
213
+ use${pascalCase(ep.name)}(${isQuery ? `args?: ${argType}, options?: { enabled?: boolean }` : `args?: ${argType}`}) {
218
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));`}
219
215
  },`;
220
216
  } else {