@superblocksteam/vite-plugin-file-sync 2.0.93 → 2.0.94-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-service/agent/prompts/api-prompts.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/api-prompts.js +9 -1
- package/dist/ai-service/agent/prompts/api-prompts.js.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js +14 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/analysis.js +4 -4
- package/dist/ai-service/agent/tools/apis/analysis.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/get-api-docs.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/apis/get-api-docs.js +3 -1
- package/dist/ai-service/agent/tools/apis/get-api-docs.js.map +1 -1
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +20 -6
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/access-control.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/access-control.js +5 -26
- package/dist/ai-service/agent/tools2/access-control.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/git-commit.d.ts +15 -0
- package/dist/ai-service/agent/tools2/tools/git-commit.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-commit.js +105 -0
- package/dist/ai-service/agent/tools2/tools/git-commit.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-diff.d.ts +9 -0
- package/dist/ai-service/agent/tools2/tools/git-diff.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-diff.js +23 -0
- package/dist/ai-service/agent/tools2/tools/git-diff.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-log.d.ts +12 -0
- package/dist/ai-service/agent/tools2/tools/git-log.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-log.js +27 -0
- package/dist/ai-service/agent/tools2/tools/git-log.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-merge-abort.d.ts +7 -0
- package/dist/ai-service/agent/tools2/tools/git-merge-abort.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-merge-abort.js +42 -0
- package/dist/ai-service/agent/tools2/tools/git-merge-abort.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-pull.d.ts +20 -0
- package/dist/ai-service/agent/tools2/tools/git-pull.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-pull.js +80 -0
- package/dist/ai-service/agent/tools2/tools/git-pull.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-stage.d.ts +9 -0
- package/dist/ai-service/agent/tools2/tools/git-stage.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-stage.js +34 -0
- package/dist/ai-service/agent/tools2/tools/git-stage.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-status.d.ts +9 -0
- package/dist/ai-service/agent/tools2/tools/git-status.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/git-status.js +18 -0
- package/dist/ai-service/agent/tools2/tools/git-status.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts +1 -1
- package/dist/ai-service/agent/tools2/tools/index.d.ts +7 -0
- package/dist/ai-service/agent/tools2/tools/index.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/index.js +8 -0
- package/dist/ai-service/agent/tools2/tools/index.js.map +1 -1
- package/dist/ai-service/agent/tools2/types.d.ts +2 -3
- package/dist/ai-service/agent/tools2/types.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/types.js +1 -0
- package/dist/ai-service/agent/tools2/types.js.map +1 -1
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +2 -0
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/features.d.ts +5 -0
- package/dist/ai-service/features.d.ts.map +1 -1
- package/dist/ai-service/features.js +5 -0
- package/dist/ai-service/features.js.map +1 -1
- package/dist/ai-service/index.d.ts +2 -1
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +135 -2
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/prompts/summarize-api-usage.d.ts +18 -0
- package/dist/ai-service/prompts/summarize-api-usage.d.ts.map +1 -0
- package/dist/ai-service/prompts/summarize-api-usage.js +30 -0
- package/dist/ai-service/prompts/summarize-api-usage.js.map +1 -0
- package/dist/ai-service/skills/system/_registry.generated.d.ts.map +1 -1
- package/dist/ai-service/skills/system/_registry.generated.js +0 -1
- package/dist/ai-service/skills/system/_registry.generated.js.map +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/code-blocks.generated.d.ts +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/code-blocks.generated.d.ts.map +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/code-blocks.generated.js +51 -37
- package/dist/ai-service/skills/system/superblocks-api/references/code-blocks.generated.js.map +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/rest-apis.generated.d.ts +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/rest-apis.generated.d.ts.map +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/rest-apis.generated.js +100 -93
- package/dist/ai-service/skills/system/superblocks-api/references/rest-apis.generated.js.map +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/sql-databases.generated.d.ts +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/sql-databases.generated.d.ts.map +1 -1
- package/dist/ai-service/skills/system/superblocks-api/references/sql-databases.generated.js +72 -49
- package/dist/ai-service/skills/system/superblocks-api/references/sql-databases.generated.js.map +1 -1
- package/dist/ai-service/skills/system/superblocks-frontend/references/embedding.generated.d.ts +1 -1
- package/dist/ai-service/skills/system/superblocks-frontend/references/embedding.generated.d.ts.map +1 -1
- package/dist/ai-service/skills/system/superblocks-frontend/references/embedding.generated.js +7 -7
- package/dist/ai-service/skills/system/superblocks-frontend/skill.generated.d.ts +1 -1
- package/dist/ai-service/skills/system/superblocks-frontend/skill.generated.d.ts.map +1 -1
- package/dist/ai-service/skills/system/superblocks-frontend/skill.generated.js +88 -28
- package/dist/ai-service/skills/system/superblocks-frontend/skill.generated.js.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.js +0 -2
- package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +9 -0
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +4 -0
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/git-service/errors.d.ts +18 -0
- package/dist/git-service/errors.d.ts.map +1 -0
- package/dist/git-service/errors.js +27 -0
- package/dist/git-service/errors.js.map +1 -0
- package/dist/git-service/index.d.ts +30 -0
- package/dist/git-service/index.d.ts.map +1 -0
- package/dist/git-service/index.js +135 -0
- package/dist/git-service/index.js.map +1 -0
- package/dist/git-service/live-branch.d.ts +10 -0
- package/dist/git-service/live-branch.d.ts.map +1 -0
- package/dist/git-service/live-branch.js +63 -0
- package/dist/git-service/live-branch.js.map +1 -0
- package/dist/lock-service/index.d.ts +5 -1
- package/dist/lock-service/index.d.ts.map +1 -1
- package/dist/lock-service/index.js +83 -16
- package/dist/lock-service/index.js.map +1 -1
- package/dist/plugin-options.d.ts +3 -0
- package/dist/plugin-options.d.ts.map +1 -1
- package/dist/plugin-options.js.map +1 -1
- package/dist/socket-manager.d.ts +4 -1
- package/dist/socket-manager.d.ts.map +1 -1
- package/dist/socket-manager.js +378 -3
- package/dist/socket-manager.js.map +1 -1
- package/dist/sync-service/index.d.ts +12 -1
- package/dist/sync-service/index.d.ts.map +1 -1
- package/dist/sync-service/index.js +37 -6
- package/dist/sync-service/index.js.map +1 -1
- package/package.json +21 -16
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const content = "# REST API Integrations\n\nReference documentation for working with REST APIs and OpenAPI integrations in Superblocks.\n\n## REST API vs OpenAPI\n\n**Use RestApi** when:\n- Making calls to custom endpoints\n- No OpenAPI spec available\n- Simple GET/POST operations\n\n**Use OpenApi** when:\n- Integration metadata shows `spec: \"openapi\"` or `specType: \"OPEN_API_SPEC\"`\n- Working with documented APIs (Stripe, Twilio, etc.)\n- Need type-safe operations\n\n## RestApi Class\n\n```typescript\nimport { RestApi } from \"@superblocksteam/library\";\n\nnew RestApi(\"fetch_data\", \"rest-integration-id\", {\n method: \"GET\",\n url: \"https://api.example.com/data\",\n params: { page: \"1\", limit: \"10\" },\n headers: { \"X-Custom-Header\": \"value\" }
|
|
1
|
+
export declare const content = "# REST API Integrations\n\nReference documentation for working with REST APIs and OpenAPI integrations in Superblocks.\n\n## REST API vs OpenAPI\n\n**Use RestApi** when:\n\n- Making calls to custom endpoints\n- No OpenAPI spec available\n- Simple GET/POST operations\n\n**Use OpenApi** when:\n\n- Integration metadata shows `spec: \"openapi\"` or `specType: \"OPEN_API_SPEC\"`\n- Working with documented APIs (Stripe, Twilio, etc.)\n- Need type-safe operations\n\n## RestApi Class\n\n```typescript\nimport { RestApi } from \"@superblocksteam/library\";\n\nnew RestApi(\"fetch_data\", \"rest-integration-id\", {\n method: \"GET\",\n url: \"https://api.example.com/data\",\n params: { page: \"1\", limit: \"10\" },\n headers: { \"X-Custom-Header\": \"value\" },\n});\n```\n\n### Dynamic Configuration\n\n```typescript\nnew RestApi(\"create_item\", \"rest-id\", {\n method: \"POST\",\n url: ({ baseUrl }: { baseUrl: string }) => `${baseUrl}/items`,\n params: ({ page }: { page: number }) => ({ page: String(page) }),\n headers: ({ authToken }: { authToken: string }) => ({\n Authorization: `Bearer ${authToken}`,\n \"Content-Type\": \"application/json\",\n }),\n body: ({ itemData }: { itemData: object }) => JSON.stringify(itemData),\n});\n```\n\n### Common REST Patterns\n\n```typescript\n// GET with query params\nnew RestApi(\"search\", \"rest-id\", {\n method: \"GET\",\n url: \"https://api.example.com/search\",\n params: ({ query, page }: { query: string; page: number }) => ({\n q: query,\n page: String(page),\n limit: \"20\",\n }),\n});\n\n// POST with JSON body\nnew RestApi(\"create\", \"rest-id\", {\n method: \"POST\",\n url: \"https://api.example.com/items\",\n headers: { \"Content-Type\": \"application/json\" },\n body: ({ data }: { data: object }) => JSON.stringify(data),\n});\n\n// PUT for updates\nnew RestApi(\"update\", \"rest-id\", {\n method: \"PUT\",\n url: ({ id }: { id: string }) => `https://api.example.com/items/${id}`,\n headers: { \"Content-Type\": \"application/json\" },\n body: ({ data }: { data: object }) => JSON.stringify(data),\n});\n\n// DELETE\nnew RestApi(\"delete\", \"rest-id\", {\n method: \"DELETE\",\n url: ({ id }: { id: string }) => `https://api.example.com/items/${id}`,\n});\n```\n\n## OpenApi Class\n\n```typescript\nimport { OpenApi } from \"@superblocksteam/library\";\n\nnew OpenApi(\"list_customers\", \"stripe-integration-id\", {\n operation: \"listCustomers\",\n params: { limit: 10 },\n});\n```\n\n### OpenAPI Operations\n\nOperation names are defined by the API spec. Common patterns:\n\n- `list{Resource}` - List all resources\n- `get{Resource}` - Get a single resource\n- `create{Resource}` - Create a resource\n- `update{Resource}` - Update a resource\n- `delete{Resource}` - Delete a resource\n\n### Dynamic OpenAPI Params\n\n```typescript\nnew OpenApi(\"get_customer\", \"stripe-id\", {\n operation: \"getCustomer\",\n params: ({ customerId }: { customerId: string }) => ({\n customer_id: customerId,\n }),\n});\n```\n\n## Response Handling\n\nREST and OpenAPI responses are available via `.output`:\n\n```typescript\nnew RestApi(\"fetch\", \"rest-id\", { ... }),\n\nnew JavaScript(\"process\", {\n fn: ({ fetch }) => {\n const data = fetch.output;\n // For REST APIs, output is typically the JSON response\n // For OpenAPI, output structure depends on the operation\n return data.items.map(item => item.name);\n }\n})\n```\n\n## Error Handling\n\nHTTP errors (4xx, 5xx) are captured in the output:\n\n```typescript\nnew TryCatch(\"safe_api_call\", {\n try: [\n new RestApi(\"risky_call\", \"rest-id\", {\n method: \"POST\",\n url: \"https://api.example.com/sensitive\",\n }),\n ],\n catch: [\n new JavaScript(\"handle_error\", {\n fn: ({ apiError }) => ({\n success: false,\n error: apiError.value.message,\n statusCode: apiError.value.statusCode,\n }),\n }),\n ],\n variables: { error: \"apiError\" },\n});\n```\n\n## Pagination Patterns\n\n### Cursor-Based Pagination\n\n```typescript\n(new Variables(\"state\", [\n { key: \"allItems\", value: () => [] },\n { key: \"cursor\", value: () => null },\n { key: \"hasMore\", value: () => true },\n]),\n new Loop(\"paginate\", {\n type: \"TYPE_FOREACH\",\n over: () => [...Array(100).keys()],\n variables: { item: \"_\", index: \"i\" },\n blocks: [\n new Conditional(\"check_done\", {\n if: {\n when: ({ hasMore }) => !hasMore.value,\n then: [new Break(\"exit\", { condition: () => true })],\n },\n }),\n new RestApi(\"fetch_page\", \"rest-id\", {\n method: \"GET\",\n url: \"https://api.example.com/items\",\n params: ({ cursor }) => (cursor.value ? { cursor: cursor.value } : {}),\n }),\n new JavaScript(\"accumulate\", {\n fn: ({ fetch_page, allItems, cursor, hasMore }) => {\n const response = fetch_page.output;\n allItems.set([...allItems.value, ...response.items]);\n cursor.set(response.nextCursor);\n hasMore.set(!!response.nextCursor);\n return allItems.value;\n },\n }),\n ],\n }));\n```\n\n### Offset-Based Pagination\n\n```typescript\n(new Variables(\"state\", [\n { key: \"allItems\", value: () => [] },\n { key: \"page\", value: () => 0 },\n { key: \"hasMore\", value: () => true },\n]),\n new Loop(\"paginate\", {\n type: \"TYPE_WHILE\",\n condition: ({ hasMore }) => hasMore.value,\n blocks: [\n new RestApi(\"fetch_page\", \"rest-id\", {\n method: \"GET\",\n url: \"https://api.example.com/items\",\n params: ({ page }) => ({\n offset: String(page.value * 100),\n limit: \"100\",\n }),\n }),\n new JavaScript(\"accumulate\", {\n fn: ({ fetch_page, allItems, page, hasMore }) => {\n const items = fetch_page.output.items;\n allItems.set([...allItems.value, ...items]);\n page.set(page.value + 1);\n hasMore.set(items.length === 100);\n return allItems.value;\n },\n }),\n ],\n }));\n```\n\n## Authentication Patterns\n\n### Bearer Token\n\n```typescript\nnew RestApi(\"authenticated_call\", \"rest-id\", {\n method: \"GET\",\n url: \"https://api.example.com/secure\",\n headers: ({ token }: { token: string }) => ({\n Authorization: `Bearer ${token}`,\n }),\n});\n```\n\n### API Key\n\n```typescript\nnew RestApi(\"api_key_call\", \"rest-id\", {\n method: \"GET\",\n url: \"https://api.example.com/data\",\n headers: ({ apiKey }: { apiKey: string }) => ({\n \"X-API-Key\": apiKey,\n }),\n});\n```\n\n### Basic Auth\n\n```typescript\nnew RestApi(\"basic_auth_call\", \"rest-id\", {\n method: \"GET\",\n url: \"https://api.example.com/data\",\n headers: ({\n username,\n password,\n }: {\n username: string;\n password: string;\n }) => ({\n Authorization: `Basic ${Buffer.from(`${username}:${password}`).toString(\"base64\")}`,\n }),\n});\n```\n";
|
|
2
2
|
//# sourceMappingURL=rest-apis.generated.d.ts.map
|
package/dist/ai-service/skills/system/superblocks-api/references/rest-apis.generated.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-apis.generated.d.ts","sourceRoot":"","sources":["../../../../../../src/ai-service/skills/system/superblocks-api/references/rest-apis.generated.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"rest-apis.generated.d.ts","sourceRoot":"","sources":["../../../../../../src/ai-service/skills/system/superblocks-api/references/rest-apis.generated.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,03NAgRnB,CAAC"}
|
|
@@ -7,11 +7,13 @@ Reference documentation for working with REST APIs and OpenAPI integrations in S
|
|
|
7
7
|
## REST API vs OpenAPI
|
|
8
8
|
|
|
9
9
|
**Use RestApi** when:
|
|
10
|
+
|
|
10
11
|
- Making calls to custom endpoints
|
|
11
12
|
- No OpenAPI spec available
|
|
12
13
|
- Simple GET/POST operations
|
|
13
14
|
|
|
14
15
|
**Use OpenApi** when:
|
|
16
|
+
|
|
15
17
|
- Integration metadata shows \`spec: "openapi"\` or \`specType: "OPEN_API_SPEC"\`
|
|
16
18
|
- Working with documented APIs (Stripe, Twilio, etc.)
|
|
17
19
|
- Need type-safe operations
|
|
@@ -25,8 +27,8 @@ new RestApi("fetch_data", "rest-integration-id", {
|
|
|
25
27
|
method: "GET",
|
|
26
28
|
url: "https://api.example.com/data",
|
|
27
29
|
params: { page: "1", limit: "10" },
|
|
28
|
-
headers: { "X-Custom-Header": "value" }
|
|
29
|
-
})
|
|
30
|
+
headers: { "X-Custom-Header": "value" },
|
|
31
|
+
});
|
|
30
32
|
\`\`\`
|
|
31
33
|
|
|
32
34
|
### Dynamic Configuration
|
|
@@ -37,11 +39,11 @@ new RestApi("create_item", "rest-id", {
|
|
|
37
39
|
url: ({ baseUrl }: { baseUrl: string }) => \`\${baseUrl}/items\`,
|
|
38
40
|
params: ({ page }: { page: number }) => ({ page: String(page) }),
|
|
39
41
|
headers: ({ authToken }: { authToken: string }) => ({
|
|
40
|
-
|
|
41
|
-
"Content-Type": "application/json"
|
|
42
|
+
Authorization: \`Bearer \${authToken}\`,
|
|
43
|
+
"Content-Type": "application/json",
|
|
42
44
|
}),
|
|
43
|
-
body: ({ itemData }: { itemData: object }) => JSON.stringify(itemData)
|
|
44
|
-
})
|
|
45
|
+
body: ({ itemData }: { itemData: object }) => JSON.stringify(itemData),
|
|
46
|
+
});
|
|
45
47
|
\`\`\`
|
|
46
48
|
|
|
47
49
|
### Common REST Patterns
|
|
@@ -54,31 +56,31 @@ new RestApi("search", "rest-id", {
|
|
|
54
56
|
params: ({ query, page }: { query: string; page: number }) => ({
|
|
55
57
|
q: query,
|
|
56
58
|
page: String(page),
|
|
57
|
-
limit: "20"
|
|
58
|
-
})
|
|
59
|
-
})
|
|
59
|
+
limit: "20",
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
60
62
|
|
|
61
63
|
// POST with JSON body
|
|
62
64
|
new RestApi("create", "rest-id", {
|
|
63
65
|
method: "POST",
|
|
64
66
|
url: "https://api.example.com/items",
|
|
65
67
|
headers: { "Content-Type": "application/json" },
|
|
66
|
-
body: ({ data }: { data: object }) => JSON.stringify(data)
|
|
67
|
-
})
|
|
68
|
+
body: ({ data }: { data: object }) => JSON.stringify(data),
|
|
69
|
+
});
|
|
68
70
|
|
|
69
71
|
// PUT for updates
|
|
70
72
|
new RestApi("update", "rest-id", {
|
|
71
73
|
method: "PUT",
|
|
72
74
|
url: ({ id }: { id: string }) => \`https://api.example.com/items/\${id}\`,
|
|
73
75
|
headers: { "Content-Type": "application/json" },
|
|
74
|
-
body: ({ data }: { data: object }) => JSON.stringify(data)
|
|
75
|
-
})
|
|
76
|
+
body: ({ data }: { data: object }) => JSON.stringify(data),
|
|
77
|
+
});
|
|
76
78
|
|
|
77
79
|
// DELETE
|
|
78
80
|
new RestApi("delete", "rest-id", {
|
|
79
81
|
method: "DELETE",
|
|
80
|
-
url: ({ id }: { id: string }) => \`https://api.example.com/items/\${id}
|
|
81
|
-
})
|
|
82
|
+
url: ({ id }: { id: string }) => \`https://api.example.com/items/\${id}\`,
|
|
83
|
+
});
|
|
82
84
|
\`\`\`
|
|
83
85
|
|
|
84
86
|
## OpenApi Class
|
|
@@ -88,13 +90,14 @@ import { OpenApi } from "@superblocksteam/library";
|
|
|
88
90
|
|
|
89
91
|
new OpenApi("list_customers", "stripe-integration-id", {
|
|
90
92
|
operation: "listCustomers",
|
|
91
|
-
params: { limit: 10 }
|
|
92
|
-
})
|
|
93
|
+
params: { limit: 10 },
|
|
94
|
+
});
|
|
93
95
|
\`\`\`
|
|
94
96
|
|
|
95
97
|
### OpenAPI Operations
|
|
96
98
|
|
|
97
99
|
Operation names are defined by the API spec. Common patterns:
|
|
100
|
+
|
|
98
101
|
- \`list{Resource}\` - List all resources
|
|
99
102
|
- \`get{Resource}\` - Get a single resource
|
|
100
103
|
- \`create{Resource}\` - Create a resource
|
|
@@ -107,9 +110,9 @@ Operation names are defined by the API spec. Common patterns:
|
|
|
107
110
|
new OpenApi("get_customer", "stripe-id", {
|
|
108
111
|
operation: "getCustomer",
|
|
109
112
|
params: ({ customerId }: { customerId: string }) => ({
|
|
110
|
-
customer_id: customerId
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
+
customer_id: customerId,
|
|
114
|
+
}),
|
|
115
|
+
});
|
|
113
116
|
\`\`\`
|
|
114
117
|
|
|
115
118
|
## Response Handling
|
|
@@ -138,20 +141,20 @@ new TryCatch("safe_api_call", {
|
|
|
138
141
|
try: [
|
|
139
142
|
new RestApi("risky_call", "rest-id", {
|
|
140
143
|
method: "POST",
|
|
141
|
-
url: "https://api.example.com/sensitive"
|
|
142
|
-
})
|
|
144
|
+
url: "https://api.example.com/sensitive",
|
|
145
|
+
}),
|
|
143
146
|
],
|
|
144
147
|
catch: [
|
|
145
148
|
new JavaScript("handle_error", {
|
|
146
149
|
fn: ({ apiError }) => ({
|
|
147
150
|
success: false,
|
|
148
151
|
error: apiError.value.message,
|
|
149
|
-
statusCode: apiError.value.statusCode
|
|
150
|
-
})
|
|
151
|
-
})
|
|
152
|
+
statusCode: apiError.value.statusCode,
|
|
153
|
+
}),
|
|
154
|
+
}),
|
|
152
155
|
],
|
|
153
|
-
variables: { error: "apiError" }
|
|
154
|
-
})
|
|
156
|
+
variables: { error: "apiError" },
|
|
157
|
+
});
|
|
155
158
|
\`\`\`
|
|
156
159
|
|
|
157
160
|
## Pagination Patterns
|
|
@@ -159,73 +162,71 @@ new TryCatch("safe_api_call", {
|
|
|
159
162
|
### Cursor-Based Pagination
|
|
160
163
|
|
|
161
164
|
\`\`\`typescript
|
|
162
|
-
new Variables("state", [
|
|
165
|
+
(new Variables("state", [
|
|
163
166
|
{ key: "allItems", value: () => [] },
|
|
164
167
|
{ key: "cursor", value: () => null },
|
|
165
|
-
{ key: "hasMore", value: () => true }
|
|
168
|
+
{ key: "hasMore", value: () => true },
|
|
166
169
|
]),
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
})
|
|
170
|
+
new Loop("paginate", {
|
|
171
|
+
type: "TYPE_FOREACH",
|
|
172
|
+
over: () => [...Array(100).keys()],
|
|
173
|
+
variables: { item: "_", index: "i" },
|
|
174
|
+
blocks: [
|
|
175
|
+
new Conditional("check_done", {
|
|
176
|
+
if: {
|
|
177
|
+
when: ({ hasMore }) => !hasMore.value,
|
|
178
|
+
then: [new Break("exit", { condition: () => true })],
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
new RestApi("fetch_page", "rest-id", {
|
|
182
|
+
method: "GET",
|
|
183
|
+
url: "https://api.example.com/items",
|
|
184
|
+
params: ({ cursor }) => (cursor.value ? { cursor: cursor.value } : {}),
|
|
185
|
+
}),
|
|
186
|
+
new JavaScript("accumulate", {
|
|
187
|
+
fn: ({ fetch_page, allItems, cursor, hasMore }) => {
|
|
188
|
+
const response = fetch_page.output;
|
|
189
|
+
allItems.set([...allItems.value, ...response.items]);
|
|
190
|
+
cursor.set(response.nextCursor);
|
|
191
|
+
hasMore.set(!!response.nextCursor);
|
|
192
|
+
return allItems.value;
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
],
|
|
196
|
+
}));
|
|
195
197
|
\`\`\`
|
|
196
198
|
|
|
197
199
|
### Offset-Based Pagination
|
|
198
200
|
|
|
199
201
|
\`\`\`typescript
|
|
200
|
-
new Variables("state", [
|
|
202
|
+
(new Variables("state", [
|
|
201
203
|
{ key: "allItems", value: () => [] },
|
|
202
204
|
{ key: "page", value: () => 0 },
|
|
203
|
-
{ key: "hasMore", value: () => true }
|
|
205
|
+
{ key: "hasMore", value: () => true },
|
|
204
206
|
]),
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
})
|
|
207
|
+
new Loop("paginate", {
|
|
208
|
+
type: "TYPE_WHILE",
|
|
209
|
+
condition: ({ hasMore }) => hasMore.value,
|
|
210
|
+
blocks: [
|
|
211
|
+
new RestApi("fetch_page", "rest-id", {
|
|
212
|
+
method: "GET",
|
|
213
|
+
url: "https://api.example.com/items",
|
|
214
|
+
params: ({ page }) => ({
|
|
215
|
+
offset: String(page.value * 100),
|
|
216
|
+
limit: "100",
|
|
217
|
+
}),
|
|
218
|
+
}),
|
|
219
|
+
new JavaScript("accumulate", {
|
|
220
|
+
fn: ({ fetch_page, allItems, page, hasMore }) => {
|
|
221
|
+
const items = fetch_page.output.items;
|
|
222
|
+
allItems.set([...allItems.value, ...items]);
|
|
223
|
+
page.set(page.value + 1);
|
|
224
|
+
hasMore.set(items.length === 100);
|
|
225
|
+
return allItems.value;
|
|
226
|
+
},
|
|
227
|
+
}),
|
|
228
|
+
],
|
|
229
|
+
}));
|
|
229
230
|
\`\`\`
|
|
230
231
|
|
|
231
232
|
## Authentication Patterns
|
|
@@ -237,9 +238,9 @@ new RestApi("authenticated_call", "rest-id", {
|
|
|
237
238
|
method: "GET",
|
|
238
239
|
url: "https://api.example.com/secure",
|
|
239
240
|
headers: ({ token }: { token: string }) => ({
|
|
240
|
-
|
|
241
|
-
})
|
|
242
|
-
})
|
|
241
|
+
Authorization: \`Bearer \${token}\`,
|
|
242
|
+
}),
|
|
243
|
+
});
|
|
243
244
|
\`\`\`
|
|
244
245
|
|
|
245
246
|
### API Key
|
|
@@ -249,9 +250,9 @@ new RestApi("api_key_call", "rest-id", {
|
|
|
249
250
|
method: "GET",
|
|
250
251
|
url: "https://api.example.com/data",
|
|
251
252
|
headers: ({ apiKey }: { apiKey: string }) => ({
|
|
252
|
-
"X-API-Key": apiKey
|
|
253
|
-
})
|
|
254
|
-
})
|
|
253
|
+
"X-API-Key": apiKey,
|
|
254
|
+
}),
|
|
255
|
+
});
|
|
255
256
|
\`\`\`
|
|
256
257
|
|
|
257
258
|
### Basic Auth
|
|
@@ -260,10 +261,16 @@ new RestApi("api_key_call", "rest-id", {
|
|
|
260
261
|
new RestApi("basic_auth_call", "rest-id", {
|
|
261
262
|
method: "GET",
|
|
262
263
|
url: "https://api.example.com/data",
|
|
263
|
-
headers: ({
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
264
|
+
headers: ({
|
|
265
|
+
username,
|
|
266
|
+
password,
|
|
267
|
+
}: {
|
|
268
|
+
username: string;
|
|
269
|
+
password: string;
|
|
270
|
+
}) => ({
|
|
271
|
+
Authorization: \`Basic \${Buffer.from(\`\${username}:\${password}\`).toString("base64")}\`,
|
|
272
|
+
}),
|
|
273
|
+
});
|
|
267
274
|
\`\`\`
|
|
268
275
|
`;
|
|
269
276
|
//# sourceMappingURL=rest-apis.generated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-apis.generated.js","sourceRoot":"","sources":["../../../../../../src/ai-service/skills/system/superblocks-api/references/rest-apis.generated.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,mDAAmD;AAEnD,MAAM,CAAC,MAAM,OAAO,GAAG
|
|
1
|
+
{"version":3,"file":"rest-apis.generated.js","sourceRoot":"","sources":["../../../../../../src/ai-service/skills/system/superblocks-api/references/rest-apis.generated.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,mDAAmD;AAEnD,MAAM,CAAC,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgRtB,CAAC"}
|
package/dist/ai-service/skills/system/superblocks-api/references/sql-databases.generated.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const content = "# SQL Database Integrations\n\nReference documentation for working with SQL databases in Superblocks APIs.\n\n## Supported Databases\n\n- PostgreSQL, MySQL, MariaDB, MSSQL\n- Snowflake, Redshift, BigQuery, Athena\n- Databricks, SingleStore, Lakebase\n- CockroachDB, YugabyteDB, OracleDB\n\n## SQL Block Classes\n\n```typescript\n// Available SQL integrations\nimport {\n PostgreSQL,\n MySQL,\n MariaDB,\n MSSQL,\n Snowflake,\n Redshift,\n BigQuery,\n Athena,\n Databricks,\n SingleStore,\n OracleDB,\n} from \"@superblocksteam/library\";\n```\n\n## Basic Usage\n\n```typescript\nnew PostgreSQL(\"get_users\", \"postgres-integration-id\", {\n statement: \"SELECT * FROM users WHERE active = true LIMIT 100\"\n})\n```\n\n## Parameterized Queries\n\n### SQL Security Priority\n\n**ALWAYS prefer parameterized queries over string interpolation for user input values.**\n\nUse `parameters: \"[var1, var2]\"` with the database-specific SQL placeholders:\n\n| Database | Placeholder Syntax | Example |\n|----------|-------------------|---------|\n| PostgreSQL, Redshift, CockroachDB | `$1`, `$2`, `$3` | `WHERE id = $1 AND status = $2` |\n| MySQL, MariaDB, Snowflake, BigQuery, Athena | `?`, `?`, `?` | `WHERE id = ? AND status = ?` |\n| MSSQL | `@PARAM_1`, `@PARAM_2` | `WHERE id = @PARAM_1 AND status = @PARAM_2` |\n| Databricks | `:PARAM_1`, `:PARAM_2` | `WHERE id = :PARAM_1 AND status = :PARAM_2` |\n| OracleDB | `:1`, `:2`, `:3` | `WHERE id = :1 AND status = :2` |\n\nOnly use binding functions for truly dynamic SQL elements like table/column names.\n\n### Parameters Syntax vs Statement Syntax\n\n**Important:** `parameters` is a JavaScript expression string that gets evaluated directly. Do NOT use `${}` interpolation or binding functions.\n\n```typescript\n// \u274C WRONG - Don't use ${} interpolation in parameters\nparameters: \"[${build_query.output.userId}, ${searchTerm}]\"\n\n// \u274C WRONG - Don't use binding functions for parameters \nparameters: ({ build_query }) => JSON.stringify(build_query.output.params)\n\n// \u2705 CORRECT - Write expressions directly (they get evaluated as JS)\nparameters: \"[build_query.output.userId, searchTerm, limit]\"\n\n// \u2705 CORRECT - Reference block output array directly\nparameters: \"build_query.output.params\"\n```\n\nThis is different from `statement`, where binding functions with `${}` ARE used to interpolate values into SQL.\n\n### String Interpolation (Alternative)\n\nFor simpler cases, string interpolation also works:\n\n```typescript\n// \u2705 CORRECT - String interpolation for WHERE clauses\nnew PostgreSQL(\"search\", \"postgres-id\", {\n statement: ({ searchTerm, limit }: { searchTerm: string; limit: number }) =>\n `SELECT * FROM users WHERE name ILIKE '%${searchTerm}%' LIMIT ${limit}`\n})\n\n// \u2705 CORRECT - For INSERT statements\nnew PostgreSQL(\"insert_user\", \"postgres-id\", {\n statement: ({ name, email }: { name: string; email: string }) =>\n `INSERT INTO users (name, email) VALUES ('${name}', '${email}') RETURNING *`\n})\n```\n\n### Dynamic SQL with Optional Filters\n\nUse the `parameters` array with the \"OR NULL\" pattern for optional filters:\n- `WHERE (column = $1 OR $1::type IS NULL)` makes the condition a no-op when parameter is null\n- Cast parameters to their type when checking for NULL (PostgreSQL can't infer types from NULL values)\n- Always pass all parameters, using null for unused filters\n- NEVER interpolate user values directly into SQL strings\n\n## Best Practices\n\n### 1. ONE Query Per Block Rule\n\nEach SQL block (PostgreSQL, Snowflake, MySQL, MicrosoftSql, Databricks) can execute **ONLY ONE SQL query**.\n\n\u274C **WRONG - Multiple queries in one block:**\n```sql\nUPDATE users SET status = 'active';\nDELETE FROM logs WHERE created < '2023-01-01';\nINSERT INTO audit VALUES ('done');\n```\n\n\u2705 **CORRECT - One query per block:**\n```typescript\nnew PostgreSQL(\"update_status\", \"postgres-id\", {\n statement: \"UPDATE users SET status = 'active'\"\n}),\nnew PostgreSQL(\"clean_logs\", \"postgres-id\", {\n statement: \"DELETE FROM logs WHERE created < '2023-01-01'\"\n})\n```\n\n### 2. Use Meaningful Block Names\n\n```typescript\n// \u2705 GOOD\nnew PostgreSQL(\"fetch_active_users\", \"pg-id\", { ... })\nnew PostgreSQL(\"insert_order_item\", \"pg-id\", { ... })\n\n// \u274C BAD\nnew PostgreSQL(\"query1\", \"pg-id\", { ... })\nnew PostgreSQL(\"sql\", \"pg-id\", { ... })\n```\n\n### 3. Always Specify Columns\n\n```typescript\n// \u2705 PREFERRED - Explicit columns\nSELECT id, name, email, created_at FROM users\n\n// \u26A0\uFE0F AVOID - Select all\nSELECT * FROM users\n```\n\n### 4. Always Add Defensive Row Limits\n\nAlways include a row limit clause to prevent runaway queries. Use 100 as the default unless user specifies otherwise.\n\nDifferent SQL dialects have different syntax:\n- **MySQL/PostgreSQL/SQLite**: `LIMIT N`\n- **SQL Server**: `SELECT TOP N`\n- **ANSI SQL (SQL Server, Oracle, DB2)**: `OFFSET 0 ROWS FETCH NEXT N ROWS ONLY`\n\n```sql\n-- \u2705 PostgreSQL/MySQL\nSELECT * FROM orders ORDER BY created_at DESC LIMIT 100;\n\n-- \u2705 SQL Server\nSELECT TOP 100 * FROM orders ORDER BY created_at DESC;\n\n-- \u2705 ANSI SQL (SQL Server with ORDER BY)\nSELECT * FROM orders ORDER BY created_at DESC OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;\n\n-- \u274C Avoid unlimited queries\nSELECT * FROM orders ORDER BY created_at DESC; -- Can timeout or crash\n```\n\n### 5. Sort, Don't Filter by Date (Default)\n\nDo NOT add automatic date filters (e.g., \"last 90 days\") unless the user explicitly requests them. This is a common cause of unexpected empty SQL results.\n\n```sql\n-- \u2705 Default approach\nSELECT * FROM orders ORDER BY created_at DESC LIMIT 100;\n\n-- \u274C Avoid automatic filtering\nSELECT * FROM orders WHERE created_at >= CURRENT_DATE - INTERVAL '90 days'; -- Can return empty results\n```\n\nOnly add date WHERE clauses when users explicitly ask for time-based filtering.\n\n### 6. Handle NULL Values\n\n```typescript\n// \u2705 Use COALESCE for default values\nSELECT COALESCE(description, 'No description') as description FROM products\n\n// \u2705 Use IS NULL / IS NOT NULL\nSELECT * FROM users WHERE deleted_at IS NULL\n```\n\n## Database-Specific Notes\n\n### PostgreSQL\n\n```typescript\n// Array operations\nnew PostgreSQL(\"array_query\", \"pg-id\", {\n statement: ({ tags }: { tags: string[] }) =>\n `SELECT * FROM posts WHERE tags && ARRAY[${tags.map(t => `'${t}'`).join(',')}]`\n})\n\n// JSON operations\nnew PostgreSQL(\"json_query\", \"pg-id\", {\n statement: \"SELECT data->>'name' as name FROM json_data\"\n})\n```\n\n- Use schema-qualified names: `schema.table` or `\"schema\".\"table\"`\n- Case sensitivity: Unquoted identifiers are lowercase\n- Use `::type` for type casting\n\n### Snowflake\n\n```typescript\n// Use QUALIFY for window function filtering\nnew Snowflake(\"ranked_query\", \"snowflake-id\", {\n statement: `\n SELECT *, ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) as rank\n FROM products\n QUALIFY rank <= 3\n `\n})\n```\n\n**Snowflake Two-Part Naming:** Snowflake uses `schema.table`\n\nWhen you see Snowflake metadata where tables have a `schema` property, **you MUST qualify table names**:\n\n```sql\n-- If table has schema property \"MASTERDATA\"\nSELECT * FROM MASTERDATA.PRODUCTLINE -- \u2705 Fully qualified\nSELECT * FROM PRODUCTLINE -- \u274C Will fail if no default schema\n```\n\n**Rule**: If a table object has a non-empty `schema` property, use `{schema}.{name}` format in your SQL queries.\n\n### Databricks\n\n**Databricks Three-Part Naming:** Databricks uses `catalog.schema.table`\n\nWhen you see Databricks metadata like:\n- `uber.default.orders` - Use the FULL path: `uber.default.orders`\n- `production.analytics.users` - Use: `production.analytics.users`\n\n```sql\n-- Metadata shows: uber.default.orders\nSELECT * FROM uber.default.orders -- \u2705 Full path\nSELECT * FROM uber.orders -- \u274C Missing schema part\nSELECT * FROM orders -- \u274C Missing catalog and schema\n```\n\n**Note:** The word \"default\" in Databricks paths is NOT optional - it's the actual schema name. Always include all three parts exactly as shown in the metadata.\n\n### BigQuery\n\n```typescript\n// Use backticks for table names\nnew BigQuery(\"query\", \"bq-id\", {\n statement: \"SELECT * FROM \\`project.dataset.table\\` LIMIT 100\"\n})\n```\n\n## Common Patterns\n\n### Pagination\n\n```typescript\nnew PostgreSQL(\"paginated_fetch\", \"pg-id\", {\n statement: ({ page, pageSize }: { page: number; pageSize: number }) =>\n `SELECT * FROM orders ORDER BY created_at DESC LIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}`\n})\n```\n\n### Search with Multiple Conditions\n\n```typescript\nnew PostgreSQL(\"advanced_search\", \"pg-id\", {\n statement: ({ name, status, minAmount }: { name?: string; status?: string; minAmount?: number }) => {\n const conditions = [\"1=1\"];\n if (name) conditions.push(`name ILIKE '%${name}%'`);\n if (status) conditions.push(`status = '${status}'`);\n if (minAmount !== undefined) conditions.push(`amount >= ${minAmount}`);\n return `SELECT * FROM orders WHERE ${conditions.join(\" AND \")} LIMIT 100`;\n }\n})\n```\n\n### Batch Insert\n\n```typescript\nnew PostgreSQL(\"batch_insert\", \"pg-id\", {\n statement: ({ items }: { items: Array<{ name: string; value: number }> }) => {\n const values = items\n .map(item => `('${item.name}', ${item.value})`)\n .join(\", \");\n return `INSERT INTO items (name, value) VALUES ${values} RETURNING *`;\n }\n})\n```\n\n### Upsert (Insert or Update)\n\n```typescript\n// PostgreSQL\nnew PostgreSQL(\"upsert_user\", \"pg-id\", {\n statement: ({ id, name, email }: { id: string; name: string; email: string }) =>\n `INSERT INTO users (id, name, email) \n VALUES ('${id}', '${name}', '${email}')\n ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, email = EXCLUDED.email\n RETURNING *`\n})\n```\n\n## Error Handling\n\nSQL errors are returned in the block's output. Common errors:\n- Syntax errors in SQL\n- Table/column doesn't exist\n- Constraint violations\n- Connection timeouts\n\nFor critical operations, wrap in TryCatch:\n\n```typescript\nnew TryCatch(\"safe_delete\", {\n try: [\n new PostgreSQL(\"delete_record\", \"pg-id\", {\n statement: ({ id }: { id: string }) => `DELETE FROM sensitive_data WHERE id = '${id}'`\n })\n ],\n catch: [\n new JavaScript(\"log_error\", {\n fn: ({ deleteError }) => ({\n success: false,\n error: deleteError.value.message\n })\n })\n ],\n variables: { error: \"deleteError\" }\n})\n```\n";
|
|
1
|
+
export declare const content = "# SQL Database Integrations\n\nReference documentation for working with SQL databases in Superblocks APIs.\n\n## Supported Databases\n\n- PostgreSQL, MySQL, MariaDB, MSSQL\n- Snowflake, Redshift, BigQuery, Athena\n- Databricks, SingleStore, Lakebase\n- CockroachDB, YugabyteDB, OracleDB\n\n## SQL Block Classes\n\n```typescript\n// Available SQL integrations\nimport {\n PostgreSQL,\n MySQL,\n MariaDB,\n MSSQL,\n Snowflake,\n Redshift,\n BigQuery,\n Athena,\n Databricks,\n SingleStore,\n OracleDB,\n} from \"@superblocksteam/library\";\n```\n\n## Basic Usage\n\n```typescript\nnew PostgreSQL(\"get_users\", \"postgres-integration-id\", {\n statement: \"SELECT * FROM users WHERE active = true LIMIT 100\",\n});\n```\n\n## Parameterized Queries\n\n### SQL Security Priority\n\n**ALWAYS prefer parameterized queries over string interpolation for user input values.**\n\nUse `parameters: \"[var1, var2]\"` with the database-specific SQL placeholders:\n\n| Database | Placeholder Syntax | Example |\n| ------------------------------------------- | ---------------------- | ------------------------------------------- |\n| PostgreSQL, Redshift, CockroachDB | `$1`, `$2`, `$3` | `WHERE id = $1 AND status = $2` |\n| MySQL, MariaDB, Snowflake, BigQuery, Athena | `?`, `?`, `?` | `WHERE id = ? AND status = ?` |\n| MSSQL | `@PARAM_1`, `@PARAM_2` | `WHERE id = @PARAM_1 AND status = @PARAM_2` |\n| Databricks | `:PARAM_1`, `:PARAM_2` | `WHERE id = :PARAM_1 AND status = :PARAM_2` |\n| OracleDB | `:1`, `:2`, `:3` | `WHERE id = :1 AND status = :2` |\n\nOnly use binding functions for truly dynamic SQL elements like table/column names.\n\n### Parameters Syntax vs Statement Syntax\n\n**Important:** `parameters` is a JavaScript expression string that gets evaluated directly. Do NOT use `${}` interpolation or binding functions.\n\n```typescript\n// \u274C WRONG - Don't use ${} interpolation in parameters\nparameters: \"[${build_query.output.userId}, ${searchTerm}]\";\n\n// \u274C WRONG - Don't use binding functions for parameters\nparameters: ({ build_query }) => JSON.stringify(build_query.output.params);\n\n// \u2705 CORRECT - Write expressions directly (they get evaluated as JS)\nparameters: \"[build_query.output.userId, searchTerm, limit]\";\n\n// \u2705 CORRECT - Reference block output array directly\nparameters: \"build_query.output.params\";\n```\n\nThis is different from `statement`, where binding functions with `${}` ARE used to interpolate values into SQL.\n\n### String Interpolation (Alternative)\n\nFor simpler cases, string interpolation also works:\n\n```typescript\n// \u2705 CORRECT - String interpolation for WHERE clauses\nnew PostgreSQL(\"search\", \"postgres-id\", {\n statement: ({ searchTerm, limit }: { searchTerm: string; limit: number }) =>\n `SELECT * FROM users WHERE name ILIKE '%${searchTerm}%' LIMIT ${limit}`,\n});\n\n// \u2705 CORRECT - For INSERT statements\nnew PostgreSQL(\"insert_user\", \"postgres-id\", {\n statement: ({ name, email }: { name: string; email: string }) =>\n `INSERT INTO users (name, email) VALUES ('${name}', '${email}') RETURNING *`,\n});\n```\n\n### Dynamic SQL with Optional Filters\n\nUse the `parameters` array with the \"OR NULL\" pattern for optional filters:\n\n- `WHERE (column = $1 OR $1::type IS NULL)` makes the condition a no-op when parameter is null\n- Cast parameters to their type when checking for NULL (PostgreSQL can't infer types from NULL values)\n- Always pass all parameters, using null for unused filters\n- NEVER interpolate user values directly into SQL strings\n\n## Best Practices\n\n### 1. ONE Query Per Block Rule\n\nEach SQL block (PostgreSQL, Snowflake, MySQL, MicrosoftSql, Databricks) can execute **ONLY ONE SQL query**.\n\n\u274C **WRONG - Multiple queries in one block:**\n\n```sql\nUPDATE users SET status = 'active';\nDELETE FROM logs WHERE created < '2023-01-01';\nINSERT INTO audit VALUES ('done');\n```\n\n\u2705 **CORRECT - One query per block:**\n\n```typescript\n(new PostgreSQL(\"update_status\", \"postgres-id\", {\n statement: \"UPDATE users SET status = 'active'\",\n}),\n new PostgreSQL(\"clean_logs\", \"postgres-id\", {\n statement: \"DELETE FROM logs WHERE created < '2023-01-01'\",\n }));\n```\n\n### 2. Use Meaningful Block Names\n\n```typescript\n// \u2705 GOOD\nnew PostgreSQL(\"fetch_active_users\", \"pg-id\", { ... })\nnew PostgreSQL(\"insert_order_item\", \"pg-id\", { ... })\n\n// \u274C BAD\nnew PostgreSQL(\"query1\", \"pg-id\", { ... })\nnew PostgreSQL(\"sql\", \"pg-id\", { ... })\n```\n\n### 3. Always Specify Columns\n\n```typescript\n// \u2705 PREFERRED - Explicit columns\nSELECT id, name, email, created_at FROM users\n\n// \u26A0\uFE0F AVOID - Select all\nSELECT * FROM users\n```\n\n### 4. Always Add Defensive Row Limits\n\nAlways include a row limit clause to prevent runaway queries. Use 100 as the default unless user specifies otherwise.\n\nDifferent SQL dialects have different syntax:\n\n- **MySQL/PostgreSQL/SQLite**: `LIMIT N`\n- **SQL Server**: `SELECT TOP N`\n- **ANSI SQL (SQL Server, Oracle, DB2)**: `OFFSET 0 ROWS FETCH NEXT N ROWS ONLY`\n\n```sql\n-- \u2705 PostgreSQL/MySQL\nSELECT * FROM orders ORDER BY created_at DESC LIMIT 100;\n\n-- \u2705 SQL Server\nSELECT TOP 100 * FROM orders ORDER BY created_at DESC;\n\n-- \u2705 ANSI SQL (SQL Server with ORDER BY)\nSELECT * FROM orders ORDER BY created_at DESC OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY;\n\n-- \u274C Avoid unlimited queries\nSELECT * FROM orders ORDER BY created_at DESC; -- Can timeout or crash\n```\n\n### 5. Sort, Don't Filter by Date (Default)\n\nDo NOT add automatic date filters (e.g., \"last 90 days\") unless the user explicitly requests them. This is a common cause of unexpected empty SQL results.\n\n```sql\n-- \u2705 Default approach\nSELECT * FROM orders ORDER BY created_at DESC LIMIT 100;\n\n-- \u274C Avoid automatic filtering\nSELECT * FROM orders WHERE created_at >= CURRENT_DATE - INTERVAL '90 days'; -- Can return empty results\n```\n\nOnly add date WHERE clauses when users explicitly ask for time-based filtering.\n\n### 6. Handle NULL Values\n\n```typescript\n// \u2705 Use COALESCE for default values\nSELECT COALESCE(description, 'No description') as description FROM products\n\n// \u2705 Use IS NULL / IS NOT NULL\nSELECT * FROM users WHERE deleted_at IS NULL\n```\n\n## Database-Specific Notes\n\n### PostgreSQL\n\n```typescript\n// Array operations\nnew PostgreSQL(\"array_query\", \"pg-id\", {\n statement: ({ tags }: { tags: string[] }) =>\n `SELECT * FROM posts WHERE tags && ARRAY[${tags.map((t) => `'${t}'`).join(\",\")}]`,\n});\n\n// JSON operations\nnew PostgreSQL(\"json_query\", \"pg-id\", {\n statement: \"SELECT data->>'name' as name FROM json_data\",\n});\n```\n\n- Use schema-qualified names: `schema.table` or `\"schema\".\"table\"`\n- Case sensitivity: Unquoted identifiers are lowercase\n- Use `::type` for type casting\n\n### Snowflake\n\n```typescript\n// Use QUALIFY for window function filtering\nnew Snowflake(\"ranked_query\", \"snowflake-id\", {\n statement: `\n SELECT *, ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) as rank\n FROM products\n QUALIFY rank <= 3\n `,\n});\n```\n\n**Snowflake Two-Part Naming:** Snowflake uses `schema.table`\n\nWhen you see Snowflake metadata where tables have a `schema` property, **you MUST qualify table names**:\n\n```sql\n-- If table has schema property \"MASTERDATA\"\nSELECT * FROM MASTERDATA.PRODUCTLINE -- \u2705 Fully qualified\nSELECT * FROM PRODUCTLINE -- \u274C Will fail if no default schema\n```\n\n**Rule**: If a table object has a non-empty `schema` property, use `{schema}.{name}` format in your SQL queries.\n\n### Databricks\n\n**Databricks Three-Part Naming:** Databricks uses `catalog.schema.table`\n\nWhen you see Databricks metadata like:\n\n- `uber.default.orders` - Use the FULL path: `uber.default.orders`\n- `production.analytics.users` - Use: `production.analytics.users`\n\n```sql\n-- Metadata shows: uber.default.orders\nSELECT * FROM uber.default.orders -- \u2705 Full path\nSELECT * FROM uber.orders -- \u274C Missing schema part\nSELECT * FROM orders -- \u274C Missing catalog and schema\n```\n\n**Note:** The word \"default\" in Databricks paths is NOT optional - it's the actual schema name. Always include all three parts exactly as shown in the metadata.\n\n### BigQuery\n\n```typescript\n// Use backticks for table names\nnew BigQuery(\"query\", \"bq-id\", {\n statement: \"SELECT * FROM \\`project.dataset.table\\` LIMIT 100\",\n});\n```\n\n## Common Patterns\n\n### Pagination\n\n```typescript\nnew PostgreSQL(\"paginated_fetch\", \"pg-id\", {\n statement: ({ page, pageSize }: { page: number; pageSize: number }) =>\n `SELECT * FROM orders ORDER BY created_at DESC LIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}`,\n});\n```\n\n### Search with Multiple Conditions\n\n```typescript\nnew PostgreSQL(\"advanced_search\", \"pg-id\", {\n statement: ({\n name,\n status,\n minAmount,\n }: {\n name?: string;\n status?: string;\n minAmount?: number;\n }) => {\n const conditions = [\"1=1\"];\n if (name) conditions.push(`name ILIKE '%${name}%'`);\n if (status) conditions.push(`status = '${status}'`);\n if (minAmount !== undefined) conditions.push(`amount >= ${minAmount}`);\n return `SELECT * FROM orders WHERE ${conditions.join(\" AND \")} LIMIT 100`;\n },\n});\n```\n\n### Batch Insert\n\n```typescript\nnew PostgreSQL(\"batch_insert\", \"pg-id\", {\n statement: ({ items }: { items: Array<{ name: string; value: number }> }) => {\n const values = items\n .map((item) => `('${item.name}', ${item.value})`)\n .join(\", \");\n return `INSERT INTO items (name, value) VALUES ${values} RETURNING *`;\n },\n});\n```\n\n### Upsert (Insert or Update)\n\n```typescript\n// PostgreSQL\nnew PostgreSQL(\"upsert_user\", \"pg-id\", {\n statement: ({\n id,\n name,\n email,\n }: {\n id: string;\n name: string;\n email: string;\n }) =>\n `INSERT INTO users (id, name, email) \n VALUES ('${id}', '${name}', '${email}')\n ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, email = EXCLUDED.email\n RETURNING *`,\n});\n```\n\n## Error Handling\n\nSQL errors are returned in the block's output. Common errors:\n\n- Syntax errors in SQL\n- Table/column doesn't exist\n- Constraint violations\n- Connection timeouts\n\nFor critical operations, wrap in TryCatch:\n\n```typescript\nnew TryCatch(\"safe_delete\", {\n try: [\n new PostgreSQL(\"delete_record\", \"pg-id\", {\n statement: ({ id }: { id: string }) =>\n `DELETE FROM sensitive_data WHERE id = '${id}'`,\n }),\n ],\n catch: [\n new JavaScript(\"log_error\", {\n fn: ({ deleteError }) => ({\n success: false,\n error: deleteError.value.message,\n }),\n }),\n ],\n variables: { error: \"deleteError\" },\n});\n```\n";
|
|
2
2
|
//# sourceMappingURL=sql-databases.generated.d.ts.map
|
package/dist/ai-service/skills/system/superblocks-api/references/sql-databases.generated.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-databases.generated.d.ts","sourceRoot":"","sources":["../../../../../../src/ai-service/skills/system/superblocks-api/references/sql-databases.generated.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"sql-databases.generated.d.ts","sourceRoot":"","sources":["../../../../../../src/ai-service/skills/system/superblocks-api/references/sql-databases.generated.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,+7VAgXnB,CAAC"}
|