create-caspian-app 0.0.21 → 0.0.23
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.
- package/dist/main.py +18 -2
- package/dist/settings/component-map.ts +44 -11
- package/package.json +1 -1
package/dist/main.py
CHANGED
|
@@ -355,10 +355,26 @@ def register_single_route(url_pattern: str, file_path: str):
|
|
|
355
355
|
if not hasattr(module, 'page'):
|
|
356
356
|
raise AttributeError(f"Missing 'def page():' in {file_path}")
|
|
357
357
|
|
|
358
|
+
# === INTELLIGENT ARGUMENT BINDING ===
|
|
359
|
+
# Detects if the page function needs 'request' or traditional kwargs
|
|
360
|
+
sig = inspect.signature(module.page)
|
|
361
|
+
call_kwargs = {}
|
|
362
|
+
call_args = []
|
|
363
|
+
|
|
364
|
+
# Legacy support: If path params exist, pass them as first positional arg
|
|
365
|
+
# UNLESS the function signature looks like it only wants request
|
|
366
|
+
if kwargs:
|
|
367
|
+
call_args.append(kwargs)
|
|
368
|
+
|
|
369
|
+
# Injection support: If 'request' is in signature, pass it
|
|
370
|
+
if 'request' in sig.parameters:
|
|
371
|
+
call_kwargs['request'] = request
|
|
372
|
+
|
|
358
373
|
if inspect.iscoroutinefunction(module.page):
|
|
359
|
-
result = await
|
|
374
|
+
result = await module.page(*call_args, **call_kwargs)
|
|
360
375
|
else:
|
|
361
|
-
result = module.page(
|
|
376
|
+
result = module.page(*call_args, **call_kwargs)
|
|
377
|
+
# ====================================
|
|
362
378
|
|
|
363
379
|
if isinstance(result, Response):
|
|
364
380
|
return result
|
|
@@ -71,7 +71,7 @@ function extractDictKeysFromNode(node: Parser.SyntaxNode): string[] {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Extracts values from a Literal[...]
|
|
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
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|