@xano/developer-mcp 1.0.35 → 1.0.37
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 +21 -4
- package/dist/xanoscript.js +40 -5
- package/dist/xanoscript.test.js +9 -2
- package/dist/xanoscript_docs/README.md +46 -42
- package/dist/xanoscript_docs/addons.md +10 -0
- package/dist/xanoscript_docs/agents.md +15 -0
- package/dist/xanoscript_docs/apis.md +45 -24
- package/dist/xanoscript_docs/cheatsheet.md +252 -0
- package/dist/xanoscript_docs/database.md +23 -0
- package/dist/xanoscript_docs/docs_index.json +241 -0
- package/dist/xanoscript_docs/frontend.md +10 -0
- package/dist/xanoscript_docs/functions.md +4 -0
- package/dist/xanoscript_docs/integrations/cloud-storage.md +142 -0
- package/dist/xanoscript_docs/integrations/external-apis.md +201 -0
- package/dist/xanoscript_docs/integrations/redis.md +194 -0
- package/dist/xanoscript_docs/integrations/search.md +242 -0
- package/dist/xanoscript_docs/integrations/utilities.md +331 -0
- package/dist/xanoscript_docs/integrations.md +55 -901
- package/dist/xanoscript_docs/mcp-servers.md +10 -0
- package/dist/xanoscript_docs/performance.md +15 -0
- package/dist/xanoscript_docs/quickstart.md +22 -88
- package/dist/xanoscript_docs/run.md +10 -0
- package/dist/xanoscript_docs/security.md +26 -0
- package/dist/xanoscript_docs/streaming.md +10 -0
- package/dist/xanoscript_docs/syntax.md +56 -0
- package/dist/xanoscript_docs/tables.md +15 -0
- package/dist/xanoscript_docs/tasks.md +11 -0
- package/dist/xanoscript_docs/tools.md +15 -0
- package/dist/xanoscript_docs/triggers.md +57 -192
- package/dist/xanoscript_docs/types.md +4 -0
- package/dist/xanoscript_docs/{testing.md → unit-testing.md} +15 -3
- package/dist/xanoscript_docs/workflow-tests.md +333 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -334,6 +334,7 @@ Retrieves XanoScript programming language documentation with context-aware suppo
|
|
|
334
334
|
| Topic | Description |
|
|
335
335
|
|-------|-------------|
|
|
336
336
|
| `readme` | XanoScript overview, workspace structure, and quick reference |
|
|
337
|
+
| `cheatsheet` | Quick reference for 20 most common XanoScript patterns (recommended first stop) |
|
|
337
338
|
| `syntax` | Expressions, operators, and filters for all XanoScript code |
|
|
338
339
|
| `types` | Data types, input blocks, and validation |
|
|
339
340
|
| `tables` | Database schema definitions with indexes and relationships |
|
|
@@ -345,8 +346,14 @@ Retrieves XanoScript programming language documentation with context-aware suppo
|
|
|
345
346
|
| `agents` | AI agent configuration with LLM providers and tools |
|
|
346
347
|
| `tools` | AI tools for agents and MCP servers |
|
|
347
348
|
| `mcp-servers` | MCP server definitions exposing tools |
|
|
348
|
-
| `testing` | Unit tests, mocks, and assertions |
|
|
349
|
-
| `
|
|
349
|
+
| `unit-testing` | Unit tests, mocks, and assertions within functions, APIs, and middleware |
|
|
350
|
+
| `workflow-tests` | End-to-end workflow tests with data sources and tags |
|
|
351
|
+
| `integrations` | External service integrations index |
|
|
352
|
+
| `integrations/cloud-storage` | AWS S3, Azure Blob, and GCP Storage |
|
|
353
|
+
| `integrations/search` | Elasticsearch, OpenSearch, and Algolia |
|
|
354
|
+
| `integrations/redis` | Redis caching, rate limiting, and queues |
|
|
355
|
+
| `integrations/external-apis` | HTTP requests with api.request |
|
|
356
|
+
| `integrations/utilities` | Local storage, email, zip, and Lambda |
|
|
350
357
|
| `frontend` | Static frontend development and deployment |
|
|
351
358
|
| `run` | Run job and service configurations |
|
|
352
359
|
| `addons` | Reusable subqueries for fetching related data |
|
|
@@ -362,6 +369,9 @@ Retrieves XanoScript programming language documentation with context-aware suppo
|
|
|
362
369
|
// Get overview
|
|
363
370
|
xanoscript_docs()
|
|
364
371
|
|
|
372
|
+
// Get quick reference cheatsheet (recommended first stop)
|
|
373
|
+
xanoscript_docs({ topic: "cheatsheet" })
|
|
374
|
+
|
|
365
375
|
// Get specific topic
|
|
366
376
|
xanoscript_docs({ topic: "functions" })
|
|
367
377
|
|
|
@@ -521,6 +531,7 @@ The server also exposes XanoScript documentation as MCP resources for direct acc
|
|
|
521
531
|
| Resource URI | Description |
|
|
522
532
|
|--------------|-------------|
|
|
523
533
|
| `xanoscript://docs/readme` | Overview and quick reference |
|
|
534
|
+
| `xanoscript://docs/cheatsheet` | Quick reference for 20 most common patterns |
|
|
524
535
|
| `xanoscript://docs/syntax` | Expressions, operators, and filters |
|
|
525
536
|
| `xanoscript://docs/types` | Data types and validation |
|
|
526
537
|
| `xanoscript://docs/tables` | Database schema definitions |
|
|
@@ -532,8 +543,14 @@ The server also exposes XanoScript documentation as MCP resources for direct acc
|
|
|
532
543
|
| `xanoscript://docs/agents` | AI agent configuration |
|
|
533
544
|
| `xanoscript://docs/tools` | AI tools for agents |
|
|
534
545
|
| `xanoscript://docs/mcp-servers` | MCP server definitions |
|
|
535
|
-
| `xanoscript://docs/testing` | Unit tests and mocks |
|
|
536
|
-
| `xanoscript://docs/
|
|
546
|
+
| `xanoscript://docs/unit-testing` | Unit tests and mocks |
|
|
547
|
+
| `xanoscript://docs/workflow-tests` | End-to-end workflow tests |
|
|
548
|
+
| `xanoscript://docs/integrations` | External service integrations index |
|
|
549
|
+
| `xanoscript://docs/integrations/cloud-storage` | AWS S3, Azure Blob, GCP Storage |
|
|
550
|
+
| `xanoscript://docs/integrations/search` | Elasticsearch, OpenSearch, Algolia |
|
|
551
|
+
| `xanoscript://docs/integrations/redis` | Redis caching and queues |
|
|
552
|
+
| `xanoscript://docs/integrations/external-apis` | HTTP requests with api.request |
|
|
553
|
+
| `xanoscript://docs/integrations/utilities` | Email, zip, Lambda utilities |
|
|
537
554
|
| `xanoscript://docs/frontend` | Static frontend development |
|
|
538
555
|
| `xanoscript://docs/run` | Run job and service configurations |
|
|
539
556
|
| `xanoscript://docs/addons` | Reusable subqueries for related data |
|
package/dist/xanoscript.js
CHANGED
|
@@ -16,6 +16,11 @@ export const XANOSCRIPT_DOCS_V2 = {
|
|
|
16
16
|
applyTo: [],
|
|
17
17
|
description: "XanoScript overview, workspace structure, and quick reference",
|
|
18
18
|
},
|
|
19
|
+
cheatsheet: {
|
|
20
|
+
file: "cheatsheet.md",
|
|
21
|
+
applyTo: ["**/*.xs"],
|
|
22
|
+
description: "Quick reference for 20 most common XanoScript patterns",
|
|
23
|
+
},
|
|
19
24
|
syntax: {
|
|
20
25
|
file: "syntax.md",
|
|
21
26
|
applyTo: ["**/*.xs"],
|
|
@@ -76,15 +81,45 @@ export const XANOSCRIPT_DOCS_V2 = {
|
|
|
76
81
|
applyTo: ["mcp_servers/**/*.xs"],
|
|
77
82
|
description: "MCP server definitions exposing tools",
|
|
78
83
|
},
|
|
79
|
-
testing: {
|
|
80
|
-
file: "testing.md",
|
|
81
|
-
applyTo: ["functions/**/*.xs", "apis/**/*.xs"],
|
|
82
|
-
description: "Unit tests, mocks, and assertions",
|
|
84
|
+
"unit-testing": {
|
|
85
|
+
file: "unit-testing.md",
|
|
86
|
+
applyTo: ["functions/**/*.xs", "apis/**/*.xs", "middleware/**/*.xs"],
|
|
87
|
+
description: "Unit tests, mocks, and assertions within functions, APIs, and middleware",
|
|
88
|
+
},
|
|
89
|
+
"workflow-tests": {
|
|
90
|
+
file: "workflow-tests.md",
|
|
91
|
+
applyTo: ["workflow_test/**/*.xs"],
|
|
92
|
+
description: "End-to-end workflow tests with data source selection and tags",
|
|
83
93
|
},
|
|
84
94
|
integrations: {
|
|
85
95
|
file: "integrations.md",
|
|
86
96
|
applyTo: ["functions/**/*.xs", "apis/**/*.xs", "tasks/*.xs"],
|
|
87
|
-
description: "
|
|
97
|
+
description: "External service integrations index - see sub-topics for details",
|
|
98
|
+
},
|
|
99
|
+
"integrations/cloud-storage": {
|
|
100
|
+
file: "integrations/cloud-storage.md",
|
|
101
|
+
applyTo: [],
|
|
102
|
+
description: "AWS S3, Azure Blob, and GCP Storage operations",
|
|
103
|
+
},
|
|
104
|
+
"integrations/search": {
|
|
105
|
+
file: "integrations/search.md",
|
|
106
|
+
applyTo: [],
|
|
107
|
+
description: "Elasticsearch, OpenSearch, and Algolia search operations",
|
|
108
|
+
},
|
|
109
|
+
"integrations/redis": {
|
|
110
|
+
file: "integrations/redis.md",
|
|
111
|
+
applyTo: [],
|
|
112
|
+
description: "Redis caching, rate limiting, and queue operations",
|
|
113
|
+
},
|
|
114
|
+
"integrations/external-apis": {
|
|
115
|
+
file: "integrations/external-apis.md",
|
|
116
|
+
applyTo: [],
|
|
117
|
+
description: "HTTP requests with api.request patterns",
|
|
118
|
+
},
|
|
119
|
+
"integrations/utilities": {
|
|
120
|
+
file: "integrations/utilities.md",
|
|
121
|
+
applyTo: [],
|
|
122
|
+
description: "Local storage, email, zip, and Lambda utilities",
|
|
88
123
|
},
|
|
89
124
|
frontend: {
|
|
90
125
|
file: "frontend.md",
|
package/dist/xanoscript.test.js
CHANGED
|
@@ -10,6 +10,7 @@ describe("xanoscript module", () => {
|
|
|
10
10
|
it("should have all expected topics", () => {
|
|
11
11
|
const expectedTopics = [
|
|
12
12
|
"readme",
|
|
13
|
+
"cheatsheet",
|
|
13
14
|
"syntax",
|
|
14
15
|
"quickstart",
|
|
15
16
|
"types",
|
|
@@ -22,8 +23,14 @@ describe("xanoscript module", () => {
|
|
|
22
23
|
"agents",
|
|
23
24
|
"tools",
|
|
24
25
|
"mcp-servers",
|
|
25
|
-
"testing",
|
|
26
|
+
"unit-testing",
|
|
27
|
+
"workflow-tests",
|
|
26
28
|
"integrations",
|
|
29
|
+
"integrations/cloud-storage",
|
|
30
|
+
"integrations/search",
|
|
31
|
+
"integrations/redis",
|
|
32
|
+
"integrations/external-apis",
|
|
33
|
+
"integrations/utilities",
|
|
27
34
|
"frontend",
|
|
28
35
|
"run",
|
|
29
36
|
"addons",
|
|
@@ -62,7 +69,7 @@ describe("xanoscript module", () => {
|
|
|
62
69
|
expect(result).toContain("apis");
|
|
63
70
|
expect(result).toContain("types");
|
|
64
71
|
expect(result).toContain("database");
|
|
65
|
-
expect(result).toContain("testing");
|
|
72
|
+
expect(result).toContain("unit-testing");
|
|
66
73
|
expect(result).toContain("addons");
|
|
67
74
|
});
|
|
68
75
|
it("should match functions files", () => {
|
|
@@ -19,6 +19,7 @@ XanoScript is the declarative scripting language for [Xano](https://xano.com), a
|
|
|
19
19
|
| `tool` | `tool/{name}.xs` | Tools for AI agents |
|
|
20
20
|
| `mcp_server` | `mcp_server/{name}.xs` | MCP server definitions |
|
|
21
21
|
| `mcp_server_trigger`| `mcp_server/trigger/{name}.xs` | MCP server event handlers |
|
|
22
|
+
| `workflow_test` | `workflow_test/{name}.xs` | End-to-end workflow tests |
|
|
22
23
|
| `addon` | `addon/{name}.xs` | Subqueries for related data |
|
|
23
24
|
| `middleware` | `middleware/{name}.xs` | Request/response interceptors |
|
|
24
25
|
| `branch` | `branch.xs` | Branch-level configuration |
|
|
@@ -65,6 +66,8 @@ project/
|
|
|
65
66
|
│ ├── my_server.xs # MCP server definitions
|
|
66
67
|
│ └── trigger/
|
|
67
68
|
│ └── on_connect.xs # MCP server triggers
|
|
69
|
+
├── workflow_test/
|
|
70
|
+
│ └── checkout_flow.xs # End-to-end workflow tests
|
|
68
71
|
├── middleware/
|
|
69
72
|
│ └── auth_check.xs # Request/response interceptors
|
|
70
73
|
├── addon/
|
|
@@ -177,69 +180,70 @@ Use `xanoscript_docs({ topic: "<topic>" })` to retrieve documentation.
|
|
|
177
180
|
|
|
178
181
|
### Core Language
|
|
179
182
|
|
|
180
|
-
| Topic | Description |
|
|
181
|
-
| ------------ | ---------------------------------------------------- |
|
|
182
|
-
| `quickstart` | Common patterns, quick examples, mistakes to avoid |
|
|
183
|
-
| `syntax` | Expressions, operators, filters, system variables |
|
|
184
|
-
| `types` | Data types, validation, input blocks |
|
|
185
|
-
| `functions` | Reusable function stacks, async, loops |
|
|
186
|
-
| `schema` | Runtime schema parsing and validation |
|
|
183
|
+
| Topic | Description | Key Sections |
|
|
184
|
+
| ------------ | ---------------------------------------------------- | ------------ |
|
|
185
|
+
| `quickstart` | Common patterns, quick examples, mistakes to avoid | Patterns, Common Mistakes |
|
|
186
|
+
| `syntax` | Expressions, operators, filters, system variables | Filters (L179-275), Error Handling (L411-477) |
|
|
187
|
+
| `types` | Data types, validation, input blocks | Validation Filters, Input Blocks |
|
|
188
|
+
| `functions` | Reusable function stacks, async, loops | Loops, Async Patterns |
|
|
189
|
+
| `schema` | Runtime schema parsing and validation | parse.object, parse.array |
|
|
187
190
|
|
|
188
191
|
### Data
|
|
189
192
|
|
|
190
|
-
| Topic | Description |
|
|
191
|
-
| ----------- | ---------------------------------------------------------- |
|
|
192
|
-
| `tables` | Database schema definitions with indexes and relationships |
|
|
193
|
-
| `database` | All db.\* operations: query, get, add, edit, patch, delete |
|
|
194
|
-
| `addons` | Reusable subqueries for fetching related data |
|
|
195
|
-
| `streaming` | Streaming data from files, requests, and responses |
|
|
193
|
+
| Topic | Description | Key Sections |
|
|
194
|
+
| ----------- | ---------------------------------------------------------- | ------------ |
|
|
195
|
+
| `tables` | Database schema definitions with indexes and relationships | Indexes, Foreign Keys |
|
|
196
|
+
| `database` | All db.\* operations: query, get, add, edit, patch, delete | Decision Tree (L11), Bulk Ops (L450-529) |
|
|
197
|
+
| `addons` | Reusable subqueries for fetching related data | Usage Patterns |
|
|
198
|
+
| `streaming` | Streaming data from files, requests, and responses | File Streams, API Streams |
|
|
196
199
|
|
|
197
200
|
### APIs & Endpoints
|
|
198
201
|
|
|
199
|
-
| Topic | Description |
|
|
200
|
-
| ---------- | --------------------------------------------------------------- |
|
|
201
|
-
| `apis` | HTTP endpoint definitions with authentication and CRUD patterns |
|
|
202
|
-
| `tasks` | Scheduled and cron jobs |
|
|
203
|
-
| `triggers` | Event-driven handlers (table, realtime, workspace, agent, MCP) |
|
|
204
|
-
| `realtime` | Real-time channels and events for push updates |
|
|
202
|
+
| Topic | Description | Key Sections |
|
|
203
|
+
| ---------- | --------------------------------------------------------------- | ------------ |
|
|
204
|
+
| `apis` | HTTP endpoint definitions with authentication and CRUD patterns | Decision Tree (L9), CRUD Examples (L220-350) |
|
|
205
|
+
| `tasks` | Scheduled and cron jobs | Cron Syntax, Input Handling |
|
|
206
|
+
| `triggers` | Event-driven handlers (table, realtime, workspace, agent, MCP) | Predefined Inputs, Event Types |
|
|
207
|
+
| `realtime` | Real-time channels and events for push updates | Channels, Events |
|
|
205
208
|
|
|
206
209
|
### AI & Agents
|
|
207
210
|
|
|
208
|
-
| Topic | Description |
|
|
209
|
-
| ------------- | --------------------------------------------------- |
|
|
210
|
-
| `agents` | AI agent configuration with LLM providers and tools |
|
|
211
|
-
| `tools` | AI tools for agents and MCP servers |
|
|
212
|
-
| `mcp-servers` | MCP server definitions exposing tools |
|
|
211
|
+
| Topic | Description | Key Sections |
|
|
212
|
+
| ------------- | --------------------------------------------------- | ------------ |
|
|
213
|
+
| `agents` | AI agent configuration with LLM providers and tools | LLM Config, Tool Binding |
|
|
214
|
+
| `tools` | AI tools for agents and MCP servers | Tool Schema, Parameters |
|
|
215
|
+
| `mcp-servers` | MCP server definitions exposing tools | Server Config, Tool Exposure |
|
|
213
216
|
|
|
214
217
|
### Integrations
|
|
215
218
|
|
|
216
|
-
| Topic | Description |
|
|
217
|
-
| -------------- | ------------------------------------------------- |
|
|
218
|
-
| `integrations` | Cloud storage, Redis, security, and external APIs |
|
|
219
|
+
| Topic | Description | Sub-topics |
|
|
220
|
+
| -------------- | ------------------------------------------------- | ---------- |
|
|
221
|
+
| `integrations` | Cloud storage, Redis, security, and external APIs | cloud-storage, search, redis, external-apis, utilities |
|
|
219
222
|
|
|
220
223
|
### Configuration
|
|
221
224
|
|
|
222
|
-
| Topic | Description |
|
|
223
|
-
| ------------ | ---------------------------------------------------------------------- |
|
|
224
|
-
| `workspace` | Workspace-level settings: environment variables, preferences, realtime |
|
|
225
|
-
| `branch` | Branch-level settings: middleware, history retention, visual styling |
|
|
226
|
-
| `middleware` | Request/response interceptors for functions, queries, tasks, and tools |
|
|
225
|
+
| Topic | Description | Key Sections |
|
|
226
|
+
| ------------ | ---------------------------------------------------------------------- | ------------ |
|
|
227
|
+
| `workspace` | Workspace-level settings: environment variables, preferences, realtime | Env Variables, Preferences |
|
|
228
|
+
| `branch` | Branch-level settings: middleware, history retention, visual styling | Middleware Config, History |
|
|
229
|
+
| `middleware` | Request/response interceptors for functions, queries, tasks, and tools | Pre/Post Hooks |
|
|
227
230
|
|
|
228
231
|
### Development
|
|
229
232
|
|
|
230
|
-
| Topic | Description |
|
|
231
|
-
| ----------- | ---------------------------------------------------------- |
|
|
232
|
-
| `testing`
|
|
233
|
-
| `
|
|
234
|
-
| `
|
|
235
|
-
| `
|
|
233
|
+
| Topic | Description | Key Sections |
|
|
234
|
+
| ----------- | ---------------------------------------------------------- | ------------ |
|
|
235
|
+
| `unit-testing` | Unit tests, mocks, and assertions within functions, APIs, and middleware | Test Syntax, Assertions, Mocking |
|
|
236
|
+
| `workflow-tests` | End-to-end workflow tests with data sources and tags | Data Sources, Tags, Common Patterns |
|
|
237
|
+
| `debugging` | Logging, inspecting, and debugging XanoScript execution | debug.log, Inspection |
|
|
238
|
+
| `frontend` | Static frontend development and deployment | File Structure |
|
|
239
|
+
| `run` | Run job and service configurations for the Xano Job Runner | Jobs, Services |
|
|
236
240
|
|
|
237
241
|
### Best Practices
|
|
238
242
|
|
|
239
|
-
| Topic | Description |
|
|
240
|
-
| ------------- | ------------------------------------------------------------ |
|
|
241
|
-
| `performance` | Performance optimization best practices |
|
|
242
|
-
| `security` | Security best practices for authentication and authorization |
|
|
243
|
+
| Topic | Description | Key Sections |
|
|
244
|
+
| ------------- | ------------------------------------------------------------ | ------------ |
|
|
245
|
+
| `performance` | Performance optimization best practices | Caching, Query Optimization |
|
|
246
|
+
| `security` | Security best practices for authentication and authorization | Auth Patterns, Token Handling |
|
|
243
247
|
|
|
244
248
|
---
|
|
245
249
|
|
|
@@ -254,3 +254,13 @@ addon/
|
|
|
254
254
|
3. **Use appropriate return types** - `list`, `single`, `count`, `exists`
|
|
255
255
|
4. **Limit nested queries** - Avoid N+1 query patterns
|
|
256
256
|
5. **Document inputs** - Add descriptions to input fields
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Related Topics
|
|
261
|
+
|
|
262
|
+
| Topic | Description |
|
|
263
|
+
|-------|-------------|
|
|
264
|
+
| `database` | db.query with addon usage |
|
|
265
|
+
| `apis` | Using addons in API responses |
|
|
266
|
+
| `functions` | Calling addons from functions |
|
|
@@ -6,6 +6,10 @@ applyTo: "agent/**/*.xs"
|
|
|
6
6
|
|
|
7
7
|
AI-powered agents that use LLMs to perform tasks autonomously.
|
|
8
8
|
|
|
9
|
+
> **TL;DR:** Define with `agent "name" { llm = { type: "provider", system_prompt: "...", prompt: "..." } tools = [...] }`. Providers: `xano-free`, `openai`, `anthropic`, `google-genai`. Tools give agents capabilities.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
9
13
|
## Quick Reference
|
|
10
14
|
|
|
11
15
|
```xs
|
|
@@ -409,3 +413,14 @@ agent "Research Agent" {
|
|
|
409
413
|
5. **Use environment variables** - Never hardcode API keys
|
|
410
414
|
6. **Test with xano-free first** - Free for development
|
|
411
415
|
7. **Validate external MCP servers** - Check server_details before using
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## Related Topics
|
|
420
|
+
|
|
421
|
+
| Topic | Description |
|
|
422
|
+
|-------|-------------|
|
|
423
|
+
| `tools` | Functions that agents can execute |
|
|
424
|
+
| `mcp-servers` | MCP server configuration |
|
|
425
|
+
| `triggers` | Agent triggers for events |
|
|
426
|
+
| `security` | API key management |
|
|
@@ -6,6 +6,30 @@ applyTo: "api/**/*.xs"
|
|
|
6
6
|
|
|
7
7
|
HTTP endpoint definitions in XanoScript.
|
|
8
8
|
|
|
9
|
+
> **TL;DR:** Use `query` to define endpoints. Require `api_group` for organization, `auth` for protected routes. Use appropriate HTTP verbs (GET/POST/PUT/PATCH/DELETE) and validate inputs with filters.
|
|
10
|
+
|
|
11
|
+
## Choosing an Approach
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Building...
|
|
15
|
+
├── REST endpoint?
|
|
16
|
+
│ ├── GET (read) → query with verb=GET
|
|
17
|
+
│ ├── POST (create) → query with verb=POST
|
|
18
|
+
│ ├── PUT/PATCH (update) → query with verb=PUT or verb=PATCH
|
|
19
|
+
│ └── DELETE (remove) → query with verb=DELETE
|
|
20
|
+
├── Protected endpoint?
|
|
21
|
+
│ ├── Token auth? → auth = "user" (table with auth=true)
|
|
22
|
+
│ └── Public? → omit auth attribute
|
|
23
|
+
├── Input handling?
|
|
24
|
+
│ ├── Path params? → query "path/{id}" + input { int id }
|
|
25
|
+
│ ├── Query params? → GET with input block
|
|
26
|
+
│ └── Body params? → POST/PUT/PATCH with input block
|
|
27
|
+
├── Reusable logic?
|
|
28
|
+
│ └── Use function, call with function.run
|
|
29
|
+
└── Scheduled job?
|
|
30
|
+
└── Use task instead of query
|
|
31
|
+
```
|
|
32
|
+
|
|
9
33
|
## Quick Reference
|
|
10
34
|
|
|
11
35
|
```xs
|
|
@@ -116,26 +140,18 @@ query "products" verb=GET {
|
|
|
116
140
|
|
|
117
141
|
## Input Block
|
|
118
142
|
|
|
119
|
-
For complete type and
|
|
120
|
-
|
|
121
|
-
### Empty and Single-Input Blocks
|
|
122
|
-
|
|
123
|
-
Empty input blocks and single-input blocks can be written as one-liners. When there are two or more inputs, each must be on its own line.
|
|
143
|
+
> **Input block rules:** Empty and single-input blocks can be one-liners. Multiple inputs must be on separate lines. For complete type reference, validation filters, and schema definitions, see `xanoscript_docs({ topic: "types" })`.
|
|
124
144
|
|
|
125
145
|
```xs
|
|
126
|
-
// OK - empty input
|
|
127
|
-
|
|
128
|
-
api_group = "System"
|
|
129
|
-
input {}
|
|
130
|
-
stack { ... }
|
|
131
|
-
response = { status: "ok" }
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// OK - single input as one-liner
|
|
146
|
+
// OK - empty or single input as one-liner
|
|
147
|
+
input {}
|
|
135
148
|
input { text query filters=trim }
|
|
136
149
|
|
|
137
|
-
//
|
|
138
|
-
input {
|
|
150
|
+
// Multiple inputs - each on own line
|
|
151
|
+
input {
|
|
152
|
+
text query filters=trim
|
|
153
|
+
int limit?=10
|
|
154
|
+
}
|
|
139
155
|
```
|
|
140
156
|
|
|
141
157
|
---
|
|
@@ -400,14 +416,7 @@ stack {
|
|
|
400
416
|
|
|
401
417
|
## Error Handling
|
|
402
418
|
|
|
403
|
-
For complete error handling
|
|
404
|
-
|
|
405
|
-
| Type | HTTP Status |
|
|
406
|
-
| -------------- | ----------- |
|
|
407
|
-
| `inputerror` | 400 |
|
|
408
|
-
| `accessdenied` | 403 |
|
|
409
|
-
| `notfound` | 404 |
|
|
410
|
-
| `standard` | 500 |
|
|
419
|
+
> **Error types:** Use `inputerror` (400), `accessdenied` (403), `notfound` (404), or `standard` (500). For complete error handling patterns including `precondition`, `try_catch`, and `throw`, see `xanoscript_docs({ topic: "syntax" })`.
|
|
411
420
|
|
|
412
421
|
---
|
|
413
422
|
|
|
@@ -437,3 +446,15 @@ When using `return = { type: "list", paging: {...} }`:
|
|
|
437
446
|
4. **Paginate lists** - Never return unbounded result sets
|
|
438
447
|
5. **Group by resource** - Organize endpoints in logical api groups
|
|
439
448
|
6. **Use specific canonicals** - Prefix canonicals to avoid instance-level collisions (e.g., `myapp-users` not `users`)
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
## Related Topics
|
|
453
|
+
|
|
454
|
+
| Topic | Description |
|
|
455
|
+
|-------|-------------|
|
|
456
|
+
| `types` | Input validation and filters |
|
|
457
|
+
| `functions` | Reusable logic called from API stacks |
|
|
458
|
+
| `database` | Database operations in API stacks |
|
|
459
|
+
| `security` | Authentication and authorization |
|
|
460
|
+
| `middleware` | Request interceptors |
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/*.xs"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# XanoScript Cheat Sheet
|
|
6
|
+
|
|
7
|
+
> **Purpose:** Quick reference for the 20 most common XanoScript patterns. For detailed documentation, use `xanoscript_docs({ topic: "<topic>" })`.
|
|
8
|
+
|
|
9
|
+
## Variable Declaration
|
|
10
|
+
|
|
11
|
+
```xs
|
|
12
|
+
var $name { value = "initial" }
|
|
13
|
+
var $count { value = 0 }
|
|
14
|
+
var $items { value = [] }
|
|
15
|
+
var $data { value = { key: "value" } }
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Conditionals
|
|
19
|
+
|
|
20
|
+
```xs
|
|
21
|
+
conditional {
|
|
22
|
+
if ($input.age >= 18) {
|
|
23
|
+
var $status { value = "adult" }
|
|
24
|
+
}
|
|
25
|
+
elseif ($input.age >= 13) {
|
|
26
|
+
var $status { value = "teen" }
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
var $status { value = "child" }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
> **Note:** Use `elseif` (one word), not `else if`.
|
|
35
|
+
|
|
36
|
+
## Loops
|
|
37
|
+
|
|
38
|
+
```xs
|
|
39
|
+
// For each loop
|
|
40
|
+
each ($input.items as $item) {
|
|
41
|
+
debug.log { value = $item.name }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// While loop (must be inside stack block)
|
|
45
|
+
stack {
|
|
46
|
+
var $counter { value = 0 }
|
|
47
|
+
while ($counter < 10) {
|
|
48
|
+
each {
|
|
49
|
+
var.update $counter { value = $counter + 1 }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Map/filter for transformations
|
|
55
|
+
var $names { value = $items|map:$$.name }
|
|
56
|
+
var $active { value = $items|filter:$$.is_active }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Database CRUD
|
|
60
|
+
|
|
61
|
+
```xs
|
|
62
|
+
// Get single record by field
|
|
63
|
+
db.get "user" {
|
|
64
|
+
field_name = "id"
|
|
65
|
+
field_value = $input.user_id
|
|
66
|
+
} as $user
|
|
67
|
+
|
|
68
|
+
// Query with filters
|
|
69
|
+
db.query "user" {
|
|
70
|
+
where = $db.user.is_active == true
|
|
71
|
+
sort = { created_at: "desc" }
|
|
72
|
+
return = { type: "list", paging: { page: 1, per_page: 25 } }
|
|
73
|
+
} as $users
|
|
74
|
+
|
|
75
|
+
// Insert record
|
|
76
|
+
db.add "user" {
|
|
77
|
+
data = { name: $input.name, email: $input.email, created_at: now }
|
|
78
|
+
} as $new_user
|
|
79
|
+
|
|
80
|
+
// Update record
|
|
81
|
+
db.edit "user" {
|
|
82
|
+
field_name = "id"
|
|
83
|
+
field_value = $input.user_id
|
|
84
|
+
data = { name: $input.name, updated_at: now }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Delete record
|
|
88
|
+
db.del "user" { field_name = "id", field_value = $input.user_id }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## API Requests
|
|
92
|
+
|
|
93
|
+
```xs
|
|
94
|
+
api.request {
|
|
95
|
+
url = "https://api.example.com/endpoint"
|
|
96
|
+
method = "POST"
|
|
97
|
+
params = { key: "value" } // Note: "params" for body, NOT "body"
|
|
98
|
+
headers = [
|
|
99
|
+
"Content-Type: application/json",
|
|
100
|
+
"Authorization: Bearer " ~ $env.API_KEY
|
|
101
|
+
]
|
|
102
|
+
timeout = 30
|
|
103
|
+
} as $api_result
|
|
104
|
+
|
|
105
|
+
// Response structure:
|
|
106
|
+
// $api_result.response.status → HTTP status code (200, 404, etc.)
|
|
107
|
+
// $api_result.response.result → Parsed response body
|
|
108
|
+
// $api_result.response.headers → Response headers
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Error Handling
|
|
112
|
+
|
|
113
|
+
```xs
|
|
114
|
+
// Precondition (stops execution if false)
|
|
115
|
+
precondition ($input.id > 0) {
|
|
116
|
+
error_type = "inputerror"
|
|
117
|
+
error = "ID must be positive"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Try-catch
|
|
121
|
+
try_catch {
|
|
122
|
+
try {
|
|
123
|
+
// risky operation
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
debug.log { value = "Operation failed" }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Throw custom error
|
|
131
|
+
throw {
|
|
132
|
+
name = "ValidationError"
|
|
133
|
+
value = "Custom error message"
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Error Types
|
|
138
|
+
|
|
139
|
+
| Type | HTTP Status | Use Case |
|
|
140
|
+
|------|-------------|----------|
|
|
141
|
+
| `inputerror` | 400 | Invalid input data |
|
|
142
|
+
| `accessdenied` | 403 | Authorization failure |
|
|
143
|
+
| `notfound` | 404 | Resource doesn't exist |
|
|
144
|
+
| `standard` | 500 | General errors |
|
|
145
|
+
|
|
146
|
+
## Common Filters
|
|
147
|
+
|
|
148
|
+
```xs
|
|
149
|
+
// String
|
|
150
|
+
$text|trim // Remove whitespace
|
|
151
|
+
$text|to_lower // Lowercase
|
|
152
|
+
$text|to_upper // Uppercase
|
|
153
|
+
$text|substr:0:10 // Substring
|
|
154
|
+
$text|split:"," // Split to array
|
|
155
|
+
$text|contains:"x" // Check contains → bool
|
|
156
|
+
|
|
157
|
+
// Array
|
|
158
|
+
$arr|first // First element
|
|
159
|
+
$arr|last // Last element
|
|
160
|
+
$arr|count // Length
|
|
161
|
+
$arr|map:$$.field // Transform elements
|
|
162
|
+
$arr|filter:$$.active // Filter by condition
|
|
163
|
+
$arr|find:$$.id == 5 // Find first match
|
|
164
|
+
|
|
165
|
+
// Type conversion
|
|
166
|
+
$val|to_text // To string
|
|
167
|
+
$val|to_int // To integer
|
|
168
|
+
$val|to_bool // To boolean
|
|
169
|
+
$val|json_encode // To JSON string
|
|
170
|
+
$text|json_decode // From JSON string
|
|
171
|
+
|
|
172
|
+
// Object
|
|
173
|
+
$obj|get:"key" // Get property
|
|
174
|
+
$obj|get:"key":"default" // Get with default
|
|
175
|
+
$obj|set:"key":"value" // Set property
|
|
176
|
+
$obj|has:"key" // Check key exists
|
|
177
|
+
|
|
178
|
+
// Null handling
|
|
179
|
+
$val|first_notnull:"default" // Default if null
|
|
180
|
+
$val ?? "default" // Nullish coalescing
|
|
181
|
+
|
|
182
|
+
// Math
|
|
183
|
+
$num|round:2 // Round to 2 decimals
|
|
184
|
+
$num|abs // Absolute value
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Authentication Check
|
|
188
|
+
|
|
189
|
+
```xs
|
|
190
|
+
precondition ($auth.id != null) {
|
|
191
|
+
error_type = "accessdenied"
|
|
192
|
+
error = "Authentication required"
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Function Call
|
|
197
|
+
|
|
198
|
+
```xs
|
|
199
|
+
function.run "my_function" {
|
|
200
|
+
input = { param1: "value" }
|
|
201
|
+
} as $result
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## String Concatenation
|
|
205
|
+
|
|
206
|
+
```xs
|
|
207
|
+
// Basic
|
|
208
|
+
var $msg { value = "Hello, " ~ $input.name ~ "!" }
|
|
209
|
+
|
|
210
|
+
// With filters - MUST use parentheses
|
|
211
|
+
var $msg { value = ($status|to_text) ~ ": " ~ ($data|json_encode) }
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Common Type Names
|
|
215
|
+
|
|
216
|
+
| Use This | Not This |
|
|
217
|
+
|----------|----------|
|
|
218
|
+
| `text` | string |
|
|
219
|
+
| `int` | integer |
|
|
220
|
+
| `bool` | boolean |
|
|
221
|
+
| `decimal` | float, number |
|
|
222
|
+
| `type[]` | array, list |
|
|
223
|
+
|
|
224
|
+
## Reserved Variables (Cannot Use)
|
|
225
|
+
|
|
226
|
+
`$response`, `$output`, `$input`, `$auth`, `$env`, `$db`, `$this`, `$result`
|
|
227
|
+
|
|
228
|
+
## Input Block Syntax
|
|
229
|
+
|
|
230
|
+
```xs
|
|
231
|
+
input {
|
|
232
|
+
text name // Required
|
|
233
|
+
text nickname? // Optional (can be omitted)
|
|
234
|
+
text role?="user" // Optional with default
|
|
235
|
+
email contact filters=trim // With filters
|
|
236
|
+
text[] tags // Array type
|
|
237
|
+
object address { // Nested object
|
|
238
|
+
schema {
|
|
239
|
+
text street
|
|
240
|
+
text city
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
**Related:** For detailed documentation, use:
|
|
249
|
+
- `xanoscript_docs({ topic: "quickstart" })` - Common patterns and mistakes
|
|
250
|
+
- `xanoscript_docs({ topic: "syntax" })` - All filters and operators
|
|
251
|
+
- `xanoscript_docs({ topic: "database" })` - All db.* operations
|
|
252
|
+
- `xanoscript_docs({ topic: "types" })` - Type validation and schemas
|