@xano/developer-mcp 1.0.45 → 1.0.47
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.
|
@@ -33,21 +33,46 @@ conditional {
|
|
|
33
33
|
|
|
34
34
|
> **Note:** Use `elseif` (one word), not `else if`.
|
|
35
35
|
|
|
36
|
+
## Switch
|
|
37
|
+
|
|
38
|
+
```xs
|
|
39
|
+
switch ($input.status) {
|
|
40
|
+
case ("active") {
|
|
41
|
+
var $message { value = "User is active" }
|
|
42
|
+
} break
|
|
43
|
+
case ("pending") {
|
|
44
|
+
var $message { value = "User is pending" }
|
|
45
|
+
} break
|
|
46
|
+
default {
|
|
47
|
+
var $message { value = "Unknown status" }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> **Note:** `break` goes **after** the closing `}` of each `case` block. The `default` case does not need `break`.
|
|
53
|
+
|
|
36
54
|
## Loops
|
|
37
55
|
|
|
38
56
|
```xs
|
|
39
57
|
// For each loop
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
foreach ($input.items) {
|
|
59
|
+
each as $item {
|
|
60
|
+
debug.log { value = $item.name }
|
|
61
|
+
}
|
|
42
62
|
}
|
|
43
63
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
// For loop (iterate N times)
|
|
65
|
+
for (10) {
|
|
66
|
+
each as $index {
|
|
67
|
+
debug.log { value = $index }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// While loop
|
|
72
|
+
var $counter { value = 0 }
|
|
73
|
+
while ($counter < 10) {
|
|
74
|
+
each {
|
|
75
|
+
var.update $counter { value = $counter + 1 }
|
|
51
76
|
}
|
|
52
77
|
}
|
|
53
78
|
|
|
@@ -149,25 +149,29 @@ var $content_type { value = $api_result.response.headers|first }
|
|
|
149
149
|
var $retries { value = 0 }
|
|
150
150
|
var $success { value = false }
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
stack {
|
|
153
|
+
while ($retries < 3 && $success == false) {
|
|
154
|
+
each {
|
|
155
|
+
try_catch {
|
|
156
|
+
try {
|
|
157
|
+
api.request {
|
|
158
|
+
url = "https://api.example.com/data"
|
|
159
|
+
method = "GET"
|
|
160
|
+
timeout = 10
|
|
161
|
+
} as $api_result
|
|
162
|
+
|
|
163
|
+
conditional {
|
|
164
|
+
if ($api_result.response.status == 200) {
|
|
165
|
+
var.update $success { value = true }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
var.update $retries { value = $retries + 1 }
|
|
171
|
+
util.sleep { value = 2 }
|
|
164
172
|
}
|
|
165
173
|
}
|
|
166
174
|
}
|
|
167
|
-
catch {
|
|
168
|
-
var.update $retries { value = $retries + 1 }
|
|
169
|
-
util.sleep { value = 2 }
|
|
170
|
-
}
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
```
|
|
@@ -286,11 +286,14 @@ For basic rate limiting setup, see `xanoscript_docs({ topic: "security" })`. Bel
|
|
|
286
286
|
|
|
287
287
|
```xs
|
|
288
288
|
// Different limits by user tier
|
|
289
|
-
var $limit {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
289
|
+
var $limit { value = 100 }
|
|
290
|
+
|
|
291
|
+
conditional {
|
|
292
|
+
if ($auth.tier == "premium") {
|
|
293
|
+
var.update $limit { value = 1000 }
|
|
294
|
+
}
|
|
295
|
+
elseif ($auth.tier == "pro") {
|
|
296
|
+
var.update $limit { value = 500 }
|
|
294
297
|
}
|
|
295
298
|
}
|
|
296
299
|
|
|
@@ -150,16 +150,19 @@ conditional {
|
|
|
150
150
|
|
|
151
151
|
> **Important:** Use `elseif` (one word), not `else if` or `else { if (...) }`. Nested `if` inside `else` blocks is not supported.
|
|
152
152
|
|
|
153
|
-
### Conditional
|
|
153
|
+
### Conditional with Variable Updates
|
|
154
154
|
|
|
155
|
-
Use conditional blocks
|
|
155
|
+
Use conditional blocks to update a variable based on conditions:
|
|
156
156
|
|
|
157
157
|
```xs
|
|
158
|
-
var $tier_limit {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
var $tier_limit { value = 100 }
|
|
159
|
+
|
|
160
|
+
conditional {
|
|
161
|
+
if ($auth.tier == "premium") {
|
|
162
|
+
var.update $tier_limit { value = 1000 }
|
|
163
|
+
}
|
|
164
|
+
elseif ($auth.tier == "pro") {
|
|
165
|
+
var.update $tier_limit { value = 500 }
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
```
|
|
@@ -55,6 +55,8 @@ addon.call "<addon_name>" as $result
|
|
|
55
55
|
|
|
56
56
|
### function.call
|
|
57
57
|
|
|
58
|
+
> **Important:** Always use `function.call` in workflow tests, not `function.run`. `function.call` handles errors internally, which is required for `expect` assertions (such as `expect.to_throw`) to work correctly. `function.run` is for calling functions from other primitives (APIs, functions, tasks, etc.) outside of workflow tests.
|
|
59
|
+
|
|
58
60
|
```xs
|
|
59
61
|
function.call "<function_name>" {
|
|
60
62
|
input = { key: "value" }
|
|
@@ -319,7 +321,8 @@ workflow_test "comprehensive_test" {
|
|
|
319
321
|
2. **Tag for filtering** — Use tags like `critical`, `e2e`, `smoke` to organize test suites
|
|
320
322
|
3. **Avoid `datasource = "live"`** — The entire datasource is cloned before each test run, which can be slow. Use no datasource or a smaller custom datasource instead
|
|
321
323
|
4. **Keep tests independent** — Each workflow test should be self-contained and not depend on other tests
|
|
322
|
-
5. **Use
|
|
324
|
+
5. **Use `function.call`, not `function.run`** — `function.call` handles errors so that `expect` assertions work correctly. `function.run` is for calling functions outside of workflow tests
|
|
325
|
+
6. **Use assertions over preconditions** — Prefer `expect.*` assertions for clearer test intent
|
|
323
326
|
|
|
324
327
|
---
|
|
325
328
|
|
package/package.json
CHANGED