@xano/developer-mcp 1.0.35 → 1.0.36
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 +17 -2
- package/dist/xanoscript.js +31 -1
- package/dist/xanoscript.test.js +6 -0
- package/dist/xanoscript_docs/README.md +42 -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 +236 -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/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 |
|
|
@@ -346,7 +347,12 @@ Retrieves XanoScript programming language documentation with context-aware suppo
|
|
|
346
347
|
| `tools` | AI tools for agents and MCP servers |
|
|
347
348
|
| `mcp-servers` | MCP server definitions exposing tools |
|
|
348
349
|
| `testing` | Unit tests, mocks, and assertions |
|
|
349
|
-
| `integrations` |
|
|
350
|
+
| `integrations` | External service integrations index |
|
|
351
|
+
| `integrations/cloud-storage` | AWS S3, Azure Blob, and GCP Storage |
|
|
352
|
+
| `integrations/search` | Elasticsearch, OpenSearch, and Algolia |
|
|
353
|
+
| `integrations/redis` | Redis caching, rate limiting, and queues |
|
|
354
|
+
| `integrations/external-apis` | HTTP requests with api.request |
|
|
355
|
+
| `integrations/utilities` | Local storage, email, zip, and Lambda |
|
|
350
356
|
| `frontend` | Static frontend development and deployment |
|
|
351
357
|
| `run` | Run job and service configurations |
|
|
352
358
|
| `addons` | Reusable subqueries for fetching related data |
|
|
@@ -362,6 +368,9 @@ Retrieves XanoScript programming language documentation with context-aware suppo
|
|
|
362
368
|
// Get overview
|
|
363
369
|
xanoscript_docs()
|
|
364
370
|
|
|
371
|
+
// Get quick reference cheatsheet (recommended first stop)
|
|
372
|
+
xanoscript_docs({ topic: "cheatsheet" })
|
|
373
|
+
|
|
365
374
|
// Get specific topic
|
|
366
375
|
xanoscript_docs({ topic: "functions" })
|
|
367
376
|
|
|
@@ -521,6 +530,7 @@ The server also exposes XanoScript documentation as MCP resources for direct acc
|
|
|
521
530
|
| Resource URI | Description |
|
|
522
531
|
|--------------|-------------|
|
|
523
532
|
| `xanoscript://docs/readme` | Overview and quick reference |
|
|
533
|
+
| `xanoscript://docs/cheatsheet` | Quick reference for 20 most common patterns |
|
|
524
534
|
| `xanoscript://docs/syntax` | Expressions, operators, and filters |
|
|
525
535
|
| `xanoscript://docs/types` | Data types and validation |
|
|
526
536
|
| `xanoscript://docs/tables` | Database schema definitions |
|
|
@@ -533,7 +543,12 @@ The server also exposes XanoScript documentation as MCP resources for direct acc
|
|
|
533
543
|
| `xanoscript://docs/tools` | AI tools for agents |
|
|
534
544
|
| `xanoscript://docs/mcp-servers` | MCP server definitions |
|
|
535
545
|
| `xanoscript://docs/testing` | Unit tests and mocks |
|
|
536
|
-
| `xanoscript://docs/integrations` | External service integrations |
|
|
546
|
+
| `xanoscript://docs/integrations` | External service integrations index |
|
|
547
|
+
| `xanoscript://docs/integrations/cloud-storage` | AWS S3, Azure Blob, GCP Storage |
|
|
548
|
+
| `xanoscript://docs/integrations/search` | Elasticsearch, OpenSearch, Algolia |
|
|
549
|
+
| `xanoscript://docs/integrations/redis` | Redis caching and queues |
|
|
550
|
+
| `xanoscript://docs/integrations/external-apis` | HTTP requests with api.request |
|
|
551
|
+
| `xanoscript://docs/integrations/utilities` | Email, zip, Lambda utilities |
|
|
537
552
|
| `xanoscript://docs/frontend` | Static frontend development |
|
|
538
553
|
| `xanoscript://docs/run` | Run job and service configurations |
|
|
539
554
|
| `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"],
|
|
@@ -84,7 +89,32 @@ export const XANOSCRIPT_DOCS_V2 = {
|
|
|
84
89
|
integrations: {
|
|
85
90
|
file: "integrations.md",
|
|
86
91
|
applyTo: ["functions/**/*.xs", "apis/**/*.xs", "tasks/*.xs"],
|
|
87
|
-
description: "
|
|
92
|
+
description: "External service integrations index - see sub-topics for details",
|
|
93
|
+
},
|
|
94
|
+
"integrations/cloud-storage": {
|
|
95
|
+
file: "integrations/cloud-storage.md",
|
|
96
|
+
applyTo: [],
|
|
97
|
+
description: "AWS S3, Azure Blob, and GCP Storage operations",
|
|
98
|
+
},
|
|
99
|
+
"integrations/search": {
|
|
100
|
+
file: "integrations/search.md",
|
|
101
|
+
applyTo: [],
|
|
102
|
+
description: "Elasticsearch, OpenSearch, and Algolia search operations",
|
|
103
|
+
},
|
|
104
|
+
"integrations/redis": {
|
|
105
|
+
file: "integrations/redis.md",
|
|
106
|
+
applyTo: [],
|
|
107
|
+
description: "Redis caching, rate limiting, and queue operations",
|
|
108
|
+
},
|
|
109
|
+
"integrations/external-apis": {
|
|
110
|
+
file: "integrations/external-apis.md",
|
|
111
|
+
applyTo: [],
|
|
112
|
+
description: "HTTP requests with api.request patterns",
|
|
113
|
+
},
|
|
114
|
+
"integrations/utilities": {
|
|
115
|
+
file: "integrations/utilities.md",
|
|
116
|
+
applyTo: [],
|
|
117
|
+
description: "Local storage, email, zip, and Lambda utilities",
|
|
88
118
|
},
|
|
89
119
|
frontend: {
|
|
90
120
|
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",
|
|
@@ -24,6 +25,11 @@ describe("xanoscript module", () => {
|
|
|
24
25
|
"mcp-servers",
|
|
25
26
|
"testing",
|
|
26
27
|
"integrations",
|
|
28
|
+
"integrations/cloud-storage",
|
|
29
|
+
"integrations/search",
|
|
30
|
+
"integrations/redis",
|
|
31
|
+
"integrations/external-apis",
|
|
32
|
+
"integrations/utilities",
|
|
27
33
|
"frontend",
|
|
28
34
|
"run",
|
|
29
35
|
"addons",
|
|
@@ -177,69 +177,69 @@ Use `xanoscript_docs({ topic: "<topic>" })` to retrieve documentation.
|
|
|
177
177
|
|
|
178
178
|
### Core Language
|
|
179
179
|
|
|
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 |
|
|
180
|
+
| Topic | Description | Key Sections |
|
|
181
|
+
| ------------ | ---------------------------------------------------- | ------------ |
|
|
182
|
+
| `quickstart` | Common patterns, quick examples, mistakes to avoid | Patterns, Common Mistakes |
|
|
183
|
+
| `syntax` | Expressions, operators, filters, system variables | Filters (L179-275), Error Handling (L411-477) |
|
|
184
|
+
| `types` | Data types, validation, input blocks | Validation Filters, Input Blocks |
|
|
185
|
+
| `functions` | Reusable function stacks, async, loops | Loops, Async Patterns |
|
|
186
|
+
| `schema` | Runtime schema parsing and validation | parse.object, parse.array |
|
|
187
187
|
|
|
188
188
|
### Data
|
|
189
189
|
|
|
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 |
|
|
190
|
+
| Topic | Description | Key Sections |
|
|
191
|
+
| ----------- | ---------------------------------------------------------- | ------------ |
|
|
192
|
+
| `tables` | Database schema definitions with indexes and relationships | Indexes, Foreign Keys |
|
|
193
|
+
| `database` | All db.\* operations: query, get, add, edit, patch, delete | Decision Tree (L11), Bulk Ops (L450-529) |
|
|
194
|
+
| `addons` | Reusable subqueries for fetching related data | Usage Patterns |
|
|
195
|
+
| `streaming` | Streaming data from files, requests, and responses | File Streams, API Streams |
|
|
196
196
|
|
|
197
197
|
### APIs & Endpoints
|
|
198
198
|
|
|
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 |
|
|
199
|
+
| Topic | Description | Key Sections |
|
|
200
|
+
| ---------- | --------------------------------------------------------------- | ------------ |
|
|
201
|
+
| `apis` | HTTP endpoint definitions with authentication and CRUD patterns | Decision Tree (L9), CRUD Examples (L220-350) |
|
|
202
|
+
| `tasks` | Scheduled and cron jobs | Cron Syntax, Input Handling |
|
|
203
|
+
| `triggers` | Event-driven handlers (table, realtime, workspace, agent, MCP) | Predefined Inputs, Event Types |
|
|
204
|
+
| `realtime` | Real-time channels and events for push updates | Channels, Events |
|
|
205
205
|
|
|
206
206
|
### AI & Agents
|
|
207
207
|
|
|
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 |
|
|
208
|
+
| Topic | Description | Key Sections |
|
|
209
|
+
| ------------- | --------------------------------------------------- | ------------ |
|
|
210
|
+
| `agents` | AI agent configuration with LLM providers and tools | LLM Config, Tool Binding |
|
|
211
|
+
| `tools` | AI tools for agents and MCP servers | Tool Schema, Parameters |
|
|
212
|
+
| `mcp-servers` | MCP server definitions exposing tools | Server Config, Tool Exposure |
|
|
213
213
|
|
|
214
214
|
### Integrations
|
|
215
215
|
|
|
216
|
-
| Topic | Description |
|
|
217
|
-
| -------------- | ------------------------------------------------- |
|
|
218
|
-
| `integrations` | Cloud storage, Redis, security, and external APIs |
|
|
216
|
+
| Topic | Description | Sub-topics |
|
|
217
|
+
| -------------- | ------------------------------------------------- | ---------- |
|
|
218
|
+
| `integrations` | Cloud storage, Redis, security, and external APIs | cloud-storage, search, redis, external-apis, utilities |
|
|
219
219
|
|
|
220
220
|
### Configuration
|
|
221
221
|
|
|
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 |
|
|
222
|
+
| Topic | Description | Key Sections |
|
|
223
|
+
| ------------ | ---------------------------------------------------------------------- | ------------ |
|
|
224
|
+
| `workspace` | Workspace-level settings: environment variables, preferences, realtime | Env Variables, Preferences |
|
|
225
|
+
| `branch` | Branch-level settings: middleware, history retention, visual styling | Middleware Config, History |
|
|
226
|
+
| `middleware` | Request/response interceptors for functions, queries, tasks, and tools | Pre/Post Hooks |
|
|
227
227
|
|
|
228
228
|
### Development
|
|
229
229
|
|
|
230
|
-
| Topic | Description |
|
|
231
|
-
| ----------- | ---------------------------------------------------------- |
|
|
232
|
-
| `testing` | Unit tests, mocks, and assertions |
|
|
233
|
-
| `debugging` | Logging, inspecting, and debugging XanoScript execution |
|
|
234
|
-
| `frontend` | Static frontend development and deployment |
|
|
235
|
-
| `run` | Run job and service configurations for the Xano Job Runner |
|
|
230
|
+
| Topic | Description | Key Sections |
|
|
231
|
+
| ----------- | ---------------------------------------------------------- | ------------ |
|
|
232
|
+
| `testing` | Unit tests, mocks, and assertions | Test Syntax, Assertions |
|
|
233
|
+
| `debugging` | Logging, inspecting, and debugging XanoScript execution | debug.log, Inspection |
|
|
234
|
+
| `frontend` | Static frontend development and deployment | File Structure |
|
|
235
|
+
| `run` | Run job and service configurations for the Xano Job Runner | Jobs, Services |
|
|
236
236
|
|
|
237
237
|
### Best Practices
|
|
238
238
|
|
|
239
|
-
| Topic | Description |
|
|
240
|
-
| ------------- | ------------------------------------------------------------ |
|
|
241
|
-
| `performance` | Performance optimization best practices |
|
|
242
|
-
| `security` | Security best practices for authentication and authorization |
|
|
239
|
+
| Topic | Description | Key Sections |
|
|
240
|
+
| ------------- | ------------------------------------------------------------ | ------------ |
|
|
241
|
+
| `performance` | Performance optimization best practices | Caching, Query Optimization |
|
|
242
|
+
| `security` | Security best practices for authentication and authorization | Auth Patterns, Token Handling |
|
|
243
243
|
|
|
244
244
|
---
|
|
245
245
|
|
|
@@ -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
|
|
@@ -6,6 +6,29 @@ applyTo: "function/**/*.xs, api/**/*.xs, task/**/*.xs, tool/**/*.xs"
|
|
|
6
6
|
|
|
7
7
|
Complete reference for XanoScript database operations.
|
|
8
8
|
|
|
9
|
+
> **TL;DR:** Use `db.get` for single record by ID, `db.query` for filtered lists, `db.has` to check existence, `db.add` to insert, `db.edit` for inline updates, `db.patch` for dynamic fields, `db.del` to delete.
|
|
10
|
+
|
|
11
|
+
## Choosing an Operation
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Need to...
|
|
15
|
+
├── Read data?
|
|
16
|
+
│ ├── Single record by ID? → db.get
|
|
17
|
+
│ ├── Check if exists? → db.has
|
|
18
|
+
│ └── Filtered list? → db.query
|
|
19
|
+
├── Write data?
|
|
20
|
+
│ ├── New record? → db.add
|
|
21
|
+
│ ├── Update known fields? → db.edit
|
|
22
|
+
│ └── Update dynamic fields? → db.patch
|
|
23
|
+
├── Delete data?
|
|
24
|
+
│ ├── Single record? → db.del
|
|
25
|
+
│ └── All records? → db.truncate
|
|
26
|
+
└── Complex query?
|
|
27
|
+
├── Join tables? → db.query with join
|
|
28
|
+
├── Aggregate? → db.query with evals
|
|
29
|
+
└── Transaction? → db.transaction
|
|
30
|
+
```
|
|
31
|
+
|
|
9
32
|
## Quick Reference
|
|
10
33
|
|
|
11
34
|
| Operation | Purpose | Returns |
|