@xano/developer-mcp 1.0.1 → 1.0.2
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/README.md +96 -31
- package/dist/index.js +248 -180
- package/package.json +4 -2
- package/xanoscript_docs/README.md +107 -1
- package/xanoscript_docs/agents.md +329 -0
- package/xanoscript_docs/apis.md +343 -0
- package/xanoscript_docs/database.md +417 -0
- package/xanoscript_docs/ephemeral.md +333 -0
- package/xanoscript_docs/frontend.md +291 -0
- package/xanoscript_docs/functions.md +232 -2035
- package/xanoscript_docs/integrations.md +439 -0
- package/xanoscript_docs/mcp-servers.md +190 -0
- package/xanoscript_docs/plan.md +192 -0
- package/xanoscript_docs/syntax.md +314 -0
- package/xanoscript_docs/tables.md +270 -0
- package/xanoscript_docs/tasks.md +254 -0
- package/xanoscript_docs/testing.md +335 -0
- package/xanoscript_docs/tools.md +305 -0
- package/xanoscript_docs/types.md +297 -0
- package/xanoscript_docs/version.json +2 -1
- package/xanoscript_docs/api_query_examples.md +0 -1255
- package/xanoscript_docs/api_query_guideline.md +0 -129
- package/xanoscript_docs/build_from_lovable.md +0 -715
- package/xanoscript_docs/db_query_guideline.md +0 -427
- package/xanoscript_docs/ephemeral_environment_guideline.md +0 -529
- package/xanoscript_docs/expression_guideline.md +0 -1086
- package/xanoscript_docs/frontend_guideline.md +0 -67
- package/xanoscript_docs/function_examples.md +0 -1406
- package/xanoscript_docs/function_guideline.md +0 -130
- package/xanoscript_docs/input_guideline.md +0 -227
- package/xanoscript_docs/mcp_server_examples.md +0 -36
- package/xanoscript_docs/mcp_server_guideline.md +0 -69
- package/xanoscript_docs/query_filter.md +0 -489
- package/xanoscript_docs/table_examples.md +0 -586
- package/xanoscript_docs/table_guideline.md +0 -137
- package/xanoscript_docs/task_examples.md +0 -511
- package/xanoscript_docs/task_guideline.md +0 -103
- package/xanoscript_docs/tips_and_tricks.md +0 -144
- package/xanoscript_docs/tool_examples.md +0 -69
- package/xanoscript_docs/tool_guideline.md +0 -139
- package/xanoscript_docs/unit_testing_guideline.md +0 -328
- package/xanoscript_docs/workspace.md +0 -17
|
@@ -1,2155 +1,352 @@
|
|
|
1
1
|
---
|
|
2
|
-
applyTo: "functions/**/*.xs
|
|
2
|
+
applyTo: "functions/**/*.xs"
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# Functions
|
|
6
|
+
|
|
7
|
+
Reusable logic blocks in XanoScript.
|
|
8
|
+
|
|
9
|
+
## Quick Reference
|
|
6
10
|
|
|
7
11
|
```xs
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
for (3) {
|
|
13
|
-
each as $index {
|
|
14
|
-
math.add $counter {
|
|
15
|
-
value = 1
|
|
16
|
-
}
|
|
17
|
-
}
|
|
12
|
+
function "<name>" {
|
|
13
|
+
description = "What this function does"
|
|
14
|
+
input {
|
|
15
|
+
<type> <name> [filters=...] { description = "..." }
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
stack {
|
|
18
|
+
# Logic here
|
|
21
19
|
}
|
|
20
|
+
response = $result
|
|
22
21
|
}
|
|
23
22
|
```
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
### Calling Functions
|
|
25
|
+
```xs
|
|
26
|
+
function.run "<name>" {
|
|
27
|
+
input = { key: value }
|
|
28
|
+
} as $result
|
|
29
|
+
```
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
---
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
## Basic Structure
|
|
35
34
|
|
|
36
35
|
```xs
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
function "calculate_total" {
|
|
37
|
+
input {
|
|
38
|
+
int quantity filters=min:0
|
|
39
|
+
decimal price filters=min:0
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
stack {
|
|
42
|
+
var $total { value = $input.quantity * $input.price }
|
|
44
43
|
}
|
|
44
|
+
response = $total
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
### With Subfolders
|
|
49
|
+
Functions can be organized in subfolders:
|
|
50
|
+
```
|
|
51
|
+
functions/
|
|
52
|
+
├── math/
|
|
53
|
+
│ ├── add.xs
|
|
54
|
+
│ └── multiply.xs
|
|
55
|
+
├── utils/
|
|
56
|
+
│ └── format.xs
|
|
57
|
+
└── validate.xs
|
|
58
|
+
```
|
|
54
59
|
|
|
55
|
-
|
|
60
|
+
Reference with path: `function.run "math/add" { ... }`
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
- timestamp
|
|
59
|
-
- text
|
|
60
|
-
- uuid
|
|
61
|
-
- vector
|
|
62
|
-
- date
|
|
63
|
-
- bool
|
|
64
|
-
- decimal
|
|
65
|
-
- email
|
|
66
|
-
- password
|
|
67
|
-
- json
|
|
68
|
-
- image
|
|
69
|
-
- video
|
|
70
|
-
- audio
|
|
71
|
-
- attachment
|
|
62
|
+
---
|
|
72
63
|
|
|
73
|
-
|
|
64
|
+
## Input Block
|
|
74
65
|
|
|
75
|
-
|
|
66
|
+
See [types.md](types.md) for complete type reference.
|
|
76
67
|
|
|
77
68
|
```xs
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
69
|
+
input {
|
|
70
|
+
text name filters=trim
|
|
71
|
+
int age? filters=min:0
|
|
72
|
+
email contact filters=lower { sensitive = true }
|
|
73
|
+
object address? {
|
|
74
|
+
schema {
|
|
75
|
+
text street
|
|
76
|
+
text city
|
|
77
|
+
text zip
|
|
78
|
+
}
|
|
86
79
|
}
|
|
87
|
-
timestamp registered_at?=now
|
|
88
80
|
}
|
|
89
81
|
```
|
|
90
82
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- Fields with their data types (e.g., `int`, `text`, `email`),
|
|
94
|
-
- Optional status (marked with `?`),
|
|
95
|
-
- Default values (e.g., `?=now`),
|
|
96
|
-
- Filters (e.g., `trim|lower`) to process field values,
|
|
97
|
-
- Metadata like `description` for clarity or `sensitive` to mark private fields.
|
|
83
|
+
---
|
|
98
84
|
|
|
99
|
-
|
|
85
|
+
## Stack Block
|
|
100
86
|
|
|
101
|
-
|
|
87
|
+
Contains the function logic using control flow, variables, and operations.
|
|
102
88
|
|
|
89
|
+
### Variables
|
|
103
90
|
```xs
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
A `response` block, used within a `query` or `function`, specifies the data to return as the result of the operation. The value parameter defines the output, which can be a variable (e.g., `$user_data`), a literal, or an expression. Responses determine what data is sent back to the caller, such as API response data or a function’s return value.
|
|
108
|
-
|
|
109
|
-
# schedule
|
|
91
|
+
stack {
|
|
92
|
+
var $counter { value = 0 }
|
|
93
|
+
var $data { value = { name: "test", items: [] } }
|
|
110
94
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
events = [
|
|
114
|
-
{starts_on: 2025-01-01 09:00:00+0000, freq: 86400},
|
|
115
|
-
{starts_on: 2025-01-02 09:00:00+0000, freq: 604800, ends_on: 2025-12-31 09:00:00+0000}
|
|
116
|
-
]
|
|
95
|
+
var.update $counter { value = $counter + 1 }
|
|
96
|
+
var.update $data.name { value = "updated" }
|
|
117
97
|
}
|
|
118
98
|
```
|
|
119
99
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
- `starts_on`: The start date and time (e.g., `2025-01-01 09:00:00+0000`),
|
|
123
|
-
- `freq`: The frequency in seconds for recurring tasks (e.g., `86400` for daily, `604800` for weekly),
|
|
124
|
-
- `ends_on`: An optional end date for recurring tasks (e.g., `2025-12-31 09:00:00+0000`).
|
|
125
|
-
|
|
126
|
-
Schedules automate task execution at specified intervals or times.
|
|
127
|
-
|
|
128
|
-
# table
|
|
129
|
-
|
|
100
|
+
### Conditionals
|
|
130
101
|
```xs
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
102
|
+
stack {
|
|
103
|
+
conditional {
|
|
104
|
+
if ($input.age >= 18) {
|
|
105
|
+
var $status { value = "adult" }
|
|
106
|
+
}
|
|
107
|
+
elseif ($input.age >= 13) {
|
|
108
|
+
var $status { value = "teen" }
|
|
137
109
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
sensitive = true
|
|
110
|
+
else {
|
|
111
|
+
var $status { value = "child" }
|
|
141
112
|
}
|
|
142
|
-
timestamp signup_date?=now
|
|
143
|
-
bool is_active?=true
|
|
144
113
|
}
|
|
145
|
-
index = [
|
|
146
|
-
{type: "primary", field: [{name: "id"}]}
|
|
147
|
-
{type: "gin", field: [{name: "xdo", op: "jsonb_path_op"}]}
|
|
148
|
-
{type: "btree", field: [{name: "email", op: "desc"}]}
|
|
149
|
-
]
|
|
150
114
|
}
|
|
151
115
|
```
|
|
152
116
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
- An `auth` flag to enable/disable authentication for the table,
|
|
156
|
-
- A `schema` block listing fields with their data types (e.g., `int`, `text`, `email`), optional status (marked with `?`), default values (e.g., `?=now`), filters (e.g., `trim|lower`), and metadata like `description` or `sensitive`,
|
|
157
|
-
- An `index` block defining indexes for efficient querying (e.g., `primary` for the `id` field, `unique` for the `email` field).
|
|
158
|
-
|
|
159
|
-
Tables are used to structure and store data in a database, such as customer information.
|
|
160
|
-
|
|
161
|
-
# query
|
|
162
|
-
|
|
117
|
+
### Loops
|
|
163
118
|
```xs
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
119
|
+
stack {
|
|
120
|
+
# For loop (count-based)
|
|
121
|
+
for (10) {
|
|
122
|
+
each as $i {
|
|
123
|
+
debug.log { value = $i }
|
|
169
124
|
}
|
|
170
125
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (`$category_filter|strlen > 0`) {
|
|
177
|
-
db.query "product" {
|
|
178
|
-
where = ($db.product.category|to_lower) == ($category_filter|to_lower)
|
|
179
|
-
} as $filtered_products
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
db.query "product" {
|
|
183
|
-
} as $filtered_products
|
|
184
|
-
}
|
|
126
|
+
|
|
127
|
+
# Foreach (array iteration)
|
|
128
|
+
foreach ($input.items) {
|
|
129
|
+
each as $item {
|
|
130
|
+
debug.log { value = $item.name }
|
|
185
131
|
}
|
|
186
132
|
}
|
|
187
|
-
response = $filtered_products
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
A `query` file defines an API endpoint to handle HTTP requests (e.g., GET, POST). It includes:
|
|
192
133
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
Queries are essential for creating API endpoints to retrieve or manipulate data, such as fetching products by category.
|
|
199
|
-
|
|
200
|
-
# function
|
|
201
|
-
|
|
202
|
-
```xs
|
|
203
|
-
function "calculate_total" {
|
|
204
|
-
input {
|
|
205
|
-
int quantity?
|
|
206
|
-
int price_per_item?
|
|
207
|
-
}
|
|
208
|
-
stack {
|
|
209
|
-
var $total {
|
|
210
|
-
value = 0
|
|
211
|
-
}
|
|
212
|
-
conditional {
|
|
213
|
-
if (`$input.quantity == null || $input.price_per_item == null`) {
|
|
214
|
-
throw {
|
|
215
|
-
name = "InvalidInputError"
|
|
216
|
-
value = "Quantity and price must be provided"
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
math.mul $total {
|
|
221
|
-
value = $input.quantity
|
|
222
|
-
}
|
|
223
|
-
math.mul $total {
|
|
224
|
-
value = $input.price_per_item
|
|
225
|
-
}
|
|
226
|
-
}
|
|
134
|
+
# While loop
|
|
135
|
+
while ($counter < 5) {
|
|
136
|
+
each {
|
|
137
|
+
math.add $counter { value = 1 }
|
|
227
138
|
}
|
|
228
139
|
}
|
|
229
|
-
response = $total
|
|
230
140
|
}
|
|
231
141
|
```
|
|
232
142
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
- A name (e.g., `"calculate_total"`) to identify the function,
|
|
236
|
-
- An `input` block to define parameters (e.g., `quantity` and `price_per_item`), which can be optional (marked with `?`),
|
|
237
|
-
- A `stack` block containing the logic to execute (e.g., calculations, conditionals),
|
|
238
|
-
- A `response` block specifying the return value (e.g., `$total`).
|
|
239
|
-
|
|
240
|
-
Functions are ideal for encapsulating logic, such as calculating a total cost, that can be reused across scripts.
|
|
241
|
-
|
|
242
|
-
# task
|
|
243
|
-
|
|
143
|
+
### Switch
|
|
244
144
|
```xs
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
145
|
+
stack {
|
|
146
|
+
switch ($input.status) {
|
|
147
|
+
case ("active") {
|
|
148
|
+
var $message { value = "User is active" }
|
|
149
|
+
} break
|
|
150
|
+
case ("pending") {
|
|
151
|
+
var $message { value = "User is pending" }
|
|
152
|
+
} break
|
|
153
|
+
default {
|
|
154
|
+
var $message { value = "Unknown status" }
|
|
155
|
+
}
|
|
250
156
|
}
|
|
251
|
-
schedule = [
|
|
252
|
-
{starts_on: 2025-01-01 08:00:00+0000, freq: 86400}
|
|
253
|
-
]
|
|
254
|
-
}
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
A `task` file defines a scheduled job that runs automatically at specified times. It includes:
|
|
258
|
-
|
|
259
|
-
- A name (e.g., `"daily_report"`) to identify the task,
|
|
260
|
-
- A `stack` block containing the actions to execute (e.g., querying a database),
|
|
261
|
-
- A `schedule` block with `events` to define when the task runs, including:
|
|
262
|
-
- `starts_on`: The start date and time (e.g., `2025-01-01 08:00:00+0000`),
|
|
263
|
-
- `freq`: The frequency in seconds for recurring tasks (e.g., `86400` for daily),
|
|
264
|
-
- `ends_on`: An optional end date for recurring tasks (not used here).
|
|
265
|
-
|
|
266
|
-
Tasks are ideal for automating recurring operations like generating reports or syncing data.
|
|
267
|
-
|
|
268
|
-
# api.lambda
|
|
269
|
-
|
|
270
|
-
```xs
|
|
271
|
-
api.lambda {
|
|
272
|
-
code = """
|
|
273
|
-
// Javascript or Typescript code goes here
|
|
274
|
-
return $input.value > 10 ? true : false;
|
|
275
|
-
timeout = 10
|
|
276
|
-
"""
|
|
277
|
-
} as $result
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
allows you to run provided `code` in Javascript or Typescript in a sandboxed environment. Maximum execution time is `timeout` seconds.
|
|
281
|
-
|
|
282
|
-
The lambda function has access to your function stack context like `$input`, `$var`, `$auth` and `$env`.
|
|
283
|
-
|
|
284
|
-
The result of the execution is stored in `as $result` variable and is the returned value of the code.
|
|
285
|
-
|
|
286
|
-
# api.request
|
|
287
|
-
|
|
288
|
-
```xs
|
|
289
|
-
api.request {
|
|
290
|
-
url = "https://api.example.com/users"
|
|
291
|
-
method = "GET"
|
|
292
|
-
params = {}|set:"user_id":"123"
|
|
293
|
-
headers = []|push:"Authorization: Bearer token123"
|
|
294
|
-
timeout = 30
|
|
295
|
-
} as $user_response
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
Sends an HTTP request to a specified URL and retrieves the response. It supports various HTTP methods, query parameters, custom headers, and a timeout to limit execution time. The response is stored in the variable specified by `as`.
|
|
299
|
-
|
|
300
|
-
# api.stream
|
|
301
|
-
|
|
302
|
-
```xs
|
|
303
|
-
api.stream {
|
|
304
|
-
value = $processed_results
|
|
305
|
-
}
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
Streams data back to the client when the API response type is set to `'Stream'`. This is useful for real-time data delivery, such as in live updates or large data transfers.
|
|
309
|
-
|
|
310
|
-
# api.realtime_event
|
|
311
|
-
|
|
312
|
-
```xs
|
|
313
|
-
api.realtime_event {
|
|
314
|
-
channel = "notifications_channel"
|
|
315
|
-
data = $alert_message
|
|
316
|
-
auth_table = "users"
|
|
317
|
-
auth_id = "user_789"
|
|
318
|
-
}
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
Sends a real-time event over a specified channel, enabling live updates in applications. It includes a data payload and optional authentication details to control access.
|
|
322
|
-
|
|
323
|
-
# var
|
|
324
|
-
|
|
325
|
-
```xs
|
|
326
|
-
var $name {
|
|
327
|
-
value = "value"
|
|
328
157
|
}
|
|
329
158
|
```
|
|
330
159
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
# var.update
|
|
334
|
-
|
|
160
|
+
### Error Handling
|
|
335
161
|
```xs
|
|
336
|
-
|
|
337
|
-
|
|
162
|
+
stack {
|
|
163
|
+
try_catch {
|
|
164
|
+
try {
|
|
165
|
+
function.run "risky_operation" { input = {} } as $result
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
debug.log { value = "Operation failed" }
|
|
169
|
+
var $result { value = null }
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
debug.log { value = "Cleanup complete" }
|
|
173
|
+
}
|
|
174
|
+
}
|
|
338
175
|
}
|
|
339
176
|
```
|
|
340
177
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
# array.find
|
|
344
|
-
|
|
178
|
+
### Throwing Errors
|
|
345
179
|
```xs
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
# array.push
|
|
180
|
+
stack {
|
|
181
|
+
precondition ($input.amount > 0) {
|
|
182
|
+
error_type = "inputerror"
|
|
183
|
+
error = "Amount must be positive"
|
|
184
|
+
}
|
|
352
185
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
description = "Add oranges to cart"
|
|
186
|
+
throw {
|
|
187
|
+
name = "ValidationError"
|
|
188
|
+
value = "Custom error message"
|
|
189
|
+
}
|
|
358
190
|
}
|
|
359
191
|
```
|
|
360
192
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
# array.unshift
|
|
364
|
-
|
|
193
|
+
### Early Return
|
|
365
194
|
```xs
|
|
366
|
-
|
|
367
|
-
|
|
195
|
+
stack {
|
|
196
|
+
conditional {
|
|
197
|
+
if ($input.skip) {
|
|
198
|
+
return { value = null }
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
# Continue processing...
|
|
368
202
|
}
|
|
369
203
|
```
|
|
370
204
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
# array.shift
|
|
374
|
-
|
|
375
|
-
```xs
|
|
376
|
-
array.shift $waiting_list as $next_customer
|
|
377
|
-
```
|
|
205
|
+
---
|
|
378
206
|
|
|
379
|
-
|
|
207
|
+
## Response Block
|
|
380
208
|
|
|
381
|
-
|
|
209
|
+
Specify what the function returns:
|
|
382
210
|
|
|
383
211
|
```xs
|
|
384
|
-
|
|
212
|
+
response = $total # Single variable
|
|
213
|
+
response = { success: true, data: $result } # Object literal
|
|
214
|
+
response = $items|first # With filter
|
|
215
|
+
response = null # No return value
|
|
385
216
|
```
|
|
386
217
|
|
|
387
|
-
|
|
218
|
+
---
|
|
388
219
|
|
|
389
|
-
|
|
220
|
+
## Calling Functions
|
|
390
221
|
|
|
222
|
+
### Basic Call
|
|
391
223
|
```xs
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
224
|
+
function.run "calculate_total" {
|
|
225
|
+
input = { quantity: 5, price: 10.50 }
|
|
226
|
+
} as $total
|
|
395
227
|
```
|
|
396
228
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
# array.map
|
|
400
|
-
|
|
229
|
+
### With Variables
|
|
401
230
|
```xs
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
} as $
|
|
231
|
+
function.run "process_order" {
|
|
232
|
+
input = {
|
|
233
|
+
user_id: $auth.id,
|
|
234
|
+
items: $input.cart_items,
|
|
235
|
+
shipping: $input.address
|
|
236
|
+
}
|
|
237
|
+
} as $order
|
|
409
238
|
```
|
|
410
239
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
# array.partition
|
|
414
|
-
|
|
240
|
+
### Nested Calls
|
|
415
241
|
```xs
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
242
|
+
stack {
|
|
243
|
+
function.run "validate_user" {
|
|
244
|
+
input = { user_id: $input.user_id }
|
|
245
|
+
} as $user
|
|
420
246
|
|
|
421
|
-
|
|
247
|
+
function.run "calculate_discount" {
|
|
248
|
+
input = { user: $user, amount: $input.total }
|
|
249
|
+
} as $discount
|
|
422
250
|
|
|
423
|
-
|
|
424
|
-
{
|
|
425
|
-
"true": [
|
|
426
|
-
/* elements matching condition */
|
|
427
|
-
],
|
|
428
|
-
"false": [
|
|
429
|
-
/* elements not matching condition */
|
|
430
|
-
]
|
|
251
|
+
var $final_total { value = $input.total - $discount }
|
|
431
252
|
}
|
|
432
253
|
```
|
|
433
254
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
```xs
|
|
437
|
-
array.group_by ($users) {
|
|
438
|
-
by = $this.gender
|
|
439
|
-
} as $user_by_gender
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
Groups elements in an array based on a specified key or expression defined in `by`.
|
|
443
|
-
|
|
444
|
-
# array.union
|
|
445
|
-
|
|
446
|
-
```xs
|
|
447
|
-
// expects the result to be [1,2,3,4,5,6,7,8,9]
|
|
448
|
-
array.union ([1,3,5,7,9]) {
|
|
449
|
-
value = [2,4,6,8]
|
|
450
|
-
by = $this
|
|
451
|
-
} as $union
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
Combines two arrays into one, removing duplicate elements based on the expression defined in `by`.
|
|
455
|
-
|
|
456
|
-
# array.difference
|
|
457
|
-
|
|
458
|
-
```xs
|
|
459
|
-
// expects the result to be [1,3,5,7,9]
|
|
460
|
-
array.difference ([1,2,3,4,5,6,7,8,9]) {
|
|
461
|
-
value = [2,4,6,8]
|
|
462
|
-
by = $this
|
|
463
|
-
} as $difference
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
Creates a new array containing elements from the original array that are not present in the provided `value` array, based on the expression defined in `by`.
|
|
467
|
-
|
|
468
|
-
# array.intersection
|
|
469
|
-
|
|
470
|
-
```xs
|
|
471
|
-
// expects the result to be [2,4,6]
|
|
472
|
-
array.intersection ([1,2,3,4,5,6,7]) {
|
|
473
|
-
value = [2,4,6,8]
|
|
474
|
-
by = $this
|
|
475
|
-
} as $intersection
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
Generates a new array containing only the elements that exist in both the original array and the provided `value` array, based on the expression defined in `by`.
|
|
479
|
-
|
|
480
|
-
# array.find_index
|
|
481
|
-
|
|
482
|
-
```xs
|
|
483
|
-
array.find_index $sale_prices if (`$this < 20`) as $first_discount_index
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
Returns the index of the first element that satisfies the condition. If no match is found, it returns `-1`. The result is stored in the variable specified by `as`.
|
|
487
|
-
|
|
488
|
-
# array.has
|
|
489
|
-
|
|
490
|
-
```xs
|
|
491
|
-
array.has $team_roles if (`$this == "manager"`) {
|
|
492
|
-
disabled = false
|
|
493
|
-
description = "Verify manager role"
|
|
494
|
-
} as $has_manager
|
|
495
|
-
```
|
|
496
|
-
|
|
497
|
-
Checks if at least one element in the array meets the condition, returning `true` if so, `false` otherwise. The result is stored in the `as` variable. Optional `disabled` and `description` parameters control execution and add context.
|
|
498
|
-
|
|
499
|
-
# array.every
|
|
500
|
-
|
|
501
|
-
```xs
|
|
502
|
-
array.every $exam_scores if (`$this >= 70`) as $all_passed
|
|
503
|
-
```
|
|
504
|
-
|
|
505
|
-
Tests whether every element in the array satisfies the condition, returning `true` if they all do, `false` if any fail. The result is stored in the `as` variable.
|
|
506
|
-
|
|
507
|
-
# array.filter
|
|
508
|
-
|
|
509
|
-
```xs
|
|
510
|
-
array.filter $temperatures if (`$this > 32`) as $above_freezing
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
Creates a new array containing only the elements that meet the condition. The filtered result is stored in the variable specified by `as`.
|
|
514
|
-
|
|
515
|
-
# array.filter_count
|
|
516
|
-
|
|
517
|
-
```xs
|
|
518
|
-
array.filter_count $survey_responses if (`$this == "yes"`) as $yes_count
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
Counts how many elements in the array satisfy the condition. The total is stored in the variable defined by `as`.
|
|
522
|
-
|
|
523
|
-
Below is the documentation for the XanoScript functions related to database operations and control flow, as requested in your query. Each entry follows the style of the existing documentation, providing a code snippet example and a brief explanation of what the function does. The examples use meaningful variable names to illustrate practical use cases.
|
|
255
|
+
---
|
|
524
256
|
|
|
525
|
-
|
|
257
|
+
## Complete Examples
|
|
526
258
|
|
|
259
|
+
### Utility Function
|
|
527
260
|
```xs
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
261
|
+
function "utils/format_currency" {
|
|
262
|
+
description = "Format number as currency string"
|
|
263
|
+
input {
|
|
264
|
+
decimal amount
|
|
265
|
+
text currency?="USD"
|
|
533
266
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
value = "
|
|
267
|
+
stack {
|
|
268
|
+
var $formatted {
|
|
269
|
+
value = $input.amount|number_format:2:".":","
|
|
537
270
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
debug.log {
|
|
541
|
-
value = "User age not specified"
|
|
271
|
+
var $result {
|
|
272
|
+
value = $input.currency ~ " " ~ $formatted
|
|
542
273
|
}
|
|
543
274
|
}
|
|
275
|
+
response = $result
|
|
544
276
|
}
|
|
545
277
|
```
|
|
546
278
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
# continue
|
|
550
|
-
|
|
551
|
-
```xs
|
|
552
|
-
foreach $users as $user {
|
|
553
|
-
if (`$user.age < 18`) {
|
|
554
|
-
continue
|
|
555
|
-
}
|
|
556
|
-
debug.log {
|
|
557
|
-
value = `$user.name + " is an adult"`
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
```
|
|
561
|
-
|
|
562
|
-
Skips the current iteration of a loop and moves to the next one. This is useful for bypassing specific items in a loop based on a condition, such as skipping users under 18 in this example.
|
|
563
|
-
|
|
564
|
-
# db.add
|
|
565
|
-
|
|
279
|
+
### Data Processing
|
|
566
280
|
```xs
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
281
|
+
function "process_order" {
|
|
282
|
+
input {
|
|
283
|
+
int user_id { table = "user" }
|
|
284
|
+
object[] items {
|
|
285
|
+
schema {
|
|
286
|
+
int product_id
|
|
287
|
+
int quantity
|
|
288
|
+
}
|
|
289
|
+
}
|
|
571
290
|
}
|
|
572
|
-
|
|
573
|
-
|
|
291
|
+
stack {
|
|
292
|
+
var $total { value = 0 }
|
|
574
293
|
|
|
575
|
-
|
|
294
|
+
foreach ($input.items) {
|
|
295
|
+
each as $item {
|
|
296
|
+
db.get "product" {
|
|
297
|
+
field_name = "id"
|
|
298
|
+
field_value = $item.product_id
|
|
299
|
+
} as $product
|
|
576
300
|
|
|
577
|
-
|
|
301
|
+
math.add $total {
|
|
302
|
+
value = $product.price * $item.quantity
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
578
306
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
307
|
+
db.add "order" {
|
|
308
|
+
data = {
|
|
309
|
+
user_id: $input.user_id,
|
|
310
|
+
total: $total,
|
|
311
|
+
status: "pending"
|
|
312
|
+
}
|
|
313
|
+
} as $order
|
|
586
314
|
}
|
|
587
|
-
|
|
588
|
-
```
|
|
589
|
-
|
|
590
|
-
Adds a new record to a database table (e.g., `user`) or updates an existing one based on a specified field (e.g., `email`) and its value (e.g., `$input.email`). The data block specifies the fields to add or update, and the resulting record is stored in `$user_record`.
|
|
591
|
-
|
|
592
|
-
# db.del
|
|
593
|
-
|
|
594
|
-
```xs
|
|
595
|
-
db.del comment {
|
|
596
|
-
field_name = "id"
|
|
597
|
-
field_value = $input.commentId
|
|
315
|
+
response = $order
|
|
598
316
|
}
|
|
599
317
|
```
|
|
600
318
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
# db.direct_query
|
|
604
|
-
|
|
605
|
-
```xs
|
|
606
|
-
db.direct_query {
|
|
607
|
-
sql = "SELECT * FROM users WHERE users.email = ?"
|
|
608
|
-
response_type = "list"
|
|
609
|
-
arg = $input.email
|
|
610
|
-
} as $query_results
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
Executes a raw SQL query directly on the database, using placeholders (`?`) for parameters provided via `arg`. The `response_type` specifies whether to return a `list` or `single` result. The output is stored in the variable defined by `as`, here `$query_results`.
|
|
614
|
-
|
|
615
|
-
# db.edit
|
|
616
|
-
|
|
617
|
-
```xs
|
|
618
|
-
db.edit "user" {
|
|
619
|
-
field_name = "email"
|
|
620
|
-
field_value = $input.email
|
|
621
|
-
data = {
|
|
622
|
-
category: $input.category
|
|
623
|
-
}
|
|
624
|
-
} as $updated_user
|
|
625
|
-
```
|
|
626
|
-
|
|
627
|
-
Updates an existing record in a database table (e.g., `user`) identified by a field (e.g., `email`) and its value (e.g., `$input.email`). The `data` block specifies the fields to update, and the revised record is stored in `$updated_user`.
|
|
628
|
-
|
|
629
|
-
# db.get
|
|
630
|
-
|
|
631
|
-
```xs
|
|
632
|
-
db.get "user" {
|
|
633
|
-
field_name = "email"
|
|
634
|
-
field_value = $input.email
|
|
635
|
-
} as $user
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
Retrieves a single record from a database table (e.g., `user`) based on a specified field (e.g., `email`) and its value (e.g., `$input.email`). The fetched record is stored in the variable specified by `as`, here `$user`.
|
|
639
|
-
|
|
640
|
-
# db.has
|
|
641
|
-
|
|
642
|
-
```xs
|
|
643
|
-
db.has "user" {
|
|
644
|
-
field_name = "email"
|
|
645
|
-
field_value = $input.email
|
|
646
|
-
} as $user_exists
|
|
647
|
-
```
|
|
648
|
-
|
|
649
|
-
Checks if a record exists in a database table (e.g., `user`) based on a specified field (e.g., `email`) and its value (e.g., `$input.email`). Returns `true` if found, `false` otherwise, stored in `$user_exists`.
|
|
650
|
-
|
|
651
|
-
# db.query
|
|
652
|
-
|
|
319
|
+
### Validation Function
|
|
653
320
|
```xs
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
return = {
|
|
659
|
-
type: "list"
|
|
660
|
-
paging: {
|
|
661
|
-
page: 1
|
|
662
|
-
per_page: 25
|
|
663
|
-
}
|
|
321
|
+
function "validate_email_unique" {
|
|
322
|
+
input {
|
|
323
|
+
email email filters=lower
|
|
324
|
+
int exclude_id?
|
|
664
325
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
sort = {created_at: "asc"}
|
|
675
|
-
return = {
|
|
676
|
-
type: "list"
|
|
677
|
-
paging: {
|
|
678
|
-
page: $input.page
|
|
679
|
-
per_page: 20
|
|
326
|
+
stack {
|
|
327
|
+
db.query "user" {
|
|
328
|
+
where = $db.user.email == $input.email && $db.user.id != $input.exclude_id
|
|
329
|
+
return = { type: "exists" }
|
|
330
|
+
} as $exists
|
|
331
|
+
|
|
332
|
+
precondition (!$exists) {
|
|
333
|
+
error_type = "inputerror"
|
|
334
|
+
error = "Email already in use"
|
|
680
335
|
}
|
|
681
336
|
}
|
|
682
|
-
|
|
337
|
+
response = true
|
|
338
|
+
}
|
|
683
339
|
```
|
|
684
340
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
# db.schema
|
|
688
|
-
|
|
689
|
-
```xs
|
|
690
|
-
db.schema user {
|
|
691
|
-
path = "email"
|
|
692
|
-
} as $email_schema
|
|
693
|
-
```
|
|
341
|
+
---
|
|
694
342
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
# db.set_datasource
|
|
698
|
-
|
|
699
|
-
```xs
|
|
700
|
-
db.set_datasource {
|
|
701
|
-
value = "test"
|
|
702
|
-
}
|
|
703
|
-
```
|
|
704
|
-
|
|
705
|
-
Changes the datasource for all subsequent database queries in the current script execution to the specified value (e.g., `"test"`). This affects all database operations that follow.
|
|
706
|
-
|
|
707
|
-
# db.transaction
|
|
708
|
-
|
|
709
|
-
```xs
|
|
710
|
-
db.transaction {
|
|
711
|
-
description = "Update user and log action"
|
|
712
|
-
stack {
|
|
713
|
-
db.update user { /* ... */ }
|
|
714
|
-
db.add log { /* ... */ }
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
```
|
|
718
|
-
|
|
719
|
-
Executes a series of database operations (e.g., updating a user and adding a log entry) within a single transaction. Ensures atomicity—either all operations succeed, or none are applied. The `description` provides context.
|
|
720
|
-
|
|
721
|
-
# db.truncate
|
|
722
|
-
|
|
723
|
-
```xs
|
|
724
|
-
db.truncate user {
|
|
725
|
-
reset = true
|
|
726
|
-
}
|
|
727
|
-
```
|
|
728
|
-
|
|
729
|
-
Deletes all records from a specified database table (e.g., `user`). If `reset = true`, it also resets any auto-incrementing IDs, effectively clearing the table and starting fresh.
|
|
730
|
-
|
|
731
|
-
# db.external.mssql.direct_query
|
|
732
|
-
|
|
733
|
-
```xs
|
|
734
|
-
db.external.mssql.direct_query {
|
|
735
|
-
sql = "SELECT * FROM orders WHERE orders.total > ?"
|
|
736
|
-
response_type = "list"
|
|
737
|
-
connection_string = "mssql://db_user:db_password@server.com:1433/sales_db?sslmode=disabled"
|
|
738
|
-
arg = $input.min_total
|
|
739
|
-
} as $large_orders
|
|
740
|
-
```
|
|
741
|
-
|
|
742
|
-
Executes a SQL query directly on an external Microsoft SQL Server database. The `code` parameter contains the SQL statement, and `response_type` specifies whether it returns a `list` of records or a `single` record. The `connection_string` provides access to the database, and `arg` supplies values for placeholders (e.g., `?`) in the query. Results are stored in the variable defined by `as`, here `$large_orders`.
|
|
743
|
-
|
|
744
|
-
# db.external.mysql.direct_query
|
|
745
|
-
|
|
746
|
-
```xs
|
|
747
|
-
db.external.mysql.direct_query {
|
|
748
|
-
sql = "SELECT * FROM products WHERE products.category = ?"
|
|
749
|
-
response_type = "list"
|
|
750
|
-
connection_string = "mysql://db_user:db_password@host.com:3306/inventory_db?sslmode=disabled"
|
|
751
|
-
arg = $input.category
|
|
752
|
-
} as $category_products
|
|
753
|
-
```
|
|
754
|
-
|
|
755
|
-
Runs a SQL query directly on an external MySQL database. The `response_type` determines if the result is a `list` or a `single` record. The `connection_string` specifies the database connection, and `arg` provides values for query placeholders. The output is stored in the `as` variable, here `$category_products`.
|
|
756
|
-
|
|
757
|
-
# db.external.oracle.direct_query
|
|
758
|
-
|
|
759
|
-
```xs
|
|
760
|
-
db.external.oracle.direct_query {
|
|
761
|
-
sql = "SELECT * FROM employees WHERE employees.department = ?"
|
|
762
|
-
response_type = "list"
|
|
763
|
-
connection_string = "oracle://db_user:db_password@server.com:1521/hr_db"
|
|
764
|
-
arg = $input.department
|
|
765
|
-
} as $department_employees
|
|
766
|
-
```
|
|
767
|
-
|
|
768
|
-
Directly executes a SQL query on an external Oracle database. The `response_type` sets whether the query returns a `list` or a `single` record. The `connection_string` defines the database connection, and `arg` supplies placeholder values. Results are stored in the variable specified by `as`, here `$department_employees`.
|
|
769
|
-
|
|
770
|
-
# db.external.postgres.direct_query
|
|
771
|
-
|
|
772
|
-
```xs
|
|
773
|
-
db.external.postgres.direct_query {
|
|
774
|
-
sql = "SELECT * FROM customers WHERE customers.last_purchase > ?"
|
|
775
|
-
response_type = "list"
|
|
776
|
-
connection_string = "postgres://db_user:db_password@host.com:5432/shop_db?sslmode=prefer"
|
|
777
|
-
arg = $input.date_threshold
|
|
778
|
-
} as $recent_customers
|
|
779
|
-
```
|
|
780
|
-
|
|
781
|
-
Performs a SQL query directly on an external PostgreSQL database. The `response_type` indicates if the result is a `list` or a `single` record. The `connection_string` establishes the database connection, and `arg` provides values for placeholders. The results are stored in the `as` variable, here `$recent_customers`.
|
|
782
|
-
|
|
783
|
-
# debug.stop
|
|
784
|
-
|
|
785
|
-
```xs
|
|
786
|
-
debug.stop {
|
|
787
|
-
value = $some_var
|
|
788
|
-
}
|
|
789
|
-
```
|
|
790
|
-
|
|
791
|
-
This function stops the script’s execution at the point where it’s called and sends the specified `value` to the debugger. It’s a handy tool for troubleshooting, allowing you to inspect the contents of a variable (like `$some_var`) during development to ensure your script is working as expected.
|
|
792
|
-
|
|
793
|
-
# foreach
|
|
794
|
-
|
|
795
|
-
```xs
|
|
796
|
-
foreach ($numbers_list) {
|
|
797
|
-
each as $item {
|
|
798
|
-
var.update $sum {
|
|
799
|
-
value = `$sum + $item`
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
```
|
|
804
|
-
|
|
805
|
-
**Example with a predefined list**:
|
|
806
|
-
|
|
807
|
-
```xs
|
|
808
|
-
foreach ([1, 2, 3, 4]) {
|
|
809
|
-
each as $item {
|
|
810
|
-
var.update $sum {
|
|
811
|
-
value = `$sum + $item`
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
```
|
|
816
|
-
|
|
817
|
-
The `foreach` function loops through every item in a list (e.g., an array like `$numbers_list` or `[1, 2, 3, 4]`). The `each as` clause assigns the current item to a variable (e.g., `$item`), which you can use inside the loop to perform actions on each element.
|
|
818
|
-
|
|
819
|
-
# for
|
|
820
|
-
|
|
821
|
-
```xs
|
|
822
|
-
for (10) {
|
|
823
|
-
description = "Repeat this 10 times, with $index counting from 0 to 9"
|
|
824
|
-
each as $index {
|
|
825
|
-
debug.log {
|
|
826
|
-
value = `$index + 1`
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
```
|
|
831
|
-
|
|
832
|
-
This function creates a loop that runs a set number of times (e.g., 10). The `each as` clause provides a counter variable (e.g., `$index`), which starts at 0 and increases by 1 each iteration, up to one less than the specified number (e.g., 0 through 9 for a count of 10).
|
|
833
|
-
|
|
834
|
-
# function.run
|
|
835
|
-
|
|
836
|
-
```xs
|
|
837
|
-
function.run "add_fn" {
|
|
838
|
-
input = { a: $input.a, b: $input.b }
|
|
839
|
-
} as $func_result
|
|
840
|
-
```
|
|
841
|
-
|
|
842
|
-
The `function.run` function calls a custom function (e.g., `add_fn`) and passes it the data specified in the `input` parameter (e.g., an object with `a` and `b` values). The result of the function is stored in the variable named after `as` (e.g., `$func_result`), making it available for further use in your script.
|
|
843
|
-
|
|
844
|
-
# group
|
|
845
|
-
|
|
846
|
-
```xs
|
|
847
|
-
group {
|
|
848
|
-
description = "your group description"
|
|
849
|
-
stack {
|
|
850
|
-
debug.log {
|
|
851
|
-
value = "Action 1"
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
```
|
|
856
|
-
|
|
857
|
-
The `group` function organizes a set of actions into a logical block that can be collapsed in the user interface for better readability. The `description` field labels the group (e.g., "group description"), and the `stack` contains the actions you want to group together.
|
|
858
|
-
|
|
859
|
-
# math.sub
|
|
860
|
-
|
|
861
|
-
```xs
|
|
862
|
-
math.sub $total_cost {
|
|
863
|
-
value = $discount_amount
|
|
864
|
-
}
|
|
865
|
-
```
|
|
866
|
-
|
|
867
|
-
Subtracts the specified `value` (e.g., `$discount_amount`) from the variable (e.g., `$total_cost`) and updates the variable with the result. This is ideal for scenarios like reducing a total by a discount.
|
|
868
|
-
|
|
869
|
-
**NOTE**: math.sub does not return a value; it mutates the variable directly.
|
|
870
|
-
|
|
871
|
-
# math.mul
|
|
872
|
-
|
|
873
|
-
```xs
|
|
874
|
-
math.mul $base_price {
|
|
875
|
-
value = $tax_rate
|
|
876
|
-
}
|
|
877
|
-
```
|
|
878
|
-
|
|
879
|
-
Multiplies the variable (e.g., `$base_price`) by the specified `value` (e.g., `$tax_rate`) and stores the product back into the variable. Use this to calculate values like a price with tax applied.
|
|
880
|
-
|
|
881
|
-
**NOTE**: math.mul does not return a value; it mutates the variable directly.
|
|
882
|
-
|
|
883
|
-
# math.div
|
|
884
|
-
|
|
885
|
-
```xs
|
|
886
|
-
math.div $total_time {
|
|
887
|
-
value = $num_tasks
|
|
888
|
-
}
|
|
889
|
-
```
|
|
890
|
-
|
|
891
|
-
Divides the variable (e.g., `$total_time`) by the specified `value` (e.g., `$num_tasks`), updating the variable with the quotient. This is useful for finding averages, such as time per task.
|
|
892
|
-
|
|
893
|
-
**NOTE**: math.div mutates the value, it doesn't have a return value.
|
|
894
|
-
|
|
895
|
-
# math.bitwise.xor
|
|
896
|
-
|
|
897
|
-
```xs
|
|
898
|
-
math.bitwise.xor $flags {
|
|
899
|
-
value = $toggle_bit
|
|
900
|
-
}
|
|
901
|
-
```
|
|
902
|
-
|
|
903
|
-
Performs a bitwise XOR operation between the variable (e.g., `$flags`) and the specified `value` (e.g., `$toggle_bit`), storing the result in the variable. This is handy for toggling specific bits in a binary flag.
|
|
904
|
-
|
|
905
|
-
**NOTE**: math.bitwise.xor mutates the value, it doesn't have a return value.
|
|
906
|
-
|
|
907
|
-
# math.bitwise.or
|
|
908
|
-
|
|
909
|
-
```xs
|
|
910
|
-
math.bitwise.or $permissions {
|
|
911
|
-
value = $new_permission
|
|
912
|
-
}
|
|
913
|
-
```
|
|
914
|
-
|
|
915
|
-
Applies a bitwise OR operation between the variable (e.g., `$permissions`) and the specified `value` (e.g., `$new_permission`), updating the variable with the result. Commonly used to add permissions to an existing set.
|
|
916
|
-
|
|
917
|
-
**NOTE**: math.bitwise.or mutates the value, it doesn't have a return value.
|
|
918
|
-
|
|
919
|
-
# math.bitwise.and
|
|
920
|
-
|
|
921
|
-
```xs
|
|
922
|
-
math.bitwise.and $status_flags {
|
|
923
|
-
value = $check_bit
|
|
924
|
-
}
|
|
925
|
-
```
|
|
926
|
-
|
|
927
|
-
Executes a bitwise AND operation between the variable (e.g., `$status_flags`) and the specified `value` (e.g., `$check_bit`), saving the result in the variable. This is useful for checking if a particular bit is set.
|
|
928
|
-
|
|
929
|
-
**NOTE**: math.bitwise.and mutates the value, it doesn't have a return value.
|
|
930
|
-
|
|
931
|
-
# math.add
|
|
932
|
-
|
|
933
|
-
```xs
|
|
934
|
-
math.add $cart_total {
|
|
935
|
-
value = $item_price
|
|
936
|
-
}
|
|
937
|
-
```
|
|
938
|
-
|
|
939
|
-
Adds the specified `value` (e.g., `$item_price`) to the variable (e.g., `$cart_total`) and updates the variable with the sum. Perfect for accumulating values, like adding an item’s cost to a cart total.
|
|
940
|
-
|
|
941
|
-
**NOTE**: math.add mutates the value, it doesn't have a return value.
|
|
942
|
-
|
|
943
|
-
# redis.unshift
|
|
944
|
-
|
|
945
|
-
```xs
|
|
946
|
-
redis.unshift {
|
|
947
|
-
key = "task_list"
|
|
948
|
-
value = "urgent_task"
|
|
949
|
-
} as $new_list_length
|
|
950
|
-
```
|
|
951
|
-
|
|
952
|
-
Adds an element to the beginning of a Redis list specified by `key`. The `value` is the element to add, and the new length of the list is stored in the variable defined by `as`, here `$new_list_length`.
|
|
953
|
-
|
|
954
|
-
# redis.incr
|
|
955
|
-
|
|
956
|
-
```xs
|
|
957
|
-
redis.incr {
|
|
958
|
-
package_key = "1"
|
|
959
|
-
key = "visit_counter"
|
|
960
|
-
by = 1
|
|
961
|
-
} as $new_count
|
|
962
|
-
```
|
|
963
|
-
|
|
964
|
-
Increments a numeric value in Redis at the specified `key` within a `package_key` namespace by the amount given in `by`. The updated value is stored in the variable specified by `as`, here `$new_count`.
|
|
965
|
-
|
|
966
|
-
# redis.remove
|
|
967
|
-
|
|
968
|
-
```xs
|
|
969
|
-
redis.remove {
|
|
970
|
-
key = "user_list"
|
|
971
|
-
value = "inactive_user"
|
|
972
|
-
count = 1
|
|
973
|
-
}
|
|
974
|
-
```
|
|
975
|
-
|
|
976
|
-
Removes a specified number (`count`) of occurrences of `value` from a Redis list identified by `key`. This is useful for cleaning up lists by removing specific elements.
|
|
977
|
-
|
|
978
|
-
# redis.del
|
|
979
|
-
|
|
980
|
-
```xs
|
|
981
|
-
redis.del {
|
|
982
|
-
key = "session_data"
|
|
983
|
-
}
|
|
984
|
-
```
|
|
985
|
-
|
|
986
|
-
Deletes a key and its associated value from Redis, specified by `key`. This clears the cache entry, freeing up space.
|
|
987
|
-
|
|
988
|
-
# redis.push
|
|
989
|
-
|
|
990
|
-
```xs
|
|
991
|
-
redis.push {
|
|
992
|
-
package_key = "1"
|
|
993
|
-
key = "message_queue"
|
|
994
|
-
value = "new_message"
|
|
995
|
-
} as $queue_length
|
|
996
|
-
```
|
|
997
|
-
|
|
998
|
-
Adds an element to the end of a Redis list identified by `key` within a `package_key` namespace. The `value` is the element to add, and the new list length is stored in the variable defined by `as`, here `$queue_length`.
|
|
999
|
-
|
|
1000
|
-
# redis.ratelimit
|
|
1001
|
-
|
|
1002
|
-
```xs
|
|
1003
|
-
redis.ratelimit {
|
|
1004
|
-
key = "api_requests"
|
|
1005
|
-
max = 100
|
|
1006
|
-
ttl = 60
|
|
1007
|
-
error = "Rate limit exceeded"
|
|
1008
|
-
} as $rate_limit_status
|
|
1009
|
-
```
|
|
1010
|
-
|
|
1011
|
-
Enforces rate limiting on requests using Redis, tracking usage with `key`. It allows up to `max` requests within a `ttl` time window (in seconds). If exceeded, the `error` message is used, and the result (e.g., success or failure) is stored in `$rate_limit_status`.
|
|
1012
|
-
|
|
1013
|
-
# redis.range
|
|
1014
|
-
|
|
1015
|
-
```xs
|
|
1016
|
-
redis.range {
|
|
1017
|
-
key = "event_log"
|
|
1018
|
-
start = 0
|
|
1019
|
-
stop = 5
|
|
1020
|
-
} as $recent_events
|
|
1021
|
-
```
|
|
1022
|
-
|
|
1023
|
-
Retrieves a range of elements from a Redis list specified by `key`, from the `start` index to the `stop` index (inclusive). The result is stored in the variable defined by `as`, here `$recent_events`.
|
|
1024
|
-
|
|
1025
|
-
# redis.decr
|
|
1026
|
-
|
|
1027
|
-
```xs
|
|
1028
|
-
redis.decr {
|
|
1029
|
-
key = "stock_count"
|
|
1030
|
-
by = 1
|
|
1031
|
-
} as $new_stock
|
|
1032
|
-
```
|
|
1033
|
-
|
|
1034
|
-
Decrements a numeric value in Redis at the specified `key` by the amount given in `by`. The updated value is stored in the variable specified by `as`, here `$new_stock`.
|
|
1035
|
-
|
|
1036
|
-
# redis.pop
|
|
1037
|
-
|
|
1038
|
-
```xs
|
|
1039
|
-
redis.pop {
|
|
1040
|
-
key = "task_queue"
|
|
1041
|
-
} as $last_task
|
|
1042
|
-
```
|
|
1043
|
-
|
|
1044
|
-
Removes and returns the last element from a Redis list specified by `key`. The removed element is stored in the variable defined by `as`, here `$last_task`.
|
|
1045
|
-
|
|
1046
|
-
# redis.get
|
|
1047
|
-
|
|
1048
|
-
```xs
|
|
1049
|
-
redis.get {
|
|
1050
|
-
key = "user_session"
|
|
1051
|
-
} as $session_data
|
|
1052
|
-
```
|
|
1053
|
-
|
|
1054
|
-
Retrieves the value associated with a `key` from Redis. The result is stored in the variable specified by `as`, here `$session_data`.
|
|
1055
|
-
|
|
1056
|
-
# redis.set
|
|
1057
|
-
|
|
1058
|
-
```xs
|
|
1059
|
-
redis.set {
|
|
1060
|
-
key = "user_token"
|
|
1061
|
-
data = "token123"
|
|
1062
|
-
ttl = 3600
|
|
1063
|
-
}
|
|
1064
|
-
```
|
|
1065
|
-
|
|
1066
|
-
Sets a `key` in Redis to the specified `data` value, with an optional `ttl` (time-to-live in seconds) to control how long the key persists before expiring.
|
|
1067
|
-
|
|
1068
|
-
# redis.has
|
|
1069
|
-
|
|
1070
|
-
```xs
|
|
1071
|
-
redis.has {
|
|
1072
|
-
key = "user_token"
|
|
1073
|
-
} as $token_exists
|
|
1074
|
-
```
|
|
1075
|
-
|
|
1076
|
-
Checks if a `key` exists in Redis, returning `true` if it does, `false` otherwise. The result is stored in the variable specified by `as`, here `$token_exists`.
|
|
1077
|
-
|
|
1078
|
-
# redis.shift
|
|
1079
|
-
|
|
1080
|
-
```xs
|
|
1081
|
-
redis.shift {
|
|
1082
|
-
key = "message_queue"
|
|
1083
|
-
} as $first_message
|
|
1084
|
-
```
|
|
1085
|
-
|
|
1086
|
-
Removes and returns the first element from a Redis list specified by `key`. The removed element is stored in the variable defined by `as`, here `$first_message`.
|
|
1087
|
-
|
|
1088
|
-
# redis.count
|
|
1089
|
-
|
|
1090
|
-
```xs
|
|
1091
|
-
redis.count {
|
|
1092
|
-
key = "message_queue"
|
|
1093
|
-
} as $queue_size
|
|
1094
|
-
```
|
|
1095
|
-
|
|
1096
|
-
Returns the number of elements in a Redis list specified by `key`. The count is stored in the variable defined by `as`, here `$queue_size`.
|
|
1097
|
-
|
|
1098
|
-
# redis.keys
|
|
1099
|
-
|
|
1100
|
-
```xs
|
|
1101
|
-
redis.keys {
|
|
1102
|
-
where = "user_*"
|
|
1103
|
-
} as $user_keys
|
|
1104
|
-
```
|
|
1105
|
-
|
|
1106
|
-
Retrieves a list of Redis keys that match the specified `search` pattern (e.g., `user_*` for all keys starting with "user\_"). The matching keys are stored in the variable specified by `as`, here `$user_keys`.
|
|
1107
|
-
|
|
1108
|
-
# object.keys
|
|
1109
|
-
|
|
1110
|
-
```xs
|
|
1111
|
-
object.keys {
|
|
1112
|
-
value = $user_data
|
|
1113
|
-
} as $user_data_keys
|
|
1114
|
-
```
|
|
1115
|
-
|
|
1116
|
-
Retrieves the property keys of an object (e.g., `$user_data`) as an array. The resulting array of keys is stored in the variable specified by `as`, here `$user_data_keys`.
|
|
1117
|
-
|
|
1118
|
-
# object.values
|
|
1119
|
-
|
|
1120
|
-
```xs
|
|
1121
|
-
object.values {
|
|
1122
|
-
value = $product_info
|
|
1123
|
-
} as $product_values
|
|
1124
|
-
```
|
|
1125
|
-
|
|
1126
|
-
Extracts the values of an object’s properties (e.g., `$product_info`) into an array. The array of values is stored in the variable defined by `as`, here `$product_values`.
|
|
1127
|
-
|
|
1128
|
-
# object.entries
|
|
1129
|
-
|
|
1130
|
-
```xs
|
|
1131
|
-
object.entries {
|
|
1132
|
-
value = $settings
|
|
1133
|
-
} as $settings_pairs
|
|
1134
|
-
```
|
|
1135
|
-
|
|
1136
|
-
Returns an array of key-value pairs from an object (e.g., `$settings`), where each pair is an array containing the key and its corresponding value. The result is stored in the variable specified by `as`, here `$settings_pairs`.
|
|
1137
|
-
|
|
1138
|
-
# precondition
|
|
1139
|
-
|
|
1140
|
-
```xs
|
|
1141
|
-
precondition (`$user_age >= 18`) {
|
|
1142
|
-
error_type = "standard"
|
|
1143
|
-
error = "User must be 18 or older"
|
|
1144
|
-
}
|
|
1145
|
-
```
|
|
1146
|
-
|
|
1147
|
-
Throws an exception if the specified condition (e.g., `$user_age >= 18`) evaluates to `false`. The `error_type` defines the type of error, and `error` provides a custom message to describe the failure.
|
|
1148
|
-
|
|
1149
|
-
# return
|
|
1150
|
-
|
|
1151
|
-
```xs
|
|
1152
|
-
return {
|
|
1153
|
-
value = $calculation_result
|
|
1154
|
-
}
|
|
1155
|
-
```
|
|
1156
|
-
|
|
1157
|
-
Halts the execution of the current function and returns the specified `value` (e.g., `$calculation_result`) as the function’s output. This allows early termination with a result.
|
|
1158
|
-
|
|
1159
|
-
# security.create_auth_token
|
|
1160
|
-
|
|
1161
|
-
```xs
|
|
1162
|
-
security.create_auth_token {
|
|
1163
|
-
table = "users"
|
|
1164
|
-
extras = { "role": "admin" }
|
|
1165
|
-
expiration = 86400
|
|
1166
|
-
id = $user_id
|
|
1167
|
-
} as $auth_token
|
|
1168
|
-
```
|
|
1169
|
-
|
|
1170
|
-
Generates an encrypted authentication token linked to a database table (e.g., `users`). The `extras` parameter adds optional data, `expiration` sets validity in seconds (e.g., 86400 for 24 hours), and `id` identifies the user. The token is stored in the variable defined by `as`, here `$auth_token`.
|
|
1171
|
-
|
|
1172
|
-
# security.create_uuid
|
|
1173
|
-
|
|
1174
|
-
```xs
|
|
1175
|
-
security.create_uuid as $unique_id
|
|
1176
|
-
```
|
|
1177
|
-
|
|
1178
|
-
Generates a Universally Unique Identifier (UUID), a random 128-bit value, stored in the variable defined by `as`, here `$unique_id`.
|
|
1179
|
-
|
|
1180
|
-
# security.encrypt
|
|
1181
|
-
|
|
1182
|
-
```xs
|
|
1183
|
-
security.encrypt {
|
|
1184
|
-
data = $sensitive_data
|
|
1185
|
-
algorithm = "aes-256-cbc"
|
|
1186
|
-
key = "encryption_key"
|
|
1187
|
-
iv = "init_vector"
|
|
1188
|
-
} as $encrypted_data
|
|
1189
|
-
```
|
|
1190
|
-
|
|
1191
|
-
Encrypts a payload into binary data using a specified `algorithm` (e.g., `aes-256-cbc`), `key`, and initialization vector (`iv`). The encrypted result is stored in the variable defined by `as`, here `$encrypted_data`.
|
|
1192
|
-
|
|
1193
|
-
# security.create_curve_key
|
|
1194
|
-
|
|
1195
|
-
```xs
|
|
1196
|
-
security.create_curve_key {
|
|
1197
|
-
curve = "P-256"
|
|
1198
|
-
format = "object"
|
|
1199
|
-
} as $crypto_key
|
|
1200
|
-
```
|
|
1201
|
-
|
|
1202
|
-
Generates a cryptographic key using an elliptic curve type (`P-256`, `P-384`, or `P-521`). The `format` parameter sets the output type (e.g., `object`), and the key is stored in the variable defined by `as`, here `$crypto_key`.
|
|
1203
|
-
|
|
1204
|
-
# security.random_bytes
|
|
1205
|
-
|
|
1206
|
-
```xs
|
|
1207
|
-
security.random_bytes {
|
|
1208
|
-
length = 16
|
|
1209
|
-
} as $random_bytes
|
|
1210
|
-
```
|
|
1211
|
-
|
|
1212
|
-
Generates a string of random bytes with the specified `length` (e.g., 16), stored in the variable defined by `as`, here `$random_bytes`.
|
|
1213
|
-
|
|
1214
|
-
# security.create_password
|
|
1215
|
-
|
|
1216
|
-
```xs
|
|
1217
|
-
security.create_password {
|
|
1218
|
-
character_count = 12
|
|
1219
|
-
require_lowercase = true
|
|
1220
|
-
require_uppercase = true
|
|
1221
|
-
require_digit = true
|
|
1222
|
-
require_symbol = false
|
|
1223
|
-
symbol_whitelist = ""
|
|
1224
|
-
} as $generated_password
|
|
1225
|
-
```
|
|
1226
|
-
|
|
1227
|
-
Generates a random password based on rules like `character_count` (e.g., 12) and requirements for lowercase, uppercase, digits, and symbols. The `symbol_whitelist` limits allowed symbols. The password is stored in the variable defined by `as`, here `$generated_password`.
|
|
1228
|
-
|
|
1229
|
-
# security.decrypt
|
|
1230
|
-
|
|
1231
|
-
```xs
|
|
1232
|
-
security.decrypt {
|
|
1233
|
-
data = $encrypted_data
|
|
1234
|
-
algorithm = "aes-256-cbc"
|
|
1235
|
-
key = "encryption_key"
|
|
1236
|
-
iv = "init_vector"
|
|
1237
|
-
} as $decrypted_data
|
|
1238
|
-
```
|
|
1239
|
-
|
|
1240
|
-
Decrypts a payload back to its original form using the specified `algorithm` (e.g., `aes-256-cbc`), `key`, and initialization vector (`iv`). The decrypted result is stored in the variable defined by `as`, here `$decrypted_data`.
|
|
1241
|
-
|
|
1242
|
-
# security.jwe_decode
|
|
1243
|
-
|
|
1244
|
-
```xs
|
|
1245
|
-
security.jwe_decode {
|
|
1246
|
-
token = $jwe_token
|
|
1247
|
-
key = "decryption_key"
|
|
1248
|
-
check_claims = { "iss": "my_app" }
|
|
1249
|
-
key_algorithm = "A256KW"
|
|
1250
|
-
content_algorithm = "A256GCM"
|
|
1251
|
-
timeDrift = 0
|
|
1252
|
-
} as $decoded_payload
|
|
1253
|
-
```
|
|
1254
|
-
|
|
1255
|
-
Decodes a JSON Web Encryption (JWE) token using the `key`, specified `key_algorithm` (e.g., `A256KW`), and `content_algorithm` (e.g., `A256GCM`). Optional `check_claims` validates token claims, and `timeDrift` adjusts time validation. The result is stored in the variable defined by `as`, here `$decoded_payload`.
|
|
1256
|
-
|
|
1257
|
-
# security.jws_encode
|
|
1258
|
-
|
|
1259
|
-
```xs
|
|
1260
|
-
security.jws_encode {
|
|
1261
|
-
headers = { "alg": "HS256" }
|
|
1262
|
-
claims = { "user_id": "123" }
|
|
1263
|
-
key = "signing_key"
|
|
1264
|
-
signature_algorithm = "HS256"
|
|
1265
|
-
ttl = 3600
|
|
1266
|
-
} as $signed_token
|
|
1267
|
-
```
|
|
1268
|
-
|
|
1269
|
-
Encodes a payload as a JSON Web Signature (JWS) token with `headers`, `claims`, and a `key`. The `signature_algorithm` (e.g., `HS256`) signs the token, and `ttl` sets its validity in seconds (e.g., 3600). The token is stored in the variable defined by `as`, here `$signed_token`.
|
|
1270
|
-
|
|
1271
|
-
# security.jws_decode
|
|
1272
|
-
|
|
1273
|
-
```xs
|
|
1274
|
-
security.jws_decode {
|
|
1275
|
-
token = $jws_token
|
|
1276
|
-
key = "signing_key"
|
|
1277
|
-
check_claims = { "user_id": "123" }
|
|
1278
|
-
signature_algorithm = "HS256"
|
|
1279
|
-
timeDrift = 0
|
|
1280
|
-
} as $verified_payload
|
|
1281
|
-
```
|
|
1282
|
-
|
|
1283
|
-
Decodes a JSON Web Signature (JWS) token using the `key` and `signature_algorithm` (e.g., `HS256`). Optional `check_claims` verifies token claims, and `timeDrift` adjusts time validation. The payload is stored in the variable defined by `as`, here `$verified_payload`.
|
|
1284
|
-
|
|
1285
|
-
# security.jwe_encode
|
|
1286
|
-
|
|
1287
|
-
```xs
|
|
1288
|
-
security.jwe_encode {
|
|
1289
|
-
headers = { "alg": "A256KW" }
|
|
1290
|
-
claims = { "data": "secret" }
|
|
1291
|
-
key = "encryption_key"
|
|
1292
|
-
key_algorithm = "A256KW"
|
|
1293
|
-
content_algorithm = "A256GCM"
|
|
1294
|
-
ttl = 0
|
|
1295
|
-
} as $encrypted_token
|
|
1296
|
-
```
|
|
1297
|
-
|
|
1298
|
-
Encodes a payload as a JSON Web Encryption (JWE) token with `headers`, `claims`, and a `key`. The `key_algorithm` (e.g., `A256KW`) and `content_algorithm` (e.g., `A256GCM`) secure the token, and `ttl` sets its validity (0 for no expiration). The token is stored in the variable defined by `as`, here `$encrypted_token`.
|
|
1299
|
-
|
|
1300
|
-
# security.create_secret_key
|
|
1301
|
-
|
|
1302
|
-
```xs
|
|
1303
|
-
security.create_secret_key {
|
|
1304
|
-
bits = 2048
|
|
1305
|
-
format = "object"
|
|
1306
|
-
} as $secret_key
|
|
1307
|
-
```
|
|
1308
|
-
|
|
1309
|
-
Generates a secret key for digital signatures or symmetric encryption with the specified `bits` (e.g., 2048) and `format` (e.g., `object`). The key is stored in the variable defined by `as`, here `$secret_key`.
|
|
1310
|
-
|
|
1311
|
-
# security.random_number
|
|
1312
|
-
|
|
1313
|
-
```xs
|
|
1314
|
-
security.random_number {
|
|
1315
|
-
min = 1
|
|
1316
|
-
max = 100
|
|
1317
|
-
} as $random_value
|
|
1318
|
-
```
|
|
1319
|
-
|
|
1320
|
-
Generates a random number between `min` and `max` (e.g., 1 to 100), stored in the variable defined by `as`, here `$random_value`.
|
|
1321
|
-
|
|
1322
|
-
# security.check_password
|
|
1323
|
-
|
|
1324
|
-
```xs
|
|
1325
|
-
security.check_password {
|
|
1326
|
-
text_password = $user_input_password
|
|
1327
|
-
hash_password = $stored_password_hash
|
|
1328
|
-
} as $is_valid
|
|
1329
|
-
```
|
|
1330
|
-
|
|
1331
|
-
Verifies if a plain-text password (e.g., `$user_input_password`) matches a hashed password (e.g., `$stored_password_hash`). Returns `true` if they match, `false` otherwise, stored in the variable defined by `as`, here `$is_valid`.
|
|
1332
|
-
|
|
1333
|
-
# stream.from_jsonl
|
|
1334
|
-
|
|
1335
|
-
```xs
|
|
1336
|
-
stream.from_jsonl {
|
|
1337
|
-
value = $jsonl_file
|
|
1338
|
-
} as $jsonl_stream
|
|
1339
|
-
```
|
|
1340
|
-
|
|
1341
|
-
Parses a JSONL (JSON Lines) file resource and streams its row data. The `value` parameter specifies the JSONL file to process, and the resulting stream is stored in the variable defined by `as`, here `$jsonl_stream`.
|
|
1342
|
-
|
|
1343
|
-
# storage.create_file_resource
|
|
1344
|
-
|
|
1345
|
-
```xs
|
|
1346
|
-
storage.create_file_resource {
|
|
1347
|
-
filename = "report.txt"
|
|
1348
|
-
filedata = $report_content
|
|
1349
|
-
} as $new_file
|
|
1350
|
-
```
|
|
1351
|
-
|
|
1352
|
-
Creates a new file with the specified `filename` and `filedata` content. The created file resource is stored in the variable specified by `as`, here `$new_file`, for further use.
|
|
1353
|
-
|
|
1354
|
-
# storage.sign_private_url
|
|
1355
|
-
|
|
1356
|
-
```xs
|
|
1357
|
-
storage.sign_private_url {
|
|
1358
|
-
pathname = "documents/secret.pdf"
|
|
1359
|
-
ttl = 60
|
|
1360
|
-
} as $signed_url
|
|
1361
|
-
```
|
|
1362
|
-
|
|
1363
|
-
Generates a signed URL for a private file at the specified `pathname`, allowing temporary access for a duration defined by `ttl` (in seconds). The signed URL is stored in the variable defined by `as`, here `$signed_url`.
|
|
1364
|
-
|
|
1365
|
-
# storage.create_attachment
|
|
1366
|
-
|
|
1367
|
-
```xs
|
|
1368
|
-
storage.create_attachment {
|
|
1369
|
-
value = $input.attachment
|
|
1370
|
-
access= "public"
|
|
1371
|
-
filename = "attachment.pdf"
|
|
1372
|
-
} as $attachment_metadata
|
|
1373
|
-
```
|
|
1374
|
-
|
|
1375
|
-
Creates attachment metadata from a file resource specified by `value`, with the given `filename`. The `access` parameter determines if the attachment is `public` or `private`. The metadata is stored in the variable specified by `as`, here `$attachment_metadata`.
|
|
1376
|
-
|
|
1377
|
-
# storage.delete_file
|
|
1378
|
-
|
|
1379
|
-
```xs
|
|
1380
|
-
storage.delete_file {
|
|
1381
|
-
pathname = "temp/data.csv"
|
|
1382
|
-
}
|
|
1383
|
-
```
|
|
1384
|
-
|
|
1385
|
-
Deletes a file from storage at the specified `pathname`. This removes the file permanently from the storage system.
|
|
1386
|
-
|
|
1387
|
-
# storage.read_file_resource
|
|
1388
|
-
|
|
1389
|
-
```xs
|
|
1390
|
-
storage.read_file_resource {
|
|
1391
|
-
value = $input.file
|
|
1392
|
-
} as $file_content
|
|
1393
|
-
```
|
|
1394
|
-
|
|
1395
|
-
Retrieves the raw data from a file resource specified by `value`. The content of the file is stored in the variable defined by `as`, here `$file_content`.
|
|
1396
|
-
|
|
1397
|
-
# storage.create_image
|
|
1398
|
-
|
|
1399
|
-
```xs
|
|
1400
|
-
storage.create_image {
|
|
1401
|
-
value = $input.image
|
|
1402
|
-
access="public"
|
|
1403
|
-
filename = "profile.jpg"
|
|
1404
|
-
} as $image_metadata
|
|
1405
|
-
```
|
|
1406
|
-
|
|
1407
|
-
Creates image metadata from a file resource specified by `value`, with the given `filename`. The `access` parameter sets the image as `public` or `private`. The metadata is stored in the variable specified by `as`, here `$image_metadata`.
|
|
1408
|
-
|
|
1409
|
-
# stream.from_csv
|
|
1410
|
-
|
|
1411
|
-
```xs
|
|
1412
|
-
stream.from_csv {
|
|
1413
|
-
value = $csv_file
|
|
1414
|
-
separator = ","
|
|
1415
|
-
enclosure = "'"
|
|
1416
|
-
escape_char = "'"
|
|
1417
|
-
} as $csv_stream
|
|
1418
|
-
```
|
|
1419
|
-
|
|
1420
|
-
Parses a CSV file resource and streams its row data. The `value` parameter specifies the CSV file, while `separator`, `enclosure`, and `escape_char` define the CSV format. The resulting stream is stored in the variable defined by `as`, here `$csv_stream`.
|
|
1421
|
-
|
|
1422
|
-
# stream.from_request
|
|
1423
|
-
|
|
1424
|
-
```xs
|
|
1425
|
-
stream.from_request {
|
|
1426
|
-
url = "http://example.com/api/v1"
|
|
1427
|
-
method = "GET"
|
|
1428
|
-
params = {}|set:"filter":"active"
|
|
1429
|
-
headers = []|push:"Authorization: Bearer token123"
|
|
1430
|
-
timeout = 15
|
|
1431
|
-
follow_location = true
|
|
1432
|
-
} as $api_stream
|
|
1433
|
-
```
|
|
1434
|
-
|
|
1435
|
-
Converts an external HTTP request into a streaming API response, returning the data as an array. It supports various HTTP methods, query parameters, headers, a `timeout` (in seconds), and an option to `follow_location` for redirects. The stream is stored in the variable specified by `as`, here `$api_stream`.
|
|
1436
|
-
|
|
1437
|
-
# switch
|
|
1438
|
-
|
|
1439
|
-
```xs
|
|
1440
|
-
switch ($user_status) {
|
|
1441
|
-
case ("active") {
|
|
1442
|
-
return {
|
|
1443
|
-
value = "User is active"
|
|
1444
|
-
}
|
|
1445
|
-
} break
|
|
1446
|
-
case ("inactive") {
|
|
1447
|
-
return {
|
|
1448
|
-
value = "User is inactive"
|
|
1449
|
-
}
|
|
1450
|
-
} break
|
|
1451
|
-
default {
|
|
1452
|
-
return {
|
|
1453
|
-
value = "User status unknown"
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
```
|
|
1458
|
-
|
|
1459
|
-
Implements switch-case logic to control script flow based on the value of a variable (e.g., `$user_status`). It evaluates the variable against each `case`, executing the corresponding block if a match is found, or the `default` block if no matches occur.
|
|
1460
|
-
|
|
1461
|
-
# text.starts_with
|
|
1462
|
-
|
|
1463
|
-
```xs
|
|
1464
|
-
text.starts_with $message {
|
|
1465
|
-
value = "Hello"
|
|
1466
|
-
} as $starts_with_hello
|
|
1467
|
-
```
|
|
1468
|
-
|
|
1469
|
-
Checks if a text string (e.g., `$message`) begins with the specified `value` (e.g., `"Hello"`). Returns `true` if it does, `false` otherwise, and stores the result in the variable defined by `as`, here `$starts_with_hello`.
|
|
1470
|
-
|
|
1471
|
-
# text.icontains
|
|
1472
|
-
|
|
1473
|
-
```xs
|
|
1474
|
-
text.icontains $description {
|
|
1475
|
-
value = "error"
|
|
1476
|
-
} as $has_error
|
|
1477
|
-
```
|
|
1478
|
-
|
|
1479
|
-
Performs a case-insensitive check to see if a text string (e.g., `$description`) contains the specified `value` (e.g., `"error"`). Returns `true` if found, `false` otherwise, and stores the result in `$has_error`.
|
|
1480
|
-
|
|
1481
|
-
# text.ltrim
|
|
1482
|
-
|
|
1483
|
-
```xs
|
|
1484
|
-
text.ltrim $user_input {
|
|
1485
|
-
value = " "
|
|
1486
|
-
}
|
|
1487
|
-
```
|
|
1488
|
-
|
|
1489
|
-
Removes leading characters (default is whitespace, or as specified by `value`) from a text string (e.g., `$user_input`). Updates the variable with the trimmed result, useful for cleaning up user input.
|
|
1490
|
-
|
|
1491
|
-
# text.rtrim
|
|
1492
|
-
|
|
1493
|
-
```xs
|
|
1494
|
-
text.rtrim $user_input {
|
|
1495
|
-
value = " "
|
|
1496
|
-
}
|
|
1497
|
-
```
|
|
1498
|
-
|
|
1499
|
-
Removes trailing characters (default is whitespace, or as specified by `value`) from a text string (e.g., `$user_input`). Updates the variable with the trimmed result, ensuring no unwanted trailing characters remain.
|
|
1500
|
-
|
|
1501
|
-
# text.append
|
|
1502
|
-
|
|
1503
|
-
```xs
|
|
1504
|
-
text.append $greeting {
|
|
1505
|
-
value = ", welcome!"
|
|
1506
|
-
}
|
|
1507
|
-
```
|
|
1508
|
-
|
|
1509
|
-
Adds the specified `value` (e.g., `", welcome!"`) to the end of a text string (e.g., `$greeting`). Updates the variable with the new concatenated string, useful for building messages.
|
|
1510
|
-
|
|
1511
|
-
# text.istarts_with
|
|
1512
|
-
|
|
1513
|
-
```xs
|
|
1514
|
-
text.istarts_with $title {
|
|
1515
|
-
value = "intro"
|
|
1516
|
-
} as $starts_with_intro
|
|
1517
|
-
```
|
|
1518
|
-
|
|
1519
|
-
Performs a case-insensitive check to see if a text string (e.g., `$title`) starts with the specified `value` (e.g., `"intro"`). Returns `true` if it does, `false` otherwise, and stores the result in `$starts_with_intro`.
|
|
1520
|
-
|
|
1521
|
-
# text.iends_with
|
|
1522
|
-
|
|
1523
|
-
```xs
|
|
1524
|
-
text.iends_with $filename {
|
|
1525
|
-
value = "pdf"
|
|
1526
|
-
} as $ends_with_pdf
|
|
1527
|
-
```
|
|
1528
|
-
|
|
1529
|
-
Performs a case-insensitive check to see if a text string (e.g., `$filename`) ends with the specified `value` (e.g., `"pdf"`). Returns `true` if it does, `false` otherwise, and stores the result in `$ends_with_pdf`.
|
|
1530
|
-
|
|
1531
|
-
# text.ends_with
|
|
1532
|
-
|
|
1533
|
-
```xs
|
|
1534
|
-
text.ends_with $url {
|
|
1535
|
-
value = ".com"
|
|
1536
|
-
} as $is_com_domain
|
|
1537
|
-
```
|
|
1538
|
-
|
|
1539
|
-
Checks if a text string (e.g., `$url`) ends with the specified `value` (e.g., `".com"`). Returns `true` if it does, `false` otherwise, and stores the result in `$is_com_domain`.
|
|
1540
|
-
|
|
1541
|
-
# text.prepend
|
|
1542
|
-
|
|
1543
|
-
```xs
|
|
1544
|
-
text.prepend $message {
|
|
1545
|
-
value = "Alert: "
|
|
1546
|
-
}
|
|
1547
|
-
```
|
|
1548
|
-
|
|
1549
|
-
Adds the specified `value` (e.g., `"Alert: "`) to the beginning of a text string (e.g., `$message`). Updates the variable with the new concatenated string, useful for adding prefixes.
|
|
1550
|
-
|
|
1551
|
-
# text.contains
|
|
1552
|
-
|
|
1553
|
-
```xs
|
|
1554
|
-
text.contains $log_entry {
|
|
1555
|
-
value = "error"
|
|
1556
|
-
} as $has_error
|
|
1557
|
-
```
|
|
1558
|
-
|
|
1559
|
-
Checks if a text string (e.g., `$log_entry`) contains the specified `value` (e.g., `"error"`). Returns `true` if found, `false` otherwise, and stores the result in `$has_error`.
|
|
1560
|
-
|
|
1561
|
-
# text.trim
|
|
1562
|
-
|
|
1563
|
-
```xs
|
|
1564
|
-
text.trim $user_input {
|
|
1565
|
-
value = " "
|
|
1566
|
-
}
|
|
1567
|
-
```
|
|
1568
|
-
|
|
1569
|
-
Removes characters (default is whitespace, or as specified by `value`) from both the beginning and end of a text string (e.g., `$user_input`). Updates the variable with the trimmed result, ensuring clean text.
|
|
1570
|
-
|
|
1571
|
-
# throw
|
|
1572
|
-
|
|
1573
|
-
```xs
|
|
1574
|
-
throw {
|
|
1575
|
-
name = "ValidationError"
|
|
1576
|
-
value = "Invalid user input provided"
|
|
1577
|
-
}
|
|
1578
|
-
```
|
|
1579
|
-
|
|
1580
|
-
Throws an error and halts the script’s execution immediately. The `name` parameter specifies the error type (e.g., `"ValidationError"`), and `value` provides a custom error message to describe the issue.
|
|
1581
|
-
|
|
1582
|
-
# try_catch
|
|
1583
|
-
|
|
1584
|
-
```xs
|
|
1585
|
-
try_catch {
|
|
1586
|
-
try {
|
|
1587
|
-
function.run "divide_fn" {
|
|
1588
|
-
input = { a: 10, b: 0 }
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
catch {
|
|
1592
|
-
debug.log {
|
|
1593
|
-
value = "Error occurred: division by zero"
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
finally {
|
|
1597
|
-
debug.log {
|
|
1598
|
-
value = "Operation completed"
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
```
|
|
1603
|
-
|
|
1604
|
-
Executes a block of code in the `try` section, catching any errors in the `catch` block for error handling (e.g., logging the error). The optional `finally` block runs regardless of success or failure, useful for cleanup tasks.
|
|
1605
|
-
|
|
1606
|
-
# util.send_email
|
|
1607
|
-
|
|
1608
|
-
```xs
|
|
1609
|
-
util.send_email {
|
|
1610
|
-
api_key = $env.secret_key
|
|
1611
|
-
service_provider = "resend"
|
|
1612
|
-
subject = "hellow"
|
|
1613
|
-
message = "Hey there"
|
|
1614
|
-
to = "some_email@xano.com"
|
|
1615
|
-
bcc = []|push:"foo@goo.com"
|
|
1616
|
-
cc = ["me@me.com", "john@be.com"]
|
|
1617
|
-
from = "admin@xano.com"
|
|
1618
|
-
reply_to = "no-reply@xano.com"
|
|
1619
|
-
scheduled_at = "2025-11-26T01:01:02.00"
|
|
1620
|
-
} as $xano_email
|
|
1621
|
-
```
|
|
1622
|
-
|
|
1623
|
-
Sends an email using the specified `"resend"`, with parameters like `subject`, `message`, `to`, `from`, and optional fields such as `bcc`, `cc`, `reply_to`, and `scheduled_at`. The result of the email operation is stored in the variable defined by `as`, here `$xano_email`. Currently, Xano only supports the Resend email service provider.
|
|
1624
|
-
|
|
1625
|
-
Xano also offers a built-in email service that can be used without an external provider for testing purposes, all emails using the `xano` service provider will be routed to the admin email address.
|
|
1626
|
-
|
|
1627
|
-
```xs
|
|
1628
|
-
util.send_email {
|
|
1629
|
-
service_provider = "xano"
|
|
1630
|
-
subject = "hellow"
|
|
1631
|
-
message = "Hey there"
|
|
1632
|
-
} as $xano_email
|
|
1633
|
-
```
|
|
1634
|
-
|
|
1635
|
-
# util.template_engine
|
|
1636
|
-
|
|
1637
|
-
```xs
|
|
1638
|
-
util.template_engine {
|
|
1639
|
-
value = """
|
|
1640
|
-
Hello, {{ $input.name|capitalize }}!
|
|
1641
|
-
Your favorite colors are:
|
|
1642
|
-
{% for color in $var.colors %}
|
|
1643
|
-
- {{ color|upper }}
|
|
1644
|
-
{% endfor %}
|
|
1645
|
-
"""
|
|
1646
|
-
} as $rendered_template
|
|
1647
|
-
```
|
|
1648
|
-
|
|
1649
|
-
Renders a template using the TWIG templating engine, allowing for dynamic content generation. The `value` parameter contains the template string, which can include variables and logic. Variables from the current XanoScript context (e.g., `$var`, `$input`) are automatically available within the template.
|
|
1650
|
-
|
|
1651
|
-
The engine supports standard TWIG syntax, including variables (`{{ ... }}`), control structures (`{% ... %}`), and filters.
|
|
1652
|
-
|
|
1653
|
-
The template engine is useful for HTML pages, AI prompts, SQL query templates, text and Markdown documents, and other dynamic templates.
|
|
1654
|
-
|
|
1655
|
-
# util.set_header
|
|
1656
|
-
|
|
1657
|
-
```xs
|
|
1658
|
-
util.set_header {
|
|
1659
|
-
value = "Set-Cookie: sessionId=e8bb43229de9; HttpOnly; Secure; Domain=foo.example.com"
|
|
1660
|
-
duplicates = "replace"
|
|
1661
|
-
}
|
|
1662
|
-
```
|
|
1663
|
-
|
|
1664
|
-
Adds a header to the response, specified by `value` (e.g., a cookie header). The `duplicates` parameter determines how to handle duplicate headers, such as `"replace"` to overwrite existing ones.
|
|
1665
|
-
|
|
1666
|
-
# util.get_env
|
|
1667
|
-
|
|
1668
|
-
```xs
|
|
1669
|
-
util.get_env as $environment_vars
|
|
1670
|
-
```
|
|
1671
|
-
|
|
1672
|
-
Retrieves all environment variables available in the script’s context and stores them in the variable specified by `as`, here `$environment_vars`. Useful for accessing system-wide settings.
|
|
1673
|
-
|
|
1674
|
-
# util.get_all_input
|
|
1675
|
-
|
|
1676
|
-
```xs
|
|
1677
|
-
util.get_all_input as $input_data
|
|
1678
|
-
```
|
|
1679
|
-
|
|
1680
|
-
Captures all parsed input data sent to the script’s context and stores it in the variable specified by `as`, here `$input_data`. This provides a structured view of input parameters.
|
|
1681
|
-
|
|
1682
|
-
# util.get_input
|
|
1683
|
-
|
|
1684
|
-
```xs
|
|
1685
|
-
util.get_input as $raw_input
|
|
1686
|
-
```
|
|
1687
|
-
|
|
1688
|
-
Retrieves the raw, unparsed input data for the request and stores it in the variable specified by `as`, here `$raw_input`. This is useful for accessing the original request data before processing.
|
|
1689
|
-
|
|
1690
|
-
# util.sleep
|
|
1691
|
-
|
|
1692
|
-
```xs
|
|
1693
|
-
util.sleep {
|
|
1694
|
-
value = 5
|
|
1695
|
-
}
|
|
1696
|
-
```
|
|
1697
|
-
|
|
1698
|
-
Pauses script execution for the specified number of seconds in `value` (e.g., 5 seconds). This can be used to introduce delays between operations.
|
|
1699
|
-
|
|
1700
|
-
# util.ip_lookup
|
|
1701
|
-
|
|
1702
|
-
```xs
|
|
1703
|
-
util.ip_lookup {
|
|
1704
|
-
value = "123.234.99.22"
|
|
1705
|
-
} as $location
|
|
1706
|
-
```
|
|
1707
|
-
|
|
1708
|
-
Retrieves the geographic location of an IP address specified in `value`. The location data (e.g., city, country) is stored in the variable defined by `as`, here `$location`.
|
|
1709
|
-
|
|
1710
|
-
# util.geo_distance
|
|
1711
|
-
|
|
1712
|
-
```xs
|
|
1713
|
-
util.geo_distance {
|
|
1714
|
-
latitude_1 = 40.71
|
|
1715
|
-
longitude_1 = 74
|
|
1716
|
-
latitude_2 = 48.86
|
|
1717
|
-
longitude_2 = 2.35
|
|
1718
|
-
} as $distance
|
|
1719
|
-
```
|
|
1720
|
-
|
|
1721
|
-
Calculates the distance between two geographic points, specified by their `latitude_1`, `longitude_1` (first point) and `latitude_2`, `longitude_2` (second point). The computed distance is stored in the variable defined by `as`, here `$distance`.
|
|
1722
|
-
|
|
1723
|
-
# while
|
|
1724
|
-
|
|
1725
|
-
```xs
|
|
1726
|
-
while (`$retry_count < 5`) {
|
|
1727
|
-
each {
|
|
1728
|
-
var.update $retry_count {
|
|
1729
|
-
value = `$retry_count + 1`
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
```
|
|
1734
|
-
|
|
1735
|
-
Continuously loops through a block of code as long as the specified condition (e.g., `$retry_count < 5`) evaluates to `true`. The `each` block contains the actions to repeat until the condition becomes `false`.
|
|
1736
|
-
|
|
1737
|
-
# zip.create_archive
|
|
1738
|
-
|
|
1739
|
-
```xs
|
|
1740
|
-
zip.create_archive {
|
|
1741
|
-
filename = "backup.zip"
|
|
1742
|
-
} as $zip_archive
|
|
1743
|
-
```
|
|
1744
|
-
|
|
1745
|
-
Creates a new compressed zip archive with the specified `filename`. The created zip file resource is stored in the variable defined by `as`, here `$zip_archive`, for further use.
|
|
1746
|
-
|
|
1747
|
-
# zip.add_to_archive
|
|
1748
|
-
|
|
1749
|
-
```xs
|
|
1750
|
-
zip.add_to_archive {
|
|
1751
|
-
file = $input.file
|
|
1752
|
-
zip = $zip_archive
|
|
1753
|
-
}
|
|
1754
|
-
```
|
|
1755
|
-
|
|
1756
|
-
Adds a file (specified by `file`) to an existing zip archive (specified by `zip`). This updates the zip archive with the new file content.
|
|
1757
|
-
|
|
1758
|
-
# zip.delete_from_archive
|
|
1759
|
-
|
|
1760
|
-
```xs
|
|
1761
|
-
zip.delete_from_archive {
|
|
1762
|
-
filename = $input.file
|
|
1763
|
-
zip = $input.file
|
|
1764
|
-
}
|
|
1765
|
-
```
|
|
1766
|
-
|
|
1767
|
-
Removes a file (specified by `filename`) from an existing zip archive (specified by `zip`). This deletes the file from the archive without affecting other contents.
|
|
1768
|
-
|
|
1769
|
-
# zip.extract
|
|
1770
|
-
|
|
1771
|
-
```xs
|
|
1772
|
-
zip.extract {
|
|
1773
|
-
zip = $zip_archive
|
|
1774
|
-
} as $extracted_files
|
|
1775
|
-
```
|
|
1776
|
-
|
|
1777
|
-
Extracts the contents of a zip archive (specified by `zip`) into individual files. The extracted files are stored in the variable defined by `as`, here `$extracted_files`.
|
|
1778
|
-
|
|
1779
|
-
# zip.view_contents
|
|
1780
|
-
|
|
1781
|
-
```xs
|
|
1782
|
-
zip.view_contents {
|
|
1783
|
-
zip = $input.file
|
|
1784
|
-
} as $archive_contents
|
|
1785
|
-
```
|
|
1786
|
-
|
|
1787
|
-
Lists the contents of a zip archive (specified by `zip`), providing details such as file names within the archive. The list is stored in the variable defined by `as`, here `$archive_contents`.
|
|
1788
|
-
|
|
1789
|
-
# cloud.azure.storage.sign_url
|
|
1790
|
-
|
|
1791
|
-
```xs
|
|
1792
|
-
cloud.azure.storage.sign_url {
|
|
1793
|
-
account_name = "my_storage_account"
|
|
1794
|
-
account_key = "my_secret_key"
|
|
1795
|
-
container_name = "documents"
|
|
1796
|
-
path = "reports/annual.pdf"
|
|
1797
|
-
ttl = 300
|
|
1798
|
-
} as $document_access_url
|
|
1799
|
-
```
|
|
1800
|
-
|
|
1801
|
-
Generates a signed URL for securely accessing a blob in Azure Blob Storage. The URL remains valid for the duration specified by `ttl` (in seconds), allowing temporary access to the file, and is stored in a variable for later use.
|
|
1802
|
-
|
|
1803
|
-
# cloud.aws.s3.sign_url
|
|
1804
|
-
|
|
1805
|
-
```xs
|
|
1806
|
-
cloud.aws.s3.sign_url {
|
|
1807
|
-
bucket = "company_assets"
|
|
1808
|
-
region = "us-east-1"
|
|
1809
|
-
key = "my_aws_key"
|
|
1810
|
-
secret = "my_aws_secret"
|
|
1811
|
-
file_key = "images/logo.png"
|
|
1812
|
-
ttl = 300
|
|
1813
|
-
} as $logo_access_url
|
|
1814
|
-
```
|
|
1815
|
-
|
|
1816
|
-
Creates a signed URL for accessing an object in an AWS S3 bucket, providing temporary access for the time set by `ttl` (in seconds). The URL is stored in the specified variable.
|
|
1817
|
-
|
|
1818
|
-
# cloud.aws.s3.list_directory
|
|
1819
|
-
|
|
1820
|
-
```xs
|
|
1821
|
-
cloud.aws.s3.list_directory {
|
|
1822
|
-
bucket = "media_library"
|
|
1823
|
-
region = "us-west-2"
|
|
1824
|
-
key = "my_aws_key"
|
|
1825
|
-
secret = "my_aws_secret"
|
|
1826
|
-
prefix = "videos/"
|
|
1827
|
-
next_page_token = $previous_page_token
|
|
1828
|
-
} as $video_list
|
|
1829
|
-
```
|
|
1830
|
-
|
|
1831
|
-
Lists the contents of an AWS S3 bucket, optionally filtered by a `prefix`, with support for pagination via `next_page_token`. The resulting list is stored in the specified variable.
|
|
1832
|
-
|
|
1833
|
-
# cloud.google.storage.upload_file
|
|
1834
|
-
|
|
1835
|
-
```xs
|
|
1836
|
-
cloud.google.storage.upload_file {
|
|
1837
|
-
service_account = "my_service_account_json"
|
|
1838
|
-
bucket = "user_uploads"
|
|
1839
|
-
filePath = "photos/vacation.jpg"
|
|
1840
|
-
file = $uploaded_image
|
|
1841
|
-
metadata = { "description": "Beach vacation photo" }
|
|
1842
|
-
}
|
|
1843
|
-
```
|
|
1844
|
-
|
|
1845
|
-
Uploads a file to Google Cloud Storage at the specified `filePath` in a bucket, with optional `metadata` for additional details.
|
|
1846
|
-
|
|
1847
|
-
# cloud.elasticsearch.request
|
|
1848
|
-
|
|
1849
|
-
```xs
|
|
1850
|
-
cloud.elasticsearch.request {
|
|
1851
|
-
auth_type = "API Key"
|
|
1852
|
-
key_id = "my_key_id"
|
|
1853
|
-
access_key = "my_access_key"
|
|
1854
|
-
method = "GET"
|
|
1855
|
-
url = "https://my-elastic-cluster.com/posts/_search"
|
|
1856
|
-
payload = { "query": { "match": { "category": "tech" } } }
|
|
1857
|
-
} as $search_results
|
|
1858
|
-
```
|
|
1859
|
-
|
|
1860
|
-
Sends an HTTP request to an Elastic Search cluster, executing the specified `method` with an optional `payload`. The response is stored in the given variable.
|
|
1861
|
-
|
|
1862
|
-
# cloud.azure.storage.list_directory
|
|
1863
|
-
|
|
1864
|
-
```xs
|
|
1865
|
-
cloud.azure.storage.list_directory {
|
|
1866
|
-
account_name = "my_storage_account"
|
|
1867
|
-
account_key = "my_secret_key"
|
|
1868
|
-
container_name = "archives"
|
|
1869
|
-
path = "2023/"
|
|
1870
|
-
} as $yearly_archives
|
|
1871
|
-
```
|
|
1872
|
-
|
|
1873
|
-
Lists the contents of an Azure Blob Storage container, optionally filtered by a `path`. The list is stored in the specified variable.
|
|
1874
|
-
|
|
1875
|
-
# cloud.aws.opensearch.document
|
|
1876
|
-
|
|
1877
|
-
```xs
|
|
1878
|
-
cloud.aws.opensearch.document {
|
|
1879
|
-
auth_type = "IAM"
|
|
1880
|
-
key_id = "my_aws_key"
|
|
1881
|
-
access_key = "my_aws_secret"
|
|
1882
|
-
region = "us-east-1"
|
|
1883
|
-
base_url = "https://my-opensearch-domain.com"
|
|
1884
|
-
index = "articles"
|
|
1885
|
-
method = "POST"
|
|
1886
|
-
doc_id = "article_123"
|
|
1887
|
-
} as $article_response
|
|
1888
|
-
```
|
|
1889
|
-
|
|
1890
|
-
Manages records (e.g., create, read, update, delete) in an AWS OpenSearch index using the specified `method`. The response is stored in the given variable.
|
|
1891
|
-
|
|
1892
|
-
# cloud.elasticsearch.document
|
|
1893
|
-
|
|
1894
|
-
```xs
|
|
1895
|
-
cloud.elasticsearch.document {
|
|
1896
|
-
auth_type = "API Key"
|
|
1897
|
-
key_id = "my_key_id"
|
|
1898
|
-
access_key = "my_access_key"
|
|
1899
|
-
base_url = "https://my-elastic-cluster.com"
|
|
1900
|
-
index = "users"
|
|
1901
|
-
method = "GET"
|
|
1902
|
-
doc_id = "user_456"
|
|
1903
|
-
} as $user_profile
|
|
1904
|
-
```
|
|
1905
|
-
|
|
1906
|
-
Manages records in an Elastic Search index (e.g., create, read, update, delete) with the specified `method`. The response is stored in the given variable.
|
|
1907
|
-
|
|
1908
|
-
# cloud.aws.s3.read_file
|
|
1909
|
-
|
|
1910
|
-
```xs
|
|
1911
|
-
cloud.aws.s3.read_file {
|
|
1912
|
-
bucket = "app_resources"
|
|
1913
|
-
region = "us-west-2"
|
|
1914
|
-
key = "my_aws_key"
|
|
1915
|
-
secret = "my_aws_secret"
|
|
1916
|
-
file_key = "configs/settings.json"
|
|
1917
|
-
} as $app_settings_file
|
|
1918
|
-
```
|
|
1919
|
-
|
|
1920
|
-
Reads a file from an AWS S3 bucket and stores its contents in a variable as a file resource.
|
|
1921
|
-
|
|
1922
|
-
# cloud.azure.storage.delete_file
|
|
1923
|
-
|
|
1924
|
-
```xs
|
|
1925
|
-
cloud.azure.storage.delete_file {
|
|
1926
|
-
account_name = "my_storage_account"
|
|
1927
|
-
account_key = "my_secret_key"
|
|
1928
|
-
container_name = "temp_files"
|
|
1929
|
-
filePath = "drafts/old_draft.docx"
|
|
1930
|
-
}
|
|
1931
|
-
```
|
|
1932
|
-
|
|
1933
|
-
Deletes a blob from an Azure Blob Storage container at the specified `filePath`.
|
|
1934
|
-
|
|
1935
|
-
# cloud.aws.s3.delete_file
|
|
1936
|
-
|
|
1937
|
-
```xs
|
|
1938
|
-
cloud.aws.s3.delete_file {
|
|
1939
|
-
bucket = "user_backups"
|
|
1940
|
-
region = "us-east-1"
|
|
1941
|
-
key = "my_aws_key"
|
|
1942
|
-
secret = "my_aws_secret"
|
|
1943
|
-
file_key = "backups/2023-01.zip"
|
|
1944
|
-
}
|
|
1945
|
-
```
|
|
1946
|
-
|
|
1947
|
-
Deletes an object from an AWS S3 bucket at the specified `file_key`.
|
|
1948
|
-
|
|
1949
|
-
# cloud.google.storage.read_file
|
|
1950
|
-
|
|
1951
|
-
```xs
|
|
1952
|
-
cloud.google.storage.read_file {
|
|
1953
|
-
service_account = "my_service_account_json"
|
|
1954
|
-
bucket = "app_data"
|
|
1955
|
-
filePath = "logs/error_log.txt"
|
|
1956
|
-
} as $error_log_file
|
|
1957
|
-
```
|
|
1958
|
-
|
|
1959
|
-
Reads a file from Google Cloud Storage and stores its contents in a variable as a file resource.
|
|
1960
|
-
|
|
1961
|
-
# cloud.aws.s3.get_file_info
|
|
1962
|
-
|
|
1963
|
-
```xs
|
|
1964
|
-
cloud.aws.s3.get_file_info {
|
|
1965
|
-
bucket = "product_images"
|
|
1966
|
-
region = "us-east-1"
|
|
1967
|
-
key = "my_aws_key"
|
|
1968
|
-
secret = "my_aws_secret"
|
|
1969
|
-
file_key = "items/shirt.jpg"
|
|
1970
|
-
} as $image_metadata
|
|
1971
|
-
```
|
|
1972
|
-
|
|
1973
|
-
Retrieves metadata (e.g., size, last modified) about an object in an AWS S3 bucket, storing it in a variable.
|
|
1974
|
-
|
|
1975
|
-
# cloud.aws.opensearch.request
|
|
1976
|
-
|
|
1977
|
-
```xs
|
|
1978
|
-
cloud.aws.opensearch.request {
|
|
1979
|
-
auth_type = "IAM"
|
|
1980
|
-
key_id = "my_aws_key"
|
|
1981
|
-
access_key = "my_aws_secret"
|
|
1982
|
-
region = "us-west-2"
|
|
1983
|
-
method = "POST"
|
|
1984
|
-
url = "https://my-opensearch-domain.com/_search"
|
|
1985
|
-
query = { "query": { "term": { "status": "active" } } }
|
|
1986
|
-
} as $active_items
|
|
1987
|
-
```
|
|
1988
|
-
|
|
1989
|
-
Sends a request to AWS OpenSearch with the specified `method` and `query`, storing the response in a variable.
|
|
1990
|
-
|
|
1991
|
-
# cloud.google.storage.list_directory
|
|
1992
|
-
|
|
1993
|
-
```xs
|
|
1994
|
-
cloud.google.storage.list_directory {
|
|
1995
|
-
service_account = "my_service_account_json"
|
|
1996
|
-
bucket = "project_files"
|
|
1997
|
-
path = "designs/"
|
|
1998
|
-
} as $design_files
|
|
1999
|
-
```
|
|
2000
|
-
|
|
2001
|
-
Lists the contents of a Google Cloud Storage bucket, optionally filtered by `path`, storing the result in a variable.
|
|
2002
|
-
|
|
2003
|
-
# cloud.google.storage.sign_url
|
|
2004
|
-
|
|
2005
|
-
```xs
|
|
2006
|
-
cloud.google.storage.sign_url {
|
|
2007
|
-
service_account = "my_service_account_json"
|
|
2008
|
-
bucket = "public_assets"
|
|
2009
|
-
filePath = "downloads/guide.pdf"
|
|
2010
|
-
method = "GET"
|
|
2011
|
-
ttl = 300
|
|
2012
|
-
} as $guide_download_url
|
|
2013
|
-
```
|
|
2014
|
-
|
|
2015
|
-
Generates a signed URL for accessing a file in Google Cloud Storage, valid for `ttl` seconds, with the specified `method`.
|
|
2016
|
-
|
|
2017
|
-
# cloud.google.storage.get_file_info
|
|
2018
|
-
|
|
2019
|
-
```xs
|
|
2020
|
-
cloud.google.storage.get_file_info {
|
|
2021
|
-
service_account = "my_service_account_json"
|
|
2022
|
-
bucket = "app_assets"
|
|
2023
|
-
filePath = "icons/app_icon.png"
|
|
2024
|
-
} as $icon_details
|
|
2025
|
-
```
|
|
2026
|
-
|
|
2027
|
-
Retrieves metadata about a file in Google Cloud Storage, storing it in a variable.
|
|
2028
|
-
|
|
2029
|
-
# cloud.azure.storage.get_file_info
|
|
2030
|
-
|
|
2031
|
-
```xs
|
|
2032
|
-
cloud.azure.storage.get_file_info {
|
|
2033
|
-
account_name = "my_storage_account"
|
|
2034
|
-
account_key = "my_secret_key"
|
|
2035
|
-
container_name = "media"
|
|
2036
|
-
filePath = "videos/intro.mp4"
|
|
2037
|
-
} as $video_metadata
|
|
2038
|
-
```
|
|
2039
|
-
|
|
2040
|
-
Retrieves metadata about a blob in Azure Blob Storage, storing it in a variable.
|
|
2041
|
-
|
|
2042
|
-
# cloud.aws.opensearch.query
|
|
2043
|
-
|
|
2044
|
-
```xs
|
|
2045
|
-
cloud.aws.opensearch.query {
|
|
2046
|
-
auth_type = "IAM"
|
|
2047
|
-
key_id = "my_aws_key"
|
|
2048
|
-
access_key = "my_aws_secret"
|
|
2049
|
-
region = "us-east-1"
|
|
2050
|
-
base_url = "https://my-opensearch-domain.com"
|
|
2051
|
-
index = "products"
|
|
2052
|
-
return_type = "search"
|
|
2053
|
-
expression = [{ "field": "price", "value": "100", "op": "lt" }]
|
|
2054
|
-
size = 10
|
|
2055
|
-
from = 0
|
|
2056
|
-
included_fields = ["name", "price"]
|
|
2057
|
-
sort = [{ "field": "price", "order": "asc" }]
|
|
2058
|
-
payload = {}
|
|
2059
|
-
} as $cheap_products
|
|
2060
|
-
```
|
|
2061
|
-
|
|
2062
|
-
Performs a search query on AWS OpenSearch with customizable filters, pagination, and sorting, storing results in a variable.
|
|
2063
|
-
|
|
2064
|
-
# cloud.aws.s3.upload_file
|
|
2065
|
-
|
|
2066
|
-
```xs
|
|
2067
|
-
cloud.aws.s3.upload_file {
|
|
2068
|
-
bucket = "user_content"
|
|
2069
|
-
region = "us-west-2"
|
|
2070
|
-
key = "my_aws_key"
|
|
2071
|
-
secret = "my_aws_secret"
|
|
2072
|
-
file_key = "uploads/profile.jpg"
|
|
2073
|
-
file = $user_photo
|
|
2074
|
-
metadata = { "user_id": "123" }
|
|
2075
|
-
object_lock_mode = "governance"
|
|
2076
|
-
object_lock_retain_until = "2025-12-31"
|
|
2077
|
-
} as $upload_result
|
|
2078
|
-
```
|
|
2079
|
-
|
|
2080
|
-
Uploads a file to an AWS S3 bucket with optional metadata and object lock settings, storing the response in a variable.
|
|
2081
|
-
|
|
2082
|
-
# cloud.algolia.request
|
|
2083
|
-
|
|
2084
|
-
```xs
|
|
2085
|
-
cloud.algolia.request {
|
|
2086
|
-
application_id = "my_algolia_app_id"
|
|
2087
|
-
api_key = "my_algolia_api_key"
|
|
2088
|
-
url = "https://my-algolia-app.algolia.net/1/indexes/posts/query"
|
|
2089
|
-
method = "POST"
|
|
2090
|
-
payload = { "query": "tech" }
|
|
2091
|
-
} as $tech_posts
|
|
2092
|
-
```
|
|
2093
|
-
|
|
2094
|
-
Sends a request to Algolia with the specified `method` and `payload`, storing the response in a variable.
|
|
2095
|
-
|
|
2096
|
-
# cloud.azure.storage.upload_file
|
|
2097
|
-
|
|
2098
|
-
```xs
|
|
2099
|
-
cloud.azure.storage.upload_file {
|
|
2100
|
-
account_name = "my_storage_account"
|
|
2101
|
-
account_key = "my_secret_key"
|
|
2102
|
-
container_name = "user_files"
|
|
2103
|
-
filePath = "docs/resume.pdf"
|
|
2104
|
-
file = $user_resume
|
|
2105
|
-
metadata = { "owner": "Jane" }
|
|
2106
|
-
} as $upload_confirmation
|
|
2107
|
-
```
|
|
2108
|
-
|
|
2109
|
-
Uploads a file to Azure Blob Storage with optional metadata, storing the response in a variable.
|
|
2110
|
-
|
|
2111
|
-
# cloud.google.storage.delete_file
|
|
2112
|
-
|
|
2113
|
-
```xs
|
|
2114
|
-
cloud.google.storage.delete_file {
|
|
2115
|
-
service_account = "my_service_account_json"
|
|
2116
|
-
bucket = "temp_storage"
|
|
2117
|
-
filePath = "old/temp_data.csv"
|
|
2118
|
-
}
|
|
2119
|
-
```
|
|
2120
|
-
|
|
2121
|
-
Deletes a file from Google Cloud Storage at the specified `filePath`.
|
|
2122
|
-
|
|
2123
|
-
# cloud.elasticsearch.query
|
|
2124
|
-
|
|
2125
|
-
```xs
|
|
2126
|
-
cloud.elasticsearch.query {
|
|
2127
|
-
auth_type = "API Key"
|
|
2128
|
-
key_id = "my_key_id"
|
|
2129
|
-
access_key = "my_access_key"
|
|
2130
|
-
base_url = "https://my-elastic-cluster.com"
|
|
2131
|
-
index = "orders"
|
|
2132
|
-
return_type = "search"
|
|
2133
|
-
expression = [{ "field": "total", "value": "50", "op": "gt" }]
|
|
2134
|
-
size = 5
|
|
2135
|
-
from = 0
|
|
2136
|
-
included_fields = ["id", "total"]
|
|
2137
|
-
sort = [{ "field": "total", "order": "desc" }]
|
|
2138
|
-
payload = {}
|
|
2139
|
-
} as $large_orders
|
|
2140
|
-
```
|
|
2141
|
-
|
|
2142
|
-
Executes a search query on Elastic Search with filters, pagination, and sorting, storing results in a variable.
|
|
2143
|
-
|
|
2144
|
-
# cloud.azure.storage.read_file
|
|
2145
|
-
|
|
2146
|
-
```xs
|
|
2147
|
-
cloud.azure.storage.read_file {
|
|
2148
|
-
account_name = "my_storage_account"
|
|
2149
|
-
account_key = "my_secret_key"
|
|
2150
|
-
container_name = "logs"
|
|
2151
|
-
filePath = "daily/2023-10-01.log"
|
|
2152
|
-
} as $daily_log_file
|
|
2153
|
-
```
|
|
343
|
+
## Best Practices
|
|
2154
344
|
|
|
2155
|
-
|
|
345
|
+
1. **Single responsibility** - Each function does one thing well
|
|
346
|
+
2. **Descriptive names** - Use verb_noun format: `calculate_total`, `validate_user`
|
|
347
|
+
3. **Organize in folders** - Group related functions: `utils/`, `auth/`, `orders/`
|
|
348
|
+
4. **Validate inputs** - Use filters and preconditions
|
|
349
|
+
5. **Handle errors** - Use try_catch for external calls
|
|
350
|
+
6. **Document purpose** - Add description field
|
|
351
|
+
7. **Return early** - Use return for guard clauses
|
|
352
|
+
8. **Keep stacks shallow** - Avoid deeply nested conditionals
|