atmx-cli 0.33.0 → 0.35.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.
@@ -30,12 +30,16 @@ function generateSdk(multiIr) {
30
30
  function generateEndpointMethod(ep, ns, pascalNs) {
31
31
  const params = ep.parameters || [];
32
32
  const argType = params.length > 0
33
- ? `{ ${params.map((p) => `${(0, utils_1.camelCase)(p.name)}${p.isOptional ? "?" : ""}: ${prefixModels((0, utils_1.mapTypeToTs)(p.typeRef, pascalNs))}`).join(", ")} }`
33
+ ? `{ ${params
34
+ .map((p) => {
35
+ // ✨ FIX: Make everything optional so DOM forms can fill in the blanks!
36
+ return `${(0, utils_1.camelCase)(p.name)}?: ${prefixModels((0, utils_1.mapTypeToTs)(p.typeRef, pascalNs))}`;
37
+ })
38
+ .join(", ")} }`
34
39
  : "void";
35
- // We generate a method that takes the typed arguments and returns the exact string ATMX expects
36
40
  return `
37
41
  /** RPC String Generator for <AxQuery> or <AxMutate> */
38
- ${(0, utils_1.camelCase)(ep.name)}(args${params.length > 0 ? "" : "?"}: ${argType}): string {
42
+ ${(0, utils_1.camelCase)(ep.name)}(args${params.length > 0 ? "?" : ""}: ${argType} | void): string {
39
43
  const argsStr = args && Object.keys(args).length > 0 ? JSON.stringify(args) : '';
40
44
  return \`${ns}.${ep.name}(\${argsStr})\`;
41
45
  }\n`;
@@ -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
- if (Array.isArray(obj))
22
- return obj.map(normalizeIr);
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 'any';
39
- if (typeRef.kind === 'primitive') {
66
+ return "any";
67
+ if (typeRef.kind === "primitive") {
40
68
  switch (typeRef.value) {
41
- case 'string': return 'string';
42
- case 'int':
43
- case 'float':
44
- case 'double': return 'number';
45
- case 'boolean': return 'boolean';
46
- case 'dateTime': return 'Date';
47
- case 'bytes': return 'Uint8Array';
48
- default: return 'any';
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 === 'named') {
85
+ if (typeRef.kind === "named") {
52
86
  const name = pascalCase(typeRef.value);
53
- return ns ? `${ns}${name}` : name; // ✅ FIX HERE
87
+ return ns ? `${ns}${name}` : name;
54
88
  }
55
- if (typeRef.kind === 'list') {
89
+ if (typeRef.kind === "list") {
56
90
  return `${mapTypeToTs(typeRef.value, ns)}[]`;
57
91
  }
58
- return 'any';
92
+ return "any";
59
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atmx-cli",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -44,13 +44,17 @@ function generateEndpointMethod(
44
44
 
45
45
  const argType =
46
46
  params.length > 0
47
- ? `{ ${params.map((p) => `${camelCase(p.name)}${p.isOptional ? "?" : ""}: ${prefixModels(mapTypeToTs(p.typeRef, pascalNs))}`).join(", ")} }`
47
+ ? `{ ${params
48
+ .map((p) => {
49
+ // ✨ FIX: Make everything optional so DOM forms can fill in the blanks!
50
+ return `${camelCase(p.name)}?: ${prefixModels(mapTypeToTs(p.typeRef, pascalNs))}`;
51
+ })
52
+ .join(", ")} }`
48
53
  : "void";
49
54
 
50
- // We generate a method that takes the typed arguments and returns the exact string ATMX expects
51
55
  return `
52
56
  /** RPC String Generator for <AxQuery> or <AxMutate> */
53
- ${camelCase(ep.name)}(args${params.length > 0 ? "" : "?"}: ${argType}): string {
57
+ ${camelCase(ep.name)}(args${params.length > 0 ? "?" : ""}: ${argType} | void): string {
54
58
  const argsStr = args && Object.keys(args).length > 0 ? JSON.stringify(args) : '';
55
59
  return \`${ns}.${ep.name}(\${argsStr})\`;
56
60
  }\n`;
@@ -1,58 +1,104 @@
1
1
  // atmx-cli/src/generators/utils.ts
2
2
 
3
3
  export function pascalCase(str: string): string {
4
- if (!str) return '';
5
- return str
6
- .split(/[_\-\s]+/)
7
- .map(part => part.charAt(0).toUpperCase() + part.slice(1))
8
- .join('');
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
- const pascal = pascalCase(str);
13
- return pascal.charAt(0).toLowerCase() + pascal.slice(1);
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
- if (Array.isArray(obj)) return obj.map(normalizeIr);
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]);
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 newObj;
58
+ return model;
59
+ });
25
60
  }
26
- return obj;
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
- if (!typeRef) return 'any';
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
- if (typeRef.kind === 'named') {
49
- const name = pascalCase(typeRef.value);
50
- return ns ? `${ns}${name}` : name; // ✅ FIX HERE
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
- if (typeRef.kind === 'list') {
54
- return `${mapTypeToTs(typeRef.value, ns)}[]`;
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
- return 'any';
58
- }
103
+ return "any";
104
+ }