create-caspian-app 0.0.21 → 0.0.22

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.
@@ -71,7 +71,7 @@ function extractDictKeysFromNode(node: Parser.SyntaxNode): string[] {
71
71
  }
72
72
 
73
73
  /**
74
- * Extracts values from a Literal[...] type node
74
+ * Extracts values from a Literal[...] or types from Union[...] node
75
75
  */
76
76
  function extractLiteralValues(node: Parser.SyntaxNode): string[] {
77
77
  const values: string[] = [];
@@ -85,19 +85,52 @@ function extractLiteralValues(node: Parser.SyntaxNode): string[] {
85
85
  typeName = node.children.find((c) => c.type === "identifier")?.text;
86
86
  }
87
87
 
88
- if (typeName !== "Literal") return values;
88
+ // --- Handle Literal[...] ---
89
+ if (typeName === "Literal") {
90
+ const findValues = (n: Parser.SyntaxNode) => {
91
+ if (n.type === "string") {
92
+ // Strip quotes from strings
93
+ values.push(n.text.replace(/^['"]|['"]$/g, ""));
94
+ } else if (
95
+ ["integer", "float", "true", "false", "none"].includes(n.type)
96
+ ) {
97
+ // Capture raw values for primitives (e.g. Literal[1, True, None])
98
+ values.push(n.text);
99
+ }
100
+ for (const child of n.children) {
101
+ findValues(child);
102
+ }
103
+ };
104
+ findValues(node);
105
+ }
89
106
 
90
- const findStrings = (n: Parser.SyntaxNode) => {
91
- if (n.type === "string") {
92
- values.push(n.text.replace(/^['"]|['"]$/g, ""));
93
- return;
94
- }
95
- for (const child of n.children) {
96
- findStrings(child);
107
+ // --- Handle Union[...] ---
108
+ else if (typeName === "Union") {
109
+ for (const child of node.children) {
110
+ // Skip the "Union" keyword itself and punctuation
111
+ if (
112
+ (child.type === "identifier" && child.text === "Union") ||
113
+ ["[", "]", ","].includes(child.type)
114
+ ) {
115
+ continue;
116
+ }
117
+
118
+ // Capture Types (bool, str, etc.) and None
119
+ if (
120
+ child.type === "identifier" ||
121
+ child.type === "none" ||
122
+ child.type === "type" ||
123
+ child.type === "primitive_type"
124
+ ) {
125
+ values.push(child.text);
126
+ }
127
+ // Recursively handle nested structures (e.g. Union[str, Literal["a"]])
128
+ else if (child.type === "subscript" || child.type === "generic_type") {
129
+ values.push(...extractLiteralValues(child));
130
+ }
97
131
  }
98
- };
132
+ }
99
133
 
100
- findStrings(node);
101
134
  return values;
102
135
  }
103
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-caspian-app",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Scaffold a new Caspian project (FastAPI-powered reactive Python framework).",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",